src/emu/machine/rp5c15.c
| r0 | r11276 | |
| 1 | /********************************************************************** |
| 2 | |
| 3 | Ricoh RP5C15 Real Time Clock 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 hour clock |
| 15 | - test register |
| 16 | - timer reset |
| 17 | |
| 18 | */ |
| 19 | |
| 20 | #include "rp5c15.h" |
| 21 | |
| 22 | |
| 23 | |
| 24 | //************************************************************************** |
| 25 | // MACROS / CONSTANTS |
| 26 | //************************************************************************** |
| 27 | |
| 28 | #define LOG 0 |
| 29 | |
| 30 | |
| 31 | // registers |
| 32 | enum |
| 33 | { |
| 34 | REGISTER_1_SECOND = 0, REGISTER_CLOCK_OUTPUT = REGISTER_1_SECOND, |
| 35 | REGISTER_10_SECOND, REGISTER_ADJUST = REGISTER_10_SECOND, |
| 36 | REGISTER_1_MINUTE, |
| 37 | REGISTER_10_MINUTE, |
| 38 | REGISTER_1_HOUR, |
| 39 | REGISTER_10_HOUR, |
| 40 | REGISTER_DAY_OF_THE_WEEK, |
| 41 | REGISTER_1_DAY, |
| 42 | REGISTER_10_DAY, |
| 43 | REGISTER_1_MONTH, |
| 44 | REGISTER_10_MONTH, REGISTER_12_24_SELECT = REGISTER_10_MONTH, |
| 45 | REGISTER_1_YEAR, REGISTER_LEAP_YEAR = REGISTER_1_YEAR, |
| 46 | REGISTER_10_YEAR, |
| 47 | REGISTER_MODE, |
| 48 | REGISTER_TEST, |
| 49 | REGISTER_RESET |
| 50 | }; |
| 51 | |
| 52 | |
| 53 | // clock output select |
| 54 | enum |
| 55 | { |
| 56 | CLKOUT_Z = 0, |
| 57 | CLKOUT_16384_HZ, |
| 58 | CLKOUT_1024_HZ, |
| 59 | CLKOUT_128_HZ, |
| 60 | CLKOUT_16_HZ, |
| 61 | CLKOUT_1_HZ, |
| 62 | CLKOUT_1_DIV_60_HZ, |
| 63 | CLKOUT_L |
| 64 | }; |
| 65 | |
| 66 | |
| 67 | // register write mask |
| 68 | static const int REGISTER_WRITE_MASK[2][16] = |
| 69 | { |
| 70 | { 0xf, 0x7, 0xf, 0x7, 0xf, 0x3, 0x7, 0xf, 0x3, 0xf, 0x1, 0xf, 0xf, 0xf, 0xf, 0xf }, |
| 71 | { 0x3, 0x1, 0xf, 0x7, 0xf, 0x3, 0x7, 0xf, 0x3, 0x0, 0x1, 0x3, 0x0, 0xf, 0xf, 0xf } |
| 72 | }; |
| 73 | |
| 74 | |
| 75 | // days per month |
| 76 | static const int DAYS_PER_MONTH[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; |
| 77 | |
| 78 | |
| 79 | // modes |
| 80 | enum |
| 81 | { |
| 82 | MODE00 = 0, |
| 83 | MODE01 |
| 84 | }; |
| 85 | |
| 86 | |
| 87 | // mode register |
| 88 | #define MODE_TIMER_EN 0x08 |
| 89 | #define MODE_ALARM_EN 0x04 |
| 90 | #define MODE_MASK 0x01 |
| 91 | |
| 92 | |
| 93 | // test register |
| 94 | #define TEST_3 0x08 |
| 95 | #define TEST_2 0x04 |
| 96 | #define TEST_1 0x02 |
| 97 | #define TEST_0 0x01 |
| 98 | |
| 99 | |
| 100 | // reset register |
| 101 | #define RESET_ALARM 0x08 |
| 102 | #define RESET_TIMER 0x04 |
| 103 | #define RESET_16_HZ 0x02 |
| 104 | #define RESET_1_HZ 0x01 |
| 105 | |
| 106 | |
| 107 | |
| 108 | //************************************************************************** |
| 109 | // GLOBAL VARIABLES |
| 110 | //************************************************************************** |
| 111 | |
| 112 | // devices |
| 113 | const device_type RP5C15 = rp5c15_device_config::static_alloc_device_config; |
| 114 | |
| 115 | |
| 116 | |
| 117 | //************************************************************************** |
| 118 | // DEVICE CONFIGURATION |
| 119 | //************************************************************************** |
| 120 | |
| 121 | //------------------------------------------------- |
| 122 | // rp5c15_device_config - constructor |
| 123 | //------------------------------------------------- |
| 124 | |
| 125 | rp5c15_device_config::rp5c15_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 126 | : device_config(mconfig, static_alloc_device_config, "RP5C15", tag, owner, clock) |
| 127 | { |
| 128 | } |
| 129 | |
| 130 | |
| 131 | //------------------------------------------------- |
| 132 | // static_alloc_device_config - allocate a new |
| 133 | // configuration object |
| 134 | //------------------------------------------------- |
| 135 | |
| 136 | device_config *rp5c15_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 137 | { |
| 138 | return global_alloc(rp5c15_device_config(mconfig, tag, owner, clock)); |
| 139 | } |
| 140 | |
| 141 | |
| 142 | //------------------------------------------------- |
| 143 | // alloc_device - allocate a new device object |
| 144 | //------------------------------------------------- |
| 145 | |
| 146 | device_t *rp5c15_device_config::alloc_device(running_machine &machine) const |
| 147 | { |
| 148 | return auto_alloc(machine, rp5c15_device(machine, *this)); |
| 149 | } |
| 150 | |
| 151 | |
| 152 | //------------------------------------------------- |
| 153 | // device_config_complete - perform any |
| 154 | // operations now that the configuration is |
| 155 | // complete |
| 156 | //------------------------------------------------- |
| 157 | |
| 158 | void rp5c15_device_config::device_config_complete() |
| 159 | { |
| 160 | // inherit a copy of the static data |
| 161 | const rp5c15_interface *intf = reinterpret_cast<const rp5c15_interface *>(static_config()); |
| 162 | if (intf != NULL) |
| 163 | *static_cast<rp5c15_interface *>(this) = *intf; |
| 164 | |
| 165 | // or initialize to defaults if none provided |
| 166 | else |
| 167 | { |
| 168 | memset(&m_out_alarm_func, 0, sizeof(m_out_alarm_func)); |
| 169 | memset(&m_out_clkout_func, 0, sizeof(m_out_clkout_func)); |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | |
| 174 | |
| 175 | //************************************************************************** |
| 176 | // INLINE HELPERS |
| 177 | //************************************************************************** |
| 178 | |
| 179 | //------------------------------------------------- |
| 180 | // set_alarm_line - |
| 181 | //------------------------------------------------- |
| 182 | |
| 183 | inline void rp5c15_device::set_alarm_line() |
| 184 | { |
| 185 | int alarm = ((m_mode & MODE_ALARM_EN) ? m_alarm_on : 1) & |
| 186 | ((m_reset & RESET_16_HZ) ? 1 : m_16hz) & |
| 187 | ((m_reset & RESET_1_HZ) ? 1 : m_1hz); |
| 188 | |
| 189 | if (m_alarm != alarm) |
| 190 | { |
| 191 | if (LOG) logerror("RP5C15 '%s' Alarm %u\n", tag(), alarm); |
| 192 | |
| 193 | devcb_call_write_line(&m_out_alarm_func, alarm); |
| 194 | m_alarm = alarm; |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | |
| 199 | //------------------------------------------------- |
| 200 | // read_counter - |
| 201 | //------------------------------------------------- |
| 202 | |
| 203 | inline int rp5c15_device::read_counter(int counter) |
| 204 | { |
| 205 | return (m_reg[MODE00][counter + 1] * 10) + m_reg[MODE00][counter]; |
| 206 | } |
| 207 | |
| 208 | |
| 209 | //------------------------------------------------- |
| 210 | // write_counter - |
| 211 | //------------------------------------------------- |
| 212 | |
| 213 | inline void rp5c15_device::write_counter(int counter, int value) |
| 214 | { |
| 215 | m_reg[MODE00][counter] = value % 10; |
| 216 | m_reg[MODE00][counter + 1] = value / 10; |
| 217 | } |
| 218 | |
| 219 | |
| 220 | //------------------------------------------------- |
| 221 | // advance_seconds - |
| 222 | //------------------------------------------------- |
| 223 | |
| 224 | inline void rp5c15_device::advance_seconds() |
| 225 | { |
| 226 | int seconds = read_counter(REGISTER_1_SECOND); |
| 227 | |
| 228 | seconds++; |
| 229 | |
| 230 | if (seconds > 59) |
| 231 | { |
| 232 | seconds = 0; |
| 233 | |
| 234 | advance_minutes(); |
| 235 | } |
| 236 | |
| 237 | write_counter(REGISTER_1_SECOND, seconds); |
| 238 | } |
| 239 | |
| 240 | |
| 241 | //------------------------------------------------- |
| 242 | // advance_minutes - |
| 243 | //------------------------------------------------- |
| 244 | |
| 245 | inline void rp5c15_device::advance_minutes() |
| 246 | { |
| 247 | int minutes = read_counter(REGISTER_1_MINUTE); |
| 248 | int hours = read_counter(REGISTER_1_HOUR); |
| 249 | int days = read_counter(REGISTER_1_DAY); |
| 250 | int month = read_counter(REGISTER_1_MONTH); |
| 251 | int year = read_counter(REGISTER_1_YEAR); |
| 252 | int day_of_week = m_reg[MODE00][REGISTER_DAY_OF_THE_WEEK]; |
| 253 | |
| 254 | minutes++; |
| 255 | |
| 256 | if (minutes > 59) |
| 257 | { |
| 258 | minutes = 0; |
| 259 | hours++; |
| 260 | } |
| 261 | |
| 262 | if (hours > 23) |
| 263 | { |
| 264 | hours = 0; |
| 265 | days++; |
| 266 | day_of_week++; |
| 267 | } |
| 268 | |
| 269 | if (day_of_week > 6) |
| 270 | { |
| 271 | day_of_week++; |
| 272 | } |
| 273 | |
| 274 | if (days > DAYS_PER_MONTH[month - 1]) |
| 275 | { |
| 276 | days = 1; |
| 277 | month++; |
| 278 | } |
| 279 | |
| 280 | if (month > 12) |
| 281 | { |
| 282 | month = 1; |
| 283 | year++; |
| 284 | m_reg[MODE01][REGISTER_LEAP_YEAR]++; |
| 285 | m_reg[MODE01][REGISTER_LEAP_YEAR] &= 0x03; |
| 286 | } |
| 287 | |
| 288 | if (year > 99) |
| 289 | { |
| 290 | year = 0; |
| 291 | } |
| 292 | |
| 293 | write_counter(REGISTER_1_MINUTE, minutes); |
| 294 | write_counter(REGISTER_1_HOUR, hours); |
| 295 | write_counter(REGISTER_1_DAY, days); |
| 296 | write_counter(REGISTER_1_MONTH, month); |
| 297 | write_counter(REGISTER_1_YEAR, year); |
| 298 | m_reg[MODE00][REGISTER_DAY_OF_THE_WEEK] = day_of_week; |
| 299 | |
| 300 | check_alarm(); |
| 301 | set_alarm_line(); |
| 302 | } |
| 303 | |
| 304 | |
| 305 | //------------------------------------------------- |
| 306 | // adjust_seconds - |
| 307 | //------------------------------------------------- |
| 308 | |
| 309 | inline void rp5c15_device::adjust_seconds() |
| 310 | { |
| 311 | int seconds = read_counter(REGISTER_1_SECOND); |
| 312 | |
| 313 | if (seconds < 30) |
| 314 | { |
| 315 | write_counter(REGISTER_1_SECOND, 0); |
| 316 | } |
| 317 | else |
| 318 | { |
| 319 | write_counter(REGISTER_1_SECOND, 0); |
| 320 | advance_minutes(); |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | |
| 325 | //------------------------------------------------- |
| 326 | // check_alarm - |
| 327 | //------------------------------------------------- |
| 328 | |
| 329 | inline void rp5c15_device::check_alarm() |
| 330 | { |
| 331 | bool all_match = true; |
| 332 | bool all_zeroes = true; |
| 333 | |
| 334 | for (int i = REGISTER_1_MINUTE; i < REGISTER_1_MONTH; i++) |
| 335 | { |
| 336 | if (m_reg[MODE01][i] != 0) all_zeroes = false; |
| 337 | if (m_reg[MODE01][i] != m_reg[MODE00][i]) all_match = false; |
| 338 | } |
| 339 | |
| 340 | m_alarm_on = (all_match || (!m_alarm_on && all_zeroes)) ? 0 : 1; |
| 341 | } |
| 342 | |
| 343 | |
| 344 | |
| 345 | //************************************************************************** |
| 346 | // LIVE DEVICE |
| 347 | //************************************************************************** |
| 348 | |
| 349 | //------------------------------------------------- |
| 350 | // rp5c15_device - constructor |
| 351 | //------------------------------------------------- |
| 352 | |
| 353 | rp5c15_device::rp5c15_device(running_machine &_machine, const rp5c15_device_config &config) |
| 354 | : device_t(_machine, config), |
| 355 | m_alarm(1), |
| 356 | m_alarm_on(1), |
| 357 | m_1hz(1), |
| 358 | m_16hz(1), |
| 359 | m_clkout(1), |
| 360 | m_config(config) |
| 361 | { |
| 362 | } |
| 363 | |
| 364 | |
| 365 | //------------------------------------------------- |
| 366 | // device_start - device-specific startup |
| 367 | //------------------------------------------------- |
| 368 | |
| 369 | void rp5c15_device::device_start() |
| 370 | { |
| 371 | // resolve callbacks |
| 372 | devcb_resolve_write_line(&m_out_alarm_func, &m_config.m_out_alarm_func, this); |
| 373 | devcb_resolve_write_line(&m_out_clkout_func, &m_config.m_out_clkout_func, this); |
| 374 | |
| 375 | // allocate timers |
| 376 | m_clock_timer = timer_alloc(TIMER_CLOCK); |
| 377 | m_clock_timer->adjust(attotime::from_hz(clock() / 16384), 0, attotime::from_hz(clock() / 16384)); |
| 378 | |
| 379 | m_16hz_timer = timer_alloc(TIMER_16HZ); |
| 380 | m_16hz_timer->adjust(attotime::from_hz(clock() / 1024), 0, attotime::from_hz(clock() / 1024)); |
| 381 | |
| 382 | m_clkout_timer = timer_alloc(TIMER_CLKOUT); |
| 383 | |
| 384 | // state saving |
| 385 | save_item(NAME(m_reg[MODE00])); |
| 386 | save_item(NAME(m_reg[MODE01])); |
| 387 | save_item(NAME(m_mode)); |
| 388 | save_item(NAME(m_reset)); |
| 389 | save_item(NAME(m_alarm)); |
| 390 | save_item(NAME(m_alarm_on)); |
| 391 | save_item(NAME(m_1hz)); |
| 392 | save_item(NAME(m_16hz)); |
| 393 | save_item(NAME(m_clkout)); |
| 394 | } |
| 395 | |
| 396 | |
| 397 | //------------------------------------------------- |
| 398 | // device_timer - handler timer events |
| 399 | //------------------------------------------------- |
| 400 | |
| 401 | void rp5c15_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 402 | { |
| 403 | switch (id) |
| 404 | { |
| 405 | case TIMER_CLOCK: |
| 406 | if (m_1hz && (m_mode & MODE_TIMER_EN)) |
| 407 | { |
| 408 | advance_seconds(); |
| 409 | } |
| 410 | |
| 411 | m_1hz = !m_1hz; |
| 412 | set_alarm_line(); |
| 413 | break; |
| 414 | |
| 415 | case TIMER_16HZ: |
| 416 | m_16hz = !m_16hz; |
| 417 | set_alarm_line(); |
| 418 | break; |
| 419 | |
| 420 | case TIMER_CLKOUT: |
| 421 | m_clkout = !m_clkout; |
| 422 | devcb_call_write_line(&m_out_clkout_func, m_clkout); |
| 423 | break; |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | |
| 428 | //------------------------------------------------- |
| 429 | // read - |
| 430 | //------------------------------------------------- |
| 431 | |
| 432 | READ8_MEMBER( rp5c15_device::read ) |
| 433 | { |
| 434 | UINT8 data = 0; |
| 435 | |
| 436 | switch (offset & 0x0f) |
| 437 | { |
| 438 | case REGISTER_MODE: |
| 439 | data = m_mode; |
| 440 | break; |
| 441 | |
| 442 | case REGISTER_TEST: |
| 443 | case REGISTER_RESET: |
| 444 | // write only |
| 445 | break; |
| 446 | |
| 447 | default: |
| 448 | data = m_reg[m_mode & MODE_MASK][offset]; |
| 449 | break; |
| 450 | } |
| 451 | |
| 452 | if (LOG) logerror("RP5C15 '%s' Register %u Read %02x\n", tag(), offset & 0x0f, data); |
| 453 | |
| 454 | return data & 0x0f; |
| 455 | } |
| 456 | |
| 457 | |
| 458 | //------------------------------------------------- |
| 459 | // write - |
| 460 | //------------------------------------------------- |
| 461 | |
| 462 | WRITE8_MEMBER( rp5c15_device::write ) |
| 463 | { |
| 464 | int mode = m_mode & MODE_MASK; |
| 465 | |
| 466 | switch (offset & 0x0f) |
| 467 | { |
| 468 | case REGISTER_MODE: |
| 469 | m_mode = data & 0x0f; |
| 470 | |
| 471 | if (LOG) |
| 472 | { |
| 473 | logerror("RP5C15 '%s' Mode %u\n", tag(), data & MODE_MASK); |
| 474 | logerror("RP5C15 '%s' Timer %s\n", tag(), (data & MODE_TIMER_EN) ? "enabled" : "disabled"); |
| 475 | logerror("RP5C15 '%s' Alarm %s\n", tag(), (data & MODE_ALARM_EN) ? "enabled" : "disabled"); |
| 476 | } |
| 477 | break; |
| 478 | |
| 479 | case REGISTER_TEST: |
| 480 | if (LOG) logerror("RP5C15 '%s' Test %u not supported!\n", tag(), data); |
| 481 | break; |
| 482 | |
| 483 | case REGISTER_RESET: |
| 484 | m_reset = data & 0x0f; |
| 485 | |
| 486 | if (data & RESET_ALARM) |
| 487 | { |
| 488 | int i; |
| 489 | |
| 490 | // reset alarm registers |
| 491 | for (i = REGISTER_1_MINUTE; i < REGISTER_1_MONTH; i++) |
| 492 | { |
| 493 | m_reg[MODE01][i] = 0; |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | if (LOG) |
| 498 | { |
| 499 | if (data & RESET_ALARM) logerror("RP5C15 '%s' Alarm Reset\n", tag()); |
| 500 | if (data & RESET_TIMER) logerror("RP5C15 '%s' Timer Reset not supported!\n", tag()); |
| 501 | logerror("RP5C15 '%s' 16Hz Signal %s\n", tag(), (data & RESET_16_HZ) ? "disabled" : "enabled"); |
| 502 | logerror("RP5C15 '%s' 1Hz Signal %s\n", tag(), (data & RESET_1_HZ) ? "disabled" : "enabled"); |
| 503 | } |
| 504 | break; |
| 505 | |
| 506 | default: |
| 507 | switch (mode) |
| 508 | { |
| 509 | case MODE00: |
| 510 | m_reg[mode][offset & 0x0f] = data & REGISTER_WRITE_MASK[mode][offset & 0x0f]; |
| 511 | break; |
| 512 | |
| 513 | case MODE01: |
| 514 | switch (offset & 0x0f) |
| 515 | { |
| 516 | case REGISTER_CLOCK_OUTPUT: |
| 517 | switch (data & 0x07) |
| 518 | { |
| 519 | case CLKOUT_16384_HZ: |
| 520 | m_clkout_timer->adjust(attotime::from_hz(clock()), 0, attotime::from_hz(clock())); |
| 521 | break; |
| 522 | |
| 523 | case CLKOUT_1024_HZ: |
| 524 | m_clkout_timer->adjust(attotime::from_hz(clock() / 16), 0, attotime::from_hz(clock() / 16)); |
| 525 | break; |
| 526 | |
| 527 | case CLKOUT_128_HZ: |
| 528 | m_clkout_timer->adjust(attotime::from_hz(clock() / 128), 0, attotime::from_hz(clock() / 128)); |
| 529 | break; |
| 530 | |
| 531 | case CLKOUT_16_HZ: |
| 532 | m_clkout_timer->adjust(attotime::from_hz(clock() / 1024), 0, attotime::from_hz(clock() / 1024)); |
| 533 | break; |
| 534 | |
| 535 | case CLKOUT_1_HZ: |
| 536 | m_clkout_timer->adjust(attotime::from_hz(clock() / 16384), 0, attotime::from_hz(clock() / 16384)); |
| 537 | break; |
| 538 | |
| 539 | case CLKOUT_1_DIV_60_HZ: |
| 540 | // TODO |
| 541 | break; |
| 542 | |
| 543 | case CLKOUT_L: |
| 544 | case CLKOUT_Z: |
| 545 | m_clkout = 1; |
| 546 | m_clkout_timer->adjust(attotime::zero, 0); |
| 547 | break; |
| 548 | } |
| 549 | |
| 550 | m_reg[mode][offset & 0x0f] = data & REGISTER_WRITE_MASK[mode][offset & 0x0f]; |
| 551 | break; |
| 552 | |
| 553 | case REGISTER_ADJUST: |
| 554 | if (BIT(data, 0)) |
| 555 | { |
| 556 | adjust_seconds(); |
| 557 | } |
| 558 | m_reg[mode][offset & 0x0f] = data & REGISTER_WRITE_MASK[mode][offset & 0x0f]; |
| 559 | break; |
| 560 | |
| 561 | default: |
| 562 | m_reg[mode][offset & 0x0f] = data & REGISTER_WRITE_MASK[mode][offset & 0x0f]; |
| 563 | break; |
| 564 | } |
| 565 | break; |
| 566 | } |
| 567 | |
| 568 | if (LOG) logerror("RP5C15 '%s' Register %u Write %02x\n", tag(), offset & 0x0f, data); |
| 569 | break; |
| 570 | } |
| 571 | } |
src/emu/machine/rp5c15.h
| r0 | r11276 | |
| 1 | /********************************************************************** |
| 2 | |
| 3 | Ricoh RP5C15 Real Time Clock emulation |
| 4 | |
| 5 | Copyright MESS Team. |
| 6 | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | |
| 8 | ********************************************************************** |
| 9 | _____ _____ |
| 10 | _CS 1 |* \_/ | 18 Vcc |
| 11 | CS 2 | | 17 OSCOUT |
| 12 | CLKOUT 3 | | 16 OSCIN |
| 13 | A0 4 | RP5C15 | 15 _ALARM |
| 14 | A1 5 | RF5C15 | 14 D3 |
| 15 | A2 6 | RJ5C15 | 13 D2 |
| 16 | A3 7 | | 12 D1 |
| 17 | _RD 8 | | 11 D0 |
| 18 | GND 9 |_____________| 10 _WR |
| 19 | |
| 20 | **********************************************************************/ |
| 21 | |
| 22 | #pragma once |
| 23 | |
| 24 | #ifndef __RP5C15__ |
| 25 | #define __RP5C15__ |
| 26 | |
| 27 | #include "emu.h" |
| 28 | |
| 29 | |
| 30 | |
| 31 | //************************************************************************** |
| 32 | // INTERFACE CONFIGURATION MACROS |
| 33 | //************************************************************************** |
| 34 | |
| 35 | #define MCFG_RP5C15_ADD(_tag, _clock, _config) \ |
| 36 | MCFG_DEVICE_ADD((_tag), RP5C15, _clock) \ |
| 37 | MCFG_DEVICE_CONFIG(_config) |
| 38 | |
| 39 | |
| 40 | #define RP5C15_INTERFACE(name) \ |
| 41 | const rp5c15_interface (name) = |
| 42 | |
| 43 | |
| 44 | |
| 45 | //************************************************************************** |
| 46 | // TYPE DEFINITIONS |
| 47 | //************************************************************************** |
| 48 | |
| 49 | // ======================> rp5c15_interface |
| 50 | |
| 51 | struct rp5c15_interface |
| 52 | { |
| 53 | devcb_write_line m_out_alarm_func; |
| 54 | devcb_write_line m_out_clkout_func; |
| 55 | }; |
| 56 | |
| 57 | |
| 58 | |
| 59 | // ======================> rp5c15_device_config |
| 60 | |
| 61 | class rp5c15_device_config : public device_config, |
| 62 | public rp5c15_interface |
| 63 | { |
| 64 | friend class rp5c15_device; |
| 65 | |
| 66 | // construction/destruction |
| 67 | rp5c15_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); |
| 68 | |
| 69 | public: |
| 70 | // allocators |
| 71 | static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); |
| 72 | virtual device_t *alloc_device(running_machine &machine) const; |
| 73 | |
| 74 | protected: |
| 75 | // device_config overrides |
| 76 | virtual void device_config_complete(); |
| 77 | }; |
| 78 | |
| 79 | |
| 80 | |
| 81 | // ======================> rp5c15_device |
| 82 | |
| 83 | class rp5c15_device : public device_t |
| 84 | { |
| 85 | friend class rp5c15_device_config; |
| 86 | |
| 87 | // construction/destruction |
| 88 | rp5c15_device(running_machine &_machine, const rp5c15_device_config &_config); |
| 89 | |
| 90 | public: |
| 91 | DECLARE_READ8_MEMBER( read ); |
| 92 | DECLARE_WRITE8_MEMBER( write ); |
| 93 | DECLARE_WRITE_LINE_MEMBER( adj_w ); |
| 94 | |
| 95 | protected: |
| 96 | // device-level overrides |
| 97 | virtual void device_start(); |
| 98 | virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr); |
| 99 | |
| 100 | private: |
| 101 | inline void set_alarm_line(); |
| 102 | inline int read_counter(int counter); |
| 103 | inline void write_counter(int counter, int value); |
| 104 | inline void advance_seconds(); |
| 105 | inline void advance_minutes(); |
| 106 | inline void adjust_seconds(); |
| 107 | inline void check_alarm(); |
| 108 | |
| 109 | static const device_timer_id TIMER_CLOCK = 0; |
| 110 | static const device_timer_id TIMER_16HZ = 1; |
| 111 | static const device_timer_id TIMER_CLKOUT = 2; |
| 112 | |
| 113 | devcb_resolved_write_line m_out_alarm_func; |
| 114 | devcb_resolved_write_line m_out_clkout_func; |
| 115 | |
| 116 | UINT8 m_reg[2][13]; // clock registers |
| 117 | UINT8 m_ram[13]; // RAM |
| 118 | |
| 119 | UINT8 m_mode; // mode register |
| 120 | UINT8 m_reset; // reset register |
| 121 | int m_alarm; // alarm output |
| 122 | int m_alarm_on; // alarm condition |
| 123 | int m_1hz; // 1 Hz condition |
| 124 | int m_16hz; // 16 Hz condition |
| 125 | int m_clkout; // clock output |
| 126 | |
| 127 | // timers |
| 128 | emu_timer *m_clock_timer; |
| 129 | emu_timer *m_16hz_timer; |
| 130 | emu_timer *m_clkout_timer; |
| 131 | |
| 132 | const rp5c15_device_config &m_config; |
| 133 | }; |
| 134 | |
| 135 | |
| 136 | // device type definition |
| 137 | extern const device_type RP5C15; |
| 138 | |
| 139 | |
| 140 | |
| 141 | #endif |
src/mess/machine/rp5c15.c
| r11275 | r11276 | |
| 1 | | /* |
| 2 | | |
| 3 | | Ricoh RP5C15 Real-time Clock |
| 4 | | Written by Barry Rodewald |
| 5 | | Started 04/07/07 |
| 6 | | |
| 7 | | Registers are separated into two banks, switchable through |
| 8 | | the LSB of the MODE register. |
| 9 | | |
| 10 | | Date and time are stored in BCD, one digit to each register |
| 11 | | |
| 12 | | Register BANK 0 BANK 1 |
| 13 | | 0 Timer seconds CLKOUT |
| 14 | | 1 Timer seconds (10s) RTC Adjustment |
| 15 | | 2 Timer minutes Alarm minutes |
| 16 | | 3 Timer minutes (10s) Alarm minutes (10s) |
| 17 | | 4 Timer hours Alarm hours |
| 18 | | 5 Timer hours (10s) Alarm hours (10s) |
| 19 | | 6 Timer day-of-week Alarm day-of-week |
| 20 | | 7 Timer day Alarm day |
| 21 | | 8 Timer day (10s) Alarm day (10s) |
| 22 | | 9 Timer month (unused) |
| 23 | | 10 Timer month (10s) 12/24 hour clock selection |
| 24 | | 11 Timer year Years until next leap year |
| 25 | | 12 Timer year (10s) (unused) |
| 26 | | 13 MODE register MODE register |
| 27 | | 14 TEST register TEST register |
| 28 | | 15 RESET register RESET register |
| 29 | | |
| 30 | | |
| 31 | | CLKOUT (W/O) - on the X68000, this is connected to the Timer LED |
| 32 | | xxxxx000 = always high (on) |
| 33 | | xxxxx001 = 16384Hz |
| 34 | | xxxxx010 = 1024Hz |
| 35 | | xxxxx011 = 128Hz |
| 36 | | xxxxx100 = 16Hz |
| 37 | | xxxxx101 = 1Hz |
| 38 | | xxxxx110 = 1/60Hz |
| 39 | | xxxxx111 = always low (off) |
| 40 | | |
| 41 | | Adjustment register (R/W) |
| 42 | | bit 0 = if set, will reset the seconds to zero, and if the |
| 43 | | seconds were > 30, increment the minutes by 1. |
| 44 | | Always returns 0. |
| 45 | | |
| 46 | | 12/24 hour clock register (R/W) (not implemented yet) |
| 47 | | bit 0 = selects 12 or 24 hour clock |
| 48 | | presumably, on reading, returns AM/PM status. |
| 49 | | |
| 50 | | Leap year register |
| 51 | | bit 0,1 = returns number of years until next leap year. |
| 52 | | Is simply year % 4. |
| 53 | | |
| 54 | | MODE register (R/W) |
| 55 | | bit 0 = if set, selects BANK 1, if reset, selects BANK 0 |
| 56 | | bit 2 = Alarm enable |
| 57 | | bit 3 = Timer enable |
| 58 | | |
| 59 | | TEST register (not implemented yet) |
| 60 | | bits 0-3 = generally all set to 0, use is unknown. |
| 61 | | |
| 62 | | RESET register (not implemented yet) |
| 63 | | bit 0 = Alarm reset |
| 64 | | bit 1 = Timer reset |
| 65 | | bit 2 = if set, 16Hz pulse is off |
| 66 | | bit 3 = if set, 1Hz pulse is off |
| 67 | | |
| 68 | | */ |
| 69 | | |
| 70 | | #include "rp5c15.h" |
| 71 | | |
| 72 | | typedef struct _rp5c15_t rp5c15_t; |
| 73 | | struct _rp5c15_t |
| 74 | | { |
| 75 | | struct |
| 76 | | { |
| 77 | | unsigned char sec_1; |
| 78 | | unsigned char sec_10; |
| 79 | | unsigned char min_1; |
| 80 | | unsigned char min_10; |
| 81 | | unsigned char hour_1; |
| 82 | | unsigned char hour_10; |
| 83 | | unsigned char dayofweek; |
| 84 | | unsigned char day_1; |
| 85 | | unsigned char day_10; |
| 86 | | unsigned char month_1; |
| 87 | | unsigned char month_10; |
| 88 | | unsigned char year_1; |
| 89 | | unsigned char year_10; |
| 90 | | } systime; |
| 91 | | struct |
| 92 | | { |
| 93 | | unsigned char min_1; |
| 94 | | unsigned char min_10; |
| 95 | | unsigned char hour_1; |
| 96 | | unsigned char hour_10; |
| 97 | | unsigned char dayofweek; |
| 98 | | unsigned char day_1; |
| 99 | | unsigned char day_10; |
| 100 | | } alarm; |
| 101 | | int clkout; |
| 102 | | int adjust; |
| 103 | | int hour24; // 12/24 hour clock |
| 104 | | int leap; // Years until next leap year (0-3, 0 = this year is leap year) |
| 105 | | int mode; |
| 106 | | int test; |
| 107 | | int reset; |
| 108 | | int pulse_count; |
| 109 | | int pulse1_state; |
| 110 | | int pulse16_state; |
| 111 | | void (*timer_expired_func)(int state); |
| 112 | | void (*alarm_callback)(running_machine &machine, int state); |
| 113 | | const rp5c15_intf* intf; |
| 114 | | emu_timer* timer; |
| 115 | | }; // Ricoh RP5C15 |
| 116 | | |
| 117 | | static void rtc_add_second(device_t*); |
| 118 | | static void rtc_add_minute(device_t*); |
| 119 | | static void rtc_add_day(device_t*); |
| 120 | | static void rtc_add_month(device_t*); |
| 121 | | |
| 122 | | INLINE rp5c15_t *get_safe_token(device_t *device) |
| 123 | | { |
| 124 | | assert(device != NULL); |
| 125 | | assert(device->type() == RP5C15); |
| 126 | | |
| 127 | | return (rp5c15_t*)downcast<legacy_device_base *>(device)->token(); |
| 128 | | } |
| 129 | | |
| 130 | | static TIMER_CALLBACK(rtc_alarm_pulse) |
| 131 | | { |
| 132 | | device_t* device = (device_t*)ptr; |
| 133 | | rp5c15_t* rtc = get_safe_token(device); |
| 134 | | |
| 135 | | if(rtc->pulse16_state == 0) // low |
| 136 | | { |
| 137 | | rtc->pulse16_state = 1; // make high |
| 138 | | rtc->pulse_count++; |
| 139 | | } |
| 140 | | else |
| 141 | | { |
| 142 | | rtc->pulse16_state = 0; // make low |
| 143 | | } |
| 144 | | |
| 145 | | if(rtc->pulse_count == 8) |
| 146 | | { |
| 147 | | rtc->pulse1_state = 0; |
| 148 | | } |
| 149 | | if(rtc->pulse_count == 16) |
| 150 | | { |
| 151 | | rtc->pulse_count = 0; |
| 152 | | rtc->pulse1_state = 1; |
| 153 | | rtc_add_second(device); |
| 154 | | } |
| 155 | | } |
| 156 | | |
| 157 | | static DEVICE_START( rp5c15 ) |
| 158 | | { |
| 159 | | rp5c15_t* rtc = get_safe_token(device); |
| 160 | | system_time systm; |
| 161 | | |
| 162 | | rtc->intf = (const rp5c15_intf*)device->baseconfig().static_config(); |
| 163 | | |
| 164 | | rtc->alarm_callback = rtc->intf->alarm_irq_callback; |
| 165 | | |
| 166 | | device->machine().base_datetime(systm); |
| 167 | | |
| 168 | | // date/time is stored as BCD |
| 169 | | rtc->systime.sec_1 = systm.local_time.second % 10; |
| 170 | | rtc->systime.sec_10 = systm.local_time.second / 10; |
| 171 | | rtc->systime.min_1 = systm.local_time.minute % 10; |
| 172 | | rtc->systime.min_10 = systm.local_time.minute / 10; |
| 173 | | rtc->systime.hour_1 = systm.local_time.hour % 10; |
| 174 | | rtc->systime.hour_10 = systm.local_time.hour / 10; |
| 175 | | rtc->systime.day_1 = systm.local_time.mday % 10; |
| 176 | | rtc->systime.day_10 = systm.local_time.mday / 10; |
| 177 | | rtc->systime.month_1 = (systm.local_time.month+1) % 10; |
| 178 | | rtc->systime.month_10 = (systm.local_time.month+1) / 10; |
| 179 | | rtc->systime.year_1 = (systm.local_time.year - 1980) % 10; |
| 180 | | rtc->systime.year_10 = (systm.local_time.year - 1980) / 10; |
| 181 | | rtc->systime.dayofweek = systm.local_time.weekday; |
| 182 | | rtc->alarm.min_1 = systm.local_time.minute % 10; |
| 183 | | rtc->alarm.min_10 = systm.local_time.minute / 10; |
| 184 | | rtc->alarm.hour_1 = systm.local_time.hour % 10; |
| 185 | | rtc->alarm.hour_10 = systm.local_time.hour / 10; |
| 186 | | rtc->alarm.day_1 = systm.local_time.mday % 10; |
| 187 | | rtc->alarm.day_10 = systm.local_time.mday / 10; |
| 188 | | rtc->alarm.dayofweek = systm.local_time.weekday; |
| 189 | | rtc->leap = systm.local_time.year % 4; |
| 190 | | |
| 191 | | rtc->mode = 0x08; // Timer enabled, Alarm disable, BANK 0 selected (defaults are guessed) |
| 192 | | rtc->reset = 0x00; // enable both 1Hz and 16Hz alarm counters by default |
| 193 | | rtc->test = 0x00; |
| 194 | | rtc->pulse_count = 0; |
| 195 | | |
| 196 | | rtc->timer = device->machine().scheduler().timer_alloc(FUNC(rtc_alarm_pulse), (void*)device); |
| 197 | | rtc->timer->adjust(attotime::zero, 0, attotime::from_hz(32)); |
| 198 | | } |
| 199 | | |
| 200 | | static int rp5c15_read(device_t* device, int offset, UINT16 mem_mask) |
| 201 | | { |
| 202 | | rp5c15_t* rtc = get_safe_token(device); |
| 203 | | if((rtc->mode & 0x01) == 0x00) // BANK 0 selected |
| 204 | | { |
| 205 | | switch(offset) |
| 206 | | { |
| 207 | | case 0: |
| 208 | | return rtc->systime.sec_1; |
| 209 | | case 1: |
| 210 | | return rtc->systime.sec_10; |
| 211 | | case 2: |
| 212 | | return rtc->systime.min_1; |
| 213 | | case 3: |
| 214 | | return rtc->systime.min_10; |
| 215 | | case 4: |
| 216 | | return rtc->systime.hour_1; |
| 217 | | case 5: |
| 218 | | return rtc->systime.hour_10; |
| 219 | | case 6: |
| 220 | | return rtc->systime.dayofweek; |
| 221 | | case 7: |
| 222 | | return rtc->systime.day_1; |
| 223 | | case 8: |
| 224 | | return rtc->systime.day_10; |
| 225 | | case 9: |
| 226 | | return rtc->systime.month_1; |
| 227 | | case 10: |
| 228 | | return rtc->systime.month_10; |
| 229 | | case 11: |
| 230 | | return rtc->systime.year_1; |
| 231 | | case 12: |
| 232 | | return rtc->systime.year_10; |
| 233 | | case 13: |
| 234 | | return rtc->mode & 0x0f; |
| 235 | | } |
| 236 | | } |
| 237 | | else // BANK 1 selected |
| 238 | | { |
| 239 | | switch(offset) |
| 240 | | { |
| 241 | | case 0: // CLKOUT |
| 242 | | return rtc->clkout & 0x07; |
| 243 | | case 1: // Adjustment (always returns 0) |
| 244 | | return 0; |
| 245 | | case 2: |
| 246 | | return rtc->alarm.min_1; |
| 247 | | case 3: |
| 248 | | return rtc->alarm.min_10; |
| 249 | | case 4: |
| 250 | | return rtc->alarm.hour_1; |
| 251 | | case 5: |
| 252 | | return rtc->alarm.hour_10; |
| 253 | | case 6: |
| 254 | | return rtc->alarm.dayofweek; |
| 255 | | case 7: |
| 256 | | return rtc->alarm.day_1; |
| 257 | | case 8: |
| 258 | | return rtc->alarm.day_10; |
| 259 | | case 10: // 12/24 hour selection (returns AM/PM?) |
| 260 | | return 0; |
| 261 | | case 11: // Leap year |
| 262 | | return rtc->leap; |
| 263 | | case 13: |
| 264 | | return rtc->mode & 0x0f; |
| 265 | | default: |
| 266 | | return 0; |
| 267 | | } |
| 268 | | } |
| 269 | | return 0; |
| 270 | | } |
| 271 | | |
| 272 | | static void rp5c15_write(device_t* device, int offset, int data, UINT16 mem_mask) |
| 273 | | { |
| 274 | | rp5c15_t* rtc = get_safe_token(device); |
| 275 | | if(offset == 13) |
| 276 | | { |
| 277 | | rtc->mode = data & 0x0f; |
| 278 | | return; |
| 279 | | } |
| 280 | | if((rtc->mode & 0x01) == 0x00) // BANK 0 selected |
| 281 | | { |
| 282 | | switch(offset) |
| 283 | | { |
| 284 | | case 0: |
| 285 | | rtc->systime.sec_1 = data & 0x0f; |
| 286 | | break; |
| 287 | | case 1: |
| 288 | | rtc->systime.sec_10 = data & 0x0f; |
| 289 | | break; |
| 290 | | case 2: |
| 291 | | rtc->systime.min_1 = data & 0x0f; |
| 292 | | break; |
| 293 | | case 3: |
| 294 | | rtc->systime.min_10 = data & 0x0f; |
| 295 | | break; |
| 296 | | case 4: |
| 297 | | rtc->systime.hour_1 = data & 0x0f; |
| 298 | | break; |
| 299 | | case 5: |
| 300 | | rtc->systime.hour_10 = data & 0x0f; |
| 301 | | break; |
| 302 | | case 6: |
| 303 | | rtc->systime.dayofweek = data & 0x0f; |
| 304 | | break; |
| 305 | | case 7: |
| 306 | | rtc->systime.day_1 = data & 0x0f; |
| 307 | | break; |
| 308 | | case 8: |
| 309 | | rtc->systime.day_10 = data & 0x0f; |
| 310 | | break; |
| 311 | | case 9: |
| 312 | | rtc->systime.month_1 = data & 0x0f; |
| 313 | | break; |
| 314 | | case 10: |
| 315 | | rtc->systime.month_10 = data & 0x0f; |
| 316 | | break; |
| 317 | | case 11: |
| 318 | | rtc->systime.year_1 = data & 0x0f; |
| 319 | | break; |
| 320 | | case 12: |
| 321 | | rtc->systime.year_10 = data & 0x0f; |
| 322 | | break; |
| 323 | | } |
| 324 | | } |
| 325 | | else // BANK 1 selected |
| 326 | | { |
| 327 | | switch(offset) |
| 328 | | { |
| 329 | | case 0: |
| 330 | | rtc->clkout = data & 0x07; |
| 331 | | break; |
| 332 | | case 1: // Adjustment (resets seconds to 0, increases minute by 1 if seconds are > 30 |
| 333 | | if(rtc->systime.sec_10 >= 3) |
| 334 | | rtc_add_minute(device); |
| 335 | | rtc->systime.sec_1 = 0; |
| 336 | | rtc->systime.sec_10 = 0; |
| 337 | | break; |
| 338 | | case 2: |
| 339 | | rtc->alarm.min_1 = data & 0x0f; |
| 340 | | break; |
| 341 | | case 3: |
| 342 | | rtc->alarm.min_10 = data & 0x0f; |
| 343 | | break; |
| 344 | | case 4: |
| 345 | | rtc->alarm.hour_1 = data & 0x0f; |
| 346 | | break; |
| 347 | | case 5: |
| 348 | | rtc->alarm.hour_10 = data & 0x0f; |
| 349 | | break; |
| 350 | | case 6: |
| 351 | | rtc->alarm.dayofweek = data & 0x0f; |
| 352 | | break; |
| 353 | | case 7: |
| 354 | | rtc->alarm.day_1 = data & 0x0f; |
| 355 | | break; |
| 356 | | case 8: |
| 357 | | rtc->alarm.day_10 = data & 0x0f; |
| 358 | | break; |
| 359 | | case 10: // 12/24 hour clock selection |
| 360 | | rtc->hour24 = data; |
| 361 | | break; |
| 362 | | |
| 363 | | } |
| 364 | | } |
| 365 | | } |
| 366 | | |
| 367 | | static void rtc_add_second(device_t* device) // add one second to current time |
| 368 | | { |
| 369 | | rp5c15_t* rtc = get_safe_token(device); |
| 370 | | |
| 371 | | if((rtc->mode & 0x08) == 0x00) // if timer is not enabled |
| 372 | | return; |
| 373 | | rtc->systime.sec_1++; |
| 374 | | if(rtc->systime.sec_1 < 10) |
| 375 | | return; |
| 376 | | rtc->systime.sec_1 = 0; |
| 377 | | rtc->systime.sec_10++; |
| 378 | | if(rtc->systime.sec_10 < 6) |
| 379 | | return; |
| 380 | | rtc->systime.sec_10 = 0; |
| 381 | | rtc_add_minute(device); |
| 382 | | } |
| 383 | | |
| 384 | | static void rtc_add_minute(device_t* device) |
| 385 | | { |
| 386 | | rp5c15_t* rtc = get_safe_token(device); |
| 387 | | |
| 388 | | rtc->systime.min_1++; |
| 389 | | if(rtc->systime.min_1 < 10) |
| 390 | | return; |
| 391 | | rtc->systime.min_1 = 0; |
| 392 | | rtc->systime.min_10++; |
| 393 | | if(rtc->systime.min_10 < 6) |
| 394 | | return; |
| 395 | | rtc->systime.min_10 = 0; |
| 396 | | rtc->systime.hour_1++; |
| 397 | | if(rtc->systime.hour_1 < 10 && rtc->systime.hour_10 < 2) |
| 398 | | return; |
| 399 | | if(rtc->systime.hour_10 < 3 && rtc->systime.hour_1 < 4) |
| 400 | | return; |
| 401 | | rtc->systime.hour_1 = 0; |
| 402 | | rtc->systime.hour_10++; |
| 403 | | if(rtc->systime.hour_10 < 3) |
| 404 | | return; |
| 405 | | rtc->systime.hour_10 = 0; |
| 406 | | rtc_add_day(device); |
| 407 | | } |
| 408 | | |
| 409 | | static void rtc_add_day(device_t* device) |
| 410 | | { |
| 411 | | rp5c15_t* rtc = get_safe_token(device); |
| 412 | | int d,m; |
| 413 | | |
| 414 | | rtc->systime.dayofweek++; |
| 415 | | if(rtc->systime.dayofweek >= 7) |
| 416 | | rtc->systime.dayofweek = 0; |
| 417 | | d = (rtc->systime.day_10 << 4) | rtc->systime.day_1; |
| 418 | | m = (rtc->systime.month_10 << 4) | rtc->systime.month_1; |
| 419 | | d++; |
| 420 | | if((d & 0x0f) >= 10) |
| 421 | | { |
| 422 | | d &= 0xf0; |
| 423 | | d += 0x10; |
| 424 | | } |
| 425 | | rtc->systime.day_1 = (d & 0x0f); |
| 426 | | rtc->systime.day_10 = (d & 0xf0) >> 4; |
| 427 | | switch(m) |
| 428 | | { |
| 429 | | case 1: |
| 430 | | case 3: |
| 431 | | case 5: |
| 432 | | case 7: |
| 433 | | case 8: |
| 434 | | case 0x10: |
| 435 | | case 0x12: |
| 436 | | if(d > 0x31) |
| 437 | | { |
| 438 | | rtc->systime.day_1 = 1; |
| 439 | | rtc->systime.day_10 = 0; |
| 440 | | rtc_add_month(device); |
| 441 | | } |
| 442 | | break; |
| 443 | | case 4: |
| 444 | | case 6: |
| 445 | | case 9: |
| 446 | | case 11: |
| 447 | | if(d > 0x30) |
| 448 | | { |
| 449 | | rtc->systime.day_1 = 1; |
| 450 | | rtc->systime.day_10 = 0; |
| 451 | | rtc_add_month(device); |
| 452 | | } |
| 453 | | break; |
| 454 | | case 2: |
| 455 | | if(rtc->leap == 0) // this is a leap year |
| 456 | | { |
| 457 | | if(d > 0x29) |
| 458 | | { |
| 459 | | rtc->systime.day_1 = 1; |
| 460 | | rtc->systime.day_10 = 0; |
| 461 | | rtc_add_month(device); |
| 462 | | } |
| 463 | | } |
| 464 | | else // not a leap year |
| 465 | | { |
| 466 | | if(d > 0x28) |
| 467 | | { |
| 468 | | rtc->systime.day_1 = 1; |
| 469 | | rtc->systime.day_10 = 0; |
| 470 | | rtc_add_month(device); |
| 471 | | } |
| 472 | | } |
| 473 | | break; |
| 474 | | } |
| 475 | | } |
| 476 | | |
| 477 | | static void rtc_add_month(device_t* device) |
| 478 | | { |
| 479 | | rp5c15_t* rtc = get_safe_token(device); |
| 480 | | |
| 481 | | rtc->systime.month_1++; |
| 482 | | if(rtc->systime.month_1 < 10 && rtc->systime.month_10 < 1) |
| 483 | | return; |
| 484 | | if(rtc->systime.month_1 < 3 && rtc->systime.month_10 < 2) |
| 485 | | return; |
| 486 | | rtc->systime.month_1 = 0; |
| 487 | | rtc->systime.month_10++; |
| 488 | | if(rtc->systime.month_10 < 2) |
| 489 | | return; |
| 490 | | rtc->systime.month_1 = 1; |
| 491 | | rtc->systime.month_10 = 0; |
| 492 | | rtc->systime.year_1++; |
| 493 | | if(rtc->systime.year_1 < 10) |
| 494 | | return; |
| 495 | | rtc->systime.year_1 = 0; |
| 496 | | rtc->systime.year_10++; |
| 497 | | if(rtc->systime.year_10 < 10) |
| 498 | | return; |
| 499 | | rtc->systime.year_10 = 0; |
| 500 | | } |
| 501 | | |
| 502 | | DEVICE_GET_INFO( rp5c15 ) |
| 503 | | { |
| 504 | | switch (state) |
| 505 | | { |
| 506 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 507 | | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(rp5c15_t); break; |
| 508 | | |
| 509 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 510 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(rp5c15); break; |
| 511 | | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 512 | | case DEVINFO_FCT_RESET: /* Nothing */ break; |
| 513 | | |
| 514 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 515 | | case DEVINFO_STR_NAME: strcpy(info->s, "Ricoh RP5C15"); break; |
| 516 | | case DEVINFO_STR_FAMILY: strcpy(info->s, "Real Time Clock"); break; |
| 517 | | case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 518 | | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 519 | | case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright the MESS Team"); break; |
| 520 | | } |
| 521 | | } |
| 522 | | |
| 523 | | READ16_DEVICE_HANDLER(rp5c15_r) { return rp5c15_read(device,offset,mem_mask); } |
| 524 | | WRITE16_DEVICE_HANDLER(rp5c15_w) { rp5c15_write(device,offset,data,mem_mask); } |
| 525 | | |
| 526 | | DEFINE_LEGACY_DEVICE(RP5C15, rp5c15); |
src/mess/drivers/atarist.c
| r11275 | r11276 | |
| 1277 | 1277 | AM_RANGE(0xfffc02, 0xfffc03) AM_DEVREADWRITE8_LEGACY(MC6850_0_TAG, acia6850_data_r, acia6850_data_w, 0xff00) |
| 1278 | 1278 | AM_RANGE(0xfffc04, 0xfffc05) AM_DEVREADWRITE8_LEGACY(MC6850_1_TAG, acia6850_stat_r, acia6850_ctrl_w, 0xff00) |
| 1279 | 1279 | AM_RANGE(0xfffc06, 0xfffc07) AM_DEVREADWRITE8_LEGACY(MC6850_1_TAG, acia6850_data_r, acia6850_data_w, 0xff00) |
| 1280 | | AM_RANGE(0xfffc20, 0xfffc3f) AM_DEVREADWRITE_LEGACY(RP5C15_TAG, rp5c15_r, rp5c15_w) |
| 1280 | AM_RANGE(0xfffc20, 0xfffc3f) AM_DEVREADWRITE8(RP5C15_TAG, rp5c15_device, read, write, 0x00ff) |
| 1281 | 1281 | ADDRESS_MAP_END |
| 1282 | 1282 | |
| 1283 | 1283 | |
| r11275 | r11276 | |
| 1355 | 1355 | AM_RANGE(0xff8e20, 0xff8e21) AM_READWRITE(cache_r, cache_w) |
| 1356 | 1356 | // AM_RANGE(0xfffa40, 0xfffa5f) AM_READWRITE(fpu_r, fpu_w)*/ |
| 1357 | 1357 | AM_RANGE(0xff8c80, 0xff8c87) AM_DEVREADWRITE8_LEGACY(Z8530_TAG, scc8530_r, scc8530_w, 0x00ff) |
| 1358 | | AM_RANGE(0xfffc20, 0xfffc3f) AM_DEVREADWRITE_LEGACY(RP5C15_TAG, rp5c15_r, rp5c15_w) |
| 1358 | AM_RANGE(0xfffc20, 0xfffc3f) AM_DEVREADWRITE8(RP5C15_TAG, rp5c15_device, read, write, 0x00ff) |
| 1359 | 1359 | ADDRESS_MAP_END |
| 1360 | 1360 | |
| 1361 | 1361 | |
| r11275 | r11276 | |
| 2154 | 2154 | |
| 2155 | 2155 | |
| 2156 | 2156 | //------------------------------------------------- |
| 2157 | | // rp5c15_interface rtc_intf |
| 2157 | // RP5C15_INTERFACE( rtc_intf ) |
| 2158 | 2158 | //------------------------------------------------- |
| 2159 | 2159 | |
| 2160 | | static const struct rp5c15_interface rtc_intf = |
| 2160 | static RP5C15_INTERFACE( rtc_intf ) |
| 2161 | 2161 | { |
| 2162 | | NULL |
| 2162 | DEVCB_NULL, |
| 2163 | DEVCB_NULL |
| 2163 | 2164 | }; |
| 2164 | 2165 | |
| 2165 | 2166 | |
| r11275 | r11276 | |
| 2449 | 2450 | MCFG_FLOPPY_2_DRIVES_ADD(atarist_floppy_config) |
| 2450 | 2451 | MCFG_RS232_ADD(RS232_TAG, rs232_intf) |
| 2451 | 2452 | MCFG_CENTRONICS_ADD(CENTRONICS_TAG, centronics_intf) |
| 2452 | | MCFG_RP5C15_ADD(RP5C15_TAG, rtc_intf) |
| 2453 | MCFG_RP5C15_ADD(RP5C15_TAG, XTAL_32_768kHz, rtc_intf) |
| 2453 | 2454 | |
| 2454 | 2455 | // cartridge |
| 2455 | 2456 | MCFG_CARTSLOT_ADD("cart") |
| r11275 | r11276 | |
| 2530 | 2531 | static MACHINE_CONFIG_DERIVED( megaste, ste ) |
| 2531 | 2532 | MCFG_CPU_MODIFY(M68000_TAG) |
| 2532 | 2533 | MCFG_CPU_PROGRAM_MAP(megaste_map) |
| 2533 | | MCFG_RP5C15_ADD(RP5C15_TAG, rtc_intf) |
| 2534 | MCFG_RP5C15_ADD(RP5C15_TAG, XTAL_32_768kHz, rtc_intf) |
| 2534 | 2535 | MCFG_SCC8530_ADD(Z8530_TAG, Y2/4) |
| 2535 | 2536 | |
| 2536 | 2537 | MCFG_FLOPPY_2_DRIVES_MODIFY(megaste_floppy_config) |
src/mess/drivers/mz2500.c
| r11275 | r11276 | |
| 57 | 57 | #include "imagedev/flopimg.h" |
| 58 | 58 | #include "formats/basicdsk.h" |
| 59 | 59 | |
| 60 | #define RP5C15_TAG "rp5c15" |
| 60 | 61 | |
| 61 | 62 | class mz2500_state : public driver_device |
| 62 | 63 | { |
| 63 | 64 | public: |
| 64 | 65 | mz2500_state(running_machine &machine, const driver_device_config_base &config) |
| 65 | | : driver_device(machine, config) { } |
| 66 | : driver_device(machine, config), |
| 67 | m_rtc(*this, RP5C15_TAG) |
| 68 | { } |
| 66 | 69 | |
| 70 | required_device<rp5c15_device> m_rtc; |
| 71 | |
| 67 | 72 | UINT8 m_bank_val[8]; |
| 68 | 73 | UINT8 m_bank_addr; |
| 69 | 74 | UINT8 m_irq_sel; |
| r11275 | r11276 | |
| 1411 | 1416 | (offset & 1) ? (state->m_kanji_index = (data << 8) | (state->m_kanji_index & 0xff)) : (state->m_kanji_index = (data & 0xff) | (state->m_kanji_index & 0xff00)); |
| 1412 | 1417 | } |
| 1413 | 1418 | |
| 1414 | | static READ8_DEVICE_HANDLER( rp5c15_8_r ) |
| 1419 | static READ8_HANDLER( rp5c15_8_r ) |
| 1415 | 1420 | { |
| 1416 | | UINT8 rtc_index; |
| 1421 | mz2500_state *state = space->machine().driver_data<mz2500_state>(); |
| 1422 | UINT8 rtc_index = (cpu_get_reg(space->machine().device("maincpu"), Z80_B)); |
| 1417 | 1423 | |
| 1418 | | rtc_index = (cpu_get_reg(device->machine().device("maincpu"), Z80_B)); |
| 1419 | | |
| 1420 | | return rp5c15_r(device,rtc_index,0xff); |
| 1424 | return state->m_rtc->read(*space, rtc_index); |
| 1421 | 1425 | } |
| 1422 | 1426 | |
| 1423 | | static WRITE8_DEVICE_HANDLER( rp5c15_8_w ) |
| 1427 | static WRITE8_HANDLER( rp5c15_8_w ) |
| 1424 | 1428 | { |
| 1425 | | UINT8 rtc_index; |
| 1429 | mz2500_state *state = space->machine().driver_data<mz2500_state>(); |
| 1430 | UINT8 rtc_index = (cpu_get_reg(space->machine().device("maincpu"), Z80_B)); |
| 1426 | 1431 | |
| 1427 | | rtc_index = (cpu_get_reg(device->machine().device("maincpu"), Z80_B)); |
| 1428 | | |
| 1429 | | rp5c15_w(device,rtc_index,data,0xff); |
| 1432 | state->m_rtc->write(*space, rtc_index, data); |
| 1430 | 1433 | } |
| 1431 | 1434 | |
| 1432 | 1435 | |
| r11275 | r11276 | |
| 1495 | 1498 | AM_RANGE(0xc7, 0xc7) AM_WRITE(mz2500_irq_data_w) |
| 1496 | 1499 | AM_RANGE(0xc8, 0xc9) AM_DEVREADWRITE("ym", ym2203_r, ym2203_w) |
| 1497 | 1500 | // AM_RANGE(0xca, 0xca) AM_READWRITE(voice_r,voice_w) |
| 1498 | | AM_RANGE(0xcc, 0xcc) AM_DEVREADWRITE("rp5c15", rp5c15_8_r, rp5c15_8_w) |
| 1501 | AM_RANGE(0xcc, 0xcc) AM_READWRITE(rp5c15_8_r, rp5c15_8_w) |
| 1499 | 1502 | AM_RANGE(0xce, 0xce) AM_WRITE(mz2500_dictionary_bank_w) |
| 1500 | 1503 | AM_RANGE(0xcf, 0xcf) AM_WRITE(mz2500_kanji_bank_w) |
| 1501 | 1504 | AM_RANGE(0xd8, 0xdb) AM_DEVREADWRITE("mb8877a", mz2500_wd17xx_r, mz2500_wd17xx_w) |
| r11275 | r11276 | |
| 2046 | 2049 | } |
| 2047 | 2050 | }; |
| 2048 | 2051 | |
| 2049 | | static void mz2500_rtc_alarm_irq(running_machine &machine, int state) |
| 2052 | static WRITE_LINE_DEVICE_HANDLER( mz2500_rtc_alarm_irq ) |
| 2050 | 2053 | { |
| 2051 | 2054 | //mz2500_state *drvstate = device->machine().driver_data<mz2500_state>(); |
| 2052 | 2055 | /* TODO: doesn't work yet */ |
| r11275 | r11276 | |
| 2054 | 2057 | // cputag_set_input_line_and_vector(device, "maincpu", 0, HOLD_LINE,drvstate->m_irq_vector[3]); |
| 2055 | 2058 | } |
| 2056 | 2059 | |
| 2057 | | static const struct rp5c15_interface rtc_intf = |
| 2060 | static RP5C15_INTERFACE( rtc_intf ) |
| 2058 | 2061 | { |
| 2059 | | mz2500_rtc_alarm_irq |
| 2062 | DEVCB_LINE(mz2500_rtc_alarm_irq), |
| 2063 | DEVCB_NULL |
| 2060 | 2064 | }; |
| 2061 | 2065 | |
| 2062 | 2066 | static const z80sio_interface mz2500_sio_intf = |
| r11275 | r11276 | |
| 2081 | 2085 | MCFG_I8255A_ADD( "i8255_0", ppi8255_intf ) |
| 2082 | 2086 | MCFG_Z80PIO_ADD( "z80pio_1", 6000000, mz2500_pio1_intf ) |
| 2083 | 2087 | MCFG_Z80SIO_ADD( "z80sio", 6000000, mz2500_sio_intf ) |
| 2084 | | MCFG_RP5C15_ADD( "rp5c15" , rtc_intf) |
| 2088 | MCFG_RP5C15_ADD(RP5C15_TAG, XTAL_32_768kHz, rtc_intf) |
| 2085 | 2089 | MCFG_PIT8253_ADD("pit", mz2500_pit8253_intf) |
| 2086 | 2090 | |
| 2087 | 2091 | MCFG_MB8877_ADD("mb8877a",mz2500_mb8877a_interface) |
src/mess/drivers/x68k.c
| r11275 | r11276 | |
| 1495 | 1495 | return i8255a_r(device,offset & 0x03); |
| 1496 | 1496 | } |
| 1497 | 1497 | |
| 1498 | | static READ16_DEVICE_HANDLER( x68k_rtc_r ) |
| 1498 | static READ16_HANDLER( x68k_rtc_r ) |
| 1499 | 1499 | { |
| 1500 | | return rp5c15_r(device, offset, mem_mask); |
| 1500 | x68k_state *state = space->machine().driver_data<x68k_state>(); |
| 1501 | |
| 1502 | return state->m_rtc->read(*space, offset); |
| 1501 | 1503 | } |
| 1502 | 1504 | |
| 1503 | | static WRITE16_DEVICE_HANDLER( x68k_rtc_w ) |
| 1505 | static WRITE16_HANDLER( x68k_rtc_w ) |
| 1504 | 1506 | { |
| 1505 | | rp5c15_w(device, offset, data, mem_mask); |
| 1507 | x68k_state *state = space->machine().driver_data<x68k_state>(); |
| 1508 | |
| 1509 | state->m_rtc->write(*space, offset, data); |
| 1506 | 1510 | } |
| 1507 | 1511 | |
| 1508 | | static void x68k_rtc_alarm_irq(running_machine &machine, int state) |
| 1512 | static WRITE_LINE_DEVICE_HANDLER( x68k_rtc_alarm_irq ) |
| 1509 | 1513 | { |
| 1510 | | x68k_state *drvstate = machine.driver_data<x68k_state>(); |
| 1514 | x68k_state *drvstate = device->machine().driver_data<x68k_state>(); |
| 1515 | |
| 1511 | 1516 | if(drvstate->m_mfp.aer & 0x01) |
| 1512 | 1517 | { |
| 1513 | 1518 | if(state == 1) |
| r11275 | r11276 | |
| 1977 | 1982 | AM_RANGE(0xe84000, 0xe85fff) AM_READWRITE(x68k_dmac_r, x68k_dmac_w) |
| 1978 | 1983 | AM_RANGE(0xe86000, 0xe87fff) AM_READWRITE(x68k_areaset_r, x68k_areaset_w) |
| 1979 | 1984 | AM_RANGE(0xe88000, 0xe89fff) AM_READWRITE(x68k_mfp_r, x68k_mfp_w) |
| 1980 | | AM_RANGE(0xe8a000, 0xe8bfff) AM_DEVREADWRITE("rp5c15", x68k_rtc_r, x68k_rtc_w) |
| 1985 | AM_RANGE(0xe8a000, 0xe8bfff) AM_READWRITE(x68k_rtc_r, x68k_rtc_w) |
| 1981 | 1986 | // AM_RANGE(0xe8c000, 0xe8dfff) AM_READWRITE(x68k_printer_r, x68k_printer_w) |
| 1982 | 1987 | AM_RANGE(0xe8e000, 0xe8ffff) AM_READWRITE(x68k_sysport_r, x68k_sysport_w) |
| 1983 | 1988 | AM_RANGE(0xe90000, 0xe91fff) AM_READWRITE(x68k_fm_r, x68k_fm_w) |
| r11275 | r11276 | |
| 2014 | 2019 | AM_RANGE(0xe84000, 0xe85fff) AM_READWRITE(x68k_dmac_r, x68k_dmac_w) |
| 2015 | 2020 | AM_RANGE(0xe86000, 0xe87fff) AM_READWRITE(x68k_areaset_r, x68k_areaset_w) |
| 2016 | 2021 | AM_RANGE(0xe88000, 0xe89fff) AM_READWRITE(x68k_mfp_r, x68k_mfp_w) |
| 2017 | | AM_RANGE(0xe8a000, 0xe8bfff) AM_DEVREADWRITE("rp5c15", x68k_rtc_r, x68k_rtc_w) |
| 2022 | AM_RANGE(0xe8a000, 0xe8bfff) AM_READWRITE(x68k_rtc_r, x68k_rtc_w) |
| 2018 | 2023 | // AM_RANGE(0xe8c000, 0xe8dfff) AM_READWRITE(x68k_printer_r, x68k_printer_w) |
| 2019 | 2024 | AM_RANGE(0xe8e000, 0xe8ffff) AM_READWRITE(x68k_sysport_r, x68k_sysport_w) |
| 2020 | 2025 | AM_RANGE(0xe90000, 0xe91fff) AM_READWRITE(x68k_fm_r, x68k_fm_w) |
| r11275 | r11276 | |
| 2052 | 2057 | AM_RANGE(0xe84000, 0xe85fff) AM_READWRITE16(x68k_dmac_r, x68k_dmac_w,0xffffffff) |
| 2053 | 2058 | AM_RANGE(0xe86000, 0xe87fff) AM_READWRITE16(x68k_areaset_r, x68k_areaset_w,0xffffffff) |
| 2054 | 2059 | AM_RANGE(0xe88000, 0xe89fff) AM_READWRITE16(x68k_mfp_r, x68k_mfp_w,0xffffffff) |
| 2055 | | AM_RANGE(0xe8a000, 0xe8bfff) AM_DEVREADWRITE16("rp5c15", x68k_rtc_r, x68k_rtc_w,0xffffffff) |
| 2060 | AM_RANGE(0xe8a000, 0xe8bfff) AM_READWRITE16(x68k_rtc_r, x68k_rtc_w,0xffffffff) |
| 2056 | 2061 | // AM_RANGE(0xe8c000, 0xe8dfff) AM_READWRITE(x68k_printer_r, x68k_printer_w) |
| 2057 | 2062 | AM_RANGE(0xe8e000, 0xe8ffff) AM_READWRITE16(x68k_sysport_r, x68k_sysport_w,0xffffffff) |
| 2058 | 2063 | AM_RANGE(0xe90000, 0xe91fff) AM_READWRITE16(x68k_fm_r, x68k_fm_w,0xffffffff) |
| r11275 | r11276 | |
| 2146 | 2151 | OUTPUT_10BITS, |
| 2147 | 2152 | }; |
| 2148 | 2153 | |
| 2149 | | static const struct rp5c15_interface rtc_intf = |
| 2154 | static RP5C15_INTERFACE( rtc_intf ) |
| 2150 | 2155 | { |
| 2151 | | x68k_rtc_alarm_irq |
| 2156 | DEVCB_LINE(x68k_rtc_alarm_irq), |
| 2157 | DEVCB_NULL |
| 2152 | 2158 | }; |
| 2153 | 2159 | |
| 2154 | 2160 | static INPUT_PORTS_START( x68000 ) |
| r11275 | r11276 | |
| 2742 | 2748 | |
| 2743 | 2749 | MCFG_SCC8530_ADD( "scc", 5000000 ) |
| 2744 | 2750 | |
| 2745 | | MCFG_RP5C15_ADD( "rp5c15" , rtc_intf) |
| 2751 | MCFG_RP5C15_ADD(RP5C15_TAG, XTAL_32_768kHz, rtc_intf) |
| 2746 | 2752 | |
| 2747 | 2753 | /* video hardware */ |
| 2748 | 2754 | MCFG_SCREEN_ADD("screen", RASTER) |