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: *
begin */
decstate <= DECODE_GOTO;
read_state <= READ_START; always @(posedge clk)
jump_base <= PC; if (decstate == DECODE_GOTO)
jump_offset <= 0; case (runstate)
load_cnt = 2; RUN_DECODE:
load_ctr = 0;
$write("%5h GOTO\t", saved_PC);
end
DECODE_GOTO:
if (read_state != READ_VALID) read_rom();
else
begin begin
jump_offset[load_ctr*4+:4] = nibble; runstate <= READ_ROM_STA;
jump_base <= PC;
jump_offset <= 0;
load_cnt <= 2;
load_ctr <= 0;
$write("%5h GOTO\t", saved_PC);
end
READ_ROM_STA, READ_ROM_CLK, READ_ROM_STR: ;
READ_ROM_VAL:
begin
jump_offset[load_ctr*4+:4] <= nibble;
$write("%1h", nibble); $write("%1h", nibble);
if (load_ctr == load_cnt) if (load_ctr == load_cnt) runstate <= RUN_EXEC;
begin
$display("\t=> %05h", jump_base + jump_offset);
PC <= jump_base + jump_offset;
end_decode();
end
else else
begin begin
load_ctr = load_ctr + 1; load_ctr <= load_ctr + 1;
read_state = READ_START; runstate <= READ_ROM_STA;
end end
end end
endcase RUN_EXEC:
endtask begin
$display("\t=> %05h", jump_base + jump_offset);
PC <= jump_base + jump_offset;
runstate <= RUN_START;
decstate <= DECODE_START;
end
default:
begin
$display("runstate %h", runstate);
halt <= 1;
end
endcase
/*
// 8x // 8x