	TITLE	"BIOS.MON   HT68K BIOS: MONITOR"
	PAGE
;*******************************************************************
;------ COPYRIGHT 1986 JOSEPH BARTEL
;-------------------------------------------------------------------
;--  PMXMON: PARTITION RESIDENT MONITOR
;-------------------------------------------------------------------
PROMPT	EQU	':'
;-------------------------------------------------------------------
MONITOR
	LEA	BIOS_STACK,A7	;SET STACK POINTER
	MOVE.L	A7,USP
	LEA	BIOS_DATA,A6	;SET VARIABLE BASE REG
	LEA	STACK_4,A4	;SET PSEUDO-HTPL STACK
	LEA	MONMES,A0
	BSR	WRITESTR	;WRITE TO TERMINAL
PRMPT	MOVEQ	#PROMPT,D0
	BSR	WRTCHR
	BSR	RDLINE		;LINE ORIENTED INPUT
	LEA	MONIBUF(A6),A5
	BSR	GETCHR		;GET FIRST CHR FROM LINE
	CMPI.B	#CR,D0		;TEST FOR NULL
	BEQ.S	PRMPT		;IGNORE IF BLANK
	CMPI.B	#'L',D0		;--- LOAD ---
	BNE.S	MAN010
	BSR	LOAD
	BRA.S	PRMPT
MAN010	CMPI.B	#'G',D0		;--- GO ---
	BNE.S	MAN020
	BSR	GTADRS
	MOVEA.L	D1,A0
	JMP	(A0)
MAN020	CMPI.B	#'D',D0		;--- DISPLAY ---
	BNE.S	MAN030
	BSR	DSPMEM
	BRA.S	PRMPT
MAN030	CMPI.B	#'E',D0		;--- EXAMINE ---
	BNE.S	MAN040
	BSR	EXAMIN
	BRA.S	PRMPT
MAN040	CMPI.B	#'F',D0		;--- FILL ---
	BNE.S	MAN050
	BSR	FILLIT
	BRA.S	PRMPT
MAN050	CMPI.B	#'M',D0		;--- MOVE MEMORY ---
	BNE.S	MAN060
	BSR	MOVIT
	BRA.S	PRMPT
MAN060	CMPI.B	#'X',D0		;--- EXAMINE LONG ---
	BNE.S	MAN070
	BSR	EXMLNG
	BRA.S	PRMPT
MAN070	CMPI.B	#'B',D0		;--- LOAD BINARY FILE FROM DISK ---
	BNE.S	MAN080
	BSR	FILOAD
	BRA.S	PRMPT
MAN080	CMPI.B	#'S',D0		;--- SYSTEM BOOT ---
	BNE.S	MAN090
	JMP	SYSTEM
MAN090	CMPI.B	#'P',D0		;--- POKE ---
	BNE.S	MAN100
	BSR	POKE
	BRA	PRMPT
MAN100	CMPI.B	#'K',D0		;--- PEEK ---
	BNE.S	MAN110
	BSR	PEEK
	BRA	PRMPT
MAN110	CMPI.B	#'R',D0		;--- READ RECORD FROM DISK ---
	BNE.S	MAN120
	BSR	READREC
	BRA	PRMPT
MAN120	CMPI.B	#'W',D0		;--- WRITE RECORD TO DISK ---
	BNE.S	MAN130
	BSR	WRITREC
	BRA	PRMPT
MAN130	CMPI.B	#'C',D0		;--- COMPARE MEMORY ---
	BNE.S	MAN140
	BSR	COMPARE
	BRA	PRMPT
MAN140	BSR	ERROR		;--- FALL INTO ERROR ---
	BRA	PRMPT		;TRY AGAIN
;----------- READ A LINE FROM THE TERMINAL AND STOP ON CR
;	ECHO CHRS, DO BS AND LINE DELETE
RDLINE	LEA	MONIBUF(A6),A0	;CHAR POINTER
	CLR.L	D4		;CHAR COUNTER
