*
* :*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*
*
* 68000 Monitor, Version 2.0, April 1989
* based on standard 8088 monitor Version 2.2;
* Login via main RS232 port;
* Link/load to network or auxiliary RS232 port;
*
* :*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*
*
*
ICPAK	equ $40		* Incoming packet bit
NBUSY	equ $02		* NOT Busy bit
BUSY	equ $0fd		* Busy bit
NTXREQ	equ $01		* NOT Transmit Request bit
TXREQ	equ $0fe		* Transmit Request bit
PAKSNT	equ $80		* Packet sent bit
ICPAKN  equ 6		* Bit no of incoming packet
PKSNTN  equ 7		* bit no of packet sent
*
CHARPK	equ $0ff		* Control field for character packet
ACKPK	equ $0f6   		* Control field for acknowledgement packet
ECHOPK	equ $0f4		* Control field for echoing acknowledgement packet
CHSUPK	equ $0ef		* Control field for connect request packet
*
CONNCT	equ $01		* CONNECT
ACCEPT	equ $02		* ACCEPT Pattern
DISCON	equ $10		* DISCONNECT
*
TOcnt	equ $200		* Tx Timeout value
ACKcnt	equ $1000		* Acknowledgement timeout value
ACCcnt	equ $1000		* Accept timeout value
*
* :*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*
*
* Store Locations
*
* :*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*
*
	org $011000
*
remadd:	ds.w 1
newadd:	ds.w 1
remflg:	ds.w 1
*
ipksa:	ds.w 1	* Incoming packet, Source Address
ipkda:	ds.w 1	* Destination address
ipkd3:	ds.w 1	* (msw) data
ipkd1:	ds.w 1	* (lsw) data
ipkct:	ds.w 1	* control field
*
opksa:	ds.w 1	* Outgoing packet, Source Address
opkda:	ds.w 1	* Destination Address
opkd3:	ds.w 1	* (msw) data
opkd1:	ds.w 1	* (lsw) data
opkct:	ds.w 1	* control field
*
cntflg:	ds.w 1	* copy of current pacnt O/P field
pakflg:	ds.w 1	* packet available flag
trccnt:	ds.w 1	* no of instructions to trace
brkflg:	ds.w 1	* breakpoint set flag
brksav:	ds.w 1	* instruction word from brkpt addr
brkadd:	ds.l 1	* breakpoint address
lnkflg:	ds.w 1	* indicates whether link is to network or RS232
*	
* :*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*
*
* 68000 Monitor, Version 2, March 1989 
*
* :*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*
*
romsize equ $010000
rombot  equ $000000
romtop  equ $00FFFF

ramsize equ $010000        * was 020000
rambot  equ $010000
ramtop  equ $01FFFF        * was 03ffff

* FIFO register addresses
fifo    equ $060000

* filter addresses
*dlbar   equ $050001
*dgbar   equ $050000
*slbar   equ $050003
*sgbar   equ $050002
*contr   equ $050005


* DUART register addresses
base    equ $020001        * was 040001
modea   equ base+0
stata   equ base+2
clka    equ base+2
cmda    equ base+4
thra    equ base+6
rhra    equ base+6
ipcr    equ base+8
acr     equ base+8
isr     equ base+10
imr     equ base+10
countl  equ base+12
counth  equ base+14
modeb   equ base+16
statb   equ base+18
clkb    equ base+18
cmdb    equ base+20
rhrb    equ base+22
thrb    equ base+22
ivr     equ base+24
iport   equ base+26
opcr    equ base+26
stcnt   equ base+28
spcnt   equ base+30
bitset  equ base+28
bitres  equ base+30



* mode reg 1

rxrts   equ $80
norrts  equ $0

rirdy   equ $0
rifful  equ $40

cerr    equ $0
blerr   equ $20

wthpar  equ $0
forcep  equ $8
nopar   equ $10
multi   equ $18

evenp   equ $0
oddp    equ $4

bits5   equ $0
bits6   equ $1
bits7   equ $2
bits8   equ $3

* mode reg 2 

norop  equ $0
echo    equ $40
lloop   equ $80
rloop   equ $C0

