From 32aef78600b53c5f8283786fc54496c7d6507f95 Mon Sep 17 00:00:00 2001 From: Alice Date: Mon, 13 Jan 2020 23:09:18 +0100 Subject: [PATCH] core: add BFile_FindFirst, Next and Close syscalls The return code -1 noted in the BFile_FindFirst or BFile_FindNext is from test, which mean it could be possibles that they are negative error code from functions failing and not meaning that no file have been found, to be sure, the value IML_FILEERR_ENUMERATEEND from filebios.h in the fxlib need to be checked (and maybe defined in gint with a more meaningful name for user interactivity) --- include/gint/bfile.h | 37 +++++++++++++++++++++++++++++++++++++ src/core/syscalls.S | 15 +++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/include/gint/bfile.h b/include/gint/bfile.h index 242ec1a..65c9a32 100644 --- a/include/gint/bfile.h +++ b/include/gint/bfile.h @@ -84,4 +84,41 @@ int BFile_Write(int fd, void const *data, int even_size); Returns a BFile error code. */ int BFile_Read(int handle, void *data, int size, int whence); +/* BFile_FindFirst(): Search a directory for file with matching name. + Doesn't work on Main memory. + Only four search handle can be opened, you need to close them to be able to reuse them. + Search is NOT case sensitive and * can be used to match any string. + + @search FONTCHARACTER file path to match + @shandle Search handle to pass to BFile_FindNext or BFile_FindClose + @founfile FONTCHARACTER found file path + @fileinfo Structure containing a lot of information on the found file + Return 0 on success, -1 if no file found, or negative value on error. */ +typedef struct tag_FILE_INFO +{ + unsigned short id; //file index + unsigned short type; //file type + unsigned long fsize; //file size + unsigned long dsize; //date size (file - header) + unsigned int property; //if 0 file complete + unsigned long adress; //top adress of data (direct access is unadvised) +} FILE_INFO; +int BFile_FindFirst(uint16_t const *search, int *shandle, uint16_t *foundfile, FILE_INFO *fileinfo); + +/* BFile_FindNext(): Continue a search a directory for file with matching name. + Only four search handle can be opened, u need to close them to be able to reuse them. + + @shandle Search handle from BFile_FindFirst + @founfile FONTCHARACTER found file path + @fileinfo Structure containing a lot of information on the found file + Return 0 on success, -1 if no file found, or negative value on error. */ +int BFile_FindNext(int shandle, uint16_t *foundfile, FILE_INFO *fileinfo); + +/* BFile_FindClose(): Close the specified search handle + Only four search handle can be opened, u need to close them to be able to reuse them. + + @shandle Search handle from BFile_FindFirst + Return 0 on success or negative value on error. */ +int BFile_FindClose(int shandle); + #endif /* GINT_BFILE */ diff --git a/src/core/syscalls.S b/src/core/syscalls.S index cbf1068..2120dfd 100644 --- a/src/core/syscalls.S +++ b/src/core/syscalls.S @@ -26,6 +26,9 @@ .global _BFile_Size .global _BFile_Write .global _BFile_Read +.global _BFile_FindFirst +.global _BFile_FindNext +.global _BFile_FindClose .section ".pretext" @@ -84,6 +87,18 @@ _BFile_Write: _BFile_Read: syscall(0x0432) +# int BFile_FindFirst(uint16_t const *search, int *shandle, uint16_t *foundfile, FILE_INFO *fileinfo) +_BFile_FindFirst: + syscall(0x043b) + +# int BFile_FindNext(int shandle, uint16_t *foundfile, FILE_INFO *fileinfo) +_BFile_FindNext: + syscall(0x043c) + +# int BFile_FindClose(int shandle) +_BFile_FindClose: + syscall(0x043d) + syscall_table: .long 0x80010070