When does the scan line counter change?

Basic and Machine Language

Moderator: Moderators

Post Reply
matsondawson
The Most Noble Order of Denial
Posts: 343
Joined: Fri May 01, 2009 4:44 pm

When does the scan line counter change?

Post by matsondawson »

Is it at the end of the line or at the start of the line.
Or put another way, is it before the horizontal blank or after?
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Post by Mike »

Maybe somewhere during the horizontal blank? ;)

Routines, that lock a raster IRQ to a definite horizontal position almost always rely on empirical facts.

You can sync the CPU to the change of the register, which will happen somewhere (at a fixed position) during the horizontal blank period. If you then want to alter a register so a visible change occurs at a certain X position, you time it out with the necessary number of NOP's, and a single conditional branch.

At least the PAL variant of recent VICE versions seem to get that right, as the contemporary demos with in-line raster splits are displayed correctly.

Michael
matsondawson
The Most Noble Order of Denial
Posts: 343
Joined: Fri May 01, 2009 4:44 pm

Post by matsondawson »

To figure it out I executed this program, that basicially inverts and un inverts the screen the moment it detects a scanline change.
With the 3 x NOPs I have in the code the disruption on screen occurs at minimum exactly on the default left hand edge of visible screen (i.e. on the left of the first character).
The default offset on PAL is 12, which is to say 12 clock cycles from left edge of screen. Given my count of instructions below of 19 cycles from scan line change to disruption created, i'd say the change occurs 7 cycles before the end of the previous scan line. This corresponds with the horizontal blanking starting.
So the simple answer is it changes at the beginning of the horizontal blank.

loop2:
sei
lda $9004
loop:
cmp $9004 ; +1 cycle as comparison done at last cycle
beq loop ; 2 cycles no branch
nop ; 2
nop ; 2
nop ; 2
lda $900F ; 4
eor #$19 ; 2
sta $900F ; 4 - first screen change occurs on the last cycle of this instruction
eor #$19
sta $900F
cli
clv
bvc loop2
Post Reply