Mercurial > repos > blastem
comparison 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 |
comparison
equal
deleted
inserted
replaced
1908:c3d49c338224 | 1909:508522f08e4d |
---|---|
30 render_audio_adjust_clock(context->audio, master_clock, context->clock_inc); | 30 render_audio_adjust_clock(context->audio, master_clock, context->clock_inc); |
31 } | 31 } |
32 | 32 |
33 void psg_write(psg_context * context, uint8_t value) | 33 void psg_write(psg_context * context, uint8_t value) |
34 { | 34 { |
35 if (context->vgm) { | |
36 vgm_sn76489_write(context->vgm, context->cycles, value); | |
37 } | |
35 if (value & 0x80) { | 38 if (value & 0x80) { |
36 context->latch = value & 0x70; | 39 context->latch = value & 0x70; |
37 uint8_t channel = value >> 5 & 0x3; | 40 uint8_t channel = value >> 5 & 0x3; |
38 if (value & 0x10) { | 41 if (value & 0x10) { |
39 context->volume[channel] = value & 0xF; | 42 context->volume[channel] = value & 0xF; |
120 | 123 |
121 context->cycles += context->clock_inc; | 124 context->cycles += context->clock_inc; |
122 } | 125 } |
123 } | 126 } |
124 | 127 |
128 void psg_vgm_log(psg_context *context, uint32_t master_clock, vgm_writer *vgm) | |
129 { | |
130 vgm_sn76489_init(vgm, master_clock / context->clock_inc, 9, 16, 0); | |
131 context->vgm = vgm; | |
132 for (int chan = 0; chan < 4; chan++) | |
133 { | |
134 uint8_t base = chan << 5 | 0x80; | |
135 vgm_sn76489_write(context->vgm, context->cycles, context->volume[chan] | base | 0x10); | |
136 if (chan == 3) { | |
137 if (context->noise_use_tone) { | |
138 vgm_sn76489_write(context->vgm, context->cycles, 3 | base); | |
139 } else { | |
140 //0x10 = 0 | |
141 //0x20 = 1 | |
142 //0x40 = 2 | |
143 vgm_sn76489_write(context->vgm, context->cycles, context->counter_load[chan] >> 5 | base); | |
144 } | |
145 } else { | |
146 vgm_sn76489_write(context->vgm, context->cycles, (context->counter_load[chan] & 0xF) | base); | |
147 vgm_sn76489_write(context->vgm, context->cycles, context->counter_load[chan] >> 4 & 0x3F); | |
148 } | |
149 } | |
150 } | |
151 | |
125 void psg_serialize(psg_context *context, serialize_buffer *buf) | 152 void psg_serialize(psg_context *context, serialize_buffer *buf) |
126 { | 153 { |
127 save_int16(buf, context->lsfr); | 154 save_int16(buf, context->lsfr); |
128 save_buffer16(buf, context->counter_load, 4); | 155 save_buffer16(buf, context->counter_load, 4); |
129 save_buffer16(buf, context->counters, 4); | 156 save_buffer16(buf, context->counters, 4); |