From df68a8941c7905badb6506bb64dee4dfedbc2683 Mon Sep 17 00:00:00 2001 From: Rodrigo Alfonso Date: Wed, 21 Aug 2024 21:24:19 -0300 Subject: [PATCH] Adding SPI transfer mode to LinkCableMultiboot_demo example --- README.md | 2 +- examples/LinkCableMultiboot_demo/src/main.cpp | 32 ++++++++++++------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 9ecb6af..f7198a3 100644 --- a/README.md +++ b/README.md @@ -121,7 +121,7 @@ You can change these compile-time constants: Name | Return type | Description --- | --- | --- -`sendRom(rom, romSize, cancel, [mode])` | **LinkCableMultiboot::Result** | Sends the `rom`. During the handshake process, the library will continuously invoke `cancel`, and abort the transfer if it returns `true`. The `romSize` must be a number between `448` and `262144`, and a multiple of `16`. The `mode` can be either `TransferMode::MULTI_PLAY` for GBA cable (default value) or `TransferMode::SPI` for GBC cable. Once completed, the return value should be `LinkCableMultiboot::Result::SUCCESS`. +`sendRom(rom, romSize, cancel, [mode])` | **LinkCableMultiboot::Result** | Sends the `rom`. During the handshake process, the library will continuously invoke `cancel`, and abort the transfer if it returns `true`. The `romSize` must be a number between `448` and `262144`, and a multiple of `16`. The `mode` can be either `LinkCableMultiboot::TransferMode::MULTI_PLAY` for GBA cable (default value) or `LinkCableMultiboot::TransferMode::SPI` for GBC cable. Once completed, the return value should be `LinkCableMultiboot::Result::SUCCESS`. ⚠️ for better results, turn on the GBAs **after** calling the `sendRom` method! diff --git a/examples/LinkCableMultiboot_demo/src/main.cpp b/examples/LinkCableMultiboot_demo/src/main.cpp index 05f5062..42bc9c7 100644 --- a/examples/LinkCableMultiboot_demo/src/main.cpp +++ b/examples/LinkCableMultiboot_demo/src/main.cpp @@ -11,6 +11,7 @@ extern "C" { static const GBFS_FILE* fs = find_first_gbfs_file(0); static u32 selectedFile = 0; +static bool spi = false; void log(std::string text); void waitFor(u16 key); @@ -53,7 +54,7 @@ int main() { ; } - bool left = false, right = false, a = false, b = false; + bool left = false, right = false, a = false, b = false, l = false; while (true) { // Get selected ROM name @@ -68,12 +69,9 @@ int main() { } } - // Menu - log("LinkCableMultiboot_demo\n (v7.0.0)\n\n" - "Press A to send the ROM...\n" - "Press B to launch the ROM...\nLEFT/RIGHT: select ROM\n\nSelected " - "ROM:\n " + - std::string(name)); + // Toggle mode + if (didPress(KEY_L, l)) + spi = !spi; // Select ROM if (didPress(KEY_LEFT, left)) @@ -81,15 +79,27 @@ int main() { if (didPress(KEY_RIGHT, right)) selectRight(); + // Menu + log("LinkCableMultiboot_demo\n (v7.0.0)\n\n" + "Press A to send the ROM...\n" + "Press B to launch the ROM...\nLEFT/RIGHT: select ROM\nL: toggle " + "mode\n\nSelected ROM:\n " + + std::string(name) + "\n\nMode:\n " + + std::string(spi ? "SPI (GBC cable)" : "MULTI_PLAY (GBA cable)")); + // Send ROM if (didPress(KEY_A, a)) { log("Sending... (SELECT to cancel)"); // (2) Send the ROM - auto result = linkCableMultiboot->sendRom(romToSend, romSize, []() { - u16 keys = ~REG_KEYS & KEY_ANY; - return keys & KEY_SELECT; - }); + auto result = linkCableMultiboot->sendRom( + romToSend, romSize, + []() { + u16 keys = ~REG_KEYS & KEY_ANY; + return keys & KEY_SELECT; + }, + spi ? LinkCableMultiboot::TransferMode::SPI + : LinkCableMultiboot::TransferMode::MULTI_PLAY); // Print results and wait log("Result: " + std::to_string(result) + "\n" +