home *** CD-ROM | disk | FTP | other *** search
- name dump
- page 78,132
- title DUMP--Display File Contents
-
- ;DUMP--a utility to display the contents
- ;of a file in hex and ASCII format. MS-DOS 2.00
-
- ;Used in the form:
- ;A>dump path\filename.ext[>device]
- ;(item in square bracket is optional)
-
- ;version 1.0 March 25, 1984
- ;copyright (c) 1984 by Ray Duncan
- ;may be freely reproduced for noncommercial use
-
- cr equ 0dh ;ASCII carriage return
- lf equ 0ah ;ASCII linefeed
- blank equ 20h ;ASCII space
- adr equ 65535
- command equ 80h ;buffer for command tail
- blksize equ 512 ;size of inputfile
- output_handle equ 1 ;handle of standard output
- ;device(redirectable)
- error_handle equ 2 ;handle of standard error device (not
- ;redirectable)
-
-
- cseg segment para public 'CODE'
-
- assume cs:cseg,ds:data,es:data,ss:stack
-
- include dump.pub
-
- dump proc far ;entry point from DOS
- push ds ;save DS:0000 for final
- xor ax,ax ;return to MS-DOS
- push ax
- mov ax,data ;make our data segment
- mov es,ax ;addressable via ES
- mov ah,30h ;check version DOS
- int 21h
- cmp al,2
- jae dump1 ;proceed if DOS 2 or greater
- mov dx,offset msg3 ;DOS 1.x-print error msg
- mov ax,es ;we must use old DOS
- mov ds,ax ;string output function
- mov ah,9 ;since handles not
- int 21h ;avail this vers DOS
- ret
-
-
- dump1: call get_filename ;get path and filespec for input
- ;file from command line tail
- mov ax,es ;Set DS=ES for remainder
- mov ds,ax ;of program
- jnc dump2 ;jump got acceptable name
- mov dx,offset msg2 ;missing or illegal
- mov cx,msg2_length ;filespec
- jmp dump9 ;print error and exit
-
- dump2: call open_input ;now try to open input
- jnc dump3 ;file-jump opened ok
- mov dx,offset msg1 ;open input file failed
- mov cx,msg1_length
- jmp dump9 ;print error and exit
-
- dump3: call read_block ;initialize input buffer
- jnc dump4 ;jump, got a block
- mov dx,offset msg4 ;empty file,print error
- mov cx,msg4_length ;message and exit
- jmp dump9
-
- dump4: call get_char ;file successfully opened
- jc dump8 ;now convert and display it.
- inc input_addr ;read 1 char from input
- ;jump, if end of file
- ;update file position
- or bx,bx ;is this 1st char blk
- jnz dump5 ;no
- call print_heading ;yes
-
- dump5: and bx,0fh ;is this 1st byte of 16?
- jnz dump6 ;no,jump
- push ax ;save the byte
- mov di,offset output ;convert relative file addr
- mov ax,input_addr ;for output string
- call conv_word
- pop ax
-
- dump6: ;store ascii vers of
- ;char if it is alphanumeric
- mov di,offset outputb
- add di,bx ;calculate output string
- mov byte ptr [di],'.' ;addr if it is control
- cmp al,blank ;char,just print dot
- jb dump7 ;jump, not alphanumeric
- cmp al,7eh
- ja dump7 ;jump,not alphanumeric
- mov [di],al ;store ascii char
-
- dump7: ;now convert binary byte
- ;to hex ascii equivalent
- push bx ;save offset 0-15 this
- ;byte calculates its posn in
- ;output string
- mov di,offset outputa
- add di,bx ;base addr + offset*3
- add di,bx
- add di,bx
- call conv_byte ;conv data byte to hex
- pop bx ;restore byte offset
- cmp bx,0fh ;16 bytes converted yet
- jne dump4 ;no,get another byte
- mov dx,offset output
- mov cx,output_length
- call write_std ;yes,print line
- jmp dump4 ;get next char from
- ;input file
-
- dump8: call close_input ;end of file detected
- ret ;close input file
-
- dump9: call write_error ;come here to print msg
- ret ;on std error device
- ;and return cntrl to DOS
-
- dump endp
-
- get_filename proc near ;process name of input file
- ;return carry=0 if successful
- ;return carry=1 if unsuccessful
- ;if no filename DS:SI<-addr command line
- mov si,offset command
- ;ES:DI<-addr filespec buffer
- mov di,offset input_name
- cld
- lodsb ;any command line present?
- or al,al ;return error status if not
- jz get_filename4
-
- get_filename1: ;scan over leading blank
- lodsb ;to filename
- cmp al,cr ;if we hit return
- je get_filename4 ;yes,exit with code
- cmp al,20h ;is this a blank
- je get_filename1 ;if not keep moving
-
- get_filename2: ;found 1st char of name
- stosb ;move last char
- lodsb ;check next char, found
- cmp al,cr ;cr yet?
- je get_filename3 ;yes,exit with success
- cmp al,20h ;code. is this a blank?
- jne get_filename2 ;if not keep moving char
-
- get_filename3: clc ;exit with carry=0
- ret ;for success flag
-
-
- get_filename4: stc ;exit with carry=1
- ret ;for error flag
-
-
- get_filename endp
-
- open_input proc near ;open input file
- ;DS:DX=addr filename
- mov dx,offset input_name
- mov al,0 ;AL=0 for read only
- mov ah,3dh ;function 3dh = open
- int 21h ;handle returned in AX
- mov input_handle,ax ;save it for later
- ret ;CY is set if error
-
- open_input endp
-
- close_input proc near ;close input file
- mov bx,input_handle ;BX=handle
- mov ah,3eh
- int 21h
- ret
- close_input endp
-
- get_char proc near ;get one char from
- ;input buffer
- mov bx,input_ptr ;return AL=char BX=buffer
- cmp bx,blksize ;offset. CY=1 if eof
- jne get_char1 ;is ptr at end of buffer
- mov input_ptr,0
- call read_block ;new block read from disk
- jnc get_char ;got blk start routine
- ret ;over
-
- get_char1: ;get data byte to AL
- mov al,[input_buffer+bx]
- inc input_ptr ;bump input buffer ptr
- clc ;return CY flag=0 since
- ret ;not end of file
- get_char endp
-
- read_block proc near ;read block of data from
- mov bx,input_handle ;input file CY=0 if ok
- mov cx,blksize ;CY=1 if end of file
- mov dx,offset input_buffer ;request read
- mov ah,3fh ;from D
- int 21h
- inc input_block ;initialize pointers
- mov input_ptr,0
- or ax,ax ;was anything read in?
- ;or turns off CY flag
-
- jnz read_block1
-
- stc ;no, eof return CY=true
-
- read_block1:
- ret
-
- read_block endp
-
- write_std proc near ;write string to std
- ;output call DX=addr
- ;of out string CX=lgth
- mov bx,output_handle ;of string
- mov ah,40h ;function 40=write to file
- int 21h ;or device function call.
- ret
- write_std endp
-
- write_error proc near ;write str to std error
- ;device call DX=addr
- ;of output string
- ;CX=length of string
- mov bx,error_handle ;BX=handle for std error
- mov ah,40h ;device funct 40h=write
- int 21h ;to device
- ret
- write_error endp
-
- print_heading proc near
- push ax ;print record nr and
- push bx ;heading for block
- mov di,offset headinga ;of data 1st save reg
- mov ax,input_block
- call conv_word ;convert record nr to
- mov dx,offset heading ;ascii
- mov cx,heading_length
- call write_std ;now print heading
- pop bx
- pop ax ;restore registers
- ret ;and exit
- print_heading endp
-
- conv_word proc near ;conv 16 bit word to hex
- ;call with ax=binary val
- ;DI=addr to store string
- ;AX,DI,CX destroyed
- push ax
- mov al,ah
- call conv_byte ;convert upper byte
- pop ax
- call conv_byte ;convert lower byte
- ret
- conv_word endp
-
- conv_byte proc near ;convert binary byte
- ;to hex ascii
- ;call with al=binary
- ;DI=addr to store str
- sub ah,ah ;clear upper byte
- mov cl,16
- div cl ;div binary by 16
- call ascii ;remainder becomes
- stosb ;second ascii char
- mov al,ah
- call ascii
- stosb
- ret
- conv_byte endp
-
- ascii proc near ;conv last 4 bits inAL
- add al,'0'
- cmp al,'9'
- jle ascii2 ;jump if range 0-9
- add al,'A'-'9'-1 ;offset to range A-F
- ascii2: ret ;return ascii char AL
- ascii endp
-
- cseg ends
-
- data segment para public 'DATA'
-
- input_name db 64 dup (0) ;buffer for input file
-
- input_handle dw 0 ;token for dos input
-
- input_ptr dw 0 ;ptr to input deblocking
-
- input_addr dw adr ;relative addr in file
-
- input_block dw 0 ;current in block nr.
-
- output db 'nnnn',blank,blank
-
- outputa db 16 dup ('00',blank)
- db blank
-
- outputb db '0123456789ABCDEF',cr,lf
-
- output_length equ $-output
-
- heading db cr,lf,'RECORD',blank
-
- headinga db 'nnnn',blank,blank,cr,lf
- db 7 dup(blank)
- db '0 1 2 3 4 5 6 7 '
- db '8 9 A B C D E F',cr,lf
-
- heading_length equ $-heading
-
- input_buffer db blksize dup(?)
-
- msg1 db cr,lf
- db 'Cannot find input file'
- db cr,lf
-
- msg1_length equ $-msg1
-
- msg2 db cr,lf
- db 'Missing file name.'
- db cr,lf
-
- msg2_length equ $-msg2
-
- msg3 db cr,lf
- db 'Requires MS-DOS version 2 or greater'
- db cr,lf,'$'
-
- msg4 db cr,lf,'Empty File.',cr,lf
-
- msg4_length equ $-msg4
-
- data ends
-
- stack segment para stack 'STACK'
-
- db 64 dup(?)
-
- stack ends
-
- end dump