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 Bios INT 12h to report installed memory size. #562

Merged
merged 2 commits into from
Jan 23, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace Spice86.Core.Emulator.InterruptHandlers.Bios;

using Spice86.Core.Emulator.CPU;
using Spice86.Core.Emulator.Memory;
using Spice86.Shared.Interfaces;

/// <summary>
/// INT 12h handler. Reports how many kb of base memory is installed.
/// </summary>
public class SystemBiosInt12Handler : InterruptHandler {
private readonly BiosDataArea _biosDataArea;

/// <summary>
/// Initializes a new instance.
/// </summary>
/// <param name="memory"></param>
/// <param name="cpu"></param>
/// <param name="biosDataArea"></param>
/// <param name="loggerService"></param>
public SystemBiosInt12Handler(IMemory memory, Cpu cpu, BiosDataArea biosDataArea, ILoggerService loggerService) : base(memory, cpu, loggerService) {
_biosDataArea = biosDataArea;
}

/// <inheritdoc />
public override byte VectorNumber => 0x12;

/// <inheritdoc />
public override void Run() {
_state.AX = _biosDataArea.ConventionalMemorySizeKb;
}
}
5 changes: 4 additions & 1 deletion src/Spice86.Core/Emulator/Memory/BiosDataArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ public BiosDataArea(IByteReaderWriter byteReaderWriter) : base(byteReaderWriter,

// Padding at 0x12

public ushort MemSizeKb { get => UInt16[0x13]; set => UInt16[0x13] = value; }
/// <summary>
/// Gets or sets the amount of installed conventional memory in KB.
/// </summary>
public ushort ConventionalMemorySizeKb { get => UInt16[0x13]; init => UInt16[0x13] = value; }

// Padding at 0x15

Expand Down
11 changes: 10 additions & 1 deletion src/Spice86.Core/Emulator/VM/Machine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ public sealed class Machine : IDisposable, IDebuggableComponent {
/// </summary>
public SoundBlaster SoundBlaster { get; }

/// <summary>
/// INT12H handler.
/// </summary>
public SystemBiosInt12Handler SystemBiosInt12Handler { get; }

/// <summary>
/// INT15H handler.
/// </summary>
Expand Down Expand Up @@ -200,7 +205,9 @@ public Machine(IGui? gui, State cpuState, IOPortDispatcher ioPortDispatcher, ILo
Memory.UInt16[0xF000, 0xFFF0] = 0xF4;
}
IoPortDispatcher = ioPortDispatcher;
BiosDataArea = new BiosDataArea(Memory);
BiosDataArea = new BiosDataArea(Memory) {
ConventionalMemorySizeKb = (ushort)Math.Clamp(Memory.Ram.Size / 1024, 0, 640) // max 640k conventional memory
};
CpuState = cpuState;
DualPic = new(CpuState, configuration.FailOnUnhandledPort, configuration.InitializeDOS is false, loggerService);
// Breakpoints
Expand Down Expand Up @@ -265,6 +272,7 @@ public Machine(IGui? gui, State cpuState, IOPortDispatcher ioPortDispatcher, ILo
BiosKeyboardInt9Handler = new BiosKeyboardInt9Handler(Memory, Cpu, DualPic, Keyboard, BiosDataArea, loggerService);

BiosEquipmentDeterminationInt11Handler = new BiosEquipmentDeterminationInt11Handler(Memory, Cpu, loggerService);
SystemBiosInt12Handler = new SystemBiosInt12Handler(Memory, Cpu, BiosDataArea, loggerService);
SystemBiosInt15Handler = new SystemBiosInt15Handler(Memory, Cpu, Memory.A20Gate, loggerService);
KeyboardInt16Handler = new KeyboardInt16Handler(Memory, Cpu, loggerService, BiosKeyboardInt9Handler.BiosKeyboardBuffer);

Expand All @@ -279,6 +287,7 @@ public Machine(IGui? gui, State cpuState, IOPortDispatcher ioPortDispatcher, ILo
RegisterInterruptHandler(TimerInt8Handler);
RegisterInterruptHandler(BiosKeyboardInt9Handler);
RegisterInterruptHandler(BiosEquipmentDeterminationInt11Handler);
RegisterInterruptHandler(SystemBiosInt12Handler);
RegisterInterruptHandler(SystemBiosInt15Handler);
RegisterInterruptHandler(KeyboardInt16Handler);
RegisterInterruptHandler(SystemClockInt1AHandler);
Expand Down
Loading