handle GOTO in the new form

This commit is contained in:
Raphael Jacquot 2019-02-04 15:30:18 +01:00
parent 9b8428c14c
commit ffaf23b363

View file

@ -14,8 +14,8 @@ module hp_rom (
); );
localparam ROM_FILENAME = "rom-gx-r.hex"; localparam ROM_FILENAME = "rom-gx-r.hex";
//reg [3:0] rom [0:(2**20)-1]; reg [3:0] rom [0:(2**20)-1];
reg[3:0] rom [0:(2**16)-1]; //reg[3:0] rom [0:(2**16)-1];
initial initial
begin begin
@ -49,7 +49,7 @@ localparam READ_ROM_STA = 1;
localparam READ_ROM_CLK = 2; localparam READ_ROM_CLK = 2;
localparam READ_ROM_STR = 3; localparam READ_ROM_STR = 3;
localparam READ_ROM_VAL = 4; localparam READ_ROM_VAL = 4;
localparam RUN_EXEC = 14;
localparam RUN_DECODE = 15; localparam RUN_DECODE = 15;
// decoder stuff // decoder stuff
@ -253,34 +253,6 @@ always @(posedge clk)
// INSTRUCTION DECODING // INSTRUCTION DECODING
// //
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/*
task run_nibble_start;
case (read_state)
READ_START:
begin
read_rom();
saved_PC <= PC;
end
READ_CLOCK, READ_STORE:
read_rom();
READ_VALID:
run_state <= RUN_DECODE;
endcase;
endtask
task run_nibble;
begin
if ((run_state == RUN_START) & (read_state == READ_START) & (decstate == DECODE_START))
display_registers();
case (run_state)
RUN_START:run_nibble_start();
RUN_DECODE: instruction_decoder();
endcase
end
endtask
*/
// first nibble instruction decoder // first nibble instruction decoder
always @(posedge clk) always @(posedge clk)
@ -294,7 +266,7 @@ always @(posedge clk)
4'h2 : decstate <= DECODE_P_EQ; 4'h2 : decstate <= DECODE_P_EQ;
//4'h3 : decstate <= DECODE_LC; //4'h3 : decstate <= DECODE_LC;
//4'h6 : decstate <= DECODE_GOTO; 4'h6 : decstate <= DECODE_GOTO;
//4'h8 : decstate <= DECODE_8; //4'h8 : decstate <= DECODE_8;
//4'ha : decstate <= DECODE_A_FS; //4'ha : decstate <= DECODE_A_FS;
default: default:
@ -469,7 +441,12 @@ endtask
*/ */
// 2n P= n /******************************************************************************
* 2n P= n
*
*
*/
always @(posedge clk) always @(posedge clk)
if (decstate == DECODE_P_EQ) if (decstate == DECODE_P_EQ)
case (runstate) case (runstate)
@ -531,40 +508,54 @@ task inst_lc;
end end
endcase endcase
endtask endtask
*/
// 6zyx GOTO xyz /******************************************************************************
task inst_goto; * 6zyx GOTO xyz
case (decstate ) *
DECODE_START: *
*/
always @(posedge clk)
if (decstate == DECODE_GOTO)
case (runstate)
RUN_DECODE:
begin begin
decstate <= DECODE_GOTO; runstate <= READ_ROM_STA;
read_state <= READ_START;
jump_base <= PC; jump_base <= PC;
jump_offset <= 0; jump_offset <= 0;
load_cnt = 2; load_cnt <= 2;
load_ctr = 0; load_ctr <= 0;
$write("%5h GOTO\t", saved_PC); $write("%5h GOTO\t", saved_PC);
end end
DECODE_GOTO: READ_ROM_STA, READ_ROM_CLK, READ_ROM_STR: ;
if (read_state != READ_VALID) read_rom(); READ_ROM_VAL:
begin
jump_offset[load_ctr*4+:4] <= nibble;
$write("%1h", nibble);
if (load_ctr == load_cnt) runstate <= RUN_EXEC;
else else
begin begin
jump_offset[load_ctr*4+:4] = nibble; load_ctr <= load_ctr + 1;
$write("%1h", nibble); runstate <= READ_ROM_STA;
if (load_ctr == load_cnt) end
end
RUN_EXEC:
begin begin
$display("\t=> %05h", jump_base + jump_offset); $display("\t=> %05h", jump_base + jump_offset);
PC <= jump_base + jump_offset; PC <= jump_base + jump_offset;
end_decode(); runstate <= RUN_START;
decstate <= DECODE_START;
end end
else default:
begin begin
load_ctr = load_ctr + 1; $display("runstate %h", runstate);
read_state = READ_START; halt <= 1;
end
end end
endcase endcase
endtask
/*
// 8x // 8x