@@ -1,4 +1,4 @@ | |||||
/* Copyright (C) 2014-2015 Ben Kurtovic <ben.kurtovic@gmail.com> | |||||
/* Copyright (C) 2014-2016 Ben Kurtovic <ben.kurtovic@gmail.com> | |||||
Released under the terms of the MIT License. See LICENSE for details. */ | Released under the terms of the MIT License. See LICENSE for details. */ | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
@@ -24,7 +24,8 @@ GameGear* gamegear_create() | |||||
GameGear *gg = cr_malloc(sizeof(GameGear)); | GameGear *gg = cr_malloc(sizeof(GameGear)); | ||||
mmu_init(&gg->mmu); | mmu_init(&gg->mmu); | ||||
vdp_init(&gg->vdp); | vdp_init(&gg->vdp); | ||||
io_init(&gg->io, &gg->vdp); | |||||
psg_init(&gg->psg); | |||||
io_init(&gg->io, &gg->vdp, &gg->psg); | |||||
z80_init(&gg->cpu, &gg->mmu, &gg->io); | z80_init(&gg->cpu, &gg->mmu, &gg->io); | ||||
gg->powered = false; | gg->powered = false; | ||||
@@ -42,6 +43,7 @@ void gamegear_destroy(GameGear *gg) | |||||
{ | { | ||||
mmu_free(&gg->mmu); | mmu_free(&gg->mmu); | ||||
vdp_free(&gg->vdp); | vdp_free(&gg->vdp); | ||||
psg_free(&gg->psg); | |||||
free(gg); | free(gg); | ||||
} | } | ||||
@@ -1,4 +1,4 @@ | |||||
/* Copyright (C) 2014-2015 Ben Kurtovic <ben.kurtovic@gmail.com> | |||||
/* Copyright (C) 2014-2016 Ben Kurtovic <ben.kurtovic@gmail.com> | |||||
Released under the terms of the MIT License. See LICENSE for details. */ | Released under the terms of the MIT License. See LICENSE for details. */ | ||||
#pragma once | #pragma once | ||||
@@ -8,6 +8,7 @@ | |||||
#include "io.h" | #include "io.h" | ||||
#include "mmu.h" | #include "mmu.h" | ||||
#include "psg.h" | |||||
#include "rom.h" | #include "rom.h" | ||||
#include "z80.h" | #include "z80.h" | ||||
@@ -23,6 +24,7 @@ typedef struct GameGear { | |||||
Z80 cpu; | Z80 cpu; | ||||
MMU mmu; | MMU mmu; | ||||
VDP vdp; | VDP vdp; | ||||
PSG psg; | |||||
IO io; | IO io; | ||||
bool powered; | bool powered; | ||||
GGFrameCallback callback; | GGFrameCallback callback; | ||||
@@ -6,9 +6,10 @@ | |||||
/* | /* | ||||
Initialize an IO object. | Initialize an IO object. | ||||
*/ | */ | ||||
void io_init(IO *io, VDP *vdp) | |||||
void io_init(IO *io, VDP *vdp, PSG *psg) | |||||
{ | { | ||||
io->vdp = vdp; | io->vdp = vdp; | ||||
io->psg = psg; | |||||
} | } | ||||
/* | /* | ||||
@@ -72,8 +73,7 @@ void io_port_write(IO *io, uint8_t port, uint8_t value) | |||||
// TODO: Write to I/O control register | // TODO: Write to I/O control register | ||||
goto except; | goto except; | ||||
} else if (port <= 0x7F) { | } else if (port <= 0x7F) { | ||||
// TODO: Write to the SN76489 PSG | |||||
goto except; | |||||
psg_write(io->psg, value); | |||||
} else if (port <= 0xBF && !(port % 2)) { | } else if (port <= 0xBF && !(port % 2)) { | ||||
vdp_write_data(io->vdp, value); | vdp_write_data(io->vdp, value); | ||||
} else if (port <= 0xBF) { | } else if (port <= 0xBF) { | ||||
@@ -6,19 +6,21 @@ | |||||
#include <stdbool.h> | #include <stdbool.h> | ||||
#include <stdint.h> | #include <stdint.h> | ||||
#include "psg.h" | |||||
#include "vdp.h" | #include "vdp.h" | ||||
/* Structs */ | /* Structs */ | ||||
typedef struct { | typedef struct { | ||||
VDP *vdp; | VDP *vdp; | ||||
PSG *psg; | |||||
bool except; | bool except; | ||||
uint8_t exc_port; | uint8_t exc_port; | ||||
} IO; | } IO; | ||||
/* Functions */ | /* Functions */ | ||||
void io_init(IO*, VDP*); | |||||
void io_init(IO*, VDP*, PSG*); | |||||
void io_power(IO*); | void io_power(IO*); | ||||
bool io_check_irq(IO*); | bool io_check_irq(IO*); | ||||
uint8_t io_port_read(IO*, uint8_t); | uint8_t io_port_read(IO*, uint8_t); | ||||
@@ -0,0 +1,43 @@ | |||||
/* Copyright (C) 2014-2016 Ben Kurtovic <ben.kurtovic@gmail.com> | |||||
Released under the terms of the MIT License. See LICENSE for details. */ | |||||
#include "psg.h" | |||||
#include "util.h" | |||||
/* | |||||
Initialize the SN76489 Programmable Sound Generator (PSG). | |||||
*/ | |||||
void psg_init(PSG *psg) | |||||
{ | |||||
// TODO | |||||
(void) psg; | |||||
} | |||||
/* | |||||
Free memory previously allocated by the PSG. | |||||
*/ | |||||
void psg_free(PSG *psg) | |||||
{ | |||||
// TODO | |||||
(void) psg; | |||||
} | |||||
/* | |||||
Power on the PSG, setting up initial state. | |||||
*/ | |||||
void psg_power(PSG *psg) | |||||
{ | |||||
psg->tone1 = psg->tone2 = psg->tone3 = 0x0000; | |||||
psg->vol1 = psg->vol2 = psg->vol3 = 0x0F; | |||||
psg->noise = 0x00; | |||||
} | |||||
/* | |||||
Write a byte of input to the PSG. | |||||
*/ | |||||
void psg_write(PSG *psg, uint8_t byte) | |||||
{ | |||||
// TODO | |||||
(void) psg; | |||||
TRACE("PSG ignoring write: 0x%02X", byte) | |||||
} |
@@ -0,0 +1,21 @@ | |||||
/* Copyright (C) 2014-2016 Ben Kurtovic <ben.kurtovic@gmail.com> | |||||
Released under the terms of the MIT License. See LICENSE for details. */ | |||||
#pragma once | |||||
#include <stdint.h> | |||||
/* Structs */ | |||||
typedef struct { | |||||
uint16_t tone1, tone2, tone3; | |||||
uint8_t vol1, vol2, vol3; | |||||
uint8_t noise; | |||||
} PSG; | |||||
/* Functions */ | |||||
void psg_init(PSG*); | |||||
void psg_free(PSG*); | |||||
void psg_power(PSG*); | |||||
void psg_write(PSG*, uint8_t); |