diff --git a/actor.cpp b/actor.cpp index 731dba22e7e..1069886e1bd 100644 --- a/actor.cpp +++ b/actor.cpp @@ -17,6 +17,9 @@ * * Change Log: * $Log$ + * Revision 1.7 2001/10/26 17:34:50 strigeus + * bug fixes, code cleanup + * * Revision 1.6 2001/10/23 19:51:50 strigeus * recompile not needed when switching games * debugger skeleton implemented @@ -445,8 +448,8 @@ void Scumm::putActor(Actor *a, int x, int y, byte room) { a->needRedraw = true; a->needBgReset = true; - if (_vars[VAR_UNK_ACTOR]==a->number) { - dseg_3A76 = 1; + if (_vars[VAR_EGO]==a->number) { + _egoPositioned = true; } if (a->visible) { @@ -774,8 +777,8 @@ void Scumm::setupCostumeRenderer(CostumeRenderer *c, Actor *a) { c->_actorX = a->x - virtscr->xstart; c->_actorY = a->y - a->elevation; c->_zbuf = a->mask; - if (c->_zbuf > _numZBuffer) - c->_zbuf = (byte)_numZBuffer; + if (c->_zbuf > gdi._numZBuffer) + c->_zbuf = (byte)gdi._numZBuffer; if (a->neverZClip) c->_zbuf = a->neverZClip; diff --git a/costume.cpp b/costume.cpp index 9aef48ab36f..62d882b9eae 100644 --- a/costume.cpp +++ b/costume.cpp @@ -17,6 +17,9 @@ * * Change Log: * $Log$ + * Revision 1.6 2001/10/26 17:34:50 strigeus + * bug fixes, code cleanup + * * Revision 1.5 2001/10/23 19:51:50 strigeus * recompile not needed when switching games * debugger skeleton implemented @@ -286,21 +289,21 @@ byte CostumeRenderer::mainRoutine(Actor *a, int slot, int frame) { return 2; } - _where_to_draw_ptr = _vm->getResourceAddress(0xA, 5) + _vm->virtscr[0].xstart + _ypos*320 + _xpos; - _bg_ptr = _vm->getResourceAddress(0xA, 1) + _vm->virtscr[0].xstart + _ypos*320 + _xpos; + _bgbak_ptr = _vm->getResourceAddress(0xA, 5) + _vm->virtscr[0].xstart + _ypos*320 + _xpos; + _backbuff_ptr = _vm->getResourceAddress(0xA, 1) + _vm->virtscr[0].xstart + _ypos*320 + _xpos; charsetmask = _vm->hasCharsetMask(_left, _top + _vm->virtscr[0].topline, _right, _vm->virtscr[0].topline + _bottom); masking = 0; if (_zbuf) { masking = _vm->isMaskActiveAt(_left, _top, _right, _bottom, - _vm->getResourceAddress(0xA, 9) + _vm->_imgBufOffs[_zbuf] + _vm->_screenStartStrip + _vm->getResourceAddress(0xA, 9) + _vm->gdi._imgBufOffs[_zbuf] + _vm->_screenStartStrip ); } if (_zbuf || charsetmask) { _mask_ptr = _vm->getResourceAddress(0xA, 9) + _ypos*40 + _vm->_screenStartStrip; - _imgbufoffs = _vm->_imgBufOffs[_zbuf]; + _imgbufoffs = _vm->gdi._imgBufOffs[_zbuf]; if (!charsetmask && _zbuf!=0) _mask_ptr += _imgbufoffs; _mask_ptr_dest = _mask_ptr + _xpos / 8; @@ -344,7 +347,7 @@ void CostumeRenderer::proc6() { y = _ypos; len = _replen; src = _srcptr; - dst = _bg_ptr; + dst = _backbuff_ptr; color = _repcolor; scrheight = _vscreenheight; width = _width2; @@ -391,7 +394,7 @@ void CostumeRenderer::proc5() { maskbit = revBitMask[_xpos&7]; y = _ypos; src = _srcptr; - dst = _bg_ptr; + dst = _backbuff_ptr; len = _replen; color = _repcolor; scrheight = _vscreenheight; @@ -451,7 +454,7 @@ void CostumeRenderer::proc4() { maskbit = revBitMask[_xpos&7]; y = _ypos; src = _srcptr; - dst = _bg_ptr; + dst = _backbuff_ptr; len = _replen; color = _repcolor; scrheight = _vscreenheight; @@ -508,7 +511,7 @@ void CostumeRenderer::proc3() { uint y; mask = _mask_ptr_dest; - dst = _bg_ptr; + dst = _backbuff_ptr; height = _height2; width = _width2; len = _replen; @@ -549,9 +552,9 @@ void CostumeRenderer::proc3() { if (_xpos >= 320) return; maskbit = revBitMask[_xpos&7]; - _bg_ptr += _scaleIndexXStep; + _backbuff_ptr += _scaleIndexXStep; } - dst = _bg_ptr; + dst = _backbuff_ptr; mask = _mask_ptr + (_xpos>>3); } StartPos:; @@ -566,7 +569,7 @@ void CostumeRenderer::proc2() { uint y; mask = _mask_ptr_dest; - dst = _bg_ptr; + dst = _backbuff_ptr; height = _height2; width = _width2; len = _replen; @@ -607,9 +610,9 @@ void CostumeRenderer::proc2() { if (_xpos >= 320) return; maskbit = revBitMask[_xpos&7]; - _bg_ptr += _scaleIndexXStep; + _backbuff_ptr += _scaleIndexXStep; } - dst = _bg_ptr; + dst = _backbuff_ptr; mask = _mask_ptr + (_xpos>>3); } StartPos:; @@ -619,28 +622,17 @@ StartPos:; } void CostumeRenderer::proc1() { - byte *mask,*src,*dst; + byte *mask,*src,*dst,*dstorg; byte maskbit,len,height,pcolor,width; uint y; int color; int t; -#if 0 - debug(1, "proc1(): (%d %d),(%d %d %d),(%d %d %d),(%d %d,%d %d,%d %d),(%d %d)", - _xpos, _ypos, - _width2, _height2, _height, - _replen,_repcolor,_docontinue, - _scaleX, _scaleY, _scaleIndexX, _scaleIndexY, - _scaleIndexXStep, _scaleIndexYStep, - _scaleIndexYTop,_vscreenheight - ); -#endif - mask = _mask_ptr = _mask_ptr_dest; maskbit = revBitMask[_xpos&7]; y = _ypos; - dst = _bg_ptr; + dstorg = dst = _backbuff_ptr; height = _height2; width = _width2; len = _replen; @@ -678,9 +670,9 @@ void CostumeRenderer::proc1() { _xpos += _scaleIndexXStep; if (_xpos >= 320) return; - _bg_ptr += _scaleIndexXStep; + _backbuff_ptr += _scaleIndexXStep; } - dst = _bg_ptr; + dst = _backbuff_ptr; } StartPos:; } while (--len); diff --git a/debug.cpp b/debug.cpp index f454b24e150..ac5765297b2 100644 --- a/debug.cpp +++ b/debug.cpp @@ -17,6 +17,9 @@ * * Change Log: * $Log$ + * Revision 1.3 2001/10/26 17:34:50 strigeus + * bug fixes, code cleanup + * * Revision 1.2 2001/10/23 19:56:57 strigeus * fixed spelling error * @@ -36,6 +39,8 @@ enum { CMD_HELP, CMD_QUIT, CMD_GO, + CMD_ACTOR, + CMD_SCRIPTS, }; void ScummDebugger::attach(Scumm *s) { @@ -57,7 +62,7 @@ bool ScummDebugger::do_command() { printf("Debugger commands:\n" "help -> display this help text\n" "quit -> quit the debugger\n" - "step -> increase one frame\n" + "go [numframes] -> increase frame\n" ); return true; @@ -71,7 +76,15 @@ bool ScummDebugger::do_command() { else _go_amount = atoi(_parameters); return false; - + case CMD_ACTOR: + if (!_parameters[0]) + printActors(-1); + else + printActors(atoi(_parameters)); + return true; + case CMD_SCRIPTS: + printScripts(); + return true; } } @@ -108,6 +121,8 @@ static const DebuggerCommands debugger_commands[] = { { "h", 1, CMD_HELP }, { "q", 1, CMD_QUIT }, { "g", 1, CMD_GO }, + { "a", 1, CMD_ACTOR }, + { "s", 1, CMD_SCRIPTS }, { 0, 0, 0 }, }; @@ -143,4 +158,39 @@ int ScummDebugger::get_command() { if (*s==32) { *s=0; break; } printf("Invalid command '%s'. Type 'help' for a list of available commands.\n", _cmd_buffer); } while (1); +} + +void ScummDebugger::printActors(int act) { + int i; + Actor *a; + + if (act==-1) { + printf("+--------------------------------------------------------------+\n"); + printf("|# |room| x y |elev|cos|width|box|mov|zp|frame|scale|spd|dir|\n"); + printf("+--+----+--------+----+---+-----+---+---+--+-----+-----+---+---+\n"); + for(i=1; i<13; i++) { + a = &_s->actor[i]; + if (a->visible) + printf("|%2d|%4d|%3d %3d|%4d|%3d|%5d|%3d|%3d|%2d|%5d|%5d|%3d|%3d|\n", + i,a->room,a->x,a->y,a->elevation,a->costume,a->width,a->walkbox,a->moving,a->neverZClip,a->animIndex,a->scalex,a->speedx,a->facing); + } + printf("+--------------------------------------------------------------+\n"); + } +} + +void ScummDebugger::printScripts() { + int i; + ScriptSlot *ss; + + printf("+---------------------------------+\n"); + printf("|# |num|sta|typ|un1|un2|fc|cut|un5|\n"); + printf("+--+---+---+---+---+---+--+---+---+\n"); + for(i=0; i<25; i++) { + ss = &_s->vm.slot[i]; + if (ss->number) { + printf("|%2d|%3d|%3d|%3d|%3d|%3d|%2d|%3d|%3d|\n", + i, ss->number, ss->status, ss->type, ss->unk1, ss->unk2, ss->freezeCount, ss->cutsceneOverride, ss->unk5); + } + } + printf("+---------------------------------+\n"); } \ No newline at end of file diff --git a/gfx.cpp b/gfx.cpp index 166ce6b1d0b..9e5617c3c85 100644 --- a/gfx.cpp +++ b/gfx.cpp @@ -17,6 +17,9 @@ * * Change Log: * $Log$ + * Revision 1.9 2001/10/26 17:34:50 strigeus + * bug fixes, code cleanup + * * Revision 1.8 2001/10/23 19:51:50 strigeus * recompile not needed when switching games * debugger skeleton implemented @@ -99,6 +102,7 @@ void Scumm::initVirtScreen(int slot, int top, int height, bool twobufs, bool fou assert(height>=0); assert(slot>=0 && slot<4); + vs->number = slot; vs->unk1 = 0; vs->width = 320; vs->topline = top; @@ -111,14 +115,10 @@ void Scumm::initVirtScreen(int slot, int top, int height, bool twobufs, bool fou if (vs->scrollable) size += 320*4; - memset( - createResource(10, slot+1, size), - 0,size); + memset(createResource(10, slot+1, size),0,size); if (twobufs) { - memset( - createResource(10, slot+5, size), - 0x23,size); + memset(createResource(10, slot+5, size),0x23,size); } if (slot != 3) { @@ -136,114 +136,77 @@ void Scumm::setDirtyRange(int slot, int top, int bottom) { } void Scumm::unkVirtScreen2() { - dseg_3DB6 = 1; + int i; + VirtScreen *vs; updateDirtyScreen(2); - if (_currentRoom != dseg_2456) { - dseg_2456 = (byte)_currentRoom; - dseg_4E8A = 1; - } - if (camera._lastPos == camera._curPos) { updateDirtyScreen(0); - dseg_4E8A = 1; - dseg_4F8C = _screenStartStrip; } else { - gdi.readPtr = getResourceAddress(10, 1); - gdi.readOffs = _screenStartStrip; - gdi.drawY = virtscr[0].topline; - gdi.drawHeight = virtscr[0].height; - - blitToScreen(this, gdi.readPtr + gdi.readOffs*8, 0, gdi.drawY, 320, gdi.drawHeight); + vs = &virtscr[0]; - for (gdi.draw8xPos = 0; gdi.draw8xPos<40; gdi.draw8xPos++) { - virtscr[0].tdirty[gdi.draw8xPos] = (byte)gdi.drawHeight; - virtscr[0].bdirty[gdi.draw8xPos] = 0; + blitToScreen(this, getResourceAddress(10, 1) + _screenStartStrip*8, + 0, vs->topline, 320, vs->height); + + for (i = 0; i<40; i++) { + vs->tdirty[i] = (byte)vs->height; + vs->bdirty[i] = 0; } } } void Scumm::updateDirtyScreen(int slot) { - VirtScreen *vs = &virtscr[slot]; + gdi.updateDirtyScreen(&virtscr[slot]); +} + +void Gdi::updateDirtyScreen(VirtScreen *vs) { int i; + int start,w,top,bottom; if (vs->height==0) return; - gdi.virtScreen = slot; - gdi.drawY = vs->topline; - gdi.drawHeight = vs->height; - gdi.readOffs = 0; + _readOffs = 0; if (vs->scrollable) - gdi.readOffs = _screenStartStrip; + _readOffs = vs->xstart; - if (_videoMode==0xE) { - for (i=0; i<40; i++) { - gdi.draw8xPos = i; - gdi.drawBottom = vs->bdirty[i]; - if (gdi.drawBottom) { - gdi.drawTop = vs->tdirty[i]; - drawStripToScreen(); - vs->tdirty[i] = (byte)gdi.drawHeight; - vs->bdirty[i] = 0; - } - } - } else { - gdi.drawWidth = 8; - gdi.draw8xPos = 0; + w = 8; + start = 0; - for (i=0; i<40; i++) { - gdi.drawBottom = vs->bdirty[i]; - if (gdi.drawBottom) { - gdi.drawTop = vs->tdirty[i]; - vs->tdirty[i] = (byte)gdi.drawHeight; - vs->bdirty[i] = 0; - if (i!=39) { - if (vs->bdirty[i+1] == gdi.drawBottom && - vs->tdirty[i+1] == gdi.drawTop) { - gdi.drawWidth += 8; - continue; - } - drawStripToScreen(); - gdi.drawWidth = 8; - } else { - drawStripToScreen(); - } + for (i=0; i<40; i++) { + bottom = vs->bdirty[i]; + if (bottom) { + top = vs->tdirty[i]; + vs->tdirty[i] = (byte)vs->height; + vs->bdirty[i] = 0; + if (i!=39 && vs->bdirty[i+1] == (byte)bottom && vs->tdirty[i+1] == (byte)top) { + w += 8; + continue; } - gdi.draw8xPos = i+1; + drawStripToScreen(vs, start, w, top, bottom); + w = 8; } + start = i+1; } } -void Scumm::drawStripToScreen() { - if (gdi.drawBottom <= gdi.drawTop) +void Gdi::drawStripToScreen(VirtScreen *vs, int x, int w, int t, int b) { + byte *ptr; + + if (b <= t) return; - if (_videoMode==0xE) { - gdi.drawTop &= 0xFE; - if (gdi.drawBottom&1) - gdi.drawBottom++; - } + if (t > vs->height) + t = 0; - if (gdi.drawBottom <= gdi.drawTop) { - gdi.drawBottom = gdi.drawTop + 4; - } + if (b > vs->height) + b = vs->height; - if (gdi.drawHeight < gdi.drawTop) { - gdi.drawTop = 0; - } - - if (gdi.drawHeight < gdi.drawBottom) { - gdi.drawBottom = gdi.drawHeight; - } - - gdi.readPtr = getResourceAddress(10, gdi.virtScreen+1) + (gdi.drawTop*40+gdi.readOffs+gdi.draw8xPos)*8; - - blitToScreen(this, gdi.readPtr, gdi.draw8xPos*8, gdi.drawY+gdi.drawTop, gdi.drawWidth, gdi.drawBottom-gdi.drawTop); + ptr = _vm->getResourceAddress(10, vs->number+1) + (t*40+x)*8 + _readOffs; + blitToScreen(_vm, ptr, x*8, vs->topline+t, w, b-t); } - void blit(byte *dst, byte *src, int w, int h) { assert(h>0); do { @@ -296,14 +259,14 @@ void Scumm::setCursor(int cursor) { uint32 data; debug(1,"Loading cursor %d", cursor); - gdi.hotspot_x = cur->hotspot_x; - gdi.hotspot_y = cur->hotspot_y; - gdi.currentCursor = cursor; + gdi._hotspot_x = cur->hotspot_x; + gdi._hotspot_y = cur->hotspot_y; + gdi._currentCursor = cursor; for (i=0; i<4; i++) - gdi.mouseColors[i] = cur->colors[i]; + gdi._mouseColors[i] = cur->colors[i]; - mask = gdi.mouseMask; + mask = gdi._mouseMask; shramount = 0; for(j=0; j<8; j++) { @@ -380,19 +343,19 @@ void Scumm::initBGBuffers() { room = getResourceAddress(1, _roomResource); - ptr = findResource(MKID('RMIH'), findResource(MKID('RMIM'), room)); + ptr = findResource(MKID('RMIH'), findResource(MKID('RMIM'), room, 0), 0); - _numZBuffer = READ_LE_UINT16(ptr+8) + 1; + gdi._numZBuffer = READ_LE_UINT16(ptr+8) + 1; - assert(_numZBuffer>=1 && _numZBuffer<=4); + assert(gdi._numZBuffer>=1 && gdi._numZBuffer<=4); itemsize = (_scrHeight + 4) * 40; - size = itemsize * _numZBuffer; + size = itemsize * gdi._numZBuffer; memset(createResource(10, 9, size), 0, size); for (i=0; i<4; i++) - _imgBufOffs[i] = i*itemsize; + gdi._imgBufOffs[i] = i*itemsize; } void Scumm::setPaletteFromPtr(byte *ptr) { @@ -451,34 +414,43 @@ void Scumm::setDirtyColors(int min, int max) { void Scumm::initCycl(byte *ptr) { int i, j; + ColorCycle *cycl; - for (i=1; i<=16; i++) - _colorCycleDelays[i] = 0; + for (i=0,cycl=_colorCycle; i<16; i++,cycl++) + cycl->delay = 0; while ((j=*ptr++) != 0) { - assert(j>=1 && j<=16); + if (j<1 || j>16) { + error("Invalid color cycle index %d", j); + } + cycl = &_colorCycle[j-1]; + ptr += 2; - _colorCycleCounter[j] = 0; - _colorCycleDelays[j] = 16384 / READ_BE_UINT16_UNALIGNED(ptr); + cycl->counter = 0; + cycl->delay = 16384 / READ_BE_UINT16_UNALIGNED(ptr); ptr += 2; - _colorCycleFlags[j] = READ_BE_UINT16_UNALIGNED(ptr); + cycl->flags = READ_BE_UINT16_UNALIGNED(ptr); ptr += 2; - _colorCycleStart[j] = *ptr++; - _colorCycleEnd[j] = *ptr++; + cycl->start = *ptr++; + cycl->end = *ptr++; } } void Scumm::stopCycle(int i) { + ColorCycle *cycl; + checkRange(16, 0, i, "Stop Cycle %d Out Of Range"); if (i!=0) { - _colorCycleDelays[i] = 0; + _colorCycle[i-1].delay = 0; return; } - for (i=1; i<=16; i++) - _colorCycleDelays[i] = 0; + + for (i=0,cycl=_colorCycle; i<16; i++,cycl++) + cycl->delay = 0; } void Scumm::cyclePalette() { + ColorCycle *cycl; int valueToAdd; int i, num; byte *start, *end; @@ -491,23 +463,21 @@ void Scumm::cyclePalette() { if (valueToAdd < _vars[VAR_TIMER_NEXT]) valueToAdd = _vars[VAR_TIMER_NEXT]; - for (i=1; i<=16; i++) { - if (_colorCycleDelays[i] && - (_colorCycleCounter[i]+=valueToAdd) >= - _colorCycleDelays[i]) { + for (i=0,cycl=_colorCycle; i<16; i++,cycl++) { + if (cycl->delay && + (cycl->counter+=valueToAdd) >= cycl->delay) { do { - _colorCycleCounter[i] -= _colorCycleDelays[i]; - } while (_colorCycleDelays[i] <= _colorCycleCounter[i]); + cycl->counter -= cycl->delay; + } while (cycl->delay <= cycl->counter); - setDirtyColors(_colorCycleStart[i], _colorCycleEnd[i]); - moveMemInPalRes(_colorCycleStart[i], _colorCycleEnd[i], - _colorCycleFlags[i]&2); - start = &_currentPalette[_colorCycleStart[i]*3]; - end = &_currentPalette[_colorCycleEnd[i]*3]; + setDirtyColors(cycl->start, cycl->end); + moveMemInPalRes(cycl->start, cycl->end, cycl->flags&2); + start = &_currentPalette[cycl->start*3]; + end = &_currentPalette[cycl->end*3]; - num = _colorCycleEnd[i] - _colorCycleStart[i]; + num = cycl->end - cycl->start; - if (!(_colorCycleFlags[i]&2)) { + if (!(cycl->flags&2)) { memmove(tmp, end, 3); memmove(start+3, start, num*3); memmove(start, tmp, 3); @@ -560,19 +530,16 @@ void Scumm::unkVirtScreen4(int a) { setDirtyRange(0, 0, 0); camera._lastPos = camera._curPos; - dseg_3DB6 = 2; - dseg_3DB6 = 1; - if (dseg_4EA0 == 0) + if (!_screenEffectFlag) return; - dseg_4EA0 = 0; + _screenEffectFlag = false; if (a==0) return; vs = &virtscr[0]; - gdi.bg_ptr = getResourceAddress(0xA, 1) + vs->xstart; - - memset(gdi.bg_ptr, 0, vs->size); + gdi._backbuff_ptr = getResourceAddress(0xA, 1) + vs->xstart; + memset(gdi._backbuff_ptr, 0, vs->size); switch(a) { case 1: case 2: case 3: @@ -583,7 +550,6 @@ void Scumm::unkVirtScreen4(int a) { break; case 129: setDirtyRange(0, 0, vs->height); - dseg_3DB6 = 2; updateDirtyScreen(0); /* XXX: EGA_proc4(0); */ break; @@ -623,7 +589,6 @@ void Scumm::redrawBGAreas() { val = 1; redrawBGStrip(0, 1); } else if (_fullRedraw!=0 || cd->_curPos != cd->_lastPos) { - dseg_719E = 0; _BgNeedsRedraw = 0; redrawBGStrip(0, 40); } @@ -639,176 +604,171 @@ const uint32 zplane_tags[] = { MKID('ZP03') }; -void Scumm::drawBmp(byte *ptr, int a, int b, int c, const char *str, int objnr) { - byte *smap_ptr; +void Gdi::drawBitmap(byte *ptr, VirtScreen *vs, int x, int y, int h, int stripnr, int numstrip, bool flag) { + byte *smap_ptr,*where_draw_ptr; int i; byte *zplane_list[4]; - int t; - VirtScreen *vs; + int bottom; byte twobufs; - int x; - byte *where_draw_ptr; - + int numzbuf; + int sx; + CHECK_HEAP - smap_ptr = findResource(MKID('SMAP'), ptr); + smap_ptr = findResource(MKID('SMAP'), ptr, 0); - for(i=1; i<_numZBuffer; i++) { - zplane_list[i] = findResource(zplane_tags[i], ptr); + numzbuf = _disable_zbuffer ? 0 : _numZBuffer; + + for(i=1; i vs->height) { - error("%s %d strip drawn to %d below window bottom %d", - str, objnr, t, vs->height); + bottom = y + h; + if (bottom > vs->height) { + error("Gdi::drawBitmap, strip drawn to %d below window bottom %d", bottom, vs->height); } twobufs = vs->alloctwobuffers; - dseg_4174 = vs->size; + _vertStripNextInc = h * 320 - 1; + + _numLinesToProcess = h; - if (vs->scrollable) - dseg_4174 += 5*256; - - gdi.vertStripNextInc = gdi.numLinesToProcess * 320 - 1; - do { - gdi.smap_ptr = smap_ptr + READ_LE_UINT32(smap_ptr + a*4 + 8); - - x = _drawBmpX; - if (vs->scrollable) - x -= _screenStartStrip; + _smap_ptr = smap_ptr + READ_LE_UINT32(smap_ptr + stripnr*4 + 8); CHECK_HEAP - if ((uint)x >= 40) + sx = x; + if (vs->scrollable) + sx -= vs->xstart>>3; + + if ((uint)sx >= 40) return; - if (_drawBmpY < vs->tdirty[x]) - vs->tdirty[x]=_drawBmpY; + if (y < vs->tdirty[sx]) + vs->tdirty[sx]=y; - if (t > vs->bdirty[x]) - vs->bdirty[x]=t; + if (bottom > vs->bdirty[sx]) + vs->bdirty[sx] = bottom; - gdi.bg_ptr = getResourceAddress(0xA, gdi.virtScreen+1) + (_drawBmpY*40+_drawBmpX)*8; - gdi.where_to_draw_ptr = getResourceAddress(0xA, gdi.virtScreen+5) + (_drawBmpY*40+_drawBmpX)*8; + _backbuff_ptr = _vm->getResourceAddress(0xA, vs->number+1) + (y*40+x)*8; + _bgbak_ptr = _vm->getResourceAddress(0xA, vs->number+5) + (y*40+x)*8; if (!twobufs) { - gdi.where_to_draw_ptr = gdi.bg_ptr; + _bgbak_ptr = _backbuff_ptr; } - gdi.mask_ptr = getResourceAddress(0xA, 9) + (_drawBmpY*40+_drawBmpX); + _mask_ptr = _vm->getResourceAddress(0xA, 9) + (y*40+x); - where_draw_ptr = gdi.where_to_draw_ptr; + where_draw_ptr = _bgbak_ptr; decompressBitmap(); CHECK_HEAP if (twobufs) { - gdi.where_to_draw_ptr = where_draw_ptr; - if (_vars[VAR_DRAWFLAGS]&2) { - if (hasCharsetMask(x<<3, _drawBmpY, (x+1)<<3, t)) + _bgbak_ptr = where_draw_ptr; + + if (_vm->hasCharsetMask(sx<<3, y, (sx+1)<<3, bottom)) { + if (_vm->_vars[VAR_V5_DRAWFLAGS]&2) draw8ColWithMasking(); - else { - blit(gdi.bg_ptr, gdi.where_to_draw_ptr, 8, gdi.numLinesToProcess); - } - } else { - if (hasCharsetMask(x<<3, _drawBmpY, (x+1)<<3, t)) + else clear8ColWithMasking(); + } else { + if (_vm->_vars[VAR_V5_DRAWFLAGS]&2) + blit(_backbuff_ptr, _bgbak_ptr, 8, h); else clear8Col(); } } CHECK_HEAP - for (i=1; i<_numZBuffer; i++) { + for (i=1; igetResourceAddress(0xA, 9) + y*40 + x + _imgBufOffs[i]; + if (dseg_4E3B!=0 && flag) decompressMaskImgOr(); else decompressMaskImg(); } CHECK_HEAP - _drawBmpX++; - a++; - } while (--b); + x++; + stripnr++; + } while (--numstrip); } -void Scumm::decompressBitmap() { +void Gdi::decompressBitmap() { const byte decompress_table[] = { 0x0, 0x1, 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F, 0xFF, 0x0, }; dseg_4E3B = 0; - byte code = *gdi.smap_ptr++; + byte code = *_smap_ptr++; - assert(gdi.numLinesToProcess); + assert(_numLinesToProcess); switch(code) { case 1: - GDI_UnkDecode7(); + unkDecode7(); break; case 14: case 15: case 16: case 17: case 18: - gdi.decomp_shr = code - 10; - gdi.decomp_mask = decompress_table[code - 10]; - GDI_UnkDecode6(); + _decomp_shr = code - 10; + _decomp_mask = decompress_table[code - 10]; + unkDecode6(); break; case 24: case 25: case 26: case 27: case 28: - gdi.decomp_shr = code - 20; - gdi.decomp_mask = decompress_table[code - 20]; - GDI_UnkDecode5(); + _decomp_shr = code - 20; + _decomp_mask = decompress_table[code - 20]; + unkDecode5(); break; case 34: case 35: case 36: case 37: case 38: dseg_4E3B = 1; - gdi.decomp_shr = code - 30; - gdi.decomp_mask = decompress_table[code - 30 ]; - GDI_UnkDecode4(); + _decomp_shr = code - 30; + _decomp_mask = decompress_table[code - 30 ]; + unkDecode4(); break; case 44: case 45: case 46: case 47: case 48: dseg_4E3B = 1; - gdi.decomp_shr = code - 40; - gdi.decomp_mask = decompress_table[code - 40]; - GDI_UnkDecode2(); + _decomp_shr = code - 40; + _decomp_mask = decompress_table[code - 40]; + unkDecode2(); break; case 64: case 65: case 66: case 67: case 68: - gdi.decomp_shr = code - 60; - gdi.decomp_mask = decompress_table[code - 60]; - GDI_UnkDecode1(); + _decomp_shr = code - 60; + _decomp_mask = decompress_table[code - 60]; + unkDecode1(); break; case 84: case 85: case 86: case 87: case 88: dseg_4E3B = 1; - gdi.decomp_shr = code - 80; - gdi.decomp_mask = decompress_table[code - 80]; - GDI_UnkDecode3(); + _decomp_shr = code - 80; + _decomp_mask = decompress_table[code - 80]; + unkDecode3(); break; /* New since version 6 */ case 104: case 105: case 106: case 107: case 108: - gdi.decomp_shr = code - 100; - gdi.decomp_mask = decompress_table[code - 100]; - GDI_UnkDecode1(); + _decomp_shr = code - 100; + _decomp_mask = decompress_table[code - 100]; + unkDecode1(); break; /* New since version 6 */ case 124: case 125: case 126: case 127: case 128: dseg_4E3B = 1; - gdi.decomp_shr = code - 120; - gdi.decomp_mask = decompress_table[code - 120]; - GDI_UnkDecode3(); + _decomp_shr = code - 120; + _decomp_mask = decompress_table[code - 120]; + unkDecode3(); break; default: - error("decompressBitmap: default case %d", code); + error("Gdi::decompressBitmap: default case %d", code); } } @@ -819,11 +779,11 @@ int Scumm::hasCharsetMask(int x, int y, int x2, int y2) { return 1; } -void Scumm::draw8ColWithMasking() { - int height = gdi.numLinesToProcess; - byte *mask = gdi.mask_ptr; - byte *dst = gdi.bg_ptr; - byte *src = gdi.where_to_draw_ptr; +void Gdi::draw8ColWithMasking() { + int height = _numLinesToProcess; + byte *mask = _mask_ptr; + byte *dst = _backbuff_ptr; + byte *src = _bgbak_ptr; byte maskbits; do { @@ -848,10 +808,10 @@ void Scumm::draw8ColWithMasking() { } while (--height); } -void Scumm::clear8ColWithMasking() { - int height = gdi.numLinesToProcess; - byte *mask = gdi.mask_ptr; - byte *dst = gdi.bg_ptr; +void Gdi::clear8ColWithMasking() { + int height = _numLinesToProcess; + byte *mask = _mask_ptr; + byte *dst = _backbuff_ptr; byte maskbits; do { @@ -873,19 +833,19 @@ void Scumm::clear8ColWithMasking() { } while (--height); } -void Scumm::clear8Col() { - int height = gdi.numLinesToProcess; - byte *dst = gdi.bg_ptr; +void Gdi::clear8Col() { + int height = _numLinesToProcess; + byte *dst = _backbuff_ptr; do { ((uint32*)dst)[1] = ((uint32*)dst)[0] = 0; dst += 320; } while (--height); } -void Scumm::decompressMaskImg() { - byte *src = gdi.z_plane_ptr; - byte *dst = gdi.mask_ptr_dest; - int height = gdi.numLinesToProcess; +void Gdi::decompressMaskImg() { + byte *src = _z_plane_ptr; + byte *dst = _mask_ptr_dest; + int height = _numLinesToProcess; byte b, c; while(1) { @@ -912,10 +872,10 @@ void Scumm::decompressMaskImg() { } } -void Scumm::decompressMaskImgOr() { - byte *src = gdi.z_plane_ptr; - byte *dst = gdi.mask_ptr_dest; - int height = gdi.numLinesToProcess; +void Gdi::decompressMaskImgOr() { + byte *src = _z_plane_ptr; + byte *dst = _mask_ptr_dest; + int height = _numLinesToProcess; byte b, c; while(1) { @@ -946,41 +906,34 @@ void Scumm::redrawBGStrip(int start, int num) { assert(s>=0 && s _scrHeight) { + if (_curVirtScreen->height > _scrHeight) { error("Screen Y size %d < Room height %d", - gdi.numLinesToProcess, + _curVirtScreen->height, _scrHeight); } - - drawBmp( - getResourceAddress(1, _roomResource) + _IM00_offs, - s, - num, - 0, - "Room", - _roomResource); + + gdi.drawBitmap(getResourceAddress(1, _roomResource)+_IM00_offs, + _curVirtScreen, s, 0, _curVirtScreen->height, s, num, 0); } #define READ_BIT (cl--,bit = bits&1, bits>>=1,bit) #define FILL_BITS if (cl <= 8) { bits |= (*src++ << cl); cl += 8;} -void Scumm::GDI_UnkDecode1() { - byte *src = gdi.smap_ptr; - byte *dst = gdi.where_to_draw_ptr; +void Gdi::unkDecode1() { + byte *src = _smap_ptr; + byte *dst = _bgbak_ptr; byte color = *src++; uint bits = *src++; byte cl = 8; byte bit; byte incm,reps; - gdi.tempNumLines = gdi.numLinesToProcess; + _tempNumLines = _numLinesToProcess; do { - gdi.currentX = 8; + _currentX = 8; do { FILL_BITS *dst++=color; @@ -996,10 +949,10 @@ againPos:; FILL_BITS reps = bits&0xFF; do { - if (!--gdi.currentX) { - gdi.currentX = 8; + if (!--_currentX) { + _currentX = 8; dst += 312; - if (!--gdi.tempNumLines) + if (!--_tempNumLines) return; } *dst++=color; @@ -1012,72 +965,39 @@ againPos:; } } else { FILL_BITS - color = bits&gdi.decomp_mask; - cl -= gdi.decomp_shr; - bits >>= gdi.decomp_shr; + color = bits&_decomp_mask; + cl -= _decomp_shr; + bits >>= _decomp_shr; } - } while (--gdi.currentX); + } while (--_currentX); dst += 312; - } while (--gdi.tempNumLines); + } while (--_tempNumLines); } -#if 0 -void Scumm::GDI_UnkDecode1() { - byte *src = gdi.smap_ptr; - byte *dst = gdi.where_to_draw_ptr; - byte color = *src++; - uint bits = *src++; - byte cl = 8; - byte bit; - gdi.tempNumLines = gdi.numLinesToProcess; - - do { - gdi.currentX = 8; - do { - FILL_BITS - *dst++=color; - - if (!READ_BIT) {} - else if (READ_BIT) { - color += (bits&7)-4; - cl-=3; - bits>>=3; - } else { - FILL_BITS - color = bits&gdi.decomp_mask; - cl -= gdi.decomp_shr; - bits >>= gdi.decomp_shr; - } - } while (--gdi.currentX); - dst += 312; - } while (--gdi.tempNumLines); -} -#endif - -void Scumm::GDI_UnkDecode2() { - byte *src = gdi.smap_ptr; - byte *dst = gdi.where_to_draw_ptr; +void Gdi::unkDecode2() { + byte *src = _smap_ptr; + byte *dst = _bgbak_ptr; byte color = *src++; int8 inc = -1; uint bits = *src++; byte cl = 8; byte bit; - gdi.tempNumLines = gdi.numLinesToProcess; + _tempNumLines = _numLinesToProcess; do { - gdi.currentX = 8; + _currentX = 8; do { FILL_BITS - if (color!=gdi.transparency) + if (color!=_transparency) *dst=color; dst++; if (!READ_BIT) {} else if (!READ_BIT) { FILL_BITS - color = bits&gdi.decomp_mask; - bits >>= gdi.decomp_shr; - cl -= gdi.decomp_shr; + color = bits&_decomp_mask; + bits >>= _decomp_shr; + cl -= _decomp_shr; inc = -1; } else if (!READ_BIT) { color += inc; @@ -1085,27 +1005,27 @@ void Scumm::GDI_UnkDecode2() { inc = -inc; color += inc; } - } while (--gdi.currentX); + } while (--_currentX); dst += 312; - } while (--gdi.tempNumLines); + } while (--_tempNumLines); } -void Scumm::GDI_UnkDecode3() { - byte *src = gdi.smap_ptr; - byte *dst = gdi.where_to_draw_ptr; +void Gdi::unkDecode3() { + byte *src = _smap_ptr; + byte *dst = _bgbak_ptr; byte color = *src++; uint bits = *src++; byte cl = 8; byte bit; byte incm,reps; - gdi.tempNumLines = gdi.numLinesToProcess; + _tempNumLines = _numLinesToProcess; do { - gdi.currentX = 8; + _currentX = 8; do { FILL_BITS - if (color!=gdi.transparency) *dst=color; + if (color!=_transparency) *dst=color; dst++; againPos:; @@ -1120,22 +1040,22 @@ againPos:; } else { FILL_BITS reps = bits&0xFF; - if (color==gdi.transparency) { + if (color==_transparency) { do { - if (!--gdi.currentX) { - gdi.currentX = 8; + if (!--_currentX) { + _currentX = 8; dst += 312; - if (!--gdi.tempNumLines) + if (!--_tempNumLines) return; } dst++; } while (--reps); } else { do { - if (!--gdi.currentX) { - gdi.currentX = 8; + if (!--_currentX) { + _currentX = 8; dst += 312; - if (!--gdi.tempNumLines) + if (!--_tempNumLines) return; } *dst++=color; @@ -1147,74 +1067,39 @@ againPos:; } } else { FILL_BITS - color = bits&gdi.decomp_mask; - cl -= gdi.decomp_shr; - bits >>= gdi.decomp_shr; + color = bits&_decomp_mask; + cl -= _decomp_shr; + bits >>= _decomp_shr; } - } while (--gdi.currentX); + } while (--_currentX); dst += 312; - } while (--gdi.tempNumLines); + } while (--_tempNumLines); } -#if 0 -void Scumm::GDI_UnkDecode3() { - byte *src = gdi.smap_ptr; - byte *dst = gdi.where_to_draw_ptr; - byte color = *src++; - uint bits = *src++; - byte cl = 8; - byte bit; - gdi.tempNumLines = gdi.numLinesToProcess; - - do { - gdi.currentX = 8; - do { - FILL_BITS - if (color!=gdi.transparency) *dst=color; - dst++; - - if (!READ_BIT) {} - else if (READ_BIT) { - color += (bits&7)-4; - cl-=3; - bits>>=3; - } else { - FILL_BITS - color = bits&gdi.decomp_mask; - cl -= gdi.decomp_shr; - bits >>= gdi.decomp_shr; - } - } while (--gdi.currentX); - dst += 312; - } while (--gdi.tempNumLines); -} -#endif - - -void Scumm::GDI_UnkDecode4() { - byte *src = gdi.smap_ptr; - byte *dst = gdi.where_to_draw_ptr; +void Gdi::unkDecode4() { + byte *src = _smap_ptr; + byte *dst = _bgbak_ptr; byte color = *src++; int8 inc = -1; uint bits = *src++; byte cl = 8; byte bit; - gdi.currentX = 8; + _currentX = 8; do { - gdi.tempNumLines = gdi.numLinesToProcess; + _tempNumLines = _numLinesToProcess; do { FILL_BITS - if (color!=gdi.transparency) + if (color!=_transparency) *dst=color; dst+=320; if (!READ_BIT) {} else if (!READ_BIT) { FILL_BITS - color = bits&gdi.decomp_mask; - bits >>= gdi.decomp_shr; - cl -= gdi.decomp_shr; + color = bits&_decomp_mask; + bits >>= _decomp_shr; + cl -= _decomp_shr; inc = -1; } else if (!READ_BIT) { color += inc; @@ -1222,33 +1107,33 @@ void Scumm::GDI_UnkDecode4() { inc = -inc; color += inc; } - } while (--gdi.tempNumLines); - dst -= gdi.vertStripNextInc; - } while (--gdi.currentX); + } while (--_tempNumLines); + dst -= _vertStripNextInc; + } while (--_currentX); } -void Scumm::GDI_UnkDecode5() { - byte *src = gdi.smap_ptr; - byte *dst = gdi.where_to_draw_ptr; +void Gdi::unkDecode5() { + byte *src = _smap_ptr; + byte *dst = _bgbak_ptr; byte color = *src++; int8 inc = -1; uint bits = *src++; byte cl = 8; byte bit; - gdi.tempNumLines = gdi.numLinesToProcess; + _tempNumLines = _numLinesToProcess; do { - gdi.currentX = 8; + _currentX = 8; do { FILL_BITS *dst++=color; if (!READ_BIT) {} else if (!READ_BIT) { FILL_BITS - color = bits&gdi.decomp_mask; - bits >>= gdi.decomp_shr; - cl -= gdi.decomp_shr; + color = bits&_decomp_mask; + bits >>= _decomp_shr; + cl -= _decomp_shr; inc = -1; } else if (!READ_BIT) { color += inc; @@ -1256,23 +1141,23 @@ void Scumm::GDI_UnkDecode5() { inc = -inc; color += inc; } - } while (--gdi.currentX); + } while (--_currentX); dst += 312; - } while (--gdi.tempNumLines); + } while (--_tempNumLines); } -void Scumm::GDI_UnkDecode6() { - byte *src = gdi.smap_ptr; - byte *dst = gdi.where_to_draw_ptr; +void Gdi::unkDecode6() { + byte *src = _smap_ptr; + byte *dst = _bgbak_ptr; byte color = *src++; int8 inc = -1; uint bits = *src++; byte cl = 8; byte bit; - gdi.currentX = 8; + _currentX = 8; do { - gdi.tempNumLines = gdi.numLinesToProcess; + _tempNumLines = _numLinesToProcess; do { FILL_BITS *dst=color; @@ -1280,9 +1165,9 @@ void Scumm::GDI_UnkDecode6() { if (!READ_BIT) {} else if (!READ_BIT) { FILL_BITS - color = bits&gdi.decomp_mask; - bits >>= gdi.decomp_shr; - cl -= gdi.decomp_shr; + color = bits&_decomp_mask; + bits >>= _decomp_shr; + cl -= _decomp_shr; inc = -1; } else if (!READ_BIT) { color += inc; @@ -1290,15 +1175,15 @@ void Scumm::GDI_UnkDecode6() { inc = -inc; color += inc; } - } while (--gdi.tempNumLines); - dst -= gdi.vertStripNextInc; - } while (--gdi.currentX); + } while (--_tempNumLines); + dst -= _vertStripNextInc; + } while (--_currentX); } -void Scumm::GDI_UnkDecode7() { - byte *src = gdi.smap_ptr; - byte *dst = gdi.where_to_draw_ptr; - int height = gdi.numLinesToProcess; +void Gdi::unkDecode7() { + byte *src = _smap_ptr; + byte *dst = _bgbak_ptr; + int height = _numLinesToProcess; do { /* Endian safe */ #if defined(SCUMM_NEED_ALIGNMENT) @@ -1316,7 +1201,7 @@ void Scumm::GDI_UnkDecode7() { #undef FILL_BITS void Scumm::restoreCharsetBg() { - dseg_4E3C = 0; + _bkColor = 0; if (string[0].mask_left != -1) { restoreBG(string[0].mask_left, string[0].mask_top, string[0].mask_right, string[0].mask_bottom); charset._hasMask = false; @@ -1332,19 +1217,18 @@ void Scumm::restoreCharsetBg() { void Scumm::restoreBG(int left, int top, int right, int bottom) { VirtScreen *vs; int topline, height, width, widthmod; + byte *backbuff,*bgbak,*mask; if (left==right || top==bottom) return; if (top<0) top=0; - if (findVirtScreen(top) == -1) + if ((vs=findVirtScreen(top)) == NULL) return; - - vs = &virtscr[gdi.virtScreen]; topline = vs->topline; height = topline + vs->height; - if (gdi.virtScreen==0) { + if (vs->number==0) { left += _lastXstart - vs->xstart; right += _lastXstart - vs->xstart; } @@ -1359,35 +1243,34 @@ void Scumm::restoreBG(int left, int top, int right, int bottom) { if (bottom>=height) bottom=height; - updateDirtyRect(gdi.virtScreen, left, right, top-topline,bottom-topline, 0x4000); + updateDirtyRect(vs->number, left, right, top-topline,bottom-topline, 0x4000); - vs = &virtscr[gdi.virtScreen]; height = (top-topline) * 320 + vs->xstart + left; - gdi.bg_ptr = getResourceAddress(0xA, gdi.virtScreen+1) + height; - gdi.where_to_draw_ptr = getResourceAddress(0xA, gdi.virtScreen+5) + height; - gdi.mask_ptr = getResourceAddress(0xA, 9) + top * 40 + (left>>3) + _screenStartStrip; - if (gdi.virtScreen==0) { - gdi.mask_ptr += vs->topline * 216; + backbuff = getResourceAddress(0xA, vs->number+1) + height; + bgbak = getResourceAddress(0xA, vs->number+5) + height; + mask = getResourceAddress(0xA, 9) + top * 40 + (left>>3) + _screenStartStrip; + if (vs->number==0) { + mask += vs->topline * 216; } height = bottom - top; width = right - left; widthmod = (width >> 2) + 2; - if (vs->alloctwobuffers && _currentRoom!=0 && _vars[VAR_DRAWFLAGS]&2) { - blit(gdi.bg_ptr, gdi.where_to_draw_ptr, width, height); - if (gdi.virtScreen==0 && charset._hasMask && height) { + if (vs->alloctwobuffers && _currentRoom!=0 && _vars[VAR_V5_DRAWFLAGS]&2) { + blit(backbuff, bgbak, width, height); + if (vs->number==0 && charset._hasMask && height) { do { - memset(gdi.mask_ptr, 0, widthmod); - gdi.mask_ptr += 40; + memset(mask, 0, widthmod); + mask += 40; } while (--height); } } else { if (height) { do { - memset(gdi.bg_ptr, dseg_4E3C, width); - gdi.bg_ptr+=320; + memset(backbuff, _bkColor, width); + backbuff+=320; } while (--height); } } @@ -1439,19 +1322,16 @@ void Scumm::updateDirtyRect(int virt, int left, int right, int top, int bottom, } } -int Scumm::findVirtScreen(int y) { +VirtScreen *Scumm::findVirtScreen(int y) { VirtScreen *vs = virtscr; int i; - - gdi.virtScreen=-1; - + for(i=0; i<3; i++,vs++) { if (y >= vs->topline && y < vs->topline+vs->height) { - gdi.virtScreen = i; - return i; + return _curVirtScreen=vs; } } - return -1; + return _curVirtScreen=NULL; } void Scumm::unkScreenEffect1() { @@ -1549,8 +1429,6 @@ void Scumm::unkScreenEffect7(int a) { updateScreen(this); waitForTimer(this); } - /* XXX: not implemented */ - warning("stub unkScreenEffect7(%d)", a); } void Scumm::unkScreenEffect6() { @@ -1572,9 +1450,9 @@ void Scumm::setShake(int mode) { warning("stub setShake(%d)",mode); } -void Scumm::clearUpperMask() { +void Gdi::clearUpperMask() { memset( - getResourceAddress(0xA, 9), + _vm->getResourceAddress(0xA, 9), 0, _imgBufOffs[1] - _imgBufOffs[0] ); @@ -1733,7 +1611,6 @@ void Scumm::palManipulate() { } void Scumm::screenEffect(int effect) { - dseg_3DB6 = 1; switch(effect) { case 1: case 2: @@ -1748,7 +1625,7 @@ void Scumm::screenEffect(int effect) { default: warning("Unknown screen effect, %d", effect); } - dseg_4EA0 = 1; + _screenEffectFlag = true; } void Scumm::resetActorBgs() { @@ -1756,6 +1633,7 @@ void Scumm::resetActorBgs() { int i,bitpos; int top,bottom; uint16 onlyActorFlags; + int offs; for(i=0; i<40; i++) { onlyActorFlags = (actorDrawBits[_screenStartStrip + i]&=0x3FFF); @@ -1766,30 +1644,9 @@ void Scumm::resetActorBgs() { if(onlyActorFlags&1 && a->top!=0xFF && a->needBgReset) { top = a->top; bottom = a->bottom; - if (a->top < virtscr[0].tdirty[i]) - virtscr[0].tdirty[i] = a->top; - - if (a->bottom > virtscr[0].bdirty[i]) - virtscr[0].bdirty[i] = a->bottom; actorDrawBits[_screenStartStrip + i] ^= bitpos; - - gdi.where_to_draw_ptr = getResourceAddress(0xA, 5) - + ((top * 40 + _screenStartStrip + i)<<3); - gdi.bg_ptr = getResourceAddress(0xA, 1) - + ((top * 40 + _screenStartStrip + i)<<3); - gdi.mask_ptr = getResourceAddress(0xA, 9) - + (top * 40 + _screenStartStrip + i); - gdi.numLinesToProcess = bottom - top; - if (gdi.numLinesToProcess) { - if (_vars[VAR_DRAWFLAGS]&2) { - if(hasCharsetMask(i<<3, top, (i+1)<<3, bottom)) - draw8ColWithMasking(); - else - blit(gdi.bg_ptr, gdi.where_to_draw_ptr, 8, gdi.numLinesToProcess); - } else { - clear8Col(); - } - } + gdi.resetBackground(a->top, a->bottom, i); + } bitpos<<=1; onlyActorFlags>>=1; @@ -1802,6 +1659,34 @@ void Scumm::resetActorBgs() { } } +void Gdi::resetBackground(byte top, byte bottom, int strip) { + VirtScreen *vs = &_vm->virtscr[0]; + int offs; + + if (top < vs->tdirty[strip]) + vs->tdirty[strip] = top; + + if (bottom > vs->bdirty[strip]) + vs->bdirty[strip] = bottom; + + offs = (top * 40 + _vm->_screenStartStrip + strip); + _mask_ptr = _vm->getResourceAddress(0xA, 9) + offs; + _bgbak_ptr = _vm->getResourceAddress(0xA, 5) + (offs<<3); + _backbuff_ptr = _vm->getResourceAddress(0xA, 1) + (offs<<3); + + _numLinesToProcess = bottom - top; + if (_numLinesToProcess) { + if (_vm->_vars[VAR_V5_DRAWFLAGS]&2) { + if(_vm->hasCharsetMask(strip<<3, top, (strip+1)<<3, bottom)) + draw8ColWithMasking(); + else + blit(_backbuff_ptr, _bgbak_ptr, 8, _numLinesToProcess); + } else { + clear8Col(); + } + } +} + void Scumm::setPalColor(int index, int r, int g, int b) { if(_videoMode==0x13) { _currentPalette[index*3+0] = r>>2; @@ -1819,11 +1704,11 @@ void Scumm::drawMouse() { /* TODO: handle shake here */ ::drawMouse(this, - mouse.x - gdi.hotspot_x, - mouse.y - gdi.hotspot_y, - gdi.mouseColors[((++gdi.mouseColorIndex)>>2)&3], - gdi.mouseMask + ((gdi.drawMouseX&7)<<6), - gdi.unk4>0 + mouse.x - gdi._hotspot_x, + mouse.y - gdi._hotspot_y, + gdi._mouseColors[((++gdi._mouseColorIndex)>>2)&3], + gdi._mouseMask + ((gdi._drawMouseX&7)<<6), + gdi._unk4>0 ); } @@ -1833,17 +1718,33 @@ void Scumm::setCursorHotspot(int cursor, int x, int y) { cur->hotspot_y = y; } -void Scumm::setCursorImg(int cursor, int img) { - MouseCursor *cur = &mouse_cursors[cursor]; +void Scumm::setCursorImg(int room, int img) { byte *ptr; + int index; + CodeHeader *cdhd; + ImageHeader *imhd; + int w,h; + byte *roomptr; + RoomHeader *rmhd; - ptr = getResourceAddress(6, 1); + if (getObjectIndex(img)!=-1) { + cdhd = (CodeHeader*)getObjectAddress(img); + ptr = (byte*)cdhd + READ_BE_UINT32(&cdhd->size); + cdhd = (CodeHeader*)findResource(MKID('CDHD'), (byte*)cdhd, 0); + w = READ_LE_UINT16(&cdhd->v6.w)>>3; + h = READ_LE_UINT16(&cdhd->v6.h)>>3; + imhd = (ImageHeader*)findResource(MKID('IMHD'), ptr, 0); + } else { +// error("setCursorImg: -1 not impl"); + } + + // offs = ((uint32*)ptr)[img+1]; // if (!offs) // return; - warning("setCursorImg: not implemented"); + warning("stub setCursorImg(%d,%d)", room, img); } byte Scumm::isMaskActiveAt(int l, int t, int r, int b, byte *mem) { @@ -1865,15 +1766,25 @@ byte Scumm::isMaskActiveAt(int l, int t, int r, int b, byte *mem) { return false; } +void Scumm::setPalette(int palindex) { + byte *pals; + + _curPalIndex = palindex; + pals = getPalettePtr(); + if (pals==NULL) + error("invalid palette %d", palindex); + setPaletteFromPtr(pals); +} + byte *Scumm::findPalInPals(byte *pal, int index) { byte *offs; uint32 size; - pal = findResource(MKID('WRAP'), pal); + pal = findResource(MKID('WRAP'), pal, 0); if (pal==NULL) return NULL; - offs = findResource(MKID('OFFS'),pal); + offs = findResource(MKID('OFFS'),pal, 0); if (offs==NULL) return NULL; @@ -1885,102 +1796,80 @@ byte *Scumm::findPalInPals(byte *pal, int index) { return offs + READ_LE_UINT32(offs + 8 + index * sizeof(uint32)); } -void Scumm::setPalette(int palindex) { - byte *pals; +byte *Scumm::getPalettePtr() { + byte *cptr; - _curPalIndex = palindex; - - pals = getResourceAddress(1, _roomResource) + _PALS_offs; - - pals = findPalInPals(pals, palindex); - - if (pals==NULL) - error("invalid palette %d", palindex); - - setPaletteFromPtr(pals); + cptr = getResourceAddress(1, _roomResource); + if (_CLUT_offs) { + cptr += _CLUT_offs; + } else { + cptr = findPalInPals(cptr + _PALS_offs, _curPalIndex); + } + return cptr; } -#if 0 -void Scumm::GDI_drawMouse() { - byte *dst,*src,*dstorg; - int y,h; - byte color,val; +void Scumm::darkenPalette(int a, int b, int c, int d, int e) { + byte *cptr, *cur; + int num; + byte color; - byte mask1,mask2,mask3; + if (_videoMode==0xE) { + warning("stub darkenPalette(%d,%d,%d,%d,%d)",a,b,c,d,e); + } - int offs = gdi.drawMouseY*320 + (gdi.drawMouseX&0xFFF8); + if (_videoMode==0x13) { + cptr = getPalettePtr(); + cptr += 8 + a*3; + cur = _currentPalette + a*3; + if (a <= b) { + num = b - a + 1; - /* XXX: check bounds here */ - if (offs<0 || offs > 320*200 - 16*320) - return; - - gdi.backupIsWhere = _vgabuf + offs; + do { + if (c != 0xFF) { + color = *cptr++ * (c>>2) / 0xFF; + } else { + color = *cptr++ >> 2; + } + if(color>63) color = 63; + *cur++=color; - src = gdi.backupIsWhere; - dst = gdi.mouseBackup; + if (d != 0xFF) { + color = *cptr++ * (d>>2) / 0xFF; + } else { + color = *cptr++ >> 2; + } + if(color>63) color = 63; + *cur++=color; - h=16; - do { - memcpy(dst,src,24); - dst+=24; - src+=320; - } while (--h); - - src = gdi.mouseMaskPtr; - color = gdi.mouseColor; - dstorg = gdi.backupIsWhere; - - h=16; - do { - src++; - mask1 = *src++; - mask2 = *src++; - mask3 = *src++; - - y = gdi.drawMouseY++; - if (y>199) - mask1 = mask2 = 0; - - val = mask1 & gdi.mouseClipMask1; - dst = dstorg; - do { - if(val&0x80) - *dst = color; - dst++; - } while (val<<=1); - - val = mask2 & gdi.mouseClipMask2; - dst = dstorg + 8; - do { - if(val&0x80) - *dst = color; - dst++; - } while (val<<=1); - - val = mask3 & gdi.mouseClipMask3; - dst = dstorg + 16; - do { - if(val&0x80) - *dst = color; - dst++; - } while (val<<=1); - - dstorg += 320; - } while (--h); -} - -void Scumm::GDI_removeMouse() { - byte *dst,*src,h; - if (gdi.backupIsWhere) { - dst = gdi.backupIsWhere; - gdi.backupIsWhere = NULL; - src = gdi.mouseBackup; - h=16; - do { - memcpy(dst,src,24); - dst+=320; - src+=24; - } while (--h); + if (e != 0xFF) { + color = *cptr++ * (e>>2) / 0xFF; + } else { + color = *cptr++ >> 2; + } + if(color>63) color = 63; + *cur++=color; + } while (--num); + } + setDirtyColors(a,b); } } -#endif + +void Scumm::unkMiscOp4(int a, int b, int c, int d) { + VirtScreen *vs = findVirtScreen(b); + + if (vs==NULL) { + warning("unkMiscOp4: invalid virtscreen %d", b); + return; + } + + grabCursor( + getResourceAddress(10, vs->number+1) + (b-vs->topline)*320 + a, + c,d); + + + warning("stub unkMiscOp4(%d,%d,%d,%d)", a,b,c,d); +} + +void Scumm::grabCursor(byte *ptr, int width, int height) { + +} diff --git a/object.cpp b/object.cpp index e48abf6ed4f..36b8390998e 100644 --- a/object.cpp +++ b/object.cpp @@ -17,6 +17,9 @@ * * Change Log: * $Log$ + * Revision 1.7 2001/10/26 17:34:50 strigeus + * bug fixes, code cleanup + * * Revision 1.6 2001/10/23 19:51:50 strigeus * recompile not needed when switching games * debugger skeleton implemented @@ -152,13 +155,13 @@ void Scumm::getObjectXYPos(int object) { if (od->fl_object_index) { ptr = getResourceAddress(0xD, od->fl_object_index); - ptr = findResource(MKID('OBIM'), ptr); + ptr = findResource(MKID('OBIM'), ptr, 0); } else { ptr = getResourceAddress(1, _roomResource); ptr += od->offs_obim_to_room; } - imhd = (ImageHeader*)findResource2(MKID('IMHD'), ptr); + imhd = (ImageHeader*)findResource(MKID('IMHD'), ptr, 0); x = od->x_pos*8 + (int16)READ_LE_UINT16(&imhd->hotspot[state].x); y = od->y_pos*8 + (int16)READ_LE_UINT16(&imhd->hotspot[state].y); } else { @@ -196,7 +199,6 @@ int Scumm::getObjActToObjActDist(int a, int b) { if (getObjectOrActorXY(b)==-1) return 0xFF; - /* XXX: bug here? should be <= */ if (acta) { AdjustBoxResult r = adjustXYToBeInBox(acta, _xPos, _yPos); _xPos = r.x; @@ -281,12 +283,13 @@ void Scumm::drawObject(int obj, int arg) { ObjectData *od; int xpos, ypos, height, width; byte *ptr; - int x,a,b; + int x,a,numstrip; + int tmp; if (_BgNeedsRedraw) arg = 0; - gdi.virtScreen = 0; + _curVirtScreen = &virtscr[0]; od = &_objs[obj]; @@ -300,40 +303,39 @@ void Scumm::drawObject(int obj, int arg) { if (od->fl_object_index) { ptr = getResourceAddress(0xD, od->fl_object_index); - ptr = findResource(MKID('OBIM'), ptr); + ptr = findResource(MKID('OBIM'), ptr, 0); } else { ptr = getResourceAddress(1, _roomResource); ptr = ptr + od->offs_obim_to_room; } - ptr = findResource(state_tags[getState(od->obj_nr)], ptr); + ptr = findResource(state_tags[getState(od->obj_nr)], ptr, 0); if (!ptr) return; x = 0xFFFF; - for (a=b=0; a _drawBmpX || _drawBmpX > _screenEndStrip) + if (tmp < _screenStartStrip || tmp > _screenEndStrip) continue; - actorDrawBits[_drawBmpX] |= 0x8000; - if (_drawBmpX < x) - x = _drawBmpX; - b++; + actorDrawBits[tmp] |= 0x8000; + if (tmp < x) + x = tmp; + numstrip++; } - if (b==0) - return; + if (numstrip!=0) + gdi.drawBitmap(ptr, _curVirtScreen, x, ypos<<3, height<<3, x-xpos, numstrip, true); - _drawBmpY = ypos << 3; - gdi.numLinesToProcess = height << 3; - - _drawBmpX = x; - drawBmp(ptr, x - xpos, b, 1, "Object", od->obj_nr); +// _drawBmpY = ypos << 3; +// gdi._numLinesToProcess = height << 3; +// _drawBmpX = x; +// drawBmp(ptr, x - xpos, b, 1, "Object", od->obj_nr); } void Scumm::loadRoomObjects() { @@ -341,7 +343,7 @@ void Scumm::loadRoomObjects() { ObjectData *od; byte *ptr; uint16 obim_id; - byte *room,*tmp_room; + byte *room; ImageHeader *imhd; RoomHeader *roomhdr; @@ -350,7 +352,7 @@ void Scumm::loadRoomObjects() { CHECK_HEAP room = getResourceAddress(1, _roomResource); - roomhdr = (RoomHeader*)findResource(MKID('RMHD'), room); + roomhdr = (RoomHeader*)findResource(MKID('RMHD'), room, 0); _numObjectsInRoom = READ_LE_UINT16(&roomhdr->numObjects); @@ -360,16 +362,14 @@ void Scumm::loadRoomObjects() { if (_numObjectsInRoom > _numLocalObjects) error("More than %d objects in room %d", _numLocalObjects, _roomResource); - tmp_room = room; - od = &_objs[1]; - for (i=1; i<=_numObjectsInRoom; i++,od++) { - ptr = findResource(MKID('OBCD'), tmp_room); + for (i=0; i<_numObjectsInRoom; i++,od++) { + ptr = findResource(MKID('OBCD'), room, i); if (ptr==NULL) error("Room %d missing object code block(s)", _roomResource); od->offs_obcd_to_room = ptr - room; - cdhd = (CodeHeader*)findResource2(MKID('CDHD'), ptr); + cdhd = (CodeHeader*)findResource(MKID('CDHD'), ptr, 0); od->obj_nr = READ_LE_UINT16(&cdhd->obj_id); #ifdef DUMP_SCRIPTS @@ -379,29 +379,26 @@ void Scumm::loadRoomObjects() { dumpResource(buf, od->obj_nr, ptr); } while (0); #endif - tmp_room = NULL; } - tmp_room = room; - for (i=1; i<=_numObjectsInRoom; i++) { - ptr = findResource(MKID('OBIM'), tmp_room); + for (i=0; i<_numObjectsInRoom; i++) { + ptr = findResource(MKID('OBIM'), room, i); if (ptr==NULL) error("Room %d missing image blocks(s)", _roomResource); - imhd = (ImageHeader*)findResource2(MKID('IMHD'), ptr); + imhd = (ImageHeader*)findResource(MKID('IMHD'), ptr, 0); obim_id = READ_LE_UINT16(&imhd->obj_id); for(j=1; j<=_numObjectsInRoom; j++) { if (_objs[j].obj_nr==obim_id) _objs[j].offs_obim_to_room = ptr - room; } - tmp_room = NULL; } od = &_objs[1]; for (i=1; i<=_numObjectsInRoom; i++,od++) { ptr = room + _objs[i].offs_obcd_to_room; - cdhd = (CodeHeader*)findResource2(MKID('CDHD'), ptr); + cdhd = (CodeHeader*)findResource(MKID('CDHD'), ptr,0); _objs[i].obj_nr = READ_LE_UINT16(&cdhd->obj_id); if (_majorScummVersion == 6) { @@ -482,14 +479,15 @@ void Scumm::clearOwnerOf(int obj) { nukeResource(5, i); _inventory[i] = 0; } - a = &_inventory[2]; - for (i=1; i < _maxInventoryItems-1; i++) { - if (!a[-1] && a[0]) { - a[-1] = a[0]; + a = &_inventory[1]; + for (i=1; i < _maxInventoryItems-1; i++,a++) { + if (!a[0] && a[1]) { + a[0] = a[1]; + a[1] = 0; ptr = getResourceAddress(5, i+1); _baseInventoryItems[i] = _baseInventoryItems[i+1]; + _baseInventoryItems[i+1] = 0; /* TODO: some wacky write is done here */ - error("clearOwnerOf: not fully implemented"); } } return; @@ -536,7 +534,7 @@ byte *Scumm::getObjOrActorName(int obj) { if (objptr==NULL) return (byte*)" "; - return findResource(MKID('OBNA'), objptr) + 8; + return findResource(MKID('OBNA'), objptr, 0) + 8; } uint32 Scumm::getOBCDOffs(int object) { @@ -579,7 +577,7 @@ void Scumm::addObjectToInventory(int obj, int room) { byte *ptr,*obcdptr; uint32 size,cdoffs; int numobj; - byte *tmp_roomptr,*roomptr; + byte *roomptr; CodeHeader *cdhd; RoomHeader *roomhdr; @@ -601,19 +599,18 @@ void Scumm::addObjectToInventory(int obj, int room) { } ensureResourceLoaded(1, room); roomptr = getResourceAddress(1, room); - roomhdr = (RoomHeader*)findResource(MKID('RMHD'), roomptr); + roomhdr = (RoomHeader*)findResource(MKID('RMHD'), roomptr, 0); numobj = READ_LE_UINT16(&roomhdr->numObjects); if (numobj==0) error("addObjectToInventory: No object found in room %d", room); if (numobj > 200) error("addObjectToInventory: More (%d) than %d objects in room %d", numobj, 200, room); - tmp_roomptr = roomptr; - for (i=1; i<=numobj; i++) { - obcdptr = findResource(MKID('OBCD'), tmp_roomptr); + for (i=0; iobj_id) == obj) { cdoffs = obcdptr - roomptr; size = READ_BE_UINT32_UNALIGNED(obcdptr+4); @@ -625,7 +622,6 @@ void Scumm::addObjectToInventory(int obj, int room) { CHECK_HEAP return; } - tmp_roomptr = NULL; } error("addObjectToInventory: Object %d not found in room %d", obj, room); diff --git a/resource.cpp b/resource.cpp index b080ee06b78..6aa877652f2 100644 --- a/resource.cpp +++ b/resource.cpp @@ -17,6 +17,9 @@ * * Change Log: * $Log$ + * Revision 1.7 2001/10/26 17:34:50 strigeus + * bug fixes, code cleanup + * * Revision 1.6 2001/10/24 20:12:52 strigeus * fixed some bugs related to string handling * @@ -650,20 +653,19 @@ void Scumm::unkResourceProc() { warning("unkResourceProc: not implemented"); } +byte *findResource(uint32 tag, byte *searchin, int index) { + uint32 maxsize,curpos,totalsize,size; -byte *Scumm::findResource(uint32 tag, byte *searchin) { - uint32 size; + searchin += 4; + totalsize = READ_BE_UINT32_UNALIGNED(searchin); + curpos = 8; + searchin += 4; - if (searchin) { - searchin+=4; - _findResSize = READ_BE_UINT32_UNALIGNED(searchin); - _findResHeaderSize = 8; - _findResPos = searchin+4; - goto startScan; - } + while (curpos>8)&0xFF,(tag>>16)&0xFF,(tag>>24)&0xFF, @@ -671,53 +673,17 @@ byte *Scumm::findResource(uint32 tag, byte *searchin) { size); return NULL; } - _findResHeaderSize += size; - _findResPos += size; - -startScan:; - if (_findResHeaderSize >= _findResSize) - return NULL; -/* endian OK, tags are in native format */ - } while (READ_UINT32_UNALIGNED(_findResPos) != tag); - return _findResPos; -} + curpos += size; + searchin += size; + } -byte *Scumm::findResource2(uint32 tag, byte *searchin) { - uint32 size; - - if (searchin) { - searchin+=4; - _findResSize2 = READ_BE_UINT32_UNALIGNED(searchin); - _findResHeaderSize2 = 8; - _findResPos2 = searchin+4; - goto startScan; - } - - do { - size = READ_BE_UINT32_UNALIGNED(_findResPos2+4); - if ((int32)size <= 0) { - error("(%c%c%c%c) Not found in %d... illegal block len %d", - tag&0xFF,(tag>>8)&0xFF,(tag>>16)&0xFF,(tag>>24)&0xFF, - 0, - size); - return NULL; - } - _findResHeaderSize2 += size; - _findResPos2 += size; - -startScan:; - if (_findResHeaderSize2 >= _findResSize2) - return NULL; -/* endian OK, tags are in native format */ - } while (READ_UINT32_UNALIGNED(_findResPos2) != tag); - return _findResPos2; + return NULL; } void Scumm::lock(int type, int i) { validateResource("Locking", type, i); res.flags[type][i] |= 0x80; - } void Scumm::unlock(int type, int i) { diff --git a/saveload.cpp b/saveload.cpp index c6f99c34cd5..2a8af2d5d2f 100644 --- a/saveload.cpp +++ b/saveload.cpp @@ -17,6 +17,9 @@ * * Change Log: * $Log$ + * Revision 1.6 2001/10/26 17:34:50 strigeus + * bug fixes, code cleanup + * * Revision 1.5 2001/10/18 20:04:58 strigeus * flags were not saved properly * @@ -72,6 +75,7 @@ bool Scumm::loadState(const char *filename) { FILE *out = fopen(filename,"rb"); int i,j; SaveGameHeader hdr; + int sb,sh; if (out==NULL) return false; @@ -105,11 +109,20 @@ bool Scumm::loadState(const char *filename) { saveOrLoad(out,false); fclose(out); - initScreens(0, _screenB, 320, _screenH); + sb = _screenB; + sh = _screenH; + + initScreens(0, 0, 320, 200); + _screenEffectFlag = 1; + unkVirtScreen4(129); + + initScreens(0, sb, 320, sh); _completeScreenRedraw = 1; setDirtyColors(0,255); + _lastCodePtr = NULL; + _drawObjectQueNr = 0; _verbMouseOver = 0; @@ -255,7 +268,7 @@ void Scumm::saveOrLoad(FILE *inout, bool mode) { MKLINE(Scumm,_numObjectsInRoom,sleByte), MKLINE(Scumm,_currentScript,sleByte), MKARRAY(Scumm,_localScriptList[0],sleUint32,0x39), - MKARRAY(Scumm,vm.localvar[0],sleUint16,20*17), + MKARRAY(Scumm,vm.localvar[0],sleUint16,NUM_SCRIPT_SLOT*17), MKARRAY(Scumm,_resourceMapper[0],sleByte,128), MKARRAY(Scumm,charset._colorMap[0],sleByte,16), MKARRAY(Scumm,_charsetData[0][0],sleByte,10*16), @@ -293,29 +306,28 @@ void Scumm::saveOrLoad(FILE *inout, bool mode) { MKLINE(Scumm,_numNestedScripts,sleByte), MKLINE(Scumm,_userPut,sleByte), MKLINE(Scumm,_cursorState,sleByte), - MKLINE(Scumm,gdi.unk4,sleByte), - MKLINE(Scumm,gdi.currentCursor,sleByte), + MKLINE(Scumm,gdi._unk4,sleByte), + MKLINE(Scumm,gdi._currentCursor,sleByte), - MKLINE(Scumm,doEffect,sleByte), + MKLINE(Scumm,_doEffect,sleByte), MKLINE(Scumm,_switchRoomEffect,sleByte), MKLINE(Scumm,_newEffect,sleByte), MKLINE(Scumm,_switchRoomEffect2,sleByte), MKLINE(Scumm,_BgNeedsRedraw,sleByte), MKARRAY(Scumm,actorDrawBits[0],sleUint16,200), - MKLINE(Scumm,gdi.transparency,sleByte), + MKLINE(Scumm,gdi._transparency,sleByte), MKARRAY(Scumm,_currentPalette[0],sleByte,768), /* virtscr */ MKARRAY(Scumm,charset._buffer[0],sleByte,256), - MKLINE(Scumm,dseg_3A76,sleUint16), + MKLINE(Scumm,_egoPositioned,sleByte), - MKARRAY(Scumm,_imgBufOffs[0],sleUint16,4), - MKLINE(Scumm,_numZBuffer,sleUint16), + MKARRAY(Scumm,gdi._imgBufOffs[0],sleUint16,4), + MKLINE(Scumm,gdi._numZBuffer,sleByte), - MKLINE(Scumm,dseg_4EA0,sleUint16), - MKLINE(Scumm,dseg_4EA0,sleUint16), + MKLINE(Scumm,_screenEffectFlag,sleByte), MKLINE(Scumm,_randSeed1,sleUint32), MKLINE(Scumm,_randSeed2,sleUint32), @@ -327,12 +339,6 @@ void Scumm::saveOrLoad(FILE *inout, bool mode) { MKLINE(Scumm,_screenB,sleUint16), MKLINE(Scumm,_screenH,sleUint16), - MKARRAY(Scumm,_colorCycleDelays[0],sleUint16,17), - MKARRAY(Scumm,_colorCycleCounter[0],sleUint16,17), - MKARRAY(Scumm,_colorCycleFlags[0],sleUint16,17), - MKARRAY(Scumm,_colorCycleStart[0],sleByte,17), - MKARRAY(Scumm,_colorCycleEnd[0],sleByte,17), - MKARRAY(Scumm,cost._transEffect[0],sleByte,256), MKEND() }; @@ -393,6 +399,14 @@ void Scumm::saveOrLoad(FILE *inout, bool mode) { MKEND() }; + const SaveLoadEntry colorCycleEntries[] = { + MKLINE(ColorCycle,delay,sleUint16), + MKLINE(ColorCycle,counter,sleUint16), + MKLINE(ColorCycle,flags,sleUint16), + MKLINE(ColorCycle,start,sleByte), + MKLINE(ColorCycle,end,sleByte), + }; + int i,j; _saveLoadStream = inout; @@ -401,7 +415,7 @@ void Scumm::saveOrLoad(FILE *inout, bool mode) { saveLoadEntries(this,mainEntries); for (i=1; i<13; i++) saveLoadEntries(&actor[i],actorEntries); - for (i=0; i<20; i++) + for (i=0; inumber || ss->type!=2 && ss->type!=3 || ss->status==0) continue; @@ -138,7 +141,7 @@ void Scumm::stopObjectScript(int script) { ss = &vm.slot[1]; - for (i=1; i<20; i++,ss++) { + for (i=1; inumber && (ss->type==1 || ss->type==0 || ss->type==4) && ss->status!=0) { if (ss->cutsceneOverride) error("Object %d stopped with active cutscene/override", script); @@ -169,11 +172,11 @@ int Scumm::getScriptSlot() { int i; ss = &vm.slot[1]; - for (i=1; i<20; i++,ss++) { + for (i=1; istatus==0) return i; } - error("Too many scripts running, %d max", 20); + error("Too many scripts running, %d max", NUM_SCRIPT_SLOT); } void Scumm::runScriptNested(int script) { @@ -414,12 +417,14 @@ void Scumm::setResult(int value) { void Scumm::drawBox(int x, int y, int x2, int y2, int color) { int top,bottom,count; + VirtScreen *vs; + byte *backbuff; - if (findVirtScreen(y)==-1) + if ((vs=findVirtScreen(y)) == NULL) return; - top = virtscr[gdi.virtScreen].topline; - bottom = top + virtscr[gdi.virtScreen].height; + top = vs->topline; + bottom = top + vs->height; if (x > x2) SWAP(x,x2); @@ -436,16 +441,14 @@ void Scumm::drawBox(int x, int y, int x2, int y2, int color) { if (x2>320) x2=320; if (y2 > bottom) y2=bottom; - updateDirtyRect(gdi.virtScreen, x, x2, y-top, y2-top, 0); + updateDirtyRect(vs->number, x, x2, y-top, y2-top, 0); - gdi.bg_ptr = getResourceAddress(0xA, gdi.virtScreen+1) - + virtscr[gdi.virtScreen].xstart - + (y-top)*320 + x; + backbuff = getResourceAddress(0xA, vs->number+1) + vs->xstart + (y-top)*320 + x; count = y2 - y; while (count) { - memset(gdi.bg_ptr, color, x2 - x); - gdi.bg_ptr += 320; + memset(backbuff, color, x2 - x); + backbuff += 320; count--; } } @@ -477,7 +480,7 @@ bool Scumm::isScriptLoaded(int script) { int i; ss = vm.slot; - for (i=0; i<20; i++,ss++) { + for (i=0; inumber == script) return true; } @@ -495,7 +498,7 @@ void Scumm::runHook(int i) { void Scumm::freezeScripts(int flag) { int i; - for(i=1; i<20; i++) { + for(i=1; i=0x80)) { vm.slot[i].status |= 0x80; vm.slot[i].freezeCount++; @@ -513,7 +516,7 @@ void Scumm::freezeScripts(int flag) { void Scumm::unfreezeScripts() { int i; - for (i=1; i<20; i++) { + for (i=1; itype==1 || ss->type==4) { if(ss->cutsceneOverride) error("Object %d stopped with active cutscene/override in exit", ss->number); @@ -613,7 +616,7 @@ void Scumm::checkAndRunVar33() { memset(_localParamList, 0, sizeof(_localParamList)); if (isScriptLoaded(_vars[VAR_SENTENCE_SCRIPT])) { ss = vm.slot; - for (i=0; i<20; i++,ss++) + for (i=0; inumber==_vars[VAR_SENTENCE_SCRIPT] && ss->status!=0 && ss->freezeCount==0) return; } @@ -648,7 +651,7 @@ void Scumm::runInputScript(int a, int cmd, int mode) { void Scumm::decreaseScriptDelay(int amount) { ScriptSlot *ss = &vm.slot[0]; int i; - for (i=0; i<20; i++,ss++) { + for (i=0; istatus==1) { ss->delay -= amount; if (ss->delay < 0){ @@ -712,7 +715,7 @@ int Scumm::getVerbEntrypoint(int obj, int entry) { objptr = getObjectAddress(obj); - verbptr = findResource(MKID('VERB'), objptr); + verbptr = findResource(MKID('VERB'), objptr, 0); if (verbptr==NULL) error("No verb block in object %d", obj); @@ -842,7 +845,7 @@ void Scumm::animateActor(int act, int anim) { int Scumm::getScriptRunning(int script) { int i; ScriptSlot *ss = vm.slot; - for (i=0; i<20; i++,ss++) + for (i=0; inumber==script && (ss->type==2 || ss->type==3) && ss->status) return 1; return 0; @@ -939,6 +942,16 @@ int Scumm::getArrayId() { error("Out of array pointers, %d max", _numArray); } +void Scumm::arrayop_1(int a, byte *ptr) { + ArrayHeader *ah; + int r; + int len = getStringLen(ptr); + + r = defineArray(a, 4, 0, len); + ah = (ArrayHeader*)getResourceAddress(7,r); + copyString(ah->data,ptr,len); +} + void Scumm::copyString(byte *dst, byte *src, int len) { if (!src) { while (--len>=0) diff --git a/script_v1.cpp b/script_v1.cpp index 24b055eca00..f4a80e80b40 100644 --- a/script_v1.cpp +++ b/script_v1.cpp @@ -17,6 +17,9 @@ * * Change Log: * $Log$ + * Revision 1.4 2001/10/26 17:34:50 strigeus + * bug fixes, code cleanup + * * Revision 1.3 2001/10/23 19:51:50 strigeus * recompile not needed when switching games * debugger skeleton implemented @@ -890,7 +893,7 @@ void Scumm::o5_getClosestObjActor() { getResultPos(); act = getVarOrDirectWord(0x80); - obj = _vars[VAR_OBJECT_HI]; + obj = _vars[VAR_V5_OBJECT_HI]; do { dist = getObjActToObjActDist(obj,act); @@ -898,7 +901,7 @@ void Scumm::o5_getClosestObjActor() { closnum = dist; closobj = obj; } - } while (--obj >= _vars[VAR_OBJECT_LO]); + } while (--obj >= _vars[VAR_V5_OBJECT_LO]); setResult(closnum); } @@ -1054,11 +1057,11 @@ void Scumm::o5_lights() { a = getVarOrDirectByte(0x80); b = fetchScriptByte(); c = fetchScriptByte(); + if (c==0) - _vars[VAR_DRAWFLAGS] = a; + _vars[VAR_V5_DRAWFLAGS] = a; else if (c==1) { - _lightsValueA = a; - _lightsValueB = b; + warning("o5_lights: lights not implemented"); } _fullRedraw=1; } @@ -1077,7 +1080,7 @@ void Scumm::o5_loadRoomWithEgo() { obj = getVarOrDirectWord(0x80); room = getVarOrDirectByte(0x40); - a = derefActorSafe(_vars[VAR_UNK_ACTOR], "o5_loadRoomWithEgo"); + a = derefActorSafe(_vars[VAR_EGO], "o5_loadRoomWithEgo"); /* Warning: uses _xPos, _yPos from a previous update of those */ putActor(a, _xPos, _yPos, room); @@ -1085,7 +1088,7 @@ void Scumm::o5_loadRoomWithEgo() { x = (int16)fetchScriptWord(); y = (int16)fetchScriptWord(); - dseg_3A76 = 0; + _egoPositioned = false; _vars[VAR_WALKTO_OBJ] = obj; @@ -1166,7 +1169,7 @@ void Scumm::o5_pickupObject() { if (room==0) room = _roomResource; addObjectToInventory(obj, room); - putOwner(obj, _vars[VAR_UNK_ACTOR]); + putOwner(obj, _vars[VAR_EGO]); putClass(obj, 32, 1); putState(obj, 1); removeObjectFromRoom(obj); @@ -1180,7 +1183,7 @@ void Scumm::o5_print() { } void Scumm::o5_printEgo() { - _actorToPrintStrFor = _vars[VAR_UNK_ACTOR]; + _actorToPrintStrFor = _vars[VAR_EGO]; decodeParseString(); } @@ -1367,12 +1370,12 @@ void Scumm::o5_roomOps() { a = getVarOrDirectByte(0x80); b = getVarOrDirectByte(0x40); c = getVarOrDirectByte(0x20); - unkRoomFunc2(b, c, a, a, a); + darkenPalette(b, c, a, a, a); break; case 9: /* ? */ _saveLoadFlag = getVarOrDirectByte(0x80); - _saveLoadData = getVarOrDirectByte(0x40); - _saveLoadData = 0; /* TODO: weird behaviour */ + _saveLoadSlot = getVarOrDirectByte(0x40); + _saveLoadSlot = 99; /* use this slot */ break; case 10: /* ? */ a = getVarOrDirectWord(0x80); @@ -1390,7 +1393,7 @@ void Scumm::o5_roomOps() { _opcode = fetchScriptByte(); d = getVarOrDirectByte(0x80); e = getVarOrDirectByte(0x40); - unkRoomFunc2(d, e, a, b, c); + darkenPalette(d, e, a, b, c); break; case 12: /* ? */ a = getVarOrDirectWord(0x80); @@ -1430,10 +1433,8 @@ void Scumm::o5_roomOps() { case 16: /* ? */ a = getVarOrDirectByte(0x80); b = getVarOrDirectByte(0x40); - if (b!=0) - _colorCycleDelays[a] = 0x4000 / (b*0x4C); - else - _colorCycleDelays[a] = 0; + checkRange(16, 1, a, "o5_roomOps: 16: color cycle out of range (%d)"); + _colorCycle[a-1].delay = (b!=0) ? 0x4000 / (b*0x4C) : 0; break; } } diff --git a/script_v2.cpp b/script_v2.cpp index 7e38f048315..f1327b4ab79 100644 --- a/script_v2.cpp +++ b/script_v2.cpp @@ -17,6 +17,9 @@ * * Change Log: * $Log$ + * Revision 1.4 2001/10/26 17:34:50 strigeus + * bug fixes, code cleanup + * * Revision 1.3 2001/10/24 20:12:52 strigeus * fixed some bugs related to string handling * @@ -978,7 +981,7 @@ void Scumm::o6_pickupObject() { if (room==0) room = _roomResource; addObjectToInventory(obj, room); - putOwner(obj, _vars[VAR_UNK_ACTOR]); + putOwner(obj, _vars[VAR_EGO]); putClass(obj, 32, 1); putState(obj, 1); removeObjectFromRoom(obj); @@ -995,15 +998,16 @@ void Scumm::o6_loadRoomWithEgo() { room = pop(); obj = pop(); - a = derefActorSafe(_vars[VAR_UNK_ACTOR], "o_loadRoomWithEgo"); + a = derefActorSafe(_vars[VAR_EGO], "o_loadRoomWithEgo"); putActor(a, 0, 0, room); - dseg_3A76 = 0; + _egoPositioned = false; + _vars[VAR_WALKTO_OBJ] = obj; startScene(a->room, a, obj); _vars[VAR_WALKTO_OBJ] = 0; - /* startScene maybe modifies VAR_UNK_ACTOR, i hope not */ + /* startScene maybe modifies VAR_EGO, i hope not */ camera._destPos = camera._curPos = a->x; setCameraFollows(a); _fullRedraw=1; @@ -1278,11 +1282,12 @@ void Scumm::o6_roomOps() { c = pop(); b = pop(); a = pop(); - unkRoomFunc2(b,c,a,a,a); + darkenPalette(b,c,a,a,a); break; case 180: - _saveLoadData = pop(); + _saveLoadCompatible = true; + _saveLoadSlot = pop(); _saveLoadFlag = pop(); warning("o6_roomops:180: partially unimplemented"); break; @@ -1303,7 +1308,7 @@ void Scumm::o6_roomOps() { c = pop(); b = pop(); a = pop(); - unkRoomFunc2(d, e, a, b, c); + darkenPalette(d, e, a, b, c); break; case 183: @@ -1334,10 +1339,8 @@ void Scumm::o6_roomOps() { case 187: /* color cycle delay */ b = pop(); a = pop(); - if (b!=0) - _colorCycleDelays[a] = 0x4000 / (b*0x4C); - else - _colorCycleDelays[a] = 0; + checkRange(16, 1, a, "o6_roomOps: 187: color cycle out of range (%d)"); + _colorCycle[a-1].delay = (b!=0) ? 0x4000 / (b*0x4C) : 0; break; case 213: /* set palette */ @@ -1863,7 +1866,7 @@ void Scumm::o6_printActor() { } void Scumm::o6_printEgo() { - push(_vars[VAR_UNK_ACTOR]); + push(_vars[VAR_EGO]); decodeParseString2(0,1); } @@ -1876,7 +1879,7 @@ void Scumm::o6_talkActor() { } void Scumm::o6_talkEgo() { - _actorToPrintStrFor = _vars[VAR_UNK_ACTOR]; + _actorToPrintStrFor = _vars[VAR_EGO]; _messagePtr = _scriptPointer; setStringVars(0); actorTalk(); diff --git a/scumm.h b/scumm.h index 24f4b78aa5c..88e44657655 100644 --- a/scumm.h +++ b/scumm.h @@ -17,6 +17,9 @@ * * Change Log: * $Log$ + * Revision 1.14 2001/10/26 17:34:50 strigeus + * bug fixes, code cleanup + * * Revision 1.13 2001/10/24 20:12:52 strigeus * fixed some bugs related to string handling * @@ -73,6 +76,8 @@ struct Actor; typedef void (Scumm::*OpcodeProc)(); +#define NUM_SCRIPT_SLOT 25 + #pragma START_PACK_STRUCTS struct Point { @@ -109,6 +114,7 @@ struct VerbSlot { }; struct VirtScreen { + int number; uint16 unk1; uint16 topline; uint16 width,height; @@ -258,80 +264,78 @@ enum { }; enum ScummVars { - VAR_UNK_ACTOR = 1, - VAR_WALKTO_OBJ = 38, + VAR_EGO = 1, + VAR_CAMERA_CUR_POS = 2, + VAR_HAVE_MSG = 3, + VAR_ROOM = 4, VAR_OVERRIDE = 5, VAR_NUM_ACTOR = 8, - VAR_OBJECT_LO = 15, - VAR_OBJECT_HI = 16, VAR_CURRENTDRIVE = 10, - VAR_TALK_ACTOR = 25, - VAR_DEBUGMODE = 39, - VAR_VERSION = 75, - VAR_FIXEDDISK = 51, - VAR_CURSORSTATE = 52, - VAR_USERPUT = 53, - VAR_SOUNDCARD = 48, - VAR_VIDEOMODE = 49, - VAR_HEAPSPACE = 40, - VAR_MOUSEPRESENT = 67, - VAR_SOUNDPARAM = 64, - VAR_SOUNDPARAM2 = 65, - VAR_SOUNDPARAM3 = 66, - VAR_GAME_LOADED = 71, + VAR_TMR_1 = 11, + VAR_TMR_2 = 12, + VAR_TMR_3 = 13, + VAR_CAMERA_MIN = 17, + VAR_CAMERA_MAX = 18, + VAR_TIMER_NEXT = 19, VAR_VIRT_MOUSE_X = 20, VAR_VIRT_MOUSE_Y = 21, - VAR_PERFORMANCE_1 = 68, - VAR_PERFORMANCE_2 = 69, - VAR_ROOM_FLAG = 70, - VAR_HAVE_MSG = 3, + VAR_ROOM_RESOURCE = 22, + VAR_LAST_SOUND = 23, + VAR_CUTSCENEEXIT_KEY = 24, + VAR_TALK_ACTOR = 25, + VAR_CAMERA_FAST = 26, + VAR_SCROLL_SCRIPT = 27, VAR_ENTRY_SCRIPT = 28, VAR_ENTRY_SCRIPT2 = 29, VAR_EXIT_SCRIPT = 30, VAR_EXIT_SCRIPT2 = 31, VAR_VERB_SCRIPT = 32, VAR_SENTENCE_SCRIPT = 33, - VAR_LAST_SOUND = 23, VAR_HOOK_SCRIPT = 34, VAR_CUTSCENE_START_SCRIPT = 35, VAR_CUTSCENE_END_SCRIPT = 36, - VAR_SCROLL_SCRIPT = 27, - VAR_CAMERA_MIN = 17, - VAR_CAMERA_MAX = 18, - VAR_CAMERA_FAST = 26, - VAR_CAMERA_CUR_POS = 2, - VAR_NEW_ROOM = 72, - VAR_ROOM = 4, - VAR_ROOM_RESOURCE = 22, - - VAR_MOUSE_X = 44, - VAR_MOUSE_Y = 45, - - VAR_TIMER = 46, - VAR_TIMER_NEXT = 19, - - VAR_TMR_1 = 11, - VAR_TMR_2 = 12, - VAR_TMR_3 = 13, - VAR_TMR_4 = 47, - - VAR_DRAWFLAGS = 9, - - VAR_SOUNDRESULT = 56, - - VAR_PLAYBACKTIMER = 19, - - VAR_TALK_STRING_Y = 54, - VAR_CHARFLAG = 60, VAR_CHARINC = 37, - + VAR_WALKTO_OBJ = 38, + VAR_DEBUGMODE = 39, + VAR_HEAPSPACE = 40, VAR_RESTART_KEY = 42, VAR_PAUSE_KEY = 43, - VAR_CUTSCENEEXIT_KEY = 24, - VAR_TALKSTOP_KEY = 57, + VAR_MOUSE_X = 44, + VAR_MOUSE_Y = 45, + VAR_TIMER = 46, + VAR_TMR_4 = 47, + VAR_SOUNDCARD = 48, + VAR_VIDEOMODE = 49, VAR_SAVELOADDIALOG_KEY = 50, + VAR_FIXEDDISK = 51, + VAR_CURSORSTATE = 52, + VAR_USERPUT = 53, + VAR_SOUNDRESULT = 56, + VAR_TALKSTOP_KEY = 57, + VAR_59 = 59, + + VAR_SOUNDPARAM = 64, + VAR_SOUNDPARAM2 = 65, + VAR_SOUNDPARAM3 = 66, + VAR_MOUSEPRESENT = 67, + VAR_PERFORMANCE_1 = 68, + VAR_PERFORMANCE_2 = 69, + VAR_ROOM_FLAG = 70, + VAR_GAME_LOADED = 71, + VAR_NEW_ROOM = 72, + VAR_VERSION = 75, + VAR_V5_DRAWFLAGS = 9, + VAR_V5_OBJECT_LO = 15, + VAR_V5_OBJECT_HI = 16, + VAR_V5_TALK_STRING_Y = 54, + VAR_V5_CHARFLAG = 60, + + VAR_V6_SCREEN_WIDTH = 41, + VAR_V6_SCREEN_HEIGHT = 54, + VAR_V6_EMSSPACE = 76, VAR_V6_RANDOM_NR = 118, + }; #define _maxRooms res.num[1] @@ -366,6 +370,7 @@ struct CharsetRenderer { int _right; byte _color; bool _hasMask; + bool _blitAlso; int _strLeft, _strRight, _strTop, _strBottom; // int _mask_bottom, _mask_right, _mask_top, _mask_left; @@ -386,8 +391,9 @@ struct CharsetRenderer { byte _ignoreCharsetMask; - byte *_bg_ptr, *_where_to_draw_ptr; + byte *_backbuff_ptr, *_bgbak_ptr; byte *_mask_ptr; + byte *_bg_ptr2; byte _colorMap[16]; byte _buffer[256]; @@ -405,7 +411,7 @@ struct CostumeRenderer { byte *_dataptr; byte *_frameptr; byte *_srcptr; - byte *_where_to_draw_ptr, *_bg_ptr, *_mask_ptr, *_mask_ptr_dest; + byte *_bgbak_ptr, *_backbuff_ptr, *_mask_ptr, *_mask_ptr_dest; int _actorX, _actorY; byte _zbuf; uint _scaleX, _scaleY; @@ -519,6 +525,82 @@ struct StringTab { int16 mask_top, mask_bottom, mask_right, mask_left; }; +struct ColorCycle { + uint16 delay; + uint16 counter; + uint16 flags; + byte start; + byte end; +}; + +struct Gdi { + Scumm *_vm; + + byte *_readPtr; + uint _readOffs; + + int8 _unk4; + + int _numZBuffer; + int _imgBufOffs[4]; + byte _disable_zbuffer; + + byte dseg_4E3B; + byte _numLinesToProcess; + byte _tempNumLines; + byte _currentX; + byte _hotspot_x; + byte _hotspot_y; + int16 _drawMouseX; + int16 _drawMouseY; + byte _currentCursor; + byte _mouseColors[4]; + byte _mouseColor; + byte _mouseClipMask1, _mouseClipMask2, _mouseClipMask3; + byte _mouseColorIndex; + byte *_mouseMaskPtr; + byte *_smap_ptr; + byte *_backbuff_ptr; + byte *_bgbak_ptr; + byte *_mask_ptr; + byte *_mask_ptr_dest; + byte *_z_plane_ptr; + + byte _decomp_shr, _decomp_mask; + byte _transparency; + uint16 _vertStripNextInc; + byte *_backupIsWhere; + + byte _mouseMask[0x200]; + + void unkDecode1(); + void unkDecode2(); + void unkDecode3(); + void unkDecode4(); + void unkDecode5(); + void unkDecode6(); + void unkDecode7(); + + void decompressBitmap(); + + void drawBitmap(byte *ptr, VirtScreen *vs, int x, int y, int h, int stripnr, int numstrip, bool flag); + void clearUpperMask(); + + void disableZBuffer() { _disable_zbuffer++; } + void enableZBuffer() { _disable_zbuffer--; } + + void draw8ColWithMasking(); + void clear8ColWithMasking(); + void clear8Col(); + void decompressMaskImgOr(); + void decompressMaskImg(); + + void resetBackground(byte top, byte bottom, int strip); + void drawStripToScreen(VirtScreen *vs, int x, int w, int t, int b); + void updateDirtyScreen(VirtScreen *vs); +}; + + enum GameId { GID_TENTACLE = 1, GID_MONKEY2 = 2, @@ -545,8 +627,10 @@ struct Scumm { void *_fileHandle; char *_exe_name; - int _saveLoadSlot; - + byte _saveLoadFlag; + byte _saveLoadSlot; + bool _saveLoadCompatible; + bool _dynamicRoomOffsets; byte _resFilePathId; @@ -571,6 +655,8 @@ struct Scumm { int _curPalIndex; + VirtScreen *_curVirtScreen; + int _numVariables; int _numBitVariables; int _numLocalObjects; @@ -584,47 +670,39 @@ struct Scumm { int _numSounds; int _numCharsets; int _numCostumes; + + byte *_msgPtrToAdd; uint8 *_roomFileIndexes; byte *_objectFlagTable; uint32 *_classData; byte _numGlobalScripts; - - uint16 _numZBuffer; - + byte *_scriptPointer, *_scriptOrgPointer; + byte *_scriptPointerStart; + byte _opcode; + uint32 _randSeed1; uint32 _randSeed2; uint16 _screenB, _screenH; - uint16 dseg_3A76; uint16 _defaultTalkDelay; - uint16 _lightsValueA,_lightsValueB; byte _haveMsg; byte _newEffect; uint16 _fullRedraw; - uint16 dseg_3DB6; - uint16 dseg_2456; /* lastDrawnRoom */ - uint16 dseg_4E8A; uint16 _soundParam,_soundParam2,_soundParam3; - uint16 dseg_4F8C; byte _switchRoomEffect2, _switchRoomEffect; - uint16 dseg_4AC2; - bool doEffect; - - uint16 _drawBmpX; - uint16 dseg_719E; - uint16 _drawBmpY; - uint16 dseg_4174; - byte dseg_4E3C; - uint16 _lastXstart; - uint16 dseg_4EA0; - + bool _egoPositioned; + bool _doEffect; + bool _screenEffectFlag; bool _keepText; + byte _bkColor; + uint16 _lastXstart; + int16 _talkDelay; int16 _shakeMode; @@ -639,7 +717,6 @@ struct Scumm { byte *_messagePtr; byte _numNestedScripts; - byte _unkTabIndex; byte _currentScript; byte _currentRoom; @@ -656,7 +733,7 @@ struct Scumm { uint16 _completeScreenRedraw; - byte _saveLoadFlag; + int8 _userPut; int8 _cursorState; @@ -666,7 +743,6 @@ struct Scumm { int _numInMsgStack; -// VerbSlot verbs[102]; VirtScreen virtscr[4]; uint32 _ENCD_offs, _EXCD_offs; @@ -703,56 +779,15 @@ struct Scumm { int16 cutSceneData[5]; int16 cutSceneScriptIndex; byte cutSceneStackPointer; - ScriptSlot slot[20]; + ScriptSlot slot[NUM_SCRIPT_SLOT]; NestedScript nest[15]; - int16 localvar[20*17]; + int16 localvar[NUM_SCRIPT_SLOT*17]; } vm; struct { int16 x,y; } mouse; - struct { - byte *readPtr; - uint16 readOffs; - uint16 drawY; - uint16 drawHeight; - uint16 drawWidth; - uint16 draw8xPos; - int16 virtScreen; - uint16 drawBottom; - uint16 drawTop; - - int8 unk4; - - byte numLinesToProcess; - byte tempNumLines; - byte currentX; - byte hotspot_x; - byte hotspot_y; - int16 drawMouseX; - int16 drawMouseY; - byte currentCursor; - byte mouseColors[4]; - byte mouseColor; - byte mouseClipMask1, mouseClipMask2, mouseClipMask3; - byte mouseColorIndex; - byte mouseMask[0x200]; - byte *mouseMaskPtr; - byte *smap_ptr; - byte *bg_ptr; - byte *where_to_draw_ptr; - byte *mask_ptr; - byte *mask_ptr_dest; - byte *z_plane_ptr; - - byte decomp_shr, decomp_mask; - byte transparency; - uint16 vertStripNextInc; - byte *backupIsWhere; -// byte mouseBackup[16*24]; - } gdi; - Actor actor[13]; uint16 actorDrawBits[200]; @@ -788,10 +823,6 @@ struct Scumm { uint32 _whereInResToRead; - byte *_scriptPointer, *_scriptOrgPointer; - byte *_scriptPointerStart; - byte _opcode; - int _xPos, _yPos; byte _dir; @@ -799,41 +830,13 @@ struct Scumm { int _resultVarNumber; - uint16 _imgBufOffs[4]; - byte _sentenceIndex; SentenceTab sentence[6]; - -#if 0 - byte _sentenceTab[6]; - byte _sentenceTab2[6]; - uint16 _sentenceTab3[6]; - uint16 _sentenceTab4[6]; - byte _sentenceTab5[6]; -#endif - StringTab string[6]; -#if 0 -// int _stringXPos[4], _stringYPos[4]; - uint16 _stringOverhead[6]; - uint16 _stringCenter[6]; - uint16 _stringRight[6]; - uint16 _stringColor[6]; - - int16 _stringXpos[6]; - int16 _stringYpos[6]; - uint16 _stringCharset[6]; - - int16 _stringXpos2[6]; - int16 _stringYpos2[6]; -#endif - CostumeRenderer cost; -// ObjectData objs[184]; - int16 _soundQuePos; int16 _soundQue[0x100]; @@ -851,22 +854,11 @@ struct Scumm { int _palDirtyMin, _palDirtyMax; - byte _saveLoadData; - uint16 _colorCycleDelays[17]; - uint16 _colorCycleCounter[17]; - uint16 _colorCycleFlags[17]; - byte _colorCycleStart[17]; - byte _colorCycleEnd[17]; - - byte dseg_4E3B; - - uint32 _findResSize, _findResHeaderSize; - byte *_findResPos; - - uint32 _findResSize2, _findResHeaderSize2; - byte *_findResPos2; + ColorCycle _colorCycle[16]; + Gdi gdi; + bool _BgNeedsRedraw; int16 _localParamList[16]; @@ -886,8 +878,6 @@ struct Scumm { int _boxPathVertexHeapIndex; int _boxMatrixItem; - byte *_msgPtrToAdd; - OpcodeProc getOpcode(int i) { return _opcodes[i]; } void openRoom(int room); @@ -958,8 +948,8 @@ struct Scumm { void updateDirtyScreen(int slot); void unkVirtScreen4(int a); + - void drawStripToScreen(); void restoreMouse(); void initActor(Actor *a, int mode); bool checkFixedDisk(); @@ -1327,8 +1317,10 @@ struct Scumm { void initBGBuffers(); void setDirtyColors(int min, int max); +#if 0 byte *findResource(uint32 tag, byte *searchin); byte *findResource2(uint32 tag, byte *searchin); +#endif void setScaleItem(int slot, int a, int b, int c, int d); @@ -1341,26 +1333,13 @@ struct Scumm { void redrawBGStrip(int start, int num); void drawObject(int obj, int arg); - void drawBmp(byte *ptr, int a, int b, int c, const char *str, int objnr); - void decompressBitmap(); +// void drawBmp(byte *ptr, int a, int b, int c, const char *str, int objnr); + int hasCharsetMask(int x, int y, int x2, int y2); - void draw8ColWithMasking(); - void clear8ColWithMasking(); - void clear8Col(); - void decompressMaskImgOr(); - void decompressMaskImg(); - - void GDI_UnkDecode1(); - void GDI_UnkDecode2(); - void GDI_UnkDecode3(); - void GDI_UnkDecode4(); - void GDI_UnkDecode5(); - void GDI_UnkDecode6(); - void GDI_UnkDecode7(); void restoreBG(int left, int top, int right, int bottom); void updateDirtyRect(int virt, int left, int right, int top, int bottom, uint16 dirtybits); - int findVirtScreen(int y); + VirtScreen *findVirtScreen(int y); void unkScreenEffect1(); void unkScreenEffect2(); @@ -1375,7 +1354,7 @@ struct Scumm { void decreaseScriptDelay(int amount); void processKbd(); - void clearUpperMask(); + void redrawVerbs(); void checkExecVerbs(); void checkAndRunVar33(); @@ -1447,7 +1426,7 @@ struct Scumm { void unkHeapProc2(int a, int b); void unkResProc(int a, int b); void setPalColor(int index, int r, int g, int b); - void unkRoomFunc2(int a, int b, int c, int d, int e); + void darkenPalette(int a, int b, int c, int d, int e); void unkRoomFunc3(int a, int b, int c, int d, int e); void unkRoomFunc4(int a, int b, int c, int d, int e); int getVerbSlot(int id, int mode); @@ -1484,9 +1463,6 @@ struct Scumm { void drawMouse(); - void GDI_drawMouse(); - void GDI_removeMouse(); - void dumpResource(char *tag, int index, byte *ptr); FILE *_saveLoadStream; @@ -1509,7 +1485,6 @@ struct Scumm { uint16 loadWord(); uint32 loadUint32(); - Actor *derefActor(int id) { return &actor[id]; } Actor *derefActorSafe(int id, const char *errmsg); Actor *getFirstActor() { return actor; } @@ -1588,6 +1563,10 @@ struct Scumm { void startManiac(); void readIndexFileV5(int i); + + void grabCursor(byte *ptr, int width, int height); + + byte *getPalettePtr(); }; struct ScummDebugger { @@ -1607,6 +1586,9 @@ struct ScummDebugger { int get_command(); void attach(Scumm *s); void detach(); + + void printActors(int act); + void printScripts(); }; @@ -1624,3 +1606,5 @@ void initGraphics(Scumm *s); void updateScreen(Scumm *s); void drawMouse(Scumm *s, int x, int y, int color, byte *mask, bool visible); +void blit(byte *dst, byte *src, int w, int h); +byte *findResource(uint32 id, byte *searchin, int index); \ No newline at end of file diff --git a/scummvm.cpp b/scummvm.cpp index 7fceb6733dc..34f31b2ce8f 100644 --- a/scummvm.cpp +++ b/scummvm.cpp @@ -17,6 +17,9 @@ * * Change Log: * $Log$ + * Revision 1.13 2001/10/26 17:34:50 strigeus + * bug fixes, code cleanup + * * Revision 1.12 2001/10/24 20:12:52 strigeus * fixed some bugs related to string handling * @@ -160,11 +163,9 @@ void Scumm::scummInit() { virtscr[0].xstart = 0; - _vars[9] = 11; + _vars[VAR_V5_DRAWFLAGS] = 11; - _lightsValueA = _lightsValueB = 7; - - _vars[59] = 3; + _vars[VAR_59] = 3; mouse.x = 104; mouse.y = 56; @@ -172,8 +173,8 @@ void Scumm::scummInit() { _ENCD_offs = 0; _EXCD_offs = 0; - _unkTabIndex = 0xFF; _currentScript = 0xFF; + _sentenceIndex = 0xFF; _currentRoom = 0; _numObjectsInRoom = 0; @@ -184,7 +185,7 @@ void Scumm::scummInit() { _screenStartStrip = 0; - _vars[25] = 0; + _vars[VAR_TALK_ACTOR] = 0; _talkDelay = 0; _keepText = false; @@ -212,7 +213,8 @@ void Scumm::scummInit() { initScummVars(); - _vars[54] = -0x50; + if (_majorScummVersion==5) + _vars[VAR_V5_TALK_STRING_Y] = -0x50; getGraphicsPerformance(); } @@ -228,6 +230,8 @@ void Scumm::initScummVars() { _vars[VAR_SOUNDPARAM] = _soundParam; _vars[VAR_SOUNDPARAM2] = _soundParam2; _vars[VAR_SOUNDPARAM3] = _soundParam3; + if (_majorScummVersion==6) + _vars[VAR_V6_EMSSPACE] = 10000; } void Scumm::checkRange(int max, int min, int no, const char *str) { @@ -242,6 +246,7 @@ void Scumm::scummMain(int argc, char **argv) { charset._vm = this; cost._vm = this; + gdi._vm = this; _fileHandle = NULL; @@ -278,8 +283,8 @@ void Scumm::scummMain(int argc, char **argv) { do { if (_playBackFile) { - while ((_scummTimer>>2) < _vars[VAR_PLAYBACKTIMER]) {} - _scummTimer = _vars[VAR_PLAYBACKTIMER] << 2; + while ((_scummTimer>>2) < _vars[VAR_TIMER_NEXT]) {} + _scummTimer = _vars[VAR_TIMER_NEXT] << 2; } CHECK_HEAP @@ -323,18 +328,24 @@ void Scumm::scummMain(int argc, char **argv) { if (_saveLoadFlag) { char buf[256]; + sprintf(buf, "savegame.%d", _saveLoadSlot); if (_saveLoadFlag==1) { saveState(buf); + if (_saveLoadCompatible) + _vars[VAR_GAME_LOADED] = 201; } else { loadState(buf); + if (_saveLoadCompatible) { + _vars[VAR_GAME_LOADED] = 203; + } } _saveLoadFlag = 0; } if (_completeScreenRedraw) { _completeScreenRedraw = 0; - clearUpperMask(); + gdi.clearUpperMask(); charset._hasMask = false; redrawVerbs(); _fullRedraw = 1; @@ -347,7 +358,7 @@ void Scumm::scummMain(int argc, char **argv) { checkAndRunVar33(); if (_currentRoom==0) { - gdi.unk4 = 0; + gdi._unk4 = 0; CHARSET_1(); unkVirtScreen2(); unkSoundProc22(); @@ -366,7 +377,7 @@ void Scumm::scummMain(int argc, char **argv) { setActorRedrawFlags(); resetActorBgs(); - if (!(_vars[VAR_DRAWFLAGS]&2) && _vars[VAR_DRAWFLAGS]&4) { + if (!(_vars[VAR_V5_DRAWFLAGS]&2) && _vars[VAR_V5_DRAWFLAGS]&4) { error("Flashlight not implemented in this version"); } @@ -375,8 +386,8 @@ void Scumm::scummMain(int argc, char **argv) { cyclePalette(); palManipulate(); - if (doEffect) { - doEffect = false; + if (_doEffect) { + _doEffect = false; screenEffect(_newEffect); clearClickedStatus(); } @@ -385,7 +396,7 @@ void Scumm::scummMain(int argc, char **argv) { verbMouseOver(checkMouseOver(mouse.x, mouse.y)); } - gdi.unk4 = _cursorState > 0; + gdi._unk4 = _cursorState > 0; unkVirtScreen2(); @@ -548,7 +559,12 @@ void Scumm::startScene(int room, Actor *a, int objectNr) { camera._mode = 1; camera._curPos = camera._destPos = 160; - + + if (_majorScummVersion==6) { + _vars[VAR_V6_SCREEN_WIDTH] = _scrWidthIn8Unit<<3; + _vars[VAR_V6_SCREEN_HEIGHT] = _scrHeight; + } + if (_roomResource == 0) return; @@ -568,17 +584,16 @@ void Scumm::startScene(int room, Actor *a, int objectNr) { } showActors(); - dseg_3A76 = 0; + + _egoPositioned = false; runEntryScript(); - - - if (a && dseg_3A76==0) { + if (a && !_egoPositioned) { getObjectXYPos(objectNr); putActor(a, _xPos, _yPos, _currentRoom); a->moving = 0; } - doEffect = true; + _doEffect = true; CHECK_HEAP } @@ -601,14 +616,14 @@ void Scumm::initRoomSubBlocks() { roomptr = getResourceAddress(1, _roomResource); - ptr = findResource(MKID('RMHD'), roomptr); + ptr = findResource(MKID('RMHD'), roomptr, 0); _scrWidthIn8Unit = READ_LE_UINT16(&((RoomHeader*)ptr)->width) >> 3; _scrHeight = READ_LE_UINT16(&((RoomHeader*)ptr)->height); - _IM00_offs = findResource(MKID('IM00'), findResource(MKID('RMIM'), roomptr)) - + _IM00_offs = findResource(MKID('IM00'), findResource(MKID('RMIM'), roomptr, 0), 0) - roomptr; - ptr = findResource(MKID('EXCD'), roomptr); + ptr = findResource(MKID('EXCD'), roomptr, 0); if (ptr) { _EXCD_offs = ptr - roomptr; #ifdef DUMP_SCRIPTS @@ -616,7 +631,7 @@ void Scumm::initRoomSubBlocks() { #endif } - ptr = findResource(MKID('ENCD'), roomptr); + ptr = findResource(MKID('ENCD'), roomptr, 0); if (ptr) { _ENCD_offs = ptr - roomptr; #ifdef DUMP_SCRIPTS @@ -624,25 +639,25 @@ void Scumm::initRoomSubBlocks() { #endif } - ptr = findResource(MKID('BOXD'), roomptr); + ptr = findResource(MKID('BOXD'), roomptr, 0); if (ptr) { int size = READ_BE_UINT32_UNALIGNED(ptr+4); createResource(14, 2, size); roomptr = getResourceAddress(1, _roomResource); - ptr = findResource(MKID('BOXD'), roomptr); + ptr = findResource(MKID('BOXD'), roomptr, 0); memcpy(getResourceAddress(0xE, 2), ptr, size); } - ptr = findResource(MKID('BOXM'), roomptr); + ptr = findResource(MKID('BOXM'), roomptr, 0); if (ptr) { int size = READ_BE_UINT32_UNALIGNED(ptr+4); createResource(14, 1, size); roomptr = getResourceAddress(1, _roomResource); - ptr = findResource(MKID('BOXM'), roomptr); + ptr = findResource(MKID('BOXM'), roomptr, 0); memcpy(getResourceAddress(0xE, 1), ptr, size); } - ptr = findResource(MKID('SCAL'), roomptr); + ptr = findResource(MKID('SCAL'), roomptr, 0); if (ptr) { offs = ptr - roomptr; for (i=1; i<_maxScaleTable; i++, offs+=8) { @@ -659,10 +674,8 @@ void Scumm::initRoomSubBlocks() { memset(_localScriptList, 0, (0x100 - _numGlobalScripts) * 4); roomptr = getResourceAddress(1, _roomResource); - ptr = findResource(MKID('LSCR'), roomptr); - while (ptr) { + for (i=0; ptr = findResource(MKID('LSCR'), roomptr, i++) ;) { _localScriptList[ptr[8] - _numGlobalScripts] = ptr - roomptr; - #ifdef DUMP_SCRIPTS do { char buf[32]; @@ -670,35 +683,34 @@ void Scumm::initRoomSubBlocks() { dumpResource(buf, ptr[8], ptr); } while (0); #endif - - ptr = findResource(MKID('LSCR'), NULL); } + - ptr = findResource(MKID('EPAL'), roomptr); + ptr = findResource(MKID('EPAL'), roomptr, 0); if (ptr) _EPAL_offs = ptr - roomptr; - ptr = findResource(MKID('CLUT'), roomptr); + ptr = findResource(MKID('CLUT'), roomptr, 0); if (ptr) { _CLUT_offs = ptr - roomptr; setPaletteFromRes(); } if (_majorScummVersion==6) { - ptr = findResource(MKID('PALS'), roomptr); + ptr = findResource(MKID('PALS'), roomptr, 0); if (ptr) { _PALS_offs = ptr - roomptr; setPalette(0); } } - initCycl(findResource(MKID('CYCL'), roomptr) + 8); + initCycl(findResource(MKID('CYCL'), roomptr, 0) + 8); - ptr = findResource(MKID('TRNS'), roomptr); + ptr = findResource(MKID('TRNS'), roomptr, 0); if (ptr) - gdi.transparency = ptr[8]; + gdi._transparency = ptr[8]; else - gdi.transparency = 255; + gdi._transparency = 255; initBGBuffers(); } @@ -764,64 +776,12 @@ void Scumm::unkRoomFunc3(int a, int b, int c, int d, int e) { warning("stub unkRoomFunc3(%d,%d,%d,%d,%d)",a,b,c,d,e); } -void Scumm::unkRoomFunc2(int a, int b, int c, int d, int e) { - byte *cptr, *cur; - int num; - byte color; - - if (_videoMode==0xE) { - warning("stub unkRoomFunc2(%d,%d,%d,%d,%d)",a,b,c,d,e); - } - - if (_videoMode==0x13) { - cptr = getResourceAddress(1, _roomResource); - if (_CLUT_offs) { - cptr += _CLUT_offs; - } else { - cptr = findPalInPals(cptr + _PALS_offs, _curPalIndex); - } - cptr += 8 + a*3; - cur = _currentPalette + a*3; - if (a <= b) { - num = b - a + 1; - - do { - if (c != 0xFF) { - color = *cptr++ * (c>>2) / 0xFF; - } else { - color = *cptr++ >> 2; - } - if(color>63) color = 63; - *cur++=color; - - if (d != 0xFF) { - color = *cptr++ * (d>>2) / 0xFF; - } else { - color = *cptr++ >> 2; - } - if(color>63) color = 63; - *cur++=color; - - if (e != 0xFF) { - color = *cptr++ * (e>>2) / 0xFF; - } else { - color = *cptr++ >> 2; - } - if(color>63) color = 63; - *cur++=color; - } while (--num); - } - setDirtyColors(a,b); - } -} - void Scumm::unkRoomFunc4(int a, int b, int c, int d, int e) { /* TODO: implement this */ warning("unkRoomFunc4: not implemented"); } - void Scumm::pauseGame(int i) { /* TODO: implement this */ warning("pauseGame: not implemented"); @@ -924,7 +884,7 @@ Actor *Scumm::derefActorSafe(int id, const char *errmsg) { } void Scumm::new_unk_1(int a) { - error("stub new_unk_1(%d)", a); + warning("stub new_unk_1(%d)", a); } void Scumm::setCursorHotspot2(int x,int y) { @@ -932,29 +892,15 @@ void Scumm::setCursorHotspot2(int x,int y) { } void Scumm::setStringVars(int slot) { - string[slot].xpos = string[slot].t_xpos; - string[slot].ypos = string[slot].t_ypos; - string[slot].center = string[slot].t_center; - string[slot].overhead = string[slot].t_overhead; - string[slot].new_3 = string[slot].t_new3; - string[slot].right = string[slot].t_right; - string[slot].color = string[slot].t_color; - string[slot].charset = string[slot].t_charset; -} - -void Scumm::arrayop_1(int a, byte *ptr) { - ArrayHeader *ah; - int r; - int len = getStringLen(ptr); - - r = defineArray(a, 4, 0, len); - ah = (ArrayHeader*)getResourceAddress(7,r); - copyString(ah->data,ptr,len); -} - - -void Scumm::unkMiscOp4(int a, int b, int c, int d) { - warning("stub unkMiscOp4(%d,%d,%d,%d)", a,b,c,d); + StringTab *st = &string[slot]; + st->xpos = st->t_xpos; + st->ypos = st->t_ypos; + st->center = st->t_center; + st->overhead = st->t_overhead; + st->new_3 = st->t_new3; + st->right = st->t_right; + st->color = st->t_color; + st->charset = st->t_charset; } void Scumm::unkMiscOp9() { diff --git a/scummvm.dsp b/scummvm.dsp index 645324c4679..505c01fbf2d 100644 --- a/scummvm.dsp +++ b/scummvm.dsp @@ -42,7 +42,7 @@ RSC=rc.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /c -# ADD CPP /nologo /Zp4 /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /c +# ADD CPP /nologo /Zp4 /MD /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /c # ADD BASE RSC /l 0x41d /d "NDEBUG" # ADD RSC /l 0x41d /d "NDEBUG" BSC32=bscmake.exe @@ -66,7 +66,7 @@ LINK32=link.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /GZ /c -# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "CHECK_HEAP" /Yu"stdafx.h" /FD /GZ /c +# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "DUMP_SCRIPTS" /Yu"stdafx.h" /FD /GZ /c # SUBTRACT CPP /Fr # ADD BASE RSC /l 0x41d /d "_DEBUG" # ADD RSC /l 0x41d /d "_DEBUG" @@ -89,71 +89,225 @@ LINK32=link.exe # Begin Source File SOURCE=.\actor.cpp + +!IF "$(CFG)" == "scummvm - Win32 Release" + +# ADD CPP /Gd + +!ELSEIF "$(CFG)" == "scummvm - Win32 Debug" + +!ENDIF + # End Source File # Begin Source File SOURCE=.\boxes.cpp + +!IF "$(CFG)" == "scummvm - Win32 Release" + +# ADD CPP /Gd + +!ELSEIF "$(CFG)" == "scummvm - Win32 Debug" + +!ENDIF + # End Source File # Begin Source File SOURCE=.\costume.cpp + +!IF "$(CFG)" == "scummvm - Win32 Release" + +# ADD CPP /Gd + +!ELSEIF "$(CFG)" == "scummvm - Win32 Debug" + +!ENDIF + # End Source File # Begin Source File SOURCE=.\debug.cpp + +!IF "$(CFG)" == "scummvm - Win32 Release" + +# ADD CPP /Gd + +!ELSEIF "$(CFG)" == "scummvm - Win32 Debug" + +!ENDIF + # End Source File # Begin Source File SOURCE=.\gfx.cpp + +!IF "$(CFG)" == "scummvm - Win32 Release" + +# ADD CPP /Gd + +!ELSEIF "$(CFG)" == "scummvm - Win32 Debug" + +!ENDIF + # End Source File # Begin Source File SOURCE=.\object.cpp + +!IF "$(CFG)" == "scummvm - Win32 Release" + +# ADD CPP /Gd + +!ELSEIF "$(CFG)" == "scummvm - Win32 Debug" + +!ENDIF + # End Source File # Begin Source File SOURCE=.\resource.cpp + +!IF "$(CFG)" == "scummvm - Win32 Release" + +# ADD CPP /Gd + +!ELSEIF "$(CFG)" == "scummvm - Win32 Debug" + +!ENDIF + # End Source File # Begin Source File SOURCE=.\saveload.cpp + +!IF "$(CFG)" == "scummvm - Win32 Release" + +# ADD CPP /Gd + +!ELSEIF "$(CFG)" == "scummvm - Win32 Debug" + +!ENDIF + # End Source File # Begin Source File SOURCE=.\script.cpp + +!IF "$(CFG)" == "scummvm - Win32 Release" + +# ADD CPP /Gd + +!ELSEIF "$(CFG)" == "scummvm - Win32 Debug" + +!ENDIF + # End Source File # Begin Source File SOURCE=.\script_v1.cpp + +!IF "$(CFG)" == "scummvm - Win32 Release" + +# ADD CPP /Gd + +!ELSEIF "$(CFG)" == "scummvm - Win32 Debug" + +!ENDIF + # End Source File # Begin Source File SOURCE=.\script_v2.cpp + +!IF "$(CFG)" == "scummvm - Win32 Release" + +# ADD CPP /Gd + +!ELSEIF "$(CFG)" == "scummvm - Win32 Debug" + +!ENDIF + # End Source File # Begin Source File SOURCE=.\scummvm.cpp + +!IF "$(CFG)" == "scummvm - Win32 Release" + +# ADD CPP /Gd + +!ELSEIF "$(CFG)" == "scummvm - Win32 Debug" + +!ENDIF + # End Source File # Begin Source File SOURCE=.\sound.cpp + +!IF "$(CFG)" == "scummvm - Win32 Release" + +# ADD CPP /Gd + +!ELSEIF "$(CFG)" == "scummvm - Win32 Debug" + +!ENDIF + # End Source File # Begin Source File SOURCE=.\StdAfx.cpp + +!IF "$(CFG)" == "scummvm - Win32 Release" + +# ADD CPP /Gd /Yc"stdafx.h" + +!ELSEIF "$(CFG)" == "scummvm - Win32 Debug" + # ADD CPP /Yc"stdafx.h" + +!ENDIF + # End Source File # Begin Source File SOURCE=.\string.cpp + +!IF "$(CFG)" == "scummvm - Win32 Release" + +# ADD CPP /Gd + +!ELSEIF "$(CFG)" == "scummvm - Win32 Debug" + +!ENDIF + # End Source File # Begin Source File SOURCE=.\sys.cpp + +!IF "$(CFG)" == "scummvm - Win32 Release" + +# ADD CPP /Gd + +!ELSEIF "$(CFG)" == "scummvm - Win32 Debug" + +!ENDIF + # End Source File # Begin Source File SOURCE=.\verbs.cpp + +!IF "$(CFG)" == "scummvm - Win32 Release" + +# ADD CPP /Gd + +!ELSEIF "$(CFG)" == "scummvm - Win32 Debug" + +!ENDIF + # End Source File # Begin Source File diff --git a/sdl.cpp b/sdl.cpp index 6e07776f205..183f7797b16 100644 --- a/sdl.cpp +++ b/sdl.cpp @@ -17,6 +17,9 @@ * * Change Log: * $Log$ + * Revision 1.12 2001/10/26 17:34:50 strigeus + * bug fixes, code cleanup + * * Revision 1.11 2001/10/23 19:51:50 strigeus * recompile not needed when switching games * debugger skeleton implemented @@ -102,6 +105,7 @@ void waitForTimer(Scumm *s) { s->_saveLoadFlag = 1; else if (event.key.keysym.mod&KMOD_CTRL) s->_saveLoadFlag = 2; + s->_saveLoadCompatible = false; } if (event.key.keysym.sym=='z' && event.key.keysym.mod&KMOD_CTRL) { exit(1); @@ -328,7 +332,7 @@ void initGraphics(Scumm *s) { } /* Clean up on exit */ - atexit(SDL_Quit); + atexit(SDL_Quit); char buf[512], *gameName; diff --git a/string.cpp b/string.cpp index ab0a00ac47b..556b6aa2493 100644 --- a/string.cpp +++ b/string.cpp @@ -17,6 +17,9 @@ * * Change Log: * $Log$ + * Revision 1.5 2001/10/26 17:34:50 strigeus + * bug fixes, code cleanup + * * Revision 1.4 2001/10/24 20:12:52 strigeus * fixed some bugs related to string handling * @@ -160,6 +163,8 @@ void Scumm::unkMessage1() { byte buf[100]; _msgPtrToAdd = buf; _messagePtr = addMessageToStack(_messagePtr); + +// warning("unkMessage1(\"%s\")", buf); } void Scumm::unkMessage2() { @@ -171,7 +176,7 @@ void Scumm::unkMessage2() { if (string[3].color==0) string[3].color = 4; - error("unkMessage2: call to printScummMessage(%s)", buf); + warning("unkMessage2(\"%s\")", buf); _messagePtr = tmp; } @@ -193,11 +198,11 @@ void Scumm::CHARSET_1() { if (_majorScummVersion==5) { string[0].xpos = a->x - camera._curPos + 160; - if (_vars[VAR_TALK_STRING_Y] < 0) { - s = (a->scaley * (int)_vars[VAR_TALK_STRING_Y]) / 0xFF; - string[0].ypos = ((_vars[VAR_TALK_STRING_Y]-s)>>1) + s - a->elevation + a->y; + if (_vars[VAR_V5_TALK_STRING_Y] < 0) { + s = (a->scaley * (int)_vars[VAR_V5_TALK_STRING_Y]) / 0xFF; + string[0].ypos = ((_vars[VAR_V5_TALK_STRING_Y]-s)>>1) + s - a->elevation + a->y; } else { - string[0].ypos = _vars[VAR_TALK_STRING_Y]; + string[0].ypos = _vars[VAR_V5_TALK_STRING_Y]; } if (string[0].ypos < 1) string[0].ypos = 1; @@ -232,7 +237,7 @@ void Scumm::CHARSET_1() { charset._center = string[0].center; charset._right = string[0].right; charset._color = _charsetColor; - dseg_4E3C = 0; + _bkColor = 0; for (i=0; i<4; i++) charset._colorMap[i] = _charsetData[charset._curId][i]; @@ -303,9 +308,14 @@ newLine:; charset._left = string[0].xpos2; charset._top = string[0].ypos2; - if (!_vars[VAR_CHARFLAG]) { + if (_majorScummVersion==5) { + if (!_vars[VAR_V5_CHARFLAG]) { + charset.printChar(c); + } + } else { charset.printChar(c); } + string[0].xpos2 = charset._left; string[0].ypos2 = charset._top; @@ -366,6 +376,7 @@ void Scumm::drawString(int a) { byte *charsetptr,*space; int i; byte byte1, chr; + uint color; _msgPtrToAdd = buf; _messagePtr = addMessageToStack(_messagePtr); @@ -376,7 +387,7 @@ void Scumm::drawString(int a) { charset._center = string[a].center; charset._right = string[a].right; charset._color = string[a].color; - dseg_4E3C = 0; + _bkColor = 0; charset._unk12 = 1; charset._disableOffsX = 1; @@ -420,6 +431,7 @@ void Scumm::drawString(int a) { chr = buf[i++]; switch(chr) { case 9: + case 10: case 13: case 14: i += 2; break; case 1: case 8: @@ -428,10 +440,22 @@ void Scumm::drawString(int a) { } else { charset._left = charset._left2; } - charset._top += byte1; + charset._top += byte1; + break; + case 12: + color = buf[i] + (buf[i+1]<<8); + i+=2; + if (color==0xFF) + charset._color = string[a].color; + else + charset._color = color; + break; } } else { + if (a==1 && _majorScummVersion==6) + charset._blitAlso = true; charset.printChar(chr); + charset._blitAlso = false; } } @@ -603,11 +627,9 @@ void CharsetRenderer::printChar(int chr) { VirtScreen *vs; _vm->checkRange(_vm->_maxCharsets-1, 1, _curId, "Printing with bad charset %d"); - if (_vm->findVirtScreen(_top)==-1) + if ((vs=_vm->findVirtScreen(_top)) == NULL) return; - vs = &_vm->virtscr[_vm->gdi.virtScreen]; - if (chr=='@') return; @@ -678,20 +700,34 @@ void CharsetRenderer::printChar(int chr) { _strTop = _top; _drawTop = _top - vs->topline; + if (_drawTop<0) _drawTop = 0; _bottom = _drawTop + _height + _offsY; - _vm->updateDirtyRect(_vm->gdi.virtScreen, _left, right, _drawTop, _bottom, 0); + _vm->updateDirtyRect(vs->number, _left, right, _drawTop, _bottom, 0); - if (_vm->gdi.virtScreen==0) +#if defined(OLD) + if (vs->number==0) _hasMask = true; +#else + if (vs->number!=0) + _blitAlso = false; + if (vs->number==0 && _blitAlso==0) + _hasMask = true; +#endif - _bg_ptr = _vm->getResourceAddress(0xA, _vm->gdi.virtScreen+1) - + vs->xstart + _drawTop * 320 + _left; - - _where_to_draw_ptr = _vm->getResourceAddress(0xA, _vm->gdi.virtScreen+5) + _bg_ptr2 = _backbuff_ptr = _vm->getResourceAddress(0xA, vs->number+1) + vs->xstart + _drawTop * 320 + _left; +#if !defined(OLD) + if (_blitAlso) { +#else + if (1) { +#endif + _bg_ptr2 = _bgbak_ptr = _vm->getResourceAddress(0xA, vs->number+5) + + vs->xstart + _drawTop * 320 + _left; + } + _mask_ptr = _vm->getResourceAddress(0xA, 9) + _drawTop * 40 + _left/8 + _vm->_screenStartStrip; @@ -702,7 +738,12 @@ void CharsetRenderer::printChar(int chr) { _charPtr += 4; drawBits(); - + +#if !defined(OLD) + if (_blitAlso) + blit(_backbuff_ptr, _bgbak_ptr, _width, _height); +#endif + _left += _width; if (_left > _strRight) _strRight = _left; @@ -722,12 +763,12 @@ void CharsetRenderer::drawBits() { int color; byte numbits,bits; - usemask = (_vm->gdi.virtScreen==0 && _ignoreCharsetMask==0); + usemask = (_vm->_curVirtScreen->number==0 && _ignoreCharsetMask==0); bits = *_charPtr++; numbits = 8; - dst = _bg_ptr; + dst = _bg_ptr2; mask = _mask_ptr; y = 0; @@ -754,7 +795,7 @@ void CharsetRenderer::drawBits() { maskpos++; } } - dst = (_bg_ptr += 320); + dst = (_bg_ptr2 += 320); mask += 40; y++; } diff --git a/verbs.cpp b/verbs.cpp index 50087eec894..1b7df4cc227 100644 --- a/verbs.cpp +++ b/verbs.cpp @@ -17,6 +17,9 @@ * * Change Log: * $Log$ + * Revision 1.4 2001/10/26 17:34:50 strigeus + * bug fixes, code cleanup + * * Revision 1.3 2001/10/16 10:01:48 strigeus * preliminary DOTT support * @@ -164,7 +167,7 @@ void Scumm::restoreVerbBG(int verb) { vs = &_verbs[verb]; if (vs->oldleft != -1) { - dseg_4E3C = vs->bkcolor; + _bkColor = vs->bkcolor; restoreBG(vs->oldleft, vs->oldtop, vs->oldright, vs->oldbottom); vs->oldleft = -1; } @@ -177,17 +180,16 @@ void Scumm::drawVerbBitmap(int vrb, int x, int y) { byte twobufs, *imptr; int ydiff, xstrip; int imgw, imgh; - int i; + int i,tmp; byte *IMHD_ptr; + byte *obim; - if (findVirtScreen(y) == -1) + if ((vs=findVirtScreen(y)) == NULL) return; _lastXstart = virtscr[0].xstart; - nozbufs = _numZBuffer; - _numZBuffer = 0; - - vs = &virtscr[gdi.virtScreen]; + + gdi.disableZBuffer(); twobufs = vs->alloctwobuffers; vs->alloctwobuffers = 0; @@ -195,22 +197,21 @@ void Scumm::drawVerbBitmap(int vrb, int x, int y) { xstrip = x>>3; ydiff = y - vs->topline; - IMHD_ptr = findResource2(MKID('IMHD'), getResourceAddress(8, vrb)); + + obim = getResourceAddress(8, vrb); + IMHD_ptr = findResource(MKID('IMHD'), obim, 0); imgw = READ_LE_UINT16(IMHD_ptr+0x14) >> 3; imgh = READ_LE_UINT16(IMHD_ptr+0x16) >> 3; - imptr = findResource2(MKID('IM01'), NULL); + imptr = findResource(MKID('IM01'), obim, 0); if (!imptr) error("No image for verb %d", vrb); for (i=0; ioldright = vst->right; vst->oldtop = vst->y; vst->oldbottom = vst->bottom; - _numZBuffer = nozbufs; + + gdi.enableZBuffer(); vs->alloctwobuffers = twobufs; } @@ -258,7 +260,7 @@ void Scumm::setVerbObject(int room, int object, int verb) { int numobj, i; byte *obimptr; uint32 imoffs,size; - byte *roomptr,*tmp_roomptr; + byte *roomptr; ImageHeader *imhd; RoomHeader *roomhdr; @@ -267,7 +269,7 @@ void Scumm::setVerbObject(int room, int object, int verb) { ensureResourceLoaded(1,room); roomptr = getResourceAddress(1, room); - roomhdr = (RoomHeader*)findResource(MKID('RMHD'), roomptr); + roomhdr = (RoomHeader*)findResource(MKID('RMHD'), roomptr, 0); numobj = READ_LE_UINT16(&roomhdr->numObjects); if (numobj==0) @@ -275,12 +277,11 @@ void Scumm::setVerbObject(int room, int object, int verb) { if (numobj > 200) error("More (%d) than %d objects in room %d", numobj, 200, room); - tmp_roomptr = roomptr; - for (i=1; i<=numobj; i++) { - obimptr = findResource(MKID('OBIM'), tmp_roomptr); + for (i=0; iobj_id) == object) { imoffs = obimptr - roomptr; size = READ_BE_UINT32_UNALIGNED(obimptr+4); @@ -289,7 +290,6 @@ void Scumm::setVerbObject(int room, int object, int verb) { memcpy(getResourceAddress(8, verb), obimptr, size); return; } - tmp_roomptr = NULL; } error("Image %d not found in room %d", object, room); } diff --git a/windows.cpp b/windows.cpp index 30906658877..dcb0f6d947d 100644 --- a/windows.cpp +++ b/windows.cpp @@ -17,6 +17,9 @@ * * Change Log: * $Log$ + * Revision 1.8 2001/10/26 17:34:50 strigeus + * bug fixes, code cleanup + * * Revision 1.7 2001/10/23 19:51:50 strigeus * recompile not needed when switching games * debugger skeleton implemented @@ -133,6 +136,7 @@ void Error(const char *msg) { int sel; Scumm scumm; +ScummDebugger debugger; WndMan wm[1]; byte veryFastMode; @@ -148,6 +152,7 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM l case WM_CLOSE: PostQuitMessage(0); break; + case WM_CHAR: wm->_scumm->_keyPressed = wParam; break; @@ -159,6 +164,7 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM l wm->_scumm->_saveLoadFlag = 1; else if (GetAsyncKeyState(VK_CONTROL)<0) wm->_scumm->_saveLoadFlag = 2; + wm->_scumm->_saveLoadCompatible = false; } if (wParam=='F') { @@ -169,6 +175,10 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM l veryFastMode ^= 1; } + if (wParam=='D') { + debugger.attach(wm->_scumm); + } + break; case WM_MOUSEMOVE: