2018-08-14 18:07:52 +02:00
|
|
|
|
/*
|
2018-03-13 03:46:10 +01:00
|
|
|
|
* VARCem Virtual ARchaeological Computer EMulator.
|
|
|
|
|
|
* An emulator of (mostly) x86-based PC systems and devices,
|
|
|
|
|
|
* using the ISA,EISA,VLB,MCA and PCI system buses, roughly
|
|
|
|
|
|
* spanning the era between 1981 and 1995.
|
2017-05-30 03:38:38 +02:00
|
|
|
|
*
|
2018-03-13 03:46:10 +01:00
|
|
|
|
* This file is part of the VARCem Project.
|
2017-05-30 03:38:38 +02:00
|
|
|
|
*
|
2018-03-13 03:46:10 +01:00
|
|
|
|
* Implement a generic NVRAM/CMOS/RTC device.
|
2017-05-30 03:38:38 +02:00
|
|
|
|
*
|
2019-11-19 04:47:00 +01:00
|
|
|
|
* Version: @(#)nvr.c 1.0.19 2019/11/19
|
2017-10-03 16:26:55 -04:00
|
|
|
|
*
|
2018-08-04 01:36:49 +02:00
|
|
|
|
* Authors: Fred N. van Kempen, <decwiz@yahoo.com>,
|
|
|
|
|
|
* David Hrdlička, <hrdlickadavid@outlook.com>
|
2017-10-03 16:26:55 -04:00
|
|
|
|
*
|
Added the IBM 5161 ISA expansion for PC and XT;
Cleaned up the parallel port emulation, added IRQ support, and made enabling/disabling per port;
Added the Award 430NX and the Intel Classic/PCI (Alfredo, 420TX);
Finished the 586MC1;
Added 8087 emulation;
Moved Cyrix 6x86'es to the Dev branch;
Sanitized/cleaned up memregs.c/h and intel.c/h;
Split the chipsets from machines and sanitized Port 92 emulation;
Added support for the 15bpp mode to the Compaq ATI 28800;
Moved the MR 386DX and 486 machines to the Dev branch;
Ported the new dynamic recompiler from PCem, but it remains in Dev branch until after v2.00;
Ported the new timer code from PCem;
Cleaned up the CPU table of unused stuff and better optimized its structure;
Ported the Open-XT and Open-AT from VARCem, the Open-AT is in the Dev branch;
Ported the XT MFM controller rewrite and adding of more controllers (incl. two RLL ones), from VARCem;
Added the AHA-1540A and the BusTek BT-542B;
Moved the Sumo SCSI-AT to the Dev branch;
Minor IDE, FDC, and floppy drive code clean-ups;
Made NCR 5380/53C400-based cards' BIOS address configurable;
Got rid of the legacy romset variable;
Unified (video) buffer and buffer32 into one and make the unified buffer 32-bit;
Added the Amstead PPC512 per PCem patch by John Elliott;
Switched memory mapping granularity from 16k to 4k (less than 1k not possible due to internal pages);
Rewrote the CL-GD 54xx blitter, fixes Win-OS/2 on the 54x6 among other thing;
Added the Image Manager 1024 and Professional Graphics Controller per PCem patch by John Elliott and work done on VARCem;
Added Headland HT-216, GC-205 and Video 7 VGA 1024i emulation based on PCem commit;
Implemented the fuction keys for the Toshiba T1000/T1200/T3100 enhancement;
Amstrad MegaPC does now works correctly with non-internal graphics card;
The SLiRP code no longer casts a packed struct type to a non-packed struct type;
The Xi8088 and PB410a no longer hang on 86Box when PS/2 mouse is not present;
The S3 Virge on BeOS is no longer broken (was broken by build #1591);
OS/2 2.0 build 6.167 now sees key presses again;
Xi8088 now work on CGA again;
86F images converted from either the old or new variants of the HxC MFM format now work correctly;
Hardware interrupts with a vector of 0xFF are now handled correctly;
OPTi 495SX boards no longer incorrectly have 64 MB maximum RAM when 32 MB is correct;
Fixed VNC keyboard input bugs;
Fixed AT RTC periodic interrupt - Chicago 58s / 73f / 73g / 81 MIDI play no longer hangs with the build's own VTD driver;
Fixed mouse polling with internal mice - Amstrad and Olivetti mice now work correctly;
Triones ATAPI DMA driver now correctly reads a file at the end of a CD image with a sectors number not divisible by 4;
Compaq Portable now works with all graphics cards;
Fixed various MDSI Genius bugs;
Added segment limit checks and improved page fault checks for several CPU instructions - Memphis 15xx WINSETUP and Chicago 58s WINDISK.CPL no longer issue a GPF, and some S3 drivers that used to have glitches, now work correctly;
Further improved the 808x emulation, also fixes the noticably choppy sound when using 808x CPU's, also fixes #355;
OS/2 installer no logner locks up on splash screen on PS/2 Model 70 and 80, fixes #400.
Fixed several Amstead bugs, GEM no longer crashes on the Amstrad 1640, fixes #391.
Ported John Elliott's Amstrad fixes and improvement from PCem, and fixed the default language so it's correctly Engliish, fixes #278, fixes #389.
Fixed a minor IDE timing bug, fixes #388.
Fixed Toshiba T1000 RAM issues, fixes #379.
Fixed EGA/(S)VGA overscan border handling, fixes #378;
Got rid of the now long useless IDE channel 2 auto-removal, fixes #370;
Fixed the BIOS files used by the AMSTRAD PC1512, fixes #366;
Ported the Unicode CD image file name fix from VARCem, fixes #365;
Fixed high density floppy disks on the Xi8088, fixes #359;
Fixed some bugs in the Hercules emulation, fixes #346, fixes #358;
Fixed the SCSI hard disk mode sense pages, fixes #356;
Removed the AMI Unknown 386SX because of impossibility to identify the chipset, closes #349;
Fixed bugs in the serial mouse emulation, fixes #344;
Compiled 86Box binaries now include all the required .DLL's, fixes #341;
Made some combo boxes in the Settings dialog slightly wider, fixes #276.
2019-09-20 14:02:30 +02:00
|
|
|
|
* Copyright 2017-2019 Fred N. van Kempen.
|
|
|
|
|
|
* Copyright 2018,2019 David Hrdlička.
|
2018-03-13 03:46:10 +01:00
|
|
|
|
*
|
|
|
|
|
|
* Redistribution and use in source and binary forms, with
|
|
|
|
|
|
* or without modification, are permitted provided that the
|
|
|
|
|
|
* following conditions are met:
|
|
|
|
|
|
*
|
|
|
|
|
|
* 1. Redistributions of source code must retain the entire
|
|
|
|
|
|
* above notice, this list of conditions and the following
|
|
|
|
|
|
* disclaimer.
|
|
|
|
|
|
*
|
|
|
|
|
|
* 2. Redistributions in binary form must reproduce the above
|
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
|
* following disclaimer in the documentation and/or other
|
|
|
|
|
|
* materials provided with the distribution.
|
|
|
|
|
|
*
|
|
|
|
|
|
* 3. Neither the name of the copyright holder nor the names
|
|
|
|
|
|
* of its contributors may be used to endorse or promote
|
|
|
|
|
|
* products derived from this software without specific
|
|
|
|
|
|
* prior written permission.
|
|
|
|
|
|
*
|
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
|
|
|
|
|
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
|
|
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2017-05-30 03:38:38 +02:00
|
|
|
|
*/
|
2018-05-21 19:04:05 +02:00
|
|
|
|
#include <stdarg.h>
|
2016-06-26 00:34:39 +02:00
|
|
|
|
#include <stdio.h>
|
2017-09-25 04:31:20 -04:00
|
|
|
|
#include <stdint.h>
|
2017-06-08 00:58:47 +02:00
|
|
|
|
#include <string.h>
|
2017-09-25 04:31:20 -04:00
|
|
|
|
#include <stdlib.h>
|
2017-10-03 16:26:55 -04:00
|
|
|
|
#include <time.h>
|
2017-06-08 00:58:47 +02:00
|
|
|
|
#include <wchar.h>
|
2018-05-21 19:04:05 +02:00
|
|
|
|
#define HAVE_STDARG_H
|
2018-02-26 22:18:31 +01:00
|
|
|
|
#include "86box.h"
|
2018-03-13 03:46:10 +01:00
|
|
|
|
#include "machine/machine.h"
|
2018-03-19 04:19:19 +01:00
|
|
|
|
#include "mem.h"
|
2016-06-26 00:34:39 +02:00
|
|
|
|
#include "timer.h"
|
2017-10-10 03:07:29 -04:00
|
|
|
|
#include "plat.h"
|
2017-10-03 16:26:55 -04:00
|
|
|
|
#include "nvr.h"
|
2016-06-26 00:34:39 +02:00
|
|
|
|
|
2017-08-24 01:14:39 -04:00
|
|
|
|
|
2018-03-13 03:46:10 +01:00
|
|
|
|
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 };
|
2018-04-25 23:51:13 +02:00
|
|
|
|
static struct tm intclk;
|
2018-03-13 03:46:10 +01:00
|
|
|
|
static nvr_t *saved_nvr = NULL;
|
2017-10-03 16:26:55 -04:00
|
|
|
|
|
|
|
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
|
#ifdef ENABLE_NVR_LOG
|
|
|
|
|
|
int nvr_do_log = ENABLE_NVR_LOG;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2018-10-19 00:39:32 +02:00
|
|
|
|
nvr_log(const char *fmt, ...)
|
2018-05-21 19:04:05 +02:00
|
|
|
|
{
|
|
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
|
|
|
|
if (nvr_do_log) {
|
2018-10-19 00:39:32 +02:00
|
|
|
|
va_start(ap, fmt);
|
|
|
|
|
|
pclog_ex(fmt, ap);
|
2018-05-21 19:04:05 +02:00
|
|
|
|
va_end(ap);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-10-19 00:39:32 +02:00
|
|
|
|
#else
|
|
|
|
|
|
#define nvr_log(fmt, ...)
|
|
|
|
|
|
#endif
|
2018-05-21 19:04:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
2017-10-03 16:26:55 -04:00
|
|
|
|
/* Determine whether or not the year is leap. */
|
2018-03-13 03:46:10 +01:00
|
|
|
|
int
|
|
|
|
|
|
nvr_is_leap(int year)
|
2016-06-26 00:34:39 +02:00
|
|
|
|
{
|
2017-10-03 16:26:55 -04:00
|
|
|
|
if (year % 400 == 0) return(1);
|
|
|
|
|
|
if (year % 100 == 0) return(0);
|
|
|
|
|
|
if (year % 4 == 0) return(1);
|
|
|
|
|
|
|
|
|
|
|
|
return(0);
|
2016-06-26 00:34:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-03 16:26:55 -04:00
|
|
|
|
|
|
|
|
|
|
/* Determine the days in the current month. */
|
2018-03-13 03:46:10 +01:00
|
|
|
|
int
|
|
|
|
|
|
nvr_get_days(int month, int year)
|
2016-06-26 00:34:39 +02:00
|
|
|
|
{
|
2017-10-03 16:26:55 -04:00
|
|
|
|
if (month != 2)
|
|
|
|
|
|
return(days_in_month[month - 1]);
|
|
|
|
|
|
|
2018-03-13 03:46:10 +01:00
|
|
|
|
return(nvr_is_leap(year) ? 29 : 28);
|
2016-06-26 00:34:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-03 16:26:55 -04:00
|
|
|
|
|
|
|
|
|
|
/* One more second has passed, update the internal clock. */
|
2018-07-15 01:41:53 +02:00
|
|
|
|
void
|
2017-10-03 16:26:55 -04:00
|
|
|
|
rtc_tick(void)
|
2016-06-26 00:34:39 +02:00
|
|
|
|
{
|
2017-10-03 16:26:55 -04:00
|
|
|
|
/* Ping the internal clock. */
|
2018-04-25 23:51:13 +02:00
|
|
|
|
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;
|
|
|
|
|
|
if (++intclk.tm_mon == 13) {
|
|
|
|
|
|
intclk.tm_mon = 1;
|
|
|
|
|
|
intclk.tm_year++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-03 16:26:55 -04:00
|
|
|
|
}
|
2016-06-26 00:34:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-07-11 01:27:23 +02:00
|
|
|
|
|
2017-10-03 16:26:55 -04:00
|
|
|
|
/* This is the RTC one-second timer. */
|
|
|
|
|
|
static void
|
|
|
|
|
|
onesec_timer(void *priv)
|
2016-06-26 00:34:39 +02:00
|
|
|
|
{
|
2017-10-03 16:26:55 -04:00
|
|
|
|
nvr_t *nvr = (nvr_t *)priv;
|
|
|
|
|
|
|
|
|
|
|
|
if (++nvr->onesec_cnt >= 100) {
|
2018-03-13 03:46:10 +01:00
|
|
|
|
/* Update the internal clock. */
|
2018-07-15 01:41:53 +02:00
|
|
|
|
if (!(machines[machine].flags & MACHINE_AT))
|
|
|
|
|
|
rtc_tick();
|
2017-10-07 00:46:54 -04:00
|
|
|
|
|
2018-03-13 03:46:10 +01:00
|
|
|
|
/* Update the RTC device if needed. */
|
|
|
|
|
|
if (nvr->tick != NULL)
|
|
|
|
|
|
(*nvr->tick)(nvr);
|
2017-10-03 16:26:55 -04:00
|
|
|
|
|
|
|
|
|
|
nvr->onesec_cnt = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-11-19 04:47:00 +01:00
|
|
|
|
timer_advance_u64(&nvr->onesec_time, (uint64_t)(10000ULL * TIMER_USEC));
|
2016-06-26 00:34:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-03 16:26:55 -04:00
|
|
|
|
|
2018-03-13 03:46:10 +01:00
|
|
|
|
/* Initialize the generic NVRAM/RTC device. */
|
2017-10-03 16:26:55 -04:00
|
|
|
|
void
|
|
|
|
|
|
nvr_init(nvr_t *nvr)
|
|
|
|
|
|
{
|
2018-03-13 03:46:10 +01:00
|
|
|
|
char temp[64];
|
|
|
|
|
|
struct tm *tm;
|
|
|
|
|
|
time_t now;
|
|
|
|
|
|
int c;
|
2017-06-08 00:58:47 +02:00
|
|
|
|
|
2018-03-13 03:46:10 +01:00
|
|
|
|
/* Set up the NVR file's name. */
|
|
|
|
|
|
sprintf(temp, "%s.nvr", machine_get_internal_name());
|
2018-04-25 23:51:13 +02:00
|
|
|
|
c = strlen(temp);
|
|
|
|
|
|
nvr->fn = (wchar_t *)malloc((c + 1) * sizeof(wchar_t));
|
|
|
|
|
|
mbstowcs(nvr->fn, temp, c + 1);
|
2017-06-08 00:58:47 +02:00
|
|
|
|
|
2018-03-13 03:46:10 +01:00
|
|
|
|
/* Initialize the internal clock as needed. */
|
|
|
|
|
|
memset(&intclk, 0x00, sizeof(intclk));
|
2018-08-01 18:07:52 +02:00
|
|
|
|
if (time_sync & TIME_SYNC_ENABLED) {
|
2018-03-13 03:46:10 +01:00
|
|
|
|
/* Get the current time of day, and convert to local time. */
|
|
|
|
|
|
(void)time(&now);
|
2018-08-01 18:07:52 +02:00
|
|
|
|
if(time_sync & TIME_SYNC_UTC)
|
2018-08-01 17:52:20 +02:00
|
|
|
|
tm = gmtime(&now);
|
|
|
|
|
|
else
|
|
|
|
|
|
tm = localtime(&now);
|
2017-10-03 16:26:55 -04:00
|
|
|
|
|
2018-03-13 03:46:10 +01:00
|
|
|
|
/* Set the internal clock. */
|
|
|
|
|
|
nvr_time_set(tm);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
/* Reset the internal clock to 1980/01/01 00:00. */
|
2018-04-25 23:51:13 +02:00
|
|
|
|
intclk.tm_mon = 1;
|
|
|
|
|
|
intclk.tm_year = 1980;
|
2018-03-13 03:46:10 +01:00
|
|
|
|
}
|
2017-10-03 16:26:55 -04:00
|
|
|
|
|
2018-03-13 03:46:10 +01:00
|
|
|
|
/* Set up our timer. */
|
Added the IBM 5161 ISA expansion for PC and XT;
Cleaned up the parallel port emulation, added IRQ support, and made enabling/disabling per port;
Added the Award 430NX and the Intel Classic/PCI (Alfredo, 420TX);
Finished the 586MC1;
Added 8087 emulation;
Moved Cyrix 6x86'es to the Dev branch;
Sanitized/cleaned up memregs.c/h and intel.c/h;
Split the chipsets from machines and sanitized Port 92 emulation;
Added support for the 15bpp mode to the Compaq ATI 28800;
Moved the MR 386DX and 486 machines to the Dev branch;
Ported the new dynamic recompiler from PCem, but it remains in Dev branch until after v2.00;
Ported the new timer code from PCem;
Cleaned up the CPU table of unused stuff and better optimized its structure;
Ported the Open-XT and Open-AT from VARCem, the Open-AT is in the Dev branch;
Ported the XT MFM controller rewrite and adding of more controllers (incl. two RLL ones), from VARCem;
Added the AHA-1540A and the BusTek BT-542B;
Moved the Sumo SCSI-AT to the Dev branch;
Minor IDE, FDC, and floppy drive code clean-ups;
Made NCR 5380/53C400-based cards' BIOS address configurable;
Got rid of the legacy romset variable;
Unified (video) buffer and buffer32 into one and make the unified buffer 32-bit;
Added the Amstead PPC512 per PCem patch by John Elliott;
Switched memory mapping granularity from 16k to 4k (less than 1k not possible due to internal pages);
Rewrote the CL-GD 54xx blitter, fixes Win-OS/2 on the 54x6 among other thing;
Added the Image Manager 1024 and Professional Graphics Controller per PCem patch by John Elliott and work done on VARCem;
Added Headland HT-216, GC-205 and Video 7 VGA 1024i emulation based on PCem commit;
Implemented the fuction keys for the Toshiba T1000/T1200/T3100 enhancement;
Amstrad MegaPC does now works correctly with non-internal graphics card;
The SLiRP code no longer casts a packed struct type to a non-packed struct type;
The Xi8088 and PB410a no longer hang on 86Box when PS/2 mouse is not present;
The S3 Virge on BeOS is no longer broken (was broken by build #1591);
OS/2 2.0 build 6.167 now sees key presses again;
Xi8088 now work on CGA again;
86F images converted from either the old or new variants of the HxC MFM format now work correctly;
Hardware interrupts with a vector of 0xFF are now handled correctly;
OPTi 495SX boards no longer incorrectly have 64 MB maximum RAM when 32 MB is correct;
Fixed VNC keyboard input bugs;
Fixed AT RTC periodic interrupt - Chicago 58s / 73f / 73g / 81 MIDI play no longer hangs with the build's own VTD driver;
Fixed mouse polling with internal mice - Amstrad and Olivetti mice now work correctly;
Triones ATAPI DMA driver now correctly reads a file at the end of a CD image with a sectors number not divisible by 4;
Compaq Portable now works with all graphics cards;
Fixed various MDSI Genius bugs;
Added segment limit checks and improved page fault checks for several CPU instructions - Memphis 15xx WINSETUP and Chicago 58s WINDISK.CPL no longer issue a GPF, and some S3 drivers that used to have glitches, now work correctly;
Further improved the 808x emulation, also fixes the noticably choppy sound when using 808x CPU's, also fixes #355;
OS/2 installer no logner locks up on splash screen on PS/2 Model 70 and 80, fixes #400.
Fixed several Amstead bugs, GEM no longer crashes on the Amstrad 1640, fixes #391.
Ported John Elliott's Amstrad fixes and improvement from PCem, and fixed the default language so it's correctly Engliish, fixes #278, fixes #389.
Fixed a minor IDE timing bug, fixes #388.
Fixed Toshiba T1000 RAM issues, fixes #379.
Fixed EGA/(S)VGA overscan border handling, fixes #378;
Got rid of the now long useless IDE channel 2 auto-removal, fixes #370;
Fixed the BIOS files used by the AMSTRAD PC1512, fixes #366;
Ported the Unicode CD image file name fix from VARCem, fixes #365;
Fixed high density floppy disks on the Xi8088, fixes #359;
Fixed some bugs in the Hercules emulation, fixes #346, fixes #358;
Fixed the SCSI hard disk mode sense pages, fixes #356;
Removed the AMI Unknown 386SX because of impossibility to identify the chipset, closes #349;
Fixed bugs in the serial mouse emulation, fixes #344;
Compiled 86Box binaries now include all the required .DLL's, fixes #341;
Made some combo boxes in the Settings dialog slightly wider, fixes #276.
2019-09-20 14:02:30 +02:00
|
|
|
|
timer_add(&nvr->onesec_time, onesec_timer, nvr, 1);
|
2017-10-03 16:26:55 -04:00
|
|
|
|
|
|
|
|
|
|
/* It does not need saving yet. */
|
|
|
|
|
|
nvr_dosave = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/* Save the NVR data pointer. */
|
|
|
|
|
|
saved_nvr = nvr;
|
|
|
|
|
|
|
2018-03-13 03:46:10 +01:00
|
|
|
|
/* Try to load the saved data. */
|
|
|
|
|
|
(void)nvr_load();
|
2017-10-03 16:26:55 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-04-25 23:51:13 +02:00
|
|
|
|
/* Get path to the NVR folder. */
|
|
|
|
|
|
wchar_t *
|
|
|
|
|
|
nvr_path(wchar_t *str)
|
|
|
|
|
|
{
|
|
|
|
|
|
static wchar_t temp[1024];
|
|
|
|
|
|
|
|
|
|
|
|
/* Get the full prefix in place. */
|
|
|
|
|
|
memset(temp, 0x00, sizeof(temp));
|
|
|
|
|
|
wcscpy(temp, usr_path);
|
|
|
|
|
|
wcscat(temp, NVR_PATH);
|
|
|
|
|
|
|
|
|
|
|
|
/* Create the directory if needed. */
|
|
|
|
|
|
if (! plat_dir_check(temp))
|
|
|
|
|
|
plat_dir_create(temp);
|
|
|
|
|
|
|
|
|
|
|
|
/* Now append the actual filename. */
|
|
|
|
|
|
plat_path_slash(temp);
|
|
|
|
|
|
wcscat(temp, str);
|
|
|
|
|
|
|
|
|
|
|
|
return(temp);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-10-07 00:46:54 -04:00
|
|
|
|
/*
|
|
|
|
|
|
* Load an NVR from file.
|
|
|
|
|
|
*
|
2017-11-19 21:58:24 -05:00
|
|
|
|
* This function does two things, really. It clears and initializes
|
2017-10-07 00:46:54 -04:00
|
|
|
|
* the RTC and NVRAM areas, sets up defaults for the RTC part, and
|
|
|
|
|
|
* then attempts to load data from a saved file.
|
|
|
|
|
|
*
|
2017-11-19 21:58:24 -05:00
|
|
|
|
* Either way, after that, it will continue to configure the local
|
|
|
|
|
|
* RTC to operate, so it can update either the local RTC, and/or
|
|
|
|
|
|
* the one supplied by a client.
|
2017-10-07 00:46:54 -04:00
|
|
|
|
*/
|
2017-11-19 21:58:24 -05:00
|
|
|
|
int
|
2017-10-03 16:26:55 -04:00
|
|
|
|
nvr_load(void)
|
|
|
|
|
|
{
|
2018-04-25 23:51:13 +02:00
|
|
|
|
wchar_t *path;
|
|
|
|
|
|
FILE *fp;
|
2017-10-03 16:26:55 -04:00
|
|
|
|
|
|
|
|
|
|
/* Make sure we have been initialized. */
|
2017-10-07 00:46:54 -04:00
|
|
|
|
if (saved_nvr == NULL) return(0);
|
2017-10-03 16:26:55 -04:00
|
|
|
|
|
|
|
|
|
|
/* Clear out any old data. */
|
2018-09-15 16:15:39 +02:00
|
|
|
|
memset(saved_nvr->regs, 0x00, sizeof(saved_nvr->regs));
|
2017-10-03 16:26:55 -04:00
|
|
|
|
|
2017-10-07 00:46:54 -04:00
|
|
|
|
/* Set the defaults. */
|
2018-03-13 03:46:10 +01:00
|
|
|
|
if (saved_nvr->reset != NULL)
|
|
|
|
|
|
saved_nvr->reset(saved_nvr);
|
2017-06-08 00:58:47 +02:00
|
|
|
|
|
2018-03-13 03:46:10 +01:00
|
|
|
|
/* Load the (relevant) part of the NVR contents. */
|
|
|
|
|
|
if (saved_nvr->size != 0) {
|
2018-04-25 23:51:13 +02:00
|
|
|
|
path = nvr_path(saved_nvr->fn);
|
2018-05-21 19:04:05 +02:00
|
|
|
|
nvr_log("NVR: loading from '%ls'\n", path);
|
2018-04-25 23:51:13 +02:00
|
|
|
|
fp = plat_fopen(path, L"rb");
|
|
|
|
|
|
if (fp != NULL) {
|
2017-10-07 00:46:54 -04:00
|
|
|
|
/* Read NVR contents from file. */
|
2020-01-15 04:58:28 +01:00
|
|
|
|
if (fread(saved_nvr->regs, 1, saved_nvr->size, fp) != saved_nvr->size)
|
|
|
|
|
|
fatal("nvr_load(): Error reading data\n");
|
2018-04-25 23:51:13 +02:00
|
|
|
|
(void)fclose(fp);
|
2017-10-07 00:46:54 -04:00
|
|
|
|
}
|
2017-10-03 16:26:55 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-07 00:46:54 -04:00
|
|
|
|
/* Get the local RTC running! */
|
2018-03-13 03:46:10 +01:00
|
|
|
|
if (saved_nvr->start != NULL)
|
|
|
|
|
|
saved_nvr->start(saved_nvr);
|
2017-10-07 00:46:54 -04:00
|
|
|
|
|
|
|
|
|
|
return(1);
|
2016-06-26 00:34:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-09-23 21:12:26 -04:00
|
|
|
|
|
2018-09-15 16:15:39 +02:00
|
|
|
|
void
|
|
|
|
|
|
nvr_set_ven_save(void (*ven_save)(void))
|
|
|
|
|
|
{
|
|
|
|
|
|
saved_nvr->ven_save = ven_save;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-10-03 16:26:55 -04:00
|
|
|
|
/* Save the current NVR to a file. */
|
2017-11-19 21:58:24 -05:00
|
|
|
|
int
|
2017-10-03 16:26:55 -04:00
|
|
|
|
nvr_save(void)
|
2016-06-26 00:34:39 +02:00
|
|
|
|
{
|
2018-04-25 23:51:13 +02:00
|
|
|
|
wchar_t *path;
|
|
|
|
|
|
FILE *fp;
|
2017-10-03 16:26:55 -04:00
|
|
|
|
|
|
|
|
|
|
/* Make sure we have been initialized. */
|
2017-10-07 00:46:54 -04:00
|
|
|
|
if (saved_nvr == NULL) return(0);
|
|
|
|
|
|
|
2018-03-13 03:46:10 +01:00
|
|
|
|
if (saved_nvr->size != 0) {
|
2018-04-25 23:51:13 +02:00
|
|
|
|
path = nvr_path(saved_nvr->fn);
|
2018-05-21 19:04:05 +02:00
|
|
|
|
nvr_log("NVR: saving to '%ls'\n", path);
|
2018-04-25 23:51:13 +02:00
|
|
|
|
fp = plat_fopen(path, L"wb");
|
|
|
|
|
|
if (fp != NULL) {
|
2017-10-07 00:46:54 -04:00
|
|
|
|
/* Save NVR contents to file. */
|
2018-04-25 23:51:13 +02:00
|
|
|
|
(void)fwrite(saved_nvr->regs, saved_nvr->size, 1, fp);
|
|
|
|
|
|
fclose(fp);
|
2017-10-07 00:46:54 -04:00
|
|
|
|
}
|
2017-10-03 16:26:55 -04:00
|
|
|
|
}
|
2016-08-15 23:40:02 +02:00
|
|
|
|
|
2018-09-15 16:15:39 +02:00
|
|
|
|
if (saved_nvr->ven_save)
|
|
|
|
|
|
saved_nvr->ven_save();
|
2018-03-19 04:19:19 +01:00
|
|
|
|
|
2017-10-03 16:26:55 -04:00
|
|
|
|
/* Device is clean again. */
|
|
|
|
|
|
nvr_dosave = 0;
|
2017-10-07 00:46:54 -04:00
|
|
|
|
|
|
|
|
|
|
return(1);
|
2016-06-26 00:34:39 +02:00
|
|
|
|
}
|
2017-09-23 21:12:26 -04:00
|
|
|
|
|
|
|
|
|
|
|
2018-04-25 23:51:13 +02:00
|
|
|
|
void
|
Added the IBM 5161 ISA expansion for PC and XT;
Cleaned up the parallel port emulation, added IRQ support, and made enabling/disabling per port;
Added the Award 430NX and the Intel Classic/PCI (Alfredo, 420TX);
Finished the 586MC1;
Added 8087 emulation;
Moved Cyrix 6x86'es to the Dev branch;
Sanitized/cleaned up memregs.c/h and intel.c/h;
Split the chipsets from machines and sanitized Port 92 emulation;
Added support for the 15bpp mode to the Compaq ATI 28800;
Moved the MR 386DX and 486 machines to the Dev branch;
Ported the new dynamic recompiler from PCem, but it remains in Dev branch until after v2.00;
Ported the new timer code from PCem;
Cleaned up the CPU table of unused stuff and better optimized its structure;
Ported the Open-XT and Open-AT from VARCem, the Open-AT is in the Dev branch;
Ported the XT MFM controller rewrite and adding of more controllers (incl. two RLL ones), from VARCem;
Added the AHA-1540A and the BusTek BT-542B;
Moved the Sumo SCSI-AT to the Dev branch;
Minor IDE, FDC, and floppy drive code clean-ups;
Made NCR 5380/53C400-based cards' BIOS address configurable;
Got rid of the legacy romset variable;
Unified (video) buffer and buffer32 into one and make the unified buffer 32-bit;
Added the Amstead PPC512 per PCem patch by John Elliott;
Switched memory mapping granularity from 16k to 4k (less than 1k not possible due to internal pages);
Rewrote the CL-GD 54xx blitter, fixes Win-OS/2 on the 54x6 among other thing;
Added the Image Manager 1024 and Professional Graphics Controller per PCem patch by John Elliott and work done on VARCem;
Added Headland HT-216, GC-205 and Video 7 VGA 1024i emulation based on PCem commit;
Implemented the fuction keys for the Toshiba T1000/T1200/T3100 enhancement;
Amstrad MegaPC does now works correctly with non-internal graphics card;
The SLiRP code no longer casts a packed struct type to a non-packed struct type;
The Xi8088 and PB410a no longer hang on 86Box when PS/2 mouse is not present;
The S3 Virge on BeOS is no longer broken (was broken by build #1591);
OS/2 2.0 build 6.167 now sees key presses again;
Xi8088 now work on CGA again;
86F images converted from either the old or new variants of the HxC MFM format now work correctly;
Hardware interrupts with a vector of 0xFF are now handled correctly;
OPTi 495SX boards no longer incorrectly have 64 MB maximum RAM when 32 MB is correct;
Fixed VNC keyboard input bugs;
Fixed AT RTC periodic interrupt - Chicago 58s / 73f / 73g / 81 MIDI play no longer hangs with the build's own VTD driver;
Fixed mouse polling with internal mice - Amstrad and Olivetti mice now work correctly;
Triones ATAPI DMA driver now correctly reads a file at the end of a CD image with a sectors number not divisible by 4;
Compaq Portable now works with all graphics cards;
Fixed various MDSI Genius bugs;
Added segment limit checks and improved page fault checks for several CPU instructions - Memphis 15xx WINSETUP and Chicago 58s WINDISK.CPL no longer issue a GPF, and some S3 drivers that used to have glitches, now work correctly;
Further improved the 808x emulation, also fixes the noticably choppy sound when using 808x CPU's, also fixes #355;
OS/2 installer no logner locks up on splash screen on PS/2 Model 70 and 80, fixes #400.
Fixed several Amstead bugs, GEM no longer crashes on the Amstrad 1640, fixes #391.
Ported John Elliott's Amstrad fixes and improvement from PCem, and fixed the default language so it's correctly Engliish, fixes #278, fixes #389.
Fixed a minor IDE timing bug, fixes #388.
Fixed Toshiba T1000 RAM issues, fixes #379.
Fixed EGA/(S)VGA overscan border handling, fixes #378;
Got rid of the now long useless IDE channel 2 auto-removal, fixes #370;
Fixed the BIOS files used by the AMSTRAD PC1512, fixes #366;
Ported the Unicode CD image file name fix from VARCem, fixes #365;
Fixed high density floppy disks on the Xi8088, fixes #359;
Fixed some bugs in the Hercules emulation, fixes #346, fixes #358;
Fixed the SCSI hard disk mode sense pages, fixes #356;
Removed the AMI Unknown 386SX because of impossibility to identify the chipset, closes #349;
Fixed bugs in the serial mouse emulation, fixes #344;
Compiled 86Box binaries now include all the required .DLL's, fixes #341;
Made some combo boxes in the Settings dialog slightly wider, fixes #276.
2019-09-20 14:02:30 +02:00
|
|
|
|
nvr_close(void)
|
2018-04-25 23:51:13 +02:00
|
|
|
|
{
|
Added the IBM 5161 ISA expansion for PC and XT;
Cleaned up the parallel port emulation, added IRQ support, and made enabling/disabling per port;
Added the Award 430NX and the Intel Classic/PCI (Alfredo, 420TX);
Finished the 586MC1;
Added 8087 emulation;
Moved Cyrix 6x86'es to the Dev branch;
Sanitized/cleaned up memregs.c/h and intel.c/h;
Split the chipsets from machines and sanitized Port 92 emulation;
Added support for the 15bpp mode to the Compaq ATI 28800;
Moved the MR 386DX and 486 machines to the Dev branch;
Ported the new dynamic recompiler from PCem, but it remains in Dev branch until after v2.00;
Ported the new timer code from PCem;
Cleaned up the CPU table of unused stuff and better optimized its structure;
Ported the Open-XT and Open-AT from VARCem, the Open-AT is in the Dev branch;
Ported the XT MFM controller rewrite and adding of more controllers (incl. two RLL ones), from VARCem;
Added the AHA-1540A and the BusTek BT-542B;
Moved the Sumo SCSI-AT to the Dev branch;
Minor IDE, FDC, and floppy drive code clean-ups;
Made NCR 5380/53C400-based cards' BIOS address configurable;
Got rid of the legacy romset variable;
Unified (video) buffer and buffer32 into one and make the unified buffer 32-bit;
Added the Amstead PPC512 per PCem patch by John Elliott;
Switched memory mapping granularity from 16k to 4k (less than 1k not possible due to internal pages);
Rewrote the CL-GD 54xx blitter, fixes Win-OS/2 on the 54x6 among other thing;
Added the Image Manager 1024 and Professional Graphics Controller per PCem patch by John Elliott and work done on VARCem;
Added Headland HT-216, GC-205 and Video 7 VGA 1024i emulation based on PCem commit;
Implemented the fuction keys for the Toshiba T1000/T1200/T3100 enhancement;
Amstrad MegaPC does now works correctly with non-internal graphics card;
The SLiRP code no longer casts a packed struct type to a non-packed struct type;
The Xi8088 and PB410a no longer hang on 86Box when PS/2 mouse is not present;
The S3 Virge on BeOS is no longer broken (was broken by build #1591);
OS/2 2.0 build 6.167 now sees key presses again;
Xi8088 now work on CGA again;
86F images converted from either the old or new variants of the HxC MFM format now work correctly;
Hardware interrupts with a vector of 0xFF are now handled correctly;
OPTi 495SX boards no longer incorrectly have 64 MB maximum RAM when 32 MB is correct;
Fixed VNC keyboard input bugs;
Fixed AT RTC periodic interrupt - Chicago 58s / 73f / 73g / 81 MIDI play no longer hangs with the build's own VTD driver;
Fixed mouse polling with internal mice - Amstrad and Olivetti mice now work correctly;
Triones ATAPI DMA driver now correctly reads a file at the end of a CD image with a sectors number not divisible by 4;
Compaq Portable now works with all graphics cards;
Fixed various MDSI Genius bugs;
Added segment limit checks and improved page fault checks for several CPU instructions - Memphis 15xx WINSETUP and Chicago 58s WINDISK.CPL no longer issue a GPF, and some S3 drivers that used to have glitches, now work correctly;
Further improved the 808x emulation, also fixes the noticably choppy sound when using 808x CPU's, also fixes #355;
OS/2 installer no logner locks up on splash screen on PS/2 Model 70 and 80, fixes #400.
Fixed several Amstead bugs, GEM no longer crashes on the Amstrad 1640, fixes #391.
Ported John Elliott's Amstrad fixes and improvement from PCem, and fixed the default language so it's correctly Engliish, fixes #278, fixes #389.
Fixed a minor IDE timing bug, fixes #388.
Fixed Toshiba T1000 RAM issues, fixes #379.
Fixed EGA/(S)VGA overscan border handling, fixes #378;
Got rid of the now long useless IDE channel 2 auto-removal, fixes #370;
Fixed the BIOS files used by the AMSTRAD PC1512, fixes #366;
Ported the Unicode CD image file name fix from VARCem, fixes #365;
Fixed high density floppy disks on the Xi8088, fixes #359;
Fixed some bugs in the Hercules emulation, fixes #346, fixes #358;
Fixed the SCSI hard disk mode sense pages, fixes #356;
Removed the AMI Unknown 386SX because of impossibility to identify the chipset, closes #349;
Fixed bugs in the serial mouse emulation, fixes #344;
Compiled 86Box binaries now include all the required .DLL's, fixes #341;
Made some combo boxes in the Settings dialog slightly wider, fixes #276.
2019-09-20 14:02:30 +02:00
|
|
|
|
saved_nvr = NULL;
|
2018-04-25 23:51:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-13 03:46:10 +01:00
|
|
|
|
/* Get current time from internal clock. */
|
|
|
|
|
|
void
|
|
|
|
|
|
nvr_time_get(struct tm *tm)
|
|
|
|
|
|
{
|
2018-04-29 00:40:26 +02:00
|
|
|
|
uint8_t dom, mon, sum, wd;
|
|
|
|
|
|
uint16_t cent, yr;
|
2018-03-13 03:46:10 +01:00
|
|
|
|
|
2018-04-25 23:51:13 +02:00
|
|
|
|
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;
|
2018-03-13 03:46:10 +01:00
|
|
|
|
sum = dom+mon+yr+cent;
|
|
|
|
|
|
wd = ((sum + 6) % 7);
|
|
|
|
|
|
tm->tm_wday = wd;
|
2018-04-25 23:51:13 +02:00
|
|
|
|
tm->tm_mday = intclk.tm_mday;
|
|
|
|
|
|
tm->tm_mon = (intclk.tm_mon - 1);
|
|
|
|
|
|
tm->tm_year = (intclk.tm_year - 1900);
|
2018-03-13 03:46:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Set internal clock time. */
|
|
|
|
|
|
void
|
|
|
|
|
|
nvr_time_set(struct tm *tm)
|
|
|
|
|
|
{
|
2018-04-25 23:51:13 +02:00
|
|
|
|
intclk.tm_sec = tm->tm_sec;
|
|
|
|
|
|
intclk.tm_min = tm->tm_min;
|
|
|
|
|
|
intclk.tm_hour = tm->tm_hour;
|
2018-04-29 03:34:43 +02:00
|
|
|
|
intclk.tm_wday = tm->tm_wday;
|
2018-04-25 23:51:13 +02:00
|
|
|
|
intclk.tm_mday = tm->tm_mday;
|
|
|
|
|
|
intclk.tm_mon = (tm->tm_mon + 1);
|
|
|
|
|
|
intclk.tm_year = (tm->tm_year + 1900);
|
2017-09-23 21:12:26 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-10-03 16:26:55 -04:00
|
|
|
|
/* Open or create a file in the NVR area. */
|
2017-09-23 21:12:26 -04:00
|
|
|
|
FILE *
|
2017-10-03 16:26:55 -04:00
|
|
|
|
nvr_fopen(wchar_t *str, wchar_t *mode)
|
2017-09-23 21:12:26 -04:00
|
|
|
|
{
|
2017-10-12 14:25:17 -04:00
|
|
|
|
return(plat_fopen(nvr_path(str), mode));
|
2017-09-23 21:12:26 -04:00
|
|
|
|
}
|