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

Subversion Repositories ag_6502

[/] [ag_6502/] [trunk/] [agat7/] [ag_6502.v] - Diff between revs 2 and 4

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

Rev 2 Rev 4
Line 3... Line 3...
// Company:   BMSTU
// Company:   BMSTU
// Engineer:  Oleg Odintsov
// Engineer:  Oleg Odintsov
// 
// 
// Create Date:    10:50:36 02/15/2012 
// Create Date:    10:50:36 02/15/2012 
// Design Name: 
// Design Name: 
// Module Name:    ag_6502 
// Module Name:    my6502 
// Project Name:    Agat Hardware Project
// Project Name:    Agat Hardware Project
// Target Devices: 
// Target Devices: 
// Tool versions: 
// Tool versions: 
// Description: 
// Description: 
//
//
// Dependencies: 
// Dependencies: 
//
//
// Revision: 
// Revision: 
// Revision 0.01 - File Created
// Revision 0.01 - File Created
 
// Revision 0.02 - Fixed NMI bug
// Additional Comments: 
// Additional Comments: 
//
//
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
 
 
 
 
Line 37... Line 38...
 
 
 
 
`else
`else
 
 
module ag6502_phase_shift(input baseclk, input phi_0, output reg phi_1);
module ag6502_phase_shift(input baseclk, input phi_0, output reg phi_1);
        parameter DELAY = 1; // delay in semi-waves of baseclk
        parameter DELAY = 1; // delay in waves of baseclk
        initial phi_1 = 0;
        initial phi_1 = 0;
        integer cnt = 0;
        integer cnt = 0;
 
 
        always @(posedge baseclk) begin
        always @(posedge baseclk) begin
                if (phi_0 != phi_1) begin
                if (phi_0 != phi_1) begin
                        if (!cnt) begin phi_1 <= ~phi_1; cnt <= DELAY; end
                        if (!cnt) begin phi_1 <= phi_0; cnt <= DELAY; end
                        else cnt <= cnt - 1;
                        else cnt <= cnt - 1;
                end
                end
        end
        end
endmodule
endmodule
 
 
// baseclk is used to simulate delays on a real hardware
// baseclk is used to simulate delays on a real hardware
module ag6502_ext_clock(input baseclk, input phi_0, output phi_1, output phi_2);
module ag6502_ext_clock(input baseclk, input phi_0, output phi_1, output phi_2);
        parameter DELAY1 = 3, DELAY2 = 1; // delays in semi-waves of baseclk
        parameter DELAY1 = 3, DELAY2 = 1; // delays in waves of baseclk
 
 
        wire phi_1_neg, phi_01;
        wire phi_1_neg, phi_01;
 
 
        ag6502_phase_shift#DELAY1 d1(baseclk, phi_0, phi_1_neg);
        ag6502_phase_shift#DELAY1 d1(baseclk, phi_0, phi_1_neg);
        assign phi_1 = ~phi_1_neg;
        assign phi_1 = ~phi_1_neg;
Line 143... Line 144...
`endif
`endif
 
 
        reg rdyg = 1;
        reg rdyg = 1;
 
 
        reg[2:0] T = 7;
        reg[2:0] T = 7;
        reg[7:0] IR ='h18;
        reg[7:0] IR ='h00;
 
 
        reg[15:0] PC = 0;
        reg[15:0] PC = 0;
        wire[7:0] PCH = PC[15:8], PCL = PC[7:0];
        wire[7:0] PCH = PC[15:8], PCL = PC[7:0];
        reg[7:0] EAL, EAH;
        reg[7:0] EAL, EAH;
        wire[15:0] EA = {EAH, EAL};
        wire[15:0] EA = {EAH, EAL};
