	TITLE	'MACHINE LANGUAGE FUNCTIONS FOR 1802 CROSS-ASSEMBLER V. 2.3'
	PAGE	60
;
;	1802 CROSS-ASSEMBLER  V. 2.3
;
;	MAY, 1980
;
;	JUNE, 1980 -- REV. 2.1 CONSISTING OF FIXING P ERRORS THAT COME
;		FROM EQUING THINGS TO THE PRE-DEFINED SYMBOLS, AND ADDING
;		THE LOAD PSEUDO-OP.
;
;	JULY, 1980 -- REV. 2.2 CONSISTING OF FIXING THE M ERRORS THAT
;		COME FROM FORWARD REFERENCES IN WORD AND BYTE PSEUDO-OPS.
;
;	OCTOBER, 1980 -- REV. 2.3 CONSISTING OF MODIFYING THE ASSEMBLY
;		LANGUAGE ROUTINES AND I/O ROUTINES TO MATCH AND TAKE
;		ADVANTAGE OF BDS C V1.4.
;
;	COPYRIGHT (C) 1980 WILLIAM C. COLLEY, III.
;
;FILE:	A18TBLS.ASM
;
;MACHINE LANGUAGE FUNCTIONS.
;
	MACLIB	CMAC
;
;HERE I BUILD THE DIRECTORY TO THE FUNCTIONS IN THIS CRL FILE:
;
	DIRECT
	DEFINE	GETOPC		;FIRST ENTRY.
	DEFINE	NUMOPCS		;SECOND ENTRY.
	DEFINE	GETATTR		;THIRD ENTRY.
	DEFINE	GETOPR		;FOURTH ENTRY.
	DEFINE	NUMOPRS		;FIFTH ENTRY.
	ENDDIR
;
;ARGUEMENTS ARE PASSED VIA OFFSETS FROM THE STACK POINTER.
;THEY ARE DEFINED AS FOLLOWS:
;
ARG0	EQU	2		;FIRST ARGUEMENT.
ARG1	EQU	4		;SECOND ARGUEMENT.
ARG2	EQU	6		;THIRD ARGUEMENT.
ARG3	EQU	8		;FOURTH ARGUEMENT.
;
	PAGE
;
;THIS FUNCTION GETS OPCODE NUMBER NUM FROM THE OPCODE TABLE.  THE FUNCTION
;RETURNS 0 IF THE OPCODE WAS NOT FOUND, 1 IF IT WAS.
;
;FUNCTION IS CALLED AS FOLLOWS:
;
;	GETOPC(NUM,OPCODE,VALUE,ATTRIB);
;
;	NUM	CHARACTER CONTAINING THE NUMBER OF THE DESIRED ENTRY.
;			0 REPRESENTS THE FIRST ENTRY IN THE TABLE.  THE
;			TABLE IS IN ALPHABETICAL ORDER FOR THE BENEFIT
;			OF THE BINARY SEARCHING ROUTINE (WRITTEN IN C).
;	OPCODE	POINTER TO A 5-CHARACTER ARRAY WHICH WILL RECEIVE THE
;			OPCODE'S NAME (NULL TERMINATED).
;	VALUE	POINTER TO A CHARACTER THAT WILL RECEIVE THE OPCODE'S
;			VALUE.
;	ATTRIB	POINTER TO A CHARACTER THAT WILL RECEIVE THE OPCODE'S
;			ATTIBUTE BYTE.
;
NUM	EQU	ARG0
OPCODE	EQU	ARG1
VALUE	EQU	ARG2
ATTRIB	EQU	ARG3
;
	PRELUDE	GETOPC
;
	LXI	H, NUM		;GET ENTRY NUMBER.
	DAD	SP
	MOV	A,M
	CPI	OPTBLL		;ENTRY IN TABLE?
	LXI	H, 0		;IF NOT, RETURN 0.
	RNC
;
	MOV	L,A		;FIND ENTRY BY COMPUTING
	DAD	H		;(6 * NUM) + TABLE BASE.
	MOV	E,L
	MOV	D,H
	DAD	H
	DAD	D
	RELOC	<LXI D,>,OPCTBL
	DAD	D
	MOV	E,L
	MOV	D,H
