2012-03-23 10:43:39 +00:00
|
|
|
#include <processor/processor.hpp>
|
|
|
|
#include "arm.hpp"
|
|
|
|
|
|
|
|
namespace Processor {
|
|
|
|
|
2012-03-19 11:19:53 +00:00
|
|
|
#include "registers.cpp"
|
2012-03-27 11:02:57 +00:00
|
|
|
#include "algorithms.cpp"
|
2012-03-23 10:43:39 +00:00
|
|
|
#include "instructions-arm.cpp"
|
|
|
|
#include "instructions-thumb.cpp"
|
2015-06-24 13:21:24 +00:00
|
|
|
#include "step.cpp"
|
2012-03-21 11:08:16 +00:00
|
|
|
#include "disassembler.cpp"
|
Update to v087r26 release.
byuu says:
Changelog:
- fixed FIFO[1] reset behavior (fixes audio in Sword of Mana)
- added FlashROM emulation (both sizes)
- GBA parses RAM settings from manifest.xml now
- save RAM is written to disk now
- added save state support (it's currently broken, though)
- fixed ROM/RAM access timings
- open bus should mostly work (we don't do the PC+12 stuff yet)
- emulated the undocumented memory control register (mirror IWRAM,
disable I+EWRAM, EWRAM wait state count)
- emulated keypad interrupts
- emulated STOP (freezes video, audio, DMA and timers; only breaks on
keypad IRQs)
- probably a lot more, it was a long night ...
Show stoppers, missing things, broken things, etc:
- ST018 is still completely broken
- GBC audio sequencer apparently needs work
- GBA audio FIFO buffer seems too quiet
- PHI / ROM prefetch needs to be emulated (no idea on how to do this,
especially PHI)
- SOUNDBIAS 64/128/256khz modes should output at that resolution
(really, we need to simulate PWM properly, no idea on how to do this)
- object mosaic top-left coordinates are wrong (minor, fixing will
actually make the effect look worse)
- need to emulate PPU greenswap and color palette distortion (no idea on
how do this)
- need GBA save type database (I would also LIKE to blacklist
/ patch-out trainers, but that's a discussion for another day.)
- some ARM ops advance the prefetch buffer, so you can read PC+12 in
some cases
2012-04-16 12:19:39 +00:00
|
|
|
#include "serialization.cpp"
|
2012-03-19 11:19:53 +00:00
|
|
|
|
2015-06-24 13:21:24 +00:00
|
|
|
auto ARM::power() -> void {
|
2012-03-19 11:19:53 +00:00
|
|
|
processor.power();
|
Update to v087r08 release.
byuu says:
Added some more ARM opcodes, hooked up MMIO. Bind it with mmio[(addr
000-3ff)] = this; inside CPU/PPU/APU, goes to read(), write().
Also moved the Hitachi HG51B core to processor/, and split it apart from
the snes/chip/hitachidsp implementation.
This one actually worked really well. Very clean split between MMIO/DMA
and the processor core. I may move a more generic DMA function inside
the core, not sure yet.
I still believe the HG51B169 to be a variant of the HG51BS family, but
given they're meant to be incredibly flexible microcontrollers, it's
possible that each variant gets its own instruction set.
So, who knows. We'll worry about it if we ever find another HG51B DSP,
I guess.
GBA BIOS is constantly reading from 04000300, but it never writes. If
I return prng()&1, I can get it to proceed until it hits a bad opcode
(stc opcode, which the GBA lacks a coprocessor so ... bad codepath.)
Without it, it just reads that register forever and keeps resetting the
system, or something ...
I guess we're going to have to try and get ARMwrestler working, because
the BIOS seems to need too much emulation code to do anything at all.
2012-03-24 07:52:36 +00:00
|
|
|
vector(0x00000000, Processor::Mode::SVC);
|
2012-03-19 11:19:53 +00:00
|
|
|
pipeline.reload = true;
|
2015-07-01 10:58:42 +00:00
|
|
|
pipeline.nonsequential = true;
|
2012-03-29 11:58:10 +00:00
|
|
|
crash = false;
|
2012-03-21 11:08:16 +00:00
|
|
|
r(15).modify = [&] {
|
|
|
|
pipeline.reload = true;
|
|
|
|
};
|
2012-03-27 11:02:57 +00:00
|
|
|
|
|
|
|
trace = false;
|
|
|
|
instructions = 0;
|
2012-03-19 11:19:53 +00:00
|
|
|
}
|
2012-03-23 10:43:39 +00:00
|
|
|
|
2015-06-24 13:21:24 +00:00
|
|
|
auto ARM::exec() -> void {
|
2012-03-29 11:58:10 +00:00
|
|
|
cpsr().t ? thumb_step() : arm_step();
|
|
|
|
}
|
|
|
|
|
2015-06-24 13:21:24 +00:00
|
|
|
auto ARM::idle() -> void {
|
2015-07-01 10:58:42 +00:00
|
|
|
pipeline.nonsequential = true;
|
|
|
|
return bus_idle();
|
2012-04-15 06:49:56 +00:00
|
|
|
}
|
|
|
|
|
2015-07-01 10:58:42 +00:00
|
|
|
auto ARM::read(unsigned mode, uint32 addr) -> uint32 {
|
|
|
|
return bus_read(mode, addr);
|
2012-04-15 06:49:56 +00:00
|
|
|
}
|
|
|
|
|
2015-07-01 10:58:42 +00:00
|
|
|
auto ARM::load(unsigned mode, uint32 addr) -> uint32 {
|
|
|
|
pipeline.nonsequential = true;
|
|
|
|
uint32 word = bus_read(Load | mode, addr);
|
2012-04-15 06:49:56 +00:00
|
|
|
|
Update to v095r03 release and icarus 20151107.
byuu says:
Note: you will need the new icarus (and please use the "no manifest"
system) to run GBA games with this WIP.
Changelog:
- fixed caching of r(d) to pass armwrestler tests [Jonas Quinn]
- DMA to/from GBA BIOS should fail [Cydrak]
- fixed sign-extend and rotate on ldrs instructions [Cydrak]
- fixed 8-bit SRAM reading/writing [byuu]
- refactored GBA/cartridge
- cartridge/rom,ram.type is now cartridge/mrom,sram,eeprom,flash
- things won't crash horribly if you specify a RAM size larger than
the largest legal size in the manifest
- specialized MROM / SRAM classes replace all the shared read/write
functions that didn't work right anyway
- there's a new ruby/video.glx2 driver, which is not enabled by default
- use this if you are running Linux/BSD, but don't have OpenGL 3.2 yet
- I'm not going to support OpenGL2 on Windows/OS X, because these OSes
don't ship ancient video card drivers
- probably more. What am I, clairvoyant? :P
For endrift's tests, this gets us to 1348/1552 memory and 1016/1260
timing. Overall, this puts us back in second place. Only no$ is ahead
on memory, but bgba is even more ahead on timing.
2015-11-08 09:09:18 +00:00
|
|
|
if(mode & Half) {
|
|
|
|
addr &= 1;
|
Update to v097r14 release.
byuu says:
This is a few days old, but oh well.
This WIP changes nall,hiro,ruby,icarus back to (u)int(8,16,32,64)_t.
I'm slowly pushing for (u)int(8,16,32,64) to use my custom
Integer<Size>/Natural<Size> classes instead. But it's going to be one
hell of a struggle to get that into higan.
2016-02-16 09:11:58 +00:00
|
|
|
word = mode & Signed ? (int16_t)word : (uint16_t)word;
|
Update to v095r03 release and icarus 20151107.
byuu says:
Note: you will need the new icarus (and please use the "no manifest"
system) to run GBA games with this WIP.
Changelog:
- fixed caching of r(d) to pass armwrestler tests [Jonas Quinn]
- DMA to/from GBA BIOS should fail [Cydrak]
- fixed sign-extend and rotate on ldrs instructions [Cydrak]
- fixed 8-bit SRAM reading/writing [byuu]
- refactored GBA/cartridge
- cartridge/rom,ram.type is now cartridge/mrom,sram,eeprom,flash
- things won't crash horribly if you specify a RAM size larger than
the largest legal size in the manifest
- specialized MROM / SRAM classes replace all the shared read/write
functions that didn't work right anyway
- there's a new ruby/video.glx2 driver, which is not enabled by default
- use this if you are running Linux/BSD, but don't have OpenGL 3.2 yet
- I'm not going to support OpenGL2 on Windows/OS X, because these OSes
don't ship ancient video card drivers
- probably more. What am I, clairvoyant? :P
For endrift's tests, this gets us to 1348/1552 memory and 1016/1260
timing. Overall, this puts us back in second place. Only no$ is ahead
on memory, but bgba is even more ahead on timing.
2015-11-08 09:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(mode & Byte) {
|
|
|
|
addr &= 0;
|
Update to v097r14 release.
byuu says:
This is a few days old, but oh well.
This WIP changes nall,hiro,ruby,icarus back to (u)int(8,16,32,64)_t.
I'm slowly pushing for (u)int(8,16,32,64) to use my custom
Integer<Size>/Natural<Size> classes instead. But it's going to be one
hell of a struggle to get that into higan.
2016-02-16 09:11:58 +00:00
|
|
|
word = mode & Signed ? (int8_t)word : (uint8_t)word;
|
Update to v095r03 release and icarus 20151107.
byuu says:
Note: you will need the new icarus (and please use the "no manifest"
system) to run GBA games with this WIP.
Changelog:
- fixed caching of r(d) to pass armwrestler tests [Jonas Quinn]
- DMA to/from GBA BIOS should fail [Cydrak]
- fixed sign-extend and rotate on ldrs instructions [Cydrak]
- fixed 8-bit SRAM reading/writing [byuu]
- refactored GBA/cartridge
- cartridge/rom,ram.type is now cartridge/mrom,sram,eeprom,flash
- things won't crash horribly if you specify a RAM size larger than
the largest legal size in the manifest
- specialized MROM / SRAM classes replace all the shared read/write
functions that didn't work right anyway
- there's a new ruby/video.glx2 driver, which is not enabled by default
- use this if you are running Linux/BSD, but don't have OpenGL 3.2 yet
- I'm not going to support OpenGL2 on Windows/OS X, because these OSes
don't ship ancient video card drivers
- probably more. What am I, clairvoyant? :P
For endrift's tests, this gets us to 1348/1552 memory and 1016/1260
timing. Overall, this puts us back in second place. Only no$ is ahead
on memory, but bgba is even more ahead on timing.
2015-11-08 09:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(mode & Signed) {
|
|
|
|
word = asr(word, 8 * (addr & 3));
|
|
|
|
} else {
|
|
|
|
word = ror(word, 8 * (addr & 3));
|
|
|
|
}
|
2012-04-15 06:49:56 +00:00
|
|
|
|
|
|
|
idle();
|
2012-03-31 08:14:31 +00:00
|
|
|
return word;
|
|
|
|
}
|
|
|
|
|
2015-07-01 10:58:42 +00:00
|
|
|
auto ARM::write(unsigned mode, uint32 addr, uint32 word) -> void {
|
|
|
|
pipeline.nonsequential = true;
|
|
|
|
return bus_write(mode, addr, word);
|
2012-04-15 06:49:56 +00:00
|
|
|
}
|
|
|
|
|
2015-07-01 10:58:42 +00:00
|
|
|
auto ARM::store(unsigned mode, uint32 addr, uint32 word) -> void {
|
|
|
|
pipeline.nonsequential = true;
|
2012-04-15 06:49:56 +00:00
|
|
|
|
2015-07-01 10:58:42 +00:00
|
|
|
if(mode & Half) { word &= 0xffff; word |= word << 16; }
|
|
|
|
if(mode & Byte) { word &= 0xff; word |= word << 8; word |= word << 16; }
|
|
|
|
|
|
|
|
return bus_write(Store | mode, addr, word);
|
2012-03-31 08:14:31 +00:00
|
|
|
}
|
|
|
|
|
2015-06-24 13:21:24 +00:00
|
|
|
auto ARM::vector(uint32 addr, Processor::Mode mode) -> void {
|
Update to v087r08 release.
byuu says:
Added some more ARM opcodes, hooked up MMIO. Bind it with mmio[(addr
000-3ff)] = this; inside CPU/PPU/APU, goes to read(), write().
Also moved the Hitachi HG51B core to processor/, and split it apart from
the snes/chip/hitachidsp implementation.
This one actually worked really well. Very clean split between MMIO/DMA
and the processor core. I may move a more generic DMA function inside
the core, not sure yet.
I still believe the HG51B169 to be a variant of the HG51BS family, but
given they're meant to be incredibly flexible microcontrollers, it's
possible that each variant gets its own instruction set.
So, who knows. We'll worry about it if we ever find another HG51B DSP,
I guess.
GBA BIOS is constantly reading from 04000300, but it never writes. If
I return prng()&1, I can get it to proceed until it hits a bad opcode
(stc opcode, which the GBA lacks a coprocessor so ... bad codepath.)
Without it, it just reads that register forever and keeps resetting the
system, or something ...
I guess we're going to have to try and get ARMwrestler working, because
the BIOS seems to need too much emulation code to do anything at all.
2012-03-24 07:52:36 +00:00
|
|
|
auto psr = cpsr();
|
|
|
|
processor.setMode(mode);
|
|
|
|
spsr() = psr;
|
|
|
|
cpsr().i = 1;
|
2012-04-15 06:49:56 +00:00
|
|
|
cpsr().f |= mode == Processor::Mode::FIQ;
|
Update to v087r08 release.
byuu says:
Added some more ARM opcodes, hooked up MMIO. Bind it with mmio[(addr
000-3ff)] = this; inside CPU/PPU/APU, goes to read(), write().
Also moved the Hitachi HG51B core to processor/, and split it apart from
the snes/chip/hitachidsp implementation.
This one actually worked really well. Very clean split between MMIO/DMA
and the processor core. I may move a more generic DMA function inside
the core, not sure yet.
I still believe the HG51B169 to be a variant of the HG51BS family, but
given they're meant to be incredibly flexible microcontrollers, it's
possible that each variant gets its own instruction set.
So, who knows. We'll worry about it if we ever find another HG51B DSP,
I guess.
GBA BIOS is constantly reading from 04000300, but it never writes. If
I return prng()&1, I can get it to proceed until it hits a bad opcode
(stc opcode, which the GBA lacks a coprocessor so ... bad codepath.)
Without it, it just reads that register forever and keeps resetting the
system, or something ...
I guess we're going to have to try and get ARMwrestler working, because
the BIOS seems to need too much emulation code to do anything at all.
2012-03-24 07:52:36 +00:00
|
|
|
cpsr().t = 0;
|
|
|
|
r(14) = pipeline.decode.address;
|
|
|
|
r(15) = addr;
|
|
|
|
}
|
|
|
|
|
2012-03-23 10:43:39 +00:00
|
|
|
}
|