8

By reading register $D012/$D011 or when pausing the execution of an emulation in VICE starting the monitor and entering io d000, it is possible to get information about the current rasterline. For some time-crucial programs it would be also helpful to know the current position of the raster beam (usually it moves 8 pixels per clock tick).

While it is not possible to derive this information from the VIC registers I think that a timer used as counter or information in the simulator would be able to provide this information. Is it possible to obtain the current raster beam position somehow by checking the timer/counter, via the interface of the VICE simulator, or by analyzing a snapshot image?

3
  • 2
    Isn't that a question that should better be asked at the VICE site as it is about said actual software and it's inner workings, not at all about the C64 (the computer does not have a way to read out the beam - or even stop it in the middle)?
    – Raffzahn
    Commented Nov 5, 2019 at 15:03
  • Thanks for the feedback, I edited the question to be more broad in addressing a retrocomputing problem.
    – Peter B.
    Commented Nov 5, 2019 at 17:47
  • To echo Raffzahn's concern, what you're asking for is not something a real C64 can answer. If you were in-circuit you could probably derive current output column — the bad lines are observeable via the RDY line, and can be used to put you into phase with the video — but that's not helpful for what you could do with one particular C64 emulator.
    – Tommy
    Commented Nov 5, 2019 at 19:38

2 Answers 2

11

On a C64 PAL model, the VIC chip processes through 312 lines where each lines takes 63 clock cycles to display (including some time for horizontal and vertical blanking for returning the raster beam). So, if a timer counting every clock cycle is once synchronized to the beginning of rasterline 0, then the timer value t tells us the number of the current line with INT(t/63) and (t MOD 63)*8 yields the X coordinate. Alternatively, the current line can be read from VIC register at $D012 and $D011 (9th bit). Note that the raster beam will be long gone from this position when the CPU is done with the calculation, but it might be helpful to record the timer value at a given point in a program and calculate where the rasterline had been in an offline debug session. The CIA 6526 latch value for a PAL-synchronized timer is 19656-1 or $4CC7.

In the VICE emulator, the problem is much easier solved because the monitor allows to stop execution and provides access to a CPU cycle counter which starts at value 0 when VICE is started or a reset takes place. This event exactly coincides with the raster beam starting at the beginning of line 0. The cycle counter can be printed with the command stopwatch in the monitor. Thus, with c being the cycle counter value, the current X position of the beam can be estimated with (c MOD 63)*8 and the current raster line with int((c MOD 19656) / 63). The line value can also be obtained by checking the VIC registers with io d000 in the monitor.

Timing of rasterbeam Image explaining timing of rasterbeam (Figure by Dustlayer based on Michael Steil's Ultimate Commodore 64 Talk) Note that the coordinate system for calculation of line and X position has its origin in the border.

4

https://www.codebase64.org/doku.php?id=base:using_a_timer_as_an_inverted_raster_x-pos_register_method

The link describes, basically: first, how to synchronize timer to the raster interrupt; second, how to use that synchronized timer that counts from 0 to 6, to get the CPU in "hard" (i.e. cycle-exact) sync with the beam position.

This link and the described method is relevant, though partially, to this particular question.

Similar to the described method, you can start timer counting up to 63 cycles and synchronize it with the raster IRQ, thus the timer from now on contains a value that is proportional to the exact horizontal beam position (in the multiples of 8 pixels).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .