gpgx: multidisk? dunno

This commit is contained in:
nattthebear 2017-07-17 18:49:16 -04:00
parent e61f7d7876
commit c31ebe176d
10 changed files with 1078 additions and 1002 deletions

View File

@ -554,7 +554,7 @@ namespace BizHawk.Client.Common
switch (game.System) switch (game.System)
{ {
case "GEN": case "GEN":
var genesis = new GPGX(nextComm, null, disc, GetCoreSettings<GPGX>(), GetCoreSyncSettings<GPGX>()); var genesis = new GPGX(nextComm, null, new[] { disc }, GetCoreSettings<GPGX>(), GetCoreSyncSettings<GPGX>());
nextEmulator = genesis; nextEmulator = genesis;
break; break;
case "SAT": case "SAT":

View File

@ -16,6 +16,28 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
Core.gpgx_reset(false); Core.gpgx_reset(false);
if (controller.IsPressed("Power")) if (controller.IsPressed("Power"))
Core.gpgx_reset(true); Core.gpgx_reset(true);
if (_cds != null)
{
var prev = controller.IsPressed("Previous Disk");
var next = controller.IsPressed("Next Disk");
int newDisk = _discIndex;
if (prev && !_prevDiskPressed)
newDisk--;
if (next && !_nextDiskPressed)
newDisk++;
if (newDisk < -1)
newDisk = -1;
if (newDisk >= _cds.Length)
newDisk = _cds.Length - 1;
if (newDisk != _discIndex)
{
_discIndex = newDisk;
Core.gpgx_swap_disc(_discIndex == -1 ? null : GetCDDataStruct(_cds[_discIndex]));
Console.WriteLine("IMMA CHANGING MAH DISKS");
}
}
// this shouldn't be needed, as nothing has changed // this shouldn't be needed, as nothing has changed
// if (!Core.gpgx_get_control(input, inputsize)) // if (!Core.gpgx_get_control(input, inputsize))
@ -39,7 +61,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
if (IsLagFrame) if (IsLagFrame)
LagCount++; LagCount++;
if (CD != null) if (_cds != null)
DriveLightOn = _drivelight; DriveLightOn = _drivelight;
} }
@ -70,8 +92,9 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
{ {
if (_elf != null) if (_elf != null)
_elf.Dispose(); _elf.Dispose();
if (CD != null) if (_cds != null)
CD.Dispose(); foreach (var cd in _cds)
cd.Dispose();
_disposed = true; _disposed = true;
} }
} }

View File

@ -36,6 +36,9 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
Frame = reader.ReadInt32(); Frame = reader.ReadInt32();
LagCount = reader.ReadInt32(); LagCount = reader.ReadInt32();
IsLagFrame = reader.ReadBoolean(); IsLagFrame = reader.ReadBoolean();
_discIndex = reader.ReadInt32();
_prevDiskPressed = reader.ReadBoolean();
_nextDiskPressed = reader.ReadBoolean();
// any managed pointers that we sent to the core need to be resent now! // any managed pointers that we sent to the core need to be resent now!
Core.gpgx_set_input_callback(InputCallback); Core.gpgx_set_input_callback(InputCallback);
RefreshMemCallbacks(); RefreshMemCallbacks();
@ -51,6 +54,9 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
writer.Write(Frame); writer.Write(Frame);
writer.Write(LagCount); writer.Write(LagCount);
writer.Write(IsLagFrame); writer.Write(IsLagFrame);
writer.Write(_discIndex);
writer.Write(_prevDiskPressed);
writer.Write(_nextDiskPressed);
} }
public byte[] SaveStateBinary() public byte[] SaveStateBinary()

View File

