diff options
author | Diegoisawesome <Diegoisawesome@users.noreply.github.com> | 2018-02-28 09:29:28 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-28 09:29:28 -0600 |
commit | 19b467e49f2a1dcf3845747dbc2f53586cc02fce (patch) | |
tree | 6dded1d66c6c125ecf41625f15ef655a00ca17b3 /src | |
parent | 5162393c166ab9a37ec22993df6588080f1a9aa0 (diff) | |
parent | 85a959f321dfa01c9c76f9c74fbbda55614271da (diff) |
Merge pull request #223 from DizzyEggg/decompile_blit
Decompile blit
Diffstat (limited to 'src')
-rw-r--r-- | src/blit.c | 209 | ||||
-rw-r--r-- | src/text.c | 12 | ||||
-rw-r--r-- | src/window.c | 23 |
3 files changed, 219 insertions, 25 deletions
diff --git a/src/blit.c b/src/blit.c new file mode 100644 index 000000000..b4d5f7de5 --- /dev/null +++ b/src/blit.c @@ -0,0 +1,209 @@ +#include "global.h" +#include "blit.h" + +void BlitBitmapRect4BitWithoutColorKey(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(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; + 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; + s32 toOrr1, toOrr2; + + 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; + toOrr1 = (u32)(fillValue << 0x1C) >> 0x18; + toOrr2 = (fillValue & 0xF); + + 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 << 0x1F) != 0) + *pixels = toOrr1 | (*pixels & 0xF); + else + *pixels = toOrr2 | (*pixels & 0xF0); + } + } +} + +void BlitBitmapRect4BitTo8Bit(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; + 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 a2495d068..eacfd2a1f 100644 --- a/src/text.c +++ b/src/text.c @@ -4,18 +4,15 @@ #include "m4a.h" #include "palette.h" #include "sound.h" +#include "constants/songs.h" #include "string_util.h" #include "window.h" #include "text.h" +#include "blit.h" -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); -extern void CopyWindowToVram(u8 windowId, u8 mode); extern u16 Font6Func(struct TextPrinter *textPrinter); extern u32 GetGlyphWidthFont6(u16 glyphId, bool32 isJapanese); -extern void PlaySE(u16 songNum); extern u8* UnkTextUtil_GetPtrI(u8 a1); extern int sub_8197964(); @@ -27,7 +24,6 @@ static u16 gLastTextBgColor; static u16 gLastTextFgColor; static u16 gLastTextShadowColor; -extern struct Main gMain; extern struct MusicPlayerInfo gMPlayInfo_BGM; const struct FontInfo *gFonts; @@ -1986,7 +1982,7 @@ bool16 TextPrinterWaitWithDownArrow(struct TextPrinter *textPrinter) if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { result = TRUE; - PlaySE(5); + PlaySE(SE_SELECT); } } return result; @@ -2004,7 +2000,7 @@ bool16 TextPrinterWait(struct TextPrinter *textPrinter) if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { result = TRUE; - PlaySE(5); + PlaySE(SE_SELECT); } } return result; diff --git a/src/window.c b/src/window.c index 589557d43..9a52a5a20 100644 --- a/src/window.c +++ b/src/window.c @@ -1,6 +1,8 @@ #include "global.h" #include "window.h" #include "malloc.h" +#include "bg.h" +#include "blit.h" u32 filler_03002F58; u32 filler_03002F5C; @@ -15,19 +17,6 @@ EWRAM_DATA struct Window gWindows[WINDOWS_MAX] = {0}; EWRAM_DATA static struct Window* sWindowPtr = NULL; EWRAM_DATA static u16 sWindowSize = 0; -extern void* GetBgTilemapBuffer(u8 bg); -extern int DummiedOutFireRedLeafGreenTileAllocFunc(int, int, int, int); -extern u16 GetBgAttribute(u8 bg, u8 attributeId); -extern void SetBgTilemapBuffer(u8 bg, void *tilemap); -extern void CopyBgTilemapBufferToVram(u8 bg); -extern u8 LoadBgTiles(u8 bg, void *src, u16 size, u16 destOffset); -extern void WriteSequenceToBgTilemapBuffer(u8 bg, u16 firstTileNum, u8 x, u8 y, u8 width, u8 height, u8 paletteSlot, u16 tileNumDelta); -extern void FillBgTilemapBufferRect(u8 bg, u16 tileNum, u8 x, u8 y, u8 width, u8 height, u8 palette); -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 u8 GetNumActiveWindowsOnBg8Bit(u8 bgId); @@ -130,13 +119,13 @@ u16 AddWindow(const struct WindowTemplate *template) u8 *allocatedTilemapBuffer; int i; - for (win = 0; win < 0x20; ++win) + for (win = 0; win < WINDOWS_MAX; ++win) { if ((bgLayer = gWindows[win].window.priority) == 0xFF) break; } - if (win == 0x20) + if (win == WINDOWS_MAX) return 0xFF; bgLayer = template->priority; @@ -199,13 +188,13 @@ int AddWindowWithoutTileMap(const struct WindowTemplate *template) u8 bgLayer; int allocatedBaseBlock; - for (win = 0; win < 0x20; ++win) + for (win = 0; win < WINDOWS_MAX; ++win) { if (gWindows[win].window.priority == 0xFF) break; } - if (win == 0x20) + if (win == WINDOWS_MAX) return 0xFF; bgLayer = template->priority; |