diff --git a/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGX.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGX.IStatable.cs index 7fd5b5e8a3..954098b2d7 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGX.IStatable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGX.IStatable.cs @@ -37,10 +37,9 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx LagCount = reader.ReadInt32(); IsLagFrame = reader.ReadBoolean(); // any managed pointers that we sent to the core need to be resent now! - // TODO: sega cd won't work until we fix that! Core.gpgx_set_input_callback(InputCallback); RefreshMemCallbacks(); - + Core.gpgx_set_cdd_callback(cd_callback_handle); UpdateVideo(); } diff --git a/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGX.cs b/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGX.cs index 211dff652c..0aba6bdd9e 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGX.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGX.cs @@ -68,7 +68,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx try { - Elf = new ElfRunner(Path.Combine(comm.CoreFileProvider.DllPath(), "gpgx.elf"), 65536, 36 * 1024 * 1024, 4 * 1024 * 1024); + Elf = new ElfRunner(Path.Combine(comm.CoreFileProvider.DllPath(), "gpgx.elf"), 256 * 1024, 36 * 1024 * 1024, 4 * 1024 * 1024); Core = BizInvoker.GetInvoker(Elf); @@ -81,7 +81,12 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx this.romfile = rom; this.CD = CD; - this.DiscSectorReader = new DiscSystem.DiscSectorReader(CD); + if (CD != null) + { + this.DiscSectorReader = new DiscSystem.DiscSectorReader(CD); + cd_callback_handle = new LibGPGX.cd_read_cb(CDRead); + Core.gpgx_set_cdd_callback(cd_callback_handle); + } LibGPGX.INPUT_SYSTEM system_a = LibGPGX.INPUT_SYSTEM.SYSTEM_NONE; LibGPGX.INPUT_SYSTEM system_b = LibGPGX.INPUT_SYSTEM.SYSTEM_NONE; @@ -304,8 +309,6 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx LibGPGX.CDData ret = new LibGPGX.CDData(); int size = Marshal.SizeOf(ret); - ret.readcallback = cd_callback_handle = new LibGPGX.cd_read_cb(CDRead); - var ses = CD.Session1; int ntrack = ses.InformationTrackCount; diff --git a/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/LibGPGX.cs b/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/LibGPGX.cs index 6328c1d29d..4b6852566f 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/LibGPGX.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/LibGPGX.cs @@ -274,9 +274,11 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx public int last; [MarshalAs(UnmanagedType.ByValArray, SizeConst = CD_MAX_TRACKS)] public readonly CDTrack[] tracks = new CDTrack[CD_MAX_TRACKS]; - public cd_read_cb readcallback; } + [BizImport(CallingConvention.Cdecl)] + public abstract void gpgx_set_cdd_callback(cd_read_cb cddcb); + [StructLayout(LayoutKind.Sequential)] public struct VDPNameTable { diff --git a/waterbox/gpgx/cinterface/callbacks.h b/waterbox/gpgx/cinterface/callbacks.h index 2b3b42abdf..b2b37edd34 100644 --- a/waterbox/gpgx/cinterface/callbacks.h +++ b/waterbox/gpgx/cinterface/callbacks.h @@ -13,6 +13,8 @@ extern ECL_ENTRY void (*biz_writecb)(unsigned addr); extern CDCallback biz_cdcallback; extern unsigned biz_lastpc; +extern ECL_ENTRY void (*cdd_readcallback)(int lba, void *dest, int audio); + enum eCDLog_AddrType { eCDLog_AddrType_MDCART, eCDLog_AddrType_RAM68k, eCDLog_AddrType_RAMZ80, eCDLog_AddrType_SRAM, diff --git a/waterbox/gpgx/cinterface/cinterface.c b/waterbox/gpgx/cinterface/cinterface.c index ff3ffb92bf..c931efc2c6 100644 --- a/waterbox/gpgx/cinterface/cinterface.c +++ b/waterbox/gpgx/cinterface/cinterface.c @@ -57,12 +57,12 @@ static uint8_t brm_format[0x40] = 0x52,0x41,0x4d,0x5f,0x43,0x41,0x52,0x54,0x52,0x49,0x44,0x47,0x45,0x5f,0x5f,0x5f }; -ECL_ENTRY void (*biz_execcb)(unsigned addr) = NULL; -ECL_ENTRY void (*biz_readcb)(unsigned addr) = NULL; -ECL_ENTRY void (*biz_writecb)(unsigned addr) = NULL; +ECL_ENTRY void (*biz_execcb)(unsigned addr); +ECL_ENTRY void (*biz_readcb)(unsigned addr); +ECL_ENTRY void (*biz_writecb)(unsigned addr); CDCallback biz_cdcallback = NULL; unsigned biz_lastpc = 0; - +ECL_ENTRY void (*cdd_readcallback)(int lba, void *dest, int audio); uint8 *tempsram; static void update_viewport(void) @@ -123,44 +123,6 @@ GPGX_EX void gpgx_get_fps(int *num, int *den) } } -GPGX_EX int gpgx_state_max_size(void) -{ - // original state size, plus 64K sram or 16K ebram, plus 8K ibram or seeprom control structures - return STATE_SIZE + (64 + 8) * 1024; -} - -GPGX_EX int gpgx_state_size(void *dest, int size) -{ - int actual = 0; - if (size < gpgx_state_max_size()) - return -1; - - actual = state_save((unsigned char*) dest); - if (actual > size) - // fixme! - return -1; - return actual; -} - -GPGX_EX int gpgx_state_save(void *dest, int size) -{ - return state_save((unsigned char*) dest) == size; -} - -GPGX_EX int gpgx_state_load(void *src, int size) -{ - if (!size) - return 0; - - if (state_load((unsigned char *) src) == size) - { - update_viewport(); - return 1; - } - else - return 0; -} - void osd_input_update(void) { } @@ -178,6 +140,11 @@ GPGX_EX void gpgx_set_input_callback(ECL_ENTRY void (*fecb)(void)) input_callback_cb = fecb; } +GPGX_EX void gpgx_set_cdd_callback(ECL_ENTRY void (*cddcb)(int lba, void *dest, int audio)) +{ + cdd_readcallback = cddcb; +} + ECL_ENTRY int (*load_archive_cb)(const char *filename, unsigned char *buffer, int maxsize); // return 0 on failure, else actual loaded size diff --git a/waterbox/gpgx/core/cd_hw/cdd.c b/waterbox/gpgx/core/cd_hw/cdd.c index e2a57fb7bb..ae9f6274e1 100644 --- a/waterbox/gpgx/core/cd_hw/cdd.c +++ b/waterbox/gpgx/core/cd_hw/cdd.c @@ -36,34 +36,35 @@ * ****************************************************************************************/ #include "shared.h" +#include "../cinterface/callbacks.h" /* BCD conversion lookup tables */ static const uint8 lut_BCD_8[100] = { - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, - 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, - 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, - 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, + 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, + 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, }; static const uint16 lut_BCD_16[100] = { - 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, - 0x0100, 0x0101, 0x0102, 0x0103, 0x0104, 0x0105, 0x0106, 0x0107, 0x0108, 0x0109, - 0x0200, 0x0201, 0x0202, 0x0203, 0x0204, 0x0205, 0x0206, 0x0207, 0x0208, 0x0209, - 0x0300, 0x0301, 0x0302, 0x0303, 0x0304, 0x0305, 0x0306, 0x0307, 0x0308, 0x0309, - 0x0400, 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x0406, 0x0407, 0x0408, 0x0409, - 0x0500, 0x0501, 0x0502, 0x0503, 0x0504, 0x0505, 0x0506, 0x0507, 0x0508, 0x0509, - 0x0600, 0x0601, 0x0602, 0x0603, 0x0604, 0x0605, 0x0606, 0x0607, 0x0608, 0x0609, - 0x0700, 0x0701, 0x0702, 0x0703, 0x0704, 0x0705, 0x0706, 0x0707, 0x0708, 0x0709, - 0x0800, 0x0801, 0x0802, 0x0803, 0x0804, 0x0805, 0x0806, 0x0807, 0x0808, 0x0809, - 0x0900, 0x0901, 0x0902, 0x0903, 0x0904, 0x0905, 0x0906, 0x0907, 0x0908, 0x0909, + 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, + 0x0100, 0x0101, 0x0102, 0x0103, 0x0104, 0x0105, 0x0106, 0x0107, 0x0108, 0x0109, + 0x0200, 0x0201, 0x0202, 0x0203, 0x0204, 0x0205, 0x0206, 0x0207, 0x0208, 0x0209, + 0x0300, 0x0301, 0x0302, 0x0303, 0x0304, 0x0305, 0x0306, 0x0307, 0x0308, 0x0309, + 0x0400, 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x0406, 0x0407, 0x0408, 0x0409, + 0x0500, 0x0501, 0x0502, 0x0503, 0x0504, 0x0505, 0x0506, 0x0507, 0x0508, 0x0509, + 0x0600, 0x0601, 0x0602, 0x0603, 0x0604, 0x0605, 0x0606, 0x0607, 0x0608, 0x0609, + 0x0700, 0x0701, 0x0702, 0x0703, 0x0704, 0x0705, 0x0706, 0x0707, 0x0708, 0x0709, + 0x0800, 0x0801, 0x0802, 0x0803, 0x0804, 0x0805, 0x0806, 0x0807, 0x0808, 0x0809, + 0x0900, 0x0901, 0x0902, 0x0903, 0x0904, 0x0905, 0x0906, 0x0907, 0x0908, 0x0909, }; /* pre-build TOC */ @@ -119,13 +120,9 @@ static const unsigned char waveHeader[32] = static blip_t* blip[2]; -// FRONTEND INTERFACE -void (*cdd_readcallback)(int lba, void *dest, int audio); - typedef struct { toc_t toc; - void (*cdd_readcallback)(int lba, void *dest, int audio); } frontendcd_t; int cdd_load(const char *key, char *header) @@ -140,7 +137,7 @@ int cdd_load(const char *key, char *header) return 0; // look for valid header - fecd.cdd_readcallback(0, data, 0); + cdd_readcallback(0, data, 0); if (memcmp("SEGADISCSYSTEM", data, 14) == 0) startoffs = 0; else if (memcmp("SEGADISCSYSTEM", data + 16, 14) == 0) @@ -151,9 +148,8 @@ int cdd_load(const char *key, char *header) memcpy(header, data + startoffs, 0x210); // copy disk information - cdd_readcallback = fecd.cdd_readcallback; memcpy(&cdd.toc, &fecd.toc, sizeof(toc_t)); - + cdd.loaded = 1; return 1; } @@ -172,13 +168,13 @@ void cdd_reset(void) { /* reset cycle counter */ cdd.cycles = 0; - + /* reset drive access latency */ cdd.latency = 0; - + /* reset track index */ cdd.index = 0; - + /* reset logical block address */ cdd.lba = 0; @@ -190,7 +186,7 @@ void cdd_reset(void) /* reset status */ cdd.status = cdd.loaded ? CD_STOP : NO_DISC; - + /* reset CD-DA fader (full volume) */ cdd.volume = 0x400; @@ -385,11 +381,11 @@ void cdd_read_audio(unsigned int samples) void cdd_update(void) -{ +{ #ifdef LOG_CDD error("LBA = %d (track n°%d)(latency=%d)\n", cdd.lba, cdd.index, cdd.latency); #endif - + /* seeking disc */ if (cdd.status == CD_SEEK) { @@ -445,7 +441,7 @@ void cdd_update(void) /* audio blocks are still sent to CDC as well as CD DAC/Fader */ cdc_decoder_update(0); - + /* next audio block is automatically read */ cdd.lba++; } @@ -482,7 +478,7 @@ void cdd_update(void) /* skip directly to track start position */ cdd.lba = cdd.toc.tracks[cdd.index].start; - + /* AUDIO track playing ? */ if (cdd.status == CD_PLAY) { @@ -655,7 +651,7 @@ void cdd_process(void) int index = 0; /* new LBA position */ - int lba = ((scd.regs[0x44>>1].byte.h * 10 + scd.regs[0x44>>1].byte.l) * 60 + + int lba = ((scd.regs[0x44>>1].byte.h * 10 + scd.regs[0x44>>1].byte.l) * 60 + (scd.regs[0x46>>1].byte.h * 10 + scd.regs[0x46>>1].byte.l)) * 75 + (scd.regs[0x48>>1].byte.h * 10 + scd.regs[0x48>>1].byte.l) - 150; @@ -679,7 +675,7 @@ void cdd_process(void) { cdd.latency += (((lba - cdd.lba) * 120) / 270000); } - else + else { cdd.latency += (((cdd.lba - lba) * 120) / 270000); } @@ -714,7 +710,7 @@ void cdd_process(void) int index = 0; /* new LBA position */ - int lba = ((scd.regs[0x44>>1].byte.h * 10 + scd.regs[0x44>>1].byte.l) * 60 + + int lba = ((scd.regs[0x44>>1].byte.h * 10 + scd.regs[0x44>>1].byte.l) * 60 + (scd.regs[0x46>>1].byte.h * 10 + scd.regs[0x46>>1].byte.l)) * 75 + (scd.regs[0x48>>1].byte.h * 10 + scd.regs[0x48>>1].byte.l) - 150;