From 2b37b7fbfb692674ba6e361bd51f4352e7e9eccd Mon Sep 17 00:00:00 2001 From: waltje Date: Sat, 7 Oct 2017 00:46:54 -0400 Subject: [PATCH] Major changes to NVR, system initialization (pc.c), and what goes on in the Windows startup (win.c.) Not fully done yet, but good enough for a first commit. --- src/Makefile.mingw | 4 +- src/bugger.c | 5 +- src/cdrom/cdrom.c | 13 +- src/cdrom/cdrom_ioctl.c | 3 +- src/config.c | 3393 +++++++++------------ src/cpu/808x.c | 8 +- src/cpu/x86_ops.h | 4 + src/device.c | 462 +-- src/device.h | 87 +- src/disk/hdc.c | 14 +- src/disk/hdc_esdi_at.c | 17 +- src/disk/hdc_esdi_mca.c | 17 +- src/disk/hdc_ide.c | 29 +- src/disk/hdc_mfm_at.c | 27 +- src/disk/hdc_mfm_xt.c | 31 +- src/disk/hdc_xtide.c | 34 +- src/disk/hdd.c | 139 +- src/disk/hdd.h | 5 +- src/floppy/fdc.c | 27 +- src/floppy/floppy.c | 7 +- src/floppy/floppy_86f.c | 5 +- src/game/gameport.c | 20 +- src/ibm.h | 24 +- src/intel_flash.c | 39 +- src/machine/machine.c | 12 +- src/machine/machine_at.c | 17 +- src/machine/machine_common.c | 4 +- src/network/net_ne2000.c | 170 +- src/network/network.c | 9 +- src/nvr.c | 130 +- src/nvr.h | 22 +- src/nvr_at.c | 5 +- src/nvr_ps2.c | 9 +- src/pc.c | 268 +- src/scsi/scsi.c | 3 +- src/scsi/scsi.h | 4 +- src/scsi/scsi_aha154x.c | 39 +- src/scsi/scsi_aha154x.h | 1 + src/scsi/scsi_bios_command.c | 3 +- src/scsi/scsi_buslogic.c | 10 +- src/scsi/scsi_device.c | 3 +- src/scsi/scsi_disk.c | 17 +- src/sound/midi.h | 14 +- src/sound/midi_mt32.c | 8 +- src/sound/midi_system.c | 7 +- src/sound/snd_adlib.c | 22 +- src/sound/snd_adlibgold.c | 5 +- src/sound/snd_cms.c | 11 +- src/sound/snd_gus.c | 11 +- src/sound/snd_mpu401.c | 9 +- src/sound/snd_pas16.c | 15 +- src/sound/snd_ps1.c | 5 +- src/sound/snd_pssj.c | 5 +- src/sound/snd_sb.c | 66 +- src/sound/snd_sn76489.c | 14 +- src/sound/snd_ssi2001.c | 11 +- src/sound/snd_wss.c | 9 +- src/sound/sound.h | 16 +- src/tandy_eeprom.c | 9 +- src/tandy_rom.c | 12 +- src/video/vid_ati18800.c | 11 +- src/video/vid_ati28800.c | 14 +- src/video/vid_ati_mach64.c | 16 +- src/video/vid_cga.c | 7 +- src/video/vid_cl_gd.c | 91 +- src/video/vid_colorplus.c | 6 +- src/video/vid_ega.c | 20 +- src/video/vid_et4000.c | 6 +- src/video/vid_et4000w32.c | 6 +- src/video/vid_genius.c | 8 +- src/video/vid_hercules.c | 8 +- src/video/vid_herculesplus.c | 6 +- src/video/vid_incolor.c | 7 +- src/video/vid_mda.c | 8 +- src/video/vid_nv_riva128.c | 56 +- src/video/vid_olivetti_m24.c | 20 +- src/video/vid_oti067.c | 20 +- src/video/vid_paradise.c | 28 +- src/video/vid_pc1512.c | 6 +- src/video/vid_pc1640.c | 10 +- src/video/vid_pc200.c | 10 +- src/video/vid_pcjr.c | 9 +- src/video/vid_ps1_svga.c | 6 +- src/video/vid_s3.c | 47 +- src/video/vid_s3_virge.c | 24 +- src/video/vid_tandy.c | 16 +- src/video/vid_tandysl.c | 6 +- src/video/vid_tgui9440.c | 6 +- src/video/vid_tvga.c | 7 +- src/video/vid_vga.c | 16 +- src/video/vid_voodoo.c | 8 +- src/video/vid_wy700.c | 7 +- src/video/video.h | 10 +- src/win/86Box.rc | 21 +- src/win/resource.h | 17 +- src/win/win.c | 4862 +++++++++++++++---------------- src/win/win.h | 93 +- src/win/win_d3d_fs.cc | 117 +- src/win/win_ddraw.cc | 2 + src/win/win_ddraw_screenshot.cc | 2 +- src/win/win_deviceconfig.c | 7 +- src/win/win_iodev.c | 204 -- src/win/win_joystick.cc | 2 +- src/win/win_language.c | 9 +- src/win/win_mouse.cc | 2 +- src/win/win_settings.c | 10 +- src/win/win_status.c | 130 +- src/win/win_thread.c | 147 + 108 files changed, 5628 insertions(+), 5912 deletions(-) delete mode 100644 src/win/win_iodev.c create mode 100644 src/win/win_thread.c diff --git a/src/Makefile.mingw b/src/Makefile.mingw index b225252a4..e85fb7d06 100644 --- a/src/Makefile.mingw +++ b/src/Makefile.mingw @@ -8,7 +8,7 @@ # # Modified Makefile for Win32 (MinGW32) environment. # -# Version: @(#)Makefile.mingw 1.0.52 2017/10/02 +# Version: @(#)Makefile.mingw 1.0.52 2017/10/05 # # Authors: Miran Grca, # Fred N. van Kempen, @@ -351,7 +351,7 @@ WINOBJ := win.o \ win_d3d.o win_d3d_fs.o \ win_language.o win_status.o $(OPENDIR) win_dynld.o \ win_video.o $(WSERIAL) win_keyboard.o win_mouse.o \ - win_iodev.o win_joystick.o win_midi.o \ + win_joystick.o win_midi.o win_thread.o \ win_settings.o win_deviceconfig.o win_joystickconfig.o OBJ := $(MAINOBJ) $(CPUOBJ) $(MCHOBJ) $(DEVOBJ) \ diff --git a/src/bugger.c b/src/bugger.c index a527c3a6b..2646d78cc 100644 --- a/src/bugger.c +++ b/src/bugger.c @@ -44,7 +44,7 @@ * configuration register (CTRL_SPCFG bit set) but have to * remember that stuff first... * - * Version: @(#)bugger.c 1.0.5 2017/09/24 + * Version: @(#)bugger.c 1.0.6 2017/10/05 * * Author: Fred N. van Kempen, * Copyright 1989-2017 Fred N. van Kempen. @@ -55,6 +55,7 @@ #include #include "ibm.h" #include "io.h" +#include "win/win.h" #include "bugger.h" @@ -103,7 +104,7 @@ bug_setui(void) (bug_ledr&0x02)?'R':'r', (bug_ledr&0x01)?'R':'r'); /* Send formatted string to the UI. */ - status_settext(bug_str); + StatusBarSetText(bug_str); } diff --git a/src/cdrom/cdrom.c b/src/cdrom/cdrom.c index 389c2a3ae..c1c214b7e 100644 --- a/src/cdrom/cdrom.c +++ b/src/cdrom/cdrom.c @@ -9,7 +9,7 @@ * Implementation of the CD-ROM drive with SCSI(-like) * commands, for both ATAPI and SCSI usage. * - * Version: @(#)cdrom.c 1.0.9 2017/10/02 + * Version: @(#)cdrom.c 1.0.9 2017/10/05 * * Author: Miran Grca, * Copyright 2016,2017 Miran Grca. @@ -29,6 +29,7 @@ #include "../nvr.h" #include "../disk/hdc.h" #include "../disk/hdc_ide.h" +#include "../win/win.h" #include "../win/plat_iodev.h" #include "cdrom.h" @@ -2565,11 +2566,11 @@ cdrom_readtoc_fallback: cdrom[id].all_blocks_total = cdrom[id].block_total; if (cdrom[id].packet_status != CDROM_PHASE_COMPLETE) { - update_status_bar_icon(SB_CDROM | id, 1); + StatusBarUpdateIcon(SB_CDROM | id, 1); } else { - update_status_bar_icon(SB_CDROM | id, 0); + StatusBarUpdateIcon(SB_CDROM | id, 0); } return; @@ -3675,7 +3676,7 @@ void cdrom_phase_callback(uint8_t id) cdrom[id].status = READY_STAT; cdrom[id].phase = 3; cdrom[id].packet_status = 0xFF; - update_status_bar_icon(SB_CDROM | id, 0); + StatusBarUpdateIcon(SB_CDROM | id, 0); cdrom_irq_raise(id); return; case CDROM_PHASE_DATA_OUT: @@ -3690,7 +3691,7 @@ void cdrom_phase_callback(uint8_t id) cdrom[id].packet_status = CDROM_PHASE_COMPLETE; cdrom[id].status = READY_STAT; cdrom[id].phase = 3; - update_status_bar_icon(SB_CDROM | id, 0); + StatusBarUpdateIcon(SB_CDROM | id, 0); cdrom_irq_raise(id); return; case CDROM_PHASE_DATA_IN: @@ -3705,7 +3706,7 @@ void cdrom_phase_callback(uint8_t id) cdrom[id].packet_status = CDROM_PHASE_COMPLETE; cdrom[id].status = READY_STAT; cdrom[id].phase = 3; - update_status_bar_icon(SB_CDROM | id, 0); + StatusBarUpdateIcon(SB_CDROM | id, 0); cdrom_irq_raise(id); return; case CDROM_PHASE_ERROR: diff --git a/src/cdrom/cdrom_ioctl.c b/src/cdrom/cdrom_ioctl.c index eb5671731..7e2d2f913 100644 --- a/src/cdrom/cdrom_ioctl.c +++ b/src/cdrom/cdrom_ioctl.c @@ -9,7 +9,7 @@ * Implementation of the CD-ROM host drive IOCTL interface for * Windows using SCSI Passthrough Direct. * - * Version: @(#)cdrom_ioctl.c 1.0.4 2017/09/24 + * Version: @(#)cdrom_ioctl.c 1.0.5 2017/10/04 * * Authors: Sarah Walker, * Miran Grca, @@ -26,6 +26,7 @@ #include #include #include "../ibm.h" +#include "../device.h" #include "../scsi/scsi.h" #include "cdrom.h" #include "cdrom_ioctl.h" diff --git a/src/config.c b/src/config.c index 1b7d28f03..da7e094e7 100644 --- a/src/config.c +++ b/src/config.c @@ -8,7 +8,7 @@ * * Configuration file handler. * - * Version: @(#)config.c 1.0.12 2017/10/02 + * Version: @(#)config.c 1.0.13 2017/10/05 * * Authors: Sarah Walker, * Miran Grca, @@ -58,50 +58,44 @@ #include "win/win_language.h" -typedef struct _list_ -{ - struct _list_ *next; +typedef struct _list_ { + struct _list_ *next; } list_t; -typedef struct -{ - list_t list; - - char name[256]; - - list_t entry_head; +typedef struct { + list_t list; + + char name[256]; + + list_t entry_head; } section_t; -typedef struct -{ - list_t list; - - char name[256]; - char data[256]; - wchar_t wdata[256]; +typedef struct { + list_t list; + + char name[256]; + char data[256]; + wchar_t wdata[256]; } entry_t; -#define list_add(new, head) \ -{ \ - list_t *next = head; \ - \ - while (next->next != NULL) \ - next = next->next; \ - \ - (next)->next = new; \ - (new)->next = NULL; \ +#define list_add(new, head) { \ + list_t *next = head; \ + \ + while (next->next != NULL) \ + next = next->next; \ + \ + (next)->next = new; \ + (new)->next = NULL; \ } -#define list_delete(old, head) \ -{ \ - list_t *next = head; \ - \ - while ((next)->next != old) \ - { \ - next = (next)->next; \ - } \ - \ - (next)->next = (old)->next; \ +#define list_delete(old, head) { \ + list_t *next = head; \ + \ + while ((next)->next != old) { \ + next = (next)->next; \ + } \ + \ + (next)->next = (old)->next; \ } @@ -113,105 +107,98 @@ static list_t config_head; static section_t * find_section(char *name) { - section_t *sec; - char blank[] = ""; - - sec = (section_t *)config_head.next; - if (name == NULL) - name = blank; + section_t *sec; + char blank[] = ""; - while (sec != NULL) - { - if (! strncmp(sec->name, name, 256)) - return(sec); - - sec = (section_t *)sec->list.next; - } + sec = (section_t *)config_head.next; + if (name == NULL) + name = blank; - return(NULL); + while (sec != NULL) { + if (! strncmp(sec->name, name, 256)) + return(sec); + + sec = (section_t *)sec->list.next; + } + + return(NULL); } static entry_t * find_entry(section_t *section, char *name) { - entry_t *ent; - - ent = (entry_t *)section->entry_head.next; - - while (ent != NULL) - { - if (! strncmp(ent->name, name, 256)) - return(ent); + entry_t *ent; - ent = (entry_t *)ent->list.next; - } + ent = (entry_t *)section->entry_head.next; - return(NULL); + while (ent != NULL) { + if (! strncmp(ent->name, name, 256)) + return(ent); + + ent = (entry_t *)ent->list.next; + } + + return(NULL); } static int entries_num(section_t *section) { - entry_t *ent; - int i = 0; - - ent = (entry_t *)section->entry_head.next; - - while (ent != NULL) - { - if (strlen(ent->name) > 0) - { - i++; - } + entry_t *ent; + int i = 0; - ent = (entry_t *)ent->list.next; - } + ent = (entry_t *)section->entry_head.next; - return(i); + while (ent != NULL) { + if (strlen(ent->name) > 0) i++; + + ent = (entry_t *)ent->list.next; + } + + return(i); } static void delete_section_if_empty(char *head) { - section_t *section; + section_t *section; - section = find_section(head); - if (section == NULL) return; + section = find_section(head); + if (section == NULL) return; - if (entries_num(section) == 0) - { - list_delete(§ion->list, &config_head); - free(section); - } + if (entries_num(section) == 0) { + list_delete(§ion->list, &config_head); + free(section); + } } static section_t * create_section(char *name) { - section_t *ns = malloc(sizeof(section_t)); + section_t *ns = malloc(sizeof(section_t)); - memset(ns, 0x00, sizeof(section_t)); - strncpy(ns->name, name, 256); - list_add(&ns->list, &config_head); - - return(ns); + memset(ns, 0x00, sizeof(section_t)); + strncpy(ns->name, name, 256); + list_add(&ns->list, &config_head); + + return(ns); } static entry_t * create_entry(section_t *section, char *name) { - entry_t *ne = malloc(sizeof(entry_t)); + entry_t *ne = malloc(sizeof(entry_t)); - memset(ne, 0x00, sizeof(entry_t)); - strncpy(ne->name, name, 256); - list_add(&ne->list, §ion->entry_head); - - return(ne); + memset(ne, 0x00, sizeof(entry_t)); + strncpy(ne->name, name, 256); + list_add(&ne->list, §ion->entry_head); + + return(ne); } @@ -219,27 +206,24 @@ create_entry(section_t *section, char *name) static void config_free(void) { - section_t *sec; + section_t *sec, *ns; + entry_t *ent; - sec = (section_t *)config_head.next; - while (sec != NULL) - { - section_t *ns = (section_t *)sec->list.next; - entry_t *ent; + sec = (section_t *)config_head.next; + while (sec != NULL) { + ns = (section_t *)sec->list.next; + ent = (entry_t *)sec->entry_head.next; - ent = (entry_t *)sec->entry_head.next; + while (ent != NULL) { + entry_t *nent = (entry_t *)ent->list.next; - while (ent != NULL) - { - entry_t *nent = (entry_t *)ent->list.next; - - free(ent); - ent = nent; - } + free(ent); + ent = nent; + } - free(sec); - sec = ns; - } + free(sec); + sec = ns; + } } #endif @@ -248,102 +232,95 @@ config_free(void) static int config_read(wchar_t *fn) { - section_t *current_section; - char sname[256], ename[256]; - wchar_t cfgbuffer[1024]; - section_t *new_section; - entry_t *new_entry; - FILE *f; - int c; - int sd = 0, ed = 0, data_pos; + char sname[256], ename[256]; + wchar_t buff[1024]; + section_t *sec, *ns; + int sd = 0, ed = 0; + int c, data_pos; + entry_t *ne; + FILE *f; #ifdef ANSI_CFG - f = _wfopen(fn, L"rt"); + f = _wfopen(fn, L"rt"); #else - f = _wfopen(fn, L"rt, ccs=UNICODE"); + f = _wfopen(fn, L"rt, ccs=UNICODE"); #endif - if (!f) - return 0; - - current_section = malloc(sizeof(section_t)); - memset(current_section, 0x00, sizeof(section_t)); - memset(&config_head, 0x00, sizeof(list_t)); - list_add(¤t_section->list, &config_head); + if (f == NULL) return(0); + + sec = malloc(sizeof(section_t)); + memset(sec, 0x00, sizeof(section_t)); + memset(&config_head, 0x00, sizeof(list_t)); + list_add(&sec->list, &config_head); - while (1) - { - memset(cfgbuffer, 0, sizeof(cfgbuffer)); - fgetws(cfgbuffer, 255, f); - if (feof(f)) break; - - c = 0; - - while (cfgbuffer[c] == L' ') - c++; + while (1) { + memset(buff, 0x00, sizeof(buff)); + fgetws(buff, sizeof(buff)-1, f); + if (feof(f)) break; - if (cfgbuffer[c] == L'\0') continue; - - if ((cfgbuffer[c] == L'#') || (cfgbuffer[c] == L';')) { - /*Comment*/ - continue; + c = 0; + while (buff[c] == L' ') + c++; + + if (buff[c] == L'\0') continue; + + if ((buff[c] == L'#') || (buff[c] == L';')) { + /*Comment*/ + continue; + } + + if (buff[c] == L'[') { /*Section*/ + sd = 0; + c++; + while (buff[c] != L']' && buff[c]) + wctomb(&(sname[sd++]), buff[c++]); + + if (buff[c] != L']') continue; + + sname[sd] = 0; + + ns = malloc(sizeof(section_t)); + memset(ns, 0x00, sizeof(section_t)); + strncpy(ns->name, sname, sizeof(ns->name)); + list_add(&ns->list, &config_head); + + sec = ns; + } else { + ed = 0; + while (buff[c] != L'=' && buff[c] != L' ' && buff[c]) + wctomb(&(ename[ed++]), buff[c++]); + + if (buff[c] == L'\0') continue; + + ename[ed] = 0; + + while ((buff[c] == L'=' || buff[c] == L' ') && buff[c]) + c++; + + if (! buff[c]) continue; + + data_pos = c; + while (buff[c]) { + if (buff[c] == L'\n') + buff[c] = L'\0'; + c++; } - if (cfgbuffer[c] == L'[') /*Section*/ - { - sd = 0; - c++; - while (cfgbuffer[c] != L']' && cfgbuffer[c]) - wctomb(&(sname[sd++]), cfgbuffer[c++]); + ne = malloc(sizeof(entry_t)); + memset(ne, 0x00, sizeof(entry_t)); + strncpy(ne->name, ename, 256); + memcpy(ne->wdata, &buff[data_pos], 512); + ne->wdata[255] = L'\0'; + wcstombs(ne->data, ne->wdata, sizeof(ne->data)); + ne->data[255] = '\0'; + list_add(&ne->list, &sec->entry_head); + } + } - if (cfgbuffer[c] != L']') - continue; - sname[sd] = 0; - - new_section = malloc(sizeof(section_t)); - memset(new_section, 0x00, sizeof(section_t)); - strncpy(new_section->name, sname, 256); - list_add(&new_section->list, &config_head); - - current_section = new_section; - } - else - { - ed = 0; - while (cfgbuffer[c] != L'=' && cfgbuffer[c] != L' ' && cfgbuffer[c]) - wctomb(&(ename[ed++]), cfgbuffer[c++]); - - if (cfgbuffer[c] == L'\0') continue; - ename[ed] = 0; + (void)fclose(f); + + config_dump(); - while ((cfgbuffer[c] == L'=' || cfgbuffer[c] == L' ') && cfgbuffer[c]) - c++; - - if (!cfgbuffer[c]) continue; - - data_pos = c; - while (cfgbuffer[c]) - { - if (cfgbuffer[c] == L'\n') - cfgbuffer[c] = L'\0'; - c++; - } - - new_entry = malloc(sizeof(entry_t)); - memset(new_entry, 0, sizeof(entry_t)); - strncpy(new_entry->name, ename, 256); - memcpy(new_entry->wdata, &cfgbuffer[data_pos], 512); - new_entry->wdata[255] = L'\0'; - wcstombs(new_entry->data, new_entry->wdata, sizeof(new_entry->data)); - new_entry->data[255] = '\0'; - list_add(&new_entry->list, ¤t_section->entry_head); - } - } - - (void)fclose(f); - - config_dump(); - - return 1; + return(1); } @@ -356,53 +333,49 @@ config_read(wchar_t *fn) void config_write(wchar_t *fn) { - wchar_t wname[512]; - section_t *sec; - FILE *f; - int fl = 0; + wchar_t wname[512]; + section_t *sec; + FILE *f; + int fl = 0; #ifdef ANSI_CFG - f = _wfopen(fn, L"wt"); + f = _wfopen(fn, L"wt"); #else - f = _wfopen(fn, L"wt, ccs=UNICODE"); + f = _wfopen(fn, L"wt, ccs=UNICODE"); #endif - if (f == NULL) return; + if (f == NULL) return; - sec = (section_t *)config_head.next; - while (sec != NULL) - { - entry_t *ent; - - if (sec->name[0]) - { - mbstowcs(wname, sec->name, strlen(sec->name)+1); - if (fl) - fwprintf(f, L"\n[%ws]\n", wname); + sec = (section_t *)config_head.next; + while (sec != NULL) { + entry_t *ent; + + if (sec->name[0]) { + mbstowcs(wname, sec->name, strlen(sec->name)+1); + if (fl) + fwprintf(f, L"\n[%ws]\n", wname); + else + fwprintf(f, L"[%ws]\n", wname); + fl++; + } + + ent = (entry_t *)sec->entry_head.next; + while (ent != NULL) { + if (ent->name[0]) { + mbstowcs(wname, ent->name, strlen(ent->name)+1); + if (ent->wdata[0] == L'\0') + fwprintf(f, L"%ws = \n", wname); else - fwprintf(f, L"[%ws]\n", wname); + fwprintf(f, L"%ws = %ws\n", wname, ent->wdata); fl++; } - - ent = (entry_t *)sec->entry_head.next; - while (ent != NULL) - { - if (ent->name[0]) - { - mbstowcs(wname, ent->name, strlen(ent->name)+1); - if (ent->wdata[0] == L'\0') - fwprintf(f, L"%ws = \n", wname); - else - fwprintf(f, L"%ws = %ws\n", wname, ent->wdata); - fl++; - } - ent = (entry_t *)ent->list.next; - } + ent = (entry_t *)ent->list.next; + } - sec = (section_t *)sec->list.next; - } - - (void)fclose(f); + sec = (section_t *)sec->list.next; + } + + (void)fclose(f); } @@ -411,11 +384,13 @@ static void config_new(void) { #ifdef ANSI_CFG - FILE *f = _wfopen(config_file, L"wt"); + FILE *f = _wfopen(config_file, L"wt"); #else - FILE *f = _wfopen(config_file, L"wt, ccs=UNICODE"); + FILE *f = _wfopen(config_file, L"wt, ccs=UNICODE"); #endif - (void)fclose(f); + + if (file != NULL) + (void)fclose(f); } #endif @@ -424,66 +399,56 @@ config_new(void) static void load_general(void) { - char *cat = "General"; - char temp[512]; - char *p; + char *cat = "General"; + char temp[512]; + char *p; - vid_resize = !!config_get_int(cat, "vid_resize", 0); + vid_resize = !!config_get_int(cat, "vid_resize", 0); - memset(temp, '\0', sizeof(temp)); - p = config_get_string(cat, "vid_renderer", "d3d9"); - if (p != NULL) - { - strcpy(temp, p); - } - if (!strcmp(temp, "ddraw")) - { - vid_api = 0; - } - else - { - vid_api = 1; - } + memset(temp, '\0', sizeof(temp)); + p = config_get_string(cat, "vid_renderer", "d3d9"); + if (p != NULL) + strcpy(temp, p); + if (! strcmp(temp, "ddraw")) + vid_api = 0; + else + vid_api = 1; + config_delete_var(cat, "vid_api"); - config_delete_var(cat, "vid_api"); + video_fullscreen_scale = config_get_int(cat, "video_fullscreen_scale", 0); - video_fullscreen_scale = config_get_int(cat, "video_fullscreen_scale", 0); - video_fullscreen_first = config_get_int(cat, "video_fullscreen_first", 0); + video_fullscreen_first = config_get_int(cat, "video_fullscreen_first", 0); - force_43 = !!config_get_int(cat, "force_43", 0); - scale = config_get_int(cat, "scale", 1); - if (scale > 3) - { - scale = 3; - } - enable_overscan = !!config_get_int(cat, "enable_overscan", 0); - vid_cga_contrast = !!config_get_int(cat, "vid_cga_contrast", 0); - video_grayscale = config_get_int(cat, "video_grayscale", 0); - video_graytype = config_get_int(cat, "video_graytype", 0); + force_43 = !!config_get_int(cat, "force_43", 0); + scale = config_get_int(cat, "scale", 1); + if (scale > 3) + scale = 3; - window_remember = config_get_int(cat, "window_remember", 0); + enable_overscan = !!config_get_int(cat, "enable_overscan", 0); + vid_cga_contrast = !!config_get_int(cat, "vid_cga_contrast", 0); + video_grayscale = config_get_int(cat, "video_grayscale", 0); + video_graytype = config_get_int(cat, "video_graytype", 0); - if (window_remember) - { - p = config_get_string(cat, "window_coordinates", NULL); - if (p == NULL) - p = "0, 0, 0, 0"; - sscanf(p, "%i, %i, %i, %i", &window_w, &window_h, &window_x, &window_y); - } - else - { - config_delete_var(cat, "window_remember"); - config_delete_var(cat, "window_coordinates"); - window_w = window_h = window_x = window_y = 0; - } + window_remember = config_get_int(cat, "window_remember", 0); + if (window_remember) { + p = config_get_string(cat, "window_coordinates", NULL); + if (p == NULL) + p = "0, 0, 0, 0"; + sscanf(p, "%i, %i, %i, %i", &window_w, &window_h, &window_x, &window_y); + } else { + config_delete_var(cat, "window_remember"); + config_delete_var(cat, "window_coordinates"); + + window_w = window_h = window_x = window_y = 0; + } #ifndef __unix - /* - * Currently, 86Box is English (US) only, but in the future - * (version 1.30 at the earliest) other languages will be - * added, therefore it is better to future-proof the code. - */ - dwLanguage = config_get_hex16(cat, "language", 0x0409); + /* + * Currently, 86Box is English (US) only, but in the future + * (version 1.30 at the earliest) other languages will be + * added, therefore it is better to future-proof the code. + */ + dwLanguage = config_get_hex16(cat, "language", 0x0409); #endif } @@ -492,59 +457,51 @@ load_general(void) static void load_machine(void) { - char *cat = "Machine"; - char *p; + char *cat = "Machine"; + char *p; - p = config_get_string(cat, "machine", NULL); - if (p != NULL) - { + p = config_get_string(cat, "machine", NULL); + if (p != NULL) + machine = machine_get_machine_from_internal_name(p); + else + machine = 0; + if (machine >= machine_count()) + machine = machine_count() - 1; + + /* This is for backwards compatibility. */ + p = config_get_string(cat, "model", NULL); + if (p != NULL) { + /* Detect the old model typos and fix them. */ + if (! strcmp(p, "p55r2p4")) { + machine = machine_get_machine_from_internal_name("p55t2p4"); + } else { machine = machine_get_machine_from_internal_name(p); } - else - machine = 0; - if (machine >= machine_count()) - machine = machine_count() - 1; + config_delete_var(cat, "model"); + } + if (machine >= machine_count()) + machine = machine_count() - 1; - /* This is for backwards compatibility. */ - p = config_get_string(cat, "model", NULL); - if (p != NULL) - { - /* Detect the old model typo and fix it, so that old configurations don't braek. */ - if (strcmp(p, "p55r2p4") == 0) - { - machine = machine_get_machine_from_internal_name("p55t2p4"); - } - else - { - machine = machine_get_machine_from_internal_name(p); - } - config_delete_var(cat, "model"); - } - if (machine >= machine_count()) - machine = machine_count() - 1; + romset = machine_getromset(); + cpu_manufacturer = config_get_int(cat, "cpu_manufacturer", 0); + cpu = config_get_int(cat, "cpu", 0); + cpu_waitstates = config_get_int(cat, "cpu_waitstates", 0); - romset = machine_getromset(); - cpu_manufacturer = config_get_int(cat, "cpu_manufacturer", 0); - cpu = config_get_int(cat, "cpu", 0); - cpu_waitstates = config_get_int(cat, "cpu_waitstates", 0); + mem_size = config_get_int(cat, "mem_size", 4096); + if (mem_size < (((machines[machine].flags & MACHINE_AT) && + (machines[machine].ram_granularity < 128)) ? machines[machine].min_ram*1024 : machines[machine].min_ram)) + mem_size = (((machines[machine].flags & MACHINE_AT) && (machines[machine].ram_granularity < 128)) ? machines[machine].min_ram*1024 : machines[machine].min_ram); + if (mem_size > 1048576) + mem_size = 1048576; - mem_size = config_get_int(cat, "mem_size", 4096); - if (mem_size < (((machines[machine].flags & MACHINE_AT) && (machines[machine].ram_granularity < 128)) ? machines[machine].min_ram*1024 : machines[machine].min_ram)) - mem_size = (((machines[machine].flags & MACHINE_AT) && (machines[machine].ram_granularity < 128)) ? machines[machine].min_ram*1024 : machines[machine].min_ram); - if (mem_size > 1048576) - { - mem_size = 1048576; - } + cpu_use_dynarec = !!config_get_int(cat, "cpu_use_dynarec", 0); - cpu_use_dynarec = !!config_get_int(cat, "cpu_use_dynarec", 0); + enable_external_fpu = !!config_get_int(cat, "cpu_enable_fpu", 0); - enable_external_fpu = !!config_get_int(cat, "cpu_enable_fpu", 0); + enable_sync = !!config_get_int(cat, "enable_sync", 1); - enable_sync = !!config_get_int(cat, "enable_sync", 1); - - /* Remove this after a while.. */ - if (config_get_string(cat, "nvr_path", NULL) != NULL) - config_delete_var(cat, "nvr_path"); + /* Remove this after a while.. */ + config_delete_var(cat, "nvr_path"); } @@ -552,18 +509,18 @@ load_machine(void) static void load_video(void) { - char *cat = "Video"; - char *p; + char *cat = "Video"; + char *p; - p = config_get_string(cat, "gfxcard", NULL); - if (p != NULL) - gfxcard = video_get_video_from_internal_name(p); - else - gfxcard = 0; + p = config_get_string(cat, "gfxcard", NULL); + if (p != NULL) + gfxcard = video_get_video_from_internal_name(p); + else + gfxcard = 0; - video_speed = config_get_int(cat, "video_speed", 3); + video_speed = config_get_int(cat, "video_speed", 3); - voodoo_enabled = !!config_get_int(cat, "voodoo", 0); + voodoo_enabled = !!config_get_int(cat, "voodoo", 0); } @@ -571,45 +528,40 @@ load_video(void) static void load_input_devices(void) { - char *cat = "Input devices"; - char temp[512]; - int c, d; - char *p; + char *cat = "Input devices"; + char temp[512]; + int c, d; + char *p; - p = config_get_string(cat, "mouse_type", NULL); - if (p != NULL) - mouse_type = mouse_get_from_internal_name(p); - else - mouse_type = 0; + p = config_get_string(cat, "mouse_type", NULL); + if (p != NULL) + mouse_type = mouse_get_from_internal_name(p); + else + mouse_type = 0; - joystick_type = config_get_int(cat, "joystick_type", 7); + joystick_type = config_get_int(cat, "joystick_type", 7); - for (c = 0; c < joystick_get_max_joysticks(joystick_type); c++) - { - sprintf(temp, "joystick_%i_nr", c); - joystick_state[c].plat_joystick_nr = config_get_int(cat, temp, 0); + for (c=0; c max_spt) - hdd[c].spt = max_spt; - if (hdd[c].hpc > max_hpc) - hdd[c].hpc = max_hpc; - if (hdd[c].tracks > max_tracks) - hdd[c].tracks = max_tracks; - - /* MFM/RLL */ - sprintf(temps, "hdd_%02i_mfm_channel", c + 1); - if (hdd[c].bus == HDD_BUS_MFM) - hdd[c].mfm_channel = !!config_get_int(cat, temps, c & 1); - else - config_delete_var(cat, temps); - - /* XT IDE */ - sprintf(temps, "hdd_%02i_xtide_channel", c + 1); - if (hdd[c].bus == HDD_BUS_XTIDE) - hdd[c].xtide_channel = !!config_get_int(cat, temps, c & 1); - else - config_delete_var(cat, temps); - - /* ESDI */ - sprintf(temps, "hdd_%02i_esdi_channel", c + 1); - if (hdd[c].bus == HDD_BUS_ESDI) - hdd[c].esdi_channel = !!config_get_int(cat, temps, c & 1); - else - config_delete_var(cat, temps); - - /* IDE */ - sprintf(temps, "hdd_%02i_ide_channel", c + 1); - if ((hdd[c].bus == HDD_BUS_IDE_PIO_ONLY) || (hdd[c].bus == HDD_BUS_IDE_PIO_AND_DMA)) - { - sprintf(temps2, "%01u:%01u", c >> 1, c & 1); - p = config_get_string(cat, temps, temps2); - - if (strstr(p, ":") == NULL) - { - sscanf(p, "%i", (int *)&hdd[c].ide_channel); - hdd[c].ide_channel &= 7; - } - else - { - sscanf(p, "%01u:%01u", &board, &dev); - - board &= 3; - dev &= 1; - hdd[c].ide_channel = (board << 1) + dev; - } - - if (hdd[c].ide_channel > 7) - hdd[c].ide_channel = 7; - } - else - { - config_delete_var(cat, temps); - } - - /* SCSI */ - sprintf(temps, "hdd_%02i_scsi_location", c + 1); - if ((hdd[c].bus == HDD_BUS_SCSI) || (hdd[c].bus == HDD_BUS_SCSI_REMOVABLE)) - { - sprintf(temps2, "%02u:%02u", c, 0); - p = config_get_string(cat, temps, temps2); - - sscanf(p, "%02u:%02u", (int *)&hdd[c].scsi_id, (int *)&hdd[c].scsi_lun); - - if (hdd[c].scsi_id > 15) - hdd[c].scsi_id = 15; - if (hdd[c].scsi_lun > 7) - hdd[c].scsi_lun = 7; - } - else - { - config_delete_var(cat, temps); - } - - memset(hdd[c].fn, 0x00, sizeof(hdd[c].fn)); - memset(hdd[c].prev_fn, 0x00, sizeof(hdd[c].prev_fn)); - sprintf(temps, "hdd_%02i_fn", c + 1); - wp = config_get_wstring(cat, temps, L""); -#if 0 - /* - * NOTE: - * Temporary hack to remove the absolute - * path currently saved in most config - * files. We should remove this before - * finalizing this release! --FvK - */ - if (! wcsnicmp(wp, cfg_path, wcslen(cfg_path))) { - /* - * Yep, its absolute and prefixed - * with the CFG path. Just strip - * that off for now... - */ - wcscpy((wchar_t *)hdd[c].fn, &wp[wcslen(cfg_path)]); - } else -#endif - memcpy(hdd[c].fn, wp, (wcslen(wp) << 1) + 2); - - /* If the hard disk is in any way empty or invalid, mark the relevant variables for deletion. */ - if (! hdd_is_valid(c)) - { - sprintf(temps, "hdd_%02i_parameters", c+1); - config_delete_var(cat, temps); - - sprintf(temps, "hdd_%02i_preide_channels", c+1); - config_delete_var(cat, temps); - - sprintf(temps, "hdd_%02i_ide_channels", c+1); - config_delete_var(cat, temps); - - sprintf(temps, "hdd_%02i_scsi_location", c+1); - config_delete_var(cat, temps); - - sprintf(temps, "hdd_%02i_fn", c+1); - config_delete_var(cat, temps); - } - - sprintf(temps, "hdd_%02i_mfm_channel", c+1); - config_delete_var(cat, temps); - - sprintf(temps, "hdd_%02i_ide_channel", c+1); - config_delete_var(cat, temps); + memset(temp, '\0', sizeof(temp)); + for (c=0; c max_spt) + hdd[c].spt = max_spt; + if (hdd[c].hpc > max_hpc) + hdd[c].hpc = max_hpc; + if (hdd[c].tracks > max_tracks) + hdd[c].tracks = max_tracks; + + /* MFM/RLL */ + sprintf(temp, "hdd_%02i_mfm_channel", c+1); + if (hdd[c].bus == HDD_BUS_MFM) + hdd[c].mfm_channel = !!config_get_int(cat, temp, c & 1); + else + config_delete_var(cat, temp); + + /* XT IDE */ + sprintf(temp, "hdd_%02i_xtide_channel", c+1); + if (hdd[c].bus == HDD_BUS_XTIDE) + hdd[c].xtide_channel = !!config_get_int(cat, temp, c & 1); + else + config_delete_var(cat, temp); + + /* ESDI */ + sprintf(temp, "hdd_%02i_esdi_channel", c+1); + if (hdd[c].bus == HDD_BUS_ESDI) + hdd[c].esdi_channel = !!config_get_int(cat, temp, c & 1); + else + config_delete_var(cat, temp); + + /* IDE */ + sprintf(temp, "hdd_%02i_ide_channel", c+1); + if ((hdd[c].bus == HDD_BUS_IDE_PIO_ONLY) || + (hdd[c].bus == HDD_BUS_IDE_PIO_AND_DMA)) { + sprintf(temp2, "%01u:%01u", c>>1, c&1); + p = config_get_string(cat, temp, temp2); + if (! strstr(p, ":")) { + sscanf(p, "%i", (int *)&hdd[c].ide_channel); + hdd[c].ide_channel &= 7; + } else { + sscanf(p, "%01u:%01u", &board, &dev); + + board &= 3; + dev &= 1; + hdd[c].ide_channel = (board<<1) + dev; + } + + if (hdd[c].ide_channel > 7) + hdd[c].ide_channel = 7; + } else { + config_delete_var(cat, temp); + } + + /* SCSI */ + sprintf(temp, "hdd_%02i_scsi_location", c + 1); + if ((hdd[c].bus == HDD_BUS_SCSI) || + (hdd[c].bus == HDD_BUS_SCSI_REMOVABLE)) { + sprintf(temp, "%02u:%02u", c, 0); + p = config_get_string(cat, temp, temp2); + + sscanf(p, "%02u:%02u", + (int *)&hdd[c].scsi_id, (int *)&hdd[c].scsi_lun); + + if (hdd[c].scsi_id > 15) + hdd[c].scsi_id = 15; + if (hdd[c].scsi_lun > 7) + hdd[c].scsi_lun = 7; + } else { + config_delete_var(cat, temp); + } + + memset(hdd[c].fn, 0x00, sizeof(hdd[c].fn)); + memset(hdd[c].prev_fn, 0x00, sizeof(hdd[c].prev_fn)); + sprintf(temp, "hdd_%02i_fn", c + 1); + wp = config_get_wstring(cat, temp, L""); + +#if 0 + /* + * NOTE: + * Temporary hack to remove the absolute + * path currently saved in most config + * files. We should remove this before + * finalizing this release! --FvK + */ + if (! wcsnicmp(wp, cfg_path, wcslen(cfg_path))) { + /* + * Yep, its absolute and prefixed + * with the CFG path. Just strip + * that off for now... + */ + wcscpy((wchar_t *)hdd[c].fn, &wp[wcslen(cfg_path)]); + } else +#endif + memcpy(hdd[c].fn, wp, (wcslen(wp) << 1) + 2); + + /* If disk is empty or invalid, mark it for deletion. */ + if (! hdd_is_valid(c)) { + sprintf(temp, "hdd_%02i_parameters", c+1); + config_delete_var(cat, temp); + + sprintf(temp, "hdd_%02i_preide_channels", c+1); + config_delete_var(cat, temp); + + sprintf(temp, "hdd_%02i_ide_channels", c+1); + config_delete_var(cat, temp); + + sprintf(temp, "hdd_%02i_scsi_location", c+1); + config_delete_var(cat, temp); + + sprintf(temp, "hdd_%02i_fn", c+1); + config_delete_var(cat, temp); + } + + sprintf(temp, "hdd_%02i_mfm_channel", c+1); + config_delete_var(cat, temp); + + sprintf(temp, "hdd_%02i_ide_channel", c+1); + config_delete_var(cat, temp); + } } @@ -1190,210 +926,177 @@ load_hard_disks(void) static void load_removable_devices(void) { - char *cat = "Removable devices"; - char temps[512]; - char temps2[512]; - char s[512]; - int c; - char *p; - wchar_t *wp; - unsigned int board = 0, dev = 0; + char *cat = "Removable devices"; + char temp[512], temp2[512], *p; + char s[512]; + unsigned int board = 0, dev = 0; + wchar_t *wp; + int c; - for (c = 0; c < FDD_NUM; c++) - { - sprintf(temps, "fdd_%02i_type", c + 1); - p = config_get_string(cat, temps, (c < 2) ? "525_2dd" : "none"); - fdd_set_type(c, fdd_get_from_internal_name(p)); - if (fdd_get_type(c) > 13) - { - fdd_set_type(c, 13); - } + for (c=0; c 13) + fdd_set_type(c, 13); + + sprintf(temp, "fdd_%02i_fn", c + 1); + wp = config_get_wstring(cat, temp, L""); - sprintf(temps, "fdd_%02i_fn", c + 1); - wp = config_get_wstring(cat, temps, L""); #if 0 + /* + * NOTE: + * Temporary hack to remove the absolute + * path currently saved in most config + * files. We should remove this before + * finalizing this release! --FvK + */ + if (! wcsnicmp(wp, cfg_path, wcslen(cfg_path))) { /* - * NOTE: - * Temporary hack to remove the absolute - * path currently saved in most config - * files. We should remove this before - * finalizing this release! --FvK + * Yep, its absolute and prefixed + * with the EXE path. Just strip + * that off for now... */ - if (! wcsnicmp(wp, cfg_path, wcslen(cfg_path))) { - /* - * Yep, its absolute and prefixed - * with the EXE path. Just strip - * that off for now... - */ - wcscpy((wchar_t *)floppyfns[c], &wp[wcslen(cfg_path)]); - } else + wcscpy((wchar_t *)floppyfns[c], &wp[wcslen(cfg_path)]); + } else #endif - memcpy(floppyfns[c], wp, (wcslen(wp) << 1) + 2); - printf("Floppy: %ws\n", floppyfns[c]); - sprintf(temps, "fdd_%02i_writeprot", c + 1); - ui_writeprot[c] = !!config_get_int(cat, temps, 0); - sprintf(temps, "fdd_%02i_turbo", c + 1); - fdd_set_turbo(c, !!config_get_int(cat, temps, 0)); - sprintf(temps, "fdd_%02i_check_bpb", c + 1); - fdd_set_check_bpb(c, !!config_get_int(cat, temps, 1)); + memcpy(floppyfns[c], wp, (wcslen(wp) << 1) + 2); - /* Check, whether each value is default, if yes, delete it so that only non-default values will later be saved. */ - if (fdd_get_type(c) == ((c < 2) ? 2 : 0)) - { - sprintf(temps, "fdd_%02i_type", c + 1); - config_delete_var(cat, temps); - } + if (*wp != L'\0') + printf("Floppy%d: %ws\n", c, floppyfns[c]); + sprintf(temp, "fdd_%02i_writeprot", c+1); + ui_writeprot[c] = !!config_get_int(cat, temp, 0); + sprintf(temp, "fdd_%02i_turbo", c + 1); + fdd_set_turbo(c, !!config_get_int(cat, temp, 0)); + sprintf(temp, "fdd_%02i_check_bpb", c+1); + fdd_set_check_bpb(c, !!config_get_int(cat, temp, 1)); - if (wcslen(floppyfns[c]) == 0) - { - sprintf(temps, "fdd_%02i_fn", c + 1); - config_delete_var(cat, temps); - } - - if (ui_writeprot[c] == 0) - { - sprintf(temps, "fdd_%02i_writeprot", c + 1); - config_delete_var(cat, temps); - } - - if (fdd_get_turbo(c) == 0) - { - sprintf(temps, "fdd_%02i_turbo", c + 1); - config_delete_var(cat, temps); - } - - if (fdd_get_check_bpb(c) == 1) - { - sprintf(temps, "fdd_%02i_check_bpb", c + 1); - config_delete_var(cat, temps); - } + /* Check, whether each value is default, if yes, delete it so that only non-default values will later be saved. */ + if (fdd_get_type(c) == ((c < 2) ? 2 : 0)) { + sprintf(temp, "fdd_%02i_type", c+1); + config_delete_var(cat, temp); } + if (wcslen(floppyfns[c]) == 0) { + sprintf(temp, "fdd_%02i_fn", c+1); + config_delete_var(cat, temp); + } + if (ui_writeprot[c] == 0) { + sprintf(temp, "fdd_%02i_writeprot", c+1); + config_delete_var(cat, temp); + } + if (fdd_get_turbo(c) == 0) { + sprintf(temp, "fdd_%02i_turbo", c+1); + config_delete_var(cat, temp); + } + if (fdd_get_check_bpb(c) == 1) { + sprintf(temp, "fdd_%02i_check_bpb", c+1); + config_delete_var(cat, temp); + } + } - memset(temps, 0, 512); - for (c = 0; c < CDROM_NUM; c++) - { - sprintf(temps, "cdrom_%02i_host_drive", c + 1); - cdrom_drives[c].host_drive = config_get_int(cat, temps, 0); - cdrom_drives[c].prev_host_drive = cdrom_drives[c].host_drive; + memset(temp, 0x00, sizeof(temp)); + for (c=0; c>1, (c+2)&1); + p = config_get_string(cat, temp, temp2); + if (! strstr(p, ":")) { + sscanf(p, "%i", (int *)&hdd[c].ide_channel); + cdrom_drives[c].ide_channel &= 7; + } else { + sscanf(p, "%02u:%02u", &board, &dev); + + board &= 3; + dev &= 1; + cdrom_drives[c].ide_channel = (board<<1)+dev; } - cdrom_drives[c].bus_type = hdd_string_to_bus(s, 1); - - sprintf(temps, "cdrom_%02i_ide_channel", c + 1); - if ((cdrom_drives[c].bus_type == CDROM_BUS_ATAPI_PIO_ONLY) || (cdrom_drives[c].bus_type == CDROM_BUS_ATAPI_PIO_AND_DMA)) - { - sprintf(temps2, "%01u:%01u", (c + 2) >> 1, (c + 2) & 1); - p = config_get_string(cat, temps, temps2); - - if (strstr(p, ":") == NULL) - { - sscanf(p, "%i", (int *)&hdd[c].ide_channel); - cdrom_drives[c].ide_channel &= 7; - } - else - { - sscanf(p, "%02u:%02u", &board, &dev); - - board &= 3; - dev &= 1; - cdrom_drives[c].ide_channel = (board << 1) + dev; - } - - if (cdrom_drives[c].ide_channel > 7) - { - cdrom_drives[c].ide_channel = 7; - } - } - else - { - config_delete_var(cat, temps); - } - - sprintf(temps, "cdrom_%02i_scsi_location", c + 1); - if (cdrom_drives[c].bus_type == CDROM_BUS_SCSI) - { - sprintf(temps2, "%02u:%02u", c + 2, 0); - p = config_get_string(cat, temps, temps2); - sscanf(p, "%02u:%02u", &cdrom_drives[c].scsi_device_id, &cdrom_drives[c].scsi_device_lun); - + if (cdrom_drives[c].ide_channel > 7) + cdrom_drives[c].ide_channel = 7; + else + config_delete_var(cat, temp); + } else { + sprintf(temp, "cdrom_%02i_scsi_location", c+1); + if (cdrom_drives[c].bus_type == CDROM_BUS_SCSI) { + sprintf(temp2, "%02u:%02u", c+2, 0); + p = config_get_string(cat, temp, temp2); + sscanf(p, "%02u:%02u", + &cdrom_drives[c].scsi_device_id, + &cdrom_drives[c].scsi_device_lun); + if (cdrom_drives[c].scsi_device_id > 15) - { cdrom_drives[c].scsi_device_id = 15; - } if (cdrom_drives[c].scsi_device_lun > 7) - { cdrom_drives[c].scsi_device_lun = 7; - } + } else { + config_delete_var(cat, temp); } - else - { - config_delete_var(cat, temps); - } - - sprintf(temps, "cdrom_%02i_image_path", c + 1); - wp = config_get_wstring(cat, temps, L""); -#if 0 - /* - * NOTE: - * Temporary hack to remove the absolute - * path currently saved in most config - * files. We should remove this before - * finalizing this release! --FvK - */ - if (! wcsnicmp(wp, cfg_path, wcslen(cfg_path))) { - /* - * Yep, its absolute and prefixed - * with the EXE path. Just strip - * that off for now... - */ - wcscpy((wchar_t *)cdrom_image[c].image_path, &wp[wcslen(cfg_path)]); - } else -#endif - memcpy(cdrom_image[c].image_path, wp, (wcslen(wp) << 1) + 2); - wcscpy(cdrom_image[c].prev_image_path, cdrom_image[c].image_path); - - if (cdrom_drives[c].host_drive < 'A') - { - cdrom_drives[c].host_drive = 0; - } - - if ((cdrom_drives[c].host_drive == 0x200) && (wcslen(cdrom_image[c].image_path) == 0)) - { - cdrom_drives[c].host_drive = 0; - } - - /* If the CD-ROM is disabled, delete all its variables. */ - if (cdrom_drives[c].bus_type == CDROM_BUS_DISABLED) - { - sprintf(temps, "cdrom_%02i_host_drive", c + 1); - config_delete_var(cat, temps); - - sprintf(temps, "cdrom_%02i_parameters", c + 1); - config_delete_var(cat, temps); - - sprintf(temps, "cdrom_%02i_ide_channel", c + 1); - config_delete_var(cat, temps); - - sprintf(temps, "cdrom_%02i_scsi_location", c + 1); - config_delete_var(cat, temps); - - sprintf(temps, "cdrom_%02i_image_path", c + 1); - config_delete_var(cat, temps); - } - - sprintf(temps, "cdrom_%02i_iso_path", c + 1); - config_delete_var(cat, temps); } + + sprintf(temp, "cdrom_%02i_image_path", c+1); + wp = config_get_wstring(cat, temp, L""); + +#if 0 + /* + * NOTE: + * Temporary hack to remove the absolute + * path currently saved in most config + * files. We should remove this before + * finalizing this release! --FvK + */ + if (! wcsnicmp(wp, cfg_path, wcslen(cfg_path))) { + /* + * Yep, its absolute and prefixed + * with the EXE path. Just strip + * that off for now... + */ + wcscpy(cdrom_image[c].image_path,&wp[wcslen(cfg_path)]); + } else +#endif + memcpy(cdrom_image[c].image_path, wp, (wcslen(wp) << 1) + 2); + wcscpy(cdrom_image[c].prev_image_path, cdrom_image[c].image_path); + + if (cdrom_drives[c].host_drive < 'A') + cdrom_drives[c].host_drive = 0; + + if ((cdrom_drives[c].host_drive == 0x200) && + (wcslen(cdrom_image[c].image_path) == 0)) + cdrom_drives[c].host_drive = 0; + + /* If the CD-ROM is disabled, delete all its variables. */ + if (cdrom_drives[c].bus_type == CDROM_BUS_DISABLED) { + sprintf(temp, "cdrom_%02i_host_drive", c+1); + config_delete_var(cat, temp); + + sprintf(temp, "cdrom_%02i_parameters", c+1); + config_delete_var(cat, temp); + + sprintf(temp, "cdrom_%02i_ide_channel", c+1); + config_delete_var(cat, temp); + + sprintf(temp, "cdrom_%02i_scsi_location", c+1); + config_delete_var(cat, temp); + + sprintf(temp, "cdrom_%02i_image_path", c+1); + config_delete_var(cat, temp); + } + + sprintf(temp, "cdrom_%02i_iso_path", c+1); + config_delete_var(cat, temp); + } } @@ -1401,66 +1104,43 @@ load_removable_devices(void) void config_load(wchar_t *fn) { - int i = 0; + if (fn == NULL) + fn = config_file_default; + pclog("Loading config file '%ws'..\n", fn); - if (fn == NULL) - fn = config_file_default; - pclog("Loading config file '%ws'..\n", fn); - i = config_read(fn); - - if (i == 0) - { - cpu = 0; + if (! config_read(fn)) { + cpu = 0; #ifndef __unix - dwLanguage = 0x0409; + dwLanguage = 0x0409; #endif - scale = 1; - vid_api = 1; - enable_sync = 1; - joystick_type = 7; - strcpy(hdc_name, "none"); - serial_enabled[0] = 1; - serial_enabled[1] = 1; - lpt_enabled = 1; - fdd_set_type(0, 2); - fdd_set_type(1, 2); - mem_size = 640; + scale = 1; + vid_api = 1; + enable_sync = 1; + joystick_type = 7; + strcpy(hdc_name, "none"); + serial_enabled[0] = 0; + serial_enabled[1] = 0; + lpt_enabled = 0; + fdd_set_type(0, 2); + fdd_set_type(1, 2); + mem_size = 640; - pclog("Config file not present or invalid!\n"); - return; - } + pclog("Config file not present or invalid!\n"); + return; + } - /* General */ - load_general(); + load_general(); /* General */ + load_machine(); /* Machine */ + load_video(); /* Video */ + load_input_devices(); /* Input devices */ + load_sound(); /* Sound */ + load_network(); /* Network */ + load_ports(); /* Ports (COM & LPT) */ + load_other_peripherals(); /* Other peripherals */ + load_hard_disks(); /* Hard disks */ + load_removable_devices(); /* Removable devices */ - /* Machine */ - load_machine(); - - /* Video */ - load_video(); - - /* Input devices */ - load_input_devices(); - - /* Sound */ - load_sound(); - - /* Network */ - load_network(); - - /* Ports (COM & LPT) */ - load_ports(); - - /* Other peripherals */ - load_other_peripherals(); - - /* Hard disks */ - load_hard_disks(); - - /* Removable devices */ - load_removable_devices(); - - pclog("Config loaded.\n"); + pclog("Config loaded.\n"); } @@ -1468,130 +1148,84 @@ config_load(wchar_t *fn) static void save_general(void) { - char *cat = "General"; - char temp[512]; + char *cat = "General"; + char temp[512]; - config_set_int(cat, "vid_resize", vid_resize); - if (vid_resize == 0) - { - config_delete_var(cat, "vid_resize"); - } + config_set_int(cat, "vid_resize", vid_resize); + if (vid_resize == 0) + config_delete_var(cat, "vid_resize"); - if (vid_api == 1) - { - config_delete_var(cat, "vid_renderer"); - } - else - { - switch(vid_api) - { - case 0: - config_set_string(cat, "vid_renderer", "ddraw"); - break; - case 1: - default: - config_set_string(cat, "vid_renderer", "d3d9"); - break; - } - } + if (vid_api == 1) { + config_delete_var(cat, "vid_renderer"); + } else switch(vid_api) { + case 0: + config_set_string(cat, "vid_renderer", "ddraw"); + break; - if (video_fullscreen_scale == 0) - { - config_delete_var(cat, "video_fullscreen_scale"); - } - else - { - config_set_int(cat, "video_fullscreen_scale", video_fullscreen_scale); - } + case 1: + default: + config_set_string(cat, "vid_renderer", "d3d9"); + break; + } - if (video_fullscreen_first == 0) - { - config_delete_var(cat, "video_fullscreen_first"); - } - else - { - config_set_int(cat, "video_fullscreen_first", video_fullscreen_first); - } + if (video_fullscreen_scale == 0) + config_delete_var(cat, "video_fullscreen_scale"); + else + config_set_int(cat, "video_fullscreen_scale", video_fullscreen_scale); - if (force_43 == 0) - { - config_delete_var(cat, "force_43"); - } - else - { - config_set_int(cat, "force_43", force_43); - } + if (video_fullscreen_first == 0) + config_delete_var(cat, "video_fullscreen_first"); + else + config_set_int(cat, "video_fullscreen_first", video_fullscreen_first); - if (scale == 1) - { - config_delete_var(cat, "scale"); - } - else - { - config_set_int(cat, "scale", scale); - } + if (force_43 == 0) + config_delete_var(cat, "force_43"); + else + config_set_int(cat, "force_43", force_43); - if (enable_overscan == 0) - { - config_delete_var(cat, "enable_overscan"); - } - else - { - config_set_int(cat, "enable_overscan", enable_overscan); - } + if (scale == 1) + config_delete_var(cat, "scale"); + else + config_set_int(cat, "scale", scale); - if (vid_cga_contrast == 0) - { - config_delete_var(cat, "vid_cga_contrast"); - } - else - { - config_set_int(cat, "vid_cga_contrast", vid_cga_contrast); - } + if (enable_overscan == 0) + config_delete_var(cat, "enable_overscan"); + else + config_set_int(cat, "enable_overscan", enable_overscan); - if (video_grayscale == 0) - { - config_delete_var(cat, "video_grayscale"); - } - else - { - config_set_int(cat, "video_grayscale", video_grayscale); - } + if (vid_cga_contrast == 0) + config_delete_var(cat, "vid_cga_contrast"); + else + config_set_int(cat, "vid_cga_contrast", vid_cga_contrast); - if (video_graytype == 0) - { - config_delete_var(cat, "video_graytype"); - } - else - { - config_set_int(cat, "video_graytype", video_graytype); - } + if (video_grayscale == 0) + config_delete_var(cat, "video_grayscale"); + else + config_set_int(cat, "video_grayscale", video_grayscale); - if (window_remember) - { - config_set_int(cat, "window_remember", window_remember); + if (video_graytype == 0) + config_delete_var(cat, "video_graytype"); + else + config_set_int(cat, "video_graytype", video_graytype); - sprintf(temp, "%i, %i, %i, %i", window_w, window_h, window_x, window_y); - config_set_string(cat, "window_coordinates", temp); - } - else - { - config_delete_var(cat, "window_remember"); - config_delete_var(cat, "window_coordinates"); - } + if (window_remember) { + config_set_int(cat, "window_remember", window_remember); + + sprintf(temp, "%i, %i, %i, %i", window_w, window_h, window_x, window_y); + config_set_string(cat, "window_coordinates", temp); + } else { + config_delete_var(cat, "window_remember"); + config_delete_var(cat, "window_coordinates"); + } #ifndef __unix - if (dwLanguage == 0x0409) - { - config_delete_var(cat, "language"); - } - else - { - config_set_hex16(cat, "language", dwLanguage); - } + if (dwLanguage == 0x0409) + config_delete_var(cat, "language"); + else + config_set_hex16(cat, "language", dwLanguage); #endif - delete_section_if_empty(cat); + delete_section_if_empty(cat); } @@ -1599,67 +1233,43 @@ save_general(void) static void save_machine(void) { - char *cat = "Machine"; + char *cat = "Machine"; - config_set_string(cat, "machine", machine_get_internal_name()); + config_set_string(cat, "machine", machine_get_internal_name()); - if (cpu_manufacturer == 0) - { - config_delete_var(cat, "cpu_manufacturer"); - } - else - { - config_set_int(cat, "cpu_manufacturer", cpu_manufacturer); - } + if (cpu_manufacturer == 0) + config_delete_var(cat, "cpu_manufacturer"); + else + config_set_int(cat, "cpu_manufacturer", cpu_manufacturer); - if (cpu == 0) - { - config_delete_var(cat, "cpu"); - } - else - { - config_set_int(cat, "cpu", cpu); - } + if (cpu == 0) + config_delete_var(cat, "cpu"); + else + config_set_int(cat, "cpu", cpu); - if (cpu_waitstates == 0) - { - config_delete_var(cat, "cpu_waitstates"); - } - else - { - config_set_int(cat, "cpu_waitstates", cpu_waitstates); - } + if (cpu_waitstates == 0) + config_delete_var(cat, "cpu_waitstates"); + else + config_set_int(cat, "cpu_waitstates", cpu_waitstates); - if (mem_size == 4096) - { - config_delete_var(cat, "mem_size"); - } - else - { - config_set_int(cat, "mem_size", mem_size); - } + if (mem_size == 4096) + config_delete_var(cat, "mem_size"); + else + config_set_int(cat, "mem_size", mem_size); - config_set_int(cat, "cpu_use_dynarec", cpu_use_dynarec); + config_set_int(cat, "cpu_use_dynarec", cpu_use_dynarec); - if (enable_external_fpu == 0) - { - config_delete_var(cat, "cpu_enable_fpu"); - } - else - { - config_set_int(cat, "cpu_enable_fpu", enable_external_fpu); - } + if (enable_external_fpu == 0) + config_delete_var(cat, "cpu_enable_fpu"); + else + config_set_int(cat, "cpu_enable_fpu", enable_external_fpu); - if (enable_sync == 1) - { - config_delete_var(cat, "enable_sync"); - } - else - { - config_set_int(cat, "enable_sync", enable_sync); - } + if (enable_sync == 1) + config_delete_var(cat, "enable_sync"); + else + config_set_int(cat, "enable_sync", enable_sync); - delete_section_if_empty(cat); + delete_section_if_empty(cat); } @@ -1667,29 +1277,22 @@ save_machine(void) static void save_video(void) { - char *cat = "Video"; + char *cat = "Video"; - config_set_string(cat, "gfxcard", video_get_internal_name(video_old_to_new(gfxcard))); + config_set_string(cat, "gfxcard", + video_get_internal_name(video_old_to_new(gfxcard))); - if (video_speed == 3) - { - config_delete_var(cat, "video_speed"); - } - else - { - config_set_int(cat, "video_speed", video_speed); - } + if (video_speed == 3) + config_delete_var(cat, "video_speed"); + else + config_set_int(cat, "video_speed", video_speed); - if (voodoo_enabled == 0) - { - config_delete_var(cat, "voodoo"); - } - else - { - config_set_int(cat, "voodoo", voodoo_enabled); - } + if (voodoo_enabled == 0) + config_delete_var(cat, "voodoo"); + else + config_set_int(cat, "voodoo", voodoo_enabled); - delete_section_if_empty(cat); + delete_section_if_empty(cat); } @@ -1697,78 +1300,61 @@ save_video(void) static void save_input_devices(void) { - char *cat = "Input devices"; - char temp[512]; - char s[512]; - int c, d; + char *cat = "Input devices"; + char temp[512], temp2[512]; + int c, d; - config_set_string(cat, "mouse_type", mouse_get_internal_name(mouse_type)); + config_set_string(cat, "mouse_type", mouse_get_internal_name(mouse_type)); - if ((joystick_type == 0) || (joystick_type == 7)) - { - if (joystick_type == 7) - { - config_delete_var(cat, "joystick_type"); + if ((joystick_type == 0) || (joystick_type == 7)) { + if (joystick_type == 7) + config_delete_var(cat, "joystick_type"); + else + config_set_int(cat, "joystick_type", joystick_type); + + for (c=0; c<16; c++) { + sprintf(temp2, "joystick_%i_nr", c); + config_delete_var(cat, temp2); + + for (d=0; d<16; d++) { + sprintf(temp2, "joystick_%i_axis_%i", c, d); + config_delete_var(cat, temp2); } - else - { - config_set_int(cat, "joystick_type", joystick_type); + for (d=0; d<16; d++) { + sprintf(temp2, "joystick_%i_button_%i", c, d); + config_delete_var(cat, temp2); + } + for (d=0; d<16; d++) { + sprintf(temp2, "joystick_%i_pov_%i", c, d); + config_delete_var(cat, temp2); } - - for (c = 0; c < 16; c++) - { - sprintf(s, "joystick_%i_nr", c); - config_delete_var(cat, s); - - for (d = 0; d < 16; d++) - { - sprintf(s, "joystick_%i_axis_%i", c, d); - config_delete_var(cat, s); - } - for (d = 0; d < 16; d++) - { - sprintf(s, "joystick_%i_button_%i", c, d); - config_delete_var(cat, s); - } - for (d = 0; d < 16; d++) - { - sprintf(s, "joystick_%i_pov_%i", c, d); - config_delete_var(cat, s); - } - } } - else - { - config_set_int(cat, "joystick_type", joystick_type); + } else { + config_set_int(cat, "joystick_type", joystick_type); - for (c = 0; c < joystick_get_max_joysticks(joystick_type); c++) - { - sprintf(s, "joystick_%i_nr", c); - config_set_int(cat, s, joystick_state[c].plat_joystick_nr); + for (c=0; c> 1, hdd[c].ide_channel & 1); - config_set_string(cat, temps, temps2); - } - - sprintf(temps, "hdd_%02i_scsi_location", c + 1); - if (! hdd_is_valid(c) || ((hdd[c].bus != HDD_BUS_SCSI) && (hdd[c].bus != HDD_BUS_SCSI_REMOVABLE))) - { - config_delete_var(cat, temps); - } - else - { - sprintf(temps2, "%02u:%02u", hdd[c].scsi_id, hdd[c].scsi_lun); - config_set_string(cat, temps, temps2); - } - - sprintf(temps, "hdd_%02i_fn", c+1); - if (! hdd_is_valid(c) || (wcslen(hdd[c].fn) == 0)) - { - config_delete_var(cat, temps); - } - else - { - config_set_wstring(cat, temps, hdd[c].fn); - } + memset(temp, 0x00, sizeof(temp)); + for (c=0; c> 1, hdd[c].ide_channel & 1); + config_set_string(cat, temp, temp2); + } + + sprintf(temp, "hdd_%02i_scsi_location", c+1); + if (! hdd_is_valid(c) || ((hdd[c].bus != HDD_BUS_SCSI) && (hdd[c].bus != HDD_BUS_SCSI_REMOVABLE))) { + config_delete_var(cat, temp); + } else { + sprintf(temp2, "%02u:%02u", hdd[c].scsi_id, hdd[c].scsi_lun); + config_set_string(cat, temp, temp2); + } + + sprintf(temp, "hdd_%02i_fn", c+1); + if (hdd_is_valid(c) || (wcslen(hdd[c].fn) == 0)) + config_set_wstring(cat, temp, hdd[c].fn); + else + config_delete_var(cat, temp); + } + + delete_section_if_empty(cat); } @@ -2092,469 +1575,389 @@ save_hard_disks(void) static void save_removable_devices(void) { - char *cat = "Removable devices"; - char temps[512]; - char temps2[512]; - int c; + char *cat = "Removable devices"; + char temp[512], temp2[512]; + int c; - memset(temps, '\0', sizeof(temps)); - for (c = 0; c < FDD_NUM; c++) - { - sprintf(temps, "fdd_%02i_type", c + 1); - if (fdd_get_type(c) == ((c < 2) ? 2 : 0)) - { - config_delete_var(cat, temps); - } - else - { - config_set_string(cat, temps, fdd_get_internal_name(fdd_get_type(c))); - } + for (c=0; c 'Z') && (cdrom_drives[c].host_drive != 200))) - { - config_delete_var(cat, temps); - } - else - { - config_set_int(cat, temps, cdrom_drives[c].host_drive); - } + sprintf(temp, "fdd_%02i_writeprot", c+1); + if (ui_writeprot[c] == 0) + config_delete_var(cat, temp); + else + config_set_int(cat, temp, ui_writeprot[c]); - sprintf(temps, "cdrom_%02i_parameters", c + 1); - if (cdrom_drives[c].bus_type == 0) - { - config_delete_var(cat, temps); - } - else - { - sprintf(temps2, "%u, %s", cdrom_drives[c].sound_on, hdd_bus_to_string(cdrom_drives[c].bus_type, 1)); - config_set_string(cat, temps, temps2); - } + sprintf(temp, "fdd_%02i_turbo", c+1); + if (fdd_get_turbo(c) == 0) + config_delete_var(cat, temp); + else + config_set_int(cat, temp, fdd_get_turbo(c)); + + sprintf(temp, "fdd_%02i_check_bpb", c+1); + if (fdd_get_check_bpb(c) == 1) + config_delete_var(cat, temp); + else + config_set_int(cat, temp, fdd_get_check_bpb(c)); + } + + for (c=0; c 'Z') && (cdrom_drives[c].host_drive != 200))) { + config_delete_var(cat, temp); + } else { + config_set_int(cat, temp, cdrom_drives[c].host_drive); + } + + sprintf(temp, "cdrom_%02i_parameters", c+1); + if (cdrom_drives[c].bus_type == 0) { + config_delete_var(cat, temp); + } else { + sprintf(temp2, "%u, %s", cdrom_drives[c].sound_on, + hdd_bus_to_string(cdrom_drives[c].bus_type, 1)); + config_set_string(cat, temp, temp2); + } - sprintf(temps, "cdrom_%02i_ide_channel", c + 1); - if ((cdrom_drives[c].bus_type != CDROM_BUS_ATAPI_PIO_ONLY) && (cdrom_drives[c].bus_type != CDROM_BUS_ATAPI_PIO_AND_DMA)) - { - config_delete_var(cat, temps); - } - else - { - sprintf(temps2, "%01u:%01u", cdrom_drives[c].ide_channel >> 1, cdrom_drives[c].ide_channel & 1); - config_set_string(cat, temps, temps2); - } - - sprintf(temps, "cdrom_%02i_scsi_location", c + 1); - if (cdrom_drives[c].bus_type != CDROM_BUS_SCSI) - { - config_delete_var(cat, temps); - } - else - { - sprintf(temps2, "%02u:%02u", cdrom_drives[c].scsi_device_id, cdrom_drives[c].scsi_device_lun); - config_set_string(cat, temps, temps2); - } - - sprintf(temps, "cdrom_%02i_image_path", c + 1); - if ((cdrom_drives[c].bus_type == 0) || (wcslen(cdrom_image[c].image_path) == 0)) - { - config_delete_var(cat, temps); - } - else - { - config_set_wstring(cat, temps, cdrom_image[c].image_path); - } + sprintf(temp, "cdrom_%02i_ide_channel", c+1); + if ((cdrom_drives[c].bus_type != CDROM_BUS_ATAPI_PIO_ONLY) && + (cdrom_drives[c].bus_type != CDROM_BUS_ATAPI_PIO_AND_DMA)) { + config_delete_var(cat, temp); + } else { + sprintf(temp2, "%01u:%01u", cdrom_drives[c].ide_channel>>1, + cdrom_drives[c].ide_channel & 1); + config_set_string(cat, temp, temp2); } - delete_section_if_empty(cat); + sprintf(temp, "cdrom_%02i_scsi_location", c + 1); + if (cdrom_drives[c].bus_type != CDROM_BUS_SCSI) { + config_delete_var(cat, temp); + } else { + sprintf(temp2, "%02u:%02u", cdrom_drives[c].scsi_device_id, + cdrom_drives[c].scsi_device_lun); + config_set_string(cat, temp, temp2); + } + + sprintf(temp, "cdrom_%02i_image_path", c + 1); + if ((cdrom_drives[c].bus_type == 0) || + (wcslen(cdrom_image[c].image_path) == 0)) { + config_delete_var(cat, temp); + } else { + config_set_wstring(cat, temp, cdrom_image[c].image_path); + } + } + + delete_section_if_empty(cat); } void config_save(void) { - /* General */ - save_general(); + save_general(); /* General */ + save_machine(); /* Machine */ + save_video(); /* Video */ + save_input_devices(); /* Input devices */ + save_sound(); /* Sound */ + save_network(); /* Network */ + save_ports(); /* Ports (COM & LPT) */ + save_other_peripherals(); /* Other peripherals */ + save_hard_disks(); /* Hard disks */ + save_removable_devices(); /* Removable devices */ - /* Machine */ - save_machine(); - - /* Video */ - save_video(); - - /* Input devices */ - save_input_devices(); - - /* Sound */ - save_sound(); - - /* Network */ - save_network(); - - /* Ports (COM & LPT) */ - save_ports(); - - /* Other peripherals */ - save_other_peripherals(); - - /* Hard disks */ - save_hard_disks(); - - /* Removable devices */ - save_removable_devices(); - - config_write(config_file_default); + config_write(config_file_default); } void config_dump(void) { - section_t *sec; - - pclog("Config data :\n"); - - sec = (section_t *)config_head.next; - while (sec != NULL) - { - entry_t *ent; + section_t *sec; + + sec = (section_t *)config_head.next; + while (sec != NULL) { + entry_t *ent; - if (sec->name && sec->name[0]) - pclog("[%s]\n", sec->name); - - ent = (entry_t *)sec->entry_head.next; - - while (ent != NULL) - { - pclog("%s = %s\n", ent->name, ent->data); + if (sec->name && sec->name[0]) + pclog("[%s]\n", sec->name); + + ent = (entry_t *)sec->entry_head.next; + while (ent != NULL) { + pclog("%s = %s\n", ent->name, ent->data); - ent = (entry_t *)ent->list.next; - } + ent = (entry_t *)ent->list.next; + } - sec = (section_t *)sec->list.next; - } + sec = (section_t *)sec->list.next; + } } void config_delete_var(char *head, char *name) { - section_t *section; - entry_t *entry; - - section = find_section(head); - if (section == NULL) return; - - entry = find_entry(section, name); - if (entry == NULL) return; + section_t *section; + entry_t *entry; + section = find_section(head); + if (section == NULL) return; + + entry = find_entry(section, name); + if (entry != NULL) { list_delete(&entry->list, §ion->entry_head); free(entry); + } } int config_get_int(char *head, char *name, int def) { - section_t *section; - entry_t *entry; - int value; + section_t *section; + entry_t *entry; + int value; - section = find_section(head); - - if (!section) - return def; - - entry = find_entry(section, name); + section = find_section(head); + if (section == NULL) + return(def); + + entry = find_entry(section, name); + if (entry == NULL) + return(def); - if (!entry) - return def; - - sscanf(entry->data, "%i", &value); - - return value; + sscanf(entry->data, "%i", &value); + + return(value); } int config_get_hex16(char *head, char *name, int def) { - section_t *section; - entry_t *entry; - int value; + section_t *section; + entry_t *entry; + int value; - section = find_section(head); - - if (!section) - return def; - - entry = find_entry(section, name); + section = find_section(head); + if (section == NULL) + return(def); - if (!entry) - return def; - - sscanf(entry->data, "%04X", &value); - - return value; + entry = find_entry(section, name); + if (entry == NULL) + return(def); + + sscanf(entry->data, "%04X", &value); + + return(value); } int config_get_hex20(char *head, char *name, int def) { - section_t *section; - entry_t *entry; - int value; + section_t *section; + entry_t *entry; + int value; - section = find_section(head); - - if (!section) - return def; - - entry = find_entry(section, name); + section = find_section(head); + if (section == NULL) + return(def); - if (!entry) - return def; - - sscanf(entry->data, "%05X", &value); - - return value; + entry = find_entry(section, name); + if (entry == NULL) + return(def); + + sscanf(entry->data, "%05X", &value); + + return(value); } int config_get_mac(char *head, char *name, int def) { - section_t *section; - entry_t *entry; - int val0 = 0, val1 = 0, val2 = 0; + section_t *section; + entry_t *entry; + int val0 = 0, val1 = 0, val2 = 0; - section = find_section(head); - - if (!section) - return def; - - entry = find_entry(section, name); + section = find_section(head); + if (section == NULL) + return(def); - if (!entry) - return def; - - sscanf(entry->data, "%02x:%02x:%02x", &val0, &val1, &val2); + entry = find_entry(section, name); + if (entry == NULL) + return(def); - return (val0 << 16) + (val1 << 8) + val2; + sscanf(entry->data, "%02x:%02x:%02x", &val0, &val1, &val2); + + return((val0 << 16) + (val1 << 8) + val2); } char * config_get_string(char *head, char *name, char *def) { - section_t *section; - entry_t *entry; + section_t *section; + entry_t *entry; - section = find_section(head); - - if (!section) - return def; - - entry = find_entry(section, name); + section = find_section(head); + if (section == NULL) + return(def); - if (!entry) - return def; - - return entry->data; + entry = find_entry(section, name); + if (entry == NULL) + return(def); + + return(entry->data); } wchar_t * config_get_wstring(char *head, char *name, wchar_t *def) { - section_t *section; - entry_t *entry; + section_t *section; + entry_t *entry; - section = find_section(head); - - if (!section) - return def; - - entry = find_entry(section, name); + section = find_section(head); + if (section == NULL) + return(def); - if (!entry) - return def; - - return entry->wdata; + entry = find_entry(section, name); + if (entry == NULL) + return(def); + + return(entry->wdata); } void config_set_int(char *head, char *name, int val) { - section_t *section; - entry_t *entry; + section_t *section; + entry_t *entry; - section = find_section(head); - - if (!section) - section = create_section(head); - - entry = find_entry(section, name); + section = find_section(head); + if (section == NULL) + section = create_section(head); - if (!entry) - entry = create_entry(section, name); + entry = find_entry(section, name); + if (entry == NULL) + entry = create_entry(section, name); - sprintf(entry->data, "%i", val); - mbstowcs(entry->wdata, entry->data, 512); + sprintf(entry->data, "%i", val); + mbstowcs(entry->wdata, entry->data, 512); } void config_set_hex16(char *head, char *name, int val) { - section_t *section; - entry_t *entry; + section_t *section; + entry_t *entry; - section = find_section(head); - - if (!section) - section = create_section(head); - - entry = find_entry(section, name); + section = find_section(head); + if (section == NULL) + section = create_section(head); - if (!entry) - entry = create_entry(section, name); + entry = find_entry(section, name); + if (entry == NULL) + entry = create_entry(section, name); - sprintf(entry->data, "%04X", val); - mbstowcs(entry->wdata, entry->data, 512); + sprintf(entry->data, "%04X", val); + mbstowcs(entry->wdata, entry->data, 512); } void config_set_hex20(char *head, char *name, int val) { - section_t *section; - entry_t *entry; + section_t *section; + entry_t *entry; - section = find_section(head); - - if (!section) - section = create_section(head); - - entry = find_entry(section, name); + section = find_section(head); + if (section == NULL) + section = create_section(head); - if (!entry) - entry = create_entry(section, name); + entry = find_entry(section, name); + if (entry == NULL) + entry = create_entry(section, name); - sprintf(entry->data, "%05X", val); - mbstowcs(entry->wdata, entry->data, 512); + sprintf(entry->data, "%05X", val); + mbstowcs(entry->wdata, entry->data, 512); } void config_set_mac(char *head, char *name, int val) { - section_t *section; - entry_t *entry; + section_t *section; + entry_t *entry; - section = find_section(head); - - if (!section) - section = create_section(head); - - entry = find_entry(section, name); + section = find_section(head); + if (section == NULL) + section = create_section(head); - if (!entry) - entry = create_entry(section, name); + entry = find_entry(section, name); + if (entry == NULL) + entry = create_entry(section, name); - sprintf(entry->data, "%02x:%02x:%02x", + sprintf(entry->data, "%02x:%02x:%02x", (val>>16)&0xff, (val>>8)&0xff, val&0xff); - mbstowcs(entry->wdata, entry->data, 512); + mbstowcs(entry->wdata, entry->data, 512); } void config_set_string(char *head, char *name, char *val) { - section_t *section; - entry_t *entry; + section_t *section; + entry_t *entry; - section = find_section(head); - - if (!section) - section = create_section(head); - - entry = find_entry(section, name); + section = find_section(head); + if (section == NULL) + section = create_section(head); - if (!entry) - entry = create_entry(section, name); + entry = find_entry(section, name); + if (entry == NULL) + entry = create_entry(section, name); - strncpy(entry->data, val, 256); - mbstowcs(entry->wdata, entry->data, 256); + strncpy(entry->data, val, 256); + mbstowcs(entry->wdata, entry->data, 256); } void config_set_wstring(char *head, char *name, wchar_t *val) { - section_t *section; - entry_t *entry; + section_t *section; + entry_t *entry; - section = find_section(head); - - if (!section) - section = create_section(head); - - entry = find_entry(section, name); + section = find_section(head); + if (section == NULL) + section = create_section(head); - if (!entry) - entry = create_entry(section, name); + entry = find_entry(section, name); + if (entry == NULL) + entry = create_entry(section, name); - memcpy(entry->wdata, val, 512); + memcpy(entry->wdata, val, 512); } @@ -2562,14 +1965,15 @@ config_set_wstring(char *head, char *name, wchar_t *val) char * get_filename(char *s) { - int c = strlen(s) - 1; - while (c > 0) - { - if (s[c] == '/' || s[c] == '\\') - return &s[c+1]; - c--; - } - return s; + int c = strlen(s) - 1; + + while (c > 0) { + if (s[c] == '/' || s[c] == '\\') + return(&s[c+1]); + c--; + } + + return(s); } @@ -2577,14 +1981,15 @@ get_filename(char *s) wchar_t * get_filename_w(wchar_t *s) { - int c = wcslen(s) - 1; - while (c > 0) - { - if (s[c] == L'/' || s[c] == L'\\') - return &s[c+1]; - c--; - } - return s; + int c = wcslen(s) - 1; + + while (c > 0) { + if (s[c] == L'/' || s[c] == L'\\') + return(&s[c+1]); + c--; + } + + return(s); } @@ -2592,7 +1997,7 @@ get_filename_w(wchar_t *s) void append_filename(char *dest, char *s1, char *s2, int size) { - sprintf(dest, "%s%s", s1, s2); + sprintf(dest, "%s%s", s1, s2); } @@ -2600,7 +2005,7 @@ append_filename(char *dest, char *s1, char *s2, int size) void append_filename_w(wchar_t *dest, wchar_t *s1, wchar_t *s2, int size) { - _swprintf(dest, L"%s%s", s1, s2); + _swprintf(dest, L"%s%s", s1, s2); } @@ -2608,9 +2013,10 @@ append_filename_w(wchar_t *dest, wchar_t *s1, wchar_t *s2, int size) void put_backslash(char *s) { - int c = strlen(s) - 1; - if (s[c] != '/' && s[c] != '\\') - s[c] = '/'; + int c = strlen(s) - 1; + + if (s[c] != '/' && s[c] != '\\') + s[c] = '/'; } @@ -2618,9 +2024,10 @@ put_backslash(char *s) void put_backslash_w(wchar_t *s) { - int c = wcslen(s) - 1; - if (s[c] != L'/' && s[c] != L'\\') - s[c] = L'/'; + int c = wcslen(s) - 1; + + if (s[c] != L'/' && s[c] != L'\\') + s[c] = L'/'; } @@ -2628,35 +2035,35 @@ put_backslash_w(wchar_t *s) char * get_extension(char *s) { - int c = strlen(s) - 1; + int c = strlen(s) - 1; - if (c <= 0) - return s; - - while (c && s[c] != '.') - c--; - - if (!c) - return &s[strlen(s)]; + if (c <= 0) + return(s); - return &s[c+1]; -} + while (c && s[c] != '.') + c--; + + if (!c) + return(&s[strlen(s)]); + + return(&s[c+1]); +} /* FIXME: should be moved elsewhere. --FvK */ wchar_t *get_extension_w(wchar_t *s) { - int c = wcslen(s) - 1; + int c = wcslen(s) - 1; - if (c <= 0) - return s; - - while (c && s[c] != L'.') - c--; - - if (!c) - return &s[wcslen(s)]; + if (c <= 0) + return(s); + + while (c && s[c] != L'.') + c--; + + if (!c) + return(&s[wcslen(s)]); - return &s[c+1]; -} + return(&s[c+1]); +} diff --git a/src/cpu/808x.c b/src/cpu/808x.c index 8c8dee9fb..d3f98e84d 100644 --- a/src/cpu/808x.c +++ b/src/cpu/808x.c @@ -18,7 +18,7 @@ * 2 clocks - fetch opcode 1 2 clocks - execute * 2 clocks - fetch opcode 2 etc * - * Version: @(#)808x.c 1.0.2 2017/09/24 + * Version: @(#)808x.c 1.0.3 2017/10/04 * * Authors: Sarah Walker, * Miran Grca, @@ -28,18 +28,18 @@ #include #include #include -//#include #include #include "../ibm.h" #include "cpu.h" #include "x86.h" -#include "../keyboard.h" +#include "../keyboard.h" /* its WRONG to have this in here!! --FvK */ #include "../mem.h" #include "../rom.h" #include "../nmi.h" #include "../pic.h" #include "../timer.h" -#include "../scsi/scsi.h" +#include "../device.h" /* for scsi.h */ +#include "../scsi/scsi.h" /* its WRONG to have this in here!! --FvK */ int xt_cpu_multi; int nmi = 0; diff --git a/src/cpu/x86_ops.h b/src/cpu/x86_ops.h index 7cce21c61..3352a2577 100644 --- a/src/cpu/x86_ops.h +++ b/src/cpu/x86_ops.h @@ -4,6 +4,10 @@ #ifndef _X86_OPS_H #define _X86_OPS_H + +#define UNUSED(x) (void)(x) + + typedef int (*OpFn)(uint32_t fetchdat); void x86_setopcodes(OpFn *opcodes, OpFn *opcodes_0f, OpFn *dynarec_opcodes, OpFn *dynarec_opcodes_0f); diff --git a/src/device.c b/src/device.c index 552b22f53..5340594ac 100644 --- a/src/device.c +++ b/src/device.c @@ -9,7 +9,7 @@ * Implementation of the generic device interface to handle * all devices attached to the emulator. * - * Version: @(#)device.c 1.0.4 2017/10/01 + * Version: @(#)device.c 1.0.4 2017/10/04 * * Authors: Sarah Walker, * Miran Grca, @@ -31,335 +31,339 @@ #define DEVICE_MAX 256 /* max # of devices */ -static void *device_priv[DEVICE_MAX]; -static device_t *devices[DEVICE_MAX]; -static device_t *current_device; +static device_t *devices[DEVICE_MAX]; +static void *device_priv[DEVICE_MAX]; +static device_t *device_current; -void device_init(void) +void +device_init(void) { - memset(devices, 0x00, sizeof(devices)); + memset(devices, 0x00, sizeof(devices)); } -void device_add(device_t *d) +void +device_add(device_t *d) { - int c = 0; - void *priv = NULL; - - while (devices[c] != NULL && c < 256) + void *priv = NULL; + int c = 0; + + while (devices[c] != NULL && c < 256) c++; - if (c >= DEVICE_MAX) - fatal("device_add : too many devices\n"); + if (c >= DEVICE_MAX) + fatal("device_add: too many devices\n"); - current_device = d; - - if (d->init != NULL) - { - priv = d->init(); - if (priv == NULL) - fatal("device_add : device init failed\n"); - } - - devices[c] = d; - device_priv[c] = priv; + device_current = d; + + if (d->init != NULL) { + priv = d->init(d); + if (priv == NULL) + fatal("device_add: device init failed\n"); + } + + devices[c] = d; + device_priv[c] = priv; } -void device_close_all(void) +void +device_close_all(void) { - int c; + int c; - for (c=0; cclose != NULL) - devices[c]->close(device_priv[c]); - devices[c] = device_priv[c] = NULL; - } - } + for (c=0; cclose != NULL) + devices[c]->close(device_priv[c]); + devices[c] = device_priv[c] = NULL; + } + } } -void *device_get_priv(device_t *d) +void +device_reset_all(void) { - int c; + int c; - for (c=0; creset != NULL) + devices[c]->reset(device_priv[c]); + } + } } -int device_available(device_t *d) +void * +device_get_priv(device_t *d) +{ + int c; + + for (c=0; cflags & DEVICE_NOT_WORKING) - return 0; + if (d->flags & DEVICE_NOT_WORKING) return(0); #endif - if (d->available) - return d->available(); - - return 1; + if (d->available != NULL) + return(d->available()); + + return(1); } -void device_speed_changed(void) +void +device_speed_changed(void) { - int c; - - for (c=0; cspeed_changed != NULL) - { - devices[c]->speed_changed(device_priv[c]); - } - } - } - - sound_speed_changed(); + int c; + + for (c=0; cspeed_changed != NULL) + devices[c]->speed_changed(device_priv[c]); + } + } + + sound_speed_changed(); } -void device_force_redraw(void) +void +device_force_redraw(void) { - int c; - - for (c=0; cforce_redraw != NULL) - { + int c; + + for (c=0; cforce_redraw != NULL) devices[c]->force_redraw(device_priv[c]); - } - } - } + } + } } -char *device_add_status_info(char *s, int max_len) +void +device_add_status_info(char *s, int max_len) { - int c; - - for (c=0; cadd_status_info != NULL) - devices[c]->add_status_info(s, max_len, device_priv[c]); - } - } + int c; - return NULL; + for (c=0; cadd_status_info != NULL) + devices[c]->add_status_info(s, max_len, device_priv[c]); + } + } } -int device_get_config_int(char *s) +char * +device_get_config_string(char *s) { - device_config_t *config = current_device->config; - - while (config && config->type != -1) - { - if (!strcmp(s, config->name)) - return config_get_int(current_device->name, s, config->default_int); + device_config_t *c = device_current->config; - config++; - } - return 0; + while (c && c->type != -1) { + if (! strcmp(s, c->name)) + return(config_get_string(device_current->name, s, c->default_string)); + + c++; + } + + return(NULL); } -int device_get_config_int_ex(char *s, int default_int) +int +device_get_config_int(char *s) { - device_config_t *config = current_device->config; - - while (config && config->type != -1) - { - if (!strcmp(s, config->name)) - return config_get_int(current_device->name, s, default_int); + device_config_t *c = device_current->config; - config++; - } - return default_int; + while (c && c->type != -1) { + if (! strcmp(s, c->name)) + return(config_get_int(device_current->name, s, c->default_int)); + + c++; + } + + return(0); } -int device_get_config_hex16(char *s) +int +device_get_config_int_ex(char *s, int default_int) { - device_config_t *config = current_device->config; + device_config_t *c = device_current->config; - while (config && config->type != -1) - { - if (!strcmp(s, config->name)) - return config_get_hex16(current_device->name, s, config->default_int); + while (c && c->type != -1) { + if (! strcmp(s, c->name)) + return(config_get_int(device_current->name, s, default_int)); - config++; - } - return 0; + c++; + } + + return(default_int); } -int device_get_config_hex20(char *s) +int +device_get_config_hex16(char *s) { - device_config_t *config = current_device->config; - - while (config && config->type != -1) - { - if (!strcmp(s, config->name)) - return config_get_hex20(current_device->name, s, config->default_int); + device_config_t *c = device_current->config; - config++; - } - return 0; + while (c && c->type != -1) { + if (! strcmp(s, c->name)) + return(config_get_hex16(device_current->name, s, c->default_int)); + + c++; + } + + return(0); } -int device_get_config_mac(char *s, int default_int) +int +device_get_config_hex20(char *s) { - device_config_t *config = current_device->config; - - while (config && config->type != -1) - { - if (!strcmp(s, config->name)) - return config_get_mac(current_device->name, s, default_int); + device_config_t *c = device_current->config; - config++; - } - return default_int; + while (c && c->type != -1) { + if (! strcmp(s, c->name)) + return(config_get_hex20(device_current->name, s, c->default_int)); + + c++; + } + + return(0); } -void device_set_config_int(char *s, int val) +int +device_get_config_mac(char *s, int default_int) { - device_config_t *config = current_device->config; - - while (config && config->type != -1) - { - if (!strcmp(s, config->name)) - { - config_set_int(current_device->name, s, val); - return; - } + device_config_t *c = device_current->config; - config++; - } + while (c && c->type != -1) { + if (! strcmp(s, c->name)) + return(config_get_mac(device_current->name, s, default_int)); + + c++; + } + + return(default_int); } -void device_set_config_hex16(char *s, int val) +void +device_set_config_int(char *s, int val) { - device_config_t *config = current_device->config; - - while (config && config->type != -1) - { - if (!strcmp(s, config->name)) - { - config_set_hex16(current_device->name, s, val); - return; - } + device_config_t *c = device_current->config; - config++; - } + while (c && c->type != -1) { + if (! strcmp(s, c->name)) { + config_set_int(device_current->name, s, val); + break; + } + + c++; + } } -void device_set_config_hex20(char *s, int val) +void +device_set_config_hex16(char *s, int val) { - device_config_t *config = current_device->config; - - while (config && config->type != -1) - { - if (!strcmp(s, config->name)) - { - config_set_hex20(current_device->name, s, val); - return; - } + device_config_t *c = device_current->config; - config++; - } + while (c && c->type != -1) { + if (! strcmp(s, c->name)) { + config_set_hex16(device_current->name, s, val); + break; + } + + c++; + } } -void device_set_config_mac(char *s, int val) +void +device_set_config_hex20(char *s, int val) { - device_config_t *config = current_device->config; - - while (config && config->type != -1) - { - if (!strcmp(s, config->name)) - { - config_set_mac(current_device->name, s, val); - return; - } + device_config_t *c = device_current->config; - config++; - } + while (c && c->type != -1) { + if (! strcmp(s, c->name)) { + config_set_hex20(device_current->name, s, val); + break; + } + + c++; + } } -char *device_get_config_string(char *s) +void +device_set_config_mac(char *s, int val) { - device_config_t *config = current_device->config; - - while (config && config->type != -1) - { - if (!strcmp(s, config->name)) - return config_get_string(current_device->name, s, config->default_string); + device_config_t *c = device_current->config; - config++; - } - return NULL; + while (c && c->type != -1) { + if (! strcmp(s, c->name)) { + config_set_mac(device_current->name, s, val); + break; + } + + c++; + } } -int machine_get_config_int(char *s) +int +machine_get_config_int(char *s) { - device_t *device = machine_getdevice(machine); - device_config_t *config; + device_t *d = machine_getdevice(machine); + device_config_t *c; - if (!device) - return 0; + if (d == NULL) return(0); - config = device->config; - - while (config && config->type != -1) - { - if (!strcmp(s, config->name)) - return config_get_int(device->name, s, config->default_int); + c = d->config; + while (c && c->type != -1) { + if (! strcmp(s, c->name)) + return(config_get_int(d->name, s, c->default_int)); - config++; - } - return 0; + c++; + } + + return(0); } -char *machine_get_config_string(char *s) +char * +machine_get_config_string(char *s) { - device_t *device = machine_getdevice(machine); - device_config_t *config; - - if (!device) - return 0; + device_t *d = machine_getdevice(machine); + device_config_t *c; - config = device->config; - - while (config && config->type != -1) - { - if (!strcmp(s, config->name)) - return config_get_string(device->name, s, config->default_string); + if (d == NULL) return(0); - config++; - } - return NULL; + c = d->config; + while (c && c->type != -1) { + if (! strcmp(s, c->name)) + return(config_get_string(d->name, s, c->default_string)); + + c++; + } + + return(NULL); } diff --git a/src/device.h b/src/device.h index 168e11508..58f143133 100644 --- a/src/device.h +++ b/src/device.h @@ -9,12 +9,14 @@ * Implementation of the generic device interface to handle * all devices attached to the emulator. * - * Version: @(#)device.h 1.0.2 2017/08/23 + * Version: @(#)device.h 1.0.3 2017/10/04 * * Authors: Sarah Walker, * Miran Grca, + * Fred N. van Kempen, * Copyright 2008-2016 Sarah Walker. * Copyright 2016,2017 Miran Grca. + * Copyright 2017 Fred N. van Kempen. */ #ifndef EMU_DEVICE_H # define EMU_DEVICE_H @@ -32,69 +34,68 @@ #define CONFIG_MAC 9 -enum -{ - DEVICE_NOT_WORKING = 1, /*Device does not currently work correctly and will be disabled in a release build*/ - DEVICE_AT = 2, /*Device requires an AT-compatible system*/ - DEVICE_PS2 = 4, /*Device requires a PS/1 or PS/2 system*/ - DEVICE_MCA = 0x20, /*Device requires the MCA bus*/ - DEVICE_PCI = 0x40 /*Device requires the PCI bus*/ +enum { + DEVICE_NOT_WORKING = 1, /* does not currently work correctly and will be disabled in a release build*/ + DEVICE_AT = 2, /* requires an AT-compatible system */ + DEVICE_PS2 = 4, /* requires a PS/1 or PS/2 system */ + DEVICE_MCA = 0x20, /* requires the MCA bus */ + DEVICE_PCI = 0x40 /* requires the PCI bus */ }; -typedef struct device_config_selection_t -{ - char description[256]; - int value; +typedef struct { + char description[256]; + int value; } device_config_selection_t; -typedef struct device_config_file_filter_t -{ - char description[256]; - char extensions[25][25]; +typedef struct { + char description[256]; + char extensions[25][25]; } device_config_file_filter_t; -typedef struct device_config_spinner_t -{ - int min; - int max; - int step; +typedef struct { + int min; + int max; + int step; } device_config_spinner_t; -typedef struct device_config_t -{ - char name[256]; - char description[256]; - int type; - char default_string[256]; - int default_int; - device_config_selection_t selection[16]; - device_config_file_filter_t file_filter[16]; - device_config_spinner_t spinner; +typedef struct { + char name[256]; + char description[256]; + int type; + char default_string[256]; + int default_int; + device_config_selection_t selection[16]; + device_config_file_filter_t file_filter[16]; + device_config_spinner_t spinner; } device_config_t; -typedef struct device_t -{ - char name[50]; - uint32_t flags; - void *(*init)(); - void (*close)(void *p); - int (*available)(); - void (*speed_changed)(void *p); - void (*force_redraw)(void *p); - void (*add_status_info)(char *s, int max_len, void *p); - device_config_t *config; +typedef struct _device_ { + char name[50]; + uint32_t flags; /* system flags */ + uint32_t local; /* flags local to device */ + + void *(*init)(struct _device_ *); + void (*close)(void *p); + void (*reset)(void *p); + int (*available)(void); + void (*speed_changed)(void *p); + void (*force_redraw)(void *p); + void (*add_status_info)(char *s, int max_len, void *p); + + device_config_t *config; } device_t; extern void device_init(void); extern void device_add(device_t *d); extern void device_close_all(void); +extern void device_reset_all(void); extern void *device_get_priv(device_t *d); extern int device_available(device_t *d); extern void device_speed_changed(void); extern void device_force_redraw(void); -extern char *device_add_status_info(char *s, int max_len); +extern void device_add_status_info(char *s, int max_len); extern int device_get_config_int(char *name); extern int device_get_config_int_ex(char *s, int default_int); diff --git a/src/disk/hdc.c b/src/disk/hdc.c index 7c1a357f5..5704ca3f5 100644 --- a/src/disk/hdc.c +++ b/src/disk/hdc.c @@ -8,7 +8,7 @@ * * Common code to handle all sorts of disk controllers. * - * Version: @(#)hdc.c 1.0.2 2017/10/01 + * Version: @(#)hdc.c 1.0.3 2017/10/04 * * Authors: Miran Grca, * Fred N. van Kempen, @@ -31,7 +31,7 @@ int hdc_current; static void * -null_init(void) +null_init(device_t *info) { return(NULL); } @@ -44,14 +44,14 @@ null_close(void *priv) static device_t null_device = { - "Null HDC", 0, - null_init, null_close, + "Null HDC", 0, 0, + null_init, null_close, NULL, NULL, NULL, NULL, NULL, NULL }; static void * -inthdc_init(void) +inthdc_init(device_t *info) { return(NULL); } @@ -64,8 +64,8 @@ inthdc_close(void *priv) static device_t inthdc_device = { - "Internal Controller", 0, - inthdc_init, inthdc_close, + "Internal Controller", 0, 0, + inthdc_init, inthdc_close, NULL, NULL, NULL, NULL, NULL, NULL }; diff --git a/src/disk/hdc_esdi_at.c b/src/disk/hdc_esdi_at.c index c50282c4b..3872a8511 100644 --- a/src/disk/hdc_esdi_at.c +++ b/src/disk/hdc_esdi_at.c @@ -8,7 +8,7 @@ * * Driver for the ESDI controller (WD1007-vse1) for PC/AT. * - * Version: @(#)hdc_esdi_at.c 1.0.2 2017/10/01 + * Version: @(#)hdc_esdi_at.c 1.0.3 2017/10/05 * * Authors: Sarah Walker, * Miran Grca, @@ -32,6 +32,7 @@ #include "../pic.h" #include "../rom.h" #include "../timer.h" +#include "../win/win.h" #include "hdc.h" #include "hdd.h" @@ -513,7 +514,7 @@ esdi_callback(void *priv) esdi->pos = 0; esdi->status = STAT_DRQ | STAT_READY | STAT_DSC; irq_raise(esdi); - update_status_bar_icon(SB_HDD | HDD_BUS_ESDI, 1); + StatusBarUpdateIcon(SB_HDD | HDD_BUS_ESDI, 1); break; case CMD_WRITE: @@ -548,7 +549,7 @@ esdi_callback(void *priv) } else { esdi->status = STAT_READY | STAT_DSC; } - update_status_bar_icon(SB_HDD | HDD_BUS_ESDI, 1); + StatusBarUpdateIcon(SB_HDD | HDD_BUS_ESDI, 1); break; case CMD_VERIFY: @@ -574,7 +575,7 @@ esdi_callback(void *priv) break; } - update_status_bar_icon(SB_HDD | HDD_BUS_ESDI, 1); + StatusBarUpdateIcon(SB_HDD | HDD_BUS_ESDI, 1); next_sector(esdi); esdi->secount = (esdi->secount - 1) & 0xff; if (esdi->secount) @@ -608,7 +609,7 @@ esdi_callback(void *priv) } esdi->status = STAT_READY | STAT_DSC; irq_raise(esdi); - update_status_bar_icon(SB_HDD | HDD_BUS_ESDI, 1); + StatusBarUpdateIcon(SB_HDD | HDD_BUS_ESDI, 1); break; case CMD_DIAGNOSE: @@ -736,7 +737,7 @@ esdi_callback(void *priv) break; } - update_status_bar_icon(SB_HDD | HDD_BUS_ESDI, 0); + StatusBarUpdateIcon(SB_HDD | HDD_BUS_ESDI, 0); } @@ -770,7 +771,7 @@ loadhd(esdi_t *esdi, int hdd_num, int d, const wchar_t *fn) static void * -wd1007vse1_init(void) +wd1007vse1_init(device_t *info) { int i, c = 0; @@ -842,8 +843,10 @@ wd1007vse1_available(void) device_t esdi_at_wd1007vse1_device = { "Western Digital WD1007V-SE1 (ESDI)", DEVICE_AT, + 0, wd1007vse1_init, wd1007vse1_close, + NULL, wd1007vse1_available, NULL, NULL, NULL, NULL }; diff --git a/src/disk/hdc_esdi_mca.c b/src/disk/hdc_esdi_mca.c index 2c2a8e397..6f50a7622 100644 --- a/src/disk/hdc_esdi_mca.c +++ b/src/disk/hdc_esdi_mca.c @@ -52,7 +52,7 @@ * however, are auto-configured by the system software as * shown above. * - * Version: @(#)hdc_esdi_mca.c 1.0.4 2017/09/29 + * Version: @(#)hdc_esdi_mca.c 1.0.5 2017/10/05 * * Authors: Sarah Walker, * Fred N. van Kempen, @@ -73,6 +73,7 @@ #include "../pic.h" #include "../rom.h" #include "../timer.h" +#include "../win/win.h" #include "hdc.h" #include "hdd.h" @@ -325,7 +326,7 @@ esdi_callback(void *priv) if (dev->rba >= drive->sectors) fatal("Read past end of drive\n"); hdd_image_read(drive->hdd_num, dev->rba, 1, (uint8_t *)dev->data); - update_status_bar_icon(SB_HDD | HDD_BUS_ESDI, 1); + StatusBarUpdateIcon(SB_HDD | HDD_BUS_ESDI, 1); } while (dev->data_pos < 256) { @@ -406,11 +407,11 @@ esdi_callback(void *priv) hdd_image_write(drive->hdd_num, dev->rba, 1, (uint8_t *)dev->data); dev->rba++; dev->sector_pos++; - update_status_bar_icon(SB_HDD | HDD_BUS_ESDI, 1); + StatusBarUpdateIcon(SB_HDD | HDD_BUS_ESDI, 1); dev->data_pos = 0; } - update_status_bar_icon(SB_HDD | HDD_BUS_ESDI, 0); + StatusBarUpdateIcon(SB_HDD | HDD_BUS_ESDI, 0); dev->status = STATUS_CMD_IN_PROGRESS; dev->cmd_state = 2; @@ -970,7 +971,7 @@ esdi_mca_write(int port, uint8_t val, void *priv) static void * -esdi_init(void) +esdi_init(device_t *info) { drive_t *drive; esdi_t *dev; @@ -1066,7 +1067,7 @@ esdi_available(void) device_t esdi_ps2_device = { "IBM ESDI Fixed Disk Adapter (MCA)", - DEVICE_MCA, - esdi_init, esdi_close, esdi_available, - NULL, NULL, NULL, NULL + DEVICE_MCA, 0, + esdi_init, esdi_close, NULL, + esdi_available, NULL, NULL, NULL, NULL }; diff --git a/src/disk/hdc_ide.c b/src/disk/hdc_ide.c index 90728036a..da90da64f 100644 --- a/src/disk/hdc_ide.c +++ b/src/disk/hdc_ide.c @@ -9,7 +9,7 @@ * Implementation of the IDE emulation for hard disks and ATAPI * CD-ROM devices. * - * Version: @(#)hdc_ide.c 1.0.9 2017/09/30 + * Version: @(#)hdc_ide.c 1.0.10 2017/10/05 * * Authors: Sarah Walker, * Miran Grca, @@ -30,6 +30,7 @@ #include "../device.h" #include "../cdrom/cdrom.h" #include "../scsi/scsi.h" +#include "../win/win.h" #include "hdc.h" #include "hdc_ide.h" #include "hdd.h" @@ -1296,7 +1297,7 @@ uint32_t ide_read_data(int ide_board, int length) } else { - update_status_bar_icon(SB_HDD | hdd[ide->hdd_num].bus, 0); + StatusBarUpdateIcon(SB_HDD | hdd[ide->hdd_num].bus, 0); } } } @@ -1644,7 +1645,7 @@ void callbackide(int ide_board) ide_irq_raise(ide); - update_status_bar_icon(SB_HDD | hdd[ide->hdd_num].bus, 1); + StatusBarUpdateIcon(SB_HDD | hdd[ide->hdd_num].bus, 1); return; case WIN_READ_DMA: @@ -1691,12 +1692,12 @@ void callbackide(int ide_board) ide_next_sector(ide); ide->atastat = BUSY_STAT; idecallback[ide_board]=6*IDE_TIME; - update_status_bar_icon(SB_HDD | hdd[ide->hdd_num].bus, 1); + StatusBarUpdateIcon(SB_HDD | hdd[ide->hdd_num].bus, 1); } else { ide_irq_raise(ide); - update_status_bar_icon(SB_HDD | hdd[ide->hdd_num].bus, 0); + StatusBarUpdateIcon(SB_HDD | hdd[ide->hdd_num].bus, 0); } } } @@ -1749,7 +1750,7 @@ void callbackide(int ide_board) ide->blockcount = 0; } - update_status_bar_icon(SB_HDD | hdd[ide->hdd_num].bus, 1); + StatusBarUpdateIcon(SB_HDD | hdd[ide->hdd_num].bus, 1); return; case WIN_WRITE: @@ -1770,12 +1771,12 @@ void callbackide(int ide_board) ide->atastat = DRQ_STAT | READY_STAT | DSC_STAT; ide->pos=0; ide_next_sector(ide); - update_status_bar_icon(SB_HDD | hdd[ide->hdd_num].bus, 1); + StatusBarUpdateIcon(SB_HDD | hdd[ide->hdd_num].bus, 1); } else { ide->atastat = READY_STAT | DSC_STAT; - update_status_bar_icon(SB_HDD | hdd[ide->hdd_num].bus, 0); + StatusBarUpdateIcon(SB_HDD | hdd[ide->hdd_num].bus, 0); } return; @@ -1809,12 +1810,12 @@ void callbackide(int ide_board) ide_next_sector(ide); ide->atastat = BUSY_STAT; idecallback[ide_board]=6*IDE_TIME; - update_status_bar_icon(SB_HDD | hdd[ide->hdd_num].bus, 1); + StatusBarUpdateIcon(SB_HDD | hdd[ide->hdd_num].bus, 1); } else { ide_irq_raise(ide); - update_status_bar_icon(SB_HDD | hdd[ide->hdd_num].bus, 0); + StatusBarUpdateIcon(SB_HDD | hdd[ide->hdd_num].bus, 0); } } } @@ -1843,12 +1844,12 @@ void callbackide(int ide_board) ide->atastat = DRQ_STAT | READY_STAT | DSC_STAT; ide->pos=0; ide_next_sector(ide); - update_status_bar_icon(SB_HDD | hdd[ide->hdd_num].bus, 1); + StatusBarUpdateIcon(SB_HDD | hdd[ide->hdd_num].bus, 1); } else { ide->atastat = READY_STAT | DSC_STAT; - update_status_bar_icon(SB_HDD | hdd[ide->hdd_num].bus, 0); + StatusBarUpdateIcon(SB_HDD | hdd[ide->hdd_num].bus, 0); } return; @@ -1865,7 +1866,7 @@ void callbackide(int ide_board) ide->pos=0; ide->atastat = READY_STAT | DSC_STAT; ide_irq_raise(ide); - update_status_bar_icon(SB_HDD | hdd[ide->hdd_num].bus, 1); + StatusBarUpdateIcon(SB_HDD | hdd[ide->hdd_num].bus, 1); return; case WIN_FORMAT: @@ -1882,7 +1883,7 @@ void callbackide(int ide_board) ide->atastat = READY_STAT | DSC_STAT; ide_irq_raise(ide); - /* update_status_bar_icon(SB_HDD | hdd[ide->hdd_num].bus, 1); */ + /* StatusBarUpdateIcon(SB_HDD | hdd[ide->hdd_num].bus, 1); */ return; case WIN_DRIVE_DIAGNOSTICS: diff --git a/src/disk/hdc_mfm_at.c b/src/disk/hdc_mfm_at.c index 80ce711df..21c6081a2 100644 --- a/src/disk/hdc_mfm_at.c +++ b/src/disk/hdc_mfm_at.c @@ -12,7 +12,7 @@ * based design. Most cards were WD1003-WA2 or -WAH, where the * -WA2 cards had a floppy controller as well (to save space.) * - * Version: @(#)hdd_mfm_at.c 1.0.4 2017/09/29 + * Version: @(#)hdd_mfm_at.c 1.0.5 2017/10/05 * * Authors: Sarah Walker, * Fred N. van Kempen, @@ -29,6 +29,7 @@ #include "../io.h" #include "../pic.h" #include "../timer.h" +#include "../win/win.h" #include "hdc.h" #include "hdd.h" @@ -461,7 +462,7 @@ mfm_readw(uint16_t port, void *priv) mfm->callback = 6*MFM_TIME; timer_update_outstanding(); } else { - update_status_bar_icon(SB_HDD|HDD_BUS_MFM, 0); + StatusBarUpdateIcon(SB_HDD|HDD_BUS_MFM, 0); } } } @@ -561,7 +562,7 @@ do_callback(void *priv) mfm->reset = 0; - update_status_bar_icon(SB_HDD|HDD_BUS_MFM, 0); + StatusBarUpdateIcon(SB_HDD|HDD_BUS_MFM, 0); return; } @@ -595,7 +596,7 @@ do_callback(void *priv) mfm->pos = 0; mfm->status = STAT_DRQ|STAT_READY|STAT_DSC; irq_raise(mfm); - update_status_bar_icon(SB_HDD|HDD_BUS_MFM, 1); + StatusBarUpdateIcon(SB_HDD|HDD_BUS_MFM, 1); break; case CMD_WRITE: @@ -620,9 +621,9 @@ do_callback(void *priv) mfm->status |= STAT_DRQ; mfm->pos = 0; next_sector(mfm); - update_status_bar_icon(SB_HDD|HDD_BUS_MFM, 1); + StatusBarUpdateIcon(SB_HDD|HDD_BUS_MFM, 1); } else { - update_status_bar_icon(SB_HDD|HDD_BUS_MFM, 0); + StatusBarUpdateIcon(SB_HDD|HDD_BUS_MFM, 0); } irq_raise(mfm); break; @@ -636,7 +637,7 @@ do_callback(void *priv) mfm->pos = 0; mfm->status = STAT_READY|STAT_DSC; irq_raise(mfm); - update_status_bar_icon(SB_HDD|HDD_BUS_MFM, 1); + StatusBarUpdateIcon(SB_HDD|HDD_BUS_MFM, 1); break; case CMD_FORMAT: @@ -656,7 +657,7 @@ do_callback(void *priv) mfm->status = STAT_READY|STAT_DSC; irq_raise(mfm); - update_status_bar_icon(SB_HDD|HDD_BUS_MFM, 1); + StatusBarUpdateIcon(SB_HDD|HDD_BUS_MFM, 1); break; case CMD_DIAGNOSE: @@ -700,7 +701,7 @@ loadhd(mfm_t *mfm, int c, int d, const wchar_t *fn) static void * -mfm_init(void) +mfm_init(device_t *info) { mfm_t *mfm; int c, d; @@ -733,7 +734,7 @@ mfm_init(void) timer_add(do_callback, &mfm->callback, &mfm->callback, mfm); - update_status_bar_icon(SB_HDD|HDD_BUS_MFM, 0); + StatusBarUpdateIcon(SB_HDD|HDD_BUS_MFM, 0); return(mfm); } @@ -753,13 +754,13 @@ mfm_close(void *priv) free(mfm); - update_status_bar_icon(SB_HDD|HDD_BUS_MFM, 0); + StatusBarUpdateIcon(SB_HDD|HDD_BUS_MFM, 0); } device_t mfm_at_wd1003_device = { "WD1003 AT MFM/RLL Controller", - DEVICE_AT, + DEVICE_AT, 0, mfm_init, mfm_close, NULL, - NULL, NULL, NULL, NULL + NULL, NULL, NULL, NULL, NULL }; diff --git a/src/disk/hdc_mfm_xt.c b/src/disk/hdc_mfm_xt.c index 56063d20f..569b6afba 100644 --- a/src/disk/hdc_mfm_xt.c +++ b/src/disk/hdc_mfm_xt.c @@ -41,7 +41,7 @@ * Since all controllers (including the ones made by DTC) use * (mostly) the same API, we keep them all in this module. * - * Version: @(#)hdd_mfm_xt.c 1.0.6 2017/09/30 + * Version: @(#)hdd_mfm_xt.c 1.0.7 2017/10/05 * * Authors: Sarah Walker, * Fred N. van Kempen, @@ -61,6 +61,7 @@ #include "../pic.h" #include "../rom.h" #include "../timer.h" +#include "../win/win.h" #include "hdc.h" #include "hdd.h" @@ -402,7 +403,7 @@ mfm_callback(void *priv) mfm_complete(mfm); - update_status_bar_icon(SB_HDD | HDD_BUS_MFM, 1); + StatusBarUpdateIcon(SB_HDD | HDD_BUS_MFM, 1); break; default: @@ -447,7 +448,7 @@ mfm_callback(void *priv) hdd_image_read(drive->hdd_num, addr, 1, (uint8_t *) mfm->sector_buf); - update_status_bar_icon(SB_HDD|HDD_BUS_MFM, 1); + StatusBarUpdateIcon(SB_HDD|HDD_BUS_MFM, 1); if (mfm->irq_dma_mask & DMA_ENA) mfm->callback = MFM_TIME; @@ -492,7 +493,7 @@ mfm_callback(void *priv) hdd_image_read(drive->hdd_num, addr, 1, (uint8_t *) mfm->sector_buf); - update_status_bar_icon(SB_HDD|HDD_BUS_MFM, 1); + StatusBarUpdateIcon(SB_HDD|HDD_BUS_MFM, 1); mfm->state = STATE_SEND_DATA; @@ -504,7 +505,7 @@ mfm_callback(void *priv) } } else { mfm_complete(mfm); - update_status_bar_icon(SB_HDD | HDD_BUS_MFM, 0); + StatusBarUpdateIcon(SB_HDD | HDD_BUS_MFM, 0); } break; @@ -565,7 +566,7 @@ mfm_callback(void *priv) hdd_image_write(drive->hdd_num, addr, 1, (uint8_t *) mfm->sector_buf); - update_status_bar_icon(SB_HDD|HDD_BUS_MFM, 1); + StatusBarUpdateIcon(SB_HDD|HDD_BUS_MFM, 1); next_sector(mfm); mfm->data_pos = 0; @@ -802,7 +803,7 @@ mfm_set_switches(mfm_t *mfm) static void * -xebec_init(void) +xebec_init(device_t *info) { int i, c = 0; @@ -856,14 +857,15 @@ xebec_available(void) device_t mfm_xt_xebec_device = { "IBM PC Fixed Disk Adapter", - 0, - xebec_init, mfm_close, xebec_available, - NULL, NULL, NULL, NULL + 0, 0, + xebec_init, mfm_close, NULL, + xebec_available, NULL, NULL, NULL, + NULL }; static void * -dtc5150x_init(void) +dtc5150x_init(device_t *info) { int i, c = 0; @@ -906,7 +908,8 @@ dtc5150x_available(void) device_t mfm_xt_dtc5150x_device = { "DTC 5150X", - 0, - dtc5150x_init, mfm_close, dtc5150x_available, - NULL, NULL, NULL, NULL + 0, 0, + dtc5150x_init, mfm_close, NULL, + dtc5150x_available, NULL, NULL, NULL, + NULL }; diff --git a/src/disk/hdc_xtide.c b/src/disk/hdc_xtide.c index a97ac2a59..51b412de7 100644 --- a/src/disk/hdc_xtide.c +++ b/src/disk/hdc_xtide.c @@ -21,7 +21,7 @@ * already on their way out, the newer IDE standard based on the * PC/AT controller and 16b design became the IDE we now know. * - * Version: @(#)xtide.c 1.0.6 2017/10/10 + * Version: @(#)hdc_xtide.c 1.0.7 2017/10/04 * * Authors: Sarah Walker, * Miran Grca, @@ -126,7 +126,7 @@ xtide_read(uint16_t port, void *priv) static void * -xtide_init(void) +xtide_init(device_t *info) { xtide_t *xtide = malloc(sizeof(xtide_t)); @@ -153,7 +153,7 @@ xtide_available(void) static void * -xtide_at_init(void) +xtide_at_init(device_t *info) { xtide_t *xtide = malloc(sizeof(xtide_t)); @@ -176,7 +176,7 @@ xtide_at_available(void) static void * -xtide_ps2_init(void) +xtide_ps2_init(device_t *info) { xtide_t *xtide = malloc(sizeof(xtide_t)); @@ -203,7 +203,7 @@ xtide_ps2_available(void) static void * -xtide_at_ps2_init(void) +xtide_at_ps2_init(device_t *info) { xtide_t *xtide = malloc(sizeof(xtide_t)); @@ -237,27 +237,35 @@ xtide_close(void *priv) device_t xtide_device = { "XTIDE", 0, - xtide_init, xtide_close, xtide_available, - NULL, NULL, NULL, NULL + 0, + xtide_init, xtide_close, NULL, + xtide_available, NULL, NULL, NULL, + NULL }; device_t xtide_at_device = { "XTIDE (AT)", DEVICE_AT, - xtide_at_init, xtide_close, xtide_at_available, - NULL, NULL, NULL, NULL + 0, + xtide_at_init, xtide_close, NULL, + xtide_at_available, NULL, NULL, NULL, + NULL }; device_t xtide_ps2_device = { "XTIDE (Acculogic)", 0, - xtide_ps2_init, xtide_close, xtide_ps2_available, - NULL, NULL, NULL, NULL + 0, + xtide_ps2_init, xtide_close, NULL, + xtide_ps2_available, NULL, NULL, NULL, + NULL }; device_t xtide_at_ps2_device = { "XTIDE (AT) (1.1.5)", DEVICE_PS2, - xtide_at_ps2_init, xtide_close, xtide_at_ps2_available, - NULL, NULL, NULL, NULL + 0, + xtide_at_ps2_init, xtide_close, NULL, + xtide_at_ps2_available, NULL, NULL, NULL, + NULL }; diff --git a/src/disk/hdd.c b/src/disk/hdd.c index 1041f66fd..00ab1dcab 100644 --- a/src/disk/hdd.c +++ b/src/disk/hdd.c @@ -8,7 +8,7 @@ * * Common code to handle all sorts of hard disk images. * - * Version: @(#)hdd.c 1.0.2 2017/09/30 + * Version: @(#)hdd.c 1.0.3 2017/10/05 * * Authors: Miran Grca, * Fred N. van Kempen, @@ -23,6 +23,8 @@ #include "../cpu/cpu.h" #include "../device.h" #include "../machine/machine.h" +#include "../win/win.h" +#include "../win/win_language.h" #include "hdd.h" @@ -37,3 +39,138 @@ hdd_init(void) return(0); } + + +int +hdd_string_to_bus(char *str, int cdrom) +{ + if (! strcmp(str, "none")) + return(HDD_BUS_DISABLED); + + if (! strcmp(str, "mfm")) { + if (cdrom) { +no_cdrom: + msgbox_error(hwndMain, IDS_4114); + return(0); + } + + return(HDD_BUS_MFM); + } + + /* FIXME: delete 'rll' in a year or so.. --FvK */ + if (!strcmp(str, "esdi") || !strcmp(str, "rll")) { + if (cdrom) goto no_cdrom; + + return(HDD_BUS_ESDI); + } + + if (! strcmp(str, "ide_pio_only")) + return(HDD_BUS_IDE_PIO_ONLY); + + if (! strcmp(str, "ide")) + return(HDD_BUS_IDE_PIO_ONLY); + + if (! strcmp(str, "atapi_pio_only")) + return(HDD_BUS_IDE_PIO_ONLY); + + if (! strcmp(str, "atapi")) + return(HDD_BUS_IDE_PIO_ONLY); + + if (! strcmp(str, "eide")) + return(HDD_BUS_IDE_PIO_ONLY); + + if (! strcmp(str, "xtide")) + return(HDD_BUS_XTIDE); + + if (! strcmp(str, "atide")) + return(HDD_BUS_IDE_PIO_ONLY); + + if (! strcmp(str, "ide_pio_and_dma")) + return(HDD_BUS_IDE_PIO_AND_DMA); + + if (! strcmp(str, "atapi_pio_and_dma")) + return(HDD_BUS_IDE_PIO_AND_DMA); + + if (! strcmp(str, "scsi")) + return(HDD_BUS_SCSI); + + if (! strcmp(str, "removable")) { + if (cdrom) goto no_cdrom; + + return(HDD_BUS_SCSI_REMOVABLE); + } + + if (! strcmp(str, "scsi_removable")) { + if (cdrom) goto no_cdrom; + + return(HDD_BUS_SCSI_REMOVABLE); + } + + if (! strcmp(str, "removable_scsi")) { + if (cdrom) goto no_cdrom; + + return(HDD_BUS_SCSI_REMOVABLE); + } + + if (! strcmp(str, "usb")) + msgbox_error(hwndMain, IDS_4110); + + return(0); +} + + +char * +hdd_bus_to_string(int bus, int cdrom) +{ + char *s = "none"; + + switch (bus) { + case HDD_BUS_DISABLED: + default: + break; + + case HDD_BUS_MFM: + s = "mfm"; + break; + + case HDD_BUS_XTIDE: + s = "xtide"; + break; + + case HDD_BUS_ESDI: + s = "esdi"; + break; + + case HDD_BUS_IDE_PIO_ONLY: + s = cdrom ? "atapi_pio_only" : "ide_pio_only"; + break; + + case HDD_BUS_IDE_PIO_AND_DMA: + s = cdrom ? "atapi_pio_and_dma" : "ide_pio_and_dma"; + break; + + case HDD_BUS_SCSI: + s = "scsi"; + break; + + case HDD_BUS_SCSI_REMOVABLE: + s = "scsi_removable"; + break; + } + + return(s); +} + + +int +hdd_is_valid(int c) +{ + if (hdd[c].bus == HDD_BUS_DISABLED) return(0); + + if ((wcslen(hdd[c].fn) == 0) && + (hdd[c].bus != HDD_BUS_SCSI_REMOVABLE)) return(0); + + if ((hdd[c].tracks==0) || (hdd[c].hpc==0) || (hdd[c].spt==0)) return(0); + + return(1); +} diff --git a/src/disk/hdd.h b/src/disk/hdd.h index c60d4d0d1..dbb951bac 100644 --- a/src/disk/hdd.h +++ b/src/disk/hdd.h @@ -8,7 +8,7 @@ * * Definitions for the hard disk image handler. * - * Version: @(#)hdd.h 1.0.2 2017/09/30 + * Version: @(#)hdd.h 1.0.3 2017/10/05 * * Authors: Miran Grca, * Fred N. van Kempen, @@ -71,6 +71,9 @@ extern uint64_t hdd_table[128][3]; extern int hdd_init(void); +extern int hdd_string_to_bus(char *str, int cdrom); +extern char *hdd_bus_to_string(int bus, int cdrom); +extern int hdd_is_valid(int c); extern int hdd_image_load(int id); extern void hdd_image_seek(uint8_t id, uint32_t sector); diff --git a/src/floppy/fdc.c b/src/floppy/fdc.c index 565ba2283..1a3b7d8da 100644 --- a/src/floppy/fdc.c +++ b/src/floppy/fdc.c @@ -9,7 +9,7 @@ * Implementation of the NEC uPD-765 and compatible floppy disk * controller. * - * Version: @(#)fdc.c 1.0.3 2017/09/24 + * Version: @(#)fdc.c 1.0.4 2017/10/05 * * Authors: Sarah Walker, * Miran Grca, @@ -28,6 +28,7 @@ #include "../dma.h" #include "../pic.h" #include "../timer.h" +#include "../win/win.h" #include "floppy.h" #include "fdc.h" #include "fdd.h" @@ -677,7 +678,7 @@ void fdc_write(uint16_t addr, uint8_t val, void *priv) floppytime = 128 * (1 << TIMER_SHIFT); timer_update_outstanding(); floppyint=-1; - update_status_bar_icon(SB_FLOPPY | 0, 0); + StatusBarUpdateIcon(SB_FLOPPY | 0, 0); fdc_reset(); } if (!fdd_get_flags(0)) @@ -714,7 +715,7 @@ void fdc_write(uint16_t addr, uint8_t val, void *priv) for (i = 0; i < FDD_NUM; i++) { - update_status_bar_icon(SB_FLOPPY | i, 0); + StatusBarUpdateIcon(SB_FLOPPY | i, 0); } fdc_reset(); @@ -987,7 +988,7 @@ bad_command: fdc.stat = 0x50; } floppytime = 0; - update_status_bar_icon(SB_FLOPPY | fdc.drive, 1); + StatusBarUpdateIcon(SB_FLOPPY | fdc.drive, 1); fdc.inread = 1; break; @@ -1032,7 +1033,7 @@ bad_command: floppy_writesector(fdc.drive, fdc.sector, fdc.params[1], fdc.head, fdc.rate, fdc.params[4]); floppytime = 0; fdc.written = 0; - update_status_bar_icon(SB_FLOPPY | fdc.drive, 1); + StatusBarUpdateIcon(SB_FLOPPY | fdc.drive, 1); fdc.pos = 0; if (fdc.pcjr) fdc.stat = 0xb0; @@ -1065,7 +1066,7 @@ bad_command: floppy_comparesector(fdc.drive, fdc.sector, fdc.params[1], fdc.head, fdc.rate, fdc.params[4]); floppytime = 0; fdc.written = 0; - update_status_bar_icon(SB_FLOPPY | fdc.drive, 1); + StatusBarUpdateIcon(SB_FLOPPY | fdc.drive, 1); fdc.pos = 0; if (fdc.pcjr || !fdc.dma) { @@ -1109,7 +1110,7 @@ bad_command: fdc.stat = 0x50; } floppytime = 0; - update_status_bar_icon(SB_FLOPPY | fdc.drive, 1); + StatusBarUpdateIcon(SB_FLOPPY | fdc.drive, 1); fdc.inread = 1; break; @@ -1466,7 +1467,7 @@ void fdc_poll_common_finish(int compare, int st5) fdc.res[9]=fdc.sector; fdc.res[10]=fdc.params[4]; fdc_log("Read/write finish (%02X %02X %02X %02X %02X %02X %02X)\n" , fdc.res[4], fdc.res[5], fdc.res[6], fdc.res[7], fdc.res[8], fdc.res[9], fdc.res[10]); - update_status_bar_icon(SB_FLOPPY | fdc.drive, 0); + StatusBarUpdateIcon(SB_FLOPPY | fdc.drive, 0); paramstogo=7; } @@ -1512,7 +1513,7 @@ void fdc_callback(void *priv) return; case 2: /*Read track*/ - update_status_bar_icon(SB_FLOPPY | fdc.drive, 1); + StatusBarUpdateIcon(SB_FLOPPY | fdc.drive, 1); fdc.eot[fdc.drive]--; fdc.read_track_sector.id.r++; if (!fdc.eot[fdc.drive] || fdc.tc) @@ -1672,7 +1673,7 @@ void fdc_callback(void *priv) { fdc.sector++; } - update_status_bar_icon(SB_FLOPPY | fdc.drive, 1); + StatusBarUpdateIcon(SB_FLOPPY | fdc.drive, 1); switch (floppyint) { case 5: @@ -1911,7 +1912,7 @@ void fdc_error(int st5, int st6) fdc.res[10]=0; break; } - update_status_bar_icon(SB_FLOPPY | fdc.drive, 0); + StatusBarUpdateIcon(SB_FLOPPY | fdc.drive, 0); paramstogo=7; } @@ -2142,7 +2143,7 @@ void fdc_sectorid(uint8_t track, uint8_t side, uint8_t sector, uint8_t size, uin fdc.res[8]=side; fdc.res[9]=sector; fdc.res[10]=size; - update_status_bar_icon(SB_FLOPPY | fdc.drive, 0); + StatusBarUpdateIcon(SB_FLOPPY | fdc.drive, 0); paramstogo=7; } @@ -2198,7 +2199,7 @@ void fdc_hard_reset() for (i = 0; i < FDD_NUM; i++) { - update_status_bar_icon(SB_FLOPPY | i, 0); + StatusBarUpdateIcon(SB_FLOPPY | i, 0); } } diff --git a/src/floppy/floppy.c b/src/floppy/floppy.c index 89c4e6268..5b1dabdc3 100644 --- a/src/floppy/floppy.c +++ b/src/floppy/floppy.c @@ -9,7 +9,7 @@ * Generic floppy disk interface that communicates with the * other handlers. * - * Version: @(#)floppy.c 1.0.5 2017/10/02 + * Version: @(#)floppy.c 1.0.5 2017/10/05 * * Authors: Sarah Walker, * Miran Grca, @@ -25,6 +25,7 @@ #include "../rom.h" #include "../config.h" #include "../timer.h" +#include "../win/win.h" #include "floppy.h" #include "floppy_86f.h" #include "floppy_fdi.h" @@ -157,7 +158,7 @@ void floppy_load(int drive, wchar_t *fn) drive_empty[drive] = 1; fdd_set_head(real_drive(drive), 0); memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); - update_status_bar_icon_state(drive, 1); + StatusBarUpdateIconState(drive, 1); } void floppy_close(int drive) @@ -176,7 +177,7 @@ void floppy_close(int drive) drives[drive].format = NULL; drives[drive].byteperiod = NULL; drives[drive].stop = NULL; - update_status_bar_icon_state(drive, 1); + StatusBarUpdateIconState(drive, 1); } int floppy_notfound=0; diff --git a/src/floppy/floppy_86f.c b/src/floppy/floppy_86f.c index e97aed779..af3e7657e 100644 --- a/src/floppy/floppy_86f.c +++ b/src/floppy/floppy_86f.c @@ -10,7 +10,7 @@ * data in the form of FM/MFM-encoded transitions) which also * forms the core of the emulator's floppy disk emulation. * - * Version: @(#)floppy_86f.c 1.0.5 2017/10/02 + * Version: @(#)floppy_86f.c 1.0.5 2017/10/05 * * Author: Miran Grca, * Copyright 2016,2017 Miran Grca. @@ -28,6 +28,7 @@ #include "../dma.h" #include "../nvr.h" #include "../random.h" +#include "../win/win.h" #include "floppy.h" #include "fdc.h" #include "fdd.h" @@ -3424,7 +3425,7 @@ void d86f_load(int drive, wchar_t *fn) } fclose(d86f[drive].f); d86f[drive].f = NULL; - update_status_bar_icon_state(drive, 1); + StatusBarUpdateIconState(drive, 1); return; } else diff --git a/src/game/gameport.c b/src/game/gameport.c index c36aea716..756887599 100644 --- a/src/game/gameport.c +++ b/src/game/gameport.c @@ -164,7 +164,7 @@ void gameport_timer_over(void *p) gameport->joystick->a0_over(gameport->joystick_dat); } -void *gameport_init_common() +void *gameport_init_common(void) { gameport_t *gameport = malloc(sizeof(gameport_t)); @@ -193,7 +193,7 @@ void *gameport_init_common() return gameport; } -void gameport_update_joystick_type() +void gameport_update_joystick_type(void) { gameport_t *gameport = gameport_global; @@ -205,7 +205,7 @@ void gameport_update_joystick_type() } } -void *gameport_init() +void *gameport_init(device_t *info) { gameport_t *gameport = NULL; @@ -222,7 +222,7 @@ void *gameport_init() return gameport; } -void *gameport_201_init() +void *gameport_201_init(device_t *info) { gameport_t *gameport; @@ -258,23 +258,19 @@ void gameport_close(void *p) device_t gameport_device = { "Game port", - 0, + 0, 0, gameport_init, gameport_close, - NULL, - NULL, - NULL, + NULL, NULL, NULL, NULL, NULL }; device_t gameport_201_device = { "Game port (port 201h only)", - 0, + 0, 0, gameport_201_init, gameport_close, - NULL, - NULL, - NULL, + NULL, NULL, NULL, NULL, NULL }; diff --git a/src/ibm.h b/src/ibm.h index d1c7f53ad..26cde0dff 100644 --- a/src/ibm.h +++ b/src/ibm.h @@ -10,7 +10,7 @@ * * !!!NOTE!!! The goal is to GET RID of this file. Do NOT add stuff !! * - * Version: @(#)ibm.h 1.0.7 2017/10/02 + * Version: @(#)ibm.h 1.0.8 2017/10/04 * * Authors: Sarah Walker, * Miran Grca, @@ -587,11 +587,11 @@ extern int scale; extern void pclog(const char *format, ...); extern void fatal(const char *format, ...); extern wchar_t *pc_concat(wchar_t *str); -extern void pc_init_modules(void); -extern void pc_init(int argc, wchar_t *argv[]); +extern int pc_init_modules(void); +extern int pc_init(int argc, wchar_t *argv[]); extern void pc_close(void); -extern void resetpchard_close(void); -extern void resetpchard_init(void); +extern void pc_reset_hard_close(void); +extern void pc_reset_hard_init(void); extern void pc_reset_hard(void); extern void pc_full_speed(void); extern void pc_speed_changed(void); @@ -635,20 +635,6 @@ extern void x86ts(char *s, uint16_t error); extern void x87_dumpregs(void); extern void x87_reset(void); -/* Platform functions. */ -extern void update_status_bar_icon(int tag, int active); -extern void update_status_bar_icon_state(int tag, int state); -extern void status_settextw(wchar_t *wstr); -extern void status_settext(char *str); - -#define SB_FLOPPY 0x00 -#define SB_CDROM 0x10 -#define SB_RDISK 0x20 -#define SB_HDD 0x40 -#define SB_NETWORK 0x50 -#define SB_TEXT 0x60 - -#define UNUSED(x) (void)x /* Configuration values. */ #define SERIAL_MAX 2 diff --git a/src/intel_flash.c b/src/intel_flash.c index eadaf4047..e112e10bf 100644 --- a/src/intel_flash.c +++ b/src/intel_flash.c @@ -8,7 +8,7 @@ * * Implementation of the Intel 2 Mbit 8-bit flash devices. * - * Version: @(#)intel_flash.c 1.0.4 2017/10/02 + * Version: @(#)intel_flash.c 1.0.5 2017/10/04 * * Authors: Sarah Walker, * Miran Grca, @@ -307,54 +307,43 @@ void intel_flash_close(void *p) free(flash); } + device_t intel_flash_bxt_ami_device = { "Intel 28F001BXT Flash BIOS", - 0, + 0, 0, intel_flash_bxt_ami_init, intel_flash_close, - NULL, - NULL, - NULL, - NULL, - NULL + NULL, + NULL, NULL, NULL, NULL, NULL }; device_t intel_flash_bxb_ami_device = { "Intel 28F001BXB Flash BIOS", - 0, + 0, 0, intel_flash_bxb_ami_init, intel_flash_close, - NULL, - NULL, - NULL, - NULL, - NULL + NULL, + NULL, NULL, NULL, NULL, NULL }; device_t intel_flash_bxt_device = { "Intel 28F001BXT Flash BIOS", - 0, + 0, 0, intel_flash_bxt_init, intel_flash_close, - NULL, - NULL, - NULL, - NULL, - NULL + NULL, + NULL, NULL, NULL, NULL, NULL }; device_t intel_flash_bxb_device = { "Intel 28F001BXB Flash BIOS", - 0, + 0, 0, intel_flash_bxb_init, intel_flash_close, - NULL, - NULL, - NULL, - NULL, - NULL + NULL, + NULL, NULL, NULL, NULL, NULL }; diff --git a/src/machine/machine.c b/src/machine/machine.c index 8373742aa..56a1200c6 100644 --- a/src/machine/machine.c +++ b/src/machine/machine.c @@ -8,7 +8,7 @@ * * Handling of the emulated machines. * - * Version: @(#)machine.c 1.0.16 2017/09/30 + * Version: @(#)machine.c 1.0.17 2017/10/04 * * Authors: Sarah Walker, * Miran Grca, @@ -172,14 +172,14 @@ machine_init(void) AMSTRAD = AT = PCI = TANDY = 0; - io_init(); - - fdc_update_is_nsc(0); - - machines[machine].init(); + /* Load the machine's ROM BIOS. */ + rom_load_bios(romset); + mem_add_bios(); if (machines[machine].get_device) device_add(machines[machine].get_device()); + + machines[machine].init(); } diff --git a/src/machine/machine_at.c b/src/machine/machine_at.c index 488b76762..98fe216d3 100644 --- a/src/machine/machine_at.c +++ b/src/machine/machine_at.c @@ -24,16 +24,20 @@ void machine_at_init(void) AT = 1; machine_common_init(); + pit_set_out_func(&pit, 1, pit_refresh_timer_at); + pic2_init(); + dma16_init(); + if (lpt_enabled) lpt2_remove(); - mem_add_bios(); - pit_set_out_func(&pit, 1, pit_refresh_timer_at); - dma16_init(); - keyboard_at_init(); + nvr_at_init(8); - pic2_init(); + + keyboard_at_init(); + if (joystick_type != 7) device_add(&gameport_device); + if (bugger_enabled) bugger_init(); } @@ -41,17 +45,20 @@ void machine_at_init(void) void machine_at_ide_init(void) { machine_at_init(); + ide_init(); } void machine_at_top_remap_init(void) { machine_at_init(); + mem_remap_top_384k(); } void machine_at_ide_top_remap_init(void) { machine_at_ide_init(); + mem_remap_top_384k(); } diff --git a/src/machine/machine_common.c b/src/machine/machine_common.c index 480e669d3..bab15b806 100644 --- a/src/machine/machine_common.c +++ b/src/machine/machine_common.c @@ -21,8 +21,6 @@ void machine_common_init(void) pic_init(); pit_init(); - fdc_add(); - if (lpt_enabled) { lpt_init(); @@ -37,4 +35,6 @@ void machine_common_init(void) { serial_setup(2, SERIAL2_ADDR, SERIAL2_IRQ); } + + fdc_add(); } diff --git a/src/network/net_ne2000.c b/src/network/net_ne2000.c index 0b0bfe30d..57420cd5e 100644 --- a/src/network/net_ne2000.c +++ b/src/network/net_ne2000.c @@ -10,7 +10,7 @@ * * NOTE: The file will also implement an NE1000 for 8-bit ISA systems. * - * Version: @(#)net_ne2000.c 1.0.15 2017/09/24 + * Version: @(#)net_ne2000.c 1.0.16 2017/10/05 * * Authors: Fred N. van Kempen, * Peter Grehan, grehan@iprg.nokia.com> @@ -35,6 +35,7 @@ #include "../pic.h" #include "../random.h" #include "../device.h" +#include "../win/win.h" #include "network.h" #include "net_ne2000.h" #include "bswap.h" @@ -497,6 +498,7 @@ asic_write(nic_t *dev, uint32_t off, uint32_t val, unsigned len) { nelog(3, "%s: ASIC write addr=0x%02x, value=0x%04x\n", dev->name, (unsigned)off, (unsigned) val); + switch(off) { case 0x00: /* Data register - see asic_read for a description */ if ((len > 1) && (dev->DCR.wdsize == 0)) { @@ -504,30 +506,25 @@ asic_write(nic_t *dev, uint32_t off, uint32_t val, unsigned len) dev->name, len); break; } - if (dev->remote_bytes == 0) { + if (dev->remote_bytes == 0) nelog(3, "%s: DMA write, byte count 0\n", dev->name); - } chipmem_write(dev, dev->remote_dma, val, len); - if (len == 4) { + if (len == 4) dev->remote_dma += len; - } else { + else dev->remote_dma += (dev->DCR.wdsize + 1); - } - if (dev->remote_dma == dev->page_stop << 8) { + if (dev->remote_dma == dev->page_stop << 8) dev->remote_dma = dev->page_start << 8; - } - if (len == 4) { + if (len == 4) dev->remote_bytes -= len; - } else { + else dev->remote_bytes -= (dev->DCR.wdsize + 1); - } - if (dev->remote_bytes > NE2K_MEMSIZ) { + if (dev->remote_bytes > NE2K_MEMSIZ) dev->remote_bytes = 0; - } /* If all bytes have been written, signal remote-DMA complete */ if (dev->remote_bytes == 0) { @@ -1423,13 +1420,10 @@ nic_update_bios(nic_t *dev) reg_bios_enable = 1; - if (!dev->has_bios) { - return; - } + if (! dev->has_bios) return; - if (PCI && dev->is_pci) { + if (PCI && dev->is_pci) reg_bios_enable = dev->pci_bar[1].addr_regs[0] & 0x01; - } /* PCI BIOS stuff, just enable_disable. */ if (reg_bios_enable) { @@ -1654,26 +1648,22 @@ static int mcast_index(const void *dst) { #define POLYNOMIAL 0x04c11db6 - unsigned long crc = 0xffffffffL; - int carry, i, j; - unsigned char b; - unsigned char *ep = (unsigned char *) dst; + uint32_t crc = 0xffffffffL; + int carry, i, j; + uint8_t b; + uint8_t *ep = (uint8_t *)dst; - for (i = 6; --i >= 0;) - { - b = *ep++; - for (j = 8; --j >= 0;) - { - carry = ((crc & 0x80000000L) ? 1 : 0) ^ (b & 0x01); - crc <<= 1; - b >>= 1; - if (carry) - { - crc = ((crc ^ POLYNOMIAL) | carry); - } - } + for (i=6; --i>=0;) { + b = *ep++; + for (j = 8; --j >= 0;) { + carry = ((crc & 0x80000000L) ? 1 : 0) ^ (b & 0x01); + crc <<= 1; + b >>= 1; + if (carry) + crc = ((crc ^ POLYNOMIAL) | carry); } - return (crc >> 26); + } + return(crc >> 26); #undef POLYNOMIAL } @@ -1681,7 +1671,7 @@ mcast_index(const void *dst) static void nic_tx(nic_t *dev, uint32_t val) { - update_status_bar_icon(SB_NETWORK, 1); + StatusBarUpdateIcon(SB_NETWORK, 1); dev->CR.tx_packet = 0; dev->TSR.tx_ok = 1; @@ -1692,7 +1682,7 @@ nic_tx(nic_t *dev, uint32_t val) nic_interrupt(dev, 1); dev->tx_timer_active = 0; - update_status_bar_icon(SB_NETWORK, 0); + StatusBarUpdateIcon(SB_NETWORK, 0); } @@ -1713,7 +1703,7 @@ nic_rx(void *priv, uint8_t *buf, int io_len) int idx, nextpage; int endbytes; - update_status_bar_icon(SB_NETWORK, 1); + StatusBarUpdateIcon(SB_NETWORK, 1); if (io_len != 60) nelog(2, "%s: rx_frame with length %d\n", dev->name, io_len); @@ -1744,14 +1734,14 @@ nic_rx(void *priv, uint8_t *buf, int io_len) ) { nelog(1, "%s: no space\n", dev->name); - update_status_bar_icon(SB_NETWORK, 0); + StatusBarUpdateIcon(SB_NETWORK, 0); return; } if ((io_len < 40/*60*/) && !dev->RCR.runts_ok) { nelog(1, "%s: rejected small packet, length %d\n", dev->name, io_len); - update_status_bar_icon(SB_NETWORK, 0); + StatusBarUpdateIcon(SB_NETWORK, 0); return; } @@ -1773,7 +1763,7 @@ nic_rx(void *priv, uint8_t *buf, int io_len) if (! dev->RCR.broadcast) { nelog(2, "%s: RX BC disabled\n", dev->name); - update_status_bar_icon(SB_NETWORK, 0); + StatusBarUpdateIcon(SB_NETWORK, 0); return; } } @@ -1786,7 +1776,7 @@ nic_rx(void *priv, uint8_t *buf, int io_len) nelog(2, "%s: RX MC disabled\n", dev->name); #endif - update_status_bar_icon(SB_NETWORK, 0); + StatusBarUpdateIcon(SB_NETWORK, 0); return; } @@ -1795,7 +1785,7 @@ nic_rx(void *priv, uint8_t *buf, int io_len) if (! (dev->mchash[idx>>3] & (1<<(idx&0x7)))) { nelog(2, "%s: RX MC not listed\n", dev->name); - update_status_bar_icon(SB_NETWORK, 0); + StatusBarUpdateIcon(SB_NETWORK, 0); return; } } @@ -1841,7 +1831,7 @@ nic_rx(void *priv, uint8_t *buf, int io_len) if (dev->IMR.rx_inte) nic_interrupt(dev, 1); - update_status_bar_icon(SB_NETWORK, 0); + StatusBarUpdateIcon(SB_NETWORK, 0); } @@ -1851,35 +1841,32 @@ nic_rom_init(nic_t *dev, wchar_t *s) uint32_t temp; FILE *f; - if (s == NULL) - { + if (s == NULL) return; + + if (dev->bios_addr == 0) return; + + if ((f = rom_fopen(s, L"rb")) != NULL) { + fseek(f, 0L, SEEK_END); + temp = ftell(f); + fclose(f); + dev->bios_size = 0x10000; + if (temp <= 0x8000) + dev->bios_size = 0x8000; + if (temp <= 0x4000) + dev->bios_size = 0x4000; + if (temp <= 0x2000) + dev->bios_size = 0x2000; + dev->bios_mask = (dev->bios_size >> 8) & 0xff; + dev->bios_mask = (0x100 - dev->bios_mask) & 0xff; + } else { + dev->bios_addr = 0x00000; + dev->bios_size = 0; return; } - if (dev->bios_addr > 0) { - if ((f = rom_fopen(s, L"rb")) != NULL) { - fseek(f, 0L, SEEK_END); - temp = ftell(f); - fclose(f); - dev->bios_size = 0x10000; - if (temp <= 0x8000) - dev->bios_size = 0x8000; - if (temp <= 0x4000) - dev->bios_size = 0x4000; - if (temp <= 0x2000) - dev->bios_size = 0x2000; - dev->bios_mask = (dev->bios_size >> 8) & 0xff; - dev->bios_mask = (0x100 - dev->bios_mask) & 0xff; - } else { - dev->bios_addr = 0x00000; - dev->bios_size = 0; - return; - } - - /* Create a memory mapping for the space. */ - rom_init(&dev->bios_rom, s, dev->bios_addr, - dev->bios_size, dev->bios_size-1, 0, MEM_MAPPING_EXTERNAL); - } + /* Create a memory mapping for the space. */ + rom_init(&dev->bios_rom, s, dev->bios_addr, + dev->bios_size, dev->bios_size-1, 0, MEM_MAPPING_EXTERNAL); nelog(1, "%s: BIOS configured at %06lX (size %ld)\n", dev->name, dev->bios_addr, dev->bios_size); @@ -1939,13 +1926,9 @@ nic_init(int board) dev->bios_addr = device_get_config_hex20("bios_addr"); if (dev->bios_addr) - { dev->has_bios = 1; - } - else - { + else dev->has_bios = 0; - } /* See if we have a local MAC address configured. */ mac = device_get_config_mac("mac", -1); @@ -2083,21 +2066,21 @@ nic_close(void *priv) static void * -ne1000_init(void) +ne1000_init(device_t *info) { return(nic_init(NE2K_NE1000)); } static void * -ne2000_init(void) +ne2000_init(device_t *info) { return(nic_init(NE2K_NE2000)); } static void * -rtl8029as_init(void) +rtl8029as_init(device_t *info) { return(nic_init(NE2K_RTL8029AS)); } @@ -2296,35 +2279,26 @@ static device_config_t rtl8029as_config[] = device_t ne1000_device = { "Novell NE1000", 0, - ne1000_init, - nic_close, - NULL, - NULL, - NULL, - NULL, + NE2K_NE1000, + ne1000_init, nic_close, NULL, + NULL, NULL, NULL, NULL, ne1000_config }; device_t ne2000_device = { "Novell NE2000", - 0, - ne2000_init, - nic_close, - NULL, - NULL, - NULL, - NULL, + DEVICE_AT, + NE2K_NE2000, + ne2000_init, nic_close, NULL, + NULL, NULL, NULL, NULL, ne2000_config }; device_t rtl8029as_device = { "Realtek RTL8029AS", 0, - rtl8029as_init, - nic_close, - NULL, - NULL, - NULL, - NULL, + NE2K_RTL8029AS, + rtl8029as_init, nic_close, NULL, + NULL, NULL, NULL, NULL, rtl8029as_config }; diff --git a/src/network/network.c b/src/network/network.c index 487bdc192..c213529e9 100644 --- a/src/network/network.c +++ b/src/network/network.c @@ -12,7 +12,7 @@ * it should be malloc'ed and then linked to the NETCARD def. * Will be done later. * - * Version: @(#)network.c 1.0.11 2017/09/24 + * Version: @(#)network.c 1.0.12 2017/10/04 * * Author: Fred N. van Kempen, */ @@ -43,12 +43,12 @@ static netcard_t net_cards[] = { /* Global variables. */ -int network_card; int network_type; int network_ndev; -int nic_do_log; +int network_card; netdev_t network_devs[32]; char network_pcap[512]; +int nic_do_log; /* @@ -69,10 +69,9 @@ network_init(void) nic_do_log = 0; #endif -#if 0 + /* Initialize to a known state. */ network_type = NET_TYPE_NONE; network_card = 0; -#endif /* Create a first device entry that's always there, as needed by UI. */ strcpy(network_devs[0].device, "none"); diff --git a/src/nvr.c b/src/nvr.c index 7495a69ec..2ef576b41 100644 --- a/src/nvr.c +++ b/src/nvr.c @@ -397,6 +397,9 @@ onesec_timer(void *priv) /* Update the system RTC. */ rtc_tick(); + if (nvr->hook != NULL) + (*nvr->hook)(nvr); + /* Re-calculate the timer. */ nvr_recalc(); @@ -455,7 +458,8 @@ update_timer(void *priv) nvr->regs[RTC_REGC] |= REGC_IRQF; /* Generate an interrupt. */ - picint(1<irq); + if (nvr->irq != -1) + picint(1<irq); } } @@ -468,7 +472,8 @@ update_timer(void *priv) nvr->regs[RTC_REGC] |= REGC_IRQF; /* Generate an interrupt. */ - picint(1<irq); + if (nvr->irq != -1) + picint(1<irq); } } @@ -496,7 +501,8 @@ ticker_timer(void *priv) nvr->regs[RTC_REGC] |= REGC_IRQF; /* Generate an interrupt. */ - picint(1<irq); + if (nvr->irq != -1) + picint(1<irq); } } @@ -642,107 +648,101 @@ nvr_recalc(void) } -/* Load an NVR from file. */ -void +/* + * Load an NVR from file. + * + * This function does two things, really. It clear and initializes + * the RTC and NVRAM areas, sets up defaults for the RTC part, and + * then attempts to load data from a saved file. + * + * Either way, after that loading, it will continue to configure + * the local RTC to operate, so it can update either the local RTC, + * and/or the supplied by a client. + */ +int nvr_load(void) { FILE *f; int c; /* Make sure we have been initialized. */ - if (saved_nvr == NULL) return; + if (saved_nvr == NULL) return(0); /* Clear out any old data. */ memset(saved_nvr->regs, 0xff, sizeof(saved_nvr->regs)); + + /* Set the defaults. */ memset(saved_nvr->regs, 0x00, RTC_REGS); + saved_nvr->regs[RTC_DOM] = 1; + saved_nvr->regs[RTC_MONTH] = 1; + saved_nvr->regs[RTC_YEAR] = RTC_BCD(80); + saved_nvr->regs[RTC_CENTURY] = RTC_BCD(19); -#if 0 - europc_load_nvr(); - - if (saved_nvr->load) - (*saved_nvr->load(); - return; - } -#endif - - f = NULL; - if (saved_nvr->mask != 0) { - pclog("Opening NVR file: %ws...\n", saved_nvr->fname); - f = _wfopen(nvr_path(saved_nvr->fname), L"rb"); - } - - if (f==NULL || saved_nvr->mask==0) { - if (f != NULL) - fclose(f); - - /* No file loaded, or no file available. */ - if (! enable_sync) { - /* No time-sync enabled, so just set the defaults. */ - saved_nvr->regs[RTC_SECONDS] = 0; - saved_nvr->regs[RTC_MINUTES] = 0; - saved_nvr->regs[RTC_HOURS] = 0; - saved_nvr->regs[RTC_DOM] = 1; - saved_nvr->regs[RTC_MONTH] = 1; - saved_nvr->regs[RTC_YEAR] = RTC_BCD(80); - saved_nvr->regs[RTC_REGB] = REGB_2412; - saved_nvr->regs[RTC_CENTURY] = RTC_BCD(19); + if (saved_nvr->load == NULL) { + /* We are responsible for loading. */ + f = NULL; + if (saved_nvr->mask != 0) { + pclog("Opening NVR file: %ws...\n", saved_nvr->fname); + f = _wfopen(nvr_path(saved_nvr->fname), L"rb"); } - return; + if (f != NULL) { + /* Read NVR contents from file. */ + fread(saved_nvr->regs, sizeof(saved_nvr->regs), 1, f); + (void)fclose(f); + } + } else { + /* OK, use alternate function. */ + (*saved_nvr->load)(saved_nvr->fname); } - /* Read NVR contents from file. */ - fread(saved_nvr->regs, sizeof(saved_nvr->regs), 1, f); - (void)fclose(f); - /* Update the internal clock state based on the NVR registers. */ if (enable_sync) rtc_sync(saved_nvr->regs); else rtc_setnvr(saved_nvr->regs); - saved_nvr->regs[RTC_REGA] = 0x06; + /* Get the local RTC running! */ + saved_nvr->regs[RTC_REGA] = (REGA_RS2|REGA_RS1); saved_nvr->regs[RTC_REGB] = REGB_2412; - c = 1 << ((saved_nvr->regs[RTC_REGA] & REGA_RS) - 1); saved_nvr->rtctime += (int)(RTCCONST * c * (1<save == NULL) { + /* We are responsible for saving. */ + f = NULL; + if (saved_nvr->mask != 0) { + pclog("Saving NVR file: %ws...\n", saved_nvr->fname); + f = _wfopen(nvr_path(saved_nvr->fname), L"wb"); + } - if (saved_nvr->save) - (*saved_nvr->save)(); - return; + if (f != NULL) { + /* Save NVR contents to file. */ + (void)fwrite(saved_nvr->regs, sizeof(saved_nvr->regs), 1, f); + (void)fclose(f); + } + } else { + /* OK, use alternate function. */ + (*saved_nvr->save)(saved_nvr->fname); } -#endif - - f = NULL; - if (saved_nvr->mask != 0) { - pclog("Saving NVR file: %ws...\n", saved_nvr->fname); - f = _wfopen(nvr_path(saved_nvr->fname), L"wb"); - } - if (f==NULL || saved_nvr->mask==0) { - if (f != NULL) - fclose(f); - return; - } - - (void)fwrite(saved_nvr->regs, sizeof(saved_nvr->regs), 1, f); - (void)fclose(f); /* Device is clean again. */ nvr_dosave = 0; + + return(1); } diff --git a/src/nvr.h b/src/nvr.h index bfc4bd0ff..0cb5f8301 100644 --- a/src/nvr.h +++ b/src/nvr.h @@ -76,6 +76,12 @@ typedef struct _nvr_ { uint8_t regs[RTC_REGS+114]; /* these are the registers */ + int mask, + irq, + addr; + + wchar_t *fname; + int upd_stat, upd_ecount, onesec_time, @@ -83,14 +89,16 @@ typedef struct _nvr_ { rtctime, oldmachine; - int mask, - irq, - addr; - + /* Hooks to internal RTC I/O functions. */ void (*set)(struct _nvr_ *, uint16_t, uint8_t); uint8_t (*get)(struct _nvr_ *, uint16_t); - wchar_t *fname; + /* Hooks to alternative load/save functions. */ + int8_t (*load)(wchar_t *fname); + int8_t (*save)(wchar_t *fname); + + /* Hook to RTC ticker handler. */ + void (*hook)(struct _nvr_ *); } nvr_t; @@ -99,8 +107,8 @@ extern int nvr_dosave; extern void nvr_init(nvr_t *); -extern void nvr_load(void); -extern void nvr_save(void); +extern int nvr_load(void); +extern int nvr_save(void); extern void nvr_recalc(void); extern wchar_t *nvr_path(wchar_t *str); diff --git a/src/nvr_at.c b/src/nvr_at.c index 299d9a730..9a74b37b8 100644 --- a/src/nvr_at.c +++ b/src/nvr_at.c @@ -14,7 +14,7 @@ * of those batteries would create corrosion issues later on * in mainboard life... * - * Version: @(#)nvr_at.c 1.0.5 2017/10/02 + * Version: @(#)nvr_at.c 1.0.6 2017/10/04 * * Authors: Miran Grca, * Fred N. van Kempen, @@ -105,4 +105,7 @@ nvr_at_init(int irq) /* Set up the PC/AT handler for this device. */ io_sethandler(0x0070, 2, nvr_read, NULL, NULL, nvr_write, NULL, NULL, nvr); + + /* Load the NVR into memory! */ + (void)nvr_load(); } diff --git a/src/nvr_ps2.c b/src/nvr_ps2.c index 817e8c43b..2be9a2fba 100644 --- a/src/nvr_ps2.c +++ b/src/nvr_ps2.c @@ -54,7 +54,7 @@ static void ps2_nvr_write(uint16_t port, uint8_t val, void *p) } } -static void *ps2_nvr_init() +static void *ps2_nvr_init(device_t *info) { ps2_nvr_t *nvr = (ps2_nvr_t *)malloc(sizeof(ps2_nvr_t)); FILE *f = NULL; @@ -100,10 +100,9 @@ device_t ps2_nvr_device = { "PS/2 NVRRAM", 0, + 0, ps2_nvr_init, ps2_nvr_close, - NULL, - NULL, - NULL, - NULL + NULL, + NULL, NULL, NULL, NULL }; diff --git a/src/pc.c b/src/pc.c index 193fe62e8..e406371d1 100644 --- a/src/pc.c +++ b/src/pc.c @@ -8,7 +8,7 @@ * * Emulation core dispatcher. * - * Version: @(#)pc.c 1.0.16 2017/10/01 + * Version: @(#)pc.c 1.0.17 2017/10/04 * * Authors: Sarah Walker, * Miran Grca, @@ -26,6 +26,7 @@ #include "86box.h" #include "config.h" #include "ibm.h" +#include "io.h" #include "mem.h" #include "rom.h" #include "cpu/codegen.h" @@ -71,6 +72,7 @@ #include "win/plat_mouse.h" #include "win/plat_ui.h" #include "win/win.h" +#include "win/win_language.h" #include "scsi/scsi.h" #include "serial.h" #include "sound/sound.h" @@ -189,20 +191,6 @@ pc_concat(wchar_t *str) } -static void -usage(void) -{ - printf("Command line options:\n\n"); - printf("--config file.cfg - use given file as initial configuration\n"); - printf("--dump - always dump memory on exit\n"); - printf("--fullscreen - start in fullscreen mode\n"); - printf("--vmpath pathname - set 'path' to be root for vm\n"); - - exit(-1); - /*NOTREACHED*/ -} - - /* * Perform initial startup of the PC. * @@ -210,7 +198,7 @@ usage(void) * where we check commandline arguments and loading a * configuration file. */ -void +int pc_init(int argc, wchar_t *argv[]) { wchar_t *cfg = NULL; @@ -225,7 +213,6 @@ pc_init(int argc, wchar_t *argv[]) get_executable_name(exe_path, sizeof(exe_path)-1); p = get_filename_w(exe_path); *p = L'\0'; - pclog("exe_path=%ws\n", exe_path); /* * Get the current working directory. @@ -239,8 +226,12 @@ pc_init(int argc, wchar_t *argv[]) for (c=1; c=0; c--) { + if (gfx_present[c]) { + gfxcard = c; + config_save(); + + /* This can loop if all cards now bad.. */ + goto again2; + } + } + } cpuspeed2 = (AT) ? 2 : 1; atfullspeed = 0; - random_init(); mem_init(); codegen_init(); - rom_load_bios(romset); - mem_add_bios(); - mouse_init(); #ifdef WALTJE serial_init(); #endif joystick_init(); video_init(); + ide_init_first(); +#if 1 + /* should be in cdrom.c */ + cdrom_init_host_drives(); + + for (c=0; c='A') && (cdrom_drives[c].host_drive <= 'Z')) + { + ioctl_open(c, cdrom_drives[c].host_drive); + } else { + cdrom_null_open(c, cdrom_drives[c].host_drive); + } + } +#endif + device_init(); timer_reset(); - for (i=0; i='A') && (cdrom_drives[i].host_drive <= 'Z')) - { - ioctl_open(i, cdrom_drives[i].host_drive); - } else { - cdrom_null_open(i, cdrom_drives[i].host_drive); - } - } - sound_reset(); #if 1 @@ -418,8 +482,6 @@ pc_init_modules(void) floppy_load(2, floppyfns[2]); floppy_load(3, floppyfns[3]); #endif - - nvr_load(); sound_init(); @@ -427,10 +489,6 @@ pc_init_modules(void) ide_reset(); - scsi_card_init(); - - pc_full_speed(); - for (i=0; i * Miran Grca, @@ -54,6 +54,7 @@ typedef struct { static SCSI_CARD scsi_cards[] = { { "None", "none", NULL, NULL }, { "Adaptec AHA-1540B", "aha1540b", &aha1540b_device, aha_device_reset }, + { "Adaptec AHA-1542C", "aha1542c", &aha1542c_device, aha_device_reset }, { "Adaptec AHA-1542CF", "aha1542cf", &aha1542cf_device, aha_device_reset }, { "Adaptec AHA-1640", "aha1640", &aha1640_device, aha_device_reset }, { "BusLogic BT-545C", "bt545c", &buslogic_device, BuslogicDeviceReset }, diff --git a/src/scsi/scsi.h b/src/scsi/scsi.h index 3c975677f..e61c0545d 100644 --- a/src/scsi/scsi.h +++ b/src/scsi/scsi.h @@ -8,7 +8,7 @@ * * SCSI controller handler header. * - * Version: @(#)scsi_h 1.0.5 2017/08/27 + * Version: @(#)scsi_h 1.0.6 2017/10/04 * * Authors: TheCollector1995, * Miran Grca, @@ -281,7 +281,7 @@ extern int scsi_card_current; extern int scsi_card_available(int card); extern char *scsi_card_getname(int card); -extern struct device_t *scsi_card_getdevice(int card); +extern device_t *scsi_card_getdevice(int card); extern int scsi_card_has_config(int card); extern char *scsi_card_get_internal_name(int card); extern int scsi_card_get_from_internal_name(char *s); diff --git a/src/scsi/scsi_aha154x.c b/src/scsi/scsi_aha154x.c index a5741232c..7dbec1efd 100644 --- a/src/scsi/scsi_aha154x.c +++ b/src/scsi/scsi_aha154x.c @@ -12,7 +12,7 @@ * * NOTE: THIS IS CURRENTLY A MESS, but will be cleaned up as I go. * - * Version: @(#)scsi_aha154x.c 1.0.19 2017/10/02 + * Version: @(#)scsi_aha154x.c 1.0.20 2017/10/04 * * Authors: Fred N. van Kempen, * Original Buslogic version by SA1988 and Miran Grca. @@ -369,7 +369,6 @@ typedef struct { } Req_t; #pragma pack(pop) -#pragma pack(push,1) typedef struct { int8_t type; /* type of device */ char name[16]; /* name of device */ @@ -425,7 +424,6 @@ typedef struct { int Lock; event_t *evt; } aha_t; -#pragma pack(pop) static uint16_t aha_ports[] = { @@ -2043,7 +2041,7 @@ aha_init(int type) case AHA_154xC: strcpy(dev->name, "AHA-154xC"); - dev->bios_path = L"roms/scsi/adaptec/aha1542c101.bin"; + dev->bios_path = L"roms/scsi/adaptec/aha1542c102.bin"; dev->bid = 'D'; dev->rom_shram = 0x3F80; /* shadow RAM address base */ dev->rom_shramsz = 128; /* size of shadow RAM */ @@ -2114,21 +2112,28 @@ aha_init(int type) static void * -aha_154xB_init(void) +aha_154xB_init(device_t *info) { return(aha_init(AHA_154xB)); } static void * -aha_154xCF_init(void) +aha_154xC_init(device_t *info) +{ + return(aha_init(AHA_154xC)); +} + + +static void * +aha_154xCF_init(device_t *info) { return(aha_init(AHA_154xCF)); } static void * -aha_1640_init(void) +aha_1640_init(device_t *info) { return(aha_init(AHA_1640)); } @@ -2272,34 +2277,54 @@ static device_config_t aha_154x_config[] = { device_t aha1540b_device = { "Adaptec AHA-1540B", 0, + 0, aha_154xB_init, aha_close, NULL, NULL, NULL, NULL, + NULL, + aha_154x_config +}; + +device_t aha1542c_device = { + "Adaptec AHA-1542C", + 0, + 0, + aha_154xC_init, + aha_close, + NULL, + NULL, + NULL, + NULL, + NULL, aha_154x_config }; device_t aha1542cf_device = { "Adaptec AHA-1542CF", 0, + 0, aha_154xCF_init, aha_close, NULL, NULL, NULL, NULL, + NULL, aha_154x_config }; device_t aha1640_device = { "Adaptec AHA-1640", DEVICE_MCA, + 0, aha_1640_init, aha_close, NULL, NULL, NULL, + NULL, NULL }; diff --git a/src/scsi/scsi_aha154x.h b/src/scsi/scsi_aha154x.h index 9634cda69..12c39b375 100644 --- a/src/scsi/scsi_aha154x.h +++ b/src/scsi/scsi_aha154x.h @@ -3,6 +3,7 @@ extern device_t aha1540b_device; +extern device_t aha1542c_device; extern device_t aha1542cf_device; extern device_t aha1640_device; diff --git a/src/scsi/scsi_bios_command.c b/src/scsi/scsi_bios_command.c index ea3cdf4e9..53463cbcb 100644 --- a/src/scsi/scsi_bios_command.c +++ b/src/scsi/scsi_bios_command.c @@ -8,7 +8,7 @@ * * The shared AHA and Buslogic SCSI BIOS command handler. * - * Version: @(#)scsi_bios_command.c 1.0.2 2017/09/24 + * Version: @(#)scsi_bios_command.c 1.0.3 2017/10/04 * * Authors: TheCollector1995, * Miran Grca, @@ -24,6 +24,7 @@ #include #include "../ibm.h" #include "../dma.h" +#include "../device.h" #include "scsi.h" #include "scsi_bios_command.h" #include "scsi_device.h" diff --git a/src/scsi/scsi_buslogic.c b/src/scsi/scsi_buslogic.c index 01ce43a36..ee0ac8ea2 100644 --- a/src/scsi/scsi_buslogic.c +++ b/src/scsi/scsi_buslogic.c @@ -10,7 +10,7 @@ * 0 - BT-545C ISA; * 1 - BT-958D PCI (but BT-545C ISA on non-PCI machines) * - * Version: @(#)scsi_buslogic.c 1.0.15 2017/10/02 + * Version: @(#)scsi_buslogic.c 1.0.16 2017/10/04 * * Authors: TheCollector1995, * Miran Grca, @@ -3019,14 +3019,14 @@ BuslogicInit(int chip) static void * -Buslogic_545C_Init(void) +Buslogic_545C_Init(device_t *info) { return BuslogicInit(CHIP_BUSLOGIC_ISA); } static void * -Buslogic_958D_Init(void) +Buslogic_958D_Init(device_t *info) { return BuslogicInit(CHIP_BUSLOGIC_PCI); } @@ -3143,23 +3143,27 @@ static device_config_t BuslogicConfig[] = { device_t buslogic_device = { "Buslogic BT-545C ISA", 0, + 0, Buslogic_545C_Init, BuslogicClose, NULL, NULL, NULL, NULL, + NULL, BuslogicConfig }; device_t buslogic_pci_device = { "Buslogic BT-958D PCI", 0, + 0, Buslogic_958D_Init, BuslogicClose, NULL, NULL, NULL, NULL, + NULL, BuslogicConfig }; diff --git a/src/scsi/scsi_device.c b/src/scsi/scsi_device.c index f06a47d37..569c31d5b 100644 --- a/src/scsi/scsi_device.c +++ b/src/scsi/scsi_device.c @@ -8,7 +8,7 @@ * * The generic SCSI device command handler. * - * Version: @(#)scsi_device.c 1.0.4 2017/10/01 + * Version: @(#)scsi_device.c 1.0.5 2017/10/04 * * Authors: Miran Grca, * Fred N. van Kempen, @@ -20,6 +20,7 @@ #include #include #include "../ibm.h" +#include "../device.h" #include "../cdrom/cdrom.h" #include "../disk/hdd.h" #include "scsi.h" diff --git a/src/scsi/scsi_disk.c b/src/scsi/scsi_disk.c index f06b8855c..5836ded9e 100644 --- a/src/scsi/scsi_disk.c +++ b/src/scsi/scsi_disk.c @@ -6,7 +6,7 @@ * * Emulation of SCSI fixed and removable disks. * - * Version: @(#)scsi_disk.c 1.0.9 2017/10/01 + * Version: @(#)scsi_disk.c 1.0.9 2017/10/05 * * Author: Miran Grca, * Copyright 2017 Miran Grca. @@ -26,6 +26,7 @@ #include "../disk/hdd.h" #include "../disk/hdc.h" #include "../disk/hdc_ide.h" +#include "../win/win.h" #include "../win/plat_iodev.h" #include "scsi.h" #include "scsi_disk.h" @@ -889,11 +890,11 @@ void scsi_hd_command(uint8_t id, uint8_t *cdb) shdc[id].all_blocks_total = shdc[id].block_total; if (shdc[id].packet_status != CDROM_PHASE_COMPLETE) { - update_status_bar_icon((hdd[id].bus == HDD_BUS_SCSI_REMOVABLE) ? (SB_RDISK | id) : (SB_HDD | HDD_BUS_SCSI), 1); + StatusBarUpdateIcon((hdd[id].bus == HDD_BUS_SCSI_REMOVABLE) ? (SB_RDISK | id) : (SB_HDD | HDD_BUS_SCSI), 1); } else { - update_status_bar_icon((hdd[id].bus == HDD_BUS_SCSI_REMOVABLE) ? (SB_RDISK | id) : (SB_HDD | HDD_BUS_SCSI), 0); + StatusBarUpdateIcon((hdd[id].bus == HDD_BUS_SCSI_REMOVABLE) ? (SB_RDISK | id) : (SB_HDD | HDD_BUS_SCSI), 0); } return; @@ -965,11 +966,11 @@ void scsi_hd_command(uint8_t id, uint8_t *cdb) shdc[id].all_blocks_total = shdc[id].block_total; if (shdc[id].packet_status != CDROM_PHASE_COMPLETE) { - update_status_bar_icon((hdd[id].bus == HDD_BUS_SCSI_REMOVABLE) ? (SB_RDISK | id) : (SB_HDD | HDD_BUS_SCSI), 1); + StatusBarUpdateIcon((hdd[id].bus == HDD_BUS_SCSI_REMOVABLE) ? (SB_RDISK | id) : (SB_HDD | HDD_BUS_SCSI), 1); } else { - update_status_bar_icon((hdd[id].bus == HDD_BUS_SCSI_REMOVABLE) ? (SB_RDISK | id) : (SB_HDD | HDD_BUS_SCSI), 0); + StatusBarUpdateIcon((hdd[id].bus == HDD_BUS_SCSI_REMOVABLE) ? (SB_RDISK | id) : (SB_HDD | HDD_BUS_SCSI), 0); } return; @@ -1163,7 +1164,7 @@ void scsi_hd_callback(uint8_t id) shdc[id].status = READY_STAT; shdc[id].phase = 3; shdc[id].packet_status = 0xFF; - update_status_bar_icon((hdd[id].bus == HDD_BUS_SCSI_REMOVABLE) ? (SB_RDISK | id) : (SB_HDD | HDD_BUS_SCSI), 0); + StatusBarUpdateIcon((hdd[id].bus == HDD_BUS_SCSI_REMOVABLE) ? (SB_RDISK | id) : (SB_HDD | HDD_BUS_SCSI), 0); return; case CDROM_PHASE_DATA_OUT: scsi_hd_log("SCSI HD %i: PHASE_DATA_OUT\n", id); @@ -1175,7 +1176,7 @@ void scsi_hd_callback(uint8_t id) shdc[id].packet_status = CDROM_PHASE_COMPLETE; shdc[id].status = READY_STAT; shdc[id].phase = 3; - update_status_bar_icon((hdd[id].bus == HDD_BUS_SCSI_REMOVABLE) ? (SB_RDISK | id) : (SB_HDD | HDD_BUS_SCSI), 0); + StatusBarUpdateIcon((hdd[id].bus == HDD_BUS_SCSI_REMOVABLE) ? (SB_RDISK | id) : (SB_HDD | HDD_BUS_SCSI), 0); return; case CDROM_PHASE_DATA_IN: scsi_hd_log("SCSI HD %i: PHASE_DATA_IN\n", id); @@ -1187,7 +1188,7 @@ void scsi_hd_callback(uint8_t id) shdc[id].packet_status = CDROM_PHASE_COMPLETE; shdc[id].status = READY_STAT; shdc[id].phase = 3; - update_status_bar_icon((hdd[id].bus == HDD_BUS_SCSI_REMOVABLE) ? (SB_RDISK | id) : (SB_HDD | HDD_BUS_SCSI), 0); + StatusBarUpdateIcon((hdd[id].bus == HDD_BUS_SCSI_REMOVABLE) ? (SB_RDISK | id) : (SB_HDD | HDD_BUS_SCSI), 0); return; case CDROM_PHASE_ERROR: scsi_hd_log("SCSI HD %i: PHASE_ERROR\n", id); diff --git a/src/sound/midi.h b/src/sound/midi.h index 371c79eb4..2b38c5a5f 100644 --- a/src/sound/midi.h +++ b/src/sound/midi.h @@ -1,8 +1,15 @@ +#ifndef EMU_SOUND_MIDI_H +# define EMU_SOUND_MIDI_H + + extern int midi_device_current; + int midi_device_available(int card); char *midi_device_getname(int card); -struct device_t *midi_device_getdevice(int card); +#ifdef EMU_DEVICE_H +device_t *midi_device_getdevice(int card); +#endif int midi_device_has_config(int card); char *midi_device_get_internal_name(int card); int midi_device_get_from_internal_name(char *s); @@ -32,4 +39,7 @@ void midi_poll(); #else #define SYSTEM_MIDI_NAME "System MIDI" #define SYSTEM_MIDI_INTERNAL_NAME "system_midi" -#endif \ No newline at end of file +#endif + + +#endif /*EMU_SOUND_MIDI_H*/ diff --git a/src/sound/midi_mt32.c b/src/sound/midi_mt32.c index cbf4c3d4d..7bfcddd63 100644 --- a/src/sound/midi_mt32.c +++ b/src/sound/midi_mt32.c @@ -222,12 +222,12 @@ void* mt32emu_init(wchar_t *control_rom, wchar_t *pcm_rom) return dev; } -void *mt32_init() +void *mt32_init(device_t *info) { return mt32emu_init(L"roms/sound/mt32/mt32_control.rom", L"roms/sound/mt32/mt32_pcm.rom"); } -void *cm32l_init() +void *cm32l_init(device_t *info) { return mt32emu_init(L"roms/sound/cm32l/cm32l_control.rom", L"roms/sound/cm32l/cm32l_pcm.rom"); } @@ -316,8 +316,10 @@ device_t mt32_device = { "Roland MT-32 Emulation", 0, + 0, mt32_init, mt32_close, + NULL, mt32_available, NULL, NULL, @@ -329,8 +331,10 @@ device_t cm32l_device = { "Roland CM-32L Emulation", 0, + 0, cm32l_init, mt32_close, + NULL, cm32l_available, NULL, NULL, diff --git a/src/sound/midi_system.c b/src/sound/midi_system.c index e2f3573d4..f8c20f29a 100644 --- a/src/sound/midi_system.c +++ b/src/sound/midi_system.c @@ -9,7 +9,7 @@ #include "midi_system.h" -void* system_midi_init() +void* system_midi_init(device_t *info) { midi_device_t* dev = malloc(sizeof(midi_device_t)); memset(dev, 0, sizeof(midi_device_t)); @@ -32,7 +32,7 @@ void system_midi_close(void* p) midi_close(); } -int system_midi_available() +int system_midi_available(void) { return plat_midi_get_num_devs(); } @@ -53,9 +53,10 @@ static device_config_t system_midi_config[] = device_t system_midi_device = { SYSTEM_MIDI_NAME, - 0, + 0, 0, system_midi_init, system_midi_close, + NULL, system_midi_available, NULL, NULL, diff --git a/src/sound/snd_adlib.c b/src/sound/snd_adlib.c index 838d74faa..c02d8c1b6 100644 --- a/src/sound/snd_adlib.c +++ b/src/sound/snd_adlib.c @@ -63,7 +63,7 @@ void adlib_mca_write(int port, uint8_t val, void *p) adlib->pos_regs[port & 7] = val; } -void *adlib_init() +void *adlib_init(device_t *info) { adlib_t *adlib = malloc(sizeof(adlib_t)); memset(adlib, 0, sizeof(adlib_t)); @@ -75,9 +75,9 @@ void *adlib_init() return adlib; } -void *adlib_mca_init() +void *adlib_mca_init(device_t *info) { - adlib_t *adlib = adlib_init(); + adlib_t *adlib = adlib_init(info); io_removehandler(0x0388, 0x0002, opl2_read, NULL, NULL, opl2_write, NULL, NULL, &adlib->opl); mca_add(adlib_mca_read, adlib_mca_write, adlib); @@ -98,11 +98,9 @@ device_t adlib_device = { "AdLib", 0, - adlib_init, - adlib_close, - NULL, - NULL, - NULL, + 0, + adlib_init, adlib_close, NULL, + NULL, NULL, NULL, NULL, NULL }; @@ -110,10 +108,8 @@ device_t adlib_mca_device = { "AdLib (MCA)", DEVICE_MCA, - adlib_init, - adlib_close, - NULL, - NULL, - NULL, + 0, + adlib_init, adlib_close, NULL, + NULL, NULL, NULL, NULL, NULL }; diff --git a/src/sound/snd_adlibgold.c b/src/sound/snd_adlibgold.c index b53ceee6e..449cbc8a2 100644 --- a/src/sound/snd_adlibgold.c +++ b/src/sound/snd_adlibgold.c @@ -754,7 +754,7 @@ static void adgold_get_buffer(int32_t *buffer, int len, void *p) } -void *adgold_init() +void *adgold_init(device_t *info) { FILE *f; int c; @@ -840,9 +840,10 @@ static device_config_t adgold_config[] = device_t adgold_device = { "AdLib Gold", - 0, + 0, 0, adgold_init, adgold_close, + NULL, NULL, NULL, NULL, diff --git a/src/sound/snd_cms.c b/src/sound/snd_cms.c index 56d46a764..9f148a57f 100644 --- a/src/sound/snd_cms.c +++ b/src/sound/snd_cms.c @@ -158,7 +158,7 @@ uint8_t cms_read(uint16_t addr, void *p) return cms->regs[chip][cms->addrs[chip] & 31]; } -void *cms_init() +void *cms_init(device_t *info) { cms_t *cms = malloc(sizeof(cms_t)); memset(cms, 0, sizeof(cms_t)); @@ -179,11 +179,8 @@ void cms_close(void *p) device_t cms_device = { "Creative Music System / Game Blaster", - 0, - cms_init, - cms_close, - NULL, - NULL, - NULL, + 0, 0, + cms_init, cms_close, NULL, + NULL, NULL, NULL, NULL, NULL }; diff --git a/src/sound/snd_gus.c b/src/sound/snd_gus.c index cc85ec430..d9043371b 100644 --- a/src/sound/snd_gus.c +++ b/src/sound/snd_gus.c @@ -995,7 +995,7 @@ static void gus_get_buffer(int32_t *buffer, int len, void *p) } -void *gus_init() +void *gus_init(device_t *info) { int c; double out = 1.0; @@ -1060,11 +1060,8 @@ void gus_speed_changed(void *p) device_t gus_device = { "Gravis UltraSound", - 0, - gus_init, - gus_close, - NULL, - gus_speed_changed, - NULL, + 0, 0, + gus_init, gus_close, NULL, NULL, + gus_speed_changed, NULL, NULL, NULL }; diff --git a/src/sound/snd_mpu401.c b/src/sound/snd_mpu401.c index 2b64c1a1f..bbe24d5f8 100644 --- a/src/sound/snd_mpu401.c +++ b/src/sound/snd_mpu401.c @@ -8,7 +8,7 @@ * * Roland MPU-401 emulation. * - * Version: @(#)snd_mpu401.c 1.0.2 2017/09/24 + * Version: @(#)snd_mpu401.c 1.0.3 2017/10/04 * * Authors: Sarah Walker, * DOSBox Team, @@ -788,7 +788,7 @@ void mpu401_device_add(void) device_add(&mpu401_device); } -void *mpu401_standalone_init() +void *mpu401_standalone_init(device_t *info) { mpu_t *mpu; @@ -872,11 +872,10 @@ static device_config_t mpu401_standalone_config[] = device_t mpu401_device = { "MPU-401 (Standalone)", - 0, + 0, 0, mpu401_standalone_init, mpu401_standalone_close, - NULL, - NULL, + NULL, NULL, NULL, NULL, NULL, mpu401_standalone_config diff --git a/src/sound/snd_pas16.c b/src/sound/snd_pas16.c index 523bd6e86..9e644cf0f 100644 --- a/src/sound/snd_pas16.c +++ b/src/sound/snd_pas16.c @@ -718,7 +718,8 @@ void pas16_get_buffer(int32_t *buffer, int len, void *p) pas16->dsp.pos = 0; } -void *pas16_init() + +static void *pas16_init(device_t *info) { pas16_t *pas16 = malloc(sizeof(pas16_t)); memset(pas16, 0, sizeof(pas16_t)); @@ -735,7 +736,7 @@ void *pas16_init() return pas16; } -void pas16_close(void *p) +static void pas16_close(void *p) { pas16_t *pas16 = (pas16_t *)p; @@ -746,10 +747,8 @@ device_t pas16_device = { "Pro Audio Spectrum 16", DEVICE_NOT_WORKING, - pas16_init, - pas16_close, - NULL, - NULL, - NULL, - NULL + 0, + pas16_init, pas16_close, NULL, + NULL, NULL, NULL, NULL, + NULL }; diff --git a/src/sound/snd_ps1.c b/src/sound/snd_ps1.c index 5580d572f..7b851c3cf 100644 --- a/src/sound/snd_ps1.c +++ b/src/sound/snd_ps1.c @@ -138,7 +138,7 @@ static void ps1_audio_get_buffer(int32_t *buffer, int len, void *p) ps1->pos = 0; } -static void *ps1_audio_init() +static void *ps1_audio_init(device_t *info) { ps1_audio_t *ps1 = malloc(sizeof(ps1_audio_t)); memset(ps1, 0, sizeof(ps1_audio_t)); @@ -163,9 +163,10 @@ static void ps1_audio_close(void *p) device_t ps1_audio_device = { "PS/1 Audio Card", - 0, + 0, 0, ps1_audio_init, ps1_audio_close, + NULL, NULL, NULL, NULL, diff --git a/src/sound/snd_pssj.c b/src/sound/snd_pssj.c index e9e65774a..5b7df72b9 100644 --- a/src/sound/snd_pssj.c +++ b/src/sound/snd_pssj.c @@ -184,7 +184,7 @@ static void pssj_get_buffer(int32_t *buffer, int len, void *p) pssj->pos = 0; } -void *pssj_init() +void *pssj_init(device_t *info) { pssj_t *pssj = malloc(sizeof(pssj_t)); memset(pssj, 0, sizeof(pssj_t)); @@ -208,9 +208,10 @@ void pssj_close(void *p) device_t pssj_device = { "Tandy PSSJ", - 0, + 0, 0, pssj_init, pssj_close, + NULL, NULL, NULL, NULL, diff --git a/src/sound/snd_sb.c b/src/sound/snd_sb.c index 6c164c305..7f46828b1 100644 --- a/src/sound/snd_sb.c +++ b/src/sound/snd_sb.c @@ -8,7 +8,7 @@ * * Sound Blaster emulation. * - * Version: @(#)sound_sb.c 1.0.1 2017/09/24 + * Version: @(#)sound_sb.c 1.0.2 2017/10/04 * * Authors: Sarah Walker, * Miran Grca, @@ -502,7 +502,7 @@ void sb_pro_mcv_write(int port, uint8_t val, void *p) sb_dsp_setdma8(&sb->dsp, sb->pos_regs[4] & 3); } -void *sb_1_init() +void *sb_1_init(device_t *info) { sb_t *sb = malloc(sizeof(sb_t)); uint16_t addr = device_get_config_hex16("base"); @@ -519,7 +519,7 @@ void *sb_1_init() sound_add_handler(sb_get_buffer_opl2, sb); return sb; } -void *sb_15_init() +void *sb_15_init(device_t *info) { sb_t *sb = malloc(sizeof(sb_t)); uint16_t addr = device_get_config_hex16("base"); @@ -537,7 +537,7 @@ void *sb_15_init() return sb; } -void *sb_mcv_init() +void *sb_mcv_init(device_t *info) { sb_t *sb = malloc(sizeof(sb_t)); memset(sb, 0, sizeof(sb_t)); @@ -554,7 +554,7 @@ void *sb_mcv_init() sb->pos_regs[1] = 0x50; return sb; } -void *sb_2_init() +void *sb_2_init(device_t *info) { sb_t *sb = malloc(sizeof(sb_t)); uint16_t addr = device_get_config_hex16("base"); @@ -572,7 +572,7 @@ void *sb_2_init() return sb; } -void *sb_pro_v1_init() +void *sb_pro_v1_init(device_t *info) { sb_t *sb = malloc(sizeof(sb_t)); uint16_t addr = device_get_config_hex16("base"); @@ -600,7 +600,7 @@ void *sb_pro_v1_init() return sb; } -void *sb_pro_v2_init() +void *sb_pro_v2_init(device_t *info) { sb_t *sb = malloc(sizeof(sb_t)); uint16_t addr = device_get_config_hex16("base"); @@ -627,7 +627,7 @@ void *sb_pro_v2_init() return sb; } -void *sb_pro_mcv_init() +void *sb_pro_mcv_init(device_t *info) { sb_t *sb = malloc(sizeof(sb_t)); memset(sb, 0, sizeof(sb_t)); @@ -650,7 +650,7 @@ void *sb_pro_mcv_init() return sb; } -void *sb_16_init() +void *sb_16_init(device_t *info) { sb_t *sb = malloc(sizeof(sb_t)); uint16_t addr = device_get_config_hex16("base"); @@ -690,12 +690,12 @@ void *sb_16_init() return sb; } -int sb_awe32_available() +int sb_awe32_available(void) { return rom_present(L"roms/sound/awe32.raw"); } -void *sb_awe32_init() +void *sb_awe32_init(device_t *info) { sb_t *sb = malloc(sizeof(sb_t)); uint16_t addr = device_get_config_hex16("base"); @@ -1212,9 +1212,8 @@ device_t sb_1_device = { "Sound Blaster v1.0", 0, - sb_1_init, - sb_close, - NULL, + 0, + sb_1_init, sb_close, NULL, NULL, sb_speed_changed, NULL, sb_add_status_info, @@ -1224,9 +1223,8 @@ device_t sb_15_device = { "Sound Blaster v1.5", 0, - sb_15_init, - sb_close, - NULL, + 0, + sb_15_init, sb_close, NULL, NULL, sb_speed_changed, NULL, sb_add_status_info, @@ -1236,9 +1234,8 @@ device_t sb_mcv_device = { "Sound Blaster MCV", DEVICE_MCA, - sb_mcv_init, - sb_close, - NULL, + 0, + sb_mcv_init, sb_close, NULL, NULL, sb_speed_changed, NULL, sb_add_status_info, @@ -1248,9 +1245,8 @@ device_t sb_2_device = { "Sound Blaster v2.0", 0, - sb_2_init, - sb_close, - NULL, + 0, + sb_2_init, sb_close, NULL, NULL, sb_speed_changed, NULL, sb_add_status_info, @@ -1260,9 +1256,8 @@ device_t sb_pro_v1_device = { "Sound Blaster Pro v1", 0, - sb_pro_v1_init, - sb_close, - NULL, + 0, + sb_pro_v1_init, sb_close, NULL, NULL, sb_speed_changed, NULL, sb_add_status_info, @@ -1272,9 +1267,8 @@ device_t sb_pro_v2_device = { "Sound Blaster Pro v2", 0, - sb_pro_v2_init, - sb_close, - NULL, + 0, + sb_pro_v2_init, sb_close, NULL, NULL, sb_speed_changed, NULL, sb_add_status_info, @@ -1284,9 +1278,8 @@ device_t sb_pro_mcv_device = { "Sound Blaster Pro MCV", DEVICE_MCA, - sb_pro_mcv_init, - sb_close, - NULL, + 0, + sb_pro_mcv_init, sb_close, NULL, NULL, sb_speed_changed, NULL, sb_add_status_info, @@ -1296,9 +1289,8 @@ device_t sb_16_device = { "Sound Blaster 16", 0, - sb_16_init, - sb_close, - NULL, + 0, + sb_16_init, sb_close, NULL, NULL, sb_speed_changed, NULL, sb_add_status_info, @@ -1308,8 +1300,8 @@ device_t sb_awe32_device = { "Sound Blaster AWE32", 0, - sb_awe32_init, - sb_close, + 0, + sb_awe32_init, sb_close, NULL, sb_awe32_available, sb_speed_changed, NULL, diff --git a/src/sound/snd_sn76489.c b/src/sound/snd_sn76489.c index e3a9342eb..7f7d02f2f 100644 --- a/src/sound/snd_sn76489.c +++ b/src/sound/snd_sn76489.c @@ -205,7 +205,7 @@ void sn76489_init(sn76489_t *sn76489, uint16_t base, uint16_t size, int type, in io_sethandler(base, size, NULL, NULL, NULL, sn76489_write, NULL, NULL, sn76489); } -void *sn76489_device_init() +void *sn76489_device_init(device_t *info) { sn76489_t *sn76489 = malloc(sizeof(sn76489_t)); memset(sn76489, 0, sizeof(sn76489_t)); @@ -214,7 +214,7 @@ void *sn76489_device_init() return sn76489; } -void *ncr8496_device_init() +void *ncr8496_device_init(device_t *info) { sn76489_t *sn76489 = malloc(sizeof(sn76489_t)); memset(sn76489, 0, sizeof(sn76489_t)); @@ -235,21 +235,19 @@ device_t sn76489_device = { "TI SN74689 PSG", 0, + 0, sn76489_device_init, sn76489_device_close, - NULL, - NULL, - NULL, + NULL, NULL, NULL, NULL, NULL }; device_t ncr8496_device = { "NCR8496 PSG", 0, + 0, ncr8496_device_init, sn76489_device_close, - NULL, - NULL, - NULL, + NULL, NULL, NULL, NULL, NULL }; diff --git a/src/sound/snd_ssi2001.c b/src/sound/snd_ssi2001.c index 6ff21e8b3..cba259422 100644 --- a/src/sound/snd_ssi2001.c +++ b/src/sound/snd_ssi2001.c @@ -57,7 +57,7 @@ static void ssi2001_write(uint16_t addr, uint8_t val, void *p) sid_write(addr, val, p); } -void *ssi2001_init() +void *ssi2001_init(device_t *info) { ssi2001_t *ssi2001 = malloc(sizeof(ssi2001_t)); memset(ssi2001, 0, sizeof(ssi2001_t)); @@ -82,11 +82,8 @@ void ssi2001_close(void *p) device_t ssi2001_device = { "Innovation SSI-2001", - 0, - ssi2001_init, - ssi2001_close, - NULL, - NULL, - NULL, + 0, 0, + ssi2001_init, ssi2001_close, NULL, + NULL, NULL, NULL, NULL, NULL }; diff --git a/src/sound/snd_wss.c b/src/sound/snd_wss.c index 472b1788e..a063fa790 100644 --- a/src/sound/snd_wss.c +++ b/src/sound/snd_wss.c @@ -77,7 +77,7 @@ static void wss_get_buffer(int32_t *buffer, int len, void *p) wss->ad1848.pos = 0; } -void *wss_init() +void *wss_init(device_t *info) { wss_t *wss = malloc(sizeof(wss_t)); @@ -115,11 +115,10 @@ void wss_speed_changed(void *p) device_t wss_device = { "Windows Sound System", - 0, - wss_init, - wss_close, + 0, 0, + wss_init, wss_close, NULL, NULL, wss_speed_changed, - NULL, + NULL, NULL, NULL }; diff --git a/src/sound/sound.h b/src/sound/sound.h index 9afdaa902..53e043cb6 100644 --- a/src/sound/sound.h +++ b/src/sound/sound.h @@ -8,13 +8,16 @@ * * Sound emulation core. * - * Version: @(#)sound.h 1.0.1 2017/06/14 + * Version: @(#)sound.h 1.0.2 2017/10/04 * - * Author: Sarah Walker, + * Authors: Sarah Walker, * Miran Grca, * Copyright 2008-2017 Sarah Walker. - * Copyright 2016-2017 Miran Grca. + * Copyright 2016,2017 Miran Grca. */ +#ifndef EMU_SOUND_H +# define EMU_SOUND_H + void sound_add_handler(void (*get_buffer)(int32_t *buffer, int len, void *p), void *p); @@ -22,7 +25,9 @@ extern int sound_card_current; int sound_card_available(int card); char *sound_card_getname(int card); -struct device_t *sound_card_getdevice(int card); +#ifdef EMU_DEVICE_H +device_t *sound_card_getdevice(int card); +#endif int sound_card_has_config(int card); char *sound_card_get_internal_name(int card); int sound_card_get_from_internal_name(char *s); @@ -48,3 +53,6 @@ void initalmain(int argc, char *argv[]); void inital(); void givealbuffer(void *buf); void givealbuffer_cd(void *buf); + + +#endif /*EMU_SOUND_H*/ diff --git a/src/tandy_eeprom.c b/src/tandy_eeprom.c index 08819a3b4..423b0e251 100644 --- a/src/tandy_eeprom.c +++ b/src/tandy_eeprom.c @@ -125,7 +125,7 @@ int tandy_eeprom_read(void) } -static void *tandy_eeprom_init(void) +static void *tandy_eeprom_init(device_t *info) { tandy_eeprom_t *eeprom = malloc(sizeof(tandy_eeprom_t)); FILE *f = NULL; @@ -180,12 +180,9 @@ void tandy_eeprom_close(void *p) device_t tandy_eeprom_device = { "Tandy EEPROM", - 0, + 0, 0, tandy_eeprom_init, tandy_eeprom_close, - NULL, - NULL, - NULL, - NULL, + NULL, NULL, NULL, NULL, NULL, NULL }; diff --git a/src/tandy_rom.c b/src/tandy_rom.c index 55f78e2a4..c2ba790ca 100644 --- a/src/tandy_rom.c +++ b/src/tandy_rom.c @@ -60,7 +60,7 @@ void tandy_rom_bank_write(uint16_t port, uint8_t val, void *p) } -void *tandy_rom_init(void) +void *tandy_rom_init(device_t *info) { FILE *f, *ff; int c; @@ -97,12 +97,8 @@ void tandy_rom_close(void *p) device_t tandy_rom_device = { "Tandy 1000SL/2 ROM", - 0, - tandy_rom_init, - tandy_rom_close, - NULL, - NULL, - NULL, - NULL, + 0, 0, + tandy_rom_init, tandy_rom_close, NULL, + NULL, NULL, NULL, NULL, NULL }; diff --git a/src/video/vid_ati18800.c b/src/video/vid_ati18800.c index 8b35f435b..b734cc4ca 100644 --- a/src/video/vid_ati18800.c +++ b/src/video/vid_ati18800.c @@ -162,7 +162,7 @@ void ati18800_recalctimings(svga_t *svga) } } -void *ati18800_init() +void *ati18800_init(device_t *info) { ati18800_t *ati18800 = malloc(sizeof(ati18800_t)); memset(ati18800, 0, sizeof(ati18800_t)); @@ -185,7 +185,7 @@ void *ati18800_init() return ati18800; } -static int ati18800_available() +static int ati18800_available(void) { return rom_present(L"roms/video/ati18800/vga88.BIN"); } @@ -223,12 +223,13 @@ void ati18800_add_status_info(char *s, int max_len, void *p) device_t ati18800_device = { "ATI-18800", - 0, + 0, 0, ati18800_init, ati18800_close, + NULL, ati18800_available, ati18800_speed_changed, ati18800_force_redraw, - ati18800_add_status_info + ati18800_add_status_info, + NULL }; - diff --git a/src/video/vid_ati28800.c b/src/video/vid_ati28800.c index 01d43f88b..3428f0d25 100644 --- a/src/video/vid_ati28800.c +++ b/src/video/vid_ati28800.c @@ -354,7 +354,7 @@ void ati28800_recalctimings(svga_t *svga) } } -void *ati28800_init() +void *ati28800_init(device_t *info) { uint32_t memory = 512; ati28800_t *ati28800; @@ -396,17 +396,17 @@ void *ati28800_init() return ati28800; } -static int ati28800_available() +static int ati28800_available(void) { return rom_present(L"roms/video/ati28800/bios.bin"); } -static int compaq_ati28800_available() +static int compaq_ati28800_available(void) { return (rom_present(L"roms/video/ati28800/XLEVEN.bin") && rom_present(L"roms/video/ati28800/XLODD.bin")); } -static int ati28800_wonderxl24_available() +static int ati28800_wonderxl24_available(void) { return (rom_present(L"roms/video/ati28800/112-14318-102.bin") && rom_present(L"roms/video/ati28800/112-14319-102.bin")); } @@ -490,8 +490,10 @@ device_t ati28800_device = { "ATI-28800", 0, + 0, ati28800_init, ati28800_close, + NULL, ati28800_available, ati28800_speed_changed, ati28800_force_redraw, @@ -503,8 +505,10 @@ device_t compaq_ati28800_device = { "Compaq ATI-28800", 0, + 0, ati28800_init, ati28800_close, + NULL, compaq_ati28800_available, ati28800_speed_changed, ati28800_force_redraw, @@ -516,8 +520,10 @@ device_t ati28800_wonderxl24_device = { "ATI-28800 (VGA Wonder XL24)", 0, + 0, ati28800_init, ati28800_close, + NULL, ati28800_wonderxl24_available, ati28800_speed_changed, ati28800_force_redraw, diff --git a/src/video/vid_ati_mach64.c b/src/video/vid_ati_mach64.c index 93ddd2a9b..506812d8a 100644 --- a/src/video/vid_ati_mach64.c +++ b/src/video/vid_ati_mach64.c @@ -8,7 +8,7 @@ * * ATi Mach64 graphics card emulation. * - * Version: @(#)vid_ati_mach64.c 1.0.2 2017/09/24 + * Version: @(#)vid_ati_mach64.c 1.0.3 2017/10/04 * * Authors: Sarah Walker, * Miran Grca, @@ -3294,7 +3294,7 @@ void mach64_pci_write(int func, int addr, uint8_t val, void *p) } } -static void *mach64_common_init() +static void *mach64_common_init(void) { mach64_t *mach64 = malloc(sizeof(mach64_t)); memset(mach64, 0, sizeof(mach64_t)); @@ -3337,7 +3337,7 @@ static void *mach64_common_init() return mach64; } -static void *mach64gx_init() +static void *mach64gx_init(device_t *info) { mach64_t *mach64 = mach64_common_init(); @@ -3357,7 +3357,7 @@ static void *mach64gx_init() return mach64; } -static void *mach64vt2_init() +static void *mach64vt2_init(device_t *info) { mach64_t *mach64 = mach64_common_init(); svga_t *svga = &mach64->svga; @@ -3378,11 +3378,11 @@ static void *mach64vt2_init() return mach64; } -int mach64gx_available() +int mach64gx_available(void) { return rom_present(L"roms/video/mach64/bios.bin"); } -int mach64vt2_available() +int mach64vt2_available(void) { return rom_present(L"roms/video/mach64/atimach64vt2pci.bin"); } @@ -3511,8 +3511,10 @@ device_t mach64gx_device = { "ATI Mach64GX", 0, + 0, mach64gx_init, mach64_close, + NULL, mach64gx_available, mach64_speed_changed, mach64_force_redraw, @@ -3523,8 +3525,10 @@ device_t mach64vt2_device = { "ATI Mach64VT2", DEVICE_PCI, + 0, mach64vt2_init, mach64_close, + NULL, mach64vt2_available, mach64_speed_changed, mach64_force_redraw, diff --git a/src/video/vid_cga.c b/src/video/vid_cga.c index 04bb7837c..3ae4ddb2b 100644 --- a/src/video/vid_cga.c +++ b/src/video/vid_cga.c @@ -8,7 +8,7 @@ * * Emulation of the old and new IBM CGA graphics cards. * - * Version: @(#)vid_cga.c 1.0.2 2017/09/24 + * Version: @(#)vid_cga.c 1.0.3 2017/10/04 * * Authors: Sarah Walker, * Miran Grca, @@ -468,7 +468,7 @@ void cga_init(cga_t *cga) cga->composite = 0; } -void *cga_standalone_init() +void *cga_standalone_init(device_t *info) { int display_type; cga_t *cga = malloc(sizeof(cga_t)); @@ -578,9 +578,10 @@ static device_config_t cga_config[] = device_t cga_device = { "CGA", - 0, + 0, 0, cga_standalone_init, cga_close, + NULL, NULL, cga_speed_changed, NULL, diff --git a/src/video/vid_cl_gd.c b/src/video/vid_cl_gd.c index c560d213e..838d57875 100644 --- a/src/video/vid_cl_gd.c +++ b/src/video/vid_cl_gd.c @@ -882,92 +882,93 @@ void *clgd_common_init(wchar_t *romfn, uint8_t id) return clgd; } -void *gd6235_init() + +void *gd6235_init(device_t *info) { return clgd_common_init(L"roms/video/cirruslogic/vga6235.rom", CIRRUS_ID_CLGD6235); } -void *gd5422_init() +void *gd5422_init(device_t *info) { return clgd_common_init(L"roms/video/cirruslogic/CL5422.ROM", CIRRUS_ID_CLGD5422); } -void *gd5429_init() +void *gd5429_init(device_t *info) { return clgd_common_init(L"roms/video/cirruslogic/5429.vbi", CIRRUS_ID_CLGD5429); } -void *gd5430_init() +void *gd5430_init(device_t *info) { return clgd_common_init(L"roms/video/cirruslogic/pci.BIN", CIRRUS_ID_CLGD5430); } -void *dia5430_init() +void *dia5430_init(device_t *info) { return clgd_common_init(L"roms/video/cirruslogic/diamondvlbus.BIN", CIRRUS_ID_CLGD5430); } -void *gd5434_init() +void *gd5434_init(device_t *info) { return clgd_common_init(L"roms/video/cirruslogic/japan.BIN", CIRRUS_ID_CLGD5434); } -void *gd5436_init() +void *gd5436_init(device_t *info) { return clgd_common_init(L"roms/video/cirruslogic/5436.VBI", CIRRUS_ID_CLGD5436); } -void *gd5440_init() +void *gd5440_init(device_t *info) { return clgd_common_init(L"roms/video/cirruslogic/5440BIOS.BIN", CIRRUS_ID_CLGD5440); } -void *gd5446_init() +void *gd5446_init(device_t *info) { return clgd_common_init(L"roms/video/cirruslogic/5446BV.VBI", CIRRUS_ID_CLGD5446); } -static int gd5422_available() +static int gd5422_available(void) { return rom_present(L"roms/video/cirruslogic/CL5422.ROM"); } -static int gd5429_available() +static int gd5429_available(void) { return rom_present(L"roms/video/cirruslogic/5429.vbi"); } -static int gd5430_available() +static int gd5430_available(void) { return rom_present(L"roms/video/cirruslogic/pci.BIN"); } -static int dia5430_available() +static int dia5430_available(void) { return rom_present(L"roms/video/cirruslogic/diamondvlbus.BIN"); } -static int gd5434_available() +static int gd5434_available(void) { return rom_present(L"roms/video/cirruslogic/japan.BIN"); } -static int gd5436_available() +static int gd5436_available(void) { return rom_present(L"roms/video/cirruslogic/5436.VBI"); } -static int gd5440_available() +static int gd5440_available(void) { return rom_present(L"roms/video/cirruslogic/5440BIOS.BIN"); } -static int gd5446_available() +static int gd5446_available(void) { return rom_present(L"roms/video/cirruslogic/5446BV.VBI"); } -static int gd6235_available() +static int gd6235_available(void) { return rom_present(L"roms/video/cirruslogic/vga6235.rom"); } @@ -1005,116 +1006,134 @@ void clgd_add_status_info(char *s, int max_len, void *p) device_t gd5422_device = { "Cirrus Logic GD5422", - // DEVICE_NOT_WORKING, + DEVICE_NOT_WORKING, 0, gd5422_init, clgd_close, + NULL, gd5422_available, clgd_speed_changed, clgd_force_redraw, - clgd_add_status_info + clgd_add_status_info, + NULL }; device_t gd5429_device = { "Cirrus Logic GD5429", - // DEVICE_NOT_WORKING, + DEVICE_NOT_WORKING, 0, gd5429_init, clgd_close, + NULL, gd5429_available, clgd_speed_changed, clgd_force_redraw, - clgd_add_status_info + clgd_add_status_info, + NULL }; device_t gd5430_device = { "Cirrus Logic GD5430", - // DEVICE_NOT_WORKING, + DEVICE_NOT_WORKING, 0, gd5430_init, clgd_close, + NULL, gd5430_available, clgd_speed_changed, clgd_force_redraw, - clgd_add_status_info + clgd_add_status_info, + NULL }; device_t dia5430_device = { "Diamond CL-GD5430", - // DEVICE_NOT_WORKING, + DEVICE_NOT_WORKING, 0, dia5430_init, clgd_close, + NULL, dia5430_available, clgd_speed_changed, clgd_force_redraw, - clgd_add_status_info + clgd_add_status_info, + NULL }; device_t gd5434_device = { "Cirrus Logic GD5434", - // DEVICE_NOT_WORKING, + DEVICE_NOT_WORKING, 0, gd5434_init, clgd_close, + NULL, gd5434_available, clgd_speed_changed, clgd_force_redraw, - clgd_add_status_info + clgd_add_status_info, + NULL }; device_t gd5436_device = { "Cirrus Logic GD5436", - // DEVICE_NOT_WORKING, + DEVICE_NOT_WORKING, 0, gd5436_init, clgd_close, + NULL, gd5436_available, clgd_speed_changed, clgd_force_redraw, - clgd_add_status_info + clgd_add_status_info, + NULL }; device_t gd5440_device = { "Cirrus Logic GD5440", - // DEVICE_NOT_WORKING, + DEVICE_NOT_WORKING, 0, gd5440_init, clgd_close, + NULL, gd5440_available, clgd_speed_changed, clgd_force_redraw, - clgd_add_status_info + clgd_add_status_info, + NULL }; device_t gd5446_device = { "Cirrus Logic GD5446", - // DEVICE_NOT_WORKING, + DEVICE_NOT_WORKING, 0, gd5446_init, clgd_close, + NULL, gd5446_available, clgd_speed_changed, clgd_force_redraw, - clgd_add_status_info + clgd_add_status_info, + NULL }; device_t gd6235_device = { "Cirrus Logic GD6235", - // DEVICE_NOT_WORKING, + DEVICE_NOT_WORKING, 0, gd6235_init, clgd_close, + NULL, gd6235_available, clgd_speed_changed, clgd_force_redraw, - clgd_add_status_info + clgd_add_status_info, + NULL }; diff --git a/src/video/vid_colorplus.c b/src/video/vid_colorplus.c index 0c5595912..efa4d9975 100644 --- a/src/video/vid_colorplus.c +++ b/src/video/vid_colorplus.c @@ -365,7 +365,7 @@ void colorplus_init(colorplus_t *colorplus) cga_init(&colorplus->cga); } -void *colorplus_standalone_init() +void *colorplus_standalone_init(device_t *info) { int display_type; @@ -445,10 +445,10 @@ static device_config_t colorplus_config[] = device_t colorplus_device = { "Colorplus", - 0, + 0, 0, colorplus_standalone_init, colorplus_close, - NULL, + NULL, NULL, colorplus_speed_changed, NULL, NULL, diff --git a/src/video/vid_ega.c b/src/video/vid_ega.c index e9da11bd2..445ce7453 100644 --- a/src/video/vid_ega.c +++ b/src/video/vid_ega.c @@ -9,7 +9,7 @@ * Emulation of the EGA, Chips & Technologies SuperEGA, and * AX JEGA graphics cards. * - * Version: @(#)vid_ega.c 1.0.4 2017/09/24 + * Version: @(#)vid_ega.c 1.0.5 2017/10/04 * * Authors: Sarah Walker, * Miran Grca, @@ -1121,7 +1121,7 @@ void *cpqega_standalone_init() return ega; } -void *sega_standalone_init() +void *sega_standalone_init(device_t *info) { ega_t *ega = malloc(sizeof(ega_t)); memset(ega, 0, sizeof(ega_t)); @@ -1255,7 +1255,7 @@ static void LoadFontxFile(wchar_t *fname) fclose(mfile); } -void *jega_standalone_init() +void *jega_standalone_init(device_t *info) { ega_t *ega = (ega_t *) sega_standalone_init(); @@ -1268,17 +1268,17 @@ void *jega_standalone_init() } #endif -static int ega_standalone_available() +static int ega_standalone_available(void) { return rom_present(L"roms/video/ega/ibm_6277356_ega_card_u44_27128.bin"); } -static int cpqega_standalone_available() +static int cpqega_standalone_available(void) { return rom_present(L"roms/video/ega/108281-001.bin"); } -static int sega_standalone_available() +static int sega_standalone_available(void) { return rom_present(L"roms/video/ega/lega.vbi"); } @@ -1326,8 +1326,10 @@ device_t ega_device = { "EGA", 0, + 0, ega_standalone_init, ega_close, + NULL, ega_standalone_available, ega_speed_changed, NULL, @@ -1339,8 +1341,10 @@ device_t cpqega_device = { "Compaq EGA", 0, + 0, cpqega_standalone_init, ega_close, + NULL, cpqega_standalone_available, ega_speed_changed, NULL, @@ -1352,8 +1356,10 @@ device_t sega_device = { "SuperEGA", 0, + 0, sega_standalone_init, ega_close, + NULL, sega_standalone_available, ega_speed_changed, NULL, @@ -1366,8 +1372,10 @@ device_t jega_device = { "AX JEGA", 0, + 0, jega_standalone_init, ega_close, + NULL, sega_standalone_available, ega_speed_changed, NULL, diff --git a/src/video/vid_et4000.c b/src/video/vid_et4000.c index 867157f75..12aeb8f27 100644 --- a/src/video/vid_et4000.c +++ b/src/video/vid_et4000.c @@ -143,7 +143,7 @@ void et4000_recalctimings(svga_t *svga) } } -void *et4000_init() +void *et4000_init(device_t *info) { et4000_t *et4000 = malloc(sizeof(et4000_t)); memset(et4000, 0, sizeof(et4000_t)); @@ -161,7 +161,7 @@ void *et4000_init() return et4000; } -static int et4000_available() +static int et4000_available(void) { return rom_present(L"roms/video/et4000/et4000.BIN"); } @@ -200,8 +200,10 @@ device_t et4000_device = { "Tseng Labs ET4000AX", 0, + 0, et4000_init, et4000_close, + NULL, et4000_available, et4000_speed_changed, et4000_force_redraw, diff --git a/src/video/vid_et4000w32.c b/src/video/vid_et4000w32.c index 6a92a0856..e5942c614 100644 --- a/src/video/vid_et4000w32.c +++ b/src/video/vid_et4000w32.c @@ -1140,7 +1140,7 @@ void et4000w32p_pci_write(int func, int addr, uint8_t val, void *p) } } -void *et4000w32p_init() +void *et4000w32p_init(device_t *info) { int vram_size; et4000w32p_t *et4000 = malloc(sizeof(et4000w32p_t)); @@ -1189,7 +1189,7 @@ void *et4000w32p_init() return et4000; } -int et4000w32p_available() +int et4000w32p_available(void) { return rom_present(L"roms/video/et4000w32/et4000w32.bin"); } @@ -1262,8 +1262,10 @@ device_t et4000w32p_device = { "Tseng Labs ET4000/w32p", 0, + 0, et4000w32p_init, et4000w32p_close, + NULL, et4000w32p_available, et4000w32p_speed_changed, et4000w32p_force_redraw, diff --git a/src/video/vid_genius.c b/src/video/vid_genius.c index fc0d882e3..6411125d2 100644 --- a/src/video/vid_genius.c +++ b/src/video/vid_genius.c @@ -553,7 +553,7 @@ void genius_poll(void *p) } } -void *genius_init() +void *genius_init(device_t *info) { int c; genius_t *genius = malloc(sizeof(genius_t)); @@ -609,7 +609,7 @@ void genius_close(void *p) free(genius); } -static int genius_available() +static int genius_available(void) { return rom_present(L"roms/video/genius/8x12.bin"); } @@ -624,11 +624,13 @@ void genius_speed_changed(void *p) device_t genius_device = { "Genius VHR", - 0, + 0, 0, genius_init, genius_close, + NULL, genius_available, genius_speed_changed, + NULL, NULL, NULL }; diff --git a/src/video/vid_hercules.c b/src/video/vid_hercules.c index 108527719..cf50cb6d6 100644 --- a/src/video/vid_hercules.c +++ b/src/video/vid_hercules.c @@ -316,7 +316,8 @@ void hercules_poll(void *p) } } -void *hercules_init() + +void *hercules_init(device_t *info) { int c; hercules_t *hercules = malloc(sizeof(hercules_t)); @@ -408,16 +409,17 @@ static device_config_t hercules_config[] = device_t hercules_device = { "Hercules", - 0, + 0, 0, hercules_init, hercules_close, + NULL, NULL, hercules_speed_changed, NULL, + NULL, #ifdef __unix NULL #else - NULL, hercules_config #endif }; diff --git a/src/video/vid_herculesplus.c b/src/video/vid_herculesplus.c index c747ceddd..1215a0dee 100644 --- a/src/video/vid_herculesplus.c +++ b/src/video/vid_herculesplus.c @@ -662,7 +662,7 @@ void herculesplus_poll(void *p) } } -void *herculesplus_init() +void *herculesplus_init(device_t *info) { int c; herculesplus_t *herculesplus = malloc(sizeof(herculesplus_t)); @@ -714,11 +714,13 @@ void herculesplus_speed_changed(void *p) device_t herculesplus_device = { "Hercules Plus", - 0, + 0, 0, herculesplus_init, herculesplus_close, + NULL, NULL, herculesplus_speed_changed, NULL, + NULL, NULL }; diff --git a/src/video/vid_incolor.c b/src/video/vid_incolor.c index 0f7834d00..3aca991f7 100644 --- a/src/video/vid_incolor.c +++ b/src/video/vid_incolor.c @@ -1010,7 +1010,7 @@ void incolor_poll(void *p) } } -void *incolor_init() +void *incolor_init(device_t *info) { int c; incolor_t *incolor = malloc(sizeof(incolor_t)); @@ -1061,11 +1061,14 @@ void incolor_speed_changed(void *p) device_t incolor_device = { "Hercules InColor", - 0, + 0, 0, incolor_init, incolor_close, + NULL, NULL, incolor_speed_changed, NULL, + NULL, + NULL, NULL }; diff --git a/src/video/vid_mda.c b/src/video/vid_mda.c index f857779e2..3cc45400a 100644 --- a/src/video/vid_mda.c +++ b/src/video/vid_mda.c @@ -265,7 +265,8 @@ void mda_poll(void *p) } } -void *mda_init() + +void *mda_init(device_t *info) { int c; mda_t *mda = malloc(sizeof(mda_t)); @@ -357,16 +358,17 @@ static device_config_t mda_config[] = device_t mda_device = { "MDA", - 0, + 0, 0, mda_init, mda_close, + NULL, NULL, mda_speed_changed, NULL, + NULL, #ifdef __unix NULL #else - NULL, mda_config #endif }; diff --git a/src/video/vid_nv_riva128.c b/src/video/vid_nv_riva128.c index 31a593568..e8919731f 100644 --- a/src/video/vid_nv_riva128.c +++ b/src/video/vid_nv_riva128.c @@ -2828,7 +2828,8 @@ void riva128_ptimer_tick(void *p) riva128->nvenable = 1; } - void *riva128_init() + +void *riva128_init(device_t *info) { riva128_t *riva128 = malloc(sizeof(riva128_t)); memset(riva128, 0, sizeof(riva128_t)); @@ -2911,7 +2912,7 @@ void riva128_ptimer_tick(void *p) riva128->ptimer.clock_mul = 1; riva128->ptimer.clock_div = 1; - //Some bullshit default values so that the emulator won't shit itself trying to boot. These'll be overwritten by the video BIOS anyway. + //default values so that the emulator can boot. These'll be overwritten by the video BIOS anyway. riva128->pramdac.m_m = 0x03; riva128->pramdac.m_n = 0xc2; riva128->pramdac.m_p = 0x0d; @@ -2962,7 +2963,7 @@ void riva128_ptimer_tick(void *p) return riva128; } - void riva128_close(void *p) +void riva128_close(void *p) { riva128_t *riva128 = (riva128_t *)p; FILE *f = fopen("vram.dmp", "wb"); @@ -2974,12 +2975,12 @@ void riva128_ptimer_tick(void *p) free(riva128); } - int riva128_available() +int riva128_available(void) { return rom_present(L"roms/video/nv_riva128/Diamond_V330_rev-e.vbi"); } - void riva128_speed_changed(void *p) +void riva128_speed_changed(void *p) { riva128_t *riva128 = (riva128_t *)p; @@ -3024,7 +3025,8 @@ device_config_t riva128_config[] = } }; -/* device_config_t riva128zx_config[] = +#if 0 +device_config_t riva128zx_config[] = { { .name = "memory", @@ -3057,14 +3059,17 @@ device_config_t riva128_config[] = { .type = -1 } -};*/ +}; +#endif device_t riva128_device = { "nVidia RIVA 128", 0, + 0, riva128_init, riva128_close, + NULL, riva128_available, riva128_speed_changed, riva128_force_redraw, @@ -3072,7 +3077,8 @@ device_t riva128_device = riva128_config }; - void *rivatnt_init() + +void *rivatnt_init(device_t *info) { riva128_t *riva128 = malloc(sizeof(riva128_t)); memset(riva128, 0, sizeof(riva128_t)); @@ -3139,7 +3145,7 @@ device_t riva128_device = riva128->pci_card = pci_add_card(PCI_ADD_VIDEO, riva128_pci_read, rivatnt_pci_write, riva128); - //Some bullshit default values so that the emulator won't shit itself trying to boot. These'll be overwritten by the video BIOS anyway. + //default values so that the emulator can boot. These'll be overwritten by the video BIOS anyway. riva128->pramdac.m_m = 0x03; riva128->pramdac.m_n = 0xc2; riva128->pramdac.m_p = 0x0d; @@ -3188,7 +3194,7 @@ device_t riva128_device = return riva128; } - void rivatnt_close(void *p) +void rivatnt_close(void *p) { riva128_t *riva128 = (riva128_t *)p; FILE *f = fopen("vram.dmp", "wb"); @@ -3200,33 +3206,33 @@ device_t riva128_device = free(riva128); } - int rivatnt_available() +int rivatnt_available(void) { return rom_present(L"roms/video/nv_riva128/NV4_diamond_revB.rom"); } - void rivatnt_speed_changed(void *p) +void rivatnt_speed_changed(void *p) { riva128_t *riva128 = (riva128_t *)p; svga_recalctimings(&riva128->svga); } - void rivatnt_force_redraw(void *p) +void rivatnt_force_redraw(void *p) { riva128_t *riva128 = (riva128_t *)p; riva128->svga.fullchange = changeframecount; } - void rivatnt_add_status_info(char *s, int max_len, void *p) +void rivatnt_add_status_info(char *s, int max_len, void *p) { riva128_t *riva128 = (riva128_t *)p; svga_add_status_info(s, max_len, &riva128->svga); } - device_config_t rivatnt_config[] = +device_config_t rivatnt_config[] = { { "memory", "Memory size", CONFIG_SELECTION, "", 16, @@ -3254,8 +3260,10 @@ device_t rivatnt_device = { "nVidia RIVA TNT", 0, + 0, rivatnt_init, rivatnt_close, + NULL, rivatnt_available, rivatnt_speed_changed, rivatnt_force_redraw, @@ -3263,7 +3271,7 @@ device_t rivatnt_device = rivatnt_config }; - void *rivatnt2_init() +void *rivatnt2_init(device_t *info) { riva128_t *riva128 = malloc(sizeof(riva128_t)); memset(riva128, 0, sizeof(riva128_t)); @@ -3343,7 +3351,7 @@ device_t rivatnt_device = riva128->pci_card = pci_add_card(PCI_ADD_VIDEO, riva128_pci_read, rivatnt_pci_write, riva128); - //Some bullshit default values so that the emulator won't shit itself trying to boot. These'll be overwritten by the video BIOS anyway. + //default values so that the emulator can boot. These'll be overwritten by the video BIOS anyway. riva128->pramdac.m_m = 0x03; riva128->pramdac.m_n = 0xc2; riva128->pramdac.m_p = 0x0d; @@ -3392,7 +3400,7 @@ device_t rivatnt_device = return riva128; } - void rivatnt2_close(void *p) +void rivatnt2_close(void *p) { riva128_t *riva128 = (riva128_t *)p; FILE *f = fopen("vram.dmp", "wb"); @@ -3404,33 +3412,33 @@ device_t rivatnt_device = free(riva128); } - int rivatnt2_available() +int rivatnt2_available(void) { return rom_present(L"roms/video/nv_riva128/NV5diamond.bin") || rom_present(L"roms/video/nv_riva128/inno3d64bit.BIN") || rom_present(L"roms/video/nv_riva128/creative.BIN"); } - void rivatnt2_speed_changed(void *p) +void rivatnt2_speed_changed(void *p) { riva128_t *riva128 = (riva128_t *)p; svga_recalctimings(&riva128->svga); } - void rivatnt2_force_redraw(void *p) +void rivatnt2_force_redraw(void *p) { riva128_t *riva128 = (riva128_t *)p; riva128->svga.fullchange = changeframecount; } - void rivatnt2_add_status_info(char *s, int max_len, void *p) +void rivatnt2_add_status_info(char *s, int max_len, void *p) { riva128_t *riva128 = (riva128_t *)p; svga_add_status_info(s, max_len, &riva128->svga); } - device_config_t rivatnt2_config[] = +device_config_t rivatnt2_config[] = { { "model", "Card model", CONFIG_SELECTION, "", 0, @@ -3475,8 +3483,10 @@ device_t rivatnt2_device = { "nVidia RIVA TNT2", 0, + 0, rivatnt2_init, rivatnt2_close, + NULL, rivatnt2_available, rivatnt2_speed_changed, rivatnt2_force_redraw, diff --git a/src/video/vid_olivetti_m24.c b/src/video/vid_olivetti_m24.c index b031a8161..e26fe499c 100644 --- a/src/video/vid_olivetti_m24.c +++ b/src/video/vid_olivetti_m24.c @@ -449,7 +449,9 @@ void m24_poll(void *p) } } -void *m24_init() + +static void * +m24_init(device_t *info) { m24_t *m24 = malloc(sizeof(m24_t)); memset(m24, 0, sizeof(m24_t)); @@ -463,7 +465,9 @@ void *m24_init() return m24; } -void m24_close(void *p) + +static void +m24_close(void *p) { m24_t *m24 = (m24_t *)p; @@ -471,21 +475,23 @@ void m24_close(void *p) free(m24); } -void m24_speed_changed(void *p) + +static void +m24_speed_changed(void *p) { m24_t *m24 = (m24_t *)p; m24_recalctimings(m24); } + device_t m24_device = { "Olivetti M24 (video)", - 0, + 0, 0, m24_init, m24_close, - NULL, - m24_speed_changed, - NULL, + NULL, NULL, m24_speed_changed, + NULL, NULL, NULL, NULL, NULL }; diff --git a/src/video/vid_oti067.c b/src/video/vid_oti067.c index 5e7edf1f7..f4d16c40b 100644 --- a/src/video/vid_oti067.c +++ b/src/video/vid_oti067.c @@ -187,29 +187,29 @@ void *oti067_common_init(wchar_t *bios_fn, int vram_size, int chip_id) return oti067; } -void *oti067_init() +void *oti067_init(device_t *info) { int vram_size = device_get_config_int("memory"); return oti067_common_init(L"roms/video/oti/bios.bin", vram_size, 2); } -void *oti077_init() +void *oti077_init(device_t *info) { int vram_size = device_get_config_int("memory"); return oti067_common_init(L"roms/video/oti/oti077.vbi", vram_size, 5); } -static int oti067_available() +static int oti067_available(void) { return rom_present(L"roms/video/oti/bios.bin"); } -static int oti077_available() +static int oti077_available(void) { return rom_present(L"roms/video/oti/oti077.vbi"); } -void oti067_close(void *p) +static void oti067_close(void *p) { oti067_t *oti067 = (oti067_t *)p; @@ -218,21 +218,21 @@ void oti067_close(void *p) free(oti067); } -void oti067_speed_changed(void *p) +static void oti067_speed_changed(void *p) { oti067_t *oti067 = (oti067_t *)p; svga_recalctimings(&oti067->svga); } -void oti067_force_redraw(void *p) +static void oti067_force_redraw(void *p) { oti067_t *oti067 = (oti067_t *)p; oti067->svga.fullchange = changeframecount; } -void oti067_add_status_info(char *s, int max_len, void *p) +static void oti067_add_status_info(char *s, int max_len, void *p) { oti067_t *oti067 = (oti067_t *)p; @@ -288,8 +288,10 @@ device_t oti067_device = { "Oak OTI-067", 0, + 0, oti067_init, oti067_close, + NULL, oti067_available, oti067_speed_changed, oti067_force_redraw, @@ -300,8 +302,10 @@ device_t oti077_device = { "Oak OTI-077", 0, + 0, oti077_init, oti067_close, + NULL, oti077_available, oti067_speed_changed, oti067_force_redraw, diff --git a/src/video/vid_paradise.c b/src/video/vid_paradise.c index 43905a4f3..62fa14d47 100644 --- a/src/video/vid_paradise.c +++ b/src/video/vid_paradise.c @@ -254,7 +254,8 @@ uint8_t paradise_read(uint32_t addr, void *p) return svga_read_linear(addr, ¶dise->svga); } -void *paradise_pvga1a_init() + +void *paradise_pvga1a_init(device_t *info) { paradise_t *paradise = malloc(sizeof(paradise_t)); svga_t *svga = ¶dise->svga; @@ -287,7 +288,7 @@ void *paradise_pvga1a_init() return paradise; } -void *paradise_wd90c11_init() +void *paradise_wd90c11_init(device_t *info) { paradise_t *paradise = malloc(sizeof(paradise_t)); svga_t *svga = ¶dise->svga; @@ -322,18 +323,18 @@ void *paradise_wd90c11_init() return paradise; } -static void *paradise_pvga1a_pc2086_init() +static void *paradise_pvga1a_pc2086_init(device_t *info) { - paradise_t *paradise = paradise_pvga1a_init(); + paradise_t *paradise = paradise_pvga1a_init(info); if (paradise) rom_init(¶dise->bios_rom, L"roms/machines/pc2086/40186.ic171", 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); return paradise; } -static void *paradise_pvga1a_pc3086_init() +static void *paradise_pvga1a_pc3086_init(device_t *info) { - paradise_t *paradise = paradise_pvga1a_init(); + paradise_t *paradise = paradise_pvga1a_init(info); if (paradise) rom_init(¶dise->bios_rom, L"roms/machines/pc3086/c000.bin", 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); @@ -341,9 +342,9 @@ static void *paradise_pvga1a_pc3086_init() return paradise; } -static void *paradise_wd90c11_megapc_init() +static void *paradise_wd90c11_megapc_init(device_t *info) { - paradise_t *paradise = paradise_wd90c11_init(); + paradise_t *paradise = paradise_wd90c11_init(info); if (paradise) rom_init_interleaved(¶dise->bios_rom, @@ -354,7 +355,7 @@ static void *paradise_wd90c11_megapc_init() return paradise; } -static int paradise_wd90c11_standalone_available() +static int paradise_wd90c11_standalone_available(void) { return rom_present(L"roms/machines/megapc/41651-bios lo.u18") && rom_present(L"roms/machines/megapc/211253-bios hi.u19"); } @@ -389,13 +390,16 @@ void paradise_add_status_info(char *s, int max_len, void *p) svga_add_status_info(s, max_len, ¶dise->svga); } + device_t paradise_pvga1a_pc2086_device = { "Paradise PVGA1A (Amstrad PC2086)", 0, + 0, paradise_pvga1a_pc2086_init, paradise_close, NULL, + NULL, paradise_speed_changed, paradise_force_redraw, paradise_add_status_info @@ -404,8 +408,10 @@ device_t paradise_pvga1a_pc3086_device = { "Paradise PVGA1A (Amstrad PC3086)", 0, + 0, paradise_pvga1a_pc3086_init, paradise_close, + NULL, NULL, paradise_speed_changed, paradise_force_redraw, @@ -415,8 +421,10 @@ device_t paradise_wd90c11_megapc_device = { "Paradise WD90C11 (Amstrad MegaPC)", 0, + 0, paradise_wd90c11_megapc_init, paradise_close, + NULL, NULL, paradise_speed_changed, paradise_force_redraw, @@ -426,8 +434,10 @@ device_t paradise_wd90c11_device = { "Paradise WD90C11", 0, + 0, paradise_wd90c11_megapc_init, paradise_close, + NULL, paradise_wd90c11_standalone_available, paradise_speed_changed, paradise_force_redraw, diff --git a/src/video/vid_pc1512.c b/src/video/vid_pc1512.c index 566c99743..57222148f 100644 --- a/src/video/vid_pc1512.c +++ b/src/video/vid_pc1512.c @@ -448,7 +448,8 @@ static void pc1512_poll(void *p) } } -static void *pc1512_init() + +static void *pc1512_init(device_t *info) { pc1512_t *pc1512 = malloc(sizeof(pc1512_t)); memset(pc1512, 0, sizeof(pc1512_t)); @@ -483,9 +484,10 @@ static void pc1512_speed_changed(void *p) device_t pc1512_device = { "Amstrad PC1512 (video)", - 0, + 0, 0, pc1512_init, pc1512_close, + NULL, NULL, pc1512_speed_changed, NULL, diff --git a/src/video/vid_pc1640.c b/src/video/vid_pc1640.c index b5f63d83c..44eb6970e 100644 --- a/src/video/vid_pc1640.c +++ b/src/video/vid_pc1640.c @@ -123,7 +123,8 @@ void pc1640_poll(void *p) } } -void *pc1640_init() + +void *pc1640_init(device_t *info) { pc1640_t *pc1640 = malloc(sizeof(pc1640_t)); cga_t *cga = &pc1640->cga; @@ -145,7 +146,7 @@ void *pc1640_init() return pc1640; } -void pc1640_close(void *p) +static void pc1640_close(void *p) { pc1640_t *pc1640 = (pc1640_t *)p; @@ -153,7 +154,7 @@ void pc1640_close(void *p) free(pc1640); } -void pc1640_speed_changed(void *p) +static void pc1640_speed_changed(void *p) { pc1640_t *pc1640 = (pc1640_t *)p; @@ -163,9 +164,10 @@ void pc1640_speed_changed(void *p) device_t pc1640_device = { "Amstrad PC1640 (video)", - 0, + 0, 0, pc1640_init, pc1640_close, + NULL, NULL, pc1640_speed_changed, NULL, diff --git a/src/video/vid_pc200.c b/src/video/vid_pc200.c index 38c1e5201..e3d1da2ed 100644 --- a/src/video/vid_pc200.c +++ b/src/video/vid_pc200.c @@ -110,7 +110,8 @@ uint8_t pc200_in(uint16_t addr, void *p) return cga_in(addr, cga); } -void *pc200_init() + +static void *pc200_init(device_t *info) { pc200_t *pc200 = malloc(sizeof(pc200_t)); cga_t *cga = &pc200->cga; @@ -126,7 +127,7 @@ void *pc200_init() return pc200; } -void pc200_close(void *p) +static void pc200_close(void *p) { pc200_t *pc200 = (pc200_t *)p; @@ -134,7 +135,7 @@ void pc200_close(void *p) free(pc200); } -void pc200_speed_changed(void *p) +static void pc200_speed_changed(void *p) { pc200_t *pc200 = (pc200_t *)p; @@ -144,9 +145,10 @@ void pc200_speed_changed(void *p) device_t pc200_device = { "Amstrad PC200 (video)", - 0, + 0, 0, pc200_init, pc200_close, + NULL, NULL, pc200_speed_changed, NULL, diff --git a/src/video/vid_pcjr.c b/src/video/vid_pcjr.c index 5853cd3ee..02b9fd428 100644 --- a/src/video/vid_pcjr.c +++ b/src/video/vid_pcjr.c @@ -517,7 +517,8 @@ void pcjr_poll(void *p) } } -static void *pcjr_video_init() + +static void *pcjr_video_init(device_t *info) { int display_type; pcjr_t *pcjr = malloc(sizeof(pcjr_t)); @@ -551,9 +552,10 @@ static void pcjr_speed_changed(void *p) device_t pcjr_video_device = { "IBM PCjr (video)", - 0, + 0, 0, pcjr_video_init, pcjr_video_close, + NULL, NULL, pcjr_speed_changed, NULL, @@ -586,9 +588,10 @@ static device_config_t pcjr_config[] = static device_t pcjr_device = { "IBM PCjr", - 0, + 0, 0, NULL, NULL, + NULL, NULL, NULL, NULL, diff --git a/src/video/vid_ps1_svga.c b/src/video/vid_ps1_svga.c index a672503c6..5b90805fb 100644 --- a/src/video/vid_ps1_svga.c +++ b/src/video/vid_ps1_svga.c @@ -122,7 +122,8 @@ uint8_t ps1_m2121_svga_in(uint16_t addr, void *p) return temp; } -void *ps1_m2121_svga_init() + +static void *ps1_m2121_svga_init(device_t *info) { ps1_m2121_svga_t *ps1 = malloc(sizeof(ps1_m2121_svga_t)); memset(ps1, 0, sizeof(ps1_m2121_svga_t)); @@ -176,10 +177,11 @@ void ps1_m2121_svga_add_status_info(char *s, int max_len, void *p) device_t ps1_m2121_svga_device = { "PS/1 Model 2121 SVGA", - 0, + 0, 0, ps1_m2121_svga_init, ps1_m2121_svga_close, NULL, + NULL, ps1_m2121_svga_speed_changed, ps1_m2121_svga_force_redraw, ps1_m2121_svga_add_status_info diff --git a/src/video/vid_s3.c b/src/video/vid_s3.c index 8163a3bac..a726b901c 100644 --- a/src/video/vid_s3.c +++ b/src/video/vid_s3.c @@ -2216,29 +2216,30 @@ void *s3_vision864_init(wchar_t *bios_fn) return s3; } -void *s3_bahamas64_init() + +static void *s3_bahamas64_init(device_t *info) { s3_t *s3 = s3_vision864_init(L"roms/video/s3/bahamas64.BIN"); return s3; } -void *s3_phoenix_vision864_init() +static void *s3_phoenix_vision864_init(device_t *info) { s3_t *s3 = s3_vision864_init(L"roms/video/s3/86c864p.bin"); return s3; } -int s3_bahamas64_available() +static int s3_bahamas64_available(void) { return rom_present(L"roms/video/s3/bahamas64.BIN"); } -int s3_phoenix_vision864_available() +static int s3_phoenix_vision864_available(void) { return rom_present(L"roms/video/s3/86c864p.bin"); } -void *s3_phoenix_trio32_init() +static void *s3_phoenix_trio32_init(device_t *info) { s3_t *s3 = s3_init(L"roms/video/s3/86C732P.bin", S3_TRIO32); @@ -2253,12 +2254,12 @@ void *s3_phoenix_trio32_init() return s3; } -int s3_phoenix_trio32_available() +static int s3_phoenix_trio32_available(void) { return rom_present(L"roms/video/s3/86C732P.bin"); } -void *s3_trio64_init(wchar_t *bios_fn) +static void *s3_trio64_init(wchar_t *bios_fn) { s3_t *s3 = s3_init(bios_fn, S3_TRIO64); @@ -2272,40 +2273,40 @@ void *s3_trio64_init(wchar_t *bios_fn) return s3; } -void *s3_9fx_init() +static void *s3_9fx_init(device_t *info) { s3_t *s3 = s3_trio64_init(L"roms/video/s3/s3_764.bin"); return s3; } -void *s3_phoenix_trio64_init() +static void *s3_phoenix_trio64_init(device_t *info) { s3_t *s3 = s3_trio64_init(L"roms/video/s3/86C764X1.bin"); return s3; } -void *s3_diamond_stealth64_init() +static void *s3_diamond_stealth64_init(device_t *info) { s3_t *s3 = s3_trio64_init(L"roms/video/s3/STEALT64.BIN"); return s3; } -int s3_9fx_available() +static int s3_9fx_available(void) { return rom_present(L"roms/video/s3/s3_764.bin"); } -int s3_phoenix_trio64_available() +static int s3_phoenix_trio64_available(void) { return rom_present(L"roms/video/s3/86c764x1.bin"); } -int s3_diamond_stealth64_available() +static int s3_diamond_stealth64_available(void) { return rom_present(L"roms/video/s3/STEALT64.BIN"); } -void s3_close(void *p) +static void s3_close(void *p) { s3_t *s3 = (s3_t *)p; @@ -2318,21 +2319,21 @@ void s3_close(void *p) free(s3); } -void s3_speed_changed(void *p) +static void s3_speed_changed(void *p) { s3_t *s3 = (s3_t *)p; svga_recalctimings(&s3->svga); } -void s3_force_redraw(void *p) +static void s3_force_redraw(void *p) { s3_t *s3 = (s3_t *)p; s3->svga.fullchange = changeframecount; } -void s3_add_status_info(char *s, int max_len, void *p) +static void s3_add_status_info(char *s, int max_len, void *p) { s3_t *s3 = (s3_t *)p; char temps[256]; @@ -2466,8 +2467,10 @@ device_t s3_bahamas64_device = { "Paradise Bahamas 64 (S3 Vision864)", 0, + 0, s3_bahamas64_init, s3_close, + NULL, s3_bahamas64_available, s3_speed_changed, s3_force_redraw, @@ -2479,8 +2482,10 @@ device_t s3_9fx_device = { "Number 9 9FX (S3 Trio64)", 0, + 0, s3_9fx_init, s3_close, + NULL, s3_9fx_available, s3_speed_changed, s3_force_redraw, @@ -2492,8 +2497,10 @@ device_t s3_phoenix_trio32_device = { "Phoenix S3 Trio32", 0, + 0, s3_phoenix_trio32_init, s3_close, + NULL, s3_phoenix_trio32_available, s3_speed_changed, s3_force_redraw, @@ -2505,8 +2512,10 @@ device_t s3_phoenix_trio64_device = { "Phoenix S3 Trio64", 0, + 0, s3_phoenix_trio64_init, s3_close, + NULL, s3_phoenix_trio64_available, s3_speed_changed, s3_force_redraw, @@ -2518,8 +2527,10 @@ device_t s3_phoenix_vision864_device = { "Phoenix S3 Vision864", 0, + 0, s3_phoenix_vision864_init, s3_close, + NULL, s3_phoenix_vision864_available, s3_speed_changed, s3_force_redraw, @@ -2531,8 +2542,10 @@ device_t s3_diamond_stealth64_device = { "S3 Trio64 (Diamond Stealth64 DRAM)", 0, + 0, s3_diamond_stealth64_init, s3_close, + NULL, s3_diamond_stealth64_available, s3_speed_changed, s3_force_redraw, diff --git a/src/video/vid_s3_virge.c b/src/video/vid_s3_virge.c index efb1cc1fe..3707f677b 100644 --- a/src/video/vid_s3_virge.c +++ b/src/video/vid_s3_virge.c @@ -3751,7 +3751,7 @@ static void s3_virge_pci_write(int func, int addr, uint8_t val, void *p) } } -static void *s3_virge_init() +static void *s3_virge_init(device_t *info) { virge_t *virge = malloc(sizeof(virge_t)); memset(virge, 0, sizeof(virge_t)); @@ -3846,7 +3846,7 @@ static void *s3_virge_init() return virge; } -static void *s3_virge_988_init() +static void *s3_virge_988_init(device_t *info) { virge_t *virge = malloc(sizeof(virge_t)); memset(virge, 0, sizeof(virge_t)); @@ -4035,12 +4035,12 @@ static void *s3_virge_375_init(wchar_t *romfn) return virge; } -static void *s3_virge_375_1_init() +static void *s3_virge_375_1_init(device_t *info) { return s3_virge_375_init(L"roms/video/s3virge/86c375_1.bin"); } -static void *s3_virge_375_4_init() +static void *s3_virge_375_4_init(device_t *info) { return s3_virge_375_init(L"roms/video/s3virge/86c375_4.bin"); } @@ -4068,22 +4068,22 @@ static void s3_virge_close(void *p) free(virge); } -static int s3_virge_available() +static int s3_virge_available(void) { return rom_present(L"roms/video/s3virge/s3virge.bin"); } -static int s3_virge_988_available() +static int s3_virge_988_available(void) { return rom_present(L"roms/video/s3virge/diamondstealth3000.VBI"); } -static int s3_virge_375_1_available() +static int s3_virge_375_1_available(void) { return rom_present(L"roms/video/s3virge/86c375_1.bin"); } -static int s3_virge_375_4_available() +static int s3_virge_375_4_available(void) { return rom_present(L"roms/video/s3virge/86c375_4.bin"); } @@ -4154,8 +4154,10 @@ device_t s3_virge_device = { "Diamond Stealth 3D 2000 (S3 ViRGE)", 0, + 0, s3_virge_init, s3_virge_close, + NULL, s3_virge_available, s3_virge_speed_changed, s3_virge_force_redraw, @@ -4167,8 +4169,10 @@ device_t s3_virge_988_device = { "Diamond Stealth 3D 3000 (S3 ViRGE/VX)", 0, + 0, s3_virge_988_init, s3_virge_close, + NULL, s3_virge_988_available, s3_virge_speed_changed, s3_virge_force_redraw, @@ -4180,8 +4184,10 @@ device_t s3_virge_375_device = { "S3 ViRGE/DX", 0, + 0, s3_virge_375_1_init, s3_virge_close, + NULL, s3_virge_375_1_available, s3_virge_speed_changed, s3_virge_force_redraw, @@ -4193,8 +4199,10 @@ device_t s3_virge_375_4_device = { "S3 ViRGE/DX (VBE 2.0)", 0, + 0, s3_virge_375_4_init, s3_virge_close, + NULL, s3_virge_375_4_available, s3_virge_speed_changed, s3_virge_force_redraw, diff --git a/src/video/vid_tandy.c b/src/video/vid_tandy.c index 082e4a378..8f4977ae7 100644 --- a/src/video/vid_tandy.c +++ b/src/video/vid_tandy.c @@ -585,7 +585,8 @@ void tandy_poll(void *p) } } -void *tandy_init() + +static void *tandy_init(device_t *info) { int display_type; tandy_t *tandy = malloc(sizeof(tandy_t)); @@ -610,14 +611,14 @@ void *tandy_init() return tandy; } -void tandy_close(void *p) +static void tandy_close(void *p) { tandy_t *tandy = (tandy_t *)p; free(tandy); } -void tandy_speed_changed(void *p) +static void tandy_speed_changed(void *p) { tandy_t *tandy = (tandy_t *)p; @@ -628,11 +629,14 @@ device_t tandy_device = { "Tandy 1000 (video)", 0, + 0, tandy_init, tandy_close, + NULL, NULL, tandy_speed_changed, NULL, + NULL, NULL }; @@ -662,8 +666,9 @@ static device_config_t tandy_config[] = static device_t tandy1000_device = { "Tandy 1000", - 0, + 0, 0, NULL, + NULL, NULL, NULL, NULL, @@ -674,8 +679,9 @@ static device_t tandy1000_device = static device_t tandy1000hx_device = { "Tandy 1000HX", - 0, + 0, 0, NULL, + NULL, NULL, NULL, NULL, diff --git a/src/video/vid_tandysl.c b/src/video/vid_tandysl.c index 4acc53b72..fabdb51d3 100644 --- a/src/video/vid_tandysl.c +++ b/src/video/vid_tandysl.c @@ -654,7 +654,8 @@ static void tandysl_poll(void *p) } } -static void *tandysl_init() + +static void *tandysl_init(device_t *info) { tandysl_t *tandy = malloc(sizeof(tandysl_t)); memset(tandy, 0, sizeof(tandysl_t)); @@ -694,10 +695,13 @@ device_t tandysl_device = { "Tandy 1000SL (video)", 0, + 0, tandysl_init, tandysl_close, + NULL, NULL, tandysl_speed_changed, NULL, + NULL, NULL }; diff --git a/src/video/vid_tgui9440.c b/src/video/vid_tgui9440.c index 63fe7e749..2fc800f1b 100644 --- a/src/video/vid_tgui9440.c +++ b/src/video/vid_tgui9440.c @@ -507,7 +507,7 @@ void tgui_pci_write(int func, int addr, uint8_t val, void *p) } } -void *tgui9440_init() +void *tgui9440_init(device_t *info) { tgui_t *tgui = malloc(sizeof(tgui_t)); memset(tgui, 0, sizeof(tgui_t)); @@ -539,7 +539,7 @@ void *tgui9440_init() return tgui; } -static int tgui9440_available() +static int tgui9440_available(void) { return rom_present(L"roms/video/tgui9440/9440.vbi"); } @@ -1275,8 +1275,10 @@ device_t tgui9440_device = { "Trident TGUI 9440", 0, + 0, tgui9440_init, tgui_close, + NULL, tgui9440_available, tgui_speed_changed, tgui_force_redraw, diff --git a/src/video/vid_tvga.c b/src/video/vid_tvga.c index de78da9af..536437f82 100644 --- a/src/video/vid_tvga.c +++ b/src/video/vid_tvga.c @@ -282,7 +282,8 @@ void tvga_recalctimings(svga_t *svga) } } -void *tvga8900d_init() + +static void *tvga8900d_init(device_t *info) { tvga_t *tvga = malloc(sizeof(tvga_t)); memset(tvga, 0, sizeof(tvga_t)); @@ -303,7 +304,7 @@ void *tvga8900d_init() return tvga; } -static int tvga8900d_available() +static int tvga8900d_available(void) { return rom_present(L"roms/video/tvga/TRIDENT.BIN"); } @@ -367,8 +368,10 @@ device_t tvga8900d_device = { "Trident TVGA 8900D", 0, + 0, tvga8900d_init, tvga_close, + NULL, tvga8900d_available, tvga_speed_changed, tvga_force_redraw, diff --git a/src/video/vid_vga.c b/src/video/vid_vga.c index b8c4212d7..99f27b60b 100644 --- a/src/video/vid_vga.c +++ b/src/video/vid_vga.c @@ -84,7 +84,8 @@ uint8_t vga_in(uint16_t addr, void *p) return temp; } -void *vga_init() + +static void *vga_init(device_t *info) { vga_t *vga = malloc(sizeof(vga_t)); memset(vga, 0, sizeof(vga_t)); @@ -105,8 +106,9 @@ void *vga_init() return vga; } + #ifdef DEV_BRANCH -void *trigem_unk_init() +static void *trigem_unk_init(device_t *info) { vga_t *vga = malloc(sizeof(vga_t)); memset(vga, 0, sizeof(vga_t)); @@ -133,7 +135,7 @@ void *trigem_unk_init() #endif /*PS/1 uses a standard VGA controller, but with no option ROM*/ -void *ps1vga_init() +void *ps1vga_init(device_t *info) { vga_t *vga = malloc(sizeof(vga_t)); memset(vga, 0, sizeof(vga_t)); @@ -152,7 +154,7 @@ void *ps1vga_init() return vga; } -static int vga_available() +static int vga_available(void) { return rom_present(L"roms/video/vga/ibm_vga.bin"); } @@ -191,8 +193,10 @@ device_t vga_device = { "VGA", 0, + 0, vga_init, vga_close, + NULL, vga_available, vga_speed_changed, vga_force_redraw, @@ -203,8 +207,10 @@ device_t trigem_unk_device = { "VGA", 0, + 0, trigem_unk_init, vga_close, + NULL, vga_available, vga_speed_changed, vga_force_redraw, @@ -215,8 +221,10 @@ device_t ps1vga_device = { "PS/1 VGA", 0, + 0, ps1vga_init, vga_close, + NULL, vga_available, vga_speed_changed, vga_force_redraw, diff --git a/src/video/vid_voodoo.c b/src/video/vid_voodoo.c index ee2c478a9..a572f3a46 100644 --- a/src/video/vid_voodoo.c +++ b/src/video/vid_voodoo.c @@ -1,7 +1,6 @@ #include #include #include -//#include #include #include #include @@ -7460,7 +7459,8 @@ static void voodoo_speed_changed(void *p) // pclog("Voodoo read_time=%i write_time=%i burst_time=%i %08x %08x\n", voodoo->read_time, voodoo->write_time, voodoo->burst_time, voodoo->fbiInit1, voodoo->fbiInit4); } -void *voodoo_card_init() + +void *voodoo_card_init(void) { int c; voodoo_t *voodoo = malloc(sizeof(voodoo_t)); @@ -7597,7 +7597,7 @@ void *voodoo_card_init() return voodoo; } -void *voodoo_init() +void *voodoo_init(device_t *info) { voodoo_set_t *voodoo_set = malloc(sizeof(voodoo_set_t)); uint32_t tmuConfig = 1; @@ -7838,8 +7838,10 @@ device_t voodoo_device = { "3DFX Voodoo Graphics", DEVICE_PCI, + 0, voodoo_init, voodoo_close, + NULL, NULL, voodoo_speed_changed, NULL, diff --git a/src/video/vid_wy700.c b/src/video/vid_wy700.c index fa2cd3658..b3a816427 100644 --- a/src/video/vid_wy700.c +++ b/src/video/vid_wy700.c @@ -875,7 +875,8 @@ void wy700_poll(void *p) } } -void *wy700_init() + +void *wy700_init(device_t *info) { int c; wy700_t *wy700 = malloc(sizeof(wy700_t)); @@ -986,11 +987,13 @@ void wy700_speed_changed(void *p) device_t wy700_device = { "Wyse 700", - 0, + 0, 0, wy700_init, wy700_close, + NULL, NULL, wy700_speed_changed, NULL, + NULL, NULL }; diff --git a/src/video/video.h b/src/video/video.h index 38b998ef4..0291810dd 100644 --- a/src/video/video.h +++ b/src/video/video.h @@ -1,6 +1,9 @@ /* Copyright holders: Sarah Walker, Tenshi see COPYING for more details */ +#ifndef EMU_VIDEO_H +# define EMU_VIDEO_H + typedef struct { @@ -28,7 +31,9 @@ extern BITMAP *buffer, *buffer32; int video_card_available(int card); char *video_card_getname(int card); -struct device_t *video_card_getdevice(int card); +#ifdef EMU_DEVICE_H +device_t *video_card_getdevice(int card); +#endif int video_card_has_config(int card); int video_card_getid(char *s); int video_old_to_new(int card); @@ -122,3 +127,6 @@ void updatewindowsize(int x, int y); #ifdef ENABLE_VRAM_DUMP void svga_dump_vram(void); #endif + + +#endif /*EMU_VIDEO_H*/ diff --git a/src/win/86Box.rc b/src/win/86Box.rc index e4df2efb4..56c085e58 100644 --- a/src/win/86Box.rc +++ b/src/win/86Box.rc @@ -8,7 +8,7 @@ * * Windows resource script. * - * Version: @(#)86Box.rc 1.0.14 2017/10/01 + * Version: @(#)86Box.rc 1.0.15 2017/10/05 * * Authors: Miran Grca, * Fred N. van Kempen, @@ -40,7 +40,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US // Menu // -MAINMENU MENU DISCARDABLE +MainMenu MENU DISCARDABLE BEGIN POPUP "&Action" BEGIN @@ -157,13 +157,17 @@ BEGIN END END +StatusBarMenu MENU DISCARDABLE +BEGIN +END + ///////////////////////////////////////////////////////////////////////////// // // Accelerator // -MAINACCEL ACCELERATORS MOVEABLE PURE +MainAccel ACCELERATORS MOVEABLE PURE BEGIN #ifdef ENABLE_VRAM_DUMP VK_F1, IDM_DUMP_VRAM, CONTROL, VIRTKEY @@ -686,9 +690,7 @@ BEGIN IDS_2053 "Invalid number of sectors (valid values are between 1 and 63)" IDS_2054 "Invalid number of heads (valid values are between 1 and 16)" IDS_2055 "Invalid number of cylinders (valid values are between 1 and 266305)" -#if NOTUSED - IDS_2056 -#endif + IDS_2056 "No usable ROM images found!" IDS_2057 "(empty)" IDS_2058 "(host drive %c:)" IDS_2059 "Turbo" @@ -735,6 +737,7 @@ BEGIN IDS_2092 "Bus" IDS_2093 "DMA" IDS_2094 "KB" + IDS_2095 "Neither DirectDraw nor Direct3D available !" END STRINGTABLE DISCARDABLE @@ -807,10 +810,8 @@ BEGIN IDS_2150 "Thrustmaster Flight Control System" IDS_2151 "Disabled" IDS_2152 "None" -#if UNUSED - IDS_2153 - IDS_2154 -#endif + IDS_2153 "Unable to load Keyboard Accelerators!" + IDS_2154 "Unable to register Raw Input!" IDS_2155 "IRQ %i" IDS_2156 "%" PRIu64 IDS_2157 "%" PRIu64 " MB (CHS: %" PRIu64 ", %" PRIu64 ", %" PRIu64 ")" diff --git a/src/win/resource.h b/src/win/resource.h index 2f73ad4ed..6ae6aa9ab 100644 --- a/src/win/resource.h +++ b/src/win/resource.h @@ -9,11 +9,8 @@ * Windows resource defines. * * NOTE: FIXME: Strings 2176 and 2193 are same. - * NOTE: FIXME: string 2052 not in use. - * NOTE: FIXME: string 2095 not in use. - * NOTE: FIXME: strings 2153-2154 not in use. * - * Version: @(#)resource.h 1.0.9 2017/10/01 + * Version: @(#)resource.h 1.0.10 2017/10/05 * * Authors: Sarah Walker, * Miran Grca, @@ -211,7 +208,7 @@ #define IDS_2053 2053 // "Invalid number of sectors.." #define IDS_2054 2054 // "Invalid number of heads.." #define IDS_2055 2055 // "Invalid number of cylinders.." -#define IDS_2056 2056 // "Please enter a valid file name" +#define IDS_2056 2056 // "No usable ROM images found!" #define IDS_2057 2057 // "Unable to open the file for write" #define IDS_2058 2058 // "Attempting to create a HDI.." #define IDS_2059 2059 // "Remember to partition and.." @@ -250,7 +247,7 @@ #define IDS_2092 2092 // "Bus" #define IDS_2093 2093 // "DMA" #define IDS_2094 2094 // "KB" -#define IDS_2095 2095 +#define IDS_2095 2095 // "No renderer available!" #define IDS_2096 2096 // "Slave" #define IDS_2097 2097 // "SCSI (ID %s, LUN %s)" #define IDS_2098 2098 // "Adapter Type" @@ -308,12 +305,10 @@ #define IDS_2150 2150 // "Thrustmaster Flight Control System" #define IDS_2151 2151 // "Disabled" #define IDS_2152 2152 // "None" -#if NOTUSED -#define IDS_2153 2153 -#define IDS_2154 2154 -#endif +#define IDS_2153 2153 // "Unable to load Accelerators" +#define IDS_2154 2154 // "Unable to register Raw Input" #define IDS_2155 2155 // "IRQ %i" -#define IDS_2156 2156 // "MFM (%01i:%01i)" +#define IDS_2156 2156 // "MFM/RLL (%91i:%01i)" #define IDS_2157 2157 // "IDE (PIO+DMA) (%01i:%01i)" #define IDS_2158 2158 // "SCSI (%02i:%02i)" #define IDS_2159 2159 // "Invalid number of cylinders.." diff --git a/src/win/win.c b/src/win/win.c index 7ee98f0cd..586e0e910 100644 --- a/src/win/win.c +++ b/src/win/win.c @@ -8,7 +8,7 @@ * * The Emulator's Windows core. * - * Version: @(#)win.c 1.0.14 2017/10/02 + * Version: @(#)win.c 1.0.15 2017/10/05 * * Authors: Sarah Walker, * Miran Grca, @@ -22,6 +22,8 @@ #include #include #include +#include +#include #include #undef BITMAP #include @@ -73,1444 +75,1190 @@ #define MAPVK_VK_TO_VSC 0 #endif -/* Declare Windows procedure */ -LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); -LRESULT CALLBACK subWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); -LRESULT CALLBACK StatusBarProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); - -#define TIMER_1SEC 1 +#define TIMER_1SEC 1 extern int updatestatus; -typedef struct win_event_t -{ - HANDLE handle; -} win_event_t; - -static wchar_t wTitle[512]; -LONG_PTR OriginalStatusBarProcedure; -HWND ghwnd; +int recv_key[272]; +HWND hwndMain; +HMENU menuMain; +HANDLE ghMutex; +HANDLE slirpMutex; HINSTANCE hinstance; -HMENU menu; +RECT oldclip; + int pause = 0; int scale = 0; -HWND hwndRender, hwndStatus; uint64_t timer_freq; int winsizex=640, winsizey=480; int efwinsizey=480; int gfx_present[GFX_MAX]; -HANDLE ghMutex; -HANDLE slirpMutex; -HANDLE mainthreadh; int infocus=1; int drawits=0; int quited=0; -RECT oldclip; int mousecapture=0; -int recv_key[272]; -HMENU *sb_menu_handles; uint64_t main_time; -static struct -{ - int (*init)(HWND h); - void (*close)(); - void (*resize)(int x, int y); -} vid_apis[2][2] = -{ { { ddraw_init, ddraw_close, NULL }, - { d3d_init, d3d_close, d3d_resize } }, - { { ddraw_fs_init, ddraw_fs_close, NULL }, - { d3d_fs_init, d3d_fs_close, NULL } } }; - -static int save_window_pos = 0; - static RAWINPUTDEVICE device; +static HHOOK hKeyboardHook; +static int hook_enabled = 0; +static HANDLE thMain; +static HICON hIcon[512]; +static HWND hwndRender; /* machine render window */ +static wchar_t wTitle[512]; +static int save_window_pos = 0; static int win_doresize = 0; - static int leave_fullscreen_flag = 0; - static int unscaled_size_x = 0; static int unscaled_size_y = 0; - static uint64_t start_time; static uint64_t end_time; - -HMENU smenu; - static uint8_t host_cdrom_drive_available[26]; - static uint8_t host_cdrom_drive_available_num = 0; - static wchar_t **argv; static int argc; static wchar_t *argbuf; +static struct { + int (*init)(HWND h); + void (*close)(void); + void (*resize)(int x, int y); +} vid_apis[2][2] = { + { + { ddraw_init, ddraw_close, NULL }, + { d3d_init, d3d_close, d3d_resize } + }, + { + { ddraw_fs_init, ddraw_fs_close, NULL }, + { d3d_fs_init, d3d_fs_close, NULL } + } +}; -static HANDLE hinstAcc; -static HICON hIcon[512]; +static HICON +LoadIconEx(PCTSTR pszIconName) +{ + return((HICON)LoadImage(hinstance, pszIconName, IMAGE_ICON, + 16, 16, LR_SHARED)); +} + +static HICON +LoadIconBig(PCTSTR pszIconName) +{ + return((HICON)LoadImage(hinstance, pszIconName, IMAGE_ICON, 64, 64, 0)); +} + + +/**************************************************************** + * Status Bar Handling * + ****************************************************************/ + +static HWND hwndSBAR; /* status bar window */ +static LONG_PTR OriginalStatusBarProcedure; +static HMENU *sb_menu_handles; +static HMENU menuSBAR; +static WCHAR **sbTips; static int *iStatusWidths; static int *sb_icon_flags; static int *sb_part_meanings; static int *sb_part_icons; -static WCHAR **sbTips; static int sb_parts = 0; static int sb_ready = 0; -void updatewindowsize(int x, int y) +/* Also used by win_settings.c */ +int +fdd_type_to_icon(int type) { - int owsx = winsizex; - int owsy = winsizey; - - int temp_overscan_x = overscan_x; - int temp_overscan_y = overscan_y; - - double dx, dy, dtx, dty; - - if (vid_resize) return; - - if (x < 160) x = 160; - if (y < 100) y = 100; - - if (x > 2048) x = 2048; - if (y > 2048) y = 2048; - - if (suppress_overscan) - { - temp_overscan_x = temp_overscan_y = 0; - } - - unscaled_size_x=x; efwinsizey=y; - - if (force_43) - { - dx = (double) x; - dtx = (double) temp_overscan_x; - - dy = (double) y; - dty = (double) temp_overscan_y; - - /* Account for possible overscan. */ - if (temp_overscan_y == 16) - { - /* CGA */ - dy = (((dx - dtx) / 4.0) * 3.0) + dty; - } - else if (temp_overscan_y < 16) - { - /* MDA/Hercules */ - dy = (x / 4.0) * 3.0; - } - else - { - if (enable_overscan) - { - /* EGA/(S)VGA with overscan */ - dy = (((dx - dtx) / 4.0) * 3.0) + dty; - } - else - { - /* EGA/(S)VGA without overscan */ - dy = (x / 4.0) * 3.0; - } - } - unscaled_size_y = (int) dy; - } - else - { - unscaled_size_y = efwinsizey; - } - - switch(scale) - { - case 0: - winsizex = unscaled_size_x >> 1; - winsizey = unscaled_size_y >> 1; - break; - case 1: - winsizex = unscaled_size_x; - winsizey = unscaled_size_y; - break; - case 2: - winsizex = (unscaled_size_x * 3) >> 1; - winsizey = (unscaled_size_y * 3) >> 1; - break; - case 3: - winsizex = unscaled_size_x << 1; - winsizey = unscaled_size_y << 1; - break; - } - - if ((owsx != winsizex) || (owsy != winsizey)) - { - win_doresize = 1; - } - else - { - win_doresize = 0; - } -} - -void uws_natural(void) -{ - updatewindowsize(unscaled_size_x, efwinsizey); -} - -void releasemouse(void) -{ - if (mousecapture) - { - ClipCursor(&oldclip); - ShowCursor(TRUE); - mousecapture = 0; - } -} - -void startblit(void) -{ - WaitForSingleObject(ghMutex, INFINITE); -} - -void endblit(void) -{ - ReleaseMutex(ghMutex); -} - -void startslirp(void) -{ - WaitForSingleObject(slirpMutex, INFINITE); -} - -void endslirp(void) -{ - ReleaseMutex(slirpMutex); -} - -void leave_fullscreen(void) -{ - leave_fullscreen_flag = 1; -} - -uint32_t get_ticks(void) -{ - return GetTickCount(); -} - -void delay_ms(uint32_t count) -{ - Sleep(count); -} - -void mainthread(LPVOID param) -{ - int frames = 0; - DWORD old_time, new_time; - - RECT r; - int sb_borders[3]; - - drawits=0; - old_time = GetTickCount(); - while (!quited) - { - if (updatestatus) - { - updatestatus = 0; - if (status_is_open) - { - SendMessage(status_hwnd, WM_USER, 0, 0); - } - } - new_time = GetTickCount(); - drawits += new_time - old_time; - old_time = new_time; - if (drawits > 0 && !pause) - { - start_time = timer_read(); - drawits-=10; if (drawits>50) drawits=0; - pc_run(); - frames++; - if (frames >= 200 && nvr_dosave) - { - frames = 0; - nvr_save(); - nvr_dosave = 0; - } - end_time = timer_read(); - main_time += end_time - start_time; - } - else - Sleep(1); - - if (!video_fullscreen && win_doresize && (winsizex > 0) && (winsizey > 0)) - { - SendMessage(hwndStatus, SB_GETBORDERS, 0, (LPARAM) sb_borders); - GetWindowRect(ghwnd, &r); - MoveWindow(hwndRender, 0, 0, winsizex, winsizey, TRUE); - GetWindowRect(hwndRender, &r); - MoveWindow(hwndStatus, 0, r.bottom + GetSystemMetrics(SM_CYEDGE), winsizex, 17, TRUE); - GetWindowRect(ghwnd, &r); - - MoveWindow(ghwnd, r.left, r.top, - winsizex + (GetSystemMetrics(vid_resize ? SM_CXSIZEFRAME : SM_CXFIXEDFRAME) * 2), - winsizey + (GetSystemMetrics(SM_CYEDGE) * 2) + (GetSystemMetrics(vid_resize ? SM_CYSIZEFRAME : SM_CYFIXEDFRAME) * 2) + GetSystemMetrics(SM_CYMENUSIZE) + GetSystemMetrics(SM_CYCAPTION) + 17 + sb_borders[1] + 1, - TRUE); - - if (mousecapture) - { - GetWindowRect(hwndRender, &r); - ClipCursor(&r); - } - - win_doresize = 0; - } - - if (leave_fullscreen_flag) - { - leave_fullscreen_flag = 0; - SendMessage(ghwnd, WM_LEAVEFULLSCREEN, 0, 0); - } - if (video_fullscreen && infocus) - { - SetCursorPos(9999, 9999); - } - } -} - -void *thread_create(void (*thread_rout)(void *param), void *param) -{ - return (void *)_beginthread(thread_rout, 0, param); -} - -void thread_kill(void *handle) -{ - TerminateThread(handle, 0); -} - -void thread_sleep(int t) -{ - Sleep(t); -} - -event_t *thread_create_event(void) -{ - win_event_t *event = malloc(sizeof(win_event_t)); - - event->handle = CreateEvent(NULL, FALSE, FALSE, NULL); - - return (event_t *)event; -} - -void thread_set_event(event_t *_event) -{ - win_event_t *event = (win_event_t *)_event; - - SetEvent(event->handle); -} - -void thread_reset_event(event_t *_event) -{ - win_event_t *event = (win_event_t *)_event; - - ResetEvent(event->handle); -} - -int thread_wait_event(event_t *_event, int timeout) -{ - win_event_t *event = (win_event_t *)_event; - - if (timeout == -1) - timeout = INFINITE; - - if (WaitForSingleObject(event->handle, timeout)) - return 1; - return 0; -} - -void thread_destroy_event(event_t *_event) -{ - win_event_t *event = (win_event_t *)_event; - - CloseHandle(event->handle); - - free(event); -} - -void *thread_create_mutex(wchar_t *name) -{ - return (void*) CreateMutex(NULL, FALSE, name); -} - -void thread_close_mutex(void *mutex) -{ - CloseHandle((HANDLE) mutex); -} - -uint8_t thread_wait_mutex(void *mutex) -{ - DWORD dwres = WaitForSingleObject((HANDLE) mutex, INFINITE); - - switch (dwres) - { - case WAIT_OBJECT_0: - return 1; - case WAIT_ABANDONED: - default: - return 0; - } -} - -uint8_t thread_release_mutex(void *mutex) -{ - return !!ReleaseMutex((HANDLE) mutex); -} - -static void init_cdrom_host_drives(void) -{ - int i = 0; - WCHAR s[64]; - - host_cdrom_drive_available_num = 0; - - for (i='A'; i<='Z'; i++) - { - _swprintf(s, L"%c:\\", i); - - if (GetDriveType(s)==DRIVE_CDROM) - { - host_cdrom_drive_available[i - 'A'] = 1; - - host_cdrom_drive_available_num++; - } - else - { - host_cdrom_drive_available[i - 'A'] = 0; - } - } -} - - -static HMENU create_popup_menu(int part) -{ - HMENU newHandle; - newHandle = CreatePopupMenu(); - AppendMenu(smenu, MF_POPUP, (UINT_PTR) newHandle, 0); - return newHandle; -} - - -static void create_floppy_submenu(HMENU m, int id) -{ - AppendMenu(m, MF_STRING, IDM_FLOPPY_IMAGE_NEW | id, win_language_get_string_from_id(IDS_2161)); - AppendMenu(m, MF_SEPARATOR, 0, 0); - AppendMenu(m, MF_STRING, IDM_FLOPPY_IMAGE_EXISTING | id, win_language_get_string_from_id(IDS_2162)); - AppendMenu(m, MF_STRING, IDM_FLOPPY_IMAGE_EXISTING_WP | id, win_language_get_string_from_id(IDS_2163)); - AppendMenu(m, MF_SEPARATOR, 0, 0); - AppendMenu(m, MF_STRING, IDM_FLOPPY_EJECT | id, win_language_get_string_from_id(IDS_2164)); -} - -static void create_cdrom_submenu(HMENU m, int id) -{ - int i = 0; - WCHAR s[64]; - - AppendMenu(m, MF_STRING, IDM_CDROM_MUTE | id, win_language_get_string_from_id(IDS_2165)); - AppendMenu(m, MF_SEPARATOR, 0, 0); - AppendMenu(m, MF_STRING, IDM_CDROM_EMPTY | id, win_language_get_string_from_id(IDS_2166)); - AppendMenu(m, MF_STRING, IDM_CDROM_RELOAD | id, win_language_get_string_from_id(IDS_2167)); - AppendMenu(m, MF_SEPARATOR, 0, 0); - AppendMenu(m, MF_STRING, IDM_CDROM_IMAGE | id, win_language_get_string_from_id(IDS_2168)); - - if (host_cdrom_drive_available_num == 0) - { - if ((cdrom_drives[id].host_drive >= 'A') && (cdrom_drives[id].host_drive <= 'Z')) - { - cdrom_drives[id].host_drive = 0; - } - - goto check_menu_items; - } - else - { - if ((cdrom_drives[id].host_drive >= 'A') && (cdrom_drives[id].host_drive <= 'Z')) - { - if (!host_cdrom_drive_available[cdrom_drives[id].host_drive - 'A']) - { - cdrom_drives[id].host_drive = 0; - } - } - } - - AppendMenu(m, MF_SEPARATOR, 0, 0); - - for (i = 0; i < 26; i++) - { - _swprintf(s, L"Host CD/DVD Drive (%c:)", i + 0x41); - if (host_cdrom_drive_available[i]) - { - AppendMenu(m, MF_STRING, IDM_CDROM_HOST_DRIVE | (i << 3) | id, s); - } - } - -check_menu_items: - if (!cdrom_drives[id].sound_on) - { - CheckMenuItem(m, IDM_CDROM_MUTE | id, MF_CHECKED); - } - - if (cdrom_drives[id].host_drive == 200) - { - CheckMenuItem(m, IDM_CDROM_IMAGE | id, MF_CHECKED); - } - else if ((cdrom_drives[id].host_drive >= 'A') && (cdrom_drives[id].host_drive <= 'Z')) - { - CheckMenuItem(m, IDM_CDROM_HOST_DRIVE | id | ((cdrom_drives[id].host_drive - 'A') << 3), MF_CHECKED); - } - else - { - cdrom_drives[id].host_drive = 0; - CheckMenuItem(m, IDM_CDROM_EMPTY | id, MF_CHECKED); - } -} - -static void create_removable_disk_submenu(HMENU m, int id) -{ - AppendMenu(m, MF_STRING, IDM_RDISK_EJECT | id, win_language_get_string_from_id(IDS_2166)); - AppendMenu(m, MF_STRING, IDM_RDISK_RELOAD | id, win_language_get_string_from_id(IDS_2167)); - AppendMenu(m, MF_SEPARATOR, 0, 0); - AppendMenu(m, MF_STRING, IDM_RDISK_SEND_CHANGE | id, win_language_get_string_from_id(IDS_2142)); - AppendMenu(m, MF_SEPARATOR, 0, 0); - AppendMenu(m, MF_STRING, IDM_RDISK_IMAGE | id, win_language_get_string_from_id(IDS_2168)); - AppendMenu(m, MF_STRING, IDM_RDISK_IMAGE_WP | id, win_language_get_string_from_id(IDS_2169)); -} - -void get_executable_name(wchar_t *s, int size) -{ - GetModuleFileName(hinstance, s, size); -} - -void set_window_title(wchar_t *s) -{ - if (! video_fullscreen) { - if (s != NULL) - wcscpy(wTitle, s); - else - s = wTitle; - - SetWindowText(ghwnd, s); - } -} - -uint64_t timer_read(void) -{ - LARGE_INTEGER qpc_time; - QueryPerformanceCounter(&qpc_time); - return qpc_time.QuadPart; -} - -static void process_command_line(void) -{ - WCHAR *cmdline; - int argc_max; - int i, q; - - cmdline = GetCommandLine(); - i = wcslen(cmdline) + 1; - argbuf = malloc(i * 2); - memcpy(argbuf, cmdline, i * 2); - - argc = 0; - argc_max = 64; - argv = malloc(sizeof(wchar_t *) * argc_max); - if (!argv) - { - free(argbuf); - return; - } - - i = 0; - - /* parse commandline into argc/argv format */ - while (argbuf[i]) - { - while (argbuf[i] == L' ') - i++; - - if (argbuf[i]) - { - if ((argbuf[i] == L'\'') || (argbuf[i] == L'"')) - { - q = argbuf[i++]; - if (!argbuf[i]) - break; - } - else - q = 0; - - argv[argc++] = &argbuf[i]; - - if (argc >= argc_max) - { - argc_max += 64; - argv = realloc(argv, sizeof(wchar_t *) * argc_max); - if (!argv) - { - free(argbuf); - return; - } - } - - while ((argbuf[i]) && ((q) ? (argbuf[i] != q) : (argbuf[i] != L' '))) - i++; - - if (argbuf[i]) - { - argbuf[i] = 0; - i++; - } - } - } - - argv[argc] = NULL; -} - -int find_in_array(int *array, int val, int len, int menu_base) -{ - int i = 0; - int temp = 0; - for (i = 0; i < len; i++) - { - CheckMenuItem(menu, menu_base + array[i], MF_UNCHECKED); - if (array[i] == val) - { - temp = 1; - } - } - return temp; -} - -HICON LoadIconEx(PCTSTR pszIconName) -{ - return (HICON) LoadImage(hinstance, pszIconName, IMAGE_ICON, 16, 16, LR_SHARED); -} - -HICON LoadIconBig(PCTSTR pszIconName) -{ - return (HICON) LoadImage(hinstance, pszIconName, IMAGE_ICON, 64, 64, 0); -} - -int fdd_type_to_icon(int type) -{ - switch(type) - { - default: - case 0: - return 512; - case 1: - case 2: - case 3: - case 4: - case 5: - case 6: - return 128; - case 7: - case 8: - case 9: - case 10: - case 11: - case 12: - case 13: - return 144; - } + int ret = 512; + + switch(type) { + case 0: + break; + + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + ret = 128; + break; + + case 7: + case 8: + case 9: + case 10: + case 11: + case 12: + case 13: + ret = 144; + break; + + default: + break; + } + + return(ret); } /* FIXME: should be hdd_count() in hdd.c */ -int hdd_count(int bus) +static int +hdd_count(int bus) { - int i = 0; + int c = 0; + int i; - int c = 0; + for (i=0; i= SB_TEXT) || !sb_ready || (sb_parts == 0) || (sb_icon_flags == NULL) || (sb_part_icons == NULL)) - { - return; - } - - temp_flags |= active; - - found = find_status_bar_part(tag); - - if (found != -1) - { - if (temp_flags != (sb_icon_flags[found] & 1)) - { - sb_icon_flags[found] &= ~1; - sb_icon_flags[found] |= active; - - sb_part_icons[found] &= ~257; - sb_part_icons[found] |= sb_icon_flags[found]; - - SendMessage(hwndStatus, SB_SETICON, found, (LPARAM) hIcon[sb_part_icons[found]]); - } - } + AppendMenu(m, MF_STRING, IDM_FLOPPY_IMAGE_NEW | id, + win_language_get_string_from_id(IDS_2161)); + AppendMenu(m, MF_SEPARATOR, 0, 0); + AppendMenu(m, MF_STRING, IDM_FLOPPY_IMAGE_EXISTING | id, + win_language_get_string_from_id(IDS_2162)); + AppendMenu(m, MF_STRING, IDM_FLOPPY_IMAGE_EXISTING_WP | id, + win_language_get_string_from_id(IDS_2163)); + AppendMenu(m, MF_SEPARATOR, 0, 0); + AppendMenu(m, MF_STRING, IDM_FLOPPY_EJECT | id, + win_language_get_string_from_id(IDS_2164)); } -/* This is for the drive state indicator. */ -void update_status_bar_icon_state(int tag, int state) -{ - int found = -1; - if (((tag & 0xf0) >= SB_HDD) || !sb_ready || (sb_parts == 0) || (sb_icon_flags == NULL) || (sb_part_icons == NULL)) - { - return; +static void +StatusBarCreateCdromSubmenu(HMENU m, int id) +{ + WCHAR s[64]; + int i; + + AppendMenu(m, MF_STRING, IDM_CDROM_MUTE | id, + win_language_get_string_from_id(IDS_2165)); + AppendMenu(m, MF_SEPARATOR, 0, 0); + AppendMenu(m, MF_STRING, IDM_CDROM_EMPTY | id, + win_language_get_string_from_id(IDS_2166)); + AppendMenu(m, MF_STRING, IDM_CDROM_RELOAD | id, + win_language_get_string_from_id(IDS_2167)); + AppendMenu(m, MF_SEPARATOR, 0, 0); + AppendMenu(m, MF_STRING, IDM_CDROM_IMAGE | id, + win_language_get_string_from_id(IDS_2168)); + + if (host_cdrom_drive_available_num == 0) { + if ((cdrom_drives[id].host_drive >= 'A') && + (cdrom_drives[id].host_drive <= 'Z')) { + cdrom_drives[id].host_drive = 0; } - found = find_status_bar_part(tag); + goto check_menu_items; + } else { + if ((cdrom_drives[id].host_drive >= 'A') && + (cdrom_drives[id].host_drive <= 'Z')) { + if (!host_cdrom_drive_available[cdrom_drives[id].host_drive - 'A']) { + cdrom_drives[id].host_drive = 0; + } + } + } - if (found != -1) - { - sb_icon_flags[found] &= ~256; - sb_icon_flags[found] |= state ? 256 : 0; + AppendMenu(m, MF_SEPARATOR, 0, 0); + + for (i=0; i<26; i++) { + _swprintf(s, L"Host CD/DVD Drive (%c:)", i+'A'); + if (host_cdrom_drive_available[i]) + AppendMenu(m, MF_STRING, IDM_CDROM_HOST_DRIVE | (i<<3)|id, s); + } + +check_menu_items: + if (! cdrom_drives[id].sound_on) + CheckMenuItem(m, IDM_CDROM_MUTE | id, MF_CHECKED); + + if (cdrom_drives[id].host_drive == 200) + CheckMenuItem(m, IDM_CDROM_IMAGE | id, MF_CHECKED); + else + if ((cdrom_drives[id].host_drive >= 'A') && (cdrom_drives[id].host_drive <= 'Z')) { + CheckMenuItem(m, IDM_CDROM_HOST_DRIVE | id | + ((cdrom_drives[id].host_drive - 'A') << 3), MF_CHECKED); + } else { + cdrom_drives[id].host_drive = 0; + CheckMenuItem(m, IDM_CDROM_EMPTY | id, MF_CHECKED); + } +} + + +static void +StatusBarCreateRemovableDiskSubmenu(HMENU m, int id) +{ + AppendMenu(m, MF_STRING, IDM_RDISK_EJECT | id, + win_language_get_string_from_id(IDS_2166)); + AppendMenu(m, MF_STRING, IDM_RDISK_RELOAD | id, + win_language_get_string_from_id(IDS_2167)); + AppendMenu(m, MF_SEPARATOR, 0, 0); + AppendMenu(m, MF_STRING, IDM_RDISK_SEND_CHANGE | id, + win_language_get_string_from_id(IDS_2142)); + AppendMenu(m, MF_SEPARATOR, 0, 0); + AppendMenu(m, MF_STRING, IDM_RDISK_IMAGE | id, + win_language_get_string_from_id(IDS_2168)); + AppendMenu(m, MF_STRING, IDM_RDISK_IMAGE_WP | id, + win_language_get_string_from_id(IDS_2169)); +} + + +/* API */ +int +StatusBarFindPart(int tag) +{ + int found = -1; + int i; + + if (!sb_ready || (sb_parts == 0) || (sb_part_meanings == NULL)) { + return -1; + } + + for (i=0; i= SB_TEXT) || !sb_ready || (sb_parts == 0) || (sb_icon_flags == NULL) || (sb_part_icons == NULL)) { + return; + } + + temp_flags |= active; + + found = StatusBarFindPart(tag); + if (found != -1) { + if (temp_flags != (sb_icon_flags[found] & 1)) { + sb_icon_flags[found] &= ~1; + sb_icon_flags[found] |= active; sb_part_icons[found] &= ~257; sb_part_icons[found] |= sb_icon_flags[found]; - SendMessage(hwndStatus, SB_SETICON, found, (LPARAM) hIcon[sb_part_icons[found]]); + SendMessage(hwndSBAR, SB_SETICON, found, + (LPARAM)hIcon[sb_part_icons[found]]); } + } } -void create_floppy_tip(int part) + +/* API: This is for the drive state indicator. */ +void +StatusBarUpdateIconState(int tag, int state) { - WCHAR wtext[512]; - WCHAR tempTip[512]; + int found = -1; - int drive = sb_part_meanings[part] & 0xf; + if (((tag & 0xf0) >= SB_HDD) || !sb_ready || (sb_parts == 0) || (sb_icon_flags == NULL) || (sb_part_icons == NULL)) { + return; + } - mbstowcs(wtext, fdd_getname(fdd_get_type(drive)), strlen(fdd_getname(fdd_get_type(drive))) + 1); - if (wcslen(floppyfns[drive]) == 0) - { - _swprintf(tempTip, win_language_get_string_from_id(IDS_2158), drive + 1, wtext, win_language_get_string_from_id(IDS_2057)); - } - else - { - _swprintf(tempTip, win_language_get_string_from_id(IDS_2158), drive + 1, wtext, floppyfns[drive]); - } + found = StatusBarFindPart(tag); + if (found != -1) { + sb_icon_flags[found] &= ~256; + sb_icon_flags[found] |= state ? 256 : 0; - if (sbTips[part] != NULL) - { - free(sbTips[part]); - } - sbTips[part] = (WCHAR *) malloc((wcslen(tempTip) << 1) + 2); - wcscpy(sbTips[part], tempTip); + sb_part_icons[found] &= ~257; + sb_part_icons[found] |= sb_icon_flags[found]; + + SendMessage(hwndSBAR, SB_SETICON, found, + (LPARAM)hIcon[sb_part_icons[found]]); + } } -void create_cdrom_tip(int part) + +static void +StatusBarCreateFloppyTip(int part) { - WCHAR wtext[512]; - WCHAR tempTip[512]; + WCHAR wtext[512]; + WCHAR tempTip[512]; - WCHAR *szText; - int id; + int drive = sb_part_meanings[part] & 0xf; - int drive = sb_part_meanings[part] & 0xf; + mbstowcs(wtext, fdd_getname(fdd_get_type(drive)), + strlen(fdd_getname(fdd_get_type(drive))) + 1); + if (wcslen(floppyfns[drive]) == 0) { + _swprintf(tempTip, win_language_get_string_from_id(IDS_2158), + drive+1, wtext, win_language_get_string_from_id(IDS_2057)); + } else { + _swprintf(tempTip, win_language_get_string_from_id(IDS_2158), + drive+1, wtext, floppyfns[drive]); + } - int bus = cdrom_drives[drive].bus_type; + if (sbTips[part] != NULL) + free(sbTips[part]); + sbTips[part] = (WCHAR *) malloc((wcslen(tempTip) << 1) + 2); + wcscpy(sbTips[part], tempTip); +} - id = IDS_4352 + (bus - 1); - szText = (WCHAR *) win_language_get_string_from_id(id); +static void +StatusBarCreateCdromTip(int part) +{ + WCHAR wtext[512]; + WCHAR tempTip[512]; + WCHAR *szText; + int id; + int drive = sb_part_meanings[part] & 0xf; + int bus = cdrom_drives[drive].bus_type; - if (cdrom_drives[drive].host_drive == 200) - { - if (wcslen(cdrom_image[drive].image_path) == 0) - { - _swprintf(tempTip, win_language_get_string_from_id(IDS_5120), drive + 1, szText, win_language_get_string_from_id(IDS_2057)); - } - else - { - _swprintf(tempTip, win_language_get_string_from_id(IDS_5120), drive + 1, szText, cdrom_image[drive].image_path); - } - } - else if ((cdrom_drives[drive].host_drive >= 'A') && (cdrom_drives[drive].host_drive <= 'Z')) - { - _swprintf(wtext, win_language_get_string_from_id(IDS_2058), cdrom_drives[drive].host_drive & ~0x20); - _swprintf(tempTip, win_language_get_string_from_id(IDS_5120), drive + 1, szText, wtext); - } - else - { + id = IDS_4352 + (bus - 1); + szText = (WCHAR *)win_language_get_string_from_id(id); + + if (cdrom_drives[drive].host_drive == 200) { + if (wcslen(cdrom_image[drive].image_path) == 0) { _swprintf(tempTip, win_language_get_string_from_id(IDS_5120), drive + 1, szText, win_language_get_string_from_id(IDS_2057)); + } else { + _swprintf(tempTip, win_language_get_string_from_id(IDS_5120), drive + 1, szText, cdrom_image[drive].image_path); } + } else if ((cdrom_drives[drive].host_drive >= 'A') && (cdrom_drives[drive].host_drive <= 'Z')) { + _swprintf(wtext, win_language_get_string_from_id(IDS_2058), cdrom_drives[drive].host_drive & ~0x20); + _swprintf(tempTip, win_language_get_string_from_id(IDS_5120), drive + 1, szText, wtext); + } else { + _swprintf(tempTip, win_language_get_string_from_id(IDS_5120), drive + 1, szText, win_language_get_string_from_id(IDS_2057)); + } - if (sbTips[part] != NULL) - { - free(sbTips[part]); - } - sbTips[part] = (WCHAR *) malloc((wcslen(tempTip) << 1) + 2); - wcscpy(sbTips[part], tempTip); + if (sbTips[part] != NULL) + free(sbTips[part]); + sbTips[part] = (WCHAR *) malloc((wcslen(tempTip) << 1) + 2); + wcscpy(sbTips[part], tempTip); } -void create_removable_hd_tip(int part) + +static void +StatusBarCreateRemovableDiskTip(int part) { - WCHAR tempTip[512]; + WCHAR tempTip[512]; + int drive = sb_part_meanings[part] & 0x1f; - int drive = sb_part_meanings[part] & 0x1f; + if (wcslen(hdd[drive].fn) == 0) { + _swprintf(tempTip, win_language_get_string_from_id(IDS_4115), drive, win_language_get_string_from_id(IDS_2057)); + } else { + _swprintf(tempTip, win_language_get_string_from_id(IDS_4115), drive, hdd[drive].fn); + } - if (wcslen(hdd[drive].fn) == 0) - { - _swprintf(tempTip, win_language_get_string_from_id(IDS_4115), drive, win_language_get_string_from_id(IDS_2057)); - } - else - { - _swprintf(tempTip, win_language_get_string_from_id(IDS_4115), drive, hdd[drive].fn); - } - - if (sbTips[part] != NULL) - { - free(sbTips[part]); - } - sbTips[part] = (WCHAR *) malloc((wcslen(tempTip) << 1) + 2); - wcscpy(sbTips[part], tempTip); + if (sbTips[part] != NULL) + free(sbTips[part]); + sbTips[part] = (WCHAR *) malloc((wcslen(tempTip) << 1) + 2); + wcscpy(sbTips[part], tempTip); } -void create_hd_tip(int part) + +static void +StatusBarCreateDiskTip(int part) { - WCHAR tempTip[512]; - WCHAR *szText; - int id; + WCHAR tempTip[512]; + WCHAR *szText; + int id; + int bus = sb_part_meanings[part] & 0xf; - int bus = sb_part_meanings[part] & 0xf; + id = IDS_4352 + (bus - 1); + szText = (WCHAR *)win_language_get_string_from_id(id); - id = IDS_4352 + (bus - 1); - - szText = (WCHAR *) win_language_get_string_from_id(id); - - _swprintf(tempTip, win_language_get_string_from_id(IDS_4096), szText); - - if (sbTips[part] != NULL) - { - free(sbTips[part]); - } - sbTips[part] = (WCHAR *) malloc((wcslen(tempTip) << 1) + 2); - wcscpy(sbTips[part], tempTip); + _swprintf(tempTip, win_language_get_string_from_id(IDS_4096), szText); + if (sbTips[part] != NULL) + free(sbTips[part]); + sbTips[part] = (WCHAR *) malloc((wcslen(tempTip) << 1) + 2); + wcscpy(sbTips[part], tempTip); } -void create_network_tip(int part) + +static void +StatusBarCreateNetworkTip(int part) { - WCHAR tempTip[512]; + WCHAR tempTip[512]; - _swprintf(tempTip, win_language_get_string_from_id(IDS_2069)); + _swprintf(tempTip, win_language_get_string_from_id(IDS_2069)); - if (sbTips[part] != NULL) - { - free(sbTips[part]); - } - sbTips[part] = (WCHAR *) malloc((wcslen(tempTip) << 1) + 2); - wcscpy(sbTips[part], tempTip); + if (sbTips[part] != NULL) + free(sbTips[part]); + sbTips[part] = (WCHAR *) malloc((wcslen(tempTip) << 1) + 2); + wcscpy(sbTips[part], tempTip); } -void update_tip(int meaning) -{ - int i = 0; - int part = -1; - if (!sb_ready || (sb_parts == 0) || (sb_part_meanings == NULL)) - { - return; +/* API */ +void +StatusBarUpdateTip(int meaning) +{ + int part = -1; + int i; + + if (!sb_ready || (sb_parts == 0) || (sb_part_meanings == NULL)) return; + + for (i=0; i 0) { for (i = 0; i < sb_parts; i++) - { - if (sb_part_meanings[i] == meaning) - { - part = i; - } + SendMessage(hwndSBAR, SB_SETICON, i, (LPARAM)NULL); + SendMessage(hwndSBAR, SB_SETPARTS, (WPARAM)0, (LPARAM)NULL); + + if (iStatusWidths) { + free(iStatusWidths); + iStatusWidths = NULL; + } + if (sb_part_meanings) { + free(sb_part_meanings); + sb_part_meanings = NULL; + } + if (sb_part_icons) { + free(sb_part_icons); + sb_part_icons = NULL; + } + if (sb_icon_flags) { + free(sb_icon_flags); + sb_icon_flags = NULL; + } + StatusBarDestroyMenus(); + StatusBarDestroyTips(); + } + sb_parts = 0; + + for (i=0; i= 'A') && (cdrom_drives[id].host_drive <= 'Z')) { + sb_icon_flags[i] = 0; + } else { + sb_icon_flags[i] = 256; + } + sb_part_icons[i] = 160 | sb_icon_flags[i]; + sb_menu_handles[i] = StatusBarCreatePopupMenu(i); + StatusBarCreateCdromSubmenu(sb_menu_handles[i], sb_part_meanings[i] & 0xf); + EnableMenuItem(sb_menu_handles[i], IDM_CDROM_RELOAD | (sb_part_meanings[i] & 0xf), MF_BYCOMMAND | MF_GRAYED); + StatusBarCreateCdromTip(i); + break; + + case SB_RDISK: /* Removable hard disk */ + sb_icon_flags[i] = (wcslen(hdd[sb_part_meanings[i] & 0x1f].fn) == 0) ? 256 : 0; + sb_part_icons[i] = 176 + sb_icon_flags[i]; + sb_menu_handles[i] = StatusBarCreatePopupMenu(i); + StatusBarCreateRemovableDiskSubmenu(sb_menu_handles[i], sb_part_meanings[i] & 0x1f); + EnableMenuItem(sb_menu_handles[i], IDM_RDISK_EJECT | (sb_part_meanings[i] & 0x1f), MF_BYCOMMAND | ((sb_icon_flags[i] & 256) ? MF_GRAYED : MF_ENABLED)); + EnableMenuItem(sb_menu_handles[i], IDM_RDISK_RELOAD | (sb_part_meanings[i] & 0x1f), MF_BYCOMMAND | MF_GRAYED); + EnableMenuItem(sb_menu_handles[i], IDM_RDISK_SEND_CHANGE | (sb_part_meanings[i] & 0x1f), MF_BYCOMMAND | ((sb_icon_flags[i] & 256) ? MF_GRAYED : MF_ENABLED)); + StatusBarCreateRemovableDiskTip(i); + break; + + case SB_HDD: /* Hard disk */ + sb_part_icons[i] = 192; + StatusBarCreateDiskTip(i); + break; + + case SB_NETWORK: /* Network */ + sb_part_icons[i] = 208; + StatusBarCreateNetworkTip(i); + break; + + case SB_TEXT: /* Status text */ + SendMessage(hwndSBAR, SB_SETTEXT, i | SBT_NOBORDERS, (LPARAM) L""); + sb_part_icons[i] = -1; + break; + } + + if (sb_part_icons[i] != -1) { + SendMessage(hwndSBAR, SB_SETTEXT, i | SBT_NOBORDERS, (LPARAM)""); + SendMessage(hwndSBAR, SB_SETICON, i, (LPARAM)hIcon[sb_part_icons[i]]); + SendMessage(hwndSBAR, SB_SETTIPTEXT, i, (LPARAM)sbTips[i]); + } else { + SendMessage(hwndSBAR, SB_SETICON, i, (LPARAM)NULL); + } + } + + sb_ready = 1; +} + + +static VOID APIENTRY +StatusBarPopupMenu(HWND hwnd, POINT pt, int id) +{ + if (id >= (sb_parts - 1)) return; + + pt.x = id * SB_ICON_WIDTH; /* Justify to the left. */ + pt.y = 0; /* Justify to the top. */ + ClientToScreen(hwnd, (LPPOINT) &pt); + TrackPopupMenu(sb_menu_handles[id], + TPM_LEFTALIGN | TPM_BOTTOMALIGN | TPM_LEFTBUTTON, + pt.x, pt.y, 0, hwndSBAR, NULL); +} + + +/* Handle messages for the Status Bar window. */ +static LRESULT CALLBACK +StatusBarProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + WCHAR temp_image_path[1024]; + RECT rc; + POINT pt; + int new_cdrom_drive; + int ret = 0; + int item_id = 0; + int item_params = 0; + int id = 0; + int part = 0; + int letter = 0; + + switch (message) { + case WM_COMMAND: + item_id = LOWORD(wParam) & 0xff00; /* low 8 bits */ + item_params = LOWORD(wParam) & 0x00ff; /* high 8 bits */ + + switch (item_id) { + case IDM_FLOPPY_IMAGE_EXISTING: + case IDM_FLOPPY_IMAGE_EXISTING_WP: + id = item_params & 0x0003; + part = StatusBarFindPart(SB_FLOPPY | id); + if ((part == -1) || (sb_menu_handles == NULL)) + break; + + ret = file_dlg_w_st(hwnd, IDS_2159, floppyfns[id], 0); + if (! ret) { + floppy_close(id); + ui_writeprot[id] = (item_id == IDM_FLOPPY_IMAGE_EXISTING_WP) ? 1 : 0; + floppy_load(id, wopenfilestring); + StatusBarUpdateIconState(SB_FLOPPY | id, wcslen(floppyfns[id]) ? 0 : 1); + EnableMenuItem(sb_menu_handles[part], IDM_FLOPPY_EJECT | id, MF_BYCOMMAND | (wcslen(floppyfns[id]) ? MF_ENABLED : MF_GRAYED)); + StatusBarUpdateTip(SB_FLOPPY | id); + config_save(); + } break; - case SB_CDROM: - create_cdrom_tip(part); + + case IDM_FLOPPY_EJECT: + id = item_params & 0x0003; + part = StatusBarFindPart(SB_FLOPPY | id); + if ((part == -1) || (sb_menu_handles == NULL)) + break; + + floppy_close(id); + StatusBarUpdateIconState(SB_FLOPPY | id, 1); + EnableMenuItem(sb_menu_handles[part], IDM_FLOPPY_EJECT | id, MF_BYCOMMAND | MF_GRAYED); + StatusBarUpdateTip(SB_FLOPPY | id); + config_save(); break; - case SB_RDISK: - create_removable_hd_tip(part); + + case IDM_CDROM_MUTE: + id = item_params & 0x0007; + part = StatusBarFindPart(SB_CDROM | id); + if ((part == -1) || (sb_menu_handles == NULL)) + break; + + cdrom_drives[id].sound_on ^= 1; + CheckMenuItem(sb_menu_handles[part], IDM_CDROM_MUTE | id, cdrom_drives[id].sound_on ? MF_UNCHECKED : MF_CHECKED); + config_save(); + sound_cd_thread_reset(); break; - case SB_HDD: - create_hd_tip(part); + + case IDM_CDROM_EMPTY: + id = item_params & 0x0007; + cdrom_eject(id); break; + + case IDM_CDROM_RELOAD: + id = item_params & 0x0007; + cdrom_reload(id); + break; + + case IDM_CDROM_IMAGE: + id = item_params & 0x0007; + part = StatusBarFindPart(SB_CDROM | id); + if ((part == -1) || (sb_menu_handles == NULL)) + break; + + if (!file_dlg_w_st(hwnd, IDS_2075, cdrom_image[id].image_path, 0)) { + cdrom_drives[id].prev_host_drive = cdrom_drives[id].host_drive; + wcscpy(temp_image_path, wopenfilestring); + if ((wcscmp(cdrom_image[id].image_path, temp_image_path) == 0) && (cdrom_drives[id].host_drive == 200)) { + /* Switching from image to the same image. Do nothing. */ + break; + } + wcscpy(cdrom_image[id].prev_image_path, cdrom_image[id].image_path); + cdrom_drives[id].handler->exit(id); + cdrom_close(id); + image_open(id, temp_image_path); + /* Signal media change to the emulated machine. */ + cdrom_insert(id); + CheckMenuItem(sb_menu_handles[part], IDM_CDROM_EMPTY | id, MF_UNCHECKED); + if ((cdrom_drives[id].host_drive >= 'A') && (cdrom_drives[id].host_drive <= 'Z')) { + CheckMenuItem(sb_menu_handles[part], IDM_CDROM_HOST_DRIVE | id | ((cdrom_drives[id].host_drive - 'A') << 3), MF_UNCHECKED); + } + cdrom_drives[id].host_drive = (wcslen(cdrom_image[id].image_path) == 0) ? 0 : 200; + if (cdrom_drives[id].host_drive == 200) { + CheckMenuItem(sb_menu_handles[part], IDM_CDROM_IMAGE | id, MF_CHECKED); + StatusBarUpdateIconState(SB_CDROM | id, 0); + } else { + CheckMenuItem(sb_menu_handles[part], IDM_CDROM_IMAGE | id, MF_UNCHECKED); + CheckMenuItem(sb_menu_handles[part], IDM_CDROM_EMPTY | id, MF_UNCHECKED); + StatusBarUpdateIconState(SB_CDROM | id, 1); + } + EnableMenuItem(sb_menu_handles[part], IDM_CDROM_RELOAD | id, MF_BYCOMMAND | MF_GRAYED); + StatusBarUpdateTip(SB_CDROM | id); + config_save(); + } + break; + + case IDM_CDROM_HOST_DRIVE: + id = item_params & 0x0007; + letter = ((item_params >> 3) & 0x001f) + 'A'; + part = StatusBarFindPart(SB_CDROM | id); + if ((part == -1) || (sb_menu_handles == NULL)) + { + break; + } + + new_cdrom_drive = letter; + if (cdrom_drives[id].host_drive == new_cdrom_drive) + { + /* Switching to the same drive. Do nothing. */ + break; + } + cdrom_drives[id].prev_host_drive = cdrom_drives[id].host_drive; + cdrom_drives[id].handler->exit(id); + cdrom_close(id); + ioctl_open(id, new_cdrom_drive); + /* Signal media change to the emulated machine. */ + cdrom_insert(id); + CheckMenuItem(sb_menu_handles[part], IDM_CDROM_EMPTY | id, MF_UNCHECKED); + if ((cdrom_drives[id].host_drive >= 'A') && (cdrom_drives[id].host_drive <= 'Z')) + { + CheckMenuItem(sb_menu_handles[part], IDM_CDROM_HOST_DRIVE | id | ((cdrom_drives[id].host_drive - 'A') << 3), MF_UNCHECKED); + } + CheckMenuItem(sb_menu_handles[part], IDM_CDROM_IMAGE | id, MF_UNCHECKED); + cdrom_drives[id].host_drive = new_cdrom_drive; + CheckMenuItem(sb_menu_handles[part], IDM_CDROM_HOST_DRIVE | id | ((cdrom_drives[id].host_drive - 'A') << 3), MF_CHECKED); + EnableMenuItem(sb_menu_handles[part], IDM_CDROM_RELOAD | id, MF_BYCOMMAND | MF_GRAYED); + StatusBarUpdateIconState(SB_CDROM | id, 0); + StatusBarUpdateTip(SB_CDROM | id); + config_save(); + break; + + case IDM_RDISK_EJECT: + id = item_params & 0x001f; + removable_disk_eject(id); + break; + + case IDM_RDISK_RELOAD: + id = item_params & 0x001f; + removable_disk_reload(id); + break; + + case IDM_RDISK_SEND_CHANGE: + id = item_params & 0x001f; + scsi_disk_insert(id); + break; + + case IDM_RDISK_IMAGE: + case IDM_RDISK_IMAGE_WP: + id = item_params & 0x001f; + ret = file_dlg_w_st(hwnd, IDS_4106, hdd[id].fn, id); + if (!ret) { + removable_disk_unload(id); + memset(hdd[id].fn, 0, sizeof(hdd[id].fn)); + wcscpy(hdd[id].fn, wopenfilestring); + hdd[id].wp = (item_id == IDM_RDISK_IMAGE_WP) ? 1 : 0; + scsi_loadhd(hdd[id].scsi_id, hdd[id].scsi_lun, id); + scsi_disk_insert(id); + if (wcslen(hdd[id].fn) > 0) { + StatusBarUpdateIconState(SB_RDISK | id, 0); + EnableMenuItem(sb_menu_handles[part], IDM_RDISK_EJECT | id, MF_BYCOMMAND | MF_ENABLED); + EnableMenuItem(sb_menu_handles[part], IDM_RDISK_RELOAD | id, MF_BYCOMMAND | MF_GRAYED); + EnableMenuItem(sb_menu_handles[part], IDM_RDISK_SEND_CHANGE | id, MF_BYCOMMAND | MF_ENABLED); + } + else { + StatusBarUpdateIconState(SB_RDISK | id, 1); + EnableMenuItem(sb_menu_handles[part], IDM_RDISK_EJECT | id, MF_BYCOMMAND | MF_GRAYED); + EnableMenuItem(sb_menu_handles[part], IDM_RDISK_RELOAD | id, MF_BYCOMMAND | MF_GRAYED); + EnableMenuItem(sb_menu_handles[part], IDM_RDISK_SEND_CHANGE | id, MF_BYCOMMAND | MF_GRAYED); + } + StatusBarUpdateTip(SB_RDISK | id); + config_save(); + } + break; + default: break; } + return(0); - SendMessage(hwndStatus, SB_SETTIPTEXT, part, (LPARAM) sbTips[part]); - } + case WM_LBUTTONDOWN: + case WM_RBUTTONDOWN: + GetClientRect(hwnd, (LPRECT)& rc); + pt.x = GET_X_LPARAM(lParam); + pt.y = GET_Y_LPARAM(lParam); + if (PtInRect((LPRECT) &rc, pt)) + StatusBarPopupMenu(hwnd, pt, (pt.x / SB_ICON_WIDTH)); + break; + + default: + return(CallWindowProc((WNDPROC)OriginalStatusBarProcedure, + hwnd, message, wParam, lParam)); + } + + return(0); } -void status_settextw(wchar_t *wstr) + +/* Create and set up the Status Bar window. */ +static void +StatusBarCreate(HWND hwndParent, int idStatus, HINSTANCE hInst) { - int i = 0; - int part = -1; + RECT rectDialog; + int dw, dh, i; - if (!sb_ready || (sb_parts == 0) || (sb_part_meanings == NULL)) - { - return; - } + for (i = 128; i < 130; i++) + hIcon[i] = LoadIconEx((PCTSTR) i); + for (i = 144; i < 146; i++) + hIcon[i] = LoadIconEx((PCTSTR) i); + for (i = 160; i < 162; i++) + hIcon[i] = LoadIconEx((PCTSTR) i); + for (i = 176; i < 178; i++) + hIcon[i] = LoadIconEx((PCTSTR) i); + for (i = 192; i < 194; i++) + hIcon[i] = LoadIconEx((PCTSTR) i); + for (i = 208; i < 210; i++) + hIcon[i] = LoadIconEx((PCTSTR) i); + for (i = 384; i < 386; i++) + hIcon[i] = LoadIconEx((PCTSTR) i); + for (i = 400; i < 402; i++) + hIcon[i] = LoadIconEx((PCTSTR) i); + for (i = 416; i < 418; i++) + hIcon[i] = LoadIconEx((PCTSTR) i); + for (i = 432; i < 434; i++) + hIcon[i] = LoadIconEx((PCTSTR) i); - for (i = 0; i < sb_parts; i++) - { - if (sb_part_meanings[i] == SB_TEXT) - { - part = i; - } - } + GetWindowRect(hwndParent, &rectDialog); + dw = rectDialog.right - rectDialog.left; + dh = rectDialog.bottom - rectDialog.top; - if (part != -1) - { - SendMessage(hwndStatus, SB_SETTEXT, part | SBT_NOBORDERS, (LPARAM) wstr); - } + /* Load the Common Controls DLL if needed. */ + InitCommonControls(); + + /* Create the window, and make sure it's using the STATUS class. */ + hwndSBAR = CreateWindowEx(0, + STATUSCLASSNAME, + (LPCTSTR)NULL, + SBARS_SIZEGRIP|WS_CHILD|WS_VISIBLE|SBT_TOOLTIPS, + 0, dh-17, dw, 17, + hwndParent, + (HMENU)idStatus, hInst, NULL); + + /* Replace the original procedure with ours. */ + OriginalStatusBarProcedure = GetWindowLongPtr(hwndSBAR, GWLP_WNDPROC); + SetWindowLongPtr(hwndSBAR, GWL_WNDPROC, (LONG_PTR)&StatusBarProcedure); + + SendMessage(hwndSBAR, SB_SETMINHEIGHT, (WPARAM)17, (LPARAM)0); + + /* Align the window with the parent (main) window. */ + GetWindowRect(hwndSBAR, &rectDialog); + SetWindowPos(hwndSBAR, + HWND_TOPMOST, + rectDialog.left, rectDialog.top, + rectDialog.right-rectDialog.left, + rectDialog.bottom-rectDialog.top, + SWP_SHOWWINDOW); + + /* Load the dummu menu for this window. */ + menuSBAR = LoadMenu(hInst, SB_MENU_NAME); + + /* Initialize the status bar and populate the icons and menus. */ + sb_parts = 0; + StatusBarUpdatePanes(); } -static wchar_t cwstr[512]; -void status_settext(char *str) +/* API */ +void +StatusBarSetTextW(wchar_t *wstr) { - memset(cwstr, 0, 1024); - mbstowcs(cwstr, str, strlen(str) + 1); - status_settextw(cwstr); + int part = -1; + int i; + + if (!sb_ready || (sb_parts == 0) || (sb_part_meanings == NULL)) return; + + for (i=0; i 0) - { - for (i = 0; i < sb_parts; i++) - { - SendMessage(hwnds, SB_SETICON, i, (LPARAM) NULL); - } - - SendMessage(hwnds, SB_SETPARTS, (WPARAM) 0, (LPARAM) NULL); - - if (iStatusWidths) - { - free(iStatusWidths); - iStatusWidths = NULL; - } - if (sb_part_meanings) - { - free(sb_part_meanings); - sb_part_meanings = NULL; - } - if (sb_part_icons) - { - free(sb_part_icons); - sb_part_icons = NULL; - } - if (sb_icon_flags) - { - free(sb_icon_flags); - sb_icon_flags = NULL; - } - destroy_menu_handles(); - destroy_tips(); - } - - sb_parts = 0; - - for (i = 0; i < FDD_NUM; i++) - { - if (fdd_get_type(i) != 0) - { - /* pclog("update_status_bar_panes(): Found floppy drive %c:, type %i\n", 65 + i, fdd_get_type(i)); */ - sb_parts++; - } - } - for (i = 0; i < CDROM_NUM; i++) - { - /* Could be Internal or External IDE.. */ - if ((cdrom_drives[i].bus_type==CDROM_BUS_ATAPI_PIO_ONLY) && - !(hdint || !memcmp(hdc_name, "ide", 3))) - { - continue; - } - /* Could be Internal or External IDE.. */ - if ((cdrom_drives[i].bus_type==CDROM_BUS_ATAPI_PIO_AND_DMA) && - !(hdint || !memcmp(hdc_name, "ide", 3))) - { - continue; - } - if ((cdrom_drives[i].bus_type == CDROM_BUS_SCSI) && (scsi_card_current == 0)) - { - continue; - } - if (cdrom_drives[i].bus_type != 0) - { - sb_parts++; - } - } - for (i = 0; i < HDD_NUM; i++) - { - if ((hdd[i].bus == HDD_BUS_SCSI_REMOVABLE) && (scsi_card_current != 0)) - { - sb_parts++; - } - } - if (c_mfm && (hdint || !memcmp(hdc_name, "mfm", 3))) - { - /* MFM drives, and MFM or Internal controller. */ - sb_parts++; - } - if (c_esdi && (hdint || !memcmp(hdc_name, "esdi", 4))) - { - /* ESDI drives, and ESDI or Internal controller. */ - sb_parts++; - } - if (c_xtide && !memcmp(hdc_name, "xtide", 5)) - { - sb_parts++; - } - if (c_ide_pio && (hdint || !memcmp(hdc_name, "ide", 3))) - { - /* IDE_PIO drives, and IDE or Internal controller. */ - sb_parts++; - } - if (c_ide_dma && (hdint || !memcmp(hdc_name, "ide", 3))) - { - /* IDE_DMA drives, and IDE or Internal controller. */ - sb_parts++; - } - if (c_scsi && (scsi_card_current != 0)) - { - sb_parts++; - } - if (do_net) - { - sb_parts++; - } - sb_parts++; - - iStatusWidths = (int *) malloc(sb_parts * sizeof(int)); - sb_part_meanings = (int *) malloc(sb_parts * sizeof(int)); - sb_part_icons = (int *) malloc(sb_parts * sizeof(int)); - sb_icon_flags = (int *) malloc(sb_parts * sizeof(int)); - sb_menu_handles = (HMENU *) malloc(sb_parts * sizeof(HMENU)); - sbTips = (WCHAR **) malloc(sb_parts * sizeof(WCHAR *)); - - memset(iStatusWidths, 0, sb_parts * sizeof(int)); - memset(sb_part_meanings, 0, sb_parts * sizeof(int)); - memset(sb_part_icons, 0, sb_parts * sizeof(int)); - memset(sb_icon_flags, 0, sb_parts * sizeof(int)); - memset(sb_menu_handles, 0, sb_parts * sizeof(HMENU)); - memset(sbTips, 0, sb_parts * sizeof(WCHAR *)); - - sb_parts = 0; - - for (i = 0; i < FDD_NUM; i++) - { - if (fdd_get_type(i) != 0) - { - /* pclog("update_status_bar_panes(): Found floppy drive %c:, type %i\n", 65 + i, fdd_get_type(i)); */ - edge += SB_ICON_WIDTH; - iStatusWidths[sb_parts] = edge; - sb_part_meanings[sb_parts] = SB_FLOPPY | i; - sb_parts++; - } - } - for (i = 0; i < CDROM_NUM; i++) - { - /* Could be Internal or External IDE.. */ - if ((cdrom_drives[i].bus_type==CDROM_BUS_ATAPI_PIO_ONLY) && - !(hdint || !memcmp(hdc_name, "ide", 3))) - { - continue; - } - /* Could be Internal or External IDE.. */ - if ((cdrom_drives[i].bus_type==CDROM_BUS_ATAPI_PIO_AND_DMA) && - !(hdint || !memcmp(hdc_name, "ide", 3))) - { - continue; - } - if ((cdrom_drives[i].bus_type == CDROM_BUS_SCSI) && (scsi_card_current == 0)) - { - continue; - } - if (cdrom_drives[i].bus_type != 0) - { - edge += SB_ICON_WIDTH; - iStatusWidths[sb_parts] = edge; - sb_part_meanings[sb_parts] = SB_CDROM | i; - sb_parts++; - } - } - for (i = 0; i < HDD_NUM; i++) - { - if ((hdd[i].bus == HDD_BUS_SCSI_REMOVABLE) && (scsi_card_current != 0)) - { - edge += SB_ICON_WIDTH; - iStatusWidths[sb_parts] = edge; - sb_part_meanings[sb_parts] = SB_RDISK | i; - sb_parts++; - } - } - if (c_mfm && (hdint || !memcmp(hdc_name, "mfm", 3))) - { - edge += SB_ICON_WIDTH; - iStatusWidths[sb_parts] = edge; - sb_part_meanings[sb_parts] = SB_HDD | HDD_BUS_MFM; - sb_parts++; - } - if (c_esdi && (hdint || !memcmp(hdc_name, "esdi", 4))) - { - edge += SB_ICON_WIDTH; - iStatusWidths[sb_parts] = edge; - sb_part_meanings[sb_parts] = SB_HDD | HDD_BUS_ESDI; - sb_parts++; - } - if (c_xtide && !memcmp(hdc_name, "xtide", 5)) - { - edge += SB_ICON_WIDTH; - iStatusWidths[sb_parts] = edge; - sb_part_meanings[sb_parts] = SB_HDD | HDD_BUS_XTIDE; - sb_parts++; - } - if (c_ide_pio && (hdint || !memcmp(hdc_name, "ide", 3))) - { - edge += SB_ICON_WIDTH; - iStatusWidths[sb_parts] = edge; - sb_part_meanings[sb_parts] = SB_HDD | HDD_BUS_IDE_PIO_ONLY; - sb_parts++; - } - if (c_ide_dma && (hdint || !memcmp(hdc_name, "ide", 3))) - { - edge += SB_ICON_WIDTH; - iStatusWidths[sb_parts] = edge; - sb_part_meanings[sb_parts] = SB_HDD | HDD_BUS_IDE_PIO_AND_DMA; - sb_parts++; - } - if (c_scsi && (scsi_card_current != 0)) - { - edge += SB_ICON_WIDTH; - iStatusWidths[sb_parts] = edge; - sb_part_meanings[sb_parts] = SB_HDD | HDD_BUS_SCSI; - sb_parts++; - } - if (do_net) - { - edge += SB_ICON_WIDTH; - iStatusWidths[sb_parts] = edge; - sb_part_meanings[sb_parts] = SB_NETWORK; - sb_parts++; - } - if (sb_parts) - { - iStatusWidths[sb_parts - 1] += (24 - SB_ICON_WIDTH); - } - iStatusWidths[sb_parts] = -1; - sb_part_meanings[sb_parts] = SB_TEXT; - sb_parts++; - - SendMessage(hwnds, SB_SETPARTS, (WPARAM) sb_parts, (LPARAM) iStatusWidths); - - for (i = 0; i < sb_parts; i++) - { - switch (sb_part_meanings[i] & 0xf0) - { - case SB_FLOPPY: - /* Floppy */ - sb_icon_flags[i] = (wcslen(floppyfns[sb_part_meanings[i] & 0xf]) == 0) ? 256 : 0; - sb_part_icons[i] = fdd_type_to_icon(fdd_get_type(sb_part_meanings[i] & 0xf)) | sb_icon_flags[i]; - sb_menu_handles[i] = create_popup_menu(i); - create_floppy_submenu(sb_menu_handles[i], sb_part_meanings[i] & 0xf); - EnableMenuItem(sb_menu_handles[i], IDM_FLOPPY_EJECT | (sb_part_meanings[i] & 0xf), MF_BYCOMMAND | ((sb_icon_flags[i] & 256) ? MF_GRAYED : MF_ENABLED)); - create_floppy_tip(i); - break; - case SB_CDROM: - /* CD-ROM */ - id = sb_part_meanings[i] & 0xf; - if (cdrom_drives[id].host_drive == 200) - { - sb_icon_flags[i] = (wcslen(cdrom_image[id].image_path) == 0) ? 256 : 0; - } - else if ((cdrom_drives[id].host_drive >= 'A') && (cdrom_drives[id].host_drive <= 'Z')) - { - sb_icon_flags[i] = 0; - } - else - { - sb_icon_flags[i] = 256; - } - sb_part_icons[i] = 160 | sb_icon_flags[i]; - sb_menu_handles[i] = create_popup_menu(i); - create_cdrom_submenu(sb_menu_handles[i], sb_part_meanings[i] & 0xf); - EnableMenuItem(sb_menu_handles[i], IDM_CDROM_RELOAD | (sb_part_meanings[i] & 0xf), MF_BYCOMMAND | MF_GRAYED); - create_cdrom_tip(i); - break; - case SB_RDISK: - /* Removable hard disk */ - sb_icon_flags[i] = (wcslen(hdd[sb_part_meanings[i] & 0x1f].fn) == 0) ? 256 : 0; - sb_part_icons[i] = 176 + sb_icon_flags[i]; - sb_menu_handles[i] = create_popup_menu(i); - create_removable_disk_submenu(sb_menu_handles[i], sb_part_meanings[i] & 0x1f); - EnableMenuItem(sb_menu_handles[i], IDM_RDISK_EJECT | (sb_part_meanings[i] & 0x1f), MF_BYCOMMAND | ((sb_icon_flags[i] & 256) ? MF_GRAYED : MF_ENABLED)); - EnableMenuItem(sb_menu_handles[i], IDM_RDISK_RELOAD | (sb_part_meanings[i] & 0x1f), MF_BYCOMMAND | MF_GRAYED); - EnableMenuItem(sb_menu_handles[i], IDM_RDISK_SEND_CHANGE | (sb_part_meanings[i] & 0x1f), MF_BYCOMMAND | ((sb_icon_flags[i] & 256) ? MF_GRAYED : MF_ENABLED)); - create_removable_hd_tip(i); - break; - case SB_HDD: - /* Hard disk */ - sb_part_icons[i] = 192; - create_hd_tip(i); - break; - case SB_NETWORK: - /* Hard disk */ - sb_part_icons[i] = 208; - create_network_tip(i); - break; - case SB_TEXT: - /* Status text */ - SendMessage(hwnds, SB_SETTEXT, i | SBT_NOBORDERS, (LPARAM) L""); - sb_part_icons[i] = -1; + default: break; } - if (sb_part_icons[i] != -1) - { - SendMessage(hwnds, SB_SETTEXT, i | SBT_NOBORDERS, (LPARAM) ""); - SendMessage(hwnds, SB_SETICON, i, (LPARAM) hIcon[sb_part_icons[i]]); - SendMessage(hwnds, SB_SETTIPTEXT, i, (LPARAM) sbTips[i]); - /* pclog("Status bar part found: %02X (%i)\n", sb_part_meanings[i], sb_part_icons[i]); */ - } - else - { - SendMessage(hwnds, SB_SETICON, i, (LPARAM) NULL); - } - } + break; + } - sb_ready = 1; + return(FALSE); } -HWND EmulatorStatusBar(HWND hwndParent, int idStatus, HINSTANCE hinst) + +static void +AboutDialogCreate(HWND hwnd) { - HWND hwndStatus; - int i; - RECT rectDialog; - int dw, dh; - - for (i = 128; i < 130; i++) - { - hIcon[i] = LoadIconEx((PCTSTR) i); - } - - for (i = 144; i < 146; i++) - { - hIcon[i] = LoadIconEx((PCTSTR) i); - } - - for (i = 160; i < 162; i++) - { - hIcon[i] = LoadIconEx((PCTSTR) i); - } - - for (i = 176; i < 178; i++) - { - hIcon[i] = LoadIconEx((PCTSTR) i); - } - - for (i = 192; i < 194; i++) - { - hIcon[i] = LoadIconEx((PCTSTR) i); - } - - for (i = 208; i < 210; i++) - { - hIcon[i] = LoadIconEx((PCTSTR) i); - } - - for (i = 384; i < 386; i++) - { - hIcon[i] = LoadIconEx((PCTSTR) i); - } - - for (i = 400; i < 402; i++) - { - hIcon[i] = LoadIconEx((PCTSTR) i); - } - - for (i = 416; i < 418; i++) - { - hIcon[i] = LoadIconEx((PCTSTR) i); - } - - for (i = 432; i < 434; i++) - { - hIcon[i] = LoadIconEx((PCTSTR) i); - } - - GetWindowRect(hwndParent, &rectDialog); - dw = rectDialog.right - rectDialog.left; - dh = rectDialog.bottom - rectDialog.top; - - InitCommonControls(); - - hwndStatus = CreateWindowEx(0, STATUSCLASSNAME, (PCTSTR) NULL, SBARS_SIZEGRIP | WS_CHILD | WS_VISIBLE | SBT_TOOLTIPS, 0, dh - 17, dw, 17, hwndParent, - (HMENU) idStatus, hinst, NULL); - - GetWindowRect(hwndStatus, &rectDialog); - - SetWindowPos(hwndStatus, HWND_TOPMOST, rectDialog.left, rectDialog.top, rectDialog.right - rectDialog.left, rectDialog.bottom - rectDialog.top, SWP_SHOWWINDOW); - - SendMessage(hwndStatus, SB_SETMINHEIGHT, (WPARAM) 17, (LPARAM) 0); - - sb_parts = 0; - - update_status_bar_panes(hwndStatus); - - return hwndStatus; + DialogBox(hinstance, (LPCTSTR)DLG_ABOUT, hwnd, AboutDialogProcedure); } -void win_menu_update(void) + +/**************************************************************** + * Main Window Handling * + ****************************************************************/ + +#if 0 +static void +win_menu_update(void) { #if 0 menu = LoadMenu(hThisInstance, TEXT("MainMenu")); @@ -1518,502 +1266,24 @@ void win_menu_update(void) smenu = LoadMenu(hThisInstance, TEXT("StatusBarMenu")); initmenu(); - SetMenu(ghwnd, menu); + SetMenu(hwndMain, menu); win_title_update = 1; #endif } - -void reset_menus(void) -{ -#ifdef ENABLE_LOG_TOGGLES -# ifdef ENABLE_BUSLOGIC_LOG - CheckMenuItem(menu, IDM_LOG_BUSLOGIC, MF_UNCHECKED); -# endif -# ifdef ENABLE_CDROM_LOG - CheckMenuItem(menu, IDM_LOG_CDROM, MF_UNCHECKED); -# endif -# ifdef ENABLE_D86F_LOG - CheckMenuItem(menu, IDM_LOG_D86F, MF_UNCHECKED); -# endif -# ifdef ENABLE_FDC_LOG - CheckMenuItem(menu, IDM_LOG_FDC, MF_UNCHECKED); -# endif -# ifdef ENABLE_IDE_LOG - CheckMenuItem(menu, IDM_LOG_IDE, MF_UNCHECKED); -# endif -# ifdef ENABLE_SERIAL_LOG - CheckMenuItem(menu, IDM_LOG_SERIAL, MF_UNCHECKED); -# endif -# ifdef ENABLE_NIC_LOG - /*FIXME: should be network_setlog(1:0) */ - CheckMenuItem(menu, IDM_LOG_NIC, MF_UNCHECKED); -# endif #endif - CheckMenuItem(menu, IDM_VID_FORCE43, MF_UNCHECKED); - CheckMenuItem(menu, IDM_VID_OVERSCAN, MF_UNCHECKED); - CheckMenuItem(menu, IDM_VID_INVERT, MF_UNCHECKED); - CheckMenuItem(menu, IDM_VID_RESIZE, MF_UNCHECKED); - CheckMenuItem(menu, IDM_VID_DDRAW + 0, MF_UNCHECKED); - CheckMenuItem(menu, IDM_VID_DDRAW + 1, MF_UNCHECKED); - CheckMenuItem(menu, IDM_VID_FS_FULL + 0, MF_UNCHECKED); - CheckMenuItem(menu, IDM_VID_FS_FULL + 1, MF_UNCHECKED); - CheckMenuItem(menu, IDM_VID_FS_FULL + 2, MF_UNCHECKED); - CheckMenuItem(menu, IDM_VID_FS_FULL + 3, MF_UNCHECKED); - CheckMenuItem(menu, IDM_VID_REMEMBER, MF_UNCHECKED); - CheckMenuItem(menu, IDM_VID_SCALE_1X + 0, MF_UNCHECKED); - CheckMenuItem(menu, IDM_VID_SCALE_1X + 1, MF_UNCHECKED); - CheckMenuItem(menu, IDM_VID_SCALE_1X + 2, MF_UNCHECKED); - CheckMenuItem(menu, IDM_VID_SCALE_1X + 3, MF_UNCHECKED); - - CheckMenuItem(menu, IDM_VID_CGACON, MF_UNCHECKED); - CheckMenuItem(menu, IDM_VID_GRAYCT_601 + 0, MF_UNCHECKED); - CheckMenuItem(menu, IDM_VID_GRAYCT_601 + 1, MF_UNCHECKED); - CheckMenuItem(menu, IDM_VID_GRAYCT_601 + 2, MF_UNCHECKED); - CheckMenuItem(menu, IDM_VID_GRAY_RGB + 0, MF_UNCHECKED); - CheckMenuItem(menu, IDM_VID_GRAY_RGB + 1, MF_UNCHECKED); - CheckMenuItem(menu, IDM_VID_GRAY_RGB + 2, MF_UNCHECKED); - CheckMenuItem(menu, IDM_VID_GRAY_RGB + 3, MF_UNCHECKED); - CheckMenuItem(menu, IDM_VID_GRAY_RGB + 4, MF_UNCHECKED); - -#ifdef ENABLE_LOG_TOGGLES -# ifdef ENABLE_BUSLOGIC_LOG - CheckMenuItem(menu, IDM_LOG_BUSLOGIC, buslogic_do_log ? MF_CHECKED : MF_UNCHECKED); -# endif -# ifdef ENABLE_CDROM_LOG - CheckMenuItem(menu, IDM_LOG_CDROM, cdrom_do_log ? MF_CHECKED : MF_UNCHECKED); -# endif -# ifdef ENABLE_D86F_LOG - CheckMenuItem(menu, IDM_LOG_D86F, d86f_do_log ? MF_CHECKED : MF_UNCHECKED); -# endif -# ifdef ENABLE_FDC_LOG - CheckMenuItem(menu, IDM_LOG_FDC, fdc_do_log ? MF_CHECKED : MF_UNCHECKED); -# endif -# ifdef ENABLE_IDE_LOG - CheckMenuItem(menu, IDM_LOG_IDE, ide_do_log ? MF_CHECKED : MF_UNCHECKED); -# endif -# ifdef ENABLE_SERIAL_LOG - CheckMenuItem(menu, IDM_LOG_SERIAL, serial_do_log ? MF_CHECKED : MF_UNCHECKED); -# endif -# ifdef ENABLE_NIC_LOG - /*FIXME: should be network_setlog(1:0) */ - CheckMenuItem(menu, IDM_LOG_NIC, nic_do_log ? MF_CHECKED : MF_UNCHECKED); -# endif -#endif - - CheckMenuItem(menu, IDM_VID_FORCE43, force_43 ? MF_CHECKED : MF_UNCHECKED); - CheckMenuItem(menu, IDM_VID_OVERSCAN, enable_overscan ? MF_CHECKED : MF_UNCHECKED); - CheckMenuItem(menu, IDM_VID_INVERT, invert_display ? MF_CHECKED : MF_UNCHECKED); - - if (vid_resize) CheckMenuItem(menu, IDM_VID_RESIZE, MF_CHECKED); - CheckMenuItem(menu, IDM_VID_DDRAW + vid_api, MF_CHECKED); - CheckMenuItem(menu, IDM_VID_FS_FULL + video_fullscreen_scale, MF_CHECKED); - CheckMenuItem(menu, IDM_VID_REMEMBER, window_remember ? MF_CHECKED : MF_UNCHECKED); - CheckMenuItem(menu, IDM_VID_SCALE_1X + scale, MF_CHECKED); - - CheckMenuItem(menu, IDM_VID_CGACON, vid_cga_contrast ? MF_CHECKED : MF_UNCHECKED); - CheckMenuItem(menu, IDM_VID_GRAYCT_601 + video_graytype, MF_CHECKED); - CheckMenuItem(menu, IDM_VID_GRAY_RGB + video_grayscale, MF_CHECKED); -} - -int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil) +static void +releasemouse(void) { - HWND hwnd; /* handle for our window */ - MSG messages; /* received-messages buffer */ - WNDCLASSEX wincl; /* buffer for main window's class */ - HACCEL haccel; /* handle to accelerator table */ - int c, d, bRet; - WCHAR title[200]; - LARGE_INTEGER qpc_freq; - - /* Process the command line for options. */ - process_command_line(); - - memset(recv_key, 0, sizeof(recv_key)); - - win_language_load_common_strings(); - - /* The Window structure. */ - hinstance = hThisInstance; - wincl.hInstance = hThisInstance; - wincl.lpszClassName = szClassName; - wincl.lpfnWndProc = WindowProcedure; /* called by Windows */ - wincl.style = CS_DBLCLKS; /* Catch double-clicks */ - wincl.cbSize = sizeof (WNDCLASSEX); - - /* Use default icon and mouse-pointer. */ - wincl.hIcon = LoadIcon(hinstance, (LPCTSTR) 100); - wincl.hIconSm = LoadIcon(hinstance, (LPCTSTR) 100); - wincl.hCursor = NULL; - wincl.lpszMenuName = NULL; /* no menu */ - wincl.cbClsExtra = 0; /* no extra bytes after window class */ - wincl.cbWndExtra = 0; /* structure or the window instance */ - - /* Use Windows's default color as the background of the window. */ - wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND; - - /* Register the window class, and if it fails quit the program. */ - if (! RegisterClassEx(&wincl)) { - return(0); - } - - wincl.lpszClassName = szSubClassName; - wincl.lpfnWndProc = subWindowProcedure; /* called by Windows */ - if (! RegisterClassEx(&wincl)) { - return(0); - } - - menu = LoadMenu(hThisInstance, TEXT("MainMenu")); - - _swprintf(title, L"%s v%s", EMU_NAME_W, EMU_VERSION_W); - - /* The class is registered, let's create the program*/ - hwnd = CreateWindowEx ( - 0, /* no extended possibilites */ - szClassName, /* class name */ - title, /* Title Text */ -#if 0 - (WS_OVERLAPPEDWINDOW & ~WS_SIZEBOX), /* default window */ -#else - (WS_OVERLAPPEDWINDOW & ~WS_SIZEBOX) | DS_3DLOOK, -#endif - CW_USEDEFAULT, /* Windows decides the position */ - CW_USEDEFAULT, /* where window ends up on the screen */ - 640+(GetSystemMetrics(SM_CXFIXEDFRAME)*2), /* width */ - 480+(GetSystemMetrics(SM_CYFIXEDFRAME)*2)+GetSystemMetrics(SM_CYMENUSIZE)+GetSystemMetrics(SM_CYCAPTION)+1, /* and height in pixels */ - HWND_DESKTOP, /* window is a child to desktop */ - menu, /* menu */ - hThisInstance, /* Program Instance handler */ - NULL /* no Window Creation data */ - ); - - /* Make the window visible on the screen. */ - ShowWindow(hwnd, nFunsterStil); - - /* Load the accelerator table */ - haccel = LoadAccelerators(hinstAcc, L"MainAccel"); - if (haccel == NULL) { - fatal("haccel is null\n"); - } - - device.usUsagePage = 0x01; - device.usUsage = 0x06; - device.dwFlags = RIDEV_NOHOTKEYS; - device.hwndTarget = hwnd; - if (RegisterRawInputDevices(&device, 1, sizeof(device))) { - pclog("Raw input registered!\n"); - } else { - pclog("Raw input registration failed!\n"); - } - - get_registry_key_map(); - - ghwnd = hwnd; - - hwndRender = CreateWindow(L"STATIC", NULL, - WS_VISIBLE|WS_CHILD|SS_BITMAP, - 0, 0, 1, 1, ghwnd, NULL, hinstance, NULL); - - -/* FIXME: Kotori, code below should be moved to pc.c, as its not Win specific. */ - /* Pre-initialize the system, this loads the config file. */ - pc_init(argc, argv); - - init_cdrom_host_drives(); - - network_init(); - - /* Now that we know our window sizes, adjust to that. */ - hwndStatus = EmulatorStatusBar(hwnd, IDC_STATUS, hThisInstance); - OriginalStatusBarProcedure = GetWindowLongPtr(hwndStatus, GWLP_WNDPROC); - SetWindowLongPtr(hwndStatus, GWL_WNDPROC, (LONG_PTR) &StatusBarProcedure); - - smenu = LoadMenu(hThisInstance, TEXT("StatusBarMenu")); - - pc_init_modules(); - - if (vid_apis[0][vid_api].init(hwndRender) == 0) - { - if (vid_apis[0][vid_api ^ 1].init(hwndRender) == 0) - { - fatal("Both DirectDraw and Direct3D renderers failed to initialize\n"); - } - else - { - vid_api ^= 1; - } - } - - if (vid_resize) - SetWindowLongPtr(hwnd, GWL_STYLE, - (WS_OVERLAPPEDWINDOW&~WS_MINIMIZEBOX)|WS_VISIBLE); - else - SetWindowLongPtr(hwnd, GWL_STYLE, - (WS_OVERLAPPEDWINDOW&~WS_SIZEBOX&~WS_THICKFRAME&~WS_MAXIMIZEBOX&~WS_MINIMIZEBOX)|WS_VISIBLE); - - reset_menus(); - -/* FIXME: Kotori, code below should be moved to pc.c, its not Win specific. */ - pclog("Scanning for ROM images:\n"); - d = 0; - for (c=0;c= 0; c--) - { - if (gfx_present[c]) - { - gfxcard = c; - config_save(); - pc_reset_hard(); - break; - } - } - } - - /* Load the selected machine's BIOS. */ - rom_load_bios(romset); - - /* Perform a hard reset to start the machine. */ - pc_reset_hard(); - - timeBeginPeriod(1); - - atexit(releasemouse); - - ghMutex = CreateMutex(NULL, FALSE, L"86Box.BlitMutex"); - slirpMutex = CreateMutex(NULL, FALSE, L"86Box.SlirpMutex"); - mainthreadh=(HANDLE)_beginthread(mainthread,0,NULL); - SetThreadPriority(mainthreadh, THREAD_PRIORITY_HIGHEST); - - updatewindowsize(640, 480); - - QueryPerformanceFrequency(&qpc_freq); - timer_freq = qpc_freq.QuadPart; - - if (start_in_fullscreen) - { - startblit(); - mouse_close(); - vid_apis[0][vid_api].close(); - video_fullscreen = 1; - vid_apis[1][vid_api].init(hwndRender); - mouse_init(); - leave_fullscreen_flag = 0; - endblit(); - device_force_redraw(); - } - - if (window_remember) { - MoveWindow(hwnd, window_x, window_y, window_w, window_h, TRUE); - } else { - MoveWindow(hwndRender, 0, 0, winsizex, winsizey, TRUE); - MoveWindow(hwndStatus, 0, winsizey+6, winsizex, 17, TRUE); - } - - /* Run the message loop. It will run until GetMessage() returns 0 */ - while (! quited) - { - bRet = GetMessage(&messages, NULL, 0, 0); - if ((bRet == 0) || quited) break; - - if (bRet == -1) { - fatal("bRet is -1\n"); - } - - if (messages.message == WM_QUIT) { - quited = 1; - break; - } - - if (! TranslateAccelerator(hwnd, haccel, &messages)) { - TranslateMessage(&messages); - DispatchMessage(&messages); - } - - if (recv_key[0x58] && recv_key[0x42] && mousecapture) { - ClipCursor(&oldclip); - ShowCursor(TRUE); - mousecapture = 0; - } - - if ((recv_key[0x1D] || recv_key[0x9D]) && - (recv_key[0x38] || recv_key[0xB8]) && - (recv_key[0x51] || recv_key[0xD1]) && video_fullscreen) { - leave_fullscreen(); - } - } - - startblit(); - - Sleep(200); - TerminateThread(mainthreadh, 0); - - nvr_save(); - - config_save(); - - pc_close(); - - vid_apis[video_fullscreen][vid_api].close(); - - timeEndPeriod(1); - if (mousecapture) - { - ClipCursor(&oldclip); - ShowCursor(TRUE); - } - - UnregisterClass(szSubClassName, hinstance); - UnregisterClass(szClassName, hinstance); - - return(messages.wParam); -} - - -HHOOK hKeyboardHook; -int hook_enabled = 0; - -LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) -{ - BOOL bControlKeyDown; - KBDLLHOOKSTRUCT* p; - - if (nCode < 0 || nCode != HC_ACTION) - { - return CallNextHookEx( hKeyboardHook, nCode, wParam, lParam); - } - - p = (KBDLLHOOKSTRUCT*)lParam; - - /* disable alt-tab */ - if (p->vkCode == VK_TAB && p->flags & LLKHF_ALTDOWN) return 1; - - /* disable alt-space */ - if (p->vkCode == VK_SPACE && p->flags & LLKHF_ALTDOWN) return 1; - - /* disable alt-escape */ - if (p->vkCode == VK_ESCAPE && p->flags & LLKHF_ALTDOWN) return 1; - - /* disable windows keys */ - if((p->vkCode == VK_LWIN) || (p->vkCode == VK_RWIN)) return 1; - - /* checks ctrl key pressed */ - bControlKeyDown = GetAsyncKeyState(VK_CONTROL)>>((sizeof(SHORT)*8)-1); - - /* disable ctrl-escape */ - if (p->vkCode == VK_ESCAPE && bControlKeyDown) return 1; - - return CallNextHookEx( hKeyboardHook, nCode, wParam, lParam ); -} - - -void -cdrom_close(uint8_t id) -{ - switch (cdrom_drives[id].host_drive) { - case 0: - null_close(id); - break; - - case 200: - image_close(id); - break; - - default: - ioctl_close(id); - break; + if (mousecapture) { + ClipCursor(&oldclip); + ShowCursor(TRUE); + mousecapture = 0; } } -static BOOL CALLBACK about_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - HWND h; - - switch (message) - { - case WM_INITDIALOG: - pause = 1; - h = GetDlgItem(hdlg, IDC_ABOUT_ICON); - SendMessage(h, STM_SETIMAGE, (WPARAM) IMAGE_ICON, (LPARAM) LoadIconBig((PCTSTR) 100)); - break; - - case WM_COMMAND: - switch (LOWORD(wParam)) - { - case IDOK: - EndDialog(hdlg, 0); - pause = 0; - return TRUE; - default: - break; - } - break; - } - - return FALSE; -} - -void about_open(HWND hwnd) -{ - DialogBox(hinstance, (LPCTSTR)DLG_ABOUT, hwnd, about_dlgproc); -} - static void win_pc_reset(int hard) @@ -2035,784 +1305,1446 @@ win_pc_reset(int hard) } -void video_toggle_option(HMENU hmenu, int *val, int id) +static void +video_toggle_option(HMENU h, int *val, int id) { - startblit(); - video_wait_for_blit(); - *val ^= 1; - CheckMenuItem(hmenu, id, *val ? MF_CHECKED : MF_UNCHECKED); - endblit(); - config_save(); - device_force_redraw(); + startblit(); + video_wait_for_blit(); + *val ^= 1; + CheckMenuItem(h, id, *val ? MF_CHECKED : MF_UNCHECKED); + endblit(); + config_save(); + device_force_redraw(); } -LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +/* The main thread runs the actual emulator code. */ +static void +MainThread(LPVOID param) { - static wchar_t wOldTitle[512]; - HMENU hmenu; - RECT rect; - int i = 0; + int sb_borders[3]; + DWORD old_time, new_time; + int frames = 0; + RECT r; - switch (message) - { - case WM_CREATE: - SetTimer(hwnd, TIMER_1SEC, 1000, NULL); - hKeyboardHook = SetWindowsHookEx( WH_KEYBOARD_LL, LowLevelKeyboardProc, GetModuleHandle(NULL), 0 ); - hook_enabled = 1; - break; + drawits = 0; + old_time = GetTickCount(); + while (! quited) { + if (updatestatus) { + if (hwndStatus != NULL) + SendMessage(hwndStatus, WM_USER, 0, 0); + updatestatus = 0; + } - case WM_COMMAND: - hmenu=GetMenu(hwnd); - switch (LOWORD(wParam)) - { - case IDM_ACTION_SCREENSHOT: - take_screenshot(); - break; + new_time = GetTickCount(); + drawits += new_time - old_time; + old_time = new_time; + if (drawits > 0 && !pause) { + start_time = timer_read(); + drawits -= 10; + if (drawits > 50) drawits = 0; + pc_run(); - case IDM_ACTION_HRESET: - win_pc_reset(1); - break; + if (++frames >= 200 && nvr_dosave) { + frames = 0; + nvr_save(); + nvr_dosave = 0; + } - case IDM_ACTION_RESET_CAD: - win_pc_reset(0); - break; + end_time = timer_read(); + main_time += end_time - start_time; + } else + Sleep(1); - case IDM_ACTION_EXIT: - PostQuitMessage(0); - break; + if (!video_fullscreen && win_doresize && (winsizex>0) && (winsizey>0)) { + SendMessage(hwndSBAR, SB_GETBORDERS, 0, (LPARAM) sb_borders); + GetWindowRect(hwndMain, &r); + MoveWindow(hwndRender, 0, 0, winsizex, winsizey, TRUE); + GetWindowRect(hwndRender, &r); + MoveWindow(hwndSBAR, + 0, r.bottom + GetSystemMetrics(SM_CYEDGE), + winsizex, 17, TRUE); + GetWindowRect(hwndMain, &r); - case IDM_ACTION_CTRL_ALT_ESC: - pc_send_cae(); - break; + MoveWindow(hwndMain, r.left, r.top, + winsizex + (GetSystemMetrics(vid_resize ? SM_CXSIZEFRAME : SM_CXFIXEDFRAME) * 2), + winsizey + (GetSystemMetrics(SM_CYEDGE) * 2) + (GetSystemMetrics(vid_resize ? SM_CYSIZEFRAME : SM_CYFIXEDFRAME) * 2) + GetSystemMetrics(SM_CYMENUSIZE) + GetSystemMetrics(SM_CYCAPTION) + 17 + sb_borders[1] + 1, + TRUE); - case IDM_ACTION_PAUSE: - pause ^= 1; - if (pause) { - wcscpy(wOldTitle, wTitle); - wcscat(wTitle, L" - PAUSED -"); + if (mousecapture) { + GetWindowRect(hwndRender, &r); + ClipCursor(&r); + } - set_window_title(NULL); - } else - set_window_title(wOldTitle); - break; + win_doresize = 0; + } - case IDM_CONFIG: - win_settings_open(hwnd); - break; + if (leave_fullscreen_flag) { + leave_fullscreen_flag = 0; - case IDM_ABOUT: - about_open(hwnd); - break; + SendMessage(hwndMain, WM_LEAVEFULLSCREEN, 0, 0); + } - case IDM_STATUS: - status_open(hwnd); - break; + if (video_fullscreen && infocus) + SetCursorPos(9999, 9999); + } +} - case IDM_VID_RESIZE: - vid_resize = !vid_resize; - CheckMenuItem(hmenu, IDM_VID_RESIZE, (vid_resize)? MF_CHECKED : MF_UNCHECKED); - if (vid_resize) SetWindowLongPtr(hwnd, GWL_STYLE, (WS_OVERLAPPEDWINDOW & ~WS_MINIMIZEBOX) | WS_VISIBLE); - else SetWindowLongPtr(hwnd, GWL_STYLE, (WS_OVERLAPPEDWINDOW & ~WS_SIZEBOX & ~WS_THICKFRAME & ~WS_MAXIMIZEBOX & ~WS_MINIMIZEBOX) | WS_VISIBLE); - GetWindowRect(hwnd, &rect); - SetWindowPos(hwnd, 0, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER | SWP_FRAMECHANGED); - GetWindowRect(hwndStatus,&rect); - SetWindowPos(hwndStatus, 0, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER | SWP_FRAMECHANGED); - if (vid_resize) - { - CheckMenuItem(hmenu, IDM_VID_SCALE_1X + scale, MF_UNCHECKED); - CheckMenuItem(hmenu, IDM_VID_SCALE_2X, MF_CHECKED); - scale = 1; - } - EnableMenuItem(hmenu, IDM_VID_SCALE_1X, vid_resize ? MF_GRAYED : MF_ENABLED); - EnableMenuItem(hmenu, IDM_VID_SCALE_2X, vid_resize ? MF_GRAYED : MF_ENABLED); - EnableMenuItem(hmenu, IDM_VID_SCALE_3X, vid_resize ? MF_GRAYED : MF_ENABLED); - EnableMenuItem(hmenu, IDM_VID_SCALE_4X, vid_resize ? MF_GRAYED : MF_ENABLED); - win_doresize = 1; - config_save(); - break; - case IDM_VID_REMEMBER: - window_remember = !window_remember; - CheckMenuItem(hmenu, IDM_VID_REMEMBER, window_remember ? MF_CHECKED : MF_UNCHECKED); - GetWindowRect(hwnd, &rect); - if (window_remember) - { - window_x = rect.left; - window_y = rect.top; - window_w = rect.right - rect.left; - window_h = rect.bottom - rect.top; - } - config_save(); - break; +static void +ResetAllMenus(void) +{ +#ifdef ENABLE_LOG_TOGGLES +# ifdef ENABLE_BUSLOGIC_LOG + CheckMenuItem(menuMain, IDM_LOG_BUSLOGIC, MF_UNCHECKED); +# endif +# ifdef ENABLE_CDROM_LOG + CheckMenuItem(menuMain, IDM_LOG_CDROM, MF_UNCHECKED); +# endif +# ifdef ENABLE_D86F_LOG + CheckMenuItem(menuMain, IDM_LOG_D86F, MF_UNCHECKED); +# endif +# ifdef ENABLE_FDC_LOG + CheckMenuItem(menuMain, IDM_LOG_FDC, MF_UNCHECKED); +# endif +# ifdef ENABLE_IDE_LOG + CheckMenuItem(menuMain, IDM_LOG_IDE, MF_UNCHECKED); +# endif +# ifdef ENABLE_SERIAL_LOG + CheckMenuItem(menuMain, IDM_LOG_SERIAL, MF_UNCHECKED); +# endif +# ifdef ENABLE_NIC_LOG + /*FIXME: should be network_setlog(1:0) */ + CheckMenuItem(menuMain, IDM_LOG_NIC, MF_UNCHECKED); +# endif +#endif - case IDM_VID_DDRAW: - case IDM_VID_D3D: - startblit(); - video_wait_for_blit(); - CheckMenuItem(hmenu, IDM_VID_DDRAW + vid_api, MF_UNCHECKED); - vid_apis[0][vid_api].close(); - vid_api = LOWORD(wParam) - IDM_VID_DDRAW; - CheckMenuItem(hmenu, IDM_VID_DDRAW + vid_api, MF_CHECKED); - vid_apis[0][vid_api].init(hwndRender); - endblit(); - config_save(); - device_force_redraw(); - cgapal_rebuild(); - break; + CheckMenuItem(menuMain, IDM_VID_FORCE43, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_OVERSCAN, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_INVERT, MF_UNCHECKED); - case IDM_VID_FULLSCREEN: - if(video_fullscreen != 1) - { - if (video_fullscreen_first) - { - video_fullscreen_first = 0; - msgbox_info(ghwnd, IDS_2074); - } + CheckMenuItem(menuMain, IDM_VID_RESIZE, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_DDRAW+0, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_DDRAW+1, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_FS_FULL+0, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_FS_FULL+1, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_FS_FULL+2, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_FS_FULL+3, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_REMEMBER, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_SCALE_1X+0, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_SCALE_1X+1, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_SCALE_1X+2, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_SCALE_1X+3, MF_UNCHECKED); - startblit(); - video_wait_for_blit(); - mouse_close(); - vid_apis[0][vid_api].close(); - video_fullscreen = 1; - vid_apis[1][vid_api].init(ghwnd); - mouse_init(); - leave_fullscreen_flag = 0; - endblit(); - config_save(); - device_force_redraw(); - cgapal_rebuild(); - } - break; - - case IDM_VID_FS_FULL: - case IDM_VID_FS_43: - case IDM_VID_FS_SQ: - case IDM_VID_FS_INT: - CheckMenuItem(hmenu, IDM_VID_FS_FULL + video_fullscreen_scale, MF_UNCHECKED); - video_fullscreen_scale = LOWORD(wParam) - IDM_VID_FS_FULL; - CheckMenuItem(hmenu, IDM_VID_FS_FULL + video_fullscreen_scale, MF_CHECKED); - config_save(); - device_force_redraw(); - break; - - case IDM_VID_SCALE_1X: - case IDM_VID_SCALE_2X: - case IDM_VID_SCALE_3X: - case IDM_VID_SCALE_4X: - CheckMenuItem(hmenu, IDM_VID_SCALE_1X + scale, MF_UNCHECKED); - scale = LOWORD(wParam) - IDM_VID_SCALE_1X; - CheckMenuItem(hmenu, IDM_VID_SCALE_1X + scale, MF_CHECKED); - config_save(); - device_force_redraw(); - break; - - case IDM_VID_FORCE43: - video_toggle_option(hmenu, &force_43, IDM_VID_FORCE43); - break; - - case IDM_VID_INVERT: - video_toggle_option(hmenu, &invert_display, IDM_VID_INVERT); - break; - - case IDM_VID_OVERSCAN: - update_overscan = 1; - video_toggle_option(hmenu, &enable_overscan, IDM_VID_OVERSCAN); - break; - - case IDM_VID_CGACON: - vid_cga_contrast ^= 1; - CheckMenuItem(hmenu, IDM_VID_CGACON, vid_cga_contrast ? MF_CHECKED : MF_UNCHECKED); - cgapal_rebuild(); - config_save(); - break; - - case IDM_VID_GRAYCT_601: - case IDM_VID_GRAYCT_709: - case IDM_VID_GRAYCT_AVE: - CheckMenuItem(hmenu, IDM_VID_GRAYCT_601 + video_graytype, MF_UNCHECKED); - video_graytype = LOWORD(wParam) - IDM_VID_GRAYCT_601; - CheckMenuItem(hmenu, IDM_VID_GRAYCT_601 + video_graytype, MF_CHECKED); - config_save(); - device_force_redraw(); - break; - - case IDM_VID_GRAY_RGB: - case IDM_VID_GRAY_MONO: - case IDM_VID_GRAY_AMBER: - case IDM_VID_GRAY_GREEN: - case IDM_VID_GRAY_WHITE: - CheckMenuItem(hmenu, IDM_VID_GRAY_RGB + video_grayscale, MF_UNCHECKED); - video_grayscale = LOWORD(wParam) - IDM_VID_GRAY_RGB; - CheckMenuItem(hmenu, IDM_VID_GRAY_RGB + video_grayscale, MF_CHECKED); - config_save(); - device_force_redraw(); - break; + CheckMenuItem(menuMain, IDM_VID_CGACON, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_GRAYCT_601+0, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_GRAYCT_601+1, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_GRAYCT_601+2, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_GRAY_RGB+0, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_GRAY_RGB+1, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_GRAY_RGB+2, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_GRAY_RGB+3, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_GRAY_RGB+4, MF_UNCHECKED); #ifdef ENABLE_LOG_TOGGLES -#ifdef ENABLE_BUSLOGIC_LOG - case IDM_LOG_BUSLOGIC: - buslogic_do_log ^= 1; - CheckMenuItem(hmenu, IDM_LOG_BUSLOGIC, buslogic_do_log ? MF_CHECKED : MF_UNCHECKED); - break; +# ifdef ENABLE_BUSLOGIC_LOG + CheckMenuItem(menuMain, IDM_LOG_BUSLOGIC, buslogic_do_log?MF_CHECKED:MF_UNCHECKED); +# endif +# ifdef ENABLE_CDROM_LOG + CheckMenuItem(menuMain, IDM_LOG_CDROM, cdrom_do_log?MF_CHECKED:MF_UNCHECKED); +# endif +# ifdef ENABLE_D86F_LOG + CheckMenuItem(menuMain, IDM_LOG_D86F, d86f_do_log?MF_CHECKED:MF_UNCHECKED); +# endif +# ifdef ENABLE_FDC_LOG + CheckMenuItem(menuMain, IDM_LOG_FDC, fdc_do_log?MF_CHECKED:MF_UNCHECKED); +# endif +# ifdef ENABLE_IDE_LOG + CheckMenuItem(menuMain, IDM_LOG_IDE, ide_do_log?MF_CHECKED:MF_UNCHECKED); +# endif +# ifdef ENABLE_SERIAL_LOG + CheckMenuItem(menuMain, IDM_LOG_SERIAL, serial_do_log?MF_CHECKED:MF_UNCHECKED); +# endif +# ifdef ENABLE_NIC_LOG + /*FIXME: should be network_setlog(1:0) */ + CheckMenuItem(menuMain, IDM_LOG_NIC, nic_do_log?MF_CHECKED:MF_UNCHECKED); +# endif #endif -#ifdef ENABLE_CDROM_LOG - case IDM_LOG_CDROM: - cdrom_do_log ^= 1; - CheckMenuItem(hmenu, IDM_LOG_CDROM, cdrom_do_log ? MF_CHECKED : MF_UNCHECKED); - break; -#endif + CheckMenuItem(menuMain, IDM_VID_FORCE43, force_43?MF_CHECKED:MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_OVERSCAN, enable_overscan?MF_CHECKED:MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_INVERT, invert_display ? MF_CHECKED : MF_UNCHECKED); -#ifdef ENABLE_D86F_LOG - case IDM_LOG_D86F: - d86f_do_log ^= 1; - CheckMenuItem(hmenu, IDM_LOG_D86F, d86f_do_log ? MF_CHECKED : MF_UNCHECKED); - break; -#endif + if (vid_resize) + CheckMenuItem(menuMain, IDM_VID_RESIZE, MF_CHECKED); + CheckMenuItem(menuMain, IDM_VID_DDRAW + vid_api, MF_CHECKED); + CheckMenuItem(menuMain, IDM_VID_FS_FULL + video_fullscreen_scale, MF_CHECKED); + CheckMenuItem(menuMain, IDM_VID_REMEMBER, window_remember?MF_CHECKED:MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_SCALE_1X + scale, MF_CHECKED); -#ifdef ENABLE_FDC_LOG - case IDM_LOG_FDC: - fdc_do_log ^= 1; - CheckMenuItem(hmenu, IDM_LOG_FDC, fdc_do_log ? MF_CHECKED : MF_UNCHECKED); - break; -#endif + CheckMenuItem(menuMain, IDM_VID_CGACON, vid_cga_contrast?MF_CHECKED:MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_GRAYCT_601 + video_graytype, MF_CHECKED); + CheckMenuItem(menuMain, IDM_VID_GRAY_RGB + video_grayscale, MF_CHECKED); +} -#ifdef ENABLE_IDE_LOG - case IDM_LOG_IDE: - ide_do_log ^= 1; - CheckMenuItem(hmenu, IDM_LOG_IDE, ide_do_log ? MF_CHECKED : MF_UNCHECKED); - break; -#endif -#ifdef ENABLE_SERIAL_LOG - case IDM_LOG_SERIAL: - serial_do_log ^= 1; - CheckMenuItem(hmenu, IDM_LOG_SERIAL, serial_do_log ? MF_CHECKED : MF_UNCHECKED); - break; -#endif +static LRESULT CALLBACK +LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) +{ + BOOL bControlKeyDown; + KBDLLHOOKSTRUCT* p; -#ifdef ENABLE_NIC_LOG - case IDM_LOG_NIC: - /*FIXME: should be network_setlog() */ - nic_do_log ^= 1; - CheckMenuItem(hmenu, IDM_LOG_NIC, nic_do_log ? MF_CHECKED : MF_UNCHECKED); - break; -#endif + if (nCode < 0 || nCode != HC_ACTION) + return(CallNextHookEx(hKeyboardHook, nCode, wParam, lParam)); + + p = (KBDLLHOOKSTRUCT*)lParam; + + /* disable alt-tab */ + if (p->vkCode == VK_TAB && p->flags & LLKHF_ALTDOWN) return(1); + + /* disable alt-space */ + if (p->vkCode == VK_SPACE && p->flags & LLKHF_ALTDOWN) return(1); + + /* disable alt-escape */ + if (p->vkCode == VK_ESCAPE && p->flags & LLKHF_ALTDOWN) return(1); + + /* disable windows keys */ + if((p->vkCode == VK_LWIN) || (p->vkCode == VK_RWIN)) return(1); + + /* checks ctrl key pressed */ + bControlKeyDown = GetAsyncKeyState(VK_CONTROL)>>((sizeof(SHORT)*8)-1); + + /* disable ctrl-escape */ + if (p->vkCode == VK_ESCAPE && bControlKeyDown) return(1); + + return(CallNextHookEx(hKeyboardHook, nCode, wParam, lParam)); +} + + +static LRESULT CALLBACK +MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + static wchar_t wOldTitle[512]; + HMENU hmenu; + RECT rect; + int i = 0; + + switch (message) { + case WM_CREATE: + SetTimer(hwnd, TIMER_1SEC, 1000, NULL); + hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, + LowLevelKeyboardProc, + GetModuleHandle(NULL), 0); + hook_enabled = 1; + break; + + case WM_COMMAND: + hmenu = GetMenu(hwnd); + switch (LOWORD(wParam)) { + case IDM_ACTION_SCREENSHOT: + take_screenshot(); + break; + + case IDM_ACTION_HRESET: + win_pc_reset(1); + break; + + case IDM_ACTION_RESET_CAD: + win_pc_reset(0); + break; + + case IDM_ACTION_EXIT: + PostQuitMessage(0); + break; + + case IDM_ACTION_CTRL_ALT_ESC: + pc_send_cae(); + break; + + case IDM_ACTION_PAUSE: + pause ^= 1; + if (pause) { + wcscpy(wOldTitle, wTitle); + wcscat(wTitle, L" - PAUSED -"); + + set_window_title(NULL); + } else + set_window_title(wOldTitle); + break; + + case IDM_CONFIG: + win_settings_open(hwnd); + break; + + case IDM_ABOUT: + AboutDialogCreate(hwnd); + break; + + case IDM_STATUS: + StatusWindowCreate(hwnd); + break; + + case IDM_VID_RESIZE: + vid_resize = !vid_resize; + CheckMenuItem(hmenu, IDM_VID_RESIZE, (vid_resize)? MF_CHECKED : MF_UNCHECKED); + if (vid_resize) + SetWindowLongPtr(hwnd, GWL_STYLE, (WS_OVERLAPPEDWINDOW & ~WS_MINIMIZEBOX) | WS_VISIBLE); + else + SetWindowLongPtr(hwnd, GWL_STYLE, (WS_OVERLAPPEDWINDOW & ~WS_SIZEBOX & ~WS_THICKFRAME & ~WS_MAXIMIZEBOX & ~WS_MINIMIZEBOX) | WS_VISIBLE); + GetWindowRect(hwnd, &rect); + SetWindowPos(hwnd, 0, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER | SWP_FRAMECHANGED); + GetWindowRect(hwndSBAR,&rect); + SetWindowPos(hwndSBAR, 0, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER | SWP_FRAMECHANGED); + if (vid_resize) { + CheckMenuItem(hmenu, IDM_VID_SCALE_1X + scale, MF_UNCHECKED); + CheckMenuItem(hmenu, IDM_VID_SCALE_2X, MF_CHECKED); + scale = 1; + } + EnableMenuItem(hmenu, IDM_VID_SCALE_1X, vid_resize ? MF_GRAYED : MF_ENABLED); + EnableMenuItem(hmenu, IDM_VID_SCALE_2X, vid_resize ? MF_GRAYED : MF_ENABLED); + EnableMenuItem(hmenu, IDM_VID_SCALE_3X, vid_resize ? MF_GRAYED : MF_ENABLED); + EnableMenuItem(hmenu, IDM_VID_SCALE_4X, vid_resize ? MF_GRAYED : MF_ENABLED); + win_doresize = 1; + config_save(); + break; + + case IDM_VID_REMEMBER: + window_remember = !window_remember; + CheckMenuItem(hmenu, IDM_VID_REMEMBER, window_remember ? MF_CHECKED : MF_UNCHECKED); + GetWindowRect(hwnd, &rect); + if (window_remember) { + window_x = rect.left; + window_y = rect.top; + window_w = rect.right - rect.left; + window_h = rect.bottom - rect.top; + } + config_save(); + break; + + case IDM_VID_DDRAW: + case IDM_VID_D3D: + startblit(); + video_wait_for_blit(); + CheckMenuItem(hmenu, IDM_VID_DDRAW + vid_api, MF_UNCHECKED); + vid_apis[0][vid_api].close(); + vid_api = LOWORD(wParam) - IDM_VID_DDRAW; + CheckMenuItem(hmenu, IDM_VID_DDRAW + vid_api, MF_CHECKED); + vid_apis[0][vid_api].init(hwndRender); + endblit(); + config_save(); + device_force_redraw(); + cgapal_rebuild(); + break; + + case IDM_VID_FULLSCREEN: + if (video_fullscreen == 1) break; + + if (video_fullscreen_first) { + video_fullscreen_first = 0; + msgbox_info(hwndMain, IDS_2074); + } + + startblit(); + video_wait_for_blit(); + mouse_close(); + vid_apis[0][vid_api].close(); + video_fullscreen = 1; + vid_apis[1][vid_api].init(hwndMain); + mouse_init(); + leave_fullscreen_flag = 0; + endblit(); + config_save(); + device_force_redraw(); + cgapal_rebuild(); + break; + + case IDM_VID_FS_FULL: + case IDM_VID_FS_43: + case IDM_VID_FS_SQ: + case IDM_VID_FS_INT: + CheckMenuItem(hmenu, IDM_VID_FS_FULL + video_fullscreen_scale, MF_UNCHECKED); + video_fullscreen_scale = LOWORD(wParam) - IDM_VID_FS_FULL; + CheckMenuItem(hmenu, IDM_VID_FS_FULL + video_fullscreen_scale, MF_CHECKED); + config_save(); + device_force_redraw(); + break; + + case IDM_VID_SCALE_1X: + case IDM_VID_SCALE_2X: + case IDM_VID_SCALE_3X: + case IDM_VID_SCALE_4X: + CheckMenuItem(hmenu, IDM_VID_SCALE_1X + scale, MF_UNCHECKED); + scale = LOWORD(wParam) - IDM_VID_SCALE_1X; + CheckMenuItem(hmenu, IDM_VID_SCALE_1X + scale, MF_CHECKED); + config_save(); + device_force_redraw(); + break; + + case IDM_VID_FORCE43: + video_toggle_option(hmenu, &force_43, IDM_VID_FORCE43); + break; + + case IDM_VID_INVERT: + video_toggle_option(hmenu, &invert_display, IDM_VID_INVERT); + break; + + case IDM_VID_OVERSCAN: + update_overscan = 1; + video_toggle_option(hmenu, &enable_overscan, IDM_VID_OVERSCAN); + break; + + case IDM_VID_CGACON: + vid_cga_contrast ^= 1; + CheckMenuItem(hmenu, IDM_VID_CGACON, vid_cga_contrast ? MF_CHECKED : MF_UNCHECKED); + cgapal_rebuild(); + config_save(); + break; + + case IDM_VID_GRAYCT_601: + case IDM_VID_GRAYCT_709: + case IDM_VID_GRAYCT_AVE: + CheckMenuItem(hmenu, IDM_VID_GRAYCT_601 + video_graytype, MF_UNCHECKED); + video_graytype = LOWORD(wParam) - IDM_VID_GRAYCT_601; + CheckMenuItem(hmenu, IDM_VID_GRAYCT_601 + video_graytype, MF_CHECKED); + config_save(); + device_force_redraw(); + break; + + case IDM_VID_GRAY_RGB: + case IDM_VID_GRAY_MONO: + case IDM_VID_GRAY_AMBER: + case IDM_VID_GRAY_GREEN: + case IDM_VID_GRAY_WHITE: + CheckMenuItem(hmenu, IDM_VID_GRAY_RGB + video_grayscale, MF_UNCHECKED); + video_grayscale = LOWORD(wParam) - IDM_VID_GRAY_RGB; + CheckMenuItem(hmenu, IDM_VID_GRAY_RGB + video_grayscale, MF_CHECKED); + config_save(); + device_force_redraw(); + break; + +#ifdef ENABLE_LOG_TOGGLES +# ifdef ENABLE_BUSLOGIC_LOG + case IDM_LOG_BUSLOGIC: + buslogic_do_log ^= 1; + CheckMenuItem(hmenu, IDM_LOG_BUSLOGIC, buslogic_do_log ? MF_CHECKED : MF_UNCHECKED); + break; +# endif + +# ifdef ENABLE_CDROM_LOG + case IDM_LOG_CDROM: + cdrom_do_log ^= 1; + CheckMenuItem(hmenu, IDM_LOG_CDROM, cdrom_do_log ? MF_CHECKED : MF_UNCHECKED); + break; +# endif + +# ifdef ENABLE_D86F_LOG + case IDM_LOG_D86F: + d86f_do_log ^= 1; + CheckMenuItem(hmenu, IDM_LOG_D86F, d86f_do_log ? MF_CHECKED : MF_UNCHECKED); + break; +# endif + +# ifdef ENABLE_FDC_LOG + case IDM_LOG_FDC: + fdc_do_log ^= 1; + CheckMenuItem(hmenu, IDM_LOG_FDC, fdc_do_log ? MF_CHECKED : MF_UNCHECKED); + break; +# endif + +# ifdef ENABLE_IDE_LOG + case IDM_LOG_IDE: + ide_do_log ^= 1; + CheckMenuItem(hmenu, IDM_LOG_IDE, ide_do_log ? MF_CHECKED : MF_UNCHECKED); + break; +# endif + +# ifdef ENABLE_SERIAL_LOG + case IDM_LOG_SERIAL: + serial_do_log ^= 1; + CheckMenuItem(hmenu, IDM_LOG_SERIAL, serial_do_log ? MF_CHECKED : MF_UNCHECKED); + break; +# endif + +# ifdef ENABLE_NIC_LOG + case IDM_LOG_NIC: + /*FIXME: should be network_setlog() */ + nic_do_log ^= 1; + CheckMenuItem(hmenu, IDM_LOG_NIC, nic_do_log ? MF_CHECKED : MF_UNCHECKED); + break; +# endif #endif #ifdef ENABLE_LOG_BREAKPOINT - case IDM_LOG_BREAKPOINT: - pclog("---- LOG BREAKPOINT ----\n"); - break; + case IDM_LOG_BREAKPOINT: + pclog("---- LOG BREAKPOINT ----\n"); + break; #endif #ifdef ENABLE_VRAM_DUMP - case IDM_DUMP_VRAM: - svga_dump_vram(); - break; + case IDM_DUMP_VRAM: + svga_dump_vram(); + break; #endif - case IDM_CONFIG_LOAD: - pause = 1; - if (!file_dlg_st(hwnd, IDS_2160, "", 0)) - { - if (msgbox_reset_yn(ghwnd) == IDYES) + case IDM_CONFIG_LOAD: + pause = 1; + if (! file_dlg_st(hwnd, IDS_2160, "", 0)) { + if (msgbox_reset_yn(hwndMain) == IDYES) { + config_write(config_file_default); + for (i = 0; i < FDD_NUM; i++) { - config_write(config_file_default); - for (i = 0; i < FDD_NUM; i++) - { - floppy_close(i); - } - for (i = 0; i < CDROM_NUM; i++) - { - cdrom_drives[i].handler->exit(i); - if (cdrom_drives[i].host_drive == 200) - { - image_close(i); - } - else if ((cdrom_drives[i].host_drive >= 'A') && (cdrom_drives[i].host_drive <= 'Z')) - { - ioctl_close(i); - } - else - { - null_close(i); - } - } - resetpchard_close(); - config_load(wopenfilestring); - for (i = 0; i < CDROM_NUM; i++) - { - if (cdrom_drives[i].bus_type) - { - SCSIReset(cdrom_drives[i].scsi_device_id, cdrom_drives[i].scsi_device_lun); - } - - if (cdrom_drives[i].host_drive == 200) - { - image_open(i, cdrom_image[i].image_path); - } - else if ((cdrom_drives[i].host_drive >= 'A') && (cdrom_drives[i].host_drive <= 'Z')) - { - ioctl_open(i, cdrom_drives[i].host_drive); - } - else - { - cdrom_null_open(i, cdrom_drives[i].host_drive); - } - } - - floppy_load(0, floppyfns[0]); - floppy_load(1, floppyfns[1]); - floppy_load(2, floppyfns[2]); - floppy_load(3, floppyfns[3]); - - /* pclog_w(L"NVR path: %s\n", nvr_path); */ - mem_resize(); - rom_load_bios(romset); - network_init(); - reset_menus(); - update_status_bar_panes(hwndStatus); - resetpchard_init(); + floppy_close(i); } - } - pause = 0; - break; + for (i = 0; i < CDROM_NUM; i++) + { + cdrom_drives[i].handler->exit(i); + if (cdrom_drives[i].host_drive == 200) + { + image_close(i); + } + else if ((cdrom_drives[i].host_drive >= 'A') && (cdrom_drives[i].host_drive <= 'Z')) + { + ioctl_close(i); + } + else + { + null_close(i); + } + } + pc_reset_hard_close(); + config_load(wopenfilestring); + for (i = 0; i < CDROM_NUM; i++) + { + if (cdrom_drives[i].bus_type) + { + SCSIReset(cdrom_drives[i].scsi_device_id, cdrom_drives[i].scsi_device_lun); + } - case IDM_CONFIG_SAVE: - pause = 1; - if (!file_dlg_st(hwnd, IDS_2160, "", 1)) - { - config_write(wopenfilestring); - } - pause = 0; - break; - } - return 0; + if (cdrom_drives[i].host_drive == 200) + { + image_open(i, cdrom_image[i].image_path); + } + else if ((cdrom_drives[i].host_drive >= 'A') && (cdrom_drives[i].host_drive <= 'Z')) + { + ioctl_open(i, cdrom_drives[i].host_drive); + } + else + { + cdrom_null_open(i, cdrom_drives[i].host_drive); + } + } - case WM_INPUT: - process_raw_input(lParam, infocus); - break; + floppy_load(0, floppyfns[0]); + floppy_load(1, floppyfns[1]); + floppy_load(2, floppyfns[2]); + floppy_load(3, floppyfns[3]); - case WM_SETFOCUS: - infocus=1; - if (!hook_enabled) - { - hKeyboardHook = SetWindowsHookEx( WH_KEYBOARD_LL, LowLevelKeyboardProc, GetModuleHandle(NULL), 0 ); - hook_enabled = 1; - } - break; - - case WM_KILLFOCUS: - infocus=0; - if (mousecapture) - { - ClipCursor(&oldclip); - ShowCursor(TRUE); - mousecapture=0; - } - memset(recv_key, 0, sizeof(recv_key)); - if (video_fullscreen) - { - leave_fullscreen_flag = 1; - } - if (hook_enabled) - { - UnhookWindowsHookEx(hKeyboardHook); - hook_enabled = 0; - } - break; - - case WM_LBUTTONUP: - if (!mousecapture && !video_fullscreen) - { - GetClipCursor(&oldclip); - GetWindowRect(hwndRender, &rect); - - ClipCursor(&rect); - mousecapture = 1; - while (1) - { - if (ShowCursor(FALSE) < 0) - { - break; + mem_resize(); + rom_load_bios(romset); + network_init(); + ResetAllMenus(); + StatusBarUpdatePanes(); + pc_reset_hard_init(); } } + pause = 0; + break; + + case IDM_CONFIG_SAVE: + pause = 1; + if (! file_dlg_st(hwnd, IDS_2160, "", 1)) { + config_write(wopenfilestring); + } + pause = 0; + break; + } + return(0); + + case WM_INPUT: + process_raw_input(lParam, infocus); + break; + + case WM_SETFOCUS: + infocus = 1; + if (! hook_enabled) { + hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, + LowLevelKeyboardProc, + GetModuleHandle(NULL), + 0); + hook_enabled = 1; + } + break; + + case WM_KILLFOCUS: + infocus = 0; + releasemouse(); + memset(recv_key, 0, sizeof(recv_key)); + if (video_fullscreen) + leave_fullscreen_flag = 1; + if (hook_enabled) { + UnhookWindowsHookEx(hKeyboardHook); + hook_enabled = 0; + } + break; + + case WM_LBUTTONUP: + if (!mousecapture && !video_fullscreen) { + GetClipCursor(&oldclip); + GetWindowRect(hwndRender, &rect); + + ClipCursor(&rect); + mousecapture = 1; + while (1) { + if (ShowCursor(FALSE) < 0) break; } - break; + } + break; - case WM_MBUTTONUP: - if (!(mouse_get_type(mouse_type) & MOUSE_TYPE_3BUTTON)) - { - releasemouse(); - } - break; + case WM_MBUTTONUP: + if (!(mouse_get_type(mouse_type) & MOUSE_TYPE_3BUTTON)) { + releasemouse(); + } + break; - case WM_ENTERMENULOOP: - break; + case WM_ENTERMENULOOP: + break; - case WM_SIZE: - winsizex = (lParam & 0xFFFF); - winsizey = (lParam >> 16) - (17 + 6); + case WM_SIZE: + winsizex = (lParam & 0xFFFF); + winsizey = (lParam >> 16) - (17 + 6); + if (winsizey < 0) + winsizey = 0; - if (winsizey < 0) - { - winsizey = 0; - } + MoveWindow(hwndSBAR, 0, winsizey + 6, winsizex, 17, TRUE); + if (hwndRender != NULL) { MoveWindow(hwndRender, 0, 0, winsizex, winsizey, TRUE); - if (vid_apis[video_fullscreen][vid_api].resize) - { + if (vid_apis[video_fullscreen][vid_api].resize) { startblit(); video_wait_for_blit(); vid_apis[video_fullscreen][vid_api].resize(winsizex, winsizey); endblit(); } - MoveWindow(hwndStatus, 0, winsizey + 6, winsizex, 17, TRUE); - - if (mousecapture) - { + if (mousecapture) { GetWindowRect(hwndRender, &rect); ClipCursor(&rect); } + } - if (window_remember) - { - GetWindowRect(hwnd, &rect); - window_x = rect.left; - window_y = rect.top; - window_w = rect.right - rect.left; - window_h = rect.bottom - rect.top; - save_window_pos = 1; - } + if (window_remember) { + GetWindowRect(hwnd, &rect); + window_x = rect.left; + window_y = rect.top; + window_w = rect.right - rect.left; + window_h = rect.bottom - rect.top; + save_window_pos = 1; + } - config_save(); - break; + config_save(); + break; - case WM_MOVE: - if (window_remember) - { - GetWindowRect(hwnd, &rect); - window_x = rect.left; - window_y = rect.top; - window_w = rect.right - rect.left; - window_h = rect.bottom - rect.top; - save_window_pos = 1; - } - break; + case WM_MOVE: + if (window_remember) { + GetWindowRect(hwnd, &rect); + window_x = rect.left; + window_y = rect.top; + window_w = rect.right - rect.left; + window_h = rect.bottom - rect.top; + save_window_pos = 1; + } + break; - case WM_TIMER: - if (wParam == TIMER_1SEC) - { - onesec(); - } - break; + case WM_TIMER: + if (wParam == TIMER_1SEC) { + onesec(); + } + break; - case WM_RESETD3D: - startblit(); - if (video_fullscreen) - { - d3d_fs_reset(); - } - else - { - d3d_reset(); - } - endblit(); - break; + case WM_RESETD3D: + startblit(); + if (video_fullscreen) + d3d_fs_reset(); + else + d3d_reset(); + endblit(); + break; - case WM_LEAVEFULLSCREEN: - startblit(); - mouse_close(); - vid_apis[1][vid_api].close(); - video_fullscreen = 0; - config_save(); - vid_apis[0][vid_api].init(hwndRender); - mouse_init(); - endblit(); - device_force_redraw(); - cgapal_rebuild(); - break; + case WM_LEAVEFULLSCREEN: + startblit(); + mouse_close(); + vid_apis[1][vid_api].close(); + video_fullscreen = 0; + config_save(); + vid_apis[0][vid_api].init(hwndRender); + mouse_init(); + endblit(); + device_force_redraw(); + cgapal_rebuild(); + break; - case WM_KEYDOWN: - case WM_SYSKEYDOWN: - case WM_KEYUP: - case WM_SYSKEYUP: - return 0; + case WM_KEYDOWN: + case WM_SYSKEYDOWN: + case WM_KEYUP: + case WM_SYSKEYUP: + return 0; - case WM_DESTROY: - UnhookWindowsHookEx(hKeyboardHook); - KillTimer(hwnd, TIMER_1SEC); - PostQuitMessage (0); /* send a WM_QUIT to the message queue */ - break; + case WM_DESTROY: + UnhookWindowsHookEx(hKeyboardHook); + KillTimer(hwnd, TIMER_1SEC); + PostQuitMessage (0); /* send WM_QUIT to message queue */ + break; - case WM_SYSCOMMAND: - /* Disable ALT key *ALWAYS*, I don't think there's any use for reaching the menu that way. */ - if (wParam == SC_KEYMENU && HIWORD(lParam) <= 0) - { - return 0; /*disable ALT key for menu*/ - } + case WM_SYSCOMMAND: + /* + * Disable ALT key *ALWAYS*, + * I don't think there's any use for + * reaching the menu that way. + */ + if (wParam == SC_KEYMENU && HIWORD(lParam) <= 0) { + return 0; /*disable ALT key for menu*/ + } - default: - return DefWindowProc (hwnd, message, wParam, lParam); - } - return 0; + default: + return(DefWindowProc(hwnd, message, wParam, lParam)); + } + + return(0); } -LRESULT CALLBACK subWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) + +static LRESULT CALLBACK +SubWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { - switch (message) - { - default: - return DefWindowProc(hwnd, message, wParam, lParam); - } - return 0; + return(DefWindowProc(hwnd, message, wParam, lParam)); } -VOID APIENTRY HandlePopupMenu(HWND hwnd, POINT pt, int id) + +/* Create a console if we don't already have one. */ +static void +CreateConsole(int init) { - if (id >= (sb_parts - 1)) - { - return; - } - pt.x = id * SB_ICON_WIDTH; /* Justify to the left. */ - pt.y = 0; /* Justify to the top. */ - ClientToScreen(hwnd, (LPPOINT) &pt); - TrackPopupMenu(sb_menu_handles[id], TPM_LEFTALIGN | TPM_BOTTOMALIGN | TPM_LEFTBUTTON, pt.x, pt.y, 0, hwndStatus, NULL); + HANDLE h; + FILE *fp; + fpos_t p; + int i; + + if (! init) { + FreeConsole(); + return; + } + + /* Are we logging to a file? */ + p = 0; + (void)fgetpos(stdout, &p); + if (p != -1) return; + + /* Not logging to file, attach to console. */ + if (! AttachConsole(ATTACH_PARENT_PROCESS)) { + /* Parent has no console, create one. */ + AllocConsole(); + } + + h = GetStdHandle(STD_OUTPUT_HANDLE); + i = _open_osfhandle((long)h, _O_TEXT); + fp = _fdopen(i, "w"); + setvbuf(fp, NULL, _IONBF, 1); + *stdout = *fp; + + h = GetStdHandle(STD_ERROR_HANDLE); + i = _open_osfhandle((long)h, _O_TEXT); + fp = _fdopen(i, "w"); + setvbuf(fp, NULL, _IONBF, 1); + *stderr = *fp; + +#if 0 + /* Set up stdin as well. */ + h = GetStdHandle(STD_INPUT_HANDLE); + i = _open_osfhandle((long)h, _O_TEXT); + fp = _fdopen(i, "r"); + setvbuf(fp, NULL, _IONBF, 128); + *stdin = *fp; +#endif } -LRESULT CALLBACK StatusBarProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) + +/* Process the commandline, and create standard argc/argv array. */ +static void +ProcessCommandLine(void) { - RECT rc; - POINT pt; + WCHAR *cmdline; + int argc_max; + int i, q; - WCHAR temp_image_path[1024]; - int new_cdrom_drive; - int ret = 0; - int item_id = 0; - int item_params = 0; - int id = 0; - int part = 0; - int letter = 0; + cmdline = GetCommandLine(); + i = wcslen(cmdline) + 1; + argbuf = malloc(i * 2); + memcpy(argbuf, cmdline, i * 2); - switch (message) - { - case WM_COMMAND: - item_id = LOWORD(wParam) & 0xff00; /* Mask out the low 8 bits for item ID. */ - item_params = LOWORD(wParam) & 0x00ff; /* Mask out the high 8 bits for item parameter. */ + argc = 0; + argc_max = 64; + argv = malloc(sizeof(wchar_t *) * argc_max); + if (argv == NULL) { + free(argbuf); + return; + } - switch (item_id) - { - case IDM_FLOPPY_IMAGE_EXISTING: - case IDM_FLOPPY_IMAGE_EXISTING_WP: - id = item_params & 0x0003; - part = find_status_bar_part(SB_FLOPPY | id); - if ((part == -1) || (sb_menu_handles == NULL)) - { - break; - } + /* parse commandline into argc/argv format */ + i = 0; + while (argbuf[i]) { + while (argbuf[i] == L' ') + i++; - ret = file_dlg_w_st(hwnd, IDS_2159, floppyfns[id], 0); - if (!ret) - { - floppy_close(id); - ui_writeprot[id] = (item_id == IDM_FLOPPY_IMAGE_EXISTING_WP) ? 1 : 0; - floppy_load(id, wopenfilestring); - update_status_bar_icon_state(SB_FLOPPY | id, wcslen(floppyfns[id]) ? 0 : 1); - EnableMenuItem(sb_menu_handles[part], IDM_FLOPPY_EJECT | id, MF_BYCOMMAND | (wcslen(floppyfns[id]) ? MF_ENABLED : MF_GRAYED)); - update_tip(SB_FLOPPY | id); - config_save(); - } - break; + if (argbuf[i]) { + if ((argbuf[i] == L'\'') || (argbuf[i] == L'"')) { + q = argbuf[i++]; + if (!argbuf[i]) + break; + } else + q = 0; - case IDM_FLOPPY_EJECT: - id = item_params & 0x0003; - part = find_status_bar_part(SB_FLOPPY | id); - if ((part == -1) || (sb_menu_handles == NULL)) - { - break; - } + argv[argc++] = &argbuf[i]; - floppy_close(id); - update_status_bar_icon_state(SB_FLOPPY | id, 1); - EnableMenuItem(sb_menu_handles[part], IDM_FLOPPY_EJECT | id, MF_BYCOMMAND | MF_GRAYED); - update_tip(SB_FLOPPY | id); - config_save(); - break; - - case IDM_CDROM_MUTE: - id = item_params & 0x0007; - part = find_status_bar_part(SB_CDROM | id); - if ((part == -1) || (sb_menu_handles == NULL)) - { - break; - } - - cdrom_drives[id].sound_on ^= 1; - CheckMenuItem(sb_menu_handles[part], IDM_CDROM_MUTE | id, cdrom_drives[id].sound_on ? MF_UNCHECKED : MF_CHECKED); - config_save(); - sound_cd_thread_reset(); - break; - - case IDM_CDROM_EMPTY: - id = item_params & 0x0007; - cdrom_eject(id); - break; - - case IDM_CDROM_RELOAD: - id = item_params & 0x0007; - cdrom_reload(id); - break; - - case IDM_CDROM_IMAGE: - id = item_params & 0x0007; - part = find_status_bar_part(SB_CDROM | id); - if ((part == -1) || (sb_menu_handles == NULL)) - { - break; - } - - if (!file_dlg_w_st(hwnd, IDS_2075, cdrom_image[id].image_path, 0)) - { - cdrom_drives[id].prev_host_drive = cdrom_drives[id].host_drive; - wcscpy(temp_image_path, wopenfilestring); - if ((wcscmp(cdrom_image[id].image_path, temp_image_path) == 0) && (cdrom_drives[id].host_drive == 200)) - { - /* Switching from image to the same image. Do nothing. */ - break; - } - wcscpy(cdrom_image[id].prev_image_path, cdrom_image[id].image_path); - cdrom_drives[id].handler->exit(id); - cdrom_close(id); - image_open(id, temp_image_path); - /* Signal media change to the emulated machine. */ - cdrom_insert(id); - CheckMenuItem(sb_menu_handles[part], IDM_CDROM_EMPTY | id, MF_UNCHECKED); - if ((cdrom_drives[id].host_drive >= 'A') && (cdrom_drives[id].host_drive <= 'Z')) - { - CheckMenuItem(sb_menu_handles[part], IDM_CDROM_HOST_DRIVE | id | ((cdrom_drives[id].host_drive - 'A') << 3), MF_UNCHECKED); - } - cdrom_drives[id].host_drive = (wcslen(cdrom_image[id].image_path) == 0) ? 0 : 200; - if (cdrom_drives[id].host_drive == 200) - { - CheckMenuItem(sb_menu_handles[part], IDM_CDROM_IMAGE | id, MF_CHECKED); - update_status_bar_icon_state(SB_CDROM | id, 0); - } - else - { - CheckMenuItem(sb_menu_handles[part], IDM_CDROM_IMAGE | id, MF_UNCHECKED); - CheckMenuItem(sb_menu_handles[part], IDM_CDROM_EMPTY | id, MF_UNCHECKED); - update_status_bar_icon_state(SB_CDROM | id, 1); - } - EnableMenuItem(sb_menu_handles[part], IDM_CDROM_RELOAD | id, MF_BYCOMMAND | MF_GRAYED); - update_tip(SB_CDROM | id); - config_save(); - } - break; - - case IDM_CDROM_HOST_DRIVE: - id = item_params & 0x0007; - letter = ((item_params >> 3) & 0x001f) + 'A'; - part = find_status_bar_part(SB_CDROM | id); - if ((part == -1) || (sb_menu_handles == NULL)) - { - break; - } - - new_cdrom_drive = letter; - if (cdrom_drives[id].host_drive == new_cdrom_drive) - { - /* Switching to the same drive. Do nothing. */ - break; - } - cdrom_drives[id].prev_host_drive = cdrom_drives[id].host_drive; - cdrom_drives[id].handler->exit(id); - cdrom_close(id); - ioctl_open(id, new_cdrom_drive); - /* Signal media change to the emulated machine. */ - cdrom_insert(id); - CheckMenuItem(sb_menu_handles[part], IDM_CDROM_EMPTY | id, MF_UNCHECKED); - if ((cdrom_drives[id].host_drive >= 'A') && (cdrom_drives[id].host_drive <= 'Z')) - { - CheckMenuItem(sb_menu_handles[part], IDM_CDROM_HOST_DRIVE | id | ((cdrom_drives[id].host_drive - 'A') << 3), MF_UNCHECKED); - } - CheckMenuItem(sb_menu_handles[part], IDM_CDROM_IMAGE | id, MF_UNCHECKED); - cdrom_drives[id].host_drive = new_cdrom_drive; - CheckMenuItem(sb_menu_handles[part], IDM_CDROM_HOST_DRIVE | id | ((cdrom_drives[id].host_drive - 'A') << 3), MF_CHECKED); - EnableMenuItem(sb_menu_handles[part], IDM_CDROM_RELOAD | id, MF_BYCOMMAND | MF_GRAYED); - update_status_bar_icon_state(SB_CDROM | id, 0); - update_tip(SB_CDROM | id); - config_save(); - break; - - case IDM_RDISK_EJECT: - id = item_params & 0x001f; - removable_disk_eject(id); - break; - - case IDM_RDISK_RELOAD: - id = item_params & 0x001f; - removable_disk_reload(id); - break; - - case IDM_RDISK_SEND_CHANGE: - id = item_params & 0x001f; - scsi_disk_insert(id); - break; - - case IDM_RDISK_IMAGE: - case IDM_RDISK_IMAGE_WP: - id = item_params & 0x001f; - ret = file_dlg_w_st(hwnd, IDS_4106, hdd[id].fn, id); - if (!ret) - { - removable_disk_unload(id); - memset(hdd[id].fn, 0, sizeof(hdd[id].fn)); - wcscpy(hdd[id].fn, wopenfilestring); - hdd[id].wp = (item_id == IDM_RDISK_IMAGE_WP) ? 1 : 0; - scsi_loadhd(hdd[id].scsi_id, hdd[id].scsi_lun, id); - scsi_disk_insert(id); - if (wcslen(hdd[id].fn) > 0) - { - update_status_bar_icon_state(SB_RDISK | id, 0); - EnableMenuItem(sb_menu_handles[part], IDM_RDISK_EJECT | id, MF_BYCOMMAND | MF_ENABLED); - EnableMenuItem(sb_menu_handles[part], IDM_RDISK_RELOAD | id, MF_BYCOMMAND | MF_GRAYED); - EnableMenuItem(sb_menu_handles[part], IDM_RDISK_SEND_CHANGE | id, MF_BYCOMMAND | MF_ENABLED); - } - else - { - update_status_bar_icon_state(SB_RDISK | id, 1); - EnableMenuItem(sb_menu_handles[part], IDM_RDISK_EJECT | id, MF_BYCOMMAND | MF_GRAYED); - EnableMenuItem(sb_menu_handles[part], IDM_RDISK_RELOAD | id, MF_BYCOMMAND | MF_GRAYED); - EnableMenuItem(sb_menu_handles[part], IDM_RDISK_SEND_CHANGE | id, MF_BYCOMMAND | MF_GRAYED); - } - update_tip(SB_RDISK | id); - config_save(); - } - break; - - default: - break; + if (argc >= argc_max) { + argc_max += 64; + argv = realloc(argv, sizeof(wchar_t *) * argc_max); + if (argv == NULL) { + free(argbuf); + return; } - return 0; + } - case WM_LBUTTONDOWN: - case WM_RBUTTONDOWN: - GetClientRect(hwnd, (LPRECT)& rc); - pt.x = GET_X_LPARAM(lParam); - pt.y = GET_Y_LPARAM(lParam); - if (PtInRect((LPRECT) &rc, pt)) - { - HandlePopupMenu(hwnd, pt, (pt.x / SB_ICON_WIDTH)); - } - break; + while ((argbuf[i]) && ((q) + ? (argbuf[i]!=q) : (argbuf[i]!=L' '))) i++; - default: - return CallWindowProc((WNDPROC) OriginalStatusBarProcedure, hwnd, message, wParam, lParam); + if (argbuf[i]) { + argbuf[i] = 0; + i++; + } } - return 0; + } + + argv[argc] = NULL; +} + + +/* @@@ + * For the Windows platform, this is the start of the application. + */ +int WINAPI +WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszArg, int nFunsterStil) +{ + WCHAR title[200]; + WNDCLASSEX wincl; /* buffer for main window's class */ + MSG messages; /* received-messages buffer */ + HWND hwnd; /* handle for our window */ + HACCEL haccel; /* handle to accelerator table */ + int bRet; + LARGE_INTEGER qpc_freq; + + /* Create console window. */ + CreateConsole(1); + + /* Process the command line for options. */ + ProcessCommandLine(); + + /* Pre-initialize the system, this loads the config file. */ + if (! pc_init(argc, argv)) { + /* Detach from console. */ + CreateConsole(0); + return(1); + } + + /* We need this later. */ + hinstance = hInst; + + /* Load common strings from the resource file. */ + win_language_load_common_strings(); + + /* Create our main window's class and register it. */ + wincl.hInstance = hInst; + wincl.lpszClassName = CLASS_NAME; + wincl.lpfnWndProc = MainWindowProcedure; + wincl.style = CS_DBLCLKS; /* Catch double-clicks */ + wincl.cbSize = sizeof(WNDCLASSEX); + wincl.hIcon = LoadIcon(hInst, (LPCTSTR)100); + wincl.hIconSm = LoadIcon(hInst, (LPCTSTR)100); + wincl.hCursor = NULL; + wincl.lpszMenuName = NULL; + wincl.cbClsExtra = 0; + wincl.cbWndExtra = 0; + wincl.hbrBackground = CreateSolidBrush(RGB(0,0,0)); + if (! RegisterClassEx(&wincl)) + return(2); + wincl.lpszClassName = SUB_CLASS_NAME; + wincl.lpfnWndProc = SubWindowProcedure; + if (! RegisterClassEx(&wincl)) + return(2); + + /* Load the Window Menu(s) from the resources. */ + menuMain = LoadMenu(hInst, MENU_NAME); + + /* Set the initial title for the program's main window. */ + _swprintf(title, L"%s v%s", EMU_NAME_W, EMU_VERSION_W); + + /* Now create our main window. */ + hwnd = CreateWindowEx ( + 0, /* no extended possibilites */ + CLASS_NAME, /* class name */ + title, /* Title Text */ +#if 0 + (WS_OVERLAPPEDWINDOW & ~WS_SIZEBOX), /* default window */ +#else + (WS_OVERLAPPEDWINDOW & ~WS_SIZEBOX) | DS_3DLOOK, +#endif + CW_USEDEFAULT, /* Windows decides the position */ + CW_USEDEFAULT, /* where window ends up on the screen */ + 640+(GetSystemMetrics(SM_CXFIXEDFRAME)*2), /* width */ + 480+(GetSystemMetrics(SM_CYFIXEDFRAME)*2)+GetSystemMetrics(SM_CYMENUSIZE)+GetSystemMetrics(SM_CYCAPTION)+1, /* and height in pixels */ + HWND_DESKTOP, /* window is a child to desktop */ + menuMain, /* menu */ + hInst, /* Program Instance handler */ + NULL); /* no Window Creation data */ + hwndMain = hwnd; + + /* Resize the window if needed. */ + if (vid_resize) + SetWindowLongPtr(hwnd, GWL_STYLE, + (WS_OVERLAPPEDWINDOW&~WS_MINIMIZEBOX)); + else + SetWindowLongPtr(hwnd, GWL_STYLE, + (WS_OVERLAPPEDWINDOW&~WS_SIZEBOX&~WS_THICKFRAME&~WS_MAXIMIZEBOX&~WS_MINIMIZEBOX)); + + if (window_remember) + MoveWindow(hwnd, window_x, window_y, window_w, window_h, TRUE); + + /* Reset all menus to their defaults. */ + ResetAllMenus(); + + /* Make the window visible on the screen. */ + ShowWindow(hwnd, nFunsterStil); + + /* Load the accelerator table */ + haccel = LoadAccelerators(hInst, ACCEL_NAME); + if (haccel == NULL) { + MessageBox(hwndMain, + win_language_get_string_from_id(IDS_2053), + win_language_get_string_from_id(IDS_2050), + MB_OK | MB_ICONERROR); + return(3); + } + + /* Initialize the input (keyboard, mouse, game) module. */ + memset(recv_key, 0x00, sizeof(recv_key)); + device.usUsagePage = 0x01; + device.usUsage = 0x06; + device.dwFlags = RIDEV_NOHOTKEYS; + device.hwndTarget = hwnd; + if (! RegisterRawInputDevices(&device, 1, sizeof(device))) { + MessageBox(hwndMain, + win_language_get_string_from_id(IDS_2054), + win_language_get_string_from_id(IDS_2050), + MB_OK | MB_ICONERROR); + return(4); + } + get_registry_key_map(); + + /* Create the status bar window. */ + StatusBarCreate(hwndMain, IDC_STATUS, hInst); + + /* + * Before we can create the Render window, we first have + * to prepare some other things that it depends on. + */ + ghMutex = CreateMutex(NULL, FALSE, L"86Box.BlitMutex"); + + /* Create the Machine Rendering window. */ + hwndRender = CreateWindow(L"STATIC", NULL, WS_VISIBLE|WS_CHILD|SS_BITMAP, + 0, 0, 1, 1, hwnd, NULL, hInst, NULL); + MoveWindow(hwndRender, 0, 0, winsizex, winsizey, TRUE); + + /* Select the best system renderer available. */ + if (! vid_apis[0][vid_api].init(hwndRender)) { + vid_api ^= 1; + if (! vid_apis[0][vid_api].init(hwndRender)) { + MessageBox(hwnd, + win_language_get_string_from_id(IDS_2095), + win_language_get_string_from_id(IDS_2050), + MB_OK | MB_ICONERROR); + return(5); + } + } + + /* Initialize the rendering window, or fullscreen. */ + if (start_in_fullscreen) { + startblit(); + vid_apis[0][vid_api].close(); + video_fullscreen = 1; + vid_apis[1][vid_api].init(hwndRender); + leave_fullscreen_flag = 0; + endblit(); + device_force_redraw(); + } + if (vid_apis[video_fullscreen][vid_api].resize) { + startblit(); + vid_apis[video_fullscreen][vid_api].resize(winsizex, winsizey); + endblit(); + } + + /* Move this to SLiRP. */ + slirpMutex = CreateMutex(NULL, FALSE, L"86Box.SlirpMutex"); + + /* All done, fire up the actual emulated machine. */ + if (! pc_init_modules()) { + /* Dang, no ROMs found at all! */ + MessageBox(hwnd, + win_language_get_string_from_id(IDS_2056), + win_language_get_string_from_id(IDS_2050), + MB_OK | MB_ICONERROR); + return(6); + } + + /* Fire up the machine. */ + pc_reset_hard(); + + /* + * Everything has been configured, and all seems to work, + * so now it is time to start the main thread to do some + * real work, and we will hang in here, dealing with the + * UI until we're done. + */ + timeBeginPeriod(1); + + atexit(releasemouse); + + thMain = (HANDLE)_beginthread(MainThread, 0, NULL); + SetThreadPriority(thMain, THREAD_PRIORITY_HIGHEST); + + QueryPerformanceFrequency(&qpc_freq); + timer_freq = qpc_freq.QuadPart; + + /* Run the message loop. It will run until GetMessage() returns 0 */ + while (! quited) { + bRet = GetMessage(&messages, NULL, 0, 0); + if ((bRet == 0) || quited) break; + + if (bRet == -1) { + fatal("bRet is -1\n"); + } + + if (messages.message == WM_QUIT) { + quited = 1; + break; + } + + if (! TranslateAccelerator(hwnd, haccel, &messages)) { + TranslateMessage(&messages); + DispatchMessage(&messages); + } + + if (recv_key[0x58] && recv_key[0x42] && mousecapture) { + ClipCursor(&oldclip); + ShowCursor(TRUE); + mousecapture = 0; + } + + if ((recv_key[0x1D] || recv_key[0x9D]) && + (recv_key[0x38] || recv_key[0xB8]) && + (recv_key[0x51] || recv_key[0xD1]) && video_fullscreen) { + leave_fullscreen(); + } + } + + /* Why start??? --FvK */ + startblit(); + + Sleep(200); + TerminateThread(thMain, 0); + + nvr_save(); + + config_save(); + + pc_close(); + + vid_apis[video_fullscreen][vid_api].close(); + + timeEndPeriod(1); + + if (mousecapture) { + ClipCursor(&oldclip); + ShowCursor(TRUE); + } + + UnregisterClass(SUB_CLASS_NAME, hInst); + UnregisterClass(CLASS_NAME, hInst); + + return(messages.wParam); +} + + +void +get_executable_name(wchar_t *s, int size) +{ + GetModuleFileName(hinstance, s, size); +} + + +void +set_window_title(wchar_t *s) +{ + if (! video_fullscreen) { + if (s != NULL) + wcscpy(wTitle, s); + else + s = wTitle; + + SetWindowText(hwndMain, s); + } +} + + +uint64_t +timer_read(void) +{ + LARGE_INTEGER li; + + QueryPerformanceCounter(&li); + + return(li.QuadPart); +} + + +uint32_t +get_ticks(void) +{ + return(GetTickCount()); +} + + +void +delay_ms(uint32_t count) +{ + Sleep(count); +} + + +void +startblit(void) +{ + WaitForSingleObject(ghMutex, INFINITE); +} + + +void +endblit(void) +{ + ReleaseMutex(ghMutex); +} + + +void +startslirp(void) +{ + WaitForSingleObject(slirpMutex, INFINITE); +} + + +void +endslirp(void) +{ + ReleaseMutex(slirpMutex); +} + + +void +updatewindowsize(int x, int y) +{ + int owsx = winsizex; + int owsy = winsizey; + int temp_overscan_x = overscan_x; + int temp_overscan_y = overscan_y; + double dx, dy, dtx, dty; + + if (vid_resize) return; + + if (x < 160) x = 160; + if (y < 100) y = 100; + if (x > 2048) x = 2048; + if (y > 2048) y = 2048; + + if (suppress_overscan) + temp_overscan_x = temp_overscan_y = 0; + + unscaled_size_x=x; efwinsizey=y; + + if (force_43) { + dx = (double) x; + dtx = (double) temp_overscan_x; + + dy = (double) y; + dty = (double) temp_overscan_y; + + /* Account for possible overscan. */ + if (temp_overscan_y == 16) { + /* CGA */ + dy = (((dx - dtx) / 4.0) * 3.0) + dty; + } else if (temp_overscan_y < 16) { + /* MDA/Hercules */ + dy = (x / 4.0) * 3.0; + } else { + if (enable_overscan) { + /* EGA/(S)VGA with overscan */ + dy = (((dx - dtx) / 4.0) * 3.0) + dty; + } else { + /* EGA/(S)VGA without overscan */ + dy = (x / 4.0) * 3.0; + } + } + unscaled_size_y = (int) dy; + } else { + unscaled_size_y = efwinsizey; + } + + switch(scale) { + case 0: + winsizex = unscaled_size_x >> 1; + winsizey = unscaled_size_y >> 1; + break; + + case 1: + winsizex = unscaled_size_x; + winsizey = unscaled_size_y; + break; + + case 2: + winsizex = (unscaled_size_x * 3) >> 1; + winsizey = (unscaled_size_y * 3) >> 1; + break; + + case 3: + winsizex = unscaled_size_x << 1; + winsizey = unscaled_size_y << 1; + break; + } + + if ((owsx != winsizex) || (owsy != winsizey)) + win_doresize = 1; + else + win_doresize = 0; +} + + +void +uws_natural(void) +{ + updatewindowsize(unscaled_size_x, efwinsizey); +} + + +void +leave_fullscreen(void) +{ + leave_fullscreen_flag = 1; +} + + +/* + * IODEV stuff, clean up! + */ +void +cdrom_init_host_drives(void) +{ + WCHAR s[64]; + int i = 0; + + host_cdrom_drive_available_num = 0; + for (i='A'; i<='Z'; i++) { + _swprintf(s, L"%c:\\", i); + + if (GetDriveType(s)==DRIVE_CDROM) { + host_cdrom_drive_available[i - 'A'] = 1; + + host_cdrom_drive_available_num++; + } else { + host_cdrom_drive_available[i - 'A'] = 0; + } + } +} + + +void +cdrom_close(uint8_t id) +{ + switch (cdrom_drives[id].host_drive) { + case 0: + null_close(id); + break; + + case 200: + image_close(id); + break; + + default: + ioctl_close(id); + break; + } +} + + +void +cdrom_eject(uint8_t id) +{ + int part; + + part = StatusBarFindPart(SB_CDROM | id); + if ((part == -1) || (sb_menu_handles == NULL)) + return; + + if (cdrom_drives[id].host_drive == 0) { + /* Switch from empty to empty. Do nothing. */ + return; + } + + if ((cdrom_drives[id].host_drive >= 'A') && + (cdrom_drives[id].host_drive <= 'Z')) { + CheckMenuItem(sb_menu_handles[part], IDM_CDROM_HOST_DRIVE | id | ((cdrom_drives[id].host_drive - 'A') << 3), MF_UNCHECKED); + } + if (cdrom_drives[id].host_drive == 200) { + wcscpy(cdrom_image[id].prev_image_path, cdrom_image[id].image_path); + } + cdrom_drives[id].prev_host_drive = cdrom_drives[id].host_drive; + cdrom_drives[id].handler->exit(id); + cdrom_close(id); + cdrom_null_open(id, 0); + if (cdrom_drives[id].bus_type) { + /* Signal disc change to the emulated machine. */ + cdrom_insert(id); + } + CheckMenuItem(sb_menu_handles[part], IDM_CDROM_IMAGE | id, MF_UNCHECKED); + cdrom_drives[id].host_drive=0; + CheckMenuItem(sb_menu_handles[part], IDM_CDROM_EMPTY | id, MF_CHECKED); + StatusBarUpdateIconState(SB_CDROM | id, 1); + EnableMenuItem(sb_menu_handles[part], IDM_CDROM_RELOAD | id, MF_BYCOMMAND | MF_ENABLED); + StatusBarUpdateTip(SB_CDROM | id); + + config_save(); +} + + +void +cdrom_reload(uint8_t id) +{ + int new_cdrom_drive; + int part; + + part = StatusBarFindPart(SB_CDROM | id); + if ((part == -1) || (sb_menu_handles == NULL)) return; + + if ((cdrom_drives[id].host_drive == cdrom_drives[id].prev_host_drive) || (cdrom_drives[id].prev_host_drive == 0) || (cdrom_drives[id].host_drive != 0)) { + /* Switch from empty to empty. Do nothing. */ + return; + } + + cdrom_close(id); + if (cdrom_drives[id].prev_host_drive == 200) { + wcscpy(cdrom_image[id].image_path, cdrom_image[id].prev_image_path); + image_open(id, cdrom_image[id].image_path); + if (cdrom_drives[id].bus_type) { + /* Signal disc change to the emulated machine. */ + cdrom_insert(id); + } + if (wcslen(cdrom_image[id].image_path) == 0) { + CheckMenuItem(sb_menu_handles[part], IDM_CDROM_EMPTY | id, MF_CHECKED); + cdrom_drives[id].host_drive = 0; + CheckMenuItem(sb_menu_handles[part], IDM_CDROM_IMAGE | id, MF_UNCHECKED); + StatusBarUpdateIconState(SB_CDROM | id, 1); + } else { + CheckMenuItem(sb_menu_handles[part], IDM_CDROM_EMPTY | id, MF_UNCHECKED); + cdrom_drives[id].host_drive = 200; + CheckMenuItem(sb_menu_handles[part], IDM_CDROM_IMAGE | id, MF_CHECKED); + StatusBarUpdateIconState(SB_CDROM | id, 0); + } + } else { + new_cdrom_drive = cdrom_drives[id].prev_host_drive; + ioctl_open(id, new_cdrom_drive); + if (cdrom_drives[id].bus_type) { + /* Signal disc change to the emulated machine. */ + cdrom_insert(id); + } + CheckMenuItem(sb_menu_handles[part], IDM_CDROM_EMPTY | id, MF_UNCHECKED); + cdrom_drives[id].host_drive = new_cdrom_drive; + CheckMenuItem(sb_menu_handles[part], IDM_CDROM_HOST_DRIVE | id | ((cdrom_drives[id].host_drive - 'A') << 3), MF_CHECKED); + StatusBarUpdateIconState(SB_CDROM | id, 0); + } + + EnableMenuItem(sb_menu_handles[part], IDM_CDROM_RELOAD | id, MF_BYCOMMAND | MF_GRAYED); + StatusBarUpdateTip(SB_CDROM | id); + + config_save(); +} + + +void +removable_disk_unload(uint8_t id) +{ + if (wcslen(hdd[id].fn) == 0) { + /* Switch from empty to empty. Do nothing. */ + return; + } + + scsi_unloadhd(hdd[id].scsi_id, hdd[id].scsi_lun, id); + scsi_disk_insert(id); +} + + +void +removable_disk_eject(uint8_t id) +{ + int part = 0; + + part = StatusBarFindPart(SB_CDROM | id); + if ((part == -1) || (sb_menu_handles == NULL)) return; + + removable_disk_unload(id); + StatusBarUpdateIconState(SB_RDISK | id, 1); + EnableMenuItem(sb_menu_handles[part], IDM_RDISK_EJECT | id, MF_BYCOMMAND | MF_GRAYED); + EnableMenuItem(sb_menu_handles[part], IDM_RDISK_RELOAD | id, MF_BYCOMMAND | MF_ENABLED); + EnableMenuItem(sb_menu_handles[part], IDM_RDISK_SEND_CHANGE | id, MF_BYCOMMAND | MF_GRAYED); + + StatusBarUpdateTip(SB_RDISK | id); + + config_save(); +} + + +void +removable_disk_reload(uint8_t id) +{ + int part = 0; + + part = StatusBarFindPart(SB_CDROM | id); + if ((part == -1) || (sb_menu_handles == NULL)) return; + + if (wcslen(hdd[id].fn) != 0) { + /* Attempting to reload while an image is already loaded. Do nothing. */ + return; + } + + scsi_reloadhd(id); +#if 0 + scsi_disk_insert(id); +#endif + + StatusBarUpdateIconState(SB_RDISK | id, wcslen(hdd[id].fn) ? 0 : 1); + + EnableMenuItem(sb_menu_handles[part], IDM_RDISK_EJECT | id, MF_BYCOMMAND | (wcslen(hdd[id].fn) ? MF_ENABLED : MF_GRAYED)); + EnableMenuItem(sb_menu_handles[part], IDM_RDISK_RELOAD | id, MF_BYCOMMAND | MF_GRAYED); + EnableMenuItem(sb_menu_handles[part], IDM_RDISK_SEND_CHANGE | id, MF_BYCOMMAND | (wcslen(hdd[id].fn) ? MF_ENABLED : MF_GRAYED)); + + StatusBarUpdateTip(SB_RDISK | id); + + config_save(); } diff --git a/src/win/win.h b/src/win/win.h index 3b89e2efc..99bae1d35 100644 --- a/src/win/win.h +++ b/src/win/win.h @@ -8,22 +8,17 @@ * * The Emulator's Windows core. * - * Version: @(#)win.h 1.0.0 2017/05/30 + * NOTE This should be named 'plat.h' and then include any + * Windows-specific header files needed, to keep them + * out of the main code. * - * Author: Sarah Walker, + * Version: @(#)win.h 1.0.2 2017/10/05 + * + * Authors: Sarah Walker, * Miran Grca, * Copyright 2008-2017 Sarah Walker. * Copyright 2016-2017 Miran Grca. */ - -/* - * This should be named 'plat.h' and then include any - * Windows-specific header files needed, to keep them - * out of the main code. - */ -/* Copyright holders: Sarah Walker - see COPYING for more details -*/ #ifndef BOX_WIN_H # define BOX_WIN_H @@ -31,32 +26,34 @@ # define UNICODE # endif # define BITMAP WINDOWS_BITMAP -/* # ifdef _WIN32_WINNT - # undef _WIN32_WINNT - # define _WIN32_WINNT 0x0501 - # endif */ +# if 0 +# ifdef _WIN32_WINNT +# undef _WIN32_WINNT +# define _WIN32_WINNT 0x0501 +# endif +# endif # include # include "resource.h" # undef BITMAP -#define szClassName L"86BoxMainWnd" -#define szSubClassName L"86BoxSubWnd" -#define szStatusBarClassName L"86BoxStatusBar" +/* Class names and such. */ +#define CLASS_NAME L"86BoxMainWnd" +#define MENU_NAME L"MainMenu" +#define ACCEL_NAME L"MainAccel" +#define SUB_CLASS_NAME L"86BoxSubWnd" +#define SB_CLASS_NAME L"86BoxStatusBar" +#define SB_MENU_NAME L"StatusBarMenu" +#define RENDER_NAME L"RenderWindow" - -#define WM_RESETD3D WM_USER -#define WM_LEAVEFULLSCREEN WM_USER + 1 - -#define WM_SAVESETTINGS 0x8888 /* 86Box-specific message, used to tell the child dialog to save the currently specified settings. */ - -#define SB_ICON_WIDTH 24 +/* Application-specific window messages. */ +#define WM_RESETD3D WM_USER +#define WM_LEAVEFULLSCREEN WM_USER+1 +#define WM_SAVESETTINGS 0x8888 extern HINSTANCE hinstance; -extern HWND ghwnd; -extern HWND status_hwnd; -extern HWND hwndStatus; +extern HWND hwndMain; extern int status_is_open; extern int mousecapture; @@ -65,9 +62,6 @@ extern WCHAR wopenfilestring[260]; extern int pause; -extern HMENU smenu; -extern HMENU *sb_menu_handles; - #ifdef __cplusplus extern "C" { @@ -75,9 +69,9 @@ extern "C" { extern void leave_fullscreen(void); -extern void status_open(HWND hwnd); - -extern void deviceconfig_open(HWND hwnd, struct device_t *device); +#ifdef EMU_DEVICE_H +extern void deviceconfig_open(HWND hwnd, device_t *device); +#endif extern void joystickconfig_open(HWND hwnd, int joy_nr, int type); extern int getfile(HWND hwnd, char *f, char *fn); @@ -92,23 +86,40 @@ extern void endblit(void); extern void win_settings_open(HWND hwnd); extern void win_menu_update(); -extern void update_status_bar_panes(HWND hwnds); - -extern int fdd_type_to_icon(int type); - extern void hard_disk_add_open(HWND hwnd, int is_existing); extern int hard_disk_was_added(void); extern void get_registry_key_map(void); extern void process_raw_input(LPARAM lParam, int infocus); -extern int find_status_bar_part(int tag); - +extern void cdrom_init_host_drives(void); extern void cdrom_close(uint8_t id); -extern void update_tip(int meaning); extern BOOL DirectoryExists(LPCTSTR szPath); +/* Status Window definitions. */ +extern HWND hwndStatus; +extern void StatusWindowCreate(HWND hwnd); + + +/* Status Bar definitions. */ +#define SB_ICON_WIDTH 24 +#define SB_FLOPPY 0x00 +#define SB_CDROM 0x10 +#define SB_RDISK 0x20 +#define SB_HDD 0x40 +#define SB_NETWORK 0x50 +#define SB_TEXT 0x60 + +extern int fdd_type_to_icon(int type); +extern int StatusBarFindPart(int tag); +extern void StatusBarUpdatePanes(void); +extern void StatusBarUpdateTip(int meaning); +extern void StatusBarUpdateIcon(int tag, int val); +extern void StatusBarUpdateIconState(int tag, int active); +extern void StatusBarSetTextW(wchar_t *wstr); +extern void StatusBarSetText(char *str); + #ifdef __cplusplus } #endif diff --git a/src/win/win_d3d_fs.cc b/src/win/win_d3d_fs.cc index 575d18d80..4bdef9c9a 100644 --- a/src/win/win_d3d_fs.cc +++ b/src/win/win_d3d_fs.cc @@ -6,9 +6,9 @@ * * This file is part of the 86Box distribution. * - * Direct3D 9 full screen rendererer and screenshots taking. + * Direct3D 9 full-screen rendererer. * - * Version: @(#)win_d3d_fs.cc 1.0.2 2017/08/23 + * Version: @(#)win_d3d_fs.cc 1.0.3 2017/10/05 * * Authors: Sarah Walker, * Miran Grca, @@ -45,9 +45,9 @@ static D3DPRESENT_PARAMETERS d3dpp; static HWND d3d_hwnd; static HWND d3d_device_window; - static int d3d_fs_w, d3d_fs_h; + struct CUSTOMVERTEX { FLOAT x, y, z, rhw; // from the D3DFVF_XYZRHW flag @@ -55,55 +55,72 @@ struct CUSTOMVERTEX FLOAT tu, tv; }; -PALETTE cgapal = -{ - {0,0,0},{0,42,0},{42,0,0},{42,21,0}, - {0,0,0},{0,42,42},{42,0,42},{42,42,42}, - {0,0,0},{21,63,21},{63,21,21},{63,63,21}, - {0,0,0},{21,63,63},{63,21,63},{63,63,63}, - {0,0,0},{0,0,42},{0,42,0},{0,42,42}, - {42,0,0},{42,0,42},{42,21,00},{42,42,42}, - {21,21,21},{21,21,63},{21,63,21},{21,63,63}, - {63,21,21},{63,21,63},{63,63,21},{63,63,63}, +PALETTE cgapal = { + {0,0,0},{0,42,0},{42,0,0},{42,21,0}, + {0,0,0},{0,42,42},{42,0,42},{42,42,42}, + {0,0,0},{21,63,21},{63,21,21},{63,63,21}, + {0,0,0},{21,63,63},{63,21,63},{63,63,63}, - {0,0,0},{0,21,0},{0,0,42},{0,42,42}, - {42,0,21},{21,10,21},{42,0,42},{42,0,63}, - {21,21,21},{21,63,21},{42,21,42},{21,63,63}, - {63,0,0},{42,42,0},{63,21,42},{41,41,41}, + {0,0,0},{0,0,42},{0,42,0},{0,42,42}, + {42,0,0},{42,0,42},{42,21,00},{42,42,42}, + {21,21,21},{21,21,63},{21,63,21},{21,63,63}, + {63,21,21},{63,21,63},{63,63,21},{63,63,63}, + + {0,0,0},{0,21,0},{0,0,42},{0,42,42}, + {42,0,21},{21,10,21},{42,0,42},{42,0,63}, + {21,21,21},{21,63,21},{42,21,42},{21,63,63}, + {63,0,0},{42,42,0},{63,21,42},{41,41,41}, - {0,0,0},{0,42,42},{42,0,0},{42,42,42}, - {0,0,0},{0,42,42},{42,0,0},{42,42,42}, - {0,0,0},{0,63,63},{63,0,0},{63,63,63}, - {0,0,0},{0,63,63},{63,0,0},{63,63,63}, + {0,0,0},{0,42,42},{42,0,0},{42,42,42}, + {0,0,0},{0,42,42},{42,0,0},{42,42,42}, + {0,0,0},{0,63,63},{63,0,0},{63,63,63}, + {0,0,0},{0,63,63},{63,0,0},{63,63,63}, }; -PALETTE cgapal_mono[6] = -{ - { // 0 - green, 4-color-optimized contrast - {0x00,0x00,0x00},{0x00,0x0d,0x03},{0x01,0x17,0x05},{0x01,0x1a,0x06},{0x02,0x28,0x09},{0x02,0x2c,0x0a},{0x03,0x39,0x0d},{0x03,0x3c,0x0e}, - {0x00,0x07,0x01},{0x01,0x13,0x04},{0x01,0x1f,0x07},{0x01,0x23,0x08},{0x02,0x31,0x0b},{0x02,0x35,0x0c},{0x05,0x3f,0x11},{0x0d,0x3f,0x17}, - }, - { // 1 - green, 16-color-optimized contrast - {0x00,0x00,0x00},{0x00,0x0d,0x03},{0x01,0x15,0x05},{0x01,0x17,0x05},{0x01,0x21,0x08},{0x01,0x24,0x08},{0x02,0x2e,0x0b},{0x02,0x31,0x0b}, - {0x01,0x22,0x08},{0x02,0x28,0x09},{0x02,0x30,0x0b},{0x02,0x32,0x0c},{0x03,0x39,0x0d},{0x03,0x3b,0x0e},{0x09,0x3f,0x14},{0x0d,0x3f,0x17}, - }, - { // 2 - amber, 4-color-optimized contrast - {0x00,0x00,0x00},{0x15,0x05,0x00},{0x20,0x0b,0x00},{0x24,0x0d,0x00},{0x33,0x18,0x00},{0x37,0x1b,0x00},{0x3f,0x26,0x01},{0x3f,0x2b,0x06}, - {0x0b,0x02,0x00},{0x1b,0x08,0x00},{0x29,0x11,0x00},{0x2e,0x14,0x00},{0x3b,0x1e,0x00},{0x3e,0x21,0x00},{0x3f,0x32,0x0a},{0x3f,0x38,0x0d}, - }, - { // 3 - amber, 16-color-optimized contrast - {0x00,0x00,0x00},{0x15,0x05,0x00},{0x1e,0x09,0x00},{0x21,0x0b,0x00},{0x2b,0x12,0x00},{0x2f,0x15,0x00},{0x38,0x1c,0x00},{0x3b,0x1e,0x00}, - {0x2c,0x13,0x00},{0x32,0x17,0x00},{0x3a,0x1e,0x00},{0x3c,0x1f,0x00},{0x3f,0x27,0x01},{0x3f,0x2a,0x04},{0x3f,0x36,0x0c},{0x3f,0x38,0x0d}, - }, - { // 4 - grey, 4-color-optimized contrast - {0x00,0x00,0x00},{0x0e,0x0f,0x10},{0x15,0x17,0x18},{0x18,0x1a,0x1b},{0x24,0x25,0x25},{0x27,0x28,0x28},{0x33,0x34,0x32},{0x37,0x38,0x35}, - {0x09,0x0a,0x0b},{0x11,0x12,0x13},{0x1c,0x1e,0x1e},{0x20,0x22,0x22},{0x2c,0x2d,0x2c},{0x2f,0x30,0x2f},{0x3c,0x3c,0x38},{0x3f,0x3f,0x3b}, - }, - { // 5 - grey, 16-color-optimized contrast - {0x00,0x00,0x00},{0x0e,0x0f,0x10},{0x13,0x14,0x15},{0x15,0x17,0x18},{0x1e,0x20,0x20},{0x20,0x22,0x22},{0x29,0x2a,0x2a},{0x2c,0x2d,0x2c}, - {0x1f,0x21,0x21},{0x23,0x25,0x25},{0x2b,0x2c,0x2b},{0x2d,0x2e,0x2d},{0x34,0x35,0x33},{0x37,0x37,0x34},{0x3e,0x3e,0x3a},{0x3f,0x3f,0x3b}, - } +PALETTE cgapal_mono[6] = { + { /* 0 - green, 4-color-optimized contrast. */ + {0x00,0x00,0x00},{0x00,0x0d,0x03},{0x01,0x17,0x05}, + {0x01,0x1a,0x06},{0x02,0x28,0x09},{0x02,0x2c,0x0a}, + {0x03,0x39,0x0d},{0x03,0x3c,0x0e},{0x00,0x07,0x01}, + {0x01,0x13,0x04},{0x01,0x1f,0x07},{0x01,0x23,0x08}, + {0x02,0x31,0x0b},{0x02,0x35,0x0c},{0x05,0x3f,0x11},{0x0d,0x3f,0x17}, + }, + { /* 1 - green, 16-color-optimized contrast. */ + {0x00,0x00,0x00},{0x00,0x0d,0x03},{0x01,0x15,0x05}, + {0x01,0x17,0x05},{0x01,0x21,0x08},{0x01,0x24,0x08}, + {0x02,0x2e,0x0b},{0x02,0x31,0x0b},{0x01,0x22,0x08}, + {0x02,0x28,0x09},{0x02,0x30,0x0b},{0x02,0x32,0x0c}, + {0x03,0x39,0x0d},{0x03,0x3b,0x0e},{0x09,0x3f,0x14},{0x0d,0x3f,0x17}, + }, + { /* 2 - amber, 4-color-optimized contrast. */ + {0x00,0x00,0x00},{0x15,0x05,0x00},{0x20,0x0b,0x00}, + {0x24,0x0d,0x00},{0x33,0x18,0x00},{0x37,0x1b,0x00}, + {0x3f,0x26,0x01},{0x3f,0x2b,0x06},{0x0b,0x02,0x00}, + {0x1b,0x08,0x00},{0x29,0x11,0x00},{0x2e,0x14,0x00}, + {0x3b,0x1e,0x00},{0x3e,0x21,0x00},{0x3f,0x32,0x0a},{0x3f,0x38,0x0d}, + }, + { /* 3 - amber, 16-color-optimized contrast. */ + {0x00,0x00,0x00},{0x15,0x05,0x00},{0x1e,0x09,0x00}, + {0x21,0x0b,0x00},{0x2b,0x12,0x00},{0x2f,0x15,0x00}, + {0x38,0x1c,0x00},{0x3b,0x1e,0x00},{0x2c,0x13,0x00}, + {0x32,0x17,0x00},{0x3a,0x1e,0x00},{0x3c,0x1f,0x00}, + {0x3f,0x27,0x01},{0x3f,0x2a,0x04},{0x3f,0x36,0x0c},{0x3f,0x38,0x0d}, + }, + { /* 4 - grey, 4-color-optimized contrast. */ + {0x00,0x00,0x00},{0x0e,0x0f,0x10},{0x15,0x17,0x18}, + {0x18,0x1a,0x1b},{0x24,0x25,0x25},{0x27,0x28,0x28}, + {0x33,0x34,0x32},{0x37,0x38,0x35},{0x09,0x0a,0x0b}, + {0x11,0x12,0x13},{0x1c,0x1e,0x1e},{0x20,0x22,0x22}, + {0x2c,0x2d,0x2c},{0x2f,0x30,0x2f},{0x3c,0x3c,0x38},{0x3f,0x3f,0x3b}, + }, + { /* 5 - grey, 16-color-optimized contrast. */ + {0x00,0x00,0x00},{0x0e,0x0f,0x10},{0x13,0x14,0x15}, + {0x15,0x17,0x18},{0x1e,0x20,0x20},{0x20,0x22,0x22}, + {0x29,0x2a,0x2a},{0x2c,0x2d,0x2c},{0x1f,0x21,0x21}, + {0x23,0x25,0x25},{0x2b,0x2c,0x2b},{0x2d,0x2e,0x2d}, + {0x34,0x35,0x33},{0x37,0x37,0x34},{0x3e,0x3e,0x3a},{0x3f,0x3f,0x3b}, + } }; uint32_t pal_lookup[256]; @@ -182,7 +199,7 @@ int d3d_fs_init(HWND h) _swprintf(emulator_title, L"%s v%s", EMU_NAME_W, EMU_VERSION_W); d3d_device_window = CreateWindowEx ( 0, - szSubClassName, + SUB_CLASS_NAME, emulator_title, WS_POPUP, CW_USEDEFAULT, @@ -497,7 +514,7 @@ static void d3d_fs_blit_memtoscreen(int x, int y, int y1, int y2, int w, int h) hr = d3ddev->Present(NULL, NULL, d3d_device_window, NULL); if (hr == D3DERR_DEVICELOST || hr == D3DERR_INVALIDCALL) - PostMessage(ghwnd, WM_RESETD3D, 0, 0); + PostMessage(hwndMain, WM_RESETD3D, 0, 0); } static void d3d_fs_blit_memtoscreen_8(int x, int y, int w, int h) @@ -615,7 +632,7 @@ static void d3d_fs_blit_memtoscreen_8(int x, int y, int w, int h) hr = d3ddev->Present(NULL, NULL, d3d_device_window, NULL); if (hr == D3DERR_DEVICELOST || hr == D3DERR_INVALIDCALL) - PostMessage(ghwnd, WM_RESETD3D, 0, 0); + PostMessage(hwndMain, WM_RESETD3D, 0, 0); } diff --git a/src/win/win_ddraw.cc b/src/win/win_ddraw.cc index e87265f87..fc6dec759 100644 --- a/src/win/win_ddraw.cc +++ b/src/win/win_ddraw.cc @@ -33,7 +33,9 @@ static HWND ddraw_hwnd; int ddraw_init(HWND h) { +#if NO_THIS_CRASHES_NOW cgapal_rebuild(); +#endif if (FAILED(DirectDrawCreate(NULL, &lpdd, NULL))) return 0; diff --git a/src/win/win_ddraw_screenshot.cc b/src/win/win_ddraw_screenshot.cc index 27bb5b0b1..9b2e5fe15 100644 --- a/src/win/win_ddraw_screenshot.cc +++ b/src/win/win_ddraw_screenshot.cc @@ -119,7 +119,7 @@ void SaveBitmap(wchar_t *szFilename,HBITMAP hBitmap) if((fp = _wfopen(szFilename,L"wb"))==NULL) { _swprintf(szMessage, win_language_get_string_from_id(IDS_2088), szFilename); - msgbox_error_wstr(ghwnd, szMessage); + msgbox_error_wstr(hwndMain, szMessage); break; } diff --git a/src/win/win_deviceconfig.c b/src/win/win_deviceconfig.c index 2414e3062..09196af8f 100644 --- a/src/win/win_deviceconfig.c +++ b/src/win/win_deviceconfig.c @@ -8,7 +8,7 @@ * * Windows device configuration dialog implementation. * - * Version: @(#)win_deviceconfig.c 1.0.3 2017/09/24 + * Version: @(#)win_deviceconfig.c 1.0.4 2017/10/05 * * Authors: Sarah Walker, * Miran Grca, @@ -32,7 +32,8 @@ static device_t *config_device; -static BOOL CALLBACK deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) +static BOOL CALLBACK +deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) { HWND h; @@ -270,7 +271,7 @@ static BOOL CALLBACK deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam return TRUE; } - ret = msgbox_reset(ghwnd); + ret = msgbox_reset(hwndMain); switch(ret) { case IDNO: diff --git a/src/win/win_iodev.c b/src/win/win_iodev.c deleted file mode 100644 index b6ae03e9c..000000000 --- a/src/win/win_iodev.c +++ /dev/null @@ -1,204 +0,0 @@ -/* - * 86Box A hypervisor and IBM PC system emulator that specializes in - * running old operating systems and software designed for IBM - * PC systems and compatibles from 1981 through fairly recent - * system designs based on the PCI bus. - * - * This file is part of the 86Box distribution. - * - * Windows IO device menu handler. - * - * Version: @(#)win_iodev.c 1.0.4 2017/10/01 - * - * Author: Miran Grca, - * Copyright 2016,2017 Miran Grca. - */ -#define UNICODE -#define _WIN32_WINNT 0x0501 -#define BITMAP WINDOWS_BITMAP -#include -#include -#undef BITMAP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "../ibm.h" -#include "../config.h" -#include "../device.h" -#include "../cdrom/cdrom.h" -#include "../cdrom/cdrom_image.h" -#include "../cdrom/cdrom_ioctl.h" -#include "../cdrom/cdrom_null.h" -#include "../disk/hdd.h" -#include "../scsi/scsi_disk.h" -#include "plat_iodev.h" -#include "win.h" - - -void cdrom_eject(uint8_t id) -{ - int part; - - part = find_status_bar_part(SB_CDROM | id); - - if ((part == -1) || (sb_menu_handles == NULL)) - { - return; - } - - if (cdrom_drives[id].host_drive == 0) - { - /* Switch from empty to empty. Do nothing. */ - return; - } - if ((cdrom_drives[id].host_drive >= 'A') && (cdrom_drives[id].host_drive <= 'Z')) - { - CheckMenuItem(sb_menu_handles[part], IDM_CDROM_HOST_DRIVE | id | ((cdrom_drives[id].host_drive - 'A') << 3), MF_UNCHECKED); - } - if (cdrom_drives[id].host_drive == 200) - { - wcscpy(cdrom_image[id].prev_image_path, cdrom_image[id].image_path); - } - cdrom_drives[id].prev_host_drive = cdrom_drives[id].host_drive; - cdrom_drives[id].handler->exit(id); - cdrom_close(id); - cdrom_null_open(id, 0); - if (cdrom_drives[id].bus_type) - { - /* Signal disc change to the emulated machine. */ - cdrom_insert(id); - } - CheckMenuItem(sb_menu_handles[part], IDM_CDROM_IMAGE | id, MF_UNCHECKED); - cdrom_drives[id].host_drive=0; - CheckMenuItem(sb_menu_handles[part], IDM_CDROM_EMPTY | id, MF_CHECKED); - update_status_bar_icon_state(SB_CDROM | id, 1); - EnableMenuItem(sb_menu_handles[part], IDM_CDROM_RELOAD | id, MF_BYCOMMAND | MF_ENABLED); - update_tip(SB_CDROM | id); - config_save(); -} - -void cdrom_reload(uint8_t id) -{ - int part; - int new_cdrom_drive; - - part = find_status_bar_part(SB_CDROM | id); - - if ((part == -1) || (sb_menu_handles == NULL)) - { - return; - } - - if ((cdrom_drives[id].host_drive == cdrom_drives[id].prev_host_drive) || (cdrom_drives[id].prev_host_drive == 0) || (cdrom_drives[id].host_drive != 0)) - { - /* Switch from empty to empty. Do nothing. */ - return; - } - cdrom_close(id); - if (cdrom_drives[id].prev_host_drive == 200) - { - wcscpy(cdrom_image[id].image_path, cdrom_image[id].prev_image_path); - image_open(id, cdrom_image[id].image_path); - if (cdrom_drives[id].bus_type) - { - /* Signal disc change to the emulated machine. */ - cdrom_insert(id); - } - if (wcslen(cdrom_image[id].image_path) == 0) - { - CheckMenuItem(sb_menu_handles[part], IDM_CDROM_EMPTY | id, MF_CHECKED); - cdrom_drives[id].host_drive = 0; - CheckMenuItem(sb_menu_handles[part], IDM_CDROM_IMAGE | id, MF_UNCHECKED); - update_status_bar_icon_state(SB_CDROM | id, 1); - } - else - { - CheckMenuItem(sb_menu_handles[part], IDM_CDROM_EMPTY | id, MF_UNCHECKED); - cdrom_drives[id].host_drive = 200; - CheckMenuItem(sb_menu_handles[part], IDM_CDROM_IMAGE | id, MF_CHECKED); - update_status_bar_icon_state(SB_CDROM | id, 0); - } - } - else - { - new_cdrom_drive = cdrom_drives[id].prev_host_drive; - ioctl_open(id, new_cdrom_drive); - if (cdrom_drives[id].bus_type) - { - /* Signal disc change to the emulated machine. */ - cdrom_insert(id); - } - CheckMenuItem(sb_menu_handles[part], IDM_CDROM_EMPTY | id, MF_UNCHECKED); - cdrom_drives[id].host_drive = new_cdrom_drive; - CheckMenuItem(sb_menu_handles[part], IDM_CDROM_HOST_DRIVE | id | ((cdrom_drives[id].host_drive - 'A') << 3), MF_CHECKED); - update_status_bar_icon_state(SB_CDROM | id, 0); - } - EnableMenuItem(sb_menu_handles[part], IDM_CDROM_RELOAD | id, MF_BYCOMMAND | MF_GRAYED); - update_tip(SB_CDROM | id); - config_save(); -} - -void removable_disk_unload(uint8_t id) -{ - if (wcslen(hdd[id].fn) == 0) - { - /* Switch from empty to empty. Do nothing. */ - return; - } - scsi_unloadhd(hdd[id].scsi_id, hdd[id].scsi_lun, id); - scsi_disk_insert(id); -} - -void removable_disk_eject(uint8_t id) -{ - int part = 0; - - part = find_status_bar_part(SB_CDROM | id); - - if ((part == -1) || (sb_menu_handles == NULL)) - { - return; - } - - removable_disk_unload(id); - update_status_bar_icon_state(SB_RDISK | id, 1); - EnableMenuItem(sb_menu_handles[part], IDM_RDISK_EJECT | id, MF_BYCOMMAND | MF_GRAYED); - EnableMenuItem(sb_menu_handles[part], IDM_RDISK_RELOAD | id, MF_BYCOMMAND | MF_ENABLED); - EnableMenuItem(sb_menu_handles[part], IDM_RDISK_SEND_CHANGE | id, MF_BYCOMMAND | MF_GRAYED); - update_tip(SB_RDISK | id); - config_save(); -} - -void removable_disk_reload(uint8_t id) -{ - int part = 0; - - part = find_status_bar_part(SB_CDROM | id); - - if ((part == -1) || (sb_menu_handles == NULL)) - { - return; - } - - if (wcslen(hdd[id].fn) != 0) - { - /* Attempting to reload while an image is already loaded. Do nothing. */ - return; - } - scsi_reloadhd(id); - /* scsi_disk_insert(id); */ - update_status_bar_icon_state(SB_RDISK | id, wcslen(hdd[id].fn) ? 0 : 1); - EnableMenuItem(sb_menu_handles[part], IDM_RDISK_EJECT | id, MF_BYCOMMAND | (wcslen(hdd[id].fn) ? MF_ENABLED : MF_GRAYED)); - EnableMenuItem(sb_menu_handles[part], IDM_RDISK_RELOAD | id, MF_BYCOMMAND | MF_GRAYED); - EnableMenuItem(sb_menu_handles[part], IDM_RDISK_SEND_CHANGE | id, MF_BYCOMMAND | (wcslen(hdd[id].fn) ? MF_ENABLED : MF_GRAYED)); - update_tip(SB_RDISK | id); - config_save(); -} - diff --git a/src/win/win_joystick.cc b/src/win/win_joystick.cc index b7c487182..469da1b4a 100644 --- a/src/win/win_joystick.cc +++ b/src/win/win_joystick.cc @@ -151,7 +151,7 @@ void joystick_init() lpdi_joystick[c]->EnumObjects(DIEnumDeviceObjectsCallback, &plat_joystick_state[c], DIDFT_ALL); - if (FAILED(lpdi_joystick[c]->SetCooperativeLevel(ghwnd, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE))) + if (FAILED(lpdi_joystick[c]->SetCooperativeLevel(hwndMain, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE))) fatal("joystick_init : SetCooperativeLevel failed\n"); if (FAILED(lpdi_joystick[c]->SetDataFormat(&c_dfDIJoystick))) fatal("joystick_init : SetDataFormat failed\n"); diff --git a/src/win/win_language.c b/src/win/win_language.c index 37407b5ca..0d117e16c 100644 --- a/src/win/win_language.c +++ b/src/win/win_language.c @@ -8,14 +8,13 @@ * * Windows localization core. * - * Version: @(#)win_language.c 1.0.2 2017/09/24 + * Version: @(#)win_language.c 1.0.3 2017/10/05 * * Authors: Sarah Walker, * Miran Grca, * Copyright 2008-2017 Sarah Walker. * Copyright 2016,2017 Miran Grca. */ -//#include #define UNICODE #define BITMAP WINDOWS_BITMAP #include @@ -129,7 +128,9 @@ LPTSTR win_language_get_settings_category(int i) void win_language_update() { win_language_set(); +#if 0 win_menu_update(); +#endif win_language_load_common_strings(); } @@ -225,7 +226,7 @@ void msgbox_error(HWND hwndParent, int i) void plat_msgbox_error(int i) { - msgbox_error(ghwnd, i); + msgbox_error(hwndMain, i); } void msgbox_error_wstr(HWND hwndParent, WCHAR *wstr) @@ -252,7 +253,7 @@ void msgbox_fatal(HWND hwndParent, char *string) void plat_msgbox_fatal(char *string) { - msgbox_fatal(ghwnd, string); + msgbox_fatal(hwndMain, string); } int file_dlg_w(HWND hwnd, WCHAR *f, WCHAR *fn, int save) diff --git a/src/win/win_mouse.cc b/src/win/win_mouse.cc index 245fd0d61..574b301dc 100644 --- a/src/win/win_mouse.cc +++ b/src/win/win_mouse.cc @@ -48,7 +48,7 @@ void mouse_init(void) fatal("mouse_init : DirectInputCreate failed\n"); if (FAILED(lpdi->CreateDevice(GUID_SysMouse, &lpdi_mouse, NULL))) fatal("mouse_init : CreateDevice failed\n"); - if (FAILED(lpdi_mouse->SetCooperativeLevel(ghwnd, DISCL_FOREGROUND | (video_fullscreen ? DISCL_EXCLUSIVE : DISCL_NONEXCLUSIVE)))) + if (FAILED(lpdi_mouse->SetCooperativeLevel(hwndMain, DISCL_FOREGROUND | (video_fullscreen ? DISCL_EXCLUSIVE : DISCL_NONEXCLUSIVE)))) fatal("mouse_init : SetCooperativeLevel failed\n"); if (FAILED(lpdi_mouse->SetDataFormat(&c_dfDIMouse))) fatal("mouse_init : SetDataFormat failed\n"); diff --git a/src/win/win_settings.c b/src/win/win_settings.c index 9780e07db..936543046 100644 --- a/src/win/win_settings.c +++ b/src/win/win_settings.c @@ -8,7 +8,7 @@ * * Windows 86Box Settings dialog handler. * - * Version: @(#)win_settings.c 1.0.17 2017/10/02 + * Version: @(#)win_settings.c 1.0.18 2017/10/05 * * Author: Miran Grca, * Copyright 2016,2017 Miran Grca. @@ -279,7 +279,7 @@ static void win_settings_save(void) { int i = 0; - resetpchard_close(); + pc_reset_hard_close(); /* Machine category */ machine = temp_machine; @@ -348,11 +348,11 @@ static void win_settings_save(void) mem_resize(); rom_load_bios(romset); - update_status_bar_panes(hwndStatus); + StatusBarUpdatePanes(); sound_realloc_buffers(); - resetpchard_init(); + pc_reset_hard_init(); cpu_set(); @@ -2804,7 +2804,7 @@ hd_add_ok_common: if (f != NULL) { fclose(f); - if (msgbox_question(ghwnd, IDS_4111) != IDYES) + if (msgbox_question(hwndMain, IDS_4111) != IDYES) { return FALSE; } diff --git a/src/win/win_status.c b/src/win/win_status.c index d77c0bd6d..786809174 100644 --- a/src/win/win_status.c +++ b/src/win/win_status.c @@ -17,81 +17,89 @@ #include "win.h" -HWND status_hwnd; -int status_is_open = 0; + +HWND hwndStatus = NULL; extern int sreadlnum, swritelnum, segareads, segawrites, scycles_lost; - extern uint64_t main_time; static uint64_t status_time; -static BOOL CALLBACK status_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) +static BOOL CALLBACK +StatusWindowProcedure(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) { - char device_s[4096]; - switch (message) - { - case WM_INITDIALOG: - status_is_open = 1; - case WM_USER: - { - uint64_t new_time = timer_read(); - uint64_t status_diff = new_time - status_time; - status_time = new_time; - sprintf(device_s, - "CPU speed : %f MIPS\n" - "FPU speed : %f MFLOPS\n\n" + char temp[4096]; + uint64_t new_time; + uint64_t status_diff; - "Video throughput (read) : %i bytes/sec\n" - "Video throughput (write) : %i bytes/sec\n\n" - "Effective clockspeed : %iHz\n\n" - "Timer 0 frequency : %fHz\n\n" - "CPU time : %f%% (%f%%)\n" + switch (message) { + case WM_INITDIALOG: + hwndStatus = hdlg; + /*FALLTHROUGH*/ - "New blocks : %i\nOld blocks : %i\nRecompiled speed : %f MIPS\nAverage size : %f\n" - "Flushes : %i\nEvicted : %i\nReused : %i\nRemoved : %i\nReal speed : %f MIPS" - ,mips, - flops, - segareads, - segawrites, - clockrate - scycles_lost, - pit_timer0_freq(), - ((double)main_time * 100.0) / status_diff, - ((double)main_time * 100.0) / timer_freq + case WM_USER: + new_time = timer_read(); + status_diff = new_time - status_time; + status_time = new_time; + sprintf(temp, + "CPU speed : %f MIPS\n" + "FPU speed : %f MFLOPS\n\n" - , cpu_new_blocks_latched, cpu_recomp_blocks_latched, (double)cpu_recomp_ins_latched / 1000000.0, (double)cpu_recomp_ins_latched/cpu_recomp_blocks_latched, - cpu_recomp_flushes_latched, cpu_recomp_evicted_latched, - cpu_recomp_reuse_latched, cpu_recomp_removed_latched, - - ((double)cpu_recomp_ins_latched / 1000000.0) / ((double)main_time / timer_freq) - ); - main_time = 0; - SendDlgItemMessage(hdlg, IDT_SDEVICE, WM_SETTEXT, (WPARAM)NULL, (LPARAM)device_s); + "Video throughput (read) : %i bytes/sec\n" + "Video throughput (write) : %i bytes/sec\n\n" + "Effective clockspeed : %iHz\n\n" + "Timer 0 frequency : %fHz\n\n" + "CPU time : %f%% (%f%%)\n" - device_s[0] = 0; - device_add_status_info(device_s, 4096); - SendDlgItemMessage(hdlg, IDT_STEXT, WM_SETTEXT, (WPARAM)NULL, (LPARAM)device_s); - } - return TRUE; - - case WM_COMMAND: - switch (LOWORD(wParam)) - { - case IDOK: - case IDCANCEL: - status_is_open = 0; - EndDialog(hdlg, 0); - return TRUE; - } - break; - } + "New blocks : %i\nOld blocks : %i\nRecompiled speed : %f MIPS\nAverage size : %f\n" + "Flushes : %i\nEvicted : %i\nReused : %i\nRemoved : %i\nReal speed : %f MIPS" + ,mips, + flops, + segareads, + segawrites, + clockrate - scycles_lost, + pit_timer0_freq(), + ((double)main_time * 100.0) / status_diff, + ((double)main_time * 100.0) / timer_freq - return FALSE; + , cpu_new_blocks_latched, cpu_recomp_blocks_latched, (double)cpu_recomp_ins_latched / 1000000.0, (double)cpu_recomp_ins_latched/cpu_recomp_blocks_latched, + cpu_recomp_flushes_latched, cpu_recomp_evicted_latched, + cpu_recomp_reuse_latched, cpu_recomp_removed_latched, + + ((double)cpu_recomp_ins_latched / 1000000.0) / ((double)main_time / timer_freq) + ); + main_time = 0; + SendDlgItemMessage(hdlg, IDT_SDEVICE, WM_SETTEXT, + (WPARAM)NULL, (LPARAM)temp); + + temp[0] = 0; + device_add_status_info(temp, 4096); + SendDlgItemMessage(hdlg, IDT_STEXT, WM_SETTEXT, + (WPARAM)NULL, (LPARAM)temp); + return(TRUE); + + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDOK: + case IDCANCEL: + hwndStatus = NULL; + EndDialog(hdlg, 0); + return(TRUE); + } + break; + } + + return(FALSE); } -void status_open(HWND hwnd) + +void +StatusWindowCreate(HWND hwndParent) { - status_hwnd = CreateDialog(hinstance, (LPCSTR)DLG_STATUS, hwnd, status_dlgproc); - ShowWindow(status_hwnd, SW_SHOW); + HWND hwnd; + + hwnd = CreateDialog(hinstance, (LPCSTR)DLG_STATUS, + hwndParent, StatusWindowProcedure); + ShowWindow(hwnd, SW_SHOW); } diff --git a/src/win/win_thread.c b/src/win/win_thread.c new file mode 100644 index 000000000..14610c8fd --- /dev/null +++ b/src/win/win_thread.c @@ -0,0 +1,147 @@ +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * Implement threads and mutexes for the Win32 platform. + * + * Version: @(#)win_thread.c 1.0.1 2017/10/05 + * + * Authors: Sarah Walker, + * Fred N. van Kempen, + * Copyright 2008-2017 Sarah Walker. + * Copyright 2017 Fred N. van Kempen. + */ +#define UNICODE +#define BITMAP WINDOWS_BITMAP +#include +#include +#include +#undef BITMAP +#include +#include +#include +#include +#include +#include "../ibm.h" +#include "plat_thread.h" + + +typedef struct { + HANDLE handle; +} win_event_t; + + +void * +thread_create(void (*thread_rout)(void *param), void *param) +{ + return((void *)_beginthread(thread_rout, 0, param)); +} + + +void +thread_kill(void *handle) +{ + TerminateThread(handle, 0); +} + + +void +thread_sleep(int t) +{ + Sleep(t); +} + + +event_t * +thread_create_event(void) +{ + win_event_t *event = malloc(sizeof(win_event_t)); + + event->handle = CreateEvent(NULL, FALSE, FALSE, NULL); + + return((event_t *)event); +} + + +void +thread_set_event(event_t *_event) +{ + win_event_t *event = (win_event_t *)_event; + + SetEvent(event->handle); +} + + +void +thread_reset_event(event_t *_event) +{ + win_event_t *event = (win_event_t *)_event; + + ResetEvent(event->handle); +} + + +int +thread_wait_event(event_t *_event, int timeout) +{ + win_event_t *event = (win_event_t *)_event; + + if (timeout == -1) + timeout = INFINITE; + + if (WaitForSingleObject(event->handle, timeout)) return(1); + + return(0); +} + + +void +thread_destroy_event(event_t *_event) +{ + win_event_t *event = (win_event_t *)_event; + + CloseHandle(event->handle); + + free(event); +} + + +void * +thread_create_mutex(wchar_t *name) +{ + return((void*)CreateMutex(NULL, FALSE, name)); +} + + +void +thread_close_mutex(void *mutex) +{ + CloseHandle((HANDLE)mutex); +} + + +uint8_t +thread_wait_mutex(void *mutex) +{ + DWORD dwres = WaitForSingleObject((HANDLE)mutex, INFINITE); + + switch (dwres) { + case WAIT_OBJECT_0: + return(1); + + case WAIT_ABANDONED: + default: + return(0); + } +} + + +uint8_t +thread_release_mutex(void *mutex) +{ + return(!!ReleaseMutex((HANDLE)mutex)); +}