Skip to content

Commit

Permalink
libdragon update + reorganized menu init + bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Polprzewodnikowy committed Sep 16, 2024
1 parent 2116f6e commit 10a8fca
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 78 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ $(SPNG_OBJS): N64_CFLAGS+=-isystem $(SOURCE_DIR)/libs/miniz -DSPNG_USE_MINIZ -fc
$(FILESYSTEM_DIR)/FiraMonoBold.font64: MKFONT_FLAGS+=-c 1 --size 16 -r 20-7F -r 80-1FF -r 2026-2026 --ellipsis 2026,1
$(FILESYSTEM_DIR)/%.wav64: AUDIOCONV_FLAGS=--wav-compress 1


$(@info $(shell mkdir -p ./$(FILESYSTEM_DIR) &> /dev/null))

$(FILESYSTEM_DIR)/%.font64: $(ASSETS_DIR)/%.ttf
Expand Down
2 changes: 1 addition & 1 deletion libdragon
Submodule libdragon updated 57 files
+4 −2 Makefile
+1 −1 examples/Makefile
+50 −34 examples/fontgallery/fontgallery.c
+1 −0 examples/loadspritefromsd/.gitignore
+20 −10 examples/loadspritefromsd/Makefile
+ examples/loadspritefromsd/assets/attack1.png
+ examples/loadspritefromsd/assets/attack2.png
+ examples/loadspritefromsd/assets/attack3.png
+ examples/loadspritefromsd/assets/attack4.png
+ examples/loadspritefromsd/filesystem/earthbound.sprite
+ examples/loadspritefromsd/filesystem/mudkip.sprite
+ examples/loadspritefromsd/filesystem/plane.sprite
+14 −42 examples/loadspritefromsd/loadspritefromsd.c
+1 −0 examples/spriteanim/.gitignore
+31 −0 examples/spriteanim/Makefile
+ examples/spriteanim/assets/knight.png
+105 −0 examples/spriteanim/spriteanim.c
+0 −19 examples/spritemap/Makefile
+ examples/spritemap/filesystem/earthbound.sprite
+ examples/spritemap/filesystem/mudkip.sprite
+ examples/spritemap/filesystem/plane.sprite
+0 −139 examples/spritemap/spritemap.c
+1 −1 examples/videoplayer/Makefile
+87 −55 examples/videoplayer/videoplayer.c
+5 −6 include/audio.h
+131 −4,108 include/font.h
+88 −0 include/ksemaphore.h
+3 −0 include/libdragon.h
+1 −1 include/mi.h
+5 −12 include/mpeg2.h
+41 −0 include/pifile.h
+1 −0 include/rdpq_font.h
+26 −11 include/rdpq_rect.h
+3 −2 include/rdpq_tex.h
+12 −10 include/yuv.h
+1 −0 src/GL/query.c
+112 −39 src/graphics.c
+4 −4 src/inspector.c
+16 −62 src/inthandler.S
+16 −0 src/kernel/kernel.c
+56 −0 src/kernel/ksemaphore.c
+6 −0 src/kernel/libdragon.mk
+141 −0 src/pifile.c
+103 −26 src/rdpq/rdpq_font.c
+536 −748 src/rdpq/rdpq_font_builtin.c
+11 −7 src/rdpq/rdpq_font_internal.h
+14 −3 src/rdpq/rdpq_paragraph.c
+1 −0 src/regs.S
+4 −0 src/system.c
+121 −0 src/system_newlib_locks.c
+30 −43 src/video/mpeg2.c
+9 −9 src/video/yuv.c
+6 −6 tools/build-toolchain.sh
+367 −15 tools/mkfont/mkfont.cpp
+5 −1 tools/mkfont/mkfont_bmfont.cpp
+270 −216 tools/mkfont/mkfont_out.cpp
+10 −2 tools/mkfont/mkfont_ttf.cpp
7 changes: 6 additions & 1 deletion src/menu/actions.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ static void actions_update_direction (menu_t *menu) {
}
}


