
;TITLE: BUFFERED I/O SOFTWARE VERSION 2.01 12/2/84
;VER 2.01 FIX-RESET BUFFER FLAG ON SPACE COMPRESSION
;*************************************************
;
;       BUFFER PARAMETER TABLE
;
;BYTE   DESCRIPTION
; 0,1   DATA IN BUFFER ADDRESS POINTER
; 2,3   DATA OUT BUFFER ADDRESS POINTER
; 4     RESERVE CELL NUMBER
; 5     ETX,ETB/ACK DATA COUNTER
; 6     RESERVE CELL USED FLAG
; 7     BUFFER FULL FLAG
; 8     PROTOCAL FLAGS
; 9     DESPOOL FUNCTION FLAGS
; 10    DATA IN STACK POINTER
; 11    DATA OUT STACK POINTER
; 12,13 DATA COUNTER
; 14,15 HOLD BUFFER DATA COUNTER
; 16,17 HOLD BUFFER ADDRESS POINTER
; 18    HOLD BUFFER OUT STACK POINTER
; 19    PRESENT COMPRESSED SPACE ADDRESS
; 21-75 BUFFER CELL STACK
;
;       PROTOCAL FLAGS
;
;BIT    DESCRIPTION
; 0     PROTOCAL ACTIVE
; 1     WAIT FLAG
; 2     XON/XOFF ACTIVE
; 3     ETX/ACK ACTIVE
; 4     ETB/ACK ACTIVE
;5-7    NOT USED
;
;       DESPOOL FLAGS
;
;BIT    DESCRIPTION
; 0     SPACE COMPRESSION ACTIVE
; 1     HOLD BUFFER ACTIVE
; 2     PAGE PAUSE ACTIVE
; 3     NEXT PAGE FLAG
; 4     SPACE PRESENT FLAG
; 5     NO BUFFERING ACTIVE
;
;*********************************************
;
;       COMMAND SUMMARY
;
;----------------------------------------------
;BAUD RATE      SERIAL A        SERIAL B
;
;    110        00H             10H
;    300        01H             11H
;    600        02H             12HŠ;  1,200        03H             13H
;  2,400        04H             14H
;  4,800        05H             15H
;  9,600        06H             16H
; 19,200        07H             17H
;
;-----------------------------------------------
;
;COUNTER FUNCTIONS
;
; COUNTER PERIOD                20H
; LSB COUNT                     XXH
; MSB COUNT                     XXH
;
; START COUNT                   21H
;
; RESET COUNT                   22H
;
;-----------------------------------------------
;
;DESPOOL FUNCTIONS      SER A   SER B   PAR B
;
; BUFFER HOLD ON        40H     50H     60H
; BUFFER HOLD OFF       41H     51H     61H
; COPY BUFFER           42H     52H     62H
; CLEAR BUFFER          43H     53H     63H
;
; PAGE PAUSE ON         44H     54H     64H
; PAGE PAUSE OFF        45H     55H     65H
; IMMEDIATE PAUSE       46H     56H     66H
; NEXT PAGE             47H     57H     67H
;
; SPACE COMPRESSION ON  48H     58H     68H
; SPACE COMPRESSION OFF 49H     59H     69H
;
; BUFFERING OFF         4AH     5AH     6AH
; BUFFERING ON          4BH     5BH     6BH
;
;-----------------------------------------------
;
;PROTOCAL FUNCTIONS     SER A   SER B
;
; BREAK ON              80H     90H
; BREAK OFF             81H     91H
;
; XON/XOFF              82H     92H
; ETX/ACK               83H     93H
; ETB/ACK               84H     94H
; ALL PROTOCALS OFF     85H     95H
;
;-----------------------------------------------
;
;SOFTWARE RESET         FFH
;
;***********************************************Š;
START:
;
;       DEFINED PARAMETERS
;
;       S100 I/O PORTS
;
BUSST	EQU	40H		;S100 I/O PORT STATUS
BSA0	EQU	41H		;SERIAL A OUTPUT PORT 
BSB0	EQU	42H		;SERIAL B OUTPUT PORT
BPA0	EQU	43H		;PARRALLEL A OUTPUT PORT
BBUFST	EQU	44H		;BUFFER STATUS PORT
BINDTA	EQU	45H		;INPUT DATA PORT
BINADD	EQU	46H		;INPUT DATA ADDRESS PORT
;
;       BAUD GENERATOR / COUNTER
;
BAUD1	EQU	00H		;BAUD RATE A COUNT REGISTER
BAUD2	EQU	01H		;BAUD RATE B COUNT REGISTER
CTR	EQU	02H		;INTERRUPT COUNT REGISTER
CTMODE	EQU	03H		;BAUD / COUNTER MODE REGISTER
;
;       PARRALLEL I/O PORT 1 & 2
;
PADATA	EQU	10H		;PARRALLEL A DATA REGISTER
PBDATA	EQU	11H		;PARRALLEL B DATA REGISTER
PSTAT	EQU	12H		;PARRALLEL STATUS REGISTER
PCMD	EQU	13H		;COMMAND MODE REGISTER
;
;       SERIAL I/O PORT A
;
SADATA	EQU	20H		;SERIAL DATA REGISTER
SACMD	EQU	21H		;SERIAL COMMAND REGISTER
;
;       SERIAL I/O PORT B
;
SBDATA	EQU	30H		;SERIAL DATA REGISTER
SBCMD	EQU	31H		;SERIAL COMMAND REGISTER
;
;       ABSOLUTE ADDRESSES
;
STACK	EQU	START+0FA0H	;STACK POINTER
				;CELL PARAMETERS
PTRHSA	EQU	START+800H	;BUFFER TO SERIAL A
PTRSAH	EQU	PTRHSA+80	;BUFFER A TO HOST
PTRHSB	EQU	PTRSAH+80	;BUFFER TO SERIAL B
PTRSBH	EQU	PTRHSB+80	;BUFFER B TO HOST
PTRPAH	EQU	PTRSBH+80	;BUFFER PAR A TO HOST
PTRHPB	EQU	PTRPAH+80	;BUFFER TO PARALLEL B
				;
MEMMAP	EQU	PTRHPB+80	;MEMORY USE BIT MAP
CMDPTR	EQU	MEMMAP+80	;COMMAND VECTOR
TEMP	EQU	CMDPTR+2	;TEMPORARY STORAGE
INTTMP	EQU	TEMP+1		;TEMPORARY STORAGE
CTRD1	EQU	INTTMP+1	;COUNTER DATAŠCTRD2	EQU	CTRD1+1		;
BUFST	EQU	CTRD2+1		;BUFFER STATUS BYTE
				;
