From 71b5e02a43bee4de2985282f6f08e24f3fac75e3 Mon Sep 17 00:00:00 2001 From: uyjulian Date: Sat, 31 Jan 2015 15:47:27 -0600 Subject: [PATCH] Some changes --- emu.c | 11 +++++------ it.c | 14 +++++++------- main.c | 24 ++++++++++++------------ sound.c | 11 +++++------ 4 files changed, 29 insertions(+), 31 deletions(-) diff --git a/emu.c b/emu.c index 6bf1bc2..6db68b6 100644 --- a/emu.c +++ b/emu.c @@ -125,9 +125,7 @@ void SPC_READ_DSP() } void SPC_WRITE_DSP() -{ - - s32 i; +{ s32 addr_lo = SPC_DSP_ADDR & 0xF, addr_hi = SPC_DSP_ADDR >> 4; switch (addr_lo) { @@ -135,8 +133,9 @@ void SPC_WRITE_DSP() SPC_DSP_DATA &= 0x3F; break; case 5: // ADSR1 - if ((SNDkeys & (1 << addr_hi)) && ((SPC_DSP_DATA & 0x80) != (SPC_DSP[SPC_DSP_ADDR] & 0x80))) + if ((SPC_DSP[0x4C] & (1 << addr_hi)) && ((SPC_DSP_DATA & 0x80) != (SPC_DSP[SPC_DSP_ADDR] & 0x80))) { + s32 i; // First of all, in case anything was already // going on, finish it up SNDDoEnv(addr_hi); @@ -174,7 +173,7 @@ void SPC_WRITE_DSP() SNDvoices[addr_hi].sl = SPC_DSP_DATA >> 5; break; case 7: // GAIN - if ((SNDkeys & (1 << addr_hi)) && (SPC_DSP_DATA != SPC_DSP[SPC_DSP_ADDR]) && + if ((SPC_DSP[0x4C] & (1 << addr_hi)) && (SPC_DSP_DATA != SPC_DSP[SPC_DSP_ADDR]) && !(SPC_DSP[(addr_hi << 4) + 5] & 0x80)) { if (SPC_DSP_DATA & 0x80) @@ -197,7 +196,7 @@ void SPC_WRITE_DSP() { case 4: // Key on SNDNoteOn(SPC_DSP_DATA); - SPC_DSP_DATA = SNDkeys; + SPC_DSP_DATA = SPC_DSP[0x4C]; break; case 5: // Key off SNDNoteOff(SPC_DSP_DATA); diff --git a/it.c b/it.c index 121dcf5..2911ae7 100644 --- a/it.c +++ b/it.c @@ -96,7 +96,6 @@ static s32 ITDecodeSample(u16 start, sndsamp **sp) u16 end; u32 brrptr, sampptr = 0; s32 i; - u8 range, filter, shift_amount; src = &SPCRAM[start]; for (end = 0; !(src[end] & 1); end += 9) ; @@ -108,9 +107,9 @@ static s32 ITDecodeSample(u16 start, sndsamp **sp) s->loopto = 0; for (brrptr = 0; brrptr <= end;) { - range = src[brrptr++]; - filter = (range & 0x0c) >> 2; - shift_amount = (range >> 4) & 0x0F; + u8 range = src[brrptr++]; + u8 filter = (range & 0x0c) >> 2; + u8 shift_amount = (range >> 4) & 0x0F; for (i = 0; i < 8; i++, brrptr++) { ITDecodeSampleInternal(src[brrptr] >> 4, shift_amount, filter); // Decode high nybble @@ -151,7 +150,7 @@ static s32 ITPitchToNote(s32 pitch, s32 base) else if (tmp < 0) tmp = 0; note = (s32)tmp; - if ((s32)(tmp * 2) != (note << 1)) + if ((s32)(tmp * 2) != (note * 2)) note++; // correct rounding return note; } @@ -453,12 +452,13 @@ void ITMix() u8 mastervolume = SPC_DSP[0x0C]; for (voice = 0; voice < 8; voice++) { - if ((SNDkeys & (1 << voice))) + if ((SPC_DSP[0x4C] & (1 << voice))) // 0x4C == key on { envx = SNDDoEnv(voice); - //envx = SPC_DSP[0x08]; lvol = (envx >> 24) * (s32)((s8)SPC_DSP[(voice << 4) ]) * mastervolume >> 14; // Ext rvol = (envx >> 24) * (s32)((s8)SPC_DSP[(voice << 4) + 0x01]) * mastervolume >> 14; // Ext + // Volume no echo: (s32)((s8)SPC_DSP[(voice << 4) ]) * mastervolume >> 7; + pitch = (s32)(*(u16 *)&SPC_DSP[(voice << 4) + 0x02]) * 7.8125; // Pointer hell? // adjust for negative volumes diff --git a/main.c b/main.c index 6dbb464..07cfe46 100644 --- a/main.c +++ b/main.c @@ -22,40 +22,40 @@ int main(int argc, char **argv) { size_t u8Size = sizeof(u8); if (!(u8Size == 1)) - printf("Warning: wrong size u8: %lu \n", u8Size); + printf("Warning: wrong size u8: %zu \n", u8Size); size_t u16Size = sizeof(u16); if (!(u16Size == 2)) - printf("Warning: wrong size u16: %lu \n", u16Size); + printf("Warning: wrong size u16: %zu \n", u16Size); size_t u32Size = sizeof(u32); if (!(u32Size == 4)) - printf("Warning: wrong size u32: %lu \n", u32Size); + printf("Warning: wrong size u32: %zu \n", u32Size); size_t u64Size = sizeof(u64); if (!(u64Size == 8)) - printf("Warning: wrong size u64: %lu \n", u64Size); + printf("Warning: wrong size u64: %zu \n", u64Size); size_t s8Size = sizeof(s8); if (!(s8Size == 1)) - printf("Warning: wrong size s8: %lu \n", s8Size); + printf("Warning: wrong size s8: %zu \n", s8Size); size_t s16Size = sizeof(s16); if (!(s16Size == 2)) - printf("Warning: wrong size s16: %lu \n", s16Size); + printf("Warning: wrong size s16: %zu \n", s16Size); size_t s32Size = sizeof(s32); if (!(s32Size == 4)) - printf("Warning: wrong size s32: %lu \n", s32Size); + printf("Warning: wrong size s32: %zu \n", s32Size); size_t s64Size = sizeof(s64); if (!(s64Size == 8)) - printf("Warning: wrong size s64: %lu \n", s64Size); + printf("Warning: wrong size s64: %zu \n", s64Size); size_t ITFileHeaderSize = sizeof(ITFileHeader); if (!(ITFileHeaderSize == 192)) - printf("Warning: wrong size ITFileHeader: %lu \n", ITFileHeaderSize); + printf("Warning: wrong size ITFileHeader: %zu \n", ITFileHeaderSize); size_t ITFileSampleSize = sizeof(ITFileSample); if (!(ITFileSampleSize == 80)) - printf("Warning: wrong size ITFileSample: %lu \n", ITFileSampleSize); + printf("Warning: wrong size ITFileSample: %zu \n", ITFileSampleSize); size_t ITFilePatternSize = sizeof(ITFilePattern); if (!(ITFilePatternSize == 8)) - printf("Warning: wrong size ITFilePattern: %lu \n", ITFilePatternSize); + printf("Warning: wrong size ITFilePattern: %zu \n", ITFilePatternSize); size_t SPCFileSize = sizeof(SPCFile); if (!(SPCFileSize == 65920)) - printf("Warning: wrong size SPCFile: %lu \n", SPCFileSize); + printf("Warning: wrong size SPCFile: %zu \n", SPCFileSize); s32 seconds, limit, ITrows; char fn[PATH_MAX]; s32 i; diff --git a/sound.c b/sound.c index 61a0112..2e85696 100644 --- a/sound.c +++ b/sound.c @@ -11,7 +11,7 @@ #include "sound.h" sndvoice SNDvoices[8]; -s32 SNDkeys, SNDratecnt; +s32 SNDratecnt; static const u32 C[0x20] = { 0x0, 0x20000, 0x18000, 0x14000, 0x10000, 0xC000, 0xA000, 0x8000, 0x6000, 0x5000, 0x4000, @@ -23,11 +23,11 @@ static const u32 C[0x20] = { s32 SNDDoEnv(s32 voice) { - u32 envx, cyc, c; + u32 envx, c; envx = SNDvoices[voice].envx; for (;;) { - cyc = TotalCycles - SNDvoices[voice].envcyc; + u32 cyc = TotalCycles - SNDvoices[voice].envcyc; switch (SNDvoices[voice].envstate) { case ATTACK: @@ -104,7 +104,7 @@ s32 SNDDoEnv(s32 voice) envx -= 0x800000; // sub 1/256th if ((envx == 0) || (envx > 0x7F000000)) { - SNDkeys &= ~(1 << voice); + SPC_DSP[0x4C] &= ~(1 << voice); return SNDvoices[voice].envx = 0; } } @@ -206,7 +206,7 @@ void SNDNoteOn(u8 v) cursamp = SPC_DSP[4 + (i << 4)]; if (cursamp < 512) { - SNDkeys |= (1 << i); + SPC_DSP[0x4C] |= (1 << i); // figure ADSR/GAIN adsr1 = SPC_DSP[(i << 4) + 5]; if (adsr1 & 0x80) @@ -257,7 +257,6 @@ void SNDNoteOff(u8 v) s32 SNDInit() { s32 i; - SNDkeys = 0; for (i = 0; i < 8; i++) SNDvoices[i].envx = 0; return (0);