Commit Graph

1973 Commits

Author SHA1 Message Date
Jesse Talavera
740305cc25
Don't reset the VRAM cache if saving a state (#1944)
- This fixes a flickering bug in melonDS DS
2024-01-08 15:20:48 +01:00
Jesse Talavera
8143f54956
Protect savestates while the threaded software renderer is running (#1864)
* First crack at ensuring the render thread doesn't touch GPU state while it's being serialized

* Get rid of the semaphore wait

* Add some extra fields into GPU3D's serialization

* Oops, TempVertexBuffer is already serialized

* Move vertex serialization into its own method

* Lock the GPU3D state when rendering on the render thread or serializing it

* Revert "Lock the GPU3D state when rendering on the render thread or serializing it"

This reverts commit 2f49a551c1.

* Add comments that describe the synchronization within GPU3D_Soft

- I need to understand it before I can solve my actual problem
- Now I do

* Revert "Revert "Lock the GPU3D state when rendering on the render thread or serializing it""

This reverts commit 1977566a6d.

* Let's try locking the GPU3D state throughout NDS::RunFrame

- Just to see what happens

* Slim down the lock's scope

* Narrow the lock's scope some more

* Remove the lock entirely

* Try protecting the GPU3D state with just a mutex

- I'll clean this up once I know it works

* Remove a duplicate method definition

* Add a missing `noexcept` specifier

* Remove an unused function

* Cut some non-hardware state from `GPU3D`'s savestate

* Assume that the next frame after loading a savestate won't be identical

* Actually, it _is_ worth it

* Don't serialize the clip matrix

- It's recalculated anyway

* Serialize `RenderPolygonRAM` as an array of indexes

* Clean up some comments

- I liked the dialogue style, but oh well

* Try restarting the render thread instead of using the lock

- Let's see what happens

* Put the lock back

* Fix some polygon and vertex indexes being saved incorrectly

- Taking the difference between two pointers results in the number of elements, not the number of bytes

* Remove `SoftRenderer::StateBusy` since it turns out we don't need it

- The real synchronization was the friends we made along the way
2024-01-07 23:39:43 +01:00
Eric Warmenhoven
f68f55d002
Reset the JIT when loading savestate (#1937)
The effect of this change is simply to call JitEnableWrite(), which is
necessary on apple silicon
2024-01-03 14:42:08 +01:00
Jesse Talavera
d1cbc41115
Slight fixups with FATStorage (#1934)
* Reload the SD card for `CartSD` and all subclasses

* Make `ROMManager::LoadDLDISDCard` delegate to `GetDLDISDCardArgs`

* Add a method overload for `CartSD::SetSDCard`

* Initialize new SD card images with the correct size

* Sync the old card to the host (if applicable) when move-assigning a new one

* Only sync the old card to the host if it's not read-only

* Remove static state in `FATStorage`

- Replace `FF_ReadStorage` and `FF_WriteStorage` with lambda functions
- Keep open and use the single `File` handle throughout the `FATStorage`'s life
2024-01-03 13:32:17 +01:00
Nadia Holmquist Pedersen
8bfc6df8de TitleManagerDialog: Fix wrong color format 2023-12-31 13:52:58 +01:00
Jesse Talavera
a4b2b0c40d
Resolve or silence some warnings (#1905)
* Resolve some warnings

- Their frequent appearance in the build logs is driving me nuts

* Silence warnings about `offsetof`

* Don't apply `-Wno-invalid-offset` to C, only to C++
2023-12-28 14:54:31 +01:00
Arisotura
345b7439e4 integrate OSD into ScreenPanel and make it nicer 2023-12-28 14:40:37 +01:00
Arisotura
5a08118c87 sfjsh 2023-12-27 21:28:03 +01:00
Jesse Talavera
cbd65a131e
Add alignas specifiers to some arrays based on how they're accessed (#1933)
* Align some two-element `u32` arrays as `u64`s

- To pacify "unaligned read/write" warnings from UBSan

* Align some more arrays based on how they're accessed
2023-12-26 22:09:39 +01:00
Arisotura
ab8938a695 fix OSD scaling on hiDPI screens 2023-12-26 19:32:38 +01:00
Arisotura
f905b6fb93 separate EmuThread to its own file 2023-12-26 19:24:14 +01:00
Arisotura
fd1e4379b9 Merge branch 'master' of github.com:melonDS-emu/melonDS 2023-12-26 19:04:31 +01:00
Arisotura
7f437d48db start cleaning up: move OpenGL stuff out of EmuThread 2023-12-26 19:04:01 +01:00
Jesse Talavera
d55a384c88
Apply some quick hotfixes (#1931) 2023-12-26 16:34:04 +01:00
Nadia Holmquist Pedersen
740489f7a4 Don't call Reset on nullptr 2023-12-26 08:49:02 +01:00
Nadia Holmquist Pedersen
ac3153d86b "Incorrectly" link libslirp to stop its broken build system fucking up
our linker flags
2023-12-26 08:14:30 +01:00
Nadia Holmquist Pedersen
f16de402cf Screen.cpp: include missing headers 2023-12-26 04:26:38 +01:00
Arisotura
5c90cb939d oops 2023-12-25 22:52:44 +01:00
Arisotura
80c6dd524b add convenience method to Window class for OSD messages 2023-12-25 16:34:29 +01:00
Arisotura
6a1232b9a9 move MainWindow and Screen stuff to separate files; WIP 2023-12-24 15:11:30 +01:00
Samuel Magnan
f580d20a7b
Support GBA .sav file with appended .rtc (#1927)
* Support GBA .sav file with appended .rtc

* Change comment
2023-12-24 01:09:43 +01:00
Arisotura
de4ae9dd92 fix possible crash 2023-12-23 23:59:59 +01:00
RSDuck
989b93c92a do not access NDS object emulation is paused 2023-12-22 23:30:59 +01:00
Nadia Holmquist Pedersen
521fc249a3 Don't try to call transferLayout on non-GL ScreenPanel 2023-12-22 02:17:26 +01:00
Nadia Holmquist Pedersen
752b37ed82 Attempt to get rid of leftover QSharedMemory instance after crash 2023-12-22 01:35:45 +01:00
RSDuck
084747abc5 Reset DS object directly after creation 2023-12-21 22:15:12 +01:00
RSDuck
ed650f2b46 call Reset on 3D renderer object 2023-12-21 21:43:57 +01:00
Nadia Holmquist Pedersen
fd3c349735 Check Q_OS_UNIX define instead 2023-12-20 21:38:55 +01:00
Daniel Simon
6c6318b63b Fix generic icon when using Wayland 2023-12-20 21:38:55 +01:00
Jesse Talavera
01f8ad009e
Wrap the EnableJIT initialization in an #ifdef (#1922) 2023-12-20 14:25:49 +01:00
Jesse Talavera
4b4239de62
Set NDS::EnableJIT in the constructor (#1921) 2023-12-19 15:15:35 +01:00
Jesse Talavera
1bec2a9293
Fix an incorrect use of std::move (#1919)
- When I adapted `GBACart::ParseROM` to use `unique_ptr` instead of a plain pointer, I forgot to remove the code that copied the SRAM data
- That code was made unnecessary because of the move
2023-12-16 00:05:43 +01:00
Jesse Talavera
eedb0ba478
Add a call to std::move that I missed (#1917) 2023-12-15 20:52:35 +01:00
Jesse Talavera
e1821d0023
Simplify the SRAM's representation in NDSCartArgs (#1914)
* Simplify the SRAM's representation in  `NDSCartArgs`

- I overthought this one.
- I could've just checked `args && args->SRAM`, but then some other poor bastard might make this mistake.
- Don't mix `pair`, `optional`, and `unique_ptr` all at once, kids.

* Fix a `nullptr` read
2023-12-15 14:56:10 +01:00
Jesse Talavera
24c402af51
Fix detection of native NDS ARM BIOS images (#1910)
* Fix detection of native NDS ARM BIOS images

- Instead of checking for built-in BIOS images, now the altered methods check for native ones
- The CRC32 must match exactly; patched BIOS images will result in `false`

* Encapsulate `NDS::ARM9BIOS` and `ARM7BIOS`

- Also compute the checksum only when setting the BIOS
2023-12-15 14:54:41 +01:00
Jesse Talavera
c867a7f1c0
Make the initial 3D renderer configurable via NDSArgs (#1913)
* Allow 3D renderers to be created without passing `GPU` to the constructor

* Make the initial 3D renderer configurable via `NDSArgs`

* Fix a compiler error
2023-12-15 14:53:31 +01:00
Adrian Siekierka
6f47c9ed4c
Support emulating R4 Revolution/M3DS Simply cartridges. (#1854)
* Support emulating R4 Revolution/M3DS Simply cartridges.

* NDSCartR4: Write state information to savestate file.

* NDSCart: Use strncmp instead of strcmp for R4 detection.

* NDSCartR4: stylistic improvements

* NDSCartR4: rudimentary Ace3DS support

* NDSCartR4: fix boot when firmware enabled

* NDSCartR4: Fix for namespace changes

---------

Co-authored-by: RSDuck <RSDuck@users.noreply.github.com>
2023-12-15 08:19:53 +01:00
Jesse Talavera
9bfc9c08ff
Sprinkle const around where appropriate (#1909)
* Sprinkle `const` around where appropriate

- This will make it easier to use `NDS` objects in `const` contexts (e.g. `const` parameters or methods)

* Remove the `const` qualifier on `DSi_DSP::DSPRead16`

- MMIO reads can be non-pure, so this may not be `const` in the future
2023-12-12 11:07:22 +01:00
Jaklyy
2cba2e783a
fix default emu settings tab (#1912) 2023-12-12 00:04:04 +01:00
Nadia Holmquist Pedersen
81219a9f5d Fix some conflicts with windows.h in some configurations
Fixes build in the MSYS2 Clang/ClangARM64 environments.
2023-12-11 10:59:05 +01:00
RSDuck
082310d5d5 hopefully reset all GPU3D attributes properly 2023-12-08 23:42:08 +01:00
Nadia Holmquist Pedersen
6949100446 Fix GBA<->DS comm not working when using FreeBIOS
Thanks CasualPokePlayer for pointing this out
2023-12-08 18:34:38 +01:00
Nadia Holmquist Pedersen
5ef35a4ccf Don't try to poke at the header on deinit if MPQueue is nullptr 2023-12-08 17:39:56 +01:00
Jesse Talavera-Greenberg
5dac65f52e Fix some minor instances of undefined behavior 2023-12-08 17:19:00 +01:00
Jesse Talavera-Greenberg
bbecab6cb0 Correctly use the refactored JitEnableWrite 2023-12-08 17:19:00 +01:00
Jesse Talavera-Greenberg
72d4eba477 Rearrange some #includes 2023-12-08 17:19:00 +01:00
Jesse Talavera-Greenberg
7cef13031f Add some headers that were transitively included by the JIT 2023-12-08 17:19:00 +01:00
Jesse Talavera-Greenberg
399a6af91c Move some constants to MemConstants.h 2023-12-08 17:19:00 +01:00
Jesse Talavera-Greenberg
53e5aa6298 Exclude JIT-related declarations more aggressively 2023-12-08 17:19:00 +01:00
Jesse Talavera-Greenberg
733769303c Add override to the ARM64 JIT's destructor 2023-12-08 17:19:00 +01:00
Jesse Talavera-Greenberg
582a421447 Don't set the JIT args if the JIT is off 2023-12-08 17:19:00 +01:00
Jesse Talavera-Greenberg
644d190e98 Add stubs for NDS::IsJITEnabled and SetJITArgs for when the JIT is excluded 2023-12-08 17:19:00 +01:00
Jesse Talavera-Greenberg
f4377e4f0f Remove a loose qualifier 2023-12-08 17:19:00 +01:00
Jesse Talavera-Greenberg
2a35af5bb9 Soften restrictions around ARMJIT_Memory::RemapNWRAM
- If in NDS mode, return instead of `assert`ing
- Use `static_cast` and `ConsoleType` instead of `dynamic_cast`
2023-12-08 17:19:00 +01:00
CasualPokePlayer
1b7b5106e2 FreeBIOS: Ensure upper 16 bits are cleared in the initial crc16 value.
Fixes Castlevania: Dawn of Sorrow's checksumming which uses crc16 swi and has garbage in the upper 16 bits of r0.
The official BIOS would seem to implicitly clear these upper 16 bits.
2023-12-06 16:51:22 +01:00
Jesse Talavera
090627b3c1
Remove the last ConfigEntry state (#1902)
* Get rid of `ConfigEntry::ExternalBIOSEnable`

- Now the BIOS files themselves are checked
- The frontend's `Config::ExternalBIOSEnable` is not affected

* Add `JITArgs`

* Pass the JIT status to the `ARM` constructors

* Encapsulate `NDS::EnableJIT`

* Pass `JITArgs` to `ARMJIT`'s constructor

* Remove the `JIT_*` `ConfigEntry`s in favor of members

- Allow all the JIT args to be set with `NDS::SetJITArgs`
- Encapsulate the JIT-related parameters in `ARMJIT` so they can reset the block cache if changed
- Update the active (or newly-created) console in the frontend with adjusted JIT args

* Make audio bit depth and interpolation configurable in `NDSArgs`

- Define enums for both
- Give those settings default values in `NDSArgs`
- Remove `ConfigEntry::AudioBitDepth`
- Initialize these settings in the relevant SPU constructors

* Move the last DSi-specific logic in `Reset` to its own subclass

* Remove `ConfigEntry::DSi_FullBIOSBoot`

- Add members to `DSi` instead for getting and setting this
- Update the frontend to accommodate these changes

* Oops, missed a spot

* Remove `ConfigEntry::Firm_MAC` and `Platform::GetConfigArray`

- Also move the MAC parsing code to `ROMManager`

* Remove the last `ConfigEntry` state

- Make GDB support configurable via members

* Add some `#ifdef`s that I'd almost forgotten
2023-12-05 16:47:16 +01:00
Jesse Talavera
ae91d89f7c
Use a constexpr-friendly cosine implementation (#1903) 2023-12-05 12:41:28 +01:00
Jesse Talavera
2e8cca9ca1
Initialize the framebuffers within the constructor (#1901) 2023-12-04 17:57:51 +01:00
Jesse Talavera
bb42c8b639
Refactor how save data (including SD cards) is initialized (#1898)
* Remove `FATStorage::Open` and `FATStorage::Close`

- That's what the constructor and destructor are for, respectively

* Add `FATStorage::IsReadOnly`

* Slight cleanup of `FATStorage`

- Make it move-constructible and move-assignable
- Represent the absence of a sync directory with `std::optional`, not an empty string
- Add `FATStorageArgs` for later use

* Refactor `CartHomebrew` to accept an optional `FATStorageArgs`

- `CartHomebrew` uses it to load an SD card image
- Not passing a `FATStorage` directly because we won't know if we need to load the card until we parse the ROM
- Store the `FATStorage` inside a `std::optional` instead of a pointer
- `CartHomebrew::Reset` no longer reloads the SD card; the frontend needs to set it with the `SetSDCard` method

* Close `NANDImage::CurFile` when move-assigning

- Whoops

* Add `Args.h`

- To construct a `NDS` or `DSi` with arguments
- Mostly intended for system files

* Fix incorrect `final` placement

* Refactor how `DSi`'s NAND and SD card are set

- Provide them via a `DSiArgs` argument in the constructor
- Give `DSi_MMCStorage` ownership of the `NANDImage` or `FATStorage` as needed, and expose getters/setters
- Replace `DSi_SDHost::Ports` with a `array<unique_ptr, 2>` to reduce the risk of leaks
- Store `DSi_MMCStorage`'s disk images in a `std::variant`
- The SD card and NAND image are no longer reset in `Reset()`; the frontend will need to do that itself

* Add getters/setters on `DSi` itself for its storage media

* Remove newly-unused `Platform::ConfigEntry`s

* Use `DSi::SetNAND` in the frontend

* Add `EmuThread::NeedToRecreateConsole`

* Document `NDSArgs` and give its fields default values

* Refactor how system files are loaded upon construction

- Pass `NDSArgs&&` into `NDS`'s constructor
- Use `std::array` for the emulator's BIOS images and the built-in FreeBIOS, to simplify copying and comparison
- Initialize the BIOS, firmware, and SD cards from `NDSArgs` or `DSiArgs`
- Add a new default constructor for `NDS` (not `DSi`) that initializes the DS with default system files
- Embed `FirmwareMem::Firmware` directly instead of in a `unique_ptr`
- `SPIHost` now takes a `Firmware&&` that it forwards to `FirmwareMem`
- Add `Firmware` getters/setters plus `const` variants for `NDS`, `Firmware`, and `FirmwareMem`
- Simplify installation of firmware

* Initialize the DSi BIOS in the constructor

- Change `DSi::ARM9iBIOS` and `ARM7iBIOS` to `std::array`

* Update the frontend to reflect the core's changes

* Remove `DSi_SDHost::CloseHandles`

* Pass `nullopt` instead of the empty string when folder sync is off

* Deduplicate ROM extraction logic

- `LoadGBAROM` and `LoadROM` now delegate to `LoadROMData`
- Also use `unique_ptr` instead of `new[]`

* Oops, missed some `get()`'s

* Move `NDS::IsLoadedARM9BIOSBuiltIn` to the header

- So it's likelier to be inlined
- Same for the ARM7 version

* Remove `NDS::SetConsoleType`

* Add `NDS::SetFirmware`

* Move `GBACart::SetupSave` to be `protected`

- It was only ever used inside the class

* Rename `GBACart::LoadSave` to `SetSaveMemory`

- Same for the cart slot

* Declare `GBACartSlot` as a friend of `GBACart::CartCommon`

* Revise `GBACartSlot`'s getters and setters

- Rename `InsertROM` and `LoadROM` to `SetCart`
- Add a `GetCart` method

* Clean up getters and setters for NDS and GBA carts

* Clean up how carts are inserted into the slots

- Remove setters that operate directly on pointers, to simplify error-handling (use ParseROM instead)
- Add overloads for all carts that accept a `const u8*` (to copy the ROM data) and a `unique_ptr<u8[]>` (to move the ROM data)
- Store all ROM and RAM data in `unique_ptr`
- Default-initialize all fields
- Simplify constructors and destructors, inheriting where applicable

* Refactor GBA save data insertion

- Make `SetupSave` private and non-virtual and move its logic to be in `SetSaveMemory`
- Add overloads for setting save data in the constructor
- Update the SRAM completely in `SetSaveMemory`

* Clean up `NDSCart::CartCommon::SetSaveMemory`

- Move its declaration next to the other `SaveMemory` methods
- Move its (empty) implementation to the header

* Add some comments

* Add Utils.cpp and Utils.h

* Rename some functions in Utils for clarity

* Add `GBACart::ParseROM` and `NDSCart::ParseROM` overloads that accept `unique_ptr<u8[]>`

- The `u8*` overloads delegate to these new overloads
- Also move `SetupSave` for both kinds of carts to be private non-virtual methods

* Finalize the `NDSCart` refactor

- Add `NDSCartArgs` to pass to `ParseROM`
- Add SRAM arguments for all retail carts
- Initialize SRAM inside the constructor
- Delegate to other constructors where possible

* Replace `ROMManager::NDSSave` and `GBASave` with `unique_ptr`

* Make both cart slots return the previously-inserted cart in `EjectCart`

- Primarily intended for reusing carts when resetting the console

* Make `NDS::EjectCart` return the old cart

* Initialize both cart slots with the provided ROM (if any)

* Make `NDS::EjectGBACart` return the ejected cart

* Clean up some comments in Args.h

* Rename `ROMManager::LoadBIOS` to `BootToMenu`

- Clarifies the intent

* Add `ROMManager::LoadDLDISDCard`

* Add a doc comment

* Refactor how the `NDS` is created or updated

- Rewrite `CreateConsole` to read from `Config` and load system files, but accept carts as arguments
- Fail without creating an `NDS` if any required system file doesn't load
- Add `UpdateConsole`, which delegates to `CreateConsole` if switching modes or starting the app
- Use `std::variant` to indicate whether a cart should be removed, inserted, or reused
- Load all system files (plus SD cards) in `UpdateConsole`
- Eject the cart and reinsert it into the new console if applicable

* Respect some more `Config` settings in the `Load*` functions

* Remove `InstallNAND` in favor of `LoadNAND`

* Fix some potential bugs in `LoadROMData`

* Oops, forgot to delete the definition of `InstallNAND`

* Add functions to get `FATStorageArgs`

- Not the cards themselves, but to get the arguments you _would_ use to load the cards

* Refactor `ROMManager::LoadROM`

- Load the ROM and save data before trying to initialize the console

* Clean up `ROMManager::Reset` and `BootToMenu`

- Let `EmuThread::UpdateConsole` do the heavy lifting

* Clean up `LoadGBAROM`

* Remove some unused functions

* Set the default DSi BIOS to be broken in `DSiArgs`

* Respect `Config::DSiFullBIOSBoot` when loading DSi BIOS files

* Remove some more unused functions

* Remove redundant `virtual` specifiers

* Refactor `NDSCart::CartCommon::Type()` to return a member instead of a constant

- One less virtual dispatch
- The cart type is read in `NDSCartSlot::DoSavestate`, which is a path downstream (due to rewinding)

* Remove a hash that I computed for debugging purposes

* Make `ByteSwap` `constexpr`

* Remove an unused `#include`

* Remove unnecessary functions from the NDS carts

- Mostly overrides that added nothing

* Default-initialize all NDSCart fields

* Make `GBACart::Type()` not rely on virtual dispatch

- `GBACartSlot::DoSavestate` calls it, and savestates can be a hot path downstream

* Don't forget to reset the base class in `CartGameSolarSensor::Reset()`

* Remove redundant `virtual` specifiers

* Default-initialize some fields in `GBACart`

* Fix ROMs not loading from archives in the frontend

- Whoops

* Change how the `Firmware` member is declared

* Forgot an include in Utils.cpp

* Rename `FirmwareMem::Firmware` to `FirmwareData` to fix a build error on Linux

- One of these days I'll convince you people to let me use `camelCaseMemberNames`

* Add `override` to places in `DSi_MMCStorage` that warrant it

* Fix firmware saving on the frontend

- Remove `GetConfigString` and `ConfigEntry::WifiSettingsPath` while I'm at it

* Add a non-const `GetNAND()`
2023-12-04 17:57:22 +01:00
Jesse Talavera
da8d413ad9
Slight cleanup to SPU (#1900)
* Move `SPUChannel` and `SPUCaptureUnit` to be stored inside `array`s instead of allocated separately

* Default-initialize most of `SPU`'s fields

* Generate the interpolation tables at compile-time with `constexpr`

- Now it's faster and thread-safe

* Slight cleanup in SPU

- Iniitialize most fields in the class declaration

* Mark `SPU` as `explicit`
2023-12-04 17:56:01 +01:00
Jesse Talavera-Greenberg
7caddf9615
Clean up the 3D renderer for enhanced flexibility (#1895)
* Give `GPU2D::Unit` a virtual destructor

- Undefined behavior avoided!

* Add an `array2d` alias

* Move various parts of `GPU2D::SoftRenderer` to `constexpr`

- `SoftRenderer::MosaicTable` is now initialized at compile-time
- Most of the `SoftRenderer::Color*` functions are now `constexpr`
- The aforementioned functions are used with a constant value in at least one place, so they'll be at least partially computed at compile-time

* Generalize `GLRenderer::PrepareCaptureFrame`

- Declare it in the base `Renderer3D` class, but make it empty

* Remove unneeded `virtual` specifiers

* Store `Framebuffer`'s memory in `unique_ptr`s

- Reduce the risk of leaks this way

* Clean up how `GLCompositor` is initialized

- Return it as an `std::optional` instead of a `std::unique_ptr`
- Make `GLCompositor` movable
- Replace `GLCompositor`'s plain arrays with `std::array` to simplify moving

* Pass `GPU` to `GLCompositor`'s important functions instead of passing it to the constructor

* Move `GLCompositor` to be a field within `GLRenderer`

- Some methods were moved up and made `virtual`

* Fix some linker errors

* Set the renderer in the frontend

* Remove unneeded `virtual` specifiers

* Remove `RenderSettings` in favor of just exposing the relevant member variables

* Update the frontend to accommodate the core changes

* Add `constexpr` and `const` to places in the interpolator

* Qualify references to `size_t`

* Construct the `optional` directly instead of using `make_optional`

- It makes the Linux build choke
- I think it's because `GLCompositor`'s constructor is `private`
2023-11-29 15:23:11 +01:00
Jesse Talavera-Greenberg
e973236203
Refactor NDS and DSi to be objects (#1893)
* First crack at refactoring NDS and DSi into objects

- Remove all global/`static` variables in `NDS` and related classes
- Rely more on virtual dispatch when we need to pick methods at runtime
- Pass `NDS&` or `DSi&` to its constituent components where necessary
- Introduce some headers or move some definitions to break `#include` cycles

* Refactor the frontend to accommodate the core's changes

* Move up `SchedList`'s declaration

- Move it to before the components are initialized so the `map`s inside are initialized
- Fields in C++ are initialized in the order they're declared

* Fix a crash when allocating memory

* Fix JIT-free builds

* Fix GDB-free builds

* Fix Linux builds

- Explicitly qualify some member types in NDS, since they share the same name as their classes

* Remove an unnecessary template argument

- This was causing the build to fail on macOS

* Fix ARM and Android builds

* Rename `Constants.h` to `MemConstants.h`

* Add `NDS::IsRunning()`

* Use an `#include` guard instead of `#pragma once`
2023-11-28 23:16:41 +01:00
Adrian Siekierka
c84cb17462
DSi_SD: implement command 17, 24 (#1877) 2023-11-26 20:07:31 +01:00
Jaklyy
ad7b1a8c61
only fill edges when translucent if blending is enabled (#1882) 2023-11-25 18:40:07 +01:00
Jesse Talavera-Greenberg
346dd4006e
Move all core types into namespaces (#1886)
* Reorganize namespaces

- Most types are now moved into the `melonDS` namespace
- Only good chance to do this for a while, since a big refactor is next

* Fix the build
2023-11-25 18:32:09 +01:00
Jesse Talavera-Greenberg
651b0f680c
Use Platform::File calls in NDS::debug (#1888) 2023-11-24 19:17:22 +01:00
Rayyan Ansari
679c37ddce
Add support for saving animated icons
Add support for exporting animated DSi icons as GIF using the
header-only gif.h library.
2023-11-23 18:50:23 +00:00
Jesse Talavera-Greenberg
544fefa27f
Refactor the JIT to be object-oriented (#1879)
* Move TinyVector to a new file

- So it's less sensitive to #include ordering

* Forgot to include assert.h

* Refactor ARMJIT_Memory into an object

* Oops, forgot a declaration

* Refactor ARMJIT to be contained in an object

* Remove an unused function declaration

* Add a missing #include

* Remove a now-unused global

* Use ARMJIT_Memory's own memory access functions

* Fix some omissions in the ARM JIT

* Move libandroid to be a member of ARMJIT_Memory instead of a global

* Default-initialize most fields in ARMJIT_Compiler.h

* Define NOOP_IF_NO_JIT

* Finish refactoring the JIT to be object-oriented
2023-11-18 16:40:54 +01:00
Nadia Holmquist Pedersen
f2d7a29015 fix forgotten <array> include 2023-11-15 17:26:01 +01:00
orbea
e63e29ca91 DSi_Camera: fix gcc-14 build issue
melonDS/src/DSi_Camera.cpp:190:23: error: 'clamp' is not a member of 'std'
  190 |             r1 = std::clamp(r1, 0, 255); g1 = std::clamp(g1, 0, 255); b1 = std::clamp(b1, 0, 255);
      |                       ^~~~~
2023-11-11 19:53:00 +01:00
Jesse Talavera-Greenberg
4558be0d8e
Refactor the GPU to be object-oriented (#1873)
* Refactor GPU3D to be an object

- Who has two thumbs and is the sworn enemy of global state? This guy!

* Refactor GPU itself to be an object

- Wow, it's used in a lot of places
- Also introduce a new `Melon` namespace for a few classes
- I expect other classes will be moved into `Melon` over time

* Change signature of Renderer3D::SetRenderSettings

- Make it noexcept, and its argument const

* Remove some stray whitespace
2023-11-09 21:54:51 +01:00
Jesse Talavera-Greenberg
88072a02c5
Move NDSCart-related global state into objects (#1871)
* Move NDSCart-related global state into objects

- RAII will now do the heavy lifting
- Mark some methods as const or noexcept

* Move GBACart-related global state into objects (#1870)

- RAII will now do the heavy lifting
- Mark some methods as const or noexcept
- Once the `NDS` object is finalized, most of these `assert`s can go away

* Make AREngine::RunCheat public (#1872)

- I use it directly in melonDS DS to apply single cheats without using ARCodeFile
- Before the AREngine refactor I could just redeclare the function in my code
- Now I can't
2023-11-09 18:57:16 +01:00
Jesse Talavera-Greenberg
3d3e4240a0
Make AREngine::RunCheat public (#1872)
- I use it directly in melonDS DS to apply single cheats without using ARCodeFile
- Before the AREngine refactor I could just redeclare the function in my code
- Now I can't
2023-11-08 22:21:30 +01:00
Jesse Talavera-Greenberg
8b47178add
Move GBACart-related global state into objects (#1870)
- RAII will now do the heavy lifting
- Mark some methods as const or noexcept
- Once the `NDS` object is finalized, most of these `assert`s can go away
2023-11-08 22:21:21 +01:00
Jaklyy
b4ff911fa3
Fix regression caused by change to front face polygon culling (#1820)
* fix regression with facing view

Only the check for a polygon being counter-clockwise is supposed to be <=

* only use dot < 0 for 'cull front face' polygons

this is the fix.
2023-11-07 21:22:25 +01:00
Nadia Holmquist Pedersen
24a33e505e Also exclude .note.GNU-stack section on Windows arm64 2023-11-07 10:53:01 +01:00
Rayyan Ansari
8fa9705079
ArchiveUtil: use signed return type instead of unsigned
The ExtractFileFromArchive function can sometimes return -1 on error,
however the function's return type was specified as u32, which would
mean that it would instead be represented as the maximum value.
Change the function's return type to the signed s32 instead, and
correct uses.
2023-11-06 21:27:09 +00:00
Rayyan Ansari
2b3bba512e
Fix some memory leaks
Free some objects that were allocated with new but not deleted, and in
one case, do not set a pointer to nullptr before deleting, as this
results in a memory leak due to memory allocated not being freed.
2023-11-06 20:25:32 +00:00
Rayyan Ansari
0e4d082361
ROMManager: initialise filedata to nullptr
If a user manages to open a file as a ROM that is greater than 1 GiB,
it will cause a segmentation fault (a crash) in LoadROM due to a delete
being called on an uninitialised pointer, which is undefined behaviour.

Initialise filedata to nullptr to prevent this, as deleting a null
pointer is defined as a no-op.
2023-11-05 20:21:16 +00:00
Rayyan Ansari
df571078cf
CameraManager: wait for camera to be loaded
In QCamera in Qt 5, the camera is required to have been loaded before
querying its settings and resolutions. Doing so without loading being
finished would result in the returned list being empty.
See https://doc.qt.io/qt-5.15/qcamera.html#supportedViewfinderSettings

Add a QEventLoop that waits for the state to change from Loading to
Loaded before supportedViewfinderSettings() is called to ensure that
valid information is returned.

(Fixes my camera being blank in preview, same issue also presumed
to occur when camera is needed in game, fix tested on a USB camera on
a Linux system and Qt 5.)
2023-11-05 15:52:13 +00:00
Arisotura
0aff9471c5 fuck every aspect of this 2023-11-05 15:38:22 +01:00
Arisotura
11c22f077d convert DSP 2023-11-05 11:58:50 +01:00
Arisotura
54ebf1b1b2 convert DSi I2C and camera 2023-11-04 19:42:36 +01:00
Arisotura
7837c169a1 convert AES 2023-11-04 17:46:52 +01:00
Arisotura
8f1b0d4a05 convert AREngine 2023-11-04 17:28:16 +01:00
Arisotura
2bd09eafeb convert Wifi and WifiAP 2023-11-04 17:00:12 +01:00
Arisotura
76976fef30 convert SPU to OOP 2023-11-04 14:20:58 +01:00
Arisotura
ac38faef14 update copyright years 2023-11-04 00:21:46 +01:00
Arisotura
f188c2cf1a hopefully get the compiler to shut up 2023-11-03 21:33:13 +01:00
Arisotura
e4f4e94694 convert RTC to OOP 2023-11-03 21:20:09 +01:00
Arisotura
440b356674 get this started: refactor SPI in OOP 2023-11-03 20:17:00 +01:00
Arisotura
70c6750561 better, less hacky, more OOP-friendly scheduler design 2023-11-02 21:04:09 +01:00
Arisotura
5ccd3916ff better be safe than sorry 2023-11-02 15:46:35 +01:00
Arisotura
2959d089fe fix weird hang when returning to the DSi menu 2023-11-02 15:31:26 +01:00
Arisotura
bff7a0d114 make linebreaks in text files not weird 2023-11-02 12:40:49 +01:00
Arisotura
eb13bce6e7 RTC: add the DSi alarm expansion registers 2023-11-02 12:21:59 +01:00
Jesse Talavera-Greenberg
d11ba63bb0
Fix compilation with the GDB stub disabled (#1863) 2023-11-01 16:02:15 +01:00
Arisotura
3b4fdea376 minor cleanup 2023-11-01 12:03:35 +01:00
Nadia Holmquist Pedersen
b8963b0738 use a grid layout in the date/time dialog so Qt will behave 2023-10-30 19:37:39 +01:00
Arisotura
e89b8a871b fdsfd 2023-10-30 18:40:26 +01:00
Arisotura
9a450f5f28
RTC revamp (#1867)
* get this started

* implement DSi RTC commands

* set up RTC clock timer. lay down basic idea of a clock.

* make the date/time registers writable

* move RTC state to its own structure, to make it easier to deal with

* more RTC work
lay base for date/time dialog

* get the bulk of the RTC functionality going

* much simpler design for RTC stuff

* aha, that is what it is

* start working on the RTC IRQ

* implement all types of RTC IRQ

* start refining sleep mode. code still kinda sucks.

* implement keypad IRQ

* refine it some more

* shut the fuck uuuuuupppppppppppppp
2023-10-30 18:37:49 +01:00
Jesse Talavera-Greenberg
21590b0709
Miscellaneous DSi NAND fixes (#1852)
* Replace some standard I/O calls with Platform equivalents

- I missed a spot when I submitted that PR a few months ago

* Include <memory> in DSi_NAND.h

- Because it uses unique_ptr

* Split DSi_NAND::ReadHardwareInfo into ReadSerialData and ReadHardwareInfoN

* Add a RegionMask enum

* Move DSi NAND patching to the frontend

* Add DSiSupportedLanguageMask

- Not currently used by the frontend, but I use it in melonDS DS

* Remove some Platform::ConfigEntry values

- The core no longer needs to know about them
- The corresponding Config values are unchanged

* Mark NANDMount's destructor as noexcept
2023-10-24 23:28:14 +02:00
Jesse Talavera-Greenberg
8c4e5af737
Slight polish to DMA (#1856)
* Slight polish to DMA

- Default-initialize members explicitly
- Mark some methods as const noexcept
- Initialize DMA::MRAMBurstTable to DMATiming::MRAMDummy
- Use the default destructor

* Move DMA_Timings definitions to a source file

- To ensure constant and unique addresses

* Include some extra DMA members in the savestate

* Simplify serializing the DMA table

- Extend the dummy table to 256 bytes (same length as the real ones)

* Revert the type change to DMA::DoSavestate

* Keep the MRAMBurstTable inside the DMA class, instead of using a pointer

- If we use a pointer to an external table, then we can't use it in savestates (else that external table gets overwritten)
2023-10-24 23:27:55 +02:00
PoroCYon
3ab752b8ca
GDB stub (#1583)
* gdbstub beginnings

* gdbstub: finish gdb impl things, next up is integration with melonDS

* holy fuck the gdbstub works

* gdb breakpoints work, but there's a mysterious crash on continue

* fix memory corruption that sometimes happened, and make resetting the console thru gdb work

* remove some gdb debug printing

* fix things in gdbstub

* separate option for enabling gdbstub

* add mode-dependent CPU registers

* C++ize the GDBstub code

* add gdbstub config in emu settings dialog

* make sure gdb is disabled when jit is enabled

* Remove unnecessary compiler flags, mark ARMJIT assembly code as no-execute-stack

This hardens the binary a little bit against common exploitation methods

* add option to wait for debugger attach on startup

* only insert GNU stack notes on linux

* disable gdbstub enable checkbox when jit is enabled

* fix non-linux incompatibilities

* enable gdbstub by default

* fix issues with gdbstub settings disable stuff

* format stuff

* update gdb test code

* Fix segfault when calling StubCallbacks->GetCPU()

C++ overrides are hard. Please I'm just a lowly C programmer.

* fix packet size not being sent correctly

Thanks to @GlowingUmbreon on Github for troubleshooting this

* fix select(2) calls (i should read docs more properly)

* fix GDB command sequencing/parsing issue (hopefully)

* [GDB] implement no-ack mode

* fix sending ack on handshake

* get lldb to work
2023-10-22 15:35:31 +02:00
RSDuck
3d58a338a1 store pc+12 when storing r15 2023-10-22 15:21:03 +02:00
Jesse Talavera-Greenberg
d4e51f8060
Refactor DSi_NAND (#1844)
* Refactor diskio's contents

- Change ff_disk_read_cb/write_cb into a std::function instead of a raw pointer
- Add const specifiers as needed

* Refactor DSi_NAND to manage the file system's mounted lifetime with RAII

* Split NANDMount into NANDMount and NANDImage

- NANDImage is used for information about the NAND that doesn't require decryption or filesystem access
- NANDMount is used to actually access the file system
- Both classes manage their respective resources (the NAND file handle and the NAND's mount) with RAII
- Also split the file loading into another function that I will remove in a later PR

* Make NANDMount immovable

* Remove NAND-loading code that I had sectioned off into a function

- Incomplete copypasta
- I must have gotten distracted

* Tidy up NANDImage's initialization

- Don't unmount the disk image if the constructor fails (that's NANDMount's job now)
- Only assign CurFile if the constructor succeeds

* Add some const-correctness

* Move DSi NAND initialization to the frontend

- The NANDImage is now installed via a unique_ptr in DSi

* Remove Platform::DSi_NANDPath

- Not Config::DSiNANDPath; that can still be configured as usual
- The core no longer needs to care
2023-10-11 17:20:05 +02:00
Jesse Talavera-Greenberg
b2fcff97c1
Add some structs for files that DSi_NAND reads (#1842)
* Add DSiFirmwareSystemSettings

* Replace DSiFirmwareSystemSettings::TouchCalibration fields with std::arrays

- So assignment can be done in one line

* Make DSiFirmwareSystemSettings a union

- So its bytes can be accessed

* Add a comment

* Use DSiFirmwareSystemSettings instead of raw byte offsets

* Add definitions for DSiSerialData and DSiHardwareInfoN

* Move DSiFirmwareSystemSettings's hash update logic into its own method
2023-10-02 17:54:17 +02:00
Jesse Talavera-Greenberg
bb09ce7d70
Replace DSi_NAND's uses of sprintf with snprintf (#1841)
- Now clang oughta stop complaining
2023-10-01 21:58:56 +02:00
Jesse Talavera-Greenberg
f8fdc77e43
Wrap CurGLCompositor cleanup in an #ifdef (#1837) 2023-09-24 18:48:37 +02:00
Jesse Talavera-Greenberg
9d9ba83731
Clean up some rendering-related resources in DeInit (#1836)
- The unique_ptr destructors will take care of the cleanup
2023-09-24 18:33:14 +02:00
Jesse Talavera-Greenberg
7d4a7969d9
Ensure that the new firmware is installed when resetting (#1834)
- It might have been changed in the settings
2023-09-21 13:54:17 +02:00
RSDuck
6ca02aab2c only recalculate extended access point checksum when firmware is a DSi one 2023-09-20 19:17:26 +02:00
Jesse Talavera-Greenberg
5bfe51e670
Refactor the core's handling of firmware and BIOS images to rely less on the file system (#1826)
* Introduce firmware-related structs

* Fix some indents

* Move the generated firmware identifier to a constant

* Document the WifiAccessPoint constructors

* Add some constants

* Remove a stray comment

* Implement Firmware::UserData

* Add Firmware::Mask

* Document Firmware::Buffer

* Add a Firmware constructor that uses a FileHandle

* Set the default username in UserData

* Update the UserData checksum

* Forgot to include Platform.h

* Remove some redundant assignments in the default Firmware constructor

* const-ify CRC16

* Replace the plain Firmware buffer with a Firmware object

- Remove some functions that were reimplemented in the Firmware constructors

* Fix some crashes due to undefined behavior

* Fix the user data initialization

- Initialize both user data objects to default
- Set both user data objects to the same touch screen calibration

* Follow the DS logic in determining which user data section is current

* Remove an unneeded include

* Remove another unneeded include

* Initialize FirmwareMask in Firmware::Firmware

* Use the DEFAULT_SSID constant

* Add SPI_Firmware::InstallFirmware and SPI_Firmware::RemoveFirmware

* Move a logging call to after the file is written

* Add a SaveManager for the firmware

* Touch up the SPI_Firmware::Firmware declaration

* Move all firmware loading and customization to the frontend

* Call Platform::WriteFirmware when it's time to write the firmware back to disk

* Fix some missing stuff

* Remove the Get* functions from SPI_Firmware in favor of GetFirmware()

* Implement SPI_Firmware::DeInit in terms of RemoveFirmware

* Add Firmware::UpdateChecksums

* Fix an incorrect length

* Update all checksums in the firmware after setting touch screen calibration data

* Use the Firmware object's Position methods

* Remove register fields from the Firmware object

* Install the firmware before seeing if direct boot is necessary

* Install the firmware before calling NDS::Reset in LoadROM

* Slight cleanup in ROMManager

* Fix the default access point name

* Shorten the various getters in Firmware

* Add qualifiers for certain uses of firmware types

- GCC can get picky if -fpermissive isn't defined

* Add an InstallFirmware overload that takes a unique_ptr

* Log when firmware is added or removed

* Don't clear the firmware in SPI_Firmware::Init

- The original code didn't, it just set the pointer to nullptr

* Fix a typo

* Write back the full firmware if it's not generated

* Move the FreeBIOS to an external file

* Load wfcsettings.bin into the correct part of the generated firmware blob

* Load BIOS files in the frontend, not in the core

* Fix logging the firmware ID

* Add some utility functions

* Mark Firmware's constructors as explicit

* Remove obsolete ConfigEntry values

* Include <locale> explicitly in ROMManager

* Fix up some includes

* Add Firmware::IsBootable()

* Add a newline to a log entry

- Whoops

* Log the number of bytes written out in SaveManager

* Mark FirmwareHeader's constructor as explicit

* Clean up GenerateDefaultFirmware and LoadFirmwareFromFile

- Now they return a pair instead of two by-ref values

* Refactor SaveManager a little bit

- Manage its buffers as unique_ptrs to mitigate leaks
- Reallocate the internal buffer if SetPath is asked to reload the file (and the new length is different)

* Remove some stray parens

* Fix some firmware-related bugs I introduced

- Firmware settings are now properly saved to disk (beforehand I misunderstood when the firmware blob was written)
- Firmware is no longer overwritten by contents of wfcsettings.bin

* Slight cleanup
2023-09-18 21:09:11 +02:00
Jesse Talavera-Greenberg
db963aa002
Make the NDS teardown more robust (#1798)
* Make cleanup a little more robust to mitigate undefined behavior

- Add some null checks before cleaning up the GPU3D renderer
- Make sure that all deleted objects are null
- Move cleanup logic out of an assert call
- Note that deleting a null pointer is a no-op, so there's no need to check for null beforehand
- Use RAII for GLCompositor instead of Init/DeInit methods

* Replace a DeInit call that I missed

* Make ARMJIT_Memory less likely to generate errors

- Set FastMem7/9Start to nullptr at the end
- Only close and unmap the file if it's initialized

* Make Renderer3D manage its resources with RAII

* Don't try to deallocate frontend resources that aren't loaded

* Make ARMJIT_Memory::DeInit more robust on the Switch

* Reset MemoryFile on Windows to INVALID_HANDLE_VALUE, not nullptr

- There is a difference

* Don't explicitly store a Valid state in GLCompositor or the 3D renderers

- Instead, create them with static methods while making the actual constructors private

* Make initialization of OpenGL resources fail if OpenGL isn't loaded

* assert that OpenGL is loaded instead of returning failure
2023-09-15 15:31:05 +02:00
RSDuck
1aaf22d181 fix last commit 2023-09-02 18:56:58 +02:00
jdp_
2a3a071216
Reduce code stink (#1818)
CRC32.cpp:
Make table initialization compile time

DSi_NAND.cpp:
Fix file close / unmount / disk close on error
~L427: Remove redundant calls, as they are immediately rendered useless by `rem` being overwritten

NDS.cpp / FreeBIOS.h:
Remove unneeded size values in header
Remove unneeded memset's as they are initialized anyway

sha1.c / sha1.h:
Fix useless warning

Wifi.cpp:
Remove unneeded includes

DSi.cpp:
Reduce ugly casts
Deduplicate code

qt_sdl/main.cpp:
silence clang switch statement warning

qt_sdl/main.h:
fix override warnings

dolphin/BitSet.h:
use msvc extensions only when appropriate, fix broken bit set count under _WIN32
2023-08-28 20:01:15 +02:00
xenticore
b4756c5944
Update macOS icon (#1609)
* Add SVG icon

* Update macOS icon

* Don't force change the application icon at runtime on macOS
2023-08-27 13:37:42 +02:00
StraDaMa
bc71618457
remove AR code size limit (#1802)
Co-authored-by: Arisotura <thetotalworm@gmail.com>
2023-08-27 13:34:11 +02:00
Jaklyy
2bd12669b2
Edge fill rules for swapped polygons + a few minor fixes to edge cases (#1815)
* fix edge fill rules for swapped polygons

also fixes translucent polygons not being always edge filled.

* fix right edge fill rule

* fix right edge fill rule for realsies

* fix a few more glitchy polygons

specifically quads similar to: (-67,40) (64, 160) (192, 160), (8, 111)

* fix one edge case pixel

i hate this so much

* fix "flat bottom" edge fill

* fix regression + apply changes to shadow masks

fix a regression with certain line polygons not rendering; there seems to be an exception made by the ds'  gpu in order for these polygons to render properly.
also apply these changes to shadow masks because i forgot to

* forgot to remove a line

---------

Co-authored-by: Arisotura <thetotalworm@gmail.com>
2023-08-27 13:32:31 +02:00
Mireille
a571fe19c3
Make sprite mosaic (more) accurate (#1687)
* Make horizontal sprite mosaic (more) accurate

* Vertical sprite mosaic should not extend the sprite's bounding area

* Vertical sprite mosaic should not extend the sprite's bounding area (2)

* OBJIndex is no longer needed
2023-08-27 13:29:23 +02:00
Jaklyy
d69745b3a8
Fix Incorrect Polygon Swapping Behavior and Implement Correct Rules for Shifting Right Edges Left (#1816)
* fix polygons being swapped incorrectly

"borrowed" this from noods
needs verification that the >= and <= signs aren't actually supposed to be > and <

* proper rules for moving vertical right slopes left

* nvm most of that was actually pointless

that's on me for not checking
2023-08-27 13:29:12 +02:00
Jaklyy
dc8efb62b8
Fix aa being upside down on swapped y-major slopes (#1803)
* fix aa being upside down on swapped y-major slopes

* further improvements to swapped aa

in addition to fixing swapped y-major slope aa, now fixes:
swapped x-major slope aa
swapped vertical slope aa

* use templates instead + style/comment tweaks

should force the compiler to precompile if statements like i want it to do, instead of just hoping it does so on its own
2023-08-27 13:28:44 +02:00
Jaklyy
d7369857c3
Small Fix to Anti-Aliasing + Edge Marking Behavior (#1680)
* Anti-Alias All Edges

Changing a bunch of 0x3s to 0xF since I figure if they're checking the left and right edge they wanna be checking the top and bottom too now that they're gonna be aa'd. also copy that if statement over since otherwise there won't be anything to blend with.

* small optimization

its probably a tiny bit faster?
idk id need actual benchmarking tools.
doesn't break anything at least.
2023-08-27 13:28:26 +02:00
Jaklyy
758b5ee7a1
fix aa calc for 1px tall 0px wide slopes (#1795) 2023-08-27 13:27:42 +02:00
Jesse Talavera-Greenberg
ee55677086
Assorted portability enhancements (#1800)
* Introduce some Platform calls for managing dynamic libraries

* Add Platform::WriteFATSectors

* Introduce some Platform calls for managing dynamic libraries

* Add Platform::WriteFATSectors

* Change includes of "../types.h" to "types.h"

- Makes it easier to directly include these headers in downstream projects

* Change an include of "../Wifi.h" to "Wifi.h"

* Allow CommonFuncs.cpp to compile on Android

* Tidy up some logging calls

- Use Platform::Log in LAN_Socket.cpp
- Soften some warnings to Debug logs (since they don't necessarily represent problems)

* Add Platform::EnterGBAMode

- Gracefully stop the emulator if trying to enter GBA mode

* Soften some logs that most players won't care about

* Soften some more logs

* Introduce Platform wrappers for file operations

* Fix pointer spacing

* Fix more style nits

* Log the errno when ftruncate fails

* Fix FileSeek offset argument

- With an s32 offset, we couldn't access files larger than 2GB

* Revise Platform::StopEmu to address feedback

- Remove Platform::EnterGBAMode in favor of adding a reason to Platform::StopEmu
- Also rename Platform::StopEmu to Platform::SignalStop
- Add an optional argument to NDS::Stop
- Use the new argument everywhere that the console stops itself

* Rename FileGetString to FileReadLine

- It conveys the meaning better

* Rename FileSeekOrigin::Set to Start

- It conveys the meaning better

* Change definition of FileGetString to FileReadLine

- Oops, almost forgot it

* Rename FlushFile to FileFlush

- To remain consistent with the other File functions

* Add a FileType usage

* Fix line break in FileSeekOrigin

* Document Platform::DeInit

* Clarify that StopReason::Unknown doesn't always mean an error

* Move and document FileType::HostFile

* Remove Platform::OpenDataFile

- Nothing currently uses it

* Refactor Platform::OpenFile and Platform::OpenLocalFile to accept a FileMode enum instead of a string

- The enum is converted to fopen flags under the hood
- The file type is used to decide whether to add the "b" flag
- Some helper functions are exposed for the benefit of consistent behavior among frontends
- Equivalent behavior is maintained

* Fix a tab that should be spaces

* Use Windows' 64-bit implementations of fseek/ftell

* Move Platform::IsBinaryFile to Platform.cpp

- It could vary by frontend

* Remove an unused FileType

* Rename an enum constant

* Document various Platform items

* Use Platform::DynamicLibrary to load libandroid

- And clean it up at the end

* Fix a typo

* Pass the correct filetype to FATStorage

- Since it can be used for DSI NAND images or for SD cards

* Remove Platform::FileType
2023-08-18 22:50:57 +02:00
Jaklyy
f454eba3c3
check lower pixel when top pixel ignores fog (#1808) 2023-08-13 05:38:26 +02:00
Jaklyy
5f9e7e19f3
Improve Interpolation Accuracy (#1686)
* Fix Up Y Interp Inputs

* Change Linear Interp Formula

Fixes a handful of pixels.
Still not perfect.

* Cleanup

remove some unnecessary code and parentheses
2023-08-10 18:00:40 +02:00
RSDuck
7731f66e55 fix some UB 2023-08-01 03:00:41 +02:00
RSDuck
3efbf1b813 a bit of frontend refactoring 2023-07-29 21:27:28 +02:00
Arisotura
8fd46e5f8c wifi: attempt two at optimizing the sync mechanism. this time it should be far less prone to problems. 2023-07-28 10:14:33 +02:00
Arisotura
9c5cde8109 wifi: implement CMD retries 2023-07-27 21:54:30 +02:00
Arisotura
c3943b29ec wifi:
* rework and clean up frame transfer code
* disable melonAP during local multiplayer comm
2023-07-27 21:11:30 +02:00
Arisotura
b04c250e2f cancel CMD transfer if there isn't enough time left 2023-07-25 23:45:10 +02:00
Arisotura
a87dc83279 wifi: mystery ack value is CMD_COUNT 2023-07-25 20:50:07 +02:00
Arisotura
c7afa8d3f6 keep that one extra line in, tho
(remind me to rename these with the proper reg names)
2023-07-25 20:32:54 +02:00
Arisotura
193c7ed97b Revert "attempt at making local multiplayer faster"
This reverts commit 8772258fe7.
2023-07-25 20:32:01 +02:00
Nadia Holmquist Pedersen
e6cc4b14b0 Work around a strange bug in Qt5 that causes melonDS to crash on launch
...but only with LTO enabled
...but only on some UNIX systems
...but only with some additional build options except when it breaks
   without any as well
2023-07-16 15:49:51 +02:00
PoroCYon
fbb41bd73d
DSi: add option to boot the full boot ROMs (#1581)
* DSi: add option to boot the full boot ROMs

added a config option for this so that this can be enabled or disabled

also added IO regs for DSi GPIO, but those don't do anything yet.

* reset GPIO regs on reset
2023-07-16 02:40:50 +02:00
Arisotura
8772258fe7 attempt at making local multiplayer faster 2023-07-15 01:16:31 +02:00
Arisotura
4b7c2ba8c2 fix bad seqno bug with MP replies (oops) 2023-07-14 12:03:58 +02:00
Arisotura
a2033a62fd wifi: only allow setting TXSLOT_CMD bit15 if CMDCOUNT is nonzero, as per GBAtek 2023-07-14 11:39:58 +02:00
Nadia Holmquist Pedersen
f432e559d4 Add a fallback to streaming decompression when loading zstd-compressed ROMs.
Because of course some compression programs aren't nice enough to tell
you the decompressed size up front in the file, so the other approach
will fail. Things just can't ever be easy and straight forward, can they?
2023-07-14 03:05:34 +02:00
Nadia Holmquist Pedersen
ca5e8792c8 Don't try to open the mic device every time if SDL says it has none
Fixes the UI hanging up on Windows 11 when there are no mics, but the mic
input is set to external device as it is by default.
2023-07-14 02:32:09 +02:00
Jesse Talavera-Greenberg
0947e941b8
Modest cleanups for DSi_NAND (#1714)
* Add a definition for TMD files

* Wrap TitleMetadata in a namespace

* Add a comment

* Remove TitleMetadataCertificate

- melonDS ignores it anyway

* Refactor the use of title metadata

- Move bitwise operations on the title ID into helper methods
- Use TitleMetadata objects instead of pointers to raw data

* Slight cleanup in DSi_NAND

- Replace some constants with sizeof
- Use an NDSHeader object instead of a raw array of bytes

* Add a DSi_NAND::ImportFile overload that loads a file from memory

* Split most of ImportTitle into InitTitleFileStructure

- It will be reused in the next commit

* Add ability to import title from memory

* Fix another potential issue

* Fix broken DSiWare installation

- The bytes of the title ID/category were being swapped in most places, but not all

* Add some logging calls

* Declare array sizes in DSi_TMD in decimal, not hex

* Add a space after the #endif

- To adhere to the style guide

* Assert the size of TitleMetadataContent

* Change the type of SignatureName

* Don't mark the TMD structs as packed

* Remove extraneous comments

* Cut down some newlines
2023-07-08 22:17:30 +02:00
Jesse Talavera-Greenberg
d1ff103259
Make linking librt conditional on it containing shm_open
Fixes building on UNIX platforms with no librt.

Co-authored-by: Nadia Holmquist Pedersen <nadia@nhp.sh>
2023-07-08 01:36:22 +02:00
Jesse Talavera-Greenberg
3c6359837d
Forgot an #include (#1712) 2023-06-30 14:28:53 +02:00
Jesse Talavera-Greenberg
b659bce3c1
Split the cart parsing and loading steps (#1707)
* Split ROMList into a .cpp file

- Its definition in ROMList.h was causing multiple-definition linker errors
- Introduce ROMListSize, since you can't take a sizeof() of an extern declaration
- Mark ROMList and ROMListSize as const

* Update ReadROMParams to accommodate ROMList changes

* Split parsing and loading of NDS ROMs

- Introduce an NDSCartData class for parsing a ROM file
- Introduce InsertROM for loading a NDS cart
- Refactor LoadROM to use NDSCartData and InsertROM under the hood

* Reset cart state and initialize save memory in the NDSCartData constructor

- Otherwise there's no way to know about SRAM-specific attributes before inserting the game

* Add a comment to NDSCartData

* First crack at splitting parsing and loading for GBACart

* Add some logging calls for encrypting the secure area

* Log the XXH64 hash of the inserted NDS ROM

* Log the XXH64 hash of the secure area after decryption

* Add some logging to Key1_LoadKeyBuf

* Re-encrypt the secure area when inserting the cart, not when parsing it

- This way, constructing a NDSCart doesn't imply a read from the filesystem (as is done in Key1_KeyBuf)

* Load Key1_KeyBuf from memory, not from the file system

- Now that the cart's secure area isn't re-encrypted until insertion, we can expect that the BIOS will be ready at this point

* Add some helper query methods to NDSHeader

* Query the DSi region directly from the header instead of checking the ROM again

* Introduce a CartType enum

- So CartCommon::Type doesn't have to return magic numbers

* Reset the cart in NDSCart::InsertROM instead of the NDSCartData constructor

- That way the constructor doesn't rely on the config or on file I/O when loading homebrew
- This keeps the use of global state closer to one place

* Add non-const getters for the carts

* Add InsertROM overloads that accept unique_ptrs

* Fix a comment

* Rename member functions on NDSCartData and GBACartData to adhere to the convention

* Rename members on NDSCartData and GBACartData to adhere to the convention

* Fix build errors on some platforms

* Add NDSHeader::IsDSiWare

* Add a ROMListEntry parameter to the cart constructors

- To allow for looking up details of SRAM or expected ROM size

* Add some new getters to CartCommon

* Use the Header/Banner members instead of globals

* Make CartCommon abstract

- It's not supposed to be instantiated anyway

* Change the signature of CartCommon::Checksum

- It's neither overridden nor mutating

* Add some clarifying comments to NDSHeader

* Delete CartCommon::ROM in its destructor

- ParseROM copies its input and gives that copy to the cart object, so it's okay

* Add some getters to CartCommon

* Refactor NDSCart

- Get rid of NDSCartData
- Get rid of cart-specific global state within NDSCart (so registers are untouched)
- Refactor uses of removed global variables to use the Cart pointer instead
- Refactor ROMInfoDialog's icon functions to accept const arguments

* Return the cart pointer

- So *that's* why it was crashing. Whoops
- Why is this even allowed?

* Refactor GBACart

- Delete CartGame::ROM in the destructor
- Get rid of GBACartData
- Remove some global state

* Mark NDSCart::CartCommon::Type as const

* Slightly refactor GBACart::CartCommon

- Mark Type as const
- Use enum constants
- Make CartCommon itself abstract

* Mark CRC32's data parameter as const

* Mark GBACart::CartCommon::Checksum as const

* Use assert.h instead of cassert

- As demanded by the style guide

* Fix some includes to adhere to the style guide

* Get the ARM9 entry address directly from the header object

* Use more Header fields directly

* Rename some parameters to match the style guide

* Remove some unused includes

* Slightly change NDS_Header::IsHomebrew for clarity
2023-06-30 13:28:52 +02:00
Nadia Holmquist Pedersen
7b948e6ec9 Assign Qt standard Quit keyboard shortcut 2023-06-29 19:12:07 +02:00
falsidge
52d6265b58
Add microphone combobox using SDL (#1709) 2023-06-27 21:31:41 +02:00
Nadia Holmquist Pedersen
4b32fb802c actually rename that setting 2023-06-24 16:34:23 +02:00