From a7ce765b1b57ec8a528263420852ed36da6d9d84 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Tue, 23 Jan 2024 10:30:54 +0100 Subject: Update profiling macros --- src/gba/gba.h | 84 +++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 50 insertions(+), 34 deletions(-) (limited to 'src/gba') diff --git a/src/gba/gba.h b/src/gba/gba.h index b5868f0..2cc167f 100644 --- a/src/gba/gba.h +++ b/src/gba/gba.h @@ -237,25 +237,25 @@ flip_page(vu16 *backbuffer) { static inline void profile_start(void) { - TIMER_DATA_2 = 0; - TIMER_DATA_3 = 0; - TIMER_CTRL_2 = 0; - TIMER_CTRL_3 = 0; - TIMER_CTRL_3 = TIMER_CTRL_ENABLE | TIMER_CTRL_CASCADE; - TIMER_CTRL_2 = TIMER_CTRL_ENABLE; + TIMER_DATA_1 = 0; + TIMER_DATA_0 = 0; + TIMER_CTRL_1 = 0; + TIMER_CTRL_0 = 0; + TIMER_CTRL_1 = TIMER_CTRL_ENABLE | TIMER_CTRL_CASCADE; + TIMER_CTRL_0 = TIMER_CTRL_ENABLE; } static inline u32 profile_stop(void) { - TIMER_CTRL_2 = 0; - return (TIMER_DATA_3 << 16) | TIMER_DATA_2; + TIMER_CTRL_0 = 0; + return (TIMER_DATA_1 << 16) | TIMER_DATA_0; } static inline u32 profile_measure(void) { - return (TIMER_DATA_3 << 16) | TIMER_DATA_2; + return (TIMER_DATA_1 << 16) | TIMER_DATA_0; } // @@ -289,12 +289,24 @@ profile_measure(void) { static u16 key_curr = 0; static u16 key_prev = 0; -static inline -void -poll_keys(void) { - key_prev = key_curr; - key_curr = ~KEY_INPUTS & KEY_MASK; -} +// Stores number of frames since a keay was pressed. +typedef struct Controller { + int key_up; + int key_down; + int key_left; + int key_right; + int key_select; + int key_start; + int key_b; + int key_a; + int key_l; + int key_r; +} Controller; + +static Controller ctrl = {0}; + +#define RETRIG_OFFSET 16 +#define RETRIG_FRAMES 3 // Returns true if the given key has been pressed at time of calling and was not // pressed since the previous call. For example, if a key is being held, this @@ -327,25 +339,6 @@ key_hold(u32 key) { return key_curr & key_prev & key; } -// Stores number of frames since a keay was pressed. -typedef struct Controller { - int key_up; - int key_down; - int key_left; - int key_right; - int key_select; - int key_start; - int key_b; - int key_a; - int key_l; - int key_r; -} Controller; - -static Controller ctrl = {0}; - -#define RETRIG_OFFSET 16 -#define RETRIG_FRAMES 3 - static inline bool _key_retrig(int key, int offset, int frames) { @@ -438,6 +431,14 @@ update_controller(void) { if (key_pressed(KEY_START)) { ctrl.key_start++; } else if (key_released(KEY_START)) { ctrl.key_start = 0; } } +static inline +void +poll_keys(void) { + key_prev = key_curr; + key_curr = ~KEY_INPUTS & KEY_MASK; + update_controller(); +} + // // Direct Memory Access (DMA) // @@ -785,6 +786,7 @@ wait_vsync(void) { // General utility macros. #define MIN(A, B) ((A) <= (B) ? (A) : (B)) #define MAX(A, B) ((A) >= (B) ? (A) : (B)) +#define ABS(A) (((A) ^ ((A) >> (sizeof(A) * 8 - 1))) - ((A) >> (sizeof(A) * 8 - 1))) #define CLAMP(X, MIN, MAX) ((X) <= (MIN) ? (MIN) : (X) > (MAX) ? (MAX): (X)) #define LEN(ARR) (sizeof(ARR) / sizeof((ARR)[0])) @@ -812,10 +814,24 @@ memcpy32(u32 *dst, const u32 *src, u32 size) { } } +static inline +void +memset32(u32 *dst, const u32 data, u32 size) { + for (size_t i = 0; i < size / 4; i++) { + dst[i] = data; + } +} + +// Optimized ARMASM versions of memcpy32 and memset32. +extern void copy32(u32 *dst, u32 *src, u32 chunks); +extern void set32(u32 *dst, u32 data, u32 chunks); + // // Compiler hints. // #define UNROLL_LOOPS __attribute__((optimize("unroll-loops"))) +#define INLINE __attribute__((always_inline)) inline #endif // GBA_H + -- cgit v1.2.1