Re:Why did I spend 1.5 months creating a Gameboy emulator? (...
by TimTheTinker on Wednesday May 23, 2018 @06:06PM
(#17138806)
Is `while(true)` preferable to `for(;;)` to get an infinite loop?
The compiler probably optimizes the condition check out, so I doubt it really matters.
Re:Why did I spend 1.5 months creating a Gameboy emulator? (...
by a_e_k on Thursday May 24, 2018 @12:10AM
(#17141022)
When 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.
Re:Why did I spend 1.5 months creating a Gameboy emulator? (...
by souprock on Wednesday May 23, 2018 @07:38PM
(#17139477)
The 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.
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
And the instruction listing I used: http://obelisk.me.uk/6502/reference.html#AND