@ -7,6 +7,8 @@ using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Waterbox; using BizHawk.Emulation.Cores.Waterbox;
using BizHawk.Common; using BizHawk.Common;
using BizHawk.Emulation.DiscSystem; using BizHawk.Emulation.DiscSystem;
using System.Collections.Generic;
using System.Linq;
namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
{ {
@ -27,7 +29,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
{ {
} }
public GPGX(CoreComm comm, byte[] rom, DiscSystem.Disc CD, object settings, object syncSettings) public GPGX(CoreComm comm, byte[] rom, IEnumerable<Disc> cds, object settings, object syncSettings)
{ {
ServiceProvider = new BasicServiceProvider(this); ServiceProvider = new BasicServiceProvider(this);
// this can influence some things internally (autodetect romtype, etc) // this can influence some things internally (autodetect romtype, etc)
@ -64,12 +66,14 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
LoadCallback = new LibGPGX.load_archive_cb(load_archive); LoadCallback = new LibGPGX.load_archive_cb(load_archive);
this.romfile = rom; this.romfile = rom;
this.CD = CD;
if (CD != null) if (cds != null)
{ {
this.DiscSectorReader = new DiscSystem.DiscSectorReader(CD); _cds = cds.ToArray();
_cdReaders = cds.Select(c => new DiscSectorReader(c)).ToArray();
cd_callback_handle = new LibGPGX.cd_read_cb(CDRead); cd_callback_handle = new LibGPGX.cd_read_cb(CDRead);
Core.gpgx_set_cdd_callback(cd_callback_handle); Core.gpgx_set_cdd_callback(cd_callback_handle);
DriveLightEnabled = true;
} }
LibGPGX.INPUT_SYSTEM system_a = LibGPGX.INPUT_SYSTEM.SYSTEM_NONE; LibGPGX.INPUT_SYSTEM system_a = LibGPGX.INPUT_SYSTEM.SYSTEM_NONE;
@ -139,9 +143,6 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
InputCallback = new LibGPGX.input_cb(input_callback); InputCallback = new LibGPGX.input_cb(input_callback);
Core.gpgx_set_input_callback(InputCallback); Core.gpgx_set_input_callback(InputCallback);
if (CD != null)
DriveLightEnabled = true;
// process the non-init settings now // process the non-init settings now
PutSettings(_settings); PutSettings(_settings);
@ -159,8 +160,12 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
private LibGPGX Core; private LibGPGX Core;
private PeRunner _elf; private PeRunner _elf;
DiscSystem.Disc CD; private Disc[] _cds;
DiscSystem.DiscSectorReader DiscSectorReader; private int _discIndex;
private DiscSectorReader[] _cdReaders;
private bool _prevDiskPressed;
private bool _nextDiskPressed;
byte[] romfile; byte[] romfile;
private bool _disposed = false; private bool _disposed = false;
@ -217,12 +222,12 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
} }
else else
{ {
if (CD == null) if (_cds == null)
{ {
Console.WriteLine("Couldn't satisfy firmware request {0} because none was provided.", filename); Console.WriteLine("Couldn't satisfy firmware request {0} because none was provided.", filename);
return 0; return 0;
} }
srcdata = GetCDData(CD); srcdata = GetCDData(_cds[0]);
if (srcdata.Length != maxsize) if (srcdata.Length != maxsize)
{ {
Console.WriteLine("Couldn't satisfy firmware request {0} because of struct size.", filename); Console.WriteLine("Couldn't satisfy firmware request {0} because of struct size.", filename);
@ -282,13 +287,15 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
} }
void CDRead(int lba, IntPtr dest, bool audio) void CDRead(int lba, IntPtr dest, bool audio)
{
if ((uint)_discIndex < _cds.Length)
{ {
if (audio) if (audio)
{ {
byte[] data = new byte[2352]; byte[] data = new byte[2352];
if (lba < CD.Session1.LeadoutLBA) if (lba < _cds[_discIndex].Session1.LeadoutLBA)
{ {
DiscSectorReader.ReadLBA_2352(lba, data, 0); _cdReaders[_discIndex].ReadLBA_2352(lba, data, 0);
} }
else else
{ {
@ -301,18 +308,18 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
else else
{ {
byte[] data = new byte[2048]; byte[] data = new byte[2048];
DiscSectorReader.ReadLBA_2048(lba, data, 0); _cdReaders[_discIndex].ReadLBA_2048(lba, data, 0);
Marshal.Copy(data, 0, dest, 2048); Marshal.Copy(data, 0, dest, 2048);
_drivelight = true; _drivelight = true;
} }
} }
}
LibGPGX.cd_read_cb cd_callback_handle; LibGPGX.cd_read_cb cd_callback_handle;
public static unsafe byte[] GetCDData(Disc cd) public static LibGPGX.CDData GetCDDataStruct(Disc cd)
{ {
LibGPGX.CDData ret = new LibGPGX.CDData(); var ret = new LibGPGX.CDData();
int size = Marshal.SizeOf(ret);
var ses = cd.Session1; var ses = cd.Session1;
int ntrack = ses.InformationTrackCount; int ntrack = ses.InformationTrackCount;
@ -338,6 +345,13 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
} }
} }
return ret;
}
public static unsafe byte[] GetCDData(Disc cd)
{
var ret = GetCDDataStruct(cd);
int size = Marshal.SizeOf(ret);
byte[] retdata = new byte[size]; byte[] retdata = new byte[size];
fixed (byte* p = &retdata[0]) fixed (byte* p = &retdata[0])
@ -360,7 +374,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
if (!Core.gpgx_get_control(input, inputsize)) if (!Core.gpgx_get_control(input, inputsize))
throw new Exception("gpgx_get_control() failed"); throw new Exception("gpgx_get_control() failed");
ControlConverter = new GPGXControlConverter(input); ControlConverter = new GPGXControlConverter(input, _cds != null);
ControllerDefinition = ControlConverter.ControllerDef; ControllerDefinition = ControlConverter.ControllerDef;
} }
@ -369,7 +383,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
return (LibGPGX.INPUT_DEVICE[])input.dev.Clone(); return (LibGPGX.INPUT_DEVICE[])input.dev.Clone();
} }
public bool IsMegaCD { get { return CD != null; } } public bool IsMegaCD { get { return _cds != null; } }
public class VDPView : IMonitor public class VDPView : IMonitor
{ {

View File

@ -175,7 +175,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
}); });
} }
public GPGXControlConverter(LibGPGX.InputData input) public GPGXControlConverter(LibGPGX.InputData input, bool cdButtons)
{ {
Console.WriteLine("Genesis Controller report:"); Console.WriteLine("Genesis Controller report:");
foreach (var e in input.system) foreach (var e in input.system)
@ -189,6 +189,11 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
ControllerDef.BoolButtons.Add("Power"); ControllerDef.BoolButtons.Add("Power");
ControllerDef.BoolButtons.Add("Reset"); ControllerDef.BoolButtons.Add("Reset");
if (cdButtons)
{
ControllerDef.BoolButtons.Add("Previous Disk");
ControllerDef.BoolButtons.Add("Next Disk");
}
for (int i = 0; i < LibGPGX.MAX_DEVICES; i++) for (int i = 0; i < LibGPGX.MAX_DEVICES; i++)
{ {

View File

@ -49,7 +49,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
public uint BackdropColor; public uint BackdropColor;
} }
[BizImport(CallingConvention.Cdecl, Compatibility=true)] [BizImport(CallingConvention.Cdecl, Compatibility = true)]
public abstract bool gpgx_init(string feromextension, load_archive_cb feload_archive_cb, bool sixbutton, INPUT_SYSTEM system_a, INPUT_SYSTEM system_b, Region region, [In]InitSettings settings); public abstract bool gpgx_init(string feromextension, load_archive_cb feload_archive_cb, bool sixbutton, INPUT_SYSTEM system_a, INPUT_SYSTEM system_b, Region region, [In]InitSettings settings);
[BizImport(CallingConvention.Cdecl)] [BizImport(CallingConvention.Cdecl)]
@ -151,8 +151,6 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
[BizImport(CallingConvention.Cdecl)] [BizImport(CallingConvention.Cdecl)]
public abstract void gpgx_set_cd_callback(CDCallback cd); public abstract void gpgx_set_cd_callback(CDCallback cd);
/// <summary> /// <summary>
/// not every flag is valid for every device! /// not every flag is valid for every device!
/// </summary> /// </summary>
@ -277,6 +275,9 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
[BizImport(CallingConvention.Cdecl)] [BizImport(CallingConvention.Cdecl)]
public abstract void gpgx_set_cdd_callback(cd_read_cb cddcb); public abstract void gpgx_set_cdd_callback(cd_read_cb cddcb);
[BizImport(CallingConvention.Cdecl, Compatibility = true)]
public abstract void gpgx_swap_disc(CDData toc);
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public struct VDPNameTable public struct VDPNameTable
{ {

Binary file not shown.

View File

@ -192,6 +192,14 @@ GPGX_EX void gpgx_advance(void)
nsamples = audio_update(soundbuffer); nsamples = audio_update(soundbuffer);
} }
GPGX_EX void gpgx_swap_disc(const toc_t* toc)
{
if (system_hw == SYSTEM_MCD)
{
cdd_hotswap(toc);
}
}
typedef struct typedef struct
{ {
uint32 width; // in cells uint32 width; // in cells

View File

@ -203,6 +203,21 @@ void cdd_unload(void)
memset(&cdd.toc, 0x00, sizeof(cdd.toc)); memset(&cdd.toc, 0x00, sizeof(cdd.toc));
} }
void cdd_hotswap(const toc_t *toc)
{
if (toc)
{
cdd.loaded = 1;
memcpy(&cdd.toc, &toc, sizeof(cdd.toc));
}
else
{
cdd.loaded = 0;
memset(&cdd.toc, 0x00, sizeof(cdd.toc));
}
cdd_reset();
}
void cdd_read_data(uint8 *dst) void cdd_read_data(uint8 *dst)
{ {
/* only read DATA track sectors */ /* only read DATA track sectors */
@ -348,7 +363,7 @@ void cdd_read_audio(unsigned int samples)
void cdd_update(void) void cdd_update(void)
{ {
#ifdef LOG_CDD #ifdef LOG_CDD
error("LBA = %d (track n°%d)(latency=%d)\n", cdd.lba, cdd.index, cdd.latency); error("LBA = %d (track n<EFBFBD>%d)(latency=%d)\n", cdd.lba, cdd.index, cdd.latency);
#endif #endif
/* seeking disc */ /* seeking disc */

View File

@ -103,4 +103,8 @@ extern void cdd_read_audio(unsigned int samples);
extern void cdd_update(void); extern void cdd_update(void);
extern void cdd_process(void); extern void cdd_process(void);
// switch disks after emulation was started
// pass NULL to open tray
void cdd_hotswap(const toc_t *toc);
#endif #endif