|
|
@ -1,5 +1,4 @@
|
|
|
|
with Ada.Sequential_IO;
|
|
|
|
with Ada.Sequential_IO;
|
|
|
|
with Ada.Text_IO;
|
|
|
|
|
|
|
|
with Bit_Ops;
|
|
|
|
with Bit_Ops;
|
|
|
|
|
|
|
|
|
|
|
|
package body CPU is
|
|
|
|
package body CPU is
|
|
|
@ -52,47 +51,32 @@ package body CPU is
|
|
|
|
end Skip;
|
|
|
|
end Skip;
|
|
|
|
|
|
|
|
|
|
|
|
procedure Math (Inst : in out Instance; VX, VY : Register_Index; N : Byte)
|
|
|
|
procedure Math (Inst : in out Instance; VX, VY : Register_Index; N : Byte)
|
|
|
|
is begin
|
|
|
|
is
|
|
|
|
case N is
|
|
|
|
|
|
|
|
when 0 =>
|
|
|
|
|
|
|
|
Inst.Registers (VX) := Inst.Registers (VY);
|
|
|
|
|
|
|
|
when 1 =>
|
|
|
|
|
|
|
|
Inst.Registers (VX) := Bit_Ops.Bitwise_Or
|
|
|
|
|
|
|
|
(Inst.Registers (VX), Inst.Registers (VY));
|
|
|
|
|
|
|
|
when 2 =>
|
|
|
|
|
|
|
|
Inst.Registers (VX) := Bit_Ops.Bitwise_And
|
|
|
|
|
|
|
|
(Inst.Registers (VX), Inst.Registers (VY));
|
|
|
|
|
|
|
|
when 3 =>
|
|
|
|
|
|
|
|
Inst.Registers (VX) := Bit_Ops.Bitwise_Xor
|
|
|
|
|
|
|
|
(Inst.Registers (VX), Inst.Registers (VY));
|
|
|
|
|
|
|
|
when 4 =>
|
|
|
|
|
|
|
|
declare
|
|
|
|
|
|
|
|
X : constant Byte := Inst.Registers (VX);
|
|
|
|
X : constant Byte := Inst.Registers (VX);
|
|
|
|
Y : constant Byte := Inst.Registers (VY);
|
|
|
|
Y : constant Byte := Inst.Registers (VY);
|
|
|
|
begin
|
|
|
|
begin
|
|
|
|
|
|
|
|
case Math_Class'Enum_Val (N) is
|
|
|
|
|
|
|
|
when Assign => Inst.Registers (VX) := Y;
|
|
|
|
|
|
|
|
when Bit_Or => Inst.Registers (VX) := Bit_Ops.Bitwise_Or (X, Y);
|
|
|
|
|
|
|
|
when Bit_And => Inst.Registers (VX) := Bit_Ops.Bitwise_And (X, Y);
|
|
|
|
|
|
|
|
when Bit_Xor => Inst.Registers (VX) := Bit_Ops.Bitwise_Xor (X, Y);
|
|
|
|
|
|
|
|
when Add =>
|
|
|
|
Inst.Registers (VX) := X + Y;
|
|
|
|
Inst.Registers (VX) := X + Y;
|
|
|
|
Inst.Registers (15) :=
|
|
|
|
Inst.Registers (15) :=
|
|
|
|
(if Integer (X) + Integer (Y) > Integer (X + Y)
|
|
|
|
(if Integer (X) + Integer (Y) > Integer (X + Y)
|
|
|
|
then 1 else 0);
|
|
|
|
then 1 else 0);
|
|
|
|
end;
|
|
|
|
when Sub_Y =>
|
|
|
|
when 5 =>
|
|
|
|
|
|
|
|
declare
|
|
|
|
|
|
|
|
X : constant Byte := Inst.Registers (VX);
|
|
|
|
|
|
|
|
Y : constant Byte := Inst.Registers (VY);
|
|
|
|
|
|
|
|
begin
|
|
|
|
|
|
|
|
Inst.Registers (VX) := X - Y;
|
|
|
|
Inst.Registers (VX) := X - Y;
|
|
|
|
Inst.Registers (15) := (if X >= Y then 1 else 0);
|
|
|
|
Inst.Registers (15) := (if X >= Y then 1 else 0);
|
|
|
|
end;
|
|
|
|
when Shift_Right =>
|
|
|
|
when 6 =>
|
|
|
|
Inst.Registers (15) := X mod 2;
|
|
|
|
Inst.Registers (15) := Inst.Registers (VX) mod 2;
|
|
|
|
Inst.Registers (VX) := X / 2;
|
|
|
|
Inst.Registers (VX) := Inst.Registers (VX) / 2;
|
|
|
|
when Sub_X =>
|
|
|
|
when 14 =>
|
|
|
|
Inst.Registers (VX) := Y - X;
|
|
|
|
Inst.Registers (15) := Inst.Registers (VX) / (2 ** 7);
|
|
|
|
Inst.Registers (15) := (if Y >= X then 1 else 0);
|
|
|
|
Inst.Registers (VX) := Inst.Registers (VX) * 2;
|
|
|
|
when Shift_Left =>
|
|
|
|
when others => begin
|
|
|
|
Inst.Registers (15) := X / (2 ** 7);
|
|
|
|
Ada.Text_IO.Put_Line ("Uh oh!");
|
|
|
|
Inst.Registers (VX) := X * 2;
|
|
|
|
Ada.Text_IO.Put_Line (Byte'Image (N));
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
end case;
|
|
|
|
end case;
|
|
|
|
end Math;
|
|
|
|
end Math;
|
|
|
|
|
|
|
|
|
|
|
|