Previous 15994 Revisions Next

r4086 Wednesday 7th January, 2009 at 12:33:40 UTC by Nathan Woods
Changed the DS1315 implementation to be a device
[docs]messnew.txt
[src/mess/devices]coco_fdc.c
[src/mess/drivers]coco.c
[src/mess/machine]ds1315.c ds1315.h

src/mess/machine/ds1315.c
r4085r4086
1/* This is an emulation of Dallas Semiconductor's Phantom Time Chip.
2   DS1315.
1/*********************************************************************
32
4   by tim lindner, November 2001.
5*/
3   ds1315.c
64
7#include "driver.h"
5   Dallas Semiconductor's Phantom Time Chip DS1315.
6
7   by tim lindner, November 2001.
8
9*********************************************************************/
10
811#include "ds1315.h"
912
1013
11enum
14/***************************************************************************
15    TYPE DEFINITIONS
16***************************************************************************/
17
18typedef enum
1219{
13   ds_seek_matching,
14   ds_calendar_io
20   DS_SEEK_MATCHING,
21   DS_CALENDAR_IO
22} ds1315_mode_t;
23
24
25typedef struct _ds1315_t ds1315_t;
26struct _ds1315_t
27{
28   int count;
29   ds1315_mode_t mode;
30   UINT8 raw_data[8*8];
1531};
1632
17static void ds1315_fill_raw_data( running_machine *machine );
18static void ds1315_input_raw_data( void );
1933
20static int ds1315_count;
21static int ds1315_mode;
22static int ds1315_raw_data[8*8];
23static const int ds1315_pattern[] = {  1, 0, 1, 0, 0, 0, 1, 1,
24                          0, 1, 0, 1, 1, 1, 0, 0,
25                          1, 1, 0, 0, 0, 1, 0, 1,
26                          0, 0, 1, 1, 1, 0, 1, 0,
27                          1, 0, 1, 0, 0, 0, 1, 1,
28                          0, 1, 0, 1, 1, 1, 0, 0,
29                          1, 1, 0, 0, 0, 1, 0, 1,
30                          0, 0, 1, 1, 1, 0, 1, 0 };
34/***************************************************************************
35    LOCAL VARIABLES
36***************************************************************************/
3137
32void ds1315_init( void )
38static const UINT8 ds1315_pattern[] =
3339{
34   ds1315_count = 0;
35   ds1315_mode = ds_seek_matching;
40   1, 0, 1, 0, 0, 0, 1, 1,
41   0, 1, 0, 1, 1, 1, 0, 0,
42   1, 1, 0, 0, 0, 1, 0, 1,
43   0, 0, 1, 1, 1, 0, 1, 0,
44   1, 0, 1, 0, 0, 0, 1, 1,
45   0, 1, 0, 1, 1, 1, 0, 0,
46   1, 1, 0, 0, 0, 1, 0, 1,
47   0, 0, 1, 1, 1, 0, 1, 0
48};
49
50
51/***************************************************************************
52    PROTOTYPES
53***************************************************************************/
54
55static void ds1315_fill_raw_data(const device_config *device);
56static void ds1315_input_raw_data(const device_config *device);
57
58
59
60/***************************************************************************
61    INLINE FUNCTIONS
62***************************************************************************/
63
64INLINE ds1315_t *get_token(const device_config *device)
65{
66   assert(device != NULL);
67   assert(device->type == DS1315);
68   return (ds1315_t *) device->token;
3669}
3770
38 READ8_HANDLER ( ds1315_r_0 )
71
72/***************************************************************************
73    IMPLEMENTATION
74***************************************************************************/
75
76/*-------------------------------------------------
77    DEVICE_START( ds1315 )
78-------------------------------------------------*/
79
80static DEVICE_START(ds1315)
3981{
40   if( ds1315_pattern[ ds1315_count++ ] == 0 )
82   ds1315_t *ds1315 = get_token(device);
83
84   memset(ds1315, 0, sizeof(*ds1315));
85   ds1315->count = 0;
86   ds1315->mode = DS_SEEK_MATCHING;
87
88   return DEVICE_START_OK;
89}
90
91
92/*-------------------------------------------------
93    DEVICE_START( ds1315 )
94-------------------------------------------------*/
95
96READ8_DEVICE_HANDLER( ds1315_r_0 )
97{
98   ds1315_t *ds1315 = get_token(device);
99
100   if (ds1315_pattern[ds1315->count++] == 0)
41101   {
42      if( ds1315_count == 64 )
102      if (ds1315->count == 64)
43103      {
44104         /* entire pattern matched */
45         ds1315_count = 0;
46         ds1315_mode = ds_calendar_io;
47         ds1315_fill_raw_data(space->machine);
105         ds1315->count = 0;
106         ds1315->mode = DS_CALENDAR_IO;
107         ds1315_fill_raw_data(device);
48108      }
49109
50110      return 0;
51111   }
52112
53   ds1315_count = 0;
54   ds1315_mode = ds_seek_matching;
55
113   ds1315->count = 0;
114   ds1315->mode = DS_SEEK_MATCHING;
56115   return 0;
57116}
58117
59 READ8_HANDLER ( ds1315_r_1 )
118
119/*-------------------------------------------------
120    ds1315_r_1
121-------------------------------------------------*/
122
123READ8_DEVICE_HANDLER ( ds1315_r_1 )
60124{
61   if( ds1315_pattern[ ds1315_count++ ] == 1 )
125   ds1315_t *ds1315 = get_token(device);
126
127   if (ds1315_pattern[ ds1315->count++ ] == 1)
128   {
129      ds1315->count %= 64;
62130      return 0;
131   }
63132
64   ds1315_count = 0;
65   ds1315_mode = ds_seek_matching;
133   ds1315->count = 0;
134   ds1315->mode = DS_SEEK_MATCHING;
66135   return 0;
67136}
68137
69 READ8_HANDLER ( ds1315_r_data )
138
139/*-------------------------------------------------
140    ds1315_r_data
141-------------------------------------------------*/
142
143READ8_DEVICE_HANDLER ( ds1315_r_data )
70144{
71   UINT8   result;
145   UINT8 result;
146   ds1315_t *ds1315 = get_token(device);
72147
73   if( ds1315_mode == ds_calendar_io )
148   if (ds1315->mode == DS_CALENDAR_IO)
74149   {
75      result = ds1315_raw_data[ ds1315_count++ ];
150      result = ds1315->raw_data[ ds1315->count++ ];
76151
77      if( ds1315_count == 64 )
152      if (ds1315->count == 64)
78153      {
79         ds1315_mode = ds_seek_matching;
80         ds1315_count = 0;
154         ds1315->mode = DS_SEEK_MATCHING;
155         ds1315->count = 0;
81156      }
82157
83158      return result;
84159   }
85160
86   ds1315_count = 0;
161   ds1315->count = 0;
87162   return 0;
88163}
89164
90WRITE8_HANDLER ( ds1315_w_data )
165
166/*-------------------------------------------------
167    ds1315_w_data
168-------------------------------------------------*/
169
170WRITE8_DEVICE_HANDLER ( ds1315_w_data )
91171{
172   ds1315_t *ds1315 = get_token(device);
92173
93   if( ds1315_mode == ds_calendar_io )
174   if (ds1315->mode == DS_CALENDAR_IO)
94175   {
95      ds1315_raw_data[ ds1315_count++ ] = data & 0x01;
176      ds1315->raw_data[ds1315->count++] = data & 0x01;
96177
97      if( ds1315_count == 64 )
178      if (ds1315->count == 64)
98179      {
99         ds1315_mode = ds_seek_matching;
100         ds1315_count = 0;
101         ds1315_input_raw_data();
180         ds1315->mode = DS_SEEK_MATCHING;
181         ds1315->count = 0;
182         ds1315_input_raw_data(device);
102183      }
103
104184      return;
105185   }
106186
107   ds1315_count = 0;
108   return;
187   ds1315->count = 0;
109188}
110189
111static void ds1315_fill_raw_data( running_machine *machine )
190
191/*-------------------------------------------------
192    ds1315_fill_raw_data
193-------------------------------------------------*/
194
195static void ds1315_fill_raw_data(const device_config *device)
112196{
113197   /* This routine will (hopefully) call a standard 'C' library routine to get the current
114198      date and time and then fill in the raw data struct.
115199   */
116200
117201   mame_system_time systime;
202   ds1315_t *ds1315 = get_token(device);
118203   int raw[8], i, j;
119204
120205   /* get the current date/time from the core */
121   mame_get_current_datetime(machine, &systime);
206   mame_get_current_datetime(device->machine, &systime);
122207
123208   raw[0] = 0;   /* tenths and hundreths of seconds are always zero */
124209   raw[1] = dec_2_bcd(systime.local_time.second);
r4085r4086
132217
133218   /* Ok now we have the raw bcd bytes. Now we need to push them into our bit array */
134219
135   for( i=0; i<64; i++ )
220   for (i = 0; i < 64; i++)
136221   {
137222      j = i / 8;
138      ds1315_raw_data[i] = (raw[j] & 0x0001);
223      ds1315->raw_data[i] = (raw[j] & 0x0001);
139224      raw[j] = raw[j] >> 1;
140225   }
141
142   /* After reading the sources for localtime(), I have determined the the
143      buffer returned is a global variable, thus it does not need to be free()d.
144   */
145226}
146227
147static void ds1315_input_raw_data( void )
228
229/*-------------------------------------------------
230    ds1315_input_raw_data
231-------------------------------------------------*/
232
233static void ds1315_input_raw_data(const device_config *device)
148234{
149235   /* This routine is called when new date and time has been written to the
150236      clock chip. Currently we ignore setting the date and time in the clock
r4085r4086
154240   */
155241}
156242
243
244/*-------------------------------------------------
245    DEVICE_SET_INFO( ds1315 )
246-------------------------------------------------*/
247
248static DEVICE_SET_INFO( ds1315 )
249{
250   switch (state)
251   {
252      /* no parameters to set */
253   }
254}
255
256
257
258/*-------------------------------------------------
259    DEVICE_GET_INFO( ds1315 )
260-------------------------------------------------*/
261
262DEVICE_GET_INFO( ds1315 )
263{
264   switch (state)
265   {
266      /* --- the following bits of info are returned as 64-bit signed integers --- */
267      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(ds1315_t);               break;
268      case DEVINFO_INT_INLINE_CONFIG_BYTES:         info->i = 0;                        break;
269      case DEVINFO_INT_CLASS:                     info->i = DEVICE_CLASS_PERIPHERAL;         break;
270
271      /* --- the following bits of info are returned as pointers to data or functions --- */
272      case DEVINFO_FCT_SET_INFO:                  info->set_info = DEVICE_SET_INFO_NAME(ds1315); break;
273      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(ds1315);   break;
274      case DEVINFO_FCT_STOP:                     /* Nothing */                        break;
275      case DEVINFO_FCT_RESET:                     /* Nothing */                        break;
276
277      /* --- the following bits of info are returned as NULL-terminated strings --- */
278      case DEVINFO_STR_NAME:                     strcpy(info->s, "Dallas Semiconductor DS1315");   break;
279      case DEVINFO_STR_FAMILY:                  strcpy(info->s, "Dallas Semiconductor DS1315");   break;
280      case DEVINFO_STR_VERSION:                  strcpy(info->s, "1.0");                  break;
281      case DEVINFO_STR_SOURCE_FILE:               strcpy(info->s, __FILE__);               break;
282      case DEVINFO_STR_CREDITS:                  /* Nothing */                        break;
283   }
284}
src/mess/machine/ds1315.h
r4085r4086
1/* This is an emulation of Dallas Semiconductor's Phantom Time Chip.
2   DS1315.
1/*********************************************************************
32
4   by tim lindner, November 2001.
5*/
3   ds1315.h
64
7void ds1315_init( void );
8 READ8_HANDLER ( ds1315_r_0 );
9 READ8_HANDLER ( ds1315_r_1 );
10 READ8_HANDLER ( ds1315_r_data );
11WRITE8_HANDLER ( ds1315_w_data );
5   Dallas Semiconductor's Phantom Time Chip DS1315.
6
7   by tim lindner, November 2001.
8
9*********************************************************************/
10
11#ifndef __DS1315_H__
12#define __DS1315_H__
13
14#include "driver.h"
15
16
17/***************************************************************************
18    MACROS
19***************************************************************************/
20
21#define DS1315         DEVICE_GET_INFO_NAME(ds1315)
22
23
24
25/***************************************************************************
26    DEVICE CONFIGURATION MACROS
27***************************************************************************/
28
29#define MDRV_DS1315_ADD(_tag) \
30   MDRV_DEVICE_ADD(_tag, DS1315, 0)
31
32
33/***************************************************************************
34    FUNCTION PROTOTYPES
35***************************************************************************/
36
37DEVICE_GET_INFO( ds1315 );
38READ8_DEVICE_HANDLER( ds1315_r_0 );
39READ8_DEVICE_HANDLER( ds1315_r_1 );
40READ8_DEVICE_HANDLER( ds1315_r_data );
41WRITE8_DEVICE_HANDLER( ds1315_w_data );
42
43#endif /* __DS1315_H__ */
src/mess/devices/coco_fdc.c
r4085r4086
408408static UINT8 fdc_coco3plus_r(running_machine *machine, coco_cartridge *cartridge, UINT16 addr)
409409{
410410   const device_config *dev;
411   const address_space *space = cpu_get_address_space( machine->cpu[0], ADDRESS_SPACE_PROGRAM );
412411   UINT8 result = fdc_coco_r(machine, cartridge, addr);
413412
414413   switch(addr)
r4085r4086
423422
424423      case 0x38:   /* FF78 */
425424         if (real_time_clock(machine) == RTC_CLOUD9)
426            ds1315_r_0(space, addr);
425         {
426            dev = device_list_find_by_tag(machine->config->devicelist, DS1315, "cloud9");
427            ds1315_r_0(dev, addr);
428         }
427429         break;
428430
429431      case 0x39:   /* FF79 */
430432         if (real_time_clock(machine) == RTC_CLOUD9)
431            ds1315_r_1(space, addr);
433         {
434            dev = device_list_find_by_tag(machine->config->devicelist, DS1315, "cloud9");
435            ds1315_r_1(dev, addr);
436         }
432437         break;
433438
434439      case 0x3C:   /* FF7C */
435440         if (real_time_clock(machine) == RTC_CLOUD9)
436            result = ds1315_r_data(space, addr);
441         {
442            dev = device_list_find_by_tag(machine->config->devicelist, DS1315, "cloud9");
443            result = ds1315_r_data(dev, addr);
444         }
437445         break;
438446
439447      case 0x40:
src/mess/drivers/coco.c
r4085r4086
1616#include "machine/6821pia.h"
1717#include "video/m6847.h"
1818#include "machine/msm6242.h"
19#include "machine/ds1315.h"
1920#include "machine/6883sam.h"
2021#include "includes/coco.h"
2122#include "devices/basicdsk.h"
r4085r4086
864865
865866   /* devices */
866867   MDRV_MSM6242_ADD("disto")
868   MDRV_DS1315_ADD("cloud9")
867869
868870   /* cassette */
869871   MDRV_CASSETTE_ADD( "cassette", coco_cassette_config )
r4085r4086
903905
904906   /* devices */
905907   MDRV_MSM6242_ADD("disto")
908   MDRV_DS1315_ADD("cloud9")
906909
907910   /* cassette */
908911   MDRV_CASSETTE_ADD( "cassette", coco_cassette_config )
r4085r4086
942945
943946   /* devices */
944947   MDRV_MSM6242_ADD("disto")
948   MDRV_DS1315_ADD("cloud9")
945949
946950   /* cassette */
947951   MDRV_CASSETTE_ADD( "cassette", coco_cassette_config )
r4085r4086
991995   /* devices */
992996   MDRV_COCO_VHD_ADD("vhd")
993997   MDRV_MSM6242_ADD("disto")
998   MDRV_DS1315_ADD("cloud9")
994999
9951000   /* cassette */
9961001   MDRV_CASSETTE_ADD( "cassette", coco_cassette_config )
docs/messnew.txt
r4085r4086
2626
2727Source Changes:
2828----------------
29(none)
29- Changed the DS1315 implementation to be a device.  [Nathan Woods]
3030
3131
3232

Previous 15994 Revisions Next


© 1998-2018 The MESS Team