2024-06-20 04:08:16 +00:00
|
|
|
#include <grrlib.h>
|
2024-06-19 04:51:50 +00:00
|
|
|
#include <duktape.h>
|
2024-06-25 23:39:04 +00:00
|
|
|
#include <ogc/pad.h>
|
2024-06-21 07:45:28 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2024-06-22 05:57:08 +00:00
|
|
|
#include <ogc/lwp_watchdog.h>
|
2024-06-21 07:45:28 +00:00
|
|
|
|
2024-06-25 21:08:04 +00:00
|
|
|
#include <data.h>
|
|
|
|
#include <duktape_engine.h>
|
2024-06-19 04:51:50 +00:00
|
|
|
|
2024-06-25 23:39:04 +00:00
|
|
|
#define LENGTH(arr) (sizeof(arr) / sizeof(arr[0]))
|
|
|
|
|
|
|
|
static bool launcher_running = true;
|
|
|
|
static bool running = false;
|
2024-06-21 07:45:28 +00:00
|
|
|
static GRRLIB_ttfFont * font;
|
2024-06-25 23:39:04 +00:00
|
|
|
static unsigned int green = RGBA(0, 255, 0, 255);
|
|
|
|
static unsigned int white = RGBA(255, 255, 255, 255);
|
|
|
|
|
|
|
|
struct menu_item {
|
|
|
|
const char * message;
|
|
|
|
void (*entrypoint)();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct menu_items {
|
|
|
|
size_t selected_index;
|
|
|
|
struct menu_item * items[2];
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct menu_items items = {
|
|
|
|
.selected_index = 0,
|
|
|
|
.items = {}
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct menu_item * create_menu_item(const char * message, void (*entrypoint)()) {
|
|
|
|
struct menu_item * item = malloc(sizeof(struct menu_item));
|
|
|
|
item->message = message;
|
|
|
|
item->entrypoint = entrypoint;
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void start_duktape() {
|
|
|
|
running = true;
|
|
|
|
duktape(font, &running);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void start_quickjs() {
|
|
|
|
running = true;
|
|
|
|
while (running) {
|
|
|
|
PAD_ScanPads();
|
|
|
|
unsigned int pressed = PAD_ButtonsDown(0);
|
|
|
|
GRRLIB_PrintfTTF(0, 0, font, "QuickJS is not implemented, yet..", 48, RGBA(255, 255, 255, 255));
|
|
|
|
GRRLIB_Render();
|
|
|
|
if (pressed & PAD_BUTTON_START) {
|
|
|
|
running = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void update_menu(unsigned int * pressed) {
|
|
|
|
if (*pressed & PAD_BUTTON_DOWN) {
|
|
|
|
int selected_index = items.selected_index;
|
|
|
|
selected_index += 1;
|
|
|
|
if (selected_index >= LENGTH(items.items)) {
|
|
|
|
selected_index = 0;
|
|
|
|
}
|
|
|
|
items.selected_index = selected_index;
|
|
|
|
} else if (*pressed & PAD_BUTTON_UP) {
|
|
|
|
int selected_index = items.selected_index;
|
|
|
|
selected_index -= 1;
|
|
|
|
if (selected_index < 0) {
|
|
|
|
selected_index = LENGTH(items.items) - 1;
|
|
|
|
}
|
|
|
|
items.selected_index = selected_index;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*pressed & PAD_BUTTON_A) {
|
|
|
|
items.items[items.selected_index]->entrypoint();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i < LENGTH(items.items); i++) {
|
|
|
|
unsigned int color;
|
|
|
|
if (items.selected_index == i) {
|
|
|
|
color = green;
|
|
|
|
} else {
|
|
|
|
color = white;
|
|
|
|
}
|
|
|
|
GRRLIB_PrintfTTF(0, 80 + (50 * i), font, items.items[i]->message, 64, color);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void launcher_loop() {
|
|
|
|
while (launcher_running) {
|
|
|
|
PAD_ScanPads();
|
|
|
|
unsigned int pressed = PAD_ButtonsDown(0);
|
|
|
|
if (pressed & PAD_BUTTON_START) {
|
|
|
|
launcher_running = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
GRRLIB_PrintfTTF(0, 0, font, "WiiDuktape Launcher", 64, RGBA(255, 255, 255, 255));
|
|
|
|
update_menu(&pressed);
|
|
|
|
GRRLIB_Render();
|
|
|
|
}
|
|
|
|
}
|
2024-06-19 07:39:01 +00:00
|
|
|
|
2024-06-19 04:51:50 +00:00
|
|
|
int main(int argc, char **argv) {
|
2024-06-25 23:39:04 +00:00
|
|
|
GRRLIB_SetAntiAliasing(false);
|
2024-06-20 04:08:16 +00:00
|
|
|
GRRLIB_Init();
|
2024-06-19 07:39:01 +00:00
|
|
|
PAD_Init();
|
2024-06-19 04:51:50 +00:00
|
|
|
|
2024-06-21 07:45:28 +00:00
|
|
|
// get the pixel operator font's data pointer and size
|
|
|
|
void * pixel_operator_font;
|
|
|
|
size_t pixel_operator_font_size;
|
|
|
|
get_file_pointer("PixelOperator.ttf", &pixel_operator_font, &pixel_operator_font_size);
|
|
|
|
|
|
|
|
font = GRRLIB_LoadTTF(pixel_operator_font, pixel_operator_font_size);
|
2024-06-19 04:51:50 +00:00
|
|
|
|
2024-06-25 23:39:04 +00:00
|
|
|
items.items[0] = create_menu_item("Duktape", start_duktape);
|
|
|
|
items.items[1] = create_menu_item("QuickJS", start_quickjs);
|
|
|
|
|
|
|
|
launcher_loop();
|
|
|
|
|
|
|
|
for (size_t i = 0; i < LENGTH(items.items); i++) {
|
|
|
|
// clear out heap allocated memory.
|
|
|
|
free(items.items[i]);
|
|
|
|
}
|
|
|
|
|
2024-06-20 04:08:16 +00:00
|
|
|
GRRLIB_Exit();
|
2024-06-19 04:51:50 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|