if (fast_dir != JOYPAD_8WAY_NONE) {
held_dir = fast_dir;
menu->actions.go_fast = true;
Expand Down Expand Up @@ -114,6 +113,12 @@ static void actions_update_buttons (menu_t *menu) {
}


void actions_init (void) {
JOYPAD_PORT_FOREACH (port) {
joypad_set_rumble_active(port, false);
}
}

void actions_update (menu_t *menu) {
joypad_poll();

Expand Down
1 change: 1 addition & 0 deletions src/menu/actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "menu_state.h"


void actions_init (void);
void actions_update (menu_t *menu);


Expand Down
13 changes: 4 additions & 9 deletions src/menu/components/background.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,20 @@ static void prepare_background (component_background_t *c) {
return;
}

uint16_t image_center_x = (c->image->width / 2);
uint16_t image_center_y = (c->image->height / 2);

// Darken the image
rdpq_attach(c->image, NULL);
rdpq_mode_push();
rdpq_set_mode_standard();
rdpq_set_prim_color(BACKGROUND_OVERLAY_COLOR);
rdpq_mode_combiner(RDPQ_COMBINER_FLAT);
rdpq_mode_blender(RDPQ_BLENDER_MULTIPLY);
rdpq_fill_rectangle(
0 - (DISPLAY_CENTER_X - image_center_x),
0 - (DISPLAY_CENTER_Y - image_center_y),
DISPLAY_WIDTH - (DISPLAY_CENTER_X - image_center_x),
DISPLAY_HEIGHT - (DISPLAY_CENTER_Y - image_center_y)
);
rdpq_fill_rectangle(0, 0, c->image->width, c->image->height);
rdpq_mode_pop();
rdpq_detach();

uint16_t image_center_x = (c->image->width / 2);
uint16_t image_center_y = (c->image->height / 2);

// Prepare display list
rspq_block_begin();
rdpq_mode_push();
Expand Down
96 changes: 30 additions & 66 deletions src/menu/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,60 +27,39 @@
#define MENU_CACHE_DIRECTORY "cache"
#define BACKGROUND_CACHE_FILE "background.data"

#define FRAMERATE_DIVIDER (2)
#define LAG_REPORT (false)
#define INTERLACED (true)
#define FPS_LIMIT (30.0f)


static menu_t *menu;
static tv_type_t tv_type;
static volatile int frame_counter = 0;

extern tv_type_t __boot_tvtype;

static void menu_init (boot_params_t *boot_params) {
menu = calloc(1, sizeof(menu_t));
assert(menu != NULL);

static void frame_counter_handler (void) {
frame_counter += 1;
}
menu->boot_params = boot_params;

menu->mode = MENU_MODE_NONE;
menu->next_mode = MENU_MODE_STARTUP;

static void frame_counter_reset (void) {
#if LAG_REPORT
static int accumulated = 0;
if (frame_counter > FRAMERATE_DIVIDER) {
accumulated += frame_counter - FRAMERATE_DIVIDER;
debugf(
"LAG: %d additional frame(s) displayed since last draw (accumulated: %d)\n",
frame_counter - FRAMERATE_DIVIDER,
accumulated
);
menu->flashcart_err = flashcart_init(&menu->storage_prefix);
if (menu->flashcart_err != FLASHCART_OK) {
menu->next_mode = MENU_MODE_FAULT;
}
#endif
frame_counter = 0;
}

static void menu_init (boot_params_t *boot_params) {
joypad_init();
timer_init();
rtc_init();
rspq_init();
rdpq_init();
dfs_init(DFS_DEFAULT_LOCATION);

actions_init();
sound_init_default();
sound_init_sfx();

JOYPAD_PORT_FOREACH (port) {
joypad_set_rumble_active(port, false);
}

menu = calloc(1, sizeof(menu_t));
assert(menu != NULL);

menu->mode = MENU_MODE_NONE;
menu->next_mode = MENU_MODE_STARTUP;

menu->flashcart_err = flashcart_init(&menu->storage_prefix);
if (menu->flashcart_err != FLASHCART_OK) {
menu->next_mode = MENU_MODE_FAULT;
}
hdmi_clear_game_id();

path_t *path = path_init(menu->storage_prefix, MENU_DIRECTORY);

Expand All @@ -91,6 +70,15 @@ static void menu_init (boot_params_t *boot_params) {
settings_load(&menu->settings);
path_pop(path);

resolution_t resolution = {
.width = 640,
.height = 480,
.interlaced = INTERLACED ? INTERLACE_HALF : INTERLACE_OFF,
.pal60 = menu->settings.pal60_enabled,
};
display_init(resolution, DEPTH_16_BPP, 2, GAMMA_NONE, INTERLACED ? FILTERS_DISABLED : FILTERS_RESAMPLE);
display_set_fps_limit(FPS_LIMIT);

path_push(path, MENU_CUSTOM_FONT_FILE);
fonts_init(path_get(path));
path_pop(path);
Expand All @@ -103,40 +91,20 @@ static void menu_init (boot_params_t *boot_params) {

path_free(path);

menu->boot_params = boot_params;
sound_use_sfx(menu->settings.sound_enabled);

menu->browser.directory = path_init(menu->storage_prefix, menu->settings.default_directory);
if (!directory_exists(path_get(menu->browser.directory))) {
path_free(menu->browser.directory);
menu->browser.directory = path_init(menu->storage_prefix, "/");
}

hdmi_clear_game_id();

tv_type = get_tv_type();
if ((tv_type == TV_PAL) && menu->settings.pal60_enabled) {
// HACK: Set TV type to NTSC, so PAL console would output 60 Hz signal instead.
__boot_tvtype = TV_NTSC;
}

sound_init_sfx();
if (menu->settings.sound_enabled) {
sound_use_sfx(true);
}

display_init(RESOLUTION_640x480, DEPTH_16_BPP, 2, GAMMA_NONE, FILTERS_DISABLED);

register_VI_handler(frame_counter_handler);
}

static void menu_deinit (menu_t *menu) {
unregister_VI_handler(frame_counter_handler);

// NOTE: Restore previous TV type so boot procedure wouldn't passthrough wrong value.
__boot_tvtype = tv_type;

hdmi_send_game_id(menu->boot_params);

component_background_free();

path_free(menu->load.disk_path);
path_free(menu->load.rom_path);
for (int i = 0; i < menu->browser.entries; i++) {
Expand All @@ -146,9 +114,7 @@ static void menu_deinit (menu_t *menu) {
path_free(menu->browser.directory);
free(menu);

component_background_free();

flashcart_deinit();
display_close();

sound_deinit();

Expand All @@ -158,7 +124,7 @@ static void menu_deinit (menu_t *menu) {
timer_close();
joypad_close();

display_close();
flashcart_deinit();
}

typedef const struct {
Expand Down Expand Up @@ -200,11 +166,9 @@ void menu_run (boot_params_t *boot_params) {
menu_init(boot_params);

while (true) {
surface_t *display = (frame_counter >= FRAMERATE_DIVIDER) ? display_try_get() : NULL;
surface_t *display = display_try_get();

if (display != NULL) {
frame_counter_reset();

actions_update(menu);

view_t *view = menu_get_view(menu->mode);
Expand Down

0 comments on commit 10a8fca

Please sign in to comment.