
Comp Mark II: Simple 4-bit/1 Hz Virtual Computer - jsnathan
https://github.com/gto76/comp-m2/
======
userbinator
The architecture looks simple enough, but when I saw the source...

[https://github.com/gto76/comp-m2/tree/master/src](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_instruction.hpp)

[https://github.com/gto76/comp-m2/blob/master/src/specific_in...](https://github.com/gto76/comp-m2/blob/master/src/specific_instruction.cpp)

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...](https://github.com/adriancable/8086tiny/blob/master/8086tiny.c)

~~~
gjm11
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.)

------
Narishma
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.

------
cbd1984
I wonder why the Makefile builds everything with -O0

~~~
pizzaburek
It takes too long to compile otherwise, and I didn't want people to give up
during compilation... You can run 'make optimize' to use -O1

