-
Notifications
You must be signed in to change notification settings - Fork 0
/
game - Copia.asm
2388 lines (1859 loc) · 31.6 KB
/
game - Copia.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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
/*
Super Star Path
https://shmups.system11.org/index.php
xeno crisis
int free=0;
char buffer[16];
void init () {
for (int i=0;i<14;i++)
buffer[i]=i+1;
buffer[15]=-1;
free=0;
}
int alloc () {
int id=free;
free=bufffer[free];
return id;
}
int release(int k) {
buffer[k]=free;
free=k;
}
*/
BasicUpstart2(main)
.var IRQ1LINE = $0 //IRQ at the top of screen
.var showRasterTime=false
.var showSubTime=false
.var r1=$0314
.var r2=$0315
.var TYPE_BULLET=$1
.var TYPE_ENEMY=$2
.var TYPE_PLAYER=$3
.var TYPE_COIN=$4
.var MODEL_PLAYER=$0
.var MODEL_ENEMY=$1
.var MODEL_BULLET=$02
.var MODEL_COIN=$03
.var ANIM_SPAWN=$00
.var ANIM_DIE=$01
.var ANIM_WALK=$02
.var ANIM_ATTACK=$03
.var ANIM_PAIN=$04
//.var r1=$fffe
//.var r2=$ffff
.var flagpause=false
.var max_sprites=24;
//.var music = LoadSid("../music/Funky_Freak.sid")
//.var cachechar=$e0
//.var cachechar1=$e8
.var first_sprite_char=64
.var bank =$8000
.var charset_vic =$3800
.var first_star=64
* = * "Code"
//*=music.location "Music"
// .fill music.size, music.getData(i)
clearscreen:{
ldy #$0
lda #32
rep:
sta bank+$400,y
//sta backdrop,y
sta bank+$400+$100,y
//sta backdrop+$100,y
sta bank+$400+$200,y
//sta backdrop+$200,y
sta bank+$400+$300,y
//sta backdrop+$300,y
iny
bne rep
rts
}
lines:
.byte 0
gameover:
.byte 0
v1:
.word 0
sprupdateflag:
.byte 0
.var freq=50;
.var timeline=100;
game_spanw_pt:
.for(var i=0;i<250;i++) {
spawnAt(timeline,MODEL_ENEMY,(50+11*8)+random()*(11*8),21)
.if (i==20) .eval freq=40
.if (i==50) .eval freq=30
.if (i==100) .eval freq=25
.if (i==150) .eval freq=22
.eval timeline+=freq;
}
levelEnd()
game_sprite_state_table_lo:
.byte <game_sprite_anim_spawn,<game_sprite_anim_die,<game_sprite_anim_walk,<game_sprite_anim_attack,<game_sprite_anim_pain
game_sprite_state_table_hi:
.byte >game_sprite_anim_spawn,>game_sprite_anim_die,>game_sprite_anim_walk,>game_sprite_anim_attack,>game_sprite_anim_pain
game_sprite_anim_spawn:
modelDef(TYPE_PLAYER,1,1,spawn_player,25,default_callback)
modelDef(TYPE_ENEMY,4,8,spawn_enemy,1,default_callback)
modelDef(TYPE_BULLET,2,2,spawn_bullet,1,default_callback)
modelDef(TYPE_COIN,3,3,spawn_coin,1,default_callback)
game_sprite_anim_die:
modelDef(TYPE_PLAYER,1,1,spawn_player,1,default_callback)
modelDef(TYPE_ENEMY,4,8,spawn_enemy,1,default_callback)
modelDef(TYPE_BULLET,2,2,spawn_bullet,1,default_callback)
modelDef(TYPE_COIN,3,3,spawn_coin,1,default_callback)
game_sprite_anim_walk:
modelDef(TYPE_PLAYER,1,1,walk_player,1,default_callback)
modelDef(TYPE_ENEMY,0,0,spawn_enemy,1,default_callback)
modelDef(TYPE_BULLET,2,2,spawn_bullet,1,default_callback)
modelDef(TYPE_COIN,3,3,spawn_coin,1,default_callback)
game_sprite_anim_attack:
modelDef(TYPE_PLAYER,1,1,spawn_player,1,default_callback)
modelDef(TYPE_ENEMY,0,0,spawn_enemy,1,default_callback)
modelDef(TYPE_BULLET,2,2,spawn_bullet,1,default_callback)
modelDef(TYPE_COIN,3,3,spawn_coin,1,default_callback)
game_sprite_anim_pain:
modelDef(TYPE_PLAYER,1,1,spawn_player,1,default_callback)
modelDef(TYPE_ENEMY,0,0,spawn_enemy,1,default_callback)
modelDef(TYPE_BULLET,2,2,spawn_bullet,1,default_callback)
modelDef(TYPE_COIN,3,3,spawn_coin,1,default_callback)
game_idx_lo:
.byte <game_spanw_pt
game_idx_hi:
.byte >game_spanw_pt
game_time_hi:
.byte 0
game_time_lo:
.byte 0
.macro levelEnd() {
.word $ffff
}
.macro spawnAt(tm,spwid,posx,posy) {
.byte <(tm)
.byte >(tm)
.byte spwid
.byte posx
.byte posy
}
.macro modelDef(model_type,first_frame,last_frame,callback,fps,frame_callback) {
.byte model_type
.byte first_frame
.byte last_frame
.byte fps
.byte <callback
.byte >callback
.byte <frame_callback
.byte >frame_callback
}
game_put_enemy:{
cont:
lda game_idx_lo
sta $04
lda game_idx_hi
sta $05
ldy #1
lda ($04),y
cmp #$ff
bne !+
ldy #0
cmp ($04),y
bne !+
lda #0
sta game_time_hi
sta game_time_lo
lda #<game_spanw_pt
sta game_idx_lo
lda #>game_spanw_pt
sta game_idx_hi
!:
ldy #1
lda game_time_hi
cmp ($04),y
bcc leave
beq compare_lo_byte
bcs go_with_the_spawn
compare_lo_byte:
ldy #0
lda game_time_lo
cmp ($04),y
bcc leave
go_with_the_spawn:
sed
clc
lda nspawn+1
adc #1
sta nspawn+1
lda nspawn
adc #$0
sta nspawn
cld
ldy #2
lda ($04),y
jsr model_alloc
cmp #$ff
beq leave
tax
ldy #3
lda ($04),y
sta sprite_pos_x_lo,x
iny
lda ($04),y
sta sprite_pos_y_lo,x
lda #40
sta sprite_timeout,x
lda game_idx_lo
clc
adc #5
sta game_idx_lo
lda game_idx_hi
adc #0
sta game_idx_hi
jmp cont
leave:
inc game_time_lo
bne l1
inc game_time_hi
l1:
rts
}
vblank: {
lda $d011
bmi vblank
L2:
lda $d011
bpl L2
rts
}
getjoy: {
lda #$FF
sta $DC00
lda $DC00
eor #$FF
sta joy
rts
}
initraster: {
sei
/*lda #<brkirq
ldy #>brkirq
sta $fffa
sty $fffb
*/
lda #<irq1
sta r1
lda #>irq1
sta r2
lda #$7f
sta $dc0d
sta $dd0d
lda #$01 //Raster interrupt on
sta $d01a
sta $d01a
lda #27 //High bit of interrupt position = 0
sta $d011
lda #IRQ1LINE //Line where next IRQ happens
sta $d012
lda $dc0d //Acknowledge IRQ (to be sure)
lda $dc0d //;ack any pending timer irq
lda $dd0d //;at cia #2 too
/*lda #$35
sta $01 //;turn off kern_A_l
*/
cli
rts
}
.macro retirq() {
asl $d019
loadregs()
//rti
jmp $ea81
}
savea:
.byte 0
savex:
.byte 0
savey:
.byte 0
.macro saveregs() {
/*php
pha
txa
pha
tya
pha */
}
.macro loadregs () {
/*pla
tay
pla
tax
pla
plp*/
}
brkirq:
rti
irq1: {
saveregs()
lda sprupdateflag //New sprites?
beq irq1_nonewsprites
inc pressed_time
jmp hw_draw_sprite
irq1_nonewsprites:
irq1_d015value:
retirq()
}
.macro drawsprite(hwid,swid) {
lda sprite_w_list+swid
tax
lda sprite_w_pos_y_lo,x
sta $d000+2*hwid+1
lda sprite_w_pos_x_lo,x
sta $d000+2*hwid
//lda #swid
lda sprite_w_image_id,x
sta $87F8+hwid
sta $b3F8+hwid
lda #10
sta $d027+hwid
}
/*.macro putsprite(_x,_y) {
jsr sprite_alloc
tay
lda #_x
sta sprite_pos_x_lo,y
lda #_y
sta sprite_pos_y_lo,y
}*/
main: {
ldx #0
lda #0
sta 53280
lda #0
sta 53281
lda $dd02
ora #3
sta $dd02 // ; Make sure CIA#2 lines set to OUTPUT
lda $dd00
and #%11111100
ora #1 // ; Bank #1, $4000-$7FFF, 16384-32767.
sta $dd00
lda $d018
and #%11110001
ora #%00001110
sta $d018
//lda #$18
//sta $d018
/*lda #$13
sta $d011
*/
ldy #0
copysprite:
lda sprites,y
sta bank,y
lda sprites+$100,y
sta bank+$100,y
lda sprites+$200,y
sta bank+$200,y
lda sprites+$300,y
sta bank+$300,y
iny
bne copysprite
jsr load_charset
jsr clearscreen
//jsr drawlevel
//jsr copyscreen
lda #MODEL_PLAYER
jsr model_alloc
sta playerid
tay
lda #20*8
sta sprite_pos_x_lo,y
lda #28*8
sta sprite_pos_y_lo,y
//lda #music.startSong-1
//lda #0
//jsr music.init
/*
test show sprite
*/
lda #0
sta $D027
lda #0
sta $d021
lda #<level_1
sta $02
lda #>level_1
sta $03
jsr initraster
jsr preparestarfield
jsr draw_room
mainloop:
lda sprupdateflag
bne mainloop
lda gameover
beq !+
jsr mygameover
!:
lda game_idx_lo
sta $04
lda game_idx_hi
sta $05
ldy #1
lda ($04),y
sta v1
ldy #0
lda ($04),y
sta v1+1
printhex(bank+$0411+40*4,score);
jsr model_update
jsr sprite_update
jsr sprite_sort
jsr calc_raster
jsr updatestarfield
inc sprupdateflag
jsr getjoy
jsr update_player
jsr sprite_collision
jsr game_put_enemy
jsr vblank
jsr drawstarfield
l1:
jmp mainloop
rts
}
.macro check_hw_sp(id) {
lda sprite_w_count
cmp #id
bcs *+5
}
.macro check_hw_rf(id,data,addr) {
lda #<addr
sta r1
lda #>addr
sta r2
ldy id+1
lda #id-1
cmp data
beq *+7
bcc *+5
}
lastYcoord_1:
.byte 0
lastYcoord_2:
.byte 0
rast_flag_1:
.byte 0
f_raster_1:
.byte 0
rast_flag_2:
.byte 0
f_raster_2:
.byte 0
gmt:
.byte 0
mygameover: {
lda #$20
sta gmt
!:
lda #1
sta 53280
sta 53281
jsr vblank
lda #0
sta 53280
sta 53281
jsr vblank
dec gmt
bne !-
lda #< gameover_r
sta $02
lda #> gameover_r
sta $03
jsr draw_room
lda #0
sta $d015
printhex(bank+$0411+40*14,score);
!:
jsr updatestarfield
inc game_time_lo
jsr vblank
jsr drawstarfield
jsr getjoy
lda joy
and #$10
beq !-
!:
jsr updatestarfield
inc game_time_lo
jsr vblank
jsr drawstarfield
jsr getjoy
lda joy
and #$10
bne !-
lda #0
sta game_time_hi
sta game_time_lo
sta sprite_count
sta bucketIdx
sta score
sta score+1
lda #<game_spanw_pt
sta game_idx_lo
lda #>game_spanw_pt
sta game_idx_hi
lda #0
sta gameover
sta sprite_first_free
jsr clearscreen
jsr preparestarfield
lda #< level_1
sta $02
lda #> level_1
sta $03
jsr draw_room
ldy #0
ldx #1
!:
txa
sta sprite_free_list,y
lda #0
sta sprite_state,y
inx
iny
cpy #max_sprites
bne !-
lda #MODEL_PLAYER
jsr model_alloc
sta playerid
tay
lda #20*8
sta sprite_pos_x_lo,y
lda #28*8
sta sprite_pos_y_lo,y
rts
}
calc_raster: {
lda #$60
sta f_raster_2
sta f_raster_1
lda sprite_count
cmp #9
bcc leave
lda sprite_list+7
tax
lda sprite_pos_y_lo,x
clc
adc #21
sta lastYcoord_1
calc_raster_band_1:
ldy #8
next:
lda sprite_list,y
tax
lda sprite_pos_y_lo,x
cmp lastYcoord_1
//beq nnk
bcs ok
nnk:
iny
cpy #16
beq ok
cpy sprite_count
bcc next
ok:
sty f_raster_1
lda sprite_count
cmp #17
bcc leave
lda sprite_list+15
tax
lda sprite_pos_y_lo,x
clc
adc #21
sta lastYcoord_2
calc_raster_band_2:
ldy #16
next1:
lda sprite_list,y
tax
lda sprite_pos_y_lo,x
cmp lastYcoord_2
beq nnk1
bcs ok1
nnk1:
iny
cpy #24
bcs ok1
cpy sprite_count
bcc next1
ok1:
sty f_raster_2
leave:
rts
}
hw_draw_sprite:{
.if (showRasterTime){
// lda #7
// sta $d020
}
lda #$ff //Any sprites?
sta $d015
lda f_raster_1
sta rast_flag_1
lda f_raster_2
sta rast_flag_2
lda sprite_count
sta sprite_w_count
.for (var i=0;i<max_sprites;i++){
lda sprite_list +i
sta sprite_w_list +i
lda sprite_pos_x_lo+i
sta sprite_w_pos_x_lo+i
lda sprite_pos_y_lo+i
sta sprite_w_pos_y_lo+i
lda sprite_image_id+i
sta sprite_w_image_id+i
}
lda #0
sta $d001
sta $d003
sta $d005
sta $d007
sta $d009
sta $d00b
sta $d00d
sta $d00f
lda #$ff
sta $d01c
lda #7
sta $D025
sta $D026
lda #$00
sta sprupdateflag
.if (showRasterTime){
//lda #0
//sta $d020
}
check_hw_sp(1)
jmp leave
drawsprite(0,0)
check_hw_sp(2)
jmp leave
drawsprite(1,1)
check_hw_sp(3)
jmp leave
drawsprite(2,2)
check_hw_sp(4)
jmp leave
drawsprite(3,3)
check_hw_sp(5)
jmp leave
drawsprite(4,4)
check_hw_sp(6)
jmp leave
drawsprite(5,5)
check_hw_sp(7)
jmp leave
drawsprite(6,6)
check_hw_sp(8)
jmp leave
drawsprite(7,7)
check_hw_sp(9)
jmp leave
lda rast_flag_1
cmp #8
beq normal
//printhex(bank+$0400,rast_flag_1)
lda #27 //High bit of interrupt position = 0
sta $d011
lda sprite_w_list+8
tax
lda sprite_w_pos_y_lo,x
sec
sbc #4
cmp $d012
beq *+4
bcs setok1
jmp imposta_sprite_8_16_no
setok1:
sta $d012
jmp setupirq
normal:
.if (showRasterTime){
//lda #9
//sta $d020
}
lda #27 //High bit of interrupt position = 0
sta $d011
ldy rast_flag_1
lda #$60
sta rast_flag_1
lda sprite_w_list+7
tax
lda sprite_w_pos_y_lo,x
clc
adc #21
//cmp $d012
//bcc imposta_sprite_8_16_no
sta $d012
jmp setupirq
normal2round:
.if (showRasterTime){
//lda #9
//sta $d020
}
lda #27 //High bit of interrupt position = 0
sta $d011
ldy rast_flag_1
lda #$60
sta rast_flag_1
lda sprite_w_list,y
tax
lda sprite_w_pos_y_lo,x
/*sec
sbc #8
cmp $d012
beq *+4
bcs setok
*/
lda sprite_w_pos_y_lo,x
clc
adc #4
setok:
sta $d012
retirq()
setupirq:
lda #<imposta_sprite_8_16
sta r1
lda #>imposta_sprite_8_16
sta r2
.if (showRasterTime){
//lda #0
//sta $d020
}
retirq()
imposta_sprite_8_16:
saveregs()
imposta_sprite_8_16_no:
.if (showRasterTime){
//lda #1
//sta $d020
//sta $d021
}