diff --git a/examples/c64/rasterirq.mfk b/examples/c64/rasterirq.mfk new file mode 100644 index 00000000..2d3b120a --- /dev/null +++ b/examples/c64/rasterirq.mfk @@ -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 + } +} diff --git a/include/c64_vic.mfk b/include/c64_vic.mfk index e19d9dee..1053ffb0 100644 --- a/include/c64_vic.mfk +++ b/include/c64_vic.mfk @@ -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 \ No newline at end of file +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 +}