ScummVM API documentation
dc.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #include "backends/base-backend.h"
23 #include <graphics/surface.h>
24 #include <graphics/paletteman.h>
25 #include <ronin/soundcommon.h>
26 #include "backends/timer/default/default-timer.h"
27 #include "backends/audiocd/default/default-audiocd.h"
28 #include "backends/fs/fs-factory.h"
29 #include "audio/mixer_intern.h"
30 #include "common/events.h"
31 #include "common/language.h"
32 #include "common/platform.h"
33 #ifdef DYNAMIC_MODULES
34 #include "backends/plugins/dynamic-plugin.h"
35 #endif
36 
37 #define NUM_BUFFERS 4
38 #define SOUND_BUFFER_SHIFT 3
39 
41 {
42  public:
43  virtual int key(int k, byte &shiftFlags) = 0;
44  virtual void mouse(int x, int y) = 0;
45  virtual ~Interactive() = 0;
46 };
47 inline Interactive::~Interactive() { }
48 
49 #include "softkbd.h"
50 
51 class DCHardware {
52  private:
53  static void dc_init_hardware();
54  protected:
55  DCHardware() { dc_init_hardware(); }
56 };
57 
59 public:
60  // Poll cdrom status
61  // Returns true if cd audio is playing
62  bool isPlaying() const override;
63 
64  // Play cdrom audio track
65  bool play(int track, int numLoops, int startFrame, int duration, bool onlyEmulate = false,
67 
68  // Stop cdrom audio track
69  void stop() override;
70 };
71 
72 class OSystem_Dreamcast : virtual public BaseBackend, public Common::EventSource, private DCHardware, public PaletteManager, public FilesystemFactory
73 #ifdef DYNAMIC_MODULES
74  , public FilePluginProvider
75 #endif
76  {
77 
78  public:
80 
81  virtual void initBackend();
82 
83  // Determine whether the backend supports the specified feature.
84  bool hasFeature(Feature f);
85 
86  // En-/disable the specified feature.
87  void setFeatureState(Feature f, bool enable);
88 
89  // Query the state of the specified feature.
90  bool getFeatureState(Feature f);
91 
92  // Set colors of the palette
93  PaletteManager *getPaletteManager() { return this; }
94 protected:
95  // PaletteManager API
96  void setPalette(const byte *colors, uint start, uint num);
97  void grabPalette(byte *colors, uint start, uint num) const;
98 
99 public:
100 
101  // Determine the pixel format currently in use for screen rendering.
102  Graphics::PixelFormat getScreenFormat() const;
103 
104  // Returns a list of all pixel formats supported by the backend.
105  Common::List<Graphics::PixelFormat> getSupportedFormats() const;
106 
107  // Set the size of the video bitmap.
108  // Typically, 320x200
109  void initSize(uint w, uint h, const Graphics::PixelFormat *format);
110  int16 getHeight() { return _screen_h; }
111  int16 getWidth() { return _screen_w; }
112 
113  // Draw a bitmap to screen.
114  // The screen will not be updated to reflect the new bitmap
115  void copyRectToScreen(const void *buf, int pitch, int x, int y, int w, int h);
116 
117  virtual Graphics::Surface *lockScreen();
118  virtual void unlockScreen();
119 
120  // Update the dirty areas of the screen
121  void updateScreen();
122 
123  // Either show or hide the mouse cursor
124  bool showMouse(bool visible);
125 
126  // Move ("warp") the mouse cursor to the specified position.
127  void warpMouse(int x, int y);
128 
129  // Set the bitmap that's used when drawing the cursor.
130  void setMouseCursor(const void *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format, const byte *mask);
131 
132  // Replace the specified range of cursor the palette with new colors.
133  void setCursorPalette(const byte *colors, uint start, uint num);
134 
135  // Shaking is used in SCUMM. Set current shake position.
136  void setShakePos(int shake_x_pos, int shake_y_pos);
137 
138  // Get the number of milliseconds since the program was started.
139  uint32 getMillis(bool skipRecord = false);
140 
141  // Delay for a specified amount of milliseconds
142  void delayMillis(uint msecs);
143 
144  // Get the current time and date. Correspond to time()+localtime().
145  void getTimeAndDate(TimeDate &td, bool skipRecord = false) const;
146 
147  // Get the next event.
148  // Returns true if an event was retrieved.
149  bool pollEvent(Common::Event &event);
150 
151  // Quit
152  void quit();
153 
154  // Overlay
155  int16 getOverlayHeight() const;
156  int16 getOverlayWidth() const;
157  bool isOverlayVisible() const { return _overlay_visible; }
158  void showOverlay(bool inGUI);
159  void hideOverlay();
160  void clearOverlay();
161  void grabOverlay(Graphics::Surface &surface);
162  void copyRectToOverlay(const void *buf, int pitch, int x, int y, int w, int h);
163  virtual Graphics::PixelFormat getOverlayFormat() const { return Graphics::PixelFormat(2, 4, 4, 4, 4, 8, 4, 0, 12); }
164 
165  // Mutex handling
166  Common::MutexInternal *createMutex();
167 
168  // Set a window caption or any other comparable status display to the
169  // given value.
170  void setWindowCaption(const Common::U32String &caption);
171 
172  // Modulatized backend
173  Audio::Mixer *getMixer() { return _mixer; }
174 
175  // Extra SoftKbd support
176  void mouseToSoftKbd(int x, int y, int &rx, int &ry) const;
177 
178  // Filesystem
179  AbstractFSNode *makeRootFileNode() const override;
180  AbstractFSNode *makeCurrentDirectoryFileNode() const override;
181  AbstractFSNode *makeFileNodePath(const Common::String &path) const override;
182 
183  private:
184 
185  Audio::MixerImpl *_mixer;
186  SoftKeyboard _softkbd;
187 
188  int _ms_cur_x, _ms_cur_y, _ms_cur_w, _ms_cur_h, _ms_old_x, _ms_old_y;
189  int _ms_hotspot_x, _ms_hotspot_y, _ms_visible, _devpoll, _last_screen_refresh;
190  int _current_shake_x_pos, _current_shake_y_pos, _screen_w, _screen_h;
191  int _overlay_x, _overlay_y;
192  unsigned char *_ms_buf;
193  uint32 _ms_keycolor;
194  bool _overlay_visible, _overlay_dirty, _screen_dirty;
195  int _screen_buffer, _overlay_buffer, _mouse_buffer;
196  bool _aspect_stretch, _softkbd_on, _enable_cursor_palette;
197  bool _overlay_in_gui;
198  float _overlay_fade, _xscale, _yscale, _top_offset;
199  int _softkbd_motion;
200 
201  unsigned char *screen;
202  unsigned short *mouse;
203  unsigned short *overlay;
204  void *screen_tx[NUM_BUFFERS];
205  void *mouse_tx[NUM_BUFFERS];
206  void *ovl_tx[NUM_BUFFERS];
207  unsigned short palette[256], cursor_palette[256];
208 
209  Graphics::Surface _framebuffer;
210  int _screenFormat, _mouseFormat;
211 
212  int temp_sound_buffer[RING_BUFFER_SAMPLES>>SOUND_BUFFER_SHIFT];
213 
214  uint initSound();
215  void checkSound();
216 
217  void updateScreenTextures(void);
218  void updateScreenPolygons(void);
219  void maybeRefreshScreen(void);
220  void drawMouse(int xdraw, int ydraw, int w, int h,
221  unsigned char *buf, bool visible);
222 
223  void setScaling();
224 
225 
226  Common::SaveFileManager *createSavefileManager();
227 
228  Common::SeekableReadStream *createConfigReadStream();
229  Common::WriteStream *createConfigWriteStream();
230 
231  void logMessage(LogMessageType::Type type, const char *message);
232  Common::String getSystemLanguage() const;
233 
234 #ifdef DYNAMIC_MODULES
235  class DCPlugin;
236 
237  protected:
238  Plugin* createPlugin(const Common::FSNode &node) const;
239  bool isPluginFilename(const Common::FSNode &node) const;
240  void addCustomDirectories(Common::FSList &dirs) const;
241  public:
242  PluginList getPlugins();
243  private:
244  const char *pluginCustomDirectory;
245 #endif
246 };
247 
248 
249 extern int handleInput(struct mapledev *pad,
250  int &mouse_x, int &mouse_y,
251  byte &shiftFlags, Interactive *inter = NULL);
252 extern bool selectGame(char *&, char *&, char *&, Common::Language &, Common::Platform &, class Icon &);
253 #ifdef DYNAMIC_MODULES
254 extern bool selectPluginDir(Common::String &selection, const Common::FSNode &base);
255 #endif
Definition: mixer.h:76
Definition: system.h:109
Definition: str.h:59
Definition: surface.h:67
virtual Graphics::PixelFormat getOverlayFormat() const
Definition: dc.h:163
Definition: stream.h:77
Definition: dc.h:51
Definition: fs-factory.h:31
Definition: array.h:52
Definition: default-audiocd.h:35
Definition: pixelformat.h:138
PaletteManager * getPaletteManager()
Definition: dc.h:93
Feature
Definition: system.h:411
Definition: list.h:44
Definition: stream.h:745
Definition: plugins.h:145
Definition: softkbd.h:31
Type
Definition: log.h:33
Definition: mixer_intern.h:58
Definition: icon.h:25
SoundType
Definition: mixer.h:73
Definition: mixer.h:70
Definition: dc.h:58
Definition: ustr.h:57
Definition: base-backend.h:31
Definition: events.h:210
Definition: fs.h:69
Definition: fs.h:57
Definition: dc.h:40
Definition: savefile.h:142
int16 getWidth()
Definition: dc.h:111
bool isOverlayVisible() const
Definition: dc.h:157
Definition: events.h:270
Definition: mutex.h:40
Audio::Mixer * getMixer()
Definition: dc.h:173
Definition: paletteman.h:47
Definition: dc.h:72
Definition: abstract-fs.h:41
int16 getHeight()
Definition: dc.h:110
Platform
Definition: platform.h:93
Language
Definition: language.h:45