*****************************************************************************)
*                                                                           *)
*                                                                           *)
*    Program  : M68000 Monitor for the POSIE Dist. Sys. Monitor Board       *)
*                                                                           *)
*    Purpose  :                                                             *)
*                                                                           *)
*                                                                           *)
*                                                                           *)
*    Name     : Vinod E.F. REBELLO                                          *)
*                                                                           *)
*    Class    : CS & E 4                                                    *)
*                                                                           *)
*    Username : VEFR                                                        *)
*                                                                           *)
*    Date     : 22nd April 1989        Version 1.0                          *)
*                                                                           *)
*    Tutor    : Damal K. ARVIND                                             *)
*                                                                           *)
*****************************************************************************)
        incl   subr.asm
*
led     equ    #$70000
off     equ    #$000f
green   equ    #$000e
rdreq   equ    #$000d
both    equ    #$000c
stack   equ    #$03fdf8
time    equ    #$020000
m1      equ    #$02000c
m2      equ    #$02000d
m3      equ    #$02000e
m4      equ    #$02000f
m5      equ    #$020010
status  equ     $020012
stats2  equ     $020013
dbadrw  equ    #$020020
dbadrr  equ    #$020024
dbase   equ    #$020028
esc     equ    #$1b
lbk     equ    #$5b
ascii0  equ    $30
hr      equ    #3600000000
tmin    equ    #600000000
min     equ    #60000000

*
*


ffserv: movem.l d0/a0/a1,-(a7)
        move.l led,a0
        move.w off,(a0)
        move.l fifo,a1
        move.w (a1),d0
        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
        move.w off,(a2)
        rts
*
grnled: move.l led,a2
        move.w green,(a2)
        rts

moveto: move.l d0,-(a7)
        move.b esc,d0
        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 #72,d0       *  H
        jsr    outch
        move.l (a7)+,d0
        rts

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

wind:   move.l d0,-(a7)
        move.b esc,d0
        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)
        move.w  #$3031,d2
        move.w  #$3232,d3
        jsr     wind
        movem.l (a7)+,d2/d3
        rts

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

cls:    move.l d0,-(a7)
        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)
        move.b esc,d0
        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)
        move.b  esc,d0
        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  #112,d0
        jsr     outch
        move.l  (a7)+,d0
        rts

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


* :*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*
*
* Program messages
*
promms:	dc.b	cr,lf,'PDSEMB>'
prommn:	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 '
*       dc.b	cr,lf,'J <add1><add2> = <value> Find location equal to <value>'
*       dc.b	cr,lf,'L                      * Link to remote device'
*       dc.b	cr,lf,'M <addr>                 Modify memory'
*       dc.b	cr,lf,'T <add1> - <add2>        Test memory - DESTROYS CONTENTS'
*       dc.b	cr,lf,'U <reg_name> = <value>   Updates saved register'
*       dc.b	cr,lf,'V <add1><add2> = <add3>  Compare two blocks of memory'
*       dc.b	cr,lf,'W                      * Display network connection'
*       dc.b	cr,lf,'X <instr_count>(00-FF)   Trace <instr_count> instrs <space> to halt'
helpmn:	ds.w	0


intro1: dc.b   'The POSIE Distributed System'
intro1n:ds.w   0
intro2: dc.b   'Event  Monitor'
intro2n:ds.w   0
intro3: dc.b   'Version  1.0'
intro3n:ds.w   0
intro4: dc.b   'April 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   'Relative  Time   From  On    To   On          '       
        dc.b   'Processor 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
diagnp: dc.b   cr,lf
        dc.b   cr,lf,'                 The POSIE Distributed Event Monitor.'
        dc.b   cr,lf,'                    A CS&E 4th Year Honours Project'
        dc.b   cr,lf
        dc.b   cr,lf,'        This project developed into a dual processor'
        dc.b   ' board system whos aim'
        dc.b   cr,lf,'     is to capture interprocess communication '
        dc.b   'packets, interpret them and'
        dc.b   cr,lf,'     log, 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,'                                 Communcations.'
        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


prtstt: movem.l d1/d2/d3/a4,-(a7)
        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
        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 #$3332,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)
        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)
        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)
        move.b esc,d0
        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

ptxtln: movem.l d0/d2/d3,-(a7)
        move.b #$30,d2
        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
        move.l #mtxtn-mtxt,d1
        move.w #$3035,d2
        move.w #$3036,d3
        jsr    moveto
        jsr    nmode
        jsr    pdata
        jsr    grmode
        jsr    ptxtln
        rts


linsc1: jsr    windf2
        jsr    cls
        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)
        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
        bra    tent
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)
        move.w  #$3038,d2
        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

inlsc2: jsr    linsc1
        jsr    linsc2
lsc:    btst   #6,status
        bne    lsc
        rts

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

cpstt:  movem.l  d0/d4/d5,-(a7)
        move.w  #$30,d4
        move.w  #$30,d5
        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
        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)
        btst    #4,status
        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
        movem.l (a7)+,d2/d3
        rts

