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 {
|
Update to v097r12 release.
byuu says:
Nothing WS-related this time.
First, I fixed expansion port device mapping. On first load, it was
mapping the expansion port device too late, so it ended up not taking
effect. I had to spin out the logic for that into
Program::connectDevices(). This was proving to be quite annoying while
testing eBoot (SNES-Hook simulation.)
Second, I fixed the audio->set(Frequency, Latency) functions to take
(uint) parameters from the configuration file, so the weird behavior
around changing settings in the audio panel should hopefully be gone
now.
Third, I rewrote the interface->load,unload functions to call into the
(Emulator)::System::load,unload functions. And I have those call out to
Cartridge::load,unload. Before, this was inverted, and Cartridge::load()
was invoking System::load(), which I felt was kind of backward.
The Super Game Boy really didn't like this change, however. And it took
me a few hours to power through it. Before, I had the Game Boy core
dummying out all the interface->(load,save)Request calls, and having the
SNES core make them for it. This is because the folder paths and IDs
will be different between the two cores.
I've redesigned things so that ICD2's Emulator::Interface overloads
loadRequest and saveRequest, and translates the requests into new
requests for the SuperFamicom core. This allows the Game Boy code to do
its own loading for everything without a bunch of Super Game Boy special
casing, and without any awkwardness around powering on with no cartridge
inserted.
This also lets the SNES side of things simply call into higher-level
GameBoy::interface->load,save(id, stream) functions instead of stabbing
at the raw underlying state inside of various Game Boy core emulation
classes. So things are a lot better abstracted now.
2016-02-08 03:17:59 +00:00
|
|
|
if(system.sgb()) system._clocksExecuted += clocks;
|
2016-01-11 10:31:30 +00:00
|
|
|
|
|
|
|
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;
|
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-02-09 11:51:12 +00:00
|
|
|
if(system.sgb()) scheduler.exit(Scheduler::Event::Step);
|
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;
|
|
|
|
}
|
|
|
|
}
|