Release

CHIP8 Emulator

14

Greenpilloz 2021-01-05 00:54 (Edited)

- Nobody :
- Me : I'm gonna build an emulator for a fantasy console inside this emulator for a fantasy console !

Bio:
Created in 1977, CHIP-8 is the original fantasy console. Initially designed to ease game development for the COSMAC VIP kit computer, it has enjoyed several revivals over the decades for new and exciting platforms. Today, creating a CHIP-8 implementation is a rite of passage for anyone interested in learning about emulation.
(from https://chip-8.github.io/links/)

Links:
- technical references: http://devernay.free.fr/hacks/chip8/C8TECH10.HTM
- Awesome CHIP-8: https://chip-8.github.io/links/
- online emulator: https://www.chip8.net

Idea:
So basically it is an emulation of a simplified CPU, with 16 Register (like variables), a stack (to save the location when jumping to subroutines), some other special registers to store a location (I), a timer (DT), and a timer for a buzzing sound (ST), as well as 4Kb of RAM where the program, font and sprites are loaded. Every address in the RAM is an address from $000 to $FFF (in hex), the program starts at $200 the fonts are at $000. Every instruction consists of 2 Bytes, so the program starts at instruction $200, then $202, $204 etc...

Instructions:
- 00E0 - CLS
- 00EE - RET
- 0NNN - SYS ADDR
- 1NNN - JP ADDR
- 2NNN - CALL ADDR
- 3XKK - SE VX, BYTE
- 4XKK - SNE VX, BYTE
- 5XY0 - SE VX, VY
- 6XKK - LD VX, BYTE
- 7XKK - ADD VX, BYTE
- 8XY0 - LD VX, VY
- 8XY1 - OR VX, VY
- 8XY2 - AND VX, VY
- 8XY3 - XOR VX, VY
- 8XY4 - ADD VX, VY
- 8XY5 - SUB VX, VY
- 8XY6 - SHR VX {, VY}
- 8XY7 - SUBN VX, VY
- 8XYE - SHL VX {, VY}
- 9XY0 - SNE VX, VY
- ANNN - LD I, ADDR
- BNNN - JP V0, ADDR
- CXKK - RND VX, BYTE
- DXYN - DRW VX, VY, NIBBLE
- EX9E - SKP VX
- EXA1 - SKNP VX
- FX07 - LD VX, DT
- FX0A - LD VX, K
- FX15 - LD DT, VX
- FX18 - LD ST, VX
- FX1E - ADD I, VX
- FX29 - LD F, VX
- FX33 - LD B, VX
- FX55 - LD [I], VX
- FX65 - LD VX, [I]
(see http://devernay.free.fr/hacks/chip8/C8TECH10.HTM for details)

Keys:
- "123AZEQSDWXC" Correspond to the 16 keys "123456789ABCDEF" of the original console

Special Keys:
? -- Load from ROM
, -- Load from DISK.nx
; -- Restart
. -- Save to disk
+ -- Settings (change speed, key config...)
H -- Help
SPACE -- Do one step
ENTER -- Run
BCKSPCE -- Edit RAM
P -- Play Mode (Run faster, don't print debug info)

Comes with 23 preloaded games !!!

(to load any other CHIP8 game you can use the following command in a unix terminal:
c=0;for d in *.ch8; do echo "#$((c++)):$d"; hexdump -e '16/1 "%02x " "\n"' $d | tr -d ' ' | tr '[a-z]' '[A-Z]'; done >DISK.nx)

CHANGES:
25/03/21 - Fixed a bug with opcodes 8XY5, 8X06, and 8X0E (bit shifting and subtraction) that caused BLINKY to not work.

CHIP8.nx | Open in app
2021-03-25 12:09
CHIP8.nx | Open in app
2021-01-05 01:16
CHIP8.nx | Open in app
2021-01-05 00:54

Timo 2021-01-05 06:57

Wow!


DrGonzo 2021-01-05 07:46

Neat! Runs better than previous version! Gg


TrashCan Games 2021-01-05 14:50

Very nice


Nicky 2021-03-24 10:55

@greenpilloz,Blinky game doesn't work! Can you fix it?


Greenpilloz 2021-03-25 12:11 (Edited)

@Nicky got you covered pal ;-) It was a sneaky bug with bit shifting. I'm not sure what are the controls for this game but it seems to work now.

btw, it's quite unplayable at the default speed, you should put 20 cpu cycles per VBL or smthg like that (press '+' for settings), and play only in 'p' mode (press 'p' instead of enter for faster execution).


nathanielbabiak 2021-10-28 06:40 (Edited)

This is very impressive! I had no idea fantasy consoles have been around for so long. I've spent DAYS learning all that I can about CHIP-8, and making my own emulator in LowRes of course! A sincere 'thank you' for introducing me to this!

Also, do you find it interesting that all the stuff available online for CHIP-8 is about programming emulators, but nobody's programming games? (Except for Octo obviously, but I'm not sure that counts...)


Greenpilloz 2021-11-11 22:21

Thanks, I also learned a lot about CPUs and coding in assembler while doing this, and I was considering trying to make a simple game for the SNES. (If you don't know how it works, check it, you'll love it, it's really bare to the circuits! Check this video playlist for example https://youtu.be/57ibhDU2SAI, it's well made, and it's a good intro to the crazy complexity of coding for the SNES)

Yes, it is funny that with CHIP8 people seems to have more fun building emulators than making games! But I think it's funny too, that people seem to have more fun building game for Lowres than playing them, I know that's my case at least.


nathanielbabiak 2021-12-14 04:06 (Edited)

I had everything done almost two weeks ago, but I almost gave up on mine! I couldn't come up with anything elegant to convert the keyboard input from LowRes NX's 'stream' to chip8's 'poll', and a bunch of the super-chip games rely on that. (Ultimately, I begrudgingly converted the input handler from keyboard to gamepad).

It's here if you want to check it out.


Greenpilloz 2021-12-28 17:33

Yes, I saw your post. Sorry I didn't have the time to check it thoroughly (I was not sure about the controls so I didn't check further), but I will try to do so at some point.

I must admit that the controls are really bad in my version, since I barely try to play the games... I was mostly interested in simply having them run and having the possibility to play (not necessarily in an enjoyable way !)


Log in to reply.