Removed some legacy NVRAM_HANDLERs in favor of NVRAM devices.

Added M48T37 variant to timekpr.c. Fixed some bugs that caused
registers to be initialized to 0xff and caused odd behavior.
Updated to modern device timers.

Converted vegas to use M48T37 instead of its own implementation.
This commit is contained in:
Aaron Giles 2011-03-10 09:55:04 +00:00
parent 88cf8e7896
commit a6b4399f9d
8 changed files with 103 additions and 136 deletions

View File

@ -187,6 +187,10 @@ void nvram_device::nvram_default()
case nvram_device_config::DEFAULT_CUSTOM: case nvram_device_config::DEFAULT_CUSTOM:
m_custom_handler(*this, m_base, m_length); m_custom_handler(*this, m_base, m_length);
break; break;
// none - do nothing
case nvram_device_config::DEFAULT_NONE:
break;
} }
} }

View File

@ -60,6 +60,10 @@
MCFG_DEVICE_ADD(_tag, NVRAM, 0) \ MCFG_DEVICE_ADD(_tag, NVRAM, 0) \
nvram_device_config::static_set_default_value(device, nvram_device_config::DEFAULT_RANDOM); \ nvram_device_config::static_set_default_value(device, nvram_device_config::DEFAULT_RANDOM); \
#define MCFG_NVRAM_ADD_NO_FILL(_tag) \
MCFG_DEVICE_ADD(_tag, NVRAM, 0) \
nvram_device_config::static_set_default_value(device, nvram_device_config::DEFAULT_NONE); \
#define MCFG_NVRAM_ADD_CUSTOM(_tag, _class, _method) \ #define MCFG_NVRAM_ADD_CUSTOM(_tag, _class, _method) \
MCFG_DEVICE_ADD(_tag, NVRAM, 0) \ MCFG_DEVICE_ADD(_tag, NVRAM, 0) \
nvram_device_config::static_set_custom_handler(device, nvram_init_proto_delegate::_create_member<_class, &_class::_method>(#_class "::" #_method)); \ nvram_device_config::static_set_custom_handler(device, nvram_init_proto_delegate::_create_member<_class, &_class::_method>(#_class "::" #_method)); \
@ -112,7 +116,8 @@ public:
DEFAULT_ALL_0, DEFAULT_ALL_0,
DEFAULT_ALL_1, DEFAULT_ALL_1,
DEFAULT_RANDOM, DEFAULT_RANDOM,
DEFAULT_CUSTOM DEFAULT_CUSTOM,
DEFAULT_NONE
}; };
// allocators // allocators

View File

