Skip to content

Commit

Permalink
Merge pull request #614 from mbbsemu/skpwrd-fix
Browse files Browse the repository at this point in the history
Fix for SKPWRD
  • Loading branch information
paladine authored Dec 30, 2023
2 parents a2eedf8 + 27459d0 commit 3628d9e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
8 changes: 5 additions & 3 deletions MBBSEmu.Tests/ExportedModules/ExportedModuleTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ namespace MBBSEmu.Tests.ExportedModules
{
public abstract class ExportedModuleTestBase : TestBase, IDisposable
{
// list of ordinals that use the __stdcall convention, which means the callee cleans up the
// stack.
// __cdecl convention has the caller cleaning up the stack.
/// <summary>
/// List of ordinals that use the __stdcall convention, which means the callee cleans up the stack.
///
/// __cdecl convention has the caller cleaning up the stack.
/// </summary>
private static readonly HashSet<ushort> STDCALL_ORDINALS = new HashSet<ushort> {
654, // f_ldiv
656, // f_ludiv
Expand Down
37 changes: 37 additions & 0 deletions MBBSEmu.Tests/ExportedModules/Majorbbs/skpwrd_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,42 @@ public void SKPWRD_Test(string inputString, string expectedString)
Encoding.ASCII.GetString(
mbbsEmuMemoryCore.GetString(mbbsEmuCpuRegisters.GetPointer())));
}

/// <summary>
/// These tests are to verify a specific scenario where the final character of the string being parsed
/// is at the last offset in a segment (0xFFFF)
/// </summary>
/// <param name="inputString"></param>
/// <param name="expectedString"></param>
[Theory]
[InlineData("TEST TEST\0", " TEST\0")]
[InlineData("TEST\0", "\0")]
[InlineData("\0", "\0")]
public void SKPWRD_Test_EndOfSegment(string inputString, string expectedString)
{
//Reset State
Reset();

//Set Argument Values to be Passed In
var stringPointer = mbbsEmuMemoryCore.AllocateVariable("INPUT_STRING", (ushort)(inputString.Length + 1));

//Ensure Input String ends in \0
if (inputString[^1] != '\0')
inputString += '\0';

//This will change the final character of the string (\0) to be at 0xFFFF
stringPointer.Offset = (ushort)(0x10000 - inputString.Length);

//Get the Segment and we'll allocate this at the end
mbbsEmuMemoryCore.SetArray(stringPointer, Encoding.ASCII.GetBytes(inputString));

//Execute Test
ExecuteApiTest(HostProcess.ExportedModules.Majorbbs.Segment, SKPWRD_ORDINAL, new List<FarPtr> { stringPointer });

//Verify Results
Assert.Equal(expectedString,
Encoding.ASCII.GetString(
mbbsEmuMemoryCore.GetString(mbbsEmuCpuRegisters.GetPointer())));
}
}
}
2 changes: 1 addition & 1 deletion MBBSEmu/HostProcess/ExportedModules/Majorbbs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7212,7 +7212,7 @@ private void skpwrd()
{
var stringPointerBase = GetParameterPointer(0);

for (var i = stringPointerBase.Offset; i < ushort.MaxValue; i++)
for (var i = stringPointerBase.Offset; i <= ushort.MaxValue; i++)
{
var currentCharacter = Module.Memory.GetByte(stringPointerBase.Segment, i);
if (currentCharacter != 0 && currentCharacter != ' ') continue;
Expand Down

0 comments on commit 3628d9e

Please sign in to comment.