Syncing code to video update

Started by Blacklord, August 07, 2009, 07:03 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Blacklord

Original post by Robin Harbron


I'm working on a game with smooth scrolling (simulated by use of PETSCII graphics) for my PET 4032, which I consider to be the ultimate PET gaming machine.

There doesn't appear to be any way of finding out when vblank has occurred, so I can sync the screen update and avoid "tearing" on screen.

Does anyone know if there is a solution for this?

I was thinking that if the video generation circuit is synced with the processor clock like in the C64 (I don't know if this is a safe assumption), then it would be possible to set up a timer interrupt to sync with that (processor clock speed divided by screen refresh rate... e.g. 1 Mhz divided by 60 hz would be around 16,667 cycles).  That interrupt would trigger the screen redraw code.  Then it would be a matter of showing a test and asking the user if there was any tearing, and adding an offset of a few thousand cycles each time they said no until it looked right.

Any other ideas?

Blacklord

Original post by nikoniko

I'm only aware of this from reading about the killer poke, but doesn't bit 5 of $E840 (VIA) indicate when the screen is in retrace?

Blacklord

Original post by Robin Harbron

Quote from: nikoniko

    I'm only aware of this from reading about the killer poke, but doesn't bit 5 of $E840 (VIA) indicate when the screen is in retrace?

Well, how about that!  It didn't even occur to me to look there.  I'll give it a try next time I get a chance, and report back.  Thanks!

Blacklord

Original post by Robin Harbron

Quote from: nikoniko

    As far as I've been able to ascertain from PET documentation on the net, the system IRQ itself is tied to the vertical retrace, so all you need to do is set up an IRQ handler, and as soon as it gets called you know you're at the beginning of the retrace period. (See PETdoc or 6502.org)

Interesting.  Well, I find just checking a bit in a register a lot easier then setting up an IRQ handler :)  Typically I just disable system interrupts altogether when doing game programming, and just deal with the hardware directly.  On the PET, that just means reading the keyboard directly, which is pretty straightforward.