Login
Back to forumReply to this topicGo to last reply

Posted By

Harry Potter
on 2025-08-06
20:04:06
 cc65/Plus4: IRQ bugs fixed!

Hi! Earlier today, I finally found out why two of my Plus4 programs weren't working. The symptoms included occasional display of garbage and system crashes. I suspected IRQ, and it was: First, I wasn't preserving the registers during IRQs, and second, there was a mismatched push or pop. Now, one project is starting better, but now, the main menu's highlight is flashing and probably in the wrong color, and text input is displaying garbage, and the highlight size is wrong. Both are within my Fields library, but the C64 version of this program is working properly. I don't actually need IRQs for this project and want to do away with them. Following is the code that handles IRQs for the Plus4:
-------------------------
.segment "LOWCODE"

IRQ: cld ; Just to be sure
pha
txa
pha
tya
pha
; tsx ; Get the stack pointer
; lda $0104,x ; Get the saved status register
; and #$10 ; Test for BRK bit
; bne dobreak

; It's an IRQ; and, RAM is enabled. If we have handlers, call them. We will use
; a flag here instead of loading __INTERRUPTOR_COUNT__ directly, since the
; condes function is not reentrant. The irqcount flag will be set/reset from
; the main code, to avoid races.

; ldy irqcount
; beq @L1
; jsr callirq_y ; Call the IRQ functions

; Since the ROM handler will end with an RTI, we have to fake an IRQ return
; on the stack, so that we get control of the CPU after the ROM handler,
; and can switch back to RAM.

@L1: lda #>irq_ret ; Push new return address
pha
lda #<irq_ret
pha
php ; Push faked IRQ frame on stack
pha ; Push faked A register
pha ; Push faked X register
pha ; Push faked Y register
sta ENABLE_ROM ; Switch to ROM
jmp (IRQVec) ; Jump indirect to Kernal IRQ handler

irq_ret:
sta ENABLE_RAM ; Switch back to RAM
pla
tay
pla
tax
pla
;plp
rti
---------------
Is there a way to do this with less code?


Back to topReply to this topic


Copyright © Plus/4 World Team, 2001-2025. Support Plus/4 World on Patreon