/[VRac]/M6502/t/05-M6502.t
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /M6502/t/05-M6502.t

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 87 by dpavlin, Thu Aug 2 11:08:10 2007 UTC revision 199 by dpavlin, Sun Apr 13 11:40:01 2008 UTC
# Line 6  use strict; Line 6  use strict;
6  use blib;  use blib;
7  use lib './lib';  use lib './lib';
8    
9  use Test::More tests => 21;  use Test::More tests => 168;
10  use Test::Exception;  use Test::Exception;
11  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
12    
# Line 40  cmp_ok( $PC, '==', 0xbeef, 'PC' ); Line 40  cmp_ok( $PC, '==', 0xbeef, 'PC' );
40    
41  ok( M6502::reset(), 'reset' );  ok( M6502::reset(), 'reset' );
42    
43  cmp_ok( $PC, '==', 0x4242, 'PC' );  cmp_ok( $PC, '==', 0xffff, 'PC' );
44    
45  diag dump_R();  diag dump_R();
46    
# Line 56  cmp_ok( $PC, '==', 0xdead, 'PC' ); Line 56  cmp_ok( $PC, '==', 0xdead, 'PC' );
56    
57  ok( M6502::reset(), 'reset again' );  ok( M6502::reset(), 'reset again' );
58    
59  cmp_ok( $PC, '==', 0x4242, 'PC' );  cmp_ok( $PC, '==', 0xffff, 'PC' );
60    
61    foreach my $byte ( 0x00, 0x01, 0xff, 0xaa, 0x00 ) {
62            my $a = 0x1000 + $byte * 100;
63            cmp_ok( M6502::_write($a,$byte), '==', $byte, 'M6502::_write' );
64            cmp_ok( $mem[$a], '==', $byte, '$mem' );
65            cmp_ok( M6502::_read($a), '==', $byte, 'M6502::_read' );
66    }
67    
68    my @flip_tests = (
69            { fill => 0b11101101, expect => 0b10110111, callbacks => 0x33 },
70            { fill => 0b11101101, expect => 0b10110111, callbacks => 0x22 },
71            { fill => 0b11110000, expect => 0b00001111, callbacks => 0x11 },
72            { fill => 0b11110011, expect => 0b11001111, callbacks => 0x00 },
73    );
74    
75    foreach my $test ( @flip_tests ) {
76    
77            diag "test ",dump( $test );
78    
79            ok( M6502::reset(), 'reset again' );
80            is( M6502::set_all_callbacks( $test->{callbacks} ), $test->{callbacks}, 'set_all_callbacks' );
81    
82            # flip bytes 6502 asm
83            my $a = 0x1000;
84    
85            $mem[$a++] = $_ foreach (
86                    0xa9, 0x60, 0xa2, 0x7f, 0xa0, 0x00, 0x85, 0xe1,
87                    0x84, 0xe0, 0xb1, 0xe0, 0x4a, 0x26, 0xe2, 0x4a,
88                    0x26, 0xe2, 0x4a, 0x26, 0xe2, 0x4a, 0x26, 0xe2,
89                    0x4a, 0x26, 0xe2, 0x4a, 0x26, 0xe2, 0x4a, 0x26,
90                    0xe2, 0x4a, 0x26, 0xe2, 0xa5, 0xe2, 0x91, 0xe0,
91                    0xc8, 0xd0, 0xdf, 0xe6, 0xe1, 0xe4, 0xe1, 0xb0,
92                    0xd9, 0x60, 0x00,
93            );
94    
95            $mem[$_] = $test->{fill} foreach ( 0x6000 .. 0x7ffff );
96    
97            diag dump_R();
98            $PC = 0x1000;
99    
100            ok( my $left = M6502::exec( 1 ), 'M6502::exec(1)' );
101            cmp_ok( $PC, '==', 0x1002, 'PC moved' );
102            cmp_ok( $left, '==', -1, 'no cycles left' );
103    
104            ok( ! M6502::exec( 1000 ), 'M6502::exec' );
105            cmp_ok( $PC, '==', 0x1016, 'PC moved' );
106    
107            foreach my $a ( 0x6000 .. 0x600c ) {
108                    cmp_ok( $mem[$a], '==', $test->{expect}, sprintf('flipped %04x %08b -> %08b',$a, $test->{fill}, $mem[$a]) );
109                    cmp_ok( M6502::get_callback( $a ), '==', $test->{callbacks}, 'callback' );
110            }
111    }

Legend:
Removed from v.87  
changed lines
  Added in v.199

  ViewVC Help
Powered by ViewVC 1.1.26