Compare commits

..

No commits in common. "416331d48bde4085cae94127a3cb9e5f3538e33c" and "dff487b20a49e50ad18d316dde0fe429f89f87e2" have entirely different histories.

19 changed files with 67 additions and 395 deletions

View file

@ -64,13 +64,8 @@
extern "C" { extern "C" {
#endif #endif
#include <gint/config.h>
#include <stdint.h> #include <stdint.h>
// BFile has a different interface on CP-400, which is not exposed by gint
// because the standard API is always available.
#if !GINT_OS_CP
//--- //---
// Common file access functions // Common file access functions
//--- //---
@ -313,8 +308,6 @@ int BFile_FindClose(int shandle);
/* BFile_Ext_Stat(): Stat an entry for type and size */ /* BFile_Ext_Stat(): Stat an entry for type and size */
int BFile_Ext_Stat(uint16_t const *path, int *type, int *size); int BFile_Ext_Stat(uint16_t const *path, int *type, int *size);
#endif /* !GINT_OS_CP */
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

@ -23,9 +23,6 @@ void r61523_display_rect(
/* r61523_win_set(): Set the display window */ /* r61523_win_set(): Set the display window */
void r61523_win_set(int x1, int x2, int y1, int y2); void r61523_win_set(int x1, int x2, int y1, int y2);
/* r61523_set_pixel(): Write a pixel directly to DD (slow) */
void r61523_set_pixel(int x, int y, int color);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

@ -1,10 +1,6 @@
#include <gint/bfile.h> #include <gint/bfile.h>
#include "util.h" #include "util.h"
#include "bfilecp.h"
// TODO: BFile_Ext_Stat: Use native stat function on CP-400?
// Unlike find functions, it doesn't provide type, as per documented API at
// least, and stat really needs it. So for now I'm sticking to the find check.
int BFile_Ext_Stat(uint16_t const *path, int *type, int *size) int BFile_Ext_Stat(uint16_t const *path, int *type, int *size)
{ {
int search_handle, rc; int search_handle, rc;

View file

@ -1,121 +0,0 @@
// CP version of the BFile interface, which is much closer to POSIX.
// Functions not available elsewhere that could be useful for optimization:
// fstat, getAddr
#ifndef GINT_FS_BFILECP_H
#define GINT_FS_BFILECP_H
#ifdef __cplusplus
extern "C" {
#endif
#include <gint/config.h>
// Only for CP, obviously.
#if GINT_OS_CP
#define BFileCP_ENOMEM -1
#define BFileCP_EINVAL -2
#define BFileCP_EDEVFAIL -3
#define BFileCP_EMOUNTED -4
#define BFileCP_EACCES -5
#define BFileCP_EBADFSID -6
#define BFileCP_ENOVOLUME -7
#define BFileCP_ENOPATH -8
#define BFileCP_EEXIST -9
#define BFileCP_ENAMETOOLONG -10
#define BFileCP_EOUTOFBOUND -11
#define BFileCP_EUNFORMAT -12
#define BFileCP_ENOSPC -13
#define BFileCP_ENOENT -14
#define BFileCP_EISDIRECTORY -15
#define BFileCP_ESHARE -16
#define BFileCP_EMFILE -17
#define BFileCP_EBADF -18
#define BFileCP_EEOF -19
#define BFileCP_ENOTEMPTY -20
#define BFileCP_ECLUSTERSIZEMISMATCH -40
#define BFileCP_ESYSTEM -99
#define BFile_ReadOnly 0x01
#define BFile_WriteOnly 0x02
#define BFile_ReadWrite (BFile_ReadOnly | BFile_WriteOnly)
#define BFile_CreateFlag 0x04
#define BFile_AppendFlag 0x10
int BFile_Open(const char *path, int flags);
int BFile_Read(int fd, void *buf, int size);
int BFile_Write(int fd, void const *buf, int size);
#define BFileCP_SEEK_SET 0
#define BFileCP_SEEK_CUR 1
#define BFileCP_SEEK_END 2
int BFile_Seek(int fd, int offset, int whence);
int BFile_Close(int fd);
int BFile_Remove(char const *path);
int BFile_Rename(char const *oldpath, char const *newpath);
int BFile_Mkdir(char const *path);
//---
// Metadata API
//---
// Dates are bitfields { year-1980: 8; month-1-12: 4; day-1-31: 4; }
// Times are bitfields { hour: 5; minute: 6; seconds_div2: 5; }
struct BFile_Statbuf {
u32 _1;
u32 size; // file size in bytes
u16 creationDate;
u16 creationTime;
u16 lastModifiedDate;
u16 lastModifiedTime;
u16 _2;
u16 lastAccessDate;
};
int BFile_FStat(int fd, struct BFile_Statbuf *statbuf);
// For API compatibility with older models.
static inline int BFile_Size(int fd) {
struct BFile_Statbuf statbuf;
int rc = BFile_FStat(fd, &statbuf);
return (rc >= 0) ? (int)statbuf.size : rc;
}
int BFile_Stat(const char *path, struct BFile_Statbuf *statbuf);
// Same as legacy, uses find API.
int BFile_Ext_Stat(uint16_t const *path, int *type, int *size);
//---
// Search API
//---
#define BFile_Type_File 1
#define BFile_Type_Directory 5
struct BFile_FileInfo {
u32 _1;
u16 type; /* 1=File, 5=Directory */
u16 _2;
u32 file_size; /* in bytes; 0 for folders */
u32 _3, _4;
};
// Same as legacy.
int BFile_FindFirst(u16 const *pattern, int *shandle, u16 *foundfile,
struct BFile_FileInfo *fileinfo);
int BFile_FindNext(
int shandle, u16 *foundfile, struct BFile_FileInfo *fileinfo);
int BFile_FindClose(int shandle);
#endif /* GINT_OS_CP */
#ifdef __cplusplus
}
#endif
#endif /* GINT_FS_BFILECP_H */

View file

@ -8,7 +8,6 @@
#include <errno.h> #include <errno.h>
#include "fugue.h" #include "fugue.h"
#include "util.h" #include "util.h"
#include "bfilecp.h"
ssize_t fugue_read(void *data0, void *buf, size_t size) ssize_t fugue_read(void *data0, void *buf, size_t size)
{ {
@ -20,11 +19,7 @@ ssize_t fugue_read(void *data0, void *buf, size_t size)
if(data->pos + (int)size > filesize) if(data->pos + (int)size > filesize)
size = filesize - data->pos; size = filesize - data->pos;
#if GINT_OS_CP
int rc = BFile_Read(fugue_fd, buf, size);
#else
int rc = BFile_Read(fugue_fd, buf, size, -1); int rc = BFile_Read(fugue_fd, buf, size, -1);
#endif
if(rc < 0) { if(rc < 0) {
errno = bfile_error_to_errno(rc); errno = bfile_error_to_errno(rc);
return -1; return -1;
@ -105,19 +100,6 @@ off_t fugue_lseek(void *data0, off_t offset, int whence)
fugue_fd_t *data = data0; fugue_fd_t *data = data0;
int fugue_fd = data->fd; int fugue_fd = data->fd;
// TODO: fugue_lseek: CP400 optimization with native whence?
#if GINT_OS_CP
whence = (whence == SEEK_SET) ? BFileCP_SEEK_SET :
(whence == SEEK_CUR) ? BFileCP_SEEK_CUR :
BFileCP_SEEK_END;
int rc = BFile_Seek(fugue_fd, offset, whence);
if(rc < 0) {
errno = bfile_error_to_errno(rc);
return -1;
}
data->pos = rc;
return rc;
#else
int filesize = BFile_Size(fugue_fd); int filesize = BFile_Size(fugue_fd);
if(whence == SEEK_CUR) if(whence == SEEK_CUR)
@ -139,7 +121,6 @@ off_t fugue_lseek(void *data0, off_t offset, int whence)
/* rc is the amount of space left in the file (including pre-allocated /* rc is the amount of space left in the file (including pre-allocated
space), so instead just return offset directly */ space), so instead just return offset directly */
return offset; return offset;
#endif
} }
int fugue_close(void *data0) int fugue_close(void *data0)

View file

@ -9,7 +9,6 @@
#include <string.h> #include <string.h>
#include "util.h" #include "util.h"
#include "fugue.h" #include "fugue.h"
#include "bfilecp.h"
typedef struct typedef struct
{ {
@ -117,11 +116,7 @@ void *fugue_dir_explore(char const *path)
rc = BFile_FindFirst(search, &sd, fc_path, &info); rc = BFile_FindFirst(search, &sd, fc_path, &info);
if(rc < 0) { if(rc < 0) {
#if GINT_OS_CP
if(rc != BFileCP_ENOENT) // BFileCP_EOUTOFBOUND?
#else
if(rc != BFile_EntryNotFound) if(rc != BFile_EntryNotFound)
#endif
errno = bfile_error_to_errno(rc); errno = bfile_error_to_errno(rc);
goto error; goto error;
} }

View file

@ -3,22 +3,11 @@
#include <gint/fs.h> #include <gint/fs.h>
#include <errno.h> #include <errno.h>
#include "util.h" #include "util.h"
#include "bfilecp.h"
int fugue_mkdir(char const *path, GUNUSED mode_t mode) int fugue_mkdir(char const *path, GUNUSED mode_t mode)
{ {
ENOTSUP_IF_NOT_FUGUE(-1); ENOTSUP_IF_NOT_FUGUE(-1);
#if GINT_OS_CP
char *normpath = fs_path_normalize_opt(path, "\\fls0\\", '\\');
if(!normpath) {
errno = ENOMEM;
return -1;
}
int rc = BFile_Mkdir(normpath);
free(normpath);
#else
uint16_t *fcpath = fs_path_normalize_fc(path); uint16_t *fcpath = fs_path_normalize_fc(path);
if(!fcpath) { if(!fcpath) {
errno = ENOMEM; errno = ENOMEM;
@ -26,12 +15,12 @@ int fugue_mkdir(char const *path, GUNUSED mode_t mode)
} }
int rc = BFile_Create(fcpath, BFile_Folder, NULL); int rc = BFile_Create(fcpath, BFile_Folder, NULL);
free(fcpath);
#endif
if(rc < 0) { if(rc < 0) {
errno = bfile_error_to_errno(rc); errno = bfile_error_to_errno(rc);
rc = -1; free(fcpath);
return -1;
} }
return rc;
free(fcpath);
return 0;
} }

View file

@ -5,54 +5,38 @@
#include <string.h> #include <string.h>
#include "util.h" #include "util.h"
#include "fugue.h" #include "fugue.h"
#include "bfilecp.h"
GUNUSED static int new_file_size; static int new_file_size;
int fugue_open(char const *path, int flags, GUNUSED mode_t mode) int fugue_open(char const *path, int flags, GUNUSED mode_t mode)
{ {
ENOTSUP_IF_NOT_FUGUE(-1); ENOTSUP_IF_NOT_FUGUE(-1);
uint16_t *fcpath = fs_path_normalize_fc(path); uint16_t *fcpath = fs_path_normalize_fc(path);
int fugue_fd, rc=-1, type, fd=-1; int fugue_fd, err, rc=-1, type, fd=-1;
if(!fcpath) { if(!fcpath) {
errno = ENOMEM; errno = ENOMEM;
return -1; return -1;
} }
#if GINT_OS_CP
char *normpath = fs_path_normalize_opt(path, "\\fls0\\", '\\');
if(!normpath) {
errno = ENOMEM;
free(fcpath);
return -1;
}
# define NORMALIZED_PATH normpath
#else
# define NORMALIZED_PATH fcpath
#endif
/* Open mode */ /* Open mode */
int bfile_mode = BFile_ReadOnly; int bfile_mode = BFile_ReadOnly;
if(flags & O_WRONLY) if(flags & O_WRONLY)
bfile_mode = BFile_WriteOnly; bfile_mode = BFile_WriteOnly;
else if(flags & O_RDWR) else if(flags & O_RDWR)
bfile_mode = BFile_ReadWrite; bfile_mode = BFile_ReadWrite;
#if GINT_OS_CP
if(flags & O_APPEND) /* Exclusive open means no sense unless creation is also requested */
bfile_mode |= BFile_AppendFlag; bool excl = (flags & O_EXCL) && (flags & O_CREAT);
#endif /* Truncation requires the file to be removed/recreated */
bool trunc = (flags & O_TRUNC) && (flags & O_CREAT);
/* Stat the entry. A special case is needed for the root, which doesn't /* Stat the entry. A special case is needed for the root, which doesn't
respond well. fs_path_normalize_fc() normalizes the path so we just respond well. fs_path_normalize_fc() normalizes the path so we just
have to check for the fixed string "\\fls0\". */ have to check for the fixed string "\\fls0\". */
bool exists; bool exists;
#if GINT_OS_CP
if(!memcmp(fcpath, u"\\fls0\\", 14)) {
#else
if(!memcmp(fcpath, u"\\\\fls0\\", 16)) { if(!memcmp(fcpath, u"\\\\fls0\\", 16)) {
#endif
exists = true; exists = true;
type = BFile_Type_Directory; type = BFile_Type_Directory;
} }
@ -61,9 +45,8 @@ int fugue_open(char const *path, int flags, GUNUSED mode_t mode)
if(!exists) type = -1; if(!exists) type = -1;
} }
/* O_EXCL: Succeed *only* if we're creating the file. Only has an /* If the entry exists and O_EXCL was requested, fail. */
effect when combined with O_CREAT, unsurprisingly. */ if(exists && excl) {
if(exists && (flags & O_EXCL) && (flags & O_CREAT)) {
errno = EEXIST; errno = EEXIST;
rc = -1; rc = -1;
goto end; goto end;
@ -93,57 +76,48 @@ int fugue_open(char const *path, int flags, GUNUSED mode_t mode)
goto end; goto end;
} }
/* We now have a regular file. Before opening it, we may need to: /* Try and open the file normally, unless O_TRUNC is specified without
1. Delete it to truncate it (BFile never truncates AFAIK) O_EXCL, in which case we simply delete and recreate the file. */
- If O_TRUNC and the file exists (obviously). if(trunc)
- Deleting and recreating for truncation purposes is allowed when fugue_fd = BFile_EntryNotFound;
not setting O_CREAT. In case of error midway, good luck. else
2. Create it (except fx-CP 400 which can create in BFile_Open()) fugue_fd = BFile_Open(fcpath, bfile_mode);
- If it didn't exist and O_CREAT was allowed; or
- if it did exist but was removed for truncation in step 1.
3. Finally, open the file. */
/* Delete for truncation. */ /* If O_TRUNC is requested and either the file exists or we can create
if((flags & O_TRUNC) && exists) { it, remove it. (If fugue_fd < 0 an opening error might still have
BFile_Remove(NORMALIZED_PATH); occurred so we delete it just in case.) */
/* Whatever happens now, allow recreating the file. */ if((flags & O_TRUNC) && (fugue_fd >= 0 || (flags & O_CREAT))) {
exists = false; if(fugue_fd >= 0)
flags |= O_CREAT; BFile_Close(fugue_fd);
BFile_Remove(fcpath);
fugue_fd = BFile_EntryNotFound;
} }
/* Create the file now, either directly with BFile_Create(), or with /* If the file does not exist and O_CREAT is set, create it */
the appropriate flag on fx-CP 400. */ if((flags & O_CREAT) && ((flags & O_TRUNC) || fugue_fd < 0)) {
if((flags & O_CREAT) && !exists) { new_file_size = 0;
#if GINT_OS_CP err = BFile_Create(fcpath, BFile_File, &new_file_size);
bfile_mode |= BFile_CreateFlag;
#else
int err = BFile_Create(fcpath, BFile_File, &new_file_size);
if(err < 0) { if(err < 0) {
errno = bfile_error_to_errno(err); errno = bfile_error_to_errno(err);
rc = -1; rc = -1;
goto end; goto end;
} }
#endif fugue_fd = BFile_Open(fcpath, bfile_mode);
} }
/* Proceed with the final BFile_Open() call. */
fugue_fd = BFile_Open(NORMALIZED_PATH, bfile_mode);
if(fugue_fd < 0) { if(fugue_fd < 0) {
errno = bfile_error_to_errno(fugue_fd); errno = bfile_error_to_errno(fugue_fd);
rc = -1; rc = fugue_fd;
goto end; goto end;
} }
/* If O_APPEND is set, move to the end of the file */ /* If O_APPEND is set, move to the end of the file */
// TODO: O_APPEND should move the cursor before *each* write // TODO: O_APPEND should move the cursor before *each* write
int pos = 0; int pos = 0;
#if !GINT_OS_CP
if((flags & O_APPEND)) { if((flags & O_APPEND)) {
pos = BFile_Size(fugue_fd); pos = BFile_Size(fugue_fd);
BFile_Seek(fugue_fd, pos); BFile_Seek(fugue_fd, pos);
} }
#endif
/* Return the now-open file descriptor */ /* Return the now-open file descriptor */
fugue_fd_t *data = malloc(sizeof *data); fugue_fd_t *data = malloc(sizeof *data);
@ -168,9 +142,6 @@ int fugue_open(char const *path, int flags, GUNUSED mode_t mode)
} }
end: end:
#if GINT_OS_CP
free(normpath);
#endif
free(fcpath); free(fcpath);
return rc; return rc;
} }

View file

@ -4,35 +4,35 @@
#include <errno.h> #include <errno.h>
#include <sys/stat.h> #include <sys/stat.h>
#include "util.h" #include "util.h"
#include "bfilecp.h"
int fugue_rename(char const *oldpath, char const *newpath) int fugue_rename(char const *oldpath, char const *newpath)
{ {
ENOTSUP_IF_NOT_FUGUE(-1); ENOTSUP_IF_NOT_FUGUE(-1);
int rc = -1;
#if GINT_OS_CP uint16_t *fcpath_1 = NULL;
int rc = BFile_Rename(oldpath, newpath); uint16_t *fcpath_2 = NULL;
#else
u16 *fcpath_1 = fs_path_normalize_fc(oldpath); fcpath_1 = fs_path_normalize_fc(oldpath);
if(!fcpath_1) { if(!fcpath_1) {
errno = ENOMEM; errno = ENOMEM;
return -1; goto end;
} }
u16 *fcpath_2 = fs_path_normalize_fc(newpath); fcpath_2 = fs_path_normalize_fc(newpath);
if(!fcpath_2) { if(!fcpath_2) {
errno = ENOMEM; errno = ENOMEM;
free(fcpath_1); goto end;
return -1;
} }
int rc = BFile_Rename(fcpath_1, fcpath_2); rc = BFile_Rename(fcpath_1, fcpath_2);
free(fcpath_1);
free(fcpath_2);
#endif
if(rc < 0) { if(rc < 0) {
errno = bfile_error_to_errno(rc); errno = bfile_error_to_errno(rc);
return -1; rc = -1;
} }
return 0; else rc = 0;
end:
free(fcpath_1);
free(fcpath_2);
return rc;
} }

View file

@ -6,7 +6,6 @@
#include <string.h> #include <string.h>
#include "util.h" #include "util.h"
#include "fugue.h" #include "fugue.h"
#include "bfilecp.h"
int fugue_rmdir(char const *path) int fugue_rmdir(char const *path)
{ {
@ -34,9 +33,6 @@ int fugue_rmdir(char const *path)
return -1; return -1;
} }
#if GINT_OS_CP
int rc = BFile_Remove(path);
#else
uint16_t *fcpath = fs_path_normalize_fc(path); uint16_t *fcpath = fs_path_normalize_fc(path);
if(!fcpath) { if(!fcpath) {
errno = ENOMEM; errno = ENOMEM;
@ -44,12 +40,12 @@ int fugue_rmdir(char const *path)
} }
int rc = BFile_Remove(fcpath); int rc = BFile_Remove(fcpath);
free(fcpath);
#endif
if(rc < 0) { if(rc < 0) {
errno = bfile_error_to_errno(rc); errno = bfile_error_to_errno(rc);
return -1; rc = -1;
} }
return 0; else rc = 0;
free(fcpath);
return rc;
} }

View file

@ -5,7 +5,6 @@
#include <errno.h> #include <errno.h>
#include <stdlib.h> #include <stdlib.h>
#include "util.h" #include "util.h"
#include "bfilecp.h"
int fugue_stat(char const * restrict path, struct stat * restrict statbuf) int fugue_stat(char const * restrict path, struct stat * restrict statbuf)
{ {

View file

@ -4,7 +4,6 @@
#include <errno.h> #include <errno.h>
#include <sys/stat.h> #include <sys/stat.h>
#include "util.h" #include "util.h"
#include "bfilecp.h"
int fugue_unlink(char const *path) int fugue_unlink(char const *path)
{ {
@ -16,15 +15,6 @@ int fugue_unlink(char const *path)
return -1; return -1;
} }
#if GINT_OS_CP
char *normpath = fs_path_normalize_opt(path, "\\fls0\\", '\\');
if(!normpath) {
errno = ENOMEM;
free(fcpath);
return -1;
}
#endif
int type, size, rc; int type, size, rc;
rc = BFile_Ext_Stat(fcpath, &type, &size); rc = BFile_Ext_Stat(fcpath, &type, &size);
if(rc < 0) { if(rc < 0) {
@ -38,22 +28,14 @@ int fugue_unlink(char const *path)
goto end; goto end;
} }
#if GINT_OS_CP
rc = BFile_Remove(normpath);
#else
rc = BFile_Remove(fcpath); rc = BFile_Remove(fcpath);
#endif
if(rc < 0) { if(rc < 0) {
errno = bfile_error_to_errno(rc); errno = bfile_error_to_errno(rc);
rc = -1; rc = -1;
} }
rc = 0; else rc = 0;
end: end:
free(fcpath); free(fcpath);
#if GINT_OS_CP
free(normpath);
#endif
return rc; return rc;
} }

View file

@ -1,5 +1,4 @@
#include "util.h" #include "util.h"
#include "bfilecp.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
@ -10,33 +9,6 @@
int bfile_error_to_errno(int e) int bfile_error_to_errno(int e)
{ {
#if GINT_OS_CP
switch(e) {
case BFileCP_ENOMEM: return ENOENT;
case BFileCP_EINVAL: return EINVAL;
case BFileCP_EDEVFAIL: return EIO;
case BFileCP_EMOUNTED: return ENODEV;
case BFileCP_EACCES: return EACCES;
case BFileCP_EBADFSID: return ENODEV;
case BFileCP_ENOVOLUME: return ENODEV;
case BFileCP_ENOPATH: return ENOENT;
case BFileCP_EEXIST: return EEXIST;
case BFileCP_ENAMETOOLONG: return EINVAL;
case BFileCP_EOUTOFBOUND: return EINVAL;
case BFileCP_EUNFORMAT: return EINVAL;
case BFileCP_ENOSPC: return ENOSPC;
case BFileCP_ENOENT: return ENOENT;
case BFileCP_EISDIRECTORY: return EISDIR;
case BFileCP_ESHARE: return EINVAL;
case BFileCP_EMFILE: return EMFILE;
case BFileCP_EBADF: return EBADF;
case BFileCP_EEOF: return EINVAL;
case BFileCP_ENOTEMPTY: return EINVAL;
case BFileCP_ECLUSTERSIZEMISMATCH: return EINVAL;
case BFileCP_ESYSTEM: return EINVAL;
default: return errno;
}
#else
/* TODO: Find BFile code for too many fds and map it to ENFILE. */ /* TODO: Find BFile code for too many fds and map it to ENFILE. */
switch(e) { switch(e) {
case BFile_EntryNotFound: return ENOENT; case BFile_EntryNotFound: return ENOENT;
@ -54,28 +26,20 @@ int bfile_error_to_errno(int e)
case BFile_DeviceNotFound: return ENOENT; case BFile_DeviceNotFound: return ENOENT;
default: return errno; default: return errno;
} }
#endif
} }
int bfile_type_to_mode_t(int bfile_type) int bfile_type_to_mode_t(int bfile_type)
{ {
#if GINT_OS_CP
return bfile_type == BFile_Type_Directory ? S_IFDIR : S_IFREG;
#else
switch(bfile_type) { switch(bfile_type) {
case BFile_Type_Directory: return S_IFDIR; case BFile_Type_Directory: return S_IFDIR;
case BFile_Type_Dot: return S_IFDIR; case BFile_Type_Dot: return S_IFDIR;
case BFile_Type_DotDot: return S_IFDIR; case BFile_Type_DotDot: return S_IFDIR;
default: return S_IFREG; default: return S_IFREG;
} }
#endif
} }
int bfile_type_to_dirent(int bfile_type) int bfile_type_to_dirent(int bfile_type)
{ {
#if GINT_OS_CP
return bfile_type == BFile_Type_Directory ? DT_DIR : DT_REG;
#else
switch(bfile_type) { switch(bfile_type) {
case BFile_Type_Directory: return DT_DIR; case BFile_Type_Directory: return DT_DIR;
case BFile_Type_Dot: return DT_DIR; case BFile_Type_Dot: return DT_DIR;
@ -90,7 +54,6 @@ int bfile_type_to_dirent(int bfile_type)
case BFile_Type_Archived: return DT_REG; case BFile_Type_Archived: return DT_REG;
default: return DT_UNKNOWN; default: return DT_UNKNOWN;
} }
#endif
} }
/* Length of FONTCHARACTER and UTF-8 strings, counting only ASCII characters */ /* Length of FONTCHARACTER and UTF-8 strings, counting only ASCII characters */
@ -206,12 +169,8 @@ char **fs_split_components(char *path, int *count)
/* Generalization of fs_path_normalize(). Returns a [char *] if use_fc=false, /* Generalization of fs_path_normalize(). Returns a [char *] if use_fc=false,
otherwise returns an [uint16_t *]. */ otherwise returns an [uint16_t *]. */
static void *path_normalize( static void *path_normalize(char const *path, bool use_fc)
char const *path, bool use_fc, char const *prefix8, int dirsep)
{ {
if(!prefix8)
prefix8 = "/";
char *path_dup = strdup(path); char *path_dup = strdup(path);
if(!path_dup) return NULL; if(!path_dup) return NULL;
@ -235,8 +194,7 @@ static void *path_normalize(
} }
/* Count total length */ /* Count total length */
int prefix8_len = strlen(prefix8); int length = (use_fc ? 7 : 1) + (wr >= 1 ? wr - 1 : 0);
int length = (use_fc ? 7 : prefix8_len) + (wr >= 1 ? wr - 1 : 0);
for(int i = 0; i < wr; i++) { for(int i = 0; i < wr; i++) {
length += utf8_len(comps[i]); length += utf8_len(comps[i]);
} }
@ -246,16 +204,11 @@ static void *path_normalize(
uint16_t *fc = malloc((length + 1) * sizeof *fc); uint16_t *fc = malloc((length + 1) * sizeof *fc);
uint16_t *fc_init = fc; uint16_t *fc_init = fc;
#if GINT_OS_CP
memcpy(fc, u"\\fls0\\", 6*2);
fc += 6;
#else
memcpy(fc, u"\\\\fls0\\", 7*2); memcpy(fc, u"\\\\fls0\\", 7*2);
fc += 7; fc += 7;
#endif
for(int i = 0; i < wr; i++) { for(int i = 0; i < wr; i++) {
if(i > 0) *fc++ = dirsep; if(i > 0) *fc++ = '\\';
utf8_to_fc(fc, comps[i], (size_t)-1); utf8_to_fc(fc, comps[i], (size_t)-1);
fc += utf8_len(comps[i]); fc += utf8_len(comps[i]);
} }
@ -268,11 +221,10 @@ static void *path_normalize(
else { else {
char *utf8 = malloc(length + 1); char *utf8 = malloc(length + 1);
char *utf8_init = utf8; char *utf8_init = utf8;
memcpy(utf8, prefix8, prefix8_len); *utf8++ = '/';
utf8 += prefix8_len;
for(int i = 0; i < wr; i++) { for(int i = 0; i < wr; i++) {
if(i > 0) *utf8++ = dirsep; if(i > 0) *utf8++ = '/';
strcpy(utf8, comps[i]); strcpy(utf8, comps[i]);
utf8 += utf8_len(comps[i]); utf8 += utf8_len(comps[i]);
} }
@ -284,17 +236,12 @@ static void *path_normalize(
} }
} }
char *fs_path_normalize(char const *path) char *fs_path_normalize(char const *path)
{ {
return path_normalize(path, false, NULL, '/'); return path_normalize(path, false);
} }
char *fs_path_normalize_opt(char const *path, char const *prefix, int dirsep)
{
return path_normalize(path, false, prefix, dirsep);
}
uint16_t *fs_path_normalize_fc(char const *path) uint16_t *fs_path_normalize_fc(char const *path)
{ {
return path_normalize(path, true, NULL, '\\'); return path_normalize(path, true);
} }

View file

@ -44,9 +44,6 @@ uint16_t *utf8_to_fc_alloc(uint16_t *prefix, char const *utf8,
/* Same as fc_to_utf8() but allocates a string with malloc(). */ /* Same as fc_to_utf8() but allocates a string with malloc(). */
char *fc_to_utf8_alloc(uint16_t const *fc); char *fc_to_utf8_alloc(uint16_t const *fc);
/* Same as fs_path_normalize() but with a prefix. If NULL, "/". */
char *fs_path_normalize_opt(char const *path, char const *prefix, int dirsep);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

@ -19,6 +19,6 @@ ssize_t pread(int fd, void *buf, size_t size, off_t offset)
end: end:
/* At the end, always try to restore the current position */ /* At the end, always try to restore the current position */
lseek(fd, current, SEEK_SET); lseek(fd, current, SEEK_CUR);
return rc; return rc;
} }

View file

@ -17,6 +17,6 @@ ssize_t pwrite(int fd, const void *buf, size_t size, off_t offset)
end: end:
/* At the end, always try to restore the current position */ /* At the end, always try to restore the current position */
lseek(fd, current, SEEK_SET); lseek(fd, current, SEEK_CUR);
return rc; return rc;
} }

View file

@ -176,7 +176,8 @@ void hw_detect(void)
gint[HWCPUVR] = PVR; gint[HWCPUVR] = PVR;
gint[HWCPUPR] = PRR; gint[HWCPUPR] = PRR;
gint[HWCALC] = HWCALC_FXCP400; gint[HWCALC] = HWCALC_FXCP400;
gint[HWFS] = HWFS_FUGUE; // TODO: What filesystem implementation on the fx-CP 400?
gint[HWFS] = HWFS_NONE;
gint[HWRAM] = 16 << 20; gint[HWRAM] = 16 << 20;
// TOOD: How much ROM on the fx-CP 400? // TOOD: How much ROM on the fx-CP 400?
gint[HWROM] = 0; gint[HWROM] = 0;

View file

@ -33,8 +33,6 @@
.global _BFile_FindFirst .global _BFile_FindFirst
.global _BFile_FindNext .global _BFile_FindNext
.global _BFile_FindClose .global _BFile_FindClose
.global _BFile_FStat // fx-CP
.global _BFile_Mkdir // fx-CP
/* Return to menu */ /* Return to menu */
.global ___Timer_Install .global ___Timer_Install
@ -291,41 +289,4 @@ ___VRAMRestore:
___Reset: ___Reset:
fixed(0xa0000000) fixed(0xa0000000)
_BFile_FindFirst:
fixed(0x8005a2ac)
_BFile_FindNext:
fixed(0x8005a5f0)
_BFile_FindClose:
fixed(0x8005a8ba)
_BFile_Remove:
fixed(0x80057fc8)
_BFile_Open:
fixed(0x80057f1c)
_BFile_Write:
fixed(0x80057f74)
_BFile_Close:
fixed(0x80057fa2)
_BFile_Read:
fixed(0x80057f46)
// _BFile_Flush:
// fixed(0x8005809a)
_BFile_Mkdir:
fixed(0x80057ef6)
// _BFile_Mount:
// fixed(0x80057e7c)
_BFile_Stat:
fixed(0x80057fee)
// _BFile_Reclaim:
// fixed(0x80058114)
// _BFile_FsInfo:
// fixed(0x800580ea)
// _BFile_Salvage:
// fixed(0x8005813e)
_BFile_Rename:
fixed(0x80058042)
_BFile_FStat:
fixed(0x80057fee)
_BFile_Seek:
fixed(0x8005806c)
#endif /* GINT_OS_CP */ #endif /* GINT_OS_CP */

View file

@ -172,18 +172,6 @@ void r61523_display_rect(
} }
} }
void r61523_set_pixel(int x, int y, int color)
{
if((unsigned)x >= 320 || (unsigned)y >= 528)
return;
// dma_transfer_wait(0);
r61523_win_set(x, x, y, y);
select(44);
uint16_t volatile *DISPLAY = (void *)0xb4000000;
*DISPLAY = color;
}
static bool r61523_update(int x, int y, image_t const *fb, int flags) static bool r61523_update(int x, int y, image_t const *fb, int flags)
{ {
if(fb->format != IMAGE_RGB565) if(fb->format != IMAGE_RGB565)