comparison psg.c @ 1931:374a5ae694e8 mame_interp

Merge from default
author Michael Pavone <pavone@retrodev.com>
date Sat, 18 Apr 2020 11:42:53 -0700
parents f2ed8df7a002
children c3c62dbf1ceb
comparison
equal deleted inserted replaced
1843:13abdc98379e 1931:374a5ae694e8
2 Copyright 2013 Michael Pavone 2 Copyright 2013 Michael Pavone
3 This file is part of BlastEm. 3 This file is part of BlastEm.
4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text. 4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text.
5 */ 5 */
6 #include "psg.h" 6 #include "psg.h"
7 #include "render.h"
8 #include "blastem.h" 7 #include "blastem.h"
9 #include <string.h> 8 #include <string.h>
10 #include <stdlib.h> 9 #include <stdlib.h>
11 #include <stdio.h> 10 #include <stdio.h>
12 #include <math.h> 11 #include <math.h>
31 render_audio_adjust_clock(context->audio, master_clock, context->clock_inc); 30 render_audio_adjust_clock(context->audio, master_clock, context->clock_inc);
32 } 31 }
33 32
34 void psg_write(psg_context * context, uint8_t value) 33 void psg_write(psg_context * context, uint8_t value)
35 { 34 {
35 if (context->vgm) {
36 vgm_sn76489_write(context->vgm, context->cycles, value);
37 }
36 if (value & 0x80) { 38 if (value & 0x80) {
37 context->latch = value & 0x70; 39 context->latch = value & 0x70;
38 uint8_t channel = value >> 5 & 0x3; 40 uint8_t channel = value >> 5 & 0x3;
39 if (value & 0x10) { 41 if (value & 0x10) {
40 context->volume[channel] = value & 0xF; 42 context->volume[channel] = value & 0xF;
121 123
122 context->cycles += context->clock_inc; 124 context->cycles += context->clock_inc;
123 } 125 }
124 } 126 }
125 127
128 void psg_vgm_log(psg_context *context, uint32_t master_clock, vgm_writer *vgm)
129 {
130 vgm_sn76489_init(vgm, 16 * 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
126 void psg_serialize(psg_context *context, serialize_buffer *buf) 152 void psg_serialize(psg_context *context, serialize_buffer *buf)
127 { 153 {
128 save_int16(buf, context->lsfr); 154 save_int16(buf, context->lsfr);
129 save_buffer16(buf, context->counter_load, 4); 155 save_buffer16(buf, context->counter_load, 4);
130 save_buffer16(buf, context->counters, 4); 156 save_buffer16(buf, context->counters, 4);