hexsave.z80 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. ; title Save Intel HEX to file -jcw, 2017-03-18
  2. ; Usage: hexsave myfile.dat
  3. ;
  4. ; Sample data:
  5. ;
  6. ; :2000000021CC013E3CCDC001CDB101FE3A20F9CD8D01474FCD8D01CD8D01CD8D01FE0128F1
  7. ; :2000200018CD8D01772310F9CD8D0179ED443E2B28D332CB013E3F18CCCD8D013ACB01B7CA
  8. ; :200040003E2D203D11B3FE19CB15CB1444C53E3ECDC0010E13CD87010E16CD8701AF327CDF
  9. ; :200060000021CC01C1C5E5EB0E1ACD05000E15CD8701E1C11180001910EB0E10CD87013ED2
  10. ; :2000800021CDC001C30000115C00C30500D5CDA401CB07CB07CB07CB0757CDA401B2D1F5E9
  11. ; :2000A000814FF1C9CDB101FE40FAAE01D607E60FC9C5E51EFF0E06CD0500B728F6E1C1C9C8
  12. ; :2000C000C5E55F0E02CD0500E1C1C9000000000000000000000000000000000000000000CA
  13. ; :2000E000000000000000000000000000000000000000000000000000000000000000000000
  14. ; :00000001FF
  15. WSTART: equ 0000h
  16. BDOS: equ 0005h
  17. FCB: equ 005Ch
  18. CONINP: equ 1
  19. CONOUT: equ 2
  20. CONIO: equ 6
  21. PSTRING:equ 9
  22. CLOSEF: equ 16
  23. DELF: equ 19
  24. WRITES: equ 21
  25. MAKEF: equ 22
  26. SETDMA: equ 26
  27. org 100h
  28. ld hl,buf
  29. ld a,'<'
  30. prompt: call putch
  31. skip: call getch
  32. cp ':'
  33. jr nz,skip
  34. call getbyte
  35. ld b,a ; length
  36. ld c,a ; running checksum
  37. call getbyte ; ignore addr hi
  38. call getbyte ; ignore addr lo
  39. call getbyte ; record type
  40. cp 1 ; eof marker?
  41. jr z, done
  42. ld a,b ; 0-length record also marks end
  43. or a
  44. jr z,done
  45. loop: call getbyte
  46. ld (hl),a
  47. inc hl
  48. djnz loop
  49. call getbyte ; checksum
  50. ld a,c
  51. neg
  52. ld a,'+'
  53. jr z,prompt
  54. ld (error),a
  55. ld a,'?'
  56. jr prompt
  57. done: call getbyte
  58. ld a,(error)
  59. or a
  60. ld a,'-'
  61. jr nz,quit
  62. ld de,127-buf ; round up to a multiple of 128
  63. add hl,de
  64. rl l
  65. rl h
  66. ld b,h ; max 256 sect, i.e. 32 KB data
  67. push bc
  68. ld a,'>'
  69. call putch
  70. ld c,DELF
  71. call fileop
  72. ld c,MAKEF
  73. call fileop
  74. xor a
  75. ld (FCB+32),a
  76. ld hl,buf
  77. pop bc
  78. sloop: push bc
  79. push hl
  80. ex de,hl
  81. ld c,SETDMA
  82. call BDOS
  83. ld c,WRITES
  84. call fileop
  85. pop hl
  86. pop bc
  87. ld de,128
  88. add hl,de
  89. djnz sloop
  90. ld c,CLOSEF
  91. call fileop
  92. ld a,'!'
  93. quit: call putch
  94. jp WSTART
  95. fileop: ld de,FCB
  96. jp BDOS
  97. getbyte:push de
  98. call gethex
  99. rlc a
  100. rlc a
  101. rlc a
  102. rlc a
  103. ld d,a
  104. call gethex
  105. or d
  106. pop de
  107. push af
  108. add c ; update checksum
  109. ld c,a
  110. pop af
  111. ret
  112. gethex: call getch
  113. cp '@'
  114. jp m,gh1 ; jr c,gh1 ?????
  115. sub 7
  116. gh1: and 0Fh
  117. ret
  118. getch: push bc
  119. push hl
  120. gc1: ld e,0FFh ; no echo
  121. ld c,CONIO
  122. call BDOS
  123. or a
  124. jr z,gc1
  125. pop hl
  126. pop bc
  127. ret
  128. putch: push bc
  129. push hl
  130. ld e,a
  131. ld c,CONOUT
  132. call BDOS
  133. pop hl
  134. pop bc
  135. ret
  136. error: db 0
  137. buf: equ $
  138. end