all repos — mgba @ b711432a5e4bedb62761e9a98452e9bccab400d7

mGBA Game Boy Advance Emulator

src/gb/io.c (view raw)

 1/* Copyright (c) 2013-2016 Jeffrey Pfau
 2 *
 3 * This Source Code Form is subject to the terms of the Mozilla Public
 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 6#include "io.h"
 7
 8#include "gb/gb.h"
 9
10void GBIOInit(struct GB* gb) {
11	memset(gb->memory.io, 0, sizeof(gb->memory.io));
12}
13
14void GBIOWrite(struct GB* gb, unsigned address, uint8_t value) {
15	switch (address) {
16	case REG_IF:
17		gb->memory.io[REG_IF] = value;
18		GBUpdateIRQs(gb);
19		return;
20	case REG_LCDC:
21		// TODO: handle GBC differences
22		GBVideoWriteLCDC(&gb->video, value);
23		break;
24	case REG_IE:
25		gb->memory.ie = value;
26		GBUpdateIRQs(gb);
27		return;
28	default:
29		// TODO: Log
30		if (address >= GB_SIZE_IO) {
31			return;
32		}
33		break;
34	}
35	gb->memory.io[address] = value;
36}
37
38uint8_t GBIORead(struct GB* gb, unsigned address) {
39	switch (address) {
40	case REG_IF:
41		break;
42	case REG_IE:
43		return gb->memory.ie;
44	default:
45		// TODO: Log
46		if (address >= GB_SIZE_IO) {
47			return 0;
48		}
49		break;
50	}
51	return gb->memory.io[address];
52}