1: /*
2: * Guitar-ZyX(tm)::MasterControlProgram - portable guitar F/X controller
3: * Copyright (C) 2009 Douglas McClendon
4: *
5: * This program is free software: you can redistribute it and/or modify
6: * it under the terms of the GNU General Public License as published by
7: * the Free Software Foundation, version 3 of the License.
8: *
9: * This program is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU General Public License for more details.
13: *
14: * You should have received a copy of the GNU General Public License
15: * along with this program. If not, see <http://www.gnu.org/licenses/>.
16: */
17: /*
18: #############################################################################
19: #############################################################################
20: ##
21: ## gzmcpc::mode__intro__credits: some source file
22: ##
23: #############################################################################
24: ##
25: ## Copyright 2008-2009 Douglas McClendon <dmc AT filteredperception DOT org>
26: ##
27: #############################################################################
28: #############################################################################
29: #
30: */
31:
32:
33:
34:
35: #include <nds.h>
36:
37: #include <stdio.h>
38:
39: #include <string.h>
40:
41:
42: #include "dmc.h"
43:
44: #include "graphics.h"
45:
46: #include "input.h"
47:
48: #include "mcp.h"
49:
50: #include "modes.h"
51:
52: #include "mode__intro__main.h"
53:
54: #include "mode__intro__credits.h"
55:
56: #include "network.h"
57:
58: #include "resources/bitmaps/guitar-zyx.splash.credits.h"
59:
60: #include "resources/bitmaps/dlava.h"
61:
62:
63:
64:
65:
66:
67:
68:
69: void mode__intro__credits___init(void) {
70:
71: // initialize main screen
72: videoSetMode(MODE_5_2D);
73:
74: // map main screen background fourth (128k) region to vram bank A
75: vramSetBankA(VRAM_A_MAIN_BG_0x06060000);
76:
77: // set the secondary/sub screen for text and a background
78: videoSetModeSub(MODE_5_2D);
79:
80: // map sub screen background (only? 1/4?) to vram bank C
81: vramSetBankC(VRAM_C_SUB_BG);
82:
83: // FRAK, may need to reimplement this with mcp_bg_init...
84: // XXX: time will tell if this flickers
85: consoleInit(&bottom_screen,
86: 0,
87: BgType_Text4bpp,
88: BgSize_T_256x256,
89: 31,
90: 0,
91: false,
92: true);
93:
94: // set printf sink
95: consoleSelect(&bottom_screen);
96:
97: // set console background layer to top priority
98: bgSetPriority(bottom_screen.bgId, 0);
99:
100: // note: this must be done _after_ consoleInit (as that resets it)
101: // and _after_ loading our 8bit indexed bitmap reloads it
102: // set to black to allow renderer to really control
103: BG_PALETTE_SUB[255] = RGB15(0, 0, 0);
104:
105: // unfaded
106: mcp_set_blend(MCP_MAIN_SCREEN,
107: MCP_MAX_BLEND_LEVEL);
108: mcp_set_blend(MCP_SUB_SCREEN,
109: MCP_MAX_BLEND_LEVEL);
110:
111: // fade the mainscreen background to/from black, layer 3
112: REG_BLDCNT = BLEND_FADE_BLACK | BLEND_SRC_BG3;
113: // fade the lava background to/from black, layer 3
114: REG_BLDCNT_SUB = BLEND_FADE_BLACK | BLEND_SRC_BG3;
115:
116: // init subscreen layer/background 3
117: // the mapbase offset of 24 here means 24*16k which means utilizing
118: // the 4th of the possible main background memory regions that vram
119: // bank A can be mapped to. I.e. above we mapped to the 4th. Had
120: // we mapped to the 1st, we would have used offset 0.
121: // note: vram bank A is 128k, i.e. 8 * 16k.
122: // note: *16k is because of bitmap type, else would be *2k
123: // bg3 = bgInit(3, BgType_Bmp16, BgSize_B16_256x256, 24, 0);
124: bg3 = mcp_bg_init(MCP_MAIN_SCREEN,
125: 3,
126: MCP_BG_HIDE,
127: BgType_Bmp16,
128: BgSize_B16_256x256,
129: 24,
130: 0);
131:
132: // its initial priority, lowest (to emphasize lack of other enabled layers)
133: // priorities 0..3, 0 highest priority
134: bgSetPriority(bg3, 3);
135:
136: // bgHide(bg3);
137:
138: // load main splash screen into screen/background memory (bgs3)
139: // note: if I wanted to do this quickly/perfectly/doublebufferred somehow
140: // I'm not sure if I'd need to tweak the bgInitSub offset or pointer
141: // here or some such. As it is, the fade to black ensures no tear
142: // as this new image gets loaded into display memory.
143: decompress(guitar_zyx_splash_creditsBitmap,
144: (u16*)bgGetGfxPtr(bg3),
145: LZ77Vram);
146:
147: bgShow(bg3);
148:
149: // note: using offset=4, because 4 will be 64k offset, where 31 above is 62k
150: // (thus above using only 2k? seems plausible with tiles for console text chars
151: // NOTE: if this flickers, could try 2 instead of 3
152: bgs3 = mcp_bg_init(MCP_SUB_SCREEN,
153: 3,
154: MCP_BG_HIDE,
155: BgType_Bmp8,
156: BgSize_B8_256x256,
157: 4,
158: 0);
159: // its initial priority, lowest (to emphasize lack of other enabled layers)
160: // priorities 0..3, 0 highest priority
161: bgSetPriority(bgs3, 2);
162:
163: // bgHide(bgs3);
164:
165: // as per libnds doc on dma
166: DC_FlushRange(dlavaBitmap, 256*256);
167: dmaCopy(dlavaBitmap, bgGetGfxPtr(bgs3), 256*256);
168: DC_FlushRange(dlavaPal, 256*2);
169: dmaCopy(dlavaPal, BG_PALETTE_SUB, 256*2);
170:
171: bgShow(bgs3);
172:
173: BG_PALETTE_SUB[255] = RGB15(0, 0, 0);
174: }
175:
176: void mode__intro__credits___top_renderer(void) {
177:
178: int t_blend;
179:
180: //
181: // initialize to unfaded values
182: //
183: t_blend = 0;
184:
185:
186: //
187: // do top background fade-in
188: //
189: if (mode_ms < INTRO__CREDITS__TOP_BG_FADE_IN_START_MS) {
190: t_blend = 31;
191: } else if (mode_ms < (INTRO__CREDITS__TOP_BG_FADE_IN_START_MS +
192: INTRO__CREDITS__TOP_BG_FADE_IN_DURATION_MS)) {
193: // main screen bg fade
194: t_blend = 31 - ((mode_ms - INTRO__CREDITS__TOP_BG_FADE_IN_START_MS) * 31 /
195: INTRO__CREDITS__TOP_BG_FADE_IN_DURATION_MS);
196:
197: }
198:
199: //
200: // handle fadeout
201: //
202: if (mode != next_mode) {
203: if ((mode_ms - exit_mode_ms) < INTRO__CREDITS__TOP_BG_FADE_OUT_DURATION_MS) {
204: t_blend = ((mode_ms - exit_mode_ms) *
205: 31 / INTRO__CREDITS__TOP_BG_FADE_OUT_DURATION_MS);
206: } else {
207: t_blend = 31;
208: }
209: // fadeouts should only be fading out
210: // i.e. this code may be executing right after an aborted fadein
211: // t_blend = MAX(REG_BLDY, t_blend);
212: t_blend = MAX(t_blend, mcp_get_blend(MCP_MAIN_SCREEN));
213: } // end handle fadeout
214:
215: // actually set the blend register value
216: mcp_set_blend(MCP_MAIN_SCREEN,
217: t_blend);
218:
219: }
220:
221:
222: void mode__intro__credits___bot_renderer(void) {
223:
224: unsigned char t_font_int;
225: int t_blend;
226:
227:
228: //
229: // initialize to unfaded values
230: //
231: t_blend = 0;
232: t_font_int = (unsigned char)((int)font_intensity * 1);
233:
234: //
235: // do bg fade-in
236: //
237: if (mode_ms < INTRO__CREDITS__BOT_BG_FADE_IN_START_MS) {
238: // pre fade-in
239: t_blend = 31;
240: } else if (mode_ms < (INTRO__CREDITS__BOT_BG_FADE_IN_START_MS +
241: INTRO__CREDITS__BOT_BG_FADE_IN_DURATION_MS)) {
242: // main screen bg fade-in
243: t_blend = 31 - ((mode_ms - INTRO__CREDITS__BOT_BG_FADE_IN_START_MS) * 31 /
244: INTRO__CREDITS__BOT_BG_FADE_IN_DURATION_MS);
245:
246: }
247:
248: //
249: // do text fade-in
250: //
251: if (mode_ms < INTRO__CREDITS__BOT_TXT_FADE_IN_START_MS) {
252: // pre fade-in
253: t_font_int = 0;
254: } else if (mode_ms < (INTRO__CREDITS__BOT_TXT_FADE_IN_START_MS +
255: INTRO__CREDITS__BOT_TXT_FADE_IN_DURATION_MS)) {
256: t_font_int = (unsigned char)((int)(font_intensity) *
257: (mode_ms - INTRO__CREDITS__BOT_TXT_FADE_IN_START_MS) /
258: INTRO__CREDITS__BOT_TXT_FADE_IN_DURATION_MS);
259: }
260:
261:
262: //
263: // do fadeout, possibly overriding above
264: //
265: if (mode != next_mode) {
266: // fade-out
267: if ((mode_ms - exit_mode_ms) < INTRO__CREDITS__BOT_BG_FADE_OUT_DURATION_MS) {
268: t_blend = ((mode_ms - exit_mode_ms) *
269: 31 / INTRO__CREDITS__BOT_BG_FADE_OUT_DURATION_MS);
270: } else {
271: t_blend = 31;
272: }
273: // only fadeout
274: t_blend = MAX(t_blend, mcp_get_blend(MCP_SUB_SCREEN));
275:
276: if ((mode_ms - exit_mode_ms) < INTRO__CREDITS__BOT_TXT_FADE_OUT_DURATION_MS) {
277: t_font_int = (unsigned char)((int)(font_intensity) *
278: (INTRO__CREDITS__BOT_TXT_FADE_OUT_DURATION_MS - (mode_ms - exit_mode_ms)) /
279: INTRO__CREDITS__BOT_TXT_FADE_OUT_DURATION_MS);
280: } else {
281: t_font_int = 0;
282: }
283: // only fadeout
284: t_font_int = MIN(t_font_int, RGB15_TO_G5(BG_PALETTE_SUB[255]));
285: }
286:
287: mcp_set_blend(MCP_SUB_SCREEN,
288: t_blend);
289: // set the font color from the calculated intensity (greenish)
290: BG_PALETTE_SUB[255] = RGB15(t_font_int / 3,
291: t_font_int,
292: t_font_int / 3);
293:
294:
295: // clear the console text
296: consoleClear();
297:
298: // tell user they can skip the intro
299: printf("\x1b[05;0H ~~~~~~~~~~~~~~~~~~~~~~ ");
300: printf("\x1b[06;0H ~~~~~~~~~~~~~~~~~~~~~~ ");
301:
302: printf("\x1b[08;0H Resistance ");
303:
304: printf("\x1b[10;0H is *NOT* futile ");
305:
306: printf("\x1b[12;0H ~~~~~~~~~~~~~~~~~~~~~~ ");
307: printf("\x1b[13;0H ~~~~~~~~~~~~~~~~~~~~~~ ");
308:
309:
310: printf("\x1b[17;0H press 'A' to go back ");
311:
312: }
313:
314: void mode__intro__credits___input_handler(void) {
315:
316: //
317: // handle input
318: //
319: if ((heldkeys & KEY_L) && (heldkeys & KEY_R)) {
320: //
321: // held(L)+held(R)+something
322: //
323:
324: } else if (heldkeys & KEY_L) {
325: //
326: // held(L)+something
327: //
328:
329: if (downkeys & KEY_X) {
330: }
331:
332: if (downkeys & KEY_Y) {
333: }
334:
335: if (downkeys & KEY_A) {
336: }
337:
338: if (downkeys & KEY_B) {
339: }
340:
341: } else if (heldkeys & KEY_R) {
342: //
343: // held(R)+something
344: //
345:
346: if (downkeys & KEY_UP) {
347: }
348:
349: if (downkeys & KEY_DOWN) {
350: }
351:
352: if (downkeys & KEY_LEFT) {
353: }
354:
355: if (downkeys & KEY_RIGHT) {
356: }
357:
358: } else {
359: //
360: // no interesting modifer keys held
361: //
362:
363: if (downkeys & KEY_START) {
364: }
365:
366: if (downkeys & KEY_SELECT) {
367: }
368:
369: if (downkeys & KEY_UP) {
370: }
371:
372: if (downkeys & KEY_DOWN) {
373: }
374:
375: if (downkeys & KEY_LEFT) {
376: }
377:
378: if (downkeys & KEY_RIGHT) {
379: }
380:
381: if (downkeys & KEY_X) {
382: }
383:
384: if (downkeys & KEY_Y) {
385: }
386:
387: if (downkeys & KEY_A) {
388: system_xmode_new(last_mode);
389: }
390:
391: if (downkeys & KEY_B) {
392: }
393:
394: }
395:
396:
397: // touchpad handling is independent of modifiers (at the moment)
398: if ((downkeys & KEY_TOUCH) || (heldkeys & KEY_TOUCH)) {
399:
400: }
401:
402: }
403:
404: void mode__intro__credits___idle(void) {
405: //
406: // handle fadeout
407: //
408: if (mode != next_mode) {
409: if (((mode_ms - exit_mode_ms) > INTRO__CREDITS__TOP_BG_FADE_OUT_DURATION_MS) &&
410: ((mode_ms - exit_mode_ms) > INTRO__CREDITS__BOT_BG_FADE_OUT_DURATION_MS) &&
411: ((mode_ms - exit_mode_ms) > INTRO__CREDITS__BOT_TXT_FADE_OUT_DURATION_MS)) {
412:
413: dmaFillHalfWords(0,
414: (u16*)bgGetGfxPtr(bg3),
415: 256 * 256 * 2);
416: // memptr = (u16*)bgGetGfxPtr(bg3);
417: // for (i = 0 ; i < (256 * 256) ; i++) memptr[i] = (u16)0;
418:
419: dmaFillHalfWords(0,
420: (u16*)bgGetGfxPtr(bgs3),
421: 256 * 256);
422:
423: dmaFillHalfWords(0,
424: (u16*)bgGetGfxPtr(bgs2),
425: 256 * 256);
426:
427: dmaFillHalfWords(0,
428: (u16*)bgGetGfxPtr(bgs0),
429: 256 * 256 / 2);
430:
431: system_xmode_real();
432: }
433: }
434: }
435:
436:
437: void mode__intro__credits___exit(void) {
438:
439: }
440:
441: