1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - GX -
3 File: gx_sp.h
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 // Simple accessors for ARM7's DISPSTAT and VCOUNT.
20 // THIS FILE IS INCLUDED BY 'nitro_sp.h'.
21 //////////////////////////////////////////////////////////////////////////////
22
23 #ifndef NITRO_GX_SP_H_
24 #define NITRO_GX_SP_H_
25
26 #include <nitro/hw/common/lcd.h>
27 #ifdef SDK_NITRO
28 #include <nitro/hw/ARM7/ioreg.h>
29 #else
30 #include <twl/hw/ARM7/ioreg.h>
31 #endif
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 //----------------------------------------------------------------------------
38 // Type definition
39 //----------------------------------------------------------------------------
40
41 #define GX_LCD_SIZE_X HW_LCD_WIDTH
42 #define GX_LCD_SIZE_Y HW_LCD_HEIGHT
43
44 //----------------------------------------------------------------------------
45 // Declaration of function
46 //----------------------------------------------------------------------------
47
48 // reg_GX_DISPSTAT
49 static s32 GX_IsHBlank(void);
50 static s32 GX_HBlankIntr(BOOL enable);
51 static s32 GX_IsVBlank(void);
52 static s32 GX_VBlankIntr(BOOL enable);
53 static s32 GX_IsVCountEq(void);
54 static void GX_VCountEqIntr(BOOL enable);
55 static void GX_SetVCountEqVal(s32 val);
56 static s32 GX_GetVCountEqVal(void);
57
58 #define GX_IsVCounterEq GX_IsVCountEq
59 #define GX_VCounterEqIntr GX_VCountEqIntr
60 #define GX_SetVCounterEqVal GX_SetVCountEqVal
61 #define GX_GetVCounterEqVal GX_GetVCountEqVal
62
63 // reg_GX_VCOUNT
64 static s32 GX_GetVCount(void);
65 static void GX_SetVCount(s32 count);
66
67 //----------------------------------------------------------------------------
68 // Implementation of inline function
69 //----------------------------------------------------------------------------
70
71 /*---------------------------------------------------------------------------*
72 Name: GX_IsHBlank
73
74 Description: Tests if H-Blank.
75
76 Arguments: none
77
78 Returns: 0 if not in H-Blank
79 otherwise if in H-Blank
80 *---------------------------------------------------------------------------*/
GX_IsHBlank(void)81 static inline s32 GX_IsHBlank(void)
82 {
83 return (reg_GX_DISPSTAT & REG_GX_DISPSTAT_HBLK_MASK);
84 }
85
86
87 /*---------------------------------------------------------------------------*
88 Name: GX_IsVBlank
89
90 Description: Tests if V-Blank.
91
92 Arguments: none
93
94 Returns: 0 if not in V-Blank
95 otherwise if in V-Blank
96 *---------------------------------------------------------------------------*/
GX_IsVBlank(void)97 static inline s32 GX_IsVBlank(void)
98 {
99 return (reg_GX_DISPSTAT & REG_GX_DISPSTAT_VBLK_MASK);
100 }
101
102
103 /*---------------------------------------------------------------------------*
104 Name: GX_IsVCountEq
105
106 Description: Tests if VCounter is equal to GX_VCounterEqVal().
107
108 Arguments: none
109
110 Returns: 0 if V-counter not equal to GX_VCountEqVal()
111 otherwise if V-counter equal to GX_VCountEqVal()
112 *---------------------------------------------------------------------------*/
GX_IsVCountEq(void)113 static inline s32 GX_IsVCountEq(void)
114 {
115 return (reg_GX_DISPSTAT & REG_GX_DISPSTAT_LYC_MASK);
116 }
117
118
119 /*---------------------------------------------------------------------------*
120 Name: GX_VCountEqIntr
121
122 Description: Enable/disable V-Counter equality interrupt.
123
124 Arguments: enable FALSE / not FALSE(TRUE)
125
126 Returns: None
127 *---------------------------------------------------------------------------*/
GX_VCountEqIntr(BOOL enable)128 static inline void GX_VCountEqIntr(BOOL enable)
129 {
130 if (enable)
131 {
132 reg_GX_DISPSTAT |= REG_GX_DISPSTAT_VQI_MASK;
133 }
134 else
135 {
136 reg_GX_DISPSTAT &= ~REG_GX_DISPSTAT_VQI_MASK;
137 }
138 }
139
140
141 /*---------------------------------------------------------------------------*
142 Name: GX_GetVCount
143
144 Description: Obtain the value of the current VCOUNTER register.
145
146 Arguments: none
147
148 Returns: the value of the current VCOUNTER register
149 *---------------------------------------------------------------------------*/
GX_GetVCount()150 static inline s32 GX_GetVCount()
151 {
152 return reg_GX_VCOUNT;
153 }
154
155
156 /*---------------------------------------------------------------------------*
157 Name: GX_SetVCount
158
159 Description: Sets the value of the current VCOUNTER register.
160
161 Arguments: count the value to be new VCOUNTER
162
163 Returns: none
164 *---------------------------------------------------------------------------*/
GX_SetVCount(s32 count)165 static inline void GX_SetVCount(s32 count)
166 {
167 SDK_WARNING(reg_GX_VCOUNT >= 202 && reg_GX_VCOUNT <= 212,
168 "V Counter out of range(%d). it must be 202 to 212.", reg_GX_VCOUNT);
169 SDK_ASSERT(count >= 202 && count <= 212);
170
171 reg_GX_VCOUNT = (u16)count;
172 }
173
174
175 /*---------------------------------------------------------------------------*
176 Name: GX_SetVCountEqVal
177
178 Description: Specifies the V-counter agreement value.
179
180 Arguments: val the value of V-counter
181
182 Returns: none
183 *---------------------------------------------------------------------------*/
GX_SetVCountEqVal(s32 val)184 static inline void GX_SetVCountEqVal(s32 val)
185 {
186 SDK_MINMAX_ASSERT(val, 0, HW_LCD_LINES - 1);
187 reg_GX_DISPSTAT = (u16)((reg_GX_DISPSTAT & (REG_GX_DISPSTAT_VBLK_MASK |
188 REG_GX_DISPSTAT_HBLK_MASK |
189 REG_GX_DISPSTAT_LYC_MASK |
190 REG_GX_DISPSTAT_VBI_MASK |
191 REG_GX_DISPSTAT_HBI_MASK |
192 REG_GX_DISPSTAT_VQI_MASK)) |
193 ((val & 0xff) << 8) | ((val & 0x100) >> 1));
194 }
195
196 /*---------------------------------------------------------------------------*
197 Name: GX_GetVCountEqVal
198
199 Description: Get the V-counter agreement value.
200
201 Arguments: None
202
203 Returns: the value of V-counter to interrupt
204 *---------------------------------------------------------------------------*/
GX_GetVCountEqVal(void)205 static inline s32 GX_GetVCountEqVal(void)
206 {
207 u16 val = reg_GX_DISPSTAT;
208 return ((val >> 8) & 0x00ff) | ((val << 1) & 0x0100);
209 }
210
211 /*---------------------------------------------------------------------------*
212 Name: GX_HBlankIntr
213
214 Description: Enables/Disables the H-Blank interrupt generation.
215
216 Arguments: enable disable if FALSE, enable otherwise.
217
218 Returns: none
219 *---------------------------------------------------------------------------*/
GX_HBlankIntr(BOOL enable)220 static inline s32 GX_HBlankIntr(BOOL enable)
221 {
222 s32 rval = (reg_GX_DISPSTAT & REG_GX_DISPSTAT_HBI_MASK);
223 if (enable)
224 {
225 reg_GX_DISPSTAT |= REG_GX_DISPSTAT_HBI_MASK;
226 }
227 else
228 {
229 reg_GX_DISPSTAT &= ~REG_GX_DISPSTAT_HBI_MASK;
230 }
231 return rval;
232 }
233
234
235 /*---------------------------------------------------------------------------*
236 Name: GX_VBlankIntr
237
238 Description: Enables/Disables the V-Blank interrupt generation.
239
240 Arguments: enable disable if FALSE, enable otherwise.
241
242 Returns: none
243 *---------------------------------------------------------------------------*/
GX_VBlankIntr(BOOL enable)244 static inline s32 GX_VBlankIntr(BOOL enable)
245 {
246 s32 rval = (reg_GX_DISPSTAT & REG_GX_DISPSTAT_VBI_MASK);
247 if (enable)
248 {
249 reg_GX_DISPSTAT |= REG_GX_DISPSTAT_VBI_MASK;
250 }
251 else
252 {
253 reg_GX_DISPSTAT &= ~REG_GX_DISPSTAT_VBI_MASK;
254 }
255 return rval;
256 }
257
258
259
260
261 #ifdef __cplusplus
262 }/* extern "C" */
263 #endif
264
265 #endif
266