Line 88... |
Line 88... |
localparam PUSH_PCH = 5'b10000;
|
localparam PUSH_PCH = 5'b10000;
|
localparam PUSH_PCL = 5'b10001;
|
localparam PUSH_PCL = 5'b10001;
|
localparam PUSH_STATUS = 5'b10010;
|
localparam PUSH_STATUS = 5'b10010;
|
localparam FETCH_PCL = 5'b10011;
|
localparam FETCH_PCL = 5'b10011;
|
localparam FETCH_PCH = 5'b10100;
|
localparam FETCH_PCH = 5'b10100;
|
|
localparam INCREMENT_SP = 5'b10101;
|
|
localparam PULL_STATUS = 5'b10110;
|
|
localparam PULL_PCL = 5'b10111;
|
|
localparam PULL_PCH = 5'b11000;
|
|
|
localparam RESET = 5'b11111;
|
localparam RESET = 5'b11111;
|
|
|
// OPCODES TODO: verify how this get synthesised
|
// OPCODES TODO: verify how this get synthesised
|
`include "../T6507LP_Package.v"
|
`include "../T6507LP_Package.v"
|
Line 129... |
Line 133... |
reg jump;
|
reg jump;
|
reg jump_indirect;
|
reg jump_indirect;
|
|
|
// regs for the special instructions
|
// regs for the special instructions
|
reg break;
|
reg break;
|
|
reg rti;
|
|
|
wire [ADDR_SIZE_:0] next_pc;
|
wire [ADDR_SIZE_:0] next_pc;
|
assign next_pc = pc + 13'b0000000000001;
|
assign next_pc = pc + 13'b0000000000001;
|
|
|
reg [ADDR_SIZE_:0] address_plus_index; // this would update more times than actually needed, consuming power.
|
reg [ADDR_SIZE_:0] address_plus_index; // this would update more times than actually needed, consuming power.
|
Line 271... |
Line 276... |
address <= sp;
|
address <= sp;
|
data_out <= {{3{1'b0}}, pc[12:8]};
|
data_out <= {{3{1'b0}}, pc[12:8]};
|
control <= MEM_WRITE;
|
control <= MEM_WRITE;
|
sp <= sp_minus_one;
|
sp <= sp_minus_one;
|
end
|
end
|
|
else if (rti) begin
|
|
address <= sp;
|
|
control <= MEM_READ;
|
|
end
|
end
|
end
|
end
|
end
|
FETCH_HIGH_CALC_INDEX: begin
|
FETCH_HIGH_CALC_INDEX: begin
|
pc <= next_pc;
|
pc <= next_pc;
|
temp_addr[12:8] <= data_in[4:0];
|
temp_addr[12:8] <= data_in[4:0];
|
Line 484... |
Line 493... |
FETCH_PCH: begin
|
FETCH_PCH: begin
|
pc[12:8] <= data_in[4:0];
|
pc[12:8] <= data_in[4:0];
|
address <= {data_in[4:0], pc[7:0]};
|
address <= {data_in[4:0], pc[7:0]};
|
control <= MEM_READ;
|
control <= MEM_READ;
|
end
|
end
|
|
INCREMENT_SP: begin
|
|
sp <= sp_plus_one;
|
|
address <= sp_plus_one;
|
|
end
|
|
PULL_STATUS: begin
|
|
sp <= sp_plus_one;
|
|
address <= sp_plus_one;
|
|
temp_data <= data_in;
|
|
end
|
|
PULL_PCL: begin
|
|
sp <= sp_plus_one;
|
|
address <= sp_plus_one;
|
|
pc[7:0] <= data_in;
|
|
end
|
|
PULL_PCH: begin
|
|
pc[12:8] <= data_in[4:0];
|
|
address <= {data_in[4:0], pc[7:0]};
|
|
end
|
default: begin
|
default: begin
|
$write("unknown state"); // TODO: check if synth really ignores this 2 lines. Otherwise wrap it with a `ifdef
|
$write("unknown state"); // TODO: check if synth really ignores this 2 lines. Otherwise wrap it with a `ifdef
|
$finish(0);
|
$finish(0);
|
end
|
end
|
|
|
Line 566... |
Line 593... |
end
|
end
|
else begin // all the special instructions will fall here
|
else begin // all the special instructions will fall here
|
if (break) begin
|
if (break) begin
|
next_state = PUSH_PCH;
|
next_state = PUSH_PCH;
|
end
|
end
|
|
else if (rti) begin
|
|
next_state = INCREMENT_SP;
|
|
end
|
end
|
end
|
end
|
end
|
READ_FROM_POINTER: begin
|
READ_FROM_POINTER: begin
|
if (indirectx) begin
|
if (indirectx) begin
|
next_state = READ_FROM_POINTER_X;
|
next_state = READ_FROM_POINTER_X;
|
Line 702... |
Line 732... |
next_state = FETCH_PCH;
|
next_state = FETCH_PCH;
|
end
|
end
|
FETCH_PCH: begin
|
FETCH_PCH: begin
|
next_state = FETCH_OP;
|
next_state = FETCH_OP;
|
end
|
end
|
|
INCREMENT_SP: begin
|
|
next_state = PULL_STATUS;
|
|
end
|
|
PULL_STATUS: begin
|
|
next_state = PULL_PCL;
|
|
end
|
|
PULL_PCL: begin
|
|
next_state = PULL_PCH;
|
|
alu_opcode = ir;
|
|
alu_enable = 1'b1;
|
|
alu_a = temp_data;
|
|
end
|
|
PULL_PCH: begin
|
|
next_state = FETCH_OP;
|
|
end
|
default: begin
|
default: begin
|
next_state = RESET;
|
next_state = RESET;
|
end
|
end
|
endcase
|
endcase
|
end
|
end
|
Line 731... |
Line 776... |
jump = 1'b0;
|
jump = 1'b0;
|
jump_indirect = 1'b0;
|
jump_indirect = 1'b0;
|
branch = 1'b0;
|
branch = 1'b0;
|
|
|
break = 1'b0;
|
break = 1'b0;
|
|
rti = 1'b0;
|
|
|
case (ir)
|
case (ir)
|
CLC_IMP, CLD_IMP, CLI_IMP, CLV_IMP, DEX_IMP, DEY_IMP, INX_IMP, INY_IMP, NOP_IMP, PHA_IMP, PHP_IMP, PLA_IMP,
|
CLC_IMP, CLD_IMP, CLI_IMP, CLV_IMP, DEX_IMP, DEY_IMP, INX_IMP, INY_IMP, NOP_IMP, PHA_IMP, PHP_IMP, PLA_IMP,
|
PLP_IMP, RTI_IMP, RTS_IMP, SEC_IMP, SED_IMP, SEI_IMP, TAX_IMP, TAY_IMP, TSX_IMP, TXA_IMP, TXS_IMP, TYA_IMP: begin
|
PLP_IMP, RTS_IMP, SEC_IMP, SED_IMP, SEI_IMP, TAX_IMP, TAY_IMP, TSX_IMP, TXA_IMP, TXS_IMP, TYA_IMP: begin
|
implied = 1'b1;
|
implied = 1'b1;
|
end
|
end
|
ASL_ACC, LSR_ACC, ROL_ACC, ROR_ACC: begin
|
ASL_ACC, LSR_ACC, ROL_ACC, ROR_ACC: begin
|
accumulator = 1'b1;
|
accumulator = 1'b1;
|
end
|
end
|
Line 875... |
Line 921... |
jump_indirect = 1'b1;
|
jump_indirect = 1'b1;
|
end
|
end
|
BRK_IMP: begin
|
BRK_IMP: begin
|
break = 1'b1;
|
break = 1'b1;
|
end
|
end
|
|
RTI_IMP: begin
|
|
rti = 1'b1;
|
|
end
|
default: begin
|
default: begin
|
$write("state : %b", state);
|
$write("state : %b", state);
|
if (reset_n == 1 && state != FETCH_OP_FIX_PC) begin // the processor is NOT being reset neither it is fixing the pc
|
if (reset_n == 1 && state != FETCH_OP_FIX_PC) begin // the processor is NOT being reset neither it is fixing the pc
|
$write("\nunknown OPCODE!!!!! 0x%h\n", ir);
|
$write("\nunknown OPCODE!!!!! 0x%h\n", ir);
|
$finish();
|
$finish();
|