Commit Graph

2042 Commits

Author SHA1 Message Date
Jesse Talavera 821f5f5f29
Allow frontends to use different headers for OpenGL declarations (#2102) 2024-07-21 17:02:31 +02:00
BueniaDev 9b828c2cde
Implement Rumble Pak support. (#2101) 2024-07-21 17:01:30 +02:00
Nadia Holmquist Pedersen 5eadd67df6 EmuInstance: Use GetLocalFilePath to get the wfcsettings path
Fixes the file being created in the current working directory.
2024-07-17 15:44:47 +02:00
Nadia Holmquist Pedersen 4b17de7e8c Fix annoying Qt touch event deprecations for real this time 2024-07-15 14:37:37 +02:00
Nadia Holmquist Pedersen 71f4d7b222 deviceType doesn't exist in Qt5 apparently 2024-07-15 14:04:40 +02:00
Nadia Holmquist Pedersen 6d2ad2a3f0 Ignore touch events originating from trackpads
Fixes multi-finger gestures causing spurious touch screen presses
Also fix some deprecations when we're at it anyway
2024-07-15 13:57:21 +02:00
Arisotura 2031f491f0 fix some Qt6 bugs (buttonClicked -> idClicked) 2024-07-15 13:00:40 +02:00
Arisotura d92c9fcd90 do not immediately create a core when creating an EmuInstance. fixes some nasty potential bugs. watch out for bugs this may introduce though... 2024-07-15 12:57:18 +02:00
Jesse Talavera 94ba7c1594
Split networking code into its own target (#2091) 2024-07-14 17:03:21 +02:00
CasualPokePlayer a812a43bda
Fix various issues with firmware generation (#2058) 2024-07-11 15:55:06 +02:00
OverdueWeevil2 a82b5758bc
Update EmuInstance.cpp (#2090) 2024-07-11 13:48:27 +02:00
Nadia Holmquist Pedersen b55eb431bd ensure that we actually link the OpenGL library on macOS 2024-07-07 13:45:45 +02:00
Nadia Holmquist Pedersen 1302cbdd64 frontend: Restore linear interpolation for audio output resampling
Also, do it smarter this time. This seems to have gone missing with the
doublemelon merge.
2024-07-07 08:19:49 +02:00
Antonio Niño Díaz 25b5ac91bd
Fix horizontal mosaic on sprites (#2084)
The code itself is correct, but the variable being read is the Y mosaic
coordinate, not the X coordinate.
2024-07-04 00:24:29 +02:00
RSDuck 613569a2ab append newline to nocash logging
makes behaviour consistent with no$gba
2024-07-02 19:09:32 +02:00
Nadia Holmquist Pedersen 4e3592f2d4 Fix loading GBA carts
UpdateConsole forgot to reinsert it when messing with the NDS.
2024-07-02 08:18:44 +02:00
Nadia Holmquist Pedersen f2611680ca EmuInstance: check consoleType from NDS rather than the instance's when
updating console, fixes crash on console type switch

EmuInstance::consoleType is already updated, so the check for whether we
should recreate the NDS to switch console type never succeeds.
2024-07-02 06:23:21 +02:00
Nadia Holmquist Pedersen db20771ef3 slirp: Add -fvisibility=hidden to glib stub
On Linux, our stubbed glib functions were conflicting with the ones from
real glib, which gets used by Qt when we're running on a GTK-based
desktop. Avoid a crash by not exposing them.
2024-06-24 05:25:00 +02:00
Nadia Holmquist Pedersen cbb0f4b872 Tell the compiler that we want wrapping signed arithmetic
The core relies on this and without -fwrapv there will be rendering
issues on some targets. Thanks CasualPokePlayer for noticing this.
2024-06-18 15:51:08 +02:00
Arisotura e234385c20 OpenGL: add support for changing BG0HOFS midframe. fixes #2072 2024-06-18 13:11:42 +02:00
Arisotura 626d2379bc * fix default for audio volume
* add default bools for battery settings
2024-06-17 14:51:32 +02:00
Nadia Holmquist Pedersen eb2bd73c7d ensure teakra is always static linked even in dynamically linked builds 2024-06-15 21:31:23 +02:00
Arisotura ae44ba2475 blarg 2024-06-15 21:01:27 +02:00
Arisotura 649462ff5c fix more bugs and crap 2024-06-15 20:57:26 +02:00
Arisotura 890dc4f228 fix other bugs with these regexes 2024-06-15 19:23:18 +02:00
Arisotura d449888405 fix up the regexes in Config.cpp 2024-06-15 19:10:28 +02:00
Arisotura ccc5c955e9 fix one potential crash bug 2024-06-15 17:42:26 +02:00
Arisotura 8fc403cdad update copyright headers 2024-06-15 17:01:19 +02:00
Arisotura 25a7b1ca1d
merge doublemelon (#2067)
non-exhaustive (but exhausting) list of changes:

* base laid for multiple window support, but will likely require more work to work correctly
* encapsulation of frontend state for proper multi-instance support
* (JIT still needs a fix for the NDS::Current workaround but we can get there later)
* new, more flexible configuration system
2024-06-15 13:52:47 +02:00
CasualPokePlayer 8e9b88d01d
Actually generate DownscaleFramebuffer (#2059) 2024-06-08 20:48:42 +02:00
Nadia Holmquist Pedersen a72b79a55a that needs to be public actually 2024-05-15 19:43:34 +02:00
Nadia Holmquist Pedersen cfc49eb286 Revert slirp dynamic/static check, and make it not use dllimport/export
when building statically
2024-05-15 19:37:14 +02:00
Nadia Holmquist Pedersen d21bc64cb3 MinGW build portability fixes
AKA you can build melonDS for Windows on Fedora now
2024-05-15 18:57:49 +02:00
Nadia Holmquist Pedersen a2406e3c0e
Vendored libslirp (#2045)
Add vendored libslirp into the repo with a shim to remove its dependency on glib.
2024-05-15 18:00:55 +02:00
Nadia Holmquist Pedersen 5ab8161a21 Prevent turning on compute renderer on macOS 2024-05-14 11:39:06 +02:00
RSDuck 442661747e add assert to make sure all shaders were compiled 2024-05-14 04:09:20 +02:00
RSDuck 5df83c97c7 bump up compute shader renderer tile amount factor to 16
also why did I think DS could render 4096 polygons? Use that extra bit for larger work offset
2024-05-13 19:15:48 +02:00
RSDuck 347f4a79fd Fix division by zero 2024-05-13 17:23:05 +02:00
RSDuck 043244a56d
Compute shader renderer (#2041)
* nothing works yet

* don't double buffer 3D framebuffers for the GL Renderer
looks like leftovers from when 3D+2D composition was done in the frontend

* oops

* it works!

* implement display capture for compute renderer
it's actually just all stolen from the regular OpenGL renderer

* fix bad indirect call

* handle cleanup properly

* add hires rendering to the compute shader renderer

* fix UB
also misc changes to use more unsigned multiplication
also fix framebuffer resize

* correct edge filling behaviour when AA is disabled

* fix full color textures

* fix edge marking (polygon id is 6-bit not 5)
also make the code a bit nicer

* take all edge cases into account for XMin/XMax calculation

* use hires coordinate again

* stop using fixed size buffers based on scale factor in shaders
this makes shader compile times tolerable on Wintel
- beginning of the shader cache
- increase size of tile idx in workdesc to 20 bits

* apparently & is not defined on bvec4
why does this even compile on Intel and Nvidia?

* put the texture cache into it's own file

* add compute shader renderer properly to the GUI
also add option to toggle using high resolution vertex coordinates

* unbind sampler object in compute shader renderer

* fix GetRangedBitMask for 64 bit aligned 64 bits
pretty embarassing

* convert NonStupidBitfield.h back to LF only new lines

* actually adapt to latest changes

* fix stupid merge

* actually make compute shader renderer work with newest changes

* show progress on shader compilation

* remove merge leftover
2024-05-13 17:17:39 +02:00
Nadia Holmquist Pedersen c85a2103bb Allow adding a suffix to the displayed melonDS version 2024-05-11 22:40:45 +02:00
Nadia Holmquist Pedersen 35cea5e1d7 Fix zstd ROM loading issues
* fix use-after-free of inContent
* don't try to free the DStream twice
2024-05-04 18:16:24 +02:00
Jakly 6112aa120a
Pu region sizing/bounds fix (#2024)
* fix the pu region's end point overflowing

According to gericom it cannot overflow at all

* set a minimum and a better maximum for the pu region size

* fix pu logging

* PU regions with a size of 31 always take up the entire address space

also tweak some logging a little more

* start is actually force aligned by size, oops

* small tweaks

* hopefully more clear code

* math is for nerds
2024-05-02 17:44:59 +02:00
RealAstolfo 84474105e2
ssize_t is not defined in stddef.h (#1999)
i had to add sys/types.h and patch my gentoo ebuilds for a successful compilation.
2024-04-18 13:40:38 +02:00
Rayyan Ansari 5a852cb00d
ROMManager: optimise ROMIcon function
Precompute all 16 5-bit RGB palette colours into 8-bit RGBA to avoid
repeated and superfluous calculation within the nested loop at the
point of index lookup.

A speedup was observed, from ~7ms, to a consistent 1ms
(i.e. now practically instantaneous) through timing with
std::chrono::high_resolution_clock.

Also improve comprehensibility, by using meaningful names, where
appropriate, for loop counter variables.
2024-04-16 23:39:22 +01:00
Arisotura 95adc87f6d wifi: try ignoring MP frames if not engaging in MP comm 2024-04-13 12:17:16 +02:00
Arisotura 8feeee6103 Input: only check joystick input if a joystick actually exists 2024-04-12 20:02:16 +02:00
Arisotura d99c571f94 FATStorage: make sure to always properly unmount the volume (fixes evil bug) 2024-04-12 19:43:02 +02:00
Arisotura 111dc7a563 wifi improvements:
* implement channels
* rework power-down support, fixing bugs
* fix bug when W_BeaconInterval is zero
* fix potential missing IRQs when writing to W_IE
2024-04-12 17:28:51 +02:00
Arisotura 0b87dd5fa6 fix touchscreen bug on Wayland 2024-04-09 12:54:31 +02:00
Arisotura 968bd26d85 fix generation of instance-unique MAC address when using an external firmware 2024-04-09 11:38:38 +02:00
Jesse Talavera 31a7f53282
Fix a crash when using DSi mode in debug builds on macOS (#1976)
Store the BIOS images in `NDSArgs`/`DSiArgs` through pointers, not directly

- This will make it easier to keep such objects on the stack
2024-03-13 14:55:20 +01:00
RSDuck ea1755bed0 call Start again NDS object after Reset
fixes issue where game doesn't properly start after changing settings
2024-03-12 09:23:20 +01:00
RSDuck 5fdd285c9a fix aarch64 build 2024-03-12 08:41:42 +01:00
RSDuck 18d1df606f fix #1959
Use QT again for opening file so that we don't depend on locale
2024-03-12 08:35:56 +01:00
Nadia Holmquist Pedersen b117bb8f58 that should be 0x8000 2024-03-08 16:59:31 +01:00
Nadia Holmquist Pedersen faf3c0f2e0 Add Gaussian (SNES) audio interpolation
Probably not a good choice for most DS games unless you really want a
very soft sound, but it could be fun if you wanted to run lolSnes in
melonDS :p
2024-03-08 16:36:00 +01:00
Nadia Holmquist Pedersen e227902cec Util_Audio: use basic linear interpolation
Should remove the artifacts caused by the previous nearest
resampling. May be worth replacing with something better in the
future, but this is an improvement for now.
2024-03-03 16:58:59 +01:00
Nadia Holmquist Pedersen 67ca4997e2 Release all keyboard keys on focus loss (fixes #1987) 2024-02-25 14:25:50 +01:00
Nadia Holmquist Pedersen 21e2a876ec build teakra's test_generator.cpp only if building its unit tests is
enabled

speeds up builds a bit
2024-02-24 01:47:04 +01:00
λP.(P izzy) 9430502b16
fix malloc on OpenBSD targets (#1979) 2024-02-20 03:33:39 +01:00
Jaklyy a8429af131
dont make a save file on launching a game (#1974)
avoids the issue of saves being created for roms that dont use save files.
2024-02-13 20:17:29 +01:00
Luca D'Amico 646ed3cb32
Add Haiku (BeOS-like OS) support (#1858) 2024-02-07 23:15:30 +01:00
Jaklyy 5ffa642980
Check for write permissions for some key files (#1972)
* check if an nds save file can be opened for writing

also add the ability to open a file in append mode

* fix multi-instance saves

also move the check for file writability into a separate function (probably uneeded?)

* implement check for gba roms

* move rom load error messages into the functions

also finish gba slot (oops)

* improve error string

* check write perms before saving path settings

* fix memory leak

* check for writability of firmware/nand/sds

* add secondary checks for nand/firmware

* add check for config file being writable

* Return the file write error as a QString to avoid the invalid char*
causing a garbled error message.

Qt wants it as QString either way.
2024-02-07 23:04:36 +01:00
Nadia Holmquist Pedersen a7575ec7b3 Allow the user to choose the UI theme
Mainly useful for those who want dark mode on Windows.
2024-02-07 20:20:54 +01:00
Jesse Talavera d48e5f2da0
Fix DSiWare detection (#1969)
- According to GBATek, all DSiWare games have a high title ID of 0x00030004
- Some homebrew apps set the Unitcode bits to DSi mode to enable support of DSi features
2024-02-01 14:36:35 +01:00
Nadia Holmquist Pedersen 7dd4152d67 Add MaxFPS setting 2024-01-26 13:06:32 +01:00
Steveice10 4b576d066e
Add support for using a portable directory without special build flags. (#1956) 2024-01-24 10:27:25 +01:00
Arisotura 7897bd387b also add writes while we're at it, we know Gericom's gonna abuse them someday :P 2024-01-17 18:54:48 +01:00
Arisotura f4c8202b1a add missing 8/16-bit reads to ROMCnt and ROM SPICnt 2024-01-17 18:50:08 +01:00
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 `#include`s 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