txrts   equ $20
notrts  equ $0

cts     equ $10
nocts   equ $0

stop1   equ $7
stop2   equ $f

* clk sel reg

b9600   equ $bb

* Command REG
* Miscell

nocmd   equ $0
point1  equ $10
rstrx   equ $20
rsttx   equ $30
rsterr  equ $40
rstint  equ $50
brkon   equ $60
brkoff  equ $70

* transmitter

tnoop   equ $0
ten     equ $4
tdis    equ $8

* receiver

rnoop   equ $0
ren     equ $1
rdis    equ $2

* interupts
noints  equ $0

* output config
allout  equ $0

* status register bits

break   equ $80
frame   equ $40
parity  equ $20
overrun equ $10
txempty equ $8
txready equ $4
ffull equ $2
rxready equ $1

* Derived memory addresses
vecsize equ $200
stack   equ ramtop-vecsize-1

*
null	equ $00
cr	equ $0d
lf	equ $0a
space	equ $20
bell	equ $07
tab	equ $09
*
netbrk	equ $1c		* Control-\
*
* :*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*
*
	org $000400
*
* :*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*
*
* *** ENTRY POINTS ***
*
* :*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*
*
normal: bra lprom	* goto prompt start
coldst: bra main	* goto restart
*
* :*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*
*
* Useful routines
*
* :*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*
*
* INCHR: inputs a character from port 1
*        returns with carry set if not available
*
inchr:	btst #0,stata	* Rx ready?
	beq inchr1	* no, return with carry
nchr:   move.b   rhra,d0	* get char
        btst.b #0,stata
        bne  nchr
	and.b #$0fe,ccr	* clear carry no error
	rts		* return
inchr1:	or.b #$01,ccr		* set carry
	rts		* return
*
* INCH: inputs a character from port 1
*	no echo, char in D0
*
inch:	jsr inchr	* get character
	bcs inch		* if not available, try again
	rts		* return
*
* INCHR2: as INCH for port 2
*
inchr2:	btst #0,statb_* Rx ready?
	beq inch21	* no, return with carry
ichr2: 	move.b rhrb,d0	* get data
       btst.b #0,statb
       bne ichr2
	and.b #$0fe,ccr	* clear carry no error
	rts
inch21:	or.b #$01,ccr	* error - set carry
	rts
*
* INCH2: as INCH for port 2
*
inch2:	jsr inchr2	* try for char
	bcs inch2	* loop if no char available
	rts
*
* INCHU: inputs a character to D0, [a-z] converted to [A-Z]
*	 <LF> converted to <CR>, no echo, uses INCH, register D0 used
*
inchu:	jsr inch	* get a character
	cmp.b #$61,d0	* is it less than "a"?
	blt inchu1	* yes, continue
	cmp.b #$7a,d0	* is it greater than "z"?
	bgt inchu1	* yes, continue
	sub.b #$20,d0	* subtract offset
	rts		* return
inchu1:	cmp.b #lf,d0	* is it LF?
	bne inchu3	* no, continue
	move.b #cr,d0	* char is CR
inchu3:	rts		* return
*
* OUTCH: output a character using duart port 1
*	 character in D0, all registers unaffected
*
outch:	btst #2,stata	* Tx ready?
	beq outch	* no, try again
     move.b   #ten,cmda
	move.b d0,thra	* output character
     move.b   #ren,cmda
	rts		* return
*
* OUTCH2: as OUTCH for auxiliary RS232 port
*
outch2:	btst #2,statb	* Tx ready?
	beq outch2	* no - loop
     move.b   #ten,cmdb
	move.b d0,thrb	* send char
     move.b   #ren,cmdb
	rts
*
* PDATA: outputs a string starting at A4, length in D2
*	 uses OUTCH 
*
pdata:	move.l d0,-(sp)		* save D0
	bra pdatst	* go to count test
pdatlp:	move.b (a4)+,d0	* get op char
	jsr outch	* print char
pdatst:	dbra d2,pdatlp	* decrement D2, repeat loop if not zero
	move.l (sp)+,d0		* restore D0
	rts		* return
