ML Scroll Routine

Author(s): Ken Berggren
Publication: Syntax
Pub Details: Syntax/Syntax ZX80 v2 n8 (Volume 2, Issue 8)
Date: August 1981
Pages: 15

In 1K ZX80s, large programs easily overfill the 24 available screen lines. This machine language routine deletes the top line from the screen so you can add lines to the bottom.

To use with 4K ROM, first LOAD Placing USR Calls (Jun.81) to reserve RAM space at the top of memory (this program uses 42 bytes; your first address is 17366). POKE in the Scroll routine, using the decimal listing below, then LOAD or type in a BASIC program.

Insert a USR call before each PRINT line in your BASIC program. A simple line like LET X=USR(17366) calls the ML routine but doesn’t affect what the computer prints (don’t use X or any variable you choose elsewhere in your program).

After you fill the screen, the Scroll routine deletes 1 line from the top of the display for each line the program PRINTs at the bottom. This listing will scroll whenever the new line would be printed on screen line 20 or below. To change how many lines the routine PRINTs before scrolling, adjust the fifth number of the decimal listing. The number of lines printed will be 25-(the fifth decimal number). If you call this routine when the screen is empty, the fifth number must be <24.

4K SCROLL ROUTINE

43D6            00100         ORG    43D6H
400A 00110 DFILE EQU 400AH
400E 00120 DFEA EQU 400EH
4025 00130 BOTLIN EQU 4025H
0014 00140 SCROLL EQU 14H
43D6 3A2540 00150 START LD A,(BOTLIN) ;THE BOTTOM LINE
43D9 FE14 00160 CP SCROLL ;IF BOTLIN>SCROLL
43DB F0 00170 RET P ;THEN RETURN TO BASIC
43DC 3C 00180 INC A ;ELSE ADD ONE
43DD 322540 00190 LD (BOTLIN),A ;TO BOTLIN
43E0 2A0A40 00200 LD HL,(DFILE) ;WHERE TO START
43E3 7E 00210 LD A,(HL) ;(NL) IN A
43E4 54 00220 LD D,H ;PUT HL IN DE
43E5 5D 00230 LD E,L
43E6 23 00240 INC HL ;FIRST CHAR IN FILE
43E7 EDB1 00250 CPIR ;FIND NEXT (NL)
43E9 ED4B0E40 00260 LD BC,(DFEA) ;WHERE TO END
43ED 1801 00270 JR SKIPHL ;DO NOT INC HL
43EF 23 00280 MOVBYT INC HL
43F0 13 00290 SKIPHL INC DE
43F1 7E 00300 LD A,(HL) ;MOVE (HL) TO (DE)
43F2 12 00310 LD (DE),A
43F3 78 00320 LD A,B ;COMPARE HL TO BC
43F4 94 00330 SUB H
43F5 20F8 00340 JR NZ,MOVBYT ;IF B<>H
43F7 79 00350 LD A,C
43F8 95 00360 SUB L
43F9 20F4 00370 JR NZ,MOVBYT ;IF C<>L
43FB ED530E40 00380 LD (DFEA),DE ;REPLACE DFEA
43FF C9 00390 RET ;RETURN TO BASIC

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