From 10c7711ce5526617ff1778fcd8cbcdd921807dac Mon Sep 17 00:00:00 2001 From: fincs Date: Fri, 20 Nov 2015 17:24:02 +0100 Subject: [PATCH] Correct osConvertVirtToPhys/osConvertOldLINEARMemToNew parameter type --- examples/graphics/gpu/geoshader/source/gpu.c | 4 ++-- examples/graphics/gpu/geoshader/source/main.c | 2 +- examples/graphics/gpu/simple_tri/source/gpu.c | 4 ++-- examples/graphics/gpu/textured_cube/source/gpu.c | 4 ++-- examples/graphics/gpu/textured_cube/source/main.c | 4 ++-- libctru/include/3ds/ndsp/ndsp.h | 8 ++++---- libctru/include/3ds/os.h | 6 +++--- libctru/source/os.c | 10 ++++++---- libctru/source/services/csnd.c | 4 ++-- libctru/source/services/mvd.c | 8 ++++---- 10 files changed, 28 insertions(+), 26 deletions(-) diff --git a/examples/graphics/gpu/geoshader/source/gpu.c b/examples/graphics/gpu/geoshader/source/gpu.c index f950130..d16f1ff 100644 --- a/examples/graphics/gpu/geoshader/source/gpu.c +++ b/examples/graphics/gpu/geoshader/source/gpu.c @@ -37,8 +37,8 @@ void gpuFrameBegin(void) { // Configure the viewport and the depth linear conversion function GPU_SetViewport( - (u32*)osConvertVirtToPhys((u32)depthBuf), - (u32*)osConvertVirtToPhys((u32)colorBuf), + (u32*)osConvertVirtToPhys(depthBuf), + (u32*)osConvertVirtToPhys(colorBuf), 0, 0, 240, 400); // The top screen is physically 240x400 pixels GPU_DepthMap(-1.0f, 0.0f); // calculate the depth value from the Z coordinate in the following way: -1.0*z + 0.0 diff --git a/examples/graphics/gpu/geoshader/source/main.c b/examples/graphics/gpu/geoshader/source/main.c index 421e6e8..83501e2 100644 --- a/examples/graphics/gpu/geoshader/source/main.c +++ b/examples/graphics/gpu/geoshader/source/main.c @@ -69,7 +69,7 @@ static void sceneRender(void) // Configure the "attribute buffers" (that is, the vertex input buffers) GPU_SetAttributeBuffers( 2, // Number of inputs per vertex - (u32*)osConvertVirtToPhys((u32)vbo_data), // Location of the VBO + (u32*)osConvertVirtToPhys(vbo_data), // Location of the VBO GPU_ATTRIBFMT(0, 3, GPU_FLOAT) | GPU_ATTRIBFMT(1, 4, GPU_FLOAT), // Format of the inputs (in this case the only input is a 3-element float vector) 0xFFC, // Unused attribute mask, in our case bit 0 is cleared since it is used diff --git a/examples/graphics/gpu/simple_tri/source/gpu.c b/examples/graphics/gpu/simple_tri/source/gpu.c index f950130..d16f1ff 100644 --- a/examples/graphics/gpu/simple_tri/source/gpu.c +++ b/examples/graphics/gpu/simple_tri/source/gpu.c @@ -37,8 +37,8 @@ void gpuFrameBegin(void) { // Configure the viewport and the depth linear conversion function GPU_SetViewport( - (u32*)osConvertVirtToPhys((u32)depthBuf), - (u32*)osConvertVirtToPhys((u32)colorBuf), + (u32*)osConvertVirtToPhys(depthBuf), + (u32*)osConvertVirtToPhys(colorBuf), 0, 0, 240, 400); // The top screen is physically 240x400 pixels GPU_DepthMap(-1.0f, 0.0f); // calculate the depth value from the Z coordinate in the following way: -1.0*z + 0.0 diff --git a/examples/graphics/gpu/textured_cube/source/gpu.c b/examples/graphics/gpu/textured_cube/source/gpu.c index f950130..d16f1ff 100644 --- a/examples/graphics/gpu/textured_cube/source/gpu.c +++ b/examples/graphics/gpu/textured_cube/source/gpu.c @@ -37,8 +37,8 @@ void gpuFrameBegin(void) { // Configure the viewport and the depth linear conversion function GPU_SetViewport( - (u32*)osConvertVirtToPhys((u32)depthBuf), - (u32*)osConvertVirtToPhys((u32)colorBuf), + (u32*)osConvertVirtToPhys(depthBuf), + (u32*)osConvertVirtToPhys(colorBuf), 0, 0, 240, 400); // The top screen is physically 240x400 pixels GPU_DepthMap(-1.0f, 0.0f); // calculate the depth value from the Z coordinate in the following way: -1.0*z + 0.0 diff --git a/examples/graphics/gpu/textured_cube/source/main.c b/examples/graphics/gpu/textured_cube/source/main.c index f4e13a1..1e9687c 100644 --- a/examples/graphics/gpu/textured_cube/source/main.c +++ b/examples/graphics/gpu/textured_cube/source/main.c @@ -145,7 +145,7 @@ static void sceneRender(void) GPU_SetTextureEnable(GPU_TEXUNIT0); GPU_SetTexture( GPU_TEXUNIT0, - (u32*)osConvertVirtToPhys((u32)tex_data), + (u32*)osConvertVirtToPhys(tex_data), 64, // Width 64, // Height GPU_TEXTURE_MAG_FILTER(GPU_LINEAR) | GPU_TEXTURE_WRAP_S(GPU_REPEAT) | GPU_TEXTURE_WRAP_T(GPU_REPEAT), // Flags @@ -155,7 +155,7 @@ static void sceneRender(void) // Configure the "attribute buffers" (that is, the vertex input buffers) GPU_SetAttributeBuffers( 3, // Number of inputs per vertex - (u32*)osConvertVirtToPhys((u32)vbo_data), // Location of the VBO + (u32*)osConvertVirtToPhys(vbo_data), // Location of the VBO GPU_ATTRIBFMT(0, 3, GPU_FLOAT) | // Format of the inputs GPU_ATTRIBFMT(1, 2, GPU_FLOAT) | GPU_ATTRIBFMT(2, 3, GPU_FLOAT), diff --git a/libctru/include/3ds/ndsp/ndsp.h b/libctru/include/3ds/ndsp/ndsp.h index 582d1d7..1a8c748 100644 --- a/libctru/include/3ds/ndsp/ndsp.h +++ b/libctru/include/3ds/ndsp/ndsp.h @@ -54,10 +54,10 @@ struct tag_ndspWaveBuf { union { - s8* data_pcm8; ///< Pointer to PCM8 sample data. - s16* data_pcm16; ///< Pointer to PCM16 sample data. - u8* data_adpcm; ///< Pointer to DSPADPCM sample data. - u32 data_vaddr; ///< Data virtual address. + s8* data_pcm8; ///< Pointer to PCM8 sample data. + s16* data_pcm16; ///< Pointer to PCM16 sample data. + u8* data_adpcm; ///< Pointer to DSPADPCM sample data. + void* data_vaddr; ///< Data virtual address. }; u32 nsamples; ///< Total number of samples (PCM8=bytes, PCM16=halfwords, DSPADPCM=nibbles without frame headers) ndspAdpcmData* adpcm_data; ///< ADPCM data. diff --git a/libctru/include/3ds/os.h b/libctru/include/3ds/os.h index 03004a5..34b4754 100644 --- a/libctru/include/3ds/os.h +++ b/libctru/include/3ds/os.h @@ -34,14 +34,14 @@ typedef struct * @return The corresponding physical address. * It is sometimes required by services or when using the GPU command buffer. */ -u32 osConvertVirtToPhys(u32 vaddr); +u32 osConvertVirtToPhys(const void* vaddr); /** * @brief Converts 0x14* vmem to 0x30*. - * @param addr Input address. + * @param vaddr Input virtual address. * @return The corresponding address in the 0x30* range, the input address if it's already within the new vmem, or 0 if it's outside of both ranges. */ -u32 osConvertOldLINEARMemToNew(u32 addr); +void* osConvertOldLINEARMemToNew(const void* vaddr); /** * @brief Retrieves basic information about a service error. diff --git a/libctru/source/os.c b/libctru/source/os.c index e09b6a8..8bbc0cc 100644 --- a/libctru/source/os.c +++ b/libctru/source/os.c @@ -28,8 +28,9 @@ typedef struct { __attribute__((weak)) bool __ctru_speedup = false; //--------------------------------------------------------------------------------- -u32 osConvertVirtToPhys(u32 vaddr) { +u32 osConvertVirtToPhys(const void* addr) { //--------------------------------------------------------------------------------- + u32 vaddr = (u32)addr; if(vaddr >= 0x14000000 && vaddr < 0x1c000000) return vaddr + 0x0c000000; // LINEAR heap if(vaddr >= 0x1F000000 && vaddr < 0x1F600000) @@ -42,10 +43,11 @@ u32 osConvertVirtToPhys(u32 vaddr) { } //--------------------------------------------------------------------------------- -u32 osConvertOldLINEARMemToNew(u32 vaddr) { +void* osConvertOldLINEARMemToNew(const void* addr) { //--------------------------------------------------------------------------------- - if(vaddr >= 0x30000000 && vaddr < 0x40000000)return vaddr; - if(vaddr >= 0x14000000 && vaddr < 0x1c000000)return vaddr+=0x1c000000; + u32 vaddr = (u32)addr; + if(vaddr >= 0x30000000 && vaddr < 0x40000000)return (void*)vaddr; + if(vaddr >= 0x14000000 && vaddr < 0x1c000000)return (void*)(vaddr+0x1c000000); return 0; } diff --git a/libctru/source/services/csnd.c b/libctru/source/services/csnd.c index 4727d64..ce00c8b 100644 --- a/libctru/source/services/csnd.c +++ b/libctru/source/services/csnd.c @@ -524,8 +524,8 @@ Result csndPlaySound(int chn, u32 flags, u32 sampleRate, float vol, float pan, v if (encoding != CSND_ENCODING_PSG) { - if (data0) paddr0 = osConvertVirtToPhys((u32)data0); - if (data1) paddr1 = osConvertVirtToPhys((u32)data1); + if (data0) paddr0 = osConvertVirtToPhys(data0); + if (data1) paddr1 = osConvertVirtToPhys(data1); if (data0 && encoding == CSND_ENCODING_ADPCM) { diff --git a/libctru/source/services/mvd.c b/libctru/source/services/mvd.c index fbf05af..06f0d31 100644 --- a/libctru/source/services/mvd.c +++ b/libctru/source/services/mvd.c @@ -117,7 +117,7 @@ Result mvdstdInit(MVDSTD_Mode mode, MVDSTD_InputFormat input_type, MVDSTD_Output mvdstd_workbuf = linearAlloc(mvdstd_workbufsize); if(mvdstd_workbuf==NULL) goto cleanup1; - ret = MVDSTD_Initialize((u32*) osConvertOldLINEARMemToNew((u32) mvdstd_workbuf), mvdstd_workbufsize); + ret = MVDSTD_Initialize((u32*) osConvertOldLINEARMemToNew(mvdstd_workbuf), mvdstd_workbufsize); if(R_FAILED(ret)) goto cleanup2; ret = MVDSTD_cmd18(); @@ -161,7 +161,7 @@ void mvdstdGenerateDefaultConfig(MVDSTD_Config*config, u32 input_width, u32 inpu config->inwidth = input_width; config->inheight = input_height; - if(mvdstd_mode==MVDMODE_COLORFORMATCONV)config->physaddr_colorconv_indata = osConvertVirtToPhys((u32)vaddr_colorconv_indata); + if(mvdstd_mode==MVDMODE_COLORFORMATCONV)config->physaddr_colorconv_indata = osConvertVirtToPhys(vaddr_colorconv_indata); if(mvdstd_mode==MVDMODE_VIDEOPROCESSING) { @@ -175,8 +175,8 @@ void mvdstdGenerateDefaultConfig(MVDSTD_Config*config, u32 input_width, u32 inpu config->outwidth1 = output_width; config->outheight1 = output_height; - config->physaddr_outdata0 = osConvertVirtToPhys((u32)vaddr_outdata0); - if(mvdstd_mode==MVDMODE_COLORFORMATCONV)config->physaddr_outdata1_colorconv = osConvertVirtToPhys((u32)vaddr_outdata1_colorconv); + config->physaddr_outdata0 = osConvertVirtToPhys(vaddr_outdata0); + if(mvdstd_mode==MVDMODE_COLORFORMATCONV)config->physaddr_outdata1_colorconv = osConvertVirtToPhys(vaddr_outdata1_colorconv); config->unk_x6c[0] = 0x1; config->unk_x6c[(0x84-0x6c)>>2] = 0x12a;