Skip to content

Instantly share code, notes, and snippets.

@cbmeeks
Last active August 18, 2020 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbmeeks/bfe4dce0129f08d2c20f241d774ec1cd to your computer and use it in GitHub Desktop.
Save cbmeeks/bfe4dce0129f08d2c20f241d774ec1cd to your computer and use it in GitHub Desktop.
Stable Raster
/*
This is working for NTSC. However, by my calculations, we're at 68 cycles instead of the required 65.
That can't be right. Yet, it works. I assume I am making a false assumption on some of the timings.
*/
BasicUpstart2(Entry)
Entry:
sei
// Disable CIA interrupts
lda #$7f
sta $dc0d
sta $dd0d
// Enable raster interrupts
lda #$01
sta $d01a
// Create IRQ entry point
lda #<IRQ
ldx #>IRQ
sta $fffe
stx $ffff
// Set line
lda $d011
and #$7f
sta $d011
lda IRQLine
sta $d012
// Bank out kernel BASCI
lda #$35
sta $01
// Acknowledge interrupt
asl $d019
cli
!Loop:
nop
bit $01
jmp !Loop-
.label IRQLine = $28
IRQ:
// Save state
pha
txa
pha
tya
pha
// Setup second interrupt (stable)
lda #<StableIRQ
ldx #>StableIRQ
sta $fffe
stx $ffff
// Move down next line (stable interrupt begins on the next line from the #$28 above)
inc $d012
asl $d019 // ack interrupt
tsx
cli
nop
nop
nop
nop
nop
nop
nop
nop
nop
StableIRQ:
// At this point, we're at 7-8 cycles (jitter) from previous IRQ
txs // 2 cycles
// Waste cycles ///////////////////////////////////////////////
ldx #$09 // X * 5 + 1 cycles
!:
dex
bne !- // X(9) * 5 = 45 + 1 = 46 cycles
// At this point, we're 46 + 2 + 7 (55 cycles BEST case) or 46 + 2 + 8 (56 cycles WORST case)
lda $d012 // 4 cycles
cmp $d012 // 4 cycles
// At this point, we're 55 + 8 = 63 cycles (BEST case) or 55 + 8 = 64 (WORST case) cycles
beq !+ // takes 3 cycles *IF* comparison is the SAME. If they're NOT the same, then 2 cycles
!:
// We're 66 cycles here based on BEQ.
nop // 2 cycles
// Here, we're at 68 cycles???? What gives??
// We should be at 65 cycles here! But, we're at 68.
inc $d020
dec $d020
// Acknowledge interrupts
asl $d019
// Point back to original IRQ
lda #<IRQ
ldx #>IRQ
sta $fffe
stx $ffff
lda #IRQLine
sta $d012
asl $d019 // ack interrupt
// Restore state
pla
tay
pla
tax
pla
rti
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment