/
main.c
3730 lines (3213 loc) · 90.5 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
/** (C) Matt Hughson 2020 */
#include "LIB/neslib.h"
#include "LIB/nesdoug.h"
#include "BG/game_area.h"
#if VS_SYS_ENABLED
#include "BG/vs_boot_screen.h"
#include "BG/vs_settings_difficulty.h"
#include "BG/vs_settings_mode.h"
#include "BG/vs_title_screen.h"
#include "BG/high_score_screen.h"
#else
#include "BG/title_screen.h"
#include "BG/boot_screen.h"
#include "BG/options_screen.h"
#endif
#include "BG/sound_screen.h"
#include "BG/ty_screen.h"
#include "../include/stdlib.h"
//#include "../include/string.h"
#include "main.h"
/*
..::TODO::..
FEATURES:
//must have
--
//should have
--
//nice to have
* Ghost pieces.
* Lock-delay settings (off, 10 frames, 20 frames)
* Options on the Pause screen (quit, music, sfx).
* Store blocks. (classic only?)
* Update mode order and names to be (will require more space):
* Kraken, Classic, Kraken Alt* Description of modes in option screen.
* Game over screen (polished).
* Points kicker
//investigate
* Number of rows that hit the tentacle adds a delay to next attack.
* Screen shake on hit. (others say this is annoying)
* Hard drop trails. (likely too much cpu)
* Drought reduction: have a max number of turns a piece can drought. If hit that max, for it to be played.
//sound
* Kraken hit.
* Kraken hitx4
* landing should be louder
COMPLETE:
* Trigger sound test on Konami Code.
* Special Thanks screen
* Allow players to start on any level up to 29.
* Start level 29.
* Select + Start on level 9.
* Disable hard drop (not on hold - People either want it or not).
* Added 3 settings: off, tap, hold.
* Test NES rotations (confirmed)
* Delay at start of match (maybe only high levels?)
* Kill screen ideas:
- Remove lock delay.
- Shrink the play area. << THIS
- 2 block drops.
* Hard drop on HOLD.
* Reset on A+B+SEL+START
* Option to disable hard-drop (or require a slight hold to trigger hard drop.)
* No hold setting, just on or off.
* Add ARE (spawn delay) Maybe 5 frames, and switch lock delay to 15.
* Clean up sound test.
* Hi-score display (per mode).
* Couldn't find a good spot during gameplay, so currently only in the options.
* Option to turn off SFX.
* Update to use NES block layouts.
* Update to have all blocks start face down. (was just T block actually).
* Score for Classic mode.
* 1 lines: 2 lines: 3 lines: 4 lines:
* 40 * (n + 1) 100 * (n + 1) 300 * (n + 1) 1200 * (n + 1)
* + 1 point for ever row soft/hard dropped over. [cut]
* Clean up options:
* Remove credits. [done]
* Remove "block type". [done]
* Re-add tower. [cut]
* Starting level. [done]
* Credits on boot.
* More clear path out of options.
* Change flow to go through options on the way to gameplay state.
* Safe zone issues.
* Faster start.
* Fast music when tentacle is maxed out.
* Better lock delay (consistent).
* Wall kicks
* Multiple tentacles. - possibly if when reaching top they go into name table.
* Pal swap based on time of day/night.
* Option to return to main menu on game over.
* Non-Nintendo blocks. (not fun :()
* Hard drop (up on d-pad).
* Option screen.
* Credits screen.
* Time based tentacle movement (rather than on landing).
* Option to choose between Kraken and Klassic gameplay. (classic may require score, ability to go back to main menu).
* Push start flashing text.
CUT:
* See if tentacles can be made to work with name tables.
* Want to keep animation.
* When on Level 29, display MAX instead.
* Doge suggested showing levels beyond 29.
* Added "Kill Screen"
* Last chance move on hard drop (maybe optional).
* Feels weird. See commented out code in movement().
* Sound on hit tentacle.
* Really need mutliple sounds for 4 line hit too.
* Sound on drop and then lock.
* Don't like that it won't be consistent between lockdelay and just slow falling.
BUGS:
* Flicker on hard drop.
* Can get game over when spawned piece clears a line. Wouldn't be so bad if the line didn't get cleared.
* Kraken eye is all glitches when hitting tentacle on hardware.
* Krysio kart only. Need resistor on pins?
* "When I was in the middle of playing a game the sound test came up, i was on a pink stage but couldn't catch the level." - KittyFae
COMPLETE:
* Flickering sprites when pressing select during Kraken modes.
* Blocks are not falling fast enough on soft drop
* Was falling every 3 frames instead of 2 frames.
* Bad wall kick: http://harddrop.com/fumen/?m115@fhB8NemL2SAy3WeD0488AwkUNEjhd5DzoBAAvhA+qu?AA
* Discovered a couple problems on top of special case for lines is now only lines.
* SKULL doesn't clear on game over.
* Game Over eat into side of nametable (1 tile too far).
* "the way nestris does it is it declares you dead when two pieces overlap which happens when there's a piece where the next piece spawns"
* Garbage in nametable after playing "timed", quiting to main menu, and entering options and changing a few settings.
* likely writing too many values in display_options, not sure why not 100% though.
* suspect you can hit this change an option with a high score at the same time PUSH START is toggled on/off
* Quick fall rate sometimes: https://clips.twitch.tv/FuriousIntelligentClipzMau5
* After quiting to main menu, previous match "next" block continues to show.
* S and Z are too high when flat (or too low when vert)
* If starting on level 10+, level up is happening on wrong level (happens as
soon as player hits 110 lines, regardles of starting level).
* Next block is hidden during line clear.
* When hitting game over, final sprite switches.
* I think this is because the vram buffer is cleared at the start of game over,
before it has a chance to copy over the new block to the nametable.
* CNR - Horz input has to be pressed again if line is cleared.
* Hitch when tentacle retracts on hitting max (because of delays).
* At level 29, the blocks never trigger game over.
* Music isn't playing on main menu.
* Moving tentacle keeps moving after reaching max (possibly fixed with multi-tentacle attack).
* Tentacles are not budgeted.
* Graphical corruption on Game Over (rarely)
* Hard drop puts blocks 1 tile too far (rarely).
* Sprite flicker when blocks land.
CUT:
* Sprites do not draw when transitioning between name tables.
* Don't care enough to redo how transitions work.
SCRIPT IDEAS:
* LAND - Make every move count! Rewards deliberate play. Punishes sloppy.
* TIME - Race to get as much done as possible before the Kraken attacks. Rewards fast play. Punishes overthinking.
* CLASSIC - The traditional block dropping puzzle mechanics you know and love.
* Story -
The Kraken cometh...
From the deepest trenches of the ocean, the Kraken has come to lay waste to your city!
The archers have slung every arrow.
The burning tar has run dry.
Every piece of military weaponary has been dispatch.
And yet... the Kraken moves forward, climbing the towering walls of your seaside fortress.
With no ammunition left, the city itself moves from a barricade, to weapon!
The stones of the walls are broken off, and hurdled down at hidious creature. And it just might be enough to
slow it down till morning, when surely help will arrive...
* Manual:
- Have a page with text book lore about the Kraken, with some cool pictures.
- A page for each mode.
- A making of section about how the game was created.
DIP SWITCHES:
* = not yet implemented.
All defaults will be 0.
FREE PLAY | 0 0 - - - - - -
CREDIT/COIN 1/1 | 0 1 - - - - - -
CREDIT/COIN 1/2 | 1 0 - - - - - -
CREDIT/COIN 1/4 | 1 1 - - - - - -
PPU RP2C04-0001 | - - 0 0 0 - - -
PPU RP2C04-0002 | - - 1 0 0 - - -
PPU RP2C04-0003 | - - 0 1 0 - - -
PPU RP2C04-0004 | - - 1 1 0 - - -
PPU 2C03/2C05 | - - 0 0 1 - - -
PPU 2C02 (NES) | - - 1 0 1 - - -
DISABLE MUSIC | - - - - - 1 - -
DISABLE SFX | - - - - - - 1 -
DISABLE ATTACT SOUND | - - - - - - - 1
Arcade Buttons:
1: p1 select (virtual - Doesn't seem to match physical controller in Messen)
2: p2 select
3: p1 start
4: p2 start
VERSUS TODO:
* Final Artwork from Duey.
* Package up artwork and dip sheet in zip (maybe zip everything including NES?)
* [cut] Font outline.
* [cut] Consider hard drop (setting, dip, hold by default, etc). [tested - no issues]
* [cut] On gameover, continue should go to Mode select, not title screen.
* [cut] Shared leaderboard on dual system (with save).
* [cut] Hide coin display in Free Play mode.
* [done] Better initial entry UI.
* [done] Add lidnariq to thanks if possible.
* [done] Shorten attract timer to 20-30 seconds.
* [done] Arrow sprites on leaderboards.
* [done] Re-enable music (when attact sound is disable) after inserting a coin. Leave disabled for Free Play.
* [done] Better gameover display. (remove press 1)
* [done] Attract gameplay.
* [done] Auto-forward if no input on the leaderboards for too long.
* [done] Countdown timer on entering initials. (not visible to player)
* [done] PPU support (incl. NES!)
* [done] Prefer credit style of 1/2
* [done] Press Start should say Press Any Button
* [done] Updated block art.
* [done] Skull transition feels odd to still have a full timer - jump to 5 seconds or something.
* [done] Leaderboards
* [done] Title Screen with "Vs."
* [done] Game Mode Screen art.
* [done] Remaining Dip Switches.
* [done] Game over timer (force quit).
* [done] Credit display.
* [done] Matenience coin counter.
* [done] Maintenience coin feeder.
* [done] start game with A or B as well.
* [done] game over quits with any key, changed messaging.
* [done] credit display.
* [done] Catch credits in NMI, and poll value in main.
* [done] Better coin display.
* [done] coin feedback across all states (but disbled during gameplay)
* [done] Auto-advance all menus to avoid burn in.
* [done] More buttons (not just 1) for entering initials. A to enter, B go back. Maybe 1 to skip.
* [done] Button 1 and Button 2 go to leaderbaords. Should just be 2.
SRAM:
* STATUS:
* Disabled behind VS_SRAM_ENABLED.
* Also need to manually turn XRAM back on in config.
* Currently only functions fully on CPU1.
* CPU2 is partially working, but that might just be by luck, since it should be mostly disabled.
* Next step is to move the leaderboards out of SRAM, and instead use SRAM as messaging system, and hook into IRQ.
* Used as a messaging system, not storage for leaderboards.
* This ensures that it works on system without access to SRAM, and on CPU2 without requesting SRAM access.
* Message: [unique id for validation] ... [msg type - leaderbaord update] [mode] [difficulty] [placement] [initals x 3] [score x 4] ... [end id]
* 1 byte ... 1 byte 1 byte 1 byte 1 byte 2 bytes 4 bytes 1 byte
CPU1:
* Keeps local copy of leaderboard, and message queue.
* When making changes to leaderboard, stores changes in message queue.
* At end of frame:
* Request SRAM.
* Copy message queue to SRAM.
* Clear local message queue.
* Trigger IRQ.
* Assume that IRQ will be done by the end of next frame.
* In IRQ, clear message queue?
CPU2:
* Keeps local copy of leaderbaord, and message queue.
* When making changes to leaderboard, stores changes in message queue.
* In IRQ:
* Request SRAM.
* Copy message queue.
* Trigger IRQ.
* Assume that IRQ will be done by the end of next frame.
*/
// const unsigned char test_palette_bg[16]=
// {
// 0x0f,0x1f,0x2f,0x3f,
// 0x0f,0x1d,0x2d,0x3d,
// 0x0f,0x1a,0x2a,0x3a,
// 0x0f,0x10,0x20,0x30
// };
// const unsigned char metasprite_flag[]={
// 0, 0,0x6e,1,
// 8, 0,0x6f,1,
// 0, 8,0x7e,1,
// 8, 8,0x7f,1,
// 0, 16,0x8e,1,
// 8, 16,0x8f,1,
// 0, 24,0x9e,1,
// 8, 24,0x9f,1,
// 128
// };
void main (void)
{
#if VS_SYS_ENABLED
static unsigned char i;
static unsigned int temp_secs;
static unsigned char digit;
#endif
#if VS_SRAM_ENABLED
static unsigned char j;
static unsigned char k;
#endif
// pal_bg(test_palette_bg);
// ppu_on_all(); // turn on screen
// while (1)
// {
// ppu_wait_nmi(); // wait till beginning of the frame
// }
ppu_off(); // screen off
// memcpy(palette_bg, { ppu_RP2C04_0001[0x0f],ppu_RP2C04_0001[0x22],ppu_RP2C04_0001[0x31],ppu_RP2C04_0001[0x30],ppu_RP2C04_0001[0x0f],ppu_RP2C04_0001[0x00],ppu_RP2C04_0001[0x17],ppu_RP2C04_0001[0x28],ppu_RP2C04_0001[0x0f],ppu_RP2C04_0001[0x2a],ppu_RP2C04_0001[0x16],ppu_RP2C04_0001[0x37],ppu_RP2C04_0001[0x0f],ppu_RP2C04_0001[0x22],ppu_RP2C04_0001[0x26],ppu_RP2C04_0001[0x37], }, 16)
// palette_bg = { ppu_RP2C04_0001[0x0f],ppu_RP2C04_0001[0x22],ppu_RP2C04_0001[0x31],ppu_RP2C04_0001[0x30],ppu_RP2C04_0001[0x0f],ppu_RP2C04_0001[0x00],ppu_RP2C04_0001[0x17],ppu_RP2C04_0001[0x28],ppu_RP2C04_0001[0x0f],ppu_RP2C04_0001[0x2a],ppu_RP2C04_0001[0x16],ppu_RP2C04_0001[0x37],ppu_RP2C04_0001[0x0f],ppu_RP2C04_0001[0x22],ppu_RP2C04_0001[0x26],ppu_RP2C04_0001[0x37], };
// palette_sp = { ppu_RP2C04_0001[0x0f],ppu_RP2C04_0001[0x22],ppu_RP2C04_0001[0x31],ppu_RP2C04_0001[0x30],ppu_RP2C04_0001[0x0f],ppu_RP2C04_0001[0x0f],ppu_RP2C04_0001[0x26],ppu_RP2C04_0001[0x37],ppu_RP2C04_0001[0x0f],ppu_RP2C04_0001[0x16],ppu_RP2C04_0001[0x31],ppu_RP2C04_0001[0x37],ppu_RP2C04_0001[0x0f],ppu_RP2C04_0001[0x22],ppu_RP2C04_0001[0x26],ppu_RP2C04_0001[0x37], };
// palette_bg_options = { ppu_RP2C04_0001[0x0f],ppu_RP2C04_0001[0x22],ppu_RP2C04_0001[0x31],ppu_RP2C04_0001[0x30],ppu_RP2C04_0001[0x0f],ppu_RP2C04_0001[0x30],ppu_RP2C04_0001[0x0f],ppu_RP2C04_0001[0x26],ppu_RP2C04_0001[0x0f],ppu_RP2C04_0001[0x22],ppu_RP2C04_0001[0x0f],ppu_RP2C04_0001[0x26],ppu_RP2C04_0001[0x0f],ppu_RP2C04_0001[0x22],ppu_RP2C04_0001[0x26],ppu_RP2C04_0001[0x37], };
// load the palettes
//pal_bg(palette_bg);
//pal_spr(palette_sp);
// use the second set of tiles for sprites
// both bg and sprites are set to 0 by default
bank_spr(1);
set_vram_buffer(); // do at least once, sets a pointer to a buffer
clear_vram_buffer();
// TODO: This is actually the gameplay setup.
off_nt = 0;
cur_nt = 2;
vram_adr(NTADR_A(0,0));
vram_unrle(title_screen);
vram_adr(NTADR_C(0,0));
vram_unrle(game_area);
scroll_y = 0x1df;
scroll(0, scroll_y); // shift the bg down 1 pixel
//set_scroll_y(0xff);
ppu_on_all(); // turn on screen
//music_play(0);
attack_style = ATTACK_ON_TIME;// ATTACK_ON_LAND;
music_on = 1;
sfx_on = 1;
hard_drops_on = 1;
block_style = BLOCK_STYLE_CLASSIC;
state = 0xff; // uninitialized so that we don't trigger a "leaving state".
cur_garbage_type = 0;
#if VS_SYS_ENABLED
credits_remaining = 0;
free_play_enabled = (DIP1 == 0 && DIP2 == 0);
game_cost = ((DIP1 != 0) << 1) | (DIP2 != 0);
if (game_cost == 3)
{
game_cost = 4; // cost of 3 seems odd.
}
music_on = DIP6 == 0;
sfx_on = DIP7 == 0;
high_score_entry_placement = 0xff;
// DIP Val PPU
// 000 0 RP2C04-0001
// 001 1 RP2C04-0002
// 010 2 RP2C04-0003
// 011 3 RP2C04-0004
// 100 4 2C03 and 2C05
PPU_VERSION = ((DIP5!=0)<<2) | ((DIP4 != 0)<<1) | (DIP3 != 0);
#endif //#if VS_SYS_ENABLED
pal_bright(0);
go_to_state(STATE_BOOT);
fade_from_black();
#if VS_SRAM_ENABLED
//one_vram_buffer('0', get_ppu_addr(0, 24, 32));
// Is primary?
if (IS_PRIMARY_CPU)
{
// // Has control.
// one_vram_buffer('0' + ((PEEK(0x4016) & (1 << 7))>>7), get_ppu_addr(0, 24, 32));
// // Take control.
POKE(0x4016, 2);
if (xram_test[1] != 6)
{
xram_test[1] = 6;
one_vram_buffer(xram_test[1], get_ppu_addr(0, 40, 32));
// for (i = 0; i < ATTACK_NUM; ++i)
// //i = 0;
// {
// for (j = 0; j < 4; ++j)
// //j = 0;
// {
// for (k = 0; k < 3; ++k)
// {
// high_scores_vs_initials[i][j][k][0] = '-';
// high_scores_vs_initials[i][j][k][1] = '-';
// high_scores_vs_initials[i][j][k][2] = '-';
// high_scores_vs_value[i][j][k] = 0;
// }
// }
// }
memfill(high_scores_vs_initials, '-', sizeof(high_scores_vs_initials));
memfill(high_scores_vs_value, 0xff, sizeof(high_scores_vs_value) * 4);
//high_scores_vs_initials[0][0][0][0] = '-';
// high_scores_vs_initials[0][0][0][1] = '-';
// high_scores_vs_initials[0][0][0][2] = '-';
//high_scores_vs_value[0][0][0] = 0;
}
// Reliquish control of SRAM.
POKE(0x4016, 0);
}
#endif // #if VS_SRAM_ENABLED
// infinite loop
while (1)
{
ppu_wait_nmi(); // wait till beginning of the frame
//set_music_speed(1);
++tick_count;
++tick_count_large;
++ticks_in_state_large;
pad1 = pad_poll(0); // read the first controller
pad1_new = get_pad_new(0); // newly pressed button. do pad_poll first
pad2 = pad_poll(1);
pad2_new = get_pad_new(1);
// Combine both controllers into one. This is mostly for Vs system, but seems like
// a nice enough feature for NES as well. Co-op mode!
pad_all = pad1 | pad2;
pad_all_new = pad1_new | pad2_new;
#if VS_SYS_ENABLED
if (attract_gameplay_enabled)
{
if ((state == STATE_OPTIONS || state == STATE_GAME))
{
if (pad_all_new != 0)
{
fade_to_black();
go_to_state(STATE_MENU);
fade_from_black();
// clear input so that we don't process it again in the new state.
pad_all = pad_all_new = pad1 = pad1_new = pad2 = pad2_new = 0;
goto skip_attract_input;
}
pad_all = pad_all_new = pad1 = pad1_new = pad2 = pad2_new = 0;
// move faster based on the current difficulty level.
if (ticks_in_state_large % (30 - cur_level) == 0)
{
if (rand() % 2 == 0)
{
pad_all_new |= PAD_LEFT;
}
else
{
pad_all_new |= PAD_RIGHT;
}
pad_all_new |= (rand() % 4 == 0) ? PAD_A : 0;
}
}
}
skip_attract_input:
#endif // #if VS_SYS_ENABLED
#if VS_SYS_ENABLED
// Don't start counting credits until the physical counter is cleared
// from the previous coin.
if (maintenance_counter == 0)
{
// Did the user drop at least 1 credit (maybe more) since the last update?
// Did the arcade owner press the maintenance button.
if (CREDITS_QUEUED > 0 || ((prev_4016 & 1<<2) && !(PEEK(0x4016) & 1<<2)))
{
if (credits_remaining < 254)
{
// Reset the timer so that the "insert coin" display updates
// this frame.
tick_count = 0;
++credits_remaining;
// If attract music is disabled, the title music will not have been started.
// If this credit is the amount needed to leave attract mode, trigger the music to
// starts.
if ((state == STATE_MENU || state == STATE_HIGH_SCORE_TABLE) && (DIP8 != 0 && credits_remaining == game_cost))
{
MUSIC_PLAY_WRAPPER(MUSIC_TITLE);
}
// If this was triggered with maintenance button, the dequeue might be 0, and this would
// send it to 255, which can never be dequeued again.
if (CREDITS_QUEUED > 0)
{
--CREDITS_QUEUED;
// We need 6 frames to set the counter. 3 on and 3 off.
maintenance_counter = 6;
// Set the phyical counter bit.
// NOTE: Overrides other values. Should this PEEK and OR?
// NOTE: This seems to have no impact in emulator. The value at $4020 does not change.
POKE(0x4020, 1);
}
// Don't play fx if in the gameplay state, as it could be distracting.
if (state != STATE_GAME)
{
screen_shake_remaining = 5;
SFX_PLAY_WRAPPER(SOUND_LEVELUP_MULTI);
}
if (attract_gameplay_enabled && (state == STATE_OPTIONS || state == STATE_GAME))
{
fade_to_black();
go_to_state(STATE_MENU);
fade_from_black();
}
}
}
}
else
{
--maintenance_counter;
// Half way throught the physicial counter sequence.
// Turn off the bit, but it needs to stay off for 3 more
// frames.
if (maintenance_counter == 3)
{
POKE(0x4020, 0);
}
}
// Store this for next frame so that we can detect maintenance key released.
prev_4016 = PEEK(0x4016);
#endif //VS_SYS_ENABLED
clear_vram_buffer(); // do at the beginning of each frame
// Quick reset when not on the VS system. I don't think it makes sense to have a quick reset there.
#if !VS_SYS_ENABLED
if (state != STATE_MENU)
{
if (pad_all & PAD_A && pad_all & PAD_B && pad_all & PAD_SELECT && pad_all & PAD_START)
{
go_to_state(STATE_MENU);
}
}
#endif // !VS_SYS_ENABLED
switch(state)
{
case STATE_BOOT:
{
if (tick_count == 120 || pad_all_new & PAD_ALL_BUTTONS)
{
fade_to_black();
go_to_state(STATE_TY);
fade_from_black();
}
break;
}
case STATE_TY:
{
// 120, means wait 240 frames from 120 (previous state).
if (tick_count == 104 || pad_all_new & PAD_ALL_BUTTONS)
{
fade_to_black();
go_to_state(STATE_MENU);
fade_from_black();
}
break;
}
case STATE_MENU:
{
draw_menu_sprites();
if (tick_count % 128 == 0)
{
#if VS_SYS_ENABLED
if (free_play_enabled) // free play
{
multi_vram_buffer_horz(text_free_play, sizeof(text_free_play)-1, get_ppu_addr(0, 8<<3, 12<<3));
}
else if (credits_remaining >= game_cost)
{
multi_vram_buffer_horz(text_push_start, sizeof(text_push_start)-1, get_ppu_addr(0, 8<<3, 12<<3));
}
else
{
if (game_cost - credits_remaining == 1)
{
multi_vram_buffer_horz(text_insert_1_coin, sizeof(text_insert_1_coin)-1, get_ppu_addr(0, 8<<3, 12<<3));
}
else
{
multi_vram_buffer_horz(text_insert_2_coin, sizeof(text_insert_2_coin)-1, get_ppu_addr(0, 8<<3, 12<<3));
}
}
#else
multi_vram_buffer_horz(text_push_start, sizeof(text_push_start)-1, get_ppu_addr(0, 12<<3, 12<<3));
#endif
}
else if (tick_count % 128 == 96)
{
#if VS_SYS_ENABLED
multi_vram_buffer_horz(clear_push_start, sizeof(clear_push_start)-1, get_ppu_addr(0, 8<<3, 12<<3));
#else
multi_vram_buffer_horz(clear_push_start, sizeof(clear_push_start)-1, get_ppu_addr(0, 12<<3, 12<<3));
#endif
}
#if !VS_SYS_ENABLED
if (pad_all_new != 0)
{
if (pad_all_new & konami_code[cur_konami_index])
{
++cur_konami_index;
}
else
{
cur_konami_index = 0;
}
}
#endif //#if !VS_SYS_ENABLED
#if VS_SYS_ENABLED
// 2
if (pad2_new & (PAD_SELECT))
{
fade_to_black();
auto_forward_leaderboards = 1;
go_to_state(STATE_HIGH_SCORE_TABLE);
fade_from_black();
}
// Any A or B, or 1, 3, 4.
else if (((pad1_new & PAD_SELECT) || (pad_all_new & (PAD_START | PAD_A | PAD_B))) && (credits_remaining >= game_cost || free_play_enabled)) // free play
#else
if (pad_all_new & PAD_START)
#endif //VS_SYS_ENABLED
{
srand(tick_count_large);
#if !VS_SYS_ENABLED
if (cur_konami_index >= KONAMI_CODE_LEN)
{
SFX_PLAY_WRAPPER(SOUND_LEVELUP_MULTI);
music_stop();
go_to_state(STATE_SOUND_TEST);
}
else
#endif //#if !VS_SYS_ENABLED
{
fade_to_black();
go_to_state(STATE_OPTIONS);
fade_from_black();
}
}
#if VS_SYS_ENABLED
// "attract mode" to avoid burn in. Just go back to the start.
// Timed to be when the title track finishes for a 2nd time.
if ((credits_remaining < game_cost) && ticks_in_state_large > (15*60*1))
{
fade_to_black();
attract_gameplay_enabled = 1;
go_to_state(STATE_OPTIONS);
fade_from_black();
}
#endif //#if VS_SYS_ENABLED
break;
}
case STATE_OPTIONS:
{
#if VS_SYS_ENABLED
// do this first, so the sprites get cleared in the case of auto-advancing.
if (ticks_in_state_large <= AUTO_FORWARD_DELAY)
{
oam_clear();
temp_secs = ((AUTO_FORWARD_DELAY - ticks_in_state_large)/60);
digit = (temp_secs) % 10;
oam_spr(27<<3, 2<<3, '0' + digit, 0);
temp_secs = temp_secs / 10;
digit = (temp_secs) % 10;
oam_spr(26<<3, 2<<3, '0' + digit, 0);
}
switch ((option_state))
{
case 0:
{
if (pad_all_new & PAD_RIGHT)
{
if (attack_style < ATTACK_NUM - 1)
{
for (i = 0; i < 4; ++i)
{
pal_col(i + (4 * attack_style), palette_vs_options_inactive[i]);
}
++attack_style;
SFX_PLAY_WRAPPER(SOUND_MENU_HIGH);
for (i = 0; i < 4; ++i)
{
pal_col(i + (4 * attack_style), palette_vs_options_active[i]);
}
}
}
else if (pad_all_new & PAD_LEFT)
{
if (attack_style > 0)
{
for (i = 0; i < 4; ++i)
{
pal_col(i + (4 * attack_style), palette_vs_options_inactive[i]);
}
--attack_style;
SFX_PLAY_WRAPPER(SOUND_MENU_LOW);
for (i = 0; i < 4; ++i)
{
pal_col(i + (4 * attack_style), palette_vs_options_active[i]);
}
}
}
if (pad_all_new & (PAD_A | PAD_B | PAD_SELECT | PAD_START) || ticks_in_state_large > AUTO_FORWARD_DELAY)
{
fade_to_black();
oam_clear();
ppu_off();
vram_adr(NTADR_A(0,0));
vram_unrle(vs_settings_difficulty);
ppu_on_all();
option_state = 1;
for (i = 0; i < 4; ++i)
{
pal_col(i + (4 * attack_style), palette_vs_options_inactive[i]);
}
for (i = 0; i < 4; ++i)
{
pal_col(i + (4 * cur_level_vs_setting), palette_vs_options_active[i]);
}
fade_from_black();
}
break;
}
case 1:
{
if (vs_code_index < VS_CODE_LEN)
{
if (pad_all_new != 0)
{
if (pad_all_new & vs_code[vs_code_index])
{
++vs_code_index;
if (vs_code_index == VS_CODE_LEN)
{
music_stop();
SFX_PLAY_WRAPPER(SOUND_LEVELUP_MULTI)
cur_level_vs_setting = 3;
pal_bg(palette_vs_options_skulls);
ticks_in_state_large = MAX(ticks_in_state_large, AUTO_FORWARD_DELAY - (5*60));
}
}
else
{
vs_code_index = 0;
}
}
}
else
{
for (i = 0; i < 8; ++i)
{
one_vram_buffer(0x01, get_ppu_addr(0, rand() % 256, rand() % 240));
}
}
if (vs_code_index < VS_CODE_LEN && pad_all_new & PAD_RIGHT)
{
if (cur_level_vs_setting < 2)
{
for (i = 0; i < 4; ++i)
{
pal_col(i + (4 * cur_level_vs_setting), palette_vs_options_inactive[i]);
}
++cur_level_vs_setting;
SFX_PLAY_WRAPPER(SOUND_MENU_HIGH);
for (i = 0; i < 4; ++i)
{
pal_col(i + (4 * cur_level_vs_setting), palette_vs_options_active[i]);
}
}
}
else if (vs_code_index < VS_CODE_LEN && pad_all_new & PAD_LEFT)
{
if (cur_level_vs_setting > 0)
{
for (i = 0; i < 4; ++i)
{
pal_col(i + (4 * cur_level_vs_setting), palette_vs_options_inactive[i]);
}
--cur_level_vs_setting;
SFX_PLAY_WRAPPER(SOUND_MENU_LOW);
for (i = 0; i < 4; ++i)
{
pal_col(i + (4 * cur_level_vs_setting), palette_vs_options_active[i]);
}
}
}
if (pad_all_new & (PAD_A | PAD_B | PAD_SELECT | PAD_START) || (ticks_in_state_large > AUTO_FORWARD_DELAY))
{
music_stop();
SFX_PLAY_WRAPPER(SOUND_START);
// 0, 9, 19, 29.
// MAX to ensure setting 0 doesn't wrap around.
cur_level = MAX(1, (cur_level_vs_setting * 10)) - 1;
fade_to_black();
ppu_off();
// prevent vram changes showing up in gameplay.
clear_vram_buffer();
vram_adr(NTADR_A(0,0));
vram_unrle(title_screen);
ppu_on_all();
go_to_state(STATE_GAME);
fade_from_black();
}
break;
}
default:
break;
}
#else
if (tick_count % 128 == 0)
{
multi_vram_buffer_horz(text_push_start, sizeof(text_push_start)-1, get_ppu_addr(0, 12<<3, 12<<3));
}
else if (tick_count % 128 == 96)
{
multi_vram_buffer_horz(clear_push_start, sizeof(clear_push_start)-1, get_ppu_addr(0, 12<<3, 12<<3));
}
if (pad_all_new & PAD_START)
{
music_stop();
SFX_PLAY_WRAPPER(SOUND_START);
fade_to_black();
ppu_off();
vram_adr(NTADR_A(0,0));
vram_unrle(title_screen);
ppu_on_all();
fade_from_black();
// little cheat to start at very high levels.
if (cur_level == 9 && pad_all & PAD_SELECT)
{
cur_level = 29;
}
else if (pad_all & PAD_A)
{
cur_level += 10;
}
go_to_state(STATE_GAME);
}
if (pad_all_new & PAD_B)
{
fade_to_black();
go_to_state(STATE_MENU);
fade_from_black();
}
else if (pad_all_new & PAD_RIGHT)
{
switch (cur_option)
{
case 0: // starting level
if (cur_level < 9 )
{
++cur_level;
}
else
{
cur_level = 0;
}
break;
case 1: // Attack style
//attack_style = (attack_style + 1) % ATTACK_NUM;
if (attack_style < ATTACK_NUM - 1)
{
++attack_style;
display_highscore();
}
break;
case 2: // Music off/on
//music_on = (music_on + 1) % 2;
if (music_on == 0)
{
music_on = 1;
MUSIC_PLAY_ATTRACT_WRAPPER(MUSIC_TITLE);
music_pause(0);
}
// if (music_on == 0)
// {
// music_stop();
// }
// else
// {
// music_play(MUSIC_TITLE);
// }
break;
case 3: // sound fx on/off
{
if (sfx_on == 0)
{
sfx_on = 1;
}
break;
}
case 4: // hard drops
{
if (hard_drops_on < NUM_HARD_DROP_SETTINGS - 1)
{
++hard_drops_on;
}
}
default:
break;
}
SFX_PLAY_WRAPPER(SOUND_MENU_HIGH);
display_options();
}
else if (pad_all_new & PAD_LEFT)