home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / bbs / bt310ab5 / driver.s < prev    next >
Text File  |  1993-10-02  |  12KB  |  617 lines

  1. ; History of DRIVER.S (BINKLEY.IO)        (Please set tab=2!)
  2. ;
  3. ; Following versions (c) St.Slabihoud
  4. ;
  5. ; 0.9x - beta testversions
  6. ; 1.00 - first official driver (only for ST)
  7. ; 1.01 - some improvements
  8. ; 1.02 - more functions implemented
  9. ; 1.03 - TT and STE support
  10. ; 1.04 - Falcon support? Hope it works...
  11. ; 1.05 - Reading/Writing from/to SCCs with a little bus delay (nop)
  12.  
  13.                     MC68000
  14.                             
  15. MFPPORT1    EQU        0x00fffa01
  16. MFPPORT2    EQU        0x00fffa81
  17. SCCA_CNT    EQU        0xFFFF8C81
  18. SCCB_CNT    EQU        0xFFFF8C85
  19.  
  20. ;    This code is called once to get the address of the jumptable.
  21. ; It is also allowed to print a small intro.
  22.  
  23. ; Do not forget to save register A2 - PureC needs it!
  24.  
  25. start:                movem.l    d1-d7/a1-a6,-(sp)
  26.                             pea            init(pc)
  27.                             move.w    #9,-(sp)
  28.                             trap        #1
  29.                             addq.w    #6,sp
  30.                             pea            get_hardware(pc)
  31.                             move.w    #38,-(sp)
  32.                             trap        #14
  33.                             addq.w    #6,sp
  34.                             tst.w        d0
  35.                             bne.s        no_st
  36.                             pea            _st(pc)
  37.                             bra.s        jump
  38. no_st:                subq.w    #1,d0
  39.                             bne.s        no_ste
  40.                             pea            _ste(pc)
  41.                             bra.s        jump
  42. no_ste:                subq.w    #1,d0
  43.                             bne.s        no_tt
  44.                             pea            _tt(pc)
  45.                             bra.s        jump
  46. no_tt:                subq.w    #1,d0
  47.                             bne.s        no_falcon
  48.                             pea            _falc(pc)
  49.                             bra.s        jump
  50. no_falcon:        pea            _unkn(pc)
  51. jump:                    move.w    #9,-(sp)
  52.                             trap        #1
  53.                             addq.w    #6,sp
  54.                             pea            _end(pc)
  55.                             move.w    #9,-(sp)
  56.                             trap        #1
  57.                             addq.w    #6,sp
  58.                             movem.l    (sp)+,d1-d7/a1-a6
  59.                             lea            tabelle(pc),a0
  60.                             move.l    a0,d0
  61.                             rts
  62.  
  63. get_hardware:    move.l    $5a0.w,a0
  64.                             move.l    a0,d0                * No Cookie-Jar found -> ST
  65.                             beq.s        ende
  66. loop:                    cmp.l        #'_MCH',(a0)
  67.                             bne.s        not_found
  68.                             move.l    4(a0),d0
  69.                             bra.s        ende
  70. not_found:        addq.w    #8,a0
  71.                             move.l    -8(a0),d0
  72.                             bne.s        loop
  73.                             moveq        #0,d0
  74. ende:                    swap        d0
  75.                             lea            HARDWARE(pc),a0
  76.                             move.w    d0,(a0)
  77.                             rts
  78.                             
  79. ; Jumptable: Some functions are called in the SupervisorMode!
  80.  
  81. ;  0 - get dcd status (<>0 : carrier detected)
  82. ;  4 - get cts status (<>0 : cts detected)
  83. ;  8 - send a byte to seriel port (d0.w : character)
  84. ; 12 - send chars to seriel port (a0.l : address, d0.l : number of bytes,
  85. ;                                                                    d1.w : CD check)
  86. ; 16 - set defaultport, only called if TOS support Bconmap (d0.w : Port n)
  87. ; 20 - read a character from seriel port
  88. ; 24 - characters available from seriel port?
  89. ; 28 - possible to send a character?
  90. ; 32 - peek a byte from seriel buffer (do not read it)
  91. ; 36 - turn DTR on
  92. ; 40 - turn DTR off
  93. ; 44 - Nothing to send?
  94.  
  95. tabelle:
  96.                     bra.w        get_dcd                *    0            Called in supervisor
  97.                     bra.w        get_cts                *    4               "    "      "
  98.                     bra.w        sendbyte            *    8
  99.                     bra.w        sendchars            * 12
  100.                     bra.w        set_new_port    * 16
  101.                     bra.w        modemin                *    20
  102.                     bra.w        charavail            * 24
  103.                     bra.w        outfull                * 28
  104.                     bra.w        peekbyte            * 32
  105.                     bra.w        dtr_on                * 36        Called in supervisor
  106.                     bra.w        dtr_off                * 40             "    "      "
  107.                     bra.w        outempty            * 44
  108.                     dc.l        0                            * 48
  109.                     dc.l        0                            * 52
  110.                     dc.l        0                            * 56
  111.                     dc.l        0                            * 60
  112.                     dc.l        0                            * 64
  113.                     dc.l        0                            * 68
  114.                     dc.l        0                            * 72
  115.                     dc.l        0                            * 76
  116.  
  117. ; Following variables are set by Binkley (Read-Only)
  118. ;
  119. ; VERSION is the version of the external driver!
  120. ; PORT is the portnumber set in BINKLEY.CFG with "Port".
  121. ;     TT        1 = MFP   (Modem-1)
  122. ;                2 = SCC-B (Modem-2)
  123. ;                3 = TTMFP (Seriell-1) (not usable for Binkley)
  124. ;                4 = SCC-A (Seriell-2)
  125. ;  STE    1 = MFP   (Modem-1)
  126. ;                2 = SCC-B (Seriell-2)
  127. ;                3 = SCC-A (Modem-2)
  128. ;  F030 2 = SCC-B (Seriell)
  129. ; HARDCTS
  130. ;            FALSE (0) Do not use HardCTS
  131. ;            TRUE  (1) Use HardCTS control
  132. ; TIME_RELEASE
  133. ;            Address of "time_release"-function in BT.
  134. ; HARDWARE ("_MCH"-Cookie)
  135. ;     0 = ST,MEGA-ST
  136. ;     1 = STE,MEGA-STE
  137. ;     2 = TT
  138. ;            3 = Falcon
  139.  
  140. VERSION:            dc.w        0x0105                * 80
  141. PORT:                    dc.w        0                            * 82 read-only
  142. HARDCTS:            dc.w        0                            * 84 read-only
  143. TIME_RELEASE:    dc.l        0                            * 86 read-only
  144. HARDWARE:            dc.w        0                            * 90 read-only
  145.  
  146. init:    dc.b    13,10
  147.             dc.b    ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ',13,10
  148.             dc.b    ' | External Binkley-Driver V1.05 | ',13,10
  149.             dc.b    ' | (c) St.Slabihoud 1993         | ',13,10
  150.             dc.b    ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ',13,10,0
  151. _st:    dc.b    ' | Binkley uses ST hardware      | ',13,10,0
  152. _ste:    dc.b    ' | Binkley uses STE hardware     | ',13,10,0
  153. _tt:    dc.b    ' | Binkley uses TT hardware      | ',13,10,0
  154. _falc:dc.b    ' | Binkley uses Falcon hardware  | ',13,10,0
  155. _unkn:dc.b    ' | Unknown hardware              | ',13,10,0
  156. _end:    dc.b    ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ',13,10,13,10,0
  157.             EVEN
  158.  
  159. ; Get carrier detect signal
  160.  
  161. get_dcd:
  162.         move.w    PORT(pc),d0
  163.         tst.w        d0
  164.         beq.s        dcd_mfpport1
  165.         subq.w    #1,d0
  166.         beq.s        dcd_mfpport1        * (Modem-1)
  167.         subq.w    #1,d0
  168.         beq.s        dcd_sccb_cnt        * (Modem-2)
  169.  
  170.         lea            HARDWARE(pc),a0
  171.         cmp.w        #1,(a0)                    * STE-Hardware?
  172.         beq.s        dcd_ste
  173.  
  174.         subq.w    #1,d0
  175. ;        beq.s        dcd_mfpport2        * (Seriell-1) returns no CD
  176.  
  177. dcd_ste:
  178.         subq.w    #1,d0
  179.         beq.s        dcd_scca_cnt        * (Seriell-2)
  180.         moveq.l    #8,d0
  181.         rts
  182.  
  183. dcd_mfpport1:
  184.         moveq.l    #0,d0
  185.         move.b    MFPPORT1,d0            * ~dcd & 2
  186.         not.b        d0
  187.         and.b        #2,d0
  188.         rts
  189. ;dcd_mfpport2:
  190. ;        moveq.l    #0,d0
  191. ;        move.b    MFPPORT2,d0            * ~dcd & 2
  192. ;        not.b        d0
  193. ;        and.b        #2,d0
  194. ;        rts
  195. dcd_sccb_cnt:
  196.         moveq.l    #0,d0
  197.         move.b    #0,SCCB_CNT
  198.         nop
  199.         nop
  200.         move.b    SCCB_CNT,d0            * dcd & 8
  201.         and.b        #8,d0
  202.         rts
  203. dcd_scca_cnt:
  204.         moveq.l    #0,d0
  205.         move.b    #0,SCCA_CNT
  206.         nop
  207.         nop
  208.         move.b    SCCA_CNT,d0            * dcd & 8
  209.         and.b        #8,d0
  210.         rts
  211.  
  212. ; Get CTS signal
  213.  
  214. get_cts:
  215.         move.w    PORT(pc),d0
  216.         tst.w        d0
  217.         beq.s        cts_mfpport1
  218.         subq.w    #1,d0
  219.         beq.s        cts_mfpport1
  220.         subq.w    #1,d0
  221.         beq.s        cts_sccb_cnt
  222.  
  223.         lea            HARDWARE(pc),a0
  224.         cmp.w        #1,(a0)                    * STE-Hardware?
  225.         beq.s        cts_ste
  226.  
  227.         subq.w    #1,d0
  228. ;        beq.s        cts_mfpport2        * (Seriell-1) returns no CTS
  229.  
  230. cts_ste:
  231.         subq.w    #1,d0
  232.         beq.s        cts_scca_cnt
  233.         moveq.l    #8,d0
  234.         rts
  235.  
  236. cts_mfpport1:
  237.       moveq.l    #0,d0
  238.         move.b    MFPPORT1,d0            * ~cts & 4
  239.         not.b        d0
  240.         and.b        #4,d0
  241.         rts
  242. ;cts_mfpport2:
  243. ;      moveq.l    #0,d0
  244. ;        move.b    MFPPORT2,d0            * ~cts & 4
  245. ;        not.b        d0
  246. ;        and.b        #4,d0
  247. ;        rts
  248. cts_sccb_cnt:
  249.       moveq.l    #0,d0
  250.         move.b    #0,SCCB_CNT
  251.         nop
  252.         nop
  253.         move.b    SCCB_CNT,d0            * cts & 0x20
  254.         and.b        #0x20,d0
  255.         rts
  256. cts_scca_cnt:
  257.       moveq.l    #0,d0
  258.         move.b    #0,SCCA_CNT
  259.         nop
  260.         nop
  261.         move.b    SCCA_CNT,d0            * cts & 0x20
  262.         and.b        #0x20,d0
  263.         rts
  264.  
  265. ; Send character to RS232
  266. ; with extra CTS checking courtesy of Iain Paton!
  267. ; Optimized assembler routines by Uwe Zerbe
  268. ;
  269. ; Call with character in D0.w
  270.  
  271. sendbyte:
  272.       movem.l d0-d7/a2,-(a7)
  273.       move.w    d0,-(a7)            ; Parameter
  274.       pea            send_byte(pc)
  275.       move.w    #$26,-(a7)
  276.       trap        #14                    ; Send character in supervisor-mode
  277.       addq.w    #8,a7
  278.       movem.l (a7)+,d0-d7/a2
  279.       rts
  280.   
  281. send_byte:
  282.       bsr     h_cts         ; HardCTS
  283.       move.w    #1,-(a7)
  284.       move.w  #8,-(a7)
  285.       lea     $562.w,a0
  286.       movea.l (a0),a0
  287.       jsr     (a0)          ; direct jump to Bcostat
  288.       addq.w    #4,a7
  289.       tst.w        d0
  290.         bne.s        senden
  291.  
  292.         pea            (a2)
  293.         move.w    #11,-(sp)            ; Cconis
  294.         trap        #1
  295.         addq.w    #2,sp
  296.         move.l    (sp)+,a2
  297.       tst.w   d0
  298.       bne.s   senden_e      ; Key-Escape 
  299.       move.l    TIME_RELEASE(pc),a0
  300.       jsr            (a0)
  301.         bra.s   send_byte
  302. senden:
  303.       move.w  8(a7),d0
  304.       move.w  d0,-(a7)
  305.       move.w  #1,-(a7)
  306.       lea     $582.w,a0
  307.       movea.l (a0),a0
  308.       jsr     (a0)          ; direct jump to Bconout
  309.       addq.w    #4,a7
  310. senden_e:
  311.       rts
  312.  
  313. ; Calling with Buffer in A0.l
  314. ;                              Bytes in D0.l
  315. ;                              CD-Check in D1 (0=FALSE,1=TRUE)
  316.  
  317. sendchars:
  318.       movem.l d3-d4/a2,-(a7)
  319.       move.l  a0,-(a7)
  320.       move.l  d0,-(a7)
  321.       move.w  d1,-(a7)
  322.       pea            sendc(pc)
  323.       move.w    #$26,-(a7)
  324.       trap        #14
  325.       lea     16(a7),a7
  326.       movem.l (a7)+,d3-d4/a2
  327.       rts
  328.   
  329. sendc:
  330.       movea.l 14(a7),a2
  331.       move.l  10(a7),d4
  332.       move.w  8(a7),d3
  333.       bra.s   sendc1
  334.       move.l  d4,d0
  335. sendc6:
  336.       move.b  (a2)+,d0
  337.       movem.l d3-d4/a2,-(a7)
  338.       move.w  d0,-(a7)
  339. sendc3:
  340.       bsr.s   h_cts         ; HardCTS
  341.       move.w    #1,-(a7)
  342.     move.w  #8,-(a7)
  343.     lea     $562.w,a0
  344.     movea.l (a0),a0
  345.     jsr     (a0)
  346.     addq.w    #4,a7
  347.     tst.w        d0
  348.       bne.s        sendc2
  349.  
  350.         pea            (a2)
  351.         move.w    #11,-(sp)            ; Cconis
  352.         trap        #1
  353.         addq.w    #2,sp
  354.         move.l    (sp)+,a2
  355.     tst.w   d0
  356.     bne.s   sendc_e       ; Key-Escape 
  357.       move.l    TIME_RELEASE(pc),a0
  358.       jsr            (a0)
  359.       bra     sendc3
  360. sendc2:
  361.     move.w  #1,-(a7)
  362.     lea     $582.w,a0
  363.     movea.l (a0),a0
  364.     jsr     (a0)
  365.     addq.w    #4,a7
  366.     movem.l (a7)+,d3-d4/a2
  367. sendc1:
  368.       tst.w   d3
  369.       beq.s   sendc4
  370.         bsr            get_dcd
  371.       tst.w   d0
  372.       beq.b   sendc5
  373. sendc4:
  374.       move.l  d4,d0
  375.       subq.l  #1,d4
  376.       tst.l      d0
  377.       bne.b   sendc6
  378. sendc5:
  379.       rts   
  380. sendc_e:
  381.       addq.w    #2,a7
  382.       movem.l (a7)+,d3-d4/a2
  383.       rts
  384.  
  385. h_cts:
  386.       move.w  d3,-(a7)            ; HardCTS-Function
  387.       move.b  d0,d3
  388.       move.w  HARDCTS(pc),d1
  389.       beq.b   h_ctsend            ; No HardCTS --> Exit
  390.       bra.b   h_cts1
  391. h_cts2:
  392.         pea            (a2)
  393.         move.w    #11,-(sp)            ; Cconis
  394.         trap        #1
  395.         addq.w    #2,sp
  396.         move.l    (sp)+,a2
  397.       tst.w   d0
  398.       bne.b   h_ctsend
  399.       move.l    TIME_RELEASE(pc),a0
  400.       jsr            (a0)
  401. h_cts1:
  402.         bsr            get_cts
  403.       tst.w        d0
  404.       beq.b        h_cts2 
  405. h_ctsend:
  406.       move.b  d3,d0
  407.       move.w  (a7)+,d3
  408.          rts
  409.  
  410. ; Calling with portnumber in D0.w ("Port n")
  411. ; This function is only called, when your TOS supports "Bconmap".
  412.  
  413. set_new_port:
  414.         subq.w    #1,d0            * 1=ST-Port
  415.         beq.s        port6
  416.         subq.w    #1,d0            * 2=SCC-B
  417.         beq.s        port7
  418.         subq.w    #1,d0            * 3=TTMFP, 3=SCC-A on a STE!
  419.         beq.s        port8
  420.         subq.w    #1,d0            * 4=SCC-A
  421.         beq.s        port9
  422.         rts                                * Unkown port
  423. port6:
  424.         moveq        #6,d0
  425.         bra.s        set_it
  426. port7:
  427.         moveq        #7,d0
  428.         bra.s        set_it
  429. port8:
  430.         moveq        #8,d0
  431.         bra.s        set_it
  432. port9:
  433.         moveq        #9,d0
  434. set_it:
  435.         pea            (a2)
  436.         move.w    d0,-(sp)
  437.         move.w    #44,-(sp)
  438.         trap        #14
  439.         addq.w    #4,sp
  440.         move.l    (sp)+,a2
  441.         rts
  442.  
  443. ; Read a character
  444. ; Returns value in D0.w
  445.  
  446. modemin:
  447.         pea            (a2)
  448.         move.w    #1,-(sp)
  449.         move.w    #2,-(sp)
  450.         trap        #13
  451.         addq.w    #4,sp
  452.         move.l    (sp)+,a2
  453.         and.l        #255,d0
  454.       rts
  455.  
  456. ; If a character available?
  457.  
  458. charavail:
  459.         pea            (a2)
  460.         move.w    #1,-(sp)
  461.         move.w    #1,-(sp)
  462.         trap        #13
  463.         addq.w    #4,sp
  464.         move.l    (sp)+,a2
  465.         rts
  466.  
  467. outfull:
  468.         pea            (a2)
  469.         move.w    #1,-(sp)
  470.         move.w    #8,-(sp)
  471.         trap        #13
  472.         addq.w    #4,sp
  473.         move.l    (sp)+,a2
  474.         tst.l        d0
  475.         bne.s        out1
  476.         moveq        #1,d0
  477.         rts
  478. out1:
  479.         moveq        #0,d0
  480.         rts
  481.  
  482. ;    Return the next character in the RS232 input buffer
  483. ;    but dont actually take it.
  484. ; Return -1 if buffer was empty
  485.  
  486. peekbyte:
  487.         pea            (a2)
  488.         clr.w        -(sp)
  489.         move.w    #14,-(sp)
  490.         trap        #14
  491.         addq.w    #4,sp
  492.         move.l    (sp)+,a2
  493.         move.l    d0,a0
  494.         move.w    6(a0),d0
  495.         cmp.w        8(a0),d0
  496.         bne.s        peek2
  497.         move.w    #-1,d0
  498.         rts
  499. peek2:
  500.         move.w    6(a0),d0
  501.         addq.w    #1,d0
  502.         cmp.w        4(a0),d0
  503.         blo.s        peek3
  504.         clr.w        d0
  505. peek3:
  506.         move.l    (a0),a0
  507.         move.b    (a0,d0.w),d0
  508.         and.w        #255,d0
  509.         rts
  510.  
  511. outempty:
  512.         pea            (a2)
  513.         clr.w        -(sp)
  514.         move.w    #14,-(sp)
  515.         trap        #14
  516.         addq.w    #4,sp
  517.         move.l    (sp)+,a2
  518.         move.l    d0,a0
  519.         lea            $e(a0),a0
  520.         move.w    6(a0),d0
  521.         cmp.w        8(a0),d0
  522.         beq.s        outempty1
  523.         moveq        #0,d0
  524.         rts
  525. outempty1:
  526.         moveq        #1,d0
  527.         rts
  528.  
  529. ; Set DTR on
  530.         
  531. dtr_on:
  532.         move.w    PORT(pc),d0
  533.         tst.w        d0
  534.         beq.s        on_mfpport1
  535.         subq.w    #1,d0
  536.         beq.s        on_mfpport1
  537.         subq.w    #1,d0
  538.         beq.s        on_sccb_cnt
  539.  
  540.         lea            HARDWARE(pc),a0
  541.         cmp.w        #1,(a0)                    * STE-Hardware?
  542.         beq.s        on_ste
  543.  
  544.         subq.w    #1,d0
  545. ;        beq.s        on_mfpport2
  546.  
  547. on_ste:
  548.         subq.w    #1,d0
  549.         beq.s        on_scca_cnt
  550.         rts
  551.  
  552. on_mfpport1:
  553.         pea            (a2)
  554.         move.w    #0xe7,-(sp)
  555.         move.w    #29,-(sp)
  556.         trap        #14
  557.         addq.w    #4,sp
  558.         move.l    (sp)+,a2
  559.         rts
  560. ;on_mfpport2:
  561. ;        rts
  562. on_sccb_cnt:
  563.         move.b    #5,SCCB_CNT
  564.         nop
  565.         nop
  566.         move.b    #$ea,SCCB_CNT
  567.         rts
  568. on_scca_cnt:
  569.         move.b    #5,SCCA_CNT
  570.         nop
  571.         nop
  572.         move.b    #$ea,SCCA_CNT
  573.         rts
  574.  
  575. dtr_off:
  576.         move.w    PORT(pc),d0
  577.         tst.w        d0
  578.         beq.s        off_mfpport1
  579.         subq.w    #1,d0
  580.         beq.s        off_mfpport1
  581.         subq.w    #1,d0
  582.         beq.s        off_sccb_cnt
  583.  
  584.         lea            HARDWARE(pc),a0
  585.         cmp.w        #1,(a0)                    * STE-Hardware?
  586.         beq.s        off_ste
  587.  
  588.         subq.w    #1,d0
  589. ;        beq.s        off_mfpport2
  590.  
  591. off_ste:
  592.         subq.w    #1,d0
  593.         beq.s        off_scca_cnt
  594.         rts
  595. off_mfpport1:
  596.         pea            (a2)
  597.         move.w    #0x18,-(sp)
  598.         move.w    #30,-(sp)
  599.         trap        #14
  600.         addq.w    #4,sp
  601.         move.l    (sp)+,a2
  602.         rts
  603. ;off_mfpport2:
  604. ;        rts
  605. off_sccb_cnt:
  606.         move.b    #5,SCCB_CNT
  607.         nop
  608.         nop
  609.         move.b    #$6a,SCCB_CNT
  610.         rts
  611. off_scca_cnt:
  612.         move.b    #5,SCCA_CNT
  613.         nop
  614.         nop
  615.         move.b    #$6a,SCCA_CNT
  616.         rts
  617.