2016-06-28 10:43:47 +00:00
|
|
|
auto CPU::wramAddress(uint16 addr) const -> uint {
|
2011-10-27 00:00:17 +00:00
|
|
|
addr &= 0x1fff;
|
|
|
|
if(addr < 0x1000) return addr;
|
2016-06-28 10:43:47 +00:00
|
|
|
auto bank = status.wramBank + (status.wramBank == 0);
|
2011-10-27 13:30:19 +00:00
|
|
|
return (bank * 0x1000) + (addr & 0x0fff);
|
2011-10-27 00:00:17 +00:00
|
|
|
}
|
|
|
|
|
2016-06-28 10:43:47 +00:00
|
|
|
auto CPU::joypPoll() -> void {
|
Update to v102r04 release.
byuu says:
Changelog:
- Super Game Boy support is functional once again
- new GameBoy::SuperGameBoyInterface class
- system.(dmg,cgb,sgb) is now Model::(Super)GameBoy(Color) ala the PC
Engine
- merged WonderSwanInterface, WonderSwanColorInterface shared
functions to WonderSwan::Interface
- merged GameBoyInterface, GameBoyColorInterface shared functions to
GameBoy::Interface
- Interface::unload() now calls Interface::save() for Master System,
Game Gear, Mega Drive, PC Engine, SuperGrafx
- PCE: emulated PCE-CD backup RAM; stored per-game as save.ram (2KiB
file)
- this means you can now save your progress in games like Neutopia
- the PCE-CD I/O registers like BRAM write protect are not
emulated yet
- PCE: IRQ sources now hold the IRQ line state, instead of the CPU
holding it
- this fixes most SuperGrafx games, which were fighting over the
VDC IRQ line previously
- PCE: CPU I/O $14xx should return the pending IRQ bits even if IRQs
are disabled
- PCE: VCE and the VDCs now synchronize to each other; fixes pixel
widths in all games
- PCE: greatly increased the accuracy of the VPC priority selection
code (windows may be buggy still)
- HuC6280: PLA, PLX, PLY should set Z, N flags; fixes many game bugs
[Jonas Quinn]
The big thing I wanted to do was enslave the VDC(s) to the VCE. But
unfortunately, I forgot about the asynchronous DMA channels that each
VDC supports, so this isn't going to be possible I'm afraid.
In the most demanding case, Daimakaimura in-game, we're looking at 85fps
on my Xeon E3 1276v3. So ... not great, and we don't even have sound
connected yet.
We are going to have to profile and optimize this code once sound
emulation and save states are in.
Basically, think of it like this: the VCE, VDC0, and VDC1 all have the
same overhead, scheduling wise (which is the bulk of the performance
loss) as the dot-renderer for the SNES core. So it's like there's three
bsnes-accuracy PPU threads running just for video.
-----
Oh, just a fair warning ... the hooks for the SGB are a work in
progress.
If anyone is working on higan or a fork and want to do something similar
to it, don't use it as a template, at least not yet.
Right now, higan looks like this:
- Emulator::Video handles the platform→videoRefresh calls
- Emulator::Audio handles the platform→audioSample calls
- each core hard-codes the platform→inputPoll, inputRumble calls
- each core hard-codes calls to path, open, load to process files
- dipSettings and notify are specialty hacks, neither are even hooked
up right now to anything
With the SGB, it's an emulation core inside an emulation core, so
ideally you want to hook all of those functions. Emulator::Video and
Emulator::Audio aren't really abstractions over that, as the GB core
calls them and we have to special case not calling them in SGB mode.
The path, open, load can be implemented without hooks, thanks to the UI
only using one instance of Emulator::Platform for all cores. All we have
to do is override the folder path ID for the "Game Boy.sys" folder, so
that it picks "Super Game Boy.sfc/" and loads its boot ROM instead.
That's just a simple argument to GameBoy::System::load() and we're done.
dipSettings, notify and inputRumble don't matter. But we do also have to
hook inputPoll as well.
The nice idea would be for SuperFamicom::ICD2 to inherit from
Emulator::Platform and provide the desired functions that we need to
overload. After that, we'd just need the GB core to keep an abstraction
over the global Emulator::platform\* handle, to select between the UI
version and the SFC::ICD2 version.
However ... that doesn't work because of Emulator::Video and
Emulator::Audio. They would also have to gain an abstraction over
Emulator::platform\*, and even worse ... you'd have to constantly swap
between the two so that the SFC core uses the UI, and the GB core uses
the ICD2.
And so, for right now, I'm checking Model::SuperGameBoy() -> bool
everywhere, and choosing between the UI and ICD2 targets that way. And
as such, the ICD2 doesn't really need Emulator::Platform inheritance,
although it certainly could do that and just use the functions it needs.
But the SGB is even weirder, because we need additional new signals
beyond just Emulator::Platform, like joypWrite(), etc.
I'd also like to work on the Emulator::Stream for the SGB core. I don't
see why we can't have the GB core create its own stream, and let the
ICD2 just use that instead. We just have to be careful about the ICD2's
CPU soft reset function, to make sure the GB core's Stream object
remains valid. What I think that needs is a way to release an
Emulator::Stream individually, rather than calling
Emulator::Audio::reset() to do it. They are shared\_pointer objects, so
I think if I added a destructor function to remove it from
Emulator::Audio::streams, then that should work.
2017-01-26 01:06:06 +00:00
|
|
|
function<auto (uint, uint, uint) -> int16> inputPoll = {&Emulator::Platform::inputPoll, platform};
|
|
|
|
if(Model::SuperGameBoy()) inputPoll = {&SuperGameBoyInterface::inputPoll, superGameBoy};
|
|
|
|
|
|
|
|
uint button = 0;
|
|
|
|
button |= inputPoll(0, 0, (uint)Input::Start) << 3;
|
|
|
|
button |= inputPoll(0, 0, (uint)Input::Select) << 2;
|
|
|
|
button |= inputPoll(0, 0, (uint)Input::B) << 1;
|
|
|
|
button |= inputPoll(0, 0, (uint)Input::A) << 0;
|
|
|
|
|
|
|
|
uint dpad = 0;
|
|
|
|
dpad |= inputPoll(0, 0, (uint)Input::Down) << 3;
|
|
|
|
dpad |= inputPoll(0, 0, (uint)Input::Up) << 2;
|
|
|
|
dpad |= inputPoll(0, 0, (uint)Input::Left) << 1;
|
|
|
|
dpad |= inputPoll(0, 0, (uint)Input::Right) << 0;
|
|
|
|
|
|
|
|
if(!Model::SuperGameBoy()) {
|
2014-01-28 10:04:58 +00:00
|
|
|
//D-pad pivot makes it impossible to press opposing directions at the same time
|
|
|
|
//however, Super Game Boy BIOS is able to set these bits together
|
|
|
|
if(dpad & 4) dpad &= ~8; //disallow up+down
|
|
|
|
if(dpad & 2) dpad &= ~1; //disallow left+right
|
|
|
|
}
|
2013-12-07 09:12:37 +00:00
|
|
|
|
2010-12-31 05:43:47 +00:00
|
|
|
status.joyp = 0x0f;
|
2016-06-28 10:43:47 +00:00
|
|
|
if(status.p15 == 1 && status.p14 == 1) status.joyp -= status.mltReq;
|
2010-12-31 05:43:47 +00:00
|
|
|
if(status.p15 == 0) status.joyp &= button ^ 0x0f;
|
|
|
|
if(status.p14 == 0) status.joyp &= dpad ^ 0x0f;
|
2016-06-05 22:10:01 +00:00
|
|
|
if(status.joyp != 0x0f) raise(Interrupt::Joypad);
|
2010-12-31 05:43:47 +00:00
|
|
|
}
|
|
|
|
|
2016-06-28 10:43:47 +00:00
|
|
|
auto CPU::readIO(uint16 addr) -> uint8 {
|
|
|
|
if(addr >= 0xc000 && addr <= 0xfdff) return wram[wramAddress(addr)];
|
2010-12-29 11:03:42 +00:00
|
|
|
if(addr >= 0xff80 && addr <= 0xfffe) return hram[addr & 0x7f];
|
2010-12-30 07:18:47 +00:00
|
|
|
|
|
|
|
if(addr == 0xff00) { //JOYP
|
2016-06-28 10:43:47 +00:00
|
|
|
joypPoll();
|
Update to v097r02 release.
byuu says:
Note: balanced/performance profiles still broken, sorry.
Changelog:
- added nall/GNUmakefile unique() function; used on linking phase of
higan
- added nall/unique_pointer
- target-tomoko and {System}::Video updated to use
unique_pointer<ClassName> instead of ClassName* [1]
- locate() updated to search multiple paths [2]
- GB: pass gekkio's if_ie_registers and boot_hwio-G test ROMs
- FC, GB, GBA: merge video/ into the PPU cores
- ruby: fixed ~AudioXAudio2() typo
[1] I expected this to cause new crashes on exit due to changing the
order of destruction of objects (and deleting things that weren't
deleted before), but ... so far, so good. I guess we'll see what crops
up, especially on OS X (which is already crashing for unknown reasons on
exit.)
[2] right now, the search paths are: programpath(), {configpath(),
"higan/"}, {localpath(), "higan/"}; but we can add as many more as we
want, and we can also add platform-specific versions.
2016-01-25 11:27:18 +00:00
|
|
|
return 0xc0
|
|
|
|
| (status.p15 << 5)
|
2010-12-30 07:18:47 +00:00
|
|
|
| (status.p14 << 4)
|
2010-12-31 05:43:47 +00:00
|
|
|
| (status.joyp << 0);
|
2010-12-30 07:18:47 +00:00
|
|
|
}
|
|
|
|
|
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(addr == 0xff01) { //SB
|
Update to v097r02 release.
byuu says:
Note: balanced/performance profiles still broken, sorry.
Changelog:
- added nall/GNUmakefile unique() function; used on linking phase of
higan
- added nall/unique_pointer
- target-tomoko and {System}::Video updated to use
unique_pointer<ClassName> instead of ClassName* [1]
- locate() updated to search multiple paths [2]
- GB: pass gekkio's if_ie_registers and boot_hwio-G test ROMs
- FC, GB, GBA: merge video/ into the PPU cores
- ruby: fixed ~AudioXAudio2() typo
[1] I expected this to cause new crashes on exit due to changing the
order of destruction of objects (and deleting things that weren't
deleted before), but ... so far, so good. I guess we'll see what crops
up, especially on OS X (which is already crashing for unknown reasons on
exit.)
[2] right now, the search paths are: programpath(), {configpath(),
"higan/"}, {localpath(), "higan/"}; but we can add as many more as we
want, and we can also add platform-specific versions.
2016-01-25 11:27:18 +00:00
|
|
|
return 0x00;
|
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(addr == 0xff02) { //SC
|
2016-06-28 10:43:47 +00:00
|
|
|
return (status.serialTransfer << 7)
|
Update to v097r02 release.
byuu says:
Note: balanced/performance profiles still broken, sorry.
Changelog:
- added nall/GNUmakefile unique() function; used on linking phase of
higan
- added nall/unique_pointer
- target-tomoko and {System}::Video updated to use
unique_pointer<ClassName> instead of ClassName* [1]
- locate() updated to search multiple paths [2]
- GB: pass gekkio's if_ie_registers and boot_hwio-G test ROMs
- FC, GB, GBA: merge video/ into the PPU cores
- ruby: fixed ~AudioXAudio2() typo
[1] I expected this to cause new crashes on exit due to changing the
order of destruction of objects (and deleting things that weren't
deleted before), but ... so far, so good. I guess we'll see what crops
up, especially on OS X (which is already crashing for unknown reasons on
exit.)
[2] right now, the search paths are: programpath(), {configpath(),
"higan/"}, {localpath(), "higan/"}; but we can add as many more as we
want, and we can also add platform-specific versions.
2016-01-25 11:27:18 +00:00
|
|
|
| 0x7e
|
2016-06-28 10:43:47 +00:00
|
|
|
| (status.serialClock << 0);
|
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
|
|
|
}
|
|
|
|
|
2010-12-30 07:18:47 +00:00
|
|
|
if(addr == 0xff04) { //DIV
|
2016-01-11 10:31:30 +00:00
|
|
|
return status.div >> 8;
|
2010-12-30 07:18:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(addr == 0xff05) { //TIMA
|
|
|
|
return status.tima;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(addr == 0xff06) { //TMA
|
|
|
|
return status.tma;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(addr == 0xff07) { //TAC
|
Update to v097r02 release.
byuu says:
Note: balanced/performance profiles still broken, sorry.
Changelog:
- added nall/GNUmakefile unique() function; used on linking phase of
higan
- added nall/unique_pointer
- target-tomoko and {System}::Video updated to use
unique_pointer<ClassName> instead of ClassName* [1]
- locate() updated to search multiple paths [2]
- GB: pass gekkio's if_ie_registers and boot_hwio-G test ROMs
- FC, GB, GBA: merge video/ into the PPU cores
- ruby: fixed ~AudioXAudio2() typo
[1] I expected this to cause new crashes on exit due to changing the
order of destruction of objects (and deleting things that weren't
deleted before), but ... so far, so good. I guess we'll see what crops
up, especially on OS X (which is already crashing for unknown reasons on
exit.)
[2] right now, the search paths are: programpath(), {configpath(),
"higan/"}, {localpath(), "higan/"}; but we can add as many more as we
want, and we can also add platform-specific versions.
2016-01-25 11:27:18 +00:00
|
|
|
return 0xf8
|
2016-06-28 10:43:47 +00:00
|
|
|
| (status.timerEnable << 2)
|
|
|
|
| (status.timerClock << 0);
|
2010-12-30 07:18:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(addr == 0xff0f) { //IF
|
Update to v097r02 release.
byuu says:
Note: balanced/performance profiles still broken, sorry.
Changelog:
- added nall/GNUmakefile unique() function; used on linking phase of
higan
- added nall/unique_pointer
- target-tomoko and {System}::Video updated to use
unique_pointer<ClassName> instead of ClassName* [1]
- locate() updated to search multiple paths [2]
- GB: pass gekkio's if_ie_registers and boot_hwio-G test ROMs
- FC, GB, GBA: merge video/ into the PPU cores
- ruby: fixed ~AudioXAudio2() typo
[1] I expected this to cause new crashes on exit due to changing the
order of destruction of objects (and deleting things that weren't
deleted before), but ... so far, so good. I guess we'll see what crops
up, especially on OS X (which is already crashing for unknown reasons on
exit.)
[2] right now, the search paths are: programpath(), {configpath(),
"higan/"}, {localpath(), "higan/"}; but we can add as many more as we
want, and we can also add platform-specific versions.
2016-01-25 11:27:18 +00:00
|
|
|
return 0xe0
|
2016-06-28 10:43:47 +00:00
|
|
|
| (status.interruptRequestJoypad << 4)
|
|
|
|
| (status.interruptRequestSerial << 3)
|
|
|
|
| (status.interruptRequestTimer << 2)
|
|
|
|
| (status.interruptRequestStat << 1)
|
|
|
|
| (status.interruptRequestVblank << 0);
|
2010-12-30 07:18:47 +00:00
|
|
|
}
|
|
|
|
|
2011-10-27 00:00:17 +00:00
|
|
|
if(addr == 0xff4d) { //KEY1
|
2016-06-28 10:43:47 +00:00
|
|
|
return (status.speedDouble << 7);
|
2011-10-27 00:00:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(addr == 0xff55) { //HDMA5
|
2016-06-28 10:43:47 +00:00
|
|
|
return (status.dmaCompleted << 7)
|
|
|
|
| (((status.dmaLength / 16) - 1) & 0x7f);
|
2011-10-27 00:00:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(addr == 0xff56) { //RP
|
|
|
|
return 0x02;
|
|
|
|
}
|
|
|
|
|
2011-10-27 13:30:19 +00:00
|
|
|
if(addr == 0xff6c) { //???
|
|
|
|
return 0xfe | status.ff6c;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(addr == 0xff70) { //SVBK
|
2016-06-28 10:43:47 +00:00
|
|
|
return status.wramBank;
|
2011-10-27 13:30:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(addr == 0xff72) { //???
|
|
|
|
return status.ff72;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(addr == 0xff73) { //???
|
|
|
|
return status.ff73;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(addr == 0xff74) { //???
|
|
|
|
return status.ff74;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(addr == 0xff75) { //???
|
|
|
|
return 0x8f | status.ff75;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(addr == 0xff76) { //???
|
2016-01-08 09:23:46 +00:00
|
|
|
return 0xff;
|
2011-10-27 13:30:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(addr == 0xff77) { //???
|
2016-01-08 09:23:46 +00:00
|
|
|
return 0xff;
|
2011-10-27 13:30:19 +00:00
|
|
|
}
|
2011-10-27 00:00:17 +00:00
|
|
|
|
2010-12-30 07:18:47 +00:00
|
|
|
if(addr == 0xffff) { //IE
|
Update to v097r02 release.
byuu says:
Note: balanced/performance profiles still broken, sorry.
Changelog:
- added nall/GNUmakefile unique() function; used on linking phase of
higan
- added nall/unique_pointer
- target-tomoko and {System}::Video updated to use
unique_pointer<ClassName> instead of ClassName* [1]
- locate() updated to search multiple paths [2]
- GB: pass gekkio's if_ie_registers and boot_hwio-G test ROMs
- FC, GB, GBA: merge video/ into the PPU cores
- ruby: fixed ~AudioXAudio2() typo
[1] I expected this to cause new crashes on exit due to changing the
order of destruction of objects (and deleting things that weren't
deleted before), but ... so far, so good. I guess we'll see what crops
up, especially on OS X (which is already crashing for unknown reasons on
exit.)
[2] right now, the search paths are: programpath(), {configpath(),
"higan/"}, {localpath(), "higan/"}; but we can add as many more as we
want, and we can also add platform-specific versions.
2016-01-25 11:27:18 +00:00
|
|
|
return 0xe0
|
2016-06-28 10:43:47 +00:00
|
|
|
| (status.interruptEnableJoypad << 4)
|
|
|
|
| (status.interruptEnableSerial << 3)
|
|
|
|
| (status.interruptEnableTimer << 2)
|
|
|
|
| (status.interruptEnableStat << 1)
|
|
|
|
| (status.interruptEnableVblank << 0);
|
2010-12-30 07:18:47 +00:00
|
|
|
}
|
|
|
|
|
2016-01-08 09:23:46 +00:00
|
|
|
return 0xff;
|
2010-12-29 11:03:42 +00:00
|
|
|
}
|
|
|
|
|
2016-06-28 10:43:47 +00:00
|
|
|
auto CPU::writeIO(uint16 addr, uint8 data) -> void {
|
|
|
|
if(addr >= 0xc000 && addr <= 0xfdff) { wram[wramAddress(addr)] = data; return; }
|
2010-12-29 11:03:42 +00:00
|
|
|
if(addr >= 0xff80 && addr <= 0xfffe) { hram[addr & 0x7f] = data; return; }
|
2010-12-30 07:18:47 +00:00
|
|
|
|
|
|
|
if(addr == 0xff00) { //JOYP
|
|
|
|
status.p15 = data & 0x20;
|
|
|
|
status.p14 = data & 0x10;
|
Update to v102r04 release.
byuu says:
Changelog:
- Super Game Boy support is functional once again
- new GameBoy::SuperGameBoyInterface class
- system.(dmg,cgb,sgb) is now Model::(Super)GameBoy(Color) ala the PC
Engine
- merged WonderSwanInterface, WonderSwanColorInterface shared
functions to WonderSwan::Interface
- merged GameBoyInterface, GameBoyColorInterface shared functions to
GameBoy::Interface
- Interface::unload() now calls Interface::save() for Master System,
Game Gear, Mega Drive, PC Engine, SuperGrafx
- PCE: emulated PCE-CD backup RAM; stored per-game as save.ram (2KiB
file)
- this means you can now save your progress in games like Neutopia
- the PCE-CD I/O registers like BRAM write protect are not
emulated yet
- PCE: IRQ sources now hold the IRQ line state, instead of the CPU
holding it
- this fixes most SuperGrafx games, which were fighting over the
VDC IRQ line previously
- PCE: CPU I/O $14xx should return the pending IRQ bits even if IRQs
are disabled
- PCE: VCE and the VDCs now synchronize to each other; fixes pixel
widths in all games
- PCE: greatly increased the accuracy of the VPC priority selection
code (windows may be buggy still)
- HuC6280: PLA, PLX, PLY should set Z, N flags; fixes many game bugs
[Jonas Quinn]
The big thing I wanted to do was enslave the VDC(s) to the VCE. But
unfortunately, I forgot about the asynchronous DMA channels that each
VDC supports, so this isn't going to be possible I'm afraid.
In the most demanding case, Daimakaimura in-game, we're looking at 85fps
on my Xeon E3 1276v3. So ... not great, and we don't even have sound
connected yet.
We are going to have to profile and optimize this code once sound
emulation and save states are in.
Basically, think of it like this: the VCE, VDC0, and VDC1 all have the
same overhead, scheduling wise (which is the bulk of the performance
loss) as the dot-renderer for the SNES core. So it's like there's three
bsnes-accuracy PPU threads running just for video.
-----
Oh, just a fair warning ... the hooks for the SGB are a work in
progress.
If anyone is working on higan or a fork and want to do something similar
to it, don't use it as a template, at least not yet.
Right now, higan looks like this:
- Emulator::Video handles the platform→videoRefresh calls
- Emulator::Audio handles the platform→audioSample calls
- each core hard-codes the platform→inputPoll, inputRumble calls
- each core hard-codes calls to path, open, load to process files
- dipSettings and notify are specialty hacks, neither are even hooked
up right now to anything
With the SGB, it's an emulation core inside an emulation core, so
ideally you want to hook all of those functions. Emulator::Video and
Emulator::Audio aren't really abstractions over that, as the GB core
calls them and we have to special case not calling them in SGB mode.
The path, open, load can be implemented without hooks, thanks to the UI
only using one instance of Emulator::Platform for all cores. All we have
to do is override the folder path ID for the "Game Boy.sys" folder, so
that it picks "Super Game Boy.sfc/" and loads its boot ROM instead.
That's just a simple argument to GameBoy::System::load() and we're done.
dipSettings, notify and inputRumble don't matter. But we do also have to
hook inputPoll as well.
The nice idea would be for SuperFamicom::ICD2 to inherit from
Emulator::Platform and provide the desired functions that we need to
overload. After that, we'd just need the GB core to keep an abstraction
over the global Emulator::platform\* handle, to select between the UI
version and the SFC::ICD2 version.
However ... that doesn't work because of Emulator::Video and
Emulator::Audio. They would also have to gain an abstraction over
Emulator::platform\*, and even worse ... you'd have to constantly swap
between the two so that the SFC core uses the UI, and the GB core uses
the ICD2.
And so, for right now, I'm checking Model::SuperGameBoy() -> bool
everywhere, and choosing between the UI and ICD2 targets that way. And
as such, the ICD2 doesn't really need Emulator::Platform inheritance,
although it certainly could do that and just use the functions it needs.
But the SGB is even weirder, because we need additional new signals
beyond just Emulator::Platform, like joypWrite(), etc.
I'd also like to work on the Emulator::Stream for the SGB core. I don't
see why we can't have the GB core create its own stream, and let the
ICD2 just use that instead. We just have to be careful about the ICD2's
CPU soft reset function, to make sure the GB core's Stream object
remains valid. What I think that needs is a way to release an
Emulator::Stream individually, rather than calling
Emulator::Audio::reset() to do it. They are shared\_pointer objects, so
I think if I added a destructor function to remove it from
Emulator::Audio::streams, then that should work.
2017-01-26 01:06:06 +00:00
|
|
|
if(Model::SuperGameBoy()) superGameBoy->joypWrite(status.p15, status.p14);
|
2010-12-30 07:18:47 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(addr == 0xff01) { //SB
|
2016-06-28 10:43:47 +00:00
|
|
|
status.serialData = data;
|
2010-12-30 07:18:47 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(addr == 0xff02) { //SC
|
2016-06-28 10:43:47 +00:00
|
|
|
status.serialTransfer = data & 0x80;
|
|
|
|
status.serialClock = data & 0x01;
|
|
|
|
if(status.serialTransfer) status.serialBits = 8;
|
2010-12-30 07:18:47 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(addr == 0xff04) { //DIV
|
|
|
|
status.div = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(addr == 0xff05) { //TIMA
|
|
|
|
status.tima = data;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(addr == 0xff06) { //TMA
|
|
|
|
status.tma = data;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(addr == 0xff07) { //TAC
|
2016-06-28 10:43:47 +00:00
|
|
|
status.timerEnable = data & 0x04;
|
|
|
|
status.timerClock = data & 0x03;
|
2010-12-30 07:18:47 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(addr == 0xff0f) { //IF
|
2016-06-28 10:43:47 +00:00
|
|
|
status.interruptRequestJoypad = data & 0x10;
|
|
|
|
status.interruptRequestSerial = data & 0x08;
|
|
|
|
status.interruptRequestTimer = data & 0x04;
|
|
|
|
status.interruptRequestStat = data & 0x02;
|
|
|
|
status.interruptRequestVblank = data & 0x01;
|
2010-12-30 07:18:47 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-27 00:00:17 +00:00
|
|
|
if(addr == 0xff4d) { //KEY1
|
2016-06-28 10:43:47 +00:00
|
|
|
status.speedSwitch = data & 0x01;
|
2011-10-27 00:00:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(addr == 0xff51) { //HDMA1
|
2016-06-28 10:43:47 +00:00
|
|
|
status.dmaSource = (status.dmaSource & 0x00ff) | (data << 8);
|
2011-10-27 00:00:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(addr == 0xff52) { //HDMA2
|
2016-06-28 10:43:47 +00:00
|
|
|
status.dmaSource = (status.dmaSource & 0xff00) | (data & 0xf0);
|
2011-10-27 00:00:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(addr == 0xff53) { //HDMA3
|
2016-06-28 10:43:47 +00:00
|
|
|
status.dmaTarget = (status.dmaTarget & 0x00ff) | (data << 8);
|
2011-10-27 00:00:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(addr == 0xff54) { //HDMA4
|
2016-06-28 10:43:47 +00:00
|
|
|
status.dmaTarget = (status.dmaTarget & 0xff00) | (data & 0xf0);
|
2011-10-27 00:00:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(addr == 0xff55) { //HDMA5
|
2016-06-28 10:43:47 +00:00
|
|
|
status.dmaMode = data & 0x80;
|
|
|
|
status.dmaLength = ((data & 0x7f) + 1) * 16;
|
|
|
|
status.dmaCompleted = !status.dmaMode;
|
2013-12-10 12:12:54 +00:00
|
|
|
|
2016-06-28 10:43:47 +00:00
|
|
|
if(status.dmaMode == 0) {
|
2013-12-10 12:12:54 +00:00
|
|
|
do {
|
2016-01-11 10:31:30 +00:00
|
|
|
for(auto n : range(16)) {
|
2016-06-28 10:43:47 +00:00
|
|
|
writeDMA(status.dmaTarget++, readDMA(status.dmaSource++));
|
2013-12-10 12:12:54 +00:00
|
|
|
}
|
2016-06-28 10:43:47 +00:00
|
|
|
step(8 << status.speedDouble);
|
|
|
|
status.dmaLength -= 16;
|
|
|
|
} while(status.dmaLength);
|
2013-12-10 12:12:54 +00:00
|
|
|
}
|
2011-10-27 00:00:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(addr == 0xff56) { //RP
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(addr == 0xff6c) { //???
|
|
|
|
status.ff6c = data & 0x01;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(addr == 0xff72) { //???
|
|
|
|
status.ff72 = data;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(addr == 0xff73) { //???
|
|
|
|
status.ff73 = data;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(addr == 0xff74) { //???
|
|
|
|
status.ff74 = data;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(addr == 0xff75) { //???
|
|
|
|
status.ff75 = data & 0x70;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(addr == 0xff70) { //SVBK
|
2016-06-28 10:43:47 +00:00
|
|
|
status.wramBank = data & 0x07;
|
2011-10-27 00:00:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-12-30 07:18:47 +00:00
|
|
|
if(addr == 0xffff) { //IE
|
2016-06-28 10:43:47 +00:00
|
|
|
status.interruptEnableJoypad = data & 0x10;
|
|
|
|
status.interruptEnableSerial = data & 0x08;
|
|
|
|
status.interruptEnableTimer = data & 0x04;
|
|
|
|
status.interruptEnableStat = data & 0x02;
|
|
|
|
status.interruptEnableVblank = data & 0x01;
|
2010-12-30 07:18:47 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-12-29 11:03:42 +00:00
|
|
|
}
|