Line 10... |
Line 10... |
input wire cpu_clk,
|
input wire cpu_clk,
|
input wire [7:0] opcode,
|
input wire [7:0] opcode,
|
input wire [7:0] postbyte0,
|
input wire [7:0] postbyte0,
|
input wire page2_valid, // is 1 when the postbyte0 is a valid opcode (after it was loaded)
|
input wire page2_valid, // is 1 when the postbyte0 is a valid opcode (after it was loaded)
|
input wire page3_valid, // is 1 when the postbyte0 is a valid opcode (after it was loaded)
|
input wire page3_valid, // is 1 when the postbyte0 is a valid opcode (after it was loaded)
|
output reg [3:0] path_left_addr_o,
|
output wire [3:0] path_left_addr_o,
|
output reg [3:0] path_right_addr_o,
|
output wire [3:0] path_right_addr_o,
|
output reg [3:0] dest_reg_o,
|
output wire [3:0] dest_reg_o,
|
|
output reg [3:0] path_left_addr_lo,
|
|
output reg [3:0] path_right_addr_lo,
|
|
output reg [3:0] dest_reg_lo,
|
output wire write_dest,
|
output wire write_dest,
|
output wire source_size,
|
output wire source_size,
|
output wire result_size
|
output wire result_size
|
);
|
);
|
reg [3:0] path_left_addr, path_right_addr, dest_reg;
|
reg [3:0] path_left_addr, path_right_addr, dest_reg;
|
// for registers, memory writes are handled differently
|
// for registers, memory writes are handled differently
|
assign write_dest = (dest_reg != `RN_INV);
|
assign write_dest = (dest_reg != `RN_INV);
|
assign source_size = (path_left_addr < `RN_ACCA);
|
assign source_size = (path_left_addr < `RN_ACCA);
|
assign result_size = (dest_reg < `RN_IMM16) ? 1:0;
|
assign result_size = (dest_reg < `RN_IMM16) ? 1:0;
|
|
|
|
assign path_right_addr_o = path_right_addr;
|
|
assign path_left_addr_o = path_left_addr;
|
|
assign dest_reg_o = dest_reg;
|
|
|
|
|
always @(opcode, postbyte0, page2_valid, page3_valid)
|
always @(opcode, postbyte0, page2_valid, page3_valid)
|
begin
|
begin
|
path_left_addr = `RN_INV;
|
path_left_addr = `RN_INV;
|
path_right_addr = `RN_INV;
|
path_right_addr = `RN_INV;
|
dest_reg = `RN_INV;
|
dest_reg = `RN_INV;
|
Line 80... |
Line 89... |
8'h33: dest_reg = `RN_U;
|
8'h33: dest_reg = `RN_U;
|
8'h39: dest_reg = `RN_PC; // rts
|
8'h39: dest_reg = `RN_PC; // rts
|
8'h3d: begin path_left_addr = `RN_ACCA; path_right_addr = `RN_ACCB; dest_reg = `RN_ACCD; end // mul
|
8'h3d: begin path_left_addr = `RN_ACCA; path_right_addr = `RN_ACCB; dest_reg = `RN_ACCD; end // mul
|
8'h4x: begin path_left_addr = `RN_ACCA; dest_reg = `RN_ACCA; end
|
8'h4x: begin path_left_addr = `RN_ACCA; dest_reg = `RN_ACCA; end
|
8'h5x: begin path_left_addr = `RN_ACCB; dest_reg = `RN_ACCB; end
|
8'h5x: begin path_left_addr = `RN_ACCB; dest_reg = `RN_ACCB; end
|
8'h0x, 8'h7x: begin path_left_addr = `RN_MEM8; dest_reg = `RN_MEM8; end
|
8'h0x, 8'h6x, 8'h7x:
|
8'h6x:
|
|
case (opcode[3:0])
|
case (opcode[3:0])
|
4'hf: begin dest_reg = `RN_MEM8; end // CLR, only dest
|
4'hf: begin dest_reg = `RN_MEM8; end // CLR, only dest
|
default: begin path_left_addr = `RN_MEM8; dest_reg = `RN_MEM8; end
|
default: begin path_left_addr = `RN_MEM8; dest_reg = `RN_MEM8; end
|
endcase
|
endcase
|
8'h8x, 8'h9x, 8'hax, 8'hbx:
|
8'h8x, 8'h9x, 8'hax, 8'hbx:
|
Line 122... |
Line 130... |
8'b1x1x_000x, 8'b1x1x_0010: path_right_addr = `RN_MEM8;
|
8'b1x1x_000x, 8'b1x1x_0010: path_right_addr = `RN_MEM8;
|
8'b1x1x_0011, 8'b1x1x_11x0: path_right_addr = `RN_MEM16;
|
8'b1x1x_0011, 8'b1x1x_11x0: path_right_addr = `RN_MEM16;
|
8'b1x1x_010x, 8'b1x1x_0110, 8'b1x1x_10xx: path_right_addr = `RN_MEM8;
|
8'b1x1x_010x, 8'b1x1x_0110, 8'b1x1x_10xx: path_right_addr = `RN_MEM8;
|
endcase
|
endcase
|
end
|
end
|
|
// latched versions are used to fetch regsiters
|
|
// not-latched version in the decoder
|
always @(posedge cpu_clk)
|
always @(posedge cpu_clk)
|
begin
|
begin
|
path_right_addr_o <= path_right_addr;
|
path_right_addr_lo <= path_right_addr;
|
path_left_addr_o <= path_left_addr;
|
path_left_addr_lo <= path_left_addr;
|
dest_reg_o <= dest_reg;
|
dest_reg_lo <= dest_reg;
|
end
|
end
|
|
|
endmodule
|
endmodule
|
|
|
/* Decodes module and addressing mode for page 1 opcodes */
|
/* Decodes module and addressing mode for page 1 opcodes */
|
module decode_op(
|
module decode_op(
|
input wire [7:0] opcode,
|
input wire [7:0] opcode,
|
Line 327... |
Line 338... |
8'h04, 8'b01xx_0100: alu_opcode = `LSR;
|
8'h04, 8'b01xx_0100: alu_opcode = `LSR;
|
8'h06, 8'b01xx_0110: alu_opcode = `ROR;
|
8'h06, 8'b01xx_0110: alu_opcode = `ROR;
|
8'h07, 8'b01xx_0111: alu_opcode = `ASR;
|
8'h07, 8'b01xx_0111: alu_opcode = `ASR;
|
8'h08, 8'b01xx_1000: alu_opcode = `LSL;
|
8'h08, 8'b01xx_1000: alu_opcode = `LSL;
|
8'h09, 8'b01xx_1001: alu_opcode = `ROL;
|
8'h09, 8'b01xx_1001: alu_opcode = `ROL;
|
8'h0a, 8'b01xx_1010: begin alu_opcode = `SUB; dec_alu_right_path_mod = `MOD_MINUS1; end // dec
|
8'h0a, 8'b01xx_1010: begin alu_opcode = `SUB; dec_alu_right_path_mod = `MOD_ONE; end // dec
|
8'h0c, 8'b01xx_1100: begin alu_opcode = `ADD; dec_alu_right_path_mod = `MOD_ONE; end // inc
|
8'h0c, 8'b01xx_1100: begin alu_opcode = `ADD; dec_alu_right_path_mod = `MOD_ONE; end // inc
|
8'h0d, 8'b01xx_1101: alu_opcode = `AND;
|
8'h0d, 8'b01xx_1101: alu_opcode = `AND;
|
8'h0f, 8'b01xx_1111: begin alu_opcode = `LD; dec_alu_right_path_mod = `MOD_ZERO; end // CLR
|
8'h0f, 8'b01xx_1111: begin alu_opcode = `LD; dec_alu_right_path_mod = `MOD_ZERO; end // CLR
|
|
|
8'h19: alu_opcode = `DAA;
|
8'h19: alu_opcode = `DAA;
|