Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C64 Raster Interrupt #108

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions examples/c64/rasterirq.mfk
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

void RasterA() {
vic_rasterirq_acknowledge()

// First raster split, set border to black
vic_border = black

// Set up next raster split
vic_rasterirq_reconfigure(RasterB.addr, $40)

vic_rasterirq_return()
}

void RasterB() {
vic_rasterirq_acknowledge()

// Second raster split, Dark grey
vic_border = dark_grey

// Set up next raster split
vic_rasterirq_reconfigure(RasterC.addr, $A0)

vic_rasterirq_return()
}

void RasterC() {
vic_rasterirq_acknowledge()

// Third raster split, Light grey
vic_border = light_grey

// Set up next raster split
vic_rasterirq_reconfigure(RasterA.addr, $00)

vic_rasterirq_return()
}

void main() {
byte i

// Configure Raster IRQ
vic_rasterirq_configure(RasterA.addr, $00)

// Loop forever
while true {
i = 0 // Do nothing here
}
}
42 changes: 41 additions & 1 deletion include/c64_vic.mfk
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,44 @@ const byte medium_gray = 12
const byte light_green = 13
const byte light_blue = 14
const byte light_grey = 15
const byte light_gray = 15
const byte light_gray = 15


asm void vic_rasterirq_configure(pointer CallbackFunction, byte RasterLine) {
sei
ldx CallbackFunction.lo
stx $0314
ldy CallbackFunction.hi
sty $0315
lda #$7f ;CIA interrupt off
sta $dc0d
lda #$01 ;Raster interrupt on
sta $d01a
lda #27 ;High bit of interrupt position = 0
sta $d011
lda RasterLine ;Line where next IRQ happens
sta $d012
lda $dc0d ;Acknowledge IRQ (to be sure)
cli
rts
}

asm void vic_rasterirq_reconfigure(pointer CallbackFunction, byte RasterLine) {
ldx CallbackFunction.lo
stx $0314
ldy CallbackFunction.hi
sty $0315
lda RasterLine ;Line where next IRQ happens
sta $d012
rts
}

asm macro void vic_rasterirq_acknowledge() {
lda #$FF
sta $D019
}

asm macro void vic_rasterirq_return() {
lda #$00
jmp $EA81
}