| 1 | /* Mednafen - Multi-system Emulator |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License as published by |
| 5 | * the Free Software Foundation; either version 2 of the License, or |
| 6 | * (at your option) any later version. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this program; if not, write to the Free Software |
| 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 16 | */ |
| 17 | |
| 18 | #include "../mednafen.h"cxx . . $ `<file>/mednafen/mednafen.h`/ |
| 19 | #include "psg.h"cxx . . $ `<file>/mednafen/pce_fast/psg.h`/ |
| 20 | |
| 21 | #include <math.h> |
| 22 | #include <string.h> |
| 23 | |
| 24 | void PCEFast_PSGcxx . . $ PCEFast_PSG#::SetVolumecxx . . $ PCEFast_PSG#SetVolume(ba8836b59fb42830).(double new_volume) |
| 25 | { |
| 26 | OutputVolumecxx . . $ PCEFast_PSG#OutputVolume. = new_volume; |
| 27 | |
| 28 | Synthcxx . . $ PCEFast_PSG#Synth..volumecxx . . $ Blip_Synth#volume(ba8836b59fb42830).(OutputVolumecxx . . $ PCEFast_PSG#OutputVolume. / 6); |
| 29 | } |
| 30 | |
| 31 | void PCEFast_PSGcxx . . $ PCEFast_PSG#::UpdateOutput_Normcxx . . $ PCEFast_PSG#UpdateOutput_Norm(e385037a997bc971).(const int32cxx . . $ int32# timestamp, psg_channelcxx . . $ psg_channel# *ch) |
| 32 | { |
| 33 | int32cxx . . $ int32# samp[2]; |
| 34 | int sv = ch->ddacxx . . $ psg_channel#dda.; |
| 35 | |
| 36 | samp[0] = dbtablecxx . . $ PCEFast_PSG#dbtable.[ch->vlcxx . . $ psg_channel#vl.[0]][sv]; |
| 37 | samp[1] = dbtablecxx . . $ PCEFast_PSG#dbtable.[ch->vlcxx . . $ psg_channel#vl.[1]][sv]; |
| 38 | |
| 39 | Synthcxx . . $ PCEFast_PSG#Synth..offset_inlinecxx . . $ Blip_Synth#offset_inline(90077ce6337795eb).(timestamp, samp[0] - ch->blip_prev_sampcxx . . $ psg_channel#blip_prev_samp.[0], sbufcxx . . $ PCEFast_PSG#sbuf.[0]); |
| 40 | Synthcxx . . $ PCEFast_PSG#Synth..offset_inlinecxx . . $ Blip_Synth#offset_inline(90077ce6337795eb).(timestamp, samp[1] - ch->blip_prev_sampcxx . . $ psg_channel#blip_prev_samp.[1], sbufcxx . . $ PCEFast_PSG#sbuf.[1]); |
| 41 | |
| 42 | ch->blip_prev_sampcxx . . $ psg_channel#blip_prev_samp.[0] = samp[0]; |
| 43 | ch->blip_prev_sampcxx . . $ psg_channel#blip_prev_samp.[1] = samp[1]; |
| 44 | } |
| 45 | |
| 46 | void PCEFast_PSGcxx . . $ PCEFast_PSG#::UpdateOutput_Noisecxx . . $ PCEFast_PSG#UpdateOutput_Noise(e385037a997bc971).(const int32cxx . . $ int32# timestamp, psg_channelcxx . . $ psg_channel# *ch) |
| 47 | { |
| 48 | int32cxx . . $ int32# samp[2]; |
| 49 | int sv = ((ch->lfsrcxx . . $ psg_channel#lfsr. & 1) << 5) - (ch->lfsrcxx . . $ psg_channel#lfsr. & 1); //(ch->lfsr & 0x1) ? 0x1F : 0; |
| 50 | |
| 51 | samp[0] = dbtablecxx . . $ PCEFast_PSG#dbtable.[ch->vlcxx . . $ psg_channel#vl.[0]][sv]; |
| 52 | samp[1] = dbtablecxx . . $ PCEFast_PSG#dbtable.[ch->vlcxx . . $ psg_channel#vl.[1]][sv]; |
| 53 | |
| 54 | Synthcxx . . $ PCEFast_PSG#Synth..offset_inlinecxx . . $ Blip_Synth#offset_inline(90077ce6337795eb).(timestamp, samp[0] - ch->blip_prev_sampcxx . . $ psg_channel#blip_prev_samp.[0], sbufcxx . . $ PCEFast_PSG#sbuf.[0]); |
| 55 | Synthcxx . . $ PCEFast_PSG#Synth..offset_inlinecxx . . $ Blip_Synth#offset_inline(90077ce6337795eb).(timestamp, samp[1] - ch->blip_prev_sampcxx . . $ psg_channel#blip_prev_samp.[1], sbufcxx . . $ PCEFast_PSG#sbuf.[1]); |
| 56 | |
| 57 | ch->blip_prev_sampcxx . . $ psg_channel#blip_prev_samp.[0] = samp[0]; |
| 58 | ch->blip_prev_sampcxx . . $ psg_channel#blip_prev_samp.[1] = samp[1]; |
| 59 | } |
| 60 | |
| 61 | void PCEFast_PSGcxx . . $ PCEFast_PSG#::UpdateOutput_Offcxx . . $ PCEFast_PSG#UpdateOutput_Off(e385037a997bc971).(const int32cxx . . $ int32# timestamp, psg_channelcxx . . $ psg_channel# *ch) |
| 62 | { |
| 63 | int32cxx . . $ int32# samp[2]; |
| 64 | |
| 65 | samp[0] = samp[1] = 0; |
| 66 | |
| 67 | Synthcxx . . $ PCEFast_PSG#Synth..offset_inlinecxx . . $ Blip_Synth#offset_inline(90077ce6337795eb).(timestamp, samp[0] - ch->blip_prev_sampcxx . . $ psg_channel#blip_prev_samp.[0], sbufcxx . . $ PCEFast_PSG#sbuf.[0]); |
| 68 | Synthcxx . . $ PCEFast_PSG#Synth..offset_inlinecxx . . $ Blip_Synth#offset_inline(90077ce6337795eb).(timestamp, samp[1] - ch->blip_prev_sampcxx . . $ psg_channel#blip_prev_samp.[1], sbufcxx . . $ PCEFast_PSG#sbuf.[1]); |
| 69 | |
| 70 | ch->blip_prev_sampcxx . . $ psg_channel#blip_prev_samp.[0] = samp[0]; |
| 71 | ch->blip_prev_sampcxx . . $ psg_channel#blip_prev_samp.[1] = samp[1]; |
| 72 | } |
| 73 | |
| 74 | |
| 75 | void PCEFast_PSGcxx . . $ PCEFast_PSG#::UpdateOutput_Accumcxx . . $ PCEFast_PSG#UpdateOutput_Accum(e385037a997bc971).(const int32cxx . . $ int32# timestamp, psg_channelcxx . . $ psg_channel# *ch) |
| 76 | { |
| 77 | int32cxx . . $ int32# samp[2]; |
| 78 | |
| 79 | samp[0] = ((int32cxx . . $ int32#)dbtable_volonlycxx . . $ PCEFast_PSG#dbtable_volonly.[ch->vlcxx . . $ psg_channel#vl.[0]] * ((int32cxx . . $ int32#)ch->samp_accumcxx . . $ psg_channel#samp_accum. - 496)) >> (8 + 5); |
| 80 | samp[1] = ((int32cxx . . $ int32#)dbtable_volonlycxx . . $ PCEFast_PSG#dbtable_volonly.[ch->vlcxx . . $ psg_channel#vl.[1]] * ((int32cxx . . $ int32#)ch->samp_accumcxx . . $ psg_channel#samp_accum. - 496)) >> (8 + 5); |
| 81 | |
| 82 | Synthcxx . . $ PCEFast_PSG#Synth..offset_inlinecxx . . $ Blip_Synth#offset_inline(90077ce6337795eb).(timestamp, samp[0] - ch->blip_prev_sampcxx . . $ psg_channel#blip_prev_samp.[0], sbufcxx . . $ PCEFast_PSG#sbuf.[0]); |
| 83 | Synthcxx . . $ PCEFast_PSG#Synth..offset_inlinecxx . . $ Blip_Synth#offset_inline(90077ce6337795eb).(timestamp, samp[1] - ch->blip_prev_sampcxx . . $ psg_channel#blip_prev_samp.[1], sbufcxx . . $ PCEFast_PSG#sbuf.[1]); |
| 84 | |
| 85 | ch->blip_prev_sampcxx . . $ psg_channel#blip_prev_samp.[0] = samp[0]; |
| 86 | ch->blip_prev_sampcxx . . $ psg_channel#blip_prev_samp.[1] = samp[1]; |
| 87 | } |
| 88 | |
| 89 | // This function should always be called after RecalcFreqCache() (it's not called from RecalcFreqCache to avoid redundant code) |
| 90 | void PCEFast_PSGcxx . . $ PCEFast_PSG#::RecalcUOFunccxx . . $ PCEFast_PSG#RecalcUOFunc(d4f767463ce0a6b3).(int chnum) |
| 91 | { |
| 92 | psg_channelcxx . . $ psg_channel# *ch = &channelcxx . . $ PCEFast_PSG#channel.[chnum]; |
| 93 | |
| 94 | //printf("UO Update: %d, %02x\n", chnum, ch->control); |
| 95 | |
| 96 | if(!(ch->controlcxx . . $ psg_channel#control. & 0xC0)) |
| 97 | ch->UpdateOutputcxx . . $ psg_channel#UpdateOutput. = &PCEFast_PSGcxx . . $ PCEFast_PSG#::UpdateOutput_Offcxx . . $ PCEFast_PSG#UpdateOutput_Off(e385037a997bc971).; |
| 98 | else if(ch->noisectrlcxx . . $ psg_channel#noisectrl. & ch->controlcxx . . $ psg_channel#control. & 0x80) |
| 99 | ch->UpdateOutputcxx . . $ psg_channel#UpdateOutput. = &PCEFast_PSGcxx . . $ PCEFast_PSG#::UpdateOutput_Noisecxx . . $ PCEFast_PSG#UpdateOutput_Noise(e385037a997bc971).; |
| 100 | // If the control for the channel is in waveform play mode, and the (real) playback frequency is too high, and the channel is either not the LFO modulator channel or |
| 101 | // if the LFO trigger bit(which halts the LFO modulator channel's waveform incrementing when set) is clear |
| 102 | else if((ch->controlcxx . . $ psg_channel#control. & 0xC0) == 0x80 && ch->freq_cachecxx . . $ psg_channel#freq_cache. <= 0xA && (chnum != 1 || !(lfoctrlcxx . . $ PCEFast_PSG#lfoctrl. & 0x80)) ) |
| 103 | ch->UpdateOutputcxx . . $ psg_channel#UpdateOutput. = &PCEFast_PSGcxx . . $ PCEFast_PSG#::UpdateOutput_Accumcxx . . $ PCEFast_PSG#UpdateOutput_Accum(e385037a997bc971).; |
| 104 | else |
| 105 | ch->UpdateOutputcxx . . $ psg_channel#UpdateOutput. = &PCEFast_PSGcxx . . $ PCEFast_PSG#::UpdateOutput_Normcxx . . $ PCEFast_PSG#UpdateOutput_Norm(e385037a997bc971).; |
| 106 | } |
| 107 | |
| 108 | |
| 109 | void PCEFast_PSGcxx . . $ PCEFast_PSG#::RecalcFreqCachecxx . . $ PCEFast_PSG#RecalcFreqCache(d4f767463ce0a6b3).(int chnum) |
| 110 | { |
| 111 | psg_channelcxx . . $ psg_channel# *ch = &channelcxx . . $ PCEFast_PSG#channel.[chnum]; |
| 112 | |
| 113 | if(chnum == 0 && (lfoctrlcxx . . $ PCEFast_PSG#lfoctrl. & 0x03)) |
| 114 | { |
| 115 | const uint32cxx . . $ uint32# shift = (((lfoctrlcxx . . $ PCEFast_PSG#lfoctrl. & 0x3) - 1) << 1); |
| 116 | uint8cxx . . $ uint8# la = channelcxx . . $ PCEFast_PSG#channel.[1].ddacxx . . $ psg_channel#dda.; |
| 117 | int32cxx . . $ int32# tmp_freq = ((int32cxx . . $ int32#)ch->frequencycxx . . $ psg_channel#frequency. + ((la - 0x10) << shift)) & 0xFFF; |
| 118 | |
| 119 | ch->freq_cachecxx . . $ psg_channel#freq_cache. = (tmp_freq ? tmp_freq : 4096) << 1; |
| 120 | } |
| 121 | else |
| 122 | { |
| 123 | ch->freq_cachecxx . . $ psg_channel#freq_cache. = (ch->frequencycxx . . $ psg_channel#frequency. ? ch->frequencycxx . . $ psg_channel#frequency. : 4096) << 1; |
| 124 | |
| 125 | if(chnum == 1 && (lfoctrlcxx . . $ PCEFast_PSG#lfoctrl. & 0x03)) |
| 126 | ch->freq_cachecxx . . $ psg_channel#freq_cache. *= lfofreqcxx . . $ PCEFast_PSG#lfofreq. ? lfofreqcxx . . $ PCEFast_PSG#lfofreq. : 256; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | void PCEFast_PSGcxx . . $ PCEFast_PSG#::RecalcNoiseFreqCachecxx . . $ PCEFast_PSG#RecalcNoiseFreqCache(d4f767463ce0a6b3).(int chnum) |
| 131 | { |
| 132 | psg_channelcxx . . $ psg_channel# *ch = &channelcxx . . $ PCEFast_PSG#channel.[chnum]; |
| 133 | int32cxx . . $ int32# freq = 0x1F - (ch->noisectrlcxx . . $ psg_channel#noisectrl. & 0x1F); |
| 134 | |
| 135 | if(!freq) |
| 136 | freq = 0x20; |
| 137 | else |
| 138 | freq <<= 6; |
| 139 | |
| 140 | freq <<= 1; |
| 141 | |
| 142 | ch->noise_freq_cachecxx . . $ psg_channel#noise_freq_cache. = freq; |
| 143 | } |
| 144 | |
| 145 | PCEFast_PSGcxx . . $ PCEFast_PSG#::PCEFast_PSGcxx . . $ PCEFast_PSG#PCEFast_PSG(ad7d7afb16d524bd).(Blip_Buffercxx . . $ Blip_Buffer# *bb_l, Blip_Buffercxx . . $ Blip_Buffer# *bb_r) |
| 146 | { |
| 147 | //printf("Test: %u, %u\n", sizeof(psg_channel), (uint8*)&channel[0].balance - (uint8*)&channel[0].waveform[0]); |
| 148 | Synthcxx . . $ PCEFast_PSG#Synth..treble_eqcxx . . $ Blip_Synth#treble_eq(a728e5f0d25ddc61).(-cxx . . $ blip_eq_t#blip_eq_t(ba8836b59fb42830).2.0); |
| 149 | |
| 150 | sbufcxx . . $ PCEFast_PSG#sbuf.[0] = bb_l; |
| 151 | sbufcxx . . $ PCEFast_PSG#sbuf.[1] = bb_r; |
| 152 | |
| 153 | lasttscxx . . $ PCEFast_PSG#lastts. = 0; |
| 154 | for(int ch = 0; ch < 6; ch++) |
| 155 | { |
| 156 | channelcxx . . $ PCEFast_PSG#channel.[ch].blip_prev_sampcxx . . $ psg_channel#blip_prev_samp.[0] = 0; |
| 157 | channelcxx . . $ PCEFast_PSG#channel.[ch].blip_prev_sampcxx . . $ psg_channel#blip_prev_samp.[1] = 0; |
| 158 | channelcxx . . $ PCEFast_PSG#channel.[ch].lasttscxx . . $ psg_channel#lastts. = 0; |
| 159 | } |
| 160 | |
| 161 | SetVolumecxx . . $ PCEFast_PSG#SetVolume(ba8836b59fb42830).(1.0); |
| 162 | |
| 163 | for(int vl = 0; vl < 32; vl++) |
| 164 | { |
| 165 | double flub = 1; |
| 166 | |
| 167 | if(vl) |
| 168 | flub /= powf(2, (double)1 / 4 * vl); // ~1.5dB reduction per increment of vl |
| 169 | |
| 170 | if(vl == 0x1F) |
| 171 | flub = 0; |
| 172 | |
| 173 | for(int samp = 0; samp < 32; samp++) |
| 174 | { |
| 175 | int eff_samp = samp * 2 - 0x1F; |
| 176 | |
| 177 | dbtablecxx . . $ PCEFast_PSG#dbtable.[vl][samp] = (int32cxx . . $ int32#)(flub * eff_samp * 128); |
| 178 | dbtable_volonlycxx . . $ PCEFast_PSG#dbtable_volonly.[vl] = (int32cxx . . $ int32#)(flub * 65536); |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | Powercxx . . $ PCEFast_PSG#Power(d4f767463ce0a6b3).(0); |
| 183 | } |
| 184 | |
| 185 | PCEFast_PSGcxx . . $ PCEFast_PSG#::~cxx . . $ PCEFast_PSG#`~PCEFast_PSG`(ced63f7c635d850d).PCEFast_PSGcxx . . $ PCEFast_PSG#() |
| 186 | { |
| 187 | |
| 188 | |
| 189 | } |
| 190 | |
| 191 | int32cxx . . $ int32# PCEFast_PSGcxx . . $ PCEFast_PSG#::GetVLcxx . . $ PCEFast_PSG#GetVL(9b79fb6aee4c0440).(const int chnum, const int lr) |
| 192 | { |
| 193 | // Note: Changing the 0x1F(not that there should be) would require changing the channel pseudo-off volume check logic later on. |
| 194 | static const uint8cxx . . $ uint8# scale_tab[] = |
| 195 | { |
| 196 | 0x00, 0x03, 0x05, 0x07, 0x09, 0x0B, 0x0D, 0x0F, |
| 197 | 0x10, 0x13, 0x15, 0x17, 0x19, 0x1B, 0x1D, 0x1F |
| 198 | }; |
| 199 | |
| 200 | psg_channelcxx . . $ psg_channel# *ch = &channelcxx . . $ PCEFast_PSG#channel.[chnum]; |
| 201 | |
| 202 | const int gbal = 0x1F - scale_tab[(globalbalancecxx . . $ PCEFast_PSG#globalbalance. >> (lr ? 0 : 4)) & 0xF]; |
| 203 | const int bal = 0x1F - scale_tab[(ch->balancecxx . . $ psg_channel#balance. >> (lr ? 0 : 4)) & 0xF]; |
| 204 | const int al = 0x1F - (ch->controlcxx . . $ psg_channel#control. & 0x1F); |
| 205 | int vol_reduction; |
| 206 | |
| 207 | vol_reduction = gbal + bal + al; |
| 208 | |
| 209 | if(vol_reduction > 0x1F) |
| 210 | vol_reduction = 0x1F; |
| 211 | |
| 212 | return(vol_reduction); |
| 213 | } |
| 214 | |
| 215 | void PCEFast_PSGcxx . . $ PCEFast_PSG#::Writecxx . . $ PCEFast_PSG#Write(109a18db49cfadc0).(int32cxx . . $ int32# timestamp, uint8cxx . . $ uint8# A, uint8cxx . . $ uint8# V) |
| 216 | { |
| 217 | A &= 0x0F; |
| 218 | |
| 219 | if(A == 0x00) |
| 220 | { |
| 221 | selectcxx . . $ PCEFast_PSG#select. = (V & 0x07); |
| 222 | return; |
| 223 | } |
| 224 | |
| 225 | Updatecxx . . $ PCEFast_PSG#Update(d4f767463ce0a6b3).(timestamp); |
| 226 | |
| 227 | psg_channelcxx . . $ psg_channel# *ch = &channelcxx . . $ PCEFast_PSG#channel.[selectcxx . . $ PCEFast_PSG#select.]; |
| 228 | |
| 229 | //if(A == 0x01 || select == 5) |
| 230 | // printf("Write Ch: %d %04x %02x, %d\n", select, A, V, timestamp); |
| 231 | |
| 232 | switch(A) |
| 233 | { |
| 234 | default: break; |
| 235 | |
| 236 | case 0x01: /* Global sound balance */ |
| 237 | globalbalancecxx . . $ PCEFast_PSG#globalbalance. = V; |
| 238 | vol_pendingcxx . . $ PCEFast_PSG#vol_pending. = true; |
| 239 | break; |
| 240 | |
| 241 | case 0x02: /* Channel frequency (LSB) */ |
| 242 | if(selectcxx . . $ PCEFast_PSG#select. > 5) return; // no more than 6 channels, silly game. |
| 243 | |
| 244 | ch->frequencycxx . . $ psg_channel#frequency. = (ch->frequencycxx . . $ psg_channel#frequency. & 0x0F00) | V; |
| 245 | RecalcFreqCachecxx . . $ PCEFast_PSG#RecalcFreqCache(d4f767463ce0a6b3).(selectcxx . . $ PCEFast_PSG#select.); |
| 246 | RecalcUOFunccxx . . $ PCEFast_PSG#RecalcUOFunc(d4f767463ce0a6b3).(selectcxx . . $ PCEFast_PSG#select.); |
| 247 | break; |
| 248 | |
| 249 | case 0x03: /* Channel frequency (MSB) */ |
| 250 | if(selectcxx . . $ PCEFast_PSG#select. > 5) return; // no more than 6 channels, silly game. |
| 251 | |
| 252 | ch->frequencycxx . . $ psg_channel#frequency. = (ch->frequencycxx . . $ psg_channel#frequency. & 0x00FF) | ((V & 0x0F) << 8); |
| 253 | RecalcFreqCachecxx . . $ PCEFast_PSG#RecalcFreqCache(d4f767463ce0a6b3).(selectcxx . . $ PCEFast_PSG#select.); |
| 254 | RecalcUOFunccxx . . $ PCEFast_PSG#RecalcUOFunc(d4f767463ce0a6b3).(selectcxx . . $ PCEFast_PSG#select.); |
| 255 | break; |
| 256 | |
| 257 | case 0x04: /* Channel enable, DDA, volume */ |
| 258 | if(selectcxx . . $ PCEFast_PSG#select. > 5) return; // no more than 6 channels, silly game. |
| 259 | |
| 260 | if((ch->controlcxx . . $ psg_channel#control. & 0x40) && !(V & 0x40)) |
| 261 | { |
| 262 | ch->waveform_indexcxx . . $ psg_channel#waveform_index. = 0; |
| 263 | ch->ddacxx . . $ psg_channel#dda. = ch->waveformcxx . . $ psg_channel#waveform.[ch->waveform_indexcxx . . $ psg_channel#waveform_index.]; |
| 264 | ch->countercxx . . $ psg_channel#counter. = ch->freq_cachecxx . . $ psg_channel#freq_cache.; |
| 265 | } |
| 266 | |
| 267 | if(!(ch->controlcxx . . $ psg_channel#control. & 0x80) && (V & 0x80)) |
| 268 | { |
| 269 | if(!(V & 0x40)) |
| 270 | { |
| 271 | ch->waveform_indexcxx . . $ psg_channel#waveform_index. = (ch->waveform_indexcxx . . $ psg_channel#waveform_index. + 1) & 0x1F; |
| 272 | ch->ddacxx . . $ psg_channel#dda. = ch->waveformcxx . . $ psg_channel#waveform.[ch->waveform_indexcxx . . $ psg_channel#waveform_index.]; |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | ch->controlcxx . . $ psg_channel#control. = V; |
| 277 | RecalcFreqCachecxx . . $ PCEFast_PSG#RecalcFreqCache(d4f767463ce0a6b3).(selectcxx . . $ PCEFast_PSG#select.); |
| 278 | RecalcUOFunccxx . . $ PCEFast_PSG#RecalcUOFunc(d4f767463ce0a6b3).(selectcxx . . $ PCEFast_PSG#select.); |
| 279 | |
| 280 | vol_pendingcxx . . $ PCEFast_PSG#vol_pending. = true; |
| 281 | break; |
| 282 | |
| 283 | case 0x05: /* Channel balance */ |
| 284 | if(selectcxx . . $ PCEFast_PSG#select. > 5) return; // no more than 6 channels, silly game. |
| 285 | ch->balancecxx . . $ psg_channel#balance. = V; |
| 286 | |
| 287 | vol_pendingcxx . . $ PCEFast_PSG#vol_pending. = true; |
| 288 | break; |
| 289 | |
| 290 | case 0x06: /* Channel waveform data */ |
| 291 | if(selectcxx . . $ PCEFast_PSG#select. > 5) return; // no more than 6 channels, silly game. |
| 292 | V &= 0x1F; |
| 293 | |
| 294 | if(!(ch->controlcxx . . $ psg_channel#control. & 0x40)) |
| 295 | { |
| 296 | ch->samp_accumcxx . . $ psg_channel#samp_accum. -= ch->waveformcxx . . $ psg_channel#waveform.[ch->waveform_indexcxx . . $ psg_channel#waveform_index.]; |
| 297 | ch->waveformcxx . . $ psg_channel#waveform.[ch->waveform_indexcxx . . $ psg_channel#waveform_index.] = V; |
| 298 | ch->samp_accumcxx . . $ psg_channel#samp_accum. += ch->waveformcxx . . $ psg_channel#waveform.[ch->waveform_indexcxx . . $ psg_channel#waveform_index.]; |
| 299 | } |
| 300 | |
| 301 | if((ch->controlcxx . . $ psg_channel#control. & 0xC0) == 0x00) |
| 302 | ch->waveform_indexcxx . . $ psg_channel#waveform_index. = ((ch->waveform_indexcxx . . $ psg_channel#waveform_index. + 1) & 0x1F); |
| 303 | |
| 304 | if(ch->controlcxx . . $ psg_channel#control. & 0x80) |
| 305 | { |
| 306 | // According to my tests(on SuperGrafx), writing to this channel |
| 307 | // will update the waveform value cache/latch regardless of DDA mode being enabled. |
| 308 | ch->ddacxx . . $ psg_channel#dda. = V; |
| 309 | } |
| 310 | break; |
| 311 | |
| 312 | case 0x07: /* Noise enable and frequency */ |
| 313 | if(selectcxx . . $ PCEFast_PSG#select. > 5) return; // no more than 6 channels, silly game. |
| 314 | if(selectcxx . . $ PCEFast_PSG#select. >= 4) |
| 315 | { |
| 316 | ch->noisectrlcxx . . $ psg_channel#noisectrl. = V; |
| 317 | RecalcNoiseFreqCachecxx . . $ PCEFast_PSG#RecalcNoiseFreqCache(d4f767463ce0a6b3).(selectcxx . . $ PCEFast_PSG#select.); |
| 318 | RecalcUOFunccxx . . $ PCEFast_PSG#RecalcUOFunc(d4f767463ce0a6b3).(selectcxx . . $ PCEFast_PSG#select.); |
| 319 | } |
| 320 | break; |
| 321 | |
| 322 | case 0x08: /* LFO frequency */ |
| 323 | lfofreqcxx . . $ PCEFast_PSG#lfofreq. = V & 0xFF; |
| 324 | //printf("LFO Freq: %02x\n", V); |
| 325 | break; |
| 326 | |
| 327 | case 0x09: /* LFO trigger and control */ |
| 328 | //printf("LFO Ctrl: %02x\n", V); |
| 329 | if(V & 0x80) |
| 330 | { |
| 331 | channelcxx . . $ PCEFast_PSG#channel.[1].waveform_indexcxx . . $ psg_channel#waveform_index. = 0; |
| 332 | channelcxx . . $ PCEFast_PSG#channel.[1].ddacxx . . $ psg_channel#dda. = channelcxx . . $ PCEFast_PSG#channel.[1].waveformcxx . . $ psg_channel#waveform.[channelcxx . . $ PCEFast_PSG#channel.[1].waveform_indexcxx . . $ psg_channel#waveform_index.]; |
| 333 | channelcxx . . $ PCEFast_PSG#channel.[1].countercxx . . $ psg_channel#counter. = channelcxx . . $ PCEFast_PSG#channel.[1].freq_cachecxx . . $ psg_channel#freq_cache.; |
| 334 | } |
| 335 | lfoctrlcxx . . $ PCEFast_PSG#lfoctrl. = V; |
| 336 | RecalcFreqCachecxx . . $ PCEFast_PSG#RecalcFreqCache(d4f767463ce0a6b3).(0); |
| 337 | RecalcUOFunccxx . . $ PCEFast_PSG#RecalcUOFunc(d4f767463ce0a6b3).(0); |
| 338 | RecalcFreqCachecxx . . $ PCEFast_PSG#RecalcFreqCache(d4f767463ce0a6b3).(1); |
| 339 | RecalcUOFunccxx . . $ PCEFast_PSG#RecalcUOFunc(d4f767463ce0a6b3).(1); |
| 340 | break; |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | // Don't use INLINE, which has always_inline in it, due to gcc's inability to cope with the type of recursion |
| 345 | // used in this function. |
| 346 | template<bool LFO_On> |
| 347 | void PCEFast_PSGcxx . . $ PCEFast_PSG#::RunChannelcxx . . $ PCEFast_PSG#RunChannel(3e454b8ccf442868).(int chc, int32cxx . . $ int32# timestamp) |
| 348 | { |
| 349 | psg_channelcxx . . $ psg_channel# *ch = &channelcxx . . $ PCEFast_PSG#channel.[chc]; |
| 350 | int32cxx . . $ int32# running_timestamp = ch->lasttscxx . . $ psg_channel#lastts.; |
| 351 | int32cxx . . $ int32# run_time = timestamp - ch->lasttscxx . . $ psg_channel#lastts.; |
| 352 | |
| 353 | ch->lasttscxx . . $ psg_channel#lastts. = timestamp; |
| 354 | |
| 355 | if(!run_time) |
| 356 | return; |
| 357 | |
| 358 | (this->*ch->UpdateOutputcxx . . $ psg_channel#UpdateOutput.)(running_timestamp, ch); |
| 359 | |
| 360 | if(chc >= 4) |
| 361 | { |
| 362 | int32cxx . . $ int32# freq = ch->noise_freq_cachecxx . . $ psg_channel#noise_freq_cache.; |
| 363 | |
| 364 | ch->noisecountcxx . . $ psg_channel#noisecount. -= run_time; |
| 365 | |
| 366 | #define CLOCK_LFSRcxx . . $ `mednafen/pce_fast/psg.cpp:366:9`!(lfsr) { unsigned int newbit = ((lfsr >> 0) ^ (lfsr >> 1) ^ (lfsr >> 11) ^ (lfsr >> 12) ^ (lfsr >> 17)) & 1; lfsr = (lfsr >> 1) | (newbit << 17); } |
| 367 | if(&PCEFast_PSGcxx . . $ PCEFast_PSG#::UpdateOutput_Noisecxx . . $ PCEFast_PSG#UpdateOutput_Noise(e385037a997bc971). == ch->UpdateOutputcxx . . $ psg_channel#UpdateOutput.) |
| 368 | { |
| 369 | while(ch->noisecountcxx . . $ psg_channel#noisecount. <= 0) |
| 370 | { |
| 371 | CLOCK_LFSRcxx . . $ `mednafen/pce_fast/psg.cpp:366:9`!(ch->lfsr); |
| 372 | UpdateOutput_Noisecxx . . $ PCEFast_PSG#UpdateOutput_Noise(e385037a997bc971).(timestamp + ch->noisecountcxx . . $ psg_channel#noisecount., ch); |
| 373 | ch->noisecountcxx . . $ psg_channel#noisecount. += freq; |
| 374 | } |
| 375 | } |
| 376 | else |
| 377 | { |
| 378 | while(ch->noisecountcxx . . $ psg_channel#noisecount. <= 0) |
| 379 | { |
| 380 | CLOCK_LFSRcxx . . $ `mednafen/pce_fast/psg.cpp:366:9`!(ch->lfsr); |
| 381 | ch->noisecountcxx . . $ psg_channel#noisecount. += freq; |
| 382 | } |
| 383 | } |
| 384 | #undef CLOCK_LFSRcxx . . $ `mednafen/pce_fast/psg.cpp:366:9`! |
| 385 | } |
| 386 | |
| 387 | // D7 of control is 0, don't clock the counter at all. |
| 388 | // D7 of lfocontrol is 1(and chc == 1), don't clock the counter at all(not sure about this) |
| 389 | // In DDA mode, don't clock the counter. |
| 390 | // (Noise being enabled isn't handled here since AFAIK it doesn't disable clocking of the waveform portion, its sound just overrides the sound from |
| 391 | // the waveform portion when the noise enable bit is set, which is handled in our RecalcUOFunc). |
| 392 | if(!(ch->controlcxx . . $ psg_channel#control. & 0x80) || (chc == 1 && (lfoctrlcxx . . $ PCEFast_PSG#lfoctrl. & 0x80)) || (ch->controlcxx . . $ psg_channel#control. & 0x40)) |
| 393 | return; |
| 394 | |
| 395 | ch->countercxx . . $ psg_channel#counter. -= run_time; |
| 396 | |
| 397 | if(!LFO_On && ch->freq_cachecxx . . $ psg_channel#freq_cache. <= 0xA) |
| 398 | { |
| 399 | if(ch->countercxx . . $ psg_channel#counter. <= 0) |
| 400 | { |
| 401 | const int32cxx . . $ int32# inc_count = ((0 - ch->countercxx . . $ psg_channel#counter.) / ch->freq_cachecxx . . $ psg_channel#freq_cache.) + 1; |
| 402 | |
| 403 | ch->countercxx . . $ psg_channel#counter. += inc_count * ch->freq_cachecxx . . $ psg_channel#freq_cache.; |
| 404 | |
| 405 | ch->waveform_indexcxx . . $ psg_channel#waveform_index. = (ch->waveform_indexcxx . . $ psg_channel#waveform_index. + inc_count) & 0x1F; |
| 406 | ch->ddacxx . . $ psg_channel#dda. = ch->waveformcxx . . $ psg_channel#waveform.[ch->waveform_indexcxx . . $ psg_channel#waveform_index.]; |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | while(ch->countercxx . . $ psg_channel#counter. <= 0) |
| 411 | { |
| 412 | ch->waveform_indexcxx . . $ psg_channel#waveform_index. = (ch->waveform_indexcxx . . $ psg_channel#waveform_index. + 1) & 0x1F; |
| 413 | ch->ddacxx . . $ psg_channel#dda. = ch->waveformcxx . . $ psg_channel#waveform.[ch->waveform_indexcxx . . $ psg_channel#waveform_index.]; |
| 414 | |
| 415 | (this->*ch->UpdateOutputcxx . . $ psg_channel#UpdateOutput.)(timestamp + ch->countercxx . . $ psg_channel#counter., ch); |
| 416 | |
| 417 | if(LFO_On) |
| 418 | { |
| 419 | RunChannelcxx . . $ PCEFast_PSG#RunChannel(3e454b8ccf442868).<false>(1, timestamp + ch->countercxx . . $ psg_channel#counter.); |
| 420 | RecalcFreqCachecxx . . $ PCEFast_PSG#RecalcFreqCache(d4f767463ce0a6b3).(0); |
| 421 | RecalcUOFunccxx . . $ PCEFast_PSG#RecalcUOFunc(d4f767463ce0a6b3).(0); |
| 422 | |
| 423 | ch->countercxx . . $ psg_channel#counter. += (ch->freq_cachecxx . . $ psg_channel#freq_cache. <= 0xA) ? 0xA : ch->freq_cachecxx . . $ psg_channel#freq_cache.; // Not particularly accurate, but faster. |
| 424 | } |
| 425 | else |
| 426 | ch->countercxx . . $ psg_channel#counter. += ch->freq_cachecxx . . $ psg_channel#freq_cache.; |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! void PCEFast_PSGcxx . . $ PCEFast_PSG#::UpdateSubLFOcxx . . $ PCEFast_PSG#UpdateSubLFO(d4f767463ce0a6b3).(int32cxx . . $ int32# timestamp) |
| 431 | { |
| 432 | RunChannelcxx . . $ PCEFast_PSG#RunChannel(3e454b8ccf442868).<true>(0, timestamp); |
| 433 | |
| 434 | for(int chc = 1; chc < 6; chc++) |
| 435 | RunChannelcxx . . $ PCEFast_PSG#RunChannel(3e454b8ccf442868).<false>(chc, timestamp); |
| 436 | } |
| 437 | |
| 438 | INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! void PCEFast_PSGcxx . . $ PCEFast_PSG#::UpdateSubNonLFOcxx . . $ PCEFast_PSG#UpdateSubNonLFO(d4f767463ce0a6b3).(int32cxx . . $ int32# timestamp) |
| 439 | { |
| 440 | for(int chc = 0; chc < 6; chc++) |
| 441 | RunChannelcxx . . $ PCEFast_PSG#RunChannel(3e454b8ccf442868).<false>(chc, timestamp); |
| 442 | } |
| 443 | |
| 444 | //static int32 last_read; |
| 445 | //static int32 last_apply; |
| 446 | |
| 447 | void PCEFast_PSGcxx . . $ PCEFast_PSG#::Updatecxx . . $ PCEFast_PSG#Update(d4f767463ce0a6b3).(int32cxx . . $ int32# timestamp) |
| 448 | { |
| 449 | int32cxx . . $ int32# run_time = timestamp - lasttscxx . . $ PCEFast_PSG#lastts.; |
| 450 | |
| 451 | if(vol_pendingcxx . . $ PCEFast_PSG#vol_pending. && !vol_update_countercxx . . $ PCEFast_PSG#vol_update_counter. && !vol_update_whichcxx . . $ PCEFast_PSG#vol_update_which.) |
| 452 | { |
| 453 | vol_update_countercxx . . $ PCEFast_PSG#vol_update_counter. = 1; |
| 454 | vol_pendingcxx . . $ PCEFast_PSG#vol_pending. = false; |
| 455 | } |
| 456 | |
| 457 | bool lfo_on = (bool)(lfoctrlcxx . . $ PCEFast_PSG#lfoctrl. & 0x03); |
| 458 | |
| 459 | if(lfo_on) |
| 460 | { |
| 461 | if(!(channelcxx . . $ PCEFast_PSG#channel.[1].controlcxx . . $ psg_channel#control. & 0x80) || (lfoctrlcxx . . $ PCEFast_PSG#lfoctrl. & 0x80)) |
| 462 | { |
| 463 | lfo_on = 0; |
| 464 | RecalcFreqCachecxx . . $ PCEFast_PSG#RecalcFreqCache(d4f767463ce0a6b3).(0); |
| 465 | RecalcUOFunccxx . . $ PCEFast_PSG#RecalcUOFunc(d4f767463ce0a6b3).(0); |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | int32cxx . . $ int32# clocks = run_time; |
| 470 | int32cxx . . $ int32# running_timestamp = lasttscxx . . $ PCEFast_PSG#lastts.; |
| 471 | |
| 472 | while(clocks > 0) |
| 473 | { |
| 474 | int32cxx . . $ int32# chunk_clocks = clocks; |
| 475 | |
| 476 | if(vol_update_countercxx . . $ PCEFast_PSG#vol_update_counter. > 0 && chunk_clocks > vol_update_countercxx . . $ PCEFast_PSG#vol_update_counter.) |
| 477 | chunk_clocks = vol_update_countercxx . . $ PCEFast_PSG#vol_update_counter.; |
| 478 | |
| 479 | running_timestamp += chunk_clocks; |
| 480 | clocks -= chunk_clocks; |
| 481 | |
| 482 | if(lfo_on) |
| 483 | UpdateSubLFOcxx . . $ PCEFast_PSG#UpdateSubLFO(d4f767463ce0a6b3).(running_timestamp); |
| 484 | else |
| 485 | UpdateSubNonLFOcxx . . $ PCEFast_PSG#UpdateSubNonLFO(d4f767463ce0a6b3).(running_timestamp); |
| 486 | |
| 487 | if(vol_update_countercxx . . $ PCEFast_PSG#vol_update_counter. > 0) |
| 488 | { |
| 489 | vol_update_countercxx . . $ PCEFast_PSG#vol_update_counter. -= chunk_clocks; |
| 490 | if(!vol_update_countercxx . . $ PCEFast_PSG#vol_update_counter.) |
| 491 | { |
| 492 | const int phase = vol_update_whichcxx . . $ PCEFast_PSG#vol_update_which. & 1; |
| 493 | const int lr = ((vol_update_whichcxx . . $ PCEFast_PSG#vol_update_which. >> 1) & 1) ^ 1; |
| 494 | const int chnum = vol_update_whichcxx . . $ PCEFast_PSG#vol_update_which. >> 2; |
| 495 | |
| 496 | if(!phase) |
| 497 | { |
| 498 | //printf("Volume update(Read, %d since last): ch=%d, lr=%d, ts=%d\n", running_timestamp - last_read, chnum, lr, running_timestamp); |
| 499 | |
| 500 | if(chnum < 6) |
| 501 | { |
| 502 | vol_update_vllatchcxx . . $ PCEFast_PSG#vol_update_vllatch. = GetVLcxx . . $ PCEFast_PSG#GetVL(9b79fb6aee4c0440).(chnum, lr); |
| 503 | } |
| 504 | //last_read = running_timestamp; |
| 505 | } |
| 506 | else |
| 507 | { |
| 508 | // printf("Volume update(Apply): ch=%d, lr=%d, ts=%d\n", chnum, lr, running_timestamp); |
| 509 | if(chnum < 6) |
| 510 | { |
| 511 | channelcxx . . $ PCEFast_PSG#channel.[chnum].vlcxx . . $ psg_channel#vl.[lr] = vol_update_vllatchcxx . . $ PCEFast_PSG#vol_update_vllatch.; |
| 512 | } |
| 513 | //last_apply = running_timestamp; |
| 514 | } |
| 515 | vol_update_whichcxx . . $ PCEFast_PSG#vol_update_which. = (vol_update_whichcxx . . $ PCEFast_PSG#vol_update_which. + 1) & 0x1F; |
| 516 | |
| 517 | if(vol_update_whichcxx . . $ PCEFast_PSG#vol_update_which.) |
| 518 | vol_update_countercxx . . $ PCEFast_PSG#vol_update_counter. = phase ? 1 : 255; |
| 519 | else if(vol_pendingcxx . . $ PCEFast_PSG#vol_pending.) |
| 520 | { |
| 521 | vol_update_countercxx . . $ PCEFast_PSG#vol_update_counter. = phase ? 1 : 255; |
| 522 | vol_pendingcxx . . $ PCEFast_PSG#vol_pending. = false; |
| 523 | } |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | lasttscxx . . $ PCEFast_PSG#lastts. = running_timestamp; |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | void PCEFast_PSGcxx . . $ PCEFast_PSG#::EndFramecxx . . $ PCEFast_PSG#EndFrame(d4f767463ce0a6b3).(int32cxx . . $ int32# timestamp) |
| 532 | { |
| 533 | Updatecxx . . $ PCEFast_PSG#Update(d4f767463ce0a6b3).(timestamp); |
| 534 | lasttscxx . . $ PCEFast_PSG#lastts. = 0; |
| 535 | for(int chc = 0; chc < 6; chc++) |
| 536 | channelcxx . . $ PCEFast_PSG#channel.[chc].lasttscxx . . $ psg_channel#lastts. = 0; |
| 537 | } |
| 538 | |
| 539 | void PCEFast_PSGcxx . . $ PCEFast_PSG#::Powercxx . . $ PCEFast_PSG#Power(d4f767463ce0a6b3).(const int32cxx . . $ int32# timestamp) |
| 540 | { |
| 541 | // Not sure about power-on values, these are mostly just intuitive guesses(with some laziness thrown in). |
| 542 | if(timestamp != lasttscxx . . $ PCEFast_PSG#lastts.) |
| 543 | Updatecxx . . $ PCEFast_PSG#Update(d4f767463ce0a6b3).(timestamp); |
| 544 | |
| 545 | memset(&channelcxx . . $ PCEFast_PSG#channel., 0, sizeof(channelcxx . . $ PCEFast_PSG#channel.)); |
| 546 | |
| 547 | selectcxx . . $ PCEFast_PSG#select. = 0; |
| 548 | globalbalancecxx . . $ PCEFast_PSG#globalbalance. = 0; |
| 549 | lfofreqcxx . . $ PCEFast_PSG#lfofreq. = 0; |
| 550 | lfoctrlcxx . . $ PCEFast_PSG#lfoctrl. = 0; |
| 551 | |
| 552 | for(int ch = 0; ch < 6; ch++) |
| 553 | { |
| 554 | channelcxx . . $ PCEFast_PSG#channel.[ch].frequencycxx . . $ psg_channel#frequency. = 0; |
| 555 | channelcxx . . $ PCEFast_PSG#channel.[ch].controlcxx . . $ psg_channel#control. = 0x00; |
| 556 | channelcxx . . $ PCEFast_PSG#channel.[ch].balancecxx . . $ psg_channel#balance. = 0; |
| 557 | memset(channelcxx . . $ PCEFast_PSG#channel.[ch].waveformcxx . . $ psg_channel#waveform., 0, 32); |
| 558 | channelcxx . . $ PCEFast_PSG#channel.[ch].samp_accumcxx . . $ psg_channel#samp_accum. = 0; |
| 559 | |
| 560 | channelcxx . . $ PCEFast_PSG#channel.[ch].waveform_indexcxx . . $ psg_channel#waveform_index. = 0; |
| 561 | channelcxx . . $ PCEFast_PSG#channel.[ch].ddacxx . . $ psg_channel#dda. = 0x00; |
| 562 | channelcxx . . $ PCEFast_PSG#channel.[ch].noisectrlcxx . . $ psg_channel#noisectrl. = 0x00; |
| 563 | |
| 564 | channelcxx . . $ PCEFast_PSG#channel.[ch].vlcxx . . $ psg_channel#vl.[0] = 0x1F; |
| 565 | channelcxx . . $ PCEFast_PSG#channel.[ch].vlcxx . . $ psg_channel#vl.[1] = 0x1F; |
| 566 | |
| 567 | channelcxx . . $ PCEFast_PSG#channel.[ch].samp_accumcxx . . $ psg_channel#samp_accum. = 0; |
| 568 | |
| 569 | RecalcFreqCachecxx . . $ PCEFast_PSG#RecalcFreqCache(d4f767463ce0a6b3).(ch); |
| 570 | RecalcUOFunccxx . . $ PCEFast_PSG#RecalcUOFunc(d4f767463ce0a6b3).(ch); |
| 571 | |
| 572 | channelcxx . . $ PCEFast_PSG#channel.[ch].countercxx . . $ psg_channel#counter. = channelcxx . . $ PCEFast_PSG#channel.[ch].freq_cachecxx . . $ psg_channel#freq_cache.; |
| 573 | |
| 574 | if(ch >= 4) |
| 575 | { |
| 576 | RecalcNoiseFreqCachecxx . . $ PCEFast_PSG#RecalcNoiseFreqCache(d4f767463ce0a6b3).(ch); |
| 577 | channelcxx . . $ PCEFast_PSG#channel.[ch].noisecountcxx . . $ psg_channel#noisecount. = 1; |
| 578 | channelcxx . . $ PCEFast_PSG#channel.[ch].lfsrcxx . . $ psg_channel#lfsr. = 1; |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | vol_pendingcxx . . $ PCEFast_PSG#vol_pending. = false; |
| 583 | vol_update_countercxx . . $ PCEFast_PSG#vol_update_counter. = 0; |
| 584 | vol_update_whichcxx . . $ PCEFast_PSG#vol_update_which. = 0; |
| 585 | } |
| 586 | |
| 587 | int PCEFast_PSGcxx . . $ PCEFast_PSG#::StateActioncxx . . $ PCEFast_PSG#StateAction(a45b884b8cf568d5).(StateMemcxx . . $ StateMem# *sm, int load, int data_only) |
| 588 | { |
| 589 | int ret = 1; |
| 590 | |
| 591 | for(int ch = 0; ch < 6; ch++) |
| 592 | { |
| 593 | char tmpstr[5] = "SCHx"; |
| 594 | psg_channelcxx . . $ psg_channel# *pt = &channelcxx . . $ PCEFast_PSG#channel.[ch]; |
| 595 | |
| 596 | SFORMATcxx . . $ SFORMAT# CH_StateRegs[] = |
| 597 | { |
| 598 | SFVARNcxx . . $ `mednafen/state.h:69:9`!(pt->counter, "counter"), |
| 599 | SFVARNcxx . . $ `mednafen/state.h:69:9`!(pt->frequency, "frequency"), |
| 600 | SFVARNcxx . . $ `mednafen/state.h:69:9`!(pt->control, "control"), |
| 601 | SFVARNcxx . . $ `mednafen/state.h:69:9`!(pt->balance, "balance"), |
| 602 | SFARRAYNcxx . . $ `mednafen/state.h:72:9`!(pt->waveform, 32, "waveform"), |
| 603 | SFVARNcxx . . $ `mednafen/state.h:69:9`!(pt->waveform_index, "waveform_index"), |
| 604 | SFVARNcxx . . $ `mednafen/state.h:69:9`!(pt->dda, "dda"), |
| 605 | SFVARNcxx . . $ `mednafen/state.h:69:9`!(pt->noisectrl, "noisectrl"), |
| 606 | SFVARNcxx . . $ `mednafen/state.h:69:9`!(pt->noisecount, "noisecount"), |
| 607 | SFVARNcxx . . $ `mednafen/state.h:69:9`!(pt->lfsr, "lfsr"), |
| 608 | SFARRAY32Ncxx . . $ `mednafen/state.h:81:9`!(pt->vl, 2, "vl"), // TODO |
| 609 | SFENDcxx . . $ `mednafen/state.h:94:9`! |
| 610 | }; |
| 611 | tmpstr[3] = '0' + ch; |
| 612 | ret &= MDFNSS_StateActioncxx . . $ MDFNSS_StateAction(3f628545d3b0df83).(sm, load, data_only, CH_StateRegs, tmpstr); |
| 613 | } |
| 614 | |
| 615 | SFORMATcxx . . $ SFORMAT# PSG_StateRegs[] = |
| 616 | { |
| 617 | SFVARcxx . . $ `mednafen/state.h:70:9`!(select), |
| 618 | SFVARcxx . . $ `mednafen/state.h:70:9`!(globalbalance), |
| 619 | SFVARcxx . . $ `mednafen/state.h:70:9`!(lfofreq), |
| 620 | SFVARcxx . . $ `mednafen/state.h:70:9`!(lfoctrl), |
| 621 | |
| 622 | SFVARcxx . . $ `mednafen/state.h:70:9`!(vol_update_counter), |
| 623 | SFVARcxx . . $ `mednafen/state.h:70:9`!(vol_update_which), |
| 624 | SFVARcxx . . $ `mednafen/state.h:70:9`!(vol_pending), |
| 625 | SFENDcxx . . $ `mednafen/state.h:94:9`! |
| 626 | }; |
| 627 | |
| 628 | ret &= MDFNSS_StateActioncxx . . $ MDFNSS_StateAction(3f628545d3b0df83).(sm, load, data_only, PSG_StateRegs, "PSG"); |
| 629 | |
| 630 | if(load) |
| 631 | { |
| 632 | vol_update_whichcxx . . $ PCEFast_PSG#vol_update_which. &= 0x1F; |
| 633 | |
| 634 | if(!channelcxx . . $ PCEFast_PSG#channel.[4].lfsrcxx . . $ psg_channel#lfsr.) |
| 635 | channelcxx . . $ PCEFast_PSG#channel.[4].lfsrcxx . . $ psg_channel#lfsr. = 1; |
| 636 | |
| 637 | if(!channelcxx . . $ PCEFast_PSG#channel.[5].lfsrcxx . . $ psg_channel#lfsr.) |
| 638 | channelcxx . . $ PCEFast_PSG#channel.[5].lfsrcxx . . $ psg_channel#lfsr. = 1; |
| 639 | |
| 640 | for(int ch = 0; ch < 6; ch++) |
| 641 | { |
| 642 | channelcxx . . $ PCEFast_PSG#channel.[ch].samp_accumcxx . . $ psg_channel#samp_accum. = 0; |
| 643 | for(int wi = 0; wi < 32; wi++) |
| 644 | { |
| 645 | channelcxx . . $ PCEFast_PSG#channel.[ch].waveformcxx . . $ psg_channel#waveform.[wi] &= 0x1F; |
| 646 | channelcxx . . $ PCEFast_PSG#channel.[ch].samp_accumcxx . . $ psg_channel#samp_accum. += channelcxx . . $ PCEFast_PSG#channel.[ch].waveformcxx . . $ psg_channel#waveform.[wi]; |
| 647 | } |
| 648 | |
| 649 | for(int lr = 0; lr < 2; lr++) |
| 650 | channelcxx . . $ PCEFast_PSG#channel.[ch].vlcxx . . $ psg_channel#vl.[lr] &= 0x1F; |
| 651 | |
| 652 | if(!channelcxx . . $ PCEFast_PSG#channel.[ch].noisecountcxx . . $ psg_channel#noisecount. && ch >= 4) |
| 653 | { |
| 654 | printf("ch=%d, noisecount == 0\n", ch); |
| 655 | channelcxx . . $ PCEFast_PSG#channel.[ch].noisecountcxx . . $ psg_channel#noisecount. = 1; |
| 656 | } |
| 657 | |
| 658 | if(channelcxx . . $ PCEFast_PSG#channel.[ch].countercxx . . $ psg_channel#counter. <= 0) |
| 659 | { |
| 660 | printf("ch=%d, counter <= 0\n", ch); |
| 661 | channelcxx . . $ PCEFast_PSG#channel.[ch].countercxx . . $ psg_channel#counter. = 1; |
| 662 | } |
| 663 | |
| 664 | if(ch >= 4) |
| 665 | RecalcNoiseFreqCachecxx . . $ PCEFast_PSG#RecalcNoiseFreqCache(d4f767463ce0a6b3).(ch); |
| 666 | RecalcFreqCachecxx . . $ PCEFast_PSG#RecalcFreqCache(d4f767463ce0a6b3).(ch); |
| 667 | RecalcUOFunccxx . . $ PCEFast_PSG#RecalcUOFunc(d4f767463ce0a6b3).(ch); |
| 668 | } |
| 669 | } |
| 670 | return(ret); |
| 671 | } |