What's new

My PotatoChipAte

OP
glVertex3f

glVertex3f

Crap Cracker
lol I did a PC += 2 in the Main loop. Either there after the OpCode switch in the Emulate function. I cant remember wich one as I have been trying different places to make sure its the same result.

I was incrementing PC every loop and doing a PC += 2 when I skip and a PC -= 2 when I did a jmp() or a jsr();
 
Last edited:

refraction

PCSX2 Coder
well then you forgot it on this one :p

Code:
void CPU::jmi()
{
  PC = (OpCode&0x0FFF) + V[0x0];
}

but best way i found is the way zenogais showed me, get it to read in the opcode, then increment the PC before it runs the op code so you have like

Opcode = Memory[PC]<<4 + Memory[PC+1];
PC+=2;

then run your opcode, then no more incrementing until it gets round to that again, or obviously if its a skip instruction :)

only think you have to take in account it will be 2 positions above the actual position its on, so if you run a debugger make sure you output (PC - 2)
 
OP
glVertex3f

glVertex3f

Crap Cracker
GDB... GNU Debugger...
How, in, the, world.....

I keep trying to do the whole

file ChipAte

and it says no debug symbols found.

What does this mean. Do I have to add something to my actual source. Is theer an easier alternative for debugging, instead of this GDB?
 

smcd

Active member
What compiler are you using? If using gcc/g++ did you compile in DEBUG mode (as in no -s option to strip symbols)? GDB is cranky, I don't like it much either.
 
OP
glVertex3f

glVertex3f

Crap Cracker
oh I have to compile it differently huh?

Seems like they coulda put in a "Compile DEBUG" or something like that.

Im using Dev-C++ with the gcc.

Ok let me go fight with it and see who wins!
 
OP
glVertex3f

glVertex3f

Crap Cracker
Bah, I cant figure out how to set up break points and step through my code.

The manual is not really much help either.
I need to find out whats going on with my Subroutine functions.
 

smcd

Active member
This is one of those times when having Visual Studio is really nice... :p I've got a (legal) copy if you'd be interested.
 

Doomulation

?????????????????????????
Yeah... visual studio is easy to use and powerful.
Anyone noticed you can actually fetch the opcode like this?

Code:
word opcode = (word)memory[PC];

;)
Go for some tutorials on the web and you'll probably find how to do stuff with the ide.
 

refraction

PCSX2 Coder
Doomulation said:
Yeah... visual studio is easy to use and powerful.
Anyone noticed you can actually fetch the opcode like this?

Code:
word opcode = (word)memory[PC];

;)
Go for some tutorials on the web and you'll probably find how to do stuff with the ide.

that would only fetch half the op code, because it uses 2 memory positions PC & PC+1
 

aprentice

Moderator
Doomulation said:
Bad refraction, bad! :p
As stated, word is 2 bytes (16 bits) ;)

no no, bad doomulation, bad :p
How much effort did you put in thinking this out before
you made your suggestion and critisims? :p

Not to put you to shame, but like refraction has said, it will
only read half the opcode :p
 
OP
glVertex3f

glVertex3f

Crap Cracker
Ive been thinking... The few Chip8 threads on here have more than enough info for people new to emulation programming. Someone should turn all this info into a tutorial.

I have definately learned alot from this board and its members (I think I have learned quite a bit in a relatively short amount of time).

I havent touched my emulator in several days, Ive had other projects plus a small sense of hopelessnes (Its hard to keep going when you cant find your problems). But I am getting ready to open my code back up and get to work. I'm gonna get this thing finished ;)
 

Doomulation

?????????????????????????
aprentice said:
no no, bad doomulation, bad :p
How much effort did you put in thinking this out before
you made your suggestion and critisims? :p

Not to put you to shame, but like refraction has said, it will
only read half the opcode :p
Bah, I don't care! :whistling
It should work in theory (besides the endianess =/), soooo.... didn't feel a need to try it. :saint:
 

refraction

PCSX2 Coder
example 0x1846 = jump opcode in chip8 to jump to 0x846, and oh look! the op code is 16 bits wide!! fancy that :p

