Make RTC/NVR a normal device instead of a special thing. Fixes nvr_recalc() being called on systems without NVR, which could cause timer crashes.
This commit is contained in:
parent
58e42fda81
commit
3508059f16
4 changed files with 90 additions and 52 deletions
14
src/model.c
14
src/model.c
|
|
@ -372,7 +372,7 @@ void ams_init()
|
|||
lpt1_remove();
|
||||
amstrad_init();
|
||||
keyboard_amstrad_init();
|
||||
nvr_init();
|
||||
device_add(&nvr_device);
|
||||
nmi_init();
|
||||
fdc_set_dskchg_activelow();
|
||||
device_add(&gameport_device);
|
||||
|
|
@ -393,7 +393,7 @@ void olim24_init()
|
|||
common_init();
|
||||
mem_add_bios();
|
||||
keyboard_olim24_init();
|
||||
nvr_init();
|
||||
device_add(&nvr_device);
|
||||
olivetti_m24_init();
|
||||
nmi_init();
|
||||
device_add(&gameport_device);
|
||||
|
|
@ -429,7 +429,7 @@ void xt_xi8088_init()
|
|||
keyboard_at_init();
|
||||
keyboard_at_init_ps2();
|
||||
nmi_init();
|
||||
nvr_init();
|
||||
device_add(&nvr_device);
|
||||
pic2_init();
|
||||
device_add(&gameport_device);
|
||||
}
|
||||
|
|
@ -442,7 +442,7 @@ void at_init()
|
|||
pit_set_out_func(&pit, 1, pit_refresh_timer_at);
|
||||
dma16_init();
|
||||
keyboard_at_init();
|
||||
nvr_init();
|
||||
device_add(&nvr_device);
|
||||
pic2_init();
|
||||
device_add(&gameport_device);
|
||||
nmi_mask = 0;
|
||||
|
|
@ -480,7 +480,7 @@ void ps1_common_init()
|
|||
pit_set_out_func(&pit, 1, pit_refresh_timer_at);
|
||||
dma16_init();
|
||||
keyboard_at_init();
|
||||
nvr_init();
|
||||
device_add(&nvr_device);
|
||||
pic2_init();
|
||||
fdc_set_dskchg_activelow();
|
||||
device_add(&ps1_audio_device);
|
||||
|
|
@ -511,7 +511,7 @@ void ps2_m30_286_init()
|
|||
dma16_init();
|
||||
keyboard_at_init();
|
||||
// mouse_ps2_init();
|
||||
nvr_init();
|
||||
device_add(&nvr_device);
|
||||
pic2_init();
|
||||
ps2board_init();
|
||||
fdc_set_dskchg_activelow();
|
||||
|
|
@ -527,7 +527,7 @@ static void ps2_common_init()
|
|||
keyboard_at_init();
|
||||
keyboard_at_init_ps2();
|
||||
// mouse_ps2_init();
|
||||
nvr_init();
|
||||
device_add(&nvr_device);
|
||||
pic2_init();
|
||||
|
||||
pit_ps2_init();
|
||||
|
|
|
|||
120
src/nvr.c
120
src/nvr.c
|
|
@ -1,5 +1,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "ibm.h"
|
||||
#include "device.h"
|
||||
#include "io.h"
|
||||
#include "nvr.h"
|
||||
#include "nvr_tc8521.h"
|
||||
|
|
@ -20,10 +22,14 @@ int nvraddr;
|
|||
|
||||
int nvr_dosave = 0;
|
||||
|
||||
static pc_timer_t nvr_onesec_timer;
|
||||
static int nvr_onesec_cnt = 0;
|
||||
typedef struct nvr_t
|
||||
{
|
||||
pc_timer_t rtc_timer;
|
||||
pc_timer_t onesec_timer;
|
||||
pc_timer_t update_end_timer;
|
||||
|
||||
static pc_timer_t rtc_timer;
|
||||
int onesec_cnt;
|
||||
} nvr_t;
|
||||
|
||||
FILE *nvrfopen(char *fn, char *mode)
|
||||
{
|
||||
|
|
@ -61,37 +67,44 @@ void getnvrtime()
|
|||
time_get(nvrram);
|
||||
}
|
||||
|
||||
void nvr_recalc()
|
||||
static void nvr_speed_changed(void *p)
|
||||
{
|
||||
int c;
|
||||
nvr_t *nvr = (nvr_t *)p;
|
||||
|
||||
if (!(nvrram[RTC_REGA] & RTC_RS))
|
||||
{
|
||||
timer_disable(&rtc_timer);
|
||||
timer_disable(&nvr->rtc_timer);
|
||||
return;
|
||||
}
|
||||
c = 1 << ((nvrram[RTC_REGA] & RTC_RS) - 1);
|
||||
timer_set_delay_u64(&rtc_timer, (uint64_t)(RTCCONST * c));
|
||||
else
|
||||
{
|
||||
int c = 1 << ((nvrram[RTC_REGA] & RTC_RS) - 1);
|
||||
timer_set_delay_u64(&nvr->rtc_timer, (uint64_t)(RTCCONST * c));
|
||||
}
|
||||
}
|
||||
|
||||
void nvr_rtc(void *p)
|
||||
static void nvr_rtc(void *p)
|
||||
{
|
||||
int c;
|
||||
nvr_t *nvr = (nvr_t *)p;
|
||||
|
||||
if (!(nvrram[RTC_REGA] & RTC_RS))
|
||||
{
|
||||
timer_disable(&rtc_timer);
|
||||
timer_disable(&nvr->rtc_timer);
|
||||
return;
|
||||
}
|
||||
c = 1 << ((nvrram[RTC_REGA] & RTC_RS) - 1);
|
||||
timer_advance_u64(&rtc_timer, (uint64_t)(RTCCONST * c));
|
||||
// pclog("RTCtime now %f\n",rtctime);
|
||||
nvrram[RTC_REGC] |= RTC_PF;
|
||||
if (nvrram[RTC_REGB] & RTC_PIE)
|
||||
else
|
||||
{
|
||||
nvrram[RTC_REGC] |= RTC_IRQF;
|
||||
if (AMSTRAD) picint(2);
|
||||
else picint(0x100);
|
||||
// pclog("RTC int\n");
|
||||
int c = 1 << ((nvrram[RTC_REGA] & RTC_RS) - 1);
|
||||
timer_advance_u64(&nvr->rtc_timer, (uint64_t)(RTCCONST * c));
|
||||
// pclog("RTCtime now %f\n",rtctime);
|
||||
nvrram[RTC_REGC] |= RTC_PF;
|
||||
if (nvrram[RTC_REGB] & RTC_PIE)
|
||||
{
|
||||
nvrram[RTC_REGC] |= RTC_IRQF;
|
||||
if (AMSTRAD) picint(2);
|
||||
else picint(0x100);
|
||||
// pclog("RTC int\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -104,10 +117,11 @@ int nvr_check_alarm(int nvraddr)
|
|||
return (nvrram[nvraddr + 1] == nvrram[nvraddr] || (nvrram[nvraddr + 1] & ALARM_DONTCARE) == ALARM_DONTCARE);
|
||||
}
|
||||
|
||||
pc_timer_t nvr_update_end_timer;
|
||||
|
||||
void nvr_update_end(void *p)
|
||||
static void nvr_update_end(void *p)
|
||||
{
|
||||
// nvr_t *nvr = (nvr_t *)p;
|
||||
|
||||
if (!(nvrram[RTC_REGB] & RTC_SET))
|
||||
{
|
||||
getnvrtime();
|
||||
|
|
@ -138,25 +152,28 @@ void nvr_update_end(void *p)
|
|||
// pclog("RTC onesec\n");
|
||||
}
|
||||
|
||||
void nvr_onesec(void *p)
|
||||
static void nvr_onesec(void *p)
|
||||
{
|
||||
nvr_onesec_cnt++;
|
||||
if (nvr_onesec_cnt >= 100)
|
||||
nvr_t *nvr = (nvr_t *)p;
|
||||
|
||||
nvr->onesec_cnt++;
|
||||
if (nvr->onesec_cnt >= 100)
|
||||
{
|
||||
if (!(nvrram[RTC_REGB] & RTC_SET))
|
||||
{
|
||||
nvr_update_status = RTC_UIP;
|
||||
rtc_tick();
|
||||
|
||||
timer_set_delay_u64(&nvr_update_end_timer, (uint64_t)((244.0 + 1984.0) * TIMER_USEC));
|
||||
timer_set_delay_u64(&nvr->update_end_timer, (uint64_t)((244.0 + 1984.0) * TIMER_USEC));
|
||||
}
|
||||
nvr_onesec_cnt = 0;
|
||||
nvr->onesec_cnt = 0;
|
||||
}
|
||||
timer_advance_u64(&nvr_onesec_timer, (uint64_t)(10000 * TIMER_USEC));
|
||||
timer_advance_u64(&nvr->onesec_timer, (uint64_t)(10000 * TIMER_USEC));
|
||||
}
|
||||
|
||||
void writenvr(uint16_t addr, uint8_t val, void *priv)
|
||||
static void writenvr(uint16_t addr, uint8_t val, void *p)
|
||||
{
|
||||
nvr_t *nvr = (nvr_t *)p;
|
||||
int c, old;
|
||||
|
||||
cycles -= ISA_CYCLES(8);
|
||||
|
|
@ -178,10 +195,10 @@ void writenvr(uint16_t addr, uint8_t val, void *priv)
|
|||
if (val & RTC_RS)
|
||||
{
|
||||
c = 1 << ((val & RTC_RS) - 1);
|
||||
timer_set_delay_u64(&rtc_timer, (uint64_t)(RTCCONST * c));
|
||||
timer_set_delay_u64(&nvr->rtc_timer, (uint64_t)(RTCCONST * c));
|
||||
}
|
||||
else
|
||||
timer_disable(&rtc_timer);
|
||||
timer_disable(&nvr->rtc_timer);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -227,8 +244,9 @@ void writenvr(uint16_t addr, uint8_t val, void *priv)
|
|||
}
|
||||
}
|
||||
|
||||
uint8_t readnvr(uint16_t addr, void *priv)
|
||||
uint8_t readnvr(uint16_t addr, void *p)
|
||||
{
|
||||
// nvr_t *nvr = (nvr_t *)p;
|
||||
uint8_t temp;
|
||||
// printf("Read NVR %03X %02X %02X %04X:%04X\n",addr,nvraddr,nvrram[nvraddr],cs>>4,pc);
|
||||
cycles -= ISA_CYCLES(8);
|
||||
|
|
@ -256,7 +274,7 @@ uint8_t readnvr(uint16_t addr, void *priv)
|
|||
void loadnvr()
|
||||
{
|
||||
FILE *f;
|
||||
int c;
|
||||
|
||||
nvrmask=63;
|
||||
oldromset=romset;
|
||||
switch (romset)
|
||||
|
|
@ -353,8 +371,6 @@ void loadnvr()
|
|||
fclose(f);
|
||||
nvrram[RTC_REGA] = 6;
|
||||
nvrram[RTC_REGB] = RTC_2412;
|
||||
c = 1 << ((nvrram[RTC_REGA] & RTC_RS) - 1);
|
||||
timer_set_delay_u64(&rtc_timer, (uint64_t)(RTCCONST * c));
|
||||
}
|
||||
void savenvr()
|
||||
{
|
||||
|
|
@ -436,11 +452,35 @@ void savenvr()
|
|||
fclose(f);
|
||||
}
|
||||
|
||||
void nvr_init()
|
||||
static void *nvr_init()
|
||||
{
|
||||
io_sethandler(0x0070, 0x0002, readnvr, NULL, NULL, writenvr, NULL, NULL, NULL);
|
||||
timer_add(&rtc_timer, nvr_rtc, NULL, 1);
|
||||
timer_add(&nvr_onesec_timer, nvr_onesec, NULL, 1);
|
||||
timer_add(&nvr_update_end_timer, nvr_update_end, NULL, 0);
|
||||
nvr_t *nvr = (nvr_t *)malloc(sizeof(nvr_t));
|
||||
memset(nvr, 0, sizeof(nvr_t));
|
||||
|
||||
io_sethandler(0x0070, 0x0002, readnvr, NULL, NULL, writenvr, NULL, NULL, nvr);
|
||||
timer_add(&nvr->rtc_timer, nvr_rtc, nvr, 1);
|
||||
timer_add(&nvr->onesec_timer, nvr_onesec, nvr, 1);
|
||||
timer_add(&nvr->update_end_timer, nvr_update_end, nvr, 0);
|
||||
|
||||
return nvr;
|
||||
}
|
||||
|
||||
static void nvr_close(void *p)
|
||||
{
|
||||
nvr_t *nvr = (nvr_t *)p;
|
||||
|
||||
free(nvr);
|
||||
}
|
||||
|
||||
device_t nvr_device =
|
||||
{
|
||||
"Motorola MC146818 RTC",
|
||||
0,
|
||||
nvr_init,
|
||||
nvr_close,
|
||||
NULL,
|
||||
nvr_speed_changed,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
void nvr_init();
|
||||
#include "device.h"
|
||||
|
||||
extern device_t nvr_device;
|
||||
|
||||
extern int enable_sync;
|
||||
|
||||
|
|
@ -7,8 +9,6 @@ extern int nvr_dosave;
|
|||
void loadnvr();
|
||||
void savenvr();
|
||||
|
||||
void nvr_recalc();
|
||||
|
||||
FILE *nvrfopen(char *fn, char *mode);
|
||||
|
||||
extern uint8_t nvrram[128];
|
||||
|
|
|
|||
2
src/pc.c
2
src/pc.c
|
|
@ -601,7 +601,6 @@ void fullspeed()
|
|||
// else setpitclock(clocks[AT?1:0][cpuspeed2][0]);
|
||||
}
|
||||
atfullspeed=1;
|
||||
nvr_recalc();
|
||||
}
|
||||
|
||||
void speedchanged()
|
||||
|
|
@ -610,7 +609,6 @@ void speedchanged()
|
|||
setpitclock(models[model].cpu[cpu_manufacturer].cpus[cpu].rspeed);
|
||||
else
|
||||
setpitclock(14318184.0);
|
||||
nvr_recalc();
|
||||
}
|
||||
|
||||
void closepc()
|
||||
|
|
|
|||
Loading…
Reference in a new issue