DS: Begin modularizing the DS backend

This commit is contained in:
Cameron Cawley 2020-09-15 20:02:53 +01:00 committed by Eugene Sandulenko
parent 6fa77b3429
commit 1c40d79732
4 changed files with 40 additions and 43 deletions

View file

@ -36,7 +36,6 @@
MaxModMixerManager::MaxModMixerManager(int freq, int bufSize) MaxModMixerManager::MaxModMixerManager(int freq, int bufSize)
: :
_mixer(0),
_freq(freq), _freq(freq),
_bufSize(bufSize) { _bufSize(bufSize) {
@ -66,17 +65,30 @@ void MaxModMixerManager::init() {
sys.fifo_channel = FIFO_MAXMOD; sys.fifo_channel = FIFO_MAXMOD;
mmInit( &sys ); mmInit( &sys );
mm_stream mystream; _stream.sampling_rate = _freq;
mystream.sampling_rate = _freq; _stream.buffer_length = _bufSize / 4;
mystream.buffer_length = _bufSize / 4; _stream.callback = on_stream_request;
mystream.callback = on_stream_request; _stream.format = MM_STREAM_16BIT_STEREO;
mystream.format = MM_STREAM_16BIT_STEREO; _stream.timer = MM_TIMER2;
mystream.timer = MM_TIMER2; _stream.manual = 0;
mystream.manual = 0;
mmStreamOpen( &mystream ); mmStreamOpen( &_stream );
_mixer->setReady(true); _mixer->setReady(true);
} }
void MaxModMixerManager::suspendAudio() {
mmStreamClose();
_audioSuspended = true;
}
int MaxModMixerManager::resumeAudio() {
if (!_audioSuspended)
return -2;
mmStreamOpen( &_stream );
_audioSuspended = false;
return 0;
}
#endif #endif

View file

@ -23,14 +23,16 @@
#ifndef BACKENDS_MIXER_MAXMOD_H #ifndef BACKENDS_MIXER_MAXMOD_H
#define BACKENDS_MIXER_MAXMOD_H #define BACKENDS_MIXER_MAXMOD_H
#include "audio/mixer_intern.h" #include "backends/mixer/mixer.h"
#include <mm_types.h>
/** /**
* MaxMod mixer manager. It wraps the actual implementation * MaxMod mixer manager. It wraps the actual implementation
* of the Audio:Mixer used by the engine, and sets up * of the Audio:Mixer used by the engine, and sets up
* MaxMod and the callback for the audio mixer implementation. * MaxMod and the callback for the audio mixer implementation.
*/ */
class MaxModMixerManager { class MaxModMixerManager : public MixerManager {
public: public:
MaxModMixerManager(int freq, int bufSize); MaxModMixerManager(int freq, int bufSize);
virtual ~MaxModMixerManager(); virtual ~MaxModMixerManager();
@ -41,14 +43,17 @@ public:
virtual void init(); virtual void init();
/** /**
* Get the audio mixer implementation * Pauses the audio system
*/ */
Audio::Mixer *getMixer() { return (Audio::Mixer *)_mixer; } virtual void suspendAudio();
/**
* Resumes the audio system
*/
virtual int resumeAudio();
protected: protected:
/** The mixer implementation */ mm_stream _stream;
Audio::MixerImpl *_mixer;
int _freq, _bufSize; int _freq, _bufSize;
}; };

View file

@ -49,6 +49,8 @@
#include "backends/audiocd/default/default-audiocd.h" #include "backends/audiocd/default/default-audiocd.h"
#include "backends/events/default/default-events.h" #include "backends/events/default/default-events.h"
#include "backends/mixer/maxmod/maxmod-mixer.h"
#include "backends/mutex/null/null-mutex.h"
#include "backends/saves/default/default-saves.h" #include "backends/saves/default/default-saves.h"
#include "backends/timer/default/default-timer.h" #include "backends/timer/default/default-timer.h"
@ -57,7 +59,7 @@
OSystem_DS *OSystem_DS::_instance = NULL; OSystem_DS *OSystem_DS::_instance = NULL;
OSystem_DS::OSystem_DS() OSystem_DS::OSystem_DS()
: _eventSource(NULL), _mixerManager(NULL), _isOverlayShown(true), : _eventSource(NULL), _isOverlayShown(true),
_graphicsMode(GFX_HWSCALE), _stretchMode(100), _graphicsMode(GFX_HWSCALE), _stretchMode(100),
_disableCursorPalette(true), _graphicsEnable(true), _disableCursorPalette(true), _graphicsEnable(true),
_callbackTimer(10), _currentTimeMillis(0) _callbackTimer(10), _currentTimeMillis(0)
@ -66,11 +68,10 @@ OSystem_DS::OSystem_DS()
nitroFSInit(NULL); nitroFSInit(NULL);
_fsFactory = new DevoptabFilesystemFactory(); _fsFactory = new DevoptabFilesystemFactory();
_mutexManager = new NullMutexManager();
} }
OSystem_DS::~OSystem_DS() { OSystem_DS::~OSystem_DS() {
delete _mixerManager;
_mixerManager = 0;
} }
void timerTickHandler() { void timerTickHandler() {
@ -441,19 +442,6 @@ void OSystem_DS::getTimeAndDate(TimeDate &td) const {
td.tm_wday = t.tm_wday; td.tm_wday = t.tm_wday;
} }
OSystem::MutexRef OSystem_DS::createMutex(void) {
return NULL;
}
void OSystem_DS::lockMutex(MutexRef mutex) {
}
void OSystem_DS::unlockMutex(MutexRef mutex) {
}
void OSystem_DS::deleteMutex(MutexRef mutex) {
}
void OSystem_DS::quit() { void OSystem_DS::quit() {
} }

View file

@ -24,9 +24,9 @@
#ifndef _OSYSTEM_DS_H_ #ifndef _OSYSTEM_DS_H_
#define _OSYSTEM_DS_H_ #define _OSYSTEM_DS_H_
#include "backends/base-backend.h" #include "backends/modular-backend.h"
#include "backends/events/ds/ds-events.h" #include "backends/events/ds/ds-events.h"
#include "backends/mixer/maxmod/maxmod-mixer.h" #include "backends/mixer/mixer.h"
#include "graphics/surface.h" #include "graphics/surface.h"
#include "graphics/palette.h" #include "graphics/palette.h"
@ -36,9 +36,8 @@ enum {
GFX_SWSCALE = 2 GFX_SWSCALE = 2
}; };
class OSystem_DS : public BaseBackend, public PaletteManager { class OSystem_DS : public ModularMutexBackend, public ModularMixerBackend, public PaletteManager {
protected: protected:
MaxModMixerManager *_mixerManager;
Graphics::Surface _framebuffer, _overlay, _cursor; Graphics::Surface _framebuffer, _overlay, _cursor;
bool _graphicsEnable, _isOverlayShown; bool _graphicsEnable, _isOverlayShown;
int _graphicsMode, _stretchMode; int _graphicsMode, _stretchMode;
@ -123,11 +122,6 @@ public:
virtual Common::String getSystemLanguage() const; virtual Common::String getSystemLanguage() const;
virtual MutexRef createMutex(void);
virtual void lockMutex(MutexRef mutex);
virtual void unlockMutex(MutexRef mutex);
virtual void deleteMutex(MutexRef mutex);
virtual void quit(); virtual void quit();
virtual void setFocusRectangle(const Common::Rect& rect); virtual void setFocusRectangle(const Common::Rect& rect);
@ -141,8 +135,6 @@ public:
virtual Graphics::Surface *lockScreen(); virtual Graphics::Surface *lockScreen();
virtual void unlockScreen(); virtual void unlockScreen();
virtual Audio::Mixer *getMixer() { return _mixerManager->getMixer(); }
virtual void setCursorPalette(const byte *colors, uint start, uint num); virtual void setCursorPalette(const byte *colors, uint start, uint num);
void refreshCursor(u16 *dst, const Graphics::Surface &src, const uint16 *palette); void refreshCursor(u16 *dst, const Graphics::Surface &src, const uint16 *palette);