Start VFS implementation ;_;

This commit is contained in:
Sergey Stepanov 2024-08-13 13:16:15 +03:00
parent 61eb55f736
commit 5af7052cb9
No known key found for this signature in database
GPG key ID: A56B4929BAA8556B
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>
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;

View file

@ -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

View file

@ -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();