all repos — mgba @ da7853bda61525c854b3d275fc6154f7e07fe54d

mGBA Game Boy Advance Emulator

Mode 5
Jeffrey Pfau jeffrey@endrift.com
Sat, 20 Jul 2013 01:46:40 -0700
commit

da7853bda61525c854b3d275fc6154f7e07fe54d

parent

15a2e43b2bc280e85daefaee5f0ba53dd57dab06

1 files changed, 41 insertions(+), 9 deletions(-)

jump to
M src/gba/renderers/video-software.csrc/gba/renderers/video-software.c

@@ -29,6 +29,7 @@ static void _drawBackgroundMode0(struct GBAVideoSoftwareRenderer* renderer, struct GBAVideoSoftwareBackground* background, int y);

static void _drawBackgroundMode2(struct GBAVideoSoftwareRenderer* renderer, struct GBAVideoSoftwareBackground* background, int y); static void _drawBackgroundMode3(struct GBAVideoSoftwareRenderer* renderer, struct GBAVideoSoftwareBackground* background, int y); static void _drawBackgroundMode4(struct GBAVideoSoftwareRenderer* renderer, struct GBAVideoSoftwareBackground* background, int y); +static void _drawBackgroundMode5(struct GBAVideoSoftwareRenderer* renderer, struct GBAVideoSoftwareBackground* background, int y); static void _preprocessTransformedSprite(struct GBAVideoSoftwareRenderer* renderer, struct GBATransformedObj* sprite, int y); static void _preprocessSprite(struct GBAVideoSoftwareRenderer* renderer, struct GBAObj* sprite, int y); static void _postprocessSprite(struct GBAVideoSoftwareRenderer* renderer, int priority);

@@ -453,6 +454,9 @@ break;

case 4: _drawBackgroundMode4(renderer, &renderer->bg[2], y); break; + case 5: + _drawBackgroundMode5(renderer, &renderer->bg[2], y); + break; } renderer->bg[2].sx += renderer->bg[2].dmx; renderer->bg[2].sy += renderer->bg[2].dmy;

@@ -811,6 +815,7 @@ }

} #define BACKGROUND_BITMAP_INIT \ + (void)(unused); \ int32_t x = background->sx - background->dx; \ int32_t y = background->sy - background->dy; \ int32_t localX; \

@@ -821,11 +826,11 @@ flags |= FLAG_TARGET_1 * (background->target1 && renderer->blendEffect == BLEND_ALPHA); \

flags |= FLAG_TARGET_2 * background->target2; \ int variant = background->target1 && (renderer->blendEffect == BLEND_BRIGHTEN || renderer->blendEffect == BLEND_DARKEN); -#define BACKGROUND_BITMAP_ITERATE \ +#define BACKGROUND_BITMAP_ITERATE(W, H) \ x += background->dx; \ y += background->dy; \ \ - if (x < 0 || y < 0 || (x >> 8) >= VIDEO_HORIZONTAL_PIXELS || (y >> 8) >= VIDEO_VERTICAL_PIXELS) { \ + if (x < 0 || y < 0 || (x >> 8) >= W || (y >> 8) >= H) { \ continue; \ } else { \ localX = x; \

@@ -833,7 +838,6 @@ localY = y; \

} static void _drawBackgroundMode2(struct GBAVideoSoftwareRenderer* renderer, struct GBAVideoSoftwareBackground* background, int unused) { - (void)(unused); int sizeAdjusted = 0x8000 << background->size; BACKGROUND_BITMAP_INIT;

@@ -871,8 +875,6 @@ }

} static void _drawBackgroundMode3(struct GBAVideoSoftwareRenderer* renderer, struct GBAVideoSoftwareBackground* background, int unused) { - (void)(unused); - BACKGROUND_BITMAP_INIT; uint16_t color;

@@ -880,7 +882,7 @@ uint32_t color32;

int outX; for (outX = 0; outX < VIDEO_HORIZONTAL_PIXELS; ++outX) { - BACKGROUND_BITMAP_ITERATE; + BACKGROUND_BITMAP_ITERATE(VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS); color = ((uint16_t*)renderer->d.vram)[(localX >> 8) + (localY >> 8) * VIDEO_HORIZONTAL_PIXELS]; color32 = 0;

@@ -901,8 +903,6 @@ }

} static void _drawBackgroundMode4(struct GBAVideoSoftwareRenderer* renderer, struct GBAVideoSoftwareBackground* background, int unused) { - (void)(unused); - BACKGROUND_BITMAP_INIT; uint16_t color;

@@ -913,7 +913,7 @@ }

int outX; for (outX = 0; outX < VIDEO_HORIZONTAL_PIXELS; ++outX) { - BACKGROUND_BITMAP_ITERATE; + BACKGROUND_BITMAP_ITERATE(VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS); color = ((uint8_t*)renderer->d.vram)[offset + (localX >> 8) + (localY >> 8) * VIDEO_HORIZONTAL_PIXELS];

@@ -922,6 +922,38 @@ if (!variant) {

_composite(renderer, outX, renderer->normalPalette[color] | flags); } else { _composite(renderer, outX, renderer->variantPalette[color] | flags); + } + } + } +} + +static void _drawBackgroundMode5(struct GBAVideoSoftwareRenderer* renderer, struct GBAVideoSoftwareBackground* background, int unused) { + BACKGROUND_BITMAP_INIT; + + uint16_t color; + uint32_t color32; + uint32_t offset = 0; + if (renderer->dispcnt.frameSelect) { + offset = 0xA000; + } + + int outX; + for (outX = 0; outX < VIDEO_HORIZONTAL_PIXELS; ++outX) { + BACKGROUND_BITMAP_ITERATE(160, 128); + + color = ((uint16_t*)renderer->d.vram)[(localX >> 8) + (localY >> 8) * 160]; + color32 = 0; + color32 |= (color << 3) & 0xF8; + color32 |= (color << 6) & 0xF800; + color32 |= (color << 9) & 0xF80000; + + if (!(renderer->row[outX] & FLAG_FINALIZED)) { + if (!variant) { + _composite(renderer, outX, color32 | flags); + } else if (renderer->blendEffect == BLEND_BRIGHTEN) { + _composite(renderer, outX, _brighten(color32, renderer->bldy) | flags); + } else if (renderer->blendEffect == BLEND_DARKEN) { + _composite(renderer, outX, _darken(color32, renderer->bldy) | flags); } } }