Page 2 of 2

Line IRQ Timing

Posted: Mon Feb 15, 2021 8:08 am
by TomXP411


15 hours ago, Elektron72 said:




Thanks for the correction; I had assumed it was the other way around. While the current version of the emulator does not account for horizontal timing, it does count the vertical front porch lines at the beginning of a frame, rather than at the end. I might open a pull request to fix this.



Yeah, I think this is one area where the emulator may not be correct - but we won't know for sure until the next revision, which will match the current hardware configuration, comes out. 

It might be worth trying to get more info on exactly when VERA triggers the line and frame interrupts... knowing the exact timing is going to be important for people doing raster effects. 

 


Line IRQ Timing

Posted: Mon Feb 15, 2021 10:45 am
by AndyMt

I experimented with the raster line IRQ the last few days, too. I got it working, but there is very few cycles left you can use. Updating a (256) color palette seems almost impossible. I'll try to use the auto-increment feature of VERA, to improve this, by storing the 2nd palette in VRAM, too.

And that's with the emulator- no idea if this will work on real hardware.


Line IRQ Timing

Posted: Mon Feb 15, 2021 11:18 am
by Guybrush


33 minutes ago, AndyMt said:




I experimented with the raster line IRQ the last few days, too. I got it working, but there is very few cycles left you can use. Updating a (256) color palette seems almost impossible. I'll try to use the auto-increment feature of VERA, to improve this, by storing the 2nd palette in VRAM, too.



And that's with the emulator- no idea if this will work on real hardware.



It's simply impossible to update the entire palette during one scanline, even if you use every available hardware trick. There's only 254 (266) CPU cycles per scanline, the exact number depends on whether the CPU runs on dedicated 8 MHz clock, or a VGA clock divided by 3 (25.175 / 3 = 8.3196666 MHz) .

Since a simple LDA/STA combination to read and write from/to VERA data registers takes 8 cycles, even if you completely unroll the loop, you can copy 254 / 8 / 2 (2 bytes per palette entry) ~= 15 palette entries. And I'm not even taking the KERNAL IRQ handler overhead into account.

Even if there was a DMA chip somewhere in the system, it couldn't update the palette in one scanline beacuse it would need 256*2*2 = 1024 cycles, which also means that even a DMA internal to VERA couldn't do it because a VGA 640x480 scanline is only 800 cycles long.

The only way to update the entire palette in one scanline would be to have a relocatable palette.

So, you can only change a few colors each scanline and must design your graphics accordingly.


Line IRQ Timing

Posted: Mon Feb 15, 2021 12:41 pm
by AndyMt


1 hour ago, Guybrush said:




So, you can only change a few colors each scanline and must design your graphics accordingly.



Yes, that's what I'm going for. And I'll have to change the entire palette over multiple scanlines. This makes the line IRQ not all too useful - I wonder how much you could do on the C64...


Line IRQ Timing

Posted: Mon Feb 15, 2021 1:43 pm
by Guybrush


26 minutes ago, AndyMt said:




Yes, that's what I'm going for. And I'll have to change the entire palette over multiple scanlines. This makes the line IRQ not all too useful - I wonder how much you could do on the C64...



Well, for one, you could not change the palette at all ?.

Of course, you could change the background color registers (1,3 or 4, depending on the display mode), the sprite multi-color registers (2) and sprite color registers (8), but you'd have to time your code very precisely. And then there are badlines ?.

On a normal line with no sprites, you get 63 cycles for PAL, and 64 or 65 for NTSC. That's 23-25 cycles off-screen, even a bit more since you only have to perform your writes in the invisible part of the scanline. If you're changing global color registers that's just about enough time to update 3-4 of them if you use self-modifying code (to directly update color values in LDA #val instructions). On a line with sprites, you lose up to 16 cycles in the invisible part, but if you're changing sprite colors you are more flexible in your timing because you know when the sprite is being displayed and since the sprite color affects only one one sprite... you get the point.

Long story short, on the C64 you also need to design the screens carefully to make big changes to colors.


Line IRQ Timing

Posted: Mon Feb 15, 2021 1:54 pm
by AndyMt


9 minutes ago, Guybrush said:




And then there are badlines ?.



I remember those. Happens every 8 pixels, right? That's the beauty of the VERA design and it's interface to the bus: it's pretty independent.