all repos — mgba @ ce4d0b5203f90f9e6dcf3d5212fc2a5559737e79

mGBA Game Boy Advance Emulator

Checksum BIOS
Jeffrey Pfau jeffrey@endrift.com
Sat, 18 Jan 2014 00:17:58 -0800
commit

ce4d0b5203f90f9e6dcf3d5212fc2a5559737e79

parent

94cc48faf11e9065025c9529e19b670bd5dd0c2a

3 files changed, 29 insertions(+), 0 deletions(-)

jump to
M src/gba/gba-bios.csrc/gba/gba-bios.c

@@ -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 @@ break;

case 0xC: _FastCpuSet(gba); break; + case 0xD: + gba->cpu.gprs[0] = GBAChecksum(gba->memory.bios, SIZE_BIOS); case 0xE: _BgAffineSet(gba); break;

@@ -315,6 +320,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) {
M src/gba/gba-bios.hsrc/gba/gba-bios.h

@@ -3,7 +3,13 @@ #define GBA_BIOS_H

#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
M src/gba/gba.csrc/gba/gba.c

@@ -360,6 +360,15 @@

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]); }