Add more tests, fix division and modulus
All checks were successful
Test / build (push) Successful in 12s
All checks were successful
Test / build (push) Successful in 12s
This commit is contained in:
parent
060ca1d3cd
commit
f3773fc82b
@ -27,6 +27,7 @@ uint16_t& Device::memory(uint16_t index)
|
|||||||
Emulator::Emulator() :
|
Emulator::Emulator() :
|
||||||
memory{},
|
memory{},
|
||||||
registers{},
|
registers{},
|
||||||
|
configuration(0),
|
||||||
mapped_base(0)
|
mapped_base(0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@ -349,7 +350,8 @@ void Emulator::DIVI()
|
|||||||
uint16_t b = decode_operand((instruction & 0x0000FF00) >> 8);
|
uint16_t b = decode_operand((instruction & 0x0000FF00) >> 8);
|
||||||
uint16_t& d = decode_operand((instruction & 0x00FF0000) >> 16);
|
uint16_t& d = decode_operand((instruction & 0x00FF0000) >> 16);
|
||||||
|
|
||||||
d = uint32_t((int32_t(a) >> shift()) / int32_t(b));
|
// convert from unsigned to signed, then widen
|
||||||
|
d = uint32_t((int32_t(int16_t(a)) << shift()) / int32_t(int16_t(b)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Emulator::MODU()
|
void Emulator::MODU()
|
||||||
@ -358,7 +360,7 @@ void Emulator::MODU()
|
|||||||
uint16_t b = decode_operand((instruction & 0x0000FF00) >> 8);
|
uint16_t b = decode_operand((instruction & 0x0000FF00) >> 8);
|
||||||
uint16_t& d = decode_operand((instruction & 0x00FF0000) >> 16);
|
uint16_t& d = decode_operand((instruction & 0x00FF0000) >> 16);
|
||||||
|
|
||||||
d = uint32_t((int32_t(a) >> shift()) / int32_t(b));
|
d = int16_t(a) % int16_t(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Emulator::repeats()
|
bool Emulator::repeats()
|
||||||
|
@ -17,3 +17,9 @@ test(band-instruction)
|
|||||||
test(bxor-instruction)
|
test(bxor-instruction)
|
||||||
test(srsh-instruction)
|
test(srsh-instruction)
|
||||||
test(zlsh-instruction)
|
test(zlsh-instruction)
|
||||||
|
test(clsh-instruction)
|
||||||
|
test(addi-instruction)
|
||||||
|
test(subt-instruction)
|
||||||
|
test(mult-instruction)
|
||||||
|
test(divi-instruction)
|
||||||
|
test(modu-instruction)
|
||||||
|
36
emulator/tests/addi-instruction.cpp
Normal file
36
emulator/tests/addi-instruction.cpp
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#include "test-common.h"
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
// CNST
|
||||||
|
// dst - 0, Direct
|
||||||
|
// imm - 0x4567
|
||||||
|
//
|
||||||
|
// ADDI
|
||||||
|
// dst - 0, Direct
|
||||||
|
// a - 0, Direct
|
||||||
|
// b - 2, Immediate
|
||||||
|
{
|
||||||
|
foot::Emulator emu = run_instructions({ 0x00204567, 0x09200220 });
|
||||||
|
if (!check(0x4569, emu.register_at(0))) { return 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// CNST
|
||||||
|
// dst - 0, Direct
|
||||||
|
// imm - 0x4567
|
||||||
|
//
|
||||||
|
// CNST
|
||||||
|
// dst - 1, Direct
|
||||||
|
// imm = 0xFFFE (-2)
|
||||||
|
//
|
||||||
|
// ADDI
|
||||||
|
// dst - 0, Direct
|
||||||
|
// a - 0, Direct
|
||||||
|
// b - 1, Direct
|
||||||
|
{
|
||||||
|
foot::Emulator emu = run_instructions({ 0x00204567, 0x0021FFFE, 0x09202120 });
|
||||||
|
if (!check(0x4565, emu.register_at(0))) { return 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
19
emulator/tests/clsh-instruction.cpp
Normal file
19
emulator/tests/clsh-instruction.cpp
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#include "test-common.h"
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
// CNST
|
||||||
|
// dst - 0, Direct
|
||||||
|
// imm - 0x4567
|
||||||
|
//
|
||||||
|
// CLSH
|
||||||
|
// dst - 0, Direct
|
||||||
|
// a - 0, Direct
|
||||||
|
// b - 2, Immediate
|
||||||
|
{
|
||||||
|
foot::Emulator emu = run_instructions({ 0x00204567, 0x08200220 });
|
||||||
|
if (!check(0x159D, emu.register_at(0))) { return 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
75
emulator/tests/divi-instruction.cpp
Normal file
75
emulator/tests/divi-instruction.cpp
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
#include "test-common.h"
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
// CNST
|
||||||
|
// dst - 0, Direct
|
||||||
|
// imm - 0x0005
|
||||||
|
//
|
||||||
|
// DIVI
|
||||||
|
// dst - 0, Direct
|
||||||
|
// a - 0, Direct
|
||||||
|
// b - 2, Immediate
|
||||||
|
{
|
||||||
|
foot::Emulator emu = run_instructions({ 0x00200005, 0x0E200220 });
|
||||||
|
if (!check(0x0002, emu.register_at(0))) { return 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// CNST
|
||||||
|
// dst - 0, Direct
|
||||||
|
// imm - 0x0007
|
||||||
|
//
|
||||||
|
// CNST
|
||||||
|
// dst - 1, Direct
|
||||||
|
// imm = 0xFFF9 (-7)
|
||||||
|
//
|
||||||
|
// DIVI
|
||||||
|
// dst - 0, Direct
|
||||||
|
// a - 0, Direct
|
||||||
|
// b - 1, Direct
|
||||||
|
{
|
||||||
|
foot::Emulator emu = run_instructions({ 0x00200007, 0x0021FFF9, 0x0E202120 });
|
||||||
|
if (!check(0xFFFF, emu.register_at(0))) { return 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// CNST
|
||||||
|
// dst - 0, Direct
|
||||||
|
// imm - 0xFFF9 (-7)
|
||||||
|
//
|
||||||
|
// CNST
|
||||||
|
// dst - 1, Direct
|
||||||
|
// imm = 0xFFF9 (-7)
|
||||||
|
//
|
||||||
|
// DIVI
|
||||||
|
// dst - 0, Direct
|
||||||
|
// a - 0, Direct
|
||||||
|
// b - 1, Direct
|
||||||
|
{
|
||||||
|
foot::Emulator emu = run_instructions({ 0x0020FFF9, 0x0021FFF9, 0x0E202120 });
|
||||||
|
if (!check(0x1, emu.register_at(0))) { return 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// CNST
|
||||||
|
// dst - 0, Direct
|
||||||
|
// imm - 0x0002 (1)
|
||||||
|
//
|
||||||
|
// CNST
|
||||||
|
// dst - 1, Direct
|
||||||
|
// imm = 0x0001 (0.5)
|
||||||
|
//
|
||||||
|
// CONF
|
||||||
|
// dst - X, Immediate
|
||||||
|
// a - 1, Immediate
|
||||||
|
//
|
||||||
|
// MULT
|
||||||
|
// dst - 0, Direct
|
||||||
|
// a - 0, Direct
|
||||||
|
// b - 1, Direct
|
||||||
|
{
|
||||||
|
foot::Emulator emu = run_instructions({ 0x00200002, 0x00210001, 0x01000401, 0x0E202120 });
|
||||||
|
// 0x4 (2)
|
||||||
|
if (!check(0x4, emu.register_at(0))) { return 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
75
emulator/tests/modu-instruction.cpp
Normal file
75
emulator/tests/modu-instruction.cpp
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
#include "test-common.h"
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
// CNST
|
||||||
|
// dst - 0, Direct
|
||||||
|
// imm - 0x0005
|
||||||
|
//
|
||||||
|
// DIVI
|
||||||
|
// dst - 0, Direct
|
||||||
|
// a - 0, Direct
|
||||||
|
// b - 2, Immediate
|
||||||
|
{
|
||||||
|
foot::Emulator emu = run_instructions({ 0x00200005, 0x0F200220 });
|
||||||
|
if (!check(0x1, emu.register_at(0))) { return 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// CNST
|
||||||
|
// dst - 0, Direct
|
||||||
|
// imm - 0x0005
|
||||||
|
//
|
||||||
|
// CNST
|
||||||
|
// dst - 1, Direct
|
||||||
|
// imm = 0xFFFE (-2)
|
||||||
|
//
|
||||||
|
// DIVI
|
||||||
|
// dst - 0, Direct
|
||||||
|
// a - 0, Direct
|
||||||
|
// b - 1, Direct
|
||||||
|
{
|
||||||
|
foot::Emulator emu = run_instructions({ 0x00200005, 0x0021FFFE, 0x0F202120 });
|
||||||
|
if (!check(0x1, emu.register_at(0))) { return 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// CNST
|
||||||
|
// dst - 0, Direct
|
||||||
|
// imm - 0xFFFE (-2)
|
||||||
|
//
|
||||||
|
// CNST
|
||||||
|
// dst - 1, Direct
|
||||||
|
// imm = 0x0005
|
||||||
|
//
|
||||||
|
// DIVI
|
||||||
|
// dst - 0, Direct
|
||||||
|
// a - 0, Direct
|
||||||
|
// b - 1, Direct
|
||||||
|
{
|
||||||
|
foot::Emulator emu = run_instructions({ 0x0020FFFE, 0x00210005, 0x0F202120 });
|
||||||
|
if (!check(0xFFFE, emu.register_at(0))) { return 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// CNST
|
||||||
|
// dst - 0, Direct
|
||||||
|
// imm - 0x0005 (2.5)
|
||||||
|
//
|
||||||
|
// CNST
|
||||||
|
// dst - 1, Direct
|
||||||
|
// imm = 0x0003 (1.5)
|
||||||
|
//
|
||||||
|
// CONF
|
||||||
|
// dst - X, Immediate
|
||||||
|
// a - 1, Immediate
|
||||||
|
//
|
||||||
|
// MULT
|
||||||
|
// dst - 0, Direct
|
||||||
|
// a - 0, Direct
|
||||||
|
// b - 1, Direct
|
||||||
|
{
|
||||||
|
foot::Emulator emu = run_instructions({ 0x00200005, 0x00210003, 0x01000401, 0x0F202120 });
|
||||||
|
|
||||||
|
if (!check(0x2, emu.register_at(0))) { return 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
75
emulator/tests/mult-instruction.cpp
Normal file
75
emulator/tests/mult-instruction.cpp
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
#include "test-common.h"
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
// CNST
|
||||||
|
// dst - 0, Direct
|
||||||
|
// imm - 0x0003
|
||||||
|
//
|
||||||
|
// MULT
|
||||||
|
// dst - 0, Direct
|
||||||
|
// a - 0, Direct
|
||||||
|
// b - 2, Immediate
|
||||||
|
{
|
||||||
|
foot::Emulator emu = run_instructions({ 0x00200003, 0x0B200220 });
|
||||||
|
if (!check(0x0006, emu.register_at(0))) { return 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// CNST
|
||||||
|
// dst - 0, Direct
|
||||||
|
// imm - 0x0007
|
||||||
|
//
|
||||||
|
// CNST
|
||||||
|
// dst - 1, Direct
|
||||||
|
// imm = 0xFFF9 (-7)
|
||||||
|
//
|
||||||
|
// MULT
|
||||||
|
// dst - 0, Direct
|
||||||
|
// a - 0, Direct
|
||||||
|
// b - 1, Direct
|
||||||
|
{
|
||||||
|
foot::Emulator emu = run_instructions({ 0x00200007, 0x0021FFF9, 0x0B202120 });
|
||||||
|
if (!check(0xFFCF, emu.register_at(0))) { return 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// CNST
|
||||||
|
// dst - 0, Direct
|
||||||
|
// imm - 0xFFF9 (-7)
|
||||||
|
//
|
||||||
|
// CNST
|
||||||
|
// dst - 1, Direct
|
||||||
|
// imm = 0xFFF9 (-7)
|
||||||
|
//
|
||||||
|
// MULT
|
||||||
|
// dst - 0, Direct
|
||||||
|
// a - 0, Direct
|
||||||
|
// b - 1, Direct
|
||||||
|
{
|
||||||
|
foot::Emulator emu = run_instructions({ 0x0020FFF9, 0x0021FFF9, 0x0B202120 });
|
||||||
|
if (!check(0x31, emu.register_at(0))) { return 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// CNST
|
||||||
|
// dst - 0, Direct
|
||||||
|
// imm - 0x0007 (3.5)
|
||||||
|
//
|
||||||
|
// CNST
|
||||||
|
// dst - 1, Direct
|
||||||
|
// imm = 0x0007 (3.5)
|
||||||
|
//
|
||||||
|
// CONF
|
||||||
|
// dst - X, Immediate
|
||||||
|
// a - 1, Immediate
|
||||||
|
//
|
||||||
|
// MULT
|
||||||
|
// dst - 0, Direct
|
||||||
|
// a - 0, Direct
|
||||||
|
// b - 1, Direct
|
||||||
|
{
|
||||||
|
foot::Emulator emu = run_instructions({ 0x00200007, 0x00210007, 0x01000401, 0x0B202120 });
|
||||||
|
// 0x18 (12)
|
||||||
|
if (!check(0x18, emu.register_at(0))) { return 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
36
emulator/tests/subt-instruction.cpp
Normal file
36
emulator/tests/subt-instruction.cpp
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#include "test-common.h"
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
// CNST
|
||||||
|
// dst - 0, Direct
|
||||||
|
// imm - 0x4567
|
||||||
|
//
|
||||||
|
// SUBT
|
||||||
|
// dst - 0, Direct
|
||||||
|
// a - 0, Direct
|
||||||
|
// b - 2, Immediate
|
||||||
|
{
|
||||||
|
foot::Emulator emu = run_instructions({ 0x00204567, 0x0A200220 });
|
||||||
|
if (!check(0x4565, emu.register_at(0))) { return 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// CNST
|
||||||
|
// dst - 0, Direct
|
||||||
|
// imm - 0x4567
|
||||||
|
//
|
||||||
|
// CNST
|
||||||
|
// dst - 1, Direct
|
||||||
|
// imm = 0xFFFE (-2)
|
||||||
|
//
|
||||||
|
// SUBT
|
||||||
|
// dst - 0, Direct
|
||||||
|
// a - 0, Direct
|
||||||
|
// b - 1, Direct
|
||||||
|
{
|
||||||
|
foot::Emulator emu = run_instructions({ 0x00204567, 0x0021FFFE, 0x0A202120 });
|
||||||
|
if (!check(0x4569, emu.register_at(0))) { return 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user