public void Cycle(Chip8Processor cpu, Chip8Memory[] ram, Chip8GPU gpu) { cpu.Opcode = (short)(ram[cpu.pc].value << 8 | ram[cpu.pc + 1].value); char test = (char)(cpu.Opcode & 0xF000); switch (cpu.Opcode & 0xF000) { case 0x0000: //call, disp_clear, return if ((char)(cpu.Opcode >> 12 & 0x0) != 0x00) //call (0NNN) { } else { if ((char)(cpu.Opcode & 0x000E) != 0x000E) //return (00EE) { } else //disp_clear (00E0) { } } return; case 0x1000: //goto NNN (1NNN) cpu.pc = (ushort)(cpu.Opcode & 0x0FFF); //TODO: make sure pc doesnt have to move 2 after this as well //TODO: gotos and jumps suck make sure this emulates right once more of emu is working return; case 0x2000: //call subroutine return; case 0x3000: //skip next inst if Vx == xxNN return; case 0x4000: //skip next inst if Vx != xxNN return; case 0x6000: //set Vx to value NN v[cpu.Opcode & 0x0F] = (char)(cpu.Opcode & 0x00FF); cpu.pc += 2; return; case 0xA000: //set I to ANNN for address use logging.Add(string.Format("Set I to {0}", (ushort)(cpu.Opcode & 0x0FFF))); i = (ushort)(cpu.Opcode & 0x0FFF); pc += 2; return; case 0xD000: //draw Vx, Vy, N (DXYN) pc += 2; return; } }
private void button1_Click(object sender, EventArgs e) { //load pong.rom cpu = new Chip8Processor(); BinaryReader rom = new BinaryReader(File.OpenRead(@"C:\Users\Michael\source\repos\Chip8Emulator\pong.rom")); ram = new Chip8Memory[4096]; for (int i = 0; i < ram.Length; i++) { ram[i] = new Chip8Memory(); } cpu.LoadGameIntoRAM(rom, ram); rom.Close(); //TODO: need to fill out static data like the font gpu = new Chip8GPU(); input = new Chip8Input(); taskPause = false; cpu.Initialize(cpu); cycle = new Task(() => Cycle(cpu, ram)); Cycle(cpu, ram); }