RDL010	BSR	RDCHAR		;GET NEXT CHAR
	CMPI.B	#CR,D0
	BNE.S	RDL020		;IF CR, DONE
	MOVE.B	D0,(A0)+	;PUT IN BUFFER
	BSR	WRTCHR		;ECHO IT
	MOVEQ	#LF,D0		;LINE FEED ALSO
	BSR	WRTCHR
	RTS
RDL020	CMPI.B	#BS,D0		;SEE IF BACK SPACE
	BNE.S	RDL030
	TST.L	D4		;CHECK FOR EMPTY BUFFER
	BEQ.S	RDL010		;IF EMPTY, IGNORE
	MOVEQ	#BS,D0		;ECHO IT
	BSR	WRTCHR
	SUBQ.L	#1,D4		;DEC CHR COUNTER
	SUBQ.L	#1,A0		;AND POINTER
	MOVEQ	#SPACE,D0	;WIPE WITH SPACE
	BSR	WRTCHR
	MOVEQ	#BS,D0		;AND BACK IN PLACE
	BSR	WRTCHR
	BRA.S	RDL010		;GO FOR NEXT
RDL030	CMPI.B	#CAN,D0		;CHECK DELETE LINE
	BNE.S	RDL050
	MOVEQ	#CR,D0		;RETURN LINE
	BSR	WRTCHR
RDL040	TST.L	D4		;CHECK EMPTY BUFFER
	BEQ.S	RDL045		;IF EMPTY, DONE
	MOVEQ	#SPACE,D0	;SEND SPACES TO BLANK LINE
	BSR	WRTCHR
	SUBQ.L	#1,D4
	SUBQ.L	#1,A0
	BRA.S	RDL040
RDL045	MOVEQ	#SPACE,D0	;ZAP PROMPT ALSO
	BSR	WRTCHR
	MOVEQ	#CR,D0		;RETURN CURSOR
	BSR	WRTCHR
	MOVEQ	#PROMPT,D0	;REDO PROMPT
	BSR	WRTCHR
	BRA.S	RDL010
RDL050	MOVE.B	D0,(A0)+	;NOTHIN SPECIAL
	ADDQ.L	#1,D4
	BSR	WRTCHR		;ECHO IT
	BRA	RDL010		;PROCESS NEXT CHAR
;------ GET NEXT CHAR FROM THE INPUT BUFFER
GETCHR	CLR.L	D0		;CLEAR WHOLE REG
	MOVE.B	(A5),D0		;GET CHAR
	CMPI.B	#CR,D0		;SEE IF EOL
	BEQ.S	GET010		;IF SO, DONT INC PNTR
	ADDQ.L	#1,A5
GET010	RTS
;----- GET CHAR FROM TERMINAL #3
RDCHAR	MOVEM.L	#4140H,-(SP)
	BSR	GETCON		;GET CHAR  (MODIFIED:A4,A1,D7,D1)
	MOVEM.L	(SP)+,#0282H
	MOVE.L	(A4)+,D0
	ANDI.L	#7FH,D0		;MASK UNUSED BITS
	RTS
;----- SEND OUT CHAR TO TERMINAL #3
WRTCHR	MOVE.L	D0,-(A4)
	MOVEM.L	#0C060H,-(SP)
	BSR	PUTCON		;PUT CHAR  (MODIFIED:A4,A2,A1,D1,D0)
	MOVEM.L	(SP)+,#0603H
	RTS
;------ GET CHAR FROM TERMINAL #4
RDCHR4	MOVEM.L	#4140H,-(SP)	;SAVE A1,D7,D1
	BSR	GETAUX		;GET CHAR  (MODIFIED:A4,A1,D7,D1)
	MOVEM.L	(SP)+,#0282H	;RESTORE A1,D7,D1
	MOVE.L	(A4)+,D0
	ANDI.L	#7FH,D0		;MASK UNUSED BITS
	RTS
