| 742 | } |
| 743 | |
| 744 | bool flash_write(void *fdv, uaecptr addr, uae_u8 v) |
| 745 | { |
| 746 | struct flashrom_data *fd = (struct flashrom_data*)fdv; |
| 747 | int other_byte_mult = 1; |
| 748 | |
| 749 | if (!fd) |
| 750 | return false; |
| 751 | |
| 752 | if (fd->flags & (FLASHROM_SKIP_EVERY_OTHER_BYTE | FLASHROM_EVERY_OTHER_BYTE)) { |
| 753 | addr >>= 1; |
| 754 | other_byte_mult = 2; |
| 755 | } |
| 756 | |
| 757 | if (addr * other_byte_mult >= fd->allocsize) { |
| 758 | return false; |
| 759 | } |
| 760 | |
| 761 | int oldstate = fd->state; |
| 762 | bool det = false; |
| 763 | |
| 764 | #if FLASH_LOG > 1 |
| 765 | write_log(_T("flash write %08x %02x (%d) PC=%08x\n"), addr, v, fd->state, m68k_getpc()); |
| 766 | #endif |
| 767 | |
| 768 | addr &= fd->mask; |
| 769 | |
| 770 | if (fd->state == 7 || fd->state == 8) { |
| 771 | int a = addr * other_byte_mult; |
| 772 | writeflash(fd, a, v); |
| 773 | return true; |
| 774 | } |
| 775 | |
| 776 | if (v == 0xf0 && fd->state > 0 && fd->state < 7) { |
| 777 | fd->state = 0; |
| 778 | return false; |
| 779 | } |
| 780 | |
| 781 | // unlock |
| 782 | if (addr == 0x5555 && fd->state <= 2 && v == 0xaa) { |
| 783 | fd->state = 1; |
| 784 | det = true; |
| 785 | } |
| 786 | if (addr == 0x2aaa && fd->state == 1 && v == 0x55) { |
| 787 | fd->state = 2; |
| 788 | det = true; |
| 789 | } |
| 790 | |
| 791 | // software id exit and reset first byte |
| 792 | if (addr == 0x5555 && fd->state == 3 && v == 0xaa) { |
| 793 | fd->state = 1; |
| 794 | det = true; |
| 795 | } |
| 796 | |
| 797 | // autoselect |
| 798 | if (addr == 0x5555 && fd->state == 2 && v == 0x90) { |
| 799 | fd->state = 3; |
| 800 | det = true; |
| 801 | } |
no test coverage detected