src/emu/machine/upd1990a.c
| r11366 | r11367 | |
| 15 | 15 | |
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | | #include "emu.h" |
| 19 | 18 | #include "upd1990a.h" |
| 20 | 19 | |
| 21 | 20 | |
| r11366 | r11367 | |
| 40 | 39 | MODE_TP_64HZ_SET, |
| 41 | 40 | MODE_TP_256HZ_SET, |
| 42 | 41 | MODE_TP_2048HZ_SET, |
| 43 | | MODE_TEST, |
| 42 | MODE_TEST |
| 44 | 43 | }; |
| 45 | 44 | |
| 46 | 45 | |
| r11366 | r11367 | |
| 161 | 160 | // or initialize to defaults if none provided |
| 162 | 161 | else |
| 163 | 162 | { |
| 164 | | // memset(&in_pa_cb, 0, sizeof(in_pa_cb)); |
| 163 | memset(&m_out_data_cb, 0, sizeof(m_out_data_cb)); |
| 164 | memset(&m_out_tp_cb, 0, sizeof(m_out_tp_cb)); |
| 165 | 165 | } |
| 166 | 166 | } |
| 167 | 167 | |
| r11366 | r11367 | |
| 178 | 178 | |
| 179 | 179 | // allocate timers |
| 180 | 180 | m_timer_clock = timer_alloc(TIMER_CLOCK); |
| 181 | | m_timer_clock->adjust(attotime::zero, 0, attotime::from_hz(1)); |
| 181 | m_timer_clock->adjust(attotime::from_hz(clock() / 32768), 0, attotime::from_hz(clock() / 32768)); |
| 182 | 182 | m_timer_tp = timer_alloc(TIMER_TP); |
| 183 | 183 | m_timer_data_out = timer_alloc(TIMER_DATA_OUT); |
| 184 | 184 | |
| r11366 | r11367 | |
| 231 | 231 | case TIMER_TP: |
| 232 | 232 | m_tp = !m_tp; |
| 233 | 233 | |
| 234 | | if (LOG) logerror("UPD1990A TP %u\n", m_tp); |
| 234 | if (LOG) logerror("uPD1990A '%s' TP %u\n", tag(), m_tp); |
| 235 | 235 | |
| 236 | 236 | devcb_call_write_line(&m_out_tp_func, m_tp); |
| 237 | 237 | break; |
| r11366 | r11367 | |
| 239 | 239 | case TIMER_DATA_OUT: |
| 240 | 240 | m_data_out = !m_data_out; |
| 241 | 241 | |
| 242 | | if (LOG) logerror("UPD1990A DATA OUT TICK %u\n", m_data_out); |
| 242 | if (LOG) logerror("uPD1990A '%s' DATA OUT TICK %u\n", tag(), m_data_out); |
| 243 | 243 | |
| 244 | 244 | devcb_call_write_line(&m_out_data_func, m_data_out); |
| 245 | 245 | break; |
| r11366 | r11367 | |
| 268 | 268 | |
| 269 | 269 | WRITE_LINE_MEMBER( upd1990a_device::oe_w ) |
| 270 | 270 | { |
| 271 | | if (LOG) logerror("UPD1990A OE %u\n", state); |
| 271 | if (LOG) logerror("uPD1990A '%s' OE %u\n", tag(), state); |
| 272 | 272 | |
| 273 | 273 | m_oe = state; |
| 274 | 274 | } |
| r11366 | r11367 | |
| 280 | 280 | |
| 281 | 281 | WRITE_LINE_MEMBER( upd1990a_device::cs_w ) |
| 282 | 282 | { |
| 283 | | if (LOG) logerror("UPD1990A CS %u\n", state); |
| 283 | if (LOG) logerror("uPD1990A '%s' CS %u\n", tag(), state); |
| 284 | 284 | |
| 285 | 285 | m_cs = state; |
| 286 | 286 | } |
| r11366 | r11367 | |
| 292 | 292 | |
| 293 | 293 | WRITE_LINE_MEMBER( upd1990a_device::stb_w ) |
| 294 | 294 | { |
| 295 | | if (LOG) logerror("UPD1990A STB %u\n", state); |
| 295 | if (LOG) logerror("uPD1990A '%s' STB %u\n", tag(), state); |
| 296 | 296 | |
| 297 | 297 | m_stb = state; |
| 298 | 298 | |
| r11366 | r11367 | |
| 301 | 301 | switch (m_c) |
| 302 | 302 | { |
| 303 | 303 | case MODE_REGISTER_HOLD: |
| 304 | | if (LOG) logerror("UPD1990A Register Hold Mode\n"); |
| 304 | if (LOG) logerror("uPD1990A '%s' Register Hold Mode\n", tag()); |
| 305 | 305 | |
| 306 | 306 | /* enable time counter */ |
| 307 | 307 | m_timer_clock->enable(1); |
| r11366 | r11367 | |
| 315 | 315 | break; |
| 316 | 316 | |
| 317 | 317 | case MODE_SHIFT: |
| 318 | | if (LOG) logerror("UPD1990A Shift Mode\n"); |
| 318 | if (LOG) logerror("uPD1990A '%s' Shift Mode\n", tag()); |
| 319 | 319 | |
| 320 | 320 | /* enable time counter */ |
| 321 | 321 | m_timer_clock->enable(1); |
| r11366 | r11367 | |
| 332 | 332 | break; |
| 333 | 333 | |
| 334 | 334 | case MODE_TIME_SET: |
| 335 | | { |
| 336 | | int i; |
| 335 | if (LOG) logerror("uPD1990A '%s' Time Set Mode\n", tag()); |
| 336 | if (LOG) logerror("uPD1990A '%s' Shift Register %02x%02x%02x%02x%02x\n", tag(), m_shift_reg[4], m_shift_reg[3], m_shift_reg[2], m_shift_reg[1], m_shift_reg[0]); |
| 337 | 337 | |
| 338 | | if (LOG) logerror("UPD1990A Time Set Mode\n"); |
| 339 | | if (LOG) logerror("UPD1990A Shift Register %02x%02x%02x%02x%02x\n", m_shift_reg[4], m_shift_reg[3], m_shift_reg[2], m_shift_reg[1], m_shift_reg[0]); |
| 340 | | |
| 341 | 338 | /* disable time counter */ |
| 342 | 339 | m_timer_clock->enable(0); |
| 343 | 340 | |
| r11366 | r11367 | |
| 349 | 346 | devcb_call_write_line(&m_out_data_func, m_data_out); |
| 350 | 347 | |
| 351 | 348 | /* load shift register data into time counter */ |
| 352 | | for (i = 0; i < 5; i++) |
| 349 | for (int i = 0; i < 5; i++) |
| 353 | 350 | { |
| 354 | 351 | m_time_counter[i] = m_shift_reg[i]; |
| 355 | 352 | } |
| 356 | 353 | |
| 357 | 354 | /* 32 Hz time pulse */ |
| 358 | 355 | m_timer_tp->adjust(attotime::zero, 0, attotime::from_hz(32*2)); |
| 359 | | } |
| 360 | 356 | break; |
| 361 | 357 | |
| 362 | 358 | case MODE_TIME_READ: |
| 363 | | { |
| 364 | | int i; |
| 359 | if (LOG) logerror("uPD1990A '%s' Time Read Mode\n", tag()); |
| 365 | 360 | |
| 366 | | if (LOG) logerror("UPD1990A Time Read Mode\n"); |
| 367 | | |
| 368 | 361 | /* enable time counter */ |
| 369 | 362 | m_timer_clock->enable(1); |
| 370 | 363 | |
| 371 | 364 | /* load time counter data into shift register */ |
| 372 | | for (i = 0; i < 5; i++) |
| 365 | for (int i = 0; i < 5; i++) |
| 373 | 366 | { |
| 374 | 367 | m_shift_reg[i] = m_time_counter[i]; |
| 375 | 368 | } |
| 376 | 369 | |
| 377 | | if (LOG) logerror("UPD1990A Shift Register %02x%02x%02x%02x%02x\n", m_shift_reg[4], m_shift_reg[3], m_shift_reg[2], m_shift_reg[1], m_shift_reg[0]); |
| 370 | if (LOG) logerror("uPD1990A '%s' Shift Register %02x%02x%02x%02x%02x\n", tag(), m_shift_reg[4], m_shift_reg[3], m_shift_reg[2], m_shift_reg[1], m_shift_reg[0]); |
| 378 | 371 | |
| 379 | 372 | /* 512 Hz data out pulse */ |
| 380 | 373 | m_data_out = 1; |
| r11366 | r11367 | |
| 382 | 375 | |
| 383 | 376 | /* 32 Hz time pulse */ |
| 384 | 377 | m_timer_tp->adjust(attotime::zero, 0, attotime::from_hz(32*2)); |
| 385 | | } |
| 386 | 378 | break; |
| 387 | 379 | |
| 388 | 380 | case MODE_TP_64HZ_SET: |
| 389 | | if (LOG) logerror("UPD1990A TP = 64 Hz Set Mode\n"); |
| 381 | if (LOG) logerror("uPD1990A '%s' TP = 64 Hz Set Mode\n", tag()); |
| 390 | 382 | |
| 391 | 383 | /* 64 Hz time pulse */ |
| 392 | 384 | m_timer_tp->adjust(attotime::zero, 0, attotime::from_hz(64*2)); |
| 393 | 385 | break; |
| 394 | 386 | |
| 395 | 387 | case MODE_TP_256HZ_SET: |
| 396 | | if (LOG) logerror("UPD1990A TP = 256 Hz Set Mode\n"); |
| 388 | if (LOG) logerror("uPD1990A '%s' TP = 256 Hz Set Mode\n", tag()); |
| 397 | 389 | |
| 398 | 390 | /* 256 Hz time pulse */ |
| 399 | 391 | m_timer_tp->adjust(attotime::zero, 0, attotime::from_hz(256*2)); |
| 400 | 392 | break; |
| 401 | 393 | |
| 402 | 394 | case MODE_TP_2048HZ_SET: |
| 403 | | if (LOG) logerror("UPD1990A TP = 2048 Hz Set Mode\n"); |
| 395 | if (LOG) logerror("uPD1990A '%s' TP = 2048 Hz Set Mode\n", tag()); |
| 404 | 396 | |
| 405 | 397 | /* 2048 Hz time pulse */ |
| 406 | 398 | m_timer_tp->adjust(attotime::zero, 0, attotime::from_hz(2048*2)); |
| 407 | 399 | break; |
| 408 | 400 | |
| 409 | 401 | case MODE_TEST: |
| 410 | | if (LOG) logerror("UPD1990A Test Mode not supported!\n"); |
| 402 | if (LOG) logerror("uPD1990A '%s' Test Mode not supported!\n", tag()); |
| 411 | 403 | |
| 412 | 404 | if (m_oe) |
| 413 | 405 | { |
| r11366 | r11367 | |
| 430 | 422 | |
| 431 | 423 | WRITE_LINE_MEMBER( upd1990a_device::clk_w ) |
| 432 | 424 | { |
| 433 | | if (LOG) logerror("UPD1990A CLK %u\n", state); |
| 425 | if (LOG) logerror("uPD1990A '%s' CLK %u\n", tag(), state); |
| 434 | 426 | |
| 435 | 427 | if (!m_clk && state) // rising edge |
| 436 | 428 | { |
| r11366 | r11367 | |
| 455 | 447 | { |
| 456 | 448 | m_data_out = BIT(m_shift_reg[0], 0); |
| 457 | 449 | |
| 458 | | if (LOG) logerror("UPD1990A DATA OUT %u\n", m_data_out); |
| 450 | if (LOG) logerror("uPD1990A '%s' DATA OUT %u\n", tag(), m_data_out); |
| 459 | 451 | |
| 460 | 452 | devcb_call_write_line(&m_out_data_func, m_data_out); |
| 461 | 453 | } |
| r11366 | r11367 | |
| 472 | 464 | |
| 473 | 465 | WRITE_LINE_MEMBER( upd1990a_device::c0_w ) |
| 474 | 466 | { |
| 475 | | if (LOG) logerror("UPD1990A C0 %u\n", state); |
| 467 | if (LOG) logerror("uPD1990A '%s' C0 %u\n", tag(), state); |
| 476 | 468 | |
| 477 | 469 | m_c = (m_c & 0x06) | state; |
| 478 | 470 | } |
| r11366 | r11367 | |
| 484 | 476 | |
| 485 | 477 | WRITE_LINE_MEMBER( upd1990a_device::c1_w ) |
| 486 | 478 | { |
| 487 | | if (LOG) logerror("UPD1990A C1 %u\n", state); |
| 479 | if (LOG) logerror("uPD1990A '%s' C1 %u\n", tag(), state); |
| 488 | 480 | |
| 489 | 481 | m_c = (m_c & 0x05) | (state << 1); |
| 490 | 482 | } |
| r11366 | r11367 | |
| 496 | 488 | |
| 497 | 489 | WRITE_LINE_MEMBER( upd1990a_device::c2_w ) |
| 498 | 490 | { |
| 499 | | if (LOG) logerror("UPD1990A C2 %u\n", state); |
| 491 | if (LOG) logerror("uPD1990A '%s' C2 %u\n", tag(), state); |
| 500 | 492 | |
| 501 | 493 | m_c = (m_c & 0x03) | (state << 2); |
| 502 | 494 | } |
| r11366 | r11367 | |
| 508 | 500 | |
| 509 | 501 | WRITE_LINE_MEMBER( upd1990a_device::data_in_w ) |
| 510 | 502 | { |
| 511 | | if (LOG) logerror("UPD1990A DATA IN %u\n", state); |
| 503 | if (LOG) logerror("uPD1990A '%s' DATA IN %u\n", tag(), state); |
| 512 | 504 | |
| 513 | 505 | m_data_in = state; |
| 514 | 506 | } |