diff --git a/A5200DS.nds b/A5200DS.nds index e7470a8..1b69d6c 100644 Binary files a/A5200DS.nds and b/A5200DS.nds differ diff --git a/Makefile b/Makefile index 6f9e369..65605f1 100644 --- a/Makefile +++ b/Makefile @@ -10,8 +10,7 @@ include $(DEVKITARM)/ds_rules export TARGET := A5200DS export TOPDIR := $(CURDIR) -VERSION=3.1 - +VERSION=3.2 ICON := -b $(CURDIR)/logo.bmp "A5200DS $(VERSION);wavemotion-dave;http://https://github.com/wavemotion-dave/A5200DS" diff --git a/arm7/Makefile b/arm7/Makefile index 075d420..3a120ed 100644 --- a/arm7/Makefile +++ b/arm7/Makefile @@ -36,8 +36,8 @@ CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -fno-rtti ASFLAGS := -g $(ARCH) LDFLAGS = -specs=ds_arm7.specs -g $(ARCH) -Wl,-Map,$(notdir $*).map -#LIBS := -ldswifi7 -lmm7 -lnds7 -lmm7 -LIBS := -ldswifi7 -lnds7 -lmm7 +#LIBS := -ldswifi7 -lmm7 -lnds7 +LIBS := -ldswifi7 -lnds7 #--------------------------------------------------------------------------------- # list of directories containing libraries, this must be the top level containing diff --git a/arm7/source/emusoundfifo.c b/arm7/source/emusoundfifo.c index f1d67a1..a455a5d 100644 --- a/arm7/source/emusoundfifo.c +++ b/arm7/source/emusoundfifo.c @@ -9,8 +9,7 @@ typedef enum { } FifoMesType; //--------------------------------------------------------------------------------- -void soundEmuDataHandler(int bytes, void *user_data) -{ +void soundEmuDataHandler(int bytes, void *user_data) { int channel = -1; FifoMessage msg; @@ -41,8 +40,7 @@ void soundEmuCommandHandler(u32 command, void* userdata) { int data = command & 0xFFFF; int channel = (command >> 16) & 0xF; - switch(cmd) - { + switch(cmd) { case SOUND_SET_VOLUME: SCHANNEL_CR(channel) &= ~0xFF; @@ -77,8 +75,7 @@ void soundEmuCommandHandler(u32 command, void* userdata) { } //--------------------------------------------------------------------------------- -void installSoundEmuFIFO(void) -{ +void installSoundEmuFIFO(void) { fifoSetDatamsgHandler(FIFO_USER_01, soundEmuDataHandler, 0); fifoSetValue32Handler(FIFO_USER_01, soundEmuCommandHandler, 0); } diff --git a/arm7/source/main.c b/arm7/source/main.c index ecf4b88..1628137 100644 --- a/arm7/source/main.c +++ b/arm7/source/main.c @@ -1,50 +1,49 @@ /*--------------------------------------------------------------------------------- - default ARM7 core + default ARM7 core - Copyright (C) 2005 - 2010 - Michael Noland (joat) - Jason Rogers (dovoto) - Dave Murphy (WinterMute) + Copyright (C) 2005 - 2010 + Michael Noland (joat) + Jason Rogers (dovoto) + Dave Murphy (WinterMute) - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any - damages arising from the use of this software. + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any + damages arising from the use of this software. - Permission is granted to anyone to use this software for any - purpose, including commercial applications, and to alter it and - redistribute it freely, subject to the following restrictions: + Permission is granted to anyone to use this software for any + purpose, including commercial applications, and to alter it and + redistribute it freely, subject to the following restrictions: - 1. The origin of this software must not be misrepresented; you - must not claim that you wrote the original software. If you use - this software in a product, an acknowledgment in the product - documentation would be appreciated but is not required. + 1. The origin of this software must not be misrepresented; you + must not claim that you wrote the original software. If you use + this software in a product, an acknowledgment in the product + documentation would be appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and - must not be misrepresented as being the original software. + 2. Altered source versions must be plainly marked as such, and + must not be misrepresented as being the original software. - 3. This notice may not be removed or altered from any source - distribution. + 3. This notice may not be removed or altered from any source + distribution. ---------------------------------------------------------------------------------*/ #include #include -#include +//#include extern void installSoundEmuFIFO(void); -extern void mmInstall( int fifo_channel ); //--------------------------------------------------------------------------------- void VblankHandler(void) { //--------------------------------------------------------------------------------- - Wifi_Update(); + Wifi_Update(); } //--------------------------------------------------------------------------------- void VcountHandler() { //--------------------------------------------------------------------------------- - inputGetAndSend(); + inputGetAndSend(); } volatile bool exitflag = false; @@ -52,47 +51,45 @@ volatile bool exitflag = false; //--------------------------------------------------------------------------------- void powerButtonCB() { //--------------------------------------------------------------------------------- - exitflag = true; + exitflag = true; } -void mmInstall(int); - //--------------------------------------------------------------------------------- int main() { //--------------------------------------------------------------------------------- - readUserSettings(); + readUserSettings(); - irqInit(); - // Start the RTC tracking IRQ - initClockIRQ(); - touchInit(); - fifoInit(); + irqInit(); + // Start the RTC tracking IRQ + initClockIRQ(); + touchInit(); + fifoInit(); - mmInstall( FIFO_MAXMOD ); + //mmInstall(FIFO_MAXMOD); - SetYtrigger(80); + SetYtrigger(80); - installWifiFIFO(); - installSoundFIFO(); + installWifiFIFO(); + installSoundFIFO(); - installSystemFIFO(); + installSystemFIFO(); - installSoundEmuFIFO(); + installSoundEmuFIFO(); - irqSet(IRQ_VCOUNT, VcountHandler); - irqSet(IRQ_VBLANK, VblankHandler); + irqSet(IRQ_VCOUNT, VcountHandler); + irqSet(IRQ_VBLANK, VblankHandler); - irqEnable( IRQ_VBLANK | IRQ_VCOUNT | IRQ_NETWORK); - - setPowerButtonCB(powerButtonCB); + irqEnable( IRQ_VBLANK | IRQ_VCOUNT | IRQ_NETWORK); + + setPowerButtonCB(powerButtonCB); - // Keep the ARM7 mostly idle - while (!exitflag) { - if ( 0 == (REG_KEYINPUT & (KEY_SELECT | KEY_START | KEY_L | KEY_R))) { - exitflag = true; - } + // Keep the ARM7 mostly idle + while (!exitflag) { + if ( 0 == (REG_KEYINPUT & (KEY_SELECT | KEY_START | KEY_L | KEY_R))) { + exitflag = true; + } - swiWaitForVBlank(); - } - return 0; + swiWaitForVBlank(); + } + return 0; } diff --git a/arm9/gfx/pdev_bg0.png b/arm9/gfx/pdev_bg0.png index 6814f37..63a6fc1 100644 Binary files a/arm9/gfx/pdev_bg0.png and b/arm9/gfx/pdev_bg0.png differ diff --git a/arm9/source/a5200utils.c b/arm9/source/a5200utils.c index 3f47712..85dae93 100644 --- a/arm9/source/a5200utils.c +++ b/arm9/source/a5200utils.c @@ -5,7 +5,6 @@ #include #include #include -#include #include "main.h" #include "a5200utils.h" @@ -15,12 +14,9 @@ #include "cartridge.h" #include "highscore.h" #include "input.h" -#include "pokeysnd.h" #include "emu/pia.h" -#include "soundbank.h" -#include "soundbank_bin.h" - +#include "clickNoQuit_wav.h" #include "bgBottom.h" #include "bgTop.h" #include "bgFileSel.h" @@ -34,8 +30,6 @@ int bg0, bg1, bg0b, bg1b, bg2, bg3; unsigned int etatEmu; int atari_frames=0; int frame_skip = TRUE; -u8 emuSoundPause = 1; // To pause sound output -u8 bRestartSoundEngine = 0; // Restart the sound output gamecfg GameConf; // Game Config svg @@ -99,95 +93,38 @@ static void DumpDebugData(void) } } -// -------------------------------------------------------------------------- -// For pausing the maxmod stream... we force a "mute" sound into the stream -// -------------------------------------------------------------------------- -void SoundPause(void) -{ - emuSoundPause = 1; - mmStreamUpdate(); - swiWaitForVBlank();swiWaitForVBlank(); -} +u16 sound_idx __attribute__((section(".dtcm"))) = 0; +u16 myPokeyBufIdx __attribute__((section(".dtcm"))) = 0; +u8 lastSample __attribute__((section(".dtcm"))) = 0; +u16 sampleExtender[256] __attribute__((section(".dtcm"))) = {0}; -// ----------------------------------------------------------------------------------------------- -// MAXMOD streaming setup and handling... We were using the normal ARM7 sound core but it -// sounded "scratchy" and so with the help of FluBBa, we've swiched over to the maxmod sound -// core which seems to perform better. we are using manual streaming to force the updates as -// close to scanline-resolution as possible which helps with volume-only voice sampling. -// ----------------------------------------------------------------------------------------------- -unsigned short sampleMult = 2; -mm_ds_system sys; -mm_stream myStream; -#define BUFFER_SIZE (256*sampleMult) - -// ------------------------------------------------------------------------------------------- -// maxmod will call this routine when the buffer is half-empty and requests that -// we fill the sound buffer with more samples. They will request 'len' samples and -// we will fill exactly that many. If the sound is paused, we fill with 'mute' samples. -// ------------------------------------------------------------------------------------------- -mm_word OurSoundMixer(mm_word len, mm_addr dest, mm_stream_formats format) +void VsoundClear(void) { - extern u8 lastSample; - extern void Pokey_process(void *sndbuffer, unsigned sndn); - if (emuSoundPause) // If paused, just "mix" in mute samples... frequency will not change here - { - // Fill buffer with "mute" sound... - memset(dest, lastSample, len); - } - else - { - Pokey_process(dest, len); // Fill the sound buffer with samples! - } - return len; + extern void PokeyClearBuffer(void); + + PokeyClearBuffer(); + memset(sound_buffer, 0x00, SNDLENGTH); + lastSample = 0x00; + myPokeyBufIdx = 0; + sound_idx = 0; } - -// ------------------------------------------------------------------------------------------- -// Setup the maxmod audio stream - this will be a 8-bit Mono PCM output at 31.4KHz which -// sounds about right for the Atari POKEY chip. For the DS-LITE we will use half that. -// ------------------------------------------------------------------------------------------- -void setupStream(void) +void VsoundHandler(void) { - static u8 bFirstTime = true; - if (bFirstTime) - { - //---------------------------------------------------------------- - // initialize maxmod with our small 2-effect soundbank - //---------------------------------------------------------------- - mmInitDefaultMem((mm_addr)soundbank_bin); - - mmLoadEffect(SFX_CLICKNOQUIT); - mmLoadEffect(SFX_KEYCLICK); - } - else - { - mmStreamClose(); // Close any active stream - we will re-setup - } - bFirstTime = false; - - //---------------------------------------------------------------- - // open stream - //---------------------------------------------------------------- - myStream.sampling_rate = SOUND_FREQ; // sampling rate = - myStream.buffer_length = BUFFER_SIZE; // buffer length = - myStream.callback = OurSoundMixer; // set callback function - myStream.format = MM_STREAM_8BIT_MONO; // format = mono 8-bit - myStream.timer = MM_TIMER3; // use hardware timer 3 (not really used as we are in manual mode anyway) - myStream.manual = true; // use manual filling - mmStreamOpen( &myStream ); - - //---------------------------------------------------------------- - // when using 'automatic' filling, your callback will be triggered - // every time half of the wave buffer is processed. - // - // so: - // 25000 (rate) - // ----- = ~21 Hz for a full pass, and ~42hz for half pass - // 1200 (length) - //---------------------------------------------------------------- - // with 'manual' filling, you must call mmStreamUpdate - // periodically (and often enough to avoid buffer underruns) - //---------------------------------------------------------------- + extern unsigned char pokey_buffer[]; + extern u16 pokeyBufIdx; + + // If there is a fresh sample... + if (myPokeyBufIdx != pokeyBufIdx) + { + *aptr = sampleExtender[pokey_buffer[myPokeyBufIdx]]; + myPokeyBufIdx = (myPokeyBufIdx+1) & (SNDLENGTH-1); + if (myPokeyBufIdx != pokeyBufIdx) + { + *bptr = sampleExtender[pokey_buffer[myPokeyBufIdx]]; + myPokeyBufIdx = (myPokeyBufIdx+1) & (SNDLENGTH-1); + } else *bptr = sampleExtender[pokey_buffer[myPokeyBufIdx]]; + } } void restore_bottom_screen(void) @@ -235,11 +172,6 @@ void vblankIntr() 0x00, 0x33, 0x88, 0x44 }; - - if (emuSoundPause) - { - mmStreamUpdate(); - } REG_BG2PA = xdxBG; REG_BG2PD = ydyBG; @@ -439,7 +371,9 @@ void dsLoadGame(char *filename) atari_pal16[index] = index; } - dsInstallSoundEmuFIFO(); + TIMER2_DATA = TIMER_FREQ((SOUND_FREQ/2)+20); // keep this a little faster than our Pokey sound generation + TIMER2_CR = TIMER_DIV_1 | TIMER_IRQ_REQ | TIMER_ENABLE; + irqSet(IRQ_TIMER2, VsoundHandler); TIMER0_CR=0; TIMER0_DATA=0; @@ -741,7 +675,7 @@ unsigned int dsWaitOnMenu(unsigned int actState) { iTx = touch.px; iTy = touch.py; if ((iTx>206) && (iTx<250) && (iTy>110) && (iTy<129)) { // 207,111 -> 249,128 quit - mmEffect(SFX_CLICKNOQUIT); + soundPlaySample(clickNoQuit_wav, SoundFormat_16Bit, clickNoQuit_wav_size, 22050, 127, 64, false, 0); bDone=dsWaitOnQuit(); if (bDone) uState=A5200_QUITSTDS; } @@ -792,13 +726,34 @@ void dsPrintValue(int x, int y, unsigned int isSelect, char *pchStr) //--------------------------------------------------------------------------------- void dsInstallSoundEmuFIFO(void) { - SoundPause(); - swiWaitForVBlank(); // Wait 2 vertical blanks... Enough for the pause to kick in... - sampleMult = (isDSiMode() ? 2:1); // For the DSi we can afford doubling the samplerate for better sound - Pokey_sound_init(FREQ_17_APPROX, SOUND_FREQ, 1, 0); // Make sure the Atari Emulation side knows our current sound frequency - setupStream(); // Setup MaxMod Audio Stream + // We are going to use the 16-bit sound engine so we need to scale up our 8-bit values... + for (int i=0; i<256; i++) + { + sampleExtender[i] = (i << 8); + } + + if (isDSiMode()) + { + aptr = (u16*) ((u32)&sound_buffer[0] + 0xA000000); + bptr = (u16*) ((u32)&sound_buffer[2] + 0xA000000); + } + else + { + aptr = (u16*) ((u32)&sound_buffer[0] + 0x00400000); + bptr = (u16*) ((u32)&sound_buffer[2] + 0x00400000); + } - bRestartSoundEngine = true; // After we process the first scanline of the new frame, we will start up the audio + FifoMessage msg; + msg.SoundPlay.data = &sound_buffer; + msg.SoundPlay.freq = SOUND_FREQ*2; + msg.SoundPlay.volume = 127; + msg.SoundPlay.pan = 64; + msg.SoundPlay.loop = 1; + msg.SoundPlay.format = ((1)<<4) | SoundFormat_16Bit; + msg.SoundPlay.loopPoint = 0; + msg.SoundPlay.dataSize = 4 >> 2; + msg.type = EMUARM7_PLAY_SND; + fifoSendDatamsg(FIFO_USER_01, sizeof(msg), (u8*)&msg); } extern u32 trig0, trig1; @@ -835,7 +790,10 @@ void dsMainLoop(void) { case A5200_PLAYINIT: irqDisable(IRQ_TIMER2); dsShowScreenEmu(); + VsoundClear(); swiWaitForVBlank();swiWaitForVBlank(); + irqEnable(IRQ_TIMER2); + fifoSendValue32(FIFO_USER_01,(1<<16) | (127) | SOUND_SET_VOLUME); etatEmu = A5200_PLAYGAME; atari_frames=0; TIMER0_DATA=0; @@ -858,13 +816,6 @@ void dsMainLoop(void) { // Execute one frame Atari800_Frame(); - // Reset the sound indexes and unpause the sound engine... - if (bRestartSoundEngine) - { - bRestartSoundEngine = 0; - emuSoundPause=0; - } - if (++atari_frames == 60) { TIMER0_CR=0; @@ -907,10 +858,11 @@ void dsMainLoop(void) { iTx = touch.px; iTy = touch.py; if ((iTx>211) && (iTx<250) && (iTy>112) && (iTy<130)) { //quit - SoundPause(); - mmEffect(SFX_CLICKNOQUIT); + fifoSendValue32(FIFO_USER_01,(1<<16) | (0) | SOUND_SET_VOLUME); + + soundPlaySample(clickNoQuit_wav, SoundFormat_16Bit, clickNoQuit_wav_size, 22050, 127, 64, false, 0); if (dsWaitOnQuit()) etatEmu=A5200_QUITSTDS; - else { bRestartSoundEngine=true; } + else { fifoSendValue32(FIFO_USER_01,(1<<16) | (127) | SOUND_SET_VOLUME);} } else if ((iTx>240) && (iTx<256) && (iTy>0) && (iTy<20)) { // Full Speed Toggle ... upper corner... if (keys_touch == 0) @@ -921,37 +873,37 @@ void dsMainLoop(void) { } } else if ((iTx>160) && (iTx<200) && (iTy>112) && (iTy<130)) { //highscore - SoundPause(); + fifoSendValue32(FIFO_USER_01,(1<<16) | (0) | SOUND_SET_VOLUME); highscore_display(); restore_bottom_screen(); - bRestartSoundEngine=true; + fifoSendValue32(FIFO_USER_01,(1<<16) | (127) | SOUND_SET_VOLUME); } else if ((iTx>115) && (iTx<150) && (iTy>112) && (iTy<130)) { //pause - if (!keys_touch) mmEffect(SFX_CLICKNOQUIT); + if (!keys_touch) soundPlaySample(clickNoQuit_wav, SoundFormat_16Bit, clickNoQuit_wav_size, 22050, 127, 64, false, 0); key_code = AKEY_5200_PAUSE + key_code; keys_touch = 1; } else if ((iTx>64) && (iTx<105) && (iTy>112) && (iTy<130)) { //reset - if (!keys_touch) mmEffect(SFX_CLICKNOQUIT); + if (!keys_touch) soundPlaySample(clickNoQuit_wav, SoundFormat_16Bit, clickNoQuit_wav_size, 22050, 127, 64, false, 0); key_code = AKEY_5200_RESET + key_code; keys_touch = 1; } else if ((iTx>8) && (iTx<54) && (iTy>112) && (iTy<130)) { //start - if (!keys_touch) mmEffect(SFX_CLICKNOQUIT); + if (!keys_touch) soundPlaySample(clickNoQuit_wav, SoundFormat_16Bit, clickNoQuit_wav_size, 22050, 127, 64, false, 0); key_code = AKEY_5200_START + key_code; keys_touch = 1; } else if ((iTy>155) && (iTy<185)) { char padKey[] = {AKEY_5200_0,AKEY_5200_1,AKEY_5200_2,AKEY_5200_3,AKEY_5200_4,AKEY_5200_5,AKEY_5200_6,AKEY_5200_7,AKEY_5200_8,AKEY_5200_9,AKEY_5200_HASH,AKEY_5200_ASTERISK}; - if (!keys_touch) mmEffect(SFX_CLICKNOQUIT); + if (!keys_touch) soundPlaySample(clickNoQuit_wav, SoundFormat_16Bit, clickNoQuit_wav_size, 22050, 127, 64, false, 0); if (iTx > 0) iTx--; if (iTx > 0) iTx--; key_code = padKey[iTx / 21] + key_code; keys_touch = 1; } else if ((iTx>70) && (iTx<185) && (iTy>7) && (iTy<50)) { // 72,8 -> 182,42 cartridge slot - SoundPause(); + fifoSendValue32(FIFO_USER_01,(1<<16) | (0) | SOUND_SET_VOLUME); // Find files in current directory and show it a52FindFiles(); romSel=dsWaitForRom(); @@ -961,7 +913,10 @@ void dsMainLoop(void) { dsLoadGame(a5200romlist[ucFicAct].filename); if (full_speed) dsPrintValue(30,0,0,"FS"); else dsPrintValue(30,0,0," "); } - bRestartSoundEngine=true; + else + { + fifoSendValue32(FIFO_USER_01,(1<<16) | (127) | SOUND_SET_VOLUME); + } } } else diff --git a/arm9/source/emu/pokey.c b/arm9/source/emu/pokey.c index 7e4f25b..c289338 100644 --- a/arm9/source/emu/pokey.c +++ b/arm9/source/emu/pokey.c @@ -21,7 +21,6 @@ * along with Atari800; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include #include #include "config.h" #include "atari.h" @@ -297,8 +296,9 @@ void POKEY_Frame(void) ***************************************************************************/ void POKEY_Scanline(void) { - mmStreamUpdate(); - + Pokey_process(&pokey_buffer[pokeyBufIdx], 1); // Each scanline, compute 1 output samples. This corresponds to a 15720Khz output sample rate if running at 60FPS (good enough) + pokeyBufIdx = (pokeyBufIdx+1) & (SNDLENGTH-1); + if (pot_scanline < 228) pot_scanline++; diff --git a/arm9/source/emu/pokeysnd.c b/arm9/source/emu/pokeysnd.c index a03d88d..32d2e45 100644 --- a/arm9/source/emu/pokeysnd.c +++ b/arm9/source/emu/pokeysnd.c @@ -370,21 +370,21 @@ static void Update_pokey_sound_rf(uint16 addr, uint8 val, uint8 chip, uint8 gain /* Outputs: the buffer will be filled with n bytes of audio - no return val */ /* */ /*****************************************************************************/ -u8 lastSample=0; void Pokey_process(void *sndbuffer, unsigned sndn) { - char *buffer = (char*) sndbuffer; - uint16 n = sndn; - uint32 *div_n_ptr; - uint8 *samp_cnt_w_ptr; - uint32 event_min; - uint8 next_event; - int16 cur_val; - uint8 *out_ptr; - uint8 audc; - uint8 toggle; - uint8 *vol_ptr; - + register char *buffer = (char *) sndbuffer; + register uint16 n = sndn; + + register uint32 *div_n_ptr; + register uint8 *samp_cnt_w_ptr; + register uint32 event_min; + register uint8 next_event; + register unsigned char cur_val; /* otherwise we'll simplify as 8-bit unsigned */ + register uint8 *out_ptr; + register uint8 audc; + register uint8 toggle; + register uint8 *vol_ptr; + /* set a pointer to the whole portion of the samp_n_cnt */ samp_cnt_w_ptr = ((uint8 *) (&Samp_n_cnt[0]) + 1); @@ -423,49 +423,50 @@ void Pokey_process(void *sndbuffer, unsigned sndn) div_n_ptr = Div_n_cnt; - /* Though I could have used a loop here, this is faster */ - if (*div_n_ptr <= event_min) { - event_min = *div_n_ptr; - next_event = CHAN1; - } - div_n_ptr++; - if (*div_n_ptr <= event_min) { - event_min = *div_n_ptr; - next_event = CHAN2; - } - div_n_ptr++; - if (*div_n_ptr <= event_min) { - event_min = *div_n_ptr; - next_event = CHAN3; - } - div_n_ptr++; - if (*div_n_ptr <= event_min) { - event_min = *div_n_ptr; - next_event = CHAN4; - } - div_n_ptr++; - - /* if the next event is a channel change */ - if (next_event != SAMPLE) - { - /* shift the polynomial counters */ - - /* decrement all counters by the smallest count found */ - /* again, no loop for efficiency */ - div_n_ptr--; - *div_n_ptr -= event_min; - div_n_ptr--; - *div_n_ptr -= event_min; - div_n_ptr--; - *div_n_ptr -= event_min; - div_n_ptr--; - *div_n_ptr -= event_min; + /* Though I could have used a loop here, this is faster */ + if (*div_n_ptr <= event_min) { + event_min = *div_n_ptr; + next_event = CHAN1; + } + div_n_ptr++; + if (*div_n_ptr <= event_min) { + event_min = *div_n_ptr; + next_event = CHAN2; + } + div_n_ptr++; + if (*div_n_ptr <= event_min) { + event_min = *div_n_ptr; + next_event = CHAN3; + } + div_n_ptr++; + if (*div_n_ptr <= event_min) { + event_min = *div_n_ptr; + next_event = CHAN4; + } + div_n_ptr++; + + /* if the next event is a channel change */ + if (next_event != SAMPLE) { + /* shift the polynomial counters */ + + /* decrement all counters by the smallest count found */ + /* again, no loop for efficiency */ + div_n_ptr--; + *div_n_ptr -= event_min; + div_n_ptr--; + *div_n_ptr -= event_min; + div_n_ptr--; + *div_n_ptr -= event_min; + div_n_ptr--; + *div_n_ptr -= event_min; WRITE_U32(samp_cnt_w_ptr, READ_U32(samp_cnt_w_ptr) - event_min); /* since the polynomials require a mod (%) function which is division, I don't adjust the polynomials on the SAMPLE events, - only the CHAN events. I have to keep track of the change, though. */ + only the CHAN events. I have to keep track of the change, + though. */ + P4 = (P4 + event_min) % POLY4_SIZE; P5 = (P5 + event_min) % POLY5_SIZE; P9 = (P9 + event_min) % POLY9_SIZE; @@ -488,8 +489,7 @@ void Pokey_process(void *sndbuffer, unsigned sndn) /* much description to explain it here. */ /* if VOLUME only then nothing to process */ - if (!(audc & VOL_ONLY)) - { + if (!(audc & VOL_ONLY)) { /* if the output is pure or the output is poly5 and the poly5 bit */ /* is set */ if ((audc & NOTPOLY5) || bit5[P5]) { @@ -548,29 +548,29 @@ void Pokey_process(void *sndbuffer, unsigned sndn) if (*out_ptr) { /* remove this channel from the signal */ cur_val -= AUDV[next_event]; + /* and turn the output off */ *out_ptr = 0; } else { /* turn the output on */ *out_ptr = 1; + /* and add it to the output signal */ cur_val += AUDV[next_event]; } } } - else - { - /* otherwise we're processing a sample */ - short iout = (short)cur_val + 128; - if(iout > 250) iout=250; - if(iout < 0) iout=0; - *buffer++ = (u8)iout; - lastSample = (u8)iout; - *Samp_n_cnt += Samp_n_max; - /* and indicate one less byte in the buffer */ - n--; - } + else { /* otherwise we're processing a sample */ + /* adjust the sample counter - note we're using the 24.8 integer + which includes an 8 bit fraction for accuracy */ + int iout; + iout = cur_val; + *buffer++ = (char) ((iout))+128; + *Samp_n_cnt += Samp_n_max; + /* and indicate one less byte in the buffer */ + n--; + } } } diff --git a/arm9/source/main.c b/arm9/source/main.c index 4fb4b60..8563015 100644 --- a/arm9/source/main.c +++ b/arm9/source/main.c @@ -39,6 +39,8 @@ int main(int argc, char **argv) } // Init Timer + dsInitTimer(); + dsInstallSoundEmuFIFO(); highscore_init(); if (keysCurrent() & KEY_R) diff --git a/readme.txt b/readme.txt index f40ce8d..167aef2 100644 --- a/readme.txt +++ b/readme.txt @@ -28,6 +28,9 @@ Check updates on my web site : https://github.com/wavemotion-dave/A5200DS -------------------------------------------------------------------------------- History : -------------------------------------------------------------------------------- +V3.2 : 12-Dec-2021 + * Reverted back to ARM7 SoundLib (a few games missing key sounds) + V3.1 : 30-Nov-2021 * Switched to maxmod audio library for improved sound. * Try to start in /roms or /roms/a5200 if possible