;------ SEND CHAR TO TERMINAL #4
WRTCH4	MOVE.L	D0,-(A4)
	MOVEM.L	#0C060H,-(SP)	;SAVE A2,A1,D1,D0
	BSR	PUTAUX		;PUT CHAR  (MODIFIED:A4,A2,A1,D1,D0)
	MOVEM.L	(SP)+,#0603H	;RESTORE A2,A1,D1,D0
	RTS
;------ SIMPLE ERROR HANDLER
ERROR	LEA	ERRMES,A0
	BSR	WRITESTR
	RTS
;---- GET VARIABLE LENGTH ADDRESS FROM INPUT BUFFER
GTADRS	CLR.L	D1		;START WITH 0
GTA010	BSR	GETCHR		;GET NEXT LINE CHAR
	CMPI.B	#SPACE,D0	;SKIP SPACES
	BEQ.S	GTA010
GTA020	CMPI.B	#'0',D0		;RET IF < '0'
	BLO.S	GTA999
	CMPI.B	#'9',D0		;SEE IF NUMBER
	BLS.S	GTA030
	CMPI.B	#'A',D0		;RET IF >9 & <A
	BLO.S	GTA999
	CMPI.B	#'F',D0		;RET IF > F
	BHI.S	GTA999
GTA030	LSL.L	#4,D1		;SHIFT HL LEFT 4
	BSR	A2HEX		;CONVERT CHAR TO BIN
	ADD.L	D0,D1		;ADD TO LOW
	BSR	GETCHR		;GET NEXT
	BRA.S	GTA020		;AND PROCESS IT
GTA999	RTS
;------ GET NAME FROM INPUT BUFFER
GTNAME	LEA	MONOBUF(A6),A0
	MOVEA.L	A0,A1
	MOVE.L	#20202020H,(A1)+	;11 SPACES, BUNCH OF NULLS
	MOVE.L	#20202020H,(A1)+
	MOVE.L	#20202000H,(A1)+
	MOVEQ	#10,D0
GTN000	CLR.L	(A1)+
	DBRA	D0,GTN000
	MOVEA.L	A0,A1
GTN010	BSR	GETCHR		;SKIP LEADING SPACES
	CMPI.B	#SPACE,D0
	BEQ.S	GTN010
GTN020	CMPI.B	#CR,D0		;WHILE NOT END_OF_LINE OR TRAILING SPACE
	BEQ.S	GTN050
	CMPI.B	#SPACE,D0
	BEQ.S	GTN050
	CMPI.B	#'.',D0		;  IF DOT
	BNE.S	GTN030
	MOVEA.L	A0,A1		;    THEN SKIP TO EXTENSION FIELD
	ADDQ.L	#8,A1
	BRA.S	GTN040
GTN030	MOVE.B	D0,(A1)+	;    ELSE SAVE CHAR
GTN040	BSR	GETCHR		;  GET NEXT CHAR IN NAME
	BRA.S	GTN020		;ENDWHILE
GTN050	RTS
;------ CONVERT ONE ASCII CHAR TO BIN
A2HEX	ANDI.L	#$7F,D0		;GET RID OF JUNK
	SUBI.B	#'0',D0		;REMOVE ASCII OFFSET
	CMPI.B	#10,D0
	BLT.S	A2HEXS		;DONE IF DIGIT
	SUBQ.B	#7,D0		;REMOVE ALPHA OFFSET
A2HEXS	RTS
;---- EXAMINE AND CHANGE A MEMORY LOCATION
;---- EXIT ON '.', EXAM NEXT W/O CHANGE IF CR
EXAMIN	BSR	GTADRS		;GET ADRS TO EXAMINE
	ANDI.W	#0FFFEH,D1	;MAKE IT EVEN
	MOVEA.L	D1,A1		;MOVE TO ADDRESS REG
