What's new

My PotatoChipAte

OP
glVertex3f

glVertex3f

Crap Cracker
Yeah, I do that alot (not enough), but today has been one of those days where your mind doesnt go as fast as you would hope ;)

Thats what my WriteLog function is for (wich I have working again).

right now its showing me all the instructions the rom is sending.. I compare that with the output from my "disassembler" program and see whats going on.

Im gonna add some more debug crap now so I can make it work better.

PS: Thank you DOOM and refraction for putting up with my noobness...Im sure i'll be back with another problem in a day or two (minutes)
 

refraction

PCSX2 Coder
glVertex3f said:
PS: Thank you DOOM and refraction for putting up with my noobness...Im sure i'll be back with another problem in a day or two (minutes)

haha its ok, your humor and willingness to admit your a n00b that compensates for it :) any more probs give either of us a shout
 
OP
glVertex3f

glVertex3f

Crap Cracker
Ok, I was looking over my code, and thought "DOH, Im not shifting my RegValues...."
When I was not shifting them... A few dots, some blinking, would appear on the screen... Now after I shifted the "vRegister"s it shows nothing...

Am I not suppose to shift them?

EDIT: I updated the zip incase anyone wanted to take a look. If you notice anything majorly wrong let me know.
 
Last edited:

refraction

PCSX2 Coder
you havent shifted them ;p

look a little advice when working with hex. if you want a single number say you got this for example

0x8264 <--- thats the add arithmetic opcode

say you do 0x0F00 to grab the 2, what you actually have there is 0x200, so you would be trying to access V[200] which is no good, so you need to shift it over. every number you go left from the end you add 4 to the shift like this

.0 x 0 0 0 0 <-- the hex
....12 8 4 0 <-- the shift to get it into a single number

so when you do vRegister[opcode&0x0F00] you are going for a number its its hundreds. so you wanna shift it like this

vRegister[((opcode&0x0F00)>>8)]

that will give you the single value you want.


may i suggest you read through the tutorial on the link below to get the basics of operators and working with hex etc.

cplusplus.com online tutorial
 
OP
glVertex3f

glVertex3f

Crap Cracker
No, I know what shifting is. Thats what I am saying. It would show a few dots on the screen and a few would blink. But later I saw that I didnt shift the Register values and I was like DOH! So I shifted them.... and then it displayed nothing.. no dots...

I guess my point was why did it show something when I didnt shift the register values.
Why did vRegister[200] (which is what it was ending up with) actually showsomething!?

:)

refraction: I said I was a n00b, not a uber noob :bouncy:
 

Doomulation

?????????????????????????
Very simple. Unlike VB, VC++ does not look if you're writing/reading outside an array. The compiler merly uses a formula to see the offset you're trying to read/write to.
If each variable in the array is 4 bytes and you try to access element 200, it uses the following forumula: addr_of_array + (4 * 200) = addr_of_array + 800. That's the location it will read from.
Do you expect this memory to be empty? No. It almost never is. You're reading junk data. You should actually concider yourself lucky that you don't get an access violation.

Make SURE you're filling the right registers everywhere. When it asks to draw from a certain register, do a sanity check to see if these contain any valid values. Also make sure the I register is properly set to point at the correct data.
You can use your watch window to see for example memory and see if there's any data there or if it's pretty much empty. This should be a fairly easy problem to solve with the debugger.
Remember: if your variables are corrupted somewhere in your program, use data breakpoints.

EDIT:
Compiling code...
Compilation errors found! Listing compilation errors in bold!


Code:
void SkipIF_A()
{
[b]  if(vRegister[OpCode&0x0F00] == (OpCode&0x00FF)) MemoryIndex += 4;[/b]
  else MemoryIndex += 2;
  WriteLog(Log);
}

[i]Compilation error! Register value not shifted properly![/i]

void SkipIF_B()
{
[b]  if(vRegister[OpCode&0x0F00] != (OpCode&0x00FF)) MemoryIndex += 4;[/b]
  else MemoryIndex += 2;
  WriteLog(Log);
}

[i]Compilation error! Register value not shifted properly![/i]

void SkipIF_C()
{
[b]  if(vRegister[OpCode&0x0F00] == vRegister[OpCode&0x00F0]) MemoryIndex += 4;[/b]
  else MemoryIndex += 2;
  WriteLog(Log);
}

