aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2012-04-05 11:48:39 -0500
committerJesse Luehrs <doy@tozt.net>2012-04-05 11:48:39 -0500
commit1ab52f775c9791e440adba515c8295b121fcb8ef (patch)
treee3a811ce3d056ff8e6421cd60583b2b5b8a62651 /lib
parent0a275c6ae1ed1d6de807f0dc8c2d29fe222140c0 (diff)
downloadgames-emulation-dcpu16-1ab52f775c9791e440adba515c8295b121fcb8ef.tar.gz
games-emulation-dcpu16-1ab52f775c9791e440adba515c8295b121fcb8ef.zip
SP starts at 0
Diffstat (limited to 'lib')
-rw-r--r--lib/Games/Emulation/DCPU16.pm18
1 files changed, 7 insertions, 11 deletions
diff --git a/lib/Games/Emulation/DCPU16.pm b/lib/Games/Emulation/DCPU16.pm
index dd0855c..41dbbf8 100644
--- a/lib/Games/Emulation/DCPU16.pm
+++ b/lib/Games/Emulation/DCPU16.pm
@@ -21,7 +21,7 @@ sub new {
memory => [(0x0000) x 0x10000],
registers => [(0x0000) x 8],
PC => 0x0000,
- SP => 0xffff,
+ SP => 0x0000,
O => 0x0000,
halt => undef,
@@ -186,13 +186,15 @@ sub _parse_value {
$self->{$key} = $value - 0x20;
}
elsif ($value == 0x18) {
- $self->{$key} = $self->{memory}[++$self->{SP}];
+ $self->{$key} = $self->{memory}[($self->{SP}++ & 0xffff)];
+ $self->{SP} &= 0xffff;
}
elsif ($value == 0x19) {
$self->{$key} = $self->{memory}[$self->{SP}];
}
elsif ($value == 0x1a) {
- $self->{$key} = $self->{memory}[$self->{SP}--];
+ $self->{$key} = $self->{memory}[(--$self->{SP} & 0xffff)];
+ $self->{SP} &= 0xffff;
}
elsif ($value == 0x1b) {
$self->{$key} = $self->{SP};
@@ -491,7 +493,8 @@ sub _op_JSR {
return if $self->_delay(2);
- $self->{memory}[$self->{SP}--] = $self->{PC};
+ $self->{memory}[(--$self->{SP} & 0xffff)] = $self->{PC};
+ $self->{SP} &= 0xffff;
$self->{PC} = $a;
}
@@ -504,10 +507,6 @@ sub _op_HLT {
=for notes
-is SP defined to start at 0xffff?
-
-is PC defined to start at 0?
-
behavior of MOD?
behavior of underflow?
@@ -521,9 +520,6 @@ does memory start out as 0, or undefined?
what happens when an invalid op is read?
-POP should be [++SP] and PUSH should be [SP--] (actually PUSH shouldn't return
-anything, probably)
-
=cut
1;