Acme-6502

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN


0.72 2008-09-24
 - Added a test suite pulled from the monkeynes project
    * patched script_7C.txt to work properly
    * patched script_94.txt to test proper mem location
    * patched script_95.txt to test proper mem location
    * patched script_96.txt to test proper mem location
    * patched all branching tests to do proper negative branches
    * patched script_40.txt and script_00.txt with proper diag info and proper
      PC storage on BRK
 - Fix PLP to clear B flag instead of setting it
 - Fix TSX to set N and Z flag based on the value of X
 - Emulate a page boundary bug in JMP instructions
 - Fix BRK to set B flag

0.71 2007-11-08
 - A new dawn in the struggle to free ourselves from the shackles of version 
   number oppression.

0.70 2007-11-07
 - An end to version number madness. I hope.

0.0.6 2007-02-23
 - Added machine readable license.

lib/Acme/6502.pm  view on Meta::CPAN

package Acme::6502;

use warnings FATAL => 'all';
use strict;
use Carp;

our $VERSION = '0.77';

# CPU flags
use constant {
  N => 0x80,
  V => 0x40,
  R => 0x20,
  B => 0x10,
  D => 0x08,
  I => 0x04,
  Z => 0x02,
  C => 0x01
};

t/monkeynes.t  view on Meta::CPAN

  my $reg = uc( defined $_[0] ? $_[0] : '' );

  _diag( 'CPU Registers' ) if !$reg;
  _diag( sprintf '  PC:    $%X', $cpu->get_pc )
   if !$reg || $reg eq 'PC';
  _diag( sprintf '  SP:    $%X', $cpu->get_s ) if !$reg || $reg eq 'SP';
  _diag( sprintf '  ACC:   $%X', $cpu->get_a )
   if !$reg || $reg eq 'ACC';
  _diag( sprintf '  IX:    $%X', $cpu->get_x ) if !$reg || $reg eq 'IX';
  _diag( sprintf '  IY:    $%X', $cpu->get_y ) if !$reg || $reg eq 'IY';
  # this should be fixed to handle just one flag at a time
  _diag( '  Flags  S V - B D I Z C' )
   if !$reg || $reg =~ m{^(PS|[SVBDIZC])$};
  _diag(
    sprintf '  PS:    %d %d %d %d %d %d %d %d',
    split( //, sprintf( '%08b', $cpu->get_p ) )
  ) if !$reg || $reg =~ m{^(PS|[SVBDIZC])$};
}

sub _diag {
  return unless $ENV{DIAG_6502};

t/monkeynes/script_18.txt  view on Meta::CPAN

clear
power on
regs

op 38

# C flag should now be 1
test c = 1

op 18

# C flag should now be 0 again
test c = 0

save verify_18.txt

t/monkeynes/script_38.txt  view on Meta::CPAN

clear
power on
regs

op 38

# C flag should now be 1
test c = 1

save verify_38.txt

t/monkeynes/script_58.txt  view on Meta::CPAN

clear
power on
regs

op 78

# I flag should now be 1
test i = 1

op 58

# I flag should now be 0 again
test i = 0

save verify_58.txt

t/monkeynes/script_65.txt  view on Meta::CPAN

clear
power on
regs

# No flags case ----------------------------
memset 00be 12

op 18
op a9 55
op 65 be

# Should be: ACC=67, C=0, V=0, S=0, Z=0
test acc = 67
test c = 0
test v = 0
test s = 0
test z = 0

# Carry flag case --------------------------
memset 00be e7

op 18
op a9 fe
op 65 be

# Should be: ACC=E5, C=1, V=0, S=1, Z=0
test acc = e5
test c = 1
test v = 0
test s = 1
test z = 0

# Overflow and Negative flag case ----------
memset 00be 12

op 18
op a9 75
op 65 be

# Should be: ACC=67, C=0, V=1, S=1, Z=0
test acc = 87
test c = 0
test v = 1
test s = 1
test z = 0

# Zero flag case ---------------------------
memset 00be 8e

op 18
op a9 72
op 65 be

# Should be: ACC=0, C=1, V=0, S=0, Z=1
test acc = 0
test c = 1
test v = 0

t/monkeynes/script_69.txt  view on Meta::CPAN

clear
power on
regs

# No flags case ----------------------------
op 18
op a9 55
op 69 12

# Should be: ACC=67, C=0, V=0, S=0, Z=0
test acc = 67
test c = 0
test v = 0
test s = 0
test z = 0

# Carry flag case --------------------------
op 18
op a9 fe
op 69 e7

# Should be: ACC=E5, C=1, V=0, S=1, Z=0
test acc = e5
test c = 1
test v = 0
test s = 1
test z = 0

# Overflow and Negative flag case ----------
op 18
op a9 75
op 69 12

# Should be: ACC=67, C=0, V=1, S=1, Z=0
test acc = 87
test c = 0
test v = 1
test s = 1
test z = 0

# Zero flag case ---------------------------
op 18
op a9 72
op 69 8e

# Should be: ACC=0, C=1, V=0, S=0, Z=1
test acc = 0
test c = 1
test v = 0
test s = 0
test z = 1

t/monkeynes/script_6D.txt  view on Meta::CPAN

clear
power on
regs

# No flags case ----------------------------
memset beef 12

op 18
op a9 55
op 6d efbe

# Should be: ACC=67, C=0, V=0, S=0, Z=0
test acc = 67
test c = 0
test v = 0
test s = 0
test z = 0

# Carry flag case --------------------------
memset beef e7

op 18
op a9 fe
op 6d efbe

# Should be: ACC=E5, C=1, V=0, S=1, Z=0
test acc = e5
test c = 1
test v = 0
test s = 1
test z = 0

# Overflow and Negative flag case ----------
memset beef 12

op 18
op a9 75
op 6d efbe

# Should be: ACC=67, C=0, V=1, S=1, Z=0
test acc = 87
test c = 0
test v = 1
test s = 1
test z = 0

# Zero flag case ---------------------------
memset beef 8e

op 18
op a9 72
op 6d efbe

# Should be: ACC=0, C=1, V=0, S=0, Z=1
test acc = 0
test c = 1
test v = 0

t/monkeynes/script_75.txt  view on Meta::CPAN

clear
power on
regs

# No flags case ----------------------------
memset 00be 12

op 18
op a9 55
op 75 be

# Should be: ACC=67, C=0, V=0, S=0, Z=0
test acc = 67
test c = 0
test v = 0
test s = 0
test z = 0

# Carry flag case --------------------------
memset 00be e7

op 18
op a9 fe
op 75 be

# Should be: ACC=E5, C=1, V=0, S=1, Z=0
test acc = e5
test c = 1
test v = 0
test s = 1
test z = 0

# Overflow and Negative flag case ----------
memset 00be 12

op 18
op a9 75
op 75 be

# Should be: ACC=67, C=0, V=1, S=1, Z=0
test acc = 87
test c = 0
test v = 1
test s = 1
test z = 0

# Zero flag case ---------------------------
memset 00be 8e

op 18
op a9 72
op 75 be

# Should be: ACC=0, C=1, V=0, S=0, Z=1
test acc = 0
test c = 1
test v = 0

t/monkeynes/script_78.txt  view on Meta::CPAN

clear
power on
regs

op 78

# I flag should now be 1
test i = 1

save verify_78.txt

t/monkeynes/script_8A.txt  view on Meta::CPAN


# IX should now show $55
test ix = 55

op 8a

# ACC and IX should now show $55
test acc = 55
test ix = 55

# Now for the Z flag case --------------------
power on

op a9 55
op a2 00

# Use the IY register to reset Z
op a0 01

# Should be: ACC=55, IX=0, Z=0
test acc = 55
test ix = 0
test z = 0

op 8a 

# Should be: ACC=0, IX=0, Z=1
test acc = 0
test ix = 0
test z = 1

# Now for the S flag case --------------------
power on

op a9 55
op a2 f2

# Use the IY register to reset S
op a0 01

# Should be: ACC=55, IX=F2, S=0
test acc = 55

t/monkeynes/script_98.txt  view on Meta::CPAN


# IY should now show $55
test iy = 55

op 98

# ACC and IY should now show $55
test acc = 55
test iy = 55

# Now for the Z flag case --------------------
power on

op a9 55
op a0 00

# Use the IX register to reset Z
op a2 01

# Should be: ACC=55, IY=0, Z=0
test acc = 55
test iy = 0
test z = 0

op 98 

# Should be: ACC=0, IY=0, Z=1
test acc = 0
test iy = 0
test z = 1

# Now for the S flag case --------------------
power on

op a9 55
op a0 f2

# Use the IX register to reset S
op a2 01

# Should be: ACC=55, IY=F2, S=0
test acc = 55

t/monkeynes/script_A8.txt  view on Meta::CPAN


# ACC should now show $55
test acc = 55

op a8 

# ACC and IY should now show $55
test acc = 55
test iy = 55

# Now for the Z flag case --------------------
power on

op a9 00
op a0 55

# Use the IX register to reset Z
op a2 01

# Should be: ACC=0, IY=55, Z=0
test acc = 0
test iy = 55
test z = 0

op a8 

# Should be: ACC=0, IY=0, Z=1
test acc = 0
test iy = 0
test z = 1

# Now for the S flag case --------------------
power on

op a9 f2
op a0 55

# Use the IX register to reset S
op a2 01

# Should be: ACC=F2, IY=55, S=0
test acc = f2

t/monkeynes/script_AA.txt  view on Meta::CPAN


# ACC should now show $55
test acc = 55

op aa 

# ACC and IX should now show $55
test acc = 55
test ix = 55

# Now for the Z flag case --------------------
power on

op a9 00
op a2 55

# Use the IY register to reset Z
op a0 01

# Should be: ACC=0, IX=55, Z=0
test acc = 0
test ix = 55
test z = 0

op aa 

# Should be: ACC=0, IX=0, Z=1
test acc = 0
test ix = 0
test z = 1

# Now for the S flag case --------------------
power on

op a9 f2
op a2 55

# Use the IY register to reset S
op a0 01

# Should be: ACC=F2, IX=55, S=0
test acc = f2

t/monkeynes/script_B8.txt  view on Meta::CPAN

clear
power on
regs

# create an overflow
memset 1000 40
op 2c 0010

# V flag should now be 1
test v = 1

op b8

# V flag should now be 0 again
test v = 0

save verify_B8.txt

t/monkeynes/script_BA.txt  view on Meta::CPAN

# Only SP should now show $55
test ix = 0
test sp = 55

op ba

# SP and IX should now show $55
test sp = 55
test ix = 55

# Now for the Z flag case --------------------
power on

op a2 00
op 9a
op a2 55

# Clear Z with the ACC
op a9 01

# Should be: IX=55, SP=0, Z=0

t/monkeynes/script_BA.txt  view on Meta::CPAN

test sp = 0
test z = 0

op ba

# SP and IX should now show $00 and Z should be 1
test sp = 0
test ix = 0
test z = 1

# Now for the S flag case --------------------
power on

op a2 f2
op 9a
op a2 55

# Clear S with the ACC
op a9 01

# Should be: IX=55, SP=F2, S=0

t/monkeynes/script_D8.txt  view on Meta::CPAN

clear
power on
regs

# this instruction is 6502 compatible but not 
# supported by the NES
op f8

# D flag should now be 1
test d = 1

op d8

# D flag should now be 0 again
test d = 0

save verify_D8.txt

t/monkeynes/script_F8.txt  view on Meta::CPAN

clear
power on
regs

# this instruction is 6502 compatible but not 
# supported by the NES
op f8

# D flag should now be 1
test d = 1

save verify_F8.txt



( run in 0.474 second using v1.01-cache-2.11-cpan-94b05bcf43c )