Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
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: 1403
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-31 13:43
ChristopherJam

Registered: Aug 2004
Posts: 1403
KERNAL/BASIC only uses IRQs

CIA#1 ($dc00) - IRQ
CIA#2 ($dd00) - NMI

(and, lol @ Krill :D)
2023-10-31 14:34
Cruzer

Registered: Dec 2001
Posts: 1048
Ah, CIA1 produces IRQs? Wow, how didn't I know this? Probably because you don't learn anything from just copy/pasting the same old block of code when doing interrupts. Glad I checked this thread so I won't forever be one of them people in the back. \o/
2023-10-31 15:54
Oswald

Registered: Apr 2002
Posts: 5074
Quote: KERNAL/BASIC only uses IRQs

CIA#1 ($dc00) - IRQ
CIA#2 ($dd00) - NMI

(and, lol @ Krill :D)


hitting restore (key) triggers an NMI, so no both are used.
2023-10-31 16:20
ChristopherJam

Registered: Aug 2004
Posts: 1403
Cruzer - glad something good came out of the thread :)

Oswald - ok ok, "KERNAL/BASIC doesn't use CIA#2 or VIC as interrupt sources"
2023-10-31 22:15
Copyfault

Registered: Dec 2001
Posts: 468
Quoting Krill
My point was that the raster interrupt...
                    lda #0x01
                    sta 0xD019
                    ; ... may trigger here
                    sta 0xD01A
                    ; ... and then fire only here
                    rts
Should usually not be a problem, but... =)
Really? Didn't some testprog show that it's more like
                 lda #0x01
                 sta 0xD019
                     ; ... may trigger here
                 sta 0xD01A
                     ; ... is ack'd here
                 rts ; ... next opcode is ececuted
                     ; ... and irq routine starts here
? Thought this was the "result" of the TIL: The instruction after SEI can be executed before a pending IRQ is handled thread, no? In post #99 of this thread MagerValp linked the testprog I have in mind.
2023-10-31 23:10
Krill

Registered: Apr 2002
Posts: 2940
Quoting Copyfault
Quoting Krill
My point was that the raster interrupt...
                    lda #0x01
                    sta 0xD019
                    ; ... may trigger here
                    sta 0xD01A
                    ; ... and then fire only here
                    rts
Should usually not be a problem, but... =)
Really? Didn't some testprog show that it's more like
                 lda #0x01
                 sta 0xD019
                     ; ... may trigger here
                 sta 0xD01A
                     ; ... is ack'd here
                 rts ; ... next opcode is ececuted
                     ; ... and irq routine starts here
? Thought this was the "result" of the TIL: The instruction after SEI can be executed before a pending IRQ is handled thread, no? In post #99 of this thread MagerValp linked the testprog I have in mind.
Maybe. But that would just underline my point. =)
2023-10-31 23:34
spider-j

Registered: Oct 2004
Posts: 483
Can this happen to CIA2 NMI too? In the latest version of my framework I switched to that for playing music to get rid of the "SEI problem".

Of course: you can break it by pressing RESTORE. But are there any sideeffects without user interaction that can happen, once you setup the timer for a PAL frame?
2023-11-01 00:43
Krill

Registered: Apr 2002
Posts: 2940
Quoting spider-j
Can this happen to CIA2 NMI too? In the latest version of my framework I switched to that for playing music to get rid of the "SEI problem".

Of course: you can break it by pressing RESTORE. But are there any sideeffects without user interaction that can happen, once you setup the timer for a PAL frame?
What is the SEI problem, specifically?

And playing regular music (no samples) via NMI? Dunno, i'd rather prefer restore-proof blocked NMI. =)
2023-11-01 01:16
spider-j

Registered: Oct 2004
Posts: 483
Quoting Krill
What is the SEI problem, specifically

My group mates ignoring the "coding guidelines" ;-) And I must admit, after switching to the NMI solution I also found everything easier to handle. You can just do with raster IRQs what you want to do and yes there is a NMI "somewhere" that will steal you cycles but it is way easier to handle than let's say moving your IRQ lines for one effect and caring about the music (avoiding frame drops or too long player call "distances"). Yeah of course the user can destroy that by pushing RESTORE, but after all tests I did even if your NMI is nothing more than "RTI" mindlessly hitting RESTORE will make problems anyway. So I decided that pressing RESTORE shouldn't be considered a "real use case".
2023-11-01 04:15
ChristopherJam

Registered: Aug 2004
Posts: 1403
A few minor points.

Firstly, my understanding is that NMIs can be prevented altogether (like, not even the single byte RTI called) if you just trigger an NMI from CIA#2 and never acknowledge it. Not something I've ever bothered with, but it's a solid option.

Secondly, minor quibble about the comments here:
                 lda #0x01
                 sta 0xD019
                     ; ... may trigger here
                 sta 0xD01A
                     ; ... is ack'd here
                 rts ; ... next opcode is ececuted
                     ; ... and irq routine starts here


The write to d019 clears the latch ('acknowledges' previous raster matches), d01a enables interrupts, doesn't acknowledge.

But yes, Copyfault is correct - going to read TIL: The instruction after SEI can be executed before a pending IRQ is handled properly I see that I missed the tail end of the discussion last time round, and it indeed confirms my experiments from yesterday. Even if the interrupt condition latch is already set, the instruction after the write to $d01a is still executed before the interrupt occurs.

(for a hot minute I thought Copyfault was erroneously drawing a connection between the post-SEI prefetch and the $d01a thing, but I was just misled by that other post changing topics partway down the page. My bad.)
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
acrouzet/G★P
Dr. Doom/RAD
Guests online: 87
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 Comaland 100%  (9.6)
8 Wonderland XIV  (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 Morph  (9.5)
8 Dawnfall V1.1  (9.5)
9 Onscreen 5k  (9.5)
10 Daah, Those Acid Pil..  (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 Graphicians
1 Mirage  (9.7)
2 Archmage  (9.7)
3 Facet  (9.6)
4 Mermaid  (9.6)
5 Carrion  (9.6)

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