What's new

Chip 8

givemeachance

New member
Can i ask all emu authors a question?

Can i take some parts of your code , and try to learn from them?
Of course , you'll be in credits!
 

d0u6

New member
Nice!!
When you're ready , can you please post the source?
I really wanna see how your app works :D


edit:
By the way , can you tell me how you render the tiles?
With resized quads? or with another way?:

My screen is a vector Screen[64*32]. I created a 640x320 window and the function that show the screen do this:

Code:
for (i=0; i<32 ; i++)  //for all lines...
{
	for (j=0; j<64; j++) // ...and rows
	{
		if (Screen[j + i*64]) // if there is a pixel to draw....
		{
			  glPointSize(10.0);          //set the pixel size
  			  glBegin(GL_POINTS);  //draw the pixel on the screen
  			  glVertex2i(i*10,j*10);
  			  glEnd();
		}
	}
}

It still needs some fixes, but is basicaly this.....

My Sprite function:

Code:
void sprite(BYTE pX, BYTE pY, BYTE Length) /*drys*/
{
	BYTE lineY=0, lineX=0;
	BYTE data,offset;
	
	if (V[pY] + Length > 32) Length = 32-V[pY];	
	
	for ( ; lineY<Length; lineY++)
	{
		data = Memory[I + lineY];
		for (offset=0 ; data!=0; data<<=1, offset++) //set screen until no more pixel remain in data
		{
			if (data & 0x80)
			{
				if (Screen[(V[pX]+64*(V[pY] + lineY) ) + offset] == 0x1) V[15]=1;
				Screen[(V[pX]+64*(V[pY] + lineY) ) + offset] ^= 0x1;
				
			}
		}	
	}
}
 
Last edited:

LotsArs

New member
My screen is a vector Screen[64*32]. I created a 640x320 window and the function that show the screen do this:

Code:
for (i=0; i<32 ; i++)  //for all lines...
{
	for (j=0; j<64; j++) // ...and rows
	{
		if (Screen[j + i*64]) // if there is a pixel to draw....
		{
			  glPointSize(10.0);          //set the pixel size
  			  glBegin(GL_POINTS);  //draw the pixel on the screen
  			  glVertex2i(i*10,j*10);
  			  glEnd();
		}
	}
}

Make sure you put your glPointSize(), glBegin() and glEnd() outside any loop and you'll save some GPU time. ;)

Code:
glPointSize(10.0);
glBegin(GL_POINTS);
for (i=0; i<32 ; i++)
{
	for (j=0; j<64; j++)
	{
		if (Screen[j + i*64])
		{
  			  glVertex2i(i*10,j*10);
		}
	}
}
glEnd();
 

Doomulation

?????????????????????????
Can i ask all emu authors a question?

Can i take some parts of your code , and try to learn from them?
Of course , you'll be in credits!

Go ahead. I'm sure lots of them wouldn't mind, if you credited them. Lots of emulators have the source available.
My own emulator, Chuit, for example is one such. Zophar has both binary and source if I recall correctly.
 

Garstyciuks

New member
I remember that my chip8 emulator couldn't properly emulate hap's sokoban game. So I have written a new emulator. I had this code written more than half a year ago, but didn't post it, because it isn't as complete as my other emulator. It still lacks some final touches, but the emulation part of it is fully finished. I am releasing it now, because I don't have enough time to work on it. While the emulation part of it is platform independent (I'm not sure about macs though), the frontend of the emulator uses wxWidgets and SDL. I can successfuly compile it on windows and linux with no changes in the code.

This emulator has better emulation code, while the other one is more 'complete' and has a debugger. So for studying emulation of chip8/schip, I would suggest reading the code of this emulator.

The controls are 1234, qwer, asdf and zxcv.

I will only provide source code for it. There are project files for MSVC 8.0 and Code::Blocks. If you decide to compile it manually, you need to link with wxWidgets (version 2.8.0 or higher) and SDL.

I don't mind people using my code as long as they don't make money from it :)
 

givemeachance

New member
Nice thanks for sharing the source!, i've made some progress while checking out your source.

Im only a little confused with binary math...so please , someone answer my questions!


1)
What does this part of the code?
PHP:
(flags & a_Random_flag)

2) Also , here ... what's happening?
the programmer removes the flag from the list??
PHP:
flags &= ~CPU_FLAGWAITING;

3)
LOL , what does this part of the code?
PHP:
 (mem->memory[pc+0]<<8)


4)
PHP:
memset(mem->vram, 0, 128*64);
Is similar to this :

PHP:
for y =  0 to 64
for x = 0 to 128
 vram[x][y] = 0;
???

5)
Why you need modulo here?
PHP:
 x_pos = ((x+i)%64)<<1;
 y_pos = ((y+j)%32)<<1;
 

Garstyciuks

New member
1) This is probably from some if conditions. It checks if some specific flag is set, or not.
2) it removes CPU_FLAGWAITING from the flags.
3) UINT16 opcode = (mem->memory[pc+0]<<8) | mem->memory[pc+1];

This piece of code loads the opcode from the chip8 memory into unsigned short variable. Say if memory[pc+0] is 0xD4 and mem->memory[pc+1] is 0x45, then opcode would be equal to 0xD445. And then this value is processed in the switch statement.

4) yes, the code is simillar
5) because the screen is 64 x 32 size. If the program is trying to draw outside the screen, it wraps it to the other side.
 

givemeachance

New member
I think i get it.
So , here:
PHP:
if (reg[(opcode&0x0F00)>>8] == reg[(opcode&0x00F0)>>4]) pc+=2;

This part is the fixed opcode value:
PHP:
reg[(opcode&0x0F00)>>8]

And this one:
PHP:
reg[(opcode&0x00F0)>>4]
The fixed memory value?

...Sorry for my newbie questions...............
 

krypt100

New member
SChip8 Intepreter (Release)

Alright I have decided to release my SChip8/Chip8 emulator after it has been sitting on my hard disk for months . It is written in JAVA and supports most of SChip8/Chip8 programs (except for some programs that end with .c8x), most of the game fixes(Hwrap,Vwrap..) that I use for my emulator come from Giedrius's, I already included all the credits in the About dialog box.

control type, qwerty
 
Last edited:

Garstyciuks

New member
It's nice that you found use from my emulator. But my name is Giedrius. :) I bet it's hard to pronounce it for english speakers... As well as my nickname. Most english people call me Garsty.
 

krypt100

New member
Ha, sorry about that. I already fixed the spelling and re-uploaded my emulator.
and my native language isn't English either I bet it will be hard for me to pronounce any word not in my language :)
 

bronxbomber92

New member
Hi,

I'm working on opcode Fx33. In the document I'm reading (http://devernay.free.fr/hacks/chip8/C8TECH10.HTM) it says
The interpreter takes the decimal value of Vx, and places the hundreds digit in memory at location in I, the tens digit at location I+1, and the ones digit at location I+2.

So, for example we have the hex number 0xFFFF (65535). My interpretation of the opcode would to store 5 (the hundreds digit) in memory, 3 (the tens digit) in memory[I+1] and 5 (the ones digit) in memory[I+2].

Is this what I should be doing? Or am I interpreting the doc wrong?

Here's my implementation in c++
Code:
case 0x33:
{
	memory[I] = static_cast<char>((VX%1000)*.01f);
	memory[I+1] = static_cast<char>((VX%100)*.1f);
	memory[I+3] = static_cast<char>(VX%10);
	break;
}
 

Doomulation

?????????????????????????
Doc says store the BCD representation of register X at I, I+1 and I+2. What BCD truly is, I don't know, unfortunately.
 

Garstyciuks

New member
BCD = Binary Coded Decimal, which means that each digit of a decimal number should be seperated to several bytes.

bronxbomber92: I think that your implementation is wrong. First of all, you have memory (lowercase i) in your 3rd line. And I don't really know if your code for determining the numbers works, but it can be done in a more efficient way. And what is VX? You should use the register which number is (opcode&0x0F00)>>8. Or was it only used as for an example? To get the digits, you have to do this:

third_num = num / 100; //assuming that num is not a float
second_num = (num % 100) / 10; //or second_num = (num / 10) % 10;
first_num = num % 10;

I don't remember in which exact order should the numbers be ordered in chip8 memory, there's only 2 possible ways to do that, so you should be able to figure it out easily.
 

Top