From 30bf0f51335e87812ffeb54e9437f0b6a1514d67 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Tue, 6 Sep 2022 07:37:20 +0100 Subject: Updated rasm to 1.7 --- tools/rasm/decrunch/dzx0_turbo_back.asm | 101 ++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 tools/rasm/decrunch/dzx0_turbo_back.asm (limited to 'tools/rasm/decrunch/dzx0_turbo_back.asm') diff --git a/tools/rasm/decrunch/dzx0_turbo_back.asm b/tools/rasm/decrunch/dzx0_turbo_back.asm new file mode 100644 index 0000000..d009e92 --- /dev/null +++ b/tools/rasm/decrunch/dzx0_turbo_back.asm @@ -0,0 +1,101 @@ +; ----------------------------------------------------------------------------- +; ZX0 decoder by Einar Saukas & introspec +; "Turbo" version (126 bytes, 21% faster) - BACKWARDS VARIANT +; ----------------------------------------------------------------------------- +; Parameters: +; HL: last source address (compressed data) +; DE: last destination address (decompressing) +; ----------------------------------------------------------------------------- + +macro dzx0_turbo_back + ld bc, 1 ; preserve default offset 1 + ld (@dzx0tb_last_offset+1), bc + ld a, $80 + jr @dzx0tb_literals +@dzx0tb_new_offset: + add a, a ; obtain offset MSB + call c, @dzx0tb_elias + dec b + ret z ; check end marker + dec c ; adjust for positive offset + ld b, c + ld c, (hl) ; obtain offset LSB + dec hl + srl b ; last offset bit becomes first length bit + rr c + inc bc + ld (@dzx0tb_last_offset+1), bc ; preserve new offset + ld bc, 1 ; obtain length + call c, @dzx0tb_elias_loop + inc bc +@dzx0tb_copy: + push hl ; preserve source +@dzx0tb_last_offset: + ld hl, 0 ; restore offset + add hl, de ; calculate destination - offset + lddr ; copy from offset + inc c + pop hl ; restore source + add a, a ; copy from literals or new offset? + jr c, @dzx0tb_new_offset +@dzx0tb_literals: + add a, a ; obtain length + call c, @dzx0tb_elias + lddr ; copy literals + inc c + add a, a ; copy from last offset or new offset? + jr c, @dzx0tb_new_offset + add a, a ; obtain length + call c, @dzx0tb_elias + jp @dzx0tb_copy +@dzx0tb_elias_loop: + add a, a + rl c + add a, a + ret nc +@dzx0tb_elias: + jp nz, @dzx0tb_elias_loop ; inverted interlaced Elias gamma coding + ld a, (hl) ; load another group of 8 bits + dec hl + rla + ret nc + add a, a + rl c + add a, a + ret nc + add a, a + rl c + add a, a + ret nc + add a, a + rl c + add a, a + ret nc +@dzx0tb_elias_reload: + add a, a + rl c + rl b + add a, a + ld a, (hl) ; load another group of 8 bits + dec hl + rla + ret nc + add a, a + rl c + rl b + add a, a + ret nc + add a, a + rl c + rl b + add a, a + ret nc + add a, a + rl c + rl b + add a, a + jr c, @dzx0tb_elias_reload + ret +; ----------------------------------------------------------------------------- +mend + -- cgit v1.2.3