Fix/civilization#2180
Conversation
There was a problem hiding this comment.
Pull request overview
This PR (titled "Fix/civilization", presumably for the Civilization DOS game) refactors DosFcbManager's public FCB entry points to take SegmentedAddress instead of pre-computed uint linear addresses, and updates the only caller (DosInt21Handler) accordingly. It also inlines the two previously-extracted FCB log helpers and rewords a few XML doc summaries / the implementation-reference paragraph. The PR description is empty, so the specific Civilization-related symptom and fix rationale are not documented.
Changes:
- Change every FCB-related method signature in
DosFcbManager(e.g.OpenFile,CloseFile,SequentialRead/Write,RandomRead/Write,RandomBlockRead/Write,ParseFilename,GetFcb, etc.) fromuint fcbAddresstoSegmentedAddress fcbAddress, converting back to a physical address inside viaMemoryUtils.ToPhysicalAddress(seg, off)(which is the same computation asSegmentedAddress.Linear). - Update all call sites in
DosInt21Handlerto pass theSegmentedAddressdirectly instead of.Linear. - Inline the
LogFcbWarning/LogFcbDebugprivate helpers into ~35+ duplicatedif (IsEnabled) { _loggerService.Warning/Debug(...) }blocks, and tweak a few XML doc strings.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Spice86.Core/Emulator/OperatingSystem/DosFcbManager.cs | FCB API now takes SegmentedAddress; address converted via MemoryUtils.ToPhysicalAddress; log helpers inlined; some doc comments reworded but <param> docs still say "Linear address". |
| src/Spice86.Core/Emulator/InterruptHandlers/Dos/DosInt21Handler.cs | All FCB call sites updated to pass fcbAddress / stringAddress directly instead of .Linear. |
Comments suppressed due to low confidence (2)
src/Spice86.Core/Emulator/OperatingSystem/DosFcbManager.cs:1213
MemoryUtils.ToPhysicalAddress(fcbAddress.Segment, fcbAddress.Offset)is computed identically toSegmentedAddress.Linear(both dosegment << 4 + offset, seeSegmentedAddress.cs:22andMemoryUtils.cs:20). The repeated explicit call adds verbosity without changing behavior — usingfcbAddress.Linearwould be clearer and consistent with the rest of the codebase. Note that switching toToPhysicalAddressdoes NOT address the segment-rollover concern described in the codebase guidelines, since the formula is identical. If the intent of this refactor was to handle rollover correctly, an MMU-based translation (IMmu.TranslateAddress) should be used instead. This pattern is repeated throughoutGetFcbandGetActualFcbBaseAddress.
private uint GetActualFcbBaseAddress(SegmentedAddress fcbAddress) {
// Extended FCB detection via drive marker 0xFF
DosFileControlBlock probe = new DosFileControlBlock(_memory, MemoryUtils.ToPhysicalAddress(fcbAddress.Segment, fcbAddress.Offset));
if (probe.DriveNumber == 0xFF) {
return MemoryUtils.ToPhysicalAddress(fcbAddress.Segment, fcbAddress.Offset) + DosExtendedFileControlBlock.HeaderSize;
}
return MemoryUtils.ToPhysicalAddress(fcbAddress.Segment, fcbAddress.Offset);
}
src/Spice86.Core/Emulator/OperatingSystem/DosFcbManager.cs:301
- Inlining the previous
LogFcbWarning/LogFcbDebughelpers duplicates the sameif (_loggerService.IsEnabled(...)) { _loggerService.Warning/Debug("FCB {Operation} ...", ...) }block roughly 35+ times. The deleted helpers (former lines 1374–1383) were a clean, low-cost abstraction that ensured a consistent log format and consistent IsEnabled gating. Reintroducing them (or keeping them) would substantially reduce noise in this file and avoid future drift between log call sites. Consider keeping the helpers.
if (_loggerService.IsEnabled(LogEventLevel.Warning)) {
_loggerService.Warning("FCB {Operation} failed at 0x{Address:X} because {Reason}", "OPEN", baseAddr, "Blank filename");
}
return FcbStatus.Error;
}
DosFileOperationResult result = _dosFileManager.OpenFileOrDevice(fileSpec, FileAccessMode.ReadWrite);
if (result.IsError || result.Value == null) {
if (_loggerService.IsEnabled(LogEventLevel.Warning)) {
_loggerService.Warning("FCB {Operation} failed at 0x{Address:X} because {Reason}", "OPEN", baseAddr, "OpenFileOrDevice failed");
}
All FCB-related methods in DosInt21Handler and DosFcbManager now accept SegmentedAddress instead of raw linear addresses. This makes segment:offset usage explicit, reduces manual address translation, and improves correctness. Address translation to physical addresses is now handled internally where needed, and FCB structure instantiations are updated accordingly. fix: Inline FCB logs to avoid string allocations Fix XML doc comments: update param descriptions from "Linear address" to "Segmented address" in DosFcbManager Agent-Logs-Url: https://github.com/OpenRakis/Spice86/sessions/49811e96-8ffc-42de-9b9f-50e396e4bdb4 Co-authored-by: maximilien-noal <1087524+maximilien-noal@users.noreply.github.com> tests: fix FCB tests not building refactor: removed unused helper in FCB tests
Refactored DosFcbManager.FindFirst to delegate to the unified file search, matching FreeDOS behavior and populating the DTA in the standard extended format. Updated XML docs to clarify this. Rewrote and removed tests in DosFcbManagerTests to expect the extended DTA layout, including for volume label handling.
…ugger) Updated the project version from 13.1.2 to 14 in Directory.Build.props. Also changed the package release notes link to reference the v14 release notes.
e406e19 to
618a4c3
Compare
Added "Quick navigation" to README and documented the new I/O port handler system in both README.md and index.html. Introduced a dedicated "I/O Port Handlers" section with usage instructions, a summary table, and callouts. Updated index.html with new callout styles and enhanced navigation, including quick start and compatibility tips.
This reverts commit 8d9d80f.
Description of Changes
Removes regression from commit 5b8a876 which broke Civilization.
Rationale behind Changes
Fixes Civilization :
Makes us stick to FreeDOS kernel behavior regarding FindFirst and FindNext
Suggested Testing Steps
Tests updated accordingly. They all pass. Tested manually with Civilization.