2010-12-28 06:03:02 +00:00
|
|
|
//70224 clocks/frame
|
|
|
|
// 456 clocks/scanline
|
|
|
|
// 154 scanlines/frame
|
|
|
|
|
2015-11-21 07:36:48 +00:00
|
|
|
auto CPU::add_clocks(uint clocks) -> void {
|
2016-01-11 10:31:30 +00:00
|
|
|
if(system.sgb()) system.clocks_executed += clocks;
|
|
|
|
|
|
|
|
while(clocks--) {
|
|
|
|
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++;
|
|
|
|
if((status.div & 15) == 0) timer_262144hz();
|
|
|
|
if((status.div & 63) == 0) timer_65536hz();
|
|
|
|
if((status.div & 255) == 0) timer_16384hz();
|
|
|
|
if((status.div & 511) == 0) timer_8192hz();
|
|
|
|
if((status.div & 1023) == 0) timer_4096hz();
|
2011-01-04 10:42:27 +00:00
|
|
|
|
2016-01-11 10:31:30 +00:00
|
|
|
ppu.clock -= ppu.frequency;
|
|
|
|
if(ppu.clock < 0) co_switch(scheduler.active_thread = ppu.thread);
|
2010-12-28 06:03:02 +00:00
|
|
|
|
2016-01-11 10:31:30 +00:00
|
|
|
apu.clock -= apu.frequency;
|
|
|
|
if(apu.clock < 0) co_switch(scheduler.active_thread = apu.thread);
|
|
|
|
}
|
2011-02-02 10:37:31 +00:00
|
|
|
|
2016-01-11 10:31:30 +00:00
|
|
|
if(system.sgb()) scheduler.exit(Scheduler::ExitReason::StepEvent);
|
2010-12-28 06:03:02 +00:00
|
|
|
}
|
|
|
|
|
2015-11-21 07:36:48 +00:00
|
|
|
auto CPU::timer_262144hz() -> void {
|
2011-01-02 04:46:54 +00:00
|
|
|
if(status.timer_enable && status.timer_clock == 1) {
|
2010-12-30 07:18:47 +00:00
|
|
|
if(++status.tima == 0) {
|
|
|
|
status.tima = status.tma;
|
2011-01-02 04:46:54 +00:00
|
|
|
interrupt_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::timer_65536hz() -> void {
|
2011-01-02 04:46:54 +00:00
|
|
|
if(status.timer_enable && status.timer_clock == 2) {
|
2010-12-30 07:18:47 +00:00
|
|
|
if(++status.tima == 0) {
|
|
|
|
status.tima = status.tma;
|
2011-01-02 04:46:54 +00:00
|
|
|
interrupt_raise(Interrupt::Timer);
|
2010-12-30 07:18:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-21 07:36:48 +00:00
|
|
|
auto CPU::timer_16384hz() -> void {
|
2011-01-02 04:46:54 +00:00
|
|
|
if(status.timer_enable && status.timer_clock == 3) {
|
2010-12-30 07:18:47 +00:00
|
|
|
if(++status.tima == 0) {
|
|
|
|
status.tima = status.tma;
|
2011-01-02 04:46:54 +00:00
|
|
|
interrupt_raise(Interrupt::Timer);
|
2010-12-30 07:18:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-21 07:36:48 +00:00
|
|
|
auto CPU::timer_8192hz() -> void {
|
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
|
|
|
if(status.serial_transfer && status.serial_clock) {
|
|
|
|
if(--status.serial_bits == 0) {
|
|
|
|
status.serial_transfer = 0;
|
|
|
|
interrupt_raise(Interrupt::Serial);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-21 07:36:48 +00:00
|
|
|
auto CPU::timer_4096hz() -> void {
|
2011-01-02 04:46:54 +00:00
|
|
|
if(status.timer_enable && status.timer_clock == 0) {
|
2010-12-30 07:18:47 +00:00
|
|
|
if(++status.tima == 0) {
|
|
|
|
status.tima = status.tma;
|
2011-01-02 04:46:54 +00:00
|
|
|
interrupt_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 {
|
2013-12-10 12:12:54 +00:00
|
|
|
if(status.dma_mode == 1 && status.dma_length && ppu.status.ly < 144) {
|
2015-11-21 07:36:48 +00:00
|
|
|
for(auto n : range(16)) {
|
2013-12-10 12:12:54 +00:00
|
|
|
dma_write(status.dma_target++, dma_read(status.dma_source++));
|
2011-10-27 00:00:17 +00:00
|
|
|
}
|
2013-12-10 12:12:54 +00:00
|
|
|
add_clocks(8 << status.speed_double);
|
2011-10-27 00:00:17 +00:00
|
|
|
status.dma_length -= 16;
|
|
|
|
}
|
|
|
|
}
|