aboutsummaryrefslogtreecommitdiffstats
path: root/src/gba/gba.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/gba/gba.h')
-rw-r--r--src/gba/gba.h84
1 files changed, 50 insertions, 34 deletions
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) {
237static inline 237static inline
238void 238void
239profile_start(void) { 239profile_start(void) {
240 TIMER_DATA_2 = 0; 240 TIMER_DATA_1 = 0;
241 TIMER_DATA_3 = 0; 241 TIMER_DATA_0 = 0;
242 TIMER_CTRL_2 = 0; 242 TIMER_CTRL_1 = 0;
243 TIMER_CTRL_3 = 0; 243 TIMER_CTRL_0 = 0;
244 TIMER_CTRL_3 = TIMER_CTRL_ENABLE | TIMER_CTRL_CASCADE; 244 TIMER_CTRL_1 = TIMER_CTRL_ENABLE | TIMER_CTRL_CASCADE;
245 TIMER_CTRL_2 = TIMER_CTRL_ENABLE; 245 TIMER_CTRL_0 = TIMER_CTRL_ENABLE;
246} 246}
247 247
248static inline 248static inline
249u32 249u32
250profile_stop(void) { 250profile_stop(void) {
251 TIMER_CTRL_2 = 0; 251 TIMER_CTRL_0 = 0;
252 return (TIMER_DATA_3 << 16) | TIMER_DATA_2; 252 return (TIMER_DATA_1 << 16) | TIMER_DATA_0;
253} 253}
254 254
255static inline 255static inline
256u32 256u32
257profile_measure(void) { 257profile_measure(void) {
258 return (TIMER_DATA_3 << 16) | TIMER_DATA_2; 258 return (TIMER_DATA_1 << 16) | TIMER_DATA_0;
259} 259}
260 260
261// 261//
@@ -289,12 +289,24 @@ profile_measure(void) {
289static u16 key_curr = 0; 289static u16 key_curr = 0;
290static u16 key_prev = 0; 290static u16 key_prev = 0;
291 291
292static inline 292// Stores number of frames since a keay was pressed.
293void 293typedef struct Controller {
294poll_keys(void) { 294 int key_up;
295 key_prev = key_curr; 295 int key_down;
296 key_curr = ~KEY_INPUTS & KEY_MASK; 296 int key_left;
297} 297 int key_right;
298 int key_select;
299 int key_start;
300 int key_b;
301 int key_a;
302 int key_l;
303 int key_r;
304} Controller;
305
306static Controller ctrl = {0};
307
308#define RETRIG_OFFSET 16
309#define RETRIG_FRAMES 3
298 310
299// Returns true if the given key has been pressed at time of calling and was not 311// Returns true if the given key has been pressed at time of calling and was not
300// pressed since the previous call. For example, if a key is being held, this 312// pressed since the previous call. For example, if a key is being held, this
@@ -327,25 +339,6 @@ key_hold(u32 key) {
327 return key_curr & key_prev & key; 339 return key_curr & key_prev & key;
328} 340}
329 341
330// Stores number of frames since a keay was pressed.
331typedef struct Controller {
332 int key_up;
333 int key_down;
334 int key_left;
335 int key_right;
336 int key_select;
337 int key_start;
338 int key_b;
339 int key_a;
340 int key_l;
341 int key_r;
342} Controller;
343
344static Controller ctrl = {0};
345
346#define RETRIG_OFFSET 16
347#define RETRIG_FRAMES 3
348
349static inline 342static inline
350bool 343bool
351_key_retrig(int key, int offset, int frames) { 344_key_retrig(int key, int offset, int frames) {
@@ -438,6 +431,14 @@ update_controller(void) {
438 if (key_pressed(KEY_START)) { ctrl.key_start++; } else if (key_released(KEY_START)) { ctrl.key_start = 0; } 431 if (key_pressed(KEY_START)) { ctrl.key_start++; } else if (key_released(KEY_START)) { ctrl.key_start = 0; }
439} 432}
440 433
434static inline
435void
436poll_keys(void) {
437 key_prev = key_curr;
438 key_curr = ~KEY_INPUTS & KEY_MASK;
439 update_controller();
440}
441
441// 442//
442// Direct Memory Access (DMA) 443// Direct Memory Access (DMA)
443// 444//
@@ -785,6 +786,7 @@ wait_vsync(void) {
785// General utility macros. 786// General utility macros.
786#define MIN(A, B) ((A) <= (B) ? (A) : (B)) 787#define MIN(A, B) ((A) <= (B) ? (A) : (B))
787#define MAX(A, B) ((A) >= (B) ? (A) : (B)) 788#define MAX(A, B) ((A) >= (B) ? (A) : (B))
789#define ABS(A) (((A) ^ ((A) >> (sizeof(A) * 8 - 1))) - ((A) >> (sizeof(A) * 8 - 1)))
788#define CLAMP(X, MIN, MAX) ((X) <= (MIN) ? (MIN) : (X) > (MAX) ? (MAX): (X)) 790#define CLAMP(X, MIN, MAX) ((X) <= (MIN) ? (MIN) : (X) > (MAX) ? (MAX): (X))
789#define LEN(ARR) (sizeof(ARR) / sizeof((ARR)[0])) 791#define LEN(ARR) (sizeof(ARR) / sizeof((ARR)[0]))
790 792
@@ -812,10 +814,24 @@ memcpy32(u32 *dst, const u32 *src, u32 size) {
812 } 814 }
813} 815}
814 816
817static inline
818void
819memset32(u32 *dst, const u32 data, u32 size) {
820 for (size_t i = 0; i < size / 4; i++) {
821 dst[i] = data;
822 }
823}
824
825// Optimized ARMASM versions of memcpy32 and memset32.
826extern void copy32(u32 *dst, u32 *src, u32 chunks);
827extern void set32(u32 *dst, u32 data, u32 chunks);
828
815// 829//
816// Compiler hints. 830// Compiler hints.
817// 831//
818 832
819#define UNROLL_LOOPS __attribute__((optimize("unroll-loops"))) 833#define UNROLL_LOOPS __attribute__((optimize("unroll-loops")))
834#define INLINE __attribute__((always_inline)) inline
820 835
821#endif // GBA_H 836#endif // GBA_H
837