From 8538116c197ef3977ab7d437599a6f51c37b84e2 Mon Sep 17 00:00:00 2001 From: SarahW Date: Thu, 4 May 2017 18:27:10 +0100 Subject: [PATCH] Initial commit for config rework. Work in progress! --- configs/configs.txt | 1 + src/ibm.h | 3 +- src/mem.c | 6 ++- src/pc.c | 30 ++++++++----- src/pc.rc | 15 ++++++- src/resources.h | 6 ++- src/win-config.c | 21 ++++++--- src/win-deviceconfig.c | 2 +- src/win-hdconf.c | 4 +- src/win.c | 100 ++++++++++++++++++++++++----------------- src/win.h | 6 ++- 11 files changed, 125 insertions(+), 69 deletions(-) create mode 100644 configs/configs.txt diff --git a/configs/configs.txt b/configs/configs.txt new file mode 100644 index 0000000..f2396cc --- /dev/null +++ b/configs/configs.txt @@ -0,0 +1 @@ +This directory is used to store config files. \ No newline at end of file diff --git a/src/ibm.h b/src/ibm.h index 559ef45..a59c16e 100644 --- a/src/ibm.h +++ b/src/ibm.h @@ -559,6 +559,7 @@ void resetpc(); void resetpchard(); void speedchanged(); -void saveconfig(); +void saveconfig(char *fn); +void getpath(); #define UNUSED(x) (void)x diff --git a/src/mem.c b/src/mem.c index 20279cd..ecfc949 100644 --- a/src/mem.c +++ b/src/mem.c @@ -54,7 +54,7 @@ uint32_t biosmask; int readlnum=0,writelnum=0; int cachesize=256; -uint8_t *ram,*rom; +uint8_t *ram, *rom = NULL; uint8_t romext[32768]; static void mem_load_atide115_bios() @@ -81,6 +81,8 @@ int loadbios() biosmask = 0xffff; + if (!rom) + rom = malloc(0x20000); memset(romext,0x63,0x4000); memset(rom, 0xff, 0x20000); @@ -1774,7 +1776,7 @@ void mem_init() int c; ram = malloc((mem_size + 384) * 1024); - rom = malloc(0x20000); +// rom = malloc(0x20000); readlookup2 = malloc(1024 * 1024 * sizeof(uintptr_t)); writelookup2 = malloc(1024 * 1024 * sizeof(uintptr_t)); biosmask = 0xffff; diff --git a/src/pc.c b/src/pc.c index 547d50b..48a6767 100644 --- a/src/pc.c +++ b/src/pc.c @@ -69,7 +69,7 @@ int framecount,fps; int output; int atfullspeed; -void saveconfig(); +void saveconfig(char *fn); int infocus; int mousecapture; FILE *pclogf; @@ -202,17 +202,23 @@ void pc_reset() // video_init(); } #undef printf -void initpc(int argc, char *argv[]) +void getpath() { char *p; - char *config_file = NULL; - int c; -// allegro_init(); + get_executable_name(pcempath,511); pclog("executable_name = %s\n", pcempath); p=get_filename(pcempath); *p=0; pclog("path = %s\n", pcempath); +} + +void initpc(int argc, char *argv[]) +{ + //char *p; + char *config_file = NULL; + int c; +// allegro_init(); for (c = 1; c < argc; c++) { @@ -241,12 +247,12 @@ void initpc(int argc, char *argv[]) joystick_init(); midi_init(); - append_filename(config_file_default, pcempath, "pcem.cfg", 511); +// append_filename(config_file_default, pcempath, "pcem.cfg", 511); loadconfig(config_file); pclog("Config loaded\n"); - if (config_file) - saveconfig(); +// if (config_file) +// saveconfig(); cpuspeed2=(AT)?2:1; // cpuspeed2=cpuspeed; @@ -713,7 +719,7 @@ void loadconfig(char *fn) enable_sync = config_get_int(NULL, "enable_sync", 1); } -void saveconfig() +void saveconfig(char *fn) { int c, d; @@ -810,5 +816,9 @@ void saveconfig() config_set_int(NULL, "enable_sync", enable_sync); - config_save(config_file_default); + pclog("config_save(%s)\n", config_file_default); + if (fn) + config_save(fn); + else + config_save(config_file_default); } diff --git a/src/pc.rc b/src/pc.rc index a5a35b5..d581364 100644 --- a/src/pc.rc +++ b/src/pc.rc @@ -54,8 +54,7 @@ BEGIN MENUITEM "Disc activity indicator", IDM_VID_DISC END MENUITEM SEPARATOR - MENUITEM "&Load configuration...", IDM_CONFIG_LOAD - MENUITEM "&Save configuration...", IDM_CONFIG_SAVE + MENUITEM "&Select configuration...", IDM_CONFIG_SELECT END POPUP "&Misc" BEGIN @@ -317,3 +316,15 @@ BEGIN COMBOBOX IDC_HDTYPE, 7,54,172,120,CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP END + +ConfigureSelectionDlg DIALOGEX 0, 0, 200, 150 +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU +CAPTION "Select Configuration" +FONT 8, "MS Sans Serif" +BEGIN + DEFPUSHBUTTON "OK", IDOK, 200-54, 4, 50, 14, WS_TABSTOP + DEFPUSHBUTTON "Cancel", IDCANCEL, 200-54,22, 50, 14, WS_TABSTOP + DEFPUSHBUTTON "New...", IDC_NEW, 200-54,40, 50, 14, WS_TABSTOP + + LISTBOX IDC_LIST, 4, 4,140,142, WS_TABSTOP +END diff --git a/src/resources.h b/src/resources.h index f5f3cd1..bc4184b 100644 --- a/src/resources.h +++ b/src/resources.h @@ -9,8 +9,7 @@ #define IDM_HDCONF 40014 #define IDM_BPB_DISABLE 40015 #define IDM_CONFIG 40020 -#define IDM_CONFIG_LOAD 40021 -#define IDM_CONFIG_SAVE 40022 +#define IDM_CONFIG_SELECT 40021 #define IDM_STATUS 40030 #define IDM_VID_RESIZE 40050 #define IDM_VID_REMEMBER 40051 @@ -134,3 +133,6 @@ #define WM_RESETD3D WM_USER #define WM_LEAVEFULLSCREEN WM_USER + 1 + +#define IDC_NEW 1200 +#define IDC_LIST 1201 diff --git a/src/win-config.c b/src/win-config.c index 02a25d2..e03f0aa 100644 --- a/src/win-config.c +++ b/src/win-config.c @@ -27,6 +27,8 @@ static int settings_sound_to_list[20], settings_list_to_sound[20]; static int settings_mouse_to_list[20], settings_list_to_mouse[20]; static char *hdd_names[16]; +static int has_been_inited = 0; + static int mouse_valid(int type, int model) { if ((type & MOUSE_TYPE_IF_MASK) == MOUSE_TYPE_PS2 && !(models[model].flags & MODEL_PS2)) @@ -471,7 +473,7 @@ static BOOL CALLBACK config_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPAR temp_fda_type != fdd_get_type(0) || temp_fdb_type != fdd_get_type(1) || temp_mouse_type != mouse_type || hdd_changed) { - if (MessageBox(NULL,"This will reset PCem!\nOkay to continue?","PCem",MB_OKCANCEL)==IDOK) + if (!has_been_inited || MessageBox(NULL,"This will reset PCem!\nOkay to continue?","PCem",MB_OKCANCEL)==IDOK) { savenvr(); model = temp_model; @@ -496,10 +498,12 @@ static BOOL CALLBACK config_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPAR else strcpy(hdd_controller_name, "none"); - - mem_resize(); - loadbios(); - resetpchard(); + if (has_been_inited) + { + mem_resize(); + loadbios(); + resetpchard(); + } } else { @@ -520,7 +524,8 @@ static BOOL CALLBACK config_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPAR cpu_waitstates = SendMessage(h, CB_GETCURSEL, 0, 0); cpu_update_waitstates(); - saveconfig(); + if (has_been_inited) + saveconfig(NULL); speedchanged(); @@ -810,7 +815,9 @@ static BOOL CALLBACK config_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPAR return FALSE; } -void config_open(HWND hwnd) +void config_open(HWND hwnd, int inited) { + has_been_inited = inited; + DialogBox(hinstance, TEXT("ConfigureDlg"), hwnd, (DLGPROC)config_dlgproc); } diff --git a/src/win-deviceconfig.c b/src/win-deviceconfig.c index 5481269..50fe626 100644 --- a/src/win-deviceconfig.c +++ b/src/win-deviceconfig.c @@ -178,7 +178,7 @@ static BOOL CALLBACK deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam config++; } - saveconfig(); + saveconfig(NULL); resetpchard(); diff --git a/src/win-hdconf.c b/src/win-hdconf.c index add5e40..edcc586 100644 --- a/src/win-hdconf.c +++ b/src/win-hdconf.c @@ -205,7 +205,7 @@ static BOOL CALLBACK hdnew_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARA return TRUE; case IDC_CFILE: - if (!getsfile(hdlg, "Hard disc image (*.IMG)\0*.IMG\0All files (*.*)\0*.*\0", "")) + if (!getsfile(hdlg, "Hard disc image (*.IMG)\0*.IMG\0All files (*.*)\0*.*\0", "", NULL)) { h = GetDlgItem(hdlg, IDC_EDITC); SendMessage(h, WM_SETTEXT, 0, (LPARAM)openfilestring); @@ -515,7 +515,7 @@ static BOOL CALLBACK hdconf_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPAR cdrom_channel = new_cdrom_channel; - saveconfig(); + saveconfig(NULL); resetpchard(); } diff --git a/src/win.c b/src/win.c index 5cff840..c6fecf8 100644 --- a/src/win.c +++ b/src/win.c @@ -173,6 +173,7 @@ void mainthread(LPVOID param) // Sleep(500); drawits=0; old_time = GetTickCount(); + while (!quited) { if (updatestatus) @@ -555,6 +556,7 @@ int WINAPI WinMain (HINSTANCE hThisInstance, /* Make the window visible on the screen */ ShowWindow (hwnd, nFunsterStil); + ghMutex = CreateMutex(NULL, FALSE, NULL); // win_set_window(hwnd); memset(rawinputkey, 0, sizeof(rawinputkey)); @@ -571,11 +573,9 @@ int WINAPI WinMain (HINSTANCE hThisInstance, get_registry_key_map(); ghwnd=hwnd; - - initpc(argc, argv); - - vid_apis[0][vid_api].init(ghwnd); + getpath(); + if (vid_resize) SetWindowLong(hwnd, GWL_STYLE, WS_OVERLAPPEDWINDOW|WS_VISIBLE); else SetWindowLong(hwnd, GWL_STYLE, (WS_OVERLAPPEDWINDOW&~WS_SIZEBOX&~WS_THICKFRAME&~WS_MAXIMIZEBOX)|WS_VISIBLE); @@ -618,9 +618,18 @@ int WINAPI WinMain (HINSTANCE hThisInstance, } romset=d; - c=loadbios(); + + for (c = 0; c < GFX_MAX; c++) + gfx_present[c] = video_card_available(video_old_to_new(c)); - if (!c) + loadconfig(NULL); + + if (!config_selection_open(ghwnd, 0)) + return 0; + + initpc(argc, argv); + + if (!loadbios()) { if (romset!=-1) MessageBox(hwnd,"Configured romset not available.\nDefaulting to available romset.","PCem error",MB_OK); for (c=0;c