]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
Return inverted bit 7 during programming, CSMK2 flasher needs it.
authorToni Wilen <twilen@winuae.net>
Mon, 28 Jul 2014 16:47:52 +0000 (19:47 +0300)
committerToni Wilen <twilen@winuae.net>
Mon, 28 Jul 2014 16:47:52 +0000 (19:47 +0300)
flashrom.cpp

index f9fcc19ca985cb34d311a56545eee13834b6fd18..7239f5a5fe73889ab94c9f6a6183fcd039010009 100644 (file)
@@ -11,6 +11,7 @@
 
 #include "zfile.h"
 #include "flashrom.h"
+#include "debug.h"
 
 #define FLASH_LOG 0
 
@@ -51,7 +52,8 @@ void flash_free(void *fdv)
 bool flash_active(void *fdv, uaecptr addr)
 {
        struct flashrom_data *fd = (struct flashrom_data*)fdv;
-
+       if (!fd)
+               return false;
        return fd->state != 0;
 }
 
@@ -61,15 +63,17 @@ bool flash_write(void *fdv, uaecptr addr, uae_u8 v)
        int oldstate = fd->state;
        uae_u32 addr2;
 
+       if (!fd)
+               return false;
 #if FLASH_LOG
-       write_log(_T("flash write %08x %02x\n"), addr, v);
+       write_log(_T("flash write %08x %02x (%d)\n"), addr, v, fd->state);
 #endif
 
        addr &= fd->mask;
        addr2 = addr & 0xffff;
 
        if (fd->state == 7) {
-               fd->state = 0;
+               fd->state = 100;
                if (addr >= fd->allocsize)
                        return false;
                if (fd->rom[addr] != v)
@@ -84,7 +88,7 @@ bool flash_write(void *fdv, uaecptr addr, uae_u8 v)
        }
 
        // unlock
-       if (addr2 == 0x5555 && fd->state == 0 && v == 0xaa)
+       if (addr2 == 0x5555 && fd->state <= 2 && v == 0xaa)
                fd->state = 1;
        if (addr2 == 0x2aaa && fd->state == 1 && v == 0x55)
                fd->state = 2;
@@ -106,7 +110,7 @@ bool flash_write(void *fdv, uaecptr addr, uae_u8 v)
                fd->state = 6;
        if (addr2 == 0x5555 && fd->state == 6 && v == 0x10) {
                memset(fd->rom, 0xff, fd->allocsize);
-               fd->state = 0;
+               fd->state = 100;
                fd->modified = 1;
 #if FLASH_LOG
                write_log(_T("flash chip erased\n"), addr);
@@ -116,10 +120,10 @@ bool flash_write(void *fdv, uaecptr addr, uae_u8 v)
                int saddr = addr & ~0x3fff;
                if (saddr < fd->allocsize)
                        memset(fd->rom + saddr, 0xff, 0x4000);
-               fd->state = 0;
+               fd->state = 100;
                fd->modified = 1;
 #if FLASH_LOG
-               write_log(_T("flash sector %d erased\n"), saddr / 0x4000);
+               write_log(_T("flash sector %d erased (%08x)\n"), saddr / 0x4000, addr);
 #endif
                return true;
        }
@@ -134,8 +138,11 @@ uae_u32 flash_read(void *fdv, uaecptr addr)
        struct flashrom_data *fd = (struct flashrom_data*)fdv;
        uae_u8 v = 0xff;
 
+       if (!fd)
+               return 0;
+
 #if FLASH_LOG
-       write_log(_T("flash read %08x\n"), addr);
+       write_log(_T("flash read %08x (%d)\n"), addr, fd->state);
 #endif
 
        addr &= fd->mask;
@@ -148,8 +155,18 @@ uae_u32 flash_read(void *fdv, uaecptr addr)
                if (a == 2)
                        return 0x00;
        }
+
+       if (fd->state >= 100) {
+               v = fd->rom[addr] ^ 0x80;
+               fd->state++;
+               if (fd->state >= 110)
+                       fd->state = 0;
+               return v;
+       }
+
        fd->state = 0;
        if (addr >= fd->allocsize)
                return 0xff;
+
        return fd->rom[addr];
 }