Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!mit-eddie!ll-xn!ames!ucbcad!ucbvax!BLIULG12.BITNET!UZ32112 From: UZ32112@BLIULG12.BITNET (Andre PIRARD) Newsgroups: comp.os.cpm Subject: Re: Details of Intel Hex format Message-ID: <8709291725.AA21503@ucbvax.Berkeley.EDU> Date: Tue, 29-Sep-87 13:26:44 EDT Article-I.D.: ucbvax.8709291725.AA21503 Posted: Tue Sep 29 13:26:44 1987 Date-Received: Thu, 1-Oct-87 04:17:33 EDT Sender: daemon@ucbvax.BERKELEY.EDU Distribution: world Organization: The ARPA Internet Lines: 58 Here is an algorithm for Intel Hex files generation: \ COMHEX: produce .HEX file out of .COM file HEX 100 CONSTANT START \ input file starting address, 100 specific for CP/M & MSDOS 10 CONSTANT SLICE \ max number of bytes in one HEX line VARIABLE CHECKSUM \ output record checksum VARIABLE ADDRESS \ running address VARIABLE IFILE \ pointer to input file VARIABLE OFILE \ pointer to output file : ASK.FILENAME \ prompt-addr id-count pointer -- fname-addr fname-count fcba >R FCBSIZE RESERVE R@ ! \ get fcb storage, set pointer CR TYPE SPACE QUERY "TOKEN \ issue prompt, input filename R> @ ; \ return filename and fcb address : CLOSE.FILE \ pointer -- @ CLOSE CLOSED? FCBSIZE FREE ; : PUT.CHAR \ char -- \ write one character to output file OFILE @ PUT ; : PUT.BYTE \ byte -- \ write 2 hex digits, compute checksum DUP CHECKSUM -! 0 <# # # #> OFILE @ WRITE ; : PUT.WORD \ word -- \ write 4 hex digits, compute checksum DUP -8 SHIFT PUT.BYTE FF AND PUT.BYTE ; : COMHEX \ main word HEX \ all stuff done in hexadecimal " INPUT FILE?:" IFILE ASK.FILENAME OPENI OPEN? \ open input " OUTPUT FILE?:" OFILE ASK.FILENAME OPENO OPEN? \ and output CR START ADDRESS ! \ init address pointer BEGIN IFILE @ INDATA WHILE \ loop until at end-of-file ASCII : PUT.CHAR \ record mark CHECKSUM OFF \ new checksum for new record PAD SLICE IFILE @ READ \ read up to SLICE bytes DUP PUT.BYTE \ output byte count ADDRESS @ PUT.WORD \ output bytes address 0 PUT.BYTE \ plus one more byte DUP ADDRESS +! \ progress address PAD SWAP BOUNDS ?DO \ loop for each byte read I C@ PUT.BYTE LOOP \ and output it with checksum CHECKSUM @ PUT.BYTE \ output checksum OFILE @ PUTEOR \ put end-of-record mark REPEAT ASCII : PUT.CHAR 0 PUT.WORD \ add end-of-file record 0 PUT.WORD 0 PUT.BYTE OFILE @ PUTEOR OFILE @ PUTEOF \ put end-of-file mark OFILE CLOSE.FILE IFILE CLOSE.FILE ; DECIMAL