diff --git a/src/gamegear.c b/src/gamegear.c index 9f9680f..73f2084 100644 --- a/src/gamegear.c +++ b/src/gamegear.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2014-2015 Ben Kurtovic +/* Copyright (C) 2014-2016 Ben Kurtovic Released under the terms of the MIT License. See LICENSE for details. */ #include @@ -24,7 +24,8 @@ GameGear* gamegear_create() GameGear *gg = cr_malloc(sizeof(GameGear)); mmu_init(&gg->mmu); 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); gg->powered = false; @@ -42,6 +43,7 @@ void gamegear_destroy(GameGear *gg) { mmu_free(&gg->mmu); vdp_free(&gg->vdp); + psg_free(&gg->psg); free(gg); } diff --git a/src/gamegear.h b/src/gamegear.h index 948beb6..f16324f 100644 --- a/src/gamegear.h +++ b/src/gamegear.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2014-2015 Ben Kurtovic +/* Copyright (C) 2014-2016 Ben Kurtovic Released under the terms of the MIT License. See LICENSE for details. */ #pragma once @@ -8,6 +8,7 @@ #include "io.h" #include "mmu.h" +#include "psg.h" #include "rom.h" #include "z80.h" @@ -23,6 +24,7 @@ typedef struct GameGear { Z80 cpu; MMU mmu; VDP vdp; + PSG psg; IO io; bool powered; GGFrameCallback callback; diff --git a/src/io.c b/src/io.c index 40ee924..4c4cc7a 100644 --- a/src/io.c +++ b/src/io.c @@ -6,9 +6,10 @@ /* Initialize an IO object. */ -void io_init(IO *io, VDP *vdp) +void io_init(IO *io, VDP *vdp, PSG *psg) { 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 goto except; } else if (port <= 0x7F) { - // TODO: Write to the SN76489 PSG - goto except; + psg_write(io->psg, value); } else if (port <= 0xBF && !(port % 2)) { vdp_write_data(io->vdp, value); } else if (port <= 0xBF) { diff --git a/src/io.h b/src/io.h index 8be1cc1..ec4df5f 100644 --- a/src/io.h +++ b/src/io.h @@ -6,19 +6,21 @@ #include #include +#include "psg.h" #include "vdp.h" /* Structs */ typedef struct { VDP *vdp; + PSG *psg; bool except; uint8_t exc_port; } IO; /* Functions */ -void io_init(IO*, VDP*); +void io_init(IO*, VDP*, PSG*); void io_power(IO*); bool io_check_irq(IO*); uint8_t io_port_read(IO*, uint8_t); diff --git a/src/psg.c b/src/psg.c new file mode 100644 index 0000000..786502e --- /dev/null +++ b/src/psg.c @@ -0,0 +1,43 @@ +/* Copyright (C) 2014-2016 Ben Kurtovic + 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) +} diff --git a/src/psg.h b/src/psg.h new file mode 100644 index 0000000..1fe7246 --- /dev/null +++ b/src/psg.h @@ -0,0 +1,21 @@ +/* Copyright (C) 2014-2016 Ben Kurtovic + Released under the terms of the MIT License. See LICENSE for details. */ + +#pragma once + +#include + +/* 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);