src/mess/formats/ti85_ser.c
| r6321 | r6322 | |
| 88 | 88 | UINT8 white_out; /* signal line from machine */ |
| 89 | 89 | UINT8 red_in; /* signal line to machine */ |
| 90 | 90 | UINT8 white_in; /* signal line to machine */ |
| 91 | UINT8 *receive_buffer; |
| 92 | UINT8 *receive_data; |
| 93 | ti85_serial_data stream; |
| 91 | 94 | } ti85serial_state; |
| 92 | 95 | |
| 93 | | static int ti85_serial_transfer_type = TI85_SEND_VARIABLES; |
| 94 | | static UINT8 * ti85_receive_buffer; |
| 95 | | static UINT8 * ti85_receive_data; |
| 96 | | static ti85_serial_data ti85_serial_stream; |
| 97 | 96 | |
| 98 | | |
| 99 | 97 | INLINE ti85serial_state *get_token(const device_config *device) |
| 100 | 98 | { |
| 101 | 99 | assert(device != NULL); |
| r6321 | r6322 | |
| 131 | 129 | } |
| 132 | 130 | |
| 133 | 131 | |
| 134 | | static void ti85_free_serial_data_memory (running_machine *machine) |
| 132 | static void ti85_free_serial_data_memory (const device_config *device) |
| 135 | 133 | { |
| 136 | | if (ti85_receive_buffer) |
| 134 | ti85serial_state *ti85serial = get_token( device ); |
| 135 | |
| 136 | if (ti85serial->receive_buffer) |
| 137 | 137 | { |
| 138 | | free (ti85_receive_buffer); |
| 139 | | ti85_receive_buffer = NULL; |
| 138 | free (ti85serial->receive_buffer); |
| 139 | ti85serial->receive_buffer = NULL; |
| 140 | 140 | } |
| 141 | | if (ti85_receive_data) |
| 141 | if (ti85serial->receive_data) |
| 142 | 142 | { |
| 143 | | free (ti85_receive_data); |
| 144 | | ti85_receive_data = NULL; |
| 143 | free (ti85serial->receive_data); |
| 144 | ti85serial->receive_data = NULL; |
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | |
| 149 | | static int ti85_alloc_serial_data_memory (UINT32 size) |
| 149 | static int ti85_alloc_serial_data_memory (const device_config *device, UINT32 size) |
| 150 | 150 | { |
| 151 | | if (!ti85_receive_buffer) |
| 151 | ti85serial_state *ti85serial = get_token( device ); |
| 152 | |
| 153 | if (!ti85serial->receive_buffer) |
| 152 | 154 | { |
| 153 | | ti85_receive_buffer = (UINT8*) malloc (8*size*sizeof(UINT8)); |
| 154 | | if (!ti85_receive_buffer) |
| 155 | ti85serial->receive_buffer = (UINT8*) malloc (8*size*sizeof(UINT8)); |
| 156 | if (!ti85serial->receive_buffer) |
| 155 | 157 | return 0; |
| 156 | 158 | } |
| 157 | 159 | |
| 158 | | if (!ti85_receive_data) |
| 160 | if (!ti85serial->receive_data) |
| 159 | 161 | { |
| 160 | | ti85_receive_data = (UINT8*) malloc (size * sizeof(UINT8)); |
| 161 | | if (!ti85_receive_data) |
| 162 | ti85serial->receive_data = (UINT8*) malloc (size * sizeof(UINT8)); |
| 163 | if (!ti85serial->receive_data) |
| 162 | 164 | { |
| 163 | | free (ti85_receive_buffer); |
| 164 | | ti85_receive_buffer = NULL; |
| 165 | free (ti85serial->receive_buffer); |
| 166 | ti85serial->receive_buffer = NULL; |
| 165 | 167 | return 0; |
| 166 | 168 | } |
| 167 | 169 | } |
| r6321 | r6322 | |
| 299 | 301 | } |
| 300 | 302 | |
| 301 | 303 | |
| 302 | | static int ti85_convert_file_data_to_serial_stream (const UINT8* file_data, unsigned int file_size, ti85_serial_data* serial_data, char* calc_type) |
| 304 | static int ti85_convert_file_data_to_serial_stream (const device_config *device, const UINT8* file_data, unsigned int file_size, ti85_serial_data* serial_data, char* calc_type) |
| 303 | 305 | { |
| 306 | ti85serial_state *ti85serial = get_token( device ); |
| 304 | 307 | UINT16 i; |
| 305 | 308 | UINT16 number_of_entries; |
| 306 | 309 | |
| r6321 | r6322 | |
| 339 | 342 | |
| 340 | 343 | if (file_data[0x3b]==0x1d) |
| 341 | 344 | { |
| 342 | | ti85_serial_transfer_type = TI85_SEND_BACKUP; |
| 345 | ti85serial->transfer_type = TI85_SEND_BACKUP; |
| 343 | 346 | ti85_backup_read (file_data, file_size, ti85_entries); |
| 344 | 347 | } |
| 345 | 348 | else |
| 346 | 349 | { |
| 347 | | ti85_serial_transfer_type = TI85_SEND_VARIABLES; |
| 350 | ti85serial->transfer_type = TI85_SEND_VARIABLES; |
| 348 | 351 | ti85_variables_read (file_data, file_size, ti85_entries); |
| 349 | 352 | } |
| 350 | 353 | for (i=0; i<number_of_entries; i++) |
| r6321 | r6322 | |
| 515 | 518 | ti85serial_state *ti85serial = get_token( device ); |
| 516 | 519 | static UINT16 variable_number = 0; |
| 517 | 520 | |
| 518 | | if (!ti85_alloc_serial_data_memory(7)) |
| 521 | if (!ti85_alloc_serial_data_memory(device, 7)) |
| 519 | 522 | ti85serial->status = TI85_SEND_STOP; |
| 520 | 523 | |
| 521 | 524 | switch (ti85serial->status) |
| 522 | 525 | { |
| 523 | 526 | case TI85_SEND_HEADER: |
| 524 | | if(!ti85_send_serial(device, ti85_serial_stream.variables[variable_number].header,ti85_serial_stream.variables[variable_number].header_size)) |
| 527 | if(!ti85_send_serial(device, ti85serial->stream.variables[variable_number].header,ti85serial->stream.variables[variable_number].header_size)) |
| 525 | 528 | { |
| 526 | 529 | ti85serial->status = TI85_RECEIVE_OK_1; |
| 527 | | memset (ti85_receive_data, 0, 7); |
| 528 | | logerror ("Header sended\n"); |
| 530 | memset (ti85serial->receive_data, 0, 7); |
| 531 | logerror ("Header sent\n"); |
| 529 | 532 | } |
| 530 | 533 | break; |
| 531 | 534 | case TI85_RECEIVE_OK_1: |
| 532 | | if(!ti85_receive_serial (device, ti85_receive_buffer, 4*8)) |
| 535 | if(!ti85_receive_serial (device, ti85serial->receive_buffer, 4*8)) |
| 533 | 536 | { |
| 534 | | ti85_convert_stream_to_data (ti85_receive_buffer, 4*8, ti85_receive_data); |
| 537 | ti85_convert_stream_to_data (ti85serial->receive_buffer, 4*8, ti85serial->receive_data); |
| 535 | 538 | ti85serial->status = TI85_RECEIVE_ANSWER_1; |
| 536 | 539 | logerror ("OK received\n"); |
| 537 | 540 | } |
| 538 | 541 | break; |
| 539 | 542 | case TI85_RECEIVE_ANSWER_1: |
| 540 | | if(!ti85_receive_serial (device, ti85_receive_buffer, 4*8)) |
| 543 | if(!ti85_receive_serial (device, ti85serial->receive_buffer, 4*8)) |
| 541 | 544 | { |
| 542 | | ti85_convert_stream_to_data (ti85_receive_buffer, 4*8, ti85_receive_data); |
| 543 | | switch (ti85_receive_data[1]) |
| 545 | ti85_convert_stream_to_data (ti85serial->receive_buffer, 4*8, ti85serial->receive_data); |
| 546 | switch (ti85serial->receive_data[1]) |
| 544 | 547 | { |
| 545 | 548 | case 0x09: //continue |
| 546 | 549 | ti85serial->status = TI85_SEND_OK; |
| r6321 | r6322 | |
| 553 | 556 | } |
| 554 | 557 | break; |
| 555 | 558 | case TI85_RECEIVE_ANSWER_2: |
| 556 | | if(!ti85_receive_serial (device, ti85_receive_buffer+4*8, 1*8)) |
| 559 | if(!ti85_receive_serial (device, ti85serial->receive_buffer+4*8, 1*8)) |
| 557 | 560 | { |
| 558 | | ti85_convert_stream_to_data (ti85_receive_buffer, 5*8, ti85_receive_data); |
| 559 | | switch (ti85_receive_data[4]) |
| 561 | ti85_convert_stream_to_data (ti85serial->receive_buffer, 5*8, ti85serial->receive_data); |
| 562 | switch (ti85serial->receive_data[4]) |
| 560 | 563 | { |
| 561 | 564 | case 0x01: //exit |
| 562 | 565 | case 0x02: //skip |
| r6321 | r6322 | |
| 564 | 567 | break; |
| 565 | 568 | case 0x03: //out of memory |
| 566 | 569 | variable_number = 0; |
| 567 | | ti85_free_serial_data_memory(device->machine); |
| 570 | ti85_free_serial_data_memory(device); |
| 568 | 571 | ti85serial->status = TI85_SEND_STOP; |
| 569 | 572 | break; |
| 570 | 573 | } |
| 571 | 574 | } |
| 572 | 575 | break; |
| 573 | 576 | case TI85_RECEIVE_ANSWER_3: |
| 574 | | if(!ti85_receive_serial (device, ti85_receive_buffer+5*8, 2*8)) |
| 577 | if(!ti85_receive_serial (device, ti85serial->receive_buffer+5*8, 2*8)) |
| 575 | 578 | { |
| 576 | | ti85_convert_stream_to_data (ti85_receive_buffer, 7*8, ti85_receive_data); |
| 577 | | switch (ti85_receive_data[4]) |
| 579 | ti85_convert_stream_to_data (ti85serial->receive_buffer, 7*8, ti85serial->receive_data); |
| 580 | switch (ti85serial->receive_data[4]) |
| 578 | 581 | { |
| 579 | 582 | case 0x01: //exit |
| 580 | 583 | variable_number = 0; |
| 581 | | ti85_free_serial_data_memory(device->machine); |
| 584 | ti85_free_serial_data_memory(device); |
| 582 | 585 | ti85serial->status = TI85_SEND_STOP; |
| 583 | 586 | break; |
| 584 | 587 | case 0x02: //skip |
| r6321 | r6322 | |
| 589 | 592 | } |
| 590 | 593 | break; |
| 591 | 594 | case TI85_SEND_OK: |
| 592 | | if(!ti85_send_serial(device, ti85_serial_stream.variables[variable_number].ok,ti85_serial_stream.variables[variable_number].ok_size)) |
| 595 | if(!ti85_send_serial(device, ti85serial->stream.variables[variable_number].ok,ti85serial->stream.variables[variable_number].ok_size)) |
| 593 | 596 | { |
| 594 | | ti85serial->status = (ti85_receive_data[4]==0x02) ? ((variable_number < ti85_serial_stream.number_of_variables) ? TI85_SEND_HEADER : TI85_SEND_END) : TI85_SEND_DATA; |
| 595 | | memset(ti85_receive_data, 0, 7); |
| 597 | ti85serial->status = (ti85serial->receive_data[4]==0x02) ? ((variable_number < ti85serial->stream.number_of_variables) ? TI85_SEND_HEADER : TI85_SEND_END) : TI85_SEND_DATA; |
| 598 | memset(ti85serial->receive_data, 0, 7); |
| 596 | 599 | } |
| 597 | 600 | break; |
| 598 | 601 | case TI85_SEND_DATA: |
| 599 | | if(!ti85_send_serial(device, ti85_serial_stream.variables[variable_number].data,ti85_serial_stream.variables[variable_number].data_size)) |
| 602 | if(!ti85_send_serial(device, ti85serial->stream.variables[variable_number].data,ti85serial->stream.variables[variable_number].data_size)) |
| 600 | 603 | ti85serial->status = TI85_RECEIVE_OK_2; |
| 601 | 604 | break; |
| 602 | 605 | case TI85_RECEIVE_OK_2: |
| 603 | | if(!ti85_receive_serial (device, ti85_receive_buffer, 4*8)) |
| 606 | if(!ti85_receive_serial (device, ti85serial->receive_buffer, 4*8)) |
| 604 | 607 | { |
| 605 | 608 | variable_number++; |
| 606 | | ti85_convert_stream_to_data (ti85_receive_buffer, 4*8, ti85_receive_data); |
| 607 | | ti85serial->status = (variable_number < ti85_serial_stream.number_of_variables) ? TI85_SEND_HEADER : TI85_SEND_END; |
| 609 | ti85_convert_stream_to_data (ti85serial->receive_buffer, 4*8, ti85serial->receive_data); |
| 610 | ti85serial->status = (variable_number < ti85serial->stream.number_of_variables) ? TI85_SEND_HEADER : TI85_SEND_END; |
| 608 | 611 | } |
| 609 | 612 | break; |
| 610 | 613 | case TI85_SEND_END: |
| 611 | | if(!ti85_send_serial(device, ti85_serial_stream.end,ti85_serial_stream.end_size)) |
| 614 | if(!ti85_send_serial(device, ti85serial->stream.end,ti85serial->stream.end_size)) |
| 612 | 615 | { |
| 613 | 616 | logerror ("End sended\n"); |
| 614 | 617 | variable_number = 0; |
| r6321 | r6322 | |
| 616 | 619 | } |
| 617 | 620 | break; |
| 618 | 621 | case TI85_RECEIVE_OK_3: |
| 619 | | if(!ti85_receive_serial (device, ti85_receive_buffer, 4*8)) |
| 622 | if(!ti85_receive_serial (device, ti85serial->receive_buffer, 4*8)) |
| 620 | 623 | { |
| 621 | 624 | logerror ("OK received\n"); |
| 622 | | ti85_convert_stream_to_data (ti85_receive_buffer, 4*8, ti85_receive_data); |
| 623 | | ti85_free_serial_data_memory(device->machine); |
| 625 | ti85_convert_stream_to_data (ti85serial->receive_buffer, 4*8, ti85serial->receive_data); |
| 626 | ti85_free_serial_data_memory(device); |
| 624 | 627 | ti85serial->status = TI85_SEND_STOP; |
| 625 | 628 | } |
| 626 | 629 | break; |
| r6321 | r6322 | |
| 636 | 639 | ti85serial_state *ti85serial = get_token( device ); |
| 637 | 640 | static UINT16 variable_number = 0; |
| 638 | 641 | |
| 639 | | if (!ti85_alloc_serial_data_memory(7)) |
| 642 | if (!ti85_alloc_serial_data_memory(device, 7)) |
| 640 | 643 | ti85serial->status = TI85_SEND_STOP; |
| 641 | 644 | |
| 642 | 645 | switch (ti85serial->status) |
| 643 | 646 | { |
| 644 | 647 | case TI85_SEND_HEADER: |
| 645 | | if(!ti85_send_serial(device, ti85_serial_stream.variables[variable_number].header,ti85_serial_stream.variables[variable_number].header_size)) |
| 648 | if(!ti85_send_serial(device, ti85serial->stream.variables[variable_number].header,ti85serial->stream.variables[variable_number].header_size)) |
| 646 | 649 | ti85serial->status = TI85_RECEIVE_OK_1; |
| 647 | 650 | break; |
| 648 | 651 | case TI85_RECEIVE_OK_1: |
| 649 | | if(!ti85_receive_serial (device, ti85_receive_buffer, 4*8)) |
| 652 | if(!ti85_receive_serial (device, ti85serial->receive_buffer, 4*8)) |
| 650 | 653 | { |
| 651 | | ti85_convert_stream_to_data (ti85_receive_buffer, 4*8, ti85_receive_data); |
| 654 | ti85_convert_stream_to_data (ti85serial->receive_buffer, 4*8, ti85serial->receive_data); |
| 652 | 655 | ti85serial->status = TI85_RECEIVE_ANSWER_1; |
| 653 | 656 | } |
| 654 | 657 | break; |
| 655 | 658 | case TI85_RECEIVE_ANSWER_1: |
| 656 | | if(!ti85_receive_serial (device, ti85_receive_buffer, 4*8)) |
| 659 | if(!ti85_receive_serial (device, ti85serial->receive_buffer, 4*8)) |
| 657 | 660 | { |
| 658 | | ti85_convert_stream_to_data (ti85_receive_buffer, 4*8, ti85_receive_data); |
| 659 | | switch (ti85_receive_data[1]) |
| 661 | ti85_convert_stream_to_data (ti85serial->receive_buffer, 4*8, ti85serial->receive_data); |
| 662 | switch (ti85serial->receive_data[1]) |
| 660 | 663 | { |
| 661 | 664 | case 0x09: //continue |
| 662 | 665 | ti85serial->status = TI85_SEND_OK; |
| r6321 | r6322 | |
| 668 | 671 | } |
| 669 | 672 | break; |
| 670 | 673 | case TI85_RECEIVE_ANSWER_2: |
| 671 | | if(!ti85_receive_serial (device, ti85_receive_buffer+4*8, 3*8)) |
| 674 | if(!ti85_receive_serial (device, ti85serial->receive_buffer+4*8, 3*8)) |
| 672 | 675 | { |
| 673 | | ti85_convert_stream_to_data (ti85_receive_buffer, 5*8, ti85_receive_data); |
| 676 | ti85_convert_stream_to_data (ti85serial->receive_buffer, 5*8, ti85serial->receive_data); |
| 674 | 677 | variable_number = 0; |
| 675 | | ti85_free_serial_data_memory(device->machine); |
| 678 | ti85_free_serial_data_memory(device); |
| 676 | 679 | ti85serial->status = TI85_SEND_STOP; |
| 677 | 680 | } |
| 678 | 681 | break; |
| 679 | 682 | case TI85_SEND_OK: |
| 680 | | if(!ti85_send_serial(device, ti85_serial_stream.variables[variable_number].ok,ti85_serial_stream.variables[variable_number].ok_size)) |
| 683 | if(!ti85_send_serial(device, ti85serial->stream.variables[variable_number].ok,ti85serial->stream.variables[variable_number].ok_size)) |
| 681 | 684 | ti85serial->status = TI85_SEND_DATA; |
| 682 | 685 | break; |
| 683 | 686 | case TI85_SEND_DATA: |
| 684 | | if(!ti85_send_serial(device, ti85_serial_stream.variables[variable_number].data,ti85_serial_stream.variables[variable_number].data_size)) |
| 687 | if(!ti85_send_serial(device, ti85serial->stream.variables[variable_number].data,ti85serial->stream.variables[variable_number].data_size)) |
| 685 | 688 | ti85serial->status = TI85_RECEIVE_OK_2; |
| 686 | 689 | break; |
| 687 | 690 | case TI85_RECEIVE_OK_2: |
| 688 | | if(!ti85_receive_serial (device, ti85_receive_buffer, 4*8)) |
| 691 | if(!ti85_receive_serial (device, ti85serial->receive_buffer, 4*8)) |
| 689 | 692 | { |
| 690 | 693 | variable_number++; |
| 691 | | ti85_convert_stream_to_data (ti85_receive_buffer, 4*8, ti85_receive_data); |
| 692 | | ti85serial->status = (variable_number < ti85_serial_stream.number_of_variables) ? TI85_SEND_DATA : TI85_SEND_END; |
| 694 | ti85_convert_stream_to_data (ti85serial->receive_buffer, 4*8, ti85serial->receive_data); |
| 695 | ti85serial->status = (variable_number < ti85serial->stream.number_of_variables) ? TI85_SEND_DATA : TI85_SEND_END; |
| 693 | 696 | } |
| 694 | 697 | break; |
| 695 | 698 | case TI85_SEND_END: |
| 696 | | if(!ti85_send_serial(device, ti85_serial_stream.end,ti85_serial_stream.end_size)) |
| 699 | if(!ti85_send_serial(device, ti85serial->stream.end,ti85serial->stream.end_size)) |
| 697 | 700 | { |
| 698 | 701 | variable_number = 0; |
| 699 | | ti85_free_serial_data_memory(device->machine); |
| 702 | ti85_free_serial_data_memory(device); |
| 700 | 703 | ti85serial->status = TI85_SEND_STOP; |
| 701 | 704 | } |
| 702 | 705 | break; |
| r6321 | r6322 | |
| 723 | 726 | switch (ti85serial->status) |
| 724 | 727 | { |
| 725 | 728 | case TI85_RECEIVE_HEADER_1: |
| 726 | | if(!ti85_receive_serial(device, ti85_receive_buffer+4*8, 3*8)) |
| 729 | if(!ti85_receive_serial(device, ti85serial->receive_buffer+4*8, 3*8)) |
| 727 | 730 | { |
| 728 | | ti85_convert_stream_to_data (ti85_receive_buffer+4*8, 3*8, ti85_receive_data+4); |
| 731 | ti85_convert_stream_to_data (ti85serial->receive_buffer+4*8, 3*8, ti85serial->receive_data+4); |
| 729 | 732 | ti85serial->status = TI85_PREPARE_VARIABLE_DATA; |
| 730 | 733 | } |
| 731 | 734 | break; |
| 732 | 735 | case TI85_PREPARE_VARIABLE_DATA: |
| 733 | | var_data = (UINT8*) malloc (ti85_receive_data[2]+2+ti85_receive_data[4]+ti85_receive_data[5]*256+2); |
| 736 | var_data = (UINT8*) malloc (ti85serial->receive_data[2]+2+ti85serial->receive_data[4]+ti85serial->receive_data[5]*256+2); |
| 734 | 737 | if(!var_data) |
| 735 | 738 | ti85serial->status = TI85_SEND_STOP; |
| 736 | | memcpy (var_data, ti85_receive_data+2, 5); |
| 737 | | ti85_free_serial_data_memory(device->machine); |
| 738 | | if (!ti85_alloc_serial_data_memory(var_data[0]-1)) |
| 739 | memcpy (var_data, ti85serial->receive_data+2, 5); |
| 740 | ti85_free_serial_data_memory(device); |
| 741 | if (!ti85_alloc_serial_data_memory(device, var_data[0]-1)) |
| 739 | 742 | { |
| 740 | 743 | free(var_data); var_data = NULL; |
| 741 | 744 | free(var_file_data); var_file_data = NULL; |
| r6321 | r6322 | |
| 744 | 747 | } |
| 745 | 748 | ti85serial->status = TI85_RECEIVE_HEADER_2; |
| 746 | 749 | case TI85_RECEIVE_HEADER_2: |
| 747 | | if(!ti85_receive_serial(device, ti85_receive_buffer, (var_data[0]-1)*8)) |
| 750 | if(!ti85_receive_serial(device, ti85serial->receive_buffer, (var_data[0]-1)*8)) |
| 748 | 751 | { |
| 749 | | ti85_convert_stream_to_data (ti85_receive_buffer, (var_data[0]-1)*8, ti85_receive_data); |
| 750 | | memcpy (var_data+5, ti85_receive_data, var_data[0]-3); |
| 751 | | ti85_free_serial_data_memory(device->machine); |
| 752 | | if(!ti85_alloc_serial_data_memory (8)) |
| 752 | ti85_convert_stream_to_data (ti85serial->receive_buffer, (var_data[0]-1)*8, ti85serial->receive_data); |
| 753 | memcpy (var_data+5, ti85serial->receive_data, var_data[0]-3); |
| 754 | ti85_free_serial_data_memory(device); |
| 755 | if(!ti85_alloc_serial_data_memory (device, 8)) |
| 753 | 756 | { |
| 754 | 757 | free(var_data); var_data = NULL; |
| 755 | 758 | free(var_file_data); var_file_data = NULL; |
| 756 | 759 | ti85serial->status = TI85_SEND_STOP; |
| 757 | 760 | return; |
| 758 | 761 | } |
| 759 | | ti85_convert_data_to_stream (ti85_pc_ok_packet, 4, ti85_receive_buffer); |
| 760 | | ti85_convert_data_to_stream (ti85_pc_continue_packet, 4, ti85_receive_buffer+4*8); |
| 762 | ti85_convert_data_to_stream (ti85_pc_ok_packet, 4, ti85serial->receive_buffer); |
| 763 | ti85_convert_data_to_stream (ti85_pc_continue_packet, 4, ti85serial->receive_buffer+4*8); |
| 761 | 764 | ti85serial->status = TI85_SEND_OK_1; |
| 762 | 765 | } |
| 763 | 766 | break; |
| 764 | 767 | case TI85_SEND_OK_1: |
| 765 | | if(!ti85_send_serial(device, ti85_receive_buffer, 4*8)) |
| 768 | if(!ti85_send_serial(device, ti85serial->receive_buffer, 4*8)) |
| 766 | 769 | ti85serial->status = TI85_SEND_CONTINUE; |
| 767 | 770 | break; |
| 768 | 771 | case TI85_SEND_CONTINUE: |
| 769 | | if(!ti85_send_serial(device, ti85_receive_buffer+4*8, 4*8)) |
| 772 | if(!ti85_send_serial(device, ti85serial->receive_buffer+4*8, 4*8)) |
| 770 | 773 | { |
| 771 | | ti85_free_serial_data_memory(device->machine); |
| 772 | | if(!ti85_alloc_serial_data_memory(4)) |
| 774 | ti85_free_serial_data_memory(device); |
| 775 | if(!ti85_alloc_serial_data_memory(device, 4)) |
| 773 | 776 | { |
| 774 | 777 | free(var_data); var_data = NULL; |
| 775 | 778 | free(var_file_data); var_file_data = NULL; |
| r6321 | r6322 | |
| 780 | 783 | } |
| 781 | 784 | break; |
| 782 | 785 | case TI85_RECEIVE_OK: |
| 783 | | if(!ti85_receive_serial (device, ti85_receive_buffer, 4*8)) |
| 786 | if(!ti85_receive_serial (device, ti85serial->receive_buffer, 4*8)) |
| 784 | 787 | { |
| 785 | | ti85_convert_stream_to_data (ti85_receive_buffer, 4*8, ti85_receive_data); |
| 786 | | ti85_free_serial_data_memory(device->machine); |
| 787 | | if(!ti85_alloc_serial_data_memory(var_data[2]+var_data[3]*256+6)) |
| 788 | ti85_convert_stream_to_data (ti85serial->receive_buffer, 4*8, ti85serial->receive_data); |
| 789 | ti85_free_serial_data_memory(device); |
| 790 | if(!ti85_alloc_serial_data_memory(device, var_data[2]+var_data[3]*256+6)) |
| 788 | 791 | { |
| 789 | 792 | free(var_data); var_data = NULL; |
| 790 | 793 | free(var_file_data); var_file_data = NULL; |
| r6321 | r6322 | |
| 795 | 798 | } |
| 796 | 799 | break; |
| 797 | 800 | case TI85_RECEIVE_DATA: |
| 798 | | if(!ti85_receive_serial (device, ti85_receive_buffer, (var_data[2]+var_data[3]*256+6)*8)) |
| 801 | if(!ti85_receive_serial (device, ti85serial->receive_buffer, (var_data[2]+var_data[3]*256+6)*8)) |
| 799 | 802 | { |
| 800 | | ti85_convert_stream_to_data (ti85_receive_buffer, (var_data[2]+var_data[3]*256+6)*8, ti85_receive_data); |
| 801 | | memcpy (var_data+var_data[0]+2, ti85_receive_data+2, var_data[2]+var_data[3]*256+2); |
| 802 | | ti85_free_serial_data_memory(device->machine); |
| 803 | | if(!ti85_alloc_serial_data_memory (4)) |
| 803 | ti85_convert_stream_to_data (ti85serial->receive_buffer, (var_data[2]+var_data[3]*256+6)*8, ti85serial->receive_data); |
| 804 | memcpy (var_data+var_data[0]+2, ti85serial->receive_data+2, var_data[2]+var_data[3]*256+2); |
| 805 | ti85_free_serial_data_memory(device); |
| 806 | if(!ti85_alloc_serial_data_memory (device, 4)) |
| 804 | 807 | { |
| 805 | 808 | free(var_data); var_data = NULL; |
| 806 | 809 | free(var_file_data); var_file_data = NULL; |
| 807 | 810 | ti85serial->status = TI85_SEND_STOP; |
| 808 | 811 | return; |
| 809 | 812 | } |
| 810 | | ti85_convert_data_to_stream (ti85_pc_ok_packet, 4, ti85_receive_buffer); |
| 813 | ti85_convert_data_to_stream (ti85_pc_ok_packet, 4, ti85serial->receive_buffer); |
| 811 | 814 | ti85serial->status = TI85_SEND_OK_2; |
| 812 | 815 | } |
| 813 | 816 | break; |
| 814 | 817 | case TI85_SEND_OK_2: |
| 815 | | if(!ti85_send_serial(device, ti85_receive_buffer, 4*8)) |
| 818 | if(!ti85_send_serial(device, ti85serial->receive_buffer, 4*8)) |
| 816 | 819 | { |
| 817 | | ti85_free_serial_data_memory(device->machine); |
| 818 | | if(!ti85_alloc_serial_data_memory(7)) |
| 820 | ti85_free_serial_data_memory(device); |
| 821 | if(!ti85_alloc_serial_data_memory(device, 7)) |
| 819 | 822 | { |
| 820 | 823 | free(var_data); var_data = NULL; |
| 821 | 824 | free(var_file_data); var_file_data = NULL; |
| r6321 | r6322 | |
| 826 | 829 | } |
| 827 | 830 | break; |
| 828 | 831 | case TI85_RECEIVE_END_OR_HEADER_1: |
| 829 | | if(!ti85_receive_serial (device, ti85_receive_buffer, 4*8)) |
| 832 | if(!ti85_receive_serial (device, ti85serial->receive_buffer, 4*8)) |
| 830 | 833 | { |
| 831 | 834 | if (variable_number == 0) |
| 832 | 835 | { |
| r6321 | r6322 | |
| 862 | 865 | var_data = NULL; |
| 863 | 866 | variable_number ++; |
| 864 | 867 | |
| 865 | | ti85_convert_stream_to_data (ti85_receive_buffer, 4*8, ti85_receive_data); |
| 866 | | if (ti85_receive_data[1] == 0x06) |
| 868 | ti85_convert_stream_to_data (ti85serial->receive_buffer, 4*8, ti85serial->receive_data); |
| 869 | if (ti85serial->receive_data[1] == 0x06) |
| 867 | 870 | ti85serial->status = TI85_RECEIVE_HEADER_1; |
| 868 | 871 | else |
| 869 | 872 | { |
| 870 | | ti85_free_serial_data_memory(device->machine); |
| 871 | | if(!ti85_alloc_serial_data_memory (4)) |
| 873 | ti85_free_serial_data_memory(device); |
| 874 | if(!ti85_alloc_serial_data_memory (device, 4)) |
| 872 | 875 | { |
| 873 | 876 | free(var_data); var_data = NULL; |
| 874 | 877 | free(var_file_data); var_file_data = NULL; |
| 875 | 878 | ti85serial->status = TI85_SEND_STOP; |
| 876 | 879 | return; |
| 877 | 880 | } |
| 878 | | ti85_convert_data_to_stream (ti85_pc_ok_packet, 4, ti85_receive_buffer); |
| 881 | ti85_convert_data_to_stream (ti85_pc_ok_packet, 4, ti85serial->receive_buffer); |
| 879 | 882 | ti85serial->status = TI85_SEND_OK_3; |
| 880 | 883 | } |
| 881 | 884 | } |
| 882 | 885 | break; |
| 883 | 886 | case TI85_SEND_OK_3: |
| 884 | | if(!ti85_send_serial(device, ti85_receive_buffer, 4*8)) |
| 887 | if(!ti85_send_serial(device, ti85serial->receive_buffer, 4*8)) |
| 885 | 888 | { |
| 886 | | ti85_free_serial_data_memory(device->machine); |
| 889 | ti85_free_serial_data_memory(device); |
| 887 | 890 | variable_number = 0; |
| 888 | 891 | ti85serial->status = TI85_SEND_STOP; |
| 889 | 892 | sprintf (var_file_name, "%08d.85g", var_file_number); |
| r6321 | r6322 | |
| 930 | 933 | switch (ti85serial->status) |
| 931 | 934 | { |
| 932 | 935 | case TI85_RECEIVE_HEADER_2: |
| 933 | | if(!ti85_receive_serial(device, ti85_receive_buffer+7*8, 8*8)) |
| 936 | if(!ti85_receive_serial(device, ti85serial->receive_buffer+7*8, 8*8)) |
| 934 | 937 | { |
| 935 | | ti85_convert_stream_to_data (ti85_receive_buffer+7*8, 8*8, ti85_receive_data+7); |
| 936 | | backup_data_size[0] = ti85_receive_data[4] + ti85_receive_data[5]*256; |
| 937 | | backup_data_size[1] = ti85_receive_data[7] + ti85_receive_data[8]*256; |
| 938 | | backup_data_size[2] = ti85_receive_data[9] + ti85_receive_data[10]*256; |
| 938 | ti85_convert_stream_to_data (ti85serial->receive_buffer+7*8, 8*8, ti85serial->receive_data+7); |
| 939 | backup_data_size[0] = ti85serial->receive_data[4] + ti85serial->receive_data[5]*256; |
| 940 | backup_data_size[1] = ti85serial->receive_data[7] + ti85serial->receive_data[8]*256; |
| 941 | backup_data_size[2] = ti85serial->receive_data[9] + ti85serial->receive_data[10]*256; |
| 939 | 942 | backup_file_data = malloc (0x42+0x06+backup_data_size[0]+backup_data_size[1]+backup_data_size[2]+0x02); |
| 940 | 943 | if(!backup_file_data) |
| 941 | 944 | { |
| r6321 | r6322 | |
| 948 | 951 | memset(backup_file_data+0x1f, 0, 0x16); |
| 949 | 952 | backup_file_data[0x35] = (backup_data_size[0]+backup_data_size[1]+backup_data_size[2]+0x11)&0x00ff; |
| 950 | 953 | backup_file_data[0x36] = ((backup_data_size[0]+backup_data_size[1]+backup_data_size[2]+0x11)&0xff00)>>8; |
| 951 | | memcpy(backup_file_data+0x37, ti85_receive_data+0x02, 0x0b); |
| 952 | | ti85_free_serial_data_memory(device->machine); |
| 953 | | if(!ti85_alloc_serial_data_memory (8)) |
| 954 | memcpy(backup_file_data+0x37, ti85serial->receive_data+0x02, 0x0b); |
| 955 | ti85_free_serial_data_memory(device); |
| 956 | if(!ti85_alloc_serial_data_memory (device, 8)) |
| 954 | 957 | { |
| 955 | 958 | free(backup_file_data); backup_file_data = NULL; |
| 956 | 959 | backup_variable_number = 0; |
| 957 | 960 | ti85serial->status = TI85_SEND_STOP; |
| 958 | 961 | return; |
| 959 | 962 | } |
| 960 | | ti85_convert_data_to_stream (ti85_pc_ok_packet, 4, ti85_receive_buffer); |
| 961 | | ti85_convert_data_to_stream (ti85_pc_continue_packet, 4, ti85_receive_buffer+4*8); |
| 963 | ti85_convert_data_to_stream (ti85_pc_ok_packet, 4, ti85serial->receive_buffer); |
| 964 | ti85_convert_data_to_stream (ti85_pc_continue_packet, 4, ti85serial->receive_buffer+4*8); |
| 962 | 965 | ti85serial->status = TI85_SEND_OK_1; |
| 963 | 966 | } |
| 964 | 967 | break; |
| 965 | 968 | case TI85_SEND_OK_1: |
| 966 | | if(!ti85_send_serial(device, ti85_receive_buffer, 4*8)) |
| 969 | if(!ti85_send_serial(device, ti85serial->receive_buffer, 4*8)) |
| 967 | 970 | ti85serial->status = TI85_SEND_CONTINUE; |
| 968 | 971 | break; |
| 969 | 972 | case TI85_SEND_CONTINUE: |
| 970 | | if(!ti85_send_serial(device, ti85_receive_buffer+4*8, 4*8)) |
| 973 | if(!ti85_send_serial(device, ti85serial->receive_buffer+4*8, 4*8)) |
| 971 | 974 | { |
| 972 | | ti85_free_serial_data_memory(device->machine); |
| 973 | | if(!ti85_alloc_serial_data_memory(4)) |
| 975 | ti85_free_serial_data_memory(device); |
| 976 | if(!ti85_alloc_serial_data_memory(device, 4)) |
| 974 | 977 | { |
| 975 | 978 | free(backup_file_data); backup_file_data = NULL; |
| 976 | 979 | backup_variable_number = 0; |
| r6321 | r6322 | |
| 981 | 984 | } |
| 982 | 985 | break; |
| 983 | 986 | case TI85_RECEIVE_OK: |
| 984 | | if(!ti85_receive_serial (device, ti85_receive_buffer, 4*8)) |
| 987 | if(!ti85_receive_serial (device, ti85serial->receive_buffer, 4*8)) |
| 985 | 988 | { |
| 986 | | ti85_convert_stream_to_data (ti85_receive_buffer, 4*8, ti85_receive_data); |
| 987 | | ti85_free_serial_data_memory(device->machine); |
| 988 | | if(!ti85_alloc_serial_data_memory(backup_data_size[backup_variable_number]+6)) |
| 989 | ti85_convert_stream_to_data (ti85serial->receive_buffer, 4*8, ti85serial->receive_data); |
| 990 | ti85_free_serial_data_memory(device); |
| 991 | if(!ti85_alloc_serial_data_memory(device, backup_data_size[backup_variable_number]+6)) |
| 989 | 992 | { |
| 990 | 993 | free(backup_file_data); backup_file_data = NULL; |
| 991 | 994 | backup_variable_number = 0; |
| r6321 | r6322 | |
| 996 | 999 | } |
| 997 | 1000 | break; |
| 998 | 1001 | case TI85_RECEIVE_DATA: |
| 999 | | if(!ti85_receive_serial (device, ti85_receive_buffer, (backup_data_size[backup_variable_number]+6)*8)) |
| 1002 | if(!ti85_receive_serial (device, ti85serial->receive_buffer, (backup_data_size[backup_variable_number]+6)*8)) |
| 1000 | 1003 | { |
| 1001 | | ti85_convert_stream_to_data (ti85_receive_buffer, (backup_data_size[backup_variable_number]+6)*8, ti85_receive_data); |
| 1004 | ti85_convert_stream_to_data (ti85serial->receive_buffer, (backup_data_size[backup_variable_number]+6)*8, ti85serial->receive_data); |
| 1002 | 1005 | switch (backup_variable_number) |
| 1003 | 1006 | { |
| 1004 | 1007 | case 0: |
| 1005 | | memcpy(backup_file_data+0x42, ti85_receive_data+0x02, backup_data_size[0]+0x02); |
| 1008 | memcpy(backup_file_data+0x42, ti85serial->receive_data+0x02, backup_data_size[0]+0x02); |
| 1006 | 1009 | break; |
| 1007 | 1010 | case 1: |
| 1008 | | memcpy(backup_file_data+0x42+backup_data_size[0]+0x02, ti85_receive_data+0x02, backup_data_size[1]+0x02); |
| 1011 | memcpy(backup_file_data+0x42+backup_data_size[0]+0x02, ti85serial->receive_data+0x02, backup_data_size[1]+0x02); |
| 1009 | 1012 | break; |
| 1010 | 1013 | case 2: |
| 1011 | | memcpy(backup_file_data+0x42+backup_data_size[0]+backup_data_size[1]+0x04, ti85_receive_data+0x02, backup_data_size[2]+0x02); |
| 1014 | memcpy(backup_file_data+0x42+backup_data_size[0]+backup_data_size[1]+0x04, ti85serial->receive_data+0x02, backup_data_size[2]+0x02); |
| 1012 | 1015 | break; |
| 1013 | 1016 | } |
| 1014 | | ti85_free_serial_data_memory(device->machine); |
| 1015 | | if(!ti85_alloc_serial_data_memory (4)) |
| 1017 | ti85_free_serial_data_memory(device); |
| 1018 | if(!ti85_alloc_serial_data_memory (device, 4)) |
| 1016 | 1019 | { |
| 1017 | 1020 | free(backup_file_data); backup_file_data = NULL; |
| 1018 | 1021 | backup_variable_number = 0; |
| 1019 | 1022 | ti85serial->status = TI85_SEND_STOP; |
| 1020 | 1023 | return; |
| 1021 | 1024 | } |
| 1022 | | ti85_convert_data_to_stream (ti85_pc_ok_packet, 4, ti85_receive_buffer); |
| 1025 | ti85_convert_data_to_stream (ti85_pc_ok_packet, 4, ti85serial->receive_buffer); |
| 1023 | 1026 | ti85serial->status = TI85_SEND_OK_2; |
| 1024 | 1027 | } |
| 1025 | 1028 | break; |
| 1026 | 1029 | case TI85_SEND_OK_2: |
| 1027 | | if(!ti85_send_serial(device, ti85_receive_buffer, 4*8)) |
| 1030 | if(!ti85_send_serial(device, ti85serial->receive_buffer, 4*8)) |
| 1028 | 1031 | { |
| 1029 | | ti85_free_serial_data_memory(device->machine); |
| 1032 | ti85_free_serial_data_memory(device); |
| 1030 | 1033 | backup_variable_number++; |
| 1031 | 1034 | if (backup_variable_number<3) |
| 1032 | 1035 | { |
| 1033 | | if(!ti85_alloc_serial_data_memory(backup_data_size[backup_variable_number]+6)) |
| 1036 | if(!ti85_alloc_serial_data_memory(device, backup_data_size[backup_variable_number]+6)) |
| 1034 | 1037 | { |
| 1035 | 1038 | free(backup_file_data); backup_file_data = NULL; |
| 1036 | 1039 | backup_variable_number = 0; |
| r6321 | r6322 | |
| 1079 | 1082 | switch (ti85serial->status) |
| 1080 | 1083 | { |
| 1081 | 1084 | case TI85_PREPARE_SCREEN_REQUEST: |
| 1082 | | if(!ti85_alloc_serial_data_memory (4)) |
| 1085 | if(!ti85_alloc_serial_data_memory (device, 4)) |
| 1083 | 1086 | { |
| 1084 | 1087 | ti85serial->status = TI85_SEND_STOP; |
| 1085 | 1088 | return; |
| 1086 | 1089 | } |
| 1087 | | ti85_convert_data_to_stream (ti85_pc_screen_request_packet, 4, ti85_receive_buffer); |
| 1090 | ti85_convert_data_to_stream (ti85_pc_screen_request_packet, 4, ti85serial->receive_buffer); |
| 1088 | 1091 | ti85serial->status = TI85_SEND_SCREEN_REQUEST; |
| 1089 | 1092 | break; |
| 1090 | 1093 | case TI85_SEND_SCREEN_REQUEST: |
| 1091 | | if(!ti85_send_serial(device, ti85_receive_buffer, 4*8)) |
| 1094 | if(!ti85_send_serial(device, ti85serial->receive_buffer, 4*8)) |
| 1092 | 1095 | { |
| 1093 | | ti85_free_serial_data_memory(device->machine); |
| 1094 | | if(!ti85_alloc_serial_data_memory (4)) |
| 1096 | ti85_free_serial_data_memory(device); |
| 1097 | if(!ti85_alloc_serial_data_memory (device, 4)) |
| 1095 | 1098 | { |
| 1096 | 1099 | ti85serial->status = TI85_SEND_STOP; |
| 1097 | 1100 | return; |
| r6321 | r6322 | |
| 1100 | 1103 | } |
| 1101 | 1104 | break; |
| 1102 | 1105 | case TI85_RECEIVE_OK: |
| 1103 | | if(!ti85_receive_serial (device, ti85_receive_buffer, 4*8)) |
| 1106 | if(!ti85_receive_serial (device, ti85serial->receive_buffer, 4*8)) |
| 1104 | 1107 | { |
| 1105 | | ti85_convert_stream_to_data (ti85_receive_buffer, 4*8, ti85_receive_data); |
| 1106 | | ti85_free_serial_data_memory(device->machine); |
| 1107 | | if(!ti85_alloc_serial_data_memory (1030)) |
| 1108 | ti85_convert_stream_to_data (ti85serial->receive_buffer, 4*8, ti85serial->receive_data); |
| 1109 | ti85_free_serial_data_memory(device); |
| 1110 | if(!ti85_alloc_serial_data_memory (device, 1030)) |
| 1108 | 1111 | { |
| 1109 | 1112 | ti85serial->status = TI85_SEND_STOP; |
| 1110 | 1113 | return; |
| r6321 | r6322 | |
| 1113 | 1116 | } |
| 1114 | 1117 | break; |
| 1115 | 1118 | case TI85_RECEIVE_DATA: |
| 1116 | | if(!ti85_receive_serial (device, ti85_receive_buffer, 1030*8)) |
| 1119 | if(!ti85_receive_serial (device, ti85serial->receive_buffer, 1030*8)) |
| 1117 | 1120 | { |
| 1118 | | ti85_convert_stream_to_data (ti85_receive_buffer, 1030*8, ti85_receive_data); |
| 1121 | ti85_convert_stream_to_data (ti85serial->receive_buffer, 1030*8, ti85serial->receive_data); |
| 1119 | 1122 | sprintf (image_file_name, "%08d.85i", image_file_number); |
| 1120 | 1123 | filerr = mame_fopen(SEARCHPATH_IMAGE, image_file_name, OPEN_FLAG_READ | OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &image_file); |
| 1121 | 1124 | if (filerr == FILERR_NONE) |
| r6321 | r6322 | |
| 1123 | 1126 | image_file_data = malloc (0x49+1008); |
| 1124 | 1127 | if(!image_file_data) |
| 1125 | 1128 | { |
| 1126 | | ti85_free_serial_data_memory(device->machine); |
| 1129 | ti85_free_serial_data_memory(device); |
| 1127 | 1130 | ti85serial->status = TI85_SEND_OK; |
| 1128 | 1131 | return; |
| 1129 | 1132 | } |
| r6321 | r6322 | |
| 1143 | 1146 | image_file_data[0x44] = 0x03; |
| 1144 | 1147 | image_file_data[0x45] = 0xf0; |
| 1145 | 1148 | image_file_data[0x46] = 0x03; |
| 1146 | | memcpy(image_file_data+0x47, ti85_receive_data+4, 1008); |
| 1149 | memcpy(image_file_data+0x47, ti85serial->receive_data+4, 1008); |
| 1147 | 1150 | image_file_data[1008+0x49-2] = ti85_calculate_checksum(image_file_data+0x37, 1008+0x10)&0x00ff; |
| 1148 | 1151 | image_file_data[1008+0x49-1] = (ti85_calculate_checksum(image_file_data+0x37, 1008+0x10)&0xff00)>>8; |
| 1149 | 1152 | mame_fwrite(image_file, image_file_data, 1008+0x49); |
| r6321 | r6322 | |
| 1151 | 1154 | free(image_file_data); |
| 1152 | 1155 | image_file_number++; |
| 1153 | 1156 | } |
| 1154 | | ti85_free_serial_data_memory(device->machine); |
| 1155 | | if(!ti85_alloc_serial_data_memory (4)) |
| 1157 | ti85_free_serial_data_memory(device); |
| 1158 | if(!ti85_alloc_serial_data_memory (device, 4)) |
| 1156 | 1159 | { |
| 1157 | 1160 | ti85serial->status = TI85_SEND_STOP; |
| 1158 | 1161 | return; |
| 1159 | 1162 | } |
| 1160 | | ti85_convert_data_to_stream (ti85_pc_ok_packet, 4, ti85_receive_buffer); |
| 1163 | ti85_convert_data_to_stream (ti85_pc_ok_packet, 4, ti85serial->receive_buffer); |
| 1161 | 1164 | ti85serial->status = TI85_SEND_OK; |
| 1162 | 1165 | } |
| 1163 | 1166 | break; |
| 1164 | 1167 | case TI85_SEND_OK: |
| 1165 | | if(!ti85_send_serial(device, ti85_receive_buffer, 4*8)) |
| 1168 | if(!ti85_send_serial(device, ti85serial->receive_buffer, 4*8)) |
| 1166 | 1169 | { |
| 1167 | | ti85_free_serial_data_memory(device->machine); |
| 1170 | ti85_free_serial_data_memory(device); |
| 1168 | 1171 | ti85serial->status = TI85_SEND_STOP; |
| 1169 | 1172 | } |
| 1170 | 1173 | break; |
| r6321 | r6322 | |
| 1180 | 1183 | { |
| 1181 | 1184 | if (input_port_read(device->machine, "SERIAL") & 0x01) |
| 1182 | 1185 | { |
| 1183 | | if(!ti85_alloc_serial_data_memory(15)) return; |
| 1184 | | if(!ti85_receive_serial (device, ti85_receive_buffer, 7*8)) |
| 1186 | if(!ti85_alloc_serial_data_memory(device, 15)) return; |
| 1187 | if(!ti85_receive_serial (device, ti85serial->receive_buffer, 7*8)) |
| 1185 | 1188 | { |
| 1186 | | ti85_convert_stream_to_data (ti85_receive_buffer, 7*8, ti85_receive_data); |
| 1187 | | if (ti85_receive_data[0]!=0x85 || ti85_receive_data[1]!=0x06) |
| 1189 | ti85_convert_stream_to_data (ti85serial->receive_buffer, 7*8, ti85serial->receive_data); |
| 1190 | if (ti85serial->receive_data[0]!=0x85 || ti85serial->receive_data[1]!=0x06) |
| 1188 | 1191 | { |
| 1189 | 1192 | ti85_receive_serial (device, NULL, 0); |
| 1190 | 1193 | return; |
| 1191 | 1194 | } |
| 1192 | | ti85_serial_transfer_type = (ti85_receive_data[6]==0x1d) ? TI85_RECEIVE_BACKUP : TI85_RECEIVE_VARIABLES; |
| 1193 | | ti85serial->status = (ti85_receive_data[6]==0x1d) ? TI85_RECEIVE_HEADER_2 : TI85_PREPARE_VARIABLE_DATA; |
| 1195 | ti85serial->transfer_type = (ti85serial->receive_data[6]==0x1d) ? TI85_RECEIVE_BACKUP : TI85_RECEIVE_VARIABLES; |
| 1196 | ti85serial->status = (ti85serial->receive_data[6]==0x1d) ? TI85_RECEIVE_HEADER_2 : TI85_PREPARE_VARIABLE_DATA; |
| 1194 | 1197 | } |
| 1195 | 1198 | } |
| 1196 | 1199 | else |
| 1197 | 1200 | { |
| 1198 | 1201 | ti85_receive_serial(device, NULL, 0); |
| 1199 | | ti85_free_serial_data_memory(device->machine); |
| 1202 | ti85_free_serial_data_memory(device); |
| 1200 | 1203 | if (input_port_read(device->machine, "DUMP") & 0x01) |
| 1201 | 1204 | { |
| 1202 | 1205 | ti85serial->status = TI85_PREPARE_SCREEN_REQUEST; |
| 1203 | | ti85_serial_transfer_type = TI85_RECEIVE_SCREEN; |
| 1206 | ti85serial->transfer_type = TI85_RECEIVE_SCREEN; |
| 1204 | 1207 | } |
| 1205 | 1208 | return; |
| 1206 | 1209 | } |
| 1207 | 1210 | } |
| 1208 | 1211 | |
| 1209 | | switch (ti85_serial_transfer_type) |
| 1212 | switch (ti85serial->transfer_type) |
| 1210 | 1213 | { |
| 1211 | 1214 | case TI85_SEND_VARIABLES: |
| 1212 | 1215 | ti85_send_variables(device); |
| r6321 | r6322 | |
| 1265 | 1268 | |
| 1266 | 1269 | ti85serial->status = TI85_SEND_STOP; |
| 1267 | 1270 | ti85serial->transfer_type = TI85_SEND_VARIABLES; |
| 1271 | ti85serial->receive_buffer = NULL; |
| 1268 | 1272 | |
| 1269 | | ti85_free_serial_data_memory(device->machine); |
| 1273 | ti85_free_serial_data_memory(device); |
| 1270 | 1274 | ti85_receive_serial (device, NULL,0); |
| 1271 | 1275 | } |
| 1272 | 1276 | |
| 1273 | 1277 | |
| 1278 | static DEVICE_STOP( ti85serial ) |
| 1279 | { |
| 1280 | ti85_free_serial_data_memory(device); |
| 1281 | } |
| 1282 | |
| 1283 | |
| 1274 | 1284 | static DEVICE_RESET( ti85serial ) |
| 1275 | 1285 | { |
| 1276 | 1286 | ti85serial_state *ti85serial = get_token( device ); |
| 1277 | 1287 | |
| 1278 | 1288 | ti85_receive_serial(device, NULL, 0); |
| 1279 | 1289 | ti85_send_serial(device, NULL, 0); |
| 1280 | | ti85_free_serial_data_memory(device->machine); |
| 1290 | ti85_free_serial_data_memory(device); |
| 1281 | 1291 | // ti85_PCR = 0xc0; |
| 1282 | 1292 | ti85serial->red_in = 0; |
| 1283 | 1293 | ti85serial->white_in = 0; |
| r6321 | r6322 | |
| 1307 | 1317 | file_data = auto_alloc_array(image->machine, UINT8, file_size); |
| 1308 | 1318 | image_fread(image, file_data, file_size); |
| 1309 | 1319 | |
| 1310 | | if(!ti85_convert_file_data_to_serial_stream(file_data, file_size, &ti85_serial_stream, (char*)image->machine->gamedrv->name)) |
| 1320 | if(!ti85_convert_file_data_to_serial_stream(image, file_data, file_size, &ti85serial->stream, (char*)image->machine->gamedrv->name)) |
| 1311 | 1321 | { |
| 1312 | | ti85_free_serial_stream (&ti85_serial_stream); |
| 1322 | ti85_free_serial_stream (&ti85serial->stream); |
| 1313 | 1323 | return INIT_FAIL; |
| 1314 | 1324 | } |
| 1315 | 1325 | |
| r6321 | r6322 | |
| 1327 | 1337 | { |
| 1328 | 1338 | ti85serial_state *ti85serial = get_token( image ); |
| 1329 | 1339 | |
| 1330 | | ti85_free_serial_data_memory(image->machine); |
| 1340 | ti85_free_serial_data_memory(image); |
| 1331 | 1341 | ti85serial->status = TI85_SEND_STOP; |
| 1332 | | ti85_free_serial_stream (&ti85_serial_stream); |
| 1342 | ti85_free_serial_stream (&ti85serial->stream); |
| 1333 | 1343 | } |
| 1334 | 1344 | |
| 1335 | 1345 | |
| r6321 | r6322 | |
| 1346 | 1356 | case DEVINFO_INT_IMAGE_CREATABLE: info->i = 0; break; |
| 1347 | 1357 | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME( ti85serial ); break; |
| 1348 | 1358 | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME( ti85serial ); break; |
| 1359 | case DEVINFO_FCT_STOP: info->stop = DEVICE_STOP_NAME( ti85serial ); break; |
| 1349 | 1360 | case DEVINFO_FCT_IMAGE_LOAD: info->f = (genf *) DEVICE_IMAGE_LOAD_NAME( ti85serial ); break; |
| 1350 | 1361 | case DEVINFO_FCT_IMAGE_UNLOAD: info->f = (genf *) DEVICE_IMAGE_UNLOAD_NAME( ti85serial ); break; |
| 1351 | 1362 | case DEVINFO_STR_IMAGE_BRIEF_INSTANCE_NAME: strcpy(info->s, "ser"); break; |