[i]Compilation error! Register value not shifted properly![/i]

void SkipIF_D()
{
[b]  if(vRegister[OpCode&0x0F00] != vRegister[OpCode&0x00F0]) MemoryIndex += 4;[/b]
  else MemoryIndex += 2;
  WriteLog(Log);
}

[i]Compilation error! Register value not shifted properly![/i]

void RegAssign_A()
{
[b]  vRegister[OpCode&0x0F00] = (OpCode&0x00FF);[/b]
  MemoryIndex += 2;
  WriteLog(Log);       
}

[i]Compilation error! Register value not shifted properly![/i]

void RegAssign_B()
{
[b]  vRegister[OpCode&0x0F00] += (OpCode&0x00FF);[/b]
  MemoryIndex += 2;
  WriteLog(Log);
}

[i]Compilation error! Register value not shifted properly![/i]

void RegAssign_C()
{
[b]  vRegister[OpCode&0x0F00] = vRegister[OpCode&0x00F0];[/b]
  MemoryIndex += 2;
  WriteLog(Log);
}

[i]Compilation error! Register value not shifted properly![/i]

void RegAssign_D()
{
[b]  vRegister[OpCode&0x0F00] |= vRegister[OpCode&0x00F0];[/b]
  MemoryIndex += 2;
  WriteLog(Log);
}

[i]Compilation error! Register value not shifted properly![/i]

void RegAssign_E()
{
[b]  vRegister[OpCode&0x0F00] &= vRegister[OpCode&0x00F0];[/b]
  MemoryIndex += 2;
  WriteLog(Log);
}

[i]Compilation error! Register value not shifted properly![/i]

void RegAssign_F()
{
[b]  vRegister[OpCode&0x0F00] ^= vRegister[OpCode&0x00F0];[/b]
  MemoryIndex += 2;
  WriteLog(Log);
}

[i]Compilation error! Register value not shifted properly![/i]

void RegAssign_G()
{
[b]  if(vRegister[OpCode&0x00F0] > (0xFF - vRegister[OpCode&0x0F00])) vRegister[0xF] = 1;[/b]

[b]  vRegister[OpCode&0x0F00] += vRegister[OpCode&0x00F0];[/b]
  MemoryIndex += 2;
  WriteLog(Log);
}

[i]Compilation error! Register value not shifted properly![/i]
[i]Compilation error! If carry is not detected, register VF is set to 0![/i]

void RegAssign_H()
{
[b]  if(vRegister[OpCode&0x0F00] >= vRegister[OpCode&0x00F0]) vRegister[0xF] = 1;
  else vRegister[0xF] = 0;

[b]  vRegister[OpCode&0x0F00] -= vRegister[OpCode&0x00F0];[/b]
  MemoryIndex += 2;
  WriteLog(Log);
}

[i]Compilation error! Register value not shifted properly![/i]

void RegAssign_I()
{
[b]  vRegister[0xF] = (vRegister[OpCode&0x0F00]&0x01);[/b]

  vRegister[OpCode&0x0F00] >>= 1;
  MemoryIndex += 2;
  WriteLog(Log);
}

[i]Compilation error! Register value not shifted properly![/i]
[i]Compilation warning: Bad name for shifting?[/i]

void RegAssign_J()
{
[b]  if(vRegister[OpCode&0x00F0] >= vRegister[OpCode&0x0F00]) vRegister[0xF] = 1;[/b]
  else vRegister[0xF] = 0;

[b]  vRegister[OpCode&0x0F00] = vRegister[OpCode&0x00F0] - vRegister[OpCode&0x0F00];[/b]
  MemoryIndex += 2;
  WriteLog(Log);
}

[i]Compilation error! Register value not shifted properly![/i]

void RegAssign_K()
{
[b]  vRegister[0xF] = ((vRegister[OpCode&0x0F00]&0x80) >> 7);[/b]

[b]  vRegister[OpCode&0x0F00] <<= 1;[/b]
  MemoryIndex += 2;
  WriteLog(Log);
}

[i]Compilation error! Register value not shifted properly![/i]

void RegRandom()
{
[b]  vRegister[OpCode&0x0F00] = ((rand() % 16) & (OpCode&0x00FF));[/b]
  MemoryIndex += 2;
  WriteLog(Log);
}

