Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

246 řádky
5.6KB

  1. ; E04-S06: parse statements.n8, execute the code the parser emitted, and
  2. ; report the resulting locals and printed bytes.
  3. ;
  4. ; The fixture runs in the compiler mapping, loads STMTS.N8, parses it with
  5. ; emission on, and JSRs cg_code in place. The emitted body reaches its locals
  6. ; through FRAME_FP, so the fixture points FP at its own buffer. Print calls go
  7. ; through the em_pr_* cells, which the fixture fills with recorders: the test
  8. ; sees exactly which bytes the generated code asked to print, without
  9. ; depending on CHROUT or the screen mapping.
  10. ;
  11. ; Mailbox data: +0 diagnostics, +1 em_bad, +2 a, +3 b, +4 cg_len, +5 cg_err,
  12. ; +6 recorded length. FAIL code is the stage: 1 load, 2 diagnostics, 3 emitter,
  13. ; 4 cg.
  14. ;
  15. ; The frame prologue is not emitted yet, so the fixture owns FP; E04-S07's
  16. ; sizing pass will emit frame_enter with the measured local bytes.
  17. .setcpu "6502"
  18. .include "../../src/common/c128.inc"
  19. .include "../../src/common/mailbox.inc"
  20. .include "../../src/common/formats.inc"
  21. .include "../../src/common/frames.inc"
  22. .import mmu_init, mmu_bank0, mmu_shutdown
  23. .import src_load, src_dos_code, src_kernal_err
  24. .import names_init
  25. .import diag_init, diag_finish, diag_screen
  26. .import parse_file
  27. .import em_on, em_bad, em_pr_text, em_pr_byte, em_pr_cr
  28. .import em_entry
  29. .import cg_code, cg_len, cg_err
  30. ; A conditional branch to a far error path: near branch over an absolute JMP.
  31. .macro ON_ZERO target
  32. beq :+
  33. jmp target
  34. :
  35. .endmacro
  36. .segment "LOADADDR"
  37. .word $1C01
  38. .segment "EXEHDR"
  39. .word basic_end
  40. .word 10
  41. .byte $9E
  42. .byte "7181"
  43. .byte $00
  44. basic_end:
  45. .word $0000
  46. .segment "MAILBOX"
  47. .res MB_SIZE
  48. .segment "STARTUP"
  49. .export test_entry
  50. test_entry:
  51. php
  52. sei
  53. ldx #MB_SIZE - 1
  54. lda #$00
  55. @clr: sta MB_BASE,x
  56. dex
  57. bpl @clr
  58. lda #MB_MAGIC0_VALUE
  59. sta MB_MAGIC0
  60. lda #MB_MAGIC1_VALUE
  61. sta MB_MAGIC1
  62. lda #MB_PROD_COMPILER
  63. sta MB_PRODUCER
  64. lda #MB_ST_RUNNING
  65. sta MB_STATUS
  66. jsr mmu_init
  67. jsr mmu_bank0
  68. lda #<name_src
  69. ldx #>name_src
  70. ldy #name_src_len
  71. jsr src_load
  72. cmp #$00
  73. ON_ZERO @fail_load
  74. jsr names_init
  75. lda #<name_src
  76. ldx #>name_src
  77. ldy #name_src_len
  78. jsr diag_init
  79. lda #$00
  80. sta diag_screen
  81. lda #$01
  82. sta em_on ; pass 2 emits statements
  83. lda #<rec_text ; record what the program prints
  84. sta em_pr_text
  85. lda #>rec_text
  86. sta em_pr_text+1
  87. lda #<rec_byte
  88. sta em_pr_byte
  89. lda #>rec_byte
  90. sta em_pr_byte+1
  91. lda #<rec_cr
  92. sta em_pr_cr
  93. lda #>rec_cr
  94. sta em_pr_cr+1
  95. lda #$00
  96. sta rec_len
  97. jsr parse_file
  98. jsr diag_finish
  99. sta diag_count
  100. lda diag_count
  101. sta MB_DATA+0
  102. lda em_bad
  103. sta MB_DATA+1
  104. lda cg_len
  105. sta MB_DATA+4
  106. lda cg_err
  107. sta MB_DATA+5
  108. lda rec_len
  109. sta MB_DATA+6
  110. lda diag_count
  111. ON_ZERO @fail_diag
  112. lda em_bad
  113. ON_ZERO @fail_emit
  114. lda cg_err
  115. ON_ZERO @fail_cg
  116. lda #<em_fp ; the fixture owns the frame base
  117. sta FRAME_FP
  118. lda #>em_fp
  119. sta FRAME_FP+1
  120. lda #<cg_code ; run the program body, not a class method
  121. clc
  122. adc em_entry
  123. sta run_ptr
  124. lda #>cg_code
  125. adc #$00
  126. sta run_ptr+1
  127. jsr run_entry
  128. lda em_fp - 2 ; a: the first local (FP-2)
  129. sta MB_DATA+2
  130. lda em_fp - 3 ; b: the second local (FP-3)
  131. sta MB_DATA+3
  132. lda rec_len
  133. sta MB_DATA+6
  134. lda #MB_ST_PASS
  135. sta MB_STATUS
  136. jmp @done
  137. @fail_load:
  138. sta MB_DATA+5 ; src_load result
  139. lda src_dos_code
  140. sta MB_DATA+6
  141. lda src_kernal_err
  142. sta MB_DATA+7
  143. lda #1
  144. jmp @fail
  145. @fail_diag:
  146. lda #2
  147. jmp @fail
  148. @fail_emit:
  149. lda #3
  150. jmp @fail
  151. @fail_cg:
  152. lda #4
  153. @fail: sta MB_CODE
  154. lda #$00
  155. sta MB_CODE+1
  156. lda #MB_ST_FAIL
  157. sta MB_STATUS
  158. @done: jsr mmu_shutdown
  159. plp
  160. rts
  161. ; JSR to the address in run_ptr (self-modifying, so a normal RTS returns here).
  162. run_entry:
  163. lda run_ptr
  164. sta @call+1
  165. lda run_ptr+1
  166. sta @call+2
  167. @call: jsr $FFFF
  168. rts
  169. ; ------------------------------------------------------------- recorders
  170. ; A/X = address, Y = length: record the literal bytes.
  171. rec_text:
  172. sta rec_ptr
  173. stx rec_ptr+1
  174. sty rec_cnt
  175. ldy #$00
  176. @loop: cpy rec_cnt
  177. beq @done
  178. lda (rec_ptr),y
  179. sty rec_y
  180. jsr rec_log
  181. ldy rec_y
  182. iny
  183. bne @loop
  184. @done: rts
  185. ; A = byte value: record $FF and the value, so a value print is distinct from
  186. ; text.
  187. rec_byte:
  188. pha
  189. lda #$FF
  190. jsr rec_log
  191. pla
  192. jmp rec_log
  193. ; A newline follows every print statement.
  194. rec_cr:
  195. lda #$0D
  196. jmp rec_log
  197. ; A = byte to append.
  198. rec_log:
  199. ldy rec_len
  200. cpy #32
  201. bcs @full
  202. sta rec_buf,y
  203. inc rec_len
  204. @full: rts
  205. .segment "ZEROPAGE"
  206. rec_ptr: .res 2
  207. run_ptr: .res 2
  208. .segment "RODATA"
  209. name_src: .byte "STMTS.N8"
  210. name_src_len = * - name_src
  211. .segment "BSS"
  212. diag_count: .res 1
  213. rec_cnt: .res 1
  214. rec_y: .res 1
  215. .export rec_len
  216. rec_len: .res 1
  217. .export rec_buf
  218. rec_buf: .res 32
  219. em_frame: .res 128
  220. em_fp = em_frame + 64
  221. .export em_fp

Powered by TurnKey Linux.