HLE: Implemented ILockAccessor and ICommonStateGetter commands and stubs for Virtual Boy – Nintendo Classics #3

- Moves emulation past the initial frame by providing the necessary inputs the game expects. Apparently games like to spin until they get what they want.

Co-authored-by: Mythrax <mythrax@mythrax-rs.org>
This commit is contained in:
Max
2026-08-29 10:49:56 -05:00
committed by KeatonTheBot
co-authored by Mythrax
parent 54e2f79c16
commit 02d8eeb18f
3 changed files with 255 additions and 3 deletions
@@ -12,12 +12,23 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys
{
class ICommonStateGetter : DisposableIpcService
{
// Nintendo serves the VR goggle commands based on Title ID, apparently.
private static ReadOnlySpan<ulong> _supportedVRGoggleTitles =>
[
0x0100CA001D972000, // Nintendo Classics: Virtual Boy NSO
0x0100BFC01D976000 // Nintendo Classics: Virtual Boy NSO
];
private int _resolutionWidth = 1280;
private int _resolutionHeight = 720;
private readonly ServiceCtx _context;
private readonly Apm.ManagerServer _apmManagerServer;
private readonly Apm.SystemManagerServer _apmSystemManagerServer;
private bool _vrModeEnabled;
private bool _vrMode3dEnabled;
#pragma warning disable CS0414, IDE0052 // Remove unread private member
private bool _lcdBacklighOffEnabled;
private bool _requestExitToLibraryAppletAtExecuteNextProgramEnabled;
@@ -153,6 +164,47 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys
return ResultCode.Success;
}
[CommandCmif(30)]
// GetHomeButtonReaderLockAccessor() -> nn::am::service::ILockAccessor
public ResultCode GetHomeButtonReaderLockAccessor(ServiceCtx context)
{
// We currently do not have any home button functionality, so it's fine to stub this for now.
// Similar to using GetReaderLockAccessorEx() with inval=0.
Logger.Stub?.PrintStub(LogClass.ServiceAm);
MakeObject(context, new ILockAccessor(context));
return ResultCode.Success;
}
[CommandCmif(31)] // 2.0.0 +
// GetReaderLockAccessorEx(uint unknown) -> nn::am::service::ILockAccessor
public ResultCode GetReaderLockAccessorEx(ServiceCtx context)
{
uint unknown = context.RequestData.ReadUInt32();
Logger.Stub?.PrintStub(LogClass.ServiceAm, new { unknown });
if (unknown < 0 || unknown > 3)
{
throw new ArgumentOutOfRangeException(nameof(unknown));
}
MakeObject(context, new ILockAccessor(context));
return ResultCode.Success;
}
[CommandCmif(32)] // 2.0.0+
// GetWriterLockAccessorEx(uint unknown) -> nn::am::service::ILockAccessor
public ResultCode GetWriterLockAccessorEx(ServiceCtx context)
{
uint unknown = context.RequestData.ReadUInt32();
Logger.Stub?.PrintStub(LogClass.ServiceAm, new { unknown });
if (unknown < 0 || unknown > 3)
{
throw new ArgumentOutOfRangeException(nameof(unknown));
}
MakeObject(context, new ILockAccessor(context));
return ResultCode.Success;
}
[CommandCmif(50)] // 3.0.0+
// IsVrModeEnabled() -> b8
public ResultCode IsVrModeEnabled(ServiceCtx context)
@@ -177,8 +229,8 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys
// SetLcdBacklighOffEnabled(b8)
public ResultCode SetLcdBacklighOffEnabled(ServiceCtx context)
{
// NOTE: Service sets a private field here, maybe this field is used somewhere else to turned off the backlight.
// Since we don't support backlight, it's fine to do nothing.
// NOTE: Service sets a private field here, maybe this field is used somewhere else to turn off the backlight.
// Since we don't support the backlight feature, it's fine to stub it.
_lcdBacklighOffEnabled = context.RequestData.ReadBoolean();
@@ -298,18 +350,43 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys
return (ResultCode)_apmSystemManagerServer.GetCurrentPerformanceConfiguration(context);
}
[CommandCmif(130)] // 21.0.0+
// EnableStartupLogoDisappearedMessage()
public ResultCode EnableStartupLogoDisappearedMessage(ServiceCtx context)
{
// NOTE: Service only delivers the message once the startup logo has actually
// disappeared. We never display one, so it is already deliverable. Callers
// gate their first frame on this message and hang without it.
AppletStateMgr appletState = context.Device.System.AppletState;
appletState.Messages.Enqueue(AppletMessage.StartupLogoDisappeared);
appletState.MessageEvent.ReadableEvent.Signal();
return ResultCode.Success;
}
[CommandCmif(300)] // 9.0.0+
// GetSettingsPlatformRegion() -> u8
public ResultCode GetSettingsPlatformRegion(ServiceCtx context)
{
PlatformRegion platformRegion = context.Device.System.State.DesiredRegionCode == (uint)RegionCode.China ? PlatformRegion.China : PlatformRegion.Global;
// FIXME: Call set:sys GetPlatformRegion
context.ResponseData.Write((byte)platformRegion);
return ResultCode.Success;
}
[CommandCmif(610)] // 21.0.0+
// UnknownCommand610(long unknown)
public ResultCode UnknownCommand610(ServiceCtx context)
{
long unknown = context.RequestData.ReadInt64();
Logger.Stub?.PrintStub(LogClass.ServiceAm, new { unknown });
return ResultCode.Success;
}
[CommandCmif(900)] // 11.0.0+
// SetRequestExitToLibraryAppletAtExecuteNextProgramEnabled()
public ResultCode SetRequestExitToLibraryAppletAtExecuteNextProgramEnabled(ServiceCtx context)
@@ -320,6 +397,100 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys
return ResultCode.Success;
}
[CommandCmif(1000)] // 19.0.0+
// BeginVrMode3d()
public ResultCode BeginVrMode3d(ServiceCtx context)
{
// NOTE: Service also applies a stereo scale to the goggle display, which we don't
// model, so only the state is kept here.
_vrMode3dEnabled = true;
return ResultCode.Success;
}
[CommandCmif(1001)] // 19.0.0+
// EndVrMode3d()
public ResultCode EndVrMode3d(ServiceCtx context)
{
_vrMode3dEnabled = false;
return ResultCode.Success;
}
[CommandCmif(1002)] // 19.0.0+
// IsVrModeEnabled3d() -> b8
public ResultCode IsVrModeEnabled3d(ServiceCtx context)
{
context.ResponseData.Write(_vrMode3dEnabled);
return ResultCode.Success;
}
[CommandCmif(1003)] // 21.0.0+
// GetVrLaboGoggleViewport() -> (s32 x, s32 y, s32 width, s32 height)
public ResultCode GetVrLaboGoggleViewport(ServiceCtx context)
{
if (!IsVrLaboGoggleSupportedTitle(context))
{
return ResultCode.ObjectInvalid;
}
int VrDisplayCoordinateX = 0;
int VrDisplayCoordinateY = 0;
int VrDisplayWidth = _resolutionWidth;
int VrDisplayHeight = _resolutionHeight;
context.ResponseData.Write(VrDisplayCoordinateX);
context.ResponseData.Write(VrDisplayCoordinateY);
context.ResponseData.Write(VrDisplayWidth);
context.ResponseData.Write(VrDisplayHeight);
return ResultCode.Success;
}
[CommandCmif(1004)] // 21.0.0+
// GetPanelPhysicalSizeForSpecificTitle() -> (f32 width, f32 height)
public ResultCode GetPanelPhysicalSizeForSpecificTitle(ServiceCtx context)
{
if (!IsVrLaboGoggleSupportedTitle(context))
{
return ResultCode.ObjectInvalid;
}
// The switch provides micrometres, but the command reports millimetres.
// 6.2 inch 16:9 panel.
float PanelPhysicalWidthMicroMeters = 137250f;
float PanelPhysicalHeightMicroMeters = 77200f;
context.ResponseData.Write(PanelPhysicalWidthMicroMeters / 1000f);
context.ResponseData.Write(PanelPhysicalHeightMicroMeters / 1000f);
return ResultCode.Success;
}
[CommandCmif(1005)] // 21.0.0+
// GetPanelResolutionForSpecificTitle() -> (s32 width, s32 height)
public ResultCode GetPanelResolutionForSpecificTitle(ServiceCtx context)
{
if (!IsVrLaboGoggleSupportedTitle(context))
{
return ResultCode.ObjectInvalid;
}
context.ResponseData.Write(_resolutionWidth);
context.ResponseData.Write(_resolutionHeight);
return ResultCode.Success;
}
private static bool IsVrLaboGoggleSupportedTitle(ServiceCtx context)
{
ulong programId = context.Device.Processes.ActiveApplication.ProgramId;
return _supportedVRGoggleTitles.Contains(programId);
}
protected override void Dispose(bool isDisposing)
{
if (isDisposing)
@@ -0,0 +1,80 @@
using Ryujinx.Common.Logging;
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.Horizon.Common;
using System;
namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.SystemAppletProxy
{
class ILockAccessor : IpcService
{
private readonly ServiceCtx _context;
private readonly Apm.ManagerServer _apmManagerServer;
private readonly Apm.SystemManagerServer _apmSystemManagerServer;
private readonly KEvent _lockEvent;
private int _lockEventHandle;
public ILockAccessor(ServiceCtx context)
{
_context = context;
_apmManagerServer = new Apm.ManagerServer(context);
_apmSystemManagerServer = new Apm.SystemManagerServer(context);
_lockEvent = new KEvent(context.Device.System.KernelContext);
}
[CommandCmif(1)]
// TryLock(unknown u8 bool) -> unknown u8 bool
public ResultCode TryLock(ServiceCtx context)
{
// Official sw only uses inflag=false.
// Official sw just closes the output handle.
// The input flag controls whether this returns the output handle.
bool unknown = context.RequestData.ReadBoolean();
Logger.Stub?.PrintStub(LogClass.ServiceAm, new { unknown });
context.ResponseData.Write(false);
context.Response.HandleDesc = IpcHandleDesc.MakeCopy(_lockEventHandle);
return ResultCode.Success;
}
[CommandCmif(2)]
// Unlock()
public ResultCode Unlock(ServiceCtx context)
{
Logger.Stub?.PrintStub(LogClass.ServiceAm);
return ResultCode.Success;
}
[CommandCmif(3)]
// GetEvent() -> EventHandle w/ autoclear = false
public ResultCode GetEvent(ServiceCtx context)
{
if (_lockEventHandle == 0)
{
if (context.Process.HandleTable.GenerateHandle(_lockEvent.ReadableEvent, out _lockEventHandle) != Result.Success)
{
throw new InvalidOperationException("Out of handles!");
}
}
context.Response.HandleDesc = IpcHandleDesc.MakeCopy(_lockEventHandle);
Logger.Stub?.PrintStub(LogClass.ServiceAm);
return ResultCode.Success;
}
[CommandCmif(4)] // 10.0.0+
// IsLocked() -> unknown u8 bool
public ResultCode IsLocked(ServiceCtx context)
{
Logger.Stub?.PrintStub(LogClass.ServiceAm);
context.ResponseData.Write(false);
return ResultCode.Success;
}
}
}
@@ -32,5 +32,6 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys
DetectShortPressingCaptureButton = 90,
AlbumScreenShotTaken = 92,
AlbumRecordingSaved = 93,
StartupLogoDisappeared = 95, // 21.0.0+
}
}