Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add back Interrupt handler generation for overridden code. Without this, any interrupt fails because handler cannot be found. #565

Merged
merged 1 commit into from
Jan 23, 2024
Merged
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
19 changes: 19 additions & 0 deletions src/Spice86.Core/Emulator/ReverseEngineer/CSharpOverrideHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,25 @@ public void CheckExternalEvents(ushort expectedReturnCs, ushort expectedReturnIp
public void Interrupt(byte vectorNumber) {
Machine.CallbackHandler.RunFromOverriden(vectorNumber);
}

/// <summary>
/// Defines C# functions for provided interrupt handlers so that when overriden code generates an interrupt, an override for it is found and executed.
/// Does not currently handle mouse code which has more than a callback + iret.
/// </summary>
public void SetProvidedInterruptHandlersAsOverridden() {
InterruptVectorTable ivt = new InterruptVectorTable(Memory);
for (byte i = 0; i < 0xFF; i++) {
SegmentedAddress handlerAddress = ivt[i];
if (handlerAddress.Segment == 0 && handlerAddress.Offset == 0) {
continue;
}
int callback = i;
DefineFunction(handlerAddress.Segment, handlerAddress.Offset, (offset) => {
Machine.CallbackHandler.RunFromOverriden(callback);
return InterruptRet();
}, false, $"provided_interrupt_handler_{ConvertUtils.ToHex(i)}");
}
}

/// <summary>
/// Halt the program.
Expand Down
Loading