-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstar.asm
344 lines (320 loc) · 6.24 KB
/
star.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
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
*=$0801
!byte $0c,$08,$0a,$00,$9e,$20,$32,$33,$30,$34,$00,$00,$00 ; BASIC auto start at $0900
screen_color = $f7
color = $f8
color_h = $f9
velocity = $fa
cursor = $fb ; locations in screen memory
cursor_h = $fc
cursor_clear = $fd
cursor_clear_h = $fe
bitmask_clear = $ff
x_pos = $1200 ; +32
x_pos_h = $1220 ; +32
y_pos = $1240 ; +32
cursor_buffer = $1260 ; + 32
cursor_buffer_h = $1280 ; + 32
bitmask_buffer = $12a0 ; + 32
size = 32
*=$0900
jsr init
jsr blank_video
jsr blank_screen
jsr init_starfield
move_loop
jsr draw_stars
jsr move_stars
jsr update_star_colors
vsync_wait
lda $d012
bne vsync_wait
jmp move_loop
init
lda $d018
ora #$8 ; Set video base to 8192
sta $d018
lda #0 ; color
sta $d020 ; set border color
lda $d011
ora #$20 ; set high res mode
sta $d011
rts
blank_video
lda #$00
sta cursor
lda #$20
sta cursor_h
ldy #0
videoloop
lda #0
sta (cursor), y
iny
bne videoloop ; loop unless high bit needs inc
inc cursor_h
lda cursor_h ; check end of range
cmp #$40 ; 8000 bytes
beq blank_screen ; finished
jmp videoloop
rts
blank_screen
ldy #0
lda #16
screenloop
sta $0400, Y
sta $0500, Y
sta $0600, Y
sta $0700, Y
iny
bne screenloop
rts
init_starfield
ldx #0
next_star
jsr init_star
inx
cpx #size
bcc next_star
rts
draw_stars
ldy #0
draw_star
jsr plot_star ; Plot star index y, return with pixel bit index in x
txa
pha
jsr set_color ; Set color in screen memory using star at index y
pla
tax
lda cursor_buffer_h, y
beq save_cursor ; Skip if buffer is empty
sta cursor_clear_h
lda cursor_buffer, y
sta cursor_clear
lda bitmask_buffer, y
sta bitmask_clear
tya
pha
ldy #0
lda (cursor_clear), y
and bitmask_clear ; clear star
sta (cursor_clear), y
pla
tay
save_cursor
lda cursor
sta cursor_buffer, y ; store coordinate in buffer
lda cursor_h
sta cursor_buffer_h, y
lda x_bit_clear, x
sta bitmask_buffer, y ; store bitmask in buffer
iny
cpy #size
bcc draw_star
rts
move_stars
ldx #0
move_next_star
jsr update_velocity ; Update velocity
lda x_pos, x
clc
adc velocity, x
sta x_pos, x
lda x_pos_h, x
adc #0
sta x_pos_h, x
inx
cpx #size
bcc move_next_star
rts
update_star_colors
ldx #0
update_color
lda cursor_buffer_h, x
beq color_loop_done
lda cursor_buffer, x
tax
lda color_h, y
sta screen_color
lda color, y
tay
pha
lda (color), y
and #%00001111
ora screen_color
sta (color), y
pla
tay
color_loop_done
inx
cpx #size
bcc update_color
; Implement your color enhancement logic here
rts
color_loop_done
inx
cpx #size
bcc update_color
rts
init_star
lda #0
sta x_pos_h, x
jsr rnd
lda $d012 ; Use current raster line for randomness
and #%00111111 ; Get a more random value for X
clc
adc x_pos, x
sta x_pos, x
lda #0
adc x_pos_h, x
sta x_pos_h, x
jsr rnd
lda $d012 ; Use current raster line for randomness
and #%11000000 ; Get a different random value for Y
sta y_pos, x
rts
new_star
jsr regen_y
lda #63 ; move x to pos 319
sta x_pos, x
lda #1
sta x_pos_h, x
continue_move
inx
cpx #size
bcc update_vel
rts
plot_star
lda y_pos, y
lsr ; /8
lsr
lsr
sta cursor_h ; high = y / 8 * 256
sta cursor
lda #0
ldx #6; low = y / 8 * 64
y_low_mul
asl cursor
rol
dex
bne y_low_mul
clc
adc cursor_h
sta cursor_h
lda y_pos, y
and #%00000111
clc
adc cursor
sta cursor
lda cursor_h
adc #0
sta cursor_h
lda x_pos, y
and #%11111000
clc
adc cursor
sta cursor
lda cursor_h
adc x_pos_h, y
sta cursor_h
lda x_pos, y
and #%00000111
tax ; Lose contents of x
lda cursor_h ; add video offset
clc
adc #$20
sta cursor_h
tya
pha
ldy #0
lda (cursor), y
ora x_bit_set, x
sta (cursor), y
pla
tay
rts
set_color
lda y_pos, y ; / 8
lsr
lsr
lsr
tax
lda y_screen_h, x ; Lookup *40 table
sta color_h
lda y_screen, x
sta color
lda x_pos_h, y ; / 8
lsr ; (x < 320)
lda x_pos, y
ror
lsr
lsr
clc
adc color
sta color
lda #04 ; Add final carry and $0400
adc color_h
sta color_h
lda y_pos, y ; Use low 4 bits for color
asl
asl
asl
asl
cmp #0
bne save_color; Proceed for normal colors
lda #16 ; Set black stars to white
save_color
sta screen_color
tya ; now set color in screen memory
pha
ldy #0
lda (color), y
and #%00001111
ora screen_color
sta (color), y
pla
tay
rts
init_star
lda #0
sta x_pos_h, x
jsr rnd
lda $d012 ; Use current raster line for randomness
and #%00111111 ; Get a more random value for X
clc
adc x_pos, x
sta x_pos, x
lda #0
adc x_pos_h, x
sta x_pos_h, x
jsr rnd
lda $d012 ; Use current raster line for randomness
and #%11000000 ; Get a different random value for Y
sta y_pos, x
rts
regen_y
jsr rnd
lda $d012 ; Use current raster line for randomness
and #%11000111 ; Get a more random value for Y
sta y_pos, x
rts
rnd
txa
pha
jsr $e09a ; Call the C64's built-in RNG
eor $d012 ; XOR with the current raster line for added randomness
pla
tax
rts
x_bit_set
!byte $80,$40,$20,$10,$08,$04,$02,$01
x_bit_clear
!byte $7F,$BF,$DF,$EF,$F7,$FB,$FD,$FE
y_screen ; *40 lookup for screen memory
!byte $00,$28,$50,$78,$A0,$C8,$F0,$18
!byte $40,$68,$90,$B8,$E0,$08,$30,$58
!byte $80,$A8,$D0,$F8,$20,$48,$70,$98
!byte $C0
y_screen_h
!byte $00,$00,$00,$00,$00,$00,$00,$01
!byte $01,$01,$01,$01,$01,$02,$02,$02
!byte $02,$02,$02,$02,$02,$03,$03,$03
!byte $03