Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add VFS v3 implementation #469

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions pkg/worker/caged/libretro/nanoarch/nanoarch.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <stdbool.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>

int initialized = 0;

Expand Down Expand Up @@ -185,6 +186,31 @@ void deinit_video_cgo() {
deinitVideo();
}

static const char* vfsGetPath_cgo(struct retro_vfs_file_handle *stream) {
const char* vfsGetPath(struct retro_vfs_file_handle *stream);
return vfsGetPath(stream);
}

static struct retro_vfs_dir_handle* vfsOpenDir_cgo(const char *dir, bool include_hidden) {
struct retro_vfs_dir_handle* vfsOpenDir(const char *dir, bool include_hidden);
return vfsOpenDir(dir, include_hidden);
}

char test[] = "TEST!";

struct retro_vfs_interface* vfs_interface_cgo() {
struct retro_vfs_interface *vfs_i = malloc(sizeof (struct retro_vfs_interface));
if (vfs_i == NULL)
return NULL;

vfs_i->get_path = &vfsGetPath_cgo;
vfs_i->opendir = &vfsOpenDir_cgo;

vfs_i->opendir((const char*)(&test), false);

return vfs_i;
}

typedef struct {
pthread_mutex_t m;
pthread_cond_t cond;
Expand Down
27 changes: 27 additions & 0 deletions pkg/worker/caged/libretro/nanoarch/nanoarch.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type Nanoarch struct {
cSaveDirectory *C.char
cSystemDirectory *C.char
cUserName *C.char
cVfsInterface *C.struct_retro_vfs_interface
Video struct {
gl struct {
enabled bool
Expand Down Expand Up @@ -374,6 +375,11 @@ func (n *Nanoarch) Shutdown() {
C.free(unsafe.Pointer(n.cUserName))
C.free(unsafe.Pointer(n.cSaveDirectory))
C.free(unsafe.Pointer(n.cSystemDirectory))
if n.cVfsInterface != nil {
n.log.Info().Msgf(">>>>>>>>> freeeing vfs interface heappp")
C.free(unsafe.Pointer(n.cVfsInterface))
n.cVfsInterface = nil
}
}

func (n *Nanoarch) Run() {
Expand Down Expand Up @@ -794,6 +800,16 @@ func coreEnvironment(cmd C.unsigned, data unsafe.Pointer) C.bool {
case C.RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY:
*(**C.char)(data) = Nan0.cSaveDirectory
return true
case C.RETRO_ENVIRONMENT_GET_VFS_INTERFACE:
vfs := (*C.struct_retro_vfs_interface_info)(data)
minVer := vfs.required_interface_version
Nan0.log.Info().Msgf("[vfs] required version: %v", minVer)
if Nan0.cVfsInterface != nil {
Nan0.log.Info().Msgf("[vfs] freeing old interface >>> %+v", *Nan0.cVfsInterface)
C.free(unsafe.Pointer(Nan0.cVfsInterface))
}
Nan0.cVfsInterface = C.vfs_interface_cgo()
return true
case C.RETRO_ENVIRONMENT_SET_MESSAGE:
// only with the Libretro debug mode
if Nan0.log.GetLevel() < logger.InfoLevel {
Expand Down Expand Up @@ -940,6 +956,17 @@ func deinitVideo() {
thread.SwitchGraphics(false)
}

//export vfsGetPath
func vfsGetPath(stream *C.struct_retro_vfs_file_handle) *C.char {
return nil
}

//export vfsOpenDir
func vfsOpenDir(dir *C.char, includeHidden C.bool) unsafe.Pointer {
Nan0.log.Info().Msgf(">>>>> Read: %v", C.GoString(dir))
return nil
}

type limit struct {
d time.Duration
t *time.Timer
Expand Down
2 changes: 2 additions & 0 deletions pkg/worker/caged/libretro/nanoarch/nanoarch.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ void core_video_refresh_cgo(void *data, unsigned width, unsigned height, size_t
void init_video_cgo();
void deinit_video_cgo();

struct retro_vfs_interface* vfs_interface_cgo();

void same_thread(void *f);
void *same_thread_with_args2(void *f, int type, void *arg1, void *arg2);
void same_thread_stop();
Expand Down