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
 
... 36 posts hidden. Click here to view all posts....
 
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.
2023-10-30 22:17
JackAsser

Registered: Jun 2002
Posts: 2014
Quote: y'all make it sound too easy, there's music sync to worry about too, frameskips are fugly.

That’s what you avoid by NOT doing SEI/CLI
2023-10-30 22:40
Burglar

Registered: Dec 2004
Posts: 1066
Quote: That’s what you avoid by NOT doing SEI/CLI

yes, but it's not the full story, u dont know when (rasterline) u arrive, so u also dont know if music played this frame or not, there may be multiple irqs.

and u dont want to modify the rasterline the music is playing at too much (or at least not at once).
2023-10-30 22:49
Cruzer

Registered: Dec 2001
Posts: 1048
Quoting Burglar
yes, but it's not the full story, u dont know when (rasterline) u arrive, so u also dont know if music played this frame or not, there may be multiple irqs.

and u dont want to modify the rasterline the music is playing at too much (or at least not at once).
Whatcha talking about? Not doing SEI/CLI fixes all this. Just remove SEI/CLI from your code and it automatically becomes a perfectly linked and sync'ed trackmo. :D
2023-10-30 23:17
chatGPZ

Registered: Dec 2001
Posts: 11290
Just use a proper dubstep soundtrack
2023-10-30 23:27
Krill

Registered: Apr 2002
Posts: 2940
Is it this time of the year again. But lemme try to add a twist to this very old discussion.

A more or less interesting detail is that when coming from BASIC, the VIC raster interrupt flag is ALWAYS set.
Meaning that when you don't clear the latch by writing a 1-bit to $D019 bit 0, the interrupt will trigger immediately after unmasking it via LDA #1 : STA $D01A.

Take note that a raster interrupt may be flagged in the 3 (or 4?) cycles between clearing the latch and unmasking the interrupt.

I'll stop here and let yous dwell on this for a bit as to what this might or might not mean for timing-sensitive routines like stable-raster clockslides. =)
2023-10-31 02:40
Martin Piper

Registered: Nov 2007
Posts: 698
I think, in the C64 world, the SEI is there because the IRQ level interrupt can have a trigger that comes from more than one source, it's not just the CIA it's also the VIC, for example.

This means that technically it's not possible to completely stop all IRQ sources with just one store to $dc0d. It's not an atomic operation because you also need to stop the VIC trigger as well.

In theory it could be the case that even if the $dc0d source is disabled in the mainline (outside the IRQ), a raster IRQ could be triggered which then enables the $dc0d source before it returns, which then means a mainline VIC trigger disable would not guarantee the IRQs are really off.

The SEI then basically is an atomic way of guaranteeing that IRQs are stopped before then having to disable their triggers, and acknowledge those potential triggers, before continuing.

Of course this doesn't handle the case when an NMI could enable a raster or CIA IRQ trigger. However at least for NMI triggers then don't happen because of the VIC and their control is via $dd0d.
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
E$G/HF ⭐ 7
Matt
Scooby/G★P/Light
Sychamis
bugjam
Da Snake
megasoftargentina
alwyz/udi
tlr
MWR/Visdom
cobbpg
Jedfox/Exclusive ON
Guests online: 141
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 Logo Graphicians
1 Sander  (9.8)
2 Mermaid  (9.5)
3 Facet  (9.4)
4 Shine  (9.4)
5 Pal  (9.4)

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