
;0058
;12/10/81
;DUAL 80/64 CHARACTERS
;SOL MONITOR VERSION 1.4
;
;********************************
;    DUAL PERSONALITY MONITOR   *
;          11/24/81             *
;********************************
;
;
;
;	CONDITIONAL ASSEMBLY CONSTANTS
;
S80	EQU	00000H	; 80 CHAR SCREEN
MUX	EQU	00000H	; TARBELL/HELIOS MULTIPLEXER
AUTO	EQU	00000H	; AUTOLOAD ON POWER-UP
NS	EQU	00001H	; NORTH STAR CONTROLLER
TARBEL	EQU	00000H	; TARBELL CONTROLLER
HELIOS	EQU	00000H	; HELIOS CONTROLLER

;	SYSTEM EQUATES

	IF	S80
;
ORGIN	EQU	0F000H	; SOLOS ORGIN
VDMEM	EQU	ORGIN+0800H	; VDM SCREEN MEMORY
RAM	EQU	ORGIN+0F80H	; SOLOS RAM AREA
SYSTP	EQU	ORGIN+1000H	; SOLOS STACK TOP
LLGTH	EQU	80	; LINE LENGTH
NLINES	EQU	24	; NUMBER OF LINES ON SCREEN

	ENDIF
	IF	NOT S80
;
ORGIN	EQU	0C000H	; SOLOS ORGIN
VDMEM	EQU	ORGIN+0C00H	; VDM SCREEN MEMORY
RAM	EQU	ORGIN+0800H	; SOLOS RAM AREA
SYSTP	EQU	ORGIN+0C00H	; SOLOS STACK TOP
LLGTH	EQU	64	; LINE LENGTH
NLINES	EQU	16	; NUMBER OF LINES ON SCREEN

	ENDIF

DOSBASE	EQU	02000H
DPROM	EQU	0E800H	; DISK BOOT ADDRESS
OS	EQU	DOSBASE+0028H
BASIC	EQU	DOSBASE+0A00H
WP	EQU	DOSBASE+0A00H

WB	EQU	0	; CP/M WARM BOOT VECTOR
;
;
;	KEYBOARD SPECIAL KEY ASSIGNMENTS
;
;	THESE DEFINITIONS ARE DSIGNED TO ALLOW
;	COMPATIBILITY WITH CUTER(TM).  THESE ARE THE
;	SAME KEYS WITH BIT 7 (X 80) STRIPPED OFF.
;
DOWN	EQU	9AH	; CTL-Z
UP	EQU	97H	; CTL-W
LEFT	EQU	81H	; CTL-A
RIGHT	EQU	93H	; CTL-S
CLEAR	EQU	9BH	; CTL-K
HOME	EQU	8EH	; CTL-N
MODE	EQU	80H	; CTL-@
BACKS	EQU	5FH	; BACKSPACE
LF	EQU	0AH
CR	EQU	0DH
LOAD	EQU	8CH
BLANK	EQU	020H
SPACE	EQU	BLANK
CX	EQU	'X'-40H
ESC	EQU	1BH
EOT	EQU	00H
BELL	EQU	07H
;
;	PORT ASSIGNMENTS
;
STAPT	EQU	0FAH	; STATUS PORT GENERAL
SERST	EQU	0F8H	; SERIAL STATUS PORT
SDATA	EQU	0F9H	; SERIAL DATA
PDATA	EQU	0FDH	; PARALLEL DATA
KDATA	EQU	0FCH	; KEYBOARD DATA
DSTAT	EQU	0FEH	; VDM CONTROL PORT
SENSE	EQU	0FFH	; SENSE SWITCHES
;
;	BIT ASSIGNMENT MASKS
;
SCD	EQU	1	; SERIAL CARRIER DETECT
SDSR	EQU	2	; SERIAL DATA SET READY
SPE	EQU	4	; SERIAL PARITY ERROR
SFE	EQU	8	; SERIAL FRAMING ERROR
SOE	EQU	16	; SERIAL OVERRUN ERROR
SCTS	EQU	32	; SERIAL CLEAR TO SEND
SDR	EQU	64	; SERIAL DATA READY
STBE	EQU	128	; SERIAL TRANSMITTER BUFFER EMPTY
;
KDR	EQU	1	; KEYBOARD DATA READY
PDR	EQU	2	; PARALLEL DATA READY
PXDR	EQU	4	; PARALEL DEVICE READY
SOK	EQU	1	; SCROLL OK FLAG
;
;
;	SYSTEM GLOBAL AREA
;	PARAMETERS STORED IN RAM
;
UIPRT	EQU	RAM+000H	; USER DEFINED INPUT RTN IF NON ZERO
UOPRT	EQU	RAM+002H	; USER DEFINED OUTPUT RTN IF NON ZERO
DFLTS	EQU	RAM+004H	; DEFAULT PSUEDO I/O PORTS
IPORT	EQU	RAM+006H	; CRNT INPUT PSUEDO PORT
OPORT	EQU	RAM+007H	; CRNT OUTPUT PSUEDO PORT
NCHAR	EQU	RAM+008H	; CURRENT CHAR POSITION
LINE	EQU	RAM+009H	; CURRENT LINE POSITION
BOT	EQU	RAM+00AH	; BEGINNING OF TEXT DISPLACEMENT
SPEED	EQU	RAM+00BH	; SPEED CONTROL BYTE
ESCFL	EQU	RAM+00CH	; ESCAPE FLAG CONTROL BYTE
INPTR	EQU	RAM+00EH	; FOR COMPATIBILITY W/ CUTER
NUCNT	EQU	RAM+010H	; NUMBER OF NULLS AFTER CRLF
RAMX	EQU	RAM+012H
LCNT	EQU	RAM+013H	; MEMORY TEST LINE COUNT
TMBGN	EQU	RAM+014H	; TEST MEMORY BEGINNING ADDRESS
TMSIZE	EQU	RAM+016H	; TEST MEMORY SIZE
RPEAT	EQU	RAM+018H	; # OF MEMORY TET CYCLES TO RUN
THEAD	EQU	RAM+01CH	; NAME
;
				; ROOM FOR FUTURE EXPANSION
;
CUTAB	EQU	RAM+03CH	; ROOM FOR UP TO 6 CUSTOM USER COMMANDS
USERAM	EQU	RAM+054H	; USER RAM AREA STARTS HERE
;
;
;
; REMEMBER THAT THE STACK WORKS ITS WAY DOWN
; FROM THE END OF THIS 1K RAM AREA.
;
;
	ORG	ORGIN
;
START:	DB	000H
;
INIT:	JMP	STRTA
RETRN:	JMP	COMND
MSGV:	JMP	MESAGE	; OUTPUT MESSAGE UNTIL '00'
	JMP	PERSE	; CLEAR SCREEN
	JMP	CRLF	; OUTPUT CR & LF
	JMP	HEOUT	; OUTPUT 'A' IN HEX
	JMP	ADOUT	; OUTPUT 'HL' IN HEX
;
	ORG	ORGIN+19H
;
SOUT:	LDA	OPORT
AOUT:	JMP	OUTPR
;
SINP:	LDA	IPORT
AINP:	PUSH	H
	LXI	H,ITAB
;
IOPRC:	ANI	003H
	RLC
	ADD	L
	MOV	L,A
	JMP	DISPT
;
KSTAT:	IN	STAPT
	CMA
	ANI	KDR
	RZ
	IN	KDATA
	RET
;
SETNU:	STA	NUCNT
	RET
;
OUTPR:	PUSH	H
	LXI	H,OTAB
	JMP	IOPRC
;
SSTAT:	IN	SERST
	ANI	SDR
	RZ
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ECON:	MOV	A,B
	CPI	003H
	JZ	CURET
	CPI	004H
	JNZ	ARET2
ARET:	MOV	B,H
	MOV	C,L
ARET1:	POP	H
	POP	D
	PUSH	B
	PUSH	H
	XRA	A
ARET2:	STA	ESCFL
	RET
;
CURET:	LXI	H,NCHAR
	MOV	B,M
	INX	H
	MOV	C,M
	JMP	ARET1
;
STRTA:	XRA	A
	MVI	C,USERAM-RAM	; CLEAR SYSTEM RAM
	LXI	H,UIPRT
CLERA:	MOV	M,A
	INX	H
	DCR	C
	JNZ	CLERA
	LXI	SP,SYSTP
	CALL	PERSE
	IN	SENSE	; GET SENSE SWITCH INPUT
	CPI	0FFH
	IF	AUTO
	JZ	COMN1
	ENDIF
	IF	NOT AUTO
	JMP	COMN1
	ENDIF
	MOV	H,A	; SET HIGH VECTOR ADDRESS
	MVI	L,0	; SET LOW VECTOR TO 00
	PUSH	H
	CALL	ADOUT	; DISPLAY VECTOR ADDR
	CALL	MSGAUTO
AUTOMSG: DB	' AUTO',EOT
MSGAUTO: POP	H
;
MESAGE:	MOV	A,M
	CPI	EOT
	RZ
	MOV	B,A
	CALL	SOUT
	INX	H
	JMP	MESAGE
;
COMN1:	XRA	A
	STA	OPORT
	STA	IPORT
COMN2:	STA	LCNT
COMND:	LXI	SP,SYSTP
	LDA	OPORT
	PUSH	PSW
	XRA	A
	STA	OPORT
	CALL	CRLF
	MVI	B,'>'	; THE PROMPT
	CALL	SOUT
	CALL	GCLIN
	POP	PSW
	STA	OPORT
	CALL	COPRC
	JMP	COMND
;
GCLIN:	CALL	SINP
	JZ	GCLIN
	CPI	LOAD
	IF	NS
	JZ	DPROM	; BOOT NORTH STAR
	ENDIF
	IF	(NOT NS) AND TARBEL
	JZ	TARBL
	ENDIF
	IF	(NOT NS) AND (NOT TARBEL) AND HELIOS
	JZ	PTBOOT
	ENDIF
	ANI	07FH
	JZ	COMN1
	MOV	B,A
	LDA	LCNT
	ORA	A
	MOV	A,B
	CZ	TOUPP	; CONVERT TO UPPER-CASE
	MOV	B,A
	CPI	CR
	JZ	CLINE
	CPI	LF
	RZ
	CPI	07FH
	JNZ	CONT
	MVI	B,'_'
CONT:	CALL	SOUT
	JMP	GCLIN
;
TOUPP:	CPI	'a'
	RC
	CPI	'z'+1
	RNC
	ANI	0DFH	; CONVERT TO UPPER
	RET
;
COPRC:	CALL	CREM
	MVI	C,001H
	CALL	VDAD2
	XCHG
	LXI	H,START
	PUSH	H
	CALL	SCHR
	JZ	ERR1
	XCHG
	LXI	D,COMTA
	CALL	FDCOM
	CZ	FDCOU
DISPO:	JZ	ERR2
	INX	D
	XCHG
DISPT:	MOV	A,M
	INX	H
	MOV	H,M
	MOV	L,A
	XTHL
	MOV	A,L
	RET
;
FDCOU:	LXI	D,CUTAB
FDCOM:	LDAX	D
	ORA	A
	RZ
	PUSH	H
	CMP	M
	INX	D
	JNZ	NCOM
	INX	H
	LDAX	D
	CMP	M
	JNZ	NCOM
	POP	H
	ORA	A
	RET
;
NCOM:	INX	D
	INX	D
	INX	D
	POP	H
	JMP	FDCOM
