Skip to content

Commit

Permalink
Update to v0.68
Browse files Browse the repository at this point in the history
  • Loading branch information
Édouard BERGÉ authored and mkoloberdin committed Feb 19, 2018
1 parent 0bfd3f6 commit 3919c27
Show file tree
Hide file tree
Showing 9 changed files with 1,228 additions and 125 deletions.
118 changes: 118 additions & 0 deletions decrunch/deexo.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
;Exomizer 2 Z80 decoder
; by Metalbrain
;
; optimized by Antonio Villena and Urusergi (169 bytes)
;
; compression algorithm by Magnus Lind

;input: hl=compressed data start
; de=uncompressed destination start
;
; you may change exo_mapbasebits to point to any free buffer
;
;ATTENTION!
;A huge speed boost (around 14%) can be gained at the cost of only 5 bytes.
;If you want this, replace all instances of "call exo_getbit" with "srl a" followed by
;"call z,exo_getbit", and remove the first two instructions in exo_getbit routine.

Macro Mizoumizeur

@deexo: ld iy, @exo_mapbasebits+11
ld a, (hl)
inc hl
ld b, 52
push de
cp a
@exo_initbits: ld c, 16
jr nz, @exo_get4bits
ld ixl, c
ld de, 1 ;DE=b2
@exo_get4bits: srl a: call z, @exo_getbit ;get one bit
rl c
jr nc, @exo_get4bits
inc c
push hl
ld hl, 1
ld (iy+41), c ;bits[i]=b1 (and opcode 41 == add hl,hl)
@exo_setbit: dec c
jr nz, @exo_setbit-1 ;jump to add hl,hl instruction
ld (iy-11), e
ld (iy+93), d ;base[i]=b2
add hl, de
ex de, hl
inc iy
pop hl
dec ixl
djnz @exo_initbits
pop de
jr @exo_mainloop
@exo_literalrun: ld e, c ;DE=1
@exo_getbits: dec b
ret z
@exo_getbits1: srl a : call z,@exo_getbit
rl e
rl d
jr nc, @exo_getbits
ld b, d
ld c, e
pop de
@exo_literalcopy:ldir
@exo_mainloop: inc c
srl a : call z,@exo_getbit ;literal?
jr c, @exo_literalcopy
ld c, 239
@exo_getindex: srl a : call z,@exo_getbit
inc c
jr nc,@exo_getindex
ret z
push de
ld d, b
jp p, @exo_literalrun
ld iy, @exo_mapbasebits-229
call @exo_getpair
push de
rlc d
jr nz, @exo_dontgo
dec e
ld bc, 512+32 ;2 bits, 48 offset
jr z, @exo_goforit
dec e ;2?
@exo_dontgo: ld bc, 1024+16 ;4 bits, 32 offset
jr z, @exo_goforit
ld de, 0
ld c, d ;16 offset
@exo_goforit: call @exo_getbits1
ld iy, @exo_mapbasebits+27
add iy, de
call @exo_getpair
pop bc
ex (sp), hl
push hl
sbc hl, de
pop de
ldir
pop hl
jr @exo_mainloop ;Next!

@exo_getpair: add iy, bc
ld e, d
ld b, (iy+41)
call @exo_getbits
ex de, hl
ld c, (iy-11)
ld b, (iy+93)
add hl, bc ;Always clear C flag
ex de, hl
ret

@exo_getbit: ; srl a
;ret nz
ld a, (hl)
inc hl
rra
ret

@exo_mapbasebits: defs 156 ;tables for bits, baseL, baseH

Mend

80 changes: 80 additions & 0 deletions decrunch/dzx7_turbo.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
; -----------------------------------------------------------------------------
; ZX7 decoder by Einar Saukas & Urusergi
; "Turbo" version (88 bytes, 25% faster)
; -----------------------------------------------------------------------------
; Parameters:
; HL: source address (compressed data)
; DE: destination address (decompressing)
; -----------------------------------------------------------------------------

