*****************************************************************************)
*                                                                           *)
*                                                                           *)
*    Program    : Display Software Monitor for EDDE.                        *)
*                                                                           *)
*    Purpose    : This the user interface software to collect, store and    *)
*                 display the event information in a dbase on this board.   *)
*                                                                           *)
*    Name       : Vinod E.F. REBELLO                                        *)
*                                                                           *)
*    Class      : CS & E 4                                                  *)
*                                                                           *)
*    Username   : VEFR                                                      *)
*                                                                           *)
*    Date       : 22nd May 1989        Version 6.1                          *)
*                 Rev. 17 July 1989    Ver 6.2  to allow display of CentreNt*)
*                                      packet without processing.           *)
*                                                                           *)
*    Supervisor : Damal K. ARVIND                                           *)
*                                                                           *)
*****************************************************************************)
        incl   subr.asm
*
led     equ    #$70000                 * General Purpose Reg. address
off     equ    #$000f                  * both led and read req off
green   equ    #$000e                  * light led
rdreq   equ    #$000d                  * read req to fifo
both    equ    #$000c                  
stack   equ    #$03fdf8
time    equ    #$020000                * Time stamp hours,mins,sec etc
m1      equ    #$02000c                * for currently displaying event
m2      equ    #$02000d                
m3      equ    #$02000e
m4      equ    #$02000f
m5      equ    #$020010
status  equ     $020012                *  Address of Mode status register
stats2  equ     $020013                *  Address of operational stats reg
dbadrw  equ    #$020020                *  address of Database write addr ptr
dbadrr  equ    #$020024                *     "    "     "     read   "    "
dbase   equ    #$020028                *  database start address
dbase2  equ    #$020078
esc     equ    #$1b
lbk     equ    #$5b
ascii0  equ    $30
hr      equ    #3600000000             * these 3 are constant used to
tmin    equ    #600000000              * convert hex timestamp to user
min     equ    #60000000               * readable time.

*
*


ffserv: movem.l d0/a0/a1,-(a7)         * Continual background process to
        move.l led,a0                  * read the Fifo. It is in fact an
        move.w off,(a0)                * service routine which places the
*       move.l fifo,a1                 * incoming packet in the next free
        move.w fifo,d0                 * address in the database.
        move.l dbadrw,a1
        move.l (a1),a0
        move.w d0,(a0)+
        move.l a0,(a1)
        move.l led,a0
        move.w rdreq,(a0)
        movem.l (a7)+,d0/a0/a1
        rte

clrled: move.l led,a2                  * LED off
        move.w off,(a2)
        rts
*
grnled: move.l led,a2                  * LED on
        move.w green,(a2)
        rts

moveto: move.l d0,-(a7)                * move the cursor on WYSE to position
        move.b esc,d0                  * x,y on the screen. 2 ascii coded values
        jsr    outch                   * required e.g. 5 = $3035 and 17 = $3137
        move.b lbk,d0
        jsr    outch
        rol.w  #8,d2
        move.b d2,d0
        jsr    outch
        lsr.w  #8,d2
        move.b d2,d0
        jsr    outch
        move.b #59,d0       *  ;
        jsr    outch
        rol.w  #8,d3
        move.b d3,d0
        jsr    outch
        lsr.w  #8,d3
        move.b d3,d0
        jsr    outch
        move.b #72,d0       *  H
        jsr    outch
        move.l (a7)+,d0
        rts

home:   movem.l d2/d3,-(a7)            * move cursor to position 1,1
        move.w #ascii0+1,d2
        move.w #ascii0+1,d3
        jsr    moveto
        movem.l (a7)+,d2/d3
        rts

wind:   move.l d0,-(a7)                * Building block routine to define
        move.b esc,d0                  * windows.
        jsr    outch
        move.b lbk,d0
        jsr    outch
        rol.w  #8,d2
        move.b d2,d0
        jsr    outch
        lsr.w  #8,d2
        move.b d2,d0
        jsr    outch
        move.b #59,d0
        jsr    outch
        rol.w  #8,d3
        move.b d3,d0
        jsr    outch
        lsr.w  #8,d3
        move.b d3,d0
        jsr    outch
        move.b #114,d0
        jsr    outch
        move.l (a7)+,d0
        rts


windf2: movem.l d2/d3,-(a7)            * defines size of window, from line 1-22.
        move.w  #$3031,d2
        move.w  #$3232,d3
        jsr     wind
        movem.l (a7)+,d2/d3
        rts

windf:  movem.l d2/d3,-(a7)            * defines the full screen window.
        move.w  #$3031,d2
        move.w  #$3234,d3
        jsr     wind
        movem.l (a7)+,d2/d3
        rts

cls:    move.l d0,-(a7)                * clear full screen routine.
        jsr    home
        move.b esc,d0
        jsr    outch
        move.b lbk,d0
        jsr    outch
        move.b #ascii0+2,d0       *  2
        jsr    outch
        move.b #ascii0+4,d0       *  4
        jsr    outch
        move.b #76,d0       *  L
        jsr    outch
        move.l (a7)+,d0
        rts

smthsc: move.l d0,-(a7)                * enable/disable Smooth scroll
        move.b esc,d0                  *     00/04 in d2 as param.
        jsr    outch
        move.b lbk,d0
        jsr    outch
        move.b #63,d0
        jsr    outch
        move.b #$34,d0
        jsr    outch
        move.b #104,d0
        add.b  d2,d0
        jsr    outch
        move.l (a7)+,d0
        rts

attr:   move.l  d0,-(a7)               * To allow character attributes
        move.b  esc,d0                 * for the text which follows.
        jsr     outch                  * Attribute value must be d2.
        move.b  lbk,d0
        jsr     outch
        rol.w   #8,d2
        move.b  d2,d0
        jsr     outch
        lsr.w   #8,d2
        move.b  d2,d0
        jsr     outch
        move.b  #112,d0
        jsr     outch
        move.l  (a7)+,d0
        rts

clratt: move.l  d2,-(a7)               * Clear text attributes.
        move.w  #$0,d2
        jsr     attr
        move.l  (a7)+,d2
        rts


* :*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*
*
* Program messages
*
promms:	dc.b	cr,lf,'PDSEMB>'
prommn:	ds.w	0                                *
iconms:	dc.b	cr,lf,' XX:Unknown Event   '
        dc.b       ' PA:Prcs. Activated '
        dc.b       ' PT:Prcs.Terminated '
        dc.b       ' PD:Process Dead    '
        dc.b	cr,lf,' PB:Process Blocked '
        dc.b       ' PH:Process Halted  '
        dc.b       ' PR:Prcs. Restarted '
        dc.b       ' ..:Process Active  '
        dc.b	cr,lf,' PS:Prcs. Suspended ' 
        dc.b       ' OF:Opening File    '
        dc.b       ' CF:Closing File    '
        dc.b       ' U1:User Defined #1 '
        dc.b	cr,lf,' T_:Tx to process _ ' 
        dc.b       ' R_:Rx from prcs. _ '
        dc.b       ' W_:Synch. with _   '
        dc.b       ' U2:User Defined #2 '
