🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.micro.atari16
Article #842

Re: keypad probem ,need vt100 for ST

#842
From: braner
Date: Fri, 06 Jun 1986 17:44
64 lines
2466 bytes
[]

/* Program to create a binary file from a hex file.
   by Moshe braner, 860606.

   Will read data with any amount of parsing characters between
    the hex codes (including none).
   Rest of a line after a '*' is regarded as a comment.
   Can be used to create keyboard translation tables, etc.
*/

#include <stdio.h>

#define  ishex(c)  ((c>='0'&&c<='9')||(c>='A'&&c<='F')||(c>='a'&&c<='f'))

/* the following macro assumes ishex(c) and ASCII: */
#define  hexval(c) ((c<'A')?(c-'0'):((c<'a')?(c-'A'+0xA):(c-'a'+0xA)))

main() {
	register int c, b, n;
	FILE *infp, *outfp;
	char infname[80], outfname[80];

	printf("\n\nHex To Binary conversion program.  MB 8606.\n\n");
	printf("Enter name of source file: ",stdout);
	gets(infname);
	if ((infp=fopen(infname,"r")) == NULL) {
		printf("cannot open source file!\n");
		exit(0);
	}
	printf("Enter name of output file: ");
	gets(outfname);
	/* open file with "bw" to avoid translation of '\n's
	   to \r\n by Megamax library
	*/
	if ((outfp=fopen(outfname,"bw")) == NULL) {
		printf("cannot open output file!\n");
		exit(0);
	}
	n = 0;
	while ((c=getc(infp)) != EOF) {
		/* rest of line after '*' is a comment: */
		if (c == '*') {
			while ((c=getc(infp)) != '\n' && c != EOF);
			continue;
		}
		/* read one or two characters for one output byte: */
		if (ishex(c)) {
			b = hexval(c);
			if ((c=getc(infp)) == EOF)
				break;
			if (ishex(c))
				b = 16*b + hexval(c);
			if (putc(b,outfp) != b) {
				printf("error writing file!\n");
				exit(0);
			}
			n++;
		}
	}
	printf("\nWrote %d bytes.\n", n);
}

/* - Moshe Braner, Cornell, 607-255-3498 */
Technical Details
Message-ID: <398@batcomputer.TN.CORNELL.EDU>
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!gamma!epsilon!zeta!sabre!petrus!bellcore!decvax!tektronix!uw-beaver!bullwinkle!batcomputer!braner
References: <8605162146.AA21671@ucbvax.Berkeley.EDU> <343@batcomputer.TN.CORNELL.EDU>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site batcomputer.TN.CORNELL.EDU
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!gamma!epsilon!zeta!sabre!petrus!bellcore!decvax!tektronix!uw-beaver!bullwinkle!batcomputer!braner
From: braner@batcomputer.TN.CORNELL.EDU (braner)
Newsgroups: net.micro.atari16
Subject: Re: keypad probem ,need vt100 for ST
Message-ID: <398@batcomputer.TN.CORNELL.EDU>
Date: Fri, 6-Jun-86 13:44:03 EDT
Article-I.D.: batcompu.398
Posted: Fri Jun  6 13:44:03 1986
Date-Received: Sun, 8-Jun-86 05:55:50 EDT
References: <8605162146.AA21671@ucbvax.Berkeley.EDU> <343@batcomputer.TN.CORNELL.EDU>
Reply-To: braner@batcomputer.UUCP (braner)
Organization: Theory Center, Cornell University, Ithaca NY
Lines: 64