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