home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Brotikasten
/
BROTCD01.iso
/
cpm
/
unzip18.lbr
/
UNZIP12.ZZ0
/
UNZIP12.Z80
Wrap
Text File
|
1991-05-12
|
18KB
|
1,440 lines
; UNZIP.Z80
;
; Version 1.2 -- July 3, 1990 -- David P. Goodenough
;
; This file has been converted to assemble with SLR's Z80ASM, resulting
; in a COM file identical to the 1.2 release version.
; Gene Pizzetta, May 11, 1991
;
CR equ 0Dh
LF equ 0Ah
CtrlZ equ 1Ah
STRSIZ equ 256
EXTRACT equ 'E'
bdos equ 5
open equ 0fh
close equ 10h
read equ 14h
write equ 15h
create equ 16h
setdma equ 1ah
infcb equ 5ch
DLE equ 144
max_bits equ 13
init_bits equ 9
hsize equ 8192
first_ent equ 257
clear equ 256
maxcmax equ 1 << max_bits
maxSF equ 256
_code equ 0
_value equ 2
_bitlength equ 3
_entries equ 0
_maxlength equ 2
_entry equ 4
_sf_tree_ equ 4 + 4 * maxSF
jr start
db CR
usage: db 'Usage: UNZIP ZIPFILE [E]',CR,LF
db 'E - extract files',CR,LF
db ' default is to just list files',CR,LF,0,CtrlZ
start: ld sp,(6) ; set the stack pointer
call ilprt
db 'UNZIP V1.2 - DPG 1990',CR,LF,LF,0
ld a,(5dh) ; filename?
cp ' '
jr nz,wasfil
ld hl,usage
call pstr
rst 0
wasfil: ld a,(6dh) ; option letter?
;.cseg
xor EXTRACT ; 'E' for extract
ld (mode),a ; set the mode
ld a,(65h)
cp 20h
jr nz,wasext
ld hl,['I' << 8] + 'Z'
ld (65h),hl
ld a,'P'
ld (67h),a ; install .ZIP extent
wasext: ld de,5ch
ld c,open
call bdos ; try and open it
inc a
jr nz,openok ; ok
call ilprt
db 'Couldn''t find ZIP file',CR,LF,0
rst 0 ; complain and exit
sigerr: call ilprt
db 'Bad signature in ZIP file',CR,LF,0
rst 0
openok: call getword
ld de,-[['K' << 8] + 'P']
add hl,de
ld a,h
or l
jr nz,sigerr
call getword
dec l
jr nz,nocfhs
dec h
dec h
jr nz,sigerr
call pcfh
jr openok
nocfhs: dec l
dec l
jr nz,nolfhs
ld a,h
sub 4
jr nz,sigerr
call plfh
jr openok
nolfhs: dec l
dec l
jr nz,sigerr
ld a,h
sub 6
jr nz,sigerr
call pecd
rst 0
pcfh: ld b,12
pcfhl1: push bc
call getword
pop bc
djnz pcfhl1
call getword
push hl
call getword
push hl
call getword
pop de
pop bc
push hl
push de
push bc
ld b,6
pcfhl2: push bc
call getword
pop bc
djnz pcfhl2
pop hl
ld de,junk
;.cseg
call getstring
pop hl
ld de,junk
call getstring
pop hl
ld de,junk
call getstring
ret
pecd: ld b,8
pecdl: push bc
call getword
pop bc
djnz pecdl
call getword
ld de,junk
call getstring
ret
;.cseg
plfh: ld de,lfh
ld hl,endlfh-lfh
; ld hl,{endlfh - lfh}
call getstring
ld hl,opfcb
ld de,opfcb + 1
ld bc,32
ld (hl),b
ldir
;.cseg
ld de,junk
ld hl,(fnl)
call getstring
ld de,junk + 20
ld hl,(efl)
call getstring
ld de,junk
ld hl,opfn
ld b,8
call scanfn
ld a,(de)
cp '.'
jr nz,nodot
inc de
nodot: ld b,3
call scanfn
ld hl,init
ld de,vars
ld bc,endinit-init
; ld bc,{endinit - init}
ldir
;.cseg
ld a,(mode)
resmod: ld (curmode),a
or a
jr nz,extrct
ld de,opfcb
ld c,0fh
call bdos
inc a
jr z,creok
ld hl,junk
call pstr
call ilprt
db ' already exists',0
noex: call ilprt
db ' -- not extracting',0
ld a,0ffh
jr resmod
extrct: xor a
ld (zipeof),a
ld a,(curmode)
dec a
jp m,doext
call ilprt
db 'Checking ',0
jr pjunk
creok: ld de,opfcb
ld c,create
call bdos
inc a
jr nz,opnok1
call ilprt
db 'Error creating ',0
ld hl,junk
call pstr
jr noex
opnok1: call ilprt
db 'Extracting ',0
pjunk: ld hl,junk
call pstr
doext: call ilprt
db ' -- ',0
ld hl,counting
inc (hl)
ld a,(cm)
or a
jr nz,case1
case0w: ld a,(zipeof)
and 1
jr nz,closeo
savcs0: call getbyte
call outbyte
jr case0w
case1: dec a
jr nz,case2p
call unshrink
jr closeo
case2p: dec a
cp 4
jr nc,tryimp
call unreduce
jr closeo
tryimp: jr nz,badzip
call unimplode
jr closeo
badzip: call ilprt
db 'Unknown compression method',CR,LF,0
ret
closeo: ld hl,zipeof
dec (hl)
inc hl
dec (hl)
ld a,(mode)
or a
jr nz,nocls
ld hl,wrtpt
ld a,(hl)
or a
jr z,noflsh
ld de,opbuf
;.cseg
ld c,setdma
call bdos
ld de,opfcb
ld c,write
call bdos
noflsh: ld de,opfcb
ld c,close
call bdos
nocls: ld hl,crc32
ld de,crc
scf
ld bc,4 << 8
crcclp: ld a,(de)
adc a,(hl)
push af
or c
ld c,a
pop af
inc hl
inc de
djnz crcclp
ld a,c
or a
jr z,crcok
call ilprt
db 'CRC error',CR,LF,0
ret
crcok: call ilprt
db 'CRC OK',CR,LF,0
ret
getchla:
call getcode
ld (code),hl
ld a,(zipeof)
and 1
ret
savstk:
ld hl,(stackp)
dec hl
ld (stackp),hl
ld (hl),a
ret
getcode:
ld a,(codesize)
readbits:
ld hl,8000h
bitlp: push af
push hl
getbit: ld hl,bleft
dec (hl)
jp m,readbt
dec hl
rr (hl)
pop hl
rr h
rr l
pop af
dec a
jr nz,bitlp
finbit: srl h
rr l
jr nc,finbit
ld a,l
ret
readbt: push hl
call getbyte
pop hl
ld (hl),8
dec hl
ld (hl),a
jr getbit
scanfn: ld a,(de)
cp '.'
jr z,nocopy
or a
jr z,nocopy
inc de
dec b
jp m,scanfn
ld (hl),a
inc hl
jr scanfn
nocopy: dec b
ret m
ld (hl),' '
inc hl
jr nocopy
ilprt: pop hl
call pstr
jp (hl)
pstr: ld a,(hl)
or a
ret z
push hl
ld e,a
ld c,2
call bdos
pop hl
inc hl
jr pstr
getstring:
ld a,h
or l
ld (de),a
ret z
push de
push hl
call getbyte
pop hl
pop de
ld (de),a
inc de
dec hl
jr getstring
getword:
call getbyte
push af
call getbyte
pop hl
ld l,h
ld h,a
ret
getbyte:
ld a,(zipeof)
and 1
ld a,CtrlZ
ret nz
ld a,(counting)
or a
jr z,skpdci
ld hl,(cs)
ld de,(cs + 2)
ld a,d
or e
or h
or l
jr nz,noteof
ld hl,zipeof
inc (hl)
ld a,CtrlZ
ret
noteof: ld a,h
or l
dec hl
ld (cs),hl
jr nz,skpdci
dec de
ld (cs + 2),de
skpdci: ld hl,readpt
;.cseg
ld a,(hl)
or a
jr nz,ptok
ld de,80h
ld (hl),e
push hl
ld c,setdma
call bdos
ld de,infcb
ld c,read
call bdos
or a
pop hl
jr nz,ateof
ptok: ld a,(hl)
inc (hl)
ld l,a
ld h,0
ld a,(hl)
ret
ateof: ld a,CtrlZ
ret
outb:
ld hl,(outpos)
push hl
push af
ld a,h
and 1fh
ld h,a
pop af
ld de,outbuf
add hl,de
ld (hl),a
pop hl
inc hl
ld (outpos),hl
push af
ld a,h
or l
jr nz,nopos
ld hl,(outpos + 2)
inc hl
ld (outpos + 2),hl
nopos: pop af
outbyte:
push af
call updcrc
ld hl,(ucs)
ld de,(ucs + 2)
ld a,h
or l
dec hl
ld (ucs),hl
jr nz,tsthl0
dec de
ld (ucs + 2),de
tsthl0: ld a,h
or l
or d
or e
jr nz,noeof
ld hl,zipeof
inc (hl)
noeof: ld a,(mode)
or a
jr nz,popret
ld hl,wrtpt
ld a,(hl)
add a,a
jr nc,wptok
ld de,opbuf
ld c,setdma
call bdos
ld de,opfcb
ld c,write
call bdos
or a
jr z,wptok
ld (mode),a
call ilprt
db 'Write Error',CR,LF,0
popret: pop af
ret
wptok: jr nz,nofilb
ld hl,opbuf
ld de,opbuf + 1
ld bc,127
ld (hl),CtrlZ
ldir
xor a
ld (wrtpt),a
nofilb: pop af
ld hl,wrtpt
inc (hl)
ld l,(hl)
ld h,0
ld de,opbuf - 1
add hl,de
ld (hl),a
ret
updcrc: ld hl,(crc32)
ld de,(crc32 + 2)
ld c,a
ld b,8
crclp: ld a,l
xor c
srl c
srl d
rr e
rr h
rr l
rra
jr nc,noxor
ld a,d
xor 0edh
ld d,a
ld a,e
xor 0b8h
ld e,a
ld a,h
xor 83h
ld h,a
ld a,l
xor 20h
ld l,a
noxor: djnz crclp
ld (crc32),hl
ld (crc32 + 2),de
ret
unshrink:
ld a,init_bits
ld (codesize),a
ld hl,[1 << init_bits] - 1;
ld (maxcode),hl
ld hl,first_ent
ld (free_ent),hl
ld hl,prefix_of
ld de,prefix_of + 1
ld bc,512
ld (hl),c
ldir
ld bc,16386 - 512
ld (hl),-1
ldir
ld hl,suffix_of
sol: ld (hl),c
inc hl
inc c
jr nz,sol
call getchla
ld (oldcode),hl
ret nz
ld a,l
ld (finchar),a
call outbyte
unshlp: ld hl,stack + 8192
ld (stackp),hl
ld a,(zipeof)
and 1
ret nz
clrlp: call z,getchla
ret nz
ld a,h
dec a
or l
jr nz,noclr
call getchla
ld a,h
or a
jr nz,clrlp
dec l
jr z,bumpcs
dec l
call z,partial_clear
jr clrlp
bumpcs: ld hl,codesize
inc (hl)
ld a,(hl)
cp max_bits
ld hl,maxcmax
jr z,atmax
ld hl,1
maxclp: add hl,hl
dec a
jr nz,maxclp
dec hl
atmax: ld (maxcode),hl
jr clrlp
noclr: ld (incode),hl
add hl,hl
ld de,prefix_of