-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdzx1_standard.asm
62 lines (61 loc) · 2.51 KB
/
dzx1_standard.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
; -----------------------------------------------------------------------------
; ZX1 decoder by Einar Saukas
; "Standard" version (68 bytes only)
; -----------------------------------------------------------------------------
; Parameters:
; HL: source address (compressed data)
; DE: destination address (decompressing)
; -----------------------------------------------------------------------------
dzx1_standard:
ld bc, $ffff ; preserve default offset 1
push bc
ld a, $80
dzx1s_literals:
call dzx1s_elias ; obtain length
ldir ; copy literals
add a, a ; copy from last offset or new offset?
jr c, dzx1s_new_offset
call dzx1s_elias ; obtain length
dzx1s_copy:
ex (sp), hl ; preserve source, restore offset
push hl ; preserve offset
add hl, de ; calculate destination - offset
ldir ; copy from offset
pop hl ; restore offset
ex (sp), hl ; preserve offset, restore source
add a, a ; copy from literals or new offset?
jr nc, dzx1s_literals
dzx1s_new_offset:
inc sp ; discard last offset
inc sp
dec b
ld c, (hl) ; obtain offset LSB
inc hl
rr c ; single byte offset?
jr nc, dzx1s_msb_skip
ld b, (hl) ; obtain offset MSB
inc hl
rr b ; replace last LSB bit with last MSB bit
inc b
ret z ; check end marker
rl c
dzx1s_msb_skip:
push bc ; preserve new offset
call dzx1s_elias ; obtain length
inc bc
jr dzx1s_copy
dzx1s_elias:
ld bc, 1 ; interlaced Elias gamma coding
dzx1s_elias_loop:
add a, a
jr nz, dzx1s_elias_skip
ld a, (hl) ; load another group of 8 bits
inc hl
rla
dzx1s_elias_skip:
ret nc
add a, a
rl c
rl b
jr dzx1s_elias_loop
; -----------------------------------------------------------------------------