OpenCores
URL https://opencores.org/ocsvn/rtf65002/rtf65002/trunk

Subversion Repositories rtf65002

[/] [rtf65002/] [trunk/] [rtl/] [verilog/] [decode.v] - Diff between revs 36 and 38

Only display areas with differences | Details | Blame | View Log

Rev 36 Rev 38
// ============================================================================
// ============================================================================
//        __
//        __
//   \\__/ o\    (C) 2013  Robert Finch, Stratford
//   \\__/ o\    (C) 2013  Robert Finch, Stratford
//    \  __ /    All rights reserved.
//    \  __ /    All rights reserved.
//     \/_//     robfinch<remove>@opencores.org
//     \/_//     robfinch<remove>@opencores.org
//       ||
//       ||
//
//
// This source file is free software: you can redistribute it and/or modify 
// This source file is free software: you can redistribute it and/or modify 
// it under the terms of the GNU Lesser General Public License as published 
// it under the terms of the GNU Lesser General Public License as published 
// by the Free Software Foundation, either version 3 of the License, or     
// by the Free Software Foundation, either version 3 of the License, or     
// (at your option) any later version.                                      
// (at your option) any later version.                                      
//                                                                          
//                                                                          
// This source file is distributed in the hope that it will be useful,      
// This source file is distributed in the hope that it will be useful,      
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
// GNU General Public License for more details.                             
// GNU General Public License for more details.                             
//                                                                          
//                                                                          
// You should have received a copy of the GNU General Public License        
// You should have received a copy of the GNU General Public License        
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
//                                                                          
//                                                                          
// ============================================================================
// ============================================================================
//
//
task decode_tsk;
task decode_tsk;
        begin
        begin
                first_ifetch <= `TRUE;
                first_ifetch <= `TRUE;
                Rt <= 4'h0;             // Default
                Rt <= 4'h0;             // Default
                state <= IFETCH;
                state <= IFETCH;
                pc <= pc + pc_inc;
                pc <= pc + pc_inc;
 
                pc_inc2 <= pc_inc;
                a <= rfoa;
                a <= rfoa;
                res <= alu_out;
                res <= alu_out;
                ttrig <= tf;
                ttrig <= tf;
                oisp <= isp;    // for bus retry
                oisp <= isp;    // for bus retry
                // This case statement should include all opcodes or the opcode
                // This case statement should include all opcodes or the opcode
                // will end up being treated as an undefined operation.
                // will end up being treated as an undefined operation.
                case(ir9)
                case(ir9)
                `STP:   clk_en <= 1'b0;
                `STP:   clk_en <= 1'b0;
                `NOP:   ;
                `NOP:   ;
//                              casex(ir[63:0])
//                              casex(ir[63:0])
//                              {`NOP,`NOP,`NOP,`NOP,`NOP,`NOP,`NOP,`NOP}:      pc <= pcp8;
//                              {`NOP,`NOP,`NOP,`NOP,`NOP,`NOP,`NOP,`NOP}:      pc <= pcp8;
//                              {8'hxx,`NOP,`NOP,`NOP,`NOP,`NOP,`NOP,`NOP}:     pc <= pcp7;
//                              {8'hxx,`NOP,`NOP,`NOP,`NOP,`NOP,`NOP,`NOP}:     pc <= pcp7;
//                              {16'hxxxx,`NOP,`NOP,`NOP,`NOP,`NOP,`NOP}:       pc <= pcp6;
//                              {16'hxxxx,`NOP,`NOP,`NOP,`NOP,`NOP,`NOP}:       pc <= pcp6;
//                              {24'hxxxxxx,`NOP,`NOP,`NOP,`NOP,`NOP}:  pc <= pcp5;
//                              {24'hxxxxxx,`NOP,`NOP,`NOP,`NOP,`NOP}:  pc <= pcp5;
//                              {32'hxxxxxxxx,`NOP,`NOP,`NOP,`NOP}:     pc <= pcp4;
//                              {32'hxxxxxxxx,`NOP,`NOP,`NOP,`NOP}:     pc <= pcp4;
//                              {40'hxxxxxxxxxx,`NOP,`NOP,`NOP}:        pc <= pcp3;
//                              {40'hxxxxxxxxxx,`NOP,`NOP,`NOP}:        pc <= pcp3;
//                              {48'hxxxxxxxxxxxx,`NOP,`NOP}:   pc <= pcp2;
//                              {48'hxxxxxxxxxxxx,`NOP,`NOP}:   pc <= pcp2;
//                              {56'hxxxxxxxxxxxxxx,`NOP}:      pc <= pcp1;
//                              {56'hxxxxxxxxxxxxxx,`NOP}:      pc <= pcp1;
//                              endcase
//                              endcase
                `CLC:   cf <= 1'b0;
                `CLC:   cf <= 1'b0;
                `SEC:   cf <= 1'b1;
                `SEC:   cf <= 1'b1;
                `CLV:   vf <= 1'b0;
                `CLV:   vf <= 1'b0;
                `CLI:   im <= 1'b0;
                `CLI:   im <= 1'b0;
                `CLD:   df <= 1'b0;
                `CLD:   df <= 1'b0;
                `SED:   df <= 1'b1;
                `SED:   df <= 1'b1;
                `SEI:   im <= 1'b1;
                `SEI:   im <= 1'b1;
                `WAI:   wai <= 1'b1;
                `WAI:   wai <= 1'b1;
                `TON:   tf <= 1'b1;
                `TON:   tf <= 1'b1;
                `TOFF:  tf <= 1'b0;
                `TOFF:  tf <= 1'b0;
                `HOFF:  hist_capture <= 1'b0;
                `HOFF:  hist_capture <= 1'b0;
                `EMM:   begin em <= 1'b1;
                // Switching to 65c02 mode zeros out the upper part of the index registers.
 
                // Switching to 65c816 mode does not zero out the upper part of the index registers,
 
                // this is unlike switching from '02 to '816 mode. Also, the register size select
 
                // bits are not affected.
 
                `XCE:   begin
 
                                        em <= 1'b1;
 
                                        m816 <= ~cf;
 
                                        cf <= ~m816;
 
                                        if (cf) begin
 
                                                x[31:8] <= 24'd0;
 
                                                y[31:8] <= 24'd0;
 
                                        end
`ifdef SUPPORT_EM8
`ifdef SUPPORT_EM8
                                state <= BYTE_IFETCH;
                                        next_state(BYTE_IFETCH);
`endif
`endif
                                end
                                end
                `DEX:   Rt <= 4'd2;
                `DEX:   Rt <= 4'd2;
                                        // DEX/BNE accelerator
                                        // DEX/BNE accelerator
