ZX81/TS1000 Tips

See all articles from SINCUS v7 n1

12. Here is a set of Machine code routines that uses a Floating Point Number as an address. It is a very useful set of routines, as it enables you to input strings with machine code. We actually use the BASIC interpreter by copying the BASIC commands into the Print buffer everytime we need an input and make the BASIC Interpreter run it, then return to the Machine Code. For example we will set RAMTOP at 29952 (7500h) and our entry point to input A$, at 30000 (7530h). The routines are:

Storage:

   7500 0000            Store: SPARE 3
(29952) 0000 SPARE 4
4 Bytes

Commands:

       LINE    COUNT   INPUT  A   $    N/L
7504 0000 0400 EE 26 0D 76 ; Input A$
LINE COUNT RAND USR 0 NUMBER
750C 0000 0A00 F9 D4 IC 7E; RAND USR 751B
___751B_____ N/L N/L
7514 8FEA 360000 76 76 (29979)
23 Bytes
751B E1  RAND USR 0;          POP HL
ED 7B 7B 40 LD SP, (SPARE 2); Restore SP
2A 00 75 LD HL, (SPARE 3);
22 29 40 LD(NXTLIN), HL ;(Restore NXTLIN)
7526 2A 10 40 LD HL, (VARS) ;get A$
23 INC HL ;skip over string name
4E LD C,(HL) ;Low count
23 INC HL
46 LD B, (HL) ;Hi count
23 INC HL
7E LD A, (HL) ;1st byte of A$
C9 RET
21 Bytes

Note: This routine returns with HL pointing to the 1st byte of A$, BC contains the count and A contains a copy of the 1st byte.

7530 ED 73 7B 40    INA$:     LD(SPARE 2), SP  ; SAVE SP
2A 29 40 LD HL,(NXTLIN)
22 00 75 LD (SPARE 3), HL ; SAVE (NXTLIN)
CD 9A 14 CALL 149A, CLEAR
21 04 75 LD HL, Commands
11 3C 40 LD DE, PR-BUFF
01 17 00 LD BC, 0017 ; 23 bytes
ED B0 LDIR ; Copy up
21 76 06 LD HL, 0676 ; Next-line
E5 PUSH HL
21 3C 40 LD HL, 403C ; PR-BUFF
22 29 40 LD(NXTLIN), HL
C9 RET
35 Bytes
83 BYTES TOTAL