src/mess/machine/ds1315.c
| r4085 | r4086 | |
| 1 | | /* This is an emulation of Dallas Semiconductor's Phantom Time Chip. |
| 2 | | DS1315. |
| 1 | /********************************************************************* |
| 3 | 2 | |
| 4 | | by tim lindner, November 2001. |
| 5 | | */ |
| 3 | ds1315.c |
| 6 | 4 | |
| 7 | | #include "driver.h" |
| 5 | Dallas Semiconductor's Phantom Time Chip DS1315. |
| 6 | |
| 7 | by tim lindner, November 2001. |
| 8 | |
| 9 | *********************************************************************/ |
| 10 | |
| 8 | 11 | #include "ds1315.h" |
| 9 | 12 | |
| 10 | 13 | |
| 11 | | enum |
| 14 | /*************************************************************************** |
| 15 | TYPE DEFINITIONS |
| 16 | ***************************************************************************/ |
| 17 | |
| 18 | typedef enum |
| 12 | 19 | { |
| 13 | | ds_seek_matching, |
| 14 | | ds_calendar_io |
| 20 | DS_SEEK_MATCHING, |
| 21 | DS_CALENDAR_IO |
| 22 | } ds1315_mode_t; |
| 23 | |
| 24 | |
| 25 | typedef struct _ds1315_t ds1315_t; |
| 26 | struct _ds1315_t |
| 27 | { |
| 28 | int count; |
| 29 | ds1315_mode_t mode; |
| 30 | UINT8 raw_data[8*8]; |
| 15 | 31 | }; |
| 16 | 32 | |
| 17 | | static void ds1315_fill_raw_data( running_machine *machine ); |
| 18 | | static void ds1315_input_raw_data( void ); |
| 19 | 33 | |
| 20 | | static int ds1315_count; |
| 21 | | static int ds1315_mode; |
| 22 | | static int ds1315_raw_data[8*8]; |
| 23 | | static 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 | ***************************************************************************/ |
| 31 | 37 | |
| 32 | | void ds1315_init( void ) |
| 38 | static const UINT8 ds1315_pattern[] = |
| 33 | 39 | { |
| 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 | |
| 55 | static void ds1315_fill_raw_data(const device_config *device); |
| 56 | static void ds1315_input_raw_data(const device_config *device); |
| 57 | |
| 58 | |
| 59 | |
| 60 | /*************************************************************************** |
| 61 | INLINE FUNCTIONS |
| 62 | ***************************************************************************/ |
| 63 | |
| 64 | INLINE ds1315_t *get_token(const device_config *device) |
| 65 | { |
| 66 | assert(device != NULL); |
| 67 | assert(device->type == DS1315); |
| 68 | return (ds1315_t *) device->token; |
| 36 | 69 | } |
| 37 | 70 | |
| 38 | | READ8_HANDLER ( ds1315_r_0 ) |
| 71 | |
| 72 | /*************************************************************************** |
| 73 | IMPLEMENTATION |
| 74 | ***************************************************************************/ |
| 75 | |
| 76 | /*------------------------------------------------- |
| 77 | DEVICE_START( ds1315 ) |
| 78 | -------------------------------------------------*/ |
| 79 | |
| 80 | static DEVICE_START(ds1315) |
| 39 | 81 | { |
| 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 | |
| 96 | READ8_DEVICE_HANDLER( ds1315_r_0 ) |
| 97 | { |
| 98 | ds1315_t *ds1315 = get_token(device); |
| 99 | |
| 100 | if (ds1315_pattern[ds1315->count++] == 0) |
| 41 | 101 | { |
| 42 | | if( ds1315_count == 64 ) |
| 102 | if (ds1315->count == 64) |
| 43 | 103 | { |
| 44 | 104 | /* 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); |
| 48 | 108 | } |
| 49 | 109 | |
| 50 | 110 | return 0; |
| 51 | 111 | } |
| 52 | 112 | |
| 53 | | ds1315_count = 0; |
| 54 | | ds1315_mode = ds_seek_matching; |
| 55 | | |
| 113 | ds1315->count = 0; |
| 114 | ds1315->mode = DS_SEEK_MATCHING; |
| 56 | 115 | return 0; |
| 57 | 116 | } |
| 58 | 117 | |
| 59 | | READ8_HANDLER ( ds1315_r_1 ) |
| 118 | |
| 119 | /*------------------------------------------------- |
| 120 | ds1315_r_1 |
| 121 | -------------------------------------------------*/ |
| 122 | |
| 123 | READ8_DEVICE_HANDLER ( ds1315_r_1 ) |
| 60 | 124 | { |
| 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; |
| 62 | 130 | return 0; |
| 131 | } |
| 63 | 132 | |
| 64 | | ds1315_count = 0; |
| 65 | | ds1315_mode = ds_seek_matching; |
| 133 | ds1315->count = 0; |
| 134 | ds1315->mode = DS_SEEK_MATCHING; |
| 66 | 135 | return 0; |
| 67 | 136 | } |
| 68 | 137 | |
| 69 | | READ8_HANDLER ( ds1315_r_data ) |
| 138 | |
| 139 | /*------------------------------------------------- |
| 140 | ds1315_r_data |
| 141 | -------------------------------------------------*/ |
| 142 | |
| 143 | READ8_DEVICE_HANDLER ( ds1315_r_data ) |
| 70 | 144 | { |
| 71 | | UINT8 result; |
| 145 | UINT8 result; |
| 146 | ds1315_t *ds1315 = get_token(device); |
| 72 | 147 | |
| 73 | | if( ds1315_mode == ds_calendar_io ) |
| 148 | if (ds1315->mode == DS_CALENDAR_IO) |
| 74 | 149 | { |
| 75 | | result = ds1315_raw_data[ ds1315_count++ ]; |
| 150 | result = ds1315->raw_data[ ds1315->count++ ]; |
| 76 | 151 | |
| 77 | | if( ds1315_count == 64 ) |
| 152 | if (ds1315->count == 64) |
| 78 | 153 | { |
| 79 | | ds1315_mode = ds_seek_matching; |
| 80 | | ds1315_count = 0; |
| 154 | ds1315->mode = DS_SEEK_MATCHING; |
| 155 | ds1315->count = 0; |
| 81 | 156 | } |
| 82 | 157 | |
| 83 | 158 | return result; |
| 84 | 159 | } |
| 85 | 160 | |
| 86 | | ds1315_count = 0; |
| 161 | ds1315->count = 0; |
| 87 | 162 | return 0; |
| 88 | 163 | } |
| 89 | 164 | |
| 90 | | WRITE8_HANDLER ( ds1315_w_data ) |
| 165 | |
| 166 | /*------------------------------------------------- |
| 167 | ds1315_w_data |
| 168 | -------------------------------------------------*/ |
| 169 | |
| 170 | WRITE8_DEVICE_HANDLER ( ds1315_w_data ) |
| 91 | 171 | { |
| 172 | ds1315_t *ds1315 = get_token(device); |
| 92 | 173 | |
| 93 | | if( ds1315_mode == ds_calendar_io ) |
| 174 | if (ds1315->mode == DS_CALENDAR_IO) |
| 94 | 175 | { |
| 95 | | ds1315_raw_data[ ds1315_count++ ] = data & 0x01; |
| 176 | ds1315->raw_data[ds1315->count++] = data & 0x01; |
| 96 | 177 | |
| 97 | | if( ds1315_count == 64 ) |
| 178 | if (ds1315->count == 64) |
| 98 | 179 | { |
| 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); |
| 102 | 183 | } |
| 103 | | |
| 104 | 184 | return; |
| 105 | 185 | } |
| 106 | 186 | |
| 107 | | ds1315_count = 0; |
| 108 | | return; |
| 187 | ds1315->count = 0; |
| 109 | 188 | } |
| 110 | 189 | |
| 111 | | static void ds1315_fill_raw_data( running_machine *machine ) |
| 190 | |
| 191 | /*------------------------------------------------- |
| 192 | ds1315_fill_raw_data |
| 193 | -------------------------------------------------*/ |
| 194 | |
| 195 | static void ds1315_fill_raw_data(const device_config *device) |
| 112 | 196 | { |
| 113 | 197 | /* This routine will (hopefully) call a standard 'C' library routine to get the current |
| 114 | 198 | date and time and then fill in the raw data struct. |
| 115 | 199 | */ |
| 116 | 200 | |
| 117 | 201 | mame_system_time systime; |
| 202 | ds1315_t *ds1315 = get_token(device); |
| 118 | 203 | int raw[8], i, j; |
| 119 | 204 | |
| 120 | 205 | /* get the current date/time from the core */ |
| 121 | | mame_get_current_datetime(machine, &systime); |
| 206 | mame_get_current_datetime(device->machine, &systime); |
| 122 | 207 | |
| 123 | 208 | raw[0] = 0; /* tenths and hundreths of seconds are always zero */ |
| 124 | 209 | raw[1] = dec_2_bcd(systime.local_time.second); |
| r4085 | r4086 | |
| 132 | 217 | |
| 133 | 218 | /* Ok now we have the raw bcd bytes. Now we need to push them into our bit array */ |
| 134 | 219 | |
| 135 | | for( i=0; i<64; i++ ) |
| 220 | for (i = 0; i < 64; i++) |
| 136 | 221 | { |
| 137 | 222 | j = i / 8; |
| 138 | | ds1315_raw_data[i] = (raw[j] & 0x0001); |
| 223 | ds1315->raw_data[i] = (raw[j] & 0x0001); |
| 139 | 224 | raw[j] = raw[j] >> 1; |
| 140 | 225 | } |
| 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 | | */ |
| 145 | 226 | } |
| 146 | 227 | |
| 147 | | static void ds1315_input_raw_data( void ) |
| 228 | |
| 229 | /*------------------------------------------------- |
| 230 | ds1315_input_raw_data |
| 231 | -------------------------------------------------*/ |
| 232 | |
| 233 | static void ds1315_input_raw_data(const device_config *device) |
| 148 | 234 | { |
| 149 | 235 | /* This routine is called when new date and time has been written to the |
| 150 | 236 | clock chip. Currently we ignore setting the date and time in the clock |
| r4085 | r4086 | |
| 154 | 240 | */ |
| 155 | 241 | } |
| 156 | 242 | |
| 243 | |
| 244 | /*------------------------------------------------- |
| 245 | DEVICE_SET_INFO( ds1315 ) |
| 246 | -------------------------------------------------*/ |
| 247 | |
| 248 | static 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 | |
| 262 | DEVICE_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
| r4085 | r4086 | |
| 1 | | /* This is an emulation of Dallas Semiconductor's Phantom Time Chip. |
| 2 | | DS1315. |
| 1 | /********************************************************************* |
| 3 | 2 | |
| 4 | | by tim lindner, November 2001. |
| 5 | | */ |
| 3 | ds1315.h |
| 6 | 4 | |
| 7 | | void ds1315_init( void ); |
| 8 | | READ8_HANDLER ( ds1315_r_0 ); |
| 9 | | READ8_HANDLER ( ds1315_r_1 ); |
| 10 | | READ8_HANDLER ( ds1315_r_data ); |
| 11 | | WRITE8_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 | |
| 37 | DEVICE_GET_INFO( ds1315 ); |
| 38 | READ8_DEVICE_HANDLER( ds1315_r_0 ); |
| 39 | READ8_DEVICE_HANDLER( ds1315_r_1 ); |
| 40 | READ8_DEVICE_HANDLER( ds1315_r_data ); |
| 41 | WRITE8_DEVICE_HANDLER( ds1315_w_data ); |
| 42 | |
| 43 | #endif /* __DS1315_H__ */ |