Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in 
CSDb User Forums


Forums > C64 Coding > Stablising raster IRQ with DMA
2012-01-08 20:49
ChristopherJam

Registered: Aug 2004
Posts: 210
Stablising raster IRQ with DMA

I was a little surprised not to see this method on codebase64, as it's really quite old. It's most useful at the top of the screen, where you can do the DMA forcing in the border, but for that very reason I find it a useful prelude to (e.g.) line crunch and other HW scrolling techniques.

The concept's fairly simple; you start a character row above the visible area, set an interrupt for a subsequent non-badline, and force a DMA to absorb the unknown number of cycles between then and end-of-row. Set $d011 back to $1b, and the screen appears as normal!

A simple example:

#define poke(addr,val)	.(:lda #val:sta addr:.)
#define doke(addr,val)	.(:lda #<val:sta addr:lda #>val:sta addr+1:.)
#define endIRQ pla:tay:pla:tax:pla:rti
#define ackIRQ pha:lda $d019:sta $d019:txa:pha:tya:pha

	*= $0801-2
	.word *+2	; load address
	.byt $0b,$08,$0a,$00,$9e,$32,$30,$36,$31,0,0,0 ; 10 sys2061
main:
	poke($d021,$04)
	sta 646
	lda#147
	jsr $ffd2
	poke($d021,0)
	poke($0400,1)  ;something to see
	poke($0428,2)

	jsr IRQstart
loop:
	inc $7e7  ; a nice untidy main loop to ensure instability!
	bpl loop
	jmp loop

IRQstart
	poke($dc0d,$7f)	; kill CIA irq
	sei
	poke($01,  $35)	; disable ROM
	poke($d01a,$01) ; enable VIC irq
	poke($d011,$1b) ; clear high bit of irq rasterline
	poke($d012,$32) ; last invisible line
	doke($fffe,irq1 ) ; set irq vector
	cli
	rts
	
irq1:
	ackIRQ
	poke($d020,$0f)   ; this is unstable!
	poke($d011,$1a)   ; force partial badline before screen starts
	poke($d020,$0b)   ; this is stable ^_^
	poke($d011,$1b)   ; trigger normal re-fetch of first row of chars
	poke($d012,$ff)   ; set end-of-screen irq
	doke($fffe,irq2 )
	endIRQ

irq2:
	ackIRQ
	;ensure first row of chars is already being displayed when badline forced by irq1
	poke($d011,$18)
	poke($d012,$32	)
	doke($fffe,irq1 )
	endIRQ


(build with Fachat's xa)


Does anyone know why this technique is so rarely mentioned?

 
... 37 posts hidden. Click here to view all posts....
 
2014-01-16 16:48
Color Bar

Registered: Oct 2012
Posts: 23
Correct me if I'm wrong: If you set it to 8, the counter will go like this: 8,7,6,5,4,3,2,1,8,8,7,6,...

So instead of 0 it will take on the value 8.
2014-01-16 17:11
robo

Registered: Nov 2012
Posts: 6
I already thought about something like that.
But with #8 the eor #7 will result in branch-offset = #0f.
That would be wrong, since there are only 7 adresses to branch to, so the Offset has to be 0..6.
2014-01-16 18:04
robo

Registered: Nov 2012
Posts: 6
Color Bar, its exactly like you wrote.
I did a short test in vice by setting up a timer and watching the values in the monitor.

So, is it a bug or what is going on?
2014-01-16 18:35
Groepaz

Registered: Dec 2001
Posts: 6702
Quote:
when you need to stabilize every N raster lines, there's a huge gain from using CIA timers since you can stabilize anywhere on a line. Hermit's init code on codebase64 is nice and compact and can be generalized to give you a 63 or 65 cycle counter, and it's smooth sailing after that. Conceptually I don't think it's much more complicated than the double IRQ, and not as crazy as putting a jmp instruction at $dc02-$dc04.

IMHO in pretty much all cases that justify using this timer method you'd also want to use the mentioned "ninja method" (best term ever :=)) for ACKing the interrupt, because every single cycle counts in these cases :)
2014-01-16 18:38
Color Bar

Registered: Oct 2012
Posts: 23
Quote: Color Bar, its exactly like you wrote.
I did a short test in vice by setting up a timer and watching the values in the monitor.

So, is it a bug or what is going on?


Maybe you should check this thread:
http://csdb.dk/forums/?roomid=11&topicid=65658&showallposts=1

There the same thing is noticed by ready. and Copyfault.
2014-01-16 19:06
Color Bar

Registered: Oct 2012
Posts: 23
Quote: Quote:
when you need to stabilize every N raster lines, there's a huge gain from using CIA timers since you can stabilize anywhere on a line. Hermit's init code on codebase64 is nice and compact and can be generalized to give you a 63 or 65 cycle counter, and it's smooth sailing after that. Conceptually I don't think it's much more complicated than the double IRQ, and not as crazy as putting a jmp instruction at $dc02-$dc04.

IMHO in pretty much all cases that justify using this timer method you'd also want to use the mentioned "ninja method" (best term ever :=)) for ACKing the interrupt, because every single cycle counts in these cases :)


haha ... It just HAD to be a guy named "ninja" to invent this. Make crazy jumps and land perfectly every time :-)
2014-01-17 15:51
Color Bar

Registered: Oct 2012
Posts: 23
Quoting Color Bar

Therefore, in my code I did not use a raster interrupt but just waited in the main routine for $d01f to become unequal to zero:

sei
...
;Place sprites
...
lda $d01f ;Clear sprite-to-background collision register
lda #$ff ; Turn sprites on
sta $d015
lda $d01f ; Wait for nonzero collision bits
beq *-3 ;
;Add delay depending on number of zero bits
asl
bcc *+2
...
...
;Set timer
;Continue main program
cli
rts


I peeked into my code and saw that I had put an "ora #$01" after the "beq *-3". It seems that reading $d01f clears it, but with some delay, so it can happen that you read $d01f while the beam is just before the sprites and then you branch back, read it again and the higher bits are set, but bit 0 is not. This should not happen if you read $d01f in the raster IRQ version (since you read $d01f only once then).

Or maybe the bits of $d01f are set with some delay. I do not really know.
2014-01-17 19:57
MagerValp

Registered: Dec 2001
Posts: 696
Quoting Groepaz
Quote:
when you need to stabilize every N raster lines, there's a huge gain from using CIA timers since you can stabilize anywhere on a line. Hermit's init code on codebase64 is nice and compact and can be generalized to give you a 63 or 65 cycle counter, and it's smooth sailing after that. Conceptually I don't think it's much more complicated than the double IRQ, and not as crazy as putting a jmp instruction at $dc02-$dc04.

IMHO in pretty much all cases that justify using this timer method you'd also want to use the mentioned "ninja method" (best term ever :=)) for ACKing the interrupt, because every single cycle counts in these cases :)

Ninja's method is impractical in some cases, since there's effectively no vector if you need to switch between several handlers, and it clobbers low ram. But if you need every last cycle, go for it.
2014-01-17 20:02
MagerValp

Registered: Dec 2001
Posts: 696
Quoting robo
I have a question regarding the cia-timer method:

When setting $dc04 to #8, will the timer really count only from 7..1?


As others pointed out, it's 8..0 (sort of), but consider setting dc04 to 62 or 64 instead. This effectively gives you free NTSC fixing and an inverted x counter that lets you stabilize anywhere on the line.
2014-01-18 10:53
Color Bar

Registered: Oct 2012
Posts: 23
Quote: Color Bar, its exactly like you wrote.
I did a short test in vice by setting up a timer and watching the values in the monitor.

So, is it a bug or what is going on?


It't not a bug, it's a feature :-)
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
Curlin/Hitmen
diver4d
Zorch
Total Chaos
N3XU5/Hitmen/Oxyron
redback
Tyke
Lemming/Offence/N0S/..
Cargo/Singular Crew
iAN CooG/HVSC
Guests online: 40
Top Demos
1 Edge of Disgrace  (9.7)
2 Coma Light 13  (9.6)
3 Wonderland XII  (9.6)
4 We Are All Connected  (9.5)
5 Deus Ex Machina  (9.3)
6 Andropolis  (9.3)
7 +H2K  (9.3)
8 2011 - A Press Space..  (9.2)
9 Continuum  (9.2)
10 Krestage  (9.2)
Top onefile Demos
1 Daah, Those Acid Pil..  (9.6)
2 Dawnfall  (9.3)
3 One-Der  (9.2)
4 Tiki Pahu!  (9.1)
5 Safe VSP  (9.0)
6 Te-Te-Te-TechTech It..  (9.0)
7 Cubase64  (8.9)
8 Are we there yet?  (8.9)
9 Krestage 3 - More We..  (8.8)
10 Frodigi 2  (8.8)
Top Groups
1 Booze Design  (9.4)
2 Crest  (9.4)
3 Censor Design  (9.3)
4 Oxyron  (9.3)
5 Chorus  (9.3)
Top NTSC-Fixers
1 Pudwerx  (9.8)
2 Danzig  (9.7)
3 Horizon  (9.7)
4 Stormbringer  (9.7)
5 Booze  (9.5)

Home - Disclaimer
Copyright © No Name 2001-2014
Page generated in: 0.259 sec.