A tutorial by Wilf Rigter, last revision 7 Sept 1996 Part 4
13. ZX-81 Fast Mode Video Routines
In order to speed up application program execution time, the FAST mode uses 100% of the CPU time for executing the application program but there are times when the application program is idle When the program is STOPped or PAUSEd or waiting for keyboard INPUT, the keyboard is checked and if no key is down the video is generated independent of NMI pulses. In fact, the ZX-81 FAST mode video routine was designed to be compatible with the ZX-80 hardware so the ROM could be used as a retrofit ROM upgrade. Since the Z)C80 generates the blank lines in software, the ZX-81 ROM does the same when in the FAST mode.
The loop of VIDEO routines for FAST video starts with the FRAME/KBDNSYNC routine at 229:
0229 Decrement Frame Counter 023D EXIT Fast Video If Frames=0 (End Of Pause) 023E Check Keyboard 0260 EXIT Fast Video If New Key Pressed 0292 SAVE The Video Pointer In LX (0281) 029B JR Z. 02A9 To Blank Line Routine 02A9 Generate Blank Lines 02B3 JP (IX) TO 0281 0281 Generate The DFile Display 0292 SAVE Video Pointer (028~ 029B JR Z. 02A9 To Blank Line Routine 02A9 Generate Blank Lines 02B3 JP (IX) TO 028F) 028F JP 229 Back To Frame Counter
Since most of the routines were described in the SLOW Mode Video chapter, only the differences are described here. Compare the way the SLOW mode enters this loop from end of blank line application program execution by saving the main registers of the program and restoring them at the end of 0292. By contrast, the FAST mode does not save any registers and branches out of the 0292 restore main register routine to literally generate the blank lines. This is done at 029B after testing the FAST fl3g and jumping to a less known routine called Display-4
02A9 ;DISPLAY-4
LD A,FC;first R delay to INT
LD B,01;one row
CALL 02B5 ;display blank lines
DEC HL ;point back to HALT
EX (SP),HL ;delay 19T
EX (SP),HL ;delay 19T
JP (IX) ;IX = 0281 or 028F
The routine at 02A9 is called twice each frame to generate the top and bottom blank lines with HL pointing to either the first HALT at the start of DFILE or the last HALT at end of DFILE. Reg C holds the number of blank lines and reg B is set up for 1 row. After VSYNC the 31 top blank lines are generated by calling the display routine at 02B5 and executing the first HALT at the START of DFILE 31 times. After returning from the display routine HL points to the last HALTs1 and DEC HL is required point HL back to the last HALT of DFILE. After saving the return address in IX, the routine at 029A is reentered with HL pointing to the last HALT and generates the bottom 31 blank lines by executing the HALT at the END of DFILE.
14. True Hires Video Software
The true hires core routines are distinguished by the use of the I and R register pair as address pointers for the display file. The only other requirement is to execute 32 NOP instructions (or equal) per horizontal line and to update the I and R registers during HSYNC time. More blank lines can be used above and below the display for faster application execution. The listings are compatible source code for the ZXAS assembler both on the ZX-81 and under XTender, the ZX-81 emulator form Carlo Delhez. Check current version of XTender for hires computability. These ASCII listings can be used to prepare a formatted 2 REM J file with the ZXAS COM program from Jack Raats
WRX16 – 1984 Wilf Rigter
This is the hires (high resolution) core used in programs by Fred Nachbaur and Greg Harder. It creates a 256×192 high resolution display in a 6144 byte array starting at (HFILE), which can be poked directly from BASIC programs. START is used to start the hires display and STOP restores the Sinclair video. It has a characteristic signature with the I register value greater than 2000 hex. PART 1 calls LBUF 192 times, displaying 256×192 pixels calculates blank lines, saves pointer to PART 2 in IX and returns to application code. PART 2 calls VSYNC etc. calculates blank lines, saves pointer to PART 2 in IX and returns to application code execution.
;ORIGIN = 16516 (hex 4084)
LBUF ;Displays one line of 256
Dixels
;like DFILE, it is called above 32K to
activate the ULA video
;hardware. The hires bytes may be
inverted for special effects
;by setting bit 7 of the NOP codes .
The hires data is loaded
;into the ULA video shift register
during the refresh cycles of
;the 32 NOP opcodes when the I and R
registers sequentially
;address 32 bytes of hires data in the
6144 byte HFILE
LBUF
LD R,A ;Now load R register
00 00 00 00 ;32 bytes of 8 pixels
00 00 00 00
00 00 00 00
00 00 00 00
00 00 00 00
00 00 00 00
00 00 00 00
00 00 00 00
JP (IX) ;Return to HR
HR :HIRES DISPLAY ROUTINE PART 1
L D B,04 ;load delay
HRO DJNZ HR0 ;delay 56T states
to synchronize with HSYNC pulses.
LD HL,(HFILE) ;RAMTOP points to the
first HFILE byte
LD B,CO ;48 horizontal lines
LD IX,HR1 ;save the return
vector in IX (for JP (IX) at end of
LBUF)
JR HR2 ;skip HR1 first time
through the loop
HR1 LD DE,20 ;this value for 32
bytes or 256 pixels per line is
ADD HL,DE ;added to HL to point
to the start of the next HLINE
DEC B ;repeat 48 times
JP Z HR3 ;if this is the last
line JP to HR3
HR2 LD A,H ;the address in HL
is then transferred to
LD 1,A ;I register
LDA,L ;and dunng LBUF to
the R register
JP C084 ;jump to LBUF @} 4084 +
8000 to start the ULA
HR3 LD IX,HR4 ;save the video
vector so that NMI retums to HR4
JR HR5 ;now get blank lines and
return to appiication code
HR4 ;HIRES DISPLAY ROUTINE PART 2
CALL 220
LD IX,WRX16
HR5 LD A,(4028)
JP 29E
;first PUSH registers then jump to
VSYNC, etc
;save the video vector so that NMI
returns to HR
;33 or 19 blank lines in system
variable MARGIN
;save blank lines, start NMI, POP
registers and RETURN
--- end of listing --
The hires video is started and stopped by changing the vector address in register IX which is used by NMI to JP (IX) to the video routine. The following routines are synchronized with the display so that the changeover in video mode occurs without display breakup. STOP :STOP hires video and return to Sinclair video
LD HL,0281
LD A,1E
LD 1,A
JR SYNC
START :Start the hires video
;pointer to SINCLAIR video routine
;SINCLAIR ROM pattern table MSB base
address (1E00)
;pointer to I register
LD HL,HR ;pointer to the hires
video routine
SYNC :used bv START and STOP to
smoothlv chanae video mode
PUSH HL
LD HL,4034
LD A,HL
SYNC1 CP A,(HL)
JR Z SYNC1
POP IX
END OF LISTING--------
;FRAMES counter
vget old FRAMES
;compare to new FRAMES
;exit after a change is detected
:SINCLAIR video routine
Guus-Flater bv Enno Borgesteede (1984)
This hires core uses a ingenious way to intercept the video vector. Instead of changing the value of the IX register, Guus-Flater intercepts at the beginning of the DFILE execution by changing the first 4 bytes including the HALT to DI and JP 409F which is the start of the hires routine. At the end of the hires screen the program simply rectums to ROM routine at xxxx. It has a characteristic DFILE starting ,ith fhn rDl and JP 409F and the HFILE starts at (4004)

