ZX81/TS1000 Tips

See all articles from SINCUS v8 n1

16. Here is another OCTAL Input and List program. This one is based on Machine Code with BASIC support. “Why OCTAL?”, You may ask. My reason for including it is due to the fact that the Z-80 microprocessor is an upgraded version of the 8080 microprocessor and like the 8080 the Z-80’s instruction code is based on OCTAL code. When the instruction codes are written in OCTAL it is easier to see what is happening inside the microprocessor. By the way the 8080 has 78 different types of instruction codes (a total of 244 possible instruction codes). All of the instruction codes are not printed in the Timex 1000 Manual. I will give You the missing codes in the next Tip.

OCTAL

1 REM 137' BLOCK of Machine Code.
5 REM "OCTAL"
10 LET A = 16514
20 PRINT "ADDRESS (DEC) ";
30 INPUT A$
40 PRINT A$,,,
50 POKE A + 1, INT (VAL A$ / 256)
60 POKE A, VAL A$ - 256 * INT
(VAL A$ / 256)
70 CLEAR
80 RETURN
100 PRINT "OCTAL WRITE"
110 GOSUB 10
120 INPUT A$
130 IF A$ = "" THEN GOTO 250
140 LET A$ = A$ + " "
150 IF A$ <> 4 * INT (LEN A$ / 4) THEN GOTO 120
160 PRINT PEEK 16514 + 256 * PEEK 16515;" ";
170 RAND USR 16516
180 GOTO 120
200 PRINT "OCTAL LIST"
210 GOSUB 10
220 RAND USR 16609
250 PRINT
260 PRINT "DONE"

MACHINE CODE:

( 16514 )  4082 0000      MCV-1:      ADDR
2 bytes
( 16516 ) 4084 2A1040 O-WRITE: LD HL, ( VARS )
23 INC HL
46 LD B, (HL) ; count
CB38 SRL B
CB38 SRL B
23 INC HL
408E C5 NEXT: PUSH BC
23 INC HL
4090 7E 1st Digit: LD A, (HL) ; Oct Hi
FE20 CP 20 ; 4 dec.
3049 JR NC, REPORT B
23 INC HL
E5 PUSH HL ; Save Pntr.
CD1B15 CALL 151B, STK-A (-2)
3E40 LD A, 40 ; 64 dec.
CD1D15 CALL 151D, STACK-A
E1 POP HL
40A0 7E 2nd Digit; LD A, (HL) ; Oct Mid
FE24 CP 24 ; 8 dec.
3039 JR NC, REPORT-B
23 INC HL
CD1B15 CALL 151B, STK-A (-2)
3E08 LD A, 08
CD1D15 CALL 151D, STACL-A
E1 POP HL
40B0 7E 3rd Digit: LD A, (HL)
FE24 CP 24 ; 8 dec.
3029 JR NC, REPORT-B
23 INC HL
E5 PUSH HL
CD1B15 CALL 151B, STK-A (-2)
40BA EF CALCULATE: RST 28 ; Use Calculator
C1 DEFB: C1 ; Store-1
02 DEFB: 02 ; Delete Last Val
04 DEFB: 04 ; Multiply
C0 DEFB: C0 ; Store-0
02 DEFB: 02 ; Delete Last Val
04 DEFB: 04 ; Multiply
E0 DEFB: E0 ; Recall-0
0F DEFB: 0F ; Add
E1 DEFB: E1 ; Recall-1
0F DEFB: 0F ; Add
34 DEFB: 34 ; End Calculating
40C6 CDCD15 GET-VAL: CALL 15CD, FP-TO-A
4F LD C,A ; Save A in C
E1 POP HL
AF XOR A
BE CP (HL)
200F JR NZ, REPORT-B
79 LD A, C ; Recover A
ED5B8240 LD DE, (ADDR)
12 LD (DE), A
13 INC DE
ED538240 LD (ADDR), DE
C1 POP BC
40DB 10B1 END-CK: DJNZ NEXT
C9 RET
40DE C1 REPORT-B: POP BC
CF0A RST 08 DEFB: 0A ;REPORT-B
93 bytes
( 16609 ) 40E1 2A8240 O-PRINT: LD HL, (ADDR)
7E LD A, (HL)
F5 PUSH AF ; Save A
E6C0 AND C0 ; Mask bits 0-5
0606 LD B, 06
40EA 1F LOOP-1: RRA ; Position bits 6-7
10FD DJNZ LOOP-1
C61C ADD 1C ; 28 dec.
D7 RST 10 ; Print A
F1 POP AF
F5 PUSH AF
E638 AND 38 ; Mask bits 0,1,2,6,7
0603 LD B, 03
40F6 1F LOOP-2: RRA ; Position bits 3,4,5
10FD DJNZ LOOP-2
C61C ADD 1C ; 28 dec.
D7 RST 10 ; Print A
F1 POP AF
E607 AND 07 ; Mask bits 3-7
C61C ADD 1C ; 28 dec.
D7 RST 10 ; Print A
23 INC HL
228240 LD (ADDR), HL
3E76 LD A, 76 ; N/L
D7 RST 10 ; Print Line Feed
18D6 JR O-PRINT
42 bytes
( 16651 ) 410B NEXT BYTE 137 Bytes Total