all repos — mgba @ a8beb9f5f38f44e937ff752aee55d9928bf297c4

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