Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
 Welcome to our latest new user eightbitswide ! (Registered 2024-12-24) You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Stable rasters, again...
2004-07-20 08:05
Trash

Registered: Jan 2002
Posts: 122
Stable rasters, again...

I'm really no newbie at this and I've got a few ideas for some new parts I want to put together but I can't seem to get my rasters stable.

Here's the code, what am I doing wrong?

(Only tested in Vice since my C128 and C64 ain't allowed in the livingroom according to my better half)

* = $0900
;-------------------------------------------------------------------------
rasterrow = $fb
;-------------------------------------------------------------------------
sei
lda #$7f
sta $dc0d
lda #<stableraster
sta $fffe
lda #>stableraster
sta $ffff
lda #rasterrow
sta $d012
lda #$1b
sta $d011
lda #1
sta $d01a
sta $d019
cli
jmp *
;-------------------------------------------------------------------------
stableraster
lda #rasterrow ;2
cmp $d012 ;6
beq newrow ;8 / 9
dec $d012 ;14
bit $ea ;17
nop ;19
adc #1 ;21
cmp $d012 ;
beq *+2 ;
;-------------------------------------------------------------------------
inc $d019 ;Trigger a new interrupt
jsr maincode ;
jmp $ea81 ;done
;-------------------------------------------------------------------------
newrow
inc $d012 ;
inc $d019 ;Trigger a new interrupt
cli
.byte $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea ; 16 * 2 = 32
.byte $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea ; 16 * 2 = 32
.byte $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea ; 16 * 2 = 32
jmp *-48
;-------------------------------------------------------------------------
maincode
inc $d020
dec $d020
rts
2004-07-20 08:18
Stryyker

Registered: Dec 2001
Posts: 468
Walk through it remembering the CPU will delay somehting like 1 cycles then it executes your code. On top of that it could be delayed by an opcode when the IRQ happens. They delay could be up to 6 or so cycles.

Did you read the VIC Artikle (sic)? From this and CBM Hackers you should learn enough to create a stable raster. Maybe you could walk us through your code and reasons/logic so we can correct you. $D012 is only the Y position. So by the time your code executes it could be anywhere along the line - hence why people have various methods. I personally use the double IRQ method. It creates a 1 cycle jitter which is normally easy to fix.
2004-07-20 08:22
Trash

Registered: Jan 2002
Posts: 122
This IS the double IRQ-method, just modified to be small and simple to use.
When you get to the label 'newrow', I create the one-cycle-delay by executing a bunch of nops ($ea). So in practice both of us are using the same routine, but my version seems to have a flaw somewhere :-(
2004-07-20 08:33
Ninja

Registered: Jan 2002
Posts: 411
So, what happens? Small jitter, heavy flickering (I am too lazy to type it in ;))? From a glimpse, following suggestions:

After 'LDA #$7F, STA $Dx0D', always do 'LDA $Dx0D' to clear the latch.

You change the vector $FFFE/F (is $01 set to $35?) and return from interrupt with $JMP $EA81. Should give you nice stack problems :)
2004-07-20 08:46
Oswald

Registered: Apr 2002
Posts: 5094
at first you should add before cli:

lda #$35
sta $01
lda $dc0d
lda $dd0d

second:

uhh this code is a mess.. the same routine for 2 purpose :)

test this code wether its at the right X position on the screen:

cmp $d012 ;
beq *+2 ;

by changing it to:

lda $d012
sta $d020

(remove all other d020 writes)

now adjust timing until the border keeps flashing, then you found the timing for the cmp.

third thing:

jmp $ea81 will do something like: pla tay pla tax pla rti, but you havent saved anything to the stack at the start of the irq!! so use a rti instead.


2004-07-20 10:20
Trash

Registered: Jan 2002
Posts: 122
Thanks for your help, now all I have to do is remember how bankswitching worked, but that I'll do on my own.

Oh, the when finished looks like this, just so noone else will bug you about unstable rasters :-):
* = $0801
.byte $0c, $08, $00, $00, $9e, $20, $32, $33
.byte $30, $34, $00, $00, $00, $00, $00, $00

* = $0900
;-------------------------------------------------------------------------
rasterrow = $4d
;-------------------------------------------------------------------------
sei
lda #$7f
sta $dc0d
lda $dc0d
lda #rasterrow
sta $d012
lda #$1b
sta $d011
lda #1
sta $d01a
sta $d019
lda #$35
sta $01
lda #<stableraster
sta $fffe
lda #>stableraster
sta $ffff
cli
jmp *
;-------------------------------------------------------------------------
stableraster
lda #rasterrow
cmp $d012
beq newrow
dec $d012
inc $d019 ; Trigger a new interrupt
.byte $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea
.byte $ea, $ea, $ea, $ea, $ea, $ea
adc #1
cmp $d012
beq * + 2
;-------------------------------------------------------------------------
jsr maincode ;
rti ; Done
;-------------------------------------------------------------------------
newrow
inc $d012 ;
inc $d019 ; Trigger a new interrupt
cli
.byte $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea ; 16 * 2 = 32
.byte $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea ; 16 * 2 = 32
.byte $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea ; 16 * 2 = 32
jmp *-48
;-------------------------------------------------------------------------
maincode
rts
2004-07-20 14:00
Oswald

