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 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
|
/* 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_printf
#define FORBIDDEN_SYMBOL_EXCEPTION_time_h
#define FORBIDDEN_SYMBOL_EXCEPTION_unistd_h
#include <3ds.h>
#include "osystem.h"
#include "backends/mutex/3ds/3ds-mutex.h"
#include "backends/saves/default/default-saves.h"
#include "backends/timer/default/default-timer.h"
#include "backends/events/default/default-events.h"
#include "audio/mixer_intern.h"
#include "common/scummsys.h"
#include "common/config-manager.h"
#include "common/str.h"
#include "backends/fs/posix-drives/posix-drives-fs-factory.h"
#include "backends/fs/posix-drives/posix-drives-fs.h"
#include <unistd.h>
#include <time.h>
namespace N3DS {
OSystem_3DS::OSystem_3DS():
_focusDirty(true),
_focusRect(Common::Rect(1, 1)),
_focusPosX(0),
_focusPosY(0),
_focusTargetPosX(0),
_focusTargetPosY(0),
_focusStepPosX(0),
_focusStepPosY(0),
_focusScaleX(1.f),
_focusScaleY(1.f),
_focusTargetScaleX(1.f),
_focusTargetScaleY(1.f),
_focusStepScaleX(0.f),
_focusStepScaleY(0.f),
_focusClearTime(0),
_cursorPaletteEnabled(false),
_cursorVisible(false),
_cursorScalable(false),
_cursorScreenX(0),
_cursorScreenY(0),
_cursorOverlayX(0),
_cursorOverlayY(0),
_cursorHotspotX(0),
_cursorHotspotY(0),
_gameTopX(0),
_gameTopY(0),
_gameBottomX(0),
_gameBottomY(0),
_gameWidth(320),
_gameHeight(240),
_magX(0),
_magY(0),
_magWidth(400),
_magHeight(240),
_gameTextureDirty(false),
_filteringEnabled(true),
_overlayVisible(false),
_overlayInGUI(false),
_screenChangeId(0),
_magnifyMode(MODE_MAGOFF),
exiting(false),
sleeping(false),
_logger(0),
_showCursor(true),
_snapToBorder(true),
_stretchToFit(false),
_screen(kScreenBoth)
{
chdir("sdmc:/");
DrivesPOSIXFilesystemFactory *fsFactory = new DrivesPOSIXFilesystemFactory();
fsFactory->addDrive("sdmc:");
fsFactory->addDrive("romfs:");
//
// Disable newlib's buffered IO, and use ScummVM's own buffering stream wrappers.
//
// The newlib version in use in devkitPro has performance issues
// when seeking with a relative offset. See:
// https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=commit;h=59362c80e3a02c011fd0ef3d7f07a20098d2a9d5
//
// devKitPro has a patch to newlib that can cause data corruption when
// seeking back in files and then reading. See:
// https://github.com/devkitPro/newlib/issues/16
//
fsFactory->configureBuffering(DrivePOSIXFilesystemNode::kBufferingModeScummVM, 2048);
_fsFactory = fsFactory;
Posix::assureDirectoryExists("/3ds/scummvm/saves/");
}
OSystem_3DS::~OSystem_3DS() {
exiting = true;
destroyEvents();
destroyAudio();
destroy3DSGraphics();
delete _logger;
_logger = 0;
delete _timerManager;
_timerManager = 0;
}
void OSystem_3DS::quit() {
printf("OSystem_3DS::quit()\n");
}
void OSystem_3DS::initBackend() {
if (!_logger)
_logger = new Backends::Log::Log(this);
if (_logger) {
Common::WriteStream *logFile = createLogFile();
if (logFile)
_logger->open(logFile);
}
updateBacklight();
updateConfig();
ConfMan.registerDefault("fullscreen", true);
ConfMan.registerDefault("aspect_ratio", true);
ConfMan.registerDefault("filtering", true);
if (!ConfMan.hasKey("vkeybd_pack_name")) {
ConfMan.set("vkeybd_pack_name", "vkeybd_small");
}
_timerManager = new DefaultTimerManager();
_savefileManager = new DefaultSaveFileManager("sdmc:/3ds/scummvm/saves/");
init3DSGraphics();
initAudio();
EventsBaseBackend::initBackend();
initEvents();
}
void OSystem_3DS::updateBacklight() {
// Turn off the backlight of any screen not used
if (R_SUCCEEDED(gspLcdInit())) {
if (_screen == kScreenTop) {
GSPLCD_PowerOnBacklight(GSPLCD_SCREEN_TOP);
GSPLCD_PowerOffBacklight(GSPLCD_SCREEN_BOTTOM);
} else if (_screen == kScreenBottom) {
GSPLCD_PowerOnBacklight(GSPLCD_SCREEN_BOTTOM);
GSPLCD_PowerOffBacklight(GSPLCD_SCREEN_TOP);
} else {
GSPLCD_PowerOnBacklight(GSPLCD_SCREEN_BOTH);
}
gspLcdExit();
}
}
void OSystem_3DS::updateConfig() {
if (_gameScreen.getPixels()) {
updateSize();
(!_overlayVisible) ? warpMouse(_cursorScreenX, _cursorScreenY) :
warpMouse(_cursorOverlayX, _cursorOverlayY);
}
}
Common::Path OSystem_3DS::getDefaultConfigFileName() {
return "sdmc:/3ds/scummvm/scummvm.ini";
}
Common::Path OSystem_3DS::getDefaultLogFileName() {
return "sdmc:/3ds/scummvm/scummvm.log";
}
void OSystem_3DS::addSysArchivesToSearchSet(Common::SearchSet &s, int priority) {
s.add("RomFS", new Common::FSDirectory(DATA_PATH"/"), priority);
}
uint32 OSystem_3DS::getMillis(bool skipRecord) {
return svcGetSystemTick() / TICKS_PER_MSEC;
}
void OSystem_3DS::delayMillis(uint msecs) {
svcSleepThread(msecs * 1000000);
}
void OSystem_3DS::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_3DS::createMutex() {
return create3DSMutexInternal();
}
Common::String OSystem_3DS::getSystemLanguage() const {
u8 langcode;
CFGU_GetSystemLanguage(&langcode);
switch (langcode) {
case CFG_LANGUAGE_JP: return "ja_JP";
case CFG_LANGUAGE_EN: return "en_US";
case CFG_LANGUAGE_FR: return "fr_FR";
case CFG_LANGUAGE_DE: return "de_DE";
case CFG_LANGUAGE_IT: return "it_IT";
case CFG_LANGUAGE_ES: return "es_ES";
case CFG_LANGUAGE_ZH: return "zh_CN";
case CFG_LANGUAGE_KO: return "ko_KR";
case CFG_LANGUAGE_NL: return "nl_NL";
case CFG_LANGUAGE_PT: return "pt_BR";
case CFG_LANGUAGE_RU: return "ru_RU";
case CFG_LANGUAGE_TW: return "zh_HK";
default: return "en_US";
}
}
void OSystem_3DS::fatalError() {
printf("FatalError!\n");
}
void OSystem_3DS::logMessage(LogMessageType::Type type, const char *message) {
printf("%s", message);
// Then log into file (via the logger)
if (_logger)
_logger->print(message);
}
Common::WriteStream *OSystem_3DS::createLogFile() {
// Start out by resetting _logFilePath, so that in case
// of a failure, we know that no log file is open.
_logFilePath.clear();
Common::Path logFile;
if (ConfMan.hasKey("logfile"))
logFile = ConfMan.getPath("logfile");
else
logFile = getDefaultLogFileName();
if (logFile.empty())
return nullptr;
Common::FSNode file(logFile);
Common::WriteStream *stream = file.createWriteStream(false);
if (stream)
_logFilePath = logFile;
return stream;
}
} // namespace N3DS
|