What's new

Chip 8

]-[ D X

New member
I didn't know the console wasn't 100% reliable. Thank you for the info :)

I've never heard about "dump" before, after a little research with the terms "dump java" on google I see "thread dump" and "head dump" appearing a lot.

Is that what you're talking about ?

All the char cast are definitely a pain in the ass but the console of processing specificly told me to do so and won't "compile" if I don't.

You are right about " V[x] += V[x] + kk;" I should have kept it, my bad :p

the random() function comes from processing, I tried to include <stdlib,h> but the console give me the error "unexpected token: class"

I really feel like my problem comes from my misunderstanding of processing.


Ohh no a dump is just a text file where you log your instructions
The IDE shouldn't dictate what you do. Type casting (forcing a variable type different that the one you originally declared) shouldn't be an issue.

Type casting works like this. You say int var = 256;
if you try to print the value it will be in fact be 256
now if you cast it (char)var that will produce the ASCII character number 256 (which is an blank space)
as far as i see that's your problem along with the adding on top. You can get rid of your

it was dot on the include my bad try wth
#include <stdlib.h>
 

Okabe

New member
Including the line "#include <stdlib.h>" gave me the error: unexpexted char: "i"

Thank you for you explanation about type casting, I tried to change every "char" into "int" and it worked....but it didn't change my problem :p

But at least, I know that I don't need to use "char" contrarely to what I thought.
 

]-[ D X

New member
I meant a dump like a log. just logging your println functions.
Dude i'm concerned about your (char) all over your code are killing your functionality

it's like declaring something and asking for other thing. that's why typecasting is dangerous. go back to the drawing board cause your code should work without needing it to typecast like that... i'm a little rusty as i'm currenlty working on gameboy, but let me see if i can find the resource doc i used

- - - Updated - - -

I mean you don't use (char) nor (int) at all... you just let the compiler work with your declared variable type

- - - Updated - - -

http://www.multigesture.net/articles/how-to-write-an-emulator-chip-8-interpreter/ look at the Fetch opcode.
If you use a char variable for opcode whenever you shift, you should be getting rid of a part of your actual opcode. The only reason you are getting away with it is cause your are type casting hard... like telling the compiler... "Nah dude just use whatever it fits" instead of what you intended. As a side effect it seems you are indeed catching the start of the opcode but not the rest of the content

1201 a full opcode could be interpreted on your end as 1200 that's why i posted a log of my execution before.
also the program counter should also be a short variable.

btw dont use char use unsigned char and unsigned short to tell the compiler you are only allowing positive numbers
 
Last edited:

Okabe

New member
I don't know how to log my println in a file but I'll check that out.

I used char for opcode because from what I remember of my research about chip8 emulation, I thought I had to use unsigned type for opcodes otherwise the bit shifting would possibly be more complex and because you could possibly get a value too high (above 255) that wouldn't be recognized by the chip8.

But I tried to get rid of every char, since you told me that those type casting could be the problem.
It didn't break my emulator, but it didn't solve the problem neither.

I made a second folder with my chip8 emaulator without any char.
https://github.com/Okarin85/Chip8-Processing/blob/master/Chip8_2/Chip8_2.pde

I couldn't get rid of the int cast at the line 38 because if I do, I get the error : unexpected token: int
I couldn't get rid of the int cast at the line 75 because the random() function return a float, if I try without casting randomNumber in a int, it gives me the error : The operator & is undefined for the argument type(s) float, int

If I use a short for the variable pc I got an error at the line 49.
It says : "cannot convert from int to short"

It's because at the line 49, I'm setting "pc" to the value of "nnn".
pc = nnn;

and the variable nnn can only be an int since it results from the operator "&"
int n = opcode & 0x000F;

I think you're right to be concerned about all of those type casting.
it confuses me a lot but believe me, I didn't came out with all those type casting on my own.
It's the results of all my attempts to fix the errors that processing is giving me.

I greatly appreciate the time and the effort you gave to help me with this but I'm done with processing :p
I going to try to make my emulator with c and sdl.
Since you did a lot to help me, I'll keep you inform of my progress on this.

Thank you very much ]-[ D X :D
 

]-[ D X

New member
Just for documenting Sake:
We already solved the issue

The problem was that he was updating the program counter after the switch, this effectively ruined the program counter for Jump instructions as it was moving the program counter more than once per JUMP

Summary:

Dont do this
switch (opcode) {
case : 0x0
break;
.
.
.case n
break;

pc += 2; // this will mess your jump instructions and possibly others

}
//instead update the counter in their own body
 

dmaass

New member
Hoi

I started an Chip8 emulator in VB and it's looking not that bad (no keyboard/sound, but the rest is implemented)
But tetris has an odd behavior: Instead of moving DOWN my blocks are alternating left to right and the scoring display is f*cked up?!
See at https://imgur.com/a/JMCkx

Other games like Pong, Maze etc look ok.

I read my opcodes atleast twice and they all look ok to me. Any suggestions what might be wrong?
 

kinder112

New member
Hey guys,

I just found this thread while googling for "Chip8 frequency" really nice to see such big community experimenting with their emu101.
I'm currently trying to fix bugs in my code. I've write it in Java + libgdx, it's complete function wise but still many games do glitch on me. Some simple games are playable already like pong or additions problem. But I'm still struggling with a Animal race and Airplanes. Will try to fix it with time and also read on this huge topic.

If someone would be interested in checking the code it's here https://github.com/kinder112/chip8 should be also quite easy to build and run.

Also Tetris fails for me similar to person above, probably some common gotcha? Will try to read previous pages maybe I'll find something to help me there :)

With regards,
Pawel
 
Last edited:

Danny

Programmer | Moderator
My final & best Chip8 Emulator

I just wrote another Chip8 Emulator to prepare me for the GameBoy :)

