all repos — mgba @ 36ea350c6a37fd851ea9dbb0881cc379198443c1

mGBA Game Boy Advance Emulator

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 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		break;
 77	case REG_WX:
 78		softwareRenderer->wx = value;
 79		break;
 80	}
 81	return value;
 82}
 83
 84static void GBVideoSoftwareRendererWritePalette(struct GBVideoRenderer* renderer, int index, uint16_t value) {
 85	struct GBVideoSoftwareRenderer* softwareRenderer = (struct GBVideoSoftwareRenderer*) renderer;
 86#ifdef COLOR_16_BIT
 87#ifdef COLOR_5_6_5
 88	color_t color = 0;
 89	color |= (value & 0x001F) << 11;
 90	color |= (value & 0x03E0) << 1;
 91	color |= (value & 0x7C00) >> 10;
 92#else
 93	color_t color = value;
 94#endif
 95#else
 96	color_t color = 0;
 97	color |= (value << 3) & 0xF8;
 98	color |= (value << 6) & 0xF800;
 99	color |= (value << 9) & 0xF80000;
100#endif
101	softwareRenderer->palette[index] = color;
102}
103
104static void GBVideoSoftwareRendererDrawRange(struct GBVideoRenderer* renderer, int startX, int endX, int y, struct GBObj* obj, size_t oamMax) {
105	struct GBVideoSoftwareRenderer* softwareRenderer = (struct GBVideoSoftwareRenderer*) renderer;
106	uint8_t* maps = &softwareRenderer->d.vram[GB_BASE_MAP];
107	if (GBRegisterLCDCIsTileMap(softwareRenderer->lcdc)) {
108		maps += GB_SIZE_MAP;
109	}
110	if (GBRegisterLCDCIsBgEnable(softwareRenderer->lcdc) || softwareRenderer->model >= GB_MODEL_CGB) {
111		if (GBRegisterLCDCIsWindow(softwareRenderer->lcdc) && softwareRenderer->wy <= y && endX >= softwareRenderer->wx - 7) {
112			if (softwareRenderer->wx - 7 > 0) {
113				GBVideoSoftwareRendererDrawBackground(softwareRenderer, maps, startX, softwareRenderer->wx - 7, softwareRenderer->scx, softwareRenderer->scy + y);
114			}
115
116			maps = &softwareRenderer->d.vram[GB_BASE_MAP];
117			if (GBRegisterLCDCIsWindowTileMap(softwareRenderer->lcdc)) {
118				maps += GB_SIZE_MAP;
119			}
120			GBVideoSoftwareRendererDrawBackground(softwareRenderer, maps, softwareRenderer->wx - 7, endX, 7 - softwareRenderer->wx, softwareRenderer->currentWy);
121		} else {
122			GBVideoSoftwareRendererDrawBackground(softwareRenderer, maps, startX, endX, softwareRenderer->scx, softwareRenderer->scy + y);
123		}
124	} else {
125		memset(&softwareRenderer->row[startX], 0, endX - startX);
126	}
127
128	if (GBRegisterLCDCIsObjEnable(softwareRenderer->lcdc)) {
129		size_t i;
130		for (i = 0; i < oamMax; ++i) {
131			GBVideoSoftwareRendererDrawObj(softwareRenderer, &obj[i], startX, endX, y);
132		}
133	}
134	color_t* row = &softwareRenderer->outputBuffer[softwareRenderer->outputBufferStride * y];
135	int x;
136	for (x = startX; x + 7 < (endX & ~7); x += 8) {
137		row[x] = softwareRenderer->palette[softwareRenderer->row[x] & 0x7F];
138		row[x + 1] = softwareRenderer->palette[softwareRenderer->row[x + 1] & 0x7F];
139		row[x + 2] = softwareRenderer->palette[softwareRenderer->row[x + 2] & 0x7F];
140		row[x + 3] = softwareRenderer->palette[softwareRenderer->row[x + 3] & 0x7F];
141		row[x + 4] = softwareRenderer->palette[softwareRenderer->row[x + 4] & 0x7F];
142		row[x + 5] = softwareRenderer->palette[softwareRenderer->row[x + 5] & 0x7F];
143		row[x + 6] = softwareRenderer->palette[softwareRenderer->row[x + 6] & 0x7F];
144		row[x + 7] = softwareRenderer->palette[softwareRenderer->row[x + 7] & 0x7F];
145	}
146	for (; x < endX; ++x) {
147		row[x] = softwareRenderer->palette[softwareRenderer->row[x] & 0x7F];
148	}
149}
150
151static void GBVideoSoftwareRendererFinishScanline(struct GBVideoRenderer* renderer, int y) {
152	struct GBVideoSoftwareRenderer* softwareRenderer = (struct GBVideoSoftwareRenderer*) renderer;
153	if (GBRegisterLCDCIsWindow(softwareRenderer->lcdc) && softwareRenderer->wy <= y && softwareRenderer->wx - 7 < GB_VIDEO_HORIZONTAL_PIXELS) {
154		++softwareRenderer->currentWy;
155	}
156}
157
158static void GBVideoSoftwareRendererFinishFrame(struct GBVideoRenderer* renderer) {
159	struct GBVideoSoftwareRenderer* softwareRenderer = (struct GBVideoSoftwareRenderer*) renderer;
160
161	if (softwareRenderer->temporaryBuffer) {
162		mappedMemoryFree(softwareRenderer->temporaryBuffer, GB_VIDEO_HORIZONTAL_PIXELS * GB_VIDEO_VERTICAL_PIXELS * 4);
163		softwareRenderer->temporaryBuffer = 0;
164	}
165	softwareRenderer->currentWy = 0;
166}
167
168static void GBVideoSoftwareRendererDrawBackground(struct GBVideoSoftwareRenderer* renderer, uint8_t* maps, int startX, int endX, int sx, int sy) {
169	uint8_t* data = renderer->d.vram;
170	uint8_t* attr = &maps[GB_SIZE_VRAM_BANK0];
171	if (!GBRegisterLCDCIsTileData(renderer->lcdc)) {
172		data += 0x1000;
173	}
174	int topY = ((sy >> 3) & 0x1F) * 0x20;
175	int bottomY = sy & 7;
176	if (startX < 0) {
177		startX = 0;
178	}
179	int x;
180	if ((startX + sx) & 7) {
181		int startX2 = startX + 8 - ((startX + sx) & 7);
182		for (x = startX; x < startX2; ++x) {
183			uint8_t* localData = data;
184			int localY = bottomY;
185			int topX = ((x + sx) >> 3) & 0x1F;
186			int bottomX = 7 - ((x + sx) & 7);
187			int bgTile;
188			if (GBRegisterLCDCIsTileData(renderer->lcdc)) {
189				bgTile = maps[topX + topY];
190			} else {
191				bgTile = ((int8_t*) maps)[topX + topY];
192			}
193			int p = 0;
194			if (renderer->model >= GB_MODEL_CGB) {
195				GBObjAttributes attrs = attr[topX + topY];
196				p = GBObjAttributesGetCGBPalette(attrs) * 4;
197				if (GBObjAttributesIsPriority(attrs) && GBRegisterLCDCIsBgEnable(renderer->lcdc)) {
198					p |= 0x80;
199				}
200				if (GBObjAttributesIsBank(attrs)) {
201					localData += GB_SIZE_VRAM_BANK0;
202				}
203				if (GBObjAttributesIsYFlip(attrs)) {
204					localY = 7 - bottomY;
205				}
206				if (GBObjAttributesIsXFlip(attrs)) {
207					bottomX = 7 - bottomX;
208				}
209			}
210			uint8_t tileDataLower = localData[(bgTile * 8 + localY) * 2];
211			uint8_t tileDataUpper = localData[(bgTile * 8 + localY) * 2 + 1];
212			tileDataUpper >>= bottomX;
213			tileDataLower >>= bottomX;
214			renderer->row[x] = p | ((tileDataUpper & 1) << 1) | (tileDataLower & 1);
215		}
216		startX = startX2;
217	}
218	for (x = startX; x < endX; x += 8) {
219		uint8_t* localData = data;
220		int localY = bottomY;
221		int topX = ((x + sx) >> 3) & 0x1F;
222		int bgTile;
223		if (GBRegisterLCDCIsTileData(renderer->lcdc)) {
224			bgTile = maps[topX + topY];
225		} else {
226			bgTile = ((int8_t*) maps)[topX + topY];
227		}
228		int p = 0;
229		if (renderer->model >= GB_MODEL_CGB) {
230			GBObjAttributes attrs = attr[topX + topY];
231			p = GBObjAttributesGetCGBPalette(attrs) * 4;
232			if (GBObjAttributesIsPriority(attrs) && GBRegisterLCDCIsBgEnable(renderer->lcdc)) {
233				p |= 0x80;
234			}
235			if (GBObjAttributesIsBank(attrs)) {
236				localData += GB_SIZE_VRAM_BANK0;
237			}
238			if (GBObjAttributesIsYFlip(attrs)) {
239				localY = 7 - bottomY;
240			}
241			if (GBObjAttributesIsXFlip(attrs)) {
242				uint8_t tileDataLower = localData[(bgTile * 8 + localY) * 2];
243				uint8_t tileDataUpper = localData[(bgTile * 8 + localY) * 2 + 1];
244				renderer->row[x + 0] = p | ((tileDataUpper & 1) << 1) | (tileDataLower & 1);
245				renderer->row[x + 1] = p | (tileDataUpper & 2) | ((tileDataLower & 2) >> 1);
246				renderer->row[x + 2] = p | ((tileDataUpper & 4) >> 1) | ((tileDataLower & 4) >> 2);
247				renderer->row[x + 3] = p | ((tileDataUpper & 8) >> 2) | ((tileDataLower & 8) >> 3);
248				renderer->row[x + 4] = p | ((tileDataUpper & 16) >> 3) | ((tileDataLower & 16) >> 4);
249				renderer->row[x + 5] = p | ((tileDataUpper & 32) >> 4) | ((tileDataLower & 32) >> 5);
250				renderer->row[x + 6] = p | ((tileDataUpper & 64) >> 5) | ((tileDataLower & 64) >> 6);
251				renderer->row[x + 7] = p | ((tileDataUpper & 128) >> 6) | ((tileDataLower & 128) >> 7);
252				continue;
253			}
254		}
255		uint8_t tileDataLower = localData[(bgTile * 8 + localY) * 2];
256		uint8_t tileDataUpper = localData[(bgTile * 8 + localY) * 2 + 1];
257		renderer->row[x + 7] = p | ((tileDataUpper & 1) << 1) | (tileDataLower & 1);
258		renderer->row[x + 6] = p | (tileDataUpper & 2) | ((tileDataLower & 2) >> 1);
259		renderer->row[x + 5] = p | ((tileDataUpper & 4) >> 1) | ((tileDataLower & 4) >> 2);
260		renderer->row[x + 4] = p | ((tileDataUpper & 8) >> 2) | ((tileDataLower & 8) >> 3);
261		renderer->row[x + 3] = p | ((tileDataUpper & 16) >> 3) | ((tileDataLower & 16) >> 4);
262		renderer->row[x + 2] = p | ((tileDataUpper & 32) >> 4) | ((tileDataLower & 32) >> 5);
263		renderer->row[x + 1] = p | ((tileDataUpper & 64) >> 5) | ((tileDataLower & 64) >> 6);
264		renderer->row[x + 0] = p | ((tileDataUpper & 128) >> 6) | ((tileDataLower & 128) >> 7);
265	}
266}
267
268static void GBVideoSoftwareRendererDrawObj(struct GBVideoSoftwareRenderer* renderer, struct GBObj* obj, int startX, int endX, int y) {
269	int ix = obj->x - 8;
270	if (endX < ix || startX >= ix + 8) {
271		return;
272	}
273	if (obj->x < endX) {
274		endX = obj->x;
275	}
276	if (obj->x - 8 > startX) {
277		startX = obj->x - 8;
278	}
279	if (startX < 0) {
280		startX = 0;
281	}
282	uint8_t* data = renderer->d.vram;
283	int tileOffset = 0;
284	int bottomY;
285	if (GBObjAttributesIsYFlip(obj->attr)) {
286		bottomY = 7 - ((y - obj->y - 16) & 7);
287		if (GBRegisterLCDCIsObjSize(renderer->lcdc) && y - obj->y < -8) {
288			++tileOffset;
289		}
290	} else {
291		bottomY = (y - obj->y - 16) & 7;
292		if (GBRegisterLCDCIsObjSize(renderer->lcdc) && y - obj->y >= -8) {
293			++tileOffset;
294		}
295	}
296	if (GBRegisterLCDCIsObjSize(renderer->lcdc) && obj->tile & 1) {
297		--tileOffset;
298	}
299	uint8_t mask = GBObjAttributesIsPriority(obj->attr) ? 0x63 : 0x60;
300	uint8_t mask2 = GBObjAttributesIsPriority(obj->attr) ? 0 : 0x83;
301	int p;
302	if (renderer->model >= GB_MODEL_CGB) {
303		p = (GBObjAttributesGetCGBPalette(obj->attr) + 8) * 4;
304		if (GBObjAttributesIsBank(obj->attr)) {
305			data += GB_SIZE_VRAM_BANK0;
306		}
307		if (!GBRegisterLCDCIsBgEnable(renderer->lcdc)) {
308			mask = 0x60;
309			mask2 = 0x83;
310		}
311	} else {
312		p = (GBObjAttributesGetPalette(obj->attr) + 8) * 4;
313	}
314	int bottomX;
315	int x = startX;
316	if ((x - obj->x) & 7) {
317		for (; x < endX; ++x) {
318			if (GBObjAttributesIsXFlip(obj->attr)) {
319				bottomX = (x - obj->x) & 7;
320			} else {
321				bottomX = 7 - ((x - obj->x) & 7);
322			}
323			int objTile = obj->tile + tileOffset;
324			uint8_t tileDataLower = data[(objTile * 8 + bottomY) * 2];
325			uint8_t tileDataUpper = data[(objTile * 8 + bottomY) * 2 + 1];
326			tileDataUpper >>= bottomX;
327			tileDataLower >>= bottomX;
328			color_t current = renderer->row[x];
329			if (((tileDataUpper | tileDataLower) & 1) && !(current & mask) && (current & mask2) <= 0x80) {
330				renderer->row[x] = p | ((tileDataUpper & 1) << 1) | (tileDataLower & 1);
331			}
332		}
333	} else if (GBObjAttributesIsXFlip(obj->attr)) {
334		int objTile = obj->tile + tileOffset;
335		uint8_t tileDataLower = data[(objTile * 8 + bottomY) * 2];
336		uint8_t tileDataUpper = data[(objTile * 8 + bottomY) * 2 + 1];
337		color_t current;
338		current = renderer->row[x];
339		if (((tileDataUpper | tileDataLower) & 1) && !(current & mask) && (current & mask2) <= 0x80) {
340			renderer->row[x] = p | ((tileDataUpper & 1) << 1) | (tileDataLower & 1);
341		}
342		current = renderer->row[x + 1];
343		if (((tileDataUpper | tileDataLower) & 2) && !(current & mask) && (current & mask2) <= 0x80) {
344			renderer->row[x + 1] = p | (tileDataUpper & 2) | ((tileDataLower & 2) >> 1);
345		}
346		current = renderer->row[x + 2];
347		if (((tileDataUpper | tileDataLower) & 4) && !(current & mask) && (current & mask2) <= 0x80) {
348			renderer->row[x + 2] = p | ((tileDataUpper & 4) >> 1) | ((tileDataLower & 4) >> 2);
349		}
350		current = renderer->row[x + 3];
351		if (((tileDataUpper | tileDataLower) & 8) && !(current & mask) && (current & mask2) <= 0x80) {
352			renderer->row[x + 3] = p | ((tileDataUpper & 8) >> 2) | ((tileDataLower & 8) >> 3);
353		}
354		current = renderer->row[x + 4];
355		if (((tileDataUpper | tileDataLower) & 16) && !(current & mask) && (current & mask2) <= 0x80) {
356			renderer->row[x + 4] = p | ((tileDataUpper & 16) >> 3) | ((tileDataLower & 16) >> 4);
357		}
358		current = renderer->row[x + 5];
359		if (((tileDataUpper | tileDataLower) & 32) && !(current & mask) && (current & mask2) <= 0x80) {
360			renderer->row[x + 5] = p | ((tileDataUpper & 32) >> 4) | ((tileDataLower & 32) >> 5);
361		}
362		current = renderer->row[x + 6];
363		if (((tileDataUpper | tileDataLower) & 64) && !(current & mask) && (current & mask2) <= 0x80) {
364			renderer->row[x + 6] = p | ((tileDataUpper & 64) >> 5) | ((tileDataLower & 64) >> 6);
365		}
366		current = renderer->row[x + 7];
367		if (((tileDataUpper | tileDataLower) & 128) && !(current & mask) && (current & mask2) <= 0x80) {
368			renderer->row[x + 7] = p | ((tileDataUpper & 128) >> 6) | ((tileDataLower & 128) >> 7);
369		}
370	} else {
371		int objTile = obj->tile + tileOffset;
372		uint8_t tileDataLower = data[(objTile * 8 + bottomY) * 2];
373		uint8_t tileDataUpper = data[(objTile * 8 + bottomY) * 2 + 1];
374		color_t current;
375		current = renderer->row[x + 7];
376		if (((tileDataUpper | tileDataLower) & 1) && !(current & mask) && (current & mask2) <= 0x80) {
377			renderer->row[x + 7] = p | ((tileDataUpper & 1) << 1) | (tileDataLower & 1);
378		}
379		current = renderer->row[x + 6];
380		if (((tileDataUpper | tileDataLower) & 2) && !(current & mask) && (current & mask2) <= 0x80) {
381			renderer->row[x + 6] = p | (tileDataUpper & 2) | ((tileDataLower & 2) >> 1);
382		}
383		current = renderer->row[x + 5];
384		if (((tileDataUpper | tileDataLower) & 4) && !(current & mask) && (current & mask2) <= 0x80) {
385			renderer->row[x + 5] = p | ((tileDataUpper & 4) >> 1) | ((tileDataLower & 4) >> 2);
386		}
387		current = renderer->row[x + 4];
388		if (((tileDataUpper | tileDataLower) & 8) && !(current & mask) && (current & mask2) <= 0x80) {
389			renderer->row[x + 4] = p | ((tileDataUpper & 8) >> 2) | ((tileDataLower & 8) >> 3);
390		}
391		current = renderer->row[x + 3];
392		if (((tileDataUpper | tileDataLower) & 16) && !(current & mask) && (current & mask2) <= 0x80) {
393			renderer->row[x + 3] = p | ((tileDataUpper & 16) >> 3) | ((tileDataLower & 16) >> 4);
394		}
395		current = renderer->row[x + 2];
396		if (((tileDataUpper | tileDataLower) & 32) && !(current & mask) && (current & mask2) <= 0x80) {
397			renderer->row[x + 2] = p | ((tileDataUpper & 32) >> 4) | ((tileDataLower & 32) >> 5);
398		}
399		current = renderer->row[x + 1];
400		if (((tileDataUpper | tileDataLower) & 64) && !(current & mask) && (current & mask2) <= 0x80) {
401			renderer->row[x + 1] = p | ((tileDataUpper & 64) >> 5) | ((tileDataLower & 64) >> 6);
402		}
403		current = renderer->row[x];
404		if (((tileDataUpper | tileDataLower) & 128) && !(current & mask) && (current & mask2) <= 0x80) {
405			renderer->row[x] = p | ((tileDataUpper & 128) >> 6) | ((tileDataLower & 128) >> 7);
406		}
407	}
408}
409
410static void GBVideoSoftwareRendererGetPixels(struct GBVideoRenderer* renderer, unsigned* stride, const void** pixels) {
411	struct GBVideoSoftwareRenderer* softwareRenderer = (struct GBVideoSoftwareRenderer*) renderer;
412	// TODO: Share with GBAVideoSoftwareRendererGetPixels
413#ifdef COLOR_16_BIT
414	*stride = GB_VIDEO_HORIZONTAL_PIXELS;
415	if (!softwareRenderer->temporaryBuffer) {
416		softwareRenderer->temporaryBuffer = anonymousMemoryMap(GB_VIDEO_HORIZONTAL_PIXELS * GB_VIDEO_VERTICAL_PIXELS * 4);
417	}
418	*pixels = softwareRenderer->temporaryBuffer;
419	unsigned y, x;
420	for (y = 0; y < GB_VIDEO_VERTICAL_PIXELS; ++y) {
421		for (x = 0; x < GB_VIDEO_HORIZONTAL_PIXELS; ++x) {
422			color_t inColor = softwareRenderer->outputBuffer[softwareRenderer->outputBufferStride * y + x];
423			uint32_t outColor;
424#ifdef COLOR_5_6_5
425			outColor = (inColor & 0x1F) << 19;
426			outColor |= (inColor & 0x7C0) << 5;
427			outColor |= (inColor & 0xF800) >> 8;
428#else
429			outColor = (inColor & 0x1F) << 3;
430			outColor |= (inColor & 0x3E0) << 6;
431			outColor |= (inColor & 0x7C00) << 9;
432#endif
433			softwareRenderer->temporaryBuffer[GB_VIDEO_HORIZONTAL_PIXELS * y + x] = outColor;
434		}
435	}
436#else
437	*stride = softwareRenderer->outputBufferStride;
438	*pixels = softwareRenderer->outputBuffer;
439#endif
440}