Mercurial > repos > blastem
diff psg.c @ 1909:508522f08e4d
Initial stab at VGM logging support
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 27 Mar 2020 00:03:58 -0700 |
parents | 4c322abd9fa5 |
children | f2ed8df7a002 |
line wrap: on
line diff
--- a/psg.c Thu Mar 26 23:53:35 2020 -0700 +++ b/psg.c Fri Mar 27 00:03:58 2020 -0700 @@ -32,6 +32,9 @@ 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_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);