Mercurial > repos > blastem
comparison psg.c @ 2053:3414a4423de1 segacd
Merge from default
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 15 Jan 2022 13:15:21 -0800 |
parents | c3c62dbf1ceb |
children | cfd53c94fffb |
comparison
equal
deleted
inserted
replaced
1692:5dacaef602a7 | 2053:3414a4423de1 |
---|---|
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" |
8 #include "event_log.h" | |
9 #include <string.h> | 9 #include <string.h> |
10 #include <stdlib.h> | 10 #include <stdlib.h> |
11 #include <stdio.h> | 11 #include <stdio.h> |
12 #include <math.h> | 12 #include <math.h> |
13 void psg_init(psg_context * context, uint32_t master_clock, uint32_t clock_div) | 13 void psg_init(psg_context * context, uint32_t master_clock, uint32_t clock_div) |
31 render_audio_adjust_clock(context->audio, master_clock, context->clock_inc); | 31 render_audio_adjust_clock(context->audio, master_clock, context->clock_inc); |
32 } | 32 } |
33 | 33 |
34 void psg_write(psg_context * context, uint8_t value) | 34 void psg_write(psg_context * context, uint8_t value) |
35 { | 35 { |
36 if (context->vgm) { | |
37 vgm_sn76489_write(context->vgm, context->cycles, value); | |
38 } | |
39 event_log(EVENT_PSG_REG, context->cycles, sizeof(value), &value); | |
36 if (value & 0x80) { | 40 if (value & 0x80) { |
37 context->latch = value & 0x70; | 41 context->latch = value & 0x70; |
38 uint8_t channel = value >> 5 & 0x3; | 42 uint8_t channel = value >> 5 & 0x3; |
39 if (value & 0x10) { | 43 if (value & 0x10) { |
40 context->volume[channel] = value & 0xF; | 44 context->volume[channel] = value & 0xF; |
121 | 125 |
122 context->cycles += context->clock_inc; | 126 context->cycles += context->clock_inc; |
123 } | 127 } |
124 } | 128 } |
125 | 129 |
130 void psg_vgm_log(psg_context *context, uint32_t master_clock, vgm_writer *vgm) | |
131 { | |
132 vgm_sn76489_init(vgm, 16 * master_clock / context->clock_inc, 9, 16, 0); | |
133 context->vgm = vgm; | |
134 for (int chan = 0; chan < 4; chan++) | |
135 { | |
136 uint8_t base = chan << 5 | 0x80; | |
137 vgm_sn76489_write(context->vgm, context->cycles, context->volume[chan] | base | 0x10); | |
138 if (chan == 3) { | |
139 if (context->noise_use_tone) { | |
140 vgm_sn76489_write(context->vgm, context->cycles, 3 | base); | |
141 } else { | |
142 //0x10 = 0 | |
143 //0x20 = 1 | |
144 //0x40 = 2 | |
145 vgm_sn76489_write(context->vgm, context->cycles, context->counter_load[chan] >> 5 | base); | |
146 } | |
147 } else { | |
148 vgm_sn76489_write(context->vgm, context->cycles, (context->counter_load[chan] & 0xF) | base); | |
149 vgm_sn76489_write(context->vgm, context->cycles, context->counter_load[chan] >> 4 & 0x3F); | |
150 } | |
151 } | |
152 } | |
153 | |
126 void psg_serialize(psg_context *context, serialize_buffer *buf) | 154 void psg_serialize(psg_context *context, serialize_buffer *buf) |
127 { | 155 { |
128 save_int16(buf, context->lsfr); | 156 save_int16(buf, context->lsfr); |
129 save_buffer16(buf, context->counter_load, 4); | 157 save_buffer16(buf, context->counter_load, 4); |
130 save_buffer16(buf, context->counters, 4); | 158 save_buffer16(buf, context->counters, 4); |