-
Notifications
You must be signed in to change notification settings - Fork 0
/
macros.asm
220 lines (191 loc) · 3.34 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
!macro reserve_int {
!fill int_sizeof, $00
}
!macro reserve_int64 {
!fill int64_sizeof, $00
}
!macro reserve_long {
!fill long_sizeof, $00
}
!macro reserve_ptr {
!fill ptr_sizeof, $00
}
!macro reserve_short {
!fill short_sizeof, $00
}
!macro BasicUpstart65 {
* = $2001
!byte $16,$20 ;End of command marker (first byte after the 00 terminator)
!byte $0a,$00 ;10
!byte $fe,$02,$30,$3a ;BANK 0:
!byte $9e ;SYS
!text "$202C"
!byte $3a, $8f ;:REM
!fill 21, $14
!text "BAS", $00
!byte $00,$00 ;End of basic terminators
.start:
}
!macro enable_40mhz {
lda #65
sta $00
}
!macro RunDMAJob .JobPointer {
lda #(.JobPointer >> 16)
sta $D702
sta $D704
lda #>.JobPointer
sta $D701
lda #<.JobPointer
sta $D705
}
!macro DMAFillJob .SourceByte, .Destination, .Length, .Chain {
!byte $00
!if (.Chain) {
!byte $07
} else {
!byte $03
}
!word .Length
!word .SourceByte
!byte $00
!word .Destination & $FFFF
!byte ((.Destination >> 16) & $0F)
!if (.Chain) {
!word $0000
}
}
!macro DMACopyJob .Source, .Destination, .Length, .Chain, .Backwards {
!byte $00 //No more options
!if(.Chain) {
!byte $04 //Copy and chain
} else {
!byte $00 //Copy and last request
}
!set .backByte = 0
!if(.Backwards) {
!set .backByte = $40
!set .Source = .Source + .Length - 1
!set .Destination = .Destination + .Length - 1
}
!word .Length //Size of Copy
!word .Source & $ffff
!byte (.Source >> 16) + .backByte
!word .Destination & $ffff
!byte ((.Destination >> 16) & $0f) + .backByte
!if(.Chain) {
!word $0000
}
}
!macro short_copy .source, .destination, .length {
ldx #.length
- lda .source, x
sta .destination, x
dex
bpl -
}
!macro long_fill .destination, .length {
lda #<.length
sta fill_dma + 2
lda #>.length
sta fill_dma + 3
lda .destination
sta fill_dma + 7
lda .destination + 1
sta fill_dma + 8
+RunDMAJob fill_dma
}
!macro long_copy .source, .destination, .length {
lda #<.length
sta copy_dma + 2
lda #>.length
sta copy_dma + 3
lda #<.source
sta copy_dma + 4
lda #>.source
sta copy_dma + 5
lda #<.destination
sta copy_dma + 7
lda #>.destination
sta copy_dma + 8
+RunDMAJob copy_dma
}
!macro set_zp .zp, .ptr {
lda .ptr
sta .zp
lda .ptr + 1
sta .zp + 1
}
!macro copy_word .src, .dst {
lda .src
sta .dst
lda .src + 1
sta .dst + 1
}
!macro store_word .value, .destination {
lda #<.value
sta .destination
lda #>.value
sta .destination + 1
}
!macro store_word_to_zp_offset .value, .zp, .offset {
ldy #.offset
lda #<.value
sta (.zp), y
iny
lda #>.value
sta (.zp), y
}
!macro store_word_to_zp_y .value, .zp {
iny
lda #<.value
sta (.zp), y
iny
lda #>.value
sta (.zp), y
}
!macro copy_ptr .ptr, .destination {
lda .ptr
sta .destination
lda .ptr + 1
sta .destination + 1
}
!macro copy_word_to_zp_offset .source, .zp, .offset {
ldy #.offset
lda .source
sta (.zp), y
iny
lda .source + 1
sta (.zp), y
}
!macro copy_word_to_zp_y .source, .zp {
iny
lda .source
sta (.zp), y
iny
lda .source + 1
sta (.zp), y
}
!macro copy_long_to_zp .source, .zp, .length {
ldy #.length
- lda .source, y
sta (.zp), y
dey
bpl -
}
!macro copy_word_from_zp_offset .zp, .destination, .offset {
ldy #.offset
lda (.zp), y
sta .destination
iny
lda (.zp), y
sta .destination + 1
}
!macro copy_word_from_zp_y .zp, .destination {
iny
lda (.zp), y
sta .destination
iny
lda (.zp), y
sta .destination + 1
}