[i]Compilation error! Register value not shifted properly![/i]

void DrawSprite()
{
  int height;
  int x, y;
  int loopX, loopY;
  unsigned char Data;

  height = (OpCode&0x000F);
[b]  x = vRegister[OpCode&0x0F00];[/b]
[b]  y = vRegister[OpCode&0x00F0];[/b]

  for(loopY = 0; loopY < height; loopY++)
  {
    Data = Memory[loopY + iRegister];
    for(loopX = 0; loopX < 8; loopX++)
    {
      if((Data&(0x80 >> loopX)) != 0)
      {
        if(DisplayBuffer[x + loopX][y + loopY] == 1) vRegister[0xF] = 1;
        DisplayBuffer[x + loopX][y + loopY] ^= 1;
      }
    }
  }

  MemoryIndex += 2;
  WriteLog(Log);
}

[i]Compilation error! Register value not shifted properly![/i]

[b]void SkipIFKey()
{
  if(KeyPress() < 16) MemoryIndex += 4;
  else MemoryIndex += 2;
  WriteLog(Log);
}

void SkipIFnKey()
{
  if(KeyPress() == 16) MemoryIndex += 4;
  else MemoryIndex += 2;
  WriteLog(Log);
}[/b]

[i]Compilation error! These opcodes checks if the register found in register defined by OpCode & 0x0F00 is pressed or not![/i]

void DelayTimer()
{
[b]  vRegister[OpCode&0x0F00] = DTimer;[/b]
  MemoryIndex += 2;
  WriteLog(Log);
}

[i]Compilation error! Register value not shifted properly![/i]

void StoreKey()
{
  if(KeyPress() < 16)
  {
[b]    vRegister[OpCode&0x0F00] = KeyPress();[/b]
    MemoryIndex += 2;
  }

  else MemoryIndex -= 2;
  WriteLog(Log);
}

[i]Compilation error! Register value not shifted properly![/i]

void SetDelayT()
{
[b]  DTimer = vRegister[OpCode&0x0F00];[/b]
  MemoryIndex += 2;
  WriteLog(Log);
}

[i]Compilation error! Register value not shifted properly![/i]

void SetSoundT()
{
[b]  STimer = vRegister[OpCode&0x0F00];[/b]
  MemoryIndex += 2;
  WriteLog(Log);
}

[i]Compilation error! Register value not shifted properly![/i]

void IAssignment()
{
[b]  iRegister += vRegister[OpCode&0x0F00];[/b]

  MemoryIndex += 2;
  WriteLog(Log);
}

[i]Compilation error! Register value not shifted properly![/i]

void IToFont()
{
[b]  iRegister = vRegister[OpCode&0x0F00] * 5;[/b]

  MemoryIndex += 2;
  WriteLog(Log);
}

[i]Compilation error! Register value not shifted properly![/i]

void SaveMem()
{
  int loop;

[b]  for(loop = 0; loop < vRegister[OpCode&0x0F00]; loop++)[/b]
    Memory[iRegister + loop] = vRegister[loop];

  MemoryIndex += 2;
  WriteLog(Log);
}

[i]Compilation error! Register value not shifted properly![/i]

void LoadMem()
{
  int loop;

[b]  for(loop = 0; loop < vRegister[OpCode&0x0F00]; loop++)[/b]
    vRegister[loop] = Memory[iRegister + loop];

  MemoryIndex += 2;
  WriteLog(Log);
}

[i]Compilation error! Register value not shifted properly![/i]

void StoreBCD()
{
[b]  iRegister = vRegister[OpCode&0x0F00];[/b]
  Memory[iRegister]     = (iRegister      ) / 100;
  Memory[iRegister + 1] = (iRegister /  10) % 10;
  Memory[iRegister + 2] = (iRegister % 100) / 10;
  WriteLog(Log);
}

[i]Compilation error! Register value not shifted properly![/i]
[i]Counting compilation errors: ...error... lost count. Cannot continue.[/I]

Congratulations, you've just been awarded for the sloppiest coding of all time! Congraulations, n00b! :flowers:
 
Last edited:

zenogais

