mirror of
https://github.com/libretro/bsnes-libretro.git
synced 2024-11-23 00:49:40 +00:00
PoC
This commit is contained in:
parent
26c583e1c5
commit
d308fe5507
@ -30,6 +30,7 @@ SOURCES_C += $(CORE_DIR)/libco/libco.c \
|
||||
$(GB_DIR)/Core/timing.c \
|
||||
|
||||
SOURCES_CXX += \
|
||||
$(BSNES_DIR)/target-libretro/program.cpp \
|
||||
$(BSNES_DIR)/target-libretro/libretro.cpp \
|
||||
$(BSNES_DIR)/emulator/emulator.cpp \
|
||||
$(BSNES_DIR)/filter/filter.cpp \
|
||||
|
@ -1,14 +1,22 @@
|
||||
#include <cassert>
|
||||
#include "libretro.h"
|
||||
#include "libretro_core_options.h"
|
||||
#include <emulator/emulator.hpp>
|
||||
#include <sfc/interface/interface.hpp>
|
||||
#include "program.h"
|
||||
|
||||
static retro_environment_t environ_cb;
|
||||
static retro_video_refresh_t video_cb;
|
||||
static retro_audio_sample_t audio_cb;
|
||||
static retro_audio_sample_batch_t audio_batch_cb;
|
||||
static retro_input_poll_t input_poll;
|
||||
static retro_input_state_t input_state;
|
||||
static retro_log_printf_t libretro_print;
|
||||
retro_environment_t environ_cb;
|
||||
retro_video_refresh_t video_cb;
|
||||
retro_audio_sample_t audio_cb;
|
||||
retro_audio_sample_batch_t audio_batch_cb;
|
||||
retro_input_poll_t input_poll;
|
||||
retro_input_state_t input_state;
|
||||
retro_log_printf_t libretro_print;
|
||||
|
||||
struct Program *program = nullptr;
|
||||
bool sgb_border_disabled = false;
|
||||
bool retro_pointer_enabled = false;
|
||||
bool retro_pointer_superscope_reverse_buttons = false;
|
||||
|
||||
#define SAMPLERATE 48000
|
||||
#define AUDIOBUFSIZE (SAMPLERATE/50) * 2
|
||||
@ -18,7 +26,7 @@ static uint16_t audio_buffer_max = AUDIOBUFSIZE;
|
||||
|
||||
static int run_ahead_frames = 0;
|
||||
|
||||
static void audio_queue(int16_t left, int16_t right)
|
||||
void audio_queue(int16_t left, int16_t right)
|
||||
{
|
||||
audio_buffer[audio_buffer_index++] = left;
|
||||
audio_buffer[audio_buffer_index++] = right;
|
||||
@ -30,7 +38,7 @@ static void audio_queue(int16_t left, int16_t right)
|
||||
}
|
||||
}
|
||||
|
||||
#include "program.cpp"
|
||||
static unique_pointer<Emulator::Interface> emulator;
|
||||
|
||||
static string sgb_bios;
|
||||
static vector<string> cheatList;
|
||||
@ -597,12 +605,13 @@ void retro_set_input_state(retro_input_state_t cb)
|
||||
void retro_init()
|
||||
{
|
||||
emulator = new SuperFamicom::Interface;
|
||||
program = new Program;
|
||||
program = new Program(emulator.data());
|
||||
}
|
||||
|
||||
void retro_deinit()
|
||||
{
|
||||
delete program;
|
||||
emulator.reset();
|
||||
}
|
||||
|
||||
unsigned retro_api_version()
|
||||
|
@ -17,14 +17,27 @@ using namespace nall;
|
||||
#include <heuristics/game-boy.cpp>
|
||||
#include <heuristics/bs-memory.cpp>
|
||||
|
||||
#include "resources.hpp"
|
||||
#include "program.h"
|
||||
|
||||
#include "libretro.h"
|
||||
extern retro_environment_t environ_cb;
|
||||
extern retro_video_refresh_t video_cb;
|
||||
extern retro_audio_sample_t audio_cb;
|
||||
extern retro_audio_sample_batch_t audio_batch_cb;
|
||||
extern retro_input_poll_t input_poll;
|
||||
extern retro_input_state_t input_state;
|
||||
extern retro_log_printf_t libretro_print;
|
||||
extern void audio_queue(int16_t left, int16_t right);
|
||||
|
||||
#define RETRO_DEVICE_LIGHTGUN_SUPER_SCOPE RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_LIGHTGUN, 0)
|
||||
|
||||
static Emulator::Interface *emulator;
|
||||
struct Program;
|
||||
static Program *program = nullptr;
|
||||
|
||||
static bool sgb_border_disabled = false;
|
||||
extern bool sgb_border_disabled;
|
||||
extern bool retro_pointer_enabled;
|
||||
extern bool retro_pointer_superscope_reverse_buttons;
|
||||
|
||||
// Touchscreen Lightgun Support
|
||||
static const int POINTER_PRESSED_CYCLES = 4; // For touchscreen sensitivity
|
||||
@ -44,8 +57,6 @@ struct retro_pointer_state
|
||||
};
|
||||
|
||||
static retro_pointer_state retro_pointer = { 0, 0, false, false, false, false };
|
||||
static bool retro_pointer_enabled = false;
|
||||
static bool retro_pointer_superscope_reverse_buttons = false;
|
||||
static void input_update_pointer_lightgun( unsigned port, unsigned gun_device)
|
||||
{
|
||||
int x, y;
|
||||
@ -166,76 +177,16 @@ static int input_handle_touchscreen_lightgun( unsigned port, unsigned gun_device
|
||||
}
|
||||
}
|
||||
|
||||
struct Program : Emulator::Platform
|
||||
{
|
||||
Program();
|
||||
~Program();
|
||||
|
||||
auto open(uint id, string name, vfs::file::mode mode, bool required) -> shared_pointer<vfs::file> override;
|
||||
auto load(uint id, string name, string type, vector<string> options = {}) -> Emulator::Platform::Load override;
|
||||
auto videoFrame(const uint16* data, uint pitch, uint width, uint height, uint scale) -> void override;
|
||||
auto audioFrame(const double* samples, uint channels) -> void override;
|
||||
auto inputPoll(uint port, uint device, uint input) -> int16 override;
|
||||
auto inputRumble(uint port, uint device, uint input, bool enable) -> void override;
|
||||
|
||||
auto load() -> void;
|
||||
auto loadFile(string location) -> vector<uint8_t>;
|
||||
auto loadSuperFamicom(string location) -> bool;
|
||||
auto loadGameBoy(string location) -> bool;
|
||||
auto loadBSMemory(string location) -> bool;
|
||||
|
||||
auto save() -> void;
|
||||
|
||||
auto openRomSuperFamicom(string name, vfs::file::mode mode) -> shared_pointer<vfs::file>;
|
||||
auto openRomGameBoy(string name, vfs::file::mode mode) -> shared_pointer<vfs::file>;
|
||||
auto openRomBSMemory(string name, vfs::file::mode mode) -> shared_pointer<vfs::file>;
|
||||
|
||||
auto hackPatchMemory(vector<uint8_t>& data) -> void;
|
||||
|
||||
string base_name;
|
||||
|
||||
bool overscan = false;
|
||||
|
||||
public:
|
||||
struct Game {
|
||||
explicit operator bool() const { return (bool)location; }
|
||||
|
||||
string option;
|
||||
string location;
|
||||
string manifest;
|
||||
Markup::Node document;
|
||||
boolean patched;
|
||||
boolean verified;
|
||||
};
|
||||
|
||||
struct SuperFamicom : Game {
|
||||
string title;
|
||||
string region;
|
||||
vector<uint8_t> program;
|
||||
vector<uint8_t> data;
|
||||
vector<uint8_t> expansion;
|
||||
vector<uint8_t> firmware;
|
||||
} superFamicom;
|
||||
|
||||
struct GameBoy : Game {
|
||||
vector<uint8_t> program;
|
||||
} gameBoy;
|
||||
|
||||
struct BSMemory : Game {
|
||||
vector<uint8_t> program;
|
||||
} bsMemory;
|
||||
};
|
||||
|
||||
static Program *program = nullptr;
|
||||
|
||||
Program::Program()
|
||||
|
||||
Program::Program(Emulator::Interface * emu)
|
||||
{
|
||||
program = this;
|
||||
emulator = emu;
|
||||
Emulator::platform = this;
|
||||
}
|
||||
|
||||
Program::~Program()
|
||||
{
|
||||
delete emulator;
|
||||
}
|
||||
|
||||
auto Program::save() -> void
|
||||
|
72
bsnes/target-libretro/program.h
Normal file
72
bsnes/target-libretro/program.h
Normal file
@ -0,0 +1,72 @@
|
||||
#pragma once
|
||||
#include <emulator/emulator.hpp>
|
||||
#include <filter/filter.hpp>
|
||||
#include <lzma/lzma.hpp>
|
||||
#include <nall/directory.hpp>
|
||||
#include <nall/instance.hpp>
|
||||
#include <nall/decode/rle.hpp>
|
||||
#include <nall/decode/zip.hpp>
|
||||
#include <nall/encode/rle.hpp>
|
||||
#include <nall/encode/zip.hpp>
|
||||
#include <nall/hash/crc16.hpp>
|
||||
#include "resources.hpp"
|
||||
|
||||
struct Program : Emulator::Platform
|
||||
{
|
||||
Program(Emulator::Interface * emu);
|
||||
~Program();
|
||||
|
||||
auto open(uint id, string name, vfs::file::mode mode, bool required) -> shared_pointer<vfs::file> override;
|
||||
auto load(uint id, string name, string type, vector<string> options = {}) -> Emulator::Platform::Load override;
|
||||
auto videoFrame(const uint16* data, uint pitch, uint width, uint height, uint scale) -> void override;
|
||||
auto audioFrame(const double* samples, uint channels) -> void override;
|
||||
auto inputPoll(uint port, uint device, uint input) -> int16 override;
|
||||
auto inputRumble(uint port, uint device, uint input, bool enable) -> void override;
|
||||
|
||||
auto load() -> void;
|
||||
auto loadFile(string location) -> vector<uint8_t>;
|
||||
auto loadSuperFamicom(string location) -> bool;
|
||||
auto loadGameBoy(string location) -> bool;
|
||||
auto loadBSMemory(string location) -> bool;
|
||||
|
||||
auto save() -> void;
|
||||
|
||||
auto openRomSuperFamicom(string name, vfs::file::mode mode) -> shared_pointer<vfs::file>;
|
||||
auto openRomGameBoy(string name, vfs::file::mode mode) -> shared_pointer<vfs::file>;
|
||||
auto openRomBSMemory(string name, vfs::file::mode mode) -> shared_pointer<vfs::file>;
|
||||
|
||||
auto hackPatchMemory(vector<uint8_t>& data) -> void;
|
||||
|
||||
string base_name;
|
||||
|
||||
bool overscan = false;
|
||||
|
||||
public:
|
||||
struct Game {
|
||||
explicit operator bool() const { return (bool)location; }
|
||||
|
||||
string option;
|
||||
string location;
|
||||
string manifest;
|
||||
Markup::Node document;
|
||||
boolean patched;
|
||||
boolean verified;
|
||||
};
|
||||
|
||||
struct SuperFamicom : Game {
|
||||
string title;
|
||||
string region;
|
||||
vector<uint8_t> program;
|
||||
vector<uint8_t> data;
|
||||
vector<uint8_t> expansion;
|
||||
vector<uint8_t> firmware;
|
||||
} superFamicom;
|
||||
|
||||
struct GameBoy : Game {
|
||||
vector<uint8_t> program;
|
||||
} gameBoy;
|
||||
|
||||
struct BSMemory : Game {
|
||||
vector<uint8_t> program;
|
||||
} bsMemory;
|
||||
};
|
Loading…
Reference in New Issue
Block a user