home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / mskermit / msbpct.asm < prev    next >
Assembly Source File  |  2020-01-01  |  7KB  |  390 lines

  1.     TITLE    MSBPC2 MS-DOS System BOO to EXE Utility Program
  2.  
  3. ; (c) 1988 W.C. Parke, WGCP0086@GWUVM
  4.  
  5. ; This program converts a BOO file to an EXE or binary file
  6. ;
  7. ;  BOO files are ASCII files constructed from binary files and used
  8. ;  to transfer the files over networks or tape which do not accept binary.
  9. ;  The translation is by the following algorithm (by Bill Catchings): 
  10. ;    1. The name of the file is placed on the first line, in plain text,
  11. ;       followed by CR,LF
  12. ;    2. If a series of nulls occurs, a '~' (7EH) is used followed by
  13. ;       an byte number for the null count, with a '0' bias, up to 7EH.
  14. ;    3. Three byte sequences are coded as 4 bytes, taking 6 bits from
  15. ;       each byte and adding a '0' bias.
  16. ;    4. Carriage return/linefeeds are inserted to make lines break
  17. ;       at approximately column 76.
  18. ;
  19. ; MSBPC2 compiled with MASM 5.10.  Use LINK and EXE2BIN to make COM file.
  20. ;
  21. ; May be used with any BOO file on any MS-DOS path.
  22. ;
  23. ; This program translated the MSVIBM.BOO file in 15 seconds
  24. ; on an IBM XT clone.  MSBPCT V1.0 took 6 min. 32 sec.
  25. ; The dramatic speed up comes largely from using large
  26. ; local file buffers.
  27. ;
  28. ; MSBPC2 uses the file name on the first line of the BOO file
  29. ; for its output file.
  30.  
  31. LF    EQU    0AH
  32. CR    EQU    0DH
  33. BUFSIZ    EQU    6000H
  34.  
  35. CODE    SEGMENT
  36.     ASSUME    CS:CODE,DS:CODE,ES:CODE,SS:CODE
  37.  
  38.     ORG    100H
  39.  
  40. START:    JMP    BOO
  41. FHAND1    DW    0
  42. FNAM1    DB    80 DUP(0)
  43. FHAND2    DW    0
  44. FNAM2    DB    80 DUP(0)
  45. INVOC    DB    CR,LF,'MSBPC2 Version 1.1'
  46.     DB    CR,LF,'BOO file to binary file converter.'
  47.     DB    CR,LF,'(c) 1988 W.C. Parke',CR,LF,CR,LF,'$'
  48. DHPERR    DB    'Syntax:',CR,LF,LF
  49.     DB    '  MSBPC2 boofile',CR,LF,CR,LF,'$'
  50. DCONV    DB    'Converting $'
  51. DTO    DB    ' to $'
  52. DDOT    DB    ' ...$'
  53. DEXIST    DB    ' already exists. Overwrite it? $'
  54. DERROR    DB    CR,LF,'Error in file $'
  55. DOPERR    DB    'open$'
  56. DCRERR    DB    'creation$'
  57. DCHERR    DB    'character$'
  58. DCLERR    DB    'close$'
  59. DRDERR    DB    'read$'
  60. DWRERR    DB    'write$'
  61. DERRF    DB    '.',CR,LF,'$'
  62. DONE    DB    CR,LF,'Done.',CR,LF,'$'
  63.  
  64. BOO:    MOV    AH,9
  65.     MOV    DX,OFFSET INVOC
  66.     INT    21H            ; invocation
  67.     MOV    SI,80H
  68.     LODSB
  69.     XOR    AH,AH            ; command line tail size
  70.     AND    AX,AX
  71.     JNZ    BOF
  72.     JMP    ABORTHP
  73. BOF:    MOV    DI,OFFSET FNAM1
  74.     INC    AX
  75.     MOV    CX,AX
  76.     PUSH    DI
  77. BO0:    LODSB
  78.     CMP    AL,CR
  79.     JZ    BO1
  80.     CMP    AL,20H
  81.     JZ    BOL
  82.     CMP    AL,'a'
  83.     JC    BOS
  84.     AND    AL,5FH
  85. BOS:    STOSB                ; save possible file name
  86. BOL:    LOOP    BO0
  87. BO1:    XOR    AL,AL
  88.     STOSB
  89.     POP    DX
  90.     MOV    AH,3DH        ; try to open file
  91.     INT    21H
  92.     JNC    BO2
  93.     JMP    ABORTOP
  94. BO2:    MOV    FHAND1,AX
  95.     MOV    DI,OFFSET FNAM2
  96.     MOV    SI,OFFSET FBUF1
  97.     XOR    AX,AX
  98.     MOV    CNT1,AX
  99.     MOV    CNT2,AX
  100. BOON:    CALL    GETBN        ; get file name from first line of file
  101.     JZ    BOG
  102.     STOSB
  103.     JMP    SHORT BOON
  104. BOG:    XOR    AL,AL
  105.     STOSB
  106.     MOV    DX,OFFSET FNAM2
  107.     XOR    CX,CX
  108.     MOV    AH,4EH
  109.     INT    21H        ; search for file in our directory
  110.     JC    BOZ        ; not there
  111.     PUSH    SI
  112.     MOV    SI,OFFSET FNAM2
  113.     CALL    SHOW
  114.     POP    SI
  115.     MOV    AH,9
  116.     MOV    DX,OFFSET DEXIST
  117.     INT    21H
  118.     MOV    AX,0C01H    ; say exists, overwrite?
  119.     INT    21H
  120.     PUSH    AX
  121.     MOV    AH,2
  122.     MOV    DL,CR
  123.     INT    21H
  124.     MOV    DL,LF
  125.     INT    21H
  126.     POP    AX
  127.     AND    AL,5FH
  128.     CMP    AL,'Y'
  129.     JZ    BOZ
  130.     JMP    EXIT
  131. BOZ:    MOV    DX,OFFSET FNAM2
  132.     MOV    AH,3CH
  133.     XOR    CX,CX
  134.     INT    21H        ; create output file
  135.     JC    ABORTCR
  136.     MOV    FHAND2,AX
  137.     PUSH    SI
  138.     MOV    AH,9
  139.     MOV    DX,OFFSET DCONV    ; say converting
  140.     INT    21H
  141.     MOV    SI,OFFSET FNAM1    ; this file
  142.     CALL    SHOW
  143.     MOV    AH,9
  144.     MOV    DX,OFFSET DTO    ; to
  145.     INT    21H
  146.     MOV    SI,OFFSET FNAM2    ; this one
  147.     CALL    SHOW
  148.     MOV    AH,9
  149.     MOV    DX,OFFSET DDOT    ; show dots
  150.     INT    21H
  151.     POP    SI
  152.     MOV    DI,OFFSET FBUF2
  153.     JMP    NEXT        ; conversion loop
  154. PUBLIC FIN
  155. FIN:    CALL    OUTLST
  156.     JC    ABORTCL
  157.     MOV    AH,9
  158.     MOV    DX,OFFSET DONE    ; say done
  159.     INT    21H
  160. EXIT:    MOV    AX,4C00H
  161.     INT    21H
  162. ABORTOP:
  163.     MOV    DX,OFFSET DOPERR    ; file open error
  164.     MOV    AL,2
  165.     JMP    ABORT
  166. ABORTCR:
  167.     MOV    DX,OFFSET DCRERR    ; file create error
  168.     MOV    AL,3
  169.     JMP    ABORT
  170. ABORTCL:
  171.     MOV    DX,OFFSET DCLERR    ; file close error
  172.     MOV    AL,7
  173.     JMP    ABORT
  174. PUBLIC NULLS                ; process nulls
  175. NULLS:    CALL    GETB
  176.     XOR    AH,AH
  177.     MOV    CX,AX
  178.     XOR    AL,AL
  179. PUBLIC NULLN
  180. NULLN:    CALL    OUTB
  181.     LOOP    NULLN
  182. PUBLIC NEXT
  183. NEXT:    CALL    GETB
  184.     CMP    AL,'~'-'0'
  185.     JZ    NULLS            ; got a null code
  186.     MOV    AH,AL
  187.     CALL    GETB
  188.     MOV    BX,AX            ; save first code pair in bx
  189.     CALL    GETB
  190.     MOV    AH,AL
  191.     CALL    GETB            ; save second code pair in ax
  192.     SHL    AL,1
  193.     SHL    AL,1
  194.     SHL    BL,1
  195.     SHL    BL,1            ; bx ax = 0xxxxxx0 0xxxxxx0
  196.     SHL    AX,1
  197.     SHL    AX,1
  198.     SHR    BX,1
  199.     SHR    BX,1            ; bx ax = 00xxxxxx xxxxxx00
  200.  
  201.     SHL    AX,1
  202.     RCL    BX,1
  203.     RCL    AX,1
  204.     RCL    BX,1
  205.     RCL    AX,1
  206.     RCL    BX,1
  207.     RCL    AX,1
  208.     RCL    BX,1            ; bx ax = xxxxxxxx xxxx0000
  209.     MOV    DX,AX
  210.     MOV    AL,BH
  211.     CALL    OUTB
  212.     MOV    AL,BL
  213.     CALL    OUTB
  214.     MOV    AL,DH
  215.     CALL    OUTB
  216.     JMP    NEXT
  217.  
  218. PUBLIC GETB
  219. CNT1    DW    0
  220. GETBF:    CALL    GETMF        ; load buffer from file
  221.     JNC    GETBG
  222.     JMP    SHORT GETBEC    ; error loading buffer
  223.  
  224. GETB:                ; get a byte from input
  225.     CMP    WORD PTR CNT1,0
  226.     JZ    GETBF        ; no more bytes in buffer - read more in
  227. GETBG:    LODSB
  228.     DEC    WORD PTR CNT1
  229.     AND    AL,7FH        ; drop eigth bit
  230.     CMP    AL,7FH        ; our EOF byte
  231.     JZ    GETBFIN
  232.     CMP    AL,LF        ; skip lf's
  233.     JZ    GETB
  234.     CMP    AL,CR        ; skip cr's
  235.     JZ    GETB
  236.     CMP    AL,1AH        ;^Z
  237.     JZ    GETBFIN        ; EOF for ascii file
  238.     AND    AL,AL
  239.     JZ    GETBFIN        ; null also EOF for ascii file
  240.     SUB    AL,'0'        ; remove bias
  241.     JC    GETBEC        ; no other control codes allowed
  242.     RET
  243. GETBEC:    POP    AX
  244.     JMP    ABORTCH        ; character error in file
  245. GETBFIN:
  246.     POP    AX
  247.     JMP    FIN        ; write and close output file
  248.  
  249. GETMF:                ; get more from input file
  250.     PUSH    AX
  251.     PUSH    BX
  252.     PUSH    CX
  253.     PUSH    DX
  254.     MOV    BX,FHAND1
  255.     MOV    DX,OFFSET FBUF1    ; buffer for input file bytes
  256.     MOV    AH,3FH
  257.     MOV    CX,BUFSIZ    ; size of buffer
  258.     INT    21H        ; get bytes
  259.     MOV    SI,OFFSET FBUF1
  260.     POP    DX
  261.     POP    CX
  262.     POP    BX
  263.     JC    GETBC        ; error reading input file
  264.     MOV    CNT1,AX
  265.     CMP    AX,BUFSIZ
  266.     JC    GETBE        ; got less than full buffer
  267.     POP    AX
  268.     RET
  269. GETBE:    PUSH    BX
  270.     MOV    BX,WORD PTR CNT1
  271.     MOV    AX,07F7FH
  272.     MOV    WORD PTR [SI+BX],AX    ; terminator bytes are 7fh
  273.     POP    BX
  274.     CLC
  275. GETBC:    POP    AX        ; carry error
  276.     RET
  277.  
  278. PUBLIC GETBN
  279. GETBN:                ; get file name from first line of input file
  280.     CMP    WORD PTR CNT1,0
  281.     JZ    GETBM
  282. GETBNG:    LODSB
  283.     DEC    WORD PTR CNT1
  284.     AND    AL,7FH
  285.     CMP    AL,LF        ; end of line sets Zero flag
  286.     JZ    GETR
  287.     CMP    AL,CR        ; end of line sets Zero flag
  288. GETR:    RET
  289. GETBM:    CALL    GETMF        ; get more characters from file
  290.     JNC    GETBNG        ; ok to get a character from buffer
  291.     POP    AX
  292.     JMP    ABORTRD        ; file read error
  293.  
  294. PUBLIC OUTB
  295. CNT2    DW    0
  296. OUTBB:    CALL    OUTBF
  297.     JC    OUTBCA
  298. OUTB:                ; output a byte to output buffer
  299.     CMP    CNT2,BUFSIZ
  300.     JNC    OUTBB
  301.     STOSB            ; store byte
  302.     INC    WORD PTR CNT2
  303.     CLC
  304.     RET
  305. OUTBCA:    POP    AX
  306.     JMP    ABORTWR        ; problems with write 
  307.  
  308. OUTBF:                ; flush output buffer to file
  309.     PUSH    AX
  310.     PUSH    BX
  311.     PUSH    CX
  312.     PUSH    DX
  313.     MOV    BX,WORD PTR FHAND2
  314.     MOV    AH,40H
  315.     MOV    DX,OFFSET FBUF2
  316.     MOV    CX,BUFSIZ
  317.     INT    21H
  318.     POP    DX
  319.     POP    CX
  320.     POP    BX
  321.     JC    OUTBC        ; write error
  322.     CMP    AX,BUFSIZ
  323.     JNZ    OUTBC        ; incomplete write, disk full
  324.     MOV    WORD PTR CNT2,0
  325.     MOV    DI,OFFSET FBUF2
  326. OUTBC:    POP    AX
  327.     RET
  328.  
  329. OUTLST:                ; flush last of buffer, then close file
  330.     MOV    BX,WORD PTR FHAND2
  331.     MOV    AH,40H
  332.     MOV    DX,OFFSET FBUF2
  333.     MOV    CX,CNT2
  334.     INT    21H
  335.     MOV    AH,3EH
  336.     INT    21H
  337.     RET
  338. ABORTHP:                ; abort with help screen
  339.     MOV    DX,OFFSET DHPERR
  340.     MOV    AH,9
  341.     INT    21H
  342.     MOV    AX,4C01H
  343.     INT    21H
  344. ABORTRD:
  345.     MOV    DX,OFFSET DRDERR    ; abort, file read error
  346.     MOV    AL,4
  347.     JMP    SHORT ABORT
  348. ABORTCH:                ; abort, file character error
  349.     CALL    OUTLST
  350.     MOV    DX,OFFSET DCHERR
  351.     MOV    AL,5
  352.     JMP    SHORT ABORT
  353. ABORTWR:                ; abort, file write error
  354.     MOV    DX,OFFSET DWRERR
  355.     MOV    AL,6
  356. ABORT:    CALL    ABERR            ; show start of error message
  357.     PUSH    AX
  358.     MOV    AH,9            ; show text of error message
  359.     INT    21H
  360.     MOV    DX,OFFSET DERRF        ; period ending
  361.     INT    21H
  362.     POP    AX            ; recover error index
  363.     MOV    AH,4CH
  364.     INT    21H
  365. ABERR:    PUSH    AX
  366.     PUSH    DX
  367.     MOV    DX,OFFSET DERROR
  368.     MOV    AH,9
  369.     INT    21H
  370.     POP    DX
  371.     POP    AX
  372.     RET
  373.     EVEN
  374. SHOW:    MOV    AH,2            ; show asciiz string
  375. SHOM:    LODSB
  376.     AND    AL,AL
  377.     JZ    SHOE
  378.     MOV    DL,AL
  379.     INT    21H
  380.     JMP    SHORT SHOM
  381. SHOE:    RET    
  382.  
  383. FBUF1    EQU    $
  384. FBUF2    EQU    $+BUFSIZ
  385.  
  386. CODE    ENDS
  387.  
  388.     END    START
  389. 
  390.