BSAOMK	EQU	01H		;HOST STATUS MASKS
BSBOMK	EQU	02H		;
BPAOMK	EQU	04H		;
				;
CTRSAH	EQU	PTRSAH+12	;CHARACTER COUNT LOCATIONS
CTRHSA	EQU	PTRHSA+12	;
CTRSBH	EQU	PTRSBH+12       ;
CTRHSB  EQU     PTRHSB+12       ;
CTRPAH  EQU     PTRPAH+12       ;
CTRHPB  EQU     PTRHPB+12       ;
				;
				;       CONSTANTS
				;
NULL    EQU     0		;NULL
ZERO    EQU     NULL
ETX     EQU     3
ETB     EQU     17H
ACK     EQU     6
XON     EQU     11H
XOFF    EQU     13H	
FFEED   EQU     0CH		;FORM FEED
MAXCNT  EQU     64		;MAX CHAR BUFFER FOR ETX/ETB
OFFSET  EQU     21		;CELL STACK OFFSET
MAPCNT  EQU     54		;NUMBER OF CELLS
ZCNT    EQU     237H		;ZERO RAM NUMBER AT INITALIZE
SEREN   EQU     37H		;SERIAL ENABLE
SERM16  EQU     4EH		;SERIAL CLOCK X16
B110    EQU     01047		;DIVIDER FOR 110 BAUD
B300    EQU     0384		;DIVIDER FOR 300 BAUD
B600    EQU     0192		;DIVIDER FOR 600 BAUD
B1200   EQU     096		;DIVIDER FOR 1200 BAUD
B2400   EQU     048		;DIVIDER FOR 2400 BAUD
B4800   EQU     024		;DIVIDER FOR 4800 BAUD
B9600   EQU     012		;DIVIDER FOR 9600 BAUD
B19200  EQU     06              ;DIVIDER FOR 19200 BAUD
				;
	ORG	00H		;BEGINING OF PROGRAM
	NOP			;FALSE STACK RETURN ADDRESS
	NOP			;
	LD	SP,STACK	;LOAD STACK POINTER
	OUT	(BBUFST),A	;CLEAR BUFFER STATUS
	IN	A,(BINDTA)	;CLEAR INPUT PORT
	LD	A,36H		;LOAD CTR MODE
	OUT	(CTMODE),A	;
	LD	A,76H		;
	OUT	(CTMODE),A	;
	LD	A,0B0H		;
	OUT	(CTMODE),A	;
	JR	PWRINT		;GO TO POWER UP INTIALIZATION
				;
	ORG	18H		;
				;Š	******************************************************************
	*		INPUT DATA / COMMAND INTERRUPT VECTOR		 *
	******************************************************************
				
	JP	CMD		;SERVICE COMMAND/INPUT DATA
				;
	ORG	28H		;
				;
	******************************************************************
	*		PARRALLEL A INTERRUPT VECTOR			 *
	******************************************************************
				
	JP	INTPAH		;SERVICE PARRALLEL A TO HOST
				;
	ORG	30H		;
				;
				;SERIAL B INTERRUPT VECTOR
				;
	JP	INTSBH		;SERVICE SERIAL B TO HOST
				;
	ORG	38H		;
				;
				;SERIAL A INTERRUPT VECTOR
				;
	JP	INTSAH		;SERVICE SERIAL A TO HOST
				;
				;INITIALIZE RAM SPACE
PWRINT:	LD	BC,ZCNT		;LOAD COUNT
	LD	HL,NULL		;POINT AT ZERO
	LD	DE,PTRHSA	;LOAD BOTTOM OF RAM
LOOP1:	LDI			;ZERO LOCATION IN DE
	JP	PO,LPEND	;IF BC ZERO END
	DEC	HL		;POINT BACK AT ZERO
	JR	LOOP1		;ZERO NEXT BYTE
				;
LPEND:	LD	DE,PTRHSA	;LOAD POINTER TOP
	LD	HL,PTRTBL	;LOAD POINTER DEFAULT TABLE
	LD	BC,5		;LOAD COUNT
	LDIR			;MOVE DATA
	LD	DE,PTRSAH	;LOAD POINTER TOP
	LD	BC,5		;LOAD COUNT
	LDIR			;MOVE DATA
	LD	DE,PTRHSB	;LOAD POINTER TOP
	LD	BC,5		;LOAD COUNT
	LDIR			;MOVE DATA
	LD	DE,PTRSBH	;LOAD POINTER TOP
	LD	BC,5		;LOAD COUNT
	LDIR			;MOVE DATA
	LD	DE,PTRPAH	;LOAD POINTER TOP
	LD	BC,5		;LOAD COUNT
	LDIR			;MOVE DATA
	LD	DE,PTRHPB	;LOAD POINTER TOP
	LD	BC,5		;LOAD COUNT
	LDIR			;MOVE DATA
	LD	DE,PTRHSA+OFFSET;PUT DEFAULT CELL NUMBERŠ	LDI			; IN STACK OF EACH PORT
	LD	DE,PTRSAH+OFFSET
	LDI	
	LD	DE,PTRHSB+OFFSET
	LDI
	LD	DE,PTRSBH+OFFSET
	LDI	
	LD	DE,PTRPAH+OFFSET
	LDI	
	LD	DE,PTRHPB+OFFSET
	LDI
				;
	LD	HL,COMDEC	;LOAD COMMAND POINTER
	LD	(CMDPTR),HL
				;
	LD	HL,MEMMAP+6	;POINT AT DEFAULT BITS
	LD	B,6		;LOAD COUNTER
MMLOOP:	LD	(HL),1		;SET THEM AS BUSY
	INC	HL
	DJNZ	MMLOOP
				;
				;       INITIALIZE THE HARDWARE
				;
	LD	A,(IOPAR+0)	;INITIALIZE BAUD RATE
	OUT	(BAUD1),A				
	LD	A,(IOPAR+1)
	OUT	(BAUD1),A
	LD	A,(IOPAR+2)
	OUT	(BAUD2),A
	LD	A,(IOPAR+3)
	OUT	(BAUD2),A
				;
	LD	A,SERM16	;SET UP SERIAL PORTS
	OUT	(SACMD),A
	OUT	(SBCMD),A
	LD	A,SEREN		;ENABLE TX,RX,RTS,DSR,INT
	OUT	(SACMD),A
	OUT	(SBCMD),A
				;
	LD	A,0B4H		;SET PARRELLEL PORT
	OUT	(PCMD),A
	LD	A,09H		;ENABLE INTERRUPT
	OUT	(PCMD),A	
	EI
				;
				;       STATUS OUTPUT ROUTINE
				;
