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

  1. ;----------------------------------------------------------------
  2. ; BIN2ASM 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. ; ASM 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. ; Note: A ".BIN" file converted to data can be reversed engineered
  12. ; simply using A86. Thus:
  13. ;    BIN2ASM FILE.BIN FOOBAR.DAT
  14. ;    A86 FOOBAR.DAT FOOBAR.BIN
  15. ;----------------------------------------------------------------
  16.  
  17.         jmp    bin2asm
  18.  
  19. INCLUDE \ALIB\MACROS.INC        ;my macros
  20. INCLUDE \ALIB\CMDLINE.INC        ;command line procedure
  21. @PRINT                    ;print string procedure
  22. @CRLF                    ;display crlf procedure
  23.  
  24. BIN2ASM:    call    cmdline
  25.         test    W filename1
  26.         if z    jmp help
  27.  
  28.         mov    si,filename1 w
  29.          mov    di,filename2 w
  30.         mov    ax,121Eh        ;dupe filename?
  31.         int    2Fh            ;undoc dos call
  32.         jnz    >l1
  33.         call    crlf
  34.         say@    "Same name! You can't do that!",bell
  35.         badexit
  36.  
  37. l1:        mov    dx,filename1        ;open
  38.         mov    ax,3D00h
  39.         dosf
  40.         if c    jmp not_found
  41.  
  42.         mov    bx,ax
  43.         mov    ax,3F00h        ;read it
  44.         mov    cx,5000            ;try this many
  45.         mov    dx,OFFSET file_buffer
  46.         dosf
  47.         if c    jmp read_error
  48.  
  49.         cmp    ax,4000            ;should be this many
  50.         if ne    jmp not_bin_file
  51.  
  52.         mov    ax,3E00h        ;close it
  53.         dosf
  54.         jmp    convert_file
  55.  
  56. ;This converts the bin file to hex
  57.  
  58. COUNTER1    db 10            ;entries per line
  59. COUNTER2    db 8            ;lines per block
  60.  
  61. CONVERT_FILE:    mov    si,OFFSET file_buffer
  62.         mov    di,OFFSET write_buffer
  63.  
  64.         mov    cx,2000
  65.         call    store_dw
  66. L1:        lodsw            ;get word
  67.         call    store_hex    ;convert and store
  68.         dec    counter1    ;one less
  69.         jz    >l2        ;end of line?
  70.         mov    al,','        ;no, just a comma
  71.         stosb
  72.         jmp    >l4        ;get next
  73. L2:        dec    counter2    ;end of 80 word block?
  74.         jnz    >l3        ;no
  75.         mov    ax,0A0Dh    ;put in a blank line
  76.         stosw
  77.         mov    counter2,8    ;reset the counter
  78. L3:        call    store_dw    ;start a line with DW
  79.         mov    counter1,10    ;reset the counter
  80. L4:        loop    l1        ;do 2000 times
  81.  
  82. ;Save bytes to write
  83.  
  84.         mov    cx,di
  85.         sub    cx,OFFSET store_buffer
  86.         push    cx
  87.  
  88. ;Create, open, read, close
  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,4            ;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 ASM code in '
  141.         mov    si,filename2
  142.         call    display
  143.         call    crlf
  144.         goodexit
  145.  
  146. ;----------------------------------------------------------------
  147.  
  148. HELP:        call    crlf
  149. HELP1:        say@    'BIN2ASM ■ Release 1994 JIM TUCKER'
  150.         say@    'Copyright (c) 1994 JIM TUCKER. All rights reserved'
  151.         say@    'Converts screen ".BIN" file to ASM data file'
  152.         say@    'USAGE: BIN2ASM 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,'WD'        ;"DW"
  196.         stosw
  197.         mov    ax,2020h    ;two spaces
  198.         stosw
  199.         ret
  200.  
  201. ;This puts the hex number in AX into the output buffer
  202. ;Enter with AX=hex number ES:DI position in buffer
  203.  
  204. @SIXTEEN    dw    16
  205. STORE_HEX:    push    ax,cx,dx
  206.         cmp    ax,0A000h    ;add leading zero
  207.         jb    >l100        ;if needed
  208.         push    ax
  209.         mov    al,'0'
  210.         stosb
  211.         pop    ax
  212.  
  213. L100:        mov    cx,4
  214. L101:        xor    dx,dx        ;clear remainder
  215.         div    @sixteen    ;div AX by 16
  216.         push    dx        ;save remainder
  217.         loop    l101
  218.  
  219.         mov    cx,4
  220. L102:        pop    ax        ;loop and save 'em
  221.         add    al,'0'
  222.         cmp    al,'9'
  223.         jbe    >l103
  224.         add    al,7
  225. L103:        stosb
  226.         loop    l102
  227.         mov    al,'h'
  228.         stosb
  229.         pop    dx,cx,ax
  230.         ret
  231.  
  232. END_MESSAGE    db 'DATA_LENGTH EQU $-OFFSET SCREEN_DATA ; Will be 4000',cr,lf
  233. END_MESSAGE_LENGTH equ $-OFFSET end_message
  234.  
  235. FILE_BUFFER    dw 2000 dup 0        ;read file
  236. STORE_BUFFER    db 'SCREEN_DATA LABEL BYTE',cr,lf
  237. WRITE_BUFFER    label byte        ;asm data
  238.