-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoption_menu.c
2574 lines (1079 loc) · 27.7 KB
/
option_menu.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <pspkernel.h>
#include <pspctrl.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <pspiofilemgr_fcntl.h>
#include "pg.h"
#include "bce.h"
#include "colors.h"
#include "piece_bitmaps.h"
//#define FILE_BASE_DIR "ms0:/PSP/GAME/PSPCHESS"
#define FILE_BASE_DIR ""
#define MUSIC_BASE_DIR "ms0:/PSP/MUSIC"
#define FILE_SAVE_NAME "ms0:/PSP/GAME/CHESS.SAV"
//#define FILE_EXPORT_NAME "ms0:/PSP/GAME/PSPCHESS/EXPORT.PGN"
#define FILE_EXPORT_NAME "EXPORT.PGN"
//#define FILE_SAVED_OPTIONS "ms0:/PSP/GAME/PSPCHESS/PSPCHESS.INI"
#define FILE_SAVED_OPTIONS "PSPCHESS.INI"
//#define SLOT_NAME_START "ms0:/PSP/GAME/PSPCHESS/GAME"
#define SLOT_NAME_START "GAME"
#define SLOT_NAME_END ".CHS"
enum {OPTION_BOOL, OPTION_INT, OPTION_FN,
OPTION_LIST, OPTION_FILE, OPTION_STRING};
#define MAX_STORAGE_SLOT 10
#define MAGIC "CHS0"
#define MAGIC_LEN 4
int g_game_mode = GAMEMODE_NORMAL;
//int g_analysis_mode = 0;
move g_analysis_stack[MAXMOVES];
char *g_list_move_types [] ={ "OFF", "COORDINATE", "SAN", 0};
char *g_variant_names[] = {"NORMAL", "FISCHER RANDOM", "WILD 5", "WILD 8",
"WILD 8a", 0};
char *g_music_options[] = {"OFF","FILE","RANDOM", 0};
char *g_game_mode_names[] = {"NORMAL","ANALYSIS","CLIENT",0};
char g_server_password[MAX_STRING] = "password";
char g_server_username[MAX_STRING] = "guest";
char g_server_quickstring[QUICK_COUNT][MAX_STRING] = {
"match",
"accept",
"who",
"who ra",
"seek",
"sought",
"news",
"messages u",
"clearmessages",
"say hi. i am using pspChess so its hard to type",
"",
"",
"",
"",
"",
"",
"",
"say",
"whisper",
"kibitz",
};
// these functions return nonzero if we should bust back out to the main
// play loop after they are called...
int do_load_game();
int do_save_game();
int do_export();
int do_save_options();
int do_load_options();
int do_import();
int do_game_options();
int do_sound_options();
int do_display_options();
int do_server_options();
int do_server_connect();
struct option_struct {
char *text;
void *var;
int type;
void *options;
};
int generic_options_menu(struct option_struct *options, int max);
struct option_struct g_options[] =
{
{"Game Options", do_game_options, OPTION_FN},
{"Sound Options", do_sound_options, OPTION_FN},
{"Display Options", do_display_options, OPTION_FN},
{"Server Options", do_server_options, OPTION_FN},
{"Pondering", &ponder_mode, OPTION_BOOL},
{"Extra Keys", &g_process_extra_keys, OPTION_BOOL},
{"Game Mode", &g_game_mode, OPTION_LIST, g_game_mode_names},
{"Search Depth", &searchdepth, OPTION_INT},
{"Minimum Delay", &g_minimum_computer_delay, OPTION_INT},
{"Reset Game", reset_game_confirm, OPTION_FN},
{"Load Game", do_load_game, OPTION_FN},
{"Save Game", do_save_game, OPTION_FN},
{"Export PGN", do_export, OPTION_FN},
{"Import PGN", do_import, OPTION_FN},
{"Save Options", do_save_options, OPTION_FN},
{"Load Options", do_load_options, OPTION_FN},
};
char *g_music_extensions[] = {"mp3","mod","stm","s3m","mtm","669",
"ult","med","xm","it",0};
char *g_pieces_extensions[] = {"png",0};
struct option_struct g_gameplay_options[] =
{
{"WHITE", &computer[WHITE], OPTION_LIST, g_personality_names},
{"BLACK", &computer[BLACK], OPTION_LIST, g_personality_names},
{"Variant", &g_default_variant, OPTION_LIST, g_variant_names},
{"Clock (Min)", &g_default_clock, OPTION_INT},
{"Inc (Sec)", &g_default_increment, OPTION_INT},
};
struct option_struct g_sound_options[] =
{
{"Backgrnd Music", &g_music_on, OPTION_LIST, g_music_options},
{"Music File", g_background_music_file, OPTION_FILE, g_music_extensions},
};
struct option_struct g_display_options[] =
{
{"Show Thinking", &g_show_thinking, OPTION_BOOL},
{"Show Captures", &g_show_captures, OPTION_BOOL},
{"Show Moves", &g_list_moves, OPTION_LIST, g_list_move_types},
{"Show Options", &g_show_options, OPTION_BOOL},
{"Hilite Checks", &g_show_checks, OPTION_BOOL},
{"Show Available", &g_show_available_moves, OPTION_BOOL},
{"Show Threats", &g_show_threats, OPTION_BOOL},
{"Debug Info", &g_show_debug_info, OPTION_BOOL},
{"Board Flipping", &g_board_flipping, OPTION_BOOL},
{"External Pieces", &g_external_pieces, OPTION_BOOL},
{"Piece File", &g_external_pieces_file, OPTION_FILE, g_pieces_extensions},
{"Backgrnd Image", &g_background_image, OPTION_BOOL},
};
struct option_struct g_server_options[] =
{
// {"connect", do_server_connect, OPTION_FN},
{"username", g_server_username, OPTION_STRING},
{"password", g_server_password, OPTION_STRING},
{"quick 1", g_server_quickstring[0], OPTION_STRING},
{"quick 2", g_server_quickstring[1], OPTION_STRING},
{"quick 3", g_server_quickstring[2], OPTION_STRING},
{"quick 4", g_server_quickstring[3], OPTION_STRING},
{"quick 5", g_server_quickstring[4], OPTION_STRING},
{"quick 6", g_server_quickstring[5], OPTION_STRING},
{"quick 7", g_server_quickstring[6], OPTION_STRING},
{"quick 8", g_server_quickstring[7], OPTION_STRING},
{"quick 9", g_server_quickstring[8], OPTION_STRING},
{"quick 10", g_server_quickstring[9], OPTION_STRING},
{"quick 11", g_server_quickstring[10], OPTION_STRING},
{"quick 12", g_server_quickstring[11], OPTION_STRING},
{"quick 13", g_server_quickstring[12], OPTION_STRING},
{"quick 14", g_server_quickstring[13], OPTION_STRING},
{"quick 15", g_server_quickstring[14], OPTION_STRING},
{"quick 16", g_server_quickstring[15], OPTION_STRING},
{"quick 17", g_server_quickstring[16], OPTION_STRING},
{"quick 18", g_server_quickstring[17], OPTION_STRING},
{"quick 19", g_server_quickstring[18], OPTION_STRING},
{"quick 20", g_server_quickstring[19], OPTION_STRING},
};
struct option_list {
struct option_struct *options;
int count;
};
struct option_list g_options_list[] =
{
{ g_options, sizeof(g_options)/sizeof(g_options[0]) },
{ g_gameplay_options,
sizeof(g_gameplay_options)/sizeof(g_gameplay_options[0]) },
{ g_sound_options,
sizeof(g_sound_options)/sizeof(g_sound_options[0]) },
{ g_display_options,
sizeof(g_display_options)/sizeof(g_display_options[0]) },
};
void user_message_wait_key(char *message)
{
clear_screen();
pgPrintCenter(12, red, message);
pgPrintCenter(14, red, "Press any key to continue");
pgScreenFlipV();
while (Read_Key() == 0) ;
}
int do_import()
{
char pgn_file[256];
char *extensions[] = { "pgn", 0 };
int n_ext = 1;
if (user_select_file(FILE_BASE_DIR,extensions,n_ext,pgn_file))
{
import_pgn(pgn_file);
}
return 0;
}
// return 0 on failure
// return 1 on success
int load_options()
{
int i;
FILE *f = fopen(FILE_SAVED_OPTIONS,"r");
if (f)
{
int option_index;
int max_option_index=sizeof(g_options_list)/sizeof(g_options_list[0]);
char buffer[256];
clear_screen();
while (!feof(f))
{
memset(buffer,0,256);
fgets(buffer, 256, f);
char *bla = buffer;
while (*bla)
{
if (*bla == '\n')
{
*bla = 0;
break;
}
bla++;
}
for (option_index=0;option_index<max_option_index;option_index++)
{
struct option_struct *options =
g_options_list[option_index].options;
int max_i = g_options_list[option_index].count;
for (i=0;i<max_i;i++)
{
if (strstr(buffer,options[i].text))
{
// foo=bar -> point to bar
char *value_ptr = buffer+strlen(options[i].text)+1;
switch (options[i].type)
{
case OPTION_STRING:
// fall through
case OPTION_FILE:
strcpy((char*)options[i].var,value_ptr);
break;
case OPTION_LIST:
case OPTION_BOOL:
case OPTION_INT:
{
int value = atoi(value_ptr);
*(int*)(options[i].var) = value;
break;
}
}
break; /* end for loop over variables */
}
}
}
}
fclose(f);
return 1;
}
return 0;
}
int do_load_options()
{
if (load_options())
{
user_message_wait_key("options loaded");
}
else
{
flash_display("load options failed");
}
return 0;
}
int do_save_options()
{
int i;
FILE *f = fopen(FILE_SAVED_OPTIONS,"w+");
if (f)
{
int option_index;
int max_option_index =
sizeof(g_options_list)/sizeof(g_options_list[0]);
for (option_index = 0; option_index < max_option_index; option_index++)
{
struct option_struct *options =
g_options_list[option_index].options;
int max_i = g_options_list[option_index].count;
for (i=0;i<max_i;i++)
{
switch (options[i].type)
{
case OPTION_STRING:
// fall through
case OPTION_FILE:
fprintf(f,"%s=%s\n",
options[i].text,
(char *)options[i].var);
break;
case OPTION_LIST:
case OPTION_BOOL:
case OPTION_INT:
{
int option_value = *(int*)(options[i].var);
fprintf(f,"%s=%d\n",options[i].text,option_value);
break;
}
}
}
}
fclose(f);
user_message_wait_key("options saved");
}
else
{
char buffer[80];
sprintf(buffer,"opening %s failed",FILE_SAVED_OPTIONS);
flash_display(buffer);
}
return 0;
}
// slot 0 is the original save file, slot 1-9 are new name scheme
char *storage_slot_name(int slot)
{
static char buffer[80];
if (slot == 0)
{
return FILE_SAVE_NAME;
}
else
{
strcpy(buffer, SLOT_NAME_START);
strcat(buffer, itoa(slot,10));
strcat(buffer, SLOT_NAME_END);
return buffer;
}
}
int storage_slot_used(int slot)
{
return file_exists(storage_slot_name(slot));
}
int load_slot(int slot)
{
FILE *f = fopen(storage_slot_name(slot), "r");
if (f)
{
int ply_count;
int i;
fread(&ply_count, sizeof(ply_count), 1, f);
// old save style
if (ply_count>0)
{
g_default_variant = VARIANT_NORMAL;
reset_game(0);
}
else
{
char magic[MAGIC_LEN+1];
memset(magic,0,sizeof(magic));
fread(magic, MAGIC_LEN, 1, f);
if (strncmp(magic, MAGIC, MAGIC_LEN) != 0)
return 0;
if (feof(f))
return 0;
fread(board, sizeof(chessboard), 1, f);
fread(&ply_count, sizeof(ply_count), 1, f);
countmaterial();
}
move m;
for (i=0;i<ply_count;i++)
{
fread(&m, sizeof(m), 1, f);
local_domove(m, 1);
}
fclose(f);
return 1;
}
return 0;
}
void preview_slot(int slot)
{
if (load_slot(slot))
{
draw_board();
}
}
int g_cached_ply;
move g_cached_gamestack[MAXMOVES];
void cache_current_game()
{
g_cached_ply = ply;
memcpy(g_cached_gamestack,gamestack,sizeof(gamestack[0])*ply);
}
void restore_cached_game()
{
int i;
reset_game(0);
for (i=0;i<g_cached_ply;i++)
{
local_domove(g_cached_gamestack[i], 1);
}
}
int is_capture(move m)
{
return getpiece__(TO(m)) != 0;
}
enum { AMBIG_NONE, AMBIG_FILE, AMBIG_RANK, AMBIG_BOTH };
// returns AMBIG_NONE if no ambiguities
// returns AMBIG_FILE if the file is ambiguous (so use rank)
// returns AMBIG_RANK if the rank is ambiguous (so use file)
// returns AMBIG_BOTH if both rank and file could be ambiguous
int is_ambiguous(move m, int piece)
{
// keep track of conflicting moves
move amb[9];
move_and_score *restore_sp = move_sp;
int count = 0;
genmoves();
while (move_sp > restore_sp)
{
move gm = popmove();
if ((TO(gm) == TO(m)) && (FR(gm) != FR(m)))
{
if (validmove(gm) == 1)
{
if (getpiece__(FR(gm)) == piece)
{
amb[count] = gm;
count++;
}
}
}
}
move_sp = restore_sp;
if (count == 0)
return AMBIG_NONE;
int file_count = 0;
int rank_count = 0;
int source_file = F(FR(m));
int source_rank = R(FR(m));
int i;
for (i=0;i<count;i++)
{
int file = F(FR(amb[i]));
int rank = R(FR(amb[i]));
if (file == source_file)
file_count++;
if (rank == source_rank)
rank_count++;
}
if (rank_count>0 && file_count>0)
return AMBIG_BOTH;
if (file_count==0)
return AMBIG_RANK;
return AMBIG_FILE;
}
char *get_san(move m)
{
static char san_buffer[SAN_BUFFER_LEN];
square fr = FR(m);
square to = TO(m);
chesspiece p = getpiece__(fr);
if (is_castle(m))
{
int f = F(to);
if (f<FILEE)
{
return "O-O-O";
}
else
{
return "O-O";
}
}
int f_fr = F(fr);
int r_fr = R(fr);
int f_to = F(to);
int r_to = R(to);
int piece = chesspiecevalue(p);
char *ret_val = &san_buffer[SAN_BUFFER_LEN-1];
*ret_val = 0;
ret_val--;
// add +/# to checks/checkmates
domove(m);
if (fullincheckp(tomove()))
{
if (gameoverp(tomove()) == END_CHECKMATE)
*ret_val = '#';
else
*ret_val = '+';
ret_val --;
}
undomove();
// add =X to promos
if (is_promo(m))
{
*ret_val = PC(PR(m));
ret_val--;
*ret_val = '=';
ret_val--;
}
// add target squares
*ret_val = RK(r_to);
ret_val--;
*ret_val = FL(f_to);
int capture = 0;
// add x to captures
if (is_capture(m))
{
ret_val --;
*ret_val = 'x';
capture = 1;
}
int amb = is_ambiguous(m, p);
switch (amb)
{
case AMBIG_NONE:
break;
case AMBIG_BOTH:
ret_val --;
*ret_val = RK(r_fr);
ret_val --;
*ret_val = FL(f_fr);
break;
case AMBIG_RANK:
ret_val --;
*ret_val = FL(f_fr);
break;
case AMBIG_FILE:
ret_val --;
*ret_val = RK(r_fr);
break;
}
if (piece == pawn)
{
// file required on pawn captures
if (capture && (amb == AMBIG_NONE))
{
ret_val --;
*ret_val = FL(f_fr);
}
return ret_val;
}
else
{
ret_val--;
*ret_val = PC(piece);
return ret_val;
}
}
char *movestring(move m)
{
static char res[5];
res[0] = FL(F(FR(m)));
res[1] = RK(R(FR(m)));
res[2] = FL(F(TO(m)));
res[3] = RK(R(TO(m)));
res[4] = 0;
return res;
}
char *get_game_status_string(int status, int turn)
{
switch (status)
{
case NON_MATERIAL:
return "1/2-1/2";
case REP_DRAW:
return "1/2-1/2";
case END_CHECKMATE:
if (turn == WHITE)
return "0-1";
return "1-0";
case END_STALEMATE:
return "1/2-1/2";
case IN_PROGRESS:
return "*";
default:
return "*";
}
}
char *get_export_name(struct tm *time_info)
{
static char export_name_buffer[256];
if (!time_info)
{
return FILE_EXPORT_NAME;
}
else
{
sprintf(export_name_buffer,"%s/%4d_%02d_%02d_%02d_%02d.PGN",
FILE_BASE_DIR,
time_info->tm_year+1900,
time_info->tm_mon+1,
time_info->tm_mday,
time_info->tm_hour,
time_info->tm_min
);
return export_name_buffer;
}
}
int do_export()
{
int i;
time_t result;
result = time(NULL);
struct tm *time_info = localtime(&result);
char *export_name = get_export_name(time_info);
FILE *f = fopen(export_name,"w+");
int game_status = gameoverp(tomove());
char *status_string = get_game_status_string(game_status, tomove());
if (f)
{
fprintf(f,"[Event \"pspChess\"]\n");
fprintf(f,"[Site \"psp\"]\n");
if (time_info)
{
fprintf(f,"[Date \"%4d.%02d.%02d\"]\n", time_info->tm_year+1900,
time_info->tm_mon+1, time_info->tm_mday);
}
else
{
fprintf(f,"[Date \"????.??.??\"]\n");
}
fprintf(f,"[Round \"1\"]\n");
fprintf(f,"[White \"%s\"]\n",g_personality_names[computer[WHITE]]);
fprintf(f,"[Black \"%s\"]\n",g_personality_names[computer[BLACK]]);
fprintf(f,"[Result \"%s\"]\n", status_string);
cache_current_game();
reset_game(0);
clear_screen();
for (i=0;i<g_cached_ply;i++)
{
move m = g_cached_gamestack[i];
if (i%2==0)
{
fprintf(f,"\n%d.", i/2 + 1);
}
fprintf(f," %s", g_san_moves[i]);
domove(m);
}
fprintf(f," %s\n", status_string);
fclose(f);
user_message_wait_key("GAME EXPORTED");
}
else
{
flash_display("opening export file failed");
}
return 0;
}
int select_storage_slot()
{
int i;
int cursor = 0;
int ret_val = -1;
cache_current_game();
while (1)
{
int x = 35;
int y = 6;
clear_screen();
if (storage_slot_used(cursor))
{
preview_slot(cursor);
}
pgFancyPrint(35,30,red,"X TO ACCEPT",1,0,0);
pgFancyPrint(35,32,red,"TRIANGLE TO CANCEL",1,0,0);
for (i=0;i<MAX_STORAGE_SLOT;i++)
{
y+=2;
if (cursor == i)
{
pgFancyPrint(x-2,y,cyan,"->",1,0,1);
pgFancyPrint(x,y,cyan,"SLOT",1,0,1);
pgFancyPrint(x+6,y,cyan,itoa(i,10),1,0,1);
}
else
{
pgFancyPrint(x,y,cyan,"SLOT",0,1,1);
pgFancyPrint(x+6,y,cyan,itoa(i,10),0,1,1);
}
if (storage_slot_used(i))
{
pgFancyPrint(x+10,y,cyan,"-USED-",1,0,0);
}
else
{
pgFancyPrint(x+10,y,cyan,"-EMPTY-",1,1,0);
}
}
pgScreenFlipV();
int key = get_buttons();
if (test_keys(key,PSP_CTRL_UP))
cursor --;
if (test_keys(key,PSP_CTRL_DOWN))
cursor ++;
if (test_keys(key,PSP_CTRL_CROSS))
{
ret_val = cursor;
break;
}
if (test_keys(key,PSP_CTRL_TRIANGLE))
break;
if (cursor>=MAX_STORAGE_SLOT)
cursor = 0;
if (cursor<0)
cursor = MAX_STORAGE_SLOT-1;
}
restore_cached_game();
return ret_val;
}
int do_clear_tables()
{
clear_hash();
return 0;
}
int do_load_book()
{
loadbook();
setupboard();
ply = 0;
change_gamemode(OPENING,0);
return 0;
}
int do_game_options()
{
return generic_options_menu(
g_gameplay_options,
sizeof(g_gameplay_options)/sizeof(g_gameplay_options[0]));
}
int do_sound_options()
{
return generic_options_menu(
g_sound_options,
sizeof(g_sound_options)/sizeof(g_sound_options[0]));
}
int do_display_options()
{
return generic_options_menu(
g_display_options,
sizeof(g_display_options)/sizeof(g_display_options[0]));
}
int do_server_options()
{
return generic_options_menu(
g_server_options,
sizeof(g_server_options)/sizeof(g_server_options[0]));
}
int do_server_connect()
{
g_game_mode = GAMEMODE_CLIENT;
computer[BLACK] = 0;
computer[WHITE] = 0;
init_network();
terminal_mode();
return 1;
}
int do_save_game()
{
int slot = select_storage_slot();
if (slot>=0)
{
if (storage_slot_used(slot) &&
!user_prompt("Do you want to overwrite the slot?"))
return 0;
FILE *f = fopen(storage_slot_name(slot),"w+");
if (f)
{
int bla = 0;
char magic[MAGIC_LEN+1] = MAGIC;
fwrite(&bla,sizeof(int),1,f);
fwrite(magic,MAGIC_LEN,1,f);
fwrite(&g_initial_board_position,sizeof(chessboard),1,f);
fwrite(&ply, sizeof(ply), 1, f);
fwrite(gamestack,sizeof(gamestack[0]), ply, f);
fclose(f);
user_message_wait_key("GAME SAVED");
}
else
{
flash_display("opening file failed");
}
}
return 0;
}
int do_load_game()
{
int slot = select_storage_slot();
if (slot>=0)
{
if (load_slot(slot))
{
user_message_wait_key("Game Loaded");
}
else
{
flash_display("Load Game failed");
}
}
return 0;
}
void setup_option_background()
{
int i;
int n_pages = 2;
for (i=0;i<n_pages;i++)
{
clear_screen();
pgPrintCenter(1,green,"PSPCHESS BY CHRISTOPHER BOWRON");
pgPrintCenter(2,green,"CHESS@BOWRON.US");
pgPrintCenter(3,green,"Graphics by Stadi Thompson");
pgPrintCenter(4,green,"Distributed under the GNU Public License");
pgPrintCenter(5,green,"--Share and Enjoy--");
pgPrintCenter(32,red,"LEFT/RIGHT/X to Change");
pgPrintCenter(33,red,"TRIANGLE to return To Game");
pgScreenFlipV();
}
}
int generic_options_menu(struct option_struct *options, int max)
{
int i, max_i, key, cursor = 0;
max_i = max;
setup_option_background();
do
{
int y, x2;
int x = 13;
int start_y = 7;
clear_text_area(x,start_y,60-2*x,max_i+2);
// display options
for (i=0;i<max_i;i++)
{
y = i+start_y+1;
x = 15;
x2 = x+18;
if (i==cursor)
{