[ZX81 Type-in] ZX-81 GT COMPILER

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
David G
Posts: 387
Joined: Thu Jul 17, 2014 7:58 am
Location: 21 North, 156 West

Re: [ZX81 Type-in] ZX-81 GT COMPILER

Post by David G »

Thanks, Xav. I am typing the entire article for the experience and to understand how it works. I realize there are P files available, but i found no complete type-in of the program and instructions. That link goes to MCODER, the commercial version of ZXGT. And yes, it does work. There are six bytes that differ between ZXGT and MCODER

In addition to the hex byte '18' vs '1B' that you point out, the
* article text says the REM must be 2303 bytes
* hex listing is 2302 bytes (and not working)
* MCODER's REM 0 is 2301 bytes (and working)

I suspect this is causing the REM2 creation portion of the code to fail, as it depends on a certain length of REM. In fact if I shorten the REM, then it starts working

For me, the challenge is not to obtain a working copy, but instead, like a jigsaw puzzle, the fun is in putting it together
Moggy
Posts: 3231
Joined: Wed Jun 18, 2008 2:00 pm

Re: [ZX81 Type-in] ZX-81 GT COMPILER

Post by Moggy »

I thought this sounded familiar, a bit late in the day I know so apologies but I actually posted the P file for ZXGT eight years ago. The relevant thread and download can be found here.

viewtopic.php?t=1393
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: [ZX81 Type-in] ZX-81 GT COMPILER

Post by XavSnap »

Thanks Moggy,

David vs Moggy:
DAVCODER.jpg
C3:AA:47 was an orphan jump offset... set to $47AB.

Code: Select all

;------- TASM ASM mnemonics. -------
; Compile this file using:
; Set TASMOPTS = -b
; tasm -80 ThisCode.tas MyBinary.BIN
;-----------------------------------
; Zx81 Program name: VB81 XuR [ZXGT Compiler (1982)(Personal Software Services).p] :ZXGT.P
; REM   line   name: D=16514/18814 : H=4082/497E

#define ORG  .org       ; TASM cross-assembler definitions
#define equ  .equ
;-----------------------------------
;- ZX81 CARACTERS CODES ------------
;-----------------------------------
_G   .equ $AC
_T   .equ $B9
_X   .equ $BD
_Z   .equ $BF
;-----------------------------------

;------- ROM and RAM Symbols -------
RAM_D_FILE equ $400C
RAM_DF_CC equ $400E
RAM_S_POSN equ $4039
KEYBOARD equ $02BB
DECODE equ $07BD
RAM_FRAMES equ $4034
RAM_T_ADDR equ $4030
CLS equ $0A2A
COPY equ $0869
RAM_SEED equ $4032
MAKE_ROOM equ $099E
RAM_SPARE2 equ $407B
RAM_MEMBOT13 equ $4070
RAM_STKEND equ $401C
RAM_MEMBOT1C equ $4079
RAM_CH_ADD equ $4016
RAM_S_TOP equ $4023
RAM_E_PPC equ $400A
RAM_MEMBOT15 equ $4072
SET_FAST equ $02E7
SLOW_FAST equ $0207


ORG $4082 ; [@16514/@h4082]
.db _Z,_X,_G,_T; ZX-TEXT

.db $76,$76; DATA
Lb4088:
	JP Lb40B4 ; [16564]
Lb408B:
	JP Lb4123 ; [16675]
Lb408E:
	JP Lb4157 ; [16727]
Lb4091:
	JP Lb414F ; [16719]
Lb4094:
	JP Lb4185 ; [16773]
Lb4097:
	JP Lb4197 ; [16791]
Lb409A:
	JP Lb41AB ; [16811]
Lb409D:
	JP Lb4221 ; [16929]
Lb40A0:
	JP Lb429C ; [17052]
Lb40A3:
	JP Lb42DE ; [17118]
Lb40A6:
	JP Lb4339 ; [17209]
Lb40A9:
	JP Lb437A ; [17274]
Lb40AC:
	JP Lb4357 ; [17239]
Lb40AF:
	JP Lb43B8 ; [17336]
Lb40B2:
	RST 08H 
.db	$8C ; RST8 Arg: Error Code:'D'
Lb40B4:
	PUSH HL 
	PUSH DE 
	XOR A 
	CALL Lb4221 ; [16929]
	BIT 7,H 
	JR Z, Lb40C6 ; [$40C6:16582]
	LD A,$16 
	CALL Lb4221 ; [16929]
	CALL Lb411B ; [16667]
Lb40C6:
	LD DE,$2710 
	CALL Lb4107 ; [16647]
	JR NC, Lb40E8 ; [$40E8:16616]
	LD DE,$03E8 
	CALL Lb4107 ; [16647]
	JR NC, Lb40EB ; [$40EB:16619]
	LD DE,$0064 
	CALL Lb4107 ; [16647]
	JR NC, Lb40F1 ; [$40F1:16625]
	LD E,$0A 
	CALL Lb4107 ; [16647]
	JR NC, Lb40F7 ; [$40F7:16631]
	JP Lb40FC ; [16636]
Lb40E8:
	CALL Lb410D ; [16653]
Lb40EB:
	LD DE,$03E8 
	CALL Lb410D ; [16653]
Lb40F1:
	LD DE,$0064 
	CALL Lb410D ; [16653]
Lb40F7:
	LD E,$0A 
	CALL Lb410D ; [16653]
Lb40FC:
	LD E,$01 
	CALL Lb410D ; [16653]
	XOR A 
	POP DE 
	POP HL 
	JP Lb4221 ; [16929]
Lb4107:
	PUSH HL 
	AND A 
	SBC HL,DE 
	POP HL 
	RET ; ==========================

Lb410D:
	LD A,$1C 
	AND A 
Lb4110:
	SBC HL,DE 
	JR C, Lb4117 ; [$4117:16663]
	INC A 
	JR Lb4110 ; [$4110:16656]
Lb4117:
	ADD HL,DE 
	JP Lb4221 ; [16929]
Lb411B:
	LD A,H 
	CPL 
	LD H,A 
	LD A,L 
	CPL 
	LD L,A 
	INC HL 
	RET ; ==========================

Lb4123:
	LD HL,(RAM_D_FILE) ; GET D-FILE
	LD DE,$0021 
	PUSH HL 
	LD BC,$0000 
	ADD HL,BC 
	INC HL 
	PUSH HL 
	ADD HL,DE 
	EX DE,HL 
	LD HL,$02D6 
	SBC HL,BC 
	EX (SP),HL 
	POP BC 
	EX DE,HL 
	LDIR 
	POP HL 
	LD BC,$02B6 
	ADD HL,BC 
	LD (RAM_DF_CC),HL ; SET DF-CC
	LD A,$21 
	LD (RAM_S_POSN),A ; SET S-POSN
	LD A,$03 
	LD (RAM_S_POSN+1),A ; SET S-POSN
	RET ; ==========================

Lb414F:
	CALL KEYBOARD ; [KEYBOARD]
	LD A,H 
	CP $FE ; [254]
	JR NZ, Lb4165 ; [$4165:16741]
Lb4157:
	CALL KEYBOARD ; [KEYBOARD]
	INC H 
	JR NZ, Lb4157 ; [$4157:16727]
Lb415D:
	CALL KEYBOARD ; [KEYBOARD]
	LD A,L 
	CP $FF ; [255]
	JR Z, Lb415D ; [$415D:16733]
Lb4165:
	LD BC,$FD7F 
	XOR A 
	PUSH HL 
	SBC HL,BC 
	POP HL 
	JP Z, Lb40B2 ; [16562]
	LD BC,$FCEF 
	XOR A 
	PUSH HL 
	SBC HL,BC 
	POP HL 
	JR Z, Lb4157 ; [$4157:16727]
	LD B,H 
	INC H 
	RET Z 
	LD C,L 
	CALL DECODE ; [DECODE]
	LD A,(HL) 
	CP $00 ; [0]
	RET ; ==========================

Lb4185:
	SET 7,H 
	LD (RAM_FRAMES),HL ; SET FRAMES
Lb418A:
	LD HL,(RAM_FRAMES) ; GET FRAMES
	LD A,H 
	AND $7F 
	OR L 
	RET Z 
	CALL Lb414F ; [16719]
	JR Z, Lb418A ; [$418A:16778]
Lb4197:
	LD B,$10 
	LD C,D 
	LD A,E 
	EX DE,HL 
	LD HL,$0000 
Lb419F:
	SRL C 
	RRA 
	JR NC, Lb41A5 ; [$41A5:16805]
	ADD HL,DE 
Lb41A5:
	EX DE,HL 
	ADD HL,HL 
	EX DE,HL 
	DJNZ Lb419F ; [$419F:16799]
	RET ; ==========================

Lb41AB:
	LD A,$2B 
	SUB B 
	JP C, Lb42DC ; [17116]
	LD B,A 
	LD A,$01 
	SRA B 
	JR NC, Lb41BA ; [$41BA:16826]
	LD A,$04 
Lb41BA:
	SRA C 
	JR NC, Lb41C0 ; [$41C0:16832]
	RLC A 
Lb41C0:
	PUSH AF 
	CALL Lb41EB ; [16875]
	LD A,(HL) 
	RLC A 
	CP $10 ; [16-"("]
	JR NC, Lb41D2 ; [$41D2:16850]
	RRC A 
	JR NC, Lb41D1 ; [$41D1:16849]
	XOR $8F 
Lb41D1:
	LD B,A 
Lb41D2:
	LD DE,$0C9E 
	LD A,(RAM_T_ADDR) ; GET T-ADDR
	SUB E 
	JP M, Lb41E1 ; [16865]
	POP AF 
	CPL 
	AND B 
	JR Lb41E3 ; [$41E3:16867]
Lb41E1:
	POP AF 
	OR B 
Lb41E3:
	CP $08 ; [8]
	JR C, Lb41E9 ; [$41E9:16873]
	XOR $8F 
Lb41E9:
	JR Lb4221 ; [$4221:16929]
Lb41EB:
	LD A,$17 
	SUB B 
	JP C, Lb42DC ; [17116]
	LD A,C 
	AND $1F 
	LD C,A 
	PUSH BC 
	PUSH BC 
	PUSH BC 
	XOR A 
	RL B 
	RL B 
	RL B 
	LD L,B 
	LD H,A 
	ADD HL,HL 
	ADD HL,HL 
	POP BC 
	LD C,B 
	LD B,A 
	ADD HL,BC 
	POP BC 
	LD B,A 
	ADD HL,BC 
	LD BC,(RAM_D_FILE) ; GET D-FILE
	ADD HL,BC 
	INC HL 
	LD (RAM_DF_CC),HL ; SET DF-CC
	POP BC 
	LD A,$18 
	SUB B 
	LD (RAM_S_POSN+1),A ; SET S-POSN
	LD A,$21 
	SUB C 
	LD (RAM_S_POSN),A ; SET S-POSN
	RET ; ==========================

Lb4221:
	PUSH DE 
	PUSH HL 
	PUSH BC 
	PUSH AF 
	LD A,(RAM_S_POSN+1) ; GET S-POSN
	CP $02 ; [2]
	JR Z, Lb4266 ; [$4266:16998]
	POP AF 
Lb422D:
	CP $76 ; [118]
	JR Z, Lb425B ; [$425B:16987]
	CP $40 ; [64]
	JR NC, Lb42A7 ; [$42A7:17063]
Lb4235:
	LD HL,(RAM_DF_CC) ; GET DF-CC
	LD (HL),A 
	INC HL 
	LD (RAM_DF_CC),HL ; SET DF-CC
	LD A,(RAM_S_POSN) ; GET S-POSN
	DEC A 
	LD (RAM_S_POSN),A ; SET S-POSN
	LD A,(HL) 
	CP $76 ; [118]
	JR NZ, Lb4293 ; [$4293:17043]
Lb4249:
	LD A,(RAM_S_POSN+1) ; GET S-POSN
	DEC A 
	LD (RAM_S_POSN+1),A ; SET S-POSN
	INC HL 
	LD (RAM_DF_CC),HL ; SET DF-CC
	LD A,$21 
	LD (RAM_S_POSN),A ; SET S-POSN
	JR Lb4293 ; [$4293:17043]
Lb425B:
	LD HL,(RAM_DF_CC) ; GET DF-CC
Lb425E:
	LD A,(HL) 
	CP $76 ; [118]
	JR Z, Lb4249 ; [$4249:16969]
	INC HL 
	JR Lb425E ; [$425E:16990]
Lb4266:
	LD HL,(RAM_D_FILE) ; GET D-FILE
	LD BC,$02F8 
	ADD HL,BC 
	LD (HL),$8F 
Lb426F:
	CALL Lb414F ; [16719]
	JR Z, Lb426F ; [$426F:17007]
	CP $28 ; [40-"C"]
	JR Z, Lb428D ; [$428D:17037]
	CP $3F ; [63-"Z"]
	JR Z, Lb4297 ; [$4297:17047]
	CP $29 ; [41-"D"]
	JR NZ, Lb4288 ; [$4288:17032]
	LD HL,$2710 
Lb4283:
	DEC HL 
	LD A,L 
	OR H 
	JR NZ, Lb4283 ; [$4283:17027]
Lb4288:
	CALL Lb4123 ; [16675]
	JR Lb4290 ; [$4290:17040]
Lb428D:
	CALL CLS ; [CLS]
Lb4290:
	POP AF 
	JR Lb422D ; [$422D:16941]
Lb4293:
	POP BC 
	POP HL 
	POP DE 
	RET ; ==========================

Lb4297:
	CALL COPY ; [COPY]
	JR Lb426F ; [$426F:17007]
Lb429C:
	LD A,B 
	OR C 
	RET Z 
	LD A,(DE) 
	CALL Lb4221 ; [16929]
	INC DE 
	DEC BC 
	JR Lb429C ; [$429C:17052]
Lb42A7:
	CP $43 ; [67]
	JR C, Lb42B4 ; [$42B4:17076]
	CP $C0 ; [192]
	RES 6,A 
	JP C, Lb4235 ; [16949]
	AND $3F 
Lb42B4:
	LD HL,$0111 
	LD B,A 
	INC B 
	CP $21 ; [33-"5"]
	JR NC, Lb42C1 ; [$42C1:17089]
	XOR A 
	CALL Lb4221 ; [16929]
Lb42C1:
	BIT 7,(HL) 
	INC HL 
	JR Z, Lb42C1 ; [$42C1:17089]
	DJNZ Lb42C1 ; [$42C1:17089]
Lb42C8:
	LD A,(HL) 
	BIT 7,A 
	JR NZ, Lb42D3 ; [$42D3:17107]
	CALL Lb4221 ; [16929]
	INC HL 
	JR Lb42C8 ; [$42C8:17096]
Lb42D3:
	AND $3F 
	CALL Lb4221 ; [16929]
	XOR A 
	JP Lb422D ; [16941]
Lb42DC:
	RST 08H 
.db	$8A ; RST8 Arg: Error Code:'B'
Lb42DE:
	LD A,E 
	OR D 
	JR Z, Lb42DC ; [$42DC:17116]
	CALL Lb4329 ; [17193]
	PUSH BC 
	LD A,H 
	OR D 
	RLCA 
	JR C, Lb42DC ; [$42DC:17116]
	LD C,E 
	LD B,D 
	LD DE,$0000 
	PUSH DE 
	EX DE,HL 
	INC HL 
Lb42F3:
	ADD HL,HL 
	EX DE,HL 
	ADD HL,HL 
	LD A,C 
	SUB L 
	LD A,B 
	SBC A,H 
	EX DE,HL 
	JR NC, Lb42F3 ; [$42F3:17139]
	EX DE,HL 
Lb42FE:
	EX DE,HL 
	XOR A 
	LD A,H 
	RRA 
	LD H,A 
	LD A,L 
	RRA 
	LD L,A 
	OR H 
	JR Z, Lb4321 ; [$4321:17185]
	EX DE,HL 
	XOR A 
	RR H 
	RR L 
	LD A,C 
	SUB L 
	LD A,B 
	SBC A,H 
	JP M, Lb42FE ; [17150]
	LD A,C 
	SUB L 
	LD C,A 
	LD A,B 
	SBC A,H 
	LD B,A 
	EX (SP),HL 
	ADD HL,DE 
	EX (SP),HL 
	JR Lb42FE ; [$42FE:17150]
Lb4321:
	POP HL 
	POP BC 
	BIT 7,B 
	JP NZ, Lb411B ; [16667]
	RET ; ==========================

Lb4329:
	LD B,H 
	LD A,H 
	RLA 
	CALL C, Lb411B ; [16667]
	EX DE,HL 
	LD A,H 
	XOR B 
	LD B,A 
	BIT 7,H 
	JP NZ, Lb411B ; [16667]
	RET ; ==========================

Lb4339:
	LD DE,(RAM_SEED) ; GET SEED
	LD H,E 
	LD L,$FD 
	LD A,D 
	OR A 
	LD B,$00 
	SBC HL,DE 
	SBC A,B 
	SBC HL,DE 
	SBC A,B 
	LD E,A 
	LD D,B 
	SBC HL,DE 
	JR NC, Lb4351 ; [$4351:17233]
	INC HL 
Lb4351:
	LD (RAM_SEED),HL ; SET SEED
	RES 7,H 
	RET ; ==========================

Lb4357:
	INC BC 
	INC BC 
	INC BC 
	PUSH BC 
	INC BC 
	INC BC 
	INC BC 
	INC BC 
	LD HL,$4980 
	CALL MAKE_ROOM+5 ; []*BIOS ROM*
	INC HL 
	LD A,$76 
	LD (HL),C 
	INC HL 
	LD (HL),$02 
	INC HL 
	POP BC 
	LD (HL),C 
	INC HL 
	LD (HL),B 
	INC HL 
	LD (HL),$EA 
	INC HL 
	LD (HL),A 
	INC HL 
	LD (HL),A 
	INC HL 
	RET ; ==========================

Lb437A:
	LD HL,$0000 
	PUSH HL 
Lb437E:
	PUSH HL 
Lb437F:
	CALL Lb4157 ; [16727]
	CP $16 ; [22-"-"]
	JR NZ, Lb438F ; [$438F:17295]
	POP HL 
	POP DE 
	PUSH AF 
	PUSH HL 
	CALL Lb4221 ; [16929]
	JR Lb437F ; [$437F:17279]
Lb438F:
	CP $76 ; [118]
	POP HL 
	JR Z, Lb43B3 ; [$43B3:17331]
	ADD HL,HL 
	PUSH HL 
	ADD HL,HL 
	ADD HL,HL 
	POP DE 
	ADD HL,DE 
	LD C,A 
	CALL Lb4221 ; [16929]
	LD A,C 
	SUB $1C 
	JR C, Lb43AB ; [$43AB:17323]
	LD C,A 
	LD B,$00 
	ADD HL,BC 
	CP $0A ; [10]
	JR C, Lb437E ; [$437E:17278]
Lb43AB:
	POP AF 
	LD A,$E6 
	CALL Lb4221 ; [16929]
	JR Lb437A ; [$437A:17274]
Lb43B3:
	POP AF 
	CALL Z, Lb411B ; [16667]
	RET ; ==========================

Lb43B8:
	PUSH BC 
	PUSH HL 
	LD HL,(RAM_SPARE2) ; GET UNUSED-16
	PUSH AF 
	LD (HL),A 
	PUSH HL 
	INC HL 
	LD (RAM_SPARE2),HL ; SET UNUSED-16
	CALL Lb414F ; [16719]
	CP $29 ; [41-"D"]
	JR NZ, Lb43DD ; [$43DD:17373]
	LD A,$76 
	CALL Lb4221 ; [16929]
	POP HL 
	CALL Lb40B4 ; [16564]
	POP AF 
	LD H,$00 
	LD L,A 
	CALL Lb40B4 ; [16564]
	JR Lb43DF ; [$43DF:17375]
Lb43DD:
	POP HL 
	POP AF 
Lb43DF:
	POP HL 
	POP BC 
	XOR A 
	RET ; ==========================

Lb43E3: ; <17379>
	RET ; ==========================

Lb43E4: ; <17380>
	RET ; ==========================

Lb43E5: ; <17381>
	LD A,$0F 
	RST 10H ; Display= A reg.
	CALL Lb4975 ; [18805]
	JR Lb43FF ; [$43FF:17407]
Lb43ED: ; <17389>
	LD HL,$0000 
	CALL Lb4412 ; [17426]
	CALL Lb48F7 ; [18679]
	INC BC 
	CALL Lb4978 ; [18808]
	PUSH HL 
	CALL Lb4906 ; [18694]
	POP HL 
Lb43FF:
	CALL Lb4412 ; [17426]
	CALL Lb4959 ; [18777]
	CALL Lb4420 ; [17440]
	CALL Lb440D ; [17421]
	RST 08H 
.db	$7F ; RST8 Arg: Error Code:'0'
Lb440D:
	LD A,$C9 
	JP Lb497B ; [18811]
Lb4412:
	LD (RAM_MEMBOT13),HL ; SET MEMBOT
	LD DE,(RAM_STKEND) ; GET STKEND
	INC DE 
	LD HL,$4072 
	CALL Lb4509 ; [17673]
Lb4420:
	LD HL,(RAM_MEMBOT13) ; GET MEMBOT
	LD (HL),$18 
	INC HL 
	LD (HL),$68 
	INC HL 
	LD (RAM_MEMBOT1C),HL ; SET MEMBOT
	LD DE,$0068 
	ADD HL,DE 
	LD (RAM_SPARE2),HL ; SET UNUSED-16
	LD HL,$407D 
Lb4436:
	CALL Lb44D4 ; [17620]
	INC HL 
	INC HL 
	PUSH HL 
	INC HL 
	LD (RAM_CH_ADD),HL ; SET CH-ADD
Lb4440:
	CALL Lb4544 ; [17732]
	CP $F2 ; [242]
	CALL Z, Lb44CB ; [17611]
	CP $F9 ; [249]
	CALL Z, Lb4896 ; [18582]
	CP $FA ; [250]
	CALL Z, Lb48C8 ; [18632]
	CP $DE ; [222]
	JR Z, Lb4440 ; [$4440:17472]
	CP $E9 ; [233]
	CALL Z, Lb491D ; [18717]
	CP $EC ; [236]
	CALL Z, Lb452B ; [17707]
	CP $ED ; [237]
	CALL Z, Lb4540 ; [17728]
	CP $EB ; [235]
	CALL Z, Lb47C7 ; [18375]
	CP $F3 ; [243]
	CALL Z, Lb47F4 ; [18420]
	CP $E4 ; [228]
	CALL Z, Lb4900 ; [18688]
	CP $F4 ; [244]
	CALL Z, Lb47B6 ; [18358]
	CP $E5 ; [229]
	CALL Z, Lb48F1 ; [18673]
	CP $EE ; [238]
	CALL Z, Lb485D ; [18525]
	CP $F6 ; [246]
	CALL Z, Lb486C ; [18540]
	CP $FC ; [252]
	CALL Z, Lb4892 ; [18578]
	CP $F1 ; [241]
	CALL Z, Lb4603 ; [17923]
	CP $FB ; [251]
	CALL Z, Lb479F ; [18335]
	CP $E3 ; [227]
	JP Z, Lb4796 ; [18326]
	CP $F5 ; [245]
	CALL Z, Lb4555 ; [17749]
	CP $EA ; [234]
	JR Z, Lb44BA ; [$44BA:17594]
	CP $E7 ; [231]
	CALL Z, Lb47A4 ; [18340]
	CP $FE ; [254]
	CALL Z, Lb440D ; [17421]
	CP $00 ; [0]
	JR NZ, Lb44C1 ; [$44C1:17601]
	CALL Lb4544 ; [17732]
	CP $76 ; [118]
	JR NZ, Lb44C1 ; [$44C1:17601]
Lb44BA:
	POP HL 
	CALL Lb490E ; [18702]
	JP NZ, Lb4436 ; [17462]
Lb44C1:
	LD A,$B8 
	CALL Lb4968 ; [18792]
	CALL Lb4959 ; [18777]
	RST 08H 
.db	$9B ; RST8 Arg: Error Code:'S'
Lb44CB:
	CALL Lb474D ; [18253]
	LD HL, Lb495F 
	JP Lb47A9 ; [18345]
Lb44D4:
	PUSH HL 
	LD D,(HL) 
	INC HL 
	LD E,(HL) 
	PUSH DE 
	EX DE,HL 
	PUSH HL 
	LD (RAM_S_TOP),HL ; SET S-TOP
	LD (RAM_E_PPC),HL ; SET E-PPC
	CALL Lb45EC ; [17900]
	CALL Lb4953 ; [18771]
	POP HL 
	CALL Lb4513 ; [17683]
	DEC DE 
	DEC DE 
	EX DE,HL 
	POP DE 
	CALL Lb4509 ; [17673]
	LD DE,(RAM_SPARE2) ; GET UNUSED-16
	CALL Lb4509 ; [17673]
	PUSH HL 
	LD DE,(RAM_MEMBOT15) ; GET MEMBOT
	AND A 
	SBC HL,DE 
	POP HL 
	JR C, Lb4507 ; [$4507:17671]
	LD (RAM_MEMBOT15),HL ; SET MEMBOT
Lb4507:
	POP HL 
	RET ; ==========================

Lb4509:
	LD (HL),E 
	INC HL 
	LD (HL),D 
	INC HL 
	RET ; ==========================

Lb450E:
	LD E,(HL) 
	INC HL 
	LD D,(HL) 
	INC HL 
	RET ; ==========================

Lb4513:
	PUSH HL 
	POP BC 
	LD HL,(RAM_STKEND) ; GET STKEND
Lb4518:
	INC HL 
	CALL Lb450E ; [17678]
	EX DE,HL 
	AND A 
	SBC HL,BC 
	RET NC 
	LD HL,(RAM_MEMBOT15) ; GET MEMBOT
	SBC HL,DE 
	RET C 
	EX DE,HL 
	INC HL 
	JR Lb4518 ; [$4518:17688]
Lb452B:
	LD A,$C3 
Lb452D:
	PUSH AF 
	CALL Lb4544 ; [17732]
	CALL Lb482A ; [18474]
	CALL Lb4513 ; [17683]
	EX DE,HL 
	CALL Lb450E ; [17678]
	EX DE,HL 
	POP AF 
	JP Lb47AB ; [18347]
Lb4540:
	LD A,$CD 
	JR Lb452D ; [$452D:17709]
Lb4544:
	PUSH HL 
	RST 20H 
	CP $76 ; [118]
	JR Z, Lb4553 ; [$4553:17747]
Lb454A:
	CP $7E ; [126]
	JR Z, Lb4553 ; [$4553:17747]
	PUSH AF 
	CALL Lb4968 ; [18792]
	POP AF 
Lb4553:
	POP HL 
	RET ; ==========================

Lb4555:
	CALL Lb4544 ; [17732]
	CP $76 ; [118]
	JR Z, Lb45D3 ; [$45D3:17875]
	CP $0B ; [11-"""]
	JR Z, Lb4573 ; [$4573:17779]
	CP $C1 ; [193]
	JR Z, Lb45B0 ; [$45B0:17840]
	CP $D6 ; [214]
	JR Z, Lb45DC ; [$45DC:17884]
	CALL Lb4750 ; [18256]
	LD HL, Lb4953 
	CALL Lb47A9 ; [18345]
	JR Lb45C2 ; [$45C2:17858]
Lb4573:
	LD A,$18 
	CALL Lb497B ; [18811]
	LD HL,(RAM_SPARE2) ; GET UNUSED-16
	PUSH HL 
	CALL Lb497B ; [18811]
	LD BC,$FFFF 
	LD HL,(RAM_CH_ADD) ; GET CH-ADD
Lb4585:
	INC HL 
	INC BC 
	LD A,(HL) 
	PUSH AF 
	CALL Lb4968 ; [18792]
	POP AF 
	CP $0B ; [11-"""]
	JR Z, Lb4596 ; [$4596:17814]
	CALL Lb497B ; [18811]
	JR Lb4585 ; [$4585:17797]
Lb4596:
	LD (RAM_CH_ADD),HL ; SET CH-ADD
	POP HL 
	PUSH BC 
	LD (HL),C 
	INC HL 
	LD A,$11 
	CALL Lb47AB ; [18347]
	LD A,$01 
	POP HL 
	CALL Lb47AB ; [18347]
	LD HL, Lb496B 
	CALL Lb47A9 ; [18345]
	JR Lb45C2 ; [$45C2:17858]
Lb45B0:
	CALL Lb4737 ; [18231]
	CALL Lb47C1 ; [18369]
	LD HL,$4D43 
	CALL Lb47AE ; [18350]
	LD HL,$08F5 
	CALL Lb47A9 ; [18345]
Lb45C2:
	CALL Lb4544 ; [17732]
	CP $1A ; [26-","]
	JR Z, Lb4555 ; [$4555:17749]
	CP $19 ; [25-";"]
	JR Z, Lb4555 ; [$4555:17749]
	LD HL, Lb45EC 
	CALL Lb47A9 ; [18345]
Lb45D3:
	LD HL,(RAM_CH_ADD) ; GET CH-ADD
	DEC HL 
	LD (RAM_CH_ADD),HL ; SET CH-ADD
	XOR A 
	RET ; ==========================

Lb45DC:
	CALL Lb474D ; [18253]
	LD A,$7D 
	CALL Lb497B ; [18811]
	LD HL, Lb4968 
	CALL Lb47A9 ; [18345]
	JR Lb45C2 ; [$45C2:17858]
Lb45EC:
	LD A,$76 
	JP Lb4968 ; [18792]
Lb45F1:
	CP $40 ; [64]
	JP NC, Lb44C1 ; [17601]
	SUB $26 
	RLA 
	RLA 
	LD BC,(RAM_MEMBOT1C) ; GET MEMBOT
	LD H,$00 
	LD L,A 
	ADD HL,BC 
	RET ; ==========================

Lb4603:
	CALL Lb4544 ; [17732]
	CALL Lb45F1 ; [17905]
	CP $64 ; [100]
	JR NZ, Lb4617 ; [$4617:17943]
	CALL Lb492A ; [18730]
	LD A,$E5 
	CALL Lb497B ; [18811]
	LD H,$FF 
Lb4617:
	PUSH HL 
	CALL Lb4544 ; [17732]
	CP $14 ; [20-"="]
	JP NZ, Lb44C1 ; [17601]
	CALL Lb463D ; [17981]
	CALL Lb45D3 ; [17875]
	POP HL 
	LD A,H 
	CP $FF ; [255]
	JR NZ, Lb4638 ; [$4638:17976]
	LD HL,$EBD1 
	CALL Lb47AE ; [18350]
	LD HL, Lb4509 
	JP Lb47A9 ; [18345]
Lb4638:
	LD A,$22 
	JP Lb47AB ; [18347]
Lb463D:
	XOR A 
	PUSH AF 
	CALL Lb474D ; [18253]
Lb4642:
	LD A,$E5 
	CALL Lb497B ; [18811]
	CALL Lb4544 ; [17732]
	CP $11 ; [17-")"]
	JR Z, Lb469E ; [$469E:18078]
	CP $76 ; [118]
	JR Z, Lb469E ; [$469E:18078]
	PUSH AF 
	CALL Lb474D ; [18253]
	POP AF 
	CP $15 ; [21-"+"]
	JR Z, Lb465F ; [$465F:18015]
	CP $16 ; [22-"-"]
	JR NZ, Lb4682 ; [$4682:18050]
Lb465F:
	POP BC 
	LD H,A 
	LD A,B 
	CP $00 ; [0]
	JR NZ, Lb466A ; [$466A:18026]
	PUSH AF 
	PUSH HL 
	JR Lb4642 ; [$4642:17986]
Lb466A:
	PUSH HL 
	LD HL,$4D44 
	CALL Lb47AE ; [18350]
	CALL Lb467E ; [18046]
	LD A,$E5 
	LD HL,$6069 
	CALL Lb47AB ; [18347]
	JR Lb4642 ; [$4642:17986]
Lb467E:
	PUSH AF 
	PUSH BC 
	JR Lb469E ; [$469E:18078]
Lb4682:
	CP $18 ; [24-"/"]
	JR Z, Lb4696 ; [$4696:18070]
	CP $17 ; [23-"*"]
	JP NZ, Lb44C1 ; [17601]
	CALL Lb46C6 ; [18118]
	LD HL, Lb4962 
Lb4691:
	CALL Lb47A9 ; [18345]
	JR Lb4642 ; [$4642:17986]
Lb4696:
	CALL Lb46C6 ; [18118]
	LD HL, Lb496E 
	JR Lb4691 ; [$4691:18065]
Lb469E:
	LD A,$E1 
	CALL Lb497B ; [18811]
Lb46A3:
	POP AF 
	CP $00 ; [0]
	RET Z 
	CP $15 ; [21-"+"]
	JR Z, Lb46BC ; [$46BC:18108]
	CALL Lb46C6 ; [18118]
	LD HL,$EBA7 
	CALL Lb47AE ; [18350]
	LD HL,$52ED 
	CALL Lb47AE ; [18350]
	JR Lb46A3 ; [$46A3:18083]
Lb46BC:
	CALL Lb46C6 ; [18118]
	LD A,$19 
	CALL Lb497B ; [18811]
	JR Lb46A3 ; [$46A3:18083]
Lb46C6:
	LD A,$D1 
	JP Lb497B ; [18811]
Lb46CB:
	CP $D3 ; [211]
	JR NZ, Lb46DE ; [$46DE:18142]
	CALL Lb474D ; [18253]
	LD HL,$6F7E 
	CALL Lb47AE ; [18350]
	LD HL,$0026 
	JP Lb47AE ; [18350]
Lb46DE:
	CP $D4 ; [212]
	JR NZ, Lb46F4 ; [$46F4:18164]
	CALL Lb474D ; [18253]
	LD HL, Lb46EB 
	JP Lb47A9 ; [18345]
Lb46EB:
	LD BC,$46F1 
	PUSH BC 
	PUSH HL 
	RET ; ==========================

Lb46F1: ; <18161>
	LD B,H 
	LD C,L 
	RET ; ==========================

Lb46F4:
	CP $C4 ; [196]
	JP NZ, Lb470F ; [18191]
	CALL Lb4544 ; [17732]
	CP $41 ; [65]
	JP NZ, Lb44C1 ; [17601]
	LD HL, Lb495C 
	CALL Lb47A9 ; [18345]
	LD A,$26 
	LD HL,$6F00 
	JP Lb47AB ; [18347]
Lb470F:
	CP $40 ; [64]
	JP NZ, Lb471A ; [18202]
	LD HL, Lb4972 
	JP Lb47A9 ; [18345]
Lb471A:
	CP $D2 ; [210]
	JR NZ, Lb472F ; [$472F:18223]
	CALL Lb474D ; [18253]
	LD HL,$7CCB 
	CALL Lb47AE ; [18350]
	LD A,$C4 
	LD HL, Lb477A 
	JP Lb47AB ; [18347]
Lb472F:
	CP $CF ; [207]
	JP NZ, Lb44C1 ; [17601]
	JP Lb474D ; [18253]
