*****************************************************************************)
*                                                                           *)
*                                                                           *)
*    Program    : Interpretation System Software for EDDE.                  *)
*                                                                           *)
*    Purpose    : Extract packets from the Network buffer, converting them  *)
*                 to event packets and sending them to the Display Proc Brd *)
*                                                                           *)
*    Name       : Vinod E.F. REBELLO                                        *)
*                                                                           *)
*    Class      : CS & E 4                                                  *)
*                                                                           *)
*    Username   : VEFR                                                      *)
*                                                                           *)
*    Date       : 23rd March 1990      Version 3.0                          *)
*                 Rev: 5th May 1990    - bugfix                             *)
*                 20 july 1990 - to test data on reboot                     *)
*                 8 oct 1990 - debugging.                                   *)
*                 22 oct 1990 - converted to ram software for monitor use   *)
*                                                                           *)
*    Supervisor : Damal K. ARVIND                                           *)
*                                                                           *)
*****************************************************************************)

fifo    equ    #$60000    * Address of the interprocess fifo
sdaddr  equ    $30000     * Source and destination address of Cent. Packet
dataMW  equ    $50000     * Most significant 16bits of the data field.
dataLW  equ    $40000     * Least significant 16 bits of the data fields.
cntfd   equ    $70000     * Control field of the centrenet packet.
led     equ    $70000     * LED address
cntrl   equ    $10000
cntrl2  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    $13000
sd      equ    $14000
dt      equ    $15000
bhead   equ    #$af       * centrenet control field values to identify
bhack   equ    #$ae       * packet type.
dtpk    equ    #$bf
ltpk    equ    #$1f
dtack   equ    #$be
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    $18000     * was $01000 when prom software.

clrled: move.b hwcnt,d0                  * LED off
        or.b   rgoff,d0
        move.w d0,led
        move.b d0,hwcnt
        rts
*
grnled: move.b hwcnt,d0                * LED on
        and.b  grnon,d0
        move.w 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


pkreq:  move.b hwcnt,d0
        and.b  prqon,d0
        move.b d0,hwcnt
        move.w d0,led
        rts

clrrq:  move.b hwcnt,d0
        or.b   prqoff,d0
        move.w d0,led
        move.b d0,hwcnt
        rts

sndack: move.b hwcnt,d0
        and.b  ackon,d0
        move.w d0,led
        move.b d0,hwcnt
        rts

clrack: move.b hwcnt,d0
        or.b   ackoff,d0
        move.b d0,hwcnt
        move.w d0,led
        rts

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


bothled: move.b hwcnt,d0
        and.b rgon,d0
        move.w 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  cntrl,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
        jsr    pkreq
gpwait: cmp.b  #0,d7
        beq    gpclr 
        jsr    clrack
        jsr    grnled
        bra    gpwait
*        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.w save,d1
        lsl.w  #8,d1
        move.l fifo,a0
        move.w cntrl,d0
        and.w  #$00ff,d0
        or.w   d1,d0
        move.w d0,(a0)
        move.w sdadd,(a0)
        move.w data1,(a0)
        move.w data2,(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.l cntrl,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,d4           * process info suppose to be in second pk.
        and.l  #$fffff00f,d4
        add.w  d5,d4
        rts
*
*
tmstmp: move.l data1,d3           * get the timestamp
        rts
*
*
sendev: move.l a0,-(a7)
*        jsr    eventid
*        jsr    tmstmp
        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
        jsr    clrled
        rts
*
*
*

ctserv: trap   #0
        jsr    sndack
        move.w #0,evmode
        rte

evserv: trap   #0
        jsr    sndack
        move.w #$ffff,evmode
        rte

rfserv: jsr    clrrq         * 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,cntrl 

* incr interrupt counter

        add.w #1,save
        rte



init:   or.w   #$0700,sr     * Disable interupts
        move.w #$ffff,led
        move.b #$ff,hwcnt
        jsr    grnled        * Turn on the green LED
        move.w #00,save      * A counter for number of Centrenet pk processed.
        move.w #$00,evmode   *  current mode default is CENTRNT PAK. mode
*                            * mode setup for centrenet packets : for develpmt.

* TESTing  fifo
        and.w  #$fcff,sr
*        or.w   #$0500,sr     * for testing disable interproc handshake.
        rts

        org    $01a000       * was $03000
start:  jsr    init

        jsr    clrled           * the main part is to check for correct 
*        jsr    txdb


p1cont: jsr    getpk
        move.w evmode,d0
        cmp.w  #0,d0
        bne    ntest
        jsr    bothled
        jsr    clrack
        jsr    centpk
*     trap   #0
        bra    p1cont
ntest:  jsr    clrled           * extract event packet information 
        jsr    clrack
        jsr    sendev
        bra    p1cont

wait:   jsr    grnled
wait2:  trap   #0               * was   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:   jsr    clrled
*        jsr    redled
*berr1   jmp    berr1        *IN CASE OF BUSERROR
*adderr: jsr    clrled
*        jsr    redled
*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.


*   Interrupt vectors for use with 68000 software monitor.
*

         org    $1fe48
         jmp    ctserv

         org    $1fe50
         jmp    evserv

         org    $1fe68
         jmp    rfserv

         END
