diff --git a/BizHawk.Emulation.Cores/Consoles/WonderSwan/BizSwan.cs b/BizHawk.Emulation.Cores/Consoles/WonderSwan/BizSwan.cs index 81e10ed943..6abb0973ae 100644 --- a/BizHawk.Emulation.Cores/Consoles/WonderSwan/BizSwan.cs +++ b/BizHawk.Emulation.Cores/Consoles/WonderSwan/BizSwan.cs @@ -11,21 +11,78 @@ namespace BizHawk.Emulation.Cores.WonderSwan const CallingConvention cc = CallingConvention.Cdecl; const string dd = "bizswan.dll"; + /// + /// create new instance + /// + /// [DllImport(dd, CallingConvention = cc)] public static extern IntPtr bizswan_new(); + /// + /// delete instance, freeing all associated memory + /// + /// [DllImport(dd, CallingConvention = cc)] public static extern void bizswan_delete(IntPtr core); + /// + /// hard reset + /// + /// [DllImport(dd, CallingConvention = cc)] public static extern void bizswan_reset(IntPtr core); + /// + /// frame advance + /// + /// + /// input to use on this frame + /// true to skip all video rendering + /// uint32 video output buffer + /// int16 sound output buffer + /// [In] max hold size of soundbuff [Out] number of samples actually deposited [DllImport(dd, CallingConvention = cc)] public static extern void bizswan_advance(IntPtr core, Buttons buttons, bool novideo, int[] surface, short[] soundbuff, ref int soundbuffsize); + /// + /// load rom + /// + /// + /// + /// + /// + /// [DllImport(dd, CallingConvention = cc)] public static extern bool bizswan_load(IntPtr core, byte[] data, int length, [In] ref Settings settings); + /// + /// get size of saveram + /// + /// + /// + [DllImport(dd, CallingConvention = cc)] + public static extern int bizswan_saveramsize(IntPtr core); + + /// + /// load saveram into core + /// + /// + /// + /// should be same as bizswan_saveramsize() + /// false if size mismatch + [DllImport(dd, CallingConvention = cc)] + public static extern bool bizswan_saveramload(IntPtr core, byte[] data, int size); + + /// + /// save saveram from core + /// + /// + /// + /// should be same as bizswan_saveramsize() + /// false if size mismatch + [DllImport(dd, CallingConvention = cc)] + public static extern bool bizswan_saveramsave(IntPtr core, byte[] data, int maxsize); + [Flags] public enum Buttons : ushort { diff --git a/BizHawk.Emulation.Cores/Consoles/WonderSwan/WonderSwan.cs b/BizHawk.Emulation.Cores/Consoles/WonderSwan/WonderSwan.cs index 54bea55575..ae09f88f59 100644 --- a/BizHawk.Emulation.Cores/Consoles/WonderSwan/WonderSwan.cs +++ b/BizHawk.Emulation.Cores/Consoles/WonderSwan/WonderSwan.cs @@ -65,6 +65,8 @@ namespace BizHawk.Emulation.Cores.WonderSwan CoreComm.VsyncNum = 3072000; // master CPU clock, also pixel clock CoreComm.VsyncDen = (144 + 15) * (224 + 32); // 144 vislines, 15 vblank lines; 224 vispixels, 32 hblank pixels + + saverambuff = new byte[BizSwan.bizswan_saveramsize(Core)]; } catch { @@ -101,6 +103,15 @@ namespace BizHawk.Emulation.Cores.WonderSwan LagCount++; } + public CoreComm CoreComm { get; private set; } + + public void ResetCounters() + { + Frame = 0; + IsLagFrame = false; + LagCount = 0; + } + IntPtr Core; public int Frame { get; private set; } @@ -114,40 +125,34 @@ namespace BizHawk.Emulation.Cores.WonderSwan #region SaveRam + byte[] saverambuff; + public byte[] ReadSaveRam() { - return new byte[0]; + if (!BizSwan.bizswan_saveramsave(Core, saverambuff, saverambuff.Length)) + throw new InvalidOperationException("bizswan_saveramsave() returned false!"); + return saverambuff; } public void StoreSaveRam(byte[] data) { - + if (!BizSwan.bizswan_saveramload(Core, data, data.Length)) + throw new InvalidOperationException("bizswan_saveramload() returned false!"); } public void ClearSaveRam() { - + throw new InvalidOperationException("A new core starts with a clear saveram. Instantiate a new core if you want this."); } public bool SaveRamModified { - get - { - return false; - } - set - { - - } + get { return BizSwan.bizswan_saveramsize(Core) > 0; } + set { throw new InvalidOperationException(); } } #endregion - public void ResetCounters() - { - throw new NotImplementedException(); - } - #region Savestates public void SaveStateText(TextWriter writer) @@ -178,8 +183,6 @@ namespace BizHawk.Emulation.Cores.WonderSwan #endregion - public CoreComm CoreComm { get; private set; } - #region Debugging public MemoryDomainList MemoryDomains diff --git a/output/dll/bizswan.dll b/output/dll/bizswan.dll index 5000718d63..76a33992fc 100644 Binary files a/output/dll/bizswan.dll and b/output/dll/bizswan.dll differ diff --git a/wonderswan/eeprom.cpp b/wonderswan/eeprom.cpp index 087915403e..03925c47ab 100644 --- a/wonderswan/eeprom.cpp +++ b/wonderswan/eeprom.cpp @@ -24,8 +24,6 @@ namespace MDFN_IEN_WSWAN { - //uint8 wsEEPROM[2048]; - //static uint8 iEEPROM[0x400]; static const uint8 iEEPROM_Init[0x400] = { 255,255,255,255,255,255,192,255,0,0,0,0, diff --git a/wonderswan/eeprom.h b/wonderswan/eeprom.h index 26d5e7b4f5..2538e39990 100644 --- a/wonderswan/eeprom.h +++ b/wonderswan/eeprom.h @@ -16,11 +16,14 @@ public: void Init(const char *Name, const uint16 BYear, const uint8 BMonth, const uint8 BDay, const uint8 Sex, const uint8 Blood); private: - uint8 wsEEPROM[2048]; - uint8 iEEPROM[0x400]; uint8 iEEPROM_Command, EEPROM_Command; uint16 iEEPROM_Address, EEPROM_Address; +public: uint32 eeprom_size; + uint8 iEEPROM[0x400]; + uint8 wsEEPROM[2048]; + + enum { ieeprom_size = 0x400 }; public: System *sys; diff --git a/wonderswan/gfx.cpp b/wonderswan/gfx.cpp index d34f238a2e..f16519b392 100644 --- a/wonderswan/gfx.cpp +++ b/wonderswan/gfx.cpp @@ -26,14 +26,11 @@ namespace MDFN_IEN_WSWAN { GFX::GFX() + :LayerEnabled(7) // 1 = bg, 2 = fg, 4 = sprite { SetPixelFormat(); } - void GFX::Init() - { - LayerEnabled = 7; // BG, FG, sprites - } void GFX::PaletteRAMWrite(uint32 ws_offset, uint8 data) { diff --git a/wonderswan/gfx.h b/wonderswan/gfx.h index 3974a4b8d1..f30709239b 100644 --- a/wonderswan/gfx.h +++ b/wonderswan/gfx.h @@ -20,7 +20,6 @@ public: void Scanline(uint32 *target); void SetPixelFormat(); - void Init(); void Reset(); void Write(uint32 A, uint8 V); uint8 Read(uint32 A); diff --git a/wonderswan/memory.cpp b/wonderswan/memory.cpp index 847798ae35..8ccef25115 100644 --- a/wonderswan/memory.cpp +++ b/wonderswan/memory.cpp @@ -289,42 +289,13 @@ namespace MDFN_IEN_WSWAN } } - /* - void Memory::Kill() - { - if((sram_size || eeprom_size) && !SkipSL) - { - - std::vector EvilRams; - - if(eeprom_size) - EvilRams.push_back(PtrLengthPair(wsEEPROM, eeprom_size)); - - if(sram_size) - EvilRams.push_back(PtrLengthPair(wsSRAM, sram_size)); - - MDFN_DumpToFile(MDFN_MakeFName(MDFNMKF_SAV, 0, "sav").c_str(), 6, EvilRams); - - } - - if(wsSRAM) - { - free(wsSRAM); - wsSRAM = NULL; - } - } - */ - - void Memory::Init(bool SkipSaveLoad, const Settings &settings) + void Memory::Init(const Settings &settings) { char tmpname[17]; std::memcpy(tmpname, settings.name, 16); tmpname[16] = 0; - language = settings.language; - SkipSL = SkipSaveLoad; - // WSwan_EEPROMInit() will also clear wsEEPROM sys->eeprom.Init(tmpname, settings.byear, settings.bmonth, settings.bday, settings.sex, settings.blood); @@ -334,28 +305,6 @@ namespace MDFN_IEN_WSWAN wsSRAM = (uint8*)malloc(sram_size); memset(wsSRAM, 0, sram_size); } - - /* TODO: SAVERAM - if((sram_size || eeprom_size) && !SkipSL) - { - gzFile savegame_fp; - - savegame_fp = gzopen(MDFN_MakeFName(MDFNMKF_SAV, 0, "sav").c_str(), "rb"); - if(savegame_fp) - { - if(eeprom_size) - gzread(savegame_fp, wsEEPROM, eeprom_size); - if(sram_size) - gzread(savegame_fp, wsSRAM, sram_size); - gzclose(savegame_fp); - } - } - */ - - //MDFNMP_AddRAM(wsRAMSize, 0x00000, wsRAM); // 65536 - - //if(sram_size) - // MDFNMP_AddRAM(sram_size, 0x10000, wsSRAM); } void Memory::Reset() diff --git a/wonderswan/memory.h b/wonderswan/memory.h index 779685768e..fc19116774 100644 --- a/wonderswan/memory.h +++ b/wonderswan/memory.h @@ -13,8 +13,7 @@ public: uint8 Read20(uint32); void Write20(uint32 address,uint8 data); - void Init(bool SkipSaveLoad, const Settings &settings); - //void Kill(); + void Init(const Settings &settings); void CheckSoundDMA(); void Reset(); @@ -22,21 +21,17 @@ public: uint8 readport(uint32 number); uint32 GetRegister(const unsigned int id, char *special, const uint32 special_len); void SetRegister(const unsigned int id, uint32 value); - -private: - bool SkipSL; // Skip save and load public: uint8 wsRAM[65536]; uint8 *wsCartROM; uint32 rom_size; uint32 sram_size; - uint32 eeprom_size; + uint8 *wsSRAM; // = NULL; uint16 WSButtonStatus; // bitfield of buttons, indeed private: - uint8 *wsSRAM; // = NULL; uint8 ButtonWhich, ButtonReadLatch; @@ -63,13 +58,6 @@ private: }; - -//extern uint8 wsRAM[65536]; -//extern uint8 *wsCartROM; -//extern uint32 eeprom_size; -//extern uint8 wsEEPROM[2048]; - - enum { MEMORY_GSREG_ROMBBSLCT = 0, diff --git a/wonderswan/rtc.cpp b/wonderswan/rtc.cpp index 643a140637..9ee167b0b9 100644 --- a/wonderswan/rtc.cpp +++ b/wonderswan/rtc.cpp @@ -23,14 +23,6 @@ namespace MDFN_IEN_WSWAN { - - /* - static uint64 CurrentTime; - static uint32 ClockCycleCounter; - static uint8 wsCA15; - static uint8 Command, Data; - */ - void RTC::Write(uint32 A, uint8 V) { switch(A) diff --git a/wonderswan/sound.cpp b/wonderswan/sound.cpp index 90300a61e9..f484d8f1e5 100644 --- a/wonderswan/sound.cpp +++ b/wonderswan/sound.cpp @@ -309,10 +309,6 @@ namespace MDFN_IEN_WSWAN Update(); } - void Sound::Init() - { - } - Sound::Sound() { for(int i = 0; i < 2; i++) diff --git a/wonderswan/sound.h b/wonderswan/sound.h index e0c9cddd04..47fc9ae3e3 100644 --- a/wonderswan/sound.h +++ b/wonderswan/sound.h @@ -15,8 +15,6 @@ public: int32 Flush(int16 *SoundBuf, const int32 MaxSoundFrames); - void Init(); - void Kill(); void SetMultiplier(double multiplier); bool SetRate(uint32 rate); diff --git a/wonderswan/start.inc b/wonderswan/start.inc index 54a871f986..c2d6d3daea 100644 --- a/wonderswan/start.inc +++ b/wonderswan/start.inc @@ -267,3 +267,50 @@ const uint8 startio[256]={ 0xd1,//fd 0xd1,//fe 0xd1};//ff + + +typedef struct +{ + const uint8 id; + const char *name; +} DLEntry; + +static const DLEntry Developers[] = + { + { 0x01, "Bandai" }, + { 0x02, "Taito" }, + { 0x03, "Tomy" }, + { 0x04, "Koei" }, + { 0x05, "Data East" }, + { 0x06, "Asmik" }, // Asmik Ace? + { 0x07, "Media Entertainment" }, + { 0x08, "Nichibutsu" }, + { 0x0A, "Coconuts Japan" }, + { 0x0B, "Sammy" }, + { 0x0C, "Sunsoft" }, + { 0x0D, "Mebius" }, + { 0x0E, "Banpresto" }, + { 0x10, "Jaleco" }, + { 0x11, "Imagineer" }, + { 0x12, "Konami" }, + { 0x16, "Kobunsha" }, + { 0x17, "Bottom Up" }, + { 0x18, "Naxat" }, // Mechanic Arms? Media Entertainment? Argh! + { 0x19, "Sunrise" }, + { 0x1A, "Cyberfront" }, + { 0x1B, "Megahouse" }, + { 0x1D, "Interbec" }, + { 0x1E, "NAC" }, + { 0x1F, "Emotion" }, // Bandai Visual?? + { 0x20, "Athena" }, + { 0x21, "KID" }, + { 0x24, "Omega Micott" }, + { 0x25, "Upstar" }, + { 0x26, "Kadokawa/Megas" }, + { 0x27, "Cocktail Soft" }, + { 0x28, "Squaresoft" }, + { 0x2B, "TomCreate" }, + { 0x2D, "Namco" }, + { 0x2F, "Gust" }, + { 0x36, "Capcom" }, +}; diff --git a/wonderswan/system.cpp b/wonderswan/system.cpp index d314822362..62b4ba7ea5 100644 --- a/wonderswan/system.cpp +++ b/wonderswan/system.cpp @@ -29,53 +29,21 @@ namespace MDFN_IEN_WSWAN { -#include "start.inc" + // maybe change? + int Debug::puts ( const char * str ) + { + return std::puts(str); + } + int Debug::printf ( const char * format, ... ) + { + va_list args; + va_start(args, format); + int ret = vprintf(format, args); + va_end(args); + return ret; + } - typedef struct - { - const uint8 id; - const char *name; - } DLEntry; - - static const DLEntry Developers[] = - { - { 0x01, "Bandai" }, - { 0x02, "Taito" }, - { 0x03, "Tomy" }, - { 0x04, "Koei" }, - { 0x05, "Data East" }, - { 0x06, "Asmik" }, // Asmik Ace? - { 0x07, "Media Entertainment" }, - { 0x08, "Nichibutsu" }, - { 0x0A, "Coconuts Japan" }, - { 0x0B, "Sammy" }, - { 0x0C, "Sunsoft" }, - { 0x0D, "Mebius" }, - { 0x0E, "Banpresto" }, - { 0x10, "Jaleco" }, - { 0x11, "Imagineer" }, - { 0x12, "Konami" }, - { 0x16, "Kobunsha" }, - { 0x17, "Bottom Up" }, - { 0x18, "Naxat" }, // Mechanic Arms? Media Entertainment? Argh! - { 0x19, "Sunrise" }, - { 0x1A, "Cyberfront" }, - { 0x1B, "Megahouse" }, - { 0x1D, "Interbec" }, - { 0x1E, "NAC" }, - { 0x1F, "Emotion" }, // Bandai Visual?? - { 0x20, "Athena" }, - { 0x21, "KID" }, - { 0x24, "Omega Micott" }, - { 0x25, "Upstar" }, - { 0x26, "Kadokawa/Megas" }, - { 0x27, "Cocktail Soft" }, - { 0x28, "Squaresoft" }, - { 0x2B, "TomCreate" }, - { 0x2D, "Namco" }, - { 0x2F, "Gust" }, - { 0x36, "Capcom" }, - }; +#include "start.inc" void System::Reset() { @@ -179,7 +147,7 @@ namespace MDFN_IEN_WSWAN } memory.sram_size = 0; - memory.eeprom_size = 0; + eeprom.eeprom_size = 0; switch(header[5]) { @@ -188,15 +156,15 @@ namespace MDFN_IEN_WSWAN case 0x03: memory.sram_size = 16 * 65536; break; case 0x04: memory.sram_size = 32 * 65536; break; // Dicing Knight! - case 0x10: memory.eeprom_size = 128; break; - case 0x20: memory.eeprom_size = 2*1024; break; - case 0x50: memory.eeprom_size = 1024; break; + case 0x10: eeprom.eeprom_size = 128; break; + case 0x20: eeprom.eeprom_size = 2*1024; break; + case 0x50: eeprom.eeprom_size = 1024; break; } //printf("%02x\n", header[5]); - if(memory.eeprom_size) - Debug::printf("EEPROM: %d bytes\n", memory.eeprom_size); + if(eeprom.eeprom_size) + Debug::printf("EEPROM: %d bytes\n", eeprom.eeprom_size); if(memory.sram_size) Debug::printf("Battery-backed RAM: %d bytes\n", memory.sram_size); @@ -229,18 +197,13 @@ namespace MDFN_IEN_WSWAN //MDFNMP_Init(16384, (1 << 20) / 1024); - cpu.init(); // TODO: control WSC setting - // TODO: rip out skipsaveload code - memory.Init(false, settings); + memory.Init(settings); - gfx.Init(); //MDFNGameInfo->fps = (uint32)((uint64)3072000 * 65536 * 256 / (159*256)); - sound.Init(); - gfx.MakeTiles(); Reset(); @@ -271,20 +234,44 @@ namespace MDFN_IEN_WSWAN { } - // maybe change? - int Debug::puts ( const char * str ) + int System::SaveRamSize() { - return std::puts(str); + return eeprom.ieeprom_size + eeprom.eeprom_size + memory.sram_size; } - int Debug::printf ( const char * format, ... ) + bool System::SaveRamLoad(const uint8 *data, int size) { - va_list args; - va_start(args, format); - int ret = vprintf(format, args); - va_end(args); - return ret; + if (size != SaveRamSize()) + return false; + + #define LOAD(sz,ptr) { if (sz) { std::memcpy((ptr), data, (sz)); data += (sz); } } + + LOAD(eeprom.ieeprom_size, eeprom.iEEPROM); + LOAD(eeprom.eeprom_size, eeprom.wsEEPROM); + LOAD(memory.sram_size, memory.wsSRAM); + + #undef LOAD + + return true; } + bool System::SaveRamSave(uint8 *dest, int maxsize) + { + if (maxsize != SaveRamSize()) + return false; + + #define SAVE(sz,ptr) { if (sz) { std::memcpy(dest, (ptr), (sz)); dest += (sz); } } + + SAVE(eeprom.ieeprom_size, eeprom.iEEPROM); + SAVE(eeprom.eeprom_size, eeprom.wsEEPROM); + SAVE(memory.sram_size, memory.wsSRAM); + + #undef SAVE + + return true; + } + + + EXPORT System *bizswan_new() @@ -312,4 +299,19 @@ namespace MDFN_IEN_WSWAN return s->Load(data, length, *settings); } + EXPORT int bizswan_saveramsize(System *s) + { + return s->SaveRamSize(); + } + + EXPORT int bizswan_saveramload(System *s, const uint8 *data, int size) + { + return s->SaveRamLoad(data, size); + } + + EXPORT int bizswan_saveramsave(System *s, uint8 *dest, int maxsize) + { + return s->SaveRamSave(dest, maxsize); + } + } diff --git a/wonderswan/system.h b/wonderswan/system.h index 9638b83d66..81c6514f5d 100644 --- a/wonderswan/system.h +++ b/wonderswan/system.h @@ -32,6 +32,10 @@ public: void Advance(uint16 buttons, bool novideo, uint32 *surface, int16 *soundbuff, int &soundbuffsize); bool Load(const uint8 *data, int length, const Settings &s); + int SaveRamSize(); + bool SaveRamLoad(const uint8 *data, int size); + bool SaveRamSave(uint8 *dest, int maxsize); + public: GFX gfx; Memory memory; diff --git a/wonderswan/v30mz.cpp b/wonderswan/v30mz.cpp index 490d308527..fbccfd5f4e 100644 --- a/wonderswan/v30mz.cpp +++ b/wonderswan/v30mz.cpp @@ -126,11 +126,6 @@ namespace MDFN_IEN_WSWAN SetupEA(); } - void V30MZ::init() - { - - } - void V30MZ::reset() { const BREGS reg_name[8] = { AL, CL, DL, BL, AH, CH, DH, BH }; diff --git a/wonderswan/v30mz.h b/wonderswan/v30mz.h index 761b28b721..400a4d0cf5 100644 --- a/wonderswan/v30mz.h +++ b/wonderswan/v30mz.h @@ -46,7 +46,6 @@ public: void set_reg(int, unsigned); unsigned get_reg(int regnum); void reset(); - void init(); void interrupt(uint32 vector, bool IgnoreIF = FALSE);