//                                      if (ir[15:8]==`BNE) begin
//                                      if (ir[15:8]==`BNE) begin
//                                              if (x!=32'd1) begin
//                                              if (x!=32'd1) begin
//                                                      if (ir[23:16]==8'h01)
//                                                      if (ir[23:16]==8'h01)
//                                                              pc <= pc + {{16{ir[39]}},ir[39:24]} + 32'd1;
//                                                              pc <= pc + {{16{ir[39]}},ir[39:24]} + 32'd1;
//                                                      else
//                                                      else
//                                                              pc <= pc + {{24{ir[23]}},ir[23:16]} + 32'd1;
//                                                              pc <= pc + {{24{ir[23]}},ir[23:16]} + 32'd1;
//                                              end
//                                              end
//                                              else begin
//                                              else begin
//                                                      if (ir[23:16]==8'h01)
//                                                      if (ir[23:16]==8'h01)
//                                                              pc <= pcp5;
//                                                              pc <= pcp5;
//                                                      else
//                                                      else
//                                                              pc <= pcp3;
//                                                              pc <= pcp3;
//                                              end
//                                              end
//                                      end
//                                      end
                `INX:   Rt <= 4'd2;
                `INX:   Rt <= 4'd2;
                `DEY:   Rt <= 4'd3;
                `DEY:   Rt <= 4'd3;
                `INY:   Rt <= 4'd3;
                `INY:   Rt <= 4'd3;
                `DEA:   Rt <= 4'd1;
                `DEA:   Rt <= 4'd1;
                `INA:   Rt <= 4'd1;
                `INA:   Rt <= 4'd1;
                `TSX:   Rt <= 4'd2;
                `TSX:   Rt <= 4'd2;
                `TSA:   Rt <= 4'd1;
                `TSA:   Rt <= 4'd1;
                `TXS:   ;
                `TXS:   ;
                `TXA:   Rt <= 4'd1;
                `TXA:   Rt <= 4'd1;
                `TXY:   Rt <= 4'd3;
                `TXY:   Rt <= 4'd3;
                `TAX:   Rt <= 4'd2;
                `TAX:   Rt <= 4'd2;
                `TAY:   Rt <= 4'd3;
                `TAY:   Rt <= 4'd3;
                `TAS:   ;
                `TAS:   ;
                `TYA:   Rt <= 4'd1;
                `TYA:   Rt <= 4'd1;
                `TYX:   Rt <= 4'd2;
                `TYX:   Rt <= 4'd2;
                `TRS:           ;
                `TRS:           ;
                `TSR:           begin
                `TSR:           begin
                                                Rt <= ir[15:12];
                                                Rt <= ir[15:12];
                                                case(ir[11:8])
                                                case(ir[11:8])
                                                4'h0:   ;
                                                4'h0:   ;
                                                4'h2:   ;
                                                4'h2:   ;
                                                4'h3:   ;
                                                4'h3:   ;
                                                4'h4:   ;
                                                4'h4:   ;
                                                4'h5:   lfsr <= {lfsr[30:0],lfsr_fb};
                                                4'h5:   lfsr <= {lfsr[30:0],lfsr_fb};
                                                4'd7:   ;
                                                4'd7:   ;
                                                4'h8:   ;
                                                4'h8:   ;
                                                4'h9:   ;
                                                4'h9:   ;
`ifdef DEBUG
`ifdef DEBUG
                                                4'hA:   history_ndx <= history_ndx + 6'd1;
                                                4'hA:   history_ndx <= history_ndx + 6'd1;
`endif
`endif
                                                4'hE:   ;
                                                4'hE:   ;
                                                4'hF:   ;
                                                4'hF:   ;
                                                default:        ;
                                                default:        ;
                                                endcase
                                                endcase
                                        end
                                        end
                `ASL_ACC:       Rt <= 4'd1;
                `ASL_ACC:       Rt <= 4'd1;
                `ROL_ACC:       Rt <= 4'd1;
                `ROL_ACC:       Rt <= 4'd1;
                `LSR_ACC:       Rt <= 4'd1;
                `LSR_ACC:       Rt <= 4'd1;
                `ROR_ACC:       Rt <= 4'd1;
                `ROR_ACC:       Rt <= 4'd1;
 
 
                `RR:
                `RR:
                        begin
                        begin
                                Rt <= ir[19:16];
                                Rt <= ir[19:16];
                                case(ir[23:20])
                                case(ir[23:20])
                                `ADD_RR:        b <= rfob;
                                `ADD_RR:        b <= rfob;
                                `SUB_RR:        b <= rfob;
                                `SUB_RR:        b <= rfob;
                                `AND_RR:        b <= rfob;      // for bit flags
                                `AND_RR:        b <= rfob;      // for bit flags
                                `OR_RR:         b <= rfob;
                                `OR_RR:         b <= rfob;
                                `EOR_RR:        b <= rfob;
                                `EOR_RR:        b <= rfob;
                                `MUL_RR:        begin b <= rfob; state <= MULDIV1; end
                                `MUL_RR:        begin b <= rfob; state <= MULDIV1; end
                                `MULS_RR:       begin b <= rfob; state <= MULDIV1; end
                                `MULS_RR:       begin b <= rfob; state <= MULDIV1; end
`ifdef SUPPORT_DIVMOD
`ifdef SUPPORT_DIVMOD
                                `DIV_RR:        begin b <= rfob; state <= MULDIV1; end
                                `DIV_RR:        begin b <= rfob; state <= MULDIV1; end
                                `DIVS_RR:       begin b <= rfob; state <= MULDIV1; end
                                `DIVS_RR:       begin b <= rfob; state <= MULDIV1; end
                                `MOD_RR:        begin b <= rfob; state <= MULDIV1; end
                                `MOD_RR:        begin b <= rfob; state <= MULDIV1; end
                                `MODS_RR:       begin b <= rfob; state <= MULDIV1; end
                                `MODS_RR:       begin b <= rfob; state <= MULDIV1; end
`endif
`endif
`ifdef SUPPORT_SHIFT
`ifdef SUPPORT_SHIFT
                                `ASL_RRR:       begin b <= rfob; state <= CALC; end
                                `ASL_RRR:       begin b <= rfob; state <= CALC; end
                                `LSR_RRR:       begin b <= rfob; state <= CALC; end
                                `LSR_RRR:       begin b <= rfob; state <= CALC; end
`endif
`endif
                                default:
                                default:
                                        begin
                                        begin
                                                Rt <= 4'h0;
                                                Rt <= 4'h0;
                                                pg2 <= `FALSE;
                                                pg2 <= `FALSE;
                                                ir <= {8{`BRK}};
                                                ir <= {8{`BRK}};
                                                hwi <= `TRUE;
                                                hwi <= `TRUE;
                                                vect <= {vbr[31:9],9'd495,2'b00};
                                                vect <= {vbr[31:9],9'd495,2'b00};
                                                pc <= pc;               // override the pc increment
                                                pc <= pc;               // override the pc increment
                                                state <= DECODE;
                                                state <= DECODE;
                                        end
                                        end
                                endcase
                                endcase
                        end
                        end
                `LD_RR:         Rt <= ir[15:12];
                `LD_RR:         Rt <= ir[15:12];
                `ASL_RR:        Rt <= ir[15:12];
                `ASL_RR:        Rt <= ir[15:12];
                `ROL_RR:        Rt <= ir[15:12];
                `ROL_RR:        Rt <= ir[15:12];
                `LSR_RR:        Rt <= ir[15:12];
                `LSR_RR:        Rt <= ir[15:12];
                `ROR_RR:        Rt <= ir[15:12];
                `ROR_RR:        Rt <= ir[15:12];
                `DEC_RR:        Rt <= ir[15:12];
                `DEC_RR:        Rt <= ir[15:12];
                `INC_RR:        Rt <= ir[15:12];
                `INC_RR:        Rt <= ir[15:12];
 