;
;
;********************************
;         COMMAND TABLE         *
;                               *
;   THIS TABLE DESCRIBES THE    *
;   VALID COMMANDS FOR SOLOS    *
;                               *
;********************************
;
	IF	HELIOS
COMTA:	DB	'BO'
	DW	PTBOOT
	ENDIF
	IF	NOT HELIOS
COMTA:	DB	'TE'	; TERMINAL MODE
	DW	TERM
	ENDIF
	IF	TARBEL
	DB	'BT'
	DW	TARBL
	ENDIF
	DB	'EX'	; EXEC
	DW	EXEC
	DB	'SE'	; SET COMMAND
	DW	SETCMD
	DB	'CU'	; CUSTOM COMMAND
	DW	CUSET
	DB	'DA'
	DW	DA
	DB	'DH'
	DW	DH
	DB	'EA'
	DW	EA
	DB	'EH'
	DW	EH
	DB	'FM'
	DW	FM
	DB	'MM'
	DW	MM
	DB	'CM'
	DW	CMCMD
	DB	'AR'
	DW	AR
	DB	'FC'
	DW	FC
	DB	'FA'
	DW	FA
	DB	'FB'
	DW	FB
	DB	'FH'
	DW	FH
	DB	'TM'
	DW	TM
	DB	'LC'
	DW	LC
;
;	JUMP VECTORS
;
	DB	'OS'
	DW	OS
	DB	'WB'
	DW	WB
	DB	'WP'
	DW	WP
	DB	'BA'
	DW	BASIC+4
	DB	'BC'
	DW	BASIC
	DB	'BV'
	DW	BASIC+14H
	DB	000H	; END OF TABLE MARK
;
;
;	DISPLAY DRIVER COMMAND TABLE
;
;	THIS TABLE DEFINES THE CHARACTERS FOR SPECIAL
;	PROCESSING.  IF THE CHARACTER IS NOT IN THE
;	TABLE, IT GOES TO THE SCREEN.
;
TBL:	DB	CLEAR-80H	; SCREEN
	DW	PERSE
	DB	UP-80H	; CURSOR
	DW	PUP
	DB	DOWN-80H ;
	DW	PDOWN
	DB	LEFT-80H ;
	DW	PLEFT
	DB	RIGHT-80H
	DW	PRIT
	DB	HOME-80H
	DW	PHOME
	DB	CR	; CARRIAGE RETURN
	DW	PCR
	DB	LF	; LINE FEED
	DW	PLF
	DB	BELL	; BELL ALARM
	DW	PBELL
	DB	BACKS	; BACKSPACE
	DW	PBACK
	DB	ESC	; ESCAPE KEY
	DW	PESC
	DB	000H	; END OF TABLE
;
;
;	OUTPUT DRIVE TABLE
;
OTAB:	DW	VDMOT	; VDM DRIVER
	DW	SDROT	; SERIAL OUTPUT
	DW	PROUT	; PARALLEL OUTPUT
	DW	ERROT	; ERROR OR USER DRIVER HANDLER
;
;
;	INPUT DEVICE TABLE
;
ITAB:	DW	KSTAT	; KEYBOARD INPUT
	DW	SSTAT	; SERIAL INPUT
	DW	PASTA	; PARALLEL INPUT
	DW	ERRIT	; ERROR OR USER DRIVER HANDLER
;
;
;	SECONDARY COMMAND TABLE FOR SET COMMAND
;
SETAB:	DB	'S='	; SET DISPLAY SPEED
	DW	DISPD
	DB	'I='	; SET INPUT
	DW	SETIN
	DB	'O='	; SET OUTPUT
	DW	SETOT
	DB	'N='	; NULLS
	DW	SETNU
	DB	'CI'	; SET CUSTOM INPUT DRIVER ADDR
	DW	SETCI
	DB	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
