|
10 | 10 |
|
11 | 11 | // nxdk includes
|
12 | 12 | #include "src/nxdk/hal/debug.h"
|
13 |
| -#include "src/nxdk/hal/xbox.h" |
14 | 13 | #include "src/nxdk/hal/video.h"
|
| 14 | +#include "src/nxdk/hal/xbox.h" |
15 | 15 | #include "src/nxdk/windows.h"
|
16 | 16 |
|
17 | 17 | // local includes
|
18 | 18 | #include "src/os.h"
|
19 | 19 |
|
20 |
| -static void printSDLErrorAndReboot() |
21 |
| -{ |
22 |
| - debugPrint("SDL_Error: %s\n", SDL_GetError()); |
23 |
| - debugPrint("Rebooting in 5 seconds.\n"); |
24 |
| - Sleep(5000); |
25 |
| - XReboot(); |
| 20 | +static void printSDLErrorAndReboot() { |
| 21 | + debugPrint("SDL_Error: %s\n", SDL_GetError()); |
| 22 | + debugPrint("Rebooting in 5 seconds.\n"); |
| 23 | + Sleep(5000); |
| 24 | + XReboot(); |
26 | 25 | }
|
27 | 26 |
|
28 |
| -static void printIMGErrorAndReboot() |
29 |
| -{ |
30 |
| - debugPrint("SDL_Image Error: %s\n", IMG_GetError()); |
31 |
| - debugPrint("Rebooting in 5 seconds.\n"); |
32 |
| - Sleep(5000); |
33 |
| - XReboot(); |
| 27 | +static void printIMGErrorAndReboot() { |
| 28 | + debugPrint("SDL_Image Error: %s\n", IMG_GetError()); |
| 29 | + debugPrint("Rebooting in 5 seconds.\n"); |
| 30 | + Sleep(5000); |
| 31 | + XReboot(); |
34 | 32 | }
|
35 | 33 |
|
36 | 34 | // Screen dimension globals
|
37 | 35 | static int SCREEN_WIDTH;
|
38 | 36 | static int SCREEN_HEIGHT;
|
39 | 37 |
|
40 |
| -void splash_screen() |
41 |
| -{ |
42 |
| - int done = 0; |
43 |
| - SDL_Window *window; |
44 |
| - SDL_Event event; |
45 |
| - SDL_Surface *screenSurface, *imageSurface; |
46 |
| - |
47 |
| - // Enable standard application logging |
48 |
| - SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); |
| 38 | +void splash_screen() { |
| 39 | + int done = 0; |
| 40 | + SDL_Window *window; |
| 41 | + SDL_Event event; |
| 42 | + SDL_Surface *screenSurface, *imageSurface; |
| 43 | + |
| 44 | + // Enable standard application logging |
| 45 | + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); |
| 46 | + |
| 47 | + if (SDL_VideoInit(NULL) < 0) { |
| 48 | + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL video.\n"); |
| 49 | + printSDLErrorAndReboot(); |
| 50 | + } |
| 51 | + |
| 52 | + window = SDL_CreateWindow("splash", |
| 53 | + SDL_WINDOWPOS_UNDEFINED, |
| 54 | + SDL_WINDOWPOS_UNDEFINED, |
| 55 | + SCREEN_WIDTH, SCREEN_HEIGHT, |
| 56 | + SDL_WINDOW_SHOWN); |
| 57 | + if(window == NULL) { |
| 58 | + debugPrint( "Window could not be created!\n"); |
| 59 | + SDL_VideoQuit(); |
| 60 | + printSDLErrorAndReboot(); |
| 61 | + } |
49 | 62 |
|
50 |
| - if (SDL_VideoInit(NULL) < 0) { |
51 |
| - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL video.\n"); |
52 |
| - printSDLErrorAndReboot(); |
53 |
| - } |
| 63 | + if (!(IMG_Init(IMG_INIT_JPG) & IMG_INIT_JPG)) { |
| 64 | + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't intialize SDL_image.\n"); |
| 65 | + SDL_VideoQuit(); |
| 66 | + printIMGErrorAndReboot(); |
| 67 | + } |
54 | 68 |
|
55 |
| - window = SDL_CreateWindow("splash", |
56 |
| - SDL_WINDOWPOS_UNDEFINED, |
57 |
| - SDL_WINDOWPOS_UNDEFINED, |
58 |
| - SCREEN_WIDTH, SCREEN_HEIGHT, |
59 |
| - SDL_WINDOW_SHOWN); |
60 |
| - if(window == NULL) |
61 |
| - { |
62 |
| - debugPrint( "Window could not be created!\n"); |
63 |
| - SDL_VideoQuit(); |
64 |
| - printSDLErrorAndReboot(); |
65 |
| - } |
| 69 | + screenSurface = SDL_GetWindowSurface(window); |
| 70 | + if (!screenSurface) { |
| 71 | + SDL_VideoQuit(); |
| 72 | + printSDLErrorAndReboot(); |
| 73 | + } |
66 | 74 |
|
67 |
| - if (!(IMG_Init(IMG_INIT_JPG) & IMG_INIT_JPG)) { |
68 |
| - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't intialize SDL_image.\n"); |
69 |
| - SDL_VideoQuit(); |
70 |
| - printIMGErrorAndReboot(); |
71 |
| - } |
| 75 | + // set string variable for splash screen path |
| 76 | + std::string _splashScreenPath = std::string(DATA_PATH) + "assets" + PATH_SEP + "moonlight-splash-" + |
| 77 | + std::to_string(SCREEN_WIDTH) + "x" + std::to_string(SCREEN_HEIGHT) + ".jpg"; |
| 78 | + const char *splashScreenPath = _splashScreenPath.c_str(); |
72 | 79 |
|
73 |
| - screenSurface = SDL_GetWindowSurface(window); |
74 |
| - if (!screenSurface) { |
75 |
| - SDL_VideoQuit(); |
76 |
| - printSDLErrorAndReboot(); |
| 80 | + imageSurface = IMG_Load(splashScreenPath); |
| 81 | + if (!imageSurface) { |
| 82 | + SDL_VideoQuit(); |
| 83 | + printIMGErrorAndReboot(); |
| 84 | + } |
| 85 | + |
| 86 | + while (!done) { |
| 87 | + // Check for events |
| 88 | + while (SDL_PollEvent(&event)) { |
| 89 | + switch (event.type) { |
| 90 | + case SDL_QUIT: |
| 91 | + done = 1; |
| 92 | + break; |
| 93 | + default: |
| 94 | + break; |
| 95 | + } |
77 | 96 | }
|
78 | 97 |
|
79 |
| - // set string variable for splash screen path |
80 |
| - std::string _splashScreenPath = std::string(DATA_PATH) + "assets" + PATH_SEP + "moonlight-splash-" + |
81 |
| - std::to_string(SCREEN_WIDTH) + "x" + std::to_string(SCREEN_HEIGHT) + ".jpg"; |
82 |
| - const char *splashScreenPath = _splashScreenPath.c_str(); |
| 98 | + SDL_BlitSurface(imageSurface, NULL, screenSurface, NULL); |
| 99 | + SDL_UpdateWindowSurface(window); |
83 | 100 |
|
84 |
| - imageSurface = IMG_Load(splashScreenPath); |
85 |
| - if (!imageSurface) { |
86 |
| - SDL_VideoQuit(); |
87 |
| - printIMGErrorAndReboot(); |
88 |
| - } |
89 |
| - |
90 |
| - while (!done) { |
91 |
| - // Check for events |
92 |
| - while (SDL_PollEvent(&event)) { |
93 |
| - switch (event.type) { |
94 |
| - case SDL_QUIT: |
95 |
| - done = 1; |
96 |
| - break; |
97 |
| - default: |
98 |
| - break; |
99 |
| - } |
100 |
| - } |
101 |
| - |
102 |
| - SDL_BlitSurface(imageSurface, NULL, screenSurface, NULL); |
103 |
| - SDL_UpdateWindowSurface(window); |
104 |
| - |
105 |
| - Sleep(1000); |
106 |
| - } |
| 101 | + Sleep(1000); |
| 102 | + } |
107 | 103 |
|
108 |
| - SDL_VideoQuit(); |
| 104 | + SDL_VideoQuit(); |
109 | 105 | }
|
110 | 106 |
|
111 |
| -int main() |
112 |
| -{ |
113 |
| - // create an empty list for the available video modes |
114 |
| - std::vector<VIDEO_MODE> availableVideoModes; |
115 |
| - |
116 |
| - // save the best video mode here |
117 |
| - VIDEO_MODE bestVideoMode = {0, 0, 0, 0}; |
| 107 | +int main() { |
| 108 | + // create an empty list for the available video modes |
| 109 | + std::vector<VIDEO_MODE> availableVideoModes; |
118 | 110 |
|
119 |
| - VIDEO_MODE vm; |
120 |
| - int bpp = 32; // Bits per pixel |
121 |
| - void *p = NULL; // Initialize to NULL for the first call |
| 111 | + // save the best video mode here |
| 112 | + VIDEO_MODE bestVideoMode = {0, 0, 0, 0}; |
122 | 113 |
|
123 |
| - // get the available video modes |
124 |
| - while (XVideoListModes(&vm, bpp, REFRESH_DEFAULT, &p)) { |
125 |
| - availableVideoModes.push_back(vm); |
| 114 | + VIDEO_MODE vm; |
| 115 | + int bpp = 32; // Bits per pixel |
| 116 | + void *p = NULL; // Initialize to NULL for the first call |
126 | 117 |
|
127 |
| - // ensure height is equal to or better than the current best video mode |
128 |
| - if (vm.height < bestVideoMode.height) { |
129 |
| - continue; |
130 |
| - } |
| 118 | + // get the available video modes |
| 119 | + while (XVideoListModes(&vm, bpp, REFRESH_DEFAULT, &p)) { |
| 120 | + availableVideoModes.push_back(vm); |
131 | 121 |
|
132 |
| - // ensure width is equal to or better than the current best video mode |
133 |
| - if (vm.width < bestVideoMode.width) { |
134 |
| - continue; |
135 |
| - } |
| 122 | + // ensure height is equal to or better than the current best video mode |
| 123 | + if (vm.height < bestVideoMode.height) { |
| 124 | + continue; |
| 125 | + } |
136 | 126 |
|
137 |
| - // ensure bpp is equal to or better than the current best video mode |
138 |
| - if (vm.bpp < bestVideoMode.bpp) { |
139 |
| - continue; |
140 |
| - } |
| 127 | + // ensure width is equal to or better than the current best video mode |
| 128 | + if (vm.width < bestVideoMode.width) { |
| 129 | + continue; |
| 130 | + } |
141 | 131 |
|
142 |
| - // ensure refresh is equal to or better than the current best video mode |
143 |
| - if (vm.refresh < bestVideoMode.refresh) { |
144 |
| - continue; |
145 |
| - } |
| 132 | + // ensure bpp is equal to or better than the current best video mode |
| 133 | + if (vm.bpp < bestVideoMode.bpp) { |
| 134 | + continue; |
| 135 | + } |
146 | 136 |
|
147 |
| - // save the best video mode |
148 |
| - bestVideoMode = vm; |
| 137 | + // ensure refresh is equal to or better than the current best video mode |
| 138 | + if (vm.refresh < bestVideoMode.refresh) { |
| 139 | + continue; |
149 | 140 | }
|
150 | 141 |
|
151 |
| - SCREEN_WIDTH = bestVideoMode.width; |
152 |
| - SCREEN_HEIGHT = bestVideoMode.height; |
| 142 | + // save the best video mode |
| 143 | + bestVideoMode = vm; |
| 144 | + } |
153 | 145 |
|
154 |
| - XVideoSetMode(640, 480, 32, REFRESH_DEFAULT); |
| 146 | + SCREEN_WIDTH = bestVideoMode.width; |
| 147 | + SCREEN_HEIGHT = bestVideoMode.height; |
155 | 148 |
|
156 |
| - debugPrint("Available video modes:\n"); |
157 |
| - for (VIDEO_MODE vm : availableVideoModes) { |
158 |
| - debugPrint("Width: %d, Height: %d, BPP: %d, Refresh: %d\n", vm.width, vm.height, vm.bpp, vm.refresh); |
159 |
| - } |
| 149 | + XVideoSetMode(640, 480, 32, REFRESH_DEFAULT); |
| 150 | + |
| 151 | + debugPrint("Available video modes:\n"); |
| 152 | + for (VIDEO_MODE vm : availableVideoModes) { |
| 153 | + debugPrint("Width: %d, Height: %d, BPP: %d, Refresh: %d\n", vm.width, vm.height, vm.bpp, vm.refresh); |
| 154 | + } |
160 | 155 |
|
161 |
| - debugPrint("Best video mode:\n"); |
162 |
| - debugPrint("Width: %d, Height: %d, BPP: %d, Refresh: %d\n", bestVideoMode.width, bestVideoMode.height, bestVideoMode.bpp, bestVideoMode.refresh); |
| 156 | + debugPrint("Best video mode:\n"); |
| 157 | + debugPrint("Width: %d, Height: %d, BPP: %d, Refresh: %d\n", bestVideoMode.width, bestVideoMode.height, bestVideoMode.bpp, bestVideoMode.refresh); |
163 | 158 |
|
164 |
| - Sleep(2000); |
| 159 | + Sleep(2000); |
165 | 160 |
|
166 |
| - XVideoSetMode(SCREEN_WIDTH, SCREEN_HEIGHT, bestVideoMode.bpp, bestVideoMode.refresh); |
| 161 | + XVideoSetMode(SCREEN_WIDTH, SCREEN_HEIGHT, bestVideoMode.bpp, bestVideoMode.refresh); |
167 | 162 |
|
168 |
| - splash_screen(); |
169 |
| - return 0; |
| 163 | + splash_screen(); |
| 164 | + return 0; |
170 | 165 | }
|
0 commit comments