The Variable Display Routine, Part Two

See all articles from ZX-Appeal Feb 89
Author(s): Wilf Rigter
Publication: ZX-Appeal
Pub Details: ZX-Appeal Feb 89
Date: February 1989
Pages: 7

Some Software hires programs use RET (instead of N/L and Interupt) to terminate each line and to return to a calling routine which processes the horizontal sync and display pointer updates. WRX16 uses a JP to terminate a dummy display line while the hires data file requires no line terminations at all.

After the last scan line execution of DFILE is interupted the B reg decrements to 0 and the Interupt routine returns to calling program at 28b. The routine continues with a CALL 292 which first saves the return address 28F in the IX register and then loads the number of blank lines below the screen from sysvar MARGIN. Next the routine restores all registers including A” and turns on the NMI generator before returning to the interupted BASIC or ML program.

So far so good but What about vertical frame synchronization?

Well the next time the A” reg overflows during a NMI instead of a JP (IX) to 281 it jumps to 28F which was the return address previously saved in IX ,followed by a JP 229 to the keyboard ,frame counter, and vertical sync service routines and finally ending at 27E with a CALL 292 which this time stores return address 281 in the IX register before loading the blank lines above the screen into A” and returning to the BASIC program.

Having come full circle,this completes the background description of the normal ZX video routines.

If we load IX with an address of an entirely different video routine we can do almost anything within the constraints of the hardware and video timing,from software hires to VDR.

Listing 1 begins with a short routine called INVOKE (INVK) to set the IX reg to point to the actual VDR routine. Note that we never execute the VDR routine directly.

The following routine restores the IX reg to point to the NORMAL (NORM) ZX display routine. This routine may not be required since during BASIC program development a simple keyboard procedure BREAK,SHIFT 0, ENTER will always return the NORMAL screen.

The next routine is VDR to which JP (IX) vectors. It consists of CALL VDP which takes the place of the routines at 281 and 2B5, followed by CALL 292 which exits to BASIC with the return address VDR1 in the IX register. When next interupted by an NMI which increments A” to overflow (ie last blank line), the CALL 220 is executed and the keyboard,vertical sync etc. gets serviced. Note that the registers are stacked first (220) so that the routine at 292 returns to VDR instead of the BASIC program and so the IX register can be restored to VDR.

Finally the jp 2A4 POPS the registers and returns to BASIC.

The Video Display Pointer (VDP) routine is used calculate the number of diplay lines and conversely the number of blank lines which are loaded into sysvar MARGIN. Then the location of the display (V-FILE) is calculated with respect to sysvar VARS and the offset in sysvar SEED. Then reg A is loaded with 100-DD characters per line (35) and a JP 41 starts the execution of the V-FILE via a part of the interupt routine which loads R,A ,Enables Interupt (EI) and JP (HL) to the actual start of V-FILE.

        ;VDR1 (C) 1986 - W RIGTER

;VARIABLE DISPLAY ROUTINE

INVK
LD IX,VDR;SET VDR VECTOR
RET
NORM
LD IX,281;SET NORM VECTOR
RET
VDR
CALL VDP;VAR DISPLAY PROC
CALL 292;RETURN TO BASIC
CALL 220;KEYBOARD/V SYNC
LD IX,VDR;RESTORE IX PNTR
JP 2A4;RETURN TO BASIC
VDP
LD A,(4021);DISPLAY LINES
AND 1F; 32 LINES MAXIMUM
LD B,A;REG B IS THE CNTR
RLCA; CHRLINES X 8=SCAN
RLCA;
RLCA;
ADD A,21;CALC BLANK LINES
CPL
LD (4028),A;SYSVAR MARGIN
LD C,8;8 SCAN / LINES
LD HL,(4010);VAR TOP
LD DE,(4032);SEED=OFFSET
ADD HL,DE;TOP OF DISPLAY
SET 7,H;ECHO ABOVE 32K
LD A,DD;100-DD= CHR/LINE
JP 41;EXECUTE DISPLAY

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.