An emulator written in C#.
There is a demonstration loading and running Notch's test program at line 252.
There is a little reference trickery in the method CPU.RefLoc which was to avoid writing that switch statement twice, but overall it should be easy to understand as I've tried to follow the spec to the letter. I'll be here if they're any questions.
Just updated your iPhone? You'll find new features for TV, Messages, News, and Shortcuts, as well as important bug fixes and security patches. Find out what's new and changed on your iPhone with the iOS 17.6 update.
6 Comments
This is excellent. Thank you for sharing! It was pretty easy to follow, especially given all the debug examples in your "Program" class. In following, I'm trying to figure out what happens when it crashes though. Could you explain?
To clarify: "Crash" as in notches example that you demonstrated... or is that just his way of exiting the code when he's done, or does it actually create a tight infinite loop like it looks like to me?
The program as-posted stops after stepping through 50 instructions (as I wanted to verify it ran Notch's example correctly).
To observe the infinite loop, simply change the for-loop "for (int i = 0; i < steps; i++)" to an infinite loop "while(true)".
Ah, yes. I didn't catch that at first look. Good. It seems that to develop a good tool to test upon, a stop-gap to halt after a certain number of loops would be a good idea. Makes me wonder how much CPU time is going to end up getting eaten up by infinite loops & other poor coding mistakes (or pranks?) in the 0x10c cloud once the game launches.
To clarify: The emulator stops after 50 steps, so I don't see a bunch of console output just running past. And yes, Notch's code does have an infinite loop in it. ;)
I got to say I'm really impressed with the emulator! I haven't done anything this low-level truthfully ever. I've done some C++ games a loooonnngg time ago but nothing this complex.
I would love to see a more detailed explanation or even a commented version of the source code because as a web dev this goes way over my head!
Share Your Thoughts