*
* NEWLN2: output two newlines
*
newln2:	jsr newlin	* do #cr,lf; fall through
*
* NEWLIN: output #cr,lf; uses OUTCH and D0
*
newlin:	move.b #cr,d0	* get CR
	jsr outch	* output char
	move.b #lf,d0	* get LF
	jsr outch	* output char
	rts		* return
*
* PSPACx: prints "x" spaces; uses OUTCH and D0
*
pspac7: jsr pspac1	* fall through
pspac6: jsr pspac1     *
pspac5:	jsr pspac1	* 
pspac4:	jsr pspac1	*
pspac3: jsr pspac1	*
pspac2: jsr pspac1	*
pspac1: move.b #space,d0	* get space
	jsr outch	* output char
	rts		* return
*
* PBELL: echo bell character, uses OUTCH and D0
*
pbell:	move.b #bell,d0	* 
	jsr outch	* output bell
	rts		* return
*
* PEQUAL: prints an "="
*
pequal:	move.b #$3d,d0	*
	jsr outch	* output "="
	rts		* return
*
* POKMS: prints an OK message
*
pokms:	move.l d0,-(sp)		* save D0
	jsr pspac1	* print space
	move.b #$2d,d0	*
	jsr outch	* print '-'
	jsr pspac1	* print space
	move.b #$4f,d0	*
	jsr outch	* print 'O'
	move.b #$4b,d0	*
	jsr outch	* print 'K'
	move.l (sp)+,d0		* restore D0
	rts		* return
*
*
* DECPT: prints a 24 bit number in D1 as a signed decimal
*
decpt:	move.l #$07,d2	* count
	move.l #10000000,d3	* compare value
declp1:	move.b #$2f,d0	* digit offset
declp2:	add.b #1,d0	* increment digit
	sub.l d3,d1	* subtract compare value
	bcc declp2	* repeat if not negative
	add.l d3,d1	* overshoot, restore value
	jsr outch	* output character from d0
	divu #10,d3	* divide by 10
	dbra d2,declp1	* decrement count and repeat if not zero
	rts		* return
*
* SCH8HX: print value in D1 as 8 hex digits, and SPACE
*
sch8hx:	jsr ch8hex	* print value
	jsr pspac1	* print space and fall through
	rts
*
* CH8HEX: print value in D1 as 8 hex digits
*
ch8hex:	move.l d1,-(sp)	* save value
	lsr.l #8,d1
	lsr.l #8,d1	* get msw to lsw
	jsr ch4hex	* print msw
	move.l (sp)+,d1	* restore value
	jsr ch4hex	* print lsw and space
	rts
*
* SCH6HX: print value in D1 as 6 hex digits, and SPACE
*
sch6hx:	jsr ch6hex	* print number
	jsr pspac1	* space
	rts
*
* SCH4HX: print value in D1 as hex digits, and SPACE
*
sch4hx:	jsr ch4hex	* print value
	jsr pspac1	* print 1 space
	rts		* return
*
* SCH2HX: print value in D0 as hex digits, and space
*
sch2hx:	jsr ch2hex	* print value
	jsr pspac1	* print 1 space
	rts		* return
*
* CH6HEX: print value in D1 as 6 hex digits
*         uses D0 register
*
ch6hex:	move.l d1,d0
	lsr.l #8,d0	*
	lsr.l #8,d0	* move top byte to lsb of d0
	jsr ch2hex	* print it and drop through
*
* CH4HEX: print value in D1 as 4 hex digits
*	  uses D0 register
*
ch4hex:	move.w d1,d0	* get msb	
	lsr.w #8,d0	* move msb to lsb of d0
	jsr ch2hex	* print it
	move.b d1,d0	* get lsb and drop through
*
* CH2HEX: print value in D0 as two hex digits
*
ch2hex:	move.l d0,-(sp)		* save value
	jsr hihex	* print ms 4 bits
	move.l (sp)+,d0		* restore value
	jsr lohex	* print ls 4 bits
	rts		* return
*
* HIHEX: print MS four bits of D0 as hexadecimal digit
*
hihex:	rol.b #4,d0	* swap nibbles
	jsr lohex	* print it
	rts		* return
