diff options
Diffstat (limited to 'engines/kyra/screen.cpp')
-rw-r--r-- | engines/kyra/screen.cpp | 364 |
1 files changed, 33 insertions, 331 deletions
diff --git a/engines/kyra/screen.cpp b/engines/kyra/screen.cpp index 6ffd0ace79..298483465e 100644 --- a/engines/kyra/screen.cpp +++ b/engines/kyra/screen.cpp @@ -34,7 +34,8 @@ namespace Kyra { Screen::Screen(KyraEngine *vm, OSystem *system) -: _system(system), _vm(vm), _sjisInvisibleColor(0) { + : _system(system), _vm(vm), _sjisInvisibleColor(0) { + _debugEnabled = false; } Screen::~Screen() { @@ -75,7 +76,34 @@ bool Screen::init() { _useSJIS = false; _sjisTempPage = _sjisFontData = 0; - setResolution(); + if (_vm->gameFlags().useHiResOverlay) { + _useOverlays = true; + _useSJIS = (_vm->gameFlags().lang == Common::JA_JPN); + _sjisInvisibleColor = (_vm->gameFlags().gameID == GI_KYRA1) ? 0x80 : 0xF6; + + for (int i = 0; i < SCREEN_OVLS_NUM; ++i) { + if (!_sjisOverlayPtrs[i]) { + _sjisOverlayPtrs[i] = new uint8[SCREEN_OVL_SJIS_SIZE]; + assert(_sjisOverlayPtrs[i]); + memset(_sjisOverlayPtrs[i], _sjisInvisibleColor, SCREEN_OVL_SJIS_SIZE); + } + } + + if (_useSJIS) { + if (!_sjisFontData) { + _sjisFontData = _vm->resource()->fileData("FMT_FNT.ROM", 0); + if (!_sjisFontData) + error("missing font rom ('FMT_FNT.ROM') required for this version"); + } + + if (!_sjisTempPage) { + _sjisTempPage = new uint8[420]; + assert(_sjisTempPage); + _sjisTempPage2 = _sjisTempPage + 60; + _sjisSourceChar = _sjisTempPage + 384; + } + } + } _curPage = 0; uint8 *pagePtr = new uint8[SCREEN_PAGE_SIZE * 8]; @@ -155,32 +183,6 @@ void Screen::setResolution() { else _system->initSize(640, 400); _system->endGFXTransaction(); - - _useOverlays = true; - _useSJIS = (_vm->gameFlags().lang == Common::JA_JPN); - _sjisInvisibleColor = (_vm->gameFlags().gameID == GI_KYRA1) ? 0x80 : 0xF6; - - for (int i = 0; i < SCREEN_OVLS_NUM; ++i) { - if (!_sjisOverlayPtrs[i]) { - _sjisOverlayPtrs[i] = new uint8[SCREEN_OVL_SJIS_SIZE]; - assert(_sjisOverlayPtrs[i]); - memset(_sjisOverlayPtrs[i], _sjisInvisibleColor, SCREEN_OVL_SJIS_SIZE); - } - } - if (_useSJIS) { - if (!_sjisFontData) { - _sjisFontData = _vm->resource()->fileData("FMT_FNT.ROM", 0); - if (!_sjisFontData) - error("missing font rom ('FMT_FNT.ROM') required for this version"); - } - - if (!_sjisTempPage) { - _sjisTempPage = new uint8[420]; - assert(_sjisTempPage); - _sjisTempPage2 = _sjisTempPage + 60; - _sjisSourceChar = _sjisTempPage + 384; - } - } } else { _system->beginGFXTransaction(); _vm->initCommonGFX(false); @@ -1181,7 +1183,7 @@ void Screen::drawShape(uint8 pageNum, const uint8 *shapeData, int x, int y, int &Screen::drawShapePlotType0, // used by Kyra 1 + 2 &Screen::drawShapePlotType1, // used by Kyra 3 0, - &Screen::drawShapePlotType3_7, // used by Kyra 1 (invisibility) + &Screen::drawShapePlotType3_7, // used by Kyra 3 (shadow) &Screen::drawShapePlotType4, // used by Kyra 1, 2 + 3 &Screen::drawShapePlotType5, // used by Kyra 1 &Screen::drawShapePlotType6, // used by Kyra 1 (invisibility) @@ -1189,7 +1191,7 @@ void Screen::drawShape(uint8 pageNum, const uint8 *shapeData, int x, int y, int &Screen::drawShapePlotType8, // used by Kyra 2 &Screen::drawShapePlotType9, // used by Kyra 1 + 3 0, - &Screen::drawShapePlotType11_15, // used by Kyra 1 /invisibility) + &Screen::drawShapePlotType11_15, // used by Kyra 1 (invisibility) + Kyra 3 (shadow) &Screen::drawShapePlotType12, // used by Kyra 2 &Screen::drawShapePlotType13, // used by Kyra 1 &Screen::drawShapePlotType14, // used by Kyra 1 (invisibility) @@ -1635,7 +1637,7 @@ void Screen::drawShapePlotType1(uint8 *dst, uint8 cmd) { } void Screen::drawShapePlotType3_7(uint8 *dst, uint8 cmd) { - cmd = dst[cmd]; + cmd = *dst; for (int i = 0; i < _dsTableLoopCount; ++i) cmd = _dsTable[cmd]; @@ -3110,305 +3112,5 @@ void Screen::drawCharSJIS(uint16 c, int x, int y) { #pragma mark - -uint8 *ScreenEx::generateOverlay(const uint8 *palette, uint8 *buffer, int startColor, uint16 factor) { - if (!palette || !buffer) - return buffer; - - factor = MIN<uint16>(255, factor); - factor >>= 1; - factor &= 0xFF; - - const byte col1 = palette[startColor * 3 + 0]; - const byte col2 = palette[startColor * 3 + 1]; - const byte col3 = palette[startColor * 3 + 2]; - - uint8 *dst = buffer; - *dst++ = 0; - - for (int i = 1; i != 255; ++i) { - uint8 processedPalette[3]; - const uint8 *src = palette + i*3; - byte col; - - col = *src++; - col -= ((((col - col1) * factor) << 1) >> 8) & 0xFF; - processedPalette[0] = col; - - col = *src++; - col -= ((((col - col2) * factor) << 1) >> 8) & 0xFF; - processedPalette[1] = col; - - col = *src++; - col -= ((((col - col3) * factor) << 1) >> 8) & 0xFF; - processedPalette[2] = col; - - *dst++ = findLeastDifferentColor(processedPalette, palette+3, 255)+1; - } - - return buffer; -} - -void ScreenEx::applyOverlay(int x, int y, int w, int h, int pageNum, const uint8 *overlay) { - if (pageNum == 0 || pageNum == 1) - addDirtyRect(x, y, w, h); - - uint8 *dst = getPagePtr(pageNum) + y * 320 + x; - while (h--) { - for (int wi = 0; wi < w; ++wi) { - uint8 index = *dst; - *dst++ = overlay[index]; - } - dst += 320 - w; - } -} - -int ScreenEx::findLeastDifferentColor(const uint8 *paletteEntry, const uint8 *palette, uint16 numColors) { - int m = 0x7fff; - int r = 0x101; - - for (int i = 0; i < numColors; i++) { - int v = paletteEntry[0] - *palette++; - int c = v * v; - v = paletteEntry[1] - *palette++; - c += (v * v); - v = paletteEntry[2] - *palette++; - c += (v * v); - - if (c <= m) { - m = c; - r = i; - } - } - - return r; -} - -void ScreenEx::copyWsaRect(int x, int y, int w, int h, int dimState, int plotFunc, const uint8 *src, - int unk1, const uint8 *unkPtr1, const uint8 *unkPtr2) { - uint8 *dstPtr = getPagePtr(_curPage); - uint8 *origDst = dstPtr; - - const ScreenDim *dim = getScreenDim(dimState); - int dimX1 = dim->sx << 3; - int dimX2 = dim->w << 3; - dimX2 += dimX1; - - int dimY1 = dim->sy; - int dimY2 = dim->h; - dimY2 += dimY1; - - int temp = y - dimY1; - if (temp < 0) { - if ((temp += h) <= 0) - return; - else { - SWAP(temp, h); - y += temp - h; - src += (temp - h) * w; - } - } - - temp = dimY2 - y; - if (temp <= 0) - return; - - if (temp < h) - h = temp; - - int srcOffset = 0; - temp = x - dimX1; - if (temp < 0) { - temp = -temp; - srcOffset = temp; - x += temp; - w -= temp; - } - - int srcAdd = 0; - - temp = dimX2 - x; - if (temp <= 0) - return; - - if (temp < w) { - SWAP(w, temp); - temp -= w; - srcAdd = temp; - } - - dstPtr += y * SCREEN_W + x; - uint8 *dst = dstPtr; - - if (_curPage == 0 || _curPage == 1) - addDirtyRect(x, y, w, h); - - clearOverlayRect(_curPage, x, y, w, h); - - temp = h; - int curY = y; - while (h--) { - src += srcOffset; - ++curY; - int cW = w; - - switch (plotFunc) { - case 0: - memcpy(dst, src, cW); - dst += cW; src += cW; - break; - - case 1: - while (cW--) { - uint8 d = *src++; - uint8 t = unkPtr1[d]; - if (t != 0xFF) - d = unkPtr2[*dst + (t << 8)]; - *dst++ = d; - } - break; - - case 4: - while (cW--) { - uint8 d = *src++; - if (d) - *dst = d; - ++dst; - } - break; - - case 5: - while (cW--) { - uint8 d = *src++; - if (d) { - uint8 t = unkPtr1[d]; - if (t != 0xFF) - d = unkPtr2[*dst + (t << 8)]; - *dst = d; - } - ++dst; - } - break; - - case 8: - case 9: - while (cW--) { - uint8 d = *src++; - uint8 t = _shapePages[0][dst - origDst] & 7; - if (unk1 < t && (curY > _maskMinY && curY < _maskMaxY)) - d = _shapePages[1][dst - origDst]; - *dst++ = d; - } - break; - - case 12: - case 13: - while (cW--) { - uint8 d = *src++; - if (d) { - uint8 t = _shapePages[0][dst - origDst] & 7; - if (unk1 < t && (curY > _maskMinY && curY < _maskMaxY)) - d = _shapePages[1][dst - origDst]; - *dst++ = d; - } else { - d = _shapePages[1][dst - origDst]; - *dst++ = d; - } - } - break; - - default: - break; - } - - dst = (dstPtr += SCREEN_W); - src += srcAdd; - } -} - -const uint8 *ScreenEx::getPtrToShape(const uint8 *shpFile, int shape) { - debugC(9, kDebugLevelScreen, "ScreenEx::getPtrToShape(%p, %d)", (const void *)shpFile, shape); - uint16 shapes = READ_LE_UINT16(shpFile); - - if (shapes <= shape) - return 0; - - uint32 offset = READ_LE_UINT32(shpFile + (shape << 2) + 2); - - return shpFile + offset + 2; -} - -uint8 *ScreenEx::getPtrToShape(uint8 *shpFile, int shape) { - debugC(9, kDebugLevelScreen, "ScreenEx::getPtrToShape(%p, %d)", (void *)shpFile, shape); - uint16 shapes = READ_LE_UINT16(shpFile); - - if (shapes <= shape) - return 0; - - uint32 offset = READ_LE_UINT32(shpFile + (shape << 2) + 2); - - return shpFile + offset + 2; -} - -int ScreenEx::getShapeScaledWidth(const uint8 *shpFile, int scale) { - int width = READ_LE_UINT16(shpFile+3); - return (width * scale) >> 8; -} - -int ScreenEx::getShapeScaledHeight(const uint8 *shpFile, int scale) { - int height = shpFile[2]; - return (height * scale) >> 8; -} - -uint16 ScreenEx::getShapeSize(const uint8 *shp) { - debugC(9, kDebugLevelScreen, "ScreenEx::getShapeSize(%p)", (const void *)shp); - - return READ_LE_UINT16(shp+6); -} - -uint8 *ScreenEx::makeShapeCopy(const uint8 *src, int index) { - debugC(9, kDebugLevelScreen, "ScreenEx::makeShapeCopy(%p, %d)", (const void *)src, index); - - const uint8 *shape = getPtrToShape(src, index); - int size = getShapeSize(shape); - - uint8 *copy = new uint8[size]; - assert(copy); - memcpy(copy, shape, size); - - return copy; -} - -int ScreenEx::getLayer(int x, int y) { - if (x < 0) - x = 0; - else if (x >= 320) - x = 319; - if (y < 0) - y = 0; - else if (y >= 144) - y = 143; - - uint8 pixel = *(getCPagePtr(5) + y * 320 + x); - pixel &= 0x7F; - pixel >>= 3; - - if (pixel < 1) - pixel = 1; - else if (pixel > 15) - pixel = 15; - return pixel; -} - -int ScreenEx::getRectSize(int w, int h) { - if (w > 320 || h > 200) - return 0; - return w*h; -} - -void ScreenEx::setTextColorMap(const uint8 *cmap) { - debugC(9, kDebugLevelScreen, "ScreenEx::setTextColorMap(%p)", (const void *)cmap); - setTextColor(cmap, 0, 15); -} - } // End of namespace Kyra |