More machine abstractions.

This commit is contained in:
OBattler
2021-12-13 14:17:49 +01:00
parent b9c564c5c0
commit 8d7f42d4aa
3 changed files with 53 additions and 21 deletions

View File

@@ -201,6 +201,10 @@ extern int machine_get_nvrmask(int m);
extern int machine_has_flags(int m, int flags); extern int machine_has_flags(int m, int flags);
extern int machine_has_bus(int m, int bus_flags); extern int machine_has_bus(int m, int bus_flags);
extern int machine_has_cartridge(int m); extern int machine_has_cartridge(int m);
extern int machine_get_min_ram(int m);
extern int machine_get_max_ram(int m);
extern int machine_get_ram_granularity(int m);
extern int machine_get_type(int m);
extern void machine_close(void); extern void machine_close(void);

View File

@@ -1000,6 +1000,34 @@ machine_has_cartridge(int m)
} }
int
machine_get_min_ram(int m)
{
return(machines[m].min_ram);
}
int
machine_get_max_ram(int m)
{
return(machines[m].max_ram);
}
int
machine_get_ram_granularity(int m)
{
return(machines[m].ram_granularity);
}
int
machine_get_type(int m)
{
return(machines[m].type);
}
int int
machine_get_machine_from_internal_name(char *s) machine_get_machine_from_internal_name(char *s)
{ {

View File

@@ -318,7 +318,7 @@ win_settings_init(void)
int i = 0; int i = 0;
/* Machine category */ /* Machine category */
temp_machine_type = machines[machine].type; temp_machine_type = machine_get_type(machine);
temp_machine = machine; temp_machine = machine;
temp_cpu_f = cpu_f; temp_cpu_f = cpu_f;
temp_wait_states = cpu_waitstates; temp_wait_states = cpu_waitstates;
@@ -786,13 +786,13 @@ win_settings_machine_recalc_machine(HWND hdlg)
win_settings_machine_recalc_cpu_m(hdlg); win_settings_machine_recalc_cpu_m(hdlg);
if ((machines[temp_machine].ram_granularity & 1023)) { if (machine_get_ram_granularity(temp_machine) & 1023) {
/* KB granularity */ /* KB granularity */
h = GetDlgItem(hdlg, IDC_MEMSPIN); h = GetDlgItem(hdlg, IDC_MEMSPIN);
SendMessage(h, UDM_SETRANGE, 0, (machines[temp_machine].min_ram << 16) | machines[temp_machine].max_ram); SendMessage(h, UDM_SETRANGE, 0, (machine_get_min_ram(temp_machine) << 16) | machine_get_max_ram(temp_machine));
accel.nSec = 0; accel.nSec = 0;
accel.nInc = machines[temp_machine].ram_granularity; accel.nInc = machine_get_ram_granularity(temp_machine);
SendMessage(h, UDM_SETACCEL, 1, (LPARAM)&accel); SendMessage(h, UDM_SETACCEL, 1, (LPARAM)&accel);
SendMessage(h, UDM_SETPOS, 0, temp_mem_size); SendMessage(h, UDM_SETPOS, 0, temp_mem_size);
@@ -803,14 +803,14 @@ win_settings_machine_recalc_machine(HWND hdlg)
/* MB granularity */ /* MB granularity */
h = GetDlgItem(hdlg, IDC_MEMSPIN); h = GetDlgItem(hdlg, IDC_MEMSPIN);
#if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) #if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64))
i = MIN(machines[temp_machine].max_ram, 2097152); i = MIN(machine_get_max_ram(temp_machine), 2097152);
#else #else
i = MIN(machines[temp_machine].max_ram, 3145728); i = MIN(machine_get_max_ram(temp_machine), 3145728);
#endif #endif
SendMessage(h, UDM_SETRANGE, 0, (machines[temp_machine].min_ram << 6) | (i >> 10)); SendMessage(h, UDM_SETRANGE, 0, (machine_get_min_ram(temp_machine) << 6) | (i >> 10));
accel.nSec = 0; accel.nSec = 0;
accel.nInc = machines[temp_machine].ram_granularity >> 10; accel.nInc = machine_get_ram_granularity(temp_machine) >> 10;
SendMessage(h, UDM_SETACCEL, 1, (LPARAM)&accel); SendMessage(h, UDM_SETACCEL, 1, (LPARAM)&accel);
@@ -820,8 +820,8 @@ win_settings_machine_recalc_machine(HWND hdlg)
SendMessage(h, WM_SETTEXT, 0, win_get_string(IDS_2086)); SendMessage(h, WM_SETTEXT, 0, win_get_string(IDS_2086));
} }
settings_enable_window(hdlg, IDC_MEMSPIN, machines[temp_machine].min_ram != machines[temp_machine].max_ram); settings_enable_window(hdlg, IDC_MEMSPIN, machine_get_min_ram(temp_machine) != machine_get_max_ram(temp_machine));
settings_enable_window(hdlg, IDC_MEMTEXT, machines[temp_machine].min_ram != machines[temp_machine].max_ram); settings_enable_window(hdlg, IDC_MEMTEXT, machine_get_min_ram(temp_machine) != machine_get_max_ram(temp_machine));
free(lptsTemp); free(lptsTemp);
} }
@@ -844,7 +844,7 @@ machine_type_available(int id)
if ((id > 0) && (id < MACHINE_TYPE_MAX)) { if ((id > 0) && (id < MACHINE_TYPE_MAX)) {
while (machine_get_internal_name_ex(c) != NULL) { while (machine_get_internal_name_ex(c) != NULL) {
if (machine_available(c) && (machines[c].type == id)) if (machine_available(c) && (machine_get_type(c) == id))
return 1; return 1;
c++; c++;
} }
@@ -891,8 +891,8 @@ win_settings_machine_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
settings_reset_content(hdlg, IDC_COMBO_MACHINE); settings_reset_content(hdlg, IDC_COMBO_MACHINE);
memset(listtomachine, 0x00, sizeof(listtomachine)); memset(listtomachine, 0x00, sizeof(listtomachine));
while (machine_get_internal_name_ex(c) != NULL) { while (machine_get_internal_name_ex(c) != NULL) {
if (machine_available(c) && (machines[c].type == temp_machine_type)) { if (machine_available(c) && (machine_get_type(c) == temp_machine_type)) {
stransi = (char *)machines[c].name; stransi = machine_getname_ex(c);
mbstowcs(lptsTemp, stransi, strlen(stransi) + 1); mbstowcs(lptsTemp, stransi, strlen(stransi) + 1);
settings_add_string(hdlg, IDC_COMBO_MACHINE, (LPARAM) lptsTemp); settings_add_string(hdlg, IDC_COMBO_MACHINE, (LPARAM) lptsTemp);
listtomachine[d] = c; listtomachine[d] = c;
@@ -946,8 +946,8 @@ win_settings_machine_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
c = d = 0; c = d = 0;
memset(listtomachine, 0x00, sizeof(listtomachine)); memset(listtomachine, 0x00, sizeof(listtomachine));
while (machine_get_internal_name_ex(c) != NULL) { while (machine_get_internal_name_ex(c) != NULL) {
if (machine_available(c) && (machines[c].type == temp_machine_type)) { if (machine_available(c) && (machine_get_type(c) == temp_machine_type)) {
stransi = (char *)machines[c].name; stransi = machine_getname_ex(c);
mbstowcs(lptsTemp, stransi, strlen(stransi) + 1); mbstowcs(lptsTemp, stransi, strlen(stransi) + 1);
settings_add_string(hdlg, IDC_COMBO_MACHINE, (LPARAM) lptsTemp); settings_add_string(hdlg, IDC_COMBO_MACHINE, (LPARAM) lptsTemp);
listtomachine[d] = c; listtomachine[d] = c;
@@ -1023,13 +1023,13 @@ win_settings_machine_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
SendMessage(h, WM_GETTEXT, 255, (LPARAM) lptsTemp); SendMessage(h, WM_GETTEXT, 255, (LPARAM) lptsTemp);
wcstombs(stransi, lptsTemp, 512); wcstombs(stransi, lptsTemp, 512);
sscanf(stransi, "%u", &temp_mem_size); sscanf(stransi, "%u", &temp_mem_size);
if (!(machines[temp_machine].ram_granularity & 1023)) if (!(machine_get_ram_granularity(temp_machine) & 1023))
temp_mem_size = temp_mem_size << 10; temp_mem_size = temp_mem_size << 10;
temp_mem_size &= ~(machines[temp_machine].ram_granularity - 1); temp_mem_size &= ~(machine_get_ram_granularity(temp_machine) - 1);
if (temp_mem_size < machines[temp_machine].min_ram) if (temp_mem_size < machine_get_min_ram(temp_machine))
temp_mem_size = machines[temp_machine].min_ram; temp_mem_size = machine_get_min_ram(temp_machine);
else if (temp_mem_size > machines[temp_machine].max_ram) else if (temp_mem_size > machine_get_max_ram(temp_machine))
temp_mem_size = machines[temp_machine].max_ram; temp_mem_size = machine_get_max_ram(temp_machine);
free(stransi); free(stransi);
free(lptsTemp); free(lptsTemp);