trunk/src/emu/machine/upd4992.c
| r0 | r26549 | |
| 1 | // license: MAME |
| 2 | // copyright-holders: Angelo Salese |
| 3 | /*************************************************************************** |
| 4 | |
| 5 | uPD4992 parallel RTC |
| 6 | |
| 7 | TODO: |
| 8 | - Add timers |
| 9 | - Add leap year count |
| 10 | - Add 12 hours mode |
| 11 | - Add mode/control register |
| 12 | |
| 13 | ***************************************************************************/ |
| 14 | |
| 15 | #include "emu.h" |
| 16 | #include "machine/upd4992.h" |
| 17 | |
| 18 | |
| 19 | |
| 20 | //************************************************************************** |
| 21 | // GLOBAL VARIABLES |
| 22 | //************************************************************************** |
| 23 | |
| 24 | // device type definition |
| 25 | const device_type UPD4992 = &device_creator<upd4992_device>; |
| 26 | |
| 27 | |
| 28 | //************************************************************************** |
| 29 | // LIVE DEVICE |
| 30 | //************************************************************************** |
| 31 | |
| 32 | //------------------------------------------------- |
| 33 | // upd4992_device - constructor |
| 34 | //------------------------------------------------- |
| 35 | |
| 36 | upd4992_device::upd4992_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 37 | : device_t(mconfig, UPD4992, "uPD4992", tag, owner, clock, "upd4992", __FILE__), |
| 38 | device_rtc_interface(mconfig, *this) |
| 39 | { |
| 40 | } |
| 41 | |
| 42 | |
| 43 | //------------------------------------------------- |
| 44 | // device_validity_check - perform validity checks |
| 45 | // on this device |
| 46 | //------------------------------------------------- |
| 47 | |
| 48 | void upd4992_device::device_validity_check(validity_checker &valid) const |
| 49 | { |
| 50 | } |
| 51 | |
| 52 | |
| 53 | //------------------------------------------------- |
| 54 | // device_start - device-specific startup |
| 55 | //------------------------------------------------- |
| 56 | |
| 57 | void upd4992_device::device_start() |
| 58 | { |
| 59 | m_timer_clock = timer_alloc(TIMER_CLOCK); |
| 60 | m_timer_clock->adjust(attotime::from_hz(clock() / 32768), 0, attotime::from_hz(clock() / 32768)); |
| 61 | } |
| 62 | |
| 63 | |
| 64 | //------------------------------------------------- |
| 65 | // device_reset - device-specific reset |
| 66 | //------------------------------------------------- |
| 67 | |
| 68 | void upd4992_device::device_reset() |
| 69 | { |
| 70 | set_current_time(machine()); |
| 71 | } |
| 72 | |
| 73 | |
| 74 | void upd4992_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 75 | { |
| 76 | switch (id) |
| 77 | { |
| 78 | case TIMER_CLOCK: |
| 79 | advance_seconds(); |
| 80 | break; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | //------------------------------------------------- |
| 85 | // rtc_clock_updated - |
| 86 | //------------------------------------------------- |
| 87 | |
| 88 | void upd4992_device::rtc_clock_updated(int year, int month, int day, int day_of_week, int hour, int minute, int second) |
| 89 | { |
| 90 | /* |
| 91 | [2] |
| 92 | x--- ---- 12/24H flag |
| 93 | -x-- ---- AM/PM flag |
| 94 | --xx ---- 10 hour digit |
| 95 | ---- xxxx 1s hour digit |
| 96 | [3] |
| 97 | xx-- ---- Leap year control |
| 98 | --xx ---- Leap year counter |
| 99 | ---- xxxx Day of week digit |
| 100 | [4] |
| 101 | xxxx ---- 10s day digit |
| 102 | ---- xxxx 1s day digit |
| 103 | [5] |
| 104 | xxxx ---- 10s month digit |
| 105 | ---- xxxx 1s month digit |
| 106 | [6] |
| 107 | xxxx ---- 10s year digit |
| 108 | ---- xxxx 1s year digit |
| 109 | [7] |
| 110 | xxxx ---- Mode register |
| 111 | ---- xxxx Control Register |
| 112 | */ |
| 113 | m_rtc_regs[0] = convert_to_bcd(second); |
| 114 | m_rtc_regs[1] = convert_to_bcd(minute); |
| 115 | m_rtc_regs[2] = convert_to_bcd(hour); |
| 116 | m_rtc_regs[3] = day_of_week-1; |
| 117 | m_rtc_regs[4] = convert_to_bcd(day); |
| 118 | m_rtc_regs[5] = convert_to_bcd(month); |
| 119 | m_rtc_regs[6] = convert_to_bcd(year); |
| 120 | } |
| 121 | |
| 122 | //************************************************************************** |
| 123 | // READ/WRITE HANDLERS |
| 124 | //************************************************************************** |
| 125 | |
| 126 | READ8_MEMBER( upd4992_device::read ) |
| 127 | { |
| 128 | return m_rtc_regs[offset]; |
| 129 | } |
| 130 | |
| 131 | WRITE8_MEMBER( upd4992_device::write ) |
| 132 | { |
| 133 | if(offset == 7) |
| 134 | { |
| 135 | if(data & 8) |
| 136 | { |
| 137 | if(data & 2) // reset |
| 138 | { |
| 139 | // ... |
| 140 | } |
| 141 | |
| 142 | m_timer_clock->enable(data & 1); |
| 143 | } |
| 144 | } |
| 145 | else // TODO: perhaps there's a write inhibit? |
| 146 | { |
| 147 | m_rtc_regs[offset] = data; |
| 148 | set_time(1, bcd_to_integer(m_rtc_regs[6]), |
| 149 | bcd_to_integer(m_rtc_regs[5]), |
| 150 | bcd_to_integer(m_rtc_regs[4]), |
| 151 | m_rtc_regs[3]+1, |
| 152 | bcd_to_integer(m_rtc_regs[2]), |
| 153 | bcd_to_integer(m_rtc_regs[1]), |
| 154 | bcd_to_integer(m_rtc_regs[0])); |
| 155 | } |
| 156 | } |
trunk/src/emu/machine/upd4992.h
| r0 | r26549 | |
| 1 | // license: ? |
| 2 | // copyright-holders: Angelo Salese |
| 3 | /*************************************************************************** |
| 4 | |
| 5 | uPD4992 RTC |
| 6 | |
| 7 | ***************************************************************************/ |
| 8 | |
| 9 | #pragma once |
| 10 | |
| 11 | #ifndef __UPD4992DEV_H__ |
| 12 | #define __UPD4992DEV_H__ |
| 13 | |
| 14 | |
| 15 | |
| 16 | //************************************************************************** |
| 17 | // INTERFACE CONFIGURATION MACROS |
| 18 | //************************************************************************** |
| 19 | |
| 20 | #define MCFG_UPD4992_ADD(_tag) \ |
| 21 | MCFG_DEVICE_ADD(_tag, UPD4992, XTAL_32_768kHz) |
| 22 | |
| 23 | //************************************************************************** |
| 24 | // TYPE DEFINITIONS |
| 25 | //************************************************************************** |
| 26 | |
| 27 | // ======================> upd4992_device |
| 28 | |
| 29 | class upd4992_device : public device_t, |
| 30 | public device_rtc_interface |
| 31 | { |
| 32 | public: |
| 33 | // construction/destruction |
| 34 | upd4992_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 35 | |
| 36 | // I/O operations |
| 37 | DECLARE_WRITE8_MEMBER( write ); |
| 38 | DECLARE_READ8_MEMBER( read ); |
| 39 | |
| 40 | protected: |
| 41 | // device-level overrides |
| 42 | virtual void device_validity_check(validity_checker &valid) const; |
| 43 | virtual void device_start(); |
| 44 | virtual void device_reset(); |
| 45 | virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr); |
| 46 | virtual void rtc_clock_updated(int year, int month, int day, int day_of_week, int hour, int minute, int second); |
| 47 | |
| 48 | private: |
| 49 | enum |
| 50 | { |
| 51 | TIMER_CLOCK |
| 52 | //TIMER_TP, |
| 53 | //TIMER_DATA_OUT, |
| 54 | //TIMER_TEST_MODE |
| 55 | }; |
| 56 | |
| 57 | emu_timer *m_timer_clock; |
| 58 | UINT8 m_rtc_regs[8]; |
| 59 | }; |
| 60 | |
| 61 | |
| 62 | // device type definition |
| 63 | extern const device_type UPD4992; |
| 64 | |
| 65 | |
| 66 | |
| 67 | //************************************************************************** |
| 68 | // GLOBAL VARIABLES |
| 69 | //************************************************************************** |
| 70 | |
| 71 | |
| 72 | |
| 73 | #endif |
trunk/src/mame/drivers/toaplan2.c
| r26548 | r26549 | |
| 356 | 356 | #include "cpu/z80/z80.h" |
| 357 | 357 | #include "cpu/z180/z180.h" |
| 358 | 358 | #include "machine/eepromser.h" |
| 359 | #include "machine/upd4992.h" |
| 359 | 360 | #include "sound/2151intf.h" |
| 360 | 361 | #include "sound/3812intf.h" |
| 361 | 362 | #include "sound/okim6295.h" |
| r26548 | r26549 | |
| 1207 | 1208 | AM_RANGE(0x700000, 0x700001) AM_READ(video_count_r) |
| 1208 | 1209 | ADDRESS_MAP_END |
| 1209 | 1210 | |
| 1210 | | /* TODO: write in a proper core */ |
| 1211 | | WRITE8_MEMBER(toaplan2_state::upd4992_calendar_w) |
| 1212 | | { |
| 1213 | | } |
| 1214 | | |
| 1215 | | READ8_MEMBER(toaplan2_state::upd4992_calendar_r) |
| 1216 | | { |
| 1217 | | system_time systime; |
| 1218 | | |
| 1219 | | machine().base_datetime(systime); |
| 1220 | | |
| 1221 | | switch (offset) |
| 1222 | | { |
| 1223 | | case 0: |
| 1224 | | return ((systime.local_time.second/10)<<4) + (systime.local_time.second%10); |
| 1225 | | case 1: |
| 1226 | | return ((systime.local_time.minute/10)<<4) + (systime.local_time.minute%10); |
| 1227 | | case 2: |
| 1228 | | return ((systime.local_time.hour/10)<<4) + (systime.local_time.hour%10); |
| 1229 | | case 3: |
| 1230 | | return systime.local_time.weekday; |
| 1231 | | case 4: |
| 1232 | | return ((systime.local_time.mday/10)<<4) + (systime.local_time.mday%10); |
| 1233 | | case 5: |
| 1234 | | return (systime.local_time.month + 1); |
| 1235 | | case 6: |
| 1236 | | return (((systime.local_time.year%100)/10)<<4) + (systime.local_time.year%10); |
| 1237 | | case 7: |
| 1238 | | default: |
| 1239 | | return 0; /* status? the other registers are read only when bit 0 is clear */ |
| 1240 | | } |
| 1241 | | } |
| 1242 | | |
| 1243 | 1211 | static ADDRESS_MAP_START( pwrkick_68k_mem, AS_PROGRAM, 16, toaplan2_state ) |
| 1244 | 1212 | AM_RANGE(0x000000, 0x07ffff) AM_ROM |
| 1245 | 1213 | AM_RANGE(0x100000, 0x10ffff) AM_RAM |
| 1246 | | AM_RANGE(0x200000, 0x20000f) AM_READWRITE8(upd4992_calendar_r,upd4992_calendar_w,0x00ff) |
| 1214 | |
| 1215 | AM_RANGE(0x200000, 0x20000f) AM_DEVREADWRITE8("rtc", upd4992_device, read, write, 0x00ff ) |
| 1247 | 1216 | AM_RANGE(0x300000, 0x30000d) AM_DEVREADWRITE("gp9001vdp0", gp9001vdp_device, gp9001_vdp_r, gp9001_vdp_w) |
| 1248 | 1217 | AM_RANGE(0x400000, 0x400fff) AM_RAM_WRITE(paletteram_xBBBBBGGGGGRRRRR_word_w) AM_SHARE("paletteram") |
| 1249 | 1218 | AM_RANGE(0x600000, 0x600001) AM_DEVREADWRITE8("oki", okim6295_device, read, write, 0x00ff) |
| r26548 | r26549 | |
| 1263 | 1232 | static ADDRESS_MAP_START( othldrby_68k_mem, AS_PROGRAM, 16, toaplan2_state ) |
| 1264 | 1233 | AM_RANGE(0x000000, 0x07ffff) AM_ROM |
| 1265 | 1234 | AM_RANGE(0x100000, 0x10ffff) AM_RAM |
| 1266 | | AM_RANGE(0x200000, 0x20000f) AM_READWRITE8(upd4992_calendar_r,upd4992_calendar_w,0x00ff) |
| 1235 | |
| 1236 | AM_RANGE(0x200000, 0x20000f) AM_DEVREADWRITE8("rtc", upd4992_device, read, write, 0x00ff ) |
| 1267 | 1237 | AM_RANGE(0x300000, 0x30000d) AM_DEVREADWRITE("gp9001vdp0", gp9001vdp_device, gp9001_vdp_r, gp9001_vdp_w) |
| 1268 | 1238 | AM_RANGE(0x400000, 0x400fff) AM_RAM_WRITE(paletteram_xBBBBBGGGGGRRRRR_word_w) AM_SHARE("paletteram") |
| 1269 | 1239 | AM_RANGE(0x600000, 0x600001) AM_DEVREADWRITE8("oki", okim6295_device, read, write, 0x00ff) |
| r26548 | r26549 | |
| 3737 | 3707 | MCFG_CPU_VBLANK_INT_DRIVER("screen", toaplan2_state, toaplan2_vblank_irq4) |
| 3738 | 3708 | |
| 3739 | 3709 | MCFG_MACHINE_START_OVERRIDE(toaplan2_state,toaplan2) |
| 3710 | MCFG_UPD4992_ADD("rtc") |
| 3740 | 3711 | |
| 3741 | 3712 | /* video hardware */ |
| 3742 | 3713 | MCFG_VIDEO_ATTRIBUTES(VIDEO_UPDATE_BEFORE_VBLANK) |
| r26548 | r26549 | |
| 3767 | 3738 | MCFG_CPU_VBLANK_INT_DRIVER("screen", toaplan2_state, toaplan2_vblank_irq4) |
| 3768 | 3739 | |
| 3769 | 3740 | MCFG_MACHINE_START_OVERRIDE(toaplan2_state,toaplan2) |
| 3741 | MCFG_UPD4992_ADD("rtc") |
| 3770 | 3742 | |
| 3771 | 3743 | /* video hardware */ |
| 3772 | 3744 | MCFG_VIDEO_ATTRIBUTES(VIDEO_UPDATE_BEFORE_VBLANK) |
trunk/src/mame/includes/toaplan2.h
| r26548 | r26549 | |
| 35 | 35 | m_nmk112(*this, "nmk112"), |
| 36 | 36 | m_oki(*this, "oki"), |
| 37 | 37 | m_oki1(*this, "oki1"), |
| 38 | | m_eeprom(*this, "eeprom") { |
| 38 | m_eeprom(*this, "eeprom"), |
| 39 | m_rtc(*this, "rtc") { |
| 39 | 40 | m_vdp0 = NULL; |
| 40 | 41 | m_vdp1 = NULL; |
| 41 | 42 | } |
| r26548 | r26549 | |
| 155 | 156 | optional_device<okim6295_device> m_oki; |
| 156 | 157 | optional_device<okim6295_device> m_oki1; |
| 157 | 158 | optional_device<eeprom_serial_93cxx_device> m_eeprom; |
| 159 | optional_device<upd4992_device> m_rtc; |
| 158 | 160 | |
| 159 | 161 | UINT8 m_pwrkick_hopper; |
| 160 | 162 | DECLARE_CUSTOM_INPUT_MEMBER(pwrkick_hopper_status_r); |
| 161 | 163 | DECLARE_WRITE8_MEMBER(pwrkick_coin_w); |
| 162 | | DECLARE_READ8_MEMBER(upd4992_calendar_r); |
| 163 | | DECLARE_WRITE8_MEMBER(upd4992_calendar_w); |
| 164 | 164 | |
| 165 | 165 | protected: |
| 166 | 166 | virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr); |