### LZMA File Compression Example Source: https://github.com/tasemulators/desmume/blob/master/desmume/src/frontend/windows/File_Extractor/7z_C/lzma.txt Compresses a file using LZMA with a specified dictionary size and literal context bits. -lc0 can reduce decompression memory requirements. ```bash LZMA e file.bin file.lzma -d16 -lc0 ``` -------------------------------- ### WinRAR Environment Variable Expansion in List Files Source: https://github.com/tasemulators/desmume/blob/master/desmume/src/frontend/windows/File_Extractor/unrar/whatsnew.txt Example of using environment variables within list files for WinRAR on Windows. This allows for dynamic path specification in list files. ```bash %windir%\*.exe ``` ```bash %USERPROFILE%\Desktop ``` -------------------------------- ### Diff-Friendly Code Insertion Example Source: https://github.com/tasemulators/desmume/blob/master/desmume/src/frontend/windows/File_Extractor/unrar/changes.txt Illustrates a method for making source code changes more visible in line-based diffs by inserting new lines rather than modifying existing ones. This approach clearly indicates added code. ```c++ static int array [4] = { 1, 2, 3, 4 }; ``` ```c++ const // added static int array [4] = { 1, 2, 3, 4 }; ``` -------------------------------- ### Record and Play Movies with DeSmuME API Source: https://context7.com/tasemulators/desmume/llms.txt Use FCEUI functions to record, load, play, and stop movie files. Includes checking movie state and getting movie information. ```cpp #include "movie.h" #include "utils/datetime.h" // Record a new movie std::wstring author = L"Player1"; DateTime startTime = DateTime::get_Now(); FCEUI_SaveMovie( "/path/to/movie.dsm", author, START_BLANK, // Start from blank: START_BLANK, START_SRAM, START_SAVESTATE "", // SRAM filename (if START_SRAM) startTime // RTC start time ); // Load and play a movie const char* result = FCEUI_LoadMovie( "/path/to/movie.dsm", true, // Read-only mode false, // TAS edit mode -1 // Pause frame (-1 = don't pause) ); if (result != NULL) { printf("Error loading movie: %s\n", result); } // Check movie state extern EMOVIEMODE movieMode; extern MovieData currMovieData; extern int currFrameCounter; switch (movieMode) { case MOVIEMODE_INACTIVE: printf("No movie active\n"); break; case MOVIEMODE_RECORD: printf("Recording: frame %d\n", currFrameCounter); break; case MOVIEMODE_PLAY: printf("Playing: frame %d / %d\n", currFrameCounter, currMovieData.getNumRecords()); break; case MOVIEMODE_FINISHED: printf("Movie finished\n"); break; } // Get movie information EMUFILE_FILE movieFile("/path/to/movie.dsm", "rb"); MOVIE_INFO info; if (FCEUI_MovieGetInfo(movieFile, info, false)) { printf("Frames: %u\n", info.num_frames); printf("Rerecords: %u\n", info.rerecord_count); printf("ROM: %s\n", info.name_of_rom_used.c_str()); } // Stop movie recording/playback FCEUI_StopMovie(); // Create backup of current movie FCEUI_MakeBackupMovie(true); // Display message // Set read-only mode extern bool movie_readonly; movie_readonly = true; // Prevent modifications during playback ``` -------------------------------- ### WinRAR SFX Archive Command Line Access via Environment Variable Source: https://github.com/tasemulators/desmume/blob/master/desmume/src/frontend/windows/File_Extractor/unrar/whatsnew.txt In newer versions, GUI self-extracting modules do not pass the entire command line to setup programs directly. Access the full command line by parsing the 'sfxcmd' environment variable. ```bash sfxcmd ``` -------------------------------- ### LZMA Decompression Initialization Source: https://github.com/tasemulators/desmume/blob/master/desmume/src/frontend/windows/File_Extractor/7z_C/lzma.txt Initializes LZMA decoder structures and allocates memory for the dictionary. This is a prerequisite before starting the decoding process. ```c CLzmaDec state; LzmaDec_Constr(&state); res = LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc); if (res != SZ_OK) return res; ``` -------------------------------- ### WinRAR SFX Archive Command Line Switches Source: https://github.com/tasemulators/desmume/blob/master/desmume/src/frontend/windows/File_Extractor/unrar/whatsnew.txt These command-line switches can be used with GUI self-extracting modules to control their behavior. They allow setting destination paths, passwords, silent modes, and parameters for setup programs. ```bash -d set the destination path ``` ```bash -p specify a password ``` ```bash -s silent mode, hide all ``` ```bash -s1 same as -s ``` ```bash -s2 silent mode, hide start dialog ``` ```bash -sp specify parameters for setup program ``` -------------------------------- ### Initialize 7z Archive Database Source: https://github.com/tasemulators/desmume/blob/master/desmume/src/frontend/windows/File_Extractor/7z_C/7zC.txt Call SzArEx_Init(&db) to initialize the 7z archive database structure before opening an archive. ```c SzArEx_Init(&db); ``` -------------------------------- ### Create .7z Archive with 7za.exe Source: https://github.com/tasemulators/desmume/blob/master/desmume/src/frontend/windows/File_Extractor/7z_C/7zC.txt Use 7za.exe to create .7z archives. The -mx flag sets the compression level, and -m0fb=255 optimizes for fast decompression. ```bash 7za.exe a archive.7z *.htm -r -mx -m0fb=255 ``` ```bash 7za.exe a archive.7z *.htm -ms=512K -r -mx -m0fb=255 -m0d=512K ``` -------------------------------- ### Initialize DeSmuME Core and Settings Source: https://context7.com/tasemulators/desmume/llms.txt Initializes the Nintendo DS emulation subsystem, including processors, memory, graphics, and sound. Configure emulation settings like core count, JIT usage, and 3D rendering options before or after initialization. Ensure sound is initialized separately. ```cpp #include "NDSSystem.h" #include "GPU.h" #include "SPU.h" // Initialize the NDS emulation core int result = NDS_Init(); if (result != 0) { printf("Failed to initialize DeSmuME core\n"); return -1; } // Initialize common settings Desmume_InitOnce(); // Configure emulation settings CommonSettings.num_cores = 4; CommonSettings.use_jit = true; CommonSettings.jit_max_block_size = 100; CommonSettings.GFX3D_HighResolutionInterpolateColor = true; CommonSettings.GFX3D_EdgeMark = true; CommonSettings.GFX3D_Fog = true; CommonSettings.GFX3D_Texture = true; // Initialize sound with a specific core and buffer size int sndResult = SPU_Init(SNDCORE_DEFAULT, 44100 * 2); // When done with emulation NDS_DeInit(); SPU_DeInit(); ``` -------------------------------- ### Initialize and Configure SPU Source: https://context7.com/tasemulators/desmume/llms.txt Initializes the Sound Processing Unit (SPU) with a specified sound core and buffer size. Allows runtime changes to the sound core, volume adjustment, pausing/resuming audio, and setting synchronization modes. Includes buffer size considerations for latency and underrun prevention. ```cpp #include "SPU.h" // Initialize SPU with a specific sound core and buffer size // Buffer size in bytes (larger = more latency, less chance of underrun) int bufferSizeBytes = 44100 * 4; // ~1 second buffer int result = SPU_Init(SNDCORE_DEFAULT, bufferSizeBytes); if (result != 0) { printf("Failed to initialize sound\n"); } // Change sound core at runtime SPU_ChangeSoundCore(SNDCORE_DEFAULT, bufferSizeBytes); // Set audio volume (0-100) SPU_SetVolume(80); // Pause/unpause audio SPU_Pause(1); // Pause SPU_Pause(0); // Resume // Set synchronization mode // Mode: 0 = Asynchronous, 1 = Synchronous // Method: 0 = None, 1 = Zero-fill, 2 = Stretch SPU_SetSynchMode(1, 2); // Clear output buffer SPU_ClearOutputBuffer(); // Configure SPU interpolation mode in settings CommonSettings.spuInterpolationMode = SPUInterpolation_CatmullRom; // Mute specific channels (0-15) CommonSettings.spu_muteChannels[0] = true; // Mute channel 0 CommonSettings.spu_muteChannels[1] = false; // Unmute channel 1 // Start WAV recording bool wavStarted = WAV_Begin("/path/to/output.wav", WAVMODE_CORE); // Check if recording if (WAV_IsRecording()) { printf("Recording audio...\n"); } // Stop WAV recording WAV_End(); // Cleanup SPU_DeInit(); ``` -------------------------------- ### Autogenerate OpenGL desktop extension loaders Source: https://github.com/tasemulators/desmume/blob/master/desmume/src/libretro-common/glsym/README.md Use this command to generate loaders for OpenGL desktop extensions. Ensure you have the Khronos glext.h header file available. ```bash ./glgen.py /usr/include/GL/glext.h glsym_gl.h glsym_gl.c ``` -------------------------------- ### Configure GPU and Graphics Source: https://context7.com/tasemulators/desmume/llms.txt Sets up the GPU subsystem, including custom framebuffer resolutions, color formats, and multi-buffering. Enables/disables GPU engines and individual display layers (BG0-BG3, OBJ). ```cpp #include "GPU.h" extern GPUSubsystem* GPU; // Set custom framebuffer size (for high-resolution rendering) // Native DS resolution is 256x192 per screen GPU->SetCustomFramebufferSize(512, 384); // 2x upscale // Set color format GPU->SetColorFormat(NDSColorFormat_BGR888_Rev); // 32-bit color // Set number of framebuffer pages for multi-buffering GPU->SetFramebufferPageCount(2); // Get the main and sub GPU engines GPUEngineA* engineMain = GPU->GetEngineMain(); GPUEngineB* engineSub = GPU->GetEngineSub(); // Get display objects NDSDisplay* displayMain = GPU->GetDisplayMain(); NDSDisplay* displayTouch = GPU->GetDisplayTouch(); // Enable/disable specific GPU engines engineMain->SetEnableState(true); engineSub->SetEnableState(true); // Enable/disable individual layers (BG0-BG3 and OBJ) engineMain->SetLayerEnableState(GPULayerID_BG0, true); engineMain->SetLayerEnableState(GPULayerID_BG1, true); engineMain->SetLayerEnableState(GPULayerID_BG2, true); engineMain->SetLayerEnableState(GPULayerID_BG3, true); engineMain->SetLayerEnableState(GPULayerID_OBJ, true); // Get current display info const NDSDisplayInfo& info = GPU->GetDisplayInfo(); printf("Custom dimensions: %ux%u\n", info.customWidth, info.customHeight); printf("Color format bytes: %u\n", info.pixelBytes); // Configure frame skipping GPU->SetWillFrameSkip(false); // Configure automatic buffer resolution GPU->SetWillAutoResolveToCustomBuffer(true); ``` -------------------------------- ### 7-Zip Compression with LZMA (No Filter) Source: https://github.com/tasemulators/desmume/blob/master/desmume/src/frontend/windows/File_Extractor/7z_C/lzma.txt Demonstrates compressing a binary file using 7-Zip with the LZMA method without any pre-applied filters. ```bash 7z a a1.7z a.bin -m0=lzma ``` -------------------------------- ### Overriding WinRAR AppData Path via Registry Source: https://github.com/tasemulators/desmume/blob/master/desmume/src/frontend/windows/File_Extractor/unrar/whatsnew.txt To change the default location for WinRAR settings and theme files from %APPDATA%\WinRAR to a custom path, set the string value 'AppData' in the Registry key HKEY_CURRENT_USER\Software\WinRAR\Paths. For example, setting it to 'c:\Program Files\WinRAR' would store these files in the WinRAR program directory. ```powershell HKEY_CURRENT_USER\Software\WinRAR\Paths ``` -------------------------------- ### Parse Command Line Arguments for DeSmuME Source: https://context7.com/tasemulators/desmume/llms.txt Use the CommandLine class to parse and validate arguments for scripted launching and automation. Access parsed options like NDS file, render mode, and sound settings. ```cpp #include "commandline.h" // Create and parse command line arguments CommandLine cmdline; // Simulated command line arguments int argc = 5; char* argv[] = { "desmume", "--load-slot=1", "--render3d=2", // Software renderer "--disable-sound", "game.nds" }; if (!cmdline.parse(argc, argv)) { cmdline.errorHelp(argv[0]); return -1; } // Validate parsed options if (!cmdline.validate()) { printf("Invalid command line options\n"); return -1; } // Access parsed values printf("NDS file: %s\n", cmdline.nds_file.c_str()); printf("Load slot: %d\n", cmdline.load_slot); printf("3D renderer: %d\n", cmdline.render3d); printf("Sound disabled: %d\n", cmdline.disable_sound); printf("Frame skip: %d\n", cmdline.frameskip); printf("Scale: %f\n", cmdline.scale); // Process movie commands if specified if (!cmdline.play_movie_file.empty()) { cmdline.process_movieCommands(); } // Process addon/slot commands cmdline.process_addonCommands(); // Available render3d values: // COMMANDLINE_RENDER3D_DEFAULT (0) // COMMANDLINE_RENDER3D_NONE (1) // COMMANDLINE_RENDER3D_SW (2) // COMMANDLINE_RENDER3D_OLDGL (3) // COMMANDLINE_RENDER3D_GL (4) // COMMANDLINE_RENDER3D_AUTOGL (5) ``` -------------------------------- ### 7z Archive Creation with Filters Source: https://github.com/tasemulators/desmume/blob/master/desmume/src/frontend/windows/File_Extractor/7z_C/lzma.txt This command creates a 7z archive named 'a2.7z' containing 'a.bin'. It utilizes LZMA compression with specific filters ('m0=arm', 'm1=lzma') to potentially improve compression ratios and decompression speed. ```bash 7z a a2.7z a.bin -m0=arm -m1=lzma ``` -------------------------------- ### List Files in 7z Archive Source: https://github.com/tasemulators/desmume/blob/master/desmume/src/frontend/windows/File_Extractor/7z_C/7zC.txt Iterate through the NumFiles in the archive database to print the size and name of each file. This is useful for displaying archive contents. ```c { UInt32 i; for (i = 0; i < db.db.NumFiles; i++) { CFileItem *f = db.db.Files + i; printf("%10d %s\n", (int)f->Size, f->Name); } } ``` -------------------------------- ### Save and Load Emulation States Source: https://context7.com/tasemulators/desmume/llms.txt Provides functionality to save and load the current emulation progress to/from files or memory. Supports direct file paths, slot numbers (0-9), and in-memory buffers. Includes scanning for available save states and SRAM management. ```cpp #include "saves.h" #include "emufile.h" // Save state to a file const char* saveStatePath = "/path/to/savestate.dst"; bool saveSuccess = savestate_save(saveStatePath); if (saveSuccess) { printf("State saved successfully\n"); } // Load state from a file bool loadSuccess = savestate_load(saveStatePath); if (loadSuccess) { printf("State loaded successfully\n"); } else { printf("Failed to load state\n"); } // Save/load using slot numbers (0-9) int slotNum = 1; savestate_slot(slotNum); // Save to slot 1 loadstate_slot(slotNum); // Load from slot 1 // Check available save states extern savestates_t savestates[NB_STATES]; scan_savestates(); // Scan for existing states for (int i = 0; i < NB_STATES; i++) { if (savestates[i].exists) { printf("Slot %d: %s\n", i, savestates[i].date); } } // Save state to memory (EMUFILE interface) EMUFILE_MEMORY memFile; savestate_save(memFile, Z_DEFAULT_COMPRESSION); // Get the state data u8* stateData = memFile.buf(); size_t stateSize = memFile.size(); // Load state from memory EMUFILE_MEMORY loadFile(stateData, stateSize); savestate_load(loadFile); // SRAM management sram_save("/path/to/game.dsv"); sram_load("/path/to/game.dsv"); ``` -------------------------------- ### Compile LZMA with Static Libraries on UNIX/Linux Source: https://github.com/tasemulators/desmume/blob/master/desmume/src/frontend/windows/File_Extractor/7z_C/lzma.txt When compiling LZMA with static libraries on certain UNIX/Linux versions, use this LIB flag. This ensures all necessary components are linked statically. ```bash LIB = -lm -static ``` -------------------------------- ### LZMA Benchmark Command Source: https://github.com/tasemulators/desmume/blob/master/desmume/src/frontend/windows/File_Extractor/7z_C/lzma.txt Runs a benchmark test for LZMA compression and decompression, showing performance in MIPS. The default number of iterations is 10; specify a number for custom iterations. ```bash LZMA b 30 ``` -------------------------------- ### LZMA Multi-Call Decompression Initialization Source: https://github.com/tasemulators/desmume/blob/master/desmume/src/frontend/windows/File_Extractor/7z_C/lzma.txt This code snippet shows the initial step for multi-call decompression, which is suitable for file-to-file decompression. It involves reading the LZMA properties (5 bytes) and uncompressed size (8 bytes, little-endian) into a header buffer. ```c unsigned char header[LZMA_PROPS_SIZE + 8]; ``` -------------------------------- ### Implement Custom DeSmuME Driver Source: https://context7.com/tasemulators/desmume/llms.txt Implement the BaseDriver interface to create a custom driver for platform-specific functionality. This includes handling info messages, screen refreshes, emulation pausing, audio updates, and the main emulation loop. ```cpp #include "driver.h" // Custom driver implementation class MyDriver : public BaseDriver { public: void USR_InfoMessage(const char* message) override { printf("[INFO] %s\n", message); } void USR_RefreshScreen() override { // Trigger screen redraw in your frontend refreshDisplay(); } void EMU_PauseEmulation(bool pause) override { isPaused = pause; if (pause) { printf("Emulation paused\n"); } else { printf("Emulation resumed\n"); } } bool EMU_IsEmulationPaused() override { return isPaused; } bool AVI_IsRecording() override { return aviRecording; } void AVI_SoundUpdate(void* soundData, int soundLen) override { if (aviRecording) { writeAudioToAvi(soundData, soundLen); } } eStepMainLoopResult EMU_StepMainLoop( bool allowSleep, bool allowPause, int frameSkip, bool disableUser, bool disableCore ) override { // Custom main loop stepping if (isPaused && allowPause) { return ESTEP_DONE; } // Execute one frame NDS_exec(560190 << 1); return ESTEP_CALL_AGAIN; } private: bool isPaused = false; bool aviRecording = false; }; // Install custom driver extern BaseDriver* driver; MyDriver* myDriver = new MyDriver(); driver = myDriver; // Use driver functions driver->USR_InfoMessage("ROM loaded successfully"); driver->EMU_PauseEmulation(true); // Check emulation state if (driver->EMU_IsEmulationPaused()) { printf("Currently paused\n"); } ``` -------------------------------- ### Initialize CRC Structures Source: https://github.com/tasemulators/desmume/blob/master/desmume/src/frontend/windows/File_Extractor/7z_C/7zC.txt Call CrcGenerateTable() to initialize the CRC structures before using the 7z decoder. ```c CrcGenerateTable(); ``` -------------------------------- ### List Archive Contents with 7zDec Source: https://github.com/tasemulators/desmume/blob/master/desmume/src/frontend/windows/File_Extractor/7z_C/7zC.txt Use the 'l' command with the 7zDec test application to list the contents of a .7z archive. This command displays file sizes and names. ```bash 7zDec l archive.7z ``` -------------------------------- ### Autogenerate OpenGL ES extension loaders Source: https://github.com/tasemulators/desmume/blob/master/desmume/src/libretro-common/glsym/README.md Use this command to generate loaders for OpenGL ES 2.0 extensions. Specify the path to the GLES2/gl2ext.h header file. ```bash ./glgen.py /usr/include/GLES2/gl2ext.h glsym_es2.h glsym_es2.c ``` -------------------------------- ### Open .7z Archive Source: https://github.com/tasemulators/desmume/blob/master/desmume/src/frontend/windows/File_Extractor/7z_C/7zC.txt Use SzArEx_Open to open a .7z archive from an input stream. This function reads headers into the provided database structure and uses specified memory allocation functions for main and temporary pools. ```c SzArEx_Open(&db, inStream, &allocMain, &allocTemp); ``` -------------------------------- ### LZMA Decompression Initialization and Decoding Source: https://github.com/tasemulators/desmume/blob/master/desmume/src/frontend/windows/File_Extractor/7z_C/lzma.txt Initializes LZMA decoder structures, allocates memory for the dictionary, and decodes data from a source buffer to a destination buffer. Ensure to free allocated structures after use. ```c CLzmaDec state; LzmaDec_Constr(&state); res = LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc); if (res != SZ_OK) return res; LzmaDec_Init(&state); for (;;) { ... int res = LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode); ... } LzmaDec_Free(&state, &g_Alloc); ``` -------------------------------- ### System Reset and Boot Modes Source: https://context7.com/tasemulators/desmume/llms.txt Resets the Nintendo DS emulation system and initiates either a fast fake boot or a more accurate legitimate boot using firmware. Legitimate boot requires valid BIOS files and setting `BootFromFirmware` to true. Fake boot is the default and faster option. ```cpp #include "NDSSystem.h" // Reset the NDS system NDS_Reset(); // Option 1: Fake boot (fast, bypasses firmware) // This is the default mode that starts games immediately bool bootSuccess = NDS_FakeBoot(); if (!bootSuccess) { printf("Fake boot failed\n"); } // Option 2: Legitimate boot through firmware (slower, more accurate) // Requires valid BIOS files CommonSettings.UseExtBIOS = true; strcpy(CommonSettings.ARM9BIOS, "/path/to/bios9.bin"); strcpy(CommonSettings.ARM7BIOS, "/path/to/bios7.bin"); CommonSettings.BootFromFirmware = true; if (CommonSettings.BootFromFirmware) { bool legitBoot = NDS_LegitBoot(); if (!legitBoot) { printf("Legitimate boot failed, falling back to fake boot\n"); NDS_FakeBoot(); } } ``` -------------------------------- ### Execute Emulation Frame Source: https://context7.com/tasemulators/desmume/llms.txt Drives the main emulation loop, executing a specified number of cycles for one frame. Use the FORCE parameter to control timing. Accesses display information and framebuffers for rendering. ```cpp #include "NDSSystem.h" #include "GPU.h" extern volatile bool execute; // Global execution flag // Main emulation loop execute = true; while (execute) { // Execute one frame's worth of cycles // The default cycle count (560190<<1) represents one frame at ~60fps NDS_exec(560190 << 1); // Get display info for rendering const NDSDisplayInfo& displayInfo = GPU->GetDisplayInfo(); // Access framebuffer data void* mainBuffer = displayInfo.renderedBuffer[NDSDisplayID_Main]; void* touchBuffer = displayInfo.renderedBuffer[NDSDisplayID_Touch]; size_t mainWidth = displayInfo.renderedWidth[NDSDisplayID_Main]; size_t mainHeight = displayInfo.renderedHeight[NDSDisplayID_Main]; // Render to screen (platform-specific) // renderToScreen(mainBuffer, touchBuffer, mainWidth, mainHeight); // Optional: Skip next frame for performance // NDS_SkipNextFrame(); } ``` -------------------------------- ### WinRAR Archiving Update Modes Command Line Source: https://github.com/tasemulators/desmume/blob/master/desmume/src/frontend/windows/File_Extractor/unrar/whatsnew.txt Command line equivalents for WinRAR's 'Ask before overwrite' and 'Skip existing files' archiving modes. Use these switches to control how WinRAR handles existing files during archiving. ```bash a) switch -o enables "Ask before overwrite" archiving mode; ``` ```bash b) switch -o- enables "Skip existing files" archiving mode; ``` ```bash c) switch -o+ enables "Overwrite all" mode (default for archiving). ``` -------------------------------- ### 7-Zip Compression with LZMA (ARM Filter) Source: https://github.com/tasemulators/desmume/blob/master/desmume/src/frontend/windows/File_Extractor/7z_C/lzma.txt Compresses a binary file using 7-Zip with the LZMA method, applying a filter specifically for little-endian ARM code to potentially improve compression ratio. ```bash 7z a a1.7z a.bin -m0=lzma -sfilter=arm ``` -------------------------------- ### Free 7z Archive Database Source: https://github.com/tasemulators/desmume/blob/master/desmume/src/frontend/windows/File_Extractor/7z_C/7zC.txt Call SzArEx_Free to release memory allocated for the archive database. Ensure to pass the correct free function from your main memory allocator. ```c SzArEx_Free(&db, allocImp.Free); ``` -------------------------------- ### File Stream Output Implementation Source: https://github.com/tasemulators/desmume/blob/master/desmume/src/frontend/windows/File_Extractor/7z_C/lzma.txt Implements the ISeqOutStream interface for writing data to a file. This involves defining a Write function that takes a file pointer. ```c CFileSeqOutStream outStream; outStream.funcTable.Write = MyWrite; outStream.file = outFile; ``` -------------------------------- ### File Stream Input Implementation Source: https://github.com/tasemulators/desmume/blob/master/desmume/src/frontend/windows/File_Extractor/7z_C/lzma.txt Implements the ISeqInStream interface for reading data from a file. This involves defining a Read function that takes a file pointer. ```c CFileSeqInStream inStream; inStream.funcTable.Read = MyRead; inStream.file = inFile; ``` -------------------------------- ### Extract Files from Archive with 7zDec Source: https://github.com/tasemulators/desmume/blob/master/desmume/src/frontend/windows/File_Extractor/7z_C/7zC.txt Use the 'e' command with the 7zDec test application to extract files from a .7z archive to the current folder. ```bash 7zDec e archive.7z ``` -------------------------------- ### Setting LZMA Encoder Properties Source: https://github.com/tasemulators/desmume/blob/master/desmume/src/frontend/windows/File_Extractor/7z_C/lzma.txt Applies the configured LZMA properties to the encoder. This must be called after initializing properties and before encoding. ```c res = LzmaEnc_SetProps(enc, &props); ``` -------------------------------- ### LZMA Encoder Properties Initialization Source: https://github.com/tasemulators/desmume/blob/master/desmume/src/frontend/windows/File_Extractor/7z_C/lzma.txt Initializes the LZMA encoder properties structure. Default properties are set, which can then be modified before encoding. ```c LzmaEncProps_Init(&props); ``` -------------------------------- ### Access ARM CPU State in DeSmuME Source: https://context7.com/tasemulators/desmume/llms.txt Read registers, CPSR, and CPU freeze status from NDS_ARM9 and NDS_ARM7 structures. Includes triggering IRQs and initializing new CPU states. ```cpp #include "armcpu.h" extern armcpu_t NDS_ARM9; extern armcpu_t NDS_ARM7; // Read ARM9 registers u32 pc = NDS_ARM9.R[15]; // Program counter u32 sp = NDS_ARM9.R[13]; // Stack pointer u32 lr = NDS_ARM9.R[14]; // Link register u32 r0 = NDS_ARM9.R[0]; // General purpose register printf("ARM9 PC: 0x%08X\n", pc); printf("ARM9 SP: 0x%08X\n", sp); // Read CPSR (Current Program Status Register) Status_Reg cpsr = NDS_ARM9.CPSR; printf("Mode: 0x%02X\n", cpsr.bits.mode); printf("Thumb: %d\n", cpsr.bits.T); printf("IRQ disabled: %d\n", cpsr.bits.I); printf("N flag: %d\n", cpsr.bits.N); printf("Z flag: %d\n", cpsr.bits.Z); printf("C flag: %d\n", cpsr.bits.C); printf("V flag: %d\n", cpsr.bits.V); // Check CPU freeze state if (NDS_ARM9.freeze & CPU_FREEZE_WAIT_IRQ) { printf("ARM9 waiting for IRQ\n"); } // ARM7 access printf("ARM7 PC: 0x%08X\n", NDS_ARM7.R[15]); // Trigger an IRQ NDS_makeIrq(0, 0); // ARM9, IRQ bit 0 (VBlank) NDS_makeIrq(1, 1); // ARM7, IRQ bit 1 (HBlank) // Initialize a new CPU state armcpu_t newCpu; armcpu_new(&newCpu, 0); // 0 = ARM9, 1 = ARM7 armcpu_init(&newCpu, 0x02000000); // Set entry point ``` -------------------------------- ### Writing LZMA Properties and File Size to Header Source: https://github.com/tasemulators/desmume/blob/master/desmume/src/frontend/windows/File_Extractor/7z_C/lzma.txt Encodes the LZMA properties and the file size into a header buffer. This header is typically written to the beginning of the compressed file. ```c Byte header[LZMA_PROPS_SIZE + 8]; size_t headerSize = LZMA_PROPS_SIZE; UInt64 fileSize; int i; res = LzmaEnc_WriteProperties(enc, header, &headerSize); fileSize = MyGetFileLength(inFile); for (i = 0; i < 8; i++) header[headerSize++] = (Byte)(fileSize >> (8 * i)); MyWriteFileAndCheck(outFile, header, headerSize) ``` -------------------------------- ### Custom Memory Allocator Implementation Source: https://github.com/tasemulators/desmume/blob/master/desmume/src/frontend/windows/File_Extractor/7z_C/lzma.txt Provides custom memory allocation and deallocation functions required by the LZMA SDK. These functions are used for managing memory during compression and decompression. ```c static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); } static void SzFree(void *p, void *address) { p = p; MyFree(address); } static ISzAlloc g_Alloc = { SzAlloc, SzFree }; ``` -------------------------------- ### Compile LZMA with GCC on UNIX/Linux Source: https://github.com/tasemulators/desmume/blob/master/desmume/src/frontend/windows/File_Extractor/7z_C/lzma.txt Use this command to recompile the C++ file-to-file LZMA encoder on UNIX/Linux systems using GCC. Ensure you are in the correct directory. ```bash make -f makefile.gcc clean all ``` -------------------------------- ### Multi-call State Decompressing Interface Source: https://github.com/tasemulators/desmume/blob/master/desmume/src/frontend/windows/File_Extractor/7z_C/lzma.txt Details the multi-call (zlib-like) interface for LZMA decompression. ```APIDOC ## Multi-call State Decompressing Interface ### Description A zlib-like interface suitable for file-to-file decompression. ### Compile Files - LzmaDec.h - LzmaDec.c - Types.h ### Memory Requirements - Input stream buffer: Any size (e.g., 16 KB). - Output stream buffer: Any size (e.g., 16 KB). - LZMA Internal Structures: `state_size` (16 KB for default settings). - LZMA dictionary: Size is encoded in the LZMA properties header. ### Initialization Steps 1. Read LZMA properties (5 bytes) and uncompressed size (8 bytes, little-endian) into a header buffer (e.g., `unsigned char header[LZMA_PROPS_SIZE + 8];`). ``` -------------------------------- ### LZMA Compression for Periodical Data Source: https://github.com/tasemulators/desmume/blob/master/desmume/src/frontend/windows/File_Extractor/7z_C/lzma.txt Compresses a file with settings optimized for 32-bit periodical data, such as ARM or MIPS code. This configuration uses specific literal and position bit settings. ```bash LZMA e file.bin file.lzma -lc0 -lp2 ``` -------------------------------- ### Load and Access ROM Information Source: https://context7.com/tasemulators/desmume/llms.txt Loads a Nintendo DS ROM file into the emulator and provides access to its metadata. After loading, you can retrieve game title, serial, size, CRC32, and header information. DSi-enhanced game detection is also available. Remember to free the ROM when finished. ```cpp #include "NDSSystem.h" // Load a ROM file const char* romPath = "/path/to/game.nds"; int loadResult = NDS_LoadROM(romPath, NULL, NULL); if (loadResult < 0) { printf("Failed to load ROM: %s\n", romPath); return -1; } // Access ROM information after loading extern GameInfo gameInfo; printf("Game Title: %s\n", gameInfo.ROMname); printf("Serial: %s\n", gameInfo.ROMserial); printf("ROM Size: %u bytes\n", gameInfo.romsize); printf("CRC32: 0x%08X\n", gameInfo.crc); // Check ROM header information NDS_header* header = NDS_getROMHeader(); printf("ARM9 Entry: 0x%08X\n", header->ARM9exe); printf("ARM7 Entry: 0x%08X\n", header->ARM7exe); // Check if this is a DSi-enhanced game if (gameInfo.isDSiEnhanced()) { printf("This ROM has DSi enhancements\n"); } // Free ROM when done NDS_FreeROM(); ``` -------------------------------- ### WinRAR SFX Archive Administrative Access Switch Source: https://github.com/tasemulators/desmume/blob/master/desmume/src/frontend/windows/File_Extractor/unrar/whatsnew.txt Use the -iadm switch to create a self-extracting archive that requests administrative access when run on Windows Vista. This is useful for SFX modules that need to create destination folders under restricted user accounts. ```bash WinRAR.exe -iadm ``` -------------------------------- ### LZMA Compressed File Format Source: https://github.com/tasemulators/desmume/blob/master/desmume/src/frontend/windows/File_Extractor/7z_C/lzma.txt Details the structure of an LZMA compressed file. ```APIDOC ## LZMA Compressed File Format ### Description Structure of an LZMA compressed file. ### Format | Offset | Size | Description | |---|---|---| | 0 | 1 | Special LZMA properties (lc, lp, pb in encoded form) | | 1 | 4 | Dictionary size (little endian) | | 5 | 8 | Uncompressed size (little endian). -1 means unknown size | | 13 | - | Compressed data | ``` -------------------------------- ### C++ LZMA Wrapper Note Source: https://github.com/tasemulators/desmume/blob/master/desmume/src/frontend/windows/File_Extractor/7z_C/lzma.txt Indicates that the C++ LZMA code uses COM-like interfaces and is a wrapper over the ANSI-C code. Familiarity with COM/OLE is suggested for usage. ```c++ // C++ LZMA code use COM-like interfaces. ``` -------------------------------- ### ANSI-C LZMA Decoder Source: https://github.com/tasemulators/desmume/blob/master/desmume/src/frontend/windows/File_Extractor/7z_C/lzma.txt Information about the ANSI-C LZMA Decoder and its requirements. ```APIDOC ## ANSI-C LZMA Decoder ### Description Requirements and usage for the ANSI-C LZMA Decoder. ### Files Required - LzmaDec.h - LzmaDec.c - Types.h ### Example Application LzmaUtil/LzmaUtil.c uses these files. ``` -------------------------------- ### Manage Cheats with CHEATS Class Source: https://context7.com/tasemulators/desmume/llms.txt Manages various cheat code formats including Action Replay and CodeBreaker, and allows direct memory modification. Supports adding, listing, toggling, updating, removing, and saving cheats. Requires initialization with a file path. ```cpp #include "cheatSystem.h" extern CHEATS* cheats; // Initialize cheat system with a file path cheats->init("/path/to/cheats.dct"); // Add a simple internal cheat (direct memory write) // Parameters: size (1/2/4 bytes), address, value, description, enabled cheats->add(4, 0x02000000, 0x000003E7, "Max Gold", true); // Add Action Replay code const char* arCode = "94000130 FFFB0000\n12345678 00000063"; cheats->add_AR((char*)arCode, "Infinite Health AR", true); // Add CodeBreaker code const char* cbCode = "82345678 0063"; cheats->add_CB((char*)cbCode, "Max Items CB", true); // Get list of all cheats size_t numCheats = cheats->getListSize(); printf("Total cheats: %zu\n", numCheats); // Iterate through cheats cheats->getListReset(); CHEATS_LIST cheatItem; while (cheats->getList(&cheatItem)) { printf("Cheat: %s - %s\n", cheatItem.description, cheatItem.enabled ? "Enabled" : "Disabled"); } // Toggle a cheat on/off cheats->toggle(true, 0); // Enable cheat at index 0 cheats->toggle(false, 1); // Disable cheat at index 1 // Update an existing cheat cheats->update(4, 0x02000000, 0x0000FFFF, "Updated Max Gold", true, 0); // Remove a cheat cheats->remove(2); // Remove cheat at index 2 // Save cheats to file cheats->save(); // Process active cheats (called each frame internally) cheats->process(CHEAT_TYPE_AR); // Load cheats from R4 cheat database CHEATSEXPORT cheatDB; if (cheatDB.load("/path/to/usrcheat.dat")) { const char* gameTitle = cheatDB.getGameTitle(); CHEATS_LIST* dbCheats = cheatDB.getCheats(); size_t dbCount = cheatDB.getCheatsNum(); printf("Found %zu cheats for %s\n", dbCount, gameTitle); } ```