diff options
author | Michael Pavone <pavone@retrodev.com> | 2020-03-27 00:03:58 -0700 |
---|---|---|
committer | Michael Pavone <pavone@retrodev.com> | 2020-03-27 00:03:58 -0700 |
commit | 66975faa75958a1a509a04801331a85291827580 (patch) | |
tree | ef9891c95f5d100b464b2497b64e08db6ad8ab31 /psg.c | |
parent | ce15f59d46ea29afc64a8018e7da089c81217dea (diff) |
Initial stab at VGM logging support
Diffstat (limited to 'psg.c')
-rw-r--r-- | psg.c | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -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); |