From dcc3a747360382857b1fbae05a06061f44e64033 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Thu, 2 May 2024 16:58:53 +0200 Subject: more experimentation --- captures.txt | 1 + src/frontend/qt_sdl/LocalMP.cpp | 52 ++++++++++++++++++++--------------------- src/frontend/qt_sdl/Window.cpp | 14 +++++++++++ src/vsr.h | 4 ++-- 4 files changed, 43 insertions(+), 28 deletions(-) diff --git a/captures.txt b/captures.txt index c3ed84f..8028a8c 100644 --- a/captures.txt +++ b/captures.txt @@ -6,4 +6,5 @@ melon_1714564166.pcap: pattern v2 message melon_1714566548.pcap: 1 pixel vertical line, then 1 pixel horizontal line (check structure) +melon_1714646100.pcap: used to count packet counts for various message sizes diff --git a/src/frontend/qt_sdl/LocalMP.cpp b/src/frontend/qt_sdl/LocalMP.cpp index 7fe4f64..32f08c8 100644 --- a/src/frontend/qt_sdl/LocalMP.cpp +++ b/src/frontend/qt_sdl/LocalMP.cpp @@ -49,8 +49,10 @@ pcap_dumper_t* dumper; #endif #ifdef VSR_MESSAGE_FIDDLING +#include "Window.h" #include -unsigned long test_start = time(NULL); +extern MainWindow* mainWindow; +bool fiddle = false; #endif using namespace melonDS; @@ -457,19 +459,6 @@ int SendPacketGeneric(u32 type, u8* packet, int len, u64 timestamp) u16 mask = header->ConnectedBitmask; -#ifdef VSR_MESSAGE_FIDDLING - // fiddle the packets after 20 seconds - unsigned long now = time(NULL); - static bool first = true; - bool fiddle = false; - if (now - test_start > 20 && InstanceID == 0) { - if (first == true) - printf("[INSTANCE %d] started fiddling!\n", InstanceID); - first = false; - fiddle = true; - } -#endif - // TODO: check if the FIFO is full! MPPacketHeader pktheader; @@ -479,8 +468,8 @@ int SendPacketGeneric(u32 type, u8* packet, int len, u64 timestamp) pktheader.Length = len; pktheader.Timestamp = timestamp; -#ifdef VSR_DUMP_MESSAGES - std::vector buf; +#ifdef VSR_MESSAGE_FIDDLING + static int package_idx = 0; #endif type &= 0xFFFF; @@ -489,21 +478,32 @@ int SendPacketGeneric(u32 type, u8* packet, int len, u64 timestamp) // seems to consistently trigger PACKET FIFO OVERFLOW errors FIFOWrite(nfifo, &pktheader, sizeof(pktheader)); #ifdef VSR_DUMP_MESSAGES + std::vector buf; buf.insert(buf.end(), (uint8_t*) &pktheader, (uint8_t*) &pktheader + sizeof(pktheader)); #endif if (len) { #ifdef VSR_MESSAGE_FIDDLING - if (fiddle && len == 0xde) { - // NOTE: packet indexes are after NIFI header! - packet[0x80] = 0x11; - packet[0x81] = 0x11; - packet[0x82] = 0x11; - packet[0x83] = 0x11; - packet[0x84] = 0x11; - packet[0x85] = 0x11; - packet[0x86] = 0x11; - packet[0x87] = 0x11; + // if message packet (has size 222 w/o ni-fi header) + if (fiddle && len == 222) { + // if fresh message (do not count resends) + if (packet[0x02] == 0x02) { + // corrupt all pixels in every nth package + package_idx = (package_idx + 1) % 10; + } + + if (true || package_idx == 0) { + // mainWindow->osdAddMessage(0x00ff00, "oops!"); + // NOTE: packet indexes are after NIFI header! + for (size_t i = 0; i < 0x80; i++) { + packet[0x3e + i] = 0x11; + } + // packet[0x3e + 0x00] = 0x13; + // packet[0x3e + 0x01] = 0x13; + + // packet[0x3e + 0x02] = 0x33; + // packet[0x3e + 0x04] = 0x33; + } } #endif diff --git a/src/frontend/qt_sdl/Window.cpp b/src/frontend/qt_sdl/Window.cpp index d1f16a1..16079be 100644 --- a/src/frontend/qt_sdl/Window.cpp +++ b/src/frontend/qt_sdl/Window.cpp @@ -83,6 +83,10 @@ #include "../../vsr.h" +#ifdef VSR_MESSAGE_FIDDLING +extern bool fiddle; +#endif + #ifdef VSR_INJECTION #include @@ -102,6 +106,7 @@ void MainWindow::injectPacket(int type) { std::vector buf(start, end); // TODO: is this melonDS::NDS::SysTimestamp??? + // emuThread->NDS->SysTimestamp melonDS::u64 timestamp = 0; switch(type) { @@ -605,6 +610,15 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) actAudioSync->setCheckable(true); connect(actAudioSync, &QAction::triggered, this, &MainWindow::onChangeAudioSync); } +#ifdef VSR_MESSAGE_FIDDLING + { + QMenu* menu = menubar->addMenu("Fiddle"); + + QAction* actFiddleToggle = menu->addAction("Enable fiddling"); + actFiddleToggle->setCheckable(true); + connect(actFiddleToggle, &QAction::triggered, this, [](){ fiddle = !fiddle; }); + } +#endif #ifdef VSR_INJECTION { QMenu* menu = menubar->addMenu("Inject"); diff --git a/src/vsr.h b/src/vsr.h index 78b4950..1db1f22 100644 --- a/src/vsr.h +++ b/src/vsr.h @@ -3,11 +3,11 @@ /** This is a central file for contolling VSR-specific experiments */ // corrupt instance=0's messages after 20 seconds -// #define VSR_MESSAGE_FIDDLING +#define VSR_MESSAGE_FIDDLING // dump all sent Ni-Fi packets // #define VSR_DUMP_MESSAGES // add "Inject" menu bar item -#define VSR_INJECTION +// #define VSR_INJECTION -- cgit v1.2.3