(400C)
409F 40A1
, 40AD
!1
j1 40B6
40B8
40D8
40DB
40DC
40DE
40E0
40E2
I
D1
JP 409F
LD B,08
DJNZ 40A1
LD A,R
LD B,C0
LD DE,20
LD HL,(4004)
LD A, H
LD 1,A
LD A, L
LD R,A
"COPYRIGHT 198.
JP 40DB
ADD HL,DE
DJNZ 40AD
LD A,1 E
LD 1,A
RET
HRG7 - in progress
;these bytes are loaded into DFILE
;to vector to the hires routine
sdelay
;delay
; delay
; 192 lines
;32 bytes per line
;hires file (HFILE) starts at RAMTOP
;MSB address of HFILE
;load MSB of HFILE pointer
:JUMP above 32K
;load LSB of HFILE pointer
a ENNO BORGESTEEDE "; same as 32 NOPs
;JUMP below 32K
;next hires line
;next line repeats 192 times
;restore ROM pattern table pointer
;load pointer
;join the SINCLAIR video in progress

WR)(16K – 1996 wilf riqter
<riqterRincafe.net>
The original WRX was written in 1984 but recent renewed interest has yielded newer more efficient versions. WRX16K 1996 is the most compact version of the WRX yet and will display a true bit mapped 256×192 hires screen. It was designed to work with the modified 16K RAMPACK or 16K SRAM and you must first lower RAMTOP with POKE 16389,96 then NEW before loading.
The hires mode can be started and stopped with the same routines shown in the WRX16 listing above. The simple START is used for starting the hires mode by changing video vector address in the IX register. Hires is stopped with the inline code segment called “BREAK” which returns synchronously to the Sinclair video mode when the space key is pressed. The HFILE is a 6K linear array starting at (4004) but is easily relocated. Note that HFILE must start on a 32 byte boundary (2000,2020, etc).
ORG
;16516 (hex 4084)
START LD IX,HR ;simple start of
the hres mode
RET
LBUF LD R,A
0 0 0 0
0 0 0 0
0000
0000
0000
0000
0000
0000
RET NZ
HR
LD B,7
H R0 DJNZ HR0
HR1
HR2
BREAK
STOP
HSCRN 2000
Note:
;load HFILE address LSB ;32 NOPs = 256
pixels
;always returns
DEC B
LD HL,(4004)
LD DE,20
LD B,C0
LD A,H
LD 1,A
LD A,L
CALL C089
ADD HL,DE
DEC B
JP NZ HR1
CALL 292
CALL 220
CALL F46
LD A,1E
LD 1,A
JR NC STOP
LD IX,HR
JP 2A4
sdelay
;delay
sreset Z. flag
;HFILE starts at RAMTOP or HSCRN (note
below)
;32 bytes per line
;192 lines per hires screen
sget HFILE address MSB
;load MSB into I register
;get HFILE address LSB
;CALL LBUF + 8000
;next line
;dec line counter
;last line
;return to application program
;extra register PUSH and VSYNC
;this code segment is optional
;check break key
;restore pattern table pointer
;skip the HR vector load if BREAK
;load the HR vector
;retum to application program
;this is used with SRAM at 8K - 16K
HFiLE can be relocated to use SRAM between 8 to 16K by changing LD HL,(4004) to LD HL,(HSCRN).
— end of listing “


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