void glNamedTexImage2DCTR(GLuint texture, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid* data) { GLtextureCTR* tex; size_t textureDataSize; int i; tex = (GLtextureCTR*) texture; if (tex->data) linearFree(tex->data); textureDataSize = width * height * 4; tex->data = linearMemAlign(textureDataSize, 0x80); if (data) memcpy(tex->data, data, textureDataSize); tex->w = width; tex->h = height; for (i = 0; i < NUM_TEXUNITS; i++) if (texturingState.texUnits[i].boundTexture == tex) { dirtyState |= GL_TEXTURING_CTR; dirtyTexUnits |= (1 << i); } }
void* bufferizeFile(const char* filename, u32* size, bool binary, bool linear) { FILE* file; if(!binary)file = openFile(filename, "r+"); else file = openFile(filename, "rb+"); if(!file)return NULL; u8* buffer; long lsize; fseek (file, 0 , SEEK_END); lsize = ftell (file); rewind (file); if(linear)buffer=(u8*)linearMemAlign(lsize, 0x80); else buffer=(u8*)malloc(lsize); if(size)*size=lsize; if(!buffer) { fclose(file); return NULL; } fread(buffer, 1, lsize, file); fclose(file); return buffer; }
void gpuVboIndices(u32 vbo, const void* data, u32 size) { VboData* vboData = (VboData*) vbo; if(vboData == NULL) { return; } if(data == NULL) { if(vboData->indices != NULL) { linearFree(vboData->indices); vboData->indices = NULL; vboData->indicesSize = 0; } return; } if(vboData->indices == NULL || vboData->indicesSize != size) { if(vboData->indices != NULL) { linearFree(vboData->indices); } vboData->indices = linearMemAlign(size, 0x80); } memcpy(vboData->indices, data, size); vboData->indicesSize = size; }
void ctr_rend_texture_init() { void *mem = linearMemAlign(MEM_SPACE_SIZE, 0x80); tex_msp = create_mspace_with_base(mem, MEM_SPACE_SIZE, 0); mspace_track_large_chunks(tex_msp, 1); tex_msp_base = mem; }
void gpuTextureData(u32 texture, const void* data, u32 inWidth, u32 inHeight, PixelFormat inFormat, u32 outWidth, u32 outHeight, PixelFormat outFormat, u32 params) { TextureData* textureData = (TextureData*) texture; if(textureData == NULL) { return; } u32 size = outWidth * outHeight; switch(outFormat) { case PIXEL_RGBA8: case PIXEL_ETC1: case PIXEL_ETC1A4: size *= 4; break; case PIXEL_RGB8: size *= 3; break; case PIXEL_RGBA5551: case PIXEL_RGB565: case PIXEL_RGBA4: case PIXEL_LA8: case PIXEL_HILO8: size *= 2; break; case PIXEL_L8: case PIXEL_A8: case PIXEL_LA4: case PIXEL_L4: break; } if(textureData->data == NULL || textureData->size != size) { if(textureData->data != NULL) { linearFree(textureData->data); } textureData->data = linearMemAlign(size, 0x80); for(u8 unit = 0; unit < TEX_UNIT_COUNT; unit++) { if(activeTextures[unit] == textureData) { dirtyState |= STATE_TEXTURES; dirtyTextures |= (1 << unit); } } } u32 flags = (u32) ((1 << 1) | (inFormat << 8) | (outFormat << 12)); if(outWidth < inWidth || outHeight < inHeight) { flags |= (1 << 2); } GX_SetDisplayTransfer(NULL, (u32*) data, (inHeight << 16) | inWidth, (u32*) textureData->data, (outHeight << 16) | outWidth, flags); gpuSafeWait(GSPEVENT_PPF); textureData->width = outWidth; textureData->height = outHeight; textureData->size = size; textureData->format = outFormat; textureData->params = params; }
void ctr_rend_buffer_init() { ctr_state.buffer = ctr_buffer = linearMemAlign(CTR_REND_BUFFER_MAX, 128); if (ctr_state.buffer == 0) { printf("-------------\n\nctr_rend_buffer_copy_stride Out of Memory\n\n-------------\n"); while (1); } ctr_state.buffer_len = CTR_REND_BUFFER_MAX; ctr_state.buffer_pos = 0; ctr_buffer_frame = 0; }
void* linearAlloc(size_t size) { #if 0 extern PrintConsole* currentConsole; if(currentConsole->consoleInitialised) { printf("linearAlloc : 0x%08X\n", size); DEBUG_HOLD(); } #endif return linearMemAlign(size, 0x80); }
sf2d_texture *sf2d_create_texture(int width, int height, GPU_TEXCOLOR pixel_format, sf2d_place place) { int pow2_w = next_pow2(width); int pow2_h = next_pow2(height); int data_size; switch (pixel_format) { case GPU_RGBA8: default: data_size = pow2_w * pow2_h * 4; break; case GPU_RGB8: data_size = pow2_w * pow2_h * 3; break; case GPU_RGBA5551: case GPU_RGB565: data_size = pow2_w * pow2_h * 2; break; } sf2d_texture *texture; if (place == SF2D_PLACE_RAM) { // If there's not enough linear heap space, return if (linearSpaceFree() < data_size) { return NULL; } texture = malloc(sizeof(*texture)); texture->data = linearMemAlign(data_size, 0x80); } else if (place == SF2D_PLACE_VRAM) { // If there's not enough VRAM heap space, return if (vramSpaceFree() < data_size) { return NULL; } texture = malloc(sizeof(*texture)); texture->data = vramMemAlign(data_size, 0x80); } else { //wot? return NULL; } texture->place = place; texture->pixel_format = pixel_format; texture->width = width; texture->height = height; texture->pow2_w = pow2_w; texture->pow2_h = pow2_h; texture->data_size = data_size; return texture; }
void retro_init(void) { struct retro_log_callback log; int level; level = 0; environ_cb(RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL, &level); if (environ_cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &log)) log_cb = log.log; else log_cb = NULL; environ_cb(RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE, &disk_control); #ifdef _3DS ctr_svchack_successful = ctr_svchack_init(); #endif PicoOpt = POPT_EN_STEREO|POPT_EN_FM|POPT_EN_PSG|POPT_EN_Z80 | POPT_EN_MCD_PCM|POPT_EN_MCD_CDDA|POPT_EN_MCD_GFX | POPT_EN_32X|POPT_EN_PWM | POPT_ACC_SPRITES|POPT_DIS_32C_BORDER; #ifdef __arm__ #ifdef _3DS if (ctr_svchack_successful) #endif PicoOpt |= POPT_EN_DRC; #endif PsndRate = 44100; PicoAutoRgnOrder = 0x184; // US, EU, JP vout_width = 320; vout_height = 240; #ifdef _3DS vout_buf = linearMemAlign(VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2, 0x80); #else vout_buf = malloc(VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2); #endif PicoInit(); PicoDrawSetOutFormat(PDF_RGB555, 0); PicoDrawSetOutBuf(vout_buf, vout_width * 2); //PicoMessage = plat_status_msg_busy_next; PicoMCDopenTray = disk_tray_open; PicoMCDcloseTray = disk_tray_close; update_variables(); }
void glNamedBufferData(GLuint buffer, GLsizei size, const void* data, GLenum usage) { GLbufferCTR* buf; buf = (GLbufferCTR*) buffer; if (buf->data != NULL) linearFree(buf->data); buf->data = linearMemAlign(size, 128); if (data != NULL) memcpy(buf->data, data, size); buf->size = size; }
void gpuVboData(u32 vbo, const void* data, u32 size, u32 numVertices, Primitive primitive) { if(data == NULL) { return; } VboData* vboData = (VboData*) vbo; if(vboData == NULL) { return; } if(vboData->data == NULL || vboData->size != size) { if(vboData->data != NULL) { linearFree(vboData->data); } vboData->data = linearMemAlign(size, 0x80); } memcpy(vboData->data, data, size); vboData->size = size; vboData->numVertices = numVertices; vboData->primitive = primitive; }
int main() { Result ret=0; int draw=1; int ready=0; int type=0; gfxInit(GSP_RGB565_OES,GSP_BGR8_OES,false); consoleInit(GFX_BOTTOM, NULL); ret = romfsInit(); if(R_FAILED(ret)) { printf("romfsInit() failed: 0x%08x\n", (unsigned int)ret); ready = -1; } if(ready==0) { inaddr = linearMemAlign(0x1000000, 0x40); outaddr = linearMemAlign(0x100000, 0x40); if(!(inaddr && outaddr)) { ready = -2; printf("Failed to allocate memory.\n"); } } // Main loop while (aptMainLoop()) { gspWaitForVBlank(); hidScanInput(); if(draw && type==0) { consoleClear(); draw = 0; if(ready==0)printf("mvd example\n"); printf("Press START to exit.\n"); if(ready==0) { printf("Press A for color-format-conversion.\n"); printf("Press B for video(no sound).\n"); } } u32 kDown = hidKeysDown(); if(type) { if(kDown & KEY_A) { type = 0; continue; } } if(type)continue; if (kDown & KEY_START) break; // break in order to return to hbmenu if(ready==0) { type = 0; if (kDown & KEY_A)type = 1; if (kDown & KEY_B)type = 2; if(type) { memset(inaddr, 0, 0x100000); memset(outaddr, 0, 0x100000); if(type==1)mvd_colorconvert(); if(type==2)mvd_video(); draw = 1; printf("Press A to continue.\n"); } } } if(inaddr)linearFree(inaddr); if(outaddr)linearFree(outaddr); if(ready!=-1)romfsExit(); gfxExit(); return 0; }
Result load_hblauncher() { Result ret = 0; u8 region=0; u8 new3dsflag = 0; OS_VersionBin nver_versionbin; OS_VersionBin cver_versionbin; u32 payloadsize = 0, payloadsize_aligned = 0; u32 payload_src = 0; char payload_sysver[32]; char payloadurl[0x80]; char payload_sdpath[0x80]; void (*funcptr)(u32*, u32*) = NULL; u32 *paramblk = NULL; memset(&nver_versionbin, 0, sizeof(OS_VersionBin)); memset(&cver_versionbin, 0, sizeof(OS_VersionBin)); memset(payload_sysver, 0, sizeof(payload_sysver)); memset(payloadurl, 0, sizeof(payloadurl)); memset(payload_sdpath, 0, sizeof(payload_sdpath)); printf("Getting system-version/system-info etc...\n"); ret = cfguInit(); if(ret!=0) { printf("Failed to init cfgu: 0x%08x.\n", (unsigned int)ret); return ret; } ret = CFGU_SecureInfoGetRegion(®ion); if(ret!=0) { printf("Failed to get region from cfgu: 0x%08x.\n", (unsigned int)ret); return ret; } if(region>=7) { printf("Region value from cfgu is invalid: 0x%02x.\n", (unsigned int)region); ret = -9; return ret; } cfguExit(); APT_CheckNew3DS(&new3dsflag); ret = osGetSystemVersionData(&nver_versionbin, &cver_versionbin); if(ret!=0) { printf("Failed to load the system-version: 0x%08x.\n", (unsigned int)ret); return ret; } snprintf(payload_sysver, sizeof(payload_sysver)-1, "%s-%d-%d-%d-%d-%s", new3dsflag?"NEW":"OLD", cver_versionbin.mainver, cver_versionbin.minor, cver_versionbin.build, nver_versionbin.mainver, regionids_table[region]); snprintf(payloadurl, sizeof(payloadurl)-1, "http://smea.mtheall.com/get_payload.php?version=%s", payload_sysver); snprintf(payload_sdpath, sizeof(payload_sdpath)-1, "sdmc:/hblauncherloader_otherapp_payload_%s.bin", payload_sysver); printf("Detected system-version: %s %d.%d.%d-%d %s\n", new3dsflag?"New3DS":"Old3DS", cver_versionbin.mainver, cver_versionbin.minor, cver_versionbin.build, nver_versionbin.mainver, regionids_table[region]); memset(filebuffer, 0, filebuffer_maxsize); hidScanInput(); if((hidKeysHeld() & KEY_X) == 0) { printf("Since the X button isn't pressed, this will now check for the otherapp payload on SD, with the following filepath: %s\n", payload_sdpath); ret = loadsd_payload(payload_sdpath, &payloadsize); } else { printf("Skipping SD payload load-attempt since the X button is pressed.\n"); ret = 1; } if(ret==0) { printf("The otherapp payload for this app already exists on SD, that will be used instead of downloading the payload via HTTP.\n"); payload_src = 0; } else { printf("Requesting the actual payload URL with HTTP...\n"); ret = http_getactual_payloadurl(payloadurl, payloadurl, sizeof(payloadurl)); if(ret!=0) { printf("Failed to request the actual payload URL: 0x%08x.\n", (unsigned int)ret); printf("If the server isn't down, and the HTTP request was actually done, this may mean your system-version or region isn't supported by the hblauncher-payload currently.\n"); return ret; } printf("Downloading the actual payload with HTTP...\n"); ret = http_download_payload(payloadurl, &payloadsize); if(ret!=0) { printf("Failed to download the actual payload with HTTP: 0x%08x.\n", (unsigned int)ret); printf("If the server isn't down, and the HTTP request was actually done, this may mean your system-version or region isn't supported by the hblauncher-payload currently.\n"); return ret; } if(ret==0)payload_src = 1; } printf("Initializing payload data etc...\n"); payloadsize_aligned = (payloadsize + 0xfff) & ~0xfff; if(payloadsize_aligned > PAYLOAD_TEXTMAXSIZE) { printf("Invalid payload size: 0x%08x.\n", (unsigned int)payloadsize); ret = -3; return ret; } if(payload_src) { hidScanInput(); if(hidKeysHeld() & KEY_Y) { printf("Saving the downloaded payload to SD since the Y button is pressed...\n"); ret = savesd_payload(payload_sdpath, payloadsize); if(ret!=0) { printf("Payload saving failed: 0x%08x.\n", (unsigned int)ret); } else { printf("Payload saving was successful.\n"); } } else { printf("Skipping saving the downloaded payload to SD since the Y button isn't pressed.\n"); } } memcpy(PAYLOAD_TEXTADDR, filebuffer, payloadsize_aligned); memset(filebuffer, 0, filebuffer_maxsize); ret = svcFlushProcessDataCache(0xffff8001, PAYLOAD_TEXTADDR, payloadsize_aligned);//Flush dcache for the payload which was copied into .text. Since that area was never executed, icache shouldn't be an issue. if(ret!=0) { printf("svcFlushProcessDataCache failed: 0x%08x.\n", (unsigned int)ret); return ret; } paramblk = linearMemAlign(0x10000, 0x1000); if(paramblk==NULL) { ret = 0xfe; printf("Failed to alloc the paramblk.\n"); return ret; } httpcExit(); memset(paramblk, 0, 0x10000); paramblk[0x1c>>2] = (u32)gxlowcmd_4; paramblk[0x20>>2] = (u32)gsp_flushdcache; paramblk[0x48>>2] = 0x8d;//flags paramblk[0x58>>2] = (u32)&gspGpuHandle; printf("Jumping into the payload...\n"); funcptr = (void*)PAYLOAD_TEXTADDR; funcptr(paramblk, (u32*)(0x10000000-0x1000)); ret = 0xff; printf("The payload returned back into the app, this should *never* happen with the actual hblauncher-payload.\n"); return ret; }
static void init_video_filter(enum retro_pixel_format colfmt) { unsigned width, height, pow2_x, pow2_y, maxsize; struct retro_game_geometry *geom = NULL; settings_t *settings = config_get_ptr(); struct retro_system_av_info *av_info = video_viewport_get_system_av_info(); deinit_video_filter(); if (!*settings->video.softfilter_plugin) return; /* Deprecated format. Gets pre-converted. */ if (colfmt == RETRO_PIXEL_FORMAT_0RGB1555) colfmt = RETRO_PIXEL_FORMAT_RGB565; if (video_state.hw_render_callback.context_type) { RARCH_WARN("Cannot use CPU filters when hardware rendering is used.\n"); return; } geom = av_info ? (struct retro_game_geometry*)&av_info->geometry : NULL; if (!geom) return; width = geom->max_width; height = geom->max_height; video_state.filter.filter = rarch_softfilter_new( settings->video.softfilter_plugin, RARCH_SOFTFILTER_THREADS_AUTO, colfmt, width, height); if (!video_state.filter.filter) { RARCH_ERR("Failed to load filter.\n"); return; } rarch_softfilter_get_max_output_size(video_state.filter.filter, &width, &height); pow2_x = next_pow2(width); pow2_y = next_pow2(height); maxsize = max(pow2_x, pow2_y); video_state.filter.scale = maxsize / RARCH_SCALE_BASE; video_state.filter.out_rgb32 = rarch_softfilter_get_output_format( video_state.filter.filter) == RETRO_PIXEL_FORMAT_XRGB8888; video_state.filter.out_bpp = video_state.filter.out_rgb32 ? sizeof(uint32_t) : sizeof(uint16_t); /* TODO: Aligned output. */ #ifdef _3DS video_state.filter.buffer = linearMemAlign(width * height * video_state.filter.out_bpp, 0x80); #else video_state.filter.buffer = malloc(width * height * video_state.filter.out_bpp); #endif if (!video_state.filter.buffer) goto error; return; error: RARCH_ERR("Softfilter initialization failed.\n"); deinit_video_filter(); }
static void* ctr_init(const video_info_t* video, const input_driver_t** input, void** input_data) { void* ctrinput = NULL; ctr_video_t* ctr = (ctr_video_t*)linearAlloc(sizeof(ctr_video_t)); if (!ctr) return NULL; // gfxInitDefault(); // gfxSet3D(false); memset(ctr, 0, sizeof(ctr_video_t)); ctr->display_list_size = 0x40000; ctr->display_list = linearAlloc(ctr->display_list_size * sizeof(uint32_t)); GPU_Reset(NULL, ctr->display_list, ctr->display_list_size); ctr->texture_width = 512; ctr->texture_height = 512; ctr->texture_linear = linearMemAlign(ctr->texture_width * ctr->texture_height * sizeof(uint32_t), 128); ctr->texture_swizzled = linearMemAlign(ctr->texture_width * ctr->texture_height * sizeof(uint32_t), 128); ctr->frame_coords = linearAlloc(sizeof(ctr_vertex_t)); ctr->frame_coords->x0 = 0; ctr->frame_coords->y0 = 0; ctr->frame_coords->x1 = CTR_TOP_FRAMEBUFFER_WIDTH; ctr->frame_coords->y1 = CTR_TOP_FRAMEBUFFER_HEIGHT; ctr->frame_coords->u = CTR_TOP_FRAMEBUFFER_WIDTH; ctr->frame_coords->v = CTR_TOP_FRAMEBUFFER_HEIGHT; GSPGPU_FlushDataCache(NULL, (u8*)ctr->frame_coords, sizeof(ctr_vertex_t)); ctr->menu.texture_width = 512; ctr->menu.texture_height = 512; ctr->menu.texture_linear = linearMemAlign(ctr->texture_width * ctr->texture_height * sizeof(uint16_t), 128); ctr->menu.texture_swizzled = linearMemAlign(ctr->texture_width * ctr->texture_height * sizeof(uint16_t), 128); ctr->menu.frame_coords = linearAlloc(sizeof(ctr_vertex_t)); ctr->menu.frame_coords->x0 = 40; ctr->menu.frame_coords->y0 = 0; ctr->menu.frame_coords->x1 = CTR_TOP_FRAMEBUFFER_WIDTH - 40; ctr->menu.frame_coords->y1 = CTR_TOP_FRAMEBUFFER_HEIGHT; ctr->menu.frame_coords->u = CTR_TOP_FRAMEBUFFER_WIDTH - 80; ctr->menu.frame_coords->v = CTR_TOP_FRAMEBUFFER_HEIGHT; GSPGPU_FlushDataCache(NULL, (u8*)ctr->menu.frame_coords, sizeof(ctr_vertex_t)); ctr_set_scale_vector(&ctr->scale_vector, CTR_TOP_FRAMEBUFFER_WIDTH, CTR_TOP_FRAMEBUFFER_HEIGHT, ctr->texture_width, ctr->texture_height); ctr_set_scale_vector(&ctr->menu.scale_vector, CTR_TOP_FRAMEBUFFER_WIDTH, CTR_TOP_FRAMEBUFFER_HEIGHT, ctr->menu.texture_width, ctr->menu.texture_height); ctr->dvlb = DVLB_ParseFile((u32*)ctr_sprite_shader_shbin, ctr_sprite_shader_shbin_size); ctrGuSetVshGsh(&ctr->shader, ctr->dvlb, 2, 2); shaderProgramUse(&ctr->shader); GPU_SetViewport(VIRT_TO_PHYS(CTR_GPU_DEPTHBUFFER), VIRT_TO_PHYS(CTR_GPU_FRAMEBUFFER), 0, 0, CTR_TOP_FRAMEBUFFER_HEIGHT, CTR_TOP_FRAMEBUFFER_WIDTH); // GPU_SetViewport(NULL, // VIRT_TO_PHYS(CTR_GPU_FRAMEBUFFER), // 0, 0, CTR_TOP_FRAMEBUFFER_HEIGHT, CTR_TOP_FRAMEBUFFER_WIDTH); GPU_DepthMap(-1.0f, 0.0f); GPU_SetFaceCulling(GPU_CULL_NONE); GPU_SetStencilTest(false, GPU_ALWAYS, 0x00, 0xFF, 0x00); GPU_SetStencilOp(GPU_KEEP, GPU_KEEP, GPU_KEEP); GPU_SetBlendingColor(0, 0, 0, 0); // GPU_SetDepthTestAndWriteMask(true, GPU_GREATER, GPU_WRITE_ALL); GPU_SetDepthTestAndWriteMask(false, GPU_ALWAYS, GPU_WRITE_ALL); // GPU_SetDepthTestAndWriteMask(true, GPU_ALWAYS, GPU_WRITE_ALL); GPUCMD_AddMaskedWrite(GPUREG_0062, 0x1, 0); GPUCMD_AddWrite(GPUREG_0118, 0); GPU_SetAlphaBlending(GPU_BLEND_ADD, GPU_BLEND_ADD, GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA); GPU_SetAlphaTest(false, GPU_ALWAYS, 0x00); GPU_SetTextureEnable(GPU_TEXUNIT0); GPU_SetTexEnv(0, GPU_TEVSOURCES(GPU_TEXTURE0, GPU_PRIMARY_COLOR, 0), GPU_TEVSOURCES(GPU_TEXTURE0, GPU_PRIMARY_COLOR, 0), GPU_TEVOPERANDS(0, 0, 0), GPU_TEVOPERANDS(0, 0, 0), GPU_MODULATE, GPU_MODULATE, 0xFFFFFFFF); GPU_SetTexEnv(1, GPU_PREVIOUS,GPU_PREVIOUS, 0, 0, 0, 0, 0); GPU_SetTexEnv(2, GPU_PREVIOUS,GPU_PREVIOUS, 0, 0, 0, 0, 0); GPU_SetTexEnv(3, GPU_PREVIOUS,GPU_PREVIOUS, 0, 0, 0, 0, 0); GPU_SetTexEnv(4, GPU_PREVIOUS,GPU_PREVIOUS, 0, 0, 0, 0, 0); GPU_SetTexEnv(5, GPU_PREVIOUS,GPU_PREVIOUS, 0, 0, 0, 0, 0); ctrGuSetAttributeBuffers(2, VIRT_TO_PHYS(ctr->menu.frame_coords), CTRGU_ATTRIBFMT(GPU_SHORT, 4) << 0 | CTRGU_ATTRIBFMT(GPU_SHORT, 2) << 4, sizeof(ctr_vertex_t)); GPUCMD_Finalize(); ctrGuFlushAndRun(true); gspWaitForEvent(GSPEVENT_P3D, false); if (input && input_data) { ctrinput = input_ctr.init(); *input = ctrinput ? &input_ctr : NULL; *input_data = ctrinput; } return ctr; }
void* linearAlloc(size_t size) { return linearMemAlign(size, 0x80); }
static void* ctr_init(const video_info_t* video, const input_driver_t** input, void** input_data) { float refresh_rate; void* ctrinput = NULL; ctr_video_t* ctr = (ctr_video_t*)linearAlloc(sizeof(ctr_video_t)); if (!ctr) return NULL; memset(ctr, 0, sizeof(ctr_video_t)); ctr->vp.x = 0; ctr->vp.y = 0; ctr->vp.width = CTR_TOP_FRAMEBUFFER_WIDTH; ctr->vp.height = CTR_TOP_FRAMEBUFFER_HEIGHT; ctr->vp.full_width = CTR_TOP_FRAMEBUFFER_WIDTH; ctr->vp.full_height = CTR_TOP_FRAMEBUFFER_HEIGHT; ctr->display_list_size = 0x400; ctr->display_list = linearAlloc(ctr->display_list_size * sizeof(uint32_t)); GPU_Reset(NULL, ctr->display_list, ctr->display_list_size); ctr->rgb32 = video->rgb32; ctr->texture_width = video->input_scale * RARCH_SCALE_BASE; ctr->texture_height = video->input_scale * RARCH_SCALE_BASE; ctr->texture_linear = linearMemAlign(ctr->texture_width * ctr->texture_height * (ctr->rgb32? 4:2), 128); ctr->texture_swizzled = linearMemAlign(ctr->texture_width * ctr->texture_height * (ctr->rgb32? 4:2), 128); ctr->frame_coords = linearAlloc(3 * sizeof(ctr_vertex_t)); ctr->frame_coords->x0 = 0; ctr->frame_coords->y0 = 0; ctr->frame_coords->x1 = CTR_TOP_FRAMEBUFFER_WIDTH; ctr->frame_coords->y1 = CTR_TOP_FRAMEBUFFER_HEIGHT; ctr->frame_coords->u0 = 0; ctr->frame_coords->v0 = 0; ctr->frame_coords->u1 = CTR_TOP_FRAMEBUFFER_WIDTH; ctr->frame_coords->v1 = CTR_TOP_FRAMEBUFFER_HEIGHT; GSPGPU_FlushDataCache(ctr->frame_coords, sizeof(ctr_vertex_t)); ctr->menu.texture_width = 512; ctr->menu.texture_height = 512; ctr->menu.texture_linear = linearMemAlign(ctr->menu.texture_width * ctr->menu.texture_height * sizeof(uint16_t), 128); ctr->menu.texture_swizzled = linearMemAlign(ctr->menu.texture_width * ctr->menu.texture_height * sizeof(uint16_t), 128); ctr->menu.frame_coords = linearAlloc(sizeof(ctr_vertex_t)); ctr->menu.frame_coords->x0 = 40; ctr->menu.frame_coords->y0 = 0; ctr->menu.frame_coords->x1 = CTR_TOP_FRAMEBUFFER_WIDTH - 40; ctr->menu.frame_coords->y1 = CTR_TOP_FRAMEBUFFER_HEIGHT; ctr->menu.frame_coords->u0 = 0; ctr->menu.frame_coords->v0 = 0; ctr->menu.frame_coords->u1 = CTR_TOP_FRAMEBUFFER_WIDTH - 80; ctr->menu.frame_coords->v1 = CTR_TOP_FRAMEBUFFER_HEIGHT; GSPGPU_FlushDataCache(ctr->menu.frame_coords, sizeof(ctr_vertex_t)); ctr_set_scale_vector(&ctr->scale_vector, CTR_TOP_FRAMEBUFFER_WIDTH, CTR_TOP_FRAMEBUFFER_HEIGHT, ctr->texture_width, ctr->texture_height); ctr_set_scale_vector(&ctr->menu.scale_vector, CTR_TOP_FRAMEBUFFER_WIDTH, CTR_TOP_FRAMEBUFFER_HEIGHT, ctr->menu.texture_width, ctr->menu.texture_height); ctr->dvlb = DVLB_ParseFile((u32*)ctr_sprite_shbin, ctr_sprite_shbin_size); ctrGuSetVshGsh(&ctr->shader, ctr->dvlb, 2, 2); shaderProgramUse(&ctr->shader); GPU_SetViewport(VIRT_TO_PHYS(CTR_GPU_DEPTHBUFFER), VIRT_TO_PHYS(CTR_TOP_FRAMEBUFFER), 0, 0, CTR_TOP_FRAMEBUFFER_HEIGHT, CTR_TOP_FRAMEBUFFER_WIDTH); GPU_DepthMap(-1.0f, 0.0f); GPU_SetFaceCulling(GPU_CULL_NONE); GPU_SetStencilTest(false, GPU_ALWAYS, 0x00, 0xFF, 0x00); GPU_SetStencilOp(GPU_STENCIL_KEEP, GPU_STENCIL_KEEP, GPU_STENCIL_KEEP); GPU_SetBlendingColor(0, 0, 0, 0); // GPU_SetDepthTestAndWriteMask(true, GPU_GREATER, GPU_WRITE_ALL); GPU_SetDepthTestAndWriteMask(false, GPU_ALWAYS, GPU_WRITE_ALL); // GPU_SetDepthTestAndWriteMask(true, GPU_ALWAYS, GPU_WRITE_ALL); GPUCMD_AddMaskedWrite(GPUREG_EARLYDEPTH_TEST1, 0x1, 0); GPUCMD_AddWrite(GPUREG_EARLYDEPTH_TEST2, 0); GPU_SetAlphaBlending(GPU_BLEND_ADD, GPU_BLEND_ADD, GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA); GPU_SetAlphaTest(false, GPU_ALWAYS, 0x00); GPU_SetTextureEnable(GPU_TEXUNIT0); GPU_SetTexEnv(0, GPU_TEXTURE0, GPU_TEXTURE0, 0, 0, GPU_REPLACE, GPU_REPLACE, 0); GPU_SetTexEnv(1, GPU_PREVIOUS, GPU_PREVIOUS, 0, 0, 0, 0, 0); GPU_SetTexEnv(2, GPU_PREVIOUS, GPU_PREVIOUS, 0, 0, 0, 0, 0); GPU_SetTexEnv(3, GPU_PREVIOUS, GPU_PREVIOUS, 0, 0, 0, 0, 0); GPU_SetTexEnv(4, GPU_PREVIOUS, GPU_PREVIOUS, 0, 0, 0, 0, 0); GPU_SetTexEnv(5, GPU_PREVIOUS, GPU_PREVIOUS, 0, 0, 0, 0, 0); ctrGuSetAttributeBuffers(2, VIRT_TO_PHYS(ctr->menu.frame_coords), CTRGU_ATTRIBFMT(GPU_SHORT, 4) << 0 | CTRGU_ATTRIBFMT(GPU_SHORT, 4) << 4, sizeof(ctr_vertex_t)); GPUCMD_Finalize(); ctrGuFlushAndRun(true); gspWaitForEvent(GSPGPU_EVENT_P3D, false); if (input && input_data) { ctrinput = input_ctr.init(); *input = ctrinput ? &input_ctr : NULL; *input_data = ctrinput; } ctr->keep_aspect = true; ctr->should_resize = true; ctr->smooth = video->smooth; ctr->vsync = video->vsync; ctr->lcd_buttom_on = true; ctr->current_buffer_top = 0; ctr->empty_framebuffer = linearAlloc(320 * 240 * 2); memset(ctr->empty_framebuffer, 0, 320 * 240 * 2); refresh_rate = (32730.0 * 8192.0) / 4481134.0; driver_ctl(RARCH_DRIVER_CTL_SET_REFRESH_RATE, &refresh_rate); aptHook(&ctr->lcd_aptHook, ctr_lcd_aptHook, ctr); return ctr; }