Skip to content

Commit 44a5a50

Browse files
fix: replace State.CarryFlag direct assignments with SetCarryFlag helper in interrupt handlers (#2149)
Agent-Logs-Url: https://github.com/OpenRakis/Spice86/sessions/8887cd41-3172-4770-a1fa-07fd79d097c0 Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: maximilien-noal <1087524+maximilien-noal@users.noreply.github.com>
1 parent a278b00 commit 44a5a50

4 files changed

Lines changed: 17 additions & 15 deletions

File tree

src/Spice86.Core/Emulator/InterruptHandlers/Dos/DosDiskInt25Handler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public override void Run() {
2727

2828
if (driveNumber >= DosDriveManager.MaxDriveCount || !_dosDriveManager.HasDriveAtIndex(State.AL)) {
2929
State.AX = 0x8002;
30-
State.CarryFlag = true;
30+
SetCarryFlag(true, true);
3131
} else {
3232
if (sectorToRead == 1 && startingLogicalSector == 0) {
3333
if (driveNumber >= 2) {
@@ -37,7 +37,7 @@ public override void Run() {
3737
} else if(LoggerService.IsEnabled(Serilog.Events.LogEventLevel.Warning)) {
3838
LoggerService.Warning("Interrupt 25 called but not as disk detection, {DriveIndex}", State.AL);
3939
}
40-
State.CarryFlag = false;
40+
SetCarryFlag(false, true);
4141
State.AX = 0;
4242
}
4343
}

src/Spice86.Core/Emulator/InterruptHandlers/Dos/DosDiskInt26Handler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ public override void Run() {
2323
}
2424
if (State.AL >= DosDriveManager.MaxDriveCount || !_dosDriveManager.HasDriveAtIndex(State.AL)) {
2525
State.AX = 0x8002;
26-
State.CarryFlag = true;
26+
SetCarryFlag(true, true);
2727
} else {
28-
State.CarryFlag = false;
28+
SetCarryFlag(false, true);
2929
State.AX = 0;
3030
}
3131
}

src/Spice86.Core/Emulator/InterruptHandlers/Dos/DosInt21Handler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ private void GetLeadByteTable() {
456456
State.DS = segment;
457457
State.SI = offset;
458458
State.AL = 0;
459-
State.CarryFlag = false;
459+
SetCarryFlag(false, true);
460460

461461
if (LoggerService.IsEnabled(LogEventLevel.Verbose)) {
462462
LoggerService.Verbose("Returning DBCS table pointer at {Segment:X4}:{Offset:X4}", segment, offset);

src/Spice86.Core/Emulator/InterruptHandlers/SystemClock/SystemClockInt1AHandler.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,20 @@ private void ReadTimeFromRTC() {
9595
State.CL = BcdConverter.ToBcd((byte)now.Minute);
9696
State.DH = BcdConverter.ToBcd((byte)now.Second);
9797
State.DL = 0; // Standard time (not daylight savings)
98-
State.CarryFlag = false;
98+
SetCarryFlag(false, true);
9999
}
100100

101101
/// <summary>
102102
/// INT 1A, AH=03h - Set RTC Time.
103-
/// Returns error as modifying the host system time is not permitted for security and consistency reasons.
104-
/// Programs should not rely on being able to set the system time in an emulated environment.
103+
/// The requested time is silently ignored as modifying the host system time is not permitted.
104+
/// Returns CF=0 (success) to match real BIOS behavior, where writes to a read-only RTC succeed
105+
/// but have no effect, ensuring DOS programs that check CF do not treat this as an error.
105106
/// </summary>
106107
private void SetRTCTime() {
107108
if (LoggerService.IsEnabled(LogEventLevel.Verbose)) {
108-
LoggerService.Verbose("INT 1A, AH=03h - Set RTC Time (not permitted, returning error)");
109+
LoggerService.Verbose("INT 1A, AH=03h - Set RTC Time (ignored, host time is read-only)");
109110
}
110-
State.CarryFlag = true;
111+
SetCarryFlag(false, true);
111112
}
112113

113114
/// <summary>
@@ -124,18 +125,19 @@ private void ReadDateFromRTC() {
124125
State.CL = BcdConverter.ToBcd((byte)(now.Year % 100));
125126
State.DH = BcdConverter.ToBcd((byte)now.Month);
126127
State.DL = BcdConverter.ToBcd((byte)now.Day);
127-
State.CarryFlag = false;
128+
SetCarryFlag(false, true);
128129
}
129130

130131
/// <summary>
131132
/// INT 1A, AH=05h - Set RTC Date.
132-
/// Returns error as modifying the host system date is not permitted for security and consistency reasons.
133-
/// Programs should not rely on being able to set the system date in an emulated environment.
133+
/// The requested date is silently ignored as modifying the host system date is not permitted.
134+
/// Returns CF=0 (success) to match real BIOS behavior, where writes to a read-only RTC succeed
135+
/// but have no effect, ensuring DOS programs that check CF do not treat this as an error.
134136
/// </summary>
135137
private void SetRTCDate() {
136138
if (LoggerService.IsEnabled(LogEventLevel.Verbose)) {
137-
LoggerService.Verbose("INT 1A, AH=05h - Set RTC Date (not permitted, returning error)");
139+
LoggerService.Verbose("INT 1A, AH=05h - Set RTC Date (ignored, host date is read-only)");
138140
}
139-
State.CarryFlag = true;
141+
SetCarryFlag(false, true);
140142
}
141143
}

0 commit comments

Comments
 (0)