I started my GameBoy Emulator, but was very rusty, so I did this to shake off the cobwebs.
Ironically enough, this is my best Chip8 Emulator to date! (I've made a few).

It offers 100% compatibility with all the games I tested (69). Now on to the challenge of the GameBoy (been waiting for this day for 15 years now...).

I hope my Emulator is of help to some of you.

Compatible Games:

  • 15 Puzzle [Roger Ivie],
  • Addition Problems [Paul C. Moews],
  • Airplane,
  • Animal Race [Brian Astle],
  • Astro Dodge [Revival Studios, 2008],
  • Biorhythm [Jef Winsor],
  • Blinky [Hans Christian Egeberg, 1991],
  • Blitz [David Winter],
  • Bowling [Gooitzen van der Wal],
  • Breakout (Brix hack) [David Winter, 1997],
  • Breakout [Carmelo Cortez, 1979],
  • Brick (Brix hack, 1990),
  • Brix [Andreas Gustafsson, 1990],
  • Cave,
  • Coin Flipping [Carmelo Cortez, 1978],
  • Connect 4 [David Winter],
  • Craps [Camerlo Cortez, 1978],
  • Deflection [John Fort],
  • Figures,
  • Filter,
  • Guess [David Winter],
  • Hidden [David Winter, 1996],
  • Hi-Lo [Jef Winsor, 1978],
  • Kaleidoscope [Joseph Weisbecker, 1978],
  • Landing,
  • Lunar Lander (Udo Pernisz, 1979),
  • Mastermind FourRow (Robert Lindley, 1978),
  • Merlin [David Winter],
  • Missile [David Winter],
  • Most Dangerous Game [Peter Maruhnic],
  • Nim [Carmelo Cortez, 1978],
  • Paddles,
  • Pong (1 player),
  • Pong 2 (Pong hack) [David Winter, 1997],
  • Pong [Paul Vervalin, 1990],
  • Programmable Spacefighters [Jef Winsor],
  • Puzzle,
  • Reversi [Philip Baltzer],
  • Rocket [Joseph Weisbecker, 1978],
  • Rocket Launcher,
  • Rocket Launch [Jonas Lindstedt],
  • Rush Hour [Hap, 2006],
  • Russian Roulette [Carmelo Cortez, 1978],
  • Sequence Shoot [Joyce Weisbecker],
  • Shooting Stars [Philip Baltzer, 1978],
  • Slide [Joyce Weisbecker],
  • Soccer,
  • Space Flight,
  • Space Intercept [Joseph Weisbecker, 1978],
  • Space Invaders [David Winter],
  • Spooky Spot [Joseph Weisbecker, 1978],
  • Squash [David Winter],
  • Submarine [Carmelo Cortez, 1978],
  • Sum Fun [Joyce Weisbecker],
  • Syzygy [Roy Trevino, 1990],
  • Tank,
  • Tapeworm [JDR, 1999],
  • Tetris [Fran Dachille, 1991],
  • Tic-Tac-Toe [David Winter],
  • Timebomb,
  • Tron,
  • UFO [Lutz V, 1992],
  • Vers [JMN, 1991],
  • Vertical Brix [Paul Robson, 1996],
  • Wall [David Winter],
  • Wipe Off [Joseph Weisbecker],
  • Worm V4 [RB-Revival Studios, 2007],
  • X-Mirror,
  • ZeroPong [zeroZshadow, 2007],

Screenshots:

Fwee4Yo.jpg)