iconmn:	ds.w	0
helpms:	dc.b	cr,lf,'A : Event Line Monitoring  '
        dc.b       'G : gandalf/aux RS232 Prt '
        dc.b       'Q : Quit                   '
        dc.b	cr,lf,'D : System Diagnostics     '
        dc.b       'H : System HALT           '
        dc.b       'R : REBOOT - Clears Dbase  '
        dc.b	cr,lf,'E : Event Log Monitoring   '
        dc.b       'I : Icon Help - Line Mntr '
        dc.b       'S : Screen Lock/Unlock     '
        dc.b	cr,lf,'F : Hware Filtering addrs  '
        dc.b       'P : Print Screen          '
        dc.b       'Z : Restart - Prsrvs Dbase '
helpmn:	ds.w	0


intro1: dc.b   'The POSIE Distributed System'
intro1n:ds.w   0
intro2: dc.b   'EDDE - Event Monitor'
intro2n:ds.w   0
intro3: dc.b   'Version  3.2'
intro3n:ds.w   0
intro4: dc.b   ' May  1989'
intro4n:ds.w   0
intro5: dc.b   'Department of Computer Science'
intro5n:ds.w   0
intro6: dc.b   'University of Edinburgh.'
intro6n:ds.w   0

lin1:   dc.b   '** Event Line Monitoring. **'
lin1n:  ds.w   0
topl:   dc.b   'lqqqqqqwqqqwqqqqw'
        dc.b   'qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq'
        dc.b   'wqqqk'
topln:  ds.w   0
midl:   dc.b   'tqqqqqqnqqqnqqqqn'
        dc.b   'qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq'
        dc.b   'nqqqu'
midln:  ds.w   0
botl:   dc.b   'mqqqqqqvqqqvqqqqv'
        dc.b   'qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq'
        dc.b   'vqqqj'
botln:  ds.w   0
mtxt:   dc.b   'Pro.No Idt LtEv             Previous Activites/Events'
        dc.b   '              BNo'
mtxtn:  ds.w   0

log1:   dc.b   '*** Event Log Monitoring ***'
log1n:  ds.w   0
tlog:   dc.b   'lqqqqqqqqqqqqqqqqwqqqqqqwqqqw'
        dc.b   'qqqqqqwqqqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk'
tlogn:  ds.w   0
mlog:   dc.b   'tqqqqqqqqqqqqqqqqnqqqqqqnqqqn'
        dc.b   'qqqqqqnqqqnqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu'
mlogn:  ds.w   0
blog:   dc.b   'mqqqqqqqqqqqqqqqqvqqqqqqvqqqv'
        dc.b   'qqqqqqvqqqvqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj'
blogn:  ds.w   0
log1t:  dc.b   ' Time  Stamp     From  On    To   On          '       
        dc.b   ' Process  Event'
log1tn: ds.w   0
log2t:  dc.b   'Hr:Mn: Seconds  Procss Brd Procss Brd'
log2tn: ds.w   0
mstat:  dc.b   'Monitor Status : '
mstatn: ds.w   0
hltp:   dc.b   '** HALTED **      '
hltpn:  ds.w   0
sclkp:  dc.b   'Screen Locked     '
sclkpn: ds.w   0
actp:   dc.b   'ACTIVE            '
actpn:  ds.w   0
prntp:  dc.b   'Printing Screen   '
prntpn  ds.w   0
wat:    dc.b   'WAITING for event '
watn:   ds.w   0
err:    dc.b   '** SYSTEM ERROR **'
errn:   ds.w   0
ev0:    dc.b   'Unknown - failed to identify'
ev0n:   ds.w   0
ev1:    dc.b   'Process Activated           '
ev1n:   ds.w   0
ev2:    dc.b   'Process Terminated          '
ev2n:   ds.w   0
ev3:    dc.b   'Process Blocked             '
ev3n:   ds.w   0
ev4:    dc.b   'Process Dead                '
ev4n:   ds.w   0
ev5:    dc.b   'Process Halted              '
ev5n:   ds.w   0
ev6:    dc.b   'Process Suspended           '
ev6n    ds.w   0
ev7:    dc.b   'Process Restarted           '
ev7n    ds.w   0
ev8:    dc.b   'Process Active              '
ev8n:   ds.w   0
ev9:    dc.b   'Process Transmitting        '
ev9n:   ds.w   0
ev10:   dc.b   'Process Receiving           '
ev10n:  ds.w   0
ev11:   dc.b   'Waiting for Synchronisation '
ev11n:  ds.w   0
ev12:   dc.b   'Opening File                '
ev12n:  ds.w   0
ev13:   dc.b   'Closing File                '
ev13n:  ds.w   0
ev14:   dc.b   'User Defined #1             '
ev14n:  ds.w   0
ev15:   dc.b   'User Defined #2             '
ev15n:  ds.w   0
lfinms: dc.b   cr,lf,'Load finished',cr,lf
lfinmn: ds.w   0
labtms: dc.b   cr,lf,'Load aborted',cr,lf,bell
labtmn: ds.w   0
* agnp: dc.b   cr,lf
diagnp: dc.b   cr,lf,'                      The POSIE Distributed Event Monitor.'
        dc.b   cr,lf
diag1:  dc.b   cr,lf,'                        A CS&E 4th Year Honours Project'

diag2:  dc.b   cr,lf,'        This project developed into a dual processor'
        dc.b   ' board system aimed'
        dc.b   cr,lf,'     at capturing interprocess communication '
        dc.b   'packets, interpreting them and'
        dc.b   cr,lf,'     logging, in chronological order, the events which '
        dc.b   'occur within a system.'
        dc.b   cr,lf
        dc.b   cr,lf,'        Current System Version :  1.0'
        dc.b   cr,lf
        dc.b   cr,lf,'          The system is configured to interface with '
        dc.b   'the departmental'
        dc.b   cr,lf,'          Centrenet network operating in Burst '
        dc.b   'Protocol Mode.'
        dc.b   cr,lf
        dc.b   cr,lf,'          Board 1 :   Hardware - Centrenet Interface,'
        dc.b   ' Interpretation'
        dc.b   cr,lf,'                                 Processor and '
        dc.b   'associated buffering (FIFO).'
        dc.b   cr,lf,'                      Software - Currently a simple '
        dc.b   'interpretation routine'
        dc.b   cr,lf,'                                 which expects '
        dc.b   'useful info in first 2 packets'
        dc.b   cr,lf,'          Board2  :   Hardware - Interprocess Buffer,'
        dc.b   ' Display Processor and'
        dc.b   cr,lf,'                                 Communications.'
        dc.b   cr,lf,'                      Software - Wyse Screen handling,'
        dc.b   ' Comms, CLI and'
        dc.b   cr,lf,'                                 Event database '
        dc.b   'bookkeeping.'
