📄 sfx.asm
字号:
page 66, 120 ;
;$_init ;
;***********************************************;
; LHarc version 1.13 (c) Yoshi 1988-89. ;
; self-extract module : 1989/ 5/ 4 ;
; ;
; HTAB = 8 ;
;***********************************************;
;
_TEXT segment byte public 'CODE' ;
_TEXT ends ;
;
DGROUP group _BSS ;
assume cs:_TEXT, ds:DGROUP ;
;
public THRESHOLD, F, N_CHAR, T ;
THRESHOLD equ 2 ;
F equ 60 ;
N_CHAR equ (256 - THRESHOLD + F) ;
T equ (N_CHAR * 2 - 1) ;
R equ (T - 1) ;
N equ 1000h ;
MAX_FREQ equ 8000h ;
CRC16 equ 0a001h ;
;
LzHead struc ;
HeadSiz db ? ;
HeadChk db ? ;
HeadID db 3 dup (?) ;
Method db ? ;
db ? ;
PacSiz dw 2 dup (?) ;
OrgSiz dw 2 dup (?) ;
FTime dw ? ;
FDate dw ? ;
FAttr dw ? ;
FnLen db ? ;
Fname db 14 dup (?) ;
LzHead ends ;
;
_BSS segment para public 'BSS' ;
public freq, prnt, son ;
public d_len, d_code ;
public crctbl ;
public cpyhdr, outfile ;
public curcrc, iobuf, iolen, crcflg, orgcrc
;
freq dw (T + 1) dup (?) ;
prnt dw (T + N_CHAR) dup (?) ;
son dw T dup (?) ;
d_len db 100h dup (?) ;
d_code db 100h dup (?) ;
crctbl dw 100h dup (?) ;
text_buf db N dup (?) ;
text_ptr dw 2 dup (?) ;
cpyhdr LzHead 1 dup (<?>) ;
outfile dw 1 dup (?) ;
orgcrc dw 1 dup (?) ;
curcrc dw 1 dup (?) ;
iobuf dw 1 dup (?) ;
crcflg db 1 dup (?) ;
iolen db 1 dup (?) ;
endBBS label byte ;
_BSS ends ;
;
_TEXT segment byte public 'CODE' ;
assume cs:_TEXT, ds:DGROUP ;
;
org 0100h ;
;
public start, main ;
public BSSseg ;
public cright, chglen, crlf, space ;
start: ;
jmp short main ;
BSSseg dw (endofcode - start + 10fh) / 10h; don't move this
mes_yn equ space - 1 ;
space db ' $' ;
cright db "LHarc's SFX 1.13S (c)Yoshi, 1989."
db 13, 10, 10, '$' ;
chglen db 01h, 04h, 0ch, 18h, 30h ; next byte must not be 3?h
overwt db 'Overwrite $' ;
yesno db '[Y/N] $' ;
memory db 'Memory$' ;
write db 'Write$' ;
header db 'Header$' ;
crcmes db 'CRC' ;
error db ' Error' ;
crlf db 13, 10, '$' ;
;
;-----------------------------------------------;
; 儊僀儞儖乕僠儞 ;
;-----------------------------------------------;
main: ;
cld ;
mov sp, offset start ;
mov bx, offset cright ;
call mesout ;
mov ax, cs ;
add ax, BSSseg ;
mov ds, ax ;
mov es, ax ;
add ax, (endBBS - freq + 0fh) / 10h ;
cmp ax, cs:[0002h]
jBE $_1
mov bx, offset memory ;
jmp errout ;
$_1:
;---------------- ;
; make CRC table ;
;---------------- ;
mov di, offset crctbl ;
xor dx, dx ;
$_2:
mov ax, dx ;
mov cx, 8 ;
$_4:
shr ax, 1
jNC $_6
xor ax, CRC16
$_6:
LOOP $_4
$_5:
stosw ;
inc dl
jNZ $_2
$_3:
;------------------------- ;
; make table for position ;
;------------------------- ;
mov si, offset _TEXT:chglen ;
mov di, offset DGROUP:d_len ;
mov ax, 1 ; d_len = real length - 2
mov dx, 0020h ;
$_7:
cmp ah, cs:[si]
jNE $_9
inc al ;
inc si ;
shr dx, 1 ;
$_9:
mov cx, dx ;
$_10:
mov [di + d_code - d_len], ah
stosb ;
LOOP $_10
$_11:
inc ah ;
cmp ah, 040h
jL $_7
$_8:
;-----------------------------------------------;
mov text_ptr + 2, cs ;
mov text_ptr, offset _TEXT:endofcode;
jmp mn1 ;
;
$_12:
xor ch, ch ;
push cx ; cx = HeadSiz
mov di, offset DGROUP:cpyhdr;
lodsw ; ah = HeadChk
stosw ;
$_14:
sub ah, [si] ;
movsb ; copy header to _BSS seg.
LOOP $_14
$_15:
; di = end of cpyhdr
pop cx ;
pop ds ;
mov text_ptr, si ;
jne errhdr ;
;
mov bx, offset DGROUP:cpyhdr.Fname
mov dx, bx ;
add bl, [bx - 1] ;
adc bh, 0 ;
;
mov ax, [bx] ; may be CRC
mov orgcrc, ax ;
;
sub di, bx ; bx end of Fname
mov word ptr crcflg, di ; if 2, crc supported.
; iolen = 0 also.
;
mov di, offset DGROUP:cpyhdr.HeadID ; check ID & sum
cmp word ptr [di], 'l-' ;
jne errhdr ;
mov ax, 2[di] ;
xchg al, ah ;
sub ax, 'h0' ;
mov bp, ax ; bp = method
cmp ax, 0001h ;
ja errhdr ;
cmp byte ptr 4[di], '-' ;
;
jE $_16
errhdr: ;
mov bx, offset header
jmp errout ;
$_16:
;
mov ax, 1 ;
cmp word ptr cpyhdr.FnLen, 2101h ; 01h, '!'
je mn7 ;
;
mov byte ptr [bx], ' ' ;
mov cx, bx ;
sub cx, dx ;
inc cx ;
push bx ;
mov bx, ax ; ax = 1
mov ah, 40h ;
int 21h ; display file name
pop bx ;
mov byte ptr [bx], 0 ;
;
mov ax, 4300h ; get file attr
int 21h ; for check existence
jc mn5 ;
;
mov bx, offset overwt ; prompt
call mesout ;
call getyn ;
je mn5 ;
;
mov ax, cpyhdr.PacSiz ; skip file
mov dx, cpyhdr.PacSiz + 2 ;
;
call adjust ;
jmp mn6 ;
mn5: ;
mov cl, 20h ; ch may be 0
mov ah, 3ch ;
int 21h ; create file
jNC $_17
jmp errwrite ;
$_17:
mn7: ;
mov outfile, ax ;
;
xor ax, ax ;
mov curcrc, ax ;
; mov iolen, al ; already iolen = 0
;
or bp, bp
jZ $_18
call Decode ;
jmp short $_19
$_18:
call copyall ;
$_19:
;
$_20:
sub iolen, 8
jL $_22
dec word ptr text_ptr
jmp $_20
$_22:
$_21:
call adjust0 ;
;
mov dx, cpyhdr.FDate ;
mov cx, cpyhdr.FTime ;
mov bx, outfile ;
cmp bx, 1 ;
je mn8 ;
mov ax, 5701h ; set date
int 21h ;
call close ;
;
cmp crcflg, 2
jNE $_23
mov ax, curcrc ;
cmp ax, orgcrc ;
jne errcrc ;
$_23:
jmp mn6 ;
mn8: ;
call getyn ;
jne exit ;
mn6: ;
mov bx, offset crlf ;
call mesout ;
mn1: ;
push ds ;
lds si, dword ptr text_ptr ;
mov cl, [si] ;
or cl, cl
jZ $_24
jmp $_12
$_13:
$_24:
pop ds ;
exit: ;
mov ax, 4c00h ;
int 21h ;
resident: ;
;
;-----------------------------------------------;
; 僄儔乕張棟 ;
;-----------------------------------------------;
public errhdr, errwrite, errout ;
errcrc: ;
call unlink ;
mov bx, offset crcmes ;
jmp short errout1 ;
;
errwrite: ;
call close ;
call unlink ;
mov bx, offset write ;
;
errout: ;
call mesout ;
mov bx, offset error ;
errout1: ;
call mesout ;
mov ax, 4c01h ;
int 21h ;
;
;-----------------------------------------------;
; get 'Y' or 'N' ;
;-----------------------------------------------;
getyn proc near ;
mov bx, offset yesno ; prompt
call mesout ;
$_25:
mov ah, 08h ;
int 21h ;
and al, 0dfh ;
cmp al, 'Y'
jE $_27
cmp al, 'N'
jNE $_25
$_26:
$_27:
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 $_28
cmp bx, 1 ;
jne errwrite ;
$_28:
;
push si ;
mov si, dx ;
jcxz putbuf9 ;
mov ax, curcrc ;
$_29:
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 $_29
$_30:
mov curcrc, ax ;
putbuf9: ;
call adjust0 ;
;
pop si ;
cmp outfile, 1 ;
je return ;
mov ah, 02h ;
mov dl, '.' ;
jmp short int21_ret ; int 21h
; ret
putbuf endp ;
;
;-----------------------------------------------;
; 僼傽僀儖偺 close ;
;-----------------------------------------------;
public close ;
close proc near ;
mov bx, outfile ;
mov ah, 3eh ;
jmp short int21_ret ; int 21h
; ret
close endp ;
;
;-----------------------------------------------;
; 僼傽僀儖偺嶍彍 ;
;-----------------------------------------------;
public unlink ;
unlink proc near ;
mov dx, offset cpyhdr.Fname ;
mov ah, 41h ; unlink
int21_ret: ;
int 21h ;
return: ;
ret ;
unlink endp ;
;
;-----------------------------------------------;
; adjust text pointer ;
;-----------------------------------------------;
; dx_ax : add count ;
;-----------------------------------------------;
public adjust0, adjust1, adjust ;
adjust0 proc near ;
xor ax, ax ;
adjust1 proc near ;
cwd ;
adjust proc near ;
mov si, offset text_ptr ;
;
add word ptr [si], 10h ;
dec word ptr 2[si] ;
;
add ax, [si] ;
adc dx, 0 ;
mov cx, ax ;
and cx, 000fh ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -