What's new

Chip 8

refraction

PCSX2 Coder
yeh its most probably your drawing routine, maybe tis not drawing black pixels?

one thing you could try, at the moment you are copying your screen array to another array, try doing it straight from the normal screen array instead.
 

ChaosBlade

My Heart Chose.. Revenge.
Hey everyone, another NGEmu'er who found his way over here :p (so of course, greetings to all NGEmu members and other random people i might recognize like Keith, Martin & DW).

Im about to start my own chip8 emulator. after acquiring a bit of experience with programming in general (3 years of C in high-school, 6months of intensive (!) programming course at the army, as thats my position in it) and provided my knack for emulation, i thought id give it a shot. Im going over the david winters doc (revised one that refraction posted) at the moment, and im working in C++ console mode (havent worked with win32 API before, might try SDL).

After reading the entire thread, Any special things i need to be aware of before starting, or any cool tips you can provide ? anything will be appriciated :p
 

hap

New member
yeah, the chip8doc (linked to on page 22 of this thread) misses the point-to-s-chip-font instruction:

FX29 I points to the 4 x 5 font sprite of hex char in VX
FX30 I points to the 8 x 10 font sprite of hex char in VX (s-chip function)
 

refraction

PCSX2 Coder
hap said:
yeah, the chip8doc (linked to on page 22 of this thread) misses the point-to-s-chip-font instruction:

FX29 I points to the 4 x 5 font sprite of hex char in VX
FX30 I points to the 8 x 10 font sprite of hex char in VX (s-chip function)


expanding on that, the chip8 system has a whole 200bytes of space at the beginning of the memory (as the games are loaded in from 0x200 onwards) so that should provide you pleanty of room to put your fonts for chip8 and schip8 :)
 

ChaosBlade

My Heart Chose.. Revenge.
Indeed. I think it was mentioned earlier in the thread.
Thanks for the tips though. Ive read through David Winter's Document as it is on the copy on your site (refraction's), and made a few comments on which sizes are everything and general things like those, aswell as a list of chip8 and schip8 opcodes.

I also looked quickly in aprentice's sourcecode aswell as bcrew's (i think ? Miracle chip8) to get a general idea on how the emulator runs (load rom, reset 'hardware', endless opcode fecthing loop).

Dont think ill get it as quick as you guys, since im not especially good with assembly and the relevent topics (havent worked with memory addresses much tho i do have alot of exp. with pointers and alike).

Anyhow, Thanks for all the great info on this thread, Imma get ChaoC8 started ;)
 

smcd

Active member
refraction said:
expanding on that, the chip8 system has a whole 200bytes of space at the beginning of the memory (as the games are loaded in from 0x200 onwards) so that should provide you pleanty of room to put your fonts for chip8 and schip8 :)

Uhh, 0x200 is 512 bytes ;)
 

ChaosBlade

My Heart Chose.. Revenge.
Indeed =p

Ok, First question: i looked at some sources loading the font into memory, cause i was confused, and im still am: why is it loaded the way it is ? a.k.a, why that certain list of values means zero or one, etc .. im missing something crucial here i think.

EDIT: nvm, looked back in the thread cause i remembred aprentice already dissassembled Pong! .. Opcode fetching works, then :)
 
Last edited:

ChaosBlade

My Heart Chose.. Revenge.
Ok, done coding the chip8 parts of the emulator (no schip8 opcodes etc implanted yet).

I wanna make sure my drawing opcode is correct, is this the result of the first 7 opcodes in pong! ? (4 6xxx assign codes, one Axxx I assign code, two DXYN draw codes.) ?

Code:
/----------------------------------------------------------------\
|                                                                |
|                                                                |
|                                                                |
|                                                                |
|                                                                |
|                                                                |
|                                                                |
|                                                                |
|                                                                |
|                                                                |
|                                                                |
|                                                                |
|  *                                                            *|
|  *                                                            *|
|  *                                                            *|
|  *                                                            *|
|  *                                                            *|
|  *                                                            *|
|                                                                |
|                                                                |
|                                                                |
|                                                                |
|                                                                |
|                                                                |
|                                                                |
|                                                                |
|                                                                |
|                                                                |
|                                                                |
|                                                                |
|                                                                |
|                                                                |
\----------------------------------------------------------------/
 

ChaosBlade

My Heart Chose.. Revenge.
Well yea, its an ascii gfx 'engine' anyway :p

Attaching ChaoC8 v0.1 - It Plays Pong Completely (No sound, i hate the friggin buzzer :p).

EDIT: blitz works, brix crashes when the paddle hits one of the edges - i think the 8xy4 opcode is doing something wrong on the VF carry save. Anyone wanna check the opcode out ? its kinda late, will work on it tommorow, but feel free to check. Attaching Source - used only one .cpp file, might look messy to some :p
 
Last edited:

Pontifice

Learning
In function

Code:
void ReverseSubRegs()
{
	if (arrcRegisters[REG_X] <= arrcRegisters[REG_Y])
	{
		arrcRegisters[0xF] = 0x1;
	}
	else
	{
		arrcRegisters[0xF] = 0x0;
	}
}
where is the substraction ?

In
Code:
void DrawSprite()
{
	// Resetting Collision Detection.
	arrcRegisters[0xF] = 0x0;

	if ((sCurrOpcode & 0x000F) == 0)
	{
		// Draw SCHIP8 Sprite Of Size 16x16.
		// * Not Implanted Yet :P *
	}
	else
	{
		// Draw CHIP8 Sprite Of Size 8xN
		for (int nSpriteY = 0; nSpriteY < (sCurrOpcode & 0x000F); nSpriteY++)
		{
			for (int nSpriteX = 0; nSpriteX < SPRITE_X; nSpriteX++)
			{
				if ((arrcMemory[sI + nSpriteY] & (0x80 >> nSpriteX)) != 0)
				{
					// Checking For Collision (Overwrite Pixel).
					if (arrcScreen[arrcRegisters[REG_Y] + nSpriteY]
								  [arrcRegisters[REG_X] + nSpriteX] == 1)
					{
						// Collision Detected.
						arrcRegisters[0xF] = 1;
					}

					// XOR Painting Current Pixel.
					arrcScreen[arrcRegisters[REG_Y] + nSpriteY]
							  [arrcRegisters[REG_X] + nSpriteX] ^= 1;
				}
			}
		}
	}

	UpdateScreen();
}
In
arrcScreen[arrcRegisters[REG_Y] + nSpriteY][arrcRegisters[REG_X] + nSpriteX]
arrcRegisters[REG_Y] + nSpriteY; could be > 31
and
[arrcRegisters[REG_X] + nSpriteX]; could be > 63
 
Last edited:

Doomulation

?????????????????????????
Well, i've no idea how your source is, because I don't have winrar here and I don't care to get it :p
Pong looks alright, from what I remember. Just one quick note: you don't need to modulate your coordinates in any way, despite what anyone says. This is ONLY used in field. Shouldn't cause any errors whatsoever otherwise.

As for doc, use winters. There are faulty docs out there, so watch out!
 

Pontifice

Learning
Just one quick note: you don't need to modulate your coordinates in any way, despite what anyone says. This is ONLY used in field. Shouldn't cause any errors whatsoever otherwise.

Ummm maybe a program will be wrong if it draws out of the screen, but if a emulator crash because a bad written rom it is wrong programmed also.
 

hap

New member
ChaosBlade, in function ShiftRegLeft: replace &0x10 with >>7.

As for not modulating, I think this is why Brix crashes.
 

ChaosBlade

My Heart Chose.. Revenge.
Pontifice: Thanks, thats what i get for working late at night, missing code lines.

So the modulating would refer to pontifice's note about the drawing opcode might be drawing out of screen. Ill try and see if this is whats causing brix to crash. hap, thanks, simpler (and perheps more correct) way of doing that ;)

EDIT: After compering between NeoCHIP8's running of pong to mine, when the paddles go out the edges they instantly reappear at the other side (the part of the paddle that went overboard). In mine, currently, the paddle appears only after ALL of it went overboard, meaning im drawing out of the screen. Tried adding modulating (as you can see in the attached code section) to the coordinates, but that messes up other games like blitz.

Code:
for (int nSpriteY = 0; nSpriteY < (sCurrOpcode & 0x000F); nSpriteY++)
{
	for (int nSpriteX = 0; nSpriteX < SPRITE_X; nSpriteX++)
	{
		nScreenY = (arrcRegisters[REG_Y] + nSpriteY) % 32;
		nScreenX = (arrcRegisters[REG_X] + nSpriteX) % 64;

		if ((arrcMemory[sI + nSpriteY] & (0x80 >> nSpriteX)) != 0)
		{
			// Checking For Collision (Overwrite Pixel).
			if (arrcScreen[nScreenY][nScreenX] == 1)
			{
				// Collision Detected.
				arrcRegisters[0xF] = 1;
			}

			// XOR Painting Current Pixel.
			arrcScreen[nScreenY][nScreenX] ^= 1;

			// Logging Drawing.
			logDrawing(nScreenX,nScreenY);
		}
	}
}
 
Last edited:

Doomulation

?????????????????????????
As stated, modulating does NOT help. If a rom draws outside the screen, the emulator should take notice of this. This is called a "stable" program. I can't be sure as to why it overlaps like thus, I'm not sure my emulator shows them until they're completely off the screen either. And I don't believe it's supposed to do it either.

Oh and here's another source you can check out:
http://www.zophar.net/Files/Chuit_Src.zip

It emulates all known chip8 and super chip8 games that I know of.
 
Last edited:

ChaosBlade

My Heart Chose.. Revenge.
Hmm, ignoring overflowing pixels. Dunno, ill try that, im a bit confused as to why games attempt to draw out of the screen on purpose.

Refraction: then how does blitz works for you guys ? it draws the last line of the towers in y32, if you did that y = 0 then it would appear at the top of the screen.
 

Top