@ -5,6 +5,7 @@
Various ST Microelectronics timekeeper SRAM implementations: Various ST Microelectronics timekeeper SRAM implementations:
- M48T02 - M48T02
- M48T35 - M48T35
- M48T37
- M48T58 - M48T58
- MK48T08 - MK48T08
@ -34,14 +35,16 @@
#define SECONDS_ST ( 0x80 ) #define SECONDS_ST ( 0x80 )
#define DAY_FT ( 0x40 ) /* not emulated */ #define DAY_FT ( 0x40 ) /* M48T37 - not emulated */
#define DAY_CEB ( 0x20 ) /* M48T35/M48T58 */ #define DAY_CEB ( 0x20 ) /* M48T35/M48T58 */
#define DAY_CB ( 0x10 ) /* M48T35/M48T58 */ #define DAY_CB ( 0x10 ) /* M48T35/M48T58 */
#define DATE_BLE ( 0x80 ) /* M48T58: not emulated */ #define DATE_BLE ( 0x80 ) /* M48T58: not emulated */
#define DATE_BL ( 0x40 ) /* M48T58: not emulated */ #define DATE_BL ( 0x40 ) /* M48T58: not emulated */
#define FLAGS_BL ( 0x10 ) /* MK48T08: not emulated */ #define FLAGS_BL ( 0x10 ) /* MK48T08/M48T37: not emulated */
#define FLAGS_AF ( 0x40 ) /* M48T37: not emulated */
#define FLAGS_WDF ( 0x80 ) /* M48T37: not emulated */
#define TIMEKPR_DEV_DERIVED_CTOR(devtype) \ #define TIMEKPR_DEV_DERIVED_CTOR(devtype) \
devtype##_device::devtype##_device(running_machine &_machine, const devtype##_device_config &config) \ devtype##_device::devtype##_device(running_machine &_machine, const devtype##_device_config &config) \
@ -164,11 +167,13 @@ static int counter_from_ram( UINT8 *data, int offset )
const device_type M48T02 = m48t02_device_config::static_alloc_device_config; const device_type M48T02 = m48t02_device_config::static_alloc_device_config;
const device_type M48T35 = m48t35_device_config::static_alloc_device_config; const device_type M48T35 = m48t35_device_config::static_alloc_device_config;
const device_type M48T37 = m48t37_device_config::static_alloc_device_config;
const device_type M48T58 = m48t58_device_config::static_alloc_device_config; const device_type M48T58 = m48t58_device_config::static_alloc_device_config;
const device_type MK48T08 = mk48t08_device_config::static_alloc_device_config; const device_type MK48T08 = mk48t08_device_config::static_alloc_device_config;
TIMEKPR_DERIVE(m48t02, "M48T02", "m48t02") TIMEKPR_DERIVE(m48t02, "M48T02", "m48t02")
TIMEKPR_DERIVE(m48t35, "M48T35", "m48t35") TIMEKPR_DERIVE(m48t35, "M48T35", "m48t35")
TIMEKPR_DERIVE(m48t37, "M48T37", "m48t37")
TIMEKPR_DERIVE(m48t58, "M48T58", "m48t58") TIMEKPR_DERIVE(m48t58, "M48T58", "m48t58")
TIMEKPR_DERIVE(mk48t08, "MK48T08", "mk48t08") TIMEKPR_DERIVE(mk48t08, "MK48T08", "mk48t08")
@ -190,8 +195,6 @@ timekeeper_device::timekeeper_device(running_machine &_machine, const timekeeper
void timekeeper_device::device_start() void timekeeper_device::device_start()
{ {
emu_timer *timer;
attotime duration;
system_time systime; system_time systime;
/* validate some basic stuff */ /* validate some basic stuff */
@ -227,9 +230,8 @@ void timekeeper_device::device_start()
save_item( NAME(m_century) ); save_item( NAME(m_century) );
save_pointer( NAME(m_data), m_size ); save_pointer( NAME(m_data), m_size );
timer = m_machine.scheduler().timer_alloc( FUNC(timekeeper_tick_callback), (void *)this ); emu_timer *timer = timer_alloc();
duration = attotime::from_seconds(1); timer->adjust(attotime::from_seconds(1), 0, attotime::from_seconds(1));
timer->adjust( duration, 0, duration );
} }
void m48t02_device::device_start() void m48t02_device::device_start()
@ -266,6 +268,23 @@ void m48t35_device::device_start()
timekeeper_device::device_start(); timekeeper_device::device_start();
} }
void m48t37_device::device_start()
{
m_offset_control = 0x7ff8;
m_offset_seconds = 0x7ff9;
m_offset_minutes = 0x7ffa;
m_offset_hours = 0x7ffb;
m_offset_day = 0x7ffc;
m_offset_date = 0x7ffd;
m_offset_month = 0x7ffe;
m_offset_year = 0x7fff;
m_offset_century = 0x7ff1;
m_offset_flags = 0x7ff0;
m_size = 0x8000;
timekeeper_device::device_start();
}
void m48t58_device::device_start() void m48t58_device::device_start()
{ {
m_offset_control = 0x1ff8; m_offset_control = 0x1ff8;
@ -307,6 +326,7 @@ void mk48t08_device::device_start()
void timekeeper_device::device_reset() { } void timekeeper_device::device_reset() { }
void m48t02_device::device_reset() { } void m48t02_device::device_reset() { }
void m48t35_device::device_reset() { } void m48t35_device::device_reset() { }
void m48t37_device::device_reset() { }
void m48t58_device::device_reset() { } void m48t58_device::device_reset() { }
void mk48t08_device::device_reset() { } void mk48t08_device::device_reset() { }
@ -336,12 +356,7 @@ void timekeeper_device::counters_from_ram()
m_century = counter_from_ram( m_data, m_offset_century ); m_century = counter_from_ram( m_data, m_offset_century );
} }
TIMER_CALLBACK( timekeeper_device::timekeeper_tick_callback ) void timekeeper_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
{
reinterpret_cast<timekeeper_device *>(ptr)->timekeeper_tick();
}
void timekeeper_device::timekeeper_tick()
{ {
if( ( m_seconds & SECONDS_ST ) != 0 || if( ( m_seconds & SECONDS_ST ) != 0 ||
( m_control & CONTROL_W ) != 0 ) ( m_control & CONTROL_W ) != 0 )
@ -431,21 +446,22 @@ void timekeeper_device::write(UINT16 offset, UINT8 data)
m_day = ( m_day & ~DAY_CEB ) | ( data & DAY_CEB ); m_day = ( m_day & ~DAY_CEB ) | ( data & DAY_CEB );
} }
} }
else if( offset == m_offset_date && type() == M48T58 )
{
data &= ~DATE_BL;
}
else if( offset == m_offset_flags && type() == MK48T08 )
{
data &= ~FLAGS_BL;
}
m_data[ offset ] = data; m_data[ offset ] = data;
} }
UINT8 timekeeper_device::read(UINT16 offset) UINT8 timekeeper_device::read(UINT16 offset)
{ {
return m_data[ offset ]; UINT8 result = m_data[ offset ];
if( offset == m_offset_date && type() == M48T58 )
{
result &= ~DATE_BL;
}
else if( offset == m_offset_flags && (type() == MK48T08 || type() == M48T37) )
{
result = 0;
}
return result;
} }
//------------------------------------------------- //-------------------------------------------------
@ -463,6 +479,10 @@ void timekeeper_device::nvram_default()
{ {
memset( m_data, 0xff, m_size ); memset( m_data, 0xff, m_size );
} }
if ( m_offset_flags >= 0 )
m_data[ m_offset_flags ] = 0;
counters_to_ram();
} }

