25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

109 satır
3.6KB

  1. ; =============================================================
  2. ; irq-handler.asm - raster IRQ skeleton for the C64 (ca65)
  3. ;
  4. ; Changes the border color at raster lines 100 and 200, on top of the normal
  5. ; Kernal IRQ (keyboard scan, jiffy clock), and returns to BASIC.
  6. ;
  7. ; RUN install (SYS 2061)
  8. ; SYS 2064 remove
  9. ;
  10. ; c64 run examples/irq-handler.asm
  11. ; c64 test examples/irq-handler.asm -AfterJiffies 300 (see build/test/screenshot.png)
  12. ;
  13. ; Timing: line numbers are valid on PAL (312 lines) and NTSC (263 lines).
  14. ; =============================================================
  15. VIC_CTRL1 = $D011 ; bit 7 = raster compare bit 8
  16. VIC_RASTER = $D012
  17. VIC_IRR = $D019 ; interrupt request register (write 1s to acknowledge)
  18. VIC_IMR = $D01A ; interrupt mask register
  19. VIC_BORDER = $D020
  20. CIA1_ICR = $DC0D
  21. CINV = $0314 ; Kernal IRQ vector (RAM)
  22. KERNAL_IRQ_EXIT = $EA81 ; pull Y, X, A and RTI (end of the Kernal handler)
  23. .segment "CODE"
  24. entry: jmp install ; SYS 2061
  25. jmp remove ; SYS 2064
  26. ; ---------------------------------------------------------------
  27. ; install: hook CINV and enable the raster interrupt
  28. ; ---------------------------------------------------------------
  29. .proc install
  30. sei ; no IRQs while the vector is half-written
  31. lda CINV ; save the current handler so we can chain to it
  32. sta oldirq
  33. lda CINV+1
  34. sta oldirq+1
  35. lda #<raster_irq
  36. sta CINV
  37. lda #>raster_irq
  38. sta CINV+1
  39. lda VIC_CTRL1
  40. and #$7F ; raster compare bit 8 = 0
  41. sta VIC_CTRL1
  42. lda #100
  43. sta VIC_RASTER
  44. lda #$01 ; enable the raster IRQ (CIA 1 timer IRQ stays on)
  45. sta VIC_IMR
  46. sta VIC_IRR ; clear any stale raster request
  47. cli
  48. rts
  49. .endproc
  50. ; ---------------------------------------------------------------
  51. ; remove: restore the saved vector and disable the raster IRQ
  52. ; ---------------------------------------------------------------
  53. .proc remove
  54. sei
  55. lda oldirq
  56. sta CINV
  57. lda oldirq+1
  58. sta CINV+1
  59. lda #$00
  60. sta VIC_IMR
  61. lda #$01
  62. sta VIC_IRR ; acknowledge a raster IRQ that may be pending
  63. cli
  64. rts
  65. .endproc
  66. ; ---------------------------------------------------------------
  67. ; raster_irq: runs for every IRQ (the Kernal pushed A, X, Y already)
  68. ; ---------------------------------------------------------------
  69. .proc raster_irq
  70. lda VIC_IRR
  71. and #$01 ; raster interrupt?
  72. beq not_raster ; no: it is the CIA timer, run the Kernal handler
  73. sta VIC_IRR ; acknowledge (write 1 to bit 0)
  74. inc coloridx ; next border color
  75. lda coloridx
  76. and #$0F
  77. sta VIC_BORDER
  78. lda VIC_RASTER ; alternate between lines 100 and 200
  79. cmp #200
  80. bcs top
  81. lda #200
  82. bne set ; always taken
  83. top: lda #100
  84. set: sta VIC_RASTER
  85. ; The raster IRQ must not run the Kernal handler: it would advance the
  86. ; jiffy clock and scan the keyboard an extra time per frame.
  87. jmp KERNAL_IRQ_EXIT
  88. not_raster:
  89. jmp (oldirq) ; usually $EA31: keyboard, clock, acknowledges CIA 1
  90. .endproc
  91. .segment "DATA"
  92. oldirq: .word $EA31
  93. coloridx: .byte 0

Powered by TurnKey Linux.