1 |
dpavlin |
83 |
#!/usr/bin/perl |
2 |
|
|
|
3 |
|
|
use warnings; |
4 |
|
|
use strict; |
5 |
|
|
|
6 |
|
|
use blib; |
7 |
|
|
use lib './lib'; |
8 |
|
|
|
9 |
dpavlin |
89 |
use Test::More tests => 36; |
10 |
dpavlin |
83 |
use Test::Exception; |
11 |
|
|
use Data::Dump qw/dump/; |
12 |
|
|
|
13 |
|
|
BEGIN { |
14 |
|
|
use_ok( 'M6502' ); |
15 |
|
|
} |
16 |
|
|
|
17 |
dpavlin |
87 |
cmp_ok( $debug, '==', 0, '$debug' ); |
18 |
|
|
cmp_ok( M6502::get_debug(), '==', 0, 'M6502::get_debug' ); |
19 |
|
|
cmp_ok( M6502->debug, '==', 0, 'M6502->debug' ); |
20 |
|
|
|
21 |
|
|
cmp_ok( M6502::set_debug( 1 ), '==', 1, 'M6502::set_debug'); |
22 |
|
|
cmp_ok( M6502::get_debug(), '==', 1, 'M6502::get_debug'); |
23 |
|
|
cmp_ok( $debug, '==', 0, '$debug still wrong'); |
24 |
|
|
|
25 |
|
|
cmp_ok( M6502->debug(1), '==', 1, 'M6502->debug(1)' ); |
26 |
|
|
cmp_ok( $debug, '==', 1, '$debug on' ); |
27 |
|
|
cmp_ok( M6502::get_debug(), '==', 1, 'get_debug on' ); |
28 |
|
|
cmp_ok( M6502->debug, '==', 1, 'M6502->debug on' ); |
29 |
|
|
|
30 |
|
|
cmp_ok( M6502->debug(0), '==', 0, 'M6502->debug(0)' ); |
31 |
|
|
cmp_ok( $debug, '==', 0, '$debug off' ); |
32 |
|
|
cmp_ok( M6502::get_debug(), '==', 0, 'get_debug off' ); |
33 |
|
|
cmp_ok( M6502->debug, '==', 0, 'M6502->debug off' ); |
34 |
|
|
|
35 |
|
|
M6502->debug( 1 ) if @ARGV; |
36 |
|
|
|
37 |
|
|
diag "debug: $debug"; |
38 |
|
|
|
39 |
dpavlin |
86 |
cmp_ok( $PC, '==', 0xbeef, 'PC' ); |
40 |
|
|
|
41 |
dpavlin |
83 |
ok( M6502::reset(), 'reset' ); |
42 |
|
|
|
43 |
dpavlin |
89 |
cmp_ok( $PC, '==', 0xffff, 'PC' ); |
44 |
dpavlin |
87 |
|
45 |
dpavlin |
86 |
diag dump_R(); |
46 |
|
|
|
47 |
dpavlin |
87 |
$PC = 0xdead; |
48 |
dpavlin |
86 |
|
49 |
dpavlin |
87 |
M6502::update_C_R(); |
50 |
dpavlin |
86 |
|
51 |
dpavlin |
87 |
$PC = 0xffff; |
52 |
|
|
|
53 |
|
|
M6502::update_perl_R(); |
54 |
|
|
|
55 |
|
|
cmp_ok( $PC, '==', 0xdead, 'PC' ); |
56 |
|
|
|
57 |
dpavlin |
83 |
ok( M6502::reset(), 'reset again' ); |
58 |
dpavlin |
87 |
|
59 |
dpavlin |
89 |
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 |
dpavlin |
91 |
|
68 |
|
|
|
69 |
|
|
$mem[$_] = 0 foreach ( 0x6000 .. 0x7ffff ); |
70 |
|
|
|
71 |
|
|
# invert screen in 6502 asm |
72 |
|
|
my $a = 0x1000; |
73 |
|
|
|
74 |
|
|
$mem[$a++] = $_ foreach ( |
75 |
|
|
0xa9, 0x60, 0xa2, 0x7f, 0xa0, 0x00, 0x85, 0xe1, |
76 |
|
|
0x84, 0xe0, 0xb1, 0xe0, 0x4a, 0x26, 0xe2, 0x4a, |
77 |
|
|
0x26, 0xe2, 0x4a, 0x26, 0xe2, 0x4a, 0x26, 0xe2, |
78 |
|
|
0x4a, 0x26, 0xe2, 0x4a, 0x26, 0xe2, 0x4a, 0x26, |
79 |
|
|
0xe2, 0x4a, 0x26, 0xe2, 0xa5, 0xe2, 0x91, 0xe0, |
80 |
|
|
0xc8, 0xd0, 0xdf, 0xe6, 0xe1, 0xe4, 0xe1, 0xb0, |
81 |
|
|
0xd9, 0x60, 0x00, |
82 |
|
|
); |
83 |
|
|
|
84 |
|
|
diag dump_R(); |
85 |
|
|
$PC = 0x1000; |
86 |
|
|
|
87 |
|
|
ok( ! M6502::exec( 1 ), 'M6502::exec(1)' ); |
88 |
|
|
cmp_ok( $PC, '>', 0x1000, 'PC moved' ); |
89 |
|
|
|
90 |
|
|
diag dump_R(); |
91 |
|
|
|
92 |
|
|
ok( my $left = M6502::exec( 10000 ), 'M6502::exec' ); |
93 |
|
|
|
94 |
|
|
diag dump_R(), "cycles left: $left"; |
95 |
|
|
|
96 |
|
|
foreach my $a ( 0x6000 .. 0x6001 ) { |
97 |
|
|
cmp_ok( $mem[$a], '==', 0xff, sprintf('inverted %04x',$a) ); |
98 |
|
|
} |