1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - GX - demos - UnitTours/Sub_Oam_1
3   File:     main.c
4 
5   Copyright 2003-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 //---------------------------------------------------------------------------
19 // A sample that displays a sphere using character OBJ
20 //
21 // HOWTO:
22 // 1. Transfer object character data with GXS_LoadOBJ
23 // 2. Transfer object palette data with GXS_LoadOBJPltt
24 // 3. Specify the attributes for objects with G2S_SetOBJAttr, etc.
25 // 4. Transfer the copy of object attribute memory with GXS_LoadOAM
26 //
27 // Do not forget to flush the corresponding cache if you modified the data
28 // before transfer
29 //---------------------------------------------------------------------------
30 
31 #ifdef SDK_TWL
32 #include <twl.h>
33 #else
34 #include <nitro.h>
35 #endif
36 #include "DEMO.h"
37 #include "data.h"
38 
39 static GXOamAttr sOamBak[128];         // Buffer for OAM
40 
41 #ifdef SDK_TWL
TwlMain(void)42 void TwlMain(void)
43 #else
44 void NitroMain(void)
45 #endif
46 {
47     //---------------------------------------------------------------------------
48     // Initialize:
49     // Enable IRQ interrupts, initialize VRAM, and make OBJ visible
50     //---------------------------------------------------------------------------
51     DEMOInitCommon();
52     DEMOInitVRAM();
53     DEMOInitDisplaySubOBJOnly();
54 
55     //---------------------------------------------------------------------------
56     // Transmitting the character data and the palette data
57     //---------------------------------------------------------------------------
58     GXS_LoadOBJ(d_64_256_obj_schDT, 0, sizeof(d_64_256_obj_schDT));
59     GXS_LoadOBJPltt(d_64_256_obj_sclDT, 0, sizeof(d_64_256_obj_sclDT));
60 
61     DEMOStartDisplay();
62     //---------------------------------------------------------------------------
63     // Main Loop
64     //---------------------------------------------------------------------------
65     while (1)
66     {
67         G2_SetOBJAttr(&sOamBak[0],     // A pointer to the attributes
68                       0,               // x
69                       0,               // y
70                       0,               // Priority
71                       GX_OAM_MODE_NORMAL,       // OBJ mode
72                       FALSE,           // Mosaic
73                       GX_OAM_EFFECT_NONE,       // Flip/affine/no display/affine(double)
74                       GX_OAM_SHAPE_64x64,       // Size and shape
75                       GX_OAM_COLORMODE_256,     // OBJ character data are in 256-color format
76                       0,               // Character name
77                       0,               // Color param
78                       0                // Affine param
79             );
80 
81         // Store the data in main memory, and invalidate the cache
82         DC_FlushRange(sOamBak, sizeof(sOamBak));
83         /* I/O register is accessed using DMA operation, so cache wait is not needed */
84         // DC_WaitWriteBufferEmpty();
85 
86         OS_WaitVBlankIntr();           // Waiting for the end of V-Blank interrupt
87 
88         GXS_LoadOAM(sOamBak, 0, sizeof(sOamBak));
89 
90         MI_DmaFill32(3, sOamBak, 192, sizeof(sOamBak)); // Let out of the screen if not display
91     }
92 
93 }
94 
95 //---------------------------------------------------------------------------
96 // V-Blank interrupt function:
97 //
98 // Interrupt handlers are registered on the interrupt table by OS_SetIRQFunction.
99 // OS_EnableIrqMask selects IRQ interrupts to enable, and
100 // OS_EnableIrq enables IRQ interrupts.
101 // Notice that you have to call OS_SetIrqCheckFlag to check a V-Blank interrupt.
102 //---------------------------------------------------------------------------
VBlankIntr(void)103 void VBlankIntr(void)
104 {
105     OS_SetIrqCheckFlag(OS_IE_V_BLANK); // Checking V-Blank interrupt
106 }
107