1 REM HEX2RAM.BAS
10 STRING 82, 80:DIM HI(70):DIM LOW(70)
15 FOR I=48 TO 57:HI(I)=(I-48)*16:LOW(I)=I-48:NEXT
25 FOR I=65 TO 70:HI(I)=(I-55)*16:LOW(I)=I-55:NEXT
35 PRINT "INTEL HEX FILE TO RAM LOADING PROGRAM V1.1"
45 PRINT "Copyright 1991 Systronix Inc. All rights reserved."
55 PRINT "This program accepts as input an Intel hex file and stores"
65 PRINT "it in external RAM at the addresses specified in the HEX file"
75 PRINT "Ready to receive the input file one line at a time. Set your"
85 PRINT "communication software to send a line when it receives"
95 PRINT "the '>' prompt.":PRINT
100 LINE=LINE+1:INPUT ">",$(0):PRINT"Validating and storing...",
105 C=ASC($(0),1):IF C<>58 THEN GOTO 500
REM Get the byte count and save it in the variable COUNT
115 I=2:GOSUB 700:COUNT=CH
REM Get the starting address for this record's data
125 FOR I=4 TO 7 STEP 2:GOSUB 700:ADDR=(ADDR*256)+ CH:NEXT
REM Get the record type (we only understand types 0 and 1)
135 I=8:GOSUB 700:IF (CH <>0 .AND. CH <>1) THEN GOTO 510
145 RECORD=CH
REM The initial checksum calculation
155 CHECK=(ADDR/256)+(ADDR.AND.0FFH)+COUNT+RECORD
REM Get the individual bytes, accumulate them in the check sum and store
REM them in memory at the appropriate destination
165 FOR I=10 TO 10+(COUNT*2) STEP 2:GOSUB 700
REM Here we deal with the data bytes (not executed when RECORD is type 1)
175 CHECK=CHECK+CH
185 IF RECORD=1 THEN GOTO 210
REM Store the data in RAM
195 XBY(ADDR)=CH
205 if CBY(ADDR)<>CH THEN GOTO 550 ELSE ADDR=ADDR+1:NEXT
210 CHECK=CHECK.AND.0FFH:IF CHECK<>0 THEN GOTO 520
215 IF RECORD=1 THEN GOTO 640
REM Reset and continue
225 ADDR=0:PRINT CR:GOTO 100
REM Error messages and program termination
500 PRINT CR, "Line ", LINE, ": Character", I, "unexpected":GOTO 600
510 PRINT CR, "Line ", LINE, ": Unknown record type", CH:GOTO 600
520 PRINT CR, "Line ", LINE, ": Checksum failure. Expected",
525 PH0. ABS(CHECK-CH):GOTO 600
550 PRINT CR, "Line", LINE, ": Verify error at address",:PH0. ADDR
555 PH0. "The byte at", addr, " is", CBY(ADDR)
565 PH0. "The byte should be", CH:GOTO 600
600 PRINT "Stop sending input file. Type a CONTROL+C to quit."
605 GOTO 605
REM Normal program exit point
640 PRINT CR, "Received an End record in line",LINE:END
REM Convert the ASCII text to numbers
700 C=ASC($(0),I):CH=HI(C):C=ASC($(0),I+1):CH=CH+LOW(C)
705 RETURN
