Skip to content

Commit

Permalink
Version 2.8 - slight sound optmization, slight speed optmization, eli…
Browse files Browse the repository at this point in the history
…mination of the need for DS-LITE version... other cleanups as time permitted.
  • Loading branch information
wavemotion-dave committed Nov 3, 2021
1 parent 02cfa1c commit bc1b557
Show file tree
Hide file tree
Showing 18 changed files with 224 additions and 176 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=2.7
VERSION=2.8
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.
119 changes: 83 additions & 36 deletions arm9/source/a7800utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#include "bgTop.h"
#include "bgFileSel.h"

static unsigned int sound_idx __attribute__((section(".dtcm"))) = 0;
static unsigned int myPokeyBufIdx __attribute__((section(".dtcm"))) = 0;
u8 isDS_LITE __attribute__((section(".dtcm"))) = 0;

static unsigned char lastPokeySample __attribute__((section(".dtcm"))) = 0;
static unsigned char lastTiaSample __attribute__((section(".dtcm"))) = 0;
static unsigned char lastSample __attribute__((section(".dtcm"))) = 0;
Expand All @@ -35,10 +35,10 @@ int bg2;
int bg3; // BG pointers
int bg0s, bg1s, bg2s, bg3s; // sub BG pointers

int full_speed = 0;
u16 full_speed = 0;
int etatEmu;
int gTotalAtariFrames=0;
int fpsDisplay=0;
u16 gTotalAtariFrames=0;
u16 fpsDisplay=0;
int atari_frames = 0;

#define MAX_DEBUG 5
Expand All @@ -56,7 +56,7 @@ short cxBG, cyBG, xdxBG,ydyBG;

unsigned char *filebuffer;

bool bRefreshXY = false;
u8 bRefreshXY = false;

#define WAITVBL swiWaitForVBlank(); swiWaitForVBlank(); swiWaitForVBlank(); swiWaitForVBlank(); swiWaitForVBlank();

Expand Down Expand Up @@ -96,37 +96,48 @@ static void DumpDebugData(void)
#endif
}


u16 myTiaBufIdx __attribute__((section(".dtcm"))) = 0;
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);
void VsoundHandler(void)
{
static unsigned int sound_idx = 0;
extern unsigned char tia_buffer[];
extern int tiaBufIdx;
static int myTiaBufIdx=0;

// If there is a fresh sample...
if (myTiaBufIdx != tiaBufIdx)
extern u16 tiaBufIdx;

for (u8 i=0; i<2; i++)
{
lastSample = tia_buffer[myTiaBufIdx];
myTiaBufIdx = (myTiaBufIdx+1) & (SNDLENGTH-1);
// 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;
}
}
sound_buffer[sound_idx] = lastSample;
sound_idx = (sound_idx+1) & (SNDLENGTH-1);
}

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

// If there is a fresh Pokey sample...
if (myPokeyBufIdx != pokeyBufIdx)
{
lastPokeySample = pokey_buffer[myPokeyBufIdx];
myPokeyBufIdx = (myPokeyBufIdx+1) & (SNDLENGTH-1);
}
sound_buffer[sound_idx] = lastPokeySample;
sound_idx = (sound_idx+1) & (SNDLENGTH-1);
*snd_ptr++ = lastPokeySample;
if (snd_ptr == snd_end)
{
snd_ptr = snd_sta;
}
}


Expand Down Expand Up @@ -205,13 +216,21 @@ void vblankIntr()

void dsInitScreenMain(void)
{
SetYtrigger(192); //trigger 2 lines before vsync
SetYtrigger(190); //trigger 2 lines before vsync
irqSet(IRQ_VBLANK, vblankIntr);
irqEnable(IRQ_VBLANK);

if (isDSiMode()) isDS_LITE = false;
else isDS_LITE = true;

vramSetBankB(VRAM_B_MAIN_BG_0x06020000 ); // Need to do this early so we can steal a bit of this RAM for bank swap...
vramSetBankD(VRAM_D_MAIN_BG_0x06040000 ); // Not using this for video but for cartridge bank swap area... it's faster!
vramSetBankE(VRAM_E_LCD ); // Not using this for video but 64K of faster RAM always useful! Mapped at 0x06880000
vramSetBankD(VRAM_D_LCD ); // Not using this for video but 128K of faster RAM always useful! Mapped at 0x06860000 - Used for Cart Bankswitch
vramSetBankE(VRAM_E_LCD ); // Not using this for video but 64K of faster RAM always useful! Mapped at 0x06880000 - Used for Cart Bankswitch
vramSetBankF(VRAM_F_LCD ); // Not using this for video but 16K of faster RAM always useful! Mapped at 0x06890000 - ..
vramSetBankG(VRAM_G_LCD ); // Not using this for video but 16K of faster RAM always useful! Mapped at 0x06894000 - ..
vramSetBankH(VRAM_H_LCD ); // Not using this for video but 32K of faster RAM always useful! Mapped at 0x06898000 - ..
vramSetBankI(VRAM_I_LCD ); // Not using this for video but 16K of faster RAM always useful! Mapped at 0x068A0000 - ..

}

