-
Notifications
You must be signed in to change notification settings - Fork 3
/
menu.c
1663 lines (1466 loc) · 53 KB
/
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 <stdlib.h>
#include <stdio.h>
#include <dirent.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h> /* test! for chdir etc. */
#include <sys/stat.h>
#include <sys/types.h>
#include <limits.h>
#include <time.h>
#include "gnuboy/Version"
#include "ohboy_ver.h"
#include "gnuboy.h"
#include "fb.h"
#include "ubytegui/gui.h"
#include "ubytegui/dialog.h"
#include "input.h"
#include "hw.h"
#include "rc.h"
#include "loader.h"
#include "mem.h"
#include "sound.h"
#include "lcd.h"
#include "menu.h"
extern void scaler_init(int scaler_number); /* maybe keeping this and loosing the other stuff */
#ifdef DINGOO_NATIVE
#include <jz4740/cpu.h> /* for cpu clock */
char *ctime(const time_t *timep);
char *ctime(const time_t *timep)
{
char *x="not_time";
return x;
}
#endif /* DINGOO_NATIVE */
char *menu_getext(char *s){
char* ext = NULL;
while(*s){
if(*s++ == '.') ext=s;
}
return ext;
}
int filterfile(char *p, char *exts){
char* ext;
char* cmp;
int n,i;
if(exts==NULL) return 1;
ext = exts;
cmp = menu_getext(p);
if(cmp==NULL) return 0;
while(*ext != 0){
n=0;
while(*exts++ != ';'){
n++;
if(*exts==0) break;
}
i=0;
while(tolower(cmp[i])==tolower(ext[i])){
i++;
if((i==n) && (cmp[i]==0)) return 1;
if((i==n) || (cmp[i]==0)) break;
}
ext = exts;
}
return 0;
}
int fcompare(const void *a, const void *b){
char *stra = *(char**)a;
char *strb = *(char**)b;
int cmp;
return strcmp(stra,strb);
}
const char *basexname (const char *f) {
const char *p;
if ((p = strrchr (f, '/')) != NULL || (p = strrchr (f, '\\')) != NULL) {
return (p + 1);
}
return (f);
}
char* menu_browsedir(char* fpathname, char* file, char *title, char *exts, int* rombrowsing){
/* this routine has side effects with fpathname and file, FIXME */
DIR *dir;
struct dirent *d;
int n=0, i, j;
char *files[1<<16]; /* 256Kb */
#ifndef DT_DIR
struct stat s;
char tmpfname[PATH_MAX];
char *tmpfname_end;
#endif /* DT_DIR */
if(!(dir = opendir(fpathname))) return NULL; /* FIXME try parent(s) until out of paths */
/* TODO FIXME add root directory check (to avoid adding .. as a menu option when at "/" or "x:\") */
files[n] = malloc(4);
strcpy(files[n], "..");
strcat(files[n], DIRSEP);
n++;
d = readdir(dir);
if(d && !strcmp(d->d_name,".")) d = readdir(dir);
if(d && !strcmp(d->d_name,"..")) d = readdir(dir);
#ifndef DT_DIR
strcpy(tmpfname, fpathname);
tmpfname_end = &tmpfname[0];
tmpfname_end += strlen(tmpfname);
#endif /* DT_DIR */
while(d){
#ifndef DT_DIR
/* can not lookup type from search result have to stat filename*/
strcpy(tmpfname_end, d->d_name);
stat(tmpfname, &s);
if(S_ISDIR (s.st_mode))
#else
if ((d->d_type & DT_DIR) == DT_DIR)
#endif /* DT_DIR */
{
files[n] = malloc(strlen(d->d_name)+2);
strcpy(files[n], d->d_name);
strcat(files[n], DIRSEP);
n++;
} else if(filterfile(d->d_name,exts)){
files[n] = malloc(strlen(d->d_name)+1);
strcpy(files[n], d->d_name);
n++;
}
d = readdir(dir);
}
closedir (dir);
qsort(files+1,n-1,sizeof(char*),fcompare);
dialog_begin(title, fpathname);
for(i=0; i<n; i++){
dialog_text(files[i],"",FIELD_SELECTABLE);
}
if(j = dialog_end(rombrowsing)){
if(file) {
strcpy(file,files[j-1]);
} else {
file = files[j-1];
files[j-1] = NULL;
}
}
for(i=0; i<n; i++){
free(files[i]);
}
return j ? file : NULL;
}
char* menu_requestfile(char* file, char *title, char* path, char *exts, int* rombrowsing){
char *dir;
int allocmem = file == NULL;
int tmplen = 0;
char parent_dir_str[5];
#ifdef DINGOO_NATIVE
static char dingoo_default_path[]="a:\\";
#endif /* DINGOO_NATIVE */
/* TODO clear all the dyanamic memory allocations in this routine and require caller to pre-allocate */
if (allocmem) file = malloc(PATH_MAX);
#ifdef DEBUG_ALWAYS_RETURN_ADJUSTRIS_GB
strcpy(file, "adjustris.gb");
return file;
#endif /* DEBUG_ALWAYS_RETURN_ADJUSTRIS_GB */
if(path)
{
strcpy(file, path);
tmplen = strlen(file);
if (tmplen >=1)
{
if (file[tmplen-1] != DIRSEP_CHAR)
strcat(file, DIRSEP); /* this is very fragile, e.g. what if dir was specified but does not exist */
}
}
else
strcpy(file, "");
snprintf(parent_dir_str, sizeof(parent_dir_str), "..%s", DIRSEP);
while(dir = menu_browsedir(file, file+strlen(file),title,exts,rombrowsing)){
if (!strcmp(dir, parent_dir_str))
{
/* need to go up a directory */
dir--;
if (dir > file)
{
*dir = '\0';
while (dir >= file && *dir != DIRSEP_CHAR)
{
*dir = '\0';
dir--;
}
}
if (strlen(file) == 0)
{
#ifdef DINGOO_NATIVE
if (dingoo_default_path[0] == 'A')
dingoo_default_path[0] = 'B';
else
dingoo_default_path[0] = 'A';
sprintf(file, "%s", dingoo_default_path);
/*
** If there is no MiniSD card in B:
** then an empty list is displayed
** click the parent directory to
** toggle back to A:
*/
#else
sprintf(file, ".%s", DIRSEP);
#endif /* DINGOO_NATIVE */
dir = file + strlen(file)+1;
*dir = '\0';
}
}
/*
** Check to see if we have a file name,
** or a new directory name to scan
** Directory name will have trailing path sep character
** FIXME check for "../" and dirname the dir
*/
tmplen = strlen(dir);
if (tmplen >=1)
if (dir[tmplen-1] != DIRSEP_CHAR)
{
if (allocmem) file = realloc(file, strlen(file)+1);
break;
}
}
if(!dir) file = NULL; /* FIXME what it file was not null when function was called, what about free'ing this is we allocated it? */
return file;
}
char *menu_requestdir(const char *title, const char *path){
char *dir=NULL, **ldirs;
int ldirsz, ldirn=0, ret, l;
DIR *cd;
struct dirent *d;
#ifndef DT_DIR
struct stat s;
#endif /* DT_DIR */
char *cdpath;
//#ifndef DT_DIR
char tmpfname[PATH_MAX];
char *tmpfname_end;
//#endif /* DT_DIR */
cdpath = malloc(PATH_MAX);
strcpy(cdpath, path);
//#ifndef DT_DIR
strcpy(tmpfname, path);
tmpfname_end = &tmpfname[0];
tmpfname_end += strlen(tmpfname);
//#endif /* DT_DIR */
while(!dir){
cd = opendir(cdpath);
dialog_begin(title, cdpath);
dialog_text("[Select This Directory]",NULL,FIELD_SELECTABLE);
dialog_text("/.. Parent Directory",NULL,FIELD_SELECTABLE);
ldirsz = 16;
ldirs = malloc(sizeof(char*)*ldirsz);
d = readdir(cd);
if(d && !strcmp(d->d_name,".")) d = readdir(cd);
if(d && !strcmp(d->d_name,"..")) d = readdir(cd);
while(d){
if(ldirn >= ldirsz){
ldirsz += 16;
ldirs = realloc(ldirs,ldirsz*sizeof(char*));
}
#ifndef DT_DIR
/* can not lookup type from search result have to stat filename*/
strcpy(tmpfname_end, d->d_name);
stat(tmpfname, &s);
if(S_ISDIR (s.st_mode))
#else
if ((d->d_type & DT_DIR) == DT_DIR)
#endif /* DT_DIR */
{
l = strlen(d->d_name);
ldirs[ldirn] = malloc(l+2);
strcpy(ldirs[ldirn], d->d_name);
ldirs[ldirn][l] = DIRSEP_CHAR;
ldirs[ldirn][l+1] = '\0';
dialog_text(ldirs[ldirn],NULL,FIELD_SELECTABLE);
ldirn++;
}
d = readdir(cd);
}
closedir(cd);
switch(ret=dialog_end(0)){
case 0:
dir = (char*)-1;
break;
case 1:
DelLastSelectedRomPos();
dir = strdup(cdpath);
break;
case 2:
{
/* need to go up a directory */
char *tmp_str=NULL;
tmp_str=cdpath;
tmp_str+=strlen(tmp_str)-1;
tmp_str--;
if (tmp_str > cdpath)
{
*tmp_str = '\0';
while (tmp_str >= cdpath && *tmp_str != DIRSEP_CHAR)
{
*tmp_str = '\0';
tmp_str--;
}
}
if (strlen(cdpath) == 0)
{
sprintf(cdpath, ".%s", DIRSEP);
tmp_str = cdpath + strlen(cdpath)+1;
*tmp_str = '\0';
}
strcpy(tmpfname, cdpath);
tmpfname_end = &tmpfname[0];
tmpfname_end += strlen(tmpfname);
}
break;
default:
strcpy(tmpfname_end, ldirs[ret-3]);
tmpfname_end = &tmpfname[0];
tmpfname_end += strlen(tmpfname);
strcpy(cdpath, tmpfname);
break;
}
while(ldirn)
free(ldirs[--ldirn]);
free(ldirs);
}
if(dir==(char*)-1)
dir = NULL;
free(cdpath);
return dir;
}
char *menu_checkdir(char *path, char *alt_path){
char *dir;
DIR *direxist;
direxist = opendir(path);
if(direxist == NULL){
dir = alt_path;
}else{
closedir(direxist);
dir = path;
}
return dir;
}
/* NOTE number of slot entries is indirectly related to font size */
/* only display one screen of save slots */
static const char *slots[] = {
"Slot 0","Slot 1","Slot 2","Slot 3","Slot 4","Slot 5","Slot 6","Slot 7",
"Slot 8","Slot 9","Slot 10","Slot 11","Slot 12","Slot 13","Slot 14","Slot 15",
NULL};
static const char *emptyslot = "<Empty>";
static const char *not_emptyslot = "<Used>";
int menu_state(int save){
char **statebody=NULL;
char* name;
int i, flags,ret, del=0,l;
#ifndef OHBOY_FILE_STAT_NOT_AVAILABLE
/* Not all platforms implement stat()/fstat() */
struct stat fstat;
time_t time;
char *tstr;
#endif
char *savedir;
char *savename;
char *saveprefix;
FILE *f;
int sizeof_slots=0;
int statesram=1;
while (slots[sizeof_slots] != NULL)
sizeof_slots++;
statebody = malloc(sizeof_slots * sizeof(char*)); /* FIXME check for NULL return from malloc */
statesram = rc_getint("statesram");
savedir = rc_getstr("savedir");
savename = rc_getstr("savename");
saveprefix = malloc(strlen(savedir) + strlen(savename) + 2);
sprintf(saveprefix, "%s%s%s", savedir, DIRSEP, savename);
if(statesram==0){
dialog_begin(save?"Save State":" Load State (SRAM Off)",rom.name);
}else if(statesram==1){
dialog_begin(save?"Save State":"Load State",rom.name);
}
for(i=0; i<sizeof_slots; i++){
name = malloc(strlen(saveprefix) + 5);
sprintf(name, "%s.%03d", saveprefix, i);
#ifndef OHBOY_FILE_STAT_NOT_AVAILABLE
/* if the file exists lookup the timestamp */
if(!stat(name,&fstat)){
time = fstat.st_mtime;
tstr = ctime(&time);
l = strlen(tstr);
statebody[i] = malloc(l);
strcpy(statebody[i],tstr);
statebody[i][l-1]=0;
#else
/* check if the file exists */
if(f=fopen(name,"rb")){
fclose(f);
statebody[i] = (char*)not_emptyslot;
#endif /* OHBOY_FILE_STAT_NOT_AVAILABLE */
flags = FIELD_SELECTABLE;
} else {
statebody[i] = (char*)emptyslot;
flags = save ? FIELD_SELECTABLE : 0;
}
dialog_text(slots[i],statebody[i],flags);
free(name);
}
if(ret=dialog_end(0)){
name = malloc(strlen(saveprefix) + 5);
sprintf(name, "%s.%03d", saveprefix, ret-1);
if(save){
if(f=fopen(name,"wb")){
savestate(f);
fclose(f);
}
}else if(statesram==0){
if(f=fopen(name,"rb")){
loadstate_nosram(f);
fclose(f);
vram_dirty();
pal_dirty();
sound_dirty();
mem_updatemap();
}
}else if(statesram==1){
if(f=fopen(name,"rb")){
loadstate(f);
fclose(f);
vram_dirty();
pal_dirty();
sound_dirty();
mem_updatemap();
}
}
free(name);
}
for(i=0; i<sizeof_slots; i++)
if(statebody[i] != emptyslot && statebody[i] != not_emptyslot) free(statebody[i]);
free(saveprefix);
return ret;
}
/*#############################DMG FILTERS##########################################*/
#define DMGFILT_COUNT 14
struct filt_s{
char name[16];
unsigned int red[4];
unsigned int green[4];
unsigned int blue[4];
}dmgfilt[DMGFILT_COUNT] = {
{//Default Filter
.name = "Default",
.red = { 95, 25, 0, 35 },
.green = { 25, 170, 25, 35 },
.blue = { 25, 60, 125, 40 }
},{//Dark Filter
.name = "Low Contrast",
.red = { 60, 10, 0, 35 },
.green = { 12, 75, 12, 35 },
.blue = { 10, 20, 65, 40 }
},{//DMG Dark
.name = "DMG Dark",
.red = { 32, 32, 32, 0 },
.green = { 41, 41, 41, 24 },
.blue = { -11, -11, -11, 40 }
},{//DMG Medium
.name = "DMG Medium",
.red = { 32, 32, 32, 0 },
.green = { 33, 33, 33, 48 },
.blue = { -13, -13, -13, 48 }
},{//DMG Light
.name = "DMG Light",
.red = { 32, 32, 32, 0 },
.green = { 25, 25, 25, 72 },
.blue = { -19, -19, -19, 64 }
},{//GBP Dark
.name = "GBPocket Dark",
.red = { 37, 37, 37, 0 },
.green = { 49, 49, 49, 24 },
.blue = { 29, 29, 29, 40 }
},{//GBP Medium
.name = "GBPocket Medium",
.red = { 37, 37, 37, 0 },
.green = { 41, 41, 41, 48 },
.blue = { 26, 26, 26, 48 }
},{//GBP Light
.name = "GBPocket Light",
.red = { 37, 37, 37, 0 },
.green = { 36, 36, 36, 64 },
.blue = { 21, 21, 21, 64 }
},{//DemoVision
.name = "DemoVision",
.red = { 61, 61, 61, 72 },
.green = { 50, 50, 50, 88 },
.blue = { 48, 48, 48, 0 }
},{//DemoVision Dark
.name = "DemoVision Dark",
.red = { 73, 73, 73, 36 },
.green = { 62, 62, 62, 51 },
.blue = { 48, 48, 48, 0 }
},{//Color 0
.name = "Grayscale",
.red = { 85, 85, 85, 0 },
.green = { 85, 85, 85, 0 },
.blue = { 85, 85, 85, 0 }
},{//Color 25
.name = "Color 25%",
.red = { 105, 75, 75, 0 },
.green = { 75, 105, 75, 0 },
.blue = { 75, 75, 105, 0 }
},{//Color 50
.name = "Color 50%",
.red = { 130, 63, 63, 0 },
.green = { 63, 130, 63, 0 },
.blue = { 63, 63, 130, 0 }
},{//Color 75
.name = "Color 75%",
.red = { 170, 43, 43, 0 },
.green = { 43, 170, 43, 0 },
.blue = { 43, 43, 170, 0 }
}
} ;
int findfilt(){
int *a, *b;
int i,j;
for(i=0; i<DMGFILT_COUNT; i++){
a = dmgfilt[i].red ; b = rc_getvec("red");
if(a[0] != b[0] || a[1] != b[1] || a[2] != b[2] || a[3] != b[3])
continue;
a = dmgfilt[i].green; b = rc_getvec("green");
if(a[0] != b[0] || a[1] != b[1] || a[2] != b[2] || a[3] != b[3])
continue;
a = dmgfilt[i].blue; b = rc_getvec("blue");
if(a[0] != b[0] || a[1] != b[1] || a[2] != b[2] || a[3] != b[3])
continue;
return i;
}
return 0;
}
char *ldmgfilters[] = {
dmgfilt[0].name,
dmgfilt[1].name,
dmgfilt[2].name,
dmgfilt[3].name,
dmgfilt[4].name,
dmgfilt[5].name,
dmgfilt[6].name,
dmgfilt[7].name,
dmgfilt[8].name,
dmgfilt[9].name,
dmgfilt[10].name,
dmgfilt[11].name,
dmgfilt[12].name,
dmgfilt[13].name,
NULL
};
/*#################################################################################*/
const char *lframeskip[] = {"Auto","Off","1","2","3","4",NULL};
const char *lsdl_showfps[] = {"Off","On",NULL};
#if WIZ
const char *lclockspeeds[] = {"Default","250 mhz","300 mhz","350 mhz","400 mhz","450 mhz","500 mhz","550 mhz","600 mhz","650 mhz","700 mhz","750 mhz",NULL};
#endif
#ifdef DINGOO_NATIVE
const char *lclockspeeds[] = { "Default", "200 mhz", "250 mhz", "300 mhz", "336 mhz", "360 mhz", "400 mhz", NULL };
#endif
const char *lstatesram[] = {"Off","Default (On)",NULL};
const char *lsystemmode[] = {"Auto","Force DMG Mode","Auto, GBA Enhanced",NULL};
const char *lsndlvl[] = {"0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "100%", NULL};
const char *lcolorfilter[] = {"Off","On","GBC Only",NULL};
#ifdef GCWZERO
const char *lupscaler[] = {"Native (No scale)", "Software 1.5x", "Scale3x+Sample.75x", "Software 1.666x", "Software Fullscreen", "Hardware 1.5x", "Hardware 1.666x", "Hardware FullScreen", NULL};
#else
const char *lupscaler[] = {"Native (No scale)", "Ayla 1.5x Upscaler", "Scale3x+Sample.75x", "1.666x Upscaler", "Ayla Fullscreen", NULL};
#endif /* GCW ZERO */
const char *lborderon[] = {"Off","Image File","BG Color",NULL};
const char *lblendfram[] = {"Off","On",NULL};
const char *lbutton_a[] = {"None","Button A","Button B","Select","Start","Reset","Quit","Quick Save","Quick Load",NULL};
const char *lbutton_b[] = {"None","Button A","Button B","Select","Start","Reset","Quit","Quick Save","Quick Load",NULL};
const char *lbutton_x[] = {"None","Button A","Button B","Select","Start","Reset","Quit","Quick Save","Quick Load",NULL};
const char *lbutton_y[] = {"None","Button A","Button B","Select","Start","Reset","Quit","Quick Save","Quick Load",NULL};
const char *lbutton_l[] = {"None","Button A","Button B","Select","Start","Reset","Quit","Quick Save","Quick Load",NULL};
const char *lbutton_r[] = {"None","Button A","Button B","Select","Start","Reset","Quit","Quick Save","Quick Load",NULL};
const char *lanalog_input[] = {"Disabled","Enabled",NULL};
#ifdef GCWZERO
const char *lalt_menu_combo[] = {"No","Select + Start",NULL};
#endif
static char config[24][256];
int menu_main_settings(){
int ret=0, i=0;
int skip=0, sfps=0, speed=0, statesram=1, systemmode=0;
int sndlvl=10;
char *romdir=0, *romtemp=0;
FILE *file;
#ifdef DINGOO_NATIVE
/*
** 100Mhz once caused Dingoo A320 MIPS to hang,
** when 100Mhz worked BW GB (Adjustris) game was running at 32 fps (versus 60 at 200Mhz).
** 150Mhz has never worked on my Dingoo A320.
*/
uintptr_t dingoo_clock_speeds[] = { 200000000, 250000000, 300000000, 336000000, 360000000, 400000000 /* , 430000000 Should not be needed */ };
/*
** under-under clock option is for GB games.
** GB games can often be ran under the already
** underclocked Dingoo speed of 336Mhz
*/
bool dingoo_clock_change_result;
uintptr_t tempCore=336000000; /* default Dingoo A320 clock speed */
uintptr_t tempMemory=112000000; /* default Dingoo A320 memory speed */
cpu_clock_get(&tempCore, &tempMemory);
#endif /* DINGOO_NATIVE */
skip = rc_getint("frameskip")+1;
sfps = rc_getint("showfps");
statesram = rc_getint("statesram");
systemmode = rc_getint("systemmode");
sndlvl = rc_getint("sndlvl");
#ifdef DINGOO_NATIVE
speed = 0;
#else
speed = rc_getint("cpuspeed")/50 - 4;
#endif /* DINGOO_NATIVE */
if(speed<0) speed = 0;
if(speed>11) speed = 11;
#if defined(DINGOO_SIM) || defined(DISABLE_ROMBROWSER)
#else
#ifdef DINGOO_OPENDINGUX
romdir = menu_checkdir(rc_getstr("romdir"),getenv("HOME"));
#else
romdir = rc_getstr("romdir");
#endif /* DINGOO_OPENDINGUX */
#endif /* DINGOO_SIM || DISABLE_ROMBROWSER*/
romdir = romdir ? strdup(romdir) : strdup(".");
start:
dialog_begin("Main Settings",NULL);
dialog_option("Frameskip",lframeskip,&skip); /* 1 */
dialog_option("Show FPS",lsdl_showfps,&sfps); /* 2 */
#if defined(WIZ) || defined(DINGOO_NATIVE)
dialog_option("Clock Speed",lclockspeeds,&speed); /* 3 */
#else
dialog_text("Clock Speed","Default",0); /* 3 */
#endif
#if defined(DINGOO_SIM) || defined(DISABLE_ROMBROWSER)
dialog_text("Rom Path", "Default", 0); /* 4 */
#else
dialog_text("Rom Path",romdir,FIELD_SELECTABLE); /* 4 */
#endif /* DINGOO_SIM || DISABLE_ROMBROWSER */
dialog_option("State SRAM",lstatesram,&statesram); /* 5 */
dialog_option("System",lsystemmode,&systemmode); /* 6 */
#ifdef GNUBOY_HARDWARE_VOLUME
dialog_option("Volume",lsndlvl,&sndlvl); /* 7 */ /* this is not the OSD volume.. */
#else
dialog_text("Volume", "Default", 0); /* 7 */ /* this is not the OSD volume.. */
#endif /* GNBOY_HARDWARE_VOLUME */
dialog_text(NULL,NULL,0); /* 8 */
dialog_text("Apply",NULL,FIELD_SELECTABLE); /* 9 */
dialog_text("Apply & Save",NULL,FIELD_SELECTABLE); /* 10 */
dialog_text("Cancel",NULL,FIELD_SELECTABLE); /* 11 */
switch(ret=dialog_end(0)){
case 4: /* "Rom Path" romdir */
romtemp = menu_requestdir("Select Rom Directory",romdir);
if(romtemp){
free(romdir);
romdir = romtemp;
}
goto start;
case 11: /* Cancel */
return ret;
break;
case 9: /* Apply */
case 10: /* Apply & Save */
#ifdef GNUBOY_HARDWARE_VOLUME
pcm_volume(sndlvl * 10);
#endif /* GNBOY_HARDWARE_VOLUME */
if(speed)
{
#ifdef DINGOO_NATIVE
/*
** For now do NOT plug in into settings system, current
** (Wiz) speed system is focused on multiples of 50Mhz.
** Dingoo default clock speed is 336Mhz (CPU certified for
** 360, 433MHz is supposed to be possible).
** Only set clock speed if changed in options each and
** everytime - do not use config file
*/
--speed;
/* check menu response is withing the preset array range/size */
if (speed > (sizeof(dingoo_clock_speeds)/sizeof(uintptr_t) - 1) )
speed = 0;
tempCore = dingoo_clock_speeds[speed];
dingoo_clock_change_result = cpu_clock_set(tempCore);
tempCore=tempMemory=0;
cpu_clock_get(&tempCore, &tempMemory); /* currently unused */
/* TODO display clock speed next to on screen FPS indicator */
#endif /* DINGOO_NATIVE */
speed = speed*50 + 200;
}
sprintf(config[0],"set frameskip %i",skip-1);
sprintf(config[1],"set showfps %i",sfps);
sprintf(config[2],"set cpuspeed %i",speed);
#ifdef DINGOO_NATIVE /* FIXME Windows too..... if (DIRSEP_CHAR == '\\').... */
{
char tmp_path[PATH_MAX];
char *dest, *src;
dest = &tmp_path[0];
src = romdir;
/* escape the path seperator (should escape other things too.) */
while(*dest = *src++)
{
if (*dest == DIRSEP_CHAR)
{
dest++;
*dest = DIRSEP_CHAR;
}
dest++;
}
sprintf(config[3], "set romdir \"%s\"", tmp_path);
}
#else
sprintf(config[3],"set romdir \"%s\"",romdir);
#endif /* DINGOO_NATIVE */
sprintf(config[4], "set statesram %i", statesram);
sprintf(config[5], "set systemmode %i", systemmode);
if(systemmode == 0){
sprintf(config[6], "set forcedmg 0");
sprintf(config[7], "set gbamode 0");
} else if(systemmode == 1){
sprintf(config[6], "set forcedmg 1");
sprintf(config[7], "set gbamode 0");
} else if(systemmode == 2){
sprintf(config[6], "set forcedmg 0");
sprintf(config[7], "set gbamode 1");
}
sprintf(config[8], "set sndlvl %i", sndlvl);
for(i=0; i<9; i++)
rc_command(config[i]);
pal_dirty();
if (ret == 10){ /* Apply & Save */
#ifdef DINGOO_SIM
file = fopen("a:"DIRSEP"ohboy"DIRSEP"ohboy.rc","w");
#else
#ifdef DINGOO_OPENDINGUX
static char *ohboyrc;
ohboyrc = malloc(strlen(getenv("HOME")) + 28);
sprintf(ohboyrc, "%s/.ohboy/ohboy.rc", getenv("HOME"));
file = fopen(ohboyrc,"w");
free (ohboyrc);
#else
file = fopen("ohboy.rc","w");
#endif /* DINGOO_OPENDINGUX */
#endif /* DINGOO_SIM */
for(i=0; i<9; i++){
fputs(config[i],file);
fputs("\n",file);
}
fclose(file);
}
break;
}
free(romdir);
return ret;
}
int menu_video_settings(){
int ret=0, i=0;
struct filt_s *filtp=0;
int filt=0, cfilter=0, upscale=0, borderon=0, blendfram=0;
char *paldir=0, *loadpal=0, *pal=0, *paltemp=0, *palname=0, *borderdir=0, *loadborder=0, *border=0, *bordertemp=0, *bordername=0, *gbcborder=0, *gbcbordertemp=0, *gbcbordername=0;
FILE *file;
filt = findfilt();
cfilter = rc_getint("colorfilter");
if(cfilter && !rc_getint("filterdmg")) cfilter = 2;
upscale = rc_getint("upscaler");
borderon = rc_getint("bmpenabled");
#ifdef DINGOO_SIM
paldir = "a:\\ohboy\\palettes\\";
#else
#ifdef DINGOO_OPENDINGUX
paldir = malloc(strlen(getenv("HOME")) + 28);
sprintf(paldir, "%s/.ohboy/palettes/", getenv("HOME"));
#else
paldir = "palettes";
#endif /* DINGOO_OPENDINGUX */
#endif /* DINGOO_SIM */
pal = rc_getstr("palette");
pal = pal ? strdup(pal) : strdup("Select Palette");
paltemp = strdup(pal);
palname = basexname(paltemp);
#ifdef DINGOO_SIM
borderdir = "a:\\ohboy\\borders\\";
#else
#ifdef DINGOO_OPENDINGUX
borderdir = malloc(strlen(getenv("HOME")) + 28);
sprintf(borderdir, "%s/.ohboy/borders/", getenv("HOME"));
#else
borderdir = "borders";
#endif /* DINGOO_OPENDINGUX */
#endif /* DINGOO_SIM */
border = rc_getstr("border");
border = border ? strdup(border) : strdup("Select DMG Border");
bordertemp = strdup(border);
bordername = basexname(bordertemp);
gbcborder = rc_getstr("gbcborder");
gbcborder = gbcborder ? strdup(gbcborder) : strdup("Select GBC Border");
gbcbordertemp = strdup(gbcborder);
gbcbordername = basexname(gbcbordertemp);
blendfram = rc_getint("blendframes");
start:
dialog_begin("Video Settings",NULL);
dialog_text("Mono Palette",palname,FIELD_SELECTABLE); /* 1 */
dialog_option("Color Filter",lcolorfilter,&cfilter); /* 2 */
dialog_option("Filter Type",ldmgfilters,&filt); /* 3 */
dialog_option("Upscaler",lupscaler,&upscale); /* 4 */
dialog_option("Use Borders",lborderon,&borderon); /* 5 */
dialog_text("DMG Border Image",bordername,FIELD_SELECTABLE); /* 6 */
dialog_text("GBC Border Image",gbcbordername,FIELD_SELECTABLE); /* 7 */
dialog_option("Simulate Ghosting",lblendfram,&blendfram); /* 8 */
dialog_text(NULL,NULL,0); /* 9 */
dialog_text("Apply",NULL,FIELD_SELECTABLE); /* 10 */
dialog_text("Apply & Save",NULL,FIELD_SELECTABLE); /* 11 */
dialog_text("Cancel",NULL,FIELD_SELECTABLE); /* 12 */
switch(ret=dialog_end(0)){
case 1: /* "Mono Palette" */
loadpal = menu_requestfile(NULL,"Select Palette",paldir,"pal",0);
if(loadpal){
pal = loadpal;
paltemp = strdup(pal);
palname = basexname(paltemp);
}
goto start;
case 6: /* "DMG Border Image" */
#ifdef OHBOY_USE_SDL_IMAGE
loadborder = menu_requestfile(NULL,"Select DMG Border Image",borderdir,"bmp;png",0);
#else
loadborder = menu_requestfile(NULL,"Select DMG Border Image",borderdir,"bmp",0);
#endif /* OHBOY_USE_SDL_IMAGE */
if(loadborder){
border = loadborder;
bordertemp = strdup(border);
bordername = basexname(bordertemp);
}
goto start;
case 7: /* "GBC Border Image" */
#ifdef OHBOY_USE_SDL_IMAGE
loadborder = menu_requestfile(NULL,"Select GBC Border Image",borderdir,"bmp;png",0);
#else
loadborder = menu_requestfile(NULL,"Select GBC Border Image",borderdir,"bmp",0);
#endif /* OHBOY_USE_SDL_IMAGE */
if(loadborder){
gbcborder = loadborder;
gbcbordertemp = strdup(gbcborder);
gbcbordername = basexname(gbcbordertemp);
}
goto start;
case 12: /* Cancel */
return ret;
break;
case 10: /* Apply */
case 11: /* Apply & Save */
filtp = &dmgfilt[filt];
#ifdef DINGOO_NATIVE /* FIXME Windows too..... if (DIRSEP_CHAR == '\\').... */
{
char tmp_pal[PATH_MAX];
char *destp, *srcp;
destp = &tmp_pal[0];
srcp = pal;
/* escape the path seperator (should escape other things too.) */
while(*destp = *srcp++)
{
if (*destp == DIRSEP_CHAR)
{
destp++;
*destp = DIRSEP_CHAR;
}
destp++;
}
sprintf(config[0], "source \"%s\"", tmp_pal);
sprintf(config[1], "set palette \"%s\"", tmp_pal);
}
#else
sprintf(config[0],"source \"%s\"",pal);
sprintf(config[1],"set palette \"%s\"",pal);
#endif /* DINGOO_NATIVE */
sprintf(config[2],"set colorfilter %i",cfilter!=0);
sprintf(config[3],"set filterdmg %i",cfilter==1);
sprintf(config[4],"set upscaler %i",upscale);