-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhisprite.s
291 lines (231 loc) · 4.19 KB
/
hisprite.s
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
;
; hisprite.s
;
; Created by Quinn Dunki on 7/19/16
; Copyright (c) 2015 One Girl, One Laptop Productions. All rights reserved.
;
.org $6000
.include "macros.s"
; Softswitches
TEXT = $c050
TEXT2 = $c051
HIRES1 = $c057
HIRES2 = $c058
; ROM entry points
COUT = $fded
ROMWAIT = $fca8
; Zero page locations we use (unused by Monitor, Applesoft, or ProDOS)
PARAM0 = $06
PARAM1 = $07
PARAM2 = $08
PARAM3 = $09
SCRATCH0 = $19
SCRATCH1 = $1a
SPRITEPTR_L = $1b
SPRITEPTR_H = $1c
MAXSPRITEINDEX = 3 ; Sprite count - 1
MAXPOSX = 127 ; This demo doesn't wanna do 16 bit math
MAXPOSY = 127
MAXLOCALBATCHINDEX = 3 ; Sprites in batch - 1
MAXBATCHINDEX = 0 ; Number of batches - 1
; Macros
.macro BLITBYTE xPos,yPos,addr
lda #xPos
sta PARAM0
lda #yPos
sta PARAM1
lda #<addr
sta PARAM2
lda #>addr
sta PARAM3
jsr BlitSpriteOnByte
.endmacro
.macro BLIT xPos,yPos,addr
lda #xPos
sta PARAM0
lda #yPos
sta PARAM1
lda #<addr
sta PARAM2
lda #>addr
sta PARAM3
jsr BlitSprite
.endmacro
.macro WAIT
lda #$80
jsr $fca8
.endmacro
main:
jsr EnableHires
lda #$00
jsr VenetianFill
mainLoop:
jsr checkKbd
renderLoop:
; Find our sprite pointer
lda spriteNum ; 4
asl ; 2
tax ; 2
lda META_BUFFERS+1,x ; 4
sta SPRITEPTR_H ; 3
lda META_BUFFERS,x ; 4
sta SPRITEPTR_L ; 3
; Find Y coordinate
ldy #1 ; 2
lda (SPRITEPTR_L),y ; 5
sta PARAM1 ; 3
; Find X coordinate
ldy #0 ; 2
lda (SPRITEPTR_L),y ; 5
sta PARAM0 ; 3
jsr SPACESHIP ; 6 48 cycles overhead to here
; Next sprite
dec spriteNum ; 6
dec batchLocalIndex ; 6
bmi restartList ; 2
jmp renderLoop ; 3 65 cycles overhead per sprite
restartList:
lda batchMaxIndex
sta spriteNum
lda #MAXLOCALBATCHINDEX
sta batchLocalIndex
; jmp batchLoop
VBL_SYNC
; Background restore
backgroundLoop:
; Find our sprite pointer
lda spriteNum
asl
tax
lda META_BUFFERS+1,x
sta SPRITEPTR_H
lda META_BUFFERS,x
sta SPRITEPTR_L
; Find Y coordinate
ldy #1
lda (SPRITEPTR_L),y
sta PARAM1
; Find X coordinate
ldy #0
lda (SPRITEPTR_L),y
sta PARAM0
jsr BLACK
; Next sprite
dec spriteNum
dec batchLocalIndex
bmi backgroundRestartList
jmp backgroundLoop ; 65 cycles overhead per rect
backgroundRestartList:
lda batchMaxIndex
sta spriteNum
lda #MAXLOCALBATCHINDEX
sta batchLocalIndex
; jmp batchLoop ; Skip movement
movementLoop:
; Find our sprite pointer
lda spriteNum
asl
tax
lda META_BUFFERS+1,x
sta SPRITEPTR_H
lda META_BUFFERS,x
sta SPRITEPTR_L
; Apply X velocity to X coordinate
clc
ldy #0
lda (SPRITEPTR_L),y
ldy #2
adc (SPRITEPTR_L),y
bmi flipX
cmp #MAXPOSX
bpl flipX
; Store the new X
ldy #0
sta (SPRITEPTR_L),y
adjustY:
; Apply Y velocity to Y coordinate
clc
ldy #1
lda (SPRITEPTR_L),y
ldy #3
adc (SPRITEPTR_L),y
bmi flipY
cmp #MAXPOSY
bpl flipY
; Store the new Y
ldy #1
sta (SPRITEPTR_L),y
continueMovementList:
dec spriteNum
bmi movementRestartList
jmp movementLoop
flipX:
lda (SPRITEPTR_L),y
eor #$ff
inc
sta (SPRITEPTR_L),y
bra adjustY
flipY:
lda (SPRITEPTR_L),y
eor #$ff
inc
sta (SPRITEPTR_L),y
bra continueMovementList
movementRestartList:
batchLoop:
dec batchIndex
bpl batchContinue
lda #MAXBATCHINDEX
sta batchIndex
lda #MAXSPRITEINDEX
sta spriteNum
batchContinue:
jmp mainLoop
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; checkKbd
; Exits app on a keystroke
;
checkKbd:
; rts
lda $c000
bpl checkKbdDone
sta $c010
cmp #241 ; 'q' with high bit set
bne checkKbdDone
jsr EnableText
; pla ; Pull our own frame off the stack...
; pla
; pla
; pla
pla ; ...four local variables + return address...
pla
rts ; ...so we can quit to ProDOS from here
checkKbdDone:
rts
spriteNum:
.byte MAXSPRITEINDEX
batchIndex:
.byte MAXBATCHINDEX
batchMaxIndex:
.byte MAXSPRITEINDEX
batchLocalIndex:
.byte MAXLOCALBATCHINDEX
bgFilename:
.byte "KOL",0
.include "graphics.s"
.include "hgrtableX.s"
.include "hgrtableY.s"
.include "spriteBuffers.s"
.include "spritegen0.s"
.include "spritegen0b.s"
;.include "spritegen1.s"
;.include "spritegen2.s"
;.include "spritegen3.s"
;.include "spritegen4.s"
; Suppress some linker warnings - Must be the last thing in the file
.SEGMENT "ZPSAVE"
.SEGMENT "EXEHDR"
.SEGMENT "STARTUP"
.SEGMENT "INIT"
.SEGMENT "LOWCODE"