2015-02-28 01:51:53 +00:00
|
|
|
#include "../tomoko.hpp"
|
|
|
|
#include <fc/interface/interface.hpp>
|
|
|
|
#include <sfc/interface/interface.hpp>
|
|
|
|
#include <gb/interface/interface.hpp>
|
|
|
|
#include <gba/interface/interface.hpp>
|
|
|
|
#include "interface.cpp"
|
|
|
|
#include "media.cpp"
|
|
|
|
Program* program = nullptr;
|
|
|
|
|
|
|
|
Program::Program() {
|
|
|
|
program = this;
|
2015-03-02 09:13:28 +00:00
|
|
|
directory::create({configpath(), "tomoko/"});
|
2015-02-28 01:51:53 +00:00
|
|
|
Application::onMain({&Program::main, this});
|
|
|
|
|
|
|
|
emulators.append(new Famicom::Interface);
|
|
|
|
emulators.append(new SuperFamicom::Interface);
|
|
|
|
emulators.append(new GameBoy::Interface);
|
|
|
|
emulators.append(new GameBoyAdvance::Interface);
|
|
|
|
for(auto& emulator : emulators) emulator->bind = this;
|
|
|
|
|
2015-03-02 09:13:28 +00:00
|
|
|
new InputManager;
|
2015-02-28 01:51:53 +00:00
|
|
|
new LibraryManager;
|
2015-03-02 09:13:28 +00:00
|
|
|
new SettingsManager;
|
2015-02-28 01:51:53 +00:00
|
|
|
new Presentation;
|
|
|
|
|
|
|
|
presentation->setVisible();
|
|
|
|
|
|
|
|
video.driver("XShm");
|
|
|
|
video.set(Video::Handle, presentation->viewport.handle());
|
|
|
|
video.set(Video::Synchronize, false);
|
|
|
|
if(!video.init()) { video.driver("None"); video.init(); }
|
|
|
|
|
|
|
|
audio.driver("OpenAL");
|
|
|
|
audio.set(Audio::Handle, presentation->viewport.handle());
|
|
|
|
audio.set(Audio::Synchronize, false);
|
|
|
|
audio.set(Audio::Frequency, 96000u);
|
|
|
|
audio.set(Audio::Latency, 80u);
|
|
|
|
if(!audio.init()) { audio.driver("None"); audio.init(); }
|
|
|
|
|
2015-03-02 09:13:28 +00:00
|
|
|
input.driver("Xlib");
|
2015-02-28 01:51:53 +00:00
|
|
|
input.set(Input::Handle, presentation->viewport.handle());
|
|
|
|
if(!input.init()) { input.driver("None"); input.init(); }
|
|
|
|
|
|
|
|
dsp.setPrecision(16);
|
|
|
|
dsp.setBalance(0.0);
|
|
|
|
dsp.setVolume(1.0);
|
|
|
|
dsp.setFrequency(32040);
|
|
|
|
dsp.setResampler(DSP::ResampleEngine::Sinc);
|
|
|
|
dsp.setResamplerFrequency(96000);
|
|
|
|
|
2015-03-02 09:13:28 +00:00
|
|
|
drawSplashScreen();
|
2015-02-28 01:51:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
auto Program::emulator() -> Emulator::Interface& {
|
|
|
|
if(activeEmulator == nullptr) throw;
|
|
|
|
return *activeEmulator;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Program::main() -> void {
|
2015-03-02 09:13:28 +00:00
|
|
|
inputManager->poll();
|
|
|
|
|
2015-02-28 01:51:53 +00:00
|
|
|
if(activeEmulator == nullptr || emulator().loaded() == false) {
|
|
|
|
audio.clear();
|
|
|
|
usleep(20 * 1000);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
emulator().run();
|
|
|
|
}
|
|
|
|
|
2015-03-02 09:13:28 +00:00
|
|
|
auto Program::quit() -> void {
|
|
|
|
unloadMedia();
|
|
|
|
inputManager->quit();
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Program::setEmulator(Emulator::Interface* emulator) -> void {
|
|
|
|
activeEmulator = emulator;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Program::drawSplashScreen() -> void {
|
|
|
|
image emblem{string{userpath(), ".local/share/icons/tomoko.png"}};
|
|
|
|
emblem.alphaBlend(0x000000);
|
|
|
|
emblem.scale(128, 128);
|
|
|
|
|
|
|
|
uint32* output;
|
|
|
|
unsigned length;
|
|
|
|
if(video.lock(output, length, 512, 480)) {
|
|
|
|
for(auto y : range(480)) {
|
|
|
|
uint32* dp = output + y * (length >> 2);
|
|
|
|
for(auto x : range(640)) *dp++ = 0xff000000;
|
|
|
|
}
|
|
|
|
unsigned z = 0;
|
|
|
|
for(auto y : range(emblem.height)) {
|
|
|
|
uint32* dp = output + (480 - emblem.height + y - 8) * (length >> 2) + (512 - emblem.width - 8);
|
|
|
|
for(auto x : range(emblem.width)) {
|
|
|
|
*dp++ = emblem.read(emblem.data + z);
|
|
|
|
z += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
video.unlock();
|
|
|
|
video.refresh();
|
|
|
|
}
|
2015-02-28 01:51:53 +00:00
|
|
|
}
|