;
	LXI	H, OPCODE	;FIND OPCODE RETURN AREA.
	DAD	SP
	MOV	A,M
	INX	H
	MOV	H,M
	MOV	L,A
;
	PUSH	B		;MOVE OPCODE OUT TO RETURN AREA.
	MVI	C, 4
MOVOPC:	LDAX	D
	INX	D
	MOV	M,A
	INX	H
	DCR	C
	RELOC	JNZ,MOVOPC
	POP	B
;
	MVI	M, 0		;TERMINATE OPCODE.
;
	LXI	H, ATTRIB	;FIND ATTRIBUTE BYTE RETURN AREA.
	DAD	SP
	MOV	A,M
	INX	H
	MOV	H,M
	MOV	L,A
;
	LDAX	D		;MOVE ATTRIBUTE BYTE TO RETURN AREA.
	INX	D
	MOV	M,A
;
	LXI	H, VALUE	;FIND VALUE BYTE RETURN AREA.
	DAD	SP
	MOV	A,M
	INX	H
	MOV	H,M
	MOV	L,A
;
	LDAX	D		;MOVE VALUE BYTE TO RETURN AREA.
	MOV	M,A
;
	LXI	H, 1		;RETURN 1 FOR SUCCESSFUL GET.
	RET
;
;THE OPCODE TABLE ITSELF:
;
;	EACH ENTRY HAS A FOUR-BYTE NAME, A ONE-BYTE ATTRIBUTE,
;	AND A ONE-BYTE VALUE.  THE VALUE IS THE LOWEST
;	NUMBERED OPCODE HAVING THAT NAME.
;
;	THE ATTRIBUTE BYTE BITS ARE ALLOCATED AS FOLLOWS:
;
;		7 = PSEUDO-OP.
;		6 = IF PSEUDO-OP, IF GROUP (NO LABEL ALLOWED).
;		5 = UNUSED.
;		2-4 = PROCESSOR NUMBER (0 IF PSEUDO-OP).
;		0,1 = NUMBER OF BYTES (0 IF PSEUDO-OP).
;
OPCTBL:	DB	'ADC', 0,	01H,	74H
	DB	'ADCI',		0AH,	7CH
	DB	'ADD', 0,	01H,	0F4H
	DB	'ADI', 0,	0AH,	0FCH
	DB	'AND', 0,	01H,	0F2H
	DB	'ANI', 0,	0AH,	0FAH
	DB	'B1', 0, 0,	0EH,	34H
	DB	'B2', 0, 0,	0EH,	35H
	DB	'B3', 0, 0,	0EH,	36H
	DB	'B4', 0, 0,	0EH,	37H
	DB	'BDF', 0,	0EH,	33H
	DB	'BGE', 0,	0EH,	33H
	DB	'BL', 0, 0,	0EH,	3BH
	DB	'BLK', 0,	80H,	05H
	DB	'BM', 0, 0,	0EH,	3BH
	DB	'BN1', 0,	0EH,	3CH
	DB	'BN2', 0,	0EH,	3DH
	DB	'BN3', 0,	0EH,	3EH
	DB	'BN4', 0,	0EH,	3FH
	DB	'BNF', 0,	0EH,	3BH
	DB	'BNQ', 0,	0EH,	39H
	DB	'BNZ', 0,	0EH,	3AH
	DB	'BPZ', 0,	0EH,	33H
	DB	'BQ', 0, 0,	0EH,	31H
	DB	'BR', 0, 0,	0EH,	30H
	DB	'BYTE',		80H,	02H
	DB	'BZ', 0, 0,	0EH,	32H
	DB	'DEC', 0,	05H,	20H
	DB	'DIS', 0,	01H,	71H
	DB	'ELSE',		0C0H,	07H
	DB	'END', 0,	80H,	06H
	DB	'ENDI', 	0C0H,	08H
	DB	'EQU', 0,	80H,	01PR(NUM,OPRATR,BS,TOKEN);