STSOUT:	LD	HL,(CTRSAH)	;HOST TO SERIAL A COUNT
	LD	A,H		;IS COUNT ZERO?
	OR	L
	CALL	NZ,BUFTHA	;SEND CHARACTER
	LD	HL,(CTRHSA)	;SERIAL A TO HOST COUNT
	LD	A,H		;IS COUNT ZERO?
	OR	L
	CALL	NZ,BUFTSA	;SEND CHARACTERŠ	LD	HL,(CTRSBH)	;HOST TO SERIAL B COUNT
	LD	A,H		;IS COUNT ZERO?
	OR	L
	CALL	NZ,BUFTHB	;SEND CHARACTER
	LD	HL,(CTRHSB)	;SERIAL B TO HOST COUNT
	LD	A,H		;IS COUNT ZERO?
	OR	L
	CALL	NZ,BUFTSB	;SEND CHARACTER
	LD	HL,(CTRPAH)	;PARALLEL A TO HOST COUNT
	LD	A,H		;IS COUNT ZERO?
	OR	L
	CALL	NZ,BUFHPA	;SEND CHARACTER
	LD	HL,(CTRHPB)	;HOST TO PARALLEL B COUNT
	LD	A,H		;IS COUNT ZERO?
	OR	L
	CALL	NZ,BUFTPB	;SEND CHARACTER
				;
				;       BREAK SERVICE ROUTINE
				;
	IN	A,(SACMD)	;LOOK FOR BREAK IN SER A
	AND	40H
	DI
	LD	A,(BUFST)	;GET STATUS BYTE
	RES	7,A		;CLEAR BREAK BIT
	JR	Z,NBRKA
	SET	7,A		;SET BREAK BIT
NBRKA:	LD	(BUFST),A	;SAVE STATUS
	EI
	OUT	(BBUFST),A	;TELL HOST
				;
	IN	A,(SBCMD)	;LOOK FOR BREAK IN SER B
	AND	40H
	DI
	LD	A,(BUFST)	;GET STATUS BYTE
	RES	6,A		;CLEAR BREAK BIT
	JR	Z,NBRKB
	SET	6,A		;SET BREAK BIT
NBRKB:	LD	(BUFST),A	;SAVE STATUS
	EI
	OUT	(BBUFST),A	;TELL HOST
	JR	STSOUT
				;
				;       SER A BUFFER OUT TO SERIAL A
				;
BUFTSA:	LD	IX,PTRHSA	;LOAD CELL PARAMETER POINTER
	LD	C,SACMD		;LOAD PORT NUMBER IN C
	LD	B,1		;LOAD BUFFER STATUS MASK
	CALL	SERST		;GET STATUS OF PORT
	JR	NZ,BUFFRE	;PORT NOT READY
	CALL	GETDTA		;GET CHARACTER & RETURN IN A
	OUT	(SADATA),A	;SEND CHARACTER TO SERIAL A
	CALL	BUFFRE		;SET BUFFER STATUS
	BIT	0,(IX+8)	;DOES PORT USE PROTOCAL?
	CALL	NZ,EXPROT	;YES DO IT
	RETŠ				;
				;
				;       SER B BUFFER TO SERIAL B
				;
BUFTSB:	LD	IX,PTRHSB	;LOAD CELL PARAMETER POINTER
	LD	C,SBCMD		;LOAD PORT NUMBER IN C
	LD	B,2		;LOAD BUFFER STATUS MASK
	CALL	SERST		;GET STATUS OF PORT
	JR	NZ,BUFFRE	;PORT NOT READY
	CALL	GETDTA		;GET CHARACTER & RETURN IN A
	OUT	(SBDATA),A	;SEND CHARACTER TO SERIAL A
	CALL	BUFFRE		;SET BUFFER STATUS
	BIT	0,(IX+8)	;DOES PORT USE PROTOCAL?
	CALL	NZ,EXPROT	;YES DO IT
	RET
				;
				;       PAR B BUFFER TO PARALLEL B
				;
BUFTPB:	LD	B,4		;LOAD BUFFER STATUS MASK
	LD	IX,PTRHPB	;LOAD CELL PARAMETER POINTER
	IN	A,(PSTAT)	;GET STATUS
	AND	02H
	JR	Z,BUFFRE	;NOT READY
				;
	CALL	GETDTA		;GET CHARACTER
	OUT	(PBDATA),A	;SEND IT
	CALL	BUFFRE		;SET BUFFER STATUS
	RET
				;
				;       UPDATE BUFFER STATUS TO HOST
				;
BUFFRE:	BIT	0,(IX+7)	;CHECK FLAG
	RET	NZ		;ON DON'T CLEAR
	DI
	LD	A,(BUFST)	;GET STATUS BYTE
	CPL			;IS IT RESET?
	OR	B		;YES DO NOTHING
	CPL			;RESET BIT
	NOP
	OUT	(BBUFST),A	;TELL HOST
	LD	(BUFST),A	;SAVE IT
OVRFRE:	EI
	RET
				;
				;       SER A BUFFER TO HOST
				;
BUFTHA:	LD	IX,PTRSAH	;LOAD CELL PARAMETER POINTER
	LD	C,SACMD		;LOAD SERIAL PORT
	IN	A,(BUSST)	;CHECK STATUS
	AND	BSAOMK		;MASK IT
	RET	NZ
				;
	CALL	GETDTA		;GET NEXT CHARACTER
	OUT	(BSA0),A	;SEND IT TO HOST
	JR	BSTPCK		;CHECK BUFFER STATUS/PROTOCALŠ				;
				;       SER B BUFFER TO HOST
				;
BUFTHB:	LD	IX,PTRSBH	;LOAD CELL PARAMETER POINTER
	LD	C,SBCMD		;LOAD SERIAL PORT
	IN	A,(BUSST)	;CHECK STATUS
	AND	BSBOMK		;MASK IT
	RET	NZ
				;
	CALL	GETDTA		;GET NEXT CHARACTER
	OUT	(BSB0),A	;SEND IT TO HOST
				;
				;       BUFFER STATUS CHECK
				;
BSTPCK:	BIT	0,(IX+7)	;IF BUFFER FULL
	RET	NZ
	LD	A,SEREN		;TURN DSR ON
	OUT	(C),A
	BIT	1,(IX+8)	;IS WAIT BIT ON?
	RET	Z
	RES	1,(IX+8)	;RESET WAIT BIT
	BIT	2,(IX+8)	;PROTOCAL XON/XOFF?
	RET	Z
SST:	IN	A,(C)		;CHECK SERIAL PORT STATUS
	CP	4		;IS TX READY?
	JR	Z,SST
	LD	A,XON		;SEND XON
	DEC	C		;POINT AT PORT
	OUT	(C),A		;SEND IT
	RET
				;
				;       PAR A BUFFER TO HOST
				;
