Skip to content

Commit

Permalink
Add Bios INT 12h to report installed memory size. (#562)
Browse files Browse the repository at this point in the history
* Add Bios INT 12h to report installed memory size.

* Update to clarify that INT12 only reports on the first 640k conventional memory
  • Loading branch information
JorisVanEijden authored Jan 23, 2024
1 parent 7f5114a commit de0094b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
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

0 comments on commit de0094b

Please sign in to comment.