EXA010	MOVE.L	A1,D1		;GET THIS ADDRESS
	MOVE.L	D1,-(A4)
	BSR	HEX4BYTE	;DISPLAY IT
	MOVEQ	#SPACE,D0	;SKIP A SPACE
	BSR	WRTCHR
	MOVE.W	(A1),D1		;GET WORD OF MEM
	MOVE.L	D1,-(A4)
	BSR	HEX2BYTE	;DISPLAY IT
	MOVEQ	#SPACE,D0	;SKIP ANOTHER SPACE
	BSR	WRTCHR
	BSR	RDCHAR		;GET A CMD CHAR
	BSR	WRTCHR		;ECHO IT
	CMPI.B	#'.',D0		;CHECK EXIT
	BNE.S	EXA020
	MOVEQ	#CR,D0		;SEND CRLF
	BSR	WRTCHR
	MOVEQ	#LF,D0
	BSR	WRTCHR
	RTS			;GET NEXT COMMAND
EXA020	CMPI.B	#SPACE,D0	;CHECK SPACE
	BEQ.S	EXA030		;IF SO, EXAM NEXT
	CMPI.B	#CR,D0		;DITO FOR CR
	BEQ.S	EXA030
	CMPI.B	#LF,D0		;ALSO LF
	BEQ.S	EXA030
	CMPI.B	#CAN,D0		;EXAM SAME
	BEQ.S	EXA040
	CMPI.B	#'-',D0		;BACK UP
	BNE.S	EXA025
	SUBQ.L	#2,A1
	BRA.S	EXA040
EXA025	MOVEQ	#3,D3		;ASSUME CHANGE
	BSR	GETLNG
	TST.B	D4		;TEST REPLACE FLAG
	BEQ	EXA040
	MOVE.W	D1,(A1)		;PUT IN MEM
EXA030	ADDQ.L	#2,A1		;POINT TO NEXT
EXA040	MOVEQ	#CR,D0
	BSR	WRTCHR
	MOVEQ	#LF,D0
	BSR	WRTCHR
	BRA	EXA010
;---- EXAMINE AND CHANGE A LONG MEMORY LOCATION
;---- EXIT ON '.', EXAM NEXT W/O CHANGE IF CR
EXMLNG	BSR	GTADRS		;GET ADRS TO EXAMINE
	ANDI.W	#0FFFEH,D1	;MAKE IT EVEN
	MOVEA.L	D1,A1		;MOVE TO ADDRESS REG
EXM100	MOVE.L	A1,D1		;GET THIS ADDRESS
	MOVE.L	D1,-(A4)
	BSR	HEX4BYTE	;DISPLAY 4 BYTES WORTH
	MOVEQ	#SPACE,D0	;SKIP A SPACE
	BSR	WRTCHR
	MOVE.W	(A1),D1		;GET WORD OF MEM
	MOVE.L	D1,-(A4)
	BSR	HEX2BYTE
	MOVEQ	#SPACE,D0	;SKIP ANOTHER SPACE
	BSR	WRTCHR
	MOVE.W	2(A1),D1	;GET NEXT WORD
	MOVE.L	D1,-(A4)
	BSR	HEX2BYTE
	MOVEQ	#SPACE,D0	;SKIP ANOTHER SPACE
	BSR	WRTCHR
	BSR	RDCHAR		;GET A CMD CHAR
	BSR	WRTCHR		;ECHO IT
	CMPI.B	#'.',D0		;CHECK EXIT
	BNE.S	EXM200
	MOVEQ	#CR,D0		;SEND CRLF
	BSR	WRTCHR
	MOVEQ	#LF,D0
	BSR	WRTCHR
	RTS			;GET NEXT COMMAND
EXM200	CMPI.B	#SPACE,D0	;CHECK SPACE
	BEQ	EXM300		;IF SO, EXAM NEXT
	CMPI.B	#CR,D0		;DITO FOR CR
	BEQ	EXM300
	CMPI.B	#LF,D0		;ALSO LF
	BEQ	EXM300
	CMPI.B	#CAN,D0		;EXAM SAME
	BEQ	EXM310
	CMPI.B	#'-',D0		;BACK UP
	BNE.S	EXM220
	SUBQ.L	#4,A1
	BRA	EXM310
