mirror of
https://github.com/libretro/mame2010-libretro.git
synced 2024-11-23 07:50:45 +00:00
remove libco
This commit is contained in:
parent
5576b2a067
commit
60666ce9ae
16
.gitignore
vendored
Normal file
16
.gitignore
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
*~
|
||||
/*
|
||||
!/*/
|
||||
!/.gitattributes
|
||||
!/.gitignore
|
||||
!/makefile
|
||||
!/*.md
|
||||
/cfg
|
||||
/diff
|
||||
/ini
|
||||
/inp
|
||||
/nvram
|
||||
/obj
|
||||
/snap
|
||||
/sta
|
||||
*.so
|
@ -4513,14 +4513,14 @@ $(LIBOBJ)/softfloat/softfloat.o: $(LIBSRC)/softfloat/softfloat.c \
|
||||
|
||||
MINISRC = $(SRC_DIR)/osd/$(OSD)
|
||||
MINIOBJ = $(OBJ)/osd/$(OSD)
|
||||
LIBCOOBJ = $(OBJ)/osd/$(OSD)/libretro-common/libco
|
||||
#LIBCOOBJ = $(OBJ)/osd/$(OSD)/libretro-common/libco
|
||||
ifeq ($(VRENDER),opengl)
|
||||
GLOBJ = $(OBJ)/osd/$(OSD)/glsym
|
||||
OBJDIRS += $(GLOBJ)
|
||||
endif
|
||||
OBJDIRS += $(MINIOBJ) \
|
||||
$(OBJ)/osd/$(OSD)/libretro-common \
|
||||
$(OBJ)/osd/$(OSD)/libretro-common/libco
|
||||
# $(OBJ)/osd/$(OSD)/libretro-common/libco
|
||||
|
||||
#-------------------------------------------------
|
||||
# OSD core library
|
||||
@ -4537,7 +4537,7 @@ OSDCOREOBJS := \
|
||||
#-------------------------------------------------
|
||||
# OSD mini library
|
||||
#-------------------------------------------------
|
||||
OSDOBJS = $(LIBCOOBJ)/libco.o
|
||||
#OSDOBJS = $(LIBCOOBJ)/libco.o
|
||||
ifeq ($(VRENDER),opengl)
|
||||
OSDOBJS += $(MINIOBJ)/libretro-common/glsym/rglgen.o
|
||||
ifeq ($(GLES), 1)
|
||||
|
@ -101,7 +101,9 @@ static const options_entry cli_options[] =
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
|
||||
#ifdef __LIBRETRO__
|
||||
/*static*/ core_options *retro_global_options;
|
||||
#endif
|
||||
|
||||
/***************************************************************************
|
||||
CORE IMPLEMENTATION
|
||||
@ -172,7 +174,14 @@ int cli_execute(int argc, char **argv, const options_entry *osd_options)
|
||||
}
|
||||
|
||||
/* run the game */
|
||||
result = mame_execute(options);
|
||||
#ifdef __LIBRETRO__
|
||||
retro_global_options=options;
|
||||
result = mame_execute(retro_global_options);
|
||||
goto retro_exit;
|
||||
|
||||
#else
|
||||
result = mame_execute(options);
|
||||
#endif
|
||||
}
|
||||
catch (emu_fatalerror &fatal)
|
||||
{
|
||||
@ -201,9 +210,24 @@ error:
|
||||
/* report any unfreed memory */
|
||||
dump_unfreed_mem();
|
||||
return result;
|
||||
#ifdef __LIBRETRO__
|
||||
retro_exit:
|
||||
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __LIBRETRO__
|
||||
|
||||
void retro_execute(){
|
||||
mame_execute(retro_global_options);
|
||||
}
|
||||
|
||||
void free_opt(){
|
||||
if (retro_global_options != NULL)options_free(retro_global_options );
|
||||
dump_unfreed_mem();
|
||||
}
|
||||
#endif
|
||||
/*-------------------------------------------------
|
||||
help_output - output callback for printing
|
||||
requested help information
|
||||
|
@ -401,7 +401,9 @@ int running_machine::run(bool firstrun)
|
||||
while ((!m_hard_reset_pending && !m_exit_pending) || m_saveload_schedule != SLS_NONE)
|
||||
{
|
||||
profiler_mark_start(PROFILER_EXTRA);
|
||||
|
||||
#ifdef __LIBRETRO__
|
||||
return 0;
|
||||
#endif
|
||||
// execute CPUs if not paused
|
||||
if (!m_paused)
|
||||
m_scheduler.timeslice();
|
||||
@ -435,6 +437,66 @@ int running_machine::run(bool firstrun)
|
||||
}
|
||||
|
||||
|
||||
#ifdef __LIBRETRO__
|
||||
void running_machine::retro_machineexit(){
|
||||
// and out via the exit phase
|
||||
m_current_phase = MACHINE_PHASE_EXIT;
|
||||
|
||||
// save the NVRAM and configuration
|
||||
sound_mute(this, true);
|
||||
nvram_save(this);
|
||||
config_save_settings(this);
|
||||
|
||||
// close the logfile
|
||||
if (m_logfile != NULL)
|
||||
mame_fclose(m_logfile);
|
||||
}
|
||||
|
||||
extern int RLOOP;
|
||||
extern int ENDEXEC;
|
||||
|
||||
void running_machine::retro_loop(){
|
||||
|
||||
while (RLOOP==1) {
|
||||
|
||||
// execute CPUs if not paused
|
||||
if (!m_paused)
|
||||
m_scheduler.timeslice();
|
||||
|
||||
// otherwise, just pump video updates through
|
||||
else
|
||||
video_frame_update(this, false);
|
||||
|
||||
// handle save/load
|
||||
if (m_saveload_schedule != SLS_NONE)
|
||||
handle_saveload();
|
||||
|
||||
}
|
||||
|
||||
if( (m_hard_reset_pending || m_exit_pending) && m_saveload_schedule == SLS_NONE){
|
||||
|
||||
// and out via the exit phase
|
||||
m_current_phase = MACHINE_PHASE_EXIT;
|
||||
|
||||
// save the NVRAM and configuration
|
||||
sound_mute(this, true);
|
||||
nvram_save(this);
|
||||
config_save_settings(this);
|
||||
|
||||
// call all exit callbacks registered
|
||||
call_notifiers(MACHINE_NOTIFY_EXIT);
|
||||
|
||||
// close the logfile
|
||||
if (m_logfile != NULL)
|
||||
mame_fclose(m_logfile);
|
||||
|
||||
|
||||
ENDEXEC=1;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//-------------------------------------------------
|
||||
// schedule_exit - schedule a clean exit
|
||||
//-------------------------------------------------
|
||||
|
@ -293,6 +293,10 @@ public:
|
||||
device_scheduler &scheduler() { return m_scheduler; }
|
||||
|
||||
// immediate operations
|
||||
#ifdef __LIBRETRO__
|
||||
void retro_machineexit();
|
||||
void retro_loop();
|
||||
#endif
|
||||
int run(bool firstrun);
|
||||
void pause();
|
||||
void resume();
|
||||
|
@ -144,6 +144,13 @@ int mame_is_valid_machine(running_machine *machine)
|
||||
return (machine != NULL && machine == global_machine);
|
||||
}
|
||||
|
||||
#ifdef __LIBRETRO__
|
||||
static running_machine *retro_global_machine;
|
||||
static const machine_config *retro_global_config;
|
||||
int ENDEXEC=0;
|
||||
static bool firstgame = true;
|
||||
static bool firstrun = true;
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------
|
||||
mame_execute - run the core emulation
|
||||
@ -151,9 +158,10 @@ int mame_is_valid_machine(running_machine *machine)
|
||||
|
||||
int mame_execute(core_options *options)
|
||||
{
|
||||
#ifndef __LIBRETRO__
|
||||
bool firstgame = true;
|
||||
bool firstrun = true;
|
||||
|
||||
#endif
|
||||
// loop across multiple hard resets
|
||||
bool exit_pending = false;
|
||||
int error = MAMERR_NONE;
|
||||
@ -187,7 +195,18 @@ int mame_execute(core_options *options)
|
||||
options_revert(options, OPTION_PRIORITY_INI);
|
||||
mame_parse_ini_files(options, driver);
|
||||
}
|
||||
#ifdef __LIBRETRO__
|
||||
|
||||
retro_global_config= global_alloc(machine_config(driver->machine_config));
|
||||
retro_global_machine= global_alloc(running_machine(*driver, *retro_global_config, *options, started_empty));
|
||||
global_machine = retro_global_machine;
|
||||
|
||||
error = retro_global_machine->run(firstrun);
|
||||
firstrun = false;
|
||||
|
||||
goto retro_handle;
|
||||
|
||||
#else
|
||||
// create the machine configuration
|
||||
const machine_config *config = global_alloc(machine_config(driver->machine_config));
|
||||
|
||||
@ -217,12 +236,76 @@ int mame_execute(core_options *options)
|
||||
|
||||
// reset the options
|
||||
mame_opts = NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
// return an error
|
||||
return error;
|
||||
#ifdef __LIBRETRO__
|
||||
retro_handle:
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __LIBRETRO__
|
||||
extern int RLOOP;
|
||||
extern void retro_loop(running_machine *machine);
|
||||
extern void retro_execute();
|
||||
extern core_options *retro_global_options;
|
||||
|
||||
void retro_main_loop()
|
||||
{
|
||||
retro_global_machine->retro_loop();
|
||||
|
||||
if(ENDEXEC==1){
|
||||
|
||||
// check the state of the machine
|
||||
if (retro_global_machine->new_driver_pending())
|
||||
{
|
||||
options_set_string(retro_global_options, OPTION_GAMENAME, retro_global_machine->new_driver_name(), OPTION_PRIORITY_CMDLINE);
|
||||
firstrun = true;
|
||||
}
|
||||
if (retro_global_machine->exit_pending())
|
||||
;//exit_pending = true;
|
||||
|
||||
// destroy the machine and the config
|
||||
global_free(retro_global_machine);
|
||||
global_free(retro_global_config);
|
||||
global_machine = NULL;
|
||||
|
||||
// reset the options
|
||||
mame_opts = NULL;
|
||||
ENDEXEC=0;
|
||||
retro_execute();
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
device_scheduler * scheduler;
|
||||
scheduler = &(retro_global_machine->scheduler());
|
||||
while (RLOOP==1) {
|
||||
scheduler->timeslice();
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void free_machineconfig(){
|
||||
|
||||
global_free(retro_global_machine);
|
||||
global_free(retro_global_config);
|
||||
global_machine = NULL;
|
||||
}
|
||||
|
||||
extern void free_opt();
|
||||
|
||||
void retro_finish(){
|
||||
|
||||
retro_global_machine->retro_machineexit();
|
||||
free_machineconfig();
|
||||
free_opt();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------
|
||||
mame_options - accesses the options for the
|
||||
|
@ -281,6 +281,10 @@ int ui_display_startup_screens(running_machine *machine, int first_time, int sho
|
||||
int show_gameinfo = !options_get_bool(machine->options(), OPTION_SKIP_GAMEINFO);
|
||||
int show_warnings = !options_get_bool(machine->options(), OPTION_SKIP_WARNINGS);
|
||||
int state;
|
||||
#ifdef __LIBRETRO__
|
||||
//for nonlibco
|
||||
show_gameinfo = show_warnings = show_disclaimer = FALSE;
|
||||
#endif
|
||||
|
||||
/* disable everything if we are using -str for 300 or fewer seconds, or if we're the empty driver,
|
||||
or if we are debugging */
|
||||
|
@ -1,79 +0,0 @@
|
||||
/* Copyright (C) 2010-2016 The RetroArch team
|
||||
*
|
||||
* ---------------------------------------------------------------------------------------
|
||||
* The following license statement only applies to this file (libco.h).
|
||||
* ---------------------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge,
|
||||
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef LIBCO_H
|
||||
#define LIBCO_H
|
||||
|
||||
#include <retro_common_api.h>
|
||||
|
||||
#ifdef LIBCO_C
|
||||
#ifdef LIBCO_MP
|
||||
#define thread_local __thread
|
||||
#else
|
||||
#define thread_local
|
||||
#endif
|
||||
#endif
|
||||
|
||||
RETRO_BEGIN_DECLS
|
||||
|
||||
typedef void* cothread_t;
|
||||
|
||||
/**
|
||||
* co_active:
|
||||
*
|
||||
* Gets the currently active context.
|
||||
*
|
||||
* Returns: active context.
|
||||
**/
|
||||
cothread_t co_active(void);
|
||||
|
||||
/**
|
||||
* co_create:
|
||||
* @int : stack size
|
||||
* @funcptr : thread entry function callback
|
||||
*
|
||||
* Create a co_thread.
|
||||
*
|
||||
* Returns: cothread if successful, otherwise NULL.
|
||||
*/
|
||||
cothread_t co_create(unsigned int, void (*)(void));
|
||||
|
||||
/**
|
||||
* co_delete:
|
||||
* @cothread : cothread object
|
||||
*
|
||||
* Frees a co_thread.
|
||||
*/
|
||||
void co_delete(cothread_t cothread);
|
||||
|
||||
/**
|
||||
* co_switch:
|
||||
* @cothread : cothread object to switch to
|
||||
*
|
||||
* Do a context switch to @cothread.
|
||||
*/
|
||||
void co_switch(cothread_t cothread);
|
||||
|
||||
RETRO_END_DECLS
|
||||
|
||||
/* ifndef LIBCO_H */
|
||||
#endif
|
@ -1,204 +0,0 @@
|
||||
/*
|
||||
libco.amd64 (2009-10-12)
|
||||
author: byuu
|
||||
license: public domain
|
||||
*/
|
||||
|
||||
#define LIBCO_C
|
||||
#include <libco.h>
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if defined(__GNUC__) && !defined(_WIN32) && !defined(__cplusplus)
|
||||
#define CO_USE_INLINE_ASM
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
static thread_local long long co_active_buffer[64];
|
||||
static thread_local cothread_t co_active_handle = 0;
|
||||
#ifndef CO_USE_INLINE_ASM
|
||||
static void (*co_swap)(cothread_t, cothread_t) = 0;
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
/* ABI: Win64 */
|
||||
static unsigned char co_swap_function[] = {
|
||||
0x48, 0x89, 0x22, /* mov [rdx],rsp */
|
||||
0x48, 0x8b, 0x21, /* mov rsp,[rcx] */
|
||||
0x58, /* pop rax */
|
||||
0x48, 0x89, 0x6a, 0x08, /* mov [rdx+0x8],rbp */
|
||||
0x48, 0x89, 0x72, 0x10, /* mov [rdx+0x10],rsi */
|
||||
0x48, 0x89, 0x7a, 0x18, /* mov [rdx+0x18],rdi */
|
||||
0x48, 0x89, 0x5a, 0x20, /* mov [rdx+0x20],rbx */
|
||||
0x4c, 0x89, 0x62, 0x28, /* mov [rdx+0x28],r12 */
|
||||
0x4c, 0x89, 0x6a, 0x30, /* mov [rdx+0x30],r13 */
|
||||
0x4c, 0x89, 0x72, 0x38, /* mov [rdx+0x38],r14 */
|
||||
0x4c, 0x89, 0x7a, 0x40, /* mov [rdx+0x40],r15 */
|
||||
0x48, 0x81, 0xc2, 0x80, 0x00, 0x00, 0x00, /* add rdx,0x80 */
|
||||
0x48, 0x83, 0xe2, 0xf0, /* and rdx,-0x10 */
|
||||
0x0f, 0x29, 0x32, /* movaps [rdx],xmm6 */
|
||||
0x0f, 0x29, 0x7a, 0x10, /* movaps [rdx+0x10],xmm7 */
|
||||
0x44, 0x0f, 0x29, 0x42, 0x20, /* movaps [rdx+0x20],xmm8 */
|
||||
0x44, 0x0f, 0x29, 0x4a, 0x30, /* movaps [rdx+0x30],xmm9 */
|
||||
0x44, 0x0f, 0x29, 0x52, 0x40, /* movaps [rdx+0x40],xmm10 */
|
||||
0x44, 0x0f, 0x29, 0x5a, 0x50, /* movaps [rdx+0x50],xmm11 */
|
||||
0x44, 0x0f, 0x29, 0x62, 0x60, /* movaps [rdx+0x60],xmm12 */
|
||||
0x44, 0x0f, 0x29, 0x6a, 0x70, /* movaps [rdx+0x70],xmm13 */
|
||||
0x44, 0x0f, 0x29, 0xb2, 0x80, 0x00, 0x00, 0x00, /* movaps [rdx+0x80],xmm14 */
|
||||
0x44, 0x0f, 0x29, 0xba, 0x90, 0x00, 0x00, 0x00, /* movaps [rdx+0x90],xmm15 */
|
||||
0x48, 0x8b, 0x69, 0x08, /* mov rbp,[rcx+0x8] */
|
||||
0x48, 0x8b, 0x71, 0x10, /* mov rsi,[rcx+0x10] */
|
||||
0x48, 0x8b, 0x79, 0x18, /* mov rdi,[rcx+0x18] */
|
||||
0x48, 0x8b, 0x59, 0x20, /* mov rbx,[rcx+0x20] */
|
||||
0x4c, 0x8b, 0x61, 0x28, /* mov r12,[rcx+0x28] */
|
||||
0x4c, 0x8b, 0x69, 0x30, /* mov r13,[rcx+0x30] */
|
||||
0x4c, 0x8b, 0x71, 0x38, /* mov r14,[rcx+0x38] */
|
||||
0x4c, 0x8b, 0x79, 0x40, /* mov r15,[rcx+0x40] */
|
||||
0x48, 0x81, 0xc1, 0x80, 0x00, 0x00, 0x00, /* add rcx,0x80 */
|
||||
0x48, 0x83, 0xe1, 0xf0, /* and rcx,-0x10 */
|
||||
0x0f, 0x29, 0x31, /* movaps [rcx],xmm6 */
|
||||
0x0f, 0x29, 0x79, 0x10, /* movaps [rcx+0x10],xmm7 */
|
||||
0x44, 0x0f, 0x29, 0x41, 0x20, /* movaps [rcx+0x20],xmm8 */
|
||||
0x44, 0x0f, 0x29, 0x49, 0x30, /* movaps [rcx+0x30],xmm9 */
|
||||
0x44, 0x0f, 0x29, 0x51, 0x40, /* movaps [rcx+0x40],xmm10 */
|
||||
0x44, 0x0f, 0x29, 0x59, 0x50, /* movaps [rcx+0x50],xmm11 */
|
||||
0x44, 0x0f, 0x29, 0x61, 0x60, /* movaps [rcx+0x60],xmm12 */
|
||||
0x44, 0x0f, 0x29, 0x69, 0x70, /* movaps [rcx+0x70],xmm13 */
|
||||
0x44, 0x0f, 0x29, 0xb1, 0x80, 0x00, 0x00, 0x00, /* movaps [rcx+0x80],xmm14 */
|
||||
0x44, 0x0f, 0x29, 0xb9, 0x90, 0x00, 0x00, 0x00, /* movaps [rcx+0x90],xmm15 */
|
||||
0xff, 0xe0, /* jmp rax */
|
||||
};
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
void co_init(void)
|
||||
{
|
||||
DWORD old_privileges;
|
||||
VirtualProtect(co_swap_function,
|
||||
sizeof(co_swap_function), PAGE_EXECUTE_READWRITE, &old_privileges);
|
||||
}
|
||||
#else
|
||||
/* ABI: SystemV */
|
||||
#ifndef CO_USE_INLINE_ASM
|
||||
static unsigned char co_swap_function[] = {
|
||||
0x48, 0x89, 0x26, /* mov [rsi],rsp */
|
||||
0x48, 0x8b, 0x27, /* mov rsp,[rdi] */
|
||||
0x58, /* pop rax */
|
||||
0x48, 0x89, 0x6e, 0x08, /* mov [rsi+0x08],rbp */
|
||||
0x48, 0x89, 0x5e, 0x10, /* mov [rsi+0x10],rbx */
|
||||
0x4c, 0x89, 0x66, 0x18, /* mov [rsi+0x18],r12 */
|
||||
0x4c, 0x89, 0x6e, 0x20, /* mov [rsi+0x20],r13 */
|
||||
0x4c, 0x89, 0x76, 0x28, /* mov [rsi+0x28],r14 */
|
||||
0x4c, 0x89, 0x7e, 0x30, /* mov [rsi+0x30],r15 */
|
||||
0x48, 0x8b, 0x6f, 0x08, /* mov rbp,[rdi+0x08] */
|
||||
0x48, 0x8b, 0x5f, 0x10, /* mov rbx,[rdi+0x10] */
|
||||
0x4c, 0x8b, 0x67, 0x18, /* mov r12,[rdi+0x18] */
|
||||
0x4c, 0x8b, 0x6f, 0x20, /* mov r13,[rdi+0x20] */
|
||||
0x4c, 0x8b, 0x77, 0x28, /* mov r14,[rdi+0x28] */
|
||||
0x4c, 0x8b, 0x7f, 0x30, /* mov r15,[rdi+0x30] */
|
||||
0xff, 0xe0, /* jmp rax */
|
||||
};
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
void co_init(void)
|
||||
{
|
||||
unsigned long long addr = (unsigned long long)co_swap_function;
|
||||
unsigned long long base = addr - (addr % sysconf(_SC_PAGESIZE));
|
||||
unsigned long long size = (addr - base) + sizeof(co_swap_function);
|
||||
mprotect((void*)base, size, PROT_READ | PROT_WRITE | PROT_EXEC);
|
||||
}
|
||||
#else
|
||||
void co_init(void) {}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static void crash(void)
|
||||
{
|
||||
assert(0); /* called only if cothread_t entrypoint returns */
|
||||
}
|
||||
|
||||
cothread_t co_active(void)
|
||||
{
|
||||
if (!co_active_handle)
|
||||
co_active_handle = &co_active_buffer;
|
||||
return co_active_handle;
|
||||
}
|
||||
|
||||
cothread_t co_create(unsigned int size, void (*entrypoint)(void))
|
||||
{
|
||||
cothread_t handle;
|
||||
|
||||
#ifndef CO_USE_INLINE_ASM
|
||||
if(!co_swap)
|
||||
{
|
||||
co_init();
|
||||
co_swap = (void (*)(cothread_t, cothread_t))co_swap_function;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!co_active_handle)
|
||||
co_active_handle = &co_active_buffer;
|
||||
size += 512; /* allocate additional space for storage */
|
||||
size &= ~15; /* align stack to 16-byte boundary */
|
||||
|
||||
if((handle = (cothread_t)malloc(size)))
|
||||
{
|
||||
long long *p = (long long*)((char*)handle + size); /* seek to top of stack */
|
||||
*--p = (long long)crash; /* crash if entrypoint returns */
|
||||
*--p = (long long)entrypoint; /* start of function */
|
||||
*(long long*)handle = (long long)p; /* stack pointer */
|
||||
}
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
void co_delete(cothread_t handle)
|
||||
{
|
||||
free(handle);
|
||||
}
|
||||
|
||||
#ifndef CO_USE_INLINE_ASM
|
||||
void co_switch(cothread_t handle)
|
||||
{
|
||||
register cothread_t co_previous_handle = co_active_handle;
|
||||
co_swap(co_active_handle = handle, co_previous_handle);
|
||||
}
|
||||
#else
|
||||
#ifdef __APPLE__
|
||||
#define ASM_PREFIX "_"
|
||||
#else
|
||||
#define ASM_PREFIX ""
|
||||
#endif
|
||||
__asm__(
|
||||
".intel_syntax noprefix \n"
|
||||
".globl " ASM_PREFIX "co_switch \n"
|
||||
ASM_PREFIX "co_switch: \n"
|
||||
"mov rsi, [rip+" ASM_PREFIX "co_active_handle]\n"
|
||||
"mov [rsi],rsp \n"
|
||||
"mov [rsi+0x08],rbp \n"
|
||||
"mov [rsi+0x10],rbx \n"
|
||||
"mov [rsi+0x18],r12 \n"
|
||||
"mov [rsi+0x20],r13 \n"
|
||||
"mov [rsi+0x28],r14 \n"
|
||||
"mov [rsi+0x30],r15 \n"
|
||||
"mov [rip+" ASM_PREFIX "co_active_handle], rdi\n"
|
||||
"mov rsp,[rdi] \n"
|
||||
"mov rbp,[rdi+0x08] \n"
|
||||
"mov rbx,[rdi+0x10] \n"
|
||||
"mov r12,[rdi+0x18] \n"
|
||||
"mov r13,[rdi+0x20] \n"
|
||||
"mov r14,[rdi+0x28] \n"
|
||||
"mov r15,[rdi+0x30] \n"
|
||||
"ret \n"
|
||||
".att_syntax \n"
|
||||
);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -1,107 +0,0 @@
|
||||
/*
|
||||
libco.armeabi (2013-04-05)
|
||||
author: Themaister
|
||||
license: public domain
|
||||
*/
|
||||
|
||||
#define LIBCO_C
|
||||
#include <libco.h>
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef __APPLE__
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
static thread_local uint32_t co_active_buffer[64];
|
||||
static thread_local cothread_t co_active_handle;
|
||||
|
||||
asm (
|
||||
#if defined(__thumb2__)
|
||||
".thumb\n"
|
||||
".align 2\n"
|
||||
".globl co_switch_arm\n"
|
||||
".globl _co_switch_arm\n"
|
||||
"co_switch_arm:\n"
|
||||
"_co_switch_arm:\n"
|
||||
" mov r3, sp\n"
|
||||
" stmia r1!, {r4, r5, r6, r7, r8, r9, r10, r11}\n"
|
||||
" stmia r1!, {r3, lr}\n"
|
||||
" ldmia r0!, {r4, r5, r6, r7, r8, r9, r10, r11}\n"
|
||||
" ldmfd r0!, { r3 }\n"
|
||||
" mov sp, r3\n"
|
||||
" ldmfd r0!, { r3 }\n"
|
||||
" mov pc, r3\n"
|
||||
#else
|
||||
".arm\n"
|
||||
".align 4\n"
|
||||
".globl co_switch_arm\n"
|
||||
".globl _co_switch_arm\n"
|
||||
"co_switch_arm:\n"
|
||||
"_co_switch_arm:\n"
|
||||
" stmia r1!, {r4, r5, r6, r7, r8, r9, r10, r11, sp, lr}\n"
|
||||
" ldmia r0!, {r4, r5, r6, r7, r8, r9, r10, r11, sp, pc}\n"
|
||||
#endif
|
||||
);
|
||||
|
||||
/* ASM */
|
||||
void co_switch_arm(cothread_t handle, cothread_t current);
|
||||
|
||||
cothread_t co_create(unsigned int size, void (*entrypoint)(void))
|
||||
{
|
||||
size = (size + 1023) & ~1023;
|
||||
cothread_t handle = 0;
|
||||
#if defined(__APPLE__) || HAVE_POSIX_MEMALIGN >= 1
|
||||
if (posix_memalign(&handle, 1024, size + 256) < 0)
|
||||
return 0;
|
||||
#else
|
||||
handle = memalign(1024, size + 256);
|
||||
#endif
|
||||
|
||||
if (!handle)
|
||||
return handle;
|
||||
|
||||
uint32_t *ptr = (uint32_t*)handle;
|
||||
/* Non-volatiles. */
|
||||
ptr[0] = 0; /* r4 */
|
||||
ptr[1] = 0; /* r5 */
|
||||
ptr[2] = 0; /* r6 */
|
||||
ptr[3] = 0; /* r7 */
|
||||
ptr[4] = 0; /* r8 */
|
||||
ptr[5] = 0; /* r9 */
|
||||
ptr[6] = 0; /* r10 */
|
||||
ptr[7] = 0; /* r11 */
|
||||
/* Align stack to 64-bit */
|
||||
ptr[8] = (uintptr_t)ptr + size + 256 - 8; /* r13, stack pointer */
|
||||
ptr[9] = (uintptr_t)entrypoint; /* r15, PC (link register r14 gets saved here). */
|
||||
return handle;
|
||||
}
|
||||
|
||||
cothread_t co_active(void)
|
||||
{
|
||||
if (!co_active_handle)
|
||||
co_active_handle = co_active_buffer;
|
||||
return co_active_handle;
|
||||
}
|
||||
|
||||
void co_delete(cothread_t handle)
|
||||
{
|
||||
free(handle);
|
||||
}
|
||||
|
||||
void co_switch(cothread_t handle)
|
||||
{
|
||||
cothread_t co_previous_handle = co_active();
|
||||
co_switch_arm(co_active_handle = handle, co_previous_handle);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
libco.win (2008-01-28)
|
||||
authors: Nach, byuu
|
||||
license: public domain
|
||||
*/
|
||||
|
||||
#define LIBCO_C
|
||||
#include <libco.h>
|
||||
#define WINVER 0x0400
|
||||
#define _WIN32_WINNT 0x0400
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
static thread_local cothread_t co_active_ = 0;
|
||||
|
||||
static void __stdcall co_thunk(void *coentry)
|
||||
{
|
||||
((void (*)(void))coentry)();
|
||||
}
|
||||
|
||||
cothread_t co_active(void)
|
||||
{
|
||||
if(!co_active_)
|
||||
{
|
||||
ConvertThreadToFiber(0);
|
||||
co_active_ = GetCurrentFiber();
|
||||
}
|
||||
return co_active_;
|
||||
}
|
||||
|
||||
cothread_t co_create(unsigned int heapsize, void (*coentry)(void))
|
||||
{
|
||||
if(!co_active_)
|
||||
{
|
||||
ConvertThreadToFiber(0);
|
||||
co_active_ = GetCurrentFiber();
|
||||
}
|
||||
return (cothread_t)CreateFiber(heapsize, co_thunk, (void*)coentry);
|
||||
}
|
||||
|
||||
void co_delete(cothread_t cothread)
|
||||
{
|
||||
DeleteFiber(cothread);
|
||||
}
|
||||
|
||||
void co_switch(cothread_t cothread)
|
||||
{
|
||||
co_active_ = cothread;
|
||||
SwitchToFiber(cothread);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -1,23 +0,0 @@
|
||||
/*
|
||||
libco
|
||||
auto-selection module
|
||||
license: public domain
|
||||
*/
|
||||
|
||||
#if defined(__GNUC__) && defined(__i386__) || (defined(_MSC_VER) && defined(_M_IX86))
|
||||
#include "x86.c"
|
||||
#elif defined(__GNUC__) && defined(__amd64__) || (defined(_MSC_VER) && defined(_M_AMD64))
|
||||
#include "amd64.c"
|
||||
#elif defined(__GNUC__) && defined(_ARCH_PPC)
|
||||
#include "ppc.c"
|
||||
#elif defined(__GNUC__) && defined(VITA)
|
||||
#include "scefiber.c"
|
||||
#elif defined(__GNUC__) && (defined(__ARM_EABI__) || defined(__arm__))
|
||||
#include "armeabi.c"
|
||||
#elif defined(__GNUC__)
|
||||
#include "sjlj.c"
|
||||
#elif defined(_MSC_VER)
|
||||
#include "fiber.c"
|
||||
#else
|
||||
#error "libco: unsupported processor, compiler or operating system"
|
||||
#endif
|
@ -1,407 +0,0 @@
|
||||
/*
|
||||
libco.ppc (2010-10-17)
|
||||
author: blargg
|
||||
license: public domain
|
||||
*/
|
||||
|
||||
/* PowerPC 32/64 using embedded or external asm, with optional
|
||||
floating-point and AltiVec save/restore */
|
||||
|
||||
#define LIBCO_C
|
||||
#include <libco.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#define LIBCO_MPROTECT (__unix__ && !LIBCO_PPC_ASM)
|
||||
|
||||
#if LIBCO_MPROTECT
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
|
||||
/* State format (offsets in 32-bit words)
|
||||
|
||||
+0 Pointer to swap code
|
||||
Rest of function descriptor for entry function
|
||||
+8 PC
|
||||
+10 SP
|
||||
Special regs
|
||||
GPRs
|
||||
FPRs
|
||||
VRs
|
||||
stack
|
||||
*/
|
||||
|
||||
enum { state_size = 1024 };
|
||||
enum { above_stack = 2048 };
|
||||
enum { stack_align = 256 };
|
||||
|
||||
static thread_local cothread_t co_active_handle = 0;
|
||||
|
||||
/**** Determine environment ****/
|
||||
|
||||
#define LIBCO_PPC64 (_ARCH_PPC64 || __PPC64__ || __ppc64__ || __powerpc64__)
|
||||
|
||||
/* Whether function calls are indirect through a descriptor,
|
||||
or are directly to function */
|
||||
#ifndef LIBCO_PPCDESC
|
||||
#if !_CALL_SYSV && (_CALL_AIX || _CALL_AIXDESC || LIBCO_PPC64)
|
||||
#define LIBCO_PPCDESC 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef LIBCO_PPC_ASM
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
#endif
|
||||
|
||||
/* Swap code is in ppc.S */
|
||||
void co_swap_asm( cothread_t, cothread_t );
|
||||
#define CO_SWAP_ASM( x, y ) co_swap_asm( x, y )
|
||||
|
||||
#else
|
||||
|
||||
/* Swap code is here in array. Please leave dieassembly comments,
|
||||
as they make it easy to see what it does, and reorder instructions
|
||||
if one wants to see whether that improves performance. */
|
||||
static const uint32_t libco_ppc_code [] = {
|
||||
#if LIBCO_PPC64
|
||||
0x7d000026, /* mfcr r8 */
|
||||
0xf8240028, /* std r1,40(r4) */
|
||||
0x7d2802a6, /* mflr r9 */
|
||||
0xf9c40048, /* std r14,72(r4) */
|
||||
0xf9e40050, /* std r15,80(r4) */
|
||||
0xfa040058, /* std r16,88(r4) */
|
||||
0xfa240060, /* std r17,96(r4) */
|
||||
0xfa440068, /* std r18,104(r4) */
|
||||
0xfa640070, /* std r19,112(r4) */
|
||||
0xfa840078, /* std r20,120(r4) */
|
||||
0xfaa40080, /* std r21,128(r4) */
|
||||
0xfac40088, /* std r22,136(r4) */
|
||||
0xfae40090, /* std r23,144(r4) */
|
||||
0xfb040098, /* std r24,152(r4) */
|
||||
0xfb2400a0, /* std r25,160(r4) */
|
||||
0xfb4400a8, /* std r26,168(r4) */
|
||||
0xfb6400b0, /* std r27,176(r4) */
|
||||
0xfb8400b8, /* std r28,184(r4) */
|
||||
0xfba400c0, /* std r29,192(r4) */
|
||||
0xfbc400c8, /* std r30,200(r4) */
|
||||
0xfbe400d0, /* std r31,208(r4) */
|
||||
0xf9240020, /* std r9,32(r4) */
|
||||
0xe8e30020, /* ld r7,32(r3) */
|
||||
0xe8230028, /* ld r1,40(r3) */
|
||||
0x48000009, /* bl 1 */
|
||||
0x7fe00008, /* trap */
|
||||
0x91040030,/*1:stw r8,48(r4) */
|
||||
0x80c30030, /* lwz r6,48(r3) */
|
||||
0x7ce903a6, /* mtctr r7 */
|
||||
0xe9c30048, /* ld r14,72(r3) */
|
||||
0xe9e30050, /* ld r15,80(r3) */
|
||||
0xea030058, /* ld r16,88(r3) */
|
||||
0xea230060, /* ld r17,96(r3) */
|
||||
0xea430068, /* ld r18,104(r3) */
|
||||
0xea630070, /* ld r19,112(r3) */
|
||||
0xea830078, /* ld r20,120(r3) */
|
||||
0xeaa30080, /* ld r21,128(r3) */
|
||||
0xeac30088, /* ld r22,136(r3) */
|
||||
0xeae30090, /* ld r23,144(r3) */
|
||||
0xeb030098, /* ld r24,152(r3) */
|
||||
0xeb2300a0, /* ld r25,160(r3) */
|
||||
0xeb4300a8, /* ld r26,168(r3) */
|
||||
0xeb6300b0, /* ld r27,176(r3) */
|
||||
0xeb8300b8, /* ld r28,184(r3) */
|
||||
0xeba300c0, /* ld r29,192(r3) */
|
||||
0xebc300c8, /* ld r30,200(r3) */
|
||||
0xebe300d0, /* ld r31,208(r3) */
|
||||
0x7ccff120, /* mtcr r6 */
|
||||
#else
|
||||
0x7d000026, /* mfcr r8 */
|
||||
0x90240028, /* stw r1,40(r4) */
|
||||
0x7d2802a6, /* mflr r9 */
|
||||
0x91a4003c, /* stw r13,60(r4) */
|
||||
0x91c40040, /* stw r14,64(r4) */
|
||||
0x91e40044, /* stw r15,68(r4) */
|
||||
0x92040048, /* stw r16,72(r4) */
|
||||
0x9224004c, /* stw r17,76(r4) */
|
||||
0x92440050, /* stw r18,80(r4) */
|
||||
0x92640054, /* stw r19,84(r4) */
|
||||
0x92840058, /* stw r20,88(r4) */
|
||||
0x92a4005c, /* stw r21,92(r4) */
|
||||
0x92c40060, /* stw r22,96(r4) */
|
||||
0x92e40064, /* stw r23,100(r4) */
|
||||
0x93040068, /* stw r24,104(r4) */
|
||||
0x9324006c, /* stw r25,108(r4) */
|
||||
0x93440070, /* stw r26,112(r4) */
|
||||
0x93640074, /* stw r27,116(r4) */
|
||||
0x93840078, /* stw r28,120(r4) */
|
||||
0x93a4007c, /* stw r29,124(r4) */
|
||||
0x93c40080, /* stw r30,128(r4) */
|
||||
0x93e40084, /* stw r31,132(r4) */
|
||||
0x91240020, /* stw r9,32(r4) */
|
||||
0x80e30020, /* lwz r7,32(r3) */
|
||||
0x80230028, /* lwz r1,40(r3) */
|
||||
0x48000009, /* bl 1 */
|
||||
0x7fe00008, /* trap */
|
||||
0x91040030,/*1:stw r8,48(r4) */
|
||||
0x80c30030, /* lwz r6,48(r3) */
|
||||
0x7ce903a6, /* mtctr r7 */
|
||||
0x81a3003c, /* lwz r13,60(r3) */
|
||||
0x81c30040, /* lwz r14,64(r3) */
|
||||
0x81e30044, /* lwz r15,68(r3) */
|
||||
0x82030048, /* lwz r16,72(r3) */
|
||||
0x8223004c, /* lwz r17,76(r3) */
|
||||
0x82430050, /* lwz r18,80(r3) */
|
||||
0x82630054, /* lwz r19,84(r3) */
|
||||
0x82830058, /* lwz r20,88(r3) */
|
||||
0x82a3005c, /* lwz r21,92(r3) */
|
||||
0x82c30060, /* lwz r22,96(r3) */
|
||||
0x82e30064, /* lwz r23,100(r3) */
|
||||
0x83030068, /* lwz r24,104(r3) */
|
||||
0x8323006c, /* lwz r25,108(r3) */
|
||||
0x83430070, /* lwz r26,112(r3) */
|
||||
0x83630074, /* lwz r27,116(r3) */
|
||||
0x83830078, /* lwz r28,120(r3) */
|
||||
0x83a3007c, /* lwz r29,124(r3) */
|
||||
0x83c30080, /* lwz r30,128(r3) */
|
||||
0x83e30084, /* lwz r31,132(r3) */
|
||||
0x7ccff120, /* mtcr r6 */
|
||||
#endif
|
||||
|
||||
#ifndef LIBCO_PPC_NOFP
|
||||
0xd9c400e0, /* stfd f14,224(r4) */
|
||||
0xd9e400e8, /* stfd f15,232(r4) */
|
||||
0xda0400f0, /* stfd f16,240(r4) */
|
||||
0xda2400f8, /* stfd f17,248(r4) */
|
||||
0xda440100, /* stfd f18,256(r4) */
|
||||
0xda640108, /* stfd f19,264(r4) */
|
||||
0xda840110, /* stfd f20,272(r4) */
|
||||
0xdaa40118, /* stfd f21,280(r4) */
|
||||
0xdac40120, /* stfd f22,288(r4) */
|
||||
0xdae40128, /* stfd f23,296(r4) */
|
||||
0xdb040130, /* stfd f24,304(r4) */
|
||||
0xdb240138, /* stfd f25,312(r4) */
|
||||
0xdb440140, /* stfd f26,320(r4) */
|
||||
0xdb640148, /* stfd f27,328(r4) */
|
||||
0xdb840150, /* stfd f28,336(r4) */
|
||||
0xdba40158, /* stfd f29,344(r4) */
|
||||
0xdbc40160, /* stfd f30,352(r4) */
|
||||
0xdbe40168, /* stfd f31,360(r4) */
|
||||
0xc9c300e0, /* lfd f14,224(r3) */
|
||||
0xc9e300e8, /* lfd f15,232(r3) */
|
||||
0xca0300f0, /* lfd f16,240(r3) */
|
||||
0xca2300f8, /* lfd f17,248(r3) */
|
||||
0xca430100, /* lfd f18,256(r3) */
|
||||
0xca630108, /* lfd f19,264(r3) */
|
||||
0xca830110, /* lfd f20,272(r3) */
|
||||
0xcaa30118, /* lfd f21,280(r3) */
|
||||
0xcac30120, /* lfd f22,288(r3) */
|
||||
0xcae30128, /* lfd f23,296(r3) */
|
||||
0xcb030130, /* lfd f24,304(r3) */
|
||||
0xcb230138, /* lfd f25,312(r3) */
|
||||
0xcb430140, /* lfd f26,320(r3) */
|
||||
0xcb630148, /* lfd f27,328(r3) */
|
||||
0xcb830150, /* lfd f28,336(r3) */
|
||||
0xcba30158, /* lfd f29,344(r3) */
|
||||
0xcbc30160, /* lfd f30,352(r3) */
|
||||
0xcbe30168, /* lfd f31,360(r3) */
|
||||
#endif
|
||||
|
||||
#ifdef __ALTIVEC__
|
||||
0x7ca042a6, /* mfvrsave r5 */
|
||||
0x39040180, /* addi r8,r4,384 */
|
||||
0x39240190, /* addi r9,r4,400 */
|
||||
0x70a00fff, /* andi. r0,r5,4095 */
|
||||
0x90a40034, /* stw r5,52(r4) */
|
||||
0x4182005c, /* beq- 2 */
|
||||
0x7e8041ce, /* stvx v20,r0,r8 */
|
||||
0x39080020, /* addi r8,r8,32 */
|
||||
0x7ea049ce, /* stvx v21,r0,r9 */
|
||||
0x39290020, /* addi r9,r9,32 */
|
||||
0x7ec041ce, /* stvx v22,r0,r8 */
|
||||
0x39080020, /* addi r8,r8,32 */
|
||||
0x7ee049ce, /* stvx v23,r0,r9 */
|
||||
0x39290020, /* addi r9,r9,32 */
|
||||
0x7f0041ce, /* stvx v24,r0,r8 */
|
||||
0x39080020, /* addi r8,r8,32 */
|
||||
0x7f2049ce, /* stvx v25,r0,r9 */
|
||||
0x39290020, /* addi r9,r9,32 */
|
||||
0x7f4041ce, /* stvx v26,r0,r8 */
|
||||
0x39080020, /* addi r8,r8,32 */
|
||||
0x7f6049ce, /* stvx v27,r0,r9 */
|
||||
0x39290020, /* addi r9,r9,32 */
|
||||
0x7f8041ce, /* stvx v28,r0,r8 */
|
||||
0x39080020, /* addi r8,r8,32 */
|
||||
0x7fa049ce, /* stvx v29,r0,r9 */
|
||||
0x39290020, /* addi r9,r9,32 */
|
||||
0x7fc041ce, /* stvx v30,r0,r8 */
|
||||
0x7fe049ce, /* stvx v31,r0,r9 */
|
||||
0x80a30034,/*2:lwz r5,52(r3) */
|
||||
0x39030180, /* addi r8,r3,384 */
|
||||
0x39230190, /* addi r9,r3,400 */
|
||||
0x70a00fff, /* andi. r0,r5,4095 */
|
||||
0x7ca043a6, /* mtvrsave r5 */
|
||||
0x4d820420, /* beqctr */
|
||||
0x7e8040ce, /* lvx v20,r0,r8 */
|
||||
0x39080020, /* addi r8,r8,32 */
|
||||
0x7ea048ce, /* lvx v21,r0,r9 */
|
||||
0x39290020, /* addi r9,r9,32 */
|
||||
0x7ec040ce, /* lvx v22,r0,r8 */
|
||||
0x39080020, /* addi r8,r8,32 */
|
||||
0x7ee048ce, /* lvx v23,r0,r9 */
|
||||
0x39290020, /* addi r9,r9,32 */
|
||||
0x7f0040ce, /* lvx v24,r0,r8 */
|
||||
0x39080020, /* addi r8,r8,32 */
|
||||
0x7f2048ce, /* lvx v25,r0,r9 */
|
||||
0x39290020, /* addi r9,r9,32 */
|
||||
0x7f4040ce, /* lvx v26,r0,r8 */
|
||||
0x39080020, /* addi r8,r8,32 */
|
||||
0x7f6048ce, /* lvx v27,r0,r9 */
|
||||
0x39290020, /* addi r9,r9,32 */
|
||||
0x7f8040ce, /* lvx v28,r0,r8 */
|
||||
0x39080020, /* addi r8,r8,32 */
|
||||
0x7fa048ce, /* lvx v29,r0,r9 */
|
||||
0x39290020, /* addi r9,r9,32 */
|
||||
0x7fc040ce, /* lvx v30,r0,r8 */
|
||||
0x7fe048ce, /* lvx v31,r0,r9 */
|
||||
#endif
|
||||
|
||||
0x4e800420, /* bctr */
|
||||
};
|
||||
|
||||
#if LIBCO_PPCDESC
|
||||
/* Function call goes through indirect descriptor */
|
||||
#define CO_SWAP_ASM( x, y ) \
|
||||
((void (*)( cothread_t, cothread_t )) (uintptr_t) x)( x, y )
|
||||
#else
|
||||
/* Function call goes directly to code */
|
||||
#define CO_SWAP_ASM( x, y ) \
|
||||
((void (*)( cothread_t, cothread_t )) (uintptr_t) libco_ppc_code)( x, y )
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
static uint32_t* co_create_( unsigned size, uintptr_t entry )
|
||||
{
|
||||
uint32_t* t = (uint32_t*) malloc( size );
|
||||
|
||||
(void) entry;
|
||||
|
||||
#if LIBCO_PPCDESC
|
||||
if ( t )
|
||||
{
|
||||
/* Copy entry's descriptor */
|
||||
memcpy( t, (void*) entry, sizeof (void*) * 3 );
|
||||
|
||||
/* Set function pointer to swap routine */
|
||||
#ifdef LIBCO_PPC_ASM
|
||||
*(const void**) t = *(void**) &co_swap_asm;
|
||||
#else
|
||||
*(const void**) t = libco_ppc_code;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
cothread_t co_create( unsigned int size, void (*entry_)( void ) )
|
||||
{
|
||||
uintptr_t entry = (uintptr_t) entry_;
|
||||
uint32_t* t = NULL;
|
||||
|
||||
/* Be sure main thread was successfully allocated */
|
||||
if ( co_active() )
|
||||
{
|
||||
size += state_size + above_stack + stack_align;
|
||||
t = co_create_( size, entry );
|
||||
}
|
||||
|
||||
if ( t )
|
||||
{
|
||||
uintptr_t sp;
|
||||
int shift;
|
||||
|
||||
/* Save current registers into new thread, so that any special ones will
|
||||
have proper values when thread is begun */
|
||||
CO_SWAP_ASM( t, t );
|
||||
|
||||
#if LIBCO_PPCDESC
|
||||
/* Get real address */
|
||||
entry = (uintptr_t) *(void**) entry;
|
||||
#endif
|
||||
|
||||
/* Put stack near end of block, and align */
|
||||
sp = (uintptr_t) t + size - above_stack;
|
||||
sp -= sp % stack_align;
|
||||
|
||||
/* On PPC32, we save and restore GPRs as 32 bits. For PPC64, we
|
||||
save and restore them as 64 bits, regardless of the size the ABI
|
||||
uses. So, we manually write pointers at the proper size. We always
|
||||
save and restore at the same address, and since PPC is big-endian,
|
||||
we must put the low byte first on PPC32. */
|
||||
|
||||
/* If uintptr_t is 32 bits, >>32 is undefined behavior, so we do two shifts
|
||||
and don't have to care how many bits uintptr_t is. */
|
||||
#if LIBCO_PPC64
|
||||
shift = 16;
|
||||
#else
|
||||
shift = 0;
|
||||
#endif
|
||||
|
||||
/* Set up so entry will be called on next swap */
|
||||
t [8] = (uint32_t) (entry >> shift >> shift);
|
||||
t [9] = (uint32_t) entry;
|
||||
|
||||
t [10] = (uint32_t) (sp >> shift >> shift);
|
||||
t [11] = (uint32_t) sp;
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
void co_delete( cothread_t t )
|
||||
{
|
||||
free(t);
|
||||
}
|
||||
|
||||
static void co_init_( void )
|
||||
{
|
||||
#if LIBCO_MPROTECT
|
||||
/* TODO: pre- and post-pad PPC code so that this doesn't make other
|
||||
data executable and writable */
|
||||
long page_size = sysconf( _SC_PAGESIZE );
|
||||
if ( page_size > 0 )
|
||||
{
|
||||
uintptr_t align = page_size;
|
||||
uintptr_t begin = (uintptr_t) libco_ppc_code;
|
||||
uintptr_t end = begin + sizeof libco_ppc_code;
|
||||
|
||||
/* Align beginning and end */
|
||||
end += align - 1;
|
||||
end -= end % align;
|
||||
begin -= begin % align;
|
||||
|
||||
mprotect( (void*) begin, end - begin, PROT_READ | PROT_WRITE | PROT_EXEC );
|
||||
}
|
||||
#endif
|
||||
|
||||
co_active_handle = co_create_( state_size, (uintptr_t) &co_switch );
|
||||
}
|
||||
|
||||
cothread_t co_active(void)
|
||||
{
|
||||
if (!co_active_handle)
|
||||
co_init_();
|
||||
|
||||
return co_active_handle;
|
||||
}
|
||||
|
||||
void co_switch(cothread_t t)
|
||||
{
|
||||
cothread_t old = co_active_handle;
|
||||
co_active_handle = t;
|
||||
|
||||
CO_SWAP_ASM( t, old );
|
||||
}
|
@ -1,113 +0,0 @@
|
||||
/*
|
||||
libco.arm (2015-06-18)
|
||||
license: public domain
|
||||
*/
|
||||
|
||||
#define LIBCO_C
|
||||
#include "libco.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <psp2/kernel/sysmem.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define FOUR_KB_ALIGN(x) align(x, 12)
|
||||
#define MB_ALIGN(x) align(x, 20)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
static inline int align(int x, int n)
|
||||
{
|
||||
return (((x >> n) + 1) << n);
|
||||
}
|
||||
|
||||
static thread_local unsigned long co_active_buffer[64];
|
||||
static thread_local cothread_t co_active_handle = 0;
|
||||
static void(*co_swap)(cothread_t, cothread_t) = 0;
|
||||
static int block;
|
||||
static uint32_t co_swap_function[] = {
|
||||
0xe8a16ff0, /* stmia r1!, {r4-r11,sp,lr} */
|
||||
0xe8b0aff0, /* ldmia r0!, {r4-r11,sp,pc} */
|
||||
0xe12fff1e, /* bx lr */
|
||||
};
|
||||
|
||||
void co_init()
|
||||
{
|
||||
int ret;
|
||||
void *base;
|
||||
|
||||
block = sceKernelAllocMemBlockForVM("libco",
|
||||
MB_ALIGN(FOUR_KB_ALIGN(sizeof co_swap_function)));
|
||||
if (block < 0)
|
||||
return;
|
||||
|
||||
/* get base address */
|
||||
ret = sceKernelGetMemBlockBase(block, &base);
|
||||
if (ret < 0)
|
||||
return;
|
||||
|
||||
/* set domain to be writable by user */
|
||||
ret = sceKernelOpenVMDomain();
|
||||
if (ret < 0)
|
||||
return;
|
||||
|
||||
memcpy(base, co_swap_function, sizeof co_swap_function);
|
||||
|
||||
/* set domain back to read-only */
|
||||
ret = sceKernelCloseVMDomain();
|
||||
if (ret < 0)
|
||||
return;
|
||||
|
||||
/* flush icache */
|
||||
ret = sceKernelSyncVMDomain(block, base,
|
||||
MB_ALIGN(FOUR_KB_ALIGN(sizeof co_swap_function)));
|
||||
if (ret < 0)
|
||||
return;
|
||||
|
||||
co_swap = (void(*)(cothread_t, cothread_t))base;
|
||||
}
|
||||
|
||||
cothread_t co_active(void)
|
||||
{
|
||||
if (!co_active_handle) co_active_handle = &co_active_buffer;
|
||||
return co_active_handle;
|
||||
}
|
||||
|
||||
cothread_t co_create(unsigned int size, void(*entrypoint)(void))
|
||||
{
|
||||
unsigned long* handle = 0;
|
||||
if (!co_swap)
|
||||
co_init();
|
||||
if (!co_active_handle) co_active_handle = &co_active_buffer;
|
||||
size += 256;
|
||||
size &= ~15;
|
||||
|
||||
if ((handle = (unsigned long*)malloc(size)))
|
||||
{
|
||||
unsigned long* p = (unsigned long*)((unsigned char*)handle + size);
|
||||
handle[8] = (unsigned long)p;
|
||||
handle[9] = (unsigned long)entrypoint;
|
||||
}
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
void co_delete(cothread_t handle)
|
||||
{
|
||||
free(handle);
|
||||
sceKernelFreeMemBlock(block);
|
||||
}
|
||||
|
||||
void co_switch(cothread_t handle)
|
||||
{
|
||||
cothread_t co_previous_handle = co_active_handle;
|
||||
co_swap(co_active_handle = handle, co_previous_handle);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -1,96 +0,0 @@
|
||||
/*
|
||||
libco.win (2016-09-06)
|
||||
authors: frangarcj
|
||||
license: public domain
|
||||
*/
|
||||
|
||||
#define LIBCO_C
|
||||
#include <libco.h>
|
||||
#include <stdlib.h>
|
||||
#include <psp2/sysmodule.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
static thread_local cothread_t co_active_ = 0;
|
||||
|
||||
typedef struct SceFiber {
|
||||
char reserved[128];
|
||||
} SceFiber __attribute__( ( aligned ( 8 ) ) ) ;
|
||||
|
||||
int32_t _sceFiberInitializeImpl(SceFiber* fiber, char* name, void* entry, uint32_t argOnInitialize, void* addrContext, int32_t sizeContext, void* params);
|
||||
|
||||
int32_t sceFiberFinalize(SceFiber* fiber);
|
||||
|
||||
int32_t sceFiberRun(SceFiber* fiber, uint32_t argOnRunTo, uint32_t* argOnRun);
|
||||
|
||||
int32_t sceFiberSwitch(SceFiber* fiber, uint32_t argOnRunTo, uint32_t* argOnRun);
|
||||
|
||||
int32_t sceFiberReturnToThread(uint32_t argOnReturn, uint32_t* argOnRun);
|
||||
|
||||
void co_thunk(uint32_t argOnInitialize, uint32_t argOnRun)
|
||||
{
|
||||
((void (*)(void))argOnInitialize)();
|
||||
}
|
||||
|
||||
cothread_t co_active(void)
|
||||
{
|
||||
if(!co_active_)
|
||||
{
|
||||
sceSysmoduleLoadModule(SCE_SYSMODULE_FIBER);
|
||||
co_active_ = (cothread_t)1;
|
||||
}
|
||||
return co_active_;
|
||||
}
|
||||
|
||||
cothread_t co_create(unsigned int heapsize, void (*coentry)(void))
|
||||
{
|
||||
SceFiber* tailFiber = malloc(sizeof(SceFiber));
|
||||
char * m_contextBuffer = malloc(sizeof(char)*heapsize);
|
||||
if(!co_active_)
|
||||
{
|
||||
sceSysmoduleLoadModule(SCE_SYSMODULE_FIBER);
|
||||
co_active_ = (cothread_t)1;
|
||||
}
|
||||
|
||||
//_sceFiberInitializeImpl
|
||||
int ret = _sceFiberInitializeImpl(tailFiber, "tailFiber", co_thunk, (uint32_t)coentry, (void*) m_contextBuffer, heapsize, NULL);
|
||||
if(ret==0){
|
||||
return (cothread_t)tailFiber;
|
||||
}else{
|
||||
return (cothread_t)ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void co_delete(cothread_t cothread)
|
||||
{
|
||||
if(cothread == (cothread_t)1){
|
||||
return;
|
||||
}
|
||||
sceFiberFinalize((SceFiber*)cothread);
|
||||
}
|
||||
|
||||
void co_switch(cothread_t cothread)
|
||||
{
|
||||
|
||||
uint32_t argOnReturn = 0;
|
||||
if(cothread == (cothread_t)1){
|
||||
co_active_ = cothread;
|
||||
sceFiberReturnToThread(0, NULL);
|
||||
}else{
|
||||
SceFiber* theFiber = (SceFiber*)cothread;
|
||||
if(co_active_ == (cothread_t)1){
|
||||
co_active_ = cothread;
|
||||
sceFiberRun(theFiber, 0, &argOnReturn);
|
||||
}else{
|
||||
co_active_ = cothread;
|
||||
sceFiberSwitch(theFiber, 0, &argOnReturn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -1,115 +0,0 @@
|
||||
/*
|
||||
libco.sjlj (2008-01-28)
|
||||
author: Nach
|
||||
license: public domain
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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 <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, *co_running = 0;
|
||||
|
||||
static void springboard(int ignored)
|
||||
{
|
||||
if(sigsetjmp(creating->context, 0))
|
||||
co_running->coentry();
|
||||
}
|
||||
|
||||
cothread_t co_active(void)
|
||||
{
|
||||
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)
|
||||
{
|
||||
stack_t stack;
|
||||
stack_t old_stack;
|
||||
|
||||
struct sigaction handler = {{0}};
|
||||
struct sigaction old_handler = {{0}};
|
||||
|
||||
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
|
@ -1,81 +0,0 @@
|
||||
/*
|
||||
libco.ucontext (2008-01-28)
|
||||
author: Nach
|
||||
license: public domain
|
||||
*/
|
||||
|
||||
/*
|
||||
* WARNING: the overhead of POSIX ucontext is very high,
|
||||
* assembly versions of libco or libco_sjlj should be much faster
|
||||
*
|
||||
* This library only exists for two reasons:
|
||||
* 1 - as an initial test for the viability of a ucontext implementation
|
||||
* 2 - to demonstrate the power and speed of libco over existing implementations,
|
||||
* such as pth (which defaults to wrapping ucontext on unix targets)
|
||||
*
|
||||
* Use this library only as a *last resort*
|
||||
*/
|
||||
|
||||
#define LIBCO_C
|
||||
#include <libco.h>
|
||||
#include <stdlib.h>
|
||||
#include <ucontext.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
static thread_local ucontext_t co_primary;
|
||||
static thread_local ucontext_t *co_running = 0;
|
||||
|
||||
cothread_t co_active(void)
|
||||
{
|
||||
if (!co_running)
|
||||
co_running = &co_primary;
|
||||
return (cothread_t)co_running;
|
||||
}
|
||||
|
||||
cothread_t co_create(unsigned int heapsize, void (*coentry)(void))
|
||||
{
|
||||
if (!co_running)
|
||||
co_running = &co_primary;
|
||||
ucontext_t *thread = (ucontext_t*)malloc(sizeof(ucontext_t));
|
||||
|
||||
if(thread)
|
||||
{
|
||||
if((!getcontext(thread) && !(thread->uc_stack.ss_sp = 0)) && (thread->uc_stack.ss_sp = malloc(heapsize)))
|
||||
{
|
||||
thread->uc_link = co_running;
|
||||
thread->uc_stack.ss_size = heapsize;
|
||||
makecontext(thread, coentry, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
co_delete((cothread_t)thread);
|
||||
thread = 0;
|
||||
}
|
||||
}
|
||||
return (cothread_t)thread;
|
||||
}
|
||||
|
||||
void co_delete(cothread_t cothread)
|
||||
{
|
||||
if (!cothread)
|
||||
return;
|
||||
|
||||
if(((ucontext_t*)cothread)->uc_stack.ss_sp)
|
||||
free(((ucontext_t*)cothread)->uc_stack.ss_sp);
|
||||
free(cothread);
|
||||
}
|
||||
|
||||
void co_switch(cothread_t cothread)
|
||||
{
|
||||
ucontext_t *old_thread = co_running;
|
||||
|
||||
co_running = (ucontext_t*)cothread;
|
||||
swapcontext(old_thread, co_running);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -1,117 +0,0 @@
|
||||
/*
|
||||
libco.x86 (2009-10-12)
|
||||
author: byuu
|
||||
license: public domain
|
||||
*/
|
||||
|
||||
#define LIBCO_C
|
||||
#include <libco.h>
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define fastcall __fastcall
|
||||
#elif defined(__GNUC__)
|
||||
#define fastcall __attribute__((fastcall))
|
||||
#else
|
||||
#error "libco: please define fastcall macro"
|
||||
#endif
|
||||
|
||||
static thread_local long co_active_buffer[64];
|
||||
static thread_local cothread_t co_active_handle = 0;
|
||||
static void (fastcall *co_swap)(cothread_t, cothread_t) = 0;
|
||||
|
||||
//ABI: fastcall
|
||||
static unsigned char co_swap_function[] = {
|
||||
0x89, 0x22, /* mov [edx],esp */
|
||||
0x8b, 0x21, /* mov esp,[ecx] */
|
||||
0x58, /* pop eax */
|
||||
0x89, 0x6a, 0x04, /* mov [edx+0x04],ebp */
|
||||
0x89, 0x72, 0x08, /* mov [edx+0x08],esi */
|
||||
0x89, 0x7a, 0x0c, /* mov [edx+0x0c],edi */
|
||||
0x89, 0x5a, 0x10, /* mov [edx+0x10],ebx */
|
||||
0x8b, 0x69, 0x04, /* mov ebp,[ecx+0x04] */
|
||||
0x8b, 0x71, 0x08, /* mov esi,[ecx+0x08] */
|
||||
0x8b, 0x79, 0x0c, /* mov edi,[ecx+0x0c] */
|
||||
0x8b, 0x59, 0x10, /* mov ebx,[ecx+0x10] */
|
||||
0xff, 0xe0, /* jmp eax */
|
||||
};
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
|
||||
void co_init(void)
|
||||
{
|
||||
DWORD old_privileges;
|
||||
VirtualProtect(co_swap_function,
|
||||
sizeof co_swap_function, PAGE_EXECUTE_READWRITE, &old_privileges);
|
||||
}
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
void co_init(void)
|
||||
{
|
||||
unsigned long addr = (unsigned long)co_swap_function;
|
||||
unsigned long base = addr - (addr % sysconf(_SC_PAGESIZE));
|
||||
unsigned long size = (addr - base) + sizeof co_swap_function;
|
||||
mprotect((void*)base, size, PROT_READ | PROT_WRITE | PROT_EXEC);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void crash(void)
|
||||
{
|
||||
assert(0); /* called only if cothread_t entrypoint returns */
|
||||
}
|
||||
|
||||
cothread_t co_active(void)
|
||||
{
|
||||
if(!co_active_handle)
|
||||
co_active_handle = &co_active_buffer;
|
||||
return co_active_handle;
|
||||
}
|
||||
|
||||
cothread_t co_create(unsigned int size, void (*entrypoint)(void))
|
||||
{
|
||||
cothread_t handle;
|
||||
if(!co_swap)
|
||||
{
|
||||
co_init();
|
||||
co_swap = (void (fastcall*)(cothread_t, cothread_t))co_swap_function;
|
||||
}
|
||||
|
||||
if(!co_active_handle)
|
||||
co_active_handle = &co_active_buffer;
|
||||
|
||||
size += 256; /* allocate additional space for storage */
|
||||
size &= ~15; /* align stack to 16-byte boundary */
|
||||
|
||||
if((handle = (cothread_t)malloc(size)))
|
||||
{
|
||||
long *p = (long*)((char*)handle + size); /* seek to top of stack */
|
||||
*--p = (long)crash; /* crash if entrypoint returns */
|
||||
*--p = (long)entrypoint; /* start of function */
|
||||
*(long*)handle = (long)p; /* stack pointer */
|
||||
}
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
void co_delete(cothread_t handle)
|
||||
{
|
||||
free(handle);
|
||||
}
|
||||
|
||||
void co_switch(cothread_t handle)
|
||||
{
|
||||
register cothread_t co_previous_handle = co_active_handle;
|
||||
co_swap(co_active_handle = handle, co_previous_handle);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -1,3 +1,117 @@
|
||||
|
||||
kt_table ktable[]={
|
||||
{"A",RETROK_a,ITEM_ID_A},
|
||||
{"B",RETROK_b,ITEM_ID_B},
|
||||
{"C",RETROK_c,ITEM_ID_C},
|
||||
{"D",RETROK_d,ITEM_ID_D},
|
||||
{"E",RETROK_e,ITEM_ID_E},
|
||||
{"F",RETROK_f,ITEM_ID_F},
|
||||
{"G",RETROK_g,ITEM_ID_G},
|
||||
{"H",RETROK_h,ITEM_ID_H},
|
||||
{"I",RETROK_i,ITEM_ID_I},
|
||||
{"J",RETROK_j,ITEM_ID_J},
|
||||
{"K",RETROK_k,ITEM_ID_K},
|
||||
{"L",RETROK_l,ITEM_ID_L},
|
||||
{"M",RETROK_m,ITEM_ID_M},
|
||||
{"N",RETROK_n,ITEM_ID_N},
|
||||
{"O",RETROK_o,ITEM_ID_O},
|
||||
{"P",RETROK_p,ITEM_ID_P},
|
||||
{"Q",RETROK_q,ITEM_ID_Q},
|
||||
{"R",RETROK_r,ITEM_ID_R},
|
||||
{"S",RETROK_s,ITEM_ID_S},
|
||||
{"T",RETROK_t,ITEM_ID_T},
|
||||
{"U",RETROK_u,ITEM_ID_U},
|
||||
{"V",RETROK_v,ITEM_ID_V},
|
||||
{"W",RETROK_w,ITEM_ID_W},
|
||||
{"X",RETROK_x,ITEM_ID_X},
|
||||
{"Y",RETROK_y,ITEM_ID_Y},
|
||||
{"Z",RETROK_z,ITEM_ID_Z},
|
||||
{"0",RETROK_0,ITEM_ID_0},
|
||||
{"1",RETROK_1,ITEM_ID_1},
|
||||
{"2",RETROK_2,ITEM_ID_2},
|
||||
{"3",RETROK_3,ITEM_ID_3},
|
||||
{"4",RETROK_4,ITEM_ID_4},
|
||||
{"5",RETROK_5,ITEM_ID_5},
|
||||
{"6",RETROK_6,ITEM_ID_6},
|
||||
{"7",RETROK_7,ITEM_ID_7},
|
||||
{"8",RETROK_8,ITEM_ID_8},
|
||||
{"9",RETROK_9,ITEM_ID_9},
|
||||
{"F1",RETROK_F1,ITEM_ID_F1},
|
||||
{"F2",RETROK_F2,ITEM_ID_F2},
|
||||
{"F3",RETROK_F3,ITEM_ID_F3},
|
||||
{"F4",RETROK_F4,ITEM_ID_F4},
|
||||
{"F5",RETROK_F5,ITEM_ID_F5},
|
||||
{"F6",RETROK_F6,ITEM_ID_F6},
|
||||
{"F7",RETROK_F7,ITEM_ID_F7},
|
||||
{"F8",RETROK_F8,ITEM_ID_F8},
|
||||
{"F9",RETROK_F9,ITEM_ID_F9},
|
||||
{"F10",RETROK_F10,ITEM_ID_F10},
|
||||
{"F11",RETROK_F11,ITEM_ID_F11},
|
||||
{"F12",RETROK_F12,ITEM_ID_F12},
|
||||
{"F13",RETROK_F13,ITEM_ID_F13},
|
||||
{"F14",RETROK_F14,ITEM_ID_F14},
|
||||
{"F15",RETROK_F15,ITEM_ID_F15},
|
||||
{"Esc",RETROK_ESCAPE,ITEM_ID_ESC},
|
||||
{"TILDE",RETROK_BACKQUOTE,ITEM_ID_TILDE},
|
||||
{"MINUS",RETROK_MINUS,ITEM_ID_MINUS},
|
||||
{"EQUALS",RETROK_EQUALS,ITEM_ID_EQUALS},
|
||||
{"BKCSPACE",RETROK_BACKSPACE,ITEM_ID_BACKSPACE},
|
||||
{"TAB",RETROK_TAB,ITEM_ID_TAB},
|
||||
{"(",RETROK_LEFTPAREN,ITEM_ID_OPENBRACE},
|
||||
{")",RETROK_RIGHTPAREN,ITEM_ID_CLOSEBRACE},
|
||||
{"ENTER",RETROK_RETURN,ITEM_ID_ENTER},
|
||||
{"·",RETROK_COLON,ITEM_ID_COLON},
|
||||
{"\'",RETROK_QUOTE,ITEM_ID_QUOTE},
|
||||
{"BCKSLASH",RETROK_BACKSLASH,ITEM_ID_BACKSLASH},
|
||||
///**/BCKSLASH2*/RETROK_,ITEM_ID_BACKSLASH2},
|
||||
{",",RETROK_COMMA,ITEM_ID_COMMA},
|
||||
///**/STOP*/RETROK_,ITEM_ID_STOP},
|
||||
{"/",RETROK_SLASH,ITEM_ID_SLASH},
|
||||
{"SPACE",RETROK_SPACE,ITEM_ID_SPACE},
|
||||
{"INS",RETROK_INSERT,ITEM_ID_INSERT},
|
||||
{"DEL",RETROK_DELETE,ITEM_ID_DEL},
|
||||
{"HOME",RETROK_HOME,ITEM_ID_HOME},
|
||||
{"END",RETROK_END,ITEM_ID_END},
|
||||
{"PGUP",RETROK_PAGEUP,ITEM_ID_PGUP},
|
||||
{"PGDW",RETROK_PAGEDOWN,ITEM_ID_PGDN},
|
||||
{"LEFT",RETROK_LEFT,ITEM_ID_LEFT},
|
||||
{"RIGHT",RETROK_RIGHT,ITEM_ID_RIGHT},
|
||||
{"UP",RETROK_UP,ITEM_ID_UP},
|
||||
{"DOWN",RETROK_DOWN,ITEM_ID_DOWN},
|
||||
{"KO",RETROK_KP0,ITEM_ID_0_PAD},
|
||||
{"K1",RETROK_KP1,ITEM_ID_1_PAD},
|
||||
{"K2",RETROK_KP2,ITEM_ID_2_PAD},
|
||||
{"K3",RETROK_KP3,ITEM_ID_3_PAD},
|
||||
{"K4",RETROK_KP4,ITEM_ID_4_PAD},
|
||||
{"K5",RETROK_KP5,ITEM_ID_5_PAD},
|
||||
{"K6",RETROK_KP6,ITEM_ID_6_PAD},
|
||||
{"K7",RETROK_KP7,ITEM_ID_7_PAD},
|
||||
{"K8",RETROK_KP8,ITEM_ID_8_PAD},
|
||||
{"K9",RETROK_KP9,ITEM_ID_9_PAD},
|
||||
{"K/",RETROK_KP_DIVIDE,ITEM_ID_SLASH_PAD},
|
||||
{"K*",RETROK_KP_MULTIPLY,ITEM_ID_ASTERISK},
|
||||
{"K-",RETROK_KP_MINUS,ITEM_ID_MINUS_PAD},
|
||||
{"K+",RETROK_KP_PLUS,ITEM_ID_PLUS_PAD},
|
||||
{"KDEL",RETROK_KP_PERIOD,ITEM_ID_DEL_PAD},
|
||||
{"KRTRN",RETROK_KP_ENTER,ITEM_ID_ENTER_PAD},
|
||||
{"PRINT",RETROK_PRINT,ITEM_ID_PRTSCR},
|
||||
{"PAUSE",RETROK_PAUSE,ITEM_ID_PAUSE},
|
||||
{"LSHFT",RETROK_LSHIFT,ITEM_ID_LSHIFT},
|
||||
{"RSHFT",RETROK_RSHIFT,ITEM_ID_RSHIFT},
|
||||
{"LCTRL",RETROK_LCTRL,ITEM_ID_LCONTROL},
|
||||
{"RCTRL",RETROK_RCTRL,ITEM_ID_RCONTROL},
|
||||
{"LALT",RETROK_LALT,ITEM_ID_LALT},
|
||||
{"RALT",RETROK_RALT,ITEM_ID_RALT},
|
||||
{"SCRLOCK",RETROK_SCROLLOCK,ITEM_ID_SCRLOCK},
|
||||
{"NUMLOCK",RETROK_NUMLOCK,ITEM_ID_NUMLOCK},
|
||||
{"CPSLOCK",RETROK_CAPSLOCK,ITEM_ID_CAPSLOCK},
|
||||
{"LMETA",RETROK_LMETA,ITEM_ID_LWIN},
|
||||
{"RMETA",RETROK_RMETA,ITEM_ID_RWIN},
|
||||
{"MENU",RETROK_MENU,ITEM_ID_MENU},
|
||||
{"BREAK",RETROK_BREAK,ITEM_ID_CANCEL},
|
||||
{"-1",-1,ITEM_ID_INVALID},
|
||||
};
|
||||
|
||||
static INT32 pad1_get_state(void *device_internal, void *item_internal)
|
||||
{
|
||||
UINT8 *itemdata = (UINT8 *)item_internal;
|
||||
@ -502,126 +616,45 @@ static void initInput(running_machine* machine)
|
||||
if (retrokbd_device == NULL)
|
||||
fatalerror("KBD Error creating keyboard device\n");
|
||||
|
||||
#define RETROK_TILDE 178
|
||||
|
||||
for(i = 0; i < RETROK_LAST; i++)
|
||||
for(i = 0; i < RETROK_LAST; i++){
|
||||
retrokbd_state[i]=0;
|
||||
retrokbd_state2[i]=0;
|
||||
}
|
||||
|
||||
i=0;
|
||||
do{
|
||||
input_device_item_add_kbd(retrokbd_device,\
|
||||
ktable[i].mame_key_name, &retrokbd_state[ktable[i].retro_key_name],ktable[i].mame_key,retrokbd_get_state);
|
||||
i++;
|
||||
}while(ktable[i].retro_key_name!=-1);
|
||||
|
||||
input_device_item_add_kbd(retrokbd_device, "A", &retrokbd_state[RETROK_a],ITEM_ID_A,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "B", &retrokbd_state[RETROK_b],ITEM_ID_B,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "C", &retrokbd_state[RETROK_c],ITEM_ID_C,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "D", &retrokbd_state[RETROK_d],ITEM_ID_D,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "E", &retrokbd_state[RETROK_e],ITEM_ID_E,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "F", &retrokbd_state[RETROK_f],ITEM_ID_F,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "G", &retrokbd_state[RETROK_g],ITEM_ID_G,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "H", &retrokbd_state[RETROK_h],ITEM_ID_H,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "I", &retrokbd_state[RETROK_i],ITEM_ID_I,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "J", &retrokbd_state[RETROK_j],ITEM_ID_J,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "K", &retrokbd_state[RETROK_k],ITEM_ID_K,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "L", &retrokbd_state[RETROK_l],ITEM_ID_L,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "M", &retrokbd_state[RETROK_m],ITEM_ID_M,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "N", &retrokbd_state[RETROK_n],ITEM_ID_N,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "O", &retrokbd_state[RETROK_o],ITEM_ID_O,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "P", &retrokbd_state[RETROK_p],ITEM_ID_P,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "Q", &retrokbd_state[RETROK_q],ITEM_ID_Q,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "R", &retrokbd_state[RETROK_r],ITEM_ID_R,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "S", &retrokbd_state[RETROK_s],ITEM_ID_S,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "T", &retrokbd_state[RETROK_t],ITEM_ID_T,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "U", &retrokbd_state[RETROK_u],ITEM_ID_U,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "V", &retrokbd_state[RETROK_v],ITEM_ID_V,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "W", &retrokbd_state[RETROK_w],ITEM_ID_W,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "X", &retrokbd_state[RETROK_x],ITEM_ID_X,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "Y", &retrokbd_state[RETROK_y],ITEM_ID_Y,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "Z", &retrokbd_state[RETROK_z],ITEM_ID_Z,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "0", &retrokbd_state[RETROK_0],ITEM_ID_0,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "1", &retrokbd_state[RETROK_1],ITEM_ID_1,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "2", &retrokbd_state[RETROK_2],ITEM_ID_2,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "3", &retrokbd_state[RETROK_QUOTEDBL/*RETROK_3*/],ITEM_ID_3,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "4", &retrokbd_state[RETROK_4],ITEM_ID_4,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "5", &retrokbd_state[RETROK_5],ITEM_ID_5,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "6", &retrokbd_state[RETROK_6],ITEM_ID_6,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "7", &retrokbd_state[RETROK_7],ITEM_ID_7,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "8", &retrokbd_state[RETROK_8],ITEM_ID_8,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "9", &retrokbd_state[RETROK_9],ITEM_ID_9,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "F1", &retrokbd_state[RETROK_F1],ITEM_ID_F1,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "F2", &retrokbd_state[RETROK_F2],ITEM_ID_F2,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "F3", &retrokbd_state[RETROK_F3],ITEM_ID_F3,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "F4", &retrokbd_state[RETROK_F4],ITEM_ID_F4,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "F5", &retrokbd_state[RETROK_F5],ITEM_ID_F5,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "F6", &retrokbd_state[RETROK_F6],ITEM_ID_F6,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "F7", &retrokbd_state[RETROK_F7],ITEM_ID_F7,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "F8", &retrokbd_state[RETROK_F8],ITEM_ID_F8,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "F9", &retrokbd_state[RETROK_F9],ITEM_ID_F9,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "F10", &retrokbd_state[RETROK_F10],ITEM_ID_F10,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "F11", &retrokbd_state[RETROK_F11],ITEM_ID_F11,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "F12", &retrokbd_state[RETROK_F12],ITEM_ID_F12,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "F13", &retrokbd_state[RETROK_F13],ITEM_ID_F13,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "F14", &retrokbd_state[RETROK_F14],ITEM_ID_F14,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "F15", &retrokbd_state[RETROK_F15],ITEM_ID_F15,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "Esc", &retrokbd_state[RETROK_ESCAPE],ITEM_ID_ESC,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "TILDE", &retrokbd_state[RETROK_TILDE],ITEM_ID_TILDE,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "MINUS", &retrokbd_state[RETROK_MINUS],ITEM_ID_MINUS,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "EQUALS", &retrokbd_state[RETROK_EQUALS],ITEM_ID_EQUALS,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "BKCSPACE", &retrokbd_state[RETROK_BACKSPACE],ITEM_ID_BACKSPACE,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "TAB", &retrokbd_state[RETROK_TAB],ITEM_ID_TAB,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "(", &retrokbd_state[RETROK_LEFTPAREN],ITEM_ID_OPENBRACE,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, ")", &retrokbd_state[RETROK_RIGHTPAREN],ITEM_ID_CLOSEBRACE,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "ENTER", &retrokbd_state[RETROK_RETURN],ITEM_ID_ENTER,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "·", &retrokbd_state[RETROK_COLON],ITEM_ID_COLON,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "\'", &retrokbd_state[RETROK_QUOTE],ITEM_ID_QUOTE,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "BCKSLASH", &retrokbd_state[RETROK_BACKSLASH],ITEM_ID_BACKSLASH,retrokbd_get_state);
|
||||
//input_device_item_add_kbd(retrokbd_device, "BCKSLASH2", &retrokbd_state[RETROK_],ITEM_ID_BACKSLASH2,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, ",", &retrokbd_state[RETROK_COMMA],ITEM_ID_COMMA,retrokbd_get_state);
|
||||
//input_device_item_add_kbd(retrokbd_device, "STOP", &retrokbd_state[RETROK_],ITEM_ID_STOP,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "/", &retrokbd_state[RETROK_SLASH],ITEM_ID_SLASH,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "SPACE", &retrokbd_state[RETROK_SPACE],ITEM_ID_SPACE,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "INS", &retrokbd_state[RETROK_INSERT],ITEM_ID_INSERT,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "DEL", &retrokbd_state[RETROK_DELETE],ITEM_ID_DEL,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "HOME", &retrokbd_state[RETROK_HOME],ITEM_ID_HOME,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "END", &retrokbd_state[RETROK_END],ITEM_ID_END,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "PGUP", &retrokbd_state[RETROK_PAGEUP],ITEM_ID_PGUP,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "PGDW", &retrokbd_state[RETROK_PAGEDOWN],ITEM_ID_PGDN,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "LEFT", &retrokbd_state[RETROK_LEFT],ITEM_ID_LEFT,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "RIGHT", &retrokbd_state[RETROK_RIGHT],ITEM_ID_RIGHT,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "UP", &retrokbd_state[RETROK_UP],ITEM_ID_UP,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "DOWN", &retrokbd_state[RETROK_DOWN],ITEM_ID_DOWN,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "KO", &retrokbd_state[RETROK_KP0],ITEM_ID_0_PAD,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "K1", &retrokbd_state[RETROK_KP1],ITEM_ID_1_PAD,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "K2", &retrokbd_state[RETROK_KP2],ITEM_ID_2_PAD,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "K3", &retrokbd_state[RETROK_KP3],ITEM_ID_3_PAD,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "K4", &retrokbd_state[RETROK_KP4],ITEM_ID_4_PAD,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "K5", &retrokbd_state[RETROK_KP5],ITEM_ID_5_PAD,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "K6", &retrokbd_state[RETROK_KP6],ITEM_ID_6_PAD,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "K7", &retrokbd_state[RETROK_KP7],ITEM_ID_7_PAD,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "K8", &retrokbd_state[RETROK_KP8],ITEM_ID_8_PAD,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "K9", &retrokbd_state[RETROK_KP9],ITEM_ID_9_PAD,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "K/", &retrokbd_state[RETROK_KP_DIVIDE],ITEM_ID_SLASH_PAD,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "K*", &retrokbd_state[RETROK_KP_MULTIPLY],ITEM_ID_ASTERISK,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "K-", &retrokbd_state[RETROK_KP_MINUS],ITEM_ID_MINUS_PAD,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "K+", &retrokbd_state[RETROK_KP_PLUS],ITEM_ID_PLUS_PAD,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "KDEL", &retrokbd_state[RETROK_KP_PERIOD],ITEM_ID_DEL_PAD,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "KRTRN", &retrokbd_state[RETROK_KP_ENTER],ITEM_ID_ENTER_PAD,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "PRINT", &retrokbd_state[RETROK_PRINT],ITEM_ID_PRTSCR,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "PAUSE", &retrokbd_state[RETROK_PAUSE],ITEM_ID_PAUSE,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "LSHFT", &retrokbd_state[RETROK_LSHIFT],ITEM_ID_LSHIFT,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "RSHFT", &retrokbd_state[RETROK_RSHIFT],ITEM_ID_RSHIFT,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "LCTRL", &retrokbd_state[RETROK_LCTRL],ITEM_ID_LCONTROL,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "RCTRL", &retrokbd_state[RETROK_RCTRL],ITEM_ID_RCONTROL,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "LALT", &retrokbd_state[RETROK_LALT],ITEM_ID_LALT,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "RALT", &retrokbd_state[RETROK_RALT],ITEM_ID_RALT,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "SCRLOCK", &retrokbd_state[RETROK_SCROLLOCK],ITEM_ID_SCRLOCK,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "NUMLOCK", &retrokbd_state[RETROK_NUMLOCK],ITEM_ID_NUMLOCK,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "CPSLOCK", &retrokbd_state[RETROK_CAPSLOCK],ITEM_ID_CAPSLOCK,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "LMETA", &retrokbd_state[RETROK_LMETA],ITEM_ID_LWIN,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "RMETA", &retrokbd_state[RETROK_RMETA],ITEM_ID_RWIN,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "MENU", &retrokbd_state[RETROK_MENU],ITEM_ID_MENU,retrokbd_get_state);
|
||||
input_device_item_add_kbd(retrokbd_device, "BREAK", &retrokbd_state[RETROK_BREAK],ITEM_ID_CANCEL,retrokbd_get_state);
|
||||
}
|
||||
|
||||
void retro_poll_mame_input()
|
||||
{
|
||||
input_poll_cb();
|
||||
|
||||
// process_keyboard_state
|
||||
|
||||
/* TODO: handle mods:SHIFT/CTRL/ALT/META/NUMLOCK/CAPSLOCK/SCROLLOCK */
|
||||
unsigned i = 0;
|
||||
do
|
||||
{
|
||||
retrokbd_state[ktable[i].retro_key_name] = input_state_cb(0, RETRO_DEVICE_KEYBOARD, 0,ktable[i].retro_key_name) ? 0x80 : 0;
|
||||
|
||||
if(retrokbd_state[ktable[i].retro_key_name] && retrokbd_state2[ktable[i].retro_key_name] == 0)
|
||||
{
|
||||
ui_ipt_pushchar=ktable[i].retro_key_name;
|
||||
retrokbd_state2[ktable[i].retro_key_name]=1;
|
||||
}
|
||||
else if(!retrokbd_state[ktable[i].retro_key_name] && retrokbd_state2[ktable[i].retro_key_name] == 1)
|
||||
retrokbd_state2[ktable[i].retro_key_name]=0;
|
||||
|
||||
i++;
|
||||
|
||||
}while(ktable[i].retro_key_name!=-1);
|
||||
|
||||
|
||||
if (mouse_enable)
|
||||
{
|
||||
static int mbL=0,mbR=0;
|
||||
|
@ -37,6 +37,8 @@ char g_rom_dir[1024];
|
||||
|
||||
#include "rendersw.c"
|
||||
|
||||
int mame_reset = -1;
|
||||
static int ui_ipt_pushchar=-1;
|
||||
|
||||
static bool mouse_enable = false;
|
||||
static bool videoapproach1_enable = false;
|
||||
@ -126,6 +128,14 @@ static input_device *mouse_device; // MOUSE
|
||||
static UINT16 P1_state[KEY_TOTAL];
|
||||
static UINT16 P2_state[KEY_TOTAL];
|
||||
static UINT16 retrokbd_state[RETROK_LAST];
|
||||
static UINT16 retrokbd_state2[RETROK_LAST];
|
||||
|
||||
struct kt_table
|
||||
{
|
||||
const char * mame_key_name;
|
||||
int retro_key_name;
|
||||
input_item_id mame_key;
|
||||
};
|
||||
static int mouseLX,mouseLY;
|
||||
static int mouseBUT[4];
|
||||
//static int mouse_enabled;
|
||||
@ -147,12 +157,12 @@ static int FirstTimeUpdate = 1;
|
||||
// LIBCO
|
||||
//============================================================
|
||||
int pauseg=0;
|
||||
|
||||
/*
|
||||
#include <libco.h>
|
||||
|
||||
cothread_t mainThread;
|
||||
cothread_t emuThread;
|
||||
|
||||
*/
|
||||
//============================================================
|
||||
// RETRO
|
||||
//============================================================
|
||||
|
@ -149,19 +149,19 @@ void retro_get_system_av_info(struct retro_system_av_info *info)
|
||||
static void retro_wrap_emulator()
|
||||
{
|
||||
mmain(1,RPATH);
|
||||
|
||||
return;
|
||||
pauseg=-1;
|
||||
|
||||
// environ_cb(RETRO_ENVIRONMENT_SHUTDOWN, 0);
|
||||
|
||||
// Were done here
|
||||
co_switch(mainThread);
|
||||
// co_switch(mainThread);
|
||||
|
||||
// Dead emulator, but libco says not to return
|
||||
while(true)
|
||||
{
|
||||
LOGI("Running a dead emulator.");
|
||||
co_switch(mainThread);
|
||||
// co_switch(mainThread);
|
||||
}
|
||||
}
|
||||
|
||||
@ -178,27 +178,36 @@ void retro_init (void){
|
||||
fprintf(stderr, "RGB pixel format is not supported.\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/*
|
||||
if(!emuThread && !mainThread)
|
||||
{
|
||||
mainThread = co_active();
|
||||
emuThread = co_create(65536*sizeof(void*), retro_wrap_emulator);
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
extern void retro_finish();
|
||||
|
||||
void retro_deinit(void)
|
||||
{
|
||||
/*
|
||||
if(emuThread)
|
||||
{
|
||||
co_delete(emuThread);
|
||||
emuThread = 0;
|
||||
}
|
||||
|
||||
LOGI("Retro DeInit\n");
|
||||
*/
|
||||
retro_finish();
|
||||
LOGI("Retro DeInit\n");
|
||||
}
|
||||
|
||||
void retro_reset (void) {}
|
||||
void retro_reset (void) {
|
||||
mame_reset = 1;
|
||||
}
|
||||
|
||||
int RLOOP=1;
|
||||
extern void retro_main_loop();
|
||||
|
||||
void retro_run (void)
|
||||
{
|
||||
@ -206,7 +215,9 @@ void retro_run (void)
|
||||
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated)
|
||||
check_variables();
|
||||
|
||||
retro_main_loop();
|
||||
retro_poll_mame_input();
|
||||
RLOOP=1;
|
||||
|
||||
#ifdef HAVE_GL
|
||||
do_gl2d();
|
||||
@ -217,7 +228,7 @@ void retro_run (void)
|
||||
video_cb(NULL,rtwi, rthe, topw << PITCH);
|
||||
#endif
|
||||
|
||||
co_switch(emuThread);
|
||||
//co_switch(emuThread);
|
||||
}
|
||||
|
||||
void prep_retro_rotation(int rot)
|
||||
@ -225,7 +236,7 @@ void prep_retro_rotation(int rot)
|
||||
LOGI("Rotation:%d\n",rot);
|
||||
environ_cb(RETRO_ENVIRONMENT_SET_ROTATION, &rot);
|
||||
}
|
||||
|
||||
/*
|
||||
static void keyboard_cb(bool down, unsigned keycode, uint32_t character, uint16_t mod)
|
||||
{
|
||||
#ifdef KEYDBG
|
||||
@ -252,12 +263,13 @@ static void keyboard_cb(bool down, unsigned keycode, uint32_t character, uint16_
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
bool retro_load_game(const struct retro_game_info *info)
|
||||
{
|
||||
/*
|
||||
struct retro_keyboard_callback cb = { keyboard_cb };
|
||||
environ_cb(RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK, &cb);
|
||||
|
||||
*/
|
||||
check_variables();
|
||||
|
||||
#ifdef M16B
|
||||
@ -284,6 +296,7 @@ bool retro_load_game(const struct retro_game_info *info)
|
||||
extract_directory(g_rom_dir, info->path, sizeof(g_rom_dir));
|
||||
strcpy(RPATH,info->path);
|
||||
|
||||
retro_wrap_emulator();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -292,7 +305,7 @@ void retro_unload_game(void)
|
||||
if(pauseg==0)
|
||||
{
|
||||
pauseg=-1;
|
||||
co_switch(emuThread);
|
||||
//co_switch(emuThread);
|
||||
}
|
||||
|
||||
LOGI("Retro unload_game\n");
|
||||
|
@ -48,6 +48,12 @@ void osd_update(running_machine *machine,int skip_redraw)
|
||||
const render_primitive_list *primlist;
|
||||
UINT8 *surfptr;
|
||||
|
||||
if (mame_reset == 1)
|
||||
{
|
||||
machine->schedule_soft_reset();
|
||||
mame_reset = -1;
|
||||
}
|
||||
|
||||
if(pauseg==-1){
|
||||
machine->schedule_exit();
|
||||
return;
|
||||
@ -150,8 +156,14 @@ rgb888_draw_primitives(primlist->head, surfptr, rtwi,rthe,rtwi);
|
||||
}
|
||||
else
|
||||
draw_this_frame = false;
|
||||
RLOOP=0;
|
||||
|
||||
co_switch(mainThread);
|
||||
if(ui_ipt_pushchar!=-1)
|
||||
{
|
||||
ui_input_push_char_event(machine, our_target, (unicode_char)ui_ipt_pushchar);
|
||||
ui_ipt_pushchar=-1;
|
||||
}
|
||||
//co_switch(mainThread);
|
||||
}
|
||||
|
||||
//============================================================
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include "options.h"
|
||||
#include "osdepend.h"
|
||||
|
||||
|
||||
extern int RLOOP;
|
||||
//============================================================
|
||||
// TYPE DEFINITIONS
|
||||
//============================================================
|
||||
|
Loading…
Reference in New Issue
Block a user