src/mess/machine/pdp1.c
| r9667 | r9668 | |
| 34 | 34 | #define LOG_IOT_OVERLAP 0 |
| 35 | 35 | |
| 36 | 36 | |
| 37 | | static int tape_read(UINT8 *reply); |
| 37 | static int tape_read(pdp1_state *state, UINT8 *reply); |
| 38 | 38 | static TIMER_CALLBACK(reader_callback); |
| 39 | 39 | static TIMER_CALLBACK(puncher_callback); |
| 40 | 40 | static TIMER_CALLBACK(tyo_callback); |
| r9667 | r9668 | |
| 71 | 71 | emulated: |
| 72 | 72 | * perforated tape reader |
| 73 | 73 | * perforated tape punch |
| 74 | | * typewriter output |
| 74 | * state->typewriter output |
| 75 | 75 | * CRT display |
| 76 | 76 | unemulated: |
| 77 | 77 | * card punch (pac: 43) |
| r9667 | r9668 | |
| 81 | 81 | */ |
| 82 | 82 | |
| 83 | 83 | /* IO status word */ |
| 84 | | static int io_status; |
| 85 | 84 | |
| 86 | 85 | /* defines for io_status bits */ |
| 87 | 86 | enum |
| 88 | 87 | { |
| 89 | 88 | io_st_pen = 0400000, /* light pen: light has hit the pen */ |
| 90 | 89 | io_st_ptr = 0200000, /* perforated tape reader: reader buffer full */ |
| 91 | | io_st_tyo = 0100000, /* typewriter out: device ready */ |
| 92 | | io_st_tyi = 0040000, /* typewriter in: new character in buffer */ |
| 90 | io_st_tyo = 0100000, /* state->typewriter out: device ready */ |
| 91 | io_st_tyi = 0040000, /* state->typewriter in: new character in buffer */ |
| 93 | 92 | io_st_ptp = 0020000 /* perforated tape punch: device ready */ |
| 94 | 93 | }; |
| 95 | 94 | |
| 96 | | /* tape reader registers */ |
| 97 | | typedef struct tape_reader_t |
| 98 | | { |
| 99 | | device_image_interface *fd; /* file descriptor of tape image */ |
| 100 | 95 | |
| 101 | | int motor_on; /* 1-bit reader motor on */ |
| 102 | 96 | |
| 103 | | int rb; /* 18-bit reader buffer */ |
| 104 | | int rcl; /* 1-bit reader clutch */ |
| 105 | | int rc; /* 2-bit reader counter */ |
| 106 | | int rby; /* 1-bit reader binary mode flip-flop */ |
| 107 | | int rcp; /* 1-bit reader "need a completion pulse" flip-flop */ |
| 108 | 97 | |
| 109 | | emu_timer *timer; /* timer to simulate reader timing */ |
| 110 | | } tape_reader_t; |
| 111 | 98 | |
| 112 | | static tape_reader_t tape_reader; |
| 113 | 99 | |
| 114 | 100 | |
| 115 | | /* tape puncher registers */ |
| 116 | | typedef struct tape_puncher_t |
| 117 | | { |
| 118 | | device_image_interface *fd; /* file descriptor of tape image */ |
| 119 | | |
| 120 | | emu_timer *timer; /* timer to generate completion pulses */ |
| 121 | | } tape_puncher_t; |
| 122 | | |
| 123 | | static tape_puncher_t tape_puncher; |
| 124 | | |
| 125 | | |
| 126 | | /* typewriter registers */ |
| 127 | | typedef struct typewriter_t |
| 128 | | { |
| 129 | | device_image_interface *fd; /* file descriptor of output image */ |
| 130 | | |
| 131 | | int tb; /* typewriter buffer */ |
| 132 | | |
| 133 | | emu_timer *tyo_timer;/* timer to generate completion pulses */ |
| 134 | | } typewriter_t; |
| 135 | | |
| 136 | | static typewriter_t typewriter; |
| 137 | | |
| 138 | | |
| 139 | 101 | /* crt display timer */ |
| 140 | | static emu_timer *dpy_timer; |
| 141 | 102 | |
| 142 | 103 | /* light pen config */ |
| 143 | | static lightpen_t lightpen; |
| 144 | 104 | |
| 145 | 105 | |
| 146 | | /* MIT parallel drum (mostly similar to type 23) */ |
| 147 | | typedef struct parallel_drum_t |
| 148 | | { |
| 149 | | device_image_interface *fd; /* file descriptor of drum image */ |
| 150 | 106 | |
| 151 | | int il; /* initial location (12-bit) */ |
| 152 | | int wc; /* word counter (12-bit) */ |
| 153 | | int wcl; /* word core location counter (16-bit) */ |
| 154 | | int rfb; /* read field buffer (5-bit) */ |
| 155 | | int wfb; /* write field buffer (5-bit) */ |
| 156 | | |
| 157 | | int dba; |
| 158 | | |
| 159 | | emu_timer *rotation_timer; /* timer called each time dc is 0 */ |
| 160 | | emu_timer *il_timer; /* timer called each time dc is il */ |
| 161 | | } parallel_drum_t; |
| 162 | | |
| 163 | | static parallel_drum_t parallel_drum; |
| 164 | | |
| 165 | 107 | #define PARALLEL_DRUM_WORD_TIME ATTOTIME_IN_NSEC(8500) |
| 166 | 108 | #define PARALLEL_DRUM_ROTATION_TIME ATTOTIME_IN_NSEC(8500*4096) |
| 167 | 109 | |
| r9667 | r9668 | |
| 202 | 144 | |
| 203 | 145 | MACHINE_RESET( pdp1 ) |
| 204 | 146 | { |
| 147 | pdp1_state *state = machine->driver_data<pdp1_state>(); |
| 205 | 148 | int cfg; |
| 206 | 149 | |
| 207 | 150 | cfg = input_port_read(machine, "CFG"); |
| r9667 | r9668 | |
| 210 | 153 | pdp1_reset_param.type_20_sbs = (cfg >> pdp1_config_type_20_sbs_bit) & pdp1_config_type_20_sbs_mask; |
| 211 | 154 | |
| 212 | 155 | /* reset device state */ |
| 213 | | tape_reader.rcl = tape_reader.rc = 0; |
| 214 | | io_status = io_st_tyo | io_st_ptp; |
| 215 | | lightpen.active = lightpen.down = 0; |
| 216 | | lightpen.x = lightpen.y = 0; |
| 217 | | lightpen.radius = 10; /* ??? */ |
| 218 | | pdp1_update_lightpen_state(&lightpen); |
| 156 | state->tape_reader.rcl = state->tape_reader.rc = 0; |
| 157 | state->io_status = io_st_tyo | io_st_ptp; |
| 158 | state->lightpen.active = state->lightpen.down = 0; |
| 159 | state->lightpen.x = state->lightpen.y = 0; |
| 160 | state->lightpen.radius = 10; /* ??? */ |
| 161 | pdp1_update_lightpen_state(machine, &state->lightpen); |
| 219 | 162 | } |
| 220 | 163 | |
| 221 | 164 | |
| 222 | 165 | static void pdp1_machine_stop(running_machine &machine) |
| 223 | 166 | { |
| 167 | pdp1_state *state = machine.driver_data<pdp1_state>(); |
| 224 | 168 | /* the core will take care of freeing the timers, BUT we must set the variables |
| 225 | 169 | to NULL if we don't want to risk confusing the tape image init function */ |
| 226 | | tape_reader.timer = tape_puncher.timer = typewriter.tyo_timer = dpy_timer = NULL; |
| 170 | state->tape_reader.timer = state->tape_puncher.timer = state->typewriter.tyo_timer = state->dpy_timer = NULL; |
| 227 | 171 | } |
| 228 | 172 | |
| 229 | 173 | |
| r9667 | r9668 | |
| 234 | 178 | */ |
| 235 | 179 | MACHINE_START( pdp1 ) |
| 236 | 180 | { |
| 181 | pdp1_state *state = machine->driver_data<pdp1_state>(); |
| 237 | 182 | UINT8 *dst; |
| 238 | 183 | |
| 239 | 184 | static const unsigned char fontdata6x8[pdp1_fontdata_size] = |
| r9667 | r9668 | |
| 367 | 312 | |
| 368 | 313 | machine->add_notifier(MACHINE_NOTIFY_EXIT, pdp1_machine_stop); |
| 369 | 314 | |
| 370 | | tape_reader.timer = timer_alloc(machine, reader_callback, NULL); |
| 371 | | tape_puncher.timer = timer_alloc(machine, puncher_callback, NULL); |
| 372 | | typewriter.tyo_timer = timer_alloc(machine, tyo_callback, NULL); |
| 373 | | dpy_timer = timer_alloc(machine, dpy_callback, NULL); |
| 315 | state->tape_reader.timer = timer_alloc(machine, reader_callback, NULL); |
| 316 | state->tape_puncher.timer = timer_alloc(machine, puncher_callback, NULL); |
| 317 | state->typewriter.tyo_timer = timer_alloc(machine, tyo_callback, NULL); |
| 318 | state->dpy_timer = timer_alloc(machine, dpy_callback, NULL); |
| 374 | 319 | } |
| 375 | 320 | |
| 376 | 321 | |
| r9667 | r9668 | |
| 410 | 355 | */ |
| 411 | 356 | DEVICE_IMAGE_LOAD( pdp1_tape ) |
| 412 | 357 | { |
| 358 | pdp1_state *state = image.device().machine->driver_data<pdp1_state>(); |
| 413 | 359 | int id = image_index_in_device(image); |
| 414 | 360 | |
| 415 | 361 | switch (id) |
| 416 | 362 | { |
| 417 | 363 | case 0: |
| 418 | 364 | /* reader unit */ |
| 419 | | tape_reader.fd = image; |
| 365 | state->tape_reader.fd = image; |
| 420 | 366 | |
| 421 | 367 | /* start motor */ |
| 422 | | tape_reader.motor_on = 1; |
| 368 | state->tape_reader.motor_on = 1; |
| 423 | 369 | |
| 424 | 370 | /* restart reader IO when necessary */ |
| 425 | 371 | /* note that this function may be called before pdp1_init_machine, therefore |
| 426 | | before tape_reader.timer is allocated. It does not matter, as the clutch is never |
| 372 | before state->tape_reader.timer is allocated. It does not matter, as the clutch is never |
| 427 | 373 | down at power-up, but we must not call timer_enable with a NULL parameter! */ |
| 428 | | if (tape_reader.timer) |
| 374 | if (state->tape_reader.timer) |
| 429 | 375 | { |
| 430 | | if (tape_reader.motor_on && tape_reader.rcl) |
| 376 | if (state->tape_reader.motor_on && state->tape_reader.rcl) |
| 431 | 377 | { |
| 432 | 378 | /* delay is approximately 1/400s */ |
| 433 | | timer_adjust_oneshot(tape_reader.timer, ATTOTIME_IN_USEC(2500), 0); |
| 379 | timer_adjust_oneshot(state->tape_reader.timer, ATTOTIME_IN_USEC(2500), 0); |
| 434 | 380 | } |
| 435 | 381 | else |
| 436 | 382 | { |
| 437 | | timer_enable(tape_reader.timer, 0); |
| 383 | timer_enable(state->tape_reader.timer, 0); |
| 438 | 384 | } |
| 439 | 385 | } |
| 440 | 386 | break; |
| 441 | 387 | |
| 442 | 388 | case 1: |
| 443 | 389 | /* punch unit */ |
| 444 | | tape_puncher.fd = image; |
| 390 | state->tape_puncher.fd = image; |
| 445 | 391 | break; |
| 446 | 392 | } |
| 447 | 393 | |
| r9667 | r9668 | |
| 450 | 396 | |
| 451 | 397 | DEVICE_IMAGE_UNLOAD( pdp1_tape ) |
| 452 | 398 | { |
| 399 | pdp1_state *state = image.device().machine->driver_data<pdp1_state>(); |
| 453 | 400 | int id = image_index_in_device(image); |
| 454 | 401 | |
| 455 | 402 | switch (id) |
| 456 | 403 | { |
| 457 | 404 | case 0: |
| 458 | 405 | /* reader unit */ |
| 459 | | tape_reader.fd = NULL; |
| 406 | state->tape_reader.fd = NULL; |
| 460 | 407 | |
| 461 | 408 | /* stop motor */ |
| 462 | | tape_reader.motor_on = 0; |
| 409 | state->tape_reader.motor_on = 0; |
| 463 | 410 | |
| 464 | | if (tape_reader.timer) |
| 465 | | timer_enable(tape_reader.timer, 0); |
| 411 | if (state->tape_reader.timer) |
| 412 | timer_enable(state->tape_reader.timer, 0); |
| 466 | 413 | break; |
| 467 | 414 | |
| 468 | 415 | case 1: |
| 469 | 416 | /* punch unit */ |
| 470 | | tape_puncher.fd = NULL; |
| 417 | state->tape_puncher.fd = NULL; |
| 471 | 418 | break; |
| 472 | 419 | } |
| 473 | 420 | } |
| r9667 | r9668 | |
| 475 | 422 | /* |
| 476 | 423 | Read a byte from perforated tape |
| 477 | 424 | */ |
| 478 | | static int tape_read(UINT8 *reply) |
| 425 | static int tape_read(pdp1_state *state, UINT8 *reply) |
| 479 | 426 | { |
| 480 | | if (tape_reader.fd && (tape_reader.fd->fread(reply, 1) == 1)) |
| 427 | if (state->tape_reader.fd && (state->tape_reader.fd->fread(reply, 1) == 1)) |
| 481 | 428 | return 0; /* unit OK */ |
| 482 | 429 | else |
| 483 | 430 | return 1; /* unit not ready */ |
| r9667 | r9668 | |
| 486 | 433 | /* |
| 487 | 434 | Write a byte to perforated tape |
| 488 | 435 | */ |
| 489 | | static void tape_write(UINT8 data) |
| 436 | static void tape_write(pdp1_state *state, UINT8 data) |
| 490 | 437 | { |
| 491 | | if (tape_puncher.fd) |
| 492 | | tape_puncher.fd->fwrite(& data, 1); |
| 438 | if (state->tape_puncher.fd) |
| 439 | state->tape_puncher.fd->fwrite(& data, 1); |
| 493 | 440 | } |
| 494 | 441 | |
| 495 | 442 | /* |
| 496 | 443 | common code for tape read commands (RPA, RPB, and read-in mode) |
| 497 | 444 | */ |
| 498 | | static void begin_tape_read(int binary, int nac) |
| 445 | static void begin_tape_read(pdp1_state *state, int binary, int nac) |
| 499 | 446 | { |
| 500 | | tape_reader.rb = 0; |
| 501 | | tape_reader.rcl = 1; |
| 502 | | tape_reader.rc = (binary) ? 1 : 3; |
| 503 | | tape_reader.rby = (binary) ? 1 : 0; |
| 504 | | tape_reader.rcp = nac; |
| 447 | state->tape_reader.rb = 0; |
| 448 | state->tape_reader.rcl = 1; |
| 449 | state->tape_reader.rc = (binary) ? 1 : 3; |
| 450 | state->tape_reader.rby = (binary) ? 1 : 0; |
| 451 | state->tape_reader.rcp = nac; |
| 505 | 452 | |
| 506 | 453 | if (LOG_IOT_OVERLAP) |
| 507 | 454 | { |
| 508 | | if (timer_enable(tape_reader.timer, 0)) |
| 455 | if (timer_enable(state->tape_reader.timer, 0)) |
| 509 | 456 | logerror("Error: overlapped perforated tape reads (Read-in mode, RPA/RPB instruction)\n"); |
| 510 | 457 | } |
| 511 | 458 | /* set up delay if tape is advancing */ |
| 512 | | if (tape_reader.motor_on && tape_reader.rcl) |
| 459 | if (state->tape_reader.motor_on && state->tape_reader.rcl) |
| 513 | 460 | { |
| 514 | 461 | /* delay is approximately 1/400s */ |
| 515 | | timer_adjust_oneshot(tape_reader.timer, ATTOTIME_IN_USEC(2500), 0); |
| 462 | timer_adjust_oneshot(state->tape_reader.timer, ATTOTIME_IN_USEC(2500), 0); |
| 516 | 463 | } |
| 517 | 464 | else |
| 518 | 465 | { |
| 519 | | timer_enable(tape_reader.timer, 0); |
| 466 | timer_enable(state->tape_reader.timer, 0); |
| 520 | 467 | } |
| 521 | 468 | } |
| 522 | 469 | |
| r9667 | r9668 | |
| 525 | 472 | */ |
| 526 | 473 | static TIMER_CALLBACK(reader_callback) |
| 527 | 474 | { |
| 475 | pdp1_state *state = machine->driver_data<pdp1_state>(); |
| 528 | 476 | int not_ready; |
| 529 | 477 | UINT8 data; |
| 530 | 478 | |
| 531 | | if (tape_reader.rc) |
| 479 | if (state->tape_reader.rc) |
| 532 | 480 | { |
| 533 | | not_ready = tape_read(& data); |
| 481 | not_ready = tape_read(state, & data); |
| 534 | 482 | if (not_ready) |
| 535 | 483 | { |
| 536 | | tape_reader.motor_on = 0; /* let us stop the motor */ |
| 484 | state->tape_reader.motor_on = 0; /* let us stop the motor */ |
| 537 | 485 | } |
| 538 | 486 | else |
| 539 | 487 | { |
| 540 | | if ((! tape_reader.rby) || (data & 0200)) |
| 488 | if ((! state->tape_reader.rby) || (data & 0200)) |
| 541 | 489 | { |
| 542 | | tape_reader.rb |= (tape_reader.rby) ? (data & 077) : data; |
| 490 | state->tape_reader.rb |= (state->tape_reader.rby) ? (data & 077) : data; |
| 543 | 491 | |
| 544 | | if (tape_reader.rc != 3) |
| 492 | if (state->tape_reader.rc != 3) |
| 545 | 493 | { |
| 546 | | tape_reader.rb <<= 6; |
| 494 | state->tape_reader.rb <<= 6; |
| 547 | 495 | } |
| 548 | 496 | |
| 549 | | tape_reader.rc = (tape_reader.rc+1) & 3; |
| 497 | state->tape_reader.rc = (state->tape_reader.rc+1) & 3; |
| 550 | 498 | |
| 551 | | if (tape_reader.rc == 0) |
| 499 | if (state->tape_reader.rc == 0) |
| 552 | 500 | { /* IO complete */ |
| 553 | | tape_reader.rcl = 0; |
| 554 | | if (tape_reader.rcp) |
| 501 | state->tape_reader.rcl = 0; |
| 502 | if (state->tape_reader.rcp) |
| 555 | 503 | { |
| 556 | | cpu_set_reg(machine->device("maincpu"), PDP1_IO, tape_reader.rb); /* transfer reader buffer to IO */ |
| 504 | cpu_set_reg(machine->device("maincpu"), PDP1_IO, state->tape_reader.rb); /* transfer reader buffer to IO */ |
| 557 | 505 | pdp1_pulse_iot_done(machine->device("maincpu")); |
| 558 | 506 | } |
| 559 | 507 | else |
| 560 | | io_status |= io_st_ptr; |
| 508 | state->io_status |= io_st_ptr; |
| 561 | 509 | } |
| 562 | 510 | } |
| 563 | 511 | } |
| 564 | 512 | } |
| 565 | 513 | |
| 566 | | if (tape_reader.motor_on && tape_reader.rcl) |
| 514 | if (state->tape_reader.motor_on && state->tape_reader.rcl) |
| 567 | 515 | /* delay is approximately 1/400s */ |
| 568 | | timer_adjust_oneshot(tape_reader.timer, ATTOTIME_IN_USEC(2500), 0); |
| 516 | timer_adjust_oneshot(state->tape_reader.timer, ATTOTIME_IN_USEC(2500), 0); |
| 569 | 517 | else |
| 570 | | timer_enable(tape_reader.timer, 0); |
| 518 | timer_enable(state->tape_reader.timer, 0); |
| 571 | 519 | } |
| 572 | 520 | |
| 573 | 521 | /* |
| r9667 | r9668 | |
| 575 | 523 | */ |
| 576 | 524 | static TIMER_CALLBACK(puncher_callback) |
| 577 | 525 | { |
| 526 | pdp1_state *state = machine->driver_data<pdp1_state>(); |
| 578 | 527 | int nac = param; |
| 579 | | io_status |= io_st_ptp; |
| 528 | state->io_status |= io_st_ptp; |
| 580 | 529 | if (nac) |
| 581 | 530 | { |
| 582 | 531 | pdp1_pulse_iot_done(machine->device("maincpu")); |
| r9667 | r9668 | |
| 588 | 537 | */ |
| 589 | 538 | void pdp1_tape_read_binary(running_device *device) |
| 590 | 539 | { |
| 591 | | begin_tape_read(1, 1); |
| 540 | pdp1_state *state = device->machine->driver_data<pdp1_state>(); |
| 541 | begin_tape_read(state, 1, 1); |
| 592 | 542 | } |
| 593 | 543 | |
| 594 | 544 | /* |
| r9667 | r9668 | |
| 620 | 570 | */ |
| 621 | 571 | static void iot_rpa(running_device *device, int op2, int nac, int mb, int *io, int ac) |
| 622 | 572 | { |
| 573 | pdp1_state *state = device->machine->driver_data<pdp1_state>(); |
| 623 | 574 | if (LOG_IOT_EXTRA) |
| 624 | 575 | logerror("Warning, RPA instruction not fully emulated: mb=0%06o, (%s)\n", (unsigned) mb, cpuexec_describe_context(device->machine)); |
| 625 | 576 | |
| 626 | | begin_tape_read(0, nac); |
| 577 | begin_tape_read(state, 0, nac); |
| 627 | 578 | } |
| 628 | 579 | |
| 629 | 580 | /* |
| r9667 | r9668 | |
| 657 | 608 | */ |
| 658 | 609 | static void iot_rpb(running_device *device, int op2, int nac, int mb, int *io, int ac) |
| 659 | 610 | { |
| 611 | pdp1_state *state = device->machine->driver_data<pdp1_state>(); |
| 660 | 612 | if (LOG_IOT_EXTRA) |
| 661 | 613 | logerror("Warning, RPB instruction not fully emulated: mb=0%06o, (%s)\n", (unsigned) mb, cpuexec_describe_context(device->machine)); |
| 662 | 614 | |
| 663 | | begin_tape_read(1, nac); |
| 615 | begin_tape_read(state, 1, nac); |
| 664 | 616 | } |
| 665 | 617 | |
| 666 | 618 | /* |
| r9667 | r9668 | |
| 668 | 620 | */ |
| 669 | 621 | static void iot_rrb(running_device *device, int op2, int nac, int mb, int *io, int ac) |
| 670 | 622 | { |
| 623 | pdp1_state *state = device->machine->driver_data<pdp1_state>(); |
| 671 | 624 | if (LOG_IOT_EXTRA) |
| 672 | 625 | logerror("RRB instruction: mb=0%06o, (%s)\n", (unsigned) mb, cpuexec_describe_context(device->machine)); |
| 673 | 626 | |
| 674 | | *io = tape_reader.rb; |
| 675 | | io_status &= ~io_st_ptr; |
| 627 | *io = state->tape_reader.rb; |
| 628 | state->io_status &= ~io_st_ptr; |
| 676 | 629 | } |
| 677 | 630 | |
| 678 | 631 | /* |
| r9667 | r9668 | |
| 691 | 644 | */ |
| 692 | 645 | static void iot_ppa(running_device *device, int op2, int nac, int mb, int *io, int ac) |
| 693 | 646 | { |
| 647 | pdp1_state *state = device->machine->driver_data<pdp1_state>(); |
| 694 | 648 | if (LOG_IOT_EXTRA) |
| 695 | 649 | logerror("PPA instruction: mb=0%06o, (%s)\n", (unsigned) mb, cpuexec_describe_context(device->machine)); |
| 696 | 650 | |
| 697 | | tape_write(*io & 0377); |
| 698 | | io_status &= ~io_st_ptp; |
| 651 | tape_write(state, *io & 0377); |
| 652 | state->io_status &= ~io_st_ptp; |
| 699 | 653 | /* delay is approximately 1/63.3 second */ |
| 700 | 654 | if (LOG_IOT_OVERLAP) |
| 701 | 655 | { |
| 702 | | if (timer_enable(tape_puncher.timer, 0)) |
| 656 | if (timer_enable(state->tape_puncher.timer, 0)) |
| 703 | 657 | logerror("Error: overlapped PPA/PPB instructions: mb=0%06o, (%s)\n", (unsigned) mb, cpuexec_describe_context(device->machine)); |
| 704 | 658 | } |
| 705 | 659 | |
| 706 | | timer_adjust_oneshot(tape_puncher.timer, ATTOTIME_IN_USEC(15800), nac); |
| 660 | timer_adjust_oneshot(state->tape_puncher.timer, ATTOTIME_IN_USEC(15800), nac); |
| 707 | 661 | } |
| 708 | 662 | |
| 709 | 663 | /* |
| r9667 | r9668 | |
| 719 | 673 | */ |
| 720 | 674 | static void iot_ppb(running_device *device, int op2, int nac, int mb, int *io, int ac) |
| 721 | 675 | { |
| 676 | pdp1_state *state = device->machine->driver_data<pdp1_state>(); |
| 722 | 677 | if (LOG_IOT_EXTRA) |
| 723 | 678 | logerror("PPB instruction: mb=0%06o, (%s)\n", (unsigned) mb, cpuexec_describe_context(device->machine)); |
| 724 | 679 | |
| 725 | | tape_write((*io >> 12) | 0200); |
| 726 | | io_status &= ~io_st_ptp; |
| 680 | tape_write(state, (*io >> 12) | 0200); |
| 681 | state->io_status &= ~io_st_ptp; |
| 727 | 682 | /* delay is approximately 1/63.3 second */ |
| 728 | 683 | if (LOG_IOT_OVERLAP) |
| 729 | 684 | { |
| 730 | | if (timer_enable(tape_puncher.timer, 0)) |
| 685 | if (timer_enable(state->tape_puncher.timer, 0)) |
| 731 | 686 | logerror("Error: overlapped PPA/PPB instructions: mb=0%06o, (%s)\n", (unsigned) mb, cpuexec_describe_context(device->machine)); |
| 732 | 687 | } |
| 733 | | timer_adjust_oneshot(tape_puncher.timer, ATTOTIME_IN_USEC(15800), nac); |
| 688 | timer_adjust_oneshot(state->tape_puncher.timer, ATTOTIME_IN_USEC(15800), nac); |
| 734 | 689 | } |
| 735 | 690 | |
| 736 | 691 | |
| r9667 | r9668 | |
| 746 | 701 | */ |
| 747 | 702 | DEVICE_IMAGE_LOAD(pdp1_typewriter) |
| 748 | 703 | { |
| 704 | pdp1_state *state = image.device().machine->driver_data<pdp1_state>(); |
| 749 | 705 | /* open file */ |
| 750 | | typewriter.fd = ℑ |
| 706 | state->typewriter.fd = ℑ |
| 751 | 707 | |
| 752 | | io_status |= io_st_tyo; |
| 708 | state->io_status |= io_st_tyo; |
| 753 | 709 | |
| 754 | 710 | return IMAGE_INIT_PASS; |
| 755 | 711 | } |
| 756 | 712 | |
| 757 | 713 | DEVICE_IMAGE_UNLOAD(pdp1_typewriter) |
| 758 | 714 | { |
| 759 | | typewriter.fd = NULL; |
| 715 | pdp1_state *state = image.device().machine->driver_data<pdp1_state>(); |
| 716 | state->typewriter.fd = NULL; |
| 760 | 717 | } |
| 761 | 718 | |
| 762 | 719 | /* |
| r9667 | r9668 | |
| 764 | 721 | */ |
| 765 | 722 | static void typewriter_out(running_machine *machine, UINT8 data) |
| 766 | 723 | { |
| 724 | pdp1_state *state = machine->driver_data<pdp1_state>(); |
| 767 | 725 | if (LOG_IOT_EXTRA) |
| 768 | 726 | logerror("typewriter output %o\n", data); |
| 769 | 727 | |
| 770 | 728 | pdp1_typewriter_drawchar(machine, data); |
| 771 | | if (typewriter.fd) |
| 729 | if (state->typewriter.fd) |
| 772 | 730 | #if 1 |
| 773 | | typewriter.fd->fwrite(& data, 1); |
| 731 | state->typewriter.fd->fwrite(& data, 1); |
| 774 | 732 | #else |
| 775 | 733 | { |
| 776 | 734 | static const char ascii_table[2][64] = |
| r9667 | r9668 | |
| 812 | 770 | '*',/*Upper Case*/ '\b',/*Backspace*/ '*', '*'/*Carriage Return*/ |
| 813 | 771 | } |
| 814 | 772 | }; |
| 815 | | static int case_shift; |
| 816 | 773 | |
| 817 | 774 | data &= 0x3f; |
| 818 | 775 | |
| r9667 | r9668 | |
| 823 | 780 | //color = color_typewriter_black; |
| 824 | 781 | { |
| 825 | 782 | static const char black[5] = { '\033', '[', '3', '0', 'm' }; |
| 826 | | image_fwrite(typewriter.fd, black, sizeof(black)); |
| 783 | image_fwrite(state->typewriter.fd, black, sizeof(black)); |
| 827 | 784 | } |
| 828 | 785 | break; |
| 829 | 786 | |
| r9667 | r9668 | |
| 832 | 789 | //color = color_typewriter_red; |
| 833 | 790 | { |
| 834 | 791 | static const char red[5] = { '\033', '[', '3', '1', 'm' }; |
| 835 | | image_fwrite(typewriter.fd, red, sizeof(red)); |
| 792 | image_fwrite(state->typewriter.fd, red, sizeof(red)); |
| 836 | 793 | } |
| 837 | 794 | break; |
| 838 | 795 | |
| 839 | 796 | case 072: |
| 840 | 797 | /* Lower case */ |
| 841 | | case_shift = 0; |
| 798 | state->case_shift = 0; |
| 842 | 799 | break; |
| 843 | 800 | |
| 844 | 801 | case 074: |
| 845 | 802 | /* Upper case */ |
| 846 | | case_shift = 1; |
| 803 | state->case_shift = 1; |
| 847 | 804 | break; |
| 848 | 805 | |
| 849 | 806 | case 077: |
| 850 | 807 | /* Carriage Return */ |
| 851 | 808 | { |
| 852 | 809 | static const char line_end[2] = { '\r', '\n' }; |
| 853 | | image_fwrite(typewriter.fd, line_end, sizeof(line_end)); |
| 810 | image_fwrite(state->typewriter.fd, line_end, sizeof(line_end)); |
| 854 | 811 | } |
| 855 | 812 | break; |
| 856 | 813 | |
| r9667 | r9668 | |
| 859 | 816 | |
| 860 | 817 | if ((data != 040) && (data != 056)) /* 040 and 056 are non-spacing characters: don't try to print right now */ |
| 861 | 818 | /* print character (lookup ASCII equivalent in table) */ |
| 862 | | image_fwrite(typewriter.fd, & ascii_table[case_shift][data], 1); |
| 819 | image_fwrite(state->typewriter.fd, & ascii_table[state->case_shift][data], 1); |
| 863 | 820 | |
| 864 | 821 | break; |
| 865 | 822 | } |
| r9667 | r9668 | |
| 872 | 829 | */ |
| 873 | 830 | static TIMER_CALLBACK(tyo_callback) |
| 874 | 831 | { |
| 832 | pdp1_state *state = machine->driver_data<pdp1_state>(); |
| 875 | 833 | int nac = param; |
| 876 | | io_status |= io_st_tyo; |
| 834 | state->io_status |= io_st_tyo; |
| 877 | 835 | if (nac) |
| 878 | 836 | { |
| 879 | 837 | pdp1_pulse_iot_done(machine->device("maincpu")); |
| r9667 | r9668 | |
| 885 | 843 | */ |
| 886 | 844 | static void iot_tyo(running_device *device, int op2, int nac, int mb, int *io, int ac) |
| 887 | 845 | { |
| 846 | pdp1_state *state = device->machine->driver_data<pdp1_state>(); |
| 888 | 847 | int ch, delay; |
| 889 | 848 | |
| 890 | 849 | if (LOG_IOT_EXTRA) |
| r9667 | r9668 | |
| 893 | 852 | ch = (*io) & 077; |
| 894 | 853 | |
| 895 | 854 | typewriter_out(device->machine, ch); |
| 896 | | io_status &= ~io_st_tyo; |
| 855 | state->io_status &= ~io_st_tyo; |
| 897 | 856 | |
| 898 | 857 | /* compute completion delay (source: maintainance manual 9-12, 9-13 and 9-14) */ |
| 899 | 858 | switch (ch) |
| r9667 | r9668 | |
| 915 | 874 | } |
| 916 | 875 | if (LOG_IOT_OVERLAP) |
| 917 | 876 | { |
| 918 | | if (timer_enable(typewriter.tyo_timer, 0)) |
| 877 | if (timer_enable(state->typewriter.tyo_timer, 0)) |
| 919 | 878 | logerror("Error: overlapped TYO instruction: mb=0%06o, (%s)\n", (unsigned) mb, cpuexec_describe_context(device->machine)); |
| 920 | 879 | } |
| 921 | 880 | |
| 922 | | timer_adjust_oneshot(typewriter.tyo_timer, ATTOTIME_IN_MSEC(delay), nac); |
| 881 | timer_adjust_oneshot(state->typewriter.tyo_timer, ATTOTIME_IN_MSEC(delay), nac); |
| 923 | 882 | } |
| 924 | 883 | |
| 925 | 884 | /* |
| r9667 | r9668 | |
| 938 | 897 | */ |
| 939 | 898 | static void iot_tyi(running_device *device, int op2, int nac, int mb, int *io, int ac) |
| 940 | 899 | { |
| 900 | pdp1_state *state = device->machine->driver_data<pdp1_state>(); |
| 941 | 901 | if (LOG_IOT_EXTRA) |
| 942 | 902 | logerror("Warning, TYI instruction not fully emulated: mb=0%06o, (%s)\n", (unsigned) mb, cpuexec_describe_context(device->machine)); |
| 943 | 903 | |
| 944 | | *io = typewriter.tb; |
| 945 | | if (! (io_status & io_st_tyi)) |
| 904 | *io = state->typewriter.tb; |
| 905 | if (! (state->io_status & io_st_tyi)) |
| 946 | 906 | *io |= 0100; |
| 947 | 907 | else |
| 948 | 908 | { |
| 949 | | io_status &= ~io_st_tyi; |
| 909 | state->io_status &= ~io_st_tyi; |
| 950 | 910 | if (USE_SBS) |
| 951 | 911 | cputag_set_input_line_and_vector(device->machine, "maincpu", 0, CLEAR_LINE, 0); /* interrupt it, baby */ |
| 952 | 912 | } |
| r9667 | r9668 | |
| 1003 | 963 | */ |
| 1004 | 964 | static void iot_dpy(running_device *device, int op2, int nac, int mb, int *io, int ac) |
| 1005 | 965 | { |
| 966 | pdp1_state *state = device->machine->driver_data<pdp1_state>(); |
| 1006 | 967 | int x; |
| 1007 | 968 | int y; |
| 1008 | 969 | |
| r9667 | r9668 | |
| 1012 | 973 | pdp1_plot(x, y); |
| 1013 | 974 | |
| 1014 | 975 | /* light pen 32 support */ |
| 1015 | | io_status &= ~io_st_pen; |
| 976 | state->io_status &= ~io_st_pen; |
| 1016 | 977 | |
| 1017 | | if (lightpen.down && ((x-lightpen.x)*(x-lightpen.x)+(y-lightpen.y)*(y-lightpen.y) < lightpen.radius*lightpen.radius)) |
| 978 | if (state->lightpen.down && ((x-state->lightpen.x)*(x-state->lightpen.x)+(y-state->lightpen.y)*(y-state->lightpen.y) < state->lightpen.radius*state->lightpen.radius)) |
| 1018 | 979 | { |
| 1019 | | io_status |= io_st_pen; |
| 980 | state->io_status |= io_st_pen; |
| 1020 | 981 | |
| 1021 | 982 | cpu_set_reg(device->machine->device("maincpu"), PDP1_PF3, 1); |
| 1022 | 983 | } |
| r9667 | r9668 | |
| 1028 | 989 | { |
| 1029 | 990 | /* note that overlap detection is incomplete: it will only work if both DPY |
| 1030 | 991 | instructions require a completion pulse */ |
| 1031 | | if (timer_enable(dpy_timer, 0)) |
| 992 | if (timer_enable(state->dpy_timer, 0)) |
| 1032 | 993 | logerror("Error: overlapped DPY instruction: mb=0%06o, (%s)\n", (unsigned) mb, cpuexec_describe_context(device->machine)); |
| 1033 | 994 | } |
| 1034 | | timer_adjust_oneshot(dpy_timer, ATTOTIME_IN_USEC(50), 0); |
| 995 | timer_adjust_oneshot(state->dpy_timer, ATTOTIME_IN_USEC(50), 0); |
| 1035 | 996 | } |
| 1036 | 997 | } |
| 1037 | 998 | |
| r9667 | r9668 | |
| 1041 | 1002 | MIT parallel drum (variant of type 23) |
| 1042 | 1003 | */ |
| 1043 | 1004 | |
| 1044 | | static void parallel_drum_set_il(int il) |
| 1005 | static void parallel_drum_set_il(pdp1_state *state, int il) |
| 1045 | 1006 | { |
| 1046 | 1007 | attotime il_phase; |
| 1047 | 1008 | |
| 1048 | | parallel_drum.il = il; |
| 1009 | state->parallel_drum.il = il; |
| 1049 | 1010 | |
| 1050 | | il_phase = attotime_sub(attotime_mul(PARALLEL_DRUM_WORD_TIME, il), timer_timeelapsed(parallel_drum.rotation_timer)); |
| 1011 | il_phase = attotime_sub(attotime_mul(PARALLEL_DRUM_WORD_TIME, il), timer_timeelapsed(state->parallel_drum.rotation_timer)); |
| 1051 | 1012 | if (attotime_compare(il_phase, attotime_zero) < 0) |
| 1052 | 1013 | il_phase = attotime_add(il_phase, PARALLEL_DRUM_ROTATION_TIME); |
| 1053 | | timer_adjust_periodic(parallel_drum.il_timer, il_phase, 0, PARALLEL_DRUM_ROTATION_TIME); |
| 1014 | timer_adjust_periodic(state->parallel_drum.il_timer, il_phase, 0, PARALLEL_DRUM_ROTATION_TIME); |
| 1054 | 1015 | } |
| 1055 | 1016 | |
| 1056 | 1017 | #ifdef UNUSED_FUNCTION |
| 1057 | 1018 | static TIMER_CALLBACK(il_timer_callback) |
| 1058 | 1019 | { |
| 1059 | | if (parallel_drum.dba) |
| 1020 | pdp1_state *state = machine->driver_data<pdp1_state>(); |
| 1021 | if (state->parallel_drum.dba) |
| 1060 | 1022 | { |
| 1061 | 1023 | /* set break request and status bit 5 */ |
| 1062 | 1024 | /* ... */ |
| 1063 | 1025 | } |
| 1064 | 1026 | } |
| 1065 | 1027 | |
| 1066 | | static void parallel_drum_init(void) |
| 1028 | static void parallel_drum_init(pdp1_state *state) |
| 1067 | 1029 | { |
| 1068 | | parallel_drum.rotation_timer = timer_alloc(machine, NULL, NULL); |
| 1069 | | timer_adjust_periodic(parallel_drum.rotation_timer, PARALLEL_DRUM_ROTATION_TIME, 0, PARALLEL_DRUM_ROTATION_TIME); |
| 1030 | state->parallel_drum.rotation_timer = timer_alloc(machine, NULL, NULL); |
| 1031 | timer_adjust_periodic(state->parallel_drum.rotation_timer, PARALLEL_DRUM_ROTATION_TIME, 0, PARALLEL_DRUM_ROTATION_TIME); |
| 1070 | 1032 | |
| 1071 | | parallel_drum.il_timer = timer_alloc(machine, il_timer_callback, NULL); |
| 1033 | state->parallel_drum.il_timer = timer_alloc(machine, il_timer_callback, NULL); |
| 1072 | 1034 | parallel_drum_set_il(0); |
| 1073 | 1035 | } |
| 1074 | 1036 | #endif |
| r9667 | r9668 | |
| 1078 | 1040 | */ |
| 1079 | 1041 | DEVICE_IMAGE_LOAD(pdp1_drum) |
| 1080 | 1042 | { |
| 1043 | pdp1_state *state = image.device().machine->driver_data<pdp1_state>(); |
| 1081 | 1044 | /* open file */ |
| 1082 | | parallel_drum.fd = ℑ |
| 1045 | state->parallel_drum.fd = ℑ |
| 1083 | 1046 | |
| 1084 | 1047 | return IMAGE_INIT_PASS; |
| 1085 | 1048 | } |
| 1086 | 1049 | |
| 1087 | 1050 | DEVICE_IMAGE_UNLOAD(pdp1_drum) |
| 1088 | 1051 | { |
| 1089 | | parallel_drum.fd = NULL; |
| 1052 | pdp1_state *state = image.device().machine->driver_data<pdp1_state>(); |
| 1053 | state->parallel_drum.fd = NULL; |
| 1090 | 1054 | } |
| 1091 | 1055 | |
| 1092 | 1056 | static void iot_dia(running_device *device, int op2, int nac, int mb, int *io, int ac) |
| 1093 | 1057 | { |
| 1094 | | parallel_drum.wfb = ((*io) & 0370000) >> 12; |
| 1095 | | parallel_drum_set_il((*io) & 0007777); |
| 1058 | pdp1_state *state = device->machine->driver_data<pdp1_state>(); |
| 1059 | state->parallel_drum.wfb = ((*io) & 0370000) >> 12; |
| 1060 | parallel_drum_set_il(state, (*io) & 0007777); |
| 1096 | 1061 | |
| 1097 | | parallel_drum.dba = 0; /* right? */ |
| 1062 | state->parallel_drum.dba = 0; /* right? */ |
| 1098 | 1063 | } |
| 1099 | 1064 | |
| 1100 | 1065 | static void iot_dba(running_device *device, int op2, int nac, int mb, int *io, int ac) |
| 1101 | 1066 | { |
| 1102 | | parallel_drum.wfb = ((*io) & 0370000) >> 12; |
| 1103 | | parallel_drum_set_il((*io) & 0007777); |
| 1067 | pdp1_state *state = device->machine->driver_data<pdp1_state>(); |
| 1068 | state->parallel_drum.wfb = ((*io) & 0370000) >> 12; |
| 1069 | parallel_drum_set_il(state, (*io) & 0007777); |
| 1104 | 1070 | |
| 1105 | | parallel_drum.dba = 1; |
| 1071 | state->parallel_drum.dba = 1; |
| 1106 | 1072 | } |
| 1107 | 1073 | |
| 1108 | 1074 | /* |
| 1109 | 1075 | Read a word from drum |
| 1110 | 1076 | */ |
| 1111 | | static UINT32 drum_read(int field, int position) |
| 1077 | static UINT32 drum_read(pdp1_state *state, int field, int position) |
| 1112 | 1078 | { |
| 1113 | 1079 | int offset = (field*4096+position)*3; |
| 1114 | 1080 | UINT8 buf[3]; |
| 1115 | 1081 | |
| 1116 | | if (parallel_drum.fd && (!parallel_drum.fd->fseek(offset, SEEK_SET)) && (parallel_drum.fd->fread( buf, 3) == 3)) |
| 1082 | if (state->parallel_drum.fd && (!state->parallel_drum.fd->fseek(offset, SEEK_SET)) && (state->parallel_drum.fd->fread( buf, 3) == 3)) |
| 1117 | 1083 | return ((buf[0] << 16) | (buf[1] << 8) | buf[2]) & 0777777; |
| 1118 | 1084 | |
| 1119 | 1085 | return 0; |
| r9667 | r9668 | |
| 1122 | 1088 | /* |
| 1123 | 1089 | Write a word to drum |
| 1124 | 1090 | */ |
| 1125 | | static void drum_write(int field, int position, UINT32 data) |
| 1091 | static void drum_write(pdp1_state *state, int field, int position, UINT32 data) |
| 1126 | 1092 | { |
| 1127 | 1093 | int offset = (field*4096+position)*3; |
| 1128 | 1094 | UINT8 buf[3]; |
| 1129 | 1095 | |
| 1130 | | if (parallel_drum.fd) |
| 1096 | if (state->parallel_drum.fd) |
| 1131 | 1097 | { |
| 1132 | 1098 | buf[0] = data >> 16; |
| 1133 | 1099 | buf[1] = data >> 8; |
| 1134 | 1100 | buf[2] = data; |
| 1135 | 1101 | |
| 1136 | | parallel_drum.fd->fseek(offset, SEEK_SET); |
| 1137 | | parallel_drum.fd->fwrite( buf, 3); |
| 1102 | state->parallel_drum.fd->fseek(offset, SEEK_SET); |
| 1103 | state->parallel_drum.fd->fwrite( buf, 3); |
| 1138 | 1104 | } |
| 1139 | 1105 | } |
| 1140 | 1106 | |
| 1141 | 1107 | static void iot_dcc(running_device *device, int op2, int nac, int mb, int *io, int ac) |
| 1142 | 1108 | { |
| 1109 | pdp1_state *state = device->machine->driver_data<pdp1_state>(); |
| 1143 | 1110 | attotime delay; |
| 1144 | 1111 | int dc; |
| 1145 | 1112 | |
| 1146 | | parallel_drum.rfb = ((*io) & 0370000) >> 12; |
| 1147 | | parallel_drum.wc = - ((*io) & 0007777); |
| 1113 | state->parallel_drum.rfb = ((*io) & 0370000) >> 12; |
| 1114 | state->parallel_drum.wc = - ((*io) & 0007777); |
| 1148 | 1115 | |
| 1149 | | parallel_drum.wcl = ac & 0177777/*0007777???*/; |
| 1116 | state->parallel_drum.wcl = ac & 0177777/*0007777???*/; |
| 1150 | 1117 | |
| 1151 | | parallel_drum.dba = 0; /* right? */ |
| 1118 | state->parallel_drum.dba = 0; /* right? */ |
| 1152 | 1119 | /* clear status bit 5... */ |
| 1153 | 1120 | |
| 1154 | 1121 | /* do transfer */ |
| 1155 | | delay = timer_timeleft(parallel_drum.il_timer); |
| 1156 | | dc = parallel_drum.il; |
| 1122 | delay = timer_timeleft(state->parallel_drum.il_timer); |
| 1123 | dc = state->parallel_drum.il; |
| 1157 | 1124 | do |
| 1158 | 1125 | { |
| 1159 | | if ((parallel_drum.wfb >= 1) && (parallel_drum.wfb <= 22)) |
| 1126 | if ((state->parallel_drum.wfb >= 1) && (state->parallel_drum.wfb <= 22)) |
| 1160 | 1127 | { |
| 1161 | | drum_write(parallel_drum.wfb-1, dc, (signed)cputag_get_address_space(device->machine,"maincpu", ADDRESS_SPACE_PROGRAM)->read_dword(parallel_drum.wcl<<2)); |
| 1128 | drum_write(state, state->parallel_drum.wfb-1, dc, (signed)cputag_get_address_space(device->machine,"maincpu", ADDRESS_SPACE_PROGRAM)->read_dword(state->parallel_drum.wcl<<2)); |
| 1162 | 1129 | } |
| 1163 | 1130 | |
| 1164 | | if ((parallel_drum.rfb >= 1) && (parallel_drum.rfb <= 22)) |
| 1131 | if ((state->parallel_drum.rfb >= 1) && (state->parallel_drum.rfb <= 22)) |
| 1165 | 1132 | { |
| 1166 | | cputag_get_address_space(device->machine,"maincpu", ADDRESS_SPACE_PROGRAM)->write_dword(parallel_drum.wcl<<2, drum_read(parallel_drum.rfb-1, dc)); |
| 1133 | cputag_get_address_space(device->machine,"maincpu", ADDRESS_SPACE_PROGRAM)->write_dword(state->parallel_drum.wcl<<2, drum_read(state, state->parallel_drum.rfb-1, dc)); |
| 1167 | 1134 | } |
| 1168 | 1135 | |
| 1169 | | parallel_drum.wc = (parallel_drum.wc+1) & 07777; |
| 1170 | | parallel_drum.wcl = (parallel_drum.wcl+1) & 0177777/*0007777???*/; |
| 1136 | state->parallel_drum.wc = (state->parallel_drum.wc+1) & 07777; |
| 1137 | state->parallel_drum.wcl = (state->parallel_drum.wcl+1) & 0177777/*0007777???*/; |
| 1171 | 1138 | dc = (dc+1) & 07777; |
| 1172 | | if (parallel_drum.wc) |
| 1139 | if (state->parallel_drum.wc) |
| 1173 | 1140 | delay = attotime_add(delay, PARALLEL_DRUM_WORD_TIME); |
| 1174 | | } while (parallel_drum.wc); |
| 1141 | } while (state->parallel_drum.wc); |
| 1175 | 1142 | cpu_adjust_icount(device->machine->device("maincpu"),-device->machine->device<cpu_device>("maincpu")->attotime_to_cycles(delay)); |
| 1176 | 1143 | /* if no error, skip */ |
| 1177 | 1144 | cpu_set_reg(device->machine->device("maincpu"), PDP1_PC, cpu_get_reg(device->machine->device("maincpu"), PDP1_PC)+1); |
| r9667 | r9668 | |
| 1179 | 1146 | |
| 1180 | 1147 | static void iot_dra(running_device *device, int op2, int nac, int mb, int *io, int ac) |
| 1181 | 1148 | { |
| 1149 | pdp1_state *state = device->machine->driver_data<pdp1_state>(); |
| 1182 | 1150 | (*io) = attotime_mul( |
| 1183 | | timer_timeelapsed(parallel_drum.rotation_timer), |
| 1151 | timer_timeelapsed(state->parallel_drum.rotation_timer), |
| 1184 | 1152 | ATTOSECONDS_PER_SECOND / (attotime_to_attoseconds(PARALLEL_DRUM_WORD_TIME))).seconds & 0007777; |
| 1185 | 1153 | |
| 1186 | 1154 | /* set parity error and timing error... */ |
| r9667 | r9668 | |
| 1240 | 1208 | */ |
| 1241 | 1209 | static void iot_cks(running_device *device, int op2, int nac, int mb, int *io, int ac) |
| 1242 | 1210 | { |
| 1211 | pdp1_state *state = device->machine->driver_data<pdp1_state>(); |
| 1243 | 1212 | if (LOG_IOT_EXTRA) |
| 1244 | 1213 | logerror("CKS instruction: mb=0%06o, (%s)\n", (unsigned) mb, cpuexec_describe_context(device->machine)); |
| 1245 | 1214 | |
| 1246 | | *io = io_status; |
| 1215 | *io = state->io_status; |
| 1247 | 1216 | } |
| 1248 | 1217 | |
| 1249 | 1218 | |
| r9667 | r9668 | |
| 1254 | 1223 | */ |
| 1255 | 1224 | void pdp1_io_sc_callback(running_device *device) |
| 1256 | 1225 | { |
| 1257 | | tape_reader.rcl = tape_reader.rc = 0; |
| 1258 | | if (tape_reader.timer) |
| 1259 | | timer_enable(tape_reader.timer, 0); |
| 1226 | pdp1_state *state = device->machine->driver_data<pdp1_state>(); |
| 1227 | state->tape_reader.rcl = state->tape_reader.rc = 0; |
| 1228 | if (state->tape_reader.timer) |
| 1229 | timer_enable(state->tape_reader.timer, 0); |
| 1260 | 1230 | |
| 1261 | | if (tape_puncher.timer) |
| 1262 | | timer_enable(tape_puncher.timer, 0); |
| 1231 | if (state->tape_puncher.timer) |
| 1232 | timer_enable(state->tape_puncher.timer, 0); |
| 1263 | 1233 | |
| 1264 | | if (typewriter.tyo_timer) |
| 1265 | | timer_enable(typewriter.tyo_timer, 0); |
| 1234 | if (state->typewriter.tyo_timer) |
| 1235 | timer_enable(state->typewriter.tyo_timer, 0); |
| 1266 | 1236 | |
| 1267 | | if (dpy_timer) |
| 1268 | | timer_enable(dpy_timer, 0); |
| 1237 | if (state->dpy_timer) |
| 1238 | timer_enable(state->dpy_timer, 0); |
| 1269 | 1239 | |
| 1270 | | io_status = io_st_tyo | io_st_ptp; |
| 1240 | state->io_status = io_st_tyo | io_st_ptp; |
| 1271 | 1241 | } |
| 1272 | 1242 | |
| 1273 | 1243 | |
| r9667 | r9668 | |
| 1276 | 1246 | */ |
| 1277 | 1247 | static void pdp1_keyboard(running_machine *machine) |
| 1278 | 1248 | { |
| 1249 | pdp1_state *state = machine->driver_data<pdp1_state>(); |
| 1279 | 1250 | int i; |
| 1280 | 1251 | int j; |
| 1281 | 1252 | |
| 1282 | 1253 | int typewriter_keys[4]; |
| 1283 | | static int old_typewriter_keys[4]; |
| 1284 | 1254 | |
| 1285 | 1255 | int typewriter_transitions; |
| 1286 | 1256 | static const char *const twrnames[] = { "TWR0", "TWR1", "TWR2", "TWR3" }; |
| r9667 | r9668 | |
| 1293 | 1263 | |
| 1294 | 1264 | for (i=0; i<4; i++) |
| 1295 | 1265 | { |
| 1296 | | typewriter_transitions = typewriter_keys[i] & (~ old_typewriter_keys[i]); |
| 1266 | typewriter_transitions = typewriter_keys[i] & (~ state->old_typewriter_keys[i]); |
| 1297 | 1267 | if (typewriter_transitions) |
| 1298 | 1268 | { |
| 1299 | 1269 | for (j=0; (((typewriter_transitions >> j) & 1) == 0) /*&& (j<16)*/; j++) |
| 1300 | 1270 | ; |
| 1301 | | typewriter.tb = (i << 4) + j; |
| 1302 | | io_status |= io_st_tyi; |
| 1271 | state->typewriter.tb = (i << 4) + j; |
| 1272 | state->io_status |= io_st_tyi; |
| 1303 | 1273 | #if USE_SBS |
| 1304 | 1274 | cputag_set_input_line_and_vector(machine, "maincpu", 0, ASSERT_LINE, 0); /* interrupt it, baby */ |
| 1305 | 1275 | #endif |
| 1306 | 1276 | cpu_set_reg(machine->device("maincpu"), PDP1_PF1, 1); |
| 1307 | | pdp1_typewriter_drawchar(machine, typewriter.tb); /* we want to echo input */ |
| 1277 | pdp1_typewriter_drawchar(machine, state->typewriter.tb); /* we want to echo input */ |
| 1308 | 1278 | break; |
| 1309 | 1279 | } |
| 1310 | 1280 | } |
| 1311 | 1281 | |
| 1312 | 1282 | for (i=0; i<4; i++) |
| 1313 | | old_typewriter_keys[i] = typewriter_keys[i]; |
| 1283 | state->old_typewriter_keys[i] = typewriter_keys[i]; |
| 1314 | 1284 | } |
| 1315 | 1285 | |
| 1316 | 1286 | static void pdp1_lightpen(running_machine *machine) |
| 1317 | 1287 | { |
| 1288 | pdp1_state *state = machine->driver_data<pdp1_state>(); |
| 1318 | 1289 | int x_delta, y_delta; |
| 1319 | 1290 | int current_state; |
| 1320 | | static int previous_state; |
| 1321 | 1291 | |
| 1322 | | lightpen.active = (input_port_read(machine, "CFG") >> pdp1_config_lightpen_bit) & pdp1_config_lightpen_mask; |
| 1292 | state->lightpen.active = (input_port_read(machine, "CFG") >> pdp1_config_lightpen_bit) & pdp1_config_lightpen_mask; |
| 1323 | 1293 | |
| 1324 | 1294 | current_state = input_port_read(machine, "LIGHTPEN"); |
| 1325 | 1295 | |
| 1326 | 1296 | /* update pen down state */ |
| 1327 | | lightpen.down = lightpen.active && (current_state & pdp1_lightpen_down); |
| 1297 | state->lightpen.down = state->lightpen.active && (current_state & pdp1_lightpen_down); |
| 1328 | 1298 | |
| 1329 | 1299 | /* update size of pen tip hole */ |
| 1330 | | if ((current_state & ~previous_state) & pdp1_lightpen_smaller) |
| 1300 | if ((current_state & ~state->old_lightpen) & pdp1_lightpen_smaller) |
| 1331 | 1301 | { |
| 1332 | | lightpen.radius --; |
| 1333 | | if (lightpen.radius < 0) |
| 1334 | | lightpen.radius = 0; |
| 1302 | state->lightpen.radius --; |
| 1303 | if (state->lightpen.radius < 0) |
| 1304 | state->lightpen.radius = 0; |
| 1335 | 1305 | } |
| 1336 | | if ((current_state & ~previous_state) & pdp1_lightpen_larger) |
| 1306 | if ((current_state & ~state->old_lightpen) & pdp1_lightpen_larger) |
| 1337 | 1307 | { |
| 1338 | | lightpen.radius ++; |
| 1339 | | if (lightpen.radius > 32) |
| 1340 | | lightpen.radius = 32; |
| 1308 | state->lightpen.radius ++; |
| 1309 | if (state->lightpen.radius > 32) |
| 1310 | state->lightpen.radius = 32; |
| 1341 | 1311 | } |
| 1342 | 1312 | |
| 1343 | | previous_state = current_state; |
| 1313 | state->old_lightpen = current_state; |
| 1344 | 1314 | |
| 1345 | 1315 | /* update pen position */ |
| 1346 | 1316 | x_delta = input_port_read(machine, "LIGHTX"); |
| r9667 | r9668 | |
| 1351 | 1321 | if (y_delta >= 0x80) |
| 1352 | 1322 | y_delta -= 256; |
| 1353 | 1323 | |
| 1354 | | lightpen.x += x_delta; |
| 1355 | | lightpen.y += y_delta; |
| 1324 | state->lightpen.x += x_delta; |
| 1325 | state->lightpen.y += y_delta; |
| 1356 | 1326 | |
| 1357 | | if (lightpen.x < 0) |
| 1358 | | lightpen.x = 0; |
| 1359 | | if (lightpen.x > 1023) |
| 1360 | | lightpen.x = 1023; |
| 1361 | | if (lightpen.y < 0) |
| 1362 | | lightpen.y = 0; |
| 1363 | | if (lightpen.y > 1023) |
| 1364 | | lightpen.y = 1023; |
| 1327 | if (state->lightpen.x < 0) |
| 1328 | state->lightpen.x = 0; |
| 1329 | if (state->lightpen.x > 1023) |
| 1330 | state->lightpen.x = 1023; |
| 1331 | if (state->lightpen.y < 0) |
| 1332 | state->lightpen.y = 0; |
| 1333 | if (state->lightpen.y > 1023) |
| 1334 | state->lightpen.y = 1023; |
| 1365 | 1335 | |
| 1366 | | pdp1_update_lightpen_state(&lightpen); |
| 1336 | pdp1_update_lightpen_state(machine, &state->lightpen); |
| 1367 | 1337 | } |
| 1368 | 1338 | |
| 1369 | 1339 | /* |
| r9667 | r9668 | |
| 1371 | 1341 | */ |
| 1372 | 1342 | INTERRUPT_GEN( pdp1_interrupt ) |
| 1373 | 1343 | { |
| 1344 | pdp1_state *state = device->machine->driver_data<pdp1_state>(); |
| 1374 | 1345 | running_machine *machine = device->machine; |
| 1375 | 1346 | int control_keys; |
| 1376 | 1347 | int tw_keys; |
| 1377 | 1348 | int ta_keys; |
| 1378 | 1349 | |
| 1379 | | static int old_control_keys; |
| 1380 | | static int old_tw_keys; |
| 1381 | | static int old_ta_keys; |
| 1382 | | |
| 1383 | 1350 | int control_transitions; |
| 1384 | 1351 | int tw_transitions; |
| 1385 | 1352 | int ta_transitions; |
| r9667 | r9668 | |
| 1393 | 1360 | if (control_keys & pdp1_control) |
| 1394 | 1361 | { |
| 1395 | 1362 | /* compute transitions */ |
| 1396 | | control_transitions = control_keys & (~ old_control_keys); |
| 1363 | control_transitions = control_keys & (~ state->old_control_keys); |
| 1397 | 1364 | |
| 1398 | 1365 | if (control_transitions & pdp1_extend) |
| 1399 | 1366 | { |
| r9667 | r9668 | |
| 1476 | 1443 | } |
| 1477 | 1444 | |
| 1478 | 1445 | /* remember new state of control keys */ |
| 1479 | | old_control_keys = control_keys; |
| 1446 | state->old_control_keys = control_keys; |
| 1480 | 1447 | |
| 1481 | 1448 | |
| 1482 | 1449 | /* handle test word keys */ |
| 1483 | 1450 | tw_keys = (input_port_read(machine, "TWDMSB") << 16) | input_port_read(machine, "TWDLSB"); |
| 1484 | 1451 | |
| 1485 | 1452 | /* compute transitions */ |
| 1486 | | tw_transitions = tw_keys & (~ old_tw_keys); |
| 1453 | tw_transitions = tw_keys & (~ state->old_tw_keys); |
| 1487 | 1454 | |
| 1488 | 1455 | if (tw_transitions) |
| 1489 | 1456 | cpu_set_reg(device, PDP1_TW, cpu_get_reg(device, PDP1_TW) ^ tw_transitions); |
| 1490 | 1457 | |
| 1491 | 1458 | /* remember new state of test word keys */ |
| 1492 | | old_tw_keys = tw_keys; |
| 1459 | state->old_tw_keys = tw_keys; |
| 1493 | 1460 | |
| 1494 | 1461 | |
| 1495 | 1462 | /* handle address keys */ |
| 1496 | 1463 | ta_keys = input_port_read(machine, "TSTADD"); |
| 1497 | 1464 | |
| 1498 | 1465 | /* compute transitions */ |
| 1499 | | ta_transitions = ta_keys & (~ old_ta_keys); |
| 1466 | ta_transitions = ta_keys & (~ state->old_ta_keys); |
| 1500 | 1467 | |
| 1501 | 1468 | if (ta_transitions) |
| 1502 | 1469 | cpu_set_reg(device, PDP1_TA, cpu_get_reg(device, PDP1_TA) ^ ta_transitions); |
| 1503 | 1470 | |
| 1504 | 1471 | /* remember new state of test word keys */ |
| 1505 | | old_ta_keys = ta_keys; |
| 1472 | state->old_ta_keys = ta_keys; |
| 1506 | 1473 | |
| 1507 | 1474 | } |
| 1508 | 1475 | else |
| 1509 | 1476 | { |
| 1510 | | old_control_keys = 0; |
| 1511 | | old_tw_keys = 0; |
| 1512 | | old_ta_keys = 0; |
| 1477 | state->old_control_keys = 0; |
| 1478 | state->old_tw_keys = 0; |
| 1479 | state->old_ta_keys = 0; |
| 1513 | 1480 | |
| 1514 | 1481 | pdp1_keyboard(machine); |
| 1515 | 1482 | } |
src/mess/machine/tx0.c
| r9667 | r9668 | |
| 16 | 16 | static TIMER_CALLBACK(dis_callback); |
| 17 | 17 | |
| 18 | 18 | |
| 19 | | /* tape reader registers */ |
| 20 | | typedef struct tape_reader_t |
| 21 | | { |
| 22 | | device_image_interface *fd; /* file descriptor of tape image */ |
| 23 | 19 | |
| 24 | | int motor_on; /* 1-bit reader motor on */ |
| 25 | 20 | |
| 26 | | int rcl; /* 1-bit reader clutch */ |
| 27 | | int rc; /* 2-bit reader counter */ |
| 28 | 21 | |
| 29 | | emu_timer *timer; /* timer to simulate reader timing */ |
| 30 | | } tape_reader_t; |
| 31 | 22 | |
| 32 | | static tape_reader_t tape_reader; |
| 33 | 23 | |
| 34 | 24 | |
| 35 | | /* tape puncher registers */ |
| 36 | | typedef struct tape_puncher_t |
| 37 | | { |
| 38 | | device_image_interface *fd; /* file descriptor of tape image */ |
| 39 | | |
| 40 | | emu_timer *timer; /* timer to generate completion pulses */ |
| 41 | | } tape_puncher_t; |
| 42 | | |
| 43 | | static tape_puncher_t tape_puncher; |
| 44 | | |
| 45 | | |
| 46 | | /* typewriter registers */ |
| 47 | | typedef struct typewriter_t |
| 48 | | { |
| 49 | | device_image_interface *fd; /* file descriptor of output image */ |
| 50 | | |
| 51 | | emu_timer *prt_timer;/* timer to generate completion pulses */ |
| 52 | | } typewriter_t; |
| 53 | | |
| 54 | | static typewriter_t typewriter; |
| 55 | | |
| 56 | | |
| 57 | 25 | /* crt display timer */ |
| 58 | | static emu_timer *dis_timer; |
| 59 | 26 | |
| 60 | 27 | |
| 61 | | enum state_t |
| 62 | | { |
| 63 | | MTS_UNSELECTED, |
| 64 | | MTS_SELECTING, |
| 65 | | MTS_SELECTED, |
| 66 | | MTS_UNSELECTING |
| 67 | | }; |
| 68 | | enum backspace_state_t |
| 69 | | { |
| 70 | | MTBSS_STATE0, |
| 71 | | MTBSS_STATE1, |
| 72 | | MTBSS_STATE2, |
| 73 | | MTBSS_STATE3, |
| 74 | | MTBSS_STATE4, |
| 75 | | MTBSS_STATE5, |
| 76 | | MTBSS_STATE6 |
| 77 | | }; |
| 78 | | enum state_2_t |
| 79 | | { |
| 80 | | MTRDS_STATE0, |
| 81 | | MTRDS_STATE1, |
| 82 | | MTRDS_STATE2, |
| 83 | | MTRDS_STATE3, |
| 84 | | MTRDS_STATE4, |
| 85 | | MTRDS_STATE5, |
| 86 | | MTRDS_STATE6 |
| 87 | | }; |
| 88 | | enum state_3_t |
| 89 | | { |
| 90 | | MTWTS_STATE0, |
| 91 | | MTWTS_STATE1, |
| 92 | | MTWTS_STATE2, |
| 93 | | MTWTS_STATE3 |
| 94 | | }; |
| 95 | 28 | |
| 96 | | enum irg_pos_t |
| 97 | | { |
| 98 | | MTIRGP_START, |
| 99 | | MTIRGP_ENDMINUS1, |
| 100 | | MTIRGP_END |
| 101 | | }; |
| 102 | | /* magnetic tape unit registers */ |
| 103 | | typedef struct magtape_t |
| 104 | | { |
| 105 | | device_image_interface *img; /* image descriptor */ |
| 106 | | |
| 107 | | state_t state; |
| 108 | | |
| 109 | | int command; |
| 110 | | int binary_flag; |
| 111 | | |
| 112 | | union |
| 113 | | { |
| 114 | | backspace_state_t backspace_state; |
| 115 | | struct |
| 116 | | { |
| 117 | | state_2_t state; |
| 118 | | int space_flag; |
| 119 | | } read; |
| 120 | | struct |
| 121 | | { |
| 122 | | state_3_t state; |
| 123 | | int counter; |
| 124 | | } write; |
| 125 | | } u; |
| 126 | | |
| 127 | | int sel_pending; |
| 128 | | int cpy_pending; |
| 129 | | |
| 130 | | irg_pos_t irg_pos; /* position relative to inter-record gap */ |
| 131 | | |
| 132 | | int long_parity; |
| 133 | | |
| 134 | | emu_timer *timer; /* timer to simulate reader timing */ |
| 135 | | } magtape_t; |
| 136 | | |
| 137 | | static magtape_t magtape; |
| 138 | | |
| 139 | 29 | enum |
| 140 | 30 | { |
| 141 | 31 | PF_RWC = 040, |
| r9667 | r9668 | |
| 147 | 37 | |
| 148 | 38 | MACHINE_RESET( tx0 ) |
| 149 | 39 | { |
| 40 | tx0_state *state = machine->driver_data<tx0_state>(); |
| 150 | 41 | /* reset device state */ |
| 151 | | tape_reader.rcl = tape_reader.rc = 0; |
| 42 | state->tape_reader.rcl = state->tape_reader.rc = 0; |
| 152 | 43 | } |
| 153 | 44 | |
| 154 | 45 | |
| 155 | 46 | static void tx0_machine_stop(running_machine &machine) |
| 156 | 47 | { |
| 48 | tx0_state *state = machine.driver_data<tx0_state>(); |
| 157 | 49 | /* the core will take care of freeing the timers, BUT we must set the variables |
| 158 | 50 | to NULL if we don't want to risk confusing the tape image init function */ |
| 159 | | tape_reader.timer = tape_puncher.timer = typewriter.prt_timer = dis_timer = NULL; |
| 51 | state->tape_reader.timer = state->tape_puncher.timer = state->typewriter.prt_timer = state->dis_timer = NULL; |
| 160 | 52 | } |
| 161 | 53 | |
| 162 | 54 | |
| 163 | 55 | MACHINE_START( tx0 ) |
| 164 | 56 | { |
| 165 | | tape_reader.timer = timer_alloc(machine, reader_callback, NULL); |
| 166 | | tape_puncher.timer = timer_alloc(machine, puncher_callback, NULL); |
| 167 | | typewriter.prt_timer = timer_alloc(machine, prt_callback, NULL); |
| 168 | | dis_timer = timer_alloc(machine, dis_callback, NULL); |
| 57 | tx0_state *state = machine->driver_data<tx0_state>(); |
| 58 | state->tape_reader.timer = timer_alloc(machine, reader_callback, NULL); |
| 59 | state->tape_puncher.timer = timer_alloc(machine, puncher_callback, NULL); |
| 60 | state->typewriter.prt_timer = timer_alloc(machine, prt_callback, NULL); |
| 61 | state->dis_timer = timer_alloc(machine, dis_callback, NULL); |
| 169 | 62 | |
| 170 | 63 | machine->add_notifier(MACHINE_NOTIFY_EXIT, tx0_machine_stop); |
| 171 | 64 | } |
| r9667 | r9668 | |
| 205 | 98 | */ |
| 206 | 99 | DEVICE_IMAGE_LOAD( tx0_tape ) |
| 207 | 100 | { |
| 101 | tx0_state *state = image.device().machine->driver_data<tx0_state>(); |
| 208 | 102 | int id = image_index_in_device(image); |
| 209 | 103 | |
| 210 | 104 | switch (id) |
| 211 | 105 | { |
| 212 | 106 | case 0: |
| 213 | 107 | /* reader unit */ |
| 214 | | tape_reader.fd = image; |
| 108 | state->tape_reader.fd = image; |
| 215 | 109 | |
| 216 | 110 | /* start motor */ |
| 217 | | tape_reader.motor_on = 1; |
| 111 | state->tape_reader.motor_on = 1; |
| 218 | 112 | |
| 219 | 113 | /* restart reader IO when necessary */ |
| 220 | 114 | /* note that this function may be called before tx0_init_machine, therefore |
| 221 | | before tape_reader.timer is allocated. It does not matter, as the clutch is never |
| 115 | before state->tape_reader.timer is allocated. It does not matter, as the clutch is never |
| 222 | 116 | down at power-up, but we must not call timer_enable with a NULL parameter! */ |
| 223 | | if (tape_reader.timer) |
| 117 | if (state->tape_reader.timer) |
| 224 | 118 | { |
| 225 | | if (tape_reader.motor_on && tape_reader.rcl) |
| 119 | if (state->tape_reader.motor_on && state->tape_reader.rcl) |
| 226 | 120 | { |
| 227 | 121 | /* delay is approximately 1/400s */ |
| 228 | | timer_adjust_oneshot(tape_reader.timer, ATTOTIME_IN_USEC(2500), 0); |
| 122 | timer_adjust_oneshot(state->tape_reader.timer, ATTOTIME_IN_USEC(2500), 0); |
| 229 | 123 | } |
| 230 | 124 | else |
| 231 | 125 | { |
| 232 | | timer_enable(tape_reader.timer, 0); |
| 126 | timer_enable(state->tape_reader.timer, 0); |
| 233 | 127 | } |
| 234 | 128 | } |
| 235 | 129 | break; |
| 236 | 130 | |
| 237 | 131 | case 1: |
| 238 | 132 | /* punch unit */ |
| 239 | | tape_puncher.fd = image; |
| 133 | state->tape_puncher.fd = image; |
| 240 | 134 | break; |
| 241 | 135 | } |
| 242 | 136 | |
| r9667 | r9668 | |
| 245 | 139 | |
| 246 | 140 | DEVICE_IMAGE_UNLOAD( tx0_tape ) |
| 247 | 141 | { |
| 142 | tx0_state *state = image.device().machine->driver_data<tx0_state>(); |
| 248 | 143 | int id = image_index_in_device(image); |
| 249 | 144 | |
| 250 | 145 | switch (id) |
| 251 | 146 | { |
| 252 | 147 | case 0: |
| 253 | 148 | /* reader unit */ |
| 254 | | tape_reader.fd = NULL; |
| 149 | state->tape_reader.fd = NULL; |
| 255 | 150 | |
| 256 | 151 | /* stop motor */ |
| 257 | | tape_reader.motor_on = 0; |
| 152 | state->tape_reader.motor_on = 0; |
| 258 | 153 | |
| 259 | | if (tape_reader.timer) |
| 260 | | timer_enable(tape_reader.timer, 0); |
| 154 | if (state->tape_reader.timer) |
| 155 | timer_enable(state->tape_reader.timer, 0); |
| 261 | 156 | break; |
| 262 | 157 | |
| 263 | 158 | case 1: |
| 264 | 159 | /* punch unit */ |
| 265 | | tape_puncher.fd = NULL; |
| 160 | state->tape_puncher.fd = NULL; |
| 266 | 161 | break; |
| 267 | 162 | } |
| 268 | 163 | } |
| r9667 | r9668 | |
| 270 | 165 | /* |
| 271 | 166 | Read a byte from perforated tape |
| 272 | 167 | */ |
| 273 | | static int tape_read(UINT8 *reply) |
| 168 | static int tape_read(tx0_state *state, UINT8 *reply) |
| 274 | 169 | { |
| 275 | | if (tape_reader.fd && (tape_reader.fd->fread(reply, 1) == 1)) |
| 170 | if (state->tape_reader.fd && (state->tape_reader.fd->fread(reply, 1) == 1)) |
| 276 | 171 | return 0; /* unit OK */ |
| 277 | 172 | else |
| 278 | 173 | return 1; /* unit not ready */ |
| r9667 | r9668 | |
| 281 | 176 | /* |
| 282 | 177 | Write a byte to perforated tape |
| 283 | 178 | */ |
| 284 | | static void tape_write(UINT8 data) |
| 179 | static void tape_write(tx0_state *state, UINT8 data) |
| 285 | 180 | { |
| 286 | | if (tape_puncher.fd) |
| 287 | | tape_puncher.fd->fwrite(& data, 1); |
| 181 | if (state->tape_puncher.fd) |
| 182 | state->tape_puncher.fd->fwrite(& data, 1); |
| 288 | 183 | } |
| 289 | 184 | |
| 290 | 185 | /* |
| 291 | 186 | common code for tape read commands (R1C, R3C, and read-in mode) |
| 292 | 187 | */ |
| 293 | | static void begin_tape_read(int binary) |
| 188 | static void begin_tape_read(tx0_state *state, int binary) |
| 294 | 189 | { |
| 295 | | tape_reader.rcl = 1; |
| 296 | | tape_reader.rc = (binary) ? 1 : 3; |
| 190 | state->tape_reader.rcl = 1; |
| 191 | state->tape_reader.rc = (binary) ? 1 : 3; |
| 297 | 192 | |
| 298 | 193 | /* set up delay if tape is advancing */ |
| 299 | | if (tape_reader.motor_on && tape_reader.rcl) |
| 194 | if (state->tape_reader.motor_on && state->tape_reader.rcl) |
| 300 | 195 | { |
| 301 | 196 | /* delay is approximately 1/400s */ |
| 302 | | timer_adjust_oneshot(tape_reader.timer, ATTOTIME_IN_USEC(2500), 0); |
| 197 | timer_adjust_oneshot(state->tape_reader.timer, ATTOTIME_IN_USEC(2500), 0); |
| 303 | 198 | } |
| 304 | 199 | else |
| 305 | 200 | { |
| 306 | | timer_enable(tape_reader.timer, 0); |
| 201 | timer_enable(state->tape_reader.timer, 0); |
| 307 | 202 | } |
| 308 | 203 | } |
| 309 | 204 | |
| r9667 | r9668 | |
| 313 | 208 | */ |
| 314 | 209 | static TIMER_CALLBACK(reader_callback) |
| 315 | 210 | { |
| 211 | tx0_state *state = machine->driver_data<tx0_state>(); |
| 316 | 212 | int not_ready; |
| 317 | 213 | UINT8 data; |
| 318 | 214 | int ac; |
| 319 | 215 | |
| 320 | | if (tape_reader.rc) |
| 216 | if (state->tape_reader.rc) |
| 321 | 217 | { |
| 322 | | not_ready = tape_read(& data); |
| 218 | not_ready = tape_read(state, & data); |
| 323 | 219 | if (not_ready) |
| 324 | 220 | { |
| 325 | | tape_reader.motor_on = 0; /* let us stop the motor */ |
| 221 | state->tape_reader.motor_on = 0; /* let us stop the motor */ |
| 326 | 222 | } |
| 327 | 223 | else |
| 328 | 224 | { |
| r9667 | r9668 | |
| 337 | 233 | /* write modified AC */ |
| 338 | 234 | cpu_set_reg(machine->device("maincpu"), TX0_AC, ac); |
| 339 | 235 | |
| 340 | | tape_reader.rc = (tape_reader.rc+1) & 3; |
| 236 | state->tape_reader.rc = (state->tape_reader.rc+1) & 3; |
| 341 | 237 | |
| 342 | | if (tape_reader.rc == 0) |
| 238 | if (state->tape_reader.rc == 0) |
| 343 | 239 | { /* IO complete */ |
| 344 | | tape_reader.rcl = 0; |
| 240 | state->tape_reader.rcl = 0; |
| 345 | 241 | cpu_set_reg(machine->device("maincpu"), TX0_IO_COMPLETE, (UINT64)0); |
| 346 | 242 | } |
| 347 | 243 | } |
| 348 | 244 | } |
| 349 | 245 | } |
| 350 | 246 | |
| 351 | | if (tape_reader.motor_on && tape_reader.rcl) |
| 247 | if (state->tape_reader.motor_on && state->tape_reader.rcl) |
| 352 | 248 | /* delay is approximately 1/400s */ |
| 353 | | timer_adjust_oneshot(tape_reader.timer, ATTOTIME_IN_USEC(2500), 0); |
| 249 | timer_adjust_oneshot(state->tape_reader.timer, ATTOTIME_IN_USEC(2500), 0); |
| 354 | 250 | else |
| 355 | | timer_enable(tape_reader.timer, 0); |
| 251 | timer_enable(state->tape_reader.timer, 0); |
| 356 | 252 | } |
| 357 | 253 | |
| 358 | 254 | /* |
| r9667 | r9668 | |
| 368 | 264 | */ |
| 369 | 265 | void tx0_io_r1l(running_device *device) |
| 370 | 266 | { |
| 371 | | begin_tape_read(0); |
| 267 | tx0_state *state = device->machine->driver_data<tx0_state>(); |
| 268 | begin_tape_read(state, 0); |
| 372 | 269 | } |
| 373 | 270 | |
| 374 | 271 | /* |
| r9667 | r9668 | |
| 376 | 273 | */ |
| 377 | 274 | void tx0_io_r3l(running_device *device) |
| 378 | 275 | { |
| 379 | | begin_tape_read(1); |
| 276 | tx0_state *state = device->machine->driver_data<tx0_state>(); |
| 277 | begin_tape_read(state, 1); |
| 380 | 278 | } |
| 381 | 279 | |
| 382 | 280 | /* |
| r9667 | r9668 | |
| 384 | 282 | */ |
| 385 | 283 | void tx0_io_p6h(running_device *device) |
| 386 | 284 | { |
| 285 | tx0_state *state = device->machine->driver_data<tx0_state>(); |
| 387 | 286 | int ac; |
| 388 | 287 | |
| 389 | 288 | /* read current AC */ |
| 390 | 289 | ac = cpu_get_reg(device, TX0_AC); |
| 391 | 290 | /* shuffle and punch 6-bit word */ |
| 392 | | tape_write(((ac & 0100000) >> 15) | ((ac & 0010000) >> 11) | ((ac & 0001000) >> 7) | ((ac & 0000100) >> 3) | ((ac & 0000010) << 1) | ((ac & 0000001) << 5)); |
| 291 | tape_write(state, ((ac & 0100000) >> 15) | ((ac & 0010000) >> 11) | ((ac & 0001000) >> 7) | ((ac & 0000100) >> 3) | ((ac & 0000010) << 1) | ((ac & 0000001) << 5)); |
| 393 | 292 | |
| 394 | | timer_adjust_oneshot(tape_puncher.timer, ATTOTIME_IN_USEC(15800), 0); |
| 293 | timer_adjust_oneshot(state->tape_puncher.timer, ATTOTIME_IN_USEC(15800), 0); |
| 395 | 294 | } |
| 396 | 295 | |
| 397 | 296 | /* |
| r9667 | r9668 | |
| 399 | 298 | */ |
| 400 | 299 | void tx0_io_p7h(running_device *device) |
| 401 | 300 | { |
| 301 | tx0_state *state = device->machine->driver_data<tx0_state>(); |
| 402 | 302 | int ac; |
| 403 | 303 | |
| 404 | 304 | /* read current AC */ |
| 405 | 305 | ac = cpu_get_reg(device, TX0_AC); |
| 406 | 306 | /* shuffle and punch 6-bit word */ |
| 407 | | tape_write(((ac & 0100000) >> 15) | ((ac & 0010000) >> 11) | ((ac & 0001000) >> 7) | ((ac & 0000100) >> 3) | ((ac & 0000010) << 1) | ((ac & 0000001) << 5) | 0100); |
| 307 | tape_write(state, ((ac & 0100000) >> 15) | ((ac & 0010000) >> 11) | ((ac & 0001000) >> 7) | ((ac & 0000100) >> 3) | ((ac & 0000010) << 1) | ((ac & 0000001) << 5) | 0100); |
| 408 | 308 | |
| 409 | | timer_adjust_oneshot(tape_puncher.timer, ATTOTIME_IN_USEC(15800), 0); |
| 309 | timer_adjust_oneshot(state->tape_puncher.timer, ATTOTIME_IN_USEC(15800), 0); |
| 410 | 310 | } |
| 411 | 311 | |
| 412 | 312 | |
| r9667 | r9668 | |
| 422 | 322 | */ |
| 423 | 323 | DEVICE_IMAGE_LOAD(tx0_typewriter) |
| 424 | 324 | { |
| 325 | tx0_state *state = image.device().machine->driver_data<tx0_state>(); |
| 425 | 326 | /* open file */ |
| 426 | | typewriter.fd = ℑ |
| 327 | state->typewriter.fd = ℑ |
| 427 | 328 | |
| 428 | 329 | return IMAGE_INIT_PASS; |
| 429 | 330 | } |
| 430 | 331 | |
| 431 | 332 | DEVICE_IMAGE_UNLOAD(tx0_typewriter) |
| 432 | 333 | { |
| 433 | | typewriter.fd = NULL; |
| 334 | tx0_state *state = image.device().machine->driver_data<tx0_state>(); |
| 335 | state->typewriter.fd = NULL; |
| 434 | 336 | } |
| 435 | 337 | |
| 436 | 338 | /* |
| r9667 | r9668 | |
| 438 | 340 | */ |
| 439 | 341 | static void typewriter_out(running_machine *machine, UINT8 data) |
| 440 | 342 | { |
| 343 | tx0_state *state = machine->driver_data<tx0_state>(); |
| 441 | 344 | tx0_typewriter_drawchar(machine, data); |
| 442 | | if (typewriter.fd) |
| 443 | | typewriter.fd->fwrite(& data, 1); |
| 345 | if (state->typewriter.fd) |
| 346 | state->typewriter.fd->fwrite(& data, 1); |
| 444 | 347 | } |
| 445 | 348 | |
| 446 | 349 | /* |
| r9667 | r9668 | |
| 456 | 359 | */ |
| 457 | 360 | void tx0_io_prt(running_device *device) |
| 458 | 361 | { |
| 362 | tx0_state *state = device->machine->driver_data<tx0_state>(); |
| 459 | 363 | int ac; |
| 460 | 364 | int ch; |
| 461 | 365 | |
| r9667 | r9668 | |
| 465 | 369 | ch = ((ac & 0100000) >> 15) | ((ac & 0010000) >> 11) | ((ac & 0001000) >> 7) | ((ac & 0000100) >> 3) | ((ac & 0000010) << 1) | ((ac & 0000001) << 5); |
| 466 | 370 | typewriter_out(device->machine, ch); |
| 467 | 371 | |
| 468 | | timer_adjust_oneshot(typewriter.prt_timer, ATTOTIME_IN_MSEC(100), 0); |
| 372 | timer_adjust_oneshot(state->typewriter.prt_timer, ATTOTIME_IN_MSEC(100), 0); |
| 469 | 373 | } |
| 470 | 374 | |
| 471 | 375 | |
| r9667 | r9668 | |
| 482 | 386 | */ |
| 483 | 387 | void tx0_io_dis(running_device *device) |
| 484 | 388 | { |
| 389 | tx0_state *state = device->machine->driver_data<tx0_state>(); |
| 485 | 390 | int ac; |
| 486 | 391 | int x; |
| 487 | 392 | int y; |
| r9667 | r9668 | |
| 491 | 396 | y = ac & 0777; |
| 492 | 397 | tx0_plot(x, y); |
| 493 | 398 | |
| 494 | | timer_adjust_oneshot(dis_timer, ATTOTIME_IN_USEC(50), 0); |
| 399 | timer_adjust_oneshot(state->dis_timer, ATTOTIME_IN_USEC(50), 0); |
| 495 | 400 | } |
| 496 | 401 | |
| 497 | 402 | |
| r9667 | r9668 | |
| 505 | 410 | |
| 506 | 411 | */ |
| 507 | 412 | |
| 508 | | static void schedule_select(void) |
| 413 | static void schedule_select(tx0_state *state) |
| 509 | 414 | { |
| 510 | 415 | attotime delay = attotime_zero; |
| 511 | 416 | |
| 512 | | switch (magtape.command) |
| 417 | switch (state->magtape.command) |
| 513 | 418 | { |
| 514 | 419 | case 0: /* backspace */ |
| 515 | 420 | delay = ATTOTIME_IN_USEC(4600); |
| r9667 | r9668 | |
| 524 | 429 | delay = ATTOTIME_IN_USEC(4600); |
| 525 | 430 | break; |
| 526 | 431 | } |
| 527 | | timer_adjust_oneshot(magtape.timer, delay, 0); |
| 432 | timer_adjust_oneshot(state->magtape.timer, delay, 0); |
| 528 | 433 | } |
| 529 | 434 | |
| 530 | | static void schedule_unselect(void) |
| 435 | static void schedule_unselect(tx0_state *state) |
| 531 | 436 | { |
| 532 | 437 | attotime delay = attotime_zero; |
| 533 | 438 | |
| 534 | | switch (magtape.command) |
| 439 | switch (state->magtape.command) |
| 535 | 440 | { |
| 536 | 441 | case 0: /* backspace */ |
| 537 | 442 | delay = ATTOTIME_IN_USEC(5750); |
| r9667 | r9668 | |
| 546 | 451 | delay = ATTOTIME_IN_USEC(5750); |
| 547 | 452 | break; |
| 548 | 453 | } |
| 549 | | timer_adjust_oneshot(magtape.timer, delay, 0); |
| 454 | timer_adjust_oneshot(state->magtape.timer, delay, 0); |
| 550 | 455 | } |
| 551 | 456 | |
| 552 | 457 | DEVICE_START( tx0_magtape ) |
| 553 | 458 | { |
| 554 | | magtape.img = dynamic_cast<device_image_interface *>(device); |
| 459 | tx0_state *state = device->machine->driver_data<tx0_state>(); |
| 460 | state->magtape.img = dynamic_cast<device_image_interface *>(device); |
| 555 | 461 | } |
| 556 | 462 | |
| 557 | 463 | /* |
| r9667 | r9668 | |
| 559 | 465 | */ |
| 560 | 466 | DEVICE_IMAGE_LOAD( tx0_magtape ) |
| 561 | 467 | { |
| 562 | | magtape.img = ℑ |
| 468 | tx0_state *state = image.device().machine->driver_data<tx0_state>(); |
| 469 | state->magtape.img = ℑ |
| 563 | 470 | |
| 564 | | magtape.irg_pos = MTIRGP_END; |
| 471 | state->magtape.irg_pos = MTIRGP_END; |
| 565 | 472 | |
| 566 | 473 | /* restart IO when necessary */ |
| 567 | 474 | /* note that this function may be called before tx0_init_machine, therefore |
| 568 | | before magtape.timer is allocated. We must not call timer_enable with a |
| 475 | before state->magtape.timer is allocated. We must not call timer_enable with a |
| 569 | 476 | NULL parameter! */ |
| 570 | | if (magtape.timer) |
| 477 | if (state->magtape.timer) |
| 571 | 478 | { |
| 572 | | if (magtape.state == MTS_SELECTING) |
| 573 | | schedule_select(); |
| 479 | if (state->magtape.state == MTS_SELECTING) |
| 480 | schedule_select(state); |
| 574 | 481 | } |
| 575 | 482 | |
| 576 | 483 | return IMAGE_INIT_PASS; |
| r9667 | r9668 | |
| 578 | 485 | |
| 579 | 486 | DEVICE_IMAGE_UNLOAD( tx0_magtape ) |
| 580 | 487 | { |
| 581 | | magtape.img = NULL; |
| 488 | tx0_state *state = image.device().machine->driver_data<tx0_state>(); |
| 489 | state->magtape.img = NULL; |
| 582 | 490 | |
| 583 | | if (magtape.timer) |
| 491 | if (state->magtape.timer) |
| 584 | 492 | { |
| 585 | | if (magtape.state == MTS_SELECTING) |
| 493 | if (state->magtape.state == MTS_SELECTING) |
| 586 | 494 | /* I/O has not actually started, we can cancel the selection */ |
| 587 | | timer_enable(tape_reader.timer, 0); |
| 588 | | if ((magtape.state == MTS_SELECTED) || ((magtape.state == MTS_SELECTING) && (magtape.command == 2))) |
| 495 | timer_enable(state->tape_reader.timer, 0); |
| 496 | if ((state->magtape.state == MTS_SELECTED) || ((state->magtape.state == MTS_SELECTING) && (state->magtape.command == 2))) |
| 589 | 497 | { /* unit has become unavailable */ |
| 590 | | magtape.state = MTS_UNSELECTING; |
| 498 | state->magtape.state = MTS_UNSELECTING; |
| 591 | 499 | cpu_set_reg(image.device().machine->device("maincpu"), TX0_PF, cpu_get_reg(image.device().machine->device("maincpu"), TX0_PF) | PF_RWC); |
| 592 | | schedule_unselect(); |
| 500 | schedule_unselect(state); |
| 593 | 501 | } |
| 594 | 502 | } |
| 595 | 503 | } |
| 596 | 504 | |
| 597 | 505 | static void magtape_callback(running_device *device) |
| 598 | 506 | { |
| 507 | tx0_state *state = device->machine->driver_data<tx0_state>(); |
| 599 | 508 | UINT8 buf = 0; |
| 600 | 509 | int lr; |
| 601 | 510 | |
| 602 | | switch (magtape.state) |
| 511 | switch (state->magtape.state) |
| 603 | 512 | { |
| 604 | 513 | case MTS_UNSELECTING: |
| 605 | | magtape.state = MTS_UNSELECTED; |
| 514 | state->magtape.state = MTS_UNSELECTED; |
| 606 | 515 | |
| 607 | 516 | case MTS_UNSELECTED: |
| 608 | | if (magtape.sel_pending) |
| 517 | if (state->magtape.sel_pending) |
| 609 | 518 | { |
| 610 | 519 | int mar; |
| 611 | 520 | |
| r9667 | r9668 | |
| 618 | 527 | } |
| 619 | 528 | else |
| 620 | 529 | { |
| 621 | | magtape.state = MTS_SELECTING; |
| 530 | state->magtape.state = MTS_SELECTING; |
| 622 | 531 | |
| 623 | | magtape.command = (mar & 014 >> 2); |
| 532 | state->magtape.command = (mar & 014 >> 2); |
| 624 | 533 | |
| 625 | | magtape.binary_flag = (mar & 020 >> 4); |
| 534 | state->magtape.binary_flag = (mar & 020 >> 4); |
| 626 | 535 | |
| 627 | | if (magtape.img) |
| 628 | | schedule_select(); |
| 536 | if (state->magtape.img) |
| 537 | schedule_select(state); |
| 629 | 538 | } |
| 630 | 539 | |
| 631 | | magtape.sel_pending = FALSE; |
| 540 | state->magtape.sel_pending = FALSE; |
| 632 | 541 | cpu_set_reg(device, TX0_IO_COMPLETE, (UINT64)0); |
| 633 | 542 | } |
| 634 | 543 | break; |
| 635 | 544 | |
| 636 | 545 | case MTS_SELECTING: |
| 637 | | magtape.state = MTS_SELECTED; |
| 638 | | switch (magtape.command) |
| 546 | state->magtape.state = MTS_SELECTED; |
| 547 | switch (state->magtape.command) |
| 639 | 548 | { |
| 640 | 549 | case 0: /* backspace */ |
| 641 | | magtape.long_parity = 0177; |
| 642 | | magtape.u.backspace_state = MTBSS_STATE0; |
| 550 | state->magtape.long_parity = 0177; |
| 551 | state->magtape.u.backspace_state = MTBSS_STATE0; |
| 643 | 552 | break; |
| 644 | 553 | case 1: /* read */ |
| 645 | | magtape.long_parity = 0177; |
| 646 | | magtape.u.read.state = MTRDS_STATE0; |
| 554 | state->magtape.long_parity = 0177; |
| 555 | state->magtape.u.read.state = MTRDS_STATE0; |
| 647 | 556 | break; |
| 648 | 557 | case 2: /* rewind */ |
| 649 | 558 | break; |
| 650 | 559 | case 3: /* write */ |
| 651 | | magtape.long_parity = 0177; |
| 652 | | magtape.u.write.state = MTWTS_STATE0; |
| 653 | | switch (magtape.irg_pos) |
| 560 | state->magtape.long_parity = 0177; |
| 561 | state->magtape.u.write.state = MTWTS_STATE0; |
| 562 | switch (state->magtape.irg_pos) |
| 654 | 563 | { |
| 655 | 564 | case MTIRGP_START: |
| 656 | | magtape.u.write.counter = 150; |
| 565 | state->magtape.u.write.counter = 150; |
| 657 | 566 | break; |
| 658 | 567 | case MTIRGP_ENDMINUS1: |
| 659 | | magtape.u.write.counter = 1; |
| 568 | state->magtape.u.write.counter = 1; |
| 660 | 569 | break; |
| 661 | 570 | case MTIRGP_END: |
| 662 | | magtape.u.write.counter = 0; |
| 571 | state->magtape.u.write.counter = 0; |
| 663 | 572 | break; |
| 664 | 573 | } |
| 665 | 574 | break; |
| 666 | 575 | } |
| 667 | 576 | |
| 668 | 577 | case MTS_SELECTED: |
| 669 | | switch (magtape.command) |
| 578 | switch (state->magtape.command) |
| 670 | 579 | { |
| 671 | 580 | case 0: /* backspace */ |
| 672 | | if (magtape.img->ftell() == 0) |
| 581 | if (state->magtape.img->ftell() == 0) |
| 673 | 582 | { /* tape at ldp */ |
| 674 | | magtape.state = MTS_UNSELECTING; |
| 583 | state->magtape.state = MTS_UNSELECTING; |
| 675 | 584 | cpu_set_reg(device, TX0_PF, cpu_get_reg(device, TX0_PF) | PF_RWC); |
| 676 | | schedule_unselect(); |
| 585 | schedule_unselect(state); |
| 677 | 586 | } |
| 678 | | else if (magtape.img->fseek( -1, SEEK_CUR)) |
| 587 | else if (state->magtape.img->fseek( -1, SEEK_CUR)) |
| 679 | 588 | { /* eject tape */ |
| 680 | | magtape.img->unload(); |
| 589 | state->magtape.img->unload(); |
| 681 | 590 | } |
| 682 | | else if (magtape.img->fread(&buf, 1) != 1) |
| 591 | else if (state->magtape.img->fread(&buf, 1) != 1) |
| 683 | 592 | { /* eject tape */ |
| 684 | | magtape.img->unload(); |
| 593 | state->magtape.img->unload(); |
| 685 | 594 | } |
| 686 | | else if (magtape.img->fseek( -1, SEEK_CUR)) |
| 595 | else if (state->magtape.img->fseek( -1, SEEK_CUR)) |
| 687 | 596 | { /* eject tape */ |
| 688 | | magtape.img->unload(); |
| 597 | state->magtape.img->unload(); |
| 689 | 598 | } |
| 690 | 599 | else |
| 691 | 600 | { |
| 692 | 601 | buf &= 0x7f; /* 7-bit tape, ignore 8th bit */ |
| 693 | | magtape.long_parity ^= buf; |
| 694 | | switch (magtape.u.backspace_state) |
| 602 | state->magtape.long_parity ^= buf; |
| 603 | switch (state->magtape.u.backspace_state) |
| 695 | 604 | { |
| 696 | 605 | case MTBSS_STATE0: |
| 697 | 606 | /* STATE0 -> initial interrecord gap, longitudinal parity; |
| 698 | 607 | if longitudinal parity was all 0s, gap between longitudinal |
| 699 | 608 | parity and data, first byte of data */ |
| 700 | 609 | if (buf != 0) |
| 701 | | magtape.u.backspace_state = MTBSS_STATE1; |
| 610 | state->magtape.u.backspace_state = MTBSS_STATE1; |
| 702 | 611 | break; |
| 703 | 612 | case MTBSS_STATE1: |
| 704 | 613 | /* STATE1 -> first byte of gap between longitudinal parity and |
| 705 | 614 | data, second byte of data */ |
| 706 | 615 | if (buf == 0) |
| 707 | | magtape.u.backspace_state = MTBSS_STATE2; |
| 616 | state->magtape.u.backspace_state = MTBSS_STATE2; |
| 708 | 617 | else |
| 709 | | magtape.u.backspace_state = MTBSS_STATE5; |
| 618 | state->magtape.u.backspace_state = MTBSS_STATE5; |
| 710 | 619 | break; |
| 711 | 620 | case MTBSS_STATE2: |
| 712 | 621 | /* STATE2 -> second byte of gap between longitudinal parity and |
| 713 | 622 | data */ |
| 714 | 623 | if (buf == 0) |
| 715 | | magtape.u.backspace_state = MTBSS_STATE3; |
| 624 | state->magtape.u.backspace_state = MTBSS_STATE3; |
| 716 | 625 | else |
| 717 | 626 | { |
| 718 | 627 | logerror("tape seems to be corrupt\n"); |
| 719 | 628 | /* eject tape */ |
| 720 | | magtape.img->unload(); |
| 629 | state->magtape.img->unload(); |
| 721 | 630 | } |
| 722 | 631 | break; |
| 723 | 632 | case MTBSS_STATE3: |
| 724 | 633 | /* STATE3 -> third byte of gap between longitudinal parity and |
| 725 | 634 | data */ |
| 726 | 635 | if (buf == 0) |
| 727 | | magtape.u.backspace_state = MTBSS_STATE4; |
| 636 | state->magtape.u.backspace_state = MTBSS_STATE4; |
| 728 | 637 | else |
| 729 | 638 | { |
| 730 | 639 | logerror("tape seems to be corrupt\n"); |
| 731 | 640 | /* eject tape */ |
| 732 | | magtape.img->unload(); |
| 641 | state->magtape.img->unload(); |
| 733 | 642 | } |
| 734 | 643 | break; |
| 735 | 644 | case MTBSS_STATE4: |
| r9667 | r9668 | |
| 737 | 646 | interrecord gap after data */ |
| 738 | 647 | if (buf == 0) |
| 739 | 648 | { |
| 740 | | if (magtape.long_parity) |
| 649 | if (state->magtape.long_parity) |
| 741 | 650 | logerror("invalid longitudinal parity\n"); |
| 742 | 651 | /* set EOR and unselect... */ |
| 743 | | magtape.state = MTS_UNSELECTING; |
| 652 | state->magtape.state = MTS_UNSELECTING; |
| 744 | 653 | cpu_set_reg(device, TX0_PF, cpu_get_reg(device, TX0_PF) | PF_EOR); |
| 745 | | schedule_unselect(); |
| 746 | | magtape.irg_pos = MTIRGP_ENDMINUS1; |
| 654 | schedule_unselect(state); |
| 655 | state->magtape.irg_pos = MTIRGP_ENDMINUS1; |
| 747 | 656 | } |
| 748 | 657 | else |
| 749 | | magtape.u.backspace_state = MTBSS_STATE5; |
| 658 | state->magtape.u.backspace_state = MTBSS_STATE5; |
| 750 | 659 | break; |
| 751 | 660 | case MTBSS_STATE5: |
| 752 | 661 | /* STATE5 -> second byte of data word */ |
| r9667 | r9668 | |
| 754 | 663 | { |
| 755 | 664 | logerror("tape seems to be corrupt\n"); |
| 756 | 665 | /* eject tape */ |
| 757 | | magtape.img->unload(); |
| 666 | state->magtape.img->unload(); |
| 758 | 667 | } |
| 759 | 668 | else |
| 760 | | magtape.u.backspace_state = MTBSS_STATE6; |
| 669 | state->magtape.u.backspace_state = MTBSS_STATE6; |
| 761 | 670 | break; |
| 762 | 671 | case MTBSS_STATE6: |
| 763 | 672 | /* STATE6 -> third byte of data word */ |
| r9667 | r9668 | |
| 765 | 674 | { |
| 766 | 675 | logerror("tape seems to be corrupt\n"); |
| 767 | 676 | /* eject tape */ |
| 768 | | magtape.img->unload(); |
| 677 | state->magtape.img->unload(); |
| 769 | 678 | } |
| 770 | 679 | else |
| 771 | | magtape.u.backspace_state = MTBSS_STATE6; |
| 680 | state->magtape.u.backspace_state = MTBSS_STATE6; |
| 772 | 681 | break; |
| 773 | 682 | } |
| 774 | | if (magtape.state != MTS_UNSELECTING) |
| 775 | | timer_adjust_oneshot(magtape.timer, ATTOTIME_IN_USEC(66), 0); |
| 683 | if (state->magtape.state != MTS_UNSELECTING) |
| 684 | timer_adjust_oneshot(state->magtape.timer, ATTOTIME_IN_USEC(66), 0); |
| 776 | 685 | } |
| 777 | 686 | break; |
| 778 | 687 | |
| 779 | 688 | case 1: /* read */ |
| 780 | | if (magtape.img->fread(&buf, 1) != 1) |
| 689 | if (state->magtape.img->fread(&buf, 1) != 1) |
| 781 | 690 | { /* I/O error or EOF? */ |
| 782 | 691 | /* The MAME fileio layer makes it very hard to make the |
| 783 | 692 | difference... MAME seems to assume that I/O errors never |
| 784 | 693 | happen, whereas it is really easy to cause one by |
| 785 | 694 | deconnecting an external drive the image is located on!!! */ |
| 786 | 695 | UINT64 offs; |
| 787 | | offs = magtape.img->ftell(); |
| 788 | | if (magtape.img->fseek( 0, SEEK_END) || (offs != magtape.img->ftell())) |
| 696 | offs = state->magtape.img->ftell(); |
| 697 | if (state->magtape.img->fseek( 0, SEEK_END) || (offs != state->magtape.img->ftell())) |
| 789 | 698 | { /* I/O error */ |
| 790 | 699 | /* eject tape */ |
| 791 | | magtape.img->unload(); |
| 700 | state->magtape.img->unload(); |
| 792 | 701 | } |
| 793 | 702 | else |
| 794 | 703 | { /* end of tape -> ??? */ |
| 795 | 704 | /* maybe we run past end of tape, so that tape is ejected from |
| 796 | 705 | upper reel and unit becomes unavailable??? */ |
| 797 | | /*magtape.img->unload();*/ |
| 706 | /*state->magtape.img->unload();*/ |
| 798 | 707 | /* Or do we stop at EOT mark??? */ |
| 799 | | magtape.state = MTS_UNSELECTING; |
| 708 | state->magtape.state = MTS_UNSELECTING; |
| 800 | 709 | cpu_set_reg(device, TX0_PF, cpu_get_reg(device, TX0_PF) | PF_EOT); |
| 801 | | schedule_unselect(); |
| 710 | schedule_unselect(state); |
| 802 | 711 | } |
| 803 | 712 | } |
| 804 | 713 | else |
| 805 | 714 | { |
| 806 | 715 | buf &= 0x7f; /* 7-bit tape, ignore 8th bit */ |
| 807 | | magtape.long_parity ^= buf; |
| 808 | | switch (magtape.u.read.state) |
| 716 | state->magtape.long_parity ^= buf; |
| 717 | switch (state->magtape.u.read.state) |
| 809 | 718 | { |
| 810 | 719 | case MTRDS_STATE0: |
| 811 | 720 | /* STATE0 -> interrecord blank or first byte of data */ |
| 812 | 721 | if (buf != 0) |
| 813 | 722 | { |
| 814 | | if (magtape.cpy_pending) |
| 723 | if (state->magtape.cpy_pending) |
| 815 | 724 | { /* read command */ |
| 816 | | magtape.u.read.space_flag = FALSE; |
| 725 | state->magtape.u.read.space_flag = FALSE; |
| 817 | 726 | cpu_set_reg(device, TX0_IO_COMPLETE, (UINT64)0); |
| 818 | 727 | cpu_set_reg(device, TX0_LR, ((cpu_get_reg(device, TX0_LR) >> 1) & 0333333) |
| 819 | 728 | | ((buf & 040) << 12) | ((buf & 020) << 10) | ((buf & 010) << 8) | ((buf & 004) << 6) | ((buf & 002) << 4) | ((buf & 001) << 2)); |
| 820 | 729 | /* check parity */ |
| 821 | | if (! (((buf ^ (buf >> 1) ^ (buf >> 2) ^ (buf >> 3) ^ (buf >> 4) ^ (buf >> 5) ^ (buf >> 6) ^ (buf >> 7)) & 1) ^ magtape.binary_flag)) |
| 730 | if (! (((buf ^ (buf >> 1) ^ (buf >> 2) ^ (buf >> 3) ^ (buf >> 4) ^ (buf >> 5) ^ (buf >> 6) ^ (buf >> 7)) & 1) ^ state->magtape.binary_flag)) |
| 822 | 731 | cpu_set_reg(device, TX0_PF, cpu_get_reg(device, TX0_PF) | PF_PC); |
| 823 | 732 | } |
| 824 | 733 | else |
| 825 | 734 | { /* space command */ |
| 826 | | magtape.u.read.space_flag = TRUE; |
| 735 | state->magtape.u.read.space_flag = TRUE; |
| 827 | 736 | } |
| 828 | | magtape.u.read.state = MTRDS_STATE1; |
| 737 | state->magtape.u.read.state = MTRDS_STATE1; |
| 829 | 738 | } |
| 830 | 739 | break; |
| 831 | 740 | case MTRDS_STATE1: |
| r9667 | r9668 | |
| 834 | 743 | { |
| 835 | 744 | logerror("tape seems to be corrupt\n"); |
| 836 | 745 | /* eject tape */ |
| 837 | | magtape.img->unload(); |
| 746 | state->magtape.img->unload(); |
| 838 | 747 | } |
| 839 | | if (!magtape.u.read.space_flag) |
| 748 | if (!state->magtape.u.read.space_flag) |
| 840 | 749 | { |
| 841 | 750 | cpu_set_reg(device, TX0_LR, ((cpu_get_reg(device, TX0_LR) >> 1) & 0333333) |
| 842 | 751 | | ((buf & 040) << 12) | ((buf & 020) << 10) | ((buf & 010) << 8) | ((buf & 004) << 6) | ((buf & 002) << 4) | ((buf & 001) << 2)); |
| 843 | 752 | /* check parity */ |
| 844 | | if (! (((buf ^ (buf >> 1) ^ (buf >> 2) ^ (buf >> 3) ^ (buf >> 4) ^ (buf >> 5) ^ (buf >> 6) ^ (buf >> 7)) & 1) ^ magtape.binary_flag)) |
| 753 | if (! (((buf ^ (buf >> 1) ^ (buf >> 2) ^ (buf >> 3) ^ (buf >> 4) ^ (buf >> 5) ^ (buf >> 6) ^ (buf >> 7)) & 1) ^ state->magtape.binary_flag)) |
| 845 | 754 | cpu_set_reg(device, TX0_PF, cpu_get_reg(device, TX0_PF) | PF_PC); |
| 846 | 755 | } |
| 847 | | magtape.u.read.state = MTRDS_STATE2; |
| 756 | state->magtape.u.read.state = MTRDS_STATE2; |
| 848 | 757 | break; |
| 849 | 758 | case MTRDS_STATE2: |
| 850 | 759 | /* STATE2 -> third byte of data word */ |
| r9667 | r9668 | |
| 852 | 761 | { |
| 853 | 762 | logerror("tape seems to be corrupt\n"); |
| 854 | 763 | /* eject tape */ |
| 855 | | magtape.img->unload(); |
| 764 | state->magtape.img->unload(); |
| 856 | 765 | } |
| 857 | | if (!magtape.u.read.space_flag) |
| 766 | if (!state->magtape.u.read.space_flag) |
| 858 | 767 | { |
| 859 | 768 | cpu_set_reg(device, TX0_LR, ((cpu_get_reg(device, TX0_LR) >> 1) & 0333333) |
| 860 | 769 | | ((buf & 040) << 12) | ((buf & 020) << 10) | ((buf & 010) << 8) | ((buf & 004) << 6) | ((buf & 002) << 4) | ((buf & 001) << 2)); |
| 861 | 770 | /* check parity */ |
| 862 | | if (! (((buf ^ (buf >> 1) ^ (buf >> 2) ^ (buf >> 3) ^ (buf >> 4) ^ (buf >> 5) ^ (buf >> 6) ^ (buf >> 7)) & 1) ^ magtape.binary_flag)) |
| 771 | if (! (((buf ^ (buf >> 1) ^ (buf >> 2) ^ (buf >> 3) ^ (buf >> 4) ^ (buf >> 5) ^ (buf >> 6) ^ (buf >> 7)) & 1) ^ state->magtape.binary_flag)) |
| 863 | 772 | cpu_set_reg(device, TX0_PF, cpu_get_reg(device, TX0_PF) | PF_PC); |
| 864 | 773 | /* synchronize with cpy instruction */ |
| 865 | | if (magtape.cpy_pending) |
| 774 | if (state->magtape.cpy_pending) |
| 866 | 775 | cpu_set_reg(device, TX0_IO_COMPLETE, (UINT64)0); |
| 867 | 776 | else |
| 868 | 777 | cpu_set_reg(device, TX0_PF, cpu_get_reg(device, TX0_PF) | PF_RWC); |
| 869 | 778 | } |
| 870 | | magtape.u.read.state = MTRDS_STATE3; |
| 779 | state->magtape.u.read.state = MTRDS_STATE3; |
| 871 | 780 | break; |
| 872 | 781 | case MTRDS_STATE3: |
| 873 | 782 | /* STATE3 -> first byte of new word of data, or first byte |
| 874 | 783 | of gap between data and longitudinal parity */ |
| 875 | 784 | if (buf != 0) |
| 876 | 785 | { |
| 877 | | magtape.u.read.state = MTRDS_STATE1; |
| 878 | | if (!magtape.u.read.space_flag) |
| 786 | state->magtape.u.read.state = MTRDS_STATE1; |
| 787 | if (!state->magtape.u.read.space_flag) |
| 879 | 788 | { |
| 880 | 789 | cpu_set_reg(device, TX0_LR, ((cpu_get_reg(device, TX0_LR) >> 1) & 0333333) |
| 881 | 790 | | ((buf & 040) << 12) | ((buf & 020) << 10) | ((buf & 010) << 8) | ((buf & 004) << 6) | ((buf & 002) << 4) | ((buf & 001) << 2)); |
| 882 | 791 | /* check parity */ |
| 883 | | if (! (((buf ^ (buf >> 1) ^ (buf >> 2) ^ (buf >> 3) ^ (buf >> 4) ^ (buf >> 5) ^ (buf >> 6) ^ (buf >> 7)) & 1) ^ magtape.binary_flag)) |
| 792 | if (! (((buf ^ (buf >> 1) ^ (buf >> 2) ^ (buf >> 3) ^ (buf >> 4) ^ (buf >> 5) ^ (buf >> 6) ^ (buf >> 7)) & 1) ^ state->magtape.binary_flag)) |
| 884 | 793 | cpu_set_reg(device, TX0_PF, cpu_get_reg(device, TX0_PF) | PF_PC); |
| 885 | 794 | } |
| 886 | 795 | } |
| 887 | 796 | else |
| 888 | | magtape.u.read.state = MTRDS_STATE4; |
| 797 | state->magtape.u.read.state = MTRDS_STATE4; |
| 889 | 798 | break; |
| 890 | 799 | case MTRDS_STATE4: |
| 891 | 800 | /* STATE4 -> second byte of gap between data and |
| r9667 | r9668 | |
| 894 | 803 | { |
| 895 | 804 | logerror("tape seems to be corrupt\n"); |
| 896 | 805 | /* eject tape */ |
| 897 | | magtape.img->unload(); |
| 806 | state->magtape.img->unload(); |
| 898 | 807 | } |
| 899 | 808 | else |
| 900 | | magtape.u.read.state = MTRDS_STATE5; |
| 809 | state->magtape.u.read.state = MTRDS_STATE5; |
| 901 | 810 | break; |
| 902 | 811 | |
| 903 | 812 | case MTRDS_STATE5: |
| r9667 | r9668 | |
| 907 | 816 | { |
| 908 | 817 | logerror("tape seems to be corrupt\n"); |
| 909 | 818 | /* eject tape */ |
| 910 | | magtape.img->unload(); |
| 819 | state->magtape.img->unload(); |
| 911 | 820 | } |
| 912 | 821 | else |
| 913 | | magtape.u.read.state = MTRDS_STATE6; |
| 822 | state->magtape.u.read.state = MTRDS_STATE6; |
| 914 | 823 | break; |
| 915 | 824 | |
| 916 | 825 | case MTRDS_STATE6: |
| 917 | 826 | /* STATE6 -> longitudinal parity */ |
| 918 | 827 | /* check parity */ |
| 919 | | if (magtape.long_parity) |
| 828 | if (state->magtape.long_parity) |
| 920 | 829 | { |
| 921 | 830 | logerror("invalid longitudinal parity\n"); |
| 922 | | /* no idea if the original tx-0 magtape controller |
| 831 | /* no idea if the original tx-0 state->magtape controller |
| 923 | 832 | checks parity, but can't harm if we do */ |
| 924 | 833 | cpu_set_reg(device, TX0_PF, cpu_get_reg(device, TX0_PF) | PF_PC); |
| 925 | 834 | } |
| 926 | 835 | /* set EOR and unselect... */ |
| 927 | | magtape.state = MTS_UNSELECTING; |
| 836 | state->magtape.state = MTS_UNSELECTING; |
| 928 | 837 | cpu_set_reg(device, TX0_PF, cpu_get_reg(device, TX0_PF) | PF_EOR); |
| 929 | | schedule_unselect(); |
| 930 | | magtape.irg_pos = MTIRGP_START; |
| 838 | schedule_unselect(state); |
| 839 | state->magtape.irg_pos = MTIRGP_START; |
| 931 | 840 | break; |
| 932 | 841 | } |
| 933 | | if (magtape.state != MTS_UNSELECTING) |
| 934 | | timer_adjust_oneshot(magtape.timer, ATTOTIME_IN_USEC(66), 0); |
| 842 | if (state->magtape.state != MTS_UNSELECTING) |
| 843 | timer_adjust_oneshot(state->magtape.timer, ATTOTIME_IN_USEC(66), 0); |
| 935 | 844 | } |
| 936 | 845 | break; |
| 937 | 846 | |
| 938 | 847 | case 2: /* rewind */ |
| 939 | | magtape.state = MTS_UNSELECTING; |
| 848 | state->magtape.state = MTS_UNSELECTING; |
| 940 | 849 | /* we rewind at 10*read speed (I don't know the real value) */ |
| 941 | | timer_adjust_oneshot(magtape.timer, attotime_mul(ATTOTIME_IN_NSEC(6600), magtape.img->ftell()), 0); |
| 942 | | //schedule_unselect(); |
| 943 | | magtape.img->fseek( 0, SEEK_END); |
| 944 | | magtape.irg_pos = MTIRGP_END; |
| 850 | timer_adjust_oneshot(state->magtape.timer, attotime_mul(ATTOTIME_IN_NSEC(6600), state->magtape.img->ftell()), 0); |
| 851 | //schedule_unselect(state); |
| 852 | state->magtape.img->fseek( 0, SEEK_END); |
| 853 | state->magtape.irg_pos = MTIRGP_END; |
| 945 | 854 | break; |
| 946 | 855 | |
| 947 | 856 | case 3: /* write */ |
| 948 | | switch (magtape.u.write.state) |
| 857 | switch (state->magtape.u.write.state) |
| 949 | 858 | { |
| 950 | 859 | case MTWTS_STATE0: |
| 951 | | if (magtape.u.write.counter != 0) |
| 860 | if (state->magtape.u.write.counter != 0) |
| 952 | 861 | { |
| 953 | | magtape.u.write.counter--; |
| 862 | state->magtape.u.write.counter--; |
| 954 | 863 | buf = 0; |
| 955 | 864 | break; |
| 956 | 865 | } |
| 957 | 866 | else |
| 958 | 867 | { |
| 959 | | magtape.u.write.state = MTWTS_STATE1; |
| 868 | state->magtape.u.write.state = MTWTS_STATE1; |
| 960 | 869 | } |
| 961 | 870 | |
| 962 | 871 | case MTWTS_STATE1: |
| 963 | | if (magtape.u.write.counter) |
| 872 | if (state->magtape.u.write.counter) |
| 964 | 873 | { |
| 965 | | magtape.u.write.counter--; |
| 874 | state->magtape.u.write.counter--; |
| 966 | 875 | lr = cpu_get_reg(device, TX0_LR); |
| 967 | 876 | buf = ((lr >> 10) & 040) | ((lr >> 8) & 020) | ((lr >> 6) & 010) | ((lr >> 4) & 004) | ((lr >> 2) & 002) | (lr & 001); |
| 968 | | buf |= ((buf << 1) ^ (buf << 2) ^ (buf << 3) ^ (buf << 4) ^ (buf << 5) ^ (buf << 6) ^ ((!magtape.binary_flag) << 6)) & 0100; |
| 877 | buf |= ((buf << 1) ^ (buf << 2) ^ (buf << 3) ^ (buf << 4) ^ (buf << 5) ^ (buf << 6) ^ ((!state->magtape.binary_flag) << 6)) & 0100; |
| 969 | 878 | cpu_set_reg(device, TX0_LR, lr >> 1); |
| 970 | 879 | } |
| 971 | 880 | else |
| 972 | 881 | { |
| 973 | | if (magtape.cpy_pending) |
| 882 | if (state->magtape.cpy_pending) |
| 974 | 883 | { |
| 975 | 884 | cpu_set_reg(device, TX0_IO_COMPLETE, (UINT64)0); |
| 976 | 885 | lr = cpu_get_reg(device, TX0_LR); |
| 977 | 886 | buf = ((lr >> 10) & 040) | ((lr >> 8) & 020) | ((lr >> 6) & 010) | ((lr >> 4) & 004) | ((lr >> 2) & 002) | (lr & 001); |
| 978 | | buf |= ((buf << 1) ^ (buf << 2) ^ (buf << 3) ^ (buf << 4) ^ (buf << 5) ^ (buf << 6) ^ ((!magtape.binary_flag) << 6)) & 0100; |
| 887 | buf |= ((buf << 1) ^ (buf << 2) ^ (buf << 3) ^ (buf << 4) ^ (buf << 5) ^ (buf << 6) ^ ((!state->magtape.binary_flag) << 6)) & 0100; |
| 979 | 888 | cpu_set_reg(device, TX0_LR, lr >> 1); |
| 980 | | magtape.u.write.counter = 2; |
| 889 | state->magtape.u.write.counter = 2; |
| 981 | 890 | break; |
| 982 | 891 | } |
| 983 | 892 | else |
| 984 | 893 | { |
| 985 | | magtape.u.write.state = MTWTS_STATE2; |
| 986 | | magtape.u.write.counter = 3; |
| 894 | state->magtape.u.write.state = MTWTS_STATE2; |
| 895 | state->magtape.u.write.counter = 3; |
| 987 | 896 | } |
| 988 | 897 | } |
| 989 | 898 | |
| 990 | 899 | case MTWTS_STATE2: |
| 991 | | if (magtape.u.write.counter != 0) |
| 900 | if (state->magtape.u.write.counter != 0) |
| 992 | 901 | { |
| 993 | | magtape.u.write.counter--; |
| 902 | state->magtape.u.write.counter--; |
| 994 | 903 | buf = 0; |
| 995 | 904 | break; |
| 996 | 905 | } |
| 997 | 906 | else |
| 998 | 907 | { |
| 999 | | buf = magtape.long_parity; |
| 1000 | | magtape.state = (state_t)MTWTS_STATE3; |
| 1001 | | magtape.u.write.counter = 150; |
| 908 | buf = state->magtape.long_parity; |
| 909 | state->magtape.state = (state_t)MTWTS_STATE3; |
| 910 | state->magtape.u.write.counter = 150; |
| 1002 | 911 | } |
| 1003 | 912 | break; |
| 1004 | 913 | |
| 1005 | 914 | case MTWTS_STATE3: |
| 1006 | | if (magtape.u.write.counter != 0) |
| 915 | if (state->magtape.u.write.counter != 0) |
| 1007 | 916 | { |
| 1008 | | magtape.u.write.counter--; |
| 917 | state->magtape.u.write.counter--; |
| 1009 | 918 | buf = 0; |
| 1010 | 919 | break; |
| 1011 | 920 | } |
| 1012 | 921 | else |
| 1013 | 922 | { |
| 1014 | | magtape.state = MTS_UNSELECTING; |
| 1015 | | schedule_unselect(); |
| 1016 | | magtape.irg_pos = MTIRGP_END; |
| 923 | state->magtape.state = MTS_UNSELECTING; |
| 924 | schedule_unselect(state); |
| 925 | state->magtape.irg_pos = MTIRGP_END; |
| 1017 | 926 | } |
| 1018 | 927 | break; |
| 1019 | 928 | } |
| 1020 | | if (magtape.state != MTS_UNSELECTING) |
| 929 | if (state->magtape.state != MTS_UNSELECTING) |
| 1021 | 930 | { /* write data word */ |
| 1022 | | magtape.long_parity ^= buf; |
| 1023 | | if (magtape.img->fwrite(&buf, 1) != 1) |
| 931 | state->magtape.long_parity ^= buf; |
| 932 | if (state->magtape.img->fwrite(&buf, 1) != 1) |
| 1024 | 933 | { /* I/O error */ |
| 1025 | 934 | /* eject tape */ |
| 1026 | | magtape.img->unload(); |
| 935 | state->magtape.img->unload(); |
| 1027 | 936 | } |
| 1028 | 937 | else |
| 1029 | | timer_adjust_oneshot(magtape.timer, ATTOTIME_IN_USEC(66), 0); |
| 938 | timer_adjust_oneshot(state->magtape.timer, ATTOTIME_IN_USEC(66), 0); |
| 1030 | 939 | } |
| 1031 | 940 | break; |
| 1032 | 941 | } |
| r9667 | r9668 | |
| 1036 | 945 | |
| 1037 | 946 | void tx0_sel(running_device *device) |
| 1038 | 947 | { |
| 1039 | | magtape.sel_pending = TRUE; |
| 948 | tx0_state *state = device->machine->driver_data<tx0_state>(); |
| 949 | state->magtape.sel_pending = TRUE; |
| 1040 | 950 | |
| 1041 | | if (magtape.state == MTS_UNSELECTED) |
| 951 | if (state->magtape.state == MTS_UNSELECTED) |
| 1042 | 952 | { |
| 1043 | 953 | if (0) |
| 1044 | 954 | magtape_callback(device); |
| 1045 | | timer_adjust_oneshot(magtape.timer, attotime_zero, 0); |
| 955 | timer_adjust_oneshot(state->magtape.timer, attotime_zero, 0); |
| 1046 | 956 | } |
| 1047 | 957 | } |
| 1048 | 958 | |
| 1049 | 959 | void tx0_io_cpy(running_device *device) |
| 1050 | 960 | { |
| 1051 | | switch (magtape.state) |
| 961 | tx0_state *state = device->machine->driver_data<tx0_state>(); |
| 962 | switch (state->magtape.state) |
| 1052 | 963 | { |
| 1053 | 964 | case MTS_UNSELECTED: |
| 1054 | 965 | case MTS_UNSELECTING: |
| r9667 | r9668 | |
| 1058 | 969 | |
| 1059 | 970 | case MTS_SELECTING: |
| 1060 | 971 | case MTS_SELECTED: |
| 1061 | | switch (magtape.command) |
| 972 | switch (state->magtape.command) |
| 1062 | 973 | { |
| 1063 | 974 | case 0: /* backspace */ |
| 1064 | 975 | case 2: /* rewind */ |
| r9667 | r9668 | |
| 1067 | 978 | break; |
| 1068 | 979 | case 1: /* read */ |
| 1069 | 980 | case 3: /* write */ |
| 1070 | | magtape.cpy_pending = TRUE; |
| 981 | state->magtape.cpy_pending = TRUE; |
| 1071 | 982 | break; |
| 1072 | 983 | } |
| 1073 | 984 | break; |
| r9667 | r9668 | |
| 1082 | 993 | */ |
| 1083 | 994 | void tx0_io_reset_callback(running_device *device) |
| 1084 | 995 | { |
| 1085 | | tape_reader.rcl = tape_reader.rc = 0; |
| 1086 | | if (tape_reader.timer) |
| 1087 | | timer_enable(tape_reader.timer, 0); |
| 996 | tx0_state *state = device->machine->driver_data<tx0_state>(); |
| 997 | state->tape_reader.rcl = state->tape_reader.rc = 0; |
| 998 | if (state->tape_reader.timer) |
| 999 | timer_enable(state->tape_reader.timer, 0); |
| 1088 | 1000 | |
| 1089 | | if (tape_puncher.timer) |
| 1090 | | timer_enable(tape_puncher.timer, 0); |
| 1001 | if (state->tape_puncher.timer) |
| 1002 | timer_enable(state->tape_puncher.timer, 0); |
| 1091 | 1003 | |
| 1092 | | if (typewriter.prt_timer) |
| 1093 | | timer_enable(typewriter.prt_timer, 0); |
| 1004 | if (state->typewriter.prt_timer) |
| 1005 | timer_enable(state->typewriter.prt_timer, 0); |
| 1094 | 1006 | |
| 1095 | | if (dis_timer) |
| 1096 | | timer_enable(dis_timer, 0); |
| 1007 | if (state->dis_timer) |
| 1008 | timer_enable(state->dis_timer, 0); |
| 1097 | 1009 | } |
| 1098 | 1010 | |
| 1099 | 1011 | |
| r9667 | r9668 | |
| 1102 | 1014 | */ |
| 1103 | 1015 | static void tx0_keyboard(running_machine *machine) |
| 1104 | 1016 | { |
| 1017 | tx0_state *state = machine->driver_data<tx0_state>(); |
| 1105 | 1018 | int i; |
| 1106 | 1019 | int j; |
| 1107 | 1020 | |
| 1108 | 1021 | int typewriter_keys[4]; |
| 1109 | | static int old_typewriter_keys[4]; |
| 1110 | 1022 | |
| 1111 | 1023 | int typewriter_transitions; |
| 1112 | 1024 | int charcode, lr; |
| r9667 | r9668 | |
| 1119 | 1031 | |
| 1120 | 1032 | for (i=0; i<4; i++) |
| 1121 | 1033 | { |
| 1122 | | typewriter_transitions = typewriter_keys[i] & (~ old_typewriter_keys[i]); |
| 1034 | typewriter_transitions = typewriter_keys[i] & (~ state->old_typewriter_keys[i]); |
| 1123 | 1035 | if (typewriter_transitions) |
| 1124 | 1036 | { |
| 1125 | 1037 | for (j=0; (((typewriter_transitions >> j) & 1) == 0) /*&& (j<16)*/; j++) |
| r9667 | r9668 | |
| 1137 | 1049 | } |
| 1138 | 1050 | |
| 1139 | 1051 | for (i=0; i<4; i++) |
| 1140 | | old_typewriter_keys[i] = typewriter_keys[i]; |
| 1052 | state->old_typewriter_keys[i] = typewriter_keys[i]; |
| 1141 | 1053 | } |
| 1142 | 1054 | |
| 1143 | 1055 | /* |
| r9667 | r9668 | |
| 1145 | 1057 | */ |
| 1146 | 1058 | INTERRUPT_GEN( tx0_interrupt ) |
| 1147 | 1059 | { |
| 1060 | tx0_state *state = device->machine->driver_data<tx0_state>(); |
| 1148 | 1061 | int control_keys; |
| 1149 | 1062 | int tsr_keys; |
| 1150 | 1063 | |
| 1151 | | static int old_control_keys; |
| 1152 | | static int old_tsr_keys; |
| 1153 | | static int tsr_index = 0; |
| 1154 | | |
| 1155 | 1064 | int control_transitions; |
| 1156 | 1065 | int tsr_transitions; |
| 1157 | 1066 | |
| r9667 | r9668 | |
| 1162 | 1071 | if (control_keys & tx0_control) |
| 1163 | 1072 | { |
| 1164 | 1073 | /* compute transitions */ |
| 1165 | | control_transitions = control_keys & (~ old_control_keys); |
| 1074 | control_transitions = control_keys & (~ state->old_control_keys); |
| 1166 | 1075 | |
| 1167 | 1076 | if (control_transitions & tx0_stop_cyc0) |
| 1168 | 1077 | { |
| r9667 | r9668 | |
| 1194 | 1103 | } |
| 1195 | 1104 | if (control_transitions & tx0_toggle_dn) |
| 1196 | 1105 | { |
| 1197 | | tsr_index++; |
| 1198 | | if (tsr_index == 18) |
| 1199 | | tsr_index = 0; |
| 1106 | state->tsr_index++; |
| 1107 | if (state->tsr_index == 18) |
| 1108 | state->tsr_index = 0; |
| 1200 | 1109 | } |
| 1201 | 1110 | if (control_transitions & tx0_toggle_up) |
| 1202 | 1111 | { |
| 1203 | | tsr_index--; |
| 1204 | | if (tsr_index == -1) |
| 1205 | | tsr_index = 17; |
| 1112 | state->tsr_index--; |
| 1113 | if (state->tsr_index == -1) |
| 1114 | state->tsr_index = 17; |
| 1206 | 1115 | } |
| 1207 | 1116 | if (control_transitions & tx0_cm_sel) |
| 1208 | 1117 | { |
| 1209 | | if (tsr_index >= 2) |
| 1118 | if (state->tsr_index >= 2) |
| 1210 | 1119 | { |
| 1211 | 1120 | UINT32 cm_sel = (UINT32) cpu_get_reg(device->machine->device("maincpu"), TX0_CM_SEL); |
| 1212 | | cpu_set_reg(device->machine->device("maincpu"), TX0_CM_SEL, cm_sel ^ (1 << (tsr_index - 2))); |
| 1121 | cpu_set_reg(device->machine->device("maincpu"), TX0_CM_SEL, cm_sel ^ (1 << (state->tsr_index - 2))); |
| 1213 | 1122 | } |
| 1214 | 1123 | } |
| 1215 | 1124 | if (control_transitions & tx0_lr_sel) |
| 1216 | 1125 | { |
| 1217 | | if (tsr_index >= 2) |
| 1126 | if (state->tsr_index >= 2) |
| 1218 | 1127 | { |
| 1219 | 1128 | UINT32 lr_sel = (UINT32) cpu_get_reg(device->machine->device("maincpu"), TX0_LR_SEL); |
| 1220 | | cpu_set_reg(device->machine->device("maincpu"), TX0_LR_SEL, (lr_sel ^ (1 << (tsr_index - 2)))); |
| 1129 | cpu_set_reg(device->machine->device("maincpu"), TX0_LR_SEL, (lr_sel ^ (1 << (state->tsr_index - 2)))); |
| 1221 | 1130 | } |
| 1222 | 1131 | } |
| 1223 | 1132 | |
| 1224 | 1133 | /* remember new state of control keys */ |
| 1225 | | old_control_keys = control_keys; |
| 1134 | state->old_control_keys = control_keys; |
| 1226 | 1135 | |
| 1227 | 1136 | |
| 1228 | 1137 | /* handle toggle switch register keys */ |
| 1229 | 1138 | tsr_keys = (input_port_read(device->machine, "MSW") << 16) | input_port_read(device->machine, "LSW"); |
| 1230 | 1139 | |
| 1231 | 1140 | /* compute transitions */ |
| 1232 | | tsr_transitions = tsr_keys & (~ old_tsr_keys); |
| 1141 | tsr_transitions = tsr_keys & (~ state->old_tsr_keys); |
| 1233 | 1142 | |
| 1234 | 1143 | /* update toggle switch register */ |
| 1235 | 1144 | if (tsr_transitions) |
| 1236 | | cpu_set_reg(device->machine->device("maincpu"), TX0_TBR+tsr_index, cpu_get_reg(device->machine->device("maincpu"), TX0_TBR+tsr_index) ^ tsr_transitions); |
| 1145 | cpu_set_reg(device->machine->device("maincpu"), TX0_TBR+state->tsr_index, cpu_get_reg(device->machine->device("maincpu"), TX0_TBR+state->tsr_index) ^ tsr_transitions); |
| 1237 | 1146 | |
| 1238 | 1147 | /* remember new state of toggle switch register keys */ |
| 1239 | | old_tsr_keys = tsr_keys; |
| 1148 | state->old_tsr_keys = tsr_keys; |
| 1240 | 1149 | } |
| 1241 | 1150 | else |
| 1242 | 1151 | { |
| 1243 | | old_control_keys = 0; |
| 1244 | | old_tsr_keys = 0; |
| 1152 | state->old_control_keys = 0; |
| 1153 | state->old_tsr_keys = 0; |
| 1245 | 1154 | |
| 1246 | 1155 | tx0_keyboard(device->machine); |
| 1247 | 1156 | } |
src/mess/machine/odyssey2.c
| r9667 | r9668 | |
| 12 | 12 | #include "sound/sp0256.h" |
| 13 | 13 | |
| 14 | 14 | |
| 15 | | static int the_voice_lrq_state; |
| 16 | | static UINT8 *ram; |
| 17 | | static UINT8 p1, p2; |
| 18 | | static size_t cart_size; |
| 19 | 15 | |
| 20 | 16 | static void odyssey2_switch_banks(running_machine *machine) |
| 21 | 17 | { |
| 22 | | switch ( cart_size ) { |
| 18 | odyssey2_state *state = machine->driver_data<odyssey2_state>(); |
| 19 | switch ( state->cart_size ) { |
| 23 | 20 | case 12288: |
| 24 | 21 | /* 12KB cart support (for instance, KTAA as released) */ |
| 25 | | memory_set_bankptr( machine, "bank1", memory_region(machine, "user1") + (p1 & 0x03) * 0xC00 ); |
| 26 | | memory_set_bankptr( machine, "bank2", memory_region(machine, "user1") + (p1 & 0x03) * 0xC00 + 0x800 ); |
| 22 | memory_set_bankptr( machine, "bank1", memory_region(machine, "user1") + (state->p1 & 0x03) * 0xC00 ); |
| 23 | memory_set_bankptr( machine, "bank2", memory_region(machine, "user1") + (state->p1 & 0x03) * 0xC00 + 0x800 ); |
| 27 | 24 | break; |
| 28 | 25 | case 16384: |
| 29 | 26 | /* 16KB cart support (for instance, full sized version KTAA) */ |
| 30 | | memory_set_bankptr( machine, "bank1", memory_region(machine, "user1") + (p1 & 0x03) * 0x1000 + 0x400 ); |
| 31 | | memory_set_bankptr( machine, "bank2", memory_region(machine, "user1") + (p1 & 0x03) * 0x1000 + 0xC00 ); |
| 27 | memory_set_bankptr( machine, "bank1", memory_region(machine, "user1") + (state->p1 & 0x03) * 0x1000 + 0x400 ); |
| 28 | memory_set_bankptr( machine, "bank2", memory_region(machine, "user1") + (state->p1 & 0x03) * 0x1000 + 0xC00 ); |
| 32 | 29 | break; |
| 33 | 30 | default: |
| 34 | | memory_set_bankptr(machine, "bank1", memory_region(machine, "user1") + (p1 & 0x03) * 0x800); |
| 35 | | memory_set_bankptr(machine, "bank2", memory_region(machine, "user1") + (p1 & 0x03) * 0x800 ); |
| 31 | memory_set_bankptr(machine, "bank1", memory_region(machine, "user1") + (state->p1 & 0x03) * 0x800); |
| 32 | memory_set_bankptr(machine, "bank2", memory_region(machine, "user1") + (state->p1 & 0x03) * 0x800 ); |
| 36 | 33 | break; |
| 37 | 34 | } |
| 38 | 35 | } |
| 39 | 36 | |
| 40 | 37 | void odyssey2_the_voice_lrq_callback(running_device *device, int state) { |
| 41 | | the_voice_lrq_state = state; |
| 38 | odyssey2_state *drvstate = device->machine->driver_data<odyssey2_state>(); |
| 39 | drvstate->the_voice_lrq_state = state; |
| 42 | 40 | } |
| 43 | 41 | |
| 44 | 42 | READ8_HANDLER( odyssey2_t0_r ) { |
| 45 | | return ( the_voice_lrq_state == ASSERT_LINE ) ? 0 : 1; |
| 43 | odyssey2_state *state = space->machine->driver_data<odyssey2_state>(); |
| 44 | return ( state->the_voice_lrq_state == ASSERT_LINE ) ? 0 : 1; |
| 46 | 45 | } |
| 47 | 46 | |
| 48 | 47 | DRIVER_INIT( odyssey2 ) |
| 49 | 48 | { |
| 49 | odyssey2_state *state = machine->driver_data<odyssey2_state>(); |
| 50 | 50 | int i; |
| 51 | 51 | UINT8 *gfx = memory_region(machine, "gfx1"); |
| 52 | | ram = auto_alloc_array(machine, UINT8, 256); |
| 52 | state->ram = auto_alloc_array(machine, UINT8, 256); |
| 53 | 53 | |
| 54 | 54 | for (i = 0; i < 256; i++) |
| 55 | 55 | { |
| 56 | 56 | gfx[i] = i; /* TODO: Why i and not 0? */ |
| 57 | | ram[i] = 0; |
| 57 | state->ram[i] = 0; |
| 58 | 58 | } |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | MACHINE_RESET( odyssey2 ) |
| 62 | 62 | { |
| 63 | odyssey2_state *state = machine->driver_data<odyssey2_state>(); |
| 63 | 64 | /* jump to "last" bank, will work for all sizes due to being mirrored */ |
| 64 | | p1 = 0xFF; |
| 65 | | p2 = 0xFF; |
| 65 | state->p1 = 0xFF; |
| 66 | state->p2 = 0xFF; |
| 66 | 67 | odyssey2_switch_banks(machine); |
| 67 | 68 | } |
| 68 | 69 | |
| r9667 | r9668 | |
| 70 | 71 | |
| 71 | 72 | READ8_HANDLER( odyssey2_bus_r ) |
| 72 | 73 | { |
| 73 | | if ((p1 & (P1_VDC_COPY_MODE_ENABLE | P1_VDC_ENABLE)) == 0) |
| 74 | | return odyssey2_video_r(space, offset); /* seems to have higher priority than ram??? */ |
| 74 | odyssey2_state *state = space->machine->driver_data<odyssey2_state>(); |
| 75 | if ((state->p1 & (P1_VDC_COPY_MODE_ENABLE | P1_VDC_ENABLE)) == 0) |
| 76 | return odyssey2_video_r(space, offset); /* seems to have higher priority than state->ram??? */ |
| 75 | 77 | |
| 76 | | else if (!(p1 & P1_EXT_RAM_ENABLE)) |
| 77 | | return ram[offset]; |
| 78 | else if (!(state->p1 & P1_EXT_RAM_ENABLE)) |
| 79 | return state->ram[offset]; |
| 78 | 80 | |
| 79 | 81 | return 0; |
| 80 | 82 | } |
| 81 | 83 | |
| 82 | 84 | WRITE8_HANDLER( odyssey2_bus_w ) |
| 83 | 85 | { |
| 84 | | if ((p1 & (P1_EXT_RAM_ENABLE | P1_VDC_COPY_MODE_ENABLE)) == 0x00) { |
| 85 | | ram[offset] = data; |
| 86 | odyssey2_state *state = space->machine->driver_data<odyssey2_state>(); |
| 87 | if ((state->p1 & (P1_EXT_RAM_ENABLE | P1_VDC_COPY_MODE_ENABLE)) == 0x00) { |
| 88 | state->ram[offset] = data; |
| 86 | 89 | if ( offset & 0x80 ) { |
| 87 | 90 | if ( data & 0x20 ) { |
| 88 | | logerror("voice write %02X, data = %02X (p1 = %02X)\n", offset, data, p1 ); |
| 91 | logerror("voice write %02X, data = %02X (state->p1 = %02X)\n", offset, data, state->p1 ); |
| 89 | 92 | sp0256_ALD_w( space->machine->device("sp0256_speech"), 0, offset & 0x7F ); |
| 90 | 93 | } else { |
| 91 | 94 | /* TODO: Reset sp0256 in this case */ |
| r9667 | r9668 | |
| 93 | 96 | } |
| 94 | 97 | } |
| 95 | 98 | |
| 96 | | else if (!(p1 & P1_VDC_ENABLE)) |
| 99 | else if (!(state->p1 & P1_VDC_ENABLE)) |
| 97 | 100 | odyssey2_video_w(space, offset, data); |
| 98 | 101 | } |
| 99 | 102 | |
| 100 | 103 | READ8_HANDLER( g7400_bus_r ) |
| 101 | 104 | { |
| 102 | | if ((p1 & (P1_VDC_COPY_MODE_ENABLE | P1_VDC_ENABLE)) == 0) { |
| 103 | | return odyssey2_video_r(space, offset); /* seems to have higher priority than ram??? */ |
| 105 | odyssey2_state *state = space->machine->driver_data<odyssey2_state>(); |
| 106 | if ((state->p1 & (P1_VDC_COPY_MODE_ENABLE | P1_VDC_ENABLE)) == 0) { |
| 107 | return odyssey2_video_r(space, offset); /* seems to have higher priority than state->ram??? */ |
| 104 | 108 | } |
| 105 | | else if (!(p1 & P1_EXT_RAM_ENABLE)) { |
| 106 | | return ram[offset]; |
| 109 | else if (!(state->p1 & P1_EXT_RAM_ENABLE)) { |
| 110 | return state->ram[offset]; |
| 107 | 111 | } else { |
| 108 | 112 | // return ef9341_r( offset & 0x02, offset & 0x01 ); |
| 109 | 113 | } |
| r9667 | r9668 | |
| 113 | 117 | |
| 114 | 118 | WRITE8_HANDLER( g7400_bus_w ) |
| 115 | 119 | { |
| 116 | | if ((p1 & (P1_EXT_RAM_ENABLE | P1_VDC_COPY_MODE_ENABLE)) == 0x00) { |
| 117 | | ram[offset] = data; |
| 120 | odyssey2_state *state = space->machine->driver_data<odyssey2_state>(); |
| 121 | if ((state->p1 & (P1_EXT_RAM_ENABLE | P1_VDC_COPY_MODE_ENABLE)) == 0x00) { |
| 122 | state->ram[offset] = data; |
| 118 | 123 | } |
| 119 | | else if (!(p1 & P1_VDC_ENABLE)) { |
| 124 | else if (!(state->p1 & P1_VDC_ENABLE)) { |
| 120 | 125 | odyssey2_video_w(space, offset, data); |
| 121 | 126 | } else { |
| 122 | 127 | // ef9341_w( offset & 0x02, offset & 0x01, data ); |
| r9667 | r9668 | |
| 127 | 132 | |
| 128 | 133 | READ8_HANDLER( odyssey2_getp1 ) |
| 129 | 134 | { |
| 130 | | UINT8 data = p1; |
| 135 | odyssey2_state *state = space->machine->driver_data<odyssey2_state>(); |
| 136 | UINT8 data = state->p1; |
| 131 | 137 | |
| 132 | | logerror("%.9f p1 read %.2x\n", attotime_to_double(timer_get_time(space->machine)), data); |
| 138 | logerror("%.9f state->p1 read %.2x\n", attotime_to_double(timer_get_time(space->machine)), data); |
| 133 | 139 | return data; |
| 134 | 140 | } |
| 135 | 141 | |
| 136 | 142 | WRITE8_HANDLER( odyssey2_putp1 ) |
| 137 | 143 | { |
| 138 | | p1 = data; |
| 144 | odyssey2_state *state = space->machine->driver_data<odyssey2_state>(); |
| 145 | state->p1 = data; |
| 139 | 146 | |
| 140 | 147 | odyssey2_switch_banks(space->machine); |
| 141 | 148 | |
| 142 | | odyssey2_lum_w ( space, 0, p1 >> 7 ); |
| 149 | odyssey2_lum_w ( space, 0, state->p1 >> 7 ); |
| 143 | 150 | |
| 144 | | logerror("%.6f p1 written %.2x\n", attotime_to_double(timer_get_time(space->machine)), data); |
| 151 | logerror("%.6f state->p1 written %.2x\n", attotime_to_double(timer_get_time(space->machine)), data); |
| 145 | 152 | } |
| 146 | 153 | |
| 147 | 154 | READ8_HANDLER( odyssey2_getp2 ) |
| 148 | 155 | { |
| 156 | odyssey2_state *state = space->machine->driver_data<odyssey2_state>(); |
| 149 | 157 | UINT8 h = 0xFF; |
| 150 | 158 | int i, j; |
| 151 | 159 | static const char *const keynames[] = { "KEY0", "KEY1", "KEY2", "KEY3", "KEY4", "KEY5" }; |
| 152 | 160 | |
| 153 | | if (!(p1 & P1_KEYBOARD_SCAN_ENABLE)) |
| 161 | if (!(state->p1 & P1_KEYBOARD_SCAN_ENABLE)) |
| 154 | 162 | { |
| 155 | | if ((p2 & P2_KEYBOARD_SELECT_MASK) <= 5) /* read keyboard */ |
| 163 | if ((state->p2 & P2_KEYBOARD_SELECT_MASK) <= 5) /* read keyboard */ |
| 156 | 164 | { |
| 157 | | h &= input_port_read(space->machine, keynames[p2 & P2_KEYBOARD_SELECT_MASK]); |
| 165 | h &= input_port_read(space->machine, keynames[state->p2 & P2_KEYBOARD_SELECT_MASK]); |
| 158 | 166 | } |
| 159 | 167 | |
| 160 | 168 | for (i= 0x80, j = 0; i > 0; i >>= 1, j++) |
| 161 | 169 | { |
| 162 | 170 | if (!(h & i)) |
| 163 | 171 | { |
| 164 | | p2 &= ~0x10; /* set key was pressed indicator */ |
| 165 | | p2 = (p2 & ~0xE0) | (j << 5); /* column that was pressed */ |
| 172 | state->p2 &= ~0x10; /* set key was pressed indicator */ |
| 173 | state->p2 = (state->p2 & ~0xE0) | (j << 5); /* column that was pressed */ |
| 166 | 174 | |
| 167 | 175 | break; |
| 168 | 176 | } |
| 169 | 177 | } |
| 170 | 178 | |
| 171 | 179 | if (h == 0xFF) /* active low inputs, so no keypresses */ |
| 172 | | p2 = p2 | 0xF0; |
| 180 | state->p2 = state->p2 | 0xF0; |
| 173 | 181 | } |
| 174 | 182 | |
| 175 | 183 | else |
| 176 | | p2 = p2 | 0xF0; |
| 184 | state->p2 = state->p2 | 0xF0; |
| 177 | 185 | |
| 178 | | logerror("%.6f p2 read %.2x\n", attotime_to_double(timer_get_time(space->machine)), p2); |
| 179 | | return p2; |
| 186 | logerror("%.6f state->p2 read %.2x\n", attotime_to_double(timer_get_time(space->machine)), state->p2); |
| 187 | return state->p2; |
| 180 | 188 | } |
| 181 | 189 | |
| 182 | 190 | WRITE8_HANDLER( odyssey2_putp2 ) |
| 183 | 191 | { |
| 184 | | p2 = data; |
| 192 | odyssey2_state *state = space->machine->driver_data<odyssey2_state>(); |
| 193 | state->p2 = data; |
| 185 | 194 | |
| 186 | | logerror("%.6f p2 written %.2x\n", attotime_to_double(timer_get_time(space->machine)), data); |
| 195 | logerror("%.6f state->p2 written %.2x\n", attotime_to_double(timer_get_time(space->machine)), data); |
| 187 | 196 | } |
| 188 | 197 | |
| 189 | 198 | READ8_HANDLER( odyssey2_getbus ) |
| 190 | 199 | { |
| 200 | odyssey2_state *state = space->machine->driver_data<odyssey2_state>(); |
| 191 | 201 | UINT8 data = 0xff; |
| 192 | 202 | |
| 193 | | if ((p2 & P2_KEYBOARD_SELECT_MASK) == 1) |
| 203 | if ((state->p2 & P2_KEYBOARD_SELECT_MASK) == 1) |
| 194 | 204 | data &= input_port_read(space->machine, "JOY0"); /* read joystick 1 */ |
| 195 | 205 | |
| 196 | | if ((p2 & P2_KEYBOARD_SELECT_MASK) == 0) |
| 206 | if ((state->p2 & P2_KEYBOARD_SELECT_MASK) == 0) |
| 197 | 207 | data &= input_port_read(space->machine, "JOY1"); /* read joystick 2 */ |
| 198 | 208 | |
| 199 | 209 | logerror("%.6f bus read %.2x\n", attotime_to_double(timer_get_time(space->machine)), data); |
| r9667 | r9668 | |
| 210 | 220 | #ifdef UNUSED_FUNCTION |
| 211 | 221 | int odyssey2_cart_verify(const UINT8 *cartdata, size_t size) |
| 212 | 222 | { |
| 213 | | cart_size = size; |
| 223 | odyssey2_state *state = machine->driver_data<odyssey2_state>(); |
| 224 | state->cart_size = size; |
| 214 | 225 | if ( (size == 2048) |
| 215 | 226 | || (size == 4096) |
| 216 | 227 | || (size == 8192) |
src/mess/machine/vectrex.c
| r9667 | r9668 | |
| 28 | 28 | |
| 29 | 29 | *********************************************************************/ |
| 30 | 30 | |
| 31 | | unsigned char vectrex_via_out[2]; |
| 32 | | rgb_t vectrex_beam_color; /* the color of the vectrex beam */ |
| 33 | | int vectrex_imager_status = 0; /* 0 = off, 1 = right eye, 2 = left eye */ |
| 34 | | double vectrex_imager_freq; |
| 35 | | emu_timer *vectrex_imager_timer; |
| 36 | | int vectrex_lightpen_port=0; |
| 37 | | int vectrex_reset_refresh; |
| 38 | 31 | |
| 39 | 32 | |
| 40 | 33 | /********************************************************************* |
| r9667 | r9668 | |
| 44 | 37 | *********************************************************************/ |
| 45 | 38 | |
| 46 | 39 | /* Colors for right and left eye */ |
| 47 | | static rgb_t imager_colors[6]; |
| 48 | 40 | |
| 49 | 41 | /* Starting points of the three colors */ |
| 50 | 42 | /* Values taken from J. Nelson's drawings*/ |
| r9667 | r9668 | |
| 55 | 47 | |
| 56 | 48 | |
| 57 | 49 | static const double unknown_game_angles[3] = {0,0.16666666, 0.33333333}; |
| 58 | | static const double *vectrex_imager_angles; |
| 59 | | static unsigned char vectrex_imager_pinlevel; |
| 60 | 50 | |
| 61 | 51 | |
| 62 | 52 | static int vectrex_verify_cart(char *data) |
| r9667 | r9668 | |
| 77 | 67 | |
| 78 | 68 | DEVICE_IMAGE_LOAD(vectrex_cart) |
| 79 | 69 | { |
| 70 | vectrex_state *state = image.device().machine->driver_data<vectrex_state>(); |
| 80 | 71 | UINT8 *mem = memory_region(image.device().machine, "maincpu"); |
| 81 | 72 | if (image.software_entry() == NULL) |
| 82 | 73 | { |
| r9667 | r9668 | |
| 93 | 84 | return IMAGE_INIT_FAIL; |
| 94 | 85 | } |
| 95 | 86 | |
| 96 | | /* If VIA T2 starts, reset refresh timer. |
| 87 | /* If VIA T2 starts, reset state->refresh timer. |
| 97 | 88 | This is the best strategy for most games. */ |
| 98 | | vectrex_reset_refresh = 1; |
| 89 | state->reset_refresh = 1; |
| 99 | 90 | |
| 100 | | vectrex_imager_angles = narrow_escape_angles; |
| 91 | state->imager_angles = narrow_escape_angles; |
| 101 | 92 | |
| 102 | 93 | /* let's do this 3D detection with a strcmp using data inside the cart images */ |
| 103 | 94 | /* slightly prettier than having to hardcode CRCs */ |
| r9667 | r9668 | |
| 105 | 96 | /* handle 3D Narrow Escape but skip the 2-d hack of it from Fred Taft */ |
| 106 | 97 | if (!memcmp(mem + 0x11,"NARROW",6) && (((char*)mem)[0x39] == 0x0c)) |
| 107 | 98 | { |
| 108 | | vectrex_imager_angles = narrow_escape_angles; |
| 99 | state->imager_angles = narrow_escape_angles; |
| 109 | 100 | } |
| 110 | 101 | |
| 111 | 102 | if (!memcmp(mem + 0x11,"CRAZY COASTER", 13)) |
| 112 | 103 | { |
| 113 | | vectrex_imager_angles = crazy_coaster_angles; |
| 104 | state->imager_angles = crazy_coaster_angles; |
| 114 | 105 | } |
| 115 | 106 | |
| 116 | 107 | if (!memcmp(mem + 0x11,"3D MINE STORM", 13)) |
| 117 | 108 | { |
| 118 | | vectrex_imager_angles = minestorm_3d_angles; |
| 109 | state->imager_angles = minestorm_3d_angles; |
| 119 | 110 | |
| 120 | 111 | /* Don't reset T2 each time it's written. |
| 121 | 112 | This would cause jerking in mine3. */ |
| 122 | | vectrex_reset_refresh = 0; |
| 113 | state->reset_refresh = 0; |
| 123 | 114 | } |
| 124 | 115 | |
| 125 | 116 | return IMAGE_INIT_PASS; |
| r9667 | r9668 | |
| 134 | 125 | |
| 135 | 126 | void vectrex_configuration(running_machine *machine) |
| 136 | 127 | { |
| 128 | vectrex_state *state = machine->driver_data<vectrex_state>(); |
| 137 | 129 | unsigned char cport = input_port_read(machine, "3DCONF"); |
| 138 | 130 | |
| 139 | 131 | /* Vectrex 'dipswitch' configuration */ |
| r9667 | r9668 | |
| 141 | 133 | /* Imager control */ |
| 142 | 134 | if (cport & 0x01) /* Imager enabled */ |
| 143 | 135 | { |
| 144 | | if (vectrex_imager_status == 0) |
| 145 | | vectrex_imager_status = cport & 0x01; |
| 136 | if (state->imager_status == 0) |
| 137 | state->imager_status = cport & 0x01; |
| 146 | 138 | |
| 147 | 139 | vector_add_point_function = cport & 0x02 ? vectrex_add_point_stereo: vectrex_add_point; |
| 148 | 140 | |
| 149 | 141 | switch ((cport >> 2) & 0x07) |
| 150 | 142 | { |
| 151 | 143 | case 0x00: |
| 152 | | imager_colors[0] = imager_colors[1] = imager_colors[2] = RGB_BLACK; |
| 144 | state->imager_colors[0] = state->imager_colors[1] = state->imager_colors[2] = RGB_BLACK; |
| 153 | 145 | break; |
| 154 | 146 | case 0x01: |
| 155 | | imager_colors[0] = imager_colors[1] = imager_colors[2] = VC_DARKRED; |
| 147 | state->imager_colors[0] = state->imager_colors[1] = state->imager_colors[2] = VC_DARKRED; |
| 156 | 148 | break; |
| 157 | 149 | case 0x02: |
| 158 | | imager_colors[0] = imager_colors[1] = imager_colors[2] = VC_GREEN; |
| 150 | state->imager_colors[0] = state->imager_colors[1] = state->imager_colors[2] = VC_GREEN; |
| 159 | 151 | break; |
| 160 | 152 | case 0x03: |
| 161 | | imager_colors[0] = imager_colors[1] = imager_colors[2] = VC_BLUE; |
| 153 | state->imager_colors[0] = state->imager_colors[1] = state->imager_colors[2] = VC_BLUE; |
| 162 | 154 | break; |
| 163 | 155 | case 0x04: |
| 164 | 156 | /* mine3 has a different color sequence */ |
| 165 | | if (vectrex_imager_angles == minestorm_3d_angles) |
| 157 | if (state->imager_angles == minestorm_3d_angles) |
| 166 | 158 | { |
| 167 | | imager_colors[0] = VC_GREEN; |
| 168 | | imager_colors[1] = VC_RED; |
| 159 | state->imager_colors[0] = VC_GREEN; |
| 160 | state->imager_colors[1] = VC_RED; |
| 169 | 161 | } |
| 170 | 162 | else |
| 171 | 163 | { |
| 172 | | imager_colors[0] = VC_RED; |
| 173 | | imager_colors[1] = VC_GREEN; |
| 164 | state->imager_colors[0] = VC_RED; |
| 165 | state->imager_colors[1] = VC_GREEN; |
| 174 | 166 | } |
| 175 | | imager_colors[2]=VC_BLUE; |
| 167 | state->imager_colors[2]=VC_BLUE; |
| 176 | 168 | break; |
| 177 | 169 | } |
| 178 | 170 | |
| 179 | 171 | switch ((cport >> 5) & 0x07) |
| 180 | 172 | { |
| 181 | 173 | case 0x00: |
| 182 | | imager_colors[3] = imager_colors[4] = imager_colors[5] = RGB_BLACK; |
| 174 | state->imager_colors[3] = state->imager_colors[4] = state->imager_colors[5] = RGB_BLACK; |
| 183 | 175 | break; |
| 184 | 176 | case 0x01: |
| 185 | | imager_colors[3] = imager_colors[4] = imager_colors[5] = VC_DARKRED; |
| 177 | state->imager_colors[3] = state->imager_colors[4] = state->imager_colors[5] = VC_DARKRED; |
| 186 | 178 | break; |
| 187 | 179 | case 0x02: |
| 188 | | imager_colors[3] = imager_colors[4] = imager_colors[5] = VC_GREEN; |
| 180 | state->imager_colors[3] = state->imager_colors[4] = state->imager_colors[5] = VC_GREEN; |
| 189 | 181 | break; |
| 190 | 182 | case 0x03: |
| 191 | | imager_colors[3] = imager_colors[4] = imager_colors[5] = VC_BLUE; |
| 183 | state->imager_colors[3] = state->imager_colors[4] = state->imager_colors[5] = VC_BLUE; |
| 192 | 184 | break; |
| 193 | 185 | case 0x04: |
| 194 | | if (vectrex_imager_angles == minestorm_3d_angles) |
| 186 | if (state->imager_angles == minestorm_3d_angles) |
| 195 | 187 | { |
| 196 | | imager_colors[3] = VC_GREEN; |
| 197 | | imager_colors[4] = VC_RED; |
| 188 | state->imager_colors[3] = VC_GREEN; |
| 189 | state->imager_colors[4] = VC_RED; |
| 198 | 190 | } |
| 199 | 191 | else |
| 200 | 192 | { |
| 201 | | imager_colors[3] = VC_RED; |
| 202 | | imager_colors[4] = VC_GREEN; |
| 193 | state->imager_colors[3] = VC_RED; |
| 194 | state->imager_colors[4] = VC_GREEN; |
| 203 | 195 | } |
| 204 | | imager_colors[5]=VC_BLUE; |
| 196 | state->imager_colors[5]=VC_BLUE; |
| 205 | 197 | break; |
| 206 | 198 | } |
| 207 | 199 | } |
| 208 | 200 | else |
| 209 | 201 | { |
| 210 | 202 | vector_add_point_function = vectrex_add_point; |
| 211 | | vectrex_beam_color = RGB_WHITE; |
| 212 | | imager_colors[0] = imager_colors[1] = imager_colors[2] = imager_colors[3] = imager_colors[4] = imager_colors[5] = RGB_WHITE; |
| 203 | state->beam_color = RGB_WHITE; |
| 204 | state->imager_colors[0] = state->imager_colors[1] = state->imager_colors[2] = state->imager_colors[3] = state->imager_colors[4] = state->imager_colors[5] = RGB_WHITE; |
| 213 | 205 | } |
| 214 | | vectrex_lightpen_port = input_port_read(machine, "LPENCONF") & 0x03; |
| 206 | state->lightpen_port = input_port_read(machine, "LPENCONF") & 0x03; |
| 215 | 207 | } |
| 216 | 208 | |
| 217 | 209 | |
| r9667 | r9668 | |
| 229 | 221 | |
| 230 | 222 | READ8_DEVICE_HANDLER(vectrex_via_pb_r) |
| 231 | 223 | { |
| 224 | vectrex_state *state = device->machine->driver_data<vectrex_state>(); |
| 232 | 225 | int pot; |
| 233 | 226 | static const char *const ctrlnames[] = { "CONTR1X", "CONTR1Y", "CONTR2X", "CONTR2Y" }; |
| 234 | 227 | |
| 235 | | pot = input_port_read(device->machine, ctrlnames[(vectrex_via_out[PORTB] & 0x6) >> 1]) - 0x80; |
| 228 | pot = input_port_read(device->machine, ctrlnames[(state->via_out[PORTB] & 0x6) >> 1]) - 0x80; |
| 236 | 229 | |
| 237 | | if (pot > (signed char)vectrex_via_out[PORTA]) |
| 238 | | vectrex_via_out[PORTB] |= 0x20; |
| 230 | if (pot > (signed char)state->via_out[PORTA]) |
| 231 | state->via_out[PORTB] |= 0x20; |
| 239 | 232 | else |
| 240 | | vectrex_via_out[PORTB] &= ~0x20; |
| 233 | state->via_out[PORTB] &= ~0x20; |
| 241 | 234 | |
| 242 | | return vectrex_via_out[PORTB]; |
| 235 | return state->via_out[PORTB]; |
| 243 | 236 | } |
| 244 | 237 | |
| 245 | 238 | |
| 246 | 239 | READ8_DEVICE_HANDLER(vectrex_via_pa_r) |
| 247 | 240 | { |
| 248 | | if ((!(vectrex_via_out[PORTB] & 0x10)) && (vectrex_via_out[PORTB] & 0x08)) |
| 241 | vectrex_state *state = device->machine->driver_data<vectrex_state>(); |
| 242 | if ((!(state->via_out[PORTB] & 0x10)) && (state->via_out[PORTB] & 0x08)) |
| 249 | 243 | /* BDIR inactive, we can read the PSG. BC1 has to be active. */ |
| 250 | 244 | { |
| 251 | 245 | running_device *ay = device->machine->device("ay8912"); |
| 252 | 246 | |
| 253 | | vectrex_via_out[PORTA] = ay8910_r(ay, 0) |
| 254 | | & ~(vectrex_imager_pinlevel & 0x80); |
| 247 | state->via_out[PORTA] = ay8910_r(ay, 0) |
| 248 | & ~(state->imager_pinlevel & 0x80); |
| 255 | 249 | } |
| 256 | | return vectrex_via_out[PORTA]; |
| 250 | return state->via_out[PORTA]; |
| 257 | 251 | } |
| 258 | 252 | |
| 259 | 253 | |
| 260 | 254 | READ8_DEVICE_HANDLER(vectrex_s1_via_pb_r) |
| 261 | 255 | { |
| 262 | | return (vectrex_via_out[PORTB] & ~0x40) | (input_port_read(device->machine, "COIN") & 0x40); |
| 256 | vectrex_state *state = device->machine->driver_data<vectrex_state>(); |
| 257 | return (state->via_out[PORTB] & ~0x40) | (input_port_read(device->machine, "COIN") & 0x40); |
| 263 | 258 | } |
| 264 | 259 | |
| 265 | 260 | |
| r9667 | r9668 | |
| 271 | 266 | |
| 272 | 267 | static TIMER_CALLBACK(vectrex_imager_change_color) |
| 273 | 268 | { |
| 274 | | vectrex_beam_color = param; |
| 269 | vectrex_state *state = machine->driver_data<vectrex_state>(); |
| 270 | state->beam_color = param; |
| 275 | 271 | } |
| 276 | 272 | |
| 277 | 273 | |
| r9667 | r9668 | |
| 284 | 280 | |
| 285 | 281 | TIMER_CALLBACK(vectrex_imager_eye) |
| 286 | 282 | { |
| 283 | vectrex_state *state = machine->driver_data<vectrex_state>(); |
| 287 | 284 | via6522_device *via_0 = machine->device<via6522_device>("via6522_0"); |
| 288 | 285 | int coffset; |
| 289 | | double rtime = (1.0 / vectrex_imager_freq); |
| 286 | double rtime = (1.0 / state->imager_freq); |
| 290 | 287 | |
| 291 | | if (vectrex_imager_status > 0) |
| 288 | if (state->imager_status > 0) |
| 292 | 289 | { |
| 293 | | vectrex_imager_status = param; |
| 290 | state->imager_status = param; |
| 294 | 291 | coffset = param > 1? 3: 0; |
| 295 | | timer_set (machine, double_to_attotime(rtime * vectrex_imager_angles[0]), NULL, imager_colors[coffset+2], vectrex_imager_change_color); |
| 296 | | timer_set (machine, double_to_attotime(rtime * vectrex_imager_angles[1]), NULL, imager_colors[coffset+1], vectrex_imager_change_color); |
| 297 | | timer_set (machine, double_to_attotime(rtime * vectrex_imager_angles[2]), NULL, imager_colors[coffset], vectrex_imager_change_color); |
| 292 | timer_set (machine, double_to_attotime(rtime * state->imager_angles[0]), NULL, state->imager_colors[coffset+2], vectrex_imager_change_color); |
| 293 | timer_set (machine, double_to_attotime(rtime * state->imager_angles[1]), NULL, state->imager_colors[coffset+1], vectrex_imager_change_color); |
| 294 | timer_set (machine, double_to_attotime(rtime * state->imager_angles[2]), NULL, state->imager_colors[coffset], vectrex_imager_change_color); |
| 298 | 295 | |
| 299 | 296 | if (param == 2) |
| 300 | 297 | { |
| r9667 | r9668 | |
| 303 | 300 | /* Index hole sensor is connected to IO7 which triggers also CA1 of VIA */ |
| 304 | 301 | via_0->write_ca1(1); |
| 305 | 302 | via_0->write_ca1(0); |
| 306 | | vectrex_imager_pinlevel |= 0x80; |
| 307 | | timer_set (machine, double_to_attotime(rtime / 360.0), &vectrex_imager_pinlevel, 0, update_level); |
| 303 | state->imager_pinlevel |= 0x80; |
| 304 | timer_set (machine, double_to_attotime(rtime / 360.0), &state->imager_pinlevel, 0, update_level); |
| 308 | 305 | } |
| 309 | 306 | } |
| 310 | 307 | } |
| r9667 | r9668 | |
| 312 | 309 | |
| 313 | 310 | WRITE8_HANDLER(vectrex_psg_port_w) |
| 314 | 311 | { |
| 315 | | static int state; |
| 316 | | static double sl, pwl; |
| 312 | vectrex_state *state = space->machine->driver_data<vectrex_state>(); |
| 317 | 313 | double wavel, ang_acc, tmp; |
| 318 | 314 | int mcontrol; |
| 319 | 315 | |
| 320 | 316 | mcontrol = data & 0x40; /* IO6 controls the imager motor */ |
| 321 | 317 | |
| 322 | | if (!mcontrol && mcontrol ^ state) |
| 318 | if (!mcontrol && mcontrol ^ state->old_mcontrol) |
| 323 | 319 | { |
| 324 | | state = mcontrol; |
| 320 | state->old_mcontrol = mcontrol; |
| 325 | 321 | tmp = attotime_to_double(timer_get_time(space->machine)); |
| 326 | | wavel = tmp - sl; |
| 327 | | sl = tmp; |
| 322 | wavel = tmp - state->sl; |
| 323 | state->sl = tmp; |
| 328 | 324 | |
| 329 | 325 | if (wavel < 1) |
| 330 | 326 | { |
| r9667 | r9668 | |
| 334 | 330 | of the whole thing and some constants of the motor's torque/speed curve. |
| 335 | 331 | pwl is the negative pulse width and wavel is the whole wavelength. */ |
| 336 | 332 | |
| 337 | | ang_acc = (50.0 - 1.55 * vectrex_imager_freq) / MMI; |
| 338 | | vectrex_imager_freq += ang_acc * pwl + DAMPC * vectrex_imager_freq / MMI * wavel; |
| 333 | ang_acc = (50.0 - 1.55 * state->imager_freq) / MMI; |
| 334 | state->imager_freq += ang_acc * state->pwl + DAMPC * state->imager_freq / MMI * wavel; |
| 339 | 335 | |
| 340 | | if (vectrex_imager_freq > 1) |
| 336 | if (state->imager_freq > 1) |
| 341 | 337 | { |
| 342 | | timer_adjust_periodic(vectrex_imager_timer, |
| 343 | | double_to_attotime(MIN(1.0 / vectrex_imager_freq, attotime_to_double(timer_timeleft(vectrex_imager_timer)))), |
| 338 | timer_adjust_periodic(state->imager_timer, |
| 339 | double_to_attotime(MIN(1.0 / state->imager_freq, attotime_to_double(timer_timeleft(state->imager_timer)))), |
| 344 | 340 | 2, |
| 345 | | double_to_attotime(1.0 / vectrex_imager_freq)); |
| 341 | double_to_attotime(1.0 / state->imager_freq)); |
| 346 | 342 | } |
| 347 | 343 | } |
| 348 | 344 | } |
| 349 | | if (mcontrol && mcontrol ^ state) |
| 345 | if (mcontrol && mcontrol ^ state->old_mcontrol) |
| 350 | 346 | { |
| 351 | | state = mcontrol; |
| 352 | | pwl = attotime_to_double(timer_get_time(space->machine)) - sl; |
| 347 | state->old_mcontrol = mcontrol; |
| 348 | state->pwl = attotime_to_double(timer_get_time(space->machine)) - state->sl; |
| 353 | 349 | } |
| 354 | 350 | } |
| 355 | 351 | |
| 356 | 352 | DRIVER_INIT(vectrex) |
| 357 | 353 | { |
| 354 | vectrex_state *state = machine->driver_data<vectrex_state>(); |
| 358 | 355 | int i; |
| 359 | 356 | |
| 360 | | vectrex_imager_angles = unknown_game_angles; |
| 361 | | vectrex_beam_color = RGB_WHITE; |
| 362 | | for (i=0; i<ARRAY_LENGTH(imager_colors); i++) |
| 363 | | imager_colors[i] = RGB_WHITE; |
| 357 | state->imager_angles = unknown_game_angles; |
| 358 | state->beam_color = RGB_WHITE; |
| 359 | for (i=0; i<ARRAY_LENGTH(state->imager_colors); i++) |
| 360 | state->imager_colors[i] = RGB_WHITE; |
| 364 | 361 | |
| 365 | 362 | /* |
| 366 | 363 | * Uninitialized RAM needs to return 0xff. Otherwise the mines in |
| 367 | 364 | * the first level of Minestorm are not evenly distributed. |
| 368 | 365 | */ |
| 369 | 366 | |
| 370 | | memset(gce_vectorram, 0xff, gce_vectorram_size); |
| 367 | memset(state->gce_vectorram, 0xff, state->gce_vectorram_size); |
| 371 | 368 | } |
src/mess/video/pdp1.c
| r9667 | r9668 | |
| 23 | 23 | #include "video/crt.h" |
| 24 | 24 | |
| 25 | 25 | |
| 26 | | static int typewriter_color; |
| 27 | 26 | |
| 28 | | static bitmap_t *panel_bitmap; |
| 29 | | static bitmap_t *typewriter_bitmap; |
| 30 | 27 | |
| 31 | 28 | static const rectangle typewriter_bitmap_bounds = |
| 32 | 29 | { |
| r9667 | r9668 | |
| 43 | 40 | static void pdp1_draw_panel_backdrop(running_machine *machine, bitmap_t *bitmap); |
| 44 | 41 | static void pdp1_draw_panel(running_machine *machine, bitmap_t *bitmap); |
| 45 | 42 | |
| 46 | | static lightpen_t lightpen_state, previous_lightpen_state; |
| 47 | | static void pdp1_erase_lightpen(bitmap_t *bitmap); |
| 48 | | static void pdp1_draw_lightpen(bitmap_t *bitmap); |
| 43 | static void pdp1_erase_lightpen(pdp1_state *state, bitmap_t *bitmap); |
| 44 | static void pdp1_draw_lightpen(pdp1_state *state, bitmap_t *bitmap); |
| 49 | 45 | |
| 50 | 46 | INLINE void pdp1_plot_pixel(bitmap_t *bitmap, int x, int y, UINT32 color) |
| 51 | 47 | { |
| r9667 | r9668 | |
| 57 | 53 | */ |
| 58 | 54 | VIDEO_START( pdp1 ) |
| 59 | 55 | { |
| 60 | | typewriter_color = color_typewriter_black; |
| 56 | pdp1_state *state = machine->driver_data<pdp1_state>(); |
| 57 | state->typewriter_color = color_typewriter_black; |
| 61 | 58 | |
| 62 | 59 | /* alloc bitmaps for our private fun */ |
| 63 | | panel_bitmap = auto_bitmap_alloc(machine, panel_window_width, panel_window_height, BITMAP_FORMAT_INDEXED16); |
| 64 | | typewriter_bitmap = auto_bitmap_alloc(machine, typewriter_window_width, typewriter_window_height, BITMAP_FORMAT_INDEXED16); |
| 60 | state->panel_bitmap = auto_bitmap_alloc(machine, panel_window_width, panel_window_height, BITMAP_FORMAT_INDEXED16); |
| 61 | state->typewriter_bitmap = auto_bitmap_alloc(machine, typewriter_window_width, typewriter_window_height, BITMAP_FORMAT_INDEXED16); |
| 65 | 62 | |
| 66 | 63 | /* set up out bitmaps */ |
| 67 | | pdp1_draw_panel_backdrop(machine, panel_bitmap); |
| 64 | pdp1_draw_panel_backdrop(machine, state->panel_bitmap); |
| 68 | 65 | |
| 69 | | bitmap_fill(typewriter_bitmap, &typewriter_bitmap_bounds, pen_typewriter_bg); |
| 66 | bitmap_fill(state->typewriter_bitmap, &typewriter_bitmap_bounds, pen_typewriter_bg); |
| 70 | 67 | |
| 71 | 68 | /* initialize CRT */ |
| 72 | 69 | video_start_crt(machine, pen_crt_num_levels, crt_window_offset_x, crt_window_offset_y, crt_window_width, crt_window_height); |
| r9667 | r9668 | |
| 90 | 87 | */ |
| 91 | 88 | VIDEO_UPDATE( pdp1 ) |
| 92 | 89 | { |
| 93 | | pdp1_erase_lightpen(bitmap); |
| 90 | pdp1_state *state = screen->machine->driver_data<pdp1_state>(); |
| 91 | pdp1_erase_lightpen(state, bitmap); |
| 94 | 92 | VIDEO_UPDATE_CALL(crt); |
| 95 | | pdp1_draw_lightpen(bitmap); |
| 93 | pdp1_draw_lightpen(state, bitmap); |
| 96 | 94 | |
| 97 | | pdp1_draw_panel(screen->machine, panel_bitmap); |
| 98 | | copybitmap(bitmap, panel_bitmap, 0, 0, panel_window_offset_x, panel_window_offset_y, cliprect); |
| 95 | pdp1_draw_panel(screen->machine, state->panel_bitmap); |
| 96 | copybitmap(bitmap, state->panel_bitmap, 0, 0, panel_window_offset_x, panel_window_offset_y, cliprect); |
| 99 | 97 | |
| 100 | | copybitmap(bitmap, typewriter_bitmap, 0, 0, typewriter_window_offset_x, typewriter_window_offset_y, cliprect); |
| 98 | copybitmap(bitmap, state->typewriter_bitmap, 0, 0, typewriter_window_offset_x, typewriter_window_offset_y, cliprect); |
| 101 | 99 | return 0; |
| 102 | 100 | } |
| 103 | 101 | |
| r9667 | r9668 | |
| 255 | 253 | */ |
| 256 | 254 | static void pdp1_draw_panel_backdrop(running_machine *machine, bitmap_t *bitmap) |
| 257 | 255 | { |
| 256 | pdp1_state *state = machine->driver_data<pdp1_state>(); |
| 258 | 257 | /* fill with black */ |
| 259 | | bitmap_fill(panel_bitmap, &panel_bitmap_bounds, pen_panel_bg); |
| 258 | bitmap_fill(state->panel_bitmap, &panel_bitmap_bounds, pen_panel_bg); |
| 260 | 259 | |
| 261 | 260 | /* column 1: registers, test word, test address */ |
| 262 | 261 | pdp1_draw_string(machine, bitmap, "program counter", x_panel_col1_offset, y_panel_pc_offset, color_panel_caption); |
| r9667 | r9668 | |
| 350 | 349 | */ |
| 351 | 350 | |
| 352 | 351 | |
| 353 | | static int pos; |
| 354 | 352 | |
| 355 | | static int case_shift; |
| 356 | 353 | |
| 357 | 354 | enum |
| 358 | 355 | { |
| r9667 | r9668 | |
| 374 | 371 | |
| 375 | 372 | static void pdp1_typewriter_linefeed(running_machine *machine) |
| 376 | 373 | { |
| 374 | pdp1_state *state = machine->driver_data<pdp1_state>(); |
| 377 | 375 | UINT8 buf[typewriter_window_width]; |
| 378 | 376 | int y; |
| 379 | 377 | |
| 380 | 378 | for (y=0; y<typewriter_window_height-typewriter_scroll_step; y++) |
| 381 | 379 | { |
| 382 | | extract_scanline8(typewriter_bitmap, 0, y+typewriter_scroll_step, typewriter_window_width, buf); |
| 383 | | draw_scanline8(typewriter_bitmap, 0, y, typewriter_window_width, buf, machine->pens); |
| 380 | extract_scanline8(state->typewriter_bitmap, 0, y+typewriter_scroll_step, typewriter_window_width, buf); |
| 381 | draw_scanline8(state->typewriter_bitmap, 0, y, typewriter_window_width, buf, machine->pens); |
| 384 | 382 | } |
| 385 | 383 | |
| 386 | | bitmap_fill(typewriter_bitmap, &typewriter_scroll_clear_window, pen_typewriter_bg); |
| 384 | bitmap_fill(state->typewriter_bitmap, &typewriter_scroll_clear_window, pen_typewriter_bg); |
| 387 | 385 | } |
| 388 | 386 | |
| 389 | 387 | void pdp1_typewriter_drawchar(running_machine *machine, int character) |
| 390 | 388 | { |
| 389 | pdp1_state *state = machine->driver_data<pdp1_state>(); |
| 391 | 390 | static const char ascii_table[2][64] = |
| 392 | 391 | { /* n-s = non-spacing */ |
| 393 | 392 | { /* lower case */ |
| r9667 | r9668 | |
| 436 | 435 | { |
| 437 | 436 | case 034: |
| 438 | 437 | /* Black */ |
| 439 | | typewriter_color = color_typewriter_black; |
| 438 | state->typewriter_color = color_typewriter_black; |
| 440 | 439 | break; |
| 441 | 440 | |
| 442 | 441 | case 035: |
| 443 | 442 | /* Red */ |
| 444 | | typewriter_color = color_typewriter_red; |
| 443 | state->typewriter_color = color_typewriter_red; |
| 445 | 444 | break; |
| 446 | 445 | |
| 447 | 446 | case 036: |
| 448 | 447 | /* Tab */ |
| 449 | | pos = pos + tab_step - (pos % tab_step); |
| 448 | state->pos = state->pos + tab_step - (state->pos % tab_step); |
| 450 | 449 | break; |
| 451 | 450 | |
| 452 | 451 | case 072: |
| 453 | 452 | /* Lower case */ |
| 454 | | case_shift = 0; |
| 453 | state->case_shift = 0; |
| 455 | 454 | break; |
| 456 | 455 | |
| 457 | 456 | case 074: |
| 458 | 457 | /* Upper case */ |
| 459 | | case_shift = 1; |
| 458 | state->case_shift = 1; |
| 460 | 459 | break; |
| 461 | 460 | |
| 462 | 461 | case 075: |
| 463 | 462 | /* Backspace */ |
| 464 | | if (pos) |
| 465 | | pos--; |
| 463 | if (state->pos) |
| 464 | state->pos--; |
| 466 | 465 | break; |
| 467 | 466 | |
| 468 | 467 | case 077: |
| 469 | 468 | /* Carriage Return */ |
| 470 | | pos = 0; |
| 469 | state->pos = 0; |
| 471 | 470 | pdp1_typewriter_linefeed(machine); |
| 472 | 471 | break; |
| 473 | 472 | |
| 474 | 473 | default: |
| 475 | 474 | /* Any printable character... */ |
| 476 | 475 | |
| 477 | | if (pos >= 80) |
| 476 | if (state->pos >= 80) |
| 478 | 477 | { /* if past right border, wrap around. (Right???) */ |
| 479 | 478 | pdp1_typewriter_linefeed(machine); /* next line */ |
| 480 | | pos = 0; /* return to start of line */ |
| 479 | state->pos = 0; /* return to start of line */ |
| 481 | 480 | } |
| 482 | 481 | |
| 483 | 482 | /* print character (lookup ASCII equivalent in table) */ |
| 484 | | pdp1_draw_char(machine, typewriter_bitmap, ascii_table[case_shift][character], |
| 485 | | 8*pos, typewriter_write_offset_y, |
| 486 | | typewriter_color); /* print char */ |
| 483 | pdp1_draw_char(machine, state->typewriter_bitmap, ascii_table[state->case_shift][character], |
| 484 | 8*state->pos, typewriter_write_offset_y, |
| 485 | state->typewriter_color); /* print char */ |
| 487 | 486 | |
| 488 | 487 | if ((character!= 040) && (character!= 056)) /* 040 and 056 are non-spacing characters */ |
| 489 | | pos++; /* step carriage forward */ |
| 488 | state->pos++; /* step carriage forward */ |
| 490 | 489 | |
| 491 | 490 | break; |
| 492 | 491 | } |
| r9667 | r9668 | |
| 498 | 497 | lightpen code |
| 499 | 498 | */ |
| 500 | 499 | |
| 501 | | void pdp1_update_lightpen_state(const lightpen_t *new_state) |
| 500 | void pdp1_update_lightpen_state(running_machine *machine, const lightpen_t *new_state) |
| 502 | 501 | { |
| 503 | | lightpen_state = *new_state; |
| 502 | pdp1_state *state = machine->driver_data<pdp1_state>(); |
| 503 | state->lightpen_state = *new_state; |
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | #if 1 |
| r9667 | r9668 | |
| 571 | 571 | } |
| 572 | 572 | #endif |
| 573 | 573 | |
| 574 | | static void pdp1_erase_lightpen(bitmap_t *bitmap) |
| 574 | static void pdp1_erase_lightpen(pdp1_state *state, bitmap_t *bitmap) |
| 575 | 575 | { |
| 576 | | if (previous_lightpen_state.active) |
| 576 | if (state->previous_lightpen_state.active) |
| 577 | 577 | { |
| 578 | 578 | #if 0 |
| 579 | | if (previous_lightpen_state.x>0) |
| 580 | | pdp1_plot_pixel(bitmap, previous_lightpen_state.x/2-1, previous_lightpen_state.y/2, pen_black); |
| 581 | | if (previous_lightpen_state.x<1023) |
| 582 | | pdp1_plot_pixel(bitmap, previous_lightpen_state.x/2+1, previous_lightpen_state.y/2, pen_black); |
| 583 | | if (previous_lightpen_state.y>0) |
| 584 | | pdp1_plot_pixel(bitmap, previous_lightpen_state.x/2, previous_lightpen_state.y/2-1, pen_black); |
| 585 | | if (previous_lightpen_state.y<1023) |
| 586 | | pdp1_plot_pixel(bitmap, previous_lightpen_state.x/2, previous_lightpen_state.y/2+1, pen_black); |
| 579 | if (state->previous_lightpen_state.x>0) |
| 580 | pdp1_plot_pixel(bitmap, state->previous_lightpen_state.x/2-1, state->previous_lightpen_state.y/2, pen_black); |
| 581 | if (state->previous_lightpen_state.x<1023) |
| 582 | pdp1_plot_pixel(bitmap, state->previous_lightpen_state.x/2+1, state->previous_lightpen_state.y/2, pen_black); |
| 583 | if (state->previous_lightpen_state.y>0) |
| 584 | pdp1_plot_pixel(bitmap, state->previous_lightpen_state.x/2, state->previous_lightpen_state.y/2-1, pen_black); |
| 585 | if (state->previous_lightpen_state.y<1023) |
| 586 | pdp1_plot_pixel(bitmap, state->previous_lightpen_state.x/2, state->previous_lightpen_state.y/2+1, pen_black); |
| 587 | 587 | #endif |
| 588 | | pdp1_draw_circle(bitmap, previous_lightpen_state.x, previous_lightpen_state.y, previous_lightpen_state.radius, pen_black); |
| 588 | pdp1_draw_circle(bitmap, state->previous_lightpen_state.x, state->previous_lightpen_state.y, state->previous_lightpen_state.radius, pen_black); |
| 589 | 589 | } |
| 590 | 590 | } |
| 591 | 591 | |
| 592 | | static void pdp1_draw_lightpen(bitmap_t *bitmap) |
| 592 | static void pdp1_draw_lightpen(pdp1_state *state, bitmap_t *bitmap) |
| 593 | 593 | { |
| 594 | | if (lightpen_state.active) |
| 594 | if (state->lightpen_state.active) |
| 595 | 595 | { |
| 596 | | int color_ = lightpen_state.down ? pen_lightpen_pressed : pen_lightpen_nonpressed; |
| 596 | int color_ = state->lightpen_state.down ? pen_lightpen_pressed : pen_lightpen_nonpressed; |
| 597 | 597 | #if 0 |
| 598 | | if (lightpen_state.x>0) |
| 599 | | pdp1_plot_pixel(bitmap, lightpen_state.x/2-1, lightpen_state.y/2, color); |
| 600 | | if (lightpen_state.x<1023) |
| 601 | | pdp1_plot_pixel(bitmap, lightpen_state.x/2+1, lightpen_state.y/2, color); |
| 602 | | if (lightpen_state.y>0) |
| 603 | | pdp1_plot_pixel(bitmap, lightpen_state.x/2, lightpen_state.y/2-1, color); |
| 604 | | if (lightpen_state.y<1023) |
| 605 | | pdp1_plot_pixel(bitmap, lightpen_state.x/2, lightpen_state.y/2+1, color); |
| 598 | if (state->lightpen_state.x>0) |
| 599 | pdp1_plot_pixel(bitmap, state->lightpen_state.x/2-1, state->lightpen_state.y/2, color); |
| 600 | if (state->lightpen_state.x<1023) |
| 601 | pdp1_plot_pixel(bitmap, state->lightpen_state.x/2+1, state->lightpen_state.y/2, color); |
| 602 | if (state->lightpen_state.y>0) |
| 603 | pdp1_plot_pixel(bitmap, state->lightpen_state.x/2, state->lightpen_state.y/2-1, color); |
| 604 | if (state->lightpen_state.y<1023) |
| 605 | pdp1_plot_pixel(bitmap, state->lightpen_state.x/2, state->lightpen_state.y/2+1, color); |
| 606 | 606 | #endif |
| 607 | | pdp1_draw_circle(bitmap, lightpen_state.x, lightpen_state.y, lightpen_state.radius, color_); |
| 607 | pdp1_draw_circle(bitmap, state->lightpen_state.x, state->lightpen_state.y, state->lightpen_state.radius, color_); |
| 608 | 608 | } |
| 609 | | previous_lightpen_state = lightpen_state; |
| 609 | state->previous_lightpen_state = state->lightpen_state; |
| 610 | 610 | } |
src/mess/video/vectrex.c
| r9667 | r9668 | |
| 9 | 9 | |
| 10 | 10 | |
| 11 | 11 | #define ANALOG_DELAY 7800 |
| 12 | | #define NVECT 10000 |
| 13 | 12 | |
| 14 | 13 | #define INT_PER_CLOCK 550 |
| 15 | 14 | |
| r9667 | r9668 | |
| 36 | 35 | A_Y, |
| 37 | 36 | }; |
| 38 | 37 | |
| 39 | | typedef struct _vectrex_point |
| 40 | | { |
| 41 | | int x; int y; |
| 42 | | rgb_t col; |
| 43 | | int intensity; |
| 44 | | } vectrex_point; |
| 45 | 38 | |
| 46 | | |
| 47 | 39 | /********************************************************************* |
| 48 | 40 | |
| 49 | 41 | Prototypes |
| r9667 | r9668 | |
| 71 | 63 | DEVCB_LINE(vectrex_via_irq), /* IRQ */ |
| 72 | 64 | }; |
| 73 | 65 | |
| 74 | | static int x_center, y_center, x_max, y_max; |
| 75 | | static int x_int, y_int; /* X, Y integrators */ |
| 76 | | static int lightpen_down, pen_x, pen_y; /* Lightpen position */ |
| 77 | | static emu_timer *lp_t; |
| 78 | | static emu_timer *refresh; |
| 79 | | static UINT8 blank; |
| 80 | | static UINT8 ramp; |
| 81 | | static INT8 analog[5]; |
| 82 | | static int vectrex_point_index; |
| 83 | | static int display_start, display_end; |
| 84 | | static vectrex_point vectrex_points[NVECT]; |
| 85 | | static UINT16 via_timer2; |
| 86 | | static attotime vector_start_time; |
| 87 | 66 | |
| 88 | | typedef void (*vector_add_point_fn)(int, int, rgb_t, int); |
| 67 | typedef void (*vector_add_point_fn)(running_machine *, int, int, rgb_t, int); |
| 89 | 68 | vector_add_point_fn vector_add_point_function; |
| 90 | 69 | |
| 91 | 70 | |
| r9667 | r9668 | |
| 97 | 76 | |
| 98 | 77 | static TIMER_CALLBACK(lightpen_trigger) |
| 99 | 78 | { |
| 100 | | if (vectrex_lightpen_port & 1) |
| 79 | vectrex_state *state = machine->driver_data<vectrex_state>(); |
| 80 | if (state->lightpen_port & 1) |
| 101 | 81 | { |
| 102 | 82 | via6522_device *via_0 = machine->device<via6522_device>("via6522_0"); |
| 103 | 83 | via_0->write_ca1(1); |
| 104 | 84 | via_0->write_ca1(0); |
| 105 | 85 | } |
| 106 | 86 | |
| 107 | | if (vectrex_lightpen_port & 2) |
| 87 | if (state->lightpen_port & 2) |
| 108 | 88 | { |
| 109 | 89 | cputag_set_input_line(machine, "maincpu", M6809_FIRQ_LINE, PULSE_LINE); |
| 110 | 90 | } |
| r9667 | r9668 | |
| 138 | 118 | |
| 139 | 119 | WRITE8_HANDLER(vectrex_via_w) |
| 140 | 120 | { |
| 121 | vectrex_state *state = space->machine->driver_data<vectrex_state>(); |
| 141 | 122 | via6522_device *via = space->machine->device<via6522_device>("via6522_0"); |
| 142 | 123 | attotime period; |
| 143 | 124 | |
| 144 | 125 | switch (offset) |
| 145 | 126 | { |
| 146 | 127 | case 8: |
| 147 | | via_timer2 = (via_timer2 & 0xff00) | data; |
| 128 | state->via_timer2 = (state->via_timer2 & 0xff00) | data; |
| 148 | 129 | break; |
| 149 | 130 | |
| 150 | 131 | case 9: |
| 151 | | via_timer2 = (via_timer2 & 0x00ff) | (data << 8); |
| 132 | state->via_timer2 = (state->via_timer2 & 0x00ff) | (data << 8); |
| 152 | 133 | |
| 153 | | period = attotime_mul(ATTOTIME_IN_HZ(cputag_get_clock(space->machine, "maincpu")), via_timer2); |
| 134 | period = attotime_mul(ATTOTIME_IN_HZ(cputag_get_clock(space->machine, "maincpu")), state->via_timer2); |
| 154 | 135 | |
| 155 | | if (vectrex_reset_refresh) |
| 156 | | timer_adjust_periodic(refresh, period, 0, period); |
| 136 | if (state->reset_refresh) |
| 137 | timer_adjust_periodic(state->refresh, period, 0, period); |
| 157 | 138 | else |
| 158 | | timer_adjust_periodic(refresh, |
| 159 | | attotime_min(period, timer_timeleft(refresh)), |
| 139 | timer_adjust_periodic(state->refresh, |
| 140 | attotime_min(period, timer_timeleft(state->refresh)), |
| 160 | 141 | 0, |
| 161 | 142 | period); |
| 162 | 143 | break; |
| r9667 | r9668 | |
| 173 | 154 | |
| 174 | 155 | static TIMER_CALLBACK(vectrex_refresh) |
| 175 | 156 | { |
| 157 | vectrex_state *state = machine->driver_data<vectrex_state>(); |
| 176 | 158 | /* Refresh only marks the range of vectors which will be drawn |
| 177 | 159 | * during the next VIDEO_UPDATE. */ |
| 178 | | display_start = display_end; |
| 179 | | display_end = vectrex_point_index; |
| 160 | state->display_start = state->display_end; |
| 161 | state->display_end = state->point_index; |
| 180 | 162 | } |
| 181 | 163 | |
| 182 | 164 | |
| 183 | 165 | VIDEO_UPDATE(vectrex) |
| 184 | 166 | { |
| 167 | vectrex_state *state = screen->machine->driver_data<vectrex_state>(); |
| 185 | 168 | int i; |
| 186 | 169 | |
| 187 | 170 | vectrex_configuration(screen->machine); |
| 188 | 171 | |
| 189 | 172 | /* start black */ |
| 190 | 173 | vector_add_point(screen->machine, |
| 191 | | vectrex_points[display_start].x, |
| 192 | | vectrex_points[display_start].y, |
| 193 | | vectrex_points[display_start].col, |
| 174 | state->points[state->display_start].x, |
| 175 | state->points[state->display_start].y, |
| 176 | state->points[state->display_start].col, |
| 194 | 177 | 0); |
| 195 | 178 | |
| 196 | | for (i = display_start; i != display_end; i = (i + 1) % NVECT) |
| 179 | for (i = state->display_start; i != state->display_end; i = (i + 1) % NVECT) |
| 197 | 180 | { |
| 198 | 181 | vector_add_point(screen->machine, |
| 199 | | vectrex_points[i].x, |
| 200 | | vectrex_points[i].y, |
| 201 | | vectrex_points[i].col, |
| 202 | | vectrex_points[i].intensity); |
| 182 | state->points[i].x, |
| 183 | state->points[i].y, |
| 184 | state->points[i].col, |
| 185 | state->points[i].intensity); |
| 203 | 186 | } |
| 204 | 187 | |
| 205 | 188 | VIDEO_UPDATE_CALL(vector); |
| r9667 | r9668 | |
| 214 | 197 | |
| 215 | 198 | *********************************************************************/ |
| 216 | 199 | |
| 217 | | void vectrex_add_point(int x, int y, rgb_t color, int intensity) |
| 200 | void vectrex_add_point(running_machine *machine, int x, int y, rgb_t color, int intensity) |
| 218 | 201 | { |
| 202 | vectrex_state *state = machine->driver_data<vectrex_state>(); |
| 219 | 203 | vectrex_point *newpoint; |
| 220 | 204 | |
| 221 | | vectrex_point_index = (vectrex_point_index+1) % NVECT; |
| 222 | | newpoint = &vectrex_points[vectrex_point_index]; |
| 205 | state->point_index = (state->point_index+1) % NVECT; |
| 206 | newpoint = &state->points[state->point_index]; |
| 223 | 207 | |
| 224 | 208 | newpoint->x = x; |
| 225 | 209 | newpoint->y = y; |
| r9667 | r9668 | |
| 228 | 212 | } |
| 229 | 213 | |
| 230 | 214 | |
| 231 | | void vectrex_add_point_stereo(int x, int y, rgb_t color, int intensity) |
| 215 | void vectrex_add_point_stereo(running_machine *machine, int x, int y, rgb_t color, int intensity) |
| 232 | 216 | { |
| 233 | | if (vectrex_imager_status == 2) /* left = 1, right = 2 */ |
| 234 | | vectrex_add_point ((int)(y * M_SQRT1_2)+ x_center, |
| 235 | | (int)(((x_max - x) * M_SQRT1_2)), |
| 217 | vectrex_state *state = machine->driver_data<vectrex_state>(); |
| 218 | if (state->imager_status == 2) /* left = 1, right = 2 */ |
| 219 | vectrex_add_point(machine, (int)(y * M_SQRT1_2)+ state->x_center, |
| 220 | (int)(((state->x_max - x) * M_SQRT1_2)), |
| 236 | 221 | color, |
| 237 | 222 | intensity); |
| 238 | 223 | else |
| 239 | | vectrex_add_point ((int)(y * M_SQRT1_2), |
| 240 | | (int)((x_max - x) * M_SQRT1_2), |
| 224 | vectrex_add_point(machine, (int)(y * M_SQRT1_2), |
| 225 | (int)((state->x_max - x) * M_SQRT1_2), |
| 241 | 226 | color, |
| 242 | 227 | intensity); |
| 243 | 228 | } |
| r9667 | r9668 | |
| 245 | 230 | |
| 246 | 231 | static TIMER_CALLBACK(vectrex_zero_integrators) |
| 247 | 232 | { |
| 248 | | x_int = x_center + (analog[A_ZR] * INT_PER_CLOCK); |
| 249 | | y_int = y_center + (analog[A_ZR] * INT_PER_CLOCK); |
| 250 | | vector_add_point_function (x_int, y_int, vectrex_beam_color, 0); |
| 233 | vectrex_state *state = machine->driver_data<vectrex_state>(); |
| 234 | state->x_int = state->x_center + (state->analog[A_ZR] * INT_PER_CLOCK); |
| 235 | state->y_int = state->y_center + (state->analog[A_ZR] * INT_PER_CLOCK); |
| 236 | vector_add_point_function(machine, state->x_int, state->y_int, state->beam_color, 0); |
| 251 | 237 | } |
| 252 | 238 | |
| 253 | 239 | |
| r9667 | r9668 | |
| 263 | 249 | |
| 264 | 250 | static TIMER_CALLBACK(update_signal) |
| 265 | 251 | { |
| 252 | vectrex_state *state = machine->driver_data<vectrex_state>(); |
| 266 | 253 | int length; |
| 267 | 254 | |
| 268 | | if (!ramp) |
| 255 | if (!state->ramp) |
| 269 | 256 | { |
| 270 | 257 | length = cputag_get_clock(machine, "maincpu") * INT_PER_CLOCK |
| 271 | | * attotime_to_double(attotime_sub(timer_get_time(machine), vector_start_time)); |
| 258 | * attotime_to_double(attotime_sub(timer_get_time(machine), state->vector_start_time)); |
| 272 | 259 | |
| 273 | | x_int += length * (analog[A_X] + analog[A_ZR]); |
| 274 | | y_int += length * (analog[A_Y] + analog[A_ZR]); |
| 260 | state->x_int += length * (state->analog[A_X] + state->analog[A_ZR]); |
| 261 | state->y_int += length * (state->analog[A_Y] + state->analog[A_ZR]); |
| 275 | 262 | |
| 276 | | vector_add_point_function(x_int, y_int, vectrex_beam_color, 2 * analog[A_Z] * blank); |
| 263 | vector_add_point_function(machine, state->x_int, state->y_int, state->beam_color, 2 * state->analog[A_Z] * state->blank); |
| 277 | 264 | } |
| 278 | 265 | else |
| 279 | 266 | { |
| 280 | | if (blank) |
| 281 | | vector_add_point_function(x_int, y_int, vectrex_beam_color, 2 * analog[A_Z]); |
| 267 | if (state->blank) |
| 268 | vector_add_point_function(machine, state->x_int, state->y_int, state->beam_color, 2 * state->analog[A_Z]); |
| 282 | 269 | } |
| 283 | 270 | |
| 284 | | vector_start_time = timer_get_time(machine); |
| 271 | state->vector_start_time = timer_get_time(machine); |
| 285 | 272 | |
| 286 | 273 | if (ptr) |
| 287 | 274 | * (UINT8 *) ptr = param; |
| r9667 | r9668 | |
| 296 | 283 | |
| 297 | 284 | VIDEO_START(vectrex) |
| 298 | 285 | { |
| 286 | vectrex_state *state = machine->driver_data<vectrex_state>(); |
| 299 | 287 | screen_device *screen = screen_first(*machine); |
| 300 | 288 | const rectangle &visarea = screen->visible_area(); |
| 301 | 289 | |
| 302 | | x_center=((visarea.max_x - visarea.min_x) / 2) << 16; |
| 303 | | y_center=((visarea.max_y - visarea.min_y) / 2) << 16; |
| 304 | | x_max = visarea.max_x << 16; |
| 305 | | y_max = visarea.max_y << 16; |
| 290 | state->x_center=((visarea.max_x - visarea.min_x) / 2) << 16; |
| 291 | state->y_center=((visarea.max_y - visarea.min_y) / 2) << 16; |
| 292 | state->x_max = visarea.max_x << 16; |
| 293 | state->y_max = visarea.max_y << 16; |
| 306 | 294 | |
| 307 | | vectrex_imager_freq = 1; |
| 295 | state->imager_freq = 1; |
| 308 | 296 | |
| 309 | 297 | vector_add_point_function = vectrex_add_point; |
| 310 | | vectrex_imager_timer = timer_alloc(machine, vectrex_imager_eye, NULL); |
| 311 | | timer_adjust_periodic(vectrex_imager_timer, |
| 312 | | ATTOTIME_IN_HZ(vectrex_imager_freq), |
| 298 | state->imager_timer = timer_alloc(machine, vectrex_imager_eye, NULL); |
| 299 | timer_adjust_periodic(state->imager_timer, |
| 300 | ATTOTIME_IN_HZ(state->imager_freq), |
| 313 | 301 | 2, |
| 314 | | ATTOTIME_IN_HZ(vectrex_imager_freq)); |
| 302 | ATTOTIME_IN_HZ(state->imager_freq)); |
| 315 | 303 | |
| 316 | | lp_t = timer_alloc(machine, lightpen_trigger, NULL); |
| 304 | state->lp_t = timer_alloc(machine, lightpen_trigger, NULL); |
| 317 | 305 | |
| 318 | | refresh = timer_alloc(machine, vectrex_refresh, NULL); |
| 306 | state->refresh = timer_alloc(machine, vectrex_refresh, NULL); |
| 319 | 307 | |
| 320 | 308 | VIDEO_START_CALL(vector); |
| 321 | 309 | } |
| r9667 | r9668 | |
| 329 | 317 | |
| 330 | 318 | static void vectrex_multiplexer(running_machine *machine, int mux) |
| 331 | 319 | { |
| 320 | vectrex_state *state = machine->driver_data<vectrex_state>(); |
| 332 | 321 | running_device *dac_device = machine->device("dac"); |
| 333 | 322 | |
| 334 | | timer_set(machine, ATTOTIME_IN_NSEC(ANALOG_DELAY), &analog[mux], vectrex_via_out[PORTA], update_signal); |
| 323 | timer_set(machine, ATTOTIME_IN_NSEC(ANALOG_DELAY), &state->analog[mux], state->via_out[PORTA], update_signal); |
| 335 | 324 | |
| 336 | 325 | if (mux == A_AUDIO) |
| 337 | | dac_data_w(dac_device, vectrex_via_out[PORTA]); |
| 326 | dac_data_w(dac_device, state->via_out[PORTA]); |
| 338 | 327 | } |
| 339 | 328 | |
| 340 | 329 | |
| 341 | 330 | static WRITE8_DEVICE_HANDLER(v_via_pb_w) |
| 342 | 331 | { |
| 332 | vectrex_state *state = device->machine->driver_data<vectrex_state>(); |
| 343 | 333 | if (!(data & 0x80)) |
| 344 | 334 | { |
| 345 | 335 | /* RAMP is active */ |
| 346 | | if ((ramp & 0x80)) |
| 336 | if ((state->ramp & 0x80)) |
| 347 | 337 | { |
| 348 | 338 | /* RAMP was inactive before */ |
| 349 | 339 | |
| 350 | | if (lightpen_down) |
| 340 | if (state->lightpen_down) |
| 351 | 341 | { |
| 352 | 342 | /* Simple lin. algebra to check if pen is near |
| 353 | 343 | * the line defined by (A_X,A_Y). |
| r9667 | r9668 | |
| 368 | 358 | * a |
| 369 | 359 | */ |
| 370 | 360 | double a2, b2, ab, d2; |
| 371 | | ab = (pen_x - x_int) * analog[A_X] |
| 372 | | +(pen_y - y_int) * analog[A_Y]; |
| 361 | ab = (state->pen_x - state->x_int) * state->analog[A_X] |
| 362 | +(state->pen_y - state->y_int) * state->analog[A_Y]; |
| 373 | 363 | if (ab > 0) |
| 374 | 364 | { |
| 375 | | a2 = (double)(analog[A_X] * analog[A_X] |
| 376 | | +(double)analog[A_Y] * analog[A_Y]); |
| 377 | | b2 = (double)(pen_x - x_int) * (pen_x - x_int) |
| 378 | | +(double)(pen_y - y_int) * (pen_y - y_int); |
| 365 | a2 = (double)(state->analog[A_X] * state->analog[A_X] |
| 366 | +(double)state->analog[A_Y] * state->analog[A_Y]); |
| 367 | b2 = (double)(state->pen_x - state->x_int) * (state->pen_x - state->x_int) |
| 368 | +(double)(state->pen_y - state->y_int) * (state->pen_y - state->y_int); |
| 379 | 369 | d2 = b2 - ab * ab / a2; |
| 380 | | if (d2 < 2e10 && analog[A_Z] * blank > 0) |
| 381 | | timer_adjust_oneshot(lp_t, double_to_attotime(ab / a2 / (cputag_get_clock(device->machine, "maincpu") * INT_PER_CLOCK)), 0); |
| 370 | if (d2 < 2e10 && state->analog[A_Z] * state->blank > 0) |
| 371 | timer_adjust_oneshot(state->lp_t, double_to_attotime(ab / a2 / (cputag_get_clock(device->machine, "maincpu") * INT_PER_CLOCK)), 0); |
| 382 | 372 | } |
| 383 | 373 | } |
| 384 | 374 | } |
| 385 | 375 | |
| 386 | | if (!(data & 0x1) && (vectrex_via_out[PORTB] & 0x1)) |
| 376 | if (!(data & 0x1) && (state->via_out[PORTB] & 0x1)) |
| 387 | 377 | { |
| 388 | 378 | /* MUX has been enabled */ |
| 389 | 379 | timer_set(device->machine, ATTOTIME_IN_NSEC(ANALOG_DELAY), NULL, 0, update_signal); |
| r9667 | r9668 | |
| 392 | 382 | else |
| 393 | 383 | { |
| 394 | 384 | /* RAMP is inactive */ |
| 395 | | if (!(ramp & 0x80)) |
| 385 | if (!(state->ramp & 0x80)) |
| 396 | 386 | { |
| 397 | 387 | /* Cancel running timer, line already finished */ |
| 398 | | if (lightpen_down) |
| 399 | | timer_adjust_oneshot(lp_t, attotime_never, 0); |
| 388 | if (state->lightpen_down) |
| 389 | timer_adjust_oneshot(state->lp_t, attotime_never, 0); |
| 400 | 390 | } |
| 401 | 391 | } |
| 402 | 392 | |
| r9667 | r9668 | |
| 406 | 396 | running_device *ay8912 = device->machine->device("ay8912"); |
| 407 | 397 | |
| 408 | 398 | if (data & 0x08) /* BC1 (do we select a reg or write it ?) */ |
| 409 | | ay8910_address_w(ay8912, 0, vectrex_via_out[PORTA]); |
| 399 | ay8910_address_w(ay8912, 0, state->via_out[PORTA]); |
| 410 | 400 | else |
| 411 | | ay8910_data_w(ay8912, 0, vectrex_via_out[PORTA]); |
| 401 | ay8910_data_w(ay8912, 0, state->via_out[PORTA]); |
| 412 | 402 | } |
| 413 | 403 | |
| 414 | | if (!(data & 0x1) && (vectrex_via_out[PORTB] & 0x1)) |
| 404 | if (!(data & 0x1) && (state->via_out[PORTB] & 0x1)) |
| 415 | 405 | vectrex_multiplexer (device->machine, (data >> 1) & 0x3); |
| 416 | 406 | |
| 417 | | vectrex_via_out[PORTB] = data; |
| 418 | | timer_set(device->machine, ATTOTIME_IN_NSEC(ANALOG_DELAY), &ramp, data & 0x80, update_signal); |
| 407 | state->via_out[PORTB] = data; |
| 408 | timer_set(device->machine, ATTOTIME_IN_NSEC(ANALOG_DELAY), &state->ramp, data & 0x80, update_signal); |
| 419 | 409 | } |
| 420 | 410 | |
| 421 | 411 | |
| 422 | 412 | static WRITE8_DEVICE_HANDLER(v_via_pa_w) |
| 423 | 413 | { |
| 414 | vectrex_state *state = device->machine->driver_data<vectrex_state>(); |
| 424 | 415 | /* DAC output always goes to Y integrator */ |
| 425 | | vectrex_via_out[PORTA] = data; |
| 426 | | timer_set(device->machine, ATTOTIME_IN_NSEC(ANALOG_DELAY), &analog[A_Y], data, update_signal); |
| 416 | state->via_out[PORTA] = data; |
| 417 | timer_set(device->machine, ATTOTIME_IN_NSEC(ANALOG_DELAY), &state->analog[A_Y], data, update_signal); |
| 427 | 418 | |
| 428 | | if (!(vectrex_via_out[PORTB] & 0x1)) |
| 429 | | vectrex_multiplexer (device->machine, (vectrex_via_out[PORTB] >> 1) & 0x3); |
| 419 | if (!(state->via_out[PORTB] & 0x1)) |
| 420 | vectrex_multiplexer (device->machine, (state->via_out[PORTB] >> 1) & 0x3); |
| 430 | 421 | } |
| 431 | 422 | |
| 432 | 423 | |
| r9667 | r9668 | |
| 439 | 430 | |
| 440 | 431 | static WRITE8_DEVICE_HANDLER(v_via_cb2_w) |
| 441 | 432 | { |
| 433 | vectrex_state *state = device->machine->driver_data<vectrex_state>(); |
| 442 | 434 | int dx, dy; |
| 443 | | static UINT8 cb2 = 0; |
| 444 | 435 | |
| 445 | | if (cb2 != data) |
| 436 | if (state->cb2 != data) |
| 446 | 437 | { |
| 447 | 438 | |
| 448 | 439 | /* Check lightpen */ |
| 449 | | if (vectrex_lightpen_port != 0) |
| 440 | if (state->lightpen_port != 0) |
| 450 | 441 | { |
| 451 | | lightpen_down = input_port_read(device->machine, "LPENCONF") & 0x10; |
| 442 | state->lightpen_down = input_port_read(device->machine, "LPENCONF") & 0x10; |
| 452 | 443 | |
| 453 | | if (lightpen_down) |
| 444 | if (state->lightpen_down) |
| 454 | 445 | { |
| 455 | | pen_x = input_port_read(device->machine, "LPENX") * (x_max / 0xff); |
| 456 | | pen_y = input_port_read(device->machine, "LPENY") * (y_max / 0xff); |
| 446 | state->pen_x = input_port_read(device->machine, "LPENX") * (state->x_max / 0xff); |
| 447 | state->pen_y = input_port_read(device->machine, "LPENY") * (state->y_max / 0xff); |
| 457 | 448 | |
| 458 | | dx = abs(pen_x - x_int); |
| 459 | | dy = abs(pen_y - y_int); |
| 449 | dx = abs(state->pen_x - state->x_int); |
| 450 | dy = abs(state->pen_y - state->y_int); |
| 460 | 451 | if (dx < 500000 && dy < 500000 && data > 0) |
| 461 | 452 | timer_set(device->machine, attotime_zero, NULL, 0, lightpen_trigger); |
| 462 | 453 | } |
| 463 | 454 | } |
| 464 | 455 | |
| 465 | | timer_set(device->machine, attotime_zero, &blank, data, update_signal); |
| 466 | | cb2 = data; |
| 456 | timer_set(device->machine, attotime_zero, &state->blank, data, update_signal); |
| 457 | state->cb2 = data; |
| 467 | 458 | } |
| 468 | 459 | } |
| 469 | 460 | |
| r9667 | r9668 | |
| 492 | 483 | |
| 493 | 484 | VIDEO_START(raaspec) |
| 494 | 485 | { |
| 486 | vectrex_state *state = machine->driver_data<vectrex_state>(); |
| 495 | 487 | screen_device *screen = screen_first(*machine); |
| 496 | 488 | const rectangle &visarea = screen->visible_area(); |
| 497 | 489 | |
| 498 | | x_center=((visarea.max_x - visarea.min_x) / 2) << 16; |
| 499 | | y_center=((visarea.max_y - visarea.min_y) / 2) << 16; |
| 500 | | x_max = visarea.max_x << 16; |
| 501 | | y_max = visarea.max_y << 16; |
| 490 | state->x_center=((visarea.max_x - visarea.min_x) / 2) << 16; |
| 491 | state->y_center=((visarea.max_y - visarea.min_y) / 2) << 16; |
| 492 | state->x_max = visarea.max_x << 16; |
| 493 | state->y_max = visarea.max_y << 16; |
| 502 | 494 | |
| 503 | 495 | vector_add_point_function = vectrex_add_point; |
| 504 | | refresh = timer_alloc(machine, vectrex_refresh, NULL); |
| 496 | state->refresh = timer_alloc(machine, vectrex_refresh, NULL); |
| 505 | 497 | |
| 506 | 498 | VIDEO_START_CALL(vector); |
| 507 | 499 | } |
src/mess/video/odyssey2.c
| r9667 | r9668 | |
| 123 | 123 | { 0x00,0x00,0x00,0x10,0x38,0xFF,0x7E,0x00 } |
| 124 | 124 | }; |
| 125 | 125 | |
| 126 | | static union { |
| 127 | | UINT8 reg[0x100]; |
| 128 | | struct { |
| 129 | | struct { |
| 130 | | UINT8 y,x,color,res; |
| 131 | | } sprites[4]; |
| 132 | | struct { |
| 133 | | UINT8 y,x,ptr,color; |
| 134 | | } foreground[12]; |
| 135 | | struct { |
| 136 | | struct { |
| 137 | | UINT8 y,x,ptr,color; |
| 138 | | } single[4]; |
| 139 | | } quad[4]; |
| 140 | | UINT8 shape[4][8]; |
| 141 | | UINT8 control; |
| 142 | | UINT8 status; |
| 143 | | UINT8 collision; |
| 144 | | UINT8 color; |
| 145 | | UINT8 y; |
| 146 | | UINT8 x; |
| 147 | | UINT8 res; |
| 148 | | UINT8 shift1,shift2,shift3; |
| 149 | | UINT8 sound; |
| 150 | | UINT8 res2[5+0x10]; |
| 151 | | UINT8 hgrid[2][0x10]; |
| 152 | | UINT8 vgrid[0x10]; |
| 153 | | } s; |
| 154 | | } o2_vdc= { { 0 } }; |
| 155 | 126 | |
| 156 | | static UINT32 o2_snd_shift[2]; |
| 157 | | static UINT8 x_beam_pos; |
| 158 | | static UINT8 y_beam_pos; |
| 159 | | static UINT8 control_status; |
| 160 | | static UINT8 collision_status; |
| 161 | | static int iff; |
| 162 | | static emu_timer *i824x_line_timer; |
| 163 | | static emu_timer *i824x_hblank_timer; |
| 164 | | static bitmap_t *tmp_bitmap; |
| 165 | | static int start_vpos; |
| 166 | | static int start_vblank; |
| 167 | | static UINT8 lum; /* Output of P1 bit 7 influences the intensity of the background and grid colours */ |
| 168 | | static UINT16 lfsr; |
| 169 | 127 | |
| 170 | | static sound_stream *odyssey2_sh_channel; |
| 171 | 128 | |
| 172 | | |
| 173 | 129 | PALETTE_INIT( odyssey2 ) |
| 174 | 130 | { |
| 175 | 131 | int i; |
| r9667 | r9668 | |
| 182 | 138 | |
| 183 | 139 | READ8_HANDLER( odyssey2_video_r ) |
| 184 | 140 | { |
| 141 | odyssey2_state *state = space->machine->driver_data<odyssey2_state>(); |
| 185 | 142 | UINT8 data = 0; |
| 186 | 143 | |
| 187 | 144 | switch (offset) |
| 188 | 145 | { |
| 189 | 146 | case 0xa1: |
| 190 | | data = control_status; |
| 191 | | iff = 0; |
| 147 | data = state->control_status; |
| 148 | state->iff = 0; |
| 192 | 149 | cputag_set_input_line(space->machine, "maincpu", 0, CLEAR_LINE); |
| 193 | | control_status &= ~ 0x08; |
| 150 | state->control_status &= ~ 0x08; |
| 194 | 151 | if ( space->machine->primary_screen->hpos() < I824X_START_ACTIVE_SCAN || space->machine->primary_screen->hpos() > I824X_END_ACTIVE_SCAN ) |
| 195 | 152 | { |
| 196 | 153 | data |= 1; |
| r9667 | r9668 | |
| 199 | 156 | break; |
| 200 | 157 | |
| 201 | 158 | case 0xa2: |
| 202 | | data = collision_status; |
| 203 | | collision_status = 0; |
| 159 | data = state->collision_status; |
| 160 | state->collision_status = 0; |
| 204 | 161 | |
| 205 | 162 | break; |
| 206 | 163 | |
| 207 | 164 | case 0xa4: |
| 208 | 165 | |
| 209 | | if ((o2_vdc.s.control & VDC_CONTROL_REG_STROBE_XY)) |
| 210 | | y_beam_pos = space->machine->primary_screen->vpos() - start_vpos; |
| 166 | if ((state->o2_vdc.s.control & VDC_CONTROL_REG_STROBE_XY)) |
| 167 | state->y_beam_pos = space->machine->primary_screen->vpos() - state->start_vpos; |
| 211 | 168 | |
| 212 | | data = y_beam_pos; |
| 169 | data = state->y_beam_pos; |
| 213 | 170 | |
| 214 | 171 | break; |
| 215 | 172 | |
| 216 | 173 | |
| 217 | 174 | case 0xa5: |
| 218 | 175 | |
| 219 | | if ((o2_vdc.s.control & VDC_CONTROL_REG_STROBE_XY)) |
| 176 | if ((state->o2_vdc.s.control & VDC_CONTROL_REG_STROBE_XY)) |
| 220 | 177 | { |
| 221 | | x_beam_pos = space->machine->primary_screen->hpos(); |
| 222 | | if ( x_beam_pos < I824X_START_ACTIVE_SCAN ) |
| 178 | state->x_beam_pos = space->machine->primary_screen->hpos(); |
| 179 | if ( state->x_beam_pos < I824X_START_ACTIVE_SCAN ) |
| 223 | 180 | { |
| 224 | | x_beam_pos = x_beam_pos - I824X_START_ACTIVE_SCAN + I824X_LINE_CLOCKS; |
| 181 | state->x_beam_pos = state->x_beam_pos - I824X_START_ACTIVE_SCAN + I824X_LINE_CLOCKS; |
| 225 | 182 | } |
| 226 | 183 | else |
| 227 | 184 | { |
| 228 | | x_beam_pos = x_beam_pos - I824X_START_ACTIVE_SCAN; |
| 185 | state->x_beam_pos = state->x_beam_pos - I824X_START_ACTIVE_SCAN; |
| 229 | 186 | } |
| 230 | 187 | } |
| 231 | 188 | |
| 232 | | data = x_beam_pos; |
| 189 | data = state->x_beam_pos; |
| 233 | 190 | |
| 234 | 191 | break; |
| 235 | 192 | |
| 236 | 193 | default: |
| 237 | | data = o2_vdc.reg[offset]; |
| 194 | data = state->o2_vdc.reg[offset]; |
| 238 | 195 | } |
| 239 | 196 | |
| 240 | 197 | return data; |
| r9667 | r9668 | |
| 242 | 199 | |
| 243 | 200 | WRITE8_HANDLER( odyssey2_video_w ) |
| 244 | 201 | { |
| 202 | odyssey2_state *state = space->machine->driver_data<odyssey2_state>(); |
| 245 | 203 | /* Update the sound */ |
| 246 | 204 | if( offset >= 0xa7 && offset <= 0xaa ) |
| 247 | | stream_update( odyssey2_sh_channel ); |
| 205 | stream_update( state->sh_channel ); |
| 248 | 206 | |
| 249 | 207 | if (offset == 0xa0) |
| 250 | 208 | { |
| 251 | | if ( o2_vdc.s.control & VDC_CONTROL_REG_STROBE_XY |
| 209 | if ( state->o2_vdc.s.control & VDC_CONTROL_REG_STROBE_XY |
| 252 | 210 | && !(data & VDC_CONTROL_REG_STROBE_XY)) |
| 253 | 211 | { |
| 254 | 212 | /* Toggling strobe bit, tuck away values */ |
| 255 | | x_beam_pos = space->machine->primary_screen->hpos(); |
| 256 | | if ( x_beam_pos < I824X_START_ACTIVE_SCAN ) |
| 213 | state->x_beam_pos = space->machine->primary_screen->hpos(); |
| 214 | if ( state->x_beam_pos < I824X_START_ACTIVE_SCAN ) |
| 257 | 215 | { |
| 258 | | x_beam_pos = x_beam_pos - I824X_START_ACTIVE_SCAN + 228; |
| 216 | state->x_beam_pos = state->x_beam_pos - I824X_START_ACTIVE_SCAN + 228; |
| 259 | 217 | } |
| 260 | 218 | else |
| 261 | 219 | { |
| 262 | | x_beam_pos = x_beam_pos - I824X_START_ACTIVE_SCAN; |
| 220 | state->x_beam_pos = state->x_beam_pos - I824X_START_ACTIVE_SCAN; |
| 263 | 221 | } |
| 264 | 222 | |
| 265 | | y_beam_pos = space->machine->primary_screen->vpos() - start_vpos; |
| 223 | state->y_beam_pos = space->machine->primary_screen->vpos() - state->start_vpos; |
| 266 | 224 | |
| 267 | 225 | /* This is wrong but more games work with it, TODO: Figure |
| 268 | 226 | * out correct change. Maybe update the screen here?? |
| r9667 | r9668 | |
| 274 | 232 | } |
| 275 | 233 | } |
| 276 | 234 | |
| 277 | | o2_vdc.reg[offset] = data; |
| 235 | state->o2_vdc.reg[offset] = data; |
| 278 | 236 | } |
| 279 | 237 | |
| 280 | 238 | WRITE8_HANDLER ( odyssey2_lum_w ) |
| 281 | 239 | { |
| 282 | | lum = data; |
| 240 | odyssey2_state *state = space->machine->driver_data<odyssey2_state>(); |
| 241 | state->lum = data; |
| 283 | 242 | } |
| 284 | 243 | |
| 285 | 244 | READ8_HANDLER( odyssey2_t1_r ) |
| 286 | 245 | { |
| 287 | | if ( space->machine->primary_screen->vpos() > start_vpos && space->machine->primary_screen->vpos() < start_vblank ) |
| 246 | odyssey2_state *state = space->machine->driver_data<odyssey2_state>(); |
| 247 | if ( space->machine->primary_screen->vpos() > state->start_vpos && space->machine->primary_screen->vpos() < state->start_vblank ) |
| 288 | 248 | { |
| 289 | 249 | if ( space->machine->primary_screen->hpos() >= I824X_START_ACTIVE_SCAN && space->machine->primary_screen->hpos() < I824X_END_ACTIVE_SCAN ) |
| 290 | 250 | { |
| r9667 | r9668 | |
| 296 | 256 | |
| 297 | 257 | static TIMER_CALLBACK( i824x_scanline_callback ) |
| 298 | 258 | { |
| 259 | odyssey2_state *state = machine->driver_data<odyssey2_state>(); |
| 299 | 260 | UINT8 collision_map[160]; |
| 300 | 261 | int vpos = machine->primary_screen->vpos(); |
| 301 | 262 | |
| 302 | | if ( vpos < start_vpos ) |
| 263 | if ( vpos < state->start_vpos ) |
| 303 | 264 | return; |
| 304 | 265 | |
| 305 | | if ( vpos == start_vpos ) |
| 266 | if ( vpos == state->start_vpos ) |
| 306 | 267 | { |
| 307 | | control_status &= ~0x08; |
| 268 | state->control_status &= ~0x08; |
| 308 | 269 | } |
| 309 | 270 | |
| 310 | | if ( vpos < start_vblank ) |
| 271 | if ( vpos < state->start_vblank ) |
| 311 | 272 | { |
| 312 | 273 | rectangle rect; |
| 313 | 274 | //int sprite_width[4] = { 8, 8, 8, 8 }; |
| 314 | 275 | int i; |
| 315 | 276 | |
| 316 | | control_status &= ~ 0x01; |
| 277 | state->control_status &= ~ 0x01; |
| 317 | 278 | |
| 318 | 279 | /* Draw a line */ |
| 319 | 280 | rect.min_y = rect.max_y = vpos; |
| 320 | 281 | rect.min_x = I824X_START_ACTIVE_SCAN; |
| 321 | 282 | rect.max_x = I824X_END_ACTIVE_SCAN - 1; |
| 322 | | bitmap_fill( tmp_bitmap, &rect , ( (o2_vdc.s.color >> 3) & 0x7 ) | ( ( lum << 3 ) ^ 0x08 )); |
| 283 | bitmap_fill( state->tmp_bitmap, &rect , ( (state->o2_vdc.s.color >> 3) & 0x7 ) | ( ( state->lum << 3 ) ^ 0x08 )); |
| 323 | 284 | |
| 324 | 285 | /* Clear collision map */ |
| 325 | 286 | memset( collision_map, 0, sizeof( collision_map ) ); |
| 326 | 287 | |
| 327 | 288 | /* Display grid if enabled */ |
| 328 | | if ( o2_vdc.s.control & 0x08 ) |
| 289 | if ( state->o2_vdc.s.control & 0x08 ) |
| 329 | 290 | { |
| 330 | | UINT16 color = ( o2_vdc.s.color & 7 ) | ( ( o2_vdc.s.color >> 3 ) & 0x08 ) | ( ( lum << 3 ) ^ 0x08 ); |
| 291 | UINT16 color = ( state->o2_vdc.s.color & 7 ) | ( ( state->o2_vdc.s.color >> 3 ) & 0x08 ) | ( ( state->lum << 3 ) ^ 0x08 ); |
| 331 | 292 | int x_grid_offset = 8; |
| 332 | 293 | int y_grid_offset = 24; |
| 333 | 294 | int width = 16; |
| 334 | 295 | int height = 24; |
| 335 | | int w = ( o2_vdc.s.control & 0x80 ) ? width : 2; |
| 296 | int w = ( state->o2_vdc.s.control & 0x80 ) ? width : 2; |
| 336 | 297 | int j, k, y; |
| 337 | 298 | |
| 338 | 299 | /* Draw horizontal part of grid */ |
| 339 | 300 | for ( j = 1, y = 0; y < 9; y++, j <<= 1 ) |
| 340 | 301 | { |
| 341 | | if ( y_grid_offset + y * height <= ( vpos - start_vpos ) && ( vpos - start_vpos ) < y_grid_offset + y * height + 3 ) |
| 302 | if ( y_grid_offset + y * height <= ( vpos - state->start_vpos ) && ( vpos - state->start_vpos ) < y_grid_offset + y * height + 3 ) |
| 342 | 303 | { |
| 343 | 304 | for ( i = 0; i < 9; i++ ) |
| 344 | 305 | { |
| 345 | | if ( ( o2_vdc.s.hgrid[0][i] & j ) || ( o2_vdc.s.hgrid[1][i] & ( j >> 8 ) ) ) |
| 306 | if ( ( state->o2_vdc.s.hgrid[0][i] & j ) || ( state->o2_vdc.s.hgrid[1][i] & ( j >> 8 ) ) ) |
| 346 | 307 | { |
| 347 | 308 | for ( k = 0; k < width + 2; k++ ) |
| 348 | 309 | { |
| 349 | 310 | int px = x_grid_offset + i * width + k; |
| 350 | 311 | collision_map[ px ] |= COLLISION_HORIZ_GRID_DOTS; |
| 351 | | *BITMAP_ADDR16( tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + px ) = color; |
| 312 | *BITMAP_ADDR16( state->tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + px ) = color; |
| 352 | 313 | } |
| 353 | 314 | } |
| 354 | 315 | } |
| r9667 | r9668 | |
| 358 | 319 | /* Draw vertical part of grid */ |
| 359 | 320 | for( j = 1, y = 0; y < 8; y++, j <<= 1 ) |
| 360 | 321 | { |
| 361 | | if ( y_grid_offset + y * height <= ( vpos - start_vpos ) && ( vpos - start_vpos ) < y_grid_offset + ( y + 1 ) * height ) |
| 322 | if ( y_grid_offset + y * height <= ( vpos - state->start_vpos ) && ( vpos - state->start_vpos ) < y_grid_offset + ( y + 1 ) * height ) |
| 362 | 323 | { |
| 363 | 324 | for ( i = 0; i < 10; i++ ) |
| 364 | 325 | { |
| 365 | | if ( o2_vdc.s.vgrid[i] & j ) |
| 326 | if ( state->o2_vdc.s.vgrid[i] & j ) |
| 366 | 327 | { |
| 367 | 328 | for ( k = 0; k < w; k++ ) |
| 368 | 329 | { |
| 369 | 330 | int px = x_grid_offset + i * width + k; |
| 370 | 331 | |
| 371 | 332 | /* Check if we collide with an already drawn source object */ |
| 372 | | if ( collision_map[ px ] & o2_vdc.s.collision ) |
| 333 | if ( collision_map[ px ] & state->o2_vdc.s.collision ) |
| 373 | 334 | { |
| 374 | | collision_status |= COLLISION_VERTICAL_GRID; |
| 335 | state->collision_status |= COLLISION_VERTICAL_GRID; |
| 375 | 336 | } |
| 376 | 337 | /* Check if an already drawn object would collide with us */ |
| 377 | | if ( COLLISION_VERTICAL_GRID & o2_vdc.s.collision && collision_map[ px ] ) |
| 338 | if ( COLLISION_VERTICAL_GRID & state->o2_vdc.s.collision && collision_map[ px ] ) |
| 378 | 339 | { |
| 379 | | collision_status |= collision_map[ px ]; |
| 340 | state->collision_status |= collision_map[ px ]; |
| 380 | 341 | } |
| 381 | 342 | collision_map[ px ] |= COLLISION_VERTICAL_GRID; |
| 382 | | *BITMAP_ADDR16( tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + px ) = color; |
| 343 | *BITMAP_ADDR16( state->tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + px ) = color; |
| 383 | 344 | } |
| 384 | 345 | } |
| 385 | 346 | } |
| r9667 | r9668 | |
| 388 | 349 | } |
| 389 | 350 | |
| 390 | 351 | /* Display objects if enabled */ |
| 391 | | if ( o2_vdc.s.control & 0x20 ) |
| 352 | if ( state->o2_vdc.s.control & 0x20 ) |
| 392 | 353 | { |
| 393 | 354 | /* Regular foreground objects */ |
| 394 | | for ( i = 0; i < ARRAY_LENGTH( o2_vdc.s.foreground ); i++ ) |
| 355 | for ( i = 0; i < ARRAY_LENGTH( state->o2_vdc.s.foreground ); i++ ) |
| 395 | 356 | { |
| 396 | | int y = o2_vdc.s.foreground[i].y; |
| 397 | | int height = 8 - ( ( ( y >> 1 ) + o2_vdc.s.foreground[i].ptr ) & 7 ); |
| 357 | int y = state->o2_vdc.s.foreground[i].y; |
| 358 | int height = 8 - ( ( ( y >> 1 ) + state->o2_vdc.s.foreground[i].ptr ) & 7 ); |
| 398 | 359 | |
| 399 | | if ( y <= ( vpos - start_vpos ) && ( vpos - start_vpos ) < y + height * 2 ) |
| 360 | if ( y <= ( vpos - state->start_vpos ) && ( vpos - state->start_vpos ) < y + height * 2 ) |
| 400 | 361 | { |
| 401 | | UINT16 color = 16 + ( ( o2_vdc.s.foreground[i].color & 0x0E ) >> 1 ); |
| 402 | | int offset = ( o2_vdc.s.foreground[i].ptr | ( ( o2_vdc.s.foreground[i].color & 0x01 ) << 8 ) ) + ( y >> 1 ) + ( ( vpos - start_vpos - y ) >> 1 ); |
| 362 | UINT16 color = 16 + ( ( state->o2_vdc.s.foreground[i].color & 0x0E ) >> 1 ); |
| 363 | int offset = ( state->o2_vdc.s.foreground[i].ptr | ( ( state->o2_vdc.s.foreground[i].color & 0x01 ) << 8 ) ) + ( y >> 1 ) + ( ( vpos - state->start_vpos - y ) >> 1 ); |
| 403 | 364 | UINT8 chr = ((char*)o2_shape)[ offset & 0x1FF ]; |
| 404 | | int x = o2_vdc.s.foreground[i].x; |
| 365 | int x = state->o2_vdc.s.foreground[i].x; |
| 405 | 366 | UINT8 m; |
| 406 | 367 | |
| 407 | 368 | for ( m = 0x80; m > 0; m >>= 1, x++ ) |
| r9667 | r9668 | |
| 411 | 372 | if ( x >= 0 && x < 160 ) |
| 412 | 373 | { |
| 413 | 374 | /* Check if we collide with an already drawn source object */ |
| 414 | | if ( collision_map[ x ] & o2_vdc.s.collision ) |
| 375 | if ( collision_map[ x ] & state->o2_vdc.s.collision ) |
| 415 | 376 | { |
| 416 | | collision_status |= COLLISION_CHARACTERS; |
| 377 | state->collision_status |= COLLISION_CHARACTERS; |
| 417 | 378 | } |
| 418 | 379 | /* Check if an already drawn object would collide with us */ |
| 419 | | if ( COLLISION_CHARACTERS & o2_vdc.s.collision && collision_map[ x ] ) |
| 380 | if ( COLLISION_CHARACTERS & state->o2_vdc.s.collision && collision_map[ x ] ) |
| 420 | 381 | { |
| 421 | | collision_status |= collision_map[ x ]; |
| 382 | state->collision_status |= collision_map[ x ]; |
| 422 | 383 | } |
| 423 | 384 | collision_map[ x ] |= COLLISION_CHARACTERS; |
| 424 | | *BITMAP_ADDR16( tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + x ) = color; |
| 385 | *BITMAP_ADDR16( state->tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + x ) = color; |
| 425 | 386 | } |
| 426 | 387 | } |
| 427 | 388 | } |
| r9667 | r9668 | |
| 429 | 390 | } |
| 430 | 391 | |
| 431 | 392 | /* Quad objects */ |
| 432 | | for ( i = 0; i < ARRAY_LENGTH( o2_vdc.s.quad ); i++ ) |
| 393 | for ( i = 0; i < ARRAY_LENGTH( state->o2_vdc.s.quad ); i++ ) |
| 433 | 394 | { |
| 434 | | int y = o2_vdc.s.quad[i].single[0].y; |
| 395 | int y = state->o2_vdc.s.quad[i].single[0].y; |
| 435 | 396 | int height = 8; |
| 436 | 397 | |
| 437 | | if ( y <= ( vpos - start_vpos ) && ( vpos - start_vpos ) < y + height * 2 ) |
| 398 | if ( y <= ( vpos - state->start_vpos ) && ( vpos - state->start_vpos ) < y + height * 2 ) |
| 438 | 399 | { |
| 439 | | int x = o2_vdc.s.quad[i].single[0].x; |
| 400 | int x = state->o2_vdc.s.quad[i].single[0].x; |
| 440 | 401 | int j; |
| 441 | 402 | |
| 442 | | for ( j = 0; j < ARRAY_LENGTH( o2_vdc.s.quad[0].single ); j++, x += 8 ) |
| 403 | for ( j = 0; j < ARRAY_LENGTH( state->o2_vdc.s.quad[0].single ); j++, x += 8 ) |
| 443 | 404 | { |
| 444 | | int char_height = 8 - ( ( ( y >> 1 ) + o2_vdc.s.quad[i].single[j].ptr ) & 7 ); |
| 445 | | if ( y <= ( vpos - start_vpos ) && ( vpos - start_vpos ) < y + char_height * 2 ) |
| 405 | int char_height = 8 - ( ( ( y >> 1 ) + state->o2_vdc.s.quad[i].single[j].ptr ) & 7 ); |
| 406 | if ( y <= ( vpos - state->start_vpos ) && ( vpos - state->start_vpos ) < y + char_height * 2 ) |
| 446 | 407 | { |
| 447 | | UINT16 color = 16 + ( ( o2_vdc.s.quad[i].single[j].color & 0x0E ) >> 1 ); |
| 448 | | int offset = ( o2_vdc.s.quad[i].single[j].ptr | ( ( o2_vdc.s.quad[i].single[j].color & 0x01 ) << 8 ) ) + ( y >> 1 ) + ( ( vpos - start_vpos - y ) >> 1 ); |
| 408 | UINT16 color = 16 + ( ( state->o2_vdc.s.quad[i].single[j].color & 0x0E ) >> 1 ); |
| 409 | int offset = ( state->o2_vdc.s.quad[i].single[j].ptr | ( ( state->o2_vdc.s.quad[i].single[j].color & 0x01 ) << 8 ) ) + ( y >> 1 ) + ( ( vpos - state->start_vpos - y ) >> 1 ); |
| 449 | 410 | UINT8 chr = ((char*)o2_shape)[ offset & 0x1FF ]; |
| 450 | 411 | UINT8 m; |
| 451 | 412 | for ( m = 0x80; m > 0; m >>= 1, x++ ) |
| r9667 | r9668 | |
| 455 | 416 | if ( x >= 0 && x < 160 ) |
| 456 | 417 | { |
| 457 | 418 | /* Check if we collide with an already drawn source object */ |
| 458 | | if ( collision_map[ x ] & o2_vdc.s.collision ) |
| 419 | if ( collision_map[ x ] & state->o2_vdc.s.collision ) |
| 459 | 420 | { |
| 460 | | collision_status |= COLLISION_CHARACTERS; |
| 421 | state->collision_status |= COLLISION_CHARACTERS; |
| 461 | 422 | } |
| 462 | 423 | /* Check if an already drawn object would collide with us */ |
| 463 | | if ( COLLISION_CHARACTERS & o2_vdc.s.collision && collision_map[ x ] ) |
| 424 | if ( COLLISION_CHARACTERS & state->o2_vdc.s.collision && collision_map[ x ] ) |
| 464 | 425 | { |
| 465 | | collision_status |= collision_map[ x ]; |
| 426 | state->collision_status |= collision_map[ x ]; |
| 466 | 427 | } |
| 467 | 428 | collision_map[ x ] |= COLLISION_CHARACTERS; |
| 468 | | *BITMAP_ADDR16( tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + x ) = color; |
| 429 | *BITMAP_ADDR16( state->tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + x ) = color; |
| 469 | 430 | } |
| 470 | 431 | } |
| 471 | 432 | } |
| r9667 | r9668 | |
| 479 | 440 | } |
| 480 | 441 | |
| 481 | 442 | /* Sprites */ |
| 482 | | for ( i = 0; i < ARRAY_LENGTH( o2_vdc.s.sprites ); i++ ) |
| 443 | for ( i = 0; i < ARRAY_LENGTH( state->o2_vdc.s.sprites ); i++ ) |
| 483 | 444 | { |
| 484 | | int y = o2_vdc.s.sprites[i].y; |
| 445 | int y = state->o2_vdc.s.sprites[i].y; |
| 485 | 446 | int height = 8; |
| 486 | | if ( o2_vdc.s.sprites[i].color & 4 ) |
| 447 | if ( state->o2_vdc.s.sprites[i].color & 4 ) |
| 487 | 448 | { |
| 488 | 449 | /* Zoomed sprite */ |
| 489 | 450 | //sprite_width[i] = 16; |
| 490 | | if ( y <= ( vpos - start_vpos ) && ( vpos - start_vpos ) < y + height * 4 ) |
| 451 | if ( y <= ( vpos - state->start_vpos ) && ( vpos - state->start_vpos ) < y + height * 4 ) |
| 491 | 452 | { |
| 492 | | UINT16 color = 16 + ( ( o2_vdc.s.sprites[i].color >> 3 ) & 0x07 ); |
| 493 | | UINT8 chr = o2_vdc.s.shape[i][ ( ( vpos - start_vpos - y ) >> 2 ) ]; |
| 494 | | int x = o2_vdc.s.sprites[i].x; |
| 453 | UINT16 color = 16 + ( ( state->o2_vdc.s.sprites[i].color >> 3 ) & 0x07 ); |
| 454 | UINT8 chr = state->o2_vdc.s.shape[i][ ( ( vpos - state->start_vpos - y ) >> 2 ) ]; |
| 455 | int x = state->o2_vdc.s.sprites[i].x; |
| 495 | 456 | UINT8 m; |
| 496 | 457 | |
| 497 | 458 | for ( m = 0x01; m > 0; m <<= 1, x += 2 ) |
| r9667 | r9668 | |
| 501 | 462 | if ( x >= 0 && x < 160 ) |
| 502 | 463 | { |
| 503 | 464 | /* Check if we collide with an already drawn source object */ |
| 504 | | if ( collision_map[ x ] & o2_vdc.s.collision ) |
| 465 | if ( collision_map[ x ] & state->o2_vdc.s.collision ) |
| 505 | 466 | { |
| 506 | | collision_status |= ( 1 << i ); |
| 467 | state->collision_status |= ( 1 << i ); |
| 507 | 468 | } |
| 508 | 469 | /* Check if an already drawn object would collide with us */ |
| 509 | | if ( ( 1 << i ) & o2_vdc.s.collision && collision_map[ x ] ) |
| 470 | if ( ( 1 << i ) & state->o2_vdc.s.collision && collision_map[ x ] ) |
| 510 | 471 | { |
| 511 | | collision_status |= collision_map[ x ]; |
| 472 | state->collision_status |= collision_map[ x ]; |
| 512 | 473 | } |
| 513 | 474 | collision_map[ x ] |= ( 1 << i ); |
| 514 | | *BITMAP_ADDR16( tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + x ) = color; |
| 475 | *BITMAP_ADDR16( state->tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + x ) = color; |
| 515 | 476 | } |
| 516 | 477 | if ( x >= -1 && x < 159 ) |
| 517 | 478 | { |
| 518 | 479 | /* Check if we collide with an already drawn source object */ |
| 519 | | if ( collision_map[ x ] & o2_vdc.s.collision ) |
| 480 | if ( collision_map[ x ] & state->o2_vdc.s.collision ) |
| 520 | 481 | { |
| 521 | | collision_status |= ( 1 << i ); |
| 482 | state->collision_status |= ( 1 << i ); |
| 522 | 483 | } |
| 523 | 484 | /* Check if an already drawn object would collide with us */ |
| 524 | | if ( ( 1 << i ) & o2_vdc.s.collision && collision_map[ x ] ) |
| 485 | if ( ( 1 << i ) & state->o2_vdc.s.collision && collision_map[ x ] ) |
| 525 | 486 | { |
| 526 | | collision_status |= collision_map[ x ]; |
| 487 | state->collision_status |= collision_map[ x ]; |
| 527 | 488 | } |
| 528 | 489 | collision_map[ x ] |= ( 1 << i ); |
| 529 | | *BITMAP_ADDR16( tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + x + 1 ) = color; |
| 490 | *BITMAP_ADDR16( state->tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + x + 1 ) = color; |
| 530 | 491 | } |
| 531 | 492 | } |
| 532 | 493 | } |
| r9667 | r9668 | |
| 535 | 496 | else |
| 536 | 497 | { |
| 537 | 498 | /* Regular sprite */ |
| 538 | | if ( y <= ( vpos - start_vpos ) && ( vpos - start_vpos ) < y + height * 2 ) |
| 499 | if ( y <= ( vpos - state->start_vpos ) && ( vpos - state->start_vpos ) < y + height * 2 ) |
| 539 | 500 | { |
| 540 | | UINT16 color = 16 + ( ( o2_vdc.s.sprites[i].color >> 3 ) & 0x07 ); |
| 541 | | UINT8 chr = o2_vdc.s.shape[i][ ( ( vpos - start_vpos - y ) >> 1 ) ]; |
| 542 | | int x = o2_vdc.s.sprites[i].x; |
| 501 | UINT16 color = 16 + ( ( state->o2_vdc.s.sprites[i].color >> 3 ) & 0x07 ); |
| 502 | UINT8 chr = state->o2_vdc.s.shape[i][ ( ( vpos - state->start_vpos - y ) >> 1 ) ]; |
| 503 | int x = state->o2_vdc.s.sprites[i].x; |
| 543 | 504 | UINT8 m; |
| 544 | 505 | |
| 545 | 506 | for ( m = 0x01; m > 0; m <<= 1, x++ ) |
| r9667 | r9668 | |
| 549 | 510 | if ( x >= 0 && x < 160 ) |
| 550 | 511 | { |
| 551 | 512 | /* Check if we collide with an already drawn source object */ |
| 552 | | if ( collision_map[ x ] & o2_vdc.s.collision ) |
| 513 | if ( collision_map[ x ] & state->o2_vdc.s.collision ) |
| 553 | 514 | { |
| 554 | | collision_status |= ( 1 << i ); |
| 515 | state->collision_status |= ( 1 << i ); |
| 555 | 516 | } |
| 556 | 517 | /* Check if an already drawn object would collide with us */ |
| 557 | | if ( ( 1 << i ) & o2_vdc.s.collision && collision_map[ x ] ) |
| 518 | if ( ( 1 << i ) & state->o2_vdc.s.collision && collision_map[ x ] ) |
| 558 | 519 | { |
| 559 | | collision_status |= collision_map[ x ]; |
| 520 | state->collision_status |= collision_map[ x ]; |
| 560 | 521 | } |
| 561 | 522 | collision_map[ x ] |= ( 1 << i ); |
| 562 | | *BITMAP_ADDR16( tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + x ) = color; |
| 523 | *BITMAP_ADDR16( state->tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + x ) = color; |
| 563 | 524 | } |
| 564 | 525 | } |
| 565 | 526 | } |
| r9667 | r9668 | |
| 570 | 531 | } |
| 571 | 532 | |
| 572 | 533 | /* Check for start of VBlank */ |
| 573 | | if ( vpos == start_vblank ) |
| 534 | if ( vpos == state->start_vblank ) |
| 574 | 535 | { |
| 575 | | control_status |= 0x08; |
| 576 | | if ( ! iff ) |
| 536 | state->control_status |= 0x08; |
| 537 | if ( ! state->iff ) |
| 577 | 538 | { |
| 578 | 539 | cputag_set_input_line(machine, "maincpu", 0, ASSERT_LINE); |
| 579 | | iff = 1; |
| 540 | state->iff = 1; |
| 580 | 541 | } |
| 581 | 542 | } |
| 582 | 543 | } |
| 583 | 544 | |
| 584 | 545 | static TIMER_CALLBACK( i824x_hblank_callback ) |
| 585 | 546 | { |
| 547 | odyssey2_state *state = machine->driver_data<odyssey2_state>(); |
| 586 | 548 | int vpos = machine->primary_screen->vpos(); |
| 587 | 549 | |
| 588 | | if ( vpos < start_vpos - 1 ) |
| 550 | if ( vpos < state->start_vpos - 1 ) |
| 589 | 551 | return; |
| 590 | 552 | |
| 591 | | if ( vpos < start_vblank - 1 ) |
| 553 | if ( vpos < state->start_vblank - 1 ) |
| 592 | 554 | { |
| 593 | | control_status |= 0x01; |
| 555 | state->control_status |= 0x01; |
| 594 | 556 | } |
| 595 | 557 | } |
| 596 | 558 | |
| r9667 | r9668 | |
| 602 | 564 | |
| 603 | 565 | VIDEO_START( odyssey2 ) |
| 604 | 566 | { |
| 567 | odyssey2_state *state = machine->driver_data<odyssey2_state>(); |
| 605 | 568 | screen_device *screen = screen_first(*machine); |
| 606 | 569 | int width = screen->width(); |
| 607 | 570 | int height = screen->height(); |
| 608 | 571 | |
| 609 | | memset(o2_vdc.reg, 0, 0x100); |
| 572 | memset(state->o2_vdc.reg, 0, 0x100); |
| 610 | 573 | |
| 611 | | o2_snd_shift[0] = o2_snd_shift[1] = 0; |
| 612 | | x_beam_pos = 0; |
| 613 | | y_beam_pos = 0; |
| 614 | | control_status = 0; |
| 615 | | collision_status = 0; |
| 616 | | iff = 0; |
| 617 | | start_vpos = 0; |
| 618 | | start_vblank = 0; |
| 619 | | lum = 0; |
| 620 | | lfsr = 0; |
| 574 | state->o2_snd_shift[0] = state->o2_snd_shift[1] = 0; |
| 575 | state->x_beam_pos = 0; |
| 576 | state->y_beam_pos = 0; |
| 577 | state->control_status = 0; |
| 578 | state->collision_status = 0; |
| 579 | state->iff = 0; |
| 580 | state->start_vpos = 0; |
| 581 | state->start_vblank = 0; |
| 582 | state->lum = 0; |
| 583 | state->lfsr = 0; |
| 621 | 584 | |
| 622 | | o2_snd_shift[0] = machine->sample_rate / 983; |
| 623 | | o2_snd_shift[1] = machine->sample_rate / 3933; |
| 585 | state->o2_snd_shift[0] = machine->sample_rate / 983; |
| 586 | state->o2_snd_shift[1] = machine->sample_rate / 3933; |
| 624 | 587 | |
| 625 | | start_vpos = I824X_START_Y; |
| 626 | | start_vblank = I824X_START_Y + I824X_SCREEN_HEIGHT; |
| 627 | | control_status = 0; |
| 628 | | iff = 0; |
| 588 | state->start_vpos = I824X_START_Y; |
| 589 | state->start_vblank = I824X_START_Y + I824X_SCREEN_HEIGHT; |
| 590 | state->control_status = 0; |
| 591 | state->iff = 0; |
| 629 | 592 | |
| 630 | | tmp_bitmap = auto_bitmap_alloc( machine, width, height, screen->format() ); |
| 593 | state->tmp_bitmap = auto_bitmap_alloc( machine, width, height, screen->format() ); |
| 631 | 594 | |
| 632 | | i824x_line_timer = timer_alloc(machine, i824x_scanline_callback, NULL ); |
| 633 | | timer_adjust_periodic( i824x_line_timer, machine->primary_screen->time_until_pos(1, I824X_START_ACTIVE_SCAN ), 0, machine->primary_screen->scan_period() ); |
| 595 | state->i824x_line_timer = timer_alloc(machine, i824x_scanline_callback, NULL ); |
| 596 | timer_adjust_periodic( state->i824x_line_timer, machine->primary_screen->time_until_pos(1, I824X_START_ACTIVE_SCAN ), 0, machine->primary_screen->scan_period() ); |
| 634 | 597 | |
| 635 | | i824x_hblank_timer = timer_alloc(machine, i824x_hblank_callback, NULL ); |
| 636 | | timer_adjust_periodic( i824x_hblank_timer, machine->primary_screen->time_until_pos(1, I824X_END_ACTIVE_SCAN + 18 ), 0, machine->primary_screen->scan_period() ); |
| 598 | state->i824x_hblank_timer = timer_alloc(machine, i824x_hblank_callback, NULL ); |
| 599 | timer_adjust_periodic( state->i824x_hblank_timer, machine->primary_screen->time_until_pos(1, I824X_END_ACTIVE_SCAN + 18 ), 0, machine->primary_screen->scan_period() ); |
| 637 | 600 | } |
| 638 | 601 | |
| 639 | 602 | /*************************************************************************** |
| r9667 | r9668 | |
| 644 | 607 | |
| 645 | 608 | VIDEO_UPDATE( odyssey2 ) |
| 646 | 609 | { |
| 647 | | copybitmap( bitmap, tmp_bitmap, 0, 0, 0, 0, cliprect ); |
| 610 | odyssey2_state *state = screen->machine->driver_data<odyssey2_state>(); |
| 611 | copybitmap( bitmap, state->tmp_bitmap, 0, 0, 0, 0, cliprect ); |
| 648 | 612 | |
| 649 | 613 | return 0; |
| 650 | 614 | } |
| 651 | 615 | |
| 652 | 616 | static DEVICE_START( odyssey2_sound ) |
| 653 | 617 | { |
| 654 | | odyssey2_sh_channel = stream_create(device, 0, 1, device->clock()/(I824X_LINE_CLOCKS*4), 0, odyssey2_sh_update ); |
| 618 | odyssey2_state *state = device->machine->driver_data<odyssey2_state>(); |
| 619 | state->sh_channel = stream_create(device, 0, 1, device->clock()/(I824X_LINE_CLOCKS*4), 0, odyssey2_sh_update ); |
| 655 | 620 | } |
| 656 | 621 | |
| 657 | 622 | |
| r9667 | r9668 | |
| 670 | 635 | |
| 671 | 636 | STREAM_UPDATE( odyssey2_sh_update ) |
| 672 | 637 | { |
| 673 | | static UINT32 signal; |
| 674 | | static UINT16 count = 0; |
| 638 | odyssey2_state *state = device->machine->driver_data<odyssey2_state>(); |
| 639 | UINT32 signal; |
| 675 | 640 | int ii; |
| 676 | 641 | int period; |
| 677 | 642 | stream_sample_t *buffer = outputs[0]; |
| 678 | 643 | |
| 679 | 644 | /* Generate the signal */ |
| 680 | | signal = o2_vdc.s.shift3 | (o2_vdc.s.shift2 << 8) | (o2_vdc.s.shift1 << 16); |
| 645 | signal = state->o2_vdc.s.shift3 | (state->o2_vdc.s.shift2 << 8) | (state->o2_vdc.s.shift1 << 16); |
| 681 | 646 | |
| 682 | | if( o2_vdc.s.sound & 0x80 ) /* Sound is enabled */ |
| 647 | if( state->o2_vdc.s.sound & 0x80 ) /* Sound is enabled */ |
| 683 | 648 | { |
| 684 | 649 | for( ii = 0; ii < samples; ii++, buffer++ ) |
| 685 | 650 | { |
| 686 | 651 | *buffer = 0; |
| 687 | 652 | *buffer = signal & 0x1; |
| 688 | | period = (o2_vdc.s.sound & 0x20) ? 1 : 4; |
| 689 | | if( ++count >= period ) |
| 653 | period = (state->o2_vdc.s.sound & 0x20) ? 1 : 4; |
| 654 | if( ++state->sh_count >= period ) |
| 690 | 655 | { |
| 691 | | count = 0; |
| 656 | state->sh_count = 0; |
| 692 | 657 | signal >>= 1; |
| 693 | 658 | /* Loop sound */ |
| 694 | | if( o2_vdc.s.sound & 0x40 ) |
| 659 | if( state->o2_vdc.s.sound & 0x40 ) |
| 695 | 660 | { |
| 696 | 661 | signal |= *buffer << 23; |
| 697 | 662 | } |
| 698 | 663 | /* Noise poly is : L=16 W=2 10000000000100001 */ |
| 699 | | lfsr = ( lfsr >> 1 ) | ( ( ( lfsr & 0x01 ) ^ ( ( lfsr & 0x800 ) >> 11 ) ) << 15 ); |
| 700 | | if ( ! lfsr ) |
| 664 | state->lfsr = ( state->lfsr >> 1 ) | ( ( ( state->lfsr & 0x01 ) ^ ( ( state->lfsr & 0x800 ) >> 11 ) ) << 15 ); |
| 665 | if ( ! state->lfsr ) |
| 701 | 666 | { |
| 702 | | lfsr = 0xFFFF; |
| 667 | state->lfsr = 0xFFFF; |
| 703 | 668 | } |
| 704 | 669 | /* Check if noise should be applied */ |
| 705 | | if ( o2_vdc.s.sound & 0x10 ) |
| 670 | if ( state->o2_vdc.s.sound & 0x10 ) |
| 706 | 671 | { |
| 707 | | *buffer |= ( lfsr & 0x01 ); |
| 672 | *buffer |= ( state->lfsr & 0x01 ); |
| 708 | 673 | } |
| 709 | | o2_vdc.s.shift3 = signal & 0xFF; |
| 710 | | o2_vdc.s.shift2 = ( signal >> 8 ) & 0xFF; |
| 711 | | o2_vdc.s.shift1 = ( signal >> 16 ) & 0xFF; |
| 674 | state->o2_vdc.s.shift3 = signal & 0xFF; |
| 675 | state->o2_vdc.s.shift2 = ( signal >> 8 ) & 0xFF; |
| 676 | state->o2_vdc.s.shift1 = ( signal >> 16 ) & 0xFF; |
| 712 | 677 | } |
| 713 | 678 | |
| 714 | 679 | /* Throw an interrupt if enabled */ |
| 715 | | if( o2_vdc.s.control & 0x4 ) |
| 680 | if( state->o2_vdc.s.control & 0x4 ) |
| 716 | 681 | { |
| 717 | 682 | cputag_set_input_line(device->machine, "maincpu", 1, HOLD_LINE); /* Is this right? */ |
| 718 | 683 | } |
| 719 | 684 | |
| 720 | 685 | /* Adjust volume */ |
| 721 | | *buffer *= o2_vdc.s.sound & 0xf; |
| 686 | *buffer *= state->o2_vdc.s.sound & 0xf; |
| 722 | 687 | /* Pump the volume up */ |
| 723 | 688 | *buffer <<= 10; |
| 724 | 689 | } |
| r9667 | r9668 | |
| 736 | 701 | */ |
| 737 | 702 | |
| 738 | 703 | #ifdef UNUSED_FUNCTION |
| 739 | | static struct { |
| 740 | | UINT8 X; |
| 741 | | UINT8 Y; |
| 742 | | UINT8 Y0; |
| 743 | | UINT8 R; |
| 744 | | UINT8 M; |
| 745 | | UINT8 TA; |
| 746 | | UINT8 TB; |
| 747 | | UINT8 busy; |
| 748 | | UINT8 ram[1024]; |
| 749 | | } ef9341; |
| 750 | | |
| 751 | | INLINE UINT16 ef9341_get_c_addr( void ) |
| 704 | INLINE UINT16 ef9341_get_c_addr( odyssey2_state *state ) |
| 752 | 705 | { |
| 753 | | if ( ( ef9341.Y & 0x0C ) == 0x0C ) |
| 706 | if ( ( state->ef9341.Y & 0x0C ) == 0x0C ) |
| 754 | 707 | { |
| 755 | | return 0x318 | ( ( ef9341.X & 0x38 ) << 2 ) | ( ef9341.X & 0x07 ); |
| 708 | return 0x318 | ( ( state->ef9341.X & 0x38 ) << 2 ) | ( state->ef9341.X & 0x07 ); |
| 756 | 709 | } |
| 757 | | if ( ef9341.X & 0x20 ) |
| 710 | if ( state->ef9341.X & 0x20 ) |
| 758 | 711 | { |
| 759 | | return 0x300 | ( ( ef9341.Y & 0x07 ) << 5 ) | ( ef9341.Y & 0x18 ) | ( ef9341.X & 0x07 ); |
| 712 | return 0x300 | ( ( state->ef9341.Y & 0x07 ) << 5 ) | ( state->ef9341.Y & 0x18 ) | ( state->ef9341.X & 0x07 ); |
| 760 | 713 | } |
| 761 | | return ( ef9341.Y << 5 ) | ef9341.X; |
| 714 | return ( state->ef9341.Y << 5 ) | state->ef9341.X; |
| 762 | 715 | } |
| 763 | 716 | |
| 764 | | INLINE void ef9341_inc_c( void ) |
| 717 | INLINE void ef9341_inc_c( odyssey2_state *state ) |
| 765 | 718 | { |
| 766 | | ef9341.X++; |
| 767 | | if ( ef9341.X >= 40 ) |
| 719 | state->ef9341.X++; |
| 720 | if ( state->ef9341.X >= 40 ) |
| 768 | 721 | { |
| 769 | | ef9341.Y = ( ef9341.Y + 1 ) % 24; |
| 722 | state->ef9341.Y = ( state->ef9341.Y + 1 ) % 24; |
| 770 | 723 | } |
| 771 | 724 | } |
| 772 | 725 | |
| 773 | | void odyssey2_ef9341_w( int command, int b, UINT8 data ) |
| 726 | void odyssey2_ef9341_w( running_machine *machine, int command, int b, UINT8 data ) |
| 774 | 727 | { |
| 728 | odyssey2_state *state = machine->driver_data<odyssey2_state>(); |
| 775 | 729 | logerror("ef9341 %s write, t%s, data %02X\n", command ? "command" : "data", b ? "B" : "A", data ); |
| 776 | 730 | |
| 777 | 731 | if ( command ) |
| 778 | 732 | { |
| 779 | 733 | if ( b ) |
| 780 | 734 | { |
| 781 | | ef9341.TB = data; |
| 782 | | ef9341.busy = 0x80; |
| 783 | | switch( ef9341.TB & 0xE0 ) |
| 735 | state->ef9341.TB = data; |
| 736 | state->ef9341.busy = 0x80; |
| 737 | switch( state->ef9341.TB & 0xE0 ) |
| 784 | 738 | { |
| 785 | 739 | case 0x00: /* Begin row */ |
| 786 | | ef9341.X = 0; |
| 787 | | ef9341.Y = ef9341.TA & 0x1F; |
| 740 | state->ef9341.X = 0; |
| 741 | state->ef9341.Y = state->ef9341.TA & 0x1F; |
| 788 | 742 | break; |
| 789 | 743 | case 0x20: /* Load Y */ |
| 790 | | ef9341.Y = ef9341.TA & 0x1F; |
| 744 | state->ef9341.Y = state->ef9341.TA & 0x1F; |
| 791 | 745 | break; |
| 792 | 746 | case 0x40: /* Load X */ |
| 793 | | ef9341.X = ef9341.TA & 0x3F; |
| 747 | state->ef9341.X = state->ef9341.TA & 0x3F; |
| 794 | 748 | break; |
| 795 | 749 | case 0x60: /* INC C */ |
| 796 | | ef9341_inc_c(); |
| 750 | ef9341_inc_c(state); |
| 797 | 751 | break; |
| 798 | 752 | case 0x80: /* Load M */ |
| 799 | | ef9341.M = ef9341.TA; |
| 753 | state->ef9341.M = state->ef9341.TA; |
| 800 | 754 | break; |
| 801 | 755 | case 0xA0: /* Load R */ |
| 802 | | ef9341.R = ef9341.TA; |
| 756 | state->ef9341.R = state->ef9341.TA; |
| 803 | 757 | break; |
| 804 | 758 | case 0xC0: /* Load Y0 */ |
| 805 | | ef9341.Y0 = ef9341.TA & 0x3F; |
| 759 | state->ef9341.Y0 = state->ef9341.TA & 0x3F; |
| 806 | 760 | break; |
| 807 | 761 | } |
| 808 | | ef9341.busy = 0; |
| 762 | state->ef9341.busy = 0; |
| 809 | 763 | } |
| 810 | 764 | else |
| 811 | 765 | { |
| 812 | | ef9341.TA = data; |
| 766 | state->ef9341.TA = data; |
| 813 | 767 | } |
| 814 | 768 | } |
| 815 | 769 | else |
| 816 | 770 | { |
| 817 | 771 | if ( b ) |
| 818 | 772 | { |
| 819 | | ef9341.TB = data; |
| 820 | | ef9341.busy = 0x80; |
| 821 | | switch ( ef9341.M & 0xE0 ) |
| 773 | state->ef9341.TB = data; |
| 774 | state->ef9341.busy = 0x80; |
| 775 | switch ( state->ef9341.M & 0xE0 ) |
| 822 | 776 | { |
| 823 | 777 | case 0x00: /* Write */ |
| 824 | | ef9341.ram[ ef9341_get_c_addr() ] = ef9341.TB; |
| 825 | | ef9341_inc_c(); |
| 778 | state->ef9341.ram[ ef9341_get_c_addr(state) ] = state->ef9341.TB; |
| 779 | ef9341_inc_c(state); |
| 826 | 780 | break; |
| 827 | 781 | case 0x20: /* Read */ |
| 828 | | logerror("ef9341 unimplemented data action %02X\n", ef9341.M & 0xE0 ); |
| 829 | | ef9341_inc_c(); |
| 782 | logerror("ef9341 unimplemented data action %02X\n", state->ef9341.M & 0xE0 ); |
| 783 | ef9341_inc_c(state); |
| 830 | 784 | break; |
| 831 | 785 | case 0x40: /* Write without increment */ |
| 832 | 786 | case 0x60: /* Read without increment */ |
| 833 | 787 | case 0x80: /* Write slice */ |
| 834 | 788 | case 0xA0: /* Read slice */ |
| 835 | | logerror("ef9341 unimplemented data action %02X\n", ef9341.M & 0xE0 ); |
| 789 | logerror("ef9341 unimplemented data action %02X\n", state->ef9341.M & 0xE0 ); |
| 836 | 790 | break; |
| 837 | 791 | } |
| 838 | | ef9341.busy = 0; |
| 792 | state->ef9341.busy = 0; |
| 839 | 793 | } |
| 840 | 794 | else |
| 841 | 795 | { |
| 842 | | ef9341.TA = data; |
| 796 | state->ef9341.TA = data; |
| 843 | 797 | } |
| 844 | 798 | } |
| 845 | 799 | } |
| 846 | 800 | |
| 847 | | UINT8 odyssey2_ef9341_r( int command, int b ) |
| 801 | UINT8 odyssey2_ef9341_r( running_machine *machine, int command, int b ) |
| 848 | 802 | { |
| 803 | odyssey2_state *state = machine->driver_data<odyssey2_state>(); |
| 849 | 804 | UINT8 data = 0xFF; |
| 850 | 805 | |
| 851 | 806 | logerror("ef9341 %s read, t%s\n", command ? "command" : "data", b ? "B" : "A" ); |
| r9667 | r9668 | |
| 857 | 812 | } |
| 858 | 813 | else |
| 859 | 814 | { |
| 860 | | data = ef9341.busy; |
| 815 | data = state->ef9341.busy; |
| 861 | 816 | } |
| 862 | 817 | } |
| 863 | 818 | else |
| 864 | 819 | { |
| 865 | 820 | if ( b ) |
| 866 | 821 | { |
| 867 | | data = ef9341.TB; |
| 868 | | ef9341.busy = 0x80; |
| 822 | data = state->ef9341.TB; |
| 823 | state->ef9341.busy = 0x80; |
| 869 | 824 | } |
| 870 | 825 | else |
| 871 | 826 | { |
| 872 | | data = ef9341.TA; |
| 827 | data = state->ef9341.TA; |
| 873 | 828 | } |
| 874 | 829 | } |
| 875 | 830 | return data; |
src/mess/drivers/mz2500.c
| r9667 | r9668 | |
| 59 | 59 | #include "formats/flopimg.h" |
| 60 | 60 | #include "formats/basicdsk.h" |
| 61 | 61 | |
| 62 | |
| 63 | class mz2500_state : public driver_device |
| 64 | { |
| 65 | public: |
| 66 | mz2500_state(running_machine &machine, const driver_device_config_base &config) |
| 67 | : driver_device(machine, config) { } |
| 68 | |
| 69 | UINT8 bank_val[8]; |
| 70 | UINT8 bank_addr; |
| 71 | UINT8 irq_sel; |
| 72 | UINT8 irq_vector[4]; |
| 73 | UINT8 irq_mask[4]; |
| 74 | UINT8 kanji_bank; |
| 75 | UINT8 dic_bank; |
| 76 | UINT8 fdc_reverse; |
| 77 | UINT8 key_mux; |
| 78 | UINT8 monitor_type; |
| 79 | UINT8 text_reg[0x100]; |
| 80 | UINT8 text_reg_index; |
| 81 | UINT8 text_col_size; |
| 82 | UINT8 text_font_reg; |
| 83 | UINT8 pal_select; |
| 84 | UINT16 cg_vs; |
| 85 | UINT16 cg_ve; |
| 86 | UINT16 cg_hs; |
| 87 | UINT16 cg_he; |
| 88 | INT16 tv_vs; |
| 89 | INT16 tv_ve; |
| 90 | INT16 tv_hs; |
| 91 | INT16 tv_he; |
| 92 | UINT8 cg_latch[4]; |
| 93 | UINT8 cg_reg_index; |
| 94 | UINT8 cg_reg[0x20]; |
| 95 | UINT8 clut16[0x10]; |
| 96 | UINT16 clut256[0x100]; |
| 97 | UINT8 cg_mask; |
| 98 | int scr_x_size; |
| 99 | int scr_y_size; |
| 100 | UINT8 cg_clear_flag; |
| 101 | UINT32 rom_index; |
| 102 | UINT8 hrom_index; |
| 103 | UINT8 lrom_index; |
| 104 | struct { UINT8 r,g,b; } pal[16]; |
| 105 | UINT8 joy_mode; |
| 106 | UINT16 kanji_index; |
| 107 | UINT32 emm_offset; |
| 108 | UINT8 old_portc; |
| 109 | UINT8 prev_col_val; |
| 110 | UINT8 pio_latchb; |
| 111 | UINT8 ym_porta; |
| 112 | }; |
| 113 | |
| 114 | |
| 62 | 115 | /* machine stuff */ |
| 63 | | static UINT8 bank_val[8],bank_addr; |
| 64 | | static UINT8 irq_sel,irq_vector[4],irq_mask[4]; |
| 65 | | static UINT8 kanji_bank,dic_bank; |
| 66 | | static UINT8 fdc_reverse; |
| 67 | | static UINT8 key_mux; |
| 68 | | static UINT8 monitor_type; |
| 69 | 116 | |
| 70 | 117 | #define WRAM_RESET 0 |
| 71 | 118 | #define IPL_RESET 1 |
| 72 | 119 | |
| 73 | | static void mz2500_reset(UINT8 type); |
| 120 | static void mz2500_reset(mz2500_state *state, UINT8 type); |
| 74 | 121 | static const UINT8 bank_reset_val[2][8] = |
| 75 | 122 | { |
| 76 | 123 | { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 }, |
| r9667 | r9668 | |
| 78 | 125 | }; |
| 79 | 126 | |
| 80 | 127 | /* video stuff*/ |
| 81 | | static UINT8 text_reg[0x100], text_reg_index; |
| 82 | | static UINT8 text_col_size, text_font_reg; |
| 83 | | static UINT8 pal_select; |
| 84 | | static UINT16 cg_vs,cg_ve,cg_hs,cg_he; //CG window parameters |
| 85 | | static INT16 tv_vs,tv_ve,tv_hs,tv_he; //TV window parameters |
| 86 | | static UINT8 cg_latch[4]; |
| 87 | | static UINT8 cg_reg_index; |
| 88 | | static UINT8 cg_reg[0x20]; |
| 89 | | static UINT8 clut16[0x10]; |
| 90 | | static UINT16 clut256[0x100]; |
| 91 | | static UINT8 cg_mask; |
| 92 | | static int scr_x_size,scr_y_size; |
| 93 | | static UINT8 cg_clear_flag; |
| 94 | 128 | |
| 95 | 129 | static VIDEO_START( mz2500 ) |
| 96 | 130 | { |
| r9667 | r9668 | |
| 132 | 166 | |
| 133 | 167 | static void draw_80x25(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect,UINT16 map_addr) |
| 134 | 168 | { |
| 169 | mz2500_state *state = machine->driver_data<mz2500_state>(); |
| 135 | 170 | UINT8 *vram = memory_region(machine, "maincpu"); |
| 136 | 171 | int x,y,count,xi,yi; |
| 137 | 172 | UINT8 *gfx_data; |
| r9667 | r9668 | |
| 141 | 176 | |
| 142 | 177 | count = (map_addr & 0x7ff); |
| 143 | 178 | |
| 144 | | y_step = (text_font_reg) ? 1 : 2; |
| 145 | | y_height = (text_reg[0] & 0x10) ? 10 : 8; |
| 146 | | s_y = text_reg[9] & 0xf; |
| 179 | y_step = (state->text_font_reg) ? 1 : 2; |
| 180 | y_height = (state->text_reg[0] & 0x10) ? 10 : 8; |
| 181 | s_y = state->text_reg[9] & 0xf; |
| 147 | 182 | |
| 148 | 183 | for (y=0;y<26*y_step;y+=y_step) |
| 149 | 184 | { |
| r9667 | r9668 | |
| 190 | 225 | res_y = y*y_height+yi-s_y; |
| 191 | 226 | |
| 192 | 227 | /* check TV window boundaries */ |
| 193 | | if(res_x < tv_hs || res_x >= tv_he || res_y < tv_vs || res_y >= tv_ve) |
| 228 | if(res_x < state->tv_hs || res_x >= state->tv_he || res_y < state->tv_vs || res_y >= state->tv_ve) |
| 194 | 229 | continue; |
| 195 | 230 | |
| 196 | 231 | if(gfx_sel & 0x8) |
| r9667 | r9668 | |
| 209 | 244 | if(pen) |
| 210 | 245 | { |
| 211 | 246 | if((res_y) >= 0 && (res_y) < 200*y_step) |
| 212 | | mz2500_draw_pixel(machine,bitmap,res_x,res_y,pen+(pal_select ? 0x00 : 0x10),0,0); |
| 247 | mz2500_draw_pixel(machine,bitmap,res_x,res_y,pen+(state->pal_select ? 0x00 : 0x10),0,0); |
| 213 | 248 | } |
| 214 | 249 | } |
| 215 | 250 | } |
| r9667 | r9668 | |
| 222 | 257 | |
| 223 | 258 | static void draw_40x25(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect,int plane,UINT16 map_addr) |
| 224 | 259 | { |
| 260 | mz2500_state *state = machine->driver_data<mz2500_state>(); |
| 225 | 261 | UINT8 *vram = memory_region(machine, "maincpu"); |
| 226 | 262 | int x,y,count,xi,yi; |
| 227 | 263 | UINT8 *gfx_data; |
| r9667 | r9668 | |
| 231 | 267 | |
| 232 | 268 | count = (((plane * 0x400) + map_addr) & 0x7ff); |
| 233 | 269 | |
| 234 | | y_step = (text_font_reg) ? 1 : 2; |
| 235 | | y_height = (text_reg[0] & 0x10) ? 10 : 8; |
| 236 | | s_y = text_reg[9] & 0xf; |
| 270 | y_step = (state->text_font_reg) ? 1 : 2; |
| 271 | y_height = (state->text_reg[0] & 0x10) ? 10 : 8; |
| 272 | s_y = state->text_reg[9] & 0xf; |
| 237 | 273 | |
| 238 | 274 | for (y=0;y<26*y_step;y+=y_step) |
| 239 | 275 | { |
| r9667 | r9668 | |
| 280 | 316 | res_y = y*y_height+yi-s_y; |
| 281 | 317 | |
| 282 | 318 | /* check TV window boundaries */ |
| 283 | | if(res_x < tv_hs || res_x >= tv_he || res_y < tv_vs || res_y >= tv_ve) |
| 319 | if(res_x < state->tv_hs || res_x >= state->tv_he || res_y < state->tv_vs || res_y >= state->tv_ve) |
| 284 | 320 | continue; |
| 285 | 321 | |
| 286 | 322 | if(gfx_sel & 0x8) |
| r9667 | r9668 | |
| 299 | 335 | if(pen) |
| 300 | 336 | { |
| 301 | 337 | if((res_y) >= 0 && (res_y) < 200*y_step) |
| 302 | | mz2500_draw_pixel(machine,bitmap,res_x,res_y,pen+(pal_select ? 0x00 : 0x10),scr_x_size == 640,0); |
| 338 | mz2500_draw_pixel(machine,bitmap,res_x,res_y,pen+(state->pal_select ? 0x00 : 0x10),state->scr_x_size == 640,0); |
| 303 | 339 | } |
| 304 | 340 | } |
| 305 | 341 | } |
| r9667 | r9668 | |
| 312 | 348 | |
| 313 | 349 | static void draw_cg4_screen(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect,int pri) |
| 314 | 350 | { |
| 351 | //mz2500_state *state = machine->driver_data<mz2500_state>(); |
| 315 | 352 | UINT32 count; |
| 316 | 353 | UINT8 *vram = memory_region(machine, "maincpu"); |
| 317 | 354 | UINT8 pen,pen_bit[2]; |
| r9667 | r9668 | |
| 330 | 367 | res_y = y; |
| 331 | 368 | |
| 332 | 369 | /* check window boundaries */ |
| 333 | | //if(res_x < cg_hs || res_x >= cg_he || res_y < cg_vs || res_y >= cg_ve) |
| 370 | //if(res_x < state->cg_hs || res_x >= state->cg_he || res_y < state->cg_vs || res_y >= state->cg_ve) |
| 334 | 371 | // continue; |
| 335 | 372 | |
| 336 | 373 | /* TODO: very preliminary, just Yukar K2 uses this so far*/ |
| r9667 | r9668 | |
| 342 | 379 | pen |= pen_bit[pen_i]; |
| 343 | 380 | |
| 344 | 381 | { |
| 345 | | //if(pri == ((clut256[pen] & 0x100) >> 8)) |
| 382 | //if(pri == ((state->clut256[pen] & 0x100) >> 8)) |
| 346 | 383 | mz2500_draw_pixel(machine,bitmap,res_x,res_y,pen,0,0); |
| 347 | 384 | } |
| 348 | 385 | } |
| r9667 | r9668 | |
| 353 | 390 | |
| 354 | 391 | static void draw_cg16_screen(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect,int plane,int x_size,int pri) |
| 355 | 392 | { |
| 393 | mz2500_state *state = machine->driver_data<mz2500_state>(); |
| 356 | 394 | UINT32 count; |
| 357 | 395 | UINT8 *vram = memory_region(machine, "maincpu"); |
| 358 | 396 | UINT8 pen,pen_bit[4]; |
| r9667 | r9668 | |
| 366 | 404 | |
| 367 | 405 | base_mask = (x_size == 640) ? 0x3f : 0x1f; |
| 368 | 406 | |
| 369 | | count = (cg_reg[0x10]) | ((cg_reg[0x11] & base_mask) << 8); |
| 370 | | wa_reg = (cg_reg[0x12]) | ((cg_reg[0x13] & base_mask) << 8); |
| 407 | count = (state->cg_reg[0x10]) | ((state->cg_reg[0x11] & base_mask) << 8); |
| 408 | wa_reg = (state->cg_reg[0x12]) | ((state->cg_reg[0x13] & base_mask) << 8); |
| 371 | 409 | /* TODO: layer 2 scrolling */ |
| 372 | | s_x = (cg_reg[0x0f] & 0xf); |
| 373 | | cg_interlace = text_font_reg ? 1 : 2; |
| 374 | | pen_mask = (cg_reg[0x18] >> ((plane & 1) * 4)) & 0x0f; |
| 410 | s_x = (state->cg_reg[0x0f] & 0xf); |
| 411 | cg_interlace = state->text_font_reg ? 1 : 2; |
| 412 | pen_mask = (state->cg_reg[0x18] >> ((plane & 1) * 4)) & 0x0f; |
| 375 | 413 | |
| 376 | | // popmessage("%d %d %d %d",cg_hs,cg_he,cg_vs,cg_ve); |
| 414 | // popmessage("%d %d %d %d",state->cg_hs,state->cg_he,state->cg_vs,state->cg_ve); |
| 377 | 415 | |
| 378 | 416 | for(y=0;y<200;y++) |
| 379 | 417 | { |
| r9667 | r9668 | |
| 385 | 423 | res_y = y; |
| 386 | 424 | |
| 387 | 425 | /* check window boundaries */ |
| 388 | | if(res_x < cg_hs || res_x >= cg_he || res_y < cg_vs || res_y >= cg_ve) |
| 426 | if(res_x < state->cg_hs || res_x >= state->cg_he || res_y < state->cg_vs || res_y >= state->cg_ve) |
| 389 | 427 | continue; |
| 390 | 428 | |
| 391 | 429 | pen_bit[0] = (vram[count+0x40000+((plane & 1) * 0x2000)+(((plane & 2)>>1) * 0x10000)]>>(xi)) & 1 ? (pen_mask & 0x01) : 0; //B |
| r9667 | r9668 | |
| 397 | 435 | for(pen_i=0;pen_i<4;pen_i++) |
| 398 | 436 | pen |= pen_bit[pen_i]; |
| 399 | 437 | |
| 400 | | if(pri == ((clut16[pen] & 0x10) >> 4) && clut16[pen] != 0x00 && pen_mask) //correct? |
| 401 | | mz2500_draw_pixel(machine,bitmap,res_x,res_y,(clut16[pen] & 0x0f)+0x10,(x_size == 320 && scr_x_size == 640),cg_interlace == 2); |
| 438 | if(pri == ((state->clut16[pen] & 0x10) >> 4) && state->clut16[pen] != 0x00 && pen_mask) //correct? |
| 439 | mz2500_draw_pixel(machine,bitmap,res_x,res_y,(state->clut16[pen] & 0x0f)+0x10,(x_size == 320 && state->scr_x_size == 640),cg_interlace == 2); |
| 402 | 440 | } |
| 403 | 441 | count++; |
| 404 | 442 | count&=((base_mask<<8) | 0xff); |
| r9667 | r9668 | |
| 410 | 448 | |
| 411 | 449 | static void draw_cg256_screen(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect,int plane,int pri) |
| 412 | 450 | { |
| 451 | mz2500_state *state = machine->driver_data<mz2500_state>(); |
| 413 | 452 | UINT32 count; |
| 414 | 453 | UINT8 *vram = memory_region(machine, "maincpu"); |
| 415 | 454 | UINT8 pen,pen_bit[8]; |
| r9667 | r9668 | |
| 422 | 461 | |
| 423 | 462 | base_mask = 0x3f; //no x_size == 640 |
| 424 | 463 | |
| 425 | | count = (cg_reg[0x10]) | ((cg_reg[0x11] & base_mask) << 8); |
| 426 | | wa_reg = (cg_reg[0x12]) | ((cg_reg[0x13] & base_mask) << 8); |
| 464 | count = (state->cg_reg[0x10]) | ((state->cg_reg[0x11] & base_mask) << 8); |
| 465 | wa_reg = (state->cg_reg[0x12]) | ((state->cg_reg[0x13] & base_mask) << 8); |
| 427 | 466 | /* TODO: layer 2 scrolling */ |
| 428 | | s_x = (cg_reg[0x0f] & 0xf); |
| 429 | | cg_interlace = text_font_reg ? 1 : 2; |
| 467 | s_x = (state->cg_reg[0x0f] & 0xf); |
| 468 | cg_interlace = state->text_font_reg ? 1 : 2; |
| 430 | 469 | |
| 431 | 470 | for(y=0;y<200;y++) |
| 432 | 471 | { |
| r9667 | r9668 | |
| 438 | 477 | res_y = y; |
| 439 | 478 | |
| 440 | 479 | /* check window boundaries */ |
| 441 | | if(res_x < cg_hs || res_x >= cg_he || res_y < cg_vs || res_y >= cg_ve) |
| 480 | if(res_x < state->cg_hs || res_x >= state->cg_he || res_y < state->cg_vs || res_y >= state->cg_ve) |
| 442 | 481 | continue; |
| 443 | 482 | |
| 444 | | pen_bit[0] = (vram[count + 0x40000 + (((plane & 2)>>1) * 0x10000) + 0x2000]>>(xi)) & 1 ? (cg_reg[0x18] & 0x10) : 0; // B1 |
| 445 | | pen_bit[1] = (vram[count + 0x40000 + (((plane & 2)>>1) * 0x10000) + 0x0000]>>(xi)) & 1 ? (cg_reg[0x18] & 0x01) : 0; // B0 |
| 446 | | pen_bit[2] = (vram[count + 0x40000 + (((plane & 2)>>1) * 0x10000) + 0x6000]>>(xi)) & 1 ? (cg_reg[0x18] & 0x20) : 0; // R1 |
| 447 | | pen_bit[3] = (vram[count + 0x40000 + (((plane & 2)>>1) * 0x10000) + 0x4000]>>(xi)) & 1 ? (cg_reg[0x18] & 0x02) : 0; // R0 |
| 448 | | pen_bit[4] = (vram[count + 0x40000 + (((plane & 2)>>1) * 0x10000) + 0xa000]>>(xi)) & 1 ? (cg_reg[0x18] & 0x40) : 0; // G1 |
| 449 | | pen_bit[5] = (vram[count + 0x40000 + (((plane & 2)>>1) * 0x10000) + 0x8000]>>(xi)) & 1 ? (cg_reg[0x18] & 0x04) : 0; // G0 |
| 450 | | pen_bit[6] = (vram[count + 0x40000 + (((plane & 2)>>1) * 0x10000) + 0xe000]>>(xi)) & 1 ? (cg_reg[0x18] & 0x80) : 0; // I1 |
| 451 | | pen_bit[7] = (vram[count + 0x40000 + (((plane & 2)>>1) * 0x10000) + 0xc000]>>(xi)) & 1 ? (cg_reg[0x18] & 0x08) : 0; // I0 |
| 483 | pen_bit[0] = (vram[count + 0x40000 + (((plane & 2)>>1) * 0x10000) + 0x2000]>>(xi)) & 1 ? (state->cg_reg[0x18] & 0x10) : 0; // B1 |
| 484 | pen_bit[1] = (vram[count + 0x40000 + (((plane & 2)>>1) * 0x10000) + 0x0000]>>(xi)) & 1 ? (state->cg_reg[0x18] & 0x01) : 0; // B0 |
| 485 | pen_bit[2] = (vram[count + 0x40000 + (((plane & 2)>>1) * 0x10000) + 0x6000]>>(xi)) & 1 ? (state->cg_reg[0x18] & 0x20) : 0; // R1 |
| 486 | pen_bit[3] = (vram[count + 0x40000 + (((plane & 2)>>1) * 0x10000) + 0x4000]>>(xi)) & 1 ? (state->cg_reg[0x18] & 0x02) : 0; // R0 |
| 487 | pen_bit[4] = (vram[count + 0x40000 + (((plane & 2)>>1) * 0x10000) + 0xa000]>>(xi)) & 1 ? (state->cg_reg[0x18] & 0x40) : 0; // G1 |
| 488 | pen_bit[5] = (vram[count + 0x40000 + (((plane & 2)>>1) * 0x10000) + 0x8000]>>(xi)) & 1 ? (state->cg_reg[0x18] & 0x04) : 0; // G0 |
| 489 | pen_bit[6] = (vram[count + 0x40000 + (((plane & 2)>>1) * 0x10000) + 0xe000]>>(xi)) & 1 ? (state->cg_reg[0x18] & 0x80) : 0; // I1 |
| 490 | pen_bit[7] = (vram[count + 0x40000 + (((plane & 2)>>1) * 0x10000) + 0xc000]>>(xi)) & 1 ? (state->cg_reg[0x18] & 0x08) : 0; // I0 |
| 452 | 491 | |
| 453 | 492 | pen = 0; |
| 454 | 493 | for(pen_i=0;pen_i<8;pen_i++) |
| 455 | 494 | pen |= pen_bit[pen_i]; |
| 456 | 495 | |
| 457 | | if(pri == ((clut256[pen] & 0x100) >> 8)) |
| 458 | | mz2500_draw_pixel(machine,bitmap,res_x,res_y,(clut256[pen] & 0xff)+0x100,scr_x_size == 640,cg_interlace == 2); |
| 496 | if(pri == ((state->clut256[pen] & 0x100) >> 8)) |
| 497 | mz2500_draw_pixel(machine,bitmap,res_x,res_y,(state->clut256[pen] & 0xff)+0x100,state->scr_x_size == 640,cg_interlace == 2); |
| 459 | 498 | } |
| 460 | 499 | count++; |
| 461 | 500 | count&=((base_mask<<8) | 0xff); |
| r9667 | r9668 | |
| 467 | 506 | |
| 468 | 507 | static void draw_tv_screen(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect) |
| 469 | 508 | { |
| 509 | mz2500_state *state = machine->driver_data<mz2500_state>(); |
| 470 | 510 | UINT16 base_addr; |
| 471 | 511 | |
| 472 | | base_addr = text_reg[1] | ((text_reg[2] & 0x7) << 8); |
| 512 | base_addr = state->text_reg[1] | ((state->text_reg[2] & 0x7) << 8); |
| 473 | 513 | |
| 474 | | // popmessage("%02x",clut16[0]); |
| 475 | | // popmessage("%d %d %d %d",tv_hs,(tv_he),tv_vs,(tv_ve)); |
| 514 | // popmessage("%02x",state->clut16[0]); |
| 515 | // popmessage("%d %d %d %d",state->tv_hs,(state->tv_he),state->tv_vs,(state->tv_ve)); |
| 476 | 516 | |
| 477 | | if(text_col_size) |
| 517 | if(state->text_col_size) |
| 478 | 518 | draw_80x25(machine,bitmap,cliprect,base_addr); |
| 479 | 519 | else |
| 480 | 520 | { |
| 481 | 521 | int tv_mode; |
| 482 | 522 | |
| 483 | | tv_mode = text_reg[0] >> 2; |
| 523 | tv_mode = state->text_reg[0] >> 2; |
| 484 | 524 | |
| 485 | 525 | switch(tv_mode & 3) |
| 486 | 526 | { |
| r9667 | r9668 | |
| 497 | 537 | draw_40x25(machine,bitmap,cliprect,1,base_addr); |
| 498 | 538 | draw_40x25(machine,bitmap,cliprect,0,base_addr); |
| 499 | 539 | break; |
| 500 | | //default: popmessage("%02x %02x %02x",tv_mode & 3,text_reg[1],text_reg[2]); break; |
| 540 | //default: popmessage("%02x %02x %02x",tv_mode & 3,state->text_reg[1],state->text_reg[2]); break; |
| 501 | 541 | } |
| 502 | 542 | } |
| 503 | 543 | } |
| 504 | 544 | |
| 505 | 545 | static void draw_cg_screen(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect,int pri) |
| 506 | 546 | { |
| 507 | | //popmessage("%02x %02x",cg_reg[0x0e],cg_reg[0x18]); |
| 547 | mz2500_state *state = machine->driver_data<mz2500_state>(); |
| 548 | //popmessage("%02x %02x",state->cg_reg[0x0e],state->cg_reg[0x18]); |
| 508 | 549 | |
| 509 | | switch(cg_reg[0x0e]) |
| 550 | switch(state->cg_reg[0x0e]) |
| 510 | 551 | { |
| 511 | 552 | case 0x00: |
| 512 | 553 | break; |
| r9667 | r9668 | |
| 531 | 572 | draw_cg16_screen(machine,bitmap,cliprect,2,640,pri); |
| 532 | 573 | break; |
| 533 | 574 | default: |
| 534 | | popmessage("Unsupported CG mode %02x, contact MESS dev",cg_reg[0x0e]); |
| 575 | popmessage("Unsupported CG mode %02x, contact MESS dev",state->cg_reg[0x0e]); |
| 535 | 576 | break; |
| 536 | 577 | } |
| 537 | 578 | } |
| 538 | 579 | |
| 539 | 580 | static VIDEO_UPDATE( mz2500 ) |
| 540 | 581 | { |
| 582 | //mz2500_state *state = screen->machine->driver_data<mz2500_state>(); |
| 541 | 583 | bitmap_fill(bitmap, cliprect, screen->machine->pens[0]); //TODO: correct? |
| 542 | 584 | |
| 543 | 585 | draw_cg_screen(screen->machine,bitmap,cliprect,0); |
| 544 | 586 | draw_tv_screen(screen->machine,bitmap,cliprect); |
| 545 | 587 | draw_cg_screen(screen->machine,bitmap,cliprect,1); |
| 546 | | // popmessage("%02x (%02x %02x) (%02x %02x) (%02x %02x) (%02x %02x)",cg_reg[0x0f],cg_reg[0x10],cg_reg[0x11],cg_reg[0x12],cg_reg[0x13],cg_reg[0x14],cg_reg[0x15],cg_reg[0x16],cg_reg[0x17]); |
| 547 | | // popmessage("%02x",text_reg[0x0f]); |
| 588 | // popmessage("%02x (%02x %02x) (%02x %02x) (%02x %02x) (%02x %02x)",state->cg_reg[0x0f],state->cg_reg[0x10],state->cg_reg[0x11],state->cg_reg[0x12],state->cg_reg[0x13],state->cg_reg[0x14],state->cg_reg[0x15],state->cg_reg[0x16],state->cg_reg[0x17]); |
| 589 | // popmessage("%02x",state->text_reg[0x0f]); |
| 548 | 590 | |
| 549 | 591 | |
| 550 | 592 | return 0; |
| r9667 | r9668 | |
| 552 | 594 | |
| 553 | 595 | static void mz2500_reconfigure_screen(running_machine *machine) |
| 554 | 596 | { |
| 597 | mz2500_state *state = machine->driver_data<mz2500_state>(); |
| 555 | 598 | rectangle visarea; |
| 556 | 599 | |
| 557 | | if((cg_reg[0x0e] & 0x1f) == 0x17 || (cg_reg[0x0e] & 0x1f) == 0x03 || text_col_size) |
| 558 | | scr_x_size = 640; |
| 600 | if((state->cg_reg[0x0e] & 0x1f) == 0x17 || (state->cg_reg[0x0e] & 0x1f) == 0x03 || state->text_col_size) |
| 601 | state->scr_x_size = 640; |
| 559 | 602 | else |
| 560 | | scr_x_size = 320; |
| 603 | state->scr_x_size = 320; |
| 561 | 604 | |
| 562 | | if((cg_reg[0x0e] & 0x1f) == 0x03) |
| 563 | | scr_y_size = 400; |
| 605 | if((state->cg_reg[0x0e] & 0x1f) == 0x03) |
| 606 | state->scr_y_size = 400; |
| 564 | 607 | else |
| 565 | | scr_y_size = 200 * ((text_font_reg) ? 1 : 2); |
| 608 | state->scr_y_size = 200 * ((state->text_font_reg) ? 1 : 2); |
| 566 | 609 | |
| 567 | 610 | visarea.min_x = 0; |
| 568 | 611 | visarea.min_y = 0; |
| 569 | | visarea.max_x = scr_x_size - 1; |
| 570 | | visarea.max_y = scr_y_size - 1; |
| 612 | visarea.max_x = state->scr_x_size - 1; |
| 613 | visarea.max_y = state->scr_y_size - 1; |
| 571 | 614 | |
| 572 | | //popmessage("%d %d %d %d %02x",vs,ve,hs,he,cg_reg[0x0e]); |
| 615 | //popmessage("%d %d %d %d %02x",vs,ve,hs,he,state->cg_reg[0x0e]); |
| 573 | 616 | |
| 574 | 617 | machine->primary_screen->configure(720, 480, visarea, machine->primary_screen->frame_period().attoseconds); |
| 575 | 618 | |
| 576 | 619 | /* calculate CG window parameters here */ |
| 577 | | cg_vs = (cg_reg[0x08]) | ((cg_reg[0x09]<<8) & 1); |
| 578 | | cg_ve = (cg_reg[0x0a]) | ((cg_reg[0x0b]<<8) & 1); |
| 579 | | cg_hs = ((cg_reg[0x0c] & 0x7f)*8); |
| 580 | | cg_he = ((cg_reg[0x0d] & 0x7f)*8); |
| 620 | state->cg_vs = (state->cg_reg[0x08]) | ((state->cg_reg[0x09]<<8) & 1); |
| 621 | state->cg_ve = (state->cg_reg[0x0a]) | ((state->cg_reg[0x0b]<<8) & 1); |
| 622 | state->cg_hs = ((state->cg_reg[0x0c] & 0x7f)*8); |
| 623 | state->cg_he = ((state->cg_reg[0x0d] & 0x7f)*8); |
| 581 | 624 | |
| 582 | | if(scr_x_size == 320) |
| 625 | if(state->scr_x_size == 320) |
| 583 | 626 | { |
| 584 | | cg_hs /= 2; |
| 585 | | cg_he /= 2; |
| 627 | state->cg_hs /= 2; |
| 628 | state->cg_he /= 2; |
| 586 | 629 | } |
| 587 | 630 | |
| 588 | 631 | /* calculate TV window parameters here */ |
| 589 | 632 | { |
| 590 | 633 | int x_offs,y_offs; |
| 591 | 634 | |
| 592 | | monitor_type = ((text_reg[0x0f] & 0x08) >> 3); |
| 635 | state->monitor_type = ((state->text_reg[0x0f] & 0x08) >> 3); |
| 593 | 636 | |
| 594 | | switch((monitor_type|text_col_size<<1) & 3) |
| 637 | switch((state->monitor_type|state->text_col_size<<1) & 3) |
| 595 | 638 | { |
| 596 | 639 | default: |
| 597 | 640 | case 0: x_offs = 64; break; |
| r9667 | r9668 | |
| 599 | 642 | case 2: x_offs = 72; break; |
| 600 | 643 | case 3: x_offs = 88; break; |
| 601 | 644 | } |
| 602 | | //printf("%d %d %d\n",x_offs,(text_reg[7] & 0x7f) * 8,(text_reg[8] & 0x7f)* 8); |
| 645 | //printf("%d %d %d\n",x_offs,(state->text_reg[7] & 0x7f) * 8,(state->text_reg[8] & 0x7f)* 8); |
| 603 | 646 | |
| 604 | | y_offs = (monitor_type) ? 76 : 34; |
| 647 | y_offs = (state->monitor_type) ? 76 : 34; |
| 605 | 648 | |
| 606 | | tv_hs = ((text_reg[7] & 0x7f)*8) - x_offs; |
| 607 | | tv_he = ((text_reg[8] & 0x7f)*8) - x_offs; |
| 608 | | tv_vs = (text_reg[3]*2) - y_offs; |
| 609 | | tv_ve = (text_reg[5]*2) - y_offs; |
| 649 | state->tv_hs = ((state->text_reg[7] & 0x7f)*8) - x_offs; |
| 650 | state->tv_he = ((state->text_reg[8] & 0x7f)*8) - x_offs; |
| 651 | state->tv_vs = (state->text_reg[3]*2) - y_offs; |
| 652 | state->tv_ve = (state->text_reg[5]*2) - y_offs; |
| 610 | 653 | |
| 611 | | if(scr_x_size == 320) |
| 654 | if(state->scr_x_size == 320) |
| 612 | 655 | { |
| 613 | | tv_hs /= 2; |
| 614 | | tv_he /= 2; |
| 656 | state->tv_hs /= 2; |
| 657 | state->tv_he /= 2; |
| 615 | 658 | } |
| 616 | 659 | |
| 617 | | if(scr_y_size == 200) |
| 660 | if(state->scr_y_size == 200) |
| 618 | 661 | { |
| 619 | | tv_vs /= 2; |
| 620 | | tv_ve /= 2; |
| 662 | state->tv_vs /= 2; |
| 663 | state->tv_ve /= 2; |
| 621 | 664 | } |
| 622 | 665 | } |
| 623 | 666 | } |
| 624 | 667 | |
| 625 | | static UINT8 mz2500_cg_latch_compare(void) |
| 668 | static UINT8 mz2500_cg_latch_compare(mz2500_state *state) |
| 626 | 669 | { |
| 627 | | UINT8 compare_val = cg_reg[0x07] & 0xf; |
| 670 | UINT8 compare_val = state->cg_reg[0x07] & 0xf; |
| 628 | 671 | UINT8 pix_val; |
| 629 | 672 | UINT8 res; |
| 630 | 673 | UINT16 i; |
| r9667 | r9668 | |
| 632 | 675 | |
| 633 | 676 | for(i=1;i<0x100;i<<=1) |
| 634 | 677 | { |
| 635 | | pix_val = ((cg_latch[0] & i) ? 1 : 0) | ((cg_latch[1] & i) ? 2 : 0) | ((cg_latch[2] & i) ? 4 : 0) | ((cg_latch[3] & i) ? 8 : 0); |
| 678 | pix_val = ((state->cg_latch[0] & i) ? 1 : 0) | ((state->cg_latch[1] & i) ? 2 : 0) | ((state->cg_latch[2] & i) ? 4 : 0) | ((state->cg_latch[3] & i) ? 8 : 0); |
| 636 | 679 | if(pix_val == compare_val) |
| 637 | 680 | res|=i; |
| 638 | 681 | } |
| r9667 | r9668 | |
| 642 | 685 | |
| 643 | 686 | static UINT8 mz2500_ram_read(running_machine *machine, UINT16 offset, UINT8 bank_num) |
| 644 | 687 | { |
| 688 | mz2500_state *state = machine->driver_data<mz2500_state>(); |
| 645 | 689 | UINT8 *ram = memory_region(machine, "maincpu"); |
| 646 | | UINT8 cur_bank = bank_val[bank_num]; |
| 690 | UINT8 cur_bank = state->bank_val[bank_num]; |
| 647 | 691 | |
| 648 | 692 | switch(cur_bank) |
| 649 | 693 | { |
| r9667 | r9668 | |
| 653 | 697 | case 0x33: |
| 654 | 698 | { |
| 655 | 699 | // READ MODIFY WRITE |
| 656 | | if(cg_reg[0x0e] == 0x3) |
| 700 | if(state->cg_reg[0x0e] == 0x3) |
| 657 | 701 | { |
| 658 | 702 | // ... |
| 659 | 703 | } |
| 660 | 704 | else |
| 661 | 705 | { |
| 662 | 706 | int plane; |
| 663 | | cg_latch[0] = ram[offset+((cur_bank & 3)*0x2000)+0x40000]; //B |
| 664 | | cg_latch[1] = ram[offset+((cur_bank & 3)*0x2000)+0x44000]; //R |
| 665 | | cg_latch[2] = ram[offset+((cur_bank & 3)*0x2000)+0x48000]; //G |
| 666 | | cg_latch[3] = ram[offset+((cur_bank & 3)*0x2000)+0x4c000]; //I |
| 667 | | plane = cg_reg[0x07] & 3; |
| 707 | state->cg_latch[0] = ram[offset+((cur_bank & 3)*0x2000)+0x40000]; //B |
| 708 | state->cg_latch[1] = ram[offset+((cur_bank & 3)*0x2000)+0x44000]; //R |
| 709 | state->cg_latch[2] = ram[offset+((cur_bank & 3)*0x2000)+0x48000]; //G |
| 710 | state->cg_latch[3] = ram[offset+((cur_bank & 3)*0x2000)+0x4c000]; //I |
| 711 | plane = state->cg_reg[0x07] & 3; |
| 668 | 712 | |
| 669 | | if(cg_reg[0x07] & 0x10) |
| 670 | | return mz2500_cg_latch_compare(); |
| 713 | if(state->cg_reg[0x07] & 0x10) |
| 714 | return mz2500_cg_latch_compare(state); |
| 671 | 715 | else |
| 672 | | return cg_latch[plane]; |
| 716 | return state->cg_latch[plane]; |
| 673 | 717 | } |
| 674 | 718 | } |
| 675 | 719 | break; |
| 676 | 720 | case 0x39: |
| 677 | 721 | { |
| 678 | | if(kanji_bank & 0x80) //kanji ROM |
| 722 | if(state->kanji_bank & 0x80) //kanji ROM |
| 679 | 723 | { |
| 680 | 724 | UINT8 *knj_rom = memory_region(machine, "kanji"); |
| 681 | 725 | |
| 682 | | return knj_rom[(offset & 0x7ff)+((kanji_bank & 0x7f)*0x800)]; |
| 726 | return knj_rom[(offset & 0x7ff)+((state->kanji_bank & 0x7f)*0x800)]; |
| 683 | 727 | } |
| 684 | 728 | else //PCG RAM |
| 685 | 729 | { |
| r9667 | r9668 | |
| 693 | 737 | { |
| 694 | 738 | UINT8 *dic_rom = memory_region(machine, "dictionary"); |
| 695 | 739 | |
| 696 | | return dic_rom[(offset & 0x1fff) + ((dic_bank & 0x1f)*0x2000)]; |
| 740 | return dic_rom[(offset & 0x1fff) + ((state->dic_bank & 0x1f)*0x2000)]; |
| 697 | 741 | } |
| 698 | 742 | break; |
| 699 | 743 | case 0x3c: |
| r9667 | r9668 | |
| 714 | 758 | |
| 715 | 759 | static void mz2500_ram_write(running_machine *machine, UINT16 offset, UINT8 data, UINT8 bank_num) |
| 716 | 760 | { |
| 761 | mz2500_state *state = machine->driver_data<mz2500_state>(); |
| 717 | 762 | UINT8 *ram = memory_region(machine, "maincpu"); |
| 718 | | UINT8 cur_bank = bank_val[bank_num]; |
| 763 | UINT8 cur_bank = state->bank_val[bank_num]; |
| 719 | 764 | |
| 720 | 765 | // if(cur_bank >= 0x30 && cur_bank <= 0x33) |
| 721 | | // printf("CG REG = %02x %02x %02x %02x | offset = %04x | data = %02x\n",cg_reg[0],cg_reg[1],cg_reg[2],cg_reg[3],offset,data); |
| 766 | // printf("CG REG = %02x %02x %02x %02x | offset = %04x | data = %02x\n",state->cg_reg[0],state->cg_reg[1],state->cg_reg[2],state->cg_reg[3],offset,data); |
| 722 | 767 | |
| 723 | 768 | switch(cur_bank) |
| 724 | 769 | { |
| r9667 | r9668 | |
| 728 | 773 | case 0x33: |
| 729 | 774 | { |
| 730 | 775 | // READ MODIFY WRITE |
| 731 | | if(cg_reg[0x0e] == 0x3) |
| 776 | if(state->cg_reg[0x0e] == 0x3) |
| 732 | 777 | { |
| 733 | 778 | // ... |
| 734 | 779 | } |
| 735 | 780 | else |
| 736 | 781 | { |
| 737 | | if((cg_reg[0x05] & 0xc0) == 0x00) //replace |
| 782 | if((state->cg_reg[0x05] & 0xc0) == 0x00) //replace |
| 738 | 783 | { |
| 739 | | if(cg_reg[5] & 1) //B |
| 784 | if(state->cg_reg[5] & 1) //B |
| 740 | 785 | { |
| 741 | | ram[offset+((cur_bank & 3)*0x2000)+0x40000] &= ~cg_reg[6]; |
| 742 | | ram[offset+((cur_bank & 3)*0x2000)+0x40000] |= (cg_reg[4] & 1) ? (data & cg_reg[0] & cg_reg[6]) : 0; |
| 786 | ram[offset+((cur_bank & 3)*0x2000)+0x40000] &= ~state->cg_reg[6]; |
| 787 | ram[offset+((cur_bank & 3)*0x2000)+0x40000] |= (state->cg_reg[4] & 1) ? (data & state->cg_reg[0] & state->cg_reg[6]) : 0; |
| 743 | 788 | } |
| 744 | | if(cg_reg[5] & 2) //R |
| 789 | if(state->cg_reg[5] & 2) //R |
| 745 | 790 | { |
| 746 | | ram[offset+((cur_bank & 3)*0x2000)+0x44000] &= ~cg_reg[6]; |
| 747 | | ram[offset+((cur_bank & 3)*0x2000)+0x44000] |= (cg_reg[4] & 2) ? (data & cg_reg[1] & cg_reg[6]) : 0; |
| 791 | ram[offset+((cur_bank & 3)*0x2000)+0x44000] &= ~state->cg_reg[6]; |
| 792 | ram[offset+((cur_bank & 3)*0x2000)+0x44000] |= (state->cg_reg[4] & 2) ? (data & state->cg_reg[1] & state->cg_reg[6]) : 0; |
| 748 | 793 | } |
| 749 | | if(cg_reg[5] & 4) //G |
| 794 | if(state->cg_reg[5] & 4) //G |
| 750 | 795 | { |
| 751 | | ram[offset+((cur_bank & 3)*0x2000)+0x48000] &= ~cg_reg[6]; |
| 752 | | ram[offset+((cur_bank & 3)*0x2000)+0x48000] |= (cg_reg[4] & 4) ? (data & cg_reg[2] & cg_reg[6]) : 0; |
| 796 | ram[offset+((cur_bank & 3)*0x2000)+0x48000] &= ~state->cg_reg[6]; |
| 797 | ram[offset+((cur_bank & 3)*0x2000)+0x48000] |= (state->cg_reg[4] & 4) ? (data & state->cg_reg[2] & state->cg_reg[6]) : 0; |
| 753 | 798 | } |
| 754 | | if(cg_reg[5] & 8) //I |
| 799 | if(state->cg_reg[5] & 8) //I |
| 755 | 800 | { |
| 756 | | ram[offset+((cur_bank & 3)*0x2000)+0x4c000] &= ~cg_reg[6]; |
| 757 | | ram[offset+((cur_bank & 3)*0x2000)+0x4c000] |= (cg_reg[4] & 8) ? (data & cg_reg[3] & cg_reg[6]) : 0; |
| 801 | ram[offset+((cur_bank & 3)*0x2000)+0x4c000] &= ~state->cg_reg[6]; |
| 802 | ram[offset+((cur_bank & 3)*0x2000)+0x4c000] |= (state->cg_reg[4] & 8) ? (data & state->cg_reg[3] & state->cg_reg[6]) : 0; |
| 758 | 803 | } |
| 759 | 804 | } |
| 760 | | else if((cg_reg[0x05] & 0xc0) == 0x40) //pset |
| 805 | else if((state->cg_reg[0x05] & 0xc0) == 0x40) //pset |
| 761 | 806 | { |
| 762 | | if(cg_reg[5] & 1) //B |
| 807 | if(state->cg_reg[5] & 1) //B |
| 763 | 808 | { |
| 764 | 809 | ram[offset+((cur_bank & 3)*0x2000)+0x40000] &= ~data; |
| 765 | | ram[offset+((cur_bank & 3)*0x2000)+0x40000] |= (cg_reg[4] & 1) ? (data & cg_reg[0]) : 0; |
| 810 | ram[offset+((cur_bank & 3)*0x2000)+0x40000] |= (state->cg_reg[4] & 1) ? (data & state->cg_reg[0]) : 0; |
| 766 | 811 | } |
| 767 | | if(cg_reg[5] & 2) //R |
| 812 | if(state->cg_reg[5] & 2) //R |
| 768 | 813 | { |
| 769 | 814 | ram[offset+((cur_bank & 3)*0x2000)+0x44000] &= ~data; |
| 770 | | ram[offset+((cur_bank & 3)*0x2000)+0x44000] |= (cg_reg[4] & 2) ? (data & cg_reg[1]) : 0; |
| 815 | ram[offset+((cur_bank & 3)*0x2000)+0x44000] |= (state->cg_reg[4] & 2) ? (data & state->cg_reg[1]) : 0; |
| 771 | 816 | } |
| 772 | | if(cg_reg[5] & 4) //G |
| 817 | if(state->cg_reg[5] & 4) //G |
| 773 | 818 | { |
| 774 | 819 | ram[offset+((cur_bank & 3)*0x2000)+0x48000] &= ~data; |
| 775 | | ram[offset+((cur_bank & 3)*0x2000)+0x48000] |= (cg_reg[4] & 4) ? (data & cg_reg[2]) : 0; |
| 820 | ram[offset+((cur_bank & 3)*0x2000)+0x48000] |= (state->cg_reg[4] & 4) ? (data & state->cg_reg[2]) : 0; |
| 776 | 821 | } |
| 777 | | if(cg_reg[5] & 8) //I |
| 822 | if(state->cg_reg[5] & 8) //I |
| 778 | 823 | { |
| 779 | 824 | ram[offset+((cur_bank & 3)*0x2000)+0x4c000] &= ~data; |
| 780 | | ram[offset+((cur_bank & 3)*0x2000)+0x4c000] |= (cg_reg[4] & 8) ? (data & cg_reg[3]) : 0; |
| 825 | ram[offset+((cur_bank & 3)*0x2000)+0x4c000] |= (state->cg_reg[4] & 8) ? (data & state->cg_reg[3]) : 0; |
| 781 | 826 | } |
| 782 | 827 | } |
| 783 | 828 | } |
| r9667 | r9668 | |
| 801 | 846 | case 0x39: |
| 802 | 847 | { |
| 803 | 848 | ram[offset+cur_bank*0x2000] = data; |
| 804 | | if(kanji_bank & 0x80) //kanji ROM |
| 849 | if(state->kanji_bank & 0x80) //kanji ROM |
| 805 | 850 | { |
| 806 | 851 | //NOP |
| 807 | 852 | } |
| r9667 | r9668 | |
| 853 | 898 | |
| 854 | 899 | static READ8_HANDLER( mz2500_bank_addr_r ) |
| 855 | 900 | { |
| 856 | | return bank_addr; |
| 901 | mz2500_state *state = space->machine->driver_data<mz2500_state>(); |
| 902 | return state->bank_addr; |
| 857 | 903 | } |
| 858 | 904 | |
| 859 | 905 | static WRITE8_HANDLER( mz2500_bank_addr_w ) |
| 860 | 906 | { |
| 907 | mz2500_state *state = space->machine->driver_data<mz2500_state>(); |
| 861 | 908 | // printf("%02x\n",data); |
| 862 | | bank_addr = data & 7; |
| 909 | state->bank_addr = data & 7; |
| 863 | 910 | } |
| 864 | 911 | |
| 865 | 912 | static READ8_HANDLER( mz2500_bank_data_r ) |
| 866 | 913 | { |
| 914 | mz2500_state *state = space->machine->driver_data<mz2500_state>(); |
| 867 | 915 | UINT8 res; |
| 868 | 916 | |
| 869 | | res = bank_val[bank_addr]; |
| 917 | res = state->bank_val[state->bank_addr]; |
| 870 | 918 | |
| 871 | | bank_addr++; |
| 872 | | bank_addr&=7; |
| 919 | state->bank_addr++; |
| 920 | state->bank_addr&=7; |
| 873 | 921 | |
| 874 | 922 | return res; |
| 875 | 923 | } |
| 876 | 924 | |
| 877 | 925 | static WRITE8_HANDLER( mz2500_bank_data_w ) |
| 878 | 926 | { |
| 927 | mz2500_state *state = space->machine->driver_data<mz2500_state>(); |
| 879 | 928 | // UINT8 *ROM = memory_region(space->machine, "maincpu"); |
| 880 | 929 | // static const char *const bank_name[] = { "bank0", "bank1", "bank2", "bank3", "bank4", "bank5", "bank6", "bank7" }; |
| 881 | 930 | |
| 882 | | bank_val[bank_addr] = data & 0x3f; |
| 931 | state->bank_val[state->bank_addr] = data & 0x3f; |
| 883 | 932 | |
| 884 | 933 | // if((data*2) >= 0x70) |
| 885 | | // printf("%s %02x\n",bank_name[bank_addr],bank_val[bank_addr]*2); |
| 934 | // printf("%s %02x\n",bank_name[state->bank_addr],state->bank_val[state->bank_addr]*2); |
| 886 | 935 | |
| 887 | | // memory_set_bankptr(space->machine, bank_name[bank_addr], &ROM[bank_val[bank_addr]*0x2000]); |
| 936 | // memory_set_bankptr(space->machine, bank_name[state->bank_addr], &ROM[state->bank_val[state->bank_addr]*0x2000]); |
| 888 | 937 | |
| 889 | | bank_addr++; |
| 890 | | bank_addr&=7; |
| 938 | state->bank_addr++; |
| 939 | state->bank_addr&=7; |
| 891 | 940 | } |
| 892 | 941 | |
| 893 | 942 | static WRITE8_HANDLER( mz2500_kanji_bank_w ) |
| 894 | 943 | { |
| 895 | | kanji_bank = data; |
| 944 | mz2500_state *state = space->machine->driver_data<mz2500_state>(); |
| 945 | state->kanji_bank = data; |
| 896 | 946 | } |
| 897 | 947 | |
| 898 | 948 | static WRITE8_HANDLER( mz2500_dictionary_bank_w ) |
| 899 | 949 | { |
| 900 | | dic_bank = data; |
| 950 | mz2500_state *state = space->machine->driver_data<mz2500_state>(); |
| 951 | state->dic_bank = data; |
| 901 | 952 | } |
| 902 | 953 | |
| 903 | 954 | /* 0xf4 - 0xf7 all returns vblank / hblank states */ |
| r9667 | r9668 | |
| 952 | 1003 | |
| 953 | 1004 | static WRITE8_HANDLER( mz2500_tv_crtc_w ) |
| 954 | 1005 | { |
| 1006 | mz2500_state *state = space->machine->driver_data<mz2500_state>(); |
| 955 | 1007 | switch(offset) |
| 956 | 1008 | { |
| 957 | | case 0: text_reg_index = data; break; |
| 1009 | case 0: state->text_reg_index = data; break; |
| 958 | 1010 | case 1: |
| 959 | | text_reg[text_reg_index] = data; |
| 1011 | state->text_reg[state->text_reg_index] = data; |
| 960 | 1012 | |
| 961 | 1013 | #if 0 |
| 962 | | //printf("[%02x] <- %02x\n",text_reg_index,data); |
| 1014 | //printf("[%02x] <- %02x\n",state->text_reg_index,data); |
| 963 | 1015 | popmessage("(%02x %02x) (%02x %02x %02x %02x) (%02x %02x %02x) (%02x %02x %02x %02x)" |
| 964 | | ,text_reg[0] & ~0x1e,text_reg[3] |
| 965 | | ,text_reg[4],text_reg[5],text_reg[6],text_reg[7] |
| 966 | | ,text_reg[8],text_reg[10],text_reg[11] |
| 967 | | ,text_reg[12],text_reg[13],text_reg[14],text_reg[15]); |
| 1016 | ,state->text_reg[0] & ~0x1e,state->text_reg[3] |
| 1017 | ,state->text_reg[4],state->text_reg[5],state->text_reg[6],state->text_reg[7] |
| 1018 | ,state->text_reg[8],state->text_reg[10],state->text_reg[11] |
| 1019 | ,state->text_reg[12],state->text_reg[13],state->text_reg[14],state->text_reg[15]); |
| 968 | 1020 | |
| 969 | 1021 | #endif |
| 970 | | //popmessage("%d %02x %d %02x %d %d",text_reg[3],text_reg[4],text_reg[5],text_reg[6],text_reg[7]*8,text_reg[8]*8); |
| 1022 | //popmessage("%d %02x %d %02x %d %d",state->text_reg[3],state->text_reg[4],state->text_reg[5],state->text_reg[6],state->text_reg[7]*8,state->text_reg[8]*8); |
| 971 | 1023 | |
| 972 | 1024 | mz2500_reconfigure_screen(space->machine); |
| 973 | 1025 | |
| 974 | | if(text_reg_index == 0x0a) // set 256 color palette |
| 1026 | if(state->text_reg_index == 0x0a) // set 256 color palette |
| 975 | 1027 | { |
| 976 | 1028 | int i,r,g,b; |
| 977 | 1029 | UINT8 b_param,r_param,g_param; |
| r9667 | r9668 | |
| 1000 | 1052 | palette_set_color_rgb(space->machine, i+0x100,pal3bit(r),pal3bit(g),pal3bit(b)); |
| 1001 | 1053 | } |
| 1002 | 1054 | } |
| 1003 | | if(text_reg_index >= 0x80 && text_reg_index <= 0x8f) //Bitmap 16 clut registers |
| 1055 | if(state->text_reg_index >= 0x80 && state->text_reg_index <= 0x8f) //Bitmap 16 clut registers |
| 1004 | 1056 | { |
| 1005 | 1057 | /* |
| 1006 | 1058 | ---x ---- priority |
| 1007 | 1059 | ---- xxxx clut number |
| 1008 | 1060 | */ |
| 1009 | | clut16[text_reg_index & 0xf] = data & 0x1f; |
| 1010 | | //printf("%02x -> [%02x]\n",text_reg[text_reg_index],text_reg_index); |
| 1061 | state->clut16[state->text_reg_index & 0xf] = data & 0x1f; |
| 1062 | //printf("%02x -> [%02x]\n",state->text_reg[state->text_reg_index],state->text_reg_index); |
| 1011 | 1063 | |
| 1012 | 1064 | { |
| 1013 | 1065 | int i; |
| 1014 | 1066 | |
| 1015 | 1067 | for(i=0;i<0x10;i++) |
| 1016 | 1068 | { |
| 1017 | | clut256[(text_reg_index & 0xf) | (i << 4)] = (((data & 0x1f) << 4) | i); |
| 1069 | state->clut256[(state->text_reg_index & 0xf) | (i << 4)] = (((data & 0x1f) << 4) | i); |
| 1018 | 1070 | } |
| 1019 | 1071 | } |
| 1020 | 1072 | } |
| 1021 | 1073 | break; |
| 1022 | 1074 | case 2: /* CG Mask reg (priority mixer) */ |
| 1023 | | cg_mask = data; |
| 1075 | state->cg_mask = data; |
| 1024 | 1076 | break; |
| 1025 | 1077 | case 3: |
| 1026 | 1078 | /* Font size reg */ |
| 1027 | | text_font_reg = data & 1; |
| 1079 | state->text_font_reg = data & 1; |
| 1028 | 1080 | mz2500_reconfigure_screen(space->machine); |
| 1029 | 1081 | break; |
| 1030 | 1082 | } |
| r9667 | r9668 | |
| 1032 | 1084 | |
| 1033 | 1085 | static WRITE8_HANDLER( mz2500_irq_sel_w ) |
| 1034 | 1086 | { |
| 1035 | | irq_sel = data; |
| 1036 | | //printf("%02x\n",irq_sel); |
| 1087 | mz2500_state *state = space->machine->driver_data<mz2500_state>(); |
| 1088 | state->irq_sel = data; |
| 1089 | //printf("%02x\n",state->irq_sel); |
| 1037 | 1090 | // activeness is trusted, see Tower of Druaga |
| 1038 | | irq_mask[0] = (data & 0x08); //CRTC |
| 1039 | | irq_mask[1] = (data & 0x04); //i8253 |
| 1040 | | irq_mask[2] = (data & 0x02); //printer |
| 1041 | | irq_mask[3] = (data & 0x01); //RP5c15 |
| 1091 | state->irq_mask[0] = (data & 0x08); //CRTC |
| 1092 | state->irq_mask[1] = (data & 0x04); //i8253 |
| 1093 | state->irq_mask[2] = (data & 0x02); //printer |
| 1094 | state->irq_mask[3] = (data & 0x01); //RP5c15 |
| 1042 | 1095 | } |
| 1043 | 1096 | |
| 1044 | 1097 | static WRITE8_HANDLER( mz2500_irq_data_w ) |
| 1045 | 1098 | { |
| 1046 | | if(irq_sel & 0x80) |
| 1047 | | irq_vector[0] = data; //CRTC |
| 1048 | | if(irq_sel & 0x40) |
| 1049 | | irq_vector[1] = data; //i8253 |
| 1050 | | if(irq_sel & 0x20) |
| 1051 | | irq_vector[2] = data; //printer |
| 1052 | | if(irq_sel & 0x10) |
| 1053 | | irq_vector[3] = data; //RP5c15 |
| 1099 | mz2500_state *state = space->machine->driver_data<mz2500_state>(); |
| 1100 | if(state->irq_sel & 0x80) |
| 1101 | state->irq_vector[0] = data; //CRTC |
| 1102 | if(state->irq_sel & 0x40) |
| 1103 | state->irq_vector[1] = data; //i8253 |
| 1104 | if(state->irq_sel & 0x20) |
| 1105 | state->irq_vector[2] = data; //printer |
| 1106 | if(state->irq_sel & 0x10) |
| 1107 | state->irq_vector[3] = data; //RP5c15 |
| 1054 | 1108 | |
| 1055 | | // popmessage("%02x %02x %02x %02x",irq_vector[0],irq_vector[1],irq_vector[2],irq_vector[3]); |
| 1109 | // popmessage("%02x %02x %02x %02x",state->irq_vector[0],state->irq_vector[1],state->irq_vector[2],state->irq_vector[3]); |
| 1056 | 1110 | } |
| 1057 | 1111 | |
| 1058 | 1112 | static WRITE8_HANDLER( mz2500_fdc_w ) |
| r9667 | r9668 | |
| 1112 | 1166 | AM_RANGE(0xe000, 0xffff) AM_READWRITE(bank7_r,bank7_w) |
| 1113 | 1167 | ADDRESS_MAP_END |
| 1114 | 1168 | |
| 1115 | | static UINT32 rom_index; |
| 1116 | | static UINT8 hrom_index,lrom_index; |
| 1117 | 1169 | |
| 1118 | 1170 | static READ8_HANDLER( mz2500_rom_r ) |
| 1119 | 1171 | { |
| 1172 | mz2500_state *state = space->machine->driver_data<mz2500_state>(); |
| 1120 | 1173 | UINT8 *rom = memory_region(space->machine, "rom"); |
| 1121 | 1174 | UINT8 res; |
| 1122 | 1175 | |
| 1123 | | lrom_index = (cpu_get_reg(space->machine->device("maincpu"), Z80_B)); |
| 1176 | state->lrom_index = (cpu_get_reg(space->machine->device("maincpu"), Z80_B)); |
| 1124 | 1177 | |
| 1125 | | rom_index = (rom_index & 0xffff00) | (lrom_index & 0xff); |
| 1178 | state->rom_index = (state->rom_index & 0xffff00) | (state->lrom_index & 0xff); |
| 1126 | 1179 | |
| 1127 | | res = rom[rom_index]; |
| 1180 | res = rom[state->rom_index]; |
| 1128 | 1181 | |
| 1129 | 1182 | return res; |
| 1130 | 1183 | } |
| 1131 | 1184 | |
| 1132 | 1185 | static WRITE8_HANDLER( mz2500_rom_w ) |
| 1133 | 1186 | { |
| 1134 | | hrom_index = (cpu_get_reg(space->machine->device("maincpu"), Z80_B)); |
| 1187 | mz2500_state *state = space->machine->driver_data<mz2500_state>(); |
| 1188 | state->hrom_index = (cpu_get_reg(space->machine->device("maincpu"), Z80_B)); |
| 1135 | 1189 | |
| 1136 | | rom_index = (data << 8) | (rom_index & 0x0000ff) | ((hrom_index & 0xff)<<16); |
| 1190 | state->rom_index = (data << 8) | (state->rom_index & 0x0000ff) | ((state->hrom_index & 0xff)<<16); |
| 1137 | 1191 | //printf("%02x\n",data); |
| 1138 | 1192 | } |
| 1139 | 1193 | |
| 1140 | 1194 | /* sets 16 color entries out of 4096 possible combinations */ |
| 1141 | 1195 | static WRITE8_HANDLER( palette4096_io_w ) |
| 1142 | 1196 | { |
| 1143 | | static UINT8 r[16],g[16],b[16]; |
| 1197 | mz2500_state *state = space->machine->driver_data<mz2500_state>(); |
| 1144 | 1198 | UINT8 pal_index; |
| 1145 | 1199 | UINT8 pal_entry; |
| 1146 | 1200 | |
| r9667 | r9668 | |
| 1148 | 1202 | pal_entry = (pal_index & 0x1e) >> 1; |
| 1149 | 1203 | |
| 1150 | 1204 | if(pal_index & 1) |
| 1151 | | g[pal_entry] = (data & 0x0f); |
| 1205 | state->pal[pal_entry].g = (data & 0x0f); |
| 1152 | 1206 | else |
| 1153 | 1207 | { |
| 1154 | | r[pal_entry] = (data & 0xf0) >> 4; |
| 1155 | | b[pal_entry] = data & 0x0f; |
| 1208 | state->pal[pal_entry].r = (data & 0xf0) >> 4; |
| 1209 | state->pal[pal_entry].b = data & 0x0f; |
| 1156 | 1210 | } |
| 1157 | 1211 | |
| 1158 | | palette_set_color_rgb(space->machine, pal_entry+0x10,pal4bit(r[pal_entry]),pal4bit(g[pal_entry]),pal4bit(b[pal_entry])); |
| 1212 | palette_set_color_rgb(space->machine, pal_entry+0x10, pal4bit(state->pal[pal_entry].r), pal4bit(state->pal[pal_entry].g), pal4bit(state->pal[pal_entry].b)); |
| 1159 | 1213 | } |
| 1160 | 1214 | |
| 1161 | 1215 | static READ8_DEVICE_HANDLER( mz2500_wd17xx_r ) |
| 1162 | 1216 | { |
| 1163 | | return wd17xx_r(device, offset) ^ fdc_reverse; |
| 1217 | mz2500_state *state = device->machine->driver_data<mz2500_state>(); |
| 1218 | return wd17xx_r(device, offset) ^ state->fdc_reverse; |
| 1164 | 1219 | } |
| 1165 | 1220 | |
| 1166 | 1221 | static WRITE8_DEVICE_HANDLER( mz2500_wd17xx_w ) |
| 1167 | 1222 | { |
| 1168 | | wd17xx_w(device, offset, data ^ fdc_reverse); |
| 1223 | mz2500_state *state = device->machine->driver_data<mz2500_state>(); |
| 1224 | wd17xx_w(device, offset, data ^ state->fdc_reverse); |
| 1169 | 1225 | } |
| 1170 | 1226 | |
| 1171 | 1227 | static READ8_HANDLER( mz2500_bplane_latch_r ) |
| 1172 | 1228 | { |
| 1173 | | if(cg_reg[7] & 0x10) |
| 1174 | | return mz2500_cg_latch_compare(); |
| 1229 | mz2500_state *state = space->machine->driver_data<mz2500_state>(); |
| 1230 | if(state->cg_reg[7] & 0x10) |
| 1231 | return mz2500_cg_latch_compare(state); |
| 1175 | 1232 | else |
| 1176 | | return cg_latch[0]; |
| 1233 | return state->cg_latch[0]; |
| 1177 | 1234 | } |
| 1178 | 1235 | |
| 1179 | 1236 | |
| 1180 | 1237 | static READ8_HANDLER( mz2500_rplane_latch_r ) |
| 1181 | 1238 | { |
| 1182 | | if(cg_reg[0x07] & 0x10) |
| 1239 | mz2500_state *state = space->machine->driver_data<mz2500_state>(); |
| 1240 | if(state->cg_reg[0x07] & 0x10) |
| 1183 | 1241 | { |
| 1184 | 1242 | UINT8 vblank_bit; |
| 1185 | 1243 | |
| 1186 | | vblank_bit = space->machine->primary_screen->vblank() ? 0 : 0x80 | cg_clear_flag; |
| 1244 | vblank_bit = space->machine->primary_screen->vblank() ? 0 : 0x80 | state->cg_clear_flag; |
| 1187 | 1245 | |
| 1188 | 1246 | return vblank_bit; |
| 1189 | 1247 | } |
| 1190 | 1248 | else |
| 1191 | | return cg_latch[1]; |
| 1249 | return state->cg_latch[1]; |
| 1192 | 1250 | } |
| 1193 | 1251 | |
| 1194 | 1252 | static READ8_HANDLER( mz2500_gplane_latch_r ) |
| 1195 | 1253 | { |
| 1196 | | return cg_latch[2]; |
| 1254 | mz2500_state *state = space->machine->driver_data<mz2500_state>(); |
| 1255 | return state->cg_latch[2]; |
| 1197 | 1256 | } |
| 1198 | 1257 | |
| 1199 | 1258 | static READ8_HANDLER( mz2500_iplane_latch_r ) |
| 1200 | 1259 | { |
| 1201 | | return cg_latch[3]; |
| 1260 | mz2500_state *state = space->machine->driver_data<mz2500_state>(); |
| 1261 | return state->cg_latch[3]; |
| 1202 | 1262 | } |
| 1203 | 1263 | |
| 1204 | 1264 | /* |
| r9667 | r9668 | |
| 1233 | 1293 | |
| 1234 | 1294 | static WRITE8_HANDLER( mz2500_cg_addr_w ) |
| 1235 | 1295 | { |
| 1236 | | cg_reg_index = data; |
| 1296 | mz2500_state *state = space->machine->driver_data<mz2500_state>(); |
| 1297 | state->cg_reg_index = data; |
| 1237 | 1298 | } |
| 1238 | 1299 | |
| 1239 | 1300 | static WRITE8_HANDLER( mz2500_cg_data_w ) |
| 1240 | 1301 | { |
| 1241 | | cg_reg[cg_reg_index & 0x1f] = data; |
| 1302 | mz2500_state *state = space->machine->driver_data<mz2500_state>(); |
| 1303 | state->cg_reg[state->cg_reg_index & 0x1f] = data; |
| 1242 | 1304 | |
| 1243 | | if((cg_reg_index & 0x1f) == 0x08) //accessing VS LO reg clears VS HI reg |
| 1244 | | cg_reg[0x09] = 0; |
| 1305 | if((state->cg_reg_index & 0x1f) == 0x08) //accessing VS LO reg clears VS HI reg |
| 1306 | state->cg_reg[0x09] = 0; |
| 1245 | 1307 | |
| 1246 | | if((cg_reg_index & 0x1f) == 0x0a) //accessing VE LO reg clears VE HI reg |
| 1247 | | cg_reg[0x0b] = 0; |
| 1308 | if((state->cg_reg_index & 0x1f) == 0x0a) //accessing VE LO reg clears VE HI reg |
| 1309 | state->cg_reg[0x0b] = 0; |
| 1248 | 1310 | |
| 1249 | | if((cg_reg_index & 0x1f) == 0x05 && (cg_reg[0x05] & 0xc0) == 0x80) //clear bitmap buffer |
| 1311 | if((state->cg_reg_index & 0x1f) == 0x05 && (state->cg_reg[0x05] & 0xc0) == 0x80) //clear bitmap buffer |
| 1250 | 1312 | { |
| 1251 | 1313 | UINT32 i; |
| 1252 | 1314 | UINT8 *vram = memory_region(space->machine, "maincpu"); |
| 1253 | 1315 | UINT32 layer_bank; |
| 1254 | 1316 | |
| 1255 | | layer_bank = (cg_reg[0x0e] & 0x80) ? 0x10000 : 0x00000; |
| 1317 | layer_bank = (state->cg_reg[0x0e] & 0x80) ? 0x10000 : 0x00000; |
| 1256 | 1318 | |
| 1257 | 1319 | /* TODO: this isn't yet 100% accurate */ |
| 1258 | | if(cg_reg[0x05] & 1) |
| 1320 | if(state->cg_reg[0x05] & 1) |
| 1259 | 1321 | { |
| 1260 | 1322 | for(i=0;i<0x4000;i++) |
| 1261 | 1323 | vram[i+0x40000+layer_bank] = 0x00; //clear B |
| 1262 | 1324 | } |
| 1263 | | if(cg_reg[0x05] & 2) |
| 1325 | if(state->cg_reg[0x05] & 2) |
| 1264 | 1326 | { |
| 1265 | 1327 | for(i=0;i<0x4000;i++) |
| 1266 | 1328 | vram[i+0x44000+layer_bank] = 0x00; //clear R |
| 1267 | 1329 | } |
| 1268 | | if(cg_reg[0x05] & 4) |
| 1330 | if(state->cg_reg[0x05] & 4) |
| 1269 | 1331 | { |
| 1270 | 1332 | for(i=0;i<0x4000;i++) |
| 1271 | 1333 | vram[i+0x48000+layer_bank] = 0x00; //clear G |
| 1272 | 1334 | } |
| 1273 | | if(cg_reg[0x05] & 8) |
| 1335 | if(state->cg_reg[0x05] & 8) |
| 1274 | 1336 | { |
| 1275 | 1337 | for(i=0;i<0x4000;i++) |
| 1276 | 1338 | vram[i+0x4c000+layer_bank] = 0x00; //clear I |
| 1277 | 1339 | } |
| 1278 | | cg_clear_flag = 1; |
| 1340 | state->cg_clear_flag = 1; |
| 1279 | 1341 | } |
| 1280 | 1342 | |
| 1281 | 1343 | { |
| 1282 | 1344 | mz2500_reconfigure_screen(space->machine); |
| 1283 | 1345 | } |
| 1284 | 1346 | |
| 1285 | | if(cg_reg_index & 0x80) //enable auto-inc |
| 1286 | | cg_reg_index = (cg_reg_index & 0xfc) | ((cg_reg_index + 1) & 0x03); |
| 1347 | if(state->cg_reg_index & 0x80) //enable auto-inc |
| 1348 | state->cg_reg_index = (state->cg_reg_index & 0xfc) | ((state->cg_reg_index + 1) & 0x03); |
| 1287 | 1349 | } |
| 1288 | 1350 | |
| 1289 | 1351 | static WRITE8_HANDLER( timer_w ) |
| r9667 | r9668 | |
| 1298 | 1360 | pit8253_gate1_w(pit8253, 1); |
| 1299 | 1361 | } |
| 1300 | 1362 | |
| 1301 | | static UINT8 joy_mode; |
| 1302 | 1363 | |
| 1303 | 1364 | static READ8_HANDLER( mz2500_joystick_r ) |
| 1304 | 1365 | { |
| 1366 | mz2500_state *state = space->machine->driver_data<mz2500_state>(); |
| 1305 | 1367 | UINT8 res,dir_en,in_r; |
| 1306 | 1368 | |
| 1307 | 1369 | res = 0xff; |
| 1308 | | in_r = ~input_port_read(space->machine, joy_mode & 0x40 ? "JOY_2P" : "JOY_1P"); |
| 1370 | in_r = ~input_port_read(space->machine, state->joy_mode & 0x40 ? "JOY_2P" : "JOY_1P"); |
| 1309 | 1371 | |
| 1310 | | if(joy_mode & 0x40) |
| 1372 | if(state->joy_mode & 0x40) |
| 1311 | 1373 | { |
| 1312 | | if(!(joy_mode & 0x04)) res &= ~0x20; |
| 1313 | | if(!(joy_mode & 0x08)) res &= ~0x10; |
| 1314 | | dir_en = (joy_mode & 0x20) ? 0 : 1; |
| 1374 | if(!(state->joy_mode & 0x04)) res &= ~0x20; |
| 1375 | if(!(state->joy_mode & 0x08)) res &= ~0x10; |
| 1376 | dir_en = (state->joy_mode & 0x20) ? 0 : 1; |
| 1315 | 1377 | } |
| 1316 | 1378 | else |
| 1317 | 1379 | { |
| 1318 | | if(!(joy_mode & 0x01)) res &= ~0x20; |
| 1319 | | if(!(joy_mode & 0x02)) res &= ~0x10; |
| 1320 | | dir_en = (joy_mode & 0x10) ? 0 : 1; |
| 1380 | if(!(state->joy_mode & 0x01)) res &= ~0x20; |
| 1381 | if(!(state->joy_mode & 0x02)) res &= ~0x10; |
| 1382 | dir_en = (state->joy_mode & 0x10) ? 0 : 1; |
| 1321 | 1383 | } |
| 1322 | 1384 | |
| 1323 | 1385 | if(dir_en) |
| r9667 | r9668 | |
| 1330 | 1392 | |
| 1331 | 1393 | static WRITE8_HANDLER( mz2500_joystick_w ) |
| 1332 | 1394 | { |
| 1333 | | joy_mode = data; |
| 1395 | mz2500_state *state = space->machine->driver_data<mz2500_state>(); |
| 1396 | state->joy_mode = data; |
| 1334 | 1397 | } |
| 1335 | 1398 | |
| 1336 | | static UINT16 kanji_index; |
| 1337 | 1399 | |
| 1338 | 1400 | static READ8_HANDLER( mz2500_kanji_r ) |
| 1339 | 1401 | { |
| 1402 | mz2500_state *state = space->machine->driver_data<mz2500_state>(); |
| 1340 | 1403 | UINT8 *knj2_rom = memory_region(space->machine, "kanji2"); |
| 1341 | 1404 | |
| 1342 | 1405 | printf("Read from kanji 2 ROM\n"); |
| 1343 | 1406 | |
| 1344 | | return knj2_rom[(kanji_index << 1) | (offset & 1)]; |
| 1407 | return knj2_rom[(state->kanji_index << 1) | (offset & 1)]; |
| 1345 | 1408 | } |
| 1346 | 1409 | |
| 1347 | 1410 | static WRITE8_HANDLER( mz2500_kanji_w ) |
| 1348 | 1411 | { |
| 1349 | | (offset & 1) ? (kanji_index = (data << 8) | (kanji_index & 0xff)) : (kanji_index = (data & 0xff) | (kanji_index & 0xff00)); |
| 1412 | mz2500_state *state = space->machine->driver_data<mz2500_state>(); |
| 1413 | (offset & 1) ? (state->kanji_index = (data << 8) | (state->kanji_index & 0xff)) : (state->kanji_index = (data & 0xff) | (state->kanji_index & 0xff00)); |
| 1350 | 1414 | } |
| 1351 | 1415 | |
| 1352 | 1416 | static READ8_DEVICE_HANDLER( rp5c15_8_r ) |
| r9667 | r9668 | |
| 1367 | 1431 | rp5c15_w(device,rtc_index,data,0xff); |
| 1368 | 1432 | } |
| 1369 | 1433 | |
| 1370 | | static UINT32 emm_offset; |
| 1371 | 1434 | |
| 1372 | 1435 | static READ8_HANDLER( mz2500_emm_data_r ) |
| 1373 | 1436 | { |
| 1437 | mz2500_state *state = space->machine->driver_data<mz2500_state>(); |
| 1374 | 1438 | UINT8 *emm_ram = memory_region(space->machine, "emm"); |
| 1375 | 1439 | UINT8 emm_lo_index; |
| 1376 | 1440 | |
| 1377 | 1441 | emm_lo_index = (cpu_get_reg(space->machine->device("maincpu"), Z80_B)); |
| 1378 | 1442 | |
| 1379 | | emm_offset = (emm_offset & 0xffff00) | (emm_lo_index & 0xff); |
| 1443 | state->emm_offset = (state->emm_offset & 0xffff00) | (emm_lo_index & 0xff); |
| 1380 | 1444 | |
| 1381 | | if(emm_offset < 0x100000) //emm max size |
| 1382 | | return emm_ram[emm_offset]; |
| 1445 | if(state->emm_offset < 0x100000) //emm max size |
| 1446 | return emm_ram[state->emm_offset]; |
| 1383 | 1447 | |
| 1384 | 1448 | return 0xff; |
| 1385 | 1449 | } |
| 1386 | 1450 | |
| 1387 | 1451 | static WRITE8_HANDLER( mz2500_emm_addr_w ) |
| 1388 | 1452 | { |
| 1453 | mz2500_state *state = space->machine->driver_data<mz2500_state>(); |
| 1389 | 1454 | UINT8 emm_hi_index; |
| 1390 | 1455 | |
| 1391 | 1456 | emm_hi_index = (cpu_get_reg(space->machine->device("maincpu"), Z80_B)); |
| 1392 | 1457 | |
| 1393 | | emm_offset = ((emm_hi_index & 0xff) << 16) | ((data & 0xff) << 8) | (emm_offset & 0xff); |
| 1458 | state->emm_offset = ((emm_hi_index & 0xff) << 16) | ((data & 0xff) << 8) | (state->emm_offset & 0xff); |
| 1394 | 1459 | } |
| 1395 | 1460 | |
| 1396 | 1461 | static WRITE8_HANDLER( mz2500_emm_data_w ) |
| 1397 | 1462 | { |
| 1463 | mz2500_state *state = space->machine->driver_data<mz2500_state>(); |
| 1398 | 1464 | UINT8 *emm_ram = memory_region(space->machine, "emm"); |
| 1399 | 1465 | UINT8 emm_lo_index; |
| 1400 | 1466 | |
| 1401 | 1467 | emm_lo_index = (cpu_get_reg(space->machine->device("maincpu"), Z80_B)); |
| 1402 | 1468 | |
| 1403 | | emm_offset = (emm_offset & 0xffff00) | (emm_lo_index & 0xff); |
| 1469 | state->emm_offset = (state->emm_offset & 0xffff00) | (emm_lo_index & 0xff); |
| 1404 | 1470 | |
| 1405 | | if(emm_offset < 0x100000) //emm max size |
| 1406 | | emm_ram[emm_offset] = data; |
| 1471 | if(state->emm_offset < 0x100000) //emm max size |
| 1472 | emm_ram[state->emm_offset] = data; |
| 1407 | 1473 | } |
| 1408 | 1474 | |
| 1409 | 1475 | static ADDRESS_MAP_START(mz2500_io, ADDRESS_SPACE_IO, 8) |
| r9667 | r9668 | |
| 1623 | 1689 | PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNUSED ) |
| 1624 | 1690 | INPUT_PORTS_END |
| 1625 | 1691 | |
| 1626 | | static void mz2500_reset(UINT8 type) |
| 1692 | static void mz2500_reset(mz2500_state *state, UINT8 type) |
| 1627 | 1693 | { |
| 1628 | 1694 | int i; |
| 1629 | 1695 | |
| 1630 | 1696 | for(i=0;i<8;i++) |
| 1631 | | bank_val[i] = bank_reset_val[type][i]; |
| 1697 | state->bank_val[i] = bank_reset_val[type][i]; |
| 1632 | 1698 | } |
| 1633 | 1699 | |
| 1634 | 1700 | static MACHINE_RESET(mz2500) |
| 1635 | 1701 | { |
| 1702 | mz2500_state *state = machine->driver_data<mz2500_state>(); |
| 1636 | 1703 | UINT8 *RAM = memory_region(machine, "maincpu"); |
| 1637 | 1704 | UINT8 *IPL = memory_region(machine, "ipl"); |
| 1638 | 1705 | UINT32 i; |
| 1639 | 1706 | |
| 1640 | | mz2500_reset(IPL_RESET); |
| 1707 | mz2500_reset(state, IPL_RESET); |
| 1641 | 1708 | |
| 1642 | | //irq_vector[0] = 0xef; /* RST 28h - vblank */ |
| 1709 | //state->irq_vector[0] = 0xef; /* RST 28h - vblank */ |
| 1643 | 1710 | |
| 1644 | | text_col_size = 0; |
| 1645 | | text_font_reg = 0; |
| 1711 | state->text_col_size = 0; |
| 1712 | state->text_font_reg = 0; |
| 1646 | 1713 | |
| 1647 | 1714 | /* copy IPL to its natural bank ROM/RAM position */ |
| 1648 | 1715 | for(i=0;i<0x8000;i++) |
| r9667 | r9668 | |
| 1657 | 1724 | |
| 1658 | 1725 | /* disable IRQ */ |
| 1659 | 1726 | for(i=0;i<4;i++) |
| 1660 | | irq_mask[i] = 0; |
| 1727 | state->irq_mask[i] = 0; |
| 1661 | 1728 | |
| 1662 | | kanji_bank = 0; |
| 1729 | state->kanji_bank = 0; |
| 1663 | 1730 | |
| 1664 | | cg_clear_flag = 0; |
| 1731 | state->cg_clear_flag = 0; |
| 1665 | 1732 | |
| 1666 | 1733 | beep_set_frequency(machine->device("beeper"),4096); |
| 1667 | 1734 | beep_set_state(machine->device("beeper"),0); |
| 1668 | 1735 | |
| 1669 | | // monitor_type = input_port_read(machine,"DSW1") & 0x40 ? 1 : 0; |
| 1736 | // state->monitor_type = input_port_read(machine,"DSW1") & 0x40 ? 1 : 0; |
| 1670 | 1737 | } |
| 1671 | 1738 | |
| 1672 | 1739 | static const gfx_layout mz2500_cg_layout = |
| r9667 | r9668 | |
| 1736 | 1803 | |
| 1737 | 1804 | static INTERRUPT_GEN( mz2500_vbl ) |
| 1738 | 1805 | { |
| 1739 | | if(irq_mask[0]) |
| 1740 | | cpu_set_input_line_and_vector(device, 0, HOLD_LINE, irq_vector[0]); |
| 1806 | mz2500_state *state = device->machine->driver_data<mz2500_state>(); |
| 1807 | if(state->irq_mask[0]) |
| 1808 | cpu_set_input_line_and_vector(device, 0, HOLD_LINE, state->irq_vector[0]); |
| 1741 | 1809 | |
| 1742 | | cg_clear_flag = 0; |
| 1810 | state->cg_clear_flag = 0; |
| 1743 | 1811 | } |
| 1744 | 1812 | |
| 1745 | 1813 | static READ8_DEVICE_HANDLER( mz2500_porta_r ) |
| r9667 | r9668 | |
| 1777 | 1845 | |
| 1778 | 1846 | static WRITE8_DEVICE_HANDLER( mz2500_portc_w ) |
| 1779 | 1847 | { |
| 1780 | | static UINT8 reset_lines; |
| 1781 | | |
| 1848 | mz2500_state *state = device->machine->driver_data<mz2500_state>(); |
| 1782 | 1849 | /* |
| 1783 | 1850 | ---- x--- 0->1 transition = IPL reset |
| 1784 | 1851 | ---- -x-- beeper state |
| r9667 | r9668 | |
| 1786 | 1853 | */ |
| 1787 | 1854 | |
| 1788 | 1855 | /* work RAM reset */ |
| 1789 | | if((reset_lines & 0x02) == 0x00 && (data & 0x02)) |
| 1856 | if((state->old_portc & 0x02) == 0x00 && (data & 0x02)) |
| 1790 | 1857 | { |
| 1791 | | mz2500_reset(WRAM_RESET); |
| 1858 | mz2500_reset(state, WRAM_RESET); |
| 1792 | 1859 | /* correct? */ |
| 1793 | 1860 | cputag_set_input_line(device->machine, "maincpu", INPUT_LINE_RESET, PULSE_LINE); |
| 1794 | 1861 | } |
| r9667 | r9668 | |
| 1796 | 1863 | /* bit 2 is speaker */ |
| 1797 | 1864 | |
| 1798 | 1865 | /* IPL reset */ |
| 1799 | | if((reset_lines & 0x08) == 0x00 && (data & 0x08)) |
| 1800 | | mz2500_reset(IPL_RESET); |
| 1866 | if((state->old_portc & 0x08) == 0x00 && (data & 0x08)) |
| 1867 | mz2500_reset(state, IPL_RESET); |
| 1801 | 1868 | |
| 1802 | | reset_lines = data; |
| 1869 | state->old_portc = data; |
| 1803 | 1870 | |
| 1804 | 1871 | beep_set_state(device->machine->device("beeper"),data & 0x04); |
| 1805 | 1872 | |
| r9667 | r9668 | |
| 1819 | 1886 | |
| 1820 | 1887 | static WRITE8_DEVICE_HANDLER( mz2500_pio1_porta_w ) |
| 1821 | 1888 | { |
| 1822 | | static UINT8 prev_col_val; |
| 1889 | mz2500_state *state = device->machine->driver_data<mz2500_state>(); |
| 1823 | 1890 | // printf("%02x\n",data); |
| 1824 | 1891 | |
| 1825 | | if(prev_col_val != ((data & 0x20) >> 5)) |
| 1892 | if(state->prev_col_val != ((data & 0x20) >> 5)) |
| 1826 | 1893 | { |
| 1827 | | text_col_size = ((data & 0x20) >> 5); |
| 1828 | | prev_col_val = text_col_size; |
| 1894 | state->text_col_size = ((data & 0x20) >> 5); |
| 1895 | state->prev_col_val = state->text_col_size; |
| 1829 | 1896 | mz2500_reconfigure_screen(device->machine); |
| 1830 | 1897 | } |
| 1831 | | key_mux = data & 0x1f; |
| 1898 | state->key_mux = data & 0x1f; |
| 1832 | 1899 | } |
| 1833 | 1900 | |
| 1834 | | static UINT8 pio_latchb; |
| 1835 | 1901 | |
| 1836 | 1902 | static READ8_DEVICE_HANDLER( mz2500_pio1_porta_r ) |
| 1837 | 1903 | { |
| 1904 | mz2500_state *state = device->machine->driver_data<mz2500_state>(); |
| 1838 | 1905 | static const char *const keynames[] = { "KEY0", "KEY1", "KEY2", "KEY3", |
| 1839 | 1906 | "KEY4", "KEY5", "KEY6", "KEY7", |
| 1840 | 1907 | "KEY8", "KEY9", "KEYA", "KEYB", |
| 1841 | 1908 | "KEYC", "KEYD", "UNUSED", "UNUSED" }; |
| 1842 | 1909 | |
| 1843 | | if(((key_mux & 0x10) == 0x00) || ((key_mux & 0x0f) == 0x0f)) //status read |
| 1910 | if(((state->key_mux & 0x10) == 0x00) || ((state->key_mux & 0x0f) == 0x0f)) //status read |
| 1844 | 1911 | { |
| 1845 | 1912 | int res,i; |
| 1846 | 1913 | |
| r9667 | r9668 | |
| 1848 | 1915 | for(i=0;i<0xe;i++) |
| 1849 | 1916 | res &= input_port_read(device->machine, keynames[i]); |
| 1850 | 1917 | |
| 1851 | | pio_latchb = res; |
| 1918 | state->pio_latchb = res; |
| 1852 | 1919 | |
| 1853 | 1920 | return res; |
| 1854 | 1921 | } |
| 1855 | 1922 | |
| 1856 | | pio_latchb = input_port_read(device->machine, keynames[key_mux & 0xf]); |
| 1923 | state->pio_latchb = input_port_read(device->machine, keynames[state->key_mux & 0xf]); |
| 1857 | 1924 | |
| 1858 | | return input_port_read(device->machine, keynames[key_mux & 0xf]); |
| 1925 | return input_port_read(device->machine, keynames[state->key_mux & 0xf]); |
| 1859 | 1926 | } |
| 1860 | 1927 | |
| 1861 | 1928 | #if 0 |
| 1862 | 1929 | static READ8_DEVICE_HANDLER( mz2500_pio1_portb_r ) |
| 1863 | 1930 | { |
| 1864 | | return pio_latchb; |
| 1931 | mz2500_state *state = device->machine->driver_data<mz2500_state>(); |
| 1932 | return state->pio_latchb; |
| 1865 | 1933 | } |
| 1866 | 1934 | #endif |
| 1867 | 1935 | |
| r9667 | r9668 | |
| 1876 | 1944 | DEVCB_NULL |
| 1877 | 1945 | }; |
| 1878 | 1946 | |
| 1879 | | static UINT8 ym_porta; |
| 1880 | 1947 | |
| 1881 | 1948 | static READ8_DEVICE_HANDLER( opn_porta_r ) |
| 1882 | 1949 | { |
| 1883 | | return ym_porta; |
| 1950 | mz2500_state *state = device->machine->driver_data<mz2500_state>(); |
| 1951 | return state->ym_porta; |
| 1884 | 1952 | } |
| 1885 | 1953 | |
| 1886 | 1954 | static WRITE8_DEVICE_HANDLER( opn_porta_w ) |
| 1887 | 1955 | { |
| 1956 | mz2500_state *state = device->machine->driver_data<mz2500_state>(); |
| 1888 | 1957 | /* |
| 1889 | 1958 | ---- x--- mouse select |
| 1890 | 1959 | ---- -x-- palette bit (16/4096 colors) |
| 1891 | 1960 | ---- --x- floppy reverse bit (controls wd17xx bits in command registers) |
| 1892 | 1961 | */ |
| 1893 | 1962 | |
| 1894 | | fdc_reverse = (data & 2) ? 0x00 : 0xff; |
| 1895 | | pal_select = (data & 4) ? 1 : 0; |
| 1963 | state->fdc_reverse = (data & 2) ? 0x00 : 0xff; |
| 1964 | state->pal_select = (data & 4) ? 1 : 0; |
| 1896 | 1965 | |
| 1897 | | ym_porta = data; |
| 1966 | state->ym_porta = data; |
| 1898 | 1967 | } |
| 1899 | 1968 | |
| 1900 | 1969 | static const ym2203_interface ym2203_interface_1 = |
| r9667 | r9668 | |
| 1953 | 2022 | |
| 1954 | 2023 | static WRITE_LINE_DEVICE_HANDLER( pit8253_clk0_irq ) |
| 1955 | 2024 | { |
| 1956 | | if(irq_mask[1]/* && state & 1*/) |
| 1957 | | cputag_set_input_line_and_vector(device->machine, "maincpu", 0, HOLD_LINE,irq_vector[1]); |
| 2025 | mz2500_state *drvstate = device->machine->driver_data<mz2500_state>(); |
| 2026 | if(drvstate->irq_mask[1]/* && state & 1*/) |
| 2027 | cputag_set_input_line_and_vector(device->machine, "maincpu", 0, HOLD_LINE,drvstate->irq_vector[1]); |
| 1958 | 2028 | } |
| 1959 | 2029 | |
| 1960 | 2030 | static const struct pit8253_config mz2500_pit8253_intf = |
| r9667 | r9668 | |
| 1980 | 2050 | |
| 1981 | 2051 | static void mz2500_rtc_alarm_irq(int state) |
| 1982 | 2052 | { |
| 2053 | //mz2500_state *drvstate = device->machine->driver_data<mz2500_state>(); |
| 1983 | 2054 | /* TODO: doesn't work yet */ |
| 1984 | | // if(irq_mask[3] && state & 1) |
| 1985 | | // cputag_set_input_line_and_vector(device, "maincpu", 0, HOLD_LINE,irq_vector[3]); |
| 2055 | // if(drvstate->irq_mask[3] && state & 1) |
| 2056 | // cputag_set_input_line_and_vector(device, "maincpu", 0, HOLD_LINE,drvstate->irq_vector[3]); |
| 1986 | 2057 | } |
| 1987 | 2058 | |
| 1988 | 2059 | static const struct rp5c15_interface rtc_intf = |
| r9667 | r9668 | |
| 2000 | 2071 | NULL |
| 2001 | 2072 | }; |
| 2002 | 2073 | |
| 2003 | | static MACHINE_CONFIG_START( mz2500, driver_device ) |
| 2074 | static MACHINE_CONFIG_START( mz2500, mz2500_state ) |
| 2004 | 2075 | /* basic machine hardware */ |
| 2005 | 2076 | MDRV_CPU_ADD("maincpu", Z80, 6000000) |
| 2006 | 2077 | MDRV_CPU_PROGRAM_MAP(mz2500_map) |
src/mess/drivers/multi8.c
| r9667 | r9668 | |
| 18 | 18 | #include "machine/i8255a.h" |
| 19 | 19 | #include "sound/beep.h" |
| 20 | 20 | |
| 21 | | static UINT8 mcu_init; |
| 22 | | static UINT8 keyb_press,keyb_press_flag,shift_press_flag,display_reg; |
| 23 | | static UINT16 cursor_addr,cursor_raster; |
| 24 | | static UINT8 vram_bank; |
| 25 | | static UINT8 pen_clut[8],bw_mode; |
| 26 | 21 | |
| 22 | class multi8_state : public driver_device |
| 23 | { |
| 24 | public: |
| 25 | multi8_state(running_machine &machine, const driver_device_config_base &config) |
| 26 | : driver_device(machine, config) { } |
| 27 | |
| 28 | UINT8 mcu_init; |
| 29 | UINT8 keyb_press; |
| 30 | UINT8 keyb_press_flag; |
| 31 | UINT8 shift_press_flag; |
| 32 | UINT8 display_reg; |
| 33 | UINT16 cursor_addr; |
| 34 | UINT16 cursor_raster; |
| 35 | UINT8 vram_bank; |
| 36 | UINT8 pen_clut[8]; |
| 37 | UINT8 bw_mode; |
| 38 | int addr_latch; |
| 39 | }; |
| 40 | |
| 41 | |
| 42 | |
| 27 | 43 | static VIDEO_START( multi8 ) |
| 28 | 44 | { |
| 29 | | keyb_press = keyb_press_flag = shift_press_flag = display_reg = 0; |
| 30 | | cursor_addr = cursor_raster = 0; |
| 31 | | for (bw_mode = 0; bw_mode < 8; bw_mode++) pen_clut[bw_mode]=0; |
| 32 | | vram_bank = 8; |
| 33 | | bw_mode = 0; |
| 45 | multi8_state *state = machine->driver_data<multi8_state>(); |
| 46 | state->keyb_press = state->keyb_press_flag = state->shift_press_flag = state->display_reg = 0; |
| 47 | state->cursor_addr = state->cursor_raster = 0; |
| 48 | for (state->bw_mode = 0; state->bw_mode < 8; state->bw_mode++) state->pen_clut[state->bw_mode]=0; |
| 49 | state->vram_bank = 8; |
| 50 | state->bw_mode = 0; |
| 34 | 51 | } |
| 35 | 52 | |
| 36 | 53 | static VIDEO_UPDATE( multi8 ) |
| 37 | 54 | { |
| 55 | multi8_state *state = screen->machine->driver_data<multi8_state>(); |
| 38 | 56 | int x,y,count; |
| 39 | 57 | int x_width; |
| 40 | 58 | int xi,yi; |
| r9667 | r9668 | |
| 43 | 61 | |
| 44 | 62 | count = 0x0000; |
| 45 | 63 | |
| 46 | | x_width = (display_reg & 0x40) ? 640 : 320; |
| 64 | x_width = (state->display_reg & 0x40) ? 640 : 320; |
| 47 | 65 | |
| 48 | 66 | for(y=0;y<200;y++) |
| 49 | 67 | { |
| r9667 | r9668 | |
| 57 | 75 | pen_r = (vram[count | 0x4000] >> (7-xi)) & 1; |
| 58 | 76 | pen_g = (vram[count | 0x8000] >> (7-xi)) & 1; |
| 59 | 77 | |
| 60 | | if(bw_mode) |
| 78 | if(state->bw_mode) |
| 61 | 79 | { |
| 62 | | pen_b = (display_reg & 1) ? pen_b : 0; |
| 63 | | pen_r = (display_reg & 2) ? pen_r : 0; |
| 64 | | pen_g = (display_reg & 4) ? pen_g : 0; |
| 80 | pen_b = (state->display_reg & 1) ? pen_b : 0; |
| 81 | pen_r = (state->display_reg & 2) ? pen_r : 0; |
| 82 | pen_g = (state->display_reg & 4) ? pen_g : 0; |
| 65 | 83 | |
| 66 | 84 | color = ((pen_b) | (pen_r) | (pen_g)) ? 7 : 0; |
| 67 | 85 | } |
| 68 | 86 | else |
| 69 | 87 | color = (pen_b) | (pen_r << 1) | (pen_g << 2); |
| 70 | 88 | |
| 71 | | *BITMAP_ADDR16(bitmap, y, x+xi) = screen->machine->pens[pen_clut[color]]; |
| 89 | *BITMAP_ADDR16(bitmap, y, x+xi) = screen->machine->pens[state->pen_clut[color]]; |
| 72 | 90 | } |
| 73 | 91 | count++; |
| 74 | 92 | } |
| 75 | 93 | } |
| 76 | 94 | |
| 77 | | x_width = (display_reg & 0x40) ? 80 : 40; |
| 95 | x_width = (state->display_reg & 0x40) ? 80 : 40; |
| 78 | 96 | count = 0xc000; |
| 79 | 97 | |
| 80 | 98 | for(y=0;y<25;y++) |
| r9667 | r9668 | |
| 83 | 101 | { |
| 84 | 102 | int tile = vram[count]; |
| 85 | 103 | int attr = vram[count+0x800]; |
| 86 | | int color = (display_reg & 0x80) ? 7 : (attr & 0x07); |
| 104 | int color = (state->display_reg & 0x80) ? 7 : (attr & 0x07); |
| 87 | 105 | |
| 88 | 106 | for(yi=0;yi<8;yi++) |
| 89 | 107 | { |
| r9667 | r9668 | |
| 104 | 122 | //drawgfx_opaque(bitmap, cliprect, screen->machine->gfx[0], tile,color >> 5, 0, 0, x*8, y*8); |
| 105 | 123 | |
| 106 | 124 | // draw cursor |
| 107 | | if(cursor_addr+0xc000 == count) |
| 125 | if(state->cursor_addr+0xc000 == count) |
| 108 | 126 | { |
| 109 | 127 | int xc,yc,cursor_on; |
| 110 | 128 | |
| 111 | 129 | cursor_on = 0; |
| 112 | | switch(cursor_raster & 0x60) |
| 130 | switch(state->cursor_raster & 0x60) |
| 113 | 131 | { |
| 114 | 132 | case 0x00: cursor_on = 1; break; //always on |
| 115 | 133 | case 0x20: cursor_on = 0; break; //always off |
| r9667 | r9668 | |
| 119 | 137 | |
| 120 | 138 | if(cursor_on) |
| 121 | 139 | { |
| 122 | | for(yc=0;yc<(8-(cursor_raster & 7));yc++) |
| 140 | for(yc=0;yc<(8-(state->cursor_raster & 7));yc++) |
| 123 | 141 | { |
| 124 | 142 | for(xc=0;xc<8;xc++) |
| 125 | 143 | { |
| r9667 | r9668 | |
| 129 | 147 | } |
| 130 | 148 | } |
| 131 | 149 | |
| 132 | | (display_reg & 0x40) ? count++ : count+=2; |
| 150 | (state->display_reg & 0x40) ? count++ : count+=2; |
| 133 | 151 | } |
| 134 | 152 | } |
| 135 | 153 | return 0; |
| r9667 | r9668 | |
| 137 | 155 | |
| 138 | 156 | static WRITE8_HANDLER( multi8_6845_w ) |
| 139 | 157 | { |
| 140 | | static int addr_latch; |
| 141 | | |
| 158 | multi8_state *state = space->machine->driver_data<multi8_state>(); |
| 142 | 159 | if(offset == 0) |
| 143 | 160 | { |
| 144 | | addr_latch = data; |
| 161 | state->addr_latch = data; |
| 145 | 162 | //mc6845_address_w(space->machine->device("crtc"), 0,data); |
| 146 | 163 | } |
| 147 | 164 | else |
| 148 | 165 | { |
| 149 | | if(addr_latch == 0x0a) |
| 150 | | cursor_raster = data; |
| 151 | | if(addr_latch == 0x0e) |
| 152 | | cursor_addr = ((data<<8) & 0x3f00) | (cursor_addr & 0xff); |
| 153 | | else if(addr_latch == 0x0f) |
| 154 | | cursor_addr = (cursor_addr & 0x3f00) | (data & 0xff); |
| 166 | if(state->addr_latch == 0x0a) |
| 167 | state->cursor_raster = data; |
| 168 | if(state->addr_latch == 0x0e) |
| 169 | state->cursor_addr = ((data<<8) & 0x3f00) | (state->cursor_addr & 0xff); |
| 170 | else if(state->addr_latch == 0x0f) |
| 171 | state->cursor_addr = (state->cursor_addr & 0x3f00) | (data & 0xff); |
| 155 | 172 | |
| 156 | 173 | //mc6845_register_w(space->machine->device("crtc"), 0,data); |
| 157 | 174 | } |
| r9667 | r9668 | |
| 159 | 176 | |
| 160 | 177 | static READ8_HANDLER( key_input_r ) |
| 161 | 178 | { |
| 162 | | if(mcu_init == 0){ mcu_init++; return 3; } |
| 179 | multi8_state *state = space->machine->driver_data<multi8_state>(); |
| 180 | if(state->mcu_init == 0){ state->mcu_init++; return 3; } |
| 163 | 181 | |
| 164 | | keyb_press_flag &= 0xfe; |
| 182 | state->keyb_press_flag &= 0xfe; |
| 165 | 183 | |
| 166 | | return keyb_press; |
| 184 | return state->keyb_press; |
| 167 | 185 | } |
| 168 | 186 | |
| 169 | 187 | static READ8_HANDLER( key_status_r ) |
| 170 | 188 | { |
| 171 | | if(mcu_init == 0){ return 1; } |
| 172 | | if(mcu_init == 1){ mcu_init++; return 1; } |
| 173 | | if(mcu_init == 2){ mcu_init++; return 0; } |
| 189 | multi8_state *state = space->machine->driver_data<multi8_state>(); |
| 190 | if(state->mcu_init == 0){ return 1; } |
| 191 | if(state->mcu_init == 1){ state->mcu_init++; return 1; } |
| 192 | if(state->mcu_init == 2){ state->mcu_init++; return 0; } |
| 174 | 193 | |
| 175 | | return keyb_press_flag | (shift_press_flag << 7); |
| 194 | return state->keyb_press_flag | (state->shift_press_flag << 7); |
| 176 | 195 | } |
| 177 | 196 | |
| 178 | 197 | static READ8_HANDLER( multi8_vram_r ) |
| 179 | 198 | { |
| 199 | multi8_state *state = space->machine->driver_data<multi8_state>(); |
| 180 | 200 | UINT8 *vram = memory_region(space->machine, "vram"); |
| 181 | 201 | UINT8 *wram = memory_region(space->machine, "wram"); |
| 182 | 202 | UINT8 res; |
| 183 | 203 | |
| 184 | | if(!(vram_bank & 0x10)) //select plain work ram |
| 204 | if(!(state->vram_bank & 0x10)) //select plain work ram |
| 185 | 205 | return wram[offset]; |
| 186 | 206 | |
| 187 | 207 | res = 0xff; |
| 188 | | if(!(vram_bank & 1)) { res &= vram[offset | 0x0000]; } |
| 189 | | if(!(vram_bank & 2)) { res &= vram[offset | 0x4000]; } |
| 190 | | if(!(vram_bank & 4)) { res &= vram[offset | 0x8000]; } |
| 191 | | if(!(vram_bank & 8)) { res &= vram[offset | 0xc000]; } |
| 208 | if(!(state->vram_bank & 1)) { res &= vram[offset | 0x0000]; } |
| 209 | if(!(state->vram_bank & 2)) { res &= vram[offset | 0x4000]; } |
| 210 | if(!(state->vram_bank & 4)) { res &= vram[offset | 0x8000]; } |
| 211 | if(!(state->vram_bank & 8)) { res &= vram[offset | 0xc000]; } |
| 192 | 212 | |
| 193 | 213 | return res; |
| 194 | 214 | } |
| 195 | 215 | |
| 196 | 216 | static WRITE8_HANDLER( multi8_vram_w ) |
| 197 | 217 | { |
| 218 | multi8_state *state = space->machine->driver_data<multi8_state>(); |
| 198 | 219 | UINT8 *vram = memory_region(space->machine, "vram"); |
| 199 | 220 | UINT8 *wram = memory_region(space->machine, "wram"); |
| 200 | 221 | |
| 201 | | if(!(vram_bank & 0x10)) //select plain work ram |
| 222 | if(!(state->vram_bank & 0x10)) //select plain work ram |
| 202 | 223 | { |
| 203 | 224 | wram[offset] = data; |
| 204 | 225 | return; |
| 205 | 226 | } |
| 206 | 227 | |
| 207 | | if(!(vram_bank & 1)) { vram[offset | 0x0000] = data; } |
| 208 | | if(!(vram_bank & 2)) { vram[offset | 0x4000] = data; } |
| 209 | | if(!(vram_bank & 4)) { vram[offset | 0x8000] = data; } |
| 210 | | if(!(vram_bank & 8)) { vram[offset | 0xc000] = data; } |
| 228 | if(!(state->vram_bank & 1)) { vram[offset | 0x0000] = data; } |
| 229 | if(!(state->vram_bank & 2)) { vram[offset | 0x4000] = data; } |
| 230 | if(!(state->vram_bank & 4)) { vram[offset | 0x8000] = data; } |
| 231 | if(!(state->vram_bank & 8)) { vram[offset | 0xc000] = data; } |
| 211 | 232 | } |
| 212 | 233 | |
| 213 | 234 | static READ8_HANDLER( pal_r ) |
| 214 | 235 | { |
| 215 | | return pen_clut[offset]; |
| 236 | multi8_state *state = space->machine->driver_data<multi8_state>(); |
| 237 | return state->pen_clut[offset]; |
| 216 | 238 | } |
| 217 | 239 | |
| 218 | 240 | static WRITE8_HANDLER( pal_w ) |
| 219 | 241 | { |
| 220 | | pen_clut[offset] = data; |
| 242 | multi8_state *state = space->machine->driver_data<multi8_state>(); |
| 243 | state->pen_clut[offset] = data; |
| 221 | 244 | |
| 222 | 245 | { |
| 223 | 246 | int i; |
| 224 | 247 | for(i=0;i<8;i++) |
| 225 | 248 | { |
| 226 | | if(pen_clut[i]) { bw_mode = 0; return; } |
| 249 | if(state->pen_clut[i]) { state->bw_mode = 0; return; } |
| 227 | 250 | } |
| 228 | | bw_mode = 1; |
| 251 | state->bw_mode = 1; |
| 229 | 252 | } |
| 230 | 253 | } |
| 231 | 254 | |
| r9667 | r9668 | |
| 374 | 397 | |
| 375 | 398 | static TIMER_CALLBACK( keyboard_callback ) |
| 376 | 399 | { |
| 400 | multi8_state *state = machine->driver_data<multi8_state>(); |
| 377 | 401 | const char* portnames[3] = { "key1","key2","key3" }; |
| 378 | 402 | int i,port_i,scancode; |
| 379 | 403 | UINT8 keymod = input_port_read(machine,"key_modifiers") & 0x1f; |
| 380 | 404 | scancode = 0; |
| 381 | 405 | |
| 382 | | shift_press_flag = ((keymod & 0x02) >> 1); |
| 406 | state->shift_press_flag = ((keymod & 0x02) >> 1); |
| 383 | 407 | |
| 384 | 408 | for(port_i=0;port_i<3;port_i++) |
| 385 | 409 | { |
| r9667 | r9668 | |
| 388 | 412 | if((input_port_read(machine,portnames[port_i])>>i) & 1) |
| 389 | 413 | { |
| 390 | 414 | //key_flag = 1; |
| 391 | | if(!shift_press_flag) // shift not pressed |
| 415 | if(!state->shift_press_flag) // shift not pressed |
| 392 | 416 | { |
| 393 | 417 | if(scancode >= 0x41 && scancode < 0x5b) |
| 394 | 418 | scancode += 0x20; // lowercase |
| r9667 | r9668 | |
| 410 | 434 | if(scancode == 0x3c) |
| 411 | 435 | scancode = 0x3e; |
| 412 | 436 | } |
| 413 | | keyb_press = scancode; |
| 414 | | keyb_press_flag = 1; |
| 437 | state->keyb_press = scancode; |
| 438 | state->keyb_press_flag = 1; |
| 415 | 439 | return; |
| 416 | 440 | } |
| 417 | 441 | scancode++; |
| r9667 | r9668 | |
| 469 | 493 | |
| 470 | 494 | static WRITE8_DEVICE_HANDLER( portb_w ) |
| 471 | 495 | { |
| 496 | multi8_state *state = device->machine->driver_data<multi8_state>(); |
| 472 | 497 | /* |
| 473 | 498 | x--- ---- color mode |
| 474 | 499 | -x-- ---- screen width (80 / 40) |
| r9667 | r9668 | |
| 480 | 505 | // printf("Port B w = %02x %04x\n",data,cpu_get_pc(space->cpu)); |
| 481 | 506 | |
| 482 | 507 | { |
| 483 | | if((display_reg & 0x40) != (data & 0x40)) |
| 508 | if((state->display_reg & 0x40) != (data & 0x40)) |
| 484 | 509 | { |
| 485 | 510 | rectangle visarea = device->machine->primary_screen->visible_area(); |
| 486 | 511 | int x_width; |
| r9667 | r9668 | |
| 495 | 520 | } |
| 496 | 521 | } |
| 497 | 522 | |
| 498 | | display_reg = data; |
| 523 | state->display_reg = data; |
| 499 | 524 | } |
| 500 | 525 | |
| 501 | 526 | static WRITE8_DEVICE_HANDLER( portc_w ) |
| 502 | 527 | { |
| 528 | multi8_state *state = device->machine->driver_data<multi8_state>(); |
| 503 | 529 | // printf("Port C w = %02x\n",data); |
| 504 | | vram_bank = data & 0x1f; |
| 530 | state->vram_bank = data & 0x1f; |
| 505 | 531 | |
| 506 | 532 | if(data & 0x20 && data != 0xff) |
| 507 | 533 | printf("Work RAM bank selected!\n"); |
| r9667 | r9668 | |
| 542 | 568 | |
| 543 | 569 | static MACHINE_RESET(multi8) |
| 544 | 570 | { |
| 571 | multi8_state *state = machine->driver_data<multi8_state>(); |
| 545 | 572 | beep_set_frequency(machine->device("beeper"),1200); //guesswork |
| 546 | 573 | beep_set_state(machine->device("beeper"),0); |
| 547 | | mcu_init = 0; |
| 574 | state->mcu_init = 0; |
| 548 | 575 | } |
| 549 | 576 | |
| 550 | | static MACHINE_CONFIG_START( multi8, driver_device ) |
| 577 | static MACHINE_CONFIG_START( multi8, multi8_state ) |
| 551 | 578 | /* basic machine hardware */ |
| 552 | 579 | MDRV_CPU_ADD("maincpu",Z80, XTAL_4MHz) |
| 553 | 580 | MDRV_CPU_PROGRAM_MAP(multi8_mem) |
src/mess/drivers/nc.c
| r9667 | r9668 | |
| 119 | 119 | |
| 120 | 120 | /* the serial clock is generated by the nc hardware and connected to the msm8251 |
| 121 | 121 | receive clock and transmit clock inputs */ |
| 122 | | static emu_timer *nc_serial_timer; |
| 123 | 122 | |
| 124 | 123 | static void nc_printer_update(running_machine *machine, UINT8 data); |
| 125 | 124 | |
| 126 | | UINT8 nc_type; |
| 127 | 125 | |
| 128 | | static char nc_memory_config[4]; |
| 129 | | unsigned long nc_display_memory_start; |
| 130 | | static emu_timer *nc_keyboard_timer = NULL; |
| 131 | 126 | |
| 132 | | static int nc_membank_rom_mask; |
| 133 | | static int nc_membank_internal_ram_mask; |
| 134 | | int nc_membank_card_ram_mask; |
| 135 | 127 | |
| 136 | 128 | static void nc100_machine_stop(running_machine &machine); |
| 137 | 129 | static void nc200_machine_stop(running_machine &machine); |
| r9667 | r9668 | |
| 265 | 257 | */ |
| 266 | 258 | |
| 267 | 259 | |
| 268 | | static UINT8 nc_poweroff_control; |
| 269 | 260 | |
| 270 | 261 | /* this is not a real register, it is used to record card status */ |
| 271 | 262 | /* ==0, card not inserted, !=0 card is inserted */ |
| 272 | | static int nc_card_status = 0; |
| 273 | 263 | |
| 274 | 264 | /* set pcmcia card present state */ |
| 275 | | void nc_set_card_present_state(int state) |
| 265 | void nc_set_card_present_state(running_machine *machine, int state) |
| 276 | 266 | { |
| 277 | | nc_card_status = state; |
| 267 | nc_state *drvstate = machine->driver_data<nc_state>(); |
| 268 | drvstate->card_status = state; |
| 278 | 269 | } |
| 279 | 270 | |
| 280 | 271 | /* card ram */ |
| 281 | 272 | unsigned char *nc_card_ram = NULL; |
| 282 | 273 | |
| 283 | | static unsigned char nc_uart_control; |
| 284 | 274 | |
| 285 | | static int nc_irq_mask; |
| 286 | | static int nc_irq_status; |
| 287 | 275 | |
| 288 | 276 | |
| 289 | 277 | /* latched interrupts are interrupts that cannot be cleared by writing to the irq |
| 290 | 278 | mask. latched interrupts can only be cleared by accessing the interrupting |
| 291 | 279 | device e.g. serial chip, fdc */ |
| 292 | | static int nc_irq_latch; |
| 293 | 280 | /* this is a mask of irqs that are latched, and it is different for nc100 and |
| 294 | 281 | nc200 */ |
| 295 | | static int nc_irq_latch_mask; |
| 296 | | static int nc_sound_channel_periods[2]; |
| 297 | 282 | |
| 298 | 283 | static void nc_update_interrupts(running_machine *machine) |
| 299 | 284 | { |
| 300 | | nc_irq_status &= ~nc_irq_latch_mask; |
| 301 | | nc_irq_status |= nc_irq_latch; |
| 285 | nc_state *state = machine->driver_data<nc_state>(); |
| 286 | state->irq_status &= ~state->irq_latch_mask; |
| 287 | state->irq_status |= state->irq_latch; |
| 302 | 288 | |
| 303 | 289 | /* any ints set and they are not masked? */ |
| 304 | 290 | if ( |
| 305 | | (((nc_irq_status & nc_irq_mask) & 0x3f)!=0) |
| 291 | (((state->irq_status & state->irq_mask) & 0x3f)!=0) |
| 306 | 292 | ) |
| 307 | 293 | { |
| 308 | | logerror("int set %02x\n", nc_irq_status & nc_irq_mask); |
| 294 | logerror("int set %02x\n", state->irq_status & state->irq_mask); |
| 309 | 295 | /* set int */ |
| 310 | 296 | cputag_set_input_line(machine, "maincpu", 0, HOLD_LINE); |
| 311 | 297 | } |
| r9667 | r9668 | |
| 318 | 304 | |
| 319 | 305 | static TIMER_CALLBACK(nc_keyboard_timer_callback) |
| 320 | 306 | { |
| 307 | nc_state *state = machine->driver_data<nc_state>(); |
| 321 | 308 | LOG(("keyboard int\n")); |
| 322 | 309 | |
| 323 | 310 | /* set int */ |
| 324 | | nc_irq_status |= (1<<3); |
| 311 | state->irq_status |= (1<<3); |
| 325 | 312 | |
| 326 | 313 | /* update ints */ |
| 327 | 314 | nc_update_interrupts(machine); |
| 328 | 315 | |
| 329 | 316 | /* don't trigger again, but don't free it */ |
| 330 | | timer_reset(nc_keyboard_timer, attotime_never); |
| 317 | timer_reset(state->keyboard_timer, attotime_never); |
| 331 | 318 | } |
| 332 | 319 | |
| 333 | 320 | |
| r9667 | r9668 | |
| 339 | 326 | |
| 340 | 327 | static void nc_refresh_memory_bank_config(running_machine *machine, int bank) |
| 341 | 328 | { |
| 329 | nc_state *state = machine->driver_data<nc_state>(); |
| 342 | 330 | address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 343 | 331 | int mem_type; |
| 344 | 332 | int mem_bank; |
| r9667 | r9668 | |
| 347 | 335 | sprintf(bank1,"bank%d",bank+1); |
| 348 | 336 | sprintf(bank5,"bank%d",bank+5); |
| 349 | 337 | |
| 350 | | mem_type = (nc_memory_config[bank]>>6) & 0x03; |
| 351 | | mem_bank = nc_memory_config[bank] & 0x03f; |
| 338 | mem_type = (state->memory_config[bank]>>6) & 0x03; |
| 339 | mem_bank = state->memory_config[bank] & 0x03f; |
| 352 | 340 | |
| 353 | 341 | memory_install_read_bank(space,(bank * 0x4000), (bank * 0x4000) + 0x3fff, 0, 0, nc_bankhandler_r[bank]); |
| 354 | 342 | |
| r9667 | r9668 | |
| 360 | 348 | { |
| 361 | 349 | unsigned char *addr; |
| 362 | 350 | |
| 363 | | mem_bank = mem_bank & nc_membank_rom_mask; |
| 351 | mem_bank = mem_bank & state->membank_rom_mask; |
| 364 | 352 | |
| 365 | 353 | addr = (memory_region(machine, "maincpu")+0x010000) + (mem_bank<<14); |
| 366 | 354 | |
| r9667 | r9668 | |
| 376 | 364 | { |
| 377 | 365 | unsigned char *addr; |
| 378 | 366 | |
| 379 | | mem_bank = mem_bank & nc_membank_internal_ram_mask; |
| 367 | mem_bank = mem_bank & state->membank_internal_ram_mask; |
| 380 | 368 | |
| 381 | 369 | addr = messram_get_ptr(machine->device("messram")) + (mem_bank<<14); |
| 382 | 370 | |
| r9667 | r9668 | |
| 392 | 380 | case 2: |
| 393 | 381 | { |
| 394 | 382 | /* card connected? */ |
| 395 | | if ((nc_card_status) && (nc_card_ram!=NULL)) |
| 383 | if ((state->card_status) && (state->card_ram!=NULL)) |
| 396 | 384 | { |
| 397 | 385 | unsigned char *addr; |
| 398 | 386 | |
| 399 | | mem_bank = mem_bank & nc_membank_card_ram_mask; |
| 400 | | addr = nc_card_ram + (mem_bank<<14); |
| 387 | mem_bank = mem_bank & state->membank_card_ram_mask; |
| 388 | addr = state->card_ram + (mem_bank<<14); |
| 401 | 389 | |
| 402 | 390 | memory_set_bankptr(machine, bank1, addr); |
| 403 | 391 | |
| r9667 | r9668 | |
| 436 | 424 | } |
| 437 | 425 | |
| 438 | 426 | |
| 439 | | static mame_file *file; |
| 440 | 427 | |
| 441 | 428 | /* restore a block of memory from the nvram file */ |
| 442 | 429 | static void nc_common_restore_memory_from_stream(running_machine *machine) |
| 443 | 430 | { |
| 431 | nc_state *state = machine->driver_data<nc_state>(); |
| 444 | 432 | unsigned long stored_size; |
| 445 | 433 | unsigned long restore_size; |
| 446 | 434 | |
| 447 | | if (!file) |
| 435 | if (!state->file) |
| 448 | 436 | return; |
| 449 | 437 | |
| 450 | 438 | LOG(("restoring nc memory\n")); |
| 451 | 439 | /* get size of memory data stored */ |
| 452 | | mame_fread(file, &stored_size, sizeof(unsigned long)); |
| 440 | mame_fread(state->file, &stored_size, sizeof(unsigned long)); |
| 453 | 441 | |
| 454 | 442 | if (stored_size > messram_get_size(machine->device("messram"))) |
| 455 | 443 | restore_size = messram_get_size(machine->device("messram")); |
| r9667 | r9668 | |
| 457 | 445 | restore_size = stored_size; |
| 458 | 446 | |
| 459 | 447 | /* read as much as will fit into memory */ |
| 460 | | mame_fread(file, messram_get_ptr(machine->device("messram")), restore_size); |
| 448 | mame_fread(state->file, messram_get_ptr(machine->device("messram")), restore_size); |
| 461 | 449 | /* seek over remaining data */ |
| 462 | | mame_fseek(file, SEEK_CUR,stored_size - restore_size); |
| 450 | mame_fseek(state->file, SEEK_CUR,stored_size - restore_size); |
| 463 | 451 | } |
| 464 | 452 | |
| 465 | 453 | /* store a block of memory to the nvram file */ |
| 466 | 454 | static void nc_common_store_memory_to_stream(running_machine *machine) |
| 467 | 455 | { |
| 456 | nc_state *state = machine->driver_data<nc_state>(); |
| 468 | 457 | UINT32 size = messram_get_size(machine->device("messram")); |
| 469 | | if (!file) |
| 458 | if (!state->file) |
| 470 | 459 | return; |
| 471 | 460 | |
| 472 | 461 | LOG(("storing nc memory\n")); |
| 473 | 462 | /* write size of memory data */ |
| 474 | | mame_fwrite(file, &size, sizeof(UINT32)); |
| 463 | mame_fwrite(state->file, &size, sizeof(UINT32)); |
| 475 | 464 | |
| 476 | 465 | /* write data block */ |
| 477 | | mame_fwrite(file, messram_get_ptr(machine->device("messram")), size); |
| 466 | mame_fwrite(state->file, messram_get_ptr(machine->device("messram")), size); |
| 478 | 467 | } |
| 479 | 468 | |
| 480 | 469 | static void nc_common_open_stream_for_reading(running_machine *machine) |
| 481 | 470 | { |
| 471 | nc_state *state = machine->driver_data<nc_state>(); |
| 482 | 472 | char filename[MAX_DRIVER_NAME_CHARS + 5]; |
| 483 | 473 | |
| 484 | 474 | sprintf(filename,"%s.nv", machine->gamedrv->name); |
| 485 | 475 | |
| 486 | | mame_fopen(SEARCHPATH_MEMCARD, filename, OPEN_FLAG_READ, &file); |
| 476 | mame_fopen(SEARCHPATH_MEMCARD, filename, OPEN_FLAG_READ, &state->file); |
| 487 | 477 | } |
| 488 | 478 | |
| 489 | 479 | static void nc_common_open_stream_for_writing(running_machine *machine) |
| 490 | 480 | { |
| 491 | | char filename[MAX_DRIVER_NAME_CHARS + 5]; |
| 481 | nc_state *state = machine->driver_data<nc_state>(); |
| 482 | char filename[MAX_DRIVER_NAME_CHARS + 5]; |
| 492 | 483 | |
| 493 | | sprintf(filename,"%s.nv", machine->gamedrv->name); |
| 484 | sprintf(filename,"%s.nv", machine->gamedrv->name); |
| 494 | 485 | |
| 495 | | mame_fopen(SEARCHPATH_MEMCARD, filename, OPEN_FLAG_WRITE, &file); |
| 486 | mame_fopen(SEARCHPATH_MEMCARD, filename, OPEN_FLAG_WRITE, &state->file); |
| 496 | 487 | } |
| 497 | 488 | |
| 498 | 489 | |
| 499 | | static void nc_common_close_stream(void) |
| 490 | static void nc_common_close_stream(running_machine *machine) |
| 500 | 491 | { |
| 501 | | if (file) |
| 502 | | mame_fclose(file); |
| 492 | nc_state *state = machine->driver_data<nc_state>(); |
| 493 | if (state->file) |
| 494 | mame_fclose(state->file); |
| 503 | 495 | } |
| 504 | 496 | |
| 505 | 497 | |
| 506 | 498 | |
| 507 | | static int previous_inputport_10_state; |
| 508 | 499 | |
| 509 | 500 | static TIMER_CALLBACK(dummy_timer_callback) |
| 510 | 501 | { |
| 502 | nc_state *state = machine->driver_data<nc_state>(); |
| 511 | 503 | int inputport_10_state; |
| 512 | 504 | int changed_bits; |
| 513 | 505 | |
| 514 | | inputport_10_state = input_port_read(machine, "EXTRA"); |
| 506 | inputport_10_state = input_port_read(machine, "EXTRA"); |
| 515 | 507 | |
| 516 | | changed_bits = inputport_10_state^previous_inputport_10_state; |
| 508 | changed_bits = inputport_10_state^state->previous_inputport_10_state; |
| 517 | 509 | |
| 518 | 510 | /* on/off button changed state? */ |
| 519 | 511 | if (changed_bits & 0x01) |
| r9667 | r9668 | |
| 522 | 514 | { |
| 523 | 515 | /* on NC100 on/off button causes a nmi, on |
| 524 | 516 | nc200 on/off button causes an int */ |
| 525 | | switch (nc_type) |
| 517 | switch (state->type) |
| 526 | 518 | { |
| 527 | 519 | case NC_TYPE_1xx: |
| 528 | 520 | { |
| r9667 | r9668 | |
| 533 | 525 | |
| 534 | 526 | case NC_TYPE_200: |
| 535 | 527 | { |
| 536 | | nc_irq_status |= (1 << 4); |
| 528 | state->irq_status |= (1 << 4); |
| 537 | 529 | nc_update_interrupts(machine); |
| 538 | 530 | } |
| 539 | 531 | break; |
| r9667 | r9668 | |
| 548 | 540 | nc_refresh_memory_config(machine); |
| 549 | 541 | } |
| 550 | 542 | |
| 551 | | previous_inputport_10_state = inputport_10_state; |
| 543 | state->previous_inputport_10_state = inputport_10_state; |
| 552 | 544 | } |
| 553 | 545 | |
| 554 | 546 | static TIMER_CALLBACK(nc_serial_timer_callback); |
| 555 | 547 | |
| 556 | 548 | static void nc_common_init_machine(running_machine *machine) |
| 557 | 549 | { |
| 550 | nc_state *state = machine->driver_data<nc_state>(); |
| 558 | 551 | /* setup reset state */ |
| 559 | | nc_display_memory_start = 0; |
| 552 | state->display_memory_start = 0; |
| 560 | 553 | |
| 561 | 554 | /* setup reset state */ |
| 562 | | nc_memory_config[0] = 0; |
| 563 | | nc_memory_config[1] = 0; |
| 564 | | nc_memory_config[2] = 0; |
| 565 | | nc_memory_config[3] = 0; |
| 555 | state->memory_config[0] = 0; |
| 556 | state->memory_config[1] = 0; |
| 557 | state->memory_config[2] = 0; |
| 558 | state->memory_config[3] = 0; |
| 566 | 559 | |
| 567 | | previous_inputport_10_state = input_port_read(machine, "EXTRA"); |
| 560 | state->previous_inputport_10_state = input_port_read(machine, "EXTRA"); |
| 568 | 561 | |
| 569 | | /* setup reset state ints are masked */ |
| 570 | | nc_irq_mask = 0; |
| 571 | | /* setup reset state no ints wanting servicing */ |
| 572 | | nc_irq_status = 0; |
| 573 | | /* at reset set to 0x0ffff */ |
| 562 | /* setup reset state ints are masked */ |
| 563 | state->irq_mask = 0; |
| 564 | /* setup reset state no ints wanting servicing */ |
| 565 | state->irq_status = 0; |
| 566 | /* at reset set to 0x0ffff */ |
| 574 | 567 | |
| 575 | | nc_irq_latch = 0; |
| 576 | | nc_irq_latch_mask = 0; |
| 568 | state->irq_latch = 0; |
| 569 | state->irq_latch_mask = 0; |
| 577 | 570 | |
| 578 | 571 | /* setup reset state */ |
| 579 | | nc_sound_channel_periods[0] = (nc_sound_channel_periods[1] = 0x0ffff); |
| 572 | state->sound_channel_periods[0] = (state->sound_channel_periods[1] = 0x0ffff); |
| 580 | 573 | |
| 581 | | /* at reset set to 1 */ |
| 582 | | nc_poweroff_control = 1; |
| 574 | /* at reset set to 1 */ |
| 575 | state->poweroff_control = 1; |
| 583 | 576 | |
| 584 | | nc_refresh_memory_config(machine); |
| 577 | nc_refresh_memory_config(machine); |
| 585 | 578 | nc_update_interrupts(machine); |
| 586 | 579 | |
| 587 | 580 | /* at reset set to 0x0ff */ |
| 588 | | nc_uart_control = 0x0ff; |
| 581 | state->uart_control = 0x0ff; |
| 589 | 582 | } |
| 590 | 583 | |
| 591 | 584 | static ADDRESS_MAP_START(nc_map, ADDRESS_SPACE_PROGRAM, 8 ) |
| r9667 | r9668 | |
| 598 | 591 | |
| 599 | 592 | static READ8_HANDLER(nc_memory_management_r) |
| 600 | 593 | { |
| 601 | | return nc_memory_config[offset]; |
| 594 | nc_state *state = space->machine->driver_data<nc_state>(); |
| 595 | return state->memory_config[offset]; |
| 602 | 596 | } |
| 603 | 597 | |
| 604 | 598 | static WRITE8_HANDLER(nc_memory_management_w) |
| 605 | 599 | { |
| 600 | nc_state *state = space->machine->driver_data<nc_state>(); |
| 606 | 601 | LOG(("Memory management W: %02x %02x\n",offset,data)); |
| 607 | | nc_memory_config[offset] = data; |
| 602 | state->memory_config[offset] = data; |
| 608 | 603 | |
| 609 | 604 | nc_refresh_memory_config(space->machine); |
| 610 | 605 | } |
| 611 | 606 | |
| 612 | 607 | static WRITE8_HANDLER(nc_irq_mask_w) |
| 613 | 608 | { |
| 609 | nc_state *state = space->machine->driver_data<nc_state>(); |
| 614 | 610 | LOG(("irq mask w: %02x\n", data)); |
| 615 | 611 | LOG_DEBUG(("irq mask nc200 w: %02x\n",data & ((1<<4) | (1<<5) | (1<<6) | (1<<7)))); |
| 616 | 612 | |
| 617 | 613 | /* writing mask clears ints that are to be masked? */ |
| 618 | | nc_irq_mask = data; |
| 614 | state->irq_mask = data; |
| 619 | 615 | |
| 620 | 616 | nc_update_interrupts(space->machine); |
| 621 | 617 | } |
| 622 | 618 | |
| 623 | 619 | static WRITE8_HANDLER(nc_irq_status_w) |
| 624 | 620 | { |
| 621 | nc_state *state = space->machine->driver_data<nc_state>(); |
| 625 | 622 | LOG(("irq status w: %02x\n", data)); |
| 626 | | data = data^0x0ff; |
| 623 | data = data^0x0ff; |
| 627 | 624 | |
| 628 | | if (nc_type == NC_TYPE_200) |
| 625 | if (state->type == NC_TYPE_200) |
| 629 | 626 | { |
| 630 | 627 | /* Russell Marks confirms that on the NC200, the key scan interrupt must be explicitly |
| 631 | 628 | cleared. It is not automatically cleared when reading 0x0b9 */ |
| 632 | 629 | if ((data & (1<<3))!=0) |
| 633 | 630 | { |
| 634 | 631 | /* set timer to occur again */ |
| 635 | | timer_reset(nc_keyboard_timer, ATTOTIME_IN_MSEC(10)); |
| 632 | timer_reset(state->keyboard_timer, ATTOTIME_IN_MSEC(10)); |
| 636 | 633 | |
| 637 | 634 | nc_update_interrupts(space->machine); |
| 638 | 635 | } |
| r9667 | r9668 | |
| 645 | 642 | /* clearing keyboard int? */ |
| 646 | 643 | ((data & (1<<3))!=0) && |
| 647 | 644 | /* keyboard int request? */ |
| 648 | | ((nc_irq_status & (1<<3))!=0) |
| 645 | ((state->irq_status & (1<<3))!=0) |
| 649 | 646 | ) |
| 650 | 647 | { |
| 651 | 648 | /* set timer to occur again */ |
| 652 | | timer_reset(nc_keyboard_timer, ATTOTIME_IN_MSEC(10)); |
| 649 | timer_reset(state->keyboard_timer, ATTOTIME_IN_MSEC(10)); |
| 653 | 650 | } |
| 654 | 651 | #endif |
| 655 | | nc_irq_status &=~data; |
| 652 | state->irq_status &=~data; |
| 656 | 653 | |
| 657 | 654 | nc_update_interrupts(space->machine); |
| 658 | 655 | } |
| 659 | 656 | |
| 660 | 657 | static READ8_HANDLER(nc_irq_status_r) |
| 661 | 658 | { |
| 662 | | return ~((nc_irq_status & (~nc_irq_latch_mask)) | nc_irq_latch); |
| 659 | nc_state *state = space->machine->driver_data<nc_state>(); |
| 660 | return ~((state->irq_status & (~state->irq_latch_mask)) | state->irq_latch); |
| 663 | 661 | } |
| 664 | 662 | |
| 665 | 663 | |
| 666 | 664 | static READ8_HANDLER(nc_key_data_in_r) |
| 667 | 665 | { |
| 666 | nc_state *state = space->machine->driver_data<nc_state>(); |
| 668 | 667 | static const char *const keynames[] = { |
| 669 | 668 | "LINE0", "LINE1", "LINE2", "LINE3", "LINE4", |
| 670 | 669 | "LINE5", "LINE6", "LINE7", "LINE8", "LINE9" |
| r9667 | r9668 | |
| 673 | 672 | if (offset==9) |
| 674 | 673 | { |
| 675 | 674 | /* reading 0x0b9 will clear int and re-start scan procedure! */ |
| 676 | | nc_irq_status &= ~(1<<3); |
| 675 | state->irq_status &= ~(1<<3); |
| 677 | 676 | |
| 678 | 677 | /* set timer to occur again */ |
| 679 | | timer_reset(nc_keyboard_timer, ATTOTIME_IN_MSEC(10)); |
| 678 | timer_reset(state->keyboard_timer, ATTOTIME_IN_MSEC(10)); |
| 680 | 679 | |
| 681 | 680 | nc_update_interrupts(space->machine); |
| 682 | 681 | } |
| r9667 | r9668 | |
| 687 | 686 | |
| 688 | 687 | static void nc_sound_update(running_machine *machine, int channel) |
| 689 | 688 | { |
| 689 | nc_state *state = machine->driver_data<nc_state>(); |
| 690 | 690 | int on; |
| 691 | 691 | int frequency; |
| 692 | 692 | int period; |
| r9667 | r9668 | |
| 702 | 702 | break; |
| 703 | 703 | } |
| 704 | 704 | |
| 705 | | period = nc_sound_channel_periods[channel]; |
| 705 | period = state->sound_channel_periods[channel]; |
| 706 | 706 | |
| 707 | 707 | /* if top bit is 0, sound is on */ |
| 708 | 708 | on = ((period & (1<<15))==0); |
| r9667 | r9668 | |
| 718 | 718 | |
| 719 | 719 | static WRITE8_HANDLER(nc_sound_w) |
| 720 | 720 | { |
| 721 | nc_state *state = space->machine->driver_data<nc_state>(); |
| 721 | 722 | LOG(("sound w: %04x %02x\n", offset, data)); |
| 722 | 723 | |
| 723 | 724 | switch (offset) |
| r9667 | r9668 | |
| 725 | 726 | case 0x0: |
| 726 | 727 | { |
| 727 | 728 | /* update period value */ |
| 728 | | nc_sound_channel_periods[0] = |
| 729 | | (nc_sound_channel_periods[0] & 0x0ff00) | (data & 0x0ff); |
| 729 | state->sound_channel_periods[0] = |
| 730 | (state->sound_channel_periods[0] & 0x0ff00) | (data & 0x0ff); |
| 730 | 731 | |
| 731 | 732 | nc_sound_update(space->machine, 0); |
| 732 | 733 | } |
| r9667 | r9668 | |
| 734 | 735 | |
| 735 | 736 | case 0x01: |
| 736 | 737 | { |
| 737 | | nc_sound_channel_periods[0] = |
| 738 | | (nc_sound_channel_periods[0] & 0x0ff) | ((data & 0x0ff)<<8); |
| 738 | state->sound_channel_periods[0] = |
| 739 | (state->sound_channel_periods[0] & 0x0ff) | ((data & 0x0ff)<<8); |
| 739 | 740 | |
| 740 | 741 | nc_sound_update(space->machine, 0); |
| 741 | 742 | } |
| r9667 | r9668 | |
| 744 | 745 | case 0x02: |
| 745 | 746 | { |
| 746 | 747 | /* update period value */ |
| 747 | | nc_sound_channel_periods[1] = |
| 748 | | (nc_sound_channel_periods[1] & 0x0ff00) | (data & 0x0ff); |
| 748 | state->sound_channel_periods[1] = |
| 749 | (state->sound_channel_periods[1] & 0x0ff00) | (data & 0x0ff); |
| 749 | 750 | |
| 750 | 751 | nc_sound_update(space->machine, 1); |
| 751 | 752 | } |
| r9667 | r9668 | |
| 753 | 754 | |
| 754 | 755 | case 0x03: |
| 755 | 756 | { |
| 756 | | nc_sound_channel_periods[1] = |
| 757 | | (nc_sound_channel_periods[1] & 0x0ff) | ((data & 0x0ff)<<8); |
| 757 | state->sound_channel_periods[1] = |
| 758 | (state->sound_channel_periods[1] & 0x0ff) | ((data & 0x0ff)<<8); |
| 758 | 759 | |
| 759 | 760 | nc_sound_update(space->machine, 1); |
| 760 | 761 | } |
| r9667 | r9668 | |
| 787 | 788 | |
| 788 | 789 | static WRITE8_HANDLER(nc_uart_control_w) |
| 789 | 790 | { |
| 791 | nc_state *state = space->machine->driver_data<nc_state>(); |
| 790 | 792 | /* update printer state */ |
| 791 | 793 | nc_printer_update(space->machine, data); |
| 792 | 794 | |
| 793 | 795 | /* on/off changed state? */ |
| 794 | | if (((nc_uart_control ^ data) & (1<<3))!=0) |
| 796 | if (((state->uart_control ^ data) & (1<<3))!=0) |
| 795 | 797 | { |
| 796 | 798 | /* changed uart from off to on */ |
| 797 | 799 | if ((data & (1<<3))==0) |
| r9667 | r9668 | |
| 800 | 802 | } |
| 801 | 803 | } |
| 802 | 804 | |
| 803 | | timer_adjust_periodic(nc_serial_timer, attotime_zero, 0, ATTOTIME_IN_HZ(baud_rate_table[(data & 0x07)])); |
| 805 | timer_adjust_periodic(state->serial_timer, attotime_zero, 0, ATTOTIME_IN_HZ(baud_rate_table[(data & 0x07)])); |
| 804 | 806 | |
| 805 | | nc_uart_control = data; |
| 807 | state->uart_control = data; |
| 806 | 808 | } |
| 807 | 809 | |
| 808 | 810 | /* NC100 printer emulation */ |
| r9667 | r9668 | |
| 820 | 822 | /********************************************************************************************************/ |
| 821 | 823 | /* NC100 hardware */ |
| 822 | 824 | |
| 823 | | static int previous_alarm_state; |
| 824 | 825 | |
| 825 | 826 | |
| 826 | 827 | static WRITE8_HANDLER(nc100_display_memory_start_w) |
| 827 | 828 | { |
| 829 | nc_state *state = space->machine->driver_data<nc_state>(); |
| 828 | 830 | /* bit 7: A15 */ |
| 829 | 831 | /* bit 6: A14 */ |
| 830 | 832 | /* bit 5: A13 */ |
| 831 | 833 | /* bit 4: A12 */ |
| 832 | 834 | /* bit 3-0: not used */ |
| 833 | | nc_display_memory_start = (data & 0x0f0)<<(12-4); |
| 835 | state->display_memory_start = (data & 0x0f0)<<(12-4); |
| 834 | 836 | |
| 835 | | LOG(("disp memory w: %04x\n", (int) nc_display_memory_start)); |
| 837 | LOG(("disp memory w: %04x\n", (int) state->display_memory_start)); |
| 836 | 838 | } |
| 837 | 839 | |
| 838 | 840 | |
| 839 | 841 | static WRITE8_HANDLER(nc100_uart_control_w) |
| 840 | 842 | { |
| 843 | //nc_state *state = space->machine->driver_data<nc_state>(); |
| 841 | 844 | nc_uart_control_w(space, offset,data); |
| 842 | 845 | |
| 843 | 846 | // /* is this correct?? */ |
| 844 | 847 | // if (data & (1<<3)) |
| 845 | 848 | // { |
| 846 | 849 | // /* clear latched irq's */ |
| 847 | | // nc_irq_latch &= ~3; |
| 850 | // state->irq_latch &= ~3; |
| 848 | 851 | // nc_update_interrupts(machine); |
| 849 | 852 | // } |
| 850 | 853 | } |
| r9667 | r9668 | |
| 852 | 855 | |
| 853 | 856 | static void nc100_tc8521_alarm_callback(running_device *device, int state) |
| 854 | 857 | { |
| 858 | nc_state *drvstate = device->machine->driver_data<nc_state>(); |
| 855 | 859 | /* I'm assuming that the nmi is edge triggered */ |
| 856 | 860 | /* a interrupt from the fdc will cause a change in line state, and |
| 857 | 861 | the nmi will be triggered, but when the state changes because the int |
| 858 | 862 | is cleared this will not cause another nmi */ |
| 859 | 863 | /* I'll emulate it like this to be sure */ |
| 860 | 864 | |
| 861 | | if (state != previous_alarm_state) |
| 865 | if (state != drvstate->previous_alarm_state) |
| 862 | 866 | { |
| 863 | 867 | if (state) |
| 864 | 868 | { |
| r9667 | r9668 | |
| 868 | 872 | } |
| 869 | 873 | } |
| 870 | 874 | |
| 871 | | previous_alarm_state = state; |
| 875 | drvstate->previous_alarm_state = state; |
| 872 | 876 | } |
| 873 | 877 | |
| 874 | 878 | static void nc100_txrdy_callback(running_device *device, int state) |
| 875 | 879 | { |
| 876 | | nc_irq_latch &= ~(1 << 1); |
| 880 | nc_state *drvstate = device->machine->driver_data<nc_state>(); |
| 881 | drvstate->irq_latch &= ~(1 << 1); |
| 877 | 882 | |
| 878 | 883 | /* uart on? */ |
| 879 | | if ((nc_uart_control & (1 << 3)) == 0) |
| 884 | if ((drvstate->uart_control & (1 << 3)) == 0) |
| 880 | 885 | { |
| 881 | 886 | if (state) |
| 882 | 887 | { |
| 883 | 888 | logerror("tx ready\n"); |
| 884 | | nc_irq_latch |= (1 << 1); |
| 889 | drvstate->irq_latch |= (1 << 1); |
| 885 | 890 | } |
| 886 | 891 | } |
| 887 | 892 | |
| r9667 | r9668 | |
| 890 | 895 | |
| 891 | 896 | static void nc100_rxrdy_callback(running_device *device, int state) |
| 892 | 897 | { |
| 893 | | nc_irq_latch &= ~(1<<0); |
| 898 | nc_state *drvstate = device->machine->driver_data<nc_state>(); |
| 899 | drvstate->irq_latch &= ~(1<<0); |
| 894 | 900 | |
| 895 | | if ((nc_uart_control & (1<<3))==0) |
| 901 | if ((drvstate->uart_control & (1<<3))==0) |
| 896 | 902 | { |
| 897 | 903 | if (state) |
| 898 | 904 | { |
| 899 | 905 | logerror("rx ready\n"); |
| 900 | | nc_irq_latch |= (1<<0); |
| 906 | drvstate->irq_latch |= (1<<0); |
| 901 | 907 | } |
| 902 | 908 | } |
| 903 | 909 | |
| r9667 | r9668 | |
| 920 | 926 | |
| 921 | 927 | static WRITE_LINE_DEVICE_HANDLER( nc100_centronics_ack_w ) |
| 922 | 928 | { |
| 929 | nc_state *drvstate = device->machine->driver_data<nc_state>(); |
| 923 | 930 | if (state) |
| 924 | | nc_irq_status |= 0x04; |
| 931 | drvstate->irq_status |= 0x04; |
| 925 | 932 | else |
| 926 | | nc_irq_status &= ~0x04; |
| 933 | drvstate->irq_status &= ~0x04; |
| 927 | 934 | |
| 928 | 935 | /* trigger an int if the irq is set */ |
| 929 | 936 | nc_update_interrupts(device->machine); |
| r9667 | r9668 | |
| 940 | 947 | |
| 941 | 948 | static MACHINE_RESET( nc100 ) |
| 942 | 949 | { |
| 943 | | /* 256k of rom */ |
| 944 | | nc_membank_rom_mask = 0x0f; |
| 950 | nc_state *state = machine->driver_data<nc_state>(); |
| 951 | /* 256k of rom */ |
| 952 | state->membank_rom_mask = 0x0f; |
| 945 | 953 | |
| 946 | | nc_membank_internal_ram_mask = 3; |
| 954 | state->membank_internal_ram_mask = 3; |
| 947 | 955 | |
| 948 | | nc_membank_card_ram_mask = 0x03f; |
| 956 | state->membank_card_ram_mask = 0x03f; |
| 949 | 957 | |
| 950 | | nc_common_init_machine(machine); |
| 958 | nc_common_init_machine(machine); |
| 951 | 959 | |
| 952 | 960 | nc_common_open_stream_for_reading(machine); |
| 953 | 961 | |
| 954 | 962 | { |
| 955 | 963 | running_device *rtc = machine->device("rtc"); |
| 956 | | tc8521_load_stream(rtc, file); |
| 964 | tc8521_load_stream(rtc, state->file); |
| 957 | 965 | } |
| 958 | 966 | |
| 959 | 967 | nc_common_restore_memory_from_stream(machine); |
| 960 | 968 | |
| 961 | | nc_common_close_stream(); |
| 969 | nc_common_close_stream(machine); |
| 962 | 970 | |
| 963 | 971 | /* serial */ |
| 964 | | nc_irq_latch_mask = (1<<0) | (1<<1); |
| 972 | state->irq_latch_mask = (1<<0) | (1<<1); |
| 965 | 973 | } |
| 966 | 974 | |
| 967 | 975 | static void nc100_machine_stop(running_machine &machine) |
| 968 | 976 | { |
| 977 | nc_state *state = machine.driver_data<nc_state>(); |
| 969 | 978 | nc_common_open_stream_for_writing(&machine); |
| 970 | 979 | { |
| 971 | 980 | running_device *rtc = machine.device("rtc"); |
| 972 | | tc8521_save_stream(rtc, file); |
| 981 | tc8521_save_stream(rtc, state->file); |
| 973 | 982 | } |
| 974 | 983 | nc_common_store_memory_to_stream(&machine); |
| 975 | | nc_common_close_stream(); |
| 984 | nc_common_close_stream(&machine); |
| 976 | 985 | } |
| 977 | 986 | |
| 978 | 987 | static MACHINE_START( nc100 ) |
| 979 | 988 | { |
| 980 | | nc_type = NC_TYPE_1xx; |
| 989 | nc_state *state = machine->driver_data<nc_state>(); |
| 990 | state->type = NC_TYPE_1xx; |
| 981 | 991 | |
| 982 | 992 | machine->add_notifier(MACHINE_NOTIFY_EXIT, nc100_machine_stop); |
| 983 | 993 | |
| 984 | 994 | /* keyboard timer */ |
| 985 | | nc_keyboard_timer = timer_alloc(machine, nc_keyboard_timer_callback, NULL); |
| 986 | | timer_adjust_oneshot(nc_keyboard_timer, ATTOTIME_IN_MSEC(10), 0); |
| 995 | state->keyboard_timer = timer_alloc(machine, nc_keyboard_timer_callback, NULL); |
| 996 | timer_adjust_oneshot(state->keyboard_timer, ATTOTIME_IN_MSEC(10), 0); |
| 987 | 997 | |
| 988 | 998 | /* dummy timer */ |
| 989 | 999 | timer_pulse(machine, ATTOTIME_IN_HZ(50), NULL, 0, dummy_timer_callback); |
| 990 | 1000 | |
| 991 | 1001 | /* serial timer */ |
| 992 | | nc_serial_timer = timer_alloc(machine, nc_serial_timer_callback, NULL); |
| 1002 | state->serial_timer = timer_alloc(machine, nc_serial_timer_callback, NULL); |
| 993 | 1003 | } |
| 994 | 1004 | |
| 995 | 1005 | |
| 996 | 1006 | static WRITE8_HANDLER(nc100_poweroff_control_w) |
| 997 | 1007 | { |
| 1008 | nc_state *state = space->machine->driver_data<nc_state>(); |
| 998 | 1009 | /* bits 7-1: not used */ |
| 999 | 1010 | /* bit 0: 1 = no effect, 0 = power off */ |
| 1000 | | nc_poweroff_control = data; |
| 1011 | state->poweroff_control = data; |
| 1001 | 1012 | LOG(("nc poweroff control: %02x\n",data)); |
| 1002 | 1013 | } |
| 1003 | 1014 | |
| r9667 | r9668 | |
| 1005 | 1016 | /* nc100 version of card/battery status */ |
| 1006 | 1017 | static READ8_HANDLER(nc100_card_battery_status_r) |
| 1007 | 1018 | { |
| 1019 | nc_state *state = space->machine->driver_data<nc_state>(); |
| 1008 | 1020 | running_device *printer = space->machine->device("centronics"); |
| 1009 | 1021 | int nc_card_battery_status = 0x0fc; |
| 1010 | 1022 | |
| r9667 | r9668 | |
| 1012 | 1024 | nc_card_battery_status |= centronics_ack_r(printer); |
| 1013 | 1025 | nc_card_battery_status |= centronics_busy_r(printer) << 1; |
| 1014 | 1026 | |
| 1015 | | if (nc_card_status) |
| 1027 | if (state->card_status) |
| 1016 | 1028 | { |
| 1017 | 1029 | /* card present */ |
| 1018 | 1030 | nc_card_battery_status &=~(1<<7); |
| r9667 | r9668 | |
| 1029 | 1041 | nc_card_battery_status |= (1<<5); |
| 1030 | 1042 | nc_card_battery_status &= ~((1<<2) | (1<<3)); |
| 1031 | 1043 | |
| 1032 | | return nc_card_battery_status; |
| 1044 | return nc_card_battery_status; |
| 1033 | 1045 | } |
| 1034 | 1046 | |
| 1035 | 1047 | static WRITE8_HANDLER(nc100_memory_card_wait_state_w) |
| r9667 | r9668 | |
| 1190 | 1202 | #if 0 |
| 1191 | 1203 | void nc150_init_machine(running_machine *machine) |
| 1192 | 1204 | { |
| 1193 | | nc_membank_internal_ram_mask = 7; |
| 1205 | nc_state *state = machine->driver_data<nc_state>(); |
| 1206 | state->membank_internal_ram_mask = 7; |
| 1194 | 1207 | |
| 1195 | | nc_membank_card_ram_mask = 0x03f; |
| 1208 | state->membank_card_ram_mask = 0x03f; |
| 1196 | 1209 | |
| 1197 | 1210 | nc_common_init_machine(machine); |
| 1198 | 1211 | } |
| r9667 | r9668 | |
| 1206 | 1219 | #ifdef UNUSED_FUNCTION |
| 1207 | 1220 | static WRITE8_HANDLER(nc200_display_memory_start_w) |
| 1208 | 1221 | { |
| 1222 | nc_state *state = space->machine->driver_data<nc_state>(); |
| 1209 | 1223 | /* bit 7: A15 */ |
| 1210 | 1224 | /* bit 6: A14 */ |
| 1211 | 1225 | /* bit 5: A13 */ |
| 1212 | 1226 | /* bit 4-0: not used */ |
| 1213 | | nc_display_memory_start = (data & 0x0e0)<<(12-4); |
| 1227 | state->display_memory_start = (data & 0x0e0)<<(12-4); |
| 1214 | 1228 | |
| 1215 | | LOG(("disp memory w: %04x\n", (int) nc_display_memory_start)); |
| 1229 | LOG(("disp memory w: %04x\n", (int) state->display_memory_start)); |
| 1216 | 1230 | } |
| 1217 | 1231 | #endif |
| 1218 | 1232 | |
| 1219 | 1233 | |
| 1220 | 1234 | static WRITE_LINE_DEVICE_HANDLER( nc200_centronics_ack_w ) |
| 1221 | 1235 | { |
| 1236 | nc_state *drvstate = device->machine->driver_data<nc_state>(); |
| 1222 | 1237 | if (state) |
| 1223 | | nc_irq_status |= 0x01; |
| 1238 | drvstate->irq_status |= 0x01; |
| 1224 | 1239 | else |
| 1225 | | nc_irq_status &= ~0x01; |
| 1240 | drvstate->irq_status &= ~0x01; |
| 1226 | 1241 | |
| 1227 | 1242 | /* trigger an int if the irq is set */ |
| 1228 | 1243 | nc_update_interrupts(device->machine); |
| r9667 | r9668 | |
| 1239 | 1254 | |
| 1240 | 1255 | /* assumption. nc200 uses the same uart chip. The rxrdy and txrdy are combined |
| 1241 | 1256 | together with a or to generate a single interrupt */ |
| 1242 | | static UINT8 nc200_uart_interrupt_irq; |
| 1243 | 1257 | |
| 1244 | 1258 | static void nc200_refresh_uart_interrupt(running_machine *machine) |
| 1245 | 1259 | { |
| 1246 | | nc_irq_latch &=~(1<<2); |
| 1260 | nc_state *state = machine->driver_data<nc_state>(); |
| 1261 | state->irq_latch &=~(1<<2); |
| 1247 | 1262 | |
| 1248 | 1263 | /* uart enabled? */ |
| 1249 | | if ((nc_uart_control & (1<<3))==0) |
| 1264 | if ((state->uart_control & (1<<3))==0) |
| 1250 | 1265 | { |
| 1251 | | if ((nc200_uart_interrupt_irq & 0x03)!=0) |
| 1266 | if ((state->nc200_uart_interrupt_irq & 0x03)!=0) |
| 1252 | 1267 | { |
| 1253 | | nc_irq_latch |= (1<<2); |
| 1268 | state->irq_latch |= (1<<2); |
| 1254 | 1269 | } |
| 1255 | 1270 | } |
| 1256 | 1271 | nc_update_interrupts(machine); |
| r9667 | r9668 | |
| 1258 | 1273 | |
| 1259 | 1274 | static void nc200_txrdy_callback(running_device *device, int state) |
| 1260 | 1275 | { |
| 1261 | | // nc200_uart_interrupt_irq &=~(1<<0); |
| 1276 | //nc_state *drvstate = machine->driver_data<nc_state>(); |
| 1277 | // drvstate->nc200_uart_interrupt_irq &=~(1<<0); |
| 1262 | 1278 | // |
| 1263 | 1279 | // if (state) |
| 1264 | 1280 | // { |
| 1265 | | // nc200_uart_interrupt_irq |=(1<<0); |
| 1281 | // drvstate->nc200_uart_interrupt_irq |=(1<<0); |
| 1266 | 1282 | // } |
| 1267 | 1283 | // |
| 1268 | 1284 | // nc200_refresh_uart_interrupt(device->machine); |
| r9667 | r9668 | |
| 1270 | 1286 | |
| 1271 | 1287 | static void nc200_rxrdy_callback(running_device *device, int state) |
| 1272 | 1288 | { |
| 1273 | | nc200_uart_interrupt_irq &=~(1<<1); |
| 1289 | nc_state *drvstate = device->machine->driver_data<nc_state>(); |
| 1290 | drvstate->nc200_uart_interrupt_irq &=~(1<<1); |
| 1274 | 1291 | |
| 1275 | 1292 | if (state) |
| 1276 | 1293 | { |
| 1277 | | nc200_uart_interrupt_irq |=(1<<1); |
| 1294 | drvstate->nc200_uart_interrupt_irq |=(1<<1); |
| 1278 | 1295 | } |
| 1279 | 1296 | |
| 1280 | 1297 | nc200_refresh_uart_interrupt(device->machine); |
| r9667 | r9668 | |
| 1290 | 1307 | |
| 1291 | 1308 | static WRITE_LINE_DEVICE_HANDLER( nc200_fdc_interrupt ) |
| 1292 | 1309 | { |
| 1310 | nc_state *drvstate = device->machine->driver_data<nc_state>(); |
| 1293 | 1311 | #if 0 |
| 1294 | | nc_irq_latch &=~(1<<5); |
| 1312 | drvstate->irq_latch &=~(1<<5); |
| 1295 | 1313 | |
| 1296 | 1314 | if (state) |
| 1297 | 1315 | { |
| 1298 | | nc_irq_latch |=(1<<5); |
| 1316 | drvstate->irq_latch |=(1<<5); |
| 1299 | 1317 | } |
| 1300 | 1318 | #endif |
| 1301 | | nc_irq_status &=~(1<<5); |
| 1319 | drvstate->irq_status &=~(1<<5); |
| 1302 | 1320 | |
| 1303 | 1321 | if (state) |
| 1304 | 1322 | { |
| 1305 | | nc_irq_status |=(1<<5); |
| 1323 | drvstate->irq_status |=(1<<5); |
| 1306 | 1324 | } |
| 1307 | 1325 | |
| 1308 | 1326 | nc_update_interrupts(device->machine); |
| r9667 | r9668 | |
| 1320 | 1338 | #ifdef UNUSED_FUNCTION |
| 1321 | 1339 | static void nc200_floppy_drive_index_callback(int drive_id) |
| 1322 | 1340 | { |
| 1341 | nc_state *state = machine->driver_data<nc_state>(); |
| 1323 | 1342 | LOG_DEBUG(("nc200 index pulse\n")); |
| 1324 | | // nc_irq_status |= (1<<4); |
| 1343 | // state->irq_status |= (1<<4); |
| 1325 | 1344 | |
| 1326 | 1345 | // nc_update_interrupts(Machine); |
| 1327 | 1346 | } |
| r9667 | r9668 | |
| 1329 | 1348 | |
| 1330 | 1349 | static MACHINE_RESET( nc200 ) |
| 1331 | 1350 | { |
| 1351 | nc_state *state = machine->driver_data<nc_state>(); |
| 1332 | 1352 | /* 512k of rom */ |
| 1333 | | nc_membank_rom_mask = 0x1f; |
| 1353 | state->membank_rom_mask = 0x1f; |
| 1334 | 1354 | |
| 1335 | | nc_membank_internal_ram_mask = 7; |
| 1355 | state->membank_internal_ram_mask = 7; |
| 1336 | 1356 | |
| 1337 | | nc_membank_card_ram_mask = 0x03f; |
| 1357 | state->membank_card_ram_mask = 0x03f; |
| 1338 | 1358 | |
| 1339 | | nc_common_init_machine(machine); |
| 1359 | nc_common_init_machine(machine); |
| 1340 | 1360 | |
| 1341 | | nc200_uart_interrupt_irq = 0; |
| 1361 | state->nc200_uart_interrupt_irq = 0; |
| 1342 | 1362 | |
| 1343 | 1363 | nc_common_open_stream_for_reading(machine); |
| 1344 | 1364 | nc_common_restore_memory_from_stream(machine); |
| 1345 | | nc_common_close_stream(); |
| 1365 | nc_common_close_stream(machine); |
| 1346 | 1366 | |
| 1347 | 1367 | /* fdc, serial */ |
| 1348 | | nc_irq_latch_mask = /*(1<<5) |*/ (1<<2); |
| 1368 | state->irq_latch_mask = /*(1<<5) |*/ (1<<2); |
| 1349 | 1369 | |
| 1350 | | nc200_video_set_backlight(0); |
| 1370 | nc200_video_set_backlight(machine, 0); |
| 1351 | 1371 | } |
| 1352 | 1372 | |
| 1353 | 1373 | static void nc200_machine_stop(running_machine &machine) |
| 1354 | 1374 | { |
| 1355 | 1375 | nc_common_open_stream_for_writing(&machine); |
| 1356 | 1376 | nc_common_store_memory_to_stream(&machine); |
| 1357 | | nc_common_close_stream(); |
| 1377 | nc_common_close_stream(&machine); |
| 1358 | 1378 | } |
| 1359 | 1379 | |
| 1360 | 1380 | static MACHINE_START( nc200 ) |
| 1361 | 1381 | { |
| 1362 | | nc_type = NC_TYPE_200; |
| 1382 | nc_state *state = machine->driver_data<nc_state>(); |
| 1383 | state->type = NC_TYPE_200; |
| 1363 | 1384 | |
| 1364 | 1385 | machine->add_notifier(MACHINE_NOTIFY_EXIT, nc200_machine_stop); |
| 1365 | 1386 | |
| 1366 | 1387 | /* keyboard timer */ |
| 1367 | | nc_keyboard_timer = timer_alloc(machine, nc_keyboard_timer_callback, NULL); |
| 1368 | | timer_adjust_oneshot(nc_keyboard_timer, ATTOTIME_IN_MSEC(10), 0); |
| 1388 | state->keyboard_timer = timer_alloc(machine, nc_keyboard_timer_callback, NULL); |
| 1389 | timer_adjust_oneshot(state->keyboard_timer, ATTOTIME_IN_MSEC(10), 0); |
| 1369 | 1390 | |
| 1370 | 1391 | /* dummy timer */ |
| 1371 | 1392 | timer_pulse(machine, ATTOTIME_IN_HZ(50), NULL, 0, dummy_timer_callback); |
| 1372 | 1393 | |
| 1373 | 1394 | /* serial timer */ |
| 1374 | | nc_serial_timer = timer_alloc(machine, nc_serial_timer_callback, NULL); |
| 1395 | state->serial_timer = timer_alloc(machine, nc_serial_timer_callback, NULL); |
| 1375 | 1396 | } |
| 1376 | 1397 | |
| 1377 | 1398 | /* |
| r9667 | r9668 | |
| 1391 | 1412 | /* nc200 version of card/battery status */ |
| 1392 | 1413 | static READ8_HANDLER(nc200_card_battery_status_r) |
| 1393 | 1414 | { |
| 1415 | nc_state *state = space->machine->driver_data<nc_state>(); |
| 1394 | 1416 | int nc_card_battery_status = 0x0ff; |
| 1395 | 1417 | |
| 1396 | 1418 | /* enough power */ |
| r9667 | r9668 | |
| 1401 | 1423 | and there is enough power for disk usage */ |
| 1402 | 1424 | nc_card_battery_status &=~((1<<5) | (1<<2) | (1<<0)); |
| 1403 | 1425 | |
| 1404 | | if (nc_card_status) |
| 1426 | if (state->card_status) |
| 1405 | 1427 | { |
| 1406 | 1428 | /* card present */ |
| 1407 | 1429 | nc_card_battery_status&=~(1<<7); |
| r9667 | r9668 | |
| 1435 | 1457 | |
| 1436 | 1458 | static WRITE8_HANDLER(nc200_uart_control_w) |
| 1437 | 1459 | { |
| 1438 | | /* int reset_fdc = (nc_uart_control^data) & (1<<5); */ |
| 1460 | nc_state *state = space->machine->driver_data<nc_state>(); |
| 1461 | /* int reset_fdc = (state->uart_control^data) & (1<<5); */ |
| 1439 | 1462 | |
| 1440 | 1463 | nc_uart_control_w(space, offset,data); |
| 1441 | 1464 | |
| 1442 | 1465 | if (data & (1<<3)) |
| 1443 | 1466 | { |
| 1444 | | nc200_uart_interrupt_irq &=~3; |
| 1467 | state->nc200_uart_interrupt_irq &=~3; |
| 1445 | 1468 | |
| 1446 | 1469 | nc200_refresh_uart_interrupt(space->machine); |
| 1447 | 1470 | } |
| r9667 | r9668 | |
| 1481 | 1504 | { |
| 1482 | 1505 | LOG_DEBUG(("nc200 power off: PC: %04x %02x\n", cpu_get_pc(space->machine->device("maincpu")), data)); |
| 1483 | 1506 | |
| 1484 | | nc200_video_set_backlight(((data ^ (1 << 2)) >> 2) & 0x01); |
| 1507 | nc200_video_set_backlight(space->machine, ((data ^ (1 << 2)) >> 2) & 0x01); |
| 1485 | 1508 | } |
| 1486 | 1509 | |
| 1487 | 1510 | static ADDRESS_MAP_START(nc200_io, ADDRESS_SPACE_IO, 8) |
| r9667 | r9668 | |
| 1662 | 1685 | |
| 1663 | 1686 | /**********************************************************************************************************/ |
| 1664 | 1687 | |
| 1665 | | static MACHINE_CONFIG_START( nc100, driver_device ) |
| 1688 | static MACHINE_CONFIG_START( nc100, nc_state ) |
| 1666 | 1689 | /* basic machine hardware */ |
| 1667 | 1690 | MDRV_CPU_ADD("maincpu", Z80, /*6000000*/ 4606000) /* Russell Marks says this is more accurate */ |
| 1668 | 1691 | MDRV_CPU_PROGRAM_MAP(nc_map) |