..............F...F..............    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    
       Vertical Blank Interrupt
      --------------------------
            by NIR DAREY


Let me start explaining what Vertical Blank is.
you probably know that the time it takes the television to draw a full picture on a screen is 1/50 of a second
(in the U.S.A it's 1/60 of a second).
The TV keeps drawing the picture again and again even if it's doesn't changes.
The routine that draws the picture on a screen is allready written in the ATARI O.S.
since the computer is running at 1.79 Mhz, there is spare time from when the computer finished drawing the picture till it's start again. this spare time we can use to insert ower own routine.
any graphic changes been made during VBLANK will shown smoothly, but most important thing is that you can run a VBI routine at the same time your main program runs!.(for example play music, do smooth scroll etc...)
There is also a Horizontal Blank which occurs after the TV has finished drawing one line and goes to the next line.
There are two stages of VBLANK, the first is called "IMMEDIATE" which allways executed, and the second called "DEFERRED".
There are two ways to set a VBI to your own routine.
The first way is to set the VBLANK registers to the start address of you own routine.
546,547 ; Immidiate VBLANK registers
548,549 ; Deferred VBLANK registers

The second way is to load the Y register (LDY) with the low byte address of your routine, and the X register (LDX) with the high byte, then load Accumulator (LDA) with 6 for Immidiate VBI, or 7 for Defferd VBI and do JSR 58460.
I recomand the second way to set your VBI routine becuse if you change the VBI registers and a VBI occurs the computer will crash!!!.
Another thing you should allways remeber is allways tell the computer at the end of you VBI routine, to go back and do the O.S. VBI routine:
JMP 58463 for Imidiate VBI.
JMP 58466 for Defferd VBI.

Now let's take a look at a small example the following source is written in MAC65:

10      *=1536
20      PLA
30      LDY #<VBLANK
40      LDX #>VBLANK
50      LDA #07       ;defferd VBI
70      JSR 58460
80      RTS
90 VBLANK LDA 20
100     STA 53274
220     JMP 5846


Here is the samll routine for the BASIC users:

10 ADDR=1536
20 READ DAT:IF DAT=-1 THEN 50
30 POKE ADDR,DAT:ADDR=ADDR+1
40 GOTO 20
50 X=USR(1536):END
60 DATA 104,160,11,162,6,169,7,32,92
70 DATA 228,96,165,20,141,26,208,76,98
80 DATA 228,-1



Some technical notes:

Immidiate VBI updates the,
Internal Realtime Clock register (RTCLOCK 18-20),
Attract Mode register (ATRACT 77),
DRKMKS 78,
Changing Color register (COLRSH 79),
System Timer One registers (CDTMV1 536,537),
Then the Time Critical register (CRITIC 66) is checked, if it's sets the O.S. returns from the interrupt.
If it's not set then the O.S. goes to stage two of the VBI.

Defferd VBI updates the:
Horizontal Position of the Light Pen register (PENH 54284),
Vertical Position of the Light Pen register (PENV 54285),
Display List address registers (DLISTL,DLISTH 54274,54275),
Priority register (PRIOR 53275),
Color of Players and Missile registers (COLPM0-3  53266-53269)
Playfield Color registers (COLPF0-3  53270-53273),
Color of the Background (COLBK 53274),
Charecter Set address register (CHBASE 54281),
CHACTL register (54273),
TRIG0-3 registers (53264-53269),
POT0-7 registers (53760-53767),
PORT A register (54016),