mirror of https://github.com/mgba-emu/mgba.git
Checksum BIOS
This commit is contained in:
parent
94cc48faf1
commit
ce4d0b5203
|
@ -7,6 +7,9 @@
|
|||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
const uint32_t GBA_BIOS_CHECKSUM = 0xBAAE187F;
|
||||
const uint32_t GBA_DS_BIOS_CHECKSUM = 0xBAAE1880;
|
||||
|
||||
static void _unLz77(struct GBAMemory* memory, uint32_t source, uint8_t* dest);
|
||||
static void _unHuffman(struct GBAMemory* memory, uint32_t source, uint32_t* dest);
|
||||
static void _unRl(struct GBAMemory* memory, uint32_t source, uint8_t* dest);
|
||||
|
@ -237,6 +240,8 @@ void GBASwi16(struct ARMBoard* board, int immediate) {
|
|||
case 0xC:
|
||||
_FastCpuSet(gba);
|
||||
break;
|
||||
case 0xD:
|
||||
gba->cpu.gprs[0] = GBAChecksum(gba->memory.bios, SIZE_BIOS);
|
||||
case 0xE:
|
||||
_BgAffineSet(gba);
|
||||
break;
|
||||
|
@ -317,6 +322,15 @@ void GBASwi32(struct ARMBoard* board, int immediate) {
|
|||
GBASwi16(board, immediate >> 16);
|
||||
}
|
||||
|
||||
uint32_t GBAChecksum(uint32_t* memory, size_t size) {
|
||||
size_t i;
|
||||
uint32_t sum = 0;
|
||||
for (i = 0; i < size; i += 4) {
|
||||
sum += memory[i >> 2];
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
static void _unLz77(struct GBAMemory* memory, uint32_t source, uint8_t* dest) {
|
||||
int remaining = (memory->d.load32(&memory->d, source, 0) & 0xFFFFFF00) >> 8;
|
||||
// We assume the signature byte (0x10) is correct
|
||||
|
|
|
@ -3,7 +3,13 @@
|
|||
|
||||
#include "arm.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
void GBASwi16(struct ARMBoard* board, int immediate);
|
||||
void GBASwi32(struct ARMBoard* board, int immediate);
|
||||
|
||||
uint32_t GBAChecksum(uint32_t* memory, size_t size);
|
||||
const uint32_t GBA_BIOS_CHECKSUM;
|
||||
const uint32_t GBA_DS_BIOS_CHECKSUM;
|
||||
|
||||
#endif
|
||||
|
|
|
@ -360,6 +360,15 @@ void GBALoadROM(struct GBA* gba, int fd, const char* fname) {
|
|||
void GBALoadBIOS(struct GBA* gba, int fd) {
|
||||
gba->memory.bios = fileMemoryMap(fd, SIZE_BIOS, MEMORY_READ);
|
||||
gba->memory.fullBios = 1;
|
||||
uint32_t checksum = GBAChecksum(gba->memory.bios, SIZE_BIOS);
|
||||
GBALog(gba, GBA_LOG_DEBUG, "BIOS Checksum: 0x%X", checksum);
|
||||
if (checksum == GBA_BIOS_CHECKSUM) {
|
||||
GBALog(gba, GBA_LOG_INFO, "Official GBA BIOS detected");
|
||||
} else if (checksum == GBA_DS_BIOS_CHECKSUM) {
|
||||
GBALog(gba, GBA_LOG_INFO, "Official GBA (DS) BIOS detected");
|
||||
} else {
|
||||
GBALog(gba, GBA_LOG_WARN, "BIOS checksum incorrect");
|
||||
}
|
||||
if ((gba->cpu.gprs[ARM_PC] >> BASE_OFFSET) == BASE_BIOS) {
|
||||
gba->memory.d.setActiveRegion(&gba->memory.d, gba->cpu.gprs[ARM_PC]);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue