diff --git a/.gitignore b/.gitignore index 6641d0c2fb..e3589bc748 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.o +*.bmpobj *.so *.dll /ssnes diff --git a/Makefile.wii b/Makefile.wii index a4d81408f6..f67bfc1f41 100644 --- a/Makefile.wii +++ b/Makefile.wii @@ -9,6 +9,7 @@ DEBUG = 0 CC = powerpc-eabi-gcc CXX = powerpc-eabi-g++ +LD = powerpc-eabi-ld DOL_TARGET := ssnes.dol ELF_TARGET := ssnes.elf @@ -22,7 +23,7 @@ CXXFLAGS += -Wall -std=gnu99 $(MACHDEP) $(INCLUDE) LDFLAGS := $(MACHDEP) LIBS := -lfat -lsnes -lwiiuse -logc -lbte -lfreetype -OBJ = wii/main.o fifo_buffer.o ssnes.o driver.o gfx/fonts.o file.o settings.o message.o rewind.o movie.o ups.o bps.o strl.o screenshot.o audio/hermite.o dynamic.o audio/utils.o conf/config_file.o wii/audio.o wii/input.o wii/video.o +OBJ = wii/main.o fifo_buffer.o ssnes.o driver.o gfx/fonts.o file.o settings.o message.o rewind.o movie.o ups.o bps.o strl.o screenshot.o audio/hermite.o dynamic.o audio/utils.o conf/config_file.o wii/audio.o wii/input.o wii/video.o console/sgui.o console/list.o console/font.bmpobj CFLAGS += -std=gnu99 -DHAVE_CONFIGFILE=1 -DHAVE_GETOPT_LONG -DHAVE_FREETYPE -DPACKAGE_VERSION=\"0.9.3\" -Dmain=ssnes_main -Wno-char-subscripts @@ -45,6 +46,9 @@ $(ELF_TARGET): $(OBJ) %.o: %.c $(CC) $(CFLAGS) -c -o $@ $< +%.bmpobj: %.bmp + $(LD) -r -b binary -o $@ $< + clean: rm -f $(DOL_TARGET) rm -f $(ELF_TARGET) diff --git a/console/font.bmp b/console/font.bmp new file mode 100755 index 0000000000..ec06a946cc Binary files /dev/null and b/console/font.bmp differ diff --git a/console/list.c b/console/list.c new file mode 100644 index 0000000000..9587b08d65 --- /dev/null +++ b/console/list.c @@ -0,0 +1,118 @@ +/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes. + * Copyright (C) 2010-2011 - Hans-Kristian Arntzen + * + * Some code herein may be based on code found in BSNES. + * + * SSNES is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with SSNES. + * If not, see . + */ + +#include "list.h" +#include +#include +#include + +struct sgui_file +{ + char *path; + sgui_file_type_t type; +}; + +struct sgui_list +{ + struct sgui_file *list; + + size_t capacity; + size_t ptr; +}; + +sgui_list_t *sgui_list_new(void) +{ + return (sgui_list_t*)calloc(1, sizeof(sgui_list_t)); +} + +bool sgui_list_empty(const sgui_list_t *list) +{ + return list->ptr == 0; +} + +void sgui_list_push(sgui_list_t *list, const char *path, sgui_file_type_t type) +{ + if (list->ptr >= list->capacity) + { + list->capacity++; + list->capacity *= 2; + list->list = (struct sgui_file*)realloc(list->list, list->capacity * sizeof(struct sgui_file)); + } + + list->list[list->ptr].path = strdup(path); + list->list[list->ptr].type = type; + list->ptr++; +} + +void sgui_list_pop(sgui_list_t *list) +{ + if (!sgui_list_empty(list)) + free(list->list[--list->ptr].path); +} + +void sgui_list_free(sgui_list_t *list) +{ + for (size_t i = 0; i < list->ptr; i++) + free(list->list[i].path); + free(list->list); + free(list); +} + +void sgui_list_clear(sgui_list_t *list) +{ + for (size_t i = 0; i < list->ptr; i++) + free(list->list[i].path); + list->ptr = 0; +} + +void sgui_list_back(const sgui_list_t *list, + const char **path, sgui_file_type_t *file_type) +{ + if (sgui_list_size(list) > 0) + sgui_list_at(list, sgui_list_size(list) - 1, path, file_type); +} + +size_t sgui_list_size(const sgui_list_t *list) +{ + return list->ptr; +} + +void sgui_list_at(const sgui_list_t *list, size_t index, + const char **path, sgui_file_type_t *file_type) +{ + if (path) + *path = list->list[index].path; + if (file_type) + *file_type = list->list[index].type; +} + +static int list_comp(const void *a_, const void *b_) +{ + const struct sgui_file *a = (const struct sgui_file*)a_; + const struct sgui_file *b = (const struct sgui_file*)b_; + + if (a->type != b->type) + return a->type == SGUI_FILE_DIRECTORY ? -1 : 1; + + return strcmp(a->path, b->path); +} + +void sgui_list_sort(sgui_list_t *list) +{ + qsort(list->list, list->ptr, sizeof(struct sgui_file), list_comp); +} + diff --git a/console/list.h b/console/list.h new file mode 100644 index 0000000000..00b31f050b --- /dev/null +++ b/console/list.h @@ -0,0 +1,34 @@ +#ifndef SGUI_LIST_H__ +#define SGUI_LIST_H__ + +#include "sgui.h" +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct sgui_list sgui_list_t; + +sgui_list_t *sgui_list_new(void); +void sgui_list_free(sgui_list_t *list); + +void sgui_list_push(sgui_list_t *list, const char *path, sgui_file_type_t type); +void sgui_list_pop(sgui_list_t *list); +void sgui_list_clear(sgui_list_t *list); + +bool sgui_list_empty(const sgui_list_t *list); +void sgui_list_back(const sgui_list_t *list, + const char **path, sgui_file_type_t *type); + +size_t sgui_list_size(const sgui_list_t *list); +void sgui_list_at(const sgui_list_t *list, size_t index, + const char **path, sgui_file_type_t *type); + +void sgui_list_sort(sgui_list_t *list); + +#ifdef __cplusplus +} +#endif +#endif + diff --git a/console/sgui.c b/console/sgui.c new file mode 100644 index 0000000000..f1c5b85367 --- /dev/null +++ b/console/sgui.c @@ -0,0 +1,308 @@ +/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes. + * Copyright (C) 2010-2011 - Hans-Kristian Arntzen + * + * Some code herein may be based on code found in BSNES. + * + * SSNES is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with SSNES. + * If not, see . + */ + +#include "sgui.h" +#include "list.h" +#include +#include +#include +#include +#include + +#define FONT_WIDTH 5 +#define FONT_HEIGHT 10 +#define FONT_WIDTH_STRIDE (FONT_WIDTH + 1) +#define FONT_HEIGHT_STRIDE (FONT_HEIGHT + 1) + +#define TERM_WIDTH (((SGUI_WIDTH - 30) / (FONT_WIDTH_STRIDE))) +#define TERM_HEIGHT (((SGUI_HEIGHT - 30) / (FONT_HEIGHT_STRIDE))) +#define TERM_START_X 15 +#define TERM_START_Y 15 + +struct sgui_handle +{ + uint16_t *frame_buf; + size_t frame_buf_pitch; + const uint8_t *font_buf; + + sgui_folder_enum_cb_t folder_cb; + void *userdata; + + sgui_list_t *path_stack; + sgui_list_t *folder_buf; + size_t directory_ptr; + bool need_refresh; + + char path_buf[PATH_MAX]; + + uint16_t font_white[256][FONT_HEIGHT][FONT_WIDTH]; + uint16_t font_green[256][FONT_HEIGHT][FONT_WIDTH]; +}; + +static void copy_glyph(uint16_t glyph_white[FONT_HEIGHT][FONT_WIDTH], + uint16_t glyph_green[FONT_HEIGHT][FONT_WIDTH], + const uint8_t *buf) +{ + for (int y = 0; y < FONT_HEIGHT; y++) + { + for (int x = 0; x < FONT_WIDTH; x++) + { + uint32_t col = + ((uint32_t)buf[3 * (-y * 256 + x) + 0] << 0) | + ((uint32_t)buf[3 * (-y * 256 + x) + 1] << 8) | + ((uint32_t)buf[3 * (-y * 256 + x) + 2] << 16); + + glyph_white[y][x] = col == 0xff ? 0 : 0x7fff; + glyph_green[y][x] = col == 0xff ? 0 : (5 << 10) | (20 << 5) | (5 << 0); + } + } +} + +static void init_font(sgui_handle_t *sgui, const char *path) +{ + for (unsigned i = 0; i < 256; i++) + { + unsigned y = i / 16; + unsigned x = i % 16; + copy_glyph(sgui->font_white[i], + sgui->font_green[i], + sgui->font_buf + 54 + 3 * (256 * (255 - 16 * y) + 16 * x)); + } +} + +sgui_handle_t *sgui_init(const char *base_path, + uint16_t *buf, size_t buf_pitch, + const uint8_t *font_buf, + sgui_folder_enum_cb_t folder_cb, void *userdata) +{ + sgui_handle_t *sgui = (sgui_handle_t*)calloc(1, sizeof(*sgui)); + + sgui->frame_buf = buf; + sgui->frame_buf_pitch = buf_pitch; + sgui->font_buf = font_buf; + + sgui->folder_cb = folder_cb; + sgui->userdata = userdata; + + sgui->path_stack = sgui_list_new(); + sgui->folder_buf = sgui_list_new(); + sgui_list_push(sgui->path_stack, base_path, SGUI_FILE_DIRECTORY); + + init_font(sgui, "font.bmp"); + + return sgui; +} + +void sgui_free(sgui_handle_t *sgui) +{ + sgui_list_free(sgui->path_stack); + sgui_list_free(sgui->folder_buf); + free(sgui); +} + +static uint16_t gray_filler(unsigned x, unsigned y) +{ + uint16_t col = ((x + y) & 1) + 2; + return (col << 0) | (col << 5) | (col << 10); +} + +static uint16_t green_filler(unsigned x, unsigned y) +{ + uint16_t col = ((x + y) & 1) + 2; + return (col << 0) | (col << 6) | (col << 10); +} + +static void fill_rect(uint16_t *buf, unsigned pitch, + unsigned x, unsigned y, + unsigned width, unsigned height, + uint16_t (*col)(unsigned x, unsigned y)) +{ + for (unsigned j = y; j < y + height; j++) + for (unsigned i = x; i < x + width; i++) + buf[j * (pitch >> 1) + i] = col(i, j); +} + +static void blit_line(sgui_handle_t *sgui, + unsigned x, unsigned y, const char *message, bool green) +{ + while (*message) + { + for (unsigned j = 0; j < FONT_HEIGHT; j++) + { + for (unsigned i = 0; i < FONT_WIDTH; i++) + { + uint16_t col = green ? + sgui->font_green[(unsigned char)*message][j][i] : + sgui->font_white[(unsigned char)*message][j][i]; + + if (col) + sgui->frame_buf[(y + j) * (sgui->frame_buf_pitch >> 1) + (x + i)] = col; + } + } + + x += FONT_WIDTH_STRIDE; + message++; + } +} + +static void render_text(sgui_handle_t *sgui, size_t begin, size_t end) +{ + fill_rect(sgui->frame_buf, sgui->frame_buf_pitch, + 0, 0, SGUI_WIDTH, SGUI_HEIGHT, gray_filler); + + fill_rect(sgui->frame_buf, sgui->frame_buf_pitch, + 5, 5, SGUI_WIDTH - 10, 5, green_filler); + + fill_rect(sgui->frame_buf, sgui->frame_buf_pitch, + 5, SGUI_HEIGHT - 10, SGUI_WIDTH - 10, 5, green_filler); + + fill_rect(sgui->frame_buf, sgui->frame_buf_pitch, + 5, 5, 5, SGUI_HEIGHT - 10, green_filler); + + fill_rect(sgui->frame_buf, sgui->frame_buf_pitch, + SGUI_WIDTH - 10, 5, 5, SGUI_HEIGHT - 10, green_filler); + + unsigned x = TERM_START_X; + unsigned y = TERM_START_Y; + + for (size_t i = begin; i < end; i++, y += FONT_HEIGHT_STRIDE) + { + const char *path; + sgui_file_type_t type; + sgui_list_at(sgui->folder_buf, i, &path, &type); + + char message[TERM_WIDTH + 1]; + snprintf(message, sizeof(message), "%c %-*s %6s\n", + i == sgui->directory_ptr ? '>' : ' ', + TERM_WIDTH - (6 + 1 + 2), + path, + type == SGUI_FILE_PLAIN ? "(FILE)" : "(DIR)"); + + blit_line(sgui, x, y, message, i == sgui->directory_ptr); + } +} + +const char *sgui_iterate(sgui_handle_t *sgui, sgui_action_t action) +{ + switch (action) + { + case SGUI_ACTION_UP: + if (sgui->directory_ptr > 0) + sgui->directory_ptr--; + break; + + case SGUI_ACTION_DOWN: + if (sgui->directory_ptr + 1 < sgui_list_size(sgui->folder_buf)) + sgui->directory_ptr++; + break; + + case SGUI_ACTION_LEFT: + case SGUI_ACTION_CANCEL: + if (sgui_list_size(sgui->path_stack) > 1) + { + sgui_list_pop(sgui->path_stack); + sgui->need_refresh = true; + } + break; + + case SGUI_ACTION_RIGHT: + case SGUI_ACTION_OK: + { + if (sgui_list_size(sgui->folder_buf) == 0) + return NULL; + + const char *path = NULL; + sgui_file_type_t type = SGUI_FILE_PLAIN; + sgui_list_at(sgui->folder_buf, sgui->directory_ptr, + &path, &type); + + const char *dir; + sgui_list_back(sgui->path_stack, &dir, NULL); + + if (type == SGUI_FILE_DIRECTORY) + { + char cat_path[PATH_MAX]; + snprintf(cat_path, sizeof(cat_path), "%s/%s", + strcmp(dir, "/") == 0 ? "" : dir, path); + + sgui_list_push(sgui->path_stack, cat_path, SGUI_FILE_DIRECTORY); + sgui->need_refresh = true; + } + else + { + snprintf(sgui->path_buf, sizeof(sgui->path_buf), "%s/%s", + strcmp(dir, "/") == 0 ? "" : dir, path); + return sgui->path_buf; + } + break; + } + + case SGUI_ACTION_REFRESH: + sgui->need_refresh = true; + break; + + default: + return NULL; + } + + if (sgui->need_refresh) + { + sgui->directory_ptr = 0; + sgui_list_clear(sgui->folder_buf); + + const char *path = NULL; + sgui_list_back(sgui->path_stack, &path, NULL); + + if (!sgui->folder_cb(path, + (sgui_file_enum_cb_t)sgui_list_push, + sgui->userdata, sgui->folder_buf)) + return NULL; + + sgui_list_sort(sgui->folder_buf); + + sgui->need_refresh = false; + } + + size_t begin = sgui->directory_ptr >= TERM_HEIGHT / 2 ? + sgui->directory_ptr - TERM_HEIGHT / 2 : 0; + size_t end = sgui->directory_ptr + TERM_HEIGHT <= sgui_list_size(sgui->folder_buf) ? + sgui->directory_ptr + TERM_HEIGHT : sgui_list_size(sgui->folder_buf); + + if (end - begin > TERM_HEIGHT) + end = begin + TERM_HEIGHT; + +#if 0 + printf("========================================\n"); + for (size_t i = begin; i < end; i++) + { + const char *path; + sgui_file_type_t type; + sgui_list_at(sgui->folder_buf, i, &path, &type); + + printf("%c %-50s %s\n", + i == sgui->directory_ptr ? '>' : ' ', + path, + type == SGUI_FILE_PLAIN ? "(FILE)" : "(DIR)"); + + } + printf("========================================\n"); +#endif + + render_text(sgui, begin, end); + return NULL; +} + diff --git a/console/sgui.h b/console/sgui.h new file mode 100644 index 0000000000..8b4c612811 --- /dev/null +++ b/console/sgui.h @@ -0,0 +1,71 @@ +/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes. + * Copyright (C) 2010-2011 - Hans-Kristian Arntzen + * + * Some code herein may be based on code found in BSNES. + * + * SSNES is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with SSNES. + * If not, see . + */ + +#ifndef SGUI_H__ +#define SGUI_H__ + +#include +#include + +#ifndef __cplusplus +#include +#else +extern "C" { +#endif + +typedef enum +{ + SGUI_FILE_PLAIN, + SGUI_FILE_DIRECTORY +} sgui_file_type_t; + +typedef enum +{ + SGUI_ACTION_UP, + SGUI_ACTION_DOWN, + SGUI_ACTION_LEFT, + SGUI_ACTION_RIGHT, + SGUI_ACTION_OK, + SGUI_ACTION_CANCEL, + SGUI_ACTION_REFRESH, + SGUI_ACTION_NOOP +} sgui_action_t; + +typedef struct sgui_handle sgui_handle_t; + +typedef void (*sgui_file_enum_cb_t)(void *ctx, const char *path, + sgui_file_type_t file_type); +typedef bool (*sgui_folder_enum_cb_t)(const char *directory, + sgui_file_enum_cb_t file_cb, void *userdata, void *ctx); + +#define SGUI_WIDTH 320 +#define SGUI_HEIGHT 240 + +sgui_handle_t *sgui_init(const char *base_path, + uint16_t *framebuf, size_t framebuf_pitch, + const uint8_t *font_buf, + sgui_folder_enum_cb_t folder_cb, void *userdata); + +const char *sgui_iterate(sgui_handle_t *sgui, sgui_action_t action); + +void sgui_free(sgui_handle_t *sgui); + +#ifdef __cplusplus +} +#endif +#endif + diff --git a/wii/driver.h b/wii/driver.h new file mode 100644 index 0000000000..cd88d0df9c --- /dev/null +++ b/wii/driver.h @@ -0,0 +1,28 @@ +/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes. + * Copyright (C) 2010-2011 - Hans-Kristian Arntzen + * + * Some code herein may be based on code found in BSNES. + * + * SSNES is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with SSNES. + * If not, see . + */ + +#ifndef WII_VIDEO_H__ +#define WII_VIDEO_H__ + +void wii_video_init(void); +void wii_video_deinit(void); + +void wii_input_init(void); +void wii_input_deinit(void); + +#endif + diff --git a/wii/input.c b/wii/input.c index 422b6f7baa..5c3f745007 100644 --- a/wii/input.c +++ b/wii/input.c @@ -60,21 +60,21 @@ static void reset_callback(void) g_quit = true; } -static void *wii_input_init(void) +void wii_input_init(void) { - static bool inited = false; - if (!inited) - { - PAD_Init(); - WPAD_Init(); - SYS_SetResetCallback(reset_callback); - SYS_SetPowerCallback(reset_callback); - inited = true; - } - - return (void*)-1; + PAD_Init(); + WPAD_Init(); + SYS_SetResetCallback(reset_callback); + SYS_SetPowerCallback(reset_callback); } +void wii_input_deinit(void) +{} + +static void *wii_input_initialize(void) +{ + return (void*)-1; +} static void wii_input_poll(void *data) { @@ -147,7 +147,7 @@ static bool wii_key_pressed(void *data, int key) } const input_driver_t input_wii = { - .init = wii_input_init, + .init = wii_input_initialize, .poll = wii_input_poll, .input_state = wii_input_state, .key_pressed = wii_key_pressed, diff --git a/wii/main.c b/wii/main.c index 6d48484598..f35d7f55e1 100644 --- a/wii/main.c +++ b/wii/main.c @@ -17,23 +17,138 @@ #undef main +#include +#include "../console/sgui.h" +#include "../driver.h" +#include "../general.h" +#include "../libsnes.hpp" +#include "driver.h" + #include #include +#include +#include +#include +#include +#include +#include + #include #include #include -#include -#include "../driver.h" + +static uint16_t menu_framebuf[SGUI_WIDTH * SGUI_HEIGHT]; + +static bool folder_cb(const char *directory, sgui_file_enum_cb_t file_cb, + void *userdata, void *ctx) +{ + (void)userdata; + + if (!*directory) + { + file_cb(ctx, "sd:", SGUI_FILE_DIRECTORY); + return true; + } + + DIR *dir = opendir(directory); + if (!dir) + return false; + + struct dirent *entry; + while ((entry = readdir(dir))) + { + char stat_path[PATH_MAX]; + snprintf(stat_path, sizeof(stat_path), "%s/%s", directory, entry->d_name); + struct stat st; + if (stat(stat_path, &st) < 0) + continue; + + if (!S_ISDIR(st.st_mode) && !S_ISREG(st.st_mode)) + continue; + + file_cb(ctx, + entry->d_name, S_ISDIR(st.st_mode) ? + SGUI_FILE_DIRECTORY : SGUI_FILE_PLAIN); + } + + closedir(dir); + return true; +} + +static const char *get_rom_path(sgui_handle_t *sgui) +{ + uint16_t old_input_state = 0; + uint16_t input_state = 0; + + for (;;) + { + input_wii.poll(NULL); + + if (input_wii.key_pressed(NULL, SSNES_QUIT_KEY)) + return NULL; + + for (unsigned i = 0; i < SSNES_FIRST_META_KEY; i++) + { + input_state |= input_wii.input_state(NULL, NULL, false, + SNES_DEVICE_JOYPAD, 0, i) ? (1 << i) : 0; + } + + uint16_t trigger_state = input_state & ~old_input_state; + + sgui_action_t action = SGUI_ACTION_NOOP; + if (trigger_state & (1 << SNES_DEVICE_ID_JOYPAD_B)) + action = SGUI_ACTION_CANCEL; + else if (trigger_state & (1 << SNES_DEVICE_ID_JOYPAD_A)) + action = SGUI_ACTION_OK; + else if (trigger_state & (1 << SNES_DEVICE_ID_JOYPAD_UP)) + action = SGUI_ACTION_UP; + else if (trigger_state & (1 << SNES_DEVICE_ID_JOYPAD_DOWN)) + action = SGUI_ACTION_DOWN; + + const char *ret = sgui_iterate(sgui, action); + if (ret) + return ret; + + video_wii.frame(NULL, menu_framebuf, + SGUI_WIDTH, SGUI_HEIGHT, + SGUI_WIDTH * sizeof(uint16_t), NULL); + + old_input_state = input_state; + ssnes_sleep(10); + } +} int ssnes_main(int argc, char **argv); +extern uint8_t _binary_console_font_bmp_start[]; + int main(void) { - char arg0[] = "ssnes"; - char arg1[] = "sd:/MM2.nes"; - char *argv[] = { arg0, arg1, NULL }; - fatInitDefault(); - return ssnes_main(sizeof(argv) / sizeof(argv[0]) - 1, argv); + + wii_video_init(); + wii_input_init(); + + sgui_handle_t *sgui = sgui_init("", + menu_framebuf, SGUI_WIDTH * sizeof(uint16_t), + _binary_console_font_bmp_start, folder_cb, NULL); + + const char *rom_path = get_rom_path(sgui); + + int ret = 0; + if (rom_path) + { + char *argv[] = { strdup("ssnes"), strdup(rom_path), NULL }; + ret = ssnes_main(sizeof(argv) / sizeof(argv[0]) - 1, argv); + free(argv[0]); + free(argv[1]); + } + + wii_input_deinit(); + wii_video_deinit(); + + sgui_free(sgui); + + return ret; } diff --git a/wii/video.c b/wii/video.c index 23e009eb4f..cdb07dd8e9 100644 --- a/wii/video.c +++ b/wii/video.c @@ -17,6 +17,7 @@ #include "../driver.h" #include "../general.h" +#include "driver.h" #include #include #include @@ -146,8 +147,7 @@ static void build_disp_list(void) display_list_size = GX_EndDispList(); } -static void *wii_init(const video_info_t *video, - const input_driver_t **input, void **input_data) +void wii_video_init(void) { VIDEO_Init(); GXRModeObj *mode = VIDEO_GetPreferredMode(NULL); @@ -160,6 +160,25 @@ static void *wii_init(const video_info_t *video, init_vtx(mode); build_disp_list(); + + g_filter = true; + g_vsync = true; +} + +void wii_video_deinit(void) +{ + GX_AbortFrame(); + GX_Flush(); + VIDEO_SetBlack(true); + VIDEO_Flush(); + + for (unsigned i = 0; i < 3; i++) + free(MEM_K1_TO_K0(g_framebuf[i])); +} + +static void *wii_init(const video_info_t *video, + const input_driver_t **input, void **input_data) +{ g_filter = video->smooth ? GX_LINEAR : GX_NEAR; g_vsync = video->vsync; @@ -255,13 +274,6 @@ static bool wii_focus(void *data) static void wii_free(void *data) { (void)data; - GX_AbortFrame(); - GX_Flush(); - VIDEO_SetBlack(true); - VIDEO_Flush(); - - for (unsigned i = 0; i < 3; i++) - free(MEM_K1_TO_K0(g_framebuf[i])); } const video_driver_t video_wii = {