BUFHPA:	LD	IX,PTRPAH	;LOAD CELL PARAMETER POINTER

	IN	A,(BUSST)	;GET STATUS
	AND	BPAOMK		;MASK IT
	RET	NZ
				;
	CALL	GETDTA		;GET NEXT CHARACTER
	OUT	(BPA0),A	;SEND IT
	BIT	0,(IX+7)	;IS BUFFER FULL
	RET	NZ		;
	LD	A,9		;TURN PORT INTERRUPT ON
	OUT	(PCMD),A	;
	RET			;
				
				;       SERIAL PORT STATUS ROUTINE
				;
SERST:	BIT	1,(IX+8)	;TEST FLAG FOR WAIT
	RET	NZ		;NOT READY RETURN
	IN	A,(C)		;GET PORT STATUS
	AND	85H		;STRIP USED BITS
	CP	85H		;ALL THERE?
	RET
				;Š				;       ETX-ETB PROTOCALL ROUTINE
				;
EXPROT:	BIT	2,(IX+8)	;IF XON/XOFF DO NOTHING
	RET	NZ
	INC	(IX+5)		;INCREMENT COUNT
	LD	A,MAXCNT	;LOAD MAX COUNT
	CP	(IX+5)		;COMPARE WITH COUNT
	RET	NZ		;NOT MAX RETURN
				;
	LD	(IX+5),0	;ZERO COUNT
	BIT	3,(IX+8)	;IS PROTOCAL ETX
	JR	Z,ETBPRO
	LD	A,ETX		;PUT ETX IN A
	JR	SENDET
ETBPRO:	LD	A,ETB		;PUT ETB IN A
	PUSH	AF
SENDET:	INC	C		;POINT TO CMD PORT
UP3:	CALL	SERST		;GET STATUS
	JR	NZ,UP3		;WAIT TILL READY
	POP	AF
	DEC	C		;POINT TO PORT
	OUT	(C),A		;SEND IT
	SET	1,(IX+8)	;SET WAIT BIT
	RET
				;
				;       GET CHARACTER ROUTINE
				;
GETDTA:	BIT	3,(IX+9)	;CHECK PAGE HOLD FLAG
	JR	Z,OVRNOT
	POP	AF		;WAIT FOR NEW PAGE
	RET
				;
OVRNOT:	PUSH	BC		;SAVE PORTS
	LD	L,(IX+2)	;GET DATA POINTER
	LD	H,(IX+3)
	LD	A,(HL)		;GET CHARACTER
	LD	(TEMP),A	;TEMPORARY STORE IT
	BIT	5,(IX+9)	;IF NO BUFFERING
	JR	Z,OVRNBR
	RES	0,(IX+7)	;RESET BUFFER FLAG
	JP	GDWCNT
OVRNBR:	BIT	0,(IX+9)	;GET SPACE BLOCKING BYTE
	JR	Z,NOSP		;NO SPACE BLOCKING
				;
	BIT	7,A		;IS IT A MULTI-SPACE
	JR	Z,NOSP		;NOT A SPACE DO NOTHING
	CP	81H		;IS THIS LAST?
	JR	Z,SPIT		;NO SEND MORE
	DEC	A		;ONE LESS
	LD	(HL),A		;SAVE COUNT IN BUFFER
	LD	A,' '		;PUT SPACE IN TEMP
	LD	(TEMP),A
	JP	GETDON		;ALL DONE
				;
SPIT:	LD	A,' '		;PUT SPACE IN TEMPŠ	LD	(TEMP),A
				;
NOSP:	CP	FFEED		;CHECK FOR FORM FEED
	JR	NZ,OVRPG
	BIT	2,(IX+9)	;PAGE HOLD ON?
	JR	Z,OVRPG	
	SET	3,(IX+9)	;SET PAGE FLAG
				;
OVRPG:	PUSH	HL		;SAVE REGISTER
	LD	DE,-3FFH	;CHECK FOR END OF CELL
	LD	A,H		;STRIP OF HIGH ADDRESS
	AND	3
	LD	H,A		
	ADC	HL,DE
	POP	HL		;RESTORE DATA
	INC	HL		;INC ONE
	JR	NZ,OLDCEL	;DON'T NEED NEW CELL
				;
	PUSH	IX		;CALC STACK ADDRESS
	POP	HL
	LD	DE,OFFSET
	ADD	HL,DE		
	LD	E,(IX+11)	;GET STACK NUMBER
	ADD	HL,DE		;OFFSET ADDRESS
	LD	A,(HL)		;GET CELL NUMBER
	SBC	HL,DE		;GET BACK TO BASE
	LD	C,(IX+4)	;GET RESERVED CELL NUMBER
	CP	C		;IF SAME RESET RESERVE FLAG
	JR	NZ,OVRRES
				;
	BIT	1,(IX+9)	;IF HOLD ON DON'T RESET
	JR	NZ,HOLDON
	RES	0,(IX+6)	;RESET RESERVED CELL FLAG
				;
OVRRES:	BIT	1,(IX+9)	;IF HOLD DON'T RESET
	JR	NZ,HOLDON	
				;
OVRHLD:	PUSH	HL		;SAVE NUMBERS
	PUSH	DE
	LD	E,A		;MOVE CELL NUMBER TO E
	LD	HL,MEMMAP	;LOAD MEMORY MAP ADDRESS
	ADD	HL,DE		;ADD CELL NUMBER
	LD	(HL),0		;RESET BIT
				;
	BIT	0,(IX+7)	;IF FULL SKIP
	JR	Z,OVRCCK
	DI
	PUSH	IX		;GIVE PUTDTA A VECTOR
	POP	IY
	CALL	CELLCK		;GET NEW ADDRESS
	EI
OVRCCK:	POP	DE		;GET NUMBER
 	POP	HL	
				;
HOLDON:	INC	E		;ADVANCE STACK POINTERŠ	LD	A,MAPCNT+2	
	CP	E		;IF AT END WRAP
	JR	NZ,OVRCEL	
	LD	E,0		;START OVER
OVRCEL:	LD	(IX+11),E	;SAVE IT
	ADD	HL,DE		;ADD NEW OFFSET
	LD	A,(HL)		;GET CELL NUMBER
				;
MULTPY:	LD	HL,1000H	;GET READY TO MULTIPLY
	LD	DE,400H		;LOAD CELL SIZE
NXTA:	SRL	A		;SHIFT TO CARRY
	JR	NC,NOADD	;IF NO CARRY NO ADD
	ADD	HL,DE		;ADD
NOADD:	SLA	D		;MULT X2
	OR	A		;A ZERO?
	JR	NZ,NXTA
				;
OLDCEL:	LD	(IX+2),L	;SAVE NEW ADDRESS
	LD	(IX+3),H	
				;
