forked from Pigu-A/nobankskank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmacros.asm
executable file
·248 lines (213 loc) · 2.93 KB
/
macros.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
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
; global.functions including pseudo instructions
; determine if word a is 2-byte immediate value or memory address of 2-byte data
; then return the correct lower byte or upper byte
lo .function a
b := a ; a
.if type(a) == address
b := <a ; #a
.fi
.endf b
hi .function a
b := a+1 ; a
.if type(a) == address
b := >a ; #a
.fi
.endf b
; stupid 6502
add .function a
clc
adc a
.endf
sub .function a
sec
sbc a
.endf
asr .function a
cmp #$80 ; bit 7 -> carry
ror a
.endf
mva .function s, d
lda s
sta d
.endf
mvx .function s, d
ldx s
stx d
.endf
mvy .function s, d
ldy s
sty d
.endf
neg .function x=-1
.if x == -1 ; acc
eor #$ff
add #1
.else ; abs/zp
lda x
eor #$ff
sta x
inc x
.fi
.endf
pusha .function
pha
txa
pha
tya
pha
.endf
popa .function
pla
tay
pla
tax
pla
.endf
adcb .function v, s, d=-1
dd := d
.if d == -1
dd := s
.fi
lda s
adc v
sta dd
.endf
addb .function v, s, d=-1
clc
adcb v, s, d
.endf
sbcb .function v, s, d=-1
dd := d
.if d == -1
dd := s
.fi
lda s
sbc v
sta dd
.endf
subb .function v, s, d=-1
sec
sbcb v, s, d
.endf
; 16-bit expansions
mwa .function s, d
mva lo(s), d
mva hi(s), d+1
.endf
mwx .function s, d
mvx lo(s), d
mvx hi(s), d+1
.endf
mwy .function s, d
mvy lo(s), d
mvy hi(s), d+1
.endf
adcw .function v, s, d=-1
.if (type(v) == address) && (v < #256) && (d == -1)
lda lo(s)
adc v
sta s
bcc _x
inc s+1
_x
.else
dd := d
.if d == -1
dd := s
.fi
lda lo(s)
adc lo(v)
sta dd
lda hi(s)
adc hi(v)
sta dd+1
.fi
.endf
addw .function v, s, d=-1
clc
adcw v, s, d
.endf
sbcw .function v, s, d=-1
.if (type(v) == address) && (v < #256) && (d == -1)
lda lo(s)
sbc v
sta s
bcs +
dec s+1
+
.else
dd := d
.if d == -1
dd := s
.fi
lda lo(s)
sbc lo(v)
sta dd
lda hi(s)
sbc hi(v)
sta dd+1
.fi
.endf
subw .function v, s, d=-1
sec
sbcw v, s, d
.endf
cmpw .function a, b
lda hi(b)
cmp hi(b)
bne _x
lda lo(b)
cmp lo(b)
_x
.endf
tstw .function a
lda a
ora a+1
.endf
incw .function a
inc a
bne _x
inc a+1
_x
.endf
decw .function a
sec
lda a
sbc #1
sta a
lda a+1
sbc #0
sta a+1
.endf
rolw .function a
rol a
rol a+1
.endf
aslw .function a
asl a
rol a+1
.endf
lsrw .function a
lsr a+1
ror a
.endf
rorw .function a
ror a+1
ror a
.endf
; adjust a constant 2-bytes length to fit the 2 vars loop
wordloopadj .function a
b := a + $100
.ifeq <a
b := a
.fi
.endf b
; return true if a's data goes over the page boundary
pagecross .function a
.endf <(a+size(a)) != <a
; get tilemap offset from 20 chars text mode
coord20 .function x, y, o=0
.endf y * 20 + x + o
; get tilemap offset from 40 chars text mode
coord40 .function x, y, o=0
.endf y * 40 + x + o