2019-04-19 05:00:24 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2019-04-16 06:25:00 +00:00
|
|
|
#include "cpu.h"
|
|
|
|
#include "rom.h"
|
|
|
|
#include "dmg.h"
|
|
|
|
#include "types.h"
|
2019-04-20 04:07:45 +00:00
|
|
|
#include "bootstrap.h"
|
2019-04-16 06:25:00 +00:00
|
|
|
|
|
|
|
void dmg_new(struct dmg *dmg, struct cpu *cpu, struct rom *rom)
|
|
|
|
{
|
|
|
|
dmg->cpu = cpu;
|
|
|
|
dmg->rom = rom;
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 dmg_read(void *_dmg, u16 address)
|
|
|
|
{
|
|
|
|
struct dmg *dmg = (struct dmg *) _dmg;
|
2019-04-25 05:19:47 +00:00
|
|
|
if (address < 0x100) {
|
|
|
|
return dmg_boot_rom[address];
|
|
|
|
}
|
2019-04-16 06:25:00 +00:00
|
|
|
if (address < 0x4000) {
|
|
|
|
return dmg->rom->data[address];
|
|
|
|
} else if (address < 0x8000) {
|
|
|
|
// TODO switchable rom bank
|
|
|
|
return dmg->rom->data[address];
|
|
|
|
} else if (address < 0xa000) {
|
|
|
|
return dmg->video_ram[address - 0x8000];
|
|
|
|
} else if (address < 0xc000) {
|
|
|
|
// TODO switchable ram bank
|
|
|
|
return 0;
|
|
|
|
} else if (address < 0xe000) {
|
|
|
|
return dmg->main_ram[address - 0xc000];
|
2019-04-25 05:19:47 +00:00
|
|
|
} else if (address >= 0xff80 && address <= 0xfffe) {
|
|
|
|
return dmg->zero_page[address - 0xff80];
|
2019-04-16 06:25:00 +00:00
|
|
|
} else {
|
|
|
|
// not sure about any of this yet
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void dmg_write(void *_dmg, u16 address, u8 data)
|
|
|
|
{
|
|
|
|
struct dmg *dmg = (struct dmg *) _dmg;
|
2019-04-19 05:00:24 +00:00
|
|
|
if (address < 0x4000) {
|
|
|
|
printf("warning: writing 0x%04x in rom\n", address);
|
|
|
|
dmg->rom->data[address] = data;
|
|
|
|
} else if (address < 0x8000) {
|
|
|
|
// TODO switchable rom bank
|
|
|
|
printf("warning: writing 0x%04x in rom\n", address);
|
|
|
|
dmg->rom->data[address] = data;
|
|
|
|
} else if (address < 0xa000) {
|
|
|
|
dmg->video_ram[address - 0x8000] = data;
|
|
|
|
} else if (address < 0xc000) {
|
|
|
|
// TODO switchable ram bank
|
|
|
|
} else if (address < 0xe000) {
|
|
|
|
dmg->main_ram[address - 0xc000] = data;
|
2019-04-25 05:19:47 +00:00
|
|
|
} else if (address >= 0xff80 && address <= 0xfffe) {
|
|
|
|
dmg->zero_page[address - 0xff80] = data;
|
2019-04-19 05:00:24 +00:00
|
|
|
} else {
|
|
|
|
// not sure about any of this yet
|
|
|
|
}
|
2019-04-16 06:25:00 +00:00
|
|
|
}
|