Skip to content

Commit

Permalink
V3.1 : 31-Jan-2022 by wavemotion-dave
Browse files Browse the repository at this point in the history
  * Now using more VRAM for bank swapping and partial DMA transfer to speed up large games.
  * Reverted part of the sound core to improve sound quality.
  * File selection cleanups to scroll less fast and be generally easier to see.
  • Loading branch information
wavemotion-dave committed Jan 31, 2022
1 parent 3f0b07d commit 639544a
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 67 deletions.
Binary file modified A7800DS.nds
Binary file not shown.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=3.0
VERSION=3.1
TARGNAME=A7800DS

#---------------------------------------------------------------------------------
Expand Down
Binary file modified arm9/gfx/pdev_bg0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
100 changes: 51 additions & 49 deletions arm9/source/a7800utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,40 +96,50 @@ static void DumpDebugData(void)
#endif
}


u16 sampleExtender[256] = {0};
u16 *aptr __attribute__((section(".dtcm"))) = (u16*)((u32)&sound_buffer[0] + 0xA000000);
u16 *bptr __attribute__((section(".dtcm"))) = (u16*)((u32)&sound_buffer[2] + 0xA000000);

u16 myTiaBufIdx __attribute__((section(".dtcm"))) = 0;
void VsoundHandler(void)
u8* snd_ptr __attribute__((section(".dtcm"))) = (u8*)((u32)sound_buffer + 0xA000000);
u8* snd_sta __attribute__((section(".dtcm"))) = (u8*)((u32)sound_buffer + 0xA000000);
u8* snd_end __attribute__((section(".dtcm"))) = (u8*)((u32)sound_buffer + 0xA000000 + SNDLENGTH);
ITCM_CODE void VsoundHandler(void)
{
extern unsigned char tia_buffer[];
extern u16 tiaBufIdx;

// If there is a fresh sample...
if (myTiaBufIdx != tiaBufIdx)
for (u8 i=0; i<4; i++)
{
u16 sample = sampleExtender[tia_buffer[myTiaBufIdx]];
myTiaBufIdx = (myTiaBufIdx+1) & (SNDLENGTH-1);
*aptr = sample;
*bptr = sample;
// If there is a fresh sample...
if (myTiaBufIdx != tiaBufIdx)
{
lastSample = tia_buffer[myTiaBufIdx];
myTiaBufIdx = (myTiaBufIdx+1) & (SNDLENGTH-1);
}
*snd_ptr++ = lastSample;
if (snd_ptr == snd_end)
{
snd_ptr = snd_sta;
}
}
}

u16 myPokeyBufIdx __attribute__((section(".dtcm"))) = 0;
void VsoundHandler_Pokey(void)
ITCM_CODE void VsoundHandler_Pokey(void)
{
extern unsigned char pokey_buffer[];
extern u16 pokeyBufIdx;

// If there is a fresh Pokey sample...
if (myPokeyBufIdx != pokeyBufIdx)
for (u8 i=0; i<2; i++)
{
u16 sample = sampleExtender[pokey_buffer[myPokeyBufIdx]];
myPokeyBufIdx = (myPokeyBufIdx+1) & (SNDLENGTH-1);
*aptr = sample;
*bptr = sample;
// If there is a fresh Pokey sample...
if (myPokeyBufIdx != pokeyBufIdx)
{
lastPokeySample = pokey_buffer[myPokeyBufIdx];
myPokeyBufIdx = (myPokeyBufIdx+1) & (SNDLENGTH-1);
}
*snd_ptr++ = lastPokeySample;
if (snd_ptr == snd_end)
{
snd_ptr = snd_sta;
}
}
}

