I explained myself horribly, Let me try againNekoNoNiaow wrote: ↑Fri Jul 19, 2019 2:27 amMy knowledge of 6502, 6522 and Oric's interrupts in general is quite limited so a cursory look at Blake's 7's IRQ routine did not allow me to pinpoint whether these 33 cycles would be justified. Moreover, if I understand correctly the mode of operation of the 6522, the timer should restart counting immediately after reaching zero and triggering the interrupt anyway so the timing of the interrupt routine should not really matter.Chema wrote: ↑Tue Jul 16, 2019 12:51 pm I tested the routine in my real Oric. A very limited test, however. The cursor in Blake's 7 flickered when being moved so I put the routine in my code trying to get a sync with the vertical retrace and avoid it. It worked, but only partially.
[...]
Now, I don't know why 19966. There are 33 cycles missing. I know some are lost due to the interrupt handling, but 33?
But I may be completely wrong there.
To get a timer at 50Hz you would start by loading the latch in Timer 1 whit 20000 cycles. In free-run mode, this will create an IRQ each time the counter reaches zero, while the counter re-loads with the latch value automatically. However, if you have a look at the specs (http://archive.worldofdragon.org/images/f/f0/6522.pdf page 8 ) you'll notice that the IRQ signal needs up to 2 extra cycles. So you'd load it with 19998. Great, that's the theory.
Now you run in Oricutron any manual calibration routine (those that use raster bars, such as the one iss posted, Fabrice's original or the one in Oricium). By pressing some keys the timer counters change their value (incrementing or decrementing from 19998). If you try to get a static raster bar anywhere in the screen which does not drift at all with time and then peek in the debugger, you'll notice the timer has the value 19966!. Put 19967 and the bar will start drifting.
You may ask if this occurs too in real hardware. Well, it does. In Oricium the calibration works this way: you press, for instance, the down arrow and the bar starts moving. Press again and the timer decrements and it moves faster. Press up and it will stop at its position (instead of decrementing speed). It does this to ease the manual calibration process, and it does it by setting the timer to 19966. You can do it in a real Oric and you'll see no drift.
Why this value? I just cannot explain.
All the other considerations about the ISR are just important if you want your code to be synchronized with the raster precisely. There is a latency from the moment the IRQ is produced and your ISR code starts running which is something between 7 and 14-15 cycles (http://www.6502.org/tutorials/interrupts.html), and then you may want to count the cycles you lose for acknowledging the IRQ, storing registers, etc.
By the way ISS. I tested your programs and pressing SPACE does not seem to be able to sync correctly with the VSync signal. The bar appears at different places... am I misunderstanding something?