-
Notifications
You must be signed in to change notification settings - Fork 0
/
fallingblocks.asm
5460 lines (4666 loc) · 106 KB
/
fallingblocks.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
;
; FallingBlocks.asm
;
; Copyright (c) 2015-2016 Peter McQuillan
;
; All Rights Reserved.
;
; Distributed under the BSD Software License (see license.txt)
;
;
ENTRY_POINT EQU 24576
org ENTRY_POINT
; set up our own routines. Two elements, a table that points to where the interrupt code is
; held and the actual interrupt code itself. Due to the strange way interrupts work on spectrum
; our table is a series of the value 200. The idea is that an interrupt call would randomly jump
; to somewhere in this table and read the values 200 (2 reads) 0 this gives a memory location of
; (200*256) + 200 = 51400, which is where we will put our actual interrupt routine
; We put our table out of the way, starting at 65024 (which is 256 * 254)
di ; we are setting up out own interrupt routine, disable while doing this
ld a,254 ; high byte of pointer table location (256 * 254 gives 65024).
ld i,a ; set high byte.
im 2 ; select interrupt mode 2.
ei ; enable interrupts.
jp START
graphics
defb 254, 126, 190, 94, 174, 86, 170, 0 ; basic block
defb 126, 129, 189, 165, 165, 189, 129, 126 ; old side wall graphic
defb 231, 231, 231, 231, 231, 231, 231, 231 ;vertical pipe
defb 60, 126, 126, 231, 231, 231, 231, 231 ;pipe end (top)
defb 231, 231, 231, 231, 231, 126, 126, 60 ; pipe end (bottom)
defb 255, 255, 255, 0, 0, 255, 255, 255 ;horizontal pipe
defb 231, 231, 227, 224, 240, 255, 127, 63 ; pipe corner bottom left
defb 63, 127, 255, 240, 224, 227, 231, 231 ; pipe corner top left
defb 231, 231, 199, 7, 15, 255, 254, 252 ; pipe corner bottom right
defb 252, 254, 255, 15, 7, 199, 231, 231 ; pipe corner top right
defb 8, 4, 2, 255, 2, 4, 8, 0, 56 ; arrow pointing right
;Port array used for the redefine keys routine
port_array: defb $7f ; B-SPACE
defb $bf ; H-ENTER
defb $df ; Y-P
defb $ef ; 6-0
defb $f7 ; 1-5
defb $fb ; Q-T
defb $fd ; A-G
defb $fe ; CAPS-V
key_music_port: defb $7f
key_music_pattern: defb 4
key_left_port: defb $df
key_left_pattern: defb 2
key_right_port: defb $df
key_right_pattern: defb 1
key_anticlockwise_port: defb $7f
key_anticlockwise_pattern: defb 1
key_clockwise_port: defb $bf
key_clockwise_pattern: defb 16
key_drop_port: defb $fd
key_drop_pattern: defb 4
key_ghost_port: defb $fd
key_ghost_pattern: defb 16
key_swap_port: defb $fd
key_swap_pattern: defb 2
ROM_CLS: EQU 3435
CHAN_OPEN: EQU 5633
CC_INK: EQU 16
CC_PAPER: EQU 17
CC_AT: EQU 22
msg_left: defm CC_INK,4,CC_AT,7,8,"Left ?",255
msg_right: defm CC_INK,4,CC_AT,8,8,"Right ?",255
msg_anticlockwise: defm CC_INK,4,CC_AT,9,8,"Anti Clockwise ?",255
msg_clockwise: defm CC_INK,4,CC_AT,10,8,"Clockwise ?",255
msg_drop: defm CC_INK,4,CC_AT,11,8,"Drop ?",255
msg_ghost: defm CC_INK,4,CC_AT,12,8,"Ghost ?",255
msg_swap: defm CC_INK,4,CC_AT,13,8,"Swap/Save ?",255
msg_music: defm CC_INK,4,CC_AT,14,8,"Music On/Off ?",255
msg_define: defm CC_INK,4,CC_AT,1,7,"Press key for ...",255
msg_gameover_score: defm CC_INK,7,CC_AT,17,10,"Your score",255
msg_gameover_newhighscore defm CC_INK,4,CC_AT,21,0,"Congratulations! New high score",255
msg_newscreen_level defm CC_INK,7,CC_AT,12,12,"Level ",255
startx defb 0 ; all blocks start at this position
starty defb 15 ; all blocks start at this position
upsidedownstartx defb 20 ; starting x position if upside down
nextblockx defb 11 ;x position of the next block space
nextblocky defb 25 ;y position of the next block space
scorex defb 4 ;x position where we write the score
scorey defb 25 ; y position where we write the score
highscorex defb 4 ; x position where we write the high score
highscorey defb 3 ; y position where we write the high score
savedblockx defb 11 ;x position of the saved block space
savedblocky defb 4 ;y position of the saved block space
ghostx defb 0 ;x position of the ghost shape
ghosty defb 15 ;y position of the ghost shape
linesx defb 18 ; x position of where we write the lines completed
linesy defb 25 ; y position of where we write the lines completed
shootingstarx defb 0 ; x position of the star
shootingstary defb 0 ; y position of the star
; holds the row that will be shifted one column left or right
slidingrow defb 0
; sliding attempt counter. We try 20 times to find a row to slide, but if not we exit
; this is to prevent the (unlikely) case of no pieces currently being on the playarea
slidingcounter defb 0
; when we slide a row we wrap around the blocks, this holds the value of the wrapped around block
slidingwraparoundcolour defb 0
; this is the temp holder for colours used in the sliding floors routine
slidingtempcolour defb 0
; This holds the colour of the ghost shape (bright white)
ghostcolour defb 71
; this is used for determining whether the ghost is actually showing, for example may not be
; due to shape being too near the top of the piled blocks
ghostshowing defb 0
; This defines the top line starting position, this is used when erasing the line
; after a winning line is detected
playareatoplinex defb 0
playareatopliney defb 12
upsidedownplayareatoplinex defb 21 ; top line when upside down
plx defb 4 ; player's x coordinate.
ply defb 4 ; player's y coordinate.
tmpx defb 16
tmpy defb 16
wallpos defb 3
shapedata
defb 15,0 ; shape 1
defb 68,68
defb 15,0
defb 68,68
defb 142,0 ; shape 2
defb 68,192
defb 14,32
defb 200,128
defb 46,0 ;shape 3
defb 196,64
defb 232,0
defb 136,192
defb 204,0 ;shape 4
defb 204,0
defb 204,0
defb 204,0
defb 108,0 ; shape 5
defb 140,64
defb 108,0
defb 140,64
defb 78,0 ; shape 6
defb 76,64
defb 14,64
defb 140,128
defb 198,0 ; shape 7
defb 76,128
defb 198,0
defb 76,128 ; this is the end of the standard blocks
defb 72,0 ;shape 8
defb 132,0
defb 72,0
defb 132,0
defb 200,192 ;shape 9
defb 174,0
defb 196,192
defb 14,160
defb 12,0 ; shape 10
defb 68,0
defb 12,0
defb 68,0
defb 164,0 ; shape 11
defb 132,128
defb 74,0
defb 72,64
defb 78,64 ; shape 12
defb 78,64
defb 78,64
defb 78,64
; this holds the offset for ghost. Basically it is the number of increments you would
; need to take for a shape to be no longer blocking itself
ghostoffset
defb 1,4,1,4
defb 2,3,2,3
defb 2,3,2,3
defb 2,2,2,2
defb 2,2,2,2
defb 2,3,2,3
defb 2,2,2,2
defb 1,1,1,1
defb 3,2,3,2
defb 1,2,1,2
defb 1,3,1,3
defb 3,3,3,3
; this table helps find the correct ghost offset
ghostlookuptable defb 0,4,8,12,16,20,24,28,32,36,40,44
; ghost offset value pointer
ghostpointer defb 0
; this gives the colour of each of the shapes
colourlookuptable defb 5,1,67,6,4,3,2,66,68,69,70,65
blockshapes defb 142,0
; this holds the current shape being shown
currentshape defb 3
; this holds the next shape that will be played
nextshape defb 2
; this holds the saved shape
savedshape defb 0
currentorientation defb 0
blockpointer defb 0
blocklookuptable defb 0,8,16,24,32,40,48,56,64,72,80,88
; this is the number of complete lines required to win each level
linesneededperlevel defb 10,6,6,5,4,8,5,5,4,25
;linesneededperlevel defb 1,3,4,1,1,1,1,1,1,1
; this holds what level the player is currently on
currentlevel defb 1
; this holds the total number of lines completed so far this level
totalrowscompleted defb '00'
; this holds the total number of lines completed so far this level (as a number)
totalrowscompletednum defb 0
; this holds the lines target for this level (as a string)
targetlinesforthislevel defb '00'
; this holds the lines target for this level (as a number)
targetlinesforthislevelnum defb 0
; this is the colour of the shape currently being played
blockcolour defb 5
; this is the colour used by showshape when showing a shape onscreen
drawcolour defb 0
; this holds the current number of complete lines we have made this level
completedlines defb 0
; this is set to 1 when a winning/complete line is detected
winningline defb 0
; when flashing a winning line, or then erasing it, this sets the colour
winninglinecolour defb 130 ; flashing red
; holds the score
score defb '000000'
; holds the high score
highscore defb '001250'
; shows whether a new high score has been set
newhighscore defb 0
; this holds whether the level is upside down (i.e. falls up rather than usual down)
upsidedown defb 0
; a value of 1 means allowed move
allowedmove defb 1
; a player is only allowed swap once (till the next shape is automatically picked)
; a value of 1 means they are allowed swap, otherwise they are not
allowedswap defb 1
; rows completed holds the number of rows filled, bonus points for 4
rowscompleted defb 0
; this holds the number of pieces played this level
piecesthislevel defb 0
; ghost active. 0 is off, 1 is on. This determines whether the ghost shape is shown
; The ghost shape shows where the shape would go if the player pressed drop
ghostactive defb 0
; this holds whether Kempston joystick support is enabled or not. Can cause
; issues if activated when, say, emulator is not set to support it.
; 0 - disabled, 1 - enabled, 2 - not available
kemsptonactivated defb 0
; this holds the difficulty level, 0 is normal, 1 is hard
difficulty defb 0
; this holds the mainmenu option pointer. If joystick is available then this is the option
; the arrow is pointing at
mainmenuoptionpointer defb 0
; this holds the current settings option pointer. If joystick is available then this is the option
; the arrow is pointing at
settingsmenuoptionpointer defb 0
; this holds the mainmenu option chosen.
mainmenuoptionchosen defb 0
; this holds the current settings option chosen.
settingsmenuoptionchosen defb 0
; this holds the colour of the arrow that points at the menu options
arrowcolour defb 2
; this holds the current x position of the arrow
arrowxpos defb 18
; timer used when deciding to auto drop the block
pretim defb 0
; this holds whether in game music is wanted/enabled (by the player)
gamemusicenabled defb 1
; drop method. When set to 0 if the player presses drop then the piece drops in one go as
; far as it can. If set to 1 then the piece only goes down while the player holds the key
; when set to 1 acts like a 'down' key rather than a drop
; when set to 2, it acts like a mixture. A quick tap causes the piece to drop down fully,
; while holding it down causes it to act like a 'down' key.
dropmethod defb 0
; this is used when the dropmethod is set to 2, used in the case when we want to say drop full
fulldropactive defb 0
; as we support key repeat, this is used to show when it is the first call of the key within a
; possible repeat series. Holds the number of repeated key presses
keypresscount defb 0
; this holds the number of repeated joystick fire button presses
firebuttoncount defb 0
; this holds the key press sensitivity, essentially this is the delay between keypress repeat
; 0 is fast, 1 is normal, 2 is slow
sensitivity defb 1
randomtable:
db 82,97,120,111,102,116,20,12
; holds a value for last action/key pressed.
; a bit is set corresponding to the action done
lastkeypressed defb 0
; holds a value for last joystick action done
; a bit is set corresponding to the action done
lastjoystick defb 0
;; this mask determines if simultaneous key presses are allowed. Set to 255 to allow
keypressmask defb 0
msg_menu_copyright: defm CC_INK,7,CC_AT,13,4,"(c)2015 Peter McQuillan",255
msg_menu_startgame: defm CC_INK,7,CC_AT,18,4,"1 Start Game",255
msg_menu_definekeys: defm CC_INK,7,CC_AT,19,4,"2 Define Keys",255
msg_menu_kempston: defm CC_INK,7,CC_AT,20,4,"3 Kempston Joystick",255
msg_menu_settings: defm CC_INK,7,CC_AT,21,4,"4 Settings",255
msg_menu_kempston_on: defm CC_INK,4,CC_AT,20,23,"(On) ",255
msg_menu_kempston_off: defm CC_INK,2,CC_AT,20,23,"(Off)",255
msg_menu_kempston_na: defm CC_INK,2,CC_AT,20,23,"(n/a)",255 ; we detect if a kempston joystick is present, if not show this
;settings menu text
msg_menu_difficulty: defm CC_INK,7,CC_AT,10,4,"1 Difficulty",255
msg_menu_difficulty_normal: defm CC_INK,4,CC_AT,10,16,"(Normal) ",255
msg_menu_difficulty_hard: defm CC_INK,2,CC_AT,10,16,"(Hard) ",255
msg_menu_dropmethod: defm CC_INK,7,CC_AT,11,4,"2 Drop Method",255
msg_menu_dropmethod_normal: defm CC_INK,4,CC_AT,11,17,"(Full) ",255
msg_menu_dropmethod_likedown: defm CC_INK,2,CC_AT,11,17,"(While Held)",255
msg_menu_dropmethod_mixture: defm CC_INK,6,CC_AT,11,17,"(Mixture) ",255
msg_menu_sensitivity: defm CC_INK,7,CC_AT,12,4,"3 Control Response",255
msg_menu_sensitivity_fast: defm CC_INK,4,CC_AT,12,22,"(Fast) ",255
msg_menu_sensitivity_normal: defm CC_INK,6,CC_AT,12,22,"(Normal)",255
msg_menu_sensitivity_slow: defm CC_INK,2,CC_AT,12,22,"(Slow) ",255
msg_menu_simultaneous: defm CC_INK,7,CC_AT,13,4,"4 Simultaneous Keys",255
msg_menu_simultaneous_off: defm CC_INK,4,CC_AT,13,23,"(Off) ",255
msg_menu_simultaneous_on: defm CC_INK,2,CC_AT,13,23,"(On) ",255
msg_menu_back_to_main_menu: defm CC_INK,7,CC_AT,14,4,"5 Back To Main Menu",255
msg_game_score: defm CC_INK,7,CC_AT,2,25,"Score",255
msg_game_highscore: defm CC_INK,7,CC_AT,2,3,"High",255
msg_game_nextpiece: defm CC_INK,7,CC_AT,9,25,"Next",255
msg_game_savedpiece: defm CC_INK,7,CC_AT,9,3,"Saved",255
msg_game_line: defm CC_INK,7,CC_AT,16,25,"Lines",255
msg_game_ghost: defm CC_INK,7,CC_AT,16,3,"Ghost",255
msg_game_ghost_active: defm CC_INK,4,CC_AT,18,2," Active ",255
msg_game_ghost_inactive: defm CC_INK,2,CC_AT,18,2,"Inactive",255
msg_game_level1: defm CC_INK,7,CC_AT,1,8,"1 - Nice and Easy",255
msg_game_level2: defm CC_INK,7,CC_AT,1,9,"2 - Spice it up ",255
msg_game_level3: defm CC_INK,7,CC_AT,1,10,"3 - G'day Mate",255
msg_game_level4: defm CC_INK,7,CC_AT,1,8,"4 - Shooting Star",255
msg_game_level5: defm CC_INK,7,CC_AT,1,10,"5 - More Stars",255
msg_game_level6: defm CC_INK,7,CC_AT,1,11,"6 - Letter F",255
msg_game_level7: defm CC_INK,7,CC_AT,1,12,"7 - Mirror",255
msg_game_level8: defm CC_INK,7,CC_AT,1,8,"8 - Sliding Floor",255
msg_game_level9: defm CC_INK,7,CC_AT,1,10,"9 - Mix it up",255
msg_game_level10: defm CC_INK,7,CC_AT,1,9,"10 - Rising Fall",255
; date for the main falling blocks logo on the main menu page. 254 means end of line, 255 means end of data
fallingblockslogo
defb 0,0,67,67,67,0,254
defb 0,0,67,0,0,0,0,7,0,0,7,0,0,0,7,0,0,0,7,7,7,0,7,7,0,0,0,7,7,254
defb 0,0,0 ,0,0,0,7,0,3,0,5,0,0,0,7,0,0,0,0,7,0,0,7,0,5,0,7,0,0,254
defb 0,0,7 ,7,0,0,7,3,3,0,5,0,0,0,7,0,0,0,0,7,0,0,7,0,5,0,7,0,2,254
defb 0,0,7 ,0,0,0,7,0,3,0,5,0,0,0,7,0,0,0,0,7,0,0,7,0,5,0,7,0,2,254
defb 0,0,7 ,0,0,0,7,0,7,0,5,7,7,0,7,7,7,0,7,7,7,0,7,0,5,0,0,2,2,254
defb 254
defb 0,0,0,0,7,7,0,0,7,0,0,0,0,7,0,0,0,7,7,0,7,0,7,0,0,7,7,254
defb 0,0,0,0,7,0,7,0,7,0,0,0,7,0,7,0,7,0,0,0,3,0,7,0,7,0,0,254
defb 0,0,0,0,67,7,0,0,7,0,0,0,7,0,7,0,7,0,0,0,3,3,0,0,0,7,0,254
defb 0,0,0,0,67,0,7,0,2,0,0,0,7,0,7,0,7,0,0,0,3,0,7,0,0,0,7,254
defb 0,0,0,0,67,67,0,0,2,2,2,0,0,7,0,0,0,7,7,0,7,0,7,0,7,7,0,254
defb 255
gameoverlogo
defb 254,254,254 ;skip a few lines
defb 0,0,0,0,0,0,0,0,7,7,0,0,7,0,0,7,0,0,0,7,0,7,7,7,254
defb 0,0,0,0,0,0,0,7,0,0,0,7,0,7,0,7,7,0,7,7,0,7,0,0,254
defb 0,0,0,0,0,0,0,7,0,7,0,7,7,7,0,7,0,7,0,7,0,7,7,0,254
defb 0,0,0,0,0,0,0,7,0,7,0,7,0,7,0,7,0,0,0,7,0,7,0,0,254
defb 0,0,0,0,0,0,0,0,7,7,0,7,0,7,0,7,0,0,0,7,0,7,7,7,254
defb 254
defb 0,0,0,0,0,0,0,0,0,7,0,0,7,0,7,0,7,7,7,0,7,7,0,254
defb 0,0,0,0,0,0,0,0,7,0,7,0,7,0,7,0,7,0,0,0,7,0,7,254
defb 0,0,0,0,0,0,0,0,7,0,7,0,7,0,7,0,7,7,0,0,7,7,0,254
defb 0,0,0,0,0,0,0,0,7,0,7,0,0,7,0,0,7,0,0,0,7,0,7,254
defb 0,0,0,0,0,0,0,0,0,7,0,0,0,7,0,0,7,7,7,0,7,0,7,254
defb 255
youwinlogo
defb 254,254,254
defb 0,0,0,0,0,0,0,0,0,0,7,0,7,0,0,7,0,0,7,0,7,254
defb 0,0,0,0,0,0,0,0,0,0,7,0,7,0,7,0,7,0,7,0,7,254
defb 0,0,0,0,0,0,0,0,0,0,0,7,0,0,7,0,7,0,7,0,7,254
defb 0,0,0,0,0,0,0,0,0,0,0,7,0,0,7,0,7,0,7,0,7,254
defb 0,0,0,0,0,0,0,0,0,0,0,7,0,0,0,7,0,0,0,7,0,254
defb 254
defb 0,0,0,0,0,0,0,0,0,7,0,0,0,7,0,7,7,7,0,7,7,0,254
defb 0,0,0,0,0,0,0,0,0,7,0,0,0,7,0,0,7,0,0,7,0,7,254
defb 0,0,0,0,0,0,0,0,0,7,0,7,0,7,0,0,7,0,0,7,0,7,254
defb 0,0,0,0,0,0,0,0,0,7,7,0,7,7,0,0,7,0,0,7,0,7,254
defb 0,0,0,0,0,0,0,0,0,7,0,0,0,7,0,7,7,7,0,7,0,7,254
defb 255
START
; Set up the graphics.
ld de,(23675) ; address of user-defined graphics data.
ld hl, graphics
ld bc,88
ldir
BEGIN
xor a ; black ink (0) on black paper (0*8).
ld (23693),a ; set our screen colours.
call 3503 ; clear the screen.
; We also want to change the border colour
xor a ; 0 is the code for black.
call 8859 ; set border colour.
;open the upper screen for printing (channel 2)
ld a,2
call 5633
; set the main menu music to be 'If I Were A Rich Man'
ld bc,ifiwerearichman
ld (gamemusic),bc
ld a, 8
ld (musicspeed),a
xor a
ld (noteindex),a ; so music plays at start of song
ld (keypresscount),a ; so we show no keys have been pressed before
ld (firebuttoncount),a ; we reset the counter for the joystick fire button presses
ld (mainmenuoptionpointer),a ; we reset where the arrow points to on main menu
ld a,18
ld (arrowxpos),a ; start position on screen for the arrow (if kemptson available)
; before we start the main menu we need to see if a kempston joystick is
; actually there. Otherwise you can have a situation where the user enables
; kempston support but they don't actually have one and strange things happen
; during the game :) This is due to floating bus values
halt
in a,(31) ;read kempston joystick port directly after HALT
and 31
ld b,a ; backup value of a in register b for later usage
and 3
cp 3 ; this is equal to both left and right being active at same time, obviously should not happen with real joystick
jr z, nojoy
ld a,b ; get back that value we saved earlier
and 12
cp 12 ; 12 (8+4) is both up and down, again should not be possible
jr z, nojoy
; a joystick is available, show arrow
call drawarrow
jr mainmenu ; all good, go to main menu
nojoy
ld a,2
ld (kemsptonactivated),a ; set value to not available
mainmenu
ld hl,fallingblockslogo
call printwordswithblocks
ld hl,msg_menu_copyright
call print_message
ld hl,msg_menu_startgame
call print_message
ld hl,msg_menu_definekeys
call print_message
ld hl, msg_menu_kempston
call print_message
ld hl,msg_menu_settings
call print_message
mm11
ld a,(kemsptonactivated)
cp 0
jr z,mm6
cp 2
jr z, mm9
ld hl, msg_menu_kempston_on
call print_message
jp mm1
mm6
ld hl, msg_menu_kempston_off
call print_message
jr mm1
mm9
; kempston is not available
ld hl, msg_menu_kempston_na
call print_message
mm1
; if kempston is active, we check for up, down and fire
ld a,(kemsptonactivated)
cp 2
jp z, mmkey1
mmjoy1
; kempston is available
ld bc,31
in a,(c)
and 31 ; bitmask 5 bits
or 0
jr nz, mmjoy2
jp mmkey1 ; no joystick action
mmjoy2
ld bc,31
in a,(c) ; read input.
and 8 ; check "up" bit.
jr nz,mmjoy3 ; move up.
jr mmjoy4
mmjoy3
; move arrow up if possible
; if mainmenuoptionpointer is 0 then cannot move up
ld a,(mainmenuoptionpointer)
or 0
jp z, mmkey1 ; at top option already, jump to key read section as nothing more to do in joystick section
; possible to move up, so decrement mainmenuoptionpointer and arrowxpos
xor a
ld (arrowcolour),a
call drawarrow ; erase old arrow
ld hl,mainmenuoptionpointer
dec (hl)
ld hl,arrowxpos
dec (hl)
ld a,2
ld (arrowcolour),a
call drawarrow
call smalldelay
jr mmkey1 ; finished in joystick read section
mmjoy4
ld bc,31
in a,(c) ; read input.
and 4 ; check "down" bit.
jr nz,mmjoy5
jr mmjoy6
mmjoy5
; move arrow down if possible
; if mainmenuoptionpointer is 3 then cannot move down
ld a,(mainmenuoptionpointer)
cp 3
jr z, mmkey1 ; at bottom option already, jump to key read section as nothing more to do in joystick section
; possible to move down, so increment mainmenuoptionpointer and arrowxpos
xor a
ld (arrowcolour),a
call drawarrow ; erase old arrow
ld hl,mainmenuoptionpointer
inc (hl)
ld hl,arrowxpos
inc (hl)
ld a,2
ld (arrowcolour),a
call drawarrow
call smalldelay
jr mmkey1 ; finished in joystick read section
mmjoy6
ld bc,31
in a,(c) ; read input.
and 16 ; try the fire bit.
jr nz,mmjoy7 ; fire pressed.
jr mmkey1
mmjoy7
; fire button pressed
ld a,(mainmenuoptionpointer)
cp 1
jr nz, mmjoy8
; the key read routine actually sets all the bits to 1 except the key corresponding to key pressed
ld a,29 ; 11101
ld (mainmenuoptionchosen),a
jr mm20
mmjoy8
cp 2
jr nz, mmjoy9
ld a,27 ; 11011
ld (mainmenuoptionchosen),a
jr mm20
mmjoy9
cp 3
jr nz, mmjoy10
ld a,23 ;10111
ld (mainmenuoptionchosen),a
jr mm20
mmjoy10
; assume it is start game
ld a,30 ;11110
ld (mainmenuoptionchosen),a
jr mm20
mmkey1
;IN 63486 reads the half row 1 to 5
ld bc,63486
in a,(c)
ld (mainmenuoptionchosen),a
mm20
ld a,(mainmenuoptionchosen)
bit 0,a
jr nz,mm2
jr mm5 ;1 key pressed, start game
mm2
ld a, (mainmenuoptionchosen)
bit 1,a
jr nz,mm3
call do_the_redefine
jp BEGIN
mm3
ld a, (mainmenuoptionchosen)
bit 2,a
jr nz,mm7
ld a,(kemsptonactivated)
cp 0
jr z,mm8
cp 2
jr z,mm10
; if here then currently support enabled, so disable
xor a
ld (kemsptonactivated),a
ld hl, msg_menu_kempston_off
call print_message
call mediumdelay
jp mm13
mm8
; if here then currently support disabled, so enable
ld a,1
ld (kemsptonactivated),a
ld hl, msg_menu_kempston_on
call print_message
call mediumdelay
jr mm13
mm10
; if we are set to n/a for kempston we ignore '3' keypresses
jr mm13
mm7
ld a, (mainmenuoptionchosen)
bit 3,a ; check for keypress of number 4
jr nz,mm13
call settingsmenu
jp BEGIN ; need to reset everything after accessing settings menu
mm13
jp mm1
mm5
call 3503
jp maingame
settingsmenu
; settings menu is where difficulty level can be chosen and where the behaviour of the pieces can be altered
call ROM_CLS
xor a
ld (settingsmenuoptionpointer),a ; we reset where the arrow points to on settings menu
ld a,10
ld (arrowxpos),a ; start position on screen for the arrow on settings menu (if kemptson available)
ld hl,msg_menu_difficulty
call print_message
ld a,(difficulty)
cp 0
jr nz,setm1 ; 0 is normal difficulty
ld hl,msg_menu_difficulty_normal
call print_message
jr setm5
setm1
ld hl,msg_menu_difficulty_hard
call print_message
setm5
ld hl,msg_menu_dropmethod
call print_message
ld a,(dropmethod)
cp 0
jr z,setm20 ; 0 is normal drop method
cp 1
jr z,setm6; 1 is when acts like a down key
; otherwise we assume acting like a mixture
jr setm21
setm20
; normal drop method
ld hl,msg_menu_dropmethod_normal
call print_message
jr setm2
setm6
; when drop acts like a down key
ld hl,msg_menu_dropmethod_likedown
call print_message
jr setm2
setm21
; when drop acts like a mixture, quick tap will drop, otherwise
; holding the key down will act like a 'down' key
ld hl,msg_menu_dropmethod_mixture
call print_message
setm2
ld hl,msg_menu_sensitivity
call print_message
ld a,(sensitivity)
cp 0
jr z,setm10
cp 1
jr z,setm11
cp 2
jr z,setm12
jr setm13 ; this line should not be called, here just in case!
setm10
; sensitivity is 0, fast
ld hl, msg_menu_sensitivity_fast
call print_message
jr setm13
setm11
; sensitivity is 1, normal
ld hl, msg_menu_sensitivity_normal
call print_message
jr setm13
setm12
; sensitivity is 2, slow
ld hl, msg_menu_sensitivity_slow
call print_message
setm13
; print the simultaneous keys message
ld hl, msg_menu_simultaneous
call print_message
ld a,(keypressmask)
cp 0
jr z,setm30
cp 255
jr z,setm31
jr setm32 ; this line should not be called, here just in case!
setm30
ld hl, msg_menu_simultaneous_off
call print_message
jr setm32
setm31
ld hl, msg_menu_simultaneous_on
call print_message
setm32
; print the back to main menu message
ld hl, msg_menu_back_to_main_menu
call print_message
call mediumdelay
setm9
; if kempston is active, we check for up, down and fire
ld a,(kemsptonactivated)
cp 2
jp z, smkey1
call drawarrow
smjoy1
; kempston is available
ld bc,31
in a,(c)
and 31 ; bitmask 5 bits
or 0
jr nz, smjoy2
jp smkey1 ; no joystick action
smjoy2
ld bc,31
in a,(c) ; read input.
and 8 ; check "up" bit.
jr nz,smjoy3 ; move up.
jr smjoy4
smjoy3
; move arrow up if possible
; if settingsmenuoptionpointer is 0 then cannot move up
ld a,(settingsmenuoptionpointer)
or 0
jp z, smkey1 ; at top option already, jump to key read section as nothing more to do in joystick section
; possible to move up, so decrement settingsmenuoptionpointer and arrowxpos
xor a
ld (arrowcolour),a
call drawarrow ; erase old arrow
ld hl,settingsmenuoptionpointer
dec (hl)
ld hl, arrowxpos
dec (hl)
ld a,2
ld (arrowcolour),a
call drawarrow
call smalldelay
jr smkey1 ; finished in joystick read section
smjoy4
ld bc,31
in a,(c) ; read input.
and 4 ; check "down" bit.
jr nz,smjoy5
jr smjoy6
smjoy5
; move arrow down if possible
; if settingsmenuoptionpointer is 4 then cannot move down
ld a,(settingsmenuoptionpointer)
cp 4
jr z, smkey1 ; at bottom option already, jump to key read section as nothing more to do in joystick section
; possible to move down, so increment settingsmenuoptionpointer and arrowxpos
xor a
ld (arrowcolour),a
call drawarrow ; erase old arrow
ld hl,settingsmenuoptionpointer
inc (hl)
ld hl, arrowxpos
inc (hl)
ld a,2
ld (arrowcolour),a
call drawarrow
call smalldelay
jr smkey1 ; finished in joystick read section
smjoy6
ld bc,31
in a,(c) ; read input.
and 16 ; try the fire bit.
jr nz,smjoy7 ; fire pressed.
jr smkey1
smjoy7
; fire button pressed
ld a,(settingsmenuoptionpointer)
cp 1
jr nz, smjoy8
; the key read routine actually sets all the bits to 1 except the key corresponding to key pressed
ld a,29 ; 11101
ld (settingsmenuoptionchosen),a
jr setm24
smjoy8
cp 2
jr nz, smjoy9
ld a,27 ; 11011
ld (settingsmenuoptionchosen),a
jr setm24
smjoy9
cp 3
jr nz, smjoy10
ld a,23 ;10111
ld (settingsmenuoptionchosen),a
jr setm24
smjoy10
cp 4
jr nz, smjoy11
ld a,15 ;01111
ld (settingsmenuoptionchosen),a
jr setm24
smjoy11
; assume it is difficulty
ld a,30 ;11110
ld (settingsmenuoptionchosen),a
jr setm24
smkey1
;IN 63486 reads the half row 1 to 5
ld bc,63486
in a,(c)
ld (settingsmenuoptionchosen), a
setm24
ld a, (settingsmenuoptionchosen)
bit 0,a ; check for keypress of number 1 - difficulty
jr nz,setm4
ld a,(difficulty)
cp 0
jr nz,setm3
; difficulty is currently 0 (normal), set to 1
ld a,1
ld (difficulty),a
ld hl,msg_menu_difficulty_hard
call print_message
call mediumdelay
jp setm19
setm3
; difficulty is currently 1 (hard), set to 0
xor a
ld (difficulty),a
ld hl,msg_menu_difficulty_normal
call print_message
call mediumdelay
jp setm19
setm4
ld a, (settingsmenuoptionchosen)
bit 1,a ; check for keypress of number 2 - drop method
jr nz,setm7
ld a,(dropmethod)
cp 1
jr z,setm8 ; currently acts like down key
cp 2
jr z,setm23
setm22
; drop method is currently 0 (normal), set to 1
ld a,1
ld (dropmethod),a
ld hl,msg_menu_dropmethod_likedown
call print_message