home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / a / cpkhex.bas < prev    next >
BASIC Source File  |  2020-01-01  |  3KB  |  89 lines

  1. 1 REM -- CP4HEX.BAS --
  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.
  9. 9 REM
  10. 100  ON ERROR GOTO 9000
  11. 200  INPUT;"Input hex file "; F$
  12. 300  PRINT
  13. 400  OPEN "I",#1,F$
  14. 500  INPUT;"Output hex file"; O$
  15. 600  PRINT
  16. 700  OPEN "O",#2,O$
  17. 800  B = 0
  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.
  28. 910  REM
  29. 1000 LINE INPUT #1, A$
  30. 1010 B = B + 1
  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)
  36. 1037 GOTO 2000
  37. 1040 PRINT "Line";B;"has no colon"
  38. 1060 GOTO 3070
  39. 2000 C% = 0
  40. 2005 PRINT ".";
  41. 2010 X$ = MID$(A$,2,2)
  42. 2020 GOSUB 8000
  43. 2030 L = K
  44. 2040 X$ = MID$(A$,4,2)
  45. 2050 GOSUB 8000
  46. 2060 N = K
  47. 2070 X$ = MID$(A$,6,2)
  48. 2080 GOSUB 8000
  49. 2090 N = 256 * N + K
  50. 2100 X$ = MID$(A$,8,2)
  51. 2110 GOSUB 8000
  52. 2120 T = K
  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
  55. 2140 M = 10
  56. 3000 X$ = MID$(A$,M,2)
  57. 3002 GOSUB 8000
  58. 3005 M = M + 2
  59. 3010 L = L - 1
  60. 3020 IF L > 0 THEN GOTO 3000
  61. 3030 X$ = MID$(A$,M,2)
  62. 3050 GOSUB 8000
  63. 3060 IF (C% AND 255) = 0 THEN GOTO 3100
  64. 3065 PRINT "Bad Checksum"
  65. 3070 PRINT "Line";B
  66. 3075 PRINT "Bad: "; A$
  67. 3080 INPUT "New  "; A$
  68. 3090 PRINT
  69. 3100 PRINT #2,A$
  70. 4000 GOTO 1000
  71. 7999 REM Subroutine to convert pair of hex nibbles to one 8-bit byte.
  72. 8000 I = ASC(LEFT$(X$,1))
  73. 8005 K = 0
  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
  81. 8080 C% = C% + K
  82. 8099 RETURN
  83. 8999 Program exit and error handler
  84. 9000 CLOSE #1
  85. 9010 CLOSE #2
  86. 9020 CLOSE
  87. 9030 PRINT "Records processed:";B
  88. 9999 END
  89.