6 |
use blib; |
use blib; |
7 |
use lib './lib'; |
use lib './lib'; |
8 |
|
|
9 |
use Test::More tests => 36; |
use Test::More tests => 92; |
10 |
use Test::Exception; |
use Test::Exception; |
11 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
12 |
|
|
64 |
cmp_ok( $mem[$a], '==', $byte, '$mem' ); |
cmp_ok( $mem[$a], '==', $byte, '$mem' ); |
65 |
cmp_ok( M6502::_read($a), '==', $byte, 'M6502::_read' ); |
cmp_ok( M6502::_read($a), '==', $byte, 'M6502::_read' ); |
66 |
} |
} |
67 |
|
|
68 |
|
# flip bytes 6502 asm |
69 |
|
my $a = 0x1000; |
70 |
|
|
71 |
|
$mem[$a++] = $_ foreach ( |
72 |
|
0xa9, 0x60, 0xa2, 0x7f, 0xa0, 0x00, 0x85, 0xe1, |
73 |
|
0x84, 0xe0, 0xb1, 0xe0, 0x4a, 0x26, 0xe2, 0x4a, |
74 |
|
0x26, 0xe2, 0x4a, 0x26, 0xe2, 0x4a, 0x26, 0xe2, |
75 |
|
0x4a, 0x26, 0xe2, 0x4a, 0x26, 0xe2, 0x4a, 0x26, |
76 |
|
0xe2, 0x4a, 0x26, 0xe2, 0xa5, 0xe2, 0x91, 0xe0, |
77 |
|
0xc8, 0xd0, 0xdf, 0xe6, 0xe1, 0xe4, 0xe1, 0xb0, |
78 |
|
0xd9, 0x60, 0x00, |
79 |
|
); |
80 |
|
|
81 |
|
my @flip_tests = ( |
82 |
|
{ fill => 0b11101101, expect => 0b10110111 }, |
83 |
|
{ fill => 0b11101101, expect => 0b10110111, disable_all_callbacks => 1 }, |
84 |
|
{ fill => 0b11110000, expect => 0b00001111, disable_all_callbacks => 1 } |
85 |
|
); |
86 |
|
|
87 |
|
foreach my $test ( @flip_tests ) { |
88 |
|
|
89 |
|
diag "test ",dump( $test ); |
90 |
|
|
91 |
|
is( M6502::disable_all_callbacks(), 0x11, 'disable_all_callbacks' ) if $test->{disable_all_callbacks}; |
92 |
|
|
93 |
|
$mem[$_] = $test->{fill} foreach ( 0x6000 .. 0x7ffff ); |
94 |
|
|
95 |
|
diag dump_R(); |
96 |
|
$PC = 0x1000; |
97 |
|
|
98 |
|
ok( my $left = M6502::exec( 1 ), 'M6502::exec(1)' ); |
99 |
|
cmp_ok( $PC, '==', 0x1002, 'PC moved' ); |
100 |
|
cmp_ok( $left, '==', -1, 'no cycles left' ); |
101 |
|
|
102 |
|
ok( ! M6502::exec( 1000 ), 'M6502::exec' ); |
103 |
|
cmp_ok( $PC, '==', 0x1016, 'PC moved' ); |
104 |
|
|
105 |
|
foreach my $a ( 0x6000 .. 0x600c ) { |
106 |
|
cmp_ok( $mem[$a], '==', $test->{expect}, sprintf('flipped %04x to %08b',$a, $mem[$a]) ); |
107 |
|
} |
108 |
|
} |