View File

@ -5,6 +5,7 @@
Various ST Microelectronics timekeeper SRAM implementations: Various ST Microelectronics timekeeper SRAM implementations:
- M48T02 - M48T02
- M48T35 - M48T35
- M48T37
- M48T58 - M48T58
- MK48T08 - MK48T08
@ -30,6 +31,9 @@
#define MCFG_M48T35_ADD(_tag) \ #define MCFG_M48T35_ADD(_tag) \
MCFG_DEVICE_ADD(_tag, M48T35, 0) MCFG_DEVICE_ADD(_tag, M48T35, 0)
#define MCFG_M48T37_ADD(_tag) \
MCFG_DEVICE_ADD(_tag, M48T37, 0)
#define MCFG_M48T58_ADD(_tag) \ #define MCFG_M48T58_ADD(_tag) \
MCFG_DEVICE_ADD(_tag, M48T58, 0) MCFG_DEVICE_ADD(_tag, M48T58, 0)
@ -59,6 +63,7 @@ class timekeeper_device_config : public device_config,
friend class timekeeper_device; friend class timekeeper_device;
friend class m48t02_device_config; friend class m48t02_device_config;
friend class m48t35_device_config; friend class m48t35_device_config;
friend class m48t37_device_config;
friend class m48t58_device_config; friend class m48t58_device_config;
friend class mk48t08_device_config; friend class mk48t08_device_config;
@ -81,6 +86,7 @@ class timekeeper_device : public device_t,
friend class timekeeper_device_config; friend class timekeeper_device_config;
friend class m48t02_device; friend class m48t02_device;
friend class m48t35_device; friend class m48t35_device;
friend class m48t37_device;
friend class m48t58_device; friend class m48t58_device;
friend class mk48t08_device; friend class mk48t08_device;
@ -88,8 +94,6 @@ class timekeeper_device : public device_t,
timekeeper_device(running_machine &_machine, const timekeeper_device_config &config); timekeeper_device(running_machine &_machine, const timekeeper_device_config &config);
public: public:
void timekeeper_tick();
void write(UINT16 offset, UINT8 data); void write(UINT16 offset, UINT8 data);
UINT8 read(UINT16 offset); UINT8 read(UINT16 offset);
@ -97,6 +101,7 @@ protected:
// device-level overrides // device-level overrides
virtual void device_start(); virtual void device_start();
virtual void device_reset(); virtual void device_reset();
virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
// device_nvram_interface overrides // device_nvram_interface overrides
virtual void nvram_default(); virtual void nvram_default();
@ -106,8 +111,6 @@ protected:
// internal state // internal state
const timekeeper_device_config &m_config; const timekeeper_device_config &m_config;
static TIMER_CALLBACK( timekeeper_tick_callback );
private: private:
void counters_to_ram(); void counters_to_ram();
void counters_from_ram(); void counters_from_ram();
@ -140,12 +143,14 @@ private:
GENERIC_DEVICE_DERIVED_CONFIG(timekeeper, m48t02) GENERIC_DEVICE_DERIVED_CONFIG(timekeeper, m48t02)
GENERIC_DEVICE_DERIVED_CONFIG(timekeeper, m48t35) GENERIC_DEVICE_DERIVED_CONFIG(timekeeper, m48t35)
GENERIC_DEVICE_DERIVED_CONFIG(timekeeper, m48t37)
GENERIC_DEVICE_DERIVED_CONFIG(timekeeper, m48t58) GENERIC_DEVICE_DERIVED_CONFIG(timekeeper, m48t58)
GENERIC_DEVICE_DERIVED_CONFIG(timekeeper, mk48t08) GENERIC_DEVICE_DERIVED_CONFIG(timekeeper, mk48t08)
// device type definition // device type definition
extern const device_type M48T02; extern const device_type M48T02;
extern const device_type M48T35; extern const device_type M48T35;
extern const device_type M48T37;
extern const device_type M48T58; extern const device_type M48T58;
extern const device_type MK48T08; extern const device_type MK48T08;

