Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions docs/decomp/AppShell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# App Shell

Start up and the frame loop of the 5960 retail binary. The app object lives at `0x0017e7a0`.

## Functions

| Address | Name | What it does |
|---------|------|--------------|
| 0x0002c520 | Alert | Formats into a 512 character buffer; retail drops the text |
| 0x0002c570 | app constructor | Frame clock from `GetTickCount`, root class, launch data (below) |
| 0x0002c660 | XboxInitRenderState | Startup render states one by one, motion blur factor 1 |
| 0x0002ccf0 | InitD3D | Present parameters by AV pack, see the video notes; creates the device |
| 0x0002d0e0 | Draw | Below |
| 0x0002d7e0 | InitApp | Below |
| 0x0002d930 | CleanupApp | XOnline cleanup, matrix stack, scene, class, `Class_Exit`, XIP sections, `Text_Exit`, DirectSound, app dir |
| 0x0002da00 | XApp | `InitApp`, then forever: clock, keyboard poll, camera, lerpers, scene advance, deferred deletes, `Draw` |
| 0x0002dbc0 | GetStartupClassFile | `y:\default.xap`, current dir `y:/default.xap` |
| 0x0002dc80 | main | Crash handler unless the hardware is a debug kit, then `XApp` |
| 0x0002dcc0 | XboxFormatMemoryUnit | Device object into a 32 byte name, `XapiFormatFATVolume`, close |
| 0x0002dd20 | Xbox_Init | Below |
| 0x00062750 | DSound_Init | Below |

## Launch data

When `*LaunchDataPage` is set and its type is 1 (`LDT_LAUNCH_DASHBOARD`), the 3 KB of launch data
are copied into the app (title id, reason, context, two parameters), the page pointer is cleared and
the page freed with `MmFreeContiguousMemory`.

## InitApp and Xbox_Init

```
_set_new_handler(...); open the CD service; g_BootType = GetDiscType();
Xbox_Init():
PAL-I or PAL-M: clear the 480p video flag
XSetFileCacheSize(1 MB); drive links; xboxdashdata.<id> or the default data dir
create C:\TDATA\fffe0000\music; T:\NoisyCamera; keyboard languages
XInitDevices(0, 0); wait while XGetDeviceEnumerationStatus() is busy; open keyboards
delete t:\tempcda.cda and t:\tempwma.wma; remember the game region
srand(GetTickCount()); version lock with the online dash; XOnline start up (may reboot into it)
InitD3D(); LoadXIP; Class_Init; title root; Material_Init;
load y:\default.xap, create it, D3DXCreateMatrixStack, call its initialize
```

DirectSound is not touched here. `DSound_Init` runs the first time a sound buffer is asked for:

```
if (g_BootType == DISC_VIDEO) return false;
speaker override = (XGetAudioFlags() low word == mono);
DirectSoundCreate(0, &g_pDirectSound, 0);
SetMixBinHeadroom(bin, 0) for all 31 mix bins;
CreateThread(worker): while (g_pDirectSound) { DirectSoundDoWork(); Sleep(100); }
```

## Draw

Projection when dirty (field of view, aspect, near and far from the bound viewpoint and navigation
info). The sky color (or dark blue `0xff00004c`) clears the frame, and a background's backdrop
draws over it; while a transition blurs (factor under 1, sky black, no backdrop, past the first two
frames) a black quad with that alpha fades the last frame instead. A default material (grey, made
once), the scene from an identity world, then Present.
50 changes: 50 additions & 0 deletions docs/decomp/Config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Config

The `Config` node in the 5960 retail binary (`0x0003a430..0x0003b9e0`, FND table at `0x0017fdf0`).
Nearly everything is one EEPROM DWORD read with `XQueryValue` and written back with `XSetValue`;
5960 never checks either result.

