/[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

Contents of /M6502/t/05-M6502.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 204 - (show annotations)
Mon Apr 14 15:03:56 2008 UTC (16 years, 1 month ago) by dpavlin
File MIME type: application/x-troff
File size: 4487 byte(s)
if we use tied memory, no callbacks work just fine
1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 use blib;
7 use lib './lib';
8
9 use Test::More tests => 226;
10 use Test::Exception;
11 use Data::Dump qw/dump/;
12
13 BEGIN {
14 use_ok( 'M6502' );
15 }
16
17 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 cmp_ok( $PC, '==', 0xbeef, 'PC' );
40
41 ok( M6502::reset(), 'reset' );
42
43 cmp_ok( $PC, '==', 0xffff, 'PC' );
44
45 diag dump_R();
46
47 $PC = 0xdead;
48
49 M6502::update_C_R();
50
51 $PC = 0xffff;
52
53 M6502::update_perl_R();
54
55 cmp_ok( $PC, '==', 0xdead, 'PC' );
56
57 ok( M6502::reset(), 'reset again' );
58
59 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 # is( M6502::mem_peek( $a ), $byte, 'M6502::mem_peek' );
66 cmp_ok( M6502::_read($a), '==', $byte, 'M6502::_read' );
67 }
68
69 sub dump_callbacks {
70 my $out = 'callbacks:';
71 $out .= sprintf(" %02x", M6502::get_callback( $_ )) foreach ( 0x6000 .. 0x6020 );
72 diag join(' ',$out, @_);
73 }
74
75 is( M6502::get_callback( 0x6000 ), 0x22, 'default callback 0x22' );
76 is( M6502::set_all_callbacks( 0x42 ), 0x42, 'set_all_callbacks( 0x42 )' );
77 is( M6502::get_callback( $_ ), 0x42, sprintf('get_callback %04x', $_) ) foreach ( 0, 1, 2, 3, 0x4000, 0x8000, 0xfffe, 0xffff );
78 is( M6502::set_all_callbacks( 0 ), 0, 'set_all_callbacks( 0 )' );
79 M6502::set_write_callback( 0x6000 );
80 is( M6502::get_callback( 0x6000 ), 0x20, 'set_write_callback' );
81 M6502::set_read_callback( 0x6000 );
82 is( M6502::get_callback( 0x6000 ), 0x22, 'set_read_callback' );
83 is( M6502::set_all_callbacks( 0xff ), 0xff, 'set_all_callbacks( 0xff )' );
84 is( M6502::get_callback( 0 ), 0xff, 'get_callback' );
85 ok( M6502::reset(), 'reset' );
86 is( M6502::get_callback( 0 ), 0x22, 'reset restore default callback 0x22' );
87
88 my @flip_tests = (
89 { fill => 0b11101101, expect => 0b10110111 },
90 { fill => 0b11101101, expect => 0b10110111, callbacks => 0x22 },
91 { fill => 0b11110000, expect => 0b00001111, callbacks => 0x11 },
92 { fill => 0b11110011, expect => 0b11001111, callbacks => 0x01 },
93 { fill => 0b11110011, expect => 0b11001111, callbacks => 0x00 },
94 );
95
96 my $i = 1;
97
98 foreach my $test ( @flip_tests ) {
99
100 diag 'flip round ',$i++,' ',dump( $test );
101
102 ok( M6502::reset(), 'reset again' );
103 dump_callbacks;
104
105 is( M6502::set_all_callbacks( $test->{callbacks} ), $test->{callbacks}, sprintf('set_all_callbacks(0x%02x)',$test->{callbacks}) )
106 if $test->{callbacks};
107 dump_callbacks;
108
109 # manually hook callbacks
110 M6502::set_write_callback( $_ ) foreach ( 0x6000 .. 0x6010 );
111 dump_callbacks('after set_write_callback');
112
113 diag 'flip bytes 6502 asm';
114 my $a = 0x1000;
115
116 $mem[$a++] = $_ foreach (
117 0xa9, 0x60, 0xa2, 0x7f, 0xa0, 0x00, 0x85, 0xe1,
118 0x84, 0xe0, 0xb1, 0xe0, 0x4a, 0x26, 0xe2, 0x4a,
119 0x26, 0xe2, 0x4a, 0x26, 0xe2, 0x4a, 0x26, 0xe2,
120 0x4a, 0x26, 0xe2, 0x4a, 0x26, 0xe2, 0x4a, 0x26,
121 0xe2, 0x4a, 0x26, 0xe2, 0xa5, 0xe2, 0x91, 0xe0,
122 0xc8, 0xd0, 0xdf, 0xe6, 0xe1, 0xe4, 0xe1, 0xb0,
123 0xd9, 0x60, 0x00,
124 );
125
126 diag 'clean video ram';
127 $mem[$_] = $test->{fill} foreach ( 0x6000 .. 0x7fff );
128
129 diag dump_R();
130 $PC = 0x1000;
131
132 ok( my $left = M6502::exec( 1 ), 'M6502::exec(1)' );
133 cmp_ok( $PC, '==', 0x1002, 'PC moved' );
134 cmp_ok( $left, '==', -1, 'no cycles left' );
135
136 ok( ! M6502::exec( 1000 ), 'M6502::exec' );
137 cmp_ok( $PC, '==', 0x1016, 'PC moved' );
138
139 foreach my $a ( 0x6000 .. 0x600c ) {
140 cmp_ok( $mem[$a], '==', $test->{expect}, sprintf('flipped 1st %04x %08b -> %08b',$a, $test->{fill}, $mem[$a]) );
141 }
142
143 dump_callbacks;
144
145 $PC = 0x1000;
146 ok( M6502::exec( 1001 ), 'M6502::exec again' );
147 cmp_ok( $PC, '==', 0x1016, 'PC moved' );
148
149 foreach my $a ( 0x6000 .. 0x600c ) {
150 is( $mem[$a], $test->{fill}, sprintf('flipped 2nd %04x %08b -> %08b',$a, $test->{fill}, $mem[$a]) );
151 }
152
153 dump_callbacks;
154 }

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26