** Stable rasters on the VIC-20

Basic and Machine Language

Moderator: Moderators

Post Reply
User avatar
Mike
Herr VC
Posts: 4871
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: ** Stable rasters on the VIC-20

Post by Mike »

I should add a few points which could be taken for granted, but still need to be accounted for reliable operation:

1. Both the initial sync routine and the interrupt server routine are extremely sensitive to timing. No interrupt must be allowed in their tracks. The initial sync does a SEI/CLI bracket, and the interrupt server anyhow executes with IRQs disabled. The two routines are not especially hardened against an NMI though, as for most times on the VIC-20 only the Restore key acts as an NMI source. An NMI during the initial sync may permanently shift the position of the stable raster, any NMIs happening while the raster effect is done will shift the timing for that frame, but this corrects itself on the next interrupt execution.

2. The routines assume that all the branch instructions do not leave the page for their branch target and thus execute in either 2 or 3 cycles (taken branches that leave the page need 4 cycles). If this is not honoured, the initial sync may fail in some circumstances, but work in others, depending upon where the second raster counter check bailed out. During the interrupt server, the timing might permanently shift in unexpected ways. It is recommended to keep the code of each of the two parts - initial sync and interrupt server - within a single page. This is already the case for the initial sync, and for the example, also for the interrupt server, but you will have to be wary about the 4 cycle branches for any own implementation of the interrupt server.

3. The very first check of the raster counter at 'line' (with the next check following at 'line'+2) is important to avoid a possible race condition at 'line'+2. It must not be left out!

4. The horizontal fine positioning should be done in the initial sync (with the loop before the final write to $9125 to (re-)start the timer), not with a delay loop after the NOP slide in the interrupt server. Doing so like the latter permanently wastes cycles each frame which were otherwise available for the main program.

5. If your actual demand for the horizontal fine positioning seems to ask for a negative delay in the initial sync routine, decrement the 'line' value by 1 and use a long delay instead.
User avatar
Mike
Herr VC
Posts: 4871
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: ** Stable rasters on the VIC-20

Post by Mike »

In another thread, I documented the workings of the inner loop in the example of this thread's start post a little more in detail:

Code: Select all

[...]
.Frame1
 LDA &900E                                ;    Load current aux. colour/volume register,
 EOR aux_extbrd_1,Y                       ;    change the aux. colour,
 AND #&0F                                 ;    but keep the volume
 EOR aux_extbrd_1,Y                       ;    and
 STA &FB                                  ;    store in $FB for later use.
 LDA aux_extbrd_1,Y                       ;    Calculate next combination
 EOR bck_intbrd_1,Y                       ;    of exterior border colour
 AND #&0F                                 ;    plus background colour from ...
 STX &900F                                ; ** re-instate exterior border colour at right edge of display window (keeping the current background colour)
 EOR bck_intbrd_1,Y                       ;    ... the table data and 
 TAX                                      ;    keep in X for later use.
 LDA &FB                                  ;    Load $FB and
 STA &900E                                ; ** write $FB as new value of aux. colour/volume register (immediately before horizontal retrace).
 STX &900F                                ; ** Change to new exterior border colour and background colour during horizontal retrace.
 ]
 IF NOT ntsc THEN [OPT pass:CMP (&00,X):] ;    6 cycles extra delay for PAL
[OPT pass
 LDA bck_intbrd_1,Y                       ;    Load combination of background colour and 'interior border colour' for the %01 multicolour pixels and
 STA &900F                                ; ** write background/border register at left edge of display window.
 NOP                                      ;    Not much leeway here.
 INY                                      ;    Count ...
 CPY #&C1                                 ;    ... 192+1 ...
 BCC Frame1                               ;    ... lines.
 [...]
The "**" markers show where the stores to the VIC registers happen. "Frame2" works the same on another set of tables in alternate frames. The demo thus combines time and raster line interlacing for a better definition of the greyscales. This technique works for both NTSC and PAL.

Attached (download) you find a PDF file which shows above code arranged in a FridgeGrid-like manner. The column "horizontal display window" shows the timing of the MINIGRAFIK display. The stores to the VIC colour registers are supposed to take effect on the next cycle ... on real hardware, an extra hires pixel is still displayed in the old colours though, and nothing can be done about that.
Post Reply