| |
ChristopherJam
Registered: Aug 2004 Posts: 1402 |
SEI considered harmful.
Once more for the people at the back:
Don't wrap your interrupt initialisation with SEI/CLI.
It's a bad way to avoid interrupts being dispatched while you're changing the IRQ pointer, because it then requires additional code to acknowledge any pending CIA IRQs that might trigger between the SEI being executed and you turning off the CIA timer or interrupt enable.
If you're coming from BASIC, just do this instead:
lda #$7f
sta $dc0d
..then change $01, set your IRQ pointer(s), and init your own raster and/or timer IRQ(s)
If you're coming from a previous part, ask your teammate to turn off any IRQs and acknowedge any requests before they pass the baton (cf 'IRQ recovery' link below) - then all you need to do is set up your own IRQ.
As previously flogged to death at
TIL: The instruction after SEI can be executed before a pending IRQ is handled
C-64 coding cargo cults
Best practice IRQ recovery |
|
| |
Oswald
Registered: Apr 2002 Posts: 5074 |
no way I'm leaving my cargo cult
sei
lda #$01
sta $d01a
lda #$3b
sta $d011
lda #ras1
sta $d012
lda #24
sta 53272
lda #$7f
sta $dc0d
sta $dd0d
lda $dc0d
lda $dd0d
lda #<irq1
sta $fffe
lda #>irq1
sta $ffff
lda #$35
sta $01
cli |
| |
ChristopherJam
Registered: Aug 2004 Posts: 1402 |
I mean, those two loads from DC0D/DD0D are the 'additional code' I was referring to in the post above.
They're easy to forget because 99% of the time they don't do anything, but I guess that's not an issue if they're in your boiler plate. Such a waste of bytes though :) |
| |
spider-j
Registered: Oct 2004 Posts: 482 |
I do it like Christopher said for years now. Never had a problem.
*= code_start
lda #0x7F
sta 0xDC0D
lda #0x35
sta 0x01
lda #0x1B
sta 0xD011
...
|
| |
Cruzer
Registered: Dec 2001 Posts: 1048 |
Quoting ChristopherJamIf you're coming from BASIC, just do this instead:
lda #$7f
sta $dc0d I never got around to study how BASIC and KERNAL works. But does this mean that I can be sure there are no IRQs or CIA2 NMIs, including from all kinds of cartridges that people might have plugged in? |
| |
MagerValp
Registered: Dec 2001 Posts: 1065 |
Quoting CruzerI never got around to study how BASIC and KERNAL works. But does this mean that I can be sure there are no IRQs or CIA2 NMIs, including from all kinds of cartridges that people might have plugged in?
The only thing that's enabled at the basic prompt is the CIA1 timer irq. None of the cartridges I know of enable anything else, and if they did it'd break a shit ton of software. |
| |
JackAsser
Registered: Jun 2002 Posts: 2014 |
Better safe than sorry during init, but between parts you know what happens. No need to clear anything. |
| |
chatGPZ
Registered: Dec 2001 Posts: 11290 |
I tend to store $7f to $dd0d as well, knowing that it isnt really required at all. And indeed, once you link stuff together, those SEI/CLI things become a super annoying source of occasional bugs. Just don't. |
| |
JackAsser
Registered: Jun 2002 Posts: 2014 |
Exacly Groepaz. |
| |
Cruzer
Registered: Dec 2001 Posts: 1048 |
Quoting MagerValpThe only thing that's enabled at the basic prompt is the CIA1 timer irq. None of the cartridges I know of enable anything else, and if they did it'd break a shit ton of software. Nice to know, thanks! It's gonna be hard to change the habit of copy/pasting the same cargo cult code I've been using forever, but I'll try. |
| |
Burglar
Registered: Dec 2004 Posts: 1066 |
y'all make it sound too easy, there's music sync to worry about too, frameskips are fugly. |
... 36 posts hidden. Click here to view all posts.... |
Previous - 1 | 2 | 3 | 4 | 5 - Next |