GDWCNT:	XOR	A		;CLEAR A
	DI
	CP	(IX+12)		;IS LSB ZERO
	JR	NZ,OVRDEC	;NO DON'T BORROW
	DEC	(IX+13)		;DEC MSB
OVRDEC:	DEC	(IX+12)		;DEC COUNT
	EI
				;
GETDON:	POP	BC		;RESTORE PORTS
	LD	A,(TEMP)	;GET CHARACTER
	RET
				;
				;         INTERRUPT SERVICE ROUTINES
				;
				;         HOST COMMAND/DATA
				;
CMD:	PUSH	AF	
	PUSH	BC	
	PUSH	DE
	PUSH	HL
	IN	A,(BINADD)	;COMMAND OR DATA?
	AND	0FH		;STRIP NON USED BITS
	CP	2		;COMMAND BYTE?
	JR	Z,CMDBYT	;YES
	CP	4		;SERIAL A DATA?
	JP	Z,INTHSA	;YES
	CP	6		;SERIAL B DATA?
	JP	Z,INTHSB	;YES
	CP	8		;PARALLEL B DATA?
	JP	Z,INTHPB	
	JP	VECT1		;CHECK OTHER VECTORS
				;
				;         COMMAND BYTE VECTOR ROUTINE
				;
CMDBYT:	LD	HL,(CMDPTR)	;GET COMMAND VECTORŠ	JP	(HL)		;GO THERE
				;
				;         COMMAND DECODER
				;
COMDEC:	IN	A,(BINDTA)	;GET COMMAND
	LD	B,A		;SAVE IT
	AND	0F0H		;MADK LSB'S
	CP	0		;SET NEW BAUD A
	JR	Z,BAUDSA	;YES
	CP	10H		;SET NEW BAUD B
	JR	Z,BAUDSB	;YES
	CP	20H		;COUNTER FUNCTIONS
	JR	Z,CTRSET	;YES
	CP	40H		;DESPOOL FUNCTIONS
	JP	Z,DSPSA		;YES
	CP	50H		;YES
	JP	Z,DSPSB		;DESPOOL FUNCTIONS SER B
	CP	60H		;YES
	JP	Z,DSPPB		;DESPOOL FUNCTIONS PAR B
	CP	80H	
	JP	Z,PROSA		;PROTOCAL FUNCTIONS SER A
	CP	90H		
	JP	Z,PROSB		;PROTOCAL FUNCTIONS SER B
	CP	0F0H		;SOFTWARE RESET
	JP	NZ,VECT1	;CHECK OTHER VECTORS
	LD	A,40H		;RESET SERIAL PORTS
	OUT	(SACMD),A	
	OUT	(SBCMD),A
	JP	START		;START OVER
				;
				;         SET BAUD RATE ON SERIAL A
				;
BAUDSA:	LD	C,BAUD1		;LOAD PORT NUMBERS
	JR	BAUDLD		;LOAD BAUD	
				;
				;          SET BAUD RATE ON SERIAL B
				;
BAUDSB:	LD	C,BAUD2		;LOAD PORT NUMBERS
				;
BAUDLD:	LD	A,B		;GET DATA
	AND	7		;STRIP HIGH BITS
	SLA	A		;MULTIPLY TIMES 3
	LD	HL,BTABLE	;LOAD BAUD TABLE
	ADD	A,L		;ADD OFFSET
	LD	L,A		;RETURN OFFSET TO L
				;
	LD	A,(HL)		;LOAD COUNTER
	OUT	(C),A
	INC	HL
	LD	A,(HL)
	OUT	(C),A
				;
	JP	VECT1		;CHECK OTHER VECTORS
				;
				;         COUNTER FUNCTIONSŠ				;
CTRSET:	LD	A,B		;GET DATA
	AND	3		;MASK UNUSED BITS
	CP	0		
	JR	Z,SETPER	;SET PERIOD
	CP	1		
	JR	Z,GOCTR		;START COUNTER
	CP	2		
	JR	Z,STCTR;	;RESET COUNTER
	JP	VECT1		;CHECK OTHER VECTORS
				;
				;         SET COUNTER PERIOD
				;
SETPER:	LD	HL,CTRLD	;LOAD INT VECTOR
	LD	(CMDPTR),HL	;STORE IT
	JP	VECT1		;CHECK OTHER VECTORS
				;
CTRLD:	IN	A,(BINDTA)	;GET COUNT LSB
	LD	(CTRD1),A	;SAVE IT
	LD	HL,CTRLD1	;LOAD INT VECTOR
	LD	(CMDPTR),HL	;STORE IT
	JP	VECT1		;CHECK OTHER VECTORS
				;
CTRLD1:	IN	A,(BINDTA)	;GET COUNT LSB
	LD	(CTRD2),A	;SAVE IT
	LD	HL,COMDEC	;LOAD INT VECTOR
	LD	(CMDPTR),HL	;STORE IT
	JP	VECT1		;CHECK OTHER VECTORS
				;
				;         START COUNTER
				;
GOCTR:	LD	A,(CTRD1)	;GET COUNT
	OUT	(CTR),A		;LOAD COUNTER
	LD	A,(CTRD2)	;GET COUNT
	OUT	(CTR),A		;LOAD & GO
	JP	VECT1		;CHECK OTHER VECTORS
				;
				;         CLEAR COUNTER
				;
STCTR:	LD	A,0B0H		;RESET MODE
	OUT	(CTMODE),A	
	JP	VECT1		;CHECK OTHER VECTORS
				;
				;DESPOOL FUNCTIONS
				;
DSPSA:	LD	IY,PTRHSA	;LOAD PARAMETER POINTER
	JR	DSPOOL
				;
DSPSB:	LD	IY,PTRHSB	;LOAD PARAMETER POINTER
	JR	DSPOOL
				;
DSPPB:	LD	IY,PTRHPB	;LOAD PARAMETER POINTER
				;
DSPOOL:	LD	A,B		;GET DATA
	AND	0FH		;MASK UNUSED BITSŠ	CP	0		;BUFFER HOLD ON
	JR	NZ,NXT1	
	SET	1,(IY+9)	;SET FLAG
				;
DSPHLD:	LD	A,(IY+12)	;MOVE CURRENT PARAMETERS
	LD	(IY+14),A	;TO HOLD REGISTERS
	LD	A,(IY+13)
	LD	(IY+15),A
	LD	A,(IY+2)
	LD	(IY+16),A
	LD	A,(IY+3)
	LD	(IY+17),A
	LD	A,(IY+11)
	LD	(IY+18),A
	JP	VECT1
				;
