home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / MOUSE / COMM1_34.ZIP / RX.ASM < prev    next >
Encoding:
Assembly Source File  |  1986-07-22  |  4.2 KB  |  203 lines

  1. PAGE    60,132
  2. ;
  3. ; RX        by DIGIBOARD INC.        07-07-86
  4. ;
  5. ; RX is the "bare-bones" of a utility to copy files or other
  6. ; serial data from one system to a file on this system. You call
  7. ; RX with a valid file name (not however a full path name) as
  8. ; a parameter and answer the what port question and all the data
  9. ; read from the serial port is coppied to a 64k buffer. When
  10. ; the ESC key is pressed the data collection is ended and the
  11. ; buffer contents are written to the named file.
  12. ;
  13. ; conditional assembly
  14. ;
  15. INIT    EQU    0    ; 1= initialise port / 0 = do not
  16. ;
  17. ; constants
  18. ;
  19. CR    EQU    0DH    ; carrage return
  20. LF    EQU    0AH    ; line feed
  21. ESC    EQU    1BH    ; escape character
  22. FCB    EQU    5CH    ; start of input FCB
  23. ;
  24.     .SALL
  25. ;
  26. CODE    SEGMENT
  27. ASSUME    CS:CODE,DS:CODE
  28. ;
  29. ;
  30. ;
  31. RX    PROC    FAR
  32.     STI
  33.     PUSH    DS        ; pointer to FCBs segment
  34.     MOV    AX,CS        ; set up
  35.     MOV    DS,AX
  36. ;
  37. ; get the extra memory (see end for P_SIZE generation)
  38. ;
  39.     POP    ES
  40.     PUSH    ES
  41.     MOV    BX,4096+P_SIZE    ; ask for 64k in paragraphs
  42.     MOV    AH,4AH        ; grow some more memory
  43.     INT    21H
  44.     JC    K2        ; error return
  45.     MOV    AX,ES        ; move ES to the new segment
  46.     ADD    AX,P_SIZE
  47.     MOV    ES,AX        ; AX is the paragraph number
  48. ;
  49. ; find out what port they want to use
  50. ; 2 digits or 1 digit carrage return
  51. ;
  52.     MOV    DX,OFFSET MSG    ; sign on + port request
  53.     MOV    AH,9        ; print a string
  54.     INT    21H
  55. ;
  56.     MOV    AH,1        ; get and echo a key
  57.     INT    21H
  58.     CMP    AL,'1'        ; first port
  59.     JL    K2        ; to small
  60.     CMP    AL,'9'        ; max
  61.     JG    K2
  62.     SUB    AL,'0'
  63.     MOV    DL,AL
  64.     XOR    DH,DH
  65.     MOV    AH,1        ; get and echo a second key
  66.     INT    21H
  67.     CMP    AL,CR        ; if carrage return then use DX
  68.     JE    K1
  69.     CMP    AL,'9'        ; test that we have a digit
  70.     JG    K2
  71.     SUB    AL,'0'
  72.     JL    K2
  73.     XOR    AH,AH        ;P.P
  74.     XCHG    AX,DX        ; get tens in AX
  75.     MOV    CL,10
  76.     MUL    CL
  77.     ADD    DX,AX
  78. K1:    CMP    DX,34        ;10 current maximum
  79.     JG    K2
  80.     DEC    DX
  81.     MOV    COM,DX        ; set this as the port to use
  82.     JMP    SHORT K3
  83. K2:    JMP    K7        ; help out the relative jumps
  84. K3:
  85. ;
  86. ; if initialisation set the port up
  87. ;
  88.     IF    INIT EQ 1
  89.     MOV    DX,COM
  90.     MOV    AH,0
  91.     MOV    AL,083H        ; 1200 baud,8 bit,no-parity
  92.     INT    14H
  93.     ENDIF
  94. ;
  95.     MOV    DI,1        ; offset (ES: is segment)
  96. ;
  97. ; hunt for keys and data from the line
  98. ;
  99. K4:    MOV    AH,1        ; keyboard status
  100.     INT    16H
  101.     JZ    K5        ; no character
  102.     MOV    AH,0        ; read the character
  103.     INT    16H
  104.     CMP    AL,ESC        ; if it's ESC we exit
  105.     JZ    K6
  106.     JMP    SHORT K4    ; keep looking
  107. ;
  108. K5:     MOV    AH,3
  109.     MOV    DX,COM        ; com:
  110.     INT    14H        ; serial status
  111.     TEST    AH,80H        ; this may be a nasty
  112.     JNZ    K8        ; sort it out
  113.     TEST    AH,1        ; DAV ?
  114.     JZ    K4        ; no
  115.     MOV    AH,2
  116.     INT    14H        ; recieve a char
  117.     MOV    ES:-1[DI],AL    ; save the character
  118.     INC    DI        ; next space
  119.     OR    DI,DI        ; test DI
  120.     JNZ    K4
  121. ;
  122. ; save the data to a file
  123. ;
  124. K6:    MOV    AX,ES
  125.     MOV    DS,AX        ; buffer segment
  126.     MOV    DX,0        ; buffer offset
  127.     MOV    AH,1AH        ; set DMA address
  128.     INT    21H        ;   to DS:DX
  129. ;
  130.     POP    DS
  131.     DEC    DI        ; convert DI to count
  132.     OR    DI,DI
  133.     JZ    K7        ; nothing to do
  134.     MOV    DX,OFFSET FCB    ; point to the FCB
  135.     MOV    AH,13H        ; delete file
  136.     INT    21H
  137. ;
  138.     MOV    AH,16H        ; create and open a new file
  139.     INT    21H
  140.     MOV    AX,DI
  141.     MOV    WORD PTR DS:FCB+14,AX    ; set the record size
  142.     MOV    AH,15H            ; write to file
  143.     INT    21H
  144. ;
  145.     MOV    AH,10H        ; close file
  146.     INT    21H
  147. ;
  148. K7:    MOV    AX,CS        ; get DS back
  149.     MOV    DS,AX
  150.     MOV    DX,OFFSET MSG1    ; sign off
  151.     MOV    AH,9        ; print a string
  152.     INT    21H
  153. ;
  154.     MOV    AH,4CH        ; return to DOS
  155.     MOV    AL,0        ; return code
  156.     INT    21H
  157. ;
  158. ; sort out scrambled compatables
  159. ; ( this problem does not occur on IBM PCs or with
  160. ;   the Com-4/Com-8 drivers )
  161. ;
  162. K8:    MOV    AH,2
  163.     INT    14H        ; recieve a char
  164.     JMP    K4
  165. ;
  166. RX    ENDP
  167. ;
  168. COM    DW    ?        ; com device to use
  169. ;
  170. MSG    DB    CR,LF,'RX : copies from a com port to a file'
  171.     DB    CR,LF,'by DIGIBOARD INC.  ver 2.10'
  172.     DB    CR,LF,LF,'Key ESC to terminate session'
  173.     IF    INIT EQ 1
  174.     DB    CR,LF,'Port is initialised to 1200 baud,'
  175.     DB    '8 bit no parity'
  176.     ELSE
  177.     DB    CR,LF,'Port is expected to be previously'
  178.     DB    ' initialised'
  179.     ENDIF
  180.     DB    CR,LF,LF,'Which com port do you wish to '
  181.     DB    'use? (1-34) $'
  182. ;
  183. MSG1    DB    CR,LF,LF,'RX Terminating$'
  184. ;
  185. FINISH    EQU    $
  186. ;
  187. ; P_SIZE is the total program size in paragraphs
  188. ;    (FINISH-RX)/16 = size of CODE segment
  189. ;    1 = margin for up to 15 bytes lost in integer division
  190. ;    10H = 100H bytes of PSP
  191. ;    5 = 40 words of SSEG
  192. ;
  193. P_SIZE    EQU    (FINISH-RX)/16+1+10H+5
  194. ;
  195. CODE    ENDS
  196. ;
  197. SSEG    SEGMENT    PARA STACK 'STACK'
  198.     DB    40 DUP (?)
  199. SSEG    ENDS
  200. ;
  201.     END    RX        ;execution address
  202. ;
  203.