diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index e5a3ad30d..55ac91455 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,6 +1,6 @@ FROM debian:bookworm-slim -ARG SC64_DEPLOYER_VERSION=v2.20.0 +ARG SC64_DEPLOYER_VERSION=v2.20.2 RUN apt-get update && \ apt-get upgrade -y && \ apt-get install build-essential doxygen git python3 wget -y && \ diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e567d6ae1..7f88be12e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -77,7 +77,8 @@ jobs: with: name: Rolling release body: Rolling release built from latest commit on `main` branch. - tag_name: rolling-release + tag_name: 'rolling_release' + make_latest: true files: | ./output/N64FlashcartMenu.n64 ./output/menu.bin @@ -90,9 +91,10 @@ jobs: uses: softprops/action-gh-release@v2 if: github.ref == 'refs/heads/develop' with: - name: 'Rolling dev release-V${{ github.run_id }}' - body: Rolling dev prerelease built from latest commit on `develop` branch. - tag_name: prerelease-dev + name: 'Rolling pre-release' + body: Experimental pre-release built from latest commit on `develop` branch. + target_commitish: develop + tag_name: 'rolling_pre-release' prerelease: true files: | ./output/N64FlashcartMenu.n64 @@ -111,7 +113,7 @@ jobs: - uses: actions/checkout@v4 - name: Run Doxygen - uses: mattnotmitt/doxygen-action@1.9.5 + uses: mattnotmitt/doxygen-action@v1 with: doxyfile-path: './Doxyfile' diff --git a/.gitignore b/.gitignore index 9b9f42053..dcc08de71 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 3b6a1f999..df9896533 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 \ @@ -40,11 +41,6 @@ SRCS = \ libs/miniz/miniz.c \ menu/actions.c \ menu/cart_load.c \ - menu/components/background.c \ - menu/components/boxart.c \ - menu/components/common.c \ - menu/components/context_menu.c \ - menu/components/file_list.c \ menu/disk_info.c \ menu/fonts.c \ menu/hdmi.c \ @@ -55,6 +51,11 @@ SRCS = \ menu/rom_info.c \ menu/settings.c \ menu/sound.c \ + menu/ui_components/background.c \ + menu/ui_components/boxart.c \ + menu/ui_components/common.c \ + menu/ui_components/context_menu.c \ + menu/ui_components/file_list.c \ menu/usb_comm.c \ menu/views/browser.c \ menu/views/credits.c \ @@ -77,24 +78,42 @@ SRCS = \ FONTS = \ FiraMonoBold.ttf +SOUNDS = \ + cursorsound.wav \ + back.wav \ + enter.wav \ + error.wav \ + settings.wav + 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)) DEPS = $(OBJS:.o=.d) FILESYSTEM = \ - $(addprefix $(FILESYSTEM_DIR)/, $(notdir $(FONTS:%.ttf=%.font64))) + $(addprefix $(FILESYSTEM_DIR)/, $(notdir $(FONTS:%.ttf=%.font64))) \ + $(addprefix $(FILESYSTEM_DIR)/, $(notdir $(SOUNDS:%.wav=%.wav64))) \ + $(addprefix $(FILESYSTEM_DIR)/, $(notdir $(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 -$(FILESYSTEM_DIR)/FiraMonoBold.font64: MKFONT_FLAGS+=-c 1 --size 16 -r 20-1FF -r 2026-2026 --ellipsis 2026,1 +$(FILESYSTEM_DIR)/FiraMonoBold.font64: MKFONT_FLAGS+=--compress 1 --outline 1 --size 16 --range 20-7F --range 80-1FF --range 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 +$(FILESYSTEM_DIR)/%.font64: $(ASSETS_DIR)/fonts/%.ttf @echo " [FONT] $@" @$(N64_MKFONT) $(MKFONT_FLAGS) -o $(FILESYSTEM_DIR) "$<" +$(FILESYSTEM_DIR)/%.wav64: $(ASSETS_DIR)/sounds/%.wav + @echo " [AUDIO] $@" + @$(N64_AUDIOCONV) $(AUDIOCONV_FLAGS) -o $(FILESYSTEM_DIR) "$<" + +$(FILESYSTEM_DIR)/%.sprite: $(ASSETS_DIR)/images/%.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 e094aeed0..72d4c468f 100644 --- a/README.md +++ b/README.md @@ -18,18 +18,21 @@ An open source menu for N64 flashcarts. * Fully Open Source. * Loads all known N64 games (including iQue and Aleck64 ROMs (even if they are byteswapped)). * Fully emulates the 64DD and loads 64DD disks (SummerCart64 only). -* Emulator support (NES, SNES, GB, GBC) ROMs. +* Emulator support (NES, SNES, GB, GBC, SMS, GG, CHF) ROMs. * N64 ROM box image support. * Background image (PNG) support. * Comprehensive ROM save database (including HomeBrew headers). * Comprehensive ROM information display. * Real Time Clock support. * Music playback (MP3). +* Menu sound effects. +* N64 ROM autoload. ## Documentation * [Getting started guide](./docs/00_getting_started_sd.md) * [Menu controls](./docs/01_menu_controls.md) +* [Menu customization](./docs/07_menu_customization.md) * [Developer guide](./docs/99_developer_guide.md) ## Video showcase (as of Oct 12 2023) @@ -48,12 +51,60 @@ An open source menu for N64 flashcarts. ## Experimental features These features are subject to change: -### ROM Boxart -To use boxart, you need to place png files of size 158x112 in the folder `/menu/boxart` on the SD card. -Each file must be named according to the 2 letter ROM ID, or 3 letter ROM ID including media type. -i.e. for GoldenEye 2 letters, this would be `GE.png`. -i.e. for GoldenEye 3 letters, this would be `NGE.png`. -A known set of PNG files using 2 letter ID's can be downloaded [here](https://mega.nz/file/6cNGwSqI#8X5ukb65n3YMlGaUtSOGXkKo9HxVnnMOgqn94Epcr7w). +### N64 ROM autoload +To use the autoload function, while on the `N64 ROM information` display, press the `R` button on your joypad and select the `Set ROM to autoload` option. When you restart the console, it will now only load the selected ROM rather than the menu. +The autoload setting is stored in `config.ini` and persists until changed. This feature may slightly increase boot time as the menu needs to check for the Start button state. +NOTE: To return to the menu, hold the joypad `Start` button while powering on the console. + +### GamePak sprites +To use N64 GamePak sprites, place PNG files within the `sd:/menu/boxart/` folder. + +#### Supported sprites +These must be `PNG` files that use the following dimensions: +* Standard N64 GamePak boxart sprites: 158x112 +* Japanese N64 GamePak boxart sprites: 112x158 +* 64DD boxart sprites: 129x112 + +Supported PNG formats: +* RGB/RGBA color formats +* 8-bit color depth + +They will be loaded by directories using each character (case-sensitive) of the full 4 character Game Code (as identified in the menu ROM information). +i.e. for GoldenEye NTSC USA (NGEE), this would be `sd:/menu/boxart/N/G/E/E/boxart_front.png`. +i.e. for GoldenEye PAL (NGEP), this would be `sd:/menu/boxart/N/G/E/P/boxart_front.png`. + +To improve compatibility between regions (as a fallback), you may exclude the region ID (last matched directory) for GamePaks to match with 3 letter IDs instead: +i.e. for GoldenEye, this would be `sd:/menu/boxart/N/G/E/boxart_front.png`. + +**Warning**: Excluding the region ID may show the wrong boxart. +**Note**: For future support, boxart sprites should also include: +* `boxart_back.png` +* `boxart_top.png` +* `boxart_bottom.png` +* `boxart_left.png` +* `boxart_right.png` + +As a starting point, here is a link to a boxart pack following the new structure, including `boxart_front.png` and failback images: +* [Link](https://drive.google.com/file/d/1IpCmFqmGgGwKKmlRBxYObfFR9XywaC6n/view?usp=drive_link) + + +#### Compatibilty mode +If you cannot yet satisfy the correct boxart layout, The menu still has **deprecated** support for filenames containing the Game ID. + +**Note:** This will add a noticeable delay for displaying parts of the menu. + +Each file must be named according to the 2,3 or 4 letter GamePak ID (matched in this order). +i.e. +* for GoldenEye 4 letters, this would be `sd:/menu/boxart/NGEE.png` and/or `sd:/menu/boxart/NGEP.png`. +* for GoldenEye 3 letters, this would be `sd:/menu/boxart/NGE.png`. +* for GoldenEye 2 letters, this would be `sd:/menu/boxart/GE.png`. + + +As a starting point, here are some links to boxart packs: +* [Japan Boxart](https://mega.nz/file/KyJR0B6B#ERabLautAVPaqJTIdBSv4ghbudNhK7hnEr2ZS1Q6ub0) +* [American Boxart](https://mega.nz/file/rugAFYSQ#JHfgCU2amzNVpC4S6enP3vg--wtAAwsziKa7cej6QCc) +* [European Boxart](https://mega.nz/file/OmIV3aAK#kOWdutK1_41ffN64R6thbU7HEPR_M9qO0YM2mNG6RbQ) +* [64DD Boxart](https://mega.nz/file/ay5wQIxJ#k3PF-VMLrZJxJTr-BOaOKa2TBIK7c2t4zwbdshsQl40) ### Menu Settings @@ -73,15 +124,32 @@ 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)). +**Warning**: The menu may be able to load ROMs but cannot guarantee save functionality. Existing saves may be corrupted. -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. Please use the official [OS](https://krikzz.com/pub/support/everdrive-64/x-series/OS/) for now. + +#### 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 + * [libdragon](https://github.com/DragonMinded/libdragon) (UNLICENSE License) * [libspng](https://github.com/randy408/libspng) (BSD 2-Clause License) * [mini.c](https://github.com/univrsal/mini.c) (BSD 2-Clause License) * [minimp3](https://github.com/lieff/minimp3) (CC0 1.0 Universal) * [miniz](https://github.com/richgel999/miniz) (MIT License) + +## Sounds +See [License](https://pixabay.com/en/service/license-summary/) for the following sounds: +* [Cursor sound](https://pixabay.com/en/sound-effects/click-buttons-ui-menu-sounds-effects-button-7-203601/) by Skyscraper_seven (Free to use) +* [Actions (Enter, back) sound](https://pixabay.com/en/sound-effects/menu-button-user-interface-pack-190041/) by Liecio (Free to use) +* [Error sound](https://pixabay.com/en/sound-effects/error-call-to-attention-129258/) by Universfield (Free to use) 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/sounds/back.wav b/assets/sounds/back.wav new file mode 100644 index 000000000..f8d4655e8 Binary files /dev/null and b/assets/sounds/back.wav differ diff --git a/assets/sounds/cursorsound.wav b/assets/sounds/cursorsound.wav new file mode 100644 index 000000000..e6b2a624f Binary files /dev/null and b/assets/sounds/cursorsound.wav differ diff --git a/assets/sounds/enter.wav b/assets/sounds/enter.wav new file mode 100644 index 000000000..ad88ca232 Binary files /dev/null and b/assets/sounds/enter.wav differ diff --git a/assets/sounds/error.wav b/assets/sounds/error.wav new file mode 100644 index 000000000..5ced329b1 Binary files /dev/null and b/assets/sounds/error.wav differ diff --git a/assets/sounds/settings.wav b/assets/sounds/settings.wav new file mode 100644 index 000000000..3e9a80f07 Binary files /dev/null and b/assets/sounds/settings.wav differ diff --git a/docs/00_getting_started_sd.md b/docs/00_getting_started_sd.md index af937dfe9..1661dacd9 100644 --- a/docs/00_getting_started_sd.md +++ b/docs/00_getting_started_sd.md @@ -1,11 +1,22 @@ ## First time setup of SD card -Using your PC, insert the SD card and ensure it is formatted for compatibility with your flashcart (*FAT32 and EXFAT are fully supported on the SC64*). +### Flashcarts +Using your PC, insert the SD card and ensure it is formatted for compatibility with your flashcart. +**warning** Filenames are expected to be part of the ASCII character set. Unicode characters are not fully supported and may cause a crash screen. + +#### SC64 +- FAT32 and EXFAT are fully supported. +- An SD formatted with 128 kiB cluster size is recommended. - Download the latest `sc64menu.n64` (assuming you are using an *sc64*) file from the [releases](https://github.com/Polprzewodnikowy/N64FlashcartMenu/releases/) page, then put it in the root directory of your SD card. - Create a folder in the root of your SD card called `menu`. - Place your ROMs on the SD Card, in any folder (**except for `menu`**). +#### Other supported flashcarts +- FAT32 recommended. +- An SD formatted with default cluster size is recommended. + + ### Emulator support Emulators should be added to the `/menu/emulators` directory on the SD card. @@ -14,6 +25,8 @@ Menu currently supports the following emulators and associated ROM file names: - **NES**: [neon64v2](https://github.com/hcs64/neon64v2/releases) by *hcs64* - `neon64bu.rom` - **SNES**: [sodium64](https://github.com/Hydr8gon/sodium64/releases) by *Hydr8gon* - `sodium64.z64` - **Game Boy** / **GB Color**: [gb64](https://lambertjamesd.github.io/gb64/romwrapper/romwrapper.html) by *lambertjamesd* - `gb.v64` / `gbc.v64` ("Download Emulator" button) +- **SMS** / **GG**: [smsPlus64](https://github.com/fhoedemakers/smsplus64/releases) by *fhoedmakers* - `smsPlus64.z64` +- **Fairchild Channel F**: [Press-F-Ultra](https://github.com/celerizer/Press-F-Ultra/releases) by *celerizer* - `Press-F.z64` ### 64DD disk support @@ -40,7 +53,9 @@ SD:\ │ ├── neon64bu.rom │ ├── sodium64.z64 │ ├── gb.v64 -│ └── gbc.v64 +│ ├── gbc.v64 +│ ├── smsPlus64.z64 +│ └── Press-F.z64 │ ├── (a rom).z64 ├── (a rom).n64 diff --git a/docs/07_menu_customization.md b/docs/07_menu_customization.md new file mode 100644 index 000000000..99807b216 --- /dev/null +++ b/docs/07_menu_customization.md @@ -0,0 +1,5 @@ +# Menu customization + +## Using a custom font +Add a `font64` file to the root directory called "custom.font64" +This can be build using `libdragon` tools. diff --git a/docs/99_developer_guide.md b/docs/99_developer_guide.md index ab1481401..8aa628795 100644 --- a/docs/99_developer_guide.md +++ b/docs/99_developer_guide.md @@ -45,10 +45,13 @@ For ease of development and debugging, the menu ROM can run in the [Ares emulato * Add the required file to the correct folder on your SD card. -## Update Libdragon submodule -This repo currently uses the `preview` branch as a submodule at a specific commit. +## Update submodules To update to the latest version, use `git submodule update --remote` from the terminal. +### libdragon +This repo currently uses the `preview` branch as a submodule at a specific commit. +* To ensure your local instance is building against it, use `cd ./libdragon && make clobber -j && make libdragon tools -j && make install tools-install -j && cd ..` + ## Generate documentation Run `doxygen` from the dev container terminal. Make sure you fix the warnings before creating a PR! @@ -57,6 +60,8 @@ Generated documentation is located in the `output/docs` folder and auto-publishe Once merged, they can be viewed [here](https://polprzewodnikowy.github.io/N64FlashcartMenu/) ### Test generated docs in the dev-container +Testing the documentation locally allows you to preview changes and ensure everything renders correctly before submitting your changes. + Install Prerequisites: ```bash apt-get install ruby-full build-essential zlib1g-dev diff --git a/libdragon b/libdragon index af650428e..a9e651fb7 160000 --- a/libdragon +++ b/libdragon @@ -1 +1 @@ -Subproject commit af650428e9615f4e08d8e7eae187929a90c15ccc +Subproject commit a9e651fb7289b30e76304eddc5f5a383ff3e2ad2 diff --git a/src/boot/boot_io.h b/src/boot/boot_io.h index 6923e4dff..eb9f5cc65 100644 --- a/src/boot/boot_io.h +++ b/src/boot/boot_io.h @@ -7,41 +7,79 @@ #ifndef BOOT_IO_H__ #define BOOT_IO_H__ - #include #include - +/** + * @typedef io8_t + * @brief 8-bit volatile IO type. + */ typedef volatile uint8_t io8_t; -typedef volatile uint32_t io32_t; +/** + * @typedef io32_t + * @brief 32-bit volatile IO type. + */ +typedef volatile uint32_t io32_t; +/** + * @brief Convert an address to its uncached equivalent. + * + * This macro takes an address and converts it to its uncached equivalent + * by setting the appropriate bits. + * + * @param address The address to convert. + * @return The uncached equivalent of the address. + */ #define UNCACHED(address) ((typeof(address)) (((io32_t) (address)) | (0xA0000000UL))) -/** @brief Memory Structure. */ +/** + * @brief Memory Structure. + * + * This structure represents the memory layout for the SP (Signal Processor), + * containing both Data Memory (DMEM) and Instruction Memory (IMEM). + */ typedef struct { - io32_t DMEM[1024]; - io32_t IMEM[1024]; + io32_t DMEM[1024]; /**< Data Memory (DMEM) array of 1024 32-bit words. */ + io32_t IMEM[1024]; /**< Instruction Memory (IMEM) array of 1024 32-bit words. */ } sp_mem_t; +/** + * @brief Base address for SP memory. + */ #define SP_MEM_BASE (0x04000000UL) + +/** + * @brief Pointer to the SP memory structure. + */ #define SP_MEM ((sp_mem_t *) SP_MEM_BASE) -/** @brief SP Registers Structure. */ +/** + * @brief SP Registers Structure. + * + * This structure represents the registers for the SP (Signal Processor). + */ typedef struct { - io32_t PADDR; - io32_t MADDR; - io32_t RD_LEN; - io32_t WR_LEN; - io32_t SR; - io32_t DMA_FULL; - io32_t DMA_BUSY; - io32_t SEMAPHORE; + io32_t PADDR; /**< Physical Address Register. */ + io32_t MADDR; /**< Memory Address Register. */ + io32_t RD_LEN; /**< Read Length Register. */ + io32_t WR_LEN; /**< Write Length Register. */ + io32_t SR; /**< Status Register. */ + io32_t DMA_FULL; /**< DMA Full Register. */ + io32_t DMA_BUSY; /**< DMA Busy Register. */ + io32_t SEMAPHORE; /**< Semaphore Register. */ io32_t __reserved[0xFFF8]; io32_t PC; } sp_regs_t; +/** + * @brief Base address for SP registers. + */ #define SP_BASE (0x04040000UL) + +/** + * @brief Pointer to the SP registers structure. + */ #define SP ((sp_regs_t *) SP_BASE) #define SP_SR_HALT (1 << 0) @@ -85,7 +123,6 @@ typedef struct { #define SP_SR_CLR_SIG7 (1 << 23) #define SP_SR_SET_SIG7 (1 << 24) - /** @brief DPC Registers Structure. */ typedef struct { io32_t START; @@ -123,7 +160,6 @@ typedef struct { #define DPC_SR_CLR_CMD_CTR (1 << 8) #define DPC_SR_CLR_CLOCK_CTR (1 << 9) - /** @brief Video Interface Registers Structure. */ typedef struct { /** @brief The Control Register. */ @@ -198,7 +234,6 @@ typedef struct { #define AI_SR_FIFO_FULL (1 << 31) #define AI_CR_DMA_ON (1 << 0) - /** @brief Peripheral Interface Register Structure. */ typedef struct { /** @brief The Memory Address. */ @@ -233,15 +268,12 @@ typedef struct { #define PI_SR_RESET (1 << 0) #define PI_SR_CLR_INTR (1 << 1) - #define ROM_DDIPL_BASE (0x06000000UL) #define ROM_DDIPL ((io32_t *) ROM_DDIPL_BASE) - #define ROM_CART_BASE (0x10000000UL) #define ROM_CART ((io32_t *) ROM_CART_BASE) - static inline uint32_t cpu_io_read (io32_t *address) { io32_t *uncached = UNCACHED(address); uint32_t value = *uncached; @@ -253,5 +285,4 @@ static inline void cpu_io_write (io32_t *address, uint32_t value) { *uncached = value; } - -#endif +#endif /* BOOT_IO_H__ */ diff --git a/src/boot/vr4300_asm.h b/src/boot/vr4300_asm.h index 59dfd77c3..b2736e212 100644 --- a/src/boot/vr4300_asm.h +++ b/src/boot/vr4300_asm.h @@ -3,37 +3,47 @@ #include +/** + * @brief VR4300 Instruction Structure + * + * This structure represents a VR4300 instruction, which can be of different types (R-type, I-type, J-type, etc.). + */ typedef union { - uint32_t raw; + uint32_t raw; /**< Raw 32-bit instruction */ struct { - uint32_t op : 6; - uint32_t rs : 5; - uint32_t rt : 5; - uint32_t imm : 16; - } i_type; + uint32_t op : 6; /**< Opcode field */ + uint32_t rs : 5; /**< Source register */ + uint32_t rt : 5; /**< Target register */ + uint32_t imm : 16; /**< Immediate value */ + } i_type; /**< I-type instruction format */ struct { - uint32_t op : 6; - uint32_t target : 26; - } j_type; + uint32_t op : 6; /**< Opcode field */ + uint32_t target : 26; /**< Target Address field */ + } j_type; /**< J-type instruction format */ struct { - uint32_t op : 6; - uint32_t rs : 5; - uint32_t rt : 5; - uint32_t rd : 5; - uint32_t sa : 5; - uint32_t funct : 6; - } r_type; + uint32_t op : 6; /**< Opcode field */ + uint32_t rs : 5; /**< Source register */ + uint32_t rt : 5; /**< Target register */ + uint32_t rd : 5; /**< Destination register */ + uint32_t sa : 5; /**< Shift amount */ + uint32_t funct : 6; /**< Function field */ + } r_type; /**< Alternate R-type instruction format */ struct { - uint32_t op : 6; - uint32_t co : 1; - uint32_t funct : 25; - } c_type; + uint32_t op : 6; /**< Opcode field */ + uint32_t co : 1; /**< Coprocessor operation bit */ + uint32_t funct : 25; /**< Function field */ + } c_type; /**< C-type instruction format */ } vr4300_instruction_t; +/** + * @brief VR4300 Opcode Enumeration + * + * Enumeration for different opcodes used in VR4300 instructions. + */ typedef enum { OP_SPECIAL, OP_REGIMM, @@ -394,4 +404,4 @@ typedef enum { #define I_SRL(rd, rt, sa) __ASM_R_INST(OP_SPECIAL, 0, rt, rd, sa, FUNCT_SRL) #define I_SW(rt, offset, base) __ASM_I_INST(OP_SW, base, rt, offset) -#endif +#endif /* VR4300_ASM_H__ */ diff --git a/src/flashcart/64drive/64drive.c b/src/flashcart/64drive/64drive.c index 61af404dc..98e28fc1a 100644 --- a/src/flashcart/64drive/64drive.c +++ b/src/flashcart/64drive/64drive.c @@ -75,10 +75,38 @@ static bool d64_has_feature (flashcart_features_t feature) { case FLASHCART_FEATURE_64DD: return false; case FLASHCART_FEATURE_RTC: return true; case FLASHCART_FEATURE_USB: return true; + case FLASHCART_FEATURE_AUTO_CIC: return true; + case FLASHCART_FEATURE_AUTO_REGION: return true; + case FLASHCART_FEATURE_SAVE_WRITEBACK: return true; default: return false; } } +/** + * @brief Retrieves the firmware version of the 64drive device. + * + * The firmware version is returned as a flashcart_firmware_version_t structure, with each field + * including the major, minor, and revision numbers. + * The major version is set to 1 for 64drive variant A, and 2 for 64drive variant B. + * + * @return A flashcart_firmware_version_t structure containing the firmware version information. + */ +static flashcart_firmware_version_t d64_get_firmware_version (void) { + flashcart_firmware_version_t version_info; + + d64_ll_get_version(&device_variant, &version_info.minor, &version_info.revision); + + if (device_variant == DEVICE_VARIANT_A) { + version_info.major = 1; + } else if (device_variant == DEVICE_VARIANT_B) { + version_info.major = 2; + } else { + version_info.major = 0; + } + + return version_info; +} + static flashcart_err_t d64_load_rom (char *rom_path, flashcart_progress_callback_t *progress) { FIL fil; UINT br; @@ -274,6 +302,7 @@ static flashcart_t flashcart_d64 = { .init = d64_init, .deinit = d64_deinit, .has_feature = d64_has_feature, + .get_firmware_version = d64_get_firmware_version, .load_rom = d64_load_rom, .load_file = d64_load_file, .load_save = d64_load_save, diff --git a/src/flashcart/64drive/README.md b/src/flashcart/64drive/README.md index 6809afccd..6c6859c0e 100644 --- a/src/flashcart/64drive/README.md +++ b/src/flashcart/64drive/README.md @@ -1,4 +1,4 @@ -## 64drive developer notes +# 64drive developer notes ### Official documentation diff --git a/src/flashcart/ed64/ed64_vseries.c b/src/flashcart/ed64/ed64_vseries.c new file mode 100644 index 000000000..02ec3f761 --- /dev/null +++ b/src/flashcart/ed64/ed64_vseries.c @@ -0,0 +1,156 @@ +#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, + .get_firmware_version = NULL, // FIXME: show the returned firmware version info. + .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 000000000..c96b5a0db --- /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 000000000..a6bf497cd --- /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 0cb55e841..6b634cace 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 @@ -152,6 +156,10 @@ bool flashcart_has_feature (flashcart_features_t feature) { return flashcart->has_feature(feature); } +flashcart_firmware_version_t flashcart_get_firmware_version (void) { + return flashcart->get_firmware_version(); +} + flashcart_err_t flashcart_load_rom (char *rom_path, bool byte_swap, flashcart_progress_callback_t *progress) { flashcart_err_t err; diff --git a/src/flashcart/flashcart.h b/src/flashcart/flashcart.h index b4996f360..4a191290b 100644 --- a/src/flashcart/flashcart.h +++ b/src/flashcart/flashcart.h @@ -29,6 +29,11 @@ typedef enum { FLASHCART_FEATURE_64DD, FLASHCART_FEATURE_RTC, FLASHCART_FEATURE_USB, + FLASHCART_FEATURE_AUTO_CIC, + FLASHCART_FEATURE_AUTO_REGION, + FLASHCART_FEATURE_DIAGNOSTIC_DATA, + FLASHCART_FEATURE_BIOS_UPDATE_FROM_MENU, + FLASHCART_FEATURE_SAVE_WRITEBACK } flashcart_features_t; /** @brief Flashcart save type enumeration */ @@ -52,6 +57,13 @@ typedef struct { uint8_t defect_tracks[16][12]; } flashcart_disk_parameters_t; +/** @brief Flashcart Firmware version Structure. */ +typedef struct { + uint16_t major; + uint16_t minor; + uint32_t revision; +} flashcart_firmware_version_t; + typedef void flashcart_progress_callback_t (float progress); /** @brief Flashcart Structure */ @@ -62,6 +74,8 @@ typedef struct { flashcart_err_t (*deinit) (void); /** @brief The flashcart feature function */ bool (*has_feature) (flashcart_features_t feature); + /** @brief The flashcart firmware version function */ + flashcart_firmware_version_t (*get_firmware_version) (void); /** @brief The flashcart ROM load function */ flashcart_err_t (*load_rom) (char *rom_path, flashcart_progress_callback_t *progress); /** @brief The flashcart file load function */ @@ -83,6 +97,7 @@ char *flashcart_convert_error_message (flashcart_err_t err); flashcart_err_t flashcart_init (const char **storage_prefix); flashcart_err_t flashcart_deinit (void); bool flashcart_has_feature (flashcart_features_t feature); +flashcart_firmware_version_t flashcart_get_firmware_version (void); flashcart_err_t flashcart_load_rom (char *rom_path, bool byte_swap, flashcart_progress_callback_t *progress); flashcart_err_t flashcart_load_file (char *file_path, uint32_t rom_offset, uint32_t file_offset); flashcart_err_t flashcart_load_save (char *save_path, flashcart_save_type_t save_type); diff --git a/src/flashcart/sc64/README.md b/src/flashcart/sc64/README.md index 5071466f3..fe3134110 100644 --- a/src/flashcart/sc64/README.md +++ b/src/flashcart/sc64/README.md @@ -1,4 +1,4 @@ -## SummerCart64 developer notes +# SummerCart64 developer notes ### Official documentation diff --git a/src/flashcart/sc64/sc64.c b/src/flashcart/sc64/sc64.c index 57bb7e73c..e53c3e278 100644 --- a/src/flashcart/sc64/sc64.c +++ b/src/flashcart/sc64/sc64.c @@ -187,6 +187,14 @@ static bool disk_load_sector_table (char *path, uint32_t *sector_table_offset, u return false; } +static flashcart_firmware_version_t sc64_get_firmware_version (void) { + flashcart_firmware_version_t version_info; + + sc64_ll_get_version(&version_info.major, &version_info.minor, &version_info.revision); + + return version_info; +} + static flashcart_err_t sc64_init (void) { uint16_t major; @@ -254,6 +262,10 @@ static bool sc64_has_feature (flashcart_features_t feature) { case FLASHCART_FEATURE_64DD: return true; case FLASHCART_FEATURE_RTC: return true; case FLASHCART_FEATURE_USB: return true; + case FLASHCART_FEATURE_AUTO_CIC: return true; + case FLASHCART_FEATURE_AUTO_REGION: return true; + case FLASHCART_FEATURE_DIAGNOSTIC_DATA: return true; + case FLASHCART_FEATURE_SAVE_WRITEBACK: return true; default: return false; } } @@ -568,6 +580,7 @@ static flashcart_t flashcart_sc64 = { .init = sc64_init, .deinit = sc64_deinit, .has_feature = sc64_has_feature, + .get_firmware_version = sc64_get_firmware_version, .load_rom = sc64_load_rom, .load_file = sc64_load_file, .load_save = sc64_load_save, diff --git a/src/libs/miniz b/src/libs/miniz index 16413c213..0f4cbb8c2 160000 --- a/src/libs/miniz +++ b/src/libs/miniz @@ -1 +1 @@ -Subproject commit 16413c213de38e703d883006193734e8b1178d5d +Subproject commit 0f4cbb8c27a5dc48967e5a7d3b68f8666d8f96d4 diff --git a/src/menu/actions.c b/src/menu/actions.c index 8bb585870..4cafbce7c 100644 --- a/src/menu/actions.c +++ b/src/menu/actions.c @@ -21,11 +21,20 @@ static void actions_clear (menu_t *menu) { menu->actions.back = false; menu->actions.options = false; menu->actions.settings = false; + menu->actions.lz_context = false; } static void actions_update_direction (menu_t *menu) { - joypad_8way_t held_dir = joypad_get_direction(JOYPAD_PORT_1, JOYPAD_2D_DPAD | JOYPAD_2D_STICK); - joypad_8way_t fast_dir = joypad_get_direction(JOYPAD_PORT_1, JOYPAD_2D_C); + joypad_8way_t held_dir = JOYPAD_8WAY_NONE; + joypad_8way_t fast_dir = JOYPAD_8WAY_NONE; + + JOYPAD_PORT_FOREACH (i) { + held_dir = joypad_get_direction(i, JOYPAD_2D_DPAD | JOYPAD_2D_STICK); + fast_dir = joypad_get_direction(i, JOYPAD_2D_C); + if (held_dir != JOYPAD_8WAY_NONE || fast_dir != JOYPAD_8WAY_NONE) { + break; + } + } if (fast_dir != JOYPAD_8WAY_NONE) { held_dir = fast_dir; @@ -81,7 +90,14 @@ static void actions_update_direction (menu_t *menu) { } static void actions_update_buttons (menu_t *menu) { - joypad_buttons_t pressed = joypad_get_buttons_pressed(JOYPAD_PORT_1); + joypad_buttons_t pressed = {0}; + + JOYPAD_PORT_FOREACH (i) { + pressed = joypad_get_buttons_pressed(i); + if (pressed.raw) { + break; + } + } if (pressed.a) { menu->actions.enter = true; @@ -91,10 +107,18 @@ static void actions_update_buttons (menu_t *menu) { menu->actions.options = true; } else if (pressed.start) { menu->actions.settings = true; + } else if (pressed.l || pressed.z) { + menu->actions.lz_context = true; } } +void actions_init (void) { + JOYPAD_PORT_FOREACH (port) { + joypad_set_rumble_active(port, false); + } +} + void actions_update (menu_t *menu) { joypad_poll(); diff --git a/src/menu/actions.h b/src/menu/actions.h index f890b55c0..f10a83cec 100644 --- a/src/menu/actions.h +++ b/src/menu/actions.h @@ -10,7 +10,10 @@ #include "menu_state.h" - +/** + * @brief Initialize the actions module + */ +void actions_init (void); void actions_update (menu_t *menu); diff --git a/src/menu/cart_load.c b/src/menu/cart_load.c index b57afb6c5..054102edc 100644 --- a/src/menu/cart_load.c +++ b/src/menu/cart_load.c @@ -177,8 +177,12 @@ cart_load_err_t cart_load_emulator (menu_t *menu, cart_load_emu_type_t emu_type, save_type = FLASHCART_SAVE_TYPE_FLASHRAM_1MBIT; break; case CART_LOAD_EMU_TYPE_SEGA_GENERIC_8BIT: - path_push(path, "TotalSMS.z64"); - save_type = FLASHCART_SAVE_TYPE_SRAM_256KBIT; + path_push(path, "smsPlus64.z64"); + save_type = FLASHCART_SAVE_TYPE_NONE; + break; + case CART_LOAD_EMU_TYPE_FAIRCHILD_CHANNELF: + path_push(path, "Press-F.z64"); + save_type = FLASHCART_SAVE_TYPE_NONE; break; } diff --git a/src/menu/cart_load.h b/src/menu/cart_load.h index 04c2c6791..ad4d34a1e 100644 --- a/src/menu/cart_load.h +++ b/src/menu/cart_load.h @@ -54,6 +54,8 @@ typedef enum { CART_LOAD_EMU_TYPE_GAMEBOY_COLOR, /** @brief The ROM is designed for a Sega 8Bit system (Game Gear or Master System). */ CART_LOAD_EMU_TYPE_SEGA_GENERIC_8BIT, + /** @brief The ROM is designed for a Fairchild Channel F system. */ + CART_LOAD_EMU_TYPE_FAIRCHILD_CHANNELF, } cart_load_emu_type_t; diff --git a/src/menu/components.h b/src/menu/components.h deleted file mode 100644 index 4925ee5b2..000000000 --- a/src/menu/components.h +++ /dev/null @@ -1,74 +0,0 @@ -/** - * @file components.h - * @brief Menu Components - * @ingroup menu - */ - -#ifndef COMPONENTS_H__ -#define COMPONENTS_H__ - - -#include -#include "menu_state.h" - - -/** - * @addtogroup - * @{ menu_components - */ - -void component_box_draw (int x0, int y0, int x1, int y1, color_t color); -void component_border_draw (int x0, int y0, int x1, int y1); -void component_layout_draw (void); -void component_progressbar_draw (int x0, int y0, int x1, int y1, float progress); -void component_seekbar_draw (float progress); -void component_loader_draw (float position); -void component_scrollbar_draw (int x, int y, int width, int height, int position, int items, int visible_items); -void component_list_scrollbar_draw (int position, int items, int visible_items); -void component_dialog_draw (int width, int height); -void component_messagebox_draw (char *fmt, ...); -void component_main_text_draw (rdpq_align_t align, rdpq_valign_t valign, char *fmt, ...); -void component_actions_bar_text_draw (rdpq_align_t align, rdpq_valign_t valign, char *fmt, ...); - -void component_background_init (char *cache_location); -void component_background_free (void); -void component_background_replace_image (surface_t *image); -void component_background_draw (void); - -void component_file_list_draw (entry_t *list, int entries, int selected); - -typedef struct component_context_menu { - int count; - int selected; - bool hide_pending; - struct component_context_menu *parent; - struct component_context_menu *submenu; - struct { - const char *text; - void (*action) (menu_t *menu, void *arg); - void *arg; - struct component_context_menu *submenu; - } list[]; -} component_context_menu_t; - -#define COMPONENT_CONTEXT_MENU_LIST_END { .text = NULL } - -void component_context_menu_init (component_context_menu_t *cm); -void component_context_menu_show (component_context_menu_t *cm); -bool component_context_menu_process (menu_t *menu, component_context_menu_t *cm); -void component_context_menu_draw (component_context_menu_t *cm); - -/** @brief Box Art Structure. */ -typedef struct { - bool loading; - surface_t *image; -} component_boxart_t; - -component_boxart_t *component_boxart_init (const char *storage_prefix, char *game_code); -void component_boxart_free (component_boxart_t *b); -void component_boxart_draw (component_boxart_t *b); - -/** @} */ /* menu_components */ - - -#endif diff --git a/src/menu/components/boxart.c b/src/menu/components/boxart.c deleted file mode 100644 index 54121b6e1..000000000 --- a/src/menu/components/boxart.c +++ /dev/null @@ -1,87 +0,0 @@ -#include - -#include "../components.h" -#include "../path.h" -#include "../png_decoder.h" -#include "constants.h" -#include "utils/fs.h" - - -#define BOXART_DIRECTORY "menu/boxart" - - -static void png_decoder_callback (png_err_t err, surface_t *decoded_image, void *callback_data) { - component_boxart_t *b = (component_boxart_t *) (callback_data); - b->loading = false; - b->image = decoded_image; -} - - -component_boxart_t *component_boxart_init (const char *storage_prefix, char *game_code) { - component_boxart_t *b; - char file_name[8]; - - if ((b = calloc(1, sizeof(component_boxart_t))) == NULL) { - return NULL; - } - - b->loading = true; - - path_t *path = path_init(storage_prefix, BOXART_DIRECTORY); - - sprintf(file_name, "%.3s.png", game_code); - path_push(path, file_name); - if (png_decoder_start(path_get(path), BOXART_WIDTH, BOXART_HEIGHT, png_decoder_callback, b) == PNG_OK) { - path_free(path); - return b; - } - path_pop(path); - - // TODO: This is bad, we should only check for 3 letter codes - sprintf(file_name, "%.2s.png", game_code + 1); - path_push(path, file_name); - if (png_decoder_start(path_get(path), BOXART_WIDTH, BOXART_HEIGHT, png_decoder_callback, b) == PNG_OK) { - path_free(path); - return b; - } - - path_free(path); - free(b); - - return NULL; -} - -void component_boxart_free (component_boxart_t *b) { - if (b) { - if (b->loading) { - png_decoder_abort(); - } - if (b->image) { - surface_free(b->image); - free(b->image); - } - free(b); - } -} - -void component_boxart_draw (component_boxart_t *b) { - if (b && b->image && b->image->width == BOXART_WIDTH && b->image->height == BOXART_HEIGHT) { - rdpq_mode_push(); - rdpq_set_mode_copy(false); - rdpq_tex_blit( - b->image, - BOXART_X, - BOXART_Y, - NULL - ); - rdpq_mode_pop(); - } else { - component_box_draw( - BOXART_X, - BOXART_Y, - BOXART_X + BOXART_WIDTH, - BOXART_Y + BOXART_HEIGHT, - BOXART_LOADING_COLOR - ); - } -} diff --git a/src/menu/disk_info.h b/src/menu/disk_info.h index fe5175ec1..656768fff 100644 --- a/src/menu/disk_info.h +++ b/src/menu/disk_info.h @@ -52,7 +52,17 @@ typedef struct { } disk_info_t; +/** + * @brief Loads disk information from the specified path. + * + * This function reads the disk information from the given path and populates + * the provided disk_info structure with the relevant data. + * + * @param path A pointer to a path_t structure that specifies the path to the disk. + * @param disk_info A pointer to a disk_info_t structure where the disk information will be stored. + * @return A disk_err_t value indicating the success or failure of the operation. + */ disk_err_t disk_info_load (path_t *path, disk_info_t *disk_info); -#endif +#endif /* DISK_INFO_H__ */ diff --git a/src/menu/fonts.h b/src/menu/fonts.h index 9fb000924..97dd54bde 100644 --- a/src/menu/fonts.h +++ b/src/menu/fonts.h @@ -7,23 +7,39 @@ #ifndef FONTS_H__ #define FONTS_H__ -/** @brief Font type enumeration. */ +/** + * @brief Font type enumeration. + * + * This enumeration defines the different types of fonts that can be used + * in the menu system. + */ typedef enum { - FNT_DEFAULT = 1, + FNT_DEFAULT = 1, /**< Default font type */ } menu_font_type_t; -/** @brief Font style enumeration. */ +/** + * @brief Font style enumeration. + * + * This enumeration defines the different styles of fonts that can be used + * in the menu system. + */ typedef enum { - STL_DEFAULT = 0, - STL_GREEN, - STL_BLUE, - STL_YELLOW, - STL_ORANGE, - STL_GRAY, + STL_DEFAULT = 0, /**< Default font style */ + STL_GREEN, /**< Green font style */ + STL_BLUE, /**< Blue font style */ + STL_YELLOW, /**< Yellow font style */ + STL_ORANGE, /**< Orange font style */ + STL_GRAY, /**< Gray font style */ } menu_font_style_t; +/** + * @brief Initialize fonts. + * + * This function initializes the fonts used in the menu system. It can load + * custom fonts from the specified path. + * + * @param custom_font_path Path to the custom font file. + */ +void fonts_init(char *custom_font_path); -void fonts_init (char *custom_font_path); - - -#endif +#endif /* FONTS_H__ */ diff --git a/src/menu/menu.c b/src/menu/menu.c index 2243a03d0..a30ff6f08 100644 --- a/src/menu/menu.c +++ b/src/menu/menu.c @@ -27,37 +27,27 @@ #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; -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->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; } -#endif - frame_counter = 0; -} -static void menu_init (boot_params_t *boot_params) { joypad_init(); timer_init(); rtc_init(); @@ -65,22 +55,11 @@ static void menu_init (boot_params_t *boot_params) { 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); @@ -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); @@ -99,39 +87,24 @@ static void menu_init (boot_params_t *boot_params) { directory_create(path_get(path)); path_push(path, BACKGROUND_CACHE_FILE); - component_background_init(path_get(path)); + ui_components_background_init(path_get(path)); path_free(path); - menu->boot_params = boot_params; + sound_use_sfx(menu->settings.soundfx_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; - } - - 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); + ui_components_background_free(); + path_free(menu->load.disk_path); path_free(menu->load.rom_path); for (int i = 0; i < menu->browser.entries; i++) { @@ -141,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(); @@ -153,7 +124,7 @@ static void menu_deinit (menu_t *menu) { timer_close(); joypad_close(); - display_close(); + flashcart_deinit(); } typedef const struct { @@ -195,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); diff --git a/src/menu/menu_state.h b/src/menu/menu_state.h index c2ad221d8..b34b6d1ad 100644 --- a/src/menu/menu_state.h +++ b/src/menu/menu_state.h @@ -85,6 +85,7 @@ typedef struct { bool back; bool options; bool settings; + bool lz_context; } actions; struct { @@ -102,7 +103,14 @@ typedef struct { rom_info_t rom_info; path_t *disk_path; disk_info_t disk_info; + bool combined_disk_rom; } load; + + struct { + bool rom_file; + bool disk_file; + bool emulator_file; + } boot_pending; } menu_t; diff --git a/src/menu/mp3_player.h b/src/menu/mp3_player.h index baea06bff..20f6c4854 100644 --- a/src/menu/mp3_player.h +++ b/src/menu/mp3_player.h @@ -7,37 +7,166 @@ #ifndef MP3_PLAYER_H__ #define MP3_PLAYER_H__ - #include - -/** @brief MP3 file error enumeration */ +/** + * @brief MP3 file error enumeration. + * + * Enumeration for different types of errors that can occur in the MP3 player. + */ typedef enum { - MP3PLAYER_OK, - MP3PLAYER_ERR_OUT_OF_MEM, - MP3PLAYER_ERR_IO, - MP3PLAYER_ERR_NO_FILE, - MP3PLAYER_ERR_INVALID_FILE, + MP3PLAYER_OK, /**< No error */ + MP3PLAYER_ERR_OUT_OF_MEM, /**< Out of memory error */ + MP3PLAYER_ERR_IO, /**< Input/Output error */ + MP3PLAYER_ERR_NO_FILE, /**< No file found error */ + MP3PLAYER_ERR_INVALID_FILE, /**< Invalid file error */ } mp3player_err_t; +/** + * @brief Initialize the MP3 player mixer. + * + * This function initializes the mixer for the MP3 player. + */ +void mp3player_mixer_init(void); + +/** + * @brief Initialize the MP3 player. + * + * This function initializes the MP3 player and prepares it for playback. + * + * @return mp3player_err_t Error code indicating the result of the initialization. + */ +mp3player_err_t mp3player_init(void); + +/** + * @brief Deinitialize the MP3 player. + * + * This function deinitializes the MP3 player and releases any resources. + */ +void mp3player_deinit(void); + +/** + * @brief Load an MP3 file. + * + * This function loads an MP3 file from the specified path. + * + * @param path Path to the MP3 file. + * @return mp3player_err_t Error code indicating the result of the load operation. + */ +mp3player_err_t mp3player_load(char *path); + +/** + * @brief Unload the current MP3 file. + * + * This function unloads the currently loaded MP3 file. + */ +void mp3player_unload(void); + +/** + * @brief Process the MP3 player. + * + * This function processes the MP3 player, handling playback and other operations. + * + * @return mp3player_err_t Error code indicating the result of the process operation. + */ +mp3player_err_t mp3player_process(void); + +/** + * @brief Check if the MP3 player is playing. + * + * This function checks if the MP3 player is currently playing. + * + * @return true if the MP3 player is playing, false otherwise. + */ +bool mp3player_is_playing(void); + +/** + * @brief Check if the MP3 player has finished playing. + * + * This function checks if the MP3 player has finished playing the current file. + * + * @return true if the MP3 player has finished playing, false otherwise. + */ +bool mp3player_is_finished(void); + +/** + * @brief Start playback of the MP3 file. + * + * This function starts playback of the currently loaded MP3 file. + * + * @return mp3player_err_t Error code indicating the result of the play operation. + */ +mp3player_err_t mp3player_play(void); + +/** + * @brief Stop playback of the MP3 file. + * + * This function stops playback of the currently loaded MP3 file. + */ +void mp3player_stop(void); + +/** + * @brief Toggle playback of the MP3 file. + * + * This function toggles playback of the currently loaded MP3 file. + * + * @return mp3player_err_t Error code indicating the result of the toggle operation. + */ +mp3player_err_t mp3player_toggle(void); + +/** + * @brief Mute or unmute the MP3 player. + * + * This function mutes or unmutes the MP3 player. + * + * @param mute true to mute, false to unmute. + */ +void mp3player_mute(bool mute); + +/** + * @brief Seek to a specific position in the MP3 file. + * + * This function seeks to a specific position in the currently loaded MP3 file. + * + * @param seconds Number of seconds to seek. + * @return mp3player_err_t Error code indicating the result of the seek operation. + */ +mp3player_err_t mp3player_seek(int seconds); + +/** + * @brief Get the duration of the MP3 file. + * + * This function gets the duration of the currently loaded MP3 file. + * + * @return float Duration of the MP3 file in seconds. + */ +float mp3player_get_duration(void); + +/** + * @brief Get the bitrate of the MP3 file. + * + * This function gets the bitrate of the currently loaded MP3 file. + * + * @return float Bitrate of the MP3 file in kbps. + */ +float mp3player_get_bitrate(void); + +/** + * @brief Get the sample rate of the MP3 file. + * + * This function gets the sample rate of the currently loaded MP3 file. + * + * @return int Sample rate of the MP3 file in Hz. + */ +int mp3player_get_samplerate(void); + +/** + * @brief Get the current playback progress. + * + * This function gets the current playback progress of the MP3 file. + * + * @return float Current playback progress as a percentage (0.0 to 100.0). + */ +float mp3player_get_progress(void); -void mp3player_mixer_init (void); -mp3player_err_t mp3player_init (void); -void mp3player_deinit (void); -mp3player_err_t mp3player_load (char *path); -void mp3player_unload (void); -mp3player_err_t mp3player_process (void); -bool mp3player_is_playing (void); -bool mp3player_is_finished (void); -mp3player_err_t mp3player_play (void); -void mp3player_stop (void); -mp3player_err_t mp3player_toggle (void); -void mp3player_mute (bool mute); -mp3player_err_t mp3player_seek (int seconds); -float mp3player_get_duration (void); -float mp3player_get_bitrate (void); -int mp3player_get_samplerate (void); -float mp3player_get_progress (void); - - -#endif +#endif /* MP3_PLAYER_H__ */ diff --git a/src/menu/png_decoder.h b/src/menu/png_decoder.h index ea7977f75..a506e1361 100644 --- a/src/menu/png_decoder.h +++ b/src/menu/png_decoder.h @@ -7,27 +7,68 @@ #ifndef PNG_DECODER_H__ #define PNG_DECODER_H__ - #include - -/** @brief PNG decoder errors */ +/** + * @brief PNG decoder errors + * + * Enumeration for different types of errors that can occur in the PNG decoder. + */ typedef enum { - PNG_OK, - PNG_ERR_INT, - PNG_ERR_BUSY, - PNG_ERR_OUT_OF_MEM, - PNG_ERR_NO_FILE, - PNG_ERR_BAD_FILE, + PNG_OK, /**< No error */ + PNG_ERR_INT, /**< Internal error */ + PNG_ERR_BUSY, /**< Decoder is busy */ + PNG_ERR_OUT_OF_MEM, /**< Out of memory error */ + PNG_ERR_NO_FILE, /**< No file found error */ + PNG_ERR_BAD_FILE, /**< Bad file error */ } png_err_t; +/** + * @brief PNG decoder callback type. + * + * This typedef defines the callback function type used by the PNG decoder. + * + * @param err Error code indicating the result of the decoding process. + * @param decoded_image Pointer to the decoded image surface. + * @param callback_data User-defined data passed to the callback function. + */ typedef void png_callback_t (png_err_t err, surface_t *decoded_image, void *callback_data); - +/** + * @brief Start the PNG decoding process. + * + * This function starts the PNG decoding process for the specified file. + * + * @param path Path to the PNG file. + * @param max_width Maximum width of the decoded image. + * @param max_height Maximum height of the decoded image. + * @param callback Callback function to be called when decoding is complete. + * @param callback_data User-defined data to be passed to the callback function. + * @return png_err_t Error code indicating the result of the start operation. + */ png_err_t png_decoder_start (char *path, int max_width, int max_height, png_callback_t *callback, void *callback_data); + +/** + * @brief Abort the PNG decoding process. + * + * This function aborts the ongoing PNG decoding process. + */ void png_decoder_abort (void); + +/** + * @brief Get the progress of the PNG decoding process. + * + * This function returns the current progress of the PNG decoding process as a percentage. + * + * @return float Current progress of the decoding process (0.0 to 100.0). + */ float png_decoder_get_progress (void); -void png_decoder_poll (void); +/** + * @brief Poll the PNG decoder. + * + * This function polls the PNG decoder to handle any ongoing decoding tasks. + */ +void png_decoder_poll (void); -#endif +#endif /* PNG_DECODER_H__ */ diff --git a/src/menu/rom_info.c b/src/menu/rom_info.c index e5b750ced..b313950c8 100644 --- a/src/menu/rom_info.c +++ b/src/menu/rom_info.c @@ -835,6 +835,7 @@ static rom_err_t save_override (path_t *path, const char *id, int value, int def mini_t *ini = mini_try_load(path_get(overrides_path)); if (!ini) { + path_free(overrides_path); return ROM_ERR_SAVE_IO; } diff --git a/src/menu/settings.c b/src/menu/settings.c index 3e046ed07..703871aab 100644 --- a/src/menu/settings.c +++ b/src/menu/settings.c @@ -13,10 +13,13 @@ static settings_t init = { .show_protected_entries = false, .default_directory = "/", .use_saves_folder = true, - + .soundfx_enabled = false, + .rom_autoload_enabled = false, + .rom_autoload_path = "", + .rom_autoload_filename = "", + /* Beta feature flags (should always init to off) */ .bgm_enabled = false, - .sound_enabled = false, .rumble_enabled = false, }; @@ -39,10 +42,14 @@ void settings_load (settings_t *settings) { settings->show_protected_entries = mini_get_bool(ini, "menu", "show_protected_entries", init.show_protected_entries); settings->default_directory = strdup(mini_get_string(ini, "menu", "default_directory", init.default_directory)); settings->use_saves_folder = mini_get_bool(ini, "menu", "use_saves_folder", init.use_saves_folder); + settings->soundfx_enabled = mini_get_bool(ini, "menu", "soundfx_enabled", init.soundfx_enabled); + + settings->rom_autoload_enabled = mini_get_bool(ini, "menu", "autoload_rom_enabled", init.rom_autoload_enabled); + settings->rom_autoload_path = strdup(mini_get_string(ini, "autoload", "rom_path", init.rom_autoload_path)); + settings->rom_autoload_filename = strdup(mini_get_string(ini, "autoload", "rom_filename", init.rom_autoload_filename)); /* Beta feature flags, they might not be in the file */ settings->bgm_enabled = mini_get_bool(ini, "menu_beta_flag", "bgm_enabled", init.bgm_enabled); - settings->sound_enabled = mini_get_bool(ini, "menu_beta_flag", "sound_enabled", init.sound_enabled); settings->rumble_enabled = mini_get_bool(ini, "menu_beta_flag", "rumble_enabled", init.rumble_enabled); mini_free(ini); @@ -55,10 +62,13 @@ void settings_save (settings_t *settings) { mini_set_bool(ini, "menu", "show_protected_entries", settings->show_protected_entries); mini_set_string(ini, "menu", "default_directory", settings->default_directory); mini_set_bool(ini, "menu", "use_saves_folder", settings->use_saves_folder); + mini_set_bool(ini, "menu", "soundfx_enabled", settings->soundfx_enabled); + mini_set_bool(ini, "menu", "autoload_rom_enabled", settings->rom_autoload_enabled); + mini_set_string(ini, "autoload", "rom_path", settings->rom_autoload_path); + mini_set_string(ini, "autoload", "rom_filename", settings->rom_autoload_filename); /* Beta feature flags, they should not save until production ready! */ // mini_set_bool(ini, "menu_beta_flag", "bgm_enabled", settings->bgm_enabled); - // mini_set_bool(ini, "menu_beta_flag", "sound_enabled", settings->sound_enabled); // mini_set_bool(ini, "menu_beta_flag", "rumble_enabled", settings->rumble_enabled); mini_save(ini, MINI_FLAGS_SKIP_EMPTY_GROUPS); diff --git a/src/menu/settings.h b/src/menu/settings.h index e9931b059..26454412b 100644 --- a/src/menu/settings.h +++ b/src/menu/settings.h @@ -26,10 +26,20 @@ typedef struct { bool bgm_enabled; /** @brief Enable Sounds */ - bool sound_enabled; + bool soundfx_enabled; /** @brief Enable rumble feedback */ bool rumble_enabled; + + /** @brief Enable the ability to bypass the menu and instantly load a ROM */ + bool rom_autoload_enabled; + + /** @brief A path to the autoloaded ROM */ + char *rom_autoload_path; + + /** @brief A filename of the autoloaded ROM */ + char *rom_autoload_filename; + } settings_t; @@ -40,5 +50,4 @@ void settings_load (settings_t *settings); /** @brief The settings to save */ void settings_save (settings_t *settings); - #endif diff --git a/src/menu/sound.c b/src/menu/sound.c index 9e58d0015..ea0884478 100644 --- a/src/menu/sound.c +++ b/src/menu/sound.c @@ -3,14 +3,18 @@ #include #include "mp3_player.h" +#include "sound.h" #define DEFAULT_FREQUENCY (44100) #define NUM_BUFFERS (4) -#define NUM_CHANNELS (2) +#define NUM_CHANNELS (3) + +static wav64_t sfx_cursor, sfx_error, sfx_enter, sfx_exit, sfx_setting; static bool sound_initialized = false; +static bool sfx_enabled = false; static void sound_reconfigure (int frequency) { @@ -35,8 +39,60 @@ void sound_init_mp3_playback (void) { sound_reconfigure(mp3player_get_samplerate()); } + +void sound_init_sfx (void) { + mixer_ch_set_vol(SOUND_SFX_CHANNEL, 0.5f, 0.5f); + wav64_open(&sfx_cursor, "rom:/cursorsound.wav64"); + wav64_open(&sfx_exit, "rom:/back.wav64"); + wav64_open(&sfx_setting, "rom:/settings.wav64"); + wav64_open(&sfx_enter, "rom:/enter.wav64"); + wav64_open(&sfx_error, "rom:/error.wav64"); + sfx_enabled = true; +} + +void sound_use_sfx(bool state) { + if (state) { + sfx_enabled = true; + } + else { + sfx_enabled = false; + } +} + +void sound_play_effect(sound_effect_t sfx) { + if(sfx_enabled) { + switch (sfx) { + case SFX_CURSOR: + wav64_play(&sfx_cursor, SOUND_SFX_CHANNEL); + break; + case SFX_EXIT: + wav64_play(&sfx_exit, SOUND_SFX_CHANNEL); + break; + case SFX_SETTING: + wav64_play(&sfx_setting, SOUND_SFX_CHANNEL); + break; + case SFX_ENTER: + wav64_play(&sfx_enter, SOUND_SFX_CHANNEL); + break; + case SFX_ERROR: + wav64_play(&sfx_error, SOUND_SFX_CHANNEL); + break; + default: + break; + } + } +} + + void sound_deinit (void) { if (sound_initialized) { + if (sfx_enabled) { + wav64_close(&sfx_cursor); + wav64_close(&sfx_exit); + wav64_close(&sfx_setting); + wav64_close(&sfx_enter); + wav64_close(&sfx_error); + } mixer_close(); audio_close(); sound_initialized = false; @@ -44,9 +100,7 @@ void sound_deinit (void) { } void sound_poll (void) { - if (sound_initialized && audio_can_write()) { - short *audio_buffer = audio_write_begin(); - mixer_poll(audio_buffer, audio_get_buffer_length()); - audio_write_end(); + if (sound_initialized) { + mixer_try_play(); } } diff --git a/src/menu/sound.h b/src/menu/sound.h index 44ecf6bc1..97d83d235 100644 --- a/src/menu/sound.h +++ b/src/menu/sound.h @@ -7,14 +7,61 @@ #ifndef SOUND_H__ #define SOUND_H__ +#include -#define SOUND_MP3_PLAYER_CHANNEL (0) +#define SOUND_MP3_PLAYER_CHANNEL (0) /**< Channel for MP3 player sound */ +#define SOUND_SFX_CHANNEL (2) /**< Channel for sound effects */ +/** + * @brief Enumeration of available sound effects for menu interactions. + * + * This enumeration defines the different sound effects that can be used + * for menu interactions. + */ +typedef enum { + SFX_CURSOR, /**< Sound effect for cursor movement */ + SFX_ERROR, /**< Sound effect for error */ + SFX_ENTER, /**< Sound effect for entering a menu */ + SFX_EXIT, /**< Sound effect for exiting a menu */ + SFX_SETTING, /**< Sound effect for changing a setting */ +} sound_effect_t; + +/** + * @brief Initialize the default sound system. + * + * This function initializes the default sound system, setting up + * necessary resources and configurations. + */ +void sound_init_default(void); -void sound_init_default (void); -void sound_init_mp3_playback (void); +/** + * @brief Initialize the MP3 playback system. + * + * This function initializes the MP3 playback system, preparing it + * for playing MP3 files. + */ +void sound_init_mp3_playback(void); + +/** + * @brief Initialize the sound effects system. + * + * This function initializes the sound effects system, setting up + * necessary resources and configurations for playing sound effects. + */ +void sound_init_sfx(void); + +/** + * @brief Enable or disable sound effects. + * @param enable True to enable sound effects, false to disable. + */ +void sound_use_sfx(bool); + +/** + * @brief Play a specified sound effect. + * @param sfx The sound effect to play, as defined in sound_effect_t. + */ +void sound_play_effect(sound_effect_t sfx); void sound_deinit (void); void sound_poll (void); - -#endif +#endif /* SOUND_H__ */ diff --git a/src/menu/ui_components.h b/src/menu/ui_components.h new file mode 100644 index 000000000..f0dc6060b --- /dev/null +++ b/src/menu/ui_components.h @@ -0,0 +1,255 @@ +/** + * @file ui_components.h + * @brief Menu Graphical User Interface Components + * @ingroup menu + */ + +#ifndef UI_COMPONENTS_H__ +#define UI_COMPONENTS_H__ + +#include +#include "menu_state.h" + + +/** + * @brief File image Enumeration. + * + * Enumeration for different types of file images used in the user interface. + */ +typedef enum { + IMAGE_BOXART_FRONT, /**< Boxart image from the front */ + IMAGE_BOXART_BACK, /**< Boxart image from the back */ + IMAGE_BOXART_TOP, /**< Boxart image from the top */ + IMAGE_BOXART_BOTTOM, /**< Boxart image from the bottom */ + IMAGE_BOXART_LEFT, /**< Boxart image from the left side */ + IMAGE_BOXART_RIGHT, /**< Boxart image from the right side */ + IMAGE_GAMEPAK_FRONT, /**< GamePak image from the front */ + IMAGE_GAMEPAK_BACK, /**< GamePak image from the back */ + IMAGE_THUMBNAIL, /**< File image thumbnail */ + IMAGE_TYPE_END /**< List end marker */ +} file_image_type_t; + +/** + * @brief Draw a box component. + * + * @param x0 Starting x-coordinate. + * @param y0 Starting y-coordinate. + * @param x1 Ending x-coordinate. + * @param y1 Ending y-coordinate. + * @param color Color of the box. + */ +void ui_components_box_draw(int x0, int y0, int x1, int y1, color_t color); + +/** + * @brief Draw a border component. + * + * @param x0 Starting x-coordinate. + * @param y0 Starting y-coordinate. + * @param x1 Ending x-coordinate. + * @param y1 Ending y-coordinate. + */ +void ui_components_border_draw(int x0, int y0, int x1, int y1); + +/** + * @brief Draw the layout component. + */ +void ui_components_layout_draw(void); + +/** + * @brief Draw a progress bar component. + * + * @param x0 Starting x-coordinate. + * @param y0 Starting y-coordinate. + * @param x1 Ending x-coordinate. + * @param y1 Ending y-coordinate. + * @param progress Progress value (0.0 to 1.0). + */ +void ui_components_progressbar_draw(int x0, int y0, int x1, int y1, float progress); + +/** + * @brief Draw a seek bar component. + * + * @param progress Progress value (0.0 to 1.0). + */ +void ui_components_seekbar_draw(float progress); + +/** + * @brief Draw a loader component. + * + * @param position Position value (0.0 to 1.0). + */ +void ui_components_loader_draw(float position); + +/** + * @brief Draw a scrollbar component. + * + * @param x Starting x-coordinate. + * @param y Starting y-coordinate. + * @param width Width of the scrollbar. + * @param height Height of the scrollbar. + * @param position Current position. + * @param items Total number of items. + * @param visible_items Number of visible items. + */ +void ui_components_scrollbar_draw(int x, int y, int width, int height, int position, int items, int visible_items); + +/** + * @brief Draw a list scrollbar component. + * + * @param position Current position. + * @param items Total number of items. + * @param visible_items Number of visible items. + */ +void ui_components_list_scrollbar_draw(int position, int items, int visible_items); + +/** + * @brief Draw a dialog component. + * + * @param width Width of the dialog. + * @param height Height of the dialog. + */ +void ui_components_dialog_draw(int width, int height); + +/** + * @brief Draw a message box component. + * + * @param fmt Format string for the message. + * @param ... Additional arguments for the format string. + */ +void ui_components_messagebox_draw(char *fmt, ...); + +/** + * @brief Draw the main text component. + * + * @param align Horizontal alignment. + * @param valign Vertical alignment. + * @param fmt Format string for the text. + * @param ... Additional arguments for the format string. + */ +void ui_components_main_text_draw(rdpq_align_t align, rdpq_valign_t valign, char *fmt, ...); + +/** + * @brief Draw the actions bar text component. + * + * @param align Horizontal alignment. + * @param valign Vertical alignment. + * @param fmt Format string for the text. + * @param ... Additional arguments for the format string. + */ +void ui_components_actions_bar_text_draw(rdpq_align_t align, rdpq_valign_t valign, char *fmt, ...); + +/** + * @brief Initialize the background component. + * + * @param cache_location Location of the cache. + */ +void ui_components_background_init(char *cache_location); + +/** + * @brief Free the background component resources. + */ +void ui_components_background_free(void); + +/** + * @brief Replace the background image. + * + * @param image New background image. + */ +void ui_components_background_replace_image(surface_t *image); + +/** + * @brief Draw the background component. + */ +void ui_components_background_draw(void); + +/** + * @brief Draw the file list component. + * + * @param list List of entries. + * @param entries Number of entries. + * @param selected Index of the selected entry. + */ +void ui_components_file_list_draw(entry_t *list, int entries, int selected); + +/** + * @brief Context menu structure. + */ +typedef struct component_context_menu { + int row_count; /**< Number of rows in the context menu */ + int row_selected; /**< Index of the selected row */ + bool hide_pending; /**< Flag to indicate if hiding is pending */ + struct component_context_menu *parent; /**< Pointer to the parent context menu */ + struct component_context_menu *submenu; /**< Pointer to the submenu */ + struct { + const char *text; /**< Text of the menu item */ + void (*action)(menu_t *menu, void *arg); /**< Action function for the menu item */ + void *arg; /**< Argument for the action function */ + struct component_context_menu *submenu; /**< Pointer to the submenu */ + } list[]; /**< List of menu items */ +} component_context_menu_t; + +#define COMPONENT_CONTEXT_MENU_LIST_END { .text = NULL } /**< End marker for the context menu list */ + +/** + * @brief Initialize the context menu component. + * + * @param cm Pointer to the context menu structure. + */ +void ui_components_context_menu_init(component_context_menu_t *cm); + +/** + * @brief Show the context menu component. + * + * @param cm Pointer to the context menu structure. + */ +void ui_components_context_menu_show(component_context_menu_t *cm); + +/** + * @brief Process the context menu component. + * + * @param menu Pointer to the menu structure. + * @param cm Pointer to the context menu structure. + * @return True if the context menu was processed, false otherwise. + */ +bool ui_components_context_menu_process(menu_t *menu, component_context_menu_t *cm); + +/** + * @brief Draw the context menu component. + * + * @param cm Pointer to the context menu structure. + */ +void ui_components_context_menu_draw(component_context_menu_t *cm); + +/** + * @brief Box Art Structure. + */ +typedef struct { + bool loading; /**< Flag to indicate if the box art is loading */ + surface_t *image; /**< Pointer to the box art image */ +} component_boxart_t; + +/** + * @brief Initialize the box art component. + * + * @param storage_prefix Prefix for the storage location. + * @param game_code Game code for the box art. + * @param current_image_view Current image view type. + * @return Pointer to the initialized box art component. + */ +component_boxart_t *ui_components_boxart_init(const char *storage_prefix, char *game_code, file_image_type_t current_image_view); + +/** + * @brief Free the box art component resources. + * + * @param b Pointer to the box art component. + */ +void ui_components_boxart_free(component_boxart_t *b); + +/** + * @brief Draw the box art component. + * + * @param b Pointer to the box art component. + */ +void ui_components_boxart_draw(component_boxart_t *b); + +#endif /* UI_COMPONENTS_H__ */ diff --git a/src/menu/components/background.c b/src/menu/ui_components/background.c similarity index 91% rename from src/menu/components/background.c rename to src/menu/ui_components/background.c index 451191079..548bc0f0c 100644 --- a/src/menu/components/background.c +++ b/src/menu/ui_components/background.c @@ -1,7 +1,7 @@ #include #include -#include "../components.h" +#include "../ui_components.h" #include "constants.h" #include "utils/fs.h" @@ -98,9 +98,6 @@ 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(); @@ -108,15 +105,13 @@ static void prepare_background (component_background_t *c) { 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(); @@ -162,7 +157,7 @@ static void display_list_free (void *arg) { } -void component_background_init (char *cache_location) { +void ui_components_background_init (char *cache_location) { if (!background) { background = calloc(1, sizeof(component_background_t)); background->cache_location = strdup(cache_location); @@ -171,7 +166,7 @@ void component_background_init (char *cache_location) { } } -void component_background_free (void) { +void ui_components_background_free (void) { if (background) { if (background->image) { surface_free(background->image); @@ -190,7 +185,7 @@ void component_background_free (void) { } } -void component_background_replace_image (surface_t *image) { +void ui_components_background_replace_image (surface_t *image) { if (!background) { return; } @@ -211,7 +206,7 @@ void component_background_replace_image (surface_t *image) { prepare_background(background); } -void component_background_draw (void) { +void ui_components_background_draw (void) { if (background && background->image_display_list) { rspq_block_run(background->image_display_list); } else { diff --git a/src/menu/ui_components/boxart.c b/src/menu/ui_components/boxart.c new file mode 100644 index 000000000..160705238 --- /dev/null +++ b/src/menu/ui_components/boxart.c @@ -0,0 +1,161 @@ +#include + +#include "../ui_components.h" +#include "../path.h" +#include "../png_decoder.h" +#include "constants.h" +#include "utils/fs.h" + + +#define BOXART_DIRECTORY "menu/boxart" + + +static void png_decoder_callback (png_err_t err, surface_t *decoded_image, void *callback_data) { + component_boxart_t *b = (component_boxart_t *) (callback_data); + b->loading = false; + b->image = decoded_image; +} + + +component_boxart_t *ui_components_boxart_init (const char *storage_prefix, char *game_code, file_image_type_t current_image_view) { + component_boxart_t *b; + char boxart_id_path[8]; + + if ((b = calloc(1, sizeof(component_boxart_t))) == NULL) { + return NULL; + } + + b->loading = true; + + path_t *path = path_init(storage_prefix, BOXART_DIRECTORY); + + sprintf(boxart_id_path, "%c/%c/%c/%c", game_code[0], game_code[1], game_code[2], game_code[3]); + path_push(path, boxart_id_path); + + if (!directory_exists(path_get(path))) { // Allow boxart to not specify the region code. + path_pop(path); + } + + if (directory_exists(path_get(path))) { + switch (current_image_view) { + case IMAGE_GAMEPAK_FRONT: + path_push(path, "gamepak_front.png"); + break; + case IMAGE_GAMEPAK_BACK: + path_push(path, "gamepak_back.png"); + break; + case IMAGE_BOXART_BACK: + path_push(path, "boxart_back.png"); + break; + case IMAGE_BOXART_LEFT: + path_push(path, "boxart_left.png"); + break; + case IMAGE_BOXART_RIGHT: + path_push(path, "boxart_right.png"); + break; + case IMAGE_BOXART_BOTTOM: + path_push(path, "boxart_bottom.png"); + break; + case IMAGE_BOXART_TOP: + path_push(path, "boxart_top.png"); + break; + default: + path_push(path, "boxart_front.png"); + break; + } + + if (file_exists(path_get(path))) { + if (png_decoder_start(path_get(path), BOXART_WIDTH_MAX, BOXART_HEIGHT_MAX, png_decoder_callback, b) == PNG_OK) { + path_free(path); + return b; + } + } + } + else { // compatibility mode + + char file_name[9]; + + // reset the directory path used for boxart. + path_free(path); + path = path_init(storage_prefix, BOXART_DIRECTORY); + + snprintf(file_name, sizeof(file_name), "%c%c%c%c.png", game_code[0], game_code[1], game_code[2], game_code[3]); + path_push(path, file_name); + + if (file_exists(path_get(path))) { + if (png_decoder_start(path_get(path), BOXART_WIDTH_MAX, BOXART_HEIGHT_MAX, png_decoder_callback, b) == PNG_OK) { + path_free(path); + return b; + } + } + + path_pop(path); + snprintf(file_name, sizeof(file_name), "%c%c%c.png", game_code[0], game_code[1], game_code[2]); + path_push(path, file_name); + + if (file_exists(path_get(path))) { + if (png_decoder_start(path_get(path), BOXART_WIDTH_MAX, BOXART_HEIGHT_MAX, png_decoder_callback, b) == PNG_OK) { + path_free(path); + return b; + } + } + else { + path_pop(path); + + snprintf(file_name, sizeof(file_name), "%c%c.png", game_code[1], game_code[2]); + path_push(path, file_name); + if (file_exists(path_get(path))) { + if (png_decoder_start(path_get(path), BOXART_WIDTH_MAX, BOXART_HEIGHT_MAX, png_decoder_callback, b) == PNG_OK) { + path_free(path); + return b; + } + } + } + } + // TODO: return default image. + + path_free(path); + free(b); + + return NULL; +} + +void ui_components_boxart_free (component_boxart_t *b) { + if (b) { + if (b->loading) { + png_decoder_abort(); + } + if (b->image) { + surface_free(b->image); + free(b->image); + } + free(b); + } +} + +void ui_components_boxart_draw (component_boxart_t *b) { + int box_x = BOXART_X; + int box_y = BOXART_Y; + + if (b && b->image && b->image->width <= BOXART_WIDTH_MAX && b->image->height <= BOXART_HEIGHT_MAX) { + rdpq_mode_push(); + rdpq_set_mode_copy(false); + if (b->image->height == BOXART_HEIGHT_MAX) { + box_x = BOXART_X_JP; + box_y = BOXART_Y_JP; + } else if (b->image->width == BOXART_WIDTH_DD && b->image->height == BOXART_HEIGHT_DD) { + box_x = BOXART_X_DD; + box_y = BOXART_Y_DD; + } + rdpq_tex_blit(b->image, box_x, box_y, NULL); + rdpq_mode_pop(); + } else { + ui_components_box_draw( + BOXART_X, + BOXART_Y, + BOXART_X + BOXART_WIDTH, + BOXART_Y + BOXART_HEIGHT, + BOXART_LOADING_COLOR + ); + } +} diff --git a/src/menu/components/common.c b/src/menu/ui_components/common.c similarity index 69% rename from src/menu/components/common.c rename to src/menu/ui_components/common.c index d0fce75f1..dec318852 100644 --- a/src/menu/components/common.c +++ b/src/menu/ui_components/common.c @@ -1,11 +1,11 @@ #include -#include "../components.h" +#include "../ui_components.h" #include "../fonts.h" #include "constants.h" -void component_box_draw (int x0, int y0, int x1, int y1, color_t color) { +void ui_components_box_draw (int x0, int y0, int x1, int y1, color_t color) { rdpq_mode_push(); rdpq_set_mode_fill(color); @@ -13,7 +13,7 @@ void component_box_draw (int x0, int y0, int x1, int y1, color_t color) { rdpq_mode_pop(); } -void component_border_draw (int x0, int y0, int x1, int y1) { +void ui_components_border_draw (int x0, int y0, int x1, int y1) { rdpq_mode_push(); rdpq_set_mode_fill(BORDER_COLOR); @@ -25,14 +25,14 @@ void component_border_draw (int x0, int y0, int x1, int y1) { rdpq_mode_pop(); } -void component_layout_draw (void) { - component_border_draw( +void ui_components_layout_draw (void) { + ui_components_border_draw( VISIBLE_AREA_X0, VISIBLE_AREA_Y0, VISIBLE_AREA_X1, VISIBLE_AREA_Y1 ); - component_box_draw( + ui_components_box_draw( VISIBLE_AREA_X0, LAYOUT_ACTIONS_SEPARATOR_Y, VISIBLE_AREA_X1, @@ -41,47 +41,47 @@ void component_layout_draw (void) { ); } -void component_progressbar_draw (int x0, int y0, int x1, int y1, float progress) { +void ui_components_progressbar_draw (int x0, int y0, int x1, int y1, float progress) { float progress_width = progress * (x1 - x0); - component_box_draw(x0, y0, x0 + progress_width, y1, PROGRESSBAR_DONE_COLOR); - component_box_draw(x0 + progress_width, y0, x1, y1, PROGRESSBAR_BG_COLOR); + ui_components_box_draw(x0, y0, x0 + progress_width, y1, PROGRESSBAR_DONE_COLOR); + ui_components_box_draw(x0 + progress_width, y0, x1, y1, PROGRESSBAR_BG_COLOR); } -void component_seekbar_draw (float position) { +void ui_components_seekbar_draw (float position) { int x0 = SEEKBAR_X; int y0 = SEEKBAR_Y; int x1 = SEEKBAR_X + SEEKBAR_WIDTH; int y1 = SEEKBAR_Y + SEEKBAR_HEIGHT; - component_border_draw(x0, y0, x1, y1); - component_progressbar_draw(x0, y0, x1, y1, position); + ui_components_border_draw(x0, y0, x1, y1); + ui_components_progressbar_draw(x0, y0, x1, y1, position); } -void component_loader_draw (float progress) { +void ui_components_loader_draw (float progress) { int x0 = LOADER_X; int y0 = LOADER_Y; int x1 = LOADER_X + LOADER_WIDTH; int y1 = LOADER_Y + LOADER_HEIGHT; - component_border_draw(x0, y0, x1, y1); - component_progressbar_draw(x0, y0, x1, y1, progress); + ui_components_border_draw(x0, y0, x1, y1); + ui_components_progressbar_draw(x0, y0, x1, y1, progress); } -void component_scrollbar_draw (int x, int y, int width, int height, int position, int items, int visible_items) { +void ui_components_scrollbar_draw (int x, int y, int width, int height, int position, int items, int visible_items) { if (items <= 1 || items <= visible_items) { - component_box_draw(x, y, x + width, y + height, SCROLLBAR_INACTIVE_COLOR); + ui_components_box_draw(x, y, x + width, y + height, SCROLLBAR_INACTIVE_COLOR); } else { int scroll_height = (int) ((visible_items / (float) (items)) * height); float scroll_position = ((position / (float) (items - 1)) * (height - scroll_height)); - component_box_draw(x, y, x + width, y + height, SCROLLBAR_BG_COLOR); - component_box_draw(x, y + scroll_position, x + width, y + scroll_position + scroll_height, SCROLLBAR_POSITION_COLOR); + ui_components_box_draw(x, y, x + width, y + height, SCROLLBAR_BG_COLOR); + ui_components_box_draw(x, y + scroll_position, x + width, y + scroll_position + scroll_height, SCROLLBAR_POSITION_COLOR); } } -void component_list_scrollbar_draw (int position, int items, int visible_items) { - component_scrollbar_draw( +void ui_components_list_scrollbar_draw (int position, int items, int visible_items) { + ui_components_scrollbar_draw( LIST_SCROLLBAR_X, LIST_SCROLLBAR_Y, LIST_SCROLLBAR_WIDTH, @@ -92,17 +92,17 @@ void component_list_scrollbar_draw (int position, int items, int visible_items) ); } -void component_dialog_draw (int width, int height) { +void ui_components_dialog_draw (int width, int height) { int x0 = DISPLAY_CENTER_X - (width / 2); int y0 = DISPLAY_CENTER_Y - (height / 2); int x1 = DISPLAY_CENTER_X + (width / 2); int y1 = DISPLAY_CENTER_Y + (height / 2); - component_border_draw(x0, y0, x1, y1); - component_box_draw(x0, y0, x1, y1, DIALOG_BG_COLOR); + ui_components_border_draw(x0, y0, x1, y1); + ui_components_box_draw(x0, y0, x1, y1, DIALOG_BG_COLOR); } -void component_messagebox_draw (char *fmt, ...) { +void ui_components_messagebox_draw (char *fmt, ...) { char buffer[512]; size_t nbytes = sizeof(buffer); @@ -126,7 +126,7 @@ void component_messagebox_draw (char *fmt, ...) { free(formatted); } - component_dialog_draw( + ui_components_dialog_draw( paragraph->bbox.x1 - paragraph->bbox.x0 + MESSAGEBOX_MARGIN, paragraph->bbox.y1 - paragraph->bbox.y0 + MESSAGEBOX_MARGIN ); @@ -136,7 +136,7 @@ void component_messagebox_draw (char *fmt, ...) { rdpq_paragraph_free(paragraph); } -void component_main_text_draw (rdpq_align_t align, rdpq_valign_t valign, char *fmt, ...) { +void ui_components_main_text_draw (rdpq_align_t align, rdpq_valign_t valign, char *fmt, ...) { char buffer[1024]; size_t nbytes = sizeof(buffer); @@ -151,7 +151,7 @@ void component_main_text_draw (rdpq_align_t align, rdpq_valign_t valign, char *f .height = LAYOUT_ACTIONS_SEPARATOR_Y - OVERSCAN_HEIGHT - (TEXT_MARGIN_VERTICAL * 2), .align = align, .valign = valign, - .wrap = WRAP_ELLIPSES, + .wrap = WRAP_WORD, .line_spacing = TEXT_LINE_SPACING_ADJUST, }, FNT_DEFAULT, @@ -166,7 +166,7 @@ void component_main_text_draw (rdpq_align_t align, rdpq_valign_t valign, char *f } } -void component_actions_bar_text_draw (rdpq_align_t align, rdpq_valign_t valign, char *fmt, ...) { +void ui_components_actions_bar_text_draw (rdpq_align_t align, rdpq_valign_t valign, char *fmt, ...) { char buffer[256]; size_t nbytes = sizeof(buffer); diff --git a/src/menu/components/constants.h b/src/menu/ui_components/constants.h similarity index 84% rename from src/menu/components/constants.h rename to src/menu/ui_components/constants.h index e4d3eb514..c468a3271 100644 --- a/src/menu/components/constants.h +++ b/src/menu/ui_components/constants.h @@ -73,10 +73,30 @@ #define BOXART_WIDTH (158) /** @brief The boxart picture height. */ #define BOXART_HEIGHT (112) + +/** @brief The boxart picture width (64DD). */ +#define BOXART_WIDTH_DD (129) +/** @brief The boxart picture height. */ +#define BOXART_HEIGHT_DD (112) + +/** @brief The boxart picture maximum width. */ +#define BOXART_WIDTH_MAX (158) +/** @brief The boxart picture maximum height. */ +#define BOXART_HEIGHT_MAX (158) + /** @brief The box art position on the X axis. */ #define BOXART_X (VISIBLE_AREA_X1 - BOXART_WIDTH - 24) /** @brief The box art position on the Y axis. */ #define BOXART_Y (LAYOUT_ACTIONS_SEPARATOR_Y - BOXART_HEIGHT - 24) +/** @brief The box art position on the X axis for japanese caratules.*/ +#define BOXART_X_JP (VISIBLE_AREA_X1 - BOXART_WIDTH_MAX + 21) +/** @brief The box art position on the Y axis for japanese caratules. */ +#define BOXART_Y_JP (LAYOUT_ACTIONS_SEPARATOR_Y - BOXART_HEIGHT_MAX - 24) + +/** @brief The box art position on the X axis for 64DD caratules.*/ +#define BOXART_X_DD (VISIBLE_AREA_X1 - BOXART_WIDTH_DD - 23) +/** @brief The box art position on the Y axis for 64DD caratules. */ +#define BOXART_Y_DD (LAYOUT_ACTIONS_SEPARATOR_Y - BOXART_HEIGHT_DD - 24) /** @brief The scroll bar width. */ #define LIST_SCROLLBAR_WIDTH (12) diff --git a/src/menu/components/context_menu.c b/src/menu/ui_components/context_menu.c similarity index 61% rename from src/menu/components/context_menu.c rename to src/menu/ui_components/context_menu.c index ff6db4dbf..b08085fcf 100644 --- a/src/menu/components/context_menu.c +++ b/src/menu/ui_components/context_menu.c @@ -1,5 +1,6 @@ -#include "../components.h" +#include "../ui_components.h" #include "../fonts.h" +#include "../sound.h" #include "constants.h" @@ -11,23 +12,23 @@ static component_context_menu_t *get_current_submenu (component_context_menu_t * } -void component_context_menu_init (component_context_menu_t *cm) { - cm->selected = -1; - cm->count = 0; +void ui_components_context_menu_init (component_context_menu_t *cm) { + cm->row_selected = -1; + cm->row_count = 0; cm->hide_pending = false; cm->parent = NULL; for (int i = 0; (cm->list[i].text) != NULL; i++) { - cm->count += 1; + cm->row_count += 1; } } -void component_context_menu_show (component_context_menu_t *cm) { - cm->selected = 0; +void ui_components_context_menu_show (component_context_menu_t *cm) { + cm->row_selected = 0; cm->submenu = NULL; } -bool component_context_menu_process (menu_t *menu, component_context_menu_t *cm) { - if (!cm || (cm->selected < 0)) { +bool ui_components_context_menu_process (menu_t *menu, component_context_menu_t *cm) { + if (!cm || (cm->row_selected < 0)) { return false; } @@ -41,33 +42,37 @@ bool component_context_menu_process (menu_t *menu, component_context_menu_t *cm) } else { cm->hide_pending = true; } + sound_play_effect(SFX_EXIT); } else if (menu->actions.enter) { - if (cm->list[cm->selected].submenu) { - cm->submenu = cm->list[cm->selected].submenu; - component_context_menu_init(cm->submenu); - cm->submenu->selected = 0; + if (cm->list[cm->row_selected].submenu) { + cm->submenu = cm->list[cm->row_selected].submenu; + ui_components_context_menu_init(cm->submenu); + cm->submenu->row_selected = 0; cm->submenu->parent = cm; - } else if (cm->list[cm->selected].action) { - cm->list[cm->selected].action(menu, cm->list[cm->selected].arg); + } else if (cm->list[cm->row_selected].action) { + cm->list[cm->row_selected].action(menu, cm->list[cm->row_selected].arg); top->hide_pending = true; } + sound_play_effect(SFX_ENTER); } else if (menu->actions.go_up) { - cm->selected -= 1; - if (cm->selected < 0) { - cm->selected = 0; + cm->row_selected -= 1; + if (cm->row_selected < 0) { + cm->row_selected = 0; } + sound_play_effect(SFX_CURSOR); } else if (menu->actions.go_down) { - cm->selected += 1; - if (cm->selected >= cm->count) { - cm->selected = (cm->count - 1); + cm->row_selected += 1; + if (cm->row_selected >= cm->row_count) { + cm->row_selected = (cm->row_count - 1); } + sound_play_effect(SFX_CURSOR); } return true; } -void component_context_menu_draw (component_context_menu_t *cm) { - if (!cm || (cm->selected < 0)) { +void ui_components_context_menu_draw (component_context_menu_t *cm) { + if (!cm || (cm->row_selected < 0)) { return; } @@ -87,7 +92,7 @@ void component_context_menu_draw (component_context_menu_t *cm) { NULL ); - for (int i = 0; i < cm->count; i++) { + for (int i = 0; i < cm->row_count; i++) { const char *text = cm->list[i].text; rdpq_paragraph_builder_span(text, strlen(text)); if (cm->list[i + 1].text != NULL) { @@ -100,14 +105,14 @@ void component_context_menu_draw (component_context_menu_t *cm) { int width = layout->bbox.x1 - layout->bbox.x0 + MESSAGEBOX_MARGIN; int height = layout->bbox.y1 - layout->bbox.y0 + MESSAGEBOX_MARGIN; - component_dialog_draw(width, height); + ui_components_dialog_draw(width, height); int highlight_x0 = DISPLAY_CENTER_X - (width / 2); int highlight_x1 = DISPLAY_CENTER_X + (width / 2); int highlight_height = (layout->bbox.y1 - layout->bbox.y0) / layout->nlines; - int highlight_y = VISIBLE_AREA_Y0 + layout->bbox.y0 + ((cm->selected) * highlight_height); + int highlight_y = VISIBLE_AREA_Y0 + layout->bbox.y0 + ((cm->row_selected) * highlight_height); - component_box_draw( + ui_components_box_draw( highlight_x0, highlight_y, highlight_x1, @@ -121,6 +126,6 @@ void component_context_menu_draw (component_context_menu_t *cm) { if (top->hide_pending) { top->hide_pending = false; - top->selected = -1; + top->row_selected = -1; } } diff --git a/src/menu/components/file_list.c b/src/menu/ui_components/file_list.c similarity index 95% rename from src/menu/components/file_list.c rename to src/menu/ui_components/file_list.c index 7a9835ce2..af10e3a09 100644 --- a/src/menu/components/file_list.c +++ b/src/menu/ui_components/file_list.c @@ -1,6 +1,6 @@ #include -#include "../components.h" +#include "../ui_components.h" #include "../fonts.h" #include "constants.h" @@ -25,7 +25,7 @@ static int format_file_size (char *buffer, int64_t size) { } -void component_file_list_draw (entry_t *list, int entries, int selected) { +void ui_components_file_list_draw (entry_t *list, int entries, int selected) { int starting_position = 0; if (entries > LIST_ENTRIES && selected >= (LIST_ENTRIES / 2)) { @@ -35,10 +35,10 @@ void component_file_list_draw (entry_t *list, int entries, int selected) { } } - component_list_scrollbar_draw(selected, entries, LIST_ENTRIES); + ui_components_list_scrollbar_draw(selected, entries, LIST_ENTRIES); if (entries == 0) { - component_main_text_draw( + ui_components_main_text_draw( ALIGN_LEFT, VALIGN_TOP, "^%02X** empty directory **", STL_GRAY @@ -117,7 +117,7 @@ void component_file_list_draw (entry_t *list, int entries, int selected) { int highlight_height = (layout->bbox.y1 - layout->bbox.y0) / layout->nlines; int highlight_y = VISIBLE_AREA_Y0 + TEXT_MARGIN_VERTICAL + TEXT_OFFSET_VERTICAL + ((selected - starting_position) * highlight_height); - component_box_draw( + ui_components_box_draw( FILE_LIST_HIGHLIGHT_X, highlight_y, FILE_LIST_HIGHLIGHT_X + FILE_LIST_HIGHLIGHT_WIDTH, diff --git a/src/menu/usb_comm.h b/src/menu/usb_comm.h index c7f9a9ed2..0b914643a 100644 --- a/src/menu/usb_comm.h +++ b/src/menu/usb_comm.h @@ -2,20 +2,36 @@ * @file usb_comm.h * @brief USB communication subsystem * @ingroup menu + * + * This file contains the declarations for the USB communication subsystem + * used in the menu system. */ #ifndef USB_COMM_H__ #define USB_COMM_H__ - #include "menu_state.h" - #ifndef NDEBUG -void usb_comm_poll (menu_t *menu); +/** + * @brief Poll the USB communication subsystem. + * + * This function polls the USB communication subsystem to handle any + * incoming or outgoing data. It is only available in debug builds. + * + * @param menu Pointer to the menu structure. + */ +void usb_comm_poll(menu_t *menu); #else +/** + * @brief Poll the USB communication subsystem (no-op in release builds). + * + * This macro is a no-op in release builds, where USB communication polling + * is disabled. + * + * @param menu Pointer to the menu structure. + */ #define usb_comm_poll(menu) #endif - -#endif +#endif /* USB_COMM_H__ */ diff --git a/src/menu/views/browser.c b/src/menu/views/browser.c index d7d518e8e..62ff21290 100644 --- a/src/menu/views/browser.c +++ b/src/menu/views/browser.c @@ -6,11 +6,12 @@ #include "../fonts.h" #include "utils/fs.h" #include "views.h" +#include "../sound.h" static const char *rom_extensions[] = { "z64", "n64", "v64", "rom", NULL }; static const char *disk_extensions[] = { "ndd", NULL }; -static const char *emulator_extensions[] = { "nes", "sfc", "smc", "gb", "gbc", "sms", "gg", "sg", NULL }; +static const char *emulator_extensions[] = { "nes", "sfc", "smc", "gb", "gbc", "sms", "gg", "sg", "chf", NULL }; // TODO: "eep", "sra", "srm", "fla" could be used if transfered from different flashcarts. static const char *save_extensions[] = { "sav", NULL }; static const char *image_extensions[] = { "png", NULL }; @@ -277,21 +278,21 @@ static void set_menu_next_mode (menu_t *menu, void *arg) { static component_context_menu_t settings_context_menu = { .list = { - { .text = "Edit settings", .action = set_menu_next_mode, .arg = (void *) (MENU_MODE_SETTINGS_EDITOR) }, - { .text = "Show system info", .action = set_menu_next_mode, .arg = (void *) (MENU_MODE_SYSTEM_INFO) }, - { .text = "Show credits", .action = set_menu_next_mode, .arg = (void *) (MENU_MODE_CREDITS) }, - { .text = "Adjust RTC", .action = set_menu_next_mode, .arg = (void *) (MENU_MODE_RTC) }, - { .text = "Show cart info", .action = set_menu_next_mode, .arg = (void *) (MENU_MODE_FLASHCART) }, + { .text = "Menu settings", .action = set_menu_next_mode, .arg = (void *) (MENU_MODE_SETTINGS_EDITOR) }, + { .text = "Time (RTC) settings", .action = set_menu_next_mode, .arg = (void *) (MENU_MODE_RTC) }, + { .text = "Menu information", .action = set_menu_next_mode, .arg = (void *) (MENU_MODE_CREDITS) }, + { .text = "Flashcart information", .action = set_menu_next_mode, .arg = (void *) (MENU_MODE_FLASHCART) }, + { .text = "N64 information", .action = set_menu_next_mode, .arg = (void *) (MENU_MODE_SYSTEM_INFO) }, COMPONENT_CONTEXT_MENU_LIST_END, } }; static void process (menu_t *menu) { - if (component_context_menu_process(menu, &entry_context_menu)) { + if (ui_components_context_menu_process(menu, &entry_context_menu)) { return; } - if (component_context_menu_process(menu, &settings_context_menu)) { + if (ui_components_context_menu_process(menu, &settings_context_menu)) { return; } @@ -303,16 +304,19 @@ static void process (menu_t *menu) { if (menu->browser.selected < 0) { menu->browser.selected = 0; } + sound_play_effect(SFX_CURSOR); } else if (menu->actions.go_down) { menu->browser.selected += scroll_speed; if (menu->browser.selected >= menu->browser.entries) { menu->browser.selected = menu->browser.entries - 1; } + sound_play_effect(SFX_CURSOR); } menu->browser.entry = &menu->browser.list[menu->browser.selected]; } if (menu->actions.enter && menu->browser.entry) { + sound_play_effect(SFX_ENTER); switch (menu->browser.entry->type) { case ENTRY_TYPE_DIR: if (push_directory(menu, menu->browser.entry->name)) { @@ -347,10 +351,13 @@ static void process (menu_t *menu) { menu->browser.valid = false; menu_show_error(menu, "Couldn't open last directory"); } + sound_play_effect(SFX_EXIT); } else if (menu->actions.options && menu->browser.entry) { - component_context_menu_show(&entry_context_menu); + ui_components_context_menu_show(&entry_context_menu); + sound_play_effect(SFX_SETTING); } else if (menu->actions.settings) { - component_context_menu_show(&settings_context_menu); + ui_components_context_menu_show(&settings_context_menu); + sound_play_effect(SFX_SETTING); } } @@ -358,11 +365,11 @@ static void process (menu_t *menu) { static void draw (menu_t *menu, surface_t *d) { rdpq_attach(d, NULL); - component_background_draw(); + ui_components_background_draw(); - component_layout_draw(); + ui_components_layout_draw(); - component_file_list_draw(menu->browser.list, menu->browser.entries, menu->browser.selected); + ui_components_file_list_draw(menu->browser.list, menu->browser.entries, menu->browser.selected); const char *action = NULL; @@ -378,7 +385,7 @@ static void draw (menu_t *menu, surface_t *d) { } } - component_actions_bar_text_draw( + ui_components_actions_bar_text_draw( ALIGN_LEFT, VALIGN_TOP, "%s\n" "^%02XB: Back^00", @@ -386,7 +393,7 @@ static void draw (menu_t *menu, surface_t *d) { path_is_root(menu->browser.directory) ? STL_GRAY : STL_DEFAULT ); - component_actions_bar_text_draw( + ui_components_actions_bar_text_draw( ALIGN_RIGHT, VALIGN_TOP, "Start: Settings\n" "^%02XR: Options^00", @@ -394,7 +401,7 @@ static void draw (menu_t *menu, surface_t *d) { ); if (menu->current_time >= 0) { - component_actions_bar_text_draw( + ui_components_actions_bar_text_draw( ALIGN_CENTER, VALIGN_TOP, "\n" "%s", @@ -402,9 +409,9 @@ static void draw (menu_t *menu, surface_t *d) { ); } - component_context_menu_draw(&entry_context_menu); + ui_components_context_menu_draw(&entry_context_menu); - component_context_menu_draw(&settings_context_menu); + ui_components_context_menu_draw(&settings_context_menu); rdpq_detach_show(); } @@ -412,8 +419,8 @@ static void draw (menu_t *menu, surface_t *d) { void view_browser_init (menu_t *menu) { if (!menu->browser.valid) { - component_context_menu_init(&entry_context_menu); - component_context_menu_init(&settings_context_menu); + ui_components_context_menu_init(&entry_context_menu); + ui_components_context_menu_init(&settings_context_menu); if (load_directory(menu)) { path_free(menu->browser.directory); menu->browser.directory = path_init(menu->storage_prefix, ""); diff --git a/src/menu/views/credits.c b/src/menu/views/credits.c index dc1d0665e..e4ddb9c32 100644 --- a/src/menu/views/credits.c +++ b/src/menu/views/credits.c @@ -1,5 +1,5 @@ #include "views.h" - +#include "../sound.h" #ifndef MENU_VERSION #define MENU_VERSION "Unknown" @@ -12,23 +12,24 @@ static void process (menu_t *menu) { if (menu->actions.back) { - menu->next_mode = MENU_MODE_BROWSER; + sound_play_effect(SFX_EXIT); + menu->next_mode = MENU_MODE_BROWSER; } } static void draw (menu_t *menu, surface_t *d) { rdpq_attach(d, NULL); - component_background_draw(); + ui_components_background_draw(); - component_layout_draw(); + ui_components_layout_draw(); - component_main_text_draw( + ui_components_main_text_draw( ALIGN_CENTER, VALIGN_TOP, "MENU INFORMATION" ); - component_main_text_draw( + ui_components_main_text_draw( ALIGN_LEFT, VALIGN_TOP, "\n" "\n" @@ -41,7 +42,7 @@ static void draw (menu_t *menu, surface_t *d) { " Robin Jones / NetworkFusion\n" " Mateusz Faderewski / Polprzewodnikowy\n" "Credits:\n" - " N64Brew / libdragon contributors\n" + " N64Brew / libDragon contributors\n" "\n" "OSS software used:\n" " libdragon (UNLICENSE License)\n" @@ -53,7 +54,7 @@ static void draw (menu_t *menu, surface_t *d) { BUILD_TIMESTAMP ); - component_actions_bar_text_draw( + ui_components_actions_bar_text_draw( ALIGN_LEFT, VALIGN_TOP, "\n" "B: Exit" diff --git a/src/menu/views/error.c b/src/menu/views/error.c index a5c0b84a3..b163f8856 100644 --- a/src/menu/views/error.c +++ b/src/menu/views/error.c @@ -1,8 +1,10 @@ #include "views.h" +#include "../sound.h" static void process (menu_t *menu) { if (menu->actions.back) { + sound_play_effect(SFX_EXIT); menu->next_mode = MENU_MODE_BROWSER; } } @@ -10,12 +12,12 @@ static void process (menu_t *menu) { static void draw (menu_t *menu, surface_t *d) { rdpq_attach(d, NULL); - component_background_draw(); + ui_components_background_draw(); if (menu->error_message) { - component_messagebox_draw(menu->error_message); + ui_components_messagebox_draw(menu->error_message); } else { - component_messagebox_draw("Unspecified error"); + ui_components_messagebox_draw("Unspecified error"); } rdpq_detach_show(); @@ -48,6 +50,7 @@ void view_error_display (menu_t *menu, surface_t *display) { } void menu_show_error (menu_t *menu, char *error_message) { + sound_play_effect(SFX_ERROR); menu->next_mode = MENU_MODE_ERROR; menu->error_message = error_message; } diff --git a/src/menu/views/fault.c b/src/menu/views/fault.c index 6ec767a4e..ee2f8c5eb 100644 --- a/src/menu/views/fault.c +++ b/src/menu/views/fault.c @@ -13,7 +13,7 @@ static void draw (menu_t *menu, surface_t *d) { "SummerCart64: 2.17.0+" ); - component_messagebox_draw( + ui_components_messagebox_draw( "UNRECOVERABLE ERROR\n" "\n" "%s\n" diff --git a/src/menu/views/file_info.c b/src/menu/views/file_info.c index 211f57914..1a979426a 100644 --- a/src/menu/views/file_info.c +++ b/src/menu/views/file_info.c @@ -1,4 +1,5 @@ #include +#include "../sound.h" #include "utils/fs.h" #include "views.h" @@ -12,8 +13,8 @@ static const char *patch_extensions[] = { "aps", "bps", "ips", "pps", "ups", "xd static const char *archive_extensions[] = { "zip", "rar", "7z", "tar", "gz", NULL }; static const char *image_extensions[] = { "png", "jpg", "gif", NULL }; static const char *music_extensions[] = { "mp3", "wav", "ogg", "wma", "flac", NULL }; -static const char *dexdrive_extensions[] = { "mpk", NULL }; -static const char *emulator_extensions[] = { "emu", NULL }; +static const char *controller_pak_extensions[] = { "mpk", "pak", NULL }; +static const char *emulator_extensions[] = { "nes", "smc", "gb", "gbc", "sms", "gg", "chf", NULL }; static struct stat st; @@ -38,10 +39,10 @@ static char *format_file_type (char *name, bool is_directory) { return " Type: Image file\n"; } else if (file_has_extensions(name, music_extensions)) { return " Type: Music file\n"; - } else if (file_has_extensions(name, dexdrive_extensions)) { - return " Type: DexDrive CPak backup file\n"; + } else if (file_has_extensions(name, controller_pak_extensions)) { + return " Type: Controller Pak file\n"; } else if (file_has_extensions(name, emulator_extensions)) { - return " Type: Emulator file\n"; + return " Type: Emulator ROM file\n"; } return " Type: Unknown file\n"; } @@ -49,6 +50,7 @@ static char *format_file_type (char *name, bool is_directory) { static void process (menu_t *menu) { if (menu->actions.back) { + sound_play_effect(SFX_EXIT); menu->next_mode = MENU_MODE_BROWSER; } } @@ -56,11 +58,11 @@ static void process (menu_t *menu) { static void draw (menu_t *menu, surface_t *d) { rdpq_attach(d, NULL); - component_background_draw(); + ui_components_background_draw(); - component_layout_draw(); + ui_components_layout_draw(); - component_main_text_draw( + ui_components_main_text_draw( ALIGN_CENTER, VALIGN_TOP, "ENTRY INFORMATION\n" "\n" @@ -68,7 +70,7 @@ static void draw (menu_t *menu, surface_t *d) { menu->browser.entry->name ); - component_main_text_draw( + ui_components_main_text_draw( ALIGN_LEFT, VALIGN_TOP, "\n" "\n" @@ -82,10 +84,10 @@ static void draw (menu_t *menu, surface_t *d) { S_ISDIR(st.st_mode) ? "Directory" : "File", st.st_mode & S_IWUSR ? "" : "(Read only)", format_file_type(menu->browser.entry->name, S_ISDIR(st.st_mode)), - ctime(&st.st_mtim.tv_sec) + ctime(&st.st_mtime) ); - component_actions_bar_text_draw( + ui_components_actions_bar_text_draw( ALIGN_LEFT, VALIGN_TOP, "\n" "B: Exit" diff --git a/src/menu/views/flashcart_info.c b/src/menu/views/flashcart_info.c index 084cc0734..64ee2060d 100644 --- a/src/menu/views/flashcart_info.c +++ b/src/menu/views/flashcart_info.c @@ -1,8 +1,41 @@ #include "views.h" +#include "../sound.h" +#include +static inline const char *format_boolean_type (bool bool_value) { + return bool_value ? "Supported" : "Unsupported"; +} + +static const char *format_cart_type () { + switch (cart_type) { + case CART_CI: + return "64drive"; + + case CART_EDX: + return "Series X EverDrive-64"; + + case CART_ED: + return "Series V EverDrive-64"; + + case CART_SC: + return "SummerCart64"; + + default: // Probably emulator + return "Emulator?"; + } +} + +static const char *format_cart_version () { + flashcart_firmware_version_t version = flashcart_get_firmware_version(); + static char buffer[16]; + sprintf(buffer, "%u.%u.%lu", version.major, version.minor, version.revision); + return buffer; +} + static void process (menu_t *menu) { if (menu->actions.back) { + sound_play_effect(SFX_EXIT); menu->next_mode = MENU_MODE_BROWSER; } } @@ -10,23 +43,49 @@ static void process (menu_t *menu) { static void draw (menu_t *menu, surface_t *d) { rdpq_attach(d, NULL); - component_background_draw(); + ui_components_background_draw(); - component_layout_draw(); + ui_components_layout_draw(); - component_main_text_draw( + ui_components_main_text_draw( ALIGN_CENTER, VALIGN_TOP, - "FLASHCART INFORMATION\n" + "FLASHCART INFORMATION" + "\n" + "\n" ); - component_main_text_draw( + ui_components_main_text_draw( ALIGN_LEFT, VALIGN_TOP, "\n" "\n" - ); + "Type:\n" + " %s\n\n" + "Firmware:\n" + " Version: %s\n\n" + "Features:\n" + " Virtual 64DD: %s.\n" + " Real Time Clock: %s.\n" + " USB Debugging: %s.\n" + " Automatic CIC: %s.\n" + " Region Detection: %s.\n" + " Save Writeback: %s.\n" + " Auto F/W Updates: %s.\n" + "\n\n", + format_cart_type(), + format_cart_version(), + format_boolean_type(flashcart_has_feature(FLASHCART_FEATURE_64DD)), + format_boolean_type(flashcart_has_feature(FLASHCART_FEATURE_RTC)), + format_boolean_type(flashcart_has_feature(FLASHCART_FEATURE_USB)), + format_boolean_type(flashcart_has_feature(FLASHCART_FEATURE_AUTO_CIC)), + format_boolean_type(flashcart_has_feature(FLASHCART_FEATURE_AUTO_REGION)), + format_boolean_type(flashcart_has_feature(FLASHCART_FEATURE_SAVE_WRITEBACK)), + format_boolean_type(flashcart_has_feature(FLASHCART_FEATURE_BIOS_UPDATE_FROM_MENU)) + //TODO: display the battery and temperature information (if available). + //format_diagnostic_data(flashcart_has_feature(FLASHCART_FEATURE_DIAGNOSTIC_DATA)) + ); - component_actions_bar_text_draw( + ui_components_actions_bar_text_draw( ALIGN_LEFT, VALIGN_TOP, "\n" "B: Back" diff --git a/src/menu/views/image_viewer.c b/src/menu/views/image_viewer.c index 21c153b31..64af16f6b 100644 --- a/src/menu/views/image_viewer.c +++ b/src/menu/views/image_viewer.c @@ -1,4 +1,5 @@ #include +#include "../sound.h" #include "../png_decoder.h" #include "views.h" @@ -40,6 +41,7 @@ static void process (menu_t *menu) { } else { menu->next_mode = MENU_MODE_BROWSER; } + sound_play_effect(SFX_EXIT); } else if (menu->actions.enter && image) { if (show_message) { show_message = false; @@ -48,6 +50,7 @@ static void process (menu_t *menu) { } else { show_message = true; } + sound_play_effect(SFX_ENTER); } } @@ -55,9 +58,9 @@ static void draw (menu_t *menu, surface_t *d) { if (!image) { rdpq_attach(d, NULL); - component_background_draw(); + ui_components_background_draw(); - component_loader_draw(png_decoder_get_progress()); + ui_components_loader_draw(png_decoder_get_progress()); } else { rdpq_attach_clear(d, NULL); @@ -70,13 +73,13 @@ static void draw (menu_t *menu, surface_t *d) { rdpq_mode_pop(); if (show_message) { - component_messagebox_draw( + ui_components_messagebox_draw( "Set \"%s\" as background image?\n\n" "A: Yes, B: Back", menu->browser.entry->name ); } else if (image_set_as_background) { - component_messagebox_draw("Preparing background…"); + ui_components_messagebox_draw("Preparing background…"); } } @@ -90,7 +93,7 @@ static void deinit (menu_t *menu) { if (image) { if (image_set_as_background) { - component_background_replace_image(image); + ui_components_background_replace_image(image); } else { surface_free(image); free(image); diff --git a/src/menu/views/load_disk.c b/src/menu/views/load_disk.c index 7216e97d2..f266021bc 100644 --- a/src/menu/views/load_disk.c +++ b/src/menu/views/load_disk.c @@ -1,11 +1,10 @@ #include "../cart_load.h" #include "../disk_info.h" #include "boot/boot.h" +#include "../sound.h" #include "views.h" - -static bool load_pending; -static bool load_rom; +static component_boxart_t *boxart; static char *convert_error_message (disk_err_t err) { @@ -29,12 +28,14 @@ static char *format_disk_region (disk_region_t region) { static void process (menu_t *menu) { if (menu->actions.enter) { - load_pending = true; - load_rom = false; - } else if (menu->actions.options && menu->load.rom_path) { - load_pending = true; - load_rom = true; + menu->boot_pending.disk_file = true; + menu->load.combined_disk_rom = false; + } else if (menu->actions.lz_context && menu->load.rom_path) { + menu->boot_pending.disk_file = true; + menu->load.combined_disk_rom = true; + sound_play_effect(SFX_SETTING); } else if (menu->actions.back) { + sound_play_effect(SFX_EXIT); menu->next_mode = MENU_MODE_BROWSER; } } @@ -42,14 +43,14 @@ static void process (menu_t *menu) { static void draw (menu_t *menu, surface_t *d) { rdpq_attach(d, NULL); - component_background_draw(); + ui_components_background_draw(); - if (load_pending) { - component_loader_draw(0.0f); + if (menu->boot_pending.disk_file) { + ui_components_loader_draw(0.0f); } else { - component_layout_draw(); + ui_components_layout_draw(); - component_main_text_draw( + ui_components_main_text_draw( ALIGN_CENTER, VALIGN_TOP, "64DD disk information\n" "\n" @@ -57,7 +58,7 @@ static void draw (menu_t *menu, surface_t *d) { menu->browser.entry->name ); - component_main_text_draw( + ui_components_main_text_draw( ALIGN_LEFT, VALIGN_TOP, "\n" "\n" @@ -77,18 +78,22 @@ static void draw (menu_t *menu, surface_t *d) { menu->load.rom_path ? path_last_get(menu->load.rom_path) : "" ); - component_actions_bar_text_draw( + ui_components_actions_bar_text_draw( ALIGN_LEFT, VALIGN_TOP, "A: Load and run 64DD disk\n" "B: Exit" ); if (menu->load.rom_path) { - component_actions_bar_text_draw( + ui_components_actions_bar_text_draw( ALIGN_RIGHT, VALIGN_TOP, - "R: Load with ROM" + "L|Z: Load with ROM\n" ); } + + if (boxart != NULL) { + ui_components_boxart_draw(boxart); + } } rdpq_detach_show(); @@ -100,9 +105,9 @@ static void draw_progress (float progress) { if (d) { rdpq_attach(d, NULL); - component_background_draw(); + ui_components_background_draw(); - component_loader_draw(progress); + ui_components_loader_draw(progress); rdpq_detach_show(); } @@ -111,7 +116,7 @@ static void draw_progress (float progress) { static void load (menu_t *menu) { cart_load_err_t err; - if (menu->load.rom_path && load_rom) { + if (menu->load.rom_path && menu->load.combined_disk_rom) { err = cart_load_n64_rom_and_save(menu, draw_progress); if (err != CART_LOAD_OK) { menu_show_error(menu, cart_load_convert_error_message(err)); @@ -127,7 +132,7 @@ static void load (menu_t *menu) { menu->next_mode = MENU_MODE_BOOT; - if (load_rom) { + if (menu->load.combined_disk_rom) { menu->boot_params->device_type = BOOT_DEVICE_TYPE_ROM; menu->boot_params->detect_cic_seed = rom_info_get_cic_seed(&menu->load.rom_info, &menu->boot_params->cic_seed); switch (rom_info_get_tv_type(&menu->load.rom_info)) { @@ -145,6 +150,9 @@ static void load (menu_t *menu) { } } +static void deinit (void) { + ui_components_boxart_free(boxart); +} void view_load_disk_init (menu_t *menu) { if (menu->load.disk_path) { @@ -152,14 +160,17 @@ void view_load_disk_init (menu_t *menu) { menu->load.disk_path = NULL; } - load_pending = false; + menu->boot_pending.disk_file = false; menu->load.disk_path = path_clone_push(menu->browser.directory, menu->browser.entry->name); disk_err_t err = disk_info_load(menu->load.disk_path, &menu->load.disk_info); if (err != DISK_OK) { menu_show_error(menu, convert_error_message(err)); + return; } + + boxart = ui_components_boxart_init(menu->storage_prefix, menu->load.disk_info.id, IMAGE_BOXART_FRONT); } void view_load_disk_display (menu_t *menu, surface_t *display) { @@ -167,8 +178,12 @@ void view_load_disk_display (menu_t *menu, surface_t *display) { draw(menu, display); - if (load_pending) { - load_pending = false; + if (menu->boot_pending.disk_file) { + menu->boot_pending.disk_file = false; load(menu); } + + if (menu->next_mode != MENU_MODE_LOAD_DISK) { + deinit(); + } } diff --git a/src/menu/views/load_emulator.c b/src/menu/views/load_emulator.c index 60f8d114f..b4e2c1b37 100644 --- a/src/menu/views/load_emulator.c +++ b/src/menu/views/load_emulator.c @@ -1,6 +1,7 @@ #include "../cart_load.h" #include "boot/boot.h" #include "utils/fs.h" +#include "../sound.h" #include "views.h" @@ -9,8 +10,8 @@ static const char *emu_snes_rom_extensions[] = { "sfc", "smc", NULL }; static const char *emu_gameboy_rom_extensions[] = { "gb", NULL }; static const char *emu_gameboy_color_rom_extensions[] = { "gbc", NULL }; static const char *emu_sega_8bit_rom_extensions[] = { "sms", "gg", "sg", NULL }; +static const char *emu_fairchild_channelf_rom_extensions[] = { "chf", NULL }; -static bool load_pending; static cart_load_emu_type_t emu_type; static char *format_emulator_name (cart_load_emu_type_t emulator_info) { @@ -25,6 +26,8 @@ static char *format_emulator_name (cart_load_emu_type_t emulator_info) { return "Nintendo GAMEBOY Color"; case CART_LOAD_EMU_TYPE_SEGA_GENERIC_8BIT: return "SEGA 8bit system"; + case CART_LOAD_EMU_TYPE_FAIRCHILD_CHANNELF: + return "Fairchild Channel F"; default: return "Unknown"; } @@ -33,8 +36,9 @@ static char *format_emulator_name (cart_load_emu_type_t emulator_info) { static void process (menu_t *menu) { if (menu->actions.enter) { - load_pending = true; + menu->boot_pending.emulator_file = true; } else if (menu->actions.back) { + sound_play_effect(SFX_EXIT); menu->next_mode = MENU_MODE_BROWSER; } } @@ -42,19 +46,19 @@ static void process (menu_t *menu) { static void draw (menu_t *menu, surface_t *d) { rdpq_attach(d, NULL); - component_background_draw(); + ui_components_background_draw(); - if (load_pending) { - component_loader_draw(0.0f); + if (menu->boot_pending.emulator_file) { + ui_components_loader_draw(0.0f); } else { - component_layout_draw(); + ui_components_layout_draw(); - component_main_text_draw( + ui_components_main_text_draw( ALIGN_CENTER, VALIGN_TOP, "Load Emulated ROM\n" ); - component_main_text_draw( + ui_components_main_text_draw( ALIGN_LEFT, VALIGN_TOP, "\n" "\n" @@ -64,7 +68,7 @@ static void draw (menu_t *menu, surface_t *d) { menu->browser.entry->name ); - component_actions_bar_text_draw( + ui_components_actions_bar_text_draw( ALIGN_LEFT, VALIGN_TOP, "A: Load and run Emulated ROM\n" "B: Exit" @@ -80,9 +84,9 @@ static void draw_progress (float progress) { if (d) { rdpq_attach(d, NULL); - component_background_draw(); + ui_components_background_draw(); - component_loader_draw(progress); + ui_components_loader_draw(progress); rdpq_detach_show(); } @@ -105,7 +109,7 @@ static void load (menu_t *menu) { void view_load_emulator_init (menu_t *menu) { - load_pending = false; + menu->boot_pending.emulator_file = false; path_t *path = path_clone_push(menu->browser.directory, menu->browser.entry->name); @@ -119,6 +123,8 @@ void view_load_emulator_init (menu_t *menu) { emu_type = CART_LOAD_EMU_TYPE_GAMEBOY_COLOR; } else if (file_has_extensions(path_get(path), emu_sega_8bit_rom_extensions)) { emu_type = CART_LOAD_EMU_TYPE_SEGA_GENERIC_8BIT; + } else if (file_has_extensions(path_get(path), emu_fairchild_channelf_rom_extensions)) { + emu_type = CART_LOAD_EMU_TYPE_FAIRCHILD_CHANNELF; } else { menu_show_error(menu, "Unsupported ROM"); } @@ -131,8 +137,8 @@ void view_load_emulator_display (menu_t *menu, surface_t *display) { draw(menu, display); - if (load_pending) { - load_pending = false; + if (menu->boot_pending.emulator_file) { + menu->boot_pending.emulator_file = false; load(menu); } } diff --git a/src/menu/views/load_rom.c b/src/menu/views/load_rom.c index dc95ab7f1..fb95003fe 100644 --- a/src/menu/views/load_rom.c +++ b/src/menu/views/load_rom.c @@ -1,13 +1,14 @@ #include "../cart_load.h" #include "../rom_info.h" #include "boot/boot.h" +#include "../sound.h" #include "views.h" +#include +#include "utils/fs.h" - -static bool load_pending; +static bool show_extra_info_message = false; static component_boxart_t *boxart; - static char *convert_error_message (rom_err_t err) { switch (err) { case ROM_ERR_LOAD_IO: return "I/O error during loading ROM information and/or options"; @@ -65,16 +66,16 @@ static const char *format_rom_destination_market (rom_destination_type_t market_ } } -static const char *format_rom_save_type (rom_save_type_t save_type) { +static const char *format_rom_save_type (rom_save_type_t save_type, bool supports_cpak) { switch (save_type) { - case SAVE_TYPE_NONE: return "None"; - case SAVE_TYPE_EEPROM_4KBIT: return "EEPROM 4kbit"; - case SAVE_TYPE_EEPROM_16KBIT: return "EEPROM 16kbit"; - case SAVE_TYPE_SRAM_256KBIT: return "SRAM 256kbit"; - case SAVE_TYPE_SRAM_BANKED: return "SRAM 768kbit / 3 banks"; - case SAVE_TYPE_SRAM_1MBIT: return "SRAM 1Mbit"; - case SAVE_TYPE_FLASHRAM_1MBIT: return "FlashRAM 1Mbit"; - case SAVE_TYPE_FLASHRAM_PKST2: return "FlashRAM (Pokemon Stadium 2)"; + case SAVE_TYPE_NONE: return supports_cpak ? "Controller PAK" : "None"; + case SAVE_TYPE_EEPROM_4KBIT: return supports_cpak ? "EEPROM 4kbit | Controller PAK" : "EEPROM 4kbit"; + case SAVE_TYPE_EEPROM_16KBIT: return supports_cpak ? "EEPROM 16kbit | Controller PAK" : "EEPROM 16kbit"; + case SAVE_TYPE_SRAM_256KBIT: return supports_cpak ? "SRAM 256kbit | Controller PAK" : "SRAM 256kbit"; + case SAVE_TYPE_SRAM_BANKED: return supports_cpak ? "SRAM 768kbit / 3 banks | Controller PAK" : "SRAM 768kbit / 3 banks"; + case SAVE_TYPE_SRAM_1MBIT: return supports_cpak ? "SRAM 1Mbit | Controller PAK" : "SRAM 1Mbit"; + case SAVE_TYPE_FLASHRAM_1MBIT: return supports_cpak ? "FlashRAM 1Mbit | Controller PAK" : "FlashRAM 1Mbit"; + case SAVE_TYPE_FLASHRAM_PKST2: return supports_cpak ? "FlashRAM (Pokemon Stadium 2) | Controller PAK" : "FlashRAM (Pokemon Stadium 2)"; default: return "Unknown"; } } @@ -144,6 +145,17 @@ static void set_tv_type (menu_t *menu, void *arg) { menu->browser.reload = true; } +static void set_autoload_type (menu_t *menu, void *arg) { + free(menu->settings.rom_autoload_path); + menu->settings.rom_autoload_path = strdup(strip_fs_prefix(path_get(menu->browser.directory))); + free(menu->settings.rom_autoload_filename); + menu->settings.rom_autoload_filename = strdup(menu->browser.entry->name); + // FIXME: add a confirmation box here! (press start on reboot) + menu->settings.rom_autoload_enabled = true; + settings_save(&menu->settings); + menu->browser.reload = true; +} + static component_context_menu_t set_cic_type_context_menu = { .list = { {.text = "Automatic", .action = set_cic_type, .arg = (void *) (ROM_CIC_TYPE_AUTOMATIC) }, {.text = "CIC-6101", .action = set_cic_type, .arg = (void *) (ROM_CIC_TYPE_6101) }, @@ -186,34 +198,44 @@ static component_context_menu_t options_context_menu = { .list = { { .text = "Set CIC Type", .submenu = &set_cic_type_context_menu }, { .text = "Set Save Type", .submenu = &set_save_type_context_menu }, { .text = "Set TV Type", .submenu = &set_tv_type_context_menu }, + { .text = "Set ROM to autoload", .action = set_autoload_type }, COMPONENT_CONTEXT_MENU_LIST_END, }}; static void process (menu_t *menu) { - if (component_context_menu_process(menu, &options_context_menu)) { + if (ui_components_context_menu_process(menu, &options_context_menu)) { return; } if (menu->actions.enter) { - load_pending = true; + menu->boot_pending.rom_file = true; } else if (menu->actions.back) { + sound_play_effect(SFX_EXIT); menu->next_mode = MENU_MODE_BROWSER; } else if (menu->actions.options) { - component_context_menu_show(&options_context_menu); + ui_components_context_menu_show(&options_context_menu); + sound_play_effect(SFX_SETTING); + } else if (menu->actions.lz_context) { + if (show_extra_info_message) { + show_extra_info_message = false; + } else { + show_extra_info_message = true; + } + sound_play_effect(SFX_SETTING); } } static void draw (menu_t *menu, surface_t *d) { rdpq_attach(d, NULL); - component_background_draw(); + ui_components_background_draw(); - if (load_pending) { - component_loader_draw(0.0f); + if (menu->boot_pending.rom_file) { + ui_components_loader_draw(0.0f); } else { - component_layout_draw(); + ui_components_layout_draw(); - component_main_text_draw( + ui_components_main_text_draw( ALIGN_CENTER, VALIGN_TOP, "N64 ROM information\n" "\n" @@ -221,57 +243,70 @@ static void draw (menu_t *menu, surface_t *d) { menu->browser.entry->name ); - component_main_text_draw( + ui_components_main_text_draw( ALIGN_LEFT, VALIGN_TOP, "\n" "\n" "\n" "\n" - " Endianness: %s\n" - " Title: %.20s\n" - " Game code: %c%c%c%c\n" - " Media type: %s\n" - " Destination market: %s\n" - " Version: %hhu\n" - " Check code: 0x%016llX\n" - " Save type: %s\n" - " TV type: %s\n" - " Expansion PAK: %s\n" - " CIC: %s\n" - " Boot address: 0x%08lX\n" - " SDK version: %.1f%c\n" - " Clock Rate: %.2fMHz\n", - format_rom_endianness(menu->load.rom_info.endianness), - menu->load.rom_info.title, - menu->load.rom_info.game_code[0], menu->load.rom_info.game_code[1], menu->load.rom_info.game_code[2], menu->load.rom_info.game_code[3], - format_rom_media_type(menu->load.rom_info.category_code), - format_rom_destination_market(menu->load.rom_info.destination_code), - menu->load.rom_info.version, - menu->load.rom_info.check_code, - format_rom_save_type(rom_info_get_save_type(&menu->load.rom_info)), - format_rom_tv_type(rom_info_get_tv_type(&menu->load.rom_info)), + "Description:\n None.\n\n\n\n\n\n\n\n" + "Expansion PAK: %s\n" + "TV type: %s\n" + "CIC: %s\n" + "GS/AR Cheats: Off\n" + "Patches: Off\n" + "Save type: %s\n", format_rom_expansion_pak_info(menu->load.rom_info.features.expansion_pak), + format_rom_tv_type(rom_info_get_tv_type(&menu->load.rom_info)), format_cic_type(rom_info_get_cic_type(&menu->load.rom_info)), - menu->load.rom_info.boot_address, - (menu->load.rom_info.libultra.version / 10.0f), menu->load.rom_info.libultra.revision, - menu->load.rom_info.clock_rate + format_rom_save_type(rom_info_get_save_type(&menu->load.rom_info), menu->load.rom_info.features.controller_pak) ); - component_actions_bar_text_draw( + ui_components_actions_bar_text_draw( ALIGN_LEFT, VALIGN_TOP, "A: Load and run ROM\n" - "B: Exit" + "B: Back" ); - component_actions_bar_text_draw( + ui_components_actions_bar_text_draw( ALIGN_RIGHT, VALIGN_TOP, - "\n" - "R: Options" + "L|Z: Extra Info\n" + "R: Options" ); - component_boxart_draw(boxart); - - component_context_menu_draw(&options_context_menu); + if (boxart != NULL) { + ui_components_boxart_draw(boxart); + } + + if (show_extra_info_message) { + ui_components_messagebox_draw( + "EXTRA ROM INFO\n" + "\n" + "Endianness: %s\n" + "Title: %.20s\n" + "Game code: %c%c%c%c\n" + "Media type: %s\n" + "Variant: %s\n" + "Version: %hhu\n" + "Check code: 0x%016llX\n" + "Boot address: 0x%08lX\n" + "SDK version: %.1f%c\n" + "Clock Rate: %.2fMHz\n\n\n" + "Press L|Z to return.\n", + format_rom_endianness(menu->load.rom_info.endianness), + menu->load.rom_info.title, + menu->load.rom_info.game_code[0], menu->load.rom_info.game_code[1], menu->load.rom_info.game_code[2], menu->load.rom_info.game_code[3], + format_rom_media_type(menu->load.rom_info.category_code), + format_rom_destination_market(menu->load.rom_info.destination_code), + menu->load.rom_info.version, + menu->load.rom_info.check_code, + menu->load.rom_info.boot_address, + (menu->load.rom_info.libultra.version / 10.0f), menu->load.rom_info.libultra.revision, + menu->load.rom_info.clock_rate + ); + } + + ui_components_context_menu_draw(&options_context_menu); } rdpq_detach_show(); @@ -283,9 +318,9 @@ static void draw_progress (float progress) { if (d) { rdpq_attach(d, NULL); - component_background_draw(); + ui_components_background_draw(); - component_loader_draw(progress); + ui_components_loader_draw(progress); rdpq_detach_show(); } @@ -313,19 +348,20 @@ static void load (menu_t *menu) { } static void deinit (void) { - component_boxart_free(boxart); + ui_components_boxart_free(boxart); + boxart = NULL; } void view_load_rom_init (menu_t *menu) { - load_pending = false; + if (!menu->settings.rom_autoload_enabled) { + if (menu->load.rom_path) { + path_free(menu->load.rom_path); + } - if (menu->load.rom_path) { - path_free(menu->load.rom_path); + menu->load.rom_path = path_clone_push(menu->browser.directory, menu->browser.entry->name); } - menu->load.rom_path = path_clone_push(menu->browser.directory, menu->browser.entry->name); - rom_err_t err = rom_info_load(menu->load.rom_path, &menu->load.rom_info); if (err != ROM_OK) { path_free(menu->load.rom_path); @@ -334,9 +370,10 @@ void view_load_rom_init (menu_t *menu) { return; } - boxart = component_boxart_init(menu->storage_prefix, menu->load.rom_info.game_code); - - component_context_menu_init(&options_context_menu); + if (!menu->settings.rom_autoload_enabled) { + boxart = ui_components_boxart_init(menu->storage_prefix, menu->load.rom_info.game_code, IMAGE_BOXART_FRONT); + ui_components_context_menu_init(&options_context_menu); + } } void view_load_rom_display (menu_t *menu, surface_t *display) { @@ -344,8 +381,8 @@ void view_load_rom_display (menu_t *menu, surface_t *display) { draw(menu, display); - if (load_pending) { - load_pending = false; + if (menu->boot_pending.rom_file) { + menu->boot_pending.rom_file = false; load(menu); } diff --git a/src/menu/views/music_player.c b/src/menu/views/music_player.c index 7b3d9751e..b2dde5975 100644 --- a/src/menu/views/music_player.c +++ b/src/menu/views/music_player.c @@ -41,12 +41,14 @@ static void process (menu_t *menu) { if (err != MP3PLAYER_OK) { menu_show_error(menu, convert_error_message(err)); } else if (menu->actions.back) { + sound_play_effect(SFX_EXIT); menu->next_mode = MENU_MODE_BROWSER; } else if (menu->actions.enter) { err = mp3player_toggle(); if (err != MP3PLAYER_OK) { menu_show_error(menu, convert_error_message(err)); } + sound_play_effect(SFX_ENTER); } else if (menu->actions.go_left || menu->actions.go_right) { int seconds = menu->actions.go_fast ? SEEK_SECONDS_FAST : SEEK_SECONDS; err = mp3player_seek(menu->actions.go_left ? (-seconds) : seconds); @@ -59,13 +61,13 @@ static void process (menu_t *menu) { static void draw (menu_t *menu, surface_t *d) { rdpq_attach(d, NULL); - component_background_draw(); + ui_components_background_draw(); - component_layout_draw(); + ui_components_layout_draw(); - component_seekbar_draw(mp3player_get_progress()); + ui_components_seekbar_draw(mp3player_get_progress()); - component_main_text_draw( + ui_components_main_text_draw( ALIGN_CENTER, VALIGN_TOP, "MUSIC PLAYER\n" "\n" @@ -81,7 +83,7 @@ static void draw (menu_t *menu, surface_t *d) { mp3player_get_duration() ); - component_main_text_draw( + ui_components_main_text_draw( ALIGN_LEFT, VALIGN_TOP, "\n" "\n" @@ -100,7 +102,7 @@ static void draw (menu_t *menu, surface_t *d) { mp3player_get_samplerate() ); - component_actions_bar_text_draw( + ui_components_actions_bar_text_draw( ALIGN_LEFT, VALIGN_TOP, "A: %s\n" "B: Exit | Left / Right: Rewind / Fast forward", diff --git a/src/menu/views/rtc.c b/src/menu/views/rtc.c index caeb9305b..3becf6c46 100644 --- a/src/menu/views/rtc.c +++ b/src/menu/views/rtc.c @@ -1,63 +1,242 @@ -#include +#include +#include +#include +#include +#include "../sound.h" #include "views.h" -// FIXME: add implementation! -// struct { -// uint16_t seconds; -// uint16_t minutes; -// uint16_t hours; -// uint16_t day; -// uint16_t month; -// uint16_t year; -// } adjusted_datetime; +#define MAX(a,b) (((a) > (b)) ? (a) : (b)) +#define MIN(a,b) (((a) < (b)) ? (a) : (b)) +#define CLAMP(x, min, max) (MIN(MAX((x), (min)), (max))) -// static void save_adjusted_datetime () { +#define YEAR_MIN 1996 +#define YEAR_MAX 2095 -// } +typedef enum { + RTC_EDIT_YEAR, + RTC_EDIT_MONTH, + RTC_EDIT_DAY, + RTC_EDIT_HOUR, + RTC_EDIT_MIN, + RTC_EDIT_SEC, +} rtc_field_t; + +static const char* const DAYS_OF_WEEK[7] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; + +static struct tm rtc_tm = {0}; +static bool is_editing_mode; +static rtc_field_t editing_field_type; + +int wrap( int val, uint16_t min, uint16_t max ) { + if( val < min ) return max; + if( val > max ) return min; + return val; +} + +rtc_time_t rtc_time_from_tm( struct tm *time ) { + return(rtc_time_t){ + .year = CLAMP(time->tm_year + 1900, YEAR_MIN, YEAR_MAX), + .month = CLAMP(time->tm_mon, 1, 12), + .day = CLAMP(time->tm_mday, 1, 31), + .hour = CLAMP(time->tm_hour, 0, 23), + .min = CLAMP(time->tm_min, 0, 59), + .sec = CLAMP(time->tm_sec, 0, 59), + .week_day = CLAMP(time->tm_wday, 0, 6), + }; +} + +void adjust_rtc_time( struct tm *t, int incr ) { + switch(editing_field_type) + { + case RTC_EDIT_YEAR: + t->tm_year = wrap( t->tm_year + incr, YEAR_MIN - 1900, YEAR_MAX - 1900 ); + break; + case RTC_EDIT_MONTH: + t->tm_mon = wrap( t->tm_mon + incr, 0, 11 ); + break; + case RTC_EDIT_DAY: + t->tm_mday = wrap( t->tm_mday + incr, 1, 31 ); + break; + case RTC_EDIT_HOUR: + t->tm_hour = wrap( t->tm_hour + incr, 0, 23 ); + break; + case RTC_EDIT_MIN: + t->tm_min = wrap( t->tm_min + incr, 0, 59 ); + break; + case RTC_EDIT_SEC: + t->tm_sec = wrap( t->tm_sec + incr, 0, 59 ); + break; + } + // Recalculate day-of-week and day-of-year + time_t timestamp = mktime( t ); + *t = *gmtime( ×tamp ); +} + +void rtc_ui_component_editdatetime_draw ( struct tm t, rtc_field_t selected_field ) { + // FIXME: move this to ui_components.c once improved. + /* Format RTC date/time as strings */ + char full_dt[30]; + char current_selection_chars[30]; + + snprintf( full_dt, sizeof(full_dt), ">%04d|%02d|%02d|%02d|%02d|%02d< %s", + t.tm_year + 1900, + t.tm_mon + 1, + t.tm_mday, + t.tm_hour, + t.tm_min, + t.tm_sec, + DAYS_OF_WEEK[t.tm_wday] + ); + + switch(selected_field) + { + // Note: for what ever reason, hat chars need to be duplicated to display correctly. This will be solved when there is a decent UI for it. + case RTC_EDIT_YEAR: + snprintf( current_selection_chars, sizeof(current_selection_chars), "*^^^^^^^^********************"); + break; + case RTC_EDIT_MONTH: + snprintf( current_selection_chars, sizeof(current_selection_chars), "******^^^^*****************"); + break; + case RTC_EDIT_DAY: + snprintf( current_selection_chars, sizeof(current_selection_chars), "*********^^^^**************"); + break; + case RTC_EDIT_HOUR: + snprintf( current_selection_chars, sizeof(current_selection_chars), "************^^^^***********"); + break; + case RTC_EDIT_MIN: + snprintf( current_selection_chars, sizeof(current_selection_chars), "***************^^^^********"); + break; + case RTC_EDIT_SEC: + snprintf( current_selection_chars, sizeof(current_selection_chars), "******************^^^^*****"); + break; + } + ui_components_messagebox_draw( + "|YYYY|MM|DD|HH|MM|SS| DOW\n%s\n%s\n", full_dt, current_selection_chars); +} static void process (menu_t *menu) { - if (menu->actions.back) { + if (menu->actions.back && !is_editing_mode) { + sound_play_effect(SFX_EXIT); menu->next_mode = MENU_MODE_BROWSER; } + else if (menu->actions.enter && !is_editing_mode && menu->current_time >= 0) { + rtc_tm = *gmtime(&menu->current_time); + is_editing_mode = true; + } + + if (is_editing_mode) { + if (menu->actions.go_left) { + if ( editing_field_type <= RTC_EDIT_YEAR ) { editing_field_type = RTC_EDIT_SEC; } + else { editing_field_type = editing_field_type - 1; } + } + else if (menu->actions.go_right) { + if ( editing_field_type >= RTC_EDIT_SEC ) { editing_field_type = RTC_EDIT_YEAR; } + else { editing_field_type = editing_field_type + 1; } + } + else if (menu->actions.go_up) { + adjust_rtc_time( &rtc_tm, +1 ); + } + else if (menu->actions.go_down) { + adjust_rtc_time( &rtc_tm, -1 ); + } + else if (menu->actions.options) { // R button = save + if(rtc_is_writable()) { + // FIXME: settimeofday is not available in libdragon yet. + // struct timeval new_time = { .tv_sec = mktime(&rtc_tm) }; + // int res = settimeofday(&new_time, NULL); + + rtc_time_t rtc_time = rtc_time_from_tm(&rtc_tm); + int res = rtc_set(&rtc_time); + if (res != 1) { + menu_show_error(menu, "Failed to set RTC time"); + } + } + else { + menu_show_error(menu, "RTC is not writable"); + } + is_editing_mode = false; + } + else if (menu->actions.back) { // cancel + is_editing_mode = false; + } + } } static void draw (menu_t *menu, surface_t *d) { rdpq_attach(d, NULL); - component_background_draw(); + ui_components_background_draw(); - component_layout_draw(); + ui_components_layout_draw(); - component_main_text_draw( - ALIGN_CENTER, VALIGN_TOP, - "ADJUST REAL TIME CLOCK\n" - "\n" - "\n" - "To set the date and time, please use the PC terminal\n" - "application and set via USB.\n\n" - "Current date & time: %s\n", - menu->current_time >= 0 ? ctime(&menu->current_time) : "Unknown\n" - ); + if (!is_editing_mode) { + if( menu->current_time >= 0 ) { - component_main_text_draw( - ALIGN_LEFT, VALIGN_TOP, - "\n" - "\n" - ); + ui_components_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" + ); + ui_components_actions_bar_text_draw( + ALIGN_LEFT, VALIGN_TOP, + "A: Adjust time\n" + "B: Back" + ); + } + else { - component_actions_bar_text_draw( - ALIGN_LEFT, VALIGN_TOP, - "\n" // "A: Save\n" - "B: Back" - ); + ui_components_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" + ); + + ui_components_actions_bar_text_draw( + ALIGN_LEFT, VALIGN_TOP, + "\n" + "B: Back" + ); + } + } + else { + ui_components_actions_bar_text_draw( + ALIGN_RIGHT, VALIGN_TOP, + "Up/Down: Adjust Field\n" + "Left/Right: Switch Field" + ); + ui_components_actions_bar_text_draw( + ALIGN_LEFT, VALIGN_TOP, + "R: Save\n" + "B: Back" + ); + } + + if (is_editing_mode) { + rtc_ui_component_editdatetime_draw(rtc_tm, editing_field_type); + } rdpq_detach_show(); } void view_rtc_init (menu_t *menu) { - // Nothing to initialize (yet) + is_editing_mode = false; + editing_field_type = RTC_EDIT_YEAR; } void view_rtc_display (menu_t *menu, surface_t *display) { diff --git a/src/menu/views/settings_editor.c b/src/menu/views/settings_editor.c index 5e9d18546..a5c3accaa 100644 --- a/src/menu/views/settings_editor.c +++ b/src/menu/views/settings_editor.c @@ -1,3 +1,6 @@ +#include +#include "../sound.h" +#include "../settings.h" #include "views.h" @@ -8,9 +11,110 @@ static const char *format_switch (bool state) { } } +static void set_protected_entries_type (menu_t *menu, void *arg) { + menu->settings.show_protected_entries = (bool)(uintptr_t)(arg); + settings_save(&menu->settings); + + menu->browser.reload = true; +} + +static void set_use_saves_folder_type (menu_t *menu, void *arg) { + menu->settings.use_saves_folder = (bool)(uintptr_t)(arg); + settings_save(&menu->settings); +} + +static void set_soundfx_enabled_type (menu_t *menu, void *arg) { + menu->settings.soundfx_enabled = (bool)(uintptr_t)(arg); + sound_use_sfx(menu->settings.soundfx_enabled); + settings_save(&menu->settings); +} + +#ifdef BETA_SETTINGS +static void set_pal60_type (menu_t *menu, void *arg) { + menu->settings.pal60_enabled = (bool)(uintptr_t)(arg); + settings_save(&menu->settings); +} + +static void set_bgm_enabled_type (menu_t *menu, void *arg) { + menu->settings.bgm_enabled = (bool)(uintptr_t)(arg); + settings_save(&menu->settings); +} + +static void set_rumble_enabled_type (menu_t *menu, void *arg) { + menu->settings.rumble_enabled = (bool)(uintptr_t)(arg); + settings_save(&menu->settings); +} + +// static void set_use_default_settings (menu_t *menu, void *arg) { +// // FIXME: add implementation +// menu->browser.reload = true; +// } +#endif + + +static component_context_menu_t set_protected_entries_type_context_menu = { .list = { + {.text = "On", .action = set_protected_entries_type, .arg = (void *)(uintptr_t)(true) }, + {.text = "Off", .action = set_protected_entries_type, .arg = (void *)(uintptr_t)(false) }, + COMPONENT_CONTEXT_MENU_LIST_END, +}}; + +static component_context_menu_t set_soundfx_enabled_type_context_menu = { .list = { + {.text = "On", .action = set_soundfx_enabled_type, .arg = (void *)(uintptr_t)(true) }, + {.text = "Off", .action = set_soundfx_enabled_type, .arg = (void *)(uintptr_t)(false) }, + COMPONENT_CONTEXT_MENU_LIST_END, +}}; + +static component_context_menu_t set_use_saves_folder_type_context_menu = { .list = { + {.text = "On", .action = set_use_saves_folder_type, .arg = (void *)(uintptr_t)(true) }, + {.text = "Off", .action = set_use_saves_folder_type, .arg = (void *)(uintptr_t)(false) }, + COMPONENT_CONTEXT_MENU_LIST_END, +}}; + +#ifdef BETA_SETTINGS +static component_context_menu_t set_pal60_type_context_menu = { .list = { + {.text = "On", .action = set_pal60_type, .arg = (void *)(uintptr_t)(true) }, + {.text = "Off", .action = set_pal60_type, .arg = (void *) (false) }, + COMPONENT_CONTEXT_MENU_LIST_END, +}}; + +static component_context_menu_t set_bgm_enabled_type_context_menu = { .list = { + {.text = "On", .action = set_bgm_enabled_type, .arg = (void *)(uintptr_t)(true) }, + {.text = "Off", .action = set_bgm_enabled_type, .arg = (void *)(uintptr_t)(false) }, + COMPONENT_CONTEXT_MENU_LIST_END, +}}; + +static component_context_menu_t set_rumble_enabled_type_context_menu = { .list = { + {.text = "On", .action = set_rumble_enabled_type, .arg = (void *)(uintptr_t)(true) }, + {.text = "Off", .action = set_rumble_enabled_type, .arg = (void *)(uintptr_t)(false) }, + COMPONENT_CONTEXT_MENU_LIST_END, +}}; +#endif + +static component_context_menu_t options_context_menu = { .list = { + { .text = "Show Hidden Files", .submenu = &set_protected_entries_type_context_menu }, + { .text = "Sound Effects", .submenu = &set_soundfx_enabled_type_context_menu }, + { .text = "Use Saves Folder", .submenu = &set_use_saves_folder_type_context_menu }, +#ifdef BETA_SETTINGS + { .text = "PAL60 Mode", .submenu = &set_pal60_type_context_menu }, + { .text = "Background Music", .submenu = &set_bgm_enabled_type_context_menu }, + { .text = "Rumble Feedback", .submenu = &set_rumble_enabled_type_context_menu }, + // { .text = "Restore Defaults", .action = set_use_default_settings }, +#endif + + COMPONENT_CONTEXT_MENU_LIST_END, +}}; + static void process (menu_t *menu) { - if (menu->actions.back) { + if (ui_components_context_menu_process(menu, &options_context_menu)) { + return; + } + + if (menu->actions.enter) { + ui_components_context_menu_show(&options_context_menu); + sound_play_effect(SFX_SETTING); + } else if (menu->actions.back) { + sound_play_effect(SFX_EXIT); menu->next_mode = MENU_MODE_BROWSER; } } @@ -18,50 +122,63 @@ static void process (menu_t *menu) { static void draw (menu_t *menu, surface_t *d) { rdpq_attach(d, NULL); - component_background_draw(); + ui_components_background_draw(); - component_layout_draw(); + ui_components_layout_draw(); - component_main_text_draw( + ui_components_main_text_draw( ALIGN_CENTER, VALIGN_TOP, - "SETTINGS EDITOR\n" + "MENU SETTINGS EDITOR\n" "\n" ); - component_main_text_draw( + ui_components_main_text_draw( ALIGN_LEFT, VALIGN_TOP, - "\n" - "\n" - "To change the settings, please adjust them\n" - "directly in the 'menu/config.ini' file.\n\n" - "pal60_enabled: %s\n" - "show_protected_entries: %s\n" - "default_directory: %s\n" - "use_saves_folder: %s\n" - "bgm_enabled: %s\n" - "sound_enabled: %s\n" - "rumble_enabled: %s\n", - format_switch(menu->settings.pal60_enabled), - format_switch(menu->settings.show_protected_entries), + "\n\n" + " Default Directory : %s\n\n" + " Autoload ROM : %s\n\n" + "To change the following menu settings, press 'A':\n" + " Show Hidden Files : %s\n" + " Use Saves folder : %s\n" + " Sound Effects : %s\n" +#ifdef BETA_SETTINGS + "* PAL60 Mode : %s\n" + " Background Music : %s\n" + " Rumble Feedback : %s\n" + "\n\n" + "Note: Certain settings have the following caveats:\n" + "* Requires rebooting the N64 Console.\n" +#endif + , menu->settings.default_directory, + format_switch(menu->settings.rom_autoload_enabled), + format_switch(menu->settings.show_protected_entries), format_switch(menu->settings.use_saves_folder), + format_switch(menu->settings.soundfx_enabled) +#ifdef BETA_SETTINGS + , + format_switch(menu->settings.pal60_enabled), format_switch(menu->settings.bgm_enabled), - format_switch(menu->settings.sound_enabled), format_switch(menu->settings.rumble_enabled) +#endif ); - component_actions_bar_text_draw( + + ui_components_actions_bar_text_draw( ALIGN_LEFT, VALIGN_TOP, - "\n" + "A: Change\n" "B: Back" ); + ui_components_context_menu_draw(&options_context_menu); + rdpq_detach_show(); } void view_settings_init (menu_t *menu) { - // Nothing to initialize (yet) + ui_components_context_menu_init(&options_context_menu); + } void view_settings_display (menu_t *menu, surface_t *display) { diff --git a/src/menu/views/startup.c b/src/menu/views/startup.c index 118d20dcb..c12a90450 100644 --- a/src/menu/views/startup.c +++ b/src/menu/views/startup.c @@ -9,6 +9,27 @@ static void draw (menu_t *menu, surface_t *d) { void view_startup_init (menu_t *menu) { + // FIXME: rather than use a controller button, would it be better to use the cart button? + JOYPAD_PORT_FOREACH (port) { + joypad_poll(); + joypad_buttons_t b_held = joypad_get_buttons_held(port); + + if (menu->settings.rom_autoload_enabled && b_held.start) { + menu->settings.rom_autoload_enabled = false; + menu->settings.rom_autoload_path = ""; + menu->settings.rom_autoload_filename = ""; + settings_save(&menu->settings); + } + } + if (menu->settings.rom_autoload_enabled) { + menu->browser.directory = path_init(menu->storage_prefix, menu->settings.rom_autoload_path); + menu->load.rom_path = path_clone_push(menu->browser.directory, menu->settings.rom_autoload_filename); + menu->boot_pending.rom_file = true; + menu->next_mode = MENU_MODE_LOAD_ROM; + + return; + } + menu->next_mode = MENU_MODE_BROWSER; } diff --git a/src/menu/views/system_info.c b/src/menu/views/system_info.c index 02b78f725..9dbe08a3e 100644 --- a/src/menu/views/system_info.c +++ b/src/menu/views/system_info.c @@ -1,5 +1,6 @@ #include +#include "../sound.h" #include "views.h" @@ -27,6 +28,7 @@ static void process (menu_t *menu) { } if (menu->actions.back) { + sound_play_effect(SFX_EXIT); menu->next_mode = MENU_MODE_BROWSER; } } @@ -34,36 +36,37 @@ static void process (menu_t *menu) { static void draw (menu_t *menu, surface_t *d) { rdpq_attach(d, NULL); - component_background_draw(); + ui_components_background_draw(); - component_layout_draw(); + ui_components_layout_draw(); - component_main_text_draw( + ui_components_main_text_draw( ALIGN_CENTER, VALIGN_TOP, "N64 SYSTEM INFORMATION" ); - component_main_text_draw( + ui_components_main_text_draw( ALIGN_LEFT, VALIGN_TOP, "\n" "\n" - "Current date & time: %s" - "\n" "Expansion PAK is %sinserted\n" "\n" "Joypad 1 is %sconnected %s\n" "Joypad 2 is %sconnected %s\n" "Joypad 3 is %sconnected %s\n" - "Joypad 4 is %sconnected %s\n", - menu->current_time >= 0 ? ctime(&menu->current_time) : "Unknown\n", + "Joypad 4 is %sconnected %s\n" + "\n" + "\n" + "Physical Disk Drive attached: %s\n", is_memory_expanded() ? "" : "not ", (joypad[0]) ? "" : "not ", format_accessory(0), (joypad[1]) ? "" : "not ", format_accessory(1), (joypad[2]) ? "" : "not ", format_accessory(2), - (joypad[3]) ? "" : "not ", format_accessory(3) + (joypad[3]) ? "" : "not ", format_accessory(3), + "Unknown" // Fixme: Implement disk drive detection ); - component_actions_bar_text_draw( + ui_components_actions_bar_text_draw( ALIGN_LEFT, VALIGN_TOP, "\n" "B: Exit" diff --git a/src/menu/views/text_viewer.c b/src/menu/views/text_viewer.c index 6b688479f..b3cdb5591 100644 --- a/src/menu/views/text_viewer.c +++ b/src/menu/views/text_viewer.c @@ -1,8 +1,9 @@ #include #include -#include "../components/constants.h" +#include "../ui_components/constants.h" #include "../fonts.h" +#include "../sound.h" #include "utils/utils.h" #include "views.h" @@ -54,6 +55,7 @@ static void perform_vertical_scroll (int lines) { static void process (menu_t *menu) { if (menu->actions.back) { + sound_play_effect(SFX_EXIT); menu->next_mode = MENU_MODE_BROWSER; } else if (text) { if (menu->actions.go_up) { @@ -67,19 +69,19 @@ static void process (menu_t *menu) { static void draw (menu_t *menu, surface_t *d) { rdpq_attach(d, NULL); - component_background_draw(); + ui_components_background_draw(); - component_layout_draw(); + ui_components_layout_draw(); - component_main_text_draw( + ui_components_main_text_draw( ALIGN_LEFT, VALIGN_TOP, "%s\n", text->contents + text->offset ); - component_list_scrollbar_draw(text->current_line, text->lines, LIST_ENTRIES); + ui_components_list_scrollbar_draw(text->current_line, text->lines, LIST_ENTRIES); - component_actions_bar_text_draw( + ui_components_actions_bar_text_draw( ALIGN_LEFT, VALIGN_TOP, "^%02XUp / Down: Scroll^00\n" "B: Back", diff --git a/src/menu/views/views.h b/src/menu/views/views.h index 8da900dcb..8c475280d 100644 --- a/src/menu/views/views.h +++ b/src/menu/views/views.h @@ -8,7 +8,7 @@ #define VIEWS_H__ -#include "../components.h" +#include "../ui_components.h" #include "../menu_state.h"