NXT1:	CP	1		;BUFFER HOLD OFF
	JR	NZ,NXT2
	RES	1,(IY+9)	;RESET FLAG
	CALL	BITRES		;CLEAR MEM MAP BITS
	JP	VECT1	
				;
NXT2:	CP	4		;PAGE PAUSE ON
	JR	NZ,NXT3	
	SET	2,(IY+9)	;SET FLAG
	JP	VECT1
				;
NXT3:	CP	5		;PAGE PAUSE OFF
	JR	NZ,NXT4
	RES	2,(IY+9)	;RESET FLAG
	RES	3,(IY+9)
	JP	VECT1
				;
NXT4:	CP	7		;NEXT PAGE
	JR	NZ,NXT5
	RES	3,(IY+9)	;RESET FLAG
	JP	VECT1
				;
NXT5:	CP	8		;SPACE COMPRESSION ON
	JR	NZ,NXT6
	SET	0,(IY+9)
	JP	VECT1
				;
NXT6:	CP	9		;SPACE COMPRESSION OFF
	JR	NZ,NXT7
	RES	0,(IY+9)
	JP	VECT1
				;
NXT7:	CP	2		;COPY BUFFER
	JP	NZ,NXT8
	BIT	1,(IY+9)	;IF NO HOLD RET
	JP	Z,VECT1
				;
	LD	A,(IY+14)	;MOVE HOLD PARAMETER
	LD	(IY+12),A	;TO ACTIVE POSITIONSŠ	LD	A,(IY+15)	
	LD	(IY+13),A
				;
	LD	A,(IY+16)
	LD	(IY+2),A
	LD	A,(IY+17)
	LD	(IY+3),A
				;
	LD	A,(IY+18)
	LD	(IY+11),A
				;
	RES	0,(IY+7)	;RESET BUFFER FUL FLAG
	JP	VECT1	
				;
NXT8:	CP	3		;CLEAR BUFFER
	JP	NZ,NXT9
				;
	CALL	BITRES		;FREE THE CELLS
	LD	A,(IY+10)	;MOVE CELL NUMBER
	LD	(IY+11),A
				;
	LD	A,(IY+0)	;MOVE POINTER
	LD	(IY+2),A	
	LD	A,(IY+1)
	LD	(IY+3),A	
	LD	(IY+12),0	;ZERO COUNT
	LD	(IY+13),0
				;
	RES	0,(IY+7)	;RESET BUFFER FULL FLAG
	BIT	1,(IY+9)	;IF HOLD REDOIT
	JP	NZ,DSPHLD
	JP	VECT1
				;
NXT9:	CP	10		;NO OUTPUT BUFFERING
	JP	NZ,NXT10
	SET	5,(IY+9)	;SET NO BUFFERING FLAG
	JP	VECT1	
				;
NXT10:	CP	11		;OUTPUT BUFFERING ON
	JP	NZ,NXT11	
	RES	5,(IY+9)	;RESET NO BUFFERING FLAG
	JP	VECT1
				;
NXT11:	CP	6		;PAUSE OUTPUT
	JP	NZ,VECT1
	SET	3,(IY+9)	;SET NEXT PAGE FLAG
	JP	VECT1
				;
				;         MEMMAP BIT RESET ROUTINE
				;
BITRES:	PUSH	IY		;CALC STACK ADDRESS
	POP	HL
	LD	DE,OFFSET
	ADD	HL,DE
	LD	E,(IY+11)	;LOAD STACK POINTERŠ	LD	C,(IY+4)
NXTBIT:	LD	A,(IY+10)
	CP	E		;IF DAME RETURN
	RET	Z
	ADD	HL,DE		;ADD OFFSET
	LD	A,(HL)
	CP	C		;IF RESERVE RESET FLAG
	JR	NZ,OVRBIT
	RES	0,(IY+6)
OVRBIT:	PUSH	DE
	PUSH	HL
	LD	E,A	
	LD	HL,MEMMAP
	ADD	HL,DE
	LD	(HL),0
	POP 	HL
	POP	DE
	INC	E
	LD	A,MAPCNT+2
	CP	E
	JR	NZ,NXTBIT
	LD	E,0
	JR	NXTBIT
				;
				;         PROTOCAL FUNCTIONS
				;
				;         SERIAL A
				;
PROSA:	LD	IY,PTRHSA	;LOAD PARAMETER POINTER
	LD	HL,PTRSAH
	LD	C,SACMD		;LOAD PORT
	JR	PROTST
				;
				;         SERIAL B
				;
PROSB:	LD	IY,PTRHSB	;LOAD PARAMETER POINTER
	LD	HL,PTRSBH	
	LD	C,SBCMD
				;
PROTST:	LD	A,B		;GET POINTERS
	AND	0FH		;MASK HI BITS
				;
	CP	0		;IS IT BREAK OFF
	JR	NZ,PNXT1	
	LD	A,SEREN		;BREAK OFF BYTE
	OUT	(C),A	
	JP	VECT1
				;
PNXT1:	CP	1		;IS IT BREAK ON
	JR	NZ,PNXT2
	LD	A,SEREN+8	;BREAK ON BYTE
	OUT	(C),A		;SEND IT
	JP	VECT1
				;
PNXT2:	CP	2		;IS IT XON/XOFFŠ	JR	NZ,PNXT3	
	LD	A,5		;LOAD ON BYTE
FIN1:	LD	(IY+8),A	;TURN OUT BUFFER ON
	PUSH	HL
	POP	IY
	LD	(IY+8),A	;TURN IN BUFFER ON
	JP	VECT1
				;
PNXT3:	CP	3		;IS IT ETX/ACK
	JR	NZ,PNXT4
	LD	A,9		;TURN OUT BUFFER ON
	JR	FIN1
				;
PNXT4:	CP	4		;IS IT ETB/ACK
	JR	NZ,PNXT5
	LD	A,11H		;TURN OUT BUFFER ON
	JR	FIN1
				;
PNXT5:	CP	5		;IS IT ALL OFF
	JP	NZ,VECT1
	XOR	A		;CLEAR A
	JR	FIN1
				;
				;         INTERRUPT HOST TO SERIAL A
				;
INTHSA:	LD	IY,PTRHSA	;LOAD PARAMETER POINTER
	LD	C,1		;LOAD BUFFER MASK
	JR	INTBUS		;GET CHARACTER
				;
				;         INTERRUPT HOST TO SERIAL B
				;
INTHSB:	LD	IY,PTRHSB	;LOAD PARAMETER POINTER
	LD	C,2		;LOAD BUFFER MASK
	JR	INTBUS		;GET CHARACTER
				;
				;         INTERRUPT HOST TO PARALLEL B
				;
