What's new

Chip 8

ector

Emulator Developer
aprentice, LXS: 1992 called, they want their compiler back :p

Modern compilers have compiled switches to jump tables wherever possible (and where it would improve performance) since many many years. Switches can be MUCH MUCH faster than a row of if/elses, and often ever so slightly faster than even function pointer arrays. I don't have MSVC right here (i'm not at my place atm), otherwise I'd show an example of what assembly it will output for some switch examples.
 

RipNLa

New member
Hey, this is my first post here. I'm a veteran-n00b programmer and I've decided to try and make a Chip8 emulator as well.

I was just wondering if anyone could direct me to some basic Windows programming, so I can learn to make a GUI for my emu. Someone posted a screenshot earlier in this thread of their emulator where they had what looked like a Dialog box acting as the debugger for their emulator. What's the best way to implement this? Win32, MFC, .NET? Any resources/links I can look at that would help? I need to learn some of these basic things, as well as how to like have a FILE..OPEN work (i know how to make Menu's, just not how to call the function..) Thanks in advance. Oh, and sorry if this isn't the correct thread for this...
 
Last edited:

RipNLa

New member
sethmcdoogle: Thx, that had exactly what I was looking for.

refraction: At first, I wanted to laugh since I thought cplusplus.com only had basic C++ tutorials. But then I saw their Win32 examples, and there is a couple of useful things in there as well, so thanks.
 

smcd

Active member
look up v8 or crazy chip-8 but if you read someone else's source you're likely to just want to copy it instead of trying stuff on your own :huh:
 

refraction

PCSX2 Coder
its not hard to do, just read up on the command, ive put a document HERE

just remember, start the program reading at position 0x200 and incrament it by 2 each cycle.
 

refraction

PCSX2 Coder
heres the source the Chuit chip 8 emulator by Doomulation with a couple of fixes by myself :) (he told me to upload it!!)

its not the easiest code to understand but it does pretty much everything

chuit8.zip
 

Doomulation

?????????????????????????
Save for that it's pretty slow. Hope it helps... to any n00b out there who wants to do their own chip8 emu.
 

aprentice

Moderator
i guess i'll release my chip8 source as well so people can learn from it. my source is probably the easiest to understand out of all chip8 emus cause its very neat and i kept the code simple :p

its fully emulates chip8 and schip8 but schip8 with problems. I havent had time lately to look into these bugs so if anyone fixes em, just post a reply to this post with the fix.

coded in vc++
 

refraction

PCSX2 Coder
only problems i can see is with the scroll

Scroll Left and Right are fixed to 4 pixel shifts.

there is no scroll up :p

Collision detection, set VF to 0 at the beginning of the command, cos if one part of the sprite collides, it will set to 1 , but then the next bit it draws, if it doesnt then its gonna set it to 0 again, so it thinks it aint collided :p

just before it plots the pixel put

if(vreg.memory[offset])
{
reg.v[0xF]=1;
vreg.memory[offset]=0;
}

and take the other bit out.

on drawsprite16 to cut the code down, just add
change xline to 16 and increase the yli
if(xline>8)
pixel=mem.memory[reg.i+yline+1];
else
pixel=mem.memory[reg.i+yline];

then modulate the shift
so its

if((pixel&(0x80>>(xline%8))
 

aprentice

Moderator
refraction said:
only problems i can see is with the scroll

Scroll Left and Right are fixed to 4 pixel shifts.

2 for chip8 and 4 for schip8

there is no scroll up :p

There is but its not working right :p

Collision detection, set VF to 0 at the beginning of the command, cos if one part of the sprite collides, it will set to 1 , but then the next bit it draws, if it doesnt then its gonna set it to 0 again, so it thinks it aint collided :p

just before it plots the pixel put

if(vreg.memory[offset])
{
reg.v[0xF]=1;
vreg.memory[offset]=0;
}

and take the other bit out.

im not sure i understand what you mean there :p

on drawsprite16 to cut the code down, just add
change xline to 16 and increase the yli
if(xline>8)
pixel=mem.memory[reg.i+yline+1];
else
pixel=mem.memory[reg.i+yline];

then modulate the shift
so its

if((pixel&(0x80>>(xline%8))

code size isnt an issue to me :p

Btw, the gfx glitches i speak of are in dragon1 schip8 game and dragon2 has problems too but its with scrolling.
 

smcd

Active member
aprentice i managed to crash your emulator in various ways. =)

1) don't load a rom & go to debug->Registers window, click "start" or "step"
2) don't load a rom & go to debug->Dump Video
3) load an invalid file (0bytes or non-chip8)
 

refraction

PCSX2 Coder
i didnt know about the scrolling in chip8, i knew it was available but ive never seen a game use it :p

what i mean with the collision detection, is on yours you set VF to 0 before it draws the sprite, thats good. but down the bottom just before it actually draws the sprite you have this
Code:
if(vreg.memory[offset]) 
				{ 
					reg.v[0xF]=1;
					vreg.memory[offset]=0;
				} 
				else 
				{
					reg.v[0xF]=0;
					vreg.memory[offset]=1;
				}
say the shape is **** right, the left 2 pixels collide with something, VF is set to 1, then it draws the other 2 pixels, VF is set to 0 again, so by the time the op is finished running, VF = 0, so the system thinks there hasnt been a collision ;) so just take out the else VF = 0 part.


Ill show you what i have for drawing a 16x16 sprite which works perfectly, im sure you can work the code out :)

Code:
	//Draw 16x16 Sprite
						
					int x = registers[((opcode&0x0F00)>>8)];
					int y = registers[((opcode&0x00F0)>>4)];
					int whatline = 0;
					registers[15] = 0x0; 
					for(int yline = 0; yline < 32; yline++) {
				
						char data = memory->readmem(I + yline);
						for(int xpix = 0; xpix < 16; xpix++) {
							if(xpix == 8) {
								yline++;
						data = memory->readmem(I + yline);}
						
							if((data&(0x80>>xpix%8)) != 0) {
							if((screen->GetPixel((x+xpix), (y+whatline)))==1) registers[15] = 0x1;  
								screen->SetPixel((x+xpix), (y+whatline));
								}
						}
						
						whatline++;
					}


For scroll down i could see this being the problem
Code:
int offset2=x+((y*scrolly)*128);
i would have said more
Code:
int offset2=x+((y+scrolly)*128);
scroll right change
Code:
offset2=(x+(y*128))+scrollx;
to
Code:
offset2=((x+scrollx)+(y*128));
(altho it probably wount change much :p )
and same sort of thing for Scroll Left
Code:
offset2=(x+(y*128))-scrollx;
to
Code:
offset2=((x-scrollx)+(y*128));



hope that helps :)
 

aprentice

Moderator
thanks for the heads up, i fixed those bugs you pointed out.

on the side note, i think the gfx glitches in the schip8 games are
comming from the 8bit sprite routine and not the 16bit sprite routine.

for example, the fighters in dragon1 are disfigured :p
 

refraction

PCSX2 Coder
i see what you mean, ive got it with mien as well, after about 5 seconds or so on Dragon1 it hangs after making some illegal calls, could be a corrupt game?

2nd one, got the scrolling working almost properly, just got like a trail on the propellers, but i dont know whats causing that
 

aprentice

Moderator
refraction said:
i see what you mean, ive got it with mien as well, after about 5 seconds or so on Dragon1 it hangs after making some illegal calls, could be a corrupt game?.....
on your emu?
it works fine on mine except for the corrupt character sprites.
The rom is not corrupt because it works fine under other schip8 emus.
 

refraction

PCSX2 Coder
aprentice said:
on your emu?
it works fine on mine except for the corrupt character sprites.
The rom is not corrupt because it works fine under other schip8 emus.


yeh, i mean as i said dragon2 (Which is a helicopter game :huh: ) works pretty much fine on mine, as does most if not all schip8 games, just Dragon1 the characters seem to start in the middle of the air for some reason.

plus it starts calling invalid op codes and gets itself into an endless loop.


this is where Dragon1 seems to go all wrong

0x804 Opcode 0x4440 Called.
0x808 Opcode 0x8441 Called.
0x80a Opcode 0x442 Called.
0x80c Opcode 0xfc44 Called.
Invalid Op Call at 0x80e opcode 0xfc44
0x80e Opcode 0x58 Called.
0x810 Opcode 0xffe0 Called.
Invalid Op Call at 0x812 opcode 0xffe0
0x812 Opcode 0x0 Called.
0x814 Opcode 0x0 Called.
0x816 Opcode 0x0 Called.
0x818 Opcode 0x400 Called.
 
Last edited:

Top