mirror of
https://github.com/d0k3/GodMode9.git
synced 2025-06-26 13:42:47 +00:00
Improve virtual.c / virtual.h code
This commit is contained in:
parent
2a5a738765
commit
e38da8a4a8
@ -1,7 +1,6 @@
|
||||
#include "fsinit.h"
|
||||
#include "fsdrive.h"
|
||||
#include "virtual.h"
|
||||
#include "vgame.h"
|
||||
#include "sddata.h"
|
||||
#include "image.h"
|
||||
#include "ff.h"
|
||||
@ -45,7 +44,7 @@ bool InitImgFS(const char* path) {
|
||||
}
|
||||
// (re)mount image, done if path == NULL
|
||||
MountImage(path);
|
||||
InitVGameDrive();
|
||||
InitVirtualImageDrive();
|
||||
if (!GetMountState()) return false;
|
||||
// reinit image filesystem
|
||||
for (u32 i = NORM_FS - IMGN_FS; i < NORM_FS; i++) {
|
||||
|
@ -8,8 +8,7 @@ typedef struct {
|
||||
u32 virtual_src;
|
||||
} __attribute__((packed)) VirtualDrive;
|
||||
|
||||
static const VirtualDrive virtualDrives[] =
|
||||
{ {'S', VRT_SYSNAND}, {'E', VRT_EMUNAND}, {'I', VRT_IMGNAND}, {'X', VRT_XORPAD }, {'M', VRT_MEMORY}, {'G', VRT_GAME} };
|
||||
static const VirtualDrive virtualDrives[] = { VRT_DRIVES };
|
||||
|
||||
u32 GetVirtualSource(const char* path) {
|
||||
// check path validity
|
||||
@ -21,6 +20,10 @@ u32 GetVirtualSource(const char* path) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool InitVirtualImageDrive(void) {
|
||||
return InitVGameDrive();
|
||||
}
|
||||
|
||||
bool CheckVirtualDrive(const char* path) {
|
||||
u32 virtual_src = GetVirtualSource(path);
|
||||
if (virtual_src & (VRT_EMUNAND|VRT_IMGNAND))
|
||||
@ -62,8 +65,14 @@ bool OpenVirtualDir(VirtualDir* vdir, VirtualFile* ventry) {
|
||||
u32 virtual_src = ventry->flags & VRT_SOURCE;
|
||||
if (ventry->flags & VFLAG_ROOT)
|
||||
return OpenVirtualRoot(vdir, virtual_src);
|
||||
if (!(virtual_src & VRT_GAME)) return false; // no subdirs in other virtual sources
|
||||
if (virtual_src & VRT_GAME) {
|
||||
if (!OpenVGameDir(vdir, ventry)) return false;
|
||||
} else {
|
||||
vdir->index = -1;
|
||||
vdir->offset = ventry->offset;
|
||||
vdir->size = ventry->size;
|
||||
vdir->flags = ventry->flags;
|
||||
}
|
||||
vdir->flags |= virtual_src;
|
||||
vdir->virtual_src = virtual_src;
|
||||
return true;
|
||||
@ -146,8 +155,7 @@ bool GetVirtualFilename(char* name, const VirtualFile* vfile, u32 n_chars) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int ReadVirtualFile(const VirtualFile* vfile, u8* buffer, u32 offset, u32 count, u32* bytes_read) /// (u64) !!!!
|
||||
{
|
||||
int ReadVirtualFile(const VirtualFile* vfile, u8* buffer, u32 offset, u32 count, u32* bytes_read) {
|
||||
// basic check of offset / count
|
||||
if (offset >= vfile->size)
|
||||
return 0;
|
||||
@ -166,8 +174,7 @@ int ReadVirtualFile(const VirtualFile* vfile, u8* buffer, u32 offset, u32 count,
|
||||
return -1;
|
||||
}
|
||||
|
||||
int WriteVirtualFile(const VirtualFile* vfile, const u8* buffer, u32 offset, u32 count, u32* bytes_written)
|
||||
{
|
||||
int WriteVirtualFile(const VirtualFile* vfile, const u8* buffer, u32 offset, u32 count, u32* bytes_written) {
|
||||
// basic check of offset / count
|
||||
if (offset >= vfile->size)
|
||||
return 0;
|
||||
|
@ -18,6 +18,9 @@
|
||||
#define VFLAG_A9LH_AREA (1<<18)
|
||||
#define VFLAG_LV3 (1<<19)
|
||||
|
||||
#define VRT_DRIVES {'S', VRT_SYSNAND}, {'E', VRT_EMUNAND}, {'I', VRT_IMGNAND}, \
|
||||
{'X', VRT_XORPAD }, {'M', VRT_MEMORY}, {'G', VRT_GAME}
|
||||
|
||||
// virtual file flag (subject to change):
|
||||
// bits 0...9 : reserved for NAND virtual sources and info
|
||||
// bits 10...15: reserved for other virtual sources
|
||||
@ -41,6 +44,7 @@ typedef struct {
|
||||
} __attribute__((packed)) VirtualDir;
|
||||
|
||||
u32 GetVirtualSource(const char* path);
|
||||
bool InitVirtualImageDrive(void);
|
||||
bool CheckVirtualDrive(const char* path);
|
||||
|
||||
bool ReadVirtualDir(VirtualFile* vfile, VirtualDir* vdir);
|
||||
|
Loading…
x
Reference in New Issue
Block a user