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....
 
2012-01-11 07:42
zscs

Registered: Sep 2010
Posts: 49
I'm (an old:) new to C=64 coding since I haven't touched any asm code for 17.5 years. ...until last Saturday, when I found an old unfinished one-file demo on one of my workdisks. ;) A really interesting one, because I have already tried to implement 5-6 raster stabilisation methods to it but the raster is still unstable... I used methods that I found here in the forums and at Codebase64.org. (I can work only with Vice 2.2 and I use an old SMON $C000 for coding/experiments.) Some methods, like Hermit's D012 algorythm (example 1) hangs in Vice because the self-modifying code has a bug (or at least it seems it has a bug - I debugged the process with Vice's built-in monitor).
It's getting more and more frustrating to me but I don't want to give it up! :) Nevertheless, if I send a file to anyone who would like to take a look to my code, could he (you) please help me, what's wrong here? I can send a Vice Snapshot file in .vsf format. Well, as I mentioned, I just started to learn asm again so probably I did a stupid and easily fixable bug in my code. :)
So just drop me a mail to zscsoka at hotmail dot com, and I will send you a file.
Thanks a lot in advance!

BR,
zs
2013-07-28 13:10
zscs

Registered: Sep 2010
Posts: 49
After 1.5 years I started to stabilize the raster again in my crappy intro. I think I totally got stucked. I tried all methods that I found here and at Codebase. Maybe I haven't noticed something which does not allow me to stabilise the raster. :)
Actually, I have a 2x2 sideborder scroll at the upper part of the screen, center part is a DXYCP scroller in a 16x16 character grid with a moving sprite logo behind of the scroller. (Problem: the sideborder scroll's sides are blinking, raster is not stable.)
Mainly I tried to use the very same method that I coded 19 years ago here (Unforeseen Open part, sideborder scroll with sideborder logo with text "Unforeseen"): Attempt One and Unforeseen Open [unfinished]
(Yes, I'm a lamer newbie again but I don't give the things up easily) :)
2013-07-28 15:14
JackAsser

Registered: Jun 2002
Posts: 2014
Do you by any chance accidently have active sprites on the raster line you're stabalizing on?
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
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
Luca/FIRE
Peacemaker/CENSOR/Hi..
Fred/Channel 4
Isildur/Samar
Guests online: 95
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 Crackers
1 Mr. Z  (9.9)
2 Antitrack  (9.8)
3 OTD  (9.8)
4 Fungus  (9.8)
5 S!R  (9.8)

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