2010-12-28 06:03:02 +00:00
|
|
|
//70224 clocks/frame
|
|
|
|
// 456 clocks/scanline
|
|
|
|
// 154 scanlines/frame
|
|
|
|
|
2016-06-28 10:43:47 +00:00
|
|
|
auto CPU::step(uint clocks) -> void {
|
2016-06-05 22:10:01 +00:00
|
|
|
for(auto n : range(clocks)) {
|
2016-01-11 10:31:30 +00:00
|
|
|
if(++status.clock == 0) {
|
|
|
|
cartridge.mbc3.second();
|
|
|
|
}
|
2011-01-06 10:16:07 +00:00
|
|
|
|
2016-01-11 10:31:30 +00:00
|
|
|
//4MHz / N(hz) - 1 = mask
|
|
|
|
status.div++;
|
2016-06-28 10:43:47 +00:00
|
|
|
if((status.div & 15) == 0) timer262144hz();
|
|
|
|
if((status.div & 63) == 0) timer65536hz();
|
|
|
|
if((status.div & 255) == 0) timer16384hz();
|
|
|
|
if((status.div & 511) == 0) timer8192hz();
|
|
|
|
if((status.div & 1023) == 0) timer4096hz();
|
2011-01-04 10:42:27 +00:00
|
|
|
|
2016-01-11 10:31:30 +00:00
|
|
|
ppu.clock -= ppu.frequency;
|
2016-02-09 11:51:12 +00:00
|
|
|
if(ppu.clock < 0) co_switch(ppu.thread);
|
2010-12-28 06:03:02 +00:00
|
|
|
|
2016-01-11 10:31:30 +00:00
|
|
|
apu.clock -= apu.frequency;
|
2016-02-09 11:51:12 +00:00
|
|
|
if(apu.clock < 0) co_switch(apu.thread);
|
2016-01-11 10:31:30 +00:00
|
|
|
}
|
2011-02-02 10:37:31 +00:00
|
|
|
|
2016-06-05 22:10:01 +00:00
|
|
|
if(system.sgb()) {
|
|
|
|
system._clocksExecuted += clocks;
|
|
|
|
scheduler.exit(Scheduler::Event::Step);
|
|
|
|
}
|
2010-12-28 06:03:02 +00:00
|
|
|
}
|
|
|
|
|
2016-06-28 10:43:47 +00:00
|
|
|
auto CPU::timer262144hz() -> void {
|
|
|
|
if(status.timerEnable && status.timerClock == 1) {
|
2010-12-30 07:18:47 +00:00
|
|
|
if(++status.tima == 0) {
|
|
|
|
status.tima = status.tma;
|
2016-06-05 22:10:01 +00:00
|
|
|
raise(Interrupt::Timer);
|
2010-12-30 07:18:47 +00:00
|
|
|
}
|
|
|
|
}
|
2010-12-28 06:03:02 +00:00
|
|
|
}
|
|
|
|
|
2016-06-28 10:43:47 +00:00
|
|
|
auto CPU::timer65536hz() -> void {
|
|
|
|
if(status.timerEnable && status.timerClock == 2) {
|
2010-12-30 07:18:47 +00:00
|
|
|
if(++status.tima == 0) {
|
|
|
|
status.tima = status.tma;
|
2016-06-05 22:10:01 +00:00
|
|
|
raise(Interrupt::Timer);
|
2010-12-30 07:18:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-28 10:43:47 +00:00
|
|
|
auto CPU::timer16384hz() -> void {
|
|
|
|
if(status.timerEnable && status.timerClock == 3) {
|
2010-12-30 07:18:47 +00:00
|
|
|
if(++status.tima == 0) {
|
|
|
|
status.tima = status.tma;
|
2016-06-05 22:10:01 +00:00
|
|
|
raise(Interrupt::Timer);
|
2010-12-30 07:18:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-28 10:43:47 +00:00
|
|
|
auto CPU::timer8192hz() -> void {
|
|
|
|
if(status.serialTransfer && status.serialClock) {
|
|
|
|
if(--status.serialBits == 0) {
|
|
|
|
status.serialTransfer = 0;
|
2016-06-05 22:10:01 +00:00
|
|
|
raise(Interrupt::Serial);
|
Update to v074r11 release.
byuu says:
Changelog:
- debugger compiles on all three profiles
- libsnes compiles on all three platforms (no API changes to libsnes)
- memory.cpp : namespace memory removed (wram -> cpu, apuram -> smp,
vram, oam, cgram -> ppu)
- sa1.cpp : namespace memory removed (SA-1 specific functions merged
inline to SA1::bus_read,write)
- GameBoy: added serial link support with interrupts and proper 8192hz
timing, but obviously it acts as if no other GB is connected to it
- GameBoy: added STAT OAM interrupt, and better STAT d1,d0 mode values
- UI: since Qt is dead, I've renamed the config files back to bsnes.cfg
and bsnes-geometry.cfg
- SA1: IRAM was not syncing to CPU on SA-1 side
- PPU/Accuracy and PPU/Performance needed Sprite oam renamed to Sprite
sprite; so that I could add uint8 oam[544]
- makes more sense anyway, OAM = object attribute memory, obj or
sprite are better names for Sprite rendering class
- more cleanup
2011-01-24 09:03:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-28 10:43:47 +00:00
|
|
|
auto CPU::timer4096hz() -> void {
|
|
|
|
if(status.timerEnable && status.timerClock == 0) {
|
2010-12-30 07:18:47 +00:00
|
|
|
if(++status.tima == 0) {
|
|
|
|
status.tima = status.tma;
|
2016-06-05 22:10:01 +00:00
|
|
|
raise(Interrupt::Timer);
|
2010-12-30 07:18:47 +00:00
|
|
|
}
|
|
|
|
}
|
2010-12-28 06:03:02 +00:00
|
|
|
}
|
|
|
|
|
2015-11-21 07:36:48 +00:00
|
|
|
auto CPU::hblank() -> void {
|
2016-06-28 10:43:47 +00:00
|
|
|
if(status.dmaMode == 1 && status.dmaLength && ppu.status.ly < 144) {
|
2015-11-21 07:36:48 +00:00
|
|
|
for(auto n : range(16)) {
|
2016-06-28 10:43:47 +00:00
|
|
|
writeDMA(status.dmaTarget++, readDMA(status.dmaSource++));
|
2011-10-27 00:00:17 +00:00
|
|
|
}
|
2016-06-28 10:43:47 +00:00
|
|
|
step(8 << status.speedDouble);
|
|
|
|
status.dmaLength -= 16;
|
2011-10-27 00:00:17 +00:00
|
|
|
}
|
|
|
|
}
|