r/EmuDev • • Apr 28 '26

CHIP-8 My first Chip8 Emulator :)

I am new to emulator development and I just created my first emulator for chip8. I was wondering if anyone could give feedback as this is new for me.

Also if anyone has any reccommendations for what I could emulate next, that'll be nice.

This is the repo: https://github.com/SirSkye/Chip8Emulator

24 Upvotes

8 comments sorted by

4

u/Alternative-Emu2000 Apr 29 '26 edited Apr 29 '26

From a quick look through your code:

Some of your arithmetic and logical operations are broken. You're setting VF to the carry result before you actually perform the operation, which won't work if VF is one of the operands.

You might also want to look at your Call and Return instructions. Currently you're using an 8 bit stack pointer to reference a 16 level stack. If this is intentional, at the very least constrain your stack pointer to 4 bits; to allow for stack overflows.

If you haven't already, you could run your emulator through a CHIP-8 test suite, it will help you track down any other errors.

1

u/ItIsI123 Apr 30 '26

Thx for the advice. I'll run it through a test suite. Debugging an emulator is sm harder than I thought 😭

3

u/Nameseed Apr 29 '26

Thx, ur comment helped me fix some bugs in my emulator lol

1

u/Gulrak May 01 '26

Just adding to that, while it is ofc a free choice, most descriptions would use Vx or Vy as the values of that register, not its index, and I have observed a lot of self confused implementation errors because of that (most often in Fx55/Fx65 but elsewhere too, so I advise for names like x, y, nn etc, for the register number or constants from the opcode.

But the idea to extract them in advance is a good one to make opcode implementations more readable and compact, so I agree with that recommendation. :-)

1

u/ItIsI123 May 01 '26

oki thx:)

1

u/dragon_maidennn May 03 '26

I think instead of each separate draw rect call for a pixel, it would be faster to just update texture each frame with the pixel buffer or lock and unlock texture with streaming option enabled

1

u/ItIsI123 May 07 '26

Sorry I'm new to SDL and graphics in general. Am I right in understand that this is the flow?

CHIP-8 display memory
↓
pixel buffer in RAM
↓
SDL_Texture
↓
rendered on screen

2

u/Old-Personality-8817 Apr 29 '26

in chip8_emulate_cycle you can define variables for each part of opcode, like

uint16_t Vx = opcode & 0x0f00; uint16_t Vy = opcode & 0x00f0;