Introducing the NES WTFulator!



  • I saw this the other day http://hackaday.com/2012/10/12/emulators-101-how-to-write-a-program-that-functions-like-an-nes-cpu/ 

    his code evolved like this:

    1. Execute(int opcode) // implemented by switch statment
    2. Execute(int opcode) // implmented by IF chain
    3. Various changes to IF tests to indexed string literals
    4. template out the opcode parameter
    5. write macro for IF tests

    Why...The....Fuck... did he template out the opcode? I don't think "template (unsigned opcode)\nvoid ex()" is even valid syntax? I didn't watch long enough to see if he trys to compile that.

    It says C++11 in one of the titles but i don't think templates work like that.

    There seems to be source code at http://bisqwit.iki.fi/source/nes.html but none of the source files have the word template in them at all.

     




  • I think he meant to template out the assembly instructions.

    Like for example, the ADD instruction.

    If I recall 8086 assembly correctly, there's an immediate version (operand is in the next memory byte), indirect(next 2 bytes are a pointer to the memory address of the operand), x-indexed (x register is an offset, next 2 bytes are the base memory location), y-indirect (etc)



    Maybe he templated opcodes of assembly instructions that are the same (functionally) just different referentially or something?

    Wouldn't know for sure tho (since I didn't actually look at the source, and I don't really do C++ LOL, just googled templates... only since I used to do NES programming)



  • Welp, reread that, he said to template out the opcode PARAMETER (does that mean the operand?), not the opcode itself.
    Fits with what I said earlier.



  • Maybe he's using the word "template" to mean something other than the C++ keyword "template?" That's all I can think of. I'm not going to watch the videos, so.



  •  you don't actually have to watch the videos you can see the "template (unsigned opcode)" line in the screenshots on the hack-a-day page.



  • As far as I can tell, he's using a giant templated method declaring all the instructions, and defined a second method which accesses a statically defined jump table for all opcode methods. Then it lets the compiler perform dead code elimination for almost all lines from the 264 template-generated methods.
    It's basically a horrifying homegrown switch statement.
    Still, I can't work out why the hell he's using base64 encoded strings instead of the damn opcode number to begin with.



  • He's just using a font where parens and angle brackets look similar in low res.

    It says template<unsigned opcode>, which is perfectly valid; C++ templates can take any sort of parameter, not just types.

    It is basically a compile-time version of a virtual function call, although I haven't read the code and have no idea how it may be of any use here: surely he doesn't know which opcode to call until runtime?

    The bit that elicited this site's eponymous ejaculation from me was the base64 stuff. Base64 encoding, in 8-bit-clean memory, inside a (virtual) cpu? Is that really necessary?



  • @aihtdikh said:

    It is basically a compile-time version of a virtual function call, although I haven't read the code and have no idea how it may be of any use here: surely he doesn't know which opcode to call until runtime?

    He uses a jump table of all the various combinations. I'm guessing because he hates switch statements.

    @aihtdikh said:

    The bit that elicited this site's eponymous ejaculation from me was the base64 stuff. Base64 encoding, in 8-bit-clean memory, inside a (virtual) cpu? Is that really necessary?

    I watched the video again, and I finally realised what he was doing. He broke down the instruction set into single C operations, and basically composes them together dynamically at compile time.
    The base 64 encoded strings are actually a form of statement composition in C. Seriously.
    He says this makes it 'neat'.



  • @aihtdikh said:

    The bit that elicited this site's eponymous ejaculation from me
    Do you get paid every time you push the E key? Let me try... EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE nope still not working



  • @Ben L. said:

    @aihtdikh said:
    The bit that elicited this site's eponymous ejaculation from me
    Do you get paid every time you push the E key? Let me try... EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE nope still not working

    If only!

    No, I did that for ephemeral entertainment, to enhance my enjoyment of the empty everyday experience of responding to exasperated forum posts; and, I must admit, to expose an example of my erudition, embarrassingly enough. coughs

    Also I was tired.



  • How many times have you watched V?



  • @dhromed said:

    How many times have you watched V?


    Urgh, it does look that way, doesn't it? :(

    That is not what I was aiming for. I am not trying to be a member of Anonymous.



  • @aihtdikh said:

    Urgh, it does look that way, doesn't it? :(
    \

    Well, it's not a *bad* movie.



  • @dhromed said:

    @aihtdikh said:
    Urgh, it does look that way, doesn't it? :(
    Well, it's not a bad movie.

    I enjoyed this one:

    Thought this one was pretty stupid:
    (Didn't watch the remake.)



  •  Fuuuuck the SF miniseries was so bad so bad.



  • LOL, I didn't think those two shared anything in common other than the letter 'V' in the title.  One is a profetic sign of our times.  The other is about a nutter revolutionary in some dystopia that would never happen.



  • @pauly said:

    LOL, I didn't think those two shared anything in common other than the letter 'V' in the title. One is a profetic sign of our times. The other is about a nutter revolutionary in some dystopia that would never happen.

    But which is which!!!



  • @blakeyrat said:

    @pauly said:
    LOL, I didn't think those two shared anything in common other than the letter 'V' in the title. One is a profetic sign of our times. The other is about a nutter revolutionary in some dystopia that would never happen.

    But which is which!!!

     

    Dude I was going to post that.



  • @blakeyrat said:

    @pauly said:
    LOL, I didn't think those two shared anything in common other than the letter 'V' in the title. One is a profetic sign of our times. The other is about a nutter revolutionary in some dystopia that would never happen.
    But which is which!!!

    I have only vague memories of the non-comic book one, how close is that description?



  • @locallunatic said:

    I have only vague memories of the non-comic book one, how close is that description?

    The only thing I liked about the old one (I never watched the new series) was the old couple because of the WTF factor



  • @locallunatic said:

    I have only vague memories of the non-comic book one, how close is that description?
     

    Good and good.


Log in to reply