diff --git a/decstates.v b/decstates.v index 0cce0fb..8c34c8c 100644 --- a/decstates.v +++ b/decstates.v @@ -17,8 +17,9 @@ `define DEC_LC_LEN 21 // 3n... `define DEC_LC 22 // 3n[x] `define DEC_GOTO 30 // 6 -`define DEC_GOTO_LOOP 31 // 6[x] -`define DEC_GOTO_EXEC 32 // 6xxx -> exec +`define DEC_GOTO_LOOP 31 // 6[x] -> exec +`define DEC_GOSUB 32 // 7 +`define DEC_GOSUB_LOOP 33 // 7[x] -> exec `define DEC_8X 40 // 8X `define DEC_80X 41 // 80X `define DEC_CONFIG 42 // 805 @@ -37,5 +38,6 @@ `define DEC_AaX_EXEC 71 // Aax `define DEC_AbX_EXEC 72 // Abx `define DEC_BX 80 // Bx +`define DEC_DX 100 // Dx `endif \ No newline at end of file diff --git a/opcodes/7xxx_GOSUB.v b/opcodes/7xxx_GOSUB.v new file mode 100644 index 0000000..147ccbb --- /dev/null +++ b/opcodes/7xxx_GOSUB.v @@ -0,0 +1,34 @@ +/****************************************************************************** + * 6xxx GOSUB xxx + * + * + */ + +`include "decstates.v" +`include "bus_commands.v" + +`DEC_GOSUB: begin + //$display("DEC_GOTO : nibble %h", nibble); + jump_offset <= 0; + t_cnt <= 2; + t_ctr <= 1; + jump_offset[3:0] <= nibble; + rstk_ptr <= rstk_ptr + 1; + decstate <= `DEC_GOSUB_LOOP; +end +`DEC_GOSUB_LOOP: begin + $display("PC %h | t_cnt %d | t_ctr %d | jump_offset %h", PC, t_cnt, t_ctr, jump_offset); + jump_offset[t_ctr*4+:4] <= nibble; + if (t_ctr == t_cnt) begin + new_PC <= PC + 1 + {8'h00, nibble, jump_offset[7:0]}; + next_cycle <= `BUSCMD_LOAD_PC; + decstate <= `DEC_START; + RSTK[rstk_ptr] <= PC + 1; +`ifdef SIM + $display("%5h GOSUB\t%3h\t=> %05h", + inst_start_PC, + {nibble, jump_offset[7:0]}, + PC + 1 + {8'h00, nibble, jump_offset[7:0]}); +`endif + end else t_ctr <= t_ctr + 1; +end