Skip to content

Commit

Permalink
feat: DOS INT21H 0x4B (WIP)
Browse files Browse the repository at this point in the history
Signed-off-by: Maximilien Noal <noal.maximilien@gmail.com>
  • Loading branch information
maximilien-noal committed Sep 30, 2024
1 parent 35ce75d commit 5086f67
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
35 changes: 33 additions & 2 deletions src/Spice86.Core/Emulator/InterruptHandlers/Dos/DosInt21Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -730,17 +730,48 @@ private enum TypeOfLoad : byte {
/// <returns>
/// CF is cleared on success. <br/>
/// CF is set on error.
/// TODO: This needs the DOS Swappable Area, and a lot of other DOS globals (current drive, current folder, ...)
/// </returns>
/// </summary>
/// <param name="calledFromVm">Whether the code was called by the emulator.</param>
public void LoadAndOrExecuteProgram(bool calledFromVm) {
bool success = false;
TypeOfLoad typeOfLoad = (TypeOfLoad)State.AL;
string programName = GetZeroTerminatedStringAtDsDx();
string? fullHostPath = _dosFileManager.TryGetFullHostPathFromDos(programName);

if(string.IsNullOrWhiteSpace(fullHostPath) || !File.Exists(fullHostPath)) {
SetCarryFlag(false, calledFromVm);
return;
}

if (LoggerService.IsEnabled(LogEventLevel.Verbose)) {
LoggerService.Verbose("LOAD AND/OR EXECUTE PROGRAM {TypeOfLoad}, {ProgramName}", typeOfLoad, programName);
}

bool isComFile = string.Equals(Path.GetExtension(programName).ToLowerInvariant(), ".com", StringComparison.OrdinalIgnoreCase);

switch (typeOfLoad) {
case TypeOfLoad.LoadAndExecute:
if (isComFile) {
LoadAndExecComFile(fullHostPath, "", 0x1000);
} else {
LoadAndExecExeFile(fullHostPath, "", 0x1000);
}
success = true;
break;
case TypeOfLoad.LoadOnly:
// Not implemented
success = false;
break;
case TypeOfLoad.LoadOverlay:
// Not implemented
success = false;
break;
default:
SetCarryFlag(false, calledFromVm);
return;
}
SetCarryFlag(success, calledFromVm);
}

Expand Down Expand Up @@ -1108,7 +1139,7 @@ private void SetStateFromDosFileOperationResult(bool calledFromVm, DosFileOperat

private const ushort ComOffset = 0x100;

internal void LoadEXEFile(string hostFile, string? arguments, ushort startSegment) {
internal void LoadAndExecExeFile(string hostFile, string? arguments, ushort startSegment) {
byte[] exe = File.ReadAllBytes(hostFile);
if (LoggerService.IsEnabled(LogEventLevel.Debug)) {
LoggerService.Debug("Exe size: {ExeSize}", exe.Length);
Expand Down Expand Up @@ -1186,7 +1217,7 @@ private void SetEntryPoint(ushort cs, ushort ip) {
}
}

internal void LoadCOMFile(string hostFile, string? arguments, ushort startSegment) {
internal void LoadAndExecComFile(string hostFile, string? arguments, ushort startSegment) {
new PspGenerator(Memory, _dos.EnvironmentVariables, _dosMemoryManager, _dosFileManager).GeneratePsp(startSegment, arguments);
byte[] com = File.ReadAllBytes(hostFile);
uint physicalStartAddress = MemoryUtils.ToPhysicalAddress(startSegment, ComOffset);
Expand Down
4 changes: 2 additions & 2 deletions src/Spice86.Core/Emulator/ProgramExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ public void Run() {
string fileExtension = Path.GetExtension(_configuration.Exe).ToLowerInvariant();
switch (fileExtension) {
case ".exe":
_dosInt21Handler.LoadEXEFile(_configuration.Exe, _configuration.ExeArgs, _configuration.ProgramEntryPointSegment);
_dosInt21Handler.LoadAndExecExeFile(_configuration.Exe, _configuration.ExeArgs, _configuration.ProgramEntryPointSegment);
break;
case ".com":
_dosInt21Handler.LoadCOMFile(_configuration.Exe, _configuration.ExeArgs, _configuration.ProgramEntryPointSegment);
_dosInt21Handler.LoadAndExecComFile(_configuration.Exe, _configuration.ExeArgs, _configuration.ProgramEntryPointSegment);
break;
default:
new BiosLoader(_memory, _state, _configuration.Exe, _loggerService).LoadHostFile();
Expand Down

0 comments on commit 5086f67

Please sign in to comment.