Previous 199869 Revisions Next

r19427 Sunday 9th December, 2012 at 15:22:09 UTC by Nathan Woods
[MSM6242] Cleanups and basic modernizations in preparation for other work (nw)
[src/emu/machine]msm6242.c msm6242.h

trunk/src/emu/machine/msm6242.c
r19426r19427
33    MSM6242 / Epson RTC 62421 / 62423 Real Time Clock
44
55    TODO:
6    - Stop timer callbacks on every single tick
67    - HOLD mechanism
78    - IRQs are grossly mapped
89    - STOP / RESET mechanism
r19426r19427
1415#include "machine/msm6242.h"
1516
1617
18//**************************************************************************
19//  CONSTANTS
20//**************************************************************************
21
1722enum
1823{
1924   MSM6242_REG_S1      = 0,
r19426r19427
3439   MSM6242_REG_CF
3540};
3641
42#define TIMER_RTC_CALLBACK      1
43
44
45
3746//**************************************************************************
3847//  GLOBAL VARIABLES
3948//**************************************************************************
r19426r19427
4756//**************************************************************************
4857
4958//-------------------------------------------------
50//  xxx_device - constructor
59//  msm6242_device - constructor
5160//-------------------------------------------------
5261
5362msm6242_device::msm6242_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
r19426r19427
5665
5766}
5867
68
69
70//-------------------------------------------------
71//  rtc_timer_callback
72//-------------------------------------------------
73
5974void msm6242_device::rtc_timer_callback()
6075{
6176   static const UINT8 dpm[12] = { 0x31, 0x28, 0x31, 0x30, 0x31, 0x30, 0x31, 0x31, 0x30, 0x31, 0x30, 0x31 };
r19426r19427
109124   }
110125}
111126
112TIMER_CALLBACK( msm6242_device::rtc_inc_callback )
127
128
129//-------------------------------------------------
130//  device_timer - handle timer callbacks
131//-------------------------------------------------
132
133void msm6242_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
113134{
114   reinterpret_cast<msm6242_device *>(ptr)->rtc_timer_callback();
135   switch(id)
136   {
137      case TIMER_RTC_CALLBACK:
138         rtc_timer_callback();
139         break;
140   }
115141}
116142
143
144
117145//-------------------------------------------------
118146//  device_validity_check - perform validity checks
119147//  on this device
r19426r19427
123151{
124152}
125153
154
155
126156//-------------------------------------------------
127157//  device_start - device-specific startup
128158//-------------------------------------------------
r19426r19427
131161{
132162   m_out_int_func.resolve( m_out_int_cb, *this );
133163
134   /* let's call the timer callback every second */
135   machine().scheduler().timer_pulse(attotime::from_hz(clock()), FUNC(rtc_inc_callback), 0, (void *)this);
164   // let's call the timer callback every tick
165   m_timer = timer_alloc(TIMER_RTC_CALLBACK);
166   m_timer->adjust(attotime::zero, 0, attotime::from_hz(clock()));
136167
168   // get real time from system
137169   system_time systime;
138170   machine().base_datetime(systime);
139171
172   // ...and set the RTC time
140173   m_rtc.day = (systime.local_time.mday);
141174   m_rtc.month = (systime.local_time.month+1);
142175   m_rtc.wday = (systime.local_time.weekday);
r19426r19427
148181   m_irq_flag = 0;
149182   m_irq_type = 0;
150183
151   /* TODO: skns writes 0x4 to D then expects E == 6 and F == 4, perhaps those are actually saved in the RTC CMOS? */
184   // TODO: skns writes 0x4 to D then expects E == 6 and F == 4, perhaps those are actually saved in the RTC CMOS?
152185   m_reg[0] = 0;
153186   m_reg[1] = 0x6;
154187   m_reg[2] = 0x4;
155188}
156189
157190
191
158192//-------------------------------------------------
159193//  device_reset - device-specific reset
160194//-------------------------------------------------
r19426r19427
166200}
167201
168202
203
169204//-------------------------------------------------
170205//  device_config_complete - perform any
171206//  operations now that the configuration is
r19426r19427
178213
179214   if ( intf != NULL )
180215   {
181      *static_cast<msm6242_interface *>(this) = *intf;
216      m_out_int_cb = intf->m_out_int_cb;
182217   }
183218   else
184219   {
r19426r19427
186221   }
187222}
188223
224
225
189226//**************************************************************************
190227//  READ/WRITE HANDLERS
191228//**************************************************************************
192229
230//-------------------------------------------------
231//  read
232//-------------------------------------------------
233
193234READ8_MEMBER( msm6242_device::read )
194235{
195236   rtc_regs_t cur_time;
196237
197   //cur_time = (m_reg[0] & 1) ? m_hold : m_rtc;
198
199238   cur_time = m_rtc;
200239
201240   switch(offset)
r19426r19427
244283   return 0;
245284}
246285
286
287
288//-------------------------------------------------
289//  write
290//-------------------------------------------------
291
247292WRITE8_MEMBER( msm6242_device::write )
248293{
249294   switch(offset)
250295   {
251296      case MSM6242_REG_CD:
252297      {
253         /*
254            x--- 30s ADJ
255            -x-- IRQ FLAG
256            --x- BUSY
257            ---x HOLD
258            */
298            //   x--- 30s ADJ
299            //   -x-- IRQ FLAG
300            //   --x- BUSY
301            //   ---x HOLD
259302
260303         m_reg[0] = data & 0x0f;
261304
262         #if 0
263         if (data & 1)   /* was Hold set? */
264         {
265            m_hold.day = m_rtc.day;
266            m_hold.month = m_rtc.month;
267            m_hold.hour = m_rtc.hour;
268            m_hold.day = m_rtc.day;
269            m_hold.month = m_rtc.month;
270            m_hold.year = m_rtc.year;
271            m_hold.wday = m_rtc.wday;
272         }
273         #endif
274
275305         return;
276306      }
277307
278308      case MSM6242_REG_CE:
279309      {
280         /*
281            xx-- t0,t1 (timing irq)
282            --x- STD
283            ---x MASK
284            */
310            //   xx-- t0,t1 (timing irq)
311            //   --x- STD
312            //   ---x MASK
285313
286314         m_reg[1] = data & 0x0f;
287315         if((data & 3) == 0) // MASK & STD = 0
288316         {
289317            m_irq_flag = 1;
290318            m_irq_type = (data & 0xc) >> 2;
291            //m_std_timer->adjust(attotime::from_msec(timer_param[(data & 0xc) >> 2]), 0, attotime::from_msec(timer_param[(data & 0xc) >> 2]));
292319         }
293320         else
294321         {
r19426r19427
302329
303330      case MSM6242_REG_CF:
304331      {
305         /*
306            x--- TEST
307            -x-- 24/12
308            --x- STOP
309            ---x RESET
310            */
332            //   x--- TEST
333            //   -x-- 24/12
334            //   --x- STOP
335            //   ---x RESET
311336
312         /* the 12/24 mode bit can only be changed when RESET does a 1 -> 0 transition */
337         // the 12/24 mode bit can only be changed when RESET does a 1 -> 0 transition
313338         if (((data & 0x01) == 0x00) && (m_reg[2] & 0x01))
314339            m_reg[2] = (m_reg[2] & ~0x04) | (data & 0x04);
315340         else
r19426r19427
321346
322347   logerror("%s: MSM6242 unmapped offset %02x written with %02x\n", machine().describe_context(), offset, data);
323348}
324
325
326
327
328
329
trunk/src/emu/machine/msm6242.h
r19426r19427
5656   virtual void device_validity_check(validity_checker &valid) const;
5757   virtual void device_start();
5858   virtual void device_reset();
59   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
5960
6061   static TIMER_CALLBACK( rtc_inc_callback );
6162
6263private:
63   UINT8 m_reg[3];
64   UINT8 m_irq_flag;
65   UINT8 m_irq_type;
66   UINT16 m_tick;
64   UINT8                  m_reg[3];
65   UINT8                  m_irq_flag;
66   UINT8                  m_irq_type;
67   UINT16                  m_tick;
6768
68   rtc_regs_t m_rtc;
69   rtc_regs_t m_hold;
69   rtc_regs_t               m_rtc;
70   rtc_regs_t               m_hold;
7071   devcb_resolved_write_line   m_out_int_func;
72   emu_timer *               m_timer;
7173};
7274
7375

Previous 199869 Revisions Next


© 1997-2024 The MAME Team