Sounds like fun.
Sounds like fun.
If he sticks with that, there are good few cross dev. tools. (even C ISTR)
It's just a big switch/case over the instruction set by the looks of it. Those things can get pretty damn large if your are implementing anything close to a proper CPU.
It's just very condensed, I imagine so he can change a bunch of values and re-test quickly.
int pos=(ram[PC++&0xffff]+X)&0xff; byte v=ram[(ram[pos]&0xff)|
And so on. It just seems like some sort of code generation would be much easier.Most likely when you have a bug in something like this it will be isolated to one specific instruction. So you can just zoom in on the bit you need.
If you followed the standard Java practice for this you would probably have an Instruction class that inherited from several base classes and that would make your project very large and difficult to navigate indeed.
Code generation doesn't need to be heavyweight.
0x0000
0x0001
0x0002
...
That help?
ram[PC++0xfff]&0xff
((ram[PC++0xfff]&0xff)|((ram[PC++0xfff]&0xff)<<8))
Of course Notch said it has been generated, so he probably had a neat definition that barfed this garbage out. But it's strange that so many commentators here are defending the output as a reasonable coding style for a VM!
Or BNE (branch not equal): if the last instruction (hopefully a compare) set the Z(ero) flag, jump ahead t instructions. otherwise don't do anything.
Maybe notch has asserted that if he can't fit what an instruction does in ~60 characters, that instruction is doing too much
I know this sounds like nitpicking, but that mistake right there has caused many a 6502 emulators to produce erroneous results. The 6502 core's status register is resident and the flags in it are changed only when an op-code directly does so; it never "resets" arbitrarily, so proper conditionals that act on a specific status flag can actually occur far and wide between the op-code that actually affected that one specific flag.
I've only briefly glanced through the dcpu-16 spec, but it doesn't seem to explicitly call Z or N by the names I've imputed, I think they're just regular registers that get used for a certain purpose sometimes.
"this _sounds_ like nitpicking"
when emulating a cpu, there's nothing but nits. pick away :)
CPUBuilder is most likely a class with a single method:
buildCPU()
{
return new CPU();
}