*
* LOHEX: print LS four bits in D0 as hex digit
*
lohex:	and.b #$0f,d0	* clear top 4 bits
	cmp.b #10,d0	* greater than 10?
	bge lohex1	* yes, continue
	add.b #$30,d0	* add char offset
lohex2:	jsr outch	* output char
	rts		* return
lohex1:	add.b #$41-10,d0	* add "A"-10
	bra lohex2	* continue
*
* CHKEVN: checks if D1 even, if so rts with carry clear
* 	  if not, prints message and rts with carry set
*
chkevn:	btst #0,d1	* test d1 bottom bit
	beq even	* branch if even
	jsr pbell	* sound bell
	lea oddms,a4	* pointer to message
	move.l #oddmn-oddms,d2	* msg length
	jsr pdata	* print message
	or.b #$01,ccr	* set carry
	rts
even:	and.b #$0fe,ccr	* unset carry
	rts
*
* SIN8HX: output a space, and input 8 hex chars to D1
*
sin8hx:	jsr pspac1	* print a space & fall through
*
* IN8HEX: inputs 8 hex chars to D1. Return with carry set if <CR>
*
in8hex:	jsr in4hex	* get 4 digits to D1
	bcs in4hx	* return if carry set
	lsl.l #8,d1
	lsl.l #8,d1	* shift to msw
	bra in4hex	* get rest
*
* SIN6HX: output a space, and input 6 hex chars to D1, msb cleared
*
sin6hx:	jsr pspac1	* print a space & fall through
*
* IN6HEX: inputs 6 hex chars to D1* returns with carry set if <CR>
* 	  msb of D1 cleared
*
in6hex:	clr.l d1	* initialize
	jsr in2hex	* get 2 hex digits
	bcs in4hx	* return if carry
	move.b d0,d1
	lsl.l #8,d1	*
	lsl.l #8,d1	* shift to correct d1 byte
	bra in4hex	* get rest
*
* SIN4HX: output a space, and input 4 hex chars
*
sin4hx:	jsr pspac1	* print a space* fall through
*
* IN4HEX: inputs 4 hex chars to D1* returns with carry set if <CR>
*
in4hex:	jsr in2hex	* get 2 hex digits
	bcs in4hx	* return if carry
	lsl.w #8,d0	* shift it up to msb
	move.w d0,d1	* save in d1
	jsr in2hex	* get 2 hex digits
	bcs in4hx	* return if carry
	move.b d0,d1	* move to lsb
in4hx:	rts		* return
*
* SIN2HX: print space, and get 2 hex digits into D0; set carry if <CR>
*
sin2hx:	jsr pspac1	* print space and drop through
*
* IN2HEX: get 2 hex digits into D0* return with carry set if <CR>
*
in2hex:	jsr in1hex	* get first hex digit
	bcs in2hx9	* return if carry set
in2hax:	move.l d1,-(sp)		* save D1
	and.b #$0f,d0	* clear ms nibble
	rol.b #4,d0	* swap nibbles
	move.l d0,-(sp)		* save D0
	jsr in1hex	* get second hex digit
	bcs in2hx8	* return if carry set
	move.b d0,d1	* save LS nibble
	move.l (sp)+,d0		* get MS nibble
	and.b #$0f,d1	* clear MS bits
	add.b d1,d0	* add nibbles
	move.l (sp)+,d1		* restore D1
	and.b #$0fe,ccr		* clear carry bit
	rts		* return
in2hx8:	move.l (sp)+,d0		*
	move.l (sp)+,d0		* clean up stack
in2hx9: or.b #$01,ccr		* set carry
	rts		* return
*
* IN1HEX: get 1 hexadecimal character into D0* sets carry if <CR>
*
in1hex:	jsr inchu	* get upper-case character
	cmp.b #$30,d0	* is it less than "0"?
	blt in1er1	* yes, possible error
	cmp.b #$39,d0	* is it greater than "9"?
	bgt in1er2	* yes, possible error
	jsr outch	* echo char
	sub.b #$30,d0	* subtract offset
	and.b #$0fe,ccr		* clear carry bit
	rts		* return
