mirror of https://github.com/mgba-emu/mgba.git
Support loading BIOS
This commit is contained in:
parent
68d85ab9b7
commit
84ad94b85e
|
@ -162,6 +162,10 @@ static void _MidiKey2Freq(struct GBA* gba) {
|
||||||
|
|
||||||
void GBASwi16(struct ARMBoard* board, int immediate) {
|
void GBASwi16(struct ARMBoard* board, int immediate) {
|
||||||
struct GBA* gba = ((struct GBABoard*) board)->p;
|
struct GBA* gba = ((struct GBABoard*) board)->p;
|
||||||
|
if (gba->memory.fullBios) {
|
||||||
|
ARMRaiseSWI(&gba->cpu);
|
||||||
|
return;
|
||||||
|
}
|
||||||
switch (immediate) {
|
switch (immediate) {
|
||||||
case 0x1:
|
case 0x1:
|
||||||
_RegisterRamReset(gba);
|
_RegisterRamReset(gba);
|
||||||
|
|
|
@ -31,6 +31,7 @@ void GBAMemoryInit(struct GBAMemory* memory) {
|
||||||
memory->d.store8 = GBAStore8;
|
memory->d.store8 = GBAStore8;
|
||||||
|
|
||||||
memory->bios = (uint32_t*) hleBios;
|
memory->bios = (uint32_t*) hleBios;
|
||||||
|
memory->fullBios = 0;
|
||||||
memory->wram = mmap(0, SIZE_WORKING_RAM, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
|
memory->wram = mmap(0, SIZE_WORKING_RAM, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
|
||||||
memory->iwram = mmap(0, SIZE_WORKING_IRAM, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
|
memory->iwram = mmap(0, SIZE_WORKING_IRAM, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
|
||||||
memory->rom = 0;
|
memory->rom = 0;
|
||||||
|
@ -125,7 +126,7 @@ int32_t GBALoad32(struct ARMMemory* memory, uint32_t address, int* cycleCounter)
|
||||||
switch (address & ~OFFSET_MASK) {
|
switch (address & ~OFFSET_MASK) {
|
||||||
case BASE_BIOS:
|
case BASE_BIOS:
|
||||||
if (gbaMemory->p->cpu.currentPC >> BASE_OFFSET == REGION_BIOS) {
|
if (gbaMemory->p->cpu.currentPC >> BASE_OFFSET == REGION_BIOS) {
|
||||||
if (address < hleBiosLength) {
|
if (address < SIZE_BIOS) {
|
||||||
value = gbaMemory->bios[address >> 2];
|
value = gbaMemory->bios[address >> 2];
|
||||||
} else {
|
} else {
|
||||||
value = 0;
|
value = 0;
|
||||||
|
@ -198,7 +199,15 @@ int16_t GBALoad16(struct ARMMemory* memory, uint32_t address, int* cycleCounter)
|
||||||
|
|
||||||
switch (address & ~OFFSET_MASK) {
|
switch (address & ~OFFSET_MASK) {
|
||||||
case BASE_BIOS:
|
case BASE_BIOS:
|
||||||
GBALog(gbaMemory->p, GBA_LOG_STUB, "Unimplemented memory Load16: 0x%08X", address);
|
if (gbaMemory->p->cpu.currentPC >> BASE_OFFSET == REGION_BIOS) {
|
||||||
|
if (address < SIZE_BIOS) {
|
||||||
|
value = ((int16_t*) gbaMemory->bios)[address >> 1];
|
||||||
|
} else {
|
||||||
|
value = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
value = gbaMemory->biosPrefetch;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case BASE_WORKING_RAM:
|
case BASE_WORKING_RAM:
|
||||||
value = ((int16_t*) gbaMemory->wram)[(address & (SIZE_WORKING_RAM - 1)) >> 1];
|
value = ((int16_t*) gbaMemory->wram)[(address & (SIZE_WORKING_RAM - 1)) >> 1];
|
||||||
|
@ -265,7 +274,15 @@ int8_t GBALoad8(struct ARMMemory* memory, uint32_t address, int* cycleCounter) {
|
||||||
|
|
||||||
switch (address & ~OFFSET_MASK) {
|
switch (address & ~OFFSET_MASK) {
|
||||||
case BASE_BIOS:
|
case BASE_BIOS:
|
||||||
GBALog(gbaMemory->p, GBA_LOG_STUB, "Unimplemented memory Load8: 0x%08X", address);
|
if (gbaMemory->p->cpu.currentPC >> BASE_OFFSET == REGION_BIOS) {
|
||||||
|
if (address < SIZE_BIOS) {
|
||||||
|
value = ((int8_t*) gbaMemory->bios)[address];
|
||||||
|
} else {
|
||||||
|
value = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
value = gbaMemory->biosPrefetch;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case BASE_WORKING_RAM:
|
case BASE_WORKING_RAM:
|
||||||
value = ((int8_t*) gbaMemory->wram)[address & (SIZE_WORKING_RAM - 1)];
|
value = ((int8_t*) gbaMemory->wram)[address & (SIZE_WORKING_RAM - 1)];
|
||||||
|
|
|
@ -114,6 +114,7 @@ struct GBAMemory {
|
||||||
|
|
||||||
struct GBASavedata savedata;
|
struct GBASavedata savedata;
|
||||||
size_t romSize;
|
size_t romSize;
|
||||||
|
int fullBios;
|
||||||
|
|
||||||
char waitstates32[256];
|
char waitstates32[256];
|
||||||
char waitstates16[256];
|
char waitstates16[256];
|
||||||
|
|
|
@ -271,6 +271,15 @@ void GBALoadROM(struct GBA* gba, int fd, const char* fname) {
|
||||||
// TODO: error check
|
// TODO: error check
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GBALoadBIOS(struct GBA* gba, int fd) {
|
||||||
|
gba->memory.bios = mmap(0, SIZE_BIOS, PROT_READ, MAP_SHARED, fd, 0);
|
||||||
|
gba->memory.fullBios = 1;
|
||||||
|
if ((gba->cpu.gprs[ARM_PC] >> BASE_OFFSET) == BASE_BIOS) {
|
||||||
|
gba->memory.d.setActiveRegion(&gba->memory.d, gba->cpu.gprs[ARM_PC]);
|
||||||
|
}
|
||||||
|
// TODO: error check
|
||||||
|
}
|
||||||
|
|
||||||
void GBATimerUpdateRegister(struct GBA* gba, int timer) {
|
void GBATimerUpdateRegister(struct GBA* gba, int timer) {
|
||||||
struct GBATimer* currentTimer = &gba->timers[timer];
|
struct GBATimer* currentTimer = &gba->timers[timer];
|
||||||
if (currentTimer->enable && !currentTimer->countUp) {
|
if (currentTimer->enable && !currentTimer->countUp) {
|
||||||
|
|
|
@ -116,6 +116,7 @@ int GBAHalt(struct GBA* gba);
|
||||||
void GBAAttachDebugger(struct GBA* gba, struct ARMDebugger* debugger);
|
void GBAAttachDebugger(struct GBA* gba, struct ARMDebugger* debugger);
|
||||||
|
|
||||||
void GBALoadROM(struct GBA* gba, int fd, const char* fname);
|
void GBALoadROM(struct GBA* gba, int fd, const char* fname);
|
||||||
|
void GBALoadBIOS(struct GBA* gba, int fd);
|
||||||
|
|
||||||
__attribute__((format (printf, 3, 4)))
|
__attribute__((format (printf, 3, 4)))
|
||||||
void GBALog(struct GBA* gba, enum GBALogLevel level, const char* format, ...);
|
void GBALog(struct GBA* gba, enum GBALogLevel level, const char* format, ...);
|
||||||
|
|
Loading…
Reference in New Issue