-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThreeteeSML.h
243 lines (196 loc) · 5.94 KB
/
ThreeteeSML.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
; ThreeteeSML.h
; Macro Library for all the typical Macros you might want to use in a program
; Threetee Gang (C) 2017
; Some notes about macros: . Signifies not to duplicate tag (e.g generates a new one for each use of the macros
; Look at WSYNC_FOR to see how to handle errors
; ------------------------------------------------------------------
; WSYNC_FOR
; ------------------------------------------------------------------
;WSYNC for a number of cycles
MAC WSYNC_FOR
.WSYNC_IT SET {0}
IF .WSYNC_IT < 2
ECHO "MACRO ERROR: 'Should Be using for values > 1"
ERR
ENDIF
ldx #.WSYNC_IT
.WSYNC_DEL
sta WSYNC
dex
bne .WSYNC_DEL
ENDM
; ------------------------------------------------------------------
; VSYNC_NTSC
; ------------------------------------------------------------------
; Account for 3 scanlines of VSYNC
MAC VSYNC_NTSC
; Enable VSYNC
lda #2
sta VSYNC
; Wait it out
sta WSYNC
sta WSYNC
sta WSYNC
; Shift right and use new value to disable
lsr
sta VSYNC
ENDM
; ------------------------------------------------------------------
; ENABLE_VBLANK
; ------------------------------------------------------------------
; Enable VBLANK
MAC ENABLE_VBLANK
lda #2
sta VBLANK
ENDM
; ------------------------------------------------------------------
; DISABLE_VBLANK
; ------------------------------------------------------------------
; Disable VBLANK
MAC DISABLE_VBLANK
lda #1
sta VBLANK
ENDM
; ------------------------------------------------------------------
; VBLANK_NTSC
; ------------------------------------------------------------------
; Account for 37 lines of VBLANK
MAC VBLANK_NTSC
ENABLE_VBLANK
WSYNC_FOR 37
; Shift right and use new value to disable
; know a is 2 from enable
lsr
sta VBLANK
ENDM
; ------------------------------------------------------------------
; OVERSCAN_NTSC
; ------------------------------------------------------------------
; Account for 30 lines of VBLANK (Overscan)
MAC OVERSCAN_NTSC
; Enable VBLANK
lda #2
sta VBLANK
WSYNC_FOR 30
; Shift right and use new value to disable
lsr
sta VBLANK
ENDM
; ------------------------------------------------------------------
; BITWISE_NOT
; ------------------------------------------------------------------
; Use EOR for a bitwise not operation
; Sets value in acc to bitwise not of prior value
MAC BITWISE_NOT
eor #$FF
ENDM
; ------------------------------------------------------------------
; MUL
; ------------------------------------------------------------------
; Function to multiply two numbers
; buggers a bunch of register values so be prepared for that
; XInput is current acc value
; ouput is in acc
; if overflows that's stored in x
MAC MUL
.YMULVAL SET {1}
ldx #0
ldy #.YMULVAL
sta .YMULVAL
.MULBRA
clc
adc #.YMULVAL
bvc .MULNOOVER
inx
.MULNOOVER
dey
bne .MULBRA
ENDM
; ------------------------------------------------------------------
; DIV_INT
; ------------------------------------------------------------------
; Function to divide two numbers
; buggers a bunch of register values so be prepared for that
; X Input is current acc value
; ouput is in acc
; X is used as overflow count
MAC DIV_INT
.YDIVVAL SET {1}
ldy #0
.DIVBRA
iny
sec
sbc #.YDIVVAL
bpl .DIVBRA
cpx #0
beq .DIVEND
dex
jmp .DIVBRA
.DIVEND
tya
ENDM
; ------------------------------------------------------------------
; CLEAR_PLAYER_0
; ------------------------------------------------------------------
; Stop drawing a sprite for player zero
MAC CLEAR_PLAYER_0
lda #0
sta GRP0
sta COLUP0
ENDM
; ------------------------------------------------------------------
; TIMER_SET_DELAY
; ------------------------------------------------------------------
; Macro to set delay
MAC TIMER_SET_DELAY
.TIMSETDEL SET {0}
lda #.TIMSETDEL
sta TIM64T
ENDM
; ------------------------------------------------------------------
; TIMER_SET_SCANLINE_DELAY_NTSC_CALC
; ------------------------------------------------------------------
; Macro to delay for a certain number of Scanlines
; Can be used to execute logic in VBLANK and overscan before we need to drawing
; Needs pairing with TIMER_WAIT at the end
; Formula used is (N*76 + 13)/64 (64 cycle timer, 13 cycles to use timer and N is number of scanlines)
; 76 is the cycles for a normal scanline to complete
; should be 43 for NTSC VBLANK
MAC TIMER_SET_SCANLINE_DELAY_NTSC_CALC
.NUM_SCANLINES SET {0}
IF .NUM_SCANLINES < 2
ECHO "MACRO ERROR: 'Just use WSYNC for values less than 2!"
ERR
ENDIF
lda #.NUM_SCANLINES
MUL #76
adc #13
DIV_INT #64
sta TIM64T
ENDM
; ------------------------------------------------------------------
; TIMER_SET_SCANLINE_DELAY_NTSC_VBLANK
; ------------------------------------------------------------------
; Cheekily sets delay required for VBLANK
; should be 43 for NTSC VBLANK
MAC TIMER_SET_SCANLINE_DELAY_NTSC_VBLANK
TIMER_SET_DELAY #43
ENDM
; ------------------------------------------------------------------
; TIMER_SET_SCANLINE_DELAY_NTSC_OVERSCAN
; ------------------------------------------------------------------
; Cheekily sets delay required for Overscan
; should be 35 for NTSC Overscan
MAC TIMER_SET_SCANLINE_DELAY_NTSC_OVERSCAN
TIMER_SET_DELAY #35
ENDM
; ------------------------------------------------------------------
; TIMER_WAIT
; ------------------------------------------------------------------
; Macro to wait for timer delay to run down
MAC TIMER_WAIT
.TIMERWAITCONT
lda INTIM
bne .TIMERWAITCONT
ENDM
; ------------------------------------------------------------------