Big cleanup of the use of regular and const string pointers. Where possible, const is used to enfore R/O-ness of string arguments.

Important change to the NVR code to "fix" the PS/1 and PS/2 systems, plus a cleanup.
All device tables now end with a NULL, not an empty string.
Configuration code now deals better with this.
Machine and Video lookup now return -1 if not found/available, and pc_init() will throw the user into Setup if that is the case.
If for some reason the configured memory size exceeds machine limit, it is now adjusted.
This commit is contained in:
waltje
2018-04-11 17:40:51 -04:00
parent 23fcf833b4
commit 6b21c4c921
30 changed files with 323 additions and 347 deletions

View File

@@ -11,7 +11,7 @@
* This header file lists the functions provided by
* various platform specific cdrom-ioctl files.
*
* Version: @(#)cdrom_image.h 1.0.2 2018/03/20
* Version: @(#)cdrom_image.h 1.0.3 2018/04/10
*
* Authors: Miran Grca, <mgrca8@gmail.com>
* RichardG, <richardg867@gmail.com>
@@ -45,6 +45,9 @@
extern "C" {
#endif
extern int cdrom_image_do_log;
extern int image_open(uint8_t id, wchar_t *fn);
extern void image_reset(uint8_t id);

View File

@@ -454,9 +454,7 @@ load_general(void)
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";
p = config_get_string(cat, "window_coordinates", "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");
@@ -554,11 +552,8 @@ load_input_devices(void)
int c, d;
char *p;
p = config_get_string(cat, "mouse_type", NULL);
if (p != NULL)
p = config_get_string(cat, "mouse_type", "none");
mouse_type = mouse_get_from_internal_name(p);
else
mouse_type = 0;
joystick_type = config_get_int(cat, "joystick_type", 0);
@@ -602,16 +597,12 @@ load_sound(void)
config_delete_var(cat, "sndcard");
}
if (p != NULL)
if (p == NULL)
p = "none";
sound_card_current = sound_card_get_from_internal_name(p);
else
sound_card_current = 0;
p = config_get_string(cat, "midi_device", NULL);
if (p != NULL)
p = config_get_string(cat, "midi_device", "none");
midi_device_current = midi_device_get_from_internal_name(p);
else
midi_device_current = 0;
mpu401_standalone_enable = !!config_get_int(cat, "mpu401_standalone", 0);
@@ -670,11 +661,8 @@ load_network(void)
} else
strcpy(network_host, "none");
p = config_get_string(cat, "net_card", NULL);
if (p != NULL)
p = config_get_string(cat, "net_card", "none");
network_card = network_card_get_from_internal_name(p);
else
network_card = 0;
}
@@ -696,9 +684,7 @@ load_ports(void)
parallel_enabled[i] = !!config_get_int(cat, temp, 0);
sprintf(temp, "parallel%i_device", i);
p = (char *)config_get_string(cat, temp, NULL);
if (p == NULL)
p = "none";
p = (char *)config_get_string(cat, temp, "none");
parallel_device[i] = parallel_device_get_from_internal_name(p);
}
}
@@ -721,10 +707,9 @@ load_other_peripherals(void)
config_delete_var(cat, "scsicard");
}
if (p != NULL)
if (p == NULL)
p = "none";
scsi_card_current = scsi_card_get_from_internal_name(p);
else
scsi_card_current = 0;
p = config_get_string(cat, "hdc", NULL);
if (p == NULL) {
@@ -737,9 +722,7 @@ load_other_peripherals(void)
for (c=2; c<4; c++) {
sprintf(temp, "ide_%02i", c + 1);
p = config_get_string(cat, temp, NULL);
if (p == NULL)
p = "0, 00";
p = config_get_string(cat, temp, "0, 00");
sscanf(p, "%i, %02i", &ide_enable[c], &ide_irq[c]);
}
@@ -865,16 +848,10 @@ load_hard_disks(void)
(hdd[c].bus == HDD_BUS_IDE_PIO_AND_DMA)) {
sprintf(tmp2, "%01u:%01u", c>>1, c&1);
p = config_get_string(cat, temp, tmp2);
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;
}
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;
@@ -1006,11 +983,8 @@ load_removable_devices(void)
cdrom_drives[c].prev_host_drive = cdrom_drives[c].host_drive;
sprintf(temp, "cdrom_%02i_parameters", c+1);
p = config_get_string(cat, temp, NULL);
if (p != NULL)
sscanf(p, "%01u, %s", &cdrom_drives[c].sound_on, s);
else
sscanf("0, none", "%01u, %s", &cdrom_drives[c].sound_on, s);
p = config_get_string(cat, temp, "0, none");
sscanf(p, "%01u, %s", &cdrom_drives[c].sound_on, s);
cdrom_drives[c].bus_type = hdd_string_to_bus(s, 1);
sprintf(temp, "cdrom_%02i_speed", c+1);
@@ -1092,11 +1066,8 @@ load_removable_devices(void)
for (c = 0; c < ZIP_NUM; c++) {
sprintf(temp, "zip_%02i_parameters", c+1);
p = config_get_string(cat, temp, NULL);
if (p != NULL)
sscanf(p, "%01u, %s", &zip_drives[c].is_250, s);
else
sscanf("0, none", "%01u, %s", &zip_drives[c].is_250, s);
p = config_get_string(cat, temp, "0, none");
sscanf(p, "%01u, %s", &zip_drives[c].is_250, s);
zip_drives[c].bus_type = hdd_string_to_bus(s, 1);
/* Default values, needed for proper operation of the Settings dialog. */
@@ -1107,16 +1078,11 @@ load_removable_devices(void)
(zip_drives[c].bus_type == ZIP_BUS_ATAPI_PIO_AND_DMA)) {
sprintf(tmp2, "%01u:%01u", (c+2)>>1, (c+2)&1);
p = config_get_string(cat, temp, tmp2);
if (! strstr(p, ":")) {
sscanf(p, "%i", (int *)&zip_drives[c].ide_channel);
zip_drives[c].ide_channel &= 7;
} else {
sscanf(p, "%01u:%01u", &board, &dev);
sscanf(p, "%01u:%01u", &board, &dev);
board &= 3;
dev &= 1;
zip_drives[c].ide_channel = (board<<1)+dev;
}
board &= 3;
dev &= 1;
zip_drives[c].ide_channel = (board<<1)+dev;
if (zip_drives[c].ide_channel > 7)
zip_drives[c].ide_channel = 7;

View File

@@ -238,5 +238,5 @@ hdc_get_from_internal_name(const char *s)
}
/* Not found. */
return(-1);
return(0);
}

View File

@@ -8,7 +8,7 @@
*
* Main include file for the application.
*
* Version: @(#)emu.h 1.0.16 2018/04/08
* Version: @(#)emu.h 1.0.17 2018/04/10
*
* Author: Fred N. van Kempen, <decwiz@yahoo.com>
*
@@ -52,16 +52,17 @@
#define SCREEN_RES_X 640
#define SCREEN_RES_Y 480
/* Filename and pathname info. */
/* Pre-defined directory names. */
#define MACHINES_PATH L"machines"
#define NVR_PATH L"nvr"
#define ROMS_PATH L"roms"
#define MACHINES_PATH L"machines"
#define VIDEO_PATH L"video"
#define SCREENSHOT_PATH L"screenshots"
#define VIDEO_PATH L"video"
/* Pre-defined file names and extensions. */
#define BIOS_FILE L"bios.txt"
#define CONFIG_FILE L"config.varc"
#define CONFIG_FILE_EXT L".varc"
#define BIOS_FILE L"bios.txt"
#define MIN(a, b) ((a) < (b) ? (a) : (b))
@@ -104,6 +105,7 @@ extern int vid_cga_contrast, /* (C) video */
force_43, /* (C) video */
vid_card, /* (C) graphics/video card */
video_speed; /* (C) video */
extern int enable_sync; /* (C) enable time sync */
extern int serial_enabled[], /* (C) enable serial ports */
parallel_enabled[], /* (C) enable LPT ports */
parallel_device[], /* (C) set up LPT devices */
@@ -124,7 +126,6 @@ extern int cpu_manufacturer, /* (C) cpu manufacturer */
cpu, /* (C) cpu type */
cpu_use_dynarec, /* (C) cpu uses/needs Dyna */
enable_external_fpu; /* (C) enable external FPU */
extern int enable_sync; /* (C) enable time sync */
extern int network_type; /* (C) net provider type */
extern int network_card; /* (C) net interface num */
extern char network_host[512]; /* (C) host network intf */
@@ -153,7 +154,7 @@ extern void pclog_ex(const char *fmt, va_list);
extern void pclog(const char *fmt, ...);
extern void fatal(const char *fmt, ...);
extern void pc_version(const char *platform);
extern void pc_path(wchar_t *dest, int dest_sz, wchar_t *src);
extern void pc_path(wchar_t *dest, int dest_sz, const wchar_t *src);
extern int pc_init(int argc, wchar_t *argv[]);
extern int pc_init_modules(void);
extern void pc_close(void *threadid);
@@ -161,7 +162,7 @@ extern void pc_reset_hard_close(void);
extern void pc_reset_hard_init(void);
extern void pc_reset_hard(void);
extern void pc_reset(int hard);
extern void pc_reload(wchar_t *fn);
extern void pc_reload(const wchar_t *fn);
extern void pc_full_speed(void);
extern void pc_speed_changed(void);
extern void pc_thread(void *param);

View File

@@ -237,7 +237,7 @@ int fdd_get_from_internal_name(const char *s)
}
/* Not found. */
return -1;
return 0;
}

View File

@@ -508,7 +508,7 @@ ps1_setup(int model)
io_sethandler(0x0324, 1,
ps1_read, NULL, NULL, ps1_write, NULL, NULL, ps);
#if 1
#if 0
rom_init(&ps->high_rom,
L"machines/ibm/ps1_2011/f80000_shell.bin",
0xf80000, 0x80000, 0x7ffff, 0, MEM_MAPPING_EXTERNAL);
@@ -530,11 +530,10 @@ ps1_setup(int model)
io_sethandler(0x00e0, 2,
ps1_read, NULL, NULL, ps1_write, NULL, NULL, ps);
#if 1
rom_init(&ps->high_rom,
L"machines/ibmps1_2121/fc0000.bin",
L"machines/ibm/ps1_2121/rom_shell.bin",
0xfc0000, 0x20000, 0x1ffff, 0, MEM_MAPPING_EXTERNAL);
#else
#if 0
rom_init(&ps->high_rom,
L"machines/ibmps1_2121/fc0000_shell.bin",
0xfc0000, 0x40000, 0x3ffff, 0, MEM_MAPPING_EXTERNAL);
@@ -565,7 +564,7 @@ ps1_common_init(const machine_t *model, void *arg)
dma16_init();
pic2_init();
device_add(&at_nvr_device);
device_add(&ps_nvr_device);
if (romset != ROM_IBMPS1_2011)
device_add(&ide_isa_device);

View File

@@ -8,7 +8,7 @@
*
* Implementation of ISA-based PS/2 machines.
*
* Version: @(#)m_ps2_isa.c 1.0.7 2018/04/09
* Version: @(#)m_ps2_isa.c 1.0.8 2018/04/10
*
* Authors: Fred N. van Kempen, <decwiz@yahoo.com>
* Miran Grca, <mgrca8@gmail.com>
@@ -195,7 +195,7 @@ machine_ps2_m30_286_init(const machine_t *model, void *arg)
pit_set_out_func(&pit, 1, pit_refresh_timer_at);
dma16_init();
device_add(&keyboard_ps2_device);
device_add(&at_nvr_device);
device_add(&ps_nvr_device);
pic2_init();
ps2board_init();
device_add(&ps1vga_device);

View File

@@ -1211,7 +1211,7 @@ machine_ps2_common_init(const machine_t *model, void *arg)
ps2_dma_init();
pit_ps2_init();
device_add(&at_nvr_device);
device_add(&ps_nvr_device);
device_add(&keyboard_ps2_mca_device);

View File

@@ -93,8 +93,8 @@ const machine_t machines[] = {
{ "[286 ISA] GW-286CT GEAR", ROM_GW286CT, "gw286ct", L"unknown/gw286ct", {{"", cpus_286}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, MACHINE_ISA | MACHINE_AT, 512,16384, 128, 128, machine_at_scat_init, NULL, NULL },
{ "[286 ISA] Hyundai Super-286TR", ROM_SUPER286TR, "hyundai_super286tr", L"hyundai/super286tr", {{"", cpus_286}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, MACHINE_ISA | MACHINE_AT, 512,16384, 128, 128, machine_at_scat_init, NULL, NULL },
{ "[286 ISA] IBM AT", ROM_IBMAT, "ibm_at", L"ibm/at", {{"", cpus_ibmat}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, MACHINE_ISA | MACHINE_AT, 256,15872, 128, 64, machine_at_ibm_init, NULL, NULL },
{ "[286 ISA] IBM PS/1 model 2011", ROM_IBMPS1_2011, "ibm_ps1_2011", L"ibm/ps1_2011", {{"", cpus_ps1_m2011}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 1, MACHINE_ISA | MACHINE_AT | MACHINE_PS2 | MACHINE_HDC_PS2, 512,16384, 512, 128, machine_ps1_m2011_init, NULL, NULL },
{ "[286 ISA] IBM PS/2 model 30-286", ROM_IBMPS2_M30_286, "ibm_ps2_m30_286", L"ibm/ps2_m30_286", {{"", cpus_ps2_m30_286}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 1, MACHINE_ISA | MACHINE_AT | MACHINE_PS2 | MACHINE_HDC_PS2, 1, 16, 1, 128, machine_ps2_m30_286_init, NULL, NULL },
{ "[286 ISA] IBM PS/1 model 2011", ROM_IBMPS1_2011, "ibm_ps1_2011", L"ibm/ps1_2011", {{"", cpus_ps1_m2011}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 1, MACHINE_ISA | MACHINE_AT | MACHINE_PS2 | MACHINE_HDC_PS2, 512,16384, 512, 64, machine_ps1_m2011_init, NULL, NULL },
{ "[286 ISA] IBM PS/2 model 30-286", ROM_IBMPS2_M30_286, "ibm_ps2_m30_286", L"ibm/ps2_m30_286", {{"", cpus_ps2_m30_286}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 1, MACHINE_ISA | MACHINE_AT | MACHINE_PS2 | MACHINE_HDC_PS2, 1, 16, 1, 64, machine_ps2_m30_286_init, NULL, NULL },
{ "[286 ISA] IBM XT Model 286", ROM_IBMXT286, "ibm_xt286", L"ibm/xt286", {{"", cpus_ibmxt286}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, MACHINE_ISA | MACHINE_AT, 256,15872, 128, 128, machine_at_ibm_init, NULL, NULL },
{ "[286 ISA] Samsung SPC-4200P", ROM_SPC4200P, "samsung_spc4200p", L"samsung/spc4200p", {{"", cpus_286}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, MACHINE_ISA | MACHINE_AT | MACHINE_PS2, 512, 2048, 128, 128, machine_at_scat_init, NULL, NULL },
{ "[286 ISA] Samsung SPC-4216P", ROM_SPC4216P, "samsung_spc4216p", L"samsung/spc4216p", {{"", cpus_286}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}}, 0, MACHINE_ISA | MACHINE_AT | MACHINE_PS2, 1, 5, 1, 128, machine_at_scat_init, NULL, NULL },
@@ -106,10 +106,10 @@ const machine_t machines[] = {
{ "[386SX ISA] Amstrad MegaPC", ROM_MEGAPC, "amstrad_megapc", L"amstrad/megapc", {{"Intel", cpus_i386SX}, {"AMD", cpus_Am386SX}, {"Cyrix", cpus_486SLC}, {"", NULL}, {"", NULL}}, 1, MACHINE_ISA | MACHINE_AT | MACHINE_PS2 | MACHINE_VIDEO | MACHINE_HDC, 1, 16, 1, 128, machine_at_wd76c10_init, NULL, NULL },
{ "[386SX ISA] Award 386SX clone", ROM_AWARD386SX_OPTI495, "award_386sx", L"generic/award/opti495", {{"Intel", cpus_i386SX}, {"AMD", cpus_Am386SX}, {"Cyrix", cpus_486SLC}, {"", NULL}, {"", NULL}}, 0, MACHINE_ISA | MACHINE_AT | MACHINE_HDC, 1, 64, 1, 128, machine_at_opti495_init, NULL, NULL },
{ "[386SX ISA] DTK 386SX clone", ROM_DTK386, "dtk_386", L"dtk/386", {{"Intel", cpus_i386SX}, {"AMD", cpus_Am386SX}, {"Cyrix", cpus_486SLC}, {"", NULL}, {"", NULL}}, 0, MACHINE_ISA | MACHINE_AT | MACHINE_HDC, 512,16384, 128, 128, machine_at_neat_init, NULL, NULL },
{ "[386SX ISA] IBM PS/1 model 2121", ROM_IBMPS1_2121, "ibm_ps1_2121", L"ibm/ps1_2121", {{"Intel", cpus_i386SX}, {"AMD", cpus_Am386SX}, {"Cyrix", cpus_486SLC}, {"", NULL}, {"", NULL}}, 1, MACHINE_ISA | MACHINE_AT | MACHINE_PS2 | MACHINE_HDC | MACHINE_VIDEO, 1, 6, 1, 128, machine_ps1_m2121_init, NULL, NULL },
{ "[386SX ISA] IBM PS/1 m.2121+ISA", ROM_IBMPS1_2121_ISA, "ibm_ps1_2121_isa", L"ibm/ps1_2121", {{"Intel", cpus_i386SX}, {"AMD", cpus_Am386SX}, {"Cyrix", cpus_486SLC}, {"", NULL}, {"", NULL}}, 0, MACHINE_ISA | MACHINE_AT | MACHINE_PS2 | MACHINE_HDC | MACHINE_VIDEO, 1, 6, 1, 128, machine_ps1_m2121_init, NULL, NULL },
{ "[386SX ISA] IBM PS/1 model 2121", ROM_IBMPS1_2121, "ibm_ps1_2121", L"ibm/ps1_2121", {{"Intel", cpus_i386SX}, {"AMD", cpus_Am386SX}, {"Cyrix", cpus_486SLC}, {"", NULL}, {"", NULL}}, 1, MACHINE_ISA | MACHINE_AT | MACHINE_PS2 | MACHINE_HDC | MACHINE_VIDEO, 1, 6, 1, 64, machine_ps1_m2121_init, NULL, NULL },
{ "[386SX ISA] IBM PS/1 m.2121+ISA", ROM_IBMPS1_2121_ISA, "ibm_ps1_2121_isa", L"ibm/ps1_2121", {{"Intel", cpus_i386SX}, {"AMD", cpus_Am386SX}, {"Cyrix", cpus_486SLC}, {"", NULL}, {"", NULL}}, 0, MACHINE_ISA | MACHINE_AT | MACHINE_PS2 | MACHINE_HDC | MACHINE_VIDEO, 1, 6, 1, 64, machine_ps1_m2121_init, NULL, NULL },
{ "[386SX MCA] IBM PS/2 model 55SX", ROM_IBMPS2_M55SX, "ibm_ps2_m55sx", L"ibm/ps2_m55sx", {{"Intel", cpus_i386SX}, {"AMD", cpus_Am386SX}, {"Cyrix", cpus_486SLC}, {"", NULL}, {"", NULL}}, 1, MACHINE_MCA | MACHINE_AT | MACHINE_PS2 | MACHINE_HDC_PS2, 1, 8, 1, 128, machine_ps2_model_55sx_init, NULL, NULL },
{ "[386SX MCA] IBM PS/2 model 55SX", ROM_IBMPS2_M55SX, "ibm_ps2_m55sx", L"ibm/ps2_m55sx", {{"Intel", cpus_i386SX}, {"AMD", cpus_Am386SX}, {"Cyrix", cpus_486SLC}, {"", NULL}, {"", NULL}}, 1, MACHINE_MCA | MACHINE_AT | MACHINE_PS2 | MACHINE_HDC_PS2, 1, 8, 1, 64, machine_ps2_model_55sx_init, NULL, NULL },
{ "[386SX ISA] KMX-C-02", ROM_KMXC02, "kmxc02", L"unknown/kmxc02", {{"Intel", cpus_i386SX}, {"AMD", cpus_Am386SX}, {"Cyrix", cpus_486SLC}, {"", NULL}, {"", NULL}}, 0, MACHINE_ISA | MACHINE_AT, 512,16384, 512, 128, machine_at_scatsx_init, NULL, NULL },
{ "[386DX ISA] AMI 386DX clone", ROM_AMI386DX_OPTI495, "ami_386dx", L"generic/ami/386dx", {{"Intel", cpus_i386DX}, {"AMD", cpus_Am386DX}, {"Cyrix", cpus_486DLC}, {"", NULL}, {"", NULL}}, 0, MACHINE_ISA | MACHINE_AT | MACHINE_HDC, 1, 64, 1, 128, machine_at_opti495_ami_init, NULL, NULL },

View File

@@ -1569,12 +1569,12 @@ mem_reset(void)
* exceed the physical limit of the machine to avoid
* nasty crashes all over the place.
*/
m = mem_size;
c = machines[machine].max_ram;
if (AT)
c <<= 10; /* make KB */
if (mem_size > c) {
pclog("MEM: %luKB exceeds machine limit (%luKB), adjusted!\n",
mem_size, c);
if (m > c) {
pclog("MEM: %luKB exceeds machine limit (%luKB), adjusted!\n", m, c);
mem_size = c;
}

View File

@@ -217,7 +217,7 @@ mouse_get_from_internal_name(const char *s)
}
/* Not found. */
return(-1);
return(0);
}

View File

@@ -417,7 +417,7 @@ network_dev_to_id(const char *devname)
}
/* Not found. */
return(-1);
return(0);
}
@@ -489,5 +489,5 @@ network_card_get_from_internal_name(const char *s)
}
/* Not found. */
return(-1);
return(0);
}

118
src/nvr.c
View File

@@ -8,9 +8,7 @@
*
* Implement a generic NVRAM/CMOS/RTC device.
*
* NOTE: I should re-do 'intclk' using a TM struct.
*
* Version: @(#)nvr.c 1.0.4 2018/03/31
* Version: @(#)nvr.c 1.0.6 2018/04/11
*
* Author: Fred N. van Kempen, <decwiz@yahoo.com>
*
@@ -61,23 +59,11 @@
#include "nvr.h"
/* Define the internal clock. */
typedef struct {
int16_t year;
int8_t sec;
int8_t min;
int8_t hour;
int8_t mday;
int8_t mon;
} intclk_t;
int enable_sync; /* configuration variable: enable time sync */
int nvr_dosave; /* NVR is dirty, needs saved */
static int8_t days_in_month[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
static intclk_t intclk;
static struct tm intclk;
static nvr_t *saved_nvr = NULL;
@@ -109,25 +95,23 @@ static void
rtc_tick(void)
{
/* Ping the internal clock. */
if (++intclk.sec == 60) {
intclk.sec = 0;
intclk.min++;
}
if (intclk.min == 60) {
intclk.min = 0;
intclk.hour++;
}
if (intclk.hour == 24) {
intclk.hour = 0;
intclk.mday++;
}
if (intclk.mday == (nvr_get_days(intclk.mon, intclk.year) + 1)) {
intclk.mday = 1;
intclk.mon++;
}
if (intclk.mon == 13) {
intclk.mon = 1;
intclk.year++;
if (++intclk.tm_sec == 60) {
intclk.tm_sec = 0;
if (++intclk.tm_min == 60) {
intclk.tm_min = 0;
if (++intclk.tm_hour == 24) {
intclk.tm_hour = 0;
if (++intclk.tm_mday == (nvr_get_days(intclk.tm_mon,
intclk.tm_year) + 1)) {
intclk.tm_mday = 1;
intclk.tm_mon++;
if (++intclk.tm_mon == 13) {
intclk.tm_mon = 1;
intclk.tm_year++;
}
}
}
}
}
}
@@ -164,9 +148,9 @@ nvr_init(nvr_t *nvr)
/* Set up the NVR file's name. */
sprintf(temp, "%s.nvr", machine_get_internal_name());
c = strlen(temp)+1;
nvr->fn = (wchar_t *)malloc(c*sizeof(wchar_t));
mbstowcs(nvr->fn, temp, c);
c = strlen(temp);
nvr->fn = (wchar_t *)malloc(c*sizeof(wchar_t) + 1);
mbstowcs(nvr->fn, temp, c + 1);
/* Initialize the internal clock as needed. */
memset(&intclk, 0x00, sizeof(intclk));
@@ -179,8 +163,8 @@ nvr_init(nvr_t *nvr)
nvr_time_set(tm);
} else {
/* Reset the internal clock to 1980/01/01 00:00. */
intclk.mon = 1;
intclk.year = 1980;
intclk.tm_mon = 1;
intclk.tm_year = 1980;
}
/* Set up our timer. */
@@ -199,7 +183,7 @@ nvr_init(nvr_t *nvr)
/* Get path to the NVR folder. */
wchar_t *
nvr_path(wchar_t *str)
nvr_path(const wchar_t *str)
{
static wchar_t temp[1024];
@@ -237,7 +221,7 @@ int
nvr_load(void)
{
wchar_t *path;
FILE *f;
FILE *fp;
/* Make sure we have been initialized. */
if (saved_nvr == NULL) return(0);
@@ -253,11 +237,11 @@ nvr_load(void)
if (saved_nvr->size != 0) {
path = nvr_path(saved_nvr->fn);
pclog("NVR: loading from '%ls'\n", path);
f = plat_fopen(path, L"rb");
if (f != NULL) {
fp = plat_fopen(path, L"rb");
if (fp != NULL) {
/* Read NVR contents from file. */
(void)fread(saved_nvr->regs, saved_nvr->size, 1, f);
(void)fclose(f);
(void)fread(saved_nvr->regs, saved_nvr->size, 1, fp);
(void)fclose(fp);
}
}
@@ -274,7 +258,7 @@ int
nvr_save(void)
{
wchar_t *path;
FILE *f;
FILE *fp;
/* Make sure we have been initialized. */
if (config_ro || saved_nvr == NULL) return(0);
@@ -282,11 +266,11 @@ nvr_save(void)
if (saved_nvr->size != 0) {
path = nvr_path(saved_nvr->fn);
pclog("NVR: saving to '%ls'\n", path);
f = plat_fopen(path, L"wb");
if (f != NULL) {
fp = plat_fopen(path, L"wb");
if (fp != NULL) {
/* Save NVR contents to file. */
(void)fwrite(saved_nvr->regs, saved_nvr->size, 1, f);
fclose(f);
(void)fwrite(saved_nvr->regs, saved_nvr->size, 1, fp);
fclose(fp);
}
}
@@ -304,19 +288,19 @@ nvr_time_get(struct tm *tm)
int8_t dom, mon, sum, wd;
int16_t cent, yr;
tm->tm_sec = intclk.sec;
tm->tm_min = intclk.min;
tm->tm_hour = intclk.hour;
dom = intclk.mday;
mon = intclk.mon;
yr = (intclk.year % 100);
cent = ((intclk.year - yr) / 100) % 4;
tm->tm_sec = intclk.tm_sec;
tm->tm_min = intclk.tm_min;
tm->tm_hour = intclk.tm_hour;
dom = intclk.tm_mday;
mon = intclk.tm_mon;
yr = (intclk.tm_year % 100);
cent = ((intclk.tm_year - yr) / 100) % 4;
sum = dom+mon+yr+cent;
wd = ((sum + 6) % 7);
tm->tm_wday = wd;
tm->tm_mday = intclk.mday;
tm->tm_mon = (intclk.mon - 1);
tm->tm_year = (intclk.year - 1900);
tm->tm_mday = intclk.tm_mday;
tm->tm_mon = (intclk.tm_mon - 1);
tm->tm_year = (intclk.tm_year - 1900);
}
@@ -324,10 +308,10 @@ nvr_time_get(struct tm *tm)
void
nvr_time_set(struct tm *tm)
{
intclk.sec = tm->tm_sec;
intclk.min = tm->tm_min;
intclk.hour = tm->tm_hour;
intclk.mday = tm->tm_mday;
intclk.mon = (tm->tm_mon + 1);
intclk.year = (tm->tm_year + 1900);
intclk.tm_sec = tm->tm_sec;
intclk.tm_min = tm->tm_min;
intclk.tm_hour = tm->tm_hour;
intclk.tm_mday = tm->tm_mday;
intclk.tm_mon = (tm->tm_mon + 1);
intclk.tm_year = (tm->tm_year + 1900);
}

View File

@@ -8,7 +8,7 @@
*
* Definitions for the generic NVRAM/CMOS driver.
*
* Version: @(#)nvr.h 1.0.5 2018/03/31
* Version: @(#)nvr.h 1.0.6 2018/04/11
*
* Author: Fred N. van Kempen, <decwiz@yahoo.com>
*
@@ -58,34 +58,34 @@
/* Define a generic RTC/NVRAM device. */
typedef struct _nvr_ {
uint8_t regs[NVR_MAXSIZE]; /* these are the registers */
wchar_t *fn; /* pathname of image file */
uint16_t size; /* device configuration */
int8_t irq;
int8_t upd_stat, /* FIXME: move to private struct */
addr;
int64_t upd_ecount, /* FIXME: move to private struct */
onesec_time,
onesec_cnt,
rtctime;
uint8_t onesec_cnt;
int64_t onesec_time;
void *data; /* local data */
/* Hooks to device functions. */
void (*reset)(struct _nvr_ *);
void (*start)(struct _nvr_ *);
void (*tick)(struct _nvr_ *);
uint8_t regs[NVR_MAXSIZE]; /* these are the registers */
} nvr_t;
extern int nvr_dosave;
#ifdef EMU_DEVICE_H
extern const device_t at_nvr_device;
extern const device_t ps_nvr_device;
extern const device_t amstrad_nvr_device;
#endif
extern void nvr_init(nvr_t *);
extern wchar_t *nvr_path(wchar_t *fn);
extern wchar_t *nvr_path(const wchar_t *fn);
extern int nvr_load(void);
extern int nvr_save(void);

View File

@@ -218,6 +218,7 @@
* Boston, MA 02111-1307
* USA.
*/
#include <inttypes.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
@@ -239,6 +240,7 @@
/* RTC registers and bit definitions. */
#define RTC_SECONDS 0
#define RTC_ALSECONDS 1
# define AL_DONTCARE 0xc0 /* Alarm time is not set */
#define RTC_MINUTES 2
#define RTC_ALMINUTES 3
#define RTC_HOURS 4
@@ -275,40 +277,53 @@
# define REGC_UF 0x10
#define RTC_REGD 13
# define REGD_VRT 0x80
#define RTC_CENTURY 0x32 /* century register */
#define RTC_CENTURY_AT 0x32 /* century register for AT etc */
#define RTC_CENTURY_PS 0x37 /* century register for PS/1 PS/2 */
#define RTC_REGS 14 /* number of registers */
typedef struct {
int8_t stat;
uint8_t cent;
uint16_t addr;
int64_t ecount,
rtctime;
} local_t;
/* Get the current NVR time. */
static void
time_get(uint8_t *regs, struct tm *tm)
time_get(nvr_t *nvr, struct tm *tm)
{
local_t *local = (local_t *)nvr->data;
int8_t temp;
if (regs[RTC_REGB] & REGB_DM) {
if (nvr->regs[RTC_REGB] & REGB_DM) {
/* NVR is in Binary data mode. */
tm->tm_sec = regs[RTC_SECONDS];
tm->tm_min = regs[RTC_MINUTES];
temp = regs[RTC_HOURS];
tm->tm_wday = (regs[RTC_DOW] - 1);
tm->tm_mday = regs[RTC_DOM];
tm->tm_mon = (regs[RTC_MONTH] - 1);
tm->tm_year = regs[RTC_YEAR];
tm->tm_year += (regs[RTC_CENTURY] * 100) - 1900;
tm->tm_sec = nvr->regs[RTC_SECONDS];
tm->tm_min = nvr->regs[RTC_MINUTES];
temp = nvr->regs[RTC_HOURS];
tm->tm_wday = (nvr->regs[RTC_DOW] - 1);
tm->tm_mday = nvr->regs[RTC_DOM];
tm->tm_mon = (nvr->regs[RTC_MONTH] - 1);
tm->tm_year = nvr->regs[RTC_YEAR];
tm->tm_year += (nvr->regs[local->cent] * 100) - 1900;
} else {
/* NVR is in BCD data mode. */
tm->tm_sec = RTC_DCB(regs[RTC_SECONDS]);
tm->tm_min = RTC_DCB(regs[RTC_MINUTES]);
temp = RTC_DCB(regs[RTC_HOURS]);
tm->tm_wday = (RTC_DCB(regs[RTC_DOW]) - 1);
tm->tm_mday = RTC_DCB(regs[RTC_DOM]);
tm->tm_mon = (RTC_DCB(regs[RTC_MONTH]) - 1);
tm->tm_year = RTC_DCB(regs[RTC_YEAR]);
tm->tm_year += (RTC_DCB(regs[RTC_CENTURY]) * 100) - 1900;
tm->tm_sec = RTC_DCB(nvr->regs[RTC_SECONDS]);
tm->tm_min = RTC_DCB(nvr->regs[RTC_MINUTES]);
temp = RTC_DCB(nvr->regs[RTC_HOURS]);
tm->tm_wday = (RTC_DCB(nvr->regs[RTC_DOW]) - 1);
tm->tm_mday = RTC_DCB(nvr->regs[RTC_DOM]);
tm->tm_mon = (RTC_DCB(nvr->regs[RTC_MONTH]) - 1);
tm->tm_year = RTC_DCB(nvr->regs[RTC_YEAR]);
tm->tm_year += (RTC_DCB(nvr->regs[local->cent]) * 100) - 1900;
}
/* Adjust for 12/24 hour mode. */
if (regs[RTC_REGB] & REGB_2412)
if (nvr->regs[RTC_REGB] & REGB_2412)
tm->tm_hour = temp;
else
tm->tm_hour = ((temp & ~RTC_AMPM)%12) + ((temp&RTC_AMPM) ? 12 : 0);
@@ -317,49 +332,50 @@ time_get(uint8_t *regs, struct tm *tm)
/* Set the current NVR time. */
static void
time_set(uint8_t *regs, struct tm *tm)
time_set(nvr_t *nvr, struct tm *tm)
{
local_t *local = (local_t *)nvr->data;
int year = (tm->tm_year + 1900);
if (regs[RTC_REGB] & REGB_DM) {
if (nvr->regs[RTC_REGB] & REGB_DM) {
/* NVR is in Binary data mode. */
regs[RTC_SECONDS] = tm->tm_sec;
regs[RTC_MINUTES] = tm->tm_min;
regs[RTC_DOW] = (tm->tm_wday + 1);
regs[RTC_DOM] = tm->tm_mday;
regs[RTC_MONTH] = (tm->tm_mon + 1);
regs[RTC_YEAR] = (year % 100);
regs[RTC_CENTURY] = (year / 100);
nvr->regs[RTC_SECONDS] = tm->tm_sec;
nvr->regs[RTC_MINUTES] = tm->tm_min;
nvr->regs[RTC_DOW] = (tm->tm_wday + 1);
nvr->regs[RTC_DOM] = tm->tm_mday;
nvr->regs[RTC_MONTH] = (tm->tm_mon + 1);
nvr->regs[RTC_YEAR] = (year % 100);
nvr->regs[local->cent] = (year / 100);
if (regs[RTC_REGB] & REGB_2412) {
if (nvr->regs[RTC_REGB] & REGB_2412) {
/* NVR is in 24h mode. */
regs[RTC_HOURS] = tm->tm_hour;
nvr->regs[RTC_HOURS] = tm->tm_hour;
} else {
/* NVR is in 12h mode. */
regs[RTC_HOURS] = (tm->tm_hour % 12) ? (tm->tm_hour % 12) : 12;
nvr->regs[RTC_HOURS] = (tm->tm_hour % 12) ? (tm->tm_hour % 12) : 12;
if (tm->tm_hour > 11)
regs[RTC_HOURS] |= RTC_AMPM;
nvr->regs[RTC_HOURS] |= RTC_AMPM;
}
} else {
/* NVR is in BCD data mode. */
regs[RTC_SECONDS] = RTC_BCD(tm->tm_sec);
regs[RTC_MINUTES] = RTC_BCD(tm->tm_min);
regs[RTC_DOW] = (RTC_BCD(tm->tm_wday) + 1);
regs[RTC_DOM] = RTC_BCD(tm->tm_mday);
regs[RTC_MONTH] = (RTC_BCD(tm->tm_mon) + 1);
regs[RTC_YEAR] = RTC_BCD(year % 100);
regs[RTC_CENTURY] = RTC_BCD(year / 100);
nvr->regs[RTC_SECONDS] = RTC_BCD(tm->tm_sec);
nvr->regs[RTC_MINUTES] = RTC_BCD(tm->tm_min);
nvr->regs[RTC_DOW] = (RTC_BCD(tm->tm_wday) + 1);
nvr->regs[RTC_DOM] = RTC_BCD(tm->tm_mday);
nvr->regs[RTC_MONTH] = (RTC_BCD(tm->tm_mon) + 1);
nvr->regs[RTC_YEAR] = RTC_BCD(year % 100);
nvr->regs[local->cent] = RTC_BCD(year / 100);
if (regs[RTC_REGB] & REGB_2412) {
if (nvr->regs[RTC_REGB] & REGB_2412) {
/* NVR is in 24h mode. */
regs[RTC_HOURS] = RTC_BCD(tm->tm_hour);
nvr->regs[RTC_HOURS] = RTC_BCD(tm->tm_hour);
} else {
/* NVR is in 12h mode. */
regs[RTC_HOURS] = (tm->tm_hour % 12)
nvr->regs[RTC_HOURS] = (tm->tm_hour % 12)
? RTC_BCD(tm->tm_hour % 12)
: RTC_BCD(12);
if (tm->tm_hour > 11)
regs[RTC_HOURS] |= RTC_AMPM;
nvr->regs[RTC_HOURS] |= RTC_AMPM;
}
}
}
@@ -367,11 +383,10 @@ time_set(uint8_t *regs, struct tm *tm)
/* Check if the current time matches a set alarm time. */
static int8_t
check_alarm(uint8_t *regs, int8_t addr)
check_alarm(nvr_t *nvr, int8_t addr)
{
#define ALARM_DONTCARE 0xc0
return((regs[addr+1] == regs[addr]) ||
((regs[addr+1] & ALARM_DONTCARE) == ALARM_DONTCARE));
return((nvr->regs[addr+1] == nvr->regs[addr]) ||
((nvr->regs[addr+1] & AL_DONTCARE) == AL_DONTCARE));
}
@@ -380,6 +395,7 @@ static void
timer_update(void *priv)
{
nvr_t *nvr = (nvr_t *)priv;
local_t *local = (local_t *)nvr->data;
struct tm tm;
if (! (nvr->regs[RTC_REGB] & REGB_SET)) {
@@ -387,23 +403,22 @@ timer_update(void *priv)
nvr_time_get(&tm);
/* Update registers with current time. */
time_set(nvr->regs, &tm);
time_set(nvr, &tm);
/* Clear update status. */
nvr->upd_stat = 0x00;
local->stat = 0x00;
/* Check for any alarms we need to handle. */
if (check_alarm(nvr->regs, RTC_SECONDS) &&
check_alarm(nvr->regs, RTC_MINUTES) &&
check_alarm(nvr->regs, RTC_HOURS)) {
if (check_alarm(nvr, RTC_SECONDS) &&
check_alarm(nvr, RTC_MINUTES) &&
check_alarm(nvr, RTC_HOURS)) {
nvr->regs[RTC_REGC] |= REGC_AF;
if (nvr->regs[RTC_REGB] & REGB_AIE) {
nvr->regs[RTC_REGC] |= REGC_IRQF;
/* Generate an interrupt. */
if (nvr->irq != -1)
picint(1<<nvr->irq);
picint(1 << nvr->irq);
}
}
@@ -417,11 +432,11 @@ timer_update(void *priv)
/* Generate an interrupt. */
if (nvr->irq != -1)
picint(1<<nvr->irq);
picint(1 << nvr->irq);
}
}
nvr->upd_ecount = 0;
local->ecount = 0;
}
@@ -429,14 +444,15 @@ timer_update(void *priv)
static void
timer_recalc(nvr_t *nvr, int add)
{
local_t *local = (local_t *)nvr->data;
int64_t c, nt;
c = 1ULL << ((nvr->regs[RTC_REGA] & REGA_RS) - 1);
nt = (int64_t)(RTCCONST * c * (1<<TIMER_SHIFT));
if (add)
nvr->rtctime += nt;
else if (nvr->rtctime > nt)
nvr->rtctime = nt;
local->rtctime += nt;
else if (local->rtctime > nt)
local->rtctime = nt;
}
@@ -444,9 +460,10 @@ static void
timer_intr(void *priv)
{
nvr_t *nvr = (nvr_t *)priv;
local_t *local = (local_t *)nvr->data;
if (! (nvr->regs[RTC_REGA] & REGA_RS)) {
nvr->rtctime = 0x7fffffff;
local->rtctime = 0x7fffffff;
return;
}
@@ -459,7 +476,7 @@ timer_intr(void *priv)
/* Generate an interrupt. */
if (nvr->irq != -1)
picint(1<<nvr->irq);
picint(1 << nvr->irq);
}
}
@@ -468,11 +485,18 @@ timer_intr(void *priv)
static void
timer_tick(nvr_t *nvr)
{
if (nvr->regs[RTC_REGB] & REGB_SET) return;
local_t *local = (local_t *)nvr->data;
nvr->upd_stat = REGA_UIP;
/* Only update it there is no SET in progress. */
if (! (nvr->regs[RTC_REGB] & REGB_SET)) {
/* Set the UIP bit, announcing the update. */
local->stat = REGA_UIP;
nvr->upd_ecount = (int64_t)((244.0 + 1984.0) * TIMER_USEC);
timer_recalc(nvr, 0);
/* Schedule the actual update. */
local->ecount = (int64_t)((244.0 + 1984.0) * TIMER_USEC);
}
}
@@ -481,20 +505,21 @@ static void
nvr_write(uint16_t addr, uint8_t val, void *priv)
{
nvr_t *nvr = (nvr_t *)priv;
local_t *local = (local_t *)nvr->data;
struct tm tm;
uint8_t old;
cycles -= ISA_CYCLES(8);
if (addr & 1) {
old = nvr->regs[nvr->addr];
switch(nvr->addr) {
old = nvr->regs[local->addr];
switch(local->addr) {
case RTC_REGA:
nvr->regs[RTC_REGA] = val;
if (val & REGA_RS)
timer_recalc(nvr, 1);
else
nvr->rtctime = 0x7fffffff;
local->rtctime = 0x7fffffff;
break;
case RTC_REGB:
@@ -511,25 +536,25 @@ nvr_write(uint16_t addr, uint8_t val, void *priv)
break;
default: /* non-RTC registers are just NVRAM */
if (nvr->regs[nvr->addr] != val) {
nvr->regs[nvr->addr] = val;
if (nvr->regs[local->addr] != val) {
nvr->regs[local->addr] = val;
nvr_dosave = 1;
}
break;
}
if ((nvr->addr < RTC_REGA) || (nvr->addr == RTC_CENTURY)) {
if ((nvr->addr != 1) && (nvr->addr != 3) && (nvr->addr != 5)) {
if ((local->addr < RTC_REGA) || (local->addr == local->cent)) {
if ((local->addr != 1) && (local->addr != 3) && (local->addr != 5)) {
if ((old != val) && !enable_sync) {
/* Update internal clock. */
time_get(nvr->regs, &tm);
time_get(nvr, &tm);
nvr_time_set(&tm);
nvr_dosave = 1;
}
}
}
} else {
nvr->addr = (val & (nvr->size - 1));
local->addr = (val & (nvr->size - 1));
if (!(machines[machine].flags & MACHINE_MCA) &&
(romset != ROM_IBMPS1_2133))
nmi_mask = (~val & 0x80);
@@ -542,17 +567,18 @@ static uint8_t
nvr_read(uint16_t addr, void *priv)
{
nvr_t *nvr = (nvr_t *)priv;
local_t *local = (local_t *)nvr->data;
uint8_t ret;
cycles -= ISA_CYCLES(8);
if (addr & 1) switch(nvr->addr) {
if (addr & 1) switch(local->addr) {
case RTC_REGA:
ret = (nvr->regs[RTC_REGA] & 0x7f) | nvr->upd_stat;
ret = (nvr->regs[RTC_REGA] & 0x7f) | local->stat;
break;
case RTC_REGC:
picintc(1<<nvr->irq);
picintc(1 << nvr->irq);
ret = nvr->regs[RTC_REGC];
nvr->regs[RTC_REGC] = 0x00;
break;
@@ -563,10 +589,10 @@ nvr_read(uint16_t addr, void *priv)
break;
default:
ret = nvr->regs[nvr->addr];
ret = nvr->regs[local->addr];
break;
} else {
ret = nvr->addr;
ret = local->addr;
}
return(ret);
@@ -577,11 +603,13 @@ nvr_read(uint16_t addr, void *priv)
static void
nvr_reset(nvr_t *nvr)
{
local_t *local = (local_t *)nvr->data;
memset(nvr->regs, 0x00, RTC_REGS);
nvr->regs[RTC_DOM] = 1;
nvr->regs[RTC_MONTH] = 1;
nvr->regs[RTC_YEAR] = RTC_BCD(80);
nvr->regs[RTC_CENTURY] = RTC_BCD(19);
nvr->regs[local->cent] = RTC_BCD(19);
}
@@ -595,23 +623,24 @@ nvr_start(nvr_t *nvr)
if (enable_sync) {
/* Use the internal clock's time. */
nvr_time_get(&tm);
time_set(nvr->regs, &tm);
time_set(nvr, &tm);
} else {
/* Set the internal clock from the chip time. */
time_get(nvr->regs, &tm);
time_get(nvr, &tm);
nvr_time_set(&tm);
}
/* Start the RTC. */
nvr->regs[RTC_REGA] = (REGA_RS2|REGA_RS1);
nvr->regs[RTC_REGB] = REGB_2412;
timer_recalc(nvr, 0);
timer_recalc(nvr, 1);
}
static void *
nvr_init_common(int irq)
nvr_at_init(const device_t *info)
{
local_t *local;
nvr_t *nvr;
/* Allocate an NVR for this machine. */
@@ -619,9 +648,28 @@ nvr_init_common(int irq)
if (nvr == NULL) return(NULL);
memset(nvr, 0x00, sizeof(nvr_t));
local = (local_t *)malloc(sizeof(local_t));
memset(local, 0x00, sizeof(local_t));
nvr->data = local;
/* This is machine specific. */
nvr->size = machines[machine].nvrsz;
nvr->irq = irq;
switch(info->local) {
case 0: /* standard AT */
nvr->irq = 8;
local->cent = RTC_CENTURY_AT;
break;
case 1: /* PS/1 or PS/2 */
nvr->irq = 8;
local->cent = RTC_CENTURY_PS;
break;
case 2: /* Amstrad PC's */
nvr->irq = 1;
local->cent = RTC_CENTURY_AT;
break;
}
/* Set up any local handlers here. */
nvr->reset = nvr_reset;
@@ -632,8 +680,8 @@ nvr_init_common(int irq)
nvr_init(nvr);
/* Start the timers. */
timer_add(timer_update, &nvr->upd_ecount, &nvr->upd_ecount, nvr);
timer_add(timer_intr, &nvr->rtctime, TIMER_ALWAYS_ENABLED, nvr);
timer_add(timer_update, &local->ecount, &local->ecount, nvr);
timer_add(timer_intr, &local->rtctime, TIMER_ALWAYS_ENABLED, nvr);
/* Set up the I/O handler for this device. */
io_sethandler(0x0070, 2,
@@ -643,14 +691,6 @@ nvr_init_common(int irq)
}
static void *
nvr_at_init(const device_t *info)
{
/* The PC/AT and compatibles use IRQ8, Amstrad uses IRQ1. */
return(nvr_init_common(info->local));
}
static void
nvr_at_close(void *priv)
{
@@ -659,6 +699,9 @@ nvr_at_close(void *priv)
if (nvr->fn != NULL)
free(nvr->fn);
if (nvr->data != NULL)
free(nvr->data);
free(nvr);
}
@@ -666,7 +709,16 @@ nvr_at_close(void *priv)
const device_t at_nvr_device = {
"PC/AT NVRAM",
DEVICE_ISA | DEVICE_AT,
8,
0,
nvr_at_init, nvr_at_close, NULL,
NULL, NULL, NULL,
NULL
};
const device_t ps_nvr_device = {
"PS/1 or PS/2 NVRAM",
DEVICE_PS2,
1,
nvr_at_init, nvr_at_close, NULL,
NULL, NULL, NULL,
NULL
@@ -675,56 +727,8 @@ const device_t at_nvr_device = {
const device_t amstrad_nvr_device = {
"Amstrad NVRAM",
MACHINE_ISA | MACHINE_AT,
1,
2,
nvr_at_init, nvr_at_close, NULL,
NULL, NULL, NULL,
NULL
};
#if 0
void
nvr_at_init(int irq)
{
nvr_t *nvr;
/* Allocate an NVR for this machine. */
nvr = (nvr_t *)malloc(sizeof(nvr_t));
if (nvr == NULL) return;
memset(nvr, 0x00, sizeof(nvr_t));
/* This is machine specific. */
nvr->size = machines[machine].nvrsz;
nvr->irq = irq;
/* Set up any local handlers here. */
nvr->reset = nvr_reset;
nvr->start = nvr_start;
nvr->tick = timer_tick;
/* Initialize the generic NVR. */
nvr_init(nvr);
/* Start the timers. */
timer_add(timer_update, &nvr->upd_ecount, &nvr->upd_ecount, nvr);
timer_add(timer_intr, &nvr->rtctime, TIMER_ALWAYS_ENABLED, nvr);
/* Set up the I/O handler for this device. */
io_sethandler(0x0070, 2,
nvr_read,NULL,NULL, nvr_write,NULL,NULL, nvr);
nvrp = nvr;
}
void
nvr_at_close(void)
{
if (nvrp == NULL) return;
if (nvrp->fn != NULL)
free(nvrp->fn);
free(nvrp);
nvrp = NULL;
}
#endif

View File

@@ -100,5 +100,5 @@ parallel_device_get_from_internal_name(const char *s)
}
/* Not found. */
return(-1);
return(0);
}

View File

@@ -119,6 +119,7 @@ int vid_cga_contrast = 0, /* (C) video */
force_43 = 0, /* (C) video */
vid_card = 0, /* (C) graphics/video card */
video_speed = 0; /* (C) video */
int enable_sync = 0; /* (C) enable time sync */
int serial_enabled[] = {0,0}, /* (C) enable serial ports */
parallel_enabled[] = {0,0,0}, /* (C) enable LPT ports */
parallel_device[] = {0,0,0}, /* (C) set up LPT devices */
@@ -139,7 +140,6 @@ int cpu_manufacturer = 0, /* (C) cpu manufacturer */
cpu_use_dynarec = 0, /* (C) cpu uses/needs Dyna */
cpu = 3, /* (C) cpu type */
enable_external_fpu = 0; /* (C) enable external FPU */
int enable_sync = 0; /* (C) enable time sync */
int network_type; /* (C) net provider type */
int network_card; /* (C) net interface num */
char network_host[512]; /* (C) host network intf */
@@ -332,7 +332,7 @@ pc_version(const char *platform)
* path, well, nothing we can do here.
*/
void
pc_path(wchar_t *dst, int sz, wchar_t *src)
pc_path(wchar_t *dst, int sz, const wchar_t *src)
{
int i = wcslen(usr_path);
@@ -641,7 +641,7 @@ pc_speed_changed(void)
/* Re-load system configuration and restart. */
/* FIXME: this has to be reviewed! */
void
pc_reload(wchar_t *fn)
pc_reload(const wchar_t *fn)
{
int i;

View File

@@ -179,7 +179,7 @@ scsi_card_get_from_internal_name(const char *s)
}
/* Not found. */
return(-1);
return(0);
}

View File

@@ -169,7 +169,7 @@ midi_device_get_from_internal_name(const char *s)
}
/* Not found. */
return(-1);
return(0);
}

View File

@@ -242,7 +242,8 @@ pclog("SOUND: inital()\n");
* initialize the MIDI buffer and source, otherwise, do not.
*/
str = midi_device_get_internal_name(midi_device_current);
if (!strcmp(str, "none") || !strcmp(str, SYSTEM_MIDI_INT)) init_midi = 1;
if ((str != NULL) &&
(!strcmp(str, "none") || !strcmp(str, SYSTEM_MIDI_INT))) init_midi = 1;
#ifdef USE_OPENAL
if (sound_is_float) {

View File

@@ -10,7 +10,7 @@
*
* NOTE: See MSC_ macros for allocation on stack. --FvK
*
* Version: @(#)snd_dbopl.cpp 1.0.4 2018/04/08
* Version: @(#)snd_dbopl.cpp 1.0.5 2018/04/10
*
* Authors: Fred N. van Kempen, <decwiz@yahoo.com>
* Miran Grca, <mgrca8@gmail.com>
@@ -40,9 +40,9 @@
* USA.
*/
#ifdef _MSC_VER
/* for _alloca() and printing of the related error message with pclog() */
/* for malloc() and printing of the related error message with pclog() */
# include <stdio.h>
# include <malloc.h>
# include <stdlib.h>
# include <stdint.h>
# include "../emu.h"
#endif
@@ -189,6 +189,10 @@ uint8_t opl_read(int nr, uint16_t addr)
void opl2_update(int nr, int16_t *buffer, int samples)
{
#ifdef _MSC_VER
static Bit32s *buffer_32 = NULL;
static Bit32s buffer_sz = 0;
#endif
int c;
#ifdef _MSC_VER
/* TODO: Fix this to use a static buffer */
@@ -197,7 +201,12 @@ void opl2_update(int nr, int16_t *buffer, int samples)
pclog("opl2_update: possible stack overflow detected. sample count was %d", samples);
return;
}
Bit32s *buffer_32 = (Bit32s *)_alloca(sizeof(Bit32s) * samples);
if (sizeof(Bit32s) * samples) > buffer_sz) {
if (buffer_32 != NULL)
free(buffer_32);
buffer_sz = sizeof(Bit32s) * samples);
buffer_32 = (Bit32s *)malloc(buffer_sz);
}
#else
Bit32s buffer_32[samples];
#endif
@@ -210,6 +219,10 @@ void opl2_update(int nr, int16_t *buffer, int samples)
void opl3_update(int nr, int16_t *buffer, int samples)
{
#ifdef _MSC_VER
static Bit32s *buffer_32 = NULL;
static Bit32s buffer_sz = 0;
#endif
int c;
#ifdef _MSC_VER
/* TODO: Fix this to use a static buffer */
@@ -218,7 +231,12 @@ void opl3_update(int nr, int16_t *buffer, int samples)
pclog("opl2_update: possible stack overflow detected. sample count was %d", samples);
return;
}
Bit32s *buffer_32 = (Bit32s *)_alloca(sizeof(Bit32s) * samples);
if (sizeof(Bit32s) * samples * 2) > buffer_sz) {
if (buffer_32 != NULL)
free(buffer_32);
buffer_sz = sizeof(Bit32s) * samples * 2);
buffer_32 = (Bit32s *)malloc(buffer_sz);
}
#else
Bit32s buffer_32[samples*2];
#endif

View File

@@ -187,5 +187,5 @@ sound_card_get_from_internal_name(const char *s)
}
/* Not found. */
return(-1);
return(0);
}

View File

@@ -367,9 +367,9 @@ BEGIN
LTEXT "Disk size:",IDT_1750,7,25,44,12,SS_CENTERIMAGE
LTEXT "RPM mode:",IDT_1751,7,45,44,12,SS_CENTERIMAGE
EDITTEXT IDC_EDIT_FILE_NAME,53,5,154,14,ES_AUTOHSCROLL | ES_READONLY
COMBOBOX IDC_COMBO_DISK_SIZE,53,25,166,14,CBS_DROPDOWNLIST |
COMBOBOX IDC_COMBO_DISK_SIZE,53,25,166,120,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP
COMBOBOX IDC_COMBO_RPM_MODE,53,45,166,14,CBS_DROPDOWNLIST |
COMBOBOX IDC_COMBO_RPM_MODE,53,45,166,120,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP
PUSHBUTTON "...",IDC_CFILE,206,5,13,14
LTEXT "Progress:",IDT_1757,7,45,44,12,SS_CENTERIMAGE
@@ -570,19 +570,19 @@ BEGIN
PUSHBUTTON "&New...",IDC_BUTTON_HDD_ADD_NEW,60,137,62,10
PUSHBUTTON "&Existing...",IDC_BUTTON_HDD_ADD,129,137,62,10
PUSHBUTTON "&Remove",IDC_BUTTON_HDD_REMOVE,198,137,62,10
COMBOBOX IDC_COMBO_HD_BUS,33,117,90,12,CBS_DROPDOWNLIST |
COMBOBOX IDC_COMBO_HD_BUS,33,117,90,120,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP
LTEXT "Bus:",IDT_1721,7,119,24,8
COMBOBOX IDC_COMBO_HD_CHANNEL,170,117,90,12,CBS_DROPDOWNLIST |
COMBOBOX IDC_COMBO_HD_CHANNEL,170,117,90,120,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP
LTEXT "Channel:",IDT_1722,131,119,38,8
COMBOBOX IDC_COMBO_HD_ID,170,117,22,12,CBS_DROPDOWNLIST |
COMBOBOX IDC_COMBO_HD_ID,170,117,22,120,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP
LTEXT "ID:",IDT_1723,131,119,38,8
COMBOBOX IDC_COMBO_HD_LUN,239,117,22,12,CBS_DROPDOWNLIST |
COMBOBOX IDC_COMBO_HD_LUN,239,117,22,120,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP
LTEXT "LUN:",IDT_1724,200,119,38,8
COMBOBOX IDC_COMBO_HD_CHANNEL_IDE,170,117,90,12,CBS_DROPDOWNLIST |
COMBOBOX IDC_COMBO_HD_CHANNEL_IDE,170,117,90,120,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP
END
@@ -599,7 +599,7 @@ BEGIN
EDITTEXT IDC_EDIT_HD_HPC,112,34,28,12
EDITTEXT IDC_EDIT_HD_CYL,42,34,28,12
EDITTEXT IDC_EDIT_HD_SIZE,42,52,28,12
COMBOBOX IDC_COMBO_HD_TYPE,113,52,98,12,CBS_DROPDOWNLIST |
COMBOBOX IDC_COMBO_HD_TYPE,113,52,98,120,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP
LTEXT "Sectors:",IDT_1726,154,35,27,10
LTEXT "Heads:",IDT_1727,81,35,29,8
@@ -607,19 +607,19 @@ BEGIN
LTEXT "Size (MB):",IDT_1729,7,54,33,8
LTEXT "Type:",IDT_1730,86,54,24,8
LTEXT "File name:",IDT_1731,7,7,204,9
COMBOBOX IDC_COMBO_HD_BUS,33,71,58,12,CBS_DROPDOWNLIST |
COMBOBOX IDC_COMBO_HD_BUS,33,71,58,120,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP
LTEXT "Bus:",IDT_1721,7,73,24,8
COMBOBOX IDC_COMBO_HD_CHANNEL,134,71,77,12,CBS_DROPDOWNLIST |
COMBOBOX IDC_COMBO_HD_CHANNEL,134,71,77,120,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP
LTEXT "Channel:",IDT_1722,99,73,34,8
COMBOBOX IDC_COMBO_HD_ID,133,71,26,12,CBS_DROPDOWNLIST |
COMBOBOX IDC_COMBO_HD_ID,133,71,26,120,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP
LTEXT "ID:",IDT_1723,117,73,15,8
COMBOBOX IDC_COMBO_HD_LUN,185,71,26,12,CBS_DROPDOWNLIST |
COMBOBOX IDC_COMBO_HD_LUN,185,71,26,120,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP
LTEXT "LUN:",IDT_1724,168,73,15,8
COMBOBOX IDC_COMBO_HD_CHANNEL_IDE,134,71,77,12,CBS_DROPDOWNLIST |
COMBOBOX IDC_COMBO_HD_CHANNEL_IDE,134,71,77,120,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP
LTEXT "Progress:",IDT_1752,7,7,204,9
CONTROL "IMGCreateProgress",IDC_PBAR_IMG_CREATE,"msctls_progress32",PBS_SMOOTH |
@@ -634,7 +634,7 @@ BEGIN
LVS_REPORT | LVS_SHOWSELALWAYS | LVS_SINGLESEL | WS_BORDER |
WS_TABSTOP,7,18,253,60
LTEXT "Floppy drives:",IDT_1737,7,7,43,8
COMBOBOX IDC_COMBO_FD_TYPE,33,85,90,12,CBS_DROPDOWNLIST |
COMBOBOX IDC_COMBO_FD_TYPE,33,85,90,120,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP
LTEXT "Type:",IDT_1738,7,87,24,8
CONTROL "Turbo timings",IDC_CHECKTURBO,"Button",
@@ -651,35 +651,35 @@ BEGIN
LVS_SHOWSELALWAYS | LVS_SINGLESEL | WS_BORDER |
WS_TABSTOP,7,18,253,60
LTEXT "CD-ROM drives:",IDT_1739,7,7,50,8
COMBOBOX IDC_COMBO_CD_BUS,33,85,90,12,CBS_DROPDOWNLIST |
COMBOBOX IDC_COMBO_CD_BUS,33,85,90,120,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP
LTEXT "Bus:",IDT_1740,7,87,24,8
COMBOBOX IDC_COMBO_CD_ID,170,85,22,12,CBS_DROPDOWNLIST |
COMBOBOX IDC_COMBO_CD_ID,170,85,22,120,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP
LTEXT "ID:",IDT_1741,131,87,38,8
COMBOBOX IDC_COMBO_CD_LUN,239,85,22,12,CBS_DROPDOWNLIST |
COMBOBOX IDC_COMBO_CD_LUN,239,85,22,120,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP
LTEXT "LUN:",IDT_1742,200,87,38,8
COMBOBOX IDC_COMBO_CD_CHANNEL_IDE,170,85,90,12,CBS_DROPDOWNLIST |
COMBOBOX IDC_COMBO_CD_CHANNEL_IDE,170,85,90,120,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP
LTEXT "Channel:",IDT_1743,131,87,38,8
COMBOBOX IDC_COMBO_CD_SPEED,33,105,90,12,CBS_DROPDOWNLIST |
COMBOBOX IDC_COMBO_CD_SPEED,33,105,90,120,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP
LTEXT "Speed:",IDT_1761,7,107,24,8
CONTROL "List1",IDC_LIST_ZIP_DRIVES,"SysListView32",LVS_REPORT |
LVS_SHOWSELALWAYS | LVS_SINGLESEL | WS_BORDER |
WS_TABSTOP,7,137,253,60
LTEXT "ZIP drives:",IDT_1762,7,127,50,8
COMBOBOX IDC_COMBO_ZIP_BUS,73,204,90,12,CBS_DROPDOWNLIST |
COMBOBOX IDC_COMBO_ZIP_BUS,73,204,90,120,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP
LTEXT "Bus:",IDT_1753,57,206,14,8
COMBOBOX IDC_COMBO_ZIP_ID,190,204,22,12,CBS_DROPDOWNLIST |
COMBOBOX IDC_COMBO_ZIP_ID,190,204,22,120,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP
LTEXT "ID:",IDT_1754,171,206,18,8
COMBOBOX IDC_COMBO_ZIP_LUN,239,204,22,12,CBS_DROPDOWNLIST |
COMBOBOX IDC_COMBO_ZIP_LUN,239,204,22,120,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP
LTEXT "LUN:",IDT_1755,220,206,18,8
COMBOBOX IDC_COMBO_ZIP_CHANNEL_IDE,200,204,60,12,CBS_DROPDOWNLIST |
COMBOBOX IDC_COMBO_ZIP_CHANNEL_IDE,200,204,60,120,CBS_DROPDOWNLIST |
WS_VSCROLL | WS_TABSTOP
LTEXT "Channel:",IDT_1756,171,206,28,8
CONTROL "ZIP 250",IDC_CHECK250,"Button",

Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 71 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 124 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 385 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 385 KiB

View File

@@ -8,7 +8,7 @@
#
# Makefile for Windows using Visual Studio 2015.
#
# Version: @(#)Makefile.VC 1.0.9 2018/04/09
# Version: @(#)Makefile.VC 1.0.10 2018/04/10
#
# Author: Fred N. van Kempen, <decwiz@yahoo.com>
#
@@ -246,7 +246,6 @@ OPTS := $(EXTRAS) $(STUFF) $(VCOPTS) \
$(WPCAPINC) $(SYSINC)
AFLAGS := /arch:SSE2
RFLAGS :=
LDFLAGS := $(LOPTS)
COPTS := -W3
CXXOPTS := -EHsc
DOPTS :=
@@ -292,7 +291,7 @@ ifeq ($(RELEASE), y)
RFLAGS += -DRELEASE_BUILD
endif
ifeq ($(PROFILER), y)
LDFLAGS += /MAP
LOPTS += /MAP
endif
ifeq ($(VRAMDUMP), y)
OPTS += -DENABLE_VRAM_DUMP
@@ -441,6 +440,7 @@ endif
# Final versions of the toolchain flags.
LDFLAGS := $(LOPTS)
CFLAGS := $(WX_FLAGS) $(OPTS) $(COPTS) $(DOPTS) $(AOPTIM) $(AFLAGS)
CXXFLAGS := $(WX_FLAGS) $(OPTS) $(CXXOPTS) $(COPTS) $(DOPTS) $(AOPTIM) $(AFLAGS)

View File

@@ -141,7 +141,7 @@ peripherals_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
c = d = 0;
while (1) {
stransi = scsi_card_getname(c);
if (! *stransi)
if (stransi == NULL)
break;
scsi_to_list[c] = d;