home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 3 / Meeting_Pearls_III.iso / Pearls / comm / Networking / ProNET / source.lzx / drivers / internal-parallel.s next >
Text File  |  1991-06-20  |  10KB  |  489 lines

  1. **
  2. ** ProNET-Driver `internal-parallel'
  3. **
  4. ** 07-05-95    Started
  5. ** 29-05-95    bset -> or  etc..
  6. ** 31-05-95    machine priority system :-(
  7. ** 05-06-95    init: flags argument
  8.  
  9. ; Format of one packet is:
  10. ; 2bytes LENGTH of data including next two words in WORDS-1 !!!!!
  11. ; 2bytes Destination port
  12. ; 2bytes Source port
  13. ; xbytes DATA
  14.  
  15. DISABLEINTS    macro
  16.         move.w    #$4000,$dff09a
  17.         endm
  18. ENABLEINTS    macro
  19.         move.w    #$c000,$dff09a
  20.         endm
  21.  
  22.         include    "A:OSmacros.i"
  23.         include    "exec/exec.i"
  24.         include    "resources/misc.i"
  25.         include    "hardware/cia.i"
  26.         include    "a:ProNET/include/devices/pronet.i"
  27.         include    "exec_lib.i"
  28.         include    "intuition_lib.i"
  29.         include    "dos_lib.i"
  30.  
  31. ; -- Initialization routine
  32. Init        ; a0 *DriverData
  33.         ; a1 *ConfigString after driver ID
  34.         ; d0 "RST!" for Identification
  35.         ; d1 Flags
  36.         ; RETURNS d0 <>0 if everything OK, else NULL!
  37.         movem.l    d2-d7/a2-a6,-(sp)
  38.         move.l    a0,a4
  39.         move.l    a1,a5
  40.         cmp.l    #"RST!",d0        ;compare ID
  41.         bne    .error
  42.         tst.l    d1
  43.         bne    .error            ;unknown Flags!
  44.  
  45.         bsr    AllocPPort
  46.         tst.w    d0
  47.         bne    .error
  48.  
  49.         move.l    a5,a0
  50.         bsr    dec2slong
  51.         move.w    d1,MACHINE
  52.         bsr    dec2slong
  53.         move.w    d1,PRIORITY
  54.  
  55.         bsr    InitTransfer
  56.         bsr    TrapOpenDevice
  57.  
  58.         move.l    4.w,a6
  59.         move.l    ThisTask(a6),a1
  60.         move.w    PRIORITY(pc),d0
  61.         LIBCALL    SetTaskPri
  62.  
  63.         move.b    INTsigbit(pc),(a4)    ;Read Signalbit
  64.         move.l    #ReadQuery,2(a4)
  65.         move.l    #Read,6(a4)
  66.         move.l    #Write,10(a4)
  67.         moveq    #-1,d0
  68.         bra.s    .ende
  69.  
  70. .error        moveq    #0,d0
  71. .ende        movem.l    (sp)+,d2-d7/a2-a6
  72.         rts
  73.  
  74.         dc.b    "$VER: pronet-driver `internal-parallel' (05-06-95)",13,10,0
  75.         even
  76.  
  77. PRIORITY    dc.w    0
  78. MACHINE        dc.w    0
  79.  
  80. dec2slong    ; konvertiert Dezimalstring ab (a0) zu Longword in D1 !!
  81.         ; SIGNED!
  82.         moveq    #0,d1
  83.         moveq    #0,d3
  84.         move.b    (a0),d0
  85.         cmp.b    #"-",d0
  86.         bne.s    .loop
  87.         addq.l    #1,a0
  88.         st    d3
  89. .loop        moveq    #0,d0
  90.         move.b    (a0)+,d0
  91.         sub.b    #"0",d0
  92.         cmp.b    #9,d0
  93.         bhi.s    .oki
  94.         move.l    d1,d2
  95.         lsl.l    #3,d1
  96.         add.l    d2,d1
  97.         add.l    d2,d1
  98.         add.l    d0,d1
  99.         bra.s    .loop
  100. .oki        tst.w    d3
  101.         beq.s    .ende
  102.         neg.l    d1
  103. .ende        rts
  104.  
  105. ; -- Read Query routine
  106. ReadQuery    ; RETURNS d0 length of pure data to come or NULL
  107.         ;         d1 destport
  108.         ;         d2 sourceport
  109.         movem.l    d3-d7/a2-a6,-(sp)
  110.         lea    $bfd000,a2    ; test if packet is pending
  111.         btst    #0,(a2)
  112.         bne.s    .error
  113.         lea    $bfd200,a3    ; ciab ddra
  114.         bset    #1,(a3)        ; set ack line to output
  115.         lea    buffer-2(pc),a4    ; first word is `empty'
  116.         moveq    #3,d4        ; (due to handshake init)
  117.         bsr    ReceiveData
  118.         movem.w    buffer(pc),d0-d2
  119.         subq.w    #2-1,d0
  120.         add.w    d0,d0
  121.         movem.l    (sp)+,d3-d7/a2-a6
  122.         rts
  123. .error        moveq    #0,d0
  124.         movem.l    (sp)+,d3-d7/a2-a6
  125.         rts
  126.  
  127. ; -- Read routine
  128. Read        ; a0 *destination
  129.         movem.l    d2-d7/a2-a6,-(sp)
  130.         move.l    a0,a4
  131.         move.w    buffer(pc),d4
  132.         subq.w    #2,d4
  133.         bsr    ReceiveData
  134.         lea    $bfd200,a3    ; ciab ddra
  135.         bclr    #1,(a3)        ; set ack line to input
  136.         movem.l    (sp)+,d2-d7/a2-a6
  137.         rts
  138.  
  139.  
  140. ; -- Write routine
  141. Write        ; a0 *data1
  142.         ; d0.l datalength1 (even)
  143.         ; a1 *data2
  144.         ; d1.l datalength2 (even)
  145.         ; d2 Destination Port
  146.         ; d3 Source Port
  147.         ; d0+d1 <= $4000
  148.         ; d1=0 --> only first chunk is sent, else second is appended
  149.         ;          to first one and sent as one chunk!
  150.         ; RETURNS d0 <>0 on error, else NULL
  151.         movem.l    d2-d7/a2-a6,-(sp)
  152.  
  153.         lea    buffer(pc),a5
  154.         movem.l    d0/d1/a0/a1,6(a5)
  155.  
  156.         move.w    d2,(a5)
  157.         move.w    d3,2(a5)
  158.  
  159.         move.w    d0,d4
  160.         add.w    d1,d4
  161.         lsr.w    #1,d4
  162.         addq.w    #2-1,d4
  163.         bsr    AcquireLine
  164.         tst.w    d0            ;Line is busy now! Try later
  165.         bne.s    .ende
  166.  
  167.         move.l    a5,a4
  168.         moveq    #1,d4
  169.         moveq    #0,d6
  170.         bsr    SendData
  171.  
  172.         move.l    14(a5),a4
  173.         move.l    6(a5),d4
  174.         lsr.w    #1,d4
  175.         subq.w    #1,d4
  176.         tst.w    12(a5)
  177.         beq.s    .0
  178.  
  179.         bsr    SendData
  180.  
  181.         move.l    18(a5),a4
  182.         move.l    10(a5),d4
  183.         lsr.w    #1,d4
  184.         subq.w    #1,d4
  185.  
  186. .0        subq.w    #1,d4
  187.         bmi.s    .lastone
  188.         bsr    SendData
  189.  
  190. .lastone    DISABLEINTS        * We don't take too long here
  191.         moveq    #0,d4        * in case the other machine wants
  192.         bsr    SendData    * to send something...
  193.  
  194.         lea    $bfd200,a3
  195.         and.b    #%11111000,(a3)    ; all control lines input
  196.         lea    $bfe301,a1
  197.         sf    (a1)        ; data lines input, too
  198.         lea    $bfd000,a2    ; ciab pra   ==> CONTROL LINES
  199.         or.b    #%00000111,(a2)
  200.         ENABLEINTS
  201.  
  202.         moveq    #0,d0
  203. .ende        movem.l    (sp)+,d2-d7/a2-a6
  204.         rts
  205.  
  206.         dc.w    0
  207. buffer        dc.w    0,0,0
  208.         dc.l    0,0,0,0
  209.  
  210. ** -----------------------------------------------------------------------
  211. **
  212. **
  213. **
  214. **
  215.  
  216. **
  217. ** Parallel.device trapping
  218. **
  219.  
  220. **
  221. **
  222. **
  223. **
  224. ** -----------------------------------------------------------------------
  225.  
  226. TrapOpenDevice    move.l    4.w,a6
  227.         move.l    a6,a1
  228.         move.l    #_LVOOpenDevice,a0
  229.         move.l    #.trap,d0
  230.         LIBCALL    SetFunction
  231.         move.l    d0,orgopendev
  232.         rts
  233. .trap        movem.l    a0/a1/d0/d1,-(sp)
  234.         lea    parname(pc),a1
  235.         bsr    CompareStrings
  236.         tst.w    d0
  237.         bne.s    .openit
  238.         movem.l    (sp)+,a0/a1/d0/d1
  239.         move.b    #-1,IO_ERROR(a1)
  240.         moveq    #-1,d0            ;IOERR_OPENFAIL
  241.         rts
  242. .openit        movem.l    (sp)+,a0/a1/d0/d1
  243.         move.l    a2,-(sp)
  244.         move.l    orgopendev(pc),a2
  245.         jsr    (a2)
  246.         move.l    (sp)+,a2
  247.         rts
  248. orgopendev    dc.l    0
  249.  
  250. ; -- Compare two null-terminated strings. Case-insensitive
  251. CompareStrings    ; a0 *String1
  252.         ; a1 *String2
  253.         ; RETURNS d0 = 0 --> Strings equal
  254.         move.l    d2,-(sp)
  255.         moveq    #-1,d0
  256. .loop        move.b    (a0)+,d1
  257.         move.b    (a1)+,d2
  258.         bclr    #5,d1
  259.         bclr    #5,d2
  260.         cmp.b    d1,d2
  261.         bne.s    .ende
  262.         tst.b    d1
  263.         bne.s    .loop
  264.         moveq    #0,d0
  265. .ende        move.l    (sp)+,d2
  266.         rts
  267.  
  268. parname        dc.b    "parallel.device",0
  269.  
  270. ** -----------------------------------------------------------------------
  271. **
  272. **
  273. **
  274. **
  275.  
  276. **
  277. ** Built-in Parallel Port Transfer routines
  278. **
  279.  
  280. **
  281. **
  282. **
  283. **
  284. ** -----------------------------------------------------------------------
  285.  
  286. ; -- Allocate Parallel Port Registers
  287. AllocPPort    lea    miscname(pc),a1
  288.         move.l    4.w,a6
  289.         LIBCALL    OpenResource
  290.         move.l    d0,a6
  291.         move.l    #MR_PARALLELPORT,d0
  292.         lea    INTname(pc),a1
  293.         jsr    -6(a6)            ;AllocMiscResource
  294.         tst.w    d0
  295.         bne.s    .err1
  296.         move.l    #MR_PARALLELBITS,d0
  297.         lea    INTname(pc),a1
  298.         jsr    -6(a6)
  299.         tst.w    d0
  300.         bne.s    .err2
  301.         moveq    #0,d0
  302.         rts
  303. .err2        move.l    #MR_PARALLELPORT,d0
  304.         jsr    -12(a6)            ;FreeMiscResource
  305. .err1        move.l    4.w,a6
  306.         moveq    #-1,d0
  307.         rts
  308. miscname    dc.b    "misc.resource",0
  309. ciaaname    dc.b    "ciaa.resource",0
  310.         even
  311. ciaabase    dc.l    0
  312.  
  313. ; -- Init Transfer routines
  314. InitTransfer    movem.l    d7/a2/a3/a6,-(sp)
  315.  
  316.         move.l    4.w,a6
  317.         move.l    ThisTask(a6),INTsigtask
  318.  
  319.         moveq    #-1,d0
  320.         LIBCALL    AllocSignal
  321.         move.b    d0,INTsigbit
  322.  
  323.         bsr    InitParallel
  324.  
  325.         lea    ciaaname(pc),a1
  326.         move.l    4.w,a6
  327.         LIBCALL    OpenResource
  328.         move.l    d0,a6
  329.         move.l    d0,ciaabase
  330.         moveq    #CIAICRB_FLG,d0
  331.         lea    INTstruct(pc),a1
  332.         jsr    -6(a6)
  333.  
  334.         movem.l    (sp)+,d7/a2/a3/a6
  335.         rts
  336.  
  337. INTsigtask    dc.l    0
  338. INTsigbit    dc.w    0
  339.  
  340. INTstruct    dc.l    0,0
  341.         dc.b    2,127
  342.         dc.l    INTname
  343.         dc.l    0,INTcode
  344. INTname        dc.b    "ProNET Internal-Parallel Driver",0
  345.         even
  346. INTcode        lea    $bfd000,a0        ;check if the interrupt
  347.         btst    #0,(a0)            ;was `correct' or caused
  348.         bne.s    .no            ;by switching on the remote
  349.         move.l    4.w,a6            ;machine
  350.         move.l    INTsigtask(pc),a1
  351.         move.b    INTsigbit(pc),d1
  352.         moveq    #0,d0
  353.         bset    d1,d0
  354.         LIBCALL    Signal
  355. .no        moveq    #1,d0
  356.         rts
  357.  
  358. ;:---------------------------------------------------------------------------
  359. ;:-- InitParallel
  360. InitParallel
  361.         lea    $bfe101,a0    ; ciaa prb   ==> DATA LINES
  362.         lea    $bfe301,a1    ; ciaa ddrb
  363.         lea    $bfd000,a2    ; ciab pra   ==> CONTROL LINES
  364.         lea    $bfd200,a3    ; ciab ddra
  365.  
  366.         and.b    #%11111000,(a3)    ; all control lines input  ---|
  367.         sf    (a1)        ; [[data lines input, too]]   v
  368.         or.b    #%00000111,(a2)    ; and 1 when we set them to output
  369.         rts
  370.  
  371. ;:---------------------------------------------------------------------------
  372. ;:-- AcquireLine
  373. ;:-- d4 Number of words-1 that will be sent !
  374. ;:-- !!!!!! RETURNS d0=0  if no error
  375. ;:--                d0<>0 if line was busy
  376. AcquireLine
  377.         lea    $bfd000,a2    ; ciab pra   ==> CONTROL LINES
  378.         lea    $bfd200,a3    ; ciab ddra
  379.  
  380.         DISABLEINTS
  381.         btst    #0,(a2)
  382.         bne.s    .free
  383.         ENABLEINTS
  384.         moveq    #-1,d0
  385.         rts
  386.  
  387. .free        bset    #0,(a3)
  388.         bclr    #0,(a2)
  389.  
  390.         bset    #2,(a3)        ; cause interrupt by quickly toggling
  391.         bclr    #2,(a2)        ; the FLAG input of the other
  392.         bset    #2,(a2)        ; machine
  393.         bclr    #2,(a3)
  394.  
  395.         move.l    ciaabase(pc),a6    ; reset interrupt flag which was
  396.         moveq    #CIAICRF_FLG,d0    ; set on our machine, too
  397.         jsr    -24(a6)        ; (SEL&ACK connected at parallel port)
  398.  
  399.         ENABLEINTS
  400.  
  401.         lea    $bfe101,a0    ; ciaa prb   ==> DATA LINES
  402.         lea    $bfe301,a1    ; ciaa ddrb
  403.  
  404.         tst.w    firstpacketflag    ; no timeout for the first packet!
  405.         beq.s    .acknotimeout
  406.         tst.w    MACHINE        ; no timeout for machine 1!
  407.         bne.s    .acknotimeout
  408.  
  409.         move.l    #100000,d0
  410. .ack0        btst    #1,(a2)        ; wait for it to respond...
  411.         beq.s    .ack0ok
  412.         subq.l    #1,d0
  413.         bne.s    .ack0
  414.  
  415.         bset    #0,(a2)
  416.         and.b    #%11111000,(a3)    ; TIMEOUT! reset all lines
  417.         or.b    #%00000111,(a2)
  418.         bsr    INTcode
  419.         moveq    #-1,d0
  420.         rts
  421.  
  422. .acknotimeout    btst    #1,(a2)
  423.         bne.s    .acknotimeout
  424.  
  425. .ack0ok        st    firstpacketflag
  426.         bset    #0,(a2)        ; and initialize handshake sequence
  427. .ack1        btst    #1,(a2)
  428.         beq.s    .ack1
  429.  
  430.         st    (a1)        ; set data lines to output now
  431.         ror.w    #8,d4        ; and hand the length word over
  432.         move.b    d4,(a0)        ; to the remote machine
  433.         bclr    #0,(a2)
  434.         ror.w    #8,d4
  435. .ack2        btst    #1,(a2)
  436.         bne.s    .ack2
  437.         move.b    d4,(a0)
  438.         bset    #0,(a2)
  439. .ack3        btst    #1,(a2)
  440.         beq.s    .ack3
  441.         moveq    #0,d0
  442.         rts
  443.  
  444. firstpacketflag    dc.w    0
  445.  
  446. ;:---------------------------------------------------------------------------
  447. ;:-- SendData
  448. ;:-- a4 *data
  449. ;:-- d4 datalength in words-1
  450. SendData
  451.         lea    $bfe101,a0    ; ciaa prb   ==> DATA LINES
  452.         lea    $bfd000,a2    ; ciab pra   ==> CONTROL LINES
  453.  
  454.         move.b    #%11111110,d0
  455.         move.b    #%00000001,d1
  456.  
  457. .loop        move.b    (a4)+,(a0)    ; fully handshaked data txfer
  458.         and.b    d0,(a2)
  459. .ack0        btst    #1,(a2)
  460.         bne.s    .ack0
  461.         move.b    (a4)+,(a0)
  462.         or.b    d1,(a2)
  463. .ack1        btst    #1,(a2)
  464.         beq.s    .ack1
  465.         dbra    d4,.loop
  466.         rts
  467.  
  468. ;:---------------------------------------------------------------------------
  469. ;:-- ReceiveData
  470. ;:-- a4 *datadest
  471. ;:-- d4 datalength in words-1
  472. ReceiveData
  473.         lea    $bfe101,a0    ; ciaa prb   ==> DATA LINES
  474.         lea    $bfd000,a2    ; ciab pra   ==> CONTROL LINES
  475.  
  476.         move.b    #%11111101,d0
  477.         move.b    #%00000010,d1
  478.  
  479. .loop        btst    #0,(a2)
  480.         bne.s    .loop
  481.         move.b    (a0),(a4)+
  482.         and.b    d0,(a2)
  483. .ack0        btst    #0,(a2)
  484.         beq.s    .ack0
  485.         move.b    (a0),(a4)+
  486.         or.b    d1,(a2)
  487.         dbra    d4,.loop
  488.         rts
  489.