ScummVM API documentation
osys_n64.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 #ifndef __OSYS_N64_H__
23 #define __OSYS_N64_H__
24 
25 #include "common/rect.h"
26 #include "common/config-manager.h"
27 
28 #include "backends/base-backend.h"
29 
30 #include "base/main.h"
31 
32 #include "graphics/surface.h"
33 #include "graphics/paletteman.h"
34 #include "graphics/pixelformat.h"
35 
36 #include "audio/mixer_intern.h"
37 
38 #include <libn64.h>
39 #include <n64utils.h>
40 
41 #define DEFAULT_SOUND_SAMPLE_RATE 8000 // 8 kHz
42 //#define DEFAULT_SOUND_SAMPLE_RATE 11025 // 11 kHz
43 
44 #define N64_PAL_FPS 25
45 #define N64_NTSC_FPS 30
46 
47 typedef int (*TimerProc)(int interval);
48 
49 // Interrupt callback functions
50 void vblCallback(void);
51 void sndCallback(void);
52 void refillAudioBuffers(void);
53 
54 // External utility functions
55 void enableAudioPlayback(void);
56 void disableAudioPlayback(void);
57 void checkTimers(void);
58 int timer_handler(int t);
59 
60 static volatile bool _audioEnabled = false; // Used by interrupt callbacks
61 
62 /* Graphic mode identifiers */
63 enum GraphicModeID {
64  OVERS_NTSC_340X240,
65  NORM_NTSC_320X240,
66  NORM_PAL_320X240,
67  OVERS_PAL_340X240,
68  NORM_MPAL_320X240,
69  OVERS_MPAL_340X240
70 };
71 
73 protected:
74  Audio::MixerImpl *_mixer;
75 
76  struct display_context * _dc; // Display context for N64 on screen buffer switching
77 
78  Graphics::Surface _framebuffer;
79 
80  uint16 *_offscreen_hic; // Offscreen converted to 16bit surface
81  uint8 *_offscreen_pal; // Offscreen with palette indexes
82  uint16 *_overlayBuffer; // Offscreen for the overlay (16 bit)
83 
84  uint16 *_screenPalette; // Array for palette entries (256 colors max)
85 
86 #ifndef N64_EXTREME_MEMORY_SAVING
87  uint8 *_screenExactPalette; // Array for palette entries, as received by setPalette(), no precision loss
88 #endif
89  uint16 _cursorPalette[256]; // Palette entries for the cursor
90 
91  int _graphicMode; // Graphic mode
92  uint16 _screenWidth, _screenHeight;
93  uint16 _gameWidth, _gameHeight;
94  uint16 _frameBufferWidth; // Width of framebuffer in N64 memory
95  uint8 _offscrPixels; // Pixels to skip on each line before start drawing, used to center image
96  uint8 _maxFps; // Max frames-per-second which can be shown on screen
97 
98  int _shakeXOffset;
99  int _shakeYOffset;
100 
101  uint8 *_cursor_pal; // Cursor buffer, palettized
102  uint16 *_cursor_hic; // Cursor buffer, 16bit
103  bool _cursorPaletteDisabled;
104  bool _dirtyPalette;
105 
106  uint _cursorWidth, _cursorHeight;
107 
108  int _cursorKeycolor;
109 
110  uint16 _overlayHeight, _overlayWidth;
111  bool _overlayVisible;
112  bool _overlayInGUI;
113 
114  bool _disableFpsLimit; // When this is enabled, the system doesn't limit screen updates
115 
116  bool _mouseVisible;
117  volatile int _mouseX, _mouseY;
118  volatile float _tempMouseX, _tempMouseY;
119  volatile int _mouseMaxX, _mouseMaxY;
120  int _mouseHotspotX, _mouseHotspotY;
121 
122  int8 _controllerPort;
123  int8 _mousePort;
124  bool _controllerHasRumble; // Gets enabled if rumble-pak is detected
125 
126  bool _dirtyOffscreen;
127 
128 public:
129 
130  /* These have to be accessed by interrupt callbacks */
131  uint16 _audioBufferSize;
132  uint32 _viClockRate; // Clock rate of video system, depending on VI mode
133 
134  uint32 _timerCallbackNext;
135  uint32 _timerCallbackTimer;
136  TimerProc _timerCallback;
137  /* *** */
138 
139  OSystem_N64();
140  virtual ~OSystem_N64();
141 
142  virtual void initBackend();
143 
144  virtual bool hasFeature(Feature f);
145  virtual void setFeatureState(Feature f, bool enable);
146  virtual bool getFeatureState(Feature f);
147  virtual const GraphicsMode *getSupportedGraphicsModes() const;
148  virtual int getDefaultGraphicsMode() const;
149  virtual bool setGraphicsMode(int mode, uint flags = OSystem::kGfxModeNoFlags);
150  virtual int getGraphicsMode() const;
151  virtual void initSize(uint width, uint height, const Graphics::PixelFormat *format);
152  virtual int16 getHeight();
153  virtual int16 getWidth();
154 
155  virtual PaletteManager *getPaletteManager() { return this; }
156 protected:
157  // PaletteManager API
158  virtual void setPalette(const byte *colors, uint start, uint num);
159  virtual void grabPalette(byte *colors, uint start, uint num) const;
160 
161 public:
162  virtual void copyRectToScreen(const void *buf, int pitch, int x, int y, int w, int h);
163  virtual void updateScreen();
164  virtual Graphics::Surface *lockScreen();
165  virtual void unlockScreen();
166  virtual void setShakePos(int shakeXOffset, int shakeYOffset);
167 
168  virtual void showOverlay(bool inGUI);
169  virtual void hideOverlay();
170  virtual bool isOverlayVisible() const { return _overlayVisible; }
171  virtual void clearOverlay();
172  virtual void grabOverlay(Graphics::Surface &surface);
173  virtual void copyRectToOverlay(const void *buf, int pitch, int x, int y, int w, int h);
174  virtual int16 getOverlayHeight();
175  virtual int16 getOverlayWidth();
177  return Graphics::PixelFormat(2, 5, 5, 5, 0, 11, 6, 1, 0);
178  }
179 
180  virtual bool showMouse(bool visible);
181 
182  virtual void warpMouse(int x, int y);
183  virtual void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format, const byte *mask);
184  virtual void setCursorPalette(const byte *colors, uint start, uint num);
185 
186  virtual bool pollEvent(Common::Event &event);
187  virtual uint32 getMillis(bool skipRecord = false);
188  virtual void delayMillis(uint msecs);
189 
190  virtual Common::MutexInternal *createMutex(void);
191 
192  virtual void quit();
193 
194  virtual Audio::Mixer *getMixer();
195  virtual void getTimeAndDate(TimeDate &t, bool skipRecord = false) const;
196  virtual void setTimerCallback(TimerProc callback, int interval);
197  virtual void logMessage(LogMessageType::Type type, const char *message);
198 
199  void rebuildOffscreenGameBuffer(void);
200  void rebuildOffscreenMouseBuffer(void);
201  void switchGraphicModeId(int mode);
202 
203  void setupMixer(void);
204 
205  void detectControllers(void);
206  void readControllerAnalogInput(void); // read controller analog nub position
207 };
208 
209 #endif /* __OSYS_N64_H__ */
virtual int16 getOverlayWidth()
virtual void initSize(uint width, uint height, const Graphics::PixelFormat *format)
Definition: system.h:105
virtual Graphics::PixelFormat getOverlayFormat() const
Definition: osys_n64.h:176
Definition: surface.h:66
Definition: system.h:788
virtual int16 getHeight()
virtual void grabOverlay(Graphics::Surface &surface)
virtual void getTimeAndDate(TimeDate &t, bool skipRecord=false) const
Definition: pixelformat.h:138
Definition: system.h:739
Feature
Definition: system.h:417
virtual void setPalette(const byte *colors, uint start, uint num)
virtual int16 getOverlayHeight()
virtual void hideOverlay()
virtual bool hasFeature(Feature f)
virtual void warpMouse(int x, int y)
virtual void unlockScreen()
virtual bool setGraphicsMode(int mode, uint flags=OSystem::kGfxModeNoFlags)
virtual Common::MutexInternal * createMutex(void)
virtual void setShakePos(int shakeXOffset, int shakeYOffset)
Type
Definition: system.h:121
virtual int getDefaultGraphicsMode() const
Definition: mixer_intern.h:58
virtual void copyRectToScreen(const void *buf, int pitch, int x, int y, int w, int h)
virtual void updateScreen()
Definition: mixer.h:59
virtual const GraphicsMode * getSupportedGraphicsModes() const
virtual bool isOverlayVisible() const
Definition: osys_n64.h:170
virtual void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format, const byte *mask)
virtual void showOverlay(bool inGUI)
Definition: events.h:198
virtual void clearOverlay()
virtual Audio::Mixer * getMixer()
virtual void quit()
virtual void initBackend()
virtual bool pollEvent(Common::Event &event)
virtual int getGraphicsMode() const
virtual void copyRectToOverlay(const void *buf, int pitch, int x, int y, int w, int h)
virtual void setCursorPalette(const byte *colors, uint start, uint num)
virtual PaletteManager * getPaletteManager()
Definition: osys_n64.h:155
Definition: base-backend.h:44
virtual uint32 getMillis(bool skipRecord=false)
virtual void logMessage(LogMessageType::Type type, const char *message)
virtual void delayMillis(uint msecs)
Definition: mutex.h:40
Definition: osys_n64.h:72
virtual Graphics::Surface * lockScreen()
Definition: paletteman.h:46
virtual void grabPalette(byte *colors, uint start, uint num) const
virtual bool getFeatureState(Feature f)
virtual int16 getWidth()
virtual void setFeatureState(Feature f, bool enable)
virtual bool showMouse(bool visible)