From 7dcc4b06a6a484946d1c6c1a8fbd64c78089b837 Mon Sep 17 00:00:00 2001 From: Stephanie Gawroriski Date: Sun, 11 Aug 2024 16:12:07 +0000 Subject: [PATCH] Base for seekable open call. --- .idea/modules/squirreljme.iml | 103 +++++++++++++++++++-------------------- nanocoat/include/sjme/native.h | 16 ++++++ nanocoat/include/sjme/rom.h | 14 ++++++ nanocoat/include/sjme/seekable.h | 30 ++++++++++-- nanocoat/lib/base/native.c | 8 +++ nanocoat/lib/base/seekable.c | 21 +++++--- nanocoat/src/boot.c | 28 ++++++++++- nanocoat/src/rom.c | 11 +++++ 8 files changed, 166 insertions(+), 65 deletions(-) diff --git a/.idea/modules/squirreljme.iml b/.idea/modules/squirreljme.iml index 95f6962b3f..4f5f74ad56 100644 --- a/.idea/modules/squirreljme.iml +++ b/.idea/modules/squirreljme.iml @@ -1,10 +1,8 @@ - - - + + - @@ -13,13 +11,9 @@ - - - - @@ -47,24 +41,6 @@ - - - - - - - - - - - - - - - - - - @@ -204,9 +180,6 @@ - - - @@ -237,9 +210,6 @@ - - - @@ -267,9 +237,6 @@ - - - @@ -282,22 +249,12 @@ - - - - - - - - - - @@ -311,12 +268,6 @@ - - - - - - @@ -324,8 +275,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - \ No newline at end of file diff --git a/nanocoat/include/sjme/native.h b/nanocoat/include/sjme/native.h index ebeaca4b91..e5016b345c 100644 --- a/nanocoat/include/sjme/native.h +++ b/nanocoat/include/sjme/native.h @@ -18,6 +18,7 @@ #include "sjme/stdTypes.h" #include "sjme/error.h" +#include "sjme/seekable.h" /* Anti-C++. */ #ifdef __cplusplus @@ -43,6 +44,18 @@ typedef sjme_errorCode (*sjme_nal_currentTimeMillisFunc)( sjme_attrCheckReturn; /** + * Opens the given file natively. + * + * @param inPath The path to open. + * @param outSeekable The seekable to open within. + * @return Any resultant error, if any. + * @since 2024/08/11 + */ +typedef sjme_errorCode (*sjme_nal_fileOpenFunc)( + sjme_attrInNotNull sjme_lpcstr inPath, + sjme_attrOutNotNull sjme_seekable* outSeekable); + +/** * Reads from the system environment a variable. * * @param buf The output buffer. @@ -92,6 +105,9 @@ typedef struct sjme_nal /** Current time in milliseconds. */ sjme_nal_currentTimeMillisFunc currentTimeMillis; + /** Opens a given native file. */ + sjme_nal_fileOpenFunc fileOpen; + /** Get environment variable. */ sjme_nal_getEnvFunc getEnv; diff --git a/nanocoat/include/sjme/rom.h b/nanocoat/include/sjme/rom.h index 8d30b5c4b4..8a717a968e 100644 --- a/nanocoat/include/sjme/rom.h +++ b/nanocoat/include/sjme/rom.h @@ -552,6 +552,20 @@ sjme_errorCode sjme_rom_suiteFromPayload( sjme_attrInNotNull const sjme_payload_config* payloadConfig); /** + * Initializes a suite from a Zip. + * + * @param pool The pool to use for allocations. + * @param outSuite The resultant suite. + * @param seekable The seekable to access the Zip through. + * @return Any resultant error, if any. + * @since 2024/08/11 + */ +sjme_errorCode sjme_rom_suiteFromZipSeekable( + sjme_attrInNotNull sjme_alloc_pool* pool, + sjme_attrOutNotNull sjme_rom_suite* outSuite, + sjme_attrInNotNull sjme_seekable seekable); + +/** * Returns all of the libraries which are available within this suite. * * @param inSuite The input suite. diff --git a/nanocoat/include/sjme/seekable.h b/nanocoat/include/sjme/seekable.h index a3f3ed8d03..522eca72a4 100644 --- a/nanocoat/include/sjme/seekable.h +++ b/nanocoat/include/sjme/seekable.h @@ -35,30 +35,30 @@ extern "C" { * * @since 2024/01/01 */ -typedef struct sjme_seekableCore sjme_seekableCore; +typedef struct sjme_seekableBase sjme_seekableBase; /** * Opaque seekable data. * * @since 2024/01/01 */ -typedef struct sjme_seekableCore* sjme_seekable; +typedef struct sjme_seekableBase* sjme_seekable; /** * Seekable lock core structure. * * @since 2024/01/01 */ -typedef struct sjme_seekable_lockCore sjme_seekable_lockCore; +typedef struct sjme_seekable_lockBase sjme_seekable_lockBase; /** * Opaque locked seekable structure. * * @since 2024/01/01 */ -typedef struct sjme_seekable_lockCore* sjme_seekable_lock; +typedef struct sjme_seekable_lockBase* sjme_seekable_lock; -struct sjme_seekable_lockCore +struct sjme_seekable_lockBase { /** The owning seekable. */ sjme_seekable seekable; @@ -99,6 +99,16 @@ typedef enum sjme_seekable_unlockAction } sjme_seekable_unlockAction; /** + * Functions for seekable implementations. + * + * @since 2024/08/11 + */ +typedef struct sjme_seekable_functions +{ + int todo; +} sjme_seekable_functions; + +/** * Provides an input stream to read data from a seekable, note that * unlike @c sjme_seekable_regionLockAsInputStream there is no locking * involved and as such there may be a performance penalty or otherwise. @@ -117,6 +127,16 @@ sjme_errorCode sjme_seekable_asInputStream( sjme_attrInPositive sjme_jint length); /** + * Closes the given seekable. + * + * @param seekable The seekable to close. + * @return Any resultant error, if any. + * @since 2024/08/11 + */ +sjme_errorCode sjme_seekable_close( + sjme_attrInNotNull sjme_seekable seekable); + +/** * Initializes a seekable from the given memory range. * * @param inPool The pool to allocate within. diff --git a/nanocoat/lib/base/native.c b/nanocoat/lib/base/native.c index be12f0528e..9af81015bc 100644 --- a/nanocoat/lib/base/native.c +++ b/nanocoat/lib/base/native.c @@ -31,6 +31,13 @@ #include "sjme/native.h" +static sjme_errorCode sjme_nal_default_fileOpen( + sjme_attrInNotNull sjme_lpcstr inPath, + sjme_attrOutNotNull sjme_seekable* outSeekable) +{ + return sjme_error_notImplemented(0); +} + static sjme_errorCode sjme_nal_default_getEnv( sjme_attrInNotNull sjme_attrOutNotNullBuf(len) sjme_lpstr buf, sjme_attrInPositiveNonZero sjme_jint bufLen, @@ -157,6 +164,7 @@ static sjme_errorCode sjme_nal_default_stdOutF( const sjme_nal sjme_nal_default = { .currentTimeMillis = NULL, + .fileOpen = sjme_nal_default_fileOpen, .getEnv = sjme_nal_default_getEnv, .nanoTime = sjme_nal_default_nanoTime, .stdErrF = sjme_nal_default_stdErrF, diff --git a/nanocoat/lib/base/seekable.c b/nanocoat/lib/base/seekable.c index fcd7c71117..fb38809eee 100644 --- a/nanocoat/lib/base/seekable.c +++ b/nanocoat/lib/base/seekable.c @@ -23,7 +23,16 @@ sjme_errorCode sjme_seekable_asInputStream( return SJME_ERROR_INDEX_OUT_OF_BOUNDS; sjme_todo("Implement this?"); - return SJME_ERROR_NOT_IMPLEMENTED; + return sjme_error_notImplemented(0); +} + +sjme_errorCode sjme_seekable_close( + sjme_attrInNotNull sjme_seekable seekable) +{ + if (seekable == NULL) + return SJME_ERROR_NULL_ARGUMENTS; + + return sjme_error_notImplemented(0); } sjme_errorCode sjme_seekable_fromMemory( @@ -43,7 +52,7 @@ sjme_errorCode sjme_seekable_fromMemory( return SJME_ERROR_INDEX_OUT_OF_BOUNDS; sjme_todo("Implement this?"); - return SJME_ERROR_NOT_IMPLEMENTED; + return sjme_error_notImplemented(0); } sjme_errorCode sjme_seekable_fromSeekable( @@ -59,7 +68,7 @@ sjme_errorCode sjme_seekable_fromSeekable( return SJME_ERROR_INDEX_OUT_OF_BOUNDS; sjme_todo("Implement this?"); - return SJME_ERROR_NOT_IMPLEMENTED; + return sjme_error_notImplemented(0); } sjme_errorCode sjme_seekable_regionLock( @@ -75,7 +84,7 @@ sjme_errorCode sjme_seekable_regionLock( return SJME_ERROR_INDEX_OUT_OF_BOUNDS; sjme_todo("Implement this?"); - return SJME_ERROR_NOT_IMPLEMENTED; + return sjme_error_notImplemented(0); } sjme_errorCode sjme_seekable_regionLockAsInputStream( @@ -91,7 +100,7 @@ sjme_errorCode sjme_seekable_regionLockAsInputStream( return SJME_ERROR_INDEX_OUT_OF_BOUNDS; sjme_todo("Implement this?"); - return SJME_ERROR_NOT_IMPLEMENTED; + return sjme_error_notImplemented(0); } sjme_errorCode sjme_seekable_regionUnlock( @@ -106,5 +115,5 @@ sjme_errorCode sjme_seekable_regionUnlock( return SJME_ERROR_INVALID_ARGUMENT; sjme_todo("Implement this?"); - return SJME_ERROR_NOT_IMPLEMENTED; + return sjme_error_notImplemented(0); } diff --git a/nanocoat/src/boot.c b/nanocoat/src/boot.c index 7f2e08ae60..189f15e23f 100644 --- a/nanocoat/src/boot.c +++ b/nanocoat/src/boot.c @@ -309,10 +309,16 @@ sjme_errorCode sjme_nvm_defaultBootSuite( { sjme_errorCode error; sjme_cchar dataPath[SJME_MAX_PATH]; + sjme_seekable rom; + sjme_rom_suite result; if (inPool == NULL || nal == NULL || outSuite == NULL) return SJME_ERROR_NULL_ARGUMENTS; + /* We cannot load if filesystem access is not supported. */ + if (nal->fileOpen == NULL) + return SJME_ERROR_NOT_IMPLEMENTED; + /* Initialize. */ memset(&dataPath, 0, sizeof(dataPath)); @@ -328,7 +334,27 @@ sjme_errorCode sjme_nvm_defaultBootSuite( SJME_JAR_NAME, INT32_MAX))) return sjme_error_default(error); - return sjme_error_notImplemented(0); + /* Open main ROM file. */ + rom = NULL; + if (sjme_error_is(error = nal->fileOpen(dataPath, + &rom)) || rom == NULL) + return sjme_error_default(error); + + /* Load suite from the ZIP. */ + result = NULL; + if (sjme_error_is(error = sjme_rom_suiteFromZipSeekable(inPool, + &result, rom)) || result == NULL) + { + /* Make sure to close the file. */ + sjme_seekable_close(rom); + + /* Fail. */ + return sjme_error_default(error); + } + + /* Success! */ + *outSuite = result; + return SJME_ERROR_NONE; } sjme_errorCode sjme_nvm_defaultDir( diff --git a/nanocoat/src/rom.c b/nanocoat/src/rom.c index fd35e5546e..e54f4e1333 100644 --- a/nanocoat/src/rom.c +++ b/nanocoat/src/rom.c @@ -544,6 +544,17 @@ sjme_errorCode sjme_rom_suiteFromPayload( return SJME_ERROR_UNKNOWN; } +sjme_errorCode sjme_rom_suiteFromZipSeekable( + sjme_attrInNotNull sjme_alloc_pool* pool, + sjme_attrOutNotNull sjme_rom_suite* outSuite, + sjme_attrInNotNull sjme_seekable seekable) +{ + if (pool == NULL || outSuite == NULL || seekable == NULL) + return SJME_ERROR_NULL_ARGUMENTS; + + return sjme_error_notImplemented(0); +} + sjme_errorCode sjme_rom_suiteNew( sjme_attrInNotNull sjme_alloc_pool* pool, sjme_attrOutNotNull sjme_rom_suite* outSuite, -- 2.11.4.GIT