home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / dev / tbsource.lha / TBSource / ShellTerm / STv1.00.S < prev    next >
Text File  |  1993-12-21  |  13KB  |  670 lines

  1. *************************************************
  2. *                        *
  3. *         (C)opyright 1992        *
  4. *                        *
  5. *        by  Tomi Blinnikka        *
  6. *                        *
  7. *    Don´t try to understand the code    *
  8. *                        *
  9. * Version 0.01    28/05/1992            *
  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.  
  27.     INCLUDE    "XREF:2.0.xref"
  28.     INCLUDE    "XREF:exec.xref"
  29.     INCLUDE    "XREF:dos.xref"
  30.  
  31.  
  32. LF:        EQU    10
  33. CR:        EQU    13
  34. CTRL_O:        EQU    $0F
  35. CTRL_P:        EQU    $10
  36.  
  37. QUIT_KEY:    EQU    CTRL_P
  38. STATS_KEY:    EQU    CTRL_O
  39.  
  40. FALSE:        EQU    0
  41. TRUE:        EQU    1
  42.  
  43. BUFLEN:        EQU    1024
  44.  
  45.         section    ST,CODE
  46.  
  47.         push    d2-d7/a2-a6
  48.         push    d0/a0
  49.  
  50.         sub.l    a1,a1            ;Find our task
  51.         lib    Exec,FindTask
  52.         move.l    d0,OurTask
  53.  
  54.         openlib    Dos,NoDos        ;Keep at beginning
  55.  
  56. CLIStart:    lib    Dos,Output
  57.         move.l    d0,_stdout
  58.         lib    Dos,Input
  59.         move.l    d0,_stdin
  60.         move.l    d0,d1
  61.         lib    Dos,IsInteractive
  62.         tst.l    d0
  63.         beq    NotInteractive
  64.         pull    d0/a0
  65.         clr.b    -1(a0,d0.l)
  66.         cmp.b    #'?',(a0)
  67.         beq    Usage
  68.         cmp.w    #'-?',(a0)
  69.         beq    Usage
  70.         cmp.w    #'-h',(a0)
  71.         beq    Usage
  72.  
  73. Cont0.2:    bsr    ConvASCII
  74.         tst.w    d0
  75.         beq    Cont1
  76.         move.w    d0,SerUnit
  77. Cont1:        cmp.b    #' ',(a0)
  78.         bne    Cont1.1
  79.         add.l    #1,a0
  80. Cont1.1:    tst.b    (a0)
  81.         beq    Cont1.2
  82.         move.l    a0,SerName
  83. Cont1.2:
  84.  
  85. ;Create read reply port for serial.device (or modem0.device etc.)
  86.  
  87. MainStart:    lib    Exec,CreateMsgPort
  88.         move.l    d0,SRRPort
  89.         beq    NoMsgPort
  90.  
  91. ;Create read IOReq for serial.device (or for other device, but size is EXTSER)
  92.  
  93.         move.l    #IOEXTSER_SIZE,d0
  94.         move.l    SRRPort,a0
  95.         lib    Exec,CreateIORequest
  96.         move.l    d0,IORRequest
  97.         beq    NoIOReq
  98.  
  99.         move.l    IORRequest,a1
  100.         move.w    #CMD_READ,IO_COMMAND(a1)
  101.         lea.l    Buffer2,a0
  102.         move.l    a0,IO_DATA(a1)
  103.  
  104. ;Create write reply port for serial.device (or modem0.device etc.)
  105.  
  106.         lib    Exec,CreateMsgPort
  107.         move.l    d0,SWRPort
  108.         beq    NoMsgPort
  109.  
  110. ;Create write IOReq for serial.device (or for other device, but size is EXTSER)
  111.  
  112.         move.l    #IOEXTSER_SIZE,d0
  113.         move.l    SWRPort,a0
  114.         lib    Exec,CreateIORequest
  115.         move.l    d0,IOWRequest
  116.         beq    NoIOReq
  117.  
  118.         move.l    IOWRequest,a1
  119.         move.w    #CMD_WRITE,IO_COMMAND(a1)
  120.         move.l    #1,IO_LENGTH(a1)        ;writes in one byte "chunks"
  121.         lea.l    Buffer1,a0
  122.         move.l    a0,IO_DATA(a1)
  123.  
  124. ;open serial.device
  125.  
  126.         move.l    SerName,a0
  127.         move.l    SerUnit,d0
  128.         move.l    IORRequest,a1
  129.         move.b    #SERF_SHARED,IO_SERFLAGS(a1)
  130.         clr.l    d1                ;no flags
  131.         lib    Exec,OpenDevice
  132.         tst.l    d0
  133.         bne    NoSerial
  134.         move.w    #$1,SerOpen        ;just to tell if open
  135.  
  136. ;Copy info from one req to the other
  137.  
  138.         move.l    IORRequest,a0
  139.         move.l    IOWRequest,a1
  140.         move.l    IO_DEVICE(a0),IO_DEVICE(a1)
  141.         move.l    IO_UNIT(a0),IO_UNIT(a1)
  142.  
  143.  
  144.         lea.l    StartText1,a0
  145.         bsr    Printer
  146.  
  147. ;Change mode for CLI to RAW:
  148.  
  149.         move.l    _stdin,d1
  150.         move.l    #TRUE,d2
  151.         lib    Dos,SetMode
  152.  
  153.         bsr    Reader
  154.  
  155. ;LOOP
  156. ;waitfor char(shell,5000)
  157. ;if char 
  158. ; IF 'EXIT' then exit
  159. ; ELSE write to serial
  160. ;ENDIF
  161. ;
  162. ;checkIO(readrequest)
  163. ;if done write to shell
  164. ;read 1 char from serial (immediate return)
  165. ;
  166. ;ELSE goto LOOP
  167.  
  168. Looper:        move.l    _stdin,d1
  169.         move.l    #5000,d2
  170.         lib    Dos,WaitForChar
  171.         tst.l    d0
  172.         beq    Looper1
  173.         move.l    _stdin,d1
  174.         lea.l    Buffer1,a0
  175.         move.l    a0,d2
  176.         move.l    #1,d3
  177.         lib    Dos,Read
  178.         cmp.b    #QUIT_KEY,Buffer1
  179.         beq    Menu
  180.         bsr    Writer
  181. Looper1:    bsr    Read
  182.         tst.l    d0
  183.         beq    Looper
  184.  
  185.         move.l    _stdout,d1
  186.         lea.l    Buffer3,a0
  187.         move.l    a0,d2
  188.         move.l    d0,d3
  189.         lib    Dos,Write
  190.  
  191.         bra    Looper
  192.  
  193. Menu:        lea.l    MenuText1,a0
  194.         bsr    Printer
  195. Menu1:        move.l    _stdin,d1
  196.         lib    Dos,FGetC
  197.         cmp.l    #-1,d0
  198.         beq    ShutDown
  199.         cmp.l    #'1',d0
  200.         beq    DoStats
  201.         cmp.l    #'2',d0
  202.         beq    ClearReceived
  203.         cmp.l    #'3',d0
  204.         beq    ClearSent
  205.         cmp.l    #'4',d0
  206.         beq    ClearBoth
  207.         cmp.l    #'5',d0
  208.         beq    DoCTRL_P
  209.         cmp.l    #'6',d0
  210.         beq    DoReset
  211.         cmp.l    #'7',d0
  212.         beq    DoHangUp
  213.         cmp.l    #'8',d0
  214.         beq    DoInfo
  215.         cmp.l    #'9',d0
  216.         beq    Quit
  217.         cmp.l    #'0',d0
  218.         bne    Menu2
  219.         lea.l    ExitText1,a0
  220.         bsr    Printer
  221.         bra    Looper1
  222. Menu2:        bra    Menu1
  223.  
  224. DoStats:    lea.l    StatsText2,a0
  225.         bsr    Printer
  226.         lea.l    CRLFText1,a0
  227.         bsr    Printer
  228.         bsr    GiveStats
  229.         bra    Exit
  230.  
  231. ClearReceived:    lea.l    ClearText1,a0
  232.         bsr    Printer
  233.         clr.l    Received
  234.         bra    Exit
  235.  
  236. ClearSent:    lea.l    ClearText1,a0
  237.         bsr    Printer
  238.         clr.l    Sent
  239.         bra    Exit
  240.  
  241. ClearBoth:    lea.l    ClearText1,a0
  242.         bsr    Printer
  243.         clr.l    Received
  244.         clr.l    Sent
  245.         bra    Exit
  246.  
  247. DoCTRL_P:    move.b    CTRL_P,Buffer1
  248.         bsr    Writer
  249.         lea.l    CTRL_PText1,a0
  250.         bsr    Printer
  251.         add.l    #1,Sent
  252.         bra    Exit
  253.  
  254. DoReset:    lea.l    ResetText1,a0
  255.         bsr    Printer
  256.         lea.l    ResetText2,a1
  257.         bsr    GetLength
  258.         add.l    d0,Sent
  259.         lea.l    ResetText2,a0
  260.         bsr    Writer2
  261.         bra    Exit
  262.  
  263. DoHangUp:    lea.l    HangUpText1,a0
  264.         bsr    Printer
  265.         move.l    #55,d1
  266.         lib    Dos,Delay
  267.         lea.l    HangUpText2,a1
  268.         bsr    GetLength
  269.         add.l    d0,Sent
  270.         lea.l    HangUpText2,a0
  271.         bsr    Writer2
  272.         move.l    #55,d1
  273.         lib    Dos,Delay
  274.         lea.l    HangUpText3,a1
  275.         bsr    GetLength
  276.         add.l    d0,Sent
  277.         lea.l    HangUpText3,a0
  278.         bsr    Writer2
  279.         bra    Exit
  280.  
  281. DoInfo:        lea.l    InfoText1,a0
  282.         bsr    Printer
  283.         lea.l    AuthorText1,a0
  284.         bsr    Printer
  285.         bra    Exit
  286.  
  287. Quit:        lea.l    QuitText1,a0
  288.         bsr    Printer
  289.         lea.l    CRLFText1,a0
  290.         bsr    Printer
  291.         bsr    GiveStats
  292.         bra    ShutDown
  293.  
  294. Exit:        lea.l    TerminalText1,a0
  295.         bsr    Printer
  296.         bra    Looper1
  297.  
  298. Break:        lea.l    BreakText1,a0
  299.         bsr    Printer
  300.         clr.l    d0
  301.         rts
  302.  
  303. ClearSer:    move.l    IORRequest,a1
  304.         lib    Exec,CheckIO
  305.         tst.l    d0
  306.         beq    ClearSer1
  307.         move.l    IORRequest,a1
  308.         lib    Exec,WaitIO
  309.  
  310. ClearSer1:    move.l    IORRequest,a1
  311.         ABORTIO
  312.         move.l    IORRequest,a1
  313.         lib    Exec,WaitIO
  314.         rts
  315.  
  316. ;Buffered read from a device
  317. ;
  318. ;Inputs d0 = Buffer length (maximum amount to read)
  319. ;
  320. ;Result d0 = amount read
  321. ;
  322.  
  323. Read:        push    d2-d7/a2-a6
  324.         move.l    d0,d4
  325.  
  326.         tst.w    Requested
  327.         beq    Read3
  328.  
  329.         move.l    SRRPort,a0
  330.         lib    Exec,GetMsg
  331.         tst.l    d0
  332.         beq    Read_OUT1
  333.  
  334.         move.l    IORRequest,a1
  335.         tst.b    IO_ERROR(a1)
  336.         beq    Read1
  337.         clr.w    Requested
  338.         bra    Read_OUT1
  339.         
  340. Read1:        add.l    #1,Received
  341.         move.b    Buffer2,Buffer3
  342.         move.l    #1,BufCount
  343.         bra    Read3
  344.  
  345. Read2:        clr.l    BufCount
  346.  
  347. Read3:        move.l    IORRequest,a1
  348.         clr.b    IO_ERROR(a1)
  349.         or.b    #IOF_QUICK,IO_FLAGS(a1)
  350.         move.w    #1,Requested
  351.  
  352. ReadLoop:    cmp.l    BufCount,d4
  353.         beq    Read_OUT2
  354.  
  355.         move.l    IORRequest,a1
  356.         BEGINIO
  357.  
  358.         move.l    IORRequest,a1
  359.         tst.b    IO_ERROR(a1)
  360.         beq    ReadLoop1
  361.  
  362.         move.l    SRRPort,a0
  363.         lib    Exec,GetMsg
  364.         clr.w    Requested
  365.         bra    Read_OUT2
  366.         
  367. ReadLoop1:    move.l    IORRequest,a1
  368.         move.b    IO_FLAGS(a1),d0
  369.         and.b    #IOF_QUICK,d0
  370.         beq    Read_OUT2
  371.  
  372.         add.l    #1,Received
  373.         lea.l    Buffer3,a0
  374.         add.l    BufCount,a0
  375.         move.b    Buffer2,(a0)
  376.         add.l    #1,BufCount
  377.  
  378.         cmp.b    #LF,Buffer2
  379.         bne    ReadLoop
  380.         move.l    IORRequest,a1
  381.         move.b    IO_FLAGS(a1),d0
  382.         and.b    #~IOF_QUICK,d0
  383.         move.b    d0,IO_FLAGS(a1)
  384.         BEGINIO
  385.         move.l    IORRequest,a1
  386.         tst.b    IO_ERROR(a1)
  387.         beq    Read_OUT2
  388.         move.l    SRRPort,a0
  389.         lib    Exec,GetMsg
  390.         clr.w    Requested
  391.         bra    Read_OUT2
  392. Read_OUT1:    clr.l    d0
  393.         pull    d2-d7/a2-a6
  394.         rts
  395. Read_OUT2:    move.l    BufCount,d0
  396.         pull    d2-d7/a2-a6
  397.         rts
  398.  
  399. Reader:        move.l    IORRequest,a1
  400.         move.w    #CMD_READ,IO_COMMAND(a1)
  401.         move.l    #1,IO_LENGTH(a1)
  402.         lea.l    Buffer2,a0
  403.         move.l    a0,IO_DATA(a1)
  404.         lib    Exec,SendIO
  405.         rts
  406.  
  407. Writer:        add.l    #1,Sent
  408.         move.l    IOWRequest,a1
  409.         lib    Exec,DoIO        ;May freeze, too bad
  410.         rts
  411. ;Writes string to serial port
  412. ;
  413. ;D0 = Length
  414. ;A0 = String
  415.  
  416. Writer2:    move.l    IOWRequest,a1
  417.         move.w    #CMD_WRITE,IO_COMMAND(a1)
  418.         move.l    d0,IO_LENGTH(a1)
  419.         move.l    a0,IO_DATA(a1)
  420.         lib    Exec,DoIO        ;May freeze, too bad
  421.  
  422. ;Reset back to default...
  423.  
  424.         move.l    IOWRequest,a1
  425.         move.w    #CMD_WRITE,IO_COMMAND(a1)
  426.         move.l    #1,IO_LENGTH(a1)        ;writes in one byte "chunks"
  427.         lea.l    Buffer1,a0
  428.         move.l    a0,IO_DATA(a1)
  429.         rts
  430.  
  431.  
  432. GiveStats:    lea.l    fstrl1,a0        ;HEX->ASCII
  433.         lea.l    Received,a1        ;Number2Print
  434.         lea.l    PutChProc,a2
  435.         lea.l    ReceivedText1,a3    ;Destination
  436.         lib    Exec,RawDoFmt
  437.  
  438.         lea.l    fstrl2,a0        ;HEX->ASCII
  439.         lea.l    Sent,a1            ;Number2Print
  440.         lea.l    PutChProc,a2
  441.         lea.l    SentText1,a3        ;Destination
  442.         lib    Exec,RawDoFmt
  443.  
  444.         lea.l    StatsText1,a0
  445.         bsr    Printer
  446.         lea.l    ReceivedText1,a0
  447.         bsr    Printer
  448.         lea.l    SentText1,a0
  449.         bsr    Printer
  450.         lea.l    CRLFText1,a0
  451.         bsr    Printer
  452.         rts
  453.  
  454. ShutDown:    tst.w    SerOpen
  455.         beq    ShutDown9000
  456.         bsr    ClearSer
  457.         move.l    IORRequest,a1
  458.         lib    Exec,CloseDevice
  459.  
  460. ShutDown9000:    move.l    IORRequest,a0
  461.         lib    Exec,DeleteIORequest
  462.  
  463. ShutDown8000:    move.l    SRRPort,a0
  464.         lib    Exec,DeleteMsgPort
  465.  
  466. ShutDown7000:    move.l    IOWRequest,a0
  467.         lib    Exec,DeleteIORequest
  468.  
  469. ShutDown6000:    move.l    SWRPort,a0
  470.         lib    Exec,DeleteMsgPort
  471.  
  472. ShutDown5000:    move.l    _stdin,d1
  473.         beq    ShutD