Simple error checking

This commit is contained in:
Jeffrey Pfau 2013-04-06 04:34:19 -07:00
parent 9efc945f1b
commit befba57fe6
2 changed files with 20 additions and 0 deletions

View File

@ -2,8 +2,14 @@
#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 @@ void GBAMemoryInit(struct GBAMemory* memory) {
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) {

View File

@ -3,6 +3,11 @@
#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);