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.

322 line
6.7KB

  1. ; E02-S03: name-table test in x128.
  2. ;
  3. ; For each fixture: src_load, names_init, then lex to EOF. Every identifier is
  4. ; interned; when the previous token is class/interface/program/method/var it
  5. ; is also declared. The dump records, per identifier:
  6. ; $01 id use $02 id declaration $03 code error
  7. ; then at EOF: $FD, names_count, guard flag (1 = guard bytes intact), and
  8. ; for each ID 1..count: flags, length, spelling bytes.
  9. ; Fixture header: $FF, index, src_load result. End of dump: $FE.
  10. ; The guard is 8 bytes of bank-1 TABLES placed directly after the name table
  11. ; (this module links after names.s), filled with $A5 before every fixture.
  12. ; Mailbox: MB_DATA+0/1 dump address, +2/3 length; PASS = loads ok, no overflow.
  13. .setcpu "6502"
  14. .include "../../src/common/c128.inc"
  15. .include "../../src/common/mailbox.inc"
  16. .include "../../src/common/tokens.inc"
  17. .include "../../src/common/names.inc"
  18. .import mmu_init, mmu_bank0, mmu_shutdown, mmu_peek1, mmu_poke1
  19. .importzp mmu_ptr
  20. .import src_load
  21. .import lex_reset, lex_next, tok_kind, tok_col, tok_len
  22. .import names_init, name_intern, name_declare, name_get, names_count
  23. .import name_out, name_out_len, name_out_flags
  24. DUMP_SIZE = $3000
  25. GUARD_SIZE = 8
  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. dump_ptr: .res 2
  40. fx_ptr: .res 2
  41. .segment "TABLES"
  42. guard: .res GUARD_SIZE
  43. .segment "STARTUP"
  44. .export test_entry, dump, guard
  45. test_entry:
  46. php
  47. sei
  48. ldx #MB_SIZE - 1
  49. lda #$00
  50. @clr: sta MB_BASE,x
  51. dex
  52. bpl @clr
  53. lda #MB_MAGIC0_VALUE
  54. sta MB_MAGIC0
  55. lda #MB_MAGIC1_VALUE
  56. sta MB_MAGIC1
  57. lda #MB_PROD_PLATFORM
  58. sta MB_PRODUCER
  59. lda #MB_ST_RUNNING
  60. sta MB_STATUS
  61. jsr mmu_init
  62. jsr mmu_bank0
  63. lda #<dump
  64. sta dump_ptr
  65. lda #>dump
  66. sta dump_ptr+1
  67. lda #<fixtures
  68. sta fx_ptr
  69. lda #>fixtures
  70. sta fx_ptr+1
  71. lda #$00
  72. sta failures
  73. sta overflow
  74. sta fx_index
  75. @fixture:
  76. lda #$FF
  77. jsr emit
  78. lda fx_index
  79. jsr emit
  80. ldy #0
  81. lda (fx_ptr),y
  82. sta name_lo
  83. iny
  84. lda (fx_ptr),y
  85. tax
  86. iny
  87. lda (fx_ptr),y
  88. tay
  89. lda name_lo
  90. jsr src_load
  91. pha
  92. jsr emit
  93. pla
  94. beq @run
  95. inc failures
  96. jmp @advance
  97. @run: jsr run_fixture
  98. @advance:
  99. clc
  100. lda fx_ptr
  101. adc #3
  102. sta fx_ptr
  103. bcc :+
  104. inc fx_ptr+1
  105. : inc fx_index
  106. lda fx_index
  107. cmp #FIXTURE_COUNT
  108. bne @fixture
  109. lda #$FE
  110. jsr emit
  111. lda #<dump ; report while the private ZP is mapped
  112. sta MB_DATA+0
  113. lda #>dump
  114. sta MB_DATA+1
  115. sec
  116. lda dump_ptr
  117. sbc #<dump
  118. sta MB_DATA+2
  119. lda dump_ptr+1
  120. sbc #>dump
  121. sta MB_DATA+3
  122. jsr mmu_shutdown
  123. lda failures
  124. ora overflow
  125. sta MB_CODE
  126. ldy #ok_msg - messages
  127. lda MB_CODE
  128. bne @fail
  129. lda #MB_ST_PASS
  130. bne @report
  131. @fail: ldy #fail_msg - messages
  132. lda #MB_ST_FAIL
  133. @report:
  134. sta MB_STATUS
  135. plp
  136. @print: lda messages,y
  137. beq @end
  138. sty print_y
  139. jsr CHROUT
  140. ldy print_y
  141. iny
  142. bne @print
  143. @end: rts
  144. .segment "CODE"
  145. run_fixture:
  146. jsr names_init
  147. jsr set_guard_ptr
  148. ldy #GUARD_SIZE - 1
  149. @fill: lda #$A5
  150. jsr mmu_poke1
  151. dey
  152. bpl @fill
  153. jsr lex_reset
  154. lda #TOK_EOL
  155. sta prev_kind
  156. @token: jsr lex_next
  157. lda tok_kind
  158. cmp #TOK_EOF
  159. beq @eof
  160. cmp #TOK_IDENT
  161. bne @remember
  162. lda tok_col
  163. ldx tok_len
  164. jsr name_intern
  165. bcc @interned
  166. pha
  167. lda #$03
  168. jsr emit
  169. pla
  170. jsr emit
  171. jmp @remember
  172. @interned:
  173. sta last_id
  174. jsr is_declaration
  175. bcs @declare
  176. lda #$01
  177. jsr emit
  178. lda last_id
  179. jsr emit
  180. jmp @remember
  181. @declare:
  182. lda last_id
  183. ldx tok_len
  184. ldy tok_col
  185. jsr name_declare
  186. lda #$02
  187. jsr emit
  188. lda last_id
  189. jsr emit
  190. @remember:
  191. lda tok_kind
  192. sta prev_kind
  193. jmp @token
  194. @eof: lda #$FD
  195. jsr emit
  196. lda names_count
  197. jsr emit
  198. jsr set_guard_ptr ; guard intact?
  199. ldy #GUARD_SIZE - 1
  200. lda #$01
  201. sta guard_ok
  202. @check: jsr mmu_peek1
  203. cmp #$A5
  204. beq :+
  205. lda #$00
  206. sta guard_ok
  207. : dey
  208. bpl @check
  209. lda guard_ok
  210. jsr emit
  211. lda #$01
  212. sta last_id
  213. @names: lda last_id
  214. cmp names_count
  215. beq :+
  216. bcs @done
  217. : jsr name_get
  218. lda name_out_flags
  219. jsr emit
  220. lda name_out_len
  221. jsr emit
  222. ldx #$00
  223. @spell: cpx name_out_len
  224. beq @next
  225. lda name_out,x
  226. stx emit_x
  227. jsr emit
  228. ldx emit_x
  229. inx
  230. bne @spell
  231. @next: inc last_id
  232. bne @names ; IDs stop at 255, so this always loops
  233. @done: rts
  234. ; C=1 when the previous token introduces a declaration name.
  235. is_declaration:
  236. lda prev_kind
  237. ldx #decl_count - 1
  238. @find: cmp decl_kinds,x
  239. beq @yes
  240. dex
  241. bpl @find
  242. clc
  243. rts
  244. @yes: sec
  245. rts
  246. set_guard_ptr:
  247. lda #<guard
  248. sta mmu_ptr
  249. lda #>guard
  250. sta mmu_ptr+1
  251. rts
  252. emit: ldy dump_ptr+1
  253. cpy #>(dump + DUMP_SIZE)
  254. bcc @room
  255. lda #$01
  256. sta overflow
  257. rts
  258. @room: sty emit_y
  259. ldy #$00
  260. sta (dump_ptr),y
  261. ldy emit_y
  262. inc dump_ptr
  263. bne :+
  264. inc dump_ptr+1
  265. : rts
  266. .segment "RODATA"
  267. decl_kinds:
  268. .byte KW_CLASS, KW_INTERFACE, KW_PROGRAM, KW_METHOD, KW_VAR
  269. decl_count = * - decl_kinds
  270. fixtures:
  271. .macro FIXTURE name
  272. .local text, done
  273. .word text
  274. .byte done - text
  275. .pushseg
  276. .segment "DATA"
  277. text: .byte name
  278. done:
  279. .popseg
  280. .endmacro
  281. FIXTURE "NAMES.N8"
  282. FIXTURE "COLLIDE.N8"
  283. FIXTURE "FULL.N8"
  284. FIXTURE_COUNT = 3
  285. messages:
  286. ok_msg: .byte "NOVA128 NAMES TEST OK", $0D, $00
  287. fail_msg: .byte "NOVA128 NAMES TEST FAIL", $0D, $00
  288. .segment "BSS"
  289. failures: .res 1
  290. overflow: .res 1
  291. fx_index: .res 1
  292. name_lo: .res 1
  293. prev_kind: .res 1
  294. last_id: .res 1
  295. guard_ok: .res 1
  296. emit_x: .res 1
  297. emit_y: .res 1
  298. print_y: .res 1
  299. dump: .res DUMP_SIZE

Powered by TurnKey Linux.