From 62c36e6e09bd939c02d575396fc9cde1f50e9838 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Fri, 6 Apr 2012 03:16:49 -0500 Subject: don't increment pc until the op finishes executing --- t/pc.t | 373 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 373 insertions(+) create mode 100644 t/pc.t (limited to 't/pc.t') diff --git a/t/pc.t b/t/pc.t new file mode 100644 index 0000000..156b165 --- /dev/null +++ b/t/pc.t @@ -0,0 +1,373 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; + +use Games::Emulation::DCPU16; + +=begin assembly_code + + SET [0x0002],PC + +=end assembly_code + +=cut + +{ + my $cpu = Games::Emulation::DCPU16->new; + $cpu->load("\x71\xe1\x00\x02"); + + $cpu->step; # load 0x0002 + + is_deeply( + $cpu->memory, + [ + 0x71e1, 0x0002, + (0) x (0x10000 - 2) + ] + ); + is_deeply( + $cpu->registers, + [ (0x0000) x 8 ], + ); + is($cpu->PC, 0x0000); + is($cpu->SP, 0x0000); + is($cpu->O, 0x0000); + is($cpu->clock, 1); + + $cpu->step; # execute SET [0x0002], PC + + is_deeply( + $cpu->memory, + [ + 0x71e1, 0x0002, + (0) x (0x10000 - 2) + ] + ); + is_deeply( + $cpu->registers, + [ (0x0000) x 8 ], + ); + is($cpu->PC, 0x0002); + is($cpu->SP, 0x0000); + is($cpu->O, 0x0000); + is($cpu->clock, 2); +} + +=begin assembly_code + + SET [0x0006], 0x02 + :loop SET [0x0007], PC + SET PC, loop + +=end assembly_code + +=cut + +{ + my $cpu = Games::Emulation::DCPU16->new; + $cpu->load("\x89\xe1\x00\x06\x71\xe1\x00\x07\x7d\xc1\x00\x02"); + + $cpu->step; # load 0x0006 + + is_deeply( + $cpu->memory, + [ + 0x89e1, 0x0006, 0x71e1, 0x0007, 0x7dc1, 0x0002, + (0) x (0x10000 - 6) + ] + ); + is_deeply( + $cpu->registers, + [ (0x0000) x 8 ], + ); + is($cpu->PC, 0x0000); + is($cpu->SP, 0x0000); + is($cpu->O, 0x0000); + is($cpu->clock, 1); + + $cpu->step; # execute SET [0x0006], 0x02 + + is_deeply( + $cpu->memory, + [ + 0x89e1, 0x0006, 0x71e1, 0x0007, 0x7dc1, 0x0002, 0x0002, + (0) x (0x10000 - 7) + ] + ); + is_deeply( + $cpu->registers, + [ (0x0000) x 8 ], + ); + is($cpu->PC, 0x0002); + is($cpu->SP, 0x0000); + is($cpu->O, 0x0000); + is($cpu->clock, 2); + + $cpu->step; # load 0x0007 + + is_deeply( + $cpu->memory, + [ + 0x89e1, 0x0006, 0x71e1, 0x0007, 0x7dc1, 0x0002, 0x0002, + (0) x (0x10000 - 7) + ] + ); + is_deeply( + $cpu->registers, + [ (0x0000) x 8 ], + ); + is($cpu->PC, 0x0002); + is($cpu->SP, 0x0000); + is($cpu->O, 0x0000); + is($cpu->clock, 3); + + $cpu->step; # execute SET [0x0007], PC + + is_deeply( + $cpu->memory, + [ + 0x89e1, 0x0006, 0x71e1, 0x0007, 0x7dc1, 0x0002, 0x0002, 0x0002, + (0) x (0x10000 - 8) + ] + ); + is_deeply( + $cpu->registers, + [ (0x0000) x 8 ], + ); + is($cpu->PC, 0x0004); + is($cpu->SP, 0x0000); + is($cpu->O, 0x0000); + is($cpu->clock, 4); + + $cpu->step; # load 0x0002 + + is_deeply( + $cpu->memory, + [ + 0x89e1, 0x0006, 0x71e1, 0x0007, 0x7dc1, 0x0002, 0x0002, 0x0002, + (0) x (0x10000 - 8) + ] + ); + is_deeply( + $cpu->registers, + [ (0x0000) x 8 ], + ); + is($cpu->PC, 0x0004); + is($cpu->SP, 0x0000); + is($cpu->O, 0x0000); + is($cpu->clock, 5); + + $cpu->step; # execute SET [0x0007], PC + + is_deeply( + $cpu->memory, + [ + 0x89e1, 0x0006, 0x71e1, 0x0007, 0x7dc1, 0x0002, 0x0002, 0x0002, + (0) x (0x10000 - 8) + ] + ); + is_deeply( + $cpu->registers, + [ (0x0000) x 8 ], + ); + is($cpu->PC, 0x0002); + is($cpu->SP, 0x0000); + is($cpu->O, 0x0000); + is($cpu->clock, 6); + + $cpu->step; # load 0x0007 + + is_deeply( + $cpu->memory, + [ + 0x89e1, 0x0006, 0x71e1, 0x0007, 0x7dc1, 0x0002, 0x0002, 0x0002, + (0) x (0x10000 - 8) + ] + ); + is_deeply( + $cpu->registers, + [ (0x0000) x 8 ], + ); + is($cpu->PC, 0x0002); + is($cpu->SP, 0x0000); + is($cpu->O, 0x0000); + is($cpu->clock, 7); + + $cpu->step; # execute SET [0x0007], PC + + is_deeply( + $cpu->memory, + [ + 0x89e1, 0x0006, 0x71e1, 0x0007, 0x7dc1, 0x0002, 0x0002, 0x0002, + (0) x (0x10000 - 8) + ] + ); + is_deeply( + $cpu->registers, + [ (0x0000) x 8 ], + ); + is($cpu->PC, 0x0004); + is($cpu->SP, 0x0000); + is($cpu->O, 0x0000); + is($cpu->clock, 8); + + $cpu->step; # load 0x0002 + + is_deeply( + $cpu->memory, + [ + 0x89e1, 0x0006, 0x71e1, 0x0007, 0x7dc1, 0x0002, 0x0002, 0x0002, + (0) x (0x10000 - 8) + ] + ); + is_deeply( + $cpu->registers, + [ (0x0000) x 8 ], + ); + is($cpu->PC, 0x0004); + is($cpu->SP, 0x0000); + is($cpu->O, 0x0000); + is($cpu->clock, 9); + + $cpu->step; # execute SET [0x0007], PC + + is_deeply( + $cpu->memory, + [ + 0x89e1, 0x0006, 0x71e1, 0x0007, 0x7dc1, 0x0002, 0x0002, 0x0002, + (0) x (0x10000 - 8) + ] + ); + is_deeply( + $cpu->registers, + [ (0x0000) x 8 ], + ); + is($cpu->PC, 0x0002); + is($cpu->SP, 0x0000); + is($cpu->O, 0x0000); + is($cpu->clock, 10); +} + +=begin assembly_code + + :loop SET PC, loop + +=end assembly_code + +=cut + +{ + my $cpu = Games::Emulation::DCPU16->new; + $cpu->load("\x7d\xc1\x00\x00"); + + $cpu->step; # load 0x0000 + + is_deeply( + $cpu->memory, + [ + 0x7dc1, + (0) x (0x10000 - 1) + ] + ); + is_deeply( + $cpu->registers, + [ (0x0000) x 8 ], + ); + is($cpu->PC, 0x0000); + is($cpu->SP, 0x0000); + is($cpu->O, 0x0000); + is($cpu->clock, 1); + + $cpu->step; # execute SET PC, loop + + is_deeply( + $cpu->memory, + [ + 0x7dc1, + (0) x (0x10000 - 1) + ] + ); + is_deeply( + $cpu->registers, + [ (0x0000) x 8 ], + ); + is($cpu->PC, 0x0000); + is($cpu->SP, 0x0000); + is($cpu->O, 0x0000); + is($cpu->clock, 2); + + $cpu->step; # load 0x0000 + + is_deeply( + $cpu->memory, + [ + 0x7dc1, + (0) x (0x10000 - 1) + ] + ); + is_deeply( + $cpu->registers, + [ (0x0000) x 8 ], + ); + is($cpu->PC, 0x0000); + is($cpu->SP, 0x0000); + is($cpu->O, 0x0000); + is($cpu->clock, 3); + + $cpu->step; # execute SET PC, loop + + is_deeply( + $cpu->memory, + [ + 0x7dc1, + (0) x (0x10000 - 1) + ] + ); + is_deeply( + $cpu->registers, + [ (0x0000) x 8 ], + ); + is($cpu->PC, 0x0000); + is($cpu->SP, 0x0000); + is($cpu->O, 0x0000); + is($cpu->clock, 4); + + $cpu->step; # load 0x0000 + + is_deeply( + $cpu->memory, + [ + 0x7dc1, + (0) x (0x10000 - 1) + ] + ); + is_deeply( + $cpu->registers, + [ (0x0000) x 8 ], + ); + is($cpu->PC, 0x0000); + is($cpu->SP, 0x0000); + is($cpu->O, 0x0000); + is($cpu->clock, 5); + + $cpu->step; # execute SET PC, loop + + is_deeply( + $cpu->memory, + [ + 0x7dc1, + (0) x (0x10000 - 1) + ] + ); + is_deeply( + $cpu->registers, + [ (0x0000) x 8 ], + ); + is($cpu->PC, 0x0000); + is($cpu->SP, 0x0000); + is($cpu->O, 0x0000); + is($cpu->clock, 6); +} + +done_testing; -- cgit v1.2.3-54-g00ecf