-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcompress.asm
173 lines (152 loc) · 2.05 KB
/
compress.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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
;
; Sequencer Pattern Compress/Decompress (RLE)
;
compress:
lda #WRAM_PATTERNS
jsr setMMC1r1
lda #<patterns
sta tmp0
lda #>patterns
sta tmp1
lda #<$7000
sta tmp2
lda #>$7000
sta tmp3
ldy #$00
lda #$FF
: sta (tmp2),y
iny
bne :-
ldx #$60 ;96 blocks
lda #$00
sta tmp4
: ldy #$00
lda (tmp0),y ;0?
bne :++
lda tmp4 ;yes, doing RLE?
bne :+ ;yes
sta (tmp2),y ;no, store 0 token
inc tmp2 ;update dest address
bne :+
inc tmp3
: inc tmp4 ;update RLE count
bne :+++ ;should never go over 255 (pattern would be 255 * 5)
: pha ;save byte
lda tmp4 ;any RLE?
beq :+ ;no
sta (tmp2),y ;yes, write count
lda #$00 ;clear count
sta tmp4
inc tmp2 ;update dest address
bne :+
inc tmp3
: pla ;retrieve byte
sta (tmp2),y
iny
lda (tmp0),y
sta (tmp2),y
iny
lda (tmp0),y
sta (tmp2),y
iny
lda (tmp0),y
sta (tmp2),y
iny
lda (tmp0),y
sta (tmp2),y
lda tmp2
clc
adc #$05
sta tmp2
bcc :+
inc tmp3
: lda tmp0
clc
adc #$05
sta tmp0
bcc :+
inc tmp1
: dex
bne :------
ldy #$00
lda tmp4
beq :+
sta (tmp2),y
iny
: lda #$00
sta (tmp2),y
iny
sta (tmp2),y
rts
decompress: lda #<$7000
sta tmp0
lda #>$7000
sta tmp1
lda #<$7200
sta tmp2
lda #>$7200
sta tmp3
: ldy #$00
lda (tmp0),y ;token?
bne :++ ;no
iny ;yes, get count
lda (tmp0),y
beq :+++++ ;00 00 so done
tax ;otherwise load count in X
: ldy #$00 ;clear 5 bytes
tya
sta (tmp2),y
iny
sta (tmp2),y
iny
sta (tmp2),y
iny
sta (tmp2),y
iny
sta (tmp2),y
lda tmp2 ;update dest pointer
clc
adc #$05
sta tmp2
lda tmp3
adc #$00
sta tmp3
dex ;dec count
bne :- ;done?
lda tmp0 ;yes update source pointer
clc
adc #$02
sta tmp0
lda tmp2
clc
adc #$00
sta tmp2
jmp :-- ;get more
: sta (tmp2),y ;copy 5 bytes
iny
lda (tmp0),y
sta (tmp2),y
iny
lda (tmp0),y
sta (tmp2),y
iny
lda (tmp0),y
sta (tmp2),y
iny
lda (tmp0),y
sta (tmp2),y
lda tmp0 ;update source
clc
adc #$05
sta tmp0
bne :+
inc tmp1
: lda tmp2 ;update dest
clc
adc #$05
sta tmp2
bne :+
inc tmp3
:
jmp :----- ;get more
: rts