Results 1 to 8 of 8
  1. #1
    EmuTalk Member
    Join Date
    Aug 2016
    Posts
    3
    Mentioned
    0 Post(s)

    Need some help with CHIP-8 emulator rendering

    DISCLAIMER: i'm a new member and I made an account just for this so please don't yell at me
    I'm working on a CHIP-8 emulator with C++ (actually C but SDL uses G++ so...), and i'm stuck.
    How should I re-draw the screen? Do I redraw every pixel manually, or what else?

    Please help

  2. #2
    EmuTalk Member
    Join Date
    May 2013
    Posts
    99
    Mentioned
    5 Post(s)
    Yes, you need to clear the buffer and draw it according to sprite positions for each frame.

  3. #3
    EmuTalk Member
    Join Date
    Aug 2016
    Posts
    3
    Mentioned
    0 Post(s)
    Thanks for the reply!

  4. #4
    EmuTalk Member
    Join Date
    Aug 2016
    Posts
    25
    Mentioned
    0 Post(s)
    Quote Originally Posted by mendus View Post
    Yes, you need to clear the buffer and draw it according to sprite positions for each frame.
    Excuse me, but are you certain about that?. I mean first of all that sounds terrible performance wise, and second as far as i know the chip8 draw rutine is only called when a DXYN type opcode is called so that would mean Keeping the vector/display array alive until the next update + XOR of Old display array vs new display array comes ( signaled by another DXYN opcode)

    My workflow is

    Wait for a DXYN opcode and decode it
    Get N = Number of Lines for the sprite to draw
    With a known N fill an Sprite Array starting at memory memory[I + 0] to [I + N]
    Get X = V[regX] = Starting pos X of the sprite
    Get Y = Y[regY] = Starting pos Y of the sprite

    Set a draw flag as true and call the draw function

    Then you mask and shift against the desired bit position and store it in your display array, repeat for every line of the sprite, XOR the whole display against the last time the display array was shown

    I hope this clears up your doubt and helps you keep going if you need anything Im also coding a chip8 emulator in c++ and SDL and Im currently doing input calls and debuging why the hell the counter on pong refuses to go Up xD

    Have fun
    Last edited by ]-[ D X; August 8th, 2016 at 15:50.

  5. #5
    EmuTalk Member
    Join Date
    May 2013
    Posts
    99
    Mentioned
    5 Post(s)
    Excuse me, but are you certain about that?.
    No, I am not certain. It's the most common approach (other sistem's do that) and no one had answered so I said it.

    So how does Chip 8 clear old data? Imagine you have a sprite with the shape of a 1 and you need to write a sprite with the shape of a 2. Does it XOR a 1 in order to clear first and then XOR a 2 to write?

  6. #6
    EmuTalk Member
    Join Date
    Aug 2016
    Posts
    25
    Mentioned
    0 Post(s)
    Sorry Mendus didnt mean to put you on the spot. I was asking in case documentations were outdated or something ( and I had to go and rework my drawing routine )

    As for clearing old sprite data...
    Yep that's exactly how it goes
    As for full screen clear there is an opcode for that 00E0 and then I just Push 0s into the whole display array and store it as last display
    Last edited by ]-[ D X; August 8th, 2016 at 22:36.

  7. #7
    EmuTalk Member
    Join Date
    Aug 2016
    Posts
    3
    Mentioned
    0 Post(s)
    Thanks! Just so you know, I've switched to Allegro and am making progress. But I had a question: does 00E0 set the draw flag?

  8. #8
    EmuTalk Member
    Join Date
    Aug 2016
    Posts
    25
    Mentioned
    0 Post(s)
    Quote Originally Posted by sampleText View Post
    Thanks! Just so you know, I've switched to Allegro and am making progress. But I had a question: does 00E0 set the draw flag?
    00E0 clears the screen.
    To clear the screen I push 0s to the whole current display matrix and also store that zeroed matrix as the last display

    Glad to know you are making progress. I'm pretty much stuck on a counter issue I'm having. Also mine is called chip4droid and I'm programming it all on my phone using c4droid and sdl2, but I only work on it while I travel every morning and afternoon ahha



    Pretty neat, but ugly way to debug... I'm currently learning how to blit/erase text with SDL_ttf but so far is resisting a bit

    Last edited by ]-[ D X; August 23rd, 2016 at 23:21.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •