📄 depptiny.nas
字号:
ret
shortmatch call getesi ;Get a byte
shr ax,1 ;Distance = AL/2, Lenght in carry flag
jz donedepacking ;If zero, end packing
adc cx,cx ;Lenght = 1 or 0
jmp short domatch_with_2inc ; Decode with lenght 2 or 3
donedepacking pop esi ;ESI=freemem32
sub edi,esi ;And here finish DEPACK 16
;Now edi has the number of depacked
; bytes left to be written
push ds ;Preserve data segment
mov ch,080h ;Write using 32K chunks to enable
; the sign optimization
mov dx,freemem ;Flush everything from here to end
more cmp edi,ecx
ja notlast ;If EDI > 32K, write 32K bytes
mov cx,di ;If EDI < 32K, write EDI bytes
notlast call writefile ;Write chunk
mov ax,ds
add ah,8
mov ds,ax ;Advance 32K
sub edi,ecx ;Update number of bytes to be written
ja more ;Above zero, continue writing
pop ds ;Recover data segment
push ds
pop es ;Set es=ds
pop dx ;Get pointer to outfile name
push dx ;store again
call close_del ;Close temporal outfile and try to
; delete the file named with our
; outfile name, in case it exists
jnc renameit ;If that file existed and was deleted,
; go ahead and rename the temporal one
cmp al,5 ;If it didn't exist, rename it too
jz finerr ;But if error was for other reason,
; exit with NOT OK
renameit mov ah,56h
pop di ;Outfile name
tmpname mov dx,notok
call int_n_check ;Rename temporal outfile to outfile
mov dl,noerr-512 ;Final message: OK
final_dxok mov ah,9
int 33 ;Show final message
int 20h ;Exit program
writefile mov bx,[ss:handletmp] ;Get temporal outfile handle
mov ah,40h
call int_n_check ;Write
dec ax
jns not_finerr ;If disk isn't full there's no error
finerr mov dx,[tmpname+1] ;Temporal outfile will be deleted
push word final_dxok
close_del mov ah,3eh
int 33 ;Close temporal outfile
mov ah,41h
int 33 ;Delete outfile (when called to
; close_del) or temporal outfile
mov dl,notok-512 ;Error message: NOT OK
not_finerr ret ; return or go to final_dxok
getesi cmp esi,[freemem32] ; If esi is at freemem32, we must
jnz dontread ;load 32k of compressed data
mov bh,128 ;BL was 0, EBX=32K
pushad ;Keep all registers (32bit because
mov ah,3fh ; DOS function may modify EAX!!!)
mov cx,bx ;Number of bytes
mov bx,[handlein] ;Take infile handle
mov dx,inbuff ;Place to read
call int_n_check ;Read and exit if error
dec ax ;---Test for bad infile #2: 0 bytes
popad ;\/ read (a good infile will finish
js finerr ;/\ and won't ask for more data)
; >Restore registers
sub esi,ebx ;esi at beginning of buffer again
dontread push esi ;----->Emulates mov al,[esi] in 16 bit
pop bx ; / code (as mov al,[esi] gives
pop bx ; / a nasty fault)
ror bx,4 ; /
mov es,bx ; /
mov al,[es:si] ;/
inc esi ;Update read pointer
ret
int_n_check int 33 ;Perform operation (depends on AH)
finerr01 jc finerr ;If it failed, exit with NOT OK
ret
getbit add dl,dl ;Get a tag bit
jnz stillbitsleft ;If zero, that bit was the marker, so
; we must read a new tag byte from
xchg ax,dx ;\ the infile buffer
call getesi ; >Emulate mov dl,[esi], inc esi
xchg ax,dx ;/
stc ;Carry flag is end marker
adc dl,dl ;Get first bit and set marker
stillbitsleft ret ;Return with bit read in flag C
newtest cmp edi,[limit32] ;Check if we've run out of memory
jc endtest ;NO: end test
pushad ;Keep registers
mov dx,freemem
mov ecx,32768+65536 ;CX=32K will be written first
;ECX=96K data will be moved then
call writefile ;Write 32K of data
sub edi,ecx ;Set pointer to origin32=limit32-96K
mov esi,[freemem32] ;Output data will be moved 32K back
xchg edi,esi ;Swap source and destination pointers
otherrepmovsb call getesi ; \
call putedi ; >Emulates rep movsb
loop otherrepmovsb,ecx ;/
popad ;Restore registers
sub esi,eax ;Update read pointer (sub 32K if
; we are in the repmovsb loop)
mov ah,128 ;EAX=32K
sub edi,eax ;Update write pointer
endtest ret
putedi push edi ;----->Emulate mov [edi],al in 16 bit
pop bx ; / code (as mov [edi],al gives
pop bx ; / a nasty fault)
ror bx,4 ; /
mov es,bx ; /
mov [es:di],al ;/
inc edi ;Update write pointer
xor eax,eax ;Clear EAX
ret
unitoutfile db "c:"
notok db "NOT "
noerr db "OK$",0
testitnow lodsb ;Parse one byte
cmp al,32 ;Is it space?
jc finerr01 ;Below space: bad arguments > exit
ret
handlein EQU testitnow
handletmp EQU testitnow+2
freemem32 EQU testitnow+4
limit32 EQU testitnow+8
;Stack is between program and 2048
inbuff EQU 2048 ;Place for 32K infile reading buffer
freemem EQU inbuff+32768
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -