src/emu/machine/rp5c01.c
| r11208 | r11209 | |
| 168 | 168 | //************************************************************************** |
| 169 | 169 | |
| 170 | 170 | //------------------------------------------------- |
| 171 | // set_alarm_line - |
| 172 | //------------------------------------------------- |
| 173 | |
| 174 | inline void rp5c01_device::set_alarm_line() |
| 175 | { |
| 176 | int alarm = ((m_mode & MODE_ALARM_EN) ? m_alarm_on : 1) & |
| 177 | ((m_reset & RESET_16_HZ) ? 1 : m_16hz) & |
| 178 | ((m_reset & RESET_1_HZ) ? 1 : m_1hz); |
| 179 | |
| 180 | if (m_alarm != alarm) |
| 181 | { |
| 182 | if (LOG) logerror("RP5C01 '%s' Alarm %u\n", tag(), alarm); |
| 183 | |
| 184 | devcb_call_write_line(&m_out_alarm_func, alarm); |
| 185 | m_alarm = alarm; |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | |
| 190 | //------------------------------------------------- |
| 171 | 191 | // read_counter - |
| 172 | 192 | //------------------------------------------------- |
| 173 | 193 | |
| r11208 | r11209 | |
| 206 | 226 | } |
| 207 | 227 | |
| 208 | 228 | write_counter(REGISTER_1_SECOND, seconds); |
| 209 | | |
| 210 | | if (!(m_mode & RESET_1_HZ)) |
| 211 | | { |
| 212 | | // pulse 1Hz alarm signal |
| 213 | | trigger_alarm(); |
| 214 | | } |
| 215 | 229 | } |
| 216 | 230 | |
| 217 | 231 | |
| r11208 | r11209 | |
| 275 | 289 | m_reg[MODE00][REGISTER_DAY_OF_THE_WEEK] = day_of_week; |
| 276 | 290 | |
| 277 | 291 | check_alarm(); |
| 292 | set_alarm_line(); |
| 278 | 293 | } |
| 279 | 294 | |
| 280 | 295 | |
| r11208 | r11209 | |
| 284 | 299 | |
| 285 | 300 | inline void rp5c01_device::check_alarm() |
| 286 | 301 | { |
| 287 | | if (m_mode & MODE_ALARM_EN) |
| 302 | bool all_match = true; |
| 303 | bool all_zeroes = true; |
| 304 | |
| 305 | for (int i = REGISTER_1_MINUTE; i < REGISTER_1_MONTH; i++) |
| 288 | 306 | { |
| 289 | | for (int i = REGISTER_1_MINUTE; i < REGISTER_1_MONTH; i++) |
| 290 | | { |
| 291 | | if (m_reg[MODE01][i] != m_reg[MODE00][i]) return; |
| 292 | | } |
| 293 | | |
| 294 | | trigger_alarm(); |
| 307 | if (m_reg[MODE01][i] != 0) all_zeroes = false; |
| 308 | if (m_reg[MODE01][i] != m_reg[MODE00][i]) all_match = false; |
| 295 | 309 | } |
| 296 | | } |
| 297 | 310 | |
| 298 | | |
| 299 | | //------------------------------------------------- |
| 300 | | // trigger_alarm - |
| 301 | | //------------------------------------------------- |
| 302 | | |
| 303 | | inline void rp5c01_device::trigger_alarm() |
| 304 | | { |
| 305 | | devcb_call_write_line(&m_out_alarm_func, 0); |
| 306 | | devcb_call_write_line(&m_out_alarm_func, 1); |
| 311 | m_alarm_on = (all_match || (!m_alarm_on && all_zeroes)) ? 0 : 1; |
| 307 | 312 | } |
| 308 | 313 | |
| 309 | 314 | |
| r11208 | r11209 | |
| 319 | 324 | rp5c01_device::rp5c01_device(running_machine &_machine, const rp5c01_device_config &config) |
| 320 | 325 | : device_t(_machine, config), |
| 321 | 326 | device_nvram_interface(_machine, config, *this), |
| 327 | m_alarm(1), |
| 328 | m_alarm_on(1), |
| 329 | m_1hz(1), |
| 330 | m_16hz(1), |
| 322 | 331 | m_config(config) |
| 323 | 332 | { |
| 324 | 333 | } |
| r11208 | r11209 | |
| 335 | 344 | |
| 336 | 345 | // allocate timers |
| 337 | 346 | m_clock_timer = timer_alloc(TIMER_CLOCK); |
| 338 | | m_clock_timer->adjust(attotime::from_hz(clock() / 32768), 0, attotime::from_hz(clock() / 32768)); |
| 347 | m_clock_timer->adjust(attotime::from_hz(clock() / 16384), 0, attotime::from_hz(clock() / 16384)); |
| 339 | 348 | |
| 340 | | m_alarm_timer = timer_alloc(TIMER_ALARM); |
| 341 | | m_alarm_timer->adjust(attotime::from_hz(clock() / 2048), 0, attotime::from_hz(clock() / 2048)); |
| 349 | m_16hz_timer = timer_alloc(TIMER_16HZ); |
| 350 | m_16hz_timer->adjust(attotime::from_hz(clock() / 1024), 0, attotime::from_hz(clock() / 1024)); |
| 342 | 351 | |
| 343 | 352 | // state saving |
| 344 | 353 | save_item(NAME(m_reg[MODE00])); |
| 345 | 354 | save_item(NAME(m_reg[MODE01])); |
| 346 | 355 | save_item(NAME(m_mode)); |
| 347 | 356 | save_item(NAME(m_reset)); |
| 357 | save_item(NAME(m_alarm)); |
| 358 | save_item(NAME(m_alarm_on)); |
| 359 | save_item(NAME(m_1hz)); |
| 360 | save_item(NAME(m_16hz)); |
| 348 | 361 | } |
| 349 | 362 | |
| 350 | 363 | |
| r11208 | r11209 | |
| 357 | 370 | switch (id) |
| 358 | 371 | { |
| 359 | 372 | case TIMER_CLOCK: |
| 360 | | advance_seconds(); |
| 361 | | break; |
| 362 | | |
| 363 | | case TIMER_ALARM: |
| 364 | | if (!(m_reset & RESET_16_HZ)) |
| 373 | if (m_1hz && (m_mode & MODE_TIMER_EN)) |
| 365 | 374 | { |
| 366 | | trigger_alarm(); |
| 375 | advance_seconds(); |
| 367 | 376 | } |
| 377 | |
| 378 | m_1hz = !m_1hz; |
| 379 | set_alarm_line(); |
| 368 | 380 | break; |
| 381 | |
| 382 | case TIMER_16HZ: |
| 383 | m_16hz = !m_16hz; |
| 384 | set_alarm_line(); |
| 385 | break; |
| 369 | 386 | } |
| 370 | 387 | } |
| 371 | 388 | |
| r11208 | r11209 | |
| 449 | 466 | break; |
| 450 | 467 | } |
| 451 | 468 | |
| 452 | | return data; |
| 469 | if (LOG) logerror("RP5C01 '%s' Register %u Read %02x\n", tag(), offset & 0x0f, data); |
| 470 | |
| 471 | return data & 0x0f; |
| 453 | 472 | } |
| 454 | 473 | |
| 455 | 474 | |
| r11208 | r11209 | |
| 464 | 483 | switch (offset & 0x0f) |
| 465 | 484 | { |
| 466 | 485 | case REGISTER_MODE: |
| 467 | | m_mode = data; |
| 486 | m_mode = data & 0x0f; |
| 468 | 487 | |
| 469 | | m_clock_timer->enable(data & MODE_TIMER_EN); |
| 470 | | |
| 471 | 488 | if (LOG) |
| 472 | 489 | { |
| 473 | 490 | logerror("RP5C01 '%s' Mode %u\n", tag(), data & MODE_MASK); |
| r11208 | r11209 | |
| 481 | 498 | break; |
| 482 | 499 | |
| 483 | 500 | case REGISTER_RESET: |
| 484 | | m_reset = data; |
| 501 | m_reset = data & 0x0f; |
| 485 | 502 | |
| 486 | 503 | if (data & RESET_ALARM) |
| 487 | 504 | { |
src/mess/machine/tc8521.c
| r11208 | r11209 | |
| 1 | | /********************************************************************* |
| 2 | | |
| 3 | | tc8521.h |
| 4 | | |
| 5 | | Toshiba TC8251 Real Time Clock code |
| 6 | | |
| 7 | | (or RICOH RF5C01A) |
| 8 | | |
| 9 | | Registers: |
| 10 | | |
| 11 | | Page 0/Mode 0 (timer): |
| 12 | | |
| 13 | | 0x00: 1-second counter |
| 14 | | 0x01: 10-second counter |
| 15 | | 0x02: 1-minute counter |
| 16 | | 0x03: 10-minute counter |
| 17 | | 0x04: 1-hour counter |
| 18 | | 0x05: 10-hour counter |
| 19 | | 0x06: day-of-the-week counter |
| 20 | | 0x07: 1-day counter |
| 21 | | 0x08: 10-day counter |
| 22 | | 0x09: 1-month counter |
| 23 | | 0x0A: 10-month counter |
| 24 | | 0x0b: 1-year counter |
| 25 | | 0x0c: 10-year counter |
| 26 | | |
| 27 | | Page 1/Mode 1 (alarm): |
| 28 | | 0x00: unused |
| 29 | | 0x01: unused |
| 30 | | 0x02: 1-minute alarm |
| 31 | | 0x03: 10-minute alarm |
| 32 | | 0x04: 1-hour alarm |
| 33 | | 0x05: 10-hour alarm |
| 34 | | 0x06: day-of-the-week alarm |
| 35 | | 0x07: 1-day alarm |
| 36 | | 0x08: 10-day alarm |
| 37 | | 0x09: unused |
| 38 | | 0x0a: 12/24 hour select register |
| 39 | | 0x0b: leap year counter |
| 40 | | 0x0c: unused |
| 41 | | |
| 42 | | Page 2/Mode 2 (ram block 1) and |
| 43 | | Page 3/Mode 3 (ram block 2): |
| 44 | | 0x00: ram |
| 45 | | 0x01: ram |
| 46 | | 0x02: ram |
| 47 | | 0x03: ram |
| 48 | | 0x04: ram |
| 49 | | 0x05: ram |
| 50 | | 0x06: ram |
| 51 | | 0x07: ram |
| 52 | | 0x08: ram |
| 53 | | 0x09: ram |
| 54 | | 0x0a: ram |
| 55 | | 0x0b: ram |
| 56 | | 0x0c: ram |
| 57 | | |
| 58 | | |
| 59 | | registers common to all modes: |
| 60 | | |
| 61 | | 0x0d: MODE register |
| 62 | | bit 3: timer enable |
| 63 | | bit 2: alarm enable |
| 64 | | bit 1,0: mode/page select |
| 65 | | 0x0e: test register |
| 66 | | bit 3: test 3 |
| 67 | | bit 2: test 2 |
| 68 | | bit 1: test 1 |
| 69 | | bit 0: test 0 |
| 70 | | 0x0f: RESET etc |
| 71 | | bit 3: 1 Hz enable |
| 72 | | bit 2: 16 Hz enable |
| 73 | | bit 1: timer reset |
| 74 | | bit 0: alarm reset |
| 75 | | |
| 76 | | *********************************************************************/ |
| 77 | | |
| 78 | | #include "emu.h" |
| 79 | | #include "tc8521.h" |
| 80 | | |
| 81 | | |
| 82 | | /*************************************************************************** |
| 83 | | CONSTANTS |
| 84 | | ***************************************************************************/ |
| 85 | | |
| 86 | | #define TC8521_TIMER_1_SECOND_COUNTER 0x00 |
| 87 | | #define TC8521_TIMER_10_SECOND_COUNTER 0x01 |
| 88 | | #define TC8521_TIMER_1_MINUTE_COUNTER 0x02 |
| 89 | | #define TC8521_TIMER_10_MINUTE_COUNTER 0x03 |
| 90 | | #define TC8521_TIMER_1_HOUR_COUNTER 0x04 |
| 91 | | #define TC8521_TIMER_10_HOUR_COUNTER 0x05 |
| 92 | | #define TC8521_TIMER_DAY_OF_THE_WEEK_COUNTER 0x06 |
| 93 | | #define TC8521_TIMER_1_DAY_COUNTER 0x07 |
| 94 | | #define TC8521_TIMER_10_DAY_COUNTER 0x08 |
| 95 | | #define TC8521_TIMER_1_MONTH_COUNTER 0x09 |
| 96 | | #define TC8521_TIMER_10_MONTH_COUNTER 0x0a |
| 97 | | #define TC8521_TIMER_1_YEAR_COUNTER 0x0b |
| 98 | | #define TC8521_TIMER_10_YEAR_COUNTER 0x0c |
| 99 | | |
| 100 | | #define TC8521_MODE_REGISTER 0x0d |
| 101 | | #define TC8521_TEST_REGISTER 0x0e |
| 102 | | #define TC8521_RESET_REGISTER 0x0f |
| 103 | | |
| 104 | | #define TC8521_ALARM_1_MINUTE_REGISTER 0x012 |
| 105 | | #define TC8521_ALARM_10_MINUTE_REGISTER 0x013 |
| 106 | | #define TC8521_ALARM_1_HOUR_REGISTER 0x014 |
| 107 | | #define TC8521_ALARM_10_HOUR_REGISTER 0x015 |
| 108 | | #define TC8521_ALARM_DAY_OF_THE_WEEK_REGISTER 0x016 |
| 109 | | #define TC8521_ALARM_1_DAY_REGISTER 0x017 |
| 110 | | #define TC8521_ALARM_10_DAY_REGISTER 0x018 |
| 111 | | |
| 112 | | #define VERBOSE 0 |
| 113 | | #define LOG(x) do { if (VERBOSE) logerror x; } while (0) |
| 114 | | |
| 115 | | #define ALARM_OUTPUT_16HZ 0x01 |
| 116 | | #define ALARM_OUTPUT_1HZ 0x02 |
| 117 | | #define ALARM_OUTPUT_ALARM 0X04 |
| 118 | | |
| 119 | | |
| 120 | | /*************************************************************************** |
| 121 | | TYPE DEFINITIONS |
| 122 | | ***************************************************************************/ |
| 123 | | |
| 124 | | typedef struct _tc8521_t tc8521_t; |
| 125 | | struct _tc8521_t |
| 126 | | { |
| 127 | | /* 4 register pages (timer, alarm, ram1 and ram2) */ |
| 128 | | unsigned char registers[16*4]; |
| 129 | | UINT32 alarm_outputs; |
| 130 | | UINT32 thirty_two_hz_counter; |
| 131 | | }; |
| 132 | | |
| 133 | | |
| 134 | | /*************************************************************************** |
| 135 | | INLINE FUNCTIONS |
| 136 | | ***************************************************************************/ |
| 137 | | |
| 138 | | INLINE tc8521_t *get_token(device_t *device) |
| 139 | | { |
| 140 | | assert(device != NULL); |
| 141 | | assert(device->type() == TC8521); |
| 142 | | return (tc8521_t *) downcast<legacy_device_base *>(device)->token(); |
| 143 | | } |
| 144 | | |
| 145 | | |
| 146 | | INLINE const tc8521_interface *get_interface(device_t *device) |
| 147 | | { |
| 148 | | assert(device != NULL); |
| 149 | | assert(device->type() == TC8521); |
| 150 | | return (tc8521_interface *) device->baseconfig().static_config(); |
| 151 | | } |
| 152 | | |
| 153 | | |
| 154 | | /*************************************************************************** |
| 155 | | GLOBAL VARIABLES |
| 156 | | ***************************************************************************/ |
| 157 | | |
| 158 | | const tc8521_interface default_tc8521_interface = {0, }; |
| 159 | | |
| 160 | | |
| 161 | | /*************************************************************************** |
| 162 | | LOCAL VARIABLES |
| 163 | | ***************************************************************************/ |
| 164 | | |
| 165 | | /* mask data with these values when writing */ |
| 166 | | static const UINT8 rtc_write_masks[16*4]= |
| 167 | | { |
| 168 | | 0x0f,0x07,0x0f,0x07,0x0f,0x03,0x07,0x0f,0x03,0x0f,0x03,0x0f,0x0f,0x0f, 0x0f, 0x0f, |
| 169 | | 0x00,0x00,0x0f,0x07,0x0f,0x03,0x07,0x0f,0x03,0x00,0x01,0x03,0x00,0x0f, 0x0f, 0x0f, |
| 170 | | 0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f, 0x0f, 0x0f, |
| 171 | | 0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f, 0x0f, 0x0f, |
| 172 | | }; |
| 173 | | |
| 174 | | |
| 175 | | |
| 176 | | /*************************************************************************** |
| 177 | | IMPLEMENTATION |
| 178 | | ***************************************************************************/ |
| 179 | | |
| 180 | | /*------------------------------------------------- |
| 181 | | tc8521_load_stream - read tc8521 data from |
| 182 | | supplied file |
| 183 | | -------------------------------------------------*/ |
| 184 | | |
| 185 | | void tc8521_load_stream(device_t *device, emu_file *file) |
| 186 | | { |
| 187 | | tc8521_t *rtc = get_token(device); |
| 188 | | |
| 189 | | if (file) |
| 190 | | { |
| 191 | | file->read(&rtc->registers[0], sizeof(unsigned char)*16*4); |
| 192 | | file->read(&rtc->alarm_outputs, sizeof(UINT32)); |
| 193 | | file->read(&rtc->thirty_two_hz_counter, sizeof(UINT32)); |
| 194 | | } |
| 195 | | } |
| 196 | | |
| 197 | | |
| 198 | | |
| 199 | | /*------------------------------------------------- |
| 200 | | tc8521_save_stream - write tc8521 data to |
| 201 | | supplied file |
| 202 | | -------------------------------------------------*/ |
| 203 | | |
| 204 | | void tc8521_save_stream(device_t *device, emu_file *file) |
| 205 | | { |
| 206 | | tc8521_t *rtc = get_token(device); |
| 207 | | |
| 208 | | if (file) |
| 209 | | { |
| 210 | | file->write(&rtc->registers[0], sizeof(unsigned char)*16*4); |
| 211 | | file->write(&rtc->alarm_outputs, sizeof(UINT32)); |
| 212 | | file->write(&rtc->thirty_two_hz_counter, sizeof(UINT32)); |
| 213 | | } |
| 214 | | } |
| 215 | | |
| 216 | | |
| 217 | | |
| 218 | | /*------------------------------------------------- |
| 219 | | tc8521_set_alarm_output |
| 220 | | -------------------------------------------------*/ |
| 221 | | |
| 222 | | static void tc8521_set_alarm_output(device_t *device) |
| 223 | | { |
| 224 | | tc8521_t *rtc = get_token(device); |
| 225 | | const tc8521_interface *rtc_interface = get_interface(device); |
| 226 | | unsigned char alarm_output; |
| 227 | | |
| 228 | | alarm_output = 0; |
| 229 | | |
| 230 | | /* what happens when all are enabled? I assume they are all or'd together */ |
| 231 | | |
| 232 | | /* 16 Hz enabled? */ |
| 233 | | if ((rtc->registers[TC8521_RESET_REGISTER] & (1<<2))==0) |
| 234 | | { |
| 235 | | /* yes */ |
| 236 | | |
| 237 | | /* add in state of 16 Hz output */ |
| 238 | | alarm_output |= (rtc->alarm_outputs & ALARM_OUTPUT_16HZ); |
| 239 | | } |
| 240 | | |
| 241 | | if ((rtc->registers[TC8521_RESET_REGISTER] & (1<<3))==0) |
| 242 | | { |
| 243 | | /* yes */ |
| 244 | | /* add in stat of 1 Hz output */ |
| 245 | | alarm_output |= ((rtc->alarm_outputs & ALARM_OUTPUT_1HZ)>>1); |
| 246 | | } |
| 247 | | |
| 248 | | alarm_output |= ((rtc->alarm_outputs & ALARM_OUTPUT_ALARM)>>2); |
| 249 | | |
| 250 | | /* if it's not enabled, then there is no output */ |
| 251 | | if (!((rtc->registers[TC8521_MODE_REGISTER] & (1<<2))!=0)) |
| 252 | | { |
| 253 | | /* alarm output enabled? */ |
| 254 | | alarm_output &= ~1; |
| 255 | | } |
| 256 | | |
| 257 | | if (rtc_interface->alarm_output_callback != NULL) |
| 258 | | { |
| 259 | | (*rtc_interface->alarm_output_callback)(device, alarm_output); |
| 260 | | } |
| 261 | | } |
| 262 | | |
| 263 | | |
| 264 | | |
| 265 | | /*------------------------------------------------- |
| 266 | | tc8521_alarm_check |
| 267 | | -------------------------------------------------*/ |
| 268 | | |
| 269 | | static void tc8521_alarm_check(device_t *device) |
| 270 | | { |
| 271 | | tc8521_t *rtc = get_token(device); |
| 272 | | |
| 273 | | rtc->alarm_outputs &= ~ALARM_OUTPUT_ALARM; |
| 274 | | if ( |
| 275 | | (rtc->registers[TC8521_TIMER_1_MINUTE_COUNTER]==rtc->registers[TC8521_ALARM_1_MINUTE_REGISTER]) && |
| 276 | | (rtc->registers[TC8521_TIMER_10_MINUTE_COUNTER]==rtc->registers[TC8521_ALARM_10_MINUTE_REGISTER]) && |
| 277 | | (rtc->registers[TC8521_TIMER_1_HOUR_COUNTER]==rtc->registers[TC8521_ALARM_1_HOUR_REGISTER]) && |
| 278 | | (rtc->registers[TC8521_TIMER_10_HOUR_COUNTER]==rtc->registers[TC8521_ALARM_10_HOUR_REGISTER]) && |
| 279 | | (rtc->registers[TC8521_TIMER_1_DAY_COUNTER]==rtc->registers[TC8521_ALARM_1_DAY_REGISTER]) && |
| 280 | | (rtc->registers[TC8521_TIMER_10_DAY_COUNTER]==rtc->registers[TC8521_ALARM_10_DAY_REGISTER]) && |
| 281 | | (rtc->registers[TC8521_TIMER_DAY_OF_THE_WEEK_COUNTER]==rtc->registers[TC8521_ALARM_DAY_OF_THE_WEEK_REGISTER]) |
| 282 | | ) |
| 283 | | { |
| 284 | | rtc->alarm_outputs |= ALARM_OUTPUT_ALARM; |
| 285 | | } |
| 286 | | |
| 287 | | tc8521_set_alarm_output(device); |
| 288 | | } |
| 289 | | |
| 290 | | |
| 291 | | |
| 292 | | /*------------------------------------------------- |
| 293 | | tc8521_timer_callback |
| 294 | | -------------------------------------------------*/ |
| 295 | | |
| 296 | | static TIMER_CALLBACK(tc8521_timer_callback) |
| 297 | | { |
| 298 | | device_t *device = (device_t *)ptr; |
| 299 | | tc8521_t *rtc = get_token(device); |
| 300 | | |
| 301 | | /* Assumption how it works */ |
| 302 | | /* 16 Hz output = 16 cycles per second, 16 cycles of high-low from counter */ |
| 303 | | |
| 304 | | /* toggle 16 Hz wave state */ |
| 305 | | rtc->alarm_outputs ^= ALARM_OUTPUT_16HZ; |
| 306 | | /* set in alarm output */ |
| 307 | | tc8521_set_alarm_output(device); |
| 308 | | |
| 309 | | rtc->thirty_two_hz_counter++; |
| 310 | | |
| 311 | | if (rtc->thirty_two_hz_counter==16) |
| 312 | | { |
| 313 | | rtc->thirty_two_hz_counter = 0; |
| 314 | | |
| 315 | | /* toggle 1 Hz output */ |
| 316 | | rtc->alarm_outputs ^= ALARM_OUTPUT_1HZ; |
| 317 | | /* set in alarm output */ |
| 318 | | tc8521_set_alarm_output(device); |
| 319 | | |
| 320 | | if ((rtc->alarm_outputs & ALARM_OUTPUT_1HZ)==0) |
| 321 | | { |
| 322 | | /* timer enable? */ |
| 323 | | if ((rtc->registers[0x0d] & (1<<3))!=0) |
| 324 | | { |
| 325 | | /* seconds; units */ |
| 326 | | rtc->registers[0]++; |
| 327 | | |
| 328 | | if (rtc->registers[0]==10) |
| 329 | | { |
| 330 | | rtc->registers[0] = 0; |
| 331 | | |
| 332 | | /* seconds; tens */ |
| 333 | | rtc->registers[1]++; |
| 334 | | |
| 335 | | if (rtc->registers[1]==6) |
| 336 | | { |
| 337 | | rtc->registers[1] = 0; |
| 338 | | |
| 339 | | /* minutes; units */ |
| 340 | | rtc->registers[2]++; |
| 341 | | |
| 342 | | if (rtc->registers[2]==10) |
| 343 | | { |
| 344 | | rtc->registers[2] = 0; |
| 345 | | |
| 346 | | /* minutes; tens */ |
| 347 | | rtc->registers[3]++; |
| 348 | | |
| 349 | | if (rtc->registers[3] == 6) |
| 350 | | { |
| 351 | | rtc->registers[3] = 0; |
| 352 | | |
| 353 | | /* hours; units */ |
| 354 | | rtc->registers[4]++; |
| 355 | | |
| 356 | | if (rtc->registers[4] == 10) |
| 357 | | { |
| 358 | | rtc->registers[4] = 0; |
| 359 | | |
| 360 | | /* hours; tens */ |
| 361 | | rtc->registers[4]++; |
| 362 | | |
| 363 | | if (rtc->registers[4] == 24) |
| 364 | | { |
| 365 | | /* TODO: finish rest of increments here! */ |
| 366 | | rtc->registers[4] = 0; |
| 367 | | } |
| 368 | | } |
| 369 | | } |
| 370 | | } |
| 371 | | |
| 372 | | tc8521_alarm_check(device); |
| 373 | | } |
| 374 | | } |
| 375 | | } |
| 376 | | } |
| 377 | | } |
| 378 | | } |
| 379 | | |
| 380 | | |
| 381 | | |
| 382 | | /*------------------------------------------------- |
| 383 | | DEVICE_START( tc8521 ) |
| 384 | | -------------------------------------------------*/ |
| 385 | | |
| 386 | | static DEVICE_START( tc8521 ) |
| 387 | | { |
| 388 | | tc8521_t *rtc = get_token(device); |
| 389 | | memset(rtc, 0, sizeof(*rtc)); |
| 390 | | device->machine().scheduler().timer_pulse(attotime::from_hz(32), FUNC(tc8521_timer_callback), 0, (void *) device); |
| 391 | | } |
| 392 | | |
| 393 | | |
| 394 | | |
| 395 | | /*------------------------------------------------- |
| 396 | | tc8521_r |
| 397 | | -------------------------------------------------*/ |
| 398 | | |
| 399 | | READ8_DEVICE_HANDLER(tc8521_r) |
| 400 | | { |
| 401 | | tc8521_t *rtc = get_token(device); |
| 402 | | UINT32 register_index; |
| 403 | | |
| 404 | | switch (offset) |
| 405 | | { |
| 406 | | /* control registers */ |
| 407 | | case 0x0d: |
| 408 | | case 0x0e: |
| 409 | | case 0x0f: |
| 410 | | LOG(("8521 RTC R: %04x %02x\n", offset, rtc->registers[offset])); |
| 411 | | return rtc->registers[offset]; |
| 412 | | |
| 413 | | default: |
| 414 | | break; |
| 415 | | } |
| 416 | | |
| 417 | | /* register in selected page */ |
| 418 | | register_index = ((rtc->registers[TC8521_MODE_REGISTER] & 0x03)<<4) | (offset & 0x0f); |
| 419 | | LOG(("8521 RTC R: %04x %02x\n", offset, rtc->registers[register_index])); |
| 420 | | /* data from selected page */ |
| 421 | | return rtc->registers[register_index]; |
| 422 | | } |
| 423 | | |
| 424 | | |
| 425 | | |
| 426 | | /*------------------------------------------------- |
| 427 | | tc8521_w |
| 428 | | -------------------------------------------------*/ |
| 429 | | |
| 430 | | WRITE8_DEVICE_HANDLER(tc8521_w) |
| 431 | | { |
| 432 | | tc8521_t *rtc = get_token(device); |
| 433 | | UINT32 register_index; |
| 434 | | |
| 435 | | LOG(("8521 RTC W: %04x %02x\n", offset, data)); |
| 436 | | |
| 437 | | switch (offset) |
| 438 | | { |
| 439 | | case 0x0D: |
| 440 | | { |
| 441 | | if (data & 0x08) |
| 442 | | { |
| 443 | | LOG(("timer enable\n")); |
| 444 | | } |
| 445 | | |
| 446 | | if (data & 0x04) |
| 447 | | { |
| 448 | | LOG(("alarm enable\n")); |
| 449 | | } |
| 450 | | |
| 451 | | logerror("page %02x selected\n", data & 0x03); |
| 452 | | } |
| 453 | | break; |
| 454 | | |
| 455 | | case 0x0e: |
| 456 | | { |
| 457 | | if (data & 0x08) |
| 458 | | { |
| 459 | | LOG(("test 3\n")); |
| 460 | | } |
| 461 | | |
| 462 | | if (data & 0x04) |
| 463 | | { |
| 464 | | LOG(("test 2\n")); |
| 465 | | } |
| 466 | | |
| 467 | | if (data & 0x02) |
| 468 | | { |
| 469 | | LOG(("test 1\n")); |
| 470 | | } |
| 471 | | |
| 472 | | if (data & 0x01) |
| 473 | | { |
| 474 | | LOG(("test 0\n")); |
| 475 | | } |
| 476 | | } |
| 477 | | break; |
| 478 | | |
| 479 | | case 0x0f: |
| 480 | | { |
| 481 | | if ((data & 0x08)==0) |
| 482 | | { |
| 483 | | LOG(("1 Hz enable\n")); |
| 484 | | } |
| 485 | | |
| 486 | | if ((data & 0x04)==0) |
| 487 | | { |
| 488 | | LOG(("16 Hz enable\n")); |
| 489 | | } |
| 490 | | |
| 491 | | if (data & 0x02) |
| 492 | | { |
| 493 | | LOG(("reset timer\n")); |
| 494 | | } |
| 495 | | |
| 496 | | if (data & 0x01) |
| 497 | | { |
| 498 | | LOG(("reset alarm\n")); |
| 499 | | } |
| 500 | | } |
| 501 | | break; |
| 502 | | |
| 503 | | default: |
| 504 | | break; |
| 505 | | } |
| 506 | | |
| 507 | | switch (offset) |
| 508 | | { |
| 509 | | /* control registers */ |
| 510 | | case 0x0d: |
| 511 | | case 0x0e: |
| 512 | | case 0x0f: |
| 513 | | rtc->registers[offset] = data & rtc_write_masks[offset]; |
| 514 | | return; |
| 515 | | default: |
| 516 | | break; |
| 517 | | } |
| 518 | | |
| 519 | | /* register in selected page */ |
| 520 | | register_index = ((rtc->registers[TC8521_MODE_REGISTER] & 0x03)<<4) | (offset & 0x0f); |
| 521 | | |
| 522 | | /* write and mask data */ |
| 523 | | rtc->registers[register_index] = data & rtc_write_masks[register_index]; |
| 524 | | } |
| 525 | | |
| 526 | | |
| 527 | | |
| 528 | | /*------------------------------------------------- |
| 529 | | DEVICE_GET_INFO( tc8521 ) |
| 530 | | -------------------------------------------------*/ |
| 531 | | |
| 532 | | DEVICE_GET_INFO( tc8521 ) |
| 533 | | { |
| 534 | | switch (state) |
| 535 | | { |
| 536 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 537 | | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(tc8521_t); break; |
| 538 | | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 539 | | |
| 540 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 541 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(tc8521); break; |
| 542 | | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 543 | | case DEVINFO_FCT_RESET: /* Nothing */ break; |
| 544 | | |
| 545 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 546 | | case DEVINFO_STR_NAME: strcpy(info->s, "Toshiba 8521 RTC"); break; |
| 547 | | case DEVINFO_STR_FAMILY: strcpy(info->s, "Toshiba 8521 RTC"); break; |
| 548 | | case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 549 | | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 550 | | case DEVINFO_STR_CREDITS: /* Nothing */ break; |
| 551 | | } |
| 552 | | } |
| 553 | | |
| 554 | | DEFINE_LEGACY_DEVICE(TC8521, tc8521); |
src/mess/drivers/nc.c
| r11208 | r11209 | |
| 101 | 101 | #include "machine/ctronics.h" |
| 102 | 102 | #include "machine/msm8251.h" /* for NC100 uart */ |
| 103 | 103 | #include "machine/mc146818.h" /* for NC200 real time clock */ |
| 104 | | #include "machine/tc8521.h" /* for NC100 real time clock */ |
| 104 | #include "machine/rp5c01.h" /* for NC100 real time clock */ |
| 105 | 105 | #include "machine/upd765.h" /* for NC200 disk drive interface */ |
| 106 | 106 | #include "imagedev/flopdrv.h" /* for NC200 disk image */ |
| 107 | 107 | #include "formats/pc_dsk.h" /* for NC200 disk image */ |
| r11208 | r11209 | |
| 466 | 466 | nc_state *state = machine.driver_data<nc_state>(); |
| 467 | 467 | char filename[MAX_DRIVER_NAME_CHARS + 5]; |
| 468 | 468 | |
| 469 | | sprintf(filename,"%s.nv", machine.system().name); |
| 469 | sprintf(filename,"%s.hack", machine.system().name); |
| 470 | 470 | |
| 471 | 471 | state->m_file = global_alloc(emu_file(machine.options().memcard_directory(), OPEN_FLAG_WRITE)); |
| 472 | 472 | state->m_file->open(filename); |
| r11208 | r11209 | |
| 477 | 477 | nc_state *state = machine.driver_data<nc_state>(); |
| 478 | 478 | char filename[MAX_DRIVER_NAME_CHARS + 5]; |
| 479 | 479 | |
| 480 | | sprintf(filename,"%s.nv", machine.system().name); |
| 480 | sprintf(filename,"%s.hack", machine.system().name); |
| 481 | 481 | |
| 482 | 482 | state->m_file = global_alloc(emu_file(machine.options().memcard_directory(), OPEN_FLAG_WRITE)); |
| 483 | 483 | state->m_file->open(filename); |
| r11208 | r11209 | |
| 850 | 850 | } |
| 851 | 851 | |
| 852 | 852 | |
| 853 | | static void nc100_tc8521_alarm_callback(device_t *device, int state) |
| 853 | static WRITE_LINE_DEVICE_HANDLER(nc100_tc8521_alarm_callback) |
| 854 | 854 | { |
| 855 | | nc_state *drvstate = device->machine().driver_data<nc_state>(); |
| 856 | | /* I'm assuming that the nmi is edge triggered */ |
| 857 | | /* a interrupt from the fdc will cause a change in line state, and |
| 858 | | the nmi will be triggered, but when the state changes because the int |
| 859 | | is cleared this will not cause another nmi */ |
| 860 | | /* I'll emulate it like this to be sure */ |
| 861 | | |
| 862 | | if (state != drvstate->m_previous_alarm_state) |
| 863 | | { |
| 864 | | if (state) |
| 865 | | { |
| 866 | | /* I'll pulse it because if I used hold-line I'm not sure |
| 867 | | it would clear - to be checked */ |
| 868 | | cputag_set_input_line(device->machine(), "maincpu", INPUT_LINE_NMI, PULSE_LINE); |
| 869 | | } |
| 870 | | } |
| 871 | | |
| 872 | | drvstate->m_previous_alarm_state = state; |
| 855 | // TODO |
| 873 | 856 | } |
| 874 | 857 | |
| 875 | 858 | static WRITE_LINE_DEVICE_HANDLER( nc100_txrdy_callback ) |
| r11208 | r11209 | |
| 908 | 891 | } |
| 909 | 892 | |
| 910 | 893 | |
| 911 | | static const tc8521_interface nc100_tc8521_interface = |
| 894 | static RP5C01_INTERFACE( rtc_intf ) |
| 912 | 895 | { |
| 913 | | nc100_tc8521_alarm_callback, |
| 896 | DEVCB_LINE(nc100_tc8521_alarm_callback) |
| 914 | 897 | }; |
| 915 | 898 | |
| 916 | 899 | static const msm8251_interface nc100_uart_interface = |
| r11208 | r11209 | |
| 961 | 944 | nc_common_init_machine(machine); |
| 962 | 945 | |
| 963 | 946 | nc_common_open_stream_for_reading(machine); |
| 964 | | |
| 965 | | { |
| 966 | | device_t *rtc = machine.device("rtc"); |
| 967 | | tc8521_load_stream(rtc, state->m_file); |
| 968 | | } |
| 969 | | |
| 970 | 947 | nc_common_restore_memory_from_stream(machine); |
| 971 | | |
| 972 | 948 | nc_common_close_stream(machine); |
| 973 | 949 | |
| 974 | 950 | /* serial */ |
| r11208 | r11209 | |
| 977 | 953 | |
| 978 | 954 | static void nc100_machine_stop(running_machine &machine) |
| 979 | 955 | { |
| 980 | | nc_state *state = machine.driver_data<nc_state>(); |
| 981 | 956 | nc_common_open_stream_for_writing(machine); |
| 982 | | { |
| 983 | | device_t *rtc = machine.device("rtc"); |
| 984 | | tc8521_save_stream(rtc, state->m_file); |
| 985 | | } |
| 986 | 957 | nc_common_store_memory_to_stream(machine); |
| 987 | 958 | nc_common_close_stream(machine); |
| 988 | 959 | } |
| r11208 | r11209 | |
| 1068 | 1039 | AM_RANGE(0xb0, 0xb9) AM_READ(nc_key_data_in_r) |
| 1069 | 1040 | AM_RANGE(0xc0, 0xc0) AM_DEVREADWRITE("uart", msm8251_data_r, msm8251_data_w) |
| 1070 | 1041 | AM_RANGE(0xc1, 0xc1) AM_DEVREADWRITE("uart", msm8251_status_r, msm8251_control_w) |
| 1071 | | AM_RANGE(0xd0, 0xdf) AM_DEVREADWRITE("rtc", tc8521_r, tc8521_w) |
| 1042 | AM_RANGE(0xd0, 0xdf) AM_DEVREADWRITE_MODERN("rtc", rp5c01_device, read, write) |
| 1072 | 1043 | ADDRESS_MAP_END |
| 1073 | 1044 | |
| 1074 | 1045 | |
| r11208 | r11209 | |
| 1641 | 1612 | PORT_DIPSETTING( 0x02, DEF_STR( On) ) |
| 1642 | 1613 | INPUT_PORTS_END |
| 1643 | 1614 | |
| 1644 | | |
| 1645 | | /* Serial */ |
| 1646 | | static DEVICE_IMAGE_LOAD( nc_serial ) |
| 1647 | | { |
| 1648 | | device_t *uart = image.device().machine().device("uart"); |
| 1649 | | |
| 1650 | | /* filename specified */ |
| 1651 | | if (device_load_serial(image)==IMAGE_INIT_PASS) |
| 1652 | | { |
| 1653 | | /* setup transmit parameters */ |
| 1654 | | serial_device_setup(&image.device(), 9600, 8, 1, SERIAL_PARITY_NONE); |
| 1655 | | |
| 1656 | | /* connect serial chip to serial device */ |
| 1657 | | msm8251_connect_to_serial_device(uart, &image.device()); |
| 1658 | | |
| 1659 | | /* and start transmit */ |
| 1660 | | serial_device_set_transmit_state(&image.device(),1); |
| 1661 | | |
| 1662 | | return IMAGE_INIT_PASS; |
| 1663 | | } |
| 1664 | | |
| 1665 | | return IMAGE_INIT_FAIL; |
| 1666 | | |
| 1667 | | } |
| 1668 | | |
| 1669 | | DEVICE_GET_INFO( nc_serial ) |
| 1670 | | { |
| 1671 | | switch ( state ) |
| 1672 | | { |
| 1673 | | case DEVINFO_FCT_IMAGE_LOAD: info->f = (genf *) DEVICE_IMAGE_LOAD_NAME( nc_serial ); break; |
| 1674 | | case DEVINFO_STR_NAME: strcpy(info->s, "NC serial port"); break; |
| 1675 | | case DEVINFO_STR_IMAGE_FILE_EXTENSIONS: strcpy(info->s, "txt"); break; |
| 1676 | | case DEVINFO_INT_IMAGE_READABLE: info->i = 1; break; |
| 1677 | | case DEVINFO_INT_IMAGE_WRITEABLE: info->i = 0; break; |
| 1678 | | case DEVINFO_INT_IMAGE_CREATABLE: info->i = 0; break; |
| 1679 | | default: DEVICE_GET_INFO_CALL(serial); break; |
| 1680 | | } |
| 1681 | | } |
| 1682 | | |
| 1683 | | DECLARE_LEGACY_IMAGE_DEVICE(NC_SERIAL, nc_serial); |
| 1684 | | DEFINE_LEGACY_IMAGE_DEVICE(NC_SERIAL, nc_serial); |
| 1685 | | |
| 1686 | | #define MCFG_NC_SERIAL_ADD(_tag) \ |
| 1687 | | MCFG_DEVICE_ADD(_tag, NC_SERIAL, 0) |
| 1688 | | |
| 1689 | 1615 | /**********************************************************************************************************/ |
| 1690 | 1616 | |
| 1691 | 1617 | static MACHINE_CONFIG_START( nc100, nc_state ) |
| r11208 | r11209 | |
| 1703 | 1629 | MCFG_SCREEN_REFRESH_RATE(50) |
| 1704 | 1630 | MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */ |
| 1705 | 1631 | MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) |
| 1706 | | MCFG_SCREEN_SIZE(640 /*NC_SCREEN_WIDTH*/, 480 /*NC_SCREEN_HEIGHT*/) |
| 1707 | | MCFG_SCREEN_VISIBLE_AREA(0, 640-1, 0, 480-1) |
| 1632 | MCFG_SCREEN_SIZE(480, 64) |
| 1633 | MCFG_SCREEN_VISIBLE_AREA(0, 480-1, 0, 64-1) |
| 1708 | 1634 | MCFG_SCREEN_UPDATE( nc ) |
| 1709 | 1635 | |
| 1710 | 1636 | MCFG_PALETTE_LENGTH(NC_NUM_COLOURS) |
| r11208 | r11209 | |
| 1727 | 1653 | MCFG_MSM8251_ADD("uart", nc100_uart_interface) |
| 1728 | 1654 | |
| 1729 | 1655 | /* rtc */ |
| 1730 | | MCFG_TC8521_ADD("rtc", nc100_tc8521_interface) |
| 1656 | MCFG_RP5C01_ADD("rtc", XTAL_32_768kHz, rtc_intf) |
| 1731 | 1657 | |
| 1732 | 1658 | /* cartridge */ |
| 1733 | 1659 | MCFG_CARTSLOT_ADD("cart") |
| r11208 | r11209 | |
| 1741 | 1667 | MCFG_RAM_ADD(RAM_TAG) |
| 1742 | 1668 | MCFG_RAM_DEFAULT_SIZE("64K") |
| 1743 | 1669 | |
| 1744 | | MCFG_NC_SERIAL_ADD("serial") |
| 1745 | | |
| 1746 | 1670 | /* dummy timer */ |
| 1747 | 1671 | MCFG_TIMER_ADD_PERIODIC("dummy_timer", dummy_timer_callback, attotime::from_hz(50)) |
| 1748 | 1672 | MACHINE_CONFIG_END |
| r11208 | r11209 | |
| 1826 | 1750 | /* YEAR NAME PARENT COMPAT MACHINE INPUT INIT COMPANY FULLNAME FLAGS */ |
| 1827 | 1751 | COMP( 1992, nc100, 0, 0, nc100, nc100, 0, "Amstrad plc", "NC100", 0 ) |
| 1828 | 1752 | COMP( 1992, nc150, nc100, 0, nc100, nc100, 0, "Amstrad plc", "NC150", 0 ) |
| 1829 | | COMP( 1993, nc200, 0, 0, nc200, nc200, 0, "Amstrad plc", "NC200", 0 ) |
| 1830 | | |
| 1753 | COMP( 1993, nc200, 0, 0, nc200, nc200, 0, "Amstrad plc", "NC200", GAME_NOT_WORKING ) // boot hangs while checking the MC146818 UIP (update in progress) bit |