- Nik's new decoupled audio code with fixes to minimize overruns.

- VBlank timing: increased to 20% of a frame.
This commit is contained in:
Bart Trzynadlowski 2011-09-12 05:43:37 +00:00
parent 4c18925679
commit cf73207c98
9 changed files with 1322 additions and 983 deletions

View file

@ -509,6 +509,10 @@ void CDSB1::SaveState(CBlockFile *StateFile)
// Z80 CPU state // Z80 CPU state
Z80.SaveState(StateFile, "DSB1 Z80"); Z80.SaveState(StateFile, "DSB1 Z80");
//DEBUG
//printf("usingMPEGStart=%X usingMPEGEnd=%X\n", usingMPEGStart, usingMPEGEnd);
//printf("usingLoopStart=%X usingLoopEnd=%X\n", usingLoopStart, usingLoopEnd);
} }
void CDSB1::LoadState(CBlockFile *StateFile) void CDSB1::LoadState(CBlockFile *StateFile)
@ -554,6 +558,10 @@ void CDSB1::LoadState(CBlockFile *StateFile)
} }
else else
MPEG_StopPlaying(); MPEG_StopPlaying();
//DEBUG
//printf("usingMPEGStart=%X usingMPEGEnd=%X\n", usingMPEGStart, usingMPEGEnd);
//printf("usingLoopStart=%X usingLoopEnd=%X\n", usingLoopStart, usingLoopEnd);
} }
// Offsets of memory regions within DSB1's pool // Offsets of memory regions within DSB1's pool
@ -1065,6 +1073,11 @@ void CDSB2::SaveState(CBlockFile *StateFile)
// 68K CPU state // 68K CPU state
M68KSetContext(&M68K); M68KSetContext(&M68K);
M68KSaveState(StateFile, "DSB2 68K"); M68KSaveState(StateFile, "DSB2 68K");
//DEBUG
//printf("mpegStart=%X, mpegEnd=%X\n", mpegStart, mpegEnd);
//printf("usingMPEGStart=%X, usingMPEGEnd=%X\n", usingMPEGStart, usingMPEGEnd);
//printf("usingLoopStart=%X, usingLoopEnd=%X\n", usingLoopStart, usingLoopEnd);
} }
void CDSB2::LoadState(CBlockFile *StateFile) void CDSB2::LoadState(CBlockFile *StateFile)

File diff suppressed because it is too large Load diff

View file

