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


Forums > C64 Coding > Timing with y-moving sprites
2006-08-17 10:14
Mantiz
Account closed

Registered: Apr 2006
Posts: 36
Timing with y-moving sprites

Hi,
I have been trying to figure this thing out for a while.
What I have now is a stable raster routine so opening the sideborders is for example no problems at all.

What I wonder is how you can have sprites moving in the Y direction over these lines and still keep the timing, because it will change depending on which and how many sprites there are crossing it. No need to take care of badlines is required in this example.

Do I need to use NMI interrupts or is there another way, for example do a calculation somewhere else on the screen how many sprites there will be on a certain line and from that set up an appropriate delay for every line in the sideborder/raster/whatever routine you need to be stable with a changing amount of sprites over it? I've been trying the later approach but my code gets rather messy.

2006-08-17 10:22
chatGPZ

Registered: Dec 2001
Posts: 11136
one common approach is to simply NOT move them at all (not in Y atleast). stretch them down using $d017 and switch sprite pointers and/or mod the way they are stretched to simulate Y movement.
2006-08-17 10:25
JackAsser

Registered: Jun 2002
Posts: 1990
If I were you I'd use the timing technique used by ninja in real. This is applicable here since the $d016 write is to be done BEFORE the sprite fetches. I.e. for each line you stabalize between the sprite fetches of the current line and the next and POKE the $d016. But that's just me since I'm familiar with that technique.

Basically you have a timer, in your case ticking down from 62 to 0 all the time. So:

$dd06: #<$62
$dd07: #>$62

But then you place a JMP and a 0 on $dd04/dd05:

$dd04: jmp-opcode (#$4c)
$dd05: #$00
$dd06: #<$62 (lobyte of timer)
$dd07: #>$62 (hibyte of timer)

The point the NMI vector to $dd04

$fffa: #<$dd04
$fffb: #>$dd04

What happens is that when the timer reaches 0 the NMI will trigger and jump to $dd04 (with the normal unstabile jitter).
Since the NMI-setup takes some cycles and the jitter takes some cycles the lobyte of the timer will be in the $e0-$f0 range approximatly then the JMP on $dd04 executes.

So, depending on timer jitter you will jump to $xx00 where (xx is typically $e0-$f0 approx.).

So, basically depending on jitter, independant of sprites and all other delays you will jump to a specific routine. And for example in the $e000 routine (where the delay is most sever) you need to store the $d016 immediatly, but in the $f000 routine you havn't delayed that much so add the correct amount of NOPs to hit the correct $d016 cycles.

Also, you must be sure that the NMI triggers after the sprite fetches and not inside them otherwise you'll get fooled when you NOP.

I.e. start the timer initially using a standard stable raster and make sure it reaches 0 just after the sprite fetches, or preferably as tight as possible to the $d016 write.

Well... have fun! :D

But yes... groepaz suggestion is perhaps the most common and most wize method to use. ;)
2006-08-17 10:28
chatGPZ

Registered: Dec 2001
Posts: 11136
jackasser: is that actually quick enough to work on every line and with a few sprites enabled?
2006-08-17 10:31
JackAsser

Registered: Jun 2002
Posts: 1990
@groepaz: Hmm yes, assuming no bad lines ofcourse. NMI setup 7 cycles, jitter max 8 cycles. Sprites 17 cycles. inc dec $d016 12 cycles. Acknowledge NMI 3 cycles (when done with a jmp to a RTI opcode before the ack io) + the rti 6. so 7+8+17+12+3+6 = 53 cycles. Then you have the JMP itself also so, an additional 3 cycles. Total 56 cycles worst case jitter.

Question is, why waste 56 cycles with this method, when there are more elegand ways to do it when it comes to this particular problem? :D
2006-08-17 11:18
chatGPZ

Registered: Dec 2001
Posts: 11136
because i havent used this method before :=)
2006-08-17 11:37
enthusi

Registered: May 2004
Posts: 675
I like timers but jumping into them is new to me. Evil. Beautyful.
2006-08-17 12:09
Jetboy

Registered: Jul 2006
Posts: 224
Once you learn ninja method you wont want to use anything else. It's beautifull, its elegant, and its fast! Especialy if you are doing every second line fli, or every 4th line fli (more elaborate duiscusion on this topic in some other thread). Surely - there is quite some memory usage with that method, so its not so good as everday solution, but it serves it;s purpose.
2006-08-17 15:00
Oswald

Registered: Apr 2002
Posts: 5025
ninja for president \:D/
2006-08-17 15:53
Mantiz
Account closed

Registered: Apr 2006
Posts: 36
Thanks a lot Groepaz and JackAsser for the ideas and explanation! I'm trying to learn as much as I can so I will try both approaches and see which one works best. The idea with using timers is nice and very clever.

Regards,
Mantiz
2006-08-18 06:23
JackAsser

Registered: Jun 2002
Posts: 1990
"The idea with using timers is nice and very clever"

Yes, but not so appropriate to use if you for instance only have a simple 8x3 sprite big logo swinger or something (with open borders). Then you simply only have two timing cases, either 0 sprites or all sprites and you know exactly when the sprites start and end so all you have to do is to do some simple self modifying timing code.

The timer method is nice if you have either 1) rather complex timing due to dynamic motion of sprites, 2) if you need to do something VIC-trickery every now and then really quick (stable that is), for instance setting up a 4x4 mode.

Using the timer approach alone for setting up a 4x4 mode won't help you add dynamic sprites on top since the $d011 write to do the FLI must take place almost directly after sprite fetch #8, but your timers must stabalize BEFORE the sprite fetches. So, unless you have equall amount of sprites all lines you have a problem, since you don't know the exact amount to NOP (due to different sprite timing), to find the correct $d011 place.

What I want to say really is that, however beautiful timers are etc. etc. they don't solve all timing problems. Sometimes you still have to manually adjust the code or use some tables due to complex y-motions of sprites.
 
... 15 posts hidden. Click here to view all posts....
 
Previous - 1 | 2 | 3 - 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
MAT64
kbs/Pht/Lxt
Higgie/Kraze/Slacker..
rexbeng
Nith/TRIÉ…D
mikme
Krill/Plush
LMan
E$G/hOKUtO fOrcE
DeMOSic/HF^MS^BCC^LSD
Honcho
Knut Clausen/SHAPE/F..
The Human Co../Maste..
TheRyk/MYD!
Ghost/Quantum
Guests online: 114
Top Demos
1 13:37  (9.8)
2 Next Level  (9.8)
3 Mojo  (9.7)
4 Coma Light 13  (9.7)
5 Edge of Disgrace  (9.6)
6 Comaland 100%  (9.6)
7 Uncensored  (9.6)
8 No Bounds  (9.6)
9 Wonderland XIV  (9.6)
10 Bromance  (9.5)
Top onefile Demos
1 It's More Fun to Com..  (9.7)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Layers  (9.6)
5 Copper Booze  (9.5)
6 TRSAC, Gabber & Pebe..  (9.5)
7 Rainbow Connection  (9.5)
8 Dawnfall V1.1  (9.5)
9 Quadrants  (9.5)
10 Daah, Those Acid Pil..  (9.5)
Top Groups
1 Oxyron  (9.3)
2 Booze Design  (9.3)
3 Nostalgia  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Diskmag Editors
1 Jazzcat  (9.4)
2 Magic  (9.4)
3 hedning  (9.2)
4 Elwix  (9.1)
5 A Life in Hell  (9.1)

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