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

  1. *************************************************
  2. *                        *
  3. *         (C)opyright 1993        *
  4. *                        *
  5. *         by Tomi Blinnikka        *
  6. *                        *
  7. *    Don't try to understand the code    *
  8. *                        *
  9. * Version 0.01    10/01/1993            *
  10. *     -0.99ö                    *
  11. *                        *
  12. * Version 1.00    DD/MM/1993            *
  13. *                        *
  14. * BUGS:                        *
  15. *                        *
  16. *************************************************
  17.  
  18.     INCLUDE    "JMPLibs.i"
  19.     INCLUDE    "libraries/dosextens.i"
  20.     INCLUDE    "libraries/dos.i"
  21.     INCLUDE    "devices/serial.i"
  22.     INCLUDE    "devices/timer.i"
  23.  
  24.     INCLUDE    "XREF:2.0.xref"
  25.     INCLUDE    "XREF:exec.xref"
  26.     INCLUDE    "XREF:dos.xref"
  27.  
  28.  
  29. TRUE:        EQU    1
  30. FALSE:        EQU    0
  31.  
  32.         section    NoDisCo,CODE
  33.  
  34.         push    d2-d7/a2-a6
  35.  
  36.         sub.l    a1,a1            ;Find our task
  37.         lib    Exec,FindTask
  38.         move.l    d0,OurTask
  39.  
  40. OpenDos:    openlib    Dos,NoDos        ;Keep at beginning
  41.  
  42.         lib    Dos,Output
  43.         move.l    d0,_stdout
  44.  
  45.         lea.l    CLTemplate1,a0
  46.         move.l    a0,d1
  47.         lea.l    CLArray1,a0
  48.         move.l    a0,d2
  49.         clr.l    d3
  50.         lib    Dos,ReadArgs
  51.         move.l    d0,RDArgs1
  52.         beq    NoRDArgs
  53.  
  54.         tst.l    UnitPointer
  55.         beq    DoParsing1
  56.         move.l    UnitPointer,a0
  57.         move.l    (a0),SerUnit
  58. DoParsing1:    tst.l    SpeedPointer
  59.         beq    DoParsing2
  60.         move.l    SpeedPointer,a0
  61.         move.l    (a0),Speed
  62. DoParsing2:    tst.l    TimePointer
  63.         beq    DoParsing3
  64.         move.l    TimePointer,a0
  65.         move.l    (a0),Time
  66. DoParsing3:
  67.  
  68. ;Create reply port for timer.device
  69.  
  70.         lib    Exec,CreateMsgPort
  71.         move.l    d0,TRPort
  72.         beq    NoMsgPort
  73.  
  74. ;Create IOReq for timer.device
  75.  
  76.         move.l    #IOTV_SIZE,d0
  77.         move.l    TRPort,a0
  78.         lib    Exec,CreateIORequest
  79.         move.l    d0,TIORequest
  80.         beq    NoIOReq
  81.  
  82. ;Create reply port for serial.device (or modem0.device etc.)
  83.  
  84.         lib    Exec,CreateMsgPort
  85.         move.l    d0,SRPort
  86.         beq    NoMsgPort
  87.  
  88. ;Create IOReq for serial.device (or for other device, but size is EXTSER)
  89.  
  90.         move.l    #IOEXTSER_SIZE,d0
  91.         move.l    SRPort,a0
  92.         lib    Exec,CreateIORequest
  93.         move.l    d0,IORequest
  94.         beq    NoIOReq
  95.  
  96. ;open timer.device
  97.  
  98.         lea.l    TimerName,a0
  99.         move.l    TIORequest,a1
  100.         move.l    #UNIT_VBLANK,d0
  101.         clr.l    d1                ;no flags
  102.         lib    Exec,OpenDevice
  103.         tst.l    d0
  104.         bne    NoTimer
  105.         move.w    #$1,TimerOpen            ;just to tell if open
  106.  
  107. ;Set up first wait request
  108.  
  109.         bsr    Waiter
  110.  
  111. ;open serial.device
  112.  
  113.         move.l    SerName,a0
  114.         move.l    SerUnit,d0
  115.         move.l    IORequest,a1
  116.         move.b    #SERF_SHARED,IO_SERFLAGS(a1)
  117.         clr.l    d1                ;no flags
  118.         lib    Exec,OpenDevice
  119.         tst.l    d0
  120.         bne    NoSerial
  121.         move.w    #$1,SerOpen            ;just to tell if open
  122.  
  123.         tst.l    Speed
  124.         beq    SkipSetParams
  125.         move.l    IORequest,a1
  126.         clr.l    IO_LENGTH(a1)
  127.         clr.l    IO_DATA(a1)
  128.         move.w    #SDCMD_SETPARAMS,IO_COMMAND(a1)
  129.         move.l    Speed,IO_BAUD(a1)
  130.         lib    Exec,DoIO
  131.         tst.l    d0
  132.         beq    SkipSetParams
  133.         bsr    NoSetSer
  134.  
  135. SkipSetParams:
  136.  
  137. ;Wait for signals from serial.device, keyboard (CTRL_C).
  138.  
  139. Main:        clr.l    d1            ;Set signals for
  140.         clr.l    d0
  141.         move.l    TRPort,a0        ;timer.device
  142.         move.b    MP_SIGBIT(a0),d1
  143.         bset.l    d1,d0
  144.         bset.l    #SIGBREAKB_CTRL_C,d0    ;and CTRL_C
  145.         bset.l    #SIGBREAKB_CTRL_D,d0    ;and CTRL_D
  146.         bset.l    #SIGBREAKB_CTRL_E,d0    ;and CTRL_E
  147.         lib    Exec,Wait
  148.  
  149.         cmp.l    #SIGBREAKF_CTRL_C,d0    ;If CTRL_C
  150.         beq    Break            ;go break
  151.         cmp.l    #SIGBREAKF_CTRL_D,d0    ;If CTRL_D
  152.         beq    Disable            ;go disable
  153.         cmp.l    #SIGBREAKF_CTRL_E,d0    ;If CTRL_E
  154.         beq    Enable            ;go enable
  155.  
  156.         move.l    TRPort,a0
  157.         move.b    MP_SIGBIT(a0),d1
  158.         btst    d1,d0            ;test for timer.device
  159.         beq    Main            ;if was go do Space->BS
  160.         move.l    TRPort,a0
  161.         lib    Exec,GetMsg
  162.         bsr    DoNoDisCo
  163.         bsr    Waiter
  164.         bra    Main
  165.  
  166. Break:        lea.l    BreakText1,a0
  167.         bsr    Printer
  168.         bra    ShutDown
  169.  
  170. Disable:    move.l    #1,Active
  171.         lea.l    DisabledText1,a0
  172.         bsr    Printer
  173.         bra    Main
  174.  
  175. Enable:        clr.l    Active
  176.         lea.l    EnabledText1,a0
  177.         bsr    Printer
  178.         bra    Main
  179.  
  180. ClearTimer:    move.l    TIORequest,a1
  181.         lib    Exec,AbortIO
  182.         tst.l    d0
  183.         beq    ClearTimer1
  184.         move.l    TRPort,a0
  185.         lib    Exec,GetMsg
  186. ClearTimer1:    move.l    TIORequest,a1
  187.         lib    Exec,WaitIO
  188.         rts
  189.  
  190. Waiter:        move.l    TIORequest,a1
  191.         move.w    #TR_ADDREQUEST,IO_COMMAND(a1)
  192.         move.l    Time,IOTV_TIME(a1)
  193.         move.l    #2,IOTV_TIME+4(a1)    ;just in case secs=0
  194.         lib    Exec,SendIO
  195.         rts
  196.  
  197. DoNoDisCo:    tst.l    Active
  198.         bne    DoNoDisCo_OUT
  199.  
  200.         move.l    IORequest,a1
  201.         move.w    #CMD_WRITE,IO_COMMAND(a1)
  202.         move.l    #1,IO_LENGTH(a1)
  203.         lea.l    SpaceText1,a0
  204.         move.l    a0,IO_DATA(a1)
  205.         lib    Exec,DoIO
  206.  
  207.         move.l    #50,d1
  208.         lib    Dos,Delay
  209.  
  210.         move.l    IORequest,a1
  211.         move.w    #CMD_WRITE,IO_COMMAND(a1)
  212.         move.l    #1,IO_LENGTH(a1)
  213.         lea.l    DelText1,a0
  214.         move.l    a0,IO_DATA(a1)
  215.         lib    Exec,DoIO
  216. DoNoDisCo_OUT:    rts
  217.  
  218. ShutDown:    tst.w    SerOpen
  219.         beq    ShutDown9000
  220.         move.l    IORequest,a1
  221.         lib    Exec,CloseDevice
  222.  
  223. ShutDown9000:    tst.w    TimerOpen
  224.         beq    ShutDown8000
  225.         bsr    ClearTimer
  226.         move.l    TIORequest,a1
  227.         lib    Exec,CloseDevice
  228.  
  229. ShutDown8000:    move.l    TIORequest,a0
  230.         lib    Exec,DeleteIORequest
  231.  
  232.         move.l    TRPort,a0
  233.         lib    Exec,DeleteMsgPort
  234.  
  235.         move.l    IORequest,a0
  236.         lib    Exec,DeleteIORequest
  237.  
  238.         move.l    SRPort,a0
  239.         lib    Exec,DeleteMsgPort
  240.  
  241. ShutDown7000:
  242. ShutDown4000:    move.l    RDArgs1,d1
  243.         beq    ShutDown3000
  244.         lib    Dos,FreeArgs
  245.  
  246. ShutDown3000:
  247. ShutDown1000:    closlib    Dos
  248.         pull    d2-d7/a2-a6
  249.         clr.l    d0
  250.         rts
  251.  
  252. ;Error etc. messages
  253.  
  254. NoDos:        pull    d2-d7/a2-a6
  255.         move.l    #RETURN_FAIL,d0
  256.         rts
  257.  
  258. NoRDArgs:    lib    Dos,IoErr
  259.         move.l    d0,d1
  260.         clr.l    d2
  261.         lib    Dos,PrintFault
  262.         bra    ShutDown
  263.  
  264. NoMsgPort:    lea.l    NoMsgPortText1,a0
  265.         bsr    Printer
  266.         bra    ShutDown
  267.  
  268. NoIOReq:    lea.l    NoIOReqText1,a0
  269.         bsr    Printer
  270.         bra    ShutDown
  271.  
  272. NoTimer:    lea.l    NoTimerText1,a0
  273.         bsr    Printer
  274.         bra    ShutDown
  275.  
  276. NoSerial:    lea.l    NoSerialText1,a0
  277.         bsr    Printer
  278.         move.l    SerName,a0
  279.         bsr    Printer
  280.         lea.l    NoSerialText2,a0
  281.         bsr    Printer
  282.         bra    ShutDown
  283.  
  284. NoSetSer:    lea.l    NoSetSerText1,a0
  285.         bsr    Printer
  286.         rts
  287.  
  288. Printer:    printa    a0,_stdout
  289.         rts
  290.  
  291. ;Structures
  292.  
  293.         libnames
  294.  
  295. ;Other stuff, part I
  296.  
  297. OurTask:    dc.l    0
  298. RDArgs1:    dc.l    0
  299. TRPort:        dc.l    0
  300. SRPort:        dc.l    0
  301. TIORequest:    dc.l    0
  302. IORequest:    dc.l    0
  303. _stdout:    dc.l    0
  304.  
  305. ;Options
  306.  
  307. CLArray1:
  308. Active:        dc.l    0        ;(0 = Yes, please, 1=No)
  309. TimePointer:    dc.l    0
  310. SerName:    dc.l    SerName2    ;A pointer!
  311. UnitPointer:    dc.l    0
  312. SpeedPointer:    dc.l    0
  313.  
  314. ;Device stuff
  315.  
  316. SerUnit:    dc.l    0
  317. Speed:        dc.l    0
  318. Time:        dc.l    120
  319. SerOpen:    dc.w    0
  320. TimerOpen:    dc.w    0
  321.  
  322. ;Strings, error
  323.  
  324. BreakText1:    dc.b    "***Break: NoDisCo",13,10,0
  325. NoMsgPortText1:    dc.b    "ERROR: Couldn't get message port!",13,10,0
  326. NoIOReqText1:    dc.b    "ERROR: Couldn't get SerialIOReq!",13,10,0
  327. NoSetSerText1:    dc.b    "ERROR: Couldn't set parameters for device!",13,10,0
  328. NoSerialText1:    dc.b    "ERROR: Couldn't open ",0
  329. SerName2:    dc.b    "serial.device",0
  330. NoSerialText2:    dc.b    13,10,0
  331. NoTimerText1:    dc.b    "ERROR: Couldn't open timer.device",13,10,0
  332.  
  333. ;Strings, names
  334.  
  335. CLTemplate1:    dc.b    "D=DISABLE/S,TIME/N/K,DEV=DEVICE/K,UNIT/N/K,SPEED/N/K",0
  336. RDVersion:    dc.b    "$VER: NoDisCo 1.00 (10.1.93) (C)opyright Tomi Blinnikka 1993",0
  337. DisabledText1:    dc.b    "NoDisCo disabled.",13,10,0
  338. EnabledText1:    dc.b    "NoDisCo enabled.",13,10,0
  339. SpaceText1:    dc.b    " ",0            ;Space
  340. DelText1:    dc.b    8,0            ;Backspace
  341. TimerName:    dc.b    "timer.device",0
  342.         ds.w    0
  343.  
  344.         end
  345.  
  346.