src/emu/machine/mccs1850.c
| r0 | r11404 | |
| 1 | /********************************************************************** |
| 2 | |
| 3 | Motorola MCCS1850 Serial 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 | - auto restart |
| 15 | - test mode |
| 16 | |
| 17 | */ |
| 18 | |
| 19 | #include "mccs1850.h" |
| 20 | |
| 21 | |
| 22 | |
| 23 | //************************************************************************** |
| 24 | // MACROS / CONSTANTS |
| 25 | //************************************************************************** |
| 26 | |
| 27 | #define LOG 0 |
| 28 | |
| 29 | |
| 30 | #define RAM_SIZE 0x80 |
| 31 | |
| 32 | |
| 33 | // serial state |
| 34 | enum |
| 35 | { |
| 36 | STATE_ADDRESS, |
| 37 | STATE_DATA |
| 38 | }; |
| 39 | |
| 40 | |
| 41 | // registers |
| 42 | enum |
| 43 | { |
| 44 | REGISTER_COUNTER_LATCH = 0x20, |
| 45 | REGISTER_ALARM_LATCH = 0x24, |
| 46 | REGISTER_STATUS = 0x30, |
| 47 | REGISTER_CONTROL = 0x31, |
| 48 | REGISTER_TEST_1 = 0x3e, |
| 49 | REGISTER_TEST_2 = 0x3f, |
| 50 | REGISTER_TEST_KICK_START_COUNTER = 0x40, |
| 51 | REGISTER_TEST_PRESCALE_COUNTER = 0x43, |
| 52 | REGISTER_TEST_COUNTER_INCREMENT = 0x4f |
| 53 | }; |
| 54 | |
| 55 | |
| 56 | // clock status/interrupt register |
| 57 | #define STATUS_TM 0x20 // test mode |
| 58 | #define STATUS_FTU 0x10 // first time up |
| 59 | #define STATUS_IT 0x08 // interrupt true |
| 60 | #define STATUS_LB 0x04 // low battery |
| 61 | #define STATUS_AI 0x02 // alarm |
| 62 | #define STATUS_RPD 0x01 // request to power down |
| 63 | |
| 64 | |
| 65 | // clock control register |
| 66 | #define CONTROL_STR_STP 0x80 // start/stop |
| 67 | #define CONTROL_PD 0x40 // power down |
| 68 | #define CONTROL_AR 0x20 // auto restart |
| 69 | #define CONTROL_AE 0x10 // alarm enable |
| 70 | #define CONTROL_AC 0x08 // alarm clear |
| 71 | #define CONTROL_FTUC 0x04 // first time up clear |
| 72 | #define CONTROL_LBE 0x02 // low battery enable |
| 73 | #define CONTROL_RPCD 0x01 // request to power down clear |
| 74 | |
| 75 | |
| 76 | // test register 1 |
| 77 | #define TEST1_DIV1 0x80 // divide by 1 |
| 78 | #define TEST1_VOVR 0x40 // Vdd override |
| 79 | #define TEST1_VDDUP 0x20 // Vdd up |
| 80 | #define TEST1_VDDON 0x10 // Vdd on |
| 81 | #define TEST1_VRT 0x08 // valid RAM and time |
| 82 | #define TEST1_LOW_BAT 0x08 // low battery |
| 83 | #define TEST1_PCC 0x04 // programmable capacitor C (10.0 pF) |
| 84 | #define TEST1_PCB 0x02 // programmable capacitor B (5.0 pF) |
| 85 | #define TEST1_PCA 0x01 // programmable capacitor A (2.5 pF) |
| 86 | |
| 87 | |
| 88 | // test register 2 |
| 89 | #define TEST2_OSCBY 0x80 // oscillator bypass |
| 90 | #define TEST2_COMPOVR 0x40 // comparator override |
| 91 | #define TEST2_POR 0x20 // power on reset |
| 92 | #define TEST2_SELTCK 0x10 // select test clock |
| 93 | #define TEST2_FRZ 0x08 // freeze mode |
| 94 | #define TEST2_DV_MASK 0x07 // divider bits select |
| 95 | |
| 96 | |
| 97 | |
| 98 | //************************************************************************** |
| 99 | // GLOBAL VARIABLES |
| 100 | //************************************************************************** |
| 101 | |
| 102 | // device type definition |
| 103 | const device_type MCCS1850 = &device_creator<mccs1850_device>; |
| 104 | |
| 105 | |
| 106 | |
| 107 | //************************************************************************** |
| 108 | // INLINE HELPERS |
| 109 | //************************************************************************** |
| 110 | |
| 111 | //------------------------------------------------- |
| 112 | // check_interrupt - |
| 113 | //------------------------------------------------- |
| 114 | |
| 115 | inline void mccs1850_device::check_interrupt() |
| 116 | { |
| 117 | UINT8 status = m_ram[REGISTER_STATUS]; |
| 118 | UINT8 control = m_ram[REGISTER_CONTROL]; |
| 119 | |
| 120 | bool interrupt = (((status & STATUS_AI) && (control & CONTROL_AE)) // alarm interrupt |
| 121 | || ((status & STATUS_LB) && (control & CONTROL_LBE)) // low battery |
| 122 | || (status & STATUS_FTU) // first time up |
| 123 | || (status & STATUS_RPD)); // request to power down |
| 124 | |
| 125 | if (interrupt) |
| 126 | { |
| 127 | m_ram[REGISTER_STATUS] |= STATUS_IT; |
| 128 | } |
| 129 | else |
| 130 | { |
| 131 | m_ram[REGISTER_STATUS] &= ~STATUS_IT; |
| 132 | } |
| 133 | |
| 134 | devcb_call_write_line(&m_out_int_func, interrupt ? ASSERT_LINE : CLEAR_LINE); |
| 135 | } |
| 136 | |
| 137 | |
| 138 | //------------------------------------------------- |
| 139 | // set_pse_line - |
| 140 | //------------------------------------------------- |
| 141 | |
| 142 | inline void mccs1850_device::set_pse_line(int state) |
| 143 | { |
| 144 | m_pse = state; |
| 145 | |
| 146 | devcb_call_write_line(&m_out_pse_func, m_pse); |
| 147 | } |
| 148 | |
| 149 | |
| 150 | //------------------------------------------------- |
| 151 | // read_register - |
| 152 | //------------------------------------------------- |
| 153 | |
| 154 | inline UINT8 mccs1850_device::read_register(offs_t offset) |
| 155 | { |
| 156 | switch (offset) |
| 157 | { |
| 158 | case REGISTER_COUNTER_LATCH: |
| 159 | // load counter value into latch |
| 160 | m_ram[REGISTER_COUNTER_LATCH] = m_counter >> 24; |
| 161 | m_ram[REGISTER_COUNTER_LATCH + 1] = m_counter >> 16; |
| 162 | m_ram[REGISTER_COUNTER_LATCH + 2] = m_counter >> 8; |
| 163 | m_ram[REGISTER_COUNTER_LATCH + 3] = m_counter; |
| 164 | break; |
| 165 | |
| 166 | case REGISTER_TEST_1: |
| 167 | case REGISTER_TEST_2: |
| 168 | case REGISTER_TEST_KICK_START_COUNTER: |
| 169 | case REGISTER_TEST_PRESCALE_COUNTER: |
| 170 | case REGISTER_TEST_COUNTER_INCREMENT: |
| 171 | logerror("MCCS1850 '%s' Unsupported read from test register %02x!\n", tag(), offset); |
| 172 | break; |
| 173 | } |
| 174 | |
| 175 | return m_ram[offset]; |
| 176 | } |
| 177 | |
| 178 | |
| 179 | //------------------------------------------------- |
| 180 | // write_register - |
| 181 | //------------------------------------------------- |
| 182 | |
| 183 | inline void mccs1850_device::write_register(offs_t offset, UINT8 data) |
| 184 | { |
| 185 | switch (offset) |
| 186 | { |
| 187 | case REGISTER_STATUS: |
| 188 | // read only |
| 189 | break; |
| 190 | |
| 191 | case REGISTER_CONTROL: |
| 192 | if (LOG) logerror("MCCS1850 '%s' Counter %s\n", tag(), (data & CONTROL_STR_STP) ? "Start" : "Stop"); |
| 193 | m_clock_timer->enable(data & CONTROL_STR_STP); |
| 194 | |
| 195 | if (data & CONTROL_PD) |
| 196 | { |
| 197 | if (LOG) logerror("MCCS1850 '%s' Power Down\n", tag()); |
| 198 | set_pse_line(0); |
| 199 | } |
| 200 | |
| 201 | if (data & CONTROL_AR) |
| 202 | { |
| 203 | if (LOG) logerror("MCCS1850 '%s' Auto Restart\n", tag()); |
| 204 | } |
| 205 | |
| 206 | if (data & CONTROL_AC) |
| 207 | { |
| 208 | if (LOG) logerror("MCCS1850 '%s' Alarm Clear\n", tag()); |
| 209 | m_ram[REGISTER_STATUS] &= ~STATUS_AI; |
| 210 | } |
| 211 | |
| 212 | if (data & CONTROL_FTUC) |
| 213 | { |
| 214 | if (LOG) logerror("MCCS1850 '%s' First Time Up Clear\n", tag()); |
| 215 | m_ram[REGISTER_STATUS] &= ~STATUS_FTU; |
| 216 | } |
| 217 | |
| 218 | if (data & CONTROL_RPCD) |
| 219 | { |
| 220 | if (LOG) logerror("MCCS1850 '%s' Request to Power Down Clear\n", tag()); |
| 221 | m_ram[REGISTER_STATUS] &= ~STATUS_RPD; |
| 222 | } |
| 223 | |
| 224 | m_ram[REGISTER_CONTROL] = data & 0xb2; |
| 225 | |
| 226 | check_interrupt(); |
| 227 | break; |
| 228 | |
| 229 | case REGISTER_TEST_1: |
| 230 | case REGISTER_TEST_2: |
| 231 | case REGISTER_TEST_KICK_START_COUNTER: |
| 232 | case REGISTER_TEST_PRESCALE_COUNTER: |
| 233 | case REGISTER_TEST_COUNTER_INCREMENT: |
| 234 | logerror("MCCS1850 '%s' Unsupported write to test register %02x!\n", tag(), offset); |
| 235 | break; |
| 236 | |
| 237 | default: |
| 238 | m_ram[offset] = data; |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | |
| 243 | //------------------------------------------------- |
| 244 | // advance_seconds - |
| 245 | //------------------------------------------------- |
| 246 | |
| 247 | inline void mccs1850_device::advance_seconds() |
| 248 | { |
| 249 | UINT32 alarm = (m_ram[REGISTER_ALARM_LATCH] << 24) | (m_ram[REGISTER_ALARM_LATCH + 1] << 16) | (m_ram[REGISTER_ALARM_LATCH + 2] << 8) | m_ram[REGISTER_ALARM_LATCH + 3]; |
| 250 | |
| 251 | m_counter++; |
| 252 | |
| 253 | if (m_counter == alarm) |
| 254 | { |
| 255 | if (m_pse) |
| 256 | { |
| 257 | // trigger alarm |
| 258 | m_ram[REGISTER_STATUS] |= STATUS_AI; |
| 259 | |
| 260 | check_interrupt(); |
| 261 | } |
| 262 | else |
| 263 | { |
| 264 | // wake up |
| 265 | set_pse_line(1); |
| 266 | } |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | |
| 271 | |
| 272 | //************************************************************************** |
| 273 | // LIVE DEVICE |
| 274 | //************************************************************************** |
| 275 | |
| 276 | //------------------------------------------------- |
| 277 | // mccs1850_device - constructor |
| 278 | //------------------------------------------------- |
| 279 | |
| 280 | mccs1850_device::mccs1850_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 281 | : device_t(mconfig, MCCS1850, "MCCS1850", tag, owner, clock), |
| 282 | device_rtc_interface(mconfig, *this), |
| 283 | device_nvram_interface(mconfig, *this), |
| 284 | m_pse(1), |
| 285 | m_ce(0), |
| 286 | m_sck(0), |
| 287 | m_sdo(0), |
| 288 | m_sdi(0), |
| 289 | m_state(STATE_ADDRESS), |
| 290 | m_bits(0) |
| 291 | { |
| 292 | } |
| 293 | |
| 294 | |
| 295 | //------------------------------------------------- |
| 296 | // device_config_complete - perform any |
| 297 | // operations now that the configuration is |
| 298 | // complete |
| 299 | //------------------------------------------------- |
| 300 | |
| 301 | void mccs1850_device::device_config_complete() |
| 302 | { |
| 303 | // inherit a copy of the static data |
| 304 | const mccs1850_interface *intf = reinterpret_cast<const mccs1850_interface *>(static_config()); |
| 305 | if (intf != NULL) |
| 306 | *static_cast<mccs1850_interface *>(this) = *intf; |
| 307 | |
| 308 | // or initialize to defaults if none provided |
| 309 | else |
| 310 | { |
| 311 | memset(&m_out_int_cb, 0, sizeof(m_out_int_cb)); |
| 312 | memset(&m_out_pse_cb, 0, sizeof(m_out_pse_cb)); |
| 313 | memset(&m_out_nuc_cb, 0, sizeof(m_out_nuc_cb)); |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | |
| 318 | //------------------------------------------------- |
| 319 | // device_start - device-specific startup |
| 320 | //------------------------------------------------- |
| 321 | |
| 322 | void mccs1850_device::device_start() |
| 323 | { |
| 324 | // resolve callbacks |
| 325 | devcb_resolve_write_line(&m_out_int_func, &m_out_int_cb, this); |
| 326 | devcb_resolve_write_line(&m_out_pse_func, &m_out_pse_cb, this); |
| 327 | devcb_resolve_write_line(&m_out_nuc_func, &m_out_nuc_cb, this); |
| 328 | |
| 329 | // allocate timers |
| 330 | m_clock_timer = timer_alloc(TIMER_CLOCK); |
| 331 | m_clock_timer->adjust(attotime::from_hz(clock() / 32768), 0, attotime::from_hz(clock() / 32768)); |
| 332 | |
| 333 | // state saving |
| 334 | save_item(NAME(m_pse)); |
| 335 | save_item(NAME(m_counter)); |
| 336 | save_item(NAME(m_ce)); |
| 337 | save_item(NAME(m_sck)); |
| 338 | save_item(NAME(m_sdo)); |
| 339 | save_item(NAME(m_sdi)); |
| 340 | save_item(NAME(m_state)); |
| 341 | save_item(NAME(m_address)); |
| 342 | save_item(NAME(m_bits)); |
| 343 | save_item(NAME(m_shift)); |
| 344 | } |
| 345 | |
| 346 | |
| 347 | //------------------------------------------------- |
| 348 | // device_reset - device-specific reset |
| 349 | //------------------------------------------------- |
| 350 | |
| 351 | void mccs1850_device::device_reset() |
| 352 | { |
| 353 | memset(m_ram, 0xff, RAM_SIZE); |
| 354 | |
| 355 | m_ram[REGISTER_STATUS] = 0x80 | STATUS_FTU; |
| 356 | m_ram[REGISTER_CONTROL] = 0x00; |
| 357 | } |
| 358 | |
| 359 | |
| 360 | //------------------------------------------------- |
| 361 | // device_timer - handler timer events |
| 362 | //------------------------------------------------- |
| 363 | |
| 364 | void mccs1850_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 365 | { |
| 366 | switch (id) |
| 367 | { |
| 368 | case TIMER_CLOCK: |
| 369 | advance_seconds(); |
| 370 | break; |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | |
| 375 | //------------------------------------------------- |
| 376 | // rtc_set_time - called to initialize the RTC to |
| 377 | // a known state |
| 378 | //------------------------------------------------- |
| 379 | |
| 380 | void mccs1850_device::rtc_set_time(int year, int month, int day, int day_of_week, int hour, int minute, int second) |
| 381 | { |
| 382 | } |
| 383 | |
| 384 | |
| 385 | //------------------------------------------------- |
| 386 | // nvram_default - called to initialize NVRAM to |
| 387 | // its default state |
| 388 | //------------------------------------------------- |
| 389 | |
| 390 | void mccs1850_device::nvram_default() |
| 391 | { |
| 392 | memset(m_ram, 0xff, RAM_SIZE); |
| 393 | } |
| 394 | |
| 395 | |
| 396 | //------------------------------------------------- |
| 397 | // nvram_read - called to read NVRAM from the |
| 398 | // .nv file |
| 399 | //------------------------------------------------- |
| 400 | |
| 401 | void mccs1850_device::nvram_read(emu_file &file) |
| 402 | { |
| 403 | file.read(m_ram, RAM_SIZE); |
| 404 | } |
| 405 | |
| 406 | |
| 407 | //------------------------------------------------- |
| 408 | // nvram_write - called to write NVRAM to the |
| 409 | // .nv file |
| 410 | //------------------------------------------------- |
| 411 | |
| 412 | void mccs1850_device::nvram_write(emu_file &file) |
| 413 | { |
| 414 | file.write(m_ram, RAM_SIZE); |
| 415 | } |
| 416 | |
| 417 | |
| 418 | //------------------------------------------------- |
| 419 | // ce_w - chip enable write |
| 420 | //------------------------------------------------- |
| 421 | |
| 422 | WRITE_LINE_MEMBER( mccs1850_device::ce_w ) |
| 423 | { |
| 424 | m_ce = state; |
| 425 | |
| 426 | if (!m_ce) |
| 427 | { |
| 428 | m_state = STATE_ADDRESS; |
| 429 | m_bits = 0; |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | |
| 434 | //------------------------------------------------- |
| 435 | // sck_w - serial clock write |
| 436 | //------------------------------------------------- |
| 437 | |
| 438 | WRITE_LINE_MEMBER( mccs1850_device::sck_w ) |
| 439 | { |
| 440 | if (!m_ce) return; |
| 441 | |
| 442 | switch (m_state) |
| 443 | { |
| 444 | case STATE_ADDRESS: |
| 445 | if (m_sck && !state) |
| 446 | { |
| 447 | m_address <<= 1; |
| 448 | m_address |= m_sdi; |
| 449 | m_bits++; |
| 450 | |
| 451 | if (m_bits == 8) |
| 452 | { |
| 453 | if (LOG) logerror("MCCS1850 '%s' %s Address %u\n", tag(), BIT(m_address, 7) ? "Read" : "Write", m_address & 0x7f); |
| 454 | |
| 455 | m_bits = 0; |
| 456 | m_state = STATE_DATA; |
| 457 | |
| 458 | if (BIT(m_address, 7)) |
| 459 | { |
| 460 | m_shift = read_register(m_address & 0x7f); |
| 461 | |
| 462 | if (LOG) logerror("MCCS1850 '%s' Data Out %02x\n", tag(), m_shift); |
| 463 | } |
| 464 | } |
| 465 | } |
| 466 | break; |
| 467 | |
| 468 | case STATE_DATA: |
| 469 | if (!BIT(m_address, 7) && m_sck && !state) |
| 470 | { |
| 471 | // shift data in |
| 472 | m_shift <<= 1; |
| 473 | m_shift |= m_sdi; |
| 474 | m_bits++; |
| 475 | |
| 476 | if (m_bits == 8) |
| 477 | { |
| 478 | if (LOG) logerror("MCCS1850 '%s' Data In %02x\n", tag(), m_shift); |
| 479 | |
| 480 | write_register(m_address & 0x7f, m_shift); |
| 481 | |
| 482 | m_bits = 0; |
| 483 | |
| 484 | // increment address counter |
| 485 | m_address++; |
| 486 | m_address &= 0x7f; |
| 487 | } |
| 488 | } |
| 489 | else if (BIT(m_address, 7) && !m_sck && state) |
| 490 | { |
| 491 | // shift data out |
| 492 | m_sdo = BIT(m_shift, 7); |
| 493 | m_shift <<= 1; |
| 494 | m_bits++; |
| 495 | |
| 496 | if (m_bits == 8) |
| 497 | { |
| 498 | m_bits = 0; |
| 499 | |
| 500 | // increment address counter |
| 501 | m_address++; |
| 502 | m_address &= 0x7f; |
| 503 | m_shift = read_register(m_address & 0x7f); |
| 504 | } |
| 505 | } |
| 506 | break; |
| 507 | } |
| 508 | |
| 509 | m_sck = state; |
| 510 | } |
| 511 | |
| 512 | |
| 513 | //------------------------------------------------- |
| 514 | // sdo_r - serial data out read |
| 515 | //------------------------------------------------- |
| 516 | |
| 517 | READ_LINE_MEMBER( mccs1850_device::sdo_r ) |
| 518 | { |
| 519 | return m_sdo; |
| 520 | } |
| 521 | |
| 522 | |
| 523 | //------------------------------------------------- |
| 524 | // sdi_w - serial data in write |
| 525 | //------------------------------------------------- |
| 526 | |
| 527 | WRITE_LINE_MEMBER( mccs1850_device::sdi_w ) |
| 528 | { |
| 529 | m_sdi = state; |
| 530 | } |
| 531 | |
| 532 | |
| 533 | //------------------------------------------------- |
| 534 | // pwrsw_w - power switch write |
| 535 | //------------------------------------------------- |
| 536 | |
| 537 | WRITE_LINE_MEMBER( mccs1850_device::pwrsw_w ) |
| 538 | { |
| 539 | if (!state) |
| 540 | { |
| 541 | if (m_pse) |
| 542 | { |
| 543 | // request to power down |
| 544 | m_ram[REGISTER_STATUS] |= STATUS_RPD; |
| 545 | check_interrupt(); |
| 546 | } |
| 547 | |
| 548 | set_pse_line(1); |
| 549 | } |
| 550 | } |
| 551 | |
| 552 | |
| 553 | //------------------------------------------------- |
| 554 | // por_w - power on reset write |
| 555 | //------------------------------------------------- |
| 556 | |
| 557 | WRITE_LINE_MEMBER( mccs1850_device::por_w ) |
| 558 | { |
| 559 | if (!state) |
| 560 | { |
| 561 | device_reset(); |
| 562 | } |
| 563 | } |
| 564 | |
| 565 | |
| 566 | //------------------------------------------------- |
| 567 | // test_w - test mode write |
| 568 | //------------------------------------------------- |
| 569 | |
| 570 | WRITE_LINE_MEMBER( mccs1850_device::test_w ) |
| 571 | { |
| 572 | if (state) |
| 573 | { |
| 574 | if (LOG) logerror("MCCS1850 '%s' Test Mode\n", tag()); |
| 575 | |
| 576 | m_ram[REGISTER_STATUS] |= STATUS_TM; |
| 577 | } |
| 578 | else |
| 579 | { |
| 580 | if (LOG) logerror("MCCS1850 '%s' Normal Operation\n", tag()); |
| 581 | |
| 582 | m_ram[REGISTER_STATUS] &= ~STATUS_TM; |
| 583 | } |
| 584 | } |
src/emu/machine/mccs1850.h
| r0 | r11404 | |
| 1 | /********************************************************************** |
| 2 | |
| 3 | Motorola MCCS1850 Serial Real-Time Clock emulation |
| 4 | |
| 5 | Copyright MESS Team. |
| 6 | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | |
| 8 | ********************************************************************** |
| 9 | _____ _____ |
| 10 | Vbat 1 |* \_/ | 16 Vdd |
| 11 | _POR 2 | | 15 TEST |
| 12 | _INT 3 | | 14 XTAL1 |
| 13 | SCK 4 | MCCS1850 | 13 XTAL2 |
| 14 | SDI 5 | | 12 _PWRSW |
| 15 | SDO 6 | | 11 NUC |
| 16 | CE 7 | | 10 _PSE |
| 17 | Vss 8 |_____________| 9 PSE |
| 18 | |
| 19 | **********************************************************************/ |
| 20 | |
| 21 | #pragma once |
| 22 | |
| 23 | #ifndef __MCCS1850__ |
| 24 | #define __MCCS1850__ |
| 25 | |
| 26 | #include "emu.h" |
| 27 | |
| 28 | |
| 29 | |
| 30 | //************************************************************************** |
| 31 | // INTERFACE CONFIGURATION MACROS |
| 32 | //************************************************************************** |
| 33 | |
| 34 | #define MCFG_MCCS1850_ADD(_tag, _clock, _config) \ |
| 35 | MCFG_DEVICE_ADD(_tag, MCCS1850, _clock) \ |
| 36 | MCFG_DEVICE_CONFIG(_config) |
| 37 | |
| 38 | |
| 39 | #define MCCS1850_INTERFACE(name) \ |
| 40 | const mccs1850_interface (name) = |
| 41 | |
| 42 | |
| 43 | |
| 44 | //************************************************************************** |
| 45 | // TYPE DEFINITIONS |
| 46 | //************************************************************************** |
| 47 | |
| 48 | // ======================> mccs1850_interface |
| 49 | |
| 50 | struct mccs1850_interface |
| 51 | { |
| 52 | devcb_write_line m_out_int_cb; |
| 53 | devcb_write_line m_out_pse_cb; |
| 54 | devcb_write_line m_out_nuc_cb; |
| 55 | }; |
| 56 | |
| 57 | |
| 58 | |
| 59 | // ======================> mccs1850_device |
| 60 | |
| 61 | class mccs1850_device : public device_t, |
| 62 | public device_rtc_interface, |
| 63 | public device_nvram_interface, |
| 64 | public mccs1850_interface |
| 65 | { |
| 66 | public: |
| 67 | // construction/destruction |
| 68 | mccs1850_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 69 | |
| 70 | DECLARE_WRITE_LINE_MEMBER( ce_w ); |
| 71 | DECLARE_WRITE_LINE_MEMBER( sck_w ); |
| 72 | DECLARE_READ_LINE_MEMBER( sdo_r ); |
| 73 | DECLARE_WRITE_LINE_MEMBER( sdi_w ); |
| 74 | DECLARE_WRITE_LINE_MEMBER( pwrsw_w ); |
| 75 | DECLARE_WRITE_LINE_MEMBER( por_w ); |
| 76 | DECLARE_WRITE_LINE_MEMBER( test_w ); |
| 77 | |
| 78 | protected: |
| 79 | // device-level overrides |
| 80 | virtual void device_config_complete(); |
| 81 | virtual void device_start(); |
| 82 | virtual void device_reset(); |
| 83 | virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr); |
| 84 | |
| 85 | // device_rtc_interface overrides |
| 86 | virtual void rtc_set_time(int year, int month, int day, int day_of_week, int hour, int minute, int second); |
| 87 | virtual bool rtc_is_year_2000_compliant() { return false; } |
| 88 | |
| 89 | // device_nvram_interface overrides |
| 90 | virtual void nvram_default(); |
| 91 | virtual void nvram_read(emu_file &file); |
| 92 | virtual void nvram_write(emu_file &file); |
| 93 | |
| 94 | private: |
| 95 | inline void check_interrupt(); |
| 96 | inline void set_pse_line(int state); |
| 97 | inline UINT8 read_register(offs_t offset); |
| 98 | inline void write_register(offs_t offset, UINT8 data); |
| 99 | inline void advance_seconds(); |
| 100 | |
| 101 | static const device_timer_id TIMER_CLOCK = 0; |
| 102 | |
| 103 | devcb_resolved_write_line m_out_int_func; |
| 104 | devcb_resolved_write_line m_out_pse_func; |
| 105 | devcb_resolved_write_line m_out_nuc_func; |
| 106 | |
| 107 | UINT8 m_ram[0x80]; // RAM |
| 108 | |
| 109 | // power supply |
| 110 | int m_pse; // power supply enable |
| 111 | |
| 112 | // counter |
| 113 | UINT32 m_counter; // seconds counter |
| 114 | |
| 115 | // serial interface |
| 116 | int m_ce; // chip enable |
| 117 | int m_sck; // serial clock |
| 118 | int m_sdo; // serial data out |
| 119 | int m_sdi; // serial data in |
| 120 | int m_state; // serial interface state |
| 121 | UINT8 m_address; // address counter |
| 122 | int m_bits; // bit counter |
| 123 | UINT8 m_shift; // shift register |
| 124 | |
| 125 | // timers |
| 126 | emu_timer *m_clock_timer; |
| 127 | }; |
| 128 | |
| 129 | |
| 130 | // device type definition |
| 131 | extern const device_type MCCS1850; |
| 132 | |
| 133 | |
| 134 | |
| 135 | #endif |
src/mess/drivers/next.c
| r11403 | r11404 | |
| 4 | 4 | |
| 5 | 5 | 05/11/2009 Skeleton driver. |
| 6 | 6 | |
| 7 | | TODO: |
| 8 | | - needs MCS1850 RTC device emulation to remove the ROM patch; |
| 9 | | |
| 10 | 7 | DASM notes: |
| 11 | 8 | - Jumping to 0x21ee means that the system POST failed |
| 12 | 9 | - 0x258c: ROM test (check with 0x1a) |
| 13 | 10 | |
| 14 | 11 | ****************************************************************************/ |
| 15 | 12 | |
| 16 | | #include "emu.h" |
| 17 | | #include "cpu/m68000/m68000.h" |
| 18 | | #include "imagedev/flopdrv.h" |
| 13 | #include "includes/next.h" |
| 19 | 14 | |
| 20 | | |
| 21 | | class next_state : public driver_device |
| 15 | bool next_state::screen_update(screen_device &screen, bitmap_t &bitmap, const rectangle &cliprect) |
| 22 | 16 | { |
| 23 | | public: |
| 24 | | next_state(const machine_config &mconfig, device_type type, const char *tag) |
| 25 | | : driver_device(mconfig, type, tag) { } |
| 26 | | |
| 27 | | UINT32 m_scr2; |
| 28 | | UINT32 m_irq_status; |
| 29 | | UINT32 m_irq_mask; |
| 30 | | UINT32 *m_vram; |
| 31 | | }; |
| 32 | | |
| 33 | | static VIDEO_START( next ) |
| 34 | | { |
| 35 | | } |
| 36 | | |
| 37 | | static SCREEN_UPDATE( next ) |
| 38 | | { |
| 39 | | next_state *state = screen->machine().driver_data<next_state>(); |
| 40 | 17 | UINT32 count; |
| 41 | 18 | int x,y,xi; |
| 42 | 19 | |
| r11403 | r11404 | |
| 48 | 25 | { |
| 49 | 26 | for(xi=0;xi<16;xi++) |
| 50 | 27 | { |
| 51 | | UINT8 pen = (state->m_vram[count] >> (30-(xi*2))) & 0x3; |
| 28 | UINT8 pen = (m_vram[count] >> (30-(xi*2))) & 0x3; |
| 52 | 29 | |
| 53 | 30 | pen ^= 3; |
| 54 | 31 | |
| 55 | | if((x+xi)>screen->machine().primary_screen->visible_area().max_x || (y)>screen->machine().primary_screen->visible_area().max_y) |
| 32 | if((x+xi)>screen.machine().primary_screen->visible_area().max_x || (y)>screen.machine().primary_screen->visible_area().max_y) |
| 56 | 33 | continue; |
| 57 | 34 | |
| 58 | | *BITMAP_ADDR16(bitmap, y, x+xi) = screen->machine().pens[pen]; |
| 35 | *BITMAP_ADDR16(&bitmap, y, x+xi) = screen.machine().pens[pen]; |
| 59 | 36 | } |
| 60 | 37 | |
| 61 | 38 | count++; |
| r11403 | r11404 | |
| 66 | 43 | } |
| 67 | 44 | |
| 68 | 45 | /* Dummy catcher for any unknown r/w */ |
| 69 | | static READ8_HANDLER( next_io_r ) |
| 46 | READ8_MEMBER( next_state::io_r ) |
| 70 | 47 | { |
| 71 | | if(!space->debugger_access()) |
| 48 | if(!space.debugger_access()) |
| 72 | 49 | printf("Read I/O register %08x\n",offset+0x02000000); |
| 73 | 50 | |
| 74 | 51 | return 0xff; |
| 75 | 52 | } |
| 76 | 53 | |
| 77 | | static WRITE8_HANDLER( next_io_w ) |
| 54 | WRITE8_MEMBER( next_state::io_w ) |
| 78 | 55 | { |
| 79 | | if(!space->debugger_access()) |
| 56 | if(!space.debugger_access()) |
| 80 | 57 | printf("Write I/O register %08x %02x\n",offset+0x02000000,data); |
| 81 | 58 | } |
| 82 | 59 | |
| 83 | 60 | /* map ROM at 0x01000000-0x0101ffff? */ |
| 84 | | static READ32_HANDLER( next_rom_map_r ) |
| 61 | READ32_MEMBER( next_state::rom_map_r ) |
| 85 | 62 | { |
| 86 | | if(!space->debugger_access()) |
| 87 | | printf("%08x ROM MAP?\n",cpu_get_pc(&space->device())); |
| 63 | if(!space.debugger_access()) |
| 64 | printf("%08x ROM MAP?\n",cpu_get_pc(&space.device())); |
| 88 | 65 | return 0x01000000; |
| 89 | 66 | } |
| 90 | 67 | |
| 91 | | static READ32_HANDLER( next_scr2_r ) |
| 68 | READ32_MEMBER( next_state::scr2_r ) |
| 92 | 69 | { |
| 93 | | next_state *state = space->machine().driver_data<next_state>(); |
| 94 | | if(!space->debugger_access()) |
| 95 | | printf("%08x\n",cpu_get_pc(&space->device())); |
| 70 | if(!space.debugger_access()) |
| 71 | printf("%08x\n",cpu_get_pc(&space.device())); |
| 96 | 72 | /* |
| 97 | 73 | x--- ---- ---- ---- ---- ---- ---- ---- dsp reset |
| 98 | 74 | -x-- ---- ---- ---- ---- ---- ---- ---- dsp block end |
| r11403 | r11404 | |
| 115 | 91 | ---- ---- ---- ---- ---- ---- ---- ---x led |
| 116 | 92 | */ |
| 117 | 93 | |
| 118 | | return state->m_scr2; |
| 94 | UINT32 data = m_scr2 & 0xfffffbff; |
| 95 | |
| 96 | data |= m_rtc->sdo_r() << 10; |
| 97 | |
| 98 | return data; |
| 119 | 99 | } |
| 120 | 100 | |
| 121 | | static WRITE32_HANDLER( next_scr2_w ) |
| 101 | WRITE32_MEMBER( next_state::scr2_w ) |
| 122 | 102 | { |
| 123 | | next_state *state = space->machine().driver_data<next_state>(); |
| 124 | | if(!space->debugger_access()) |
| 125 | | printf("%08x %08x\n",cpu_get_pc(&space->device()),data); |
| 126 | | COMBINE_DATA(&state->m_scr2); |
| 103 | if(!space.debugger_access()) |
| 104 | printf("%08x %08x\n",cpu_get_pc(&space.device()),data); |
| 105 | COMBINE_DATA(&m_scr2); |
| 106 | |
| 107 | m_rtc->ce_w(BIT(m_scr2, 8)); |
| 108 | m_rtc->sdi_w(BIT(m_scr2, 10)); |
| 109 | m_rtc->sck_w(BIT(m_scr2, 9)); |
| 127 | 110 | } |
| 128 | 111 | |
| 129 | | static READ32_HANDLER( next_scr1_r ) |
| 112 | READ32_MEMBER( next_state::scr1_r ) |
| 130 | 113 | { |
| 131 | 114 | /* |
| 132 | 115 | xxxx ---- ---- ---- ---- ---- ---- ---- slot ID |
| r11403 | r11404 | |
| 141 | 124 | return 0x00012002; // TODO |
| 142 | 125 | } |
| 143 | 126 | |
| 144 | | static READ32_HANDLER( next_irq_status_r ) |
| 127 | READ32_MEMBER( next_state::irq_status_r ) |
| 145 | 128 | { |
| 146 | | next_state *state = space->machine().driver_data<next_state>(); |
| 147 | | |
| 148 | | return state->m_irq_status; |
| 129 | return m_irq_status; |
| 149 | 130 | } |
| 150 | 131 | |
| 151 | | static WRITE32_HANDLER( next_irq_status_w ) |
| 132 | WRITE32_MEMBER( next_state::irq_status_w ) |
| 152 | 133 | { |
| 153 | | next_state *state = space->machine().driver_data<next_state>(); |
| 154 | | |
| 155 | | COMBINE_DATA(&state->m_irq_status); |
| 134 | COMBINE_DATA(&m_irq_status); |
| 156 | 135 | } |
| 157 | 136 | |
| 158 | | static READ32_HANDLER( next_irq_mask_r ) |
| 137 | READ32_MEMBER( next_state::irq_mask_r ) |
| 159 | 138 | { |
| 160 | | next_state *state = space->machine().driver_data<next_state>(); |
| 161 | | |
| 162 | | return state->m_irq_mask; |
| 139 | return m_irq_mask; |
| 163 | 140 | } |
| 164 | 141 | |
| 165 | | static WRITE32_HANDLER( next_irq_mask_w ) |
| 142 | WRITE32_MEMBER( next_state::irq_mask_w ) |
| 166 | 143 | { |
| 167 | | next_state *state = space->machine().driver_data<next_state>(); |
| 168 | | |
| 169 | | COMBINE_DATA(&state->m_irq_mask); |
| 144 | COMBINE_DATA(&m_irq_mask); |
| 170 | 145 | } |
| 171 | 146 | |
| 172 | | static ADDRESS_MAP_START(next_mem, AS_PROGRAM, 32) |
| 147 | static ADDRESS_MAP_START( next_mem, AS_PROGRAM, 32, next_state ) |
| 173 | 148 | AM_RANGE(0x00000000, 0x0001ffff) AM_ROM AM_REGION("user1", 0) |
| 174 | 149 | AM_RANGE(0x01000000, 0x0101ffff) AM_ROM AM_REGION("user1", 0) |
| 175 | | AM_RANGE(0x02007000, 0x02007003) AM_MIRROR(0x100000) AM_READWRITE(next_irq_status_r,next_irq_status_w) |
| 176 | | AM_RANGE(0x02007800, 0x02007803) AM_MIRROR(0x100000) AM_READWRITE(next_irq_mask_r,next_irq_mask_w) |
| 150 | AM_RANGE(0x02007000, 0x02007003) AM_MIRROR(0x100000) AM_READWRITE(irq_status_r,irq_status_w) |
| 151 | AM_RANGE(0x02007800, 0x02007803) AM_MIRROR(0x100000) AM_READWRITE(irq_mask_r,irq_mask_w) |
| 177 | 152 | |
| 178 | | AM_RANGE(0x0200c000, 0x0200c003) AM_MIRROR(0x100000) AM_READ(next_scr1_r) |
| 179 | | AM_RANGE(0x0200c800, 0x0200c803) AM_MIRROR(0x100000) AM_READ(next_rom_map_r) |
| 180 | | AM_RANGE(0x0200d000, 0x0200d003) AM_MIRROR(0x100000) AM_READWRITE(next_scr2_r,next_scr2_w) |
| 153 | AM_RANGE(0x0200c000, 0x0200c003) AM_MIRROR(0x100000) AM_READ(scr1_r) |
| 154 | AM_RANGE(0x0200c800, 0x0200c803) AM_MIRROR(0x100000) AM_READ(rom_map_r) |
| 155 | AM_RANGE(0x0200d000, 0x0200d003) AM_MIRROR(0x100000) AM_READWRITE(scr2_r,scr2_w) |
| 181 | 156 | |
| 182 | | AM_RANGE(0x02000000, 0x0201ffff) AM_MIRROR(0x100000) AM_READWRITE8(next_io_r,next_io_w,0xffffffff) //intentional fall-through |
| 157 | AM_RANGE(0x02000000, 0x0201ffff) AM_MIRROR(0x100000) AM_READWRITE8(io_r,io_w,0xffffffff) //intentional fall-through |
| 183 | 158 | |
| 184 | 159 | AM_RANGE(0x04000000, 0x07ffffff) AM_RAM //work ram |
| 185 | 160 | |
| 186 | | AM_RANGE(0x0b000000, 0x0b03ffff) AM_RAM AM_BASE_MEMBER(next_state, m_vram) //vram |
| 161 | AM_RANGE(0x0b000000, 0x0b03ffff) AM_RAM AM_BASE(m_vram) //vram |
| 187 | 162 | ADDRESS_MAP_END |
| 188 | 163 | |
| 189 | 164 | /* Input ports */ |
| 190 | 165 | static INPUT_PORTS_START( next ) |
| 191 | 166 | INPUT_PORTS_END |
| 192 | 167 | |
| 193 | | |
| 194 | | static MACHINE_RESET(next) |
| 195 | | { |
| 196 | | } |
| 197 | | |
| 198 | 168 | static PALETTE_INIT(next) |
| 199 | 169 | { |
| 200 | 170 | /* TODO: simplify this*/ |
| r11403 | r11404 | |
| 204 | 174 | palette_set_color(machine, 3,MAKE_RGB(0xff,0xff,0xff)); |
| 205 | 175 | } |
| 206 | 176 | |
| 177 | static MCCS1850_INTERFACE( rtc_intf ) |
| 178 | { |
| 179 | DEVCB_NULL, // RTCINT |
| 180 | DEVCB_NULL, |
| 181 | DEVCB_NULL |
| 182 | }; |
| 207 | 183 | |
| 208 | 184 | static const floppy_config next_floppy_config = |
| 209 | 185 | { |
| r11403 | r11404 | |
| 222 | 198 | MCFG_CPU_ADD("maincpu",M68030, XTAL_25MHz) |
| 223 | 199 | MCFG_CPU_PROGRAM_MAP(next_mem) |
| 224 | 200 | |
| 225 | | MCFG_MACHINE_RESET(next) |
| 226 | | |
| 227 | 201 | /* video hardware */ |
| 228 | 202 | MCFG_SCREEN_ADD("screen", RASTER) |
| 229 | 203 | MCFG_SCREEN_REFRESH_RATE(60) |
| r11403 | r11404 | |
| 231 | 205 | MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) |
| 232 | 206 | MCFG_SCREEN_SIZE(1120, 832) |
| 233 | 207 | MCFG_SCREEN_VISIBLE_AREA(0, 1120-1, 0, 832-1) |
| 234 | | MCFG_SCREEN_UPDATE(next) |
| 235 | 208 | |
| 236 | 209 | MCFG_PALETTE_LENGTH(4) |
| 237 | 210 | MCFG_PALETTE_INIT(next) |
| 238 | 211 | |
| 239 | | MCFG_VIDEO_START(next) |
| 240 | | |
| 241 | 212 | // devices |
| 213 | MCFG_MCCS1850_ADD(MCCS1850_TAG, XTAL_32_768kHz, rtc_intf) |
| 242 | 214 | MCFG_FLOPPY_DRIVE_ADD(FLOPPY_0, next_floppy_config) |
| 243 | 215 | |
| 244 | 216 | // software list |
| r11403 | r11404 | |
| 300 | 272 | COMP( 1987, next, 0, 0, next, next, next, "Next Software Inc", "NeXT Computer", GAME_NOT_WORKING | GAME_NO_SOUND) |
| 301 | 273 | COMP( 1990, nextnt, next, 0, next040, next, 0, "Next Software Inc", "NeXT (Non Turbo)", GAME_NOT_WORKING | GAME_NO_SOUND) |
| 302 | 274 | COMP( 1992, nexttrb,next, 0, next040, next, 0, "Next Software Inc", "NeXT (Turbo)", GAME_NOT_WORKING | GAME_NO_SOUND) |
| 303 | | |