BASE	EQU	0E000H		;Assembly Address
;BASE	EQU	0100H		;Assembly Address (TPA)
SPTR	EQU	BASE+1FD0H	;Stack Pointer
*
****************************************************
*                                                  *
* Vector Graphic Serial Extended Systems Monitor   *
*                                                  *
*   Version 4.0x2 (1K) for Vector Graphic I/O	   *
*        Updated and Modified by                   *
*     Tom Sanderson and Mike Douglas 		   *
*						   *
*   Original 4.0C VECTOR MZ MONITOR written by	   *
*                                                  *
*       R. S. HARP  10/16/79			   *
*                                                  *		
****************************************************
*    Commands: 					   *
*                                                  *
*    B Jump to Bootstrap Loader (VG FD)		   *
*    C SSSS FFFF CCCC Compare Blocks 		   *
*    D SSSS FFFF Dump in Hex  			   *
*    E External Communications  		   *
*    F SSSS FFFF DD DD Find Two Bytes 		   *
*    G SSSS - Go to and Execute 		   *		
*    I PP Input from I/O Port			   *
*    J SSSS - Go to and Execute (Jump and Execute) *
*    L Jump to Bootstrap Loader (Tarbell 1011D)	   *
*    M SSSS FFFF DDDD Move Memory Block		   *
*    O PP DD Output to Port 			   *
*    P LLLL Program Memory  			   *
*    Q SSSS FFFF Compute Checksum 		   *
*    S SSSS FFFF DD Search for Single Byte 	   *
*    T SSSS FFFF Test Memory			   *
*    U Jump to Bootstrap Loader (VG FD)		   *
*    V Jump to Bootstrap Loader (VG 8")            *
*    W Jump to Bootstrap Loader (VG HD)  	   *
*    Z Zero or Fill Memory 			   *
*                                                  *
****************************************************
*						   *
*          4.0x2 Modified 25 July 2021             *
*          by Tom Sanderson			   *
*						   *
*						   *
* (1) Added L Jump to Tarbell 1011D Boot Loader    *
*						   *
* (2) Added U Jump to Bootstrap Loader VG FD       *
*						   *
* (3) Added J Go to and Execute (Jump and Execute) *
*						   *
****************************************************
*                                                  *
*          4.0x Modified 1 July 2021               *
*          by Tom Sanderson & Mike Douglas         *
*						   *
*          (1) Added E External Communications	   *
*						   *
*          (2) Corrected string display when using *
*	       a Windows terminal emulator 	   *
*						   *
****************************************************
*						   *
*          4.0C Modified 10 February 1984          *
*          by Tom Sanderson (4.0x)                 *
*						   *
*	   (1) B Command for Boot A  om E80CH	   *
*	       Floppy Bootstrap	using FD/HD	   *
*	       controller and Tandon drives	   *
*						   *
*	   (2) U Command for CP/M TPA at 0100H	   *
*						   *
*	   (3) V Command for Boot A Prom E800H	   *
*	       Dualstor Bootstrap for System	   *
*	       2800 using Qume Data Track 8 	   *
*	       drives and Vector 8" controller     *
*						   *
*	   (4) W Command for Boot A Prom E802H 	   *
*	       Megastor Bootstrap using FD/HD	   *
*	       contraller and 5 1/4 Hard Disk	   *
*						   *
*	   (5) Serial port initialization from	   *
*	       4.3 Version - ZCB at 6 MHz	   *
*						   *
*	   (6) INIT from 4.3 Version for Boot A	   *
*	       prom - Dump latch at E018H and 	   *
*	       clear controller flag DBUSY	   *
*						   *
*	   (7) The following commands were	   *
*	       removed to reduce the prom size	   *
*	       to 1K:				   *
*						   *
*		A ASCII Dump of Memory		   *
*		E External Communications	   *
*		H Jump to Hi Ram at FC00	   *
*		J Jump to DOS			   *
*		K Set a Breakpoint		   *
*		L Jump to Low Ram at 0		   *
*		N Non Destructive Memory Test	   *
*		R Dump Z80 Registers		   *
*		U Jump to User Area		   *
*		X Exchange Block		   *
*		Y Keyboard Echo			   *
*						   *
****************************************************
 
	FORM
*
* System Equates
*
CONS	EQU	3		;Console Status Port
COND	EQU	2		;Console Data Port
SIOS	EQU	5		;Port B Status Port
SIOD	EQU	4		;Port B Data Port
RDA	EQU	2		;Receive Flag
TBE	EQU	1		;Transmit Flag
STPOL	EQU	0		;Status Polarity
DSBOOT	EQU	0E800H		;Dualstor Bootstrap
MSBOOT	EQU	0E802H		;Megastor Bootstrap
FLBOOT	EQU	0E80CH		;Tandon Floppy Bootstrap
TBOOT   EQU	0EC00H		;Tarbell 1011D Bootstrap
DBUSY	EQU	0FF10H		;Controller Busy
*
*
	ORG	BASE
*
* Jump Table Of Entry Points
*
MONIT	JMP	INIT		;Initialize All
KEYTST	JMP	KEYSTAT		;Test Keyboard
KEYDATA	JMP	CONVERT		;Input Keyboard
CRT	JMP	PTCN		;Output To Screen
ESC	JMP	ESCAPE		;Keyboard Input
*
* Table Of Commands For USART
*
INITABLE	DB	0,0,0,40H,0CEH,27H
*
INIT	LXI	SP,SPTR		;Init Stack
	CALL	ESCAPE		;Dump Latch
	XRA	A
	STA	DBUSY		;Clear Controller Flag
*
* Initialize USARTS At Ports 3, 5, 7
*
	MVI	A,3		;Starting Port
	MOV	C,A
INILOOP	MVI	B,6		;No Of Commands
	LXI	H,INITABLE
OUTLOOP	OUTI			;Output A Byte
	XTHL			;Delay For 6 MHz
	XTHL
	JRNZ	OUTLOOP		;Send Next Byte
	INR	C
	INR	C
	DCR	A		;Do 3 Ports In All
	JRNZ	INILOOP
	CALL	ESCAPE
*
* Display Sign On
*
	CALL	SIGN	
*
START:		
	LXI	SP,SPTR	
	CALL	PROMPT	
KEYPOL	CALL	ESCAPE	
	JRZ	KEYPOL
	ANI	5FH
	LXI	H,START	
	PUSH	H
	CPI	'D'-64
	CZ	PTCN	
	CPI	'A'	
	RC
	CPI	5BH
	RNC
	LXI	H,CMDTB+7EH
	PUSH	PSW
	ADD	A
	ADD	L
	MOV	L,A
	MOV	E,M
	INX	H
	MOV	D,M
	XCHG
	POP	PSW
	PCHL
*
* Command Table
*
CMDTB	DW	START	;A
	DW	FLBOOT	;B - Jump to Bootstrap Loader (VG FD)	
	DW	COMPR	;C - SSSS FFFF CCCC Compare Blocks
	DW	HEXRUL	;D - SSSS FFFF Dump in Hex
	DW	EXTCOM	;E - External Communications
	DW	FIND	;F - SSSS FFFF DD DD Find Two Bytes
	DW	EXEC	;G - SSSS - Go to and Execute 
	DW	START	;H
	DW	PINPT	;I - PP Input from I/O Port
	DW	EXEC	;J - Go to and Execute (Jump and Execute)
	DW	START	;K
	DW	TBOOT	;L - Jump to Bootstrap Loader (Tarbell 1011D)
	DW	MOVEB	;M - SSSS FFFF DDDD Move Memory Block
	DW	START	;N
	DW	POUTP	;O - PP DD Output to Port
	DW	PROGRAM	;P - LLLL Program Memory
	DW	CHKSM	;Q - SSSS FFFF Compute Checksum
	DW	START 	;R
	DW	SRCH	;S - SSSS FFFF DD Search for Single Byte
	DW	TMEM	;T - SSSS FFFF Test Memory
	DW	FLBOOT	;U - Jump to Bootstrap Loader (VG FD)
	DW	DSBOOT	;V - Jump to Bootstrap Loader (VG 8")
	DW	MSBOOT	;W - Jump to Bootstrap Loader (VG HD)
	DW	START 	;X
	DW	START	;Y
	DW	ZEROM	;Z - Zero or Fill Memory 
*
*** Execute The Program At The Address ***
*
EXEC	CALL	PTSTNG
	DTH	'Go '
	CALL	AHEX	
	XCHG
	PCHL
*
*** Convert up to 4 Hex digits to bin
*
AHEX:		
	MVI	C,4
AHE0:		
	LXI	H,0
AHE1:		
	CALL	ESCAPE	
	CPI	' '	
	JZ	SPCOVR	
AHE3:		
	CALL	HEX	
	JRC	AHE1	
	DAD	H
	DAD	H
	DAD	H
	DAD	H
	ADD	L
	MOV	L,A
	DCR	C
	JNZ	AHE1	
	XCHG
SPCE:		
	MVI	A,' '	
PTCN:		
	JMP	CONOUT	
CRLF:		
	MVI	A,0DH
	CALL	PTCN	
	MVI	A,0AH
	JR	PTCN	
*
SPCOVR:		
	CALL	PTCN	
	JR	SPCE-1
*
* Check for Hex value, convert
*
HEX:		
	CPI	'0'	
	RC
	CPI	':'	
	JRC	NUM	
	ANI	5FH
	CPI	'A'	
	RC
	CPI	'G'	
	CMC
	RC
NUM:		
	CALL	PTCN	
	SUI	48
	CPI	10
	JRC	ALFA	
	SUI	7
ALFA:		
	ANA	A
	RET
*
* Read 2 digits from the console
*
AHE2:		
	MVI	C,2
	JR	AHE0	
*
* Short routine to save code
*
TAHEX:		
	CALL	AHEX	
	JR	AHEX	
*
*** Read from the console to reg A ***
*
RDCN:		
	CALL	ESCAPE	
	JRZ	RDCN	
	CPI	60H
	JRC	PTCN	
	ANI	5FH
	JR	PTCN	
*
PAUSE:		
	CALL	ESCAPE	
	CPI	20H
	RNZ
PLOOP:		
	CALL	ESCAPE	
	CPI	20H
	JNZ	PLOOP	
	RET
*
ESCAPE:		
	CALL	KEYSTAT	
	RZ
	CALL	CONVERT
	CPI	1BH
	JZ	START	
	RET
*
KEYSTAT:		
	IN	CONS
	ANI	RDA
	RET
*
* Keyboard code conversion
*
CONVERT:		
	IN	COND
	PUSH	H
	PUSH	B
	LXI	B,TABLEND-KTABL/2
	LXI	H,KTABL
LOOP:		
	CCI
	JRZ	FND
	INX	H
	JPE	LOOP
	JR	NFND
FND:		
	MOV	A,M
NFND:		
	ANI	7FH
	POP	B
	POP	H
	RET
*
* This table can be extended if desired
*
KTABL:		
	DD	0
TABLEND	EQU	$
*
* Checksum routine
*
CHKSM:		
	CALL	PTSTNG	
	DTH	'Chksum '
	CALL	TAHEX	
	MVI	B,0
CHKSMLP:		
	MOV	A,M
	ADD	B
	MOV	B,A
	CALL	BMP	
	JRNZ	CHKSMLP	
	MOV	A,B
	JMP	PT2	
*
*** Memory test routine ***
*
TMEM	CALL	PTSTNG	
	DTH	'Test '
	CALL	TAHEX	
	LXI	B,5A5AH
CYCL:		
	CALL	RNDM	
	PUSH	B
	PUSH	H
	PUSH	D
TLOP:		
	CALL	RNDM	
	MOV	M,B
	CALL	BMP	
	JNZ	TLOP	
	POP	D
	POP	H
	POP	B
	PUSH	H
	PUSH	D
RLOP:		
	CALL	RNDM	
	MOV	A,M
	CMP	B
	CNZ	ERR	
	CALL	BMP	
	JNZ	RLOP	
	POP	D
	POP	H
	MVI	A,'.'	
	CALL	PTCN	
	JR	CYCL	
*
*** This routine generates random nos ***
*
RNDM:		
	CALL	PAUSE	
	MOV	A,B
	ANI	0B4H
	ANA	A
	JPE	PEVE	
	STC
PEVE:		
	MOV	A,C
	RAL
	MOV	C,A
	MOV	A,B
	RAL
	MOV	B,A
	RET
*
*** Error print out routine
*
PTAD:		
	CALL	CRLF	
	CALL	PAUSE	
	MOV	A,H
	CALL	PT2	
	MOV	A,L
	JMP	PT2S	
*
ERR:		
	PUSH	PSW
	CALL	PTAD	
	MOV	A,B
	CALL	PT2S	
	POP	PSW
PT2:		
	PUSH	PSW
	CALL	BINH	
	POP	PSW
	JR	BINL	
BINH:		
	RAR
	RAR
	RAR
	RAR
BINL:		
	ANI	0FH
	ADI	48
	CPI	58
	JC	PTCN	
	ADI	7
	JMP	PTCN	
*
* Compare addresses and increment H
*
BMP:		
	MOV	A,E
	SUB	L
	JRNZ	GOON	
	MOV	A,D
	SBB	H
GOON:		
	INX	H
	RET
*
* Zero or fill memory with a constant
*
ZEROM	CALL	PTSTNG
	DTH	'Fill '
	CALL	TAHEX	
	PUSH	H
	CALL	AHE2	
	XCHG
	XTHL
	POP	B
ZLOOP:		
	MOV	M,C
	CALL	BMP	
	RZ
	JR	ZLOOP	
MOVEB:		
	MOV	B,A
	CALL	PTSTNG	
	DTH	'Move '
MOVENTR:		
	CALL	TAHEX	
	PUSH	H
	CALL	AHEX	
	XCHG
	XTHL
MLOOP:		
	MOV	C,M
	XTHL
	MOV	A,B
	CPI	'M'	
	JRZ	NEXCH	
	MOV	A,M
	XTHL
	MOV	M,A
	XTHL
NEXCH:		
	MOV	M,C
	INX	H
	XTHL
	CALL	BMP	
	JZ	START	
	JR	MLOOP	
*
* Compare two blocks of memory
*
COMPR:		
	CALL	PTSTNG	
	DTH	'Comp '
	CALL	TAHEX	
	PUSH	H
	CALL	AHEX	
	XCHG
VMLOP:		
	MOV	A,M
	INX	H
	XTHL
	CMP	M
	MOV	B,M
	CNZ	ERR	
	CALL	BMP	
	XTHL
	JRNZ	VMLOP	
	POP	PSW
	RET
*
* Search for specific codes
*
FIND	PUSH	PSW
	CALL	PTSTNG	
	DTH	'Find '
	JR	SRCHENT
SRCH	PUSH	PSW
	CALL	PTSTNG	
	DTH	'Search '
SRCHENT	CALL	TAHEX	
	PUSH	H
	CALL	AHE2	
	XCHG
	MOV	B,L
	POP	H
	POP	PSW
	CPI	'S'	
	PUSH	PSW
	JRZ	CONT	
	PUSH	H
	CALL	AHE2	
	XCHG
	MOV	C,L
	POP	H
CONT:		
	MOV	A,M
	CMP	B
	JRNZ	SKP	
	POP	PSW
	CPI	'S'	
	PUSH	PSW
	JRZ	OBCP	
	INX	H
	MOV	A,M
	DCX	H
	CMP	C
	JRNZ	SKP	
OBCP:		
	INX	H
	MOV	A,M
	DCX	H
	CALL	ERR	
SKP:		
	CALL	BMP	
	JRNZ	CONT	
	POP	PSW
	RET
*
* Input data from a port
*
PINPT:		
	CALL	PTSTNG	
	DTH	'In '
	CALL	AHE2	
	MOV	C,E
	INP	A
	JMP	PT2	
*
* Output to a port
*
POUTP	CALL	PTSTNG	
	DTH	'Out '
	CALL	AHE2	
	CALL	AHE2	
	MOV	C,L
	OUTP	E
	RET
*
* Additions to 4.0 Monitor
* Print a string
*
RPTSTNG:		
	CALL	CRLF	
PTSTNG:		
	XTHL
	MOV	A,M
	INX	H
	XTHL
	ANA	A
	CALL	PTCN	
	RM
	JR	PTSTNG	
*
* Sign on message
*
SIGN:		
	CALL	CRLF	
	CALL	PTSTNG	
	DT	'Vector Graphic Monitor 4.0x2',0AH
	DD	0A8DH
	CALL	PTSTNG	
	DT	'Copyright 1979'
	DD	0A8AH
	RET
PROMPT:		
	CALL	RPTSTNG	
	DTH	'->'
	RET
WDMP2:		
	MOV	A,M
	ANI	7FH
	CPI	07FH
	JZ	NCNTL-2
	CPI	20H
	JP	NCNTL	
	MVI	A,'.'	
NCNTL:		
	CALL	PTCN	0DCH
	CALL	BMP	
	RZ
	DCR	C
	RM
	JR	WDMP2	
*
* Home cursor, Print "ADDR"
*
HOMEC:		
	CALL	RPTSTNG	
	DTH	'Addr '
	MVI	B,0
	MVI	A,24
	STA	WIDTH	
	RET
*
* Make a ruler for hex dump
*
HEXRULER:		
	MOV	A,B
	CPI	16
	JRZ	HEXRCT	
	CALL	PT2S	
	INR	B
	JR	HEXRULER	
HEXRCT:		
	CALL	SPCE	
	CALL	SPCE	
	MVI	B,0
HEXRLP:		
	MOV	A,B
	CPI	16
	RZ
	ANI	0FH
	CALL	BINL	
	INR	B
	JR	HEXRLP	
*
* Hex dump routine
*
HEXRUL	CALL	PTSTNG	
	DTH	'Dump '
	CALL	TAHEX	
	CALL	HOMEC	
	CALL	HEXRULER	
HLP1:		
	CALL	PTAD	
	PUSH	H
	PUSH	D
	MVI	C,16
HLP2:		
	MOV	A,M
	CALL	PT2S	
	INX	H
	DCR	C
	JNZ	HLP2	
	POP	D
	POP	H
	MVI	C,15
	CALL	SPCE	
	CALL	SPCE	
	CALL	WDMP2	
	JM	HLP1	
	RET
*
* Program Memory
*
PROGRAM	CALL	PTSTNG	
	DTH	'Prog '
	CALL	AHEX	
	SDED	TCURPOS	
	CALL	HOMEC	
	CALL	HEXRULER	
	XRA	A
	STA	WIDTH	
	CALL	PRT1LINE	
	CALL	CRLF	
PGLP:		
	LHLD	TCURPOS	
	MOV	A,M
	CALL	PT2	
	MVI	A,'-'	
	CALL	PTCN	
CRIG:		
	CALL	ESCAPE	
	JRZ	CRIG	
	CPI	' '	
	JRZ	NXTLOC	
	MVI	C,2
	LXI	H,0
	CALL	AHE3	
	LHLD	TCURPOS	
	MOV	M,E
NXTLOC:		
	INX	H
	SHLD	TCURPOS	
	JMPR	PGLP	
*
* Print a line containing ((H))
*
PRT1LINE:		
	LHLD	TCURPOS	
	PUSH	H
	POP	D
	MOV	A,L
	ORI	0FH
	MOV	E,A
	ANI	0F0H
	MOV	L,A
	JMP	HLP1	
*
PT2S:
	CALL	PT2
	JMP	SPCE
*
*EXTERNAL COMMUNICATIONS
*
EXTCOM:
	CALL	PTSTNG
	DTH	'Ext Com '
 
RECEIVE:
	IN	SIOS
	ANI	RDA
	JRZ	NEXCHAR
	IN	SIOD
	CALL	PTCN

NEXCHAR:
	CALL	ESCAPE       
	JRZ	RECEIVE
	OUT	SIOD
	JR	RECEIVE
*
*
CONOUT:
	PUSH	PSW

COLOOP:	IN	CONS
	ANI	TBE
	JRZ	COLOOP

	POP	PSW
	PUSH	PSW
	ANI	7FH		;MSBIT AFFECTS SOME DISPLAY DEVICES
	OUT	COND
	POP	PSW
	RET
*
*
*
* Temporary storage locations for registers, etc.
*
	ORG	SPTR+0EH	;TYPICALLY FFDE
*
WIDTH	DS	1
TCURPOS	DS	2