INTHPB:	LD	IY,PTRHPB	;LOAD PARAMETER TABLE
	LD	C,4		;LOAD BUFFER MASK
				;
				;         INTERRUPT HOST TO ALL I/O PORTS
				;
INTBUS:	LD	A,(BUFST)	;TELL HOST YOUR BUSY
	OR	C		;SET BIT
	OUT	(BBUFST),A	;TELL HOST
	LD	(BUFST),A	;SAVE IT
				;
	IN	A,(BINDTA)	;GET DATA
	BIT	0,(IY+7)	;IF BUFFER FULL
	JP	NZ,VECT1
	CALL	PUTDTA		;STORE IT IN BUFFER
	JP	VECT1
				;
				;         INTERRUPT SERIAL A TO HOST
				;ŠINTSAH:	PUSH	AF
	PUSH	BC	
	PUSH	DE
	PUSH	HL
SAH:	LD	C,SACMD		;LOAD PORT NUMBER
	LD	IY,PTRSAH	;LOAD PARAMETER POINTER
	CALL	SERIN		;GET CHARACTER
	CALL	NC,PUTDTA	;STORE DATA IN BUFFER
	CALL 	SBUFF		;DO PROTOCALS IN BUFFER FULL
	JP	VECT4		;CHECK OTHER VECTORS
				;
				;         INTERRUPT SERIAL B TO HOST
				;
INTSBH:	PUSH	AF
	PUSH	BC
	PUSH	DE
	PUSH	HL
SBH:	LD	C,SBCMD		;LOAD PORT NUMBERS
	LD	IY,PTRSBH	;LOAD PARAMETER POINTER
	CALL	SERIN		;GET CHARACTER
	CALL	NC,PUTDTA	;STORE DATA IN BUFFER
	CALL	SBUFF		;DO PROTOCALS IF BUFFER FULL
	JP	VECT3		;CHECK OTHER VECTORS
				;
				;         SERIAL BUFFERS STATUS CHECK
				;
SBUFF:	BIT	0,(IY+7)	;IF BUFFER FULL
	JR	Z,OVRDSR	;DO NOTHING
	LD	A,SEREN-1	;DISABLE RCVR INTERRUPT
	OUT	(C),A
	BIT	2,(IY+8)	;XON/XOFF ON?
	RET	Z		;NO SEND
	IN	A,(C)		;CHECK STATUS
	AND	81H
	CP	81H	
	JR	Z,$-6
	DEC	C		;POINT AT DATA PORT
	LD	A,XOFF	
	OUT	(C),A		;SEND XOFF
	SET	1,(IY+8)	;SET WAIT BIT
	RET	
				;
OVRDSR:	LD	A,SEREN		;RESET DSR
	OUT	(C),A		SEND IT
	RET
				;
				;         INTERRUPT PARALLEL A TO HOST
				;
INTPAH:	PUSH	AF
	PUSH	BC
	PUSH	DE
	PUSH	HL
PAH:	LD	IY,PTRPAH	;LOAD PARAMETER POINTER
	LD	A,8		;DISABLE PORT INTERRUPT
	OUT	(PCMD),A	Š	BIT	0,(IY+7)	;IF BUFFERS FULL
	JP	NZ,VECT2	;NOT OK RETURN
	IN	A,(PADATA)	;GET CHARACTER
	CALL	PUTDTA
	BIT	0,(IY+7)	;CHECK IF BUFFER FULL
	JP	NZ,VECT2
	LD	A,9		;ENABLE PORT INTERRUPT
	OUT	(PCMD),A	
	JP	VECT2
				;
				;         SERIAL INPUT ROUTINE
				;
SERIN:	LD	A,SEREN-2	;SET DSR FOR BUSY
	OUT	(C),A		;TELL PERIPHAIL
	DEC	C		;POINT AT PORT
	IN	A,(C)		;GET DATA
	INC	C		;POINT AT CMD
	BIT	0,(IY+7)	;IF BUFFER FULL WASTE DATA
	SCF			;SET CARRY
	RET	NZ	
	OR	A		;CLEAR CARRY
	RET
				;
				;         INTERRUPT PROTOCAL SERIVCE ROUTINE
				;
PROTO:	BIT	2,(IY-72)	;IS PROTO XON/XOFF
	JR	Z,CKXACK
 	CP	XON		;IS IT XON
	JR	NZ,CKXOFF	
	RES	1,(IY-72)	;RESET WAIT FLAG
	OR	A		;CLEAR CARRY
	RET
				;
CKXOFF:	CP	XOFF		;IS IT XOFF
	JR	NZ,NOACT	
	SET	1,(IY-72)	;SET WAIT FLAG
	OR	A		;CLEAR CARRY
	RET
				;
CKXACK:	CP	ACK		;IS IT ACK
	JR	NZ,NOACT	;NO ACTION NEEDED
	RES	1,(IY-72)	;RESET WAIR FLAG
	OR	A		;CLEAR CARRY
	RET
				;
NOACT:	SCF			;SET CARRY
	RET
				;
				;         PUT DATA
				;
PUTDTA:	BIT	0,(IX+8)	;CHECK FOR PROTOCAL
	JR	Z,NOPRO	
	CALL	PROTO		;DO PROTOCAL
	RET	NC		;NO CHARACTER
				;ŠNOPRO:	PUSH	BC		;SAVE PORT
	LD	L,(IY+0)	;LOAD CELL POINTERS
	LD	H,(IY+1)
				;
	LD	(INTTMP),A	;TEMP STORE
	BIT	7,A		;CHECK FOR PARITY BIT
	JR	Z,SPCK	
	RES	0,(IY+9)	;CANCEL SPACE COMPRESSION
				;
SPCK:	BIT	0,(IY+9)	;CHECK FOR SPACE COMPRESSION
	JP	Z,NOPACK
	CP	' '		;IS CHARACTER A SPACE?
	JR	Z,ITISSP	;YES-PACK IT
	BIT	4,(IY+9)	;SPACE PRESENT
	JR	Z,NOPACK
ADCNT:	RES	4,(IY+9)	;RESET SPACE PRESENT FLAG
	CALL	ADVANC		;INC COUNTER
	JR	NOPACK
				;
ITISSP:	LD	A,(BUFST)	;CLEAR BUFFER FULL FLAG
	XOR	C		;CLEAR BIT FOR THIS BUFFER
	LD	(BUFST),A	;SAVE IT
	OUT	(BBUFST),A	;TELL HOST
				;
	BIT	4,(IY+9)	;SPACE COUNT?
	JR	NZ,MORSP	
	LD	(HL),81H	;START SPCE COUNT
	SET	4,(IY+9)	;DET SPACE PRESENT BIT
	LD	(IY+19),L	;SAVE SPACE ADDRESS
	LD	(IY+20),H	
	JR	ALLDON
				;
