summaryrefslogtreecommitdiff
path: root/psg.c
diff options
context:
space:
mode:
Diffstat (limited to 'psg.c')
-rw-r--r--psg.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/psg.c b/psg.c
index ccf0779..363114c 100644
--- a/psg.c
+++ b/psg.c
@@ -32,6 +32,9 @@ void psg_adjust_master_clock(psg_context * context, uint32_t master_clock)
void psg_write(psg_context * context, uint8_t value)
{
+ if (context->vgm) {
+ vgm_sn76489_write(context->vgm, context->cycles, value);
+ }
if (value & 0x80) {
context->latch = value & 0x70;
uint8_t channel = value >> 5 & 0x3;
@@ -122,6 +125,30 @@ void psg_run(psg_context * context, uint32_t cycles)
}
}
+void psg_vgm_log(psg_context *context, uint32_t master_clock, vgm_writer *vgm)
+{
+ vgm_sn76489_init(vgm, master_clock / context->clock_inc, 9, 16, 0);
+ context->vgm = vgm;
+ for (int chan = 0; chan < 4; chan++)
+ {
+ uint8_t base = chan << 5 | 0x80;
+ vgm_sn76489_write(context->vgm, context->cycles, context->volume[chan] | base | 0x10);
+ if (chan == 3) {
+ if (context->noise_use_tone) {
+ vgm_sn76489_write(context->vgm, context->cycles, 3 | base);
+ } else {
+ //0x10 = 0
+ //0x20 = 1
+ //0x40 = 2
+ vgm_sn76489_write(context->vgm, context->cycles, context->counter_load[chan] >> 5 | base);
+ }
+ } else {
+ vgm_sn76489_write(context->vgm, context->cycles, (context->counter_load[chan] & 0xF) | base);
+ vgm_sn76489_write(context->vgm, context->cycles, context->counter_load[chan] >> 4 & 0x3F);
+ }
+ }
+}
+
void psg_serialize(psg_context *context, serialize_buffer *buf)
{
save_int16(buf, context->lsfr);