mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-08-21 00:11:30 +02:00
Update to v094r09 release.
byuu says: This will easily be the biggest diff in the history of higan. And not in a good way. * target-higan and target-loki have been blown away completely * nall and ruby massively updated * phoenix replaced with hiro (pretty near a total rewrite) * target-higan restarted using hiro (just a window for now) * all emulation cores updated to compile again * installation changed to not require root privileges (installs locally) For the foreseeable future (maybe even permanently?), the new higan UI will only build under Linux/BSD with GTK+ 2.20+. Probably the most likely route for Windows/OS X will be to try and figure out how to build hiro/GTK on those platforms, as awful as that would be. The other alternative would be to produce new UIs for those platforms ... which would actually be a good opportunity to make something much more user friendly. Being that I just started on this a few hours ago, that means that for at least a few weeks, don't expect to be able to actually play any games. Right now, you can pretty much just compile the binary and that's it. It's quite possible that some nall changes didn't produce compilation errors, but will produce runtime errors. So until the UI can actually load games, we won't know if anything is broken. But we should mostly be okay. It was mostly just trim<1> -> trim changes, moving to Hash::SHA256 (much cleaner), and patching some reckless memory copy functions enough to compile. Progress isn't going to be like it was before: I'm now dividing my time much thinner between studying and other hobbies. My aim this time is not to produce a binary for everyone to play games on. Rather, it's to keep the emulator alive. I want to be able to apply critical patches again. And I would also like the base of the emulator to live on, for use in other emulator frontends that utilize higan.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include <ruby/ruby.hpp>
|
||||
|
||||
#undef deprecated
|
||||
#undef mkdir
|
||||
#undef usleep
|
||||
#include <ruby/implementation.cpp>
|
||||
|
@@ -1,8 +1,11 @@
|
||||
/*
|
||||
ruby
|
||||
version: 0.11 (2013-12-19)
|
||||
license: public domain
|
||||
*/
|
||||
/* ruby
|
||||
* author: byuu
|
||||
* license: ISC
|
||||
* version: 0.11 (2013-12-19)
|
||||
*
|
||||
* ruby is a cross-platform hardware abstraction layer
|
||||
* it provides a common interface to video, audio and input devices
|
||||
*/
|
||||
|
||||
#ifndef RUBY_H
|
||||
#define RUBY_H
|
||||
|
@@ -28,11 +28,11 @@ void OpenGL::shader(const char* pathname) {
|
||||
for(auto& node : document["output"]) {
|
||||
string text = node.text();
|
||||
if(node.name == "width") {
|
||||
if(text.endsWith("%")) relativeWidth = real(text.rtrim<1>("%")) / 100.0;
|
||||
if(text.endsWith("%")) relativeWidth = real(text.rtrim("%")) / 100.0;
|
||||
else absoluteWidth = decimal(text);
|
||||
}
|
||||
if(node.name == "height") {
|
||||
if(text.endsWith("%")) relativeHeight = real(text.rtrim<1>("%")) / 100.0;
|
||||
if(text.endsWith("%")) relativeHeight = real(text.rtrim("%")) / 100.0;
|
||||
else absoluteHeight = decimal(text);
|
||||
}
|
||||
}
|
||||
|
@@ -4,9 +4,9 @@ void OpenGLProgram::bind(OpenGL* instance, const Markup::Node& node, const strin
|
||||
modulo = glrModulo(node["modulo"].integer());
|
||||
|
||||
string w = node["width"].text(), h = node["height"].text();
|
||||
if(w.endsWith("%")) relativeWidth = real(w.rtrim<1>("%")) / 100.0;
|
||||
if(w.endsWith("%")) relativeWidth = real(w.rtrim("%")) / 100.0;
|
||||
else absoluteWidth = decimal(w);
|
||||
if(h.endsWith("%")) relativeHeight = real(h.rtrim<1>("%")) / 100.0;
|
||||
if(h.endsWith("%")) relativeHeight = real(h.rtrim("%")) / 100.0;
|
||||
else absoluteHeight = decimal(h);
|
||||
|
||||
format = glrFormat(node["format"].text());
|
||||
@@ -78,7 +78,7 @@ void OpenGLProgram::parse(OpenGL* instance, string& source) {
|
||||
if(auto position = s.find("//")) s.resize(position()); //strip comments
|
||||
s.strip(); //remove extraneous whitespace
|
||||
if(s.match("#in ?*")) {
|
||||
s.ltrim<1>("#in ").strip();
|
||||
s.ltrim("#in ").strip();
|
||||
if(auto setting = instance->settings.find({s})) {
|
||||
line = {"#define ", setting().name, " ", setting().value};
|
||||
} else {
|
||||
|
@@ -109,6 +109,7 @@ struct pVideoSDL {
|
||||
bool init() {
|
||||
display = XOpenDisplay(0);
|
||||
|
||||
//todo: this causes a segfault inside SDL_SetVideoMode on FreeBSD (works under Linux)
|
||||
char env[512];
|
||||
sprintf(env, "SDL_WINDOWID=%ld", (long int)settings.handle);
|
||||
putenv(env);
|
||||
|
@@ -1,3 +1,10 @@
|
||||
//XShm driver for Xorg
|
||||
|
||||
//Note that on composited displays, the alpha bits will allow translucency underneath the active window
|
||||
//As this is not a feature of ruby, this driver must always set the alpha bits on clear() and refresh()
|
||||
|
||||
//Linear interpolation is only applied horizontally for performance reasons, although Nearest is still much faster
|
||||
|
||||
#include <sys/shm.h>
|
||||
#include <X11/extensions/XShm.h>
|
||||
|
||||
@@ -18,30 +25,22 @@ struct pVideoXShm {
|
||||
} device;
|
||||
|
||||
struct Settings {
|
||||
uintptr_t handle;
|
||||
unsigned depth = 24;
|
||||
uintptr_t handle = 0;
|
||||
unsigned filter = Video::FilterLinear;
|
||||
|
||||
uint32_t* buffer = nullptr;
|
||||
unsigned width, height;
|
||||
} settings;
|
||||
|
||||
struct Color {
|
||||
unsigned depth;
|
||||
unsigned shift;
|
||||
|
||||
unsigned idepth;
|
||||
unsigned ishift;
|
||||
} red, green, blue;
|
||||
|
||||
bool cap(const string& name) {
|
||||
if(name == Video::Handle) return true;
|
||||
if(name == Video::Depth) return true;
|
||||
if(name == Video::Filter) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
any get(const string& name) {
|
||||
if(name == Video::Handle) return settings.handle;
|
||||
if(name == Video::Depth) return settings.depth;
|
||||
if(name == Video::Filter) return settings.filter;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -50,8 +49,9 @@ struct pVideoXShm {
|
||||
settings.handle = any_cast<uintptr_t>(value);
|
||||
return true;
|
||||
}
|
||||
if(name == Video::Depth) {
|
||||
return setDepth(any_cast<unsigned>(value));
|
||||
if(name == Video::Filter) {
|
||||
settings.filter = any_cast<unsigned>(value);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -60,7 +60,7 @@ struct pVideoXShm {
|
||||
if(settings.buffer == nullptr || settings.width != width || settings.height != height) {
|
||||
if(settings.buffer) delete[] settings.buffer;
|
||||
settings.width = width, settings.height = height;
|
||||
settings.buffer = new uint32_t[width * height]();
|
||||
settings.buffer = new uint32_t[width * height + 16]; //+16 is padding for linear interpolation
|
||||
}
|
||||
|
||||
data = settings.buffer;
|
||||
@@ -73,7 +73,9 @@ struct pVideoXShm {
|
||||
|
||||
void clear() {
|
||||
if(settings.buffer == nullptr) return;
|
||||
memset(settings.buffer, 0, settings.width * settings.height * sizeof(uint32_t));
|
||||
uint32_t* dp = settings.buffer;
|
||||
unsigned length = settings.width * settings.height;
|
||||
while(length--) *dp++ = (255u << 24);
|
||||
refresh();
|
||||
}
|
||||
|
||||
@@ -81,23 +83,27 @@ struct pVideoXShm {
|
||||
if(settings.buffer == nullptr) return;
|
||||
size();
|
||||
|
||||
float xRatio = (float)settings.width / (float)device.width;
|
||||
float yRatio = (float)settings.height / (float)device.height;
|
||||
float yStep = 0;
|
||||
float xratio = (float)settings.width / (float)device.width;
|
||||
float yratio = (float)settings.height / (float)device.height;
|
||||
|
||||
#pragma omp parallel for
|
||||
for(unsigned y = 0; y < device.height; y++) {
|
||||
uint32_t* sp = settings.buffer + (unsigned)yStep * settings.width;
|
||||
float ystep = y * yratio;
|
||||
float xstep = 0;
|
||||
|
||||
uint32_t* sp = settings.buffer + (unsigned)ystep * settings.width;
|
||||
uint32_t* dp = device.buffer + y * device.width;
|
||||
yStep += yRatio;
|
||||
float xStep = 0;
|
||||
for(unsigned x = 0; x < device.width; x++) {
|
||||
uint32_t color = sp[(unsigned)xStep];
|
||||
xStep += xRatio;
|
||||
unsigned r = (color >> red.ishift ) & ((1 << red.idepth ) - 1);
|
||||
unsigned g = (color >> green.ishift) & ((1 << green.idepth) - 1);
|
||||
unsigned b = (color >> blue.ishift ) & ((1 << blue.idepth ) - 1);
|
||||
*dp++ = image::normalize(r, red.idepth, red.depth ) << red.shift
|
||||
| image::normalize(g, green.idepth, green.depth) << green.shift
|
||||
| image::normalize(b, blue.idepth, blue.depth ) << blue.shift;
|
||||
|
||||
if(settings.filter == Video::FilterNearest) {
|
||||
for(unsigned x = 0; x < device.width; x++) {
|
||||
*dp++ = (255u << 24) | sp[(unsigned)xstep];
|
||||
xstep += xratio;
|
||||
}
|
||||
} else { //settings.filter == Video::FilterLinear
|
||||
for(unsigned x = 0; x < device.width; x++) {
|
||||
*dp++ = (255u << 24) | interpolate(xstep - (unsigned)xstep, sp[(unsigned)xstep], sp[(unsigned)xstep + 1]);
|
||||
xstep += xratio;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,24 +124,12 @@ struct pVideoXShm {
|
||||
XGetWindowAttributes(device.display, (Window)settings.handle, &getAttributes);
|
||||
device.depth = getAttributes.depth;
|
||||
device.visual = getAttributes.visual;
|
||||
unsigned visualID = XVisualIDFromVisual(device.visual);
|
||||
|
||||
XVisualInfo visualTemplate = {0};
|
||||
visualTemplate.screen = device.screen;
|
||||
visualTemplate.depth = device.depth;
|
||||
int visualsMatched = 0;
|
||||
XVisualInfo* visualList = XGetVisualInfo(device.display, VisualScreenMask | VisualDepthMask, &visualTemplate, &visualsMatched);
|
||||
for(unsigned n = 0; n < visualsMatched; n++) {
|
||||
auto& v = visualList[n];
|
||||
if(v.visualid == visualID) {
|
||||
red.depth = bit::count(v.red_mask), red.shift = bit::first(v.red_mask);
|
||||
green.depth = bit::count(v.green_mask), green.shift = bit::first(v.green_mask);
|
||||
blue.depth = bit::count(v.blue_mask), blue.shift = bit::first(v.blue_mask);
|
||||
break;
|
||||
}
|
||||
//driver only supports 32-bit pixels
|
||||
//note that even on 15-bit and 16-bit displays, the window visual's depth should be 32
|
||||
if(device.depth < 24 || device.depth > 32) {
|
||||
free();
|
||||
return false;
|
||||
}
|
||||
XFree(visualList);
|
||||
setDepth(settings.depth);
|
||||
|
||||
XSetWindowAttributes setAttributes = {0};
|
||||
setAttributes.border_pixel = 0;
|
||||
@@ -168,26 +162,6 @@ struct pVideoXShm {
|
||||
}
|
||||
|
||||
//internal:
|
||||
bool setDepth(unsigned depth) {
|
||||
if(depth == 24) {
|
||||
settings.depth = 24;
|
||||
red.idepth = 8, red.ishift = 16;
|
||||
green.idepth = 8, green.ishift = 8;
|
||||
blue.idepth = 8, blue.ishift = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
if(depth == 30) {
|
||||
settings.depth = 30;
|
||||
red.idepth = 10, red.ishift = 20;
|
||||
green.idepth = 10, green.ishift = 10;
|
||||
blue.idepth = 10, blue.ishift = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool size() {
|
||||
XWindowAttributes windowAttributes;
|
||||
XGetWindowAttributes(device.display, settings.handle, &windowAttributes);
|
||||
@@ -197,7 +171,6 @@ struct pVideoXShm {
|
||||
XResizeWindow(device.display, device.window, device.width, device.height);
|
||||
free();
|
||||
|
||||
//create
|
||||
device.shmInfo.shmid = shmget(IPC_PRIVATE, device.width * device.height * sizeof(uint32_t), IPC_CREAT | 0777);
|
||||
if(device.shmInfo.shmid < 0) return false;
|
||||
|
||||
@@ -220,6 +193,15 @@ struct pVideoXShm {
|
||||
shmdt(device.shmInfo.shmaddr);
|
||||
shmctl(device.shmInfo.shmid, IPC_RMID, 0);
|
||||
}
|
||||
|
||||
alwaysinline uint32_t interpolate(float mu, uint32_t a, uint32_t b) {
|
||||
uint8_t ar = (a >> 16), ag = (a >> 8), ab = (a >> 0);
|
||||
uint8_t br = (b >> 16), bg = (b >> 8), bb = (b >> 0);
|
||||
uint8_t cr = ar * (1.0 - mu) + br * mu;
|
||||
uint8_t cg = ag * (1.0 - mu) + bg * mu;
|
||||
uint8_t cb = ab * (1.0 - mu) + bb * mu;
|
||||
return (cr << 16) | (cg << 8) | (cb << 0);
|
||||
}
|
||||
};
|
||||
|
||||
DeclareVideo(XShm)
|
||||
|
Reference in New Issue
Block a user