What's new

Need some help with CHIP-8 emulator rendering

sampleText

New member
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:(
 

]-[ D X

New member
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 :D if you need anything I´m also coding a chip8 emulator in c++ and SDL and I´m currently doing input calls and debuging why the hell the counter on pong refuses to go Up xD

Have fun
 
Last edited:

mendus

New member
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?
 

]-[ D X

New member
Sorry Mendus didn´t 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 :p )

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:
OP
S

sampleText

New member
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?
 

]-[ D X

New member
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 :p
 
Last edited:

Top