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

Subversion Repositories t6507lp

[/] [t6507lp/] [trunk/] [rtl/] [verilog/] [t6507lp_alu.v] - Diff between revs 238 and 239

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 238 Rev 239
Line 217... Line 217...
        if (alu_enable == 1'b1) begin
        if (alu_enable == 1'b1) begin
                case (alu_opcode)
                case (alu_opcode)
                        // BIT - Bit Test
                        // BIT - Bit Test
                        BIT_ZPG, BIT_ABS: begin
                        BIT_ZPG, BIT_ABS: begin
                                result[7:0] = A & alu_a;
                                result[7:0] = A & alu_a;
                                STATUS[Z] = (result == 0) ? 1'b1 : 1'b0;
                                STATUS[Z] = (result[7:0] == 0) ? 1'b1 : 1'b0;
                                STATUS[N] = result[7];
                                STATUS[N] = result[7];
                        end
                        end
 
 
                        // PLA - Pull Accumulator
                        // PLA - Pull Accumulator
                        PLA_IMP : begin
                        PLA_IMP : begin
                                result[7:0] = alu_a;
                                result[7:0] = alu_a;
                                STATUS[Z] = (result == 0) ? 1'b1 : 1'b0;
                                STATUS[Z] = (result[7:0] == 0) ? 1'b1 : 1'b0;
                                STATUS[N] = result[7];
                                STATUS[N] = result[7];
                        end
                        end
 
 
                        // TAX - Transfer Accumulator to X
                        // TAX - Transfer Accumulator to X
                        // TAY - Transfer Accumulator to Y
                        // TAY - Transfer Accumulator to Y
                        // PHA - Push Accumulator
                        // PHA - Push Accumulator
                        // STA - Store Accumulator
                        // STA - Store Accumulator
                        TAX_IMP, TAY_IMP, PHA_IMP, STA_ZPG, STA_ZPX, STA_ABS, STA_ABX,
                        TAX_IMP, TAY_IMP, PHA_IMP, STA_ZPG, STA_ZPX, STA_ABS, STA_ABX,
                        STA_ABY, STA_IDX, STA_IDY : begin
                        STA_ABY, STA_IDX, STA_IDY : begin
                                result[7:0] = A;
                                result[7:0] = A;
                                STATUS[Z] = (result == 0) ? 1'b1 : 1'b0;
                                STATUS[Z] = (result[7:0] == 0) ? 1'b1 : 1'b0;
                                STATUS[N] = result[7];
                                STATUS[N] = result[7];
                        end
                        end
 
 
                        // STX - Store X Register
                        // STX - Store X Register
                        // TXA - Transfer X to Accumulator
                        // TXA - Transfer X to Accumulator
                        // TXS - Transfer X to Stack pointer
                        // TXS - Transfer X to Stack pointer
                        STX_ZPG, STX_ZPY, STX_ABS, TXA_IMP, TXS_IMP : begin
                        STX_ZPG, STX_ZPY, STX_ABS, TXA_IMP, TXS_IMP : begin
                                result[7:0] = alu_x;
                                result[7:0] = alu_x;
                                STATUS[Z] = (result == 0) ? 1'b1 : 1'b0;
                                STATUS[Z] = (result[7:0] == 0) ? 1'b1 : 1'b0;
                                STATUS[N] = result[7];
                                STATUS[N] = result[7];
                        end
                        end
 
 
                        // STY - Store Y Register
                        // STY - Store Y Register
                        // TYA - Transfer Y to Accumulator
                        // TYA - Transfer Y to Accumulator
                        STY_ZPG, STY_ZPX, STY_ABS, TYA_IMP : begin
                        STY_ZPG, STY_ZPX, STY_ABS, TYA_IMP : begin
                                result[7:0] = alu_y;
                                result[7:0] = alu_y;
                                STATUS[Z] = (result == 0) ? 1'b1 : 1'b0;
                                STATUS[Z] = (result[7:0] == 0) ? 1'b1 : 1'b0;
                                STATUS[N] = result[7];
                                STATUS[N] = result[7];
                        end
                        end
 
 
                        // INC - Increment memory
                        // INC - Increment memory
                        INC_ZPG, INC_ZPX, INC_ABS, INC_ABX : begin
                        INC_ZPG, INC_ZPX, INC_ABS, INC_ABX : begin
                                result[7:0] = alu_a + 8'd1;
                                result[7:0] = alu_a + 8'd1;
                                STATUS[Z] = (result == 0) ? 1'b1 : 1'b0;
                                STATUS[Z] = (result[7:0] == 0) ? 1'b1 : 1'b0;
                                STATUS[N] = result[7];
                                STATUS[N] = result[7];
                        end
                        end
 
 
                        // INX - Increment X Register
                        // INX - Increment X Register
                        INX_IMP: begin
                        INX_IMP: begin
                                result[7:0] = alu_x + 8'd1;
                                result[7:0] = alu_x + 8'd1;
                                STATUS[Z] = (result == 0) ? 1'b1 : 1'b0;
                                STATUS[Z] = (result[7:0] == 0) ? 1'b1 : 1'b0;
                                STATUS[N] = result[7];
                                STATUS[N] = result[7];
                        end
                        end
 
 
                        // INY - Increment Y Register
                        // INY - Increment Y Register
                        INY_IMP : begin
                        INY_IMP : begin
                                result[7:0] = alu_y + 8'd1;
                                result[7:0] = alu_y + 8'd1;
                                STATUS[Z] = (result == 0) ? 1'b1 : 1'b0;
                                STATUS[Z] = (result[7:0] == 0) ? 1'b1 : 1'b0;
                                STATUS[N] = result[7];
                                STATUS[N] = result[7];
                        end
                        end
 
 
                        // DEC - Decrement memory
                        // DEC - Decrement memory
                        DEC_ZPG, DEC_ZPX, DEC_ABS, DEC_ABX : begin
                        DEC_ZPG, DEC_ZPX, DEC_ABS, DEC_ABX : begin
                                result[7:0] = alu_a - 8'd1;
                                result[7:0] = alu_a - 8'd1;
                                STATUS[Z] = (result == 0) ? 1'b1 : 1'b0;
                                STATUS[Z] = (result[7:0] == 0) ? 1'b1 : 1'b0;
                                STATUS[N] = result[7];
                                STATUS[N] = result[7];
                        end
                        end
 
 
                        // DEX - Decrement X register
                        // DEX - Decrement X register
                        DEX_IMP: begin
                        DEX_IMP: begin
                                result[7:0] = alu_x - 8'd1;
                                result[7:0] = alu_x - 8'd1;
                                STATUS[Z] = (result == 0) ? 1'b1 : 1'b0;
                                STATUS[Z] = (result[7:0] == 0) ? 1'b1 : 1'b0;
                                STATUS[N] = result[7];
                                STATUS[N] = result[7];
                        end
                        end
 
 
                        // DEY - Decrement Y Register
                        // DEY - Decrement Y Register
                        DEY_IMP: begin
                        DEY_IMP: begin
                                result[7:0] = alu_y - 8'd1;
                                result[7:0] = alu_y - 8'd1;
                                STATUS[Z] = (result == 0) ? 1'b1 : 1'b0;
                                STATUS[Z] = (result[7:0] == 0) ? 1'b1 : 1'b0;
                                STATUS[N] = result[7];
                                STATUS[N] = result[7];
                        end
                        end
 
 
                        // ADC - Add with carry
                        // ADC - Add with carry
                        ADC_IMM, ADC_ZPG, ADC_ZPX, ADC_ABS,
                        ADC_IMM, ADC_ZPG, ADC_ZPX, ADC_ABS,
                        ADC_ABX, ADC_ABY, ADC_IDX, ADC_IDY : begin
                        ADC_ABX, ADC_ABY, ADC_IDX, ADC_IDY : begin
                                if (!alu_status[D]) begin
                                if (!alu_status[D]) begin
                                        result = op1 + op2 + {7'd0, alu_status[C]}; // this looks so ugly but the operands are all 8 bits now
                                        result = op1 + op2 + {7'd0, alu_status[C]}; // this looks so ugly but the operands are all 8 bits now
                                        STATUS[N] = result[7];
                                        STATUS[N] = result[7];
                                        STATUS[Z] = (result == 0) ? 1'b1 : 1'b0;
                                        STATUS[Z] = (result[7:0] == 0) ? 1'b1 : 1'b0;
                                        STATUS[V] = ((op1[7] == op2[7]) && (op1[7] != result[7])) ? 1'b1 : 1'b0;
                                        STATUS[V] = ((op1[7] == op2[7]) && (op1[7] != result[7])) ? 1'b1 : 1'b0;
                                        STATUS[C] = result[8];
                                        STATUS[C] = result[8];
                                end
                                end
                                else begin
                                else begin
                                        AL = op1[3:0] + op2[3:0] + {7'd0, alu_status[C]};
                                        AL = op1[3:0] + op2[3:0] + {7'd0, alu_status[C]};
Line 337... Line 337...
 
 
                        // AND - Logical AND
                        // AND - Logical AND
                        AND_IMM, AND_ZPG, AND_ZPX, AND_ABS, AND_ABX, AND_ABY, AND_IDX,
                        AND_IMM, AND_ZPG, AND_ZPX, AND_ABS, AND_ABX, AND_ABY, AND_IDX,
                        AND_IDY : begin
                        AND_IDY : begin
                                result[7:0] = A & alu_a;
                                result[7:0] = A & alu_a;
                                STATUS[Z] = (result == 0) ? 1'b1 : 1'b0;
                                STATUS[Z] = (result[7:0] == 0) ? 1'b1 : 1'b0;
                                STATUS[N] = result[7];
                                STATUS[N] = result[7];
                        end
                        end
 
 
                        // CMP - Compare
                        // CMP - Compare
                        CMP_IMM, CMP_ZPG, CMP_ZPX, CMP_ABS, CMP_ABX, CMP_ABY, CMP_IDX,
                        CMP_IMM, CMP_ZPG, CMP_ZPX, CMP_ABS, CMP_ABX, CMP_ABY, CMP_IDX,
                        CMP_IDY : begin
                        CMP_IDY : begin
                                result[7:0] = A - alu_a;
                                result[7:0] = A - alu_a;
                                STATUS[C] = (A >= alu_a) ? 1'b1 : 1'b0;
                                STATUS[C] = (A >= alu_a) ? 1'b1 : 1'b0;
                                STATUS[Z] = (result == 0) ? 1'b1 : 1'b0;
                                STATUS[Z] = (result[7:0] == 0) ? 1'b1 : 1'b0;
                                STATUS[N] = result[7];
                                STATUS[N] = result[7];
                        end
                        end
 
 
                        // EOR - Exclusive OR
                        // EOR - Exclusive OR
                        EOR_IMM, EOR_ZPG, EOR_ZPX, EOR_ABS, EOR_ABX, EOR_ABY,
                        EOR_IMM, EOR_ZPG, EOR_ZPX, EOR_ABS, EOR_ABX, EOR_ABY,
                        EOR_IDX, EOR_IDY : begin
                        EOR_IDX, EOR_IDY : begin
                                result[7:0] = A ^ alu_a;
                                result[7:0] = A ^ alu_a;
                                STATUS[Z] = (result == 0) ? 1'b1 : 1'b0;
                                STATUS[Z] = (result[7:0] == 0) ? 1'b1 : 1'b0;
                                STATUS[N] = result[7];
                                STATUS[N] = result[7];
                        end
                        end
 
 
                        // LDA - Load Accumulator
                        // LDA - Load Accumulator
                        // LDX - Load X Register
                        // LDX - Load X Register
Line 366... Line 366...
                        // TSX - Transfer Stack Pointer to X
                        // TSX - Transfer Stack Pointer to X
                        LDA_IMM, LDA_ZPG, LDA_ZPX, LDA_ABS, LDA_ABX, LDA_ABY, LDA_IDX,
                        LDA_IMM, LDA_ZPG, LDA_ZPX, LDA_ABS, LDA_ABX, LDA_ABY, LDA_IDX,
                        LDA_IDY, LDX_IMM, LDX_ZPG, LDX_ZPY, LDX_ABS, LDX_ABY, LDY_IMM,
                        LDA_IDY, LDX_IMM, LDX_ZPG, LDX_ZPY, LDX_ABS, LDX_ABY, LDY_IMM,
                        LDY_ZPG, LDY_ZPX, LDY_ABS, LDY_ABX, TSX_IMP : begin
                        LDY_ZPG, LDY_ZPX, LDY_ABS, LDY_ABX, TSX_IMP : begin
                                result[7:0] = alu_a;
                                result[7:0] = alu_a;
                                STATUS[Z] = (result == 0) ? 1'b1 : 1'b0;
                                STATUS[Z] = (result[7:0] == 0) ? 1'b1 : 1'b0;
                                STATUS[N] = result[7];
                                STATUS[N] = result[7];
                        end
                        end
 
 
                        // ORA - Logical OR
                        // ORA - Logical OR
                        ORA_IMM, ORA_ZPG, ORA_ZPX, ORA_ABS, ORA_ABX, ORA_ABY, ORA_IDX,
                        ORA_IMM, ORA_ZPG, ORA_ZPX, ORA_ABS, ORA_ABX, ORA_ABY, ORA_IDX,
                        ORA_IDY : begin
                        ORA_IDY : begin
                                result[7:0] = A | alu_a;
                                result[7:0] = A | alu_a;
                                STATUS[Z] = (result == 0) ? 1'b1 : 1'b0;
                                STATUS[Z] = (result[7:0] == 0) ? 1'b1 : 1'b0;
                                STATUS[N] = result[7];
                                STATUS[N] = result[7];
                        end
                        end
 
 
                        // SBC - Subtract with Carry
                        // SBC - Subtract with Carry
                        SBC_IMM, SBC_ZPG, SBC_ZPX, SBC_ABS, SBC_ABX, SBC_ABY, SBC_IDX,
                        SBC_IMM, SBC_ZPG, SBC_ZPX, SBC_ABS, SBC_ABX, SBC_ABY, SBC_IDX,
                        SBC_IDY : begin
                        SBC_IDY : begin
                                result = op1 - op2 - (1'b1 - alu_status[C]);
                                result = op1 - op2 - (1'b1 - alu_status[C]);
                                STATUS[N] = result[7];
                                STATUS[N] = result[7];
                                STATUS[V] = ((op1[7] ^ op2[7]) && (op1[7] ^ result[7])) ? 1'b1 : 1'b0;
                                STATUS[V] = ((op1[7] ^ op2[7]) && (op1[7] ^ result[7])) ? 1'b1 : 1'b0;
                                STATUS[Z] = (result == 0) ? 1'b1 : 1'b0;
                                STATUS[Z] = (result[7:0] == 0) ? 1'b1 : 1'b0;
                                STATUS[C] = ~(result[8] || result[9]);
                                STATUS[C] = ~(result[8] || result[9]);
                                if (alu_status[D]) begin
                                if (alu_status[D]) begin
                                        AL = op1[3:0] - op2[3:0] - (1'b1 - alu_status[C]);
                                        AL = op1[3:0] - op2[3:0] - (1'b1 - alu_status[C]);
                                        AH = op1[7:4] - op2[7:4];
                                        AH = op1[7:4] - op2[7:4];
                                        if (AL[4]) begin
                                        if (AL[4]) begin
Line 410... Line 410...
                        end
                        end
 
 
                        // ASL - Arithmetic Shift Left
                        // ASL - Arithmetic Shift Left
                        ASL_ACC : begin
                        ASL_ACC : begin
                                {STATUS[C],result[7:0]} = {A, 1'b0};
                                {STATUS[C],result[7:0]} = {A, 1'b0};
                                STATUS[Z] = (result == 0) ? 1'b1 : 1'b0;
                                STATUS[Z] = (result[7:0] == 0) ? 1'b1 : 1'b0;
                                STATUS[N] = result[7];
                                STATUS[N] = result[7];
                        end
                        end
                        ASL_ZPG, ASL_ZPX, ASL_ABS, ASL_ABX : begin
                        ASL_ZPG, ASL_ZPX, ASL_ABS, ASL_ABX : begin
                                {STATUS[C],result[7:0]} = {alu_a, 1'b0};
                                {STATUS[C],result[7:0]} = {alu_a, 1'b0};
                                STATUS[Z] = (result == 0) ? 1'b1 : 1'b0;
                                STATUS[Z] = (result[7:0] == 0) ? 1'b1 : 1'b0;
                                STATUS[N] = result[7];
                                STATUS[N] = result[7];
                        end
                        end
 
 
                        // LSR - Logical Shift Right
                        // LSR - Logical Shift Right
                        LSR_ACC: begin
                        LSR_ACC: begin
                                {result[7:0],STATUS[C]} = {1'b0,A};
                                {result[7:0],STATUS[C]} = {1'b0,A};
                                STATUS[Z] = (result == 0) ? 1'b1 : 1'b0;
                                STATUS[Z] = (result[7:0] == 0) ? 1'b1 : 1'b0;
                                STATUS[N] = result[7];
                                STATUS[N] = result[7];
                        end
                        end
                        LSR_ZPG, LSR_ZPX, LSR_ABS, LSR_ABX : begin
                        LSR_ZPG, LSR_ZPX, LSR_ABS, LSR_ABX : begin
                                {result[7:0],STATUS[C]} = {1'b0,alu_a};
                                {result[7:0],STATUS[C]} = {1'b0,alu_a};
                                STATUS[Z] = (result == 0) ? 1'b1 : 1'b0;
                                STATUS[Z] = (result[7:0] == 0) ? 1'b1 : 1'b0;
                                STATUS[N] = result[7];
                                STATUS[N] = result[7];
                        end
                        end
 
 
                        // ROL - Rotate Left
                        // ROL - Rotate Left
                        ROL_ACC : begin
                        ROL_ACC : begin
                                {STATUS[C],result[7:0]} = {A,alu_status[C]};
                                {STATUS[C],result[7:0]} = {A,alu_status[C]};
                                STATUS[Z] = (result == 0) ? 1'b1 : 1'b0;
                                STATUS[Z] = (result[7:0] == 0) ? 1'b1 : 1'b0;
                                STATUS[N] = result[7];
                                STATUS[N] = result[7];
                        end
                        end
                        ROL_ZPG, ROL_ZPX, ROL_ABS, ROL_ABX : begin
                        ROL_ZPG, ROL_ZPX, ROL_ABS, ROL_ABX : begin
                                {STATUS[C],result[7:0]} = {alu_a,alu_status[C]};
                                {STATUS[C],result[7:0]} = {alu_a,alu_status[C]};
                                STATUS[Z] = (result == 0) ? 1'b1 : 1'b0;
                                STATUS[Z] = (result[7:0] == 0) ? 1'b1 : 1'b0;
                                STATUS[N] = result[7];
                                STATUS[N] = result[7];
                        end
                        end
 
 
                        // ROR - Rotate Right
                        // ROR - Rotate Right
                        ROR_ACC : begin
                        ROR_ACC : begin
                                {result[7:0],STATUS[C]} = {alu_status[C],A};
                                {result[7:0],STATUS[C]} = {alu_status[C],A};
                                STATUS[Z] = (result == 0) ? 1'b1 : 1'b0;
                                STATUS[Z] = (result[7:0] == 0) ? 1'b1 : 1'b0;
                                STATUS[N] = result[7];
                                STATUS[N] = result[7];
                        end
                        end
                        ROR_ZPG, ROR_ZPX, ROR_ABS, ROR_ABX : begin
                        ROR_ZPG, ROR_ZPX, ROR_ABS, ROR_ABX : begin
                                {result[7:0], STATUS[C]} = {alu_status[C], alu_a};
                                {result[7:0], STATUS[C]} = {alu_status[C], alu_a};
                                STATUS[Z] = (result == 0) ? 1'b1 : 1'b0;
                                STATUS[Z] = (result[7:0] == 0) ? 1'b1 : 1'b0;
                                STATUS[N] = result[7];
                                STATUS[N] = result[7];
                        end
                        end
 
 
                        // CPX - Compare X Register
                        // CPX - Compare X Register
                        CPX_IMM, CPX_ZPG, CPX_ABS : begin
                        CPX_IMM, CPX_ZPG, CPX_ABS : begin
                                result[7:0] = alu_x - alu_a;
                                result[7:0] = alu_x - alu_a;
                                STATUS[C] = (alu_x >= alu_a) ? 1'b1 : 1'b0;
                                STATUS[C] = (alu_x >= alu_a) ? 1'b1 : 1'b0;
                                STATUS[Z] = (result == 0) ? 1'b1 : 1'b0;
                                STATUS[Z] = (result[7:0] == 0) ? 1'b1 : 1'b0;
                                STATUS[N] = result[7];
                                STATUS[N] = result[7];
                        end
                        end
 
 
                        // CPY - Compare Y Register
                        // CPY - Compare Y Register
                        CPY_IMM, CPY_ZPG, CPY_ABS : begin
                        CPY_IMM, CPY_ZPG, CPY_ABS : begin
                                result[7:0] = alu_y - alu_a;
                                result[7:0] = alu_y - alu_a;
                                STATUS[C] = (alu_y >= alu_a) ? 1'b1 : 1'b0;
                                STATUS[C] = (alu_y >= alu_a) ? 1'b1 : 1'b0;
                                STATUS[Z] = (result == 0) ? 1'b1 : 1'b0;
                                STATUS[Z] = (result[7:0] == 0) ? 1'b1 : 1'b0;
                                STATUS[N] = result[7];
                                STATUS[N] = result[7];
                        end
                        end
 
 
                        default: begin
                        default: begin
                                result = 10'h3FF;
                                result = 10'h3FF;

powered by: WebSVN 2.1.0

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