home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / a / tcomtxt.asm < prev   
Assembly Source File  |  2020-01-01  |  9KB  |  295 lines

  1. ; To: kermit@columbia.edu 
  2. ; Subject: Small ASCII encoded comm program for DOS
  3. ; Date: Tue, 16 Apr 2002 16:41:37 -0600 (MDT)
  4. ; From: carruth@ece.utah.edu (Brent Carruth)
  5. ;
  6. ; I have put together ASM code that generates a small ASCII encoded comm
  7. ; program for DOS. It may prove useful to others and so I am sending it
  8. ; to you for inclusion in the MS-KERMIT software repository. Included below
  9. ; is a file which I have named TCOMTXT.ASM. If you need to rename the file,
  10. ; then a few lines in the commented source code need to reflect this change.
  11. ;
  12. ; Brent L. Carruth, Ph.D.
  13. ; ----------------------------------------------------------------------
  14. ; This program is useful in copying files to a computer using only the
  15. ; serial port and starting with only the COPY command.
  16. ;
  17. ; Use this program to generate TCOM.COM for MS-DOS with the commands:
  18. ;
  19. ;   TASM TCOMTXT
  20. ;   TLINK TCOMTXT /T
  21. ;   TCOMTXT > TCOM.COM
  22. ;
  23. ; The resulting TCOM.COM file is encoded with only printable 7-bit ASCII
  24. ; characters. It can be entered as plain text (shown below) and executed.
  25. ; TCOM is a 185 byte (with CRLFs) comm program that sets port 1 to 300
  26. ; baud and polls it. To set port 2 replace 'ss' with 'ts'. To set 2400 baud
  27. ; replace '26' with 'V'. On 25MHz+ computers 2400 baud works fine.
  28. ;
  29. ; XPHPD[0GG0G,0G51G31GB'(G+(G:u'0g?(G>(GE1G@arwIV_F*=US@<1|_,5wXNg-7muTu(4
  30. ; 1m0ss1k260s@3G1g360@3G0i7t2g3A1g350@3G2E1=0C1g350@3T2M0^\1g3>0@3T=1s2g0T
  31. ; 1g3;0@3ToN2g391g0t@3G0^F1k0s2?0@3T4
  32. ;
  33. ;
  34. ; The loader and builder portions of this program were written by
  35. ; Dan Norstedt, Stockholm, Sweden on 17 Feb 1990 who placed them in the
  36. ; public domain. He notes that they may be useful for other programs, too.
  37. ;
  38. ;
  39. ; The source code for the comm program portion of this program was modified
  40. ; from a debug listing of the TINYCOMM.COM program shown and explained in an
  41. ; article describing it (along with other related matters, including a tiny
  42. ; comm program in BASIC) in a 26911-byte file named TINYCOMM.TXT dated 13 Dec
  43. ; 1986. Unfortunately, no author is listed in this article. However, the
  44. ; author of the article is presumably Charles Petzold because, when assembled
  45. ; with debug, the TINYCOMM program described in the article is byte-for-byte
  46. ; identical to the first 49 bytes of the 103 byte TINYCOMM program dated
  47. ; 1 Jun 1988 from PC-MAG Utilities and the last 54 bytes includes the string
  48. ; ' by Charles Petzold - (c) 1988 Ziff Communications Co.'
  49. ;
  50. ;
  51. ; I have changed the source code for TINYCOMM in two trivial, but significant,
  52. ; ways related to file transfers. The first is that COM1 is initialized to 300
  53. ; baud but may be readily changed to either COM2 and/or 2400 baud. The second
  54. ; is that the program exits by pressing Esc. This makes it possible to use
  55. ; TCOM to download a file from another computer connected with a fully-wired
  56. ; null modem cable with 'TCOM > filename' and pressing Esc when done. I use
  57. ; MS-Kermit on the other computer to upload the file with the commands "set
  58. ; port 1, set speed 300, set local-echo on, set transmit line-feeds-sent on,
  59. ; set transmit prompt \0, transmit filename". To get TCOM on the first
  60. ; computer to begin with, carefully type it in using the standard DOS
  61. ; 'COPY CON TCOM.COM' command and pressing Ctrl-Z when done. MSBPCG.ASM is
  62. ; another program by Dan Norstedt that generates a 557 byte 7-bit ASCII encoded
  63. ; program named MSBPCT.COM that decodes standard Kermit bootstrap or "BOO"
  64. ; files. The first BOO file downloaded should be a small, reliable file trans-
  65. ; fer program. Thus, starting with a DOS boot disk having only the system files
  66. ; and COMMAND.COM it is possible to get other files copied to this disk using
  67. ; only the serial port and starting with only the DOS 'COPY' command.
  68. ;
  69. ;
  70. ; Brent L. Carruth, Ph.D.
  71. ; 9 April 2002
  72.  
  73.     CODE    SEGMENT PUBLIC
  74.  
  75.     ASSUME    CS:CODE,DS:CODE
  76.  
  77.     ORG    100H
  78.  
  79. START:    JMP    GENCOM
  80.  
  81.     ORG    100H+72+1    ; Address where loader starts loading
  82.  
  83. CODARE:
  84.  
  85. ;----------------------- beginning of PROGRAM code area -----------------------
  86.  
  87. ;TCOM.ASM -- assemble with TASM v1.0
  88. ;58 byte communications program that polls COM1 at 300 baud.
  89. ;Esc key exits. Avoid Ctrl-P.
  90. ;Major portions attributable to Charles Petzold.
  91. ;
  92. ;Brent L. Carruth, Ph.D.
  93. ;18 April 2002
  94. ;
  95. ;CODE    SEGMENT    PARA
  96. ;    ASSUME    CS:CODE,DS:CODE
  97. ;    ORG    100H
  98.  
  99. BEGIN:    MOV    DX,0        ; 0 FOR COM1 (1 FOR COM2)
  100.     MOV    AX,43H        ; SET PORT 300,N,8,1 (0A3H FOR 2400,N,8,1)
  101.     INT    14H
  102. TC_1:    MOV    AH,03        ; GET COMM PORT STATUS
  103.     INT    14H
  104.     TEST    AH,01        ; IF NO DATA READY, GO ON
  105.     JZ    TC_2
  106.     MOV    AH,02        ; READ CHARACTER FROM COMM PORT
  107.     INT    14H
  108.     PUSH    DX
  109.     MOV    DL,AL
  110.     MOV    AH,02        ; WRITE TO DISPLAY
  111.     INT    21H
  112.     POP    DX
  113.     JMP    TC_1        ; LOOP AROUND
  114. TC_2:    MOV    AH,0BH        ; CHECK KEYBOARD
  115.     INT    21H
  116.     OR    AL,AL
  117.     JZ    TC_1
  118.     MOV    AH,08        ; IF CHAR, READ IT
  119.     INT    21H
  120.     CMP    AL,1BH        ; IS IT ESC KEY ?
  121.     JZ    QUIT        ; YES, QUIT
  122.     MOV    AH,01        ; NO, SEND TO MODEM
  123.     INT    14H
  124.     JMP    TC_1        ; LOOP AROUND
  125. QUIT:    MOV    AX,4C00H    ; EXIT TO DOS
  126.     INT    21H
  127. ;CODE    ENDS
  128. ;    END    BEGIN
  129.  
  130. ;-------------------------- end of PROGRAM code area --------------------------
  131.  
  132. CODEND:
  133.  
  134. ;-- Loader starts here; don't touch unless you REALLY know what's going on --
  135.  
  136. FIXUP    MACRO    LABL,OFFS,DAT,DA2,DAS
  137.     ORG    $+(OFFS)
  138. LABL    Label    Byte
  139.     IFNB    <DAS>
  140.      IFNB    <DA2>
  141.       DB     (((DAS) OR 65H)-((DAS) AND 65H)) AND 0FFH,0FFH-(DA2)
  142.       ORG     $-1H
  143.      ELSE
  144.       DB     ((DAS)+65H) AND 0FFH
  145.      ENDIF
  146.     ELSE
  147.      DB    0FFH-((DAT) AND 0FFH)
  148.      IFNB    <DA2>
  149.       DB     0FFH-(DA2)
  150.       ORG     $-1H
  151.      ENDIF
  152.     ENDIF
  153.     ORG    $-(OFFS)-1H
  154.     ENDM
  155.  
  156. FIXBYT    MACRO    ADDR     ; Generate "XOR [BX+ADDR-0FFH],AL" with 8-bit offset
  157.     DB    30H,47H,(Offset ADDR-Offset LOADER+100H)-0FFH
  158.     ENDM
  159.  
  160. FIXBYH    MACRO    ADDR     ; Generate "XOR [BX+ADDR-0FFH],AH" with 8-bit offset
  161.     DB    30H,67H,(Offset ADDR-Offset LOADER+100H)-0FFH
  162.     ENDM
  163.  
  164. FIXWRD    MACRO    ADDR     ; Generate "XOR [BX+ADDR-0FFH],AX" with 8-bit offset
  165.     DB    31H,47H,(Offset ADDR-Offset LOADER+100H)-0FFH
  166.     ENDM
  167.  
  168. FIXSUB    MACRO    ADDR     ; Generate "SUB [BX+ADDR-0FFH],AL" with 8-bit offset
  169.     DB    28H,47H,(Offset ADDR-Offset LOADER+100H)-0FFH
  170.     ENDM
  171.  
  172. LOADER:    POP    AX
  173.     PUSH    AX
  174.     DEC    AX        ; Load AX with 0FFFFH
  175.     PUSH    AX        ; Now FF FF 00 00 on stack
  176.     INC    SP
  177.     POP    BX        ; Load BX with 00FF
  178.     FIXBYT    XORBXX        ; Fix up end of loader code
  179.     FIXBYT    XORB1
  180.     FIXBYT    XORB2
  181.     FIXWRD    XORW1
  182.     FIXWRD    XORW2
  183.     DAA            ; Load AL with 65H
  184.     FIXSUB    SUBB1
  185.     FIXSUB    SUBB2
  186.     JNZ    J0JMP        ; Break pipeline
  187. J0DST:    FIXBYH    XORB3
  188.     FIXSUB    SUBB3
  189.     FIXSUB    SUBB4
  190.     FIXWRD    XORX1
  191.  
  192. ; FC
  193.     CLD            ; Set LODSB direction
  194.     FIXUP    SUBB1,-1H,,,0FCH
  195. ; 8D7749  LEA    SI,[BX+DATA-0FFH] ; Point at 100H+72
  196.     DB    8DH,77H,(Offset DATA-Offset LOADER+100H)-0FFH
  197.     FIXUP    XORB1,-3H,8DH
  198. ; 56
  199.     PUSH    SI        ; Copy SI -> DI
  200. ; 5F
  201.     POP    DI
  202. ; 46
  203.     INC    SI
  204. J2DST:
  205. ; 2AC2
  206.     SUB    AL,DL        ; Compute real code/data byte
  207. ; AA
  208.     STOSB            ; Save it
  209.     FIXUP    XORW1,-2H,0C2H,0AAH
  210. J1DST:
  211. J3DST:
  212. ; AC
  213.     LODSB            ; Get an encoded data byte
  214.     FIXUP    XORB2,-1H,0ACH
  215. ; 40
  216.     INC    AX
  217. ; 3C31
  218.     CMP    AL,31H        ; Printable and >= '0'?
  219. ; 7CFA
  220.     JL    J1DST
  221. J1SRC:    FIXUP    SUBB2,-1H,,,J1DST-J1SRC
  222. ; 2C35
  223.     SUB    AL,'4'+1    ; Yes, '0'-'3' (or '4' = exit code) ?
  224. ; 77F3
  225.     JA    J2DST        ; No, store with current prefix code
  226. J2SRC:    FIXUP    SUBB3,-1H,,,J2DST-J2SRC
  227. ; B102
  228.     MOV    CL,2H
  229.     FIXUP    XORB3,-2H,0B1H
  230. ; D2C8
  231.     ROR    AL,CL
  232.     FIXUP    XORX1,-3H,,0D2H,2H
  233. ; 92
  234.     XCHG    DX,AX        ; Yes, just save shifted value
  235.     FIXUP    XORW2,-2H,0C8H,92H
  236. ; 75EF
  237.     JNZ    J3DST        ; No, contine loop
  238. J3SRC:    FIXUP    SUBB4,-1H,,,J3DST-J3SRC
  239. ; 75D7
  240. J0JMP:    JNZ    J0DST        ; (Dummy branch used to clear prefetch queue)
  241. J0SRC:    FIXUP    XORBXX,-1H,J0DST-J0SRC
  242.     DB    34H        ; Skip over next byte (34H = XOR AL,nn opcode)
  243.  
  244. DATA:    DB    "$"        ; CRLF data to make sure JL J1DST taken first time
  245.  
  246. GENCOM:    PUSH    CS            ; Allow use without EXE2BIN
  247.     POP    DS
  248.     MOV    DX,Offset LOADER    ; Output LOADER code (!)
  249.     MOV    AH,9H
  250.     INT    21H
  251.     CLD
  252.     MOV    SI,Offset CODARE    ; Pointer to real PROGRAM code
  253.     XOR    BP,BP            ; Reset columns left counter
  254.     MOV    BH,17            ; Assure that BH not in range '0'-'3'
  255. BYTLOP:    MOV    AX,0C01H
  256.     SUB    AL,[SI]            ; Convert PROGRAM code to loader format
  257.     INC    SI
  258.     MOV    CL,2H
  259.     SHL    AX,CL            ; First byte is top 2 bits of byte+43H
  260.     NOT    AL
  261.     SHR    AL,CL            ; Second byte is low 6 bits of -byte-3
  262.     ADD    AL,35H            ; Based value is '5' for second byte
  263.     CMP    AH,BH            ; Same prefix as previous byte?
  264.     MOV    BH,AH
  265.     XCHG    DX,AX
  266. OUTBYT:    XCHG    DH,DL            ; Swap output order
  267.     JZ    OUTNHI            ; Skip unnecessary prefix byte
  268.     DEC    BP
  269.     JG    OUTNCR            ; Not 72 chars on the line yet
  270.     PUSH    DX
  271.     MOV    DX,Offset CRLF        ; 72 chars on line, add CR LF
  272.     MOV    AH,9H
  273.     INT    21H
  274.     MOV    BP,48H            ; Restart line pointer
  275.     POP    DX
  276. OUTNCR:    MOV    AH,2H            ; Output a byte
  277.     INT    21H
  278. OUTNHI:    XOR    DL,DL            ; Clear out used code byte
  279.     AND    DH,DH            ; Anything more to print?
  280.     JNZ    OUTBYT
  281.     CMP    SI,Offset CODEND    ; End of area?
  282.     JNZ    BYTLOP
  283.     MOV    DX,Offset ENDTXT    ; Yes, add trailer: 34H and CR LF
  284.     MOV    AH,9H
  285.     INT    21H
  286.     MOV    AH,4CH            ; End GENCOM program section
  287.     INT    21H
  288.  
  289. ENDTXT    DB    34H            ; End of file marker for loader
  290. CRLF    DB    0DH,0AH,"$"
  291.  
  292. CODE ENDS
  293.     END    START
  294.  
  295.