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: 1424
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 11:59
Krill

Registered: Apr 2002
Posts: 3098
Okay then! =)
php
pla
ora #$04
pha
plp
2023-10-31 12:13
Martin Piper

Registered: Nov 2007
Posts: 739
Quote: Okay then! =)
php
pla
ora #$04
pha
plp


You beat me to it. :)
2023-10-31 12:36
spider-j

Registered: Oct 2004
Posts: 505
Quoting Krill
Okay then! =)
php
pla
ora #$04
pha
plp

*lol* Thank you Krill. Made my day :-)
2023-10-31 13:30
Cruzer

Registered: Dec 2001
Posts: 1051
Wait a second... If the Kernal/Basic only uses NMIs, how come you can disable them with sei? I mean, if you do something like this:
!:	inc $d020
	jmp !-
You will see the code getting interrupted when pressing down keys. But start out with a sei, and there are no interruptions:
	sei
!:	inc $d020
	jmp !-
2023-10-31 13:43
ChristopherJam

Registered: Aug 2004
Posts: 1424
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: 1051
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: 5127
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: 1424
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: 487
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: 3098
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. =)
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
Mibri/ATL^MSL^PRX
TheRyk/MYD!
CopAss/Leader
Core/VPN
Spinball/Excess
Sixx
Jazzcat/Onslaught
d0c
HBH.ZTH/Abnormal
Guests online: 316
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Codeboys & Endians  (9.7)
4 Mojo  (9.6)
5 Coma Light 13  (9.6)
6 Edge of Disgrace  (9.6)
7 Signal Carnival  (9.6)
8 Wonderland XIV  (9.5)
9 Uncensored  (9.5)
10 Comaland 100%  (9.5)
Top onefile Demos
1 Nine  (9.7)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.5)
6 Scan and Spin  (9.5)
7 Onscreen 5k  (9.5)
8 Grey  (9.5)
9 Dawnfall V1.1  (9.5)
10 Rainbow Connection  (9.5)
Top Groups
1 Artline Designs  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Performers  (9.3)
5 Censor Design  (9.3)
Top Diskmag Editors
1 Magic  (10)
2 Jazzcat  (9.5)
3 hedning  (9.2)
4 Elwix  (9.1)
5 Peter  (9.0)

Home - Disclaimer
Copyright © No Name 2001-2025
Page generated in: 0.051 sec.