Expand Down Expand Up @@ -489,7 +499,8 @@ void dsDisplayFiles(unsigned int NoDebGame,u32 ucSel)
unsigned int dsWaitForRom(void)
{
bool bDone=false, bRet=false;
u32 ucHaut=0x00, ucBas=0x00,ucSHaut=0x00, ucSBas=0x00,romSelected= 0, firstRomDisplay=0,nbRomPerPage, uNbRSPage, uLenFic=0,ucFlip=0, ucFlop=0;
u32 ucHaut=0x00, ucBas=0x00,ucSHaut=0x00, ucSBas=0x00,romSelected= 0, firstRomDisplay=0,nbRomPerPage, uNbRSPage, uLenFic=0;
s32 ucFlip=0, ucFlop=0;
char szName[64];

decompress(bgFileSelTiles, bgGetGfxPtr(bg0b), LZ77Vram);
Expand All @@ -511,6 +522,9 @@ unsigned int dsWaitForRom(void)
dsDisplayFiles(firstRomDisplay,romSelected);
while (!bDone) {
if (keysCurrent() & KEY_UP) {
ucFlip = -50;
ucFlop = 0;
uLenFic = 0;
if (!ucHaut) {
ucFicAct = (ucFicAct>0 ? ucFicAct-1 : countpro-1);
if (romSelected>uNbRSPage) { romSelected -= 1; }
Expand All @@ -536,6 +550,9 @@ unsigned int dsWaitForRom(void)
ucHaut = 0;
}
if (keysCurrent() & KEY_DOWN) {
ucFlip = -50;
ucFlop = 0;
uLenFic = 0;
if (!ucBas) {
ucFicAct = (ucFicAct< countpro-1 ? ucFicAct+1 : 0);
if (romSelected<uNbRSPage-1) { romSelected += 1; }
Expand Down Expand Up @@ -630,12 +647,12 @@ unsigned int dsWaitForRom(void)
// Scroll la selection courante
if (strlen(proromlist[ucFicAct].filename) > 29) {
ucFlip++;
if (ucFlip >= 8) {
if (ucFlip >= 20) {
ucFlip = 0;
uLenFic++;
if ((uLenFic+29)>strlen(proromlist[ucFicAct].filename)) {
ucFlop++;
if (ucFlop >= 8) {
if (ucFlop >= 20) {
uLenFic=0;
ucFlop = 0;
}
Expand Down Expand Up @@ -733,57 +750,42 @@ void dsInstallSoundEmuFIFO(void)
{
return; // We've been asked to not install sound...
}

for (int i=0; i<256; i++)
{
sampleExtender[i] = (i << 8);
}

FifoMessage msg;
msg.SoundPlay.data = &sound_buffer;
msg.SoundPlay.freq = (isDSiMode() ? 48000: 32000);
msg.SoundPlay.freq = (cartridge_pokey ? SOUND_FREQ+21:(SOUND_FREQ*2)+21);
msg.SoundPlay.volume = 127;
msg.SoundPlay.pan = 64;
msg.SoundPlay.loop = 1;
msg.SoundPlay.format = ((1)<<4) | SoundFormat_16Bit;
msg.SoundPlay.format = ((1)<<4) | SoundFormat_8Bit;
msg.SoundPlay.loopPoint = 0;
msg.SoundPlay.dataSize = 4 >> 2;
msg.SoundPlay.dataSize = SNDLENGTH >> 2;
msg.type = EMUARM7_PLAY_SND;
fifoSendDatamsg(FIFO_USER_01, sizeof(msg), (u8*)&msg);

if (isDS_LITE)
{
aptr = (u16*)((u32)&sound_buffer[0] + 0x00400000);
bptr = (u16*)((u32)&sound_buffer[2] + 0x00400000);
snd_ptr = (u8*)((u32)sound_buffer + 0x00400000);
snd_sta = (u8*)((u32)sound_buffer + 0x00400000);
snd_end = (u8*)((u32)sound_buffer + 0x00400000 + SNDLENGTH);
}
else
{
aptr = (u16*)((u32)&sound_buffer[0] + 0xA000000);
bptr = (u16*)((u32)&sound_buffer[2] + 0xA000000);
snd_ptr = (u8*)((u32)sound_buffer + 0xA000000);
snd_sta = (u8*)((u32)sound_buffer + 0xA000000);
snd_end = (u8*)((u32)sound_buffer + 0xA000000 + SNDLENGTH);
}

TIMER2_DATA = TIMER_FREQ(SOUND_FREQ/2);
TIMER2_CR = TIMER_DIV_1 | TIMER_IRQ_REQ | TIMER_ENABLE;
if (cartridge_pokey)
{
TIMER2_DATA = TIMER_FREQ(SOUND_FREQ+3);
TIMER2_CR = TIMER_DIV_1 | TIMER_IRQ_REQ | TIMER_ENABLE;
irqSet(IRQ_TIMER2, VsoundHandler_Pokey);
}
else
{
if (isDSiMode())
{
TIMER2_DATA = TIMER_FREQ((SOUND_FREQ*2)+3); // For the DSi we can run at the full 31KHz.
}
else
{
TIMER2_DATA = TIMER_FREQ((SOUND_FREQ)+3); // For the older DS-LITE we only run at 15.5KHz
}
TIMER2_CR = TIMER_DIV_1 | TIMER_IRQ_REQ | TIMER_ENABLE;
irqSet(IRQ_TIMER2, VsoundHandler);
}
irqEnable(IRQ_TIMER2);
}


void dsMainLoop(void)
{
static int lcd_swap_counter=0;
Expand Down
33 changes: 18 additions & 15 deletions arm9/source/emu/Cartridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ uint cartridge_diff1 = DIFF_A;
uint cartridge_diff2 = DIFF_A;

extern int debug[];
static byte* cartridge_buffer __attribute__((section(".dtcm"))) = NULL;
static byte cartridge_buffer[512 * 1024] ALIGN(32);
static uint cartridge_size __attribute__((section(".dtcm"))) = 0;
static uint maxbank = 9;

Expand Down Expand Up @@ -93,9 +93,13 @@ inline static void cartridge_WriteBank(word address, byte bank)
{
last_bank = bank;
uint offset = cartridge_GetBank(bank) * 16384;
if(offset < cartridge_size) {
memory_WriteROMFast(address, (16384/4), cartridge_buffer + offset);
cartridge_bank = bank;
if(offset < cartridge_size)
{
if (offset < (256*1024)) // If we are in fast VRAM memory
memory_WriteROM_DMA((u32*)&memory_ram[address], (u32*)(0x06860000 + offset), 16384);
else // Normal memory
memory_WriteROMFast(address, (16384/4), cartridge_buffer + offset);
cartridge_bank = bank;
}
}
}
Expand Down Expand Up @@ -201,7 +205,7 @@ static bool _cartridge_Load(const byte* data, uint size)
uint offset = 0;
if(cartridge_HasHeader(header))
{
cartridge_ReadHeader(header);
cartridge_ReadHeader(header); // cartridge_size will get filled in from this
size -= 128;
offset = 128;
}
Expand All @@ -211,10 +215,15 @@ static bool _cartridge_Load(const byte* data, uint size)
cartridge_size = size;
}

if (cartridge_size <= (144 * 1024))
cartridge_buffer = (byte *) 0x06860000; // If smaller than 144k (98% of all carts are), we can use the VRAM buffer since it's faster to move stuff around...
else
cartridge_buffer = (byte *) malloc(cartridge_size); // Otherwise allocate memory
// -----------------------------------------------------------------------------
// Copy up to 256K bytes of cart into the fast memory - used for bank swap only
// -----------------------------------------------------------------------------
u32 *fast_mem = (u32*)0x06860000;
memcpy(fast_mem, &data[offset], (256 * 1024));

// ----------------------------------------------------
// And copy the full ROM into the main cart area...
// ----------------------------------------------------
for(index = 0; index < cartridge_size; index++) {
cartridge_buffer[index] = data[index + offset];
}
Expand Down Expand Up @@ -410,13 +419,7 @@ void cartridge_Release( )
{
// Snap out the High Score SRAM (if used)
cartridge_SaveHighScoreSram();

if ((u32)cartridge_buffer != 0x06860000)
{
free(cartridge_buffer);
}
cartridge_size = 0;
cartridge_buffer = NULL;

// These values need to be reset so that moving between carts works
// consistently. This seems to be a ProSystem emulator bug.
Expand Down
3 changes: 2 additions & 1 deletion arm9/source/emu/Database.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ Database_Entry game_list[] = {
{"220121f771fc4b98cef97dc040e8d378", "Ninja Golf", CT_SUPROM, POKEY_NONE, JOY, JOY, DIFF_A, DIFF_A, NTSC, STEAL_CYCLE, USES_WSYNC, HSC_NO, 10, 22, 270, 220}, // title=Ninja Golf
{"74569571a208f8b0b1ccfb22d7c914e1", "One On One", CT_NORMAL, POKEY_NONE, JOY, JOY, DIFF_A, DIFF_A, NTSC, STEAL_CYCLE, USES_WSYNC, HSC_NO, 0, 12, 256, 220}, // title=One On One
{"5013b69cb05b21a1194ce48517df7bfc", "Pac-Man Collection", CT_NORMAL, POKEY_AT_4000, JOY, JOY, DIFF_B, DIFF_B, NTSC, STEAL_CYCLE, USES_WSYNC, HSC_YES, 0, 19, 256, 216}, // title=Pac-Man Collection (homebrew)
{"a59d362e3a391ff1482131aa0818ad3e", "Pac-Man XM", CT_SUPCAR, POKEY_NONE, JOY, JOY, DIFF_A, DIFF_A, NTSC, STEAL_CYCLE, USES_WSYNC, HSC_YES, 9, 25, 278, 220}, // title=Pac-Man Collection 40th Anniversary Edition (homebrew)
{"a59d362e3a391ff1482131aa0818ad3e", "Pac-Man 40th", CT_SUPCAR, POKEY_NONE, JOY, JOY, DIFF_A, DIFF_A, NTSC, STEAL_CYCLE, USES_WSYNC, HSC_YES, 9, 25, 278, 220}, // title=Pac-Man Collection 40th Anniversary Edition (homebrew)
{"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "PMC", CT_SUPCAR, POKEY_NONE, JOY, JOY, DIFF_A, DIFF_A, NTSC, STEAL_CYCLE, USES_WSYNC, HSC_YES, 9, 25, 278, 220}, // title=Pac-Man Collection 40th Anniversary Edition (homebrew)
{"1a5207870dec6fae9111cb747e20d8e3", "Pete Rose Baseball", CT_NORMAL, POKEY_NONE, JOY, JOY, DIFF_A, DIFF_A, NTSC, STEAL_CYCLE, USES_WSYNC, HSC_NO, 0, 22, 256, 220}, // title=Pete Rose Baseball
{"ec206c8db4316eb1ebce9fc960da7d8f", "Pit Fighter", CT_SUPROM, POKEY_NONE, JOY, JOY, DIFF_A, DIFF_A, NTSC, STEAL_CYCLE, USES_WSYNC, HSC_NO, 0, 22, 256, 220}, // title=Pit Fighter
{"33aea1e2b6634a1dec8c7006d9afda22", "Planet Smashers", CT_SUPROM, POKEY_NONE, JOY, JOY, DIFF_A, DIFF_A, NTSC, STEAL_CYCLE, USES_WSYNC, HSC_NO, 0, 18, 256, 226}, // title=Planet Smashers
Expand Down
17 changes: 17 additions & 0 deletions arm9/source/emu/Memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,23 @@ ITCM_CODE void memory_WriteROMFast(word address, word size, const byte* data)
}
}

// ----------------------------------------------------------------------------
// WriteROMFast (assumes memory_rom[] already set properly)
// size is already in multiples of u32 dwords
// ----------------------------------------------------------------------------
ITCM_CODE void memory_WriteROM_DMA(u32 *dest, u32 *src, u32 size)
{
// -------------------------------------------------------------------------
// DMA is holding up the bus for sound so we do a mix of DMA and memcpy()
// which is a slight improvement but keeps the sound engine mostly running.
// -------------------------------------------------------------------------
DC_InvalidateRange(dest, 4096);
dmaCopyWordsAsynch(3, src, dest, 4096);
memcpy(dest+(4096>>2), src+(4096>>2), size-4096);
while (dmaBusy(3)) asm("nop");
}


// ----------------------------------------------------------------------------
// ClearROM
// ----------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions arm9/source/emu/Memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ extern ITCM_CODE void memory_Write(word address, byte data);

extern void memory_WriteROM(word address, word size, const byte* data);
extern void memory_WriteROMFast(word address, word size, const byte* data);
extern void memory_WriteROM_DMA(u32 *dest, u32 *src, u32 size);
extern void memory_WriteROM32(word address, word size, const byte* data);
extern void memory_ClearROM(word address, word size);
extern byte memory_ram[MEMORY_SIZE];
Expand Down
2 changes: 1 addition & 1 deletion arm9/source/emu/ProSystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ ITCM_CODE void prosystem_ExecuteFrame(const byte* input)
// --------------------------------------------------------------------
pokey_Process(1);
pokey_Scanline();
} else tia_Process(isDSiMode() ? 2:1); // If all we have to deal with is the TIA, we can do so at 31KHz unless we are older DS-LITE in which case we run at 15.5KHz
} else tia_Process(2); // If all we have to deal with is the TIA, we can do so at 31KHz
}
}

Expand Down
5 changes: 5 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ Philosophy :
--------------------------------------------------------------------------------
History :
--------------------------------------------------------------------------------
V3.1 : 31-Jan-2022 by wavemotion-dave
* Now using more VRAM for bank swapping and partial DMA transfer to speed up large games.
* Reverted part of the sound core to improve sound quality.
* File selection cleanups to scroll less fast and be generally easier to see.

V3.0 : 06-Nov-2021 by wavemotion-dave
* Reworked sound output core so it's now zinger-free!
* Refresh of bottom screen - improved font and button debounce.
Expand Down

0 comments on commit 639544a

Please sign in to comment.