*****************************************************************************)
*                                                                           *)
*                                                                           *)
*    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       : 18th July 1989       Version 6.2                          *)
*                 Rev. 17 July 1989    Ver 6.2  to allow display of CentreNt*)
*                                      packet without processing.           *)
*                 Rev. 12 March 1990   Bugfixing.                           *)
*                                                                           *)
*    Supervisor : Damal K. ARVIND                                           *)
*                                                                           *)
*****************************************************************************)

fifo    equ    #$60000      * Address of the interprocess fifo
sdaddr  equ    $30000      * Source and destination address of Cent. Packet
dataMW  equ    $40000      * Most significant 16bits of the data field.
dataLW  equ    $50000      * Least significant 16 bits of the data fields.
cntfd   equ    $70000      * Control field of the centrenet packet.
led     equ    $70000      * LED address
cntrl2  equ    $10000
cntrl   equ    $10001     * Holding space for the packet which has just
sdadd   equ    $10002     * been read.
data1   equ    $10004
data2   equ    $10006
save    equ    $11002
hwcnt   equ    $11004     * Mirror register for H'ware control register.
evmode  equ    $12000     * Flag to indicate which mode, event or centrenet pkt.
ct      equ    $18000
sd      equ    $19000
dt      equ    $1a000
bhead   equ    #$af         * centrenet control field values to identify
bhack   equ    #$ae         * packet type.
dtpk    equ    #$bf
ltpk    equ    #$1f
dtack   equ    #$be
pkreq   equ    #$fffb      
greq    equ    #$fffa
ld2req  equ    #$fff8
ack     equ    #$fff7
ackreq  equ    #$fff3
clr     equ    #$ff                    * Clear all H'ware Flags.
grnoff  equ    #$01
redoff  equ    #$02
rgoff   equ    #$03                    * both leds off.
prqoff  equ    #$04
ackoff  equ    #$08
cepoff  equ    #$0c
grnon   equ    #$fe           * light green led.
redon   equ    #$fd           * light red led.
rgon    equ    #$fc           * light both leds.
prqon   equ    #$fb           * Initiate a packet request from the fifo.
ackon   equ    #$f7           * Acknowledge   
*
*
        org    $01000
*
*


*
*

clrled: move.b hwcnt,d0                  * LED off
        or.b   rgoff,d0
        move.b d0,led
        move.b d0,hwcnt
        rts
*
grnled: move.b hwcnt,d0                * LED on
        and.b  grnon,d0
        move.b d0,led
        move.b d0,hwcnt
        rts


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


redled: move.b hwcnt,d0
        and.b  redon,d0
        move.b d0,led
        move.b d0,hwcnt
        rts


bothled: move.b hwcnt,d0
        and.b rgon,d0
        move.b d0,led
        move.b d0,hwcnt
        rts

*readpk: movem.l d0/d1/a0/a1,-(a7)   * simulates the fifo by providing
*        move.l  ct,a1               * a packet and placing it in the 
*        move.l  (a1),a0             * holding ram space
*        move.w  (a0)+,d0
*        move.l  a0,(a1)
*        move.l  cntrl2,a1
*        move.w  d0,(a1)
*
*        move.l  sd,a1
*        move.l  (a1),a0
*        move.w  (a0)+,d0
*        move.l  a0,(a1)
*        move.l  sdadd,a1
*        move.w  d0,(a1)
*
*        move.l  dt,a1
*        move.l  (a1),a0
*        move.l  (a0)+,d0
*        move.l  a0,(a1)
*        move.l  data1,a1
*        move.l  d0,(a1)
*        movem.l (a7)+,d0/d1/a0/a1
*        rts
*
*

getpk:  movem.l d7/d0,-(a7)
        move.b #1,d7
        move.w ld2req,led
gpwait: cmp.b #0,d7
        beq gpclr
        move.w ld2req,led
        move.w evmode,d0
        cmp.w #0,d0
        beq gpwait
        movem.l (a7)+,d7/d0
        or.b  #$01,ccr       * set carry, mode change taken place
        rts
gpclr:  movem.l (a7)+,d7/d0
        and.b #$fe,ccr       * clear carry, packet available
        rts

centpk: movem.l a0/d0,-(a7) 
        move.l fifo,a0
        move.w cntfd,d0
        or.w   #$ff00,d0
        move.w d0,(a0)
        move.w sdaddr,(a0)
        move.w dataMW,(a0)
        move.w dataLW,(a0)
        movem.l (a7)+,a0/d0
        rts

cmode:  move.w evmode,d0
        cmp.w  #0,d0
        bne    cmend
        move.w both,led
        jsr    getpk
        bcs    cmend
        jsr    centpk
        cmp.w  #10,save
        beq    wait
        bra    cmode
cmend:  rts

eventid:move.w (a1),d5           * extract the event id
        and.w  #$0f0f,d5
        move.w d5,d4
        lsl.w  #4,d4
        add.w  d4,d5
        and.l  #$00000ff0,d5
        move.l data1,a3
        move.l (a3),d4
        and.l  #$fffff00f,d4
        add.w  d5,d4
        rts
*
*
tmstmp: move.l data1,a3           * get the timestamp
        move.l (a3),d3
        rts
*
*
sendev: move.l a0,-(a7)
        move.l fifo,a0
        move.l d3,(a0)
        move.l d4,(a0)
        move.l (a7)+,a0
        rts

dbase:  dc.l   $5,$1fef6c41
        dc.l   $7,$1fef6c4b
        dc.l   $19,$2f9f34c1
        dc.l   $40,$1fef6c49
        dc.l   $40,$2f9f34ca
        dc.l   $103,$251f37c1
        dc.l   $257,$251f37c6
        dc.l   $290,$2f9f34c2
        dc.l   $596,$251f37c7
        dc.l   $1214,$251f37cb
        dc.l   $5681,$251f37c9
        dc.l   $5681,$1fe50c7a
        dc.l   $12143,$2f9f34c4
        dc.l   $22772,$1fe50c75
        dc.l   $22772,$251f37c5
        dc.l   $79abcd,$1fe50c72

txdb:   move.l #16,d5
        lea    dbase,a1
        bra    chk
more:   move.l (a1)+,d3
        move.l (a1)+,d4
        jsr    sendev
chk:    dbra   d5,more
        move.w off,led
        rts
*
*
*

ctserv: move.w #0,evmode
scont:  cmp.b  #0,d7
*        beq    nord
*        move.w ackreq,led
*        rte
nord:   move.w ack,led
        rte

evserv: move.w #$ffff,evmode
        bra    scont

rfserv: move.w off,led       * clear interupt
        move.b #$00,d7       * clear flag

* move fields to holding ram space

*       move.w sdaddr,sdadd
*       move.w dataMW,data1
*       move.w dataLW,data2
*       move.w cntfd,cntrl2

* incr interrupt counter

        add.w #1,save

        rte


        org    $003000

init:   move.w green,led     * Turn on the green LED
        move.w #00,save      * A counter for number of Centrenet pk processed.
        and.w  #$f8ff,sr
*
        move.w #$ff,evmode   *  current mode default is EVENT MONIT. mode
        rts

start:  jsr    init

*        move.w off,led           * the main part is to check for correct 
        jsr    txdb

p1cont: move.w evmode,d0
        cmp.w  #0,d0
        bne    ntest
        move.w both,led
*        jsr    cmode
        bra    p1cont
ntest:  move.w off,led           * extract event packet information 
        bra    p1cont

wait:   move.w green,led
wait2:  jmp    wait2

*                                * handshake
*nobhd:  jsr    readpk            * read next centrenet packet
*        move.l cntrl,a0          * get control field
*        move.b (a0),d0
*        cmp.b  bhead,d0          * is packet a burst header?
*        bne    halt          *nobhd             * no !
*        move.l sdadd,a1          * get source & dest processor addresses
*        move.w (a1),d1
*        rol.w  #8,d1             * swap addresses
*nohack: jsr    readpk
*        move.b (a0),d2
*        cmp.b  bhack,d2          * is packet burst header ack?
*        bne    halt          *nohack            * No!
*        move.w (a1),d2
*        cmp.b  d2,d1             * Do source & dest address match
*        bne    halt          *nohack            * No!
*nodtpk: jsr    readpk            * read next centrenet packet
*        move.b (a0),d0
*        cmp.b  dtpk,d0           * Is this packet a data packet
*        bne    halt          *nodtpk
*        jsr    eventid           * Generate event identifaction
*notmsp: jsr    readpk
*        move.b (a0),d0
**        cmp.b  enddt,d0
**        beq    endpk
*        cmp.b  dtpk,d0
*        bne    halt          *notmsp
*        jsr    tmstmp            * Generate time stamp
*moredt  jsr    readpk
*        move.b (a0),d0
*        cmp.b  ltpk,d0           * Last data packet ?
*        bne    halt          *moredt
*nopack: jsr    readpk
*        cmp.b  dtack,(a0)        * Burst data ack ?
*        bne    halt          *nopack
*        cmp.w  (a1),d1           * source & dest match ?
*        bne    nopack
*        jsr    sendev            * pass on event log
**
*        move.w green,led
*halt:   trap   #0
*
*        bra    nobhd             * repeat

berr:   move.w red,led
berr1   jmp    berr1        *IN CASE OF BUSERROR
adderr: move.w red,led
aderr1: jmp    aderr1      *IN CASE OF ADDRERROR

        org    $0
        dc.l   $1fffe       *SETUP STACK POINTER
        dc.l   start        *START OF PROGRAM
        dc.l   berr         *BUSERROR VECTOR
        dc.l   adderr       *ADDRERROR VECTOR

        org    $68
        dc.l   ctserv       * Clear event flag to false

        org    $6c
        dc.l   evserv       * set event flag to true

        org    $78
        dc.l   rfserv       * storage fifo read service routine.
*
         END
