diff --git a/pkg/worker/caged/libretro/nanoarch/nanoarch.c b/pkg/worker/caged/libretro/nanoarch/nanoarch.c index 4c46963bc..488000787 100644 --- a/pkg/worker/caged/libretro/nanoarch/nanoarch.c +++ b/pkg/worker/caged/libretro/nanoarch/nanoarch.c @@ -3,6 +3,7 @@ #include #include #include +#include int initialized = 0; @@ -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; diff --git a/pkg/worker/caged/libretro/nanoarch/nanoarch.go b/pkg/worker/caged/libretro/nanoarch/nanoarch.go index f334c64eb..ee6d6824b 100644 --- a/pkg/worker/caged/libretro/nanoarch/nanoarch.go +++ b/pkg/worker/caged/libretro/nanoarch/nanoarch.go @@ -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 @@ -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() { @@ -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 { @@ -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 diff --git a/pkg/worker/caged/libretro/nanoarch/nanoarch.h b/pkg/worker/caged/libretro/nanoarch/nanoarch.h index 661036434..dd49b14bb 100644 --- a/pkg/worker/caged/libretro/nanoarch/nanoarch.h +++ b/pkg/worker/caged/libretro/nanoarch/nanoarch.h @@ -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();