Fixed PPU bug.
Fixed polling SDL events speed issue.
This commit is contained in:
parent
796828fa01
commit
5a459e582d
9
main.cpp
9
main.cpp
@ -14,20 +14,21 @@ int main() {
|
|||||||
nes::SdlWindow window(nes::Ppu::SCREEN_WIDTH, nes::Ppu::SCREEN_HEIGHT);
|
nes::SdlWindow window(nes::Ppu::SCREEN_WIDTH, nes::Ppu::SCREEN_HEIGHT);
|
||||||
window.setSize(nes::Ppu::SCREEN_WIDTH * 4, nes::Ppu::SCREEN_HEIGHT * 4);
|
window.setSize(nes::Ppu::SCREEN_WIDTH * 4, nes::Ppu::SCREEN_HEIGHT * 4);
|
||||||
|
|
||||||
device.setNewFrameCallback(std::bind(&nes::SdlWindow::drawFrame, &window, _1));
|
SDL_Event e;
|
||||||
|
device.setNewFrameCallback([&window, &e](auto buffer){
|
||||||
|
window.drawFrame(buffer);
|
||||||
|
while(SDL_PollEvent(&e));
|
||||||
|
});
|
||||||
device.connect(std::make_shared<SdlKeyboardController>());
|
device.connect(std::make_shared<SdlKeyboardController>());
|
||||||
device.insertCartridge("/home/selim/Downloads/smb.nes");
|
device.insertCartridge("/home/selim/Downloads/smb.nes");
|
||||||
//device.insertCartridge("/Users/selim/Documents/nestest.nes");
|
//device.insertCartridge("/Users/selim/Documents/nestest.nes");
|
||||||
//device.insertCartridge("C:\\Users\\selim\\Documents\\nestest.nes");
|
//device.insertCartridge("C:\\Users\\selim\\Documents\\nestest.nes");
|
||||||
|
|
||||||
SDL_Event e;
|
|
||||||
uint64_t cycles = 0;
|
uint64_t cycles = 0;
|
||||||
while (cycles < 1000000000) {
|
while (cycles < 1000000000) {
|
||||||
device.tick();
|
device.tick();
|
||||||
cycles++;
|
cycles++;
|
||||||
|
|
||||||
while(SDL_PollEvent(&e));
|
|
||||||
|
|
||||||
//int64_t us = static_cast<int64_t>(1000000000.0/(60*nes::Ppu::SCREEN_WIDTH*nes::Ppu::SCREEN_HEIGHT));
|
//int64_t us = static_cast<int64_t>(1000000000.0/(60*nes::Ppu::SCREEN_WIDTH*nes::Ppu::SCREEN_HEIGHT));
|
||||||
//std::this_thread::sleep_for(std::chrono::nanoseconds(1));
|
//std::this_thread::sleep_for(std::chrono::nanoseconds(1));
|
||||||
}
|
}
|
||||||
|
|||||||
33
src/Nes.cpp
33
src/Nes.cpp
@ -10,7 +10,12 @@
|
|||||||
|
|
||||||
namespace nes {
|
namespace nes {
|
||||||
|
|
||||||
Nes::Nes(): _cycles{}, _logger(100*1024*1024) {
|
Nes::Nes():
|
||||||
|
_cycles{}
|
||||||
|
#ifdef NES_LOGGING
|
||||||
|
,_logger(500*1024*1024)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
_cpu = std::make_unique<Cpu>();
|
_cpu = std::make_unique<Cpu>();
|
||||||
_ppu = std::make_shared<Ppu>();
|
_ppu = std::make_shared<Ppu>();
|
||||||
}
|
}
|
||||||
@ -42,24 +47,32 @@ namespace nes {
|
|||||||
void Nes::tick() {
|
void Nes::tick() {
|
||||||
|
|
||||||
bool needInterrupt = _ppu->tick();
|
bool needInterrupt = _ppu->tick();
|
||||||
// _logger.addLine(_cycles, _ppu->state());
|
#ifdef NES_LOGGING
|
||||||
|
_logger.addLine(_cycles, _ppu->state());
|
||||||
|
#endif
|
||||||
|
|
||||||
if(_cycles % 3 == 0) {
|
if(_cycles % 3 == 0) {
|
||||||
bool instructionExecuted = _cpu->tick();
|
bool instructionExecuted = _cpu->tick();
|
||||||
// if(instructionExecuted) {
|
#ifdef NES_LOGGING
|
||||||
// _logger.addLine(_cycles, _cpu->state());
|
if(instructionExecuted) {
|
||||||
// }
|
_logger.addLine(_cycles, _cpu->state());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if(needInterrupt) {
|
if(needInterrupt) {
|
||||||
_cpu->nmi();
|
_cpu->nmi();
|
||||||
// _logger.addLine(_cycles, "NMI");
|
#ifdef NES_LOGGING
|
||||||
// _logger.addLine(_cycles, _cpu->state());
|
_logger.addLine(_cycles, "NMI");
|
||||||
|
_logger.addLine(_cycles, _cpu->state());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// if(_cycles == 500000) {
|
#ifdef NES_LOGGING
|
||||||
// _logger.dump("/home/selim/Documents/log.txt");
|
if(_cycles == 3000000) {
|
||||||
// }
|
_logger.dump("/home/selim/Documents/log.txt");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
_cycles++;
|
_cycles++;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,7 +31,10 @@ namespace nes {
|
|||||||
std::unique_ptr<Cpu> _cpu;
|
std::unique_ptr<Cpu> _cpu;
|
||||||
std::shared_ptr<Ppu> _ppu;
|
std::shared_ptr<Ppu> _ppu;
|
||||||
std::shared_ptr<Cartridge> _cartridge;
|
std::shared_ptr<Cartridge> _cartridge;
|
||||||
|
|
||||||
|
#ifdef NES_LOGGING
|
||||||
Logger _logger;
|
Logger _logger;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -170,8 +170,8 @@ namespace nes {
|
|||||||
break;
|
break;
|
||||||
case PpuData:
|
case PpuData:
|
||||||
value = _dataTemp;
|
value = _dataTemp;
|
||||||
_dataTemp = internalRead(address);
|
_dataTemp = internalRead(_vRamAddress.value);
|
||||||
if(address >= 0x3F00) {
|
if(_vRamAddress.value >= 0x3F00) {
|
||||||
value = _dataTemp;
|
value = _dataTemp;
|
||||||
}
|
}
|
||||||
_vRamAddress.value += _control.incrementMode ? 32 : 1;
|
_vRamAddress.value += _control.incrementMode ? 32 : 1;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user