首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如果我关闭了两个CIA,谁会调用我的中断处理程序?

如果我关闭了两个CIA,谁会调用我的中断处理程序?
EN

Stack Overflow用户
提问于 2013-05-18 23:16:22
回答 1查看 149关注 0票数 3

我正在尝试设置一个简单的光栅中断处理程序来更改给定条纹中的背景颜色。但是,我的中断处理程序似乎总是被调用。(代码使用CA65的格式)

代码语言:javascript
复制
.include "c64.inc"

ROW = 100

.segment "ZPSAVE"

.segment "STARTUP"

        sei

        ;; Turn off BASIC and KERNAL ROM
        lda #$35
        sta $01

        ;; Flush CIA IRQs
        bit CIA1_ICR
        bit CIA2_ICR

        ;; Turn off CIA interrupts
        lda #%011111111
        sta CIA1_ICR
        sta CIA2_ICR

        ;; Set target raster line
        lda #%01111111
        and VIC_CTRL1
        sta VIC_CTRL1

        lda #ROW
        sta VIC_HLINE

        ;; Enable VIC interrupt
        lda #%00000001
        sta VIC_IMR

        ;; Install interrupt handler
        lda #<isr
        sta $fffe
        lda #>isr
        sta $ffff
        cli

        rts

.macro isr_pre
        pha
        txa
        pha
        tya
        pha
.endmacro

.macro isr_post
        pla
        tay
        pla
        tax
        rti
.endmacro

;;; Acknowledge VIC interrupt
.macro ack_vic
        lda VIC_IRR
        and #$01
        sta VIC_IRR
.endmacro

.proc isr
        isr_pre
        ack_vic

        ;; Uncommenting these lines works around the problem
        ;; lda VIC_HLINE
        ;; cmp #ROW
        ;; bne exit

        lda #1
        sta VIC_BORDERCOLOR
        sta VIC_BG_COLOR0

        ldx #50
:       dex
        bne :-

        lda #0
        sta VIC_BORDERCOLOR
        sta VIC_BG_COLOR0

exit:   isr_post
.endproc

如果我注释掉上面代码中标记为“临时解决办法”的三行代码,那么我的中断处理程序就会一直被调用,而不仅仅是在行ROW (开始)上调用

如果我取消对这三行的注释,那么它可以工作,但它非常不稳定,我猜是因为那些相同的意外中断:

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-05-23 00:04:27

我在上面的代码中发现了几个问题,并修复了所有这些问题:

  1. 关闭CIA中断的位掩码是错误的(它意外地有9位长) --这就是导致所有这些额外中断触发的原因...
  2. ISR Postscriptom宏缺少恢复A寄存器的pla --这严重地搞砸了状态,所以无论旧代码发生了什么,都或多或少是偶然发生的...

< code >H19VIC中断在中断设置代码中没有被刷新--因此,在修复了前面两个问题之后,现在中断永远不会在设置代码的末尾triggered.

  1. There's nothing to rts to,因为我们关闭了内核和基本ROM

因此,固定代码如下:

代码语言:javascript
复制
.include "c64.inc"

ROW = 100

;;; Acknowledge VIC interrupt
.macro ack_vic
        lda VIC_IRR
        and #$01
        sta VIC_IRR
.endmacro

.segment "ZPSAVE"

.segment "STARTUP"

        sei

        ;; Turn off BASIC and KERNAL ROM
        lda #$35
        sta $01

        ;; Flush CIA IRQs
        bit CIA1_ICR
        bit CIA2_ICR
        ack_vic

        ;; Turn off CIA interrupts
        lda #%01111111
        sta CIA1_ICR
        sta CIA2_ICR

        ;; Set target raster line
        lda #%01111111
        and VIC_CTRL1
        sta VIC_CTRL1

        lda #ROW
        sta VIC_HLINE

        ;; Enable VIC interrupt
        lda #%00000001
        sta VIC_IMR

        ;; Install interrupt handler
        lda #<isr
        sta $fffe
        lda #>isr
        sta $ffff
        cli    
        jmp *

.macro isr_pre
        pha
        txa
        pha
        tya
        pha
.endmacro

.macro isr_post
        pla
        tay
        pla
        tax
        pla
        rti
.endmacro

.proc isr
        isr_pre
        ack_vic

        lda #1
        sta VIC_BORDERCOLOR
        sta VIC_BG_COLOR0

        ldx #50
:       dex
        bne :-

        lda #0
        sta VIC_BORDERCOLOR
        sta VIC_BG_COLOR0

exit:   isr_post
.endproc

正如预期的那样,这会产生一个纯白的条纹。由于某些未知的原因,条纹水平地从屏幕的中间开始,但我猜这是一个单独的SO问题。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16625796

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档