spt.mac 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. ; code: lang=asm-collection tabSize=8
  2. ; macros for placing interrupt vectors in the middle of a block of threaded code
  3. SPT_SKIP_INTVEC .macro
  4. dw spt_jp, .intvec_continue ; continue after the NMI vector
  5. PLACE_INTVEC
  6. ; ld sp,0
  7. reti
  8. .intvec_continue:
  9. .endm
  10. SPT_SKIP_NMIVEC .macro
  11. dw spt_jp, .nmivec_continue ; continue after the NMI vector
  12. ; PLACE_NMIVEC
  13. PLACE_VEC $66
  14. ; ld sp,0 ; on model 1, NMI is connected to reset button
  15. retn
  16. .nmivec_continue:
  17. .endm
  18. ; Start a threaded-code section by pointing to it with SP and issuing RET
  19. ; immediately following this macro should be the addresses (and optionally,
  20. ; parameters) for the threaded code
  21. SPTHREAD_BEGIN .macro
  22. .local threadstart
  23. ld sp,.`threadstart
  24. ret
  25. .`threadstart:
  26. .endm
  27. ; At the end of the threaded code section, place an address just beyond
  28. ; the list of addresses, to jump back to conventional code
  29. SPTHREAD_END .macro
  30. dw $+2
  31. .endm
  32. ; Save the stack pointer into the stack registers. This is analogous
  33. ; to pushing SP onto the (simulated) stack. The shadow registers hold
  34. ; two copies of SP, and effectively become a 2-element stack. This means
  35. ; that there can be up to two threaded code stack frames saved. The
  36. ; innermost threaded stack frame can call a third-level machine-code
  37. ; subroutine, but that subroutine can't make any further calls or run
  38. ; threaded code itself.
  39. SPTHREAD_SAVE .macro
  40. exx
  41. ex af,af' ; save flags because of the add hl,sp instruction
  42. ex de,hl
  43. ld hl,0 ; copy old sp to iy
  44. add hl,sp
  45. ex af,af'
  46. exx
  47. .endm
  48. ; The opposite of SPTHREAD_SAVE. Pops SP off the simulated stack in
  49. ; preparation for returning to the enclosing threaded stack frame.
  50. SPTHREAD_RESTORE .macro
  51. exx
  52. ld sp,hl ; resume from the thread location saved in hl'
  53. ex de,hl
  54. exx
  55. .endm
  56. ; The prologue for a subroutine that contains threaded code.
  57. SPTHREAD_ENTER .macro
  58. SPTHREAD_SAVE
  59. SPTHREAD_BEGIN
  60. .endm
  61. ; The epilogue for a subroutine that contains threaded code. To be followed by RET
  62. SPTHREAD_LEAVE .macro
  63. SPTHREAD_END
  64. SPTHREAD_RESTORE
  65. .endm
  66. MAC_SPT_CON_GOTO .macro row,col
  67. dw spt_con_goto, VBASE+(row*VLINE)+col
  68. .endm
  69. MAC_SPT_CON_OFFSET .macro row,col
  70. dw VBASE+(row*VLINE)+col
  71. .endm