mirror of https://github.com/mgba-emu/mgba.git
Simple error checking
This commit is contained in:
parent
9efc945f1b
commit
befba57fe6
12
src/gba.c
12
src/gba.c
|
@ -2,8 +2,14 @@
|
||||||
|
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
|
||||||
|
static const char* GBA_CANNOT_MMAP = "Could not map memory";
|
||||||
|
|
||||||
void GBAInit(struct GBA* gba) {
|
void GBAInit(struct GBA* gba) {
|
||||||
|
gba->errno = GBA_NO_ERROR;
|
||||||
|
gba->errstr = 0;
|
||||||
|
|
||||||
ARMInit(&gba->cpu);
|
ARMInit(&gba->cpu);
|
||||||
|
|
||||||
gba->memory.p = gba;
|
gba->memory.p = gba;
|
||||||
GBAMemoryInit(&gba->memory);
|
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->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;
|
||||||
|
|
||||||
|
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) {
|
void GBAMemoryDeinit(struct GBAMemory* memory) {
|
||||||
|
|
|
@ -3,6 +3,11 @@
|
||||||
|
|
||||||
#include "arm.h"
|
#include "arm.h"
|
||||||
|
|
||||||
|
enum GBAError {
|
||||||
|
GBA_NO_ERROR = 0,
|
||||||
|
GBA_OUT_OF_MEMORY = -1
|
||||||
|
};
|
||||||
|
|
||||||
enum GBAMemoryRegion {
|
enum GBAMemoryRegion {
|
||||||
REGION_BIOS = 0x0,
|
REGION_BIOS = 0x0,
|
||||||
REGION_WORKING_RAM = 0x2,
|
REGION_WORKING_RAM = 0x2,
|
||||||
|
@ -59,6 +64,9 @@ struct GBA {
|
||||||
struct ARMCore cpu;
|
struct ARMCore cpu;
|
||||||
struct GBABoard board;
|
struct GBABoard board;
|
||||||
struct GBAMemory memory;
|
struct GBAMemory memory;
|
||||||
|
|
||||||
|
enum GBAError errno;
|
||||||
|
const char* errstr;
|
||||||
};
|
};
|
||||||
|
|
||||||
void GBAInit(struct GBA* gba);
|
void GBAInit(struct GBA* gba);
|
||||||
|
|
Loading…
Reference in New Issue