From cee18a572e3cb39b2ee34eb3328266401ec707bb Mon Sep 17 00:00:00 2001 From: kichikuou Date: Sun, 31 Jul 2022 12:44:30 +0900 Subject: [PATCH] Implement palette shift effect (CD 1001) Used in Toushin Toshi 2. --- src/ags.c | 14 ++++++++++++++ src/ags.h | 1 + src/ecopy.c | 15 +++++++-------- src/effect.h | 3 ++- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/ags.c b/src/ags.c index d071cc7..4220c55 100644 --- a/src/ags.c +++ b/src/ags.c @@ -301,6 +301,20 @@ void ags_getPixel(int x, int y, Palette *cell) { sdl_getPixel(x, y, cell); } +void ags_copyPaletteShift(int sx, int sy, int w, int h, int dx, int dy, BYTE sprite) { + if (!ags_check_param(&sx, &sy, &w, &h)) return; + if (!ags_check_param(&dx, &dy, &w, &h)) return; + + for (int y = 0; y < h; y++) { + BYTE *src = GETOFFSET_PIXEL(nact->ags.dib, sx, sy + y); + BYTE *dst = GETOFFSET_PIXEL(nact->ags.dib, dx, dy + y); + for (int x = 0; x < w; x++, src++, dst++) { + if (*src != sprite) + *dst = (*src & 0xf0) | (*dst & 0x0f); + } + } +} + void ags_changeColorArea(int sx, int sy, int w, int h, int dst, int src, int cnt) { if (nact->ags.world_depth != 8) return; diff --git a/src/ags.h b/src/ags.h index 8b06f73..e777d53 100644 --- a/src/ags.h +++ b/src/ags.h @@ -161,6 +161,7 @@ extern void ags_copyArea_shadow_withrate(int sx, int sy, int w, int h, int dx, i extern void ags_wrapColor(int x, int y, int w, int h, int p1, int p2); extern void ags_getPixel(int x, int y, Palette *cell); +extern void ags_copyPaletteShift(int sx, int sy, int w, int h, int dx, int dy, BYTE sprite); extern void ags_changeColorArea(int x, int y, int w, int h, int dst, int src, int cnt); extern void* ags_saveRegion(int x, int y, int w, int h); diff --git a/src/ecopy.c b/src/ecopy.c index aa239f1..9b859b1 100644 --- a/src/ecopy.c +++ b/src/ecopy.c @@ -284,11 +284,6 @@ static int eCopyArea1000(int sx, int sy, int w, int h, int dx, int dy, int opt, return sys_getInputInfo(); } -static int eCopyArea1001(int sx, int sy, int w, int h, int dx, int dy, int opt, int spCol) { - /* パレットシフト */ - return sys_getInputInfo(); -} - static int eCopyArea2000(int sx, int sy, int w, int h, int dx, int dy, int opt) { sdl_fillRectangleRGB(dx, dy, w, h, 0, 0, 0); ags_copyArea_alphaLevel(sx, sy, w, h, dx, dy, opt); @@ -401,6 +396,8 @@ static int duration(enum nact_effect effect, int opt, SDL_Rect *rect) { return opt ? opt : 1000; case NACT_EFFECT_LINEAR_BLUR: return opt ? opt : 1700; + case NACT_EFFECT_PALETTE_SHIFT: + return 0; } return 1000; } @@ -522,9 +519,11 @@ void ags_eCopyArea(int sx, int sy, int w, int h, int dx, int dy, int sw, int opt if (nact->ags.world_depth != 8) return; ret = eCopyArea1000(sx, sy, w, h, dx, dy, opt, spCol); break; - case 1001: - if (nact->ags.world_depth != 8) return; - ret = eCopyArea1001(sx, sy, w, h, dx, dy, opt, spCol); + case NACT_EFFECT_PALETTE_SHIFT: + if (nact->ags.world_depth != 8 || spCol == -1) return; + ags_copyPaletteShift(sx, sy, w, h, dx, dy, spCol); + ags_updateArea(dx, dy, w, h); + ret = sys_getInputInfo(); break; case 2000: if (nact->ags.world_depth == 8) return; diff --git a/src/effect.h b/src/effect.h index dc65546..7a21566 100644 --- a/src/effect.h +++ b/src/effect.h @@ -20,7 +20,7 @@ #ifndef __EFFECT_H__ #define __EFFECT_H__ -// Effect types of the CE command. +// Effect types of the CE/CD command. enum nact_effect { NACT_EFFECT_WIPE_IN = 7, NACT_EFFECT_WIPE_OUT = 8, @@ -64,6 +64,7 @@ enum nact_effect { NACT_EFFECT_WINDMILL_180 = 51, NACT_EFFECT_WINDMILL_360 = 52, NACT_EFFECT_LINEAR_BLUR = 53, + NACT_EFFECT_PALETTE_SHIFT = 1001, // CD command only }; // Effect types of SCAT.DrawEffect and Gpx.EffectCopy.