Run a virtual iPhone on an Apple Silicon Mac.
Swift
Duo: boot on the cover's own screen
Jacky5713cc40922a
diff --git a/Research/Guest/iphone_duo_bringup.md b/Research/Guest/iphone_duo_bringup.mdindex 71f783cf..e408a261 100644--- a/Research/Guest/iphone_duo_bringup.md+++ b/Research/Guest/iphone_duo_bringup.md@@ -4758,3 +4758,31 @@ within 32 points of an edge: swipe home, Control Center, Notification Center,and the Dock at the usual window size) no longer reach SpringBoard until theguest reboots; the host's VZ taps keep working. Seen with the bundle's ownbuild as well. Not yet explained.++## 2026-10-29 evening: the panel is the cover's++Main (the paravirtual panel) had been sized for the inner display,+2007×2853 (669×951 points), since the single-display design, where SpringBoard+laid the inner content out on Main itself (`VPhoneBootCommand` replaced the+machine's 1398×2034 screen with `iPhone19_4InnerScreen` on every boot). With+the two-display path that reason is gone: the inner display is its own+2853×2007 virtual display, and Main is the cover. A cover laid out on+669×951 points looked like a second inner display, not the Duo's outer one.++vphone-vm now boots the machine's own screen, 1398×2034 at 3x: the cover is+466×678 points with its native layout (the right-side Dock and status column+are the Duo's outer-display design). Open, the compositor fits the inner+display onto the panel turned upright and shrunk to 0.697, which leaves 23 px+bars along the panel's long sides. backboardd computes the same rectangle when+it adds the inner display (`vpLocateInnerPanelImage`, from the LCD's and the+inner display's pixel sizes) and maps each touch through it before turning it+by the mount; a touch in a bar lands on the inner display's edge.++Measured on the test VM (bundle built from this change):++- Taps logged in SpringBoard land at the expected points: inner, panel pixel+ (X, Y) of the landscape screenshot at ((X - 23.3) / 2.09, Y / 2.09) points+ for the centre and four corners; cover, at (X / 3, Y / 3).+- Guest screenshots match the VM window at offset (0, 0) in all four inner and+ three cover orientations (cover tested with Safari, which rotates on iPhone).+- Three launch-sequence captures: no black frames, 2-5 transient tiles.diff --git a/VPhoneExecutable/VPhoneVirtualization/UI/VPhoneBootCommand+VirtualMachine.swift b/VPhoneExecutable/VPhoneVirtualization/UI/VPhoneBootCommand+VirtualMachine.swiftindex 967d0220..1b7cdc7e 100644--- a/VPhoneExecutable/VPhoneVirtualization/UI/VPhoneBootCommand+VirtualMachine.swift+++ b/VPhoneExecutable/VPhoneVirtualization/UI/VPhoneBootCommand+VirtualMachine.swift@@ -17,15 +17,6 @@ extension VPhoneBootCommand {let vmDir = config.deletingLastPathComponent()- // One immutable physical Main backs both logical Duo panels. Keep- // enough native pixels for inner mode even when booting closed.- var screenWidth = manifest.screenConfig.width- var screenHeight = manifest.screenConfig.height- if manifest.guestDevice == .iPhone19_4 {- screenWidth = VPhoneGuestDevice.iPhone19_4InnerScreen.width- screenHeight = VPhoneGuestDevice.iPhone19_4InnerScreen.height- }-return try VPhoneVirtualMachine.Options(configURL: config,romURL: manifest.romImages.map { try manifest.resolve(path: $0.avpBooter, in: vmDir) },@@ -35,8 +26,8 @@ extension VPhoneBootCommand {memorySize: manifest.memorySize,sepStorageURL: manifest.resolve(path: manifest.sepStorage, in: vmDir),sepRomURL: manifest.romImages.map { try manifest.resolve(path: $0.avpSEPBooter, in: vmDir) },- screenWidth: screenWidth,- screenHeight: screenHeight,+ screenWidth: manifest.screenConfig.width,+ screenHeight: manifest.screenConfig.height,screenPPI: manifest.screenConfig.pixelsPerInch,screenScale: manifest.screenConfig.scale,kernelDebugPort: kernelDebugPort,diff --git a/VPhoneGuestComponents/FoldDisplay/FoldDisplayBackboard.m b/VPhoneGuestComponents/FoldDisplay/FoldDisplayBackboard.mindex 28519db9..d5153a6d 100644--- a/VPhoneGuestComponents/FoldDisplay/FoldDisplayBackboard.m+++ b/VPhoneGuestComponents/FoldDisplay/FoldDisplayBackboard.m@@ -5,6 +5,12 @@static id vpInnerRenderDisplay;+// Where the inner display's image lies on the panel, in the panel's normalized+// portrait frame. The panel is the cover's; SpringBoard's compositor+// (FoldDisplayPanel.m) fits the inner display onto it upright, centered and+// shrunk to fit, so touches on the panel are mapped through this rectangle.+static CGRect vpInnerPanelImage = {{0, 0}, {1, 1}};+// MARK: - the render display@protocol VPhoneInnerDisplayInitialization@@ -35,6 +41,29 @@ static void vpTagUnknownDisplay(id display) {vpFoldDisplayLog([NSString stringWithFormat:@"inner display: tag %@ (%lu)", describe(unknown), (unsigned long)unknown]);}+static CGSize vpDisplayPixels(id display) {+ CGRect bounds = CGRectZero;+ id value = [display valueForKey:@"bounds"];+ if ([value isKindOfClass:NSValue.class] && strcmp([value objCType], @encode(CGRect)) == 0) [value getValue:&bounds];+ return bounds.size;+}++static void vpLocateInnerPanelImage(id server, id inner) {+ CGSize panel = CGSizeZero, pixels = vpDisplayPixels(inner);+ for (id display in [server valueForKey:@"displays"])+ if ([[display valueForKey:@"name"] isEqual:@"LCD"]) panel = vpDisplayPixels(display);+ if (panel.width < 1 || pixels.width < 1) {+ vpFoldDisplayLog([NSString stringWithFormat:@"inner display: panel size unknown ({%.0f, %.0f}), touches unfitted", panel.width, panel.height]);+ return;+ }+ CGSize upright = pixels.width > pixels.height ? CGSizeMake(pixels.height, pixels.width) : pixels;+ CGFloat scale = MIN(1, MIN(panel.width / upright.width, panel.height / upright.height));+ CGSize image = CGSizeMake(upright.width * scale / panel.width, upright.height * scale / panel.height);+ vpInnerPanelImage = CGRectMake((1 - image.width) / 2, (1 - image.height) / 2, image.width, image.height);+ vpFoldDisplayLog([NSString stringWithFormat:@"inner display: on the {%.0f, %.0f} panel at {%.4f, %.4f, %.4f, %.4f}",+ panel.width, panel.height, vpInnerPanelImage.origin.x, vpInnerPanelImage.origin.y, image.width, image.height]);+}+// Adds the inner panel's render display to a render server, once. It is// never removed: FrontBoard keeps identities for the life of the monitor.static BOOL vpAddInnerRenderDisplayToServer(id server) {@@ -59,6 +88,7 @@ static BOOL vpAddInnerRenderDisplayToServer(id server) {((void (*)(id, SEL, BOOL))objc_msgSend)(display, setEnabled, YES);vpTagUnknownDisplay(display);vpInnerRenderDisplay = display;+ vpLocateInnerPanelImage(server, display);vpFoldDisplayLog([NSString stringWithFormat:@"inner display: render display added %@ uniqueId=%@", display,[display respondsToSelector:sel_registerName("uniqueId")] ? [display valueForKey:@"uniqueId"] : @"-"]);return YES;@@ -160,6 +190,7 @@ static id vpInnerDigitizerState(id self, SEL selector, id service) {// reports positions on the portrait cover panel, which backboardd would// stretch onto the inner display's landscape space unturned; while the// inner display has the digitizer, each finger's normalized position is+// taken into the inner display's image on the panel (vpInnerPanelImage) and// turned by the mount first.typedef struct __IOHIDEvent *VPHIDEventRef;static IMP vpOriginalHandleDirectTouch;@@ -171,9 +202,11 @@ static void (*vpHIDEventSetFloat)(VPHIDEventRef, uint32_t, double);static void vpTurnDigitizerPosition(VPHIDEventRef event) {static const uint32_t digitizer = 11, x = 11 << 16, y = (11 << 16) | 1;if (vpHIDEventType(event) == digitizer) {- double nx = vpHIDEventGetFloat(event, x), ny = vpHIDEventGetFloat(event, y);- vpHIDEventSetFloat(event, x, 1 - ny);- vpHIDEventSetFloat(event, y, nx);+ CGRect image = vpInnerPanelImage;+ double u = MIN(1, MAX(0, (vpHIDEventGetFloat(event, x) - image.origin.x) / image.size.width));+ double v = MIN(1, MAX(0, (vpHIDEventGetFloat(event, y) - image.origin.y) / image.size.height));+ vpHIDEventSetFloat(event, x, 1 - v);+ vpHIDEventSetFloat(event, y, u);}CFArrayRef children = vpHIDEventChildren(event);for (CFIndex index = 0; children && index < CFArrayGetCount(children); index++)diff --git a/VPhoneKit/VPhoneCoreKit/VirtualMachine/VPhoneGuestDevice.swift b/VPhoneKit/VPhoneCoreKit/VirtualMachine/VPhoneGuestDevice.swiftindex e5d2089d..4cd0893a 100644--- a/VPhoneKit/VPhoneCoreKit/VirtualMachine/VPhoneGuestDevice.swift+++ b/VPhoneKit/VPhoneCoreKit/VirtualMachine/VPhoneGuestDevice.swift@@ -136,20 +136,11 @@ public struct VPhoneGuestDevice: Sendable, Equatable {/// iPhone 18 Pro (V63AP): 1206x2622, 402x874 points.public static let iPhone19_2 = iPhone("iPhone19,2", "v63ap", "iPhone 18 Pro", width: 1206, height: 2622)- /// iPhone Duo (V68AP), using only its outer display for initial bring-up.- /// The inner display and hinge are not represented by the VM's single panel.+ /// iPhone Duo (V68AP). The VM's panel is its outer display (the cover); the+ /// guest publishes the inner display as a second, virtual display and shows+ /// it on that panel while the device is open (libvphonefolddisplay).public static let iPhone19_4 = iPhone("iPhone19,4", "v68ap", "iPhone Duo", width: 1398, height: 2034)- /// The Duo's inner display, the panel the fold opens onto. A machine is- /// created on the outer panel above; the open and book postures- /// relaunch on this one — the host refuses runtime display resizing- /// (measured 2026-10-25, see Research/Guest/iphone_duo_bringup.md), so- /// the panel is chosen at boot. Apple's iPhone Duo device profile declares- /// 2007×2853 at 3x (669×951 points); 2034 was a custom bring-up width.- public static let iPhone19_4InnerScreen = VPhoneVirtualMachineManifest.ScreenConfig(- width: 2007, height: 2853, pixelsPerInch: 460, scale: 3.0- )-/// iPhone XS Max: 1242x2688 at 458 ppi, 414x896 points. Its IPSW carries the/// iOS 18 releases after 18.6, which the iPhone 16 never got; the research/// board's own iOS 18 kernel boots it (the 18.x kernelcache recipes, `minimal`