What's new

Chip 8

bgilb

New member
Well all the other instructions aren't used by INVADERS, so those can't be the problem with the gfx glitch.

Its so wierd too because, why does it do it on those 2 tiles and none of the otherones?

Heres a list of all the ones it uses:
(From when it starts to when it glitchs)
0x1
0x3
0x6
0x7
0xFX1E
0xANNN
0xDXYN
 
Last edited:

bcrew1375

New member
Ah, are they being properly modulated? Once the V registers pass 255 they need to be reset to 0. Are they perhaps passing 255? If that's the case, you are right about it being number 0x7. If those registers exceed 255 and then are added to the index, that could possibly screw up the graphics.
 
Last edited:

bcrew1375

New member
Well, the best way would be to make the registers 8-bit variables, or a single byte variable, they usually modulate themselves. If not, then you can simply do a logical and on the register with 255 "register & 255" after doing anything that could make it exceed 255. The index would be "index & 4095." I can't say that'll fix it, but you won't know until you try. Oh, that's right! The Chip8 has no subtract constant function, it subtracts a constant by adding. So, if the registers are not modulated it would cause problems with anything that needs to subtract a constant. Oh, I shouldn't need to say this, but don't modulate the index register when the instruction points it to the font. :p
 
Last edited:

bcrew1375

New member
Have you checked to see if the numbers are modulated correctly? Try adding to the register so it will go over 255, then print out it's value. 256 should be 0. BTW, your code looks much cleaner now. I'd forget about modulating the index, you probably won't need it.
 
Last edited:

refraction

PCSX2 Coder
your stack code is wrong, you arent incrementing the stack pointer, nor are you pointing the stacked PC to the correct place.

this is the code you should have

To return

Code:
case 0xEE:
                      {
                          if(SP>0)
			  {
                                SP--;
				PC=stack[SP];
				System.out.print("RETURN Subroutine! XXXX");
		      	  }
                      }
			break;

and to call the sub routine

Code:
case 0x2000:
{
System.out.println("Jump to Sub");
if(SP<16)
   {
     stack[SP++]=(PC + 2);
     PC=(opcode&0x0FFF);
   }
}
break;


also

0xC000 is wrong, think you should revise that one. you have no shift left, your collision detection is a bit wrong in 0xD000.

also you have no 0xE000 case opcodes, altho that probably wont effect your graphics problem, you just wont have any controls :p

Edit: actually you haev a couple of opcodes missing, id look at the docs if i were you, make sure you are using dave winters doc, ive got it uploaded on the link below for you.

Chip8doc
 
Last edited:

bgilb

New member
Yeah i know im missing alot, but as I said the space invaders title doesn't use much, Im pretty sure it has no collision. So why would missing ones that don't use it effect the title?


Thanks for pointing out the stack errors

Some things to note: The blitz title is draw in much of the same way as the space invaders except that the length is 16, and it turns out perfectly fine..
:

http://lockandload.8m.com/chip8-3.png

Im looking into the register exceeding 255 right now..
 
Last edited:

bgilb

New member
opcode 0x2KXX isn't called till after the title screen is drawn :\


but i looked into what bcrew said and there are alot of 0's where it looks like there shouldn't be but im not sure, Any non 0 is pretty much below 40

i get some wierd calls at the start, like
0x6000
and 0x6100
both of these put nothing into register [0] and [1], perhaps they're for clearing them though?

Heres all the calls it makes before it draws the first broken tile ( the D ):
http://lockandload.8m.com/regerror.png
 
Last edited:

refraction

PCSX2 Coder
well can you show your compete drawing routine? not just the opcode.

and actually i think subroutines are called quite a few times during the title.
 

refraction

PCSX2 Coder
hmm, i think that drawing code is a lil off, ill show you what i did back when i used a text based graphics engine, dunno where you got the +8 and +40 rubbish from...

Note: i was using a single dimension array, instead of 2 dimension.

Code:
void TextGraphics::UpdateScreen() {
	system("cls");

	for(int y = 0; y < 32; y++) {
		for(int x = 0; x < 64; x++) {
			if(ScreenBuffer[x + (y*64)] == 1)
				cout<<"#";
			else
				cout<<" ";
		}
		cout<<endl;
	}}
 

bgilb

