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

Subversion Repositories t6507lp

[/] [t6507lp/] [trunk/] [rtl/] [verilog/] [t6507lp_alu_tb.v] - Diff between revs 186 and 224

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

Rev 186 Rev 224
Line 1... Line 1...
 
////////////////////////////////////////////////////////////////////////////
 
////                                                                    ////
 
//// T6507LP IP Core                                                    ////
 
////                                                                    ////
 
//// This file is part of the T6507LP project                           ////
 
//// http://www.opencores.org/cores/t6507lp/                            ////
 
////                                                                    ////
 
//// Description                                                        ////
 
//// 6507 ALU Testbench                                                 ////
 
////                                                                    ////
 
//// To Do:                                                             ////
 
//// - Search for TODO                                                  ////
 
////                                                                    ////
 
//// Author(s):                                                         ////
 
//// - Gabriel Oshiro Zardo, gabrieloshiro@gmail.com                    ////
 
//// - Samuel Nascimento Pagliarini (creep), snpagliarini@gmail.com     ////
 
////                                                                    ////
 
////////////////////////////////////////////////////////////////////////////
 
////                                                                    ////
 
//// Copyright (C) 2001 Authors and OPENCORES.ORG                       ////
 
////                                                                    ////
 
//// This source file may be used and distributed without               ////
 
//// restriction provided that this copyright statement is not          ////
 
//// removed from the file and that any derivative work contains        ////
 
//// the original copyright notice and the associated disclaimer.       ////
 
////                                                                    ////
 
//// 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 by the Free Software Foundation;       ////
 
//// either version 2.1 of the License, or (at your option) any         ////
 
//// later version.                                                     ////
 
////                                                                    ////
 
//// This source is distributed in the hope that it will be             ////
 
//// useful, but WITHOUT ANY WARRANTY; without even the implied         ////
 
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR            ////
 
//// PURPOSE. See the GNU Lesser General Public License for more        ////
 
//// details.                                                           ////
 
////                                                                    ////
 
//// You should have received a copy of the GNU Lesser General          ////
 
//// Public License along with this source; if not, download it         ////
 
//// from http://www.opencores.org/lgpl.shtml                           ////
 
////                                                                    ////
 
////////////////////////////////////////////////////////////////////////////
 
 
`include "timescale.v"
`include "timescale.v"
 
 
module t6507lp_alu_tb;
module t6507lp_alu_tb;
 
 
`include  "t6507lp_package.v"
`include  "t6507lp_package.v"
 
 
reg         clk;
reg         clk;
Line 10... Line 55...
wire [7:0]  alu_status;
wire [7:0]  alu_status;
reg  [7:0]  alu_opcode;
reg  [7:0]  alu_opcode;
reg  [7:0]  alu_a;
reg  [7:0]  alu_a;
wire [7:0]  alu_x;
wire [7:0]  alu_x;
wire [7:0]  alu_y;
wire [7:0]  alu_y;
reg  [31:0] i;
 
 
integer i, j;
 
integer ADC_RESULTS, SBC_RESULTS;
 
 
reg [7:0] alu_result_expected;
reg [7:0] alu_result_expected;
reg [7:0] alu_status_expected;
reg [7:0] alu_status_expected;
reg [7:0] alu_x_expected;
reg [7:0] alu_x_expected;
reg [7:0] alu_y_expected;
reg [7:0] alu_y_expected;
 
 
reg C_in;
reg C_in;
reg C_temp;
reg C_temp;
 
reg       sign;
reg [7:0] temp1;
reg [7:0] temp1;
reg [7:0] temp2;
reg [7:0] temp2;
reg sign;
 
reg [3:0] AL;
reg [3:0] AL;
reg [3:0] AH;
reg [3:0] AH;
reg [3:0] BL;
reg [3:0] BL;
reg [3:0] BH;
reg [3:0] BH;
reg [7:0] alu_result_expected_temp;
reg [7:0] alu_result_expected_temp;
Line 69... Line 116...
        #(period/2) clk = ~clk;
        #(period/2) clk = ~clk;