EXM220	MOVEQ	#7,D3		;ASSUME CHANGE
	BSR	GETLNG		;GET LONG REPLACEMENT
	TST.B	D4		;CHECK NO REPLACE FLAG
	BEQ	EXM310
	MOVE.L	D1,(A1)		;PUT IN MEM
EXM300	ADDQ.L	#4,A1		;POINT TO NEXT
EXM310	MOVEQ	#CR,D0
	BSR	WRTCHR
	MOVEQ	#LF,D0
	BSR	WRTCHR
	BRA	EXM100
;----- GET REPLACEMENT FOR E OR X
GETLNG	MOVEQ	#$FF,D4		;SET REPLACE FLAG
	BSR	A2HEX		;CONVERT FIRST CHAR
	MOVE.L	D0,D1
GET100	BSR	RDCHAR		;GET NEXT CHAR
	CMPI.B	#CAN,D0		;CHECK FOR EXIT
	BEQ	GET200
	CMPI.B	#CR,D0		;CHECK FOR SHORT
	BEQ	GET150		;EARLY EXIT
	BSR	WRTCHR		;ECHO IT
	BSR	A2HEX		;CONVERT IT
	LSL.L	#4,D1		;MAKE ROOM FOR IT
	OR.B	D0,D1		;PUT IN NEW
	SUBQ.W	#1,D3		;SEE IF DONE
	BNE	GET100		;GO FOR MORE
GET150	RTS			;GO HOME
GET200	CLR.L	D4		;FLAG FOR NO REPLACE
	RTS
;----- POKE BYTE INTO MEMORY
POKE	BSR	GTADRS		;GET POKE LOCATION
	MOVE.L	D1,-(SP)
	BSR	GTADRS		;GET DATA
	MOVEA.L	(SP)+,A0
	MOVE.B	D1,(A0)		;SAVE BYTE
	RTS
;----- PEEK AT BYTE IN MEMORY
PEEK	BSR	GTADRS		;GET PEEK LOCATION
	MOVEA.L	D1,A0
	MOVE.B	(A0),D0		;GET DATA
	MOVE.L	D0,-(A4)
	BSR	HEXBYTE		;DISPLAY DATA
	MOVEQ	#CR,D0
	BSR	WRTCHR
	MOVEQ	#LF,D0
	BSR	WRTCHR
	RTS
;----- CONVERT D1.B TO ASCII AND DISPLAY IT
DSPHEX	BSR	BINHEX
	MOVE.L	D1,D0
	LSR.L	#8,D0
	BSR	WRTCHR
	MOVE.B	D1,D0
	BSR	WRTCHR
	RTS
;----- CONVERT BINARY D1.B TO ASCII
;    MSD IN D, LSD IN E
BINHEX	MOVE.W	D1,D0		;SAVE VALUE
	LSR.L	#4,D1		;RIGHT 4 TIME FOR HIGH
	BSR	BIN010		;CONVERT
	EXG	D0,D1		;GET VALUE BACK
	BSR	BIN010		;CONVERT LOW
	LSL.L	#8,D0
	OR.W	D0,D1
	RTS
BIN010	ANDI.L	#0FH,D1		;MASK IT
	CMPI.W	#10,D1		;SEE IF NUMBER
	BLT.S	BIN020
	ADDQ.W	#7,D1		;ALPHA OFFSET NEEDED
BIN020	ADD.W	#'0',D1		;ASCII OFFSET
	RTS
;------- DISPLAY HEX CHARACTERS
HEX4BYTE MOVE.L	(A4),D0
	SWAP	D0
	MOVE.L	D0,-(A4)
	BSR	HEX2BYTE
;------- 2 BYTES
HEX2BYTE MOVE.L	(A4),D0
	LSR.L	#8,D0
	MOVE.L	D0,-(A4)
	BSR	HEXBYTE
;------ 1 BYTE
HEXBYTE	MOVE.L	(A4),D0
	LSR.L	#4,D0
	MOVE.L	D0,-(A4)
	BSR	HEXCHR		;CALL THEN FALL INTO