/*
 
                Can't P&R this
 
                `ADD_R:         begin Rt <= ir[11: 8]; b <= rfob; end
 
                `SUB_R:         begin Rt <= ir[11: 8]; b <= rfob; end
 
                `OR_R:          begin Rt <= ir[11: 8]; b <= rfob; end
 
                `AND_R:         begin Rt <= ir[11: 8]; b <= rfob; end
 
                `EOR_R:         begin Rt <= ir[11: 8]; b <= rfob; end
 
*/
 
                `ADD_IMM4:      begin Rt <= ir[11: 8]; b <= {{28{ir[15]}},ir[15:12]}; end
 
                `SUB_IMM4:      begin Rt <= ir[11: 8]; b <= {{28{ir[15]}},ir[15:12]}; end
 
                `OR_IMM4:       begin Rt <= ir[11: 8]; b <= {{28{ir[15]}},ir[15:12]}; end
 
                `AND_IMM4:      begin Rt <= ir[11: 8]; b <= {{28{ir[15]}},ir[15:12]}; end
 
                `EOR_IMM4:      begin Rt <= ir[11: 8]; b <= {{28{ir[15]}},ir[15:12]}; end
 
 
                `ADD_IMM8:      begin Rt <= ir[15:12]; b <= {{24{ir[23]}},ir[23:16]}; end
                `ADD_IMM8:      begin Rt <= ir[15:12]; b <= {{24{ir[23]}},ir[23:16]}; end
                `SUB_IMM8:      begin Rt <= ir[15:12]; b <= {{24{ir[23]}},ir[23:16]}; end
                `SUB_IMM8:      begin Rt <= ir[15:12]; b <= {{24{ir[23]}},ir[23:16]}; end
                `MUL_IMM8:      begin Rt <= ir[15:12]; b <= {{24{ir[23]}},ir[23:16]}; state <= MULDIV1; end
                `MUL_IMM8:      begin Rt <= ir[15:12]; b <= {{24{ir[23]}},ir[23:16]}; state <= MULDIV1; end
`ifdef SUPPORT_DIVMOD
`ifdef SUPPORT_DIVMOD
                `DIV_IMM8:      begin Rt <= ir[15:12]; b <= {{24{ir[23]}},ir[23:16]}; state <= MULDIV1; end
                `DIV_IMM8:      begin Rt <= ir[15:12]; b <= {{24{ir[23]}},ir[23:16]}; state <= MULDIV1; end
                `MOD_IMM8:      begin Rt <= ir[15:12]; b <= {{24{ir[23]}},ir[23:16]}; state <= MULDIV1; end
                `MOD_IMM8:      begin Rt <= ir[15:12]; b <= {{24{ir[23]}},ir[23:16]}; state <= MULDIV1; end
`endif
`endif
                `OR_IMM8:       begin Rt <= ir[15:12]; end
                `OR_IMM8:       begin Rt <= ir[15:12]; end
                `AND_IMM8:      begin Rt <= ir[15:12]; b <= {{24{ir[23]}},ir[23:16]}; end
                `AND_IMM8:      begin Rt <= ir[15:12]; b <= {{24{ir[23]}},ir[23:16]}; end
                `EOR_IMM8:      begin Rt <= ir[15:12]; end
                `EOR_IMM8:      begin Rt <= ir[15:12]; end
                `CMP_IMM8:      ;
                `CMP_IMM8:      ;
`ifdef SUPPORT_SHIFT
`ifdef SUPPORT_SHIFT
                `ASL_IMM8:      begin Rt <= ir[15:12]; b <= ir[20:16]; state <= CALC; end
                `ASL_IMM8:      begin Rt <= ir[15:12]; b <= ir[20:16]; state <= CALC; end
                `LSR_IMM8:      begin Rt <= ir[15:12]; b <= ir[20:16]; state <= CALC; end
                `LSR_IMM8:      begin Rt <= ir[15:12]; b <= ir[20:16]; state <= CALC; end
`endif
`endif
 
 
                `ADD_IMM16:     begin Rt <= ir[15:12]; a <= rfoa; b <= {{16{ir[31]}},ir[31:16]}; end
                `ADD_IMM16:     begin Rt <= ir[15:12]; a <= rfoa; b <= {{16{ir[31]}},ir[31:16]}; end
                `SUB_IMM16:     begin Rt <= ir[15:12]; a <= rfoa; b <= {{16{ir[31]}},ir[31:16]}; end
                `SUB_IMM16:     begin Rt <= ir[15:12]; a <= rfoa; b <= {{16{ir[31]}},ir[31:16]}; end
                `MUL_IMM16:     begin Rt <= ir[15:12]; b <= {{16{ir[31]}},ir[31:16]}; state <= MULDIV1; end
                `MUL_IMM16:     begin Rt <= ir[15:12]; b <= {{16{ir[31]}},ir[31:16]}; state <= MULDIV1; end
`ifdef SUPPORT_DIVMOD
`ifdef SUPPORT_DIVMOD
                `DIV_IMM16:     begin Rt <= ir[15:12]; b <= {{16{ir[31]}},ir[31:16]}; state <= MULDIV1; end
                `DIV_IMM16:     begin Rt <= ir[15:12]; b <= {{16{ir[31]}},ir[31:16]}; state <= MULDIV1; end
                `MOD_IMM16:     begin Rt <= ir[15:12]; b <= {{16{ir[31]}},ir[31:16]}; state <= MULDIV1; end
                `MOD_IMM16:     begin Rt <= ir[15:12]; b <= {{16{ir[31]}},ir[31:16]}; state <= MULDIV1; end
`endif
`endif
                `OR_IMM16:      begin Rt <= ir[15:12]; end
                `OR_IMM16:      begin Rt <= ir[15:12]; end
                `AND_IMM16:     begin Rt <= ir[15:12]; b <= {{16{ir[31]}},ir[31:16]}; end
                `AND_IMM16:     begin Rt <= ir[15:12]; b <= {{16{ir[31]}},ir[31:16]}; end
                `EOR_IMM16:     begin Rt <= ir[15:12]; end
                `EOR_IMM16:     begin Rt <= ir[15:12]; end
 
 
                `ADD_IMM32:     begin Rt <= ir[15:12]; b <= ir[47:16]; end
                `ADD_IMM32:     begin Rt <= ir[15:12]; b <= ir[47:16]; end
                `SUB_IMM32:     begin Rt <= ir[15:12]; b <= ir[47:16]; end
                `SUB_IMM32:     begin Rt <= ir[15:12]; b <= ir[47:16]; end
                `MUL_IMM16:     begin Rt <= ir[15:12]; b <= ir[47:16]; state <= MULDIV1; end
                `MUL_IMM16:     begin Rt <= ir[15:12]; b <= ir[47:16]; state <= MULDIV1; end
`ifdef SUPPORT_DIVMOD
`ifdef SUPPORT_DIVMOD
                `DIV_IMM32:     begin Rt <= ir[15:12]; b <= ir[47:16]; state <= MULDIV1; end
                `DIV_IMM32:     begin Rt <= ir[15:12]; b <= ir[47:16]; state <= MULDIV1; end
                `MOD_IMM32:     begin Rt <= ir[15:12]; b <= ir[47:16]; state <= MULDIV1; end
                `MOD_IMM32:     begin Rt <= ir[15:12]; b <= ir[47:16]; state <= MULDIV1; end
`endif
`endif
                `OR_IMM32:      begin Rt <= ir[15:12]; end
                `OR_IMM32:      begin Rt <= ir[15:12]; end
                `AND_IMM32:     begin Rt <= ir[15:12]; b <= ir[47:16]; end
                `AND_IMM32:     begin Rt <= ir[15:12]; b <= ir[47:16]; end
                `EOR_IMM32:     begin Rt <= ir[15:12]; end
                `EOR_IMM32:     begin Rt <= ir[15:12]; end
 
 
                `LDA_IMM32:     Rt <= 4'd1;
                `LDA_IMM32:     Rt <= 4'd1;
                `LDX_IMM32:     Rt <= 4'd2;
                `LDX_IMM32:     Rt <= 4'd2;
                `LDY_IMM32: Rt <= 4'd3;
                `LDY_IMM32: Rt <= 4'd3;
                `LDA_IMM16:     Rt <= 4'd1;
                `LDA_IMM16:     Rt <= 4'd1;
                `LDX_IMM16: Rt <= 4'd2;
                `LDX_IMM16: Rt <= 4'd2;
                `LDA_IMM8: Rt <= 4'd1;
                `LDA_IMM8: Rt <= 4'd1;
                `LDX_IMM8: Rt <= 4'd2;
                `LDX_IMM8: Rt <= 4'd2;
 
 
                `SUB_SP8:       ;
                `SUB_SP8:       ;
                `SUB_SP16:      ;
                `SUB_SP16:      ;
                `SUB_SP32:      ;
                `SUB_SP32:      ;
 
 
                `CPX_IMM32:     ;
                `CPX_IMM32:     ;
                `CPY_IMM32:     ;
                `CPY_IMM32:     ;
 
 
                `LDX_ZPX:
                `LDX_ZPX:
                        begin
                        begin
                                Rt <= 4'd2;
                                Rt <= 4'd2;
                                radr <= zpx32xy_address;
                                radr <= zpx32xy_address;
                                load_what <= `WORD_311;
                                load_what <= `WORD_311;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
                `LDY_ZPX:
                `LDY_ZPX:
                        begin
                        begin
                                Rt <= 4'd3;
                                Rt <= 4'd3;
                                radr <= zpx32xy_address;
                                radr <= zpx32xy_address;
                                load_what <= `WORD_311;
                                load_what <= `WORD_311;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
                `ORB_ZPX:
                `ORB_ZPX:
                        begin
                        begin
                                Rt <= ir[19:16];
                                Rt <= ir[19:16];
                                radr <= zpx32_address[31:2];
                                radr <= zpx32_address[31:2];
                                radr2LSB <= zpx32_address[1:0];
                                radr2LSB <= zpx32_address[1:0];
                                load_what <= `WORD_310;
                                load_what <= `WORD_310;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
                `LDX_ABS:
                `LDX_ABS:
                        begin
                        begin
                                Rt <= 4'd2;
                                Rt <= 4'd2;
                                radr <= ir[39:8];
                                radr <= ir[39:8];
                                load_what <= `WORD_311;
                                load_what <= `WORD_311;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
                `LDY_ABS:
                `LDY_ABS:
                        begin
                        begin
                                Rt <= 4'd3;
                                Rt <= 4'd3;
                                radr <= ir[39:8];
                                radr <= ir[39:8];
                                load_what <= `WORD_311;
                                load_what <= `WORD_311;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
                `ORB_ABS:
                `ORB_ABS:
                        begin
                        begin
                                Rt <= ir[15:12];
                                Rt <= ir[15:12];
                                radr <= ir[47:18];
                                radr <= ir[47:18];
                                radr2LSB <= ir[17:16];
                                radr2LSB <= ir[17:16];
                                load_what <= `WORD_310;
                                load_what <= `WORD_310;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
                `LDX_ABSY:
                `LDX_ABSY:
                        begin
                        begin
                                Rt <= 4'd2;
                                Rt <= 4'd2;
                                radr <= absx32xy_address;
                                radr <= absx32xy_address;
                                load_what <= `WORD_311;
                                load_what <= `WORD_311;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
                `LDY_ABSX:
                `LDY_ABSX:
                        begin
                        begin
                                Rt <= 4'd3;
                                Rt <= 4'd3;
                                radr <= absx32xy_address;
                                radr <= absx32xy_address;
                                load_what <= `WORD_311;
                                load_what <= `WORD_311;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
                `ORB_ABSX:
                `ORB_ABSX:
                        begin
                        begin
                                Rt <= ir[19:16];
                                Rt <= ir[19:16];
                                radr <= absx32_address[31:2];
                                radr <= absx32_address[31:2];
                                radr2LSB <= absx32_address[1:0];
                                radr2LSB <= absx32_address[1:0];
                                load_what <= `WORD_310;
                                load_what <= `WORD_310;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
                `ST_ZPX:
                `ST_ZPX:
                        begin
                        begin
                                wadr <= zpx32_address;
                                wadr <= zpx32_address;
                                store_what <= `STW_RFA;
                                store_what <= `STW_RFA;
                                state <= STORE1;
                                state <= STORE1;
                        end
                        end
                `STB_ZPX:
                `STB_ZPX:
                        begin
                        begin
                                wadr <= zpx32_address[31:2];
                                wadr <= zpx32_address[31:2];
                                wadr2LSB <= zpx32_address[1:0];
                                wadr2LSB <= zpx32_address[1:0];
                                store_what <= `STW_RFA8;
                                store_what <= `STW_RFA8;
                                state <= STORE1;
                                state <= STORE1;
                        end
                        end
                `ST_DSP:
                `ST_DSP:
                        begin
                        begin
                                wadr <= {{24{ir[23]}},ir[23:16]} + isp;
                                wadr <= {24'b0,ir[23:16]} + isp;
                                store_what <= `STW_RFA;
                                store_what <= `STW_RFA;
                                state <= STORE1;
                                state <= STORE1;
                        end
                        end
                `ST_ABS:
                `ST_ABS:
                        begin
                        begin
                                wadr <= ir[47:16];
                                wadr <= ir[47:16];
                                store_what <= `STW_RFA;
                                store_what <= `STW_RFA;
                                state <= STORE1;
                                state <= STORE1;
                        end
                        end
                `STB_ABS:
                `STB_ABS:
                        begin
                        begin
                                wadr <= ir[47:18];
                                wadr <= ir[47:18];
                                wadr2LSB <= ir[17:16];
                                wadr2LSB <= ir[17:16];
                                store_what <= `STW_RFA8;
                                store_what <= `STW_RFA8;
                                state <= STORE1;
                                state <= STORE1;
                        end
                        end
                `ST_ABSX:
                `ST_ABSX:
                        begin
                        begin
                                wadr <= absx32_address;
                                wadr <= absx32_address;
                                store_what <= `STW_RFA;
                                store_what <= `STW_RFA;
                                state <= STORE1;
                                state <= STORE1;
                        end
                        end
                `STB_ABSX:
                `STB_ABSX:
                        begin
                        begin
                                wadr <= absx32_address[31:2];
                                wadr <= absx32_address[31:2];
                                wadr2LSB <= absx32_address[1:0];
                                wadr2LSB <= absx32_address[1:0];
                                store_what <= `STW_RFA8;
                                store_what <= `STW_RFA8;
                                state <= STORE1;
                                state <= STORE1;
                        end
                        end
                `STX_ZPX:
                `STX_ZPX:
                        begin
                        begin
                                wadr <= zpx32xy_address;
                                wadr <= zpx32xy_address;
                                store_what <= `STW_X;
                                store_what <= `STW_X;
                                state <= STORE1;
                                state <= STORE1;
                        end
                        end
                `STX_ABS:
                `STX_ABS:
                        begin
                        begin
                                wadr <= ir[39:8];
                                wadr <= ir[39:8];
                                store_what <= `STW_X;
                                store_what <= `STW_X;
                                state <= STORE1;
                                state <= STORE1;
                        end
                        end
                `STY_ZPX:
                `STY_ZPX:
                        begin
                        begin
                                wadr <= zpx32xy_address;
                                wadr <= zpx32xy_address;
                                store_what <= `STW_Y;
                                store_what <= `STW_Y;
                                state <= STORE1;
                                state <= STORE1;
                        end
                        end
                `STY_ABS:
                `STY_ABS:
                        begin
                        begin
                                wadr <= ir[39:8];
                                wadr <= ir[39:8];
                                store_what <= `STW_Y;
                                store_what <= `STW_Y;
                                state <= STORE1;
                                state <= STORE1;
                        end
                        end
                `ADD_ZPX,`SUB_ZPX,`AND_ZPX,`TRB_ZPX:
                `ADD_ZPX,`SUB_ZPX,`AND_ZPX,`TRB_ZPX:
                        begin
                        begin
                                Rt <= ir[19:16];
                                Rt <= ir[19:16];
                                radr <= zpx32_address;
                                radr <= zpx32_address;
                                load_what <= `WORD_310;
                                load_what <= `WORD_310;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
                `LEA_ZPX:
                `LEA_ZPX:
                        begin
                        begin
                                Rt <= ir[19:16];
                                Rt <= ir[19:16];
                                res <= zpx32_address;
                                res <= zpx32_address;
                                state <= IFETCH;
                                state <= IFETCH;
                        end
                        end
                // Trim a clock cycle off of loads by testing for Ra = 0.
                // Trim a clock cycle off of loads by testing for Ra = 0.
                `OR_ZPX,`EOR_ZPX,`TSB_ZPX:
                `OR_ZPX,`EOR_ZPX,`TSB_ZPX:
                        begin
                        begin
                                Rt <= ir[19:16];
                                Rt <= ir[19:16];
                                radr <= zpx32_address;
                                radr <= zpx32_address;
                                load_what <= (Ra==4'd0) ? `WORD_311: `WORD_310;
                                load_what <= (Ra==4'd0) ? `WORD_311: `WORD_310;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
                `ASL_ZPX,`ROL_ZPX,`LSR_ZPX,`ROR_ZPX,`INC_ZPX,`DEC_ZPX:
                `ASL_ZPX,`ROL_ZPX,`LSR_ZPX,`ROR_ZPX,`INC_ZPX,`DEC_ZPX:
                        begin
                        begin
                                radr <= zpx32xy_address;
                                radr <= zpx32xy_address;
                                load_what <= `WORD_310;
                                load_what <= `WORD_310;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
                `BMS_ZPX,`BMC_ZPX,`BMF_ZPX,`BMT_ZPX:
                `BMS_ZPX,`BMC_ZPX,`BMF_ZPX,`BMT_ZPX:
                        begin
                        begin
                                radr <= zpx32xy_address + acc[31:5];
                                radr <= zpx32xy_address + acc[31:5];
                                load_what <= `WORD_310;
                                load_what <= `WORD_310;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
                `LEA_DSP:
                `LEA_DSP:
                        begin
                        begin
                                Rt <= ir[15:12];
                                Rt <= ir[15:12];
                                res <= {{24{ir[23]}},ir[23:16]} + isp;
                                res <= {24'b0,ir[23:16]} + isp;
                                state <= IFETCH;
                                state <= IFETCH;
                        end
                        end
                `ADD_DSP,`SUB_DSP,`OR_DSP,`AND_DSP,`EOR_DSP:
                `ADD_DSP,`SUB_DSP,`OR_DSP,`AND_DSP,`EOR_DSP:
                        begin
                        begin
                                Rt <= ir[15:12];
                                Rt <= ir[15:12];
                                radr <= {{24{ir[23]}},ir[23:16]} + isp;
                                radr <= {24'b0,ir[23:16]} + isp;
                                load_what <= `WORD_310;
                                load_what <= `WORD_310;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
                `ADD_IX,`SUB_IX,`OR_IX,`AND_IX,`EOR_IX,`ST_IX,`LEA_IX:
                `ADD_IX,`SUB_IX,`OR_IX,`AND_IX,`EOR_IX,`ST_IX,`LEA_IX:
                        begin
                        begin
                                if (ir[7:0]!=`ST_IX)     // for ST_IX, Rt=0
                                if (ir[7:0]!=`ST_IX)     // for ST_IX, Rt=0
                                        Rt <= ir[19:16];
                                        Rt <= ir[19:16];
                                radr <= zpx32_address;
                                radr <= zpx32_address;
                                load_what <= `IA_310;
                                load_what <= `IA_310;
                                store_what <= `STW_A;
                                store_what <= `STW_A;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
                `LEA_RIND:
                `LEA_RIND:
                        begin
                        begin
                                Rt <= ir[19:16];
                                Rt <= ir[19:16];
                                res <= rfob;
                                res <= rfob;
                                state <= IFETCH;
                                state <= IFETCH;
                        end
                        end
                `ADD_RIND,`SUB_RIND,`OR_RIND,`AND_RIND,`EOR_RIND:
                `ADD_RIND,`SUB_RIND,`OR_RIND,`AND_RIND,`EOR_RIND:
                        begin
                        begin
                                radr <= rfob;
                                radr <= rfob;
                                Rt <= ir[19:16];
                                Rt <= ir[19:16];
                                load_what <= `WORD_310;
                                load_what <= `WORD_310;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
                `ST_RIND:
                `ST_RIND:
                        begin
                        begin
                                wadr <= rfob;
                                wadr <= rfob;
                                store_what <= `STW_RFA;
                                store_what <= `STW_RFA;
                                state <= STORE1;
                                state <= STORE1;
                        end
                        end
                `ADD_IY,`SUB_IY,`OR_IY,`AND_IY,`EOR_IY,`ST_IY,`LEA_IY:
                `ADD_IY,`SUB_IY,`OR_IY,`AND_IY,`EOR_IY,`ST_IY,`LEA_IY:
                        begin
                        begin
                                if (ir[7:0]!=`ST_IY)     // for ST_IY, Rt=0
                                if (ir[7:0]!=`ST_IY)     // for ST_IY, Rt=0
                                        Rt <= ir[19:16];
                                        Rt <= ir[19:16];
                                isIY <= 1'b1;
                                isIY <= 1'b1;
                                radr <= ir[31:20];
                                radr <= ir[31:20];
                                load_what <= `IA_310;
                                load_what <= `IA_310;
                                store_what <= `STW_A;
                                store_what <= `STW_A;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
                `LEA_ABS:
                `LEA_ABS:
                        begin
                        begin
                                res <= ir[47:16];
                                res <= ir[47:16];
                                Rt <= ir[15:12];
                                Rt <= ir[15:12];
                                state <= IFETCH;
                                state <= IFETCH;
                        end
                        end
                `OR_ABS,`EOR_ABS,`TSB_ABS:
                `OR_ABS,`EOR_ABS,`TSB_ABS:
                        begin
                        begin
                                radr <= ir[47:16];
                                radr <= ir[47:16];
                                Rt <= ir[15:12];
                                Rt <= ir[15:12];
                                load_what <= (Ra==4'd0) ? `WORD_311 : `WORD_310;
                                load_what <= (Ra==4'd0) ? `WORD_311 : `WORD_310;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
                `ADD_ABS,`SUB_ABS,`AND_ABS,`TRB_ABS:
                `ADD_ABS,`SUB_ABS,`AND_ABS,`TRB_ABS:
                        begin
                        begin
                                radr <= ir[47:16];
                                radr <= ir[47:16];
                                Rt <= ir[15:12];
                                Rt <= ir[15:12];
                                load_what <= `WORD_310;
                                load_what <= `WORD_310;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
                `ASL_ABS,`ROL_ABS,`LSR_ABS,`ROR_ABS,`INC_ABS,`DEC_ABS:
                `ASL_ABS,`ROL_ABS,`LSR_ABS,`ROR_ABS,`INC_ABS,`DEC_ABS:
                        begin
                        begin
                                radr <= ir[39:8];
                                radr <= ir[39:8];
                                load_what <= `WORD_310;
                                load_what <= `WORD_310;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
 
                `SPL_ABS:
 
                        begin
 
                                Rt <= 4'h0;
 
                                radr <= ir[39:8];
 
                                load_what <= `WORD_310;
 
                                state <= LOAD_MAC1;
 
                        end
                `BMS_ABS,`BMC_ABS,`BMF_ABS,`BMT_ABS:
                `BMS_ABS,`BMC_ABS,`BMF_ABS,`BMT_ABS:
                        begin
                        begin
                                radr <= ir[39:8] + acc[31:5];
                                radr <= ir[39:8] + acc[31:5];
                                load_what <= `WORD_310;
                                load_what <= `WORD_310;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
                `LEA_ABSX:
                `LEA_ABSX:
                        begin
                        begin
                                res <= absx32_address;
                                res <= absx32_address;
                                Rt <= ir[19:16];
                                Rt <= ir[19:16];
                                state <= IFETCH;
                                state <= IFETCH;
                        end
                        end
                `ADD_ABSX,`SUB_ABSX,`AND_ABSX:
                `ADD_ABSX,`SUB_ABSX,`AND_ABSX:
                        begin
                        begin
                                radr <= absx32_address;
                                radr <= absx32_address;
                                Rt <= ir[19:16];
                                Rt <= ir[19:16];
                                load_what <= `WORD_310;
                                load_what <= `WORD_310;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
                `OR_ABSX,`EOR_ABSX:
                `OR_ABSX,`EOR_ABSX:
                        begin
                        begin
                                radr <= absx32_address;
                                radr <= absx32_address;
                                Rt <= ir[19:16];
                                Rt <= ir[19:16];
                                load_what <= (Ra==4'd0) ? `WORD_311 : `WORD_310;
                                load_what <= (Ra==4'd0) ? `WORD_311 : `WORD_310;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
                `ASL_ABSX,`ROL_ABSX,`LSR_ABSX,`ROR_ABSX,`INC_ABSX,`DEC_ABSX:
                `ASL_ABSX,`ROL_ABSX,`LSR_ABSX,`ROR_ABSX,`INC_ABSX,`DEC_ABSX:
                        begin
                        begin
                                radr <= absx32xy_address;
                                radr <= absx32xy_address;
                                load_what <= `WORD_310;
                                load_what <= `WORD_310;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
                `BMS_ABSX,`BMC_ABSX,`BMF_ABSX,`BMT_ABSX:
                `BMS_ABSX,`BMC_ABSX,`BMF_ABSX,`BMT_ABSX:
                        begin
                        begin
                                radr <= absx32xy_address + acc[31:5];
                                radr <= absx32xy_address + acc[31:5];
                                load_what <= `WORD_310;
                                load_what <= `WORD_310;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
 
                `SPL_ABSX:
 
                        begin
 
                                Rt <= 4'h0;
 
                                radr <= absx32xy_address;
 
                                load_what <= `WORD_310;
 
                                state <= LOAD_MAC1;
 
                        end
 
 
                `CPX_ZPX:
                `CPX_ZPX:
                        begin
                        begin
                                radr <= zpx32xy_address;
                                radr <= zpx32xy_address;
                                load_what <= `WORD_310;
                                load_what <= `WORD_310;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
                `CPY_ZPX:
                `CPY_ZPX:
                        begin
                        begin
                                radr <= zpx32xy_address;
                                radr <= zpx32xy_address;
                                load_what <= `WORD_310;
                                load_what <= `WORD_310;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
                `CPX_ABS:
                `CPX_ABS:
                        begin
                        begin
                                radr <= ir[39:8];
                                radr <= ir[39:8];
                                load_what <= `WORD_310;
                                load_what <= `WORD_310;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
                `CPY_ABS:
                `CPY_ABS:
                        begin
                        begin
                                radr <= ir[39:8];
                                radr <= ir[39:8];
                                load_what <= `WORD_310;
                                load_what <= `WORD_310;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
                `BRK:
                `BRK:
                        begin
                        begin
                                bf <= !hwi;
                                bf <= !hwi;
                                km <= `TRUE;
                                km <= `TRUE;
`ifdef DEBUG
`ifdef DEBUG
                                hist_capture <= `FALSE;
                                hist_capture <= `FALSE;
`endif
`endif
                                radr <= isp_dec;
                                radr <= isp_dec;
                                wadr <= isp_dec;
                                wadr <= isp_dec;
                                isp <= isp_dec;
                                isp <= isp_dec;
                                store_what <= `STW_PCHWI;
                                store_what <= `STW_PCHWI;
                                state <= STORE1;
                                state <= STORE1;
                        end
                        end
                `INT0,`INT1:
                `INT0,`INT1:
                        begin
                        begin
                                pg2 <= `FALSE;
                                pg2 <= `FALSE;
                                ir <= {8{`BRK}};
                                ir <= {8{`BRK}};
                                vect <= {vbr[31:9],ir[15:7],2'b00};
                                vect <= {vbr[31:9],ir[0],ir[15:8],2'b00};
                                state <= DECODE;
                                state <= DECODE;
                        end
                        end
                `JMP:
                `JMP:
                        begin
                        begin
                                pc[15:0] <= ir[23:8];
                                pc[15:0] <= ir[23:8];
                                state <= IFETCH;
                                state <= IFETCH;
                        end
                        end
                `JML:
                `JML:
                        begin
                        begin
                                pc <= ir[39:8];
                                pc <= ir[39:8];
                                state <= IFETCH;
                                state <= IFETCH;
                        end
                        end
                `JMP_IND:
                `JMP_IND:
                        begin
                        begin
                                radr <= ir[39:8];
                                radr <= ir[39:8];
                                load_what <= `PC_310;
                                load_what <= `PC_310;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
                `JMP_INDX:
                `JMP_INDX:
                        begin
                        begin
                                radr <= ir[39:8] + x;
                                radr <= ir[39:8] + x;
                                load_what <= `PC_310;
                                load_what <= `PC_310;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
                `JMP_RIND:
                `JMP_RIND:
                        begin
                        begin
                                pc <= rfoa;
                                pc <= rfoa;
                                res <= pc + 32'd2;
                                res <= pc + 32'd2;
                                Rt <= ir[15:12];
                                Rt <= ir[15:12];
                                state <= IFETCH;
                                state <= IFETCH;
                        end
                        end
                `JSR:
                `JSR:
                        begin
                        begin
                                radr <= isp_dec;
                                radr <= isp_dec;
                                wadr <= isp_dec;
                                wadr <= isp_dec;
                                isp <= isp_dec;
                                isp <= isp_dec;
                                store_what <= `STW_DEF;
                                store_what <= `STW_DEF;
                                wdat <= pc+{31'd1,suppress_pcinc[0]};
                                wdat <= pc+{31'd1,suppress_pcinc[0]};
                                pc <= {pc[31:16],ir[23:8]};
                                pc <= {pc[31:16],ir[23:8]};
                                state <= STORE1;
                                state <= STORE1;
                        end
                        end
                `JSR_RIND:
                `JSR_RIND:
                        begin
                        begin
                                radr <= isp_dec;
                                radr <= isp_dec;
                                wadr <= isp_dec;
                                wadr <= isp_dec;
                                wdat <= pc + 32'd2;
                                wdat <= pc + 32'd2;
                                isp <= isp_dec;
                                isp <= isp_dec;
                                store_what <= `STW_DEF;
                                store_what <= `STW_DEF;
                                pc <= rfoa;
                                pc <= rfoa;
                                state <= STORE1;
                                state <= STORE1;
                        end
                        end
                `JSL,`JSR_INDX,`JSR_IND:
                `JSL,`JSR_INDX,`JSR_IND:
                        begin
                        begin
                                radr <= isp_dec;
                                radr <= isp_dec;
                                wadr <= isp_dec;
                                wadr <= isp_dec;
                                isp <= isp_dec;
                                isp <= isp_dec;
                                store_what <= `STW_DEF;
                                store_what <= `STW_DEF;
                                wdat <= suppress_pcinc[0] ? pc + 32'd5 : pc + 32'd2;
                                wdat <= suppress_pcinc[0] ? pc + 32'd5 : pc + 32'd2;
                                pc <= ir[39:8];         // This pc assignment will be overridden later by JSR_INDX
                                pc <= ir[39:8];         // This pc assignment will be overridden later by JSR_INDX
                                state <= STORE1;
                                state <= STORE1;
                        end
                        end
                `BSR:
                `BSR:
                        begin
                        begin
                                radr <= isp_dec;
                                radr <= isp_dec;
                                wadr <= isp_dec;
                                wadr <= isp_dec;
                                isp <= isp_dec;
                                isp <= isp_dec;
                                store_what <= `STW_DEF;
                                store_what <= `STW_DEF;
                                wdat <= pc+{31'd1,suppress_pcinc[0]};
                                wdat <= pc+{31'd1,suppress_pcinc[0]};
                                pc <= pc + {{16{ir[23]}},ir[23:8]};
                                pc <= pc + {{16{ir[23]}},ir[23:8]};
                                state <= STORE1;
                                state <= STORE1;
                        end
                        end
                `RTS,`RTL:
                `RTS,`RTL:
                                begin
                                begin
                                radr <= isp;
                                radr <= isp;
                                isp <= isp_inc;
                                isp <= isp_inc;
                                load_what <= `PC_310;
                                load_what <= `PC_310;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                                end
                                end
                `RTI:   begin
                `RTI:   begin
                                hist_capture <= `TRUE;
                                hist_capture <= `TRUE;
                                radr <= isp;
                                radr <= isp;
                                isp <= isp_inc;
                                isp <= isp_inc;
                                load_what <= `SR_310;
                                load_what <= `SR_310;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                                end
                                end
                `BEQ,`BNE,`BPL,`BMI,`BCC,`BCS,`BVC,`BVS,`BRA,
                `BEQ,`BNE,`BPL,`BMI,`BCC,`BCS,`BVC,`BVS,`BRA,
                `BGT,`BGE,`BLT,`BLE,`BHI,`BLS:
                `BGT,`BGE,`BLT,`BLE,`BHI,`BLS:
                        begin
                        begin
                                if (ir[15:8]==8'h00) begin
                                if (ir[15:8]==8'h00) begin
                                        pg2 <= `FALSE;
                                        pg2 <= `FALSE;
                                        ir <= {8{`BRK}};
                                        ir <= {8{`BRK}};
                                        pc <= pc;               // override the pc increment
                                        pc <= pc;               // override the pc increment
                                        vect <= {vbr[31:9],`SLP_VECTNO,2'b00};
                                        vect <= {vbr[31:9],`SLP_VECTNO,2'b00};
                                        state <= DECODE;
                                        state <= DECODE;
                                end
                                end
                                else if (ir[15:8]==8'h1) begin
                                else if (ir[15:8]==8'h1) begin
                                        if (takb)
                                        if (takb)
                                                pc <= pc + {{16{ir[31]}},ir[31:16]};
                                                pc <= pc + {{16{ir[31]}},ir[31:16]};
                                        else
                                        else
                                                pc <= pcp4;
                                                pc <= pcp4;
                                end
                                end
                                else begin
                                else begin
                                        if (takb)
                                        if (takb)
                                                pc <= pc + {{24{ir[15]}},ir[15:8]};
                                                pc <= pc + {{24{ir[15]}},ir[15:8]};
                                        else
                                        else
                                                pc <= pcp2;
                                                pc <= pcp2;
                                end
                                end
                        end
                        end
                `BRL:
                `BRL:
                        begin
                        begin
                                if (ir[23:8]==16'h0000) begin
                                if (ir[23:8]==16'h0000) begin
                                        pg2 <= `FALSE;
                                        pg2 <= `FALSE;
                                        ir <= {8{`BRK}};
                                        ir <= {8{`BRK}};
                                        vect <= {vbr[31:9],`SLP_VECTNO,2'b00};
                                        vect <= {vbr[31:9],`SLP_VECTNO,2'b00};
                                        pc <= pc;               // override the pc increment
                                        pc <= pc;               // override the pc increment
                                        state <= DECODE;
                                        state <= DECODE;
                                end
                                end
                                else begin
                                else begin
                                        pc <= pc + {{16{ir[23]}},ir[23:8]};
                                        pc <= pc + {{16{ir[23]}},ir[23:8]};
                                        state <= IFETCH;
                                        state <= IFETCH;
                                end
                                end
                        end
                        end
`ifdef SUPPORT_EXEC
`ifdef SUPPORT_EXEC
                `EXEC,`ATNI:
                `EXEC,`ATNI:
                        begin
                        begin
                                exbuf[31:0] <= rfoa;
                                exbuf[31:0] <= rfoa;
                                exbuf[63:32] <= rfob;
                                exbuf[63:32] <= rfob;
                        end
                        end
`endif
`endif
                `PHP:
                `PHP:
                        begin
                        begin
                                radr <= isp_dec;
                                radr <= isp_dec;
                                wadr <= isp_dec;
                                wadr <= isp_dec;
                                store_what <= `STW_SR;
                                store_what <= `STW_SR;
                                isp <= isp_dec;
                                isp <= isp_dec;
                                state <= STORE1;
                                state <= STORE1;
                        end
                        end
                `PHA:
                `PHA:
                        begin
                        begin
                                radr <= isp_dec;
                                radr <= isp_dec;
                                wadr <= isp_dec;
                                wadr <= isp_dec;
                                store_what <= `STW_ACC;
                                store_what <= `STW_ACC;
                                isp <= isp_dec;
                                isp <= isp_dec;
                                state <= STORE1;
                                state <= STORE1;
                        end
                        end
                `PHX:
                `PHX:
                        begin
                        begin
                                radr <= isp_dec;
                                radr <= isp_dec;
                                wadr <= isp_dec;
                                wadr <= isp_dec;
                                store_what <= `STW_X;
                                store_what <= `STW_X;
                                isp <= isp_dec;
                                isp <= isp_dec;
                                state <= STORE1;
                                state <= STORE1;
                        end
                        end
                `PHY:
                `PHY:
                        begin
                        begin
                                radr <= isp_dec;
                                radr <= isp_dec;
                                wadr <= isp_dec;
                                wadr <= isp_dec;
                                store_what <= `STW_Y;
                                store_what <= `STW_Y;
                                isp <= isp_dec;
                                isp <= isp_dec;
                                state <= STORE1;
                                state <= STORE1;
                        end
                        end
                `PUSH:
                `PUSH:
                        begin
                        begin
                                if (ir[15:12]==4'h0) begin
                                if (ir[15:12]==4'h0) begin
                                        radr <= isp_dec;
                                        radr <= isp_dec;
                                        wadr <= isp_dec;
                                        wadr <= isp_dec;
                                        isp <= isp_dec;
                                        isp <= isp_dec;
                                end
                                end
                                else begin
                                else begin
                                        radr <= rfob-32'd1;
                                        radr <= rfob-32'd1;
                                        wadr <= rfob-32'd1;
                                        wadr <= rfob-32'd1;
                                        wrrf <= 1'b1;
                                        wrrf <= 1'b1;
                                        Rt <= ir[15:12];
                                        Rt <= ir[15:12];
                                        res <= rfob-32'd1;
                                        res <= rfob-32'd1;
                                end
                                end
                                store_what <= `STW_A;
                                store_what <= `STW_A;
                                state <= STORE1;
                                state <= STORE1;
                        end
                        end
                `PUSHA:
                `PUSHA:
                        begin
                        begin
                                radr <= isp_dec;
                                radr <= isp_dec;
                                wadr <= isp_dec;
                                wadr <= isp_dec;
                                ir[11:8] <= 4'd1;
                                ir[11:8] <= 4'd1;
                                store_what <= `STW_RFA;
                                store_what <= `STW_RFA;
                                state <= STORE1;
                                state <= STORE1;
                                isp <= isp_dec;
                                isp <= isp_dec;
                        end
                        end
                `PLP:
                `PLP:
                        begin
                        begin
                                radr <= isp;
                                radr <= isp;
                                isp <= isp_inc;
                                isp <= isp_inc;
                                load_what <= `SR_310;
                                load_what <= `SR_310;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
                `PLA:
                `PLA:
                        begin
                        begin
                                Rt <= 4'd1;
                                Rt <= 4'd1;
                                radr <= isp;
                                radr <= isp;
                                isp <= isp_inc;
                                isp <= isp_inc;
                                load_what <= `WORD_311;
                                load_what <= `WORD_311;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
                `PLX:
                `PLX:
                        begin
                        begin
                                Rt <= 4'd2;
                                Rt <= 4'd2;
                                radr <= isp;
                                radr <= isp;
                                isp <= isp_inc;
                                isp <= isp_inc;
                                load_what <= `WORD_311;
                                load_what <= `WORD_311;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
                `PLY:
                `PLY:
                        begin
                        begin
                                Rt <= 4'd3;
                                Rt <= 4'd3;
                                radr <= isp;
                                radr <= isp;
                                isp <= isp_inc;
                                isp <= isp_inc;
                                load_what <= `WORD_311;
                                load_what <= `WORD_311;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
                `POP:
                `POP:
                        begin
                        begin
                                if (ir[11:8]!=4'h0) begin
                                if (ir[11:8]!=4'h0) begin
                                        Rt <= ir[11:8];
                                        Rt <= ir[11:8];
                                        res <= rfoa+32'd1;
                                        res <= rfoa+32'd1;
                                        wrrf <= 1'b1;
                                        wrrf <= 1'b1;
                                        radr <= rfoa;
                                        radr <= rfoa;
                                end
                                end
                                else begin
                                else begin
                                        radr <= isp;
                                        radr <= isp;
                                        isp <= isp_inc;
                                        isp <= isp_inc;
                                end
                                end
                                load_what <= `WORD_311;
                                load_what <= `WORD_311;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
                `POPA:
                `POPA:
                        begin
                        begin
                                Rt <= 4'd15;
                                Rt <= 4'd15;
                                radr <= isp;
                                radr <= isp;
                                isp <= isp_inc;
                                isp <= isp_inc;
                                load_what <= `WORD_311;
                                load_what <= `WORD_311;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
`ifdef SUPPORT_STRING
`ifdef SUPPORT_STRING
                `MVN:
                `MVN:
                        begin
                        begin
                                Rt <= 4'd3;
                                Rt <= 4'd3;
                                radr <= x;
                                radr <= x;
                                res <= x + 32'd1;
                                res <= x_inc;
                                load_what <= `WORD_312;
                                load_what <= `WORD_312;
 
                                pc <= pc;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
                `MVP:
                `MVP:
                        begin
                        begin
                                Rt <= 4'd3;
                                Rt <= 4'd3;
                                radr <= x;
                                radr <= x;
                                res <= x - 32'd1;
                                res <= x_dec;
                                load_what <= `WORD_312;
                                load_what <= `WORD_312;
 
                                pc <= pc;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
                `STS:
                `STS:
                        begin
                        begin
                                Rt <= 4'd3;
                                Rt <= 4'd3;
                                radr <= y;
                                radr <= y;
                                wadr <= y;
                                wadr <= y;
                                store_what <= `STW_X;
                                store_what <= `STW_X;
                                acc <= acc - 32'd1;
                                acc <= acc_dec;
 
                                pc <= pc;
                                state <= STORE1;
                                state <= STORE1;
                        end
                        end
                `CMPS:
                `CMPS:
                        begin
                        begin
                                Rt <= 4'd3;
                                Rt <= 4'd3;
                                radr <= x;
                                radr <= x;
                                res <= x + 32'd1;
                                res <= x_inc;
 
                                pc <= pc;
                                load_what <= `WORD_313;
                                load_what <= `WORD_313;
                                state <= LOAD_MAC1;
                                state <= LOAD_MAC1;
                        end
                        end
`endif
`endif
                `PG2:   begin
                `PG2:   begin
                                        pg2 <= `TRUE;
                                        pg2 <= `TRUE;
                                        ir <= ir[63:8];
                                        ir <= ir[63:8];
                                        state <= DECODE;
                                        state <= DECODE;
                                end
                                end
                default:        // unimplemented opcode
                default:        // unimplemented opcode
                        begin
                        begin
                                res <= 32'd0;
                                res <= 32'd0;
                                pg2 <= `FALSE;
                                pg2 <= `FALSE;
                                ir <= {8{`BRK}};
                                ir <= {8{`BRK}};
                                hwi <= `TRUE;
                                hwi <= `TRUE;
                                vect <= {vbr[31:9],9'd495,2'b00};
                                vect <= {vbr[31:9],9'd495,2'b00};
                                pc <= pc;               // override the pc increment
                                pc <= pc;               // override the pc increment
                                state <= DECODE;
                                state <= DECODE;
                        end
                        end
                endcase
                endcase
        end
        end
endtask
endtask
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.