void dsInitTimer(void)
Expand All @@ -226,7 +245,8 @@ void dsShowScreenEmu(void)
videoSetMode(MODE_5_2D | DISPLAY_BG2_ACTIVE | DISPLAY_BG3_ACTIVE);
vramSetBankA(VRAM_A_MAIN_BG_0x06000000);
vramSetBankB(VRAM_B_MAIN_BG_0x06020000 );
vramSetBankD(VRAM_D_MAIN_BG_0x06040000 ); // Not using this for video but for cartridge bank swap area... it's faster!
vramSetBankD(VRAM_D_LCD ); // Not using this for video but 128K of faster RAM always useful! Mapped at 0x06860000 - Used for Cart Bankswitch
vramSetBankE(VRAM_E_LCD ); // Not using this for video but 64K of faster RAM always useful! Mapped at 0x06880000 - Used for Cart Bankswitch
bg0 = bgInit(3, BgType_Bmp8, BgSize_B8_512x512, 0,0);
bg1 = bgInit(2, BgType_Bmp8, BgSize_B8_512x512, 0,0);

Expand Down Expand Up @@ -360,13 +380,6 @@ void dsLoadGame(char *filename)
GameConf.DS_Pad[14] = 7; GameConf.DS_Pad[15] = 9;

dsInstallSoundEmuFIFO();
TIMER2_DATA = TIMER_FREQ((cartridge_pokey ? SOUND_FREQ:SOUND_FREQ*2));
TIMER2_CR = TIMER_DIV_1 | TIMER_IRQ_REQ | TIMER_ENABLE;
if (cartridge_pokey)
irqSet(IRQ_TIMER2, VsoundHandler_Pokey);
else
irqSet(IRQ_TIMER2, VsoundHandler);
irqEnable(IRQ_TIMER2);

atari_frames = 0;
TIMER0_CR=0;
Expand Down Expand Up @@ -454,7 +467,7 @@ void dsDisplayFiles(unsigned int NoDebGame,u32 ucSel)
dsPrintValue(16-strlen(szName)/2,3,0,szName);
dsPrintValue(31,5,0,(char *) (NoDebGame>0 ? "<" : " "));
dsPrintValue(31,22,0,(char *) (NoDebGame+14<countpro ? ">" : " "));
sprintf(szName,"%s","A TO SELECT A GAME, B TO GO BACK");
sprintf(szName,"%s","A=SELECT, X=NO SOUND, B=BACK");
dsPrintValue(16-strlen(szName)/2,23,0,szName);
for (ucBcl=0;ucBcl<17; ucBcl++)
{
Expand Down Expand Up @@ -590,12 +603,16 @@ unsigned int dsWaitForRom(void)
while (keysCurrent() & KEY_B);
}

