X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fpsg.cpp;h=21ceb90cebcf4dcc6d3990860f8349c405b0123b;hb=HEAD;hp=ec849c5d8d1cbed2c1f40587e71c0edcef333817;hpb=a046907b274eb0cfa9c10a4c68fb38255f96714c;p=thunder diff --git a/src/psg.cpp b/src/psg.cpp index ec849c5..21ceb90 100644 --- a/src/psg.cpp +++ b/src/psg.cpp @@ -22,6 +22,7 @@ #include "psg.h" #include #include +#include "fileio.h" struct Voice { @@ -39,6 +40,18 @@ static uint8_t memory[0x200]; static uint32_t sampleRate = 44100; static uint32_t divisor; +void PSGSaveState(FILE * file) +{ + size_t ignored = fwrite(memory, 1, 0x200, file); + ignored = fwrite(&voice, 1, sizeof(voice), file); +} + +void PSGLoadState(FILE * file) +{ + size_t ignored = fread(memory, 1, 0x200, file); + ignored = fread(&voice, 1, sizeof(voice), file); +} + void InitPSG(uint32_t s/*=44100*/) { sampleRate = s; @@ -55,11 +68,6 @@ void InitPSG(uint32_t s/*=44100*/) // void UpdatePSG(uint8_t * buffer, int count) { -/* -if F == 44100, then counter++ for each sample. -if F == 88200, then counter += 2 for each sample. -if F == 22050, then counter += 0.5 for each sample. -*/ // Recast buffer as int16, we're doing 16-bit sound here int16_t * p = (int16_t *)buffer; @@ -72,19 +80,10 @@ if F == 22050, then counter += 0.5 for each sample. for(int j=0; j> 4 : memory[(voice[i].waveform * 16) + (pos / 2)]) & 0x0F; -// p[j] += (((memory[(voice[i].waveform * 32) + pos] & 0x0F) - 8) -// * voice[i].leftVolume) << 5; p[j] += ((sample - 8) * voice[i].leftVolume) << 5; voice[i].counter += voice[i].frequency; } @@ -151,9 +150,6 @@ void WritePSG(uint16_t address, uint8_t data) voice[channel].waveform = data >> 4; voice[channel].frequency = ((data & 0x0F) << 16) | (voice[channel].frequency & 0x0FFFF); -#if 0 -printf("PSG: Setting waveform on channel %i to %i...\n", channel, voice[channel].waveform); -#endif break; case 2: voice[channel].frequency = (data << 8) @@ -167,32 +163,10 @@ printf("PSG: Setting waveform on channel %i to %i...\n", channel, voice[channel] voice[channel].rightVolume = data & 0x0F; // Noise switch is channel # + 1 (wraps to zero) voice[(channel + 1) & 0x07].noise = (data & 0x80 ? true : false); -#if 0 -if (voice[(channel + 1) & 0x07].noise) -{ - uint8_t ch = (channel + 1) & 0x07; - printf("PSG: Setting noise on channel %i, vol=%i, freq=%i...\n", ch, voice[ch].leftVolume, voice[ch].frequency); -} -#endif -#if 0 -if (data & 0x0F) -{ - printf("PSG: Setting right volume on channel %i: vol=%i...\n", channel, voice[channel].rightVolume); -} -#endif break; } } - -// return; } -#if 0 - else - printf("PSG: Write to $%03X of $%02X...\n", address, data); -#endif - -//if (address < 0x100) -// printf("PSG: Waveform byte[$%02X] = $%02X...\n", address, data); memory[address & 0x01FF] = data; }