Lb4737:
	CALL Lb474D ; [18253]
	CALL Lb4544 ; [17732]
	PUSH AF 
	LD A,$E5 
	CALL Lb497B ; [18811]
	CALL Lb474D ; [18253]
	LD A,$D1 
	CALL Lb497B ; [18811]
	POP AF 
	RET ; ==========================

Lb474D:
	CALL Lb4544 ; [17732]
Lb4750:
	CP $16 ; [22-"-"]
	PUSH AF 
	CALL Z, Lb4544 ; [17732]
	CP $10 ; [16-"("]
	JR Z, Lb4770 ; [$4770:18288]
	CP $40 ; [64]
	JR NC, Lb476B ; [$476B:18283]
	CP $26 ; [38-"A"]
	CALL NC, Lb4782 ; [18306]
	CALL C, Lb478F ; [18319]
Lb4766:
	POP AF 
	CALL Z, Lb4775 ; [18293]
	RET ; ==========================

Lb476B:
	CALL Lb46CB ; [18123]
	JR Lb4766 ; [$4766:18278]
Lb4770:
	CALL Lb463D ; [17981]
	JR Lb4766 ; [$4766:18278]
Lb4775:
	LD HL, Lb477A 
	JR Lb47A9 ; [$47A9:18345]
Lb477A:
	LD A,H 
	CPL 
	LD H,A 
	LD A,L 
	CPL 
	LD L,A 
	INC HL 
	RET ; ==========================

Lb4782:
	CALL Lb45F1 ; [17905]
	CP $64 ; [100]
	JP Z, Lb493F ; [18751]
	LD A,$2A 
	JP Lb47AB ; [18347]
Lb478F:
	CALL Lb482A ; [18474]
	LD A,$21 
	JR Lb47AB ; [$47AB:18347]
Lb4796:
	CALL Lb440D ; [17421]
	POP HL 
	LD BC,(RAM_SPARE2) ; GET UNUSED-16
	RET ; ==========================

Lb479F:
	LD HL,$0A2A 
	JR Lb47A9 ; [$47A9:18345]
Lb47A4:
	LD HL, Lb4956 
	JR Lb47A9 ; [$47A9:18345]
Lb47A9:
	LD A,$CD 
Lb47AB:
	CALL Lb497B ; [18811]
Lb47AE:
	LD A,L 
	CALL Lb497B ; [18811]
	LD A,H 
	JP Lb497B ; [18811]
Lb47B6:
	CALL Lb4737 ; [18231]
	CALL Lb47C1 ; [18369]
	LD HL,$73EB 
	JR Lb47AE ; [$47AE:18350]
Lb47C1:
	CP $1A ; [26-","]
	JP NZ, Lb44C1 ; [17601]
	RET ; ==========================

Lb47C7:
	CALL Lb4544 ; [17732]
	CALL Lb45F1 ; [17905]
	PUSH HL 
	PUSH HL 
	CALL Lb4544 ; [17732]
	CALL Lb4737 ; [18231]
	LD A,$23 
	CALL Lb497B ; [18811]
	LD HL,$53ED 
	CALL Lb47AE ; [18350]
	POP HL 
	CALL Lb47AE ; [18350]
	LD A,$22 
	INC HL 
	INC HL 
	CALL Lb47AB ; [18347]
	POP HL 
	LD DE,(RAM_SPARE2) ; GET UNUSED-16
	CALL Lb4509 ; [17673]
	RET ; ==========================

Lb47F4:
	CALL Lb4544 ; [17732]
	CALL Lb45F1 ; [17905]
	PUSH HL 
	PUSH HL 
	LD A,$2A 
	CALL Lb47AB ; [18347]
	LD HL,$2223 
	CALL Lb47AE ; [18350]
	POP HL 
	CALL Lb47AE ; [18350]
	INC HL 
	INC HL 
	LD A,$ED 
	CALL Lb497B ; [18811]
	LD A,$5B 
	CALL Lb47AB ; [18347]
	LD A,$A7 
	LD HL,$52ED 
	CALL Lb47AB ; [18347]
	LD A,$FA 
	POP HL 
	CALL Lb450E ; [17678]
	EX DE,HL 
	CALL Lb47AB ; [18347]
	RET ; ==========================

Lb482A:
	LD HL,$0000 
	JR Lb483E ; [$483E:18494]
Lb482F:
	CALL Lb4544 ; [17732]
	CP $7E ; [126]
	JR Z, Lb4850 ; [$4850:18512]
	PUSH AF 
	LD DE,$000A 
	CALL Lb4962 ; [18786]
	POP AF 
Lb483E:
	CP $26 ; [38-"A"]
	JP NC, Lb44C1 ; [17601]
	CP $1C ; [28-"0"]
	JP C, Lb44C1 ; [17601]
	SUB $1C 
	LD B,$00 
	LD C,A 
	ADD HL,BC 
	JR Lb482F ; [$482F:18479]
Lb4850:
	PUSH HL 
	LD HL,(RAM_CH_ADD) ; GET CH-ADD
	LD DE,$0005 
	ADD HL,DE 
	LD (RAM_CH_ADD),HL ; SET CH-ADD
	POP HL 
	RET ; ==========================

Lb485D:
	LD HL, Lb4975 
	CALL Lb47A9 ; [18345]
	CALL Lb4544 ; [17732]
	CALL Lb45F1 ; [17905]
	JP Lb4638 ; [17976]
Lb486C:
	LD A,$9B 
Lb486E:
	PUSH AF 
	CALL Lb4737 ; [18231]
	CALL Lb47C1 ; [18369]
	LD HL, Lb454A+1 
	CALL Lb47AE ; [18350]
	LD A,$3E 
	CALL Lb497B ; [18811]
	POP AF 
	CALL Lb497B ; [18811]
	LD A,$32 
	LD HL,$4030 
	CALL Lb47AB ; [18347]
	LD HL, Lb4965 
	JP Lb47A9 ; [18345]
Lb4892:
	LD A,$A0 
	JR Lb486E ; [$486E:18542]
Lb4896:
	LD A,$2A 
	LD HL,$4034 
	CALL Lb47AB ; [18347]
	LD A,$22 
	LD HL,$4032 
	JP Lb47AB ; [18347]
Lb48A6:
	CP $DD ; [221]
	JR Z, Lb48BC ; [$48BC:18620]
	CP $14 ; [20-"="]
	JR Z, Lb48C2 ; [$48C2:18626]
	RRA 
	JR NC, Lb48B2 ; [$48B2:18610]
	EX DE,HL 
Lb48B2:
	RLA 
	AND A 
	SBC HL,DE 
	SCF 
	RET M 
	RLA 
	RET NC 
	JR Lb48C4 ; [$48C4:18628]
Lb48BC:
	SBC HL,DE 
	SCF 
	RET NZ 
	JR Lb48C6 ; [$48C6:18630]
Lb48C2:
	SBC HL,DE 
Lb48C4:
	SCF 
	RET Z 
Lb48C6:
	CCF 
	RET ; ==========================

