public override void ExecuteCycle(ICpuState cpuState, IRandomAccessMemory mainMemory) { switch (_remainingCycles) { case 5: _writeAddress = mainMemory.ReadByte(cpuState.ProgramCounter++); break; case 4: _writeAddress |= (ushort)(mainMemory.ReadByte(cpuState.ProgramCounter++) << 8); break; case 3: //write lsb of stack pointer mainMemory.WriteByte(_writeAddress, (byte)cpuState.StackPointer); break; case 2: //write msb of stack pointer mainMemory.WriteByte((ushort)(_writeAddress + 1), (byte)(cpuState.StackPointer >> 8)); break; case 1: break; } base.ExecuteCycle(cpuState, mainMemory); }
public override void ExecuteCycle(ICpuState cpuState, IRandomAccessMemory mainMemory) { switch (_remainingCycles) { case 6: //read jump address lsb _jumpAddress = mainMemory.ReadByte(cpuState.ProgramCounter++); break; case 5: //read jump address msb _jumpAddress |= (ushort)(mainMemory.ReadByte(cpuState.ProgramCounter++) << 8); break; case 3: //write msb of program counter to stack mainMemory.WriteByte(--cpuState.StackPointer, (byte)(cpuState.ProgramCounter >> 8)); break; case 2: //write lsb of program counter to stack mainMemory.WriteByte(--cpuState.StackPointer, (byte)(cpuState.ProgramCounter & 0x00FF)); break; case 1: //do the jump cpuState.ProgramCounter = _jumpAddress; break; } base.ExecuteCycle(cpuState, mainMemory); }
public override void ExecuteCycle(ICpuState cpuState, IRandomAccessMemory mainMemory) { switch (_remainingCycles) { case 4: //calculate jump address _jumpAddress = (ushort)(_opcode & 0x38); break; case 3: //write msb of program counter to stack mainMemory.WriteByte(--cpuState.StackPointer, (byte)(cpuState.ProgramCounter >> 8)); break; case 2: //write lsb of program counter to stack mainMemory.WriteByte(--cpuState.StackPointer, (byte)(cpuState.ProgramCounter & 0x00FF)); break; case 1: //do the jump cpuState.ProgramCounter = _jumpAddress; break; } base.ExecuteCycle(cpuState, mainMemory); }
internal void RequestVBlankInterrupt() { var currentIf = _mainMemory.ReadByte(MiscRegisters.InterruptFlags); _mainMemory.WriteByte(MiscRegisters.InterruptFlags, (byte)(currentIf | 0x01)); NotifyNextFrameReady(); SwapBuffers(); }
public override void ExecuteCycle(ICpuState cpuState, IRandomAccessMemory mainMemory) { switch (_remainingCycles) { case 3: _currentData = mainMemory.ReadByte(cpuState.Registers.HL); break; case 2: _hiBit = _currentData & 0x80; _loBit = _currentData & 0x01; _writeData = (byte)(_currentData >> 1); _writeData |= (byte)_hiBit; mainMemory.WriteByte(cpuState.Registers.HL, _writeData); cpuState.Registers.CarryFlag = _loBit == 0x01; cpuState.Registers.ZeroFlag = _writeData == 0; cpuState.Registers.HalfCarryFlag = false; cpuState.Registers.SubtractionFlag = false; break; } base.ExecuteCycle(cpuState, mainMemory); }
public override void ExecuteCycle(ICpuState cpuState, IRandomAccessMemory mainMemory) { switch (_remainingCycles) { case 3: _currentData = mainMemory.ReadByte(cpuState.Registers.HL); break; case 2: byte lowNibble = (byte)(_currentData & 0x0F); byte highNibble = (byte)(_currentData & 0xF0); _writeData = (byte)((lowNibble << 4) | (highNibble >> 4)); mainMemory.WriteByte(cpuState.Registers.HL, _writeData); cpuState.Registers.ZeroFlag = _writeData == 0; cpuState.Registers.HalfCarryFlag = false; cpuState.Registers.SubtractionFlag = false; cpuState.Registers.CarryFlag = false; break; } base.ExecuteCycle(cpuState, mainMemory); }
public override void ExecuteCycle(ICpuState cpuState, IRandomAccessMemory mainMemory) { switch (_remainingCycles) { case 2: mainMemory.WriteByte(cpuState.Registers.BC, cpuState.Registers.A); break; } base.ExecuteCycle(cpuState, mainMemory); }
public override void ExecuteCycle(ICpuState cpuState, IRandomAccessMemory mainMemory) { switch (_remainingCycles) { case 4: _registerBits = (byte)((_opcode >> 4) & 0x03); LoadWriteData(cpuState); break; case 3: mainMemory.WriteByte(--cpuState.StackPointer, _msbData); break; case 2: mainMemory.WriteByte(--cpuState.StackPointer, _lsbData); break; } base.ExecuteCycle(cpuState, mainMemory); }
public override void ExecuteCycle(ICpuState cpuState, IRandomAccessMemory mainMemory) { switch (_remainingCycles) { case 2: var registerIndex = _opcode & 0x07; mainMemory.WriteByte(cpuState.Registers.HL, (byte)cpuState.Registers[registerIndex]); break; } base.ExecuteCycle(cpuState, mainMemory); }
public override void ExecuteCycle(ICpuState cpuState, IRandomAccessMemory mainMemory) { switch (_remainingCycles) { case 3: _loadData = mainMemory.ReadByte(cpuState.ProgramCounter++); break; case 2: mainMemory.WriteByte(cpuState.Registers.HL, _loadData); break; } base.ExecuteCycle(cpuState, mainMemory); }
public override void ExecuteCycle(ICpuState cpuState, IRandomAccessMemory mainMemory) { switch (_remainingCycles) { case 3: _addressLsb = mainMemory.ReadByte(cpuState.ProgramCounter++); break; case 2: mainMemory.WriteByte((ushort)((0xFF << 8) | _addressLsb), cpuState.Registers.A); break; } base.ExecuteCycle(cpuState, mainMemory); }
public override void ExecuteCycle(ICpuState cpuState, IRandomAccessMemory mainMemory) { switch (_remainingCycles) { case 3: _currentData = mainMemory.ReadByte(cpuState.Registers.HL); var bitIndex = (_opcode & 0x38) >> 3; _writeData = (byte)(_currentData & ~(0x01 << bitIndex)); break; case 2: mainMemory.WriteByte(cpuState.Registers.HL, _writeData); break; } base.ExecuteCycle(cpuState, mainMemory); }
public override void ExecuteCycle(ICpuState cpuState, IRandomAccessMemory mainMemory) { switch (_remainingCycles) { case 3: _currentData = mainMemory.ReadByte(cpuState.Registers.HL); break; case 2: _decrementedData = (byte)(_currentData - 1); mainMemory.WriteByte(cpuState.Registers.HL, _decrementedData); break; case 1: cpuState.Registers.ZeroFlag = _decrementedData == 0; cpuState.Registers.SubtractionFlag = true; cpuState.Registers.HalfCarryFlag = (_currentData & 0x0F) == 0; break; } base.ExecuteCycle(cpuState, mainMemory); }
public override void ExecuteCycle(ICpuState cpuState, IRandomAccessMemory mainMemory) { switch (_remainingCycles) { case 3: mainMemory.WriteByte(--cpuState.StackPointer, (byte)(cpuState.ProgramCounter >> 8)); break; case 2: mainMemory.WriteByte(--cpuState.StackPointer, (byte)(cpuState.ProgramCounter & 0x00FF)); break; case 1: var interruptFlags = mainMemory.ReadByte(MiscRegisters.InterruptFlags); //vblank interrupt if ((_readyInterrupts & 0x01) == 0x01) { //Console.WriteLine("Loading vblank isr..."); cpuState.ProgramCounter = InterruptAddresses.VblankInterrupt; mainMemory.WriteByte(MiscRegisters.InterruptFlags, (byte)(interruptFlags & 0xFE)); } //lcd stat interrupt else if ((_readyInterrupts & 0x02) == 0x02) { //Console.WriteLine("Loading lcd stat isr..."); cpuState.ProgramCounter = InterruptAddresses.LcdInterrupt; //clear interrupt flag mainMemory.WriteByte(MiscRegisters.InterruptFlags, (byte)(interruptFlags & 0xFD)); } //timer interrupt else if ((_readyInterrupts & 0x04) == 0x04) { //Console.WriteLine("Loading timer isr..."); cpuState.ProgramCounter = InterruptAddresses.TimerInterrupt; //clear interrupt flag mainMemory.WriteByte(MiscRegisters.InterruptFlags, (byte)(interruptFlags & 0xFB)); } //serial interrupt else if ((_readyInterrupts & 0x08) == 0x08) { cpuState.ProgramCounter = InterruptAddresses.SerialInterrupt; //clear interrupt flag mainMemory.WriteByte(MiscRegisters.InterruptFlags, (byte)(interruptFlags & 0xF7)); } //joypad interrupt else if ((_readyInterrupts & 0x10) == 0x10) { cpuState.ProgramCounter = InterruptAddresses.JoypadInterrupt; //clear interrupt flag mainMemory.WriteByte(MiscRegisters.InterruptFlags, (byte)(interruptFlags & 0x0F)); } cpuState.InterruptMasterEnable = false; break; } base.ExecuteCycle(cpuState, mainMemory); }