-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphc25_lib.asm
More file actions
138 lines (115 loc) · 3.91 KB
/
Copy pathphc25_lib.asm
File metadata and controls
138 lines (115 loc) · 3.91 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
SECTION code_compiler
; -----------------------------------------------------------------------------
; Decompress bitmaps for the UI
; -----------------------------------------------------------------------------
PUBLIC _decompress_ui_left
_decompress_ui_left:
ld hl, ui_left
ld de, 0xe000
call dzx0_standard
ret
PUBLIC _decompress_ui_right
_decompress_ui_right:
ld hl, ui_right
ld de, 0xe000
call dzx0_standard
ret
PUBLIC _decompress_ui_title
_decompress_ui_title:
ld hl, ui_title
ld de, 0xe000
call dzx0_standard
ret
PUBLIC _decompress_ui_bottom
_decompress_ui_bottom:
ld hl, ui_bottom
ld de, 0xe000
call dzx0_standard
ret
PUBLIC _decompress_splash
_decompress_splash:
ld hl, splash
ld de, 0xe000
call dzx0_standard
ret
PUBLIC _decompress_gameover
_decompress_gameover:
ld hl, gameover
ld de, 0xe000
call dzx0_standard
ret
; -----------------------------------------------------------------------------
; ZX0 decoder by Einar Saukas & Urusergi
; "Standard" version (68 bytes only)
; -----------------------------------------------------------------------------
; Parameters:
; HL: source address (compressed data)
; DE: destination address (decompressing)
; -----------------------------------------------------------------------------
PUBLIC dzx0_standard
dzx0_standard:
ld bc, $ffff ; preserve default offset 1
push bc
inc bc
ld a, $80
dzx0s_literals:
call dzx0s_elias ; obtain length
ldir ; copy literals
add a, a ; copy from last offset or new offset?
jr c, dzx0s_new_offset
call dzx0s_elias ; obtain length
dzx0s_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, dzx0s_literals
dzx0s_new_offset:
pop bc ; discard last offset
ld c, $fe ; prepare negative offset
call dzx0s_elias_loop ; obtain offset MSB
inc c
ret z ; check end marker
ld b, c
ld c, (hl) ; obtain offset LSB
inc hl
rr b ; last offset bit becomes first length bit
rr c
push bc ; preserve new offset
ld bc, 1 ; obtain length
call nc, dzx0s_elias_backtrack
inc bc
jr dzx0s_copy
dzx0s_elias:
inc c ; interlaced Elias gamma coding
dzx0s_elias_loop:
add a, a
jr nz, dzx0s_elias_skip
ld a, (hl) ; load another group of 8 bits
inc hl
rla
dzx0s_elias_skip:
ret c
dzx0s_elias_backtrack:
add a, a
rl c
rl b
jr dzx0s_elias_loop
; -----------------------------------------------------------------------------
; Compressed bitmaps
; -----------------------------------------------------------------------------
ui_left:
incbin "gfx/ui_left.bin.zx0"
ui_right:
incbin "gfx/ui_right.bin.zx0"
ui_title:
incbin "gfx/ui_title.bin.zx0"
ui_bottom:
incbin "gfx/ui_bottom.bin.zx0"
splash:
incbin "gfx/splash.bin.zx0"
gameover:
incbin "gfx/gameover.bin.zx0"