Registered: Apr 2002
Posts: 5094
We're glad we could help :) But I guess everyone likes to do his own routine, even with help, so probably this wasnt the last topic about it :)
2004-07-20 15:38
SIDWAVE
Account closed

Registered: Apr 2002
Posts: 2238
Don't do cmp xx for D012, it's a waste if time, instead just write a new D012 and new intvector, then it skips to that line immediately. Last int then points to the first (0314/15 fffe/ff)
2004-07-20 18:38
Trash

Registered: Jan 2002
Posts: 122
Well, since that time is going to be wasted anyway I'll figured I could use it to trigger the next interrupt and it seems to work without any problems. So I'll problably keep the code as it is now since it's quite compact, works fine and it fit my purposes.
2004-07-20 19:49
Cruzer

Registered: Dec 2001
Posts: 1048
Now we're talking stable rasters - anyone knows if there's a way to do it if you're not just jumping to * outside the irq, but doing something else that takes more cycles/command? And preferrably a way that doesn't waste too many additional rasterlines ofcourse.
2004-07-20 19:58
TDJ

Registered: Dec 2001
Posts: 1879
"(Only tested in Vice since my C128 and C64 ain't allowed in the livingroom according to my better half)"

I think you need a better better half more than you need stable rasters :)
2004-07-20 20:43
Trash

Registered: Jan 2002
Posts: 122
Quote: Now we're talking stable rasters - anyone knows if there's a way to do it if you're not just jumping to * outside the irq, but doing something else that takes more cycles/command? And preferrably a way that doesn't waste too many additional rasterlines ofcourse.

I've got an idea that involves NMI-interrupts, in theory all you need for that idea isto do it this way:

1. Find out which timerchip you're working with (it's my understanding that there are two versions out and that they differ a cycle when interrupting)
2. Stable your rasters the usual way (double irq or whatever)
3. Point a timer interrupt at the code above
4. Prepare the interrupt so it corresponds to the exakt number of cycles your C64 invokes in a screen
5. Start the interrupt so it occurs exactly when you want it to

That could work!

The Dark Judge:
No, what I need is a big house with a playroom for just me :-)
2004-07-20 21:20
trident

Registered: May 2002
Posts: 91
Quote: Now we're talking stable rasters - anyone knows if there's a way to do it if you're not just jumping to * outside the irq, but doing something else that takes more cycles/command? And preferrably a way that doesn't waste too many additional rasterlines ofcourse.

Is that really a problem with the double-IRQ method? The first IRQ should work with any normal amount of cycle jitter and the second IRQ occurs in the midst of NOPs and isn't affected. In any case, it is always possible to do a tripple-IRQ where the first IRQ just invokes a jmp * loop.
2004-07-21 07:35
Oswald

Registered: Apr 2002
Posts: 5094
Trash: your idea wont work, as even NMI has to wait the current instruction to be finished before it can jump to it's routine.

The nicest way is to have an nmi timer count the horizontal cycles of each rasterline. So it runs 0-63 all the time in synch with the VIC. Now when your raster irq starts, you just poll the timer to see how much cycles you are off, and then add the needed delay with a self modded beq/bne. (check reflex's 4x4 routines for example, they use this method)
2004-07-21 09:14
Ninja

Registered: Jan 2002
Posts: 411
Oswald: NMI timer count? Any timer will do :)

The fastest way for a stable raster is probably Double-Timer. Most convenient... way too much ;) Most seem to like Double-IRQ or IRQ+Timer, though.

I give away sources, if someone is interested...
2004-07-21 09:22
Oswald

Registered: Apr 2002
Posts: 5094
ninja:Yeah any timer, just in my mind nmi and timer is connected in a strange way .)
2004-07-21 11:00
Cruzer

Registered: Dec 2001
Posts: 1048
Guess the double irq would work with more instability aswell. Didn't really get it at first actually. :-) I wasn't aware that you could interrupt and interrupt with another interrupt. I have always used two d012-compares to get the raster stabilized.
2004-08-11 04:32
Fungus

Registered: Sep 2002
Posts: 686
Sure you can interrupt an IRQ. or even an NMI.

Just CLI in your irq/nmi routine (as the processor sets this flag when any irq/nmi condition occurs).

This is even used as a protection sometimes.

I like that timer/irq method. But doubel irq is most trustworthy when it comes right down to it. It works weather your on pal or ntsc (provided enough nops are there) , doesnt matter what vic chip revision (pal or ntsc), or CIA revision (pal or ntsc).

www.ffd2.com/fridge/stableraster.txt

;)


2004-08-11 09:22
JackAsser

Registered: Jun 2002
Posts: 2014
I prefer the timer approach since 63-timer value + some offset is actually the X-position of the rasterbeam. This gives you the opportunity to create auto adjusting timing such as when removing the sideborder which requires exact timing plus using an unknown number of sprites flying around which screws up the timing.

/JackAsser
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
Krill/Plush
Guests online: 86
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 The Demo Coder  (9.6)
6 Edge of Disgrace  (9.6)
7 What Is The Matrix 2  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 Layers  (9.6)
2 Cubic Dream  (9.6)
3 Party Elk 2  (9.6)
4 Copper Booze  (9.6)
5 X-Mas Demo 2024  (9.5)
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 Webmasters
1 Slaygon  (9.6)
2 Perff  (9.6)
3 Sabbi  (9.5)
4 Morpheus  (9.4)
5 CreaMD  (9.1)

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