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

Subversion Repositories t6507lp

[/] [t6507lp/] [trunk/] [rtl/] [verilog/] [t6507lp_fsm.v] - Diff between revs 146 and 194

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

Rev 146 Rev 194
Line 142... Line 142...
        reg pha;
        reg pha;
        reg php;
        reg php;
        reg pla;
        reg pla;
        reg plp;
        reg plp;
        reg jsr;
        reg jsr;
 
        reg tsx;
 
        reg txs;
 
 
        wire [ADDR_SIZE_:0] next_pc;      // a simple logic to add one to the PC
        wire [ADDR_SIZE_:0] next_pc;      // a simple logic to add one to the PC
        assign next_pc = pc + 13'b0000000000001;
        assign next_pc = pc + 13'b0000000000001;
 
 
        wire [8:0] sp_plus_one;          // simple adder and subtracter for the stack pointer
        wire [8:0] sp_plus_one;          // simple adder and subtracter for the stack pointer
Line 202... Line 204...
 
 
        always @ (posedge clk or negedge reset_n) begin // sequencial always block
        always @ (posedge clk or negedge reset_n) begin // sequencial always block
                if (reset_n == 1'b0) begin
                if (reset_n == 1'b0) begin
                        // all registers must assume default values
                        // all registers must assume default values
                        pc <= 0; // TODO: this is written somewhere. something about a reset vector. must be checked.
                        pc <= 0; // TODO: this is written somewhere. something about a reset vector. must be checked.
                        sp <= 9'b000000000; // the default is 'h100 
                        sp <= 9'b111111111; // the default is 'h1FF 
                        ir <= 8'h00;
                        ir <= 8'h00;
                        temp_addr <= 13'h0000;
                        temp_addr <= 13'h0000;
                        temp_data <= 8'h00;
                        temp_data <= 8'h00;
                        state <= RESET;
                        state <= RESET;
                        // registered outputs also receive default values
                        // registered outputs also receive default values
Line 219... Line 221...
                        state <= next_state;
                        state <= next_state;
 
 
                        case (state)
                        case (state)
                                RESET: begin    // The processor was reset
                                RESET: begin    // The processor was reset
                                        rst_counter <= rst_counter + 1;
                                        rst_counter <= rst_counter + 1;
                                        sp <= 9'b100000000; // this prevents flipflops with different drivers
                                        //sp <= 9'b111111111; // this prevents flipflops with different drivers
                                        //$write("under reset"); 
                                        //$write("under reset"); 
                                end
                                end
                                /*
                                /*
                                FETCH_OP: executed when the processor was reset or the last instruction could not fetch.
                                FETCH_OP: executed when the processor was reset or the last instruction could not fetch.
                                FETCH_OP_CALC_PARAM: enables the alu with an argument (alu_a) and fetchs the next instruction opcode. (pipelining)
                                FETCH_OP_CALC_PARAM: enables the alu with an argument (alu_a) and fetchs the next instruction opcode. (pipelining)
Line 241... Line 243...
                                FETCH_LOW: begin
                                FETCH_LOW: begin
                                        if (accumulator || implied) begin
                                        if (accumulator || implied) begin
                                                pc <= pc; // is this better?
                                                pc <= pc; // is this better?
                                                address <= pc;
                                                address <= pc;
                                                mem_rw <= MEM_READ;
                                                mem_rw <= MEM_READ;
 
 
 
                                                if (txs) begin
 
                                                        sp[7:0] <= data_in;
 
                                                end
 
                                                //alu_a
                                        end
                                        end
                                        else if (immediate || relative) begin
                                        else if (immediate || relative) begin
                                                pc <= next_pc;
                                                pc <= next_pc;
                                                address <= next_pc;
                                                address <= next_pc;
                                                mem_rw <= MEM_READ;
                                                mem_rw <= MEM_READ;
Line 600... Line 607...
                        FETCH_LOW: begin
                        FETCH_LOW: begin
                                if (accumulator  || implied) begin
                                if (accumulator  || implied) begin
                                        alu_opcode = ir;
                                        alu_opcode = ir;
                                        alu_enable = 1'b1;
                                        alu_enable = 1'b1;
                                        next_state = FETCH_OP;
                                        next_state = FETCH_OP;
 
 
 
                                        if (tsx) begin
 
                                                alu_a = sp[7:0];
 
                                        end
                                end
                                end
                                else if (immediate) begin
                                else if (immediate) begin
                                        next_state = FETCH_OP_CALC_PARAM;
                                        next_state = FETCH_OP_CALC_PARAM;
                                end
                                end
                                else if (zero_page) begin
                                else if (zero_page) begin
Line 878... Line 889...
                pha = 1'b0;
                pha = 1'b0;
                php = 1'b0;
                php = 1'b0;
                pla = 1'b0;
                pla = 1'b0;
                plp = 1'b0;
                plp = 1'b0;
                jsr = 1'b0;
                jsr = 1'b0;
 
                tsx = 1'b0;
 
                txs = 1'b0;
 
 
                case (ir)
                case (ir)
                        CLC_IMP, CLD_IMP, CLI_IMP, CLV_IMP, DEX_IMP, DEY_IMP, INX_IMP, INY_IMP, NOP_IMP,
                        CLC_IMP, CLD_IMP, CLI_IMP, CLV_IMP, DEX_IMP, DEY_IMP, INX_IMP, INY_IMP, NOP_IMP,
                        SEC_IMP, SED_IMP, SEI_IMP, TAX_IMP, TAY_IMP, TSX_IMP, TXA_IMP, TXS_IMP, TYA_IMP: begin
                        SEC_IMP, SED_IMP, SEI_IMP, TAX_IMP, TAY_IMP, TXA_IMP, TYA_IMP: begin
                                implied = 1'b1;
                                implied = 1'b1;
                        end
                        end
                        ASL_ACC, LSR_ACC, ROL_ACC, ROR_ACC: begin
                        ASL_ACC, LSR_ACC, ROL_ACC, ROR_ACC: begin
                                accumulator = 1'b1;
                                accumulator = 1'b1;
                        end
                        end
Line 1043... Line 1056...
                                plp = 1'b1;
                                plp = 1'b1;
                        end
                        end
                        JSR_ABS: begin
                        JSR_ABS: begin
                                jsr = 1'b1;
                                jsr = 1'b1;
                        end
                        end
 
                        TSX_IMP: begin
 
                                tsx = 1'b1;
 
                        end
 
                        TXS_IMP: begin
 
                                txs = 1'b1;
 
                        end
                        default: begin
                        default: begin
                                //$write("state : %b", state);
                                //$write("state : %b", state);
                                if (reset_n == 1'b1 && state != FETCH_OP_FIX_PC) begin // the processor is NOT being reset neither it is fixing the pc
                                if (reset_n == 1'b1 && state != FETCH_OP_FIX_PC) begin // the processor is NOT being reset neither it is fixing the pc
                                        //$write("\nunknown OPCODE!!!!! 0x%h\n", ir);
                                        //$write("\nunknown OPCODE!!!!! 0x%h\n", ir);
                                        //$finish();
                                        //$finish();

powered by: WebSVN 2.1.0

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