Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
 Welcome to our latest new user jmi ! (Registered 2024-09-15) You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > SEI considered harmful.
2023-10-30 05:16
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
2023-10-30 09:06
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
2023-10-30 09:45
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 :)
2023-10-30 09:52
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
                    ...
2023-10-30 11:01
Cruzer

Registered: Dec 2001
Posts: 1048
Quoting ChristopherJam
If 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?
2023-10-30 12:11
MagerValp

Registered: Dec 2001
Posts: 1065
Quoting Cruzer
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?

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.
2023-10-30 13:45
JackAsser

Registered: Jun 2002
Posts: 2014
Better safe than sorry during init, but between parts you know what happens. No need to clear anything.
2023-10-30 15:29
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.
2023-10-30 21:13
JackAsser

Registered: Jun 2002
Posts: 2014
Exacly Groepaz.
2023-10-30 21:32
Cruzer

Registered: Dec 2001
Posts: 1048
Quoting MagerValp
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.
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.
2023-10-30 21:52
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
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Pajda/Faith Design
icon/The Silents, Sp..
Matt
lucommodore
Scooby/G★P/Light
Brush/Elysium
Avalanche/Atlantis
Higgie/Kraze/Slackers
Da Snake
REBEL 1/HF
Courage
bugjam
Sychamis
E$G/HF ⭐ 7
WVL/Xenon
Guests online: 148
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Mojo  (9.6)
6 Uncensored  (9.6)
7 Wonderland XIV  (9.6)
8 Comaland 100%  (9.6)
9 No Bounds  (9.6)
10 Unboxed  (9.6)
Top onefile Demos
1 Layers  (9.6)
2 Party Elk 2  (9.6)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.6)
5 Rainbow Connection  (9.5)
6 It's More Fun to Com..  (9.5)
7 Dawnfall V1.1  (9.5)
8 Onscreen 5k  (9.5)
9 Daah, Those Acid Pil..  (9.5)
10 Morph  (9.5)
Top Groups
1 Booze Design  (9.3)
2 Oxyron  (9.3)
3 Nostalgia  (9.3)
4 Censor Design  (9.3)
5 Triad  (9.2)
Top Organizers
1 Burglar  (9.9)
2 Sixx  (9.8)
3 hedning  (9.7)
4 Irata  (9.7)
5 Tim  (9.7)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.044 sec.