if (keysCurrent() & KEY_A) {
if (!proromlist[ucFicAct].directory) {
if (keysCurrent() & (KEY_A | KEY_X))
{
if (!proromlist[ucFicAct].directory)
{
if (keysCurrent() & KEY_X) is_mute = true; else is_mute=false;
bRet=true;
bDone=true;
}
else {
else
{
chdir(proromlist[ucFicAct].filename);
proFindFiles();
ucFicAct = 0;
Expand Down Expand Up @@ -712,9 +729,17 @@ void dsPrintValue(int x, int y, unsigned int isSelect, char *pchStr)
//---------------------------------------------------------------------------------
void dsInstallSoundEmuFIFO(void)
{
memset(sound_buffer, 0x00, SNDLENGTH);
irqDisable(IRQ_TIMER2);

if (is_mute)
{
return; // We've been asked to not install sound...
}

FifoMessage msg;
msg.SoundPlay.data = &sound_buffer;
msg.SoundPlay.freq = (cartridge_pokey ? SOUND_FREQ:SOUND_FREQ*2);
msg.SoundPlay.freq = (cartridge_pokey ? SOUND_FREQ+21:(SOUND_FREQ*2)+21);
msg.SoundPlay.volume = 127;
msg.SoundPlay.pan = 64;
msg.SoundPlay.loop = 1;
Expand All @@ -723,6 +748,27 @@ void dsInstallSoundEmuFIFO(void)
msg.SoundPlay.dataSize = SNDLENGTH >> 2;
msg.type = EMUARM7_PLAY_SND;
fifoSendDatamsg(FIFO_USER_01, sizeof(msg), (u8*)&msg);

if (isDS_LITE)
{
snd_ptr = (u8*)((u32)sound_buffer + 0x00400000);
snd_sta = (u8*)((u32)sound_buffer + 0x00400000);
snd_end = (u8*)((u32)sound_buffer + 0x00400000 + SNDLENGTH);
}
else
{
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);
TIMER2_CR = TIMER_DIV_1 | TIMER_IRQ_REQ | TIMER_ENABLE;
if (cartridge_pokey)
irqSet(IRQ_TIMER2, VsoundHandler_Pokey);
else
irqSet(IRQ_TIMER2, VsoundHandler);
irqEnable(IRQ_TIMER2);
}

void dsMainLoop(void)
Expand Down Expand Up @@ -933,6 +979,7 @@ void dsMainLoop(void)
if (fpsDisplay)
{
int fps = gTotalAtariFrames;
if (fps == 61) fps=60;
gTotalAtariFrames = 0;
fpsbuf[0] = '0' + (int)fps/100;
fps = fps % 100;
Expand Down
30 changes: 15 additions & 15 deletions arm9/source/emu/Cartridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,24 @@ char cartridge_year[128];
char cartridge_maker[128];
byte cartridge_digest[128];
char cartridge_filename[128];
byte cartridge_type;
byte cartridge_region;
byte cartridge_pokey;
byte cartridge_type __attribute__((section(".dtcm")));
byte cartridge_region __attribute__((section(".dtcm")));
byte cartridge_pokey __attribute__((section(".dtcm")));
bool cartridge_hsc_enabled;
byte cartridge_controller[2];
byte cartridge_bank;
bool cartridge_steals_cycles;
bool cartridge_uses_wsync;
int cartridge_xOffset = 0;
int cartridge_yOffset = 22;
int cartridge_xScale = 256;
int cartridge_yScale = 220;
byte cartridge_bank __attribute__((section(".dtcm")));
bool cartridge_steals_cycles __attribute__((section(".dtcm")));
bool cartridge_uses_wsync __attribute__((section(".dtcm")));
short cartridge_xOffset = 0;
short cartridge_yOffset = 22;
short cartridge_xScale = 256;
short cartridge_yScale = 220;
uint cartridge_diff1 = DIFF_A;
uint cartridge_diff2 = DIFF_A;

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

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -94,7 +94,7 @@ 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, cartridge_buffer + offset);
memory_WriteROMFast(address, (16384/4), cartridge_buffer + offset);
cartridge_bank = bank;
}
}
Expand Down Expand Up @@ -212,7 +212,7 @@ static bool _cartridge_Load(const byte* data, uint size)
}

if (cartridge_size <= (144 * 1024))
cartridge_buffer = (byte *) 0x0603C000; // If smaller than 144k (98% of all carts are), we can use the VRAM buffer since it's faster to move stuff around...
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
for(index = 0; index < cartridge_size; index++) {
Expand Down Expand Up @@ -411,7 +411,7 @@ void cartridge_Release( )
// Snap out the High Score SRAM (if used)
cartridge_SaveHighScoreSram();

if ((u32)cartridge_buffer != 0x0603C000)
if ((u32)cartridge_buffer != 0x06860000)
{
free(cartridge_buffer);
}
Expand Down
8 changes: 4 additions & 4 deletions arm9/source/emu/Cartridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ extern byte cartridge_pokey;
extern bool cartridge_hsc_enabled;
extern byte cartridge_controller[2];
extern byte cartridge_bank;
extern int cartridge_xOffset;
extern int cartridge_yOffset;
extern int cartridge_xScale;
extern int cartridge_yScale;
extern short cartridge_xOffset;
extern short cartridge_yOffset;
extern short cartridge_xScale;
extern short cartridge_yScale;
extern bool cartridge_steals_cycles;
extern bool cartridge_uses_wsync;
extern uint cartridge_diff1;
Expand Down
Loading

0 comments on commit bc1b557

Please sign in to comment.