1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-06-29 09:29:31 +00:00
kickc/src/test/ref/irq-hardware-clobber-jsr.asm
2020-02-23 09:44:36 +01:00

95 lines
2.3 KiB
NASM

// A minimal working raster hardware IRQ with clobber-based register savings
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
// Processor port data direction register
.label PROCPORT_DDR = 0
// Mask for PROCESSOR_PORT_DDR which allows only memory configuration to be written
.const PROCPORT_DDR_MEMORY_MASK = 7
// Processor Port Register controlling RAM/ROM configuration and the datasette
.label PROCPORT = 1
// RAM in $A000, $E000 I/O in $D000
.const PROCPORT_RAM_IO = 5
.label RASTER = $d012
.label BORDERCOL = $d020
.label BGCOL = $d021
.label VIC_CONTROL = $d011
// VIC II IRQ Status Register
.label IRQ_STATUS = $d019
// VIC II IRQ Enable Register
.label IRQ_ENABLE = $d01a
// Bits for the IRQ Status/Enable Registers
.const IRQ_RASTER = 1
// CIA#1 Interrupt Status & Control Register
.label CIA1_INTERRUPT = $dc0d
// Value that disables all CIA interrupts when stored to the CIA Interrupt registers
.const CIA_INTERRUPT_CLEAR = $7f
// The vector used when the HARDWARE serves IRQ interrupts
.label HARDWARE_IRQ = $fffe
// The colors of the C64
.const BLACK = 0
.const WHITE = 1
main: {
// asm
sei
// *PROCPORT_DDR = PROCPORT_DDR_MEMORY_MASK
// Disable kernal & basic
lda #PROCPORT_DDR_MEMORY_MASK
sta PROCPORT_DDR
// *PROCPORT = PROCPORT_RAM_IO
lda #PROCPORT_RAM_IO
sta PROCPORT
// *CIA1_INTERRUPT = CIA_INTERRUPT_CLEAR
// Disable CIA 1 Timer IRQ
lda #CIA_INTERRUPT_CLEAR
sta CIA1_INTERRUPT
// *VIC_CONTROL |=$80
// Set raster line to $100
lda #$80
ora VIC_CONTROL
sta VIC_CONTROL
// *RASTER = $00
lda #0
sta RASTER
// *IRQ_ENABLE = IRQ_RASTER
// Enable Raster Interrupt
lda #IRQ_RASTER
sta IRQ_ENABLE
// *HARDWARE_IRQ = &irq
// Set the IRQ routine
lda #<irq
sta HARDWARE_IRQ
lda #>irq
sta HARDWARE_IRQ+1
// asm
cli
__b1:
// (*BORDERCOL)++;
inc BORDERCOL
jmp __b1
}
// Interrupt Routine
irq: {
sta rega+1
// do_irq()
jsr do_irq
// }
rega:
lda #00
rti
}
do_irq: {
// *BGCOL = WHITE
lda #WHITE
sta BGCOL
// *BGCOL = BLACK
lda #BLACK
sta BGCOL
// *IRQ_STATUS = IRQ_RASTER
// Acknowledge the IRQ
lda #IRQ_RASTER
sta IRQ_STATUS
// }
rts
}