in1er2:	cmp.b #$41,d0	* is it less than "A"?
	blt in1err	* yes, error
	cmp.b #$46,d0	* is it greater than "F"?
	bgt in1err	* yes, error
	jsr outch	* output char
	sub.b #$41-10,d0	* subtract char offset
	and.b #$0fe,ccr		* clear carry
	rts		* return
in1er1:	cmp.b #cr,d0	* is it CR?
	beq in1cr	* yes, continue
in1err:	jsr pbell	* output bell
	bra in1hex	* try again
in1cr:	jsr outch	* echo character
	or.b #$01,ccr		* set carry
	rts		* return
*
* HINCH: gets a character - if lnkflg = 00 gets char from network,
* echos and acknowledges it; if lnkflg <> 00 gets char from
* auxiliary RS232 port;
* char got to d0, all other registers unaffected, clears top bit of char
*
hinch:	jsr inch2	* get char from aux RS232
	and.b #$7f,d0	* clear top bit
	rts		* return
*
* HINCHR: gets an UPPER-CASE character from network interface to D0
*         <LF> converted to <CR>, uses HINCH routine
*
hinchr:	jsr hinch	* get character
	cmp.b #$61,d0	* is it less than "a"?
	blt hincu1	* yes, continue
	cmp.b #$7a,d0	* is it greater than "z"?
	bgt hincu1	* yes, continue
	sub.b #$20,d0	* subtract character offset
	rts		* return
hincu1:	cmp.b #lf,d0	* is it <LF>?
	bne hincu3	* no, continue
	move.b #cr,d0	*  character is <CR>
hincu3:	rts		* return
*
* HIN1HX: gets a hexadecimal character from network interface to D0
*         uses HINCHR routine, return with carry set if <CR>
*         other characters ignored
*
hin1hx:	jsr hinchr	* get character
	cmp.b #$30,d0	* is it less than "0"?
	blt hin1e1	* yes, possible error
	cmp.b #$39,d0	* is it greater than "9"?
	bgt hin1e2	* yes, possible error
	sub.b #$30,d0	* subtract offset
	and.b #$0fe,ccr		* clear carry
	rts		* return
hin1e2:	cmp.b #$41,d0	* is it less than "A"?
	blt hin1er	* yes, error
	cmp.b #$46,d0	* is it greater than "F"?
	bgt hin1er	* yes, error
	sub.b #$41-10,d0	* subtract offset
	and.b #$0fe,ccr		* clear carry
	rts		* return
hin1e1:	cmp.b #cr,d0	* is it <CR>?
	bne hin1er	* no, error
	or.b #$01,ccr		* set carry
	rts		* return
hin1er:	bra hin1hx	* try again
*
* HIN2HX: gets 2 hexadecimal characters into D0 from network
*         All other registers preserved
*         return with carry set if <CR>
*
hin2hx:	jsr hin1hx	* get 1 hex char
	bcs hin2h9	* if carry set, return
	move.l d1,-(sp)		* save D1
	and.b #$0f,d0	* clear ms nibble
	rol.b #4,d0	* swap nibbles
	move.l d0,-(sp)		* save D0 (1st char)
	jsr hin1hx	* get second hex char
	bcs hin2h8	* return if carry set
	move.b d0,d1	* save ls nibble
	move.l (sp)+,d0		* restore D0
	and.b #$0f,d1	* clear ms nibble
	add.b d1,d0	* combine nibbles
	move.l (sp)+,d1		* restore D1
	and.b #$0fe,ccr		* clear carry
hin2h9:	rts		*
hin2h8:	move.l (sp)+,d0		*
	move.l (sp)+,d0		* clean up stack
	or.b #$01,ccr		* set carry
	rts		* return
*
* HIN4HX: gets 4 hex characters from network into D1
*         uses HIN2HX routine, returns with carry set if <CR>
*
hin4hx:	jsr hin2hx	* get 2 chars
	bcs hin4hr	* return if carry
	move.b d0,d1	
	lsl.w #8,d1	* shift to msb of d1
	jsr hin2hx	* get 2 chars
	bcs hin4hr	* return if carry
	move.b d0,d1	* move to lsb
hin4hr:	rts		* return
*
*
*
	end
