From: <sba...@us...> - 2023-01-08 05:48:32
|
This is an automated email from the git hooks/post-receive-user script. sbaldovi pushed a commit to branch master in repository fuse. View the commit online: https://sourceforge.net/p/fuse-emulator/fuse/ci/2effbd6d9c71419779372eeb13327e2f2013c9c2/ The following commit(s) were added to refs/heads/master by this push: new 2effbd6d More accurate emulation of AM29F010B flash ROM. 2effbd6d is described below commit 2effbd6d9c71419779372eeb13327e2f2013c9c2 Author: ZXGuesser <ali...@zx...> AuthorDate: Wed Sep 21 20:32:37 2022 +0100 More accurate emulation of AM29F010B flash ROM. --- compat.h | 1 + memory_pages.c | 6 ++++++ peripherals/flash/am29f010.c | 34 ++++++++++++++++++++++++++++++---- peripherals/flash/am29f010.h | 2 +- peripherals/spectranet.c | 28 ++++++++++++++++++++++++++-- peripherals/spectranet.h | 2 ++ 6 files changed, 66 insertions(+), 7 deletions(-) diff --git a/compat.h b/compat.h index f1c019d4..931fea15 100644 --- a/compat.h +++ b/compat.h @@ -177,6 +177,7 @@ int compat_get_tap( const char *interface_name ); #ifdef WIN32 #include <winsock2.h> +#include <ws2tcpip.h> #define COMPAT_ENOTCONN WSAENOTCONN #define COMPAT_EWOULDBLOCK WSAEWOULDBLOCK #define COMPAT_EINPROGRESS WSAEINPROGRESS diff --git a/memory_pages.c b/memory_pages.c index 2cb8ccc4..cafc4574 100644 --- a/memory_pages.c +++ b/memory_pages.c @@ -394,6 +394,12 @@ readbyte( libspectrum_word address ) return spectranet_w5100_read( mapping, address ); if( spectranet_w5100_paged_b && address >= 0x2000 && address < 0x3000 ) return spectranet_w5100_read( mapping, address ); + if( address < 0x1000 ) + return spectranet_flash_rom_read( mapping, address ); + if( spectranet_flash_paged_a && address >= 0x1000 && address < 0x2000 ) + return spectranet_flash_rom_read( mapping, address ); + if( spectranet_flash_paged_b && address >= 0x2000 && address < 0x3000 ) + return spectranet_flash_rom_read( mapping, address ); } if( ttx2000s_paged && address >= 0x2000 ) diff --git a/peripherals/flash/am29f010.c b/peripherals/flash/am29f010.c index 3cb216a6..df36c0ba 100644 --- a/peripherals/flash/am29f010.c +++ b/peripherals/flash/am29f010.c @@ -38,6 +38,7 @@ typedef enum am29f010_flash_state { FLASH_STATE_CYCLE5, FLASH_STATE_CYCLE6, FLASH_STATE_PROGRAM, + FLASH_STATE_AUTOSELECT, } am29f010_flash_state; struct flash_am29f010_t { @@ -83,13 +84,33 @@ flash_am29f010_program( flash_am29f010_t *self, libspectrum_byte page, libspectr self->memory[ flash_offset ] = b; } +libspectrum_byte +flash_am29f010_read( flash_am29f010_t *self, libspectrum_byte page, libspectrum_word address ) +{ + if( self->flash_state == FLASH_STATE_AUTOSELECT ) { + switch( address & 0xff ) { + case 0x00: /* manufacturer ID */ + return 0x01; /* AMD */ + case 0x01: /* device ID */ + return 0x20; /* Am29F010B */ + case 0x02: /* sector protect verify */ + return 0x00; /* always unprotected */ + default: + return 0xff; /* undefined - don't know what this should return */ + } + } + + libspectrum_dword flash_offset = page * SIZE_OF_FLASH_PAGE + address; + return self->memory[ flash_offset ]; +} + void flash_am29f010_write( flash_am29f010_t *self, libspectrum_byte page, libspectrum_word address, libspectrum_byte b ) { - libspectrum_word flash_address = address & 0xfff; + libspectrum_word flash_address = address & 0x7ff; - /* We implement only the reset, program, chip erase and sector erase - commands for now */ + /* We implement only the reset, program, chip erase, sector erase + and autoselect commands for now */ switch (self->flash_state) { case FLASH_STATE_RESET: if( flash_address == 0x555 && b == 0xaa ) @@ -105,6 +126,8 @@ flash_am29f010_write( flash_am29f010_t *self, libspectrum_byte page, libspectrum self->flash_state = FLASH_STATE_PROGRAM; else if( b == 0x80 ) self->flash_state = FLASH_STATE_CYCLE4; + else if( b == 0x90 ) + self->flash_state = FLASH_STATE_AUTOSELECT; } break; case FLASH_STATE_CYCLE4: @@ -128,8 +151,11 @@ flash_am29f010_write( flash_am29f010_t *self, libspectrum_byte page, libspectrum flash_am29f010_program( self, page, address, b ); self->flash_state = FLASH_STATE_RESET; break; + case FLASH_STATE_AUTOSELECT: + break; } - if( b == 0x0f ) + if( b == 0xf0 ) self->flash_state = FLASH_STATE_RESET; } + diff --git a/peripherals/flash/am29f010.h b/peripherals/flash/am29f010.h index 6c452d3a..3b213fc6 100644 --- a/peripherals/flash/am29f010.h +++ b/peripherals/flash/am29f010.h @@ -30,7 +30,7 @@ typedef struct flash_am29f010_t flash_am29f010_t; flash_am29f010_t* flash_am29f010_alloc( void ); void flash_am29f010_free( flash_am29f010_t *self ); void flash_am29f010_init( flash_am29f010_t *self, libspectrum_byte *memory ); - +libspectrum_byte flash_am29f010_read( flash_am29f010_t *self, libspectrum_byte page, libspectrum_word address ); void flash_am29f010_write( flash_am29f010_t *self, libspectrum_byte page, libspectrum_word address, libspectrum_byte b ); #endif /* #ifndef FUSE_AM29F010_H */ diff --git a/peripherals/spectranet.c b/peripherals/spectranet.c index db18fa71..ba59c211 100644 --- a/peripherals/spectranet.c +++ b/peripherals/spectranet.c @@ -69,6 +69,7 @@ int spectranet_available = 0; int spectranet_paged; int spectranet_paged_via_io; int spectranet_w5100_paged_a = 0, spectranet_w5100_paged_b = 0; +int spectranet_flash_paged_a = 0, spectranet_flash_paged_b = 0; /* Whether the programmable trap is active */ int spectranet_programmable_trap_active; @@ -140,6 +141,7 @@ spectranet_map_page( int dest, int source ) { int i; int w5100_page = source >= 0x40 && source < 0x48; + int flash_page = source >= 0x00 && source < 0x20; for( i = 0; i < MEMORY_PAGES_IN_4K; i++ ) spectranet_current_map[dest * MEMORY_PAGES_IN_4K + i] = @@ -147,8 +149,14 @@ spectranet_map_page( int dest, int source ) switch( dest ) { - case 1: spectranet_w5100_paged_a = w5100_page; break; - case 2: spectranet_w5100_paged_b = w5100_page; break; + case 1: + spectranet_w5100_paged_a = w5100_page; + spectranet_flash_paged_a = flash_page; + break; + case 2: + spectranet_w5100_paged_b = w5100_page; + spectranet_flash_paged_b = flash_page; + break; } } @@ -496,6 +504,15 @@ spectranet_w5100_write( memory_page *page, libspectrum_word address, libspectrum nic_w5100_write( w5100, get_w5100_register( page, address ), b ); } +libspectrum_byte +spectranet_flash_rom_read( memory_page *page, libspectrum_word address ) +{ + int flash_page = page->page_num / 4; + libspectrum_word flash_address = + (page->page_num % 4) * SPECTRANET_PAGE_LENGTH + (address & 0xfff); + return flash_am29f010_read( flash_rom, flash_page, flash_address ); +} + void spectranet_flash_rom_write( libspectrum_word address, libspectrum_byte b ) { @@ -559,6 +576,13 @@ spectranet_w5100_write( memory_page *page GCC_UNUSED, { } +libspectrum_byte +spectranet_flash_rom_read( memory_page *page GCC_UNUSED, + libspectrum_word address GCC_UNUSED ) +{ + return 0xff; +} + void spectranet_flash_rom_write( libspectrum_word address GCC_UNUSED, libspectrum_byte b GCC_UNUSED ) diff --git a/peripherals/spectranet.h b/peripherals/spectranet.h index e6678cba..bd636cad 100644 --- a/peripherals/spectranet.h +++ b/peripherals/spectranet.h @@ -34,11 +34,13 @@ int spectranet_nmi_flipflop( void ); libspectrum_byte spectranet_w5100_read( memory_page *page, libspectrum_word address ); void spectranet_w5100_write( memory_page *page, libspectrum_word address, libspectrum_byte b ); +libspectrum_byte spectranet_flash_rom_read( memory_page *page, libspectrum_word address ); void spectranet_flash_rom_write( libspectrum_word address, libspectrum_byte b ); extern int spectranet_available; extern int spectranet_paged; extern int spectranet_w5100_paged_a, spectranet_w5100_paged_b; +extern int spectranet_flash_paged_a, spectranet_flash_paged_b; extern int spectranet_programmable_trap_active; extern libspectrum_word spectranet_programmable_trap; |