diff options
author | Jesse Luehrs <doy@tozt.net> | 2012-04-06 03:16:49 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2012-04-06 03:16:49 -0500 |
commit | 62c36e6e09bd939c02d575396fc9cde1f50e9838 (patch) | |
tree | dc20a6f97a85228715b79a7f8134a6e7f8505105 /t/pc.t | |
parent | 3394c2ace3a2c555cce22095f66cfc258873d8c0 (diff) | |
download | games-emulation-dcpu16-62c36e6e09bd939c02d575396fc9cde1f50e9838.tar.gz games-emulation-dcpu16-62c36e6e09bd939c02d575396fc9cde1f50e9838.zip |
don't increment pc until the op finishes executing
Diffstat (limited to 't/pc.t')
-rw-r--r-- | t/pc.t | 373 |
1 files changed, 373 insertions, 0 deletions
@@ -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; |