1 /*---------------------------------------------------------------------------*
2 Project: Dolphin OS screen print demo
3 File: report.c
4
5 Copyright 2002 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 $Log: report.c,v $
14 Revision 1.2 02/20/2006 04:13:11 mitu
15 changed include path from dolphin/ to revolution/.
16
17 Revision 1.1 01/13/2006 11:24:13 hiratsu
18 Initial check in.
19
20
21 2 8/26/02 13:57 Shiki
22 Clean up.
23
24 1 8/22/02 20:37 Shiki
25 Initial check-in.
26 $NoKeywords: $
27 *---------------------------------------------------------------------------*/
28
29 #include <string.h>
30 #include <demo.h>
31 #include <revolution.h>
32
33 #define LINES 24
34
35 GXColor Black = { 0, 0, 0, 0 };
36 GXColor Blue = { 0, 0, 192, 0 };
37 GXColor Red = { 255, 0, 0, 0 };
38 GXColor Green = { 0, 224, 0, 0 };
39 GXColor White = { 255, 255, 255, 0 };
40
41 static char ReportBuffer[4096];
42
DoReport(void)43 static void DoReport(void)
44 {
45 GXRenderModeObj* rmp;
46
47 rmp = DEMOGetRenderModeObj();
48 DEMOInitCaption(DM_FT_XLU, (s16) rmp->fbWidth, (s16) rmp->efbHeight);
49 DEMOSetROMFontSize(16, -1);
50 DEMORFPuts(25, 25, 0, ReportBuffer);
51 }
52
53 // Define program-specific OSReport() function.
OSReport(const char * msg,...)54 void OSReport(const char* msg, ...)
55 {
56 BOOL enabled;
57 va_list marker;
58 u32 len;
59 int c;
60 char* p;
61 char* q;
62
63 enabled = OSDisableInterrupts();
64
65 len = strlen(ReportBuffer);
66 va_start(marker, msg);
67 len += vsprintf(ReportBuffer + len, msg, marker);
68 va_end(marker);
69
70 c = 0;
71 q = ReportBuffer;
72 for (p = ReportBuffer; p < ReportBuffer + len; ++p)
73 {
74 if (*p == '\n')
75 {
76 ++c;
77 if (LINES <= c)
78 {
79 q = strchr(q, '\n');
80 }
81 }
82 }
83 if (LINES <= c)
84 {
85 memmove(ReportBuffer, q + 1, len - (q - ReportBuffer));
86 }
87
88 OSRestoreInterrupts(enabled);
89 }
90
main(void)91 void main(void)
92 {
93 OSTime t1, t2;
94 OSCalendarTime ct;
95
96 OSReport("This program illustrates how to implement program-specific\n"
97 "OSReport() function at the user-level.\n");
98
99 DEMOInit(NULL);
100 DEMOInitROMFont();
101
102 // Clear EFB
103 GXSetCopyClear(Blue, 0x00ffffff);
104 GXCopyDisp(DEMOGetCurrentBuffer(), GX_TRUE);
105
106 t1 = OSGetTime();
107 for (;;)
108 {
109 DEMOBeforeRender();
110 DoReport();
111 DEMODoneRender();
112
113 t2 = OSGetTime();
114 if (OSSecondsToTicks(1) < t2 - t1)
115 {
116 t1 = t2;
117 OSTicksToCalendarTime(t1, &ct);
118 OSReport("%02d:%02d %02d\n", ct.hour, ct.min, ct.sec);
119 }
120 }
121
122 OSHalt("End of demo");
123 }
124