Commit Graph

262 Commits

Author SHA1 Message Date
Billy Laws
2b4adee213 Stub gameplay recording and save data checking functions
Gameplay recording does not need to be emulated and EnsureSaveData isn't
necessary for proper save data support.
2020-07-09 18:42:36 +00:00
Billy Laws
2e60b5e60d Stub play reporting services 2020-07-09 18:42:36 +00:00
Billy Laws
378e494d82 Add an empty ssl service implementation
This stubs a single function that is needed for SMO's init.
2020-07-09 18:42:36 +00:00
Billy Laws
a2c6a2a4ff Add a base socket (bsd) services implementation
This stubs enough to pass SMO's socket init.
2020-07-09 18:42:36 +00:00
Billy Laws
2aefb4ae84 Implement network interface services
nifm:u is used by applications to enable a connection to the network.
2020-07-09 18:42:36 +00:00
Billy Laws
7102fa910e Implement nfp services 2020-07-09 18:42:36 +00:00
Billy Laws
4cf7f9288e Add an empty friend service implementation
This is used to access a users friends. It is used by Super Mario
Odyssey.
2020-07-09 18:42:36 +00:00
Billy Laws
ff5dddbd5b Extend account services to support BAAS and some user operations
These are needed by Super Mario Odyssey and several other games.
2020-07-09 18:42:36 +00:00
Billy Laws
80270637c1 Fix the spacing on lm log messages 2020-07-09 18:42:36 +00:00
Billy Laws
dae799dbb5 Implement svcClearEvent
This removes a signal from a KEvent. It is used by Mario Odyssey.
2020-07-09 18:42:36 +00:00
Billy Laws
92e3f84242 Stub SetGraphicsFirmwareMemoryMarginEnabled
This is used by most retail games released after 3.0.
2020-07-09 18:42:36 +00:00
Billy Laws
ef9760570b Extend parental control services 2020-07-09 18:42:36 +00:00
◱ PixelyIon
180ba97440 Print the sleep duration before actually sleeping 2020-07-09 14:08:58 +00:00
Billy Laws
c708c353e3 Fix block insertion
The subtraction was the wrong way round causing an underflow.
2020-07-09 14:08:58 +00:00
Billy Laws
1383e17341 Mark CodeStatic regions that are writable as CodeMutable instead
This is required for applications that attempt to map from the bss.
2020-07-09 14:08:58 +00:00
Billy Laws
2f8a217204 Use the heap size rather than the heap address when calculating the
total memory usage

Without this fix allocations are broken in Puyo Puyo Tetris.
2020-07-09 14:08:58 +00:00
Billy Laws
f1a28f7a1c Fix the behaviour of svcQueryMemory and allow getting the extents of
unmapped regions

svcQueryMemory will return a valid descriptor for anything in the
address space, from 0 to 1 << addrSpaceBits, this was handled
incorrectly before and we were only returning descriptors if the
address was in a mapped region.

If an address in an unmapped region is requested then the extents of the
unmapped region up to the address space end are returned. If the address
requested is outside of the address space then the extents of the
inaccessible address space are returned.

To facilitate this support was added to MemoryManager::Get for
generating the extents of unmapped regions using the chunk list.
2020-07-09 14:08:58 +00:00
Billy Laws
670a80d2c4 Create a memory chunk for the stack shared memory
As the stack is automatically mapped in the guest by `clone` we do not
need to explicitly map it. This adds a flag to solve the issue.

Also mark the stack as stack rather than reserved.
2020-07-09 14:08:58 +00:00
Billy Laws
7884a60679 Make regions public members of the memory class and drop the type enum
There isn't really much benefit in having a getter or an enum, so drop
it.
2020-07-09 14:08:58 +00:00
Billy Laws
eadc016525 Lock the audio buffer lock when reading released buffers
This is required to prevent races in Puyo Puyo Tetris and potentially
other games.
2020-07-09 14:08:58 +00:00
Billy Laws
6329537a9e Correct audren event handling and zero the sample buffer
Not zeroing the sample buffer causes issues when a voice is started but
is playing no samples. The system event handling was also reworked
according to Thog's info.
2020-07-09 14:08:58 +00:00
Billy Laws
24d086cbec Correctly check the usage bits in DequeueBuffer and fix it's result
The extra parameters in result are required for retail games to accept
it as valid.
2020-07-09 14:08:58 +00:00
Billy Laws
a96b8eb7a3 Add vi:u and vi:s to service list and fix the result parcel type of OpenLayer
vi:u is used by user applications and games and it has the same api as
vi:m.
2020-07-09 14:08:58 +00:00
◱ PixelyIon
9ef25a6beb IPC bug fixes
This fixes two bugs in IPC that were discovered when running Puyo Puyo
Tetris.

The CloneCurrentObject control IPC will now correctly return the handle
of the newly created object through move handles, rather than pushing it
as a result.

The size array of u16s with the sizes of each C buffer is now taken into
account when reading them. Before this change C buffers were entirely
broken.
2020-07-09 14:08:58 +00:00
Billy Laws
6e074d596c Extend applet manager services for the library applet
This commit adds stubs for the library applet and adds support for
writing to an AM IStorage.
2020-07-09 13:57:28 +00:00
Billy Laws
30936ce6dc Implement an ADPCM decoder for audren
This is used by many retail games, it only supports mono sound.

This implementation is based on Ryu's.
2020-07-09 13:56:04 +00:00
Billy Laws
b1e15efbab Use new android R APIs for hiding insets 2020-07-08 20:11:55 +00:00
Billy Laws
012be0adae Fix some warnings produced by enabling -Wall 2020-07-08 20:11:55 +00:00
Billy Laws
af709efb15 Kotlin updates for compatibility with the Android R SDK preview 2020-07-08 20:11:55 +00:00
Billy Laws
68fcb2e4e5 Extend account services and add support for PopLaunchParameters
This is needed for Puyo Puyo Tetris.
2020-07-07 16:21:13 +00:00
Billy Laws
ff1c0e254f Add an empty account services implementation
This implements the base account service and stubs
InitializeApplicationInfoV0 which is used by Puyo Puyo Tetris. Support
for the entirety of account services will be added in the future.
2020-07-06 21:04:31 +01:00
Billy Laws
3a343d3a48 Implement log services (lm)
lm is used by applications to print messages to the system log. Log
messages are made up of a header and then several fields containing
metadata or string messages.
2020-07-06 19:59:26 +00:00
Billy Laws
8985fe705f Implement IStorage services in Applet Manager
In the case of am, IStorage is used to exchange buffers of data such
as application launch parameters or an applets result. It has no
relation to fsp-srv's IStorage.
2020-07-06 19:57:00 +00:00
Billy Laws
162df93870 Add an empty pctl implementation
This is required by Puyo Puyo Tetris. It may be stubbed further if
needed in the future.
2020-07-06 20:46:38 +01:00
Billy Laws
23d6b596b2 Add an empty aoc:u implementation
This is required by Puyo Puyo Tetris, it will be extended in the future
to allow using real DLC with the emulator.
2020-07-06 19:43:17 +00:00
Billy Laws
4a88adafb6 Implement the set service together with GetAvailableLanguageCodes
The 'set' service is used to obtain user settings such as language.
This is used by Puyo Puyo Tetris.
2020-07-06 19:17:20 +00:00
Billy Laws
801382e43a Implement pl:u for accessing shared fonts
Fonts are stored in an array of TTF data with an 8 byte header
containing a magic and an XOR'd length. Instead of requiring users to
provide original Nintendo fonts we pack open source replacements.
They are generated with the scripts here
https://github.com/FearlessTobi/yuzu_system_archives. All the fonts are
licenced under the Open Font or Apache 2 License so we can include them
all freely.
2020-07-06 19:17:02 +00:00
Billy Laws
45b4811c5b Create adaptive icons for pinned games 2020-07-01 06:24:41 +00:00
Billy Laws
f2c5b96b04 Revert "Use X9 rather than LR when jumping to the guest"
This caused issues loading retail games and will be soon obsoleted by
pre-patching.
This reverts commit f381883c0b.
2020-07-01 06:24:41 +00:00
Billy Laws
a53d6266c7 Implement a basic NSP loader
An NSP (Nintendo Submission Package) is effectively a PFS0 containing
NCAs, there are also tickets and a CNMT file which contains metadata
about updates. The current implementation is very basic and only
support Control and Program NCAs which is enough for loading games.

