mirror of
https://github.com/libretro/RetroArch
synced 2025-03-30 07:20:36 +00:00
Add script support to Cg.
This commit is contained in:
parent
a605628dff
commit
884e2881a0
@ -21,6 +21,7 @@
|
|||||||
#include "libsnes.hpp"
|
#include "libsnes.hpp"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "py_state.h"
|
#include "py_state.h"
|
||||||
|
#include "general.h"
|
||||||
|
|
||||||
#define PY_READ_FUNC_DECL(RAMTYPE) py_read_##RAMTYPE
|
#define PY_READ_FUNC_DECL(RAMTYPE) py_read_##RAMTYPE
|
||||||
#define PY_READ_FUNC(RAMTYPE) \
|
#define PY_READ_FUNC(RAMTYPE) \
|
||||||
@ -79,6 +80,9 @@ struct py_state
|
|||||||
PyObject *main;
|
PyObject *main;
|
||||||
PyObject *dict;
|
PyObject *dict;
|
||||||
PyObject *inst;
|
PyObject *inst;
|
||||||
|
|
||||||
|
bool warned_ret;
|
||||||
|
bool warned_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
py_state_t *py_state_new(const char *script_path, const char *pyclass)
|
py_state_t *py_state_new(const char *script_path, const char *pyclass)
|
||||||
@ -139,11 +143,22 @@ int py_state_get(py_state_t *handle, const char *id,
|
|||||||
{
|
{
|
||||||
PyObject *ret = PyObject_CallMethod(handle->inst, (char*)id, (char*)"I", frame_count);
|
PyObject *ret = PyObject_CallMethod(handle->inst, (char*)id, (char*)"I", frame_count);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
|
{
|
||||||
|
if (!handle->warned_ret)
|
||||||
|
SSNES_WARN("Didn't get return value from script! Bug?\n");
|
||||||
|
handle->warned_ret = true;
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
if (PyLong_Check(ret))
|
if (PyLong_Check(ret))
|
||||||
retval = (int)PyLong_AsLong(ret);
|
retval = (int)PyLong_AsLong(ret);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!handle->warned_type)
|
||||||
|
SSNES_WARN("Didn't get long compatible value from script! Bug?\n");
|
||||||
|
handle->warned_type = true;
|
||||||
|
}
|
||||||
|
|
||||||
Py_DECREF(ret);
|
Py_DECREF(ret);
|
||||||
return retval;
|
return retval;
|
||||||
|
@ -374,7 +374,7 @@ error:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool load_imports(config_file_t *conf)
|
static bool load_imports(const char *dir_path, config_file_t *conf)
|
||||||
{
|
{
|
||||||
char *imports = NULL;
|
char *imports = NULL;
|
||||||
|
|
||||||
@ -414,7 +414,7 @@ static bool load_imports(config_file_t *conf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
enum snes_tracker_type tracker_type;
|
enum snes_tracker_type tracker_type;
|
||||||
enum snes_ram_type ram_type;
|
enum snes_ram_type ram_type = SNES_MEMORY_WRAM;
|
||||||
|
|
||||||
if (strcmp(semantic, "capture") == 0)
|
if (strcmp(semantic, "capture") == 0)
|
||||||
tracker_type = SSNES_STATE_CAPTURE;
|
tracker_type = SSNES_STATE_CAPTURE;
|
||||||
@ -424,28 +424,39 @@ static bool load_imports(config_file_t *conf)
|
|||||||
tracker_type = SSNES_STATE_CAPTURE_PREV;
|
tracker_type = SSNES_STATE_CAPTURE_PREV;
|
||||||
else if (strcmp(semantic, "transition_previous") == 0)
|
else if (strcmp(semantic, "transition_previous") == 0)
|
||||||
tracker_type = SSNES_STATE_TRANSITION_PREV;
|
tracker_type = SSNES_STATE_TRANSITION_PREV;
|
||||||
|
#ifdef HAVE_PYTHON
|
||||||
|
else if (strcmp(semantic, "python") == 0)
|
||||||
|
tracker_type = SSNES_STATE_PYTHON;
|
||||||
|
#endif
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SSNES_ERR("Invalid semantic.\n");
|
SSNES_ERR("Invalid semantic.\n");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned addr;
|
unsigned addr = 0;
|
||||||
if (config_get_hex(conf, wram_buf, &addr))
|
#ifdef HAVE_PYTHON
|
||||||
ram_type = SSNES_STATE_WRAM;
|
if (tracker_type != SSNES_STATE_PYTHON)
|
||||||
else if (config_get_hex(conf, apuram_buf, &addr))
|
|
||||||
ram_type = SSNES_STATE_APURAM;
|
|
||||||
else if (config_get_hex(conf, oam_buf, &addr))
|
|
||||||
ram_type = SSNES_STATE_OAM;
|
|
||||||
else if (config_get_hex(conf, cgram_buf, &addr))
|
|
||||||
ram_type = SSNES_STATE_CGRAM;
|
|
||||||
else if (config_get_hex(conf, vram_buf, &addr))
|
|
||||||
ram_type = SSNES_STATE_VRAM;
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
SSNES_ERR("No address assigned to semantic.\n");
|
#endif
|
||||||
goto error;
|
if (config_get_hex(conf, wram_buf, &addr))
|
||||||
|
ram_type = SSNES_STATE_WRAM;
|
||||||
|
else if (config_get_hex(conf, apuram_buf, &addr))
|
||||||
|
ram_type = SSNES_STATE_APURAM;
|
||||||
|
else if (config_get_hex(conf, oam_buf, &addr))
|
||||||
|
ram_type = SSNES_STATE_OAM;
|
||||||
|
else if (config_get_hex(conf, cgram_buf, &addr))
|
||||||
|
ram_type = SSNES_STATE_CGRAM;
|
||||||
|
else if (config_get_hex(conf, vram_buf, &addr))
|
||||||
|
ram_type = SSNES_STATE_VRAM;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SSNES_ERR("No address assigned to semantic.\n");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
#ifdef HAVE_PYTHON
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int memtype = 0;
|
int memtype = 0;
|
||||||
switch (ram_type)
|
switch (ram_type)
|
||||||
@ -501,10 +512,32 @@ static bool load_imports(config_file_t *conf)
|
|||||||
.info_elem = info_cnt
|
.info_elem = info_cnt
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef HAVE_PYTHON
|
||||||
|
char script_path[128];
|
||||||
|
char *script = NULL;
|
||||||
|
char *script_class = NULL;
|
||||||
|
if (config_get_string(conf, "import_script", &script))
|
||||||
|
{
|
||||||
|
strlcpy(script_path, dir_path, sizeof(script_path));
|
||||||
|
strlcat(script_path, script, sizeof(script_path));
|
||||||
|
|
||||||
|
tracker_info.script = script_path;
|
||||||
|
}
|
||||||
|
if (config_get_string(conf, "import_script_class", &script_class))
|
||||||
|
tracker_info.script_class = script_class;
|
||||||
|
#endif
|
||||||
|
|
||||||
snes_tracker = snes_tracker_init(&tracker_info);
|
snes_tracker = snes_tracker_init(&tracker_info);
|
||||||
if (!snes_tracker)
|
if (!snes_tracker)
|
||||||
SSNES_WARN("Failed to init SNES tracker.\n");
|
SSNES_WARN("Failed to init SNES tracker.\n");
|
||||||
|
|
||||||
|
#ifdef HAVE_PYTHON
|
||||||
|
if (script)
|
||||||
|
free(script);
|
||||||
|
if (script_class)
|
||||||
|
free(script_class);
|
||||||
|
#endif
|
||||||
|
|
||||||
free(imports);
|
free(imports);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -752,7 +785,7 @@ static bool load_preset(const char *path)
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!load_imports(conf))
|
if (!load_imports(dir_path, conf))
|
||||||
{
|
{
|
||||||
SSNES_ERR("Failed to load imports ...\n");
|
SSNES_ERR("Failed to load imports ...\n");
|
||||||
goto error;
|
goto error;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user