From 5d8ebf9200b2b8539cbb12639185304d9aae162e Mon Sep 17 00:00:00 2001 From: Mateusz Faderewski Date: Thu, 10 Aug 2023 22:39:26 +0200 Subject: [PATCH] Add PixelFX N64Digital/GEM support. (#28) --- Makefile | 1 + src/hdmi/hdmi.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++ src/hdmi/hdmi.h | 12 ++++++++++ src/main.c | 5 ++++ 4 files changed, 79 insertions(+) create mode 100644 src/hdmi/hdmi.c create mode 100644 src/hdmi/hdmi.h diff --git a/Makefile b/Makefile index a146ac81..dab647a1 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,7 @@ SRCS = \ flashcart/flashcart.c \ flashcart/sc64/sc64_ll.c \ flashcart/sc64/sc64.c \ + hdmi/hdmi.c \ libs/libspng/spng/spng.c \ libs/mini.c/src/mini.c \ libs/miniz/miniz_tdef.c \ diff --git a/src/hdmi/hdmi.c b/src/hdmi/hdmi.c new file mode 100644 index 00000000..aa6971c1 --- /dev/null +++ b/src/hdmi/hdmi.c @@ -0,0 +1,61 @@ +// Implementation based on https://gitlab.com/pixelfx-public/n64-game-id + +#include + +#include "hdmi.h" + + +#define ROM_ADDRESS (0x10000000) +#define DDIPL_ADDRESS (0x06000000) +#define CONTROLLER_PORT (0) +#define GAME_ID_COMMAND (0x1D) + + +void hdmi_reset_game_id (void) { + uint8_t joybus_tx[10]; + uint8_t joybus_rx[1]; + + memset(joybus_tx, 0, sizeof(joybus_tx)); + + execute_raw_command( + CONTROLLER_PORT, + GAME_ID_COMMAND, + sizeof(joybus_tx), + sizeof(joybus_rx), + joybus_tx, + joybus_rx + ); +} + +void hdmi_broadcast_game_id (boot_params_t *boot_params) { + uint8_t rom_header[0x40] __attribute__((aligned(8))); + uint32_t pi_address = ROM_ADDRESS; + + if (boot_params->device_type == BOOT_DEVICE_TYPE_DD) { + pi_address = DDIPL_ADDRESS; + } + + dma_read_async(rom_header, pi_address, sizeof(rom_header)); + dma_wait(); + + uint8_t joybus_tx[10]; + uint8_t joybus_rx[1]; + + // Copy CRC + memcpy(joybus_tx, rom_header + 0x10, 8); + + // Copy media format + joybus_tx[8] = rom_header[0x3B]; + + // Copy country code + joybus_tx[9] = rom_header[0x3E]; + + execute_raw_command( + CONTROLLER_PORT, + GAME_ID_COMMAND, + sizeof(joybus_tx), + sizeof(joybus_rx), + joybus_tx, + joybus_rx + ); +} diff --git a/src/hdmi/hdmi.h b/src/hdmi/hdmi.h new file mode 100644 index 00000000..222974c8 --- /dev/null +++ b/src/hdmi/hdmi.h @@ -0,0 +1,12 @@ +#ifndef HDMI_H__ +#define HDMI_H__ + + +#include "boot/boot.h" + + +void hdmi_reset_game_id (void); +void hdmi_broadcast_game_id (boot_params_t *boot_params); + + +#endif diff --git a/src/main.c b/src/main.c index d188c650..f8dde253 100644 --- a/src/main.c +++ b/src/main.c @@ -1,14 +1,19 @@ #include #include "boot/boot.h" +#include "hdmi/hdmi.h" #include "menu/menu.h" int main (void) { boot_params_t boot_params; + hdmi_reset_game_id(); + menu_run(&boot_params); + hdmi_broadcast_game_id(&boot_params); + disable_interrupts(); boot(&boot_params);