Hi,
Dunno if this is appropriate for this subforum, but I came across this video where a guy programmed a NES emulator in a 1000 lines of code.
Because it was a youtube video he had to make sure to not make it too long, so he made a lookup table for CPU "microinstructions". What I mean is he made a table/matrix that contained stuff like temp = X+=1; and X = temp.
So if there is an instruction that adds 1 to to the X register, the program would look inside the lookup table to see what is needed to do for this instruction, which is temp = X+=1 and then X = temp.
This is what such lookup table looks like:
There would of course be way more if's and 0's and 1's, but I hope you get the idea.
So let's say we have a fictional CPU with that is emulated with above table and the currect opcode would be 1, which would be to increment X by one. What it will do is look at the second number in the string, then if it's one it will execute the thing that "microinstruction" is meant to do.
So an instruction that increments by one would execute the first and second microinstruction, but not the last one since it's not needed for the opcode we are handling.
Now I believe the intention that the person in the video did it this way was because it uses less code, but I think it could implementing instructions way easier since you just need to select the right microinstructions for the instruction/opcode being executed.
So what I'm wondering is(and this is why I created this post), are there any other emulators that do this? It seems like a smart way to implement instructions. But it might impact performance(on slower PCs).
Thanks!
Dunno if this is appropriate for this subforum, but I came across this video where a guy programmed a NES emulator in a 1000 lines of code.
Because it was a youtube video he had to make sure to not make it too long, so he made a lookup table for CPU "microinstructions". What I mean is he made a table/matrix that contained stuff like temp = X+=1; and X = temp.
So if there is an instruction that adds 1 to to the X register, the program would look inside the lookup table to see what is needed to do for this instruction, which is temp = X+=1 and then X = temp.
This is what such lookup table looks like:
Code:
if ("0100100"[opcode] == '1') {temp = X+=1;};
if ("0101000"[opcode] == '1') {X = temp;};
if ("0010001"[opcode] == '1') {Y = temp;};
if ("0101000"[opcode] == '1') {X = temp;};
if ("0010001"[opcode] == '1') {Y = temp;};
There would of course be way more if's and 0's and 1's, but I hope you get the idea.
So let's say we have a fictional CPU with that is emulated with above table and the currect opcode would be 1, which would be to increment X by one. What it will do is look at the second number in the string, then if it's one it will execute the thing that "microinstruction" is meant to do.
So an instruction that increments by one would execute the first and second microinstruction, but not the last one since it's not needed for the opcode we are handling.
Now I believe the intention that the person in the video did it this way was because it uses less code, but I think it could implementing instructions way easier since you just need to select the right microinstructions for the instruction/opcode being executed.
So what I'm wondering is(and this is why I created this post), are there any other emulators that do this? It seems like a smart way to implement instructions. But it might impact performance(on slower PCs).
Thanks!