| Setting | Index | Bits used |
|---------|-------|-----------|
| Language | 7 (`XC_LANGUAGE`) | whole value; 0 or past the last language reads as 1 (English) |
| Video flags | 8 | widescreen 0x10000, 720p 0x20000, 1080i 0x40000, 480p 0x80000, letterbox 0x100000, PAL60 0x400000 |
| Audio flags | 9 | low word speakers (0 stereo, 1 mono, 2 surround), Dolby Digital 0x10000, DTS 0x20000 |
| Game rating | 10 | stored as 6 - level |
| Pass code | 11 | one nibble per pad press, below |
| Movie rating | 12 | stored as 7 - level |
| Misc flags | 0x11 | don't use DST 2, hide Live today 4, legal notice accepted 8 |

## Notes per function

- `GetVideoMode` (`0x0003a860`): letterbox wins (1), else widescreen (2), else 0.
`SetVideoMode` (`0x0003a8a0`) clears both, sets the chosen one and, if widescreen changed, flips the
widescreen present flag, zeroes D3D's cached AV mode and resets the device; it always marks the
projection dirty.
- `Set480Support` (`0x0003a980`): stores the bit; while a DVD plays on an HDTV pack with the 480p
Macrovision hardware flag it also switches the display between progressive and interlaced.
- `GetAudioMode` / `SetAudioMode` (`0x0003abb0`, `0x0003abf0`): script modes 0 mono, 1 stereo,
2 surround; the encodings in the high word stay.
- `EncodePassword` (`0x0003b0a0`): `code = code * 16 + n` per character with u1 d2 l3 r4 a5 b6 x7 y8
B9 W10 L11 R12, anything else 0.
- `GetTimeZone` (`0x0003ae80`): with no zone set the default is 11, 60 or 25 by game region (North
America, Japan, elsewhere). `GetDSTAllowed` / `GetDST` need both transition months set.
- `GetLaunchReason` (`0x0003b2d0`): names by reason through the jump table at `0x0003b3ac`:
1 Error, 2 Memory, 3 Settings, 4 Music, 12 FromOnlineDash, 13 FriendsInternal, 14 VoiceChatInternal,
15 MessagesInternal, 16 AccountManagementInternal, 17 NewAccountInternal, 18 AccountRecoveryInternal,
19 NetworkSettingsInternal; anything else, or no launch data, gives an empty string.
- `ForceSetLanguage` / `ForceSetTimeZone` / `ForceSetClock` (`0x0003a430..0x0003a470`): reason 3 and
bit 4, 2 or 1 of the first launch parameter.
- `BackToLauncher` (`0x0003b4b0`): a forced language, zone or clock reboots; otherwise
`default.xbe` on `\Device\CdRom0` relaunches with the launch context.
- `BackToLauncher2` (`0x0003b550`): `settings_adoc.xip`, title 0xFFFE0000, context 'ADOC', from
wherever the dash's own drive link points.
- `GetFontVersion` (`0x0003a520`): the top byte of the font file's first DWORD as a digit, cached in
the node (+0x1c), -1 when there is no font file.
- `GetROMVersion` / `GetXdashVersion` (`0x0003b7b0`, `0x0003b860`): `%d.%02d.%d.%02d`; the dash
prints 1, 0, 5960, 1.
- `GetEthernetLinkStatus` (`0x0003b9d0`): `XNetGetEthernetLinkStatus() & 1`.

Theseus differs on purpose in `NtFileExists` / `FileExists` (drive letter mapping instead of
`NtOpenFile`), `GetRecoveryKey` (empty), `GoToXOnlineDash` (logs only), `ToggleNoisyCamera` (skin
setting instead of `T:\NoisyCamera`), `GetFontVersion` (system fonts per language), and adds the
SMBus, power, network, skin, modchip and XBE title id functions.
67 changes: 67 additions & 0 deletions docs/decomp/Disc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Disc Drive

The `DiscDrive` node and disc type detection in the 5960 retail binary. The boot disc type lives
at `0x0017aee4`; the node's type names are the table at `0x0017453c` (`none`, `unknown`, `Title`,
`Audio`, `Video`).

## Functions

| Address | Name | What it does |
|---------|------|--------------|
| 0x00039d70 | CDiscDrive::CDiscDrive | Joins the drive list, takes the starting type and tray state, below |
| 0x00039ec0 | CDiscDrive::~CDiscDrive | Leaves the list (freeing it when empty), frees the type string |
| 0x00039f20 | CDiscDrive::Advance | Deferred event, then a tray poll every 0.04 s, below |
| 0x0003a030 | CDiscDrive::getTrackCount | Audio track count when the boot type is Audio, else 0 |
| 0x0003a060 | CDiscDrive::FormatTotalTime | Disc length as `%02d:%02d` (see NtIoSvc.md) |
| 0x0003a150 | CDiscDrive::FormatTrackTime | One track's length the same way |
| 0x0003a260 | CDiscDrive::LaunchDisc | Keeps the display up; a game disc reboots the console, anything else `XLaunchNewImage(NULL)` |
| 0x0003a2b0 | GetDiscType | Below |

## Constructor

```
if (g_bHasLaunchData && reason == XLD_LAUNCH_DASHBOARD_DVDPLAYER && DoesFileExist("CDROM0:\video_ts\video_ts.ifo"))
g_BootType = DISC_VIDEO;
if ((g_bHasLaunchData && reason != 0x0C) || g_BootType == DISC_VIDEO || g_BootType == DISC_BAD)
{ m_nDiscType = g_BootType; HalReadSMCTrayState(&m_trayState, 0); }
else
{ m_nDiscType = DISC_NONE; m_trayState = 0x40; } // the first poll reports the disc
```

Reason `0x0C` is a return from the online dashboard.

## Advance

```
if (m_bDeferNotification && !m_locked) { m_bDeferNotification = false; fire inserted or removed; }
if (now - lastPoll < 0.04) return; // 0x0002c1c8, one clock for every drive
lastPoll = now;
if (HalReadSMCTrayState(&tray, 0) < 0 || tray == m_trayState) return;
m_trayState = tray; ResetScreenSaver();
g_BootType = GetDiscType();
if (g_BootType == m_nDiscType) return;
m_nDiscType = g_BootType; replace discType string;
if (m_locked) m_bDeferNotification = true; else fire OnDiscInserted (type != none) or OnDiscRemoved;
```

## GetDiscType

```
close the CD service; IoDismountVolumeByName("\??\CdRom0:");
if (HalReadSMCTrayState(&tray, 0) >= 0 && tray != 0x60 /* still detecting */) {
if (tray != 0x40 /* no media */) return DISC_NONE;
h = CreateFile("cdrom0:"); if (h == -1) return DISC_NONE;
bad = DeviceIoControl(h, IOCTL_CDROM_CHECK_VERIFY) || GetLastError() == ERROR_UNRECOGNIZED_MEDIA;
CloseHandle(h); return bad ? DISC_BAD : DISC_NONE;
}
open the CD service; if it found audio tracks return DISC_AUDIO;
type = DISC_BAD;
for each of default.xbe (Title), video_ts\video_ts.ifo (Video), track01.cda (Audio) on CDROM0:
if it exists return its type;
an error other than file or path not found retries the same file once after Sleep(100);
if (HalReadSMCTrayState(&tray, 0) >= 0 && tray != 0x60) type = DISC_NONE; // gone meanwhile
return type;
```

Theseus launches a game disc's `default.xbe` directly (after its Discord relay) instead of
rebooting, and adds `OpenTray`, `CloseTray` and the CD name lookups.
5 changes: 5 additions & 0 deletions docs/decomp/Input.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,8 @@ Every event goes through the binding and `enableGamepad` checks (`enableRemote`
Theseus's desktop node reads an SDL pad and the keyboard as one player, adds media keys, has no
remote or progressive scan combo, accepts pad events even with `enableGamepad` off, and fires
OnMoveCenter after the button events rather than before them.

The Xbox node (`xbox/input.cpp`) keeps 5960's devices, remote codes and event rules but reads each
port on its own instead of merging the pads first, records the last port that gave input
(`LastActivePort`), lets Theseus's overlay take moves and A/B while it captures input (B with the
left trigger shows or hides it), and has no progressive scan combo or keyboard event.
50 changes: 50 additions & 0 deletions docs/decomp/MemoryMonitor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Memory Monitor

