Skip to content

Commit

Permalink
Added game database search code (and a debug menu for it).
Browse files Browse the repository at this point in the history
Mimic ROM "open bus" (not 100% accurate) and ROM mirroring. Fixes #21.
Implemented some useful ARM instruction intrinsics.
  • Loading branch information
profi200 committed Oct 22, 2020
1 parent 8fdc74a commit bbcfb69
Show file tree
Hide file tree
Showing 7 changed files with 531 additions and 72 deletions.
263 changes: 263 additions & 0 deletions include/arm_intrinsic.h

Large diffs are not rendered by default.

40 changes: 21 additions & 19 deletions include/error_codes.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,30 @@ enum
RES_SD_CARD_REMOVED = 1u,
RES_INVALID_ARG = 2u,
RES_OUT_OF_MEM = 3u,
RES_OUT_OF_RANGE = 4u,
RES_NOT_FOUND = 5u,

// fatfs errors.
// Caution: Update fres2Res() in fs.c on ARM9 if this changes!
RES_FR_DISK_ERR = 4u, /* (1) A hard error occurred in the low level disk I/O layer */
RES_FR_INT_ERR = 5u, /* (2) Assertion failed */
RES_FR_NOT_READY = 6u, /* (3) The physical drive cannot work */
RES_FR_NO_FILE = 7u, /* (4) Could not find the file */
RES_FR_NO_PATH = 8u, /* (5) Could not find the path */
RES_FR_INVALID_NAME = 9u, /* (6) The path name format is invalid */
RES_FR_DENIED = 10u, /* (7) Access denied due to prohibited access or directory full */
RES_FR_EXIST = 11u, /* (8) Access denied due to prohibited access */
RES_FR_INVALID_OBJECT = 12u, /* (9) The file/directory object is invalid */
RES_FR_WRITE_PROTECTED = 13u, /* (10) The physical drive is write protected */
RES_FR_INVALID_DRIVE = 14u, /* (11) The logical drive number is invalid */
RES_FR_NOT_ENABLED = 15u, /* (12) The volume has no work area */
RES_FR_NO_FILESYSTEM = 16u, /* (13) There is no valid FAT volume */
RES_FR_MKFS_ABORTED = 17u, /* (14) The f_mkfs() aborted due to any problem */
RES_FR_TIMEOUT = 18u, /* (15) Could not get a grant to access the volume within defined period */
RES_FR_LOCKED = 19u, /* (16) The operation is rejected according to the file sharing policy */
RES_FR_NOT_ENOUGH_CORE = 20u, /* (17) LFN working buffer could not be allocated */
RES_FR_TOO_MANY_OPEN_FILES = 21u, /* (18) Number of open files > FF_FS_LOCK */
RES_FR_INVALID_PARAMETER = 22u, /* (19) Given parameter is invalid */
RES_FR_DISK_ERR = 6u, /* (1) A hard error occurred in the low level disk I/O layer */
RES_FR_INT_ERR = 7u, /* (2) Assertion failed */
RES_FR_NOT_READY = 8u, /* (3) The physical drive cannot work */
RES_FR_NO_FILE = 9u, /* (4) Could not find the file */
RES_FR_NO_PATH = 10u, /* (5) Could not find the path */
RES_FR_INVALID_NAME = 11u, /* (6) The path name format is invalid */
RES_FR_DENIED = 12u, /* (7) Access denied due to prohibited access or directory full */
RES_FR_EXIST = 13u, /* (8) Access denied due to prohibited access */
RES_FR_INVALID_OBJECT = 14u, /* (9) The file/directory object is invalid */
RES_FR_WRITE_PROTECTED = 15u, /* (10) The physical drive is write protected */
RES_FR_INVALID_DRIVE = 16u, /* (11) The logical drive number is invalid */
RES_FR_NOT_ENABLED = 17u, /* (12) The volume has no work area */
RES_FR_NO_FILESYSTEM = 18u, /* (13) There is no valid FAT volume */
RES_FR_MKFS_ABORTED = 19u, /* (14) The f_mkfs() aborted due to any problem */
RES_FR_TIMEOUT = 20u, /* (15) Could not get a grant to access the volume within defined period */
RES_FR_LOCKED = 21u, /* (16) The operation is rejected according to the file sharing policy */
RES_FR_NOT_ENOUGH_CORE = 22u, /* (17) LFN working buffer could not be allocated */
RES_FR_TOO_MANY_OPEN_FILES = 23u, /* (18) Number of open files > FF_FS_LOCK */
RES_FR_INVALID_PARAMETER = 24u, /* (19) Given parameter is invalid */

// Custom errors.
RES_ROM_TOO_BIG = MAKE_CUSTOM_ERR(0),
Expand Down
19 changes: 10 additions & 9 deletions include/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@



#define ALIGN(a) __attribute__((aligned(a))) // Use alignas() instead.
#define NAKED __attribute__((naked))
#define NOINLINE __attribute__((noinline))
#define PACKED __attribute__((packed))
#define TARGET_ARM __attribute__((target("arm")))
#define TARGET_THUMB __attribute__((target("thumb")))
#define UNUSED __attribute__((unused))
#define USED __attribute__((used))
#define WEAK __attribute__((weak))
#define ALIGN(a) __attribute__((aligned(a))) // Use alignas() instead.
#define NAKED __attribute__((naked))
#define NOINLINE __attribute__((noinline))
#define ALWAYS_INLINE __attribute__((always_inline)) static inline
#define PACKED __attribute__((packed))
#define TARGET_ARM __attribute__((target("arm")))
#define TARGET_THUMB __attribute__((target("thumb")))
#define UNUSED __attribute__((unused))
#define USED __attribute__((used))
#define WEAK __attribute__((weak))


typedef uint8_t u8;
Expand Down
20 changes: 20 additions & 0 deletions include/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,23 @@ static inline u32 intLog2(u32 val)
// The result is undefined if __builtin_clz() is called with 0.
return (val ? 31u - __builtin_clz(val) : 0u);
}

// Round up to the next power of 2.
static inline u32 nextPow2(u32 val)
{
// Portable variant:
// https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
/*val--;
val |= val>>1;
val |= val>>2;
val |= val>>4;
val |= val>>8;
val |= val>>16;
val++;
return val;*/

// Warning: Allowed range is 2 - 2147483648.
// Everything else is undefined behavior.
return 1u<<(32u - __builtin_clz(val - 1));
}

0 comments on commit bbcfb69

Please sign in to comment.