-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdzx1_turbo.asm
102 lines (101 loc) · 3.26 KB
/
dzx1_turbo.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
; -----------------------------------------------------------------------------
; ZX1 decoder by Einar Saukas & introspec
; "Turbo" version (128 bytes, 20% faster)
; -----------------------------------------------------------------------------
; Parameters:
; HL: source address (compressed data)
; DE: destination address (decompressing)
; -----------------------------------------------------------------------------
dzx1_turbo:
ld bc, $ffff ; preserve default offset 1
ld (dzx1t_last_offset+1), bc
inc bc
ld a, $80
jr dzx1t_literals
dzx1t_new_offset:
dec b
ld c, (hl) ; obtain offset LSB
inc hl
rr c ; single byte offset?
jr nc, dzx1t_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
dzx1t_msb_skip:
ld (dzx1t_last_offset+1), bc ; preserve new offset
ld bc, 1 ; obtain length
add a, a
call c, dzx1t_elias
inc bc
dzx1t_copy:
push hl ; preserve source
dzx1t_last_offset:
ld hl, 0 ; restore offset
add hl, de ; calculate destination - offset
ldir ; copy from offset
pop hl ; restore source
add a, a ; copy from literals or new offset?
jr c, dzx1t_new_offset
dzx1t_literals:
inc c ; obtain length
add a, a
call c, dzx1t_elias
ldir ; copy literals
add a, a ; copy from last offset or new offset?
jr c, dzx1t_new_offset
inc c ; obtain length
add a, a
call c, dzx1t_elias
jp dzx1t_copy
dzx1t_elias_loop:
add a, a
rl c
add a, a
ret nc
dzx1t_elias:
jp nz, dzx1t_elias_loop ; inverted interlaced Elias gamma coding
ld a, (hl) ; load another group of 8 bits
inc 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
dzx1t_elias_reload:
add a, a
rl c
rl b
add a, a
ld a, (hl) ; load another group of 8 bits
inc 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, dzx1t_elias_reload
ret
; -----------------------------------------------------------------------------