5 ms·
It's not quite as bad as it would be in a program other than an emulator, granted, but I can't imagine that it's easy to notice a bug in a 200-character line of
by someone13 15y ago
It's not quite as bad as it would be in a program other than an emulator, granted, but I can't imagine that it's easy to notice a bug in a 200-character line of:
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.
- jiggy2011 15y agoThis is true, but it should be easy enough to make a script that can pack/unpack the code as needed. 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.
- Tuna-Fish 15y agoYou cannot really do code-generation when all the lines have meaningful differences. What you saw was very likely the most compact representation of the VM -- any other form would likely be just as bad.
- viraptor 15y agoThat kind of code generation is unlikely to exist. Each line of that code has its own specific purpose, it's not some copy pasta. And surprisingly, it should be trivial to test it! there are no conditions of edge cases apart from the conditional instructions. As long as you test for ranges and off by ones, there's no space for mistakes really. I'd take that kind of code over usual "business logic" any time :-)
- pjscott 15y agoNonsense! Look at the code again. There are a lot of repeated motifs, like the things that fetch from memory and increment the program counter. It cries out to be partially automated. If nothing else, there has got to be a more human-readable equivalent to all that bit-masking and offset-adding. Code generation doesn't need to be heavyweight.
- cpeterso 15y agoEven some one-line functions or macros would make that code much more compact and readable.
- coopdog 15y agoOff by one errors, maybe we'll even bring back the golden age of buffer overflow exploits, emergent realistic hacking gameplay mechanics, Notch you're a genius...
- kingatomic 15y agoPart of the battle system could be causing segfaults in rival ship computers.