From aeda01b5244295795249b5f70008e13c9347652a Mon Sep 17 00:00:00 2001 From: Mike Nolan Date: Wed, 4 Oct 2023 18:54:24 -0500 Subject: [PATCH] Testing --- src/common.hpp | 11 +++++++++++ src/main.cpp | 25 +++++++++++++++++-------- src/pads.c | 35 +++++++++++++++++++++++++++++++++++ src/pads.h | 17 +++++++++++++++++ 4 files changed, 80 insertions(+), 8 deletions(-) create mode 100644 src/common.hpp create mode 100644 src/pads.c create mode 100644 src/pads.h diff --git a/src/common.hpp b/src/common.hpp new file mode 100644 index 0000000..fbc57a4 --- /dev/null +++ b/src/common.hpp @@ -0,0 +1,11 @@ +#pragma once +#include +#include +#include +#include "pads.h" + +typedef struct { + GRRLIB_ttfFont *myFont; +} app_global_data_t; + +extern app_global_data_t* global_data; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index f02261a..28a7376 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,25 +4,32 @@ Minimum Code To Use GRRLIB ============================================*/ -#include -#include -#include + +#include "FreeMonoBold_ttf.h" + +app_global_data_t* global_data; int main(int argc, char **argv) { + global_data=(app_global_data_t*)calloc(1,sizeof(app_global_data_t)); // Initialise the Graphics & Video subsystem GRRLIB_Init(); - // Initialise the Wiimotes - WPAD_Init(); + global_data->myFont =GRRLIB_LoadTTF(FreeMonoBold_ttf, FreeMonoBold_ttf_size); + + // Initialise the Controllers + Ctrl_Init(); + // Loop forever while(1) { + GRRLIB_SetBackgroundColour(0xff, 0x00, 0x00, 0xFF); + Ctrl_ScanPads(); // Scan the Controllers - WPAD_ScanPads(); // Scan the Wiimotes + // If [HOME] was pressed on the first Controller, break out of the loop + if (Ctrl_ButtonsDown(0) & PAD_BUTTON_START) break; - // If [HOME] was pressed on the first Wiimote, break out of the loop - if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME) break; + if(Ctrl_ButtonsDown(0) & PAD_BUTTON_A) GRRLIB_PrintfTTF(200,200,global_data->myFont,"A Pressed",12,0xFFFFFFFF); // --------------------------------------------------------------------- // Place your drawing code here @@ -32,6 +39,8 @@ int main(int argc, char **argv) { } GRRLIB_Exit(); // Be a good boy, clear the memory allocated by GRRLIB + GRRLIB_FreeTTF(global_data->myFont); + free(global_data); exit(0); // Use exit() to exit a program, do not use 'return' from main() } \ No newline at end of file diff --git a/src/pads.c b/src/pads.c new file mode 100644 index 0000000..a769a39 --- /dev/null +++ b/src/pads.c @@ -0,0 +1,35 @@ +#include "controller.h" + +void Ctrl_Init() +{ + PAD_Init(); + #if defined(HW_RVL) + WPAD_Init(); + #endif +} +void Ctrl_ScanPads() +{ + PAD_ScanPads(); + #if defined(HW_RVL) + WPAD_ScanPads(); + #endif +} + +u32 Ctrl_ButtonsDown(int pad) +{ + u32 buttons=PAD_ButtonsDown(pad); + #if defined(HW_RVL) + u32 wbuttons = WPAD_ButtonsDown(pad); + if(wbuttons & WPAD_BUTTON_A) buttons |= PAD_BUTTON_A; + if(wbuttons & WPAD_BUTTON_B) buttons |= PAD_BUTTON_B; + if(wbuttons & WPAD_BUTTON_1) buttons |= PAD_BUTTON_X; + if(wbuttons & WPAD_BUTTON_2) buttons |= PAD_BUTTON_Y; + if(wbuttons & WPAD_BUTTON_HOME) buttons |= PAD_BUTTON_START; + if(wbuttons & WPAD_BUTTON_DOWN) buttons |= PAD_BUTTON_DOWN; + if(wbuttons & WPAD_BUTTON_UP) buttons |= PAD_BUTTON_UP; + if(wbuttons & WPAD_BUTTON_LEFT) buttons |= PAD_BUTTON_LEFT; + if(wbuttons & WPAD_BUTTON_RIGHT) buttons |= PAD_BUTTON_RIGHT; + + #endif + return buttons; +} \ No newline at end of file diff --git a/src/pads.h b/src/pads.h new file mode 100644 index 0000000..516d494 --- /dev/null +++ b/src/pads.h @@ -0,0 +1,17 @@ +#pragma once +#include +#include +#include +#include +#if defined(HW_RVL) +#include +#endif +#ifdef __cplusplus +extern "C" { +#endif +void Ctrl_Init(); +void Ctrl_ScanPads(); +u32 Ctrl_ButtonsDown(int pad); +#ifdef __cplusplus +} +#endif \ No newline at end of file