New member
I tried switching my array to 1D but now the program is crashing :-\
EDIT: Fixed the problem with the index out of bounds, but now all i see is 100% white pixels ( 0xDXYN must not be setting any values )

Array index out of bounds :-\
Code:
public static char[] screen = new char[60*32];

Heres the draw routine,
Code:
public void paint(Graphics g)
	{
		g.setColor(Color.black);
		g.fillRect(0,0,this.getWidth(),this.getHeight());
		g.setColor(Color.white);
		char[] newScreen = new char[64*32];
		for(int x = 0;x<63;x++)
		{
			
			for(int y = 0;y<31;y++)
			{
				newScreen=Chip8Emu.screen;
				if(newScreen[(x)+(y*64)]>=1)
				{
					g.setColor(Color.white);
					g.fillRect(((x)*2)+8,((y)*2)+40,2,2);
					
				}
				if(newScreen[(x)+(y*64)]!=1)
				{
					g.setColor(Color.white);
					g.fillRect(((x)*2)+8,((y)*2)+40,2,2);
					
				}
				
			}
		}
	}

//and 0xDXYN
Code:
				case 0xD000:
				
					int X = register[(opcode&0x0F00)>>8];
					int Y = register[(opcode&0x00F0)>>4];
					for (int yline=0;yline<(opcode&0x000F);yline++)
					{
						int data = memory[I+yline]; //this retreives the byte for a give line of pixels
						for(int xpix=0;xpix<8;xpix++)
						{
 							if ((data&(0x80>>xpix))!=0)
 							{
								if (screen[register[X] +(register[Y]*64)]==1) register[0xF]=1; //there has been a collision
								
								screen[register[X] +(register[Y]*64)]^=1; //note: coordinate registers from opcode
							}
							
						}
						
					}
					PC+=2;
				break;
 
Last edited:

refraction

PCSX2 Coder
how have you initialized screen at the top of your code? should be screen[64*32] or screen[2048];

and you will have to have all your display code follow a simular thing to the code i showed you

so your drawing routine will change to

if(screen[(X + xpix) + ((Y + yline)*64)] >= 0x1) register[0xF] = 1;

screen[(X+xpix)+((Y+yline)*64)]^=0x1;
 

refraction

PCSX2 Coder
public static char[] screen = new char[60*32];

thats why, its 64*32, not 60.

look at your for loop, y is 63 there (altho i think thats missing a pixel), so no wonder its out of bounds

edit: and your gfillrect lines are wrong, im guessing your doubling the size so you want

g.fillRect(((x)*2),((y)*2),2,2);
 
Last edited:

bgilb

New member
yeah i fixed that, now all its drawing is a 64x32 grid of white pixels, and when it gets to a draw sprite it does nothing
 

refraction

PCSX2 Coder
bgilb said:
yeah i fixed that, now all its drawing is a 64x32 grid of white pixels, and when it gets to a draw sprite it does nothing


look at your code, tell me what colours you are setting for both black and white pixels :happy:
 

bgilb

New member
Argh!! forgot i had copied that code and put it there ^ ^, okay thats solved, but now all its draw is about 5 pixels set across the screen like so:


. . . . .


updated drawing code:
Code:
public void paint(Graphics g)
	{
		g.setColor(Color.black);
		g.fillRect(0,0,this.getWidth(),this.getHeight());
		g.setColor(Color.white);
		char[] newScreen = new char[64*32];
		newScreen=Chip8Emu.screen;
		for(int y = 0;y<63;y++)
		{
			int data = newScreen[y];
			for(int x = 0;x<31;x++)
			{
				if((data&(0x80>>x))!=0)
 				{
					g.setColor(Color.white);
					g.fillRect(((y)*2)+8,((x)*2)+40,2,2);
					
				}
				else
				{
					g.setColor(Color.black);
					g.fillRect(((y)*2)+8,((x)*2)+40,2,2);
					
				}
				
			}
		}
	}

Thanks for your ongoing help btw :D
 
Last edited:

refraction

PCSX2 Coder
bedause you are getting the value from the register in your drawing routine then trying to get it from a register again with the value you originally got :p

you have to change the setpixel stuff to

screen[(X + xpix) +((Y*64)+yline)]^=1;


do the same changes for your collision


Edit: on your drawing code take out them damn +8 and +40, you really dont need that :p
 

Top