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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
|
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2005 Eli Sherer
*
* Heavily modified for embedded use by Björn Stenberg (bjorn@haxx.se)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include "plugin.h"
#include "lib/display_text.h"
#include "lib/helper.h"
#include "lib/highscore.h"
#include "lib/playback_control.h"
#include "lib/playergfx.h"
PLUGIN_HEADER
#if (CONFIG_KEYPAD == IPOD_4G_PAD) || \
(CONFIG_KEYPAD == IPOD_3G_PAD) || \
(CONFIG_KEYPAD == IPOD_1G2G_PAD)
#define ROCKBLOX_OFF (BUTTON_MENU | BUTTON_SELECT)
#define ROCKBLOX_ROTATE_RIGHT BUTTON_SCROLL_BACK
#define ROCKBLOX_ROTATE_RIGHT2 (BUTTON_MENU | BUTTON_REL)
#define ROCKBLOX_ROTATE_LEFT BUTTON_SCROLL_FWD
#define ROCKBLOX_LEFT BUTTON_LEFT
#define ROCKBLOX_RIGHT BUTTON_RIGHT
#define ROCKBLOX_DOWN BUTTON_PLAY
#define ROCKBLOX_RESTART (BUTTON_SELECT | BUTTON_PLAY)
#define ROCKBLOX_DROP (BUTTON_SELECT | BUTTON_REL)
#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
(CONFIG_KEYPAD == IRIVER_H300_PAD)
#define ROCKBLOX_OFF BUTTON_OFF
#define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
#define ROCKBLOX_ROTATE_LEFT BUTTON_SELECT
#define ROCKBLOX_DOWN BUTTON_DOWN
#define ROCKBLOX_LEFT BUTTON_LEFT
#define ROCKBLOX_RIGHT BUTTON_RIGHT
#define ROCKBLOX_DROP BUTTON_MODE
#define ROCKBLOX_RESTART BUTTON_ON
#define ROCKBLOX_RC_OFF BUTTON_RC_STOP
#elif CONFIG_KEYPAD == RECORDER_PAD
#define ROCKBLOX_OFF BUTTON_OFF
#define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
#define ROCKBLOX_ROTATE_LEFT BUTTON_PLAY
#define ROCKBLOX_DOWN BUTTON_DOWN
#define ROCKBLOX_LEFT BUTTON_LEFT
#define ROCKBLOX_RIGHT BUTTON_RIGHT
#define ROCKBLOX_DROP BUTTON_ON
#define ROCKBLOX_RESTART BUTTON_F1
#elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
#define ROCKBLOX_OFF BUTTON_OFF
#define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
#define ROCKBLOX_ROTATE_LEFT BUTTON_SELECT
#define ROCKBLOX_DOWN BUTTON_DOWN
#define ROCKBLOX_LEFT BUTTON_LEFT
#define ROCKBLOX_RIGHT BUTTON_RIGHT
#define ROCKBLOX_DROP BUTTON_ON
#define ROCKBLOX_RESTART BUTTON_F1
#elif CONFIG_KEYPAD == PLAYER_PAD
#define ROCKBLOX_OFF_PRE BUTTON_STOP
#define ROCKBLOX_OFF (BUTTON_STOP|BUTTON_REL)
#define ROCKBLOX_ROTATE_RIGHT BUTTON_PLAY
#define ROCKBLOX_ROTATE_LEFT (BUTTON_ON|BUTTON_PLAY)
#define ROCKBLOX_DOWN BUTTON_MENU
#define ROCKBLOX_LEFT BUTTON_LEFT
#define ROCKBLOX_RIGHT BUTTON_RIGHT
#define ROCKBLOX_DROP_PRE BUTTON_ON
#define ROCKBLOX_DROP (BUTTON_ON|BUTTON_REL)
#define ROCKBLOX_RESTART (BUTTON_STOP|BUTTON_MENU)
#elif CONFIG_KEYPAD == ONDIO_PAD
#define ROCKBLOX_OFF_PRE BUTTON_OFF
#define ROCKBLOX_OFF (BUTTON_OFF|BUTTON_REL)
#define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
#define ROCKBLOX_ROTATE_LEFT (BUTTON_MENU|BUTTON_UP)
#define ROCKBLOX_DOWN BUTTON_DOWN
#define ROCKBLOX_LEFT BUTTON_LEFT
#define ROCKBLOX_RIGHT BUTTON_RIGHT
#define ROCKBLOX_DROP_PRE BUTTON_MENU
#define ROCKBLOX_DROP (BUTTON_MENU|BUTTON_REL)
#define ROCKBLOX_RESTART (BUTTON_OFF|BUTTON_MENU)
#elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
#define ROCKBLOX_OFF BUTTON_POWER
#define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
#define ROCKBLOX_ROTATE_LEFT BUTTON_SELECT
#define ROCKBLOX_DOWN BUTTON_DOWN
#define ROCKBLOX_LEFT BUTTON_LEFT
#define ROCKBLOX_RIGHT BUTTON_RIGHT
#define ROCKBLOX_DROP BUTTON_REC
#define ROCKBLOX_RESTART BUTTON_PLAY
#elif CONFIG_KEYPAD == SANSA_E200_PAD
#define ROCKBLOX_OFF BUTTON_POWER
#define ROCKBLOX_ROTATE_RIGHT BUTTON_SCROLL_BACK
#define ROCKBLOX_ROTATE_RIGHT2 BUTTON_UP
#define ROCKBLOX_ROTATE_LEFT BUTTON_SCROLL_FWD
#define ROCKBLOX_DOWN BUTTON_DOWN
#define ROCKBLOX_LEFT BUTTON_LEFT
#define ROCKBLOX_RIGHT BUTTON_RIGHT
#define ROCKBLOX_DROP BUTTON_SELECT
#define ROCKBLOX_RESTART BUTTON_REC
#elif CONFIG_KEYPAD == SANSA_FUZE_PAD
#define ROCKBLOX_OFF (BUTTON_HOME|BUTTON_REPEAT)
#define ROCKBLOX_ROTATE_RIGHT BUTTON_SCROLL_BACK
#define ROCKBLOX_ROTATE_RIGHT2 BUTTON_UP
#define ROCKBLOX_ROTATE_LEFT BUTTON_SCROLL_FWD
#define ROCKBLOX_DOWN BUTTON_DOWN
#define ROCKBLOX_LEFT BUTTON_LEFT
#define ROCKBLOX_RIGHT BUTTON_RIGHT
#define ROCKBLOX_DROP (BUTTON_SELECT | BUTTON_REL)
#define ROCKBLOX_RESTART (BUTTON_SELECT | BUTTON_UP)
#elif CONFIG_KEYPAD == SANSA_C200_PAD
#define ROCKBLOX_OFF BUTTON_POWER
#define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
#define ROCKBLOX_ROTATE_RIGHT2 BUTTON_VOL_DOWN
#define ROCKBLOX_ROTATE_LEFT BUTTON_VOL_UP
#define ROCKBLOX_DOWN BUTTON_DOWN
#define ROCKBLOX_LEFT BUTTON_LEFT
#define ROCKBLOX_RIGHT BUTTON_RIGHT
#define ROCKBLOX_DROP BUTTON_SELECT
#define ROCKBLOX_RESTART BUTTON_REC
#elif CONFIG_KEYPAD == SANSA_CLIP_PAD
#define ROCKBLOX_OFF BUTTON_POWER
#define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
#define ROCKBLOX_ROTATE_RIGHT2 BUTTON_VOL_DOWN
#define ROCKBLOX_ROTATE_LEFT BUTTON_VOL_UP
#define ROCKBLOX_DOWN BUTTON_DOWN
#define ROCKBLOX_LEFT BUTTON_LEFT
#define ROCKBLOX_RIGHT BUTTON_RIGHT
#define ROCKBLOX_DROP BUTTON_SELECT
#define ROCKBLOX_RESTART BUTTON_HOME
#elif CONFIG_KEYPAD == SANSA_M200_PAD
#define ROCKBLOX_OFF BUTTON_POWER
#define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
#define ROCKBLOX_ROTATE_RIGHT2 BUTTON_VOL_DOWN
#define ROCKBLOX_ROTATE_LEFT BUTTON_VOL_UP
#define ROCKBLOX_DOWN BUTTON_DOWN
#define ROCKBLOX_LEFT BUTTON_LEFT
#define ROCKBLOX_RIGHT BUTTON_RIGHT
#define ROCKBLOX_RESTART (BUTTON_SELECT | BUTTON_UP)
#define ROCKBLOX_DROP (BUTTON_SELECT | BUTTON_REL)
#elif CONFIG_KEYPAD == IRIVER_H10_PAD
#define ROCKBLOX_OFF BUTTON_POWER
#define ROCKBLOX_ROTATE_RIGHT BUTTON_SCROLL_UP
#define ROCKBLOX_ROTATE_LEFT BUTTON_REW
#define ROCKBLOX_DOWN BUTTON_SCROLL_DOWN
#define ROCKBLOX_LEFT BUTTON_LEFT
#define ROCKBLOX_RIGHT BUTTON_RIGHT
#define ROCKBLOX_DROP BUTTON_FF
#define ROCKBLOX_RESTART BUTTON_PLAY
#elif CONFIG_KEYPAD == GIGABEAT_PAD
#define ROCKBLOX_OFF BUTTON_POWER
#define ROCKBLOX_ROTATE_RIGHT BUTTON_VOL_DOWN
#define ROCKBLOX_ROTATE_LEFT BUTTON_VOL_UP
#define ROCKBLOX_ROTATE BUTTON_UP
#define ROCKBLOX_DOWN BUTTON_DOWN
#define ROCKBLOX_LEFT BUTTON_LEFT
#define ROCKBLOX_RIGHT BUTTON_RIGHT
#define ROCKBLOX_DROP BUTTON_SELECT
#define ROCKBLOX_RESTART BUTTON_A
#elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
#define ROCKBLOX_OFF BUTTON_PLAY
#define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
#define ROCKBLOX_ROTATE_LEFT BUTTON_SELECT
#define ROCKBLOX_DOWN BUTTON_DOWN
#define ROCKBLOX_LEFT BUTTON_LEFT
#define ROCKBLOX_RIGHT BUTTON_RIGHT
#define ROCKBLOX_DROP BUTTON_MODE
#define ROCKBLOX_RESTART BUTTON_EQ
#elif CONFIG_KEYPAD == MROBE500_PAD
#define ROCKBLOX_OFF BUTTON_POWER
#elif CONFIG_KEYPAD == GIGABEAT_S_PAD
#define ROCKBLOX_OFF BUTTON_BACK
#define ROCKBLOX_ROTATE_RIGHT BUTTON_VOL_DOWN
#define ROCKBLOX_ROTATE_LEFT BUTTON_VOL_UP
#define ROCKBLOX_ROTATE BUTTON_UP
#define ROCKBLOX_DOWN BUTTON_DOWN
#define ROCKBLOX_LEFT BUTTON_LEFT
#define ROCKBLOX_RIGHT BUTTON_RIGHT
#define ROCKBLOX_DROP BUTTON_SELECT
#define ROCKBLOX_RESTART BUTTON_PLAY
#elif CONFIG_KEYPAD == MROBE100_PAD
#define ROCKBLOX_OFF BUTTON_POWER
#define ROCKBLOX_ROTATE_RIGHT BUTTON_MENU
#define ROCKBLOX_ROTATE_LEFT BUTTON_PLAY
#define ROCKBLOX_ROTATE BUTTON_UP
#define ROCKBLOX_DOWN BUTTON_DOWN
#define ROCKBLOX_LEFT BUTTON_LEFT
#define ROCKBLOX_RIGHT BUTTON_RIGHT
#define ROCKBLOX_DROP BUTTON_SELECT
#define ROCKBLOX_RESTART BUTTON_DISPLAY
#elif CONFIG_KEYPAD == IAUDIO_M3_PAD
#define ROCKBLOX_OFF BUTTON_RC_REC
#define ROCKBLOX_ROTATE_RIGHT BUTTON_RC_VOL_DOWN
#define ROCKBLOX_ROTATE_LEFT BUTTON_RC_VOL_UP
#define ROCKBLOX_DOWN BUTTON_RC_MENU
#define ROCKBLOX_LEFT BUTTON_RC_REW
#define ROCKBLOX_RIGHT BUTTON_RC_FF
#define ROCKBLOX_DROP BUTTON_RC_PLAY
#define ROCKBLOX_RESTART BUTTON_RC_MODE
#elif CONFIG_KEYPAD == COWOND2_PAD
#define ROCKBLOX_OFF BUTTON_POWER
#define ROCKBLOX_RESTART BUTTON_MENU
#elif CONFIG_KEYPAD == IAUDIO67_PAD
#define ROCKBLOX_OFF BUTTON_POWER
#define ROCKBLOX_ROTATE_RIGHT BUTTON_VOLDOWN
#define ROCKBLOX_ROTATE_LEFT BUTTON_VOLUP
#define ROCKBLOX_DOWN BUTTON_STOP
#define ROCKBLOX_LEFT BUTTON_LEFT
#define ROCKBLOX_RIGHT BUTTON_RIGHT
#define ROCKBLOX_DROP BUTTON_PLAY
#define ROCKBLOX_RESTART BUTTON_MENU
#elif CONFIG_KEYPAD == CREATIVEZVM_PAD
#define ROCKBLOX_OFF BUTTON_BACK
#define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
#define ROCKBLOX_ROTATE_LEFT BUTTON_PLAY
#define ROCKBLOX_DOWN BUTTON_DOWN
#define ROCKBLOX_LEFT BUTTON_LEFT
#define ROCKBLOX_RIGHT BUTTON_RIGHT
#define ROCKBLOX_DROP BUTTON_SELECT
#define ROCKBLOX_RESTART BUTTON_CUSTOM
#elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
#define ROCKBLOX_OFF BUTTON_POWER
#define ROCKBLOX_ROTATE_RIGHT BUTTON_VOL_DOWN
#define ROCKBLOX_ROTATE_LEFT BUTTON_VOL_UP
#define ROCKBLOX_ROTATE BUTTON_UP
#define ROCKBLOX_DOWN BUTTON_DOWN
#define ROCKBLOX_LEFT BUTTON_LEFT
#define ROCKBLOX_RIGHT BUTTON_RIGHT
#define ROCKBLOX_DROP BUTTON_SELECT
#define ROCKBLOX_RESTART BUTTON_MENU
# elif CONFIG_KEYPAD == PHILIPS_SA9200_PAD
#define ROCKBLOX_OFF BUTTON_POWER
#define ROCKBLOX_ROTATE_RIGHT BUTTON_VOL_DOWN
#define ROCKBLOX_ROTATE_LEFT BUTTON_VOL_UP
#define ROCKBLOX_ROTATE BUTTON_UP
#define ROCKBLOX_DOWN BUTTON_DOWN
#define ROCKBLOX_LEFT BUTTON_PREV
#define ROCKBLOX_RIGHT BUTTON_NEXT
#define ROCKBLOX_DROP BUTTON_PLAY
#define ROCKBLOX_RESTART BUTTON_MENU
#elif CONFIG_KEYPAD == ONDAVX747_PAD
#define ROCKBLOX_OFF BUTTON_POWER
#define ROCKBLOX_RESTART BUTTON_MENU
#elif CONFIG_KEYPAD == ONDAVX777_PAD
#define ROCKBLOX_OFF BUTTON_POWER
#elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
#define ROCKBLOX_OFF (BUTTON_REC|BUTTON_PLAY)
#define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
#define ROCKBLOX_ROTATE_LEFT BUTTON_DOWN
#define ROCKBLOX_DOWN BUTTON_REW
#define ROCKBLOX_LEFT BUTTON_LEFT
#define ROCKBLOX_RIGHT BUTTON_RIGHT
#define ROCKBLOX_DROP BUTTON_FFWD
#define ROCKBLOX_RESTART (BUTTON_REC|BUTTON_REW)
#else
#error No keymap defined!
#endif
#ifdef HAVE_TOUCHSCREEN
#ifndef ROCKBLOX_OFF
#define ROCKBLOX_OFF BUTTON_TOPLEFT
#endif
#ifndef ROCKBLOX_ROTATE_RIGHT
#define ROCKBLOX_ROTATE_RIGHT BUTTON_BOTTOMRIGHT
#endif
#ifndef ROCKBLOX_ROTATE_LEFT
#define ROCKBLOX_ROTATE_LEFT BUTTON_BOTTOMLEFT
#endif
#ifndef ROCKBLOX_DOWN
#define ROCKBLOX_DOWN BUTTON_BOTTOMMIDDLE
#endif
#ifndef ROCKBLOX_LEFT
#define ROCKBLOX_LEFT BUTTON_MIDLEFT
#endif
#ifndef ROCKBLOX_RIGHT
#define ROCKBLOX_RIGHT BUTTON_MIDRIGHT
#endif
#ifndef ROCKBLOX_DROP
#define ROCKBLOX_DROP BUTTON_CENTER
#endif
#ifndef ROCKBLOX_RESTART
#define ROCKBLOX_RESTART BUTTON_TOPRIGHT
#endif
#endif
#define BLOCKS_NUM 7
#define EMPTY_BLOCK 7
#define BOARD_WIDTH 10
#ifdef HAVE_LCD_BITMAP
#define BOARD_HEIGHT 20
#if (LCD_WIDTH == 640) && (LCD_HEIGHT == 480)
#define BLOCK_WIDTH 24
#define BLOCK_HEIGHT 24
#define BOARD_X 172
#define BOARD_Y 0
#define PREVIEW_X 24
#define PREVIEW_Y 22
#define LABEL_X 482
#define SCORE_Y 50
#define LEVEL_Y 140
#define LINES_Y 210
#elif (LCD_WIDTH == 480) && (LCD_HEIGHT == 640)
#define BLOCK_WIDTH 30
#define BLOCK_HEIGHT 30
#define BOARD_X 14
#define BOARD_Y 2
#define PREVIEW_X 342
#define PREVIEW_Y 482
#define LABEL_X 344
#define SCORE_Y 58
#define LEVEL_Y 142
#define LINES_Y 218
#elif (LCD_WIDTH == 320) && (LCD_HEIGHT == 240)
#define BLOCK_WIDTH 12
#define BLOCK_HEIGHT 12
#define BOARD_X 86
#define BOARD_Y 0
#define PREVIEW_X 12
#define PREVIEW_Y 11
#define LABEL_X 242
#define SCORE_Y 25
#define LEVEL_Y 70
#define LINES_Y 105
#elif (LCD_WIDTH == 240) && ((LCD_HEIGHT == 320) || (LCD_HEIGHT == 400))
#define BLOCK_WIDTH 15
#define BLOCK_HEIGHT 15
#define BOARD_X 7
#define BOARD_Y 1
#define PREVIEW_X 171
#define PREVIEW_Y 241
#define LABEL_X 172
#define SCORE_Y 29
#define LEVEL_Y 71
#define LINES_Y 109
#define HIGH_LABEL_X 172
#define HIGH_SCORE_Y 163
#define HIGH_LEVEL_Y 172
#elif (LCD_WIDTH == 220) && (LCD_HEIGHT == 176)
#define BLOCK_WIDTH 8
#define BLOCK_HEIGHT 8
#define BOARD_X 27
#define BOARD_Y 5
#define PREVIEW_X 158
#define PREVIEW_Y 130
#define LABEL_X 147
#define SCORE_Y 20
#define LEVEL_Y 65
#define LINES_Y 100
#elif (LCD_WIDTH == 176) && (LCD_HEIGHT == 132)
#define BLOCK_WIDTH 6
#define BLOCK_HEIGHT 6
#define BOARD_X 25
#define BOARD_Y 1
#define PREVIEW_X 126
#define PREVIEW_Y 102
#define LABEL_X 112
#define SCORE_Y 17
#define LEVEL_Y 49
#define LINES_Y 81
#elif (LCD_WIDTH == 176) && (LCD_HEIGHT == 220)
/* no room for the space in the highscore list */
#define _SPACE ""
#define BLOCK_WIDTH 10
#define BLOCK_HEIGHT 10
#define BOARD_X 6
#define BOARD_Y 10
#define PREVIEW_X 124
#define PREVIEW_Y 174
#define LABEL_X 117
#define SCORE_Y 18
#define LEVEL_Y 52
#define LINES_Y 85
#define HIGH_SCORE_Y 119
#define HIGH_LEVEL_Y 126
#define HIGH_LABEL_X 114
#elif (LCD_WIDTH == 160) && (LCD_HEIGHT == 128)
#define BLOCK_WIDTH 6
#define BLOCK_HEIGHT 6
#define BOARD_X 22
#define BOARD_Y 3
#define PREVIEW_X 114
#define PREVIEW_Y 100
#define LABEL_X 101
#define SCORE_Y 17
#define LEVEL_Y 49
#define LINES_Y 82
#elif (LCD_WIDTH == 138) && (LCD_HEIGHT == 110)
#define BLOCK_WIDTH 5
#define BLOCK_HEIGHT 5
#define BOARD_X 14
#define BOARD_Y 0
#define PREVIEW_X 98
#define PREVIEW_Y 88
#define LABEL_X 80
#define SCORE_Y 15
#define LEVEL_Y 45
#define LINES_Y 74
#elif (LCD_WIDTH == 132) && (LCD_HEIGHT == 80)
#define BLOCK_WIDTH 4
#define BLOCK_HEIGHT 4
#define BOARD_X 10
#define BOARD_Y 0
#define PREVIEW_X 89
#define PREVIEW_Y 61
#define LABEL_X 78
#define SCORE_Y 10
#define LEVEL_Y 30
#define LINES_Y 50
#elif (LCD_WIDTH == 128) && (LCD_HEIGHT == 128)
#define BLOCK_WIDTH 6
#define BLOCK_HEIGHT 6
#define BOARD_X 4
#define BOARD_Y 3
#define PREVIEW_X 84
#define PREVIEW_Y 100
#define LABEL_X 71
#define SCORE_Y 17
#define LEVEL_Y 49
#define LINES_Y 82
/* NOTE: This is for the GoGear SA9200 and is only
temporary until I can get better coordinates! */
#elif (LCD_WIDTH == 128) && (LCD_HEIGHT == 160)
#define BLOCK_WIDTH 6
#define BLOCK_HEIGHT 6
#define BOARD_X 4
#define BOARD_Y 3
#define PREVIEW_X 84
#define PREVIEW_Y 100
#define LABEL_X 71
#define SCORE_Y 17
#define LEVEL_Y 49
#define LINES_Y 82
#elif (LCD_WIDTH == 128) && (LCD_HEIGHT == 96)
#define BLOCK_WIDTH 4
#define BLOCK_HEIGHT 4
#define BOARD_X 14
#define BOARD_Y 2
#define PREVIEW_X 89
#define PREVIEW_Y 76
#define LABEL_X 70
#define SCORE_Y 14
#define LEVEL_Y 39
#define LINES_Y 64
#elif (LCD_WIDTH == 128) && (LCD_HEIGHT == 64)
#define BLOCK_WIDTH 3
#define BLOCK_HEIGHT 3
#define BOARD_X 9
#define BOARD_Y 3
#define PREVIEW_X 53
#define PREVIEW_Y 5
#define LABEL_X 70
#define SCORE_Y 32
#define LEVEL_Y 13
#define LINES_Y 51
#elif (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
#define BLOCK_WIDTH 4
#define BLOCK_HEIGHT 3
#define BOARD_X 9
#define BOARD_Y 3
#define PREVIEW_X 59
#define PREVIEW_Y 5
#define LABEL_X 59
#define SCORE_Y 32
#define LEVEL_Y 13
#define LEVEL_X 78
#define LINES_Y 51
#endif
#ifndef LEVEL_X
#define LEVEL_X LABEL_X
#endif
#ifndef LINES_X
#define LINES_X LABEL_X
#endif
#define MYLCD(fn) rb->lcd_ ## fn
extern const fb_data rockblox_background[];
#else /* HAVE_LCD_CHARCELLS */
#define BOARD_HEIGHT 14
#define BLOCK_WIDTH 1
#define BLOCK_HEIGHT 1
#define BOARD_X 5
#define BOARD_Y 0
#define PREVIEW_X 15
#define PREVIEW_Y 1
#define MYLCD(fn) pgfx_ ## fn
#endif
#ifndef _SPACE
#define _SPACE " "
#endif
/* <<Explanation on Rockblox shapes>>
%%
%% - O has 1 orientation
%% %
%% %% - Z has 2 orientations
%
%% %
%% %% - S has 2 orientations
%
%
%
% %%%% - I has 2 orientations
%
% %%
% % % %%% - L has 4 orientations
%% %%% % %
% %%
% % % %%% - J has 4 orientations
%% %%% % %
% % %%%
%% % %% % - T has 4 orientations
% %%% %
*/
/* c=current f=figure o=orientation n=next */
static struct _rockblox_status
{
int gameover;
int lines;
int level;
int score;
int cx;
int cy;
int cf;
int co;
int nf;
short board[BOARD_HEIGHT][BOARD_WIDTH]; /* 20 rows of 10 blocks */
} rockblox_status;
/* prototypes */
static void draw_next_block(void);
static void new_block(void);
#ifdef HAVE_SCROLLWHEEL
int wheel_events = 0, last_wheel_event = 0;
bool wheel_enabled = false;
#endif
static const short scoring[4] = { /* scoring for each number of lines */
#if BOARD_HEIGHT == 20
40 /* single */ , 100 /* double */ , 300 /* triple */ , 1200 /* rockblox */
#elif BOARD_HEIGHT == 14 /* Player special values */
60 /* single */ , 150 /* double */ , 500 /* triple */ , 2000 /* rockblox */
#endif
};
struct figure
{
#if LCD_DEPTH >= 2
unsigned short color[3]; /* color of figure (light,middle,shadow) */
#endif
unsigned short max_or; /* max orientations */
signed short shapeX[4], shapeY[4]; /* implementation of figures */
}
/* array of figures */
figures[BLOCKS_NUM] = {
/* O */
{
#if LCD_DEPTH >= 16
{LCD_RGBPACK (153, 255, 255), LCD_RGBPACK(0, 255, 255),
LCD_RGBPACK(0,153,153)},
#elif LCD_DEPTH == 2
{LCD_WHITE, LCD_LIGHTGRAY, LCD_DARKGRAY},
#endif
1,
{-1, 0, -1, 0},
{0, 0, 1, 1}
},
/* I */
{
#if LCD_DEPTH >= 16
{LCD_RGBPACK (255, 153, 128), LCD_RGBPACK (255, 0, 0),
LCD_RGBPACK (153, 0, 0)},
#elif LCD_DEPTH == 2
{LCD_WHITE, LCD_LIGHTGRAY, LCD_DARKGRAY},
#endif
2,
{-2, -1, 0, 1},
{0, 0, 0, 0}
},
/* 'Z' */
{
#if LCD_DEPTH >= 16
{LCD_RGBPACK (153, 255, 153), LCD_RGBPACK (0, 255, 0),
LCD_RGBPACK (0, 153, 0)},
#elif LCD_DEPTH == 2
{LCD_WHITE, LCD_LIGHTGRAY, LCD_DARKGRAY},
#endif
2,
{0, 1, -1, 0},
{0, 0, 1, 1}
},
/* 'S' */
{
#if LCD_DEPTH >= 16
{LCD_RGBPACK (153, 153, 255), LCD_RGBPACK (0, 0, 255),
LCD_RGBPACK (0, 0, 153)},
#elif LCD_DEPTH == 2
{LCD_WHITE, LCD_LIGHTGRAY, LCD_DARKGRAY},
#endif
2,
{-1, 0, 0, 1},
{0, 0, 1, 1}
},
/* 'L' */
{
#if LCD_DEPTH >= 16
{LCD_RGBPACK (255, 255, 153), LCD_RGBPACK (255, 255, 0),
LCD_RGBPACK (153, 153, 0)},
#elif LCD_DEPTH == 2
{LCD_WHITE, LCD_LIGHTGRAY, LCD_DARKGRAY},
#endif
4,
{-1, 0, 1, 1},
{0, 0, 0, 1}
},
/* 'J' */
{
#if LCD_DEPTH >= 16
{LCD_RGBPACK (255, 153, 255), LCD_RGBPACK (255, 0, 255),
LCD_RGBPACK (153, 0, 153)},
#elif LCD_DEPTH == 2
{LCD_WHITE, LCD_LIGHTGRAY, LCD_DARKGRAY},
#endif
4,
{-1, 0, 1, -1},
{0, 0, 0, 1}
},
/* 'T' */
{
#if LCD_DEPTH >= 16
{LCD_RGBPACK (204, 204, 204), LCD_RGBPACK (153, 153, 153),
LCD_RGBPACK (85, 85, 85)},
#elif LCD_DEPTH == 2
{LCD_WHITE, LCD_LIGHTGRAY, LCD_DARKGRAY},
#endif
4,
{-1, 0, 1, 0},
{0, 0, 0, 1}
}
};
bool resume = false;
bool resume_file = false;
/* Rockbox File System only supports full filenames inc dir */
#define HIGH_SCORE PLUGIN_GAMES_DIR "/rockblox.score"
#define RESUME_FILE PLUGIN_GAMES_DIR "/rockblox.resume"
#define MAX_HIGH_SCORES 5
/* Default High Scores... */
struct highscore highest[MAX_HIGH_SCORES];
/* get random number from (0) to (range-1) */
static int t_rand (int range)
{
return rb->rand () % range;
}
static inline void show_game_over (void)
{
rb->splash(HZ,"Game over!");
}
/* init the board array to have no blocks */
static void init_board (void)
{
int i, j;
for (i = 0; i < BOARD_WIDTH; i++)
for (j = 0; j < BOARD_HEIGHT; j++)
rockblox_status.board[j][i] = EMPTY_BLOCK;
}
/* show the score, level and lines */
static void show_details (void)
{
char str[25]; /* for strings */
#ifdef HAVE_LCD_BITMAP
#if LCD_DEPTH >= 2
rb->lcd_set_foreground (LCD_BLACK);
rb->lcd_set_background (LCD_WHITE);
#endif
rb->snprintf (str, sizeof (str), "%d", rockblox_status.score);
rb->lcd_putsxy (LABEL_X, SCORE_Y, str);
rb->snprintf (str, sizeof (str), "%d", rockblox_status.level);
rb->lcd_putsxy (LEVEL_X, LEVEL_Y, str);
rb->snprintf (str, sizeof (str), "%d", rockblox_status.lines);
rb->lcd_putsxy (LINES_X, LINES_Y, str);
#else /* HAVE_LCD_CHARCELLS */
rb->snprintf (str, sizeof (str), "L%d/%d", rockblox_status.level,
rockblox_status.lines);
rb->lcd_puts (5, 0, str);
rb->snprintf (str, sizeof (str), "S%d", rockblox_status.score);
rb->lcd_puts (5, 1, str);
#endif
}
#ifdef HIGH_SCORE_Y
static void show_highscores (void)
{
int i;
char str[25]; /* for strings */
for (i = 0; i<MAX_HIGH_SCORES; i++)
{
rb->snprintf (str, sizeof (str), "%06d" _SPACE "L%1d",
highest[i].score, highest[i].level);
rb->lcd_putsxy (HIGH_LABEL_X, HIGH_SCORE_Y + (10 * i), str);
}
}
#endif
static void load_game(void)
{
int fd;
resume = false;
fd = rb->open(RESUME_FILE, O_RDONLY);
if (fd < 0) return;
if (rb->read(fd, &rockblox_status, sizeof(struct _rockblox_status))
< (ssize_t)sizeof(struct _rockblox_status))
{
rb->splash(HZ/2, "Loading Rockblox resume info failed");
return;
} else {
resume = true;
}
rb->close(fd);
return;
}
static void dump_resume(void)
{
int fd;
fd = rb->open(RESUME_FILE, O_WRONLY|O_CREAT);
if (fd < 0)
goto fail;
if (rb->write(fd, &rockblox_status, sizeof(struct _rockblox_status))
<= 0)
{
rb->close(fd);
goto fail;
}
rb->close(fd);
return;
fail:
rb->splash(HZ/2, "Writing Rockblox resume info failed");
return;
}
static void init_rockblox (bool resume)
{
char score_name[50];
struct tm* tm;
tm = rb->get_time();
rb->snprintf(score_name, sizeof(score_name), "%04d%02d%02d %02d%02d%02d",
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec);
#ifdef HAVE_LCD_BITMAP
rb->lcd_bitmap (rockblox_background, 0, 0, LCD_WIDTH, LCD_HEIGHT);
#else /* HAVE_LCD_CHARCELLS */
pgfx_display (0, 0);
pgfx_display_block (3, 0, 3, 1);
pgfx_display_block (4, 0, 3, 0);
pgfx_clear_display();
pgfx_fillrect (3, 0, 2, 14);
pgfx_fillrect (15, 7, 2, 7);
pgfx_update();
#endif
if (!resume)
{
rockblox_status.level = 1;
rockblox_status.lines = 0;
rockblox_status.score = 0;
rockblox_status.nf = t_rand(BLOCKS_NUM);
init_board ();
new_block ();
}
draw_next_block();
show_details ();
#ifdef HIGH_SCORE_Y
show_highscores ();
#endif
}
static inline int level_speed(int level)
{
#if BOARD_HEIGHT == 20
return (5*HZ) / (level + 9);
#elif BOARD_HEIGHT == 14
return (7*HZ) / (level + 9);
#endif
}
static int getRelativeX (int figure, int square, int orientation)
{
switch (orientation) {
case 0:
return figures[figure].shapeX[square];
case 1:
return figures[figure].shapeY[square];
case 2:
return -figures[figure].shapeX[square];
case 3:
return -figures[figure].shapeY[square];
default:
return 0;
}
}
static int getRelativeY (int figure, int square, int orientation)
{
switch (orientation) {
case 0:
return figures[figure].shapeY[square];
case 1:
return -figures[figure].shapeX[square];
case 2:
return -figures[figure].shapeY[square];
case 3:
return figures[figure].shapeX[square];
default:
return 0;
}
}
/* redraw the while board on the screen */
static void refresh_board (void)
{
int i, j, x, y, block;
#if LCD_DEPTH >= 2
rb->lcd_set_foreground (LCD_BLACK);
#elif LCD_DEPTH == 1
MYLCD(set_drawmode) (DRMODE_SOLID | DRMODE_INVERSEVID);
#endif
MYLCD(fillrect) (BOARD_X, BOARD_Y, BOARD_WIDTH * BLOCK_WIDTH,
BOARD_HEIGHT * BLOCK_HEIGHT);
#if LCD_DEPTH == 1
MYLCD(set_drawmode) (DRMODE_SOLID);
#endif
for (i = 0; i < BOARD_WIDTH; i++)
for (j = 0; j < BOARD_HEIGHT; j++) {
block = rockblox_status.board[j][i];
if (block != EMPTY_BLOCK) {
#ifdef HAVE_LCD_BITMAP
#if LCD_DEPTH >= 2
/* middle drawing */
rb->lcd_set_foreground (figures[block].color[1]);
#endif
rb->lcd_fillrect (BOARD_X + i * BLOCK_WIDTH,
BOARD_Y + j * BLOCK_HEIGHT,
BLOCK_WIDTH, BLOCK_HEIGHT);
#if LCD_DEPTH >= 2
/* light drawing */
rb->lcd_set_foreground (figures[block].color[0]);
#endif
rb->lcd_vline (BOARD_X + i * BLOCK_WIDTH,
BOARD_Y + j * BLOCK_HEIGHT,
BOARD_Y + (j + 1) * BLOCK_HEIGHT - 2);
rb->lcd_hline (BOARD_X + i * BLOCK_WIDTH,
BOARD_X + (i + 1) * BLOCK_WIDTH - 2,
BOARD_Y + j * BLOCK_HEIGHT);
#if LCD_DEPTH >= 2
/* shadow drawing */
rb->lcd_set_foreground (figures[block].color[2]);
#endif
rb->lcd_vline (BOARD_X + (i + 1) * BLOCK_WIDTH - 1,
BOARD_Y + j * BLOCK_HEIGHT + 1,
BOARD_Y + (j + 1) * BLOCK_HEIGHT - 1);
rb->lcd_hline (BOARD_X + i * BLOCK_WIDTH + 1,
BOARD_X + (i + 1) * BLOCK_WIDTH - 1,
BOARD_Y + (j + 1) * BLOCK_HEIGHT - 1);
#else /* HAVE_LCD_CHARCELLS */
pgfx_drawpixel (BOARD_X + i, BOARD_Y + j);
#endif
}
}
for (i = 0; i < 4; i++) {
x = getRelativeX (rockblox_status.cf, i, rockblox_status.co)
+ rockblox_status.cx;
y = getRelativeY (rockblox_status.cf, i, rockblox_status.co)
+ rockblox_status.cy;
#ifdef HAVE_LCD_BITMAP
#if LCD_DEPTH >= 2
/* middle drawing */
rb->lcd_set_foreground (figures[rockblox_status.cf].color[1]);
#endif
rb->lcd_fillrect (BOARD_X + x * BLOCK_WIDTH,
BOARD_Y + y * BLOCK_HEIGHT,
BLOCK_WIDTH, BLOCK_HEIGHT);
#if LCD_DEPTH >= 2
/* light drawing */
rb->lcd_set_foreground (figures[rockblox_status.cf].color[0]);
#endif
rb->lcd_vline (BOARD_X + x * BLOCK_WIDTH, BOARD_Y + y * BLOCK_HEIGHT,
BOARD_Y + (y + 1) * BLOCK_HEIGHT - 2);
rb->lcd_hline (BOARD_X + x * BLOCK_WIDTH,
BOARD_X + (x + 1) * BLOCK_WIDTH - 2,
BOARD_Y + y * BLOCK_HEIGHT);
#if LCD_DEPTH >= 2
/* shadow drawing */
rb->lcd_set_foreground (figures[rockblox_status.cf].color[2]);
#endif
rb->lcd_vline (BOARD_X + (x + 1) * BLOCK_WIDTH - 1,
BOARD_Y + y * BLOCK_HEIGHT + 1,
BOARD_Y + (y + 1) * BLOCK_HEIGHT - 1);
rb->lcd_hline (BOARD_X + x * BLOCK_WIDTH + 1,
BOARD_X + (x + 1) * BLOCK_WIDTH - 1,
BOARD_Y + (y + 1) * BLOCK_HEIGHT - 1);
#else /* HAVE_LCD_CHARCELLS */
pgfx_drawpixel (BOARD_X + x, BOARD_Y + y);
#endif
}
MYLCD(update) ();
}
static bool canMoveTo (int x, int y, int newOrientation)
{
int i, rx, ry;
for (i = 0; i < 4; i++) {
ry = getRelativeY (rockblox_status.cf, i, newOrientation) + y;
rx = getRelativeX (rockblox_status.cf, i, newOrientation) + x;
if ((rx < 0 || rx >= BOARD_WIDTH) ||
(ry < 0 || ry >= BOARD_HEIGHT) ||
(rockblox_status.board[ry][rx] != EMPTY_BLOCK))
return false;
}
return true;
}
/* draws the preview of next block in the preview window */
static void draw_next_block (void)
{
int i, rx, ry;
/* clear preview window first */
#if LCD_DEPTH >= 2
rb->lcd_set_foreground (LCD_BLACK);
#elif LCD_DEPTH == 1
MYLCD(set_drawmode) (DRMODE_SOLID | DRMODE_INVERSEVID);
#endif
/* 4x4 */
MYLCD(fillrect) (PREVIEW_X, PREVIEW_Y, BLOCK_WIDTH * 4, BLOCK_HEIGHT * 4);
#if LCD_DEPTH == 1
MYLCD(set_drawmode) (DRMODE_SOLID);
#endif
/* draw the lightgray rectangles */
#if LCD_DEPTH >= 16
rb->lcd_set_foreground (LCD_RGBPACK (40, 40, 40));
#elif LCD_DEPTH == 2
rb->lcd_set_foreground (LCD_DARKGRAY);
#endif
#if LCD_DEPTH >= 2
for (rx = 0; rx < 4; rx++)
for (ry = 0; ry < 4; ry++)
rb->lcd_drawrect (PREVIEW_X + rx * BLOCK_WIDTH,
PREVIEW_Y + ry * BLOCK_HEIGHT, BLOCK_WIDTH,
BLOCK_HEIGHT);
#endif
/* draw the figure */
for (i = 0; i < 4; i++) {
rx = getRelativeX (rockblox_status.nf, i, 0) + 2;
ry = getRelativeY (rockblox_status.nf, i, 0) + 2;
#ifdef HAVE_LCD_BITMAP
#if LCD_DEPTH >= 2
rb->lcd_set_foreground (figures[rockblox_status.nf].color[1]); /* middle drawing */
#endif
rb->lcd_fillrect (PREVIEW_X + rx * BLOCK_WIDTH,
PREVIEW_Y + ry * BLOCK_HEIGHT,
BLOCK_WIDTH, BLOCK_HEIGHT);
#if LCD_DEPTH >= 2
rb->lcd_set_foreground (figures[rockblox_status.nf].color[0]); /* light drawing */
#endif
rb->lcd_vline (PREVIEW_X + rx * BLOCK_WIDTH,
PREVIEW_Y + ry * BLOCK_HEIGHT,
PREVIEW_Y + (ry + 1) * BLOCK_HEIGHT - 2);
rb->lcd_hline (PREVIEW_X + rx * BLOCK_WIDTH,
PREVIEW_X + (rx + 1) * BLOCK_WIDTH - 2,
PREVIEW_Y + ry * BLOCK_HEIGHT);
#if LCD_DEPTH >= 2
rb->lcd_set_foreground (figures[rockblox_status.nf].color[2]); /* shadow drawing */
#endif
rb->lcd_vline (PREVIEW_X + (rx + 1) * BLOCK_WIDTH - 1,
PREVIEW_Y + ry * BLOCK_HEIGHT + 1,
PREVIEW_Y + (ry + 1) * BLOCK_HEIGHT - 1);
rb->lcd_hline (PREVIEW_X + rx * BLOCK_WIDTH + 1,
PREVIEW_X + (rx + 1) * BLOCK_WIDTH - 1,
PREVIEW_Y + (ry + 1) * BLOCK_HEIGHT - 1);
#else /* HAVE_LCD_CHARCELLS */
pgfx_drawpixel (PREVIEW_X + rx, PREVIEW_Y + ry);
#endif
}
}
/* move the block to a relative location */
static void move_block (int x, int y, int o)
{
if (canMoveTo (rockblox_status.cx + x, rockblox_status.cy + y, o)) {
rockblox_status.cy += y;
rockblox_status.cx += x;
rockblox_status.co = o;
}
}
/* try to add a new block to play with (return true if gameover) */
static void new_block (void)
{
rockblox_status.cy = 1;
rockblox_status.cx = 5;
rockblox_status.cf = rockblox_status.nf;
rockblox_status.co = 0; /* start at the same orientation all time */
rockblox_status.nf = t_rand (BLOCKS_NUM);
rockblox_status.gameover = !canMoveTo (rockblox_status.cx,
rockblox_status.cy, rockblox_status.co);
draw_next_block ();
}
/* check for filled rockblox_status.lines and do what necessary */
static int check_lines (void)
{
int i, j, y;
int rockblox = 0;
for (j = 0; j < BOARD_HEIGHT; j++) {
for (i = 0; ((i < BOARD_WIDTH) &&
(rockblox_status.board[j][i] != EMPTY_BLOCK)); i++);
if (i == BOARD_WIDTH) { /* woo hoo, we have a line */
rockblox++;
for (y = j; y > 0; y--)
{
for (i = 0; i < BOARD_WIDTH; i++)
{ /* fall line */
rockblox_status.board[y][i] = rockblox_status.board[y - 1][i];
}
}
}
}
return rockblox;
}
/* moves down the figure and returns true if gameover */
static void move_down (void)
{
int l, i, rx, ry;
if (!canMoveTo (rockblox_status.cx, rockblox_status.cy + 1, rockblox_status.co)) {
/* save figure to board */
for (i = 0; i < 4; i++) {
rx = getRelativeX (rockblox_status.cf, i, rockblox_status.co) + rockblox_status.cx;
ry = getRelativeY (rockblox_status.cf, i, rockblox_status.co) + rockblox_status.cy;
rockblox_status.board[ry][rx] = rockblox_status.cf;
}
/* check if formed some lines */
l = check_lines ();
if (l) {
/* the original scoring from "http://en.wikipedia.org/wiki/Rockblox" */
rockblox_status.score += scoring[l - 1] * rockblox_status.level;
rockblox_status.lines += l;
rockblox_status.level = (int) rockblox_status.lines / 10 + 1;
}
/* show details */
show_details ();
/* generate a new figure */
new_block ();
} else
move_block (0, 1, rockblox_status.co);
}
static bool rockblox_help(void)
{
int button;
#define WORDS (sizeof help_text / sizeof (char*))
char *help_text[] = {
"Rockblox", "", "Aim", "", "Make", "the", "falling", "blocks", "of", "different",
"shapes", "form", "full", "rows.", "Whenever", "a", "row", "is", "completed,", "it",
"will", "be", "cleared", "away", "and", "you", "gain", "points."
};
static struct style_text formation[]={
{ 0, TEXT_CENTER|TEXT_UNDERLINE },
{ 2, C_RED },
{ -1, 0 }
};
#ifdef HAVE_LCD_BITMAP
rb->lcd_setfont(FONT_UI);
#endif
#ifdef HAVE_LCD_COLOR
rb->lcd_set_background(LCD_BLACK);
rb->lcd_set_foreground(LCD_WHITE);
#endif
if (display_text(WORDS, help_text, formation, NULL))
return true;
do {
button = rb->button_get(true);
if ( rb->default_event_handler( button ) == SYS_USB_CONNECTED )
return true;
} while( ( button == BUTTON_NONE )
|| ( button & (BUTTON_REL|BUTTON_REPEAT) ) );
#ifdef HAVE_LCD_BITMAP
rb->lcd_setfont(FONT_SYSFIXED);
#endif
return false;
}
static int rockblox_menu_cb(int action, const struct menu_item_ex *this_item)
{
int i = ((intptr_t)this_item);
if(action == ACTION_REQUEST_MENUITEM
&& !resume && (i==0 || i==5))
return ACTION_EXIT_MENUITEM;
return action;
}
static int rockblox_menu(void)
{
int selected = 0;
MENUITEM_STRINGLIST(main_menu, "Rockblox Menu", rockblox_menu_cb,
"Resume Game", "Start New Game",
"Help", "High Scores", "Playback Control",
"Quit without Saving", "Quit");
rb->button_clear_queue();
while (true) {
switch (rb->do_menu(&main_menu, &selected, NULL, false)) {
case 0:
if(resume_file)
rb->remove(RESUME_FILE);
init_rockblox(true);
return 0;
case 1:
init_rockblox(false);
return 0;
case 2:
if (rockblox_help())
return 1;
break;
case 3:
#ifdef HAVE_LCD_BITMAP
highscore_show(MAX_HIGH_SCORES, highest, MAX_HIGH_SCORES, true);
#else
rb->splashf(2*HZ, "High Score: %d", highest[0].score);
#endif
break;
case 4:
if (playback_control(NULL))
return 1;
break;
case 5:
return 1;
case 6:
if (resume) {
rb->splash(HZ*1, "Saving game ...");
dump_resume();
}
return 1;
case MENU_ATTACHED_USB:
return 1;
default:
return 1;
break;
}
}
}
static int rockblox_loop (void)
{
int button;
int lastbutton = BUTTON_NONE;
long next_down_tick = *rb->current_tick + level_speed(rockblox_status.level);
if (rockblox_menu()) {
return 1;
}
resume = false;
resume_file = false;
while (1) {
#ifdef HAS_BUTTON_HOLD
if (rb->button_hold ()) {
/* Turn on backlight timeout (revert to settings) */
backlight_use_settings(); /* backlight control in lib/helper.c */
rb->splash(0, "Paused");
while (rb->button_hold ())
rb->sleep(HZ/10);
/* Turn off backlight timeout */
backlight_force_on(); /* backlight control in lib/helper.c */
/* get rid of the splash text */
rb->lcd_bitmap (rockblox_background, 0, 0, LCD_WIDTH, LCD_HEIGHT);
show_details ();
#ifdef HIGH_SCORE_Y
show_highscores ();
#endif
draw_next_block ();
refresh_board ();
}
#endif
button = rb->button_get_w_tmo (MAX(next_down_tick - *rb->current_tick, 1));
switch (button) {
#ifdef ROCKBLOX_RC_OFF
case ROCKBLOX_RC_OFF:
#endif
case ROCKBLOX_OFF:
#ifdef ROCKBLOX_OFF_PRE
if (lastbutton != ROCKBLOX_OFF_PRE)
break;
#endif
resume = true;
return 0;
break;
#if defined(ROCKBLOX_ROTATE)
case ROCKBLOX_ROTATE:
#endif
case ROCKBLOX_ROTATE_RIGHT:
case ROCKBLOX_ROTATE_RIGHT | BUTTON_REPEAT:
#ifdef HAVE_SCROLLWHEEL
/* if the wheel is disabled, add an event to the stack. */
if(wheel_enabled == false)
wheel_events++;
/* if it's enabled, go ahead and rotate.. */
if(wheel_enabled)
#endif
move_block (0, 0, (rockblox_status.co + 1) % figures[rockblox_status.cf].max_or);
break;
case ROCKBLOX_ROTATE_LEFT:
case ROCKBLOX_ROTATE_LEFT | BUTTON_REPEAT:
#ifdef HAVE_SCROLLWHEEL
if(wheel_enabled == false)
wheel_events++;
if(wheel_enabled)
#endif
move_block (0, 0,
(rockblox_status.co + figures[rockblox_status.cf].max_or -
1) % figures[rockblox_status.cf].max_or);
break;
#ifdef ROCKBLOX_ROTATE_RIGHT2
case ROCKBLOX_ROTATE_RIGHT2:
move_block (0, 0, (rockblox_status.co + 1) % figures[rockblox_status.cf].max_or);
break;
#endif
case ROCKBLOX_DOWN:
case ROCKBLOX_DOWN | BUTTON_REPEAT:
move_block (0, 1, rockblox_status.co);
break;
case ROCKBLOX_RIGHT:
case ROCKBLOX_RIGHT | BUTTON_REPEAT:
move_block (1, 0, rockblox_status.co);
break;
case ROCKBLOX_LEFT:
case ROCKBLOX_LEFT | BUTTON_REPEAT:
move_block (-1, 0, rockblox_status.co);
break;
case ROCKBLOX_DROP:
#ifdef ROCKBLOX_DROP_PRE
if (lastbutton != ROCKBLOX_DROP_PRE)
break;
#endif
while (canMoveTo (rockblox_status.cx, rockblox_status.cy + 1, rockblox_status.co))
move_block (0, 1, rockblox_status.co);
break;
#ifdef ROCKBLOX_RESTART
case ROCKBLOX_RESTART:
rb->splash (HZ * 1, "Restarting...");
init_rockblox (false);
break;
#endif
default:
if (rb->default_event_handler (button) == SYS_USB_CONNECTED)
return PLUGIN_USB_CONNECTED;
break;
}
if (button != BUTTON_NONE)
lastbutton = button;
#ifdef HAVE_SCROLLWHEEL
/* check if we should enable the scroll wheel, if events
* begin to stack up... */
if(wheel_enabled == false)
{
/* stopped rotating the wheel, reset the count */
if(wheel_events == last_wheel_event)
{
last_wheel_event = 0;
wheel_events = 0;
}
/* rotated the wheel a while constantly, enable it. */
else if(wheel_events > 3)
{
wheel_enabled = true;
}
/* this evens out the last event and the "current" event.
* if we get an event next time through button reading, it will
* remain ahead of last_event. if we don't, they'll end up equaling
* each other.. thus, the scroll count will be reset. */
if(wheel_enabled == false && wheel_events > last_wheel_event)
last_wheel_event++;
}
#endif
if (TIME_AFTER(*rb->current_tick, next_down_tick)) {
move_down ();
next_down_tick += level_speed(rockblox_status.level);
if (TIME_AFTER(*rb->current_tick, next_down_tick))
/* restart time "raster" when we had to wait longer than usual
* (pause, game restart etc) */
next_down_tick = *rb->current_tick + level_speed(rockblox_status.level);
}
if (rockblox_status.gameover) {
#if LCD_DEPTH >= 2
rb->lcd_set_foreground (LCD_BLACK);
#endif
show_game_over();
resume = false;
return 0;
}
refresh_board ();
}
return 0;
}
enum plugin_status plugin_start (const void *parameter)
{
(void) parameter;
rb->srand (*rb->current_tick);
/* Load HighScore if any */
highscore_load(HIGH_SCORE, highest, MAX_HIGH_SCORES);
#if LCD_DEPTH > 1
rb->lcd_set_backdrop(NULL);
#endif
#ifdef HAVE_LCD_BITMAP
rb->lcd_setfont (FONT_SYSFIXED);
#else
if (!pgfx_init(4, 2))
{
rb->splash(HZ*2, "Old LCD :(");
return PLUGIN_OK;
}
#endif
/* Turn off backlight timeout */
backlight_force_on(); /* backlight control in lib/helper.c */
load_game();
resume_file = resume;
while(!rockblox_loop()) {
if(!resume) {
int position = highscore_update(rockblox_status.score, rockblox_status.level, "", highest,
MAX_HIGH_SCORES);
if (position == 0) {
rb->splash(HZ*2, "New High Score");
}
if (position != -1) {
#ifdef HAVE_LCD_BITMAP
highscore_show(position, highest, MAX_HIGH_SCORES, true);
#else
rb->splashf(2*HZ, "High Score: %d", highest[position].score);
#endif
}
}
}
#ifndef HAVE_LCD_BITMAP
pgfx_release();
#endif
/* Save user's HighScore */
highscore_save(HIGH_SCORE, highest, MAX_HIGH_SCORES);
backlight_use_settings(); /* backlight control in lib/helper.c */
return PLUGIN_OK;
}
|