Merge pull request #2455 from aliaspider/master

(3DS) update.
This commit is contained in:
Twinaphex 2015-11-24 11:36:00 +01:00
commit 0958acd0b1
8 changed files with 94 additions and 149 deletions

View File

@ -7,6 +7,7 @@ WHOLE_ARCHIVE_LINK = 0
BUILD_3DSX = 1
BUILD_3DS = 1
BUILD_CIA = 1
LIBCTRU_NO_DEPRECATION = 1
APP_TITLE = Retroarch 3DS
APP_DESCRIPTION = Retroarch 3DS
@ -278,6 +279,10 @@ else
CFLAGS += -O3
endif
ifeq ($(LIBCTRU_NO_DEPRECATION), 1)
CFLAGS += -DLIBCTRU_NO_DEPRECATION
endif
ifeq ($(WHOLE_ARCHIVE_LINK), 1)
WHOLE_START := -Wl,--whole-archive
WHOLE_END := -Wl,--no-whole-archive

View File

@ -122,8 +122,8 @@ static void *ctr_csnd_audio_init(const char *device, unsigned rate, unsigned lat
ctr->pos = 0;
GSPGPU_FlushDataCache(ctr->l_paddr, CTR_CSND_AUDIO_SIZE);
GSPGPU_FlushDataCache(ctr->r_paddr, CTR_CSND_AUDIO_SIZE);
GSPGPU_FlushDataCache((void*)ctr->l_paddr, CTR_CSND_AUDIO_SIZE);
GSPGPU_FlushDataCache((void*)ctr->r_paddr, CTR_CSND_AUDIO_SIZE);
csndPlaySound_custom(0x8, SOUND_LOOPMODE(CSND_LOOPMODE_NORMAL)| SOUND_FORMAT(CSND_ENCODING_PCM16),
1.0, -1.0, ctr->l, ctr->l, CTR_CSND_AUDIO_SIZE);

View File

@ -18,21 +18,16 @@
#include "../audio_driver.h"
#include "../../configuration.h"
#include "../../performance.h"
#define CTR_DSP_BUFFERS_COUNT (1u << 4u)
#define CTR_DSP_BUFFERS_MASK (CTR_DSP_BUFFERS_COUNT - 1)
#include "../../ctr/ctr_debug.h"
typedef struct
{
bool nonblocking;
bool playing;
int channel;
ndspWaveBuf dsp_buf[CTR_DSP_BUFFERS_COUNT];
uint32_t dsp_buf_id;
uint8_t* linear_buffer;
ndspWaveBuf dsp_buf;
uint32_t pos;
} ctr_dsp_audio_t;
#define CTR_DSP_AUDIO_COUNT (1u << 11u)
@ -40,48 +35,6 @@ typedef struct
#define CTR_DSP_AUDIO_SIZE (CTR_DSP_AUDIO_COUNT * sizeof(int16_t) * 2)
#define CTR_DSP_AUDIO_SIZE_MASK (CTR_DSP_AUDIO_SIZE - 1u)
#ifndef DEBUG_HOLD
void wait_for_input(void);
#define PRINTFPOS(X,Y) "\x1b["#X";"#Y"H"
#define DEBUG_HOLD() do{printf("%s@%s:%d.\n",__FUNCTION__, __FILE__, __LINE__);fflush(stdout);wait_for_input();}while(0)
#define DEBUG_VAR(X) printf( "%-20s: 0x%08X\n", #X, (u32)(X))
#define DEBUG_VAR64(X) printf( #X"\r\t\t\t\t : 0x%016llX\n", (u64)(X))
#endif
static uint32_t ctr_get_queued_samples(ctr_dsp_audio_t* ctr)
{
uint32_t sample_pos, sample_count;
uint16_t buf_seq;
buf_seq = ndspChnGetWaveBufSeq(ctr->channel);
if(!buf_seq)
return 0;
sample_pos = ndspChnGetSamplePos(ctr->channel);
sample_count = 0;
int buf_id = ctr->dsp_buf_id;
do
{
buf_id++;
buf_id&= CTR_DSP_BUFFERS_MASK;
}
while(ctr->dsp_buf[buf_id].sequence_id != buf_seq);
ndspWaveBuf* current = &ctr->dsp_buf[buf_id];
sample_count = current->nsamples - sample_pos;
while((current = current->next))
{
sample_count += current->nsamples;
}
return sample_count;
}
static void *ctr_dsp_audio_init(const char *device, unsigned rate, unsigned latency)
{
ctr_dsp_audio_t *ctr;
@ -99,34 +52,32 @@ static void *ctr_dsp_audio_init(const char *device, unsigned rate, unsigned late
if (!ctr)
return NULL;
// memset(ctr, 0, sizeof(*ctr));
settings->audio.out_rate = 32730;
ctr->channel = 0;
ctr->dsp_buf_id = 0;
ndspSetOutputMode(NDSP_OUTPUT_STEREO);
ndspSetClippingMode(NDSP_CLIP_SOFT); //??
// ndspSetClippingMode(NDSP_CLIP_NORMAL); //??
ndspSetOutputCount(CTR_DSP_BUFFERS_COUNT);
ndspSetOutputCount(1);
ndspChnReset(ctr->channel);
// ndspChnInitParams(ctr->channel);
ndspChnSetFormat(ctr->channel, NDSP_FORMAT_STEREO_PCM16);
ndspChnSetInterp(ctr->channel, NDSP_INTERP_NONE);
// ndspChnSetInterp(ctr->channel, NDSP_INTERP_LINEAR);
// ndspChnSetInterp(ctr->channel, NDSP_INTERP_POLYPHASE);
ndspChnSetRate(ctr->channel, 32728.0f);
// ndspChnSetRate(ctr->channel, CTR_DSP_AUDIO_RATE);
// ndspChnSetRate(ctr->channel, 0x7F00);
// ndspChnSetMix(ctr->channel, (float[12]){1.0, 1.0, 0.0});
ndspChnWaveBufClear(ctr->channel);
ctr->linear_buffer = linearAlloc(CTR_DSP_BUFFERS_COUNT * CTR_DSP_AUDIO_SIZE);
ctr->dsp_buf.data_pcm16 = linearAlloc(CTR_DSP_AUDIO_SIZE);
memset(ctr->dsp_buf.data_pcm16, 0, CTR_DSP_AUDIO_SIZE);
DSP_FlushDataCache(ctr->dsp_buf.data_pcm16, CTR_DSP_AUDIO_SIZE);
int i;
for (i = 0; i < CTR_DSP_BUFFERS_COUNT; i++)
ctr->dsp_buf[i].data_pcm16 = (uint16_t*)(ctr->linear_buffer + i * CTR_DSP_AUDIO_SIZE);
ctr->dsp_buf.looping = true;
ctr->dsp_buf.nsamples = CTR_DSP_AUDIO_COUNT;
ndspChnWaveBufAdd(ctr->channel, &ctr->dsp_buf);
ctr->pos = 0;
ctr->playing = true;
ndspSetMasterVol(1.0);
return ctr;
}
@ -134,8 +85,8 @@ static void *ctr_dsp_audio_init(const char *device, unsigned rate, unsigned late
static void ctr_dsp_audio_free(void *data)
{
ctr_dsp_audio_t* ctr = (ctr_dsp_audio_t*)data;
linearFree(ctr->linear_buffer);
ndspChnWaveBufClear(ctr->channel);
linearFree(ctr->dsp_buf.data_pcm16);
free(ctr);
ndspExit();
}
@ -144,61 +95,51 @@ static ssize_t ctr_dsp_audio_write(void *data, const void *buf, size_t size)
{
static struct retro_perf_counter ctraudio_dsp_f = {0};
ctr_dsp_audio_t* ctr = (ctr_dsp_audio_t*)data;
u32 pos;
uint32_t sample_pos = ndspChnGetSamplePos(ctr->channel);
ndspWaveBuf* current_buf = &ctr->dsp_buf[ctr->dsp_buf_id];
static int dropped=0;
uint32_t queued = ctr_get_queued_samples(ctr);
if(size > CTR_DSP_AUDIO_SIZE)
if((((sample_pos - ctr->pos) & CTR_DSP_AUDIO_COUNT_MASK) < (CTR_DSP_AUDIO_COUNT >> 2)) ||
(((ctr->pos - sample_pos ) & CTR_DSP_AUDIO_COUNT_MASK) < (CTR_DSP_AUDIO_COUNT >> 4)) ||
(((sample_pos - ctr->pos) & CTR_DSP_AUDIO_COUNT_MASK) < (size >> 2)))
{
DEBUG_VAR(size);
ctr_dsp_audio_write(ctr, buf, CTR_DSP_AUDIO_SIZE);
buf = (const void*)((u32)buf + CTR_DSP_AUDIO_SIZE);
size = size - CTR_DSP_AUDIO_SIZE;
}
dropped++;
if(ctr->nonblocking)
{
if((current_buf->status == NDSP_WBUF_QUEUED) || (current_buf->status == NDSP_WBUF_PLAYING))
return size;
if((queued + (size>>2)) > 0x2000)
return size;
}
if (ctr->nonblocking)
ctr->pos = (sample_pos + (CTR_DSP_AUDIO_COUNT >> 1)) & CTR_DSP_AUDIO_COUNT_MASK;
else
{
if(queued > (0x1000 + (size>>2)))
{
// printf(PRINTFPOS(24,0)"queued :0x%08X \n", ctr_get_queued_samples(ctr));
while(ctr_get_queued_samples(ctr) > 160 )
do{
svcSleepThread(100000);
sample_pos = ndspChnGetSamplePos(ctr->channel);
}while (((sample_pos - (ctr->pos + size >>2)) & CTR_DSP_AUDIO_COUNT_MASK) > (CTR_DSP_AUDIO_COUNT >> 1)
|| (((ctr->pos - (CTR_DSP_AUDIO_COUNT >> 4) - sample_pos) & CTR_DSP_AUDIO_COUNT_MASK) > (CTR_DSP_AUDIO_COUNT >> 1)));
}
}
dropped--;
rarch_perf_init(&ctraudio_dsp_f, "ctraudio_dsp_f");
retro_perf_start(&ctraudio_dsp_f);
memcpy(current_buf->data_pcm16, buf, size);
current_buf->nsamples = size>>2;
pos = ctr->pos << 2;
DSP_FlushDataCache(current_buf->data_pcm16, size);
DSP_FlushDataCache(ctr->dsp_buf, sizeof(ctr->dsp_buf));
gfxFlushBuffers();
if((pos + size) > CTR_DSP_AUDIO_SIZE)
{
memcpy(ctr->dsp_buf.data_pcm8 + pos, buf,
(CTR_DSP_AUDIO_SIZE - pos));
DSP_FlushDataCache(ctr->dsp_buf.data_pcm8 + pos, (CTR_DSP_AUDIO_SIZE - pos));
memcpy(ctr->dsp_buf.data_pcm8, (uint8_t*) buf + (CTR_DSP_AUDIO_SIZE - pos),
(pos + size - CTR_DSP_AUDIO_SIZE));
DSP_FlushDataCache(ctr->dsp_buf.data_pcm8, (pos + size - CTR_DSP_AUDIO_SIZE));
}
else
{
memcpy(ctr->dsp_buf.data_pcm8 + pos, buf, size);
DSP_FlushDataCache(ctr->dsp_buf.data_pcm8 + pos, size);
}
ctr->pos += size >> 2;
ctr->pos &= CTR_DSP_AUDIO_COUNT_MASK;
ndspChnWaveBufAdd(ctr->channel, current_buf);
retro_perf_stop(&ctraudio_dsp_f);
// printf(PRINTFPOS(25,0)"dropped:0x%08X queued :0x%08X \n", dropped, queued);
// printf(PRINTFPOS(26,0)"current:0x%08X nsamples:0x%08X \n", ctr->dsp_buf_id, current_buf->nsamples);
// printf(PRINTFPOS(27,0)"dropped:0x%08X count :0x%08X \n", ndspGetDroppedFrames(), ndspGetFrameCount());
// printf(PRINTFPOS(28,0)"Pos :0x%08X Seq :0x%08X \n", ndspChnGetSamplePos(ctr->channel), ndspChnGetWaveBufSeq(ctr->channel));
ctr->dsp_buf_id++;
ctr->dsp_buf_id &= CTR_DSP_BUFFERS_MASK;
return size;
}
@ -206,12 +147,8 @@ static bool ctr_dsp_audio_stop(void *data)
{
ctr_dsp_audio_t* ctr = (ctr_dsp_audio_t*)data;
ndspChnWaveBufClear(ctr->channel);
ndspSetMasterVol(0.0);
ctr->playing = false;
int i;
memset(ctr->dsp_buf, 0, sizeof(ctr->dsp_buf));
for (i = 0; i < CTR_DSP_BUFFERS_COUNT; i++)
ctr->dsp_buf[i].data_pcm16 = (uint16_t*)(ctr->linear_buffer + i * CTR_DSP_AUDIO_SIZE);
return true;
}
@ -233,6 +170,7 @@ static bool ctr_dsp_audio_start(void *data)
if (system->shutdown)
return true;
ndspSetMasterVol(1.0);
ctr->playing = true;
return true;
@ -254,15 +192,14 @@ static bool ctr_dsp_audio_use_float(void *data)
static size_t ctr_dsp_audio_write_avail(void *data)
{
ctr_dsp_audio_t* ctr = (ctr_dsp_audio_t*)data;
uint32_t queued_samples = ctr_get_queued_samples(ctr);
return queued_samples < 0x1000 ? 0x1000 - queued_samples : 0;
return (ndspChnGetSamplePos(ctr->channel) - ctr->pos) & CTR_DSP_AUDIO_COUNT_MASK;
}
static size_t ctr_dsp_audio_buffer_size(void *data)
{
(void)data;
return 0x1000;
return CTR_DSP_AUDIO_COUNT;
}

View File

@ -13,6 +13,7 @@ void dump_result_value(Result val);
#endif
#define DEBUG_HOLD() do{printf("%s@%s:%d.\n",__FUNCTION__, __FILE__, __LINE__);fflush(stdout);wait_for_input();}while(0)
#define DEBUG_LINE() do{printf("%s:%d.\n",__FUNCTION__, __LINE__);fflush(stdout);}while(0)
#define DEBUG_STR(X) printf( "%s: %s\n", #X, (char*)(X))
#define DEBUG_VAR(X) printf( "%-20s: 0x%08X\n", #X, (u32)(X))
#define DEBUG_VAR64(X) printf( #X"\r\t\t\t\t : 0x%016llX\n", (u64)(X))

View File

@ -4,16 +4,16 @@
static void svchax_gspwn(u32 dst, u32 src, u32 size, u8* flush_buffer)
{
extern Handle gspEvents[GSPEVENT_MAX];
extern Handle gspEvents[GSPGPU_EVENT_MAX];
memcpy(flush_buffer, flush_buffer + 0x4000, 0x4000);
GSPGPU_InvalidateDataCache(dst, size);
GSPGPU_FlushDataCache(src, size);
GSPGPU_InvalidateDataCache((void*)dst, size);
GSPGPU_FlushDataCache((void*)src, size);
memcpy(flush_buffer, flush_buffer + 0x4000, 0x4000);
svcClearEvent(gspEvents[GSPEVENT_PPF]);
GX_TextureCopy(src, 0, dst, 0, size, 8);
svcWaitSynchronization(gspEvents[GSPEVENT_PPF], U64_MAX);
svcClearEvent(gspEvents[GSPGPU_EVENT_PPF]);
GX_TextureCopy((void*)src, 0, (void*)dst, 0, size, 8);
svcWaitSynchronization(gspEvents[GSPGPU_EVENT_PPF], U64_MAX);
memcpy(flush_buffer, flush_buffer + 0x4000, 0x4000);
}
@ -123,7 +123,7 @@ u32 __ctr_svchax = 0;
void svchax_init(void)
{
extern u32 __service_ptr;
extern void* __service_ptr;
if (__ctr_svchax)
return;

View File

@ -21,7 +21,7 @@ extern u32 __heap_size_hbl;
extern void (*__system_retAddr)(void);
void __destroy_handle_list(void);
void envDestroyHandles(void);
void __appExit();
void __libc_fini_array(void);
@ -111,7 +111,7 @@ void __attribute__((noreturn)) __libctru_exit(int rc)
svcControlMemory(&tmp, __stack_bottom, 0x0, __stack_size_extra, MEMOP_FREE, 0x0);
// Close some handles
__destroy_handle_list();
envDestroyHandles();
if (__sync_fini)
__sync_fini();

View File

@ -215,7 +215,7 @@ static void ctr_update_viewport(ctr_video_t* ctr)
}
static void ctr_lcd_aptHook(int hook, void* param)
static void ctr_lcd_aptHook(APT_HookType hook, void* param)
{
ctr_video_t *ctr = (ctr_video_t*)param;
if(!ctr)
@ -356,7 +356,7 @@ static void* ctr_init(const video_info_t* video,
sizeof(ctr_vertex_t));
GPUCMD_Finalize();
ctrGuFlushAndRun(true);
gspWaitForEvent(GSPEVENT_P3D, false);
gspWaitForEvent(GSPGPU_EVENT_P3D, false);
if (input && input_data)
{
@ -401,7 +401,7 @@ static bool ctr_frame(void* data, const void* frame,
if (!width || !height)
{
gspWaitForEvent(GSPEVENT_VBlank0, true);
gspWaitForEvent(GSPGPU_EVENT_VBlank0, true);
return true;
}
@ -441,17 +441,17 @@ static bool ctr_frame(void* data, const void* frame,
ctr->lcd_buttom_on = !ctr->lcd_buttom_on;
}
svcWaitSynchronization(gspEvents[GSPEVENT_P3D], 20000000);
svcClearEvent(gspEvents[GSPEVENT_P3D]);
svcWaitSynchronization(gspEvents[GSPEVENT_PPF], 20000000);
svcClearEvent(gspEvents[GSPEVENT_PPF]);
svcWaitSynchronization(gspEvents[GSPGPU_EVENT_P3D], 20000000);
svcClearEvent(gspEvents[GSPGPU_EVENT_P3D]);
svcWaitSynchronization(gspEvents[GSPGPU_EVENT_PPF], 20000000);
svcClearEvent(gspEvents[GSPGPU_EVENT_PPF]);
frames++;
if (ctr->vsync)
svcWaitSynchronization(gspEvents[GSPEVENT_VBlank0], U64_MAX);
svcWaitSynchronization(gspEvents[GSPGPU_EVENT_VBlank0], U64_MAX);
svcClearEvent(gspEvents[GSPEVENT_VBlank0]);
svcClearEvent(gspEvents[GSPGPU_EVENT_VBlank0]);
currentTick = svcGetSystemTick();
diff = currentTick - lastTick;
@ -541,7 +541,9 @@ static bool ctr_frame(void* data, const void* frame,
&& (pitch > 0x40))
{
/* can copy the buffer directly with the GPU */
ctrGuCopyImage(false, frame, pitch / (ctr->rgb32? 4: 2), height, ctr->rgb32 ? CTRGU_RGBA8: CTRGU_RGB565, false,
// GSPGPU_FlushDataCache(frame, pitch * height);
ctrGuSetCommandList_First(true,frame, pitch * height,0,0,0,0);
ctrGuCopyImage(true, frame, pitch / (ctr->rgb32? 4: 2), height, ctr->rgb32 ? CTRGU_RGBA8: CTRGU_RGB565, false,
ctr->texture_swizzled, ctr->texture_width, ctr->rgb32 ? CTRGU_RGBA8: CTRGU_RGB565, true);
}
else

View File

@ -61,7 +61,7 @@ void wait_for_input(void);
#endif
extern Handle gspEvents[GSPEVENT_MAX];
extern Handle gspEvents[GSPGPU_EVENT_MAX];
extern u32* gpuCmdBuf;
extern u32 gpuCmdBufOffset;
extern u32 __linear_heap_size;
@ -109,7 +109,7 @@ static INLINE Result ctrGuSetCommandList_First(bool queued, u32* buf0a, u32 buf0
gxCommand[6]=(u32)buf2s; //buf2 size
gxCommand[7]=0x0;
return GSPGPU_SubmitGxCommand(gxCmdBuf, gxCommand);
return gspSubmitGxCommand(gxCmdBuf, gxCommand);
}
__attribute__((always_inline))
@ -123,7 +123,7 @@ static INLINE Result ctrGuSetCommandList_Last(bool queued, u32* buf0a, u32 buf0s
gxCommand[4]=gxCommand[5]=gxCommand[6]=0x0;
gxCommand[7]=(flags>>1)&1; //when non-zero, call svcFlushProcessDataCache() with the specified buffer
return GSPGPU_SubmitGxCommand(gxCmdBuf, gxCommand);
return gspSubmitGxCommand(gxCmdBuf, gxCommand);
}
__attribute__((always_inline))
@ -147,7 +147,7 @@ static INLINE Result ctrGuSetMemoryFill(bool queued, u32* buf0a, u32 buf0v, u32*
gxCommand[6]=(u32)buf1e; //buf1 end addr
gxCommand[7]=(width0)|(width1<<16);
return GSPGPU_SubmitGxCommand(gxCmdBuf, gxCommand);
return gspSubmitGxCommand(gxCmdBuf, gxCommand);
}
__attribute__((always_inline))
@ -169,7 +169,7 @@ static INLINE Result ctrGuCopyImage
| ((dst_w > src_w) ? CTRGU_DMA_TRUNCATE : 0);
gxCommand[6]=gxCommand[7]=0x0;
return GSPGPU_SubmitGxCommand(gxCmdBuf, gxCommand);
return gspSubmitGxCommand(gxCmdBuf, gxCommand);
}
@ -188,7 +188,7 @@ static INLINE Result ctrGuDisplayTransfer
gxCommand[5]=(src_fmt << 8) | (dst_fmt << 12) | multisample_lvl;
gxCommand[6]=gxCommand[7]=0x0;
return GSPGPU_SubmitGxCommand(gxCmdBuf, gxCommand);
return gspSubmitGxCommand(gxCmdBuf, gxCommand);
}