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


Forums > C64 Coding > TIL: The instruction after SEI can be executed before a pending IRQ is handled
2017-11-07 15:56
Krill

Registered: Apr 2002
Posts: 2825
TIL: The instruction after SEI can be executed before a pending IRQ is handled

As described here: http://visual6502.org/wiki/index.php?title=6502_Timing_of_Inter..

I never knew this, after all those years, and thought i'd share this as a heads-up.

Thanks to Bubis for pointing it out to me!
 
... 89 posts hidden. Click here to view all posts....
 
2017-11-08 18:09
Oswald

Registered: Apr 2002
Posts: 5017
Quote: SEI doesn't prevent IRQs from happening, it just stops the CPU from handling them. Odds are good that you have a pending IRQ when you CLI, which means you have to have extra setup code to clear that. So for your generic $080d setup code, simply do
lda #$7f
sta $dc0d
before setting up a raster IRQ instead of using SEI.


you also need lda $dc0d to clear the pending irq, lda #$7f.. just stops more to happen. afaik.

lda #$7f
sta $dc0d
sta $dd0d

lda $dc0d
lda $dd0d

to be on the safe side.
2017-11-08 19:47
lft

Registered: Jul 2007
Posts: 369
Yes, but the point is that if you do
   lda #$7f
   sta $dc0d

before turning off interrupts, then you don't have to clear the flag. If there is an interrupt pending, it will be invoked right now, once. Then it will be off.

On a side note, there is no need to disable CIA2 interrupts (NMI) at the beginning of a program that is launched from BASIC. They aren't active in that environment.
2017-11-08 19:48
Krill

Registered: Apr 2002
Posts: 2825
Quoting MagerValp
I think you're reading the trace wrong. The next instruction following an SEI can be fetched, but not executed if an IRQ occurs during the SEI. The instruction will be re-fetched and executed following the RTI.
You're probably right, that makes a lot more sense. The text on visual6502.org is a bit ambiguous.

Oswald: I guess it's safe to assume that previously installed interrupt handlers would acknowledge their IRQs until you disable them. So don't exchange one cargo cult for another. :)

But anyhow, SEI/CLI is required when you install interrupt hooks on top of pre-existing handlers, especially if you have no knowledge of which interrupts are currently active and shall remain so.
2017-11-08 20:12
Oswald

Registered: Apr 2002
Posts: 5017
ah right, my eye didnt catch the instead :)thanks.
2017-11-08 20:17
Krill

Registered: Apr 2002
Posts: 2825
Quoting lft
On a side note, there is no need to disable CIA2 interrupts (NMI) at the beginning of a program that is launched from BASIC.
You do, however, want to trigger one NMI that you never acknowledge, so the pesky restore key won't disrupt your meticulously hand-crafted timing. :)
2017-11-08 20:38
Oswald

Registered: Apr 2002
Posts: 5017
I dont care about restore, if the user wants to crash the demo let it be. its his own fault :)
2017-11-08 20:46
lft

Registered: Jul 2007
Posts: 369
The enemy (nmi?) cannot push RESTORE if you disable his hand.
2017-11-08 21:05
chatGPZ

Registered: Dec 2001
Posts: 11100
Quote:
I dont care about restore

i've switched to just pointing the NMI vectors to some silly routine that punishes the bastard who pressed RESTORE accordingly :)
2017-11-09 14:43
TWW

Registered: Jul 2009
Posts: 541
Ground the fucker ^^
2017-11-09 15:18
MagerValp

Registered: Dec 2001
Posts: 1055
For reference, here's a bog standard raster IRQ setup that'll work every time if run from basic:
	lda #$7f
	sta $dc0d

	lda #$35
	sta $01

	lda #$1b
	sta $d011
	lda #$fa
	sta $d012

	lda #<irq
	sta $fffe
	lda #>irq
	sta $ffff

	lda #1
	sta $d019
	sta $d01a
NB: Clearing pending IRQs with $d019 is not strictly necessary if you run from a freshly reset machine (the kernal writes $0f to $d019 on reset), but if something else ran before and exited to the basic prompt there may be an unacknowledged raster IRQ pending.
Previous - 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 - 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
Courage
Monte Carlos/Cascade
CA$H/TRiAD
hedning/G★P
kbs/Pht/Lxt
chesser/Nigaz
Guests online: 78
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 No Bounds  (9.6)
7 Uncensored  (9.6)
8 Wonderland XIV  (9.6)
9 The Ghost  (9.6)
10 Bromance  (9.6)
Top onefile Demos
1 It's More Fun to Com..  (9.8)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 Rainbow Connection  (9.5)
6 Wafer Demo  (9.5)
7 TRSAC, Gabber & Pebe..  (9.5)
8 Onscreen 5k  (9.5)
9 Dawnfall V1.1  (9.5)
10 Quadrants  (9.5)
Top Groups
1 Oxyron  (9.3)
2 Nostalgia  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Organizers
1 Burglar  (9.9)
2 Sixx  (9.8)
3 hedning  (9.7)
4 Irata  (9.7)
5 MWS  (9.6)

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