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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
.include "declare.s"
.org 0
free:
pha.q
phb.q
phy.q
pha.q
and
tay
sbs
lda.q sp+25
ora.d sp+29
bne @getrealblk
bra @end
@getrealblk:
lda.q sp+25
sec
sbc
sta.q sp+25
lda.q (sp+25)
sta.q sp+25
ldy
lda.q (sp+25), y
sta.q sp+17
clc
adc.q sp+25
cmp.q heapptr
bne @heapadd
@dectop:
lda.q sp+25
sta.q heapptr
@chklastblk:
lda.q heapl
sta.q sp+17
ora.d sp+21
beq @end
lda.q sp+17
ldy
lda.q (sp+17), y
clc
adc.q sp+17
cmp.q heapptr
bne @end
@delblk:
lda.q sp+17
sta.q heapptr
@correctblk:
ldy
lda.q (sp+17), y
sta.q sp+25
sta.q heapl
ora.d sp+29
bne @delnxtblk
sta.q heapf
bra @end
@delnxtblk:
and
ldy
sta.q (sp+25), y
@end:
ads
ply.q
plb.q
pla.q
rts
@heapadd:
lda.q heapf
sta.q sp+9
ora.d sp+13
bne @srchflst
@empty:
ldy
sta.q (sp+25), y
ldy
sta.q (sp+25), y
lda.q sp+25
sta.q heapf
sta.q heapf
bra @end
@srchflst:
and
sta.q sp+1
ldy
@loop:
lda.q sp+9
cmp.q sp+25
beq @nextright
bcs @chkrmerge
@nextright:
sta.q sp+1
lda.q (sp+9), y
sta.q sp+9
ora.d sp+13
bne @loop
@st_lmerge2:
sta.q (sp+25), y
lda.q sp+25
sta.q heapl
bra @chklmerge2
@chkrmerge:
lda.q sp+25
clc
adc.q sp+17
cmp.q sp+9
bne @normerge
@rmerge:
ldy
lda.q sp+17
clc
adc.q (sp+9), y
sta.q (sp+25), y
@rmerge2:
ldy
lda.q (sp+9), y
sta.q (sp+25), y
sta.q sp+17
ora.d sp+21
beq @setheapl
@setprev:
lda.q sp+25
ldy
sta.q (sp+17), y
bra @chklmerge
@setheapl:
lda.q sp+25
sta.q heapl
bra @chklmerge
@normerge:
lda.q sp+9
ldy
sta.q (sp+25), y
lda.q sp+25
ldy
lda.q (sp+9), y
@chklmerge:
lda.q sp+1
ora.d sp+5
bne @chklmerge2
@newstart:
ldy
sta.q (sp+25), y
lda.q sp+25
sta.q heapf
bra @end2
@chklmerge2:
ldy
lda.q (sp+1), y
clc
adc.q sp+1
cmp.q sp+25
bne @nolmerge
@lmerge:
lda.q (sp+1), y
clc
ldb.q (sp+25), y
adc b
sta.q (sp+1), y
@lmerge2:
ldy
lda.q (sp+25), y
sta.q (sp+1), y
sta.q sp+17
ora.d sp+21
beq @newlast
@lprev:
lda.q sp+1
ldy
sta.q (sp+17), y
bra @end2
@newlast:
lda.q sp+1
sta.q heapl
bra @end2
@nolmerge:
lda.q sp+25
ldy
sta.q (sp+1), y
@nolmerge2:
lda.q sp+1
ldy
sta.q (sp+25), y
@end2:
ads
ply.q
plb.q
pla.q
rts
a
q
|