summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPikalaxALT <pikalaxalt@gmail.com>2019-04-27 12:39:26 -0400
committerPikalaxALT <pikalaxalt@gmail.com>2019-04-27 12:39:26 -0400
commit523c53506da69eccebb95af1d1cb76803d0fb88f (patch)
treed28bb836f948ba97fbc618a5e7873d3c94be846c /src
parent9e4b16b614280e4092bb5e7a632d6a5cdff83110 (diff)
Port blit from Emerald
Diffstat (limited to 'src')
-rw-r--r--src/blit.c212
-rw-r--r--src/text.c2
-rw-r--r--src/window.c6
-rw-r--r--src/window_8bpp.c4
4 files changed, 215 insertions, 9 deletions
diff --git a/src/blit.c b/src/blit.c
new file mode 100644
index 000000000..969f89900
--- /dev/null
+++ b/src/blit.c
@@ -0,0 +1,212 @@
+#include "global.h"
+#include "blit.h"
+
+void BlitBitmapRect4BitWithoutColorKey(const struct Bitmap *src, struct Bitmap *dst, u16 srcX, u16 srcY, u16 dstX, u16 dstY, u16 width, u16 height)
+{
+ BlitBitmapRect4Bit(src, dst, srcX, srcY, dstX, dstY, width, height, 0xFF);
+}
+
+void BlitBitmapRect4Bit(const struct Bitmap *src, struct Bitmap *dst, u16 srcX, u16 srcY, u16 dstX, u16 dstY, u16 width, u16 height, u8 colorKey)
+{
+ s32 xEnd;
+ s32 yEnd;
+ s32 multiplierSrcY;
+ s32 multiplierDstY;
+ s32 loopSrcY, loopDstY;
+ s32 loopSrcX, loopDstX;
+ const u8 *pixelsSrc;
+ u8 *pixelsDst;
+ s32 toOrr;
+ s32 toAnd;
+ s32 toShift;
+
+ if (dst->width - dstX < width)
+ xEnd = (dst->width - dstX) + srcX;
+ else
+ xEnd = srcX + width;
+
+ if (dst->height - dstY < height)
+ yEnd = (dst->height - dstY) + srcY;
+ else
+ yEnd = height + srcY;
+
+ multiplierSrcY = (src->width + (src->width & 7)) >> 3;
+ multiplierDstY = (dst->width + (dst->width & 7)) >> 3;
+
+ if (colorKey == 0xFF)
+ {
+ for (loopSrcY = srcY, loopDstY = dstY; loopSrcY < yEnd; loopSrcY++, loopDstY++)
+ {
+ for (loopSrcX = srcX, loopDstX = dstX; loopSrcX < xEnd; loopSrcX++, loopDstX++)
+ {
+ pixelsSrc = src->pixels + ((loopSrcX >> 1) & 3) + ((loopSrcX >> 3) << 5) + (((loopSrcY >> 3) * multiplierSrcY) << 5) + ((u32)(loopSrcY << 0x1d) >> 0x1B);
+ pixelsDst = dst->pixels + ((loopDstX >> 1) & 3) + ((loopDstX >> 3) << 5) + (((loopDstY >> 3) * multiplierDstY) << 5) + ((u32)(loopDstY << 0x1d) >> 0x1B);
+ toOrr = ((*pixelsSrc >> ((loopSrcX & 1) << 2)) & 0xF);
+ toShift = ((loopDstX & 1) << 2);
+ toOrr <<= toShift;
+ toAnd = 0xF0 >> (toShift);
+ *pixelsDst = toOrr | (*pixelsDst & toAnd);
+ }
+ }
+ }
+ else
+ {
+ for (loopSrcY = srcY, loopDstY = dstY; loopSrcY < yEnd; loopSrcY++, loopDstY++)
+ {
+ for (loopSrcX = srcX, loopDstX = dstX; loopSrcX < xEnd; loopSrcX++, loopDstX++)
+ {
+ pixelsSrc = src->pixels + ((loopSrcX >> 1) & 3) + ((loopSrcX >> 3) << 5) + (((loopSrcY >> 3) * multiplierSrcY) << 5) + ((u32)(loopSrcY << 0x1d) >> 0x1B);
+ pixelsDst = dst->pixels + ((loopDstX >> 1) & 3) + ((loopDstX >> 3) << 5) + (((loopDstY >> 3) * multiplierDstY) << 5) + ((u32)(loopDstY << 0x1d) >> 0x1B);
+ toOrr = ((*pixelsSrc >> ((loopSrcX & 1) << 2)) & 0xF);
+ if (toOrr != colorKey)
+ {
+ toShift = ((loopDstX & 1) << 2);
+ toOrr <<= toShift;
+ toAnd = 0xF0 >> (toShift);
+ *pixelsDst = toOrr | (*pixelsDst & toAnd);
+ }
+ }
+ }
+ }
+}
+
+void FillBitmapRect4Bit(struct Bitmap *surface, u16 x, u16 y, u16 width, u16 height, u8 fillValue)
+{
+ s32 xEnd;
+ s32 yEnd;
+ s32 multiplierY;
+ s32 loopX, loopY;
+
+ xEnd = x + width;
+ if (xEnd > surface->width)
+ xEnd = surface->width;
+
+ yEnd = y + height;
+ if (yEnd > surface->height)
+ yEnd = surface->height;
+
+ multiplierY = (surface->width + (surface->width & 7)) >> 3;
+
+ for (loopY = y; loopY < yEnd; loopY++)
+ {
+ for (loopX = x; loopX < xEnd; loopX++)
+ {
+ u8 *pixels = surface->pixels + ((loopX >> 1) & 3) + ((loopX >> 3) << 5) + (((loopY >> 3) * multiplierY) << 5) + ((u32)(loopY << 0x1d) >> 0x1B);
+ if ((loopX & 1) != 0)
+ {
+ *pixels &= 0xF;
+ *pixels |= fillValue << 4;
+ }
+ else
+ {
+ *pixels &= 0xF0;
+ *pixels |= fillValue;
+ }
+ }
+ }
+}
+
+void BlitBitmapRect4BitTo8Bit(const struct Bitmap *src, struct Bitmap *dst, u16 srcX, u16 srcY, u16 dstX, u16 dstY, u16 width, u16 height, u8 colorKey, u8 paletteOffset)
+{
+ s32 palOffsetBits;
+ s32 xEnd;
+ s32 yEnd;
+ s32 multiplierSrcY;
+ s32 multiplierDstY;
+ s32 loopSrcY, loopDstY;
+ s32 loopSrcX, loopDstX;
+ const u8 *pixelsSrc;
+ u8 *pixelsDst;
+ s32 colorKeyBits;
+
+ palOffsetBits = (u32)(paletteOffset << 0x1C) >> 0x18;
+ colorKeyBits = (u32)(colorKey << 0x1C) >> 0x18;
+
+ if (dst->width - dstX < width)
+ xEnd = (dst->width - dstX) + srcX;
+ else
+ xEnd = width + srcX;
+
+ if (dst->height - dstY < height)
+ yEnd = (srcY + dst->height) - dstY;
+ else
+ yEnd = srcY + height;
+
+ multiplierSrcY = (src->width + (src->width & 7)) >> 3;
+ multiplierDstY = (dst->width + (dst->width & 7)) >> 3;
+
+ if (colorKey == 0xFF)
+ {
+ for (loopSrcY = srcY, loopDstY = dstY; loopSrcY < yEnd; loopSrcY++, loopDstY++)
+ {
+ pixelsSrc = src->pixels + ((srcX >> 1) & 3) + ((srcX >> 3) << 5) + (((loopSrcY >> 3) * multiplierSrcY) << 5) + ((u32)(loopSrcY << 0x1d) >> 0x1b);
+ for (loopSrcX = srcX, loopDstX = dstX; loopSrcX < xEnd; loopSrcX++, loopDstX++)
+ {
+ pixelsDst = dst->pixels + (loopDstX & 7) + ((loopDstX >> 3) << 6) + (((loopDstY >> 3) * multiplierDstY) << 6) + ((u32)(loopDstY << 0x1d) >> 0x1a);
+ if (loopSrcX & 1)
+ {
+ *pixelsDst = palOffsetBits + (*pixelsSrc >> 4);
+ }
+ else
+ {
+ pixelsSrc = src->pixels + ((loopSrcX >> 1) & 3) + ((loopSrcX >> 3) << 5) + (((loopSrcY >> 3) * multiplierSrcY) << 5) + ((u32)(loopSrcY << 0x1d) >> 0x1b);
+ *pixelsDst = palOffsetBits + (*pixelsSrc & 0xF);
+ }
+ }
+ }
+ }
+ else
+ {
+ for (loopSrcY = srcY, loopDstY = dstY; loopSrcY < yEnd; loopSrcY++, loopDstY++)
+ {
+ pixelsSrc = src->pixels + ((srcX >> 1) & 3) + ((srcX >> 3) << 5) + (((loopSrcY >> 3) * multiplierSrcY) << 5) + ((u32)(loopSrcY << 0x1d) >> 0x1b);
+ for (loopSrcX = srcX, loopDstX = dstX; loopSrcX < xEnd; loopSrcX++, loopDstX++)
+ {
+ if (loopSrcX & 1)
+ {
+ if ((*pixelsSrc & 0xF0) != colorKeyBits)
+ {
+ pixelsDst = dst->pixels + (loopDstX & 7) + ((loopDstX >> 3) << 6) + (((loopDstY >> 3) * multiplierDstY) << 6) + ((u32)(loopDstY << 0x1d) >> 0x1a);
+ *pixelsDst = palOffsetBits + (*pixelsSrc >> 4);
+ }
+ }
+ else
+ {
+ pixelsSrc = src->pixels + ((loopSrcX >> 1) & 3) + ((loopSrcX >> 3) << 5) + (((loopSrcY >> 3) * multiplierSrcY) << 5) + ((u32)(loopSrcY << 0x1d) >> 0x1b);
+ if ((*pixelsSrc & 0xF) != colorKey)
+ {
+ pixelsDst = dst->pixels + (loopDstX & 7) + ((loopDstX >> 3) << 6) + (((loopDstY >> 3) * multiplierDstY) << 6) + ((u32)(loopDstY << 0x1d) >> 0x1a);
+ *pixelsDst = palOffsetBits + (*pixelsSrc & 0xF);
+ }
+ }
+ }
+ }
+ }
+}
+
+void FillBitmapRect8Bit(struct Bitmap *surface, u16 x, u16 y, u16 width, u16 height, u8 fillValue)
+{
+ s32 xEnd;
+ s32 yEnd;
+ s32 multiplierY;
+ s32 loopX, loopY;
+
+ xEnd = x + width;
+ if (xEnd > surface->width)
+ xEnd = surface->width;
+
+ yEnd = y + height;
+ if (yEnd > surface->height)
+ yEnd = surface->height;
+
+ multiplierY = (surface->width + (surface->width & 7)) >> 3;
+
+ for (loopY = y; loopY < yEnd; loopY++)
+ {
+ for (loopX = x; loopX < xEnd; loopX++)
+ {
+ u8 *pixels = surface->pixels + (loopX & 7) + ((loopX >> 3) << 6) + (((loopY >> 3) * multiplierY) << 6) + ((u32)(loopY << 0x1d) >> 0x1a);
+ *pixels = fillValue;
+ }
+ }
+}
diff --git a/src/text.c b/src/text.c
index d74d77e2f..34ceb92d4 100644
--- a/src/text.c
+++ b/src/text.c
@@ -5,13 +5,13 @@
#include "window.h"
#include "text.h"
#include "sprite.h"
+#include "blit.h"
extern u8 gGlyphInfo[0x90];
extern u8 gUnknown_203ADFA;
extern u16 gTMCaseMainWindowPalette[];
extern const struct OamData gOamData_83AC9D0;
-extern void FillBitmapRect4Bit(struct Bitmap *surface, u16 x, u16 y, u16 width, u16 height, u8 fillValue);
extern void FillWindowPixelRect(u8 windowId, u8 fillValue, u16 x, u16 y, u16 width, u16 height);
extern void BlitBitmapRectToWindow(u8 windowId, const u8 *pixels, u16 srcX, u16 srcY, u16 srcWidth, int srcHeight, u16 destX, u16 destY, u16 rectWidth, u16 rectHeight);
extern u8 GetKeypadIconWidth(u8 keypadIconId);
diff --git a/src/window.c b/src/window.c
index 71cfa6898..c4ea49956 100644
--- a/src/window.c
+++ b/src/window.c
@@ -2,17 +2,13 @@
#include "window.h"
#include "malloc.h"
#include "bg.h"
+#include "blit.h"
u8 gWindowClearTile;
void *gWindowBgTilemapBuffers[4];
EWRAM_DATA struct Window gWindows[WINDOWS_MAX] = {0};
-extern void BlitBitmapRect4Bit(struct Bitmap *src, struct Bitmap *dest, u16 srcX, u16 srcY, u16 destX, u16 destY, u16 width, u16 height, u8 colorKey);
-extern void BlitBitmapRect4BitTo8Bit(struct Bitmap *src, struct Bitmap *dest, u16 srcX, u16 srcY, u16 destX, u16 destY, u16 width, u16 height, u8 colorKey, u8 paletteNum);
-extern void FillBitmapRect4Bit(struct Bitmap *surface, u16 x, u16 y, u16 width, u16 height, u8 fillValue);
-extern void FillBitmapRect8Bit(struct Bitmap *surface, u16 x, u16 y, u16 width, u16 height, u8 fillValue);
-
static u8 GetNumActiveWindowsOnBg(u8 bgId);
static const struct WindowTemplate sDummyWindowTemplate = {0xFF, 0, 0, 0, 0, 0, 0};
diff --git a/src/window_8bpp.c b/src/window_8bpp.c
index 5eac3c558..8e5d19565 100644
--- a/src/window_8bpp.c
+++ b/src/window_8bpp.c
@@ -2,13 +2,11 @@
#include "window.h"
#include "malloc.h"
#include "bg.h"
+#include "blit.h"
EWRAM_DATA static struct Window* sWindowPtr = NULL;
EWRAM_DATA static u16 sWindowSize = 0;
-extern void BlitBitmapRect4BitTo8Bit(struct Bitmap *src, struct Bitmap *dest, u16 srcX, u16 srcY, u16 destX, u16 destY, u16 width, u16 height, u8 colorKey, u8 paletteNum);
-extern void FillBitmapRect8Bit(struct Bitmap *surface, u16 x, u16 y, u16 width, u16 height, u8 fillValue);
-
static u8 GetNumActiveWindowsOnBg8Bit(u8 bgId);
static void nullsub_9(void)