home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / DOS / UTILITY / DIVERSEN / KWIKHELP / BIN2PAS.A86 < prev    next >
Text File  |  1994-12-01  |  5KB  |  226 lines

  1. ;----------------------------------------------------------------
  2. ; BIN2PAS 21 August 1994
  3. ; jtucker@adam.com.au
  4. ; JIM TUCKER 3:800/805
  5.  
  6. ; This reads a screen binary file (4000 bytes) then converts it to
  7. ; PASCAL for inclusion as data in your program. Screens can be saved
  8. ; using KWIKGRAB. This code is is for Eric Isaacson's A86V371
  9. ; assembler released April 1994. (This is a variation on BIN2TEXT).
  10. ;----------------------------------------------------------------
  11.  
  12.         jmp    bin2pas
  13.  
  14. INCLUDE \ALIB\MACROS.INC        ;my macros
  15. INCLUDE \ALIB\CMDLINE.INC        ;command line procedure
  16. @PRINT                    ;print string procedure
  17. @CRLF                    ;display crlf procedure
  18.  
  19. BIN2PAS:    call    cmdline
  20.         test    W filename1
  21.         if z    jmp help
  22.  
  23.         mov    si,filename1 w
  24.          mov    di,filename2 w
  25.         mov    ax,121Eh        ;dupe filename?
  26.         int    2Fh            ;undoc dos call
  27.         jnz    >l1
  28.         call    crlf
  29.         say@    "Same name! You can't do that!",bell
  30.         badexit
  31.  
  32. l1:        mov    dx,filename1        ;open
  33.         mov    ax,3D00h
  34.         dosf
  35.         if c    jmp not_found
  36.  
  37.         mov    bx,ax
  38.         mov    ax,3F00h        ;read it
  39.         mov    cx,5000            ;try this many
  40.         mov    dx,OFFSET file_buffer
  41.         dosf
  42.         if c    jmp read_error
  43.  
  44.         cmp    ax,4000            ;should be this many
  45.         if ne    jmp not_bin_file
  46.  
  47.         mov    ax,3E00h        ;close it
  48.         dosf
  49.         jmp    convert_file
  50.  
  51. ;This converts the bin file to decimal bytes
  52.  
  53. COUNTER1    db 10            ;entries per line
  54. COUNTER2    db 8            ;lines per block
  55.  
  56. CONVERT_FILE:    mov    si,OFFSET file_buffer
  57.         mov    di,OFFSET write_buffer
  58.  
  59.         mov    cx,2000
  60.         call    store_dw
  61. L1:        lodsb            ;get byte
  62.         xor    ah,ah
  63.         call    store_dec    ;store it
  64.         mov    al,','        ;al=","
  65.         stosb
  66.         xor    ah,ah
  67.         lodsb
  68.         call    store_dec
  69.  
  70.         dec    counter1    ;one less
  71.         jz    >l2        ;end of line?
  72.         mov    al,','        ;no, just a comma
  73.         stosb
  74.         jmp    >l4        ;get next
  75. L2:        dec    counter2    ;end of 80 word block?
  76.         jnz    >l3        ;no
  77.         mov    ax,0A0Dh    ;put in a blank line
  78.         stosw
  79.         mov    counter2,8    ;reset the counter
  80. L3:        call    store_dw    ;start a line with DW
  81.         mov    counter1,10    ;reset the counter
  82. L4:        loop    l1        ;do 2000 times
  83.  
  84. ;Save bytes to write
  85.  
  86.         mov    cx,di
  87.         sub    cx,OFFSET store_buffer
  88.         push    cx
  89.  
  90.         test    word ptr filename2
  91.         if z    jmp no_file2        ;wasted our time
  92.  
  93.         mov    dx,filename2        ;open
  94.         mov    ax,3D00h
  95.         dosf
  96.         jc    >l2            ;error, so not exist        
  97.  
  98.         mov    bx,ax            ;close it
  99.         mov    ah,3Eh
  100.         dosf
  101.         call    crlf
  102.         say    'Destination file exists. Overwrite (Y/N)? '
  103. L1:        mov    ah,0
  104.         int    16h
  105.         or    al,20h
  106.         cmp    al,'y'
  107.         je    >l2
  108.         cmp    al,'n'
  109.         jne    l1
  110.         call    crlf
  111.         say@    'Aborted at user request'
  112.         goodexit
  113.  
  114. L2:        mov    dx,filename2        ;make it or set zero
  115.         mov    ax,3C00h
  116.         mov    cx,0
  117.         dosf
  118.         if c    jmp create_error
  119.  
  120.         mov    bx,ax            ;write CX bytes
  121.         mov    ax,4000h
  122.         mov    dx,OFFSET store_buffer
  123.         pop    cx            ;bytes to write
  124.         sub    cx,6            ;don't write last dw
  125.         dosf
  126.         if c    jmp write_error
  127.  
  128.         mov    dx,OFFSET end_message    ;write the end comment
  129.         mov    cx,end_message_length
  130.         mov    ax,4000h
  131.         dosf
  132.         if c    jmp write_error
  133.  
  134.         mov    ax,3E00h        ;close it
  135.         dosf
  136.  
  137.         call    crlf            ;say all done
  138.         mov    si,filename1
  139.         call    display
  140.         say    ' converted to PAS code in '
  141.         mov    si,filename2
  142.         call    display
  143.         call    crlf
  144.         goodexit
  145.  
  146. ;----------------------------------------------------------------
  147.  
  148. HELP:        call    crlf
  149. HELP1:        say@    'BIN2PAS ■ Release 1994 JIM TUCKER'
  150.         say@    'Copyright (c) 1994 JIM TUCKER. All rights reserved'
  151.         say@    'Converts screen ".BIN" file to PASCAL data file'
  152.         say@    'USAGE: BIN2PAS SOURCEfile TARGETfile'
  153.         goodexit
  154.  
  155. NOT_FOUND:    call    crlf
  156.         say@    'Source file not found',bell
  157.         badexit
  158.  
  159. LENGTH_ERROR:    call    crlf
  160.         say@    'DOS length error',bell
  161.         badexit
  162.  
  163. NOT_BIN_FILE:    call    crlf
  164.         mov    si,FILENAME1
  165.         call    display
  166.         say@    ' is not a screen binary file',bell
  167.         badexit
  168.  
  169. READ_ERROR:    call    crlf
  170.         say@    'DOS error reading source file',bell
  171.         badexit
  172.  
  173. NO_FILE2:    call    crlf
  174.         say@    'No DESTINATION file specified',bell
  175.         jmp    help1
  176.  
  177. CREATE_ERROR:    call    crlf
  178.         say@    'Bad destination filename',bell
  179.         badexit
  180.  
  181. WRITE_ERROR:    call    crlf
  182.         say@    'DOS error writing destination file',bell
  183.         badexit
  184.  
  185. DISPLAY:    mov    ah,2        ;display ASCIIZ string
  186. L1:        lodsb
  187.         or    al,al
  188.         jz    ret
  189.         mov    dl,al
  190.         int    21h
  191.         jmp    l1
  192.  
  193. STORE_DW:    mov    ax,0A0Dh    ;crlf
  194.         stosw
  195.         mov    ax,2020h    ;two spaces
  196.         stosw
  197.         ret
  198.  
  199.         @ten    dw 10
  200. STORE_DEC:    push    ax,cx,dx
  201.         xor    cx,cx
  202. L101:        inc    cx        ; count the loops
  203.         xor    dx,dx        ; clear remainder
  204.         div    @ten        ; div AX by 10
  205.         push    dx        ; save remainder
  206.         or    ax,ax        ; any quotient?
  207.         jnz    l101        ; yes
  208.  
  209. L102:        pop    ax        ; loop and print em
  210.         add    al,'0'        ; make it ascii
  211.         stosb
  212.         loop    l102
  213.         pop    dx,cx,ax
  214.         ret
  215.  
  216. END_MESSAGE    db ');',cr,lf,'{ END OF DATA }',cr,lf
  217. END_MESSAGE_LENGTH equ $-OFFSET end_message
  218.  
  219. FILE_BUFFER    dw 2000 dup 0        ;read file
  220. STORE_BUFFER    db 'CONST',cr,lf
  221.         db '  ScnRows=25;',cr,lf
  222.         db '  ScnCols=80;',cr,lf,cr,lf
  223.         db '  SCREEN_DATA : ARRAY [1..4000] OF byte = ('
  224. WRITE_BUFFER    label byte        ;asm 
  225.  
  226.