end
end
 
 
initial
initial
begin
begin
 
        //ADC_RESULT = fopen("ADC_RESULTS.txt");
 
        //SBC_RESULT = fopen("SBC_RESULTS.txt");
 
 
        // Reset
        // Reset
        clk = 0;
        clk = 0;
        reset_n = 0;
        reset_n = 0;
        @(negedge clk);
        @(negedge clk);
        //@(negedge clk);
 
        reset_n = 1;
        reset_n = 1;
        alu_enable = 1;
        alu_enable = 1;
        alu_result_expected = 8'h00;
        alu_result_expected = 8'h00;
        alu_status_expected = 8'b00100010;
        alu_status_expected = 8'b00100010;
        alu_x_expected = 8'h00;
        alu_x_expected = 8'h00;
        alu_y_expected = 8'h00;
        alu_y_expected = 8'h00;
 
 
        // LDA
        // LDA
        alu_a = 0;
        alu_a = 0;
        alu_opcode = LDA_IMM;
        alu_opcode = LDA_IMM;
        //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
 
        //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
 
        @(negedge clk);
        @(negedge clk);
        alu_result_expected = 8'h00;
        alu_result_expected = 8'h00;
        //                       NV1BDIZC
        //                       NV1BDIZC
    alu_status_expected = 8'b00100010;
    alu_status_expected = 8'b00100010;
        check;
        check;
 
 
        // ADC
        // ADC
        alu_opcode = ADC_IMM;
        for (i = 0; i < 256; i = i + 1)
        alu_a = 1;
 
        for (i = 0; i < 1000; i = i + 1)
 
        begin
        begin
                alu_a = $random;
                alu_a = i;
 
                alu_opcode = LDA_IMM;
 
                @(negedge clk);
 
                alu_result_expected = i;
 
                alu_status_expected[Z] = (alu_a == 0) ? 1 : 0;
 
                alu_status_expected[N] = alu_a[7];
 
                check;
 
                for (j = 0; j < 256; j = j + 1)
 
                begin
 
                        alu_opcode = ADC_IMM;
 
                        alu_a = j;
                @(negedge clk);
                @(negedge clk);
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
 
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
 
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], DUT.result);
 
                sign = alu_result_expected[7];
                sign = alu_result_expected[7];
                {alu_status_expected[C], alu_result_expected} = alu_a + alu_result_expected + alu_status_expected[C];
                        {alu_status_expected[C], alu_result_expected} = alu_result_expected + alu_a + alu_status_expected[C];
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
                alu_status_expected[N] = alu_result_expected[7];
                alu_status_expected[N] = alu_result_expected[7];
                alu_status_expected[V] = ((alu_a[7] == sign) && (alu_a[7] != alu_result_expected[7]));
                alu_status_expected[V] = ((alu_a[7] == sign) && (alu_a[7] != alu_result_expected[7]));
                check;
                check;
        end
        end
 
        end
 
 
        // CLC
        // SBC
        alu_opcode = CLC_IMP;
        for (i = 0; i < 256; i = i + 1)
        @(negedge clk);
        begin
        alu_status_expected[C] = 0;
                alu_a = i;
        check;
 
 
 
        // SED
 
        alu_opcode = SED_IMP;
 
        //$display("A = %h B = %h X = %h Y = %h", alu_result, alu_a, alu_x, alu_y);
 
        @(negedge clk);
 
        alu_status_expected[D] = 1;
 
        check;
 
        //Corner Case 12 + 88 decimal mode
 
        // LDA
 
        alu_a = 8'h88;
 
        alu_opcode = LDA_IMM;
        alu_opcode = LDA_IMM;
        @(negedge clk);
        @(negedge clk);
        alu_result_expected = 8'h88;
                alu_result_expected = i;
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
                alu_status_expected[Z] = (alu_a == 0) ? 1 : 0;
        alu_status_expected[N] = alu_result_expected[7];
                alu_status_expected[N] = alu_a[7];
        check;
        check;
 
                for (j = 0; j < 256; j = j + 1)
        // ADC
                begin
        alu_opcode = ADC_IMM;
                        alu_opcode = SBC_IMM;
        alu_a = 8'h12;
                        alu_a = j;
        $display("A = %h B = %h X = %h Y = %h", alu_result, alu_a, alu_x, alu_y);
 
        @(negedge clk);
        @(negedge clk);
        sign = alu_result_expected[7];
        sign = alu_result_expected[7];
        AL = alu_a[3:0] + alu_result_expected[3:0] + alu_status_expected[C];
                        alu_result_expected = alu_result_expected - alu_a - (1 - alu_status_expected[C]);
        $display("AL = %b", AL);
 
        AH = alu_a[7:4] + alu_result_expected[7:4] + AL[4];
 
        $display("AH = %b", AH);
 
        if (AL > 9) begin
 
          temp1 = AL - 6;
 
        end
 
        else begin
 
          temp1 = AL;
 
        end
 
        $display("temp1 = %b", temp1);
 
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
        alu_status_expected[N] = alu_result_expected[7];
        alu_status_expected[N] = alu_result_expected[7];
        alu_status_expected[V] = ((alu_a[7] == sign) && (alu_a[7] != alu_result_expected[7]));
                        alu_status_expected[V] = ((alu_a[7] == sign) && (alu_a[7] == alu_result_expected[7]));
        if (AH > 9) begin
                        alu_status_expected[C] = ~alu_result_expected[7];
          temp2 = AH - 6;
                        check;
        end
        end
        else begin
 
          temp2 = AH;
 
        end
        end
        $display("temp2 = %b", temp2);
 
        alu_status_expected[C] = (temp2 > 15) ? 1 : 0;
 
        alu_result_expected = {temp2[3:0],temp1[3:0]};
 
        $display("A = %b PS = %b", alu_result_expected, alu_status_expected);
 
        check;
 
 
 
        // CLD
        // CLC
        alu_opcode = CLD_IMP;
        alu_opcode = CLC_IMP;
        @(negedge clk);
 
        alu_status_expected[D] = 0;
 
        check;
 
        $stop;
 
        // BCD
 
        // LDA
 
        alu_a = 0;
 
        alu_opcode = LDA_IMM;
 
        //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
 
        //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
 
        @(negedge clk);
 
        alu_result_expected = 8'h00;
 
        //                       NV1BDIZC
 
        alu_status_expected[N] = 0;
 
        alu_status_expected[Z] = 1;
 
        check;
 
        // SED
 
        alu_opcode = SED_IMP;
 
        //$display("A = %h B = %h X = %h Y = %h", alu_result, alu_a, alu_x, alu_y);
 
        @(negedge clk);
        @(negedge clk);
        alu_status_expected[D] = 1;
        alu_status_expected[C] = 0;
        check;
        check;
 
 
        // ADC
 
        alu_opcode = ADC_IMM;
 
        for (i = 0; i < 1000; i = i + 1)
 
        begin
 
                alu_a = $random;
 
                //$display("A = %h B = %h C = %b X = %h Y = %h", alu_result, alu_a, alu_status_expected[C], alu_x, alu_y);
 
                @(negedge clk);
 
                AL = alu_result_expected[3:0] + alu_a[3:0] + alu_status_expected[C];
 
                AH = alu_result_expected[7:4] + alu_a[7:4] + AL[4];
 
                if (AL > 9) AL = AL + 6;
 
                if (AH > 9) AH = AH + 6;
 
                alu_status_expected[C] = AH[4];
 
                alu_result_expected = {AH[3:0],AL[3:0]};
 
                //C_temp = 0;
 
                //sign = alu_result_expected[7];
 
                //AL = alu_a[3:0];
 
                //AH = alu_a[7:4];
 
                //BL = alu_result_expected[3:0];
 
                //BH = alu_result_expected[7:4];
 
                /*
                /*
 
        // SED
 
        alu_opcode = SED_IMP;
 
        @(negedge clk);
 
        alu_status_expected[D] = 1;
 
        check;
 
 
 
        // ADC
 
        alu_opcode = ADC_IMM;
 
        alu_a = 8'h12;
 
        @(negedge clk);
 
        sign = alu_result_expected[7];
 
        AL = alu_a[3:0] + alu_result_expected[3:0] + alu_status_expected[C];
 
        $display("AL = %b", AL);
 
        AH = alu_a[7:4] + alu_result_expected[7:4] + AL[4];
 
        $display("AH = %b", AH);
                if (AL > 9) begin
                if (AL > 9) begin
                        AL = AL - 10;
          temp1 = AL - 6;
                        AH = AH + 1;
 
                end
                end
                if ( AH > 9 ) begin
        else begin
                        AH = AH - 10;
          temp1 = AL;
                        C_temp = 1;
 
                end
                end
                if (BL > 9) begin
        $display("temp1 = %b", temp1);
                        BL = BL - 10;
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
                        BH = BH + 1;
        alu_status_expected[N] = alu_result_expected[7];
 
        alu_status_expected[V] = ((alu_a[7] == sign) && (alu_a[7] != alu_result_expected[7]));
 
        if (AH > 9) begin
 
          temp2 = AH - 6;
                end
                end
                if ( BH > 9 ) begin
        else begin
                        BH = BH - 10;
          temp2 = AH;
                        C_temp = 1;
 
                end
                end
                */
        $display("temp2 = %b", temp2);
                //$display("AL = %h BL = %h", AL, BL, );
        alu_status_expected[C] = (temp2 > 15) ? 1 : 0;
                //temp1 = AL + BL + alu_status_expected[C];
        alu_result_expected = {temp2[3:0],temp1[3:0]};
                //AH = A[7:4] + alu_a[7:4];
        $display("A = %b PS = %b", alu_result_expected, alu_status_expected);
                //temp2 = AH + BH + temp1[4];
        check;
                //$display("temp1 = %h temp2 = %h", temp1, temp2);
 
                //if (temp1 > 9) begin
 
                //      temp2 = temp2 + (temp1 / 10);
 
        //              temp1 = temp1 % 10;
 
                //end
 
                //if (temp2 > 9) begin
 
                //      alu_status_expected[C] = 1;
 
                //      temp2 = temp2 % 10;
 
                //end
 
                //else begin
 
                //      alu_status_expected[C] = 0;
 
                //end
 
                //$display("bcdh2 = %d", bcdh2);
 
                //$display("bcdl = %d", bcdl);
 
                //alu_result_expected = {temp2[3:0],temp1[3:0]};
 
                //{C_in,alu_result_expected[3:0]} = AL + BL + alu_status_expected[C];
 
                //{alu_status_expected[C],alu_result_expected[7:4]} = AH + BH + C_in;
 
                //if ( alu_result_expected[3:0] > 9 ) begin
 
                //      alu_result_expected[3:0] = alu_result_expected[3:0] - 10;
 
        //              alu_result_expected[7:4] = alu_result_expected[7:4] + 1;
 
                //end
 
                //if ( alu_result_expected[7:4] > 9 ) begin
 
                //      alu_result_expected[7:4] = alu_result_expected[7:4] - 10;
 
        //              alu_status_expected[C] = 1;
 
                //end
 
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
 
                alu_status_expected[N] = alu_result_expected[7];
 
                alu_status_expected[V] = ((alu_a[7] == sign) && (alu_a[7] != alu_result_expected[7]));
 
                check;
 
        end
 
        //$stop;
 
        // CLD
 
        alu_opcode = CLD_IMP;
 
        @(negedge clk);
 
        alu_status_expected[D] = 0;
 
        check;
 
 
 
 
        // CLD
 
        alu_opcode = CLD_IMP;
 
        @(negedge clk);
 
        alu_status_expected[D] = 0;
 
        check;
 