Lb48C8:
	CALL Lb4737 ; [18231]
	LD H,A 
	LD L,$3E 
	CALL Lb47AE ; [18350]
	LD HL, Lb48A6 
	CALL Lb47A9 ; [18345]
	LD HL,(RAM_E_PPC) ; GET E-PPC
	INC HL 
	CALL Lb4513 ; [17683]
	EX DE,HL 
	CALL Lb450E ; [17678]
	EX DE,HL 
	LD A,$D2 
	CALL Lb47AB ; [18347]
	CALL Lb4544 ; [17732]
	CP $DE ; [222]
	JP NZ, Lb44C1 ; [17601]
	RET ; ==========================

Lb48F1:
	LD HL, Lb48F7 
	JP Lb47A9 ; [18345]
Lb48F7:
	CALL SET_FAST ; [SET-FAST]
	LD HL,$403B 
	RES 6,(HL) 
	RET ; ==========================

Lb4900:
	LD HL, Lb4906 
	JP Lb47A9 ; [18345]
Lb4906:
	LD HL,$403B 
	SET 6,(HL) 
	JP SLOW_FAST ; [SLOW/FAST]
Lb490E:
	LD C,(HL) 
	INC HL 
	LD B,(HL) 
	ADD HL,BC 
	INC HL 
	LD A,(RAM_D_FILE) ; GET D-FILE
	SBC A,L 
	RET NZ 
	LD A,(RAM_D_FILE+1) ; GET D-FILE
	SBC A,H 
	RET ; ==========================

Lb491D:
	CALL Lb4544 ; [17732]
	CP $3F ; [63-"Z"]
	JP NZ, Lb44C1 ; [17601]
	CALL Lb474D ; [18253]
	XOR A 
	RET ; ==========================

Lb492A:
	CALL Lb474D ; [18253]
	LD HL,$4BED 
	CALL Lb47AE ; [18350]
	LD HL,$401C 
	CALL Lb47AE ; [18350]
	LD HL,$0929 
	JP Lb47AE ; [18350]
Lb493F:
	CALL Lb492A ; [18730]
	LD A,$D5 
	CALL Lb497B ; [18811]
	LD HL, Lb450E 
	CALL Lb47A9 ; [18345]
	LD HL,$D1EB 
	JP Lb47AE ; [18350]
Lb4953:
	JP Lb4088 ; [16520]
Lb4956:
	JP Lb408B ; [16523]
Lb4959:
	JP Lb408E ; [16526]
Lb495C:
	JP Lb4091 ; [16529]
Lb495F:
	JP Lb4094 ; [16532]
Lb4962:
	JP Lb4097 ; [16535]
Lb4965:
	JP Lb409A ; [16538]
Lb4968:
	JP Lb409D ; [16541]
Lb496B:
	JP Lb40A0 ; [16544]

Lb496E:
.db $EB; DATA
	JP Lb40A3 ; [16547]
Lb4972:
	JP Lb40A6 ; [16550]
Lb4975:
	JP Lb40A9 ; [16553]
Lb4978:
	JP Lb40AC ; [16556]
Lb497B:
	JP Lb40AF ; [16559]

.db $AF; DATA
.end
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
David G
Posts: 387
Joined: Thu Jul 17, 2014 7:58 am
Location: 21 North, 156 West

Re: [ZX81 Type-in] ZX-81 GT COMPILER

Post by David G »

Differences between ZXGT (type-in) and MCODER are six bytes, in addition to MCODER having several lines of BASIC

Here are the six differences in the machine code of REM 0


First is the PRINT statement compilation routine
  • POKE 17780,24 address $4574,$18 (replacing $1B/27) PRINT statement QUOTE handling
  • POKE 17782,123 address $4576,$7B (replacing $78/120) PRINT statement CALL
without these two changes, ZXGT won't compile this example:

Code: Select all

  10 PRINT "HELLO WORLD"
  20 STOP

Next is the USR statement compilation. ZXGT has these reversed:
  • POKE 18161,68
  • POKE 18162,77
Nonetheless, either way fails. MCODER won't compile this program:

Code: Select all

  10 LET L=USR [address of M/C]
  20 STOP
ZXGT will compile it (if you DO NOT perform the POKEs), but when running the compiled program it will hang or reboot


The AA/AB byte mentioned by Xav above
  • POKE 18596,171
This allows the following to compile:

Code: Select all

  10 RAND
  20 STOP
Curiously, 10 RAND 0 does not compile. Any argument after RAND causes a compiler syntax error. The MCODER instructions don't say anything about this. But this is valid according to the ZX81 BASIC PROGRAMMING manual Chapter 5 - Functions. I suspect this is why the ZXGT type-in article says "don't use RAND USR 17389" -- which, although it works fine to invoke the compiler (when typed from the command line), when used in a program the compiler will choke on it


Finally the sixth byte difference:
  • 18815 is 64/40h in ZXGT, but in MCODER it is NEWLINE (end of the REM)
This is not fixed by a simple poke, however i see two methods to fix it:
1) change the REM you type in to use one less character. AND change the HEX digits (Figure 5) to delete the last byte, and modify the LOADER last line and checksum/CRC to match
or
2) by modifying the m/c that refers to the affected length. This is the REM creation routine that creates REM2. It is hard-coded to last character of REM0 Since ZXGT is one byte longer, increase this by one

Code: Select all

POKE 17248,129
change $4360 from $80/128 to $81/129


I was a bit surprised the magazine article type-in had these flaws, because it simply does not work when typed in, and it is more than simple typos. The article is well written by Threlfall, and the compiler is genius. The loader is good, but somehow it still failed. I guess QA was not perfected in 1983
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: [ZX81 Type-in] ZX-81 GT COMPILER

Post by XavSnap »

Thanks David.
8-)
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
David G
Posts: 387
Joined: Thu Jul 17, 2014 7:58 am
Location: 21 North, 156 West

Re: [ZX81 Type-in] ZX-81 GT COMPILER

Post by David G »

OK finally here is the type-in along with the six POKEs to patch it

ZXGT_PATCHER.p
(3.52 KiB) Downloaded 71 times

First it POKEs the six patches in
Then it prints out the ZX81 character set

RUN and it take the normal amount of time

Compile it with RAND USR 17389. When it shows the '?' cursor, hold down the any key
Lastly, execute it with RAND USR 18823 -- and see it fly!
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: [ZX81 Type-in] ZX-81 GT COMPILER

Post by XavSnap »

French article:
Ordi-5_07_43[1].png
Ordi-5_07_44[1].png
Mcoder.pdf
(1.17 MiB) Downloaded 80 times
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: [ZX81 Type-in] ZX-81 GT COMPILER

Post by XavSnap »

MCODER manual reversion: (from the Moggy's original one)
Mcoder_livret-2.jpg
Mcoder_livret-1.jpg
Mcoder_livret.pdf
(78.97 KiB) Downloaded 84 times
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
Moggy
Posts: 3231
Joined: Wed Jun 18, 2008 2:00 pm

Re: [ZX81 Type-in] ZX-81 GT COMPILER

Post by Moggy »

Excellent work guys. :geek:

I have Mcoder and Mcoder2 so it's nice to have the type in to complete the trio. :D
For the print routine I suspect it's actually using the ROM code at RST address 16 (10H) judging by the speed and manner of its effect rather than a dedicated compiled print routine of it's own which would require a lot of housekeeping re valid screen positions etc which the ROM routine handles by itself.

Flawed magazine articles should come as a shock as they were quite common along with books that fell into the same trap.
The late Tim Hartnell's books were littered with errors as was Tony Bakers esteemed book on the ZX80/81 which had the same errors,incorrect ROM addresses duff maths routines etc, throughout three revisions so no surprises there then.

I remember an article written by maths guru Frank O'Hara in one magazine recalling how he did in just over three hours with a ZX81what a Cray Mk1 took three months to do in the 70's ( big primes) and the article stated that included in the listing is the code he used, except it bloody wasn't and no errata corrections in later magazine editions which given that the article was something to do with actual computing, and was above most readers heads, as opposed to yet another pac man clone came as no surprise.

Again great work many thanks.
David G
Posts: 387
Joined: Thu Jul 17, 2014 7:58 am
Location: 21 North, 156 West

Re: [ZX81 Type-in] ZX-81 GT COMPILER

Post by David G »

Surprisingly ZXGT does not appear to use the ROM routine for printing. It uses CH_ADD to keep track of the position


Now is a good time to type out the directions for use. A tiny bit of this is covered by the type-in article, but it's missing a lot of important info like the S cursor and so on

Since ZXGT and MCODER are exactly the same byte-for-byte, these instructions apply except for the "alternative" part which is provided with MCODER in a another REM

From the livret (cassette instructions)
MCODER
ZX81

(C) P.S.S. 1983

452, Stoney Stanton Road.
Coventry
CV6 5DG

Telephone: (0203) 667556


Why Use MCODER?
The simple answer to this question is that machine code programs run much faster than those written in BASIC. In general an improvement of about 50 times can be expected although in some instances the improvement may be up to 900 times faster than in BASIC.


How Do I Compile Programs Using MCODER?
MCODER must always be present in the machine before you enter anything. It is loaded from tape using LOAD "". MCODER uses the lines numbered 1 to 4 and so you should not have BASIC statements which use these line numbers. Although line 3 only appears to contain TAN do not delete it as it is included in case you try to run a program you have not compiled (TAN has the same code as RETURN).

You may now type in your BASIC program. Once entered it is essential that you check and de-bug it as normal. Once you are satisfied that the program works properly you should activate the compiler which is done by the direct command LET L = USR 17389. Pressing any key causes the commands to scroll up the screen.

The actual compilation is fast and takes place in three passes or views of the BASIC code. At the end of the second pass an inverse ? will be displayed and there will be a pause until you press another key. Keep O key depressed and the screen scrolling until 0/0 appears in the bottom corner. This is the end of the process and your program is now in machine code.

An alternative way to use MCODER is to load in a Basic program from cassette and then compile it. This can be done by the following procedure:
1) Load MCODER. [and RUN it]
2) Load the program you wish to compile.
3) When loaded use the direct command
LET L = USR 32577.
4) Ensure that the computer is in slow mode and enter LET L = USR 17389 as a direct command. You may now use MCODER as normal but remember that you will probably have to make some changes to your program before it will compile properly.


What Commands Will MCODER Accept?
Presented below is a list of the commands on which MCODER works along with a brief explanation on how they are to be used.

ABS: SEE LET

CHR$: SEE PRINT

DIM Z(V): Only one array is available in MCODER and this should always be Z.

CLS: AS NORMAL

COPY: Use USR 2153

FAST: AS NORMAL

FOR - NEXT: As normal except that the increment value is always 1.

GOSUB: Calls line given as a subroutine.

GOTO: Jumps unconditionally to line number given.

IF - THEN: The condition can be any of <>, =, = <> =, < or >. The command following THEN can be any other MCODER statement.

INKEY$: SEE LET

INT: SEE LET

LET: The arithmetic permitted by LET is restricted to the four standard operations (/*+-) plus certain other functions: -
PEEK V returns the contents of location V
USR V
RND gives the value of a random number between 0 and 32767. Note this is not the same as Sinclair.

CODE INKEY$ returns the value of the key pressed. Break stops the program

ABS V

INT V

NEW: Use USR 0 if you wish to clear the whole machine including above RAMTOP. Use USR 963 to clear the machine up to the RAMTOP as is done by the normal Sinclair NEW command.

PAUSE V: This causes the program to stop for V/50 seconds. There is no flicker as in Sinclair BASIC. V must always be less than 32768 and pressing any key except break during PAUSE causes the next statement to be executed. Pressing BREAK returns the computer to BASIC.

PEEK V: SEE LET

PLOT U,V: Turns on the pixel at screen location x U, y V.

POKE U,V: Location U is filled with the value V.

PRINT: The following format may be used with MCODER,
PRINT AT
PRINT "string"
PRINT any variable
PRINT CHR$
Notice that these may be intermixed for example PRINT AT 6,10;"A=",A

RAND: Seed the random number generator.

REM: Ignored as usual.

RETURN: Returns from a subroutine started by a GOSUB.

RND: SEE LET

SCROLL: Scrolls the screen up one line, this is very smooth compared with the Sinclair command.

SLOW: AS NORMAL

STOP: This must always be the last statement in a MCODER program and there can only be one STOP per program. If you wish to use stop command within your program as well as at the end then use LET L = USR 3292 which will give error code 9.

UNPLOT U,V: Turns off the pixel at U,V.

USR V: SEE LET


What Errors Can Occur?
If you have properly de-bugged your program in BASIC then there are only a few errors which can occur. These are identified by an inverse S at or near the offending character. Should this happen you will be put back into BASIC and you can make the correction and restart the compiler. Possible errors include:
1) Failure to use STOP as the last statement,
2) Using illegal variable names (only single letters are allowed).
3) Use of inkey$ with anything other than CODE.
4) Illegal statement.
5) Attempting to use Z for anything other than an array.
6) Attempting to do arithmetic in any statement except LET without using parenthesis.
7) Integer number containing either "." or E.

Notice that before recompiling a corrected program you should edit out line 2. Failure to do this could cause the program to crash. Do not worry if line 2 does not appear to be affected, this is normal, the line you have actually edited is invisible.


How Do I Run Compiled Program?
Once you have successfully compiled the BASIC code it should be treated as a machine code subroutine and called using the command LET L =USE 18823. If you wish to add a section of compiled code to BASIC code remember than MCODER keeps it's own variable table (not the same as Sinclair's) and you may PEEK or POKE to this as required. Variable A is at 18825, B at 18829, C at 18823 etc.


Improved Scrolling Using MCODER
Under Sinclair BASIC each new print starts on a new line and when the output reaches the bottom of the screen an error 5 is reported. Under MCODER an inverse ? will appear and pressing CONT causes a CLS to be executed and the program continues (keeping CONT continually depressed causes this to auto repeat). Pressing BREAK/SPACE stops the program, key D causes the screen to scroll at a maximum of 2 lines per second, pressing Z causes a hard copy to be produced onto the ZX printer. Pressing any other key causes the screen to scroll smoothly upwards whilst a key is depressed. The choice of mode may be varied each time a ? is displayed.


As an Example of MCODERS Speed
Enter the following program and compile it.
10 FOR A = 1 TO 50
20 FOR B = 1 TO 30
25 PLOT A,B
30 NEXT B
40 NEXT A
50 STOP

Once it has been compiled compare the speed of the compiled code with the basic program (using run) and you will see why MCODER is so useful.
Post Reply