2012-03-19 11:19:53 +00:00
|
|
|
struct GPR {
|
|
|
|
inline operator uint32() const { return data; }
|
2015-06-24 13:21:24 +00:00
|
|
|
inline auto operator=(uint32 n) { data = n; if(modify) modify(); return *this; }
|
|
|
|
inline auto operator=(const GPR& source) { return operator=(source.data); }
|
|
|
|
|
|
|
|
inline auto operator &=(uint32 n) { return operator=(data & n); }
|
|
|
|
inline auto operator |=(uint32 n) { return operator=(data | n); }
|
|
|
|
inline auto operator ^=(uint32 n) { return operator=(data ^ n); }
|
|
|
|
inline auto operator +=(uint32 n) { return operator=(data + n); }
|
|
|
|
inline auto operator -=(uint32 n) { return operator=(data - n); }
|
|
|
|
inline auto operator *=(uint32 n) { return operator=(data * n); }
|
|
|
|
inline auto operator /=(uint32 n) { return operator=(data / n); }
|
|
|
|
inline auto operator %=(uint32 n) { return operator=(data % n); }
|
|
|
|
inline auto operator<<=(uint32 n) { return operator=(data << n); }
|
|
|
|
inline auto operator>>=(uint32 n) { return operator=(data >> n); }
|
|
|
|
|
2015-06-27 02:38:08 +00:00
|
|
|
uint32 data = 0;
|
|
|
|
function<auto () -> void> modify;
|
2012-03-19 11:19:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PSR {
|
|
|
|
inline operator uint32() const {
|
|
|
|
return (n << 31) + (z << 30) + (c << 29) + (v << 28)
|
2012-04-17 12:16:54 +00:00
|
|
|
+ (i << 7) + (f << 6) + (t << 5) + (m << 0);
|
2012-03-19 11:19:53 +00:00
|
|
|
}
|
|
|
|
|
2015-06-24 13:21:24 +00:00
|
|
|
inline auto operator=(uint32 d) {
|
2012-03-19 11:19:53 +00:00
|
|
|
n = d & (1 << 31);
|
|
|
|
z = d & (1 << 30);
|
|
|
|
c = d & (1 << 29);
|
|
|
|
v = d & (1 << 28);
|
|
|
|
i = d & (1 << 7);
|
|
|
|
f = d & (1 << 6);
|
|
|
|
t = d & (1 << 5);
|
|
|
|
m = d & 31;
|
|
|
|
return *this;
|
|
|
|
}
|
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
|
|
|
|
2015-06-24 13:21:24 +00:00
|
|
|
auto serialize(serializer&) -> void;
|
|
|
|
|
2015-06-27 02:38:08 +00:00
|
|
|
bool n = false; //negative
|
|
|
|
bool z = false; //zero
|
|
|
|
bool c = false; //carry
|
|
|
|
bool v = false; //overflow
|
|
|
|
bool i = false; //irq
|
|
|
|
bool f = false; //fiq
|
|
|
|
bool t = false; //thumb
|
|
|
|
unsigned m = 0; //mode
|
2012-03-19 11:19:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Pipeline {
|
2015-06-27 02:38:08 +00:00
|
|
|
bool reload = false;
|
2015-07-01 10:58:42 +00:00
|
|
|
bool nonsequential = false;
|
2012-03-21 11:08:16 +00:00
|
|
|
|
2012-03-19 11:19:53 +00:00
|
|
|
struct Instruction {
|
2015-06-27 02:38:08 +00:00
|
|
|
uint32 address = 0;
|
|
|
|
uint32 instruction = 0;
|
2012-03-19 11:19:53 +00:00
|
|
|
};
|
2012-03-21 11:08:16 +00:00
|
|
|
|
2012-03-19 11:19:53 +00:00
|
|
|
Instruction execute;
|
|
|
|
Instruction decode;
|
|
|
|
Instruction fetch;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Processor {
|
|
|
|
enum class Mode : unsigned {
|
|
|
|
USR = 0x10, //user
|
|
|
|
FIQ = 0x11, //fast interrupt request
|
|
|
|
IRQ = 0x12, //interrupt request
|
|
|
|
SVC = 0x13, //supervisor (software interrupt)
|
|
|
|
ABT = 0x17, //abort
|
|
|
|
UND = 0x1b, //undefined
|
|
|
|
SYS = 0x1f, //system
|
|
|
|
};
|
|
|
|
|
|
|
|
GPR r0, r1, r2, r3, r4, r5, r6, r7;
|
|
|
|
|
|
|
|
struct USR {
|
|
|
|
GPR r8, r9, r10, r11, r12, sp, lr;
|
|
|
|
} usr;
|
|
|
|
|
|
|
|
struct FIQ {
|
|
|
|
GPR r8, r9, r10, r11, r12, sp, lr;
|
|
|
|
PSR spsr;
|
|
|
|
} fiq;
|
|
|
|
|
|
|
|
struct IRQ {
|
|
|
|
GPR sp, lr;
|
|
|
|
PSR spsr;
|
|
|
|
} irq;
|
|
|
|
|
|
|
|
struct SVC {
|
|
|
|
GPR sp, lr;
|
|
|
|
PSR spsr;
|
|
|
|
} svc;
|
|
|
|
|
|
|
|
struct ABT {
|
|
|
|
GPR sp, lr;
|
|
|
|
PSR spsr;
|
|
|
|
} abt;
|
|
|
|
|
|
|
|
struct UND {
|
|
|
|
GPR sp, lr;
|
|
|
|
PSR spsr;
|
|
|
|
} und;
|
|
|
|
|
|
|
|
GPR pc;
|
|
|
|
PSR cpsr;
|
2015-06-27 02:38:08 +00:00
|
|
|
bool carryout = false;
|
|
|
|
bool irqline = false;
|
2012-03-19 11:19:53 +00:00
|
|
|
|
2015-06-27 02:38:08 +00:00
|
|
|
GPR* r[16] = {nullptr};
|
|
|
|
PSR* spsr = nullptr;
|
2012-03-19 11:19:53 +00:00
|
|
|
|
2015-06-24 13:21:24 +00:00
|
|
|
auto power() -> void;
|
|
|
|
auto setMode(Mode) -> void;
|
2012-03-19 11:19:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Processor processor;
|
|
|
|
Pipeline pipeline;
|
2015-06-27 02:38:08 +00:00
|
|
|
bool crash = false;
|
2015-06-24 13:21:24 +00:00
|
|
|
|
|
|
|
alwaysinline auto r(unsigned n) -> GPR& { return *processor.r[n]; }
|
|
|
|
alwaysinline auto cpsr() -> PSR& { return processor.cpsr; }
|
|
|
|
alwaysinline auto spsr() -> PSR& { return *processor.spsr; }
|
|
|
|
alwaysinline auto carryout() -> bool& { return processor.carryout; }
|
|
|
|
alwaysinline auto instruction() -> uint32 { return pipeline.execute.instruction; }
|
|
|
|
alwaysinline auto mode() -> Processor::Mode { return (Processor::Mode)processor.cpsr.m; }
|
2015-06-27 02:38:08 +00:00
|
|
|
alwaysinline auto privilegedMode() const -> bool { return (Processor::Mode)processor.cpsr.m != Processor::Mode::USR; }
|
|
|
|
alwaysinline auto exceptionMode() const -> bool { return privilegedMode() && (Processor::Mode)processor.cpsr.m != Processor::Mode::SYS; }
|