@ -1,386 +1,400 @@
/** /**
** Supermodel ** Supermodel
** A Sega Model 3 Arcade Emulator. ** A Sega Model 3 Arcade Emulator.
** Copyright 2011 Bart Trzynadlowski ** Copyright 2011 Bart Trzynadlowski
** **
** This file is part of Supermodel. ** This file is part of Supermodel.
** **
** Supermodel is free software: you can redistribute it and/or modify it under ** Supermodel is free software: you can redistribute it and/or modify it under
** the terms of the GNU General Public License as published by the Free ** the terms of the GNU General Public License as published by the Free
** Software Foundation, either version 3 of the License, or (at your option) ** Software Foundation, either version 3 of the License, or (at your option)
** any later version. ** any later version.
** **
** Supermodel is distributed in the hope that it will be useful, but WITHOUT ** Supermodel is distributed in the hope that it will be useful, but WITHOUT
** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
** more details. ** more details.
** **
** You should have received a copy of the GNU General Public License along ** You should have received a copy of the GNU General Public License along
** with Supermodel. If not, see <http://www.gnu.org/licenses/>. ** with Supermodel. If not, see <http://www.gnu.org/licenses/>.
**/ **/
/* /*
* Model3.h * Model3.h
* *
* Header file defining the CModel3, CModel3Config, and CModel3Inputs classes. * Header file defining the CModel3, CModel3Config, and CModel3Inputs classes.
*/ */
#ifndef INCLUDED_MODEL3_H #ifndef INCLUDED_MODEL3_H
#define INCLUDED_MODEL3_H #define INCLUDED_MODEL3_H
/* /*
* CModel3Config: * CModel3Config:
* *
* Settings used by CModel3. * Settings used by CModel3.
*/ */
class CModel3Config class CModel3Config
{ {
public: public:
bool multiThreaded; // Multi-threading (enabled if true) bool multiThreaded; // Multi-threading (enabled if true)
// PowerPC clock frequency in MHz (minimum: 1 MHz) // PowerPC clock frequency in MHz (minimum: 1 MHz)
inline void SetPowerPCFrequency(unsigned f) inline void SetPowerPCFrequency(unsigned f)
{ {
if ((f<1) || (f>1000)) if ((f<1) || (f>1000))
{ {
ErrorLog("PowerPC frequency must be between 1 and 1000 MHz; setting to 40 MHz."); ErrorLog("PowerPC frequency must be between 1 and 1000 MHz; setting to 40 MHz.");
f = 40; f = 40;
} }
ppcFrequency = f*1000000; ppcFrequency = f*1000000;
} }
inline unsigned GetPowerPCFrequency(void) inline unsigned GetPowerPCFrequency(void)
{ {
return ppcFrequency/1000000; return ppcFrequency/1000000;
} }
// Defaults // Defaults
CModel3Config(void) CModel3Config(void)
{ {
multiThreaded = false; // disable by default multiThreaded = false; // disable by default
ppcFrequency = 40*1000000; // 40 MHz ppcFrequency = 40*1000000; // 40 MHz
} }
private: private:
unsigned ppcFrequency; // in Hz unsigned ppcFrequency; // in Hz
}; };
/* /*
* CModel3: * CModel3:
* *
* A complete Model 3 system. * A complete Model 3 system.
* *
* Inherits CBus in order to pass the address space handlers to devices that * Inherits CBus in order to pass the address space handlers to devices that
* may need them (CPU, DMA, etc.) * may need them (CPU, DMA, etc.)
* *
* NOTE: Currently NOT re-entrant due to a non-OOP PowerPC core. Do NOT create * NOTE: Currently NOT re-entrant due to a non-OOP PowerPC core. Do NOT create
* create more than one CModel3 object! * create more than one CModel3 object!
*/ */
class CModel3: public CBus, public CPCIDevice class CModel3: public CBus, public CPCIDevice
{ {
public: public:
/* /*
* ReadPCIConfigSpace(device, reg, bits, offset): * ReadPCIConfigSpace(device, reg, bits, offset):
* *
* Handles unknown PCI devices. See CPCIDevice definition for more details. * Handles unknown PCI devices. See CPCIDevice definition for more details.
* *
* Parameters: * Parameters:
* device Device number. * device Device number.
* reg Register number. * reg Register number.
* bits Bit width of access (8, 16, or 32 only).; * bits Bit width of access (8, 16, or 32 only).;
* offset Byte offset within register, aligned to the specified bit * offset Byte offset within register, aligned to the specified bit
* width, and offset from the 32-bit aligned base of the * width, and offset from the 32-bit aligned base of the
* register number. * register number.
* *
* Returns: * Returns:
* Register data. * Register data.
*/ */
UINT32 ReadPCIConfigSpace(unsigned device, unsigned reg, unsigned bits, unsigned width); UINT32 ReadPCIConfigSpace(unsigned device, unsigned reg, unsigned bits, unsigned width);
/* /*
* WritePCIConfigSpace(device, reg, bits, offset, data): * WritePCIConfigSpace(device, reg, bits, offset, data):
* *
* Handles unknown PCI devices. See CPCIDevice definition for more details. * Handles unknown PCI devices. See CPCIDevice definition for more details.
* *
* Parameters: * Parameters:
* device Device number. * device Device number.
* reg Register number. * reg Register number.
* bits Bit width of access (8, 16, or 32 only). * bits Bit width of access (8, 16, or 32 only).
* offset Byte offset within register, aligned to the specified bit * offset Byte offset within register, aligned to the specified bit
* width, and offset from the 32-bit aligned base of the * width, and offset from the 32-bit aligned base of the
* register number. * register number.
* data Data. * data Data.
*/ */
void WritePCIConfigSpace(unsigned device, unsigned reg, unsigned bits, unsigned width, UINT32 data); void WritePCIConfigSpace(unsigned device, unsigned reg, unsigned bits, unsigned width, UINT32 data);
/* /*
* Read8(addr): * Read8(addr):
* Read16(addr): * Read16(addr):
* Read32(addr): * Read32(addr):
* Read64(addr): * Read64(addr):
* *
* Read a byte, 16-bit half word, 32-bit word, or 64-bit double word from * Read a byte, 16-bit half word, 32-bit word, or 64-bit double word from
* the PowerPC address space. This implements the PowerPC address bus. Note * the PowerPC address space. This implements the PowerPC address bus. Note
* that it is big endian, so when accessing from a little endian device, * that it is big endian, so when accessing from a little endian device,
* the byte order must be manually reversed. * the byte order must be manually reversed.
* *
* Parameters: * Parameters:
* addr Address to read. * addr Address to read.
* *
* Returns: * Returns:
* Data at the address. * Data at the address.
*/ */
UINT8 Read8(UINT32 addr); UINT8 Read8(UINT32 addr);
UINT16 Read16(UINT32 addr); UINT16 Read16(UINT32 addr);
UINT32 Read32(UINT32 addr); UINT32 Read32(UINT32 addr);
UINT64 Read64(UINT32 addr); UINT64 Read64(UINT32 addr);
/* /*
* Write8(addr, data): * Write8(addr, data):
* Write16(addr, data): * Write16(addr, data):
* Write32(addr, data): * Write32(addr, data):
* Write64(addr, data): * Write64(addr, data):
* *
* Write a byte, half word, word, or double word to the PowerPC address * Write a byte, half word, word, or double word to the PowerPC address
* space. Note that everything is stored in big endian form, so when * space. Note that everything is stored in big endian form, so when
* accessing with a little endian device, the byte order must be manually * accessing with a little endian device, the byte order must be manually
* reversed. * reversed.
* *
* Parameters: * Parameters:
* addr Address to write. * addr Address to write.
* data Data to write. * data Data to write.
*/ */
void Write8(UINT32 addr, UINT8 data); void Write8(UINT32 addr, UINT8 data);
void Write16(UINT32 addr, UINT16 data); void Write16(UINT32 addr, UINT16 data);
void Write32(UINT32 addr, UINT32 data); void Write32(UINT32 addr, UINT32 data);
void Write64(UINT32 addr, UINT64 data); void Write64(UINT32 addr, UINT64 data);
/* /*
* SaveState(SaveState): * SaveState(SaveState):
* *
* Saves an image of the current state. Must never be called while emulator * Saves an image of the current state. Must never be called while emulator
* is running (inside RunFrame()). * is running (inside RunFrame()).
* *
* Parameters: * Parameters:
* SaveState Block file to save state information to. * SaveState Block file to save state information to.
*/ */
void SaveState(CBlockFile *SaveState); void SaveState(CBlockFile *SaveState);
/* /*
* LoadState(SaveState): * LoadState(SaveState):
* *
* Loads and resumes execution from a state image. Modifies data that may * Loads and resumes execution from a state image. Modifies data that may
* be used by multiple threads -- use with caution and ensure threads are * be used by multiple threads -- use with caution and ensure threads are
* not accessing data that will be touched. Must never be called while * not accessing data that will be touched. Must never be called while
* emulator is running (inside RunFrame()). * emulator is running (inside RunFrame()).
* *
* Parameters: * Parameters:
* SaveState Block file to load state information from. * SaveState Block file to load state information from.
*/ */
void LoadState(CBlockFile *SaveState); void LoadState(CBlockFile *SaveState);
/* /*
* SaveNVRAM(NVRAM): * SaveNVRAM(NVRAM):
* *
* Saves an image of the current NVRAM state. * Saves an image of the current NVRAM state.
* *
* Parameters: * Parameters:
* NVRAM Block file to save NVRAM to. * NVRAM Block file to save NVRAM to.
*/ */
void SaveNVRAM(CBlockFile *NVRAM); void SaveNVRAM(CBlockFile *NVRAM);
/* /*
* LoadNVRAM(NVRAM): * LoadNVRAM(NVRAM):
* *
* Loads an NVRAM image. * Loads an NVRAM image.
* *
* Parameters: * Parameters:
* NVRAM Block file to load NVRAM state from. * NVRAM Block file to load NVRAM state from.
*/ */
void LoadNVRAM(CBlockFile *NVRAM); void LoadNVRAM(CBlockFile *NVRAM);
/* /*
* ClearNVRAM(void): * ClearNVRAM(void):
* *
* Clears all NVRAM (backup RAM and EEPROM). * Clears all NVRAM (backup RAM and EEPROM).
*/ */
void ClearNVRAM(void); void ClearNVRAM(void);
/* /*
* RunFrame(void): * RunFrame(void):
* *
* Runs one frame (assuming 60 Hz video refresh rate). * Runs one frame (assuming 60 Hz video refresh rate).
*/ */
void RunFrame(void); void RunFrame(void);
/* /*
* Reset(void): * Reset(void):
* *
* Resets the system. Does not modify non-volatile memory. * Resets the system. Does not modify non-volatile memory.
*/ */
void Reset(void); void Reset(void);
/* /*
* GetGameInfo(void): * GetGameInfo(void):
* *
* Returns: * Returns:
* A pointer to the presently loaded game's information structure (or * A pointer to the presently loaded game's information structure (or
* NULL if no ROM set has yet been loaded). * NULL if no ROM set has yet been loaded).
*/ */
const struct GameInfo * GetGameInfo(void); const struct GameInfo * GetGameInfo(void);
/* /*
* LoadROMSet(GameList, zipFile): * LoadROMSet(GameList, zipFile):
* *
* Loads a complete ROM set from the specified ZIP archive. * Loads a complete ROM set from the specified ZIP archive.
* *
* NOTE: Command line settings will not have been applied here yet. * NOTE: Command line settings will not have been applied here yet.
* *
* Parameters: * Parameters:
* GameList List of all supported games and their ROMs. * GameList List of all supported games and their ROMs.
* zipFile ZIP file to load from. * zipFile ZIP file to load from.
* *
* Returns: * Returns:
* OKAY if successful, FAIL otherwise. Prints errors. * OKAY if successful, FAIL otherwise. Prints errors.
*/ */
bool LoadROMSet(const struct GameInfo *GameList, const char *zipFile); bool LoadROMSet(const struct GameInfo *GameList, const char *zipFile);
/* /*
* AttachRenderers(Render2DPtr, Render3DPtr): * AttachRenderers(Render2DPtr, Render3DPtr):
* *
* Attaches the renderers to the appropriate device objects. * Attaches the renderers to the appropriate device objects.
* *
* Parameters: * Parameters:
* Render2DPtr Pointer to a tile renderer object. * Render2DPtr Pointer to a tile renderer object.
* Render3DPtr Same as above but for a 3D renderer. * Render3DPtr Same as above but for a 3D renderer.
*/ */
void AttachRenderers(CRender2D *Render2DPtr, CRender3D *Render3DPtr); void AttachRenderers(CRender2D *Render2DPtr, CRender3D *Render3DPtr);
/* /*
* AttachInputs(InputsPtr): * AttachInputs(InputsPtr):
* *
* Attaches OSD-managed inputs. * Attaches OSD-managed inputs.
* *
* Parameters: * Parameters:
* InputsPtr Pointer to the object containing input states. * InputsPtr Pointer to the object containing input states.
*/ */
void AttachInputs(CInputs *InputsPtr); void AttachInputs(CInputs *InputsPtr);
/* /*
* Init(void): * Init(void):
* *
* One-time initialization of the context. Must be called prior to all * One-time initialization of the context. Must be called prior to all
* other members. Allocates memory and initializes device states. * other members. Allocates memory and initializes device states.
* *
* NOTE: Command line settings will not have been applied here yet. * NOTE: Command line settings will not have been applied here yet.
* *
* Returns: * Returns:
* OKAY is successful, otherwise FAILED if a non-recoverable error * OKAY is successful, otherwise FAILED if a non-recoverable error
* occurred. Prints own error messages. * occurred. Prints own error messages.
*/ */
bool Init(void); bool Init(void);
/* /*
* CModel3(void): * CModel3(void):
* ~CModel3(void): * ~CModel3(void):
* *
* Constructor and destructor for Model 3 class. Constructor performs a * Constructor and destructor for Model 3 class. Constructor performs a
* bare-bones initialization of object; does not perform any memory * bare-bones initialization of object; does not perform any memory
* allocation or any actions that can fail. The destructor will deallocate * allocation or any actions that can fail. The destructor will deallocate
* memory and free resources used by the object (and its child objects). * memory and free resources used by the object (and its child objects).
*/ */
CModel3(void); CModel3(void);
~CModel3(void); ~CModel3(void);
/* bool PauseThreads(void);
* Private Property. void ResumeThreads(void);
* Tresspassers will be shot! ;)
*/ /*
private: * Private Property.
// Private member functions * Tresspassers will be shot! ;)
UINT8 ReadInputs(unsigned reg); */
void WriteInputs(unsigned reg, UINT8 data); private:
UINT32 ReadSecurity(unsigned reg); // Private member functions
void WriteSecurity(unsigned reg, UINT32 data); UINT8 ReadInputs(unsigned reg);
void SetCROMBank(unsigned idx); void WriteInputs(unsigned reg, UINT8 data);
UINT8 ReadSystemRegister(unsigned reg); UINT32 ReadSecurity(unsigned reg);
void WriteSystemRegister(unsigned reg, UINT8 data); void WriteSecurity(unsigned reg, UINT32 data);
void Patch(void); void SetCROMBank(unsigned idx);
UINT8 ReadSystemRegister(unsigned reg);
void RunMainBoardFrame(); // Runs the main board (PPC) for a frame void WriteSystemRegister(unsigned reg, UINT8 data);
bool StartThreads(); // Starts all threads void Patch(void);
void StopThreads(); // Stops all threads
void DeleteThreadObjects(); // Deletes all threads and synchronization objects void RunMainBoardFrame(void); // Runs the main board (PPC) for a frame
bool StartThreads(void); // Starts all threads
static int StartSoundBoardThread(void *data); // Callback to start sound board thread void StopThreads(void); // Stops all threads
static int StartDriveBoardThread(void *data); // Callback to start drive board thread void DeleteThreadObjects(void); // Deletes all threads and synchronization objects
void RunSoundBoardThread(); // Runs sound board thread static int StartSoundBoardThread(void *data); // Callback to start unsync'd sound board thread
void RunDriveBoardThread(); // Runs drive board thread static int StartSoundBoardThreadSyncd(void *data); // Callback to start sync'd sound board thread
static int StartDriveBoardThreadSyncd(void *data); // Callback to start sync'd drive board thread
// Game and hardware information
const struct GameInfo *Game; static void AudioCallback(void *data); // Audio buffer callback
// Game inputs void WakeSoundBoardThread(void); // Used by audio callback to wake sound board thread when not sync'd with PPC thread
CInputs *Inputs; void RunSoundBoardThread(void); // Runs sound board thread unsync'd with PPC thread, ie at full speed
void RunSoundBoardThreadSyncd(void); // Runs sound board thread sync'd in step with PPC thread
// Input registers (game controls) void RunDriveBoardThreadSyncd(void); // Runs drive board thread sync'd in step with PPC thread
UINT8 inputBank;
UINT8 serialFIFO1, serialFIFO2; // Game and hardware information
UINT8 gunReg; const struct GameInfo *Game;
int adcChannel;
// Game inputs
// MIDI port CInputs *Inputs;
UINT8 midiCtrlPort; // controls MIDI (SCSP) IRQ behavior
// Input registers (game controls)
// Emulated core Model 3 memory regions UINT8 inputBank;
UINT8 *memoryPool; // single allocated region for all ROM and system RAM UINT8 serialFIFO1, serialFIFO2;
UINT8 *ram; // 8 MB PowerPC RAM UINT8 gunReg;
UINT8 *crom; // 8+128 MB CROM (fixed CROM first, then 64MB of banked CROMs -- Daytona2 might need extra?) int adcChannel;
UINT8 *vrom; // 64 MB VROM (video ROM, visible only to Real3D)
UINT8 *soundROM; // 512 KB sound ROM (68K program) // MIDI port
UINT8 *sampleROM; // 8 MB samples (68K) UINT8 midiCtrlPort; // controls MIDI (SCSP) IRQ behavior
UINT8 *dsbROM; // 128 KB DSB ROM (Z80 program)
UINT8 *mpegROM; // 8 MB DSB MPEG ROM // Emulated core Model 3 memory regions
UINT8 *backupRAM; // 128 KB Backup RAM (battery backed) UINT8 *memoryPool; // single allocated region for all ROM and system RAM
UINT8 *securityRAM; // 128 KB Security Board RAM UINT8 *ram; // 8 MB PowerPC RAM
UINT8 *driveROM; // 32 KB drive board ROM (Z80 program) (optional) UINT8 *crom; // 8+128 MB CROM (fixed CROM first, then 64MB of banked CROMs -- Daytona2 might need extra?)
UINT8 *vrom; // 64 MB VROM (video ROM, visible only to Real3D)
// Banked CROM UINT8 *soundROM; // 512 KB sound ROM (68K program)
UINT8 *cromBank; // currently mapped in CROM bank UINT8 *sampleROM; // 8 MB samples (68K)
unsigned cromBankReg; // the CROM bank register UINT8 *dsbROM; // 128 KB DSB ROM (Z80 program)
UINT8 *mpegROM; // 8 MB DSB MPEG ROM
// Security device UINT8 *backupRAM; // 128 KB Backup RAM (battery backed)
unsigned securityPtr; // pointer to current offset in security data UINT8 *securityRAM; // 128 KB Security Board RAM
UINT8 *driveROM; // 32 KB drive board ROM (Z80 program) (optional)
// PowerPC
PPC_FETCH_REGION PPCFetchRegions[3]; // Banked CROM
UINT8 *cromBank; // currently mapped in CROM bank
// Multiple threading unsigned cromBankReg; // the CROM bank register
bool startedThreads; // True if threads have been created and started
CThread *sndBrdThread; // Sound board thread // Security device
CThread *drvBrdThread; // Drive board thread unsigned securityPtr; // pointer to current offset in security data
bool sndBrdThreadDone; // Flag to indicate sound board thread has finished processing for current frame
bool drvBrdThreadDone; // Flag to indicate drive board thread has finished processing for current frame // PowerPC
PPC_FETCH_REGION PPCFetchRegions[3];
// Thread synchronization objects
CSemaphore *sndBrdThreadSync; // Multiple threading
CSemaphore *drvBrdThreadSync; bool startedThreads; // True if threads have been created and started
CMutex *notifyLock; bool pausedThreads; // True if threads are currently paused
CCondVar *notifySync; CThread *sndBrdThread; // Sound board thread
CThread *drvBrdThread; // Drive board thread
// Other devices bool sndBrdThreadRunning; // Flag to indicate sound board thread is currently processing
CIRQ IRQ; // Model 3 IRQ controller bool sndBrdThreadDone; // Flag to indicate sound board thread has finished processing
CMPC10x PCIBridge; // MPC10x PCI/bridge/memory controller bool drvBrdThreadRunning; // Flag to indicate drive board thread is currently processing
CPCIBus PCIBus; // Model 3's PCI bus bool drvBrdThreadDone; // Flag to indicate drive board thread has finished processing
C53C810 SCSI; // NCR 53C810 SCSI controller
CRTC72421 RTC; // Epson RTC-72421 real-time clock // Thread synchronization objects
C93C46 EEPROM; // 93C46 EEPROM bool syncSndBrdThread;
CTileGen TileGen; // Sega 2D tile generator CSemaphore *sndBrdThreadSync;
CReal3D GPU; // Real3D graphics hardware CMutex *sndBrdNotifyLock;
CSoundBoard SoundBoard; // Sound board CCondVar *sndBrdNotifySync;
CDSB *DSB; // Digital Sound Board (type determined dynamically at load time) CSemaphore *drvBrdThreadSync;
CDriveBoard DriveBoard; // Drive board CMutex *notifyLock;
}; CCondVar *notifySync;
// Other devices
#endif // INCLUDED_MODEL3_H CIRQ IRQ; // Model 3 IRQ controller
CMPC10x PCIBridge; // MPC10x PCI/bridge/memory controller
CPCIBus PCIBus; // Model 3's PCI bus
C53C810 SCSI; // NCR 53C810 SCSI controller
CRTC72421 RTC; // Epson RTC-72421 real-time clock
C93C46 EEPROM; // 93C46 EEPROM
CTileGen TileGen; // Sega 2D tile generator
CReal3D GPU; // Real3D graphics hardware
CSoundBoard SoundBoard; // Sound board
CDSB *DSB; // Digital Sound Board (type determined dynamically at load time)
CDriveBoard DriveBoard; // Drive board
};
#endif // INCLUDED_MODEL3_H

View file

@ -1,4 +1,3 @@
//TODO: before release, comment out printf()'s
/** /**
** Supermodel ** Supermodel
** A Sega Model 3 Arcade Emulator. ** A Sega Model 3 Arcade Emulator.
@ -358,7 +357,7 @@ void CSoundBoard::WriteMIDIPort(UINT8 data)
DSB->SendCommand(data); DSB->SendCommand(data);
} }
void CSoundBoard::RunFrame(void) bool CSoundBoard::RunFrame(void)
{ {
#ifdef SUPERMODEL_SOUND #ifdef SUPERMODEL_SOUND
// Run sound board first to generate SCSP audio // Run sound board first to generate SCSP audio
@ -379,7 +378,7 @@ void CSoundBoard::RunFrame(void)
DSB->RunFrame(audioL, audioR); DSB->RunFrame(audioL, audioR);
// Output the audio buffers // Output the audio buffers
OutputAudio(44100/60, audioL, audioR); bool bufferFull = OutputAudio(44100/60, audioL, audioR);
#ifdef SUPERMODEL_LOG_AUDIO #ifdef SUPERMODEL_LOG_AUDIO
// Output to binary file // Output to binary file
@ -391,8 +390,10 @@ void CSoundBoard::RunFrame(void)
s = audioR[i]; s = audioR[i];
fwrite(&s, sizeof(INT16), 1, soundFP); // right channel fwrite(&s, sizeof(INT16), 1, soundFP); // right channel
} }
#endif #endif // SUPERMODEL_LOG_AUDIO
#endif #endif // SUPERMODEL_SOUND
return bufferFull;
} }
void CSoundBoard::Reset(void) void CSoundBoard::Reset(void)

View file

@ -126,7 +126,7 @@ public:
* *
* Runs the sound board for one frame, updating sound in the process. * Runs the sound board for one frame, updating sound in the process.
*/ */
void RunFrame(void); bool RunFrame(void);
/* /*
* Reset(void): * Reset(void):
@ -161,7 +161,7 @@ public:
* error messages. * error messages.
*/ */
bool Init(const UINT8 *soundROMPtr, const UINT8 *sampleROMPtr); bool Init(const UINT8 *soundROMPtr, const UINT8 *sampleROMPtr);
/* /*
* CSoundBoard(void): * CSoundBoard(void):
* ~CSoundBoard(void): * ~CSoundBoard(void):

View file

@ -7,6 +7,12 @@
* Function-based interface for audio output. * Function-based interface for audio output.
*/ */
typedef void (*AudioCallbackFPtr)(void *data);
extern void SetAudioCallback(AudioCallbackFPtr callback, void *data);
extern void SetAudioEnabled(bool enabled);
/* /*
* OpenAudio() * OpenAudio()
* *
@ -19,7 +25,7 @@ extern bool OpenAudio();
* *
* Sends a chunk of two-channel audio with the given number of samples to the audio system. * Sends a chunk of two-channel audio with the given number of samples to the audio system.
*/ */
extern void OutputAudio(unsigned numSamples, INT16 *leftBuffer, INT16 *rightBuffer); extern bool OutputAudio(unsigned numSamples, INT16 *leftBuffer, INT16 *rightBuffer);
/* /*
* CloseAudio() * CloseAudio()

View file

@ -38,11 +38,30 @@ static bool writeWrapped = false; // True if write position has wrapped around
static unsigned underRuns = 0; // Number of buffer under-runs that have occured static unsigned underRuns = 0; // Number of buffer under-runs that have occured
static unsigned overRuns = 0; // Number of buffer over-runs that have occured static unsigned overRuns = 0; // Number of buffer over-runs that have occured
static AudioCallbackFPtr callback = NULL;
static void *callbackData = NULL;
void SetAudioCallback(AudioCallbackFPtr newCallback, void *newData)
{
// Lock audio whilst changing callback pointers
SDL_LockAudio();
callback = newCallback;
callbackData = newData;
SDL_UnlockAudio();
}
void SetAudioEnabled(bool newEnabled)
{
enabled = newEnabled;
}
static void PlayCallback(void *data, Uint8 *stream, int len) static void PlayCallback(void *data, Uint8 *stream, int len)
{ {
//printf("PlayCallback(%d) [writePos = %u, writeWrapped = %s, playPos = %u, audioBufferSize = %u]\n", //printf("PlayCallback(%d) [writePos = %u, writeWrapped = %s, playPos = %u, audioBufferSize = %u]\n",
// len, writePos, (writeWrapped ? "true" : "false"), playPos, audioBufferSize); // len, writePos, (writeWrapped ? "true" : "false"), playPos, audioBufferSize);
// Get current write position and adjust it if write has wrapped but play position has not // Get current write position and adjust it if write has wrapped but play position has not
UINT32 adjWritePos = writePos; UINT32 adjWritePos = writePos;
if (writeWrapped) if (writeWrapped)
@ -128,6 +147,8 @@ static void PlayCallback(void *data, Uint8 *stream, int len)
// Move play position forward for next time // Move play position forward for next time
playPos += len; playPos += len;
bool halfEmpty = adjWritePos + audioBufferSize / 2 - BYTES_PER_FRAME / 2 < playPos + audioBufferSize;
// Check if play position has moved past end of buffer // Check if play position has moved past end of buffer
if (playPos >= audioBufferSize) if (playPos >= audioBufferSize)
{ {
@ -135,6 +156,10 @@ static void PlayCallback(void *data, Uint8 *stream, int len)
playPos -= audioBufferSize; playPos -= audioBufferSize;
writeWrapped = false; writeWrapped = false;
} }
// If buffer is more than half empty then call callback
if (callback && halfEmpty)
callback(callbackData);
} }
static void MixChannels(unsigned numSamples, INT16 *leftBuffer, INT16 *rightBuffer, void *dest) static void MixChannels(unsigned numSamples, INT16 *leftBuffer, INT16 *rightBuffer, void *dest)
@ -227,11 +252,13 @@ bool OpenAudio()
return OKAY; return OKAY;
} }
void OutputAudio(unsigned numSamples, INT16 *leftBuffer, INT16 *rightBuffer) bool OutputAudio(unsigned numSamples, INT16 *leftBuffer, INT16 *rightBuffer)
{ {
//printf("OutputAudio(%u) [writePos = %u, writeWrapped = %s, playPos = %u, audioBufferSize = %u]\n", //printf("OutputAudio(%u) [writePos = %u, writeWrapped = %s, playPos = %u, audioBufferSize = %u]\n",
// numSamples, writePos, (writeWrapped ? "true" : "false"), playPos, audioBufferSize); // numSamples, writePos, (writeWrapped ? "true" : "false"), playPos, audioBufferSize);
bool halfFull = false;
UINT32 bytesRemaining; UINT32 bytesRemaining;
UINT32 bytesToCopy; UINT32 bytesToCopy;
INT16 *src; INT16 *src;
@ -296,6 +323,9 @@ void OutputAudio(unsigned numSamples, INT16 *leftBuffer, INT16 *rightBuffer)
// Check if write position has caught up with play region and now overlaps it (ie buffer over-run) // Check if write position has caught up with play region and now overlaps it (ie buffer over-run)
bool overRun = writePos + numBytes > playPos + audioBufferSize; bool overRun = writePos + numBytes > playPos + audioBufferSize;
if (writePos + audioBufferSize / 2 + BYTES_PER_FRAME / 2 > playPos + audioBufferSize)
halfFull = true;
// Move write position back to within buffer // Move write position back to within buffer
if (writePos >= audioBufferSize) if (writePos >= audioBufferSize)
writePos -= audioBufferSize; writePos -= audioBufferSize;
@ -308,6 +338,8 @@ void OutputAudio(unsigned numSamples, INT16 *leftBuffer, INT16 *rightBuffer)
//printf("Audio buffer over-run #%u in OutputAudio(%u) [writePos = %u, writeWrapped = %s, playPos = %u, audioBufferSize = %u, numBytes = %u]\n", //printf("Audio buffer over-run #%u in OutputAudio(%u) [writePos = %u, writeWrapped = %s, playPos = %u, audioBufferSize = %u, numBytes = %u]\n",
// overRuns, numSamples, writePos, (writeWrapped ? "true" : "false"), playPos, audioBufferSize, numBytes); // overRuns, numSamples, writePos, (writeWrapped ? "true" : "false"), playPos, audioBufferSize, numBytes);
halfFull = true;
// Discard current chunk of data // Discard current chunk of data
goto Finish; goto Finish;
} }
@ -366,6 +398,9 @@ void OutputAudio(unsigned numSamples, INT16 *leftBuffer, INT16 *rightBuffer)
Finish: Finish:
// Unlock SDL audio callback // Unlock SDL audio callback
SDL_UnlockAudio(); SDL_UnlockAudio();
// Return whether buffer is half full
return halfFull;
} }
void CloseAudio() void CloseAudio()

View file

@ -762,17 +762,25 @@ int Supermodel(const char *zipFile, CInputs *Inputs, CINIFile *CmdLine)
quit = 1; quit = 1;
#ifdef SUPERMODEL_DEBUGGER #ifdef SUPERMODEL_DEBUGGER
bool processUI = true;
if (Debugger != NULL) if (Debugger != NULL)
{ {
Debugger->Poll(); Debugger->Poll();
// Check if debugger requests exit or pause // Check if debugger requests exit or pause
if (Debugger->CheckExit()) if (Debugger->CheckExit())
quit = 1;
else if (Debugger->CheckPause())
paused = 1;
else
{ {
quit = 1;
processUI = false;
}
else if (Debugger->CheckPause())
{
paused = 1;
processUI = false;
}
}
if (processUI)
{
#endif // SUPERMODEL_DEBUGGER #endif // SUPERMODEL_DEBUGGER
// Check UI controls // Check UI controls
@ -783,6 +791,12 @@ int Supermodel(const char *zipFile, CInputs *Inputs, CINIFile *CmdLine)
} }
else if (Inputs->uiReset->Pressed()) else if (Inputs->uiReset->Pressed())
{ {
if (!paused)
{
Model3->PauseThreads();
SetAudioEnabled(false);
}
// Reset emulator // Reset emulator
Model3->Reset(); Model3->Reset();
@ -792,17 +806,46 @@ int Supermodel(const char *zipFile, CInputs *Inputs, CINIFile *CmdLine)
Debugger->Reset(); Debugger->Reset();
#endif // SUPERMODEL_DEBUGGER #endif // SUPERMODEL_DEBUGGER
if (!paused)
{
Model3->ResumeThreads();
SetAudioEnabled(true);
}
puts("Model 3 reset."); puts("Model 3 reset.");
} }
else if (Inputs->uiPause->Pressed()) else if (Inputs->uiPause->Pressed())
{ {
// Toggle emulator paused flag // Toggle emulator paused flag
paused = !paused; paused = !paused;
if (paused)
{
Model3->PauseThreads();
SetAudioEnabled(false);
}
else
{
Model3->ResumeThreads();
SetAudioEnabled(true);
}
} }
else if (Inputs->uiSaveState->Pressed()) else if (Inputs->uiSaveState->Pressed())
{ {
if (!paused)
{
Model3->PauseThreads();
SetAudioEnabled(false);
}
// Save game state // Save game state
SaveState(Model3); SaveState(Model3);
if (!paused)
{
Model3->ResumeThreads();
SetAudioEnabled(true);
}
} }
else if (Inputs->uiChangeSlot->Pressed()) else if (Inputs->uiChangeSlot->Pressed())
{ {
@ -813,6 +856,12 @@ int Supermodel(const char *zipFile, CInputs *Inputs, CINIFile *CmdLine)
} }
else if (Inputs->uiLoadState->Pressed()) else if (Inputs->uiLoadState->Pressed())
{ {
if (!paused)
{
Model3->PauseThreads();
SetAudioEnabled(false);
}
// Load game state // Load game state
LoadState(Model3); LoadState(Model3);
@ -821,6 +870,12 @@ int Supermodel(const char *zipFile, CInputs *Inputs, CINIFile *CmdLine)
if (Debugger != NULL) if (Debugger != NULL)
Debugger->Reset(); Debugger->Reset();
#endif // SUPERMODEL_DEBUGGER #endif // SUPERMODEL_DEBUGGER
if (!paused)
{
Model3->ResumeThreads();
SetAudioEnabled(true);
}
} }
else if (Inputs->uiMusicVolUp->Pressed()) else if (Inputs->uiMusicVolUp->Pressed())
{ {
@ -904,12 +959,12 @@ int Supermodel(const char *zipFile, CInputs *Inputs, CINIFile *CmdLine)
printf("Frame limiting: %s\n", g_Config.throttle?"On":"Off"); printf("Frame limiting: %s\n", g_Config.throttle?"On":"Off");
} }
#ifdef SUPERMODEL_DEBUGGER #ifdef SUPERMODEL_DEBUGGER
else if (Inputs->uiEnterDebugger->Pressed()) else if (Debugger != NULL && Inputs->uiEnterDebugger->Pressed())
{ {
// Break execution and enter debugger // Break execution and enter debugger
Debugger->ForceBreak(true); Debugger->ForceBreak(true);
}
} }
}
#endif // SUPERMODEL_DEBUGGER #endif // SUPERMODEL_DEBUGGER
// FPS and frame rate // FPS and frame rate

View file

@ -122,6 +122,11 @@ bool CCondVar::Signal()
return SDL_CondSignal((SDL_cond*)m_impl) == 0; return SDL_CondSignal((SDL_cond*)m_impl) == 0;
} }
bool CCondVar::SignalAll()
{
return SDL_CondBroadcast((SDL_cond*)m_impl) == 0;
}
CMutex::CMutex(void *impl) : m_impl(impl) CMutex::CMutex(void *impl) : m_impl(impl)
{ {
// //