src/gb/renderers/software.c (view raw)
1/* Copyright (c) 2013-2016 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#include "software.h"
7
8#include "gb/io.h"
9#include "util/memory.h"
10
11static void GBVideoSoftwareRendererInit(struct GBVideoRenderer* renderer, enum GBModel model);
12static void GBVideoSoftwareRendererDeinit(struct GBVideoRenderer* renderer);
13static uint8_t GBVideoSoftwareRendererWriteVideoRegister(struct GBVideoRenderer* renderer, uint16_t address, uint8_t value);
14static void GBVideoSoftwareRendererWritePalette(struct GBVideoRenderer* renderer, int index, uint16_t value);
15static void GBVideoSoftwareRendererDrawRange(struct GBVideoRenderer* renderer, int startX, int endX, int y, struct GBObj** obj, size_t oamMax);
16static void GBVideoSoftwareRendererFinishScanline(struct GBVideoRenderer* renderer, int y);
17static void GBVideoSoftwareRendererFinishFrame(struct GBVideoRenderer* renderer);
18static void GBVideoSoftwareRendererGetPixels(struct GBVideoRenderer* renderer, unsigned* stride, const void** pixels);
19static void GBVideoSoftwareRendererPutPixels(struct GBVideoRenderer* renderer, unsigned stride, void* pixels);
20
21static void GBVideoSoftwareRendererDrawBackground(struct GBVideoSoftwareRenderer* renderer, uint8_t* maps, int startX, int endX, int y, int sx, int sy);
22static void GBVideoSoftwareRendererDrawObj(struct GBVideoSoftwareRenderer* renderer, struct GBObj* obj, int startX, int endX, int y);
23
24void GBVideoSoftwareRendererCreate(struct GBVideoSoftwareRenderer* renderer) {
25 renderer->d.init = GBVideoSoftwareRendererInit;
26 renderer->d.deinit = GBVideoSoftwareRendererDeinit;
27 renderer->d.writeVideoRegister = GBVideoSoftwareRendererWriteVideoRegister;
28 renderer->d.writePalette = GBVideoSoftwareRendererWritePalette,
29 renderer->d.drawRange = GBVideoSoftwareRendererDrawRange;
30 renderer->d.finishScanline = GBVideoSoftwareRendererFinishScanline;
31 renderer->d.finishFrame = GBVideoSoftwareRendererFinishFrame;
32 renderer->d.getPixels = GBVideoSoftwareRendererGetPixels;
33 renderer->d.putPixels = 0;
34
35 renderer->temporaryBuffer = 0;
36}
37
38static void GBVideoSoftwareRendererInit(struct GBVideoRenderer* renderer, enum GBModel model) {
39 struct GBVideoSoftwareRenderer* softwareRenderer = (struct GBVideoSoftwareRenderer*) renderer;
40 softwareRenderer->scy = 0;
41 softwareRenderer->scx = 0;
42 softwareRenderer->wy = 0;
43 softwareRenderer->currentWy = 0;
44 softwareRenderer->wx = 0;
45 softwareRenderer->model = model;
46
47 int y;
48 for (y = 0; y < GB_VIDEO_VERTICAL_PIXELS; ++y) {
49 color_t* row = &softwareRenderer->outputBuffer[softwareRenderer->outputBufferStride * y];
50 int x;
51 for (x = 0; x < GB_VIDEO_HORIZONTAL_PIXELS; ++x) {
52 row[x] = softwareRenderer->palette[0];
53 }
54 }
55}
56
57static void GBVideoSoftwareRendererDeinit(struct GBVideoRenderer* renderer) {
58 struct GBVideoSoftwareRenderer* softwareRenderer = (struct GBVideoSoftwareRenderer*) renderer;
59 UNUSED(softwareRenderer);
60}
61
62static uint8_t GBVideoSoftwareRendererWriteVideoRegister(struct GBVideoRenderer* renderer, uint16_t address, uint8_t value) {
63 struct GBVideoSoftwareRenderer* softwareRenderer = (struct GBVideoSoftwareRenderer*) renderer;
64 switch (address) {
65 case REG_LCDC:
66 softwareRenderer->lcdc = value;
67 break;
68 case REG_SCY:
69 softwareRenderer->scy = value;
70 break;
71 case REG_SCX:
72 softwareRenderer->scx = value;
73 break;
74 case REG_WY:
75 softwareRenderer->wy = value;
76 softwareRenderer->currentWy = value;
77 break;
78 case REG_WX:
79 softwareRenderer->wx = value;
80 break;
81 }
82 return value;
83}
84
85static void GBVideoSoftwareRendererWritePalette(struct GBVideoRenderer* renderer, int index, uint16_t value) {
86 struct GBVideoSoftwareRenderer* softwareRenderer = (struct GBVideoSoftwareRenderer*) renderer;
87#ifdef COLOR_16_BIT
88#ifdef COLOR_5_6_5
89 color_t color = 0;
90 color |= (value & 0x001F) << 11;
91 color |= (value & 0x03E0) << 1;
92 color |= (value & 0x7C00) >> 10;
93#else
94 color_t color = value;
95#endif
96#else
97 color_t color = 0;
98 color |= (value << 3) & 0xF8;
99 color |= (value << 6) & 0xF800;
100 color |= (value << 9) & 0xF80000;
101#endif
102 softwareRenderer->palette[index] = color;
103}
104
105static void GBVideoSoftwareRendererDrawRange(struct GBVideoRenderer* renderer, int startX, int endX, int y, struct GBObj** obj, size_t oamMax) {
106 struct GBVideoSoftwareRenderer* softwareRenderer = (struct GBVideoSoftwareRenderer*) renderer;
107 uint8_t* maps = &softwareRenderer->d.vram[GB_BASE_MAP];
108 if (GBRegisterLCDCIsTileMap(softwareRenderer->lcdc)) {
109 maps += GB_SIZE_MAP;
110 }
111 if (GBRegisterLCDCIsBgEnable(softwareRenderer->lcdc) || softwareRenderer->model >= GB_MODEL_CGB) {
112 if (GBRegisterLCDCIsWindow(softwareRenderer->lcdc) && softwareRenderer->wy <= y && endX >= softwareRenderer->wx - 7) {
113 if (softwareRenderer->wx - 7 > 0) {
114 GBVideoSoftwareRendererDrawBackground(softwareRenderer, maps, startX, softwareRenderer->wx - 7, y, softwareRenderer->scx, softwareRenderer->scy);
115 }
116
117 maps = &softwareRenderer->d.vram[GB_BASE_MAP];
118 if (GBRegisterLCDCIsWindowTileMap(softwareRenderer->lcdc)) {
119 maps += GB_SIZE_MAP;
120 }
121 GBVideoSoftwareRendererDrawBackground(softwareRenderer, maps, softwareRenderer->wx - 7, endX, y, 7 - softwareRenderer->wx, (softwareRenderer->currentWy - y) - softwareRenderer->wy);
122 } else {
123 GBVideoSoftwareRendererDrawBackground(softwareRenderer, maps, startX, endX, y, softwareRenderer->scx, softwareRenderer->scy);
124 }
125 } else {
126 memset(&softwareRenderer->row[startX], 0, endX - startX);
127 }
128
129 if (GBRegisterLCDCIsObjEnable(softwareRenderer->lcdc)) {
130 size_t i;
131 for (i = 0; i < oamMax; ++i) {
132 GBVideoSoftwareRendererDrawObj(softwareRenderer, obj[i], startX, endX, y);
133 }
134 }
135 color_t* row = &softwareRenderer->outputBuffer[softwareRenderer->outputBufferStride * y];
136 int x;
137 for (x = startX; x < (endX & ~7); x += 8) {
138 row[x] = softwareRenderer->palette[softwareRenderer->row[x] & 0x7F];
139 row[x + 1] = softwareRenderer->palette[softwareRenderer->row[x + 1] & 0x7F];
140 row[x + 2] = softwareRenderer->palette[softwareRenderer->row[x + 2] & 0x7F];
141 row[x + 3] = softwareRenderer->palette[softwareRenderer->row[x + 3] & 0x7F];
142 row[x + 4] = softwareRenderer->palette[softwareRenderer->row[x + 4] & 0x7F];
143 row[x + 5] = softwareRenderer->palette[softwareRenderer->row[x + 5] & 0x7F];
144 row[x + 6] = softwareRenderer->palette[softwareRenderer->row[x + 6] & 0x7F];
145 row[x + 7] = softwareRenderer->palette[softwareRenderer->row[x + 7] & 0x7F];
146 }
147 for (; x < endX; ++x) {
148 row[x] = softwareRenderer->palette[softwareRenderer->row[x] & 0x7F];
149 }
150}
151
152static void GBVideoSoftwareRendererFinishScanline(struct GBVideoRenderer* renderer, int y) {
153 struct GBVideoSoftwareRenderer* softwareRenderer = (struct GBVideoSoftwareRenderer*) renderer;
154 if (GBRegisterLCDCIsBgEnable(softwareRenderer->lcdc) && GBRegisterLCDCIsWindow(softwareRenderer->lcdc) && softwareRenderer->wy <= y && softwareRenderer->wx - 7 < GB_VIDEO_HORIZONTAL_PIXELS) {
155 ++softwareRenderer->currentWy;
156 }
157}
158
159static void GBVideoSoftwareRendererFinishFrame(struct GBVideoRenderer* renderer) {
160 struct GBVideoSoftwareRenderer* softwareRenderer = (struct GBVideoSoftwareRenderer*) renderer;
161
162 if (softwareRenderer->temporaryBuffer) {
163 mappedMemoryFree(softwareRenderer->temporaryBuffer, GB_VIDEO_HORIZONTAL_PIXELS * GB_VIDEO_VERTICAL_PIXELS * 4);
164 softwareRenderer->temporaryBuffer = 0;
165 }
166 softwareRenderer->currentWy = softwareRenderer->wy;
167}
168
169static void GBVideoSoftwareRendererDrawBackground(struct GBVideoSoftwareRenderer* renderer, uint8_t* maps, int startX, int endX, int y, int sx, int sy) {
170 uint8_t* data = renderer->d.vram;
171 uint8_t* attr = &maps[GB_SIZE_VRAM_BANK0];
172 if (!GBRegisterLCDCIsTileData(renderer->lcdc)) {
173 data += 0x1000;
174 }
175 int topY = (((y + sy) >> 3) & 0x1F) * 0x20;
176 int bottomY = (y + sy) & 7;
177 if (startX < 0) {
178 startX = 0;
179 }
180 int x;
181 if ((startX + sx) & 7) {
182 int startX2 = startX + 8 - ((startX + sx) & 7);
183 for (x = startX; x < startX2; ++x) {
184 uint8_t* localData = data;
185 int localY = bottomY;
186 int topX = ((x + sx) >> 3) & 0x1F;
187 int bottomX = 7 - ((x + sx) & 7);
188 int bgTile;
189 if (GBRegisterLCDCIsTileData(renderer->lcdc)) {
190 bgTile = maps[topX + topY];
191 } else {
192 bgTile = ((int8_t*) maps)[topX + topY];
193 }
194 int p = 0;
195 if (renderer->model >= GB_MODEL_CGB) {
196 GBObjAttributes attrs = attr[topX + topY];
197 p = GBObjAttributesGetCGBPalette(attrs) * 4;
198 if (GBObjAttributesIsPriority(attrs) && GBRegisterLCDCIsBgEnable(renderer->lcdc)) {
199 p |= 0x80;
200 }
201 if (GBObjAttributesIsBank(attrs)) {
202 localData += GB_SIZE_VRAM_BANK0;
203 }
204 if (GBObjAttributesIsYFlip(attrs)) {
205 localY = 7 - bottomY;
206 }
207 if (GBObjAttributesIsXFlip(attrs)) {
208 bottomX = 7 - bottomX;
209 }
210 }
211 uint8_t tileDataLower = localData[(bgTile * 8 + localY) * 2];
212 uint8_t tileDataUpper = localData[(bgTile * 8 + localY) * 2 + 1];
213 tileDataUpper >>= bottomX;
214 tileDataLower >>= bottomX;
215 renderer->row[x] = p | ((tileDataUpper & 1) << 1) | (tileDataLower & 1);
216 }
217 startX = startX2;
218 }
219 for (x = startX; x < endX; x += 8) {
220 uint8_t* localData = data;
221 int localY = bottomY;
222 int topX = ((x + sx) >> 3) & 0x1F;
223 int bgTile;
224 if (GBRegisterLCDCIsTileData(renderer->lcdc)) {
225 bgTile = maps[topX + topY];
226 } else {
227 bgTile = ((int8_t*) maps)[topX + topY];
228 }
229 int p = 0;
230 if (renderer->model >= GB_MODEL_CGB) {
231 GBObjAttributes attrs = attr[topX + topY];
232 p = GBObjAttributesGetCGBPalette(attrs) * 4;
233 if (GBObjAttributesIsPriority(attrs) && GBRegisterLCDCIsBgEnable(renderer->lcdc)) {
234 p |= 0x80;
235 }
236 if (GBObjAttributesIsBank(attrs)) {
237 localData += GB_SIZE_VRAM_BANK0;
238 }
239 if (GBObjAttributesIsYFlip(attrs)) {
240 localY = 7 - bottomY;
241 }
242 if (GBObjAttributesIsXFlip(attrs)) {
243 uint8_t tileDataLower = localData[(bgTile * 8 + localY) * 2];
244 uint8_t tileDataUpper = localData[(bgTile * 8 + localY) * 2 + 1];
245 renderer->row[x + 0] = p | ((tileDataUpper & 1) << 1) | (tileDataLower & 1);
246 renderer->row[x + 1] = p | (tileDataUpper & 2) | ((tileDataLower & 2) >> 1);
247 renderer->row[x + 2] = p | ((tileDataUpper & 4) >> 1) | ((tileDataLower & 4) >> 2);
248 renderer->row[x + 3] = p | ((tileDataUpper & 8) >> 2) | ((tileDataLower & 8) >> 3);
249 renderer->row[x + 4] = p | ((tileDataUpper & 16) >> 3) | ((tileDataLower & 16) >> 4);
250 renderer->row[x + 5] = p | ((tileDataUpper & 32) >> 4) | ((tileDataLower & 32) >> 5);
251 renderer->row[x + 6] = p | ((tileDataUpper & 64) >> 5) | ((tileDataLower & 64) >> 6);
252 renderer->row[x + 7] = p | ((tileDataUpper & 128) >> 6) | ((tileDataLower & 128) >> 7);
253 continue;
254 }
255 }
256 uint8_t tileDataLower = localData[(bgTile * 8 + localY) * 2];
257 uint8_t tileDataUpper = localData[(bgTile * 8 + localY) * 2 + 1];
258 renderer->row[x + 7] = p | ((tileDataUpper & 1) << 1) | (tileDataLower & 1);
259 renderer->row[x + 6] = p | (tileDataUpper & 2) | ((tileDataLower & 2) >> 1);
260 renderer->row[x + 5] = p | ((tileDataUpper & 4) >> 1) | ((tileDataLower & 4) >> 2);
261 renderer->row[x + 4] = p | ((tileDataUpper & 8) >> 2) | ((tileDataLower & 8) >> 3);
262 renderer->row[x + 3] = p | ((tileDataUpper & 16) >> 3) | ((tileDataLower & 16) >> 4);
263 renderer->row[x + 2] = p | ((tileDataUpper & 32) >> 4) | ((tileDataLower & 32) >> 5);
264 renderer->row[x + 1] = p | ((tileDataUpper & 64) >> 5) | ((tileDataLower & 64) >> 6);
265 renderer->row[x + 0] = p | ((tileDataUpper & 128) >> 6) | ((tileDataLower & 128) >> 7);
266 }
267}
268
269static void GBVideoSoftwareRendererDrawObj(struct GBVideoSoftwareRenderer* renderer, struct GBObj* obj, int startX, int endX, int y) {
270 int ix = obj->x - 8;
271 if (endX < ix || startX >= ix + 8) {
272 return;
273 }
274 if (obj->x < endX) {
275 endX = obj->x;
276 }
277 if (obj->x - 8 > startX) {
278 startX = obj->x - 8;
279 }
280 if (startX < 0) {
281 startX = 0;
282 }
283 uint8_t* data = renderer->d.vram;
284 int tileOffset = 0;
285 int bottomY;
286 if (GBObjAttributesIsYFlip(obj->attr)) {
287 bottomY = 7 - ((y - obj->y - 16) & 7);
288 if (GBRegisterLCDCIsObjSize(renderer->lcdc) && y - obj->y < -8) {
289 ++tileOffset;
290 }
291 } else {
292 bottomY = (y - obj->y - 16) & 7;
293 if (GBRegisterLCDCIsObjSize(renderer->lcdc) && y - obj->y >= -8) {
294 ++tileOffset;
295 }
296 }
297 if (GBRegisterLCDCIsObjSize(renderer->lcdc) && obj->tile & 1) {
298 --tileOffset;
299 }
300 uint8_t mask = GBObjAttributesIsPriority(obj->attr) ? 0xE3 : 0x60;
301 uint8_t mask2 = GBObjAttributesIsPriority(obj->attr) ? 0 : 0x83;
302 int p;
303 if (renderer->model >= GB_MODEL_CGB) {
304 p = (GBObjAttributesGetCGBPalette(obj->attr) + 8) * 4;
305 if (GBObjAttributesIsBank(obj->attr)) {
306 data += GB_SIZE_VRAM_BANK0;
307 }
308 if (!GBRegisterLCDCIsBgEnable(renderer->lcdc)) {
309 mask = 0x60;
310 mask2 = 0x83;
311 }
312 } else {
313 p = (GBObjAttributesGetPalette(obj->attr) + 8) * 4;
314 }
315 int bottomX;
316 int x = startX;
317 if ((x - obj->x) & 7) {
318 for (; x < endX; ++x) {
319 if (GBObjAttributesIsXFlip(obj->attr)) {
320 bottomX = (x - obj->x) & 7;
321 } else {
322 bottomX = 7 - ((x - obj->x) & 7);
323 }
324 int objTile = obj->tile + tileOffset;
325 uint8_t tileDataLower = data[(objTile * 8 + bottomY) * 2];
326 uint8_t tileDataUpper = data[(objTile * 8 + bottomY) * 2 + 1];
327 tileDataUpper >>= bottomX;
328 tileDataLower >>= bottomX;
329 color_t current = renderer->row[x];
330 if (((tileDataUpper | tileDataLower) & 1) && !(current & mask) && (current & mask2) <= 0x80) {
331 renderer->row[x] = p | ((tileDataUpper & 1) << 1) | (tileDataLower & 1);
332 }
333 }
334 } else if (GBObjAttributesIsXFlip(obj->attr)) {
335 int objTile = obj->tile + tileOffset;
336 uint8_t tileDataLower = data[(objTile * 8 + bottomY) * 2];
337 uint8_t tileDataUpper = data[(objTile * 8 + bottomY) * 2 + 1];
338 color_t current;
339 current = renderer->row[x];
340 if (((tileDataUpper | tileDataLower) & 1) && !(current & mask) && (current & mask2) <= 0x80) {
341 renderer->row[x] = p | ((tileDataUpper & 1) << 1) | (tileDataLower & 1);
342 }
343 current = renderer->row[x + 1];
344 if (((tileDataUpper | tileDataLower) & 2) && !(current & mask) && (current & mask2) <= 0x80) {
345 renderer->row[x + 1] = p | (tileDataUpper & 2) | ((tileDataLower & 2) >> 1);
346 }
347 current = renderer->row[x + 2];
348 if (((tileDataUpper | tileDataLower) & 4) && !(current & mask) && (current & mask2) <= 0x80) {
349 renderer->row[x + 2] = p | ((tileDataUpper & 4) >> 1) | ((tileDataLower & 4) >> 2);
350 }
351 current = renderer->row[x + 3];
352 if (((tileDataUpper | tileDataLower) & 8) && !(current & mask) && (current & mask2) <= 0x80) {
353 renderer->row[x + 3] = p | ((tileDataUpper & 8) >> 2) | ((tileDataLower & 8) >> 3);
354 }
355 current = renderer->row[x + 4];
356 if (((tileDataUpper | tileDataLower) & 16) && !(current & mask) && (current & mask2) <= 0x80) {
357 renderer->row[x + 4] = p | ((tileDataUpper & 16) >> 3) | ((tileDataLower & 16) >> 4);
358 }
359 current = renderer->row[x + 5];
360 if (((tileDataUpper | tileDataLower) & 32) && !(current & mask) && (current & mask2) <= 0x80) {
361 renderer->row[x + 5] = p | ((tileDataUpper & 32) >> 4) | ((tileDataLower & 32) >> 5);
362 }
363 current = renderer->row[x + 6];
364 if (((tileDataUpper | tileDataLower) & 64) && !(current & mask) && (current & mask2) <= 0x80) {
365 renderer->row[x + 6] = p | ((tileDataUpper & 64) >> 5) | ((tileDataLower & 64) >> 6);
366 }
367 current = renderer->row[x + 7];
368 if (((tileDataUpper | tileDataLower) & 128) && !(current & mask) && (current & mask2) <= 0x80) {
369 renderer->row[x + 7] = p | ((tileDataUpper & 128) >> 6) | ((tileDataLower & 128) >> 7);
370 }
371 } else {
372 int objTile = obj->tile + tileOffset;
373 uint8_t tileDataLower = data[(objTile * 8 + bottomY) * 2];
374 uint8_t tileDataUpper = data[(objTile * 8 + bottomY) * 2 + 1];
375 color_t current;
376 current = renderer->row[x + 7];
377 if (((tileDataUpper | tileDataLower) & 1) && !(current & mask) && (current & mask2) <= 0x80) {
378 renderer->row[x + 7] = p | ((tileDataUpper & 1) << 1) | (tileDataLower & 1);
379 }
380 current = renderer->row[x + 6];
381 if (((tileDataUpper | tileDataLower) & 2) && !(current & mask) && (current & mask2) <= 0x80) {
382 renderer->row[x + 6] = p | (tileDataUpper & 2) | ((tileDataLower & 2) >> 1);
383 }
384 current = renderer->row[x + 5];
385 if (((tileDataUpper | tileDataLower) & 4) && !(current & mask) && (current & mask2) <= 0x80) {
386 renderer->row[x + 5] = p | ((tileDataUpper & 4) >> 1) | ((tileDataLower & 4) >> 2);
387 }
388 current = renderer->row[x + 4];
389 if (((tileDataUpper | tileDataLower) & 8) && !(current & mask) && (current & mask2) <= 0x80) {
390 renderer->row[x + 4] = p | ((tileDataUpper & 8) >> 2) | ((tileDataLower & 8) >> 3);
391 }
392 current = renderer->row[x + 3];
393 if (((tileDataUpper | tileDataLower) & 16) && !(current & mask) && (current & mask2) <= 0x80) {
394 renderer->row[x + 3] = p | ((tileDataUpper & 16) >> 3) | ((tileDataLower & 16) >> 4);
395 }
396 current = renderer->row[x + 2];
397 if (((tileDataUpper | tileDataLower) & 32) && !(current & mask) && (current & mask2) <= 0x80) {
398 renderer->row[x + 2] = p | ((tileDataUpper & 32) >> 4) | ((tileDataLower & 32) >> 5);
399 }
400 current = renderer->row[x + 1];
401 if (((tileDataUpper | tileDataLower) & 64) && !(current & mask) && (current & mask2) <= 0x80) {
402 renderer->row[x + 1] = p | ((tileDataUpper & 64) >> 5) | ((tileDataLower & 64) >> 6);
403 }
404 current = renderer->row[x];
405 if (((tileDataUpper | tileDataLower) & 128) && !(current & mask) && (current & mask2) <= 0x80) {
406 renderer->row[x] = p | ((tileDataUpper & 128) >> 6) | ((tileDataLower & 128) >> 7);
407 }
408 }
409}
410
411static void GBVideoSoftwareRendererGetPixels(struct GBVideoRenderer* renderer, unsigned* stride, const void** pixels) {
412 struct GBVideoSoftwareRenderer* softwareRenderer = (struct GBVideoSoftwareRenderer*) renderer;
413 // TODO: Share with GBAVideoSoftwareRendererGetPixels
414#ifdef COLOR_16_BIT
415 *stride = GB_VIDEO_HORIZONTAL_PIXELS;
416 if (!softwareRenderer->temporaryBuffer) {
417 softwareRenderer->temporaryBuffer = anonymousMemoryMap(GB_VIDEO_HORIZONTAL_PIXELS * GB_VIDEO_VERTICAL_PIXELS * 4);
418 }
419 *pixels = softwareRenderer->temporaryBuffer;
420 unsigned y, x;
421 for (y = 0; y < GB_VIDEO_VERTICAL_PIXELS; ++y) {
422 for (x = 0; x < GB_VIDEO_HORIZONTAL_PIXELS; ++x) {
423 color_t inColor = softwareRenderer->outputBuffer[softwareRenderer->outputBufferStride * y + x];
424 uint32_t outColor;
425#ifdef COLOR_5_6_5
426 outColor = (inColor & 0x1F) << 19;
427 outColor |= (inColor & 0x7C0) << 5;
428 outColor |= (inColor & 0xF800) >> 8;
429#else
430 outColor = (inColor & 0x1F) << 3;
431 outColor |= (inColor & 0x3E0) << 6;
432 outColor |= (inColor & 0x7C00) << 9;
433#endif
434 softwareRenderer->temporaryBuffer[GB_VIDEO_HORIZONTAL_PIXELS * y + x] = outColor;
435 }
436 }
437#else
438 *stride = softwareRenderer->outputBufferStride;
439 *pixels = softwareRenderer->outputBuffer;
440#endif
441}