and glvertex3f: Its not really a tutorial (But there is one in the making) but there is a well commented source code of the NeoChip8 emu me and zenogais worked on HERE

if you take out the NeoChip8/ from the address it has a function pointers tutorial in the tutorial section to tell you how to make jump tables properly :)

i shall enquire about the actual tutorial later on.
 

smcd

Active member
Doomulation it would work in assembly (telling the assembler to fetch a value 16bits wide from memory XXXX) but in C and/or C++ it'd just cast the 8-bit value at that location to a 16-bit value. :)
 
OP
glVertex3f

glVertex3f

Crap Cracker
Thought I would share something interesting from the debug output.

Code:
OpCode: 0x22F6 Memory[220] Call SubRoutine at 2F6
OpCode: 0xA314 Memory[2F6] I = 314
OpCode: 0xF533 Memory[2F8] Store BCD
OpCode: 0xF265 Memory[2FA] Load Mem
OpCode: 0xF129 Memory[2FC] I to Font
OpCode: 0x6337 Memory[2FE] V[3] = 37
OpCode: 0x6400 Memory[300] V[4] = 00
OpCode: 0xD345 Memory[302] DrawSprite: X = 55 Y = 0 Height = 5
OpCode: 0x7305 Memory[304] V[3] = V[3] + 05
OpCode: 0xF229 Memory[306] I to Font
OpCode: 0xD345 Memory[308] DrawSprite: X = 60 Y = 0 Height = 5
OpCode: 0x00EE Memory[30A] Return From Sub
OpCode: 0xF0F0 Memory[22] Return From Sub
OpCode: 0x1020 Memory[24] MemoryIndex = 020
OpCode: 0xF090 Memory[20] MemoryIndex = 020
OpCode: 0xF0F0 Memory[22] MemoryIndex = 020
OpCode: 0x1020 Memory[24] MemoryIndex = 020
OpCode: 0xF090 Memory[20] MemoryIndex = 020
OpCode: 0xF0F0 Memory[22] MemoryIndex = 020
OpCode: 0x1020 Memory[24] MemoryIndex = 020

Notice where the subroutine is called... and noticed where it returns to. Could there be just some simple mistake causing this?

Also, here is updated code where I have fixed a few OpCodes.
 
Last edited:

Doomulation

?????????????????????????
sethmcdoogle said:
Doomulation it would work in assembly (telling the assembler to fetch a value 16bits wide from memory XXXX) but in C and/or C++ it'd just cast the 8-bit value at that location to a 16-bit value. :)
Hmmm... now I think I got it.
What if I did...


Code:
word opcode = *(word*)&memory[PC];
That should do it! Just the stupid endianess would probably get it backwards.

glVertex3f: your return address is definetly getting corrupted from what I see. And I wrote before, "use data breakpoints." That is your easiest and best solution. Or simply step through all the opcodes and watch your return address to see where it gets corrupted.

I don't have an IDE at my current location, so I can't test for you.
 
Last edited:
OP
glVertex3f

glVertex3f

Crap Cracker
I downloaded and installed the MinGW studio again. And I am really enjoying the IDE. A few problems though.

Code:
..\..\Emul8\Chip8.cpp:81: error: invalid conversion from `unsigned char*' to `
char*'

That happens here..

Code:
bool CPU::LoadRom(char *sFileName)
{
  ifstream Rom(sFileName);

  if(!Rom.is_open())
    return FALSE;

  Rom.seekg(0, ios::end);
  long size = Rom.tellg();
  Rom.seekg(0, ios::beg);

  Rom.read(Memory + 0x200, size);  <---- HERE 

  Rom.close();
  return TRUE;
}

Why is this happening and how can I fix it?

edit: Also I had functions named and() or() and xor()
These names seemed to be keywords in this IDE.. why is that.

EDIT2: I did this
Code:
Rom.read((char*)Memory + 0x200, size);
Is this acceptable?

EDIT AGAIN:
Also I tried to use the debugger and I set some breakpoints and watch points on PC and Stack and I cant really figure out how to find out where things go wrong. Any tips or advice on how to debug on this thing would be great
 
Last edited:

Top