;------ ONE HEX CHAR
HEXCHR	MOVE.L	(A4)+,D0
	ANDI.W	#$000F,D0
	CMPI.W	#10,D0
	BLT.S	HEXC00
	ADDQ.W	#7,D0
HEXC00	ADD.W	#'0',D0
	BSR	WRTCHR
	RTS	
;----- LOAD AN INTEL HEX FILE FROM TERMINAL
LOAD	BSR	GTADRS		;GET BIAS ADDRESS
	MOVEA.L	D1,A5
LOA005	BSR	RDCHR4		;GET AND ECHO CHAR
	BSR	WRTCH4
	CMPI.B	#':',D0		;CHECK FOR LEAD IN
	BNE.S	LOA005
	CLR.L	D1
	BSR	RDCHR4		;FIRST DIG OF COUNT
	BSR	WRTCH4
	BSR	A2HEX
	LSL.L	#4,D1
	ADD.L	D0,D1
	BSR	RDCHR4		;SECOND DIGIT OF COUNT
	BSR	WRTCH4
	BSR	A2HEX
	LSL.L	#4,D1
	ADD.L	D0,D1		;DONE IF ZERO
	BNE.S	LOA010
	LEA	LDMES,A0	;ANNOUNCE LOAD COMPLETE
	BSR	WRITESTR
	RTS
LOA010	MOVE.W	D1,D3		;SAVE BYTE COUNT
	CLR.L	D1		;START ADDRESS AT 0
	BSR	RDCHR4
	BSR	WRTCH4
	BSR	A2HEX		;FIRST CHAR OF ADRESS
	LSL.L	#4,D1
	ADD.L	D0,D1
	BSR	RDCHR4
	BSR	WRTCH4
	BSR	A2HEX		;SECOND CHAR OF ADRESS
	LSL.L	#4,D1
	ADD.L	D0,D1
	BSR	RDCHR4
	BSR	WRTCH4
	BSR	A2HEX		;THIRD CHAR OF ADRESS
	LSL.L	#4,D1
	ADD.L	D0,D1
	BSR	RDCHR4
	BSR	WRTCH4
	BSR	A2HEX		;FOURTH CHAR OF ADRESS
	LSL.L	#4,D1
	ADD.L	D0,D1
	MOVEA.L	D1,A3		;SAVE ADRS
	ADDA.L	A5,A3		;ADD BIAS VALUE
	BSR	RDCHR4		;SKIP FILE TYPE, 2 CHRS
	BSR	WRTCH4
	BSR	RDCHR4
	BSR	WRTCH4
LOA020	BSR	RDCHR4		;GET DATA MSD
	BSR	WRTCH4
	BSR	A2HEX
	LSL.L	#4,D1
	ADD.L	D0,D1
	BSR	RDCHR4		;GET DATA LSD
	BSR	WRTCH4
	BSR	A2HEX
	LSL.L	#4,D1
	ADD.L	D0,D1
	MOVE.B	D1,(A3)+	;STORE IT
	DBRA	D3,LOA020	;GO FOR NEXT
	BRA	LOA005		;GET NEXT RECORD
;------ DISPLAY MEMORY IN 16 BYTE BLOCKS
DSPMEM	BSR	GTADRS		;GET START ADDRESS
	AND.W	#0FFF0H,D1	;ROUND IT DOWN
	MOVE.L	D1,D5		;SAVE IT
	BSR	GTADRS		;GET END ADRESS
	ADD.L	#0FH,D1		;ROUND IT UP
	AND.W	#0FFF0H,D1	;FIX IT
	MOVE.L	D1,D4		;SAVE IT
DSP010	LEA	MONOBUF(A6),A1	;CREATE BUFFER POINTER
	MOVE.L	D5,D1		;GET START ADDRESS
	LSR.L	#8,D1
	LSR.L	#8,D1
	LSR.L	#8,D1
	BSR	BINHEX		;CONVERT FOR BUFFER
	MOVE.W	D1,(A1)+	;PUT IN BUFFER
	MOVE.L	D5,D1
	LSR.L	#8,D1
	LSR.L	#8,D1
	BSR	BINHEX
	MOVE.W	D1,(A1)+	;PUT IN BUFFER
	MOVE.L	D5,D1
	LSR.L	#8,D1
	BSR	BINHEX
	MOVE.W	D1,(A1)+	;PUT IN BUFFER
	MOVE.L	D5,D1
	BSR	BINHEX		;LOW BUFFER ADRS
	MOVE.W	D1,(A1)+	;PUT IN BUFFER
	MOVE.W	#2020H,(A1)+	;SKIP 2 SPACES
	MOVEA.L	D5,A0
	MOVEQ	#7,D3		;8 GROUPS OF 2 BYTES
DSP020	MOVE.B	(A0)+,D1	;GET FIRST BYTE
	BSR	BINHEX		;CONVERT IT
	ROL.W	#8,D1
	MOVE.B	D1,(A1)+
	ROL.W	#8,D1
	MOVE.B	D1,(A1)+
	MOVE.B	(A0)+,D1	;GET SECOND BYTE
	BSR	BINHEX		;CONVERT IT
	ROL.W	#8,D1
	MOVE.B	D1,(A1)+
	ROL.W	#8,D1
	MOVE.B	D1,(A1)+
	MOVE.B	#SPACE,(A1)+	;SKIP ONE SPACE
	DBRA	D3,DSP020	;LOOP (8)
	MOVE.B	#SPACE,(A1)+	;SKIP ONE SPACE
	MOVEA.L	D5,A0		;GET START ADDRESS
	MOVEQ	#15,D3		;ONE GROUP OF 16 CHARS	
DSP030	MOVE.B	(A0)+,D0	;GET BYTE
	CMPI.B	#SPACE,D0	;SEE IF < SPACE
	BLO.S	DSP040
	CMPI.B	#07BH,D0	;SEE IF TOO BIG
	BHI.S	DSP040
	MOVE.B	D0,(A1)+	;ITS PRINTABLE
	BRA.S	DSP050
DSP040	MOVE.B	#'.',(A1)+	;NOT PRINTABLE, USE '.'
DSP050	DBRA	D3,DSP030	;LOOP
	MOVE.B	#CR,(A1)+
	MOVE.B	#LF,(A1)+
	MOVE.B	#0,(A1)+	;NULL IS END OF STRING
	LEA	MONOBUF(A6),A0	;WRITE IT
	BSR	WRITESTR
	ADDI.L	#010H,D5
	CMP.L	D4,D5		;(ENADRS,STADRS)
	BLS	DSP010		;GO AGAIN
	RTS
;---- FILL MEMORY WITH BYTE
FILLIT	BSR	GTADRS		;GET START
	MOVEA.L	D1,A0
	BSR	GTADRS		;GET FINISH
	MOVE.L	D1,D2		;COMPUTE SIZE
	SUB.L	A0,D2
	BSR	GTADRS		;GET BYTE
FIL020	MOVE.B	D1,(A0)+	;PUT AND POINT
	DBRA	D2,FIL020
	RTS
;---- MOVE REGION OF MEMORY
MOVIT	BSR	GTADRS		;GET START
	MOVEA.L	D1,A0
	BSR	GTADRS		;GET FINISH
	MOVE.L	D1,D2		;COUNT SIZE
	SUB.L	A0,D2
	BSR	GTADRS		;GET DESTINATION
	MOVEA.L	D1,A1
MOV020	MOVE.B	(A0)+,(A1)+	;MOVE A BYTE
	DBRA	D2,MOV020
	RTS
;---- COMPARE TWO REGIONS OF MEMORY
COMPARE	BSR	GTADRS		;GET START
	MOVEA.L	D1,A0
	BSR	GTADRS		;GET FINISH
	MOVE.L	D1,D2		;COUNT SIZE
	SUB.L	A0,D2
	BSR	GTADRS		;GET START OF SECOND BLOCK
	MOVEA.L	D1,A1
