Re: How to implement bareback interrupts?
Posted: Sun Aug 04, 2024 3:14 am
I can try to fix if you upload the complete source code file here + the ca65 config file
Commander X16 Community Forums
https://cx16forum.com/forum/
Code: Select all
MEMORY {
ZP: file = "", start = $0022, size = $0080 - $0022, define = yes;
CARTRAM: start = $1000, size = $8f00, define = yes;
CARTROM: start = $c000, size = $3fff, fill = yes, fillval = $aa;
}
SEGMENTS {
SETUP: load = CARTROM, type = rw, define = yes;
CODE: load = CARTROM, run = CARTRAM, type=rw, define=yes;
}
Code: Select all
; Build with: cl65 -o cart.bin -t cx16 -C cart.cfg main.asm
.import __CODE_LOAD__
.import __CODE_SIZE__
.import __CODE_RUN__
IRQVec = $0314
.segment "SETUP"
; Magic cartridge string at $c000
.byt "cx16"
; Copy code to RAM
init:
lda #<__CODE_LOAD__
sta $22
lda #>__CODE_LOAD__
sta $23
lda #<__CODE_RUN__
sta $24
lda #>__CODE_RUN__
sta $25
lda #<__CODE_SIZE__
sta $26
lda #>__CODE_SIZE__
sta $27
loop:
lda ($22)
sta ($24)
inc $22
bne :+
inc $23
: inc $24
bne :+
inc $25
: lda $26
bne :+
dec $27
: dec $26
lda $26
ora $27
bne loop
; Jump to RAM code
jmp __CODE_RUN__
.CODE
hello:
; Select Kernal ROM bank
stz $01
; Print hello
ldx #0
: lda msg,x
beq _setup_irq
jsr $ffd2
inx
bra :-
msg:
.byt "hello",0
; Your code...
_setup_irq:
;nop
;php
sei
lda #<loop_irq
sta IRQVec
lda #>loop_irq
sta IRQVec+1
cli
;plp
;lda #1
;sta $9F27
;rts
wait:
bra wait
loop_irq:
jsr handle_clock
jsr handle_joystick
jsr handle_keyboard
jsr show_life
lda #1
sta $9F27 ; ISR, bit 0=VSYNC
ply
plx
pla
rti
handle_clock:
;inc $22
rts
handle_joystick:
rts
handle_keyboard:
rts
show_life:
inc $22
bne :+
lda #'.'
jsr $ffd2
: rts
Code: Select all
_setup_irq:
nop
php
sei
stz ClockLo
stz ClockHi
lda #<loop_irq
sta IRQVec
lda #>loop_irq
sta IRQVec+1
; Setup first VBLANK
lda #$1
sta VERA::IRQ_EN
cli
plp
rts
loop_irq:
jsr handle_clock
jsr handle_joystick
jsr handle_keyboard
; Sign IRQ
lda #$1
sta VERA::IRQ_FLAGS
; Cleanup
ply
plx
pla
rti
Code: Select all
_setup_irq:
nop
php
sei
lda #<_loop_irq
sta IRQVec
lda #>_loop_irq
sta IRQVec+1
; Setup first VBLANK
lda VERA::IRQ_EN
ora #$1
sta VERA::IRQ_EN
plp
cli
rts
_loop_irq:
; Sign IRQ
lda #$1
sta VERA::IRQ_FLAGS
; Cleanup
ply
plx
pla
rti
Code: Select all
php
sei
<do some work>
plp