Change the way the system type is managed

and changed the logic on how the GPU use "color". 
Now IO register tell properly the selected system, and B&W swan does not allow to switch to color. Also the Swan do not start in color mode as it should.
This commit is contained in:
Godzil
2021-04-05 13:23:44 +01:00
parent 330262b55c
commit 925bfd3b65
9 changed files with 650 additions and 721 deletions

18
main.c
View File

@@ -47,7 +47,6 @@ int gui_get_key_key;
int ws_videoEnhancementType=0;
int ws_colourScheme=COLOUR_SCHEME_DEFAULT;
int ws_system=WS_SYSTEM_COLOR;
int sram_path_explicit = 0;
int ieep_path_explicit = 0;
@@ -121,16 +120,16 @@ int ws_mk_ieppath()
int main(int argc, char *argv[])
{
if (!log_init(LOG_PATH))
{
printf("Warning: cannot open log file %s\n",LOG_PATH);
}
wssystem_t ws_system = WS_SYSTEM_AUTODETECT;
snprintf(app_window_title, 255, "Oswan %s - Esc to return to GUI", VERSION);
if (!log_init(LOG_PATH))
{
printf("Warning: cannot open log file %s\n", LOG_PATH);
}
fprintf(log_get(),"NewOswan %s (built at: %s %s)\n",VERSION , __DATE__, __TIME__);
snprintf(app_window_title, 255, "Oswan %s - Esc to return to GUI", VERSION);
ws_system = WS_SYSTEM_COLOR;
fprintf(log_get(), "NewOswan %s (built at: %s %s)\n", VERSION, __DATE__, __TIME__);
ws_rom_path = NULL;
@@ -195,9 +194,6 @@ int main(int argc, char *argv[])
app_rotated=ws_rotated();
app_gameRunning=1;
if (ws_system == WS_SYSTEM_COLOR)
{
ws_gpu_operatingInColor=1;
}
ws_set_colour_scheme(ws_colourScheme);

View File

@@ -27,6 +27,7 @@
#include "./nec/nec.h"
#include "io.h"
#include "gpu.h"
#include "ws.h"
#ifdef STATISTICS
#include "ticker.h"
@@ -100,9 +101,6 @@ int16_t ws_palette[16*4];
int8_t ws_paletteColors[8];
int16_t wsc_palette[16*16];
int16_t ws_shades[16];
int ws_gpu_forceColorSystemBool=0;
int ws_gpu_forceMonoSystemBool=0;
// white
@@ -232,40 +230,6 @@ void ws_gpu_set_colour_scheme(int scheme)
//
//
////////////////////////////////////////////////////////////////////////////////
void ws_gpu_forceColorSystem(void)
{
ws_gpu_forceColorSystemBool=1;
ws_gpu_forceMonoSystemBool=0;
ws_gpu_operatingInColor=1;
}
////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////
//
//
//
//
//
//
//
////////////////////////////////////////////////////////////////////////////////
void ws_gpu_forceMonoSystem(void)
{
ws_gpu_forceColorSystemBool=0;
ws_gpu_forceMonoSystemBool=1;
ws_gpu_operatingInColor=0;
}
////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////
//
//
//
//
//
//
//
////////////////////////////////////////////////////////////////////////////////
void ws_gpu_init(void)
{
ws_tile_cache = (uint8_t*)malloc(1024*8*8);
@@ -286,8 +250,6 @@ void ws_gpu_init(void)
memset(ws_modified_tile,0x01,1024);
memset(wsc_modified_tile,0x01,1024);
ws_gpu_forceColorSystemBool=0;
ws_gpu_forceMonoSystemBool=0;
}
////////////////////////////////////////////////////////////////////////////////
//
@@ -356,12 +318,18 @@ void ws_gpu_done(void)
////////////////////////////////////////////////////////////////////////////////
void ws_gpu_changeVideoMode(uint8_t value)
{
if (ws_videoMode != (value>>5))
{
ws_videoMode = value >> 5;
memset(ws_modified_tile,0x01,1024);
}
if (ws_videoMode != (value >> 5))
{
ws_videoMode = value >> 5;
memset(ws_modified_tile, 0x01, 1024);
}
ws_gpu_operatingInColor = 0;
if (value & 0x80)
{
ws_gpu_operatingInColor = 1;
}
}
////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////
@@ -2204,60 +2172,64 @@ void ws_gpu_write_byte(uint32_t offset, uint8_t value)
//
////////////////////////////////////////////////////////////////////////////////
unsigned int ws_gpu_unknownPort;
int ws_gpu_port_write(uint32_t port,uint8_t value)
int ws_gpu_port_write(uint32_t port, uint8_t value)
{
ws_gpu_unknownPort=0;
ws_gpu_unknownPort = 0;
switch (port)
{
case 0x60:
ws_gpu_changeVideoMode(value);
return 0;
switch (port)
{
case 0x60:
if (ws_get_system() != WS_SYSTEM_MONO)
{
ws_gpu_changeVideoMode(value);
}
return 0;
case 0x1C:
ws_paletteColors[0]=value&0xf;
ws_paletteColors[1]=(value>>4)&0xf;
return 0;
case 0x1C:
ws_paletteColors[0] = value & 0xf;
ws_paletteColors[1] = (value >> 4) & 0xf;
return 0;
case 0x1D:
ws_paletteColors[2]=value&0xf;
ws_paletteColors[3]=(value>>4)&0xf;
return 0;
case 0x1D:
ws_paletteColors[2] = value & 0xf;
ws_paletteColors[3] = (value >> 4) & 0xf;
return 0;
case 0x1E:
ws_paletteColors[4]=value&0xf;
ws_paletteColors[5]=(value>>4)&0xf;
return 0;
case 0x1E:
ws_paletteColors[4] = value & 0xf;
ws_paletteColors[5] = (value >> 4) & 0xf;
return 0;
case 0x1F:
ws_paletteColors[6]=value&0xf;
ws_paletteColors[7]=(value>>4)&0xf;
return 0;
case 0x1F:
ws_paletteColors[6] = value & 0xf;
ws_paletteColors[7] = (value >> 4) & 0xf;
return 0;
default:
ws_gpu_unknownPort=1;
}
default:ws_gpu_unknownPort = 1;
}
if ((port>=0x20)&&(port<=0x3f))
{
ws_gpu_unknownPort=0;
port-=0x20;
int paletteIndex=port>>1;
if ((port >= 0x20) && (port <= 0x3f))
{
ws_gpu_unknownPort = 0;
port -= 0x20;
int paletteIndex = port >> 1;
if (port&0x01)
{
ws_palette[(paletteIndex<<2)+2]=value&0x7;
ws_palette[(paletteIndex<<2)+3]=(value>>4)&0x7;
}
else
{
ws_palette[(paletteIndex<<2)+0]=value&0x7;
ws_palette[(paletteIndex<<2)+1]=(value>>4)&0x7;
}
}
if (port & 0x01)
{
ws_palette[(paletteIndex << 2) + 2] = value & 0x7;
ws_palette[(paletteIndex << 2) + 3] = (value >> 4) & 0x7;
}
else
{
ws_palette[(paletteIndex << 2) + 0] = value & 0x7;
ws_palette[(paletteIndex << 2) + 1] = (value >> 4) & 0x7;
}
}
return ws_gpu_unknownPort;
return ws_gpu_unknownPort;
}
////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////
@@ -2271,43 +2243,32 @@ int ws_gpu_port_write(uint32_t port,uint8_t value)
////////////////////////////////////////////////////////////////////////////////
uint8_t ws_gpu_port_read(uint8_t port)
{
switch(port)
{
case 0xa0:
if (ws_gpu_forceColorSystemBool)
{
return ws_ioRam[0xa0]|2;
}
else if (ws_gpu_forceMonoSystemBool)
{
return ws_ioRam[0xa0]&(~0x02);
}
else
{
if (ws_gpu_operatingInColor)
{
return ws_ioRam[0xa0]|2;
}
else
{
return ws_ioRam[0xa0]&(~0x02);
}
}
switch (port)
{
case 0xa0:
ws_ioRam[0xA0] |= 0x80;
if (ws_get_system() == WS_SYSTEM_MONO)
{
return ws_ioRam[0xa0] & (~0x2);
}
else
{
return ws_ioRam[0xa0] | 2;
}
break;
break;
case 0xaa:
return vblank_count & 0xff;
case 0xaa:
return vblank_count&0xff;
case 0xab:
return (vblank_count >> 8) & 0xff;
case 0xab:
return (vblank_count>>8)&0xff;
case 0xac:
return (vblank_count >> 16) & 0xff;
case 0xac:
return (vblank_count>>16)&0xff;
case 0xad:
return (vblank_count >> 24) & 0xff;
}
case 0xad:
return (vblank_count>>24)&0xff;
}
return(ws_ioRam[port]);
return (ws_ioRam[port]);
}

View File

@@ -39,8 +39,6 @@ int ws_gpu_port_write(uint32_t port, uint8_t value);
uint8_t ws_gpu_port_read(uint8_t port);
void ws_gpu_set_colour_scheme(int scheme);
void ws_gpu_changeVideoMode(uint8_t value);
void ws_gpu_forceColorSystem(void);
void ws_gpu_forceMonoSystem(void);
void ws_gpu_clearCache(void);
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -21,6 +21,7 @@
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include "ws.h"
#include "log.h"
#include "rom.h"
#include "./nec/nec.h"
@@ -159,78 +160,89 @@ void cpu_writemem20(uint32_t addr, uint8_t value)
////////////////////////////////////////////////////////////////////////////////
uint8_t cpu_readmem20(uint32_t addr)
{
uint32_t offset=addr&0xffff;
uint32_t bank=addr>>16;
//uint16_t romBank;
uint8_t hwReg;
uint32_t temp;
uint8_t ret;
uint32_t offset = addr & 0xffff;
uint32_t bank = addr >> 16;
//uint16_t romBank;
uint8_t hwReg;
uint32_t temp;
uint8_t ret;
wssystem_t currentSystem = ws_get_system();
switch (bank)
{
case 0: // 0 - RAM - 16 KB (WS) / 64 KB (WSC) internal RAM
if (ws_gpu_operatingInColor)
{
return(internalRam[offset]);
}
else if (offset<0x4000)
{
return(internalRam[offset]);
}
switch (bank)
{
case 0:
/*
* So the original WonderSwan, and Color/Crystal in B&W mode have 16KB of IRAM Mapped.
* Color/Crystal in color mode have 64 KB IRAM mapped.
*/
if (ws_gpu_operatingInColor)
{
return (internalRam[offset]);
}
else if (offset < 0x4000)
{
return (internalRam[offset]);
}
return(0x90);
return (0x90);
case 1: // 1 - SRAM (cart)
return ws_staticRam[offset&sramAddressMask];
case 1: // 1 - SRAM (cart)
return ws_staticRam[offset & sramAddressMask];
case 2:
// Bank 2
hwReg = ws_ioRam[0xC2];
temp = hwReg << 16;
temp += offset;
temp &= (romSize - 1);
return ws_rom[temp];
case 3:
// Bank 3
hwReg = ws_ioRam[0xC3];
temp = hwReg << 16;
temp += offset;
temp &= (romSize - 1);
return ws_rom[temp];
case 2:
// Bank 2
hwReg = ws_ioRam[0xC2];
temp = hwReg << 16;
temp += offset;
temp &= (romSize - 1);
return ws_rom[temp];
case 3:
// Bank 3
hwReg = ws_ioRam[0xC3];
temp = hwReg << 16;
temp += offset;
temp &= (romSize - 1);
return ws_rom[temp];
case 0xF:
hwReg = ws_ioRam[0xA0];
case 0xF:hwReg = ws_ioRam[0xA0];
if (!(hwReg & 1))
{
if (ws_gpu_operatingInColor && ws_haveColorIRom)
{
if (addr >= 0xFE000)
if (!(hwReg & 1))
{
if (currentSystem == WS_SYSTEM_COLOR && ws_haveColorIRom)
{
ret = internalColorIRom[addr & ~0xFE000];
return ret;
if (addr >= 0xFE000)
{
ret = internalColorIRom[addr & ~0xFE000];
return ret;
}
}
}
else if (!ws_gpu_operatingInColor && ws_haveBWIRom)
{
if (addr >= 0xFF000)
else if (currentSystem == WS_SYSTEM_CRYSTAL && ws_haveColorIRom)
{
ret = internalBWIRom[addr & ~0xFF000];
return ret;
if (addr >= 0xFE000)
{
ret = internalCrystalIRom[addr & ~0xFE000];
return ret;
}
}
}
}
// fall through
else if (currentSystem == WS_SYSTEM_MONO && ws_haveBWIRom)
{
if (addr >= 0xFF000)
{
ret = internalBWIRom[addr & ~0xFF000];
return ret;
}
}
}
// fall through
default:
hwReg = ws_ioRam[0xC0];
temp = hwReg << 20;
temp += addr & 0xFFFFF;
temp &= (romSize - 1);
return ws_rom[temp];
}
default:hwReg = ws_ioRam[0xC0];
temp = hwReg << 20;
temp += addr & 0xFFFFF;
temp &= (romSize - 1);
return ws_rom[temp];
}
return(0x90);
return (0x90);
}
////////////////////////////////////////////////////////////////////////////////
//

View File

@@ -74,7 +74,7 @@ void ws_rom_dumpInfo(uint8_t *wsrom, uint32_t romSize)
fprintf(log_get(),"rom: developper Id 0x%.2x\n",romHeader->developperId);
fprintf(log_get(),"rom: cart Id 0x%.2x\n",romHeader->cartId);
fprintf(log_get(),"rom: minimum system %s\n",(romHeader->minimumSupportSystem==WS_SYSTEM_MONO)?"Wonderswan mono":"Wonderswan color");
fprintf(log_get(),"rom: minimum system %s\n",(romHeader->minimumSupportSystem==0)?"Wonderswan mono":"Wonderswan color");
fprintf(log_get(),"rom: size %i Mbits\n",(romSize>>20)<<3);
fprintf(log_get(),"rom: eeprom ");

View File

@@ -14,9 +14,6 @@
#include <stdint.h>
#define WS_SYSTEM_MONO 0
#define WS_SYSTEM_COLOR 1
#define WS_ROM_SIZE_2MBIT 1
#define WS_ROM_SIZE_4MBIT 2
#define WS_ROM_SIZE_8MBIT 3

View File

@@ -51,8 +51,6 @@ uint32_t vblank_count=0;
char *ws_sram_path = NULL;
char *ws_ieep_path = NULL;
char *ws_rom_path = NULL;
extern int ws_gpu_forceColorSystemBool;
extern int ws_gpu_forceMonoSystemBool;
////////////////////////////////////////////////////////////////////////////////
//
@@ -307,31 +305,18 @@ void ws_done(void)
//
//
////////////////////////////////////////////////////////////////////////////////
void ws_set_colour_scheme(int scheme)
void ws_set_system(wssystem_t system)
{
ws_gpu_set_colour_scheme(scheme);
if (system == WS_SYSTEM_AUTODETECT)
{
system = WS_SYSTEM_CRYSTAL;
}
systemType = system;
}
////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////
//
//
//
//
//
//
//
////////////////////////////////////////////////////////////////////////////////
void ws_set_system(int system)
wssystem_t ws_get_system()
{
if (system==WS_SYSTEM_COLOR)
{
ws_gpu_forceColorSystem();
}
else if (system==WS_SYSTEM_MONO)
{
ws_gpu_forceMonoSystem();
}
return systemType;
}
////////////////////////////////////////////////////////////////////////////////
//

View File

@@ -14,16 +14,20 @@
#include <stdint.h>
#define WS_SYSTEM_MONO 0
#define WS_SYSTEM_COLOR 1
#define WS_SYSTEM_AUTODETECT 2
typedef enum wssystem_t {
WS_SYSTEM_AUTODETECT = 0,
WS_SYSTEM_MONO,
WS_SYSTEM_COLOR,
WS_SYSTEM_CRYSTAL,
} wssystem_t;
extern uint32_t ws_cyclesByLine;
int ws_init(char *rompath);
int ws_rotated(void);
void ws_set_colour_scheme(int scheme);
void ws_set_system(int system);
void ws_set_system(wssystem_t system);
wssystem_t ws_get_system();
void ws_reset(void);
int ws_executeLine(int16_t *framebuffer, int renderLine);
void ws_patchRom(void);