diff options
Diffstat (limited to 'engines/queen/bankman.cpp')
-rw-r--r-- | engines/queen/bankman.cpp | 198 |
1 files changed, 142 insertions, 56 deletions
diff --git a/engines/queen/bankman.cpp b/engines/queen/bankman.cpp index 18ad276d0f..d9eb020dfe 100644 --- a/engines/queen/bankman.cpp +++ b/engines/queen/bankman.cpp @@ -31,7 +31,6 @@ BankManager::BankManager(Resource *res) : _res(res) { memset(_frames, 0, sizeof(_frames)); memset(_banks, 0, sizeof(_banks)); - memset(_loadedBanks, 0, sizeof(_loadedBanks)); } BankManager::~BankManager() { @@ -43,102 +42,189 @@ BankManager::~BankManager() { void BankManager::load(const char *bankname, uint32 bankslot) { debug(9, "BankManager::load(%s, %d)", bankname, bankslot); + assert(bankslot < MAX_BANKS_NUMBER); + PackedBank *bank = &_banks[bankslot]; - if (!scumm_stricmp(bankname, _loadedBanks[bankslot])) { + if (!scumm_stricmp(bankname, bank->name)) { debug(9, "BankManager::load() bank '%s' already loaded", bankname); return; } close(bankslot); - _banks[bankslot].data = _res->loadFile(bankname); - - uint16 entries = READ_LE_UINT16(_banks[bankslot].data); - assert(entries < MAX_BANK_SIZE); - debug(9, "BankManager::load() entries = %d", entries); - - uint32 offset = 2; - const uint8 *p = _banks[bankslot].data; - for (uint16 i = 1; i <= entries; ++i) { - _banks[bankslot].indexes[i] = offset; - uint16 w = READ_LE_UINT16(p + offset + 0); - uint16 h = READ_LE_UINT16(p + offset + 2); - // jump to next entry, skipping data & header - offset += w * h + 8; + bank->data = _res->loadFile(bankname); + + if (_res->getPlatform() == Common::kPlatformAmiga) { + uint16 entries = READ_BE_UINT16(bank->data + 4); + assert(entries < MAX_BANK_SIZE); + debug(9, "BankManager::load() entries = %d", entries); + uint32 offset = 6; + for (uint16 i = 1; i <= entries; ++i) { + _banks[bankslot].indexes[i] = offset; + uint16 dataSize = READ_BE_UINT16(bank->data + offset + 10); + offset += dataSize + 12; + } + } else { + uint16 entries = READ_LE_UINT16(bank->data); + assert(entries < MAX_BANK_SIZE); + debug(9, "BankManager::load() entries = %d", entries); + uint32 offset = 2; + for (uint16 i = 1; i <= entries; ++i) { + _banks[bankslot].indexes[i] = offset; + uint16 w = READ_LE_UINT16(bank->data + offset + 0); + uint16 h = READ_LE_UINT16(bank->data + offset + 2); + offset += w * h + 8; + } } // mark this bank as loaded - strcpy(_loadedBanks[bankslot], bankname); + strcpy(bank->name, bankname); +} + +static void convertPlanarBitmap(uint8 *dst, int dstPitch, const uint8 *src, int w, int h, int plane) { + assert(w != 0 && h != 0); + int planarSize = plane * h * w * 2; + uint8 *planarBuf = new uint8[ planarSize ]; + uint8 *dstPlanar = planarBuf; + while (planarSize > 0) { + if (src[0] == 0) { + int count = src[1]; + memset(dstPlanar, 0, count); + dstPlanar += count; + src += 2; + planarSize -= count; + } else { + *dstPlanar++ = *src++; + --planarSize; + } + } + + src = planarBuf; + int i = 0; + int planeSize = h * w * 2; + while (h--) { + for (int x = 0; x < w * 2; ++x) { + for (int b = 0; b < 8; ++b) { + const uint8 mask = (1 << (7 - b)); + uint8 color = 0; + for (int p = 0; p < plane; ++p) { + if (src[planeSize * p + i] & mask) { + color |= (1 << p); + } + } + dst[8 * x + b] = color; + } + ++i; + } + dst += dstPitch; + } + + delete[] planarBuf; } void BankManager::unpack(uint32 srcframe, uint32 dstframe, uint32 bankslot) { debug(9, "BankManager::unpack(%d, %d, %d)", srcframe, dstframe, bankslot); + assert(bankslot < MAX_BANKS_NUMBER); - assert(_banks[bankslot].data != NULL); - - BobFrame *pbf = &_frames[dstframe]; - const uint8 *p = _banks[bankslot].data + _banks[bankslot].indexes[srcframe]; - pbf->width = READ_LE_UINT16(p + 0); - pbf->height = READ_LE_UINT16(p + 2); - pbf->xhotspot = READ_LE_UINT16(p + 4); - pbf->yhotspot = READ_LE_UINT16(p + 6); - - uint32 size = pbf->width * pbf->height; - delete[] pbf->data; - pbf->data = new uint8[ size ]; - memcpy(pbf->data, p + 8, size); + PackedBank *bank = &_banks[bankslot]; + assert(bank->data != NULL); + + assert(dstframe < MAX_FRAMES_NUMBER); + BobFrame *bf = &_frames[dstframe]; + delete[] bf->data; + bf->data = NULL; + + const uint8 *p = bank->data + bank->indexes[srcframe]; + + if (_res->getPlatform() == Common::kPlatformAmiga) { + uint16 w = READ_BE_UINT16(p + 0); + uint16 h = READ_BE_UINT16(p + 2); + uint16 plane = READ_BE_UINT16(p + 4); + bf->xhotspot = READ_BE_UINT16(p + 6); + bf->yhotspot = READ_BE_UINT16(p + 8); + bf->width = w * 16; + bf->height = h; + + uint32 size = bf->width * bf->height; + bf->data = new uint8[ size ]; + convertPlanarBitmap(bf->data, bf->width, p + 12, w, h, plane); + } else { + bf->width = READ_LE_UINT16(p + 0); + bf->height = READ_LE_UINT16(p + 2); + bf->xhotspot = READ_LE_UINT16(p + 4); + bf->yhotspot = READ_LE_UINT16(p + 6); + + uint32 size = bf->width * bf->height; + bf->data = new uint8[ size ]; + memcpy(bf->data, p + 8, size); + } } void BankManager::overpack(uint32 srcframe, uint32 dstframe, uint32 bankslot) { debug(9, "BankManager::overpack(%d, %d, %d)", srcframe, dstframe, bankslot); - assert(bankslot < MAX_BANKS_NUMBER); - assert(_banks[bankslot].data != NULL); - const uint8 *p = _banks[bankslot].data + _banks[bankslot].indexes[srcframe]; - uint16 src_w = READ_LE_UINT16(p + 0); - uint16 src_h = READ_LE_UINT16(p + 2); - - // unpack if destination frame is smaller than source one - if (_frames[dstframe].width < src_w || _frames[dstframe].height < src_h) { - unpack(srcframe, dstframe, bankslot); + assert(bankslot < MAX_BANKS_NUMBER); + PackedBank *bank = &_banks[bankslot]; + assert(bank->data != NULL); + + assert(dstframe < MAX_FRAMES_NUMBER); + BobFrame *bf = &_frames[dstframe]; + + const uint8 *p = bank->data + bank->indexes[srcframe]; + + if (_res->getPlatform() == Common::kPlatformAmiga) { + uint16 w = READ_BE_UINT16(p + 0); + uint16 h = READ_BE_UINT16(p + 2); + uint16 plane = READ_BE_UINT16(p + 4); + uint16 src_w = w * 16; + uint16 src_h = h; + + if (bf->width < src_w || bf->height < src_h) { + unpack(srcframe, dstframe, bankslot); + } else { + convertPlanarBitmap(bf->data, bf->width, p + 12, w, h, plane); + } } else { - // copy data 'over' destination frame (without changing frame header) - memcpy(_frames[dstframe].data, p + 8, src_w * src_h); + uint16 src_w = READ_LE_UINT16(p + 0); + uint16 src_h = READ_LE_UINT16(p + 2); + + // unpack if destination frame is smaller than source + if (bf->width < src_w || bf->height < src_h) { + unpack(srcframe, dstframe, bankslot); + } else { + // copy data 'over' destination frame (without updating frame header) + memcpy(bf->data, p + 8, src_w * src_h); + } } } void BankManager::close(uint32 bankslot) { debug(9, "BankManager::close(%d)", bankslot); assert(bankslot < MAX_BANKS_NUMBER); - delete[] _banks[bankslot].data; - memset(&_banks[bankslot], 0, sizeof(PackedBank)); - _loadedBanks[bankslot][0] = '\0'; + PackedBank *bank = &_banks[bankslot]; + delete[] bank->data; + memset(bank, 0, sizeof(PackedBank)); } BobFrame *BankManager::fetchFrame(uint32 index) { debug(9, "BankManager::fetchFrame(%d)", index); assert(index < MAX_FRAMES_NUMBER); - BobFrame *pbf = &_frames[index]; - assert(pbf->data != 0); - return pbf; + BobFrame *bf = &_frames[index]; + assert(bf->data != 0); + return bf; } void BankManager::eraseFrame(uint32 index) { debug(9, "BankManager::eraseFrame(%d)", index); assert(index < MAX_FRAMES_NUMBER); - BobFrame *pbf = &_frames[index]; - delete[] pbf->data; - memset(pbf, 0, sizeof(BobFrame)); + BobFrame *bf = &_frames[index]; + delete[] bf->data; + memset(bf, 0, sizeof(BobFrame)); } void BankManager::eraseFrames(bool joe) { - uint32 i = 0; - if (!joe) { - i = FRAMES_JOE; - } - while (i < MAX_FRAMES_NUMBER) { + for (uint32 i = joe ? 0 : FRAMES_JOE; i < MAX_FRAMES_NUMBER; ++i) { eraseFrame(i); - ++i; } } |