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: 1378
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?

2012-01-09 11:02
Skate

Registered: Jul 2003
Posts: 490
@ChristopherJam: Codebase64 is still far from being a complete code/tutorial resource. Many many known tricks are not explained there. Probably that's why this was missing, too. Also this technique doesn't look that flexible since you must catch the interrupt at a fixed area. Still very useful though, thanks for sharing.
2012-01-09 11:11
JackAsser

Registered: Jun 2002
Posts: 1989
Quote: @ChristopherJam: Codebase64 is still far from being a complete code/tutorial resource. Many many known tricks are not explained there. Probably that's why this was missing, too. Also this technique doesn't look that flexible since you must catch the interrupt at a fixed area. Still very useful though, thanks for sharing.

Which is good enough for setting up the initial timer, THEN use the timer to jitter compensate at any raster line on any frame.

(i'd choose a 63 cycle timer though...)
2012-01-09 11:23
Flavioweb

Registered: Nov 2011
Posts: 447
Here is my version.
Works stable in PAL and NTSC.
(CA65 version, comile with cl65 -tc64 filename.asm)
; ------------------------------------------------------------------------------
rasterlogo1	= $34
; ------------------------------------------------------------------------------
	.code 
	.org $07ff
; ------------------------------------------------------------------------------

; ------------------------------------------------------------------------------
; "sys" basic
; ------------------------------------------------------------------------------

	.word *+2	;loading bytes
basicstub:
	.word @nextline
	.word 2012	; line number
	.byte $9e	; sys
	.byte <(((init / 1000) .mod 10) + $30)
	.byte <(((init / 100 ) .mod 10) + $30)
	.byte <(((init / 10 ) .mod 10) + $30)
	.byte <(((init ) .mod 10) + $30)
	.byte 0		;end of line
@nextline:
	.word 0		;empty line == end basic code

init:
	lda #$00
	sta $d020
	sta $d021
	sta $3fff
; ------------------------------------------------------------------------------
;set up irq
; ------------------------------------------------------------------------------
setup:	lda #$1b
	sta $d011

	lda #rasterlogo1
	sta $d012

	ldy #$00
	sty $d015 

	sei  

	lda #$7f
	sta $dc0d 
	sta $dd0d 

	lda #$35   
	sta $01    

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

	lda #$01   
	sta $d01a

	lda $dc0d     
	lda $dd0d
	lda #$01
	sta $d019    

	cli        

jmp *
; ------------------------------------------------------------------------------
; Routine in interrupt
; ------------------------------------------------------------------------------
irq1:
	ldx #$08
	dex
	bne *-1

	lda $d012
	and #$07
	ora #$18
	sta $d011
	cmp $00,x
	cmp $00,x
	cmp $00

	inc $d021
	inc $d021
	inc $d021
	inc $d021
	inc $d021
	inc $d021


	ldy #$00
	sty $d021

	lda #$1b
	sta $d011

	asl $d019  

	rti
2012-01-09 11:24
enthusi

Registered: May 2004
Posts: 675
oh, and please add it to codebase in case you didnt already :)
2012-01-09 15:09
chatGPZ

Registered: Dec 2001
Posts: 11108
and incase you do, remove that poke stuff... *please* =P
2012-01-09 16:19
ChristopherJam

Registered: Aug 2004
Posts: 1378
@Groepaz hehe. My assembler of choice for many many years was FASSEM; I got used to doing a lot of set up in BASIC, and old habits die hard ;)
2012-01-09 20:04
Frantic

Registered: Mar 2003
Posts: 1627
@Christopher: Codebase is only a click away — pokes or not! :)

http://codebase64.org/

...and more specifically:

http://codebase64.org/doku.php?id=base:interrupts#stable_timing

As someone said, there are still many areas to fill in on codebase, waiting for contributions. :)
2012-01-11 07:42
zscs

Registered: Sep 2010
Posts: 45
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: 45
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: 1989
Do you by any chance accidently have active sprites on the raster line you're stabalizing on?
 
... 37 posts hidden. Click here to view all posts....
 
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
CA$H/TRiAD
FABS/HF
Rico/Pretzel Logic
Oswald/Resource
Fred/Channel 4
csabanw
t0m3000/ibex-crew
Flex/Artline Designs
Guests online: 131
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 Bromance  (9.6)
10 Memento Mori  (9.6)
Top onefile Demos
1 It's More Fun to Com..  (9.7)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 Rainbow Connection  (9.5)
6 TRSAC, Gabber & Pebe..  (9.5)
7 Onscreen 5k  (9.5)
8 Wafer Demo  (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 Swappers
1 Derbyshire Ram  (10)
2 Jerry  (9.8)
3 Violator  (9.8)
4 Acidchild  (9.7)
5 Starlight  (9.6)

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