;----------------------------------------------------------------------------]
; The ASM source code for BinEdit program.
; be.asm
;---------------------------------------------------------------------------]
; (c) Copyright YuHuan
; (r) All rights reserved
;
; Date: 1996,6
; Release: Version 1.07
; e-mail : yu.huan@263.net
;---------------------------------------------------------------------------]
; Notes:
; (1) : Add to show the Ascii Chart for 'A' command
; data: 1997/04/01,YuHuan
; (2) : Add to Encrypt the buffer,for '~'=Not,'&'=And,'|'=Or
; '+'=Add,'-'=Sub,'^'=Xor,'<'=Shift left,'>'=Shift right.
; data: 1997/04/03,YuHuan
; (3) : Add to Encrypt the all code for undebug,when 'be'
; is running,unEncrypted by itself.
; So,when I compile the program,I must use the 'be'
; to Encrypt the code,from 'filename' to 'EndFlag'
; else,the program will halt.
; data: 1997/04/11, YuHuan
; (4) : Find a error when read a file from the CD-ROM,(show 'the file '
; is not exist',and exit),I correct it in procedure "TestisBinOr
; Not'.
; data: 1997/05/06, YuHuan
; (5) : Find a bug when press Enter to save the file to 'yh.lxf'
; When creat file error,the program can not show any message.
; data: 1997/05/06, YuHuan
; (6) : I change the display color in area 'XXXX:XXXX'
; data: 1997/05/06, YuHuan
;===========================================================================]
EncryptFlag equ 0
; YuHuan,1997/04/11
;--------------------------------------------------------------------------]
PUSHALL MACRO
PUSH AX
PUSH BX
PUSH CX
PUSH DX
PUSH DS
PUSH ES
PUSH SI
PUSH DI
PUSH BP
ENDM
POPALL MACRO
POP BP
POP DI
POP SI
POP ES
POP DS
POP DX
POP CX
POP BX
POP AX
ENDM
;---------------------------------------------------------------
.model small
.code
org 100h
;----------------------------------------------------------------------
up equ 4800h
down equ 5000h
left equ 4b00h
right equ 4d00h
pgdn equ 5100h
pgup equ 4900h
escape equ 011bh
F3 equ 3d00h
F1 equ 3b00h
F6 equ 4000h
F2 equ 3C00h
F4 equ 3E00h
F5 equ 3F00h
F7 equ 4100h
F8 equ 4200h
F9 equ 4300h
F10 equ 4400h
Home equ 4700h
Ender equ 4f00h
EnterChar equ 1C0Dh
Tab equ 0F09h
Insert equ 5200h
NextIns equ 4E2Bh
Del equ 5300h
Subchar equ 4A2Dh
;Define the key Value
maxreadfile equ 0fe00h
;Define the Max Read file length
MessageBoxColor equ 3eh
;Define the Message Color
;-------------------------------------------------------------------------
Pager STRUC
upl dw 0
uph dw 0
downl dw 0
downh dw 0
zone dw 0
pager ENDS
;Define the Current disp page structure
;----------------------------------------------------------------------
start:
jmp begin
;------------------------------------------------------------------------
filename db 'Please input FileName:',24h
file db 65
db ?
db 66 dup(0)
;The File name buffer
handle dw 0
buffer db 20 dup(?)
Herc dw 0
;The flag of Monitor type
scrseg dw 0
;The Video Segment Addr
FileLenh dw 0
FileLenl dw 0
;The file length buffer
Filestartaddr dw 0F000h
bufferstartaddr dw 4100 ;500 bytes
writebufferstart dw 4600 ;56K bytes
;Define the every buffer length
pagerr pager {}
IsInScrBuffer db 0
;The flag to process either write
;the char to memory buffer then movs
;to the video buffer (isinscrbuffer=1)
;or direct write
;to the video buffer(isinscrbuffer=0)
SaveInMess db 1
;the flag to process is Save buffer
;in message or not
;-------------------------------------------------------------------------
; The Procedure to Hide the cursor
; Entrance: None
; OutParam: None
;------------------------------------------------------------------------
HideCursor proc
mov ah,1
mov cx,2000h
int 10h
ret
HideCursor endp
;-------------------------------------------------------------
; The Procedure Show the standard cursor
; Entrance: None
; OutParam: None
;-------------------------------------------------------------
ShowCursor proc
mov ah,1
mov cx,0607h
int 10h
ret
ShowCursor endp
;--------------------------------------------------------------
; The Procedure Show the Edit's Big cursor
; Entrance: None
; OutParam: None
;-----------------------------------------------------------
ShowBigCursor proc
mov ah,1
mov cx,0007h
int 10h
ret
ShowBigCursor endp
;----------------------------------------------------------------
; The Procedure Show the Hex Value in Ascii Mode
; Entrance: al-char
; bh-Attr.
; cl-x
; ch-y
; cs:tofilef=1.....write to file
; =0.....write to video (Byte)
; OutParam: None
;--------------------------------------------------------------
CharTable db '0123456789ABCDEF',0
CharStore db 3 dup (20h)
CharPos db 0
ToFileF db 0
;--------------------------------------------------------------
DispChar proc
push ax
push bx
push cx
push dx
push bp
push ds
push si
push di
push cs
pop ds
mov byte ptr cs:CharPos,0
;clear the position
mov dh,al
mov bp,2
push cx
and al,0f0h
mov cl,4
shr al,cl
pop cx
and al,0fh
@DDA:
push bx
lea bx,CharTable
xlat
;Change Hex value to Ascii mode
mov dl,al
pop bx
cmp byte ptr cs:tofileF,1
jnz to_video
push cx
push si
lea si,CharStore
mov cl,byte ptr cs:charPos
xor ch,ch
add si,cx
mov byte ptr cs:si,al
pop si
pop cx
inc byte ptr cs:charPos
;adjust the postion
jmp to_allvf
to_video:
call Write_char
;Write to Video buffer
to_allvf:
inc ch
cmp ch,80
jbe ddk
inc cl
xor ch,ch
ddk:
mov al,dh
and al,0fh
dec bp
jnz @DDA
pop di
pop si
pop ds
pop bp
pop dx
pop cx
pop bx
pop ax
ret
DispChar endp
;-------------------------------------------------------
; The Procedure Show The Ax (Hex) to Ascii Mode
; Entrance: cl-x
; ch-y
; bh-Attr
; ax-Word
; OutParam: None
;------------------------------------------------------
DispWord proc
xchg ah,al
call DispChar
inc ch
inc ch
xchg ah,al
call DispChar
ret
DispWord endp
;/*-------------------------------------------------------*/
; The Procedure Test the file is Bin or Test mode
;/* Entrance: Ds:Dx:FileName /
;/* OutParam: Ax=1...Is Bin File /
;/* Ax=2...Is not Bin File /
;/* Bx=Handle /
;/*-------------------------------------------------------*/
IsBin dw 0
fileAttr dw 0
;-----------------------------------------------------------
TestIsBinOrNot proc
push cs
pop ds
mov ax,4300h
int 21h
jc exit_open
mov cs:fileAttr,cx
cmp cx,20h
jz not_chgattr
;if is not hidden/system,do not change attr
mov ax,4301h
xor cx,cx
int 21h
; jc exit_open
;Get& Set the file attribute
not_chgAttr:
clc
mov ax,3d02h
int 21h
jnc ok_op
; jc exit_open
;Open file
mov ax,3d00h
int 21h
ok_op:
mov bx,ax
mov cs:handle,ax
mov ah,3fh
lea dx,buffer
mov cx,16
int 21h
jc exit_open
;Read file with 16 bytes
mov si,dx
cld
mov cx,ax
or cx,cx
jnz testbin
stc
ret
;error,not byte has read
testbin:
lodsb
cmp al,08h
jbe @7
cmp al,7fh
ja @7
loop testbin
jmp @8
@7:
clc
mov al,1
mov cs:isbin,1
ret
@8:
mov al,2
mov cs:isbin,0
clc
exit_open:
ret
TestIsBinOrNot endp
;/*-------------------------------------------------------*/
; The Procedure Load the file,if file > Maxmem ;Error exit
; if file < 64kb,load the file,form the offset
; if file > 64kb,Select the file block and form the offset
;/* Entrance: Bx=Handle */
;/* OutParam: Dx:Ax....The File Length */
;/*-------------------------------------------------------*/
maxoff dw 0
FileTooLong db 'Error: The file is too big to fit in Memory',0
fileloadsmall db 'Sorry: File Too long,Loading 0001 st 64KB ...',0
selectmess db ' ',18h,' ',19h,' ',1ah,' ',1bh,' pgdn,pgup--Select'
db ' Enter--Go '
db ' |(C)Copyright YuHuan',0
;------------------------------------------------------------
GetFileLength proc
mov byte ptr cs:over64k,0
;clear the flag
mov bx,cs:handle
mov ax,4200h
xor cx,cx
xor dx,dx
int 21h
jnc abcde
jmp exit_getlen
abcde:
mov ax,4202h
xor cx,cx
xor dx,dx
int 21h
jc exit_getlen
mov cs:filelenh,dx
mov cs:filelenl,ax
;Get file length
push ax
mov cl,12
shl dx,cl
mov cl,4
shr ax,cl
add dx,ax
pop ax
cmp word ptr cs:maxmem,0fffh
ja ok_file
;test left memory is enough or not
mov cs:stop,1
lea si,filetoolong
call messagebox
stc
;the program can edit file >64kb
jmp exit_getlen
ok_file:
mov dx,word ptr cs:filelenh
or dx,dx
jz ok_file1
mov byte ptr cs:over64k,1
push bx
lea si,selectmess
mov cl,24
mov ch,0
mov bh,0fh
call write_str
;show select help message
mov cs:stop,0
lea si,fileloadsmall
mov bx,offset selRange
call messagebox
mov word ptr cs:filelenh,0
pop bx
ok_file1:
mov ax,word ptr cs:filelenl
push ax
and ax,0fh
mov word ptr cs:nextchar,ax
pop ax
;get the last char
dec ax
mov cl,4
shr ax,cl
mov cl,4
shl ax,cl
mov cs:maxoff,ax
;Form the file last offset(=filelen/16)
clc
exit_getlen:
ret
GetFileLength endp
;--------------------------------------------------------
seekh dw 0
seekl dw 0
block dw 0
Totalblock dw 0
;------------------------------------------------------
; The Procedure to Select the file's block to edit
;-------------------------------------------------------
SelRange proc
mov dx,word ptr cs:filelenh
mov ax,word ptr cs:filelenl
mov cx,maxreadfile
div cx
or dx,dx
jz sel_0
inc ax
mov cs:totalblock,ax
sel_0:
;Get the max block of file
mov bp,ax
mov si,1
sel_loop:
mov cl,11
mov ch,42
mov bh,2fh
mov ax,si
call dispword
;disp the number
xor ah,ah
int 16h
;select the block
cmp ax,up
jnz sel_1
@@up:
cmp si,1
jz sel_2
dec si
jmp sel_loop
sel_2:
mov si,bp
jmp sel_loop
sel_1:
cmp ax,down
jnz sel_3
@@down:
cmp si,bp
jae sel_4
inc si
jmp sel_loop
sel_4:
mov si,1
jmp sel_loop
sel_3:
cmp ax,Enterchar
jnz sel_5
jmp sel_@1
sel_5:
cmp ax,left
jnz sel_6
jmp @@up
sel_6:
cmp ax,right
jnz sel_7
jmp @@down
sel_7:
cmp ax,pgup
jnz sel_8
cmp si,10h
jb not_s
sub si,10h
jmp sel_loop
not_s:
mov si,1
jmp sel_loop
sel_8:
cmp ax,pgdn
jnz sel_9
mov ax,bp
cmp ax,10h
jb is_la
sub ax,10h
cmp si,ax
ja is_la
add si,10h
jmp sel_loop
is_la:
mov si,bp
sel_9:
jmp sel_loop
;--------------------------------------key process
sel_@1:
mov cs:block,si
dec si
mov cx,si
mov cs:seekh,0
mov cs:seekl,0
or cx,cx
jz not_selseek
sel_seek:
add cs:seekl,maxreadfile
adc cs:seekh,0
loop sel_seek
;form the file's start offset to read
not_selseek:
mov dx,cs:filelenl
mov cx,cs:filelenh
mov ax,cs:seekl
mov cs:filelenl,maxreadfile
sub dx,ax
sbb cx,cs:seekh
or cx,cx
jnz exit_sel
mov cs:filelenl,dx
;get the read file's length
exit_sel:
ret
SelRange endp
;----------------------------------------------------------
NextSeekl dw 0
NextSeekh dw 0
;----------------------------------------------------------
; The Procedure Read the file's block
; Entrance: Bx-Handle
; OutParam: clc-ok
; stc-error
;----------------------------------------------------------
ReadFile proc
pushall
mov bx,cs:handle
mov ax,4200h
mov cx,cs:seekh
mov dx,cs:seekl
int 21h
;seek the file
mov ax,cs:scrseg
mov dx,cs:filestartaddr
shr dx,4
add ax,dx
mov ds,ax
;form the file buffer segment
mov dx,0
mov cx,cs:filelenl
@r64:
mov ah,3fh
int 21h
jc read_64k
cmp ax,0
jnz read_ok
stc
jmp read_64k
read_ok:
mov cs:filelenl,ax
push ax
mov ax,cs:seekl
mov cs:nextseekl,ax
mov ax,cs:seekh
mov cs:nextseekh,ax
pop ax
add cs:nextseekl,ax
adc cs:nextseekh,0
;if file >64k ,form the next file offset
;for save the file(in edit zone)
clc
read_64k:
popall
ret
ReadFile endp
;----------------------------------------------------------
; The Prodedure Test file is end or not
; Entrance: None
; OutParam: clc-ok
; stc-file ends
;----------------------------------------------------------
TestFileEnd proc
push ax
push bx
push cx
mov ax,word ptr cs:fileLenl
mov bx,word ptr cs:pagerr.downl
cmp ax,bx
jb small_ex
pop cx
pop bx
pop ax
clc
ret
small_ex:
pop cx
pop bx
pop ax
stc
ret
TestFileEnd endp
;-----------------------------------------------------------
; The Procedure Process the Pgdn key
; Entrance: None
; OutParam: None
;-----------------------------------------------------------
do_pgdn proc
call TestfileEnd
jc exit_dnend
;Test file is end or not
mov ax,word ptr cs:pagerr.downl
add ax,22*16
;Form the new offset to display
cmp ax,word ptr cs:maxoff
jbe nexdn
Do_End:
call TestfileEnd
jc exit_dnend
mov ax,word ptr cs:maxoff
add ax,10h
sub ax,22*16
mov word ptr cs:pagerr.upl,ax
mov word ptr cs:pagerr.downl,ax
jmp nexdn1
;If file is end,to disp the last page
nexdn:
add word ptr cs:pagerr.upl,16*22
adc word ptr cs:pagerr.uph,0
nexdn1:
; push ax
mov bh,byte ptr cs:dispcolor
; call Clr_win
;Clear the disp windows
; pop ax
mov ax,word ptr cs:pagerr.upl
mov word ptr cs:dispaddrl,ax
mov cl,2
; mov bp,22
; loop_dn:
mov ch,10
; call displine
; jc exit_dnend
; inc cl
; add word ptr cs:pagerr.downl,16
; adc word ptr cs:pagerr.downh,0
; dec bp
; jnz loop_dn
;disp the current page (== 22 lines)
call disppage
exit_dnend:
ret
do_pgdn endp
;-----------------------------------------------------------
; The Procedure the Pgup key
; Entrance: None
; OutParam: None
;-----------------------------------------------------------
do_pgup proc
mov ax,word ptr cs:pagerr.upl
cmp ax,22*16
jb Do_home
sub ax,22*16
cmp ax,0
ja up_n
Do_Home:
;Test is file start or not
mov ax,0
up_n:
; push ax
; mov bh,byte ptr cs:dispcolor
; call Clr_win
;clear the windows
; pop ax
mov word ptr cs:pagerr.upl,ax
mov word ptr cs:pagerr.downl,ax
mov word ptr cs:dispaddrl,ax
; mov bp,22
mov cl,2
; mov bp,22
; loop_up:
mov ch,10
; call displine
; jc exit_upend
; inc cl
; add word ptr cs:pagerr.downl,16
; adc word ptr cs:pagerr.downh,0
; dec bp
; jnz loop_up
;disp the current page
call disppage
exit_upend:
ret
do_pgup endp
;-----------------------------------------------------------
; The Procedure process the down key
; Entrance: cl-x
; ch-y
; OutParam: None
;----------------------------------------------------------
ScroolLine proc
call TestfileEnd
jc exit_lined
mov ax,word ptr cs:filelenl
mov cx,word ptr cs:pagerr.downl
cmp ax,cx
jbe exit_lined
mov ax,word ptr cs:pagerr.upl
add ax,16*22
jc exit_lined
mov word ptr cs:dispaddrl,ax
mov word ptr cs:pagerr.downl,ax
mov ah,6
mov al,1
mov bh,07h
mov cx,0200h
mov dh,23
mov dl,78
int 10h
;Scrool a line
; call clr_win
mov cl,23
mov ch,10
call displine
jc exit_lined
;disp the line
add word ptr cs:pagerr.upl,16
adc word ptr cs:pagerr.uph,0
add word ptr cs:pagerr.downl,16
adc word ptr cs:pagerr.downh,0
;form the new offset
exit_lined:
ret
ScroolLine endp
;---------------------------------------------------------
scrup dw 0
scrdn dw 0
;-----------------------------------------------------------
; The procedure process the up key
; Entrance: cl-x
; ch-y
; OutParam: None
;----------------------------------------------------------
Scroolup proc
cmp word ptr cs:pagerr.upl,0
jnz doup
cmp word ptr cs:pagerr.uph,0
jnz doup
jmp noneup
doup:
mov word ptr cs:upp,1
mov ah,7
mov al,1
mov bh,07h
mov cx,0200h
mov dh,23
mov dl,79
int 10h
;scrooll 1 line
sub word ptr cs:pagerr.upl,16
sbb word ptr cs:pagerr.uph,0
mov ax,word ptr cs:pagerr.upl
mov word ptr cs:dispaddrl,ax
; add ax,160h
mov word ptr cs:pagerr.downl,ax
;form the new offset
mov cl,2
mov ch,10
call displine
;disp the line
mov word ptr cs:upp,0
;clear the flag
noneup:
ret
Scroolup endp
;------------------------------------------------------------
; The procedure disp the line to screen at position
; Entrance: cl-x
; ch-y
; OutParam: clc-ok
; stc-file ends
;------------------------------------------------------------
DispAddrh dw 0
DispAddrl dw 0 ;the address of file buffer
Line db 18 dup(0) ;the lines chars buffer
halff dw 0 ;the flag of half lines
chard db 0
charnum dw 0 ;the char number
upp dw 0
nextchar dw 0
CurrentSeg dw 0
;the two parameters point to the
;current memory's Seg:Off
dispcolor db 17h ;first=1ah
datewinspace db 70 dup (20h),0
;-----------------------------------------------------------------
DispLine proc
pushall
mov di,cs:fileLenl
mov si,cs:pagerr.downl
cmp di,si
jae nexon
stc
jmp line_e@
nexon:
sub di,si
mov cs:charnum,16
cmp di,16
jae dispnow
mov di,word ptr cs:nextchar
mov cs:charnum,di
cmp di,0
jnz dispnow
stc
jmp line_e@
dispnow:
cmp word ptr cs:upp,1
jnz notup
mov word ptr cs:charnum,16
notup:
push cx
mov si,word ptr cs:dispaddrl
mov di,offset line
mov cx,cs:charnum
cld
mov byte ptr cs:chard,62
;chard=start ascii zone address
mov ax,cs:filestartaddr
shr ax,4
; mov ds,ax
push cx
mov cx,cs:scrseg
add ax,cx
pop cx
mov ds,ax
;Form the file Buffer Segment
mov ax,cs
mov es,ax
;Form the destination Segment
rep movsb
;Get the 16 bytes chars to display
pop cx
push cx
mov bh,30h
;bh-Attri
mov ch,0
;ch=col
mov ax,cs:dispaddrh
add ax,word ptr cs:scrseg
push bx
push cx
mov bx,word ptr cs:filestartaddr
mov cl,4
shr bx,cl
add ax,bx
pop cx
pop bx
mov word ptr cs:currentseg,ax
;ax=the file to the memory's segment
call dispword
inc ch
inc ch
mov dl,':'
call write_char
add ch,1
mov ax,cs:dispaddrl
call dispword
;disp address XXXX:XXXX
add cs:dispaddrl,16
adc cs:dispaddrh,0
push ds
push cs
pop ds
lea si,datewinspace
mov bh,byte ptr cs:dispcolor
mov ch,9
call write_str
pop ds
;clear the line with dispcolor
lea si,line
mov ax,cs
mov ds,ax
pop cx
mov cs:halff,0
@displ:
lodsb
mov dl,al
push dx
mov bh,byte ptr cs:dispcolor
call dispchar
inc ch
inc ch
mov dl,20h
call Write_char
inc ch
pop dx
;write the hex code and space
push cx
mov ch,byte ptr cs:chard
cmp dl,20h
jae nextc@
mov dl,'.'
jmp clds
nextc@:
cmp dl,80h
jb clds
cmp dl,0a0h
jae clds
;if > 0a0h, the char is chinese
mov dl,'.'
clds:
mov bh,byte ptr cs:dispcolor
or bh,0fh
call Write_char
inc byte ptr cs:chard
pop cx
;write ascii at the ascii zone
inc cs:halff
cmp cs:halff,8
je dhaf
cmp word ptr cs:charnum,0
jz @34
dec cs:charnum
jnz @displ
@34:
clc
jmp line_e@
dhaf:
cmp cs:charnum,1
jz @34
;test file is over or not
cmp word ptr cs:charnum,0
jz @34
dec word ptr cs:charnum
mov dl,'-'
mov bh,byte ptr cs:dispcolor
call write_char
inc ch
mov dl,20h
call write_char
inc ch
mov cs:halff,9
jmp @displ
line_e@:
popall
ret
displine endp
;----------------------------------------------------------
; Entrance: cl-x
; ch-y
; OutParam: None
;----------------------------------------------------------
DispPage proc
push bp
mov byte ptr cs:isinscrbuffer,1
;set write to memory flag
call Save_scr
;Load the screen to Edit
mov ax,word ptr cs:pagerr.upl
mov word ptr cs:dispaddrl,ax
mov ax,word ptr cs:pagerr.uph
mov word ptr cs:dispaddrh,ax
mov bp,22
;bp=total lines/page
@repage:
call displine
jc page_over
push ax
add word ptr cs:pagerr.downl,16
adc word ptr cs:pagerr.downh,0
pop ax
inc cl
mov ch,10
dec bp
jnz @repage
page_over:
call Pop_scr
;Restore the Edited Buffer to Screen
mov byte ptr cs:isinscrbuffer,0
;clear write to memory flag
pop bp
ret
DispPage endp
;----------------------------------------------------------
; The procedure disp the file as text mode to screen
; Entrance: None
; OutParam: None
;------------------------------------------------------------
togglemess db 'Do you want all file list:<y/n>: ',0
toggleall dw 0
lines dw 0
lines1 dw 0
row db 0
notbinmess db 'Warning: The file is not Text file mode..',0
toggleheader db 'Toggle file name ---->',0
;-------------------------------------------------------------
do_toggle proc
pushall
call save_scr
;call save the screen
cmp cs:isbin,1
jnz do_showto
lea si,notbinmess
mov cs:stop,1
call messagebox
; jmp exit_toggle1
do_showto:
; mov bh,1eh
; call Clr_win
;clear the windows
mov bp,3
call DrawShadow
;draw the windows with shadow
mov cl,9
mov ch,25
mov bh,MessageBoxColor
lea si,togglemess
call write_str
xor ah,ah
int 16h
and al,0dfh
;change to big char
mov word ptr cs:toggleall,0
cmp al,'Y'
jnz notall
mov word ptr cs:toggleall,1
notall:
mov bx,word ptr cs:scrseg
mov ax,word ptr cs:filestartaddr
mov cl,4
shr ax,cl
add bx,ax
mov ds,bx
mov si,word ptr cs:pagerr.upl
cmp word ptr cs:toggleall,1
jnz notallt
mov si,0
notallt:
cld
mov word ptr cs:lines,1
mov byte ptr cs:row,1
mov word ptr cs:lines1,1
mov bh,1fh
call clrscr
mov cx,0
call setcursor
mov cx,160h
loop_toggle:
cmp cs:toggleall,1
jnz do_showline
pushall
push cs
pop ds
mov cl,0
mov ch,2
mov bh,12h
lea si,toggleheader
call write_str
mov cl,0
mov ch,30
mov bh,13h
lea si,file
add si,2
call write_str
;show the header
popall
cmp word ptr cs:toggleall,1
jnz do_showline
mov bh,1eh
mov ax,word ptr cs:lines
push cx
mov cl,byte ptr cs:row
xor ch,ch
call dispword
mov ch,4
mov dl,':'
call write_char
pop cx
;show lines
do_showline:
cmp si,cs:filelenl
jb togger2
jmp exit_toggle
togger2:
;Test file is end or not
lodsb
jmp nextc0
cmp al,09h
jae togger1
jmp exit_toggle
togger1:
cmp al,80h
jb nextc0
jmp exit_toggle
;not active
nextc0:
; cmp al,1ah
; je exit_toggle
nextla:
mov bp,1
cmp al,09
jnz not_tab
mov bp,8
mov al,20h
;if al=09,disp 8 times spaces
not_tab:
mov ah,0eh
mov bx,03h
int 10h
dec bp
jnz not_tab
cmp word ptr cs:toggleall,1
jz alldo
dec cx
jz exit_toggle
; jmp loop_toggle
jmp do_showline
alldo:
cmp al,0ah
jnz adcd
inc word ptr cs:lines
inc word ptr cs:lines1
inc byte ptr cs:row
cmp word ptr cs:lines1,23
ja shok
jmp loop_toggle
shok:
push ax
xor ah,ah
int 16h
mov cx,ax
cmp ax,escape
pop ax
jz exit_toggle1
push cx
mov bh,1fh
call clrscr
mov cx,0
call setcursor
;clear screen,for next page
mov word ptr cs:lines1,1
mov word ptr cs:row,1
pop cx
cmp cx,up
jnz next_togglekey
jmp loop_toggle
Next_ToggleKey:
jmp loop_toggle
adcd:
jmp do_showline
exit_toggle:
mov ah,0
int 16h
exit_toggle1:
call pop_scr
popall
ret
do_toggle endp
;/*--------------------------------------------------------*/
; The procedure clear the screen
;/* Entrance: bh--Color /
;/* OutParam: None /
;/*---------------------------------------------------------/
ClrScr proc
mov ax,0600h
mov cx,0
mov dh,24
mov dl,79
int 10h
ret
ClrScr endp
;-------------------------------------------------------*/
; Entrance: None /
; OutParam: Herc=0--is Color Monitor /
; Herc=1--is MDA Monitor /
;--------------------------------------------------------/
TestMonitor PROC
push ax
push ds
xor ax,ax
mov ds,ax
mov al,byte ptr ds:[449h]
mov cs:herc,0
cmp al,7
jnz @1
mov cs:herc,1
@1:
pop ds
pop ax
ret
TestMonitor endp
;-------------------------------------------------------
; The procedure set cursor position
; Entrance: cl-x
; ch-y
; OutParam: None
;------------------------------------------------------
SetCursor proc
mov ah,2
mov bh,0
mov dh,cl
mov dl,ch
int 10h
ret
SetCursor endp
;--------------------------------------------------------+
; The procedure get the char/Attri from the video
; Note: The procedure Destroy many registers
; Entrance: cl-x
; ch-y
; Outparam: cs:getcolor=Attri (byte)
; cs:getchar =Char (byte)
;--------------------------------------------------------+
GetColor db 0
GetChar db 0
;---------------------------------------------------------+
Get_charAttri proc
pushall
mov ax,0b800h
cmp cs:herc,1
jnz @2ca
mov ax,0b000h
@2ca:
mov ds,ax
mov al,cl
mov cl,80
mul cl
mov cl,ch
xor ch,ch
add ax,cx
mov cl,1
shl ax,cl
;ax=position
mov si,ax
cld
lodsb
mov byte ptr cs:getchar,al
;al=char
lodsb
mov byte ptr cs:getcolor,al
;al=attri
popall
ret
Get_CharAttri endp
;--------------------------------------------------------/
; The procedure write the byte to the video buffer /
; Entrance: cl-x /
; ch-y /
; bh-Attribute /
; dl-Char /
; OutParam: None /
;--------------------------------------------------------/
Write_char proc
pushall
push cx
cmp byte ptr cs:isInScrBuffer,1
jnz to_32
mov ax,word ptr cs:scrseg
jmp @2
;if is in memory buffer,write char to momery
;then use rep movsb instruct to move the memory
;to the video buffer
to_32:
mov ax,0b800h
cmp herc,1
jnz @2
mov ax,0b000h
@2:
mov ds,ax
push ax
push dx
mov al,cl
mov cl,80
mul cl
mov cl,ch
xor ch,ch
add ax,cx
mov cl,1
shl ax,cl
;ax=position
mov si,ax
pop dx
pop ax
xor ax,ax
mov al,dl
cld
mov byte ptr ds:[si+1],bh
mov byte ptr ds:[si],al
pop cx
inc ch
cmp ch,80
jb set_c
xor ch,ch
inc cl
cmp cl,24
jb set_c
xor cx,cx
set_c:
call SetCursor
popall
ret
Write_Char endp
;----------------------------------------------------------------/
;' The procedure wirte the string to the video buffer /
; Entrance: Ds:si--String(end with 0) /
; bh-Attri /
; cl--x /
; ch--y /
; OutParam: None /
;----------------------------------------------------------------/
Write_Str proc
pushall
cld
lodsb
@5:
or al,al
jz @3
mov dl,al
call Write_char
inc ch
cmp ch,80
jbe @4
inc cl
xor ch,ch
@4:
lodsb
jmp @5
@3:
popall
ret
Write_Str endp
;----------------------------------------------------------------
; The procedure save the current screen to the buffer
; Entrance: None
; OutParam: None
;---------------------------------------------------------------
Save_scr proc
pushall
mov ax,0b800h
cmp herc,1
jnz @s
mov ax,0b000h
@s:
mov ds,ax
xor si,si
xor di,di
cld
mov ax,cs:scrseg
mov es,ax
mov cx,2048*2
rep movsb
popall
ret
Save_scr endp
;----------------------------------------------------------------/
; The procedure restore the screen from the buffer
; Entrance: None
; OutParam: None
;---------------------------------------------------------------
Pop_scr proc
pushall
mov ax,0b800h
cmp herc,1
jnz @ss
mov ax,0b000h
@ss:
mov es,ax
xor si,si
xor di,di
cld
mov ax,cs:scrseg
mov ds,ax
mov cx,2048*2
rep movsb
popall
ret
Pop_scr endp
;---------------------------------------------------------------
; Entrance: Ds:si--Message
; if Stop==1,bx=Porcedure addr.
; OutParam: None
;---------------------------------------------------------------
stop dw 1
Sdp db 50 dup(20h),0
messb db 201,18 dup(205),' MessageBox ',18 dup(205)
db 187,0
messb1 db 186,48 dup(20h),186,0
messb2 db 186,48 dup(20h),186,0
messb3 db 186,48 dup(20h),186,0
messb4 db 200,48 dup(205),188,0
;--------------------------------------------------------------
MessageBox proc
pushall
push bx
;bx=procedure addr.
push si
cmp byte ptr cs:saveinmess,0
jz not_sa
call Save_scr
not_sa: ;Test save screen or not
call HideCursor
mov bh,07h
mov cl,10
mov ch,12
lea si,sdp
mov ax,5
@rr:
call Write_str
inc cl
dec ax
jnz @rr
;Clear BackGround
mov bh,2fh
mov ch,10
mov cl,9
lea si,messb
call Write_str
inc cl
lea si,messb1
call Write_str
inc cl
lea si,messb2
call Write_str
inc cl
lea si,messb3
call Write_str
inc cl
lea si,messb4
call Write_str
mov cl,11
mov ch,13
mov bh,MessageBoxColor
and bh,2fh
pop si
call Write_str
pop bx
cmp stop,1
jnz hg
mov ah,0
int 16h
jmp hg1
hg:
call bx
hg1:
cmp byte ptr cs:saveinmess,0
jz to_po
call Pop_scr
to_po:
popall
ret
MessageBox endp
;-----------------------------------------------------------------
header db ' Hex 00 01 02 03 04 05 06 07 - 08 09 0A 0B 0C 0D 0E 0F '
db ' --'
DB ' ASCII -- ',0
bottom db 'F1-Help,F2-Go,F3-Load,F4-Edit,F5-Color,F6-Toggle,'
db 'F7-Block,F8-Search,F9-Key Value',0
EditBo db 18h,19h,1ah,1bh,'--Move,Enter--Save,Tab--Change Edit Zo'
db 'ne,Esc--Exit,De'
db 'l--Delete,Ins--Insert ',0
insertmess db '| Browse ',0
overmess db '| Overwrite',0
insmess db '| Insert ',0
blockmess db 'Block: |',0
;----------------------------------------------------------------
ShowHeader proc
mov bp,70h
mov dl,20h
mov cl,0
mov ch,0
mov bh,70h
clearline:
call Write_char
inc ch
dec bp
jnz clearline
;Clear the Top Line
lea si,insertmess
mov cl,0
mov ch,69
mov bh,2fh
call write_str
;show the status
mov cl,0
mov ch,20
mov bh,74h
lea si,file
add si,2
call Write_str
;show file message
mov cx,0001h
mov bh,0fh
lea si,header
call write_str
mov cx,0018h
mov bh,0Fh
lea si,bottom
call write_str
;show bottom message
mov cx,0
mov bh,2fh
lea si,blockmess
call write_str
mov ax,cs:block
mov cx,0600h
; mov bh,MessageBoxColor
mov bh,20h
call dispword
;show block message
ret
ShowHeader endp
;----------------------------------------------------------------/
; Entrance: Bx-Handle /
; OutParam: None /
;----------------------------------------------------------------/
Do_bin proc
call HideCursor
;Hide Cursor
mov ax,cs:scrseg
mov dx,cs:writebufferstart
shr dx,4
add ax,dx
mov word ptr cs:writebufferseg,ax
;form write buffer segment
mov word ptr cs:pagerr.upl,0
mov word ptr cs:pagerr.uph,0
mov word ptr cs:pagerr.downl,0
mov word ptr cs:pagerr.downh,0
mov word ptr cs:pagerr.zone,0
call getfilelength
jnc to_binon
jmp exit_bin
to_binon:
call Readfile
jnc to_binon1
jmp exit_bin
to_binon1:
push bx
call showheader
;show header
pop bx
redrawpage:
mov cx,0a02h
call disppage
main_loop:
; call showaddress
mov ah,0
int 16h
cmp ax,down
jnz main_1@
call ScroolLIne
jmp main_loop
main_1@:
cmp ax,Escape
jnz main_ins
jmp exit_bin
main_ins:
cmp ax,up
jnz main_2@
call Scroolup
jmp main_loop
main_2@:
cmp ax,pgdn
jnz main_3@
call do_pgdn
jmp main_loop
main_3@:
cmp ax,F3
jnz main_4@
call do_f3
jmp main_loop
main_4@:
cmp ax,pgup
jnz main_5@
call do_pgup
jmp main_loop
main_5@:
cmp ax,F1
jnz main_6@
call do_help
jmp main_loop
main_6@:
cmp ax,Ender
jnz main_7@
call do_end
jmp main_loop
main_7@:
cmp ax,home
jnz main_8@
call do_home
jmp main_loop
main_8@:
cmp ax,F6
jnz main_9@
call do_toggle
jmp main_loop
main_9@:
cmp ax,F2
jnz main_a@
call do_go
jc to_llpg
mov cs:pagerr.upl,ax
mov cs:pagerr.downl,ax
jmp redrawpage
to_llpg:
jmp main_loop
main_a@:
cmp ax,F4
jnz main_b@
call do_edit
jmp main_loop
main_b@:
cmp ax,F5
jnz main_c@
call do_F5
jmp main_loop
main_c@:
cmp ax,F7
jnz main_d@
call do_fill
jmp main_loop
main_d@:
cmp ax,F9
jnz main_e@
call do_F9
main_e@:
cmp ax,F8
jnz main_f@
call do_f8
jmp main_loop
main_f@:
cmp ax,F10
jnz main_g@
call do_f10
jmp main_loop
main_g@:
cmp ax,EnterChar
jnz main_h@
call Do_enter
jmp main_loop
main_h@:
cmp ax,NextIns
jnz main_i@
mov bh,byte ptr cs:dispcolor
call clr_win
;clear the screen
jmp do_bin
;read the other block
main_i@:
cmp ax,Subchar
jnz main_j@
call do_cut
main_j@:
and al,0DFh
; change to big char
cmp al,'A'
jnz main_k@
call ShowAscii
jmp main_loop
main_k@:
cmp al,'E'
jnz main_l@
call Do_Encrypt
jmp main_loop
main_l@:
jmp main_loop
exit_bin:
;scrool screen up of 1 line
ret
Do_bin endp
;----------------------------------------------------------------/
; Entrance: Bx-Handle /
; OutParam: None /
;----------------------------------------------------------------/
Do_Text proc
ret
Do_Text endp
;-----------------------------------------------------------------
; Entrance: None
; OutParam: clc-Ok
; stc-Error
;-----------------------------------------------------------------
ReAllocMem proc
mov ax,cs:psp
lea bx,all
mov cl,4
shr bx,cl
add ax,bx
add ax,100
mov cs:scrseg,ax
;Free More Memory
; mov ax,cs:scrseg
mov bx,cs:bufferstartaddr
mov cl,4
shr bx,cl
add ax,bx
mov cs:currentbuffseg,ax
;ax=temp buffer for edit
ret
ReAllocMem endp
;---------------------------------------------------------
; Entrance: None
; OutParam: None
;-------------------------------------------------------
addrmess db 'The Position is:',0
copy1 db 10h,'Thanks For Using.'
db '(C)Copyright ',0
Yc db 'YuHuan & Lxf /1996 ',0
Yi db '(r) All rights reserved. ',11h,0
;--------------------------------------------------------
showaddress proc
mov ch,60
mov cl,0
mov bh,07h
push cs
pop ds
lea si,addrmess
call write_str
mov bh,70h
mov ch,76
mov cl,0
mov ax,word ptr cs:pagerr.zone
call Dispword
ret
showaddress endp
;---------------------------------------------------------
; Entrance: None
; OutParam: None
;----------------------------------------------------------
helpmess0 db "The BinEdit Program's Help",0
helpmess1 db ' Author: YuHuan ',0
helpmess2 db 'Date : 1996.5 [ Version 1.0 ]',0
helpmess3 db 'Addr. : BeiJing CS&S HuaTech Info Tech LTD.',0
helpmess4 db 'Tel : (010)62177722-6406',0
helpmess5 db ' Notes:',0
helpmess6 db ' If you find any bugs,Please contact with me',0
helpmess7 db ' The program can be released at any way',0
helpmess8 db ' ',0
helpmess9 db ' Function: ',0
helpmess10 db ' ',18h,19h,1ah,1bh,',pgup,pgdn,home,end-List,Enter-Save file',0
helpmess12 db ' F1-Help,F2-Go,F3-Load,F4- Edit,F5- Chg Color',0
helpmess13 db ' F6-Toggle Bin/Text,F7-Fill/Delete/Save Block',0
helpmess14 db ' F8-Search,F9-Key Value,F10-Chg file,Esc-Exit',0
helpmess15 db ' Gray [+]- Load Block,Gray [-]-Cut large file',0
helpmess11 db ' A-Ascii Chart,E-Encrypt.',0
; helpmess11 db ' Press any key to continue...',0
helpaddr dw offset helpmess1
dw offset helpmess2
dw offset helpmess3
dw offset helpmess4
helpaddr1 dw offset helpmess5
dw offset helpmess6
dw offset helpmess7
dw offset helpmess8
dw offset helpmess9
dw offset helpmess10
dw offset helpmess12
dw offset helpmess13
dw offset helpmess14
dw offset helpmess15
dw offset helpmess11
;----------------------------------------------------------
Do_help proc
pushall
call save_scr
call hidecursor
mov bh,17h
call clrscr
lea si,sdp
mov cl,4
mov ch,16
mov bp,19
mov bh,07h
help_l1:
call write_str
inc cl
dec bp
jnz help_l1
mov bh,25h
mov cl,3
mov ch,14
mov bp,19
help_l:
call Write_str
inc cl
dec bp
jnz help_l
lea si,helpmess0
mov cl,2
mov ch,25
mov bh,1eh
call write_str
;show help header
mov cl,5
mov ch,20
mov bh,20h
lea di,helpaddr
mov bp,4
push cs
pop es
help_l2:
mov si,word ptr es:[di]
add di,2
call write_str
inc cl
dec bp
jnz help_l2
;first helpmess
mov cl,10
mov ch,15
lea di,helpaddr1
mov bh,2fh
mov bp,11
help_l3:
mov si,word ptr es:[di]
add di,2
call write_str
inc cl
dec bp
jnz help_l3
;show help mess
; mov cl,20
; mov ch,20
; mov si,word ptr es:[di]
; mov bh,MessageBoxColor
; call write_str
;show press any key mess
xor bp,bp
to_shh:
mov ah,1
int 16h
jnz to_noke
mov bh,70h
mov cl,5
mov ch,19
mov dl,'-'
or bp,bp
jz to_dg
xor bp,bp
mov dl,'|'
jmp to_dgg
to_dg:
mov bp,1
to_dgg:
push dx
call write_char
pop dx
mov ch,40
mov cl,5
call write_char
;disp '/' or '/'
call Changecolor
mov bh,al
and bh,0fh
or bh,bh
jnz to_ddafa
mov bh,07h
;al=color
to_ddafa:
mov cl,5
mov ch,20
lea si,helpmess1
call write_str
mov ah,2ch
int 21h
mov bl,dh
to_rt:
mov ah,2ch
int 21h
cmp bl,dh
jz to_rt
;disp a second
jmp to_shh
to_noke:
xor ah,ah
int 16h
;flush the extra key
call pop_scr
; call showcursor
popall
ret
Do_help endp
;------------------------------------------------------------
; Entrance; None
; OutParam: None
;------------------------------------------------------------
segg db 5
db ?
db 5 dup(0)
offmess db 'Please input Offset ->',0
;----------------------------------------------------------
; The Procedure Form the Jmp Offset
;
; Entrance:None
; OutParam:ax=Offset
;----------------------------------------------------------
Do_Go proc
push ds
push es
push bx
push cx
push dx
call save_scr
;save the screen
; mov bh,1fh
; call clr_win
;scrool the window
mov bp,4
call drawShadow
mov cl,09h
mov ch,09h
mov bh,MessageBoxColor
lea si,offmess
call write_str
;show message
mov ch,33
call setcursor
;set cursor
call getnum
jc exit_go
;get offset from keyboard
and ax,0fff0h
; mov cx,cs:maxoff
; sub cx,160h
cmp ax,cs:maxoff
jae go_yh
mov cx,cs:maxoff
cmp cx,160h
jbe go_yh
sub cx,160h
cmp ax,cx
jbe exit_go1
mov ax,cx
jmp exit_go1
go_yh:
mov ax,0
exit_go1:
clc
exit_go:
;process offset
pushf
push ax
call pop_scr
pop ax
popf
;restore screen
pop dx
pop cx
pop bx
pop es
pop ds
ret
Do_Go endp
;---------------------------------------------------------
off db 4 dup(30h)
notdogo dw 0
NoCharFlag db 0
;--------------------------------------------------------
; Entrance: None
; OutParam: stc--Error
; clc-ok,Ax-Number from keyboard
;---------------------------------------------------------
GetNum proc
mov byte ptr cs:nocharflag,0
lea dx,segg
push cs
pop ds
mov ah,0ah
call get_str
jnc next_numa
jmp error_char
next_numa:
lea si,segg
mov cl,byte ptr ds:[si+1]
xor ch,ch
or cx,cx
jnz charyes
mov byte ptr cs:nocharflag,1
charyes:
mov bp,cx
mov cx,4
sub cx,bp
mov bp,cx
push bp
;bp=numbers to fill with '0'
cld
mov al,30h
lea di,off
push cs
pop es
mov cx,4
rep stosb
;fill buffer with '0'
add si,2
lea di,off
add di,bp
mov cl,byte ptr ds:[si-1]
xor ch,ch
rep movsb
;form to 4 byts
lea si,off
lea di,segg
add di,2
mov cx,4
pop bp
next_char:
lodsb
cmp al,'9'
jg ischar
cmp al,'0'
jb error_char
sub al,30h
to_store:
stosb
loop next_char
lea si,segg
add si,2
mov bx,4
xor bp,bp
mov cs:notdogo,1
to_lp:
lodsb
xor ah,ah
or bp,ax
cmp bx,1
jnz to_lp1
cmp cs:notdogo,1
jz go_changeover
to_lp1:
mov cl,4
rol bp,cl
dec bx
jnz to_lp
;change 4 byte number to a words
go_changeover:
clc
jmp ok_char
ischar:
and al,0dfh
cmp al,'A'
jb error_char
cmp al,'F'
ja error_char
sub al,37h
jmp to_store
error_char:
stc
ret
ok_char:
clc
mov ax,bp
ret
getnum endp
;------------------------------------------------------------------------+
offst1 db 'Please input start offset:',0
offst2 db 'Please input end offset:',0
offst3 db 'Input Fill Char (Hex) :',0
off1 dw 0
;------------------------------------------------------------------------
; OutParam: stc-error
; clc-ok
; bp=second offset
; cs:off1=first offset
; cx=Length
;----------------------------------------------------------------------
Get_TwoOffset proc
; mov bh,1fh
; call clr_win
mov bp,6
call DrawShadow
;draw the windows with shadow
mov cl,09h
lea si,offst1
mov bp,2
loop_offget:
mov ch,0bh
mov bh,MessageBoxColor
call write_str
mov ch,37
call setcursor
push bp
call getnum
pop bp
jc exit_gettwo_error
dec bp
jz exit_getoff
mov cs:off1,ax
mov cl,0ah
lea si,offst2
jmp loop_offget
exit_getoff:
mov bp,ax
cmp ax,cs:off1
jbe exit_GetTwo_error
cmp ax,cs:filelenl
jb get_yh1
mov ax,cs:filelenl
get_yh1:
mov bx,cs:off1
cmp bx,cs:filelenl
ja exit_getTwo_error
sub ax,bx
mov cx,ax
cmp cx,0
jbe Exit_getTwo_error
clc
jmp exit_GetTwo
;cx=length
exit_GetTwo_error:
stc
exit_GetTwo:
ret
Get_TwoOffset endp
;---------------------------------------------------------------
; Entrance: cx= The Length
; OutParam: clc-ok,ax=length
; stc-Error
;------------------------------------------------------------
Test_Para proc
cmp cx,cs:filelenl
jb fill@5
jmp exit_fillt
fill@5:
mov ax,cs:off1
cmp ax,cs:filelenl
jb fill@6
jmp exit_fillt
fill@6:
add ax,cx
cmp ax,cs:filelenl
jae exit_fillt
clc
ret
;test the parameter is valid or not
exit_fillt:
stc
ret
Test_Para endp
;-----------------------------------------------------------------
FillMess db 'Fill or Delete or Save Block <F/D/S>:',0
;-----------------------------------------------------------------
; The procedure to process the Fill or Delete the block
;-----------------------------------------------------------------
Do_Fill proc
pushall
call Get_TwoOffset
jnc fill@4
jmp exit_fill
fill@4:
push cx
mov cl,0bh
lea si,fillmess
mov ch,0bh
mov bh,MessageBoxColor
call write_str
fill@3:
xor ax,ax
int 16h
cmp ax,escape
jnz fill@1
pop cx
jmp exit_fill
;process esc key
fill@1:
and al,0dfh
cmp al,'F'
jz fill@2
cmp al,'D'
jz fillDel
cmp al,'S'
jnz fill@3
pop cx
call SaveBlock
jmp exit_fill
;do Save the Block
fillDel:
pop cx
inc cx
call Test_para
jc exit_fill
mov si,cs:filelenl
sub si,ax
mov bp,si
mov si,cs:off1
mov di,si
add si,cx
mov ax,cs:currentseg
mov es,ax
mov ds,ax
cld
push cx
mov cx,bp
rep movsb
pop cx
sub cs:filelenl,cx
;form new file len
mov ax,cs:filelenl
and ax,0fh
mov cs:nextchar,ax
;form the new last char number
mov ax,cs:filelenl
dec ax
mov cl,4
shr ax,cl
mov cl,4
shl ax,cl
mov cs:maxoff,ax
;form the maxlines
jmp exit_fill
fill@2:
pop cx
push cx
mov cl,0ch
lea si,offst3
mov ch,0bh
mov bh,MessageBoxColor
call write_str
mov ch,37
call setcursor
mov byte ptr cs:segg,3
call getnum
mov byte ptr cs:segg,5
pop cx
jc exit_fill
;get char
mov dx,cs:currentseg
mov es,dx
mov di,cs:off1
cld
inc cx
rep stosb
exit_fill:
mov bh,byte ptr cs:dispcolor
call clr_win
;clear the window
call redrawpager
popall
ret
Do_fill endp
;---------------------------------------------------------------------
cutst1 db 'Please input First Block : ',0
cutst2 db 'Please input First Offset: ',0
cutst3 db 'Please input Second Block :',0
cutst4 db 'Please input Second Offset:',0
;------------------------------------------------------------------------
; OutParam: stc-error
; clc-ok
; bp=second offset
; cs:off1=first offset
; cx=Length
;----------------------------------------------------------------------
Get_FourOffset proc
mov bp,8
call DrawShadow
;draw the windows with shadow
mov bp,4
loop_offcut:
cmp bp,4
jnz lopc1
lea si,cutst1
mov cl,09h
jmp to_alopc
lopc1:
cmp bp,3
jnz lopc2
lea si,cutst2
mov cl,0ah
jmp to_alopc
lopc2:
cmp bp,2
jnz lopc3
lea si,cutst3
mov cl,0bh
jmp to_alopc
lopc3:
cmp bp,1
jnz to_alopc
lea si,cutst4
mov cl,0ch
to_alopc:
mov bh,MessageBoxColor
mov ch,0bh
call write_str
mov ch,39
call setcursor
push bp
call getnum
pop bp
jnc ok_ut
jmp exit_cuttwo_error
ok_ut:
cmp bp,4
jnz slop1
mov cs:firstb,ax
jmp to_sex
slop1:
cmp bp,3
jnz slop2
mov cs:firsto,ax
jmp to_sex
slop2:
cmp bp,2
jnz slop3
mov cs:secb,ax
jmp to_sex
slop3:
cmp bp,1
jnz to_sex
mov cs:seco,ax
to_sex:
dec bp
jz exit_cutoff
jmp loop_offcut
exit_cutoff:
mov ax,cs:firstb
mov cx,cs:secb
cmp ax,cx
ja exit_cutTwo_error
cmp cx,cs:totalblock
ja exit_cutTwo_error
mov ax,cs:firstb
or ax,ax
jz exit_cutTwo_error
mov ax,cs:firsto
cmp ax,maxreadfile
jb get_yh1c
jmp exit_cuttwo_error
get_yh1c:
mov bx,cs:seco
cmp bx,maxreadfile
ja exit_cutTwo_error
dec cs:firstb
dec cs:secb
mov ax,cs:firstb
mov cx,maxreadfile
mul cx
clc
add ax,cs:firsto
adc dx,0
mov cs:firstb,dx
mov cs:firsto,ax
;start file offset
mov ax,cs:secb
mov cx,maxreadfile
mul cx
clc
add ax,cs:seco
adc dx,0
clc
sub ax,cs:firsto
sbb dx,cs:firstb
clc
inc ax
adc dx,0
;inc a byte
mov cs:secb,dx
mov cs:seco,ax
;length
clc
jmp exit_CutTwo
;cx=length
exit_cutTwo_error:
stc
exit_CutTwo:
ret
Get_FourOffset endp
;---------------------------------------------------------------
; The procedure cut the file
; Entrance: None
; Outparam: None
;--------------------------------------------------------------
FirstB dw 0
FirstO dw 0
Seco dw 0
SecB dw 0
;-------------------------------------------------------------
Do_Cut proc
pushall
call save_scr
;save the screen
call Get_fourOffset
jnc fill@4c
jmp exit_cut
fill@4c:
mov cl,0dh
call OpenFile
jc exit_cut
mov bp,bx
;bp=handle
mov bx,cs:handle
mov ax,4200h
mov cx,cs:firstb
mov dx,cs:firsto
int 21h
jc exit_cut
loop_cut:
mov ax,cs:currentbuffseg
mov ds,ax
mov ah,3fh
mov bx,cs:handle
mov cx,400
xor dx,dx
int 21h
jc exit_cut
mov cx,ax
or cx,cx
jz exit_cut
clc
sub cs:seco,cx
sbb cs:secb,0
jnc cut_ok
add cs:seco,cx
mov cx,cs:seco
mov bx,bp
mov ah,40h
int 21h
jmp exit_cut
;write the tail
cut_ok:
push cx
mov bx,bp
mov ah,40h
int 21h
pop cx
jc exit_cut
jmp loop_cut
exit_cut:
mov bx,bp
mov ah,3eh
int 21h
;close the file
call pop_scr
popall
ret
do_cut endp
;----------------------------------------------------------------
; The procedure draw the error message
; Entrance: si=the errormsg offset
; OUtparam: none
;---------------------------------------------------------------
DrawError proc
; mov bp,3
; push si
; call DrawShadow
; pop si
;draw windows
mov cx,0b0ch
mov bh,2fh
call write_str
xor ah,ah
int 16h
ret
DrawError endp
;-----------------------------------------------------------------
f10File db 64
db ?
db 64 dup(0)
;the save file buffer
f10mess db 'Please input Save File name:',0
f10Wait db 'The Program Change Hex file to Ascii File,Wait...',0
f10Error db 'Error:The Offset is Invalid,Program Abort...',0
handle2 dw 0
f10buffer dw 0
changeNum dw 0
LineChar db 0dh,0ah
Destfile db 09h,'(c) Copyright YuHuan & LXF,1996,BeiJing,(r)'
db ' All rights reserved,.',0dh,0ah
db 09h,'The Source File:',09h
destLen equ $-offset DestFile
destseg dw 0
destOff dw 0
CutChar db ':',0
;-------------------------------------------------------------
; The procedure change the HEX file to the Ascii file
;------------------------------------------------------------
Do_F10 proc
pushall
; call Save_scr
mov cs:destoff,0
mov cs:destseg,0
; init the offset
mov bp,4
call drawShadow
; Draw the window
mov cl,09h
call OpenFile
jnc to_cf
jmp exit_cf
to_cf:
mov byte ptr cs:ToFileF,1
mov cs:changeNum,0
mov cs:handle2,bx
;set the write to file flag
lea dx,DestFile
mov cx,DestLen
mov ah,40h
int 21h
;write the file header
mov di,offset file
add di,2
mov cl,byte ptr cs:[di-1]
xor ch,ch
mov dx,di
mov ah,40h
int 21h
mov ah,40h
lea dx,linechar
mov cx,2
int 21h
;write the file name to dest file
call WriteAdd
mov cl,0bh
lea si,f10Wait
mov ch,0bh
mov bh,MessageBoxColor
or bh,0fh
call write_str
;show the wait message
mov bx,cs:handle
mov ax,4200h
xor cx,cx
xor dx,dx
int 21h
lea di,f10file
add di,2
mov byte ptr cs:[di],20h
mov byte ptr cs:[di-1],09h
inc di
loop_change:
mov bx,cs:handle
mov ah,3fh
mov cx,1
push cs
pop ds
lea dx,f10buffer
int 21h
;Read the Souce file every Byte
jc exit_change
or ax,ax
jz exit_change
mov al,byte ptr cs:f10buffer
cmp al,20h
jb not_asciilow
cmp al,80h
jae not_asciilow
mov byte ptr cs:[di],al
jmp to_allasc
not_asciilow:
mov byte ptr cs:[di],'.'
to_allasc:
inc di
;store the byte to buffer for ascii write
call dispchar
mov bx,cs:handle2
mov dx,offset charStore
mov cx,3
push cs
pop ds
mov ah,40h
int 21h
;Write the Exchange Byte to Dest file
; call ChangeAndWrite
jc exit_change
inc cs:changenum
cmp cs:changenum,16
jnz to_nc
lea di,f10file
add di,2
mov dx,di
mov cx,17
mov ah,40h
int 21h
inc di
;skip the 09h char
;write the ascii char
lea dx,LineChar
mov cx,2
mov ah,40h
int 21h
jc exit_change
mov cs:changenum,0
add cs:destoff,16
adc cs:destseg,0
call WriteAdd
; write the address seg:off
to_nc:
jmp loop_change
exit_change:
cmp cs:changenum,0
jz to_exitch
mov bx,cs:handle2
mov cx,10h
sub cx,cs:changenum
inc cx
shl cx,1
lea dx,datewinspace
mov ah,40h
int 21h
;write some space
mov cx,cs:changenum
add cx,2
lea dx,f10file
inc dx
mov ah,40h
int 21h
;write the last line ascii chars
to_exitch:
mov bx,cs:handle2
mov ah,3eh
int 21h
;close the file
exit_cf:
mov byte ptr cs:toFileF,0
;clear the flag
; call pop_scr
call redrawpager
popall
ret
do_f10 endp
;----------------------------------------------------------------
; The procedure change the Hex byte to ascii and write to file
; Entrance: AL= byte to change and write
;---------------------------------------------------------------
ChangeAndWrite proc
call dispchar
mov bx,cs:handle2
mov dx,offset charStore
mov cx,2
push cs
pop ds
mov ah,40h
int 21h
;Write the Exchange Byte to Dest file
ret
ChangeAndWrite endp
;----------------------------------------------------------------
; The procedure change the ax to ascii mode and write to the file
; Entrance: Ax= word
;---------------------------------------------------------------
WriteWordToFile proc
xchg ah,al
push ax
call ChangeAndWrite
pop ax
xchg ah,al
call ChangeAndWrite
ret
WriteWordToFile endp
;----------------------------------------------------------------
; The procedure write the seg:off to file
;---------------------------------------------------------------
SpaceChar db 4 dup(20h),0
;--------------------------------------------------------------
WriteAdd proc
mov ax,cs:destseg
call WriteWordToFile
mov ah,40h
lea dx,CutChar
mov cx,1
int 21h
; write the ':'
mov ax,cs:destoff
call WriteWordToFile
; write the Seg:Off to the file
mov ah,40h
lea dx,SpaceChar
mov cx,2
int 21h
ret
WriteAdd endp
;-----------------------------------------------------------------
; The Procedure Save the Block to the File
; Entrance: None
; OutParam: None
;----------------------------------------------------------------
SaveBlock proc
push cx
call Test_para
pop cx
jnc f10ok2
lea si,f10error
call DrawError
;show the error msg
jmp exit_f10
;test the para is valid or not
f10ok2:
push cx
mov cl,0ch
call OpenFile
jmp EndOpenF
;--------------------------------------------------------------------------
OpenFile proc
lea si,f10mess
mov ch,0bh
mov bh,MessageBoxColor
call write_str
mov ch,40
call setcursor
push cs
pop ds
lea dx,f10file
mov si,dx
call Get_str
cmp byte ptr cs:[si+1],0
jz exit_f10
mov cl,byte ptr cs:[si+1]
add si,2
xor ch,ch
add si,cx
mov byte ptr cs:[si],0
mov ah,3ch
lea dx,f10file
add dx,2
mov cx,0
int 21h
jc exit_openf
mov bx,ax
exit_openf:
ret
OpenFile endp
EndOpenF:
pop cx
inc cx
push ds
mov ah,40h
mov dx,cs:currentseg
mov ds,dx
mov dx,cs:off1
int 21h
pop ds
jc exit_f10
mov ah,3eh
int 21h
exit_f10:
mov byte ptr cs:saveinmess,1
;restore the flag
ret
SaveBlock endp
;------------------------------------------------------------------------
Offsetfind db 'The Data in the last page,it is at offset: '
db ' | Esc--Exit ',0
AtLastF db 0
;------------------------------------------------------------------------
; The procedure re-draw the page of screen
;-----------------------------------------------------------------------
redrawpager proc
mov byte ptr cs:atlastf,0
;Clear the last page flag
; mov bh,byte ptr cs:dispcolor
; call clr_win
mov ax,word ptr cs:pagerr.upl
cmp byte ptr cs:f88,1
jz do_f88
jmp next_p1
do_f88:
push ax
add ax,160h
cmp ax,cs:maxoff
pop ax
jbe next_p1
mov byte ptr cs:atlastf,1
;Set the last page flag
mov ax,cs:maxoff
cmp word ptr cs:nextchar,0
jz to_nonextc
add ax,10h
to_nonextc:
sub ax,160h
push ax
lea si,offsetfind
mov cl,24
mov ch,0
mov bh,4eh
call write_str
pop ax
mov cl,24
mov ch,45
mov bh,0fh
push ax
mov ax,cs:pagerr.upl
call dispword
pop ax
;test the offset is to file end or not
next_p1:
mov cx,0a02h
mov bh,07h
and ax,0fff0h
mov word ptr cs:pagerr.upl,ax
mov word ptr cs:pagerr.downl,ax
call disppage
ret
redrawpager endp
;------------------- The Next is Edit Procedure -------------------------+
ColMove STRUC
; Name Byte Position
HexAddrl db ? ;0
HexAddrh db ? ;1
AscAddr db ? ;2
ColNum db ? ;3
NextColPoint dw ? ;4
PrevColPoint dw ? ;6
ColMove ENDS
;The struct of edit,is the Cycle Linker
;----------------------------------------------------------------------+
HexAddrlp equ 0
HexAddrhp equ 1
AscAddrp equ 2
ColNump equ 3
NextColPointp equ 4
PrevColPointp equ 6
maxrow equ 23
minrow equ 2
;-----------------------------------------------------------------------
CurrentCol db 0
CurrentRow db 0
CurrentP dw offset col1
HasChanged dw 0
;Globle Var.
InAscZone dw 0
currentbuffseg dw 0
bufferlen dw 0
NewFile db 'YH.LXF',0
NewFileMess db 'The Old File Backup to [YH.LXF]',0
;-----------------------------------------------------------------------
col1 ColMove <10,11,62,1,offset col2,offset col0 >
col2 ColMove <13,14,63,2,offset col3,offset col1>
col3 ColMove <16,17,64,3,offset col4,offset col2 >
col4 ColMove <19,20,65,4,offset col5,offset col3 >
col5 ColMove <22,23,66,5,offset col6,offset col4 >
col6 ColMove <25,26,67,6,offset col7,offset col5 >
col7 ColMove <28,29,68,7,offset col8,offset col6 >
col8 ColMove <31,32,69,8,offset col9,offset col7 >
col9 ColMove <36,37,70,9,offset cola,offset col8 >
cola ColMove <39,40,71,10,offset colb,offset col9>
colb ColMove <42,43,72,11,offset colc,offset cola>
colc ColMove <45,46,73,12,offset cold,offset colb>
cold ColMove <48,49,74,13,offset cole,offset colc>
cole ColMove <51,52,75,14,offset colf,offset cold>
colf ColMove <54,55,76,15,offset col0,offset cole>
col0 ColMove <57,58,77,16,offset col1,offset colf>
;Initilize the Cycle Linker
;----------------------------------------------------------
Do_Edit proc
lea si,overmess
mov cl,0
mov ch,69
mov bh,20h
call write_str
;show the status
mov cx,0018h
mov bh,2fh
lea si,editbo
call write_str
;Write the Bottom Message
Re_editp:
mov word ptr cs:haschanged,0
mov byte ptr cs:currentcol,10
mov byte ptr cs:currentrow,2
mov word ptr cs:currentp,offset col1
mov word ptr cs:InAscZone,0
;init the val
call seteditcursor
push es
push ds
mov ax,cs:currentseg
mov ds,ax
mov ax,cs:currentbuffseg
mov es,ax
xor di,di
mov ax,cs:pagerr.upl
mov si,ax
mov cx,cs:pagerr.downl
sub cx,ax
mov cs:bufferlen,cx
cld
rep movsb
;save the edit buffer for esc fuction
pop ds
pop es
next_edit:
call ShowBigCursor
mov ah,0
int 16h
cmp ax,right
jnz edit_1
call do_editright
jmp next_edit
edit_1:
cmp ax,left
jnz edit_2
call do_editleft
jmp next_edit
edit_2:
cmp ax,escape
jnz edit_3
cmp cs:haschanged,1
jz to_notrest
call do_editesc
to_notrest:
call HideCursor
call redrawpager
jmp edit_exit
edit_3:
cmp ax,up
jnz edit_4
call do_editup
jmp next_edit
edit_4:
cmp ax,down
jnz edit_5
call do_editdown
jmp next_edit
edit_5:
cmp ax,EnterChar
jnz edit_6
call do_Enter
mov cs:haschanged,1
;set the changed flag
jmp next_edit
edit_6:
cmp ax,Tab
jnz edit_7
cmp word ptr cs:inasczone,0
jz tab_1
mov word ptr cs:inasczone,0
call do_Tab
jmp next_edit
tab_1:
mov word ptr cs:inasczone,1
call do_Tab
jmp next_edit
edit_7:
cmp ax,del
jnz edit_9
mov cs:haschanged,1
call do_editdel
jmp next_edit
edit_9:
cmp ax,insert
jnz edit_a
cmp cs:insertflag,0
jz insert_1
mov cs:insertflag,0
jmp insert_2
insert_1:
mov cs:insertflag,1
mov cs:haschanged,1
insert_2:
call do_editins
jmp next_edit
edit_a:
cmp ax,pgup
jnz edit_a1
call HideCursor
call do_pgup
jmp re_editp
edit_a1:
cmp ax,pgdn
jnz edit_a2
call HideCursor
call do_pgdn
jmp re_editp
;if is Pgup/Pgdn,Scrool page first
;then do edit
edit_a2:
cmp ax,home
jnz edit_a3
call HideCursor
call do_home
jmp re_editp
edit_a3:
cmp ax,ender
jnz edit_a4
call HideCursor
call do_end
jmp re_editp
;if is Home/End,scrool page first,the edit it
edit_a4:
cmp al,20h
jae exit_b
jmp next_edit
exit_b:
cmp al,80h
jb exit_c
jmp next_edit
exit_c:
cmp cs:inasczone,0
jz edit_8
call do_editascchar
jmp next_edit
edit_8:
call do_editchar
jmp next_edit
edit_exit:
lea si,insertmess
mov cl,0
mov ch,69
mov bh,2fh
call write_str
;show the status
mov cx,0018h
mov bh,0Fh
lea si,bottom
call write_str
call HideCursor
ret
do_edit endp
;-------------------------------------------------------------
; the procedure set the correct cursor in Edit mode
;-------------------------------------------------------------
Seteditcursor proc
mov cl,byte ptr cs:currentrow
mov ch,byte ptr cs:currentcol
call setcursor
ret
seteditcursor endp
;----------------------------------------------------------------
do_editesc proc
push ds
push es
mov ax,cs:currentbuffseg
mov ds,ax
mov ax,cs:currentseg
mov es,ax
xor si,si
mov di,cs:pagerr.upl
mov cx,cs:bufferlen
cld
rep movsb
;restore the buffer with the old value
pop es
pop ds
ret
do_editesc endp
;--------------------------------------------------------------------
; The process the left key in Edit mode(either in Hex Zone or in Ascii
; Zone,and set correct cursor position)
;-------------------------------------------------------------------
do_editright proc
mov bx,cs:currentp
mov al,byte ptr cs:[bx]+colnum
cmp al,16
jnz not_line
cmp cs:inasczone,0
jnz do_hexasc
mov al,byte ptr cs:currentcol
mov ah,byte ptr cs:[bx]+hexaddrhp
cmp al,ah
jnz add_col
do_hexasc:
cmp byte ptr cs:currentrow,maxrow
jnz not_endpage
mov byte ptr cs:currentrow,minrow
jmp do_changep
;process the row range
not_endpage:
inc byte ptr cs:currentrow
jmp do_changep
not_line:
cmp word ptr cs:inasczone,1
jz add_col
mov al,byte ptr cs:currentcol
mov ah,byte ptr cs:[bx]+hexaddrlp
cmp al,ah
jnz do_changep
add_col:
cmp cs:inasczone,1
jz do_changep
inc byte ptr cs:currentcol
jmp left_set
do_changep:
mov ax,cs:[bx]+nextcolpointp
mov word ptr cs:currentp,ax
mov bx,cs:currentp
mov al,byte ptr cs:[bx+hexaddrlp]
mov byte ptr cs:currentcol,al
cmp cs:inasczone,0
jz left_set
mov al,byte ptr cs:[bx+ascaddrp]
mov byte ptr cs:currentcol,al
;set new point&new colnum
left_set:
call seteditcursor
ret
do_editright endp
;----------------------------------------------------------------------
do_editleft proc
mov bx,cs:currentp
mov al,byte ptr cs:[bx]+colnum
cmp al,1
jnz not_linel
cmp cs:inasczone,0
jnz left_hex
mov al,byte ptr cs:currentcol
mov ah,byte ptr cs:[bx]+hexaddrlp
cmp al,ah
jnz add_coll
left_hex:
cmp byte ptr cs:currentrow,minrow
jnz not_endpagel
mov byte ptr cs:currentrow,maxrow
jmp do_changepl
;process the row range
not_endpagel:
dec byte ptr cs:currentrow
jmp do_changepl
not_linel:
cmp cs:inasczone,1
jz add_coll
mov al,byte ptr cs:currentcol
mov ah,byte ptr cs:[bx]+hexaddrhp
cmp al,ah
jnz do_changepl
add_coll:
cmp cs:inasczone,1
jz do_changepl
dec byte ptr cs:currentcol
jmp left_setl
do_changepl:
mov ax,cs:[bx]+prevcolpointp
mov word ptr cs:currentp,ax
mov bx,cs:currentp
mov al,byte ptr cs:[bx+hexaddrhp]
mov byte ptr cs:currentcol,al
;set new point&new colnum
cmp cs:inasczone,0
jz left_setl
mov al,byte ptr cs:[bx+ascaddrp]
mov byte ptr cs:currentcol,al
left_setl:
call seteditcursor
ret
do_editleft endp
;----------------------------------------------------------
; The procedure process the up key in Edit mode
;----------------------------------------------------------
do_editup proc
cmp byte ptr cs:currentrow,minrow
jnz to_upzero
mov byte ptr cs:currentrow,maxrow
jmp show_editup
to_upzero:
dec byte ptr cs:currentrow
show_editup:
call seteditcursor
ret
do_editup endp
;---------------------------------------------------------------
; The procedure process the down key in Edit mode(Set correct cursor pos
;--------------------------------------------------------------
do_editdown proc
cmp byte ptr cs:currentrow,maxrow
jnz to_downzero
mov byte ptr cs:currentrow,minrow
jmp show_editdown
to_downzero:
inc byte ptr cs:currentrow
show_editdown:
call seteditcursor
ret
do_editdown endp
;-------------------------------------------------------------
; Entrance: dl-char
; OutParam: None
;------------------------------------------------------------
show_asciichar proc
cmp dl,20h
jbe to_dodot
cmp dl,80h
jae to_dodot1
jmp do_love
to_dodot1:
cmp dl,0a0h
jbe to_dodot
jmp do_love
to_dodot:
mov dl,'.'
do_love:
call write_char
ret
show_asciichar endp
;----------------------------------------------------------
; The Procedure move 1 byte every time
;----------------------------------------------------------
strmove proc
mov al,byte ptr ds:[si]
strmove1:
mov ah,byte ptr es:[di]
mov byte ptr es:[di],al
inc si
inc di
mov al,ah
loop strmove1
ret
strmove endp
;------------------------------------------------------------
; Entrance: ds-file buffer seg
; si-current offset
; OutParam: clc-ok
; stc-error
;------------------------------------------------------------
do_charinsert proc
push ax
push dx
push si
push ds
pop es
mov di,si
inc di
mov cx,word ptr cs:filelenl
sub cx,si
cld
push si
call strmove
;move buffer
pop si
cmp cs:filelenl,maxreadfile
jb do_ycg
stc
jmp insert_allexit
do_ycg:
inc cs:filelenl
mov ax,cs:filelenl
and ax,0fh
mov cs:nextchar,ax
;form the last char number
mov ax,cs:filelenl
dec ax
mov cl,4
shr ax,cl
mov cl,4
shl ax,cl
mov cs:maxoff,ax
;form the max lines
mov byte ptr ds:[si],0
call HideCursor
call redrawpager
call ShowBigCursor
clc
insert_allexit:
pop si
pop dx
pop ax
ret
do_charinsert endp
;--------------------------------------------------------------
insertnum dw 0
insertbig db 'Error: File is too big to insert a byte',0
;--------------------------------------------------------------
do_editchar proc
push ds
push ax
;al=the get char
mov cs:insertnum,2
mov ax,word ptr cs:filestartaddr
mov cl,4
shr ax,cl
mov cx,ax
mov ax,word ptr cs:scrseg
add ax,cx
mov ds,ax
;form the edit file start seg
cld
call form_editoffset
cmp ax,word ptr cs:filelenl
pop ax
jb lxflike
jmp exit_dochar
lxflike:
cmp cs:insertflag,0
jz do_overys1
mov bx,cs:currentp
mov ch,byte ptr cs:[bx+hexaddrlp]
mov byte ptr cs:currentcol,ch
call seteditcursor
;set cursor
call do_charinsert
jnc do_overys1
mov cs:haschanged,0
;clear the flag
push ds
push cs
pop ds
lea si,insertbig
mov cs:stop,1
call messagebox
call seteditcursor
pop ds
jmp exit_dochar
do_overys1:
cmp al,'0'
jae mt
jmp exit_dochar
mt:
cmp al,'9'
ja do_chare
mov cl,byte ptr cs:currentrow
mov ch,byte ptr cs:currentcol
mov bh,4eh
mov dl,al
call write_char
sub al,30h
jmp to_charstr
do_chare:
and al,0dfh
;little char change to Big char
cmp al,'F'
jbe do_lxff
cmp cs:insertflag,1
jz do_126
jmp exit_dochar
do_126:
call do_editdel
call seteditcursor
jmp exit_dochar
do_lxff:
cmp al,'A'
jae do_mtg
cmp cs:insertflag,1
jz do_127
jmp exit_dochar
do_127:
call do_editdel
call seteditcursor
jmp exit_dochar
;error exit
do_mtg:
mov cl,byte ptr cs:currentrow
mov ch,byte ptr cs:currentcol
mov bh,4eh
mov dl,al
call write_char
sub al,37h
;change char to number
to_charstr:
mov dl,al
mov bx,cs:currentp
mov cl,byte ptr cs:[bx+hexaddrl]
mov ch,byte ptr cs:currentcol
cmp cl,ch
jnz do_high
lodsb
and al,0fh
and dl,0fh
mov cl,4
shl dl,cl
and dl,0f0h
or dl,al
mov byte ptr ds:[si-1],dl
;store to buffer
jmp to_alowhigh
do_high:
lodsb
and al,0f0h
and dl,0fh
or al,dl
mov dl,al
mov byte ptr ds:[si-1],dl
;store to buffer
to_alowhigh:
mov bx,cs:currentp
mov cl,byte ptr cs:currentrow
mov ch,byte ptr cs:[bx+ascaddrp]
mov bh,4eh
call show_asciichar
;show the ascii code
call do_editright
cmp cs:insertflag,0
jz exit_dochar
dec cs:insertnum
jz exit_dochar
xor ah,ah
int 16h
dec si
jmp do_overys1
exit_dochar:
pop ds
ret
do_editchar endp
;--------------------------------------------------------------
do_editascchar proc
push ds
push ax
;al=the get char
mov ax,word ptr cs:currentseg
mov ds,ax
;form the edit file start seg
cld
call form_editoffset
cmp ax,word ptr cs:filelenl
pop ax
jae exit_doascchar
cmp cs:insertflag,0
jz do_xidian
call do_charinsert
jnc do_xidian
mov cs:haschanged,0
;clear the flag
push ds
push cs
pop ds
lea si,insertbig
mov cs:stop,1
call messagebox
call seteditcursor
pop ds
jmp exit_doascchar
do_xidian:
cmp al,20h
jae do_123
call do_editdel
jb exit_doascchar
do_123:
cmp al,80h
jb do_124
call do_editdel
jmp exit_doascchar
do_124:
mov cl,byte ptr cs:currentrow
mov ch,byte ptr cs:currentcol
mov bh,4eh
mov dl,al
push si
call write_char
;disp al in ascii zone
mov bx,cs:currentp
mov ch,byte ptr cs:[bx+hexaddrl]
mov cl,byte ptr cs:currentrow
mov bh,4eh
call dispchar
;disp al in hex zone
pop si
mov byte ptr ds:[si],al
;store to buffer
call do_editright
exit_doascchar:
pop ds
ret
do_editascchar endp
;-------------------------------------------------------
; Entrance: None
; OutParam: si=offset
;-----------------------------------------------------
form_editoffset proc
mov bx,cs:currentp
mov al,byte ptr cs:currentrow
sub al,2
mov cl,10h
mul cl
mov cl,byte ptr cs:[bx+colnump]
dec cl
xor ch,ch
add ax,cx
mov cx,word ptr cs:pagerr.upl
add ax,cx
mov si,ax
;ax=the file offset
ret
form_editoffset endp
;----------------------------------------------------------
do_editdel proc
push es
push ds
mov ax,word ptr cs:currentseg
mov ds,ax
;form the edit file start seg
call form_editoffset
cmp ax,cs:filelenl
jae exit_del
push ds
pop es
mov di,si
inc si
mov cx,cs:filelenl
sub cx,ax
;cx=len
rep movsb
dec cs:filelenl
mov ax,cs:filelenl
and ax,0fh
mov cs:nextchar,ax
;form the new last char number
mov ax,cs:filelenl
dec ax
and ax,0fff0h
mov cs:maxoff,ax
;form the maxlines
mov cs:haschanged,1
mov ax,cs:pagerr.upl
add ax,160h
cmp ax,cs:filelenl
jbe not_clrscr
;if is in last page,clear the screen
mov bh,byte ptr cs:dispcolor
call clr_win
;clear the window
not_clrscr:
call HideCursor
call redrawpager
;redraw the screen
call seteditcursor
exit_del:
pop ds
pop es
ret
do_editdel endp
;-----------------------------------------------------------
handle1 dw 0
saveErrormsg db 'Error: Save the File Error ..',0
;---------------------------------------------------------
do_Enter proc
push cs
pop ds
lea dx,newfile
mov ah,3ch
mov cx,0
int 21h
jnc sldf
lea si,saveErrormsg
jmp over_now2
sldf:
mov bx,ax
mov cs:handle1,ax
call CopyOldFile
;copy the old file
mov bx,cs:handle
;bx=the edit file
;------------------
mov ax,4200h
mov cx,cs:seekh
mov dx,cs:seekl
int 21h
;seek to file postion
mov ax,cs:currentseg
mov ds,ax
xor dx,dx
mov cx,word ptr cs:filelenl
mov ah,40h
int 21h
;write the current buffer to the file
lea si,newfilemess
jnc ok_enter
lea si,saveErrormsg
ok_enter:
push si
mov ah,40h
xor cx,cx
int 21h
;Cut the file end
cmp byte ptr cs:over64k,1
jnz over_now
;test file is over 64k or not
;if over 64k ,copy the last file to save
mov bp,cs:handle
mov ax,cs:writebufferseg
mov ds,ax
;form the write buffer seg
mov bx,cs:handle1
mov ax,4200h
xor Dx,cs:nextseekl
xor Cx,cs:nextseekh
int 21h
;seek the backup file correct offset
xor dx,dx
;the writebuffer offset =0
loop_copyv:
mov cx,4096
mov ah,3fh
int 21h
jc over_now1
;read the backup file
cmp ax,0
jz over_now
push bx
mov bx,bp
mov cx,ax
mov ah,40h
int 21h
pop bx
;write the data
jc over_now1
jmp loop_copyv
over_now1:
pop si
lea si,saveErrormsg
jmp over_now2
;error exit
over_now:
pop si
over_now2:
push cs
pop ds
mov cs:stop,1
call messagebox
;show the ok / error msg
call redrawpager
;re-draw the page
exit_ENter:
;------ Exchange the File Handle
mov bx,cs:handle1
mov ah,3eh
int 21h
;close the file 'yh.lxf'
mov cs:handle1,0
;clear the handle value
call seteditcursor
ret
do_enter endp
;---------------------------------------------------------
; Entrance:bx-new file handle
; OutParam:clc-ok
; stc-error
;----------------------------------------------------------
WriteBufferSeg dw 0
;---------------------------------------------------------
CopyOldFile proc
push ds
mov bp,bx
mov ax,cs:writebufferseg
mov ds,ax
;form the write buffer seg
mov bx,cs:handle
mov ax,4200h
xor cx,cx
xor dx,dx
int 21h
xor dx,dx
loop_copy:
mov cx,4096
mov ah,3fh
int 21h
jc error_exitcopy
cmp ax,0
jz exit_copy
push bx
mov bx,bp
mov cx,ax
mov ah,40h
int 21h
pop bx
jc error_exitcopy
jmp loop_copy
exit_copy:
; mov ah,3eh
; int 21h
;close the old file
mov bx,bp
mov ax,4200h
xor cx,cx
xor dx,dx
int 21h
;seek the new file head
clc
pop ds
ret
error_exitcopy:
; mov ah,3eh
; int 21h
;close the old file
stc
pop ds
ret
CopyOldFile endp
;-----------------------------------------------------------------
do_tab proc
mov bx,cs:currentp
cmp cs:inasczone,0
jnz do_asc
mov al,byte ptr cs:[bx+hexaddrlp]
jmp do_lxf0
do_asc:
mov al,byte ptr cs:[bx+ascaddrp]
do_lxf0:
mov byte ptr cs:currentcol,al
call seteditcursor
ret
do_tab endp
;---------------------------------------------------------------
insertflag dw 0
;--------------------------------------------------------------
do_editins proc
mov cl,0
mov ch,69
lea si,insmess
cmp cs:insertflag,1
jnz over_mess
mov bh,4eh
jmp mess_show
over_mess:
mov bh,20h
lea si,overmess
mess_show:
call write_str
call seteditcursor
ret
do_editins endp
;-------------------------------------------------------------
ColorTable db 07H,07h,0EH,0AH,0BH,0CH,0DH,0FH,10h,12H,13H
DB 14H,15H,16H,1AH,1EH,1CH,1DH
DB 1FH,31h,32h,30H,31h,34H,35H,36H,37H,3AH,3BH,3CH,3DH
DB 3EH,3FH,30h
DB 40h,41h,42h,43h,45H,46H,47H,4AH,4BH,4CH,4DH,4FH,50H
DB 51h,52h,53h,54h,56H,57H,5AH,5BH,5CH,5DH,5EH,5FH
db 60H,61h,62h,63h,64h,65h,67H,6AH,6BH
DB 6CH,6DH,6EH,6FH,70H,0
COLORP DB 0
;-----------------------------------------------------------
Do_F5 proc
call ChangeColor
jmp get_colorp
;--------------------------------------------------------/
; outparam: al=color
;--------------------------------------------------------
ChangeColor:
inc byte ptr cs:colorp
F5_1:
mov al,byte ptr cs:colorp
lea si,colortable
xor ah,ah
add si,ax
mov al,byte ptr cs:[si]
cmp al,0
jnz change_color
mov byte ptr cs:colorp,0
jmp f5_1
change_color:
ret
get_colorp:
mov byte ptr cs:dispcolor,al
;change disp color
call redrawpager
; mov cx,0a02h
; mov ax,cs:pagerr.upl
; mov cs:pagerr.downl,ax
; call disppage
;redraw current page
ret
do_f5 endp
;--------------------------------------------------------------------
keymess0 db 'Please press the key to get Value',0
keymess1 db 'The key Value (HEX) is: ',0
keyval dw 0
;------------------------------------------------------------------
do_F9 proc
push ds
push es
mov bh,4eh
mov cs:stop,0
lea bx,key_press
lea si,keymess0
call messagebox
;show press key
jmp key_press1
key_press:
xor ah,ah
int 16h
mov cs:keyval,ax
ret
;get key
key_press1:
lea si,keymess1
mov cs:stop,0
lea bx,keypress2
call messagebox
jmp keypress3
keypress2:
mov ax,cs:keyval
mov bh,4eh
mov cx,250bh
call dispword
xor ah,ah
int 16h
;press any key
ret
keypress3:
pop es
pop ds
ret
do_F9 endp
;--------------------------------------------------------------------
F8mess1 db 'Hex Value :',0
F8mess2 db 'Ascii Value:',0
f8sta0 db 'Hex Mode',0
f8sta1 db 'Ascii Mode',0
dohelp db 'Help: Any Key Change Mode... Enter = Continue..'
db ' |(C)YuHuan ',0
dohelp1 db '(C)Copyright Yuhuan, Enter=Go Search'
db ',Other Key=Search Value,MaxChar=16 ',0
notfindmess db ' The string can not find more... Press'
db ' any key to continue... ',0
putin db 'Input a Byte: ',0
F8Asc db 0
addrasc db 16
hexHea db 17
db ?
hexvalue db 18 dup(0)
valnum db 0
findnext db 'Any Key to Find the next item,.....Esc=Exit the '
db 'find...... >> ',0
f88 db 0
CaseMsg db 'Search Case-Sensitive: <y/n>',0
CaseF db 0
FindOffset dw 0
;------------------------------------------------------------------
Do_F8 proc
push ds
push es
call save_scr
mov si,offset f8mess1
mov di,offset putin
call chkcode
xor al,al
; mov cl,24
; mov ch,0
; mov bh,4eh
; call dispword
; xor ax,ax
; int 16h
; debug
; diaply the check code
sub ah,0d3h
cli
mov bx,ss
add bx,ax
; mov ss,bx ; This code can halt the system!!!
sti
;Test the message has change or not
;Untrace the hacker (********)
mov bh,1fh
call clrscr
;clear the screen
mov byte ptr cs:f8asc,1
mov byte ptr cs:addrasc,16
mov byte ptr cs:valnum,0
;Init the Flag value
push cs
pop ds
push cs
pop es
;init the segment register
mov cl,24
mov ch,0
mov bh,17h
lea si,dohelp
call write_str
lea si,f8sta1
mov cx,2501h
mov bh,4eh
call Write_str
;show the ascii/hex mode msg
abc2:
xor ah,ah
int 16h
;test change to ascii zone or not
mov cx,2501h
cmp ax,enterchar
jz next_f8
cmp byte ptr cs:f8asc,0
jz abc1
mov byte ptr cs:f8asc,0
lea si,f8sta0
call Write_str
jmp abc2
abc1:
mov byte ptr cs:f8asc,1
lea si,f8sta1
call Write_str
jmp abc2
;get the mode
next_f8:
lea si,dohelp1
mov cl,24
mov ch,0
mov bh,2fh
call write_str
mov bh,1eh
lea si,f8mess1
mov cx,0305h
call write_str
lea si,f8mess2
mov cx,0307h
call write_str
;show message
lea di,hexvalue
cld
cmp byte ptr cs:f8asc,1
jnz f8_1@
;do ascii
loop_f81:
mov cl,7
mov ch,byte ptr cs:addrasc
call setcursor
;Set the Cursor
lea dx,hexHea
call Get_str
mov cl,byte ptr cs:[hexHea+1]
mov byte ptr cs:valnum,cl
or cl,cl
jz to_jmpsta
lea si,hexHea
add si,2
xor ch,ch
add si,cx
mov byte ptr cs:[si],0
to_jmpsta:
;get ascii value to search
mov byte ptr cs:CaseF,0
mov cx,0309h
lea si,CaseMsg
mov bh,1eh
call Write_str
mov ah,0
int 16h
and al,0dfh
cmp al,'N'
jnz Not_case
lea si,HexHea
inc si
mov byte ptr cs:cAseF,1
;set the case flag
loop_case:
inc si
mov al,byte ptr cs:[si]
or al,al
jz not_case
cmp al,'a'
jb loop_case
cmp al,'z'
ja loop_case
and al,0dfh
mov byte ptr cs:[si],al
jmp loop_case
;Change the small to big char
not_case:
jmp f8_stasearch
; cmp al,0dh
; jnz abh
; jmp F8_stasearch
; abh:
; cmp al,20h
; jb loop_f81
; cmp al,80h
; jae loop_f81
; ;if =enter,exit to search
; ascstt:
; push ax
; mov ah,0eh
; mov bx,3
; int 10h
; pop ax
; ;show ascii
; stosb
; mov bh,07h
; mov cl,5
; call dispchar
; add byte ptr cs:addrasc,3
; inc byte ptr cs:valnum
; cmp byte ptr cs:valnum,16
; jae f8_stasearch
; ;max number=16
; jmp loop_f81
f8_1@:
;do hex
mov cl,15
mov ch,9
lea si,putin
mov bh,1eh
call write_str
mov ch,17h
call setcursor
mov byte ptr cs:segg,3
push di
call getnum
pop di
jc f8_stasearch
cmp byte ptr cs:nocharflag,1
jz f8_stasearch
stosb
mov bh,07h
mov cl,5
mov ch,byte ptr cs:addrasc
call dispchar
mov cl,7
cmp al,20h
ja f8_2@
mov al,'.'
jmp f8_3@
f8_2@:
cmp al,80h
jb f8_3@
mov al,'.'
f8_3@:
call setcursor
mov ah,0eh
mov bx,3
int 10h
;show hex
add byte ptr cs:addrasc,3
inc byte ptr cs:valnum
cmp byte ptr cs:valnum,16
jae f8_stasearch
;max num=16
jmp f8_1@
f8_stasearch:
cmp byte ptr cs:f8asc,1
jz f8_aa
mov byte ptr cs:segg,5
;restore the old val.
f8_aa:
mov cl,byte ptr cs:valnum
xor ch,ch
mov cx,cs:filelenl
xor di,di
mov ax,cs:currentseg
mov es,ax
last_find:
lea si,hexvalue
xor dx,dx
loop_cmp:
mov al,byte ptr es:[DI]
cmp byte ptr cs:[casef],0
jz next_case
cmp al,'a'
jb next_case
cmp al,'z'
ja next_case
and al,0dfh
;test al is ascii char or not
;if is char and is small char
;change it to big now
next_case:
mov ah,byte ptr cs:[si]
cmp al,ah
jnz not_lop
inc si
inc di
inc dx
cmp dl,byte ptr cs:valnum
jz ok_find
loop loop_cmp
not_lop:
lea si,hexvalue
sub di,dx
inc di
add cx,dx
xor dx,dx
loop loop_cmp
;not find
mov cl,24
mov ch,0
mov bh,70h
lea si,notfindmess
call write_str
;show not find message
xor ah,ah
int 16h
call pop_scr
jmp exit_f8
ok_find:
xor dh,dh
mov ax,di
sub ax,dx
mov word ptr cs:FindOffset,ax
; Save the find offset,YuHuan,2001-04-15,BeiJing.
call pop_scr
mov ax,di
sub ax,dx
mov cs:pagerr.upl,ax
push di
push cx
mov byte ptr cs:f88,1
call redrawpager
mov byte ptr cs:f88,0
pop cx
pop di
or cx,cx
jz exit_f8
cmp byte ptr cs:atlastf,1
jz to_do_atlast
push cx
push di
lea si,findnext
mov cl,24
mov ch,0
mov bh,4eh
call write_str
;show new bottom message
mov cl,24
mov ch,72
mov cs:tofilef,0
mov ax,word ptr cs:FindOffset
; dec ax
mov bh,4eh
call dispword
; show the find offset,YuHuan,2001-04-15,BeiJing
pop di
pop cx
to_do_atlast:
xor ah,ah
int 16h
cmp ax,escape
jz exit_f8
;esc=exit find
call save_scr
jmp last_find
;find next item
exit_f8:
mov cx,0018h
mov bh,0Fh
lea si,bottom
call write_str
;show old bottom message
pop es
pop ds
ret
do_f8 endp
;-----------------------------------------------------------------
; The procedure show the Exit Message
;----------------------------------------------------------------
Exit_message proc
; mov bh,17h
; call clrscr
; mov cs:stop,1
; lea si,copy
; call messagebox
mov ah,6
mov al,1
mov bh,07h
mov ch,24
mov cl,0
mov dh,24
mov dl,79
int 10h
mov cl,24
mov ch,0
call setcursor
mov cl,24
mov ch,0
mov bh,07h
lea si,copy1
call write_str
; show the message first
mov ch,32
lea si,yc
mov bh,0fh
call write_str
; show the copyright
mov ch,52
lea si,yi
mov bh,07h
call write_str
; show the message end
ret
Exit_message endp
;------------------------------------------------------------------
; Entrance: bh-Attri
;-----------------------------------------------------------------
Clr_win proc
mov ah,6
mov al,22
; mov bh,17h
mov cx,0200h
mov dh,23
mov dl,78
int 10h
;scrool the window
ret
Clr_Win endp
;-------------------------------------------------------------------
; Entrance: Ds:dx-offset
;-------------------------------------------------------------------
ccol db 0
crow db 0
;------------------------------------------------------------------
Get_str proc
pushall
push ds
pop es
mov di,dx
mov si,dx
add di,2
mov byte ptr ds:[si+1],0
cld
str_loop:
xor ah,ah
int 16h
cmp al,0dh
jnz str1
stosb
clc
jmp exit_str
str1:
cmp ax,escape
jz do_esct
cmp al,8
jz do_backsp
cmp al,20h
jb str_loop
cmp al,80h
jae str_loop
mov ah,byte ptr ds:[si]
dec ah
cmp ah,byte ptr ds:[si+1]
jbe str_loop
;wait for enter
stosb
mov ah,0eh
mov bx,3
int 10h
inc byte ptr ds:[si+1]
mov ah,3
int 10h
mov byte ptr cs:crow,dh
mov byte ptr cs:ccol,dl
;get cursor position
jmp str_loop
do_backsp:
cmp byte ptr ds:[si+1],0
jbe str_loop
mov dh,byte ptr cs:crow
mov dl,byte ptr cs:ccol
dec dl
mov ah,2
mov bx,3
int 10h
mov ah,0eh
mov al,20h
int 10h
mov dl,byte ptr cs:ccol
dec dl
mov ah,2
int 10h
dec di
dec byte ptr ds:[si+1]
dec byte ptr cs:ccol
jmp str_loop
do_esct:
stc
mov byte ptr ds:[si+1],0
;do esc
exit_str:
popall
ret
get_str endp
;------------------------------------------------------------------
f3mess0 db 'Please input Load file name:',0
f3mess db 'Error: Load file is not successfully..',0
f3mess1 db 'Load--(Overwrite/Insert): ',0
f3mess2 db 'Insert File now,please Wait..',0
f3Len dw 0
;------------------------------------------------------------------
do_f3 proc
pushall
; mov bh,1fh
; call clr_win
;clear the windows
mov bp,8
call DrawShadow
;draw the windows with shadow
mov cl,09h
lea si,offst1
mov bp,2
mov ch,07h
mov bh,MessageBoxColor
call write_str
mov ch,37
call setcursor
call getnum
;get the offset
jnc f3_4
jmp exit_f3
f3_4:
mov cs:off1,ax
;Get offset
cmp ax,0fe00h
jb f3_6
jmp exit_f3
;offset must < 0fe00h
f3_6:
push cs
pop ds
mov cl,0bh
lea si,f3mess0
mov ch,07h
mov bh,MessageBoxColor
call write_str
mov ch,37
call setcursor
push cs
pop ds
lea dx,f10file
mov si,dx
call Get_str
cmp byte ptr cs:[si+1],0
jnz f3_5
jmp exit_f3
;get the file name
f3_5:
mov cl,byte ptr cs:[si+1]
add si,2
xor ch,ch
add si,cx
mov byte ptr cs:[si],0
mov ax,3d00h
lea dx,f10file
add dx,2
mov cx,0
int 21h
jnc f3_9
jmp exit_f3
f3_9:
;Open file
mov bx,ax
mov ax,4202h
xor cx,cx
xor dx,dx
int 21h
;get the file length
OR DX,DX
JNZ F3_L
mov bp,ax
cmp ax,0d000h
jbe f3_1
F3_L:
mov bp,0d000h
f3_1:
;read max=0fe00h bytes
mov ax,4200h
xor cx,cx
xor dx,dx
int 21h
mov cx,bp
mov ax,cs:writebufferseg
mov ds,ax
xor dx,dx
mov ah,3fh
int 21h
jnc f3_8
jmp exit_f3
f3_8:
mov cx,ax
mov cs:f3Len,ax
mov ah,3eh
int 21h
;close the file
push cs
pop ds
mov cl,0ch
lea si,f3mess1
mov ch,07h
mov bh,MessageBoxColor
call write_str
;disp insert/overwirte message
mov ch,45
call setcursor
to_fk:
xor ah,ah
int 16h
cmp ax,escape
jnz f3_ab
jmp exit_f31
f3_ab:
and al,0dfh
cmp al,'O'
jnz f3_g
jmp do_f3O
f3_g:
cmp al,'I'
jnz to_fk
;do Insert mode
push cs
pop ds
mov cl,0dh
lea si,f3mess2
mov ch,07h
mov bh,02fh
call write_str
;disp wait message
mov ax,cs:f3Len
mov cx,cs:off1
add ax,cx
cmp ax,0fe00h
jbe f3_c
jmp exit_f3
f3_c:
mov ax,cs:off1
mov cx,cs:filelenl
cmp ax,cx
jbe f3_d
mov cx,cs:f3Len
add ax,cx
cmp ax,0fe00h
jbe f3_f
mov ax,0fe00h
f3_f:
mov cs:filelenl,ax
jmp do_f3O
f3_d:
mov ax,cs:filelenl
mov cx,cs:f3Len
add ax,cx
mov cs:filelenl,ax
;form the new len
cmp ax,0fe00h
jbe f3_a
mov cs:filelenl,0fe00h
f3_a:
cld
mov si,cs:off1
mov di,si
inc di
mov ax,cs:currentseg
mov ds,ax
mov es,ax
mov bp,cs:F3LEN
mov cx,cs:filelenl
sub cx,si
f3_b:
push si
push di
push cx
call strmove
pop cx
pop di
pop si
inc si
inc di
pushall
mov ax,bp
mov bh,MessageBoxColor
mov cx,300dh
call dispword
popall
;disp the move bytes
dec bp
jnz f3_b
;move date for more room
call overwritedo
jmp f3_2
do_f3O:
;do Overwrite mode
call overwritedo
jmp f3@
overwritedo:
mov ax,cs:writebufferseg
mov ds,ax
xor si,si
mov cx,cs:f3Len
mov ax,cs:currentseg
mov es,ax
mov di,cs:off1
cld
rep movsb
;move the buffer date
ret
f3@:
mov ax,cs:off1
add ax,word ptr cs:f3Len
cmp ax,cs:filelenl
jbe f3_2
mov cs:filelenl,ax
cmp ax,0fe00h
jbe f3_2
mov cs:filelenl,0fe00h
f3_2:
mov ax,cs:filelenl
and ax,0fh
mov cs:nextchar,ax
;form the new last char number
mov ax,cs:filelenl
dec ax
mov cl,4
shr ax,cl
mov cl,4
shl ax,cl
mov cs:maxoff,ax
;form the maxlines
jmp exit_f31
exit_f3:
mov cs:stop,1
lea si,f3mess
call messagebox
exit_f31:
mov bh,1fh
call clr_win
;clear the windows
mov cs:pagerr.upl,0
call redrawpager
popall
ret
do_f3 endp
;-------------------------------------------------------------------
; Entrance: si--start offset,di-End offset
; Outparam: ah=checkcode
;------------------------------------------------------------------
ChkCode proc
mov ah,0
mov cx,di
sub cx,si
chksum:
mov al,byte ptr cs:[si]
add ah,al
inc si
loop chksum
;Get Checksum
ret
ChkCode endp
;;-----------------------------------------------------------------
; The procedure dare the background of windows
; Entrance: cl-x
; ch-y
; bp=total lines
; Outparam: None
;-----------------------------------------------------------------
Draw_back proc
mov ch,byte ptr cs:ScrStartpos
to_dispachar:
push cx
call Get_CharAttri
mov bh,byte ptr cs:getcolor
; and bh,0Fh
mov bh,01h
mov dl,byte ptr cs:getchar
call Write_char
pop cx
inc ch
cmp ch,77
jnz to_dispachar
inc cl
dec bp
jnz draw_back
ret
Draw_back endp
;;-----------------------------------------------------------------
; The procedure dare the foreground of windows
; Entrance: cl-x
; ch-y
; bp=total lines
; bh=color
; Outparam: None
;-----------------------------------------------------------------
Draw_Fore proc
lea si,datewinspace
mov ch,byte ptr cs:ScrStartpos
push cx
call write_str
pop cx
inc cl
dec bp
jnz draw_fore
ret
Draw_Fore endp
;------------------------------------------------------------------
ScrStartpos db 0
;-----------------------------------------------------------------
; The procedure draw the windows with shadow
; Entrance: bp= loop lines
; Outparam: None
;----------------------------------------------------------------
DrawShadow proc
mov cl,9
; mov bh,07h
mov byte ptr cs:scrstartpos,7
push bp
call Draw_back
pop bp
;draw bakcground
mov cl,8
mov bh,30h
;the color
mov byte ptr cs:scrstartpos,5
call draw_fore
;draw foreground
ret
DrawShadow endp
;------------------------------------------------------------------
E241 db 'Disk write protected',0
E242 db 'Unknow Unit',0
E243 db 'Disk is not ready',0
E244 db 'Unrecognize command',0
E245 db 'Bad CRC',0
E246 db 'Required Struct Error',0
E247 db 'Search Error',0
E248 db 'Invalid Media type',0
E249 db 'Sector not found',0
E240 db 'Out of Paper',0
E24A db 'Write disk error',0
E24B db 'Read disk error',0
E24C db 'General error',0
E24D db 'Invalid change disk',0
E24O dw offset E241
dw offset E242
dw offset E243
dw offset E244
dw offset E245
dw offset E246
dw offset E247
dw offset E248
dw offset E249
dw offset E24A
dw offset E24B
dw offset E24C
dw 0
dw 0
dw offset E24D
dw 0
laster db 0ffh
disper db 0
;-------------------------------------------------------------------
; The procedure process the int 24h of dos
;-------------------------------------------------------------------
new24h proc
lea si,E24O
mov bx,di
xor bh,bh
cmp byte ptr cs:laster,bl
jz to_dispornot
mov byte ptr cs:laster,bl
jmp to_diso
to_dispornot:
cmp byte ptr cs:disper,0
jz to_diso
jmp not_disp24
to_diso:
mov byte ptr cs:disper,1
shl bx,1
mov si,word ptr cs:[bx+si]
or si,si
jz not_disp24
push cs
pop ds
mov cs:stop,1
call messagebox
not_disp24:
mov al,3
;Call error....return code
iret
new24h endp
;-------------------------------------------------------------------/
Get_commandline proc
cmp byte ptr ds:[80h],0
jz get_commandexit
push cs
pop es
mov di,offset file
mov cl,byte ptr ds:[80h]
mov byte ptr es:[di+1],cl
add di,2
cld
mov si,81h
loop_commandline:
lodsb
cmp al,0dh
jz to_cend
cmp al,20h
jz loop_commandline
cmp al,09h
jz loop_commandline
stosb
jmp loop_commandline
to_cend:
mov al,0
stosb
mov byte ptr cs:commandline,1
get_commandexit:
ret
Get_commandline endp
;---------------------------------------------------------------------
Asciimess db ' The Ascii Chart,(c) Copyright YuHuan & LXF',0
AsciiHead db ' 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F ',0
AsciiBuffer db 0,0
AsciiRow db 0
AsciiCol db 0
;---------------------------------------------------------------------
ShowAscii proc
pushall
call Save_Scr
mov bp,20
mov cl,4
mov byte ptr cs:scrstartpos,7
push bp
call Draw_back
pop bp
;draw bakcground
mov cl,3
mov bh,70h
;the color
mov byte ptr cs:scrstartpos,5
call draw_fore
;draw foreground
; Draw the windows with Shadow
lea si,AsciiMess
mov bh,74h
mov cl,4
mov ch,18
call Write_str
; show copyright
lea si,AsciiHead
mov bh,71h
mov cl,5
mov ch,15
call Write_Str
; draw the ascii head
mov cx,0
mov bp,0
mov byte ptr cs:ToFileF,0
mov byte ptr cs:AsciiRow,6
mov Byte ptr cs:AsciiCol,16
mov byte ptr cs:Asciibuffer,0
loopascii:
mov al,byte ptr cs:AsciiRow
sub al,6
push cx
mov cl,4
rol al,cl
mov ch,13
mov cl,byte ptr cs:AsciiRow
mov bh,71h
call DispChar
pop cx
; show the other header of row
loopascii1:
mov si,offset AsciiBuffer
mov byte ptr cs:[si+1],0
mov bh,70h
push cx
mov cl,byte ptr cs:AsciiRow
mov ch,byte ptr cs:AsciiCol
call Write_Str
inc byte ptr cs:AsciiBuffer
add byte ptr cs:AsciiCol,3
pop cx
inc cx
inc bp
cmp cx,255
ja exit_ascii
cmp bp,15
jbe loopascii1
inc byte ptr cs:AsciiRow
mov byte ptr cs:AsciiCol,16
xor bp,bp
jmp loopascii
exit_ascii:
xor ah,ah
int 16h
call Pop_Scr
popall
ret
ShowAscii endp
;--------------------------------------------------------------------
EncryMess db 'Formula(+/-/^/</>/~/&/|) :',0
EncryCharMess db 'Input Char to Encrypted :',0
EncryLen dw 0
EncryChar db 0
;-----------------------------------------------------------------
; The procedure to process the Encrypt the block
;-----------------------------------------------------------------
Do_Encrypt proc
pushall
call Get_TwoOffset
jnc encry@4
jmp exit_fill
encry@4:
inc cx
mov cs:EncryLen,cx
; get the length
call Test_para
jnc encry@11
jmp exit_encry
; test the offset is valid or not
encry@11:
mov cl,0bh
lea si,EncryCharMess
mov ch,0bh
mov bh,MessageBoxColor
call write_str
mov ch,37
call setcursor
mov byte ptr cs:segg,3
call getnum
mov byte ptr cs:segg,5
jnc encry@12
jmp exit_encry
;get char
encry@12:
mov byte ptr cs:EncryChar,al
; get the encrypt char
mov cl,0ch
lea si,EncryMess
mov ch,0bh
mov bh,MessageBoxColor
call write_str
; show function message
mov si,cs:off1
mov dx,cs:currentseg
mov ds,dx
mov dl,byte ptr cs:EncryChar
mov cx,cs:EncryLen
encry@3:
push si
push cx
push dx
push ds
xor ah,ah
int 16h
pop ds
pop dx
pop cx
pop si
cmp ax,escape
jnz en@7
jmp exit_encry
en@7:
cmp al,'^'
jz to_xor
cmp al,'+'
jz to_add
cmp al,'-'
jz to_sub
cmp al,'>'
jz to_shiftr
cmp al,'<'
jz to_shiftl
cmp al,'~'
jz to_not
cmp al,'&'
jz to_and
cmp al,'|'
jz to_or
jmp encry@3
; process the key
to_not:
lodsb
not al
mov byte ptr ds:[si-1],al
loop to_not
jmp exit_encry
to_and:
lodsb
and al,dl
mov byte ptr ds:[si-1],al
loop to_and
jmp exit_encry
to_or:
lodsb
or al,dl
mov byte ptr ds:[si-1],al
loop to_or
jmp exit_encry
to_xor:
lodsb
xor al,dl
mov byte ptr ds:[si-1],al
loop to_xor
jmp exit_encry
to_add:
lodsb
add al,dl
mov byte ptr ds:[si-1],al
loop to_add
jmp exit_encry
to_sub:
lodsb
sub al,dl
mov byte ptr ds:[si-1],al
loop to_sub
jmp exit_encry
to_shiftl:
lodsb
push cx
mov cl,dl
rol al,cl
pop cx
mov byte ptr ds:[si-1],al
loop to_shiftl
jmp exit_encry
to_shiftr:
lodsb
push cx
mov cl,dl
ror al,cl
pop cx
mov byte ptr ds:[si-1],al
loop to_shiftr
jmp exit_encry
exit_encry:
mov bh,byte ptr cs:dispcolor
call clr_win
;clear the window
call redrawpager
popall
ret
Do_Encrypt endp
;---------------------------------------------------------------------
nofile db 'Error: The file is not exist...',0
filerror db 'Error: The BinEdit File has been changed..',0dh,0ah,24h
maxmem dw 0
reeditmess db 'Do you want to Edit next block <y/n>:',0
;----------------------------------------------------------
filelenall equ $
psp dw 0
reeditf dw 0
over64k db 0
commandline db 0
old24h dw 0
dw 0
EndFlag db 'FFF888',0
;---------------------------------------------------------
DEncryLen equ $- offset filename
;---------------------------------------------------------
BEGIN:
push es
mov bx,word ptr es:[2ch]
mov es,bx
mov ah,49h
int 21h
pop es
; free the env.
;---------------------------
mov byte ptr cs:commandline,0
push es
call get_commandline
pop es
;get command line
mov ax,ds
mov cs:psp,ax
;ax=psp
mov byte ptr cs:isInScrBuffer,0
;set flag,to write char to video buffer
;not in memory buffer
mov byte ptr cs:saveinmess,1
;save the screen in messagebox proc
sub ax,1
mov ds,ax
mov ax,word ptr ds:[3]
sub ax,500h
mov word ptr cs:maxmem,ax
;Get Max Memory Size
push cs
pop ds
push cs
pop es
cli
push cs
pop ss
lea si,all
add si,1024
mov sp,si
sti
xor ax,ax
push ax
;clear the stack
mov si,offset helpmess0
mov di,offset helpaddr
call ChkCode
mov ax,3524h
int 21h
mov cs:old24h,bx
mov cs:old24h+2,es
;Get old int 24h
push cs
pop ds
lea dx,new24h
mov ax,2524h
int 21h
;set new int 24h
call ReAllocMem
mov bh,10h
call TestMonitor
; do_reedit:
cmp byte ptr cs:commandline,1
jz re_edit
;if has command line,edit the commandline file
mov ah,09h
push cs
pop ds
lea dx,filename
int 21h
;input filename message
mov ah,0ah
lea dx,file
mov si,dx
; int 21h
call get_str
mov cl,byte ptr cs:[file+1]
add si,2
xor ch,ch
add si,cx
mov byte ptr cs:[si],0
;Get file name
re_edit:
mov bh,07h
call clrscr
lea dx,file
add dx,2
call TestIsBinOrNot
jnc do_nextbin
lea si,nofile
mov cs:stop,1
call messagebox
jmp main_ex
do_nextbin:
call Do_Bin
;do the main loop
Main_ex:
mov cx,2
mov bx,cs:handle
aabbcc:
cmp bx,0
jb exit_nowall
mov ah,3eh
int 21h
mov bx,cs:handle1
loop aabbcc
;close the file
exit_nowall:
to_yhexit:
call Exit_message
;show exit message
call ShowCursor
;show cursor now
xor ax,ax
mov es,ax
mov ax,cs:old24h
mov word ptr es:[4*24h],ax
mov ax,cs:old24h+2
mov word ptr es:[4*24h+2],ax
;set old int 24h
push cs
pop ds
lea dx,file
add dx,2
mov ax,4301h
mov cx,cs:fileAttr
cmp cx,20h
jz not_exch
int 21h
;Set the old file attribute
not_exch:
mov ax,4c00h
int 21h
;------------------------------------------------------------------
All: db 0
end start
;-----------------------------------------------------------------------
编译:
tasm be.asm;
tlink -t be.com;
; The ASM source code for BinEdit program.
; be.asm
;---------------------------------------------------------------------------]
; (c) Copyright YuHuan
; (r) All rights reserved
;
; Date: 1996,6
; Release: Version 1.07
; e-mail : yu.huan@263.net
;---------------------------------------------------------------------------]
; Notes:
; (1) : Add to show the Ascii Chart for 'A' command
; data: 1997/04/01,YuHuan
; (2) : Add to Encrypt the buffer,for '~'=Not,'&'=And,'|'=Or
; '+'=Add,'-'=Sub,'^'=Xor,'<'=Shift left,'>'=Shift right.
; data: 1997/04/03,YuHuan
; (3) : Add to Encrypt the all code for undebug,when 'be'
; is running,unEncrypted by itself.
; So,when I compile the program,I must use the 'be'
; to Encrypt the code,from 'filename' to 'EndFlag'
; else,the program will halt.
; data: 1997/04/11, YuHuan
; (4) : Find a error when read a file from the CD-ROM,(show 'the file '
; is not exist',and exit),I correct it in procedure "TestisBinOr
; Not'.
; data: 1997/05/06, YuHuan
; (5) : Find a bug when press Enter to save the file to 'yh.lxf'
; When creat file error,the program can not show any message.
; data: 1997/05/06, YuHuan
; (6) : I change the display color in area 'XXXX:XXXX'
; data: 1997/05/06, YuHuan
;===========================================================================]
EncryptFlag equ 0
; YuHuan,1997/04/11
;--------------------------------------------------------------------------]
PUSHALL MACRO
PUSH AX
PUSH BX
PUSH CX
PUSH DX
PUSH DS
PUSH ES
PUSH SI
PUSH DI
PUSH BP
ENDM
POPALL MACRO
POP BP
POP DI
POP SI
POP ES
POP DS
POP DX
POP CX
POP BX
POP AX
ENDM
;---------------------------------------------------------------
.model small
.code
org 100h
;----------------------------------------------------------------------
up equ 4800h
down equ 5000h
left equ 4b00h
right equ 4d00h
pgdn equ 5100h
pgup equ 4900h
escape equ 011bh
F3 equ 3d00h
F1 equ 3b00h
F6 equ 4000h
F2 equ 3C00h
F4 equ 3E00h
F5 equ 3F00h
F7 equ 4100h
F8 equ 4200h
F9 equ 4300h
F10 equ 4400h
Home equ 4700h
Ender equ 4f00h
EnterChar equ 1C0Dh
Tab equ 0F09h
Insert equ 5200h
NextIns equ 4E2Bh
Del equ 5300h
Subchar equ 4A2Dh
;Define the key Value
maxreadfile equ 0fe00h
;Define the Max Read file length
MessageBoxColor equ 3eh
;Define the Message Color
;-------------------------------------------------------------------------
Pager STRUC
upl dw 0
uph dw 0
downl dw 0
downh dw 0
zone dw 0
pager ENDS
;Define the Current disp page structure
;----------------------------------------------------------------------
start:
jmp begin
;------------------------------------------------------------------------
filename db 'Please input FileName:',24h
file db 65
db ?
db 66 dup(0)
;The File name buffer
handle dw 0
buffer db 20 dup(?)
Herc dw 0
;The flag of Monitor type
scrseg dw 0
;The Video Segment Addr
FileLenh dw 0
FileLenl dw 0
;The file length buffer
Filestartaddr dw 0F000h
bufferstartaddr dw 4100 ;500 bytes
writebufferstart dw 4600 ;56K bytes
;Define the every buffer length
pagerr pager {}
IsInScrBuffer db 0
;The flag to process either write
;the char to memory buffer then movs
;to the video buffer (isinscrbuffer=1)
;or direct write
;to the video buffer(isinscrbuffer=0)
SaveInMess db 1
;the flag to process is Save buffer
;in message or not
;-------------------------------------------------------------------------
; The Procedure to Hide the cursor
; Entrance: None
; OutParam: None
;------------------------------------------------------------------------
HideCursor proc
mov ah,1
mov cx,2000h
int 10h
ret
HideCursor endp
;-------------------------------------------------------------
; The Procedure Show the standard cursor
; Entrance: None
; OutParam: None
;-------------------------------------------------------------
ShowCursor proc
mov ah,1
mov cx,0607h
int 10h
ret
ShowCursor endp
;--------------------------------------------------------------
; The Procedure Show the Edit's Big cursor
; Entrance: None
; OutParam: None
;-----------------------------------------------------------
ShowBigCursor proc
mov ah,1
mov cx,0007h
int 10h
ret
ShowBigCursor endp
;----------------------------------------------------------------
; The Procedure Show the Hex Value in Ascii Mode
; Entrance: al-char
; bh-Attr.
; cl-x
; ch-y
; cs:tofilef=1.....write to file
; =0.....write to video (Byte)
; OutParam: None
;--------------------------------------------------------------
CharTable db '0123456789ABCDEF',0
CharStore db 3 dup (20h)
CharPos db 0
ToFileF db 0
;--------------------------------------------------------------
DispChar proc
push ax
push bx
push cx
push dx
push bp
push ds
push si
push di
push cs
pop ds
mov byte ptr cs:CharPos,0
;clear the position
mov dh,al
mov bp,2
push cx
and al,0f0h
mov cl,4
shr al,cl
pop cx
and al,0fh
@DDA:
push bx
lea bx,CharTable
xlat
;Change Hex value to Ascii mode
mov dl,al
pop bx
cmp byte ptr cs:tofileF,1
jnz to_video
push cx
push si
lea si,CharStore
mov cl,byte ptr cs:charPos
xor ch,ch
add si,cx
mov byte ptr cs:si,al
pop si
pop cx
inc byte ptr cs:charPos
;adjust the postion
jmp to_allvf
to_video:
call Write_char
;Write to Video buffer
to_allvf:
inc ch
cmp ch,80
jbe ddk
inc cl
xor ch,ch
ddk:
mov al,dh
and al,0fh
dec bp
jnz @DDA
pop di
pop si
pop ds
pop bp
pop dx
pop cx
pop bx
pop ax
ret
DispChar endp
;-------------------------------------------------------
; The Procedure Show The Ax (Hex) to Ascii Mode
; Entrance: cl-x
; ch-y
; bh-Attr
; ax-Word
; OutParam: None
;------------------------------------------------------
DispWord proc
xchg ah,al
call DispChar
inc ch
inc ch
xchg ah,al
call DispChar
ret
DispWord endp
;/*-------------------------------------------------------*/
; The Procedure Test the file is Bin or Test mode
;/* Entrance: Ds:Dx:FileName /
;/* OutParam: Ax=1...Is Bin File /
;/* Ax=2...Is not Bin File /
;/* Bx=Handle /
;/*-------------------------------------------------------*/
IsBin dw 0
fileAttr dw 0
;-----------------------------------------------------------
TestIsBinOrNot proc
push cs
pop ds
mov ax,4300h
int 21h
jc exit_open
mov cs:fileAttr,cx
cmp cx,20h
jz not_chgattr
;if is not hidden/system,do not change attr
mov ax,4301h
xor cx,cx
int 21h
; jc exit_open
;Get& Set the file attribute
not_chgAttr:
clc
mov ax,3d02h
int 21h
jnc ok_op
; jc exit_open
;Open file
mov ax,3d00h
int 21h
ok_op:
mov bx,ax
mov cs:handle,ax
mov ah,3fh
lea dx,buffer
mov cx,16
int 21h
jc exit_open
;Read file with 16 bytes
mov si,dx
cld
mov cx,ax
or cx,cx
jnz testbin
stc
ret
;error,not byte has read
testbin:
lodsb
cmp al,08h
jbe @7
cmp al,7fh
ja @7
loop testbin
jmp @8
@7:
clc
mov al,1
mov cs:isbin,1
ret
@8:
mov al,2
mov cs:isbin,0
clc
exit_open:
ret
TestIsBinOrNot endp
;/*-------------------------------------------------------*/
; The Procedure Load the file,if file > Maxmem ;Error exit
; if file < 64kb,load the file,form the offset
; if file > 64kb,Select the file block and form the offset
;/* Entrance: Bx=Handle */
;/* OutParam: Dx:Ax....The File Length */
;/*-------------------------------------------------------*/
maxoff dw 0
FileTooLong db 'Error: The file is too big to fit in Memory',0
fileloadsmall db 'Sorry: File Too long,Loading 0001 st 64KB ...',0
selectmess db ' ',18h,' ',19h,' ',1ah,' ',1bh,' pgdn,pgup--Select'
db ' Enter--Go '
db ' |(C)Copyright YuHuan',0
;------------------------------------------------------------
GetFileLength proc
mov byte ptr cs:over64k,0
;clear the flag
mov bx,cs:handle
mov ax,4200h
xor cx,cx
xor dx,dx
int 21h
jnc abcde
jmp exit_getlen
abcde:
mov ax,4202h
xor cx,cx
xor dx,dx
int 21h
jc exit_getlen
mov cs:filelenh,dx
mov cs:filelenl,ax
;Get file length
push ax
mov cl,12
shl dx,cl
mov cl,4
shr ax,cl
add dx,ax
pop ax
cmp word ptr cs:maxmem,0fffh
ja ok_file
;test left memory is enough or not
mov cs:stop,1
lea si,filetoolong
call messagebox
stc
;the program can edit file >64kb
jmp exit_getlen
ok_file:
mov dx,word ptr cs:filelenh
or dx,dx
jz ok_file1
mov byte ptr cs:over64k,1
push bx
lea si,selectmess
mov cl,24
mov ch,0
mov bh,0fh
call write_str
;show select help message
mov cs:stop,0
lea si,fileloadsmall
mov bx,offset selRange
call messagebox
mov word ptr cs:filelenh,0
pop bx
ok_file1:
mov ax,word ptr cs:filelenl
push ax
and ax,0fh
mov word ptr cs:nextchar,ax
pop ax
;get the last char
dec ax
mov cl,4
shr ax,cl
mov cl,4
shl ax,cl
mov cs:maxoff,ax
;Form the file last offset(=filelen/16)
clc
exit_getlen:
ret
GetFileLength endp
;--------------------------------------------------------
seekh dw 0
seekl dw 0
block dw 0
Totalblock dw 0
;------------------------------------------------------
; The Procedure to Select the file's block to edit
;-------------------------------------------------------
SelRange proc
mov dx,word ptr cs:filelenh
mov ax,word ptr cs:filelenl
mov cx,maxreadfile
div cx
or dx,dx
jz sel_0
inc ax
mov cs:totalblock,ax
sel_0:
;Get the max block of file
mov bp,ax
mov si,1
sel_loop:
mov cl,11
mov ch,42
mov bh,2fh
mov ax,si
call dispword
;disp the number
xor ah,ah
int 16h
;select the block
cmp ax,up
jnz sel_1
@@up:
cmp si,1
jz sel_2
dec si
jmp sel_loop
sel_2:
mov si,bp
jmp sel_loop
sel_1:
cmp ax,down
jnz sel_3
@@down:
cmp si,bp
jae sel_4
inc si
jmp sel_loop
sel_4:
mov si,1
jmp sel_loop
sel_3:
cmp ax,Enterchar
jnz sel_5
jmp sel_@1
sel_5:
cmp ax,left
jnz sel_6
jmp @@up
sel_6:
cmp ax,right
jnz sel_7
jmp @@down
sel_7:
cmp ax,pgup
jnz sel_8
cmp si,10h
jb not_s
sub si,10h
jmp sel_loop
not_s:
mov si,1
jmp sel_loop
sel_8:
cmp ax,pgdn
jnz sel_9
mov ax,bp
cmp ax,10h
jb is_la
sub ax,10h
cmp si,ax
ja is_la
add si,10h
jmp sel_loop
is_la:
mov si,bp
sel_9:
jmp sel_loop
;--------------------------------------key process
sel_@1:
mov cs:block,si
dec si
mov cx,si
mov cs:seekh,0
mov cs:seekl,0
or cx,cx
jz not_selseek
sel_seek:
add cs:seekl,maxreadfile
adc cs:seekh,0
loop sel_seek
;form the file's start offset to read
not_selseek:
mov dx,cs:filelenl
mov cx,cs:filelenh
mov ax,cs:seekl
mov cs:filelenl,maxreadfile
sub dx,ax
sbb cx,cs:seekh
or cx,cx
jnz exit_sel
mov cs:filelenl,dx
;get the read file's length
exit_sel:
ret
SelRange endp
;----------------------------------------------------------
NextSeekl dw 0
NextSeekh dw 0
;----------------------------------------------------------
; The Procedure Read the file's block
; Entrance: Bx-Handle
; OutParam: clc-ok
; stc-error
;----------------------------------------------------------
ReadFile proc
pushall
mov bx,cs:handle
mov ax,4200h
mov cx,cs:seekh
mov dx,cs:seekl
int 21h
;seek the file
mov ax,cs:scrseg
mov dx,cs:filestartaddr
shr dx,4
add ax,dx
mov ds,ax
;form the file buffer segment
mov dx,0
mov cx,cs:filelenl
@r64:
mov ah,3fh
int 21h
jc read_64k
cmp ax,0
jnz read_ok
stc
jmp read_64k
read_ok:
mov cs:filelenl,ax
push ax
mov ax,cs:seekl
mov cs:nextseekl,ax
mov ax,cs:seekh
mov cs:nextseekh,ax
pop ax
add cs:nextseekl,ax
adc cs:nextseekh,0
;if file >64k ,form the next file offset
;for save the file(in edit zone)
clc
read_64k:
popall
ret
ReadFile endp
;----------------------------------------------------------
; The Prodedure Test file is end or not
; Entrance: None
; OutParam: clc-ok
; stc-file ends
;----------------------------------------------------------
TestFileEnd proc
push ax
push bx
push cx
mov ax,word ptr cs:fileLenl
mov bx,word ptr cs:pagerr.downl
cmp ax,bx
jb small_ex
pop cx
pop bx
pop ax
clc
ret
small_ex:
pop cx
pop bx
pop ax
stc
ret
TestFileEnd endp
;-----------------------------------------------------------
; The Procedure Process the Pgdn key
; Entrance: None
; OutParam: None
;-----------------------------------------------------------
do_pgdn proc
call TestfileEnd
jc exit_dnend
;Test file is end or not
mov ax,word ptr cs:pagerr.downl
add ax,22*16
;Form the new offset to display
cmp ax,word ptr cs:maxoff
jbe nexdn
Do_End:
call TestfileEnd
jc exit_dnend
mov ax,word ptr cs:maxoff
add ax,10h
sub ax,22*16
mov word ptr cs:pagerr.upl,ax
mov word ptr cs:pagerr.downl,ax
jmp nexdn1
;If file is end,to disp the last page
nexdn:
add word ptr cs:pagerr.upl,16*22
adc word ptr cs:pagerr.uph,0
nexdn1:
; push ax
mov bh,byte ptr cs:dispcolor
; call Clr_win
;Clear the disp windows
; pop ax
mov ax,word ptr cs:pagerr.upl
mov word ptr cs:dispaddrl,ax
mov cl,2
; mov bp,22
; loop_dn:
mov ch,10
; call displine
; jc exit_dnend
; inc cl
; add word ptr cs:pagerr.downl,16
; adc word ptr cs:pagerr.downh,0
; dec bp
; jnz loop_dn
;disp the current page (== 22 lines)
call disppage
exit_dnend:
ret
do_pgdn endp
;-----------------------------------------------------------
; The Procedure the Pgup key
; Entrance: None
; OutParam: None
;-----------------------------------------------------------
do_pgup proc
mov ax,word ptr cs:pagerr.upl
cmp ax,22*16
jb Do_home
sub ax,22*16
cmp ax,0
ja up_n
Do_Home:
;Test is file start or not
mov ax,0
up_n:
; push ax
; mov bh,byte ptr cs:dispcolor
; call Clr_win
;clear the windows
; pop ax
mov word ptr cs:pagerr.upl,ax
mov word ptr cs:pagerr.downl,ax
mov word ptr cs:dispaddrl,ax
; mov bp,22
mov cl,2
; mov bp,22
; loop_up:
mov ch,10
; call displine
; jc exit_upend
; inc cl
; add word ptr cs:pagerr.downl,16
; adc word ptr cs:pagerr.downh,0
; dec bp
; jnz loop_up
;disp the current page
call disppage
exit_upend:
ret
do_pgup endp
;-----------------------------------------------------------
; The Procedure process the down key
; Entrance: cl-x
; ch-y
; OutParam: None
;----------------------------------------------------------
ScroolLine proc
call TestfileEnd
jc exit_lined
mov ax,word ptr cs:filelenl
mov cx,word ptr cs:pagerr.downl
cmp ax,cx
jbe exit_lined
mov ax,word ptr cs:pagerr.upl
add ax,16*22
jc exit_lined
mov word ptr cs:dispaddrl,ax
mov word ptr cs:pagerr.downl,ax
mov ah,6
mov al,1
mov bh,07h
mov cx,0200h
mov dh,23
mov dl,78
int 10h
;Scrool a line
; call clr_win
mov cl,23
mov ch,10
call displine
jc exit_lined
;disp the line
add word ptr cs:pagerr.upl,16
adc word ptr cs:pagerr.uph,0
add word ptr cs:pagerr.downl,16
adc word ptr cs:pagerr.downh,0
;form the new offset
exit_lined:
ret
ScroolLine endp
;---------------------------------------------------------
scrup dw 0
scrdn dw 0
;-----------------------------------------------------------
; The procedure process the up key
; Entrance: cl-x
; ch-y
; OutParam: None
;----------------------------------------------------------
Scroolup proc
cmp word ptr cs:pagerr.upl,0
jnz doup
cmp word ptr cs:pagerr.uph,0
jnz doup
jmp noneup
doup:
mov word ptr cs:upp,1
mov ah,7
mov al,1
mov bh,07h
mov cx,0200h
mov dh,23
mov dl,79
int 10h
;scrooll 1 line
sub word ptr cs:pagerr.upl,16
sbb word ptr cs:pagerr.uph,0
mov ax,word ptr cs:pagerr.upl
mov word ptr cs:dispaddrl,ax
; add ax,160h
mov word ptr cs:pagerr.downl,ax
;form the new offset
mov cl,2
mov ch,10
call displine
;disp the line
mov word ptr cs:upp,0
;clear the flag
noneup:
ret
Scroolup endp
;------------------------------------------------------------
; The procedure disp the line to screen at position
; Entrance: cl-x
; ch-y
; OutParam: clc-ok
; stc-file ends
;------------------------------------------------------------
DispAddrh dw 0
DispAddrl dw 0 ;the address of file buffer
Line db 18 dup(0) ;the lines chars buffer
halff dw 0 ;the flag of half lines
chard db 0
charnum dw 0 ;the char number
upp dw 0
nextchar dw 0
CurrentSeg dw 0
;the two parameters point to the
;current memory's Seg:Off
dispcolor db 17h ;first=1ah
datewinspace db 70 dup (20h),0
;-----------------------------------------------------------------
DispLine proc
pushall
mov di,cs:fileLenl
mov si,cs:pagerr.downl
cmp di,si
jae nexon
stc
jmp line_e@
nexon:
sub di,si
mov cs:charnum,16
cmp di,16
jae dispnow
mov di,word ptr cs:nextchar
mov cs:charnum,di
cmp di,0
jnz dispnow
stc
jmp line_e@
dispnow:
cmp word ptr cs:upp,1
jnz notup
mov word ptr cs:charnum,16
notup:
push cx
mov si,word ptr cs:dispaddrl
mov di,offset line
mov cx,cs:charnum
cld
mov byte ptr cs:chard,62
;chard=start ascii zone address
mov ax,cs:filestartaddr
shr ax,4
; mov ds,ax
push cx
mov cx,cs:scrseg
add ax,cx
pop cx
mov ds,ax
;Form the file Buffer Segment
mov ax,cs
mov es,ax
;Form the destination Segment
rep movsb
;Get the 16 bytes chars to display
pop cx
push cx
mov bh,30h
;bh-Attri
mov ch,0
;ch=col
mov ax,cs:dispaddrh
add ax,word ptr cs:scrseg
push bx
push cx
mov bx,word ptr cs:filestartaddr
mov cl,4
shr bx,cl
add ax,bx
pop cx
pop bx
mov word ptr cs:currentseg,ax
;ax=the file to the memory's segment
call dispword
inc ch
inc ch
mov dl,':'
call write_char
add ch,1
mov ax,cs:dispaddrl
call dispword
;disp address XXXX:XXXX
add cs:dispaddrl,16
adc cs:dispaddrh,0
push ds
push cs
pop ds
lea si,datewinspace
mov bh,byte ptr cs:dispcolor
mov ch,9
call write_str
pop ds
;clear the line with dispcolor
lea si,line
mov ax,cs
mov ds,ax
pop cx
mov cs:halff,0
@displ:
lodsb
mov dl,al
push dx
mov bh,byte ptr cs:dispcolor
call dispchar
inc ch
inc ch
mov dl,20h
call Write_char
inc ch
pop dx
;write the hex code and space
push cx
mov ch,byte ptr cs:chard
cmp dl,20h
jae nextc@
mov dl,'.'
jmp clds
nextc@:
cmp dl,80h
jb clds
cmp dl,0a0h
jae clds
;if > 0a0h, the char is chinese
mov dl,'.'
clds:
mov bh,byte ptr cs:dispcolor
or bh,0fh
call Write_char
inc byte ptr cs:chard
pop cx
;write ascii at the ascii zone
inc cs:halff
cmp cs:halff,8
je dhaf
cmp word ptr cs:charnum,0
jz @34
dec cs:charnum
jnz @displ
@34:
clc
jmp line_e@
dhaf:
cmp cs:charnum,1
jz @34
;test file is over or not
cmp word ptr cs:charnum,0
jz @34
dec word ptr cs:charnum
mov dl,'-'
mov bh,byte ptr cs:dispcolor
call write_char
inc ch
mov dl,20h
call write_char
inc ch
mov cs:halff,9
jmp @displ
line_e@:
popall
ret
displine endp
;----------------------------------------------------------
; Entrance: cl-x
; ch-y
; OutParam: None
;----------------------------------------------------------
DispPage proc
push bp
mov byte ptr cs:isinscrbuffer,1
;set write to memory flag
call Save_scr
;Load the screen to Edit
mov ax,word ptr cs:pagerr.upl
mov word ptr cs:dispaddrl,ax
mov ax,word ptr cs:pagerr.uph
mov word ptr cs:dispaddrh,ax
mov bp,22
;bp=total lines/page
@repage:
call displine
jc page_over
push ax
add word ptr cs:pagerr.downl,16
adc word ptr cs:pagerr.downh,0
pop ax
inc cl
mov ch,10
dec bp
jnz @repage
page_over:
call Pop_scr
;Restore the Edited Buffer to Screen
mov byte ptr cs:isinscrbuffer,0
;clear write to memory flag
pop bp
ret
DispPage endp
;----------------------------------------------------------
; The procedure disp the file as text mode to screen
; Entrance: None
; OutParam: None
;------------------------------------------------------------
togglemess db 'Do you want all file list:<y/n>: ',0
toggleall dw 0
lines dw 0
lines1 dw 0
row db 0
notbinmess db 'Warning: The file is not Text file mode..',0
toggleheader db 'Toggle file name ---->',0
;-------------------------------------------------------------
do_toggle proc
pushall
call save_scr
;call save the screen
cmp cs:isbin,1
jnz do_showto
lea si,notbinmess
mov cs:stop,1
call messagebox
; jmp exit_toggle1
do_showto:
; mov bh,1eh
; call Clr_win
;clear the windows
mov bp,3
call DrawShadow
;draw the windows with shadow
mov cl,9
mov ch,25
mov bh,MessageBoxColor
lea si,togglemess
call write_str
xor ah,ah
int 16h
and al,0dfh
;change to big char
mov word ptr cs:toggleall,0
cmp al,'Y'
jnz notall
mov word ptr cs:toggleall,1
notall:
mov bx,word ptr cs:scrseg
mov ax,word ptr cs:filestartaddr
mov cl,4
shr ax,cl
add bx,ax
mov ds,bx
mov si,word ptr cs:pagerr.upl
cmp word ptr cs:toggleall,1
jnz notallt
mov si,0
notallt:
cld
mov word ptr cs:lines,1
mov byte ptr cs:row,1
mov word ptr cs:lines1,1
mov bh,1fh
call clrscr
mov cx,0
call setcursor
mov cx,160h
loop_toggle:
cmp cs:toggleall,1
jnz do_showline
pushall
push cs
pop ds
mov cl,0
mov ch,2
mov bh,12h
lea si,toggleheader
call write_str
mov cl,0
mov ch,30
mov bh,13h
lea si,file
add si,2
call write_str
;show the header
popall
cmp word ptr cs:toggleall,1
jnz do_showline
mov bh,1eh
mov ax,word ptr cs:lines
push cx
mov cl,byte ptr cs:row
xor ch,ch
call dispword
mov ch,4
mov dl,':'
call write_char
pop cx
;show lines
do_showline:
cmp si,cs:filelenl
jb togger2
jmp exit_toggle
togger2:
;Test file is end or not
lodsb
jmp nextc0
cmp al,09h
jae togger1
jmp exit_toggle
togger1:
cmp al,80h
jb nextc0
jmp exit_toggle
;not active
nextc0:
; cmp al,1ah
; je exit_toggle
nextla:
mov bp,1
cmp al,09
jnz not_tab
mov bp,8
mov al,20h
;if al=09,disp 8 times spaces
not_tab:
mov ah,0eh
mov bx,03h
int 10h
dec bp
jnz not_tab
cmp word ptr cs:toggleall,1
jz alldo
dec cx
jz exit_toggle
; jmp loop_toggle
jmp do_showline
alldo:
cmp al,0ah
jnz adcd
inc word ptr cs:lines
inc word ptr cs:lines1
inc byte ptr cs:row
cmp word ptr cs:lines1,23
ja shok
jmp loop_toggle
shok:
push ax
xor ah,ah
int 16h
mov cx,ax
cmp ax,escape
pop ax
jz exit_toggle1
push cx
mov bh,1fh
call clrscr
mov cx,0
call setcursor
;clear screen,for next page
mov word ptr cs:lines1,1
mov word ptr cs:row,1
pop cx
cmp cx,up
jnz next_togglekey
jmp loop_toggle
Next_ToggleKey:
jmp loop_toggle
adcd:
jmp do_showline
exit_toggle:
mov ah,0
int 16h
exit_toggle1:
call pop_scr
popall
ret
do_toggle endp
;/*--------------------------------------------------------*/
; The procedure clear the screen
;/* Entrance: bh--Color /
;/* OutParam: None /
;/*---------------------------------------------------------/
ClrScr proc
mov ax,0600h
mov cx,0
mov dh,24
mov dl,79
int 10h
ret
ClrScr endp
;-------------------------------------------------------*/
; Entrance: None /
; OutParam: Herc=0--is Color Monitor /
; Herc=1--is MDA Monitor /
;--------------------------------------------------------/
TestMonitor PROC
push ax
push ds
xor ax,ax
mov ds,ax
mov al,byte ptr ds:[449h]
mov cs:herc,0
cmp al,7
jnz @1
mov cs:herc,1
@1:
pop ds
pop ax
ret
TestMonitor endp
;-------------------------------------------------------
; The procedure set cursor position
; Entrance: cl-x
; ch-y
; OutParam: None
;------------------------------------------------------
SetCursor proc
mov ah,2
mov bh,0
mov dh,cl
mov dl,ch
int 10h
ret
SetCursor endp
;--------------------------------------------------------+
; The procedure get the char/Attri from the video
; Note: The procedure Destroy many registers
; Entrance: cl-x
; ch-y
; Outparam: cs:getcolor=Attri (byte)
; cs:getchar =Char (byte)
;--------------------------------------------------------+
GetColor db 0
GetChar db 0
;---------------------------------------------------------+
Get_charAttri proc
pushall
mov ax,0b800h
cmp cs:herc,1
jnz @2ca
mov ax,0b000h
@2ca:
mov ds,ax
mov al,cl
mov cl,80
mul cl
mov cl,ch
xor ch,ch
add ax,cx
mov cl,1
shl ax,cl
;ax=position
mov si,ax
cld
lodsb
mov byte ptr cs:getchar,al
;al=char
lodsb
mov byte ptr cs:getcolor,al
;al=attri
popall
ret
Get_CharAttri endp
;--------------------------------------------------------/
; The procedure write the byte to the video buffer /
; Entrance: cl-x /
; ch-y /
; bh-Attribute /
; dl-Char /
; OutParam: None /
;--------------------------------------------------------/
Write_char proc
pushall
push cx
cmp byte ptr cs:isInScrBuffer,1
jnz to_32
mov ax,word ptr cs:scrseg
jmp @2
;if is in memory buffer,write char to momery
;then use rep movsb instruct to move the memory
;to the video buffer
to_32:
mov ax,0b800h
cmp herc,1
jnz @2
mov ax,0b000h
@2:
mov ds,ax
push ax
push dx
mov al,cl
mov cl,80
mul cl
mov cl,ch
xor ch,ch
add ax,cx
mov cl,1
shl ax,cl
;ax=position
mov si,ax
pop dx
pop ax
xor ax,ax
mov al,dl
cld
mov byte ptr ds:[si+1],bh
mov byte ptr ds:[si],al
pop cx
inc ch
cmp ch,80
jb set_c
xor ch,ch
inc cl
cmp cl,24
jb set_c
xor cx,cx
set_c:
call SetCursor
popall
ret
Write_Char endp
;----------------------------------------------------------------/
;' The procedure wirte the string to the video buffer /
; Entrance: Ds:si--String(end with 0) /
; bh-Attri /
; cl--x /
; ch--y /
; OutParam: None /
;----------------------------------------------------------------/
Write_Str proc
pushall
cld
lodsb
@5:
or al,al
jz @3
mov dl,al
call Write_char
inc ch
cmp ch,80
jbe @4
inc cl
xor ch,ch
@4:
lodsb
jmp @5
@3:
popall
ret
Write_Str endp
;----------------------------------------------------------------
; The procedure save the current screen to the buffer
; Entrance: None
; OutParam: None
;---------------------------------------------------------------
Save_scr proc
pushall
mov ax,0b800h
cmp herc,1
jnz @s
mov ax,0b000h
@s:
mov ds,ax
xor si,si
xor di,di
cld
mov ax,cs:scrseg
mov es,ax
mov cx,2048*2
rep movsb
popall
ret
Save_scr endp
;----------------------------------------------------------------/
; The procedure restore the screen from the buffer
; Entrance: None
; OutParam: None
;---------------------------------------------------------------
Pop_scr proc
pushall
mov ax,0b800h
cmp herc,1
jnz @ss
mov ax,0b000h
@ss:
mov es,ax
xor si,si
xor di,di
cld
mov ax,cs:scrseg
mov ds,ax
mov cx,2048*2
rep movsb
popall
ret
Pop_scr endp
;---------------------------------------------------------------
; Entrance: Ds:si--Message
; if Stop==1,bx=Porcedure addr.
; OutParam: None
;---------------------------------------------------------------
stop dw 1
Sdp db 50 dup(20h),0
messb db 201,18 dup(205),' MessageBox ',18 dup(205)
db 187,0
messb1 db 186,48 dup(20h),186,0
messb2 db 186,48 dup(20h),186,0
messb3 db 186,48 dup(20h),186,0
messb4 db 200,48 dup(205),188,0
;--------------------------------------------------------------
MessageBox proc
pushall
push bx
;bx=procedure addr.
push si
cmp byte ptr cs:saveinmess,0
jz not_sa
call Save_scr
not_sa: ;Test save screen or not
call HideCursor
mov bh,07h
mov cl,10
mov ch,12
lea si,sdp
mov ax,5
@rr:
call Write_str
inc cl
dec ax
jnz @rr
;Clear BackGround
mov bh,2fh
mov ch,10
mov cl,9
lea si,messb
call Write_str
inc cl
lea si,messb1
call Write_str
inc cl
lea si,messb2
call Write_str
inc cl
lea si,messb3
call Write_str
inc cl
lea si,messb4
call Write_str
mov cl,11
mov ch,13
mov bh,MessageBoxColor
and bh,2fh
pop si
call Write_str
pop bx
cmp stop,1
jnz hg
mov ah,0
int 16h
jmp hg1
hg:
call bx
hg1:
cmp byte ptr cs:saveinmess,0
jz to_po
call Pop_scr
to_po:
popall
ret
MessageBox endp
;-----------------------------------------------------------------
header db ' Hex 00 01 02 03 04 05 06 07 - 08 09 0A 0B 0C 0D 0E 0F '
db ' --'
DB ' ASCII -- ',0
bottom db 'F1-Help,F2-Go,F3-Load,F4-Edit,F5-Color,F6-Toggle,'
db 'F7-Block,F8-Search,F9-Key Value',0
EditBo db 18h,19h,1ah,1bh,'--Move,Enter--Save,Tab--Change Edit Zo'
db 'ne,Esc--Exit,De'
db 'l--Delete,Ins--Insert ',0
insertmess db '| Browse ',0
overmess db '| Overwrite',0
insmess db '| Insert ',0
blockmess db 'Block: |',0
;----------------------------------------------------------------
ShowHeader proc
mov bp,70h
mov dl,20h
mov cl,0
mov ch,0
mov bh,70h
clearline:
call Write_char
inc ch
dec bp
jnz clearline
;Clear the Top Line
lea si,insertmess
mov cl,0
mov ch,69
mov bh,2fh
call write_str
;show the status
mov cl,0
mov ch,20
mov bh,74h
lea si,file
add si,2
call Write_str
;show file message
mov cx,0001h
mov bh,0fh
lea si,header
call write_str
mov cx,0018h
mov bh,0Fh
lea si,bottom
call write_str
;show bottom message
mov cx,0
mov bh,2fh
lea si,blockmess
call write_str
mov ax,cs:block
mov cx,0600h
; mov bh,MessageBoxColor
mov bh,20h
call dispword
;show block message
ret
ShowHeader endp
;----------------------------------------------------------------/
; Entrance: Bx-Handle /
; OutParam: None /
;----------------------------------------------------------------/
Do_bin proc
call HideCursor
;Hide Cursor
mov ax,cs:scrseg
mov dx,cs:writebufferstart
shr dx,4
add ax,dx
mov word ptr cs:writebufferseg,ax
;form write buffer segment
mov word ptr cs:pagerr.upl,0
mov word ptr cs:pagerr.uph,0
mov word ptr cs:pagerr.downl,0
mov word ptr cs:pagerr.downh,0
mov word ptr cs:pagerr.zone,0
call getfilelength
jnc to_binon
jmp exit_bin
to_binon:
call Readfile
jnc to_binon1
jmp exit_bin
to_binon1:
push bx
call showheader
;show header
pop bx
redrawpage:
mov cx,0a02h
call disppage
main_loop:
; call showaddress
mov ah,0
int 16h
cmp ax,down
jnz main_1@
call ScroolLIne
jmp main_loop
main_1@:
cmp ax,Escape
jnz main_ins
jmp exit_bin
main_ins:
cmp ax,up
jnz main_2@
call Scroolup
jmp main_loop
main_2@:
cmp ax,pgdn
jnz main_3@
call do_pgdn
jmp main_loop
main_3@:
cmp ax,F3
jnz main_4@
call do_f3
jmp main_loop
main_4@:
cmp ax,pgup
jnz main_5@
call do_pgup
jmp main_loop
main_5@:
cmp ax,F1
jnz main_6@
call do_help
jmp main_loop
main_6@:
cmp ax,Ender
jnz main_7@
call do_end
jmp main_loop
main_7@:
cmp ax,home
jnz main_8@
call do_home
jmp main_loop
main_8@:
cmp ax,F6
jnz main_9@
call do_toggle
jmp main_loop
main_9@:
cmp ax,F2
jnz main_a@
call do_go
jc to_llpg
mov cs:pagerr.upl,ax
mov cs:pagerr.downl,ax
jmp redrawpage
to_llpg:
jmp main_loop
main_a@:
cmp ax,F4
jnz main_b@
call do_edit
jmp main_loop
main_b@:
cmp ax,F5
jnz main_c@
call do_F5
jmp main_loop
main_c@:
cmp ax,F7
jnz main_d@
call do_fill
jmp main_loop
main_d@:
cmp ax,F9
jnz main_e@
call do_F9
main_e@:
cmp ax,F8
jnz main_f@
call do_f8
jmp main_loop
main_f@:
cmp ax,F10
jnz main_g@
call do_f10
jmp main_loop
main_g@:
cmp ax,EnterChar
jnz main_h@
call Do_enter
jmp main_loop
main_h@:
cmp ax,NextIns
jnz main_i@
mov bh,byte ptr cs:dispcolor
call clr_win
;clear the screen
jmp do_bin
;read the other block
main_i@:
cmp ax,Subchar
jnz main_j@
call do_cut
main_j@:
and al,0DFh
; change to big char
cmp al,'A'
jnz main_k@
call ShowAscii
jmp main_loop
main_k@:
cmp al,'E'
jnz main_l@
call Do_Encrypt
jmp main_loop
main_l@:
jmp main_loop
exit_bin:
;scrool screen up of 1 line
ret
Do_bin endp
;----------------------------------------------------------------/
; Entrance: Bx-Handle /
; OutParam: None /
;----------------------------------------------------------------/
Do_Text proc
ret
Do_Text endp
;-----------------------------------------------------------------
; Entrance: None
; OutParam: clc-Ok
; stc-Error
;-----------------------------------------------------------------
ReAllocMem proc
mov ax,cs:psp
lea bx,all
mov cl,4
shr bx,cl
add ax,bx
add ax,100
mov cs:scrseg,ax
;Free More Memory
; mov ax,cs:scrseg
mov bx,cs:bufferstartaddr
mov cl,4
shr bx,cl
add ax,bx
mov cs:currentbuffseg,ax
;ax=temp buffer for edit
ret
ReAllocMem endp
;---------------------------------------------------------
; Entrance: None
; OutParam: None
;-------------------------------------------------------
addrmess db 'The Position is:',0
copy1 db 10h,'Thanks For Using.'
db '(C)Copyright ',0
Yc db 'YuHuan & Lxf /1996 ',0
Yi db '(r) All rights reserved. ',11h,0
;--------------------------------------------------------
showaddress proc
mov ch,60
mov cl,0
mov bh,07h
push cs
pop ds
lea si,addrmess
call write_str
mov bh,70h
mov ch,76
mov cl,0
mov ax,word ptr cs:pagerr.zone
call Dispword
ret
showaddress endp
;---------------------------------------------------------
; Entrance: None
; OutParam: None
;----------------------------------------------------------
helpmess0 db "The BinEdit Program's Help",0
helpmess1 db ' Author: YuHuan ',0
helpmess2 db 'Date : 1996.5 [ Version 1.0 ]',0
helpmess3 db 'Addr. : BeiJing CS&S HuaTech Info Tech LTD.',0
helpmess4 db 'Tel : (010)62177722-6406',0
helpmess5 db ' Notes:',0
helpmess6 db ' If you find any bugs,Please contact with me',0
helpmess7 db ' The program can be released at any way',0
helpmess8 db ' ',0
helpmess9 db ' Function: ',0
helpmess10 db ' ',18h,19h,1ah,1bh,',pgup,pgdn,home,end-List,Enter-Save file',0
helpmess12 db ' F1-Help,F2-Go,F3-Load,F4- Edit,F5- Chg Color',0
helpmess13 db ' F6-Toggle Bin/Text,F7-Fill/Delete/Save Block',0
helpmess14 db ' F8-Search,F9-Key Value,F10-Chg file,Esc-Exit',0
helpmess15 db ' Gray [+]- Load Block,Gray [-]-Cut large file',0
helpmess11 db ' A-Ascii Chart,E-Encrypt.',0
; helpmess11 db ' Press any key to continue...',0
helpaddr dw offset helpmess1
dw offset helpmess2
dw offset helpmess3
dw offset helpmess4
helpaddr1 dw offset helpmess5
dw offset helpmess6
dw offset helpmess7
dw offset helpmess8
dw offset helpmess9
dw offset helpmess10
dw offset helpmess12
dw offset helpmess13
dw offset helpmess14
dw offset helpmess15
dw offset helpmess11
;----------------------------------------------------------
Do_help proc
pushall
call save_scr
call hidecursor
mov bh,17h
call clrscr
lea si,sdp
mov cl,4
mov ch,16
mov bp,19
mov bh,07h
help_l1:
call write_str
inc cl
dec bp
jnz help_l1
mov bh,25h
mov cl,3
mov ch,14
mov bp,19
help_l:
call Write_str
inc cl
dec bp
jnz help_l
lea si,helpmess0
mov cl,2
mov ch,25
mov bh,1eh
call write_str
;show help header
mov cl,5
mov ch,20
mov bh,20h
lea di,helpaddr
mov bp,4
push cs
pop es
help_l2:
mov si,word ptr es:[di]
add di,2
call write_str
inc cl
dec bp
jnz help_l2
;first helpmess
mov cl,10
mov ch,15
lea di,helpaddr1
mov bh,2fh
mov bp,11
help_l3:
mov si,word ptr es:[di]
add di,2
call write_str
inc cl
dec bp
jnz help_l3
;show help mess
; mov cl,20
; mov ch,20
; mov si,word ptr es:[di]
; mov bh,MessageBoxColor
; call write_str
;show press any key mess
xor bp,bp
to_shh:
mov ah,1
int 16h
jnz to_noke
mov bh,70h
mov cl,5
mov ch,19
mov dl,'-'
or bp,bp
jz to_dg
xor bp,bp
mov dl,'|'
jmp to_dgg
to_dg:
mov bp,1
to_dgg:
push dx
call write_char
pop dx
mov ch,40
mov cl,5
call write_char
;disp '/' or '/'
call Changecolor
mov bh,al
and bh,0fh
or bh,bh
jnz to_ddafa
mov bh,07h
;al=color
to_ddafa:
mov cl,5
mov ch,20
lea si,helpmess1
call write_str
mov ah,2ch
int 21h
mov bl,dh
to_rt:
mov ah,2ch
int 21h
cmp bl,dh
jz to_rt
;disp a second
jmp to_shh
to_noke:
xor ah,ah
int 16h
;flush the extra key
call pop_scr
; call showcursor
popall
ret
Do_help endp
;------------------------------------------------------------
; Entrance; None
; OutParam: None
;------------------------------------------------------------
segg db 5
db ?
db 5 dup(0)
offmess db 'Please input Offset ->',0
;----------------------------------------------------------
; The Procedure Form the Jmp Offset
;
; Entrance:None
; OutParam:ax=Offset
;----------------------------------------------------------
Do_Go proc
push ds
push es
push bx
push cx
push dx
call save_scr
;save the screen
; mov bh,1fh
; call clr_win
;scrool the window
mov bp,4
call drawShadow
mov cl,09h
mov ch,09h
mov bh,MessageBoxColor
lea si,offmess
call write_str
;show message
mov ch,33
call setcursor
;set cursor
call getnum
jc exit_go
;get offset from keyboard
and ax,0fff0h
; mov cx,cs:maxoff
; sub cx,160h
cmp ax,cs:maxoff
jae go_yh
mov cx,cs:maxoff
cmp cx,160h
jbe go_yh
sub cx,160h
cmp ax,cx
jbe exit_go1
mov ax,cx
jmp exit_go1
go_yh:
mov ax,0
exit_go1:
clc
exit_go:
;process offset
pushf
push ax
call pop_scr
pop ax
popf
;restore screen
pop dx
pop cx
pop bx
pop es
pop ds
ret
Do_Go endp
;---------------------------------------------------------
off db 4 dup(30h)
notdogo dw 0
NoCharFlag db 0
;--------------------------------------------------------
; Entrance: None
; OutParam: stc--Error
; clc-ok,Ax-Number from keyboard
;---------------------------------------------------------
GetNum proc
mov byte ptr cs:nocharflag,0
lea dx,segg
push cs
pop ds
mov ah,0ah
call get_str
jnc next_numa
jmp error_char
next_numa:
lea si,segg
mov cl,byte ptr ds:[si+1]
xor ch,ch
or cx,cx
jnz charyes
mov byte ptr cs:nocharflag,1
charyes:
mov bp,cx
mov cx,4
sub cx,bp
mov bp,cx
push bp
;bp=numbers to fill with '0'
cld
mov al,30h
lea di,off
push cs
pop es
mov cx,4
rep stosb
;fill buffer with '0'
add si,2
lea di,off
add di,bp
mov cl,byte ptr ds:[si-1]
xor ch,ch
rep movsb
;form to 4 byts
lea si,off
lea di,segg
add di,2
mov cx,4
pop bp
next_char:
lodsb
cmp al,'9'
jg ischar
cmp al,'0'
jb error_char
sub al,30h
to_store:
stosb
loop next_char
lea si,segg
add si,2
mov bx,4
xor bp,bp
mov cs:notdogo,1
to_lp:
lodsb
xor ah,ah
or bp,ax
cmp bx,1
jnz to_lp1
cmp cs:notdogo,1
jz go_changeover
to_lp1:
mov cl,4
rol bp,cl
dec bx
jnz to_lp
;change 4 byte number to a words
go_changeover:
clc
jmp ok_char
ischar:
and al,0dfh
cmp al,'A'
jb error_char
cmp al,'F'
ja error_char
sub al,37h
jmp to_store
error_char:
stc
ret
ok_char:
clc
mov ax,bp
ret
getnum endp
;------------------------------------------------------------------------+
offst1 db 'Please input start offset:',0
offst2 db 'Please input end offset:',0
offst3 db 'Input Fill Char (Hex) :',0
off1 dw 0
;------------------------------------------------------------------------
; OutParam: stc-error
; clc-ok
; bp=second offset
; cs:off1=first offset
; cx=Length
;----------------------------------------------------------------------
Get_TwoOffset proc
; mov bh,1fh
; call clr_win
mov bp,6
call DrawShadow
;draw the windows with shadow
mov cl,09h
lea si,offst1
mov bp,2
loop_offget:
mov ch,0bh
mov bh,MessageBoxColor
call write_str
mov ch,37
call setcursor
push bp
call getnum
pop bp
jc exit_gettwo_error
dec bp
jz exit_getoff
mov cs:off1,ax
mov cl,0ah
lea si,offst2
jmp loop_offget
exit_getoff:
mov bp,ax
cmp ax,cs:off1
jbe exit_GetTwo_error
cmp ax,cs:filelenl
jb get_yh1
mov ax,cs:filelenl
get_yh1:
mov bx,cs:off1
cmp bx,cs:filelenl
ja exit_getTwo_error
sub ax,bx
mov cx,ax
cmp cx,0
jbe Exit_getTwo_error
clc
jmp exit_GetTwo
;cx=length
exit_GetTwo_error:
stc
exit_GetTwo:
ret
Get_TwoOffset endp
;---------------------------------------------------------------
; Entrance: cx= The Length
; OutParam: clc-ok,ax=length
; stc-Error
;------------------------------------------------------------
Test_Para proc
cmp cx,cs:filelenl
jb fill@5
jmp exit_fillt
fill@5:
mov ax,cs:off1
cmp ax,cs:filelenl
jb fill@6
jmp exit_fillt
fill@6:
add ax,cx
cmp ax,cs:filelenl
jae exit_fillt
clc
ret
;test the parameter is valid or not
exit_fillt:
stc
ret
Test_Para endp
;-----------------------------------------------------------------
FillMess db 'Fill or Delete or Save Block <F/D/S>:',0
;-----------------------------------------------------------------
; The procedure to process the Fill or Delete the block
;-----------------------------------------------------------------
Do_Fill proc
pushall
call Get_TwoOffset
jnc fill@4
jmp exit_fill
fill@4:
push cx
mov cl,0bh
lea si,fillmess
mov ch,0bh
mov bh,MessageBoxColor
call write_str
fill@3:
xor ax,ax
int 16h
cmp ax,escape
jnz fill@1
pop cx
jmp exit_fill
;process esc key
fill@1:
and al,0dfh
cmp al,'F'
jz fill@2
cmp al,'D'
jz fillDel
cmp al,'S'
jnz fill@3
pop cx
call SaveBlock
jmp exit_fill
;do Save the Block
fillDel:
pop cx
inc cx
call Test_para
jc exit_fill
mov si,cs:filelenl
sub si,ax
mov bp,si
mov si,cs:off1
mov di,si
add si,cx
mov ax,cs:currentseg
mov es,ax
mov ds,ax
cld
push cx
mov cx,bp
rep movsb
pop cx
sub cs:filelenl,cx
;form new file len
mov ax,cs:filelenl
and ax,0fh
mov cs:nextchar,ax
;form the new last char number
mov ax,cs:filelenl
dec ax
mov cl,4
shr ax,cl
mov cl,4
shl ax,cl
mov cs:maxoff,ax
;form the maxlines
jmp exit_fill
fill@2:
pop cx
push cx
mov cl,0ch
lea si,offst3
mov ch,0bh
mov bh,MessageBoxColor
call write_str
mov ch,37
call setcursor
mov byte ptr cs:segg,3
call getnum
mov byte ptr cs:segg,5
pop cx
jc exit_fill
;get char
mov dx,cs:currentseg
mov es,dx
mov di,cs:off1
cld
inc cx
rep stosb
exit_fill:
mov bh,byte ptr cs:dispcolor
call clr_win
;clear the window
call redrawpager
popall
ret
Do_fill endp
;---------------------------------------------------------------------
cutst1 db 'Please input First Block : ',0
cutst2 db 'Please input First Offset: ',0
cutst3 db 'Please input Second Block :',0
cutst4 db 'Please input Second Offset:',0
;------------------------------------------------------------------------
; OutParam: stc-error
; clc-ok
; bp=second offset
; cs:off1=first offset
; cx=Length
;----------------------------------------------------------------------
Get_FourOffset proc
mov bp,8
call DrawShadow
;draw the windows with shadow
mov bp,4
loop_offcut:
cmp bp,4
jnz lopc1
lea si,cutst1
mov cl,09h
jmp to_alopc
lopc1:
cmp bp,3
jnz lopc2
lea si,cutst2
mov cl,0ah
jmp to_alopc
lopc2:
cmp bp,2
jnz lopc3
lea si,cutst3
mov cl,0bh
jmp to_alopc
lopc3:
cmp bp,1
jnz to_alopc
lea si,cutst4
mov cl,0ch
to_alopc:
mov bh,MessageBoxColor
mov ch,0bh
call write_str
mov ch,39
call setcursor
push bp
call getnum
pop bp
jnc ok_ut
jmp exit_cuttwo_error
ok_ut:
cmp bp,4
jnz slop1
mov cs:firstb,ax
jmp to_sex
slop1:
cmp bp,3
jnz slop2
mov cs:firsto,ax
jmp to_sex
slop2:
cmp bp,2
jnz slop3
mov cs:secb,ax
jmp to_sex
slop3:
cmp bp,1
jnz to_sex
mov cs:seco,ax
to_sex:
dec bp
jz exit_cutoff
jmp loop_offcut
exit_cutoff:
mov ax,cs:firstb
mov cx,cs:secb
cmp ax,cx
ja exit_cutTwo_error
cmp cx,cs:totalblock
ja exit_cutTwo_error
mov ax,cs:firstb
or ax,ax
jz exit_cutTwo_error
mov ax,cs:firsto
cmp ax,maxreadfile
jb get_yh1c
jmp exit_cuttwo_error
get_yh1c:
mov bx,cs:seco
cmp bx,maxreadfile
ja exit_cutTwo_error
dec cs:firstb
dec cs:secb
mov ax,cs:firstb
mov cx,maxreadfile
mul cx
clc
add ax,cs:firsto
adc dx,0
mov cs:firstb,dx
mov cs:firsto,ax
;start file offset
mov ax,cs:secb
mov cx,maxreadfile
mul cx
clc
add ax,cs:seco
adc dx,0
clc
sub ax,cs:firsto
sbb dx,cs:firstb
clc
inc ax
adc dx,0
;inc a byte
mov cs:secb,dx
mov cs:seco,ax
;length
clc
jmp exit_CutTwo
;cx=length
exit_cutTwo_error:
stc
exit_CutTwo:
ret
Get_FourOffset endp
;---------------------------------------------------------------
; The procedure cut the file
; Entrance: None
; Outparam: None
;--------------------------------------------------------------
FirstB dw 0
FirstO dw 0
Seco dw 0
SecB dw 0
;-------------------------------------------------------------
Do_Cut proc
pushall
call save_scr
;save the screen
call Get_fourOffset
jnc fill@4c
jmp exit_cut
fill@4c:
mov cl,0dh
call OpenFile
jc exit_cut
mov bp,bx
;bp=handle
mov bx,cs:handle
mov ax,4200h
mov cx,cs:firstb
mov dx,cs:firsto
int 21h
jc exit_cut
loop_cut:
mov ax,cs:currentbuffseg
mov ds,ax
mov ah,3fh
mov bx,cs:handle
mov cx,400
xor dx,dx
int 21h
jc exit_cut
mov cx,ax
or cx,cx
jz exit_cut
clc
sub cs:seco,cx
sbb cs:secb,0
jnc cut_ok
add cs:seco,cx
mov cx,cs:seco
mov bx,bp
mov ah,40h
int 21h
jmp exit_cut
;write the tail
cut_ok:
push cx
mov bx,bp
mov ah,40h
int 21h
pop cx
jc exit_cut
jmp loop_cut
exit_cut:
mov bx,bp
mov ah,3eh
int 21h
;close the file
call pop_scr
popall
ret
do_cut endp
;----------------------------------------------------------------
; The procedure draw the error message
; Entrance: si=the errormsg offset
; OUtparam: none
;---------------------------------------------------------------
DrawError proc
; mov bp,3
; push si
; call DrawShadow
; pop si
;draw windows
mov cx,0b0ch
mov bh,2fh
call write_str
xor ah,ah
int 16h
ret
DrawError endp
;-----------------------------------------------------------------
f10File db 64
db ?
db 64 dup(0)
;the save file buffer
f10mess db 'Please input Save File name:',0
f10Wait db 'The Program Change Hex file to Ascii File,Wait...',0
f10Error db 'Error:The Offset is Invalid,Program Abort...',0
handle2 dw 0
f10buffer dw 0
changeNum dw 0
LineChar db 0dh,0ah
Destfile db 09h,'(c) Copyright YuHuan & LXF,1996,BeiJing,(r)'
db ' All rights reserved,.',0dh,0ah
db 09h,'The Source File:',09h
destLen equ $-offset DestFile
destseg dw 0
destOff dw 0
CutChar db ':',0
;-------------------------------------------------------------
; The procedure change the HEX file to the Ascii file
;------------------------------------------------------------
Do_F10 proc
pushall
; call Save_scr
mov cs:destoff,0
mov cs:destseg,0
; init the offset
mov bp,4
call drawShadow
; Draw the window
mov cl,09h
call OpenFile
jnc to_cf
jmp exit_cf
to_cf:
mov byte ptr cs:ToFileF,1
mov cs:changeNum,0
mov cs:handle2,bx
;set the write to file flag
lea dx,DestFile
mov cx,DestLen
mov ah,40h
int 21h
;write the file header
mov di,offset file
add di,2
mov cl,byte ptr cs:[di-1]
xor ch,ch
mov dx,di
mov ah,40h
int 21h
mov ah,40h
lea dx,linechar
mov cx,2
int 21h
;write the file name to dest file
call WriteAdd
mov cl,0bh
lea si,f10Wait
mov ch,0bh
mov bh,MessageBoxColor
or bh,0fh
call write_str
;show the wait message
mov bx,cs:handle
mov ax,4200h
xor cx,cx
xor dx,dx
int 21h
lea di,f10file
add di,2
mov byte ptr cs:[di],20h
mov byte ptr cs:[di-1],09h
inc di
loop_change:
mov bx,cs:handle
mov ah,3fh
mov cx,1
push cs
pop ds
lea dx,f10buffer
int 21h
;Read the Souce file every Byte
jc exit_change
or ax,ax
jz exit_change
mov al,byte ptr cs:f10buffer
cmp al,20h
jb not_asciilow
cmp al,80h
jae not_asciilow
mov byte ptr cs:[di],al
jmp to_allasc
not_asciilow:
mov byte ptr cs:[di],'.'
to_allasc:
inc di
;store the byte to buffer for ascii write
call dispchar
mov bx,cs:handle2
mov dx,offset charStore
mov cx,3
push cs
pop ds
mov ah,40h
int 21h
;Write the Exchange Byte to Dest file
; call ChangeAndWrite
jc exit_change
inc cs:changenum
cmp cs:changenum,16
jnz to_nc
lea di,f10file
add di,2
mov dx,di
mov cx,17
mov ah,40h
int 21h
inc di
;skip the 09h char
;write the ascii char
lea dx,LineChar
mov cx,2
mov ah,40h
int 21h
jc exit_change
mov cs:changenum,0
add cs:destoff,16
adc cs:destseg,0
call WriteAdd
; write the address seg:off
to_nc:
jmp loop_change
exit_change:
cmp cs:changenum,0
jz to_exitch
mov bx,cs:handle2
mov cx,10h
sub cx,cs:changenum
inc cx
shl cx,1
lea dx,datewinspace
mov ah,40h
int 21h
;write some space
mov cx,cs:changenum
add cx,2
lea dx,f10file
inc dx
mov ah,40h
int 21h
;write the last line ascii chars
to_exitch:
mov bx,cs:handle2
mov ah,3eh
int 21h
;close the file
exit_cf:
mov byte ptr cs:toFileF,0
;clear the flag
; call pop_scr
call redrawpager
popall
ret
do_f10 endp
;----------------------------------------------------------------
; The procedure change the Hex byte to ascii and write to file
; Entrance: AL= byte to change and write
;---------------------------------------------------------------
ChangeAndWrite proc
call dispchar
mov bx,cs:handle2
mov dx,offset charStore
mov cx,2
push cs
pop ds
mov ah,40h
int 21h
;Write the Exchange Byte to Dest file
ret
ChangeAndWrite endp
;----------------------------------------------------------------
; The procedure change the ax to ascii mode and write to the file
; Entrance: Ax= word
;---------------------------------------------------------------
WriteWordToFile proc
xchg ah,al
push ax
call ChangeAndWrite
pop ax
xchg ah,al
call ChangeAndWrite
ret
WriteWordToFile endp
;----------------------------------------------------------------
; The procedure write the seg:off to file
;---------------------------------------------------------------
SpaceChar db 4 dup(20h),0
;--------------------------------------------------------------
WriteAdd proc
mov ax,cs:destseg
call WriteWordToFile
mov ah,40h
lea dx,CutChar
mov cx,1
int 21h
; write the ':'
mov ax,cs:destoff
call WriteWordToFile
; write the Seg:Off to the file
mov ah,40h
lea dx,SpaceChar
mov cx,2
int 21h
ret
WriteAdd endp
;-----------------------------------------------------------------
; The Procedure Save the Block to the File
; Entrance: None
; OutParam: None
;----------------------------------------------------------------
SaveBlock proc
push cx
call Test_para
pop cx
jnc f10ok2
lea si,f10error
call DrawError
;show the error msg
jmp exit_f10
;test the para is valid or not
f10ok2:
push cx
mov cl,0ch
call OpenFile
jmp EndOpenF
;--------------------------------------------------------------------------
OpenFile proc
lea si,f10mess
mov ch,0bh
mov bh,MessageBoxColor
call write_str
mov ch,40
call setcursor
push cs
pop ds
lea dx,f10file
mov si,dx
call Get_str
cmp byte ptr cs:[si+1],0
jz exit_f10
mov cl,byte ptr cs:[si+1]
add si,2
xor ch,ch
add si,cx
mov byte ptr cs:[si],0
mov ah,3ch
lea dx,f10file
add dx,2
mov cx,0
int 21h
jc exit_openf
mov bx,ax
exit_openf:
ret
OpenFile endp
EndOpenF:
pop cx
inc cx
push ds
mov ah,40h
mov dx,cs:currentseg
mov ds,dx
mov dx,cs:off1
int 21h
pop ds
jc exit_f10
mov ah,3eh
int 21h
exit_f10:
mov byte ptr cs:saveinmess,1
;restore the flag
ret
SaveBlock endp
;------------------------------------------------------------------------
Offsetfind db 'The Data in the last page,it is at offset: '
db ' | Esc--Exit ',0
AtLastF db 0
;------------------------------------------------------------------------
; The procedure re-draw the page of screen
;-----------------------------------------------------------------------
redrawpager proc
mov byte ptr cs:atlastf,0
;Clear the last page flag
; mov bh,byte ptr cs:dispcolor
; call clr_win
mov ax,word ptr cs:pagerr.upl
cmp byte ptr cs:f88,1
jz do_f88
jmp next_p1
do_f88:
push ax
add ax,160h
cmp ax,cs:maxoff
pop ax
jbe next_p1
mov byte ptr cs:atlastf,1
;Set the last page flag
mov ax,cs:maxoff
cmp word ptr cs:nextchar,0
jz to_nonextc
add ax,10h
to_nonextc:
sub ax,160h
push ax
lea si,offsetfind
mov cl,24
mov ch,0
mov bh,4eh
call write_str
pop ax
mov cl,24
mov ch,45
mov bh,0fh
push ax
mov ax,cs:pagerr.upl
call dispword
pop ax
;test the offset is to file end or not
next_p1:
mov cx,0a02h
mov bh,07h
and ax,0fff0h
mov word ptr cs:pagerr.upl,ax
mov word ptr cs:pagerr.downl,ax
call disppage
ret
redrawpager endp
;------------------- The Next is Edit Procedure -------------------------+
ColMove STRUC
; Name Byte Position
HexAddrl db ? ;0
HexAddrh db ? ;1
AscAddr db ? ;2
ColNum db ? ;3
NextColPoint dw ? ;4
PrevColPoint dw ? ;6
ColMove ENDS
;The struct of edit,is the Cycle Linker
;----------------------------------------------------------------------+
HexAddrlp equ 0
HexAddrhp equ 1
AscAddrp equ 2
ColNump equ 3
NextColPointp equ 4
PrevColPointp equ 6
maxrow equ 23
minrow equ 2
;-----------------------------------------------------------------------
CurrentCol db 0
CurrentRow db 0
CurrentP dw offset col1
HasChanged dw 0
;Globle Var.
InAscZone dw 0
currentbuffseg dw 0
bufferlen dw 0
NewFile db 'YH.LXF',0
NewFileMess db 'The Old File Backup to [YH.LXF]',0
;-----------------------------------------------------------------------
col1 ColMove <10,11,62,1,offset col2,offset col0 >
col2 ColMove <13,14,63,2,offset col3,offset col1>
col3 ColMove <16,17,64,3,offset col4,offset col2 >
col4 ColMove <19,20,65,4,offset col5,offset col3 >
col5 ColMove <22,23,66,5,offset col6,offset col4 >
col6 ColMove <25,26,67,6,offset col7,offset col5 >
col7 ColMove <28,29,68,7,offset col8,offset col6 >
col8 ColMove <31,32,69,8,offset col9,offset col7 >
col9 ColMove <36,37,70,9,offset cola,offset col8 >
cola ColMove <39,40,71,10,offset colb,offset col9>
colb ColMove <42,43,72,11,offset colc,offset cola>
colc ColMove <45,46,73,12,offset cold,offset colb>
cold ColMove <48,49,74,13,offset cole,offset colc>
cole ColMove <51,52,75,14,offset colf,offset cold>
colf ColMove <54,55,76,15,offset col0,offset cole>
col0 ColMove <57,58,77,16,offset col1,offset colf>
;Initilize the Cycle Linker
;----------------------------------------------------------
Do_Edit proc
lea si,overmess
mov cl,0
mov ch,69
mov bh,20h
call write_str
;show the status
mov cx,0018h
mov bh,2fh
lea si,editbo
call write_str
;Write the Bottom Message
Re_editp:
mov word ptr cs:haschanged,0
mov byte ptr cs:currentcol,10
mov byte ptr cs:currentrow,2
mov word ptr cs:currentp,offset col1
mov word ptr cs:InAscZone,0
;init the val
call seteditcursor
push es
push ds
mov ax,cs:currentseg
mov ds,ax
mov ax,cs:currentbuffseg
mov es,ax
xor di,di
mov ax,cs:pagerr.upl
mov si,ax
mov cx,cs:pagerr.downl
sub cx,ax
mov cs:bufferlen,cx
cld
rep movsb
;save the edit buffer for esc fuction
pop ds
pop es
next_edit:
call ShowBigCursor
mov ah,0
int 16h
cmp ax,right
jnz edit_1
call do_editright
jmp next_edit
edit_1:
cmp ax,left
jnz edit_2
call do_editleft
jmp next_edit
edit_2:
cmp ax,escape
jnz edit_3
cmp cs:haschanged,1
jz to_notrest
call do_editesc
to_notrest:
call HideCursor
call redrawpager
jmp edit_exit
edit_3:
cmp ax,up
jnz edit_4
call do_editup
jmp next_edit
edit_4:
cmp ax,down
jnz edit_5
call do_editdown
jmp next_edit
edit_5:
cmp ax,EnterChar
jnz edit_6
call do_Enter
mov cs:haschanged,1
;set the changed flag
jmp next_edit
edit_6:
cmp ax,Tab
jnz edit_7
cmp word ptr cs:inasczone,0
jz tab_1
mov word ptr cs:inasczone,0
call do_Tab
jmp next_edit
tab_1:
mov word ptr cs:inasczone,1
call do_Tab
jmp next_edit
edit_7:
cmp ax,del
jnz edit_9
mov cs:haschanged,1
call do_editdel
jmp next_edit
edit_9:
cmp ax,insert
jnz edit_a
cmp cs:insertflag,0
jz insert_1
mov cs:insertflag,0
jmp insert_2
insert_1:
mov cs:insertflag,1
mov cs:haschanged,1
insert_2:
call do_editins
jmp next_edit
edit_a:
cmp ax,pgup
jnz edit_a1
call HideCursor
call do_pgup
jmp re_editp
edit_a1:
cmp ax,pgdn
jnz edit_a2
call HideCursor
call do_pgdn
jmp re_editp
;if is Pgup/Pgdn,Scrool page first
;then do edit
edit_a2:
cmp ax,home
jnz edit_a3
call HideCursor
call do_home
jmp re_editp
edit_a3:
cmp ax,ender
jnz edit_a4
call HideCursor
call do_end
jmp re_editp
;if is Home/End,scrool page first,the edit it
edit_a4:
cmp al,20h
jae exit_b
jmp next_edit
exit_b:
cmp al,80h
jb exit_c
jmp next_edit
exit_c:
cmp cs:inasczone,0
jz edit_8
call do_editascchar
jmp next_edit
edit_8:
call do_editchar
jmp next_edit
edit_exit:
lea si,insertmess
mov cl,0
mov ch,69
mov bh,2fh
call write_str
;show the status
mov cx,0018h
mov bh,0Fh
lea si,bottom
call write_str
call HideCursor
ret
do_edit endp
;-------------------------------------------------------------
; the procedure set the correct cursor in Edit mode
;-------------------------------------------------------------
Seteditcursor proc
mov cl,byte ptr cs:currentrow
mov ch,byte ptr cs:currentcol
call setcursor
ret
seteditcursor endp
;----------------------------------------------------------------
do_editesc proc
push ds
push es
mov ax,cs:currentbuffseg
mov ds,ax
mov ax,cs:currentseg
mov es,ax
xor si,si
mov di,cs:pagerr.upl
mov cx,cs:bufferlen
cld
rep movsb
;restore the buffer with the old value
pop es
pop ds
ret
do_editesc endp
;--------------------------------------------------------------------
; The process the left key in Edit mode(either in Hex Zone or in Ascii
; Zone,and set correct cursor position)
;-------------------------------------------------------------------
do_editright proc
mov bx,cs:currentp
mov al,byte ptr cs:[bx]+colnum
cmp al,16
jnz not_line
cmp cs:inasczone,0
jnz do_hexasc
mov al,byte ptr cs:currentcol
mov ah,byte ptr cs:[bx]+hexaddrhp
cmp al,ah
jnz add_col
do_hexasc:
cmp byte ptr cs:currentrow,maxrow
jnz not_endpage
mov byte ptr cs:currentrow,minrow
jmp do_changep
;process the row range
not_endpage:
inc byte ptr cs:currentrow
jmp do_changep
not_line:
cmp word ptr cs:inasczone,1
jz add_col
mov al,byte ptr cs:currentcol
mov ah,byte ptr cs:[bx]+hexaddrlp
cmp al,ah
jnz do_changep
add_col:
cmp cs:inasczone,1
jz do_changep
inc byte ptr cs:currentcol
jmp left_set
do_changep:
mov ax,cs:[bx]+nextcolpointp
mov word ptr cs:currentp,ax
mov bx,cs:currentp
mov al,byte ptr cs:[bx+hexaddrlp]
mov byte ptr cs:currentcol,al
cmp cs:inasczone,0
jz left_set
mov al,byte ptr cs:[bx+ascaddrp]
mov byte ptr cs:currentcol,al
;set new point&new colnum
left_set:
call seteditcursor
ret
do_editright endp
;----------------------------------------------------------------------
do_editleft proc
mov bx,cs:currentp
mov al,byte ptr cs:[bx]+colnum
cmp al,1
jnz not_linel
cmp cs:inasczone,0
jnz left_hex
mov al,byte ptr cs:currentcol
mov ah,byte ptr cs:[bx]+hexaddrlp
cmp al,ah
jnz add_coll
left_hex:
cmp byte ptr cs:currentrow,minrow
jnz not_endpagel
mov byte ptr cs:currentrow,maxrow
jmp do_changepl
;process the row range
not_endpagel:
dec byte ptr cs:currentrow
jmp do_changepl
not_linel:
cmp cs:inasczone,1
jz add_coll
mov al,byte ptr cs:currentcol
mov ah,byte ptr cs:[bx]+hexaddrhp
cmp al,ah
jnz do_changepl
add_coll:
cmp cs:inasczone,1
jz do_changepl
dec byte ptr cs:currentcol
jmp left_setl
do_changepl:
mov ax,cs:[bx]+prevcolpointp
mov word ptr cs:currentp,ax
mov bx,cs:currentp
mov al,byte ptr cs:[bx+hexaddrhp]
mov byte ptr cs:currentcol,al
;set new point&new colnum
cmp cs:inasczone,0
jz left_setl
mov al,byte ptr cs:[bx+ascaddrp]
mov byte ptr cs:currentcol,al
left_setl:
call seteditcursor
ret
do_editleft endp
;----------------------------------------------------------
; The procedure process the up key in Edit mode
;----------------------------------------------------------
do_editup proc
cmp byte ptr cs:currentrow,minrow
jnz to_upzero
mov byte ptr cs:currentrow,maxrow
jmp show_editup
to_upzero:
dec byte ptr cs:currentrow
show_editup:
call seteditcursor
ret
do_editup endp
;---------------------------------------------------------------
; The procedure process the down key in Edit mode(Set correct cursor pos
;--------------------------------------------------------------
do_editdown proc
cmp byte ptr cs:currentrow,maxrow
jnz to_downzero
mov byte ptr cs:currentrow,minrow
jmp show_editdown
to_downzero:
inc byte ptr cs:currentrow
show_editdown:
call seteditcursor
ret
do_editdown endp
;-------------------------------------------------------------
; Entrance: dl-char
; OutParam: None
;------------------------------------------------------------
show_asciichar proc
cmp dl,20h
jbe to_dodot
cmp dl,80h
jae to_dodot1
jmp do_love
to_dodot1:
cmp dl,0a0h
jbe to_dodot
jmp do_love
to_dodot:
mov dl,'.'
do_love:
call write_char
ret
show_asciichar endp
;----------------------------------------------------------
; The Procedure move 1 byte every time
;----------------------------------------------------------
strmove proc
mov al,byte ptr ds:[si]
strmove1:
mov ah,byte ptr es:[di]
mov byte ptr es:[di],al
inc si
inc di
mov al,ah
loop strmove1
ret
strmove endp
;------------------------------------------------------------
; Entrance: ds-file buffer seg
; si-current offset
; OutParam: clc-ok
; stc-error
;------------------------------------------------------------
do_charinsert proc
push ax
push dx
push si
push ds
pop es
mov di,si
inc di
mov cx,word ptr cs:filelenl
sub cx,si
cld
push si
call strmove
;move buffer
pop si
cmp cs:filelenl,maxreadfile
jb do_ycg
stc
jmp insert_allexit
do_ycg:
inc cs:filelenl
mov ax,cs:filelenl
and ax,0fh
mov cs:nextchar,ax
;form the last char number
mov ax,cs:filelenl
dec ax
mov cl,4
shr ax,cl
mov cl,4
shl ax,cl
mov cs:maxoff,ax
;form the max lines
mov byte ptr ds:[si],0
call HideCursor
call redrawpager
call ShowBigCursor
clc
insert_allexit:
pop si
pop dx
pop ax
ret
do_charinsert endp
;--------------------------------------------------------------
insertnum dw 0
insertbig db 'Error: File is too big to insert a byte',0
;--------------------------------------------------------------
do_editchar proc
push ds
push ax
;al=the get char
mov cs:insertnum,2
mov ax,word ptr cs:filestartaddr
mov cl,4
shr ax,cl
mov cx,ax
mov ax,word ptr cs:scrseg
add ax,cx
mov ds,ax
;form the edit file start seg
cld
call form_editoffset
cmp ax,word ptr cs:filelenl
pop ax
jb lxflike
jmp exit_dochar
lxflike:
cmp cs:insertflag,0
jz do_overys1
mov bx,cs:currentp
mov ch,byte ptr cs:[bx+hexaddrlp]
mov byte ptr cs:currentcol,ch
call seteditcursor
;set cursor
call do_charinsert
jnc do_overys1
mov cs:haschanged,0
;clear the flag
push ds
push cs
pop ds
lea si,insertbig
mov cs:stop,1
call messagebox
call seteditcursor
pop ds
jmp exit_dochar
do_overys1:
cmp al,'0'
jae mt
jmp exit_dochar
mt:
cmp al,'9'
ja do_chare
mov cl,byte ptr cs:currentrow
mov ch,byte ptr cs:currentcol
mov bh,4eh
mov dl,al
call write_char
sub al,30h
jmp to_charstr
do_chare:
and al,0dfh
;little char change to Big char
cmp al,'F'
jbe do_lxff
cmp cs:insertflag,1
jz do_126
jmp exit_dochar
do_126:
call do_editdel
call seteditcursor
jmp exit_dochar
do_lxff:
cmp al,'A'
jae do_mtg
cmp cs:insertflag,1
jz do_127
jmp exit_dochar
do_127:
call do_editdel
call seteditcursor
jmp exit_dochar
;error exit
do_mtg:
mov cl,byte ptr cs:currentrow
mov ch,byte ptr cs:currentcol
mov bh,4eh
mov dl,al
call write_char
sub al,37h
;change char to number
to_charstr:
mov dl,al
mov bx,cs:currentp
mov cl,byte ptr cs:[bx+hexaddrl]
mov ch,byte ptr cs:currentcol
cmp cl,ch
jnz do_high
lodsb
and al,0fh
and dl,0fh
mov cl,4
shl dl,cl
and dl,0f0h
or dl,al
mov byte ptr ds:[si-1],dl
;store to buffer
jmp to_alowhigh
do_high:
lodsb
and al,0f0h
and dl,0fh
or al,dl
mov dl,al
mov byte ptr ds:[si-1],dl
;store to buffer
to_alowhigh:
mov bx,cs:currentp
mov cl,byte ptr cs:currentrow
mov ch,byte ptr cs:[bx+ascaddrp]
mov bh,4eh
call show_asciichar
;show the ascii code
call do_editright
cmp cs:insertflag,0
jz exit_dochar
dec cs:insertnum
jz exit_dochar
xor ah,ah
int 16h
dec si
jmp do_overys1
exit_dochar:
pop ds
ret
do_editchar endp
;--------------------------------------------------------------
do_editascchar proc
push ds
push ax
;al=the get char
mov ax,word ptr cs:currentseg
mov ds,ax
;form the edit file start seg
cld
call form_editoffset
cmp ax,word ptr cs:filelenl
pop ax
jae exit_doascchar
cmp cs:insertflag,0
jz do_xidian
call do_charinsert
jnc do_xidian
mov cs:haschanged,0
;clear the flag
push ds
push cs
pop ds
lea si,insertbig
mov cs:stop,1
call messagebox
call seteditcursor
pop ds
jmp exit_doascchar
do_xidian:
cmp al,20h
jae do_123
call do_editdel
jb exit_doascchar
do_123:
cmp al,80h
jb do_124
call do_editdel
jmp exit_doascchar
do_124:
mov cl,byte ptr cs:currentrow
mov ch,byte ptr cs:currentcol
mov bh,4eh
mov dl,al
push si
call write_char
;disp al in ascii zone
mov bx,cs:currentp
mov ch,byte ptr cs:[bx+hexaddrl]
mov cl,byte ptr cs:currentrow
mov bh,4eh
call dispchar
;disp al in hex zone
pop si
mov byte ptr ds:[si],al
;store to buffer
call do_editright
exit_doascchar:
pop ds
ret
do_editascchar endp
;-------------------------------------------------------
; Entrance: None
; OutParam: si=offset
;-----------------------------------------------------
form_editoffset proc
mov bx,cs:currentp
mov al,byte ptr cs:currentrow
sub al,2
mov cl,10h
mul cl
mov cl,byte ptr cs:[bx+colnump]
dec cl
xor ch,ch
add ax,cx
mov cx,word ptr cs:pagerr.upl
add ax,cx
mov si,ax
;ax=the file offset
ret
form_editoffset endp
;----------------------------------------------------------
do_editdel proc
push es
push ds
mov ax,word ptr cs:currentseg
mov ds,ax
;form the edit file start seg
call form_editoffset
cmp ax,cs:filelenl
jae exit_del
push ds
pop es
mov di,si
inc si
mov cx,cs:filelenl
sub cx,ax
;cx=len
rep movsb
dec cs:filelenl
mov ax,cs:filelenl
and ax,0fh
mov cs:nextchar,ax
;form the new last char number
mov ax,cs:filelenl
dec ax
and ax,0fff0h
mov cs:maxoff,ax
;form the maxlines
mov cs:haschanged,1
mov ax,cs:pagerr.upl
add ax,160h
cmp ax,cs:filelenl
jbe not_clrscr
;if is in last page,clear the screen
mov bh,byte ptr cs:dispcolor
call clr_win
;clear the window
not_clrscr:
call HideCursor
call redrawpager
;redraw the screen
call seteditcursor
exit_del:
pop ds
pop es
ret
do_editdel endp
;-----------------------------------------------------------
handle1 dw 0
saveErrormsg db 'Error: Save the File Error ..',0
;---------------------------------------------------------
do_Enter proc
push cs
pop ds
lea dx,newfile
mov ah,3ch
mov cx,0
int 21h
jnc sldf
lea si,saveErrormsg
jmp over_now2
sldf:
mov bx,ax
mov cs:handle1,ax
call CopyOldFile
;copy the old file
mov bx,cs:handle
;bx=the edit file
;------------------
mov ax,4200h
mov cx,cs:seekh
mov dx,cs:seekl
int 21h
;seek to file postion
mov ax,cs:currentseg
mov ds,ax
xor dx,dx
mov cx,word ptr cs:filelenl
mov ah,40h
int 21h
;write the current buffer to the file
lea si,newfilemess
jnc ok_enter
lea si,saveErrormsg
ok_enter:
push si
mov ah,40h
xor cx,cx
int 21h
;Cut the file end
cmp byte ptr cs:over64k,1
jnz over_now
;test file is over 64k or not
;if over 64k ,copy the last file to save
mov bp,cs:handle
mov ax,cs:writebufferseg
mov ds,ax
;form the write buffer seg
mov bx,cs:handle1
mov ax,4200h
xor Dx,cs:nextseekl
xor Cx,cs:nextseekh
int 21h
;seek the backup file correct offset
xor dx,dx
;the writebuffer offset =0
loop_copyv:
mov cx,4096
mov ah,3fh
int 21h
jc over_now1
;read the backup file
cmp ax,0
jz over_now
push bx
mov bx,bp
mov cx,ax
mov ah,40h
int 21h
pop bx
;write the data
jc over_now1
jmp loop_copyv
over_now1:
pop si
lea si,saveErrormsg
jmp over_now2
;error exit
over_now:
pop si
over_now2:
push cs
pop ds
mov cs:stop,1
call messagebox
;show the ok / error msg
call redrawpager
;re-draw the page
exit_ENter:
;------ Exchange the File Handle
mov bx,cs:handle1
mov ah,3eh
int 21h
;close the file 'yh.lxf'
mov cs:handle1,0
;clear the handle value
call seteditcursor
ret
do_enter endp
;---------------------------------------------------------
; Entrance:bx-new file handle
; OutParam:clc-ok
; stc-error
;----------------------------------------------------------
WriteBufferSeg dw 0
;---------------------------------------------------------
CopyOldFile proc
push ds
mov bp,bx
mov ax,cs:writebufferseg
mov ds,ax
;form the write buffer seg
mov bx,cs:handle
mov ax,4200h
xor cx,cx
xor dx,dx
int 21h
xor dx,dx
loop_copy:
mov cx,4096
mov ah,3fh
int 21h
jc error_exitcopy
cmp ax,0
jz exit_copy
push bx
mov bx,bp
mov cx,ax
mov ah,40h
int 21h
pop bx
jc error_exitcopy
jmp loop_copy
exit_copy:
; mov ah,3eh
; int 21h
;close the old file
mov bx,bp
mov ax,4200h
xor cx,cx
xor dx,dx
int 21h
;seek the new file head
clc
pop ds
ret
error_exitcopy:
; mov ah,3eh
; int 21h
;close the old file
stc
pop ds
ret
CopyOldFile endp
;-----------------------------------------------------------------
do_tab proc
mov bx,cs:currentp
cmp cs:inasczone,0
jnz do_asc
mov al,byte ptr cs:[bx+hexaddrlp]
jmp do_lxf0
do_asc:
mov al,byte ptr cs:[bx+ascaddrp]
do_lxf0:
mov byte ptr cs:currentcol,al
call seteditcursor
ret
do_tab endp
;---------------------------------------------------------------
insertflag dw 0
;--------------------------------------------------------------
do_editins proc
mov cl,0
mov ch,69
lea si,insmess
cmp cs:insertflag,1
jnz over_mess
mov bh,4eh
jmp mess_show
over_mess:
mov bh,20h
lea si,overmess
mess_show:
call write_str
call seteditcursor
ret
do_editins endp
;-------------------------------------------------------------
ColorTable db 07H,07h,0EH,0AH,0BH,0CH,0DH,0FH,10h,12H,13H
DB 14H,15H,16H,1AH,1EH,1CH,1DH
DB 1FH,31h,32h,30H,31h,34H,35H,36H,37H,3AH,3BH,3CH,3DH
DB 3EH,3FH,30h
DB 40h,41h,42h,43h,45H,46H,47H,4AH,4BH,4CH,4DH,4FH,50H
DB 51h,52h,53h,54h,56H,57H,5AH,5BH,5CH,5DH,5EH,5FH
db 60H,61h,62h,63h,64h,65h,67H,6AH,6BH
DB 6CH,6DH,6EH,6FH,70H,0
COLORP DB 0
;-----------------------------------------------------------
Do_F5 proc
call ChangeColor
jmp get_colorp
;--------------------------------------------------------/
; outparam: al=color
;--------------------------------------------------------
ChangeColor:
inc byte ptr cs:colorp
F5_1:
mov al,byte ptr cs:colorp
lea si,colortable
xor ah,ah
add si,ax
mov al,byte ptr cs:[si]
cmp al,0
jnz change_color
mov byte ptr cs:colorp,0
jmp f5_1
change_color:
ret
get_colorp:
mov byte ptr cs:dispcolor,al
;change disp color
call redrawpager
; mov cx,0a02h
; mov ax,cs:pagerr.upl
; mov cs:pagerr.downl,ax
; call disppage
;redraw current page
ret
do_f5 endp
;--------------------------------------------------------------------
keymess0 db 'Please press the key to get Value',0
keymess1 db 'The key Value (HEX) is: ',0
keyval dw 0
;------------------------------------------------------------------
do_F9 proc
push ds
push es
mov bh,4eh
mov cs:stop,0
lea bx,key_press
lea si,keymess0
call messagebox
;show press key
jmp key_press1
key_press:
xor ah,ah
int 16h
mov cs:keyval,ax
ret
;get key
key_press1:
lea si,keymess1
mov cs:stop,0
lea bx,keypress2
call messagebox
jmp keypress3
keypress2:
mov ax,cs:keyval
mov bh,4eh
mov cx,250bh
call dispword
xor ah,ah
int 16h
;press any key
ret
keypress3:
pop es
pop ds
ret
do_F9 endp
;--------------------------------------------------------------------
F8mess1 db 'Hex Value :',0
F8mess2 db 'Ascii Value:',0
f8sta0 db 'Hex Mode',0
f8sta1 db 'Ascii Mode',0
dohelp db 'Help: Any Key Change Mode... Enter = Continue..'
db ' |(C)YuHuan ',0
dohelp1 db '(C)Copyright Yuhuan, Enter=Go Search'
db ',Other Key=Search Value,MaxChar=16 ',0
notfindmess db ' The string can not find more... Press'
db ' any key to continue... ',0
putin db 'Input a Byte: ',0
F8Asc db 0
addrasc db 16
hexHea db 17
db ?
hexvalue db 18 dup(0)
valnum db 0
findnext db 'Any Key to Find the next item,.....Esc=Exit the '
db 'find...... >> ',0
f88 db 0
CaseMsg db 'Search Case-Sensitive: <y/n>',0
CaseF db 0
FindOffset dw 0
;------------------------------------------------------------------
Do_F8 proc
push ds
push es
call save_scr
mov si,offset f8mess1
mov di,offset putin
call chkcode
xor al,al
; mov cl,24
; mov ch,0
; mov bh,4eh
; call dispword
; xor ax,ax
; int 16h
; debug
; diaply the check code
sub ah,0d3h
cli
mov bx,ss
add bx,ax
; mov ss,bx ; This code can halt the system!!!
sti
;Test the message has change or not
;Untrace the hacker (********)
mov bh,1fh
call clrscr
;clear the screen
mov byte ptr cs:f8asc,1
mov byte ptr cs:addrasc,16
mov byte ptr cs:valnum,0
;Init the Flag value
push cs
pop ds
push cs
pop es
;init the segment register
mov cl,24
mov ch,0
mov bh,17h
lea si,dohelp
call write_str
lea si,f8sta1
mov cx,2501h
mov bh,4eh
call Write_str
;show the ascii/hex mode msg
abc2:
xor ah,ah
int 16h
;test change to ascii zone or not
mov cx,2501h
cmp ax,enterchar
jz next_f8
cmp byte ptr cs:f8asc,0
jz abc1
mov byte ptr cs:f8asc,0
lea si,f8sta0
call Write_str
jmp abc2
abc1:
mov byte ptr cs:f8asc,1
lea si,f8sta1
call Write_str
jmp abc2
;get the mode
next_f8:
lea si,dohelp1
mov cl,24
mov ch,0
mov bh,2fh
call write_str
mov bh,1eh
lea si,f8mess1
mov cx,0305h
call write_str
lea si,f8mess2
mov cx,0307h
call write_str
;show message
lea di,hexvalue
cld
cmp byte ptr cs:f8asc,1
jnz f8_1@
;do ascii
loop_f81:
mov cl,7
mov ch,byte ptr cs:addrasc
call setcursor
;Set the Cursor
lea dx,hexHea
call Get_str
mov cl,byte ptr cs:[hexHea+1]
mov byte ptr cs:valnum,cl
or cl,cl
jz to_jmpsta
lea si,hexHea
add si,2
xor ch,ch
add si,cx
mov byte ptr cs:[si],0
to_jmpsta:
;get ascii value to search
mov byte ptr cs:CaseF,0
mov cx,0309h
lea si,CaseMsg
mov bh,1eh
call Write_str
mov ah,0
int 16h
and al,0dfh
cmp al,'N'
jnz Not_case
lea si,HexHea
inc si
mov byte ptr cs:cAseF,1
;set the case flag
loop_case:
inc si
mov al,byte ptr cs:[si]
or al,al
jz not_case
cmp al,'a'
jb loop_case
cmp al,'z'
ja loop_case
and al,0dfh
mov byte ptr cs:[si],al
jmp loop_case
;Change the small to big char
not_case:
jmp f8_stasearch
; cmp al,0dh
; jnz abh
; jmp F8_stasearch
; abh:
; cmp al,20h
; jb loop_f81
; cmp al,80h
; jae loop_f81
; ;if =enter,exit to search
; ascstt:
; push ax
; mov ah,0eh
; mov bx,3
; int 10h
; pop ax
; ;show ascii
; stosb
; mov bh,07h
; mov cl,5
; call dispchar
; add byte ptr cs:addrasc,3
; inc byte ptr cs:valnum
; cmp byte ptr cs:valnum,16
; jae f8_stasearch
; ;max number=16
; jmp loop_f81
f8_1@:
;do hex
mov cl,15
mov ch,9
lea si,putin
mov bh,1eh
call write_str
mov ch,17h
call setcursor
mov byte ptr cs:segg,3
push di
call getnum
pop di
jc f8_stasearch
cmp byte ptr cs:nocharflag,1
jz f8_stasearch
stosb
mov bh,07h
mov cl,5
mov ch,byte ptr cs:addrasc
call dispchar
mov cl,7
cmp al,20h
ja f8_2@
mov al,'.'
jmp f8_3@
f8_2@:
cmp al,80h
jb f8_3@
mov al,'.'
f8_3@:
call setcursor
mov ah,0eh
mov bx,3
int 10h
;show hex
add byte ptr cs:addrasc,3
inc byte ptr cs:valnum
cmp byte ptr cs:valnum,16
jae f8_stasearch
;max num=16
jmp f8_1@
f8_stasearch:
cmp byte ptr cs:f8asc,1
jz f8_aa
mov byte ptr cs:segg,5
;restore the old val.
f8_aa:
mov cl,byte ptr cs:valnum
xor ch,ch
mov cx,cs:filelenl
xor di,di
mov ax,cs:currentseg
mov es,ax
last_find:
lea si,hexvalue
xor dx,dx
loop_cmp:
mov al,byte ptr es:[DI]
cmp byte ptr cs:[casef],0
jz next_case
cmp al,'a'
jb next_case
cmp al,'z'
ja next_case
and al,0dfh
;test al is ascii char or not
;if is char and is small char
;change it to big now
next_case:
mov ah,byte ptr cs:[si]
cmp al,ah
jnz not_lop
inc si
inc di
inc dx
cmp dl,byte ptr cs:valnum
jz ok_find
loop loop_cmp
not_lop:
lea si,hexvalue
sub di,dx
inc di
add cx,dx
xor dx,dx
loop loop_cmp
;not find
mov cl,24
mov ch,0
mov bh,70h
lea si,notfindmess
call write_str
;show not find message
xor ah,ah
int 16h
call pop_scr
jmp exit_f8
ok_find:
xor dh,dh
mov ax,di
sub ax,dx
mov word ptr cs:FindOffset,ax
; Save the find offset,YuHuan,2001-04-15,BeiJing.
call pop_scr
mov ax,di
sub ax,dx
mov cs:pagerr.upl,ax
push di
push cx
mov byte ptr cs:f88,1
call redrawpager
mov byte ptr cs:f88,0
pop cx
pop di
or cx,cx
jz exit_f8
cmp byte ptr cs:atlastf,1
jz to_do_atlast
push cx
push di
lea si,findnext
mov cl,24
mov ch,0
mov bh,4eh
call write_str
;show new bottom message
mov cl,24
mov ch,72
mov cs:tofilef,0
mov ax,word ptr cs:FindOffset
; dec ax
mov bh,4eh
call dispword
; show the find offset,YuHuan,2001-04-15,BeiJing
pop di
pop cx
to_do_atlast:
xor ah,ah
int 16h
cmp ax,escape
jz exit_f8
;esc=exit find
call save_scr
jmp last_find
;find next item
exit_f8:
mov cx,0018h
mov bh,0Fh
lea si,bottom
call write_str
;show old bottom message
pop es
pop ds
ret
do_f8 endp
;-----------------------------------------------------------------
; The procedure show the Exit Message
;----------------------------------------------------------------
Exit_message proc
; mov bh,17h
; call clrscr
; mov cs:stop,1
; lea si,copy
; call messagebox
mov ah,6
mov al,1
mov bh,07h
mov ch,24
mov cl,0
mov dh,24
mov dl,79
int 10h
mov cl,24
mov ch,0
call setcursor
mov cl,24
mov ch,0
mov bh,07h
lea si,copy1
call write_str
; show the message first
mov ch,32
lea si,yc
mov bh,0fh
call write_str
; show the copyright
mov ch,52
lea si,yi
mov bh,07h
call write_str
; show the message end
ret
Exit_message endp
;------------------------------------------------------------------
; Entrance: bh-Attri
;-----------------------------------------------------------------
Clr_win proc
mov ah,6
mov al,22
; mov bh,17h
mov cx,0200h
mov dh,23
mov dl,78
int 10h
;scrool the window
ret
Clr_Win endp
;-------------------------------------------------------------------
; Entrance: Ds:dx-offset
;-------------------------------------------------------------------
ccol db 0
crow db 0
;------------------------------------------------------------------
Get_str proc
pushall
push ds
pop es
mov di,dx
mov si,dx
add di,2
mov byte ptr ds:[si+1],0
cld
str_loop:
xor ah,ah
int 16h
cmp al,0dh
jnz str1
stosb
clc
jmp exit_str
str1:
cmp ax,escape
jz do_esct
cmp al,8
jz do_backsp
cmp al,20h
jb str_loop
cmp al,80h
jae str_loop
mov ah,byte ptr ds:[si]
dec ah
cmp ah,byte ptr ds:[si+1]
jbe str_loop
;wait for enter
stosb
mov ah,0eh
mov bx,3
int 10h
inc byte ptr ds:[si+1]
mov ah,3
int 10h
mov byte ptr cs:crow,dh
mov byte ptr cs:ccol,dl
;get cursor position
jmp str_loop
do_backsp:
cmp byte ptr ds:[si+1],0
jbe str_loop
mov dh,byte ptr cs:crow
mov dl,byte ptr cs:ccol
dec dl
mov ah,2
mov bx,3
int 10h
mov ah,0eh
mov al,20h
int 10h
mov dl,byte ptr cs:ccol
dec dl
mov ah,2
int 10h
dec di
dec byte ptr ds:[si+1]
dec byte ptr cs:ccol
jmp str_loop
do_esct:
stc
mov byte ptr ds:[si+1],0
;do esc
exit_str:
popall
ret
get_str endp
;------------------------------------------------------------------
f3mess0 db 'Please input Load file name:',0
f3mess db 'Error: Load file is not successfully..',0
f3mess1 db 'Load--(Overwrite/Insert): ',0
f3mess2 db 'Insert File now,please Wait..',0
f3Len dw 0
;------------------------------------------------------------------
do_f3 proc
pushall
; mov bh,1fh
; call clr_win
;clear the windows
mov bp,8
call DrawShadow
;draw the windows with shadow
mov cl,09h
lea si,offst1
mov bp,2
mov ch,07h
mov bh,MessageBoxColor
call write_str
mov ch,37
call setcursor
call getnum
;get the offset
jnc f3_4
jmp exit_f3
f3_4:
mov cs:off1,ax
;Get offset
cmp ax,0fe00h
jb f3_6
jmp exit_f3
;offset must < 0fe00h
f3_6:
push cs
pop ds
mov cl,0bh
lea si,f3mess0
mov ch,07h
mov bh,MessageBoxColor
call write_str
mov ch,37
call setcursor
push cs
pop ds
lea dx,f10file
mov si,dx
call Get_str
cmp byte ptr cs:[si+1],0
jnz f3_5
jmp exit_f3
;get the file name
f3_5:
mov cl,byte ptr cs:[si+1]
add si,2
xor ch,ch
add si,cx
mov byte ptr cs:[si],0
mov ax,3d00h
lea dx,f10file
add dx,2
mov cx,0
int 21h
jnc f3_9
jmp exit_f3
f3_9:
;Open file
mov bx,ax
mov ax,4202h
xor cx,cx
xor dx,dx
int 21h
;get the file length
OR DX,DX
JNZ F3_L
mov bp,ax
cmp ax,0d000h
jbe f3_1
F3_L:
mov bp,0d000h
f3_1:
;read max=0fe00h bytes
mov ax,4200h
xor cx,cx
xor dx,dx
int 21h
mov cx,bp
mov ax,cs:writebufferseg
mov ds,ax
xor dx,dx
mov ah,3fh
int 21h
jnc f3_8
jmp exit_f3
f3_8:
mov cx,ax
mov cs:f3Len,ax
mov ah,3eh
int 21h
;close the file
push cs
pop ds
mov cl,0ch
lea si,f3mess1
mov ch,07h
mov bh,MessageBoxColor
call write_str
;disp insert/overwirte message
mov ch,45
call setcursor
to_fk:
xor ah,ah
int 16h
cmp ax,escape
jnz f3_ab
jmp exit_f31
f3_ab:
and al,0dfh
cmp al,'O'
jnz f3_g
jmp do_f3O
f3_g:
cmp al,'I'
jnz to_fk
;do Insert mode
push cs
pop ds
mov cl,0dh
lea si,f3mess2
mov ch,07h
mov bh,02fh
call write_str
;disp wait message
mov ax,cs:f3Len
mov cx,cs:off1
add ax,cx
cmp ax,0fe00h
jbe f3_c
jmp exit_f3
f3_c:
mov ax,cs:off1
mov cx,cs:filelenl
cmp ax,cx
jbe f3_d
mov cx,cs:f3Len
add ax,cx
cmp ax,0fe00h
jbe f3_f
mov ax,0fe00h
f3_f:
mov cs:filelenl,ax
jmp do_f3O
f3_d:
mov ax,cs:filelenl
mov cx,cs:f3Len
add ax,cx
mov cs:filelenl,ax
;form the new len
cmp ax,0fe00h
jbe f3_a
mov cs:filelenl,0fe00h
f3_a:
cld
mov si,cs:off1
mov di,si
inc di
mov ax,cs:currentseg
mov ds,ax
mov es,ax
mov bp,cs:F3LEN
mov cx,cs:filelenl
sub cx,si
f3_b:
push si
push di
push cx
call strmove
pop cx
pop di
pop si
inc si
inc di
pushall
mov ax,bp
mov bh,MessageBoxColor
mov cx,300dh
call dispword
popall
;disp the move bytes
dec bp
jnz f3_b
;move date for more room
call overwritedo
jmp f3_2
do_f3O:
;do Overwrite mode
call overwritedo
jmp f3@
overwritedo:
mov ax,cs:writebufferseg
mov ds,ax
xor si,si
mov cx,cs:f3Len
mov ax,cs:currentseg
mov es,ax
mov di,cs:off1
cld
rep movsb
;move the buffer date
ret
f3@:
mov ax,cs:off1
add ax,word ptr cs:f3Len
cmp ax,cs:filelenl
jbe f3_2
mov cs:filelenl,ax
cmp ax,0fe00h
jbe f3_2
mov cs:filelenl,0fe00h
f3_2:
mov ax,cs:filelenl
and ax,0fh
mov cs:nextchar,ax
;form the new last char number
mov ax,cs:filelenl
dec ax
mov cl,4
shr ax,cl
mov cl,4
shl ax,cl
mov cs:maxoff,ax
;form the maxlines
jmp exit_f31
exit_f3:
mov cs:stop,1
lea si,f3mess
call messagebox
exit_f31:
mov bh,1fh
call clr_win
;clear the windows
mov cs:pagerr.upl,0
call redrawpager
popall
ret
do_f3 endp
;-------------------------------------------------------------------
; Entrance: si--start offset,di-End offset
; Outparam: ah=checkcode
;------------------------------------------------------------------
ChkCode proc
mov ah,0
mov cx,di
sub cx,si
chksum:
mov al,byte ptr cs:[si]
add ah,al
inc si
loop chksum
;Get Checksum
ret
ChkCode endp
;;-----------------------------------------------------------------
; The procedure dare the background of windows
; Entrance: cl-x
; ch-y
; bp=total lines
; Outparam: None
;-----------------------------------------------------------------
Draw_back proc
mov ch,byte ptr cs:ScrStartpos
to_dispachar:
push cx
call Get_CharAttri
mov bh,byte ptr cs:getcolor
; and bh,0Fh
mov bh,01h
mov dl,byte ptr cs:getchar
call Write_char
pop cx
inc ch
cmp ch,77
jnz to_dispachar
inc cl
dec bp
jnz draw_back
ret
Draw_back endp
;;-----------------------------------------------------------------
; The procedure dare the foreground of windows
; Entrance: cl-x
; ch-y
; bp=total lines
; bh=color
; Outparam: None
;-----------------------------------------------------------------
Draw_Fore proc
lea si,datewinspace
mov ch,byte ptr cs:ScrStartpos
push cx
call write_str
pop cx
inc cl
dec bp
jnz draw_fore
ret
Draw_Fore endp
;------------------------------------------------------------------
ScrStartpos db 0
;-----------------------------------------------------------------
; The procedure draw the windows with shadow
; Entrance: bp= loop lines
; Outparam: None
;----------------------------------------------------------------
DrawShadow proc
mov cl,9
; mov bh,07h
mov byte ptr cs:scrstartpos,7
push bp
call Draw_back
pop bp
;draw bakcground
mov cl,8
mov bh,30h
;the color
mov byte ptr cs:scrstartpos,5
call draw_fore
;draw foreground
ret
DrawShadow endp
;------------------------------------------------------------------
E241 db 'Disk write protected',0
E242 db 'Unknow Unit',0
E243 db 'Disk is not ready',0
E244 db 'Unrecognize command',0
E245 db 'Bad CRC',0
E246 db 'Required Struct Error',0
E247 db 'Search Error',0
E248 db 'Invalid Media type',0
E249 db 'Sector not found',0
E240 db 'Out of Paper',0
E24A db 'Write disk error',0
E24B db 'Read disk error',0
E24C db 'General error',0
E24D db 'Invalid change disk',0
E24O dw offset E241
dw offset E242
dw offset E243
dw offset E244
dw offset E245
dw offset E246
dw offset E247
dw offset E248
dw offset E249
dw offset E24A
dw offset E24B
dw offset E24C
dw 0
dw 0
dw offset E24D
dw 0
laster db 0ffh
disper db 0
;-------------------------------------------------------------------
; The procedure process the int 24h of dos
;-------------------------------------------------------------------
new24h proc
lea si,E24O
mov bx,di
xor bh,bh
cmp byte ptr cs:laster,bl
jz to_dispornot
mov byte ptr cs:laster,bl
jmp to_diso
to_dispornot:
cmp byte ptr cs:disper,0
jz to_diso
jmp not_disp24
to_diso:
mov byte ptr cs:disper,1
shl bx,1
mov si,word ptr cs:[bx+si]
or si,si
jz not_disp24
push cs
pop ds
mov cs:stop,1
call messagebox
not_disp24:
mov al,3
;Call error....return code
iret
new24h endp
;-------------------------------------------------------------------/
Get_commandline proc
cmp byte ptr ds:[80h],0
jz get_commandexit
push cs
pop es
mov di,offset file
mov cl,byte ptr ds:[80h]
mov byte ptr es:[di+1],cl
add di,2
cld
mov si,81h
loop_commandline:
lodsb
cmp al,0dh
jz to_cend
cmp al,20h
jz loop_commandline
cmp al,09h
jz loop_commandline
stosb
jmp loop_commandline
to_cend:
mov al,0
stosb
mov byte ptr cs:commandline,1
get_commandexit:
ret
Get_commandline endp
;---------------------------------------------------------------------
Asciimess db ' The Ascii Chart,(c) Copyright YuHuan & LXF',0
AsciiHead db ' 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F ',0
AsciiBuffer db 0,0
AsciiRow db 0
AsciiCol db 0
;---------------------------------------------------------------------
ShowAscii proc
pushall
call Save_Scr
mov bp,20
mov cl,4
mov byte ptr cs:scrstartpos,7
push bp
call Draw_back
pop bp
;draw bakcground
mov cl,3
mov bh,70h
;the color
mov byte ptr cs:scrstartpos,5
call draw_fore
;draw foreground
; Draw the windows with Shadow
lea si,AsciiMess
mov bh,74h
mov cl,4
mov ch,18
call Write_str
; show copyright
lea si,AsciiHead
mov bh,71h
mov cl,5
mov ch,15
call Write_Str
; draw the ascii head
mov cx,0
mov bp,0
mov byte ptr cs:ToFileF,0
mov byte ptr cs:AsciiRow,6
mov Byte ptr cs:AsciiCol,16
mov byte ptr cs:Asciibuffer,0
loopascii:
mov al,byte ptr cs:AsciiRow
sub al,6
push cx
mov cl,4
rol al,cl
mov ch,13
mov cl,byte ptr cs:AsciiRow
mov bh,71h
call DispChar
pop cx
; show the other header of row
loopascii1:
mov si,offset AsciiBuffer
mov byte ptr cs:[si+1],0
mov bh,70h
push cx
mov cl,byte ptr cs:AsciiRow
mov ch,byte ptr cs:AsciiCol
call Write_Str
inc byte ptr cs:AsciiBuffer
add byte ptr cs:AsciiCol,3
pop cx
inc cx
inc bp
cmp cx,255
ja exit_ascii
cmp bp,15
jbe loopascii1
inc byte ptr cs:AsciiRow
mov byte ptr cs:AsciiCol,16
xor bp,bp
jmp loopascii
exit_ascii:
xor ah,ah
int 16h
call Pop_Scr
popall
ret
ShowAscii endp
;--------------------------------------------------------------------
EncryMess db 'Formula(+/-/^/</>/~/&/|) :',0
EncryCharMess db 'Input Char to Encrypted :',0
EncryLen dw 0
EncryChar db 0
;-----------------------------------------------------------------
; The procedure to process the Encrypt the block
;-----------------------------------------------------------------
Do_Encrypt proc
pushall
call Get_TwoOffset
jnc encry@4
jmp exit_fill
encry@4:
inc cx
mov cs:EncryLen,cx
; get the length
call Test_para
jnc encry@11
jmp exit_encry
; test the offset is valid or not
encry@11:
mov cl,0bh
lea si,EncryCharMess
mov ch,0bh
mov bh,MessageBoxColor
call write_str
mov ch,37
call setcursor
mov byte ptr cs:segg,3
call getnum
mov byte ptr cs:segg,5
jnc encry@12
jmp exit_encry
;get char
encry@12:
mov byte ptr cs:EncryChar,al
; get the encrypt char
mov cl,0ch
lea si,EncryMess
mov ch,0bh
mov bh,MessageBoxColor
call write_str
; show function message
mov si,cs:off1
mov dx,cs:currentseg
mov ds,dx
mov dl,byte ptr cs:EncryChar
mov cx,cs:EncryLen
encry@3:
push si
push cx
push dx
push ds
xor ah,ah
int 16h
pop ds
pop dx
pop cx
pop si
cmp ax,escape
jnz en@7
jmp exit_encry
en@7:
cmp al,'^'
jz to_xor
cmp al,'+'
jz to_add
cmp al,'-'
jz to_sub
cmp al,'>'
jz to_shiftr
cmp al,'<'
jz to_shiftl
cmp al,'~'
jz to_not
cmp al,'&'
jz to_and
cmp al,'|'
jz to_or
jmp encry@3
; process the key
to_not:
lodsb
not al
mov byte ptr ds:[si-1],al
loop to_not
jmp exit_encry
to_and:
lodsb
and al,dl
mov byte ptr ds:[si-1],al
loop to_and
jmp exit_encry
to_or:
lodsb
or al,dl
mov byte ptr ds:[si-1],al
loop to_or
jmp exit_encry
to_xor:
lodsb
xor al,dl
mov byte ptr ds:[si-1],al
loop to_xor
jmp exit_encry
to_add:
lodsb
add al,dl
mov byte ptr ds:[si-1],al
loop to_add
jmp exit_encry
to_sub:
lodsb
sub al,dl
mov byte ptr ds:[si-1],al
loop to_sub
jmp exit_encry
to_shiftl:
lodsb
push cx
mov cl,dl
rol al,cl
pop cx
mov byte ptr ds:[si-1],al
loop to_shiftl
jmp exit_encry
to_shiftr:
lodsb
push cx
mov cl,dl
ror al,cl
pop cx
mov byte ptr ds:[si-1],al
loop to_shiftr
jmp exit_encry
exit_encry:
mov bh,byte ptr cs:dispcolor
call clr_win
;clear the window
call redrawpager
popall
ret
Do_Encrypt endp
;---------------------------------------------------------------------
nofile db 'Error: The file is not exist...',0
filerror db 'Error: The BinEdit File has been changed..',0dh,0ah,24h
maxmem dw 0
reeditmess db 'Do you want to Edit next block <y/n>:',0
;----------------------------------------------------------
filelenall equ $
psp dw 0
reeditf dw 0
over64k db 0
commandline db 0
old24h dw 0
dw 0
EndFlag db 'FFF888',0
;---------------------------------------------------------
DEncryLen equ $- offset filename
;---------------------------------------------------------
BEGIN:
push es
mov bx,word ptr es:[2ch]
mov es,bx
mov ah,49h
int 21h
pop es
; free the env.
;---------------------------
mov byte ptr cs:commandline,0
push es
call get_commandline
pop es
;get command line
mov ax,ds
mov cs:psp,ax
;ax=psp
mov byte ptr cs:isInScrBuffer,0
;set flag,to write char to video buffer
;not in memory buffer
mov byte ptr cs:saveinmess,1
;save the screen in messagebox proc
sub ax,1
mov ds,ax
mov ax,word ptr ds:[3]
sub ax,500h
mov word ptr cs:maxmem,ax
;Get Max Memory Size
push cs
pop ds
push cs
pop es
cli
push cs
pop ss
lea si,all
add si,1024
mov sp,si
sti
xor ax,ax
push ax
;clear the stack
mov si,offset helpmess0
mov di,offset helpaddr
call ChkCode
mov ax,3524h
int 21h
mov cs:old24h,bx
mov cs:old24h+2,es
;Get old int 24h
push cs
pop ds
lea dx,new24h
mov ax,2524h
int 21h
;set new int 24h
call ReAllocMem
mov bh,10h
call TestMonitor
; do_reedit:
cmp byte ptr cs:commandline,1
jz re_edit
;if has command line,edit the commandline file
mov ah,09h
push cs
pop ds
lea dx,filename
int 21h
;input filename message
mov ah,0ah
lea dx,file
mov si,dx
; int 21h
call get_str
mov cl,byte ptr cs:[file+1]
add si,2
xor ch,ch
add si,cx
mov byte ptr cs:[si],0
;Get file name
re_edit:
mov bh,07h
call clrscr
lea dx,file
add dx,2
call TestIsBinOrNot
jnc do_nextbin
lea si,nofile
mov cs:stop,1
call messagebox
jmp main_ex
do_nextbin:
call Do_Bin
;do the main loop
Main_ex:
mov cx,2
mov bx,cs:handle
aabbcc:
cmp bx,0
jb exit_nowall
mov ah,3eh
int 21h
mov bx,cs:handle1
loop aabbcc
;close the file
exit_nowall:
to_yhexit:
call Exit_message
;show exit message
call ShowCursor
;show cursor now
xor ax,ax
mov es,ax
mov ax,cs:old24h
mov word ptr es:[4*24h],ax
mov ax,cs:old24h+2
mov word ptr es:[4*24h+2],ax
;set old int 24h
push cs
pop ds
lea dx,file
add dx,2
mov ax,4301h
mov cx,cs:fileAttr
cmp cx,20h
jz not_exch
int 21h
;Set the old file attribute
not_exch:
mov ax,4c00h
int 21h
;------------------------------------------------------------------
All: db 0
end start
;-----------------------------------------------------------------------
编译:
tasm be.asm;
tlink -t be.com;