From 53c814a38aaa5b7cb7136ef5c1a5815f018ddcb9 Mon Sep 17 00:00:00 2001 From: Fabian Ockenfels Date: Sun, 8 Jun 2025 13:00:57 +0200 Subject: [PATCH 1/7] refactor: remove `gdrom_fs` in favor of default KallistiOS `kos/fs.h` --- src/openmenu/src/ui/dc/font_bmf.c | 5 +-- src/openmenu/src/ui/dc/pvr_texture.c | 9 ++-- src/openmenu/src/ui/theme_manager.c | 7 ++-- src/openmenu_shared/CMakeLists.txt | 1 - .../include/backend/dat_format.h | 5 ++- src/openmenu_shared/include/gdrom/gdrom_fs.h | 41 ------------------- src/openmenu_shared/src/backend/db_list.c | 1 - src/openmenu_shared/src/backend/gd_list.c | 11 ++--- src/openmenu_shared/src/texture/dat_reader.c | 4 +- 9 files changed, 16 insertions(+), 68 deletions(-) delete mode 100644 src/openmenu_shared/include/gdrom/gdrom_fs.h diff --git a/src/openmenu/src/ui/dc/font_bmf.c b/src/openmenu/src/ui/dc/font_bmf.c index 9c70f26..f1fc71b 100644 --- a/src/openmenu/src/ui/dc/font_bmf.c +++ b/src/openmenu/src/ui/dc/font_bmf.c @@ -8,13 +8,13 @@ */ #include +#include #include #include #include #include #include -#include #include #include "ui/draw_prototypes.h" @@ -407,8 +407,7 @@ font_bmf_init(const char* fnt, const char* texture, int is_wide) { } int ret = 0; char temp_fnt[128]; - memcpy(temp_fnt, DISC_PREFIX, strlen(DISC_PREFIX) + 1); - strcat(temp_fnt, fnt); + snprintf(temp_fnt, 127, "/cd/%s", fnt); /* If we arent loaded then load eveyrthing, otherwise just load texture */ if (!font_loaded) { diff --git a/src/openmenu/src/ui/dc/pvr_texture.c b/src/openmenu/src/ui/dc/pvr_texture.c index 49a1085..ecb89f2 100644 --- a/src/openmenu/src/ui/dc/pvr_texture.c +++ b/src/openmenu/src/ui/dc/pvr_texture.c @@ -6,13 +6,12 @@ * ----- * Copyright (c) 2019 Hayden Kowalchuk */ -#include "pvr_texture.h" +#include #include #include #include - -#include +#include "pvr_texture.h" #define PVR_HDR_SIZE 0x20 @@ -139,9 +138,7 @@ static void pvr_read_to_internal(const char* filename) { uint32_t texSize; file_t tex_fd; - // memcpy(filename_safe, DISC_PREFIX, strlen(DISC_PREFIX) + 1); - // strcat(filename_safe, filename); - snprintf(filename_safe, 127, "%s%s", DISC_PREFIX, filename); + snprintf(filename_safe, 127, "/cd/%s", filename); /* replace all - with _ */ char* iter = filename_safe; diff --git a/src/openmenu/src/ui/theme_manager.c b/src/openmenu/src/ui/theme_manager.c index c54100a..0dcd3bd 100644 --- a/src/openmenu/src/ui/theme_manager.c +++ b/src/openmenu/src/ui/theme_manager.c @@ -9,12 +9,12 @@ * http://www.opensource.org/licenses/BSD-3-Clause */ +#include #include #include #include #include -#include #include "ui/draw_prototypes.h" #include "ui/theme_manager.h" @@ -238,15 +238,14 @@ theme_read(const char* filename, void* theme, int type) { static void load_themes(char* basePath) { char path[128]; - DIRENT_TYPE dp; - DIR_TYPE dir = opendir(basePath); + struct dirent* dp; + DIR* dir = opendir(basePath); if (!dir) { return; } while ((dp = readdir(dir)) != NULL) { - // printf("load_themes: %s\n", dp->d_name); if (strcmp(dp->d_name, ".") != 0 && strcmp(dp->d_name, "..") != 0) { if (strncasecmp(dp->d_name, "CUST_", 5) == 0) { int theme_num = dp->d_name[5] - '0'; diff --git a/src/openmenu_shared/CMakeLists.txt b/src/openmenu_shared/CMakeLists.txt index 11de0aa..928d1b9 100644 --- a/src/openmenu_shared/CMakeLists.txt +++ b/src/openmenu_shared/CMakeLists.txt @@ -21,7 +21,6 @@ if (BUILD_DREAMCAST) ) list(APPEND OPENMENUSHARED_DREAMCAST_HEADERS include/backend/db_list.h - include/gdrom/gdrom_fs.h include/texture/serial_sanitize.h ) endif () diff --git a/src/openmenu_shared/include/backend/dat_format.h b/src/openmenu_shared/include/backend/dat_format.h index 5315b39..2eeec82 100644 --- a/src/openmenu_shared/include/backend/dat_format.h +++ b/src/openmenu_shared/include/backend/dat_format.h @@ -11,9 +11,12 @@ #pragma once #include - #include +#ifdef _arch_dreamcast +#include +#endif + typedef struct bin_item { char ID[12]; uint32_t offset; diff --git a/src/openmenu_shared/include/gdrom/gdrom_fs.h b/src/openmenu_shared/include/gdrom/gdrom_fs.h deleted file mode 100644 index 5421ba7..0000000 --- a/src/openmenu_shared/include/gdrom/gdrom_fs.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * File: gdrom_fs.h - * Project: gdrom - * File Created: Wednesday, 9th June 2021 4:27:01 pm - * Author: Hayden Kowalchuk - * ----- - * Copyright (c) 2021 Hayden Kowalchuk, Hayden Kowalchuk - * License: BSD 3-clause "New" or "Revised" License, http://www.opensource.org/licenses/BSD-3-Clause - */ - -#pragma once - -/* Used to control reading from GD-ROM or CD-ROM */ -#ifdef GDROM_FS -#include "gdfs.h" -typedef int FD_TYPE; -typedef DIR* DIR_TYPE; -typedef struct gd_dirent* DIRENT_TYPE; -#define DISC_PREFIX "" - -#define fopen(path, b) gd_open(path, O_RDONLY) -#define fread(buf, size, num, fd) gd_read(fd, buf, (size) * (num)) -#define fseek(fd, offset, origin) gd_seek(fd, offset, origin) -#define fclose(fd) gd_close(fd) -#define ftell(fd) gd_tell(fd) -#define opendir(path) gd_opendir(path) -#define readdir(fd) gd_readdir(fd) -#define closedir(fd) gd_closedir(fd) -#define FD_IS_OK(fd) (((fd) > 0)) -#else -#include -#include -#include -typedef FILE* FD_TYPE; -typedef DIR* DIR_TYPE; -typedef struct dirent* DIRENT_TYPE; -#ifdef _arch_dreamcast -#define DISC_PREFIX "/cd/" -#endif -#define FD_IS_OK(fd) ((fd) != NULL) -#endif diff --git a/src/openmenu_shared/src/backend/db_list.c b/src/openmenu_shared/src/backend/db_list.c index 6c9f811..2ace597 100644 --- a/src/openmenu_shared/src/backend/db_list.c +++ b/src/openmenu_shared/src/backend/db_list.c @@ -11,7 +11,6 @@ #include -#include "gdrom/gdrom_fs.h" #include "backend/db_list.h" #include "backend/dat_format.h" #include "texture/serial_sanitize.h" diff --git a/src/openmenu_shared/src/backend/gd_list.c b/src/openmenu_shared/src/backend/gd_list.c index 2bc4e53..03bf4d5 100644 --- a/src/openmenu_shared/src/backend/gd_list.c +++ b/src/openmenu_shared/src/backend/gd_list.c @@ -23,8 +23,8 @@ #include "backend/gd_list.h" #ifdef _arch_dreamcast -#include "gdrom/gdrom_fs.h" -#define PATH_PREFIX DISC_PREFIX +#include +#define PATH_PREFIX "/cd/" #else #define PATH_PREFIX "" #endif @@ -108,12 +108,7 @@ static gd_item* list_multidisc[MULTIDISC_MAX_GAMES_PER_SET] = {NULL}; #ifndef STANDALONE_BINARY static inline long int filelength(file_t f) { - long int end; - fs_seek(f, 0, SEEK_END); - end = fs_tell(f); - fs_seek(f, 0, SEEK_SET); - - return end; + return fs_total(f); } #else static inline long int diff --git a/src/openmenu_shared/src/texture/dat_reader.c b/src/openmenu_shared/src/texture/dat_reader.c index cc8f117..5185545 100644 --- a/src/openmenu_shared/src/texture/dat_reader.c +++ b/src/openmenu_shared/src/texture/dat_reader.c @@ -14,7 +14,6 @@ #include -#include #include /* Define configure constants */ @@ -54,8 +53,7 @@ DAT_load_parse(dat_file* bin, const char* path) { const char* filename_safe = path; #else char filename_safe[128]; - memcpy(filename_safe, DISC_PREFIX, strlen(DISC_PREFIX) + 1); - strcat(filename_safe, path); + snprintf(filename_safe, 127, "/cd/%s", path); bin_fd = fs_open(filename_safe, O_RDONLY); #endif From 528478f240ab0c5231a6bf09f5b5997584a8e42e Mon Sep 17 00:00:00 2001 From: Fabian Ockenfels Date: Sun, 8 Jun 2025 13:10:26 +0200 Subject: [PATCH 2/7] refactor: remove code comments, touch up some code --- .../src/texture/simple_texture_allocator.c | 9 +-------- src/openmenu/src/ui/dc/font_bitmap.c | 15 --------------- src/openmenu/src/ui/dc/font_bmf.c | 6 ------ src/openmenu/src/ui/dc/input.c | 4 ---- src/openmenu/src/ui/draw_kos.c | 11 +++++------ src/openmenu/src/ui/ui_grid.c | 4 ++-- src/openmenu/src/ui/ui_line_desc.c | 8 ++++---- src/openmenu/src/ui/ui_menu_credits.c | 4 ++-- src/openmenu/src/ui/ui_scroll.c | 5 +++-- src/openmenu/src/vm2/vm2_api.c | 10 ---------- src/openmenu_shared/src/backend/gd_list.c | 5 ++++- src/openmenu_shared/src/texture/dat_reader.c | 6 ++---- 12 files changed, 23 insertions(+), 64 deletions(-) diff --git a/src/openmenu/src/texture/simple_texture_allocator.c b/src/openmenu/src/texture/simple_texture_allocator.c index 6fc5c89..a601ef8 100644 --- a/src/openmenu/src/texture/simple_texture_allocator.c +++ b/src/openmenu/src/texture/simple_texture_allocator.c @@ -13,8 +13,8 @@ #include #include -#include "texture/txr_manager.h" #include "texture/simple_texture_allocator.h" +#include "texture/txr_manager.h" static struct Simple_Texture textures[32]; static void* tex_buffer = NULL; @@ -34,8 +34,6 @@ texman_inited(void) { void texman_reset(void* buf, uint32_t size) { - // txr_empty_small_pool(); - // txr_empty_large_pool(); memset(textures, 0, sizeof(textures)); tex_number = 0; tex_buffer = tex_buffer_start = buf; @@ -43,7 +41,6 @@ texman_reset(void* buf, uint32_t size) { #ifdef DEBUG char msg[64]; sprintf(msg, "TEXMAN: reset @ %p size %d bytes\n", buf, size); - // sceIoWrite(1, msg, strlen(msg)); printf(msg); #endif } @@ -56,7 +53,6 @@ texman_clear(void) { #ifdef DEBUG char msg[64]; sprintf(msg, "TEXMAN: clear %p size %d bytes!\n", tex_buffer, TEXMAN_BUFFER_SIZE); - // sceIoWrite(1, msg, strlen(msg)); printf(msg); #endif } @@ -114,7 +110,4 @@ texman_upload(uint32_t width, uint32_t height, int bpp, const void* buffer) { current->width = width; current->height = height; memcpy(current->location, buffer, getMemorySize(width, height, bpp)); -#ifdef DEBUG - // printf("TEX_MAN upload plain [%d]\n", tex_number); -#endif } diff --git a/src/openmenu/src/ui/dc/font_bitmap.c b/src/openmenu/src/ui/dc/font_bitmap.c index eb5e504..73a5015 100644 --- a/src/openmenu/src/ui/dc/font_bitmap.c +++ b/src/openmenu/src/ui/dc/font_bitmap.c @@ -64,9 +64,6 @@ font_bmp_begin_draw() { font.texture.texture, PVR_FILTER_BILINEAR); pvr_poly_compile(&font_header, &tmp); #endif - - /* Start a textured polygon set (with the font texture) */ - // pvr_prim(&font_header, sizeof(font_header)); } void @@ -203,18 +200,6 @@ _font_bmp_draw_string(int x1, int y1, const char* str) { void font_bmp_draw_sub_wrap(int x1, int y1, int width, const char* str) { (void)width; -#if 0 - int x_start = x1; - do { - unsigned char chr = (*str) + (1 * 128); - font_draw_char(x1, y1, color, chr, 0); - x1 += (int)(char_widths[chr - 32] * FONT_SIZE_SUB + 1); - if ((x1 - x_start >= width) && (*str == ' ')) { - y1 += (FONT_HEIGHT * FONT_SIZE_SUB) + 4; - x1 = x_start; - } - } while (*++str) { -#endif _font_bmp_draw_string(x1, y1, str); } diff --git a/src/openmenu/src/ui/dc/font_bmf.c b/src/openmenu/src/ui/dc/font_bmf.c index f1fc71b..42c49ec 100644 --- a/src/openmenu/src/ui/dc/font_bmf.c +++ b/src/openmenu/src/ui/dc/font_bmf.c @@ -256,12 +256,6 @@ static int BMF_parse_kerning(file_t fd, size_t block_size, bm_font* font) { DBG_PRINT("BMF found kerning block!\n"); - /* Do nothing! */ - /* - fseek(fd, block_size, SEEK_CUR); - font->kerns = NULL; - */ - /* Parse and save */ int num_pairs = block_size / sizeof(bm_kern_pair); diff --git a/src/openmenu/src/ui/dc/input.c b/src/openmenu/src/ui/dc/input.c index 2f626ba..d2af782 100644 --- a/src/openmenu/src/ui/dc/input.c +++ b/src/openmenu/src/ui/dc/input.c @@ -47,10 +47,6 @@ INPT_ReceiveFromHost(inputs _in) { /* Handle Analog Axes Values */ /* Loops through 4 Axes for 2 Analog Sticks */ - /*for (int index = 0; index < 2; index++) - { - uint8_t *axes_in = (&_in.axes_1) + index; - }*/ _current.axes_1 = _in.axes_1; _current.axes_2 = _in.axes_2; diff --git a/src/openmenu/src/ui/draw_kos.c b/src/openmenu/src/ui/draw_kos.c index af72996..d92840f 100644 --- a/src/openmenu/src/ui/draw_kos.c +++ b/src/openmenu/src/ui/draw_kos.c @@ -148,13 +148,12 @@ draw_load_texture_from_DAT_to_buffer(const struct dat_file* bin, const char* ID, img->height = img_empty_boxart.height; img->format = img_empty_boxart.format; return img; - } else { - txr = - load_pvr_from_buffer_to_buffer(pvr_get_internal_buffer(), &img->width, &img->height, &img->format, buffer); - img->texture = txr; - - return user; } + + txr = load_pvr_from_buffer_to_buffer(pvr_get_internal_buffer(), &img->width, &img->height, &img->format, buffer); + img->texture = txr; + + return user; } /* draws an image at coords of a given size */ diff --git a/src/openmenu/src/ui/ui_grid.c b/src/openmenu/src/ui/ui_grid.c index 2585053..e99e53d 100644 --- a/src/openmenu/src/ui/ui_grid.c +++ b/src/openmenu/src/ui/ui_grid.c @@ -281,8 +281,8 @@ draw_grid_boxes(void) { /* Draw multiple discs and how many */ draw_draw_quad(x_pos, y_pos, TILE_SIZE_X * X_SCALE * 0.5f, 28, current_theme_colors->menu_bkg_color); - char disc_str[8]; - snprintf(disc_str, 8, "%d Discs", disc_set); + char disc_str[12]; + snprintf(disc_str, 11, "%d Discs", disc_set); font_bmf_begin_draw(); font_bmf_set_height(24); font_bmf_draw_sub(x_pos + 8, y_pos + 2, current_theme_colors->text_color, disc_str); diff --git a/src/openmenu/src/ui/ui_line_desc.c b/src/openmenu/src/ui/ui_line_desc.c index ca1e3d7..0107ba1 100644 --- a/src/openmenu/src/ui/ui_line_desc.c +++ b/src/openmenu/src/ui/ui_line_desc.c @@ -201,13 +201,13 @@ draw_game_meta(void) { { if (disc_set > 1) { if (!hide_multidisc) { - char disc_str[8]; - snprintf(disc_str, 8, "Disc %d", disc_num); + char disc_str[12]; + snprintf(disc_str, 11, "Disc %d", disc_num); font_bmf_draw_sub(316 + 22 + 4, 36, current_theme_colors->text_color, disc_str); } else { /* Draw multiple discs and how many */ - char disc_str[8]; - snprintf(disc_str, 8, "%d Discs", disc_set); + char disc_str[12]; + snprintf(disc_str, 11, "%d Discs", disc_set); font_bmf_draw_sub(316 + 22 + 4, 36, current_theme_colors->text_color, disc_str); } } diff --git a/src/openmenu/src/ui/ui_menu_credits.c b/src/openmenu/src/ui/ui_menu_credits.c index e7f60ea..d374988 100644 --- a/src/openmenu/src/ui/ui_menu_credits.c +++ b/src/openmenu/src/ui/ui_menu_credits.c @@ -500,7 +500,7 @@ draw_menu_tr(void) { const int y = (480 / 2) - (height / 2); const int x_item = x + 4; - char line_buf[65]; + char line_buf[70]; /* Draw a popup in the middle of the screen */ draw_popup_menu(x, y, width, height); @@ -744,7 +744,7 @@ draw_multidisc_tr(void) { const int disc_num = list_multidisc[i]->disc[0] - '0'; strncpy(temp_game_name, list_multidisc[i]->name, sizeof(temp_game_name) - 1); temp_game_name[sizeof(temp_game_name) - 1] = '\0'; - snprintf(line_buf, 65, "%s #%d", temp_game_name, disc_num); + snprintf(line_buf, 69, "%s #%d", temp_game_name, disc_num); font_bmf_draw_auto_size(x_item, cur_y, temp_color, line_buf, width - 4); } } diff --git a/src/openmenu/src/ui/ui_scroll.c b/src/openmenu/src/ui/ui_scroll.c index 8efeae8..b3c845b 100644 --- a/src/openmenu/src/ui/ui_scroll.c +++ b/src/openmenu/src/ui/ui_scroll.c @@ -158,7 +158,7 @@ draw_bg_layers(void) { static void draw_gamelist(void) { - char buffer[128]; + char buffer[192]; const int X_ADJUST_TEXT = 7; const int Y_ADJUST_TEXT = 4; const int Y_ADJUST_CRSR = 3; /* 2 pixels higher than text */ @@ -177,7 +177,8 @@ draw_gamelist(void) { break; } - sprintf(buffer, "%02d %s", current_starting_index + i + 1, list_current[current_starting_index + i]->name); + snprintf(buffer, 191, "%02d %s", current_starting_index + i + 1, + list_current[current_starting_index + i]->name); if ((current_starting_index + i) == current_selected_item) { /* grab the disc number and if there is more than one */ int disc_set = list_current[current_selected_item]->disc[2] - '0'; diff --git a/src/openmenu/src/vm2/vm2_api.c b/src/openmenu/src/vm2/vm2_api.c index c116125..36538fd 100644 --- a/src/openmenu/src/vm2/vm2_api.c +++ b/src/openmenu/src/vm2/vm2_api.c @@ -20,12 +20,6 @@ vbl_allinfo_callback(struct maple_state_str*, maple_frame_t* frm) { /* Copy in the new buff */ memcpy(recv_buff, resp, 196); } - /*else - { - printf("maple: bad response %d on device\n",resp->response); - memcpy(recv_buff, resp, 196); - - }*/ maple_frame_unlock(frm); genwait_wake_all(frm); @@ -73,8 +67,6 @@ vm2_reply(struct maple_state_str*, maple_frame_t* frm) { if (resp->response != MAPLE_RESPONSE_OK) { printf("maple: bad response %d on device, wait ACK\n", resp->response); - } else { - printf("set image done\n"); } memcpy(recv_buff, resp, 4); @@ -145,7 +137,5 @@ check_vm2_present(maple_device_t* dev) { return 1; } - printf("check_vm2_present ERROR: %s\n", info->extended); - return 0; } diff --git a/src/openmenu_shared/src/backend/gd_list.c b/src/openmenu_shared/src/backend/gd_list.c index 03bf4d5..8153673 100644 --- a/src/openmenu_shared/src/backend/gd_list.c +++ b/src/openmenu_shared/src/backend/gd_list.c @@ -9,11 +9,11 @@ * http://www.opensource.org/licenses/BSD-3-Clause */ +#include #include #include #include #include -#include #include @@ -184,6 +184,7 @@ list_print_slots(void) { gd_item* item = &gd_slots_BASE[i]; #define CFG(s, n, default) printf("%s = %s\n", #n, item->n); #include "backend/gd_item.def" + printf("\n"); } } @@ -195,6 +196,7 @@ list_print_temp(void) { gd_item* item = list_temp[i]; #define CFG(s, n, default) printf("%s = %s\n", #n, item->n); #include "backend/gd_item.def" + printf("\n"); } } @@ -207,6 +209,7 @@ list_print(const gd_item** list) { const gd_item* item = list[i]; #define CFG(s, n, default) printf("%s = %s\n", #n, item->n); #include "backend/gd_item.def" + printf("\n"); } printf("\n"); diff --git a/src/openmenu_shared/src/texture/dat_reader.c b/src/openmenu_shared/src/texture/dat_reader.c index 5185545..a05f14c 100644 --- a/src/openmenu_shared/src/texture/dat_reader.c +++ b/src/openmenu_shared/src/texture/dat_reader.c @@ -162,9 +162,8 @@ DAT_read_file_by_ID(const dat_file* bin, const char* ID, void* buf) { fread(buf, bin->chunk_size, 1, bin->handle); #endif return 1; - } else { - return 0; } + return 0; } int @@ -179,7 +178,6 @@ DAT_read_file_by_num(const dat_file* bin, uint32_t chunk_num, void* buf) { fread(buf, bin->chunk_size, 1, bin->handle); #endif return 1; - } else { - return 0; } + return 0; } From 56b5604034cf56cfb091d28a0513b0b313e75501 Mon Sep 17 00:00:00 2001 From: Fabian Ockenfels Date: Sun, 8 Jun 2025 13:13:04 +0200 Subject: [PATCH 3/7] refactor: use standard library `round` function --- src/openmenu/src/main.c | 9 --------- src/openmenu/src/ui/draw_kos.c | 3 +-- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/src/openmenu/src/main.c b/src/openmenu/src/main.c index 425f0df..8e6deb2 100644 --- a/src/openmenu/src/main.c +++ b/src/openmenu/src/main.c @@ -88,15 +88,6 @@ ui_set_choice(int choice) { (*current_ui_setup)(); } -int -round(float x) { - if (x < 0.0f) { - return (int)(x - 0.5f); - } else { - return (int)(x + 0.5f); - } -} - void reload_ui(void) { need_reload_ui = 1; diff --git a/src/openmenu/src/ui/draw_kos.c b/src/openmenu/src/ui/draw_kos.c index d92840f..a6cd2ac 100644 --- a/src/openmenu/src/ui/draw_kos.c +++ b/src/openmenu/src/ui/draw_kos.c @@ -9,6 +9,7 @@ * http://www.opensource.org/licenses/BSD-3-Clause */ +#include #include #include @@ -17,8 +18,6 @@ #include "ui/draw_kos.h" -extern int round(float x); - image img_empty_boxart; image img_dir_boxart; From 7539bfe1037e358336e2ef0865b9979407f319b0 Mon Sep 17 00:00:00 2001 From: Fabian Ockenfels Date: Sun, 8 Jun 2025 13:15:29 +0200 Subject: [PATCH 4/7] refactor: use `fs_stat` from `kos/fs.h` to check file existence --- src/openmenu/src/ui/common.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/openmenu/src/ui/common.h b/src/openmenu/src/ui/common.h index 4513e54..7cf439e 100644 --- a/src/openmenu/src/ui/common.h +++ b/src/openmenu/src/ui/common.h @@ -10,7 +10,7 @@ #pragma once -#include +#include #include @@ -18,6 +18,6 @@ enum control { NONE = 0, LEFT, RIGHT, UP, DOWN, A, B, X, Y, START, TRIG_L, TRIG_ static inline int file_exists(const char* path) { - struct stat buffer; - return (stat(path, &buffer) == 0); + struct stat st; + return (fs_stat(path, &st, STAT_TYPE_NONE) == 0); } From cba58c6bf5393e982edc067311ffa4d1f00794fc Mon Sep 17 00:00:00 2001 From: Fabian Ockenfels Date: Sun, 8 Jun 2025 13:16:08 +0200 Subject: [PATCH 5/7] refactor: organize includes --- src/openmenu/src/main.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/openmenu/src/main.c b/src/openmenu/src/main.c index 8e6deb2..fa02b61 100644 --- a/src/openmenu/src/main.c +++ b/src/openmenu/src/main.c @@ -17,17 +17,18 @@ #include #include #include +#include #include #include -#include "vm2/vm2_api.h" +#include +#include #include "ui/common.h" #include "ui/dc/input.h" -#include "ui/ui_common.h" #include "ui/draw_prototypes.h" -#include -#include +#include "ui/ui_common.h" #include "ui/ui_menu_credits.h" +#include "vm2/vm2_api.h" /* UI Collection */ #include "ui/ui_grid.h" From cea4e841567ae7238b377e0e0ae3ae03294b6d8b Mon Sep 17 00:00:00 2001 From: Fabian Ockenfels Date: Sun, 8 Jun 2025 13:17:21 +0200 Subject: [PATCH 6/7] refactor: streamline `send_allinfo` in vm2_api --- src/openmenu/src/vm2/vm2_api.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/openmenu/src/vm2/vm2_api.c b/src/openmenu/src/vm2/vm2_api.c index 36538fd..a9d9154 100644 --- a/src/openmenu/src/vm2/vm2_api.c +++ b/src/openmenu/src/vm2/vm2_api.c @@ -27,11 +27,7 @@ vbl_allinfo_callback(struct maple_state_str*, maple_frame_t* frm) { /* Send a ALLINFO command for the given port/unit */ static int -send_allinfo(int p, int u) { - maple_device_t* dev; - - dev = &maple_state.ports[p].units[u]; - +send_allinfo(maple_device_t* dev) { // Reserve access; if we don't get it, forget about it if (maple_frame_lock(&dev->frame) < 0) { return -1; @@ -40,8 +36,8 @@ send_allinfo(int p, int u) { // Setup our autodetect frame to probe at a new device maple_frame_init(&dev->frame); dev->frame.cmd = MAPLE_COMMAND_ALLINFO; - dev->frame.dst_port = p; - dev->frame.dst_unit = u; + dev->frame.dst_port = dev->port; + dev->frame.dst_unit = dev->unit; dev->frame.callback = vbl_allinfo_callback; maple_queue_frame(&dev->frame); @@ -127,7 +123,7 @@ check_vm2_present(maple_device_t* dev) { /* Clear the old buffer */ memset(recv_buff, 0, 196); - if (send_allinfo(dev->port, dev->unit) != MAPLE_EOK) { + if (send_allinfo(dev) != MAPLE_EOK) { return 0; } From 97bff9613fbebdcc2c32a8df6ecc77244f077ed0 Mon Sep 17 00:00:00 2001 From: Fabian Ockenfels Date: Sun, 8 Jun 2025 13:19:10 +0200 Subject: [PATCH 7/7] feat: add support for launching PS1 applications via Bloom --- src/openmenu/src/backend/gdemu_control.c | 33 +++++++++++++++++++++++- src/openmenu/src/ui/draw_prototypes.h | 1 + src/openmenu/src/ui/ui_grid.c | 6 +++-- src/openmenu/src/ui/ui_line_desc.c | 6 +++-- src/openmenu/src/ui/ui_scroll.c | 6 +++-- 5 files changed, 45 insertions(+), 7 deletions(-) diff --git a/src/openmenu/src/backend/gdemu_control.c b/src/openmenu/src/backend/gdemu_control.c index 6a75c76..415c038 100644 --- a/src/openmenu/src/backend/gdemu_control.c +++ b/src/openmenu/src/backend/gdemu_control.c @@ -9,6 +9,7 @@ #include "backend/gdemu_sdk.h" #include "backend/gdmenu_binary.h" #include "vm2/vm2_api.h" + extern maple_device_t* vm2_dev; static void @@ -19,7 +20,37 @@ wait_cd_ready(void) { } thd_sleep(20); } - return; +} + +void +bloom_launch(gd_item* disc) { + file_t fd; + uint32_t bloom_size; + uint8_t* bloom_buf; + + fd = fs_open("/cd/BLOOM.BIN", O_RDONLY); + + if (fd == -1) { + printf("Can't open %s\n", "/cd/BLOOM.BIN"); + return; + } + + fs_seek(fd, 0, SEEK_END); + bloom_size = fs_tell(fd); + fs_seek(fd, 0, SEEK_SET); + bloom_buf = (uint8_t*)malloc(bloom_size + 32); + bloom_buf = (uint8_t*)(((uint32_t)bloom_buf & 0xffffffe0) + 0x20); + fs_read(fd, bloom_buf, bloom_size); + fs_close(fd); + + gdemu_set_img_num((uint16_t)disc->slot_num); + + wait_cd_ready(); + + /* Patch */ + ((uint16_t*)0xAC000198)[0] = 0xFF86; + + arch_exec(bloom_buf, bloom_size); } void diff --git a/src/openmenu/src/ui/draw_prototypes.h b/src/openmenu/src/ui/draw_prototypes.h index 3255244..b72e608 100644 --- a/src/openmenu/src/ui/draw_prototypes.h +++ b/src/openmenu/src/ui/draw_prototypes.h @@ -60,6 +60,7 @@ void draw_draw_quad(int x, int y, float width, float height, uint32_t color); /* exec proto */ struct gd_item; +void bloom_launch(const struct gd_item* disc); void bleem_launch(const struct gd_item* disc); void dreamcast_launch_disc(const struct gd_item* disc); void dreamcast_launch_cb(const struct gd_item* disc); diff --git a/src/openmenu/src/ui/ui_grid.c b/src/openmenu/src/ui/ui_grid.c index e99e53d..382a6e2 100644 --- a/src/openmenu/src/ui/ui_grid.c +++ b/src/openmenu/src/ui/ui_grid.c @@ -463,8 +463,10 @@ menu_cb(void) { return; } - if (!strncmp(list_current[current_selected()]->disc, "PS1", 3) - || !strncmp(list_current[current_selected()]->disc, "DIR", 3)) { + if (!strncmp(list_current[current_selected()]->disc, "DIR", 3)) { + return; + } else if (!strncmp(list_current[current_selected()]->disc, "PS1", 3)) { + bloom_launch(list_current[current_selected()]); return; } diff --git a/src/openmenu/src/ui/ui_line_desc.c b/src/openmenu/src/ui/ui_line_desc.c index 0107ba1..644c6ae 100644 --- a/src/openmenu/src/ui/ui_line_desc.c +++ b/src/openmenu/src/ui/ui_line_desc.c @@ -411,8 +411,10 @@ menu_cb(void) { return; } - if (!strncmp(list_current[current_selected_item]->disc, "PS1", 3) - || !strncmp(list_current[current_selected_item]->disc, "DIR", 3)) { + if (!strncmp(list_current[current_selected_item]->disc, "DIR", 3)) { + return; + } else if (!strncmp(list_current[current_selected_item]->disc, "PS1", 3)) { + bloom_launch(list_current[current_selected_item]); return; } diff --git a/src/openmenu/src/ui/ui_scroll.c b/src/openmenu/src/ui/ui_scroll.c index b3c845b..357e0ae 100644 --- a/src/openmenu/src/ui/ui_scroll.c +++ b/src/openmenu/src/ui/ui_scroll.c @@ -357,8 +357,10 @@ menu_cb(void) { return; } - if (!strncmp(list_current[current_selected_item]->disc, "PS1", 3) - || !strncmp(list_current[current_selected_item]->disc, "DIR", 3)) { + if (!strncmp(list_current[current_selected_item]->disc, "DIR", 3)) { + return; + } else if (!strncmp(list_current[current_selected_item]->disc, "PS1", 3)) { + bloom_launch(list_current[current_selected_item]); return; }