Line 175... Line 176...
        wire nmi_active = ~nmi & nmi_prev;
        wire nmi_active = ~nmi & nmi_prev;
        wire int_active = irq_active | nmi_active;
        wire int_active = irq_active | nmi_active;
        wire rst_active = ~rst;
        wire rst_active = ~rst;
        wire so_active = so & ~so_prev;
        wire so_active = so & ~so_prev;
 
 
 
        wire[7:0] IR_in = int_active?8'b0:db_in;
 
 
        wire[1:0] vec_bits=
        wire[1:0] vec_bits=
                        nmi_active?2'b01:
                        nmi_active?2'b01:
                        rst_active?2'b10:
                        rst_active?2'b10:
                        2'b11;
                        2'b11;
 
 
        wire[15:0] vec_addr = {{13{1'b1}}, vec_bits, 1'b0};
        wire[15:0] vec_addr = {{13{1'b1}}, vec_bits, 1'b0};
 
 
        wire[7:0] IR_eff = int_active?8'b0:IR;
        wire[10:0] L = {T, IR};
 
 
        wire[10:0] L = {T, IR_eff};
 
 
 
        `include "states.v"
        `include "states.v"
 
 
        assign read = ~A_RW_W;
        assign read = ~A_RW_W;
        assign sync = !T;
        assign sync = !T;
Line 264... Line 265...
                        E_T__0IFZF__IR_5_?(FLAG_Z != IR[5]):
                        E_T__0IFZF__IR_5_?(FLAG_Z != IR[5]):
                        E_T__0IF_C7F? CF_OUT == EAL[7]:
                        E_T__0IF_C7F? CF_OUT == EAL[7]:
                        E_T__0;
                        E_T__0;
 
 
        always @(negedge phi_2) if (rdyg) begin
        always @(negedge phi_2) if (rdyg) begin
                if (E_PC__PC_1) PC <= PC + 1;
                if (E_PC__PC_1) begin
                else if (E_PC__EA) PC <= EA;
                        if (T || (!int_active && !rst_active)) PC <= PC + 1;
 
                end else if (E_PC__EA) PC <= EA;
                else begin
                else begin
                        if (E_PCH__RES) PC[15:8] <= RES;
                        if (E_PCH__RES) PC[15:8] <= RES;
                        if (E_PCL__ALU) PC[7:0] <= ALU;
                        if (E_PCL__ALU) PC[7:0] <= ALU;
                        else if (E_PCL__RES) PC[7:0] <= RES;
                        else if (E_PCL__RES) PC[7:0] <= RES;
                        else if (E_PCL__EAL) PC[7:0] <= EAL;
                        else if (E_PCL__EAL) PC[7:0] <= EAL;
                        else if (E_PCL__DB) PC[7:0] <= db_in;
                        else if (E_PCL__DB) PC[7:0] <= db_in;
                end
                end
 
 
                if (!T) begin
                if (!T) begin
                        IR <= db_in;
                        IR <= IR_in;
                        if (!db_in) begin // BRK instruction
                        if (!IR_in) begin // BRK instruction
                                {EAH, EAL} <= vec_addr;
                                {EAH, EAL} <= vec_addr;
                        end
                        end
                        nmi_prev <= nmi;
                        nmi_prev <= nmi;
                end
                end
 
 
Line 324... Line 326...
 
 
                eALU <= {CF_OUT, RES};
                eALU <= {CF_OUT, RES};
 
 
                if (cond) begin
                if (cond) begin
                        T <= 0;
                        T <= 0;
                        if (!IR_eff) begin
                        if (!IR) begin
                                FLAG_B <= !IR;
                                FLAG_B <= !int_active;
                                FLAG_I <= 1;
                                FLAG_I <= 1;
                        end
                        end
                end else T <= T + ((E_T__T_1IF_ALUCZ && !ALU_CF)?2: 1);
                end else T <= T + ((E_T__T_1IF_ALUCZ && !ALU_CF)?2: 1);
 
 
                if (rst_active) begin
                if (rst_active) begin

powered by: WebSVN 2.1.0

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