MORSP:	LD	L,(IY+19)	;GET SPACE ADDRESS
	LD	H,(IY+20)	
	LD	A,(HL)		;GET SPACE COUNT
	INC	A		;ADD ONE TO SPACE COUNT
	CP	0FFH		;COUNT FULL?
	JR	NZ,OVRCT
	RES	4,(IY+9)	;RESET SPACE BPRESENT FLAG
	CALL	ADVANC
				;
OVRCT:	LD	(HL),A		;SAVE COUNT
	POP	BC		;RESTOREPORTS
	RET
				;
NOPACK:	LD	A,(INTTMP)	;GET CHARACTER
	LD	(HL),A		;SAVE CHARACTER
	CALL	ADVANC		;INC COUNT
ALLDON:	BIT	5,(IY+9)	;IF NO BUFFERING
	JR	Z,OVRNB	
	SET	0,(IY+7)	;SET BUFFER FULL
	POP	BC		;RESTORE BC
	RET
				;
OVRNB:	CALL	NXTADD		;GET NXTADDŠ	LD	(IY+0),L	;SAVE ADDRESS
	LD	(IY+1),H	
	POP	BC		;RESTORE PORTS
	BIT	1,(IY+9)	;IF HOLD ON INC HOLD COUNT
	RET	Z	
	INC	(IY+14)
	RET	NZ
	INC	(IY+15)
	RET
				;
				;         ADVANCE CHARACTER COUNT
				;
ADVANC:	INC	(IY+12)		;INC LSB
	RET	NZ	
	INC	(IY+13)		;INC	MSB
	RET	
				;
				;         CALC NEXT BUFFER CHARACTER ADDRESS
				;
NXTADD:	PUSH	HL		;SAVE REGISTER
	LD	DE,-3FFH	;CHECK FOR END OF CELL
	LD	A,H		;STRIP OF HIGH ADRESS
	AND	3	
	LD	H,A	
	ADC	HL,DE
	POP	HL		;RESTORE DATA
	INC	HL		;INC ONE
	CALL	Z,CELLCK	;NEED NEW CELL
	RET
				;
				; ROUTINE LOOKS FOR FREE CELLS & CALC'S ADDRESS
				;
CELLCK:	LD	HL,MEMMAP+6	;LOAD MEMORY MAP POINTER
	LD	BC,MAPCNT	;LOAD COUNTER
	XOR	A		;CLEAR A
	CPIR			;LOOK FOR FREE CE;;
	JP	Z,ONECEL	;FOUND FREE CELL
				;
	BIT	0,(IY+6)	;NO CELLS FREE
	LD	A,0FFH		;SET FLAG FOR RETURN
	SET	0,(IY+7)	;SET BUFFER FULL FLAG
	RET	NZ		;BUFFER FULL+RESERVE IN USE
				;
	SET	0,(IY+6)	;SET RESERVE CELL FLAG
	LD	A,(IY+4)	;GET RESERVE CELL NUMBER
	JR	OVRSUB		
				;
ONECEL:	DEC	HL		;ADJUST POINTER
	SET	0,(HL)		;SET CELL AS BUSY
				;
	LD	A,MAPCNT+5	;FIGURE CELL ADDRESS
	SUB	C		
OVRSUB:	LD	C,A		;CELL NUMBER IN C
	PUSH	IY		;CALC STACK ADDRESS
	POP	HL	Š	LD	DE,OFFSET	;ADD OFSET TO BASE
	ADD	HL,DE	
	LD	E,(IY+10)	;ADD STACK POINTER
	INC	E		;ADVANCE POINTER
	LD	A,MAPCNT+2	;WRAP IF END OF STACK
	CP	E	
	JR	NZ,OVRRAP	;NO DON'T WRAP
	LD	E,0		;WRAP
OVRRAP:	ADD	HL,DE	
	LD	(HL),C		;PUT CELL NUMBER IN STACK
	LD	(IY+10),E	;SAVE POINTER
				;
CELADD:	LD	HL,1000H	;GET READY TO MULTIPLY
	LD	DE,400H		;LOAD CELL SIZE
	LD	A,C		;PUT CELL NUMBER IN A
CELA:	SRL	A		;SHIFT TO CARRY
	JR	NC,NADD		;IF NO CARRY NO ADD
	ADD	HL,DE		;ADD
NADD:	SLA	D		;MULT X2
	OR	A		;A ZERO?
	JR	NZ,CELA
	LD	(IY+0),L	;SAVE ADDRESS
	LD	(IY+1),H
	XOR	A		;SET FLAG AS FOUND	
	RES	0,(IY+7)	;RESET BUFFER FULL FLAG
	RET
				;
				;         INTERRUPT VECTOR CHECK
				;
VECT1:	IN	A,(PSTAT)	;CHECK STATUS ON PAR A
	AND	8H	
	JP	NZ,PAH
VECT2:	IN	A,(SBCMD)	;CHECK STATUS ON SER B
	AND 	2	
	JP	NZ,SBH
VECT3:	IN	A,(SBCMD)	;CHECK STATUS ON SER A
	AND	2	
	JP	NZ,SAH
VECT4:	POP	HL		;RESTORE REGISTERS
	POP	DE
	POP	BC
	POP	AF
	EI
	RET
				;
				;
				;         BAUD RATE TABLE
				;
BTABLE:	DEFW	B110		;110 BAUD
	DEFW	B300		;300 BAUD
	DEFW	B600		;600 BAUD
	DEFW	B1200		;1200 BAUD
	DEFW	B2400		;2400 BAUD
	DEFW	B4800		;4800 BAUD
	DEFW	B9600		;9600 BAUDŠ	DEFW 	B19200		;19200 BAUD
				;
				;         DEFAULT I/O PORT PARAMETER TABLE
				;
PTRTBL:	DEFW	2800H		;HOST TO SERIAL A
	DEFW	2800H
	DEFB	0
				;
	DEFW	2C00H		;SERIAL A TO HOST
	DEFW	2C00H
	DEFB	1
				;
	DEFW	3000H		;HOST TO SERIAL B
	DEFW	3000H
	DEFB	2
				;
	DEFW	3400H		;SERIAL B TO HOST
	DEFW	3400H
	DEFB	3
				;
	DEFW	3800H		;PARALLEL A TO HOST
	DEFW	3800H
	DEFB	4
				;
	DEFW	3C00H		;HOST TO PARALLEL B
	DEFW	3C00H
	DEFB	5
				;
	DEFB	6,7,8,9,10,11
				;
				;         INITIALIZED I/0 PARAMETERS
				;
IOPAR:	DEFW	B9600		;BAUD A
	DEFW	B300		;BAUD B
	END