View File

@ -22,6 +22,7 @@ Notes:
#include "emu.h" #include "emu.h"
#include "cpu/z80/z80.h" #include "cpu/z80/z80.h"
#include "machine/z80ctc.h" #include "machine/z80ctc.h"
#include "machine/nvram.h"
#include "includes/nb1413m3.h" // needed for mahjong input controller #include "includes/nb1413m3.h" // needed for mahjong input controller
#include "sound/3812intf.h" #include "sound/3812intf.h"
#include "sound/dac.h" #include "sound/dac.h"
@ -37,19 +38,6 @@ Notes:
#endif #endif
static NVRAM_HANDLER( nbmj9195 )
{
nbmj9195_state *state = machine->driver_data<nbmj9195_state>();
if (read_or_write)
file->write(state->nvram, state->nvram_size);
else {
if (file)
file->read(state->nvram, state->nvram_size);
else
memset(state->nvram, 0, state->nvram_size);
}
}
static WRITE8_HANDLER( nbmj9195_soundbank_w ) static WRITE8_HANDLER( nbmj9195_soundbank_w )
{ {
UINT8 *SNDROM = space->machine->region("audiocpu")->base(); UINT8 *SNDROM = space->machine->region("audiocpu")->base();
@ -721,7 +709,7 @@ ADDRESS_MAP_END
static ADDRESS_MAP_START( sailorws_map, ADDRESS_SPACE_PROGRAM, 8 ) static ADDRESS_MAP_START( sailorws_map, ADDRESS_SPACE_PROGRAM, 8 )
AM_RANGE(0x0000, 0xefff) AM_ROM AM_RANGE(0x0000, 0xefff) AM_ROM
AM_RANGE(0xf000, 0xf1ff) AM_READWRITE(nbmj9195_palette_r,nbmj9195_palette_w) AM_RANGE(0xf000, 0xf1ff) AM_READWRITE(nbmj9195_palette_r,nbmj9195_palette_w)
AM_RANGE(0xf800, 0xffff) AM_RAM AM_BASE_MEMBER(nbmj9195_state, nvram) AM_SIZE_MEMBER(nbmj9195_state, nvram_size) AM_RANGE(0xf800, 0xffff) AM_RAM AM_SHARE("nvram")
ADDRESS_MAP_END ADDRESS_MAP_END
static ADDRESS_MAP_START( mjuraden_map, ADDRESS_SPACE_PROGRAM, 8 ) static ADDRESS_MAP_START( mjuraden_map, ADDRESS_SPACE_PROGRAM, 8 )
@ -733,7 +721,7 @@ ADDRESS_MAP_END
static ADDRESS_MAP_START( koinomp_map, ADDRESS_SPACE_PROGRAM, 8 ) static ADDRESS_MAP_START( koinomp_map, ADDRESS_SPACE_PROGRAM, 8 )
AM_RANGE(0x0000, 0xdfff) AM_ROM AM_RANGE(0x0000, 0xdfff) AM_ROM
AM_RANGE(0xe000, 0xe1ff) AM_READWRITE(nbmj9195_palette_r,nbmj9195_palette_w) AM_RANGE(0xe000, 0xe1ff) AM_READWRITE(nbmj9195_palette_r,nbmj9195_palette_w)
AM_RANGE(0xe800, 0xefff) AM_RAM AM_BASE_MEMBER(nbmj9195_state, nvram) AM_SIZE_MEMBER(nbmj9195_state, nvram_size) AM_RANGE(0xe800, 0xefff) AM_RAM AM_SHARE("nvram")
ADDRESS_MAP_END ADDRESS_MAP_END
static ADDRESS_MAP_START( ngpgal_map, ADDRESS_SPACE_PROGRAM, 8 ) static ADDRESS_MAP_START( ngpgal_map, ADDRESS_SPACE_PROGRAM, 8 )
@ -3199,7 +3187,7 @@ static MACHINE_CONFIG_DERIVED( janbari, NBMJDRV1 )
MCFG_CPU_MODIFY("maincpu") MCFG_CPU_MODIFY("maincpu")
MCFG_CPU_IO_MAP(patimono_io_map) MCFG_CPU_IO_MAP(patimono_io_map)
MCFG_NVRAM_HANDLER(nbmj9195) MCFG_NVRAM_ADD_0FILL("nvram")
MACHINE_CONFIG_END MACHINE_CONFIG_END
@ -3210,7 +3198,7 @@ static MACHINE_CONFIG_DERIVED( mmehyou, NBMJDRV1 )
MCFG_CPU_PROGRAM_MAP(koinomp_map) MCFG_CPU_PROGRAM_MAP(koinomp_map)
MCFG_CPU_IO_MAP(mmehyou_io_map) MCFG_CPU_IO_MAP(mmehyou_io_map)
MCFG_NVRAM_HANDLER(nbmj9195) MCFG_NVRAM_ADD_0FILL("nvram")
MACHINE_CONFIG_END MACHINE_CONFIG_END
@ -3221,7 +3209,7 @@ static MACHINE_CONFIG_DERIVED( ultramhm, NBMJDRV1 )
MCFG_CPU_PROGRAM_MAP(koinomp_map) MCFG_CPU_PROGRAM_MAP(koinomp_map)
MCFG_CPU_IO_MAP(koinomp_io_map) MCFG_CPU_IO_MAP(koinomp_io_map)
MCFG_NVRAM_HANDLER(nbmj9195) MCFG_NVRAM_ADD_0FILL("nvram")
MACHINE_CONFIG_END MACHINE_CONFIG_END
@ -3263,7 +3251,7 @@ static MACHINE_CONFIG_DERIVED( pachiten, NBMJDRV1 )
MCFG_CPU_MODIFY("maincpu") MCFG_CPU_MODIFY("maincpu")
MCFG_CPU_IO_MAP(pachiten_io_map) MCFG_CPU_IO_MAP(pachiten_io_map)
MCFG_NVRAM_HANDLER(nbmj9195) MCFG_NVRAM_ADD_0FILL("nvram")
MACHINE_CONFIG_END MACHINE_CONFIG_END
@ -3279,7 +3267,7 @@ static MACHINE_CONFIG_DERIVED( sailorwr, NBMJDRV1 )
MCFG_CPU_MODIFY("maincpu") MCFG_CPU_MODIFY("maincpu")
MCFG_CPU_IO_MAP(sailorwr_io_map) MCFG_CPU_IO_MAP(sailorwr_io_map)
MCFG_NVRAM_HANDLER(nbmj9195) MCFG_NVRAM_ADD_0FILL("nvram")
MACHINE_CONFIG_END MACHINE_CONFIG_END

View File

@ -194,6 +194,7 @@ NOTE: On CTRG2-B, The "A" lines start at "A1". If you trace this on an
#include "emu.h" #include "emu.h"
#include "cpu/m68000/m68000.h" #include "cpu/m68000/m68000.h"
#include "includes/neogeo.h" #include "includes/neogeo.h"
#include "machine/nvram.h"
#include "machine/pd4990a.h" #include "machine/pd4990a.h"
#include "cpu/z80/z80.h" #include "cpu/z80/z80.h"
#include "sound/2610intf.h" #include "sound/2610intf.h"
@ -536,22 +537,6 @@ static CUSTOM_INPUT( get_calendar_status )
* *
*************************************/ *************************************/
static NVRAM_HANDLER( neogeo )
{
if (read_or_write)
/* save the SRAM settings */
file->write(save_ram, 0x2000);
else
{
/* load the SRAM settings */
if (file)
file->read(save_ram, 0x2000);
else
memset(save_ram, 0, 0x10000);
}
}
static void set_save_ram_unlock( running_machine *machine, UINT8 data ) static void set_save_ram_unlock( running_machine *machine, UINT8 data )
{ {
neogeo_state *state = machine->driver_data<neogeo_state>(); neogeo_state *state = machine->driver_data<neogeo_state>();
@ -1058,6 +1043,9 @@ static MACHINE_START( neogeo )
{ {
neogeo_state *state = machine->driver_data<neogeo_state>(); neogeo_state *state = machine->driver_data<neogeo_state>();
/* configure NVRAM */
machine->device<nvram_device>("saveram")->set_base(save_ram, 0x2000);
/* set the BIOS bank */ /* set the BIOS bank */
memory_set_bankptr(machine, NEOGEO_BANK_BIOS, machine->region("mainbios")->base()); memory_set_bankptr(machine, NEOGEO_BANK_BIOS, machine->region("mainbios")->base());
@ -1355,7 +1343,7 @@ static MACHINE_CONFIG_START( neogeo, neogeo_state )
MCFG_MACHINE_START(neogeo) MCFG_MACHINE_START(neogeo)
MCFG_MACHINE_RESET(neogeo) MCFG_MACHINE_RESET(neogeo)
MCFG_NVRAM_HANDLER(neogeo) MCFG_NVRAM_ADD_0FILL("saveram")
MCFG_MEMCARD_HANDLER(neogeo) MCFG_MEMCARD_HANDLER(neogeo)
/* video hardware */ /* video hardware */

View File

@ -337,6 +337,7 @@ Notes:
#include "sound/ym2151.h" #include "sound/ym2151.h"
#include "sound/dac.h" #include "sound/dac.h"
#include "sound/2151intf.h" #include "sound/2151intf.h"
#include "machine/nvram.h"
#include "video/segaic24.h" #include "video/segaic24.h"
#include "includes/segas24.h" #include "includes/segas24.h"
@ -1066,18 +1067,11 @@ ADDRESS_MAP_END
* *
*************************************/ *************************************/
static NVRAM_HANDLER(system24)
{
if(!track_size || !file)
return;
if(read_or_write)
file->write(machine->region("floppy")->base(), 2*track_size);
else
file->read(machine->region("floppy")->base(), 2*track_size);
}
static MACHINE_START( system24 ) static MACHINE_START( system24 )
{ {
if (track_size)
machine->device<nvram_device>("floppy_nvram")->set_base(machine->region("floppy")->base(), 2*track_size);
UINT8 *usr1 = machine->region("romboard")->base(); UINT8 *usr1 = machine->region("romboard")->base();
if (usr1) if (usr1)
{ {
@ -1813,7 +1807,7 @@ static MACHINE_CONFIG_START( system24, driver_device )
MACHINE_CONFIG_END MACHINE_CONFIG_END
static MACHINE_CONFIG_DERIVED( system24_floppy, system24 ) static MACHINE_CONFIG_DERIVED( system24_floppy, system24 )
MCFG_NVRAM_HANDLER(system24) MCFG_NVRAM_ADD_NO_FILL("floppy_nvram")
MACHINE_CONFIG_END MACHINE_CONFIG_END

View File

@ -276,6 +276,7 @@
#include "cpu/adsp2100/adsp2100.h" #include "cpu/adsp2100/adsp2100.h"
#include "cpu/mips/mips3.h" #include "cpu/mips/mips3.h"
#include "audio/dcs.h" #include "audio/dcs.h"
#include "machine/timekpr.h"
#include "machine/idectrl.h" #include "machine/idectrl.h"
#include "machine/midwayic.h" #include "machine/midwayic.h"
#include "machine/smc91c9x.h" #include "machine/smc91c9x.h"
@ -458,8 +459,10 @@ class vegas_state : public driver_device
{ {
public: public:
vegas_state(running_machine &machine, const driver_device_config_base &config) vegas_state(running_machine &machine, const driver_device_config_base &config)
: driver_device(machine, config) { } : driver_device(machine, config),
timekeeper(*this, "timekeeper") { }
required_device<m48t37_device> timekeeper;
UINT32 *rambase; UINT32 *rambase;
UINT32 *rombase; UINT32 *rombase;
size_t ramsize; size_t ramsize;
@ -478,8 +481,6 @@ public:
UINT8 sio_led_state; UINT8 sio_led_state;
UINT8 pending_analog_read; UINT8 pending_analog_read;
UINT8 cmos_unlocked; UINT8 cmos_unlocked;
UINT32 *timekeeper_nvram;
size_t timekeeper_nvram_size;
device_t *voodoo; device_t *voodoo;
UINT8 dcs_idma_cs; UINT8 dcs_idma_cs;
int count; int count;
@ -611,7 +612,14 @@ static WRITE32_HANDLER( timekeeper_w )
vegas_state *state = space->machine->driver_data<vegas_state>(); vegas_state *state = space->machine->driver_data<vegas_state>();
if (state->cmos_unlocked) if (state->cmos_unlocked)
{ {
COMBINE_DATA(&state->timekeeper_nvram[offset]); if ((mem_mask & 0x000000ff) != 0)
state->timekeeper->write(offset * 4 + 0, data >> 0);
if ((mem_mask & 0x0000ff00) != 0)
state->timekeeper->write(offset * 4 + 1, data >> 8);
if ((mem_mask & 0x00ff0000) != 0)
state->timekeeper->write(offset * 4 + 2, data >> 16);
if ((mem_mask & 0xff000000) != 0)
state->timekeeper->write(offset * 4 + 3, data >> 24);
if (offset*4 >= 0x7ff0) if (offset*4 >= 0x7ff0)
if (LOG_TIMEKEEPER) logerror("timekeeper_w(%04X & %08X) = %08X\n", offset*4, mem_mask, data); if (LOG_TIMEKEEPER) logerror("timekeeper_w(%04X & %08X) = %08X\n", offset*4, mem_mask, data);
state->cmos_unlocked = 0; state->cmos_unlocked = 0;
@ -621,64 +629,24 @@ static WRITE32_HANDLER( timekeeper_w )
} }
INLINE UINT8 make_bcd(UINT8 data)
{
return ((data / 10) << 4) | (data % 10);
}
static READ32_HANDLER( timekeeper_r ) static READ32_HANDLER( timekeeper_r )
{ {
vegas_state *state = space->machine->driver_data<vegas_state>(); vegas_state *state = space->machine->driver_data<vegas_state>();
UINT32 result = state->timekeeper_nvram[offset]; UINT32 result = 0xffffffff;
if ((mem_mask & 0x000000ff) != 0)
/* upper bytes are a realtime clock */ result = (result & ~0x000000ff) | (state->timekeeper->read(offset * 4 + 0) << 0);
if ((offset*4) >= 0x7ff0) if ((mem_mask & 0x0000ff00) != 0)
{ result = (result & ~0x0000ff00) | (state->timekeeper->read(offset * 4 + 1) << 8);
/* get the time */ if ((mem_mask & 0x00ff0000) != 0)
system_time systime; result = (result & ~0x00ff0000) | (state->timekeeper->read(offset * 4 + 2) << 16);
space->machine->base_datetime(systime); if ((mem_mask & 0xff000000) != 0)
result = (result & ~0xff000000) | (state->timekeeper->read(offset * 4 + 3) << 24);
/* return portions thereof */ if (offset*4 >= 0x7ff0)
switch (offset*4) if (LOG_TIMEKEEPER) logerror("timekeeper_r(%04X & %08X) = %08X\n", offset*4, mem_mask, result);
{
case 0x7ff0:
result &= 0x00ff0000;
result |= (make_bcd(systime.local_time.year) / 100) << 8;
break;
case 0x7ff4:
break;
case 0x7ff8:
result &= 0x000000ff;
result |= make_bcd(systime.local_time.second) << 8;
result |= make_bcd(systime.local_time.minute) << 16;
result |= make_bcd(systime.local_time.hour) << 24;
break;
case 0x7ffc:
result = systime.local_time.weekday + 1;
result |= 0x40; /* frequency test */
result |= make_bcd(systime.local_time.mday) << 8;
result |= make_bcd(systime.local_time.month + 1) << 16;
result |= make_bcd(systime.local_time.year % 100) << 24;
break;
}
}
return result; return result;
} }
static NVRAM_HANDLER( timekeeper_save )
{
vegas_state *state = machine->driver_data<vegas_state>();
if (read_or_write)
file->write(state->timekeeper_nvram, state->timekeeper_nvram_size);
else if (file)
file->read(state->timekeeper_nvram, state->timekeeper_nvram_size);
else
memset(state->timekeeper_nvram, 0xff, state->timekeeper_nvram_size);
}
/************************************* /*************************************
* *
@ -2260,7 +2228,7 @@ static MACHINE_CONFIG_START( vegascore, vegas_state )
MCFG_MACHINE_START(vegas) MCFG_MACHINE_START(vegas)
MCFG_MACHINE_RESET(vegas) MCFG_MACHINE_RESET(vegas)
MCFG_NVRAM_HANDLER(timekeeper_save) MCFG_M48T37_ADD("timekeeper")
MCFG_IDE_CONTROLLER_ADD("ide", ide_interrupt) MCFG_IDE_CONTROLLER_ADD("ide", ide_interrupt)
MCFG_IDE_BUS_MASTER_SPACE("maincpu", PROGRAM) MCFG_IDE_BUS_MASTER_SPACE("maincpu", PROGRAM)
@ -2504,14 +2472,9 @@ ROM_END
static void init_common(running_machine *machine, int ioasic, int serialnum) static void init_common(running_machine *machine, int ioasic, int serialnum)
{ {
vegas_state *state = machine->driver_data<vegas_state>();
/* initialize the subsystems */ /* initialize the subsystems */
midway_ioasic_init(machine, ioasic, serialnum, 80, ioasic_irq); midway_ioasic_init(machine, ioasic, serialnum, 80, ioasic_irq);
midway_ioasic_set_auto_ack(1); midway_ioasic_set_auto_ack(1);
/* allocate RAM for the timekeeper */
state->timekeeper_nvram_size = 0x8000;
state->timekeeper_nvram = auto_alloc_array(machine, UINT32, state->timekeeper_nvram_size/4);
} }