game.c
7.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
/*
game.c
Copyright (C) 1999, NINTENDO Co,Ltd., MONEGI CORPORATION.
Jan. 28, 1999.
*/
#include <ultra64.h>
#include <PR/gs2dex.h>
#include "Tile_Rect.h"
#include "Cont.h"
extern Rectangle dk_rect;
extern Rectangle dk7_rect;
extern Rectangle road_rect;
extern Rectangle l2tv_rect;
int giDrawMode = 0;
static void add_scrollx_rect( Rectangle *rect );
static void add_scrolly_rect( Rectangle *rect );
static void sub_scrollx_rect( Rectangle *rect );
static void sub_scrolly_rect( Rectangle *rect );
static void add_sclx_rect( Rectangle *rect );
static void sub_sclx_rect( Rectangle *rect );
static void add_scly_rect( Rectangle *rect );
static void sub_scly_rect( Rectangle *rect );
static void add_sc_width_rect( Rectangle *rect );
static void sub_sc_width_rect( Rectangle *rect );
static void add_sc_hight_rect( Rectangle *rect );
static void sub_sc_hight_rect( Rectangle *rect );
static void add_scalex_rect( Rectangle *rect );
static void sub_scalex_rect( Rectangle *rect );
static void add_scaley_rect( Rectangle *rect );
static void sub_scaley_rect( Rectangle *rect );
#define _Memcpy(dest, src, size) bcopy(src, dest, size)
static u16 gNewTexture = 0;
static u16 gZButtonPush = 0;
static Rectangle gRect;
void game_init( void );
Gfx *game_main( Gfx *glistp, Control *cont );
static void SetMyTexture(void)
{
static char *pszFormat[] = {
"RGBA", "YUV", "CI", "IA", "I"
};
static char *pszSize[] = {
"4b", "8b", "16b", "32b", "DD"
};
Rectangle *pRect;
switch(gNewTexture) {
case 0:
pRect = &dk_rect;
break;
case 1:
pRect = &dk7_rect;
break;
case 2:
pRect = &l2tv_rect;
break;
default:
pRect = &road_rect;
break;
}
_Memcpy(&gRect, pRect, sizeof(Rectangle));
#ifdef _DEBUG
/* print image iformation */
osSyncPrintf("width = %d, height = %d, format = %s, size = %s\n",
gRect.width,
gRect.height,
pszFormat[gRect.fmt],
pszSize[gRect.size]);
#endif /* _DEBUG */
}
void game_init( void )
{
SetMyTexture();
}
Gfx *game_main( Gfx *glistp, Control *cont )
{
/* Zボタン押下 */
if ( cont->trigger & Z_TRIG ) gZButtonPush ^= 1;
/* 描画テクスチャーイメージの変更 */
if ( cont->trigger & CONT_A )
{
gNewTexture += 1;
if ( gNewTexture > 3 ) gNewTexture = 0;
SetMyTexture();
}
/* BG描画方法の変更 */
if ( cont->trigger & CONT_B ) {
static char *pszDrawMode[] = {
"draw : gSPBgRect1Cyc\n",
"draw : guS2DEmuBgRect1Cyc\n"
};
giDrawMode++;
if(giDrawMode > 1) {
giDrawMode = 0;
}
#ifdef _DEBUG
osSyncPrintf(pszDrawMode[giDrawMode]);
#endif /* _DEBUG */
}
/* reset parameter */
if ( cont->trigger & CONT_START )
{
#ifdef _DEBUG
osSyncPrintf("reset parameter\n");
#endif /* _DEBUG */
SetMyTexture();
}
gRect.flipy ^= 1;
/* Tのフリップ(反転) */
if ( cont->trigger & CONT_R ) gRect.flipy ^= 1;
/* Sのフリップ(反転) */
if ( cont->trigger & CONT_L ) gRect.flipx ^= 1;
if ( gZButtonPush )
{
/* Zトリガーが押下されている */
/* Texture Imageのスクロール制御 */
if ( cont->lastbutton & L_JPAD ) add_scrollx_rect( &gRect );
if ( cont->lastbutton & R_JPAD ) sub_scrollx_rect( &gRect );
if ( cont->lastbutton & U_JPAD ) add_scrolly_rect( &gRect );
if ( cont->lastbutton & D_JPAD ) sub_scrolly_rect( &gRect );
} else {
/* Texture Imageの拡大縮小 */
if ( cont->lastbutton & L_JPAD ) sub_scalex_rect( &gRect );
if ( cont->lastbutton & R_JPAD ) add_scalex_rect( &gRect );
if ( cont->lastbutton & U_JPAD ) sub_scaley_rect( &gRect );
if ( cont->lastbutton & D_JPAD ) add_scaley_rect( &gRect );
}
/* C UNITボタンの制御 */
/* Texture Imageサイズの変更 */
if ( cont->lastbutton & L_CBUTTONS ) sub_sc_width_rect( &gRect );
if ( cont->lastbutton & R_CBUTTONS ) add_sc_width_rect( &gRect );
if ( cont->lastbutton & U_CBUTTONS ) sub_sc_hight_rect( &gRect );
if ( cont->lastbutton & D_CBUTTONS ) add_sc_hight_rect( &gRect );
/* アナログスティック制御 */
/* Texture Rectangleの表示座標制御 */
if ( cont->stick_x < -3.0f ) sub_sclx_rect( &gRect );
if ( cont->stick_x > 3.0f ) add_sclx_rect( &gRect );
if ( cont->stick_y > 3.0f ) sub_scly_rect( &gRect );
if ( cont->stick_y < -3.0f ) add_scly_rect( &gRect );
/* RSP RDPの初期化 */
glistp = setup_rsprdp( glistp );
/* Texture Tileの描画 */
glistp = tile_rectangle( glistp, &gRect );
return glistp;
}
/*** Textureスクロールコントロール S ***/
static void add_scrollx_rect( Rectangle *rect )
{
int sc_max = rect->width - (int)(rect->sc_width / SCALE_VALUE(rect->scalex));
if(rect->scrollx < sc_max) {
u16 d = (u16)(2.0f * SCALE_VALUE(rect->scalex));
rect->scrollx += (u16)((d > 0) ? d : 1);
}
}
static void sub_scrollx_rect( Rectangle *rect )
{
int sc_d = (int)(2.0f * SCALE_VALUE(rect->scalex));
if(sc_d < 1) sc_d = 1;
rect->scrollx = (u16)((rect->scrollx > sc_d) ? rect->scrollx - sc_d : 0);
}
static void add_scrolly_rect( Rectangle *rect )
{
int sc_max = rect->height - (int)(rect->sc_height / SCALE_VALUE(rect->scaley));
if(rect->scrolly < sc_max) {
u16 d = (u16)(2.0f * SCALE_VALUE(rect->scaley));
rect->scrolly += (u16)((d > 0) ? d : 1);
}
}
static void sub_scrolly_rect( Rectangle *rect )
{
int sc_d = (int)(2.0f * SCALE_VALUE(rect->scaley));
if(sc_d < 1) sc_d = 1;
rect->scrolly = (u16)((rect->scrolly > sc_d) ? rect->scrolly - sc_d : 0);
}
/*** Textureスクロールコントロール E ***/
/*** Texture表示位置コントロール S ***/
static void add_sclx_rect( Rectangle *rect )
{
rect->sclx += 2;
}
static void sub_sclx_rect( Rectangle *rect )
{
rect->sclx -= 2;
}
static void add_scly_rect( Rectangle *rect )
{
rect->scly += 2;
}
static void sub_scly_rect( Rectangle *rect )
{
rect->scly -= 2;
}
/*** Texture表示位置コントロール E ***/
/*** Texture表示(レクタングル)サイズコントロール S */
static void add_sc_width_rect( Rectangle *rect )
{
float fScMax = (u16)((float)(rect->width - rect->scrollx) * SCALE_VALUE(rect->scalex));
if(rect->sc_width < fScMax) {
rect->sc_width += 2.0f;
}
}
static void sub_sc_width_rect( Rectangle *rect )
{
if ( rect->sc_width > 0.0f ) rect->sc_width -= 2.0f;
}
static void add_sc_hight_rect( Rectangle *rect )
{
float fScMax = (u16)((float)(rect->height - rect->scrolly) * SCALE_VALUE(rect->scaley));
if(rect->sc_height < fScMax) {
rect->sc_height += 2.0f;
}
}
static void sub_sc_hight_rect( Rectangle *rect )
{
if ( rect->sc_height > 0.0f ) rect->sc_height -= 2.0f;
}
/*** Texture表示(レクタングル)サイズコントロール E */
/*** Texture拡大・縮小コントロール S ***/
static void add_scalex_rect( Rectangle *rect )
{
if(rect->scalex < 6.0f) {
float fOldScw = rect->sc_width / rect->scalex;
rect->scalex += 0.05f;
rect->sc_width = fOldScw * rect->scalex;
}
}
static void sub_scalex_rect( Rectangle *rect )
{
if(rect->scalex > 0.25f) {
float fOldScw = rect->sc_width / rect->scalex;
rect->scalex -= 0.05f;
rect->sc_width = fOldScw * rect->scalex;
}
}
static void add_scaley_rect( Rectangle *rect )
{
if(rect->scaley < 6.0f) {
float fOldSch = rect->sc_height / rect->scaley;
rect->scaley += 0.05f;
rect->sc_height = fOldSch * rect->scaley;
}
}
static void sub_scaley_rect( Rectangle *rect )
{
if(rect->scaley > 0.25f) {
float fOldSch = rect->sc_height / rect->scaley;
rect->scaley -= 0.05f;
rect->sc_height = fOldSch * rect->scaley;
}
}
/*** Texture拡大・縮小コントロール E ***/