Machine Code Screen Fill

Author(s): Harold Miller
Publication: Syntax
Pub Details: Syntax/Syntax ZX80 v3 n8 (Volume 3, Issue 8)
Date: August 1982
Pages: 6-7

This simple 16-byte machine code program fills the screen with any character. It executes faster and takes up less space than the BASIC program by Paul Qualls, Jr., in Jun.82 (p.20).

The MC routine is contained in this REM statement:

Line 1 REM statement holding the machine code
Line 1 REM statement holding the machine code

There are 16 keystrokes after REM. For easy typing, follow this guide. Finished result should look like the line above:

1 REM Y inverseSPACE graphicT graphic4 : inverseK tokenNOT $ tokenTAB inverseH tokenRND graphic5 tokenTAB graphicY tokenRND tokenTAN

Don’t type any spaces. Spaces in line 1 come from keywords (tokens).

Execute line 1 by entering RAND USR 16514 in the FAST mode. Almost instantly, the entire screen blackens. The second keystroke after REM is the fill character, here inverse space. To change this character, substitute another for the inverse space, or POKE the new character’s code to address 16515 in the immediate mode (with no line number). Be sure this REM line is the first line in your program.

The assembly listing for this routine (128 in location 16515 is inverse space) follows next page.

Loc.    Dec.  Hex          Opcode       Comment

16514    62   3E           LD A,N       ;load code of fill character in A
16515   128   80
16516     6   06           LD B,04      ;set LOOP1 counter for 4
                                         iterations
16517     4   04
16518    14   0E    LOOP1: LD C,B0      ;set LOOP2 counter for 176
                                         iterations
16519   176   B0
16520   215   D7    LOOP2: rst 10       ;character printing routine
16521    13   0D           DEC C        ;reduce LOOP2 counter by 1
16522   194   C2           JPNZ,LOOP2;  if C=0, go to LOOP2
16523   136   88
16524    64   40
16525     5   05           DEC B        ;reduce LOOP1 counter by 1
16526   194   C2           JPNZ,LOOP1;  if B=0, go to LOOP1
16527   134   86
16528    64   40
16529   201   C9           ret          ;B=0, return to BASIC

Using a loop within another loop, this ML program executes the character printing routine exactly 704 times (4*176=704), which fills the screen. By POKEing smaller values into registers B and C, you can fill as much of the screen as you wish.


If you’d rather POKE the decimal values in, use a loader program:

 1 REM (16 spaces)
2 FOR X=16514 TO 16529
3 INPUT I
4 POKE X,I
5 NEXT X

RUN, then input the numbers in the assembly listing dec. column, hitting ENTER or NEWLINE after each. After the last number press LIST then ENTER or NEWLINE to see the listing again. Line 1 now looks like Dr. Miller’s line 1. Delete lines 2-5. Or use David Ornstein‘s XFER hex loading program (Jun.82) to load the hex numbers.–AZ

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