A Basic Eraser

Author(s): Dave Wood
Pub Details: Sinclair Timex User Group Newsletter v3 n1 (Volume 3, Issue 1)
Date: January 1984
Pages: 5

The following 5-line BASIC program demonstrates several useful machine language concepts. One; it shows the idea of entering machine code as decimal character triplets, which are translated into decimal numbers by the VAL instruction using three characters at a time. Two; it shows the use of the print buffer at 16444 for temporary storage of a short machine code program. Three; the program itself shows the application of a number of ROM routines

TFAST (02E7h) will temporarily place the computer in FAST mode.

LINEADDR (09D8h) will locate the memory address of a BASIC line, given its line number in the HL register.

ZAPDIF (0A5Dh) will erase memory from where HL points up to, but not including, where DE points.

RMODE (0207h) will return the computer to the original mode ( FAST or SLOW).

RST 8 goes to the system error return.

This BASIC/machine code program will erase a block of BASIC program extending from where the cursor is pointing to the end of BASIC. To use the program, simply set the cursor and enter GOTO 100. By using the error exit ( RST 8) rather than return, the erase program is oblivious to self destruction – it can erase itself with no ill effects. Do make sure that line 100 is correct before you run it. The string should contain 63 characters with no blanks.

100 LET X$="205231002042010064205216009235042012064205093010205007002207255"
110 FOR I=0 TO 20
120 POKE 16444+I, VAL X$(3*I+1 TO 3*(I+1))
130 NEXT I
140 RAND USR 16444

The machine code in statement 100:

CD E7 02  CALL TFAST      Go to temporary FAST
2A 0A 40 LD HL,(E-PPC) Fetch line no. of cursor
CD D8 09 CALL LINEADDR Get address of that line
EB EX DE,HL Move addr. to DE
2A 0C 40 LD HL,(D-FILE) Get addr. past BASIC end
CD 5D 0A CALL ZAPDIF Erase BASIC
CD 07 02 CALL RMODE Return to original mode
CF RST 8 Return control to system:
FF DEFB FF and provide "0" return code

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