Previous 15994 Revisions Next

r11218 Sunday 17th April, 2011 at 14:06:48 UTC by Curt Coder
[MYCOM] Added MSM5832 RTC.
[src/emu]emu.mak
[src/emu/machine]msm5832.c* msm5832.h* msm58321.c msm58321.h
[src/mess/drivers]mycom.c

src/emu/emu.mak
r11217r11218
193193   $(EMUMACHINE)/mc146818.o   \
194194   $(EMUMACHINE)/mc6852.o      \
195195   $(EMUMACHINE)/mc68901.o      \
196   $(EMUMACHINE)/msm5832.o   \
196197   $(EMUMACHINE)/msm58321.o   \
197198   $(EMUMACHINE)/microtch.o   \
198199   $(EMUMACHINE)/mos6529.o      \
src/emu/machine/msm5832.c
r0r11218
1/**********************************************************************
2
3    OKI MSM5832 Real Time Clock/Calendar emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************/
9
10/*
11
12    TODO:
13
14   - 12/24 hour
15   - AM/PM
16   - leap year
17   - test input
18   - reference signal output
19
20*/
21
22#include "msm5832.h"
23#include "machine/devhelpr.h"
24
25
26
27//**************************************************************************
28//  MACROS / CONSTANTS
29//**************************************************************************
30
31#define LOG 0
32
33
34// registers
35enum
36{
37   REGISTER_S1 = 0,
38   REGISTER_S10,
39   REGISTER_MI1,
40   REGISTER_MI10,
41   REGISTER_H1,
42   REGISTER_H10,
43   REGISTER_W,
44   REGISTER_D1,
45   REGISTER_D10,
46   REGISTER_MO1,
47   REGISTER_MO10,
48   REGISTER_Y1,
49   REGISTER_Y10,
50   REGISTER_REF = 15
51};
52
53
54// days per month
55static const int DAYS_PER_MONTH[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
56
57
58
59//**************************************************************************
60//  GLOBAL VARIABLES
61//**************************************************************************
62
63// devices
64const device_type MSM5832 = msm5832_device_config::static_alloc_device_config;
65
66
67
68//**************************************************************************
69//  DEVICE CONFIGURATION
70//**************************************************************************
71
72GENERIC_DEVICE_CONFIG_SETUP(msm5832, "MSM5832")
73
74
75
76//**************************************************************************
77//  INLINE HELPERS
78//**************************************************************************
79
80//-------------------------------------------------
81//  read_counter -
82//-------------------------------------------------
83
84inline int msm5832_device::read_counter(int counter)
85{
86   return (m_reg[counter + 1] * 10) + m_reg[counter];
87}
88
89
90//-------------------------------------------------
91//  write_counter -
92//-------------------------------------------------
93
94inline void msm5832_device::write_counter(int counter, int value)
95{
96   m_reg[counter] = value % 10;
97   m_reg[counter + 1] = value / 10;
98}
99
100
101//-------------------------------------------------
102//  advance_seconds -
103//-------------------------------------------------
104
105inline void msm5832_device::advance_seconds()
106{
107   int seconds = read_counter(REGISTER_S1);
108
109   seconds++;
110
111   if (seconds > 59)
112   {
113      seconds = 0;
114
115      advance_minutes();
116   }
117
118   write_counter(REGISTER_S1, seconds);
119}
120
121
122//-------------------------------------------------
123//  advance_minutes -
124//-------------------------------------------------
125
126inline void msm5832_device::advance_minutes()
127{
128   int minutes = read_counter(REGISTER_MI1);
129   int hours = read_counter(REGISTER_H1);
130   int days = read_counter(REGISTER_D1);
131   int month = read_counter(REGISTER_MO1);
132   int year = read_counter(REGISTER_Y1);
133   int day_of_week = m_reg[REGISTER_W];
134
135   minutes++;
136
137   if (minutes > 59)
138   {
139      minutes = 0;
140      hours++;
141   }
142
143   if (hours > 23)
144   {
145      hours = 0;
146      days++;
147      day_of_week++;
148   }
149
150   if (day_of_week > 6)
151   {
152      day_of_week++;
153   }
154
155   if (days > DAYS_PER_MONTH[month - 1])
156   {
157      days = 1;
158      month++;
159   }
160
161   if (month > 12)
162   {
163      month = 1;
164      year++;
165   }
166
167   if (year > 99)
168   {
169      year = 0;
170   }
171
172   write_counter(REGISTER_MI1, minutes);
173   write_counter(REGISTER_H1, hours);
174   write_counter(REGISTER_D1, days);
175   write_counter(REGISTER_MO1, month);
176   write_counter(REGISTER_Y1, year);
177   m_reg[REGISTER_W] = day_of_week;
178}
179
180
181
182//**************************************************************************
183//  LIVE DEVICE
184//**************************************************************************
185
186//-------------------------------------------------
187//  msm5832_device - constructor
188//-------------------------------------------------
189
190msm5832_device::msm5832_device(running_machine &_machine, const msm5832_device_config &config)
191    : device_t(_machine, config),
192     m_hold(0),
193     m_address(0),
194     m_read(0),
195     m_write(0),
196     m_cs(0),
197      m_config(config)
198{
199   for (int i = 0; i < 13; i++)
200      m_reg[i] = 0;
201}
202
203
204//-------------------------------------------------
205//  device_start - device-specific startup
206//-------------------------------------------------
207
208void msm5832_device::device_start()
209{
210   // allocate timers
211   m_clock_timer = timer_alloc(TIMER_CLOCK);
212   m_clock_timer->adjust(attotime::from_hz(clock() / 32768), 0, attotime::from_hz(clock() / 32768));
213
214   // state saving
215   save_item(NAME(m_reg));
216   save_item(NAME(m_hold));
217   save_item(NAME(m_address));
218   save_item(NAME(m_read));
219   save_item(NAME(m_write));
220   save_item(NAME(m_cs));
221}
222
223
224//-------------------------------------------------
225//  device_timer - handler timer events
226//-------------------------------------------------
227
228void msm5832_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
229{
230   switch (id)
231   {
232   case TIMER_CLOCK:
233      if (!m_hold)
234      {
235         advance_seconds();
236      }
237      break;
238   }
239}
240
241
242//-------------------------------------------------
243//  data_r -
244//-------------------------------------------------
245
246READ8_MEMBER( msm5832_device::data_r )
247{
248   UINT8 data = 0;
249   
250   if (m_cs && m_read)
251   {
252      if (m_address == REGISTER_REF)
253      {
254         // TODO reference output
255      }
256      else
257      {
258         data = m_reg[m_address];
259      }
260   }
261
262   if (LOG) logerror("MSM5832 '%s' Register Read %01x: %01x\n", tag(), m_address, data & 0x0f);
263
264   return data & 0x0f;
265}
266
267
268//-------------------------------------------------
269//  data_w -
270//-------------------------------------------------
271
272WRITE8_MEMBER( msm5832_device::data_w )
273{
274   if (LOG) logerror("MSM5832 '%s' Register Write %01x: %01x\n", tag(), m_address, data & 0x0f);
275
276   if (m_cs && m_write)
277   {
278      m_reg[m_address] = data & 0x0f;
279   }
280}
281
282
283//-------------------------------------------------
284//  address_w -
285//-------------------------------------------------
286
287void msm5832_device::address_w(UINT8 data)
288{
289   if (LOG) logerror("MSM5832 '%s' Address: %01x\n", tag(), data & 0x0f);
290
291   m_address = data & 0x0f;
292}
293
294
295//-------------------------------------------------
296//  adj_w -
297//-------------------------------------------------
298
299WRITE_LINE_MEMBER( msm5832_device::adj_w )
300{
301   if (LOG) logerror("MSM5832 '%s' 30 ADJ: %u\n", tag(), state);
302
303   if (state)
304   {
305      int seconds = read_counter(REGISTER_S1);
306
307      if (seconds < 30)
308      {
309         write_counter(REGISTER_S1, 0);
310      }
311      else
312      {
313         write_counter(REGISTER_S1, 0);
314         advance_minutes();
315      }
316   }
317}
318
319
320//-------------------------------------------------
321//  test_w -
322//-------------------------------------------------
323
324WRITE_LINE_MEMBER( msm5832_device::test_w )
325{
326   if (LOG) logerror("MSM5832 '%s' TEST: %u\n", tag(), state);
327}
328
329
330//-------------------------------------------------
331//  hold_w -
332//-------------------------------------------------
333
334WRITE_LINE_MEMBER( msm5832_device::hold_w )
335{
336   if (LOG) logerror("MSM5832 '%s' HOLD: %u\n", tag(), state);
337
338   m_hold = state;
339}
340
341
342//-------------------------------------------------
343//  read_w -
344//-------------------------------------------------
345
346WRITE_LINE_MEMBER( msm5832_device::read_w )
347{
348   if (LOG) logerror("MSM5832 '%s' READ: %u\n", tag(), state);
349
350   m_read = state;
351}
352
353
354//-------------------------------------------------
355//  write_w -
356//-------------------------------------------------
357
358WRITE_LINE_MEMBER( msm5832_device::write_w )
359{
360   if (LOG) logerror("MSM5832 '%s' WR: %u\n", tag(), state);
361
362   m_write = state;
363}
364
365
366//-------------------------------------------------
367//  cs_w -
368//-------------------------------------------------
369
370WRITE_LINE_MEMBER( msm5832_device::cs_w )
371{
372   if (LOG) logerror("MSM5832 '%s' CS: %u\n", tag(), state);
373
374   m_cs = state;
375}
src/emu/machine/msm5832.h
r0r11218
1/**********************************************************************
2
3    OKI MSM5832 Real Time Clock/Calendar emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************
9                            _____   _____
10                   Vdd   1 |*    \_/     | 18  HOLD
11                 WRITE   2 |             | 17  _XT
12                  READ   3 |             | 16  XT
13                    A0   4 |             | 15  +- 30 ADJ
14                    A1   5 |   MSM5832   | 14  TEST
15                    A2   6 |             | 13  GND
16                    A3   7 |             | 12  D3
17                    CS   8 |             | 11  D2
18                    D0   9 |_____________| 10  D1
19
20**********************************************************************/
21
22#pragma once
23
24#ifndef __MSM5832__
25#define __MSM5832__
26
27#include "emu.h"
28
29
30
31//**************************************************************************
32//  INTERFACE CONFIGURATION MACROS
33//**************************************************************************
34
35#define MCFG_MSM5832_ADD(_tag, _clock) \
36   MCFG_DEVICE_ADD(_tag, MSM5832, _clock)
37
38
39
40//**************************************************************************
41//  TYPE DEFINITIONS
42//**************************************************************************
43
44// ======================> msm5832_device_config
45
46class msm5832_device_config :   public device_config
47{
48    friend class msm5832_device;
49
50    // construction/destruction
51    msm5832_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
52
53public:
54    // allocators
55    static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
56    virtual device_t *alloc_device(running_machine &machine) const;
57};
58
59
60
61// ======================> msm5832_device
62
63class msm5832_device :   public device_t
64{
65    friend class msm5832_device_config;
66
67    // construction/destruction
68    msm5832_device(running_machine &_machine, const msm5832_device_config &_config);
69
70public:
71   DECLARE_READ8_MEMBER( data_r );
72   DECLARE_WRITE8_MEMBER( data_w );
73
74   void address_w(UINT8 data);
75
76   DECLARE_WRITE_LINE_MEMBER( adj_w );
77   DECLARE_WRITE_LINE_MEMBER( test_w );
78   DECLARE_WRITE_LINE_MEMBER( hold_w );
79
80   DECLARE_WRITE_LINE_MEMBER( read_w );
81   DECLARE_WRITE_LINE_MEMBER( write_w );
82   DECLARE_WRITE_LINE_MEMBER( cs_w );
83
84protected:
85    // device-level overrides
86    virtual void device_start();
87   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
88
89private:
90   static const device_timer_id TIMER_CLOCK = 0;
91
92   inline int read_counter(int counter);
93   inline void write_counter(int counter, int value);
94   inline void advance_seconds();
95   inline void advance_minutes();
96
97   UINT8 m_reg[13];         // registers
98
99   int m_hold;               // counter hold
100   int m_address;            // address
101
102   int m_read;
103   int m_write;
104   int m_cs;
105
106   // timers
107   emu_timer *m_clock_timer;
108
109   const msm5832_device_config &m_config;
110};
111
112
113// device type definition
114extern const device_type MSM5832;
115
116
117
118#endif
src/emu/machine/msm58321.c
r11217r11218
1111
1212    TODO:
1313
14    - count
14   - 12/24 hour
15   - AM/PM
16   - leap year
1517    - stop
1618    - reset
1719    - reference registers
r11217r11218
5254};
5355
5456
57// days per month
58static const int DAYS_PER_MONTH[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
5559
60
61
5662//**************************************************************************
5763//  GLOBAL VARIABLES
5864//**************************************************************************
r11217r11218
9298
9399
94100//**************************************************************************
101//  INLINE HELPERS
102//**************************************************************************
103
104//-------------------------------------------------
105//  read_counter -
106//-------------------------------------------------
107
108inline int msm58321_device::read_counter(int counter)
109{
110   return (m_reg[counter + 1] * 10) + m_reg[counter];
111}
112
113
114//-------------------------------------------------
115//  write_counter -
116//-------------------------------------------------
117
118inline void msm58321_device::write_counter(int counter, int value)
119{
120   m_reg[counter] = value % 10;
121   m_reg[counter + 1] = value / 10;
122}
123
124
125//-------------------------------------------------
126//  advance_seconds -
127//-------------------------------------------------
128
129inline void msm58321_device::advance_seconds()
130{
131   int seconds = read_counter(REGISTER_S1);
132
133   seconds++;
134
135   if (seconds > 59)
136   {
137      seconds = 0;
138
139      advance_minutes();
140   }
141
142   write_counter(REGISTER_S1, seconds);
143}
144
145
146//-------------------------------------------------
147//  advance_minutes -
148//-------------------------------------------------
149
150inline void msm58321_device::advance_minutes()
151{
152   int minutes = read_counter(REGISTER_MI1);
153   int hours = read_counter(REGISTER_H1);
154   int days = read_counter(REGISTER_D1);
155   int month = read_counter(REGISTER_MO1);
156   int year = read_counter(REGISTER_Y1);
157   int day_of_week = m_reg[REGISTER_W];
158
159   minutes++;
160
161   if (minutes > 59)
162   {
163      minutes = 0;
164      hours++;
165   }
166
167   if (hours > 23)
168   {
169      hours = 0;
170      days++;
171      day_of_week++;
172   }
173
174   if (day_of_week > 6)
175   {
176      day_of_week++;
177   }
178
179   if (days > DAYS_PER_MONTH[month - 1])
180   {
181      days = 1;
182      month++;
183   }
184
185   if (month > 12)
186   {
187      month = 1;
188      year++;
189   }
190
191   if (year > 99)
192   {
193      year = 0;
194   }
195
196   write_counter(REGISTER_MI1, minutes);
197   write_counter(REGISTER_H1, hours);
198   write_counter(REGISTER_D1, days);
199   write_counter(REGISTER_MO1, month);
200   write_counter(REGISTER_Y1, year);
201   m_reg[REGISTER_W] = day_of_week;
202}
203
204
205
206//**************************************************************************
95207//  LIVE DEVICE
96208//**************************************************************************
97209
r11217r11218
103215    : device_t(_machine, config),
104216      m_config(config)
105217{
218   for (int i = 0; i < 13; i++)
219      m_reg[i] = 0;
106220}
107221
108222
r11217r11218
116230   devcb_resolve_write_line(&m_out_busy_func, &m_config.m_out_busy_func, this);
117231
118232   // allocate timers
119   m_busy_timer = timer_alloc();
120   m_busy_timer->adjust(attotime::from_hz(2), 0, attotime::from_hz(2));
233   m_clock_timer = timer_alloc(TIMER_CLOCK);
234   m_clock_timer->adjust(attotime::from_hz(clock() / 32768), 0, attotime::from_hz(clock() / 32768));
121235
236   m_busy_timer = timer_alloc(TIMER_BUSY);
237   m_busy_timer->adjust(attotime::from_hz(clock() / 16384), 0, attotime::from_hz(clock() / 16384));
238
122239   // state saving
123240   save_item(NAME(m_cs1));
124241   save_item(NAME(m_cs2));
r11217r11218
138255
139256void msm58321_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
140257{
141   devcb_call_write_line(&m_out_busy_func, m_busy);
258   switch (id)
259   {
260   case TIMER_CLOCK:
261      advance_seconds();
262      break;
142263
143   m_busy = !m_busy;
264   case TIMER_BUSY:
265      devcb_call_write_line(&m_out_busy_func, m_busy);
266      m_busy = !m_busy;
267      break;
268   }
144269}
145270
146271
r11217r11218
156281   {
157282      if (m_read)
158283      {
159         system_time systime;
160
161         m_machine.current_datetime(systime);
162
163284         switch (m_address)
164285         {
165         case REGISTER_S1:   data = systime.local_time.second % 10; break;
166         case REGISTER_S10:   data = systime.local_time.second / 10; break;
167         case REGISTER_MI1:   data = systime.local_time.minute % 10; break;
168         case REGISTER_MI10: data = systime.local_time.minute / 10; break;
169         case REGISTER_H1:   data = systime.local_time.hour % 10; break;
170         case REGISTER_H10:   data = (systime.local_time.hour / 10) | 0x08; break;
171         case REGISTER_W:   data = systime.local_time.weekday; break;
172         case REGISTER_D1:   data = systime.local_time.mday % 10; break;
173         case REGISTER_D10:   data = (systime.local_time.mday / 10) | ((systime.local_time.year % 4) ? 0 : 0x04); break;
174         case REGISTER_MO1:   data = (systime.local_time.month + 1) % 10; break;
175         case REGISTER_MO10: data = (systime.local_time.month + 1) / 10; break;
176         case REGISTER_Y1:   data = systime.local_time.year % 10; break;
177         case REGISTER_Y10:   data = (systime.local_time.year / 10) % 10;   break;
178
179286         case REGISTER_RESET:
180287            break;
181288
r11217r11218
184291            break;
185292
186293         default:
187            data = m_reg[offset];
294            data = m_reg[m_address];
188295            break;
189296         }
190297      }
r11217r11218
238345
239346      default:
240347         if (LOG) logerror("MSM58321 '%s' Register Write %01x: %01x\n", tag(), m_address, data & 0x0f);
241         m_reg[offset] = m_latch & 0x0f;
348         m_reg[m_address] = m_latch & 0x0f;
242349         break;
243350      }
244351   }
src/emu/machine/msm58321.h
r11217r11218
103103   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
104104
105105private:
106   static const device_timer_id TIMER_CLOCK = 0;
107   static const device_timer_id TIMER_BUSY = 1;
108
109   inline int read_counter(int counter);
110   inline void write_counter(int counter, int value);
111   inline void advance_seconds();
112   inline void advance_minutes();
113
106114   devcb_resolved_write_line   m_out_busy_func;
107115
108116   int m_cs1;               // chip select 1
r11217r11218
117125   UINT8 m_address;         // address latch
118126
119127   // timers
128   emu_timer *m_clock_timer;
120129   emu_timer *m_busy_timer;
121130
122131   const msm58321_device_config &m_config;
src/mess/drivers/mycom.c
r11217r11218
3939    - FDC, type 1771, single sided, capacity 143KBytes, not connected up
4040    - Cassette doesn't load
4141    - Printer
42    - RTC, type MSM5832RS, unemulated device
4342    - Keyboard lookup table for Kana and Shifted Kana
4443    - Keyboard autorepeat
4544
r11217r11218
5352#include "imagedev/cassette.h"
5453#include "sound/wave.h"
5554#include "machine/wd17xx.h"
55#include "machine/msm5832.h"
5656#include "imagedev/flopdrv.h"
5757#include "formats/basicdsk.h"
5858
59#define MSM5832RS_TAG "rtc"
5960
6061class mycom_state : public driver_device
6162{
6263public:
6364   mycom_state(running_machine &machine, const driver_device_config_base &config)
64      : driver_device(machine, config) { }
65      : driver_device(machine, config),
66        m_rtc(*this, MSM5832RS_TAG)
67   { }
6568
69   required_device<msm5832_device> m_rtc;
70
6671   device_t *m_mc6845;
6772   device_t *m_audio;
6873   device_t *m_cassette;
r11217r11218
422427      sn76496_w(state->m_audio, 0, state->m_sn_we);
423428}
424429
430static WRITE8_DEVICE_HANDLER( mycom_rtc_w )
431{
432   mycom_state *state = device->machine().driver_data<mycom_state>();
433
434   state->m_rtc->address_w(data & 0x0f);
435   
436   state->m_rtc->hold_w(BIT(data, 4));
437   state->m_rtc->read_w(BIT(data, 5));
438   state->m_rtc->write_w(BIT(data, 6));
439   state->m_rtc->cs_w(BIT(data, 7));
440}
441
425442static I8255A_INTERFACE( ppi8255_intf_0 )
426443{
427444   DEVCB_NULL,         /* Port A read */
r11217r11218
445462static I8255A_INTERFACE( ppi8255_intf_2 )
446463{
447464   DEVCB_NULL,         /* Port A read */
448   DEVCB_NULL,         /* Port B read */
465   DEVCB_DEVICE_MEMBER(MSM5832RS_TAG, msm5832_device, data_r),         /* Port B read */
449466   DEVCB_NULL,         /* Port C read */
450467   DEVCB_NULL,         /* Port A write */
451   DEVCB_NULL,         /* Port B write */
452   DEVCB_NULL         /* Port C write */
468   DEVCB_DEVICE_MEMBER(MSM5832RS_TAG, msm5832_device, data_w),         /* Port B write */
469   DEVCB_HANDLER(mycom_rtc_w)         /* Port C write */
453470};
454471
455472static const UINT8 mycom_keyval[] = { 0,
r11217r11218
568585   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
569586
570587   /* Devices */
588   MCFG_MSM5832_ADD(MSM5832RS_TAG, XTAL_32_768kHz)
571589   MCFG_CASSETTE_ADD( "cassette", default_cassette_config )
572590   MCFG_WD179X_ADD("fdc", wd1771_intf) // WD1771
573591

Previous 15994 Revisions Next


© 1998-2018 The MESS Team