Added general configuration management

This commit is contained in:
fabio.olimpieri 2012-05-26 13:03:17 +00:00
parent a93b567fda
commit b81feb3573
4 changed files with 193 additions and 62 deletions

View File

@ -494,22 +494,16 @@ void load_main_game(char *nombre) {
} }
} }
void save_config(struct computer *object) { int save_config(struct computer *object, char *filename) {
char config_path[1024];
int length;
unsigned char key, joy_n; unsigned char key, joy_n;
FILE *fconfig; FILE *fconfig;
strcpy(config_path,getenv("HOME")); fconfig = fopen(filename,"wb");
length=strlen(config_path);
if ((length>0)&&(config_path[length-1]!='/'))
strcat(config_path,"/");
strcat(config_path,"fbzx_conf");
fconfig = fopen(config_path,"wb");
if (fconfig==NULL) { if (fconfig==NULL) {
return; return -2; // can't create file
} }
fprintf(fconfig,"mode=%c%c",48+object->mode128k,10); fprintf(fconfig,"mode=%c%c",48+object->mode128k,10);
fprintf(fconfig,"issue=%c%c",48+object->issue,10); fprintf(fconfig,"issue=%c%c",48+object->issue,10);
fprintf(fconfig,"joystick1=%c%c",48+object->joystick[0],10); fprintf(fconfig,"joystick1=%c%c",48+object->joystick[0],10);
@ -533,6 +527,7 @@ void save_config(struct computer *object) {
fprintf(fconfig,"joybutton_%c_%c=%.3d%c",joy_n+48,key+97, object->joybuttonkey[joy_n][key],10); fprintf(fconfig,"joybutton_%c_%c=%.3d%c",joy_n+48,key+97, object->joybuttonkey[joy_n][key],10);
fclose(fconfig); fclose(fconfig);
return 0;
} }
@ -642,21 +637,13 @@ int load_config(struct computer *object, char *filename) {
char config_path[1024]; char config_path[1024];
char line[1024],carac,done; char line[1024],carac,done;
int length,pos, key_sdl=0; int pos, key_sdl=0;
FILE *fconfig; FILE *fconfig;
unsigned char volume=255,mode128k=255,issue=255,joystick1=255,joystick2=255,ay_emul=255,mdr_active=255, unsigned char volume=255,mode128k=255,issue=255,joystick1=255,joystick2=255,ay_emul=255,mdr_active=255,
dblscan=255,bw=255, tap_fast=255, joypad1=255, joypad2=255, rumble1=255, rumble2=255, joy_n=255, key_n=255, port=255, autoconf=255; dblscan=255,bw=255, tap_fast=255, joypad1=255, joypad2=255, rumble1=255, rumble2=255, joy_n=255, key_n=255, port=255, autoconf=255;
if (filename) strcpy(config_path,filename); if (filename) strcpy(config_path,filename);
else return -2;
else
{
strcpy(config_path,getenv("HOME"));
length=strlen(config_path);
if ((length>0)&&(config_path[length-1]!='/'))
strcat(config_path,"/");
strcat(config_path,"fbzx_conf");
}
fconfig = fopen(config_path,"rb"); fconfig = fopen(config_path,"rb");
if (fconfig==NULL) { if (fconfig==NULL) {
@ -816,9 +803,11 @@ int load_config(struct computer *object, char *filename) {
int main(int argc,char *argv[]) { int main(int argc,char *argv[]) {
int bucle,tstados,argumento,fullscreen,dblbuffer,hwsurface,length; int bucle,tstados,argumento,fullscreen,dblbuffer,hwsurface,length;
char gamefile[4096]; char gamefile[4096],config_path[1024] ;
word PC=0; word PC=0;
// by default, try all sound modes // by default, try all sound modes
sound_type=SOUND_AUTOMATIC; sound_type=SOUND_AUTOMATIC;
gamefile[0]=0; gamefile[0]=0;
@ -868,7 +857,14 @@ int main(int argc,char *argv[]) {
set_volume(16); set_volume(16);
// load current config // load current config
load_config(&ordenador, NULL); strcpy(config_path,getenv("HOME"));
length=strlen(config_path);
if ((length>0)&&(config_path[length-1]!='/'))
strcat(config_path,"/");
strcat(config_path,"fbzx.conf");
load_config(&ordenador, config_path);
printf("Modo: %d\n",ordenador.mode128k); printf("Modo: %d\n",ordenador.mode128k);
while(argumento<argc) { while(argumento<argc) {
if ((0==strcmp(argv[argumento],"-h"))||(0==strcmp(argv[argumento],"--help"))) { if ((0==strcmp(argv[argumento],"-h"))||(0==strcmp(argv[argumento],"--help"))) {

View File

@ -44,7 +44,7 @@ void SDL_Fullscreen_Switch(void);
void load_rom(char); void load_rom(char);
void load_main_game(char *nombre); void load_main_game(char *nombre);
int load_config(struct computer *object, char *filename); int load_config(struct computer *object, char *filename);
void save_config(struct computer *object); int save_config(struct computer *object, char *filename);
int save_config_game(struct computer *object, char *filename, int overwrite); int save_config_game(struct computer *object, char *filename, int overwrite);
FILE *myfopen(char *filename,char *mode); FILE *myfopen(char *filename,char *mode);

View File

@ -62,9 +62,9 @@ static const char *main_menu_messages[] = {
/*05*/ "Wiimote configuration", /*05*/ "Wiimote configuration",
/*06*/ "^|Wiimote1|Wiimote2", /*06*/ "^|Wiimote1|Wiimote2",
/*07*/ "Emulation settings", /*07*/ "Emulation settings",
/*08*/ "Microdrive", /*08*/ "Confs files",
/*09*/ "Tools", /*09*/ "Microdrive",
/*10*/ "Confs files", /*10*/ "Tools",
/*11*/ "Reset", /*11*/ "Reset",
/*12*/ "Help", /*12*/ "Help",
/*13*/ "Quit", /*13*/ "Quit",
@ -153,13 +153,14 @@ static const char *help_messages[] = {
}; };
static const char *confs_messages[] = { static const char *confs_messages[] = {
/*00*/ "Save general configs", /*00*/ "General configurations",
/*01*/ " ", /*01*/ "^|Load|Save|Delete",
/*02*/ "Game configurations", /*02*/ " ",
/*03*/ "^|Load|Save|Delete", /*03*/ "Game configurations",
/*04*/ " ", /*04*/ "^|Load|Save|Delete",
/*05*/ "Load confs automatically", /*05*/ " ",
/*06*/ "^|on|off", /*06*/ "Load confs automatically",
/*07*/ "^|on|off",
NULL NULL
}; };
@ -905,7 +906,7 @@ static void save_load_snapshot(int which)
} }
} }
static void save_load_configurations(int which) static void save_load_game_configurations(int which)
{ {
const char *dir = path_confs; const char *dir = path_confs;
const char *tape = ordenador.last_selected_file; const char *tape = ordenador.last_selected_file;
@ -914,18 +915,6 @@ static void save_load_configurations(int which)
char fb[81]; char fb[81];
int retorno; int retorno;
// Name (for saves) - TO CHECK
if (tape && strrchr(tape, '/'))
strncpy(fb, strrchr(tape, '/') + 1, 80);
else
strcpy(fb, "unknown");
//remove the extension
ptr = strrchr (fb, '.');
if (ptr) *ptr = 0;
snprintf(db, 255, "%s/%s.conf", dir, fb);
switch(which) switch(which)
{ {
case 2: case 2:
@ -940,7 +929,7 @@ static void save_load_configurations(int which)
{ {
if (which == 0) // Load config file if (which == 0) // Load config file
{ {
if (!load_config(&ordenador,db)) msgInfo("Configurations loaded",3000,NULL); if (!load_config(&ordenador,db)) msgInfo("Game confs loaded",3000,NULL);
break; break;
} }
else // Delete config file else // Delete config file
@ -949,18 +938,35 @@ static void save_load_configurations(int which)
free((void*)filename); free((void*)filename);
} break; } break;
case 1: // Save configuration file case 1: // Save configuration file
// Name (for game config saves) - TO CHECK
if (tape && strrchr(tape, '/'))
strncpy(fb, strrchr(tape, '/') + 1, 80);
else
{
msgInfo("No file selected",3000,NULL);
return;
}
//remove the extension
ptr = strrchr (fb, '.');
if (ptr) *ptr = 0;
snprintf(db, 255, "%s/%s.conf", dir, fb);
retorno=save_config_game(&ordenador,db,0); retorno=save_config_game(&ordenador,db,0);
switch(retorno) switch(retorno)
{ {
case 0: //OK case 0: //OK
msgInfo("Configurations saved",3000,NULL); msgInfo("Game confs saved",3000,NULL);
break; break;
case -1: case -1:
if (msgYesNo("Overwrite the exiting file?", 0, FULL_DISPLAY_X /2-160, FULL_DISPLAY_Y /2-48)) if (msgYesNo("Overwrite the exiting file?", 0, FULL_DISPLAY_X /2-160, FULL_DISPLAY_Y /2-48))
{ {
save_config_game(&ordenador,db,1); //force overwrite save_config_game(&ordenador,db,1); //force overwrite
msgInfo("Configurations saved",3000,NULL); msgInfo("Game confs saved",3000,NULL);
} }
break; break;
case -2: case -2:
@ -972,31 +978,87 @@ static void save_load_configurations(int which)
break; break;
} }
} }
static void save_load_general_configurations(int which)
{
int retorno;
unsigned char old_bw,old_model;
char config_path[1024];
int length;
FILE *fconfig;
strcpy(config_path,getenv("HOME"));
length=strlen(config_path);
if ((length>0)&&(config_path[length-1]!='/'))
strcat(config_path,"/");
strcat(config_path,"fbzx.conf");
switch(which)
{
case 2:
case 0: // Load or delete file
{
fconfig = fopen(config_path,"r");
if (fconfig==NULL)
{
msgInfo("Can not access the file",3000,NULL);
return;
}
else fclose(fconfig);
if (which == 0) // Load config file
{
old_bw = ordenador.bw;
old_model= get_machine_model();
if (!load_config(&ordenador,config_path)) msgInfo("General confs loaded",3000,NULL);
if (old_bw!=ordenador.bw) computer_set_palete();
if (old_model != get_machine_model()) ResetComputer();
break;
}
else // Delete config file
if (msgYesNo("Delete the file?", 0, FULL_DISPLAY_X /2-138, FULL_DISPLAY_Y /2-48)) unlink(config_path);
} break;
case 1: // Save configuration file
retorno=save_config(&ordenador,config_path);
switch(retorno)
{
case 0: //OK
msgInfo("General confs saved",3000,NULL);
break;
case -2:
msgInfo("Can't create file",3000,NULL);
break;
}
break;
default:
break;
}
}
static void manage_configurations() static void manage_configurations()
{ {
int opt ; int opt ;
int submenus[2]; int submenus[3];
memset(submenus, 0, sizeof(submenus)); memset(submenus, 0, sizeof(submenus));
submenus[1]=!ordenador.autoconf; submenus[2]=!ordenador.autoconf;
opt = menu_select_title("Configurations file menu", opt = menu_select_title("Configurations file menu",
confs_messages, submenus); confs_messages, submenus);
if (opt < 0) if (opt < 0)
return; return;
ordenador.autoconf=!submenus[1]; ordenador.autoconf=!submenus[2];
switch(opt) switch(opt)
{ {
case 0: // Save general configurations case 0: // Save, load and delete general configurations
save_config(&ordenador); save_load_general_configurations(submenus[0]);
msgInfo("Configurations saved",3000,NULL);
break; break;
case 2: // Save, load and delete game configurations case 3: // Save, load and delete game configurations
save_load_configurations(submenus[0]); save_load_game_configurations(submenus[1]);
break; break;
default: default:
break; break;
@ -1038,13 +1100,13 @@ void main_menu()
emulation_settings(); emulation_settings();
break; break;
case 8: case 8:
microdrive(); manage_configurations();
break; break;
case 9: case 9:
tools(); microdrive();
break; break;
case 10: case 10:
manage_configurations(); tools();
break; break;
case 11: case 11:
ResetComputer (); ResetComputer ();
@ -1064,7 +1126,7 @@ void main_menu()
default: default:
break; break;
} }
} while (opt == 5 || opt == 7 || opt == 8 || opt == 12); } while (opt == 5 || opt == 7 || opt == 9 || opt == 12);
clean_screen(); clean_screen();

View File

@ -0,0 +1,73 @@
File formats
============
tests.in
--------
Each test has the format:
<arbitrary test description>
AF BC DE HL AF' BC' DE' HL' IX IY SP PC
I R IFF1 IFF2 IM <halted> <tstates>
<halted> specifies whether the Z80 is halted.
<tstates> specifies the number of tstates to run the test for, in
decimal; the number actually executed may be higher, as the final
instruction is allowed to complete.
Then followed by lines specifying the initial memory setup. Each has
the format:
<start address> <byte1> <byte2> ... -1
eg
1234 56 78 9a -1
says to put 0x56 at 0x1234, 0x78 at 0x1235 and 0x9a at 0x1236.
Finally, -1 to end the test. Blank lines may follow before the next test.
tests.expected
--------------
Each test output starts with the test description, followed by a list
of 'events': each has the format
<time> <type> <address> <data>
<time> is simply the time at which the event occurs.
<type> is one of MR (memory read), MW (memory write), MC (memory
contend), PR (port read), PW (port write) or PC (port contend).
<address> is the address (or IO port) affected.
<data> is the byte written or read. Missing for contentions.
After that, lines specifying AF, BC etc as for .in files. <tstates>
now specifies the final time.
After that, lines specifying which bits of memory have changed since
the initial setup. Same format as for .in files.
Why some specific tests are here
================================
37_{1,2,3}: check the behaviour of SCF with respect to bits 3 and 5
(bug fixed on 20040225).
cb{4,5,6,7}{7,f}_1: designed to check that bits 3 and 5 are copied to
F only for BIT 3,<arg> and BIT 5,<arg> respectively
(bug fixed on 20040225).
However, later research has revealed the bits 3
and 5 are copied on all BIT instructions, so these
tests are now essentially redundant.
d{3,b}_{1,2,3}: check for correct port contention on IO in the four
relevant states (port high byte in 0x40 to 0x7f or not,
port low bit set or reset).
dd00.in, ddfd00.in: test timings of "extended NOP" opcodes DD 00 and
DD FD 00; the extra 00 at the end is to check the
next opcode executes at the right time (bug fixed
on 20060722).