diagnn: ds.w   0
gandp:  dc.b   ' ** Aux RS232 Link To The Gandalf ** '
        dc.b   cr,lf,'Control \ to return to Monitor. '
gandpn: ds.w   0


prtstt: movem.l d1/d2/d3/a4,-(a7)      * Print Monitor status prompt
        move.w #$3033,d2
        move.w #$3434,d3
        jsr    moveto
        lea    mstat,a4
        move.l #mstatn-mstat,d1
        jsr    pdata
        movem.l (a7)+,d1/d2/d3/a4
        rts

intscn: jsr    windf                   * Draws the Introduction screen.
        jsr    cls
        lea    intro1,a4
        move.l #intro1n-intro1,d1
        move.w #ascii0+4,d2
        move.w #$3235,d3
        jsr    moveto
        move.w #$3038,d2
        jsr    attr
        jsr    pdata
        jsr    clratt
        lea    intro2,a4
        move.l #intro2n-intro2,d1
        move.w #ascii0+6,d2
        move.w #$3239,d3           *  32
        jsr    moveto
        move.w #$3130,d2
        jsr    attr
        jsr    pdata
        jsr    clratt
        lea    intro3,a4
        move.l #intro3n-intro3,d1
        move.w #$3039,d2
        move.w #$3334,d3
        jsr    moveto
        jsr    pdata
        lea    intro4,a4
        move.l #intro4n-intro4,d1
        move.w #$3130,d2
        move.w #$3335,d3
        jsr    moveto
        jsr    pdata
        lea    intro5,a4
        move.l #intro5n-intro5,d1
        move.w #$3133,d2
        move.w #$3235,d3
        jsr    moveto
        jsr    pdata
        lea    intro6,a4
        move.l #intro6n-intro6,d1
        move.w #$3135,d2
        move.w #$3238,d3
        jsr    moveto
        jsr    pdata
        jsr    home 
        jsr    pbell
        rts

grmode: move.l d0,-(a7)                * Put WYSE in Graphics mode.
        move.b esc,d0
        jsr    outch
        move   #40,d0     *   (
        jsr    outch
        move   #ascii0,d0
        jsr    outch
        move.l (a7)+,d0
        rts

nmode:  move.l d0,-(a7)                * Returns WYSE to Normal Font mode.
        move.b esc,d0
        jsr    outch
        move   #40,d0
        jsr    outch
        move.b #66,d0    *    B
        jsr    outch
        move.l (a7)+,d0
        rts

movec:  move.l d0,-(a7)                * Cursor to column stored in ascii code
        move.b esc,d0                  * with tens in d2 and units in d3.
        jsr    outch
        move.b lbk,d0
        jsr    outch
        move.b d2,d0
        jsr    outch
        move.b d3,d0
        jsr    outch
        move.b #71,d0    *   G
        jsr    outch
        move.l (a7)+,d0
        rts

************************************************************
**      Routines to display the Event Line Monitoring Screen

ptxtln: movem.l d0/d2/d3,-(a7)         * draws graphics chars for the text
        move.b #$30,d2                 * lines in the graphics window.
        move.b #$35,d3
        jsr    movec
        move.b #120,d0       *  x
        jsr    outch
        move.b #$31,d2
        move.b #$32,d3
        jsr    movec
        jsr    outch
        move.b #$36,d3
        jsr    movec
        jsr    outch
        move.b #$32,d2
        move.b #$31,d3
        jsr    movec
        jsr    outch
        move.b #$37,d2
        move.b #$32,d3
        jsr    movec
        jsr    outch
        move.b #$36,d3
        jsr    movec
        jsr    outch
        movem.l (a7)+,d0/d2/d3
        rts

ttxtln: lea    mtxt,a4                 * Prints headings for columns in 
        move.l #mtxtn-mtxt,d1          * the graphics window.
        move.w #$3035,d2
        move.w #$3036,d3
        jsr    moveto
        jsr    nmode
        jsr    pdata
        jsr    grmode
        jsr    ptxtln
        rts


linsc1: jsr    windf2                  * Draws the top half of the
        jsr    cls                     * Graphics window 
        lea    lin1,a4
        move.l #lin1n-lin1,d1
        move.w #ascii0+2,d2
        move.w #$3235,d3
        jsr    moveto
        move.w #$3038,d2
        jsr    attr
        jsr    pdata
        jsr    clratt
        jsr    prtstt
        lea    topl,a4
        move.l #topln-topl,d1
        move.w #ascii0+4,d2
        move.w #ascii0+5,d3
        jsr    moveto
        jsr    grmode
        jsr    pdata
        move.w #ascii0+5,d2
        move.w #ascii0+1,d3
        jsr    moveto
        jsr    ttxtln
        lea    midl,a4
        move.l #midln-midl,d1
        move.w #ascii0+6,d2
        move.w #ascii0+5,d3
        jsr    moveto
        jsr    pdata
        rts

nxtln:  move.l d0,-(a7)                * moves the cursor down one line.
        move.b esc,d0
        jsr    outch
        move.b lbk,d0
        jsr    outch
        move.b #69,d0
        jsr    outch
        move.l (a7)+,d0
        rts


linsc2: move.w #11,d0                  * Draws the second half the 
        bra    tent                    * graphics display window.
more:   jsr    nxtln
        jsr    ptxtln
tent:   dbra   d0,more
        lea    botl,a4
        move.l #botln-botl,d1
        move.w #$3138,d2
        move.w #ascii0+5,d3
        jsr    moveto
        jsr    pdata
        jsr    nmode
        rts

wind1a: movem.l d2/d3,-(a7)            * Sets up the graphics display
        move.w  #$3038,d2              * Window
        move.w  #$3137,d3
        jsr     wind
        movem.l (a7)+,d2/d3
        rts

wind1:  movem.l d2/d3,-(a7)
        move.w  #$3037,d2
        move.w  #$3137,d3
        jsr     wind
        movem.l (a7)+,d2/d3
        rts

wind2a: movem.l d2/d3,-(a7)
        move.w  #$3139,d2
        move.w  #$3234,d3
        jsr     wind
        movem.l (a7)+,d2/d3
        rts

wind2:  movem.l d2/d3,-(a7)
        move.w  #$3139,d2
        move.w  #$3232,d3
        jsr     wind
        movem.l (a7)+,d2/d3
        rts

wind3:  movem.l d2/d3,-(a7)
        move.w  #$3233,d2
        move.w  #$3234,d3
        jsr     wind
        movem.l (a7)+,d2/d3
        rts

*
* :*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*
*
* Initialisation routines
*
* :*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*
*
*
* 68681 initialization : 9600 baud,8 data bits,1 stop bit,
* no parity check and for interupt interface with processor.
*
duart:	movem.l d0/d1/a0/a1,-(a7)   * save registers
	move.b	#noints,imr	* clear all interrupt enables
	move.l	#tablx,a0   * get init parameters
	move.l	#lengtx,d0  * get number of parameters
