summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nandgame/instruction_decode_tb.sv310
1 files changed, 309 insertions, 1 deletions
diff --git a/nandgame/instruction_decode_tb.sv b/nandgame/instruction_decode_tb.sv
index b272f13..02919bf 100644
--- a/nandgame/instruction_decode_tb.sv
+++ b/nandgame/instruction_decode_tb.sv
@@ -33,11 +33,12 @@ end
initial begin
#1
+
+ // LDI 0
tst_instruction = 0;
tst_data_A = 0;
tst_data_D = 0;
tst_data_pA = 0;
-
#1
`TB_CHECK(tst_result, 0);
`TB_CHECK(tst_destination_A, 1);
@@ -45,6 +46,313 @@ initial begin
`TB_CHECK(tst_destination_pA, 0);
`TB_CHECK(tst_should_jump, 0);
#1
+
+ // LDI ff
+ tst_instruction = 'hff;
+ tst_data_A = 0;
+ tst_data_D = 0;
+ tst_data_pA = 0;
+ #1
+ `TB_CHECK(tst_result, 'hff);
+ `TB_CHECK(tst_destination_A, 1);
+ `TB_CHECK(tst_destination_D, 0);
+ `TB_CHECK(tst_destination_pA, 0);
+ `TB_CHECK(tst_should_jump, 0);
+ #1
+
+ // Unless otherwise specified,
+ // X=D
+ // Y=A
+
+ // (nodest) = D & A
+ tst_instruction = 'h8000;
+ tst_data_A = 0;
+ tst_data_D = 0;
+ tst_data_pA = 0;
+ #1
+ `TB_CHECK(tst_result, 'h00);
+ `TB_CHECK(tst_destination_A, 0);
+ `TB_CHECK(tst_destination_D, 0);
+ `TB_CHECK(tst_destination_pA, 0);
+ `TB_CHECK(tst_should_jump, 0);
+ #1
+
+ // A = D & A
+ tst_instruction = 'h8020;
+ tst_data_A = 0;
+ tst_data_D = 0;
+ tst_data_pA = 0;
+ #1
+ `TB_CHECK(tst_result, 'h0);
+ `TB_CHECK(tst_destination_A, 1);
+ `TB_CHECK(tst_destination_D, 0);
+ `TB_CHECK(tst_destination_pA, 0);
+ `TB_CHECK(tst_should_jump, 0);
+ #1
+
+ // D = D & A
+ tst_instruction = 'h8010;
+ tst_data_A = 0;
+ tst_data_D = 0;
+ tst_data_pA = 0;
+ #1
+ `TB_CHECK(tst_result, 'h0);
+ `TB_CHECK(tst_destination_A, 0);
+ `TB_CHECK(tst_destination_D, 1);
+ `TB_CHECK(tst_destination_pA, 0);
+ `TB_CHECK(tst_should_jump, 0);
+ #1
+
+ // M = D & A
+ tst_instruction = 'h8008;
+ tst_data_A = 0;
+ tst_data_D = 0;
+ tst_data_pA = 0;
+ #1
+ `TB_CHECK(tst_result, 'h0);
+ `TB_CHECK(tst_destination_A, 0);
+ `TB_CHECK(tst_destination_D, 0);
+ `TB_CHECK(tst_destination_pA, 1);
+ `TB_CHECK(tst_should_jump, 0);
+ #1
+
+ // (result) = D & A
+ tst_instruction = 'h8000;
+ tst_data_A = 'b1100;
+ tst_data_D = 'b1010;
+ tst_data_pA = 0;
+ #1
+ `TB_CHECK(tst_result, 'b1000);
+ `TB_CHECK(tst_destination_A, 0);
+ `TB_CHECK(tst_destination_D, 0);
+ `TB_CHECK(tst_destination_pA, 0);
+ `TB_CHECK(tst_should_jump, 0);
+ #1
+
+ // (result) = D | A
+ tst_instruction = 'h8100;
+ tst_data_A = 'b1100;
+ tst_data_D = 'b1010;
+ tst_data_pA = 0;
+ #1
+ `TB_CHECK(tst_result, 'b1110);
+ `TB_CHECK(tst_destination_A, 0);
+ `TB_CHECK(tst_destination_D, 0);
+ `TB_CHECK(tst_destination_pA, 0);
+ `TB_CHECK(tst_should_jump, 0);
+ #1
+
+ // (result) = A ^ D
+ tst_instruction = 'h8200;
+ tst_data_A = 'b1100;
+ tst_data_D = 'b1010;
+ tst_data_pA = 0;
+ #1
+ `TB_CHECK(tst_result, 'b0110);
+ `TB_CHECK(tst_destination_A, 0);
+ `TB_CHECK(tst_destination_D, 0);
+ `TB_CHECK(tst_destination_pA, 0);
+ `TB_CHECK(tst_should_jump, 0);
+ #1
+
+ // (result) = ~D
+ tst_instruction = 'h8300;
+ tst_data_A = 'b1010;
+ tst_data_D = 'haaaa;
+ tst_data_pA = 0;
+ #1
+ `TB_CHECK(tst_result, 'h5555);
+ `TB_CHECK(tst_destination_A, 0);
+ `TB_CHECK(tst_destination_D, 0);
+ `TB_CHECK(tst_destination_pA, 0);
+ `TB_CHECK(tst_should_jump, 0);
+ #1
+
+ // (result) = D + A
+ tst_instruction = 'h8400;
+ tst_data_A = 2;
+ tst_data_D = 3;
+ tst_data_pA = 0;
+ #1
+ `TB_CHECK(tst_result, 5);
+ `TB_CHECK(tst_destination_A, 0);
+ `TB_CHECK(tst_destination_D, 0);
+ `TB_CHECK(tst_destination_pA, 0);
+ `TB_CHECK(tst_should_jump, 0);
+ #1
+
+ // (result) = D + 1
+ tst_instruction = 'h8500;
+ tst_data_A = 5;
+ tst_data_D = 7;
+ tst_data_pA = 0;
+ #1
+ `TB_CHECK(tst_result, 8);
+ `TB_CHECK(tst_destination_A, 0);
+ `TB_CHECK(tst_destination_D, 0);
+ `TB_CHECK(tst_destination_pA, 0);
+ `TB_CHECK(tst_should_jump, 0);
+ #1
+
+ // (result) = D - A
+ tst_instruction = 'h8600;
+ tst_data_A = 7;
+ tst_data_D = 13;
+ tst_data_pA = 0;
+ #1
+ `TB_CHECK(tst_result, 6);
+ `TB_CHECK(tst_destination_A, 0);
+ `TB_CHECK(tst_destination_D, 0);
+ `TB_CHECK(tst_destination_pA, 0);
+ `TB_CHECK(tst_should_jump, 0);
+ #1
+
+ // (result) = D - 1
+ tst_instruction = 'h8700;
+ tst_data_A = 5;
+ tst_data_D = 7;
+ tst_data_pA = 0;
+ #1
+ `TB_CHECK(tst_result, 6);
+ `TB_CHECK(tst_destination_A, 0);
+ `TB_CHECK(tst_destination_D, 0);
+ `TB_CHECK(tst_destination_pA, 0);
+ `TB_CHECK(tst_should_jump, 0);
+ #1
+
+ // bit 12: M
+ // (result) = D & M
+ tst_instruction = 'h9000;
+ tst_data_A = 0;
+ tst_data_D = 'b1010;
+ tst_data_pA = 'b1100;
+ #1
+ `TB_CHECK(tst_result, 'b1000);
+ `TB_CHECK(tst_destination_A, 0);
+ `TB_CHECK(tst_destination_D, 0);
+ `TB_CHECK(tst_destination_pA, 0);
+ `TB_CHECK(tst_should_jump, 0);
+ #1
+
+ // bit 7: zx
+ // (result) = 0 + A
+ tst_instruction = 'h8480;
+ tst_data_A = 2;
+ tst_data_D = 3;
+ tst_data_pA = 0;
+ #1
+ `TB_CHECK(tst_result, 2);
+ `TB_CHECK(tst_destination_A, 0);
+ `TB_CHECK(tst_destination_D, 0);
+ `TB_CHECK(tst_destination_pA, 0);
+ `TB_CHECK(tst_should_jump, 0);
+ #1
+
+ // bit 6: sw
+ // (result) = A - D
+ tst_instruction = 'h8640;
+ tst_data_A = 13;
+ tst_data_D = 7;
+ tst_data_pA = 0;
+ #1
+ `TB_CHECK(tst_result, 6);
+ `TB_CHECK(tst_destination_A, 0);
+ `TB_CHECK(tst_destination_D, 0);
+ `TB_CHECK(tst_destination_pA, 0);
+ `TB_CHECK(tst_should_jump, 0);
+ #1
+
+ // bit 6+7: sw+zx
+ // (result) = 0 - D
+ tst_instruction = 'h86c0;
+ tst_data_A = 13;
+ tst_data_D = 7;
+ tst_data_pA = 0;
+ #1
+ `TB_CHECK(tst_result, 16'(-7));
+ `TB_CHECK(tst_destination_A, 0);
+ `TB_CHECK(tst_destination_D, 0);
+ `TB_CHECK(tst_destination_pA, 0);
+ `TB_CHECK(tst_should_jump, 0);
+ #1
+
+ // bit2(jl), bit1(je), bit0(jg)
+
+ // --zero
+ // (result) = D(0) + A(0), jl
+ tst_instruction = 'h8404;
+ tst_data_A = 0;
+ tst_data_D = 0;
+ #1
+ `TB_CHECK(tst_should_jump, 0);
+ #1
+
+ // (result) = D(0) + A(0), je
+ tst_instruction = 'h8402;
+ tst_data_A = 0;
+ tst_data_D = 0;
+ #1
+ `TB_CHECK(tst_should_jump, 1);
+ #1
+
+ // (result) = D(0) + A(0), jg
+ tst_instruction = 'h8401;
+ tst_data_A = 0;
+ tst_data_D = 0;
+ #1
+ `TB_CHECK(tst_should_jump, 0);
+ #1
+
+ // -- >0
+ // (result) = D(0) + A(0), jl
+ tst_instruction = 'h8404;
+ tst_data_A = 1;
+ tst_data_D = 0;
+ #1
+ `TB_CHECK(tst_should_jump, 0);
+ #1
+
+ // (result) = D(0) + A(0), je
+ tst_instruction = 'h8402;
+ tst_data_A = 1;
+ tst_data_D = 0;
+ #1
+ `TB_CHECK(tst_should_jump, 0);
+ #1
+
+ // (result) = D(0) + A(0), jg
+ tst_instruction = 'h8401;
+ tst_data_A = 1;
+ tst_data_D = 0;
+ #1
+ `TB_CHECK(tst_should_jump, 1);
+ #1
+
+ // -- <0
+ // (result) = D(0) + A(0), jl
+ tst_instruction = 'h8404;
+ tst_data_A = -1;
+ tst_data_D = 0;
+ #1
+ `TB_CHECK(tst_should_jump, 1);
+ #1
+
+ // (result) = D(0) + A(0), je
+ tst_instruction = 'h8402;
+ tst_data_A = -1;
+ tst_data_D = 0;
+ #1
+ `TB_CHECK(tst_should_jump, 0);
+ #1
+
+ // (result) = D(0) + A(0), jg
+ tst_instruction = 'h8401;
+ tst_data_A = -1;
+ tst_data_D = 0;
+ #1
+ `TB_CHECK(tst_should_jump, 0);
+ #1
+
$finish();
end