4 ms·
Show HN: Cycle-accurate Nintendo NES emulator in ~1000 lines of code
- Sephiroth87 10y agoI'm not sure if this can be technically defined as cycle accurate, since cpu instructions are still executed atomically, instead of executing each instruction cycle independently... I guess the end result is what matters and not the actual implementation? EDIT: I suck at c++
- andreaorru 10y agoIt's not atomical. Note that the PPU is constantly updated in the middle of the CPU instructions in a way that respects the timing of the original hardware. The relative order of operations between CPU and PPU is respected.
- Sephiroth87 10y agoYou're right, sorry ^^ Too many meta-programming tricks for me
- loboto3 10y agoSuch pregunta. Very clever. Many condense. Such switch. WOW. So emulator.
- Koshkin 10y agoThis is one example of how powerful and expressive C++ can be in the hands of the right person. I love (plain) C for its openness and the apparent ease of use but keep being amazed at how much more powerful as a language C++ is - to the point that C starts looking like a children's toy tool that should be abandoned as soon as the hand is strong enough to hold the real one.
- andreaorru 10y agoThanks (for calling me the right person). There is a price to pay for power in C++ though. Keeping the code beautiful and readable is often a challenge, as the syntax gets convoluted very quickly. I'm not the biggest fan of the Standard Template Library either. Lately I've been experimenting with D (https://dlang.org https://dlang.org), created by Walter Bright and Andrei Alexandrescu, both well known expert C++ programmers. D feels a lot like C++ should have been had it dropped some C compatibility in exchange for clarity. Its meta-programming capabilities are also far more powerful. I can think of features (like template mixins) that would make this project even more compact.
- closetheworld 10y agoThis is insanely good. I remember studying the code of other NES emulators and all of them easily passed the 10k lines mark. Makes you wonder how much repeated code is there.
- andreaorru 10y agoTo be fair I don't implement all the mappers, but I'm pretty confident the core parts of the emulator (CPU and PPU) are as small as it gets.