The `MemoryMonitor` node in the 5960 retail binary (one global instance at `0x0017c610`). Memory
units are numbered `port * 2 + slot` (0..7) with the hard drive as 8. Layout: `curDevUnit` +0x1c,
`invalidDevUnit` +0x20, `blockInsertion` +0x24, `enumerationOn` +0x25, block totals +0x28/+0x2c,
slot totals +0x30/+0x34, preferred row/side/slot +0x38..+0x40, pending units +0x44, mounted flags
+0x48, mount letters +0x50.

## Functions

| Address | Name | What it does |
|---------|------|--------------|
| 0x0004be70 | CMemoryMonitor::CMemoryMonitor | Totals -1, hard drive selected, everything plugged in pending, one enumeration |
| 0x0004bf50 | CMemoryMonitor::UpdateValidDeviceFlags | Below |
| 0x0004c1f0 / 0x0004c210 | HaveDeviceTop / HaveDeviceBottom | Mounted flag of a port's slot, 0 for a bad port |
| 0x0004c3b0 | CMemoryMonitor::GetTotalAndFreeBlocks | `C:` or the unit's letter through `GetDiskFreeSpaceEx`, rounded up to 16 KB blocks, total less one for the root; a failure marks a unit gone and gives 0 |
| 0x0004c230 | (slot counter) | Xbox Live accounts: 8 on the hard drive less those stored, 1 on a unit without one |
| 0x0004c480 | CMemoryMonitor::Advance | Enumerate, fall back to the hard drive, refresh the selected drive's blocks, `OnTotalFreeChanged` |
| 0x0004c510..0x0004c6e0 | selectUp/Down/Left/Right | Below |
| 0x0004c7d0 | selectDevUnit | T or U is the hard drive, F..M a unit; enumerates once, selects if mounted |
| 0x0004c840 / 0x0004c8c0 | FormatDeviceName | `XMUNameFromDriveLetter` of a mounted unit (-1 is the selection), else "" |
| 0x0004cbc0 / 0x0004ca90 / 0x0004cb90 | FormatTotalBlocks / FormatFreeBlocks / GetTotalFreeBlocks | `%d`, capped as "50000+" |
| 0x0004c930 / 0x0004c9d0 / 0x0004cb60 | FormatTotalSlots / FormatFreeSlots / GetTotalFreeSlots | Slot counts, capped as "8+" |
| 0x0004cc70 | GetFreeTotalRatio | free / total, 0 when the drive can't be read |
| 0x0004ccd0 | SetMUName | Names a mounted unit when the name fits in 32 characters |
| 0x0004cd10 | FormatMemoryUnit | Unmount, format (0x0002dcc0), remount, rescan its titles |

## UpdateValidDeviceFlags

Runs only with `enumerationOn`, and only when `XGetDeviceChanges` reports something or a unit is
pending. Wakes the screen saver, then `pending = (pending & ~removed) | inserted` and for each unit
(bit `1 << port` for the top slot, `0x10000 << port` for the bottom):

- Removed: if mounted, unmount, clear its titles, and if it was selected select the hard drive
(`OnCurDevUnitChange`). If it was the bad unit, `OnInvalidMURemoved`. Then `OnDeviceChange`.
- Pending and insertion not blocked: up to three `XMountMURoot` tries. Mounted: clean it, set its
titles' root, `OnDeviceChange`. Not: it becomes the bad unit, is formatted, `OnDeviceChange`, then
`OnInvalidMU(unit, mounted now ? 1 : 0)`.

## Selection

Each unit has a path per direction (table `0x00174b38`, terminated by 0xFF); the first entry that is
the hard drive or a mounted unit wins. From the hard drive, up and down do nothing; left tries the
preferred row's port 1 or 2 (bottom slot first) then the other row, right ports 4 or 3 (top slot
first); nothing there leaves the hard drive selected with no event. Every move records the
preferred row (up 0, down 1) or side (left 0, right 1) and the unit's slot, then fires
`OnCurDevUnitChange`.

Theseus mounts units at H..O rather than F..M, counts slots from blocks (capped at 8) instead of
accounts, refuses `FormatMemoryUnit` for the hard drive, and returns 0 for an empty drive's ratio.
82 changes: 61 additions & 21 deletions docs/decomp/NtIoSvc.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,63 @@
# NtIoSvc

