diff --git a/decstates.v b/decstates.v index a635bbf..8299d06 100644 --- a/decstates.v +++ b/decstates.v @@ -2,49 +2,55 @@ `define _DECSTATES -`define DEC_START 12'h000 // X -`define DEC_0X 12'h001 // 0X -`define DEC_1X 12'h100 // 1X -`define DEC_13X 12'h130 // 13X -`define DEC_14X 12'h140 // 14X -`define DEC_15X 12'h150 // 15X -`define DEC_15X_FIELD 12'h151 // 15XX -`define DEC_MEMAXX 12'h152 // 1[45]x[y] -`define DEC_MEMAXX_END 12'h153 -`define DEC_D0_EQ_5N 12'h1B0 // 1B -`define DEC_D0_EQ_LOOP 12'h1B1 // 1Bxxxxx (exec) -`define DEC_D1_EQ_4N 12'h1E0 // 1E -`define DEC_D1_EQ_5N 12'h1F0 // 1F -`define DEC_D1_EQ_LOOP 12'h1F1 // 1[EF]xxxxx (exec) -`define DEC_P_EQ_N 12'h200 // 2n -`define DEC_LC_LEN 12'h300 // 3n... -`define DEC_LC 12'h301 // 3n[x] -`define DEC_GOTO 12'h600 // 6 -`define DEC_GOTO_LOOP 12'h601 // 6[x] -> exec -`define DEC_GOSUB 12'h700 // 7 -`define DEC_GOSUB_LOOP 12'h701 // 7[x] -> exec -`define DEC_8X 12'h800 // 8X -`define DEC_80X 12'h801 // 80X -`define DEC_CONFIG 12'h805 // 805 -`define DEC_RESET 12'h80A // 80A -`define DEC_C_EQ_P_N 12'h80C // 80Cm -`define DEC_82X_CLRHST 12'h820 // 82X -`define DEC_ST_EQ_0_N 12'h840 // 84n -`define DEC_ST_EQ_1_N 12'h850 // 85n -`define DEC_8AX 12'h8A0 // 8Ax -`define DEC_GOVLNG 12'h8D0 // 8D -`define DEC_GOVLNG_LOOP 12'h8D1 // 8D[x] -`define DEC_GOVLNG_EXEC 12'h8D2 // 8Dxxxxx -> exec -`define DEC_GOSBVL 12'h8F0 // 8F -`define DEC_GOSBVL_LOOP 12'h8F1 // 8F[x] -`define DEC_GOSBVL_EXEC 12'h8F2 // 8Fxxxxx -> exec -`define DEC_AX 12'hA00 // Ax -`define DEC_AaX_EXEC 12'hA01 // Aax -`define DEC_AbX_EXEC 12'hA02 // Abx -`define DEC_BX 12'hB00 // Bx -`define DEC_CX 12'hC00 // Cx -`define DEC_DX 12'hD00 // Dx -`define DEC_FX 12'hF00 // Fx -`define DEC_TEST_GO 12'hFFF // GOYES / RTNYES +`define DEC_START 12'h000 // X +`define DEC_0X 12'h001 // 0X +`define DEC_1X 12'h100 // 1X +`define DEC_13X 12'h130 // 13X +`define DEC_14X 12'h140 // 14X +`define DEC_15X 12'h150 // 15X +`define DEC_15X_FIELD 12'h151 // 15XX +`define DEC_MEMAXX 12'h152 // 1[45]x[y] +`define DEC_MEMAXX_END 12'h153 +`define DEC_D0_EQ_5N 12'h1B0 // 1B +`define DEC_D0_EQ_LOOP 12'h1B1 // 1Bxxxxx (exec) +`define DEC_D1_EQ_4N 12'h1E0 // 1E +`define DEC_D1_EQ_5N 12'h1F0 // 1F +`define DEC_D1_EQ_LOOP 12'h1F1 // 1[EF]xxxxx (exec) +`define DEC_P_EQ_N 12'h200 // 2n +`define DEC_LC_LEN 12'h300 // 3n... +`define DEC_LC 12'h301 // 3n[x] +`define DEC_GOTO 12'h600 // 6 +`define DEC_GOTO_LOOP 12'h601 // 6[x] -> exec +`define DEC_GOSUB 12'h700 // 7 +`define DEC_GOSUB_LOOP 12'h701 // 7[x] -> exec +`define DEC_8X 12'h800 // 8X +`define DEC_80X 12'h801 // 80X +`define DEC_CONFIG 12'h805 // 805 +`define DEC_RESET 12'h80A // 80A +`define DEC_C_EQ_P_N 12'h80C // 80Cn C=P n +`define DEC_P_EQ_C_N 12'h80D // 80Dn P=C n +`define DEC_82X_CLRHST 12'h820 // 82X +`define DEC_ST_EQ_0_N 12'h840 // 84n ST=0 n +`define DEC_ST_EQ_1_N 12'h850 // 85n ST=1 n +`define DEC_TEST_ST_EQ_0_N 12'h860 // 86n ?ST=0 n +`define DEC_TEST_ST_EQ_1_N 12'h870 // 87n ?ST=1 n +`define DEC_TEST_P_NEQ_N 12'h880 // 88n ?P# n +`define DEC_TEST_P_EQ_N 12'h890 // 89n ?P= n +`define DEC_8AX 12'h8A0 // 8Ax +`define DEC_GOVLNG 12'h8D0 // 8D +`define DEC_GOVLNG_LOOP 12'h8D1 // 8D[x] +`define DEC_GOVLNG_EXEC 12'h8D2 // 8Dxxxxx -> exec +`define DEC_GOSBVL 12'h8F0 // 8F +`define DEC_GOSBVL_LOOP 12'h8F1 // 8F[x] +`define DEC_GOSBVL_EXEC 12'h8F2 // 8Fxxxxx -> exec +`define DEC_AX 12'hA00 // Ax +`define DEC_AaX_EXEC 12'hA01 // Aax +`define DEC_AbX_EXEC 12'hA02 // Abx +`define DEC_BX 12'hB00 // Bx +`define DEC_CX 12'hC00 // Cx +`define DEC_DX 12'hD00 // Dx +`define DEC_FX 12'hF00 // Fx +`define DEC_TEST_GO 12'hFFE // GOYES / RTNYES nibble 1 +`define DEC_TEST_GO_1 12'hFFF // GOYES / RTNYES nibble 2 `endif \ No newline at end of file diff --git a/opcodes/1[45]_memaccess.v b/opcodes/1[45]_memaccess.v index 82c232f..f5f0d8a 100644 --- a/opcodes/1[45]_memaccess.v +++ b/opcodes/1[45]_memaccess.v @@ -108,7 +108,7 @@ end if ((t_cnt==t_ctr) & - (((t_dir == `T_DIR_IN) & (decstate == `DEC_MEMAXX)) | + (((t_dir == `T_DIR_IN) & (decstate == `DEC_MEMAXX)&(next_cycle!=`BUSCMD_LOAD_DP)) | ((t_dir == `T_DIR_OUT) & (decstate == `DEC_MEMAXX_END)))) begin $display("---------------------------- DEC_MEMAXX_END -------------------------------"); decstate <= `DEC_START; diff --git a/opcodes/805_CONFIG.v b/opcodes/805_CONFIG.v deleted file mode 100644 index b70175e..0000000 --- a/opcodes/805_CONFIG.v +++ /dev/null @@ -1,18 +0,0 @@ -/****************************************************************************** - * 805 CONFIG - * - * - */ - -`include "decstates.v" -`include "bus_commands.v" - -begin - add_out <= C[19:0]; - next_cycle <= `BUSCMD_CONFIGURE; - decstate <= `DEC_START; -`ifdef SIM - $display("%05h CONFIG", inst_start_PC); -`endif -end - diff --git a/opcodes/80Cn_C_EQ_P_n.v b/opcodes/80[CD]n_C_and_P_n.v similarity index 65% rename from opcodes/80Cn_C_EQ_P_n.v rename to opcodes/80[CD]n_C_and_P_n.v index ad4e070..0d14fba 100644 --- a/opcodes/80Cn_C_EQ_P_n.v +++ b/opcodes/80[CD]n_C_and_P_n.v @@ -13,3 +13,11 @@ $display("%05h C=P\t%h", inst_start_PC, nb_in); `endif end +`DEC_P_EQ_C_N: begin + P <= C[nb_in*4+:4]; + decstate <= `DEC_START; +`ifdef SIM + $display("%05h P=C\t%h", inst_start_PC, nb_in); +`endif +end + diff --git a/opcodes/80x.v b/opcodes/80x.v index db82d3d..61ccc67 100644 --- a/opcodes/80x.v +++ b/opcodes/80x.v @@ -6,14 +6,27 @@ */ `include "decstates.v" +`include "bus_commands.v" `DEC_80X: begin case (nb_in) - 4'h5: -`include "opcodes/805_CONFIG.v" - 4'ha: -`include "opcodes/80A_RESET.v" - 4'hc: decstate <= `DEC_C_EQ_P_N; + 4'h5: begin + add_out <= C[19:0]; + next_cycle <= `BUSCMD_CONFIGURE; + decstate <= `DEC_START; + `ifdef SIM + $display("%05h CONFIG", inst_start_PC); + `endif + end + 4'hA: begin + next_cycle <= `BUSCMD_RESET; + decstate <= `DEC_START; + `ifdef SIM + $display("%05h RESET", inst_start_PC); + `endif + end + 4'hC: decstate <= `DEC_C_EQ_P_N; + 4'hD: decstate <= `DEC_P_EQ_C_N; default: begin $display("ERROR : DEC_80X"); decode_error <= 1; diff --git a/opcodes/8[45]n_ST_EQ_[01]_n.v b/opcodes/8[4567]n_work_test_ST.v similarity index 56% rename from opcodes/8[45]n_ST_EQ_[01]_n.v rename to opcodes/8[4567]n_work_test_ST.v index 173d9a2..29f2ee8 100644 --- a/opcodes/8[45]n_ST_EQ_[01]_n.v +++ b/opcodes/8[4567]n_work_test_ST.v @@ -19,3 +19,17 @@ end $display("%05h ST=1\t%h", inst_start_PC, nb_in); `endif end +`DEC_TEST_ST_EQ_0_N: begin + Carry <= (!ST[nb_in]); + decstate <= `DEC_TEST_GO; +`ifdef SIM + $display("%05h ?ST=0\t%h", inst_start_PC, nb_in); +`endif +end +`DEC_TEST_ST_EQ_1_N: begin + Carry <= (ST[nb_in]); + decstate <= `DEC_TEST_GO; +`ifdef SIM + $display("%05h ?ST=1\t%h", inst_start_PC, nb_in); +`endif +end diff --git a/opcodes/8[89]n_test_P.v b/opcodes/8[89]n_test_P.v new file mode 100644 index 0000000..3c25291 --- /dev/null +++ b/opcodes/8[89]n_test_P.v @@ -0,0 +1,20 @@ +/****************************************************************************** + * 88n ?P# n + * 89n ?P= n + * + */ + +`DEC_TEST_P_NEQ_N: begin + Carry <= !(P == nb_in); + decstate <= `DEC_TEST_GO; +`ifdef SIM + $display("%5h ?P#\t\t%h", inst_start_PC, nb_in); +`endif +end +`DEC_TEST_P_EQ_N: begin + Carry <= (P == nb_in); + decstate <= `DEC_TEST_GO; +`ifdef SIM + $display("%5h ?P=\t\t%h", inst_start_PC, nb_in); +`endif +end \ No newline at end of file diff --git a/opcodes/8x.v b/opcodes/8x.v index ac7e532..d8d360f 100644 --- a/opcodes/8x.v +++ b/opcodes/8x.v @@ -13,6 +13,10 @@ 4'h2: decstate <= `DEC_82X_CLRHST; 4'h4: decstate <= `DEC_ST_EQ_0_N; 4'h5: decstate <= `DEC_ST_EQ_1_N; + 4'h6: decstate <= `DEC_TEST_ST_EQ_0_N; + 4'h7: decstate <= `DEC_TEST_ST_EQ_1_N; + 4'h8: decstate <= `DEC_TEST_P_NEQ_N; + 4'h9: decstate <= `DEC_TEST_P_EQ_N; 4'hA: decstate <= `DEC_8AX; 4'hD: decstate <= `DEC_GOVLNG; 4'hF: decstate <= `DEC_GOSBVL; diff --git a/opcodes/Fx.v b/opcodes/Fx.v index ccc1959..afb0f82 100644 --- a/opcodes/Fx.v +++ b/opcodes/Fx.v @@ -29,6 +29,28 @@ endcase if (!hex_dec) $display("\tA"); else $display("\tA\t\t\t <=== DEC MODE NOT IMPLEMENTED"); +`endif + end + 4'hC, 4'hD, 4'hE, 4'hF: begin + if (!hex_dec) begin + case (nb_in) + 4'hC: {Carry, A[19:0]} <= - A[19:0] - 1; + 4'hD: {Carry, B[19:0]} <= - B[19:0] - 1; + 4'hE: {Carry, C[19:0]} <= - C[19:0] - 1; + 4'hF: {Carry, D[19:0]} <= - D[19:0] - 1; + endcase + decstate <= `DEC_START; + end +`ifdef SIM + $write("%5h ", inst_start_PC); + case (nb_in) + 4'h8: $write("A=-A-1"); + 4'h8: $write("B=-B-1"); + 4'h8: $write("C=-C-1"); + 4'h8: $write("D=-D-1"); + endcase + if (!hex_dec) $display("\tA"); + else $display("\tA\t\t\t <=== DEC MODE NOT IMPLEMENTED"); `endif end default: begin diff --git a/opcodes/xx_RTNYES_GOYES.v b/opcodes/xx_RTNYES_GOYES.v new file mode 100644 index 0000000..73c4eee --- /dev/null +++ b/opcodes/xx_RTNYES_GOYES.v @@ -0,0 +1,42 @@ +/****************************************************************************** + * xx + * RTNYES or GOYES + * + */ + +`include "decstates.v" + +`DEC_TEST_GO: begin + jump_base <= PC; + jump_offset <= {{16{1'b0}},nb_in}; + decstate <= `DEC_TEST_GO_1; +end + +`DEC_TEST_GO_1: begin + $display("DEC_TEST_GO_1 opcode %h | base %h | offset %h", + {nb_in, jump_offset[3:0]}, jump_base, + {{12{nb_in[3]}},nb_in,jump_offset[3:0]}); + if (Carry) begin + case ({nb_in, jump_offset[3:0]}) + 8'h00: begin // RTNYES + new_PC <= RSTK[rstk_ptr]; + RSTK[rstk_ptr] <= 0; + rstk_ptr <= rstk_ptr - 1; + next_cycle <= `BUSCMD_LOAD_PC; + end + default: begin // GOYES + new_PC <= jump_base + {{12{nb_in[3]}},nb_in,jump_offset[3:0]}; + next_cycle <= `BUSCMD_LOAD_PC; + end + endcase + end +`ifdef SIM + $write("%5h ", jump_base); + case ({nb_in, jump_offset[3:0]}) + 8'h00: $display("RTNYES"); + default: $display ("GOYES\t%2h\t=> %5h", {nb_in, jump_offset[3:0]}, + jump_base + {{12{nb_in[3]}},nb_in,jump_offset[3:0]}); + endcase +`endif + decstate <= `DEC_START; + end \ No newline at end of file diff --git a/saturn_core.v b/saturn_core.v index 2b6a0f4..7d985db 100644 --- a/saturn_core.v +++ b/saturn_core.v @@ -326,7 +326,7 @@ always @(posedge ph2) end always @(posedge ph3) begin - if (cycle_ctr == 240) + if (cycle_ctr == 333) debug_stop <= 1; end @@ -397,9 +397,10 @@ always @(posedge dec_strobe) begin `include "opcodes/7xxx_GOSUB.v" `include "opcodes/8x.v" `include "opcodes/80x.v" -`include "opcodes/80Cn_C_EQ_P_n.v" +`include "opcodes/80[CD]n_C_and_P_n.v" `include "opcodes/82x_CLRHST.v" -`include "opcodes/8[45]n_ST_EQ_[01]_n.v" +`include "opcodes/8[4567]n_work_test_ST.v" +`include "opcodes/8[89]n_test_P.v" `include "opcodes/8Ax_test_[n]eq_A.v" `include "opcodes/8[DF]xxxxx_GO.v" `include "opcodes/A[ab]x.v" @@ -407,6 +408,7 @@ always @(posedge dec_strobe) begin `include "opcodes/Cx.v" `include "opcodes/Dx_regs_field_A.v" `include "opcodes/Fx.v" +`include "opcodes/xx_RTNYES_GOYES.v" default: begin $display("ERROR : GENERAL"); decode_error <= 1;