This commit is contained in:
sergystepanov 2025-11-30 10:37:34 +01:00 committed by GitHub
commit 61067efb5d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 55 additions and 0 deletions

View file

@ -3,6 +3,7 @@
#include <stdbool.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#define RETRO_ENVIRONMENT_GET_CLEAR_ALL_THREAD_WAITS_CB (3 | 0x800000)
@ -182,6 +183,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;

View file

@ -57,6 +57,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
@ -390,6 +391,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) Reset() {
@ -808,6 +814,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 {
@ -936,6 +952,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

View file

@ -31,6 +31,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();