CD-ROM device I/O service. Wraps NT `DeviceIoControl` calls for CDROM access on Xbox. Backed by `ntiosvc.cpp` in the active source tree.

## CNtIoctlCdromService

The main class. Opens a handle to `CDROM0:` (the Xbox DVD drive's device path) and provides methods to query disc information.

### TOC Reading

Reads the disc's table of contents via `IOCTL_CDROM_READ_TOC`. The TOC contains track start addresses in MSF (Minutes/Seconds/Frames) format, which are converted to absolute frame offsets for seeking and playback calculations.

## XCDROM_TOC

Structure storing parsed disc information:

- **Track addresses**: Array of start frame offsets for each track on the disc.
- **Disc ID**: A hex string computed from the track frame offsets. This serves as a unique-enough identifier for matching discs against metadata databases (title, artist, track names).
- **Metadata fields**: Optional title, artist, and per-track name strings. Populated from external lookup if available; empty otherwise.

## Usage

Used by the disc-management and music-collection layers for audio CD detection and playback. When a disc is inserted, the service reads the TOC, computes the disc ID, and hands the result to the music system for track enumeration.
The CD-ROM service in the 5960 retail binary. One global instance lives at `0x00188780`: the drive
handle, then the audio track count (`0x00188784`), then the start frame of every track
(`0x00188788`). Audio CD detection, the disc's track times and the CD audio streamer all read it.

## Functions

| Address | Name | What it does |
|---------|------|--------------|
| 0x00064da0 | CNtIoctlCdromService::CNtIoctlCdromService | Handle -1, no tracks |
| 0x00064db0 | CNtIoctlCdromService::Close | Closes an open handle, sets it to -1, zeroes the track count |
| 0x00064dd0 | CNtIoctlCdromService::Open | Opens `CDROM0:` for reading; a failed open returns the error as an HRESULT; a disc with no usable table of contents closes it again but still returns 0 |
| 0x00064f20 | CNtIoctlCdromService::GetTableOfContents | Reads the TOC and fills the track list, below |
| 0x000650c0 | CNtIoctlCdromService::Read | Raw CDDA read with retries, below |

## GetTableOfContents

```
if (!DeviceIoControl(h, IOCTL_CDROM_READ_TOC, 0, 0, &toc, 0x324, &n, 0)) {
hr = HRESULT_FROM_WIN32(GetLastError());
if (hr < 0) return false; // ERROR_NOT_READY gets one try, same result
}
if (toc.LastTrack < toc.FirstTrack) return false;
i = 0;
do {
TrackAddr[i] = (Address[1] * 60 + Address[2]) * 75 + Address[3];
if (TrackNumber == 0xAA) break; // lead out
if (Control & 4) { // data track
Address[1] -= 2; Address[2] += 30;
if (Address[2] < 60) Address[1] -= 1; else Address[2] -= 60;
TrackAddr[i] = (recomputed); break;
}
} while (++i <= LastTrack - FirstTrack + 1); // i stays at the last entry read
LastTrack = i;
return i > 0;
```

A data track (an enhanced CD) is moved back two and a half minutes, the gap the drive leaves before
the second session, so the audio track before it ends where its sound does.

## Read

```
rri.DiskOffset = (start - 150) * 2048; rri.SectorCount = count; rri.TrackMode = CDDA;
for (;;) {
if (DeviceIoControl(h, IOCTL_CDROM_RAW_READ, &rri, 0x10, buf, count * 2352, &n, 0)) return 0;
hr = HRESULT_FROM_WIN32(GetLastError());
if (hr >= 0) break;
if (retries-- == 0) return hr;
}
return hr;
```

## Track times

The disc drive node's `FormatTotalTime` (`0x0003a060`) and `FormatTrackTime` (`0x0003a150`) read the
list directly: the length is `TrackAddr[LastTrack] - TrackAddr[0]` (or `[n + 1] - [n]` for a track
inside `0..LastTrack-1`), printed `%02d:%02d` as `(BYTE)(frames / 4500)` and `frames % 4500 / 75`.
With no disc open, or a track out of range, they return an empty string.

Theseus adds a disc id (each track's start frame as six hex digits) and title, artist and track name
slots that nothing fills yet.
Loading
Loading