1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-21 23:30:58 +00:00
8bitworkshop/presets/c64/rasterirq.s

112 lines
2.0 KiB
ArmAsm
Raw Normal View History

2022-07-20 19:32:47 +00:00
2023-11-09 18:54:58 +00:00
; use CC65's interrupter (slower)
2022-07-20 19:32:47 +00:00
USE_INTERRUPTOR = 0
.segment "DATA"
StartDlist: .word NullDlist-1
2022-08-11 20:27:20 +00:00
NextDlist: .word NullDlist-1
2022-07-20 19:32:47 +00:00
.segment "CODE"
2022-08-11 20:27:20 +00:00
.global ___dlist_setup
2023-11-09 18:54:58 +00:00
.global ___dlist_done
2022-07-20 19:32:47 +00:00
.global DLIST_IRQ_NEXT
.global DLIST_IRQ_RESTART
2023-11-09 18:54:58 +00:00
2022-07-20 19:32:47 +00:00
.if USE_INTERRUPTOR
.interruptor DLIST_IRQ
.endif
2022-08-11 20:27:20 +00:00
___dlist_setup:
2023-11-09 18:54:58 +00:00
sei ; set interrupt bit, make the CPU ignore interrupt requests
2022-07-20 19:32:47 +00:00
sta StartDlist+0 ; save XA as pointer to start of dlist
stx StartDlist+1
2023-11-09 18:54:58 +00:00
lda #%01111111 ; switch off interrupt signals from CIA-1
sta $DC0D
2022-07-20 19:32:47 +00:00
2023-11-09 18:54:58 +00:00
and $D011 ; clear most significant bit of VIC's raster register
sta $D011
2022-07-20 19:32:47 +00:00
2023-11-09 18:54:58 +00:00
lda $DC0D ; acknowledge pending interrupts from CIA-1
lda $DD0D ; acknowledge pending interrupts from CIA-2
2022-07-20 19:32:47 +00:00
2023-11-09 18:54:58 +00:00
lda #252 ; set rasterline where interrupt shall occur
sta $D012
2022-07-20 19:32:47 +00:00
.if !USE_INTERRUPTOR
2023-11-09 18:54:58 +00:00
lda #<DLIST_IRQ ; set interrupt vectors, pointing to interrupt service routine below
sta $0314
lda #>DLIST_IRQ
sta $0315
2022-07-20 19:32:47 +00:00
.endif
2023-11-09 18:54:58 +00:00
lda #%00000001 ; enable raster interrupt signals from VIC
sta $D01A
2022-07-20 19:32:47 +00:00
cli
rts
DLIST_IRQ:
DLIST_CALL:
lda NextDlist+1
pha
lda NextDlist+0
pha
rts
DLIST_IRQ_RESTART:
2023-11-09 18:54:58 +00:00
sta $D012 ; set IRQ raster line
2022-07-20 19:32:47 +00:00
lda StartDlist+0
sta NextDlist+0
lda StartDlist+1
sta NextDlist+1
bne DLIST_ACK
DLIST_IRQ_NEXT:
2023-11-09 18:54:58 +00:00
sta $D012
2022-07-20 19:32:47 +00:00
pla
sta NextDlist+0
pla
sta NextDlist+1
DLIST_ACK:
2023-11-09 18:54:58 +00:00
asl $D019 ; acknowledge the interrupt by clearing the VIC's interrupt flag
2022-07-20 19:32:47 +00:00
.if USE_INTERRUPTOR
clc
rts
.else
2022-08-09 14:47:55 +00:00
pla
tay
pla
tax
pla
rti ; return from interrupt
2022-07-20 19:32:47 +00:00
.endif
2023-11-09 18:54:58 +00:00
___dlist_done:
php
sei ; disable interrupts
lda #$0 ; disable raster interrupt signals from VIC
sta $D01A
lda #$ff
sta $DC0D
.if !USE_INTERRUPTOR
lda #$31 ; set interrupt vectors back to KERNAL
sta $0314
lda #$ea
sta $0315
.else
lda #<(NullDlist-1)
sta StartDlist
lda #>(NullDlist-1)
sta StartDlist+1
.endif
plp
rts
2022-07-20 19:32:47 +00:00
NullDlist:
lda #252
jmp DLIST_IRQ_RESTART