diff --git a/.gitignore b/.gitignore index 9b9f4205..dcc08de7 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ # Ignore generated files in the libdragon FS /filesystem/FiraMonoBold.font64 /filesystem/*.wav64 +/filesystem/*.sprite # Ignore external development tools /tools/* diff --git a/Makefile b/Makefile index 2265c991..d2d8ae95 100644 --- a/Makefile +++ b/Makefile @@ -29,6 +29,7 @@ SRCS = \ flashcart/64drive/64drive_ll.c \ flashcart/64drive/64drive.c \ flashcart/flashcart_utils.c \ + flashcart/ed64/ed64_vseries.c \ flashcart/flashcart.c \ flashcart/sc64/sc64_ll.c \ flashcart/sc64/sc64.c \ @@ -86,6 +87,30 @@ SOUNDS = \ error.wav \ settings.wav +JOYPAD_IMAGES = \ + joypad_a.png \ + joypad_b.png \ + joypad_c_down.png \ + joypad_c_left.png \ + joypad_c_right.png \ + joypad_c_up.png \ + joypad_d_down.png \ + joypad_d_left.png \ + joypad_d_right.png \ + joypad_d_up.png \ + joypad_l.png \ + joypad_r.png \ + joypad_start.png \ + joypad_z.png +# joypad_j_east.png \ +# joypad_j_north.png \ +# joypad_j_northeast.png \ +# joypad_j_northwest.png \ +# joypad_j_south.png \ +# joypad_j_southeast.png \ +# joypad_j_southwest.png \ +# joypad_j_west.png \ + OBJS = $(addprefix $(BUILD_DIR)/, $(addsuffix .o,$(basename $(SRCS)))) MINIZ_OBJS = $(filter $(BUILD_DIR)/libs/miniz/%.o,$(OBJS)) SPNG_OBJS = $(filter $(BUILD_DIR)/libs/libspng/%.o,$(OBJS)) @@ -93,7 +118,8 @@ DEPS = $(OBJS:.o=.d) FILESYSTEM = \ $(addprefix $(FILESYSTEM_DIR)/, $(notdir $(FONTS:%.ttf=%.font64))) \ - $(addprefix $(FILESYSTEM_DIR)/, $(notdir $(SOUNDS:%.wav=%.wav64))) + $(addprefix $(FILESYSTEM_DIR)/, $(notdir $(SOUNDS:%.wav=%.wav64))) \ + $(addprefix $(FILESYSTEM_DIR)/, $(notdir $(JOYPAD_IMAGES:%.png=%.sprite))) $(MINIZ_OBJS): N64_CFLAGS+=-DMINIZ_NO_TIME -fcompare-debug-second $(SPNG_OBJS): N64_CFLAGS+=-isystem $(SOURCE_DIR)/libs/miniz -DSPNG_USE_MINIZ -fcompare-debug-second @@ -102,14 +128,18 @@ $(FILESYSTEM_DIR)/%.wav64: AUDIOCONV_FLAGS=--wav-compress 1 $(@info $(shell mkdir -p ./$(FILESYSTEM_DIR) &> /dev/null)) -$(FILESYSTEM_DIR)/%.font64: $(ASSETS_DIR)/%.ttf +$(FILESYSTEM_DIR)/%.font64: $(ASSETS_DIR)/fonts/%.ttf @echo " [FONT] $@" @$(N64_MKFONT) $(MKFONT_FLAGS) -o $(FILESYSTEM_DIR) "$<" -$(FILESYSTEM_DIR)/%.wav64: $(ASSETS_DIR)/%.wav +$(FILESYSTEM_DIR)/%.wav64: $(ASSETS_DIR)/sounds/%.wav @echo " [AUDIO] $@" @$(N64_AUDIOCONV) $(AUDIOCONV_FLAGS) -o $(FILESYSTEM_DIR) "$<" +$(FILESYSTEM_DIR)/%.sprite: $(ASSETS_DIR)/images/joypad/%.png + @echo " [SPRITE] $@" + @$(N64_MKSPRITE) $(MKSPRITE_FLAGS) -o $(dir $@) "$<" + $(BUILD_DIR)/$(PROJECT_NAME).dfs: $(FILESYSTEM) $(BUILD_DIR)/menu/views/credits.o: .FORCE diff --git a/README.md b/README.md index c44efae5..974577ba 100644 --- a/README.md +++ b/README.md @@ -114,10 +114,20 @@ If required, you can manually adjust the file on the SD card using your computer * Download the latest `menu.bin` file from the [releases](https://github.com/Polprzewodnikowy/N64FlashcartMenu/releases/) page, then put it in the root directory of your SD card. -### ED64 & ED64P +### ED64 - WIP - UNTESTED AND UNSUPPORTED - USE AT OWN RISK Currently not supported, but work is in progress (See [PR's](https://github.com/Polprzewodnikowy/N64FlashcartMenu/pulls)). +NOTE: The menu may be able to load ROM's but not perform saves and may break existing ones.. -The aim is to replace [Altra64](https://github.com/networkfusion/altra64) and [ED64-UnofficialOS](https://github.com/n64-tools/ED64-UnofficialOS-binaries). +#### ED64 (Vseries) +The aim is to reach feature parity with [ED64-UnofficialOS](https://github.com/n64-tools/ED64-UnofficialOS-binaries) / [ED64-OfficialOS](https://krikzz.com/pub/support/everdrive-64/v2x-v3x/os-bin/). +Download the `OS64.v64` ROM from the latest [action run - assets] and place it in the `/ED64` folder. + +#### ED64 (X series) +X Series support is currently awaiting fixes, in the meantime use the official [OS](https://krikzz.com/pub/support/everdrive-64/x-series/OS/) instead. + +#### ED64 (P clone) +Download the `OS64P.v64` ROM from the latest [action run - assets] and place it in the `/ED64P` folder. +The aim is to reach feature parity with [Altra64](https://github.com/networkfusion/altra64) # Open source software and licenses used diff --git a/assets/FiraMonoBold.ttf b/assets/fonts/FiraMonoBold.ttf similarity index 100% rename from assets/FiraMonoBold.ttf rename to assets/fonts/FiraMonoBold.ttf diff --git a/assets/images/joypad/joypad_a.png b/assets/images/joypad/joypad_a.png new file mode 100644 index 00000000..9e6e6493 Binary files /dev/null and b/assets/images/joypad/joypad_a.png differ diff --git a/assets/images/joypad/joypad_b.png b/assets/images/joypad/joypad_b.png new file mode 100644 index 00000000..e5874cff Binary files /dev/null and b/assets/images/joypad/joypad_b.png differ diff --git a/assets/images/joypad/joypad_c_down.png b/assets/images/joypad/joypad_c_down.png new file mode 100644 index 00000000..773e1391 Binary files /dev/null and b/assets/images/joypad/joypad_c_down.png differ diff --git a/assets/images/joypad/joypad_c_left.png b/assets/images/joypad/joypad_c_left.png new file mode 100644 index 00000000..2896b627 Binary files /dev/null and b/assets/images/joypad/joypad_c_left.png differ diff --git a/assets/images/joypad/joypad_c_right.png b/assets/images/joypad/joypad_c_right.png new file mode 100644 index 00000000..7eca4a87 Binary files /dev/null and b/assets/images/joypad/joypad_c_right.png differ diff --git a/assets/images/joypad/joypad_c_up.png b/assets/images/joypad/joypad_c_up.png new file mode 100644 index 00000000..487eee68 Binary files /dev/null and b/assets/images/joypad/joypad_c_up.png differ diff --git a/assets/images/joypad/joypad_d_down.png b/assets/images/joypad/joypad_d_down.png new file mode 100644 index 00000000..4223ec3b Binary files /dev/null and b/assets/images/joypad/joypad_d_down.png differ diff --git a/assets/images/joypad/joypad_d_left.png b/assets/images/joypad/joypad_d_left.png new file mode 100644 index 00000000..fb467603 Binary files /dev/null and b/assets/images/joypad/joypad_d_left.png differ diff --git a/assets/images/joypad/joypad_d_right.png b/assets/images/joypad/joypad_d_right.png new file mode 100644 index 00000000..d9f3fd93 Binary files /dev/null and b/assets/images/joypad/joypad_d_right.png differ diff --git a/assets/images/joypad/joypad_d_up.png b/assets/images/joypad/joypad_d_up.png new file mode 100644 index 00000000..9689c3df Binary files /dev/null and b/assets/images/joypad/joypad_d_up.png differ diff --git a/assets/images/joypad/joypad_l.png b/assets/images/joypad/joypad_l.png new file mode 100644 index 00000000..e4d4e01d Binary files /dev/null and b/assets/images/joypad/joypad_l.png differ diff --git a/assets/images/joypad/joypad_r.png b/assets/images/joypad/joypad_r.png new file mode 100644 index 00000000..5d0ecb0a Binary files /dev/null and b/assets/images/joypad/joypad_r.png differ diff --git a/assets/images/joypad/joypad_start.png b/assets/images/joypad/joypad_start.png new file mode 100644 index 00000000..99c1ebb5 Binary files /dev/null and b/assets/images/joypad/joypad_start.png differ diff --git a/assets/images/joypad/joypad_z.png b/assets/images/joypad/joypad_z.png new file mode 100644 index 00000000..f3cb289e Binary files /dev/null and b/assets/images/joypad/joypad_z.png differ diff --git a/assets/back.wav b/assets/sounds/back.wav similarity index 100% rename from assets/back.wav rename to assets/sounds/back.wav diff --git a/assets/cursorsound.wav b/assets/sounds/cursorsound.wav similarity index 100% rename from assets/cursorsound.wav rename to assets/sounds/cursorsound.wav diff --git a/assets/enter.wav b/assets/sounds/enter.wav similarity index 100% rename from assets/enter.wav rename to assets/sounds/enter.wav diff --git a/assets/error.wav b/assets/sounds/error.wav similarity index 100% rename from assets/error.wav rename to assets/sounds/error.wav diff --git a/assets/settings.wav b/assets/sounds/settings.wav similarity index 100% rename from assets/settings.wav rename to assets/sounds/settings.wav diff --git a/libdragon b/libdragon index 52950162..0c4e3888 160000 --- a/libdragon +++ b/libdragon @@ -1 +1 @@ -Subproject commit 5295016230d657cd6c7fce5b6ed4a342538e09f5 +Subproject commit 0c4e388851cabab52f421bff5e75e9dc3ab36c72 diff --git a/src/flashcart/ed64/ed64_vseries.c b/src/flashcart/ed64/ed64_vseries.c new file mode 100644 index 00000000..22b6596d --- /dev/null +++ b/src/flashcart/ed64/ed64_vseries.c @@ -0,0 +1,155 @@ +#include +#include +#include + +#include +#include + +#include "utils/fs.h" +#include "utils/utils.h" + +#include "../flashcart_utils.h" +#include "ed64_vseries.h" + +typedef enum { + ED64_V1_0 = 110, + ED64_V2_0 = 320, + ED64_V2_5 = 325, + ED64_V3_0 = 330, +} ed64_vseries_device_variant_t; + +/* ED64 save location base address */ +#define SRAM_ADDRESS (0xA8000000) +/* ED64 ROM location base address */ +#define ROM_ADDRESS (0xB0000000) + +static flashcart_err_t ed64_vseries_init (void) { + return FLASHCART_OK; +} + +static flashcart_err_t ed64_vseries_deinit (void) { + return FLASHCART_OK; +} + +static ed64_vseries_device_variant_t get_cart_model() { + ed64_vseries_device_variant_t variant = ED64_V1_0; // FIXME: check cart model from ll for better feature handling. + return variant; +} + +static bool ed64_vseries_has_feature (flashcart_features_t feature) { + bool is_model_v3 = (get_cart_model() == ED64_V3_0); + switch (feature) { + case FLASHCART_FEATURE_RTC: return is_model_v3 ? true : false; + case FLASHCART_FEATURE_USB: return is_model_v3 ? true : false; + case FLASHCART_FEATURE_AUTO_CIC: return is_model_v3 ? true : false; + default: return false; + } +} + +static flashcart_err_t ed64_vseries_load_rom (char *rom_path, flashcart_progress_callback_t *progress) { + FIL fil; + UINT br; + + if (f_open(&fil, strip_fs_prefix(rom_path), FA_READ) != FR_OK) { + return FLASHCART_ERR_LOAD; + } + + fatfs_fix_file_size(&fil); + + size_t rom_size = f_size(&fil); + + if (rom_size > MiB(64)) { + f_close(&fil); + return FLASHCART_ERR_LOAD; + } + + size_t sdram_size = MiB(64); + + size_t chunk_size = KiB(128); + for (int offset = 0; offset < sdram_size; offset += chunk_size) { + size_t block_size = MIN(sdram_size - offset, chunk_size); + if (f_read(&fil, (void *) (ROM_ADDRESS + offset), block_size, &br) != FR_OK) { + f_close(&fil); + return FLASHCART_ERR_LOAD; + } + if (progress) { + progress(f_tell(&fil) / (float) (f_size(&fil))); + } + } + if (f_tell(&fil) != rom_size) { + f_close(&fil); + return FLASHCART_ERR_LOAD; + } + + if (f_close(&fil) != FR_OK) { + return FLASHCART_ERR_LOAD; + } + + return FLASHCART_OK; +} + +static flashcart_err_t ed64_vseries_load_file (char *file_path, uint32_t rom_offset, uint32_t file_offset) { + FIL fil; + UINT br; + + if (f_open(&fil, strip_fs_prefix(file_path), FA_READ) != FR_OK) { + return FLASHCART_ERR_LOAD; + } + + fatfs_fix_file_size(&fil); + + size_t file_size = f_size(&fil) - file_offset; + + if (file_size > (MiB(64) - rom_offset)) { + f_close(&fil); + return FLASHCART_ERR_ARGS; + } + + if (f_lseek(&fil, file_offset) != FR_OK) { + f_close(&fil); + return FLASHCART_ERR_LOAD; + } + + if (f_read(&fil, (void *) (ROM_ADDRESS + rom_offset), file_size, &br) != FR_OK) { + f_close(&fil); + return FLASHCART_ERR_LOAD; + } + if (br != file_size) { + f_close(&fil); + return FLASHCART_ERR_LOAD; + } + + if (f_close(&fil) != FR_OK) { + return FLASHCART_ERR_LOAD; + } + + return FLASHCART_OK; +} + +static flashcart_err_t ed64_vseries_load_save (char *save_path) { + // FIXME: the savetype will be none. + return FLASHCART_OK; +} + +static flashcart_err_t ed64_vseries_set_save_type (flashcart_save_type_t save_type) { + // FIXME: the savetype will be none. + return FLASHCART_OK; +} + +static flashcart_t flashcart_ed64_vseries = { + .init = ed64_vseries_init, + .deinit = ed64_vseries_deinit, + .has_feature = ed64_vseries_has_feature, + .load_rom = ed64_vseries_load_rom, + .load_file = ed64_vseries_load_file, + .load_save = ed64_vseries_load_save, + .load_64dd_ipl = NULL, + .load_64dd_disk = NULL, + .set_save_type = ed64_vseries_set_save_type, + .set_save_writeback = NULL, +}; + + +flashcart_t *ed64_vseries_get_flashcart (void) { + return &flashcart_ed64_vseries; +} diff --git a/src/flashcart/ed64/ed64_vseries.h b/src/flashcart/ed64/ed64_vseries.h new file mode 100644 index 00000000..c96b5a0d --- /dev/null +++ b/src/flashcart/ed64/ed64_vseries.h @@ -0,0 +1,24 @@ +/** + * @file ed64_vseries.h + * @brief ED64 Vseries flashcart support + * @ingroup flashcart + */ + +#ifndef FLASHCART_ED64_VSERIES_H__ +#define FLASHCART_ED64_VSERIES_H__ + + +#include "../flashcart.h" + + +/** + * @addtogroup ED64_Vseries + * @{ + */ + +flashcart_t *ed64_vseries_get_flashcart (void); + +/** @} */ /* ED64_Vseries */ + + +#endif diff --git a/src/flashcart/ed64/ed64_xseries.h b/src/flashcart/ed64/ed64_xseries.h new file mode 100644 index 00000000..a6bf497c --- /dev/null +++ b/src/flashcart/ed64/ed64_xseries.h @@ -0,0 +1,24 @@ +/** + * @file ed64xseries.h + * @brief ED64 Xseries flashcart support + * @ingroup flashcart + */ + +#ifndef FLASHCART_ED64XSERIES_H__ +#define FLASHCART_ED64XSERIES_H__ + + +#include "../flashcart.h" + + +/** + * @addtogroup ED64_Xseries + * @{ + */ + +flashcart_t *ed64xseries_get_flashcart (void); + +/** @} */ /* ED64_Xseries */ + + +#endif diff --git a/src/flashcart/flashcart.c b/src/flashcart/flashcart.c index 0cb55e84..942ebd50 100644 --- a/src/flashcart/flashcart.c +++ b/src/flashcart/flashcart.c @@ -10,6 +10,7 @@ #include "flashcart.h" #include "flashcart_utils.h" +#include "ed64/ed64_vseries.h" #include "64drive/64drive.h" #include "sc64/sc64.h" @@ -108,10 +109,13 @@ flashcart_err_t flashcart_init (const char **storage_prefix) { flashcart = d64_get_flashcart(); break; - case CART_EDX: // Series X EverDrive-64 - break; + // FIXME: this is commented out awaiting a fix from libcart. + // case CART_EDX: // Series X EverDrive-64 + // flashcart = ed64_xseries_get_flashcart(); + // break; - case CART_ED: // Original EverDrive-64 + case CART_ED: // Series V EverDrive-64 or clone + flashcart = ed64_vseries_get_flashcart(); break; case CART_SC: // SummerCart64 diff --git a/src/menu/views/rtc.c b/src/menu/views/rtc.c index c93d7aa2..88196d00 100644 --- a/src/menu/views/rtc.c +++ b/src/menu/views/rtc.c @@ -119,7 +119,7 @@ static void process (menu_t *menu) { sound_play_effect(SFX_EXIT); menu->next_mode = MENU_MODE_BROWSER; } - else if (menu->actions.enter && !is_editing_mode) { + else if (menu->actions.enter && !is_editing_mode && menu->current_time >= 0) { rtc_tm = *gmtime(&menu->current_time); is_editing_mode = true; } @@ -169,26 +169,49 @@ static void draw (menu_t *menu, surface_t *d) { component_layout_draw(); - component_main_text_draw( - ALIGN_CENTER, VALIGN_TOP, - "ADJUST REAL TIME CLOCK\n" - "\n" - "\n" - "To set the RTC date and time, Press A.\n" - "You can also use the PC terminal application via USB,\n" - "or even an N64 game with RTC support.\n" - "\n" - "Current date & time: %s\n" - "\n", - menu->current_time >= 0 ? ctime(&menu->current_time) : "Unknown" - ); - if (!is_editing_mode) { - component_actions_bar_text_draw( - ALIGN_LEFT, VALIGN_TOP, - "A: Change\n" - "B: Back" - ); + if( menu->current_time >= 0 ) { + + component_main_text_draw( + ALIGN_CENTER, VALIGN_TOP, + "ADJUST REAL TIME CLOCK\n" + "\n" + "\n" + "To set the RTC date and time, Press A.\n" + "You can also use the PC terminal application via USB,\n" + "or even an N64 game with RTC support.\n" + "\n" + "Current date & time: %s\n" + "\n", + menu->current_time >= 0 ? ctime(&menu->current_time) : "Unknown" + ); + + component_actions_bar_text_draw( + ALIGN_LEFT, VALIGN_TOP, + "A: Change\n" + "B: Back" + ); + } + else { + + component_main_text_draw( + ALIGN_CENTER, VALIGN_TOP, + "ADJUST REAL TIME CLOCK\n" + "\n" + "\n" + "This cart does not support a real time clock." + "\n" + "Current date & time: %s\n" + "\n", + menu->current_time >= 0 ? ctime(&menu->current_time) : "Unknown" + ); + + component_actions_bar_text_draw( + ALIGN_LEFT, VALIGN_TOP, + "\n" + "B: Back" + ); + } } else { component_actions_bar_text_draw(