Support for updates and dlc will be added at a later date.
2020-07-01 06:24:41 +00:00
Billy Laws
a5513bd7e6 Implement an NCA parser and loader
Nintendo Content Archives are used to store the assets, executables
and updates of applications. They support holding either a PFS0 or a
RomFS.

An NCA's ExeFS can be loaded by placing each NSO sequentially into
memory, starting with rtld which will link them together.

Currently only decrypted NCAs are supported, encryption and BKTR
handling will be added at a later time.
2020-07-01 06:24:41 +00:00
Billy Laws
db64f53cfb Implement filesystem backends for RomFS and Partition FS
RomFS is a hierarchial filesystem where each level is made up of a
linked list of files and child directories. It is used in NCAs to store
the applications icon as well as by applications themselves for
accessing assets.

Partition FS encapsulates both the HFS0 found in XCIs and the PFS0 used
for ExeFS images and NSPs, it is purely file based and has no support at
all for directories aside from the root.
2020-07-01 06:24:41 +00:00
Billy Laws
2071796696 Implement basic filesystem support in VFS
This mirrors Horizon's IFileSystem, it will be used by the nsp and nca
loaders to read their content.
https://switchbrew.org/wiki/Filesystem_services#IFileSystem
2020-07-01 06:24:41 +00:00
Billy Laws
e2bd50a1fd Implement a simple directory system in VFS
This mirrors Horizon's IDirectory:
https://switchbrew.org/wiki/Filesystem_services#IDirectory
2020-07-01 06:24:41 +00:00
Billy Laws
7114ad1734 Use the first available language entry in NACPs rather than hardcoding
American English

Without this, if an NACP didn't contain a title for a US english it
would show in the UI as blank.
2020-07-01 06:24:41 +00:00
Billy Laws
26025d9adf Implement backing modes
These are used to determine the capabilities of a backing.
2020-07-01 06:24:41 +00:00
Billy Laws
b94248cec0 Move the loader backing out of the main loader class
The presence of a backing is an implementation detail.
2020-07-01 06:24:41 +00:00
Billy Laws
3a23ec06a4 Implement NSO loader
The NSO format is used by all retail games and some homebrew. It
supports compressing sections with lz4 and dynamic linking through the
use of rtld.
2020-06-28 07:54:12 +00:00
Billy Laws
bf46293fc7 Commonise executable loading infrastructure
Mapping and writing segments into memory is now handled by a common
function that can be shared between all loaders. All they need to do now
is to pack each segment into a common struct.
2020-06-28 07:54:12 +00:00
◱ PixelyIon
e7f880e782 Clear floating point registers on guest entry
Mesosphere does this too:
fa4a96d021/libraries/libmesosphere/source/arch/arm64/kern_k_thread_context.cpp (L135)
2020-06-28 03:49:10 +00:00
Billy Laws
f381883c0b Use X9 rather than LR when jumping to the guest
The homebrew ABI expects LR to be zero otherwise on exit it will jump to
it upon exit rather than exiting. Use X9 instead to fix this.
2020-06-28 03:49:10 +00:00
Billy Laws
b823f1cd0d Correct the handle argument in svcGetThreadPriority
The thread handle is sent in w1 rather than w0.
2020-06-28 03:49:10 +00:00
Billy Laws
138e219e0c Emulate TPIDR_EL0 accesses using TLS 2020-06-28 03:49:10 +00:00
Billy Laws
c423a66020
Fixes for control IPC (#57)
* Correctly handle -WithContext IPC Requests

They should be treated the same as the non WithContext variants.

* Only send domain data on non-control IPC responses

Control IPC doesn't make use of domains so we shouldn't send extra data
in the response.

* Add the IStorage implementation to CMakeLists
2020-06-23 18:49:06 +00:00
Billy Laws
8d470d3218 Introduce basic RomFS support
This commit adds support for reading the RomFS data from an NRO and
obtaining an IStorage handle to it through 'OpenDataStorageByCurrentProcess'.
There is currently only support for reading and no support
for enlarging or writing.

Also fixup a few capitalisation issues.
2020-06-22 16:45:32 +00:00
Billy Laws
b9b889fc3c Add loader to the emulator state
This will allow accessing data from the loader within other parts of the
emulator, such as in fssrv for RomFS.
2020-06-22 16:45:32 +00:00
Billy Laws
1bb979a7e1 Introduce new loader JNI for parsing application data and port Kotlin
code to use it

This will help ease the process of implementing new formats in the
future and remove duplicated code.
2020-06-20 20:26:53 +00:00
Billy Laws
dca06f2b49 Rework loader abstractions and the NRO loader to use the vfs APIs
This will make it easier for us to implement more executable formats in
the future.
2020-06-20 20:26:53 +00:00
Billy Laws
4950dd5638 Introduce NACP class for reading control data
This contains info such as the application name and publisher.
2020-06-20 20:26:53 +00:00
Billy Laws
5c103ce9a6 Introduce basic VFS backing system together with two implementations
- The backing system provides a flexible way to access a a region of
   abstract memory.

- It is currently barebones and only has support for reading data but
   this will be expanded as necessary.

The current implementations are:
- OsBacking - A backing that abstracts a linux file descriptor
- RegionBacking - A backing that creates a region from a portion of an
   existing one
2020-06-20 20:26:53 +00:00
◱ PixelyIon
4d787c904e Improvements to UI/UX
This commit makes a few improvements to the UI/UX:
* Crop Game Icons to ImageView
* Controller Support for Game List
* EmulationActivity is fullscreen now
2020-04-24 17:09:13 +05:30
Ivar
f909c00e31 Improve README
This commit improves the README by changing the license and adding in more extensive credit + changing up other parts of it.
2020-04-24 02:33:36 +05:30
◱ PixelyIon
925d05d049 Add String Support to IPC Push/Pop
This commit does some minor renaming/reordering in IPC and adds support for strings to IPC Push/Pop. It also fixes a tiny regression with the frametime display.
2020-04-23 22:26:27 +05:30
◱ PixelyIon
05f3e3c3ac Improve NCE and Finish Up Refactor
This commit mainly finishes up refactor by fixing everything brought up in the CR + Improving NCE somewhat and actually killing the child processes properly now.
2020-04-23 22:26:27 +05:30
◱ PixelyIon
c76ef3730b Move to MPL-2.0
We earlier moved to LGPLv3.0 or Later. This was a mistake as what we wanted was being able to link to proprietary libraries but LGPL is the opposite and it allows linking proprietary libraries to libskyline instead. After further consideration, we've moved to MPL-2.0, it allows linking to proprietary libraries and is a standardized license as compared to adding an exception to GPL.
2020-04-23 22:26:27 +05:30
◱ PixelyIon
1c54bff215 Make AppDialog Expand Fully and Fix Race in MainActivity::addEntries
This commit mainly fixes the issue with `AppDialog` where it didn't expand fully in landscape leading to UX issues. In addition, a race condition was fixed in `MainActivity::addEntries`, in regards to `foundCurrent` being returned incorrectly. The text in the performance counters were also made yellow and much more opaque.
2020-04-23 22:26:27 +05:30
◱ PixelyIon
a0b9a635ca Fix Killing Guest Processes in KThread::Kill and fix TID/PID naming
This commit mainly fixes the problem with process leakage before where the guest process wouldn't be killed. In addition, it clears up the problem with naming differences with PID/TID where purely PID was used before but that term is generally used to refer to the PGID. So, `KProcess` has a `pid` member but `KThread` has a `tid` member.
2020-04-23 22:26:27 +05:30
◱ PixelyIon
4637b4ac97 Run Android Studio Formatter on the Project
This commit fixes a lot of style errors throughout the project by letting the Android Studio Formatter fix them. This commit also splits the Circular Buffer into it's own file.
2020-04-23 22:26:27 +05:30
◱ PixelyIon
7f78a679c3 Add Performance Statistics to EmulationActivity
This commit adds performance statistics to the emulator that can be toggled in preferences. The layout of `EmulationActivity` was also changed from `ConstraintLayout` to `RelativeLayout` due to poor performance of the former.
2020-04-23 22:26:27 +05:30
◱ PixelyIon
fb1a158e8f Optimize Audio by using Circular Buffers, Handle Device Disconnection and Fix Some Bugs
This optimizes a lot of audio by using a circular buffer rather than queues. In addition to handling device disconnection using oboe callbacks and fix bugs in regards to audio saturation.
2020-04-23 22:26:27 +05:30
◱ PixelyIon
4e4ed5aac0 Refactor Audio
This commit refactors a lot of audio by fixing a lot of nitpicks here and there.
2020-04-23 22:26:27 +05:30
◱ PixelyIon
af98455ede Add Mutexes to Logger, Introduce util::MakeMagic and Refactor IPC
This commit adds mutexes to the logger so they produce a valid log file rather than breaking due to a race condition. It also introduced `util::MakeMagic` so the magic functions are far more clear. A small refactor of IPC was also done which cleared up some of the for loops.
2020-04-23 22:26:27 +05:30
◱ PixelyIon
91644255da Add Preference For Always Showing Game Information
This commit mainly adds a preference for always showing the game information. In addition to a tiny tweak to the contributing guidelines.
2020-04-23 22:26:27 +05:30
◱ PixelyIon
4500f54e85 Refactor Activities and Improve MainActivity
This commit mainly refactors all activities to bring them in-line with the guidelines and makes certain improvements such as using `Snackbar`s rather than `Toast`s where possible, Using `CoordinatorLayout` to allow the app bar to hide itself when possible, the app bar has also been consolidated into it's own layout file to increase layout redraw performance as existing views can be used.
2020-04-23 22:26:27 +05:30
◱ PixelyIon
0a5460f4fc Refactor Utilities
This refactors the utilities which at the moment is only `RandomAccessDocument`.
2020-04-23 22:26:27 +05:30
◱ PixelyIon
2ce8581aa6 Refactor + Redesign AppDialog
This commit refactors `AppDialog` by bringing it in line with the guidelines. In addition, it improves the design of it substantially by modifying the layout and making it a `BottomSheetDialogFragment`.
2020-04-23 22:26:27 +05:30
◱ PixelyIon
ce4d295d81 Refactor Preferences and Loaders
This refactors all preferences and loaders in regards to This commit mainly refactors the adapters by adding spacing, comments and following other guidelines. In addition, preferences are now moved into their own sub-package and `LicensePreference` has a minor UI update.
2020-04-23 22:26:27 +05:30
◱ PixelyIon
c9dcb070ad Grid Layout Support
With `RecyclerView` being used rather than `ListView` or `GridView`. It's now possible to display the items in a flexible manner and so support for a grid view in addition to the already existing list view was added in.
2020-04-23 22:26:27 +05:30
◱ PixelyIon
d86d5c1a35 Refactor and Convert Adapters to RecyclerView.Adapter
This commit mainly refactors the adapters by adding spacing, comments and following other guidelines. In addition, it moves from using `BaseAdapter` to `RecyclerView.Adapter` which leads to much cleaner adapter classes.
a
2020-04-23 22:26:27 +05:30
◱ PixelyIon
55a9f8e937 Refactor all Game-related Kotlin Classes/Objects
This refactors most game-related classes and objects mainly adding spacing, adding comments and making improvements if possible.
2020-04-23 22:26:27 +05:30
◱ PixelyIon
f4968793b8 Fix minor inaccuracy with VMM and mutexes
This commit fixes a tiny inaccuracy with the VMM which was a problem with block insertion, The mutexes on the other hand had a minor issue regarding owner checks.
2020-04-23 22:26:27 +05:30
◱ PixelyIon
41ddaf7f33 Add in Licenses to Settings
This commit adds in all the licenses to the end of settings by introducing a new type of preference: "LicensePreference"
2020-04-23 22:26:27 +05:30
◱ PixelyIon
820bbaede5 Fix occurrence of multiple headers in game list + Make TinyXML2 Static
This commit mainly fixes multiple headers in the game list, which was caused by using the wrong variable for the recursive function. In addition, it makes TinyXML2 statically linked to libskyline which makes it the lone shared objects present in APKs.
2020-04-23 22:26:27 +05:30
◱ PixelyIon
72272fa4c2 Replace xdrop/fuzzywuzzy with tdebatty/java-string-similarity
This commit replaced `xdrop/fuzzywuzzy` with `tdebatty/java-string-similarity` as the former is under an incompatible GPLv3 license.
2020-04-23 22:26:27 +05:30
◱ PixelyIon
c37f350c02 Move from GPLv3 to LGPLv3 or later
Skyline has been licensed with GPLv3 but as we want to look into optional ads in the future, and that would require linking AdMob SDKs which are proprietary. So, we decided to move to LGPLv3 so we could keep that option open as a revenue stream. 

We've gathered consent from all contributors for the license change:
* PixelyIon - https://github.com/PixelyIon (Commit Author)
* Zephyren25 - https://github.com/zephyren25
* ByLaws - https://github.com/bylaws
* IvarWithoutBones - https://github.com/IvarWithoutBones
* Cyuubi - https://github.com/Cyuubi
* greggamesplayer - https://github.com/greggameplayer
2020-04-23 22:26:27 +05:30
◱ PixelyIon
c3c9982ddc Add Comments to Time Services + Fix IDE Case Conventions
This commit mainly just adds comments to parts of time services and fixes the case conventions in Android Studio.
2020-04-23 22:26:27 +05:30
◱ PixelyIon
a60ab89c5d Fix Include Order
This commit fixes the include order of files throughout the code-base to be compliant with the new guidelines.
2020-04-23 22:26:27 +05:30
◱ PixelyIon
d75d30b809 Minor Audio Refactor (and fix sm:IUserManager service name)
This makes some tiny changes to audio to make them compliant with the guidelines. In addition, to changing `IUserManager:IUserManager` to `sm:IUserManager`.
2020-04-23 22:26:27 +05:30
◱ PixelyIon
9f0ad46903 Refactor OS/Kernel
This refactors the OS/Kernel by adding spacing and fixing/adding comments in some cases, in addition to some other minor fixes here and there.
2020-04-23 22:26:27 +05:30
◱ PixelyIon
773ee25e5a Refactor Common
This refactored common by:
* Moving out as many constants to class/function local scopes from being declared in `common`
* Spacing out common and any function to which a constant was moved out to
* Fixing comments here and there
In addition, some naming inconsistencies were fixed as well.
2020-04-23 22:26:27 +05:30
◱ PixelyIon
bbdd41a86c Refactor NCE
This commit mainly just refactors NCE by adding spacing and fixing other minor errors. In addition, it adds comments to `nce/guest.h` and `nce/instructions.h`.
2020-04-23 22:26:27 +05:30
◱ PixelyIon
42d982c6fb Refactor Display Services and GPU
This commit addresses the incorrect hierarchy of the GPU and refactors them at the same time. Now, the hierarchy much closely matches HOS. This commit also introduces a texture classes, albeit they're not complete and only partially implemented.
2020-04-23 22:26:27 +05:30
◱ PixelyIon
5f072da2b8 Fix GitHub Actions Build + Move Stack to Shared Memory
This commit mainly fixes GitHub Actions builds which were broken due to an outdated version of Android NDK. In addition, it moves all stack to shared memory.
2020-04-23 22:26:27 +05:30
Max K
38f63eced3 Some small refactoring for the app (#38)
* Add Gradle versions plugin for simple dependency updates
* Update dependency versions
* Refactor MainActivity to be more Kotlin-like
* Simplify LogActivity a little
* Remove useless run calls in GameDialog
2020-04-23 22:26:27 +05:30
Billy Laws
4af37c4367 Refactor am services
Use the new service naming scheme.
Remove redundant casts and template specifiers in response.Push.
2020-04-23 22:26:27 +05:30
Billy Laws
616222a6db Refactor apm services
Use the new service naming scheme.
Switch to std::array for performanceConfig.
2020-04-23 22:26:27 +05:30
Billy Laws
52d47120a8 Refactor audio backend and services
Use the new service naming convention.
Move both audout and audren into one directory.
Close the audio stream upon emulator exit.
2020-04-23 22:26:27 +05:30
Billy Laws
2e0ac9bdd5 Refactor fatal services
Use the new service naming convention.
2020-04-23 22:26:27 +05:30
Billy Laws
644cfbe332 Refactor filesystem services
Use the new service naming convention.
2020-04-23 22:26:27 +05:30
Billy Laws
524cd26649 Refactor HID services
Use the new service naming convention.
Tidy up some unused includes.
Move constants to service namespace.
2020-04-23 22:26:27 +05:30