COM020	CMPM.B	(A0)+,(A1)+	;COMPARE A BYTE
	DBNE	D2,COM020
	BNE.S	COM040
	LEA	EQMES,A0	;MEMORY EQUAL
	BSR	WRITESTR
	RTS
COM040	SUBQ.L	#1,A0
	SUBQ.L	#1,A1
	MOVE.L	A0,-(A4)
	BSR	HEX4BYTE	;WRITE FIRST ADDRESS
	MOVEQ	#SPACE,D0
	BSR	WRTCHR
	MOVE.B	(A0),D0
	MOVE.L	D0,-(A4)
	BSR	HEXBYTE		;WRITE FIRST DATA
	MOVEQ	#SPACE,D0
	BSR	WRTCHR
	MOVE.L	A1,-(A4)
	BSR	HEX4BYTE	;WRITE SECOND ADDRESS
	MOVEQ	#SPACE,D0
	BSR	WRTCHR
	MOVE.B	(A1),D0
	MOVE.L	D0,-(A4)
	BSR	HEXBYTE		;WRITE SECOND DATA
	MOVEQ	#SPACE,D0
	BSR	WRTCHR
	LEA	NEMES,A0	;MEMORY NOT EQUAL
	BSR	WRITESTR
	RTS
;---- LOAD BINARY FILE FROM DISK ---------
FILOAD	BSR	GTNAME		;GET FILENAME
	MOVE.L	A0,FNAMPN(A6)
	BSR	GTADRS		;GET LOAD ADDRESS
	MOVE.L	D1,LOADPN(A6)
	BSR	LOADFAT		;LOAD FAT TABLE
	TST.B	DSKERR(A6)	;IF READ ERROR
	BEQ.S	FLD010
	LEA	DKMES,A0	;  THEN DISK ERROR MESSAGE
	BRA.S	FLD040
FLD010	BSR	FINDFIL		;ELSE LOOK FOR FILE IN ROOT DIRECTORY
	BEQ.S	FLD020		;IF NOT FOUND THEN
	LEA	NFMES,A0	;  NOT FOUND MESSAGE
	TST.B	DSKERR(A6)	;  IF READ ERROR
	BEQ.S	FLD040
	LEA	DKMES,A0	;    THEN DISK ERROR MESSAGE
	BRA.S	FLD040
FLD020	BSR	LOADFIL		;ELSE LOAD FILE
	TST.B	DSKERR(A6)	;IF READ ERROR
	BEQ.S	FLD030
	LEA	DKMES,A0	;  THEN DISK ERROR MESSAGE
	BRA.S	FLD040
FLD030	LEA	LDMES,A0	;ELSE NICE MESSAGE
FLD040	BSR	WRITESTR
	RTS
;---- READ RECORD FROM DISK -----------
READREC	BSR	GTADRS		;GET RECORD NUMBER
	MOVE.L	D1,-(A4)
	BSR	GTADRS		;GET BUFFER ADDRESS
	MOVE.L	D1,-(A4)
	BSR	DSKREAD1	;READ RECORD TO BUFFER
	MOVE.L	(A4)+,D0
	TST.B	D0		;IF READ ERROR
	BEQ.S	RRC010
	LEA	DKMES,A0	;  THEN DISK ERROR MESSAGE
	BSR	WRITESTR
RRC010	RTS
;---- WRITE RECORD TO DISK -----------
WRITREC	BSR	GTADRS		;GET RECORD NUMBER
	MOVE.L	D1,-(A4)
	BSR	GTADRS		;GET BUFFER ADDRESS
	MOVE.L	D1,-(A4)
	BSR	DSKWRITE1	;WRITE BUFFER TO RECORD
	MOVE.L	(A4)+,D0
	TST.B	D0		;IF WRITE ERROR
	BEQ.S	WRC010
	LEA	DKMES,A0	;  THEN DISK ERROR MESSAGE
	BSR	WRITESTR
WRC010	RTS

	END	;BIOS.MON
