Commit Graph

49 Commits

Author SHA1 Message Date
Jesse Talavera-Greenberg 5dac65f52e Fix some minor instances of undefined behavior 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
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
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 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
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
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
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
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
Jesse Talavera-Greenberg 79dfb8dc8f
Introduce `Platform::Log` (#1640)
* Add Platform::Log and Platform::LogLevel

* Replace most printf calls with Platform::Log calls

* Move a brace down

* Move some log entries to one Log call

- Some implementations of Log may assume a full line

* Log the MAC address as LogLevel::Info
2023-03-23 18:04:38 +01:00
Nadia Holmquist Pedersen 9a5e884913 JIT: Add bits for Windows ARM64 support 2022-11-05 22:37:27 +01:00
Arisotura 0294bcb5f2 add support for the mainRAM mirror at 0x0C000000 in DSi mode, makes SM64DSi work correctly 2022-04-10 14:54:40 +02:00
Arisotura 9394dde67a fix copyright headers 2022-03-07 21:08:54 +01:00
Arisotura 35cc79787d update copyright headers 2022-01-09 02:15:50 +01:00
RSDuck c233d99211 dtcm not dtcb 2021-10-29 12:09:00 +02:00
RSDuck 6c2ea93173 get rid of DTCMSize 2021-10-29 01:35:47 +02:00
RSDuck 1793abcfb4 don't printf from exception handler
it was handy for debugging, but it's dangerous
2021-06-07 19:02:09 +02:00
WaluigiWare64 2ff065e5ea Fix some compiler warnings 2021-05-03 13:40:44 +01:00
WaluigiWare64 ac49d8e25c Update copyright year and add missing GPL headers part 2
Looks like a lot of files were missed...
Closes #1036
2021-03-21 21:32:26 +00:00
RSDuck 6a3aa551da remove direct reference to Switch frontend header 2021-03-03 00:43:56 +01:00
WaluigiWare64 89051f63d4
Define CONTEXT_PC and use instead for much cleaner code (#1017)
* Define CONTEXT_PC and use instead for much cleaner code

Also include ways to get the Program Counter on ARM64 FreeBSD and NetBSD
2021-02-25 21:17:11 +00:00
RSDuck 891427c75c fix #994 2021-02-09 23:36:46 +01:00
RSDuck e7ee3b7bc8 wild shot into the dark 2021-02-09 22:19:44 +01:00
WaluigiWare64 2502c8d212
Add NetBSD support (#985)
Note - This will require PaX MPROTECT to be disabled for melonDS by running:
paxctl +m melonDS
2021-02-03 16:14:53 +00:00
WaluigiWare64 9994d3a644
Add FreeBSD support (#939)
* Add FreeBSD support

* Fix indentation

* Fix Linux not finding OpenGL

* Link POSIX Realtime Extensions library

* Link POSIX Realtime Extensions when OpenGL is enabled too

* Fail if shm_open memory exists and also check for errors

* fix the last commit

* (try to) Setup FreeBSD CI

* Fix some issues with FreeBSD CI

* Make with all cores

* Remove FreeBSD CI 

It doesn't want to work for some reason
2021-01-22 19:20:32 +01:00
RSDuck ef75e3cdd1 JIT A64: fixes
also update Switch code for latest libnx
2021-01-05 14:36:50 +01:00
WaluigiWare64 a9223d6c0a
Fix fastmem building on ARM64 Macs (#841) 2020-12-11 01:41:53 +01:00
RSDuck 49b5860f0f aligned_alloc instead of memalign
also carry over new Switch changes
2020-12-09 18:58:51 +01:00
Filippo Scognamiglio acb272ed78
Use ashmem instead of memfd_create on Android. (#816)
* Use ashmem instead of memfd_create on Android.

* Fix code styling issues.

* fix small mistake in merge commit

Co-authored-by: RSDuck <RSDuck@users.noreply.github.com>
2020-11-30 15:33:43 +01:00
WaluigiWare64 7da4550eea
Add support for macOS (#771)
* use shm_open() instead of memfd_create() on macOS

malloc.h isn't a header on macOS

* Change OpenGL headers + create ifdef for DO_PROCLIST

macOS seems to already have the OpenGL functions defined, without the ifdef, it gives "ambiguous references" errors.

* macOS doesn't have ->gregs in uc_mcontext

and it doesn't have REG_RIP either
https://github.com/gperftools/gperftools/blob/master/m4/pc_from_ucontext.m4

* use getpid() to make memory file name unique

* #ifndef __APPLE__ for AF_PACKET and linux/if_packet.h

* Add include and link directories for macOS and link the OpenGL framework

* Add macOS CI

* Use newly added libslirp package from Homebrew

https://github.com/Homebrew/homebrew-core/pull/63412

* Use Apple's Clang instead of GNU GCC on macOS

* Add macOS build instructions to README

* Try to fix macOS undefined symbol

* snprintf doesn't take null terminator into account

* Map new memory on macOS for JIT

* Only use gcc-ar if using GNU Compiler

* re-add fastmem code - whoops!

* Fix style issue - use camelCase not snake_case

* Set Minimum macOS version

* Switch Minimum OS X version to 10.9

* Add macOS libpcap library name

* fix memory leak

* Fix binding keys in macOS

* Allow getting MAC address on macOS

melonDS on Linux uses AF_PACKET, which doesn't exist on macOS. Instead, this commit uses AF_LINK on macOS to get the MAC address.

* Remove unneeded macOS CI dependencies

* Build melonDS app bundle on macOS

Now it is no longer required to install the libraries on macOS, they come with the app bundle.

* fix macOS CI not being able to find macdeployqt

* copy melonDS.app with recursive because it's a folder

* Disable fastmem checkbox on macOS

* Disable fastmem by default in config

* forgot a semicolon

* Don't bundle libraries, causes issues on macOS <10.15

* Update README + allow finding version in Finder on macOS

* Make sure fastmem checkbox stays uncheckable
2020-11-29 17:11:33 +01:00
RSDuck d697f9e0d2 make fastmem work again 2020-11-13 15:20:53 +01:00
RSDuck 052079afeb fix Windows 2020-11-09 20:56:31 +01:00
RSDuck 78839f862e JIT fixes
- fix fastmem problems on linux
- small fix memory leak
- SlowWrite functions always take in a 32-bit variable so that the C compiler knows that the values aren't necessary zero extended
- a few other stylistic things
- handle SIGBUS as well (for macos)
2020-11-09 20:43:31 +01:00
RSDuck edf4c66724 fix build on Switch 2020-09-11 19:29:06 +02:00
RSDuck b12e1a1b6e JIT fastmem: fix out of bounds read
seems to fix #727
2020-08-25 18:13:17 +02:00
RSDuck 4299ef5f06 use unordered map for JIT RestoreCandidates
also fix WifiRead32?
2020-08-14 23:38:47 +02:00
RSDuck 36bdb591be fix JIT for code in VRAM
apparantely Pokemon B/W needs this
fixes #708
2020-08-09 13:29:04 +02:00
RSDuck 2a3147db46 reset fastmem on DSi soft reset 2020-07-31 22:39:27 +02:00
RSDuck a89741c628 fix unterminated string + remove some JIT logging 2020-07-29 01:31:57 +02:00
RSDuck e63bd7e38c for some reason tabs and spaces were mixed 2020-07-23 17:43:25 +02:00
RSDuck 1519b3d5fa attempt at fixing aarch64 linux yet again 2020-07-08 23:57:43 +02:00
RSDuck 8f5d8d1e12 fix for fastmem when pc is used as immediate
and (hopefully) make SIGSEGV handler work for aarch64 linux
2020-07-08 23:47:24 +02:00
RSDuck 3786660099 misc JIT changes 2020-07-08 23:08:25 +02:00
RSDuck 778623a8b7 make linux work and fix a few bugs 2020-07-04 18:58:00 +02:00
RSDuck c5381d2911 reconcile DSi and JIT, fastmem for x64 and Windows 2020-06-30 23:50:41 +02:00
RSDuck e335a8ca76 first steps in bringing over the JIT refactor/fastmem 2020-06-16 12:11:19 +02:00