void config_default(void) { /* version TAG */ strncpy(config.version,CONFIG_VERSION,16); /* sound options */ config.psg_preamp = 150; config.fm_preamp = 100; config.hq_fm = 1; config.psgBoostNoise = 1; config.filter = 1; config.lp_range = 0x9999; /* 0.6 in 16.16 fixed point */ config.low_freq = 880; config.high_freq = 5000; config.lg = 1.0; config.mg = 1.0; config.hg = 1.0; config.dac_bits = 14; config.ym2413 = 2; /* AUTO */ config.mono = 0; /* system options */ config.system = 0; /* AUTO */ config.region_detect = 0; /* AUTO */ config.vdp_mode = 0; /* AUTO */ config.master_clock = 0; /* AUTO */ config.force_dtack = 0; config.addr_error = 1; config.bios = 0; config.lock_on = 0; config.hot_swap = 0; /* video options */ config.xshift = 0; config.yshift = 0; config.xscale = 0; config.yscale = 0; config.aspect = 1; config.overscan = 3; /* FULL */ config.gg_extra = 0; config.ntsc = 0; config.vsync = 1; /* AUTO */ config.bilinear = 1; config.vfilter = 1; if (VIDEO_HaveComponentCable()) { config.render = 2; } else { config.render = 0; } switch (vmode->viTVMode >> 2) { case VI_PAL: config.tv_mode = 1; /* 50hz only */ break; case VI_EURGB60: config.tv_mode = 2; /* 50/60hz */ break; default: config.tv_mode = 0; /* 60hz only */ break; } #ifdef HW_RVL config.trap = 0; config.gamma = VI_GM_1_0 / 10.0; #endif /* controllers options */ config.gun_cursor[0] = 1; config.gun_cursor[1] = 1; config.invert_mouse = 0; /* on-screen options */ config.cd_leds = 0; /* menu options */ config.autoload = 0; config.autocheat = 0; #ifdef HW_RVL config.s_auto = 1; #else config.s_auto = 0; config.v_prog = 1; #endif config.s_default = 1; config.s_device = 0; config.l_device = 0; config.bg_overlay = 0; config.screen_w = 658; config.bgm_volume = 100.0; config.sfx_volume = 100.0; /* default ROM directories */ #ifdef HW_RVL sprintf (config.lastdir[0][TYPE_SD], "sd:%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[1][TYPE_SD], "sd:%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[2][TYPE_SD], "sd:%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[3][TYPE_SD], "sd:%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[4][TYPE_SD], "sd:%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[0][TYPE_USB], "usb:%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[1][TYPE_USB], "usb:%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[2][TYPE_USB], "usb:%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[3][TYPE_USB], "usb:%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[4][TYPE_USB], "usb:%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[0][TYPE_DVD], "dvd:%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[1][TYPE_DVD], "dvd:%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[2][TYPE_DVD], "dvd:%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[3][TYPE_DVD], "dvd:%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[4][TYPE_DVD], "dvd:%s/roms/", DEFAULT_PATH); #else sprintf (config.lastdir[0][TYPE_SD], "%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[1][TYPE_SD], "%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[2][TYPE_SD], "%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[3][TYPE_SD], "%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[4][TYPE_SD], "%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[0][TYPE_DVD], "dvd:%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[1][TYPE_DVD], "dvd:%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[2][TYPE_DVD], "dvd:%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[3][TYPE_DVD], "dvd:%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[4][TYPE_DVD], "dvd:%s/roms/", DEFAULT_PATH); #endif /* try to restore user config */ int loaded = config_load(); #ifndef HW_RVL /* detect progressive mode enable/disable requests */ PAD_ScanPads(); if (PAD_ButtonsHeld(0) & PAD_BUTTON_B) { /* swap progressive mode enable flag and play some sound to inform user */ config.v_prog ^= 1; ASND_Pause(0); int voice = ASND_GetFirstUnusedVoice(); ASND_SetVoice(voice,VOICE_MONO_16BIT,44100,0,(u8 *)intro_pcm,intro_pcm_size,200,200,NULL); sleep (2); ASND_Pause(1); } /* switch into 480p if component cable has been detected and progressive mode is enabled */ if (VIDEO_HaveComponentCable() && config.v_prog) { vmode = &TVNtsc480Prog; VIDEO_Configure (vmode); VIDEO_Flush(); VIDEO_WaitVSync(); VIDEO_WaitVSync(); } #endif /* inform user if default config is used */ if (!loaded) { GUI_WaitPrompt("Warning","Default Settings restored"); gx_input_SetDefault(); } /* default emulated inputs */ input.system[0] = SYSTEM_MD_GAMEPAD; input.system[1] = (config.input[1].device != -1) ? SYSTEM_MD_GAMEPAD : NO_SYSTEM; input_init(); }
int main(int argc, char* argv[]) { // Setup video VIDEO_Init(); GXRModeObj* pref_vid_mode = VIDEO_GetPreferredMode(NULL); #if USING_AA pref_vid_mode = &TVNtsc480ProgAa; u32 half_height = pref_vid_mode->xfbHeight / 2; u32 bottom_offset = VIDEO_PadFramebufferWidth(pref_vid_mode->fbWidth) * (pref_vid_mode->efbHeight-3) * VI_DISPLAY_PIX_SZ; #endif VIDEO_Configure(pref_vid_mode); xfb[0] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(pref_vid_mode)); xfb[1] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(pref_vid_mode)); fbi = 0; VIDEO_SetNextFramebuffer(xfb[0]); // Console console_init(xfb[0],20,20,pref_vid_mode->fbWidth,pref_vid_mode->xfbHeight,pref_vid_mode->fbWidth*VI_DISPLAY_PIX_SZ); // Make display visible VIDEO_SetBlack(FALSE); VIDEO_Flush(); VIDEO_WaitVSync(); if(pref_vid_mode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); printf("Console active\n"); // Setup GX void *gp_fifo = NULL; gp_fifo = memalign(32,DEFAULT_FIFO_SIZE); memset(gp_fifo,0,DEFAULT_FIFO_SIZE); GX_Init(gp_fifo, DEFAULT_FIFO_SIZE); GXColor background = {0x0,0x0,0x0,0xff}; GX_SetCopyClear(background, 0x00ffffff); f32 yscale; u32 xfbHeight; yscale = GX_GetYScaleFactor(pref_vid_mode->efbHeight,pref_vid_mode->xfbHeight); xfbHeight = GX_SetDispCopyYScale(yscale); GX_SetScissor(0,0,pref_vid_mode->fbWidth,pref_vid_mode->efbHeight); GX_SetDispCopySrc(0,0,pref_vid_mode->fbWidth,pref_vid_mode->efbHeight); GX_SetDispCopyDst(pref_vid_mode->fbWidth,xfbHeight); GX_SetCopyFilter(pref_vid_mode->aa,pref_vid_mode->sample_pattern,GX_TRUE,pref_vid_mode->vfilter); GX_SetFieldMode(pref_vid_mode->field_rendering,((pref_vid_mode->viHeight==2*pref_vid_mode->xfbHeight)?GX_ENABLE:GX_DISABLE)); if (pref_vid_mode->aa) { GX_SetPixelFmt(GX_PF_RGB565_Z16, GX_ZC_LINEAR); GX_SetDispCopyYScale(1); GX_SetDither(GX_ENABLE); } else GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR); GX_SetDispCopyGamma(GX_GM_1_0); // Setup PSPL const pspl_platform_t* plat; pspl_runtime_init(&plat); const pspl_runtime_package_t* package = NULL; printf("PACKAGE OFF: %p SIZE: %u\n", (void*)&monkey_psplp, monkey_psplp_size); pspl_runtime_load_package_membuf((void*)&monkey_psplp, monkey_psplp_size, &package); pspl_runtime_enumerate_psplcs(package, enumerate_psplc_hook); printf("PSPL package read\n"); // Setup monkey rendering context monkey_ctx = pmdl_new_draw_context(); monkey_ctx->texcoord_mtx[1].m[0][0] = 0.5; monkey_ctx->texcoord_mtx[1].m[1][1] = -0.5; monkey_ctx->texcoord_mtx[1].m[0][3] = 0.5; monkey_ctx->texcoord_mtx[1].m[1][3] = 0.5; monkey_ctx->camera_view.pos.f[0] = 0; monkey_ctx->camera_view.pos.f[1] = 3; monkey_ctx->camera_view.pos.f[2] = 0; monkey_ctx->camera_view.look.f[0] = 0; monkey_ctx->camera_view.look.f[1] = 0; monkey_ctx->camera_view.look.f[2] = 0; monkey_ctx->camera_view.up.f[0] = 0; monkey_ctx->camera_view.up.f[1] = 0; monkey_ctx->camera_view.up.f[2] = 1; monkey_ctx->projection_type = PMDL_PERSPECTIVE; monkey_ctx->projection.perspective.fov = 55; monkey_ctx->projection.perspective.far = 5; monkey_ctx->projection.perspective.near = 1; monkey_ctx->projection.perspective.aspect = 1.777; monkey_ctx->projection.perspective.post_translate_x = 0; monkey_ctx->projection.perspective.post_translate_y = 0; pmdl_update_context(monkey_ctx, PMDL_INVALIDATE_ALL); // Load monkey const pspl_runtime_psplc_t* monkey_obj = pspl_runtime_get_psplc_from_key(package, "Monkey", 1); monkey_ctx->default_shader = monkey_obj; monkey_model = pmdl_lookup(monkey_obj, "monkey"); printf("Monkey loaded\n"); // Setup animation context haha_action_ctx = pmdl_action_init(pmdl_action_lookup(monkey_model, "haha")); haha_action_ctx->loop_flag = 1; rotate_action_ctx = pmdl_action_init(pmdl_action_lookup(monkey_model, "rotate")); rotate_action_ctx->loop_flag = 1; anim_ctx = pmdl_animation_initv(rotate_action_ctx, haha_action_ctx, NULL); printf("Animation Context Setup\n"); //init_time_profile(&profile); // Loop until reset button pressed SYS_SetResetCallback(reset_press_cb); double tex_off = 0; while (!reset_pressed) { //start_time_profile(&profile); // Update action contexts pmdl_action_advance(rotate_action_ctx, 0.1/60.0); pmdl_action_advance(haha_action_ctx, 1/60.0); pmdl_animation_evaluate(anim_ctx); tex_off += 0.005; //stop_time_profile(&profile); //report_time_profile(&profile); #if USING_AA GX_SetViewport(0, 0, pref_vid_mode->fbWidth, pref_vid_mode->xfbHeight, 0, 1); GX_SetScissor(0, 0, pref_vid_mode->fbWidth, half_height); GX_SetScissorBoxOffset(0, 0); #endif // Render top renderfunc(); // Copy to XFB GX_CopyDisp(xfb[fbi], GX_TRUE); #if USING_AA GX_SetViewport(0, 1, pref_vid_mode->fbWidth, pref_vid_mode->xfbHeight, 0, 1); GX_SetScissor(0, half_height, pref_vid_mode->fbWidth, half_height); GX_SetScissorBoxOffset(0, half_height); // Render bottom renderfunc(); // Copy to XFB GX_CopyDisp(xfb[fbi] + bottom_offset, GX_TRUE); #endif GX_DrawDone(); // Swap buffers VIDEO_SetNextFramebuffer(xfb[fbi]); fbi ^= 1; VIDEO_Flush(); ++cur_frame; VIDEO_WaitVSync(); } return 0; }
int main(int argc,char **argv) { f32 yscale; u32 xfbHeight; u32 fb = 0; f32 rquad = 0.0f; u32 first_frame = 1; GXTexObj texture; Mtx view; // view and perspective matrices Mtx model, modelview; Mtx44 perspective; void *gpfifo = NULL; GXColor background = {0, 0, 0, 0xff}; guVector cam = {0.0F, 0.0F, 0.0F}, up = {0.0F, 1.0F, 0.0F}, look = {0.0F, 0.0F, -1.0F}; TPLFile neheTPL; VIDEO_Init(); WPAD_Init(); rmode = VIDEO_GetPreferredMode(NULL); // allocate the fifo buffer gpfifo = memalign(32,DEFAULT_FIFO_SIZE); memset(gpfifo,0,DEFAULT_FIFO_SIZE); // allocate 2 framebuffers for double buffering frameBuffer[0] = SYS_AllocateFramebuffer(rmode); frameBuffer[1] = SYS_AllocateFramebuffer(rmode); // configure video VIDEO_Configure(rmode); VIDEO_SetNextFramebuffer(frameBuffer[fb]); VIDEO_Flush(); VIDEO_WaitVSync(); if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); fb ^= 1; // init the flipper GX_Init(gpfifo,DEFAULT_FIFO_SIZE); // clears the bg to color and clears the z buffer GX_SetCopyClear(background, 0x00ffffff); // other gx setup GX_SetViewport(0,0,rmode->fbWidth,rmode->efbHeight,0,1); yscale = GX_GetYScaleFactor(rmode->efbHeight,rmode->xfbHeight); xfbHeight = GX_SetDispCopyYScale(yscale); GX_SetScissor(0,0,rmode->fbWidth,rmode->efbHeight); GX_SetDispCopySrc(0,0,rmode->fbWidth,rmode->efbHeight); GX_SetDispCopyDst(rmode->fbWidth,xfbHeight); GX_SetCopyFilter(rmode->aa,rmode->sample_pattern,GX_TRUE,rmode->vfilter); GX_SetFieldMode(rmode->field_rendering,((rmode->viHeight==2*rmode->xfbHeight)?GX_ENABLE:GX_DISABLE)); if (rmode->aa) GX_SetPixelFmt(GX_PF_RGB565_Z16, GX_ZC_LINEAR); else GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR); GX_SetCullMode(GX_CULL_NONE); GX_CopyDisp(frameBuffer[fb],GX_TRUE); GX_SetDispCopyGamma(GX_GM_1_0); // setup the vertex attribute table // describes the data // args: vat location 0-7, type of data, data format, size, scale // so for ex. in the first call we are sending position data with // 3 values X,Y,Z of size F32. scale sets the number of fractional // bits for non float data. GX_ClearVtxDesc(); GX_SetVtxDesc(GX_VA_POS, GX_DIRECT); GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT); GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGB8, 0); // set number of rasterized color channels GX_SetNumChans(1); //set number of textures to generate GX_SetNumTexGens(1); // setup texture coordinate generation // args: texcoord slot 0-7, matrix type, source to generate texture coordinates from, matrix to use GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY); GX_InvVtxCache(); GX_InvalidateTexAll(); TPL_OpenTPLFromMemory(&neheTPL, (void *)NeHe_tpl,NeHe_tpl_size); TPL_GetTexture(&neheTPL,nehe,&texture); // setup our camera at the origin // looking down the -z axis with y up guLookAt(view, &cam, &up, &look); // setup our projection matrix // this creates a perspective matrix with a view angle of 90, // and aspect ratio based on the display resolution f32 w = rmode->viWidth; f32 h = rmode->viHeight; guPerspective(perspective, 45, (f32)w/h, 0.1F, 300.0F); GX_LoadProjectionMtx(perspective, GX_PERSPECTIVE); guVector cubeAxis = {1,1,1}; while(1) { WPAD_ScanPads(); if ( WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME) exit(0); GX_SetTevOp(GX_TEVSTAGE0,GX_REPLACE); GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0); GX_LoadTexObj(&texture, GX_TEXMAP0); guMtxIdentity(model); guMtxRotAxisDeg(model, &cubeAxis, rquad); guMtxTransApply(model, model, 1.5f,0.0f,-7.0f); guMtxConcat(view,model,modelview); // load the modelview matrix into matrix memory GX_LoadPosMtxImm(modelview, GX_PNMTX0); GX_Begin(GX_QUADS, GX_VTXFMT0, 24); // Draw a Cube GX_Position3f32(-1.0f, 1.0f, -1.0f); // Top Left of the quad (top) GX_Color3f32(0.0f,1.0f,0.0f); // Set The Color To Green GX_TexCoord2f32(0.0f,0.0f); GX_Position3f32(-1.0f, 1.0f, 1.0f); // Top Right of the quad (top) GX_Color3f32(0.0f,1.0f,0.0f); // Set The Color To Green GX_TexCoord2f32(1.0f,0.0f); GX_Position3f32(-1.0f, -1.0f, 1.0f); // Bottom Right of the quad (top) GX_Color3f32(0.0f,1.0f,0.0f); // Set The Color To Green GX_TexCoord2f32(1.0f,1.0f); GX_Position3f32(- 1.0f, -1.0f, -1.0f); // Bottom Left of the quad (top) GX_Color3f32(0.0f,1.0f,0.0f); // Set The Color To Green GX_TexCoord2f32(0.0f,1.0f); GX_Position3f32( 1.0f,1.0f, -1.0f); // Top Left of the quad (bottom) GX_Color3f32(1.0f,0.5f,0.0f); // Set The Color To Orange GX_TexCoord2f32(0.0f,0.0f); GX_Position3f32(1.0f,-1.0f, -1.0f); // Top Right of the quad (bottom) GX_Color3f32(1.0f,0.5f,0.0f); // Set The Color To Orange GX_TexCoord2f32(1.0f,0.0f); GX_Position3f32(1.0f,-1.0f,1.0f); // Bottom Right of the quad (bottom) GX_Color3f32(1.0f,0.5f,0.0f); // Set The Color To Orange GX_TexCoord2f32(1.0f,1.0f); GX_Position3f32( 1.0f,1.0f,1.0f); // Bottom Left of the quad (bottom) GX_Color3f32(1.0f,0.5f,0.0f); // Set The Color To Orange GX_TexCoord2f32(0.0f,1.0f); GX_Position3f32( -1.0f, -1.0f, 1.0f); // Top Right Of The Quad (Front) GX_Color3f32(1.0f,0.0f,0.0f); // Set The Color To Red GX_TexCoord2f32(0.0f,0.0f); GX_Position3f32(1.0f, -1.0f, 1.0f); // Top Left Of The Quad (Front) GX_Color3f32(1.0f,0.0f,0.0f); // Set The Color To Red GX_TexCoord2f32(1.0f,0.0f); GX_Position3f32(1.0f,-1.0f, -1.0f); // Bottom Left Of The Quad (Front) GX_Color3f32(1.0f,0.0f,0.0f); // Set The Color To Red GX_TexCoord2f32(1.0f,1.0f); GX_Position3f32( -1.0f,-1.0f, -1.0f); // Bottom Right Of The Quad (Front) GX_Color3f32(1.0f,0.0f,0.0f); // Set The Color To Red GX_TexCoord2f32(0.0f,1.0f); GX_Position3f32( -1.0f,1.0f,1.0f); // Bottom Left Of The Quad (Back) GX_Color3f32(1.0f,1.0f,0.0f); // Set The Color To Yellow GX_TexCoord2f32(0.0f,0.0f); GX_Position3f32(-1.0f,1.0f,-1.0f); // Bottom Right Of The Quad (Back) GX_Color3f32(1.0f,1.0f,0.0f); // Set The Color To Yellow GX_TexCoord2f32(1.0f,0.0f); GX_Position3f32(1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Back) GX_Color3f32(1.0f,1.0f,0.0f); // Set The Color To Yellow GX_TexCoord2f32(1.0f,1.0f); GX_Position3f32( 1.0f, 1.0f,1.0f); // Top Left Of The Quad (Back) GX_Color3f32(1.0f,1.0f,0.0f); // Set The Color To Yellow GX_TexCoord2f32(0.0f,1.0f); GX_Position3f32(1.0f, -1.0f, -1.0f); // Top Right Of The Quad (Left) GX_Color3f32(0.0f,0.0f,1.0f); // Set The Color To Blue GX_TexCoord2f32(0.0f,0.0f); GX_Position3f32(1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Left) GX_Color3f32(0.0f,0.0f,1.0f); // Set The Color To Blue GX_TexCoord2f32(1.0f,0.0f); GX_Position3f32(-1.0f,1.0f,-1.0f); // Bottom Left Of The Quad (Left) GX_Color3f32(0.0f,0.0f,1.0f); // Set The Color To Blue GX_TexCoord2f32(1.0f,1.0f); GX_Position3f32(-1.0f,-1.0f, -1.0f); // Bottom Right Of The Quad (Left) GX_Color3f32(0.0f,0.0f,1.0f); // Set The Color To Blue GX_TexCoord2f32(0.0f,1.0f); GX_Position3f32( 1.0f, -1.0f,1.0f); // Top Right Of The Quad (Right) GX_Color3f32(1.0f,0.0f,1.0f); // Set The Color To Violet GX_TexCoord2f32(0.0f,0.0f); GX_Position3f32( -1.0f, -1.0f, 1.0f); // Top Left Of The Quad (Right) GX_Color3f32(1.0f,0.0f,1.0f); // Set The Color To Violet GX_TexCoord2f32(1.0f,0.0f); GX_Position3f32( -1.0f,1.0f, 1.0f); // Bottom Left Of The Quad (Right) GX_Color3f32(1.0f,0.0f,1.0f); // Set The Color To Violet GX_TexCoord2f32(1.0f,1.0f); GX_Position3f32( 1.0f,1.0f,1.0f); // Bottom Right Of The Quad (Right) GX_Color3f32(1.0f,0.0f,1.0f); // Set The Color To Violet GX_TexCoord2f32(0.0f,1.0f); GX_End(); // Done Drawing The Quad GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE); GX_SetColorUpdate(GX_TRUE); GX_CopyDisp(frameBuffer[fb],GX_TRUE); GX_DrawDone(); VIDEO_SetNextFramebuffer(frameBuffer[fb]); if(first_frame) { first_frame = 0; VIDEO_SetBlack(FALSE); } VIDEO_Flush(); VIDEO_WaitVSync(); fb ^= 1; rquad -= 0.15f; // Decrease The Rotation Variable For The Quad ( NEW ) } }