home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / dev / tbsource.lha / TBSource / ResSer / RS.S
Text File  |  1993-12-21  |  7KB  |  379 lines

  1. *************************************************
  2. *                        *
  3. *        (C)opyright 1991-92        *
  4. *                        *
  5. *         by Tomi Blinnikka        *
  6. *                        *
  7. *    Don't try to understand the code    *
  8. *                        *
  9. * Version 0.01    01/07/1991            *
  10. *     -0.99ö                    *
  11. *                        *
  12. *************************************************
  13.  
  14.     INCLUDE    "JMPLibs.i"
  15.     INCLUDE    "exec/types.i"
  16.     INCLUDE    "exec/nodes.i"
  17.     INCLUDE    "exec/lists.i"
  18.     INCLUDE    "exec/ports.i"
  19.     INCLUDE    "exec/memory.i"
  20.     INCLUDE    "exec/devices.i"
  21.     INCLUDE    "exec/io.i"
  22.     INCLUDE    "exec/tasks.i"
  23.     INCLUDE    "libraries/dosextens.i"
  24.     INCLUDE    "libraries/dos.i"
  25.     INCLUDE    "devices/serial.i"
  26.     INCLUDE "workbench/startup.i"
  27.  
  28.     INCLUDE    "XREF:2.0.xref"
  29.     INCLUDE    "XREF:exec.xref"
  30.     INCLUDE    "XREF:dos.xref"
  31.     INCLUDE    "XREF:icon.xref"
  32.  
  33.     XREF    _CreatePort
  34.     XREF    _DeletePort
  35.     XREF    _CreateExtIO
  36.     XREF    _DeleteExtIO
  37.  
  38.     XDEF    _DOSBase
  39.     XDEF    _SysBase
  40.  
  41. DIntuition    set    1
  42.  
  43. RingTop:    EQU    2
  44. OptionTop:    EQU    56
  45.  
  46. TRUE:        EQU    1
  47.  
  48.         section    RS,CODE
  49.  
  50.         push    d2-d7/a2-a6
  51.         push    d0/a0
  52.  
  53.         sub.l    a1,a1            ;Find our task
  54.         lib    Exec,FindTask
  55.         move.l    d0,OurTask
  56.         move.l    d0,a4
  57.         move.l    pr_CLI(a4),d0
  58.         bne    OpenDos
  59.  
  60.         add.l    #8,sp
  61.         lea.l    pr_MsgPort(a4),a0
  62.         lib    Exec,WaitPort
  63.         lea.l    pr_MsgPort(a4),a0
  64.         lib    Exec,GetMsg
  65.         move.l    d0,WBMsg
  66.  
  67. OpenDos:    openlib    Dos,NoDos        ;Keep at beginning
  68.  
  69.         tst.l    WBMsg
  70.         beq    CLIStart
  71.  
  72.         lea.l    NILName,a0
  73.         move.l    a0,d1
  74.         move.l    #MODE_NEWFILE,d2
  75.         lib    Dos,Open
  76.         move.l    d0,NILFile
  77.         beq    ShutDown
  78.         move.l    NILFile,_stdout
  79.         beq    NoNIL
  80.  
  81.         openlib    Icon,NoIcon
  82.  
  83.         move.l    WBMsg,a0
  84.         move.l    sm_ArgList(a0),a1
  85.         move.l    wa_Lock(a1),d1
  86.         lib    Dos,CurrentDir
  87.         move.l    d0,OldLock
  88.  
  89.         move.l    WBMsg,a0
  90.         move.l    sm_ArgList(a0),a1
  91.         move.l    wa_Name(a1),a0
  92.         lib    Icon,GetDiskObject
  93.         move.l    d0,DiskObject
  94.         beq    MainStart
  95.  
  96.         move.l    DiskObject,a4
  97.         move.l    $36(a4),a0        ;do_ToolTypes
  98.         lea.l    DEVICEText1,a1
  99.         lib    Icon,FindToolType
  100.         tst.l    d0
  101.         beq    DoToolType1
  102.         move.l    d0,SerName
  103.  
  104. DoToolType1:    move.l    $36(a4),a0        ;do_ToolTypes
  105.         lea.l    UNITText1,a1
  106.         lib    Icon,FindToolType
  107.         tst.l    d0
  108.         beq    DoToolType2
  109.         move.l    d0,a0
  110.         bsr    ConvASCII
  111.         tst.w    d0
  112.         beq    DoToolType2
  113.         move.w    d0,SerUnit
  114.  
  115. DoToolType2:    bra    MainStart
  116.  
  117. CLIStart:    lib    Dos,Output
  118.         move.l    d0,_stdout
  119.         pull    d0/a0
  120.         clr.b    -1(a0,d0.l)
  121.         cmp.b    #"?",(a0)
  122.         beq    Usage
  123.         cmp.w    #'-?',(a0)
  124.         beq    Usage
  125.         cmp.w    #'-h',(a0)
  126.         beq    Usage
  127.  
  128. Cont0.2:    bsr    ConvASCII
  129.         tst.w    d0
  130.         beq    Cont1
  131.         move.w    d0,SerUnit
  132. Cont1:        cmp.b    #32,(a0)        ;Test for space
  133.         bne    Cont1.01
  134.         add.l    #1,a0
  135.         bra    Cont1            ;Loop until no spaces
  136. Cont1.01:    cmp.b    #9,(a0)            ;Test for TAB
  137.         bne    Cont1.1
  138.         add.l    #1,a0
  139.         bra    Cont1.01        ;Loop until no spaces
  140. Cont1.1:    tst.b    (a0)
  141.         beq    Cont1.4
  142.         push    a0
  143. Cont1.2:    cmp.b    #32,(a0)        ;Test for spaces
  144.         beq    Cont1.3
  145.         cmp.b    #9,(a0)            ;Test for TAB
  146.         beq    Cont1.3
  147.         add.l    #1,a0
  148.         bra    Cont1.2
  149. Cont1.3:    clr.b    (a0)
  150.         pull    a0
  151.         move.l    a0,SerName
  152. Cont1.4:
  153.  
  154. MainStart:    move.l    _DosBase,_DOSBase
  155.         move.l    $4,_SysBase
  156.  
  157. ;Create reply port for serial.device (or modem0.device etc.)
  158.  
  159.         move.l    #0,-(sp)
  160.         pea    SRPortName        ;S(erial)R(eply)PortName
  161.         jsr    _CreatePort
  162.         add.l    #8,sp
  163.         move.l    d0,SRPort
  164.         beq    ShutDown
  165.  
  166. ;Create IOReq for serial.device (or for other device, but size is EXTSER)
  167.  
  168.         move.l    #IOEXTSER_SIZE,-(sp)
  169.         move.l    d0,-(sp)
  170.         jsr    _CreateExtIO
  171.          add.l    #8,sp
  172.         move.l    d0,IORequest
  173.         beq    NoIOReq
  174.  
  175. ;open serial.device
  176.  
  177.         move.l    SerName,a0
  178.         move.l    SerUnit,d0
  179.         move.l    IORequest,a1
  180.         move.b    #SERF_SHARED,IO_SERFLAGS(a1)
  181.         clr.l    d1                ;no flags
  182.         lib    Exec,OpenDevice
  183.         tst.l    d0
  184.         bne    NoSerial
  185.         move.w    #$1,SerOpen        ;just to tell if open
  186.  
  187.         clr.l    d1            ;Set signals for
  188.         clr.l    d0
  189.         bset.l    #SIGBREAKB_CTRL_C,d0    ;and CTRL_C
  190.         lib    Exec,Wait
  191.         bra    ShutDown
  192.  
  193. ClearSer:    move.l    IORequest,a1
  194.         lib    Exec,CheckIO
  195.         tst.l    d0
  196.         beq    ClearSer1
  197.         move.l    IORequest,a1
  198.         lib    Exec,WaitIO
  199.  
  200. ClearSer1:    move.l    IORequest,a1
  201.         ABORTIO
  202.         move.l    IORequest,a1
  203.         lib    Exec,WaitIO
  204.         rts
  205.  
  206. ShutDown:    tst.w    SerOpen
  207.         beq    ShutDown9000
  208.         move.l    IORequest,a1
  209.         lib    Exec,CloseDevice
  210.  
  211. ShutDown9000:    move.l    IORequest,d0
  212.         tst.l    d0
  213.         beq    ShutDown8000
  214.         move.l    #IOEXTSER_SIZE,-(sp)
  215.         move.l    d0,-(sp)
  216.         jsr    _DeleteExtIO
  217.         add.l    #8,sp
  218.  
  219. ShutDown8000:    move.l    SRPort,d0
  220.         tst.l    d0
  221.         beq    ShutDown7000
  222.         move.l    d0,-(sp)
  223.         jsr    _DeletePort
  224.         add.l    #4,sp
  225.  
  226. ShutDown7000:
  227. ShutDown4000:    tst.l    NILFile
  228.         beq    ShutDown3000
  229.         move.l    NILFile,d1
  230.         lib    Dos,Close
  231.  
  232. ShutDown3000:    tst.l    DiskObject
  233.         beq    ShutDown2000
  234.         move.l    DiskObject,a0
  235.         lib    Icon,FreeDiskObject
  236.  
  237. ShutDown2000:    move.l    OldLock,d1
  238.         beq    ShutDown1050
  239.         lib    Dos,CurrentDir
  240.  
  241. ShutDown1050:    move.l    WBMsg,d2
  242.         beq    ShutDown1000
  243.         lib    Exec,Forbid
  244.         move.l    d2,a1
  245.         flib    Exec,ReplyMsg
  246.  
  247. ShutDown1000:    closlib    Icon
  248.         closlib    Dos
  249.         pull    d2-d7/a2-a6
  250.         clr.l    d0
  251.         rts
  252.  
  253. ;Get length of text in given address
  254. ;
  255. ;Input a1 = Address of null terminated text string
  256. ;
  257. ;Result d0 = Length
  258.  
  259. GetLength:    clr.l    d0
  260.         cmp.l    #$00,a1        ;fixes enforcer hit
  261.         beq    GetLength_OUT
  262. GetLength2:    add.l    #1,d0
  263.         tst.b    (a1)+
  264.         bne    GetLength2
  265.         sub.l    #1,d0        ;don't include NULL
  266. GetLength_OUT:    rts
  267.  
  268.  
  269. ConvASCII:    clr.l    d0
  270.         clr.l    d1
  271.         cmp.b    #' ',(a0)
  272.         bne    ConvASCII2
  273.         add.l    #1,a0
  274. ConvASCII2:    move.b    (a0),d1
  275.         cmp.b    #'0',d1
  276.         bcs    ConvASCII_OUT
  277.         cmp.b    #'9',d1
  278.         bhi    ConvASCII_OUT
  279.         sub.b    #'0',d1
  280.         mulu.w    #10,d0
  281.         add.l    d1,d0
  282.         add.l    #1,a0
  283.         bra    ConvASCII2
  284. ConvASCII_OUT:    rts
  285.  
  286. ;Error etc. messages
  287.  
  288. Usage:        lea.l    UsageText1,a0
  289.         bsr    Printer
  290.         bra    ShutDown
  291.  
  292. NoDos:        add.l    #8,sp
  293.         pull    d2-d7/a2-a6
  294.         move.l    #RETURN_FAIL,d0
  295.         rts
  296.  
  297. NoNIL:        lea.l    NoNILText1,a0
  298.         bsr    Printer
  299.         bra    ShutDown
  300.  
  301. NoIcon:        lea.l    NoIconText1,a0
  302.         bsr    Printer
  303.         bra    ShutDown
  304.  
  305. NoIOReq:    lea.l    NoIOReqText1,a0
  306.         bsr    Printer
  307.         bra    ShutDown
  308.  
  309. NoSerial:    lea.l    NoSerialText1,a0
  310.         bsr    Printer
  311.         move.l    SerName,a0
  312.         bsr    Printer
  313.         lea.l    NoSerialText2,a0
  314.         bsr    Printer
  315.         bra    ShutDown
  316.  
  317. Printer:    printa    a0,_stdout
  318.         rts
  319.  
  320.  
  321. ;Structures
  322.  
  323. Iconify:    dc.w    0        ;(1 = Yes, please)
  324.  
  325. ;lib stuff
  326.  
  327. _SysBase:    dc.l    0
  328. _DOSBase:    dc.l    0
  329.  
  330.         libnames
  331.  
  332. ;Other stuff, part I
  333.  
  334. OurTask:    dc.l    0
  335. SRPort:        dc.l    0
  336. IORequest:    dc.l    0
  337. NILFile:    dc.l    0
  338. _stdout:    dc.l    0
  339. WBMsg:        dc.l    0
  340. DiskObject:    dc.l    0
  341. OldLock:    dc.l    0
  342.  
  343. ;Serial device stuff
  344.  
  345. SerName:    dc.l    SerName2        ;A pointer!
  346. SerUnit:    dc.l    0
  347. SerOpen:    dc.w    0
  348.  
  349. ;Strings, error
  350.  
  351. BreakText1:    dc.b    "***Break",13,10,0
  352. NoNILText1:    dc.b    "ERROR: Couldn't open device NIL:!",13,10,0
  353. NoIconText1:    dc.b    "ERROR: Couldn't open icon.library!",13,10,0
  354. NoIOReqText1:    dc.b    "ERROR: Couldn't get SerialIOReq!",13,10,0
  355. NoSerialText1:    dc.b    "ERROR: Couldn't open ",0
  356. SerName2:    dc.b    "modem0.device",0
  357. NoSerialText2:    dc.b    10,0
  358.  
  359. ;Strings, names
  360.  
  361. RSVersion:    dc.b    "$VER: "
  362. UsageText1:    dc.b    "Reserve Serial 321.221 (1.7.92). (C)opyright Tomi Blinnikka 1992",13,10,13,10
  363.         dc.b    10,"           !!! BETA TESTER VERSION !!!",13,10,13,10,13,10
  364.         dc.b    "USAGE: RS [Unit] [Device]",13,10,13,10
  365.         dc.b    "       Where: [Unit] is the unit number",13,10
  366.         dc.b    "              [Device] is the device name",13,10,13,10
  367.         dc.b    "       Default [Device] is serial.device",13,10,13,10
  368.         dc.b    "Program opens specified device.",13,10
  369.         dc.b    "See docs for more information.",13,10,0
  370. SRPortName:    dc.b    "ResSer port",0
  371. NILName:    dc.b    "NIL:",0
  372. DEVICEText1:    dc.b    "DEVICE",0
  373. UNITText1:    dc.b    "UNIT",0
  374. YESText1:    dc.b    "YES",0
  375.         ds.l    0
  376.  
  377.         end
  378.  
  379.