*
	bra sk0inix        * do loop test
lp0inix:	move.l (a0)+,a1   * get register address
	move.l (a0)+,d1     * parity etc.
*
	move.b	d1,(a1)   	* put command
sk0inix:	dbra	d0,lp0inix * loop test
*
*
*
     move.b    #ten,cmda
     move.b    #ten,cmdb
     move.b    #ren,cmda
     move.b    #ren,cmdb
     movem.l   (a7)+,d0/d1/a0/a1_*restore registers
	rts
*
* set mode of channel A - 7 bits, no parity, 1 stop bit 9600 baud
*  no hsking
*
tablx:dc.l   cmda,point1
     dc.l   modea,norrts+rirdy+cerr+nopar+bits8
     dc.l   modea,norop+notrts+nocts+stop1
*
* Set mode of Channel B - 7 bits, no parity, 1 stop bit, 9600 baud
* no hsking
*
     dc.l   cmdb,point1
     dc.l   modeb,norrts+rirdy+cerr+nopar+bits8
     dc.l   modeb,norop+notrts+nocts+stop1
*
* set output port config register
*
     dc.l   opcr,allout
*
* Reset and enable channel A
*
     dc.l    cmda,rstrx
     dc.l    cmda,rsttx_* reset transmitter
     dc.l    cmda,rsterr
     dc.l    cmda,rstint
     dc.l    cmda,brkoff+tdis+ren
     dc.l    clka,b9600
*
* Reset and enable channel b
*
     dc.l   cmdb,rstrx
     dc.l   cmdb,rsttx
     dc.l   cmdb,rsterr
     dc.l   cmdb,rstint
     dc.l   cmdb,brkoff+tdis+ren
     dc.l   clkb,b9600
*
* Setup output pins
*
     dc.l   imr,$02 
     dc.l   bitset,$ff
lengtx equ   (*-tablx)/8
     rts

* :*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*
*
*
* 68681 initialization : 9600 baud,8 data bits,1 stop bit,
* no parity checkand for a polling interface with processor
*
redrt:	movem.l d0/d1/a0/a1,-(a7)   * save registers
	move.b	#noints,imr	* clear all interrupt enables
	move.l	#table,a0   * get init parameters
	move.l	#length,d0  * get number of parameters
*
	bra sk0init        * do loop test
lp0init:	move.l (a0)+,a1   * get register address
	move.l (a0)+,d1     * parity etc.
*
	move.b	d1,(a1)   	* put command
sk0init:	dbra	d0,lp0init * loop test
*
*
*
     move.b    #ten,cmda
     move.b    #ten,cmdb
     move.b    #ren,cmda
     move.b    #ren,cmdb
     movem.l   (a7)+,d0/d1/a0/a1_*restore registers
	rts
*
* set mode of channel A - 7 bits, no parity, 1 stop bit 9600 baud
*  no hsking
*
table:dc.l   imr,noints
     dc.l   cmda,point1
     dc.l   modea,norrts+rirdy+cerr+nopar+bits8
     dc.l   modea,norop+notrts+nocts+stop1
*
* Set mode of Channel B - 7 bits, no parity, 1 stop bit, 9600 baud
* no hsking
*
     dc.l   cmdb,point1
     dc.l   modeb,norrts+rirdy+cerr+nopar+bits8
     dc.l   modeb,norop+notrts+nocts+stop1
*
* set output port config register
*
     dc.l   opcr,allout
*
* Reset and enable channel A
*
     dc.l    cmda,rstrx
     dc.l    cmda,rsttx_* reset transmitter
     dc.l    cmda,rsterr
     dc.l    cmda,rstint
     dc.l    cmda,brkoff+tdis+ren
     dc.l    clka,b9600
*
* Reset and enable channel b
*
     dc.l   cmdb,rstrx
     dc.l   cmdb,rsttx
     dc.l   cmdb,rsterr
     dc.l   cmdb,rstint
     dc.l   cmdb,brkoff+tdis+ren
     dc.l   clkb,b9600
*
* Setup output pins
*
     dc.l   bitset,$ff
length equ   (*-table)/8
     rts

sinit:  jsr    clrled                  * Initialises the event database.
        move.l dbadrw,a0
        move.l dbase,(a0)    * test on dbase2
        move.l dbadrr,a0
        move.l dbase,(a0)
        rts

init:   jsr    sinit                   * clears database registers.
        move.b #0,stats2               * clears monitor status register
        move.b #0,status               * clears monitor mode register
        move.l led,a0                  * initiate database entry of 
        move.w both,(a0)               * event packets.
*       or.w   #$0700,sr               * disable all interrupts
        and.w  #$f7ff,sr               * enable level 5 and above interrupts
        jsr    duart                   * duart initialise in interupt mode
        jsr    inchu                   * press a key to start
        move.l #4,d2                   * smooth scroll currently disabled
        jsr    smthsc
        rts

* :*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*
*
* Main command interpreter routine
*
* :*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*
*

cpstt:  movem.l  d0/d4/d5,-(a7)        * Get cursor position.
        move.w  #$30,d4                * Need two communication with
        move.w  #$30,d5                * the WYSE.
        move.w  #00,d6
        move.w  #00,d7
        move.b  esc,d0
        jsr     outch
        move    lbk,d0
        jsr     outch
        cmp.b   #$36,d2
        bne     printc
        move.b  d2,d0
        jsr     outch
        move.b  #110,d0
        jsr     outch
        jsr     inch     * the esc
        jsr     inch     * [
        jsr     inch     * P0
        move.b  d0,d6
        jsr     inch
        cmp.b   #59,d0   * ;
        beq     yval
        move.b  d6,d5
        move.b  d0,d6
        jsr     inch
yval:   jsr     inch
        move.b  d0,d7
        jsr     inch
        cmp.b   #82,d0   * R
        beq     nval
        move.b  d7,d4
        move.b  d0,d7
        jsr     inch
nval:   lsl.w   #8,d4
        lsl.w   #8,d5
        add.w   d5,d6
        add.w   d4,d7
        movem.l (a7)+,d0/d4/d5
        rts
printc: move.b  #63,d0                 Tell WYSE to print screen.
        jsr     outch
        move.b  #$31,d0
        jsr     outch
        move.b  #$35,d0
        jsr     outch
        jsr     inchu
        jsr     inchu
        jsr     inchu
        jsr     inchu
        jsr     inchu
        move.b  d0,d2
        jsr     inchu
        movem.l (a7)+,d0/d4/d5
        rts

tstwd:  movem.l d2/d3,-(a7)            * Reset the Windows after key
        btst    #4,status              * pressed routines.
        beq     tst5
        jsr     windf2
        bra     tted
tst5:   btst    #5,status
        beq     tst6
        jsr     windf2
        bra     tted
tst6:   btst    #6,status
        beq     tst7
        jsr     wind1
        bra     tted
tst7:   btst    #7,status
        beq     tted
        jsr     wind1a
tted:   move.w  d6,d2
        move.w  d7,d3
        jsr     moveto
        move.b  #04,d2
        jsr     smthsc
        movem.l (a7)+,d2/d3
        rts

lpromt: movem.l d2/d3,-(a7)            * Move cursor to user prompt.
        jsr    wind3
        move.w #$3233,d2
        move.w #$3031,d3
        jsr    moveto
        jsr    nxtln
        movem.l (a7)+,d2/d3
        rts

lprom:  movem.l d1/a4,-(a7)            * Print user/monitor prompt
        jsr    lpromt
        lea    promms,a4	*
        move.l #prommn-promms,d1	* get message length
        jsr    pdata	* print prompt
        movem.l (a7)+,d1/a4
        rts

upst:   movem.l d1/d2/d3/a4,-(a7)      * Update monitor status and display
        move.w #$3033,d2               * current status.
        move.w #$3631,d3
        jsr    moveto
        btst   #0,stats2
        beq    ht
        lea    err,a4
        move.l #errn-err,d1            * Error status
        jsr    pdata
        bra    upe
ht:     btst   #2,stats2
        beq    ptn
        lea    hltp,a4
        move.l #hltpn-hltp,d1          * Halt status
        jsr    pdata
        bra    upe
ptn:    btst   #4,stats2
        beq    nht
        lea    prntp,a4
        move.l #prntpn-prntp,d1        * Printing screen status
        jsr    pdata
        bra    upe
nht:    btst   #1,stats2
        beq    nsl
        lea    sclkp,a4
        move.l #sclkpn-sclkp,d1        * Screen lock status
        jsr    pdata
        bra    upe
nsl:    btst   #3,stats2
        beq    ac
        lea    wat,a4
        move.l #watn-wat,d1            * Wait for event i.e. all entries
        jsr    pdata                   * in the data base have been displayed.
        bra    upe
ac:     lea    actp,a4
        move.l #actpn-actp,d1          * Monitor active status
        jsr    pdata
upe     movem.l (a7)+,d1/d2/d3/a4
        rts

eline:  jsr     outch                  * Change mode to event line monitoring
        jsr     lprom
        jsr     tstwd
        move.b  #$40,status
        movem.l (a7)+,d0/d1/d2/d3
        rte

elog:   jsr     outch                  * Change mode to event log monitoring.
        jsr     lprom
        jsr     tstwd
        move.b  #$80,status
        movem.l (a7)+,d0/d1/d2/d3
        rte

shdg:   jsr     outch                  * Change mode to display version
        jsr     lprom                  * of hardware and software in use
        jsr     tstwd
        move.b  #$10,status
        movem.l (a7)+,d0/d1/d2/d3
        rte

fltch:  jsr     outch                  * Change mode to Allow the filter latches to be
        jsr     lprom                  * to be updated. 
        jsr     tstwd
        move.b  #$20,status
        movem.l (a7)+,d0/d1/d2/d3
        rte

rset:   jsr     outch                  * change mode to reset sequence
        jsr     lprom
        jsr     tstwd
        or.w    #$0700,sr
        jsr     init
        move.b  #$00,status
        movem.l (a7)+,d0/d1/d2/d3
        rte
*
*
* Load program from remote device
*
ploadr: jsr outch	* echo command char
pload1:	jsr hinch	* get char from network
	cmp.b #$53,d0	* is it "S"?
	bne pload1	* no, try again
	jsr outch	* output "S"
	jsr hinch	* get record type no (1,2 or 9)
	cmp.b #$31,d0	* is it 1?
	beq shadd	* yes, short address version
	cmp.b #$32,d0	* is it 2?
	beq lngadd	* yes, long address version
	cmp.b #$39,d0	* is it 9?
	beq windup	* yes, download ending
	bra lprm70	* abort if any other character
shadd:	jsr hin2hx	* get record length
	bcs lprm70	* prompt if <CR>
	clr.l d2
	move.b d0,d2	* record length in D2
	sub.l #4,d2	* adjust it to count data only
	clr.l d3	* clear address pointer
shad2:	jsr hin4hx	* get address
	bcs lprm70	* prompt if <CR>
	move.w d1,d3	* put addr in pointer
	move.l d3,a4	* move it to a4
getbyt:	jsr hin2hx	* get data byte
	bcs lprm70	* prompt if <CR>
	move.b d0,(a4)+	* put in memory
	dbra d2,getbyt	* repeat as rqd
	jsr hin2hx	* throw away checksum
	bcs lprm70	* prompt if <CR>
	bra pload1	* get next record
lngadd:	jsr hin2hx	* get record length
	bcs lprm70	* prompt if <CR>
	clr.l d2
	move.b d0,d2	* record length into d2
	sub.l #5,d2	* adjust to count data only
	clr.l d3
	jsr hin2hx	* get msb of addr to d0
	bcs lprm70	* prompt if <CR>
	move.b d0,d3	* put it in d3
	swap d3		* move it to correct byte of d3
	bra shad2	* continue
windup:	jsr hin4hx
	jsr hin4hx	* throw away 4 bytes
	lea lfinms,a4	* load finished message
	move.l #lfinmn-lfinms,d1
lprm69:	jsr pdata	* print message
       rts
*      bra lprom	* goto prompt
lprm70: lea labtms,a4	* load aborted message
        move.l #labtmn-labtms,d1
        bra lprm69
*
* RSLINK: links to auxiliary RS232 port, allows downloading
* 
rslink: lea    gandp,a4
        move.l #gandpn-gandp,d1
        jsr    pdata
        move.b cr,d0
        jsr    outch2
*	jsr outch	* echo char
rsloop:	jsr inchr2	* get char from aux RS232
	bcc gotch	* branch if char available
	jsr inchr	* get char from terminal
	bcs rsloop	* loop if no char available
	cmp.b #netbrk,d0	* is it NETWORK BREAK char?
	bne rscont	* branch if not
     rts
*bra lprom	* goto prompt
rscont:	jsr outch2	* send char to aux RS232 port
	bra rsloop	* loop
gotch:	cmp.b #00,d0	* is it null char?
	beq rsloop	* if so discard and loop
	cmp.b #netbrk,d0	* is it NETWORK BREAK char?
	beq ploadr	* if so, go to program downloader
	jsr outch	* otherwise send to terminal
	bra rsloop	* and loop

gand:   jsr     windf2                 * Setup gandalf link.
        jsr     cls
        move.b  #04,d2
        jsr     smthsc
        jsr     rslink
        move.b  #$02,status
        jsr     lprom
        jsr     tstwd
        movem.l (a7)+,d0/d1/d2/d3
        rte

quit:   jsr     outch                  * Change mode the quit mode.
        move.b  #$04,status
*        jsr     setst
        jsr     lprom
        jsr     tstwd
        movem.l (a7)+,d0/d1/d2/d3
        rte

lpromx: jsr lprom                     * No action to mode update
        jsr     tstwd                 * since return pressed.- escape
        movem.l (a7)+,d0/d1/d2/d3     * from key board handling routines.
        rte


iconi:  move.b #00,d2
        jsr    smthsc
        jsr    outch                  * Icon help
        jsr    wind2
        move.w #$3139,d2
        move.w #$3031,d3
        jsr    moveto
        move.l a4,-(a7)
        lea    iconms,a4	* get message pointer
        move.l #iconmn-iconms,d1	* get message length
        jsr    pdata	* print it
        jsr    lprom
        jsr     tstwd
        move.l (a7)+,a4
        movem.l (a7)+,d0/d1/d2/d3
        rte

pscrn:  jsr    outch                  * Print screen      
        eori.b #$10,stats2
        jsr    upst
        jsr    lprom
*prtst:  move.b #0,d2
*       jsr    cpstt
*       cmp.b  #$30,d2
*       bne    prtst
*       move.b esc,d0
*       jsr    outch
*       move.b lbk,d0
*       jsr    outch
*       move.b #105,d0
*       jsr    outch
        jsr     tstwd
        movem.l (a7)+,d0/d1/d2/d3
        rte

tlah:   eori.b #$04,stats2            * Cause monitor to halt.
        jsr    outch
        jsr    upst
        jsr    lprom
        jsr    tstwd
        movem.l (a7)+,d0/d1/d2/d3
        rte

lkscrn: eori.b #$02,stats2            * Cause screen display to freeze.
        jsr    outch
        jsr    upst
        jsr    lprom
        jsr     tstwd
        movem.l (a7)+,d0/d1/d2/d3
        rte

rstart: jsr    outch                  * initate a soft reset
        jsr    lprom
        jsr     tstwd
        move.l  dbadrr,a0
        move.l  dbase,(a0)
        move.b  #00,status
        movem.l (a7)+,d0/d1/d2/d3
        rte
**
*
chinp:  movem.l d0/d1/d2/d3,-(a7)     * Get character from Duart
        move.l d0,-(a7)               * converted it to upper case.
*       move.b  #00,d2                * Take the necessary action by
*       jsr     smthsc                * setting the status registers.
        move.b #$36,d2                * The monitor will then change
        jsr    cpstt                  * mode at specific times.
        jsr    lpromt
*       move.l #prommn-promms,d1
        move.w #$3234,d2
        move.w #$3038,d3
*       add.b  d1,d3
        jsr    moveto
        move.l (a7)+,d0
*       jsr    upcse
        jsr    inchu	* get an upper-case character
        cmp.b  #cr,d0	* is it <CR>?
        beq    lpromx	* yes, goto prompt
        cmp.b  #$3f,d0	* is it "?"?
        beq    query	* yes, goto query
        cmp.b  #$41,d0	* is it "A"?
        beq    eline	* yes, goto event line monitor
        cmp.b  #$44,d0	* is it "D"?
        beq    shdg	* yes, goto system diagnostics
        cmp.b  #$45,d0	* is it "E"?
        beq    elog	* yes, goto event log monitor
        cmp.b  #$46,d0	* is it "F"?
        beq    fltch	* yes, goto filter change      
        cmp.b  #$47,d0	* is it "G"?
        beq    gand	* yes, goto gandalf interface
        cmp.b  #$48,d0	* is it "H"?
        beq    tlah	* yes, goto halt routine
        cmp.b  #$49,d0	* is it "I"?
        beq    iconi	* yes, goto icon info for event line monitor
        cmp.b  #$50,d0	* is it "P"?
        beq    pscrn	* yes, goto print screen routine
        cmp.b  #$51,d0	* is it "Q"?
        beq    quit	* yes, goto quit routine
        cmp.b  #$52,d0	* is it "R"?
        beq    rset	* yes, goto REBOOT routine
        cmp.b  #$53,d0	* is it "S"?
        beq    lkscrn	* yes, goto lock screen routine
        cmp.b  #$5a,d0	* is it "Z"?
        beq    rstart	* yes, goto restart routine
*
* character not found
*
        jsr    pbell	* char not found, print bell
        movem.l (a7)+,d0/d1/d2/d3
        rte

akey:   movem.l d0/d2,-(a7)            * Has a key been pressed if so
        and.w   #$f9ff,sr           * what is and take the appropriate action.
*       jsr     inchr
*       bcs     nokey
*       jsr     chinp
        move.l  #$ffffffff,d0       * A delay
zz:     dbra    d0,zz
        or.w    #$0400,sr           * disable level 4 and below interrupts
        move.b  #04,d2
        jsr     smthsc
        movem.l (a7)+,d0/d2
        rts

*
* Command Jump table
*
lprom1: move.b  #00,d2
        jsr     smthsc
        jsr    outch	* echo character   
        jsr    lprom	* goto prompt
        jsr     tstwd
        movem.l (a7)+,d0/d1/d2/d3
        rte
*
* QUERY: print help message* uses D1, D0
*
query:  move.b #00,d2
        jsr    smthsc
        jsr    outch	* output character
        jsr    wind2
        move.w #$3139,d2
        move.w #$3031,d3
        jsr    moveto
        move.l a4,-(a7)
        lea    helpms,a4	* get message pointer
        move.l #helpmn-helpms,d1	* get message length
        jsr    pdata	* print it
        jsr    lprom
        jsr    tstwd
        move.l (a7)+,a4
        movem.l (a7)+,d0/d1/d2/d3
        rte

*************************************************************
*       Routines for Event Log Monitoring.

**   Graphics routines to draw the graphical window.

ptlgln: movem.l d0/d2/d3,-(a7)       * draws the vertical lines between
        move.b #$30,d2               * columns
        move.b #$35,d3
        jsr    movec
        move.b #120,d0       *  x
        jsr    outch
        move.b #$32,d2
        move.b #$32,d3
        jsr    movec
        jsr    outch
        move.b #$39,d3
        jsr    movec
        jsr    outch
        move.b #$33,d2
        move.b #$33,d3
        jsr    movec
        jsr    outch
        move.b #$34,d2
        move.b #$30,d3
        jsr    movec
        jsr    outch
        move.b #$34,d3
        jsr    movec
        jsr    outch
        move.b #$37,d2
        move.b #$36,d3
        jsr    movec
        jsr    outch
        movem.l (a7)+,d0/d2/d3
        rts

evlg2:  move.w #10,d0             * Draws the lower half of the graphics
        bra    lgnt               * window for event log monitoring
lgre:   jsr    nxtln
        jsr    ptlgln
lgnt:   dbra   d0,lgre
        lea    blog,a4
        move.l #blogn-blog,d1
        move.w #$3138,d2
        move.w #ascii0+5,d3
        jsr    moveto
        jsr    pdata
        jsr    nmode
        rts

tlogln: lea    log1t,a4          * Draws the top half of the graphics
        move.l #log1tn-log1t,d1  * window.
        move.w #$3035,d2
        move.w #$3037,d3
        jsr    moveto
        jsr    nmode
        jsr    pdata
        jsr    grmode
        jsr    ptlgln
        lea    log2t,a4
        move.l #log2tn-log2t,d1
        move.w #$3036,d2
        jsr    moveto
        jsr    nmode
        jsr    pdata
        jsr    grmode
        jsr    ptlgln
        rts



evlg1:  jsr    windf2               * Sets up screen for event log monitoring
        jsr    cls                  * displays screen heading
        lea    log1,a4
        move.l #log1n-log1,d1
        move.w #ascii0+2,d2
        move.w #$3235,d3
        jsr    moveto
        move.w #$3038,d2
        jsr    attr
        jsr    pdata
        jsr    clratt
        jsr    prtstt
        lea    tlog,a4
        move.l #tlogn-tlog,d1
        move.w #ascii0+4,d2
        move.w #ascii0+5,d3
        jsr    moveto
        jsr    grmode
        jsr    pdata
        move.w #ascii0+5,d2
        move.w #ascii0+1,d3
        jsr    moveto
        jsr    tlogln
        lea    mlog,a4
        move.l #mlogn-mlog,d1
        move.w #ascii0+7,d2
        move.w #ascii0+5,d3
        jsr    moveto
        jsr    pdata
        rts

**********************************************************
***      Routines to interpret the event packet and convert 
***      to a human readable format and display it.

gttmp:  movem.l d0/d1/d3/a0,-(a7)     * This routine converts the timestamp
        move.l  time,a0               * to hrs, min, secs and usec.
        move.l  #00,(a0)+
        move.l  #00,(a0)+
        move.l  #00,(a0)
        move.l  time,a0
        move.b  #$2f,d0
dhr:    add.b   #1,d0
        sub.l   hr,d2
        bcc     dhr
        add.l   hr,d2
        move.b  d0,(a0)+
        move.b  #$2f,d0
dtmin:  add.b   #1,d0
        sub.l   tmin,d2
        bcc     dtmin
        add.l   tmin,d2
        move.b  d0,(a0)+
        move.b  #$2f,d0
dmin:   add.b   #1,d0
        sub.l   min,d2
        bcc     dmin
        add.l   min,d2
        move.b  d0,(a0)+
        jsr     decpt
        movem.l (a7)+,d0/d1/d3/a0
        rts

prtms:  movem.l d0/d2/a0,-(a7)       * this routine prints the timestamp
        move.l  time,a0              * the lefthand side column.
        move.b  (a0)+,d0
        jsr     outch
        move.b  #58,d0
        jsr     outch
        move.b  (a0)+,d0
        jsr     outch
        move.b  (a0)+,d0
        jsr     outch
        move.b  #58,d0
        jsr     outch
        move.b  (a0)+,d0
        jsr     outch
        move.b  (a0)+,d0 
        jsr     outch
        move.b  #46,d0
        jsr     outch
        move.b  #05,d2
pts:    move.b  (a0)+,d0
        jsr     outch
        dbra    d2,pts
        movem.l (a7)+,d0/d2/a0
        rts

ptev:   movem.l d1/d2/a4,-(a7)    * Identifies the one of 16 events
        and.b   #$0f,d2           * and print the corresponding message
        cmp.b   #0,d2
        bne     ne0
        lea     ev0,a4
        move.l  #ev0n-ev0,d1
        bra     eeq
ne0:    cmp.b   #1,d2
        bne     ne1
        lea     ev1,a4
        move.l  #ev1n-ev1,d1
        bra     eeq
ne1:    cmp.b   #2,d2
        bne     ne2
        lea     ev2,a4
        move.l  #ev2n-ev2,d1
        bra     eeq
ne2:    cmp.b   #3,d2
        bne     ne3
        lea     ev3,a4
        move.l  #ev3n-ev3,d1
        bra     eeq
ne3:    cmp.b   #4,d2
        bne     ne4
        lea     ev4,a4
        move.l  #ev4n-ev4,d1
        bra     eeq
ne4:    cmp.b   #5,d2
        bne     ne5
        lea     ev5,a4
        move.l  #ev5n-ev5,d1
        bra     eeq
ne5:    cmp.b   #6,d2
        bne     ne6
        lea     ev6,a4
        move.l  #ev6n-ev6,d1
        bra     eeq
ne6:    cmp.b   #7,d2
        bne     ne7
        lea     ev7,a4
        move.l  #ev7n-ev7,d1
        bra     eeq
ne7:    cmp.b   #8,d2
        bne     ne8
        lea     ev8,a4
        move.l  #ev8n-ev8,d1
        bra     eeq
ne8:    cmp.b   #9,d2
        bne     ne9
        lea     ev9,a4
        move.l  #ev9n-ev9,d1
        bra     eeq
ne9:    cmp.b   #10,d2
        bne     ne10
        lea     ev10,a4
        move.l  #ev10n-ev10,d1
        bra     eeq
ne10:   cmp.b   #11,d2
        bne     ne11
        lea     ev11,a4
        move.l  #ev11n-ev11,d1
        bra     eeq
ne11:   cmp.b   #12,d2
        bne     ne12
        lea     ev12,a4
        move.l  #ev12n-ev12,d1
        bra     eeq
ne12:   cmp.b   #13,d2
        bne     ne13
        lea     ev13,a4
        move.l  #ev13n-ev13,d1
        bra     eeq
ne13:   cmp.b   #14,d2
        bne     ne14
        lea     ev14,a4
        move.l  #ev14n-ev14,d1
        bra     eeq
ne14:   lea     ev15,a4
        move.l  #ev15n-ev15,d1
eeq:    jsr     pdata
        movem.l (a7)+,d1/d2/a4
        rts

*
* 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
*
* HIHEX: print MS four bits of D0 as hexadecimal digit
*
hihex: rol.b    #4,d0	* swap nibbles
       jsr      lohex	* print it
       rts		* return

*
* 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
        move.b  #$34,d2
        move.b  #$32,d3
       jsr      movec
       jsr      lohex	* print ls 4 bits
       rts		* return
*
sdb:    move.l  d0,-(a7)          * Prints out the source and destination 
        move.l  d2,d0             * 4-bit address in hex
        lsr.w   #4,d0
        move.b  #$33,d2
        move.b  #$31,d3
        jsr     movec
        jsr     ch2hex
        move.l  (a7)+,d0
        rts

dval:   dc.l    1000,100,10,1
ptpn:   movem.l d0/d1/d2/d3,-(a7)      * prints out the process id in decimal.
        move.l  #$03,d1             * max val = 1023
        lea     dval,a1
        move.l  (a1)+,d3
pn1:    move.b  #$2f,d0
pn2:    add.b   #1,d0
        sub.l   d3,d2
        bcc     pn2
        add.l   d3,d2
        jsr     outch
        move.l  (a1)+,d3
        dbra    d1,pn1
        movem.l (a7)+,d0/d1/d2/d3
        rts

ptsp:   movem.l d1/d2,-(a7)         * print the source process id
        move.l  #22,d1
        lsr.l   d1,d2
        and.l   #$03ff,d2
        jsr     ptpn
        movem.l (a7)+,d1/d2
        rts

ptdp:   movem.l d1/d2,-(a7)         * print the destination process id
        move.l  #12,d1
        lsr.l   d1,d2
        and.l   #$03ff,d2
        jsr     ptpn
        movem.l (a7)+,d1/d2
        rts

evlog:  movem.l d2/d3,-(a7)       * logs an event to the screen
        move.b  #$30,d2
        move.b  #$37,d3
        jsr     movec
        move.l  d0,d2
        jsr     gttmp             * convert timestamp
        jsr     prtms             * print timestamp
        move.b  #$32,d2
        move.b  #$34,d3
        jsr     movec
        move.l  d1,d2
        jsr     ptsp              * print source proc id
        move.b  #$33,d2
        move.b  #$35,d3
        jsr     movec
        move.l  d1,d2
        jsr     ptdp              * print destination proc id
*       move.l  d1,d2
        jsr     sdb
        move.b  #$34,d2
        move.b  #$36,d3
        jsr     movec
        move.l  d1,d2
        jsr     ptev              * print type of event
        movem.l (a7)+,d2/d3
        rts
****************************************************************

chst2:  jsr    akey               * Checks the status register and take
        btst   #0,stats2          * necessary action
        bne    error              * error condition - flag error and hang
        btst   #1,stats2
        bne    chst2              * Halt - cycle until condition cleared
        btst   #2,stats2          * also interupts should be disabled.
        bne    chst2              * screen lock - cycle until condition cleared
*       btst   #3,stats2
*       bne    chst2
        btst   #4,stats2          * Waiting for event- wait until another event
        bne    chst2              * arrives.
        rts

fetchv: movem.l d0/d1/a0/a1,-(a7)
        movem.l (a7)+,d0/d1/a0/a1
        rts

lgln:   movem.l d0/d2/d3,-(a7)      * Scrolls inside the graphics window
        jsr    wind1a               * to allow new events to be printed
        move.w #$3137,d2            * of the window.
        move.w #$3031,d3
        jsr    moveto
        move.b #lf,d0
        jsr    outch
        move.b #cr,d0
        jsr    outch
        jsr    grmode
        jsr    ptlgln
        jsr    nmode
        movem.l (a7)+,d0/d2/d3
        rts


scrn3:  movem.l d0/d1/a0/a1,-(a7)   * If there is an event yet to be displayed
        jsr    chst2                * print it otherwise update status and exit
*       jsr    fetchv
        move.l  dbadrw,a0
        move.l  (a0)+,d0
        move.l  (a0),d1
        sub.l   d1,d0
        move.l  #stats2,a1
        move.b  (a1),d1
        cmp.l   #08,d0
        bge     rdev
        move.b  #$08,stats2
        cmp.b   #$08,d1
        beq     nchnge
        jsr     upst
        bra     nchnge
rdev:   move.b  #$00,stats2
        cmp.b   #$00,d1
        beq     nchg
        jsr     upst
nchg:   jsr    lgln             * an event to be printed
        move.l  (a0),a1
        move.l  (a1)+,d0
        move.l  (a1)+,d1
        move.l  a1,(a0)
        jsr    evlog            * display event
        jsr    akey             * Check to see if a key has been pressed.
nchnge: movem.l (a7)+,d0/d1/a0/a1
        rts

inevlg: jsr    evlg1            * set up and display graphics window
        jsr    evlg2            * for event log monitoring.
        jsr    upst
evg:    jsr    scrn3
*       jsr    upst
        jsr    akey
        btst   #7,status        * Check if a change of mode has been
        bne    evg              * indicated by key board support routines
        rts

shdiag: move.b #04,d2           * Change screen format and print out 
        jsr    smthsc           * information on current hardware and 
        jsr    windf2           * software being used.
        jsr    cls
        move.w #$3031,d2
        move.w #$3031,d3
        jsr    moveto
        lea    diagnp,a4
        move.l #diagnn-diagnp,d1
        jsr    pdata
*        move.b #00,d2
*        jsr    smthsc
shdig:  jsr    akey
        btst   #4,status
        bne    shdig
        rts

filtch: jsr    windf2
        jsr    cls
ftch:   jsr    akey
        btst   #5,status
        bne    ftch
        rts

inlsc2: jsr    linsc1         * setup for event line monitoring
        jsr    linsc2
        jsr    upst
lsc:    jsr    akey
        btst   #6,status
        bne    lsc
        rts

quitt:  jsr    windf2        * Routine to shutdown monitor.
        jsr    cls
        or.w  #$0700,sr      * disable interupts
*       jsr    redrt
        jsr    intscn
        trap   #0
stop:   jmp    stop

error:  move.w #$3033,d2     * Fatal system errors will be flagged
        move.w #$3631,d3     * and currently monitor will hang.
        jsr    moveto
        lea    err,a4
        move.l #errn-err,d1
        jsr    pdata
err1:   jmp    err1

chgst:  jsr    chst2         * Routine to change mode of operation of the
*       btst   #0,status     * monitor.
*       beq    nxtst4
*       move.l stack,a7     ***   Clear the stack
*       bra    start
        btst   #2,status     * quit the monitor
        beq    nxtst
        rts
nxtst:  btst   #4,status
        beq    nxtst1
        jsr    shdiag        * print out system information
nxtst1: btst   #5,status
        beq    nxtst2
        jsr    filtch        * update hardware filter addresses
nxtst2: btst   #6,status
        beq    nxtst3
        jsr    inlsc2        * Event line monitoring.
nxtst3: btst   #7,status
        beq    nwscn
        jsr    inevlg        * Event log monitoring.
nwscn:  move.l #status,a0
        move.w (a0),d0
        lsr.w  #8,d0
        cmp.b  #00,d0
        bne    chgst
        jsr    windf         * If no mode active draw intro screen
        jsr    cls
        jsr    intscn
        jsr    lprom
nwscn2: jsr    akey
        move.l #status,a0    * wait to move into an active mode.
        move.w (a0),d0
        lsr.w  #8,d0
        cmp.b  #00,d0
        beq    nwscn2
        bra    chgst

        org    $034000

start:  jsr    init         * setup register, database and duart
        jsr    chgst        * Get monitor mode and cycle thro modes until
        jsr    grnled       * quit. light green led for okay

        jmp    quitt
        jmp    stop
*

*
*******************************************************************
**      Interupt vector - for use with running the 68000 software monitor.

        org    $03fe50
        jmp    chinp
        org    $03fe60
        jmp    ffserv
*
        END
