Skip to content

Commit

Permalink
Small cleanup (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
hensldm authored Feb 24, 2024
1 parent 34e07ce commit d0bb8af
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 44 deletions.
14 changes: 7 additions & 7 deletions src/io/contpfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ s32 __osRepairPackId(OSPfs* pfs, __OSPackId* badid, __OSPackId* newid) {
#if BUILD_VERSION >= VERSION_J
j = 0;
#else
SET_ACTIVEBANK_TO_ZERO;
SET_ACTIVEBANK_TO_ZERO();
#endif

newid->repaired = -1;
Expand All @@ -65,7 +65,7 @@ s32 __osRepairPackId(OSPfs* pfs, __OSPackId* badid, __OSPackId* newid) {
newid->serial_low = badid->serial_low;

#if BUILD_VERSION >= VERSION_J
SET_ACTIVEBANK_TO_ZERO;
SET_ACTIVEBANK_TO_ZERO();
#else
j = 0;
#endif
Expand Down Expand Up @@ -105,7 +105,7 @@ s32 __osRepairPackId(OSPfs* pfs, __OSPackId* badid, __OSPackId* newid) {
} while (j < PFS_MAX_BANKS);

#if BUILD_VERSION >= VERSION_J
SET_ACTIVEBANK_TO_ZERO;
SET_ACTIVEBANK_TO_ZERO();
#else
ERRCK(SELECT_BANK(pfs, 0));
#endif
Expand Down Expand Up @@ -147,7 +147,7 @@ s32 __osCheckPackId(OSPfs* pfs, __OSPackId* temp) {
int i;
int j;

SET_ACTIVEBANK_TO_ZERO;
SET_ACTIVEBANK_TO_ZERO();
index[0] = PFS_ID_0AREA;
index[1] = PFS_ID_1AREA;
index[2] = PFS_ID_2AREA;
Expand Down Expand Up @@ -184,7 +184,7 @@ s32 __osGetId(OSPfs* pfs) {
s32 ret;
__OSPackId* id;

SET_ACTIVEBANK_TO_ZERO;
SET_ACTIVEBANK_TO_ZERO();
ERRCK(__osContRamRead(pfs->queue, pfs->channel, PFS_ID_0AREA, (u8*)temp));
__osIdCheckSum((u16*)temp, &sum, &isum);
id = (__OSPackId*)temp;
Expand Down Expand Up @@ -247,7 +247,7 @@ s32 __osCheckId(OSPfs* pfs) {
}
}
#else
SET_ACTIVEBANK_TO_ZERO;
SET_ACTIVEBANK_TO_ZERO();
#endif

ret = __osContRamRead(pfs->queue, pfs->channel, PFS_ID_0AREA, (u8*)temp);
Expand Down Expand Up @@ -287,7 +287,7 @@ s32 __osPfsRWInode(OSPfs* pfs, __OSInode* inode, u8 flag, u8 bank) {
}
#endif

SET_ACTIVEBANK_TO_ZERO;
SET_ACTIVEBANK_TO_ZERO();

offset = (bank > 0) ? 1 : pfs->inode_start_page;

Expand Down
23 changes: 11 additions & 12 deletions src/io/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,36 +251,35 @@ extern u8 __osMaxControllers;
#define SELECT_BANK(pfs, bank) \
__osPfsSelectBank((pfs), (bank))

#define SET_ACTIVEBANK_TO_ZERO \
if (pfs->activebank != 0) \
{ \
#define SET_ACTIVEBANK_TO_ZERO() \
if (pfs->activebank != 0) \
{ \
ERRCK(__osPfsSelectBank(pfs, 0)); \
} (void)0

#else

#define SELECT_BANK(pfs, bank) \
(pfs->activebank = (bank), \
__osPfsSelectBank((pfs))) \
(pfs->activebank = (bank), __osPfsSelectBank((pfs)))

#define SET_ACTIVEBANK_TO_ZERO \
if (pfs->activebank != 0) \
{ \
pfs->activebank = 0; \
#define SET_ACTIVEBANK_TO_ZERO() \
if (pfs->activebank != 0) \
{ \
pfs->activebank = 0; \
ERRCK(__osPfsSelectBank(pfs)); \
} (void)0

#endif

#define PFS_CHECK_ID \
#define PFS_CHECK_ID() \
if (__osCheckId(pfs) == PFS_ERR_NEW_PACK) \
return PFS_ERR_NEW_PACK

#define PFS_CHECK_STATUS \
#define PFS_CHECK_STATUS() \
if ((pfs->status & PFS_INITIALIZED) == 0) \
return PFS_ERR_INVALID

#define PFS_GET_STATUS \
#define PFS_GET_STATUS() \
__osSiGetAccess(); \
ret = __osPfsGetStatus(queue, channel); \
__osSiRelAccess(); \
Expand Down
2 changes: 1 addition & 1 deletion src/io/pfsallocatefile.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ s32 osPfsAllocateFile(OSPfs* pfs, u16 company_code, u32 game_code, u8* game_name
return PFS_ERR_INVALID;
}

PFS_CHECK_ID;
PFS_CHECK_ID();

if (((ret = osPfsFindFile(pfs, company_code, game_code, game_name, ext_name, file_no)) != 0) &&
ret != PFS_ERR_INVALID) {
Expand Down
6 changes: 3 additions & 3 deletions src/io/pfschecker.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ s32 osPfsChecker(OSPfs* pfs) {
if (cc != 0 || next_page.ipage != PFS_EOF) {
bzero(&tmp_dir, sizeof(__OSDir));

SET_ACTIVEBANK_TO_ZERO;
SET_ACTIVEBANK_TO_ZERO();
ERRCK(__osContRamWrite(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*)&tmp_dir, FALSE));
fixed++;
}
Expand Down Expand Up @@ -111,7 +111,7 @@ s32 osPfsChecker(OSPfs* pfs) {
tmp_dir.status = DIR_STATUS_EMPTY;
tmp_dir.data_sum = 0;

SET_ACTIVEBANK_TO_ZERO;
SET_ACTIVEBANK_TO_ZERO();
ERRCK(__osContRamWrite(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*)&tmp_dir, FALSE));
fixed++;
}
Expand All @@ -123,7 +123,7 @@ s32 osPfsChecker(OSPfs* pfs) {
tmp_dir.status = DIR_STATUS_EMPTY;
tmp_dir.data_sum = 0;

SET_ACTIVEBANK_TO_ZERO;
SET_ACTIVEBANK_TO_ZERO();
ERRCK(__osContRamWrite(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*)&tmp_dir, FALSE));
fixed++;
}
Expand Down
8 changes: 4 additions & 4 deletions src/io/pfsdeletefile.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ s32 osPfsDeleteFile(OSPfs* pfs, u16 company_code, u32 game_code, u8* game_name,

#if BUILD_VERSION >= VERSION_J
ERRCK(osPfsFindFile(pfs, company_code, game_code, game_name, ext_name, &file_no));
SET_ACTIVEBANK_TO_ZERO;
SET_ACTIVEBANK_TO_ZERO();
#else
PFS_CHECK_STATUS;
PFS_CHECK_ID;
SET_ACTIVEBANK_TO_ZERO;
PFS_CHECK_STATUS();
PFS_CHECK_ID();
SET_ACTIVEBANK_TO_ZERO();
ERRCK(osPfsFindFile(pfs, company_code, game_code, game_name, ext_name, &file_no));

if (file_no == -1) {
Expand Down
6 changes: 3 additions & 3 deletions src/io/pfsfilestate.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ s32 osPfsFileState(OSPfs* pfs, s32 file_no, OSPfsState* state) {
return PFS_ERR_INVALID;
}

PFS_CHECK_STATUS;
PFS_CHECK_STATUS();
#if BUILD_VERSION >= VERSION_J
ERRCK(__osCheckId(pfs));
#else
PFS_CHECK_ID;
PFS_CHECK_ID();
#endif
SET_ACTIVEBANK_TO_ZERO;
SET_ACTIVEBANK_TO_ZERO();

ERRCK(__osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + file_no, (u8*)&dir));

Expand Down
4 changes: 2 additions & 2 deletions src/io/pfsfreeblocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ s32 osPfsFreeBlocks(OSPfs* pfs, s32* bytes_not_used) {
u8 bank;
int offset;

PFS_CHECK_STATUS;
PFS_CHECK_STATUS();
#if BUILD_VERSION >= VERSION_J
ERRCK(__osCheckId(pfs));
#else
PFS_CHECK_ID;
PFS_CHECK_ID();
#endif
for (bank = 0; bank < pfs->banks; bank++) {
ERRCK(__osPfsRWInode(pfs, &inode, OS_READ, bank));
Expand Down
6 changes: 3 additions & 3 deletions src/io/pfsnumfiles.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ s32 osPfsNumFiles(OSPfs* pfs, s32* max_files, s32* files_used) {
__OSDir dir;
int files = 0;

PFS_CHECK_STATUS;
PFS_CHECK_STATUS();
#if BUILD_VERSION >= VERSION_J
ERRCK(__osCheckId(pfs));
#else
PFS_CHECK_ID;
PFS_CHECK_ID();
#endif
SET_ACTIVEBANK_TO_ZERO;
SET_ACTIVEBANK_TO_ZERO();

for (j = 0; j < pfs->dir_size; j++) {
ERRCK(__osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*)&dir));
Expand Down
8 changes: 4 additions & 4 deletions src/io/pfsreadwritefile.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ s32 osPfsReadWriteFile(OSPfs* pfs, s32 file_no, u8 flag, int offset, int size_in
return PFS_ERR_INVALID;
}

PFS_CHECK_STATUS;
PFS_CHECK_ID;
SET_ACTIVEBANK_TO_ZERO;
PFS_CHECK_STATUS();
PFS_CHECK_ID();
SET_ACTIVEBANK_TO_ZERO();
ERRCK(__osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + file_no, (u8*)&dir));

if (dir.company_code == 0 || dir.game_code == 0) {
Expand Down Expand Up @@ -108,7 +108,7 @@ s32 osPfsReadWriteFile(OSPfs* pfs, s32 file_no, u8 flag, int offset, int size_in
if (flag == PFS_WRITE && (dir.status & DIR_STATUS_OCCUPIED) == 0) {
dir.status |= DIR_STATUS_OCCUPIED;
#if BUILD_VERSION >= VERSION_J
SET_ACTIVEBANK_TO_ZERO;
SET_ACTIVEBANK_TO_ZERO();
#else
ERRCK(SELECT_BANK(pfs, 0));
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/io/pfsreformat.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ s32 osPfsReFormat(OSPfs* pfs, OSMesgQueue* queue, int channel) {
__osSiRelAccess();
ERRCK(__osGetId(pfs));

SET_ACTIVEBANK_TO_ZERO;
SET_ACTIVEBANK_TO_ZERO();

for (j = 0; j < ARRLEN(tmp_data); j++) {
tmp_data[j] = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/io/pfsrepairid.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ s32 osPfsRepairId(OSPfs *pfs) {
s32 ret;
__OSPackId *id;

SET_ACTIVEBANK_TO_ZERO;
SET_ACTIVEBANK_TO_ZERO();
ERRCK(__osContRamRead(pfs->queue, pfs->channel, 1, (u8*)&temp));
__osIdCheckSum((u16*)&temp, &sum, &isum);
id = (__OSPackId*)&temp;
Expand Down
2 changes: 1 addition & 1 deletion src/io/pfssearchfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ s32 osPfsFindFile(OSPfs* pfs, u16 company_code, u32 game_code, u8* game_name, u8
}
ERRCK(__osCheckId(pfs));
#else
PFS_CHECK_ID;
PFS_CHECK_ID();
#endif

for (j = 0; j < pfs->dir_size; j++) {
Expand Down
4 changes: 2 additions & 2 deletions src/io/pfssetlabel.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ s32 osPfsSetLabel(OSPfs* pfs, u8* label) {

ERRCK(__osCheckId(pfs));
#else
PFS_CHECK_ID;
PFS_CHECK_ID();
#endif

if (label != NULL) {
Expand All @@ -34,7 +34,7 @@ s32 osPfsSetLabel(OSPfs* pfs, u8* label) {
}
return ret;
#else
SET_ACTIVEBANK_TO_ZERO;
SET_ACTIVEBANK_TO_ZERO();
ERRCK(__osContRamWrite(pfs->queue, pfs->channel, PFS_LABEL_AREA, pfs->label, FALSE));
return 0;
#endif
Expand Down

0 comments on commit d0bb8af

Please sign in to comment.