src/mess/machine/trs80.c
| r3285 | r3286 | |
| 18 | 18 | |
| 19 | 19 | /* Devices */ |
| 20 | 20 | #include "devices/basicdsk.h" |
| 21 | #include "devices/cassette.h" |
| 21 | 22 | #include "devices/flopdrv.h" |
| 22 | 23 | |
| 23 | 24 | |
| r3285 | r3286 | |
| 49 | 50 | #endif |
| 50 | 51 | static UINT8 irq_mask = 0; |
| 51 | 52 | |
| 52 | | static UINT8 *cas_buff = NULL; |
| 53 | | static UINT32 cas_size = 0; |
| 54 | | |
| 55 | | /* current tape file handles */ |
| 56 | | static mame_file *tape_put_file = NULL; |
| 57 | | static mame_file *tape_get_file = NULL; |
| 58 | | |
| 59 | | /* tape buffer for the first eight bytes at write (to extract a filename) */ |
| 60 | | static UINT8 tape_buffer[8]; |
| 61 | | |
| 62 | | static int tape_count = 0; /* file offset within tape file */ |
| 63 | | static int put_bit_count = 0; /* number of sync and data bits that were written */ |
| 64 | | static int get_bit_count = 0; /* number of sync and data bits to read */ |
| 65 | | static int tape_bits = 0; /* sync and data bits mask */ |
| 66 | | static int tape_time = 0; /* time in cycles for the next bit at read */ |
| 67 | | static int in_sync = 0; /* flag if writing to tape detected the sync header A5 already */ |
| 68 | | static int put_cycles = 0; /* cycle count at last output port change */ |
| 69 | | static int get_cycles = 0; /* cycle count at last input port read */ |
| 70 | | |
| 71 | | static void tape_put_byte(UINT8 value); |
| 72 | | static void tape_get_open(running_machine *machine); |
| 73 | | static void tape_put_close(running_machine *machine); |
| 74 | | |
| 75 | 53 | #define FW TRS80_FONT_W |
| 76 | 54 | #define FH TRS80_FONT_H |
| 77 | 55 | |
| 56 | static double old_cassette_val; |
| 57 | static UINT8 cassette_data; |
| 58 | static emu_timer *cassette_data_timer; |
| 78 | 59 | |
| 79 | | static TIMER_CALLBACK(cas_copy_callback) |
| 60 | static TIMER_CALLBACK( cassette_data_callback ) |
| 80 | 61 | { |
| 81 | | UINT16 entry = 0, block_ofs = 0, block_len = 0; |
| 82 | | unsigned offs = 0; |
| 62 | double new_val = cassette_input(device_list_find_by_tag( machine->config->devicelist, CASSETTE, "cassette" )); |
| 83 | 63 | |
| 84 | | while( cas_size > 3 ) |
| 64 | /* Check for HI-LO transition */ |
| 65 | if ( old_cassette_val > -0.2 && new_val < -0.2 ) |
| 85 | 66 | { |
| 86 | | UINT8 data = cas_buff[offs++]; |
| 87 | | |
| 88 | | switch( data ) |
| 89 | | { |
| 90 | | case 0x3c: /* CAS file header */ |
| 91 | | block_len = cas_buff[offs++]; |
| 92 | | /* on CMD files size=zero means size 256 */ |
| 93 | | if( block_len == 0 ) |
| 94 | | block_len += 256; |
| 95 | | block_ofs = cas_buff[offs++]; |
| 96 | | block_ofs += 256 * cas_buff[offs++]; |
| 97 | | cas_size -= 4; |
| 98 | | LOG(("cas_copy_callback block ($%02X) %d at $%04X\n", data, block_len, block_ofs)); |
| 99 | | while( block_len && cas_size ) |
| 100 | | { |
| 101 | | program_write_byte(block_ofs, cas_buff[offs]); |
| 102 | | offs++; |
| 103 | | block_ofs++; |
| 104 | | block_len--; |
| 105 | | cas_size--; |
| 106 | | } |
| 107 | | /* skip the CHKSUM byte */ |
| 108 | | offs++; |
| 109 | | break; |
| 110 | | case 0x78: |
| 111 | | entry = cas_buff[offs++]; |
| 112 | | entry += 256 * cas_buff[offs++]; |
| 113 | | LOG(("cas_copy_callback entry ($%02X) at $%04X\n", data, entry)); |
| 114 | | cas_size -= 3; |
| 115 | | break; |
| 116 | | default: |
| 117 | | cas_size--; |
| 118 | | } |
| 67 | cassette_data |= 0x80; |
| 119 | 68 | } |
| 120 | | cas_size = 0; |
| 121 | | activecpu_set_reg(Z80_PC, entry); |
| 69 | old_cassette_val = new_val; |
| 122 | 70 | } |
| 123 | 71 | |
| 124 | | DEVICE_IMAGE_LOAD( trs80_cas ) |
| 125 | | { |
| 126 | | cas_size = image_length(image); |
| 127 | | cas_buff = image_ptr(image); |
| 128 | | if (!cas_buff) |
| 129 | | return INIT_FAIL; |
| 130 | 72 | |
| 131 | | if (cas_buff[1] == 0x55) |
| 132 | | { |
| 133 | | LOG(("trs80_cas_init: loading %s size %d\n", image_filename(image), cas_size)); |
| 134 | | } |
| 135 | | else |
| 136 | | { |
| 137 | | cas_buff = NULL; |
| 138 | | cas_size = 0; |
| 139 | | logerror("trs80_cas_init: CAS file is not in SYSTEM format\n"); |
| 140 | | return 1; |
| 141 | | } |
| 142 | | return 0; |
| 143 | | } |
| 144 | | |
| 145 | | DEVICE_IMAGE_UNLOAD( trs80_cas ) |
| 146 | | { |
| 147 | | cas_buff = NULL; |
| 148 | | cas_size = 0; |
| 149 | | } |
| 150 | | |
| 151 | 73 | QUICKLOAD_LOAD( trs80_cmd ) |
| 152 | 74 | { |
| 153 | 75 | UINT16 entry = 0, block_ofs = 0, block_len = 0; |
| r3285 | r3286 | |
| 282 | 204 | |
| 283 | 205 | static void trs80_fdc_callback(running_machine *machine, wd17xx_state_t event, void *param); |
| 284 | 206 | |
| 207 | |
| 285 | 208 | MACHINE_RESET( trs80 ) |
| 286 | 209 | { |
| 287 | | if (cas_size) |
| 288 | | { |
| 289 | | LOG(("trs80_init_machine: schedule cas_copy_callback (%d)\n", cas_size)); |
| 290 | | timer_set(ATTOTIME_IN_MSEC(500), NULL, 0, cas_copy_callback); |
| 291 | | } |
| 210 | cassette_data = 0x00; |
| 211 | cassette_data_timer = timer_alloc( cassette_data_callback, NULL ); |
| 212 | timer_adjust_periodic( cassette_data_timer, attotime_zero, 0, ATTOTIME_IN_HZ(11025) ); |
| 292 | 213 | } |
| 293 | 214 | |
| 215 | |
| 294 | 216 | DRIVER_INIT( trs80 ) |
| 295 | 217 | { |
| 296 | 218 | UINT8 *FNT = memory_region(machine, "gfx1"); |
| r3285 | r3286 | |
| 354 | 276 | { |
| 355 | 277 | } |
| 356 | 278 | |
| 279 | |
| 357 | 280 | DRIVER_INIT( ht108064 ) |
| 358 | 281 | { |
| 359 | 282 | UINT8 *FNT = memory_region(machine, "gfx1"); |
| r3285 | r3286 | |
| 363 | 286 | } |
| 364 | 287 | } |
| 365 | 288 | |
| 289 | |
| 366 | 290 | MACHINE_START( trs80 ) |
| 367 | 291 | { |
| 368 | 292 | wd17xx_init(machine, WD_TYPE_179X,trs80_fdc_callback, NULL); |
| 369 | | add_exit_callback(machine, tape_put_close); |
| 370 | 293 | } |
| 371 | 294 | |
| 372 | | /************************************* |
| 373 | | * |
| 374 | | * Tape emulation. |
| 375 | | * |
| 376 | | *************************************/ |
| 377 | 295 | |
| 378 | | static void tape_put_byte(UINT8 value) |
| 379 | | { |
| 380 | | if (tape_count < 8) |
| 381 | | { |
| 382 | | tape_buffer[tape_count++] = value; |
| 383 | | if (tape_count == 8) |
| 384 | | { |
| 385 | | /* BASIC tape ? */ |
| 386 | | if (tape_buffer[1] == 0xd3) |
| 387 | | { |
| 388 | | char filename[12+1]; |
| 389 | | UINT8 zeroes[256] = {0,}; |
| 390 | | |
| 391 | | sprintf(filename, "basic%c.cas", tape_buffer[4]); |
| 392 | | mame_fopen(SEARCHPATH_IMAGE, filename, OPEN_FLAG_READ | OPEN_FLAG_WRITE, &tape_put_file); |
| 393 | | mame_fwrite(tape_put_file, zeroes, 256); |
| 394 | | mame_fwrite(tape_put_file, tape_buffer, 8); |
| 395 | | } |
| 396 | | else |
| 397 | | /* SYSTEM tape ? */ |
| 398 | | if (tape_buffer[1] == 0x55) |
| 399 | | { |
| 400 | | char filename[12+1]; |
| 401 | | UINT8 zeroes[256] = {0,}; |
| 402 | | |
| 403 | | sprintf(filename, "%-6.6s.cas", tape_buffer+2); |
| 404 | | mame_fopen(SEARCHPATH_IMAGE, filename, OPEN_FLAG_READ | OPEN_FLAG_WRITE, &tape_put_file); |
| 405 | | mame_fwrite(tape_put_file, zeroes, 256); |
| 406 | | mame_fwrite(tape_put_file, tape_buffer, 8); |
| 407 | | } |
| 408 | | } |
| 409 | | } |
| 410 | | else |
| 411 | | { |
| 412 | | if (tape_put_file) |
| 413 | | mame_fwrite(tape_put_file, &value, 1); |
| 414 | | } |
| 415 | | } |
| 416 | | |
| 417 | | static void tape_put_close(running_machine *machine) |
| 418 | | { |
| 419 | | /* file open ? */ |
| 420 | | if (tape_put_file) |
| 421 | | { |
| 422 | | if (put_bit_count) |
| 423 | | { |
| 424 | | UINT8 value; |
| 425 | | while (put_bit_count < 16) |
| 426 | | { |
| 427 | | tape_bits <<= 1; |
| 428 | | put_bit_count++; |
| 429 | | } |
| 430 | | value = 0; |
| 431 | | if (tape_bits & 0x8000) value |= 0x80; |
| 432 | | if (tape_bits & 0x2000) value |= 0x40; |
| 433 | | if (tape_bits & 0x0800) value |= 0x20; |
| 434 | | if (tape_bits & 0x0200) value |= 0x10; |
| 435 | | if (tape_bits & 0x0080) value |= 0x08; |
| 436 | | if (tape_bits & 0x0020) value |= 0x04; |
| 437 | | if (tape_bits & 0x0008) value |= 0x02; |
| 438 | | if (tape_bits & 0x0002) value |= 0x01; |
| 439 | | tape_put_byte(value); |
| 440 | | } |
| 441 | | mame_fclose(tape_put_file); |
| 442 | | } |
| 443 | | tape_count = 0; |
| 444 | | tape_put_file = 0; |
| 445 | | } |
| 446 | | |
| 447 | | static void tape_get_byte(running_machine *machine) |
| 448 | | { |
| 449 | | int count; |
| 450 | | UINT8 value; |
| 451 | | if (tape_get_file) |
| 452 | | { |
| 453 | | count = mame_fread(tape_get_file, &value, 1); |
| 454 | | if (count == 0) |
| 455 | | { |
| 456 | | value = 0; |
| 457 | | mame_fclose(tape_get_file); |
| 458 | | tape_get_file = 0; |
| 459 | | } |
| 460 | | tape_bits |= 0xaaaa; |
| 461 | | if (value & 0x80) tape_bits ^= 0x4000; |
| 462 | | if (value & 0x40) tape_bits ^= 0x1000; |
| 463 | | if (value & 0x20) tape_bits ^= 0x0400; |
| 464 | | if (value & 0x10) tape_bits ^= 0x0100; |
| 465 | | if (value & 0x08) tape_bits ^= 0x0040; |
| 466 | | if (value & 0x04) tape_bits ^= 0x0010; |
| 467 | | if (value & 0x02) tape_bits ^= 0x0004; |
| 468 | | if (value & 0x01) tape_bits ^= 0x0001; |
| 469 | | get_bit_count = 16; |
| 470 | | tape_count++; |
| 471 | | } |
| 472 | | } |
| 473 | | |
| 474 | | static void tape_get_open(running_machine *machine) |
| 475 | | { |
| 476 | | /* TODO: remove this */ |
| 477 | | unsigned char *RAM = memory_region(machine, "main"); |
| 478 | | |
| 479 | | if (!tape_get_file) |
| 480 | | { |
| 481 | | char filename[12+1]; |
| 482 | | |
| 483 | | sprintf(filename, "%-6.6s.cas", RAM + 0x41e8); |
| 484 | | logerror("filename %s\n", filename); |
| 485 | | mame_fopen(SEARCHPATH_IMAGE, filename, OPEN_FLAG_READ, &tape_get_file); |
| 486 | | tape_count = 0; |
| 487 | | } |
| 488 | | } |
| 489 | | |
| 490 | 296 | /************************************* |
| 491 | 297 | * |
| 492 | 298 | * Port handlers. |
| 493 | 299 | * |
| 494 | 300 | *************************************/ |
| 495 | 301 | |
| 302 | |
| 496 | 303 | READ8_HANDLER( trs80_port_xx_r ) |
| 497 | 304 | { |
| 498 | 305 | return 0; |
| 499 | 306 | } |
| 500 | 307 | |
| 308 | |
| 501 | 309 | WRITE8_HANDLER( trs80_port_ff_w ) |
| 502 | 310 | { |
| 503 | | int changes = trs80_port_ff ^ data; |
| 311 | static const double levels[4] = { 0.0, -1.0, 0.0, 1.0 }; |
| 312 | const device_config *cass = device_list_find_by_tag( machine->config->devicelist, CASSETTE, "cassette" ); |
| 504 | 313 | |
| 505 | | /* tape output changed ? */ |
| 506 | | if( changes & 0x03 ) |
| 507 | | { |
| 508 | | /* virtual tape ? */ |
| 509 | | if( input_port_read(machine, "CONFIG") & 0x20 ) |
| 510 | | { |
| 511 | | int now_cycles = activecpu_gettotalcycles(); |
| 512 | | int diff = now_cycles - put_cycles; |
| 513 | | UINT8 value; |
| 514 | | /* overrun since last write ? */ |
| 515 | | if (diff > 4000) |
| 516 | | { |
| 517 | | /* reset tape output */ |
| 518 | | tape_put_close(machine); |
| 519 | | put_bit_count = tape_bits = in_sync = 0; |
| 520 | | } |
| 521 | | else |
| 522 | | /* just wrote the interesting value ? */ |
| 523 | | if( (data & 0x03) == 0x01 ) |
| 524 | | { |
| 525 | | /* change within time for a 1 bit ? */ |
| 526 | | if( diff < 2000 ) |
| 527 | | { |
| 528 | | tape_bits = (tape_bits << 1) | 1; |
| 529 | | /* in sync already ? */ |
| 530 | | if( in_sync ) |
| 531 | | { |
| 532 | | /* count 1 bit */ |
| 533 | | put_bit_count += 1; |
| 534 | | } |
| 535 | | else |
| 536 | | { |
| 537 | | /* try to find sync header A5 */ |
| 538 | | if( tape_bits == 0xcc33 ) |
| 539 | | { |
| 540 | | in_sync = 1; |
| 541 | | put_bit_count = 16; |
| 542 | | } |
| 543 | | } |
| 544 | | } |
| 545 | | else /* no change indicates a 0 bit */ |
| 546 | | { |
| 547 | | /* shift twice */ |
| 548 | | tape_bits <<= 2; |
| 549 | | /* in sync already ? */ |
| 550 | | if( in_sync ) |
| 551 | | put_bit_count += 2; |
| 552 | | } |
| 314 | cassette_change_state( cass, ( data & 0x04 ) ? CASSETTE_MOTOR_ENABLED : CASSETTE_MOTOR_DISABLED, CASSETTE_MASK_MOTOR ); |
| 553 | 315 | |
| 554 | | /* collected 8 sync plus 8 data bits ? */ |
| 555 | | if( put_bit_count >= 16 ) |
| 556 | | { |
| 557 | | /* extract data bits to value */ |
| 558 | | value = 0; |
| 559 | | if (tape_bits & 0x8000) value |= 0x80; |
| 560 | | if (tape_bits & 0x2000) value |= 0x40; |
| 561 | | if (tape_bits & 0x0800) value |= 0x20; |
| 562 | | if (tape_bits & 0x0200) value |= 0x10; |
| 563 | | if (tape_bits & 0x0080) value |= 0x08; |
| 564 | | if (tape_bits & 0x0020) value |= 0x04; |
| 565 | | if (tape_bits & 0x0008) value |= 0x02; |
| 566 | | if (tape_bits & 0x0002) value |= 0x01; |
| 567 | | put_bit_count -= 16; |
| 568 | | tape_bits = 0; |
| 569 | | tape_put_byte(value); |
| 570 | | } |
| 571 | | } |
| 572 | | /* remember the cycle count of this write */ |
| 573 | | put_cycles = now_cycles; |
| 574 | | } |
| 575 | | else |
| 576 | | { |
| 577 | | switch( data & 0x03 ) |
| 578 | | { |
| 579 | | case 0: /* 0.46 volts */ |
| 580 | | speaker_level_w(0,1); |
| 581 | | break; |
| 582 | | case 1: |
| 583 | | case 3: /* 0.00 volts */ |
| 584 | | speaker_level_w(0,0); |
| 585 | | break; |
| 586 | | case 2: /* 0.85 volts */ |
| 587 | | speaker_level_w(0,2); |
| 588 | | break; |
| 589 | | } |
| 590 | | } |
| 591 | | } |
| 316 | cassette_output( cass, levels[data & 0x03]); |
| 592 | 317 | |
| 318 | cassette_data &= ~0x80; |
| 593 | 319 | trs80_port_ff = data; |
| 594 | 320 | } |
| 595 | 321 | |
| 322 | |
| 596 | 323 | READ8_HANDLER( trs80_port_ff_r ) |
| 597 | 324 | { |
| 598 | | int now_cycles = activecpu_gettotalcycles(); |
| 599 | | /* virtual tape ? */ |
| 600 | | if( input_port_read(machine, "CONFIG") & 0x20 ) |
| 601 | | { |
| 602 | | int diff = now_cycles - get_cycles; |
| 603 | | /* overrun since last read ? */ |
| 604 | | if (diff >= 4000) |
| 605 | | { |
| 606 | | if (tape_get_file) |
| 607 | | { |
| 608 | | mame_fclose(tape_get_file); |
| 609 | | tape_get_file = 0; |
| 610 | | } |
| 611 | | get_bit_count = tape_bits = tape_time = 0; |
| 612 | | } |
| 613 | | else /* check what he will get for input */ |
| 614 | | { |
| 615 | | /* count down cycles */ |
| 616 | | tape_time -= diff; |
| 617 | | /* time for the next sync or data bit ? */ |
| 618 | | if (tape_time <= 0) |
| 619 | | { |
| 620 | | /* approx. time for a bit */ |
| 621 | | tape_time += 1570; |
| 622 | | /* need to read get new data ? */ |
| 623 | | if (--get_bit_count <= 0) |
| 624 | | { |
| 625 | | tape_get_open(machine); |
| 626 | | tape_get_byte(machine); |
| 627 | | } |
| 628 | | /* shift next sync or data bit to bit 16 */ |
| 629 | | tape_bits <<= 1; |
| 630 | | /* if bit is set, set trs80_port_ff bit 4 |
| 631 | | which is then read as bit 7 */ |
| 632 | | if (tape_bits & 0x10000) |
| 633 | | trs80_port_ff |= 0x80; |
| 634 | | } |
| 635 | | } |
| 636 | | /* remember the cycle count of this read */ |
| 637 | | get_cycles = now_cycles; |
| 638 | | } |
| 639 | | return (trs80_port_ff << 3) & 0xc0; |
| 325 | return cassette_data | 0x7F; |
| 640 | 326 | } |
| 641 | 327 | |
| 642 | 328 | /************************************* |
src/mess/drivers/trs80.c
| r3285 | r3286 | |
| 87 | 87 | |
| 88 | 88 | /* Devices */ |
| 89 | 89 | #include "devices/basicdsk.h" |
| 90 | #include "devices/cassette.h" |
| 90 | 91 | |
| 91 | 92 | |
| 92 | 93 | #define FW TRS80_FONT_W |
| r3285 | r3286 | |
| 402 | 403 | |
| 403 | 404 | /* devices */ |
| 404 | 405 | MDRV_QUICKLOAD_ADD(trs80_cmd, "cmd", 0.5) |
| 406 | |
| 407 | MDRV_CASSETTE_ADD( "cassette", default_cassette_config ) |
| 405 | 408 | MACHINE_DRIVER_END |
| 406 | 409 | |
| 407 | 410 | |
| r3285 | r3286 | |
| 524 | 527 | ROM_END |
| 525 | 528 | |
| 526 | 529 | |
| 527 | | static void trs80_cassette_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info) |
| 528 | | { |
| 529 | | /* cassette */ |
| 530 | | switch(state) |
| 531 | | { |
| 532 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 533 | | case MESS_DEVINFO_INT_TYPE: info->i = IO_CASSETTE; break; |
| 534 | | case MESS_DEVINFO_INT_READABLE: info->i = 1; break; |
| 535 | | case MESS_DEVINFO_INT_WRITEABLE: info->i = 0; break; |
| 536 | | case MESS_DEVINFO_INT_CREATABLE: info->i = 0; break; |
| 537 | | case MESS_DEVINFO_INT_COUNT: info->i = 1; break; |
| 538 | | |
| 539 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 540 | | case MESS_DEVINFO_PTR_LOAD: info->load = DEVICE_IMAGE_LOAD_NAME(trs80_cas); break; |
| 541 | | case MESS_DEVINFO_PTR_UNLOAD: info->unload = DEVICE_IMAGE_UNLOAD_NAME(trs80_cas); break; |
| 542 | | |
| 543 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 544 | | case MESS_DEVINFO_STR_FILE_EXTENSIONS: strcpy(info->s = device_temp_str(), "cas"); break; |
| 545 | | } |
| 546 | | } |
| 547 | | |
| 548 | | static SYSTEM_CONFIG_START(trs80) |
| 549 | | CONFIG_DEVICE(trs80_cassette_getinfo) |
| 550 | | SYSTEM_CONFIG_END |
| 551 | | |
| 552 | | |
| 553 | 530 | static void trs8012_floppy_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info) |
| 554 | 531 | { |
| 555 | 532 | /* floppy */ |
| r3285 | r3286 | |
| 569 | 546 | } |
| 570 | 547 | |
| 571 | 548 | static SYSTEM_CONFIG_START(trs8012) |
| 572 | | CONFIG_IMPORT_FROM(trs80) |
| 573 | 549 | CONFIG_DEVICE(trs8012_floppy_getinfo) |
| 574 | 550 | SYSTEM_CONFIG_END |
| 575 | 551 | |
| 576 | 552 | |
| 577 | 553 | /* YEAR NAME PARENT COMPAT MACHINE INPUT INIT CONFIG COMPANY FULLNAME */ |
| 578 | | COMP( 1977, trs80, 0, 0, level1, trs80, trs80, trs80, "Tandy Radio Shack", "TRS-80 Model I (Level I Basic)" , 0) |
| 554 | COMP( 1977, trs80, 0, 0, level1, trs80, trs80, 0, "Tandy Radio Shack", "TRS-80 Model I (Level I Basic)" , 0) |
| 579 | 555 | COMP( 1978, trs80l2, trs80, 0, model1, trs80, trs80, trs8012, "Tandy Radio Shack", "TRS-80 Model I (Level II Basic)" , 0) |
| 580 | 556 | COMP( 1980, sys80, trs80, 0, model1, trs80, trs80, trs8012, "EACA Computers Ltd.","System-80" , 0) |
| 581 | 557 | COMP( 1981, lnw80, trs80, 0, model1, trs80, lnw80, trs8012, "LNW Research","LNW-80", 0 ) |