mappum / DCPU-16

:floppy_disk: A javascript emulator for DCPU-16 (the computer system in Mojang's new game, 0x10c). Works in browsers and Node.
http://mappum.github.com/DCPU-16/
94 stars 18 forks source link

Fix stack handling. #23

Closed apage43 closed 12 years ago

apage43 commented 12 years ago

The spec specifies that POP is [SP++] and PUSH is [--SP].

Program that breaks without this fix is detailed here: http://0x10cforum.com/forum/m/4932880/viewthread/2713790-program-that-breaks-in-some-emulators

mappum commented 12 years ago

Did he really mean for push to decrement first? That would mean address 0xffff is never used.

Twisol commented 12 years ago

SP is supposed to start at 0, so the first time it's used, it decrements and wraps around to 0xFFFF.

EDIT: And now I can't find where I read that for some reason...

deps commented 12 years ago

The spec says stack starts at 0xffff but 0x10.cc linka to a tweet where he says it starts at 0. Confysing. :)

mappum commented 12 years ago

SP is supposed to start at 0, so the first time it's used, it decrements and wraps around to 0xFFFF.

Even on a PEEK?

Twisol commented 12 years ago

That's what gave me pause, yeah. Still trying to find my source on that, sorry...

Twisol commented 12 years ago

Here it is, thanks @deps for the tip-off: https://twitter.com/#!/notch/status/187636538870468608

mappum commented 12 years ago

Cool, pulled and your code works now. It's long, make sure to turn off debug to run it! (Setting the text in a textarea is slow).