1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - WM - demos - dataShare-Model
3 File: grahics.c
4
5 Copyright 2005-2008 Nintendo. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Date:: 2008-09-18#$
14 $Rev: 8573 $
15 $Author: okubata_ryoma $
16 *---------------------------------------------------------------------------*/
17
18 #ifdef SDK_TWL
19 #include <twl.h>
20 #else
21 #include <nitro.h>
22 #endif
23
24 #include "graphics.h"
25
initGraphics(void)26 void initGraphics(void)
27 {
28 GX_Init();
29
30 GX_DispOff();
31 GXS_DispOff();
32
33 GX_SetBankForLCDC(GX_VRAM_LCDC_ALL);
34 MI_CpuClearFast((void *)HW_LCDC_VRAM, HW_LCDC_VRAM_SIZE);
35
36 (void)GX_DisableBankForLCDC();
37 MI_CpuFillFast((void *)HW_OAM, 192, HW_OAM_SIZE);
38 MI_CpuClearFast((void *)HW_PLTT, HW_PLTT_SIZE);
39 MI_CpuFillFast((void *)HW_DB_OAM, 192, HW_DB_OAM_SIZE);
40 MI_CpuClearFast((void *)HW_DB_PLTT, HW_DB_PLTT_SIZE);
41
42 G3X_Init();
43 G3X_InitMtxStack();
44
45 GX_SetBankForTex(GX_VRAM_TEX_0_D);
46 GX_SetBankForTexPltt(GX_VRAM_TEXPLTT_0123_E);
47 GX_SetGraphicsMode(GX_DISPMODE_GRAPHICS, GX_BGMODE_3, GX_BG0_AS_3D);
48 G3X_AntiAlias(TRUE);
49 G3_SwapBuffers(GX_SORTMODE_AUTO, GX_BUFFERMODE_W);
50 G3X_SetClearColor(GX_RGB(0, 0, 0), 0, 0x7fff, 63, FALSE);
51
52 G3_ViewPort(0, 0, 255, 191);
53
54 G2_SetBG0Priority(1);
55 G2_SetBG2Priority(0);
56
57 G2_BG0Mosaic(FALSE);
58 G2_BG2Mosaic(FALSE);
59
60 GX_SetVisiblePlane(GX_PLANEMASK_BG0 | GX_PLANEMASK_BG2);
61 }
62
setupPseudo2DCamera(void)63 void setupPseudo2DCamera(void)
64 {
65 VecFx32 Eye = { 0, 0, FX32_ONE };
66 VecFx32 at = { 0, 0, 0 };
67 VecFx32 vUp = { 0, -FX32_ONE, 0 };
68
69 G3_Ortho(96 * PSEUDO2D_ONE, -96 * PSEUDO2D_ONE,
70 128 * PSEUDO2D_ONE, -128 * PSEUDO2D_ONE, FX32_ONE, FX32_ONE * 400, NULL);
71 G3_StoreMtx(0);
72 G3X_Reset();
73 G3_LookAt(&Eye, &vUp, &at, NULL);
74 }
75
drawPseudo2DTexQuad(int sx,int sy,int width,int height,int texw,int texh)76 void drawPseudo2DTexQuad(int sx, int sy, int width, int height, int texw, int texh)
77 {
78 sx -= 128;
79 sy -= 96;
80
81 G3_Begin(GX_BEGIN_QUADS);
82
83 G3_TexCoord(0, 0);
84 G3_Normal(0, 0, FX16_ONE - 1);
85 G3_Vtx((fx16)(sx * PSEUDO2D_ONE), (fx16)(sy * PSEUDO2D_ONE), 0);
86
87 G3_TexCoord(FX32_ONE * texw, 0);
88 G3_Normal(0, 0, FX16_ONE - 1);
89 G3_Vtx((fx16)((sx + width) * PSEUDO2D_ONE), (fx16)(sy * PSEUDO2D_ONE), 0);
90
91 G3_TexCoord(FX32_ONE * texw, FX32_ONE * texh);
92 G3_Normal(0, 0, FX16_ONE - 1);
93 G3_Vtx((fx16)((sx + width) * PSEUDO2D_ONE), (fx16)((sy + height) * PSEUDO2D_ONE), 0);
94
95 G3_TexCoord(0, FX32_ONE * texh);
96 G3_Normal(0, 0, FX16_ONE - 1);
97 G3_Vtx((fx16)(sx * PSEUDO2D_ONE), (fx16)((sy + height) * PSEUDO2D_ONE), 0);
98 G3_End();
99 }
100
drawPseudo2DColorQuad(int sx,int sy,int width,int height,GXRgb color)101 void drawPseudo2DColorQuad(int sx, int sy, int width, int height, GXRgb color)
102 {
103 sx -= 128;
104 sy -= 96;
105
106 G3_Begin(GX_BEGIN_QUADS);
107 G3_Color(color);
108 G3_Vtx((fx16)(sx * PSEUDO2D_ONE), (fx16)(sy * PSEUDO2D_ONE), 0);
109 G3_Vtx((fx16)((sx + width) * PSEUDO2D_ONE), (fx16)(sy * PSEUDO2D_ONE), 0);
110 G3_Vtx((fx16)((sx + width) * PSEUDO2D_ONE), (fx16)((sy + height) * PSEUDO2D_ONE), 0);
111 G3_Vtx((fx16)(sx * PSEUDO2D_ONE), (fx16)((sy + height) * PSEUDO2D_ONE), 0);
112 G3_End();
113 }
114