From b81feb357351541486cace12d0df7e3e1e696e2f Mon Sep 17 00:00:00 2001 From: "fabio.olimpieri" Date: Sat, 26 May 2012 13:03:17 +0000 Subject: [PATCH] Added general configuration management --- src/emulator.c | 40 +++++------ src/emulator.h | 2 +- src/gui_sdl.c | 140 ++++++++++++++++++++++++++---------- src/z80free/README_test.txt | 73 +++++++++++++++++++ 4 files changed, 193 insertions(+), 62 deletions(-) create mode 100644 src/z80free/README_test.txt diff --git a/src/emulator.c b/src/emulator.c index 97b9f17..5cb5c5e 100644 --- a/src/emulator.c +++ b/src/emulator.c @@ -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; 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"); - fconfig = fopen(config_path,"wb"); + fconfig = fopen(filename,"wb"); if (fconfig==NULL) { - return; + return -2; // can't create file } + fprintf(fconfig,"mode=%c%c",48+object->mode128k,10); fprintf(fconfig,"issue=%c%c",48+object->issue,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); fclose(fconfig); + return 0; } @@ -642,21 +637,13 @@ int load_config(struct computer *object, char *filename) { char config_path[1024]; char line[1024],carac,done; - int length,pos, key_sdl=0; + int pos, key_sdl=0; FILE *fconfig; 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; if (filename) strcpy(config_path,filename); - - 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"); - } + else return -2; fconfig = fopen(config_path,"rb"); if (fconfig==NULL) { @@ -816,8 +803,10 @@ int load_config(struct computer *object, char *filename) { int main(int argc,char *argv[]) { int bucle,tstados,argumento,fullscreen,dblbuffer,hwsurface,length; - char gamefile[4096]; + char gamefile[4096],config_path[1024] ; + word PC=0; + // by default, try all sound modes sound_type=SOUND_AUTOMATIC; @@ -868,7 +857,14 @@ int main(int argc,char *argv[]) { set_volume(16); // 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); while(argumento0)&&(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() { int opt ; - int submenus[2]; + int submenus[3]; memset(submenus, 0, sizeof(submenus)); - submenus[1]=!ordenador.autoconf; + submenus[2]=!ordenador.autoconf; opt = menu_select_title("Configurations file menu", confs_messages, submenus); if (opt < 0) return; - ordenador.autoconf=!submenus[1]; + ordenador.autoconf=!submenus[2]; switch(opt) { - case 0: // Save general configurations - save_config(&ordenador); - msgInfo("Configurations saved",3000,NULL); + case 0: // Save, load and delete general configurations + save_load_general_configurations(submenus[0]); break; - case 2: // Save, load and delete game configurations - save_load_configurations(submenus[0]); + case 3: // Save, load and delete game configurations + save_load_game_configurations(submenus[1]); break; default: break; @@ -1038,13 +1100,13 @@ void main_menu() emulation_settings(); break; case 8: - microdrive(); + manage_configurations(); break; case 9: - tools(); + microdrive(); break; case 10: - manage_configurations(); + tools(); break; case 11: ResetComputer (); @@ -1064,7 +1126,7 @@ void main_menu() default: break; } - } while (opt == 5 || opt == 7 || opt == 8 || opt == 12); + } while (opt == 5 || opt == 7 || opt == 9 || opt == 12); clean_screen(); diff --git a/src/z80free/README_test.txt b/src/z80free/README_test.txt new file mode 100644 index 0000000..798d7a6 --- /dev/null +++ b/src/z80free/README_test.txt @@ -0,0 +1,73 @@ +File formats +============ + +tests.in +-------- + +Each test has the format: + + +AF BC DE HL AF' BC' DE' HL' IX IY SP PC +I R IFF1 IFF2 IM + + specifies whether the Z80 is halted. + 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: + + ... -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 + +