-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #628 from mbbsemu/GE-Fixes
PHAPI, `TOKOPT`, `CHROPT` and `SAMTO` Fixes
- Loading branch information
Showing
9 changed files
with
419 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
using Iced.Intel; | ||
using Xunit; | ||
using static Iced.Intel.AssemblerRegisters; | ||
|
||
namespace MBBSEmu.Tests.CPU | ||
{ | ||
public class IMUL_Tests : CpuTestBase | ||
{ | ||
[Theory] | ||
[InlineData(127, 127, 1, 63, true, true)] | ||
[InlineData(-1, -1, 1, 0, false, false)] | ||
[InlineData(-127, -1, 127, 0, false, false)] | ||
[InlineData(-127, 2, 2, -1, true, true)] | ||
[InlineData(-127, -127, 1, 63, true, true)] | ||
[InlineData(127, -1, -127, -1, false, false)] | ||
[InlineData(5, 5, 25, 0, false, false)] | ||
public void IMUL_8_R8_Test(sbyte alValue, sbyte valueToMultiply, sbyte expectedALValue, sbyte expectedAHValue, bool carryFlag, | ||
bool overflowFlag) | ||
{ | ||
Reset(); | ||
mbbsEmuCpuRegisters.AL = (byte)alValue; | ||
mbbsEmuCpuRegisters.BL = (byte)valueToMultiply; | ||
|
||
var instructions = new Assembler(16); | ||
instructions.imul(bl); | ||
CreateCodeSegment(instructions); | ||
|
||
mbbsEmuCpuCore.Tick(); | ||
|
||
//Verify Results | ||
Assert.Equal(expectedALValue, (sbyte)mbbsEmuCpuRegisters.AL); | ||
Assert.Equal(expectedAHValue, (sbyte)mbbsEmuCpuRegisters.AH); | ||
Assert.Equal(carryFlag, mbbsEmuCpuRegisters.CarryFlag); | ||
Assert.Equal(overflowFlag, mbbsEmuCpuRegisters.OverflowFlag); | ||
} | ||
|
||
[Theory] | ||
[InlineData(32767, 1, 32767, false, false)] // Max positive * 1 | ||
[InlineData(-32768, 1, -32768, false, false)] // Max negative * 1 | ||
[InlineData(100, 100, 10000, false, false)] // Positive * Positive | ||
[InlineData(-100, -100, 10000, false, false)] // Negative * Negative | ||
[InlineData(100, -100, -10000, false, false)] // Positive * Negative | ||
[InlineData(32767, 2, -2, true, true)] // Positive overflow case | ||
[InlineData(-32768, 2, 0, true, true)] // Negative overflow case | ||
[InlineData(0, 32767, 0, false, false)] // Zero * Positive | ||
[InlineData(0, -32768, 0, false, false)] // Zero * Negative | ||
[InlineData(0, 0, 0, false, false)] // Zero * Zero | ||
public void IMUL_16_R16_Test(short axValue, short valueToMultiply, short expectedValue, bool carryFlag, | ||
bool overflowFlag) | ||
{ | ||
Reset(); | ||
mbbsEmuCpuRegisters.AX = (ushort)axValue; | ||
mbbsEmuCpuRegisters.BX = (ushort)valueToMultiply; | ||
|
||
var instructions = new Assembler(16); | ||
instructions.imul(bx); | ||
CreateCodeSegment(instructions); | ||
|
||
mbbsEmuCpuCore.Tick(); | ||
|
||
//Verify Results | ||
Assert.Equal(expectedValue, (short)mbbsEmuCpuRegisters.AX); | ||
Assert.Equal(carryFlag, mbbsEmuCpuRegisters.CarryFlag); | ||
Assert.Equal(overflowFlag, mbbsEmuCpuRegisters.OverflowFlag); | ||
} | ||
|
||
|
||
[Theory] | ||
[InlineData(1, -1, -1, false, false)] | ||
[InlineData(-1, -1, 1, false, false)] | ||
[InlineData(-127, -1, 127, false, false)] | ||
[InlineData(127, -1, -127, false, false)] | ||
[InlineData(short.MaxValue, -1, short.MinValue + 1, false, false)] | ||
[InlineData(short.MaxValue, -2, 2, true, true)] | ||
public void IMUL_16_R16_3OP_Test(short bxValue, short valueToMultiply, short expectedValue, bool carryFlag, | ||
bool overflowFlag) | ||
{ | ||
Reset(); | ||
mbbsEmuCpuRegisters.BX = (ushort)bxValue; | ||
|
||
var instructions = new Assembler(16); | ||
//AX = BX * ValueToMultiply | ||
instructions.imul(ax, bx, valueToMultiply); | ||
CreateCodeSegment(instructions); | ||
|
||
mbbsEmuCpuCore.Tick(); | ||
|
||
//Verify Results | ||
Assert.Equal(expectedValue, (short)mbbsEmuCpuRegisters.AX); | ||
Assert.Equal(carryFlag, mbbsEmuCpuRegisters.CarryFlag); | ||
Assert.Equal(overflowFlag, mbbsEmuCpuRegisters.OverflowFlag); | ||
} | ||
|
||
[Theory] | ||
[InlineData(1, -1, -1, false, false)] | ||
[InlineData(5, 10, 50, false, false)] | ||
[InlineData(-1, -1, 1, false, false)] | ||
[InlineData(-127, -1, 127, false, false)] | ||
[InlineData(127, -1, -127, false, false)] | ||
[InlineData(short.MaxValue, -1, short.MinValue + 1, false, false)] | ||
[InlineData(short.MaxValue, -2, 2, true, true)] | ||
public void IMUL_16_M16_3OP_Test(short memoryValue, short valueToMultiply, short expectedValue, bool carryFlag, | ||
bool overflowFlag) | ||
{ | ||
Reset(); | ||
|
||
//Setup Memory | ||
CreateDataSegment(new byte[ushort.MaxValue]); | ||
mbbsEmuMemoryCore.SetWord(2,0, (ushort)memoryValue); | ||
mbbsEmuCpuRegisters.DS = 2; | ||
|
||
var instructions = new Assembler(16); | ||
//AX == DS:[0] * ValueToMultiply | ||
instructions.imul(ax, __word_ptr[0], valueToMultiply); | ||
CreateCodeSegment(instructions); | ||
|
||
mbbsEmuCpuCore.Tick(); | ||
|
||
//Verify Results | ||
Assert.Equal(expectedValue, (short)mbbsEmuCpuRegisters.AX); | ||
Assert.Equal(carryFlag, mbbsEmuCpuRegisters.CarryFlag); | ||
Assert.Equal(overflowFlag, mbbsEmuCpuRegisters.OverflowFlag); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using MBBSEmu.Memory; | ||
using MBBSEmu.Module; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Xunit; | ||
|
||
namespace MBBSEmu.Tests.ExportedModules.Majorbbs | ||
{ | ||
public class tokopt_Tests : ExportedModuleTestBase | ||
{ | ||
private const int TOKPT_ORDINAL = 602; | ||
|
||
[Theory] | ||
[InlineData(new[] { "TEST1", "TEST2", "TEST3" }, "TEST", 0)] | ||
[InlineData(new[] { "TEST1", "TEST2", "TEST3" }, "TEST2", 2)] | ||
[InlineData(new[] { "TEST1", "TEST2", "TEST3" }, "Testing Multiple Words: TEST", 0)] | ||
[InlineData(new[] { "TEST1", "TEST2", "TEST3" }, "Testing Multiple Words: TEST3", 3)] | ||
public void tokopt_Test(string[] tokens, string valueToTest, ushort expectedResult) | ||
{ | ||
//Reset State | ||
Reset(); | ||
|
||
//Allocate Memory for each Token which will be passed in as params to the function | ||
var tokenPointers = new List<FarPtr>(); | ||
foreach(var token in tokens) | ||
{ | ||
var tokenPointer = | ||
mbbsEmuMemoryCore.AllocateVariable($"TOKEN{tokenPointers.Count + 1}", (ushort)(token.Length + 1)); | ||
mbbsEmuMemoryCore.SetArray(tokenPointer, Encoding.ASCII.GetBytes(token)); | ||
|
||
tokenPointers.Add(tokenPointer); | ||
} | ||
|
||
|
||
//Set Argument Values to be Passed In | ||
var mcvPointer = (ushort)majorbbs.McvPointerDictionary.Allocate(new McvFile("TEST.MCV", | ||
new Dictionary<int, byte[]> { { 0, Encoding.ASCII.GetBytes(valueToTest) } })); | ||
|
||
mbbsEmuMemoryCore.SetPointer("CURRENT-MCV", new FarPtr(0xFFFF, mcvPointer)); | ||
|
||
//Build Parameters List | ||
var parameters = new List<ushort>(); | ||
parameters.Add(0); //Ordinal of MCV Value | ||
//Add Token Pointers | ||
foreach (var tokenPointer in tokenPointers) | ||
{ | ||
parameters.Add(tokenPointer.Offset); | ||
parameters.Add(tokenPointer.Segment); | ||
} | ||
//Terminate with Null Pointer | ||
parameters.Add(0); | ||
parameters.Add(0); | ||
|
||
//Execute Test | ||
ExecuteApiTest(HostProcess.ExportedModules.Majorbbs.Segment, TOKPT_ORDINAL, parameters); | ||
|
||
//Verify Results | ||
Assert.Equal(expectedResult, mbbsEmuCpuRegisters.AX); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.