;
DELAY:	LXI	D,0000H
DLOP1:	DCX	D
	MOV	A,D
	ORA	E
	JNZ	DLOP1
	DCR	B
	JNZ	DELAY
	RET
;
EH:	MVI	A,004H
	DB	01	;LXI B,
EA:	MVI	A,003H
	DB	01
DA:	MVI	A,001H
DH:	STA	RAMX
	CALL	L0032
DH1:	CALL	DH3
	CALL	BOUT
	MVI	C,010H
DH2:	MOV	A,M
	CALL	L0034
	CALL	MM2
	INX	H
	DCR	C
	JZ	DH1
	JMP	DH2
;
DH3:	CALL	CRLF
	MOV	A,H
	CALL	HEOUT
	MOV	A,L
	CALL	HEOUT
	JMP	L0039
;
L0034:	MOV	B,A
	LDA	RAMX
	ANI	003H
	MOV	A,B
	JZ	L0040
	PUSH	H
	PUSH	B
	CALL	VDADD
	CALL	L0039
	POP	B
	MOV	M,B
	POP	H
	JMP	L0042
;
L0040:	PUSH	B
	CALL	HEOUT
	POP	B
	JMP	L0042
;
L0044:	CALL	SINP
	JZ	BOUT
	ANI	07FH
	JZ	COMN1
	JMP	HBOU1
;
L0042:	LDA	RAMX
	SUI	002H
	JC	L0044
	PUSH	H
	CALL	VDADD
	CALL	BOUT
	XCHG
	POP	H
	MVI	C,002H
;
L0046:	CALL	KSTAT
	JZ	L0046
	MOV	B,A
	CPI	MODE
	JZ	COMN1
	CPI	DOWN
	JZ	L0047
	CPI	UP
	JZ	L0048
	ANI	7FH
	MOV	B,A
	CALL	SOUT
	LDA	RAMX
	CPI	003H
	JZ	L0049
	DCR	C
	JNZ	L0046
	PUSH	H
	CALL	CREM
	CALL	PSCAN
	POP	H
	MOV	B,A
;
L0049:	MOV	M,B
;
L0047:	MVI	C,001H
;
L0039:	CALL	BOUT
	JMP	BOUT
;
L0048:	DCX	H
	DCX	H
	JMP	L0047
;
L0032:	CALL	SCONV
	PUSH	H
	CALL	PSCAN
	PUSH	H
	CALL	PSCAN
	POP	D
	POP	B
	XTHL
	PUSH	H
	PUSH	B
	POP	H
	RET
;
L0053:	CALL	L0032
	XTH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USH	B
	LDA	LCNT
	ADI	07H
	IF	S80
	CPI	LLGTH-3
	ENDIF
	IF	NOT S80
	CPI	LLGTH-1
	ENDIF
	CNC	CRLF0
	STA	LCNT
	POP	B
	PUSH	B
	CALL	SOUT
	MVI	B,';'
	CALL	SOUT
	CALL	ADOUT
	POP	B
	POP	PSW
	RET
;
PASCMPT	PUSH	H
	PUSH	B
	CALL	CRLF0
	MOV	A,C
	CALL	HEOUT
	LXI	H,PCMPLT
	CALL	MESAGE
	CALL	CRLF0
	MVI	A,(-7 AND 0FFH)
	STA	LCNT
	CALL	KSTAT
	CPI	MODE
	JZ	COMN1
	POP	B
	POP	H
	RET
;
L0098:	INR	B
L0099:	DAD	D
	JC	L0098
L0104:	CALL	DSUBR
	MOV	A,B
	ORA	A
	JNZ	L0105
	MOV	A,C
	ORA	A
	RZ
L0105:	INR	C
	MOV	A,B
	CALL	HEOU1
	MVI	B,000H
	RET
;
HLDEQ:	MOV	A,L
	SUB	E
	MOV	A,H
	SBB	D
	RET
;
DSUBR:	MOV	A,L
	SUB	E
	MOV	L,A
	MOV	A,H
	SBB	D
	MOV	H,A
	RET
