IMHO this is a good example of how OOP can obfuscate. Over a dozen classes, all almost the same. This could easily be condensed into a single lookup table.
For comparison, here is a complete 8086 emulator, and it also includes some code to emulate other hardware of the PC:
Re:Comp Mark II: Simple 4-bit/1 Hz Virtual Computer
by gjm11 on Sunday October 04, 2015 @09:14AM
(#10327431)
In fairness, (1) a lot of the verbosity of the code here is because of the way C++ makes you separate out declarations and definitions, and makes you declare member functions even when they are just overriding virtual member functions in a base class, and in a nicer language equivalent code would be distinctly less painful; and (2) the 8086 emulator is able to be nice and small partly because its author is very, very, very clever. (Note: author of 8086tiny is my boss.)
Re:Comp Mark II: Simple 4-bit/1 Hz Virtual Computer
by w0utert on Sunday October 04, 2015 @10:52AM
(#10327680)
The code is just normalized to separate each bit of functionality and each class into its own source file, which IMO can hardly be seen as a negative. Yes you could do the same in a lot less lines of code, in a single source file, but that does not necessarily mean the code would be 'better' (easier to read, debug, maintain), just shorter and easier to analyse by quickly scanning it. If someone would ever like to add more advanced features to this simulator, the advantages of the normalisation and separation of concerns will quickly outweigh the 'downside' of having a few more files than absolutely necessary.
Re:Comp Mark II: Simple 4-bit/1 Hz Virtual Computer
by Narishma on Sunday October 04, 2015 @07:21AM
(#10327228)
That looks to be an 8-bit CPU. It has an 8-bit accumulator and instructions are encoded in 8-bits. The only 4-bit thing in there is the address space, but even that is really 2*4-bits.
https://github.com/gto76/comp-m2/tree/master/src
...that's quite a bit more code than I was expecting.
https://github.com/gto76/comp-m2/blob/master/src/specific_in...
https://github.com/gto76/comp-m2/blob/master/src/specific_in...
IMHO this is a good example of how OOP can obfuscate. Over a dozen classes, all almost the same. This could easily be condensed into a single lookup table.
For comparison, here is a complete 8086 emulator, and it also includes some code to emulate other hardware of the PC:
https://github.com/adriancable/8086tiny/blob/master/8086tiny...