-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
2183 lines (1895 loc) · 55.1 KB
/
main.c
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
#include <stdio.h>
#include <stdlib.h>
#include <6502.h>
#include "common.h"
#include "util.h"
#include "music.h"
#include "bitmap_ids.h"
#include "sound_ids.h"
//#define SAVEMEM
//#define SHOW_OPTIONS
//#define CROPPEDBMP
//#define ANIMBKGND
#define DRAWSPRITES
//#define BLANKSCREEN
//#define HITBOXES
// ================================
// EXTERNS
// ================================
extern void draw_sprintf(unsigned char posx, unsigned char posy, char* str, ...);
extern void draw_text(char* str, unsigned char posx, unsigned char posy, unsigned char invert);
extern unsigned int screen_loc, rel_loc, gtmpw, gtmpw2, gtmpw3, gtmpw4;
extern unsigned char a, b, gk, gtmp, num_repairs;
extern unsigned char snd_trigger, snd_idx, snd_delay;
extern int sky_idx;
// ================================
// GLOBALS
// ================================
unsigned char hit, hithead, hittorso, hitfeet;
unsigned char* ptr, *ptr2;
int bx, by, cx, cy;
unsigned char energies_buffered = 0;
unsigned char energies[2] = { 0 };
unsigned char last_energies[2] = { 0 };
unsigned char screen_flag = 0;
unsigned char firedown[2]= { 0 };
unsigned char walkingright[2]= { 0 };
unsigned char walkingleft[2]= { 0 };
unsigned char crouching[2]= { 0 };
unsigned char punching[2]= { 0 };
unsigned char floor_idx=12;
unsigned char escdown = 0;
enum OPT_BKGND { BKGND_STATIC, BKGND_ANIM, BKGND_ANIM_REPAIR };
unsigned char option_background = BKGND_STATIC; //BKGND_ANIM;
int building_idx=0;
int fence_idx=0;
int temple_idx=0;
enum { GAME_INTRO, GAME_TITLE, GAME_MAIN, GAME_OPTIONS };
void play_sound(unsigned char idx);
unsigned char gamestate = GAME_INTRO;
enum anim_ids
{
RYU_IDLE,
RYU_WALK, RYU_WALKB,
RYU_JUMP, RYU_FJUMP, RYU_BJUMP,
RYU_CROUCHBLOCK,
RYU_LPUNCH, RYU_MHPUNCH,
RYU_FLPUNCH, RYU_FMPUNCH, RYU_FHPUNCH,
RYU_LMKICK, RYU_HKICK,
RYU_FLKICK, RYU_FMKICK, RYU_FHKICK,
RYU_CROUCH_LPUNCH, RYU_CROUCH_MPUNCH, RYU_CROUCH_HPUNCH,
RYU_CROUCH_LKICK, RYU_CROUCH_MKICK, RYU_CROUCH_HKICK,
RYU_JUMP_LMHPUNCH,
RYU_JUMP_LMKICK, RYU_JUMP_HKICK,
RYU_FJUMP_LPUNCH,
RYU_FJUMP_MHKICK,
RYU_SHOURYUKEN, RYU_TATSUMAKI,
RYU_HADOUKEN,
RYU_HADPROJ_START, RYU_HADPROJ, RYU_HADPROJ_END,
RYU_SHOULDERTOSS, RYU_BACKROLL,
RYU_HIT, RYU_FACEHIT, RYU_CROUCHHIT,
RYU_KNOCKDOWN, RYU_STUNNED, RYU_KO,
RYU_VICTORY, RYU_VICTORYALT,
//RYU_MUGSHOT,
RYU_MAX
};
#define FIRST_ATTACK RYU_LPUNCH
unsigned char punch_style = FIRST_ATTACK;
unsigned int anim_ryu_idle[] = { RYU_IDLE2, RYU_IDLE3, RYU_IDLE4 };
unsigned int anim_ryu_walk[] = { RYU_WALK1, RYU_WALK2, RYU_WALK3, RYU_WALK4, RYU_WALK5, RYU_WALK6, RYU_WALK7, RYU_WALK8 };
unsigned int anim_ryu_walkb[] = { RYU_WALK8, RYU_WALK7, RYU_WALK6, RYU_WALK5, RYU_WALK4, RYU_WALK3, RYU_WALK2, RYU_WALK1 };
unsigned int anim_ryu_jump[] = { RYU_JUMP2, RYU_JUMP3, RYU_JUMP4 };
unsigned int anim_ryu_fjump[] = { RYU_FJUMP2, RYU_FJUMP3, RYU_FJUMP4, RYU_FJUMP5, RYU_FJUMP6, RYU_FJUMP7 };
unsigned int anim_ryu_bjump[] = { RYU_FJUMP7, RYU_FJUMP6, RYU_FJUMP5, RYU_FJUMP4, RYU_FJUMP3, RYU_FJUMP2 };
unsigned int anim_ryu_crouchblock[] = { RYU_CROUCH1, RYU_CROUCH2, RYU_BLOCK1, RYU_BLOCK2 };
unsigned int anim_ryu_lpunch[] = { RYU_LPUNCH1, RYU_LPUNCH2, RYU_LPUNCH1 };
unsigned int anim_ryu_mhpunch[] = { RYU_MHPUNCH1, RYU_MHPUNCH2, RYU_MHPUNCH3 };
unsigned int anim_ryu_flpunch[] = { RYU_FLPUNCH1, RYU_FLPUNCH2, RYU_FLPUNCH3 };
unsigned int anim_ryu_fmpunch[] = { RYU_FMPUNCH1, RYU_FMPUNCH2, RYU_FMPUNCH3, RYU_FMPUNCH4 };
unsigned int anim_ryu_fhpunch[] = { RYU_FHPUNCH1, RYU_FHPUNCH2, RYU_FHPUNCH3, RYU_FHPUNCH4 };
unsigned int anim_ryu_lmkick[] = { RYU_LMKICK1, RYU_LMKICK2 };
unsigned int anim_ryu_hkick[] = { RYU_HKICK1, RYU_HKICK2, RYU_HKICK3, RYU_HKICK4, RYU_HKICK5 };
unsigned int anim_ryu_flkick[] = { RYU_FLKICK1, RYU_FLKICK2 };
unsigned int anim_ryu_fmkick[] = { RYU_FMKICK1, RYU_FMKICK2, RYU_FMKICK3 };
unsigned int anim_ryu_fhkick[] = { RYU_FHKICK1, RYU_FHKICK2, RYU_FHKICK3 };
unsigned int anim_ryu_crouch_lpunch[] = { RYU_CROUCH_LPUNCH1, RYU_CROUCH_LPUNCH2 };
unsigned int anim_ryu_crouch_mpunch[] = { RYU_CROUCH_MPUNCH1, RYU_CROUCH_MPUNCH2 };
unsigned int anim_ryu_crouch_hpunch[] = { RYU_CROUCH_HPUNCH1, RYU_CROUCH_HPUNCH2, RYU_CROUCH_HPUNCH3 };
unsigned int anim_ryu_crouch_lkick[] = { RYU_CROUCH_LKICK1, RYU_CROUCH_LKICK2 };
unsigned int anim_ryu_crouch_mkick[] = { RYU_CROUCH_MKICK1, RYU_CROUCH_MKICK2 };
unsigned int anim_ryu_crouch_hkick[] = { RYU_CROUCH_HKICK1, RYU_CROUCH_HKICK2, RYU_CROUCH_HKICK3, RYU_CROUCH_HKICK4, RYU_CROUCH_HKICK5 };
unsigned int anim_ryu_jump_lmhpunch[] = { RYU_JUMP_LMHPUNCH1, RYU_JUMP_LMHPUNCH2, RYU_JUMP_LMHPUNCH3 };
unsigned int anim_ryu_jump_lmkick[] = { RYU_JUMP_LMKICK1, RYU_JUMP_LMKICK2 };
unsigned int anim_ryu_jump_hkick[] = { RYU_JUMP_HKICK1, RYU_JUMP_HKICK2, RYU_JUMP_HKICK3 };
unsigned int anim_ryu_fjump_lpunch[] = { RYU_FJUMP_LPUNCH1, RYU_FJUMP_LPUNCH2 };
unsigned int anim_ryu_fjump_mhkick[] = { RYU_FJUMP_MHKICK1, RYU_FJUMP_MHKICK2, RYU_FJUMP_MHKICK3 };
unsigned int anim_ryu_shouryuken[] = { RYU_SHOURYUKEN1, RYU_SHOURYUKEN2, RYU_SHOURYUKEN3, RYU_SHOURYUKEN4, RYU_SHOURYUKEN5, RYU_SHOURYUKEN6, RYU_SHOURYUKEN7 };
unsigned int anim_ryu_tatsumaki[] = { RYU_TATSUMAKI1, RYU_TATSUMAKI2, RYU_TATSUMAKI3, RYU_TATSUMAKI4, RYU_TATSUMAKI5, RYU_TATSUMAKI6, RYU_TATSUMAKI7, RYU_TATSUMAKI8, RYU_TATSUMAKI9 };
unsigned int anim_ryu_hadouken[] = { RYU_HADOUKEN1, RYU_HADOUKEN2, RYU_HADOUKEN3, RYU_HADOUKEN4, RYU_HADOUKEN5 };
unsigned int anim_ryu_hadproj_start[] = { RYU_HADPROJ1, RYU_HADPROJ2 };
unsigned int anim_ryu_hadproj[] = { RYU_HADPROJ3, RYU_HADPROJ4, RYU_HADPROJ5, RYU_HADPROJ6, RYU_HADPROJ7, RYU_HADPROJ8, RYU_HADPROJ9, RYU_HADPROJ10, RYU_HADPROJ11, RYU_HADPROJ12, RYU_HADPROJ13, RYU_HADPROJ14 };
unsigned int anim_ryu_hadproj_end[] = { RYU_HADPROJ15, RYU_HADPROJ16, RYU_HADPROJ17, RYU_HADPROJ18 };
unsigned int anim_ryu_shouldertoss[] = { RYU_SHOULDERTOSS1, RYU_SHOULDERTOSS2, RYU_SHOULDERTOSS3, RYU_SHOULDERTOSS4, RYU_SHOULDERTOSS5 };
unsigned int anim_ryu_backroll[] = { RYU_BACKROLL1, RYU_BACKROLL2, RYU_BACKROLL3, RYU_BACKROLL4, RYU_BACKROLL5, RYU_BACKROLL6, RYU_BACKROLL7 };
unsigned int anim_ryu_hit[] = { RYU_HIT1, RYU_HIT2, RYU_HIT3, RYU_HIT4 };
unsigned int anim_ryu_facehit[] = { RYU_FACEHIT1, RYU_FACEHIT2, RYU_FACEHIT3, RYU_FACEHIT4 };
unsigned int anim_ryu_crouchhit[] = { RYU_CROUCHHIT1, RYU_CROUCHHIT2, RYU_CROUCHHIT3 };
unsigned int anim_ryu_knockdown[] = { RYU_KNOCKDOWN1, RYU_KNOCKDOWN2, RYU_KNOCKDOWN3, RYU_KNOCKDOWN4, RYU_KNOCKDOWN5, RYU_KNOCKDOWN6, RYU_KNOCKDOWN7, RYU_KNOCKDOWN8 };
unsigned int anim_ryu_stunned[] = { RYU_STUNNED1, RYU_STUNNED2, RYU_STUNNED3 };
unsigned int anim_ryu_ko[] = { RYU_KO1, RYU_KO2, RYU_KO3, RYU_KO4, RYU_KO5 };
unsigned int anim_ryu_victory[] = { RYU_VICTORY1, RYU_VICTORY2, RYU_VICTORY3 };
unsigned int anim_ryu_victoryalt[] = { RYU_VICTORYALT1, RYU_VICTORYALT2, RYU_VICTORYALT3, RYU_VICTORYALT4, RYU_VICTORYALT5, RYU_VICTORYALT6, RYU_VICTORYALT7 };
//unsigned int anim_ryu_mugshot[] = { RYU_MUGSHOT1, RYU_MUGSHOT2, RYU_MUGSHOT3 };
typedef struct
{
unsigned int v1;
unsigned int v2;
unsigned int v3;
} voice_offset;
enum { SONG_INTRO, SONG_GAME };
voice_offset lstVoiceOffsets[2] =
{
{ 0xe000, 0xe000 + 0x0370, 0xe000 + 0x03f2 }, // INTRO SONG
{ 0xe000, 0xe000 + 0x0146, 0xe000 + 0x0796 } // GAME SONG
};
typedef struct
{
unsigned char anim_length;
char *relx;
char *rely;
unsigned char *frame;
} anim_movement;
char ryu_jump_relx[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
char ryu_jump_rely[] = { -3, -3, -2, -1, -1, 1, 1, 2, 3, 3 };
char ryu_jump_frame[] = { 0, 0, 1, 1, 2, 2, 1, 1, 0, 0 };
anim_movement ryu_anim_jump =
{
10,
ryu_jump_relx,
ryu_jump_rely,
ryu_jump_frame
};
char ryu_fjump_relx[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
char ryu_fjump_rely[] = { -3, -3, -2, -1, -1, 1, 1, 2, 3, 3 };
char ryu_fjump_frame[] = { 0, 1, 1, 2, 2, 3, 3, 4, 5, 6 };
anim_movement ryu_anim_fjump =
{
10,
ryu_fjump_relx,
ryu_fjump_rely,
ryu_fjump_frame
};
char ryu_bjump_relx[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
anim_movement ryu_anim_bjump =
{
10,
ryu_bjump_relx,
ryu_fjump_rely,
ryu_fjump_frame
};
char ryu_tatsu_relx[] = { 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 3, 0, 0, 0, 3, 0, 0 };
char ryu_tatsu_rely[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
char ryu_tatsu_frame[] = { 0, 1, 2, 3, 4, 5, 2, 3, 4, 5, 2, 3, 4, 5, 6, 7, 8 };
anim_movement ryu_anim_tatsu =
{
17,
ryu_tatsu_relx,
ryu_tatsu_rely,
ryu_tatsu_frame
};
char ryu_shouryuken_relx[] = { 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
char ryu_shouryuken_rely[] = { 0, 0, 0, 0, -1, -2, -1, -1, 1, 1, 2, 1, 0 };
char ryu_shouryuken_frame[] = { 0, 1, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 7 };
anim_movement ryu_anim_shouryuken =
{
13,
ryu_shouryuken_relx,
ryu_shouryuken_rely,
ryu_shouryuken_frame
};
typedef struct
{
//unsigned long reu_loc;
//unsigned int frame_size; // in bytes
unsigned int* frames;
unsigned char frame_count;
unsigned char pingpong;
unsigned int cols;
unsigned char rows;
} anim_detail;
anim_detail anims[RYU_MAX] =
{
// let the first two fields be auto-generated by the details in the other fields
// (reu_loc and frame_size)
{ anim_ryu_idle, 3, 1, 6, 13 }, // RYU_IDLE
{ anim_ryu_walk, 8, 0, 9, 13 }, // RYU_WALK
{ anim_ryu_walkb, 8, 0, 9, 13 }, // RYU_WALKB
{ anim_ryu_jump, 3, 1, 6, 13 }, // RYU_JUMP
{ anim_ryu_fjump, 7, 0, 10, 13 }, // RYU_FJUMP
{ anim_ryu_bjump, 7, 0, 10, 13 }, // RYU_BJUMP
{ anim_ryu_crouchblock, 4, 0, 6, 13 }, // RYU_CROUCHBLOCK
{ anim_ryu_lpunch, 3, 0, 8, 14 }, // RYU_LPUNCH
{ anim_ryu_mhpunch, 3, 1, 10, 14 }, // RYU_MHPUNCH
{ anim_ryu_flpunch, 3, 0, 7, 14 }, // RYU_FLPUNCH
{ anim_ryu_fmpunch, 4, 1, 8, 14 }, // RYU_FMPUNCH
{ anim_ryu_fhpunch, 4, 1, 8, 14 }, // RYU_FHPUNCH
{ anim_ryu_lmkick, 2, 1, 9, 16 }, // RYU_LMKICK
{ anim_ryu_hkick, 5, 0, 10, 16 }, // RYU_HKICK
{ anim_ryu_flkick, 2, 1, 10, 16 }, // RYU_FLKICK
{ anim_ryu_fmkick, 3, 1, 8, 16 }, // RYU_FMKICK
{ anim_ryu_fhkick, 3, 1, 11, 16 }, // RYU_FHKICK
{ anim_ryu_crouch_lpunch, 2, 1, 9, 16 }, // RYU_CROUCH_LPUNCH
{ anim_ryu_crouch_mpunch, 2, 1, 9, 16 }, // RYU_CROUCH_MPUNCH
{ anim_ryu_crouch_hpunch, 3, 1, 7, 16 }, // RYU_CROUCH_HPUNCH
{ anim_ryu_crouch_lkick, 2, 1, 10, 16 }, // RYU_CROUCH_LKICK
{ anim_ryu_crouch_mkick, 2, 1, 12, 16 }, // RYU_CROUCH_MKICK
{ anim_ryu_crouch_hkick, 5, 0, 10, 16 }, // RYU_CROUCH_HKICK
{ anim_ryu_jump_lmhpunch, 3, 0, 7, 18 }, // RYU_JUMP_LMHPUNCH
{ anim_ryu_jump_lmkick, 2, 0, 7, 18 }, // RYU_JUMP_LMKICK
{ anim_ryu_jump_hkick, 3, 0, 8, 18 }, // RYU_JUMP_HKICK
{ anim_ryu_fjump_lpunch, 2, 0, 6, 12 }, // RYU_FJUMP_LPUNCH
{ anim_ryu_fjump_mhkick, 3, 0, 9, 12 }, // RYU_FJUMP_MHKICK
{ anim_ryu_shouryuken, 7, 0, 7, 18 }, // RYU_SHOURYUKEN
{ anim_ryu_tatsumaki, 9, 0, 12, 18 }, // RYU_TATSUMAKI
{ anim_ryu_hadouken, 5, 0, 12, 12 }, // RYU_HADOUKEN
{ anim_ryu_hadproj_start, 2, 0, 6, 8 }, // RYU_HADPROJ_START
{ anim_ryu_hadproj, 12, 0, 11, 8 }, // RYU_HADPROJ
{ anim_ryu_hadproj_end, 4, 0, 6, 8 }, // RYU_HADPROJ_END
{ anim_ryu_shouldertoss, 5, 0, 9, 13 }, // RYU_SHOULDERTOSS
{ anim_ryu_backroll, 7, 0, 10, 12 }, // RYU_BACKROLL
{ anim_ryu_hit, 4, 0, 7, 15 }, // RYU_HIT
{ anim_ryu_facehit, 4, 0, 8, 15 }, // RYU_FACEHIT
{ anim_ryu_crouchhit, 3, 0, 9, 15 }, // RYU_CROUCHHIT
{ anim_ryu_knockdown, 8, 0, 10, 15 }, // RYU_KNOCKDOWN
{ anim_ryu_stunned, 3, 1, 8, 15 }, // RYU_STUNNED
{ anim_ryu_ko, 5, 0, 10, 15 }, // RYU_KO
{ anim_ryu_victory, 3, 0, 7, 16 }, // RYU_VICTORY
{ anim_ryu_victoryalt, 7, 1, 7, 16 }, // RYU_VICTORYALT
//{ anim_ryu_mugshot, 3, 0, 11, 15 }, // RYU_MUGSHOT
};
typedef struct
{
unsigned char dir; // if dir == 1 then use the mirrored version of the sprite
unsigned char posx, posy;
unsigned char anim;
unsigned char anim_idx; // the index within an animation
unsigned char anim_tmr; // how many ticks within the animation (i.e., you will sit on some frame-indexes for multiple ticks)
unsigned char anim_dir;
unsigned char visible;
anim_movement *anim_movement;
unsigned char jumping;
unsigned int boxes[4][4];
} sprite_detail;
#define SPR_MAX 4
sprite_detail* cur_spr;
sprite_detail sprites[SPR_MAX] =
{
{ 0, 4, 23, RYU_IDLE, 0, 0, 1, 1, NULL, 0 }, // player 1 (port 2)
{ 1, 30, 23, RYU_IDLE, 0, 0, 1, 1, NULL, 0 }, // player 2 (port 1)
{ 0, 10, 15, RYU_HADPROJ_START, 0, 0, 1, 0, NULL, 0 },
{ 0, 10, 15, RYU_HADPROJ_START, 0, 0, 1, 0, NULL, 0 },
/* { 7, 0, RYU_WALK, 0, 1 },
{ 14, 0, RYU_JUMP, 0, 1 },
{ 21, 0, RYU_FJUMP, 0, 1 },
{ 31, 0, RYU_CROUCHBLOCK, 0, 1 }, */
};
typedef struct
{
unsigned int reloffset; // this is the byte-offset starting from the top-right corner of the object, but will increment per row_segment
unsigned char length; // the number of length in chars for this row segment
} reu_row_segment;
typedef struct
{
unsigned char num_segments;
unsigned int start_segment_idx; // NOTE: reu_loc for segment metadata = start_segment_idx * sizeof(reu_row_segment)
// NOTE: this might have to be a relative value, and I make it absolute at run-time
unsigned char num_repairs; // how many repair chars are needed for this bitmap
unsigned long reu_ptr; // pointer to reu-memory for the data for the first row-segment (for the next segment, it'll be adjecent to this one in reu memory)
// I might have to leave this last field empty (relocatable?) and fill it in at run-time, depending on the ordering of all the objects
} reu_segged_bmp_obj;
typedef struct
{
unsigned int reloffset; // this is the byte-offset starting from the top-left corner of the object, but will increment per row_segment
unsigned char vals[16]; // 0=bmpval0, 1=maskval0, 2=bmpval1, 3=maskval1, etc...
} reu_repair_obj;
reu_segged_bmp_obj* segbmps = (reu_segged_bmp_obj*)0x1000;
reu_repair_obj *repair;
// ================================
// RAM Expansion Controller (REC) Registers
#define REC_STATUS 0xDF00
#define REC_COMMAND 0xDF01
#define REC_C64_ADDR_LO 0xDF02
#define REC_C64_ADDR_HI 0xDF03
#define REC_REU_ADDR_LO 0xDF04
#define REC_REU_ADDR_HI 0xDF05
#define REC_REU_ADDR_BANK 0xDF06
#define REC_TXFR_LEN_LO 0xDF07
#define REC_TXFR_LEN_HI 0xDF08
#define REC_INTRPT_MASK 0xDF09
#define REC_ADDR_CTRL 0xDF0A
int c64loc;
unsigned long reuloc;
unsigned char reudir=0; // 0=reu-to-c64, 1=c64-to-reu
int length;
void reu_simple_copy(void)
{
// c64base = 8192 = 0x2000
Poke(REC_C64_ADDR_LO, c64loc & 0xff);
Poke(REC_C64_ADDR_HI, c64loc >> 8);
Poke(REC_REU_ADDR_LO, reuloc & 0xff);
Poke(REC_REU_ADDR_HI, (reuloc >> 8) & 0xff);
Poke(REC_REU_ADDR_BANK, (reuloc >> 16) & 0xff);
Poke(REC_TXFR_LEN_LO, length & 0xff);
Poke(REC_TXFR_LEN_HI, length >> 8);
// c64 to REU with immediate execution
if (reudir)
{
Poke(REC_COMMAND, 0x90); // %10010001
}
else
{
// REU to c64 with immediate execution
Poke(REC_COMMAND, 0x91); // %10010001
}
}
/*
void reu_copy(int c64loc, unsigned long reuloc, int rowsize, unsigned char rows)
{
unsigned char y;
for (y = 0; y < rows; y++)
{
// c64base = 8192 = 0x2000
Poke(REC_C64_ADDR_LO, c64loc & 0xff);
Poke(REC_C64_ADDR_HI, c64loc >> 8);
Poke(REC_REU_ADDR_LO, reuloc & 0xff);
Poke(REC_REU_ADDR_HI, (reuloc >> 8) & 0xff);
Poke(REC_REU_ADDR_BANK, (reuloc >> 16) & 0xff);
Poke(REC_TXFR_LEN_LO, rowsize & 0xff);
Poke(REC_TXFR_LEN_HI, rowsize >> 8);
// REU to c64 with immediate execution
Poke(REC_COMMAND, 0x91); // %10010001
c64loc += 40*8;
reuloc += rowsize;
}
}
*/
int vicbase = 0x0000;
unsigned int draw_page = 1;
void clear_petscii(void)
{
vicbase = 0xd800;
while (vicbase < 0xd800+1000)
{
Poke(vicbase, 0);
vicbase++;
}
}
void clear_screen(void)
{
unsigned int i;
// Clear bitmap
rel_loc = vicbase+0x2000+8000;
for (screen_loc = vicbase+0x2000; screen_loc < rel_loc; screen_loc++)
{
Poke(screen_loc, 0x00);
}
// Set bitmap colours
for (i = 1024; i < 2024; i++)
{
Poke(i, (0 << 4) + 1); // black and white
}
//
// Set bitmap colours
for (i = 0x4000+1024; i < 0x4000+2024; i++)
{
Poke(i, (0 << 4) + 1); // black and white
}
}
void animate_sprite(sprite_detail* spr)
{
if (spr->anim_movement)
{
gk = spr->anim_tmr;
if (spr->dir)
spr->posx -= spr->anim_movement->relx[gk];
else
spr->posx += spr->anim_movement->relx[gk];
spr->posy += spr->anim_movement->rely[gk];
spr->anim_idx = spr->anim_movement->frame[gk];
spr->anim_tmr++;
// test for end of jump (probably not the nicest place to put this, but it'll do)
if (spr->anim_tmr == spr->anim_movement->anim_length)
{
spr->jumping=0;
spr->anim = RYU_IDLE;
spr->anim_idx = 0;
spr->anim_dir = 1;
spr->anim_movement = NULL;
}
return;
}
if (spr->anim_dir == 1)
{
if (spr->anim_idx == anims[spr->anim].frame_count-1)
{
if (anims[spr->anim].pingpong)
{
spr->anim_dir = 0;
spr->anim_idx--;
}
else
spr->anim_idx=0;
}
else
spr->anim_idx++;
}
else if (spr->anim_dir == 0)
{
if (spr->anim_idx == 0)
{
spr->anim_dir = 1;
spr->anim_idx++;
}
else
spr->anim_idx--;
}
}
unsigned keycode;
unsigned char col;
void check_real_keyboard(void)
{
keycode = 0;
__asm__ ( "jsr " FUNC_MINIKEY );
__asm__ ( "bcc rkskip" );
__asm__ ( "sta %v", keycode );
__asm__ ( "rkskip:" );
__asm__ ( "lda #$0" ); // set DDR for CIA-portA back to input so we can read joyport2 again
__asm__ ( "sta $dc02" );
}
unsigned char pi;
unsigned char key;
void get_keyboard_input(void)
{
check_real_keyboard();
#ifdef SHOW_OPTIONS
// check for escape key
if (keycode == 0x77)
{
if (!escdown)
{
escdown = 1;
gamestate = GAME_OPTIONS;
}
}
else
{
escdown = 0;
}
#endif
//draw_sprintf(0, 0, "key=0x%02X", keycode);
/*
if (keycode == 0x21) bx--; // A
if (keycode == 0x22) bx++; // D
if (keycode == 0x11) by--; // W
if (keycode == 0x07) by++; // S
if (keycode == 0x24) cx--; // J
if (keycode == 0x25) cx++; // L
if (keycode == 0x14) cy--; // I
if (keycode == 0x54) cy++; // K
*/
for (pi = 0; pi < 2; pi++)
{
// JOYSTICK: left=4, right=8, up=1, down=2, fire=16
key = (~Peek(56320U + pi)) & 31; //cgetc();
if (!(key & 16) && firedown[pi]) // test if fire was released
{
firedown[pi]=0;
// sprites[0].anim = RYU_IDLE;
// sprites[0].anim_idx = 0;
// sprites[0].anim_dir = 1;
}
// did we release down key?
if (!(key & 2) && crouching[pi])
{
crouching[pi] = 0;
sprites[pi].anim = RYU_IDLE;
sprites[pi].anim_idx = 0;
sprites[pi].anim_dir = 1;
}
if (key != 0)
{
if (punching[pi])
{
// ignore keyboard input while punching flag is on
}
else if (key & 16 && !firedown[pi]) // fire button
{
firedown[pi]=1;
punching[pi]=1;
// check direction of joystick to decide on which punch/kick to use
if (key & 1) // up
{
if (sprites[pi].dir ? (key & 4) : (key & 8)) // right
{
snd_trigger = 2;
snd_delay = 1;
snd_idx = SND_SHOURYUKEN1;
sprites[pi].anim = RYU_SHOURYUKEN;
sprites[pi].anim_movement = &ryu_anim_shouryuken;
sprites[pi].anim_tmr = 0;
}
else if (sprites[pi].dir ? (key & 8) : (key & 4)) // left
{
snd_trigger = 2;
snd_delay = 1;
snd_idx = SND_TATSUMAKI1;
sprites[pi].anim = RYU_TATSUMAKI;
//sprites[pi].anim = sprites[pi].dir ? RYU_FJUMP : RYU_BJUMP;
sprites[pi].anim_idx = 0;
sprites[pi].anim_dir = 1;
sprites[pi].anim_movement = &ryu_anim_tatsu;
sprites[pi].anim_tmr = 0;
}
else // purely up
{
sprites[pi].anim = RYU_HKICK;
}
key &= ~(1+4+8); // remove up flag
}
else if (key & 2) // down
{
if (key & 8) // right
sprites[pi].anim = sprites[pi].dir ? RYU_HADOUKEN : RYU_CROUCH_HKICK;
else if (key & 4) // left
sprites[pi].anim = sprites[pi].dir ? RYU_CROUCH_HKICK : RYU_HADOUKEN;
else // purely down
sprites[pi].anim = RYU_CROUCH_HPUNCH;
key &= ~(4+8);
}
else if (key & 8) // right only
{
sprites[pi].anim = sprites[pi].dir ? RYU_LMKICK : RYU_MHPUNCH;
key &= ~8;
}
else if (key & 4) // left only
{
sprites[pi].anim = sprites[pi].dir ? RYU_MHPUNCH : RYU_LMKICK;
key &= ~4;
}
else
{
sprites[pi].anim = punch_style;
punch_style++;
}
switch(sprites[pi].anim)
{
case RYU_HKICK:
case RYU_MHPUNCH:
case RYU_CROUCH_HPUNCH:
snd_trigger = 1;
snd_delay = 2;
snd_idx = SND_FALL;
break;
case RYU_LMKICK:
snd_trigger = 1;
snd_delay = 1;
snd_idx = SND_PUNCH2;
break;
}
sprites[pi].anim_idx = 0;
sprites[pi].anim_dir = 1;
if (punch_style == RYU_MAX)
punch_style = RYU_LPUNCH;
}
else if (key & 1 && !sprites[pi].jumping && sprites[pi].anim == RYU_IDLE) // up
{
sprites[pi].jumping = 1;
walkingright[pi] = 0; // TODO: consider how far we've walked in deciding where to jump
walkingleft[pi] = 0;
if (key & 8) // are we walking right too?
{
sprites[pi].anim = sprites[pi].dir ? RYU_BJUMP : RYU_FJUMP;
sprites[pi].anim_idx = 0;
sprites[pi].anim_dir = 1;
sprites[pi].anim_movement = sprites[pi].dir ? &ryu_anim_bjump : &ryu_anim_fjump;
sprites[pi].anim_tmr = 0;
}
else if (key & 4) // left jump?
{
sprites[pi].anim = sprites[pi].dir ? RYU_FJUMP : RYU_BJUMP;
sprites[pi].anim_idx = 0;
sprites[pi].anim_dir = 1;
sprites[pi].anim_movement = sprites[pi].dir ? &ryu_anim_fjump : &ryu_anim_bjump;
sprites[pi].anim_tmr = 0;
}
else
{
sprites[pi].anim = RYU_JUMP;
sprites[pi].anim_idx = 0;
sprites[pi].anim_dir = 1;
sprites[pi].anim_movement = &ryu_anim_jump;
sprites[pi].anim_tmr = 0;
}
//vely=-6 << 5;
}
// DOWN KEY
else if (key & 2 && !sprites[pi].jumping && !walkingleft[pi] && !walkingright[pi])
{
crouching[pi] = 1;
sprites[pi].anim = RYU_CROUCHBLOCK;
sprites[pi].anim_idx = 1;
sprites[pi].anim_dir = 2;
}
// LEFT KEY
else if (key & 4 && !walkingleft[pi] && !walkingright[pi] && !sprites[pi].jumping) // left
{
walkingleft[pi] = 1;
if (sprites[pi].dir == 0)
sprites[pi].posx -= 3;
sprites[pi].anim = sprites[pi].dir ? RYU_WALK : RYU_WALKB;
sprites[pi].anim_idx = 0;
sprites[pi].anim_dir = 1;
//dir = 1;
//girlx -= 2;
//if (!(i % 6)) // modulo operation seems to be time consuming !(i % 6))
// frame = (frame+1) % 2; // & 0x01; // % 2;
//if (girlx < 25) girlx = 25;
}
// RIGHT KEY
else if (key & 8 && !walkingleft[pi] && !walkingright[pi] && !sprites[pi].jumping) // right
{
walkingright[pi] = 1;
if (sprites[pi].dir == 1)
sprites[pi].posx += 3;
sprites[pi].anim = sprites[pi].dir ? RYU_WALKB : RYU_WALK;
sprites[pi].anim_idx = 0;
sprites[pi].anim_dir = 1;
//dir = 0;
//girlx += 2;
//if (!(i & 0x03)) // don't use modulo operation !(i % 6))
// frame = (frame+1) % 2; //& 0x01; // % 2;
//if (girlx > 323) girlx = 323;
}
// floor animate
if (key & 4) // floor-left animate
{
building_idx--;
fence_idx--;
temple_idx--;
if (floor_idx < 24)
floor_idx++;
}
if (key & 8) // floor-right animate
{
building_idx++;
fence_idx++;
temple_idx++;
if (floor_idx > 0)
floor_idx--;
}
} // end if
// - - - - no key is pressed? still some checks to do.. - - - -
else
{
// have we stopped walking left
if (key != 4 && walkingleft[pi])
{
if (sprites[pi].dir == 0)
sprites[pi].posx += 3 - sprites[pi].anim_idx / 3;
else
sprites[pi].posx -= sprites[pi].anim_idx / 3;
sprites[pi].anim = RYU_IDLE;
sprites[pi].anim_idx = 0;
walkingleft[pi] = 0;
}
else if (key != 8 && walkingright[pi])
{
if (sprites[pi].dir == 1)
sprites[pi].posx -= (3 - sprites[pi].anim_idx / 3);
else
sprites[pi].posx += (sprites[pi].anim_idx / 3);
sprites[pi].anim = RYU_IDLE;
sprites[pi].anim_idx = 0;
walkingright[pi] = 0;
}
}
} // end for
//Poke(8192L, walkingright);
//Poke(8193L, walkingleft);
//Poke(8194L, jumping);
}
// returns 1 = skip next animation step
// returns 0 = perform next animation step
unsigned char post_draw_processing(unsigned char sprite)
{
if (sprite < 2) // player 1 or 2?
{
// extra movement-related processing
if (walkingright[sprite] && sprites[sprite].anim_idx==7)
{
walkingright[sprite]=0;
if (sprites[sprite].dir == 0)
sprites[sprite].posx += 3;
sprites[sprite].anim = RYU_IDLE;
sprites[sprite].anim_idx = 0;
sprites[sprite].anim_dir = 1;
}
if (walkingleft[sprite] && sprites[sprite].anim_idx==7)
{
walkingleft[sprite]=0;
if (sprites[sprite].dir == 1)
sprites[sprite].posx -= 3;
sprites[sprite].anim = RYU_IDLE;
sprites[sprite].anim_idx = 0;
sprites[sprite].anim_dir = 1;
}
// start hadouken projectile?
if (sprites[sprite].anim == RYU_HADOUKEN)
{
if (sprites[sprite].anim_idx == 2)
{
snd_trigger = 2;
snd_idx = SND_HADOUKEN1;
}
else if (sprites[sprite].anim_idx == 4)
{
sprites[sprite+2].anim=RYU_HADPROJ_START;
sprites[sprite+2].anim_idx=0;
sprites[sprite+2].visible=1;
sprites[sprite+2].dir = sprites[sprite].dir;
if (sprites[sprite].dir)
{
sprites[sprite+2].posx = sprites[sprite].posx - 8;
sprites[sprite+2].posy = sprites[sprite].posy - 3;
}
else
{
sprites[sprite+2].posx = sprites[sprite].posx + 9;
sprites[sprite+2].posy = sprites[sprite].posy - 3;
}
}
}
if (punching[sprite] && !sprites[sprite].anim_movement)
{
if (anims[sprites[sprite].anim].pingpong)
{
if (sprites[sprite].anim_idx == 0 && sprites[sprite].anim_dir==0)
{
punching[sprite] = 0;
sprites[sprite].anim = RYU_IDLE;
sprites[sprite].anim_idx = 0;
sprites[sprite].anim_dir = 1;
return 1;
}
}
else if (sprites[sprite].anim_idx == anims[sprites[sprite].anim].frame_count-1)
{
punching[sprite] = 0;
sprites[sprite].anim = RYU_IDLE;
sprites[sprite].anim_idx = 0;
sprites[sprite].anim_dir = 1;
return 1;
}
}
} // end sprite0 processing
// hadouken projectile sprite?
if (sprite == 2 || sprite == 3)
{
//draw_sprintf(0, 0, "posx=%d", sprites[sprite].posx);
//draw_sprintf(0, 1, "posy=%d", sprites[sprite].posy);
if (sprites[sprite].anim == RYU_HADPROJ_START && sprites[sprite].anim_idx == 1)
{
sprites[sprite].anim = RYU_HADPROJ;
sprites[sprite].anim_idx = 0;
}
else if (sprites[sprite].anim == RYU_HADPROJ && sprites[sprite].anim_idx == 11)
{
if (sprites[sprite].posx <= 3 || sprites[sprite].posx > 28)
{
sprites[sprite].anim=RYU_HADPROJ_END;
sprites[sprite].anim_idx=0;
if (sprites[sprite].dir)
sprites[sprite].posx -= 6;
else
sprites[sprite].posx += 6;
}
else
{
if (sprites[sprite].dir)
sprites[sprite].posx -= 6;
else
sprites[sprite].posx += 6;
}
}
else if (sprites[sprite].anim == RYU_HADPROJ_END && sprites[sprite].anim_idx == 3)
{
sprites[sprite].visible=0;
}
}
return 0;
}
void drawbox(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, unsigned char white)
{
unsigned int len = x2 - x1;
unsigned char offs = x1 & 0x07;
unsigned char offs2, offsy;
rel_loc = vicbase+0x2000;
gtmpw = rel_loc;
gtmpw3 = rel_loc;
// take offset to the start of which character block the first pixel resides in
rel_loc += (y1 >> 3) * 320 + (x1 & 0xfff8);
// now take offset to the start of the row within the char-block
rel_loc += (y1 & 0x07);
a = 0xff >> offs;
b = a ^ 0xff;
if (white)
Poke(rel_loc, Peek(rel_loc) & b);
else
Poke(rel_loc, Peek(rel_loc) | a);
// back up this location for later
gtmpw2 = rel_loc;
// do the same for the lower line
gtmpw += (y2 >> 3) * 320 + (x1 & 0xfff8);
gtmpw += (y2 & 0x07);
if (white)
Poke(gtmpw, Peek(gtmpw) & b);
else
Poke(gtmpw, Peek(gtmpw) | a);
// draw the rest of the horizontal line, in 8-bit chunks
offs2 = x2 & 0x07;
len -= offs2;
rel_loc += 8;
gtmpw += 8;
while (len > 8)
{
if (white)
{
Poke(rel_loc, 0x00);
Poke(gtmpw, 0x00);
}
else
{
Poke(rel_loc, 0xff);
Poke(gtmpw, 0xff);
}
len -=8;
rel_loc += 8;
gtmpw += 8;
}
// draw any trailing end
a = 0xff << (7 - offs2);
b = a ^ 0xff;
if (white)
{
Poke(rel_loc, Peek(rel_loc) & b);
Poke(gtmpw, Peek(gtmpw) & b);
}
else
{
Poke(rel_loc, Peek(rel_loc) | a);
Poke(gtmpw, Peek(gtmpw) | a);
}
// draw the vertical lines...
offsy = y1 & 0x07;
gtmpw3 += (y1 >> 3) * 320 + (x2 & 0xfff8);
gtmpw3 += (y1 & 0x07);
len = y2-y1;
a = 1 << (7-offs);
b = a ^ 0xff;
gk = 1 << (7-offs2);
gtmp = gk ^ 0xff;
while (len > 1)
{
len--;
offsy++;
if (offsy == 8)
{
gtmpw2 += 320;
gtmpw2 &= 0xfff8;
gtmpw3 += 320;
gtmpw3 &= 0xfff8;
offsy=0;
}
else
{
gtmpw2++;
gtmpw3++;
}
if (white)
{
Poke(gtmpw2, Peek(gtmpw2) & b);
Poke(gtmpw3, Peek(gtmpw3) & gtmp);
}
else
{
Poke(gtmpw2, Peek(gtmpw2) | a);
Poke(gtmpw3, Peek(gtmpw3) | gk );