R6CkHKc.jpg)

UJyM3Lv.jpg)

XnU6NKC.jpg)

OsUseK4.jpg)

5iRm10S.jpg)

6QGLmSF.jpg)

jBE8SwI.jpg)

5ZxCbCN.jpg)

dX6A4OJ.jpg)

zIWBSdz.jpg)


Source Code:

The Emulator is written in C++ and uses SDL2 for Input & Windowing and OpenGL for rendering.

Get it on GitHub
 

kinder112

New member
Nice work Danny,

I was also able to fix bug in my code reading through this topic. The problem I had was that I didn't clear Carry (VF) on the beginning of DXYN opcode. Now seems like games work correctly but haven't done that much of testing. Next thing for me will be probably dynamic compiler or disassembler not sure yet :) Probably will pick GamBoy as next level as I see here it's most common next project for aspiring emu devs.

PS. Just checked animal race, I still have some bugs there as the animals get messed up during the race. What's the best way to debug this? Do I dump machine state and compare with other emulator? Any reference emulators for use?

Some screenshots:
XuYUzqE.png

J4MF1V8.png

GXmTWrr.png


Check out the code here: https://github.com/kinder112/chip8
 
Last edited:

Danny

Programmer | Moderator
Nice work Danny,

I was also able to fix bug in my code reading through this topic. The problem I had was that I didn't clear Carry (VF) on the beginning of DXYN opcode. Now seems like games work correctly but haven't done that much of testing. Next thing for me will be probably dynamic compiler or disassembler not sure yet :) Probably will pick GamBoy as next level as I see here it's most common next project for aspiring emu devs.

PS. Just checked animal race, I still have some bugs there as the animals get messed up during the race. What's the best way to debug this? Do I dump machine state and compare with other emulator? Any reference emulators for use?

Some screenshots:
XuYUzqE.png

J4MF1V8.png

GXmTWrr.png


Check out the code here: https://github.com/kinder112/chip8

Nice!

I have a few bugs in animal race too (they get jumbled together). Theres a few small bugs in my emulator still that I plan on fixing when I get bored.

When they're fixed, i'll let you know if it resolves the animal race issue.
 

spotanjo3

Moderator
Moderator
Nice!

I have a few bugs in animal race too (they get jumbled together). Theres a few small bugs in my emulator still that I plan on fixing when I get bored.

When they're fixed, i'll let you know if it resolves the animal race issue.

Good to hear from you, Danny.
 

shutterbug2000

New member
It might be a little unusual, but I recently wrote a Chip-8 emulator in SmileBasic for the 3DS. If you want to try it for yourself, let me know and I'll post the download key here.
 

dparrott

New member
Should I attempt a CHIP-8 emulator in python or C#?

There's no real correct answer to that, it can be done in either without any issues.

Which do you want to do it in? Is there one you're more comfortable with? Are you trying an emulator to improve one of those languages?

Those questions really answer your original question.
 

dwesti

New member
It is interesting to watch the work of different emulators
BC_test - failed
balls - no boundary check screen
sierp2 - wrong picture
clock - artefacts on screen or unknown opcod 02D8 at #2666
 

Attachments

  • psto.zip
    38.2 KB · Views: 0

Top