*/
/*
/*
        // SBC BCD
 
        // LDA
        // LDA
        alu_a = 0;
        alu_a = 0;
        alu_opcode = LDA_IMM;
        alu_opcode = LDA_IMM;
        //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
        //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
        //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
        //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
Line 280... Line 250...
        alu_result_expected = 8'h00;
        alu_result_expected = 8'h00;
        //                       NV1BDIZC
        //                       NV1BDIZC
        alu_status_expected[N] = 0;
        alu_status_expected[N] = 0;
        alu_status_expected[Z] = 1;
        alu_status_expected[Z] = 1;
        check;
        check;
 
 
        // SED
        // SED
        alu_opcode = SED_IMP;
        alu_opcode = SED_IMP;
        $display("A = %h B = %h X = %h Y = %h", alu_result, alu_a, alu_x, alu_y);
        //$display("A = %h B = %h X = %h Y = %h", alu_result, alu_a, alu_x, alu_y);
        @(negedge clk);
        @(negedge clk);
        alu_status_expected[D] = 1;
        alu_status_expected[D] = 1;
        check;
        check;
 
 
        // SBC
        // ADC
        alu_opcode = SBC_IMM;
        alu_opcode = ADC_IMM;
        for (i = 0; i < 1000; i = i + 1)
        for (i = 0; i < 1000; i = i + 1)
        begin
        begin
                alu_a = $random;
                alu_a = $random;
                $display("A = %h B = %h C = %b X = %h Y = %h", alu_result, alu_a, alu_status_expected[C], alu_x, alu_y);
                //$display("A = %h B = %h C = %b X = %h Y = %h", alu_result, alu_a, alu_status_expected[C], alu_x, alu_y);
                @(negedge clk);
                @(negedge clk);
                C_temp = 0;
                AL = alu_result_expected[3:0] + alu_a[3:0] + alu_status_expected[C];
                sign   = alu_a[7];
                AH = alu_result_expected[7:4] + alu_a[7:4] + AL[4];
                AL     = alu_a[3:0];
                if (AL > 9) AL = AL + 6;
                AH     = alu_a[7:4];
                if (AH > 9) AH = AH + 6;
                BL     = ~alu_result_expected[3:0];
                alu_status_expected[C] = AH[4];
                BH     = ~alu_result_expected[7:4];
                alu_result_expected = {AH[3:0],AL[3:0]};
 
 
                //$display("AL = %h BL = %h", AL, BL, );
 
                temp1 = AL + BL + alu_status_expected[C];
 
                //AH = A[7:4] + alu_a[7:4];
 
                temp2 = AH + BH;
 
                //$display("temp1 = %h temp2 = %h", temp1, temp2);
 
                if (temp1 > 9) begin
 
                        temp2 = temp2 + (temp1 / 10);
 
                        temp1 = temp1 % 10;
 
                end
 
                if (temp2 > 9) begin
 
                        alu_status_expected[C] = 1;
 
                        temp2 = temp2 % 10;
 
                end
 
                else begin
 
                        alu_status_expected[C] = 0;
 
                end
 
                //$display("bcdh2 = %d", bcdh2);
 
                //$display("bcdl = %d", bcdl);
 
                alu_result_expected = {temp2[3:0],temp1[3:0]};
 
                //{C_in,alu_result_expected[3:0]} = AL + BL + alu_status_expected[C];
 
                //{alu_status_expected[C],alu_result_expected[7:4]} = AH + BH + C_in;
 
                //if ( alu_result_expected[3:0] > 9 ) begin
 
                //      alu_result_expected[3:0] = alu_result_expected[3:0] - 10;
 
        //              alu_result_expected[7:4] = alu_result_expected[7:4] + 1;
 
                //end
 
                //if ( alu_result_expected[7:4] > 9 ) begin
 
                //      alu_result_expected[7:4] = alu_result_expected[7:4] - 10;
 
        //              alu_status_expected[C] = 1;
 
                //end
 
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
                alu_status_expected[N] = alu_result_expected[7];
                alu_status_expected[N] = alu_result_expected[7];
                alu_status_expected[V] = ((alu_a[7] == sign) && (alu_a[7] != alu_result_expected[7]));
                alu_status_expected[V] = ((alu_a[7] == sign) && (alu_a[7] != alu_result_expected[7]));
                check;
                check;
        end
        end
Line 342... Line 283...
        alu_opcode = CLD_IMP;
        alu_opcode = CLD_IMP;
        @(negedge clk);
        @(negedge clk);
        alu_status_expected[D] = 0;
        alu_status_expected[D] = 0;
        check;
        check;
*/
*/
 
 
        // ASL
        // ASL
        alu_opcode = ASL_ABS;
        alu_opcode = ASL_ABS;
        for (i = 0; i < 1000; i = i + 1)
        for (i = 0; i < 1000; i = i + 1)
        begin
        begin
                alu_a = i;
                alu_a = i;
                @(negedge clk);
                @(negedge clk);
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
 
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
 
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
 
                {alu_status_expected[C], alu_result_expected} = {alu_a,1'b0};
                {alu_status_expected[C], alu_result_expected} = {alu_a,1'b0};
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
                alu_status_expected[N] = alu_result_expected[7];
                alu_status_expected[N] = alu_result_expected[7];
                check;
                check;
        end
        end
Line 363... Line 300...
        // ROL
        // ROL
        alu_opcode = ROL_ABS;
        alu_opcode = ROL_ABS;
        for (i = 0; i < 1000; i = i + 1)
        for (i = 0; i < 1000; i = i + 1)
        begin
        begin
                alu_a = i;
                alu_a = i;
                $display("A = %b", alu_a);
 
                @(negedge clk);
                @(negedge clk);
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
 
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
 
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
 
                {alu_status_expected[C], alu_result_expected} = {alu_a,alu_status_expected[C]};
                {alu_status_expected[C], alu_result_expected} = {alu_a,alu_status_expected[C]};
                $display("R = %b", alu_result);
 
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
                alu_status_expected[N] = alu_result_expected[7];
                alu_status_expected[N] = alu_result_expected[7];
                check;
                check;
        end
        end
 
 
        // ROR
        // ROR
        alu_opcode = ROR_ABS;
        alu_opcode = ROR_ABS;
        for (i = 0; i < 1000; i = i + 1)
        for (i = 0; i < 1000; i = i + 1)
        begin
        begin
                alu_a = i;
                alu_a = i;
                $display("A = %b", alu_a);
 
                @(negedge clk);
                @(negedge clk);
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
 
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
 
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
 
                {alu_result_expected, alu_status_expected[C]} = {alu_status_expected[C],alu_a};
                {alu_result_expected, alu_status_expected[C]} = {alu_status_expected[C],alu_a};
                $display("R = %b", alu_result);
 
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
                alu_status_expected[N] = alu_result_expected[7];
                alu_status_expected[N] = alu_result_expected[7];
                check;
                check;
        end
        end
 
 
        // LDA
        // LDA
        alu_a = 137;
        alu_a = 137;
        alu_opcode = LDA_IMM;
        alu_opcode = LDA_IMM;
    //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
 
        //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
 
        @(negedge clk);
        @(negedge clk);
        alu_result_expected = 8'd137;
        alu_result_expected = 8'd137;
        //                       NV1BDIZC
        //                       NV1BDIZC
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
        alu_status_expected[N] = alu_result_expected[7];
        alu_status_expected[N] = alu_result_expected[7];
Line 410... Line 335...
        alu_opcode = EOR_IMM;
        alu_opcode = EOR_IMM;
        for (i = 0; i < 1000; i = i + 1)
        for (i = 0; i < 1000; i = i + 1)
        begin
        begin
                alu_a = i;
                alu_a = i;
                @(negedge clk);
                @(negedge clk);
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
 
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
 
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
 
                //$display("result_expected = %d",alu_result_expected);
 
                alu_result_expected = alu_a ^ alu_result_expected;
                alu_result_expected = alu_a ^ alu_result_expected;
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
                alu_status_expected[N] = alu_result_expected[7];
                alu_status_expected[N] = alu_result_expected[7];
                //$display("result_expected = %d", alu_result_expected);
 
                check;
                check;
        end
        end
 
 
        // LDA
        /*
        alu_a = 0;
        // LDA
        alu_opcode = LDA_IMM;
        alu_a = 0;
    //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
        alu_opcode = LDA_IMM;
        //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
    //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
        @(negedge clk);
        //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
        alu_result_expected = 8'h00;
        @(negedge clk);
        //                       NV1BDIZC
        alu_result_expected = 8'h00;
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
        //                       NV1BDIZC
        alu_status_expected[N] = alu_result_expected[7];
        alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
        check;
        alu_status_expected[N] = alu_result_expected[7];
 
        check;
 
 
        // SBC
        // SBC
        alu_opcode = SBC_IMM;
        alu_opcode = SBC_IMM;
        for (i = 0; i < 1000; i = i + 1)
        for (i = 0; i < 1000; i = i + 1)
        begin
        begin
                alu_a = 1;
                alu_a = 1;
                @(negedge clk);
                @(negedge clk);
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
                sign = alu_result_expected[7];
                sign = alu_result_expected[7];
                alu_result_expected = alu_result_expected - alu_a - ( 1 - alu_status_expected[C]);
                alu_result_expected = alu_result_expected - alu_a - ( 1 - alu_status_expected[C]);
                alu_status_expected[C] = ~alu_result_expected[7];
                alu_status_expected[C] = ~alu_result_expected[7];
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
                alu_status_expected[N] = alu_result_expected[7];
                alu_status_expected[N] = alu_result_expected[7];
                //$display("alu_a[7] = %b == sign = %b && alu_a[7] = %b != alu_result_expected[7] = %b", alu_a[7], sign, alu_a[7], alu_result_expected[7]);
                //$display("alu_a[7] = %b == sign = %b && alu_a[7] = %b != alu_result_expected[7] = %b", alu_a[7], sign, alu_a[7], alu_result_expected[7]);
                alu_status_expected[V] = ((alu_a[7] == sign) && (alu_a[7] != alu_result_expected[7]));
                alu_status_expected[V] = ((alu_a[7] == sign) && (alu_a[7] != alu_result_expected[7]));
                check;
                check;
        end
        end
 
        */
 
 
        // LDA
        // LDA
        alu_opcode = LDA_IMM;
        alu_opcode = LDA_IMM;
        for (i = 0; i < 1000; i = i + 1)
        for (i = 0; i < 1000; i = i + 1)
        begin
        begin
                alu_a = i;
                alu_a = i;
                @(negedge clk);
                @(negedge clk);
                alu_result_expected = i;
                alu_result_expected = i;
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
                alu_status_expected[N] = alu_result_expected[7];
                alu_status_expected[N] = alu_result_expected[7];
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
 
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
 
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
 
                check;
                check;
        end
        end
 
 
        // LDX
        // LDX
        alu_opcode = LDX_IMM;
        alu_opcode = LDX_IMM;
        for (i = 0; i < 1000; i = i + 1)
        for (i = 0; i < 1000; i = i + 1)
        begin
        begin
                alu_a = i;
                alu_a = i;
                @(negedge clk);
                @(negedge clk);
                alu_x_expected = alu_a;
                alu_x_expected = alu_a;
                //$display("alu_x_expected = %h", alu_x_expected);
 
                //alu_result_expected = i;
 
                alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
                alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
                alu_status_expected[N] = alu_x_expected[7];
                alu_status_expected[N] = alu_x_expected[7];
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
 
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
 
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
 
                check;
                check;
        end
        end
 
 
        // LDY
        // LDY
        alu_opcode = LDY_IMM;
        alu_opcode = LDY_IMM;
        for (i = 0; i < 1001; i = i + 1)
        for (i = 0; i < 1001; i = i + 1)
        begin
        begin
                alu_a = i;
                alu_a = i;
                @(negedge clk);
                @(negedge clk);
                alu_y_expected = alu_a;
                alu_y_expected = alu_a;
                //$display("alu_y_expected = %h", alu_y_expected);
 
                //alu_result_expected = i;
 
                alu_status_expected[Z] = (alu_y_expected == 0) ? 1 : 0;
                alu_status_expected[Z] = (alu_y_expected == 0) ? 1 : 0;
                alu_status_expected[N] = alu_y_expected[7];
                alu_status_expected[N] = alu_y_expected[7];
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
 
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
 
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
 
                check;
                check;
        end
        end
 
 
        // STA
        // STA
        alu_opcode = STA_ABS;
        alu_opcode = STA_ABS;
        for (i = 0; i < 1000; i = i + 1)
        for (i = 0; i < 1000; i = i + 1)
        begin
        begin
                alu_a = i;
                alu_a = i;
                @(negedge clk);
                @(negedge clk);
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
 
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
 
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
 
                //alu_result_expected = alu_a;
 
                //alu_result_expected = DUT.A;
 
                check;
                check;
        end
        end
 
 
        // STX
        // STX
        alu_opcode = STX_ABS;
        alu_opcode = STX_ABS;
        for (i = 0; i < 1000; i = i + 1)
        for (i = 0; i < 1000; i = i + 1)
        begin
        begin
                alu_a = i;
                alu_a = i;
                @(negedge clk);
                @(negedge clk);
                //$display("alu_x_expected = %h", alu_x_expected);
 
                //alu_result_expected = i;
 
                //alu_x_expected = alu_a;
 
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
 
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
 
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
 
                check;
                check;
        end
        end
 
 
        // STY
        // STY
        alu_opcode = STY_ABS;
        alu_opcode = STY_ABS;
        for (i = 0; i < 1000; i = i + 1)
        for (i = 0; i < 1000; i = i + 1)
        begin
        begin
                alu_a = i;
                alu_a = i;
                @(negedge clk);
                @(negedge clk);
                //$display("alu_y_expected = %h", alu_y_expected);
 
                //alu_result_expected = i;
 
                //alu_y_expected = alu_a;
 
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
 
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
 
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
 
                check;
                check;
        end
        end
 
 
        // CMP
        // CMP
        alu_opcode = CMP_IMM;
        alu_opcode = CMP_IMM;
Line 555... Line 447...
                @(negedge clk);
                @(negedge clk);
                temp1 = alu_result_expected - alu_a;
                temp1 = alu_result_expected - alu_a;
                alu_status_expected[Z] = (temp1 == 0) ? 1 : 0;
                alu_status_expected[Z] = (temp1 == 0) ? 1 : 0;
                alu_status_expected[N] = temp1[7];
                alu_status_expected[N] = temp1[7];
                alu_status_expected[C] = (alu_result_expected >= alu_a) ? 1 : 0;
                alu_status_expected[C] = (alu_result_expected >= alu_a) ? 1 : 0;
                //alu_result_expected = i;
 
                //alu_y_expected = i;
 
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
 
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
 
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
 
                check;
                check;
        end
        end
 
 
        // CPX
        // CPX
        alu_opcode = CPX_IMM;
        alu_opcode = CPX_IMM;
Line 573... Line 460...
                @(negedge clk);
                @(negedge clk);
                temp1 = alu_x_expected - alu_a;
                temp1 = alu_x_expected - alu_a;
                alu_status_expected[Z] = (temp1 == 0) ? 1 : 0;
                alu_status_expected[Z] = (temp1 == 0) ? 1 : 0;
                alu_status_expected[N] = temp1[7];
                alu_status_expected[N] = temp1[7];
                alu_status_expected[C] = (alu_x_expected >= alu_a) ? 1 : 0;
                alu_status_expected[C] = (alu_x_expected >= alu_a) ? 1 : 0;
                //alu_result_expected = i;
 
                //alu_y_expected = i;
 
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
 
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
 
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
 
                check;
                check;
        end
        end
 
 
        // CPY
        // CPY
        alu_opcode = CPY_IMM;
        alu_opcode = CPY_IMM;
Line 591... Line 473...
                @(negedge clk);
                @(negedge clk);
                temp1 = alu_y_expected - alu_a;
                temp1 = alu_y_expected - alu_a;
                alu_status_expected[Z] = (temp1 == 0) ? 1 : 0;
                alu_status_expected[Z] = (temp1 == 0) ? 1 : 0;
                alu_status_expected[N] = temp1[7];
                alu_status_expected[N] = temp1[7];
                alu_status_expected[C] = (alu_y_expected >= alu_a) ? 1 : 0;
                alu_status_expected[C] = (alu_y_expected >= alu_a) ? 1 : 0;
                //alu_result_expected = i;
 
                //alu_y_expected = i;
 
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
 
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
 
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
 
                check;
                check;
        end
        end
 
 
 
 
        // AND
        // AND
Line 609... Line 486...
                alu_a = i;
                alu_a = i;
                @(negedge clk);
                @(negedge clk);
                alu_result_expected = alu_a & alu_result_expected;
                alu_result_expected = alu_a & alu_result_expected;
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
                alu_status_expected[N] = alu_result_expected[7];
                alu_status_expected[N] = alu_result_expected[7];
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
 
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
 
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
 
                check;
                check;
        end
        end
 
 
        // ASL
        // ASL
        alu_opcode = ASL_ACC;
        alu_opcode = ASL_ACC;
Line 625... Line 499...
                @(negedge clk);
                @(negedge clk);
                alu_status_expected[C] = alu_result_expected[7];
                alu_status_expected[C] = alu_result_expected[7];
                alu_result_expected[7:0] = alu_result_expected << 1;
                alu_result_expected[7:0] = alu_result_expected << 1;
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
                alu_status_expected[N] = alu_result_expected[7];
                alu_status_expected[N] = alu_result_expected[7];
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
 
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
 
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
 
                check;
                check;
        end
        end
 
 
        // INC
        // INC
        alu_opcode = INC_ZPG;
        alu_opcode = INC_ZPG;
        for (i = 0; i < 1000; i = i + 1)
        for (i = 0; i < 1000; i = i + 1)
        begin
        begin
                alu_a = i;
                alu_a = i;
                @(negedge clk);
                @(negedge clk);
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
 
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
 
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
 
                alu_result_expected = alu_a + 1;
                alu_result_expected = alu_a + 1;
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
                alu_status_expected[N] = alu_result_expected[7];
                alu_status_expected[N] = alu_result_expected[7];
                check;
                check;
        end
        end
Line 652... Line 520...
        alu_opcode = INX_IMP;
        alu_opcode = INX_IMP;
        for (i = 0; i < 1000; i = i + 1)
        for (i = 0; i < 1000; i = i + 1)
        begin
        begin
                alu_a = i;
                alu_a = i;
                @(negedge clk);
                @(negedge clk);
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
 
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
 
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
 
                alu_x_expected = alu_x_expected + 1;
                alu_x_expected = alu_x_expected + 1;
                alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
                alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
                alu_status_expected[N] = alu_x_expected[7];
                alu_status_expected[N] = alu_x_expected[7];
                check;
                check;
        end
        end
Line 667... Line 532...
        alu_opcode = INY_IMP;
        alu_opcode = INY_IMP;
        for (i = 0; i < 1000; i = i + 1)
        for (i = 0; i < 1000; i = i + 1)
        begin
        begin
                alu_a = i;
                alu_a = i;
                @(negedge clk);
                @(negedge clk);
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
 
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
 
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
 
                alu_y_expected = alu_y_expected + 1;
                alu_y_expected = alu_y_expected + 1;
                alu_status_expected[Z] = (alu_y_expected == 0) ? 1 : 0;
                alu_status_expected[Z] = (alu_y_expected == 0) ? 1 : 0;
                alu_status_expected[N] = alu_y_expected[7];
                alu_status_expected[N] = alu_y_expected[7];
                check;
                check;
        end
        end
Line 682... Line 544...
        alu_opcode = DEC_ZPG;
        alu_opcode = DEC_ZPG;
        for (i = 0; i < 1000; i = i + 1)
        for (i = 0; i < 1000; i = i + 1)
        begin
        begin
                alu_a = i;
                alu_a = i;
                @(negedge clk);
                @(negedge clk);
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
 
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
 
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
 
                alu_result_expected = alu_a - 1;
                alu_result_expected = alu_a - 1;
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
                alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
                alu_status_expected[N] = alu_result_expected[7];
                alu_status_expected[N] = alu_result_expected[7];
                check;
                check;
        end
        end
Line 697... Line 556...
        alu_opcode = DEX_IMP;
        alu_opcode = DEX_IMP;
        for (i = 0; i < 1000; i = i + 1)
        for (i = 0; i < 1000; i = i + 1)
        begin
        begin
                alu_a = i;
                alu_a = i;
                @(negedge clk);
                @(negedge clk);
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
 
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
 
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
 
                alu_x_expected = alu_x_expected - 1;
                alu_x_expected = alu_x_expected - 1;
                alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
                alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
                alu_status_expected[N] = alu_x_expected[7];
                alu_status_expected[N] = alu_x_expected[7];
                check;
                check;
        end
        end
Line 712... Line 568...
        alu_opcode = DEY_IMP;
        alu_opcode = DEY_IMP;
        for (i = 0; i < 1000; i = i + 1)
        for (i = 0; i < 1000; i = i + 1)
        begin
        begin
                alu_a = i;
                alu_a = i;
                @(negedge clk);
                @(negedge clk);
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
 
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
 
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
 
                alu_y_expected = alu_y_expected - 1;
                alu_y_expected = alu_y_expected - 1;
                alu_status_expected[Z] = (alu_y_expected == 0) ? 1 : 0;
                alu_status_expected[Z] = (alu_y_expected == 0) ? 1 : 0;
                alu_status_expected[N] = alu_y_expected[7];
                alu_status_expected[N] = alu_y_expected[7];
                check;
                check;
        end
        end
 
 
 
 
        // LDA
        // LDA
        alu_a = 0;
        alu_a = 0;
        alu_opcode = LDA_IMM;
        alu_opcode = LDA_IMM;
        //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
 
        //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
 
        @(negedge clk);
        @(negedge clk);
        alu_result_expected = 8'h00;
        alu_result_expected = 8'h00;
        //                       NV1BDIZC
        //                       NV1BDIZC
        alu_status_expected = 8'b00100010;
        alu_status_expected[Z] = 1;
 
        alu_status_expected[N] = 0;
        check;
        check;
 
 
        // BIT
        // BIT
        alu_opcode = BIT_ZPG;
        alu_opcode = BIT_ZPG;
        for (i = 0; i < 1000; i = i + 1)
        for (i = 0; i < 1000; i = i + 1)
        begin
        begin
                alu_a = i;
                alu_a = i;
                @(negedge clk);
                @(negedge clk);
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
 
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
 
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
 
                alu_status_expected[Z] = ((alu_a & alu_result_expected) == 0) ? 1 : 0;
                alu_status_expected[Z] = ((alu_a & alu_result_expected) == 0) ? 1 : 0;
                alu_status_expected[V] = alu_a[6];
                alu_status_expected[V] = alu_a[6];
                alu_status_expected[N] = alu_a[7];
                alu_status_expected[N] = alu_a[7];
                check;
                check;
        end
        end
Line 754... Line 603...
        alu_opcode = RTI_IMP;
        alu_opcode = RTI_IMP;
        for (i = 0; i < 1000; i = i + 1)
        for (i = 0; i < 1000; i = i + 1)
        begin
        begin
                alu_a = i;
                alu_a = i;
                @(negedge clk);
                @(negedge clk);
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
 
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
 
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
 
                alu_status_expected[C] = alu_a[C];
                alu_status_expected[C] = alu_a[C];
                alu_status_expected[Z] = alu_a[Z];
                alu_status_expected[Z] = alu_a[Z];
                alu_status_expected[N] = alu_a[N];
                alu_status_expected[N] = alu_a[N];
                alu_status_expected[V] = alu_a[V];
                alu_status_expected[V] = alu_a[V];
                alu_status_expected[B] = alu_a[B];
                alu_status_expected[B] = alu_a[B];
Line 773... Line 619...
        alu_opcode = PLP_IMP;
        alu_opcode = PLP_IMP;
        for (i = 0; i < 1000; i = i + 1)
        for (i = 0; i < 1000; i = i + 1)
        begin
        begin
                alu_a = i;
                alu_a = i;
                @(negedge clk);
                @(negedge clk);
                //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
 
                //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
 
                //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
 
                alu_status_expected[C] = alu_a[C];
                alu_status_expected[C] = alu_a[C];
                alu_status_expected[Z] = alu_a[Z];
                alu_status_expected[Z] = alu_a[Z];
                alu_status_expected[N] = alu_a[N];
                alu_status_expected[N] = alu_a[N];
                alu_status_expected[V] = alu_a[V];
                alu_status_expected[V] = alu_a[V];
                alu_status_expected[B] = alu_a[B];
                alu_status_expected[B] = alu_a[B];
Line 789... Line 632...
        end
        end
 
 
        // PHA
        // PHA
        alu_opcode = PHA_IMP;
        alu_opcode = PHA_IMP;
        @(negedge clk);
        @(negedge clk);
        //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
 
        //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
 
        //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
 
        //alu_result_expected = DUT.A;
 
        //alu_result_expected = alu_a;
 
        check;
        check;
 
 
        // PHP
        // PHP
        alu_opcode = PHP_IMP;
        alu_opcode = PHP_IMP;
        @(negedge clk);
        @(negedge clk);
        //$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
 
        //$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
 
        //$display("op1 = %d op2 = %d  c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
 
        //alu_status_expected = DUT.STATUS;
 
        check;
        check;
 
 
        // BRK
        // BRK
        alu_opcode = BRK_IMP;
        alu_opcode = BRK_IMP;
        @(negedge clk);
        @(negedge clk);
Line 982... Line 816...
end
end
 
 
endmodule
endmodule
 
 
 
 
 No newline at end of file
 No newline at end of file
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

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