;
;	NUM	CHARACTER CONTAINING THE NUMBER OF THE DESIRED ENTRY.
;			0 REPRESENTS THE FIRST ENTRY IN THE TABLE.  THE
;			TABLE IS IN ALPHABETICAL ORDER FOR THE BENEFIT
;			OF THE BINARY SEARCHING ROUTINE (WRITTEN IN C).
;	OPRATR	POINTER TO A 5-CHARACTER ARRAY WHICH WILL RECEIVE THE
;			OPERATOR'S NAME (NULL TERMINATED).
;	BS	A DUD ARGUMENT TO MAINTAIN COMPATIBILITY WITH GETOPC.
;	TOKEN	A POINTER TO A CHARACTER THAT WILL RECEIVE THE OPERATOR'S
;			TOKEN BYTE.
;
OPRATR	EQU	ARG1
TOKEN	EQU	ARG3
;
	PRELUDE	GETOPR
;
	LXI	H, NUM		;GET ENTRY NUMBER.
	DAD	SP
	MOV	A,M
	CPI	OPRTLL		;ENTRY IN TABLE?
	LXI	H, 0		;IF NOT, RETURN 0.
	RNC
;
	MOV	L,A		;FIND ENTRY BY COMPUTING
	ADD	A		;(5 * NUM) + TABLE BASE.
	ADD	A
	ADD	L
	MOV	L,A
	RELOC	<LXI D,>,OPRTBL
	DAD	D
	MOV	E,L
	MOV	D,H
;
	LXI	H, OPRATR	;FIND OPERATOR RETURN AREA.
	DAD	SP
	MOV	A,M
	INX	H
	MOV	H,M
	MOV	L,A
;
	PUSH	B		;MOVE OPERATOR NAME TO RETURN AREA.
	MVI	C, 4		;MOVE OPERATOR NAME TO RETURN AREA.
MOVOPR:	LDAX	D
	INX	D
	MOV	M,A
	INX	H
	DCR	C
	RELOC	JNZ,MOVOPR
	POP	B
;
	MVI	M, 0		;TERMINATE OPERATOR NAME.
;
	LXI	H, TOKEN	;FIND TOKEN RETURN AREA.
	DAD	SP
	MOV	A,M
	INX	H
	MOV	H,M
	MOV	L,A
;
	LDAX	D		;MOVE TOKEN TO RETURN AREA.
	MOV	M,A
;
	LXI	H, 1		;RETURN 1 FOR SUCCESSFUL GET.
	RET
;
;THE OPERATOR TABLE ITSELF:
;
;	THE OPERATOR TOKENS ARE AS FOLLOWS:
;
GETKN	EQU	1
NETKN	EQU	2
LETKN	EQU	3
ANDTKN	EQU	4
ORTKN	EQU	5
XORTKN	EQU	6
NOTTKN	EQU	7
MODTKN	EQU	8
SHLTKN	EQU	9
SHRTKN	EQU	10
HITKN	EQU	11
LOWTKN	EQU	12
GTTKN	EQU	'>'
EQTKN	EQU	'='
LTTKN	EQU	'<'
;
OPRTBL:	DB	'AND', 0,	ANDTKN
	DB	'EQ', 0, 0,	EQTKN
	DB	'GE', 0, 0,	GETKN
	DB	'GT', 0, 0,	GTTKN
	DB	'HIGH',		HITKN
	DB	'LE', 0, 0,	LETKN
	DB	'LOW', 0,	LOWTKN
	DB	'LT', 0, 0,	LTTKN
	DB	'MOD', 0,	MODTKN
	DB	'NE', 0, 0,	NETKN
	DB	'NOT', 0,	NOTTKN
	DB	'OR', 0, 0,	ORTKN
	DB	'SHL', 0,	SHLTKN
	DB	'SHR', 0,	SHRTKN
	DB	'XOR', 0,	XORTKN
;
OPRTLL	EQU	($-OPRTBL)/5	;CALCULATE LENGTH OF TABLE.
;
	POSTLUDE GETOPR
;
	PAGE
;