home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 5
/
ctrom5b.zip
/
ctrom5b
/
DOS
/
UTILITY
/
DIVERSEN
/
KWIKHELP
/
BIN2C.A86
< prev
next >
Wrap
Text File
|
1994-12-01
|
5KB
|
226 lines
;----------------------------------------------------------------
; BIN2C 21 August 1994
; jtucker@adam.com.au
; JIM TUCKER 3:800/805
; This reads a screen binary file (4000 bytes) then converts it to
; C for inclusion as data in your program. Screens can be saved
; using KWIKGRAB. This code is is for Eric Isaacson's A86V371
; assembler released April 1994. (This is a variation on BIN2TEXT).
;----------------------------------------------------------------
jmp bin2C
INCLUDE \ALIB\MACROS.INC ;my macros
INCLUDE \ALIB\CMDLINE.INC ;command line procedure
@PRINT ;print string procedure
@CRLF ;display crlf procedure
BIN2C: call cmdline
test W filename1
if z jmp help
mov si,filename1 w
mov di,filename2 w
mov ax,121Eh ;dupe filename?
int 2Fh ;undoc dos call
jnz >l1
call crlf
say@ "Same name! You can't do that!",bell
badexit
l1: mov dx,filename1 ;open
mov ax,3D00h
dosf
if c jmp not_found
mov bx,ax
mov ax,3F00h ;read it
mov cx,5000 ;try this many
mov dx,OFFSET file_buffer
dosf
if c jmp read_error
cmp ax,4000 ;should be this many
if ne jmp not_bin_file
mov ax,3E00h ;close it
dosf
jmp convert_file
;This converts the bin file to hex
COUNTER1 db 8 ;entries per line
COUNTER2 db 10 ;lines per block
CONVERT_FILE: mov si,OFFSET file_buffer
mov di,OFFSET write_buffer
mov cx,2000
call store_dw
L1: mov ax,'x0' ;"0x"
stosw
lodsw ;get word
call store_hex ;convert and store
dec counter1 ;one less
jz >l2 ;end of line?
mov ax,' ,' ;no, ", "
stosw
jmp >l4 ;get next
L2: dec counter2 ;end of 80 word block?
jnz >l3 ;no
mov ax,0A0Dh ;put in a blank line
stosw
mov counter2,10 ;reset the counter
L3: call store_dw ;start a line
mov counter1,8 ;reset the counter
L4: loop l1 ;do 2000 times
;Save bytes to write
mov cx,di
sub cx,OFFSET store_buffer
push cx
;Create, open, read, close
test word ptr filename2
if z jmp no_file2 ;wasted our time
mov dx,filename2 ;open
mov ax,3D00h
dosf
jc >l2 ;error, so not exist
mov bx,ax ;close it
mov ah,3Eh
dosf
call crlf
say 'Destination file exists. Overwrite (Y/N)? '
L1: mov ah,0
int 16h
or al,20h
cmp al,'y'
je >l2
cmp al,'n'
jne l1
call crlf
say@ 'Aborted at user request'
goodexit
L2: mov dx,filename2 ;make it or set zero
mov ax,3C00h
mov cx,0
dosf
if c jmp create_error
mov bx,ax ;write CX bytes
mov ax,4000h
mov dx,OFFSET store_buffer
pop cx ;bytes to write
sub cx,6 ;don't write last dw
dosf
if c jmp write_error
mov dx,OFFSET end_message ;write the end comment
mov cx,end_message_length
mov ax,4000h
dosf
if c jmp write_error
mov ax,3E00h ;close it
dosf
call crlf ;say all done
mov si,filename1
call display
say ' converted to C code in '
mov si,filename2
call display
call crlf
goodexit
;----------------------------------------------------------------
HELP: call crlf
HELP1: say@ 'BIN2C ■ Release 1994 JIM TUCKER'
say@ 'Copyright (c) 1994 JIM TUCKER. All rights reserved'
say@ 'Converts screen ".BIN" file to C data file'
say@ 'USAGE: BIN2C SOURCEfile TARGETfile'
goodexit
NOT_FOUND: call crlf
say@ 'Source file not found',bell
badexit
LENGTH_ERROR: call crlf
say@ 'DOS length error',bell
badexit
NOT_BIN_FILE: call crlf
mov si,FILENAME1
call display
say@ ' is not a screen binary file',bell
badexit
READ_ERROR: call crlf
say@ 'DOS error reading source file',bell
badexit
NO_FILE2: call crlf
say@ 'No DESTINATION file specified',bell
jmp help1
CREATE_ERROR: call crlf
say@ 'Bad destination filename',bell
badexit
WRITE_ERROR: call crlf
say@ 'DOS error writing destination file',bell
badexit
DISPLAY: mov ah,2 ;display ASCIIZ string
L1: lodsb
or al,al
jz ret
mov dl,al
int 21h
jmp l1
STORE_DW: mov ax,0A0Dh ;crlf
stosw
mov ax,2020h ;two spaces
stosw
ret
;This puts the hex number in AX into the output buffer
;Enter with AX=hex number ES:DI position in buffer
@SIXTEEN dw 16
STORE_HEX: push ax,cx,dx
xor cx,cx
L101: inc cx
xor dx,dx ;clear remainder
div @sixteen ;div AX by 16
push dx ;save remainder
or ax,ax
jnz l101
L102: pop ax ;loop and save 'em
add al,'0'
cmp al,'9'
jbe >l103
add al,7
L103: stosb
loop l102
pop dx,cx,ax
ret
END_MESSAGE db '};',cr,lf
db '/** END OF DATA **/',cr,lf
END_MESSAGE_LENGTH equ $-OFFSET end_message
FILE_BUFFER dw 2000 dup 0 ;read file
STORE_BUFFER db 'int screen_data[] = {'
WRITE_BUFFER label byte ;asm data