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

Subversion Repositories t6507lp

[/] [t6507lp/] [trunk/] [rtl/] [verilog/] [t6507lp_alu.v] - Diff between revs 184 and 186

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

Rev 184 Rev 186
Line 69... Line 69...
reg [7:0] bcdl;
reg [7:0] bcdl;
reg [7:0] bcdh;
reg [7:0] bcdh;
reg [7:0] bcdh2;
reg [7:0] bcdh2;
reg [7:0] AL;
reg [7:0] AL;
reg [7:0] AH;
reg [7:0] AH;
//reg C_aux;
reg C_aux;
reg sign;
reg sign;
 
 
`include "t6507lp_package.v"
`include "t6507lp_package.v"
 
 
always @ (posedge clk or negedge reset_n)
always @ (posedge clk or negedge reset_n)
Line 87... Line 87...
                alu_status[Z] <= 1;
                alu_status[Z] <= 1;
                alu_status[I] <= 0;
                alu_status[I] <= 0;
                alu_status[B] <= 0;
                alu_status[B] <= 0;
                alu_status[D] <= 0;
                alu_status[D] <= 0;
                A <= 0;
                A <= 0;
                //X <= 0;
 
                //Y <= 0;
 
                alu_x <= 0;
                alu_x <= 0;
                alu_y <= 0;
                alu_y <= 0;
        end
        end
        else if ( alu_enable == 1 ) begin
        else if ( alu_enable == 1 ) begin
                case (alu_opcode)
                case (alu_opcode)
Line 108... Line 106...
                                alu_result <= result;
                                alu_result <= result;
                                alu_status <= STATUS;
                                alu_status <= STATUS;
                        end
                        end
                        LDX_IMM, LDX_ZPG, LDX_ZPY, LDX_ABS, LDX_ABY, TAX_IMP, TSX_IMP, INX_IMP, DEX_IMP :
                        LDX_IMM, LDX_ZPG, LDX_ZPY, LDX_ABS, LDX_ABY, TAX_IMP, TSX_IMP, INX_IMP, DEX_IMP :
                        begin
                        begin
                                //X          <= result;
 
                                alu_x      <= result;
                                alu_x      <= result;
                                alu_status <= STATUS;
                                alu_status <= STATUS;
                        end
                        end
                        TXS_IMP :
                        TXS_IMP :
                        begin
                        begin
                                //X          <= result;
 
                                alu_x      <= result;
                                alu_x      <= result;
                        end
                        end
                        TXA_IMP, TYA_IMP :
                        TXA_IMP, TYA_IMP :
                        begin
                        begin
                                A          <= result;
                                A          <= result;
                                alu_status <= STATUS;
                                alu_status <= STATUS;
                        end
                        end
                        LDY_IMM, LDY_ZPG, LDY_ZPX, LDY_ABS, LDY_ABX, TAY_IMP, INY_IMP, DEY_IMP :
                        LDY_IMM, LDY_ZPG, LDY_ZPX, LDY_ABS, LDY_ABX, TAY_IMP, INY_IMP, DEY_IMP :
                        begin
                        begin
                                //Y          <= result;
 
                                alu_y      <= result;
                                alu_y      <= result;
                                alu_status <= STATUS;
                                alu_status <= STATUS;
                        end
                        end
                        CMP_IMM, CMP_ZPG, CMP_ZPX, CMP_ABS, CMP_ABX, CMP_ABY, CMP_IDX, CMP_IDY,
                        CMP_IMM, CMP_ZPG, CMP_ZPX, CMP_ABS, CMP_ABX, CMP_ABY, CMP_IDX, CMP_IDY,
                        CPX_IMM, CPX_ZPG, CPX_ABS, CPY_IMM, CPY_ZPG, CPY_ABS :
                        CPX_IMM, CPX_ZPG, CPX_ABS, CPY_IMM, CPY_ZPG, CPY_ABS :
Line 198... Line 193...
                        ROL_ZPG, ROL_ZPX, ROL_ABS, ROL_ABX, ROR_ZPG, ROR_ZPX, ROR_ABS, ROR_ABX :
                        ROL_ZPG, ROL_ZPX, ROL_ABS, ROL_ABX, ROR_ZPG, ROR_ZPX, ROR_ABS, ROR_ABX :
                        begin
                        begin
                                alu_result <= result;
                                alu_result <= result;
                                alu_status <= STATUS;
                                alu_status <= STATUS;
                        end
                        end
                        //PHP_IMP : begin
 
                        //end
 
                        default : begin
                        default : begin
                                //$display("ERROR");
 
                        end
                        end
                endcase
                endcase
        end
        end
end
end
 
 
always @ (*) begin
always @ (*) begin
if (alu_enable == 1) begin
if (alu_enable == 1) begin
        //op1      = A;
 
        op1      = A;
        op1      = A;
        op2      = alu_a;
        op2      = alu_a;
        result    = alu_result;
        result    = alu_result;
        STATUS[N] = alu_status[N];
        STATUS[N] = alu_status[N];
        STATUS[C] = alu_status[C];
        STATUS[C] = alu_status[C];
Line 232... Line 223...
        sign = op2[7];
        sign = op2[7];
 
 
        case (alu_opcode)
        case (alu_opcode)
                // BIT - Bit Test
                // BIT - Bit Test
                BIT_ZPG, BIT_ABS: begin
                BIT_ZPG, BIT_ABS: begin
                        //result = A & alu_a;
 
                        result = A & alu_a;
                        result = A & alu_a;
                end
                end
 
 
                // BRK - Force Interrupt
                // BRK - Force Interrupt
                //BRK_IMP: begin
                //BRK_IMP: begin
Line 281... Line 271...
                // STA - Store Accumulator
                // STA - Store Accumulator
                // PHA - Push A
                // PHA - Push A
                // TAX - Transfer Accumulator to X
                // TAX - Transfer Accumulator to X
                // TAY - Transfer Accumulator to Y
                // TAY - Transfer Accumulator to Y
                TAX_IMP, TAY_IMP, PHA_IMP, STA_ZPG, STA_ZPX, STA_ABS, STA_ABX, STA_ABY, STA_IDX, STA_IDY : begin
                TAX_IMP, TAY_IMP, PHA_IMP, STA_ZPG, STA_ZPX, STA_ABS, STA_ABX, STA_ABY, STA_IDX, STA_IDY : begin
                        //result = A;
 
                        result = A;
                        result = A;
                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 = X;
 
                        result = alu_x;
                        result = alu_x;
                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 = Y;
 
                        result = alu_y;
                        result = alu_y;
                end
                end
 
 
                // SEC - Set Carry Flag
                // SEC - Set Carry Flag
                //SEC_IMP: begin
                //SEC_IMP: begin
Line 322... Line 309...
                        result = alu_a + 1;
                        result = alu_a + 1;
                end
                end
 
 
                // INX - Increment X Register
                // INX - Increment X Register
                INX_IMP: begin
                INX_IMP: begin
                        //result = X + 1;
 
                        result = alu_x + 1;
                        result = alu_x + 1;
                end
                end
 
 
                // INY - Increment Y Register
                // INY - Increment Y Register
                INY_IMP : begin
                INY_IMP : begin
                        //result = Y + 1;
 
                        result = alu_y + 1;
                        result = alu_y + 1;
                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 = alu_a - 1;
                        result = alu_a - 1;
                end
                end
 
 
                // DEX - Decrement X register
                // DEX - Decrement X register
                DEX_IMP: begin
                DEX_IMP: begin
                        //result = X - 1;
 
                        result = alu_x - 1;
                        result = alu_x - 1;
                end
                end
 
 
                // DEY - Decrement Y Register
                // DEY - Decrement Y Register
                DEY_IMP: begin
                DEY_IMP: begin
                        //result = Y - 1;
 
                        result = alu_y - 1;
                        result = alu_y - 1;
                end
                end
 
 
                // ADC - Add with carry
                // ADC - Add with carry
                // TODO: verify synthesis for % operand
                // TODO: verify synthesis for % operand
                ADC_IMM, ADC_ZPG, ADC_ZPX, ADC_ABS, ADC_ABX, ADC_ABY, ADC_IDX, ADC_IDY : begin
                ADC_IMM, ADC_ZPG, ADC_ZPX, ADC_ABS, ADC_ABX, ADC_ABY, ADC_IDX, ADC_IDY : begin
                        if (alu_status[D] == 1) begin
                        if (alu_status[D] == 1) begin
                                //$display("MODO DECIMAL");
                                //$display("MODO DECIMAL");
                                //AL = A[3:0] + alu_a[3:0] + alu_status[C];
                                //AL = A[3:0] + alu_a[3:0] + alu_status[C];
                                AL = op1[3:0] + op2[3:0] + alu_status[C];
                                AL = op1[3:0] + op2[3:0] + alu_status[C];
 
                                //$display("op1[3:0] + op2[3:0] + alu_status[C]",op1[3:0], op2[3:0], alu_status[C]);
                                //AH = A[7:4] + alu_a[7:4];
                                //AH = A[7:4] + alu_a[7:4];
                                AH = op1[7:4] + op2[7:4];
                                AH = op1[7:4] + op2[7:4] + AL[4];
                                $display("AL = %d", AL);
                                //$display("op1[7:4] + op2[7:4] + AL[4]",op1[7:4], op2[7:4], AL[4]);
                                $display("AH = %d", AH);
                                if (AL > 9) bcdl = AL + 6;
                                if (AL > 9) begin
                                else bcdl = AL;
                                        bcdh = AH + (AL / 10);
                                STATUS[Z] =
                                        bcdl = AL % 10;
                                if (bcdh > 9)
                                end
                                        bcdh2 = bcdh + 6;
                                else begin
                                else bcdh2 = bcdh;
                                        bcdh = AH;
 
                                        bcdl = AL;
 
                                end
 
 
 
                                // ok
 
 
 
                                if (bcdh > 9) begin
 
                                        STATUS[C] = 1;
 
                                        bcdh2 = bcdh % 10;
 
                                end
 
                                else begin
 
                                        STATUS[C] = 0;
 
                                        bcdh2 = bcdh;
 
                                end
 
                                //$display("bcdh2 = %d", bcdh2);
                                //$display("bcdh2 = %d", bcdh2);
                                //$display("bcdl = %d", bcdl);
                                //$display("bcdl = %d", bcdl);
 
                                STATUS[C] = AH[4];
                                result = {bcdh2[3:0],bcdl[3:0]};
                                result = {bcdh2[3:0],bcdl[3:0]};
                        end
                        end
                        else begin
                        else begin
                                //$display("MODO NORMAL");
                                //$display("MODO NORMAL");
                                {STATUS[C],result} = op1 + op2 + alu_status[C];
                                {STATUS[C],result} = op1 + op2 + alu_status[C];
Line 396... Line 367...
                                STATUS[V] = 0;
                                STATUS[V] = 0;
                end
                end
 
 
                // AND - Logical AND
                // AND - Logical AND
                AND_IMM, AND_ZPG, AND_ZPX, AND_ABS, AND_ABX, AND_ABY, AND_IDX, AND_IDY : begin
                AND_IMM, AND_ZPG, AND_ZPX, AND_ABS, AND_ABX, AND_ABY, AND_IDX, AND_IDY : begin
                        //result = A & alu_a;
 
                        result = A & alu_a;
                        result = A & alu_a;
                end
                end
 
 
                // CMP - Compare
                // CMP - Compare
                CMP_IMM, CMP_ZPG, CMP_ZPX, CMP_ABS, CMP_ABX, CMP_ABY, CMP_IDX, CMP_IDY : begin
                CMP_IMM, CMP_ZPG, CMP_ZPX, CMP_ABS, CMP_ABX, CMP_ABY, CMP_IDX, CMP_IDY : begin
                        //result = A - alu_a;
 
                        result = A - alu_a;
                        result = A - alu_a;
                        //STATUS[C] = (A >= alu_a) ? 1 : 0;
 
                        STATUS[C] = (A >= alu_a) ? 1 : 0;
                        STATUS[C] = (A >= alu_a) ? 1 : 0;
                end
                end
 
 
                // EOR - Exclusive OR
                // EOR - Exclusive OR
                EOR_IMM, EOR_ZPG, EOR_ZPX, EOR_ABS, EOR_ABX, EOR_ABY, EOR_IDX, EOR_IDY : begin
                EOR_IMM, EOR_ZPG, EOR_ZPX, EOR_ABS, EOR_ABX, EOR_ABY, EOR_IDX, EOR_IDY : begin
                        result = A ^ alu_a;
                        result = A ^ alu_a;
                        //result = A ^ alu_a;
 
                        //$display("op1 ^ op2 = result");
 
                        //$display("%d  ^ %d  = %d", op1, op2, result);
 
                end
                end
 
 
                // LDA - Load Accumulator
                // LDA - Load Accumulator
                // LDX - Load X Register
                // LDX - Load X Register
                // LDY - Load Y Register
                // LDY - Load Y Register

powered by: WebSVN 2.1.0

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