bsnes/libco/sjlj.c

100 lines
2.2 KiB
C
Raw Normal View History

/*
note this was designed for UNIX systems. Based on ideas expressed in a paper by Ralf Engelschall.
for SJLJ on other systems, one would want to rewrite springboard() and co_create() and hack the jmb_buf stack pointer.
*/
#define LIBCO_C
#include "libco.h"
#include "settings.h"
Update to v103r21 release. byuu says: Changelog: - gb: added TAMA emulation [thanks to endrift for the initial notes] - gb: save RTC memory to disk (MBC3 doesn't write to said memory yet; TAMA doesn't emulate it yet) - gb: expect MMM01 boot loader to be at end of ROM instead of start - gb: store MBC2 save RAM as 256-bytes (512x4-bit) instead of 512-bytes (with padding) - gb: major cleanups to every cartridge mapper; moved to Mapper class instead of MMIO class - gb: don't serialize all mapper states with every save state; only serialize the active mapper - gb: serialize RAM even if a battery isn't present¹ - gb/cartridge: removed unnecessary code; refactored other code to eliminate duplication of functions - icarus: improve GB(C) heuristics generation to not include filenames for cartridges without battery backup - icarus: remove incorrect rearrangement of MMM01 ROM data - md/vdp: fix CRAM reads -- fixes Sonic Spinball colors [hex\_usr] - tomoko: hide the main higan window when entering fullscreen exclusive mode; helps with multi-monitor setups - tomoko: destroy ruby drivers before calling Application::quit() [Screwtape] - libco: add settings.h and defines to fiber, ucontext [Screwtape] ¹: this is one of those crystal clear indications that nobody's actually playing the higan DMG/CGB cores, or at least not with save states. This was a major mistake. Note: I can't find any official documentation that `GL_ALPHA_TEST` was removed from OpenGL 3.2. Since it's not hurting anything except showing some warnings in debug mode, I'm just going to leave it there for now.
2017-07-26 12:42:06 +00:00
#define _BSD_SOURCE
Update to v103r19 release. byuu says: Changelog: - tomoko: Application::onMain assigned at end of Program::Program() [Screwtape]¹ - libco: add `#define _XOPEN_SOURCE 500` to fix compilation of sjlj.c [Screwtape] - ruby/audio/openal: fixed device driver string list enumeration - ruby/audio/wasapi: changing device re-initializes the driver now - ruby/audio/wasapi: probably a pointless change, but don't fill the buffer beyond the queue size with silence - ruby/video/xvideo: renamed from ruby/video/xv - ruby/video/xvideo: check to see if `XV_AUTOPAINT_COLORKEY` exists before setting it [SuperMikeMan] - ruby/video/xvideo: align buffer sizes to be evenly divisible by four [SuperMikeMan] - ruby/video/xvideo: fail nicely without crashing (hopefully) - ruby/video/xvideo: add support for YV12 and I420 12-bit planar YUV formats² ¹: prevents crashes when drivers fail to initialize from running the main loop that polls input drivers before the input driver is initialized (or fails to initialize itself.) Some drivers still don't block their main functions when initialization fails, so they will still crash, but I'll work to fix them. ²: this was a **major** pain in the ass, heh. You only get one chroma sample for every four luma samples, so the color reproduction is even worse than UYVY and YUYV (which is two to four chroma to luma.) Further, the planar format took forever to figure out. Apparently it doesn't care what portion of the image you specify in XvShmPutImage, it expects you to use the buffer dimensions to locate the U and V portions of the data. This is probably the most thorough X-Video driver in existence now. Notes: - forgot to rename the configuration settings dialog window title to just "Settings"
2017-07-23 09:18:16 +00:00
#define _XOPEN_SOURCE 500
#include <stdlib.h>
#include <signal.h>
#include <setjmp.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
sigjmp_buf context;
void (*coentry)(void);
void* stack;
} cothread_struct;
static thread_local cothread_struct co_primary;
static thread_local cothread_struct* creating;
static thread_local cothread_struct* co_running = 0;
static void springboard(int ignored) {
if(sigsetjmp(creating->context, 0)) {
co_running->coentry();
}
}
cothread_t co_active() {
if(!co_running) co_running = &co_primary;
return (cothread_t)co_running;
}
cothread_t co_create(unsigned int size, void (*coentry)(void)) {
if(!co_running) co_running = &co_primary;
cothread_struct *thread = (cothread_struct*)malloc(sizeof(cothread_struct));
if(thread) {
struct sigaction handler;
struct sigaction old_handler;
stack_t stack;
stack_t old_stack;
thread->coentry = thread->stack = 0;
stack.ss_flags = 0;
stack.ss_size = size;
thread->stack = stack.ss_sp = malloc(size);
if(stack.ss_sp && !sigaltstack(&stack, &old_stack)) {
handler.sa_handler = springboard;
handler.sa_flags = SA_ONSTACK;
sigemptyset(&handler.sa_mask);
creating = thread;
if(!sigaction(SIGUSR1, &handler, &old_handler)) {
if(!raise(SIGUSR1)) {
thread->coentry = coentry;
}
sigaltstack(&old_stack, 0);
sigaction(SIGUSR1, &old_handler, 0);
}
}
if(thread->coentry != coentry) {
co_delete(thread);
thread = 0;
}
}
return (cothread_t)thread;
}
void co_delete(cothread_t cothread) {
if(cothread) {
if(((cothread_struct*)cothread)->stack) {
free(((cothread_struct*)cothread)->stack);
}
free(cothread);
}
}
void co_switch(cothread_t cothread) {
if(!sigsetjmp(co_running->context, 0)) {
co_running = (cothread_struct*)cothread;
siglongjmp(co_running->context, 1);
}
}
#ifdef __cplusplus
}
#endif