diff options
author | Johannes Schickel | 2005-10-22 12:59:16 +0000 |
---|---|---|
committer | Johannes Schickel | 2005-10-22 12:59:16 +0000 |
commit | d8aa978ae74ae7ee00c38cb3aa0ec47050e47d46 (patch) | |
tree | 087cdfe6510c7a285d68e03e97fc3da53ef96f0e | |
parent | f8981765e924ecd632a99072287af7254eb9c4fc (diff) | |
download | scummvm-rg350-d8aa978ae74ae7ee00c38cb3aa0ec47050e47d46.tar.gz scummvm-rg350-d8aa978ae74ae7ee00c38cb3aa0ec47050e47d46.tar.bz2 scummvm-rg350-d8aa978ae74ae7ee00c38cb3aa0ec47050e47d46.zip |
Made the shape handling endian safe, also renamned some functions and
variables. (mostly the *Helper functions and decodeShape -> encodeShape)
But kept mouse handling.
svn-id: r19241
-rw-r--r-- | kyra/kyra.cpp | 18 | ||||
-rw-r--r-- | kyra/screen.cpp | 119 | ||||
-rw-r--r-- | kyra/screen.h | 8 |
3 files changed, 78 insertions, 67 deletions
diff --git a/kyra/kyra.cpp b/kyra/kyra.cpp index 851ad1dd70..9c92cb133a 100644 --- a/kyra/kyra.cpp +++ b/kyra/kyra.cpp @@ -957,15 +957,15 @@ void KyraEngine::snd_haltTrack() { void KyraEngine::loadMouseShapes() { loadBitmap("MOUSE.CPS", 3, 3, 0); _screen->_curPage = 2; - _itemShapes[4] = _screen->decodeShape(0, 0, 8, 10, 0); - _itemShapes[5] = _screen->decodeShape(0, 0x17, 0x20, 7, 0); - _itemShapes[6] = _screen->decodeShape(0x50, 0x12, 0x10, 9, 0); - _itemShapes[7] = _screen->decodeShape(0x60, 0x12, 0x10, 11, 0); - _itemShapes[8] = _screen->decodeShape(0x70, 0x12, 0x10, 9, 0); - _itemShapes[9] = _screen->decodeShape(0x80, 0x12, 0x10, 11, 0); - _itemShapes[10] = _screen->decodeShape(0x90, 0x12, 0x10, 10, 0); - _itemShapes[10] = _screen->decodeShape(0x90, 0x12, 0x10, 10, 0); - _itemShapes[364] = _screen->decodeShape(0x28, 0, 0x10, 13, 0); + _itemShapes[4] = _screen->encodeShape(0, 0, 8, 10, 0); + _itemShapes[5] = _screen->encodeShape(0, 0x17, 0x20, 7, 0); + _itemShapes[6] = _screen->encodeShape(0x50, 0x12, 0x10, 9, 0); + _itemShapes[7] = _screen->encodeShape(0x60, 0x12, 0x10, 11, 0); + _itemShapes[8] = _screen->encodeShape(0x70, 0x12, 0x10, 9, 0); + _itemShapes[9] = _screen->encodeShape(0x80, 0x12, 0x10, 11, 0); + _itemShapes[10] = _screen->encodeShape(0x90, 0x12, 0x10, 10, 0); + _itemShapes[10] = _screen->encodeShape(0x90, 0x12, 0x10, 10, 0); + _itemShapes[364] = _screen->encodeShape(0x28, 0, 0x10, 13, 0); _screen->setMouseCursor(1, 1, 0); _screen->setMouseCursor(1, 1, _itemShapes[4]); _screen->setShapePages(3, 5); diff --git a/kyra/screen.cpp b/kyra/screen.cpp index c89ab01cbb..c95ce3bfeb 100644 --- a/kyra/screen.cpp +++ b/kyra/screen.cpp @@ -940,8 +940,8 @@ void Screen::decodeFrameDeltaPage(uint8 *dst, const uint8 *src, int pitch) { } } -uint8 *Screen::decodeShape(int x, int y, int w, int h, int flags) { - debug(9, "decodeShape(%d, %d, %d, %d, %d)", x, y, w, h, flags); +uint8 *Screen::encodeShape(int x, int y, int w, int h, int flags) { + debug(9, "encodeShape(%d, %d, %d, %d, %d)", x, y, w, h, flags); uint8 *srcPtr = &_pagePtrs[_curPage][y * SCREEN_W + x]; int16 shapeSize = 0; uint8 *tmp = srcPtr; @@ -998,12 +998,12 @@ uint8 *Screen::decodeShape(int x, int y, int w, int h, int flags) { assert(newShape); byte *dst = newShape; - *(uint16*)dst = flags & 3; dst += 2; + WRITE_LE_UINT16(dst, (flags & 3)); dst += 2; *dst = h; dst += 1; - *(uint16*)dst = w; dst += 2; + WRITE_LE_UINT16(dst, w); dst += 2; *dst = h; dst += 1; - *(uint16*)dst = shapeSize; dst += 2; - *(uint16*)dst = shapeSize2; dst += 2; + WRITE_LE_UINT16(dst, shapeSize); dst += 2; + WRITE_LE_UINT16(dst, shapeSize2); dst += 2; byte *src = srcPtr; if (flags & 1) { @@ -1063,7 +1063,9 @@ uint8 *Screen::decodeShape(int x, int y, int w, int h, int flags) { if (!(flags & 2)) { if (shapeSize > _animBlockSize) { dst = newShape; - *(uint16*)dst |= 2; + flags = READ_LE_UINT16(dst); + flags |= 2; + WRITE_LE_UINT16(dst, flags); } else { src = newShape; if (flags & 1) { @@ -1074,7 +1076,7 @@ uint8 *Screen::decodeShape(int x, int y, int w, int h, int flags) { dst = _animBlockPtr; memcpy(dst, src, shapeSize2); - int16 size = decodeShapeHelper(_animBlockPtr, shapePtrBackUp, shapeSize2); + int16 size = encodeShapeAndCalculateSize(_animBlockPtr, shapePtrBackUp, shapeSize2); if (size > shapeSize2) { shapeSize -= shapeSize2 - size; newShape = (uint8*)realloc(newShape, shapeSize); @@ -1084,12 +1086,14 @@ uint8 *Screen::decodeShape(int x, int y, int w, int h, int flags) { src = _animBlockPtr; memcpy(dst, src, shapeSize2); dst = newShape; - *(uint16*)dst |= 2; + flags = READ_LE_UINT16(dst); + flags |= 2; + WRITE_LE_UINT16(dst, flags); } } } - *(uint16*)(newShape + 6) = shapeSize; + WRITE_LE_UINT16((newShape + 6), shapeSize); if (flags & 1) { dst = newShape + 10; @@ -1100,11 +1104,11 @@ uint8 *Screen::decodeShape(int x, int y, int w, int h, int flags) { return newShape; } -int16 Screen::decodeShapeHelper(uint8 *from, uint8 *to, int size_to) { - debug(9, "decodeShapeHelper(0x%X, 0x%X, %d)", from, to, size_to); +int16 Screen::encodeShapeAndCalculateSize(uint8 *from, uint8 *to, int size_to) { + debug(9, "encodeShapeAndCalculateSize(0x%X, 0x%X, %d)", from, to, size_to); byte *fromPtrEnd = from + size_to; - int var1 = 1; - byte *var7 = 0; + bool skipPixel = true; + byte *tempPtr = 0; byte *toPtr = to; byte *fromPtr = from; byte *toPtr2 = to; @@ -1115,7 +1119,7 @@ int16 Screen::decodeShapeHelper(uint8 *from, uint8 *to, int size_to) { while (from < fromPtrEnd) { byte *curToPtr = to; to = fromPtr; - int var6 = 1; + int size = 1; while (true) { byte curPixel = *from; @@ -1128,13 +1132,13 @@ int16 Screen::decodeShapeHelper(uint8 *from, uint8 *to, int size_to) { break; } --to; - uint16 size = (to - from); - if (size >= 0x41) { - var1 = 0; + uint16 diffSize = (to - from); + if (diffSize >= 0x41) { + skipPixel = false; from = to; to = curToPtr; *to++ = 0xFE; - WRITE_LE_UINT16(to, size); to += 2; + WRITE_LE_UINT16(to, diffSize); to += 2; *to++ = (size >> 8) & 0xFF; curToPtr = to; to = toBackUp; @@ -1155,7 +1159,7 @@ int16 Screen::decodeShapeHelper(uint8 *from, uint8 *to, int size_to) { break; } if (*to == curPixel) { - if (*(from+var6-1) == *(to+var6-2)) + if (*(from+size-1) == *(to+size-2)) break; byte *fromBackUp = from; @@ -1170,9 +1174,9 @@ int16 Screen::decodeShapeHelper(uint8 *from, uint8 *to, int size_to) { from = fromBackUp; int temp = to - toBackUp; to = toBackUp; - if (temp >= var6) { - var6 = temp; - var7 = toBackUp - 1; + if (temp >= size) { + size = temp; + tempPtr = toBackUp - 1; } break; } else { @@ -1186,33 +1190,33 @@ int16 Screen::decodeShapeHelper(uint8 *from, uint8 *to, int size_to) { } to = curToPtr; - if (var6 > 2) { + if (size > 2) { uint16 word = 0; - if (var6 <= 0x0A) { - uint16 size = from - var7; + if (size <= 0x0A) { + uint16 diffSize = from - tempPtr; if (size <= 0x0FFF) { - byte highByte = ((size & 0xFF00) >> 8) + (((var6 & 0xFF) - 3) << 4); - word = ((size & 0xFF) << 8) | highByte; + byte highByte = ((diffSize & 0xFF00) >> 8) + (((size & 0xFF) - 3) << 4); + word = ((diffSize & 0xFF) << 8) | highByte; WRITE_LE_UINT16(to, word); to += 2; - from += var6; - var1 = 0; + from += size; + skipPixel = false; continue; } } - if (var6 > 0x40) { + if (size > 0x40) { *to++ = 0xFF; - WRITE_LE_UINT16(to, var6); to += 2; + WRITE_LE_UINT16(to, size); to += 2; } else { - *to++ = ((var6 & 0xFF) - 3) | 0xC0; + *to++ = ((size & 0xFF) - 3) | 0xC0; } - word = var7 - fromPtr; + word = tempPtr - fromPtr; WRITE_LE_UINT16(to, word); to += 2; - from += var6; - var1 = 0; + from += size; + skipPixel = false; } else { - if (var1 == 0) { + if (!skipPixel) { toPtr2 = to; *to++ = 0x80; } @@ -1224,7 +1228,7 @@ int16 Screen::decodeShapeHelper(uint8 *from, uint8 *to, int size_to) { ++(*toPtr2); *to++ = *from++; - var1 = 1; + skipPixel = true; } } *to++ = 0x80; @@ -1249,18 +1253,21 @@ int Screen::getRectSize(int x, int y) { } void Screen::hideMouse() { + debug(9, "hideMouse()"); // if mouseDisabled // return - hideMouseHelper(); + restoreMouseRect(); } void Screen::showMouse() { + debug(9, "showMouse()"); // if mouseDisabled // return - showMouseHelper(); + copyMouseToScreen(); } void Screen::setShapePages(int page1, int page2) { + debug(9, "setShapePages(%d, %d)", page1, page2); _shapePages[0] = _pagePtrs[page1]; _shapePages[1] = _pagePtrs[page2]; } @@ -1272,9 +1279,9 @@ byte *Screen::setMouseCursor(int x, int y, byte *shape) { // if mouseDisabled // return _mouseShape - hideMouseHelper(); + restoreMouseRect(); - int mouseRectSize = getRectSize(((*(uint16*)(shape + 3)) >> 3) + 2, shape[5]); + int mouseRectSize = getRectSize((READ_LE_UINT16(shape + 3) >> 3) + 2, shape[5]); if (_mouseRectSize < mouseRectSize) { free(_mouseRect); _mouseRect = (uint8*)malloc(mouseRectSize << 3); @@ -1282,8 +1289,8 @@ byte *Screen::setMouseCursor(int x, int y, byte *shape) { _mouseRectSize = mouseRectSize; } - int shapeSize = *(uint16*)(shape + 8) + 10; - if ((*(uint16*)shape) & 1) + int shapeSize = READ_LE_UINT16(shape + 8) + 10; + if (READ_LE_UINT16(shape) & 1) shapeSize += 16; if (_mouseShapeSize < shapeSize) { @@ -1296,15 +1303,15 @@ byte *Screen::setMouseCursor(int x, int y, byte *shape) { byte *dst = _mouseShape; byte *src = shape; - if (!((*(uint16*)shape) & 2)) { + if (!(READ_LE_UINT16(shape) & 2)) { uint16 newFlags = 0; - newFlags = *(uint16*)src | 2; src += 2; - *(uint16*)dst = newFlags; dst += 2; + newFlags = READ_LE_UINT16(src) | 2; src += 2; + WRITE_LE_UINT16(dst, newFlags); dst += 2; memcpy(dst, src, 6); dst += 6; src += 6; - int size = *(uint16*)src; src += 2; - *(uint16*)dst = size; dst += 2; + int size = READ_LE_UINT16(src); src += 2; + WRITE_LE_UINT16(dst, size); dst += 2; if (newFlags & 1) { memcpy(dst, src, 8); dst += 16; @@ -1313,20 +1320,21 @@ byte *Screen::setMouseCursor(int x, int y, byte *shape) { decodeFrame4(src, _animBlockPtr, size); memcpy(dst, _animBlockPtr, size); } else { - int size = *(uint16*)(shape + 6); + int size = READ_LE_UINT16(shape + 6); memcpy(dst, src, size); } _mouseXOffset = x; _mouseYOffset = y; _mouseHeight = _mouseShape[5]; - _mouseWidth = ((*(uint16*)(_mouseShape+3)) >> 3) + 2; + _mouseWidth = (READ_LE_UINT16(_mouseShape + 3) >> 3) + 2; - showMouseHelper(); + copyMouseToScreen(); return _mouseShape; } -void Screen::hideMouseHelper() { +void Screen::restoreMouseRect() { + debug(9, "restoreMouseRect()"); // if disableMouse // return @@ -1339,7 +1347,8 @@ void Screen::hideMouseHelper() { // ++mouseUnk } -void Screen::showMouseHelper() { +void Screen::copyMouseToScreen() { + debug(9, "copyMouseToScreen()"); // if disableMouse // return @@ -1391,6 +1400,7 @@ void Screen::showMouseHelper() { } void Screen::copyScreenFromRect(int x, int y, int w, int h, uint8 *ptr) { + debug(9, "copyScreenFromRect(%d, %d, %d, %d, 0x%X)", x, y, w, h, ptr); x <<= 3; w <<= 3; uint8 *src = ptr; uint8 *dst = &_pagePtrs[0][y * SCREEN_W + x]; @@ -1398,6 +1408,7 @@ void Screen::copyScreenFromRect(int x, int y, int w, int h, uint8 *ptr) { } void Screen::copyScreenToRect(int x, int y, int w, int h, uint8 *ptr) { + debug(9, "copyScreenToRect(%d, %d, %d, %d, 0x%X)", x, y, w, h, ptr); x <<= 3; w <<= 3; uint8 *src = &_pagePtrs[0][y * SCREEN_W + x]; uint8 *dst = ptr; diff --git a/kyra/screen.h b/kyra/screen.h index 692cc659dc..2642ba782a 100644 --- a/kyra/screen.h +++ b/kyra/screen.h @@ -115,7 +115,7 @@ public: static void decodeFrame4(const uint8 *src, uint8 *dst, uint32 dstSize); static void decodeFrameDelta(uint8 *dst, const uint8 *src); static void decodeFrameDeltaPage(uint8 *dst, const uint8 *src, int pitch); - uint8 *decodeShape(int x, int y, int w, int h, int flags); + uint8 *encodeShape(int x, int y, int w, int h, int flags); void copyRegionToBuffer(int pageNum, int x, int y, int w, int h, uint8 *dest); int getRectSize(int x, int y); @@ -132,9 +132,9 @@ public: typedef void (Screen::*DrawShapePlotPixelCallback)(uint8 *dst, uint8 c); private: - int16 decodeShapeHelper(uint8 *from, uint8 *to, int size); - void hideMouseHelper(); - void showMouseHelper(); + int16 encodeShapeAndCalculateSize(uint8 *from, uint8 *to, int size); + void restoreMouseRect(); + void copyMouseToScreen(); void copyScreenFromRect(int x, int y, int w, int h, uint8 *ptr); void copyScreenToRect(int x, int y, int w, int h, uint8 *ptr); |