dzx7_turbo:
ld a, $80
dzx7t_copy_byte_loop:
ldi ; copy literal byte
dzx7t_main_loop:
add a, a ; check next bit
call z, dzx7t_load_bits ; no more bits left?
jr nc, dzx7t_copy_byte_loop ; next bit indicates either literal or sequence

; determine number of bits used for length (Elias gamma coding)
push de
ld bc, 1
ld d, b
dzx7t_len_size_loop:
inc d
add a, a ; check next bit
call z, dzx7t_load_bits ; no more bits left?
jr nc, dzx7t_len_size_loop
jp dzx7t_len_value_start

; determine length
dzx7t_len_value_loop:
add a, a ; check next bit
call z, dzx7t_load_bits ; no more bits left?
rl c
rl b
jr c, dzx7t_exit ; check end marker
dzx7t_len_value_start:
dec d
jr nz, dzx7t_len_value_loop
inc bc ; adjust length

; determine offset
ld e, (hl) ; load offset flag (1 bit) + offset value (7 bits)
inc hl
defb $cb, $33 ; opcode for undocumented instruction "SLL E" aka "SLS E"
jr nc, dzx7t_offset_end ; if offset flag is set, load 4 extra bits
add a, a ; check next bit
call z, dzx7t_load_bits ; no more bits left?
rl d ; insert first bit into D
add a, a ; check next bit
call z, dzx7t_load_bits ; no more bits left?
rl d ; insert second bit into D
add a, a ; check next bit
call z, dzx7t_load_bits ; no more bits left?
rl d ; insert third bit into D
add a, a ; check next bit
call z, dzx7t_load_bits ; no more bits left?
ccf
jr c, dzx7t_offset_end
inc d ; equivalent to adding 128 to DE
dzx7t_offset_end:
rr e ; insert inverted fourth bit into E

; copy previous sequence
ex (sp), hl ; store source, restore destination
push hl ; store destination
sbc hl, de ; HL = destination - offset - 1
pop de ; DE = destination
ldir
dzx7t_exit:
pop hl ; restore source address (compressed data)
jp nc, dzx7t_main_loop

dzx7t_load_bits:
ld a, (hl) ; load another group of 8 bits
inc hl
rla
ret

; -----------------------------------------------------------------------------
113 changes: 113 additions & 0 deletions decrunch/lz48decrunch_v006.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
;
; LZ48 decrunch
;
; hl compressed data adress
; de output adress of data
;


org #8000

; CALL #8000,source,destination
di

; parameters
ld h,(ix+3)
ld l,(ix+2)
ld d,(ix+1)
ld e,(ix+0)

call LZ48_decrunch

ei
ret





LZ48_decrunch
ldi
ld b,0

nextsequence
ld a,(hl)
inc hl
ld lx,a
and #F0
jr z,lzunpack ; no litteral bytes
rrca
rrca
rrca
rrca

ld c,a
cp 15 ; more bytes for length?
jr nz,copyliteral

getadditionallength
ld a,(hl)
inc hl
inc a
jr nz,lengthnext
inc b
dec bc
jr getadditionallength
lengthnext
dec a
add a,c
ld c,a
ld a,b
adc a,0
ld b,a ; bc=length

copyliteral
ldir

lzunpack
ld a,lx
and #F
add 3
ld c,a
cp 18 ; more bytes for length?
jr nz,readoffset

getadditionallengthbis
ld a,(hl)
inc hl
inc a
jr nz,lengthnextbis
inc b
dec bc
jr getadditionallengthbis
lengthnextbis
dec a
add a,c
ld c,a
ld a,b
adc a,0
ld b,a ; bc=length

readoffset
; read encoded offset
ld a,(hl)
inc a
ret z ; LZ48 end with zero offset
inc hl
push hl
ld l,a
ld a,e
sub l
ld l,a
ld a,d
sbc a,0
ld h,a
; source=dest-copyoffset

copykey
ldir

pop hl
jr nextsequence


Loading

0 comments on commit 3919c27

Please sign in to comment.