Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

228 строки
5.2KB

  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 cg_code, cg_len, cg_err
  29. ; A conditional branch to a far error path: near branch over an absolute JMP.
  30. .macro ON_ZERO target
  31. beq :+
  32. jmp target
  33. :
  34. .endmacro
  35. .segment "LOADADDR"
  36. .word $1C01
  37. .segment "EXEHDR"
  38. .word basic_end
  39. .word 10
  40. .byte $9E
  41. .byte "7181"
  42. .byte $00
  43. basic_end:
  44. .word $0000
  45. .segment "MAILBOX"
  46. .res MB_SIZE
  47. .segment "STARTUP"
  48. .export test_entry
  49. test_entry:
  50. php
  51. sei
  52. ldx #MB_SIZE - 1
  53. lda #$00
  54. @clr: sta MB_BASE,x
  55. dex
  56. bpl @clr
  57. lda #MB_MAGIC0_VALUE
  58. sta MB_MAGIC0
  59. lda #MB_MAGIC1_VALUE
  60. sta MB_MAGIC1
  61. lda #MB_PROD_COMPILER
  62. sta MB_PRODUCER
  63. lda #MB_ST_RUNNING
  64. sta MB_STATUS
  65. jsr mmu_init
  66. jsr mmu_bank0
  67. lda #<name_src
  68. ldx #>name_src
  69. ldy #name_src_len
  70. jsr src_load
  71. cmp #$00
  72. ON_ZERO @fail_load
  73. jsr names_init
  74. lda #<name_src
  75. ldx #>name_src
  76. ldy #name_src_len
  77. jsr diag_init
  78. lda #$00
  79. sta diag_screen
  80. lda #$01
  81. sta em_on ; pass 2 emits statements
  82. lda #<rec_text ; record what the program prints
  83. sta em_pr_text
  84. lda #>rec_text
  85. sta em_pr_text+1
  86. lda #<rec_byte
  87. sta em_pr_byte
  88. lda #>rec_byte
  89. sta em_pr_byte+1
  90. lda #<rec_cr
  91. sta em_pr_cr
  92. lda #>rec_cr
  93. sta em_pr_cr+1
  94. lda #$00
  95. sta rec_len
  96. jsr parse_file
  97. jsr diag_finish
  98. sta diag_count
  99. lda diag_count
  100. sta MB_DATA+0
  101. lda em_bad
  102. sta MB_DATA+1
  103. lda cg_len
  104. sta MB_DATA+4
  105. lda cg_err
  106. sta MB_DATA+5
  107. lda rec_len
  108. sta MB_DATA+6
  109. lda diag_count
  110. ON_ZERO @fail_diag
  111. lda em_bad
  112. ON_ZERO @fail_emit
  113. lda cg_err
  114. ON_ZERO @fail_cg
  115. lda #<em_fp ; the fixture owns the frame base
  116. sta FRAME_FP
  117. lda #>em_fp
  118. sta FRAME_FP+1
  119. jsr cg_code ; run the emitted body
  120. lda em_fp - 2 ; a: the first local (FP-2)
  121. sta MB_DATA+2
  122. lda em_fp - 3 ; b: the second local (FP-3)
  123. sta MB_DATA+3
  124. lda rec_len
  125. sta MB_DATA+6
  126. lda #MB_ST_PASS
  127. sta MB_STATUS
  128. jmp @done
  129. @fail_load:
  130. sta MB_DATA+5 ; src_load result
  131. lda src_dos_code
  132. sta MB_DATA+6
  133. lda src_kernal_err
  134. sta MB_DATA+7
  135. lda #1
  136. jmp @fail
  137. @fail_diag:
  138. lda #2
  139. jmp @fail
  140. @fail_emit:
  141. lda #3
  142. jmp @fail
  143. @fail_cg:
  144. lda #4
  145. @fail: sta MB_CODE
  146. lda #$00
  147. sta MB_CODE+1
  148. lda #MB_ST_FAIL
  149. sta MB_STATUS
  150. @done: jsr mmu_shutdown
  151. plp
  152. rts
  153. ; ------------------------------------------------------------- recorders
  154. ; A/X = address, Y = length: record the literal bytes.
  155. rec_text:
  156. sta rec_ptr
  157. stx rec_ptr+1
  158. sty rec_cnt
  159. ldy #$00
  160. @loop: cpy rec_cnt
  161. beq @done
  162. lda (rec_ptr),y
  163. sty rec_y
  164. jsr rec_log
  165. ldy rec_y
  166. iny
  167. bne @loop
  168. @done: rts
  169. ; A = byte value: record $FF and the value, so a value print is distinct from
  170. ; text.
  171. rec_byte:
  172. pha
  173. lda #$FF
  174. jsr rec_log
  175. pla
  176. jmp rec_log
  177. ; A newline follows every print statement.
  178. rec_cr:
  179. lda #$0D
  180. jmp rec_log
  181. ; A = byte to append.
  182. rec_log:
  183. ldy rec_len
  184. cpy #32
  185. bcs @full
  186. sta rec_buf,y
  187. inc rec_len
  188. @full: rts
  189. .segment "ZEROPAGE"
  190. rec_ptr: .res 2
  191. .segment "RODATA"
  192. name_src: .byte "STMTS.N8"
  193. name_src_len = * - name_src
  194. .segment "BSS"
  195. diag_count: .res 1
  196. rec_cnt: .res 1
  197. rec_y: .res 1
  198. .export rec_len
  199. rec_len: .res 1
  200. .export rec_buf
  201. rec_buf: .res 32
  202. em_frame: .res 128
  203. em_fp = em_frame + 64
  204. .export em_fp

Powered by TurnKey Linux.