From 3af2a29cfef63c1866f5a70e599849d686a0f945 Mon Sep 17 00:00:00 2001 From: Pk11 Date: Sat, 16 Jan 2021 19:44:31 -0600 Subject: [PATCH] Fix tonccpy missing last byte in DS mode Cleanup in image.cpp is unrelated --- source/image.cpp | 7 +++---- source/tonccpy.c | 6 ++++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/source/image.cpp b/source/image.cpp index ceebf64..63e0fad 100644 --- a/source/image.cpp +++ b/source/image.cpp @@ -88,15 +88,14 @@ void Image::draw(int x, int y, bool top, int layer, bool copyPal) { if(copyPal) tonccpy((top ? BG_PALETTE : BG_PALETTE_SUB) + _palOfs, _palette.data(), _palette.size() * 2); - u8 *dst = (u8 *)bgGetGfxPtr(top ? layer : layer + 4); - int width = 256; + u8 *dst = (u8 *)bgGetGfxPtr(top ? layer : layer + 4) + y * 256 + x; // If full width and X is 0, copy it all in one go - if(_width == width && x == 0) { + if(_width == 256 && x == 0) { tonccpy(dst, _bitmap.data(), _width * _height); } else { for(int i = 0; i < _height; i++) { - tonccpy(dst + (y + i) * 256 + x, _bitmap.data() + i * _width, _width); + tonccpy(dst + i * 256, _bitmap.data() + i * _width, _width); } } } diff --git a/source/tonccpy.c b/source/tonccpy.c index 9618fc2..e4641cd 100644 --- a/source/tonccpy.c +++ b/source/tonccpy.c @@ -70,8 +70,10 @@ void tonccpy(void *dst, const void *src, uint size) { } // Tail: 1 byte. - if(size & 1) - *dst16 = (*dst16 & ~0xFF) | *src8; + if(size & 1) { + *dst16 &= ~0xFF; + *dst16 |= *src8; + } } //# toncset.c