Line 5... |
Line 5... |
*
|
*
|
*
|
*
|
*/
|
*/
|
`include "defs.v"
|
`include "defs.v"
|
module decode_regs(
|
module decode_regs(
|
|
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,
|
output reg [3:0] path_left_addr_o,
|
output reg [3:0] path_right_addr,
|
output reg [3:0] path_right_addr_o,
|
output reg [3:0] dest_reg,
|
output reg [3:0] dest_reg_o,
|
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;
|
// 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;
|
always @(opcode, postbyte0, page2_valid, page3_valid)
|
always @(opcode, postbyte0, page2_valid, page3_valid)
|
Line 86... |
Line 88... |
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'h4x, 8'h8x, 8'h9x, 8'hax, 8'hbx:
|
8'h4x, 8'h8x, 8'h9x, 8'hax, 8'hbx:
|
case (opcode[3:0])
|
case (opcode[3:0])
|
4'h1: path_left_addr = `RN_ACCA; // CMP
|
4'h1, 4'h5: path_left_addr = `RN_ACCA; // CMP, BIT
|
4'h3: begin path_left_addr = `RN_ACCD; dest_reg = `RN_ACCD; end
|
4'h3: begin path_left_addr = `RN_ACCD; dest_reg = `RN_ACCD; end
|
4'h7: begin path_left_addr = `RN_ACCA; dest_reg = `RN_MEM8; end
|
4'h7: begin path_left_addr = `RN_ACCA; dest_reg = `RN_MEM8; end
|
4'hc: path_left_addr = `RN_IX; // cmpx
|
4'hc: path_left_addr = `RN_IX; // cmpx
|
4'he, 4'hf: begin path_left_addr = `RN_IX; dest_reg = `RN_IX; end
|
4'he, 4'hf: begin path_left_addr = `RN_IX; dest_reg = `RN_IX; end
|
4'hd: begin end // nothing active, jsr
|
4'hd: begin end // nothing active, jsr
|
default: begin path_left_addr = `RN_ACCA; dest_reg = `RN_ACCA; end
|
default: begin path_left_addr = `RN_ACCA; dest_reg = `RN_ACCA; end
|
endcase
|
endcase
|
8'h5x, 8'hcx, 8'hdx, 8'hex, 8'hfx:
|
8'h5x, 8'hcx, 8'hdx, 8'hex, 8'hfx:
|
case (opcode[3:0])
|
case (opcode[3:0])
|
4'h1: path_left_addr = `RN_ACCB; // CMP
|
4'h1, 4'h5: path_left_addr = `RN_ACCB; // CMP, BIT
|
4'h3, 4'hc: begin path_left_addr = `RN_ACCD; dest_reg = `RN_ACCD; end
|
4'h3, 4'hc: begin path_left_addr = `RN_ACCD; dest_reg = `RN_ACCD; end
|
4'h7: begin path_left_addr = `RN_ACCB; dest_reg = `RN_MEM8; end // store to mem
|
4'h7: begin path_left_addr = `RN_ACCB; dest_reg = `RN_MEM8; end // store to mem
|
4'he: begin path_left_addr = `RN_U; dest_reg = `RN_IX; end
|
4'he: begin path_left_addr = `RN_U; dest_reg = `RN_IX; end
|
4'hf: begin path_left_addr = `RN_IX; dest_reg = `RN_IX; end
|
4'hf: begin path_left_addr = `RN_IX; dest_reg = `RN_IX; end
|
4'hd: begin path_left_addr = `RN_ACCD; end
|
4'hd: begin path_left_addr = `RN_ACCD; end
|
Line 122... |
Line 124... |
8'b1x1x_0011, 8'b1x1x_11x0, 8'b1x1x_1111: path_right_addr = `RN_MEM16;
|
8'b1x1x_0011, 8'b1x1x_11x0, 8'b1x1x_1111: path_right_addr = `RN_MEM16;
|
8'b1x1x_010x, 8'b1x1x_0110,
|
8'b1x1x_010x, 8'b1x1x_0110,
|
8'b1x1x_10xx: path_right_addr = `RN_MEM8;
|
8'b1x1x_10xx: path_right_addr = `RN_MEM8;
|
endcase
|
endcase
|
end
|
end
|
|
always @(posedge cpu_clk)
|
|
begin
|
|
path_right_addr_o <= path_right_addr;
|
|
path_left_addr_o <= path_left_addr;
|
|
dest_reg_o <= dest_reg;
|
|
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 297... |
Line 304... |
begin
|
begin
|
alu_opcode = `NOP;
|
alu_opcode = `NOP;
|
dec_alu_right_path_mod = `MOD_DEFAULT;
|
dec_alu_right_path_mod = `MOD_DEFAULT;
|
casex (opcode)
|
casex (opcode)
|
8'b1xxx_0000: alu_opcode = `SUB;
|
8'b1xxx_0000: alu_opcode = `SUB;
|
8'b1xxx_0001: alu_opcode = `CMP;
|
8'b1xxx_0001: alu_opcode = `SUB; // CMP
|
8'b1xxx_0010: alu_opcode = `SBC;
|
8'b1xxx_0010: alu_opcode = `SBC;
|
8'b10xx_0011: alu_opcode = `SUB;
|
8'b10xx_0011: alu_opcode = `SUB;
|
8'b11xx_0011: alu_opcode = `ADD;
|
8'b11xx_0011: alu_opcode = `ADD;
|
8'b1xxx_0100: alu_opcode = `AND;
|
8'b1xxx_0100: alu_opcode = `AND;
|
8'b1xxx_0101: alu_opcode = `BIT;
|
8'b1xxx_0101: alu_opcode = `AND; // BIT
|
8'b1xxx_0110: alu_opcode = `LD;
|
8'b1xxx_0110: alu_opcode = `LD;
|
8'b1xxx_0111: alu_opcode = `ST;
|
8'b1xxx_0111: alu_opcode = `ST;
|
8'b1xxx_1000: alu_opcode = `EOR;
|
8'b1xxx_1000: alu_opcode = `EOR;
|
8'b1xxx_1001: alu_opcode = `ADC;
|
8'b1xxx_1001: alu_opcode = `ADC;
|
8'b1xxx_1010: alu_opcode = `OR;
|
8'b1xxx_1010: alu_opcode = `OR;
|
8'b1xxx_1011: alu_opcode = `ADD;
|
8'b1xxx_1011: alu_opcode = `ADD;
|
8'b10xx_1100: alu_opcode = `CMP;
|
8'b10xx_1100: alu_opcode = `SUB; // CMP
|
8'b11xx_1100: alu_opcode = `LD;
|
8'b11xx_1100: alu_opcode = `LD;
|
8'b11xx_1101: alu_opcode = `LD;
|
8'b11xx_1101: alu_opcode = `LD;
|
8'b1xxx_1110: alu_opcode = `LD;
|
8'b1xxx_1110: alu_opcode = `LD;
|
8'b1xxx_1111: alu_opcode = `ST;
|
8'b1xxx_1111: alu_opcode = `ST;
|
|
|
Line 331... |
Line 338... |
|
|
8'h19: alu_opcode = `DAA;
|
8'h19: alu_opcode = `DAA;
|
8'h1a: alu_opcode = `ORCC;
|
8'h1a: alu_opcode = `ORCC;
|
8'h1c, 8'h3c: alu_opcode = `ANDCC;
|
8'h1c, 8'h3c: alu_opcode = `ANDCC;
|
8'h1d: alu_opcode = `SEXT;
|
8'h1d: alu_opcode = `SEXT;
|
8'h1e: alu_opcode = `EXG;
|
//8'h1e: alu_opcode = `EXG;
|
8'b0011_000x: alu_opcode = `LEA;
|
8'b0011_000x: alu_opcode = `LEA;
|
8'h3d: alu_opcode = `MUL;
|
8'h3d: alu_opcode = `MUL;
|
endcase
|
endcase
|
if (page2_valid)
|
if (page2_valid)
|
casex (postbyte0)
|
casex (postbyte0)
|
8'b10xx_0011,
|
8'b10xx_0011,
|
8'b10xx_1010: alu_opcode = `CMP;
|
8'b10xx_1010: alu_opcode = `SUB; //CMP
|
8'b1xxx_1110: alu_opcode = `LD;
|
8'b1xxx_1110: alu_opcode = `LD;
|
8'b1xxx_1111: alu_opcode = `ST;
|
8'b1xxx_1111: alu_opcode = `ST;
|
endcase
|
endcase
|
if (page3_valid)
|
if (page3_valid)
|
casex (postbyte0)
|
casex (postbyte0)
|
8'b10xx_0011,
|
8'b10xx_0011,
|
8'b10xx_1010: alu_opcode = `CMP;
|
8'b10xx_1010: alu_opcode = `SUB; //CMP
|
8'b1xxx_1110: alu_opcode = `LD;
|
8'b1xxx_1110: alu_opcode = `LD;
|
8'b1xxx_1111: alu_opcode = `ST;
|
8'b1xxx_1111: alu_opcode = `ST;
|
endcase
|
endcase
|
end
|
end
|
|
|