lpromt: movem.l d2/d3,-(a7)
        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)
        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)
        move.w #$3033,d2
        move.w #$3631,d3
        jsr    moveto
        btst   #0,stats2
        beq    ht
        lea    err,a4
        move.l #errn-err,d1
        jsr    pdata
        bra    upe
ht:     btst   #2,stats2
        beq    ptn
        lea    hltp,a4
        move.l #hltpn-hltp,d1
        jsr    pdata
        bra    upe
ptn:    btst   #4,stats2
        beq    nht
        lea    prntp,a4
        move.l #prntpn-prntp,d1
        jsr    pdata
        bra    upe
nht:    btst   #1,stats2
        beq    nsl
        lea    sclkp,a4
        move.l #sclkpn-sclkp,d1
        jsr    pdata
        bra    upe
nsl:    btst   #3,stats2
        beq    ac
        lea    wat,a4
        move.l #watn-wat,d1
        jsr    pdata
        bra    upe
ac:     lea    actp,a4
        move.l #actpn-actp,d1
        jsr    pdata
upe     movem.l (a7)+,d1/d2/d3/a4
        rts

eline:  jsr     outch
        jsr     lprom
        jsr     tstwd
        move.b  #$40,status
        movem.l (a7)+,d0/d1/d2/d3
        rte

elog:   jsr     outch
        jsr     lprom
        jsr     tstwd
        move.b  #$80,status
        movem.l (a7)+,d0/d1/d2/d3
        rte

shdg:   jsr     outch
        jsr     lprom
        jsr     tstwd
        move.b  #$10,status
        movem.l (a7)+,d0/d1/d2/d3
        rte

fltch:  jsr     outch
        jsr     lprom
        jsr     tstwd
        move.b  #$20,status
        movem.l (a7)+,d0/d1/d2/d3
        rte

rset:   jsr     outch
        jsr     lprom
        jsr     tstwd
        move.b  #$01,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,d2
lprm69:	jsr pdata	* print message
	bra lprom	* goto prompt
lprm70:	lea labtms,a4	* load aborted message
	move.l #labtmn-labtms,d2
	bra lprm69
*
* RSLINK: links to auxiliary RS232 port, allows downloading
* 
rslink:	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
        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
        move.b  #$04,status
*        jsr     setst
        jsr     lprom
        jsr     tstwd
        movem.l (a7)+,d0/d1/d2/d3
        rte

lpromx: jsr lprom
        jsr     tstwd
        movem.l (a7)+,d0/d1/d2/d3
        rte

iconi:  jsr    outch
        jsr    lprom
        jsr     tstwd
        movem.l (a7)+,d0/d1/d2/d3
        rte

pscrn:  jsr    outch
        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
        jsr    outch
        jsr    upst
        jsr    lprom
        jsr    tstwd
        movem.l (a7)+,d0/d1/d2/d3
        rte

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

rstart: jsr    outch
        jsr    lprom
        jsr     tstwd
        movem.l (a7)+,d0/d1/d2/d3
        rte
**
*
chinp:  movem.l d0/d1/d2/d3,-(a7)
        move.b #$36,d2
        jsr    cpstt
        jsr    lpromt
*       move.l #prommn-promms,d1
        move.w #$3234,d2
        move.w #$3038,d3
*       add.b  d1,d3
        jsr    moveto
        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 #$42,d0	* is it "B"?
*	beq brkpt	* yes, goto set breakpoint
        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 #$4a,d0	* is it "J"?
*	beq findr	* yes, goto find routine
*	cmp.b #$4b,d0	* is it "K"?
*	beq killbp	* yes, goto kill breakpoint
**	cmp.b #$4c,d0	* is it "L"?
**	beq loadr	* yes, goto load routine
*	cmp.b #$4d,d0	* is it "M"?
*	beq modif	* yes, goto modify memory routine
        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 #$54,d0	* is it "T"?
*	beq tstmem	* yes, goto test memory
*	cmp.b #$55,d0	* is it "U"?
*	beq setreg	* yes, goto register set routine
*	cmp.b #$56,d0	* is it "V"?
*	beq compr	* yes, goto compare routine
**	cmp.b #$57,d0	* is it "W"?
**	beq where	* yes, goto where connected routine
*	cmp.b #$58,d0	* is it "X"?
*	beq xtrace	* yes, goto trace 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
*       bra    chinp	* get next char
*
* Command Jump table
*
lprom1: 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:  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
*
* :*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*
*
* Initialisation routines
*
* :*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*
*
*
* 68681 initialization : 9600 baud,8 data bits,1 stop bit,
* no parity check
*
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.l    led,a0
     move.w    green,(a0)
*
     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 check
*
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.l    led,a0
     move.w    green,(a0)
*
     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
        move.l dbadrw,a0
        move.l dbase,(a0)
        move.l dbadrr,a0
        move.l dbase,(a0)
        rts

init:   jsr    sinit
        move.b #0,stats2
        move.b #0,status
        jsr    duart
        jsr    inchu
        and.w  #$f9ff,sr     * enable interupts
        move.l #0,d2
        jsr    smthsc
        rts


ptlgln: movem.l d0/d2/d3,-(a7)
        move.b #$30,d2
        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
        bra    lgnt
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
        move.l #log1tn-log1t,d1
        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
        jsr    cls
        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


gttmp:  movem.l d0/d1/d3/a0,-(a7)
        move.l  time,a0
        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,d0
        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)
        move.l  time,a0
        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)
        and.b   #$0f,d2
        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)+,d0/d1/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
       jsr      movec
       jsr      lohex	* print ls 4 bits
       rts		* return
*
sdb:    move.l  d0,-(a7)
        move.l  d2,d0
        lsr.w   #4,d0
        move.b  #$33,d2
        move.b  #$31,d3
        jsr     movec
        move.b  #$34,d2
        move.b  #$42,d3
        jsr     ch2hex
        move.l  (a7)+,d0
        rts

ptpn:   movem.l d1/d2/d3,-(a7)
        move.l  #$03,d1
        move.l  #1000,d3
pn1:    move.b  #$2f,d0
pn2:    add.b   #1,d0
        sub.l   d3,d2
        bcc     pn2
        add.l   d3,d2
        jsr     outch
        divu    #10,d3
        dbra    d1,pn1
        movem.l (a7)+,d1/d2/d3
        rts

ptsp:   movem.l d1/d2,-(a7)
        move.l  #22,d1
        lsr.l   d1,d2
        and.w   #$03ff,d2
        jsr     ptpn
        movem.l (a7)+,d1/d2
        rts

ptdp:   movem.l d1/d2,-(a7)
        move.l  #12,d1
        lsr.l   d1,d2
        and.w   #$03ff,d2
        jsr     ptpn
        movem.l (a7)+,d1/d2
        rts

evlog:  movem.l d2/d3,-(a7)
        move.b  #$30,d2
        move.b  #$37,d3
        jsr     movec
        move.l  d0,d2
        jsr     gttmp
        jsr     prtms
        move.b  #$32,d2
        move.b  #$34,d3
        jsr     movec
        move.l  d1,d2
        jsr     ptsp
        move.b  #$32,d2
        move.b  #$34,d3
        jsr     movec
        move.l  d1,d2
        jsr     ptdp
        jsr     sdb
        move.b  #$34,d2
        move.b  #$36,d3
        jsr     movec
        move.l  d1,d2
        jsr     ptev
        movem.l (a7)+,d2/d3
        rts

chst2:  btst   #0,stats2
        bne    error
        btst   #1,stats2
        bne    chst2
        btst   #2,stats2
        bne    chst2
        btst   #4,stats2
        bne    chst2
        rts

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

lgln:   movem.l d0/d2/d3,-(a7)
        jsr    wind1a
        move.w #$3137,d2
        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:  jsr    chst2
*       jsr    fetchv
        move.l  dbadrw,a0
        move.l  (a0)+,d0
        move.l  (a0),d1
        sub.l   d1,d0
        cmp.l   #08,d0
        bge     rdev
        move.b  #$08,stats2
        cmp.b   #$08,d5
        beq     nchnge
        jsr     upst
        move.b  #$08,d5
        rts
rdev:   move.b  #$00,stats2
        jsr     upst
        move.l  (a0),a1
        move.l  (a1)+,d0
        move.l  (a1)+,d1
        move.l  a1,(a0)
        jsr    lgln
        jsr    evlog
        cmp.b  #$00,d5
        beq    nchnge
        jsr    upst
        move.b #00,d5
nchnge: rts

inevlg: jsr    evlg1
        jsr    evlg2
*       move.b #$80,status          ***######
evg:    jsr    scrn3
*       jsr    upst
        btst   #7,status
        bne    evg
        rts

shdiag: jsr    windf2
        jsr    cls
        move.w #$3031,d2
        move.w #$3031,d3
        jsr    moveto
        lea    diagnp,a4
        move.l #diagnn-diagnp,d1
        jsr    pdata
shdig:  btst   #4,status
        bne    shdig
        rts

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

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

error:  move.w #$3033,d2
        move.w #$3631,d3
        jsr    moveto
        lea    err,a4
        move.l #errn-err,d1
        jsr    pdata
err1:   jmp    err1

chgst:  jsr    chst2
*       btst   #0,status
*       beq    nxtst4
*       move.l stack,a7     ***   Clear the stack
*       bra    start
        btst   #2,status
        beq    nxtst
        rts
nxtst:  btst   #4,status
        beq    nxtst1
        jsr    shdiag
nxtst1: btst   #5,status
        beq    nxtst2
        jsr    filtch
nxtst2: btst   #6,status
        beq    nxtst3
        jsr    inlsc2
nxtst3: btst   #7,status
        beq    chgst
        jsr    inevlg
        bra    chgst

        org    $034000

start:  jsr    init 
        jsr    windf
        jsr    cls
        jsr    intscn
        jsr    lprom
        jsr    chgst
*       jsr    inchu
*       jsr    inlsc2
*       jsr    inchu
*       jsr    inevlg
        jsr    grnled
*       jsr    lprom

        jmp    quitt
        jmp    stop
*

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