src/mess/machine/6525tpi.c
| r11230 | r11231 | |
| 109 | 109 | typedef struct _tpi6525_state tpi6525_state; |
| 110 | 110 | struct _tpi6525_state |
| 111 | 111 | { |
| 112 | | const tpi6525_interface *intf; |
| 113 | | |
| 112 | devcb_resolved_write_line out_irq_func; |
| 113 | devcb_resolved_read8 in_pa_func; |
| 114 | devcb_resolved_write8 out_pa_func; |
| 115 | devcb_resolved_read8 in_pb_func; |
| 116 | devcb_resolved_write8 out_pb_func; |
| 117 | devcb_resolved_read8 in_pc_func; |
| 118 | devcb_resolved_write8 out_pc_func; |
| 119 | devcb_resolved_write_line out_ca_func; |
| 120 | devcb_resolved_write_line out_cb_func; |
| 121 | |
| 114 | 122 | UINT8 port_a, ddr_a, in_a; |
| 115 | 123 | UINT8 port_b, ddr_b, in_b; |
| 116 | 124 | UINT8 port_c, ddr_c, in_c; |
| r11230 | r11231 | |
| 144 | 152 | static DEVICE_START( tpi6525 ) |
| 145 | 153 | { |
| 146 | 154 | tpi6525_state *tpi6525 = get_safe_token(device); |
| 155 | const tpi6525_interface *intf = (const tpi6525_interface*)device->baseconfig().static_config(); |
| 147 | 156 | |
| 157 | // resolve callbacks |
| 158 | devcb_resolve_write_line(&tpi6525->out_irq_func, &intf->out_irq_func, device); |
| 159 | devcb_resolve_read8(&tpi6525->in_pa_func, &intf->in_pa_func, device); |
| 160 | devcb_resolve_write8(&tpi6525->out_pa_func, &intf->out_pa_func, device); |
| 161 | devcb_resolve_read8(&tpi6525->in_pb_func, &intf->in_pb_func, device); |
| 162 | devcb_resolve_write8(&tpi6525->out_pb_func, &intf->out_pb_func, device); |
| 163 | devcb_resolve_read8(&tpi6525->in_pc_func, &intf->in_pc_func, device); |
| 164 | devcb_resolve_write8(&tpi6525->out_pc_func, &intf->out_pc_func, device); |
| 165 | devcb_resolve_write_line(&tpi6525->out_ca_func, &intf->out_ca_func, device); |
| 166 | devcb_resolve_write_line(&tpi6525->out_cb_func, &intf->out_cb_func, device); |
| 167 | |
| 148 | 168 | /* verify that we have an interface assigned */ |
| 149 | 169 | assert(device->baseconfig().static_config() != NULL); |
| 150 | 170 | |
| r11230 | r11231 | |
| 174 | 194 | /* clear old values */ |
| 175 | 195 | memset(tpi6525, 0, sizeof(*tpi6525)); |
| 176 | 196 | |
| 177 | | /* copy interface pointer */ |
| 178 | | tpi6525->intf = (const tpi6525_interface*)device->baseconfig().static_config(); |
| 179 | | |
| 180 | 197 | /* setup some initial values */ |
| 181 | 198 | tpi6525->in_a = 0xff; |
| 182 | 199 | tpi6525->in_b = 0xff; |
| r11230 | r11231 | |
| 220 | 237 | |
| 221 | 238 | DBG_LOG(device->machine(), 3, "tpi6525", ("%s set interrupt\n", device->tag())); |
| 222 | 239 | |
| 223 | | if (tpi6525->intf->irq_func != NULL) |
| 224 | | tpi6525->intf->irq_func(device, tpi6525->interrupt_level); |
| 240 | devcb_call_write_line(&tpi6525->out_irq_func, tpi6525->interrupt_level); |
| 225 | 241 | } |
| 226 | 242 | } |
| 227 | 243 | |
| r11230 | r11231 | |
| 236 | 252 | |
| 237 | 253 | DBG_LOG(device->machine(), 3, "tpi6525", ("%s clear interrupt\n", device->tag())); |
| 238 | 254 | |
| 239 | | if (tpi6525->intf->irq_func != NULL) |
| 240 | | tpi6525->intf->irq_func(device, tpi6525->interrupt_level); |
| 255 | devcb_call_write_line(&tpi6525->out_irq_func, tpi6525->interrupt_level); |
| 241 | 256 | } |
| 242 | 257 | } |
| 243 | 258 | |
| 244 | 259 | |
| 245 | | void tpi6525_irq0_level(device_t *device, int level) |
| 260 | WRITE_LINE_DEVICE_HANDLER( tpi6525_i0_w ) |
| 246 | 261 | { |
| 247 | 262 | tpi6525_state *tpi6525 = get_safe_token(device); |
| 248 | 263 | |
| 249 | | if (INTERRUPT_MODE && (level != tpi6525->irq_level[0])) |
| 264 | if (INTERRUPT_MODE && (state != tpi6525->irq_level[0])) |
| 250 | 265 | { |
| 251 | | tpi6525->irq_level[0] = level; |
| 266 | tpi6525->irq_level[0] = state; |
| 252 | 267 | |
| 253 | | if ((level == 0) && !(tpi6525->air & 1) && (tpi6525->ddr_c & 1)) |
| 268 | if ((state == 0) && !(tpi6525->air & 1) && (tpi6525->ddr_c & 1)) |
| 254 | 269 | { |
| 255 | 270 | tpi6525->air |= 1; |
| 256 | 271 | tpi6525_set_interrupt(device); |
| r11230 | r11231 | |
| 259 | 274 | } |
| 260 | 275 | |
| 261 | 276 | |
| 262 | | void tpi6525_irq1_level(device_t *device, int level) |
| 277 | WRITE_LINE_DEVICE_HANDLER( tpi6525_i1_w ) |
| 263 | 278 | { |
| 264 | 279 | tpi6525_state *tpi6525 = get_safe_token(device); |
| 265 | 280 | |
| 266 | | if (INTERRUPT_MODE && (level != tpi6525->irq_level[1])) |
| 281 | if (INTERRUPT_MODE && (state != tpi6525->irq_level[1])) |
| 267 | 282 | { |
| 268 | | tpi6525->irq_level[1] = level; |
| 283 | tpi6525->irq_level[1] = state; |
| 269 | 284 | |
| 270 | | if ((level == 0) && !(tpi6525->air & 2) && (tpi6525->ddr_c & 2)) |
| 285 | if ((state == 0) && !(tpi6525->air & 2) && (tpi6525->ddr_c & 2)) |
| 271 | 286 | { |
| 272 | 287 | tpi6525->air |= 2; |
| 273 | 288 | tpi6525_set_interrupt(device); |
| r11230 | r11231 | |
| 276 | 291 | } |
| 277 | 292 | |
| 278 | 293 | |
| 279 | | void tpi6525_irq2_level(device_t *device, int level) |
| 294 | WRITE_LINE_DEVICE_HANDLER( tpi6525_i2_w ) |
| 280 | 295 | { |
| 281 | 296 | tpi6525_state *tpi6525 = get_safe_token(device); |
| 282 | 297 | |
| 283 | | if (INTERRUPT_MODE && (level != tpi6525->irq_level[2])) |
| 298 | if (INTERRUPT_MODE && (state != tpi6525->irq_level[2])) |
| 284 | 299 | { |
| 285 | | tpi6525->irq_level[2] = level; |
| 300 | tpi6525->irq_level[2] = state; |
| 286 | 301 | |
| 287 | | if ((level == 0) && !(tpi6525->air & 4) && (tpi6525->ddr_c & 4)) |
| 302 | if ((state == 0) && !(tpi6525->air & 4) && (tpi6525->ddr_c & 4)) |
| 288 | 303 | { |
| 289 | 304 | tpi6525->air |= 4; |
| 290 | 305 | tpi6525_set_interrupt(device); |
| r11230 | r11231 | |
| 293 | 308 | } |
| 294 | 309 | |
| 295 | 310 | |
| 296 | | void tpi6525_irq3_level(device_t *device, int level) |
| 311 | WRITE_LINE_DEVICE_HANDLER( tpi6525_i3_w ) |
| 297 | 312 | { |
| 298 | 313 | tpi6525_state *tpi6525 = get_safe_token(device); |
| 299 | 314 | |
| 300 | | if (INTERRUPT_MODE && (level != tpi6525->irq_level[3])) |
| 315 | if (INTERRUPT_MODE && (state != tpi6525->irq_level[3])) |
| 301 | 316 | { |
| 302 | | tpi6525->irq_level[3] = level; |
| 317 | tpi6525->irq_level[3] = state; |
| 303 | 318 | |
| 304 | | if (((INTERRUPT3_RISING_EDGE && (level == 1)) |
| 305 | | || (!INTERRUPT3_RISING_EDGE && (level == 0))) |
| 319 | if (((INTERRUPT3_RISING_EDGE && (state == 1)) |
| 320 | || (!INTERRUPT3_RISING_EDGE && (state == 0))) |
| 306 | 321 | && !(tpi6525->air & 8) && (tpi6525->ddr_c & 8)) |
| 307 | 322 | { |
| 308 | 323 | tpi6525->air |= 8; |
| r11230 | r11231 | |
| 312 | 327 | } |
| 313 | 328 | |
| 314 | 329 | |
| 315 | | void tpi6525_irq4_level(device_t *device, int level) |
| 330 | WRITE_LINE_DEVICE_HANDLER( tpi6525_i4_w ) |
| 316 | 331 | { |
| 317 | 332 | tpi6525_state *tpi6525 = get_safe_token(device); |
| 318 | 333 | |
| 319 | | if (INTERRUPT_MODE && (level != tpi6525->irq_level[4]) ) |
| 334 | if (INTERRUPT_MODE && (state != tpi6525->irq_level[4]) ) |
| 320 | 335 | { |
| 321 | | tpi6525->irq_level[4] = level; |
| 336 | tpi6525->irq_level[4] = state; |
| 322 | 337 | |
| 323 | | if (((INTERRUPT4_RISING_EDGE && (level == 1)) |
| 324 | | ||(!INTERRUPT4_RISING_EDGE&&(level == 0))) |
| 338 | if (((INTERRUPT4_RISING_EDGE && (state == 1)) |
| 339 | ||(!INTERRUPT4_RISING_EDGE&&(state == 0))) |
| 325 | 340 | && !(tpi6525->air & 0x10) && (tpi6525->ddr_c & 0x10)) |
| 326 | 341 | { |
| 327 | 342 | tpi6525->air |= 0x10; |
| r11230 | r11231 | |
| 336 | 351 | tpi6525_state *tpi6525 = get_safe_token(device); |
| 337 | 352 | UINT8 data = tpi6525->in_a; |
| 338 | 353 | |
| 339 | | if (tpi6525->intf->in_a_func) |
| 340 | | data = tpi6525->intf->in_a_func(device, offset); |
| 354 | if (tpi6525->in_pa_func.target != NULL) |
| 355 | data = devcb_call_read8(&tpi6525->in_pa_func, offset); |
| 341 | 356 | |
| 342 | 357 | data = (data & ~tpi6525->ddr_a) | (tpi6525->ddr_a & tpi6525->port_a); |
| 343 | 358 | |
| r11230 | r11231 | |
| 358 | 373 | tpi6525_state *tpi6525 = get_safe_token(device); |
| 359 | 374 | UINT8 data = tpi6525->in_b; |
| 360 | 375 | |
| 361 | | if (tpi6525->intf->in_b_func) |
| 362 | | data = tpi6525->intf->in_b_func(device, offset); |
| 376 | if (tpi6525->in_pb_func.target != NULL) |
| 377 | data = devcb_call_read8(&tpi6525->in_pb_func, offset); |
| 363 | 378 | |
| 364 | 379 | data = (data & ~tpi6525->ddr_b) | (tpi6525->ddr_b & tpi6525->port_b); |
| 365 | 380 | |
| r11230 | r11231 | |
| 380 | 395 | tpi6525_state *tpi6525 = get_safe_token(device); |
| 381 | 396 | UINT8 data = tpi6525->in_c; |
| 382 | 397 | |
| 383 | | if (tpi6525->intf->in_c_func) |
| 384 | | data &= tpi6525->intf->in_c_func(device, offset); |
| 398 | if (tpi6525->in_pc_func.target != NULL) |
| 399 | data &= devcb_call_read8(&tpi6525->in_pc_func, offset); |
| 385 | 400 | |
| 386 | 401 | data = (data & ~tpi6525->ddr_c) | (tpi6525->ddr_c & tpi6525->port_c); |
| 387 | 402 | |
| r11230 | r11231 | |
| 407 | 422 | case 0: |
| 408 | 423 | data = tpi6525->in_a; |
| 409 | 424 | |
| 410 | | if (tpi6525->intf->in_a_func) |
| 411 | | data &= tpi6525->intf->in_a_func(device, 0); |
| 425 | if (tpi6525->in_pa_func.target != NULL) |
| 426 | data &= devcb_call_read8(&tpi6525->in_pa_func, 0); |
| 412 | 427 | |
| 413 | 428 | data = (data & ~tpi6525->ddr_a) | (tpi6525->ddr_a & tpi6525->port_a); |
| 414 | 429 | |
| r11230 | r11231 | |
| 417 | 432 | case 1: |
| 418 | 433 | data = tpi6525->in_b; |
| 419 | 434 | |
| 420 | | if (tpi6525->intf->in_b_func) |
| 421 | | data &= tpi6525->intf->in_b_func(device, 0); |
| 435 | if (tpi6525->in_pb_func.target != NULL) |
| 436 | data &= devcb_call_read8(&tpi6525->in_pb_func, 0); |
| 422 | 437 | |
| 423 | 438 | data = (data & ~tpi6525->ddr_b) | (tpi6525->ddr_b & tpi6525->port_b); |
| 424 | 439 | |
| r11230 | r11231 | |
| 442 | 457 | { |
| 443 | 458 | data = tpi6525->in_c; |
| 444 | 459 | |
| 445 | | if (tpi6525->intf->in_c_func) |
| 446 | | data &= tpi6525->intf->in_c_func(device, 0); |
| 460 | if (tpi6525->in_pc_func.target != NULL) |
| 461 | data &= devcb_call_read8(&tpi6525->in_pc_func, 0); |
| 447 | 462 | |
| 448 | 463 | data = (data & ~tpi6525->ddr_c) | (tpi6525->ddr_c & tpi6525->port_c); |
| 449 | 464 | } |
| r11230 | r11231 | |
| 523 | 538 | { |
| 524 | 539 | case 0: |
| 525 | 540 | tpi6525->port_a = data; |
| 526 | | |
| 527 | | if (tpi6525->intf->out_a_func) |
| 528 | | tpi6525->intf->out_a_func(device, 0, tpi6525->port_a & tpi6525->ddr_a); |
| 529 | | |
| 541 | devcb_call_write8(&tpi6525->out_pa_func, 0, tpi6525->port_a & tpi6525->ddr_a); |
| 530 | 542 | break; |
| 531 | 543 | |
| 532 | 544 | case 1: |
| 533 | 545 | tpi6525->port_b = data; |
| 534 | | |
| 535 | | if (tpi6525->intf->out_b_func) |
| 536 | | tpi6525->intf->out_b_func(device, 0, tpi6525->port_b & tpi6525->ddr_b); |
| 537 | | |
| 546 | devcb_call_write8(&tpi6525->out_pb_func, 0, tpi6525->port_b & tpi6525->ddr_b); |
| 538 | 547 | break; |
| 539 | 548 | |
| 540 | 549 | case 2: |
| 541 | 550 | tpi6525->port_c = data; |
| 542 | 551 | |
| 543 | | if (!INTERRUPT_MODE && tpi6525->intf->out_c_func) |
| 544 | | tpi6525->intf->out_c_func(device, 0, tpi6525->port_c & tpi6525->ddr_c); |
| 545 | | |
| 552 | if (!INTERRUPT_MODE) |
| 553 | devcb_call_write8(&tpi6525->out_pc_func, 0, tpi6525->port_c & tpi6525->ddr_c); |
| 546 | 554 | break; |
| 547 | 555 | |
| 548 | 556 | case 3: |
| 549 | 557 | tpi6525->ddr_a = data; |
| 558 | devcb_call_write8(&tpi6525->out_pa_func, 0, tpi6525->port_a & tpi6525->ddr_a); |
| 550 | 559 | |
| 551 | | if (tpi6525->intf->out_a_func) |
| 552 | | tpi6525->intf->out_a_func(device, 0, tpi6525->port_a & tpi6525->ddr_a); |
| 553 | | |
| 554 | 560 | break; |
| 555 | 561 | |
| 556 | 562 | case 4: |
| 557 | 563 | tpi6525->ddr_b = data; |
| 558 | | |
| 559 | | if (tpi6525->intf->out_b_func) |
| 560 | | tpi6525->intf->out_b_func(device, 0, tpi6525->port_b & tpi6525->ddr_b); |
| 561 | | |
| 564 | devcb_call_write8(&tpi6525->out_pb_func, 0, tpi6525->port_b & tpi6525->ddr_b); |
| 562 | 565 | break; |
| 563 | 566 | |
| 564 | 567 | case 5: |
| 565 | 568 | tpi6525->ddr_c = data; |
| 566 | 569 | |
| 567 | | if (!INTERRUPT_MODE && tpi6525->intf->out_c_func) |
| 568 | | tpi6525->intf->out_c_func(device, 0, tpi6525->port_c & tpi6525->ddr_c); |
| 569 | | |
| 570 | if (!INTERRUPT_MODE) |
| 571 | devcb_call_write8(&tpi6525->out_pc_func, 0, tpi6525->port_c & tpi6525->ddr_c); |
| 570 | 572 | break; |
| 571 | 573 | |
| 572 | 574 | case 6: |
| r11230 | r11231 | |
| 579 | 581 | if (tpi6525->ca_level != CA_MANUAL_LEVEL) |
| 580 | 582 | { |
| 581 | 583 | tpi6525->ca_level = CA_MANUAL_LEVEL; |
| 582 | | |
| 583 | | if (tpi6525->intf->out_ca_func) |
| 584 | | tpi6525->intf->out_ca_func(device, 0, tpi6525->ca_level); |
| 584 | devcb_call_write_line(&tpi6525->out_ca_func, tpi6525->ca_level); |
| 585 | 585 | } |
| 586 | 586 | } |
| 587 | 587 | if (CB_MANUAL_OUT) |
| r11230 | r11231 | |
| 589 | 589 | if (tpi6525->cb_level != CB_MANUAL_LEVEL) |
| 590 | 590 | { |
| 591 | 591 | tpi6525->cb_level = CB_MANUAL_LEVEL; |
| 592 | | |
| 593 | | if (tpi6525->intf->out_cb_func) |
| 594 | | tpi6525->intf->out_cb_func(device, 0, tpi6525->cb_level); |
| 592 | devcb_call_write_line(&tpi6525->out_cb_func, tpi6525->cb_level); |
| 595 | 593 | } |
| 596 | 594 | } |
| 597 | 595 | } |