home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / BNU202.ZIP / FTYPE.ASM < prev    next >
Assembly Source File  |  1989-06-02  |  7KB  |  461 lines

  1. ;
  2. ; FTYPE        Type a file to a COM Port
  3. ;
  4.  
  5. COM equ 1
  6.  
  7. ifdef ??version
  8.     masm51
  9.     quirks
  10. endif
  11.  
  12. _code    segment byte
  13.   if COM
  14.     org    0100H
  15.   endif
  16.     assume    cs:_code
  17. _go:
  18.     jmp _start
  19.  
  20. PortNum    dw 0        ; Assumes port 0
  21. ChgBaud    dw -1        ; -1 means don't change
  22. Share    dw 0        ; FOSSIL is shared
  23. IsInit    dw 0        ; FOSSIL is initialised
  24. Carrier    dw 0        ; Don't check carrier if non-zero
  25. Handle    dw 0        ; DOS file handle
  26. DoEcho    dw 0        ; Echo to screen as well
  27.  
  28. RateTbl    dw 0043H    ; 300 baud
  29.     dw 0063H    ; 600 baud
  30.     dw 0083H    ; 1200 baud
  31.     dw 00a3H    ; 2400 baud
  32.     dw 00c3H    ; 4800 baud
  33.     dw 00e3H    ; 9600 baud
  34.     dw 0003H    ; 19200 baud
  35.     dw 0023H    ; 38400 baud
  36.  
  37. BaudTbl    dw 300
  38.     dw 600
  39.     dw 1200
  40.     dw 2400
  41.     dw 4800
  42.     dw 9600
  43.     dw 19200
  44.     dw 38400
  45.  
  46. _bmark    equ $
  47.  
  48. UseText    db 'FTYPE v1.10   Type a file to a port via FOSSIL',13,10
  49.     db '              Copyright (C) 1992  David Nugent & Unique Computing Ptd Ltd',13,10,10
  50.     db 'Usage: ftype [/Pn] [/Bnnn] [/S] [/N] <filename>',13,10,10
  51.     db '   Where:  /Pn    Optional port number: 0=COM1 1=COM2 ... (default is 0, COM1)',13,10
  52.     db '           /Bnnnn Optional baud rate (default is current baud rate)',13,10
  53.     db '           /S     Leaves FOSSIL driver active on exit',13,10
  54.     db '           /N     Proceed even if carrier is not present',13,10
  55.     db '           /E     Type output to screen (as well)',13,10
  56.     db 10
  57.  
  58. _utend    equ $
  59.  
  60. NoFoss    db 13,10,'ftype: No FOSSIL loaded!',13,10
  61. _nfend    equ $
  62. NoPort    db 13,10,'ftype: FOSSIL init error (port not available)?',13,10
  63. _nport    equ $
  64. NoCarr    db 13,10,'ftype: No carrier - lost caller?',13,10
  65. _ncarr    equ $
  66. SndErr    db 13,10,'ftype: Error sending string!',13,10
  67. _serr    equ $
  68. TimErr    db 13,10,'ftype: Timeout waiting for output to clear!',13,10
  69. _terr    equ $
  70. InBaud    db 13,10,'ftype: Invalid baud rate specified',31,10
  71. _vbaud    equ $
  72. NoFile    db 13,10,'ftype: Unable to open file',13,10
  73. _nfile    equ $
  74. RdErr    db 13,10,'ftype: Error reading file',13,10
  75. _rerr    equ $
  76.  
  77. _start:
  78.  
  79. ; Scan the command line for switches
  80.  
  81.   if COM
  82.     assume ds:_code, es:_code
  83.   else
  84.     mov ax,cs
  85.     mov ds,ax
  86.     assume ds:_code,es:nothing
  87.   endif
  88.     mov SI,080H
  89.     mov AL,ES:[SI]
  90.     inc SI
  91.     mov DI,SI
  92.     mov CL,AL
  93.     xor CH,CH
  94.     cmp CX,1
  95.     jg @S
  96.     jmp Usage
  97. @S:
  98.     mov AL,byte ptr ES:[SI]
  99.     cmp AL,020H
  100.     je @F
  101.     cmp AL,009H
  102.     jne @N
  103. @@:
  104.     inc SI
  105.     loop @S
  106.     jmp Usage
  107. @N:
  108.     cmp AL,'/'
  109.     jne _ChkFile
  110.     inc SI
  111.     dec CX
  112.     mov AL,byte ptr ES:[SI]
  113.     inc SI
  114.     dec CX
  115.     cmp CX,1
  116.     jg @F
  117.     jmp Usage
  118. @@:
  119.     cmp AL,'a'
  120.     jb @F
  121.     cmp AL,'z'
  122.     ja @F
  123.     sub AL,32
  124. @@:
  125.     cmp AL,'P'
  126.     jne @F
  127.     jmp @Port
  128. @@:
  129.     cmp AL,'B'
  130.     jne @F
  131.     jmp @Baud
  132. @@:
  133.     cmp AL,'S'
  134.     je @Share
  135.     cmp AL,'E'
  136.     je @Echo
  137.     cmp AL,'N'
  138.     je @F
  139.     jmp Usage
  140. @@:
  141.     inc Carrier
  142.     jmp @S
  143. @Echo:
  144.     inc DoEcho
  145.     jmp @S
  146. @Share:
  147.     inc Share
  148.     jmp @S
  149.  
  150. ;
  151. ; Check tha file exists and can be opened
  152. ;
  153. _ChkFile:
  154.     mov BX,offset BufferStart
  155.     add BX,800FH                ; Add buffer and round
  156.     mov AX,CS
  157.     sub BX,AX
  158.     shr BX,1
  159.     shr BX,1
  160.     shr BX,1
  161.     shr BX,1
  162.     mov AH,04aH                ; Chop off memory for DOS 4.x->
  163.     int 021H
  164.  
  165.     mov DX,SI                ; Find end of string
  166. @@:
  167.     lodsb
  168.     cmp AL,0dH
  169.     je @F
  170.     cmp AL,020H
  171.     je @F
  172.     cmp AL,09H
  173.     je @F
  174.     loop @B
  175.     inc SI
  176. @@:
  177.     dec SI                    ; ASCIZ string
  178.     mov byte ptr [SI],0
  179.     xor AL,AL                ; Open read_only
  180.     mov AH,03DH
  181.     int 021H
  182.     jnc @F
  183.     mov DX,offset NoFile
  184.     mov CX,_nfile - NoFile
  185.     jmp Error
  186. @@:
  187.     mov Handle,AX                ; Save handle
  188.     xor CX,CX                ; No bytes currently in buffer
  189. ;
  190. ; Check that a FOSSIL exists
  191. ;
  192.     push ES
  193.     mov AX,03514H                ; Check INT 14H vector
  194.     int 021H
  195.     cmp ES:[BX+6],01954H
  196.     pop ES
  197.     je @F
  198.     mov DX,offset NoFoss
  199.     mov CX,_nfend - NoFoss
  200.     jmp Error
  201. @@:
  202.     mov AH,04H
  203.     mov DX,PortNum
  204.     int 014H                ; Initialise FOSSIL driver
  205.     cmp AX,01954H
  206.     je @F
  207.     mov DX,offset NoPort
  208.     mov CX,_nport - NoPort
  209.     jmp Error
  210. @@:
  211.     cmp ChgBaud,-1
  212.     je @M
  213.     mov AL,byte ptr ChgBaud            ; Set baud rate
  214.     xor AH,AH
  215.     mov DX,PortNum
  216.     int 014H
  217. @M:
  218.     push CS
  219.     inc IsInit
  220. @@:
  221.     cmp CX,0                ; How many bytes left?
  222.     jne @F
  223.     mov DX,offset BufferStart
  224.     mov CX,8000                ; 32K chunks
  225.     mov BX,Handle
  226.     mov AH,03fH                ; Read next slab
  227.     int 021H
  228.     mov CX,AX                ; Update counter
  229.     mov SI,offset BufferStart        ; And start of buffer
  230.     jnc @F
  231.     mov DX,offset RdErr            ; File read error
  232.     mov CX,_rerr - RdErr
  233.     jmp SHORT Error
  234. @@:
  235.     jcxz _nomore                ; End of file
  236.     lodsb
  237.     call @Send                ; Send next one
  238.     dec CX
  239.     push CX
  240.     xor CX,CX                ; Large timeout value
  241. @J:
  242.     mov AH,03H
  243.     mov DX,PortNum
  244.     int 014H
  245.     cmp Carrier,0
  246.     jne @F
  247.     test AL,080H                ; Is carrier up?
  248. @cl:
  249.     mov DX,offset NoCarr
  250.     mov CX,_ncarr - NoCarr
  251.     jmp SHORT Error
  252. @@:
  253.     and AH,40H                ; Is TX buffer empty yet?
  254.     jnz @F
  255.     loop @J
  256.     jmp SHORT @to
  257. @@:
  258.     mov AH,0DH
  259.     int 014H
  260.     cmp AX,-1
  261.     je @F
  262.     mov AH,0EH
  263.     int 014H
  264.     cmp AL,27                ; Was ESC hit?
  265.     je @End
  266. @@:
  267.     pop CX
  268.     jmp @M
  269.  
  270. _nomore:
  271.     mov AL,13                ; Send CR
  272.     call @Send
  273.     mov AL,10                ; Send LF
  274.     call @Send
  275.  
  276.     xor CX,CX                ; Large timeout value
  277. @H:
  278.     mov AH,03H
  279.     mov DX,PortNum
  280.     int 014H
  281.     cmp Carrier,0
  282.     jne @F
  283.     test AL,080H                ; Is carrier up?
  284.     jz @cl
  285. @@:
  286.     and AH,40H                ; Is TX buffer empty yet?
  287.     jnz @End
  288.     loop @H
  289. @to:
  290.     mov DX,offset TimErr            ; Transmitter timed out
  291.     mov CX,_terr - TimErr
  292.     jmp SHORT Error
  293.  
  294. @End:
  295.     xor AL,AL
  296.     jmp SHORT Exit
  297.  
  298. ;---------
  299.  
  300. Usage:
  301.     mov DX,offset UseText
  302.     mov CX,_utend - UseText
  303.  
  304. ;---------
  305.  
  306. Error:
  307.     mov BX,2
  308.     call Write
  309.     mov BX,1
  310.     cmp IsInit,0
  311.     je Exit
  312.     mov AL,1
  313.  
  314. ; -------
  315.  
  316. Exit:
  317.     cmp Share,0
  318.     jne @F
  319.     cmp IsInit,0
  320.     je @F
  321.     mov AH,05H
  322.     mov DX,PortNum
  323.     int 014H
  324. @@:
  325.     mov BX,Handle
  326.     or BX,BX            ; Close file
  327.     je @F
  328.     mov AH,03fH
  329.     int 021H
  330. @@:
  331.     mov AH,04CH
  332.     int 021H
  333.  
  334. ; -------
  335.  
  336. Write:
  337.     mov AH,040H
  338.     int 021H
  339.     ret
  340.  
  341. ;
  342. ; Parse port number
  343. ;
  344. @Port:
  345.     mov AL,byte ptr ES:[DI]
  346.     inc SI
  347.     dec CX
  348.     sub AL,'0'
  349.     xor AH,AH
  350.     mov PortNum,AX
  351.     jmp @S
  352. ;
  353. ; Parse baud rate
  354. ;
  355. @Baud:
  356.     xor DX,DX
  357.     xor AH,AH
  358. @L:
  359.     jcxz @F
  360.     mov AL,byte ptr ES:[SI]
  361.     cmp AL,'0'
  362.     jb @F
  363.     cmp AL,'9'
  364.     ja @F
  365.     inc SI
  366.     dec CX
  367.     sub AL,'0'
  368.     mov BX,DX
  369.     shl DX,1
  370.     shl DX,1
  371.     add DX,BX
  372.     shl DX,1
  373.     add DX,AX
  374.     jmp @L
  375. @@:
  376.     push CX
  377.     mov CX,(_bmark - BaudTbl)/2
  378.     mov BX,offset BaudTbl
  379. @@:
  380.     cmp DX,[BX]
  381.     je  @F
  382.     add BX,2
  383.     loop @B
  384.     pop CX
  385.     mov DX,offset InBaud
  386.     mov CX,_vbaud - InBaud
  387.     jmp Error
  388.  
  389. @@:
  390.     sub BX,BaudTbl - RateTbl
  391.     mov AX,[BX]
  392.     mov ChgBaud,AX
  393.     pop CX
  394.     jmp @S
  395.  
  396. ;
  397. ; Send a character to the port
  398. ;
  399.  
  400. @Send:
  401.     push CX
  402.     mov CX,512                ; Attempt sending 512 times
  403. @X:
  404.     push AX
  405.     mov AH,0BH                ; TX chr no wait
  406.     mov DX,PortNum
  407.     int 014H
  408.     or AL,AL                ; Character sent?
  409.     jne @F
  410.     pop AX
  411.     loop @X
  412.  
  413.     pop CX
  414.     pop AX                    ; Pop return address
  415.     mov DX,offset SndErr
  416.     mov CX,_serr - SndErr
  417.     jmp Error
  418. @@:
  419.     pop AX
  420.     cmp AL,13                ; Delay after CR or LF
  421.     je @F
  422.     cmp AL,10
  423.     jne @K
  424. @@:
  425.     xor CX,CX
  426.     mov AH,03H                ; Wait until its sent
  427. @@:
  428.     push AX
  429.     mov DX,PortNum
  430.     int 014H
  431.     and AH,040H
  432.     pop AX
  433.     jne @F
  434.     loop @B
  435.     jmp @to
  436. @@:
  437.     mov CX,3
  438.     push ES
  439.     mov BX,ES:[046cH]
  440. @Q:
  441.     sti
  442. @@:
  443.     cmp BX,ES:[046cH]
  444.     jne @B
  445.     loop @B
  446.     pop ES
  447. @K:
  448.     cmp DoEcho,0
  449.     je @F
  450.     mov AH,13H
  451.     int 014H
  452. @@:
  453.     pop CX                    ; Character sent
  454.     ret
  455.  
  456.  
  457. BufferStart label byte
  458. _code    ends
  459.  
  460. end    _go
  461.