all repos — mgba @ befba57fe6a18fba4272ae5832a9cd6f3a5d70aa

mGBA Game Boy Advance Emulator

Simple error checking
Jeffrey Pfau jeffrey@endrift.com
Sat, 06 Apr 2013 04:34:19 -0700
commit

befba57fe6a18fba4272ae5832a9cd6f3a5d70aa

parent

9efc945f1b9172d6c0af6ac038ddf5400f63c0d2

2 files changed, 20 insertions(+), 0 deletions(-)

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

@@ -2,8 +2,14 @@ #include "gba.h"

#include <sys/mman.h> +static const char* GBA_CANNOT_MMAP = "Could not map memory"; + void GBAInit(struct GBA* gba) { + gba->errno = GBA_NO_ERROR; + gba->errstr = 0; + ARMInit(&gba->cpu); + gba->memory.p = gba; GBAMemoryInit(&gba->memory); }

@@ -26,6 +32,12 @@ memory->bios = 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->rom = 0; + + if (!memory->wram || !memory->iwram) { + GBAMemoryDeinit(memory); + memory->p->errno = GBA_OUT_OF_MEMORY; + memory->p->errstr = GBA_CANNOT_MMAP; + } } void GBAMemoryDeinit(struct GBAMemory* memory) {
M src/gba.hsrc/gba.h

@@ -3,6 +3,11 @@ #define GBA_MEMORY_H

#include "arm.h" +enum GBAError { + GBA_NO_ERROR = 0, + GBA_OUT_OF_MEMORY = -1 +}; + enum GBAMemoryRegion { REGION_BIOS = 0x0, REGION_WORKING_RAM = 0x2,

@@ -59,6 +64,9 @@ struct GBA {

struct ARMCore cpu; struct GBABoard board; struct GBAMemory memory; + + enum GBAError errno; + const char* errstr; }; void GBAInit(struct GBA* gba);