;***********************************************************
;
;THIS IS AN EXAMPLE PROGRAM FOR THE Z8 MICROPROCESSOR.
;IT IS TAKEN FROM AN ARTICLE BY STEVE CIARCIA ON
;PAGE 120 & 122 OF THE OCTOBER 1984 ISSUE OF BYTE MAGAZINE,
;AND AFTER ONLY FORMAT MODIFICATIONS FOR CROSS-32, IT IS
;PASSED ON AS AN EXAMPLE, FREE OF CHARGE, BY
;UNIVERSAL CROSS-ASSEMBLERS.

	HOF	"INT8"		;INTEL OUTPUT FORMAT
	CPU	"Z8.TBL"	;CPU TABLE

;THE ASSEMBLER WILL CHECK THAT ADRESSES FOR INSTRUCTIONS
;REQUIRING DOUBLE REGISTERS ARE EVEN, AND FLAG AN
;ASSEMBLY ERROR IF THEY ARE NOT.

;THE LOAD CONSTANT AUTOINCREMENT AND LOAD EXTERNAL DATA
;AUTOINCREMENT INSTRUCTIONS USE AN EXTRA 'R' TO SPECIFY
;THE DOUBLE REGISTER.  VALID EXAMPLES ARE:
;
	LDCI	@R5,@RR0
	LDCI	@RR0,@R5
;
	LDEI	@R8,@RR4
	LDEI	@RR4,@R8
;
;THE FOLLOWING IS A LIST OF Z8 REGISTER NAMES
;WITH THEIR CORRESPONDING ADRESSES.

SPL:	EQU	255		;STACK POINTER LOW
SPH:	EQU	254		;STACK POINTER HIGH
RP:	EQU	253		;REGISTER POINTER
FLAGS:	EQU	252		;PROGRAM CONTROL FLAGS
IMR:	EQU	251		;INTERRUPT MASK REGISTER
IRQ:	EQU	250		;INTERRUPT REQUEST REGISTER
IPR:	EQU	249		;INTERRUPT PRIORITY REGISTER
P01M:	EQU	248		;PORTS 0-1 MODE
P3M:	EQU	247		;PORT 3 MODE
P2M:	EQU	246		;PORT 2 MODE
PRE0:	EQU	245		;T0 PRESCALER LOAD
T0:	EQU	244		;TIMER/COUNTER 0 LOAD
PRE1:	EQU	243		;T1 PRESCALER LOAD
T1:	EQU	242		;TIMER/COUNTER 1 LOAD
TMR:	EQU	241		;TIMER MODE REGISTER
SIO:	EQU	240		;SERIAL I/O

R15:	EQU	239		;REGISTER
R14:	EQU	238		;REGISTER
R13:	EQU	237		;REGISTER
R12:	EQU	236		;REGISTER
R11:	EQU	235		;REGISTER
R10:	EQU	234		;REGISTER
R9:	EQU	233		;REGISTER
R8:	EQU	232		;REGISTER
R7:	EQU	231		;REGISTER
R6:	EQU	230		;REGISTER
R5:	EQU	229		;REGISTER
R4:	EQU	228		;REGISTER
R3:	EQU	227		;REGISTER
R2:	EQU	226		;REGISTER
R1:	EQU	225		;REGISTER
R0:	EQU	224		;REGISTER

P3:	EQU	003		;PORT 3
P2:	EQU	002		;PORT 2
P1:	EQU	001		;PORT 1
P0:	EQU	000		;PORT 0

;***********************************************************
;
; Z8 VERSION RANGE-FINDER ROUTINES
;
; DRIVE INIT LINE AND SET UP CLOCKS
;
	ORG	1500H
INIT:	EQU	$
	DI			;SHUT DOWN INTERRUPTS
	OR	IMR,#20H	;ENABLE IRQ 5 (TIMER 1)
	LD	02H,#02		;TURN ON INIT LINE
	OR	TMR,#0CH	;LOAD AND START TIMER 1
	EI			;ENABLE INTERRUPTS
	RET			;RETURN TO BASIC
;
;
; THIS IS THE INTERRUPT-DRIVEN RANGING ROUTINE
;
;
RANGE:	EQU	$
	INC	30H		;ADD 1 TO PERIOD COUNTER
	JR	NZ,ECHO		;IF NO WRAP, CHECK ECHO
	LD	30H,#0FFH	;SET COUNT TO %FF
	JR	DONE		;AND SHUT DOWN RANGE ROUTINE
ECHO:	EQU	$
	TM	02H,#01		;IS ECHO BIT ON?
	JR	Z,EXIT		;NO, LET ANOTHER PASS OCCUR
DONE:	EQU	$
	LD	31H,#0FFH	;TURN ON DONE FLAG
	AND	TMR,#0F3H	;TURN OFF T1 TIMER
	AND	IMR,#1FH	;DISABLE IRQ 5 INTERRUPT
	LD	02H,#0		;SHUT OFF INIT LINE
EXIT:	EQU	$
	IRET			;RETURN FROM INTERRUPT
;
;END OF MACHINE-LANGUAGE ROUTINES
;
ZZZZ:	EQU	$

	END