;
LC:	DCR	A
	STA	LCNT
	RET
;
PBELL:	MOV	A,B	; GET BELL CODE
	OUT	0FCH	; SOUND ALARM
	RET
;
PCMPLT:	DB	'  PASS COMPLETED',EOT
;
	IF	HELIOS
;
;  Helios II bootstrap
;  Syntax:  BOOT
;
PTBOOT:	EQU	$
	ENDIF
	IF	HELIOS AND MUX
	MVI	A,04H
	OUT	0ECH	;switch Tarbell Multiplexer 'ON'
	ENDIF
	IF	HELIOS
	MVI	A,0CFH
	OUT	0F7H	;restore, latch load head, select 0
	OUT	0F5H	;reset TC, ABORT, CRC error and checked
	MVI	A,(-1 AND 0FFH)
	OUT	0F1H	;set do nothing
;
BOOTL:	IN	0F0H	;wait til ABORT clears
	ANI	40H
	JNZ	BOOTL
	MVI	A,0DFH
	OUT	0F7H	;latch load head, select 0
;
IFIN:	IN	0F0H	;wait for index
	RLC
	JZ	IFIN
	LXI	D,1290H
;
IFIN2:	DCX	D
	MOV	A,D
	ORA	E
	JNZ	IFIN2
;
IFIN3:	IN	0F0H	;wait for index - again!
	RLC
	JC	IFIN3
;
SWAIT:	IN	0F0H	;wait for SREADY (controller ready)
	ANI	2
	JZ	SWAIT
	MVI	A,40H
	OUT	0F3H	;set DMA length to 340H
	MVI	A,3
	OUT	0F4H
	XRA	A
	OUT	0F5H	;set DMA start to DMA
	OUT	0F6H
	MVI	A,3
	OUT	0F1H	;read disk (latch 3 to U22)
;
PTDLOOP: IN 0F0H	;wait until CRC error, TC, or
;			SREADY
	ANI	0BH
	JZ	PTDLOOP
	ANI	8	;non zero means CRC error
	JNZ	PTBOOT
	JMP	4
;
	ENDIF
	IF	NOT HELIOS
;
TERM:	CALL	PSCAN
	STA	IPORT
	CALL	PSCAN
	STA	OPORT
TERM1:	CALL	KSTAT
	JZ	TIN
	MOV	B,A
	CPI	MODE
	JZ	COMN1
	JC	TOUT
	CALL	VDMOT
	JMP	TIN
;
TOUT:	CALL	SOUT
TIN:	CALL	SINP
	JZ	TERM1
	ANI	07FH
	JZ	TERM1
	MOV	B,A
	CPI	ESC
	JNC	TERM2
	CPI	CR
	JZ	TERM2
	CPI	LF
	JZ	TERM2
	CPI	BELL
	JZ	TERM2
	LDA	ESCFL
	ORA	A
	JNZ	TERM2
	PUSH	B
	MVI	B,ESC
	CALL	VDMOT
	MVI	B,007H
	CALL	VDMOT
	POP	B
TERM2:	CALL	VDMOT
	JMP	TERM1
;
;
	ENDIF
;
	IF	TARBEL

;TARBELL BOOT ROUTINE
;
TARBL:	EQU	$
	ENDIF
	IF	TARBEL AND MUX
	MVI	A,03H
	OUT	0ECH
	ENDIF
	IF	TARBEL
	IN	0ECH
	XRA	A
	MOV	L,A
	MOV	H,A
	INR	A
	OUT	0EAH
	MVI	A,08CH
	OUT	0E8H
TRB17:	IN	0ECH
	ORA	A
	JP	TRB16
	IN	0EBH
	MOV	M,A
	INX	H
	JMP	TRB17
TRB16:	IN	0E8H
	ORA	A
	JZ	007DH
	JMP	TARBL
;
	ENDIF
;
	END

