| |
Trifox Account closed
Registered: Mar 2006 Posts: 108 |
question about triggered raster line in raster interrupt
i am using this code
to initialise my interrupt
this should look fairly common:
(pasted from somewhere ... )
; Initialise Music Interrupt
sei ; turn off interrupts
lda #$7f
ldx #$01
sta $dc0d ; Turn off CIA 1 interrupts
sta $dd0d ; Turn off CIA 2 interrupts
stx $d01a ; Turn on raster interrupts
lda $d011
;ldx #%1000
;ldy #$14
and #%01111111
sta $d011 ; Clear high bit of $d012, set text mode
;stx $d016 ; single-colour
;sty $d018 ; screen at $0400, charset at $2000
lda #<int ; low part of address of interrupt handler code
ldx #>int ; high part of address of interrupt handler code
ldy #0 ; line to trigger interrupt
sta $0314 ; store in interrupt vector
stx $0315
sty $d012
lda $dc0d ; ACK CIA 1 interrupts
lda $dd0d ; ACK CIA 2 interrupts
asl $d019 ; ACK VIC interrupts
cli
to init my interrrupt, i encountered that this interrupt is triggered in row 256 :( what must i do to let it trigger on exactly line 0 ? and only there, not on line 0 AND 256 ... know what i mean ?
i am leaving the interrupt with following fragment:
; Initialise Music Interrupt
sei ; turn off interrupts
lda #$7f
ldx #$01
sta $dc0d ; Turn off CIA 1 interrupts
sta $dd0d ; Turn off CIA 2 interrupts
stx $d01a ; Turn on raster interrupts
lda $d011
;ldx #%1000
;ldy #$14
and #%01111111
sta $d011 ; Clear high bit of $d012, set text mode
;stx $d016 ; single-colour
;sty $d018 ; screen at $0400, charset at $2000
lda #<int ; low part of address of interrupt handler code
ldx #>int ; high part of address of interrupt handler code
ldy #0 ; line to trigger interrupt
sta $0314 ; store in interrupt vector
stx $0315
sty $d012
lda $dc0d ; ACK CIA 1 interrupts
lda $dd0d ; ACK CIA 2 interrupts
asl $d019 ; ACK VIC interrupts
cli
|
|
| |
Mace
Registered: May 2002 Posts: 1799 |
Not sure if it matters, but I usually INC$d019 and set $D012 in the interrupt itself, not in the initialise routine. |
| |
MagerValp
Registered: Dec 2001 Posts: 1078 |
This init routine correctly sets the irq to trigger on line 0. Perhaps you're setting the high bit of d011 later on?
Btw, there's no need for sei/cli. Just do
lda #$7f
sta $dc0d
sta $dd0d
and the irqs are disabled
then
lda #1
sta $d01a
at the end when you're ready to go.
|
| |
Krill
Registered: Apr 2002 Posts: 2980 |
Quote: Not sure if it matters, but I usually INC$d019 and set $D012 in the interrupt itself, not in the initialise routine.
BAD style. :) During the set-up period with SEI, interrupts can be requested but won't be fired until CLI. So if you skip the irq acks before the CLI, you'll get an interrupt right after the CLI, and this is what you want seldomly. |
| |
JackAsser
Registered: Jun 2002 Posts: 2014 |
Funny how all these IRQ-stuff always get's copied and pasted instead of simply learn why and how it works... It's not THAT tricky.
; Disable IRQs
sei
; Swap out bitch
lda #$35
sta $01
; write 0 to all CIA IRQ-masks
lda #$7f
sta $dc0d
sta $dd0d
; Acknowledge pending CIA-interrupts
bit $dc0d
bit $dd0d
; Enable raster IRQs
lda #$01
sta $d01a
; Acknowledge pending Raster-IRQ
dec $d019
; Set raster compare + standard textmode
lda #$80
sta $d012
lda #$1b
sta $d011
; Set IRQ pointers
lda #<irq
sta $fffe
lda #>irq
sta $ffff
; Init-music
lda #$00
tax
tay
jsr music
; Re-enable irqs and stall
cli
jmp *
irq:
; Save regs
sta _AREG+1
stx _XREG+1
sty _YREG+1
; Call music
inc $d020
jsr music+3
dec $d020
; Restore registers
_AREG: lda #$00
_XREG: ldx #$00
_YREG: ldy #$00
; Acknowledge raster IRQ with favorite RMW-instruction of choice
dec $d019
rti
It's really not more tricky than that.
|
| |
ChristopherJam
Registered: Aug 2004 Posts: 1409 |
I'd go as far as advising against an SEI before killing the CIA interrupt, else there's a chance that the first interrupt you get will be from the CIA at some random raster position.
I had a bug at one stage from doing an lda$d011:and#248:ora#0n:sta $d011 - my intention was to avoid touching bits I didn't need to, but the result was whenever my music routine pushed the execution of that code past line 255, the next raster interrupt would never happen,as it would be set for some time after line 312! (Thanks Magervalp for suggesting I test in an emu and look at the raster position of the IRQ).
ETA: JackAsser wrote
; Acknowledge pending CIA-interrupts
bit $dc0d
bit $dd0d
Well yes, that works too. |
| |
JackAsser
Registered: Jun 2002 Posts: 2014 |
Quote: I'd go as far as advising against an SEI before killing the CIA interrupt, else there's a chance that the first interrupt you get will be from the CIA at some random raster position.
I had a bug at one stage from doing an lda$d011:and#248:ora#0n:sta $d011 - my intention was to avoid touching bits I didn't need to, but the result was whenever my music routine pushed the execution of that code past line 255, the next raster interrupt would never happen,as it would be set for some time after line 312! (Thanks Magervalp for suggesting I test in an emu and look at the raster position of the IRQ).
ETA: JackAsser wrote
; Acknowledge pending CIA-interrupts
bit $dc0d
bit $dd0d
Well yes, that works too.
"I'd go as far as advising against an SEI before killing the CIA interrupt, else there's a chance that the first interrupt you get will be from the CIA at some random raster position"
That's why you should acknowledge them within the SEI/CLI pair.
Edit: So u figured it out. :D Sorry |
| |
ChristopherJam
Registered: Aug 2004 Posts: 1409 |
We should stop posting comments simultaneously!
Anyone feel like implementing a semaphore? ;-) |
| |
tlr
Registered: Sep 2003 Posts: 1790 |
Quote: We should stop posting comments simultaneously!
Anyone feel like implementing a semaphore? ;-)
Just to a SEI before you post and a CLI afterwards. |
| |
ChristopherJam
Registered: Aug 2004 Posts: 1409 |
Alternately you could just temporarily disable the other poster before responding, then no SEI/CLI should be needed. |
| |
JackAsser
Registered: Jun 2002 Posts: 2014 |
It's rather comical that we have pending posting problems speaking of pending IRQ problems. ; |
| |
yago
Registered: May 2002 Posts: 333 |
While we are at it...
dont use dec $d019, or asl $d019 or similar..
Please use
lda $d019
sta $d019
makes sure to stay compatible with e.g. c65.
Thanks in Advance,
Zed
|
| |
tlr
Registered: Sep 2003 Posts: 1790 |
Quote: While we are at it...
dont use dec $d019, or asl $d019 or similar..
Please use
lda $d019
sta $d019
makes sure to stay compatible with e.g. c65.
Thanks in Advance,
Zed
I always used lda #$01/sta $d019 in my stuff, but I've never seen anybody use lda $d019/sta $d019.
|
| |
Trifox Account closed
Registered: Mar 2006 Posts: 108 |
whao, thanks for so much information |
| |
Mace
Registered: May 2002 Posts: 1799 |
Why would I want to make my stuff compatible with C65?
I'd have to stick to all compatibility rules then, and I didn't even _know_ there was the possibility to do so :-)
BTW, what _are_ the (other) rules to keep C64 compatibility? |
| |
MagerValp
Registered: Dec 2001 Posts: 1078 |
WTF? CSDB just deleted my post and gave me a search page instead.
|
| |
WVL
Registered: Mar 2002 Posts: 902 |
Right. Like most demos are not compatible with c64 because of ASL $d019.. :) I'm guessing 99.9% of demos wouldnt run anyway, because of
-vic trickery
-illegal opcodes
-lotsa other stuff
So please keep saving those cycles and do ASL $D019 ;) |
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
looks like I'm alone with my lsr $d019 :) |
| |
chatGPZ
Registered: Dec 2001 Posts: 11386 |
inc $d019 ftw! |
| |
Scout
Registered: Dec 2002 Posts: 1570 |
Quote: looks like I'm alone with my lsr $d019 :)
Nope :) |
| |
Graham Account closed
Registered: Dec 2002 Posts: 990 |
SRE $D019 |
| |
TWW
Registered: Jul 2009 Posts: 545 |
dec $d019? |
| |
SIDWAVE Account closed
Registered: Apr 2002 Posts: 2238 |
RTFM...
the correct thing is poke d019,1 |
| |
Mace
Registered: May 2002 Posts: 1799 |
awww... please close this thread, it's many moons old :( |