4 ms·
You could try writing a homebrew game for an old system. That's a pretty good way to learn things. Once you start on the emulator, the first thing you'll do is
by pubby 8y ago
You could try writing a homebrew game for an old system. That's a pretty good way to learn things.
Once you start on the emulator, the first thing you'll do is emulate the CPU, which can be done as a big switch statement inside of a loop. Knowing how to code each instruction is easy when you have an instruction listing handy.
Here's a quick example of how I would write an emulator, with 2 opcodes already implemented (6502 assembly): https://pastebin.com/raw/PhCEqh35 https://pastebin.com/raw/PhCEqh35
And the instruction listing I used: http://obelisk.me.uk/6502/reference.html#AND http://obelisk.me.uk/6502/reference.html#AND
- TimTheTinker 8y agoIs `while(true)` preferable to `for(;;)` to get an infinite loop? The compiler probably optimizes the condition check out, so I doubt it really matters.
- souprock 8y agoThe compiler won't care unless you "#define true 0". The "for(;;)" loop is easier and faster for the human to parse. It stands out in source code. With the "while(true)", you have to pay attention. It could be "while(tnie)" or "while(trua)". Whenever you see it, you have to read carefully.
- a_e_k 8y agoWhen I tested this in the distant past, I found that all the compilers I tried generated exactly the same assembly for both loops. I've seen it said that "The most optimizing compiler is the most normalizing compiler." [1] The infinite loop structure is pretty easy to normalize. The only real difference that I saw was that some compiler front ends would produce warnings that the condition in the while loop was always true, where they seemed to assume the empty for must be intentional. [1] https://www.cl.cam.ac.uk/techreports/UCAM-CL-TR-705.pdf https://www.cl.cam.ac.uk/techreports/UCAM-CL-TR-705.pdf