| 1 |
/* Mednafen - Multi-system Emulator |
| 2 |
* |
| 3 |
* Original skeleton write handler and PSG structure definition: |
| 4 |
* Copyright (C) 2001 Charles MacDonald |
| 5 |
* |
| 6 |
* This program is free software; you can redistribute it and/or modify |
| 7 |
* it under the terms of the GNU General Public License as published by |
| 8 |
* the Free Software Foundation; either version 2 of the License, or |
| 9 |
* (at your option) any later version. |
| 10 |
* |
| 11 |
* This program is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this program; if not, write to the Free Software |
| 18 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 |
*/ |
| 20 |
|
| 21 |
// additional modifications by tildearrow for furnace |
| 22 |
|
| 23 |
#ifndef __MDFN_HW_SOUND_PCE_PSG_PCE_PSG_H |
| 24 |
#define __MDFN_HW_SOUND_PCE_PSG_PCE_PSG_H |
| 25 |
|
| 26 |
#include <stdint.h> |
| 27 |
#include "blip_buf.h" |
| 28 |
#include "../../dispatch.h" |
| 29 |
|
| 30 |
class PCE_PSG; |
| 31 |
|
| 32 |
struct psg_channel |
| 33 |
{ |
| 34 |
uint8_t waveform[32]; /* Waveform data */ |
| 35 |
uint8_t waveform_index; /* Waveform data index */ |
| 36 |
uint8_t dda; |
| 37 |
uint8_t control; /* Channel enable, DDA, volume */ |
| 38 |
uint8_t noisectrl; /* Noise enable/ctrl (channels 4,5 only) */ |
| 39 |
|
| 40 |
int32_t vl[2]; //vll, vlr; |
| 41 |
|
| 42 |
int32_t counter; |
| 43 |
|
| 44 |
void (PCE_PSG::*UpdateOutput)(const int32_t timestamp, psg_channel *ch); |
| 45 |
DivDispatchOscBuffer* oscBuf; |
| 46 |
|
| 47 |
uint32_t freq_cache; |
| 48 |
uint32_t noise_freq_cache; // Channel 4,5 only |
| 49 |
int32_t noisecount; |
| 50 |
uint32_t lfsr; |
| 51 |
|
| 52 |
int32_t samp_accum; // The result of adding up all the samples in the waveform buffer(part of an optimization for high-frequency playback). |
| 53 |
int32_t blip_prev_samp[2]; |
| 54 |
int32_t lastts; |
| 55 |
|
| 56 |
uint16_t frequency; /* Channel frequency */ |
| 57 |
uint8_t balance; /* Channel balance */ |
| 58 |
}; |
| 59 |
|
| 60 |
// Only CH4 and CH5 have NCTRL and LFSR, but it's here for the other channels for "consistency". |
| 61 |
enum |
| 62 |
{ |
| 63 |
PSG_GSREG_CH0_FREQ = 0x000, |
| 64 |
// PSG_GSREG_CH0_COUNTER, |
| 65 |
PSG_GSREG_CH0_CTRL, |
| 66 |
PSG_GSREG_CH0_BALANCE, |
| 67 |
PSG_GSREG_CH0_WINDEX, |
| 68 |
PSG_GSREG_CH0_SCACHE, |
| 69 |
PSG_GSREG_CH0_NCTRL, |
| 70 |
PSG_GSREG_CH0_LFSR, |
| 71 |
|
| 72 |
PSG_GSREG_CH1_FREQ = 0x100, |
| 73 |
// PSG_GSREG_CH1_COUNTER, |
| 74 |
PSG_GSREG_CH1_CTRL, |
| 75 |
PSG_GSREG_CH1_BALANCE, |
| 76 |
PSG_GSREG_CH1_WINDEX, |
| 77 |
PSG_GSREG_CH1_SCACHE, |
| 78 |
PSG_GSREG_CH1_NCTRL, |
| 79 |
PSG_GSREG_CH1_LFSR, |
| 80 |
|
| 81 |
PSG_GSREG_CH2_FREQ = 0x200, |
| 82 |
// PSG_GSREG_CH2_COUNTER, |
| 83 |
PSG_GSREG_CH2_CTRL, |
| 84 |
PSG_GSREG_CH2_BALANCE, |
| 85 |
PSG_GSREG_CH2_WINDEX, |
| 86 |
PSG_GSREG_CH2_SCACHE, |
| 87 |
PSG_GSREG_CH2_NCTRL, |
| 88 |
PSG_GSREG_CH2_LFSR, |
| 89 |
|
| 90 |
PSG_GSREG_CH3_FREQ = 0x300, |
| 91 |
// PSG_GSREG_CH3_COUNTER, |
| 92 |
PSG_GSREG_CH3_CTRL, |
| 93 |
PSG_GSREG_CH3_BALANCE, |
| 94 |
PSG_GSREG_CH3_WINDEX, |
| 95 |
PSG_GSREG_CH3_SCACHE, |
| 96 |
PSG_GSREG_CH3_NCTRL, |
| 97 |
PSG_GSREG_CH3_LFSR, |
| 98 |
|
| 99 |
PSG_GSREG_CH4_FREQ = 0x400, |
| 100 |
// PSG_GSREG_CH4_COUNTER, |
| 101 |
PSG_GSREG_CH4_CTRL, |
| 102 |
PSG_GSREG_CH4_BALANCE, |
| 103 |
PSG_GSREG_CH4_WINDEX, |
| 104 |
PSG_GSREG_CH4_SCACHE, |
| 105 |
PSG_GSREG_CH4_NCTRL, |
| 106 |
PSG_GSREG_CH4_LFSR, |
| 107 |
|
| 108 |
PSG_GSREG_CH5_FREQ = 0x500, |
| 109 |
// PSG_GSREG_CH5_COUNTER, |
| 110 |
PSG_GSREG_CH5_CTRL, |
| 111 |
PSG_GSREG_CH5_BALANCE, |
| 112 |
PSG_GSREG_CH5_WINDEX, |
| 113 |
PSG_GSREG_CH5_SCACHE, |
| 114 |
PSG_GSREG_CH5_NCTRL, |
| 115 |
PSG_GSREG_CH5_LFSR, |
| 116 |
|
| 117 |
PSG_GSREG_SELECT = 0x1000, |
| 118 |
PSG_GSREG_GBALANCE, |
| 119 |
PSG_GSREG_LFOFREQ, |
| 120 |
PSG_GSREG_LFOCTRL, |
| 121 |
_PSG_GSREG_COUNT |
| 122 |
}; |
| 123 |
|
| 124 |
class PCE_PSG |
| 125 |
{ |
| 126 |
public: |
| 127 |
|
| 128 |
enum |
| 129 |
{ |
| 130 |
REVISION_HUC6280 = 0, |
| 131 |
REVISION_HUC6280A, |
| 132 |
_REVISION_COUNT |
| 133 |
}; |
| 134 |
|
| 135 |
|
| 136 |
PCE_PSG(int want_revision); |
| 137 |
~PCE_PSG(); |
| 138 |
|
| 139 |
void Power(const int32_t timestamp); |
| 140 |
void Write(int32_t timestamp, uint8_t A, uint8_t V); |
| 141 |
|
| 142 |
void SetVolume(double new_volume); |
| 143 |
|
| 144 |
void Update(int32_t timestamp); |
| 145 |
void ResetTS(int32_t ts_base = 0); |
| 146 |
|
| 147 |
// TODO: timestamp |
| 148 |
uint32_t GetRegister(const unsigned int id, char *special, const uint32_t special_len); |
| 149 |
void SetRegister(const unsigned int id, const uint32_t value); |
| 150 |
|
| 151 |
void PeekWave(const unsigned int ch, uint32_t Address, uint32_t Length, uint8_t *Buffer); |
| 152 |
void PokeWave(const unsigned int ch, uint32_t Address, uint32_t Length, const uint8_t *Buffer); |
| 153 |
|
| 154 |
psg_channel channel[6]; |
| 155 |
|
| 156 |
blip_buffer_t* bb[2]; |
| 157 |
|
| 158 |
private: |
| 159 |
|
| 160 |
void UpdateSubLFO(int32_t timestamp); |
| 161 |
void UpdateSubNonLFO(int32_t timestamp); |
| 162 |
|
| 163 |
void RecalcUOFunc(int chnum); |
| 164 |
void UpdateOutputSub(const int32_t timestamp, psg_channel *ch, const int32_t samp0, const int32_t samp1); |
| 165 |
void UpdateOutput_Off(const int32_t timestamp, psg_channel *ch); |
| 166 |
void UpdateOutput_Accum_HuC6280(const int32_t timestamp, psg_channel *ch); |
| 167 |
void UpdateOutput_Accum_HuC6280A(const int32_t timestamp, psg_channel *ch); |
| 168 |
void UpdateOutput_Norm(const int32_t timestamp, psg_channel *ch); |
| 169 |
void UpdateOutput_Noise(const int32_t timestamp, psg_channel *ch); |
| 170 |
void (PCE_PSG::*UpdateOutput_Accum)(const int32_t timestamp, psg_channel *ch); |
| 171 |
|
| 172 |
int32_t GetVL(const int chnum, const int lr); |
| 173 |
|
| 174 |
void RecalcFreqCache(int chnum); |
| 175 |
void RecalcNoiseFreqCache(int chnum); |
| 176 |
void RunChannel(int chc, int32_t timestamp, bool LFO_On); |
| 177 |
|
| 178 |
uint8_t select; /* Selected channel (0-5) */ |
| 179 |
uint8_t globalbalance; /* Global sound balance */ |
| 180 |
uint8_t lfofreq; /* LFO frequency */ |
| 181 |
uint8_t lfoctrl; /* LFO control */ |
| 182 |
|
| 183 |
int32_t vol_update_counter; |
| 184 |
int32_t vol_update_which; |
| 185 |
int32_t vol_update_vllatch; |
| 186 |
bool vol_pending; |
| 187 |
|
| 188 |
int32_t lastts; |
| 189 |
int revision; |
| 190 |
|
| 191 |
int32_t dbtable_volonly[32]; |
| 192 |
|
| 193 |
int32_t dbtable[32][32]; |
| 194 |
}; |
| 195 |
|
| 196 |
#endif |