forked from tschak909/dodgeball
-
Notifications
You must be signed in to change notification settings - Fork 0
/
macro.h
executable file
·293 lines (254 loc) · 9.36 KB
/
macro.h
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
; MACRO.H
; Version 1.05, 13/NOVEMBER/2003
VERSION_MACRO = 105
;
; THIS FILE IS EXPLICITLY SUPPORTED AS A DASM-PREFERRED COMPANION FILE
; PLEASE DO *NOT* REDISTRIBUTE MODIFIED VERSIONS OF THIS FILE!
;
; This file defines DASM macros useful for development for the Atari 2600.
; It is distributed as a companion machine-specific support package
; for the DASM compiler. Updates to this file, DASM, and associated tools are
; available at at http://www.atari2600.org/dasm
;
; Many thanks to the people who have contributed. If you take issue with the
; contents, or would like to add something, please write to me
; ([email protected]) with your contribution.
;
; Latest Revisions...
;
; 1.05 14/NOV/2003 - Added VERSION_MACRO equate (which will reflect 100x version #)
; This will allow conditional code to verify MACRO.H being
; used for code assembly.
; 1.04 13/NOV/2003 - SET_POINTER macro added (16-bit address load)
;
; 1.03 23/JUN/2003 - CLEAN_START macro added - clears TIA, RAM, registers
;
; 1.02 14/JUN/2003 - VERTICAL_SYNC macro added
; (standardised macro for vertical synch code)
; 1.01 22/MAR/2003 - SLEEP macro added.
; - NO_ILLEGAL_OPCODES switch implemented
; 1.0 22/MAR/2003 Initial release
; Note: These macros use illegal opcodes. To disable illegal opcode usage,
; define the symbol NO_ILLEGAL_OPCODES (-DNO_ILLEGAL_OPCODES=1 on command-line).
; If you do not allow illegal opcode usage, you must include this file
; *after* including VCS.H (as the non-illegal opcodes access hardware
; registers and require them to be defined first).
; Available macros...
; SLEEP n - sleep for n cycles
; VERTICAL_SYNC - correct 3 scanline vertical synch code
; CLEAN_START - set machine to known state on startup
; SET_POINTER - load a 16-bit absolute to a 16-bit variable
;-------------------------------------------------------------------------------
; SLEEP duration
; Original author: Thomas Jentzsch
; Inserts code which takes the specified number of cycles to execute. This is
; useful for code where precise timing is required.
; ILLEGAL-OPCODE VERSION DOES NOT AFFECT FLAGS OR REGISTERS.
; LEGAL OPCODE VERSION MAY AFFECT FLAGS
; Uses illegal opcode (DASM 2.20.01 onwards).
MAC SLEEP ;usage: SLEEP n (n>1)
.CYCLES SET {1}
IF .CYCLES < 2
ECHO "MACRO ERROR: 'SLEEP': Duration must be > 1"
ERR
ENDIF
IF .CYCLES & 1
IFNCONST NO_ILLEGAL_OPCODES
nop 0
ELSE
bit VSYNC
ENDIF
.CYCLES SET .CYCLES - 3
ENDIF
REPEAT .CYCLES / 2
nop
REPEND
ENDM
;-------------------------------------------------------------------------------
; VERTICAL_SYNC
; Original author: Manuel Polik
; Inserts the code required for a proper 3 scannline
; vertical sync sequence
;
; Note: Alters the accumulator
;
; IN:
; OUT: A = 1
MAC VERTICAL_SYNC
LDA #$02 ; A = VSYNC enable
STA WSYNC ; Finish current line
STA VSYNC ; Start vertical sync
STA WSYNC ; 1st line vertical sync
STA WSYNC ; 2nd line vertical sync
LSR ; A = VSYNC disable
STA WSYNC ; 3rd line vertical sync
STA VSYNC ; Stop vertical sync
ENDM
;-------------------------------------------------------------------------------
; CLEAN_START
; Original author: Andrew Davie
; Standardised start-up code, clears stack, all TIA registers and RAM to 0
; Sets stack pointer to $FF, and all registers to 0
; Sets decimal mode off, sets interrupt flag (kind of un-necessary)
; Use as very first section of code on boot (ie: at reset)
; Code written to minimise total ROM usage - uses weird 6502 knowledge :)
MAC CLEAN_START
sei
cld
ldx #0
txa
tay
.CLEAR_STACK dex
txs
pha
bne .CLEAR_STACK ; SP=$FF, X = A = Y = 0
ENDM
;-------------------------------------------------------
; SET_POINTER
; Original author: Manuel Rotschkar
;
; Sets a 2 byte RAM pointer to an absolute address.
;
; Usage: SET_POINTER pointer, address
; Example: SET_POINTER SpritePTR, SpriteData
;
; Note: Alters the accumulator, NZ flags
; IN 1: 2 byte RAM location reserved for pointer
; IN 2: absolute address
MAC SET_POINTER
.POINTER SET {1}
.ADDRESS SET {2}
LDA #<.ADDRESS ; Get Lowbyte of Address
STA .POINTER ; Store in pointer
LDA #>.ADDRESS ; Get Hibyte of Address
STA .POINTER+1 ; Store in pointer+1
ENDM
;-------------------------------------------------------
; SAME PAGE BRANCH CHECK
; Original auther: John Payson
;
; Usage: sbeq, sbne, etc just like a normal beq, bne, etc.
; A message will be output if the target of the branch
; is not on the same page.
;
mac sbcc
bcc {1}
if (* ^ {1}) & $FF00
echo "PAGE CROSSING","WARNING ",{1}," at ",*
err
endif
endm
mac sbcs
bcs {1}
if (* ^ {1}) & $FF00
echo "PAGE CROSSING","WARNING ",{1}," at ",*
err
endif
endm
mac sbeq
beq {1}
if (* ^ {1}) & $FF00
echo "PAGE CROSSING","WARNING ",{1}," at ",*
err
endif
endm
mac sbmi
bmi {1}
if (* ^ {1}) & $FF00
echo "PAGE CROSSING","WARNING ",{1}," at ",*
err
endif
endm
mac sbne
bne {1}
if (* ^ {1}) & $FF00
echo "PAGE CROSSING","WARNING ",{1}," at ",*
err
endif
endm
mac sbpl
bpl {1}
if (* ^ {1}) & $FF00
echo "PAGE CROSSING","WARNING ",{1}," at ",*
err
endif
endm
mac sbvc
bvc {1}
if (* ^ {1}) & $FF00
echo "PAGE CROSSING","WARNING ",{1}," at ",*
err
endif
endm
mac sbvs
bvs {1}
if (* ^ {1}) & $FF00
echo "PAGE CROSSING","WARNING ",{1}," at ",*
err
endif
endm
;-------------------------------------------------------
; DIFFERENT PAGE BRANCH CHECK
; Original auther: Darrell Spice, Jr.
;
; Usage: dbeq, dbne, etc just like a normal beq, bne, etc.
; A message will be output if the target of the branch
; is not on a different page.
;
mac dbcc
bcc {1}
if ((* ^ {1}) & $FF00) = 0
echo "SAME PAGE","WARNING ",{1}," at ",*
err
endif
endm
mac dbcs
bcs {1}
if ((* ^ {1}) & $FF00) = 0
echo "SAME PAGE","WARNING ",{1}," at ",*
err
endif
endm
mac dbeq
beq {1}
if ((* ^ {1}) & $FF00) = 0
echo "SAME PAGE","WARNING ",{1}," at ",*
err
endif
endm
mac dbmi
bmi {1}
if ((* ^ {1}) & $FF00) = 0
echo "SAME PAGE","WARNING ",{1}," at ",*
err
endif
endm
mac dbne
bne {1}
if ((* ^ {1}) & $FF00) = 0
echo "SAME PAGE","WARNING ",{1}," at ",*
err
endif
endm
mac dbpl
bpl {1}
if ((* ^ {1}) & $FF00) = 0
echo "SAME PAGE","WARNING ",{1}," at ",*
err
endif
endm
mac dbvc
bvc {1}
if ((* ^ {1}) & $FF00) = 0
echo "SAME PAGE","WARNING ",{1}," at ",*
err
endif
endm
mac dbvs
bvs {1}
if ((* ^ {1}) & $FF00) = 0
echo "SAME PAGE","WARNING ",{1}," at ",*
err
endif
endm
; EOF