now im having more problems....
every single time i get unkown opcode, is it the loading or the actual cpu
please help me out
or load
theres some objective c in there but its a lot like c
memory is a unsigned char. is that right?
heres my startGLWindow
thanks in advance
full source is included here - http://www.megaupload.com/?d=1BJPMRV1
every single time i get unkown opcode, is it the loading or the actual cpu
please help me out
Code:
// Fetch opcode
chip8.opcode = memory[chip8.pc << 8] | memory[chip8.pc+1];
// Set Some Values
chip8.regs[(chip8.opcode & 0x0F00) >> 8] = chip8.VX;
chip8.regs[(chip8.opcode & 0x00F0) >> 4] = chip8.VY;
chip8.regs[15] = chip8.VF;
chip8.KK = chip8.opcode & 0x00FF;
// Next Instruction for next execute
chip8.pc += 2;
// Emulate the opcode
switch (((chip8.opcode & 0xF000)>>12))
{
case 0x0:
{
switch ((chip8.opcode&0xFFF))
{
case 0xE0: // Clear the screen
{
memset(chip8.display, 0, 64*32);
break;
}
case 0xEE: // Return from a subroutine
{
chip8.pc = chip8.stack[chip8.sp];
chip8.sp--;
break;
}
default:
{
UnkownOpcode();
break;
}
}
break;
}
case 0x1: // Jump to address NNN
{
chip8.pc = (chip8.opcode&0xFFF);
break;
}
case 0x2: // Cals subroutine at NNN
{
chip8.sp++;
chip8.stack[chip8.sp] = chip8.pc;
chip8.pc = (chip8.opcode&0xFFF);
break;
}
case 0x3: // Skips next instruction if chip8.VX == NN
{
if (chip8.VX == chip8.KK)
chip8.pc += 2;
break;
}
case 0x4: // Skips next intruction if chip8.VX != NN
{
if (chip8.VX != chip8.KK)
chip8.pc += 2;
break;
}
case 0x5: // Skips next intruction if chip8.VX == chip8.VY
{
if (chip8.VX == chip8.VY)
chip8.pc += 2;
break;
}
case 0x6: // Set chip8.VX to NN
{
chip8.VX = chip8.KK;
break;
}
case 0x7: // Adds NN to chip8.VX
{
chip8.VX += chip8.KK;
break;
}
case 0x8:
{
switch ((chip8.opcode&0x00FF))
{
case 0x0: // Sets chip8.VX to chip8.VY
chip8.VX = chip8.VY;
break;
case 0x1: // Sets chip8.VX to chip8.VX or chip8.VY
chip8.VX |= chip8.VY;
break;
case 0x2: // Sets chip8.VX to chip8.VX and chip8.VY
chip8.VX &= chip8.VY;
break;
case 0x3: // Sets chip8.VX to chip8.VX xor chip8.VY
chip8.VX ^= chip8.VY;
break;
case 0x4: // Adds chip8.VY to chip8.VX. chip8.VF is set to 1 if there's a carry, otherwise chip8.VF = 0
chip8.VF = (chip8.VX += chip8.VY) >> 8;
break;
case 0x5: // chip8.VY is subtracted from chip8.VX. chip8.VF is set 0 if there is borrow, else chip8.VF = 1
chip8.VF = (chip8.VX > chip8.VY);
chip8.VX -= chip8.VY;
break;
case 0x6: // chip8.VX Shifts right by one. chip8.VF = least significant bit value of chip8.VX before shift
chip8.VF = (chip8.VX & 0x1);
chip8.VX >>= 0x1;
break;
case 0x7: // chip8.VX -= chip8.VYÂ chip8.VF is set to 0 if theres a borrow, otherwise chip8.VF = 1
chip8.VF = (chip8.VY > chip8.VX);
chip8.VX = chip8.VY - chip8.VX;
break;
case 0x0E: // Shifts chip8.VX to left by one. chip8.VF is set to the most significant bit of chip8.VX before shift
chip8.VF = (chip8.VX & 0x80);
chip8.VX <<= 0x1;
break;
default: // Unkown Opcode
UnkownOpcode();
break;
}
break;
}
case 0x09: // Skips next instruction if chip8.VX != chip8.VY
if (chip8.VX != chip8.VY)
chip8.pc += 2;
break;
case 0x0A: // Sets I to the address NNN
chip8.I = (chip8.opcode&0xFFF);
break;
case 0x0B: // Jumps to address NNN + V0
chip8.pc = (chip8.opcode&0xFFF)+chip8.regs[0];
break;
case 0x0C: // Sets chip8.VX to a random number and NN
chip8.VX = (unsigned int)(rand() & chip8.KK );
break;
case 0x0D:
{
/*
* Draws a sprite at (chip8.VX, chip8.VY) with a width of 8 pixels and a height of N pixels
* chip8.VF is set to 1 if any screen pixels are flipped from set to unset when the
* sprite is drawn, and to 0 if that doesn't happen.
*/
break;
}
case 0x0E:
{
switch ((chip8.opcode&0x00FF))
{
case 0x9E: // Skips the next instruction if the key stored in chip8.VX is pressed
if (keys[chip8.VX])
chip8.pc += 2;
break;
case 0xA1: // Skips the next instruction if the key stored in chip8.VX isn't pressed
if (!keys[chip8.VX])
chip8.pc += 2;
break;
default:
UnkownOpcode();
break;
}
break;
}
case 0x0F:
{
switch ((chip8.opcode&0x00FF))
{
case 0x07: // Sets chip8.VX to the vaue of the delay timer
chip8.VX = chip8.delayTimer;
break;
case 0x0A: // A key press is awaited, then stored in chip8.VX;
if (key == -1)
chip8.pc -= 2;
else
chip8.VX = key;
break;
case 0x15: // Sets the delay timer to chip8.VX
chip8.delayTimer = chip8.VX;
break;
case 0x18: // Sets the sound timer to chip8.VX
chip8.soundTimer = chip8.VX;
break;
case 0x1E: // Adds chip8.VX to I
chip8.VX += chip8.I;
break;
case 0x29:
{
/*
* Sets I to the location of the sprite for the character in chip8.VX
* Characters 0-F (in hexadecimal) are represented by a 4x5 font
*/
chip8.I = chip8.VX*5;
break;
}
case 0x33:
{
/*
* Stores the binary coded decimal representation of chip8.VX at the a
* the adresses I, I + 1, and I + 2
*/
memory[chip8.I] = chip8.VX / 100;
memory[chip8.I+1] = (chip8.VX/10) % 10;
memory[chip8.I+2] = chip8.VX % 10;
break;
}
case 0x55: // Stores V0 to chip8.VX in memory starting at address I
memcpy(&memory[chip8.I], chip8.regs, 16);
break;
case 0x65: // Fills V0 to chip8.VX with values from memory starting at adress I
memcpy(chip8.regs, &memory[chip8.I], 16);
break;
default:
UnkownOpcode();
break;
}
break;
}
default:
{
UnkownOpcode();
break;
}
}or load
Code:
// Load filename from the openPanel
filename = [ NSString stringWithString:[ [ panel filenames ] objectAtIndex:0 ] ];
// Load rom into memory
FILE* file = fopen([ filename UTF8String ], "rb");
// Get the file size
fseek(file, 0, SEEK_END);
size_t size = ftell(file);
rewind(file);
if (size > 3584)
{
// File is not valid
fclose(file);
NSRunAlertPanel(@"Error", @"Invalid Rom", @"Ok", nil, nil);
[ NSApp terminate:self ];
}
[ console Log:[ NSString stringWithFormat:@"Rom Selected - %@\n\n", filename ] ];
// Read the data into memory
fread(&memory[0x200], 1, size, file);
// Release the file
fclose(file);
// Log the memory that has a value
for (int x = 0; x < 4096; x++)
{
if (memory[x] != 0)
{
[ console Log:[ NSString stringWithFormat:@"Memory[%i] = %i\n", x, memory[x] ] ];
}
}
[ NSTimer scheduledTimerWithTimeInterval: 0.1 target:self selector:@selector( startGLWindow )
userInfo:nil repeats:NO ];
}
else // Exit the app if they don't open a file
[ NSApp terminate:self ];theres some objective c in there but its a lot like c
memory is a unsigned char. is that right?
heres my startGLWindow
Code:
// Initialize
glView = [ [ OpenGLView alloc ] initWithFrame:[ glWindow frame ] colorBits: 32
depthBits: 32 fullscreen:NO ];
if (glView == nil)
{
// Does not have a good enough graphics card
NSRunAlertPanel(@"Error", @"Could not create OpenGL context.\nPress Ok to quit", @"Ok", nil, nil);
[ self dealloc ];
[ NSApp terminate:self ];
}
// Make eveything visible
[ glWindow setContentView:glView ];
[ glWindow makeKeyAndOrderFront:self ];
// Get ready for emulating
Reset();
// Start looping
for (;;)
{
Execute(console);
[ self interrupt ];
if (!running)
break;
}thanks in advance
full source is included here - http://www.megaupload.com/?d=1BJPMRV1