1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
|
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#define FORBIDDEN_SYMBOL_EXCEPTION_time_h
#define FORBIDDEN_SYMBOL_EXCEPTION_printf
#include <nds.h>
#include <filesystem.h>
#include "backends/platform/ds/osystem_ds.h"
#include "common/config-manager.h"
#include "common/translation.h"
#include "backends/audiocd/default/default-audiocd.h"
#include "backends/events/default/default-events.h"
#include "backends/fs/devoptab/devoptab-fs-factory.h"
#include "backends/keymapper/hardware-input.h"
#include "backends/mixer/maxmod/maxmod-mixer.h"
#include "backends/mutex/null/null-mutex.h"
#include "backends/saves/default/default-saves.h"
#include "backends/timer/default/default-timer.h"
#include <time.h>
OSystem_DS *OSystem_DS::_instance = NULL;
OSystem_DS::OSystem_DS()
: _eventSource(NULL), _engineRunning(false), _disableCursorPalette(true),
_graphicsMode(GFX_HWSCALE), _stretchMode(100),
_paletteDirty(false), _cursorDirty(false), _overlayInGUI(false),
_pfCLUT8(Graphics::PixelFormat::createFormatCLUT8()),
_pfABGR1555(Graphics::PixelFormat(2, 5, 5, 5, 1, 0, 5, 10, 15)),
_callbackTimer(10), _currentTimeMillis(0), _subScreenActive(true)
{
_instance = this;
nitroFSInit(NULL);
DevoptabFilesystemFactory *fsFactory = new DevoptabFilesystemFactory();
// Disable newlib's buffering, since libfat handles caching.
fsFactory->configureBuffering(DrivePOSIXFilesystemNode::kBufferingModeDisabled, 0);
_fsFactory = fsFactory;
}
OSystem_DS::~OSystem_DS() {
}
void timerTickHandler() {
OSystem_DS *system = OSystem_DS::instance();
if (system->_callbackTimer > 0) {
system->_callbackTimer--;
}
system->_currentTimeMillis++;
}
void OSystem_DS::initBackend() {
defaultExceptionHandler();
ConfMan.setInt("autosave_period", 0);
ConfMan.setBool("FM_medium_quality", true);
_eventSource = new DSEventSource();
_eventManager = new DefaultEventManager(_eventSource);
_savefileManager = new DefaultSaveFileManager();
_timerManager = new DefaultTimerManager();
timerStart(0, ClockDivider_1, (u16)TIMER_FREQ(1000), timerTickHandler);
_mixerManager = new MaxModMixerManager(11025, 32768);
_mixerManager->init();
initGraphics();
BaseBackend::initBackend();
}
void OSystem_DS::addSysArchivesToSearchSet(Common::SearchSet &s, int priority) {
s.add("nitro:/", new Common::FSDirectory("nitro:/"), priority);
}
uint32 OSystem_DS::getMillis(bool skipRecord) {
return _currentTimeMillis;
}
void OSystem_DS::delayMillis(uint msecs) {
int st = getMillis();
doTimerCallback();
if (_mixerManager)
((MaxModMixerManager *)_mixerManager)->updateAudio();
while (st + msecs >= getMillis());
}
void OSystem_DS::doTimerCallback(int interval) {
DefaultTimerManager *tm = (DefaultTimerManager *)getTimerManager();
if (_callbackTimer <= 0) {
_callbackTimer += interval;
tm->handler();
}
}
void OSystem_DS::getTimeAndDate(TimeDate &td, bool skipRecord) const {
time_t curTime = time(0);
struct tm t = *localtime(&curTime);
td.tm_sec = t.tm_sec;
td.tm_min = t.tm_min;
td.tm_hour = t.tm_hour;
td.tm_mday = t.tm_mday;
td.tm_mon = t.tm_mon;
td.tm_year = t.tm_year;
td.tm_wday = t.tm_wday;
}
Common::MutexInternal *OSystem_DS::createMutex() {
return new NullMutexInternal();
}
void OSystem_DS::quit() {
}
void OSystem_DS::logMessage(LogMessageType::Type type, const char *message) {
#ifndef DISABLE_TEXT_CONSOLE
if (type == LogMessageType::kError) {
printf("\x1b[41m%s\x1b[39m", message);
} else {
printf("%s", message);
}
#endif
}
void OSystem_DS::messageBox(LogMessageType::Type type, const char *message) {
if (type == LogMessageType::kError) {
#ifdef DISABLE_TEXT_CONSOLE
consoleDemoInit();
printf("\x1b[41m%s\x1b[39m", message);
#endif
printf("\nPress any button to continue\n");
while(1) {
swiWaitForVBlank();
scanKeys();
if (keysDown()) break;
}
}
}
static const Common::HardwareInputTableEntry ndsJoystickButtons[] = {
{ "JOY_A", Common::JOYSTICK_BUTTON_A, _s("A") },
{ "JOY_B", Common::JOYSTICK_BUTTON_B, _s("B") },
{ "JOY_X", Common::JOYSTICK_BUTTON_X, _s("X") },
{ "JOY_Y", Common::JOYSTICK_BUTTON_Y, _s("Y") },
{ "JOY_BACK", Common::JOYSTICK_BUTTON_BACK, _s("Select") },
{ "JOY_START", Common::JOYSTICK_BUTTON_START, _s("Start") },
{ "JOY_LEFT_SHOULDER", Common::JOYSTICK_BUTTON_LEFT_SHOULDER, _s("L") },
{ "JOY_RIGHT_SHOULDER", Common::JOYSTICK_BUTTON_RIGHT_SHOULDER, _s("R") },
{ "JOY_UP", Common::JOYSTICK_BUTTON_DPAD_UP, _s("D-pad Up") },
{ "JOY_DOWN", Common::JOYSTICK_BUTTON_DPAD_DOWN, _s("D-pad Down") },
{ "JOY_LEFT", Common::JOYSTICK_BUTTON_DPAD_LEFT, _s("D-pad Left") },
{ "JOY_RIGHT", Common::JOYSTICK_BUTTON_DPAD_RIGHT, _s("D-pad Right") },
{ nullptr, 0, nullptr }
};
static const Common::AxisTableEntry ndsJoystickAxes[] = {
{ nullptr, 0, Common::kAxisTypeFull, nullptr }
};
const Common::HardwareInputTableEntry ndsMouseButtons[] = {
{ "MOUSE_LEFT", Common::MOUSE_BUTTON_LEFT, _s("Touch") },
{ nullptr, 0, nullptr }
};
Common::HardwareInputSet *OSystem_DS::getHardwareInputSet() {
using namespace Common;
CompositeHardwareInputSet *inputSet = new CompositeHardwareInputSet();
// Touch input sends mouse events for now, so we need to declare we have a mouse...
inputSet->addHardwareInputSet(new MouseHardwareInputSet(ndsMouseButtons));
inputSet->addHardwareInputSet(new JoystickHardwareInputSet(ndsJoystickButtons, ndsJoystickAxes));
return inputSet;
}
Common::String OSystem_DS::getSystemLanguage() const {
switch (PersonalData->language) {
case 0: return "ja_JP";
case 1: return "en_US";
case 2: return "fr_FR";
case 3: return "de_DE";
case 4: return "it_IT";
case 5: return "es_ES";
case 6: return "zh_CN";
default: return "en_US";
}
}
void OSystem_DS::engineInit() {
_engineRunning = true;
}
void OSystem_DS::engineDone() {
_engineRunning = false;
}
|