Skip to content

Instantly share code, notes, and snippets.

@JettMonstersGoBoom
Created June 25, 2020 16:03
Show Gist options
  • Save JettMonstersGoBoom/54d48011db5562a1b971451dd566694b to your computer and use it in GitHub Desktop.
Save JettMonstersGoBoom/54d48011db5562a1b971451dd566694b to your computer and use it in GitHub Desktop.
// build with
// millfork.exe -t c64 irq.mfk
import random
import c64_joy
import stdio
const byte VIC_25LINES = %00001000
const byte VIC_DISPLAY_ENABLED = %00010000
const byte VIC_BITMAP_ENABLED = %00100000
const byte VIC_ECM_ENABLED = %01000000
// lets move these around with the joystick
byte top_raster_line
byte bottom_raster_line
// this is the last byte in the vic bank
byte border_fill_byte @$3fff
// without kernal
pointer NMI_pointer@$fffa
pointer IRQ_pointer@$fffe
//
volatile byte IRQ_framesync
// empty NMI
// just incase it gets triggered do nothing
interrupt void NMI_nop() {
}
// this can be fairly freely placed
// this sets 25 line mode back
// and changes the border to red
// sets IRQ address to the bottom irq function
interrupt void IRQ_top_border(){
vic_cr1=VIC_DISPLAY_ENABLED | VIC_25LINES | 3 //%00111 011
vic_border = 2
vic_raster = bottom_raster_line
IRQ_pointer = IRQ_kick_border.addr
asm {
asl $d019
}
}
// this MUST happen at $fa
// we set 24 lines mode at this exact line
interrupt void IRQ_kick_border(){
asm {
asl $d019
}
vic_cr1=VIC_DISPLAY_ENABLED | 3
vic_raster = top_raster_line
vic_border = 4
IRQ_framesync = 0
IRQ_pointer = IRQ_top_border.addr
}
// this waits for the IRQ to set framesync to zero
// so we can run our code outside of an irq but remain framesynced
void IRQ_vsync() {
IRQ_framesync+=1
while (IRQ_framesync!=0){}
}
//
void main(){
asm {
sei
ldx #$ff
txs
}
// set screen off while we setup
//
vic_cr1 = 0
// we can safely use the kernal here
putstrz("joy up + down to move top raster"z)
new_line()
putstrz("hold fire + up or down for bottom raster"z)
new_line()
cia_disable_irq()
// can no longer use the kernal
// disable kernal
c64_ram_io()
// set irq and nmi pointers
IRQ_pointer = IRQ_top_border.addr
NMI_pointer = NMI_nop.addr
// enable vic irq
vic_irq_ena = 1
// set irq position
// for the 1st call
vic_raster = $21
top_raster_line = $21
// for knocking out border
bottom_raster_line = $fa
// re-enable irq
asm {
// acknoledge
asl $d019
cli
}
while true {
// inplace of while $d012 != $80 style
IRQ_vsync()
// change the border byte
border_fill_byte += 1
// check joy
read_joy2()
if (input_btn==1) {
bottom_raster_line+=input_dy
} else {
top_raster_line+=input_dy
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment