You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

347 lines
8.0KB

  1. ; E02-S01: source-reader test in x128.
  2. ;
  3. ; Loads each fixture from drive 8 with src_load. For a successful load it
  4. ; replays the source twice (src_rewind + src_next_line) and records the line
  5. ; count and a Fletcher-16 checksum of the delivered lines, each terminated by
  6. ; $0D. For a failed load it records the error and checks that no source
  7. ; survives. Every record is 16 bytes in `results`:
  8. ; +0 result code +1 DOS status code +2 KERNAL error
  9. ; +3 error line (2) +5 error column +6 LDTND after src_load
  10. ; +7 lines (2) +9 src_len (2) +11 Fletcher s1, +12 s2
  11. ; +13 flag: OK -> both passes identical; error -> next_line gave EOF
  12. ; +14 src_line_no after the last line (2)
  13. ; Mailbox: PASS when every result code matches its expectation and every
  14. ; flag is 1; MB_DATA+0 = fixture count, MB_DATA+1/2 = address of results.
  15. ; The host checks every other field against values it computes itself.
  16. .setcpu "6502"
  17. .include "../../src/common/c128.inc"
  18. .include "../../src/common/mailbox.inc"
  19. .include "../../src/common/source.inc"
  20. .import mmu_init, mmu_bank0, mmu_shutdown, kcall_inline
  21. .import src_load, src_rewind, src_next_line
  22. .import src_line, src_line_len, src_line_no, src_len
  23. .import src_err_line, src_err_col, src_kernal_err, src_dos_code
  24. .import __COMPILER_ZP_PAGE__
  25. REC_SIZE = 16
  26. .segment "LOADADDR"
  27. .word $1C01
  28. .segment "EXEHDR"
  29. .word basic_end
  30. .word 10
  31. .byte $9E
  32. .byte "7181"
  33. .byte $00
  34. basic_end:
  35. .word $0000
  36. .segment "MAILBOX"
  37. .res MB_SIZE
  38. .segment "ZEROPAGE"
  39. fx_ptr: .res 2 ; current fixture table entry
  40. rec_ptr: .res 2 ; current result record
  41. .segment "STARTUP"
  42. .export test_entry, results
  43. test_entry:
  44. php
  45. sei
  46. ldx #MB_SIZE - 1
  47. lda #$00
  48. @clr: sta MB_BASE,x
  49. dex
  50. bpl @clr
  51. lda #MB_MAGIC0_VALUE
  52. sta MB_MAGIC0
  53. lda #MB_MAGIC1_VALUE
  54. sta MB_MAGIC1
  55. lda #MB_PROD_PLATFORM
  56. sta MB_PRODUCER
  57. lda #MB_ST_RUNNING
  58. sta MB_STATUS
  59. jsr mmu_init
  60. jsr mmu_bank0
  61. lda #$00
  62. sta failures
  63. sta fx_index
  64. lda #<fixtures
  65. sta fx_ptr
  66. lda #>fixtures
  67. sta fx_ptr+1
  68. lda #<results
  69. sta rec_ptr
  70. lda #>results
  71. sta rec_ptr+1
  72. @next: ldy #0 ; entry: name lo, name hi, length, expected
  73. lda (fx_ptr),y
  74. sta name_lo
  75. iny
  76. lda (fx_ptr),y
  77. sta name_hi
  78. iny
  79. lda (fx_ptr),y
  80. sta name_len
  81. iny
  82. lda (fx_ptr),y
  83. sta expected
  84. jsr run_fixture
  85. clc
  86. lda fx_ptr
  87. adc #4
  88. sta fx_ptr
  89. bcc :+
  90. inc fx_ptr+1
  91. : clc
  92. lda rec_ptr
  93. adc #REC_SIZE
  94. sta rec_ptr
  95. bcc :+
  96. inc rec_ptr+1
  97. : inc fx_index
  98. lda fx_index
  99. cmp #FIXTURE_COUNT
  100. bne @next
  101. jsr mmu_shutdown
  102. lda #FIXTURE_COUNT
  103. sta MB_DATA+0
  104. lda #<results
  105. sta MB_DATA+1
  106. lda #>results
  107. sta MB_DATA+2
  108. lda failures
  109. sta MB_CODE
  110. ldy #ok_msg - messages
  111. lda failures
  112. bne @fail
  113. lda #MB_ST_PASS
  114. bne @report
  115. @fail: ldy #fail_msg - messages
  116. lda #MB_ST_FAIL
  117. @report:
  118. sta MB_STATUS
  119. plp
  120. @print: lda messages,y
  121. beq @end
  122. sty print_y
  123. jsr CHROUT
  124. ldy print_y
  125. iny
  126. bne @print
  127. @end: rts
  128. .segment "CODE"
  129. ; Load one fixture and fill its record (rec_ptr).
  130. run_fixture:
  131. ldx #REC_SIZE - 1
  132. lda #$00
  133. @zero: sta record,x
  134. dex
  135. bpl @zero
  136. jsr show_name
  137. lda name_lo
  138. ldx name_hi
  139. ldy name_len
  140. jsr src_load
  141. sta record+0
  142. lda src_dos_code
  143. sta record+1
  144. lda src_kernal_err
  145. sta record+2
  146. lda src_err_line
  147. sta record+3
  148. lda src_err_line+1
  149. sta record+4
  150. lda src_err_col
  151. sta record+5
  152. lda __COMPILER_ZP_PAGE__ * 256 + LDTND ; system ZP via the swap
  153. sta record+6
  154. lda src_len
  155. sta record+9
  156. lda src_len+1
  157. sta record+10
  158. lda record+0
  159. bne @failed
  160. jsr replay ; pass A
  161. lda count
  162. sta record+7
  163. lda count+1
  164. sta record+8
  165. lda s1
  166. sta record+11
  167. lda s2
  168. sta record+12
  169. lda src_line_no
  170. sta record+14
  171. lda src_line_no+1
  172. sta record+15
  173. jsr replay ; pass B must match exactly
  174. lda count
  175. cmp record+7
  176. bne @check
  177. lda count+1
  178. cmp record+8
  179. bne @check
  180. lda s1
  181. cmp record+11
  182. bne @check
  183. lda s2
  184. cmp record+12
  185. bne @check
  186. inc record+13
  187. bne @check
  188. @failed:
  189. jsr src_rewind ; nothing may be delivered after a failure
  190. jsr src_next_line
  191. bcc @check
  192. inc record+13
  193. @check: lda record+0
  194. cmp expected
  195. bne @bad
  196. lda record+13
  197. cmp #$01
  198. beq @store
  199. @bad: inc failures
  200. @store: ldy #REC_SIZE - 1
  201. @copy: lda record,y
  202. sta (rec_ptr),y
  203. dey
  204. bpl @copy
  205. lda record+0
  206. ora #'0'
  207. jsr kcall_inline
  208. .word CHROUT
  209. lda #$0D
  210. jsr kcall_inline
  211. .word CHROUT
  212. rts
  213. ; One pass over the source: count lines, Fletcher-16 over line bytes + $0D.
  214. replay: lda #$00
  215. sta count
  216. sta count+1
  217. sta s1
  218. sta s2
  219. jsr src_rewind
  220. @line: jsr src_next_line
  221. bcs @done
  222. inc count
  223. bne :+
  224. inc count+1
  225. : ldy #$00
  226. @byte: cpy src_line_len
  227. beq @eol
  228. lda src_line,y
  229. jsr fletcher
  230. iny
  231. bne @byte
  232. @eol: lda #SRC_EOL
  233. jsr fletcher
  234. jmp @line
  235. @done: rts
  236. ; s1 = (s1 + A) mod 255; s2 = (s2 + s1) mod 255. Preserves Y.
  237. fletcher:
  238. clc
  239. adc s1
  240. adc #$00 ; end-around carry: 256 = 1 (mod 255)
  241. cmp #$FF
  242. bne :+
  243. lda #$00
  244. : sta s1
  245. clc
  246. adc s2
  247. adc #$00
  248. cmp #$FF
  249. bne :+
  250. lda #$00
  251. : sta s2
  252. rts
  253. show_name:
  254. ldy #$00
  255. @ch: cpy name_len
  256. beq @sp
  257. lda name_lo
  258. sta @rd+1
  259. lda name_hi
  260. sta @rd+2
  261. @rd: lda $FFFF,y ; patched
  262. sty print_y
  263. jsr kcall_inline
  264. .word CHROUT
  265. ldy print_y
  266. iny
  267. bne @ch
  268. @sp: lda #' '
  269. jsr kcall_inline
  270. .word CHROUT
  271. rts
  272. .segment "RODATA"
  273. ; name address, name length, expected result code
  274. fixtures:
  275. .word f_decls
  276. .byte f_decls_end - f_decls, SRC_OK
  277. .word f_nofinal
  278. .byte f_nofinal_end - f_nofinal, SRC_OK
  279. .word f_edge
  280. .byte f_edge_end - f_edge, SRC_OK
  281. .word f_longln
  282. .byte f_longln_end - f_longln, SRC_ERR_LINE_TOO_LONG
  283. .word f_manyln
  284. .byte f_manyln_end - f_manyln, SRC_ERR_TOO_MANY_LINES
  285. .word f_big
  286. .byte f_big_end - f_big, SRC_ERR_FILE_TOO_LARGE
  287. .word f_missing
  288. .byte f_missing_end - f_missing, SRC_ERR_DISK
  289. .word f_decls
  290. .byte f_decls_end - f_decls, SRC_OK ; again, after failures
  291. FIXTURE_COUNT = (* - fixtures) / 4
  292. ; Unshifted PETSCII letters ($41-$5A) are what c1541 stores for lowercase.
  293. f_decls: .byte "DECLS.N8"
  294. f_decls_end:
  295. f_nofinal: .byte "NOFINAL.N8"
  296. f_nofinal_end:
  297. f_edge: .byte "EDGE.N8"
  298. f_edge_end:
  299. f_longln: .byte "LONGLN.N8"
  300. f_longln_end:
  301. f_manyln: .byte "MANYLN.N8"
  302. f_manyln_end:
  303. f_big: .byte "BIG.N8"
  304. f_big_end:
  305. f_missing: .byte "MISSING.N8"
  306. f_missing_end:
  307. messages:
  308. ok_msg: .byte "NOVA128 SOURCE TEST OK", $0D, $00
  309. fail_msg: .byte "NOVA128 SOURCE TEST FAIL", $0D, $00
  310. .segment "BSS"
  311. results: .res REC_SIZE * FIXTURE_COUNT
  312. record: .res REC_SIZE
  313. failures: .res 1
  314. fx_index: .res 1
  315. name_lo: .res 1
  316. name_hi: .res 1
  317. name_len: .res 1
  318. expected: .res 1
  319. count: .res 2
  320. s1: .res 1
  321. s2: .res 1
  322. print_y: .res 1

Powered by TurnKey Linux.