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 > NMI Grounding vs. IRQ Raster interrupts
2011-03-08 14:55
TWW

Registered: Jul 2009
Posts: 545
NMI Grounding vs. IRQ Raster interrupts

Ello'

Right!

So If You ground an NMI (trigger it and don't acknowledge it) how come IRQ's are allowed?

Simple, You do the RTI which ends the NMI code but don't ack. the NMI 8-D

Can't for the life of me understand why people don't get that ;-)

cheers!
2011-03-08 22:46
Ventura
Account closed

Registered: Jan 2006
Posts: 67
NMI = Non Maskable Interrupt, it's oblivious to the interrupt flag: SEI, CLI all you want.
When the NMI doesn't get acknowledged you can always set the timer to count for you, usefull for DYSP w. sideborder?.

cheers back!

2011-03-10 09:18
ready.

Registered: Feb 2003
Posts: 441
Quote:
So If You ground an NMI (trigger it and don't acknowledge it) how come IRQ's are allowed?


to be precise, the IRQs are not allowed until the RTI of the NMI. While the NMI is being executed (i.e. before RTI), no IRQ will be served.
2011-03-10 11:09
Frantic

Registered: Mar 2003
Posts: 1648
I added a little section about this at the end of Ninja's article on how to block NMI's in case people may wonder about this in the future. Feel free to modify it in case you think I didn't explain it good enough.

http://codebase64.org/doku.php?id=base:nmi_lock
2011-03-10 13:10
TWW

Registered: Jul 2009
Posts: 545
Quote: Quote:
So If You ground an NMI (trigger it and don't acknowledge it) how come IRQ's are allowed?


to be precise, the IRQs are not allowed until the RTI of the NMI. While the NMI is being executed (i.e. before RTI), no IRQ will be served.


Which I believe was excatly the same as my conclusion:

"Simple, You do the RTI which ends the NMI code but don't ack. the NMI 8-D"

So yes you are excatly right :-)

@ Frantic: Looks good and detailed too me 8-b
2011-03-10 13:30
Ventura
Account closed

Registered: Jan 2006
Posts: 67
TWW: You beat me to it, but reading that article raises a question:
Does all that talk in the article either confuse or clarify things for people who like to know?.
2011-03-10 13:40
assiduous
Account closed

Registered: Jun 2007
Posts: 343
Quoting ready.
to be precise, the IRQs are not allowed until the RTI of the NMI. While the NMI is being executed (i.e. before RTI), no IRQ will be served.

to be even more precise IRQs are not allowed until the interrupt mask flag of CPU is cleared. when a NMI starts the I flag is set automatically and RTI clears the I flag among other things. if you clear the mask manually (using CLI) before quitting the NMI code with RTI,you can serve IRQs while executing your NMI.
2011-03-10 15:28
TWW

Registered: Jul 2009
Posts: 545
Quote: Quoting ready.
to be precise, the IRQs are not allowed until the RTI of the NMI. While the NMI is being executed (i.e. before RTI), no IRQ will be served.

to be even more precise IRQs are not allowed until the interrupt mask flag of CPU is cleared. when a NMI starts the I flag is set automatically and RTI clears the I flag among other things. if you clear the mask manually (using CLI) before quitting the NMI code with RTI,you can serve IRQs while executing your NMI.


No shit...


A CLI inside a NMI allows IRQs... Shit my head is spinning now.....

I guess you'd need to pay special attention to the stack O.o
2011-03-10 15:59
assiduous
Account closed

Registered: Jun 2007
Posts: 343
usually you dont need any other interrupts during nmi. but it may be useful if you want to keep related code in 1 block for clarity. for example in your nmi routine:-

1. a block of code that shouldnt be interrupted by any irq
2. cli (I flag cleared)
3. a block of code related to the one above where irqs are expected and can take priority
4. rti

since stack works on the last in first out basis you dont need any special handling
2011-03-10 17:18
TWW

Registered: Jul 2009
Posts: 545
Alright.

What if you got one IRQ running, then NMI occurs on top then you CLI inside the NMI, the "old IRQ" would have higer priority then the NMI?

What about BRK interrupt in all this?
2011-03-10 18:39
assiduous
Account closed

Registered: Jun 2007
Posts: 343
Quote:
What if you got one IRQ running, then NMI occurs on top then you CLI inside the NMI, the "old IRQ" would have higer priority then the NMI?

its not a matter of priority (the old irq source can be acknowlegded so even with the interrupt mask cleared the old irq wouldnt be retriggered) but irqs(and brk) share the same vector so any new irqs would land at the beginning of the old irq code and you probably wouldnt want it. allowing irqs in the nmi code is a risky thing and unless you can perfectly predict the outcome it should be avoided. im saying it can be done only as a fun fact- to explain whats the reason behind rti allowing new irqs on the hardware level =)
2011-03-10 22:21
Ventura
Account closed

Registered: Jan 2006
Posts: 67
Quote:
allowing irqs in the nmi code is a risky thing and unless you can perfectly predict the outcome it should be avoided.

Well, it isn't *that* hard to do, here's some proof:

;PAL only - needs sync. too btw

const_timer_speed1 = $4cc6
const_timer_speed2 = $4cc8


start
sei
lda #$35
sta $01
ldx #<irq
ldy #>irq
stx $fffe
sty $ffff
ldx #$00
stx $dc0e
stx $dd0d
stx $dd0e
inx
stx $d019
stx $d01a
lda #$1b
sta $d011
lda $d011
bpl *-3
lda $d011
bmi *-3
lda $d011
bpl *-3
ldx #<nmi
ldy #>nmi
stx $fffa
sty $fffb
ldx #<const_timer_speed1
ldy #>const_timer_speed1
stx $dd04
sty $dd05
ldx #$81
ldy #$01
stx $dd0d
sty $dd0e
end jmp end

timer_low
.byte <const_timer_speed1, <const_timer_speed2
timer_high
.byte >const_timer_speed1, >const_timer_speed2

raster_bah
.byte $00,$09,$02,$08,$0a,$0c,$0f,$07
.byte $01,$07,$0f,$0c,$0a,$08,$02,$09

irq
ldx #$0f
irq_
ldy raster_bah,x
lda $d012
cmp $d012
beq *-3
sty $d020
sty $d021
dex
bpl irq_
inc $d019
bit $dc0e
rti

nmi
.byte $a9 ; LDA #$..
nmi_
.byte 1
eor #1
sta nmi_
tax
lda timer_low,x
sta $dd04
lda timer_high,x
sta $dd05

cli

bit $dd0d
rti
2011-03-11 01:16
TWW

Registered: Jul 2009
Posts: 545
Ok. I tried it, I thought about it and I even think I understand it...

Now for the real question: When will this approach be beneficial compared to a regular raster compare and some tight timing (stabbing if neccessary)?

No I'm not asking coz I'm a snotnose I'm asking coz I am curious^^
2011-03-11 05:34
Ventura
Account closed

Registered: Jan 2006
Posts: 67
A regular raster compare/irq will only get you near a scanline, which can be convieniant for setting registers,
but not for rasterstuff which has to be exact, in most cases this will cost you cycles, but less than using this approach.

Benefits:

1. You can start it anywhere on the screen.
2. You don't need to set $d012
3. No more ugly padding to get the first scanline right.

This is just a quick written routine, experiment with it, add more functionality and find out for yourself.

Edit: And thank assiduous for explaining it, something I won't do, I'm kinda old when it comes to 64 :'(
2011-03-12 18:30
Powerslave

Registered: Dec 2006
Posts: 24
Can someone post example of demos using NMI interupts so that we understand the potential of this type of interupt?
I've found an old demo from 1990 (unreleased) in my diskbox were I used NMI to remove the sideborder for a fullscreen DYSP. But still I'm not sure what the benefit is compared with IRQ raster interupts.
2011-03-13 02:31
Martin Piper

Registered: Nov 2007
Posts: 722
Quoting Ventura
1. You can start it anywhere on the screen.


Not quite anywhere, there is still the opcode wobble to stabilise.
2011-03-13 03:42
Ventura
Account closed

Registered: Jan 2006
Posts: 67
Yes you can, even with that "wobble", which can be circumvented by triggering the NMI more than once a frame.
PAL: 63x312 = $4cc8
2011-03-13 10:07
Ninja

Registered: Jan 2002
Posts: 411
I usually use IRQ for VIC-based interrupts and NMI for CIA-based interrupts (e.g. double timer stable raster). That separation is convenient and nothing uncommon these days I'd say. There should be plenty of demos to examine.
2011-03-13 11:18
Martin Piper

Registered: Nov 2007
Posts: 722
Quoting Ventura
Yes you can, even with that "wobble", which can be circumvented by triggering the NMI more than once a frame.
PAL: 63x312 = $4cc8


You are wrong because the opcode wobble stops you targeting any cycle you like. An NMI is not magically stable just because you set the same timer value at the same source cycle. It wobbles depending on the length of the opcode that was executing when it was triggered.
The double NMI/IRQ method is used because the first triggered opcode does wobble and it needs known code to be executing to get stable for the second trigger.
2011-03-13 13:12
Ventura
Account closed

Registered: Jan 2006
Posts: 67
Thanks for the info: I'll be more specific next time, I was referring to scanlines.
Retrigging the NMI is far, far from a last minute insight, happy now?.
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
kbs/Pht/Lxt
Sepa/OCD
Andy/AEG
MCM/ONSLAUGHT
theK/ATL
Peacemaker/CENSOR/Hi..
New Design/Excess
MightyAxle
LDX#40
algorithm
Guests online: 100
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 No Listen  (9.6)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 Dawnfall V1.1  (9.5)
7 Rainbow Connection  (9.5)
8 Onscreen 5k  (9.5)
9 Morph  (9.5)
10 Libertongo  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Censor Design  (9.3)
5 Triad  (9.3)
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.055 sec.