// Original Coco 3 Plus contributions: Copyright (c) 2026 Brian K. Holman. // Original component notices/terms retained; see COPYRIGHT.md and LICENSING.md. // SPDX-License-Identifier: BSD-3-Clause // Full original TMS7000 opcode map. VCCPlus/MAME reference; see LICENSE. module ssc_tms7000_decode(input wire [7:0] opcode, output reg [5:0] operation,output reg [4:0] mode, output reg [5:0] base_cycles); `include "ssc_tms7000_defs.vh" reg [5:0] binary_operation,unary_operation; always @* begin binary_operation=OP_BAD;unary_operation=OP_BAD; case(opcode[3:0]) 2:binary_operation=OP_MOV;3:binary_operation=OP_AND;4:binary_operation=OP_OR; 5:binary_operation=OP_XOR;6:binary_operation=OP_BTJO;7:binary_operation=OP_BTJZ; 8:binary_operation=OP_ADD;9:binary_operation=OP_ADC;10:binary_operation=OP_SUB; 11:binary_operation=OP_SBB;12:binary_operation=OP_MPY;13:binary_operation=OP_CMP; 14:binary_operation=OP_DAC;15:binary_operation=OP_DSB; default:binary_operation=OP_BAD; endcase case(opcode[3:0]) 2:unary_operation=OP_DEC;3:unary_operation=OP_INC;4:unary_operation=OP_INV; 5:unary_operation=OP_CLR;6:unary_operation=OP_XCHB;7:unary_operation=OP_SWAP; 8:unary_operation=OP_PUSH;9:unary_operation=OP_POP;10:unary_operation=OP_DJNZ; 11:unary_operation=OP_DECD;12:unary_operation=OP_RR;13:unary_operation=OP_RRC; 14:unary_operation=OP_RL;15:unary_operation=OP_RLC; default:unary_operation=OP_BAD; endcase operation=OP_BAD;mode=AM_NONE;base_cycles=5; if(opcode>=8'h12 && opcode<=8'h7f && opcode[3:0]>=2) begin operation=binary_operation; case(opcode[7:4]) 1:begin mode=AM_R_A;base_cycles=8;end 2:begin mode=AM_I_A;base_cycles=7;end 3:begin mode=AM_R_B;base_cycles=8;end 4:begin mode=AM_R_R;base_cycles=10;end 5:begin mode=AM_I_B;base_cycles=7;end 6:begin mode=AM_B_A;base_cycles=5;end 7:begin mode=AM_I_R;base_cycles=9;end default:begin mode=AM_NONE;operation=OP_BAD;end endcase end else if(opcode>=8'hb0 && opcode<=8'hdf) begin operation=unary_operation; mode=(opcode[7:4]==11)?AM_A:(opcode[7:4]==12)?AM_B:AM_R; base_cycles=(mode==AM_R)?6'd7:6'd5; case(opcode[3:0]) 0:begin operation=OP_MOV;mode=(opcode[7:4]==11)?AM_A_A:(opcode[7:4]==12)?AM_A_B:AM_A_R;base_cycles=(mode==AM_A_R)?6'd8:6'd6;end 1:begin operation=OP_MOV;mode=(opcode[7:4]==11)?AM_B_A:(opcode[7:4]==12)?AM_B_B:AM_B_R;base_cycles=(mode==AM_B_A)?6'd5:(mode==AM_B_R)?6'd7:6'd6;end 8,9:base_cycles=(mode==AM_R)?6'd8:6'd6; 11:base_cycles=(mode==AM_R)?6'd11:6'd9; default:begin end endcase end else if(opcode>=8'he8) begin operation=OP_TRAP;base_cycles=14;end else if(opcode>=8'he0) begin operation=OP_JUMP;base_cycles=3;end else case(opcode) 8'h00:operation=OP_NOP; 8'h01:begin operation=OP_IDLE;base_cycles=6;end 8'h05:operation=OP_EINT; 8'h06:operation=OP_DINT; 8'h07:operation=OP_SETC; 8'h08:begin operation=OP_POPST;base_cycles=6;end 8'h09:begin operation=OP_STSP;base_cycles=6;end 8'h0a:begin operation=OP_RETS;base_cycles=7;end 8'h0b:begin operation=OP_RETI;base_cycles=9;end 8'h0d:operation=OP_LDSP; 8'h0e:begin operation=OP_PUSHST;base_cycles=6;end 8'h80:begin operation=OP_MOV;mode=AM_P_A;base_cycles=9;end 8'h91:begin operation=OP_MOV;mode=AM_P_B;base_cycles=8;end default:begin if(opcode[7:4]>=8 && opcode[7:4]<=10) begin if(opcode[3:0]>=2 && opcode[3:0]<=7) begin operation=binary_operation;mode=(opcode[7:4]==8)?AM_A_P:(opcode[7:4]==9)?AM_B_P:AM_I_P; base_cycles=(opcode[7:4]==8)?6'd10:(opcode[7:4]==9)?6'd9:6'd11; end else begin mode=(opcode[7:4]==8)?AM_DIR:(opcode[7:4]==9)?AM_IND:AM_INX; case(opcode[3:0]) 8:begin operation=OP_MOVD;base_cycles=(mode==AM_DIR)?6'd15:(mode==AM_IND)?6'd14:6'd17;end 10:begin operation=OP_LDA;base_cycles=(mode==AM_DIR)?6'd11:(mode==AM_IND)?6'd10:6'd13;end 11:begin operation=OP_STA;base_cycles=(mode==AM_DIR)?6'd11:(mode==AM_IND)?6'd10:6'd13;end 12:begin operation=OP_BR;base_cycles=(mode==AM_DIR)?6'd10:(mode==AM_IND)?6'd9:6'd12;end 13:begin operation=OP_CMPA;base_cycles=(mode==AM_DIR)?6'd12:(mode==AM_IND)?6'd11:6'd14;end 14:begin operation=OP_CALL;base_cycles=(mode==AM_DIR)?6'd14:(mode==AM_IND)?6'd13:6'd16;end default:mode=AM_NONE; endcase end end end endcase end endmodule