public AudioProcessingUnit(IntPtr handle, NesEmulator NesEmu, SystemBus systemBus) { _Nes = NesEmu; _systemBus = systemBus; InitDirectSound(handle); _handle = handle; }
public PictureProcessingUnit(NesEmulator theEngine, SystemBus systemBus) { _bus = systemBus; myEngine = theEngine; nameTables = new byte[0x2000]; spriteRam = new byte[0x100]; RestartPPU(); }
/// <summary> /// The main cpu of the nes /// </summary> /// <param name="NesEmu">The current nes machine</param> public Cpu6502(NesEmulator NesEmu, SystemBus bus) { _bus = bus; _NesEmu = NesEmu; a_register = 0; x_index_register = 0; y_index_register = 0; sp_register = 0xff; }
public SystemOrchestration(AudioProcessingUnit apu, PictureProcessingUnit ppu, SystemBus bus, Cpu6502 cpu, NesEmulator emulator) { _apu = apu; _ppu = ppu; _cpu = cpu; _systemBus = bus; _emulator = emulator; }
public SystemBus(NesEmulator nes) { _nes = nes; }
public Chn_DMC(NesEmulator NesEmu, SystemBus bus) { _Nes = NesEmu; _bus = bus; }
public Mappers(NesEmulator theEngine, ref Cart theCartridge, SystemBus bus) { _bus = bus; myEngine = theEngine; mapperCartridge = theCartridge; current_prg_rom_page = new uint[8]; current_chr_rom_page = new uint[8]; }
/// <summary> /// The state saver / loader /// </summary> /// <param name="NesEmu">The current system you want to save / load state from / into</param> public State(NesEmulator NesEmu) { _Nes = NesEmu; }
public void ApplyDataToNes(NesEmulator _Nes) { //CPU _Nes.my6502.a_register = a_register; _Nes.my6502.x_index_register = x_index_register; _Nes.my6502.y_index_register = y_index_register; _Nes.my6502.sp_register = sp_register; _Nes.my6502.pc_register = pc_register; _Nes.my6502.carry_flag = carry_flag; _Nes.my6502.zero_flag = zero_flag; _Nes.my6502.interrupt_flag = interrupt_flag; _Nes.my6502.decimal_flag = decimal_flag; _Nes.my6502.brk_flag = brk_flag; _Nes.my6502.overflow_flag = overflow_flag; _Nes.my6502.sign_flag = sign_flag; _Nes.my6502.tick_count = tick_count; _Nes.my6502.total_cycles = total_cycles; _Nes.my6502.currentOpcode = currentOpcode; _Nes.my6502.previousPC = previousPC; //MEMORY _Nes.scratchRam = scratchRam; _Nes.saveRam = saveRam; _Nes.JoyData1 = JoyData1; _Nes.JoyData2 = JoyData2; _Nes.JoyStrobe = JoyStrobe; _Nes.isSaveRAMReadonly = isSaveRAMReadonly; //CART if (_Nes.myCartridge.chr_rom_pages == 0) _Nes.myCartridge.chr_rom = chr_rom; _Nes.myCartridge.mirroring = mirroring; _Nes.myCartridge.save_ram_present = save_ram_present; _Nes.myCartridge.is_vram = is_vram; _Nes.myCartridge.mirroringBase = mirroringBase; //MAPPERS _Nes.myMapper.current_prg_rom_page = current_prg_rom_page; _Nes.myMapper.current_chr_rom_page = current_chr_rom_page; //PPU _Nes.myPPU.executeNMIonVBlank = executeNMIonVBlank; _Nes.myPPU.ppuMaster = ppuMaster; _Nes.myPPU.spriteSize = spriteSize; _Nes.myPPU.backgroundAddress = backgroundAddress; _Nes.myPPU.spriteAddress = spriteAddress; _Nes.myPPU.ppuAddressIncrement = ppuAddressIncrement; _Nes.myPPU.nameTableAddress = nameTableAddress; _Nes.myPPU.monochromeDisplay = monochromeDisplay; _Nes.myPPU.noBackgroundClipping = noBackgroundClipping; _Nes.myPPU.noSpriteClipping = noSpriteClipping; _Nes.myPPU.backgroundVisible = backgroundVisible; _Nes.myPPU.spritesVisible = spritesVisible; _Nes.myPPU.ppuColor = ppuColor; _Nes.myPPU.sprite0Hit = sprite0Hit; _Nes.myPPU.vramReadWriteAddress = vramReadWriteAddress; _Nes.myPPU.prev_vramReadWriteAddress = prev_vramReadWriteAddress; _Nes.myPPU.vramHiLoToggle = vramHiLoToggle; _Nes.myPPU.vramReadBuffer = vramReadBuffer; _Nes.myPPU.scrollV = scrollV; _Nes.myPPU.scrollH = scrollH; _Nes.myPPU.currentScanline = currentScanline; _Nes.myPPU.nameTables = nameTables; _Nes.myPPU.spriteRam = spriteRam; _Nes.myPPU.spriteRamAddress = spriteRamAddress; _Nes.myPPU.spritesCrossed = spritesCrossed; _Nes.frameCounter = frameCounter; //APU _Nes.myAPU.FrameCounter = FrameCounter; _Nes.myAPU.PAL = _PAL; _Nes.myAPU.FrameIRQ = _FrameIRQ; //MAPPER 1 if (_Nes.myCartridge.mapper == 1) { Mapper1 map1 = (Mapper1)_Nes.myMapper.CurrentMapper; map1.mapper1_register8000BitPosition = mapper1_register8000BitPosition; map1.mapper1_registerA000BitPosition = mapper1_registerA000BitPosition; map1.mapper1_registerC000BitPosition = mapper1_registerC000BitPosition; map1.mapper1_registerE000BitPosition = mapper1_registerE000BitPosition; map1.mapper1_register8000Value = mapper1_register8000Value; map1.mapper1_registerA000Value = mapper1_registerA000Value; map1.mapper1_registerC000Value = mapper1_registerC000Value; map1.mapper1_registerE000Value = mapper1_registerE000Value; map1.mapper1_mirroringFlag = mapper1_mirroringFlag; map1.mapper1_onePageMirroring = mapper1_onePageMirroring; map1.mapper1_prgSwitchingArea = mapper1_prgSwitchingArea; map1.mapper1_prgSwitchingSize = mapper1_prgSwitchingSize; map1.mapper1_vromSwitchingSize = mapper1_vromSwitchingSize; } //MAPPER 4 if (_Nes.myCartridge.mapper == 4) { Mapper4 map4 = (Mapper4)_Nes.myMapper.CurrentMapper; map4.mapper4_commandNumber = mapper4_commandNumber; map4.mapper4_prgAddressSelect = mapper4_prgAddressSelect; map4.mapper4_chrAddressSelect = mapper4_chrAddressSelect; map4.timer_irq_enabled = mapper4_timer_irq_enabled; map4.timer_irq_count = mapper4_timer_irq_count; map4.timer_irq_reload = mapper4_timer_irq_reload; } //MAPPER 5 if (_Nes.myCartridge.mapper == 5) { Mapper5 map5 = (Mapper5)_Nes.myMapper.CurrentMapper; map5.mapper5_prgBankSize = mapper5_prgBankSize; map5.mapper5_chrBankSize = mapper5_chrBankSize; map5.mapper5_scanlineSplit = mapper5_scanlineSplit; map5.mapper5_splitIrqEnabled = mapper5_splitIrqEnabled; } //MAPPER 9 if (_Nes.myCartridge.mapper == 9) { Mapper9 map9 = (Mapper9)_Nes.myMapper.CurrentMapper; map9.latch1 = mapper9_latch1; map9.latch2 = mapper9_latch2; map9.latch1data1 = mapper9_latch1data1; map9.latch1data2 = mapper9_latch1data2; map9.latch2data1 = mapper9_latch2data1; map9.latch2data2 = mapper9_latch2data2; } //MAPPER 10 if (_Nes.myCartridge.mapper == 10) { Mapper10 map10 = (Mapper10)_Nes.myMapper.CurrentMapper; map10.latch1 = mapper10_latch1; map10.latch2 = mapper10_latch2; map10.latch1data1 = mapper10_latch1data1; map10.latch1data2 = mapper10_latch1data2; map10.latch2data1 = mapper10_latch2data1; map10.latch2data2 = mapper10_latch2data2; } //MAPPER 16 if (_Nes.myCartridge.mapper == 16) { Mapper16 map16 = (Mapper16)_Nes.myMapper.CurrentMapper; map16.timer_irq_counter_16 = timer_irq_counter_16; map16.timer_irq_Latch_16 = timer_irq_Latch_16; map16.timer_irq_enabled = timer_irq_enabled; } //MAPPER 18 if (_Nes.myCartridge.mapper == 18) { Mapper18 map18 = (Mapper18)_Nes.myMapper.CurrentMapper; map18.Mapper18_Timer = Mapper18_Timer; map18.Mapper18_latch = Mapper18_latch; map18.mapper18_control = mapper18_control; map18.Mapper18_IRQWidth = Mapper18_IRQWidth; map18.timer_irq_enabled = Mapper18_timer_irq_enabled; map18.x = Mapper18_x; } //MAPPER 225 if (_Nes.myCartridge.mapper == 225) { Mapper225 map225 = (Mapper225)_Nes.myMapper.CurrentMapper; map225.Mapper225_reg0 = Mapper225_reg0; map225.Mapper225_reg1 = Mapper225_reg1; map225.Mapper225_reg2 = Mapper225_reg2; map225.Mapper225_reg3 = Mapper225_reg3; } //MAPPER 32 if (_Nes.myCartridge.mapper == 32) { Mapper32 map32 = (Mapper32)_Nes.myMapper.CurrentMapper; map32.mapper32SwitchingMode = mapper32SwitchingMode; } //MAPPER 41 if (_Nes.myCartridge.mapper == 41) { Mapper41 map41 = (Mapper41)_Nes.myMapper.CurrentMapper; map41.Mapper41_CHR_Low = Mapper41_CHR_Low; map41.Mapper41_CHR_High = Mapper41_CHR_High; } //MAPPER 64 if (_Nes.myCartridge.mapper == 64) { Mapper64 map64 = (Mapper64)_Nes.myMapper.CurrentMapper; map64.mapper64_commandNumber = mapper64_commandNumber; map64.mapper64_prgAddressSelect = mapper64_prgAddressSelect; map64.mapper64_chrAddressSelect = mapper64_chrAddressSelect; } }
public void LoadNesData(NesEmulator _Nes) { //CPU a_register = _Nes.my6502.a_register; x_index_register = _Nes.my6502.x_index_register; y_index_register = _Nes.my6502.y_index_register; sp_register = _Nes.my6502.sp_register; pc_register = _Nes.my6502.pc_register; carry_flag = _Nes.my6502.carry_flag; zero_flag = _Nes.my6502.zero_flag; interrupt_flag = _Nes.my6502.interrupt_flag; decimal_flag = _Nes.my6502.decimal_flag; brk_flag = _Nes.my6502.brk_flag; overflow_flag = _Nes.my6502.overflow_flag; sign_flag = _Nes.my6502.sign_flag; tick_count = _Nes.my6502.tick_count; total_cycles = _Nes.my6502.total_cycles; currentOpcode = _Nes.my6502.currentOpcode; previousPC = _Nes.my6502.previousPC; //MEMORY scratchRam = _Nes.scratchRam; saveRam = _Nes.saveRam; JoyData1 = _Nes.JoyData1; JoyData2 = _Nes.JoyData2; JoyStrobe = _Nes.JoyStrobe; isSaveRAMReadonly = _Nes.isSaveRAMReadonly; //CART /* * We must save the chr_rom ONLY if the cart comes * with 0 chr_pages. */ if (_Nes.myCartridge.chr_rom_pages == 0) chr_rom = _Nes.myCartridge.chr_rom; mirroring = _Nes.myCartridge.mirroring; save_ram_present = _Nes.myCartridge.save_ram_present; is_vram = _Nes.myCartridge.is_vram; mirroringBase = _Nes.myCartridge.mirroringBase; //MAPPERS current_prg_rom_page = _Nes.myMapper.current_prg_rom_page; current_chr_rom_page = _Nes.myMapper.current_chr_rom_page; //PPU executeNMIonVBlank = _Nes.myPPU.executeNMIonVBlank; ppuMaster = _Nes.myPPU.ppuMaster; spriteSize = _Nes.myPPU.spriteSize; backgroundAddress = _Nes.myPPU.backgroundAddress; spriteAddress = _Nes.myPPU.spriteAddress; ppuAddressIncrement = _Nes.myPPU.ppuAddressIncrement; nameTableAddress = _Nes.myPPU.nameTableAddress; monochromeDisplay = _Nes.myPPU.monochromeDisplay; noBackgroundClipping = _Nes.myPPU.noBackgroundClipping; noSpriteClipping = _Nes.myPPU.noSpriteClipping; backgroundVisible = _Nes.myPPU.backgroundVisible; spritesVisible = _Nes.myPPU.spritesVisible; ppuColor = _Nes.myPPU.ppuColor; sprite0Hit = _Nes.myPPU.sprite0Hit; vramReadWriteAddress = _Nes.myPPU.vramReadWriteAddress; prev_vramReadWriteAddress = _Nes.myPPU.prev_vramReadWriteAddress; vramHiLoToggle = _Nes.myPPU.vramHiLoToggle; vramReadBuffer = _Nes.myPPU.vramReadBuffer; scrollV = _Nes.myPPU.scrollV; scrollH = _Nes.myPPU.scrollH; currentScanline = _Nes.myPPU.currentScanline; nameTables = _Nes.myPPU.nameTables; spriteRam = _Nes.myPPU.spriteRam; spriteRamAddress = _Nes.myPPU.spriteRamAddress; spritesCrossed = _Nes.myPPU.spritesCrossed; frameCounter = _Nes.frameCounter; //APU FrameCounter = _Nes.myAPU.FrameCounter; _PAL = _Nes.myAPU.PAL; _FrameIRQ = _Nes.myAPU.FrameIRQ; //MAPPERS //MAPPER 1 if (_Nes.myCartridge.mapper == 1) { Mapper1 map1 = (Mapper1)_Nes.myMapper.CurrentMapper; mapper1_register8000BitPosition = map1.mapper1_register8000BitPosition; mapper1_registerA000BitPosition = map1.mapper1_registerA000BitPosition; mapper1_registerC000BitPosition = map1.mapper1_registerC000BitPosition; mapper1_registerE000BitPosition = map1.mapper1_registerE000BitPosition; mapper1_register8000Value = map1.mapper1_register8000Value; mapper1_registerA000Value = map1.mapper1_registerA000Value; mapper1_registerC000Value = map1.mapper1_registerC000Value; mapper1_registerE000Value = map1.mapper1_registerE000Value; mapper1_mirroringFlag = map1.mapper1_mirroringFlag; mapper1_onePageMirroring = map1.mapper1_onePageMirroring; mapper1_prgSwitchingArea = map1.mapper1_prgSwitchingArea; mapper1_prgSwitchingSize = map1.mapper1_prgSwitchingSize; mapper1_vromSwitchingSize = map1.mapper1_vromSwitchingSize; } //MAPPER 4 if (_Nes.myCartridge.mapper == 4) { Mapper4 map4 = (Mapper4)_Nes.myMapper.CurrentMapper; mapper4_commandNumber = map4.mapper4_commandNumber; mapper4_prgAddressSelect = map4.mapper4_prgAddressSelect; mapper4_chrAddressSelect = map4.mapper4_chrAddressSelect; mapper4_timer_irq_enabled = map4.timer_irq_enabled; mapper4_timer_irq_count = map4.timer_irq_count; mapper4_timer_irq_reload = map4.timer_irq_reload; } //MAPPER 5 if (_Nes.myCartridge.mapper == 5) { Mapper5 map5 = (Mapper5)_Nes.myMapper.CurrentMapper; mapper5_prgBankSize = map5.mapper5_prgBankSize; mapper5_chrBankSize = map5.mapper5_chrBankSize; mapper5_scanlineSplit = map5.mapper5_scanlineSplit; mapper5_splitIrqEnabled = map5.mapper5_splitIrqEnabled; } //MAPPER 9 if (_Nes.myCartridge.mapper == 9) { Mapper9 map9 = (Mapper9)_Nes.myMapper.CurrentMapper; mapper9_latch1 = map9.latch1; mapper9_latch2 = map9.latch2; mapper9_latch1data1 = map9.latch1data1; mapper9_latch1data2 = map9.latch1data2; mapper9_latch2data1 = map9.latch2data1; mapper9_latch2data2 = map9.latch2data2; } //MAPPER 10 if (_Nes.myCartridge.mapper == 10) { Mapper10 map10 = (Mapper10)_Nes.myMapper.CurrentMapper; mapper10_latch1 = map10.latch1; mapper10_latch2 = map10.latch2; mapper10_latch1data1 = map10.latch1data1; mapper10_latch1data2 = map10.latch1data2; mapper10_latch2data1 = map10.latch2data1; mapper10_latch2data2 = map10.latch2data2; } //MAPPER 16 if (_Nes.myCartridge.mapper == 16) { Mapper16 map16 = (Mapper16)_Nes.myMapper.CurrentMapper; timer_irq_counter_16 = map16.timer_irq_counter_16; timer_irq_Latch_16 = map16.timer_irq_Latch_16; timer_irq_enabled = map16.timer_irq_enabled; } //MAPPER 18 if (_Nes.myCartridge.mapper == 18) { Mapper18 map18 = (Mapper18)_Nes.myMapper.CurrentMapper; Mapper18_Timer = map18.Mapper18_Timer; Mapper18_latch = map18.Mapper18_latch; mapper18_control = map18.mapper18_control; Mapper18_IRQWidth = map18.Mapper18_IRQWidth; Mapper18_timer_irq_enabled = map18.timer_irq_enabled; Mapper18_x = map18.x; } //MAPPER 225 if (_Nes.myCartridge.mapper == 225) { Mapper225 map225 = (Mapper225)_Nes.myMapper.CurrentMapper; Mapper225_reg0 = map225.Mapper225_reg0; Mapper225_reg1 = map225.Mapper225_reg1; Mapper225_reg2 = map225.Mapper225_reg2; Mapper225_reg3 = map225.Mapper225_reg3; } //MAPPER 32 if (_Nes.myCartridge.mapper == 32) { Mapper32 map32 = (Mapper32)_Nes.myMapper.CurrentMapper; mapper32SwitchingMode = map32.mapper32SwitchingMode; } //MAPPER 41 if (_Nes.myCartridge.mapper == 41) { Mapper41 map41 = (Mapper41)_Nes.myMapper.CurrentMapper; Mapper41_CHR_Low = map41.Mapper41_CHR_Low; Mapper41_CHR_High = map41.Mapper41_CHR_High; } //MAPPER 64 if (_Nes.myCartridge.mapper == 64) { Mapper64 map64 = (Mapper64)_Nes.myMapper.CurrentMapper; mapper64_commandNumber = map64.mapper64_commandNumber; mapper64_prgAddressSelect = map64.mapper64_prgAddressSelect; mapper64_chrAddressSelect = map64.mapper64_chrAddressSelect; } }