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 > Stablising raster IRQ with DMA
2012-01-08 19:49
ChristopherJam

Registered: Aug 2004
Posts: 1409
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....
 
2013-07-28 16:04
zscs

Registered: Sep 2010
Posts: 49
Quote: Do you by any chance accidently have active sprites on the raster line you're stabalizing on?

Hm, it can happened, I'm going to check. Thanks for the tip!
2014-01-09 13:40
zscs

Registered: Sep 2010
Posts: 49
Quote: Hm, it can happened, I'm going to check. Thanks for the tip!

It was long time ago when I tried to stabilize the raster in my very old intro that I mentioned here, earlier. 4 days ago (and almost 1.5 years of inactivity:) I tried to stabilize an another intro (that I coded 21 years ago:-) and I could fix it with the "IRQ with DMA" technique. I got the example from Codebase: http://codebase64.org/doku.php?id=base:stable_irq_with_dma
So yesterday I fent myself quite motivated, therefore I tried to stabilize the IRQ in my another intro and after 3 hours of experiments with the code changes, finally I could stabilize the raster there as well! :)
OFF: I will release the intro very soon. The only thing that I need to do, compress it with a "packer", create .d64 image and copy the file to the image and upload. (Nothing special actually, however the DXYCP that I coded (and without sprites) can be interesting I guess.) ;) ON.
2014-01-10 04:09
dink
Account closed

Registered: Mar 2012
Posts: 30
I was about to say, that poke macro sure makes the code 6502 code look a lot nicer.
2014-01-11 12:33
Krill

Registered: Apr 2002
Posts: 2980
If i were to use such things, i'd prefer a "mov" macro-op, as in
mov #$00, $d020
My 2 bitcents.
2014-01-11 15:37
chatGPZ

Registered: Dec 2001
Posts: 11386
ab ins eck!
2014-01-11 15:46
tlr

Registered: Sep 2003
Posts: 1790
sys ($ffd2)... ;)
2014-01-11 21:41
Mace

Registered: May 2002
Posts: 1799
I tried the DMA method, but results vary.
How come that it sometimes jitters while with a different timing, it's stable?
And the single cycle I change, is at a point where I'd expect it to have no effect on the stabilization.

On second thought: could it be that I put the #$1b into $d011 too early afterwards?

.pc = $0810

	sei
	lda #$35	// switch off kernal
	sta $01
	
	ldx #$00
	stx $d015	// switch off sprites
	stx $3fff	// clear garbage gfx
	inx
	stx $d01a	// raster interrupt

	lda #$7f	// clear timers
	sta $dc0d
	sta $dd0d
	lda #$1b	// clear MSB of rasterline
	sta $d011
	lda #$33	// set triggering rasterline
	sta $d012
	ldx #<irq	// set IRQ vectors
	ldy #>irq
	stx $fffe
	sty $ffff

	lda $dc0d	// ack pending timers
	lda $dd0d
	lda #$01	// ack pending irq
	sta $d019

	cli
	jmp *		// infinite loop

irq:
	sta saveA
	stx saveX
	sty saveY
	
	ldx #$08
timeloop1:
	dex
	bne timeloop1

	nop
	nop

	lda $d012	// DMA
	and #$07
	ora #$18
	sta $d011

	bit $eaea
	bit $eaea
	bit $eaea
	bit $eaea
	bit $eaea
	bit $eaea
	bit $eaea
	bit $eaea
	bit $eaea
	bit $eaea
	bit $eaea
	bit $eaea
	bit $eaea	// jitters, change into bit $ea to stabilize

	ldy #$c0
	lda #$c8
	sty $d021
	sta $d021

	lda #$1b
	sta $d011

	asl $d019

.label saveA = * +1
	lda #$00
.label saveX = * +1
	ldx #$00
.label saveY = * +1
	ldy #$00
	rti
2014-01-12 08:57
Flavioweb

Registered: Nov 2011
Posts: 463
Dma trick to stabilize raster is more useful if used to start a cia timer (reverse counter method).
This avoid to care about idle gfx and screen display.
But is better for no background gfx with sprites over rasterbars (or sprites with open sideborder) parts.
2014-01-12 09:01
Mace

Registered: May 2002
Posts: 1799
That's what I was trying to do: open borders (using d020 instead of d016, to find the sweet spot).
2014-01-12 09:34
Flavioweb

Registered: Nov 2011
Posts: 463
I never tried it, but i remember some trick like
LDX #$0B
STA $D016,X
with in .A the color.
If executed with right timing it should open border and put color on screen...
But i have not really tried it...
It's done using a 6502 bug that read and discard value from base address before add .X and write to the dest address.
You can give a try +)
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
heavymett
Peacemaker/CENSOR/Hi..
Acidchild/Padua
HCL/Booze Design
MightyAxle
JEZ
Pantaloon/Fairlight
Freeze/Blazon
Guests online: 119
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 Diskmag Editors
1 Magic  (9.8)
2 hedning  (9.6)
3 Jazzcat  (9.5)
4 Elwix  (9.1)
5 Remix  (9.1)

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