2 2 REM This program reads an Intel-format hex file and checks it for validity.
3 3 REM It discards blank lines, and if it finds any other lines that are bad,
4 4 REM either bacause the format is wrong or the checksum doesn't agree, it
5 5 REM prompts you to type in a replacement line. Use this program to fix
6 6 REM hex files you have downloaded using a non-error-correcting method.
7 7 REM Written by F. da Cruz & C. Gianone, Columbia University, April 1986.
8 8 REM Used with success on Vector Graphic Model 3 CP/M-80 system.
10 100 ON ERROR GOTO 9000
11 200 INPUT;"Input hex file "; F$
14 500 INPUT;"Output hex file"; O$
18 900 REM Loop at 1000 for each line, B, of the input hex file, then...
19 901 REM Discard blank lines.
20 902 REM Look for colon that begins hex record
21 903 REM Decode rest of record...
22 904 REM L = length of rest, in bytes (not hex characters!), 1 byte
23 905 REM N = address, 2 bytes
24 906 REM T = record type, 0 = data, 1 = EOF
25 907 REM C% = 1-byte checksum
26 908 REM Record has negative of actual checksum, adding to C% should give 0.
27 909 REM Subroutine at 8000 converts pair of hex nibbles to 8-bit byte.
29 1000 LINE INPUT #1, A$
31 1015 IF A$ = "" THEN GOTO 1000
32 1020 IF LEFT$(A$,1) = ":" THEN GOTO 2000
33 1030 X = INSTR(2,A$,":")
34 1033 IF X < 1 THEN GOTO 1040
35 1035 A$ = MID$(A$,X,LEN(A$)-X+1)
37 1040 PRINT "Line";B;"has no colon"
41 2010 X$ = MID$(A$,2,2)
44 2040 X$ = MID$(A$,4,2)
47 2070 X$ = MID$(A$,6,2)
50 2100 X$ = MID$(A$,8,2)
53 2125 IF T = 1 THEN PRINT "End of";F$;"at line";B : GOTO 9000
54 2130 IF T <> 0 THEN PRINT "Invalid record type"; T : GOTO 3070
56 3000 X$ = MID$(A$,M,2)
60 3020 IF L > 0 THEN GOTO 3000
61 3030 X$ = MID$(A$,M,2)
63 3060 IF (C% AND 255) = 0 THEN GOTO 3100
64 3065 PRINT "Bad Checksum"
66 3075 PRINT "Bad: "; A$
71 7999 REM Subroutine to convert pair of hex nibbles to one 8-bit byte.
72 8000 I = ASC(LEFT$(X$,1))
74 8010 IF I > 64 AND I < 71 THEN I = I - 7
75 8020 IF I < 48 OR I > 63 THEN K = -1
76 8030 J = ASC(MID$(X$,2,1))
77 8040 IF J > 64 AND J < 71 THEN J = J - 7
78 8050 IF J < 48 OR J > 63 THEN K = -1
79 8060 IF K < 0 THEN RETURN
80 8070 K = 16 * (I - 48) + J - 48
83 8999 Program exit and error handler
87 9030 PRINT "Records processed:";B