New member
Doomulation said:
Very simple. Unlike VB, VC++ does not look if you're writing/reading outside an array. The compiler merly uses a formula to see the offset you're trying to read/write to.
If each variable in the array is 4 bytes and you try to access element 200, it uses the following forumula: addr_of_array + (4 * 200) = addr_of_array + 800. That's the location it will read from.
Do you expect this memory to be empty? No. It almost never is. You're reading junk data. You should actually concider yourself lucky that you don't get an access violation.

Make SURE you're filling the right registers everywhere. When it asks to draw from a certain register, do a sanity check to see if these contain any valid values. Also make sure the I register is properly set to point at the correct data.
You can use your watch window to see for example memory and see if there's any data there or if it's pretty much empty. This should be a fairly easy problem to solve with the debugger.
Remember: if your variables are corrupted somewhere in your program, use data breakpoints.



The formula can be simplified in C++ format to:

Code:
int nMyArray[10];
int nOffset = 1;
*(((char*)nMyArray) + (nOffset*sizeof(int))) = 4;

In order for Doomulations technique to work in C++, everything must be recast into a char*, but this is how memory is handled under-the-hood. Also, I would recommend crashing if the "sanity check" fails, this would mean using assert() or C++ exceptions (if you're using assert's then C: <assert.h> C++: <cassert>). Using an assert will show you exactly on what line the crash happens in your program, but with exceptions you can throw a string telling the exact error. Which one you choose is up to you.
 
OP
glVertex3f

glVertex3f

Crap Cracker
"Congratulations, you've just been awarded for the sloppiest coding of all time! Congraulations, n00b!"

What do you mean? I've said several times "Doh, I forgot to shift"...

:bye3:

btw, is the Dev-C++ debugger even worth using?
 

refraction

PCSX2 Coder
glVertex3f said:
"Congratulations, you've just been awarded for the sloppiest coding of all time! Congraulations, n00b!"

What do you mean? I've said several times "Doh, I forgot to shift"...

:bye3:

btw, is the Dev-C++ debugger even worth using?


no he doesnt mean the program debugger, cos your c code could be perfectly fine, but its if its emulating the machine properly or not. so you need a debugger for the actual system your emulating :)
 
OP
glVertex3f

glVertex3f

Crap Cracker
Ok I made a debugger to output what the EMU is being told to do (and im quite proud of it)...

Any way...

Code:
VX = KK: V[E] 05
VX = KK: V[5] 00
VX = KK: V[B] 06
VX = KK: V[A] 00
I = 30C
DrawSprite: X = 0 Y = 6 Height = 1
VX = VX + KK: V[A] 04
Skip IF VX == KK: V[A] 40
MemoryIndex = 208
I = 30C
DrawSprite: X = 4 Y = 6 Height = 1
VX = VX + KK: V[A] 04
Skip IF VX == KK: V[A] 40
MemoryIndex = 208
I = 30C
DrawSprite: X = 8 Y = 6 Height = 1
VX = VX + KK: V[A] 04
Skip IF VX == KK: V[A] 40
MemoryIndex = 208
I = 30C
DrawSprite: X = C Y = 6 Height = 1
VX = VX + KK: V[A] 04
Skip IF VX == KK: V[A] 40
MemoryIndex = 208
I = 30C
DrawSprite: X = 10 Y = 6 Height = 1
VX = VX + KK: V[A] 04
Skip IF VX == KK: V[A] 40
MemoryIndex = 208
I = 30C
DrawSprite: X = 14 Y = 6 Height = 1
VX = VX + KK: V[A] 04
Skip IF VX == KK: V[A] 40
MemoryIndex = 208
I = 30C
DrawSprite: X = 18 Y = 6 Height = 1

This is some of the output... This way is alot easier to find problems..

Is this what you are talking about?
 
OP
glVertex3f

glVertex3f

Crap Cracker
Im still working out some opcodes... but one interesting thing... See that debug output up there... That would basically make you think it is actually drawing something to screen... well, it doesnt... UNLESS!

If I take out the
Code:
if((Data&(0x80 >> loopX)) != 0)

It shows crap in the screen... of course not what its supposed to.. but it does.
So my question is what is wrong with my drawing code!?

