?? sfx2.asm
字號:
call close ;
mov ax, 4c01h ;
int 21h ;
;
;-----------------------------------------------;
; get 'Y' or 'N' ;
;-----------------------------------------------;
public getyn ;
getyn proc near ;
mov bx, offset yesno ; prompt
call mesout ;
$_58:
mov ah, 08h ;
int 21h ;
and al, 0dfh ;
cmp al, 'Y'
jE $_60
cmp al, 'N'
jNE $_58
$_59:
$_60:
mov bx, offset mes_yn ;
mov cs:[bx], al ;
call mesout ;
cmp al, 'Y' ;
ret ;
getyn endp ;
;-----------------------------------------------;
; 僶僢僼傽偺弌椡 ;
;-----------------------------------------------;
public putbuf ;
putbuf proc near ;
mov dx, offset text_buf ;
mov cx, di ;
mov bx, outfile ;
mov ah, 40h ; write to file
int 21h ;
jc errwrite ;
sub ax, cx
jE $_61
cmp bx, 1 ;
jne errwrite ;
$_61:
;
push si ;
mov si, dx ;
jcxz putbuf9 ;
mov ax, curcrc ;
$_62:
xor al, [si] ;
inc si ;
mov bl, al ; crc & 0xff
xor bh, bh ;
mov al, ah ; crc >> 8
xor ah, ah ;
shl bx, 1 ;
xor ax, crctbl[bx] ;
LOOP $_62
$_63:
mov curcrc, ax ;
putbuf9: ;
pop si ;
cmp outfile, 1 ;
je return ;
mov ah, 02h ;
mov dl, '.' ;
jmp short int21_ret ; int 21h
; ret
putbuf endp ;
;
;-----------------------------------------------;
; 偦偺傑傑弌椡 ;
;-----------------------------------------------;
public copyall ;
copyall proc near ;
xor di, di ;
$_64:
mov bx, offset DGROUP:cpyhdr.OrgSiz
sub [bx], di ;
sbb word ptr 2[bx], 0 ;
mov cx, N ;
jNE $_67
mov ax, [bx] ;
or ax, ax ;
jz cpyend ;
cmp ax, cx
jAE $_67
mov cx, ax ;
$_67:
;
mov dx, offset DGROUP:text_buf
mov bx, infile ;
mov ah, 3fh ;
int 21h ;
mov di, cx ;
call putbuf ;
jmp $_64
$_66:
$_65:
cpyend: ;
ret ;
copyall endp ;
;
;-----------------------------------------------;
; 僼傽僀儖偺 close ;
;-----------------------------------------------;
public close ;
close proc near ;
mov ah, 3eh ;
jmp short int21_ret ; int 21h
; ret
close endp ;
;
;-----------------------------------------------;
; 僼傽僀儖偺嶍彍 ;
;-----------------------------------------------;
public unlink ;
unlink proc near ;
mov dx, fnptr ;
mov ah, 41h ; unlink
int21_ret: ;
int 21h ;
return: ;
ret ;
unlink endp ;
;
;-----------------------------------------------;
; buffer 擖椡 ;
;-----------------------------------------------;
public getbuf ;
getbuf proc near ;
push ax ;
push bx ;
push cx ;
push dx ;
mov bx, infile ;
mov dx, offset DGROUP:inpbuf ;
mov cx, BufSiz ;
cmp DGROUP:cpyhdr.PacSiz + 2, 0
jNE $_68
cmp cx, DGROUP:cpyhdr.PacSiz
jBE $_68
mov cx, DGROUP:cpyhdr.PacSiz;
$_68:
sub DGROUP:cpyhdr.PacSiz, cx ;
sbb DGROUP:cpyhdr.PacSiz + 2, 0 ;
mov ah, 3fh ;
int 21h ; Read from an Archive
mov inpptr, dx ;
pop dx ;
pop cx ;
pop bx ;
pop ax ;
ret ;
getbuf endp ;
;
;-----------------------------------------------;
; 儊僢僙乕僕偺弌椡 ;
;-----------------------------------------------;
public mesout ;
mesout proc near ;
push ds ;
push ax ;
push dx ;
push cs ;
pop ds ;
call dispent ;
pop dx ;
pop ax ;
pop ds ;
ret ;
mesout endp ;
;
;-----------------------------------------------;
; 栘峔憿偺嵞峔抸 ;
;-----------------------------------------------;
public reconst ;
reconst proc near ;
push si ;
;
xor si, si ;
mov di, si ;
$_69:
mov bx, son[si] ;
lodsw ; freq[si]
cmp bx, bp
jB $_71
inc ax ;
shr ax, 1 ;
mov son[di], bx ;
stosw ; mov freq[di], ax
; add di, 2
$_71:
cmp si, bp
jB $_69
$_70:
xor si, si ;
$_72:
push si ;
lodsw ; freq[si]
add ax, [si] ; freq[bx]
mov [di], ax ; freq[di], ax
;
mov bx, di ;
$_74:
dec bx ;
dec bx ;
cmp ax, [bx]
jB $_74
$_75:
inc bx ;
inc bx ;
;
push ax ;
push di ;
std ;
jmp short rc1 ;
$_76:
mov ax, [di - 2] ; freq[di - 2]
mov cx, son[di - 2] ;
mov son[di], cx ;
stosw ; freq[di], ax
rc1: ;
cmp di, bx
jA $_76
$_77:
cld ;
pop di ;
pop [bx] ; freq[bx]
pop son[bx] ;
;
lodsw ; add si, 2
scasw ; add di, 2
cmp di, bp
jB $_72
$_73:
xor si, si ;
$_78:
mov di, son[si] ;
mov prnt[di], si ;
cmp di, bp
jAE $_80
mov prnt[di + 2], si;
$_80:
lodsw ; add si, 2
cmp si, bp
jB $_78
$_79:
;
pop si ;
ret ;
reconst endp ;
;
;-----------------------------------------------;
; 栘峔憿偺峏怴 ;
;-----------------------------------------------;
; si : prnt[c + T] ;
;-----------------------------------------------;
public update ;
update proc near ;
or freq[R * 2], 0
jNS $_81
call near ptr reconst ;
$_81:
mov si, ds:prnt[si + bp] ;
$_82:
mov di, si ; lea di, freq[si]
mov ax, [di] ;
scasw ; inc di ;
; inc di ;
scasw
jNE $_84
mov cx, 0ffffh ; must large enough
repe scasw ;
sub di, 4 ; offset freq + 4
;
mov bx, son[si] ;
mov prnt[bx], di ;
cmp bx, bp
jAE $_85
mov prnt[bx + 2], di
$_85:
xchg bx, son[di] ;
mov prnt[bx], si ;
cmp bx, bp
jAE $_86
mov prnt[bx + 2], si
$_86:
mov son[si], bx ;
;
mov si, di ;
$_84:
inc word ptr [si] ; freq[si]
mov si, prnt[si] ;
or si, si
jNZ $_82
$_83:
ret ;
update endp ;
;
;-----------------------------------------------;
; 俫倀俥偺夝撉 ;
;-----------------------------------------------;
public DecodeChar ;
DecodeChar proc near ;
push bp ;
mov bp, T * 2 ;
mov si, son[R * 2] ;
mov dx, DGROUP:iobuf ;
mov cl, DGROUP:iolen ;
xor ch, ch ;
$_87:
jcxz getword ;
dc2: ;
shr si, 1 ;
shl dx, 1 ;
adc si, 0 ;
shl si, 1 ;
mov si, son[si] ;
dec cx ;
cmp si, bp
jB $_87
$_88:
mov DGROUP:iobuf, dx ;
mov DGROUP:iolen, cl ;
sub si, bp ;
push si ;
call near ptr update ;
pop ax ;
shr ax, 1 ;
pop bp ;
ret ;
DecodeChar endp ;
;
public getword ;
getword: ;
call getc ;
mov dh, al ;
call getc ;
mov dl, al ;
mov cl, 16 ;
jmp short dc2 ;
;
;-----------------------------------------------;
; getc ;
; ax: 1 byte (return) ;
;-----------------------------------------------;
public getc ;
getc proc near ;
cmp inpptr, offset inpbuf + BufSiz
jB $_89
call getbuf ;
$_89:
mov bx, inpptr ;
mov al, [bx] ;
inc inpptr ;
xor ah, ah ;
ret ;
getc endp ;
;
;-----------------------------------------------;
; 擖椡偐傜値價僢僩傪摼傞 ;
;-----------------------------------------------;
; cl : n bits ;
;-----------------------------------------------;
public GetNBits ;
GetNBits proc near ;
push cx ;
mov dx, DGROUP:iobuf ;
cmp iolen, 8
jG $_90
call getc ;
mov cl, 8 ;
sub cl, DGROUP:iolen ;
shl ax, cl ;
or dx, ax ;
add DGROUP:iolen, 8 ;
$_90:
pop cx ;
mov ax, dx ;
shl dx, cl ;
mov DGROUP:iobuf, dx ;
sub DGROUP:iolen, cl ;
mov dx, -1 ;
shr dx, cl ;
not dx ;
and ax, dx ;
ret ;
GetNBits endp ;
;
;-----------------------------------------------;
; 埵抲忣曬偺夝撉 ;
;-----------------------------------------------;
public DecodePosition ;
DecodePosition proc near ;
mov cx, 8 ;
call near ptr GetNBits ;
xchg al, ah ;
mov si, ax ;
mov dl, d_code[si] ;
mov dh, 0 ;
mov cl, 6 ;
shl dx, cl ;
push dx ;
mov cl, d_len[si] ; ch == 0
call near ptr GetNBits ;
or ax, si ;
rol ax, cl ;
and ax, 003fh ;
pop dx ;
add ax, dx ;
ret ;
DecodePosition endp ;
;
;-----------------------------------------------;
; Decode ;
;-----------------------------------------------;
public Decode ;
Decode proc near ;
mov si, offset DGROUP:cpyhdr.OrgSiz ;
lodsw ;
or ax, [si] ;
jNZ $_91
jmp de9 ;
$_91:
push ds ;
pop es ;
;--------------------------------------- ;
; 俫倀俥梡偺栘峔憿偺弶婜壔 ;
;--------------------------------------- ;
public StartHuff ;
StartHuff: ;
mov ax, 1 ;
mov cx, N_CHAR ;
push cx ;
xor di, di ; mov di, offset DGROUP:freq
rep stosw ;
mov ax, T * 2 ;
xor dx, dx ;
pop cx ;
mov di, offset DGROUP:son ;
mov bx, offset DGROUP:prnt[T * 2] ;
$_92:
stosw ;
inc ax ; add ax, 2
inc ax ;
mov [bx], dx ;
inc bx ; add bx, 2
inc bx ;
inc dx ; add dx, 2
inc dx ;
LOOP $_92
$_93:
;
xor si, si ;
mov di, N_CHAR * 2 ;
mov cx, N_CHAR - 1 ;
$_94:
mov son[di], si ;
mov prnt[si], di ;
lodsw ; mov ax, freq[si]
add ax, [si] ; add ax, freq[si + 2]
mov prnt[si], di ;
stosw ; mov freq[di], ax
lodsw ;
LOOP $_94
$_95:
xor ax, ax ;
mov iobuf, ax ;
; mov iolen, al ;
mov DGROUP:prnt[R * 2], ax ; prnt[R * 2], 0
dec ax ;
mov [di], ax ; freq[T * 2], -1
;--------------------------------------- ;
;
mov al, 20h ;
mov cx, F ;
mov di, offset DGROUP:text_buf + N - F
rep stosb ;
;
xor di, di ;
mov bp, N - 1 ;
$_96:
push di ;
call near ptr DecodeChar ;
; $_if ;
or ah, ah ;
jnz de1 ;
pop di ;
mov cx, 1 ;
push cx ;
jmp short de2 ;
; $_else ;
de1: ;
push ax ;
call near ptr DecodePosition
pop cx ;
pop di ;
mov si, di ;
sub si, ax ;
dec si ;
and si, bp ;
sub cx, 255 - THRESHOLD
push cx ;
$_98:
mov al, DGROUP:text_buf[si]
inc si ;
and si, bp ;
de2: ;
mov DGROUP:text_buf[di], al
inc di ;
cmp di, bp
jBE $_100
push cx
call putbuf
pop cx
$_100:
and di, bp ;
LOOP $_98
$_99:
pop cx ;
; $_elseif ;
mov bx, offset DGROUP:cpyhdr.OrgSiz
sub [bx], cx ;
pushf ;
sbb word ptr 2[bx], 0 ;
pop ax ;
lahf ;
and ah, al ;
sahf ;
jG $_96
$_97:
call putbuf ;
de9: ;
ret ;
Decode endp ;
;
;-----------------------------------------------;
; is Japanese kanji char ;
;-----------------------------------------------;
public iskanji ;
iskanji proc near ;
push ax ;
and al, 0e0h ;
cmp al, 080h ;
je ik_ret ;
cmp al, 0e0h ;
ik_ret: ;
pop ax ;
ret ;
iskanji endp ;
;
;-----------------------------------------------;
; is delimiter of path-name ;
;-----------------------------------------------;
public isdelim ;
public isdelim2 ;
isdelim proc near ;
cmp al, ':' ;
je id_ret ;
isdelim2: ;
cmp al, '\' ;
je id_ret ;
cmp al, '/' ;
id_ret: ;
ret ;
isdelim endp ;
;
;-----------------------------------------------;
; is spacing char ;
;-----------------------------------------------;
public isspace ;
isspace proc near ;
cmp al, 0dh ;
je is_ret ;
cmp al, 09h ;
je is_ret ;
cmp al, ' ' ;
is_ret: ;
ret ;
isspace endp ;
;
;-----------------------------------------------;
; transfer from cmd-line ;
;-----------------------------------------------;
public trans ;
public trans_t ;
trans proc near ;
$_101:
mov ah, al ;
stosb ;
call iskanji
jNZ $_103
movsb ;
$_103:
trans_e: ;
lodsb ;
trans_t: ;
call isspace
jNZ $_101
$_102:
mov byte ptr es:[di], 0 ;
ret ;
trans endp ;
;
;-----------------------------------------------;
; display ASCIZ char ;
;-----------------------------------------------;
public disp ;
disp proc near ;
$_104:
inc bx ;
mov ah, 02h ;
int 21h ;
dispent: ;
mov dl, [bx] ;
or dl, dl
jNZ $_104
$_105:
ret ;
disp endp ;
;
public endofcode ;
endofcode: ;
_TEXT ends ;
end start ;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -