scummvm/backends/platform/dc/dc.h

258 lines
8 KiB
C
Raw Permalink Normal View History

/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program 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 Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "backends/base-backend.h"
#include <graphics/surface.h>
2011-04-28 20:55:00 +03:00
#include <graphics/palette.h>
#include <ronin/soundcommon.h>
#include "backends/timer/default/default-timer.h"
#include "backends/audiocd/default/default-audiocd.h"
#include "backends/fs/fs-factory.h"
#include "audio/mixer_intern.h"
#include "common/language.h"
#include "common/platform.h"
#ifdef DYNAMIC_MODULES
#include "backends/plugins/dynamic-plugin.h"
#endif
2002-02-02 15:44:27 +00:00
#define NUM_BUFFERS 4
#define SOUND_BUFFER_SHIFT 3
2004-03-14 22:16:22 +00:00
class Interactive
{
public:
virtual int key(int k, byte &shiftFlags) = 0;
virtual void mouse(int x, int y) = 0;
2014-01-09 23:26:31 +01:00
virtual ~Interactive() = 0;
2004-03-14 22:16:22 +00:00
};
2014-01-09 23:26:31 +01:00
inline Interactive::~Interactive() { }
2004-03-14 22:16:22 +00:00
#include "softkbd.h"
class DCHardware {
private:
static void dc_init_hardware();
protected:
DCHardware() { dc_init_hardware(); }
};
class DCCDManager : public DefaultAudioCDManager {
public:
// Poll cdrom status
// Returns true if cd audio is playing
bool isPlaying() const override;
// Play cdrom audio track
bool play(int track, int numLoops, int startFrame, int duration, bool onlyEmulate = false,
2020-04-26 03:18:46 +01:00
Audio::Mixer::SoundType soundType = Audio::Mixer::kMusicSoundType) override;
// Stop cdrom audio track
void stop() override;
};
class OSystem_Dreamcast : private DCHardware, public EventsBaseBackend, public PaletteManager, public FilesystemFactory
#ifdef DYNAMIC_MODULES
, public FilePluginProvider
#endif
{
public:
OSystem_Dreamcast();
2006-10-22 17:58:38 +00:00
virtual void initBackend();
2004-03-13 14:00:44 +00:00
// Determine whether the backend supports the specified feature.
bool hasFeature(Feature f);
// En-/disable the specified feature.
void setFeatureState(Feature f, bool enable);
// Query the state of the specified feature.
2004-03-13 14:00:44 +00:00
bool getFeatureState(Feature f);
// Set colors of the palette
PaletteManager *getPaletteManager() { return this; }
protected:
// PaletteManager API
void setPalette(const byte *colors, uint start, uint num);
void grabPalette(byte *colors, uint start, uint num) const;
public:
2009-10-10 14:26:53 +00:00
// Determine the pixel format currently in use for screen rendering.
Graphics::PixelFormat getScreenFormat() const;
// Returns a list of all pixel formats supported by the backend.
Common::List<Graphics::PixelFormat> getSupportedFormats() const;
2009-10-10 14:26:53 +00:00
// Set the size of the video bitmap.
// Typically, 320x200
void initSize(uint w, uint h, const Graphics::PixelFormat *format);
int16 getHeight() { return _screen_h; }
int16 getWidth() { return _screen_w; }
// Draw a bitmap to screen.
// The screen will not be updated to reflect the new bitmap
void copyRectToScreen(const void *buf, int pitch, int x, int y, int w, int h);
virtual Graphics::Surface *lockScreen();
virtual void unlockScreen();
// Update the dirty areas of the screen
void updateScreen();
// Either show or hide the mouse cursor
bool showMouse(bool visible);
// Move ("warp") the mouse cursor to the specified position.
void warpMouse(int x, int y);
2003-03-02 17:41:47 +00:00
// Set the bitmap that's used when drawing the cursor.
void setMouseCursor(const void *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format);
// Replace the specified range of cursor the palette with new colors.
void setCursorPalette(const byte *colors, uint start, uint num);
// Shaking is used in SCUMM. Set current shake position.
void setShakePos(int shake_x_pos, int shake_y_pos);
// Get the number of milliseconds since the program was started.
2013-05-17 00:18:09 +03:00
uint32 getMillis(bool skipRecord = false);
// Delay for a specified amount of milliseconds
void delayMillis(uint msecs);
// Get the current time and date. Correspond to time()+localtime().
void getTimeAndDate(TimeDate &td, bool skipRecord = false) const;
// Get the next event.
// Returns true if an event was retrieved.
bool pollEvent(Common::Event &event);
// Quit
void quit();
// Overlay
int16 getOverlayHeight();
int16 getOverlayWidth();
bool isOverlayVisible() const { return _overlay_visible; }
void showOverlay();
void hideOverlay();
void clearOverlay();
BACKENDS: fixed segfault in EventRecorder with buffer out of bounds writes ==3124361== Invalid write of size 8 ==3124361== at 0x483F803: memmove (vg_replace_strmem.c:1270) ==3124361== by 0x4DBF61: SurfaceSdlGraphicsManager::grabOverlay(void*, int) const (surfacesdl-graphics.cpp:1753) ==3124361== by 0x482051: ModularGraphicsBackend::grabOverlay(void*, int) (modular-backend.cpp:215) ==3124361== by 0x434EE1: GUI::ThemeEngine::clearAll() (ThemeEngine.cpp:376) ==3124361== by 0x40128E: GUI::EventRecorder::preDrawOverlayGui() (EventRecorder.cpp:558) ==3124361== by 0x481DB2: ModularGraphicsBackend::updateScreen() (modular-backend.cpp:173) ==3124361== by 0x559967: Graphics::Screen::updateScreen() (screen.cpp:62) ==3124361== by 0x55991C: Graphics::Screen::update() (screen.cpp:56) ==3124361== by 0x38AFC7: TwinE::TwineScreen::update() (twine.cpp:126) ==3124361== by 0x3B8759: TwinE::Screens::adjustPalette(unsigned char, unsigned char, unsigned char, unsigned int const*, int) (screens.cpp:150) ==3124361== by 0x3B8A89: TwinE::Screens::fadeToPal(unsigned int const*) (screens.cpp:207) ==3124361== by 0x3B8403: TwinE::Screens::loadImage(int, int, bool) (screens.cpp:80) ==3124361== Address 0x31453050 is 16 bytes after a block of size 512,000 alloc'd ==3124361== at 0x483AB65: calloc (vg_replace_malloc.c:760) ==3124361== by 0x55B38C: Graphics::Surface::create(unsigned short, unsigned short, Graphics::PixelFormat const&) (surface.cpp:75) ==3124361== by 0x551111: Graphics::ManagedSurface::create(unsigned short, unsigned short, Graphics::PixelFormat const&) (managed_surface.cpp:153) ==3124361== by 0x4352D5: GUI::ThemeEngine::setGraphicsMode(GUI::ThemeEngine::GraphicsMode) (ThemeEngine.cpp:453) ==3124361== by 0x434A52: GUI::ThemeEngine::init() (ThemeEngine.cpp:324) ==3124361== by 0x43501B: GUI::ThemeEngine::refresh() (ThemeEngine.cpp:394) ==3124361== by 0x405780: GUI::GuiManager::screenChange() (gui-manager.cpp:603) ==3124361== by 0x405C6B: GUI::GuiManager::processEvent(Common::Event const&, GUI::Dialog*) (gui-manager.cpp:677) ==3124361== by 0x404EBA: GUI::GuiManager::runLoop() (gui-manager.cpp:429) ==3124361== by 0x3FD847: GUI::Dialog::runModal() (dialog.cpp:77) ==3124361== by 0x36D747: launcherDialog() (main.cpp:106) ==3124361== by 0x36FF92: scummvm_main (main.cpp:552) It looks like the _videoMode.overlayHeight in SurfaceSdlGraphicsManager::grabOverlay and ThemeEngine::_backBuffer::h are somehow out of sync after starting the game in a different resolution as the gui was started with. So the overlayHeight is updated - but the backbuffer (Surface) is not resized. This is with event recorder being active - right after starting the game and switching the resolution.
2021-06-16 20:05:03 +02:00
void grabOverlay(Graphics::Surface &surface);
void copyRectToOverlay(const void *buf, int pitch, int x, int y, int w, int h);
virtual Graphics::PixelFormat getOverlayFormat() const { return Graphics::PixelFormat(2, 4, 4, 4, 4, 8, 4, 0, 12); }
2002-09-13 15:01:20 +00:00
// Mutex handling
MutexRef createMutex();
void lockMutex(MutexRef mutex);
void unlockMutex(MutexRef mutex);
void deleteMutex(MutexRef mutex);
// Set a window caption or any other comparable status display to the
// given value.
void setWindowCaption(const Common::U32String &caption);
2002-09-13 15:01:20 +00:00
2006-10-22 17:58:38 +00:00
// Modulatized backend
Audio::Mixer *getMixer() { return _mixer; }
2002-09-13 15:01:20 +00:00
// Extra SoftKbd support
void mouseToSoftKbd(int x, int y, int &rx, int &ry) const;
// Filesystem
AbstractFSNode *makeRootFileNode() const override;
AbstractFSNode *makeCurrentDirectoryFileNode() const override;
AbstractFSNode *makeFileNodePath(const Common::String &path) const override;
private:
2008-06-29 11:51:47 +00:00
Audio::MixerImpl *_mixer;
2004-03-14 22:16:22 +00:00
SoftKeyboard _softkbd;
int _ms_cur_x, _ms_cur_y, _ms_cur_w, _ms_cur_h, _ms_old_x, _ms_old_y;
int _ms_hotspot_x, _ms_hotspot_y, _ms_visible, _devpoll, _last_screen_refresh;
int _current_shake_x_pos, _current_shake_y_pos, _screen_w, _screen_h;
int _overlay_x, _overlay_y;
unsigned char *_ms_buf;
2009-10-10 14:26:53 +00:00
uint32 _ms_keycolor;
bool _overlay_visible, _overlay_dirty, _screen_dirty;
int _screen_buffer, _overlay_buffer, _mouse_buffer;
bool _aspect_stretch, _softkbd_on, _enable_cursor_palette;
float _overlay_fade, _xscale, _yscale, _top_offset;
2004-03-14 22:16:22 +00:00
int _softkbd_motion;
unsigned char *screen;
unsigned short *mouse;
unsigned short *overlay;
void *screen_tx[NUM_BUFFERS];
void *mouse_tx[NUM_BUFFERS];
void *ovl_tx[NUM_BUFFERS];
unsigned short palette[256], cursor_palette[256];
Graphics::Surface _framebuffer;
2009-10-10 14:26:53 +00:00
int _screenFormat, _mouseFormat;
int temp_sound_buffer[RING_BUFFER_SAMPLES>>SOUND_BUFFER_SHIFT];
2008-06-29 11:51:47 +00:00
uint initSound();
void checkSound();
void updateScreenTextures(void);
void updateScreenPolygons(void);
void maybeRefreshScreen(void);
void drawMouse(int xdraw, int ydraw, int w, int h,
unsigned char *buf, bool visible);
void setScaling();
Common::SaveFileManager *createSavefileManager();
Common::SeekableReadStream *createConfigReadStream();
Common::WriteStream *createConfigWriteStream();
void logMessage(LogMessageType::Type type, const char *message);
Common::String getSystemLanguage() const;
#ifdef DYNAMIC_MODULES
class DCPlugin;
protected:
Plugin* createPlugin(const Common::FSNode &node) const;
bool isPluginFilename(const Common::FSNode &node) const;
void addCustomDirectories(Common::FSList &dirs) const;
public:
PluginList getPlugins();
private:
const char *pluginCustomDirectory;
#endif
};
2004-03-14 22:16:22 +00:00
extern int handleInput(struct mapledev *pad,
int &mouse_x, int &mouse_y,
2004-03-14 22:16:22 +00:00
byte &shiftFlags, Interactive *inter = NULL);
2018-06-02 14:45:36 +02:00
extern bool selectGame(char *&, char *&, char *&, Common::Language &, Common::Platform &, class Icon &);
#ifdef DYNAMIC_MODULES
extern bool selectPluginDir(Common::String &selection, const Common::FSNode &base);
#endif