Code:
void DrawSprite()
{
  int height;
  int x, y;
  int loopX, loopY;
  unsigned char Data;

  height = (OpCode&0x000F);
  x = vRegister[(OpCode&0x0F00) >> 8];
  y = vRegister[(OpCode&0x00F0) >> 4];

  for(loopY = 0; loopY < height; loopY++)
  {
    Data = Memory[loopY + iRegister];
    for(loopX = 0; loopX < 8; loopX++)
    {
      if((Data&(0x80 >> loopX)) != 0)
      {
        if(DisplayBuffer[x + loopX][y + loopY] == 1) vRegister[0xF] = 1;
        DisplayBuffer[x + loopX][y + loopY] ^= 1;
      }
    }
  }

  MemoryIndex += 2;
  RenderScreen();
}
 

Doomulation

?????????????????????????
Yes, but asm output is not enough. You'll want a nice GUI debugger, where you can step your code and see the effects.
Make SURE you have shifted ALL your registers properly, as I showed in the code above. Create a define named GetReg or something.
Even when I first made the emulator, I got output, although it was off a little. You must be doing some simple mistake.

EDIT: Here's my newest version of the doc. It should be complete. I've updated the doc with my latest opcodes, which seem to get most games working perfecly :) Note that most of the opcodes were fixed by refraction, as he's been working on it like 24 hours a day.
Anyway, this should help you once you fix your display!
 
Last edited:
OP
glVertex3f

glVertex3f

Crap Cracker
Thanks Doom,
I'll give that a look as son as I figure out my drawing code. Cant figure out what's going on with it.
 
OP
glVertex3f

glVertex3f

Crap Cracker
I have found the mother of all problems... I cant belive no one else saw this in my code. It's so simple.

I think when I actually put the ROM into the memory array... the loop is broken before the ROM is through loading. I realized this as I was looking through debug output. the iRegister was pointing to a place in memory that was far ahead of any data hence nothing to draw.

I need to figure out a way to get the file size and read that amount then break instead of the way I was doing it.
 

refraction

PCSX2 Coder
Doomulation said:
EDIT: Here's my newest version of the doc. It should be complete. I've updated the doc with my latest opcodes, which seem to get most games working perfecly :) Note that most of the opcodes were fixed by refraction, as he's been working on it like 24 hours a day.
Anyway, this should help you once you fix your display!


one problem in that mate, the Schip8 fonts arent exactly double the chip8 ones, on chip8 they are 4x5, and schip is 4x10 i think, you may get away with 8x10, it may also be that but ive never seen a doc that actually says that!
 

Doomulation

?????????????????????????
8x10 is double width of a chip8 font. It looks better plus it won't cause trouble since it's 8 bits.
Besides that, each schip8 pixel is supposed to be two chip8 pixels. Remember that.

glVertex3f: I, as well as the others, I guess, just skimmed through your code without actually running it. Plus, I only looked at your opcodes, and not the rest of the code. Which is probably why I missed this.
But if you use code such as this, it should be no problem:

Code:
FILE* fFile = fopen(rom);
fseek(fFile,0,SEEK_END);
int size = ftell(fFile);
fseek(fFile,0,SEEK_SET);
fread(memory,size,1,fFile);
fclose(fFile);

This will read the entire rom into memory directly. If it does this, I cannot see how it can't miss parts of the rom.
 
Last edited:

aprentice

Moderator
refraction said:
one problem in that mate, the Schip8 fonts arent exactly double the chip8 ones, on chip8 they are 4x5, and schip is 4x10 i think, you may get away with 8x10, it may also be that but ive never seen a doc that actually says that!

I ran the fontset in dooms docs through the fontset tester in my chip8 emu and these are the results. It looks fine to me... (D,E,F goes offscreen by 1 pixel but thats my fault since i have it in CHIP8 mode res)
 
Last edited:

refraction

PCSX2 Coder
umm, then fonts look the same width to me of 4 pixels. so that brings me to think youve got 4x5 and 4x10 fonts, which is what i said ;)
 

Doomulation

?????????????????????????
Wellll... actually, my fonts are only 4x10, I'm too lazy to re-do them. But they are supposed to be 8x10. If you don't believe me, run alien and when you see the "0 1" at the beginning, you'll notice a lot of gap.
That alone makes me think they should be 8x10.

EDIT: Look at the pic.
 
Last edited:

Top