This repository has been archived on 2025-05-24. You can view files and clone it, but cannot push or open issues or pull requests.
Files
VARCem/src/win/win_settings.c

678 lines
17 KiB
C
Raw Normal View History

2018-02-20 21:44:51 -05:00
/*
2018-03-08 15:58:46 -05:00
* VARCem Virtual ARchaeological Computer EMulator.
2018-02-20 21:44:51 -05:00
* An emulator of (mostly) x86-based PC systems and devices,
* using the ISA,EISA,VLB,MCA and PCI system buses, roughly
* spanning the era between 1981 and 1995.
*
* This file is part of the VARCem Project.
*
* Implementation of the Settings dialog.
*
* Version: @(#)win_settings.c 1.0.24 2018/04/26
2018-02-20 21:44:51 -05:00
*
* Authors: Fred N. van Kempen, <decwiz@yahoo.com>
* Miran Grca, <mgrca8@gmail.com>
*
* Copyright 2017,2018 Fred N. van Kempen.
* Copyright 2016-2018 Miran Grca.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the:
*
* Free Software Foundation, Inc.
* 59 Temple Place - Suite 330
* Boston, MA 02111-1307
* USA.
*/
#define UNICODE
#define WIN32_LEAN_AND_MEAN
2018-02-20 21:44:51 -05:00
#include <windows.h>
#include <commctrl.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
2018-02-20 21:44:51 -05:00
#include <string.h>
#include <wchar.h>
#include "../emu.h"
#include "../config.h"
#include "../cpu/cpu.h"
#include "../mem.h"
#include "../rom.h"
#include "../device.h"
#include "../nvr.h"
#include "../machine/machine.h"
#include "../ports/game_dev.h"
#include "../ports/parallel.h"
#include "../ports/parallel_dev.h"
#include "../ports/serial.h"
#include "../input/mouse.h"
#include "../input/game/joystick.h"
#include "../floppy/fdd.h"
2018-02-20 21:44:51 -05:00
#include "../disk/hdd.h"
#include "../disk/hdc.h"
#include "../disk/hdc_ide.h"
#include "../disk/zip.h"
#include "../cdrom/cdrom.h"
2018-02-20 21:44:51 -05:00
#include "../scsi/scsi.h"
#include "../network/network.h"
#include "../sound/sound.h"
#include "../sound/midi.h"
#include "../sound/snd_mpu401.h"
#include "../video/video.h"
#include "../plat.h"
#include "../ui.h"
#include "win.h"
/* Defined in the Video module. */
extern const device_t voodoo_device;
/* Machine category. */
static int temp_machine,
temp_cpu_m, temp_cpu, temp_wait_states,
temp_mem_size, temp_fpu, temp_sync;
2018-02-20 21:44:51 -05:00
#ifdef USE_DYNAREC
static int temp_dynarec;
2018-02-20 21:44:51 -05:00
#endif
/* Video category. */
static int temp_video_card, temp_video_speed, temp_voodoo;
2018-02-20 21:44:51 -05:00
/* Input devices category. */
static int temp_mouse, temp_joystick;
2018-02-20 21:44:51 -05:00
/* Sound category. */
static int temp_sound_card, temp_midi_device, temp_mpu401,
2018-04-08 21:19:10 -04:00
temp_opl3_type, temp_float;
2018-02-20 21:44:51 -05:00
/* Network category. */
static int temp_net_type, temp_net_card;
static char temp_host_dev[128];
2018-02-20 21:44:51 -05:00
/* Ports category. */
static int temp_game,
temp_serial[SERIAL_MAX],
temp_parallel[PARALLEL_MAX],
temp_parallel_device[PARALLEL_MAX];
2018-02-20 21:44:51 -05:00
/* Other peripherals category. */
static int temp_hdc_type,
temp_scsi_card,
temp_ide_ter, temp_ide_ter_irq,
temp_ide_qua, temp_ide_qua_irq;
static int temp_bugger;
2018-02-20 21:44:51 -05:00
/* Floppy drives category. */
static int temp_fdd_types[FDD_NUM],
temp_fdd_turbo[FDD_NUM],
temp_fdd_check_bpb[FDD_NUM];
2018-02-20 21:44:51 -05:00
/* Hard disks category. */
2018-02-20 21:44:51 -05:00
static hard_disk_t temp_hdd[HDD_NUM];
/* Other removable devices category. */
2018-02-20 21:44:51 -05:00
static cdrom_drive_t temp_cdrom_drives[CDROM_NUM];
static zip_drive_t temp_zip_drives[ZIP_NUM];
static HWND hwndParentDialog,
hwndChildDialog;
static int displayed_category = 0;
static int ask_sure = 0;
static uint8_t temp_deviceconfig;
2018-02-20 21:44:51 -05:00
/* Show a MessageBox dialog. This is nasty, I know. --FvK */
static int
settings_msgbox(int type, void *arg)
{
HWND h;
int i;
h = hwndMain;
hwndMain = hwndParentDialog;
i = ui_msgbox(type, arg);
hwndMain = h;
return(i);
}
/* Load the per-page dialogs. */
#include "win_settings_machine.h" /* Machine dialog */
#include "win_settings_video.h" /* Video dialog */
#include "win_settings_input.h" /* Input dialog */
#include "win_settings_sound.h" /* Sound dialog */
#include "win_settings_ports.h" /* Ports dialog */
#include "win_settings_periph.h" /* Other Peripherals dialog */
#include "win_settings_network.h" /* Network dialog */
#include "win_settings_floppy.h" /* Floppy dialog */
#include "win_settings_disk.h" /* (Hard) Disk dialog */
#include "win_settings_remov.h" /* Removable Devices dialog */
2018-02-20 21:44:51 -05:00
/* This does the initial read of global variables into the temporary ones. */
static void
settings_init(void)
2018-02-20 21:44:51 -05:00
{
int i = 0;
/* Machine category */
temp_machine = machine;
temp_cpu_m = cpu_manufacturer;
temp_wait_states = cpu_waitstates;
temp_cpu = cpu;
temp_mem_size = mem_size;
2018-02-20 21:44:51 -05:00
#ifdef USE_DYNAREC
temp_dynarec = cpu_use_dynarec;
2018-02-20 21:44:51 -05:00
#endif
temp_fpu = enable_external_fpu;
temp_sync = enable_sync;
/* Video category */
temp_video_card = video_card;
temp_video_speed = video_speed;
temp_voodoo = voodoo_enabled;
/* Input devices category */
temp_mouse = mouse_type;
temp_joystick = joystick_type;
/* Sound category */
temp_sound_card = sound_card;
temp_midi_device = midi_device;
temp_mpu401 = mpu401_standalone_enable;
temp_opl3_type = opl3_type;
temp_float = sound_is_float;
/* Network category */
temp_net_type = network_type;
memset(temp_host_dev, 0, sizeof(temp_host_dev));
strcpy(temp_host_dev, network_host);
temp_net_card = network_card;
/* Ports category */
temp_game = game_enabled;
for (i = 0; i < SERIAL_MAX; i++)
temp_serial[i] = serial_enabled[i];
for (i = 0; i < PARALLEL_MAX; i++) {
temp_parallel[i] = parallel_enabled[i];
temp_parallel_device[i] = parallel_device[i];
}
/* Other peripherals category */
temp_scsi_card = scsi_card;
temp_hdc_type = hdc_type;
temp_ide_ter = ide_enable[2];
temp_ide_ter_irq = ide_irq[2];
temp_ide_qua = ide_enable[3];
temp_ide_qua_irq = ide_irq[3];
temp_bugger = bugger_enabled;
/* Floppy drives category */
for (i=0; i<FDD_NUM; i++) {
temp_fdd_types[i] = fdd_get_type(i);
temp_fdd_turbo[i] = fdd_get_turbo(i);
temp_fdd_check_bpb[i] = fdd_get_check_bpb(i);
}
/* Hard disks category */
memcpy(temp_hdd, hdd, HDD_NUM * sizeof(hard_disk_t));
/* Other removable devices category */
memcpy(temp_cdrom_drives, cdrom_drives, CDROM_NUM * sizeof(cdrom_drive_t));
memcpy(temp_zip_drives, zip_drives, ZIP_NUM * sizeof(zip_drive_t));
temp_deviceconfig = 0;
2018-02-20 21:44:51 -05:00
}
/* This returns 1 if any variable has changed, 0 if not. */
static int
settings_changed(void)
2018-02-20 21:44:51 -05:00
{
int i = 0, j;
/* Machine category */
i = i || (machine != temp_machine);
i = i || (cpu_manufacturer != temp_cpu_m);
i = i || (cpu_waitstates != temp_wait_states);
i = i || (cpu != temp_cpu);
i = i || (mem_size != temp_mem_size);
2018-02-20 21:44:51 -05:00
#ifdef USE_DYNAREC
i = i || (temp_dynarec != cpu_use_dynarec);
2018-02-20 21:44:51 -05:00
#endif
i = i || (temp_fpu != enable_external_fpu);
i = i || (temp_sync != enable_sync);
/* Video category */
i = i || (video_card != temp_video_card);
i = i || (video_speed != temp_video_speed);
i = i || (voodoo_enabled != temp_voodoo);
/* Input devices category */
i = i || (mouse_type != temp_mouse);
i = i || (joystick_type != temp_joystick);
/* Sound category */
i = i || (sound_card != temp_sound_card);
i = i || (midi_device != temp_midi_device);
i = i || (mpu401_standalone_enable != temp_mpu401);
i = i || (opl3_type != temp_opl3_type);
i = i || (sound_is_float != temp_float);
/* Network category */
i = i || (network_type != temp_net_type);
i = i || strcmp(temp_host_dev, network_host);
i = i || (network_card != temp_net_card);
/* Ports category */
i = i || (temp_game != game_enabled);
for (j = 0; j < SERIAL_MAX; j++)
i = i || (temp_serial[j] != serial_enabled[j]);
for (j = 0; j < PARALLEL_MAX; j++) {
i = i || (temp_parallel[j] != parallel_enabled[j]);
i = i || (temp_parallel_device[j] != parallel_device[j]);
}
/* Peripherals category */
i = i || (temp_scsi_card != scsi_card);
i = i || (temp_hdc_type != hdc_type);
i = i || (temp_ide_ter != ide_enable[2]);
i = i || (temp_ide_ter_irq != ide_irq[2]);
i = i || (temp_ide_qua != ide_enable[3]);
i = i || (temp_ide_qua_irq != ide_irq[3]);
i = i || (temp_bugger != bugger_enabled);
/* Hard disks category */
i = i || memcmp(hdd, temp_hdd, HDD_NUM * sizeof(hard_disk_t));
/* Floppy drives category */
for (j=0; j<FDD_NUM; j++) {
i = i || (temp_fdd_types[j] != fdd_get_type(j));
i = i || (temp_fdd_turbo[j] != fdd_get_turbo(j));
i = i || (temp_fdd_check_bpb[j] != fdd_get_check_bpb(j));
}
/* Other removable devices category */
i = i || memcmp(cdrom_drives, temp_cdrom_drives, CDROM_NUM * sizeof(cdrom_drive_t));
i = i || memcmp(zip_drives, temp_zip_drives, ZIP_NUM * sizeof(zip_drive_t));
i = i || !!temp_deviceconfig;
2018-02-20 21:44:51 -05:00
return(i);
2018-02-20 21:44:51 -05:00
}
static int
msgbox_reset(void)
2018-02-20 21:44:51 -05:00
{
int changed = 0;
int i = 0;
2018-02-20 21:44:51 -05:00
changed = settings_changed();
2018-02-20 21:44:51 -05:00
if (changed) {
i = settings_msgbox(MBX_QUESTION, (wchar_t *)IDS_2052);
2018-02-20 21:44:51 -05:00
if (i == 1) return(1); /* no */
2018-02-20 21:44:51 -05:00
if (i < 0) return(0); /* cancel */
2018-02-20 21:44:51 -05:00
return(2); /* yes */
} else {
return(1);
}
2018-02-20 21:44:51 -05:00
}
/* This saves the settings back to the global variables. */
static void
settings_save(void)
2018-02-20 21:44:51 -05:00
{
int i;
2018-02-20 21:44:51 -05:00
pc_reset_hard_close();
2018-02-20 21:44:51 -05:00
/* Machine category */
machine = temp_machine;
romset = machine_getromset();
cpu_manufacturer = temp_cpu_m;
cpu_waitstates = temp_wait_states;
cpu = temp_cpu;
mem_size = temp_mem_size;
2018-02-20 21:44:51 -05:00
#ifdef USE_DYNAREC
cpu_use_dynarec = temp_dynarec;
2018-02-20 21:44:51 -05:00
#endif
enable_external_fpu = temp_fpu;
enable_sync = temp_sync;
/* Video category */
video_card = temp_video_card;
video_speed = temp_video_speed;
voodoo_enabled = temp_voodoo;
/* Input devices category */
mouse_type = temp_mouse;
joystick_type = temp_joystick;
/* Sound category */
sound_card = temp_sound_card;
midi_device = temp_midi_device;
mpu401_standalone_enable = temp_mpu401;
opl3_type = temp_opl3_type;
sound_is_float = temp_float;
/* Network category */
network_type = temp_net_type;
memset(network_host, '\0', sizeof(network_host));
strcpy(network_host, temp_host_dev);
network_card = temp_net_card;
/* Ports category */
game_enabled = temp_game;
for (i = 0; i < SERIAL_MAX; i++)
serial_enabled[i] = temp_serial[i];
for (i = 0; i < PARALLEL_MAX; i++) {
parallel_enabled[i] = temp_parallel[i];
parallel_device[i] = temp_parallel_device[i];
}
/* Peripherals category */
scsi_card = temp_scsi_card;
hdc_type = temp_hdc_type;
ide_enable[2] = temp_ide_ter;
ide_irq[2] = temp_ide_ter_irq;
ide_enable[3] = temp_ide_qua;
ide_irq[3] = temp_ide_qua_irq;
bugger_enabled = temp_bugger;
/* Hard disks category */
memcpy(hdd, temp_hdd, HDD_NUM * sizeof(hard_disk_t));
/* Floppy drives category */
for (i=0; i<FDD_NUM; i++) {
fdd_set_type(i, temp_fdd_types[i]);
fdd_set_turbo(i, temp_fdd_turbo[i]);
fdd_set_check_bpb(i, temp_fdd_check_bpb[i]);
}
/* Removable devices category */
memcpy(cdrom_drives, temp_cdrom_drives, CDROM_NUM * sizeof(cdrom_drive_t));
memcpy(zip_drives, temp_zip_drives, ZIP_NUM * sizeof(zip_drive_t));
/* Mark configuration as changed. */
config_changed = 1;
2018-02-20 21:44:51 -05:00
}
/************************************************************************
* *
* Main Settings Dialog *
* *
************************************************************************/
#define PAGE_MACHINE 0
#define PAGE_VIDEO 1
#define PAGE_INPUT 2
#define PAGE_SOUND 3
#define PAGE_NETWORK 4
#define PAGE_PORTS 5
#define PAGE_PERIPHERALS 6
#define PAGE_HARD_DISKS 7
#define PAGE_FLOPPY_DRIVES 8
#define PAGE_OTHER_REMOVABLE_DEVICES 9
static void
show_child(HWND hwndParent, DWORD child_id)
2018-02-20 21:44:51 -05:00
{
if (child_id == displayed_category) return;
2018-02-20 21:44:51 -05:00
displayed_category = child_id;
2018-02-20 21:44:51 -05:00
SendMessage(hwndChildDialog, WM_SAVESETTINGS, 0, 0);
2018-02-20 21:44:51 -05:00
DestroyWindow(hwndChildDialog);
switch(child_id) {
case PAGE_MACHINE:
hwndChildDialog = CreateDialog(hinstance,
(LPCWSTR)DLG_CFG_MACHINE,
hwndParent, machine_proc);
break;
case PAGE_VIDEO:
hwndChildDialog = CreateDialog(hinstance,
(LPCWSTR)DLG_CFG_VIDEO,
hwndParent, video_proc);
break;
case PAGE_INPUT:
hwndChildDialog = CreateDialog(hinstance,
(LPCWSTR)DLG_CFG_INPUT,
hwndParent, input_proc);
break;
case PAGE_SOUND:
hwndChildDialog = CreateDialog(hinstance,
(LPCWSTR)DLG_CFG_SOUND,
hwndParent, sound_proc);
break;
case PAGE_NETWORK:
hwndChildDialog = CreateDialog(hinstance,
(LPCWSTR)DLG_CFG_NETWORK,
hwndParent, network_proc);
break;
2018-02-20 21:44:51 -05:00
case PAGE_PORTS:
hwndChildDialog = CreateDialog(hinstance,
(LPCWSTR)DLG_CFG_PORTS,
hwndParent, ports_proc);
break;
case PAGE_PERIPHERALS:
hwndChildDialog = CreateDialog(hinstance,
(LPCWSTR)DLG_CFG_PERIPHERALS,
hwndParent, peripherals_proc);
break;
case PAGE_HARD_DISKS:
hwndChildDialog = CreateDialog(hinstance,
(LPCWSTR)DLG_CFG_DISK,
hwndParent, disk_proc);
break;
case PAGE_FLOPPY_DRIVES:
hwndChildDialog = CreateDialog(hinstance,
(LPCWSTR)DLG_CFG_FLOPPY,
hwndParent, floppy_proc);
break;
case PAGE_OTHER_REMOVABLE_DEVICES:
hwndChildDialog = CreateDialog(hinstance,
(LPCWSTR)DLG_CFG_RMV_DEVICES,
hwndParent, rmv_devices_proc);
break;
default:
fatal("Invalid child dialog ID\n");
return;
}
ShowWindow(hwndChildDialog, SW_SHOWNORMAL);
2018-02-20 21:44:51 -05:00
}
static BOOL
image_list_init(HWND hwndList)
{
HICON hiconItem;
HIMAGELIST hSmall;
int i = 0;
2018-02-20 21:44:51 -05:00
hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON),
GetSystemMetrics(SM_CYSMICON),
ILC_MASK | ILC_COLOR32, 1, 1);
2018-02-20 21:44:51 -05:00
for (i=0; i<10; i++) {
hiconItem = LoadIcon(hinstance, (LPCWSTR) (256 + (uintptr_t) i));
ImageList_AddIcon(hSmall, hiconItem);
DestroyIcon(hiconItem);
}
2018-02-20 21:44:51 -05:00
ListView_SetImageList(hwndList, hSmall, LVSIL_SMALL);
2018-02-20 21:44:51 -05:00
return(TRUE);
2018-02-20 21:44:51 -05:00
}
static BOOL
insert_categories(HWND hwndList)
2018-02-20 21:44:51 -05:00
{
LVITEM lvI;
int i = 0;
2018-02-20 21:44:51 -05:00
lvI.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE;
lvI.stateMask = lvI.iSubItem = lvI.state = 0;
2018-02-20 21:44:51 -05:00
for (i=0; i<10; i++) {
lvI.pszText = plat_get_string(IDS_2065+i);
lvI.iItem = i;
lvI.iImage = i;
2018-02-20 21:44:51 -05:00
if (ListView_InsertItem(hwndList, &lvI) == -1)
return(FALSE);
}
2018-02-20 21:44:51 -05:00
return(TRUE);
2018-02-20 21:44:51 -05:00
}
2018-02-20 21:44:51 -05:00
#ifdef __amd64__
static LRESULT CALLBACK
#else
static BOOL CALLBACK
#endif
settings_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
2018-02-20 21:44:51 -05:00
{
HWND h;
int category;
int i = 0;
int j = 0;
hwndParentDialog = hdlg;
switch (message) {
case WM_INITDIALOG:
settings_init();
disk_track_init();
cdrom_track_init();
zip_track_init();
displayed_category = -1;
h = GetDlgItem(hdlg, IDC_SETTINGSCATLIST);
image_list_init(h);
insert_categories(h);
ListView_SetItemState(h, 0, LVIS_FOCUSED|LVIS_SELECTED, 0x000F);
2018-02-20 21:44:51 -05:00
#if 0
/*Leave this commented out until we do localization. */
h = GetDlgItem(hdlg, IDC_COMBO_LANG); /* This is currently disabled, I am going to add localization options in the future. */
EnableWindow(h, FALSE);
ShowWindow(h, SW_HIDE);
h = GetDlgItem(hdlg, IDS_LANG_ENUS); /*was:2047 !*/
EnableWindow(h, FALSE);
ShowWindow(h, SW_HIDE);
2018-02-20 21:44:51 -05:00
#endif
return(TRUE);
case WM_NOTIFY:
if ((((LPNMHDR)lParam)->code == LVN_ITEMCHANGED) && (((LPNMHDR)lParam)->idFrom == IDC_SETTINGSCATLIST)) {
category = -1;
for (i=0; i<10; i++) {
h = GetDlgItem(hdlg, IDC_SETTINGSCATLIST);
j = ListView_GetItemState(h, i, LVIS_SELECTED);
if (j) category = i;
}
if (category != -1)
show_child(hdlg, category);
}
break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
SendMessage(hwndChildDialog, WM_SAVESETTINGS, 0, 0);
if (ask_sure) {
i = msgbox_reset();
if (i == 0) {
/* CANCEL, just kidding! */
return(FALSE);
2018-02-20 21:44:51 -05:00
}
} else {
i = 2;
2018-02-20 21:44:51 -05:00
}
if (i == 2) {
/* YES, reset system. */
settings_save();
2018-02-20 21:44:51 -05:00
}
DestroyWindow(hwndChildDialog);
EndDialog(hdlg, i);
return(TRUE);
2018-02-20 21:44:51 -05:00
case IDCANCEL:
DestroyWindow(hwndChildDialog);
EndDialog(hdlg, 0);
return(TRUE);
}
break;
default:
return(FALSE);
}
return(FALSE);
2018-02-20 21:44:51 -05:00
}
int
win_settings_open(HWND hwnd, int ask)
2018-02-20 21:44:51 -05:00
{
int i, m, v;
/* Enumerate the available machines. */
m = machine_detect();
/* Enumerate the available video cards. */
v = video_detect();
if (m == 0 || v == 0) {
ui_msgbox(MBX_ERROR|MBX_FATAL, (wchar_t *)IDS_2056);
return(0);
}
ask_sure = ask;
i = DialogBox(hinstance, (LPCWSTR)DLG_CONFIG, hwnd, settings_proc);
return(i);
2018-02-20 21:44:51 -05:00
}