home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / dev / asm / tbsource / atcontrol / atc.s
Text File  |  1993-12-21  |  6KB  |  327 lines

  1. *************************************************
  2. *                        *
  3. *         (C)opyright 1993        *
  4. *                        *
  5. *          Tomi Blinnikka        *
  6. *                        *
  7. *    Don't try to understand the code    *
  8. *                        *
  9. * Version 1.00    11/07/1993            *
  10. *                        *
  11. * BUGS:    Didn't do anything really.        *
  12. *                        *
  13. * Version 1.01    14/07/1993            *
  14. *                        *
  15. * BUGS:    Didn't set speed or unit.        *
  16. *                        *
  17. * Version 1.02    17/07/1993            *
  18. *                        *
  19. * BUGS:                        *
  20. *                        *
  21. *************************************************
  22.  
  23.  
  24.     INCLUDE "JMPLibs.i"
  25.     INCLUDE "libraries/dos.i"
  26.     INCLUDE    "exec/devices.i"
  27.     INCLUDE    "devices/serial.i"
  28.     INCLUDE    "intuition/intuition.i"
  29.  
  30.     INCLUDE "XREF:2.0.xref"
  31.     INCLUDE "XREF:exec.xref"
  32.     INCLUDE "XREF:dos.xref"
  33.  
  34. PROGVERSION:    macro
  35.         dc.b    "1.02 (17.07.93)"
  36.         endm
  37.  
  38.         section    ATControl,CODE
  39.  
  40.         push    d2-d7/a2-a6
  41.  
  42.         sub.l    a1,a1            ;Find our task
  43.         lib    Exec,FindTask
  44.         move.l    d0,OurTask
  45.  
  46.         openlib    Dos,NoDos
  47.  
  48.         lib    Dos,Output
  49.         move.l    d0,_stdout
  50.  
  51.         lea.l    CLTemplate1,a0
  52.         move.l    a0,d1
  53.         lea.l    CLArray1,a0
  54.         move.l    a0,d2
  55.         clr.l    d3
  56.         lib    Dos,ReadArgs
  57.         move.l    d0,RDArgs1
  58.         beq    NoRDArgs
  59.  
  60. DoParsing:    tst.l    UnitPointer
  61.         beq    DoParsing1
  62.         move.l    UnitPointer,a0
  63.         move.l    (a0),SerUnit
  64. DoParsing1:    tst.l    SpeedPointer
  65.         beq    DoParsing2
  66.         move.l    SpeedPointer,a0
  67.         move.l    (a0),Speed
  68. DoParsing2:
  69.  
  70. ;Create reply port for serial.device (or modem0.device etc.)
  71.  
  72.         lib    Exec,CreateMsgPort
  73.         move.l    d0,SRPort
  74.         beq    NoMsgPort
  75.  
  76. ;Create IOReq for serial.device (or for other device, but size is EXTSER)
  77.  
  78.         move.l    #IOEXTSER_SIZE,d0
  79.         move.l    SRPort,a0
  80.         lib    Exec,CreateIORequest
  81.         move.l    d0,IORequest
  82.         beq    NoIOReq
  83.  
  84. ;open serial.device
  85.  
  86.         move.l    SerName,a0
  87.         move.l    SerUnit,d0
  88.         move.l    IORequest,a1
  89.         move.b    #SERF_SHARED,IO_SERFLAGS(a1)
  90.         clr.l    d1                ;no flags
  91.         lib    Exec,OpenDevice
  92.         tst.l    d0
  93.         bne    NoSerial
  94.         move.w    #$1,SerOpen        ;just to tell if open
  95.  
  96.         tst.l    Speed
  97.         beq    SkipSetParams
  98.         move.l    IORequest,a1
  99.         clr.l    IO_LENGTH(a1)
  100.         clr.l    IO_DATA(a1)
  101.         move.w    #SDCMD_SETPARAMS,IO_COMMAND(a1)
  102.         move.l    Speed,IO_BAUD(a1)
  103.         lib    Exec,DoIO
  104.         tst.l    d0
  105.         beq    SkipSetParams
  106.         bsr    NoSetSer
  107.  
  108. SkipSetParams:    bsr    Reader            ;Set up first read
  109.  
  110. MainLoop:    bsr    WaitForChar
  111.         tst.l    d0
  112.         beq    ShutDown
  113.         bsr    SendIDCMP
  114.  
  115.         move.l    IORequest,a1        ;Check to see
  116.         lib    Exec,CheckIO        ;if we've already
  117.         tst.l    d0            ;finished reading
  118.         beq    MainLoop2        ;current char from serial
  119.  
  120.         bsr    Reader            ;Yes, then start new read
  121.  
  122. MainLoop2:    bra    MainLoop
  123.  
  124. WaitForChar:    clr.l    d1            ;Set signals for
  125.         clr.l    d0
  126.         move.l    SRPort,a1        ;serial.device
  127.         move.b    MP_SIGBIT(a1),d1
  128.         bset.l    d1,d0
  129.         bset.l    #SIGBREAKB_CTRL_C,d0    ;and CTRL_C
  130.         lib    Exec,Wait
  131.  
  132.         cmp.l    #SIGBREAKF_CTRL_C,d0    ;If CTRL_C
  133.         beq    Break            ;go break
  134.  
  135. WaitForChar1:    move.l    SRPort,a0
  136.         lib    Exec,GetMsg
  137.  
  138.         tst.l    d0
  139.         bne    WaitForChar1
  140.         move.l    #-1,d0            ;All OK.
  141.         rts
  142.  
  143. SendIDCMP:    tst.b    Buffer1
  144.         beq    SendIDCMP_OUT
  145.  
  146.         lea.l    FakeIDCMP,a2
  147.         move.l    SRPort,MN_REPLYPORT(a2)
  148.         move.b    #NT_MESSAGE,LN_TYPE(a2)
  149.  
  150.         move.l    #RAWKEY,im_Class(a2)
  151.         move.b    Buffer1,im_Code+1(a2)
  152. ;        move.l    Window1,im_IDCMPWindow(a2)
  153.  
  154.         lib    Exec,Forbid
  155.         lea.l    PortName1,a1        ;Find port to send to
  156.         lib    Exec,FindPort
  157.         move.l    d0,a3
  158.  
  159.         tst.l    d0            ;If none skip
  160.         beq    SendIDCMP2
  161.  
  162.         move.l    a3,a0            ;Port
  163.         move.l    a2,a1            ;Message
  164.         lib    Exec,PutMsg        ;Send!
  165. SendIDCMP2:    lib    Exec,Permit
  166.  
  167. ;        lea.l    Buffer1,a0        ;DEBUG
  168. ;        bsr    Printer            ;DEBUG
  169.  
  170.         clr.b    Buffer1
  171.  
  172.         cmp.l    #0,a3
  173.         bne    SendIDCMP_OUT
  174.  
  175.         lea.l    NoPortText1,a0
  176.         bsr    Printer
  177.  
  178. SendIDCMP_OUT:    rts
  179.  
  180. ClearSer:    clr.w    Buffer1
  181.         move.l    IORequest,a1
  182.         lib    Exec,CheckIO
  183.         tst.l    d0
  184.         beq    ClearSer1
  185.         move.l    IORequest,a1
  186.         lib    Exec,WaitIO
  187.  
  188. ClearSer1:    move.l    IORequest,a1
  189.         ABORTIO
  190.         move.l    IORequest,a1
  191.         lib    Exec,WaitIO
  192.         rts
  193.  
  194. Reader:        move.l    IORequest,a1
  195.         move.w    #CMD_READ,IO_COMMAND(a1)
  196.         move.l    #1,IO_LENGTH(a1)
  197.         lea.l    Buffer1,a0
  198.         move.l    a0,IO_DATA(a1)
  199.         lib    Exec,SendIO
  200.         rts
  201.  
  202. Break:        lea.l    BreakText1,a0
  203.         bsr    Printer
  204.         clr.l    d0
  205.         rts
  206.  
  207. ShutDown:    tst.w    SerOpen
  208.         beq    ShutDown9000
  209.         bsr    ClearSer
  210.         move.l    IORequest,a1
  211.         lib    Exec,CloseDevice
  212.  
  213. ShutDown9000:    move.l    IORequest,a0
  214.         lib    Exec,DeleteIORequest
  215.  
  216.         move.l    SRPort,a0
  217.         lib    Exec,DeleteMsgPort
  218.  
  219.  
  220. ShutDown3000:    move.l    RDArgs1,d1
  221.         beq    ShutDown2000
  222.         lib    Dos,FreeArgs
  223.  
  224. ShutDown2000:
  225.  
  226. ShutDown1000:    closlib Dos
  227.  
  228.         pull    d2-d7/a2-a6
  229.         clr.l    d0
  230.         rts
  231.  
  232. ;Error etc. messages
  233.  
  234. NoDos:        pull    d2-d7/a2-a6
  235.         move.l    #RETURN_FAIL,d0
  236.         rts
  237.  
  238. NoRDArgs:    lib    Dos,IoErr
  239.         move.l    d0,d1
  240.         clr.l    d2
  241.         lib    Dos,PrintFault
  242.         bra    ShutDown
  243.  
  244. NoMsgPort:    lea.l    NoMsgPortText1,a0
  245.         bsr    Printer
  246.         bra    ShutDown
  247.  
  248. NoIOReq:    lea.l    NoIOReqText1,a0
  249.         bsr    Printer
  250.         bra    ShutDown
  251.  
  252. NoSerial:    lea.l    NoSerialText1,a0
  253.         bsr    Printer
  254.         move.l    SerName,a0
  255.         bsr    Printer
  256.         lea.l    NoSerialText2,a0
  257.         bsr    Printer
  258.         bra    ShutDown
  259.  
  260. NoSetSer:    lea.l    NoSetSerText1,a0
  261.         bsr    Printer
  262.         rts
  263.  
  264.  
  265.  
  266. Printer:    printa    a0,_stdout
  267.         rts
  268.  
  269.  
  270. ;Reservations
  271.  
  272.         libnames
  273.  
  274. ;Options
  275.  
  276. CLArray1:
  277. SerName:    dc.l    SerName2    ;A pointer!
  278. UnitPointer:    dc.l    0
  279. SpeedPointer:    dc.l    0
  280.  
  281. ;Serial device stuff
  282.  
  283. SerUnit:    dc.l    0
  284. Speed:        dc.l    0
  285. SerOpen:    dc.w    0
  286.  
  287. ;Other stuff, part I
  288.  
  289. OurTask:    dc.l    0
  290. RDArgs1:    dc.l    0
  291. _stdout:    dc.l    0
  292. SRPort:        dc.l    0
  293. IORequest:    dc.l    0
  294.  
  295. ;Strings, error & other info
  296.  
  297. BreakText1:    dc.b    "***Break: ATControl",13,10,0
  298. NoMsgPortText1:    dc.b    "ERROR: Couldn't get message port!",13,10,0
  299. NoIOReqText1:    dc.b    "ERROR: Couldn't get SerialIOReq!",13,10,0
  300. NoSetSerText1:    dc.b    "ERROR: Couldn't set parameters for device!",13,10,0
  301. NoSerialText1:    dc.b    "ERROR: Couldn't open ",0
  302. SerName2:    dc.b    "serial.device",0
  303. NoSerialText2:    dc.b    13,10,0
  304. NoPortText1:    dc.b    "ERROR: Port not open!",13,10,0
  305.  
  306. ;Strings, names
  307.  
  308. CLTemplate1:    dc.b    "DEV=DEVICE/K,UNIT/N/K,SPEED/N/K",0
  309. ATVersion:    dc.b    "$VER: ATControl "
  310.         PROGVERSION
  311.         dc.b    " (c) Copyright Tomi Blinnikka 1993",0
  312. PortName1:    dc.b    "InputMonitorPort.2.Zaphod",0
  313.         ds.w    0
  314.  
  315.  
  316. ;Our Fake IDCMP Message
  317.  
  318.  
  319. FakeIDCMP:    dcb.b    im_SIZEOF,0
  320.  
  321. ;Buffers
  322.  
  323. Buffer1:    dc.b    2,0
  324.  
  325.  
  326.         END
  327.