aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Brown2002-04-11 17:19:16 +0000
committerJames Brown2002-04-11 17:19:16 +0000
commit7696081c54a6cac8152a227bd9d0bcc41999f261 (patch)
tree70859cf2d6be5ad77d7e7c41ed01c20837a0b2d0
parent34747b792a42e8129af60371541e9b7321d4d55f (diff)
downloadscummvm-rg350-7696081c54a6cac8152a227bd9d0bcc41999f261.tar.gz
scummvm-rg350-7696081c54a6cac8152a227bd9d0bcc41999f261.tar.bz2
scummvm-rg350-7696081c54a6cac8152a227bd9d0bcc41999f261.zip
Large pointless reindentation of all the code. Also fixed a few mistakes
in the object flags code cleanup. Flags used: indent *.cpp -br -bap -nbc -lp -ce -cdw -brs -nbad -nbc -npsl -nip -ts2 -ncs -nbs -npcs -nbap -Tbyte -Tuint32 -Tuint8 -Tuint16 -TArrayHeader -TMemBlkHeader -TVerbSlot -TObjectData -Tvoid -TImageHeader -TRoomHeader -TCodeHeader -TResHdr -TBompHeader -TMidiChannelAdl -TGui -TScumm -TSoundEngine -TPart -TPlayer svn-id: r3908
-rw-r--r--actor.cpp739
-rw-r--r--akos.cpp734
-rw-r--r--boxes.cpp808
-rw-r--r--costume.cpp565
-rw-r--r--debug.cpp197
-rw-r--r--debugrl.cpp119
-rw-r--r--gameDetector.cpp445
-rw-r--r--gfx.cpp1979
-rw-r--r--gui.cpp733
-rw-r--r--init.cpp5
-rw-r--r--insane.cpp597
-rwxr-xr-xmp3_cd.cpp284
-rw-r--r--object.cpp1009
-rw-r--r--readme.txt13
-rw-r--r--resource.cpp891
-rw-r--r--saveload.cpp952
-rw-r--r--script.cpp557
-rw-r--r--script_v1.cpp2598
-rw-r--r--script_v2.cpp2591
-rw-r--r--scummvm.cpp625
-rw-r--r--sdl.cpp2508
-rw-r--r--sound.cpp912
-rw-r--r--sound/adlib.cpp706
-rw-r--r--sound/fmopl.cpp913
-rw-r--r--sound/gmidi.cpp509
-rw-r--r--sound/imuse.cpp1272
-rw-r--r--string.cpp618
-rw-r--r--sys.cpp130
-rw-r--r--v3/resource_v3.cpp221
-rw-r--r--v4/resource_v4.cpp10
-rw-r--r--vars.cpp30
-rw-r--r--verbs.cpp165
-rw-r--r--windows.cpp388
-rw-r--r--x11.cpp1354
34 files changed, 13836 insertions, 12341 deletions
diff --git a/actor.cpp b/actor.cpp
index 4f727fecd3..93e9123719 100644
--- a/actor.cpp
+++ b/actor.cpp
@@ -24,19 +24,20 @@
#include "scumm.h"
#include "math.h"
-void Scumm::initActor(Actor *a, int mode) {
- if (mode==1) {
+void Scumm::initActor(Actor * a, int mode)
+{
+ if (mode == 1) {
a->costume = 0;
a->room = 0;
a->x = 0;
a->y = 0;
a->facing = 180;
a->newDirection = 180;
- } else if (mode==2) {
+ } else if (mode == 2) {
a->facing = 180;
a->newDirection = 180;
}
-
+
a->elevation = 0;
a->width = 24;
a->talkColor = 15;
@@ -53,7 +54,7 @@ void Scumm::initActor(Actor *a, int mode) {
a->sound[6] = 0;
a->sound[7] = 0;
a->newDirection = 0;
-
+
stopActorMoving(a);
a->shadow_mode = 0;
@@ -80,12 +81,14 @@ void Scumm::initActor(Actor *a, int mode) {
}
}
-void Scumm::stopActorMoving(Actor *a) {
+void Scumm::stopActorMoving(Actor * a)
+{
stopScriptNr(a->walk_script);
a->moving = 0;
}
-void Scumm::setActorWalkSpeed(Actor *a, uint speedx, uint speedy) {
+void Scumm::setActorWalkSpeed(Actor * a, uint speedx, uint speedy)
+{
if (speedx == a->speedx && speedy == a->speedy)
return;
@@ -97,24 +100,26 @@ void Scumm::setActorWalkSpeed(Actor *a, uint speedx, uint speedy) {
}
}
-int Scumm::getAngleFromPos(int x, int y) {
- if (_gameId==GID_DIG) {
- double temp = atan2 (x, -y);
+int Scumm::getAngleFromPos(int x, int y)
+{
+ if (_gameId == GID_DIG) {
+ double temp = atan2(x, -y);
return normalizeAngle((int)(temp * 1.8e2 / 3.14));
} else {
- if (abs(y)*2 < abs(x)) {
- if (x>0)
+ if (abs(y) * 2 < abs(x)) {
+ if (x > 0)
return 90;
return 270;
} else {
- if (y>0)
+ if (y > 0)
return 180;
return 0;
}
}
}
-int Scumm::calcMovementFactor(Actor *a, int newX, int newY) {
+int Scumm::calcMovementFactor(Actor * a, int newX, int newY)
+{
int actorX, actorY;
int diffX, diffY;
int32 XYFactor, YXFactor;
@@ -127,7 +132,7 @@ int Scumm::calcMovementFactor(Actor *a, int newX, int newY) {
diffX = newX - actorX;
diffY = newY - actorY;
- YXFactor = a->speedy<<16;
+ YXFactor = a->speedy << 16;
if (diffY < 0)
YXFactor = -YXFactor;
@@ -139,8 +144,8 @@ int Scumm::calcMovementFactor(Actor *a, int newX, int newY) {
YXFactor = 0;
}
- if ((uint)abs(XYFactor >> 16) > a->speedx) {
- XYFactor = a->speedx<<16;
+ if ((uint) abs(XYFactor >> 16) > a->speedx) {
+ XYFactor = a->speedx << 16;
if (diffX < 0)
XYFactor = -XYFactor;
@@ -166,7 +171,8 @@ int Scumm::calcMovementFactor(Actor *a, int newX, int newY) {
return actorWalkStep(a);
}
-int Scumm::remapDirection(Actor *a, int dir) {
+int Scumm::remapDirection(Actor * a, int dir)
+{
int specdir;
byte flags;
byte dirflag;
@@ -182,37 +188,42 @@ int Scumm::remapDirection(Actor *a, int dir) {
}
flags = getBoxFlags(a->walkbox);
-
- dirflag = ((a->walkdata.XYFactor>0) ? 1 : 0) |
- ((a->walkdata.YXFactor>0) ? 2 : 0);
+
+ dirflag = ((a->walkdata.XYFactor > 0) ? 1 : 0) |
+ ((a->walkdata.YXFactor > 0) ? 2 : 0);
- if ((flags&8) || getClass(a->number, 0x1E)) {
+ if ((flags & 8) || getClass(a->number, 0x1E)) {
dir = 360 - dir;
dirflag ^= 1;
}
- if ((flags&0x10) || getClass(a->number, 0x1D)) {
+ if ((flags & 0x10) || getClass(a->number, 0x1D)) {
dir = 180 - dir;
dirflag ^= 2;
}
- switch(flags & 7) {
+ switch (flags & 7) {
case 1:
- return (dirflag&1) ? 90 : 270;
- case 2:
- return (dirflag&2) ? 180 : 0;
- case 3: return 270;
- case 4: return 90;
- case 5: return 0;
- case 6: return 180;
+ return (dirflag & 1) ? 90 : 270;
+ case 2:
+ return (dirflag & 2) ? 180 : 0;
+ case 3:
+ return 270;
+ case 4:
+ return 90;
+ case 5:
+ return 0;
+ case 6:
+ return 180;
}
}
return normalizeAngle(dir);
}
-int Scumm::updateActorDirection(Actor *a) {
- int from,to;
+int Scumm::updateActorDirection(Actor * a)
+{
+ int from, to;
int diff;
int dirType;
int num;
@@ -225,41 +236,43 @@ int Scumm::updateActorDirection(Actor *a) {
num = numSimpleDirDirections(dirType);
- if (abs(diff) > (num>>1))
+ if (abs(diff) > (num >> 1))
diff = -diff;
- if (diff==0) {
- } else if (diff>0) {
+ if (diff == 0) {
+ } else if (diff > 0) {
from++;
} else {
from--;
}
- return fromSimpleDir(dirType, from & (num-1));
+ return fromSimpleDir(dirType, from & (num - 1));
}
-void Scumm::setActorBox(Actor *a, int box) {
+void Scumm::setActorBox(Actor * a, int box)
+{
a->walkbox = box;
a->mask = getMaskFromBox(box);
setupActorScale(a);
}
-int Scumm::actorWalkStep(Actor *a) {
+int Scumm::actorWalkStep(Actor * a)
+{
int tmpX, tmpY;
int actorX, actorY;
int distX, distY;
int direction;
-
+
a->needRedraw = true;
a->needBgReset = true;
direction = updateActorDirection(a);
- if (!(a->moving&MF_IN_LEG) || a->facing!=direction) {
+ if (!(a->moving & MF_IN_LEG) || a->facing != direction) {
if (a->walkFrame != a->frame || a->facing != direction) {
- startWalkAnim(a, a->walkFrame==a->frame ? 2 : 1, direction);
+ startWalkAnim(a, a->walkFrame == a->frame ? 2 : 1, direction);
}
- a->moving|=MF_IN_LEG;
+ a->moving |= MF_IN_LEG;
}
actorX = a->x;
@@ -273,24 +286,22 @@ int Scumm::actorWalkStep(Actor *a) {
distX = abs(a->walkdata.newx - a->walkdata.x);
distY = abs(a->walkdata.newy - a->walkdata.y);
- if (
- abs(actorX - a->walkdata.x) >= distX &&
- abs(actorY - a->walkdata.y) >= distY
- ) {
+ if (abs(actorX - a->walkdata.x) >= distX &&
+ abs(actorY - a->walkdata.y) >= distY) {
a->moving &= ~MF_IN_LEG;
return 0;
}
- tmpX = ((actorX + 8000)<<16) + a->walkdata.xfrac +
- (a->walkdata.XYFactor>>8) * a->scalex;
+ tmpX = ((actorX + 8000) << 16) + a->walkdata.xfrac +
+ (a->walkdata.XYFactor >> 8) * a->scalex;
a->walkdata.xfrac = (uint16)tmpX;
- actorX = (tmpX>>16) - 8000;
+ actorX = (tmpX >> 16) - 8000;
- tmpY = (actorY<<16) + a->walkdata.yfrac +
- (a->walkdata.YXFactor>>8) * a->scalex;
+ tmpY = (actorY << 16) + a->walkdata.yfrac +
+ (a->walkdata.YXFactor >> 8) * a->scalex;
a->walkdata.yfrac = (uint16)tmpY;
- actorY = (tmpY>>16);
-
+ actorY = (tmpY >> 16);
+
if (abs(actorX - a->walkdata.x) > distX) {
actorX = a->walkdata.newx;
}
@@ -305,7 +316,8 @@ int Scumm::actorWalkStep(Actor *a) {
}
-void Scumm::setupActorScale(Actor *a) {
+void Scumm::setupActorScale(Actor * a)
+{
uint16 scale;
byte *resptr;
int y;
@@ -315,40 +327,51 @@ void Scumm::setupActorScale(Actor *a) {
a->scaley = 0xFF;
return;
}
-
+
if (a->ignoreBoxes != 0)
return;
scale = getBoxScale(a->walkbox);
if (scale & 0x8000) {
- scale = (scale&0x7FFF)+1;
+ scale = (scale & 0x7FFF) + 1;
resptr = getResourceAddress(rtScaleTable, scale);
- if (resptr==NULL)
- error("Scale table %d not defined",scale);
+ if (resptr == NULL)
+ error("Scale table %d not defined", scale);
y = a->y;
- if (y>=200)
- y=199;
- if (y<0)
- y=0;
+ if (y >= 200)
+ y = 199;
+ if (y < 0)
+ y = 0;
scale = resptr[y];
}
- if (scale>255)
- warning("Actor %d at %d, scale %d out of range", a->number, a->y, scale);
-
+ if (scale > 255)
+ warning("Actor %d at %d, scale %d out of range", a->number, a->y, scale);
+
a->scalex = (byte)scale;
a->scaley = (byte)scale;
}
-void Scumm::startAnimActor(Actor *a, int frame) {
+void Scumm::startAnimActor(Actor * a, int frame)
+{
if (_features & GF_NEW_COSTUMES) {
- switch(frame) {
- case 1001: frame = a->initFrame; break;
- case 1002: frame = a->walkFrame; break;
- case 1003: frame = a->standFrame; break;
- case 1004: frame = a->talkFrame1; break;
- case 1005: frame = a->talkFrame2; break;
+ switch (frame) {
+ case 1001:
+ frame = a->initFrame;
+ break;
+ case 1002:
+ frame = a->walkFrame;
+ break;
+ case 1003:
+ frame = a->standFrame;
+ break;
+ case 1004:
+ frame = a->talkFrame1;
+ break;
+ case 1005:
+ frame = a->talkFrame2;
+ break;
}
if (a->costume != 0) {
@@ -357,35 +380,35 @@ void Scumm::startAnimActor(Actor *a, int frame) {
a->needBgReset = true;
if (frame == a->initFrame)
initActorCostumeData(a);
- akos_decodeData(a, frame, (uint)-1);
+ akos_decodeData(a, frame, (uint) - 1);
}
} else {
- if (frame==0x38)
+ if (frame == 0x38)
frame = a->initFrame;
- if (frame==0x39)
+ if (frame == 0x39)
frame = a->walkFrame;
- if (frame==0x3A)
+ if (frame == 0x3A)
frame = a->standFrame;
- if (frame==0x3B)
+ if (frame == 0x3B)
frame = a->talkFrame1;
- if (frame==0x3C)
+ if (frame == 0x3C)
frame = a->talkFrame2;
if (a->room == _currentRoom && a->costume) {
a->animProgress = 0;
a->cost.animCounter1 = 0;
a->needRedraw = true;
-
- if (a->initFrame==frame)
+
+ if (a->initFrame == frame)
initActorCostumeData(a);
- if (frame!=0x3E) {
- cost_decodeData(a, frame, (uint) -1);
+ if (frame != 0x3E) {
+ cost_decodeData(a, frame, (uint) - 1);
}
}
@@ -393,7 +416,8 @@ void Scumm::startAnimActor(Actor *a, int frame) {
}
}
-void Scumm::fixActorDirection(Actor *a, int direction) {
+void Scumm::fixActorDirection(Actor * a, int direction)
+{
uint mask;
int i;
uint16 vald;
@@ -403,26 +427,28 @@ void Scumm::fixActorDirection(Actor *a, int direction) {
a->facing = direction;
- if (a->costume==0)
+ if (a->costume == 0)
return;
mask = 0x8000;
- for (i=0; i<16; i++,mask>>=1) {
+ for (i = 0; i < 16; i++, mask >>= 1) {
vald = a->cost.frame[i];
- if (vald==0xFFFF)
+ if (vald == 0xFFFF)
continue;
- if(_features & GF_AFTER_V7)
- akos_decodeData(a, vald, mask);
- else
- cost_decodeData(a, vald, mask);
+ if (_features & GF_AFTER_V7)
+ akos_decodeData(a, vald, mask);
+ else
+ cost_decodeData(a, vald, mask);
}
a->needRedraw = true;
a->needBgReset = true;
}
-void Scumm::putActor(Actor *a, int x, int y, byte room) {
- if (a->visible && _currentRoom!=room && _vars[VAR_TALK_ACTOR]==a->number) {
+void Scumm::putActor(Actor * a, int x, int y, byte room)
+{
+ if (a->visible && _currentRoom != room
+ && _vars[VAR_TALK_ACTOR] == a->number) {
clearMsgQueue();
}
@@ -432,7 +458,7 @@ void Scumm::putActor(Actor *a, int x, int y, byte room) {
a->needRedraw = true;
a->needBgReset = true;
- if (_vars[VAR_EGO]==a->number) {
+ if (_vars[VAR_EGO] == a->number) {
_egoPositioned = true;
}
@@ -452,7 +478,8 @@ void Scumm::putActor(Actor *a, int x, int y, byte room) {
}
}
-int Scumm::getActorXYPos(Actor *a) {
+int Scumm::getActorXYPos(Actor * a)
+{
if (a->room != _currentRoom)
return -1;
_xPos = a->x;
@@ -460,89 +487,94 @@ int Scumm::getActorXYPos(Actor *a) {
return 0;
}
-AdjustBoxResult Scumm::adjustXYToBeInBox(Actor *a, int x, int y, int pathfrom) {
- // Yazoo: need to recheck with Loom for the class data flags (0x400000)
- AdjustBoxResult abr,tmp;
+AdjustBoxResult Scumm::adjustXYToBeInBox(Actor * a, int x, int y,
+ int pathfrom)
+{
+ // Yazoo: need to recheck with Loom for the class data flags (0x400000)
+ AdjustBoxResult abr, tmp;
uint threshold;
uint best;
- int box, iterations = 0; /* Use iterations for those odd times we get stuck in the loop */
- int firstValidBox,j;
+ int box, iterations = 0; /* Use iterations for those odd times we get stuck in the loop */
+ int firstValidBox, j;
byte flags, b;
-
- if(_features & GF_SMALL_HEADER)
- firstValidBox=0;
+
+ if (_features & GF_SMALL_HEADER)
+ firstValidBox = 0;
else
- firstValidBox=1;
+ firstValidBox = 1;
abr.x = x;
abr.y = y;
abr.dist = 0;
- if ((_features & GF_SMALL_HEADER) && getClass(a->number, 21))
+ if ((_features & GF_SMALL_HEADER) && getClass(a->number, 22))
return abr;
-
- if (a && a->ignoreBoxes==0) {
+
+ if (a && a->ignoreBoxes == 0) {
threshold = 30;
- while(1) {
+ while (1) {
iterations++;
- if (iterations > 1000) return abr; /* Safety net */
+ if (iterations > 1000)
+ return abr; /* Safety net */
box = getNumBoxes() - 1;
if (box == 0)
return abr;
- best = (uint)0xFFFF;
+ best = (uint) 0xFFFF;
b = 0;
- if(((_features & GF_SMALL_HEADER) && box) || !(_features & GF_SMALL_HEADER))
- for (j=box;j>=firstValidBox;j--) {
- flags = getBoxFlags(j);
- if (flags&0x80 && (!(flags&0x20) || getClass(a->number, 0x1F)) )
- continue;
-
- if (pathfrom && (getPathToDestBox(pathfrom, j)==-1))
- continue;
-
- if (!inBoxQuickReject(j, x, y, threshold))
- continue;
-
- if (checkXYInBoxBounds(j, x, y)) {
- abr.x = x;
- abr.y = y;
- abr.dist = j;
- return abr;
- }
+ if (((_features & GF_SMALL_HEADER) && box)
+ || !(_features & GF_SMALL_HEADER))
+ for (j = box; j >= firstValidBox; j--) {
+ flags = getBoxFlags(j);
+ if (flags & 0x80 && (!(flags & 0x20) || getClass(a->number, 0x1F)))
+ continue;
+
+ if (pathfrom && (getPathToDestBox(pathfrom, j) == -1))
+ continue;
+
+ if (!inBoxQuickReject(j, x, y, threshold))
+ continue;
- tmp = getClosestPtOnBox(j, x, y);
+ if (checkXYInBoxBounds(j, x, y)) {
+ abr.x = x;
+ abr.y = y;
+ abr.dist = j;
+ return abr;
+ }
- if (tmp.dist >= best)
- continue;
+ tmp = getClosestPtOnBox(j, x, y);
- abr.x = tmp.x;
- abr.y = tmp.y;
+ if (tmp.dist >= best)
+ continue;
- if (tmp.dist==0) {
- abr.dist = j;
- return abr;
+ abr.x = tmp.x;
+ abr.y = tmp.y;
+
+ if (tmp.dist == 0) {
+ abr.dist = j;
+ return abr;
+ }
+ best = tmp.dist;
+ b = j;
}
- best = tmp.dist;
- b = j;
- }
-
- if (threshold==0 || threshold * threshold >= best) {
+
+ if (threshold == 0 || threshold * threshold >= best) {
abr.dist = b;
return abr;
}
- threshold = (threshold==30) ? 80 : 0;
+ threshold = (threshold == 30) ? 80 : 0;
}
}
return abr;
}
-void Scumm::adjustActorPos(Actor *a) {
+void Scumm::adjustActorPos(Actor * a)
+{
AdjustBoxResult abr;
byte flags;
-
+
abr = adjustXYToBeInBox(a, a->x, a->y, 0);
a->x = abr.x;
@@ -557,12 +589,13 @@ void Scumm::adjustActorPos(Actor *a) {
a->cost.animCounter2 = 0;
flags = getBoxFlags(a->walkbox);
- if (flags&7) {
+ if (flags & 7) {
turnToDirection(a, a->facing);
}
}
-void Scumm::hideActor(Actor *a) {
+void Scumm::hideActor(Actor * a)
+{
if (!a->visible)
return;
@@ -576,8 +609,9 @@ void Scumm::hideActor(Actor *a) {
a->needBgReset = true;
}
-void Scumm::turnToDirection(Actor *a, int newdir) {
- if (newdir==-1)
+void Scumm::turnToDirection(Actor * a, int newdir)
+{
+ if (newdir == -1)
return;
a->moving &= ~4;
@@ -588,7 +622,8 @@ void Scumm::turnToDirection(Actor *a, int newdir) {
}
}
-void Scumm::showActor(Actor *a) {
+void Scumm::showActor(Actor * a)
+{
if (_currentRoom == 0 || a->visible)
return;
@@ -605,18 +640,20 @@ void Scumm::showActor(Actor *a) {
a->needRedraw = true;
}
-void Scumm::showActors() {
+void Scumm::showActors()
+{
int i;
Actor *a;
-
- for (i=1; i<NUM_ACTORS; i++) {
+
+ for (i = 1; i < NUM_ACTORS; i++) {
a = derefActor(i);
if (a->room == _currentRoom)
showActor(a);
}
}
-void Scumm::stopTalk() {
+void Scumm::stopTalk()
+{
int act;
stopTalkSound();
@@ -625,7 +662,7 @@ void Scumm::stopTalk() {
_talkDelay = 0;
act = _vars[VAR_TALK_ACTOR];
- if (act && act<0x80) {
+ if (act && act < 0x80) {
Actor *a = derefActorSafe(act, "stopTalk");
if (_currentRoom == a->room && _useTalkAnims) {
startAnimActor(a, a->talkFrame2);
@@ -637,36 +674,39 @@ void Scumm::stopTalk() {
restoreCharsetBg();
}
-void Scumm::clearMsgQueue() {
- _messagePtr = (byte*)" ";
+void Scumm::clearMsgQueue()
+{
+ _messagePtr = (byte *)" ";
stopTalk();
}
-void Scumm::walkActors() {
+void Scumm::walkActors()
+{
int i;
Actor *a;
- for (i=1; i<NUM_ACTORS; i++) {
+ for (i = 1; i < NUM_ACTORS; i++) {
a = derefActor(i);
- if (a->room==_currentRoom)
- if(_features & GF_OLD256)
- walkActorOld(a);
- else
- walkActor(a);
+ if (a->room == _currentRoom)
+ if (_features & GF_OLD256)
+ walkActorOld(a);
+ else
+ walkActor(a);
}
}
/* Used in Scumm v5 only. Play sounds associated with actors */
-void Scumm::playActorSounds() {
+void Scumm::playActorSounds()
+{
int i;
Actor *a;
-
- for (i=1; i<NUM_ACTORS; i++) {
+
+ for (i = 1; i < NUM_ACTORS; i++) {
a = derefActor(i);
- if (a->cost.animCounter2 && a->room==_currentRoom && a->sound) {
+ if (a->cost.animCounter2 && a->room == _currentRoom && a->sound) {
_currentScript = 0xFF;
addSoundToQueue(a->sound[0]);
- for (i=1; i<NUM_ACTORS; i++) {
+ for (i = 1; i < NUM_ACTORS; i++) {
a = derefActor(i);
a->cost.animCounter2 = 0;
}
@@ -676,7 +716,8 @@ void Scumm::playActorSounds() {
}
-void Scumm::startWalkAnim(Actor *a, int cmd, int angle) {
+void Scumm::startWalkAnim(Actor * a, int cmd, int angle)
+{
int16 args[16];
if (angle == -1)
@@ -688,16 +729,16 @@ void Scumm::startWalkAnim(Actor *a, int cmd, int angle) {
args[1] = cmd;
runScript(a->walk_script, 1, 0, args);
} else {
- switch(cmd) {
- case 1: /* start walk */
+ switch (cmd) {
+ case 1: /* start walk */
//a->facing = angle;
fixActorDirection(a, angle);
startAnimActor(a, a->walkFrame);
break;
- case 2: /* change dir only */
+ case 2: /* change dir only */
fixActorDirection(a, angle);
break;
- case 3: /* stop walk */
+ case 3: /* stop walk */
turnToDirection(a, angle);
startAnimActor(a, a->standFrame);
break;
@@ -706,27 +747,28 @@ void Scumm::startWalkAnim(Actor *a, int cmd, int angle) {
}
-void Scumm::walkActor(Actor *a) {
+void Scumm::walkActor(Actor * a)
+{
int j;
if (!a->moving)
return;
-
- if (!(a->moving&1)) {
- if (a->moving&2 && actorWalkStep(a))
+
+ if (!(a->moving & 1)) {
+ if (a->moving & 2 && actorWalkStep(a))
return;
-
- if (a->moving&8) {
+
+ if (a->moving & 8) {
a->moving = 0;
setActorBox(a, a->walkdata.destbox);
startWalkAnim(a, 3, a->walkdata.destdir);
return;
}
- if (a->moving&4) {
+ if (a->moving & 4) {
j = updateActorDirection(a);
- if (a->facing != j)
- fixActorDirection(a,j);
+ if (a->facing != j)
+ fixActorDirection(a, j);
else
a->moving = 0;
return;
@@ -735,10 +777,9 @@ void Scumm::walkActor(Actor *a) {
setActorBox(a, a->walkdata.curbox);
a->moving &= 2;
}
-
#if OLD
a->moving &= ~1;
-
+
if (!a->walkbox) {
a->walkbox = a->walkdata.destbox;
a->walkdata.curbox = a->walkdata.destbox;
@@ -746,20 +787,21 @@ void Scumm::walkActor(Actor *a) {
calcMovementFactor(a, a->walkdata.destx, a->walkdata.desty);
return;
}
-
- if (a->ignoreBoxes || a->walkbox==a->walkdata.destbox) {
+
+ if (a->ignoreBoxes || a->walkbox == a->walkdata.destbox) {
a->walkdata.curbox = a->walkbox;
a->moving |= 8;
calcMovementFactor(a, a->walkdata.destx, a->walkdata.desty);
return;
}
- j = getPathToDestBox(a->walkbox,a->walkdata.destbox);
- if (j==-1) {
- error("walkActor: no path found between %d and %d", a->walkbox, a->walkdata.destbox);
+ j = getPathToDestBox(a->walkbox, a->walkdata.destbox);
+ if (j == -1) {
+ error("walkActor: no path found between %d and %d", a->walkbox,
+ a->walkdata.destbox);
}
a->walkdata.curbox = j;
-
+
if (findPathTowards(a, a->walkbox, j, a->walkdata.destbox)) {
a->moving |= 8;
calcMovementFactor(a, a->walkdata.destx, a->walkdata.desty);
@@ -769,42 +811,40 @@ void Scumm::walkActor(Actor *a) {
#endif
#if 1
do {
- a->moving&=~1;
- if ((!a->walkbox && (!(_features & GF_SMALL_HEADER))) ) {
+ a->moving &= ~1;
+ if ((!a->walkbox && (!(_features & GF_SMALL_HEADER)))) {
setActorBox(a, a->walkdata.destbox);
a->walkdata.curbox = a->walkdata.destbox;
break;
}
if (a->walkbox == a->walkdata.destbox)
break;
- j = getPathToDestBox(a->walkbox,a->walkdata.destbox);
- if (j==-1 || j>0xF0) {
+ j = getPathToDestBox(a->walkbox, a->walkdata.destbox);
+ if (j == -1 || j > 0xF0) {
a->walkdata.destbox = a->walkbox;
a->moving |= 8;
return;
}
a->walkdata.curbox = j;
- if(_features & GF_OLD256)
- {
+ if (_features & GF_OLD256) {
findPathTowardsOld(a, a->walkbox, j, a->walkdata.destbox);
- if (p[2].x == 32000 && p[3].x == 32000)
- {
+ if (p[2].x == 32000 && p[3].x == 32000) {
a->moving |= 8;
calcMovementFactor(a, a->walkdata.destx, a->walkdata.desty);
return;
}
-
+
if (p[2].x != 32000) {
- if (calcMovementFactor(a, p[2].x, p[2].y)){
+ if (calcMovementFactor(a, p[2].x, p[2].y)) {
a->walkdata.destx = p[3].x;
a->walkdata.desty = p[3].y;
- return;
+ return;
}
}
if (calcMovementFactor(a, p[3].x, p[3].y))
return;
-
+
} else {
if (findPathTowards(a, a->walkbox, j, a->walkdata.destbox))
break;
@@ -819,12 +859,13 @@ void Scumm::walkActor(Actor *a) {
#endif
}
-void Scumm::processActors() {
+void Scumm::processActors()
+{
int i;
- Actor *actors[MAX_ACTORS], *a,**ac,**ac2,*tmp;
- int numactors = 0, cnt,cnt2;
+ Actor *actors[MAX_ACTORS], *a, **ac, **ac2, *tmp;
+ int numactors = 0, cnt, cnt2;
- for (i=1; i<NUM_ACTORS; i++) {
+ for (i = 1; i < NUM_ACTORS; i++) {
a = derefActor(i);
if (a->room == _currentRoom)
actors[numactors++] = a;
@@ -838,33 +879,32 @@ void Scumm::processActors() {
ac2 = actors;
cnt2 = numactors;
do {
- if ( (*ac2)->y - ((*ac2)->layer<<11) > (*ac)->y - ((*ac)->layer<<11) ) {
+ if ((*ac2)->y - ((*ac2)->layer << 11) > (*ac)->y - ((*ac)->layer << 11)) {
tmp = *ac;
*ac = *ac2;
*ac2 = tmp;
}
} while (ac2++, --cnt2);
- } while (ac++,--cnt);
+ } while (ac++, --cnt);
ac = actors;
cnt = numactors;
do {
a = *ac;
if (a->costume) {
- CHECK_HEAP
- getMaskFromBox(a->walkbox);
+ CHECK_HEAP getMaskFromBox(a->walkbox);
drawActorCostume(a);
- CHECK_HEAP
- actorAnimate(a);
+ CHECK_HEAP actorAnimate(a);
}
- } while (ac++,--cnt);
+ } while (ac++, --cnt);
}
-void Scumm::drawActorCostume(Actor *a) {
- if(!(_features & GF_AFTER_V7)) {
+void Scumm::drawActorCostume(Actor * a)
+{
+ if (!(_features & GF_AFTER_V7)) {
CostumeRenderer cr;
-
- if (a==NULL || !a->needRedraw)
+
+ if (a == NULL || !a->needRedraw)
return;
a->needRedraw = false;
@@ -884,7 +924,7 @@ void Scumm::drawActorCostume(Actor *a) {
cr._zbuf = (byte)gdi._numZBuffer;
if (a->forceClip)
cr._zbuf = a->forceClip;
-
+
cr._shadow_table = _shadowPalette;
cost_setCostume(&cr, a->costume);
@@ -892,18 +932,18 @@ void Scumm::drawActorCostume(Actor *a) {
cost_setFacing(&cr, a);
a->top = 0xFF;
-
+
a->bottom = 0;
/* if the actor is partially hidden, redraw it next frame */
- if(cr.drawCostume(a)&1) {
+ if (cr.drawCostume(a) & 1) {
a->needBgReset = true;
a->needRedraw = true;
}
} else {
AkosRenderer ar;
- if (a==NULL || !a->needRedraw)
+ if (a == NULL || !a->needRedraw)
return;
a->needRedraw = false;
@@ -920,23 +960,23 @@ void Scumm::drawActorCostume(Actor *a) {
if (ar.clipping > (byte)gdi._numZBuffer)
ar.clipping = gdi._numZBuffer;
}
- ar.charsetmask = _vars[VAR_CHARSET_MASK]!=0;
-
+ ar.charsetmask = _vars[VAR_CHARSET_MASK] != 0;
+
ar.outptr = virtscr->screenPtr + virtscr->xstart;
ar.outwidth = virtscr->width;
ar.outheight = virtscr->height;
-
+
ar.shadow_mode = a->shadow_mode;
ar.shadow_table = _shadowPalette;
-
+
akos_setCostume(&ar, a->costume);
akos_setPalette(&ar, a->palette);
akos_setFacing(&ar, a);
-
+
ar.dirty_id = a->number;
-
+
ar.cd = &a->cost;
-
+
ar.draw_top = a->top = 0x7fffffff;
ar.draw_bottom = a->bottom = 0;
akos_drawCostume(&ar);
@@ -945,13 +985,14 @@ void Scumm::drawActorCostume(Actor *a) {
}
}
-void Scumm::actorAnimate(Actor *a) {
+void Scumm::actorAnimate(Actor * a)
+{
byte *akos;
LoadedCostume lc;
- if (a==NULL || a->costume == 0)
+ if (a == NULL || a->costume == 0)
return;
-
+
a->animProgress++;
if (a->animProgress >= a->animSpeed) {
a->animProgress = 0;
@@ -973,15 +1014,16 @@ void Scumm::actorAnimate(Actor *a) {
}
}
-void Scumm::setActorRedrawFlags() {
- int i,j;
+void Scumm::setActorRedrawFlags()
+{
+ int i, j;
uint32 bits;
- for (i=0; i<40; i++) {
- bits = gfxUsageBits[_screenStartStrip+i];
- if (bits&0x3FFFFFFF) {
- for(j=0; j<NUM_ACTORS; j++) {
- if ((bits&(1<<j)) && bits!=(uint32)(1<<j)) {
+ for (i = 0; i < 40; i++) {
+ bits = gfxUsageBits[_screenStartStrip + i];
+ if (bits & 0x3FFFFFFF) {
+ for (j = 0; j < NUM_ACTORS; j++) {
+ if ((bits & (1 << j)) && bits != (uint32)(1 << j)) {
Actor *a = derefActor(j);
a->needRedraw = true;
a->needBgReset = true;
@@ -991,54 +1033,58 @@ void Scumm::setActorRedrawFlags() {
}
}
-int Scumm::getActorFromPos(int x, int y) {
+int Scumm::getActorFromPos(int x, int y)
+{
uint32 drawbits;
int i;
- drawbits = gfxUsageBits[x>>3];
+ drawbits = gfxUsageBits[x >> 3];
if (!(drawbits & 0x3FFFFFFF))
return 0;
- for (i=1; i<NUM_ACTORS; i++) {
+ for (i = 1; i < NUM_ACTORS; i++) {
Actor *a = derefActor(i);
- if (drawbits&(1<<i) && !getClass(i, 32) && y >= a->top && y <= a->bottom) {
+ if (drawbits & (1 << i) && !getClass(i, 32) && y >= a->top
+ && y <= a->bottom) {
return i;
}
}
return 0;
}
-void Scumm::actorTalk() {
+void Scumm::actorTalk()
+{
int oldact;
Actor *a;
_msgPtrToAdd = charset._buffer;
_messagePtr = addMessageToStack(_messagePtr);
- assert((int)(_msgPtrToAdd - charset._buffer) < (int)(sizeof(charset._buffer)));
-
- if (_actorToPrintStrFor==0xFF) {
+ assert((int)(_msgPtrToAdd - charset._buffer) <
+ (int)(sizeof(charset._buffer)));
+
+ if (_actorToPrintStrFor == 0xFF) {
if (!_keepText)
stopTalk();
_vars[VAR_TALK_ACTOR] = 0xFF;
oldact = 0;
} else {
a = derefActorSafe(_actorToPrintStrFor, "actorTalk");
- if (a->room!=_currentRoom) {
+ if (a->room != _currentRoom) {
oldact = 0xFF;
} else {
if (!_keepText)
stopTalk();
_vars[VAR_TALK_ACTOR] = a->number;
if (!string[0].no_talk_anim) {
- startAnimActor(a,a->talkFrame1);
+ startAnimActor(a, a->talkFrame1);
_useTalkAnims = true;
}
oldact = _vars[VAR_TALK_ACTOR];
}
}
- if (oldact>=0x80)
+ if (oldact >= 0x80)
return;
-
- if (_vars[VAR_TALK_ACTOR]>0x7F) {
+
+ if (_vars[VAR_TALK_ACTOR] > 0x7F) {
_charsetColor = (byte)string[0].color;
} else {
a = derefActorSafe(_vars[VAR_TALK_ACTOR], "actorTalk(2)");
@@ -1051,11 +1097,12 @@ void Scumm::actorTalk() {
CHARSET_1();
}
-void Scumm::setActorCostume(Actor *a, int c) {
+void Scumm::setActorCostume(Actor * a, int c)
+{
int i;
a->costumeNeedsInit = true;
-
+
if (a->visible) {
hideActor(a);
initActorCostumeData(a);
@@ -1066,11 +1113,12 @@ void Scumm::setActorCostume(Actor *a, int c) {
initActorCostumeData(a);
}
- for (i=0; i<32; i++)
+ for (i = 0; i < 32; i++)
a->palette[i] = 0xFF;
}
-void Scumm::startWalkActor(Actor *a, int x, int y, int dir) {
+void Scumm::startWalkActor(Actor * a, int x, int y, int dir)
+{
AdjustBoxResult abr;
abr = adjustXYToBeInBox(a, x, y, a->walkbox);
@@ -1083,49 +1131,50 @@ void Scumm::startWalkActor(Actor *a, int x, int y, int dir) {
return;
}
- if (a->ignoreBoxes!=0) {
+ if (a->ignoreBoxes != 0) {
abr.dist = 0;
a->walkbox = 0;
} else {
- if (checkXYInBoxBounds(a->walkdata.destbox, abr.x,abr.y)) {
+ if (checkXYInBoxBounds(a->walkdata.destbox, abr.x, abr.y)) {
abr.dist = a->walkdata.destbox;
} else {
abr = adjustXYToBeInBox(a, abr.x, abr.y, a->walkbox);
}
if (a->moving && a->walkdata.destdir == dir
- && a->walkdata.destx == abr.x
- && a->walkdata.desty == abr.y)
- return;
+ && a->walkdata.destx == abr.x && a->walkdata.desty == abr.y)
+ return;
}
- if (a->x==abr.x && a->y==abr.y) {
+ if (a->x == abr.x && a->y == abr.y) {
turnToDirection(a, dir);
return;
}
a->walkdata.destx = abr.x;
a->walkdata.desty = abr.y;
- a->walkdata.destbox = (byte)abr.dist; /* a box */
+ a->walkdata.destbox = (byte)abr.dist; /* a box */
a->walkdata.destdir = dir;
- a->moving = (a->moving&2)|1;
+ a->moving = (a->moving & 2) | 1;
a->walkdata.point3x = 32000;
-
+
a->walkdata.curbox = a->walkbox;
}
-byte *Scumm::getActorName(Actor *a) {
+byte *Scumm::getActorName(Actor * a)
+{
byte *ptr = getResourceAddress(rtActorName, a->number);
- if(ptr==NULL)
- return (byte*)" ";
+ if (ptr == NULL)
+ return (byte *)" ";
return ptr;
}
-bool Scumm::isCostumeInUse(int cost) {
+bool Scumm::isCostumeInUse(int cost)
+{
int i;
Actor *a;
- if (_roomResource!=0)
- for (i=1; i<NUM_ACTORS; i++) {
+ if (_roomResource != 0)
+ for (i = 1; i < NUM_ACTORS; i++) {
a = derefActor(i);
if (a->room == _currentRoom && a->costume == cost)
return true;
@@ -1134,187 +1183,181 @@ bool Scumm::isCostumeInUse(int cost) {
return false;
}
-void Scumm::remapActor(Actor *a, int r_fact, int g_fact, int b_fact, int threshold) {
- byte *akos, *rgbs,*akpl;
+void Scumm::remapActor(Actor * a, int r_fact, int g_fact, int b_fact,
+ int threshold)
+{
+ byte *akos, *rgbs, *akpl;
int akpl_size, i;
- int r,g,b;
+ int r, g, b;
byte akpl_color;
if (a->room != _currentRoom) {
- warning("Remap actor %d not in current room",a->number);
+ warning("Remap actor %d not in current room", a->number);
return;
}
- if (a->costume < 1 || a->costume >= _numCostumes-1){
- warning("Remap actor %d invalid costume",a->number,a->costume);
+ if (a->costume < 1 || a->costume >= _numCostumes - 1) {
+ warning("Remap actor %d invalid costume", a->number, a->costume);
return;
}
akos = getResourceAddress(rtCostume, a->costume);
akpl = findResource(MKID('AKPL'), akos);
-
+
//get num palette entries
- akpl_size=RES_SIZE(akpl) - 8;
+ akpl_size = RES_SIZE(akpl) - 8;
//skip resource header
akpl = RES_DATA(akpl);
-
+
rgbs = findResource(MKID('RGBS'), akos);
if (!rgbs) {
- warning("Can't remap actor %d costume %d doesn't contain an RGB block",a->number,a->costume);
+ warning("Can't remap actor %d costume %d doesn't contain an RGB block",
+ a->number, a->costume);
return;
}
// skip resource header
rgbs = RES_DATA(rgbs);
-
- for(i=0; i<akpl_size; i++) {
- r=*rgbs++;
- g=*rgbs++;
- b=*rgbs++;
- akpl_color=*akpl++;
+ for (i = 0; i < akpl_size; i++) {
+ r = *rgbs++;
+ g = *rgbs++;
+ b = *rgbs++;
+
+ akpl_color = *akpl++;
// allow remap of generic palette entry?
- if (!a->shadow_mode || akpl_color>=16) {
- if (r_fact!=256) r = (r*r_fact) >> 8;
- if (g_fact!=256) g = (g*g_fact) >> 8;
- if (b_fact!=256) b = (b*b_fact) >> 8;
- a->palette[i]=remapPaletteColor(r,g,b,threshold);
+ if (!a->shadow_mode || akpl_color >= 16) {
+ if (r_fact != 256)
+ r = (r * r_fact) >> 8;
+ if (g_fact != 256)
+ g = (g * g_fact) >> 8;
+ if (b_fact != 256)
+ b = (b * b_fact) >> 8;
+ a->palette[i] = remapPaletteColor(r, g, b, threshold);
}
}
}
-void Scumm::setupShadowPalette(int slot,int rfact,int gfact,int bfact,int from,int to) {
+void Scumm::setupShadowPalette(int slot, int rfact, int gfact, int bfact,
+ int from, int to)
+{
byte *table;
- int i,num;
+ int i, num;
byte *curpal;
- if (slot<0 || slot > 7)
+ if (slot < 0 || slot > 7)
error("setupShadowPalette: invalid slot %d", slot);
- if (from<0 || from>255 || to<0 || from>255 || to < from)
+ if (from < 0 || from > 255 || to < 0 || from > 255 || to < from)
error("setupShadowPalette: invalid range from %d to %d", from, to);
table = _shadowPalette + slot * 256;
- for(i=0; i<256; i++)
+ for (i = 0; i < 256; i++)
table[i] = i;
table += from;
- curpal = _currentPalette + from*3;
+ curpal = _currentPalette + from * 3;
num = to - from + 1;
do {
- *table++ = remapPaletteColor(
- curpal[0] * rfact >> 8,
- curpal[1] * gfact >> 8,
- curpal[2] * bfact >> 8,
- (uint)-1);
- curpal+=3;
+ *table++ = remapPaletteColor(curpal[0] * rfact >> 8,
+ curpal[1] * gfact >> 8,
+ curpal[2] * bfact >> 8, (uint) - 1);
+ curpal += 3;
} while (--num);
}
-void Scumm::walkActorOld(Actor *a) {
- int new_dir,next_box;
+void Scumm::walkActorOld(Actor * a)
+{
+ int new_dir, next_box;
- if(!a->moving)
+ if (!a->moving)
return;
- if(a->moving&1)
- {
-restart:
+ if (a->moving & 1) {
+ restart:
a->moving &= ~1;
- if (a->walkbox==0xFF)
- {
+ if (a->walkbox == 0xFF) {
a->walkbox = a->walkdata.destbox;
a->walkdata.curbox = a->walkdata.destbox;
- a->moving |=8;
+ a->moving |= 8;
calcMovementFactor(a, a->walkdata.destx, a->walkdata.desty);
return;
}
- if (a->walkbox==a->walkdata.destbox)
- {
- a->moving |=8;
+ if (a->walkbox == a->walkdata.destbox) {
+ a->moving |= 8;
calcMovementFactor(a, a->walkdata.destx, a->walkdata.desty);
return;
}
- next_box = getPathToDestBox(a->walkbox,a->walkdata.destbox);
+ next_box = getPathToDestBox(a->walkbox, a->walkdata.destbox);
- if( next_box == -1)
- {
- a->moving |=8;
+ if (next_box == -1) {
+ a->moving |= 8;
return;
}
a->walkdata.curbox = next_box;
findPathTowardsOld(a, a->walkbox, next_box, a->walkdata.destbox);
- if(p[2].x == 32000 && p[3].x == 32000)
- {
- a->moving |=8;
+ if (p[2].x == 32000 && p[3].x == 32000) {
+ a->moving |= 8;
calcMovementFactor(a, a->walkdata.destx, a->walkdata.desty);
return;
}
- if(p[2].x != 32000)
- {
- if(calcMovementFactor(a, p[2].x, p[2].y))
- {
- actor->walkdata.point3x=p[3].x;
- actor->walkdata.point3y=p[3].y;
+ if (p[2].x != 32000) {
+ if (calcMovementFactor(a, p[2].x, p[2].y)) {
+ actor->walkdata.point3x = p[3].x;
+ actor->walkdata.point3y = p[3].y;
return;
}
}
- if(calcMovementFactor(a,p[3].x,p[3].y))
+ if (calcMovementFactor(a, p[3].x, p[3].y))
return;
-
+
a->walkbox = a->walkdata.destbox;
a->mask = getMaskFromBox(a->walkbox);
goto restart;
}
- if(a->moving & 2)
- {
- if(actorWalkStep(a))
+ if (a->moving & 2) {
+ if (actorWalkStep(a))
return;
}
- if(a->moving & 8)
- {
+ if (a->moving & 8) {
a->moving = 0;
startWalkAnim(a, 3, a->walkdata.destdir);
return;
}
- if(a->moving & 4)
- {
+ if (a->moving & 4) {
new_dir = updateActorDirection(a);
- if (a->facing != new_dir)
- {
- fixActorDirection(a,new_dir);
+ if (a->facing != new_dir) {
+ fixActorDirection(a, new_dir);
return;
}
- a->moving=0;
+ a->moving = 0;
return;
}
- if(a->walkdata.point3x != 32000)
- {
- if(calcMovementFactor(a,a->walkdata.point3x,a->walkdata.point3y))
- {
- a->walkdata.point3x=32000;
+ if (a->walkdata.point3x != 32000) {
+ if (calcMovementFactor(a, a->walkdata.point3x, a->walkdata.point3y)) {
+ a->walkdata.point3x = 32000;
return;
}
- a->walkdata.point3x=32000;
+ a->walkdata.point3x = 32000;
}
a->walkbox = a->walkdata.curbox;
a->mask = getMaskFromBox(a->walkbox);
a->moving &= 2;
a->moving |= 1;
-goto restart;
+ goto restart;
}
diff --git a/akos.cpp b/akos.cpp
index 54db7e3c6e..b5a444bc43 100644
--- a/akos.cpp
+++ b/akos.cpp
@@ -22,16 +22,17 @@
#include "stdafx.h"
#include "scumm.h"
-bool Scumm::akos_hasManyDirections(Actor *a) {
- if (_features & GF_NEW_COSTUMES) {
+bool Scumm::akos_hasManyDirections(Actor * a)
+{
+ if (_features & GF_NEW_COSTUMES) {
byte *akos;
AkosHeader *akhd;
akos = getResourceAddress(rtCostume, a->costume);
assert(akos);
- akhd = (AkosHeader*)findResourceData(MKID('AKHD'), akos);
- return (akhd->flags&2) != 0;
+ akhd = (AkosHeader *) findResourceData(MKID('AKHD'), akos);
+ return (akhd->flags & 2) != 0;
}
return 0;
}
@@ -41,50 +42,50 @@ int Scumm::akos_findManyDirection(int16 ManyDirection, uint16 facing)
int32 direction;
int32 temp;
- temp=many_direction_tab[ManyDirection];
- direction=temp + ManyDirection * 8;
- do{
- if(facing>=many_direction_tab[direction+1])
- {
- if(facing<=many_direction_tab[direction+2])
- {
- return(temp);
+ temp = many_direction_tab[ManyDirection];
+ direction = temp + ManyDirection * 8;
+ do {
+ if (facing >= many_direction_tab[direction + 1]) {
+ if (facing <= many_direction_tab[direction + 2]) {
+ return (temp);
}
}
-
+
--temp;
--direction;
-
- }while(temp);
- return(temp);
+ } while (temp);
+
+ return (temp);
}
-int Scumm::akos_frameToAnim(Actor *a, int frame) {
+int Scumm::akos_frameToAnim(Actor * a, int frame)
+{
bool ManyDirection;
ManyDirection = akos_hasManyDirections(a);
-
- if (ManyDirection){
- frame*=many_direction_tab[ManyDirection];
+
+ if (ManyDirection) {
+ frame *= many_direction_tab[ManyDirection];
return akos_findManyDirection(ManyDirection, a->facing) + frame;
} else {
return newDirToOldDir(a->facing) + frame * 4;
}
}
-void Scumm::akos_decodeData(Actor *a, int frame, uint usemask) {
+void Scumm::akos_decodeData(Actor * a, int frame, uint usemask)
+{
uint anim;
- byte *akos,*r;
+ byte *akos, *r;
AkosHeader *akhd;
uint offs;
int i;
byte code;
- uint16 start,len;
+ uint16 start, len;
uint16 mask;
-
- if (a->costume==0)
+
+ if (a->costume == 0)
return;
anim = akos_frameToAnim(a, frame);
@@ -92,27 +93,27 @@ void Scumm::akos_decodeData(Actor *a, int frame, uint usemask) {
akos = getResourceAddress(rtCostume, a->costume);
assert(akos);
- akhd = (AkosHeader*)findResourceData(MKID('AKHD'), akos);
+ akhd = (AkosHeader *) findResourceData(MKID('AKHD'), akos);
- if (anim>=READ_LE_UINT16(&akhd->num_anims))
+ if (anim >= READ_LE_UINT16(&akhd->num_anims))
return;
r = findResourceData(MKID('AKCH'), akos);
assert(r);
offs = READ_LE_UINT16(r + anim * sizeof(uint16));
- if (offs==0)
+ if (offs == 0)
return;
r += offs;
i = 0;
mask = READ_LE_UINT16(r);
- r+=sizeof(uint16);
+ r += sizeof(uint16);
do {
- if (mask&0x8000) {
+ if (mask & 0x8000) {
code = *r++;
- if (usemask&0x8000) {
- switch(code) {
+ if (usemask & 0x8000) {
+ switch (code) {
case 1:
a->cost.active[i] = 0;
a->cost.frame[i] = frame;
@@ -121,15 +122,15 @@ void Scumm::akos_decodeData(Actor *a, int frame, uint usemask) {
a->cost.curpos[i] = 0;
break;
case 4:
- a->cost.stopped |= 1<<i;
+ a->cost.stopped |= 1 << i;
break;
case 5:
- a->cost.stopped &= ~(1<<i);
+ a->cost.stopped &= ~(1 << i);
break;
default:
start = READ_LE_UINT16(r);
- len = READ_LE_UINT16(r+sizeof(uint16));
- r+=sizeof(uint16)*2;
+ len = READ_LE_UINT16(r + sizeof(uint16));
+ r += sizeof(uint16) * 2;
a->cost.active[i] = code;
a->cost.frame[i] = frame;
@@ -139,17 +140,18 @@ void Scumm::akos_decodeData(Actor *a, int frame, uint usemask) {
break;
}
} else {
- if (code!=1 && code!=4 && code!=5)
- r+=sizeof(uint16)*2;
+ if (code != 1 && code != 4 && code != 5)
+ r += sizeof(uint16) * 2;
}
}
i++;
- mask<<=1;
- usemask<<=1;
+ mask <<= 1;
+ usemask <<= 1;
} while ((uint16)mask);
}
-void Scumm::akos_setPalette(AkosRenderer *ar, byte *palette) {
+void Scumm::akos_setPalette(AkosRenderer * ar, byte *palette)
+{
byte *akpl;
uint size, i;
@@ -159,17 +161,18 @@ void Scumm::akos_setPalette(AkosRenderer *ar, byte *palette) {
if (size > 256)
error("akos_setPalette: %d is too many colors", size);
- for(i=0; i<size; i++) {
- ar->palette[i] = palette[i]!=0xFF ? palette[i] : akpl[i];
+ for (i = 0; i < size; i++) {
+ ar->palette[i] = palette[i] != 0xFF ? palette[i] : akpl[i];
}
}
-void Scumm::akos_setCostume(AkosRenderer *ar, int costume) {
+void Scumm::akos_setCostume(AkosRenderer * ar, int costume)
+{
ar->akos = getResourceAddress(rtCostume, costume);
assert(ar->akos);
- ar->akhd = (AkosHeader*)findResourceData(MKID('AKHD'), ar->akos);
- ar->akof = (AkosOffset*)findResourceData(MKID('AKOF'), ar->akos);
+ ar->akhd = (AkosHeader *) findResourceData(MKID('AKHD'), ar->akos);
+ ar->akof = (AkosOffset *) findResourceData(MKID('AKOF'), ar->akos);
ar->akci = findResourceData(MKID('AKCI'), ar->akos);
ar->aksq = findResourceData(MKID('AKSQ'), ar->akos);
ar->akcd = findResourceData(MKID('AKCD'), ar->akos);
@@ -177,58 +180,63 @@ void Scumm::akos_setCostume(AkosRenderer *ar, int costume) {
ar->codec = READ_LE_UINT16(&ar->akhd->codec);
}
-void Scumm::akos_setFacing(AkosRenderer *ar, Actor *a) {
- ar->mirror = (newDirToOldDir(a->facing)!=0 || ar->akhd->flags&1);
+void Scumm::akos_setFacing(AkosRenderer * ar, Actor * a)
+{
+ ar->mirror = (newDirToOldDir(a->facing) != 0 || ar->akhd->flags & 1);
if (a->flip)
ar->mirror ^= 1;
}
-bool Scumm::akos_drawCostume(AkosRenderer *ar) {
+bool Scumm::akos_drawCostume(AkosRenderer * ar)
+{
int i;
bool result = false;
ar->move_x = ar->move_y = 0;
- for(i=0; i<16; i++)
+ for (i = 0; i < 16; i++)
result |= akos_drawCostumeChannel(ar, i);
return result;
}
-bool Scumm::akos_drawCostumeChannel(AkosRenderer *ar, int chan) {
+bool Scumm::akos_drawCostumeChannel(AkosRenderer * ar, int chan)
+{
uint code;
byte *p;
AkosOffset *off;
AkosCI *akci;
- uint i,extra;
+ uint i, extra;
- if (!ar->cd->active[chan] || ar->cd->stopped&(1<<chan))
+ if (!ar->cd->active[chan] || ar->cd->stopped & (1 << chan))
return false;
p = ar->aksq + ar->cd->curpos[chan];
code = p[0];
- if (code & 0x80) code = (code<<8)|p[1];
+ if (code & 0x80)
+ code = (code << 8) | p[1];
- if (code==AKC_Return)
+ if (code == AKC_Return)
return false;
- if (code!=AKC_ComplexChan) {
+ if (code != AKC_ComplexChan) {
off = ar->akof + (code & 0xFFF);
- assert( (code & 0xFFF)*6 < READ_BE_UINT32_UNALIGNED((byte*)ar->akof - 4)-8 );
+ assert((code & 0xFFF) * 6 <
+ READ_BE_UINT32_UNALIGNED((byte *)ar->akof - 4) - 8);
- assert( (code&0x7000) == 0);
+ assert((code & 0x7000) == 0);
ar->srcptr = ar->akcd + READ_LE_UINT32(&off->akcd);
- akci = (AkosCI*)(ar->akci + READ_LE_UINT16(&off->akci));
+ akci = (AkosCI *) (ar->akci + READ_LE_UINT16(&off->akci));
- ar->move_x_cur = ar->move_x + (int16)READ_LE_UINT16(&akci->rel_x);
- ar->move_y_cur = ar->move_y + (int16)READ_LE_UINT16(&akci->rel_y);
+ ar->move_x_cur = ar->move_x + (int16) READ_LE_UINT16(&akci->rel_x);
+ ar->move_y_cur = ar->move_y + (int16) READ_LE_UINT16(&akci->rel_y);
ar->width = READ_LE_UINT16(&akci->width);
ar->height = READ_LE_UINT16(&akci->height);
- ar->move_x += (int16)READ_LE_UINT16(&akci->move_x);
- ar->move_y -= (int16)READ_LE_UINT16(&akci->move_y);
+ ar->move_x += (int16) READ_LE_UINT16(&akci->move_x);
+ ar->move_y -= (int16) READ_LE_UINT16(&akci->move_y);
- switch(ar->codec) {
+ switch (ar->codec) {
case 1:
akos_codec1(ar);
break;
@@ -243,25 +251,26 @@ bool Scumm::akos_drawCostumeChannel(AkosRenderer *ar, int chan) {
}
} else {
extra = p[2];
- p+=3;
+ p += 3;
- for(i=0; i!=extra; i++) {
+ for (i = 0; i != extra; i++) {
code = p[4];
- if (code&0x80) code = ((code&0xF)<<8)|p[5];
+ if (code & 0x80)
+ code = ((code & 0xF) << 8) | p[5];
off = ar->akof + code;
ar->srcptr = ar->akcd + READ_LE_UINT32(&off->akcd);
- akci = (AkosCI*)(ar->akci + READ_LE_UINT16(&off->akci));
+ akci = (AkosCI *) (ar->akci + READ_LE_UINT16(&off->akci));
- ar->move_x_cur = ar->move_x + (int16)READ_LE_UINT16(p+0);
- ar->move_y_cur = ar->move_y + (int16)READ_LE_UINT16(p+2);
-
- p += (p[4]&0x80) ? 6 : 5;
+ ar->move_x_cur = ar->move_x + (int16) READ_LE_UINT16(p + 0);
+ ar->move_y_cur = ar->move_y + (int16) READ_LE_UINT16(p + 2);
+
+ p += (p[4] & 0x80) ? 6 : 5;
ar->width = READ_LE_UINT16(&akci->width);
ar->height = READ_LE_UINT16(&akci->height);
- switch(ar->codec) {
+ switch (ar->codec) {
case 1:
akos_codec1(ar);
break;
@@ -280,8 +289,9 @@ bool Scumm::akos_drawCostumeChannel(AkosRenderer *ar, int chan) {
return true;
}
-void akos_c1_0y_decode(AkosRenderer *ar) {
- byte len,color;
+void akos_c1_0y_decode(AkosRenderer * ar)
+{
+ byte len, color;
byte *src, *dst;
int height;
uint y;
@@ -295,13 +305,15 @@ void akos_c1_0y_decode(AkosRenderer *ar) {
height = ar->height;
y = ar->v1.y;
- if (len) goto StartPos;
+ if (len)
+ goto StartPos;
do {
len = *src++;
- color = len>>ar->v1.shl;
+ color = len >> ar->v1.shl;
len &= ar->v1.mask;
- if (!len) len = *src++;
+ if (!len)
+ len = *src++;
do {
if (color && y < scrheight) {
@@ -317,15 +329,16 @@ void akos_c1_0y_decode(AkosRenderer *ar) {
height = ar->height;
y = ar->v1.y;
}
-StartPos:;
+ StartPos:;
} while (--len);
} while (1);
}
-void akos_generic_decode(AkosRenderer *ar) {
- byte *src,*dst;
- byte len,height, maskbit;
- uint y, color;
+void akos_generic_decode(AkosRenderer * ar)
+{
+ byte *src, *dst;
+ byte len, height, maskbit;
+ uint y, color;
const byte *scaleytab, *mask;
@@ -338,20 +351,24 @@ void akos_generic_decode(AkosRenderer *ar) {
height = ar->height;
scaleytab = &ar->v1.scaletable[ar->v1.tmp_y];
- maskbit = revBitMask[ar->v1.x&7];
- mask = ar->v1.mask_ptr + (ar->v1.x>>3);
+ maskbit = revBitMask[ar->v1.x & 7];
+ mask = ar->v1.mask_ptr + (ar->v1.x >> 3);
- if (len) goto StartPos;
+ if (len)
+ goto StartPos;
do {
len = *src++;
- color = len>>ar->v1.shl;
+ color = len >> ar->v1.shl;
len &= ar->v1.mask;
- if (!len) len = *src++;
-
+ if (!len)
+ len = *src++;
+
do {
if (*scaleytab++ < ar->scale_y) {
- if (color && y < ar->outheight && (!ar->v1.mask_ptr || !((mask[0]|mask[ar->v1.imgbufoffs]) & maskbit)) ) {
+ if (color && y < ar->outheight
+ && (!ar->v1.mask_ptr
+ || !((mask[0] | mask[ar->v1.imgbufoffs]) & maskbit))) {
*dst = ar->palette[color];
}
mask += 40;
@@ -359,34 +376,35 @@ void akos_generic_decode(AkosRenderer *ar) {
y++;
}
if (!--height) {
- if(!--ar->v1.skip_width)
+ if (!--ar->v1.skip_width)
return;
height = ar->height;
y = ar->v1.y;
scaleytab = &ar->v1.scaletable[ar->v1.tmp_y];
-
+
if (ar->v1.scaletable[ar->v1.tmp_x] < ar->scale_x) {
ar->v1.x += ar->v1.scaleXstep;
- if ((uint)ar->v1.x >= 320)
+ if ((uint) ar->v1.x >= 320)
return;
- maskbit = revBitMask[ar->v1.x&7];
+ maskbit = revBitMask[ar->v1.x & 7];
ar->v1.destptr += ar->v1.scaleXstep;
}
- mask = ar->v1.mask_ptr + (ar->v1.x>>3);
+ mask = ar->v1.mask_ptr + (ar->v1.x >> 3);
ar->v1.tmp_x += ar->v1.scaleXstep;
dst = ar->v1.destptr;
}
-StartPos:;
+ StartPos:;
} while (--len);
- } while(1);
+ } while (1);
}
-void akos_c1_spec1(AkosRenderer *ar) {
- byte *src,*dst;
- byte len,height,pcolor, maskbit;
- uint y, color;
+void akos_c1_spec1(AkosRenderer * ar)
+{
+ byte *src, *dst;
+ byte len, height, pcolor, maskbit;
+ uint y, color;
const byte *scaleytab, *mask;
@@ -399,22 +417,26 @@ void akos_c1_spec1(AkosRenderer *ar) {
height = ar->height;
scaleytab = &ar->v1.scaletable[ar->v1.tmp_y];
- maskbit = revBitMask[ar->v1.x&7];
- mask = ar->v1.mask_ptr + (ar->v1.x>>3);
+ maskbit = revBitMask[ar->v1.x & 7];
+ mask = ar->v1.mask_ptr + (ar->v1.x >> 3);
- if (len) goto StartPos;
+ if (len)
+ goto StartPos;
do {
len = *src++;
- color = len>>ar->v1.shl;
+ color = len >> ar->v1.shl;
len &= ar->v1.mask;
- if (!len) len = *src++;
-
+ if (!len)
+ len = *src++;
+
do {
if (*scaleytab++ < ar->scale_y) {
- if (color && y < ar->outheight && (!ar->v1.mask_ptr || !((mask[0]|mask[ar->v1.imgbufoffs]) & maskbit)) ) {
+ if (color && y < ar->outheight
+ && (!ar->v1.mask_ptr
+ || !((mask[0] | mask[ar->v1.imgbufoffs]) & maskbit))) {
pcolor = ar->palette[color];
- if (pcolor==13)
+ if (pcolor == 13)
pcolor = ar->shadow_table[*dst];
*dst = pcolor;
}
@@ -423,137 +445,138 @@ void akos_c1_spec1(AkosRenderer *ar) {
y++;
}
if (!--height) {
- if(!--ar->v1.skip_width)
+ if (!--ar->v1.skip_width)
return;
height = ar->height;
y = ar->v1.y;
scaleytab = &ar->v1.scaletable[ar->v1.tmp_y];
-
+
if (ar->v1.scaletable[ar->v1.tmp_x] < ar->scale_x) {
ar->v1.x += ar->v1.scaleXstep;
- if ((uint)ar->v1.x >= 320)
+ if ((uint) ar->v1.x >= 320)
return;
- maskbit = revBitMask[ar->v1.x&7];
+ maskbit = revBitMask[ar->v1.x & 7];
ar->v1.destptr += ar->v1.scaleXstep;
}
- mask = ar->v1.mask_ptr + (ar->v1.x>>3);
+ mask = ar->v1.mask_ptr + (ar->v1.x >> 3);
ar->v1.tmp_x += ar->v1.scaleXstep;
dst = ar->v1.destptr;
}
-StartPos:;
+ StartPos:;
} while (--len);
- } while(1);
+ } while (1);
}
const byte default_scale_table[768] = {
-0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
-0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
-0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
-0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
-0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,
-0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
-0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,
-0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
-0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
-0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
-0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,
-0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
-0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,
-0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
-0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
-0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
-0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,
-0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
-0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,
-0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
-0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
-0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
-0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,
-0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
-0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,
-0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
-0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
-0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
-0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,
-0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
-0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,
-0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFE,
-
-0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
-0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
-0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
-0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
-0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,
-0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
-0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,
-0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
-0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
-0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
-0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,
-0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
-0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,
-0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
-0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
-0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
-0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,
-0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
-0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,
-0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
-0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
-0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
-0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,
-0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
-0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,
-0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
-0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
-0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
-0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,
-0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
-0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,
-0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFE,
-
-0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
-0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
-0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
-0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
-0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,
-0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
-0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,
-0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
-0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
-0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
-0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,
-0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
-0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,
-0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
-0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
-0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
-0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,
-0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
-0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,
-0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
-0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
-0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
-0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,
-0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
-0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,
-0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
-0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
-0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
-0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,
-0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
-0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,
-0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF,
+ 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
+ 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
+ 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
+ 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
+ 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,
+ 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
+ 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,
+ 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
+ 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
+ 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
+ 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,
+ 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
+ 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,
+ 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
+ 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
+ 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
+ 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,
+ 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
+ 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,
+ 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
+ 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
+ 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
+ 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,
+ 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
+ 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,
+ 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
+ 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
+ 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
+ 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,
+ 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
+ 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,
+ 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFE,
+
+ 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
+ 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
+ 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
+ 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
+ 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,
+ 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
+ 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,
+ 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
+ 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
+ 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
+ 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,
+ 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
+ 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,
+ 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
+ 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
+ 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
+ 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,
+ 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
+ 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,
+ 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
+ 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
+ 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
+ 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,
+ 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
+ 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,
+ 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
+ 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
+ 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
+ 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,
+ 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
+ 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,
+ 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFE,
+
+ 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
+ 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
+ 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
+ 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
+ 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,
+ 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
+ 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,
+ 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
+ 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
+ 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
+ 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,
+ 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
+ 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,
+ 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
+ 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
+ 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
+ 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,
+ 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
+ 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,
+ 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
+ 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
+ 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
+ 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,
+ 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
+ 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,
+ 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
+ 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
+ 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
+ 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,
+ 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
+ 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,
+ 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF,
};
-void Scumm::akos_codec1(AkosRenderer *ar) {
+void Scumm::akos_codec1(AkosRenderer * ar)
+{
int num_colors;
bool use_scaling;
- int i,j;
- int x,x_right,x_left,skip=0,tmp_x,tmp_y;
- int y,y_top,y_bottom;
+ int i, j;
+ int x, x_right, x_left, skip = 0, tmp_x, tmp_y;
+ int y, y_top, y_bottom;
bool y_clipping;
bool charsetmask;
bool masking;
@@ -565,23 +588,23 @@ void Scumm::akos_codec1(AkosRenderer *ar) {
/* Setup color decoding variables */
num_colors = getResourceDataSize(ar->akpl);
if (num_colors == 32) {
- ar->v1.mask = (1<<3)-1;
+ ar->v1.mask = (1 << 3) - 1;
ar->v1.shl = 3;
} else if (num_colors == 64) {
- ar->v1.mask = (1<<2)-1;
+ ar->v1.mask = (1 << 2) - 1;
ar->v1.shl = 2;
} else {
- ar->v1.mask = (1<<4)-1;
+ ar->v1.mask = (1 << 4) - 1;
ar->v1.shl = 4;
}
- use_scaling = (ar->scale_x!=0xFF) || (ar->scale_y!=0xFF);
+ use_scaling = (ar->scale_x != 0xFF) || (ar->scale_y != 0xFF);
x = ar->x;
y = ar->y;
if (use_scaling) {
-
+
/* Scale direction */
ar->v1.scaleXstep = -1;
if (ar->move_x_cur < 0) {
@@ -593,7 +616,7 @@ void Scumm::akos_codec1(AkosRenderer *ar) {
/* Adjust X position */
tmp_x = 0x180 - ar->move_x_cur;
j = tmp_x;
- for(i=0; i<ar->move_x_cur; i++) {
+ for (i = 0; i < ar->move_x_cur; i++) {
if (ar->v1.scaletable[j++] < ar->scale_x)
x -= ar->v1.scaleXstep;
}
@@ -601,7 +624,7 @@ void Scumm::akos_codec1(AkosRenderer *ar) {
x_left = x_right = x;
j = tmp_x;
- for(i=0,skip=0; i<ar->width; i++) {
+ for (i = 0, skip = 0; i < ar->width; i++) {
if (x_right < 0) {
skip++;
tmp_x = j;
@@ -614,7 +637,7 @@ void Scumm::akos_codec1(AkosRenderer *ar) {
/* Adjust X position */
tmp_x = 0x180 + ar->move_x_cur;
j = tmp_x;
- for(i=0; i<ar->move_x_cur; i++) {
+ for (i = 0; i < ar->move_x_cur; i++) {
if (ar->v1.scaletable[j++] < ar->scale_x)
x += ar->v1.scaleXstep;
}
@@ -622,18 +645,19 @@ void Scumm::akos_codec1(AkosRenderer *ar) {
x_left = x_right = x;
j = tmp_x;
- for(i=0,skip=0; i<ar->width; i++) {
+ for (i = 0, skip = 0; i < ar->width; i++) {
if (x_left >= (int)ar->outwidth) {
tmp_x = j;
skip++;
-
+
}
if (ar->v1.scaletable[j--] < ar->scale_x)
x_left--;
}
}
- if (skip) skip--;
+ if (skip)
+ skip--;
step = -1;
if (ar->move_y_cur < 0) {
@@ -642,14 +666,14 @@ void Scumm::akos_codec1(AkosRenderer *ar) {
}
tmp_y = 0x180 - ar->move_y_cur;
- for(i=0; i<ar->move_y_cur; i++) {
+ for (i = 0; i < ar->move_y_cur; i++) {
if (ar->v1.scaletable[tmp_y++] < ar->scale_y)
y -= step;
}
-
+
y_top = y_bottom = y;
tmp_y = 0x180 - ar->move_y_cur;
- for(i=0; i<ar->height; i++) {
+ for (i = 0; i < ar->height; i++) {
if (ar->v1.scaletable[tmp_y++] < ar->scale_y)
y_bottom++;
}
@@ -658,7 +682,7 @@ void Scumm::akos_codec1(AkosRenderer *ar) {
} else {
if (!ar->mirror)
ar->move_x_cur = -ar->move_x_cur;
-
+
x += ar->move_x_cur;
y += ar->move_y_cur;
@@ -680,12 +704,12 @@ void Scumm::akos_codec1(AkosRenderer *ar) {
ar->v1.tmp_x = tmp_x;
ar->v1.tmp_y = tmp_y;
ar->v1.skip_width = ar->width;
-
+
ar->v1.scaleXstep = -1;
if (ar->mirror)
ar->v1.scaleXstep = -ar->v1.scaleXstep;
- if ((uint)y_top >= (uint)ar->outheight || y_bottom <= 0)
+ if ((uint) y_top >= (uint) ar->outheight || y_bottom <= 0)
return;
if ((int)x_left >= (int)ar->outwidth || x_right <= 0)
@@ -693,7 +717,7 @@ void Scumm::akos_codec1(AkosRenderer *ar) {
ar->v1.replen = 0;
ar->v1.y_pitch = ar->height * ar->outwidth;
-
+
if (ar->mirror) {
ar->v1.y_pitch--;
if (!use_scaling)
@@ -726,17 +750,17 @@ void Scumm::akos_codec1(AkosRenderer *ar) {
ar->v1.x = x;
ar->v1.y = y;
- if (ar->v1.skip_width <= 0 || ar->height<=0)
+ if (ar->v1.skip_width <= 0 || ar->height <= 0)
return;
- updateDirtyRect(0, x_left, x_right, y_top, y_bottom, 1<<ar->dirty_id);
+ updateDirtyRect(0, x_left, x_right, y_top, y_bottom, 1 << ar->dirty_id);
- y_clipping = ((uint)y_bottom > ar->outheight || y_top < 0);
+ y_clipping = ((uint) y_bottom > ar->outheight || y_top < 0);
- if ( (uint)y_top > (uint)ar->outheight)
+ if ((uint) y_top > (uint) ar->outheight)
y_top = 0;
-
- if ( (uint) y_bottom > (uint)ar->outheight)
+
+ if ((uint) y_bottom > (uint) ar->outheight)
y_bottom = ar->outheight;
if (y_top < ar->draw_top)
@@ -744,7 +768,8 @@ void Scumm::akos_codec1(AkosRenderer *ar) {
if (y_bottom > ar->draw_bottom)
ar->draw_bottom = y_bottom;
- if (x==-1) x=0; /* ?? */
+ if (x == -1)
+ x = 0; /* ?? */
ar->v1.destptr = ar->outptr + x + y * ar->outwidth;
@@ -752,14 +777,17 @@ void Scumm::akos_codec1(AkosRenderer *ar) {
masking = false;
if (ar->clipping) {
masking = isMaskActiveAt(x_left, y_top, x_right, y_bottom,
- getResourceAddress(rtBuffer, 9) + gdi._imgBufOffs[ar->clipping] + _screenStartStrip
- ) != 0;
+ getResourceAddress(rtBuffer,
+ 9) +
+ gdi._imgBufOffs[ar->clipping] +
+ _screenStartStrip) != 0;
}
-
+
ar->v1.mask_ptr = NULL;
if (masking || charsetmask || ar->shadow_mode) {
- ar->v1.mask_ptr = getResourceAddress(rtBuffer, 9) + y*40 + _screenStartStrip;
+ ar->v1.mask_ptr =
+ getResourceAddress(rtBuffer, 9) + y * 40 + _screenStartStrip;
ar->v1.imgbufoffs = gdi._imgBufOffs[ar->clipping];
if (!charsetmask && masking) {
ar->v1.mask_ptr += ar->v1.imgbufoffs;
@@ -767,66 +795,89 @@ void Scumm::akos_codec1(AkosRenderer *ar) {
}
}
- switch(ar->shadow_mode) {
+ switch (ar->shadow_mode) {
case 1:
akos_c1_spec1(ar);
return;
case 2:
-// akos_c1_spec2(ar);
+// akos_c1_spec2(ar);
warning("akos_c1_spec2");
return;
case 3:
-// akos_c1_spec3(ar);
+// akos_c1_spec3(ar);
warning("akos_c1_spec3");
return;
}
akos_generic_decode(ar);
-
-// akos_c1_0y_decode(ar);
+
+// akos_c1_0y_decode(ar);
#if 0
- switch(((byte)y_clipping<<3) | ((byte)use_scaling<<2) | ((byte)masking<<1) | (byte)charsetmask) {
- case 0: akos_c1_0_decode(ar); break;
- case 0+8: akos_c1_0y_decode(ar); break;
+ switch (((byte)y_clipping << 3) | ((byte)use_scaling << 2) |
+ ((byte)masking << 1) | (byte)charsetmask) {
+ case 0:
+ akos_c1_0_decode(ar);
+ break;
+ case 0 + 8:
+ akos_c1_0y_decode(ar);
+ break;
case 2:
- case 1: akos_c1_12_decode(ar); break;
- case 2+8:
- case 1+8: akos_c1_12y_decode(ar); break;
- case 3+8:
- case 3: akos_c1_3_decode(ar); break;
- case 4: akos_c1_4_decode(ar); break;
- case 4+8: akos_c1_4y_decode(ar); break;
+ case 1:
+ akos_c1_12_decode(ar);
+ break;
+ case 2 + 8:
+ case 1 + 8:
+ akos_c1_12y_decode(ar);
+ break;
+ case 3 + 8:
+ case 3:
+ akos_c1_3_decode(ar);
+ break;
+ case 4:
+ akos_c1_4_decode(ar);
+ break;
+ case 4 + 8:
+ akos_c1_4y_decode(ar);
+ break;
case 6:
- case 5: akos_c1_56_decode(ar); break;
- case 6+8:
- case 5+8: akos_c1_56y_decode(ar); break;
+ case 5:
+ akos_c1_56_decode(ar);
+ break;
+ case 6 + 8:
+ case 5 + 8:
+ akos_c1_56y_decode(ar);
+ break;
case 7:
- case 7+8: akos_c1_7_decode(ar); break;
+ case 7 + 8:
+ akos_c1_7_decode(ar);
+ break;
}
#endif
}
-void Scumm::akos_codec1_ignorePakCols(AkosRenderer *ar, int num) {
+void Scumm::akos_codec1_ignorePakCols(AkosRenderer * ar, int num)
+{
int n;
byte repcolor;
byte replen;
byte *src;
n = ar->height;
- if (num>1) n *= num;
+ if (num > 1)
+ n *= num;
src = ar->srcptr;
do {
repcolor = *src++;
replen = repcolor & ar->v1.mask;
- if (replen==0) {
+ if (replen == 0) {
replen = *src++;
}
do {
if (!--n) {
- ar->v1.repcolor = repcolor>>ar->v1.shl;
+ ar->v1.repcolor = repcolor >> ar->v1.shl;
ar->v1.replen = replen;
ar->srcptr = src;
return;
@@ -836,16 +887,19 @@ void Scumm::akos_codec1_ignorePakCols(AkosRenderer *ar, int num) {
}
-void Scumm::akos_codec5(AkosRenderer *ar) {
+void Scumm::akos_codec5(AkosRenderer * ar)
+{
warning("akos_codec5: not implemented");
}
-void Scumm::akos_codec16(AkosRenderer *ar) {
+void Scumm::akos_codec16(AkosRenderer * ar)
+{
warning("akos_codec16: not implemented");
}
-bool Scumm::akos_increaseAnims(byte *akos, Actor *a) {
+bool Scumm::akos_increaseAnims(byte *akos, Actor * a)
+{
byte *aksq, *akfo;
int i;
uint size;
@@ -853,13 +907,13 @@ bool Scumm::akos_increaseAnims(byte *akos, Actor *a) {
aksq = findResourceData(MKID('AKSQ'), akos);
akfo = findResourceData(MKID('AKFO'), akos);
-
- size = getResourceDataSize(akfo)>>1;
-
+
+ size = getResourceDataSize(akfo) >> 1;
+
result = false;
- for(i=0;i!=0x10;i++) {
- if (a->cost.active[i]!=0)
- result|=akos_increaseAnim(a, i, aksq, (uint16*)akfo, size);
+ for (i = 0; i != 0x10; i++) {
+ if (a->cost.active[i] != 0)
+ result |= akos_increaseAnim(a, i, aksq, (uint16 *)akfo, size);
}
return result;
}
@@ -869,12 +923,14 @@ bool Scumm::akos_increaseAnims(byte *akos, Actor *a) {
#define GUW(o) READ_LE_UINT16(aksq+curpos+(o))
#define GB(o) aksq[curpos+(o)]
-bool Scumm::akos_increaseAnim(Actor *a, int chan, byte *aksq, uint16 *akfo, int numakfo) {
+bool Scumm::akos_increaseAnim(Actor * a, int chan, byte *aksq, uint16 *akfo,
+ int numakfo)
+{
byte active;
- uint old_curpos, curpos,end;
+ uint old_curpos, curpos, end;
uint code;
bool flag_value;
- int tmp,tmp2;
+ int tmp, tmp2;
active = a->cost.active[chan];
end = a->cost.end[chan];
@@ -884,11 +940,12 @@ bool Scumm::akos_increaseAnim(Actor *a, int chan, byte *aksq, uint16 *akfo, int
do {
code = aksq[curpos];
- if (code & 0x80) code = (code<<8)|aksq[curpos+1];
+ if (code & 0x80)
+ code = (code << 8) | aksq[curpos + 1];
- switch(active) {
+ switch (active) {
case 6:
- switch(code) {
+ switch (code) {
case AKC_JumpIfSet:
case AKC_AddVar:
case AKC_SetVar:
@@ -938,46 +995,48 @@ bool Scumm::akos_increaseAnim(Actor *a, int chan, byte *aksq, uint16 *akfo, int
break;
case AKC_ComplexChan:
curpos += 3;
- tmp = aksq[curpos-1];
+ tmp = aksq[curpos - 1];
while (--tmp >= 0) {
curpos += 4;
- curpos += (aksq[curpos]&0x80) ? 2 : 1;
+ curpos += (aksq[curpos] & 0x80) ? 2 : 1;
}
break;
default:
- if (code&0xC000)
+ if (code & 0xC000)
error("akos_increaseAnim: invalid code %x", code);
- curpos += (code&0x8000) ? 2 : 1;
+ curpos += (code & 0x8000) ? 2 : 1;
}
break;
case 2:
- curpos += (code&0x8000) ? 2 : 1;
+ curpos += (code & 0x8000) ? 2 : 1;
if (curpos > end)
curpos = a->cost.start[chan];
break;
case 3:
if (curpos != end)
- curpos += (code&0x8000) ? 2 : 1;
+ curpos += (code & 0x8000) ? 2 : 1;
break;
}
code = aksq[curpos];
- if (code & 0x80) code = (code<<8)|aksq[curpos+1];
+ if (code & 0x80)
+ code = (code << 8) | aksq[curpos + 1];
- if (flag_value && code!=AKC_ClearFlag)
+ if (flag_value && code != AKC_ClearFlag)
continue;
- switch(code) {
+ switch (code) {
case AKC_StartAnimInActor:
- akos_queCommand(4,
- derefActorSafe(getAnimVar(a, GB(2)), "akos_increaseAnim:29"),
- getAnimVar(a, GB(3)),
- 0
- );
+ akos_queCommand(4,
+ derefActorSafe(getAnimVar(a, GB(2)),
+ "akos_increaseAnim:29"), getAnimVar(a,
+ GB
+ (3)),
+ 0);
continue;
case AKC_Random:
- setAnimVar(a, GB(6), getRandomNumberRng(GW(2),GW(4)));
+ setAnimVar(a, GB(6), getRandomNumberRng(GW(2), GW(4)));
continue;
case AKC_SkipGE:
case AKC_SkipG:
@@ -985,24 +1044,24 @@ bool Scumm::akos_increaseAnim(Actor *a, int chan, byte *aksq, uint16 *akfo, int
case AKC_SkipL:
case AKC_SkipNE:
case AKC_SkipE:
- if ( !akos_compare(getAnimVar(a, GB(4)),GW(2), code-AKC_SkipStart) )
+ if (!akos_compare(getAnimVar(a, GB(4)), GW(2), code - AKC_SkipStart))
flag_value = true;
continue;
case AKC_IncVar:
- setAnimVar(a, 0, getAnimVar(a, 0)+1);
+ setAnimVar(a, 0, getAnimVar(a, 0) + 1);
continue;
case AKC_SetVar:
setAnimVar(a, GB(4), GW(2));
continue;
case AKC_AddVar:
- setAnimVar(a, GB(4), getAnimVar(a, GB(4)) + GW(2) );
+ setAnimVar(a, GB(4), getAnimVar(a, GB(4)) + GW(2));
continue;
case AKC_Flip:
a->flip = GW(2) != 0;
continue;
case AKC_CmdQue3:
tmp = GB(2);
- if ((uint)tmp < 8)
+ if ((uint) tmp < 8)
akos_queCommand(3, a, a->sound[tmp], 0);
continue;
case AKC_CmdQue3Quick:
@@ -1015,10 +1074,9 @@ bool Scumm::akos_increaseAnim(Actor *a, int chan, byte *aksq, uint16 *akfo, int
akos_queCommand(4, a, getAnimVar(a, GB(2)), 0);
continue;
case AKC_SetVarInActor:
- setAnimVar(
- derefActorSafe(getAnimVar(a, GB(2)),"akos_increaseAnim:9"),
- GB(3), GW(4)
- );
+ setAnimVar(derefActorSafe(getAnimVar(a, GB(2)), "akos_increaseAnim:9"),
+ GB(3), GW(4)
+ );
continue;
case AKC_HideActor:
akos_queCommand(1, a, 0, 0);
@@ -1031,19 +1089,19 @@ bool Scumm::akos_increaseAnim(Actor *a, int chan, byte *aksq, uint16 *akfo, int
if (tmp >= 8)
continue;
tmp2 = GB(4);
- if (tmp2<1 || tmp2>3)
+ if (tmp2 < 1 || tmp2 > 3)
error("akos_increaseAnim:8 invalid code %d", tmp2);
- akos_queCommand(tmp2+6, a, a->sound[tmp], GB(6));
+ akos_queCommand(tmp2 + 6, a, a->sound[tmp], GB(6));
continue;
case AKC_SetDrawOffs:
akos_queCommand(6, a, GW(2), GW(4));
continue;
case AKC_JumpTable:
- if (akfo==NULL)
+ if (akfo == NULL)
error("akos_increaseAnim: no AKFO table");
tmp = getAnimVar(a, GB(2)) - 1;
- if (tmp<0 || tmp >= numakfo-1)
- error("akos_increaseAnim: invalid jump value %d",tmp);
+ if (tmp < 0 || tmp >= numakfo - 1)
+ error("akos_increaseAnim: invalid jump value %d", tmp);
curpos = READ_LE_UINT16(&akfo[tmp]);
break;
case AKC_JumpIfSet:
@@ -1056,7 +1114,7 @@ bool Scumm::akos_increaseAnim(Actor *a, int chan, byte *aksq, uint16 *akfo, int
case AKC_ClearFlag:
flag_value = false;
continue;
-
+
case AKC_Jump:
curpos = GUW(2);
break;
@@ -1069,54 +1127,66 @@ bool Scumm::akos_increaseAnim(Actor *a, int chan, byte *aksq, uint16 *akfo, int
case AKC_Ignore2:
case AKC_Ignore3:
continue;
-
+
case AKC_JumpE:
case AKC_JumpNE:
case AKC_JumpL:
case AKC_JumpLE:
case AKC_JumpG:
case AKC_JumpGE:
- if ( !akos_compare(getAnimVar(a, GB(4)), GW(2), code - AKC_JumpStart) )
+ if (!akos_compare(getAnimVar(a, GB(4)), GW(2), code - AKC_JumpStart))
continue;
curpos = GUW(2);
break;
default:
- if ((code&0xC000)==0xC000)
+ if ((code & 0xC000) == 0xC000)
error("Undefined uSweat token %X", code);
}
break;
- } while(1);
+ } while (1);
int code2 = aksq[curpos];
- if (code2 & 0x80) code2 = (code2<<8)|aksq[curpos+1];
- assert((code2&0xC000)!=0xC000 || code2==AKC_ComplexChan || code2==AKC_Return);
+ if (code2 & 0x80)
+ code2 = (code2 << 8) | aksq[curpos + 1];
+ assert((code2 & 0xC000) != 0xC000 || code2 == AKC_ComplexChan
+ || code2 == AKC_Return);
a->cost.curpos[chan] = curpos;
return curpos != old_curpos;
}
-void Scumm::akos_queCommand(byte cmd, Actor *a, int param_1, int param_2) {
-// warning("akos_queCommand(%d,%d,%d,%d)", cmd, a->number, param_1, param_2);
+void Scumm::akos_queCommand(byte cmd, Actor * a, int param_1, int param_2)
+{
+// warning("akos_queCommand(%d,%d,%d,%d)", cmd, a->number, param_1, param_2);
}
-bool Scumm::akos_compare(int a, int b, byte cmd) {
- switch(cmd) {
- case 0: return a==b;
- case 1: return a!=b;
- case 2: return a<b;
- case 3: return a<=b;
- case 4: return a>b;
- default: return a>=b;
+bool Scumm::akos_compare(int a, int b, byte cmd)
+{
+ switch (cmd) {
+ case 0:
+ return a == b;
+ case 1:
+ return a != b;
+ case 2:
+ return a < b;
+ case 3:
+ return a <= b;
+ case 4:
+ return a > b;
+ default:
+ return a >= b;
}
}
-int Scumm::getAnimVar(Actor *a, byte var) {
+int Scumm::getAnimVar(Actor * a, byte var)
+{
return a->animVariable[var];
}
-void Scumm::setAnimVar(Actor *a, byte var, int value) {
+void Scumm::setAnimVar(Actor * a, byte var, int value)
+{
a->animVariable[var] = value;
}
diff --git a/boxes.cpp b/boxes.cpp
index d6459c7023..78ee20f48b 100644
--- a/boxes.cpp
+++ b/boxes.cpp
@@ -24,140 +24,136 @@
#include "scumm.h"
#include "math.h"
-byte Scumm::getMaskFromBox(int box) {
+byte Scumm::getMaskFromBox(int box)
+{
Box *ptr = getBoxBaseAddr(box);
if (!ptr)
return 0;
return ptr->mask;
}
-byte Scumm::getBoxFlags(int box) {
+byte Scumm::getBoxFlags(int box)
+{
Box *ptr = getBoxBaseAddr(box);
if (!ptr)
return 0;
return ptr->flags;
}
-int Scumm::getBoxScale(int box) {
- if(_features & GF_NO_SCALLING)
- return(255);
+int Scumm::getBoxScale(int box)
+{
+ if (_features & GF_NO_SCALLING)
+ return (255);
Box *ptr = getBoxBaseAddr(box);
if (!box)
return 255;
return FROM_LE_16(ptr->scale);
}
-byte Scumm::getNumBoxes() {
+byte Scumm::getNumBoxes()
+{
byte *ptr = getResourceAddress(rtMatrix, 2);
- if (!ptr) return 0;
+ if (!ptr)
+ return 0;
return ptr[0];
}
-Box *Scumm::getBoxBaseAddr(int box) {
- byte *ptr = getResourceAddress(rtMatrix, 2);
- if (!ptr)
- return NULL;
- checkRange(ptr[0]-1, 0, box, "Illegal box %d");
- if(_features & GF_SMALL_HEADER) {
- if (_features & GF_OLD256)
- return (Box*)(ptr + box*(SIZEOF_BOX-2) + 1);
+Box *Scumm::getBoxBaseAddr(int box)
+{
+ byte *ptr = getResourceAddress(rtMatrix, 2);
+ if (!ptr)
+ return NULL;
+ checkRange(ptr[0] - 1, 0, box, "Illegal box %d");
+ if (_features & GF_SMALL_HEADER) {
+ if (_features & GF_OLD256)
+ return (Box *) (ptr + box * (SIZEOF_BOX - 2) + 1);
else
- return (Box*)(ptr + box*SIZEOF_BOX + 1);
- } else
- return (Box*)(ptr + box*SIZEOF_BOX + 2);
+ return (Box *) (ptr + box * SIZEOF_BOX + 1);
+ } else
+ return (Box *) (ptr + box * SIZEOF_BOX + 2);
}
-bool Scumm::checkXYInBoxBounds(int b, int x, int y) {
+bool Scumm::checkXYInBoxBounds(int b, int x, int y)
+{
BoxCoords box;
- if (b==0 && (!(_features & GF_SMALL_HEADER)))
+ if (b == 0 && (!(_features & GF_SMALL_HEADER)))
return 0;
getBoxCoordinates(b, &box);
- if (x < box.ul.x && x < box.ur.x &&
- x < box.ll.x && x < box.lr.x)
- return 0;
-
- if (x > box.ul.x && x > box.ur.x &&
- x > box.ll.x && x > box.lr.x)
- return 0;
-
- if (y < box.ul.y && y < box.ur.y &&
- y < box.ll.y && y < box.lr.y)
- return 0;
-
- if (y > box.ul.y && y > box.ur.y &&
- y > box.ll.y && y > box.lr.y)
- return 0;
-
+ if (x < box.ul.x && x < box.ur.x && x < box.ll.x && x < box.lr.x)
+ return 0;
+
+ if (x > box.ul.x && x > box.ur.x && x > box.ll.x && x > box.lr.x)
+ return 0;
+
+ if (y < box.ul.y && y < box.ur.y && y < box.ll.y && y < box.lr.y)
+ return 0;
+
+ if (y > box.ul.y && y > box.ur.y && y > box.ll.y && y > box.lr.y)
+ return 0;
+
if (box.ul.x == box.ur.x &&
- box.ul.y == box.ur.y &&
- box.ll.x == box.lr.x &&
- box.ll.y == box.lr.y ||
- box.ul.x == box.lr.x &&
- box.ul.y == box.lr.y &&
- box.ur.x== box.ll.x &&
- box.ur.y== box.ll.y) {
+ box.ul.y == box.ur.y &&
+ box.ll.x == box.lr.x &&
+ box.ll.y == box.lr.y ||
+ box.ul.x == box.lr.x &&
+ box.ul.y == box.lr.y && box.ur.x == box.ll.x && box.ur.y == box.ll.y) {
ScummPoint pt;
pt = closestPtOnLine(box.ul.x, box.ul.y, box.ll.x, box.ll.y, x, y);
- if (distanceFromPt(x, y, pt.x,pt.y) <= 4)
+ if (distanceFromPt(x, y, pt.x, pt.y) <= 4)
return 1;
}
-
- if (!getSideOfLine(
- box.ul.x, box.ul.y, box.ur.x, box.ur.y, x,y,b))
- return 0;
-
- if (!getSideOfLine(
- box.ur.x, box.ur.y, box.ll.x, box.ll.y, x,y,b))
- return 0;
-
- if (!getSideOfLine(
- box.ll.x, box.ll.y, box.lr.x, box.lr.y, x,y,b))
- return 0;
-
- if (!getSideOfLine(
- box.lr.x, box.lr.y, box.ul.x, box.ul.y, x,y,b))
- return 0;
+
+ if (!getSideOfLine(box.ul.x, box.ul.y, box.ur.x, box.ur.y, x, y, b))
+ return 0;
+
+ if (!getSideOfLine(box.ur.x, box.ur.y, box.ll.x, box.ll.y, x, y, b))
+ return 0;
+
+ if (!getSideOfLine(box.ll.x, box.ll.y, box.lr.x, box.lr.y, x, y, b))
+ return 0;
+
+ if (!getSideOfLine(box.lr.x, box.lr.y, box.ul.x, box.ul.y, x, y, b))
+ return 0;
return 1;
}
-void Scumm::getBoxCoordinates(int boxnum, BoxCoords *box) {
+void Scumm::getBoxCoordinates(int boxnum, BoxCoords * box)
+{
Box *bp = getBoxBaseAddr(boxnum);
- box->ul.x = (int16)FROM_LE_16(bp->ulx);
- box->ul.y = (int16)FROM_LE_16(bp->uly);
- box->ur.x = (int16)FROM_LE_16(bp->urx);
- box->ur.y = (int16)FROM_LE_16(bp->ury);
-
- if(_features & GF_OLD256)
- {
- box->ll.x = (int16)FROM_LE_16(bp->lrx);
- box->ll.y = (int16)FROM_LE_16(bp->lry);
- box->lr.x = (int16)FROM_LE_16(bp->llx);
- box->lr.y = (int16)FROM_LE_16(bp->lly);
- }
- else
- {
- box->ll.x = (int16)FROM_LE_16(bp->llx);
- box->ll.y = (int16)FROM_LE_16(bp->lly);
- box->lr.x = (int16)FROM_LE_16(bp->lrx);
- box->lr.y = (int16)FROM_LE_16(bp->lry);
+ box->ul.x = (int16) FROM_LE_16(bp->ulx);
+ box->ul.y = (int16) FROM_LE_16(bp->uly);
+ box->ur.x = (int16) FROM_LE_16(bp->urx);
+ box->ur.y = (int16) FROM_LE_16(bp->ury);
+
+ if (_features & GF_OLD256) {
+ box->ll.x = (int16) FROM_LE_16(bp->lrx);
+ box->ll.y = (int16) FROM_LE_16(bp->lry);
+ box->lr.x = (int16) FROM_LE_16(bp->llx);
+ box->lr.y = (int16) FROM_LE_16(bp->lly);
+ } else {
+ box->ll.x = (int16) FROM_LE_16(bp->llx);
+ box->ll.y = (int16) FROM_LE_16(bp->lly);
+ box->lr.x = (int16) FROM_LE_16(bp->lrx);
+ box->lr.y = (int16) FROM_LE_16(bp->lry);
}
-
+
}
-uint Scumm::distanceFromPt(int x, int y, int ptx, int pty) {
+uint Scumm::distanceFromPt(int x, int y, int ptx, int pty)
+{
int diffx, diffy;
-
- diffx = abs(ptx-x);
+
+ diffx = abs(ptx - x);
if (diffx >= 0x100)
return 0xFFFF;
-
+
diffy = abs(pty - y);
if (diffy >= 0x100)
@@ -167,20 +163,24 @@ uint Scumm::distanceFromPt(int x, int y, int ptx, int pty) {
return diffx + diffy;
}
-bool Scumm::getSideOfLine(int x1,int y1, int x2, int y2, int x, int y, int box) {
- return (x-x1)*(y2-y1) <= (y-y1)*(x2-x1);
+bool Scumm::getSideOfLine(int x1, int y1, int x2, int y2, int x, int y,
+ int box)
+{
+ return (x - x1) * (y2 - y1) <= (y - y1) * (x2 - x1);
}
-ScummPoint Scumm::closestPtOnLine(int ulx, int uly, int llx, int lly, int x, int y) {
- int lydiff,lxdiff;
- int32 dist,a,b,c;
- int x2,y2;
+ScummPoint Scumm::closestPtOnLine(int ulx, int uly, int llx, int lly, int x,
+ int y)
+{
+ int lydiff, lxdiff;
+ int32 dist, a, b, c;
+ int x2, y2;
ScummPoint pt;
- if (llx==ulx) {
+ if (llx == ulx) {
x2 = ulx;
y2 = y;
- } else if (lly==uly) {
+ } else if (lly == uly) {
x2 = x;
y2 = uly;
} else {
@@ -203,7 +203,7 @@ ScummPoint Scumm::closestPtOnLine(int ulx, int uly, int llx, int lly, int x, int
a = uly * lxdiff / lydiff;
b = y * lydiff / lxdiff;
-
+
c = (a + b - ulx + x) * lydiff * lxdiff / dist;
y2 = c;
@@ -217,25 +217,31 @@ ScummPoint Scumm::closestPtOnLine(int ulx, int uly, int llx, int lly, int x, int
if (abs(lydiff) < abs(lxdiff)) {
if (lxdiff > 0) {
if (x2 < ulx) {
-type1:;
+ type1:;
x2 = ulx;
y2 = uly;
} else if (x2 > llx) {
-type2:;
+ type2:;
x2 = llx;
y2 = lly;
}
} else {
- if (x2 > ulx) goto type1;
- if (x2 < llx) goto type2;
+ if (x2 > ulx)
+ goto type1;
+ if (x2 < llx)
+ goto type2;
}
} else {
if (lydiff > 0) {
- if (y2 < uly) goto type1;
- if (y2 > lly) goto type2;
+ if (y2 < uly)
+ goto type1;
+ if (y2 > lly)
+ goto type2;
} else {
- if (y2 > uly) goto type1;
- if (y2 < lly) goto type2;
+ if (y2 > uly)
+ goto type1;
+ if (y2 < lly)
+ goto type2;
}
}
@@ -244,48 +250,46 @@ type2:;
return pt;
}
-bool Scumm::inBoxQuickReject(int b, int x, int y, int threshold) {
+bool Scumm::inBoxQuickReject(int b, int x, int y, int threshold)
+{
int t;
BoxCoords box;
getBoxCoordinates(b, &box);
- if (threshold==0)
+ if (threshold == 0)
return 1;
-
+
t = x - threshold;
- if (t > box.ul.x && t > box.ur.x &&
- t > box.ll.x && t > box.lr.x)
- return 0;
-
+ if (t > box.ul.x && t > box.ur.x && t > box.ll.x && t > box.lr.x)
+ return 0;
+
t = x + threshold;
- if (t < box.ul.x && t < box.ur.x &&
- t < box.ll.x && t < box.lr.x)
- return 0;
-
+ if (t < box.ul.x && t < box.ur.x && t < box.ll.x && t < box.lr.x)
+ return 0;
+
t = y - threshold;
- if (t > box.ul.y && t > box.ur.y &&
- t > box.ll.y && t > box.lr.y)
- return 0;
-
+ if (t > box.ul.y && t > box.ur.y && t > box.ll.y && t > box.lr.y)
+ return 0;
+
t = y + threshold;
- if (t < box.ul.y && t < box.ur.y &&
- t < box.ll.y && t < box.lr.y)
- return 0;
+ if (t < box.ul.y && t < box.ur.y && t < box.ll.y && t < box.lr.y)
+ return 0;
return 1;
}
-AdjustBoxResult Scumm::getClosestPtOnBox(int b, int x, int y) {
+AdjustBoxResult Scumm::getClosestPtOnBox(int b, int x, int y)
+{
ScummPoint pt;
AdjustBoxResult best;
uint dist;
- uint bestdist = (uint)0xFFFF;
+ uint bestdist = (uint) 0xFFFF;
BoxCoords box;
getBoxCoordinates(b, &box);
- pt = closestPtOnLine(box.ul.x,box.ul.y,box.ur.x,box.ur.y,x,y);
+ pt = closestPtOnLine(box.ul.x, box.ul.y, box.ur.x, box.ur.y, x, y);
dist = distanceFromPt(x, y, pt.x, pt.y);
if (dist < bestdist) {
bestdist = dist;
@@ -293,7 +297,7 @@ AdjustBoxResult Scumm::getClosestPtOnBox(int b, int x, int y) {
best.y = pt.y;
}
- pt = closestPtOnLine(box.ur.x,box.ur.y,box.ll.x,box.ll.y,x,y);
+ pt = closestPtOnLine(box.ur.x, box.ur.y, box.ll.x, box.ll.y, x, y);
dist = distanceFromPt(x, y, pt.x, pt.y);
if (dist < bestdist) {
bestdist = dist;
@@ -301,7 +305,7 @@ AdjustBoxResult Scumm::getClosestPtOnBox(int b, int x, int y) {
best.y = pt.y;
}
- pt = closestPtOnLine(box.ll.x,box.ll.y,box.lr.x,box.lr.y,x,y);
+ pt = closestPtOnLine(box.ll.x, box.ll.y, box.lr.x, box.lr.y, x, y);
dist = distanceFromPt(x, y, pt.x, pt.y);
if (dist < bestdist) {
bestdist = dist;
@@ -309,34 +313,37 @@ AdjustBoxResult Scumm::getClosestPtOnBox(int b, int x, int y) {
best.y = pt.y;
}
- pt = closestPtOnLine(box.lr.x,box.lr.y,box.ul.x,box.ul.y,x,y);
+ pt = closestPtOnLine(box.lr.x, box.lr.y, box.ul.x, box.ul.y, x, y);
dist = distanceFromPt(x, y, pt.x, pt.y);
if (dist < bestdist) {
bestdist = dist;
best.x = pt.x;
best.y = pt.y;
}
-
+
best.dist = bestdist;
return best;
}
-byte *Scumm::getBoxMatrixBaseAddr() {
+byte *Scumm::getBoxMatrixBaseAddr()
+{
byte *ptr = getResourceAddress(rtMatrix, 1);
- if (*ptr==0xFF) ptr++;
+ if (*ptr == 0xFF)
+ ptr++;
return ptr;
}
-int Scumm::getPathToDestBox(byte from, byte to) {
+int Scumm::getPathToDestBox(byte from, byte to)
+{
byte *boxm;
byte i;
- if (from==to)
+ if (from == to)
return to;
-
+
boxm = getBoxMatrixBaseAddr();
- i=0;
+ i = 0;
while (i != from) {
while (*boxm != 0xFF)
boxm += 3;
@@ -344,30 +351,30 @@ int Scumm::getPathToDestBox(byte from, byte to) {
boxm++;
}
- while (boxm[0]!=0xFF) {
- if (boxm[0] <= to && boxm[1]>=to)
+ while (boxm[0] != 0xFF) {
+ if (boxm[0] <= to && boxm[1] >= to)
return boxm[2];
- boxm+=3;
+ boxm += 3;
}
return -1;
}
-int Scumm::findPathTowards(Actor *a, byte box1nr, byte box2nr, byte box3nr) {
+int Scumm::findPathTowards(Actor * a, byte box1nr, byte box2nr, byte box3nr)
+{
BoxCoords box1;
BoxCoords box2;
ScummPoint tmp;
- int i,j;
+ int i, j;
int flag;
- int q,pos;
+ int q, pos;
- getBoxCoordinates(box1nr,&box1);
- getBoxCoordinates(box2nr,&box2);
+ getBoxCoordinates(box1nr, &box1);
+ getBoxCoordinates(box2nr, &box2);
- for(i=0; i<4; i++) {
- for(j=0; j<4; j++) {
- if (box1.ul.x==box1.ur.x &&
- box1.ul.x==box2.ul.x &&
- box1.ul.x==box2.ur.x) {
+ for (i = 0; i < 4; i++) {
+ for (j = 0; j < 4; j++) {
+ if (box1.ul.x == box1.ur.x &&
+ box1.ul.x == box2.ul.x && box1.ul.x == box2.ur.x) {
flag = 0;
if (box1.ul.y > box1.ur.y) {
SWAP(box1.ul.y, box1.ur.y);
@@ -380,24 +387,25 @@ int Scumm::findPathTowards(Actor *a, byte box1nr, byte box2nr, byte box3nr) {
}
if (box1.ul.y > box2.ur.y || box2.ul.y > box1.ur.y ||
- (box1.ur.y==box2.ul.y || box2.ur.y==box1.ul.y) &&
- box1.ul.y!=box1.ur.y && box2.ul.y!=box2.ur.y) {
- if (flag&1)
+ (box1.ur.y == box2.ul.y || box2.ur.y == box1.ul.y) &&
+ box1.ul.y != box1.ur.y && box2.ul.y != box2.ur.y) {
+ if (flag & 1)
SWAP(box1.ul.y, box1.ur.y);
- if (flag&2)
+ if (flag & 2)
SWAP(box2.ul.y, box2.ur.y);
} else {
if (box2nr == box3nr) {
int diffX = a->walkdata.destx - a->x;
int diffY = a->walkdata.desty - a->y;
int boxDiffX = box1.ul.x - a->x;
-
- if (diffX!=0) {
+
+ if (diffX != 0) {
int t;
diffY *= boxDiffX;
t = diffY / diffX;
- if (t==0 && (diffY<=0 || diffX<=0) && (diffY>=0 || diffX>=0))
+ if (t == 0 && (diffY <= 0 || diffX <= 0)
+ && (diffY >= 0 || diffX >= 0))
t = -1;
pos = a->y + t;
} else {
@@ -409,14 +417,14 @@ int Scumm::findPathTowards(Actor *a, byte box1nr, byte box2nr, byte box3nr) {
q = pos;
if (q < box2.ul.y)
- q = box2.ul.y;
+ q = box2.ul.y;
if (q > box2.ur.y)
q = box2.ur.y;
if (q < box1.ul.y)
q = box1.ul.y;
if (q > box1.ur.y)
q = box1.ur.y;
- if (q==pos && box2nr==box3nr)
+ if (q == pos && box2nr == box3nr)
return 1;
_foundPathY = q;
_foundPathX = box1.ul.x;
@@ -424,9 +432,8 @@ int Scumm::findPathTowards(Actor *a, byte box1nr, byte box2nr, byte box3nr) {
}
}
- if (box1.ul.y==box1.ur.y &&
- box1.ul.y==box2.ul.y &&
- box1.ul.y==box2.ur.y) {
+ if (box1.ul.y == box1.ur.y &&
+ box1.ul.y == box2.ul.y && box1.ul.y == box2.ur.y) {
flag = 0;
if (box1.ul.x > box1.ur.x) {
SWAP(box1.ul.x, box1.ur.x);
@@ -439,11 +446,11 @@ int Scumm::findPathTowards(Actor *a, byte box1nr, byte box2nr, byte box3nr) {
}
if (box1.ul.x > box2.ur.x || box2.ul.x > box1.ur.x ||
- (box1.ur.x==box2.ul.x || box2.ur.x==box1.ul.x) &&
- box1.ul.x!=box1.ur.x && box2.ul.x!=box2.ur.x) {
- if (flag&1)
+ (box1.ur.x == box2.ul.x || box2.ur.x == box1.ul.x) &&
+ box1.ul.x != box1.ur.x && box2.ul.x != box2.ur.x) {
+ if (flag & 1)
SWAP(box1.ul.x, box1.ur.x);
- if (flag&2)
+ if (flag & 2)
SWAP(box2.ul.x, box2.ur.x);
} else {
@@ -451,9 +458,9 @@ int Scumm::findPathTowards(Actor *a, byte box1nr, byte box2nr, byte box3nr) {
int diffX = a->walkdata.destx - a->x;
int diffY = a->walkdata.desty - a->y;
int boxDiffY = box1.ul.y - a->y;
-
+
pos = a->x;
- if (diffY!=0) {
+ if (diffY != 0) {
pos += diffX * boxDiffY / diffY;
}
} else {
@@ -469,7 +476,7 @@ int Scumm::findPathTowards(Actor *a, byte box1nr, byte box2nr, byte box3nr) {
q = box1.ul.x;
if (q > box1.ur.x)
q = box1.ur.x;
- if (q==pos && box2nr==box3nr)
+ if (q == pos && box2nr == box3nr)
return 1;
_foundPathX = q;
_foundPathY = box1.ul.y;
@@ -490,10 +497,11 @@ int Scumm::findPathTowards(Actor *a, byte box1nr, byte box2nr, byte box3nr) {
}
return 0;
}
-void Scumm::setBoxFlags(int box, int val) {
+void Scumm::setBoxFlags(int box, int val)
+{
/* FULL_THROTTLE stuff */
if (val & 0xC000) {
- assert(box>=0 && box<65);
+ assert(box >= 0 && box < 65);
_extraBoxFlags[box] = val;
} else {
Box *b = getBoxBaseAddr(box);
@@ -501,28 +509,30 @@ void Scumm::setBoxFlags(int box, int val) {
}
}
-void Scumm::setBoxScale(int box, int scale) {
+void Scumm::setBoxScale(int box, int scale)
+{
Box *b = getBoxBaseAddr(box);
b->scale = scale;
}
#define BOX_MATRIX_SIZE 2000
-void Scumm::createBoxMatrix() {
+void Scumm::createBoxMatrix()
+{
byte *matrix_ptr;
- int num,i,j;
+ int num, i, j;
byte flags;
- int table_1[66],table_2[66];
- int counter,val;
+ int table_1[66], table_2[66];
+ int counter, val;
int code;
PathVertex *vtx;
- PathNode *node, *node2=NULL;
+ PathNode *node, *node2 = NULL;
_maxBoxVertexHeap = 1000;
createResource(rtMatrix, 4, 1000);
- createResource(rtMatrix, 3, 4160); //65 items of something of size 64
+ createResource(rtMatrix, 3, 4160); //65 items of something of size 64
createResource(rtMatrix, 1, BOX_MATRIX_SIZE);
matrix_ptr = getResourceAddress(rtMatrix, 1);
@@ -532,22 +542,22 @@ void Scumm::createBoxMatrix() {
_boxMatrixPtr3 = getResourceAddress(rtMatrix, 3);
_boxPathVertexHeapIndex = _boxMatrixItem = 0;
-
+
num = getNumBoxes();
- for (i=0; i<num; i++) {
- for (j=0; j<num; j++) {
- if (i==j) {
- _boxMatrixPtr3[i*64+j] = 0;
+ for (i = 0; i < num; i++) {
+ for (j = 0; j < num; j++) {
+ if (i == j) {
+ _boxMatrixPtr3[i * 64 + j] = 0;
} else if (areBoxesNeighbours(i, j)) {
- _boxMatrixPtr3[i*64+j] = 1;
+ _boxMatrixPtr3[i * 64 + j] = 1;
} else {
- _boxMatrixPtr3[i*64+j] = 250;
+ _boxMatrixPtr3[i * 64 + j] = 250;
}
}
}
- for (j=0; j<num; j++) {
+ for (j = 0; j < num; j++) {
flags = getBoxFlags(j);
if (flags & 0x80) {
addToBoxMatrix(0xFF);
@@ -556,11 +566,11 @@ void Scumm::createBoxMatrix() {
addToBoxMatrix(j);
} else {
vtx = addPathVertex();
- for (i=0; i<num; i++) {
+ for (i = 0; i < num; i++) {
flags = getBoxFlags(j);
- if (!(flags&0x80)) {
+ if (!(flags & 0x80)) {
node = unkMatrixProc2(vtx, i);
- if (i==j)
+ if (i == j)
node2 = node;
}
}
@@ -571,24 +581,25 @@ void Scumm::createBoxMatrix() {
counter = 250;
while (node) {
- val = _boxMatrixPtr3[j*64 + node->index];
+ val = _boxMatrixPtr3[j * 64 + node->index];
table_1[node->index] = val;
- if (val<counter) counter=val;
-
- if (table_1[node->index]!=250)
+ if (val < counter)
+ counter = val;
+
+ if (table_1[node->index] != 250)
table_2[node->index] = node->index;
else
table_2[node->index] = -1;
node = node->left;
}
-
+
while (vtx) {
counter = 250;
node2 = node = vtx->left;
while (node) {
- if ( table_1[node->index] < counter ) {
+ if (table_1[node->index] < counter) {
counter = table_1[node->index];
node2 = node;
}
@@ -608,25 +619,25 @@ void Scumm::createBoxMatrix() {
}
addToBoxMatrix(0xFF);
- for (i=1; i<num;) {
- if (table_2[i-1]!=-1) {
- addToBoxMatrix(i-1); /* lo */
- if (table_2[i-1] != table_2[i]) {
- addToBoxMatrix(i-1); /* hi */
- addToBoxMatrix(table_2[i-1]); /* dst */
+ for (i = 1; i < num;) {
+ if (table_2[i - 1] != -1) {
+ addToBoxMatrix(i - 1); /* lo */
+ if (table_2[i - 1] != table_2[i]) {
+ addToBoxMatrix(i - 1); /* hi */
+ addToBoxMatrix(table_2[i - 1]); /* dst */
} else {
- while (table_2[i-1] == table_2[i]) {
- if (++i==num)
+ while (table_2[i - 1] == table_2[i]) {
+ if (++i == num)
break;
}
- addToBoxMatrix(i-1); /* hi */
- addToBoxMatrix(table_2[i-1]); /* dst */
+ addToBoxMatrix(i - 1); /* hi */
+ addToBoxMatrix(table_2[i - 1]); /* dst */
}
}
- if (++i==num && table_2[i-1]!=-1) {
- addToBoxMatrix(i-1); /* lo */
- addToBoxMatrix(i-1); /* hi */
- addToBoxMatrix(table_2[i-1]); /* dest */
+ if (++i == num && table_2[i - 1] != -1) {
+ addToBoxMatrix(i - 1); /* lo */
+ addToBoxMatrix(i - 1); /* hi */
+ addToBoxMatrix(table_2[i - 1]); /* dest */
}
}
}
@@ -637,8 +648,9 @@ void Scumm::createBoxMatrix() {
nukeResource(rtMatrix, 3);
}
-PathVertex *Scumm::unkMatrixProc1(PathVertex *vtx, PathNode *node) {
- if (node==NULL || vtx==NULL)
+PathVertex *Scumm::unkMatrixProc1(PathVertex * vtx, PathNode * node)
+{
+ if (node == NULL || vtx == NULL)
return NULL;
if (!node->right) {
@@ -659,23 +671,24 @@ PathVertex *Scumm::unkMatrixProc1(PathVertex *vtx, PathNode *node) {
return NULL;
}
-PathNode *Scumm::unkMatrixProc2(PathVertex *vtx, int i) {
+PathNode *Scumm::unkMatrixProc2(PathVertex * vtx, int i)
+{
PathNode *node;
- if (vtx==NULL)
+ if (vtx == NULL)
return NULL;
if (!vtx->right) {
- node = (PathNode*)addToBoxVertexHeap(sizeof(PathNode));
+ node = (PathNode *) addToBoxVertexHeap(sizeof(PathNode));
vtx->left = vtx->right = node;
node->index = i;
node->left = 0;
node->right = 0;
} else {
- node = (PathNode*)addToBoxVertexHeap(sizeof(PathNode));
+ node = (PathNode *) addToBoxVertexHeap(sizeof(PathNode));
vtx->right->left = node;
-
+
node->right = vtx->right;
node->index = i;
node->left = 0;
@@ -687,28 +700,28 @@ PathNode *Scumm::unkMatrixProc2(PathVertex *vtx, int i) {
}
/* Check if two boxes are neighbours */
-bool Scumm::areBoxesNeighbours(int box1nr, int box2nr) {
- int j,k,m,n;
+bool Scumm::areBoxesNeighbours(int box1nr, int box2nr)
+{
+ int j, k, m, n;
int tmp_x, tmp_y;
bool result;
BoxCoords box;
BoxCoords box2;
- if (getBoxFlags(box1nr)&0x80 || getBoxFlags(box2nr)&0x80)
+ if (getBoxFlags(box1nr) & 0x80 || getBoxFlags(box2nr) & 0x80)
return false;
getBoxCoordinates(box1nr, &box2);
getBoxCoordinates(box2nr, &box);
-
+
result = false;
j = 4;
-
+
do {
k = 4;
do {
if (box2.ur.x == box2.ul.x &&
- box.ul.x == box2.ul.x &&
- box.ur.x == box2.ur.x) {
+ box.ul.x == box2.ul.x && box.ur.x == box2.ur.x) {
n = m = 0;
if (box2.ur.y < box2.ul.y) {
n = 1;
@@ -719,11 +732,10 @@ bool Scumm::areBoxesNeighbours(int box1nr, int box2nr) {
SWAP(box.ur.y, box.ul.y);
}
if (box.ur.y < box2.ul.y ||
- box.ul.y > box2.ur.y ||
+ box.ul.y > box2.ur.y ||
(box.ul.y == box2.ur.y ||
- box.ur.y==box2.ul.y) &&
- box2.ur.y != box2.ul.y &&
- box.ul.y!=box.ur.y) {
+ box.ur.y == box2.ul.y) &&
+ box2.ur.y != box2.ul.y && box.ul.y != box.ur.y) {
if (n) {
SWAP(box2.ur.y, box2.ul.y);
}
@@ -738,12 +750,11 @@ bool Scumm::areBoxesNeighbours(int box1nr, int box2nr) {
SWAP(box.ur.y, box.ul.y);
}
result = true;
- }
+ }
}
- if (box2.ur.y == box2.ul.y &&
- box.ul.y == box2.ul.y &&
- box.ur.y == box2.ur.y) {
+ if (box2.ur.y == box2.ul.y &&
+ box.ul.y == box2.ul.y && box.ur.y == box2.ur.y) {
n = m = 0;
if (box2.ur.x < box2.ul.x) {
n = 1;
@@ -754,11 +765,10 @@ bool Scumm::areBoxesNeighbours(int box1nr, int box2nr) {
SWAP(box.ur.x, box.ul.x);
}
if (box.ur.x < box2.ul.x ||
- box.ul.x > box2.ur.x ||
+ box.ul.x > box2.ur.x ||
(box.ul.x == box2.ur.x ||
- box.ur.x==box2.ul.x) &&
- box2.ur.x != box2.ul.x &&
- box.ul.x!=box.ur.x) {
+ box.ur.x == box2.ul.x) &&
+ box2.ur.x != box2.ul.x && box.ul.x != box.ur.x) {
if (n) {
SWAP(box2.ur.x, box2.ul.x);
@@ -776,7 +786,7 @@ bool Scumm::areBoxesNeighbours(int box1nr, int box2nr) {
result = true;
}
}
-
+
tmp_x = box2.ul.x;
tmp_y = box2.ul.y;
box2.ul.x = box2.ur.x;
@@ -788,7 +798,7 @@ bool Scumm::areBoxesNeighbours(int box1nr, int box2nr) {
box2.lr.x = tmp_x;
box2.lr.y = tmp_y;
} while (--k);
-
+
tmp_x = box.ul.x;
tmp_y = box.ul.y;
box.ul.x = box.ur.x;
@@ -804,13 +814,15 @@ bool Scumm::areBoxesNeighbours(int box1nr, int box2nr) {
return result;
}
-void Scumm::addToBoxMatrix(byte b) {
+void Scumm::addToBoxMatrix(byte b)
+{
if (++_boxMatrixItem > BOX_MATRIX_SIZE)
error("Box matrix overflow");
*_boxMatrixPtr1++ = b;
}
-void *Scumm::addToBoxVertexHeap(int size) {
+void *Scumm::addToBoxVertexHeap(int size)
+{
byte *ptr = _boxMatrixPtr4;
_boxMatrixPtr4 += size;
@@ -822,184 +834,188 @@ void *Scumm::addToBoxVertexHeap(int size) {
return ptr;
}
-PathVertex *Scumm::addPathVertex() {
+PathVertex *Scumm::addPathVertex()
+{
_boxMatrixPtr4 = getResourceAddress(rtMatrix, 4);
_boxPathVertexHeapIndex = 0;
- return (PathVertex*)addToBoxVertexHeap(sizeof(PathVertex));
+ return (PathVertex *) addToBoxVertexHeap(sizeof(PathVertex));
}
-int Scumm::findPathTowardsOld(Actor *a, byte trap1, byte trap2, byte final_trap)
+int Scumm::findPathTowardsOld(Actor * a, byte trap1, byte trap2,
+ byte final_trap)
{
- GetGates(trap1,trap2);
+ GetGates(trap1, trap2);
ScummPoint pt;
- p[1].x = actor->x;
- p[1].y = actor->y;
- p[2].x = 32000;
- p[3].x = 32000;
- p[4].x = 32000;
-
- if (trap2 == final_trap) { /* next = final box? */
- p[4].x = actor->walkdata.destx;
- p[4].y = actor->walkdata.desty;
-
- if (getMaskFromBox(trap1) == getMaskFromBox(trap2) || 1) {
- if (CompareSlope(p[1].x,p[1].y,p[4].x,p[4].y, gate1ax,gate1ay) !=
- CompareSlope(p[1].x,p[1].y,p[4].x,p[4].y, gate1bx,gate1by) &&
- CompareSlope(p[1].x,p[1].y,p[4].x,p[4].y, gate2ax,gate2ay) !=
- CompareSlope(p[1].x,p[1].y,p[4].x,p[4].y, gate2bx,gate2by)) {
- return 0; /* same zplane and between both gates? */
- }
- }
- }
-
- pt=closestPtOnLine(gate2ax,gate2ay,gate2bx,gate2by,p[1].x,p[1].y);
- p[3].x = pt.x;
- p[3].y = pt.y;
-
- if (CompareSlope(p[1].x,p[1].y,p[3].x,p[3].y, gate1ax,gate1ay) ==
- CompareSlope(p[1].x,p[1].y,p[3].x,p[3].y, gate1bx,gate1by)) {
- closestPtOnLine(gate1ax,gate1ay,gate1bx,gate1by,p[1].x,p[1].y);
- p[2].x = pt.x; /* if point 2 between gates, ignore! */
- p[2].y = pt.y;
- }
-
- return 0;
+ p[1].x = actor->x;
+ p[1].y = actor->y;
+ p[2].x = 32000;
+ p[3].x = 32000;
+ p[4].x = 32000;
+
+ if (trap2 == final_trap) { /* next = final box? */
+ p[4].x = actor->walkdata.destx;
+ p[4].y = actor->walkdata.desty;
+
+ if (getMaskFromBox(trap1) == getMaskFromBox(trap2) || 1) {
+ if (CompareSlope(p[1].x, p[1].y, p[4].x, p[4].y, gate1ax, gate1ay) !=
+ CompareSlope(p[1].x, p[1].y, p[4].x, p[4].y, gate1bx, gate1by) &&
+ CompareSlope(p[1].x, p[1].y, p[4].x, p[4].y, gate2ax, gate2ay) !=
+ CompareSlope(p[1].x, p[1].y, p[4].x, p[4].y, gate2bx, gate2by)) {
+ return 0; /* same zplane and between both gates? */
+ }
+ }
+ }
+
+ pt = closestPtOnLine(gate2ax, gate2ay, gate2bx, gate2by, p[1].x, p[1].y);
+ p[3].x = pt.x;
+ p[3].y = pt.y;
+
+ if (CompareSlope(p[1].x, p[1].y, p[3].x, p[3].y, gate1ax, gate1ay) ==
+ CompareSlope(p[1].x, p[1].y, p[3].x, p[3].y, gate1bx, gate1by)) {
+ closestPtOnLine(gate1ax, gate1ay, gate1bx, gate1by, p[1].x, p[1].y);
+ p[2].x = pt.x; /* if point 2 between gates, ignore! */
+ p[2].y = pt.y;
+ }
+
+ return 0;
}
-void Scumm::GetGates(int trap1,int trap2) {
-int i;
-int Closest1=0,Closest2=0,Closest3=0;
-int Dist[8];
-int Dist1,Dist2,Dist3;
-int Box1,Box2,Box3;
-BoxCoords box;
-int polyx[8];
-int polyy[8];
-AdjustBoxResult pt;
-
- getBoxCoordinates(trap1,&box);
- polyx[0] = box.ul.x;
- polyy[0] = box.ul.y;
- polyx[1] = box.ur.x;
- polyy[1] = box.ur.y;
- polyx[2] = box.ll.x;
- polyy[2] = box.ll.y;
- polyx[3] = box.lr.x;
- polyy[3] = box.lr.y;
- for (i = 0 ; i < 4 ; i++) {
- pt = getClosestPtOnBox(trap2,polyx[i],polyy[i]);
+void Scumm::GetGates(int trap1, int trap2)
+{
+ int i;
+ int Closest1 = 0, Closest2 = 0, Closest3 = 0;
+ int Dist[8];
+ int Dist1, Dist2, Dist3;
+ int Box1, Box2, Box3;
+ BoxCoords box;
+ int polyx[8];
+ int polyy[8];
+ AdjustBoxResult pt;
+
+ getBoxCoordinates(trap1, &box);
+ polyx[0] = box.ul.x;
+ polyy[0] = box.ul.y;
+ polyx[1] = box.ur.x;
+ polyy[1] = box.ur.y;
+ polyx[2] = box.ll.x;
+ polyy[2] = box.ll.y;
+ polyx[3] = box.lr.x;
+ polyy[3] = box.lr.y;
+ for (i = 0; i < 4; i++) {
+ pt = getClosestPtOnBox(trap2, polyx[i], polyy[i]);
+ Dist[i] = pt.dist;
+ CloX[i] = pt.x;
+ CloY[i] = pt.y;
+ }
+
+ getBoxCoordinates(trap2, &box);
+ polyx[4] = box.ul.x;
+ polyy[4] = box.ul.y;
+ polyx[5] = box.ur.x;
+ polyy[5] = box.ur.y;
+ polyx[6] = box.ll.x;
+ polyy[6] = box.ll.y;
+ polyx[7] = box.lr.x;
+ polyy[7] = box.lr.y;
+ for (i = 4; i < 8; i++) {
+ pt = getClosestPtOnBox(trap1, polyx[i], polyy[i]);
Dist[i] = pt.dist;
- CloX[i] = pt.x;
- CloY[i] = pt.y;
- }
-
- getBoxCoordinates(trap2,&box);
- polyx[4] = box.ul.x;
- polyy[4] = box.ul.y;
- polyx[5] = box.ur.x;
- polyy[5] = box.ur.y;
- polyx[6] = box.ll.x;
- polyy[6] = box.ll.y;
- polyx[7] = box.lr.x;
- polyy[7] = box.lr.y;
- for (i = 4 ; i < 8 ; i++) {
- pt = getClosestPtOnBox(trap1,polyx[i],polyy[i]);
- Dist[i] = pt.dist;
- CloX[i] = pt.x;
- CloY[i] = pt.y;
- }
-
-
- Dist1 = 0xFFFF;
- for (i = 0 ; i < 8 ; i++) {
- if (Dist[i] < Dist1) {
- Dist1 = Dist[i];
- Closest1 = i;
- }
- }
- Dist[Closest1] = 0xFFFF;
-
- Dist2 = 0xFFFF;
- for (i = 0 ; i < 8 ; i++) {
- if (Dist[i] < Dist2) {
- Dist2 = Dist[i];
- Closest2 = i;
- }
- }
- Dist[Closest2] = 0xFFFF;
-
- Dist3 = 0xFFFF;
- for (i = 0 ; i < 8 ; i++) {
- if (Dist[i] < Dist3) {
- Dist3 = Dist[i];
- Closest3 = i;
- }
- }
-
- Box1 = (Closest1 > 3);
- Box2 = (Closest2 > 3);
- Box3 = (Closest3 > 3);
-
- Dist1 = (int)sqrt(Dist1);
- Dist2 = (int)sqrt(Dist2);
- Dist3 = (int)sqrt(Dist3);
-
- if (Box1 == Box2 && abs(Dist1-Dist2) < 4) {
- SetGate(Closest1,Closest2,polyx,polyy);
-
- } else if (Box1 == Box2 && Dist1 == Dist2) { /* parallel */
- SetGate(Closest1,Closest2,polyx,polyy);
- } else if (Box1 == Box3 && Dist1 == Dist3) { /* parallel */
- SetGate(Closest1,Closest3,polyx,polyy);
- } else if (Box2 == Box3 && Dist2 == Dist3) { /* parallel */
- SetGate(Closest2,Closest3,polyx,polyy);
-
-
- } else if (Box1 == Box3 && abs(Dist1-Dist3) < 4) {
- SetGate(Closest1,Closest3,polyx,polyy);
- } else if (abs(Dist1-Dist3) < 4) { /* if 1 close to 3 then use 2-3 */
- SetGate(Closest2,Closest3,polyx,polyy);
- } else if (abs(Dist1-Dist2) < 4) {
- SetGate(Closest1,Closest2,polyx,polyy);
- } else {
- SetGate(Closest1,Closest1,polyx,polyy);
- }
+ CloX[i] = pt.x;
+ CloY[i] = pt.y;
+ }
+
+
+ Dist1 = 0xFFFF;
+ for (i = 0; i < 8; i++) {
+ if (Dist[i] < Dist1) {
+ Dist1 = Dist[i];
+ Closest1 = i;
+ }
+ }
+ Dist[Closest1] = 0xFFFF;
+
+ Dist2 = 0xFFFF;
+ for (i = 0; i < 8; i++) {
+ if (Dist[i] < Dist2) {
+ Dist2 = Dist[i];
+ Closest2 = i;
+ }
+ }
+ Dist[Closest2] = 0xFFFF;
+
+ Dist3 = 0xFFFF;
+ for (i = 0; i < 8; i++) {
+ if (Dist[i] < Dist3) {
+ Dist3 = Dist[i];
+ Closest3 = i;
+ }
+ }
+
+ Box1 = (Closest1 > 3);
+ Box2 = (Closest2 > 3);
+ Box3 = (Closest3 > 3);
+
+ Dist1 = (int)sqrt(Dist1);
+ Dist2 = (int)sqrt(Dist2);
+ Dist3 = (int)sqrt(Dist3);
+
+ if (Box1 == Box2 && abs(Dist1 - Dist2) < 4) {
+ SetGate(Closest1, Closest2, polyx, polyy);
+
+ } else if (Box1 == Box2 && Dist1 == Dist2) { /* parallel */
+ SetGate(Closest1, Closest2, polyx, polyy);
+ } else if (Box1 == Box3 && Dist1 == Dist3) { /* parallel */
+ SetGate(Closest1, Closest3, polyx, polyy);
+ } else if (Box2 == Box3 && Dist2 == Dist3) { /* parallel */
+ SetGate(Closest2, Closest3, polyx, polyy);
+
+
+ } else if (Box1 == Box3 && abs(Dist1 - Dist3) < 4) {
+ SetGate(Closest1, Closest3, polyx, polyy);
+ } else if (abs(Dist1 - Dist3) < 4) { /* if 1 close to 3 then use 2-3 */
+ SetGate(Closest2, Closest3, polyx, polyy);
+ } else if (abs(Dist1 - Dist2) < 4) {
+ SetGate(Closest1, Closest2, polyx, polyy);
+ } else {
+ SetGate(Closest1, Closest1, polyx, polyy);
+ }
}
-int Scumm::CompareSlope(int X1,int Y1,int X2,int Y2,int X3,int Y3)
+int Scumm::CompareSlope(int X1, int Y1, int X2, int Y2, int X3, int Y3)
{
- if ((Y2 - Y1) * (X3 - X1) > (Y3 - Y1) * (X2 - X1)) return(0);
- return(1);
+ if ((Y2 - Y1) * (X3 - X1) > (Y3 - Y1) * (X2 - X1))
+ return (0);
+ return (1);
}
-void Scumm::SetGate(int line1,int line2, int polyx[8], int polyy[8])
+void Scumm::SetGate(int line1, int line2, int polyx[8], int polyy[8])
{
- if (line1 < 4) { /* from box 1 to box 2 */
- gate1ax = polyx[line1];
- gate1ay = polyy[line1];
- gate2ax = CloX[line1];
- gate2ay = CloY[line1];
-
- } else {
- gate2ax = polyx[line1];
- gate2ay = polyy[line1];
- gate1ax = CloX[line1];
- gate1ay = CloY[line1];
- }
-
- if (line2 < 4) { /* from box */
- gate1bx = polyx[line2];
- gate1by = polyy[line2];
- gate2bx = CloX[line2];
- gate2by = CloY[line2];
-
- } else {
- gate2bx = polyx[line2];
- gate2by = polyy[line2];
- gate1bx = CloX[line2];
- gate1by = CloY[line2];
- }
+ if (line1 < 4) { /* from box 1 to box 2 */
+ gate1ax = polyx[line1];
+ gate1ay = polyy[line1];
+ gate2ax = CloX[line1];
+ gate2ay = CloY[line1];
+
+ } else {
+ gate2ax = polyx[line1];
+ gate2ay = polyy[line1];
+ gate1ax = CloX[line1];
+ gate1ay = CloY[line1];
+ }
+
+ if (line2 < 4) { /* from box */
+ gate1bx = polyx[line2];
+ gate1by = polyy[line2];
+ gate2bx = CloX[line2];
+ gate2by = CloY[line2];
+
+ } else {
+ gate2bx = polyx[line2];
+ gate2by = polyy[line2];
+ gate1bx = CloX[line2];
+ gate1by = CloY[line2];
+ }
}
diff --git a/costume.cpp b/costume.cpp
index 10e8ff6dfd..cb566ee368 100644
--- a/costume.cpp
+++ b/costume.cpp
@@ -23,16 +23,18 @@
#include "stdafx.h"
#include "scumm.h"
-const byte revBitMask[8] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
+const byte revBitMask[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
-void CostumeRenderer::ignorePakCols(int a) {
+void CostumeRenderer::ignorePakCols(int a)
+{
int n;
n = _height;
- if (a>1) n *= a;
+ if (a > 1)
+ n *= a;
do {
_repcolor = *_srcptr++;
- _replen = _repcolor&_maskval;
- if (_replen==0) {
+ _replen = _repcolor & _maskval;
+ if (_replen == 0) {
_replen = *_srcptr++;
}
do {
@@ -45,74 +47,75 @@ void CostumeRenderer::ignorePakCols(int a) {
}
const byte cost_scaleTable[256] = {
-255, 253, 125, 189, 61, 221, 93, 157, 29, 237,
-109, 173, 45, 205, 77, 141, 13, 245, 117, 181,
-53, 213, 85, 149, 21, 229, 101, 165, 37, 197, 69,
-133, 5, 249, 121, 185, 57, 217, 89, 153, 25, 233,
-105, 169, 41, 201, 73, 137, 9, 241, 113, 177, 49,
-209, 81, 145, 17, 225, 97, 161, 33, 193, 65, 129,
-1, 251, 123, 187, 59, 219, 91, 155, 27, 235, 107,
-171, 43, 203, 75, 139, 11, 243, 115, 179, 51, 211,
-83, 147, 19, 227, 99, 163, 35, 195, 67, 131, 3,
-247, 119, 183, 55, 215, 87, 151, 23, 231, 103,
-167, 39, 199, 71, 135, 7, 239, 111, 175, 47, 207,
-79, 143, 15, 223, 95, 159, 31, 191, 63, 127, 0,
-128, 64, 192, 32, 160, 96, 224, 16, 144, 80, 208,
-48, 176, 112, 240, 8, 136, 72, 200, 40, 168, 104,
-232, 24, 152, 88, 216, 56, 184, 120, 248, 4, 132,
-68, 196, 36, 164, 100, 228, 20, 148, 84, 212, 52,
-180, 116, 244, 12, 140, 76, 204, 44, 172, 108,
-236, 28, 156, 92, 220, 60, 188, 124, 252, 2, 130,
-66, 194, 34, 162, 98, 226, 18, 146, 82, 210, 50,
-178, 114, 242, 10, 138, 74, 202, 42, 170, 106,
-234, 26, 154, 90, 218, 58, 186, 122, 250, 6, 134,
-70, 198, 38, 166, 102, 230, 22, 150, 86, 214, 54,
-182, 118, 246, 14, 142, 78, 206, 46, 174, 110,
-238, 30, 158, 94, 222, 62, 190, 126, 254
+ 255, 253, 125, 189, 61, 221, 93, 157, 29, 237,
+ 109, 173, 45, 205, 77, 141, 13, 245, 117, 181,
+ 53, 213, 85, 149, 21, 229, 101, 165, 37, 197, 69,
+ 133, 5, 249, 121, 185, 57, 217, 89, 153, 25, 233,
+ 105, 169, 41, 201, 73, 137, 9, 241, 113, 177, 49,
+ 209, 81, 145, 17, 225, 97, 161, 33, 193, 65, 129,
+ 1, 251, 123, 187, 59, 219, 91, 155, 27, 235, 107,
+ 171, 43, 203, 75, 139, 11, 243, 115, 179, 51, 211,
+ 83, 147, 19, 227, 99, 163, 35, 195, 67, 131, 3,
+ 247, 119, 183, 55, 215, 87, 151, 23, 231, 103,
+ 167, 39, 199, 71, 135, 7, 239, 111, 175, 47, 207,
+ 79, 143, 15, 223, 95, 159, 31, 191, 63, 127, 0,
+ 128, 64, 192, 32, 160, 96, 224, 16, 144, 80, 208,
+ 48, 176, 112, 240, 8, 136, 72, 200, 40, 168, 104,
+ 232, 24, 152, 88, 216, 56, 184, 120, 248, 4, 132,
+ 68, 196, 36, 164, 100, 228, 20, 148, 84, 212, 52,
+ 180, 116, 244, 12, 140, 76, 204, 44, 172, 108,
+ 236, 28, 156, 92, 220, 60, 188, 124, 252, 2, 130,
+ 66, 194, 34, 162, 98, 226, 18, 146, 82, 210, 50,
+ 178, 114, 242, 10, 138, 74, 202, 42, 170, 106,
+ 234, 26, 154, 90, 218, 58, 186, 122, 250, 6, 134,
+ 70, 198, 38, 166, 102, 230, 22, 150, 86, 214, 54,
+ 182, 118, 246, 14, 142, 78, 206, 46, 174, 110,
+ 238, 30, 158, 94, 222, 62, 190, 126, 254
};
-byte CostumeRenderer::mainRoutine(Actor *a, int slot, int frame) {
- int xmove, ymove, i,b,s;
+byte CostumeRenderer::mainRoutine(Actor * a, int slot, int frame)
+{
+ int xmove, ymove, i, b, s;
uint scal;
byte scaling;
byte charsetmask, masking;
byte unk19;
- int ex1,ex2;
+ int ex1, ex2;
- CHECK_HEAP
-
- _maskval = 0xF;
+ CHECK_HEAP _maskval = 0xF;
_shrval = 4;
if (_loaded._numColors == 32) {
_maskval = 7;
_shrval = 3;
}
-
+
_width2 = _srcptr[0];
_width = _width2;
_height2 = _srcptr[2];
_height = _height2;
- xmove = (int16)READ_LE_UINT16(_srcptr+4) + _xmove;
- ymove = (int16)READ_LE_UINT16(_srcptr+6) + _ymove;
- _xmove += (int16)READ_LE_UINT16(_srcptr+8);
- _ymove -= (int16)READ_LE_UINT16(_srcptr+10);
+ xmove = (int16) READ_LE_UINT16(_srcptr + 4) + _xmove;
+ ymove = (int16) READ_LE_UINT16(_srcptr + 6) + _ymove;
+ _xmove += (int16) READ_LE_UINT16(_srcptr + 8);
+ _ymove -= (int16) READ_LE_UINT16(_srcptr + 10);
_srcptr += 12;
- switch(_loaded._ptr[7]&0x7F) {
- case 0x60: case 0x61:
+ switch (_loaded._ptr[7] & 0x7F) {
+ case 0x60:
+ case 0x61:
ex1 = _srcptr[0];
ex2 = _srcptr[1];
_srcptr += 2;
- if (ex1!=0xFF || ex2!=0xFF) {
- ex1=READ_LE_UINT16(_loaded._ptr + _loaded._numColors + 10 + ex1*2);
- _srcptr = _loaded._ptr + READ_LE_UINT16(_loaded._ptr + ex1 + ex2*2) + 14;
+ if (ex1 != 0xFF || ex2 != 0xFF) {
+ ex1 = READ_LE_UINT16(_loaded._ptr + _loaded._numColors + 10 + ex1 * 2);
+ _srcptr =
+ _loaded._ptr + READ_LE_UINT16(_loaded._ptr + ex1 + ex2 * 2) + 14;
}
- }
+ }
_xpos = _actorX;
_ypos = _actorY;
-
- scaling = _scaleX==255 && _scaleY==255 ? 0 : 1;
+
+ scaling = _scaleX == 255 && _scaleY == 255 ? 0 : 1;
s = 0;
if (scaling) {
@@ -122,16 +125,16 @@ byte CostumeRenderer::mainRoutine(Actor *a, int slot, int frame) {
_scaleIndexXStep = 1;
}
- if(_mirror) {
+ if (_mirror) {
unk19 = _scaleIndexX = 128 - xmove;
- for (i=0; i<xmove; i++) {
+ for (i = 0; i < xmove; i++) {
scal = cost_scaleTable[_scaleIndexX++];
if (scal < _scaleX)
_xpos -= _scaleIndexXStep;
}
_right = _left = _xpos;
_scaleIndexX = unk19;
- for (i=0; i<_width; i++) {
+ for (i = 0; i < _width; i++) {
if (_right < 0) {
s++;
unk19 = _scaleIndexX;
@@ -142,20 +145,20 @@ byte CostumeRenderer::mainRoutine(Actor *a, int slot, int frame) {
}
} else {
unk19 = _scaleIndexX = xmove + 128;
- for (i=0; i<xmove; i++) {
+ for (i = 0; i < xmove; i++) {
scal = cost_scaleTable[_scaleIndexX--];
if (scal < _scaleX)
_xpos += _scaleIndexXStep;
}
_right = _left = _xpos;
_scaleIndexX = unk19;
- for (i=0; i<_width; i++) {
+ for (i = 0; i < _width; i++) {
if (_left > 319) {
s++;
unk19 = _scaleIndexX;
}
scal = cost_scaleTable[_scaleIndexX--];
- if(scal < _scaleX)
+ if (scal < _scaleX)
_left--;
}
}
@@ -168,21 +171,21 @@ byte CostumeRenderer::mainRoutine(Actor *a, int slot, int frame) {
_scaleIndexYStep = 1;
}
_scaleIndexY = 128 - ymove;
- for (i=0; i<ymove; i++) {
+ for (i = 0; i < ymove; i++) {
scal = cost_scaleTable[_scaleIndexY++];
if (scal < _scaleY)
_ypos -= _scaleIndexYStep;
}
_top = _bottom = _ypos;
_scaleIndexY = 128 - ymove;
- for (i=0; i<_height; i++) {
+ for (i = 0; i < _height; i++) {
scal = cost_scaleTable[_scaleIndexY++];
- if (scal < _scaleY)
+ if (scal < _scaleY)
_bottom++;
}
_scaleIndexY = _scaleIndexYTop = 128 - ymove;
} else {
- if(_mirror==0)
+ if (_mirror == 0)
xmove = -xmove;
_xpos += xmove;
_ypos += ymove;
@@ -202,7 +205,7 @@ byte CostumeRenderer::mainRoutine(Actor *a, int slot, int frame) {
_scaleIndexXStep = 1;
_ypostop = _ypos;
- _vm->updateDirtyRect(0, _left, _right+1,_top,_bottom,1<<a->number);
+ _vm->updateDirtyRect(0, _left, _right + 1, _top, _bottom, 1 << a->number);
if (_top >= (int)_outheight || _bottom <= 0)
return 0;
@@ -214,7 +217,7 @@ byte CostumeRenderer::mainRoutine(Actor *a, int slot, int frame) {
return 1;
if (_mirror) {
_ypitch--;
- if (scaling==0) {
+ if (scaling == 0) {
s = -_xpos;
}
if (s > 0) {
@@ -224,7 +227,7 @@ byte CostumeRenderer::mainRoutine(Actor *a, int slot, int frame) {
_docontinue = 1;
} else {
s = _right - 320;
- if (s<=0) {
+ if (s <= 0) {
b = 2;
} else {
_width2 -= s;
@@ -232,7 +235,7 @@ byte CostumeRenderer::mainRoutine(Actor *a, int slot, int frame) {
}
} else {
_ypitch++;
- if(scaling==0)
+ if (scaling == 0)
s = _right - 320;
if (s > 0) {
_width2 -= s;
@@ -248,15 +251,16 @@ byte CostumeRenderer::mainRoutine(Actor *a, int slot, int frame) {
}
}
- if (_width2==0)
+ if (_width2 == 0)
return 0;
- if ((uint)_top > (uint)_outheight)
+ if ((uint) _top > (uint) _outheight)
_top = 0;
- if (_left<0) _left=0;
+ if (_left < 0)
+ _left = 0;
- if ((uint)_bottom > _outheight)
+ if ((uint) _bottom > _outheight)
_bottom = _outheight;
if (a->top > _top)
@@ -266,42 +270,49 @@ byte CostumeRenderer::mainRoutine(Actor *a, int slot, int frame) {
a->bottom = _bottom;
if (_height2 + _top >= 256) {
- CHECK_HEAP
- return 2;
+ CHECK_HEAP return 2;
}
- _bgbak_ptr = _vm->getResourceAddress(rtBuffer, 5) + _vm->virtscr[0].xstart + _ypos*320 + _xpos;
- _backbuff_ptr = _vm->virtscr[0].screenPtr + _vm->virtscr[0].xstart + _ypos*320 + _xpos;
- charsetmask = _vm->hasCharsetMask(_left, _top + _vm->virtscr[0].topline, _right, _vm->virtscr[0].topline + _bottom);
+ _bgbak_ptr =
+ _vm->getResourceAddress(rtBuffer,
+ 5) + _vm->virtscr[0].xstart + _ypos * 320 + _xpos;
+ _backbuff_ptr =
+ _vm->virtscr[0].screenPtr + _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(rtBuffer, 9) + _vm->gdi._imgBufOffs[_zbuf] + _vm->_screenStartStrip
- );
+ _vm->getResourceAddress(rtBuffer,
+ 9) +
+ _vm->gdi._imgBufOffs[_zbuf] +
+ _vm->_screenStartStrip);
}
if (_zbuf || charsetmask) {
- _mask_ptr = _vm->getResourceAddress(rtBuffer, 9) + _ypos*40 + _vm->_screenStartStrip;
+ _mask_ptr =
+ _vm->getResourceAddress(rtBuffer,
+ 9) + _ypos * 40 + _vm->_screenStartStrip;
_imgbufoffs = _vm->gdi._imgBufOffs[_zbuf];
- if (!charsetmask && _zbuf!=0)
+ if (!charsetmask && _zbuf != 0)
_mask_ptr += _imgbufoffs;
_mask_ptr_dest = _mask_ptr + _xpos / 8;
}
- CHECK_HEAP
-
- if (a->shadow_mode) {
+ CHECK_HEAP if (a->shadow_mode) {
proc_special(a->shadow_mode);
return b;
}
- switch ((scaling<<2)|(masking<<1)|charsetmask) {
- case 0:
+ switch ((scaling << 2) | (masking << 1) | charsetmask) {
+ case 0:
proc6();
break;
- case 1: case 2:
+ case 1:
+ case 2:
proc5();
break;
case 3:
@@ -310,7 +321,8 @@ byte CostumeRenderer::mainRoutine(Actor *a, int slot, int frame) {
case 4:
proc1();
break;
- case 5:case 6:
+ case 5:
+ case 6:
proc2();
break;
case 7:
@@ -318,14 +330,14 @@ byte CostumeRenderer::mainRoutine(Actor *a, int slot, int frame) {
break;
}
- CHECK_HEAP
- return b;
+ CHECK_HEAP return b;
}
-void CostumeRenderer::proc6() {
+void CostumeRenderer::proc6()
+{
byte len;
byte *src, *dst;
- byte width,height,pcolor;
+ byte width, height, pcolor;
int color;
uint y;
uint scrheight;
@@ -339,18 +351,20 @@ void CostumeRenderer::proc6() {
width = _width2;
height = _height2;
- if (_docontinue) goto StartPos;
+ if (_docontinue)
+ goto StartPos;
do {
len = *src++;
- color = len>>_shrval;
+ color = len >> _shrval;
len &= _maskval;
- if (!len) len = *src++;
+ if (!len)
+ len = *src++;
do {
if (color && y < scrheight) {
pcolor = _palette[color];
- if (pcolor==13) {
+ if (pcolor == 13) {
pcolor = _transEffect[*dst];
}
*dst = pcolor;
@@ -365,19 +379,20 @@ void CostumeRenderer::proc6() {
dst -= _ypitch;
y = _ypostop;
}
-StartPos:;
+ StartPos:;
} while (--len);
} while (1);
}
-void CostumeRenderer::proc5() {
- byte *mask,*src,*dst;
- byte maskbit,len,height,pcolor;
- uint y,scrheight;
+void CostumeRenderer::proc5()
+{
+ byte *mask, *src, *dst;
+ byte maskbit, len, height, pcolor;
+ uint y, scrheight;
int color;
mask = _mask_ptr = _mask_ptr_dest;
- maskbit = revBitMask[_xpos&7];
+ maskbit = revBitMask[_xpos & 7];
y = _ypos;
src = _srcptr;
dst = _backbuff_ptr;
@@ -386,18 +401,20 @@ void CostumeRenderer::proc5() {
scrheight = _outheight;
height = _height2;
- if (_docontinue) goto StartPos;
+ if (_docontinue)
+ goto StartPos;
do {
len = *src++;
- color = len>>_shrval;
+ color = len >> _shrval;
len &= _maskval;
- if (!len) len = *src++;
+ if (!len)
+ len = *src++;
do {
- if (color && y<scrheight && !(*mask&maskbit)) {
+ if (color && y < scrheight && !(*mask & maskbit)) {
pcolor = _palette[color];
- if (pcolor==13)
+ if (pcolor == 13)
pcolor = _transEffect[*dst];
*dst = pcolor;
}
@@ -405,39 +422,40 @@ void CostumeRenderer::proc5() {
y++;
mask += 40;
if (!--height) {
- if(!--_width2)
+ if (!--_width2)
return;
height = _height;
dst -= _ypitch;
y = _ypostop;
- if(_scaleIndexXStep!=1) {
- maskbit<<=1;
+ if (_scaleIndexXStep != 1) {
+ maskbit <<= 1;
if (!maskbit) {
- maskbit=1;
+ maskbit = 1;
_mask_ptr--;
}
} else {
- maskbit>>=1;
+ maskbit >>= 1;
if (!maskbit) {
- maskbit=0x80;
+ maskbit = 0x80;
_mask_ptr++;
}
}
mask = _mask_ptr;
}
-StartPos:;
+ StartPos:;
} while (--len);
- } while(1);
+ } while (1);
}
-void CostumeRenderer::proc4() {
- byte *mask,*src,*dst;
- byte maskbit,len,height,pcolor;
- uint y,scrheight;
+void CostumeRenderer::proc4()
+{
+ byte *mask, *src, *dst;
+ byte maskbit, len, height, pcolor;
+ uint y, scrheight;
int color;
-
+
mask = _mask_ptr = _mask_ptr_dest;
- maskbit = revBitMask[_xpos&7];
+ maskbit = revBitMask[_xpos & 7];
y = _ypos;
src = _srcptr;
dst = _backbuff_ptr;
@@ -446,18 +464,20 @@ void CostumeRenderer::proc4() {
scrheight = _outheight;
height = _height2;
- if (_docontinue) goto StartPos;
+ if (_docontinue)
+ goto StartPos;
do {
len = *src++;
- color = len>>_shrval;
+ color = len >> _shrval;
len &= _maskval;
- if (!len) len = *src++;
-
+ if (!len)
+ len = *src++;
+
do {
- if (color && y<scrheight && !((*mask|mask[_imgbufoffs])&maskbit)) {
+ if (color && y < scrheight && !((*mask | mask[_imgbufoffs]) & maskbit)) {
pcolor = _palette[color];
- if (pcolor==13)
+ if (pcolor == 13)
pcolor = _transEffect[*dst];
*dst = pcolor;
}
@@ -465,37 +485,38 @@ void CostumeRenderer::proc4() {
y++;
mask += 40;
if (!--height) {
- if(!--_width2)
+ if (!--_width2)
return;
height = _height;
dst -= _ypitch;
y = _ypostop;
- if(_scaleIndexXStep!=1) {
- maskbit<<=1;
+ if (_scaleIndexXStep != 1) {
+ maskbit <<= 1;
if (!maskbit) {
- maskbit=1;
+ maskbit = 1;
_mask_ptr--;
}
} else {
- maskbit>>=1;
+ maskbit >>= 1;
if (!maskbit) {
- maskbit=0x80;
+ maskbit = 0x80;
_mask_ptr++;
}
}
mask = _mask_ptr;
}
-StartPos:;
+ StartPos:;
} while (--len);
- } while(1);
+ } while (1);
}
-void CostumeRenderer::proc3() {
- byte *mask,*src,*dst;
- byte maskbit,len,height,pcolor,width;
- int color,t;
+void CostumeRenderer::proc3()
+{
+ byte *mask, *src, *dst;
+ byte maskbit, len, height, pcolor, width;
+ int color, t;
uint y;
-
+
mask = _mask_ptr_dest;
dst = _backbuff_ptr;
height = _height2;
@@ -503,21 +524,24 @@ void CostumeRenderer::proc3() {
len = _replen;
color = _repcolor;
src = _srcptr;
- maskbit = revBitMask[_xpos&7];
+ maskbit = revBitMask[_xpos & 7];
y = _ypos;
- if (_docontinue) goto StartPos;
+ if (_docontinue)
+ goto StartPos;
do {
len = *src++;
- color = len>>_shrval;
+ color = len >> _shrval;
len &= _maskval;
- if (!len) len = *src++;
+ if (!len)
+ len = *src++;
do {
if (cost_scaleTable[_scaleIndexY++] < _scaleY) {
- if (color && y < _outheight && !((*mask|mask[_imgbufoffs])&maskbit)) {
+ if (color && y < _outheight
+ && !((*mask | mask[_imgbufoffs]) & maskbit)) {
pcolor = _palette[color];
- if (pcolor==13)
+ if (pcolor == 13)
pcolor = _transEffect[*dst];
*dst = pcolor;
}
@@ -526,7 +550,7 @@ void CostumeRenderer::proc3() {
y++;
}
if (!--height) {
- if(!--width)
+ if (!--width)
return;
height = _height;
y = _ypostop;
@@ -537,23 +561,24 @@ void CostumeRenderer::proc3() {
_xpos += _scaleIndexXStep;
if (_xpos >= 320)
return;
- maskbit = revBitMask[_xpos&7];
+ maskbit = revBitMask[_xpos & 7];
_backbuff_ptr += _scaleIndexXStep;
}
dst = _backbuff_ptr;
- mask = _mask_ptr + (_xpos>>3);
+ mask = _mask_ptr + (_xpos >> 3);
}
-StartPos:;
+ StartPos:;
} while (--len);
- } while(1);
+ } while (1);
}
-void CostumeRenderer::proc2() {
- byte *mask,*src,*dst;
- byte maskbit,len,height,pcolor,width;
- int color,t;
+void CostumeRenderer::proc2()
+{
+ byte *mask, *src, *dst;
+ byte maskbit, len, height, pcolor, width;
+ int color, t;
uint y;
-
+
mask = _mask_ptr_dest;
dst = _backbuff_ptr;
height = _height2;
@@ -561,21 +586,23 @@ void CostumeRenderer::proc2() {
len = _replen;
color = _repcolor;
src = _srcptr;
- maskbit = revBitMask[_xpos&7];
+ maskbit = revBitMask[_xpos & 7];
y = _ypos;
- if (_docontinue) goto StartPos;
+ if (_docontinue)
+ goto StartPos;
do {
len = *src++;
- color = len>>_shrval;
+ color = len >> _shrval;
len &= _maskval;
- if (!len) len = *src++;
+ if (!len)
+ len = *src++;
do {
if (cost_scaleTable[_scaleIndexY++] < _scaleY) {
- if (color && y < _outheight && !(*mask&maskbit)) {
+ if (color && y < _outheight && !(*mask & maskbit)) {
pcolor = _palette[color];
- if (pcolor==13)
+ if (pcolor == 13)
pcolor = _transEffect[*dst];
*dst = pcolor;
}
@@ -584,7 +611,7 @@ void CostumeRenderer::proc2() {
y++;
}
if (!--height) {
- if(!--width)
+ if (!--width)
return;
height = _height;
y = _ypostop;
@@ -595,27 +622,28 @@ void CostumeRenderer::proc2() {
_xpos += _scaleIndexXStep;
if (_xpos >= 320)
return;
- maskbit = revBitMask[_xpos&7];
+ maskbit = revBitMask[_xpos & 7];
_backbuff_ptr += _scaleIndexXStep;
}
dst = _backbuff_ptr;
- mask = _mask_ptr + (_xpos>>3);
+ mask = _mask_ptr + (_xpos >> 3);
}
-StartPos:;
+ StartPos:;
} while (--len);
- } while(1);
+ } while (1);
}
-void CostumeRenderer::proc1() {
- byte *mask,*src,*dst,*dstorg;
- byte maskbit,len,height,pcolor,width;
+void CostumeRenderer::proc1()
+{
+ byte *mask, *src, *dst, *dstorg;
+ byte maskbit, len, height, pcolor, width;
uint y;
int color;
int t;
mask = _mask_ptr = _mask_ptr_dest;
- maskbit = revBitMask[_xpos&7];
+ maskbit = revBitMask[_xpos & 7];
y = _ypos;
dstorg = dst = _backbuff_ptr;
@@ -625,19 +653,21 @@ void CostumeRenderer::proc1() {
color = _repcolor;
src = _srcptr;
- if (_docontinue) goto StartPos;
+ if (_docontinue)
+ goto StartPos;
do {
len = *src++;
- color = len>>_shrval;
+ color = len >> _shrval;
len &= _maskval;
- if (!len) len = *src++;
-
+ if (!len)
+ len = *src++;
+
do {
if (cost_scaleTable[_scaleIndexY++] < _scaleY) {
if (color && y < _outheight) {
pcolor = _palette[color];
- if (pcolor==13)
+ if (pcolor == 13)
pcolor = _transEffect[*dst];
*dst = pcolor;
}
@@ -645,7 +675,7 @@ void CostumeRenderer::proc1() {
y++;
}
if (!--height) {
- if(!--width)
+ if (!--width)
return;
height = _height;
y = _ypostop;
@@ -660,36 +690,38 @@ void CostumeRenderer::proc1() {
}
dst = _backbuff_ptr;
}
-StartPos:;
+ StartPos:;
} while (--len);
- } while(1);
+ } while (1);
}
-void CostumeRenderer::proc_special(byte code) {
+void CostumeRenderer::proc_special(byte code)
+{
warning("stub CostumeRenderer::proc_special(%d) not implemented");
}
#if 0
-void CostumeRenderer::loadCostume(int id) {
+void CostumeRenderer::loadCostume(int id)
+{
_ptr = _vm->getResourceAddress(rtCostume, id);
-
- if (_vm->_features&GF_AFTER_V6) {
+
+ if (_vm->_features & GF_AFTER_V6) {
_ptr += 8;
- } else if(!(_vm->_features&GF_SMALL_HEADER)) {
+ } else if (!(_vm->_features & GF_SMALL_HEADER)) {
_ptr += 2;
}
- switch(_ptr[7]&0x7F) {
+ switch (_ptr[7] & 0x7F) {
case 0x58:
_numColors = 16;
break;
case 0x59:
_numColors = 32;
break;
- case 0x60: /* New since version 6 */
+ case 0x60: /* New since version 6 */
_numColors = 16;
break;
- case 0x61: /* New since version 6 */
+ case 0x61: /* New since version 6 */
_numColors = 32;
break;
default:
@@ -700,36 +732,40 @@ void CostumeRenderer::loadCostume(int id) {
}
#endif
-void Scumm::initActorCostumeData(Actor *a) {
+void Scumm::initActorCostumeData(Actor * a)
+{
CostumeData *cd = &a->cost;
int i;
cd->stopped = 0;
- for (i=0; i<16; i++) {
+ for (i = 0; i < 16; i++) {
cd->active[i] = 0;
cd->curpos[i] = cd->start[i] = cd->end[i] = cd->frame[i] = 0xFFFF;
}
}
-byte CostumeRenderer::drawOneSlot(Actor *a, int slot) {
-
- if(!(_vm->_features & GF_AFTER_V7)) {
+byte CostumeRenderer::drawOneSlot(Actor * a, int slot)
+{
+
+ if (!(_vm->_features & GF_AFTER_V7)) {
int i;
int code;
CostumeData *cd = &a->cost;
-
- if (cd->curpos[slot]==0xFFFF || cd->stopped & (1<<slot))
+
+ if (cd->curpos[slot] == 0xFFFF || cd->stopped & (1 << slot))
return 0;
-
- i = cd->curpos[slot]&0x7FFF;
- _frameptr = _loaded._ptr + READ_LE_UINT16(_loaded._ptr + _loaded._numColors + slot*2 + 10);
- code = _loaded._dataptr[i]&0x7F;
- _srcptr = _loaded._ptr + READ_LE_UINT16(_frameptr + code*2);
+ i = cd->curpos[slot] & 0x7FFF;
+ _frameptr =
+ _loaded._ptr + READ_LE_UINT16(_loaded._ptr + _loaded._numColors +
+ slot * 2 + 10);
+ code = _loaded._dataptr[i] & 0x7F;
+
+ _srcptr = _loaded._ptr + READ_LE_UINT16(_frameptr + code * 2);
if (code != 0x7B) {
- if ( !(_vm->_features & GF_OLD256) || code <0x79)
- return mainRoutine(a, slot, code);
+ if (!(_vm->_features & GF_OLD256) || code < 0x79)
+ return mainRoutine(a, slot, code);
}
}
@@ -737,40 +773,43 @@ byte CostumeRenderer::drawOneSlot(Actor *a, int slot) {
}
-byte CostumeRenderer::drawCostume(Actor *a) {
+byte CostumeRenderer::drawCostume(Actor * a)
+{
int i;
byte r = 0;
_xmove = _ymove = 0;
- for (i=0; i!=16; i++)
- r|=drawOneSlot(a, i);
+ for (i = 0; i != 16; i++)
+ r |= drawOneSlot(a, i);
return r;
}
-int Scumm::cost_frameToAnim(Actor *a, int frame) {
+int Scumm::cost_frameToAnim(Actor * a, int frame)
+{
return newDirToOldDir(a->facing) + frame * 4;
}
-void Scumm::loadCostume(LoadedCostume *lc, int costume) {
+void Scumm::loadCostume(LoadedCostume * lc, int costume)
+{
lc->_ptr = getResourceAddress(rtCostume, costume);
-
- if (_features&GF_AFTER_V6) {
+
+ if (_features & GF_AFTER_V6) {
lc->_ptr += 8;
- } else if (!(_features&GF_SMALL_HEADER)) {
+ } else if (!(_features & GF_SMALL_HEADER)) {
lc->_ptr += 2;
}
- switch(lc->_ptr[7]&0x7F) {
+ switch (lc->_ptr[7] & 0x7F) {
case 0x58:
lc->_numColors = 16;
break;
case 0x59:
lc->_numColors = 32;
break;
- case 0x60: /* New since version 6 */
+ case 0x60: /* New since version 6 */
lc->_numColors = 16;
break;
- case 0x61: /* New since version 6 */
+ case 0x61: /* New since version 6 */
lc->_numColors = 32;
break;
default:
@@ -780,11 +819,12 @@ void Scumm::loadCostume(LoadedCostume *lc, int costume) {
lc->_dataptr = lc->_ptr + READ_LE_UINT16(lc->_ptr + lc->_numColors + 8);
}
-void Scumm::cost_decodeData(Actor *a, int frame, uint usemask) {
- byte *p,*r;
- uint mask,j;
+void Scumm::cost_decodeData(Actor * a, int frame, uint usemask)
+{
+ byte *p, *r;
+ uint mask, j;
int i;
- byte extra,cmd;
+ byte extra, cmd;
byte *dataptr;
int anim;
LoadedCostume lc;
@@ -792,59 +832,59 @@ void Scumm::cost_decodeData(Actor *a, int frame, uint usemask) {
loadCostume(&lc, a->costume);
anim = cost_frameToAnim(a, frame);
-
+
p = lc._ptr;
if (anim > p[6]) {
return;
}
- r = p + READ_LE_UINT16(p + anim*2 + lc._numColors + 42);
- if (r==p) {
+ r = p + READ_LE_UINT16(p + anim * 2 + lc._numColors + 42);
+ if (r == p) {
return;
}
-
- if(_features & GF_OLD256)
+
+ if (_features & GF_OLD256)
dataptr = p + *(p + lc._numColors + 8);
else
dataptr = p + READ_LE_UINT16(p + lc._numColors + 8);
mask = READ_LE_UINT16(r);
- r+=2;
+ r += 2;
i = 0;
do {
- if (mask&0x8000) {
- if(_features & GF_OLD256 ) {
+ if (mask & 0x8000) {
+ if (_features & GF_OLD256) {
j = 0;
j = *(r);
r++;
- if(j==0xFF)
- j=0xFFFF;
+ if (j == 0xFF)
+ j = 0xFFFF;
} else {
j = READ_LE_UINT16(r);
- r+=2;
+ r += 2;
}
- if (usemask&0x8000) {
- if (j==0xFFFF) {
+ if (usemask & 0x8000) {
+ if (j == 0xFFFF) {
a->cost.curpos[i] = 0xFFFF;
a->cost.start[i] = 0;
a->cost.frame[i] = frame;
} else {
extra = *r++;
cmd = dataptr[j];
- if (cmd==0x7A) {
- a->cost.stopped &= ~(1<<i);
- } else if (cmd==0x79) {
- a->cost.stopped |= (1<<i);
+ if (cmd == 0x7A) {
+ a->cost.stopped &= ~(1 << i);
+ } else if (cmd == 0x79) {
+ a->cost.stopped |= (1 << i);
} else {
a->cost.curpos[i] = a->cost.start[i] = j;
- a->cost.end[i] = j + (extra&0x7F);
- if (extra&0x80)
+ a->cost.end[i] = j + (extra & 0x7F);
+ if (extra & 0x80)
a->cost.curpos[i] |= 0x8000;
a->cost.frame[i] = frame;
}
}
} else {
- if (j!=0xFFFF)
+ if (j != 0xFFFF)
r++;
}
}
@@ -854,49 +894,55 @@ void Scumm::cost_decodeData(Actor *a, int frame, uint usemask) {
} while ((uint16)mask);
}
-void Scumm::cost_setPalette(CostumeRenderer *cr, byte *palette) {
+void Scumm::cost_setPalette(CostumeRenderer * cr, byte *palette)
+{
int i;
byte color;
- for (i=0; i<cr->_loaded._numColors; i++) {
+ for (i = 0; i < cr->_loaded._numColors; i++) {
color = palette[i];
- if (color==255)
- color = cr->_loaded._ptr[8+i];
+ if (color == 255)
+ color = cr->_loaded._ptr[8 + i];
cr->_palette[i] = color;
}
}
-void Scumm::cost_setFacing(CostumeRenderer *cr, Actor *a) {
- cr->_mirror = newDirToOldDir(a->facing)!=0 || (cr->_loaded._ptr[7]&0x80);
+void Scumm::cost_setFacing(CostumeRenderer * cr, Actor * a)
+{
+ cr->_mirror = newDirToOldDir(a->facing) != 0
+ || (cr->_loaded._ptr[7] & 0x80);
}
-void Scumm::cost_setCostume(CostumeRenderer *cr, int costume) {
+void Scumm::cost_setCostume(CostumeRenderer * cr, int costume)
+{
loadCostume(&cr->_loaded, costume);
}
-byte Scumm::cost_increaseAnims(LoadedCostume *lc, Actor *a) {
+byte Scumm::cost_increaseAnims(LoadedCostume * lc, Actor * a)
+{
int i;
byte r = 0;
- for (i=0; i!=16; i++) {
- if(a->cost.curpos[i]!=0xFFFF)
- r+=cost_increaseAnim(lc, a, i);
+ for (i = 0; i != 16; i++) {
+ if (a->cost.curpos[i] != 0xFFFF)
+ r += cost_increaseAnim(lc, a, i);
}
return r;
}
-byte Scumm::cost_increaseAnim(LoadedCostume *lc, Actor *a, int slot) {
+byte Scumm::cost_increaseAnim(LoadedCostume * lc, Actor * a, int slot)
+{
int highflag;
- int i,end;
- byte code,nc;
+ int i, end;
+ byte code, nc;
- if (a->cost.curpos[slot]==0xFFFF)
+ if (a->cost.curpos[slot] == 0xFFFF)
return 0;
- highflag = a->cost.curpos[slot]&0x8000;
- i = a->cost.curpos[slot]&0x7FFF;
+ highflag = a->cost.curpos[slot] & 0x8000;
+ i = a->cost.curpos[slot] & 0x7FFF;
end = a->cost.end[slot];
- code=lc->_dataptr[i]&0x7F;
+ code = lc->_dataptr[i] & 0x7F;
do {
if (!highflag) {
@@ -909,28 +955,27 @@ byte Scumm::cost_increaseAnim(LoadedCostume *lc, Actor *a, int slot) {
nc = lc->_dataptr[i];
- if (nc==0x7C) {
+ if (nc == 0x7C) {
a->cost.animCounter1++;
- if(a->cost.start[slot] != end)
+ if (a->cost.start[slot] != end)
continue;
} else {
- if (_features&GF_AFTER_V6) {
- if (nc>=0x71 && nc<=0x78) {
- addSoundToQueue2(a->sound[nc-0x71]);
- if(a->cost.start[slot] != end)
+ if (_features & GF_AFTER_V6) {
+ if (nc >= 0x71 && nc <= 0x78) {
+ addSoundToQueue2(a->sound[nc - 0x71]);
+ if (a->cost.start[slot] != end)
continue;
}
} else {
- if (nc==0x78) {
+ if (nc == 0x78) {
a->cost.animCounter2++;
- if(a->cost.start[slot] != end)
+ if (a->cost.start[slot] != end)
continue;
}
}
}
- a->cost.curpos[slot] = i|highflag;
- return (lc->_dataptr[i]&0x7F) != code;
- } while(1);
+ a->cost.curpos[slot] = i | highflag;
+ return (lc->_dataptr[i] & 0x7F) != code;
+ } while (1);
}
-
diff --git a/debug.cpp b/debug.cpp
index ff98639842..840d430172 100644
--- a/debug.cpp
+++ b/debug.cpp
@@ -41,13 +41,14 @@ enum {
CMD_ACTOR,
CMD_SCRIPTS,
CMD_LOAD_ROOM,
- CMD_DUMPBOX,
- CMD_VAR,
+ CMD_DUMPBOX,
+ CMD_VAR,
CMD_WATCH,
CMD_EXIT
};
-void ScummDebugger::attach(Scumm *s) {
+void ScummDebugger::attach(Scumm *s)
+{
if (_s)
detach();
@@ -62,22 +63,21 @@ void ScummDebugger::attach(Scumm *s) {
}
void BoxTest(int num);
-bool ScummDebugger::do_command() {
- switch(get_command()) {
+bool ScummDebugger::do_command()
+{
+ switch (get_command()) {
case CMD_HELP:
- printf(
- "Debugger commands:\n"
- "(h)elp -> display this help text\n"
- "(q)uit -> quit the debugger\n"
- "(g)o [numframes] -> increase frame\n"
- "(a)ctor [actornum] -> show actor information\n"
- "(r)oom roomnum -> load room\n"
- "(s)cripts -> show running scripts\n"
- "(b)oxes -> list and draw boxen\n"
- "(v)ariable -> set or show a variable value\n"
- "(w)atch [varnum] -> set a variable watch. 0 means all variables.\n"
- "(e)xit -> exit game\n"
- );
+ printf("Debugger commands:\n"
+ "(h)elp -> display this help text\n"
+ "(q)uit -> quit the debugger\n"
+ "(g)o [numframes] -> increase frame\n"
+ "(a)ctor [actornum] -> show actor information\n"
+ "(r)oom roomnum -> load room\n"
+ "(s)cripts -> show running scripts\n"
+ "(b)oxes -> list and draw boxen\n"
+ "(v)ariable -> set or show a variable value\n"
+ "(w)atch [varnum] -> set a variable watch. 0 means all variables.\n"
+ "(e)xit -> exit game\n");
return true;
case CMD_QUIT:
@@ -102,9 +102,9 @@ bool ScummDebugger::do_command() {
case CMD_LOAD_ROOM:
if (!_parameters[0]) {
printf("Enter a room number...\n");
- } else {
- int room=atoi(_parameters);
- _s->actor[_s->_vars[_s->VAR_EGO]].room=room;
+ } else {
+ int room = atoi(_parameters);
+ _s->actor[_s->_vars[_s->VAR_EGO]].room = room;
_s->startScene(room, 0, 0);
_s->_fullRedraw = 1;
}
@@ -112,43 +112,43 @@ bool ScummDebugger::do_command() {
case CMD_DUMPBOX:
{
int num, i = 0;
- BoxCoords box;
+ BoxCoords box;
byte *boxm = _s->getBoxMatrixBaseAddr();
- num = _s->getNumBoxes();
+ num = _s->getNumBoxes();
printf("Walk matrix:\n");
- for (i=0;i<num;i++)
- {
- while(*boxm != 0xFF) {
- printf ("[%d] ",*boxm);
+ for (i = 0; i < num; i++) {
+ while (*boxm != 0xFF) {
+ printf("[%d] ", *boxm);
boxm++;
}
boxm++;
printf("\n");
}
-
- printf("\nWalk boxes:\n");
- for (i=0; i<num; i++) {
+
+ printf("\nWalk boxes:\n");
+ for (i = 0; i < num; i++) {
BoxTest(i);
_s->getBoxCoordinates(i, &box);
- printf("%d: [%d x %d] [%d x %d] [%d x %d] [%d x %d]\n", i,
- box.ul.x, box.ul.y, box.ll.x, box.ll.y,
- box.ur.x, box.ur.y, box.lr.x, box.lr.y);
+ printf("%d: [%d x %d] [%d x %d] [%d x %d] [%d x %d]\n", i,
+ box.ul.x, box.ul.y, box.ll.x, box.ll.y,
+ box.ur.x, box.ur.y, box.lr.x, box.lr.y);
}
}
return true;
case CMD_VAR:
if (!_parameters[0]) {
- printf("v 123 will show the value of 123, v 123 456 will set the value of 123 to 456.\n");
- } else {
+ printf
+ ("v 123 will show the value of 123, v 123 456 will set the value of 123 to 456.\n");
+ } else {
char *tok = strtok(_parameters, " ");
int var = atoi(tok);
tok = strtok(NULL, "");
- if (tok)
- _s->writeVar(var, atoi(tok));
+ if (tok)
+ _s->writeVar(var, atoi(tok));
printf("Var[%d] = %d\n", var, _s->readVar(var));
- }
+ }
return true;
case CMD_WATCH:
if (!_parameters[0]) {
@@ -156,7 +156,7 @@ bool ScummDebugger::do_command() {
_s->_varwatch = -1;
} else {
_s->_varwatch = atoi(_parameters);
- if (_s->_varwatch == 0)
+ if (_s->_varwatch == 0)
printf("Watching all variables\n");
else
printf("Watching vars[%d]\n", _s->_varwatch);
@@ -165,31 +165,36 @@ bool ScummDebugger::do_command() {
case CMD_EXIT:
exit(1);
- default: /* this line is never reached */
- error("Unknown debug command");
+ default: /* this line is never reached */
+ error("Unknown debug command");
return true;
}
}
-void ScummDebugger::enter() {
+void ScummDebugger::enter()
+{
if (_welcome) {
_welcome = false;
- printf("Debugging Mode entered!, please switch to this console for input.\n"
- "Enter h to list all the debug commands\n");
+ printf
+ ("Debugging Mode entered!, please switch to this console for input.\n"
+ "Enter h to list all the debug commands\n");
+ }
+ while (do_command()) {
}
- while(do_command()) {}
}
-void ScummDebugger::on_frame() {
- if (_go_amount==0)
+void ScummDebugger::on_frame()
+{
+ if (_go_amount == 0)
return;
if (!--_go_amount)
enter();
}
-void ScummDebugger::detach() {
+void ScummDebugger::detach()
+{
_s->_debugger = NULL;
_s = NULL;
}
@@ -201,20 +206,21 @@ struct DebuggerCommands {
};
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 },
- { "r", 1, CMD_LOAD_ROOM },
- { "b", 1, CMD_DUMPBOX},
- { "v", 1, CMD_VAR},
- { "w", 1, CMD_WATCH},
- { "e", 1, CMD_EXIT },
- { "" , 0, 0 }
+ {"h", 1, CMD_HELP},
+ {"q", 1, CMD_QUIT},
+ {"g", 1, CMD_GO},
+ {"a", 1, CMD_ACTOR},
+ {"s", 1, CMD_SCRIPTS},
+ {"r", 1, CMD_LOAD_ROOM},
+ {"b", 1, CMD_DUMPBOX},
+ {"v", 1, CMD_VAR},
+ {"w", 1, CMD_WATCH},
+ {"e", 1, CMD_EXIT},
+ {"", 0, 0}
};
-int ScummDebugger::get_command() {
+int ScummDebugger::get_command()
+{
const DebuggerCommands *dc;
char *s;
int i;
@@ -228,22 +234,22 @@ int ScummDebugger::get_command() {
return CMD_QUIT;
i = strlen(_cmd_buffer);
- while (i>0 && _cmd_buffer[i-1]==10)
+ while (i > 0 && _cmd_buffer[i - 1] == 10)
_cmd_buffer[--i] = 0;
- if (i==0)
+ if (i == 0)
continue;
-
-#else // yes we do have readline
- if(buf) {
- free(buf);
+
+#else // yes we do have readline
+ if (buf) {
+ free(buf);
}
buf = readline("debug> ");
- if(!buf) {
- printf("\n");
- return CMD_QUIT;
+ if (!buf) {
+ printf("\n");
+ return CMD_QUIT;
}
- if(strlen(buf) == 0) {
+ if (strlen(buf) == 0) {
continue;
}
add_history(buf);
@@ -252,50 +258,67 @@ int ScummDebugger::get_command() {
dc = debugger_commands;
do {
if (!strncmp(buf, dc->text, dc->len)) {
- for(s=buf;*s;s++) {
- if (*s==32) { s++; break; }
+ for (s = buf; *s; s++) {
+ if (*s == 32) {
+ s++;
+ break;
+ }
}
_parameters = s;
return _command = dc->id;
}
} while ((++dc)->text[0]);
-
- for(s=buf;*s;s++)
- if (*s==32) { *s=0; break; }
- printf("Invalid command '%s'. Type 'help' for a list of available commands.\n", buf);
+
+ for (s = buf; *s; s++)
+ if (*s == 32) {
+ *s = 0;
+ break;
+ }
+ printf
+ ("Invalid command '%s'. Type 'help' for a list of available commands.\n",
+ buf);
} while (1);
}
-void ScummDebugger::printActors(int act) {
+void ScummDebugger::printActors(int act)
+{
int i;
Actor *a;
- printf("+--------------------------------------------------------------+\n");
- printf("|# |room| x y |elev|cos|width|box|mov|zp|frame|scale|spd|dir|\n");
- printf("+--+----+--------+----+---+-----+---+---+--+-----+-----+---+---+\n");
- for(i=1; i<_s->NUM_ACTORS; i++) {
- if (act==-1 || act==i) {
+ printf
+ ("+--------------------------------------------------------------+\n");
+ printf
+ ("|# |room| x y |elev|cos|width|box|mov|zp|frame|scale|spd|dir|\n");
+ printf
+ ("+--+----+--------+----+---+-----+---+---+--+-----+-----+---+---+\n");
+ for (i = 1; i < _s->NUM_ACTORS; i++) {
+ if (act == -1 || act == 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->forceClip,a->frame,a->scalex,a->speedx,a->facing);
+ i, a->room, a->x, a->y, a->elevation, a->costume, a->width,
+ a->walkbox, a->moving, a->forceClip, a->frame, a->scalex,
+ a->speedx, a->facing);
}
}
- printf("+--------------------------------------------------------------+\n");
+ printf
+ ("+--------------------------------------------------------------+\n");
}
-void ScummDebugger::printScripts() {
+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++) {
+ 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->where, ss->unk1, ss->unk2, ss->freezeCount, ss->cutsceneOverride, ss->unk5);
+ i, ss->number, ss->status, ss->where, ss->unk1, ss->unk2,
+ ss->freezeCount, ss->cutsceneOverride, ss->unk5);
}
}
printf("+---------------------------------+\n");
diff --git a/debugrl.cpp b/debugrl.cpp
index 86d72327a0..8c9366a2f4 100644
--- a/debugrl.cpp
+++ b/debugrl.cpp
@@ -4,83 +4,84 @@
// A lot of this was ripped straight from the readline fileman.c example.
-char* _debugger_commands[] = {
- "help",
- "quit",
- "go",
- "actor",
- "scripts",
- "exit",
- (char *)NULL
+char *_debugger_commands[] = {
+ "help",
+ "quit",
+ "go",
+ "actor",
+ "scripts",
+ "exit",
+ (char *)NULL
};
// forwards decls
-char ** scumm_debugger_completion (const char *text, int start, int end);
-char * scumm_debugger_command_generator (const char *text, int state);
+char **scumm_debugger_completion(const char *text, int start, int end);
+char *scumm_debugger_command_generator(const char *text, int state);
-void initialize_readline () {
- /* Allow conditional parsing of the ~/.inputrc file. */
- rl_readline_name = "scummvm";
+void initialize_readline()
+{
+ /* Allow conditional parsing of the ~/.inputrc file. */
+ rl_readline_name = "scummvm";
- /* Tell the completer that we want a crack first. */
- rl_attempted_completion_function = scumm_debugger_completion;
+ /* Tell the completer that we want a crack first. */
+ rl_attempted_completion_function = scumm_debugger_completion;
}
-char ** scumm_debugger_completion (const char *text, int start, int end) {
+char **scumm_debugger_completion(const char *text, int start, int end)
+{
- char **matches;
+ char **matches;
- matches = (char **)NULL;
+ matches = (char **)NULL;
- // If this word is at the start of the line, then it is a command
- // to complete.
- if (start == 0) {
- matches = rl_completion_matches (text, scumm_debugger_command_generator);
- } else {
- // At some stage it'd be nice to have symbolic actor name completion
- // or something similarly groovy. Not right now though.
- }
+ // If this word is at the start of the line, then it is a command
+ // to complete.
+ if (start == 0) {
+ matches = rl_completion_matches(text, scumm_debugger_command_generator);
+ } else {
+ // At some stage it'd be nice to have symbolic actor name completion
+ // or something similarly groovy. Not right now though.
+ }
- // This just makes sure that readline doesn't try to use its default
- // completer, which uses filenames in the current dir, if we can't find
- // a match, since filenames don't have much use in the debuger :)
- // There's probably a nice way to do this once, rather than every time.
- rl_attempted_completion_over = 1;
-
- return (matches);
+ // This just makes sure that readline doesn't try to use its default
+ // completer, which uses filenames in the current dir, if we can't find
+ // a match, since filenames don't have much use in the debuger :)
+ // There's probably a nice way to do this once, rather than every time.
+ rl_attempted_completion_over = 1;
+
+ return (matches);
}
/* Generator function for command completion. STATE lets us know whether
to start from scratch; without any state (i.e. STATE == 0), then we
start at the top of the list. */
-char * scumm_debugger_command_generator (const char *text, int state) {
-
- static int list_index, len;
- char *name;
-
- /* If this is a new word to complete, initialize now. This includes
- saving the length of TEXT for efficiency, and initializing the index
- variable to 0. */
- if (!state)
- {
- list_index = 0;
- len = strlen (text);
- }
-
- /* Return the next name which partially matches from the command list. */
- while (name = _debugger_commands[list_index])
- {
- list_index++;
-
- if (strncmp (name, text, len) == 0)
- //return (dupstr(name));
- return strdup(name);
- }
-
- /* If no names matched, then return NULL. */
- return ((char *)NULL);
+char *scumm_debugger_command_generator(const char *text, int state)
+{
+
+ static int list_index, len;
+ char *name;
+
+ /* If this is a new word to complete, initialize now. This includes
+ saving the length of TEXT for efficiency, and initializing the index
+ variable to 0. */
+ if (!state) {
+ list_index = 0;
+ len = strlen(text);
+ }
+
+ /* Return the next name which partially matches from the command list. */
+ while (name = _debugger_commands[list_index]) {
+ list_index++;
+
+ if (strncmp(name, text, len) == 0)
+ //return (dupstr(name));
+ return strdup(name);
+ }
+
+ /* If no names matched, then return NULL. */
+ return ((char *)NULL);
}
#endif /* HAVE_READLINE */
diff --git a/gameDetector.cpp b/gameDetector.cpp
index 0c885d5be6..2c2cd18b13 100644
--- a/gameDetector.cpp
+++ b/gameDetector.cpp
@@ -45,131 +45,132 @@
"\tg - graphics mode. 1 for 2xSai anti-aliasing\n" \
"\ta - load autosave game (for recovering from crashes)\n"
-void GameDetector::parseCommandLine(int argc, char **argv) {
- #if !defined(__APPLE__CW)
- int i;
- char *s;
-
- // check for arguments
- if (argc < 2)
- {
- printf( USAGE_STRING );
- //exit(1);
- }
-
- /* Parse the arguments */
- for (i=1; i < argc; i++) {
- s = argv[i];
-
- if (s && s[0]=='-') {
- s++;
- while (*s) {
- switch(tolower(*s)) {
- case 'a':
- _restore = true;
- break;
- case 'b':
- if (*(s+1) == '\0')
- goto ShowHelpAndExit;
- _bootParam = atoi(s+1);
- goto NextArg;
- case 'f':
- _fullScreen = true;
- break;
- case 'd':
- _debugMode = true;
- break;
- case 'n':
- _noSubtitles = true;
- break;
- case 's':
- if (*(s+1) == '\0')
- goto ShowHelpAndExit;
- _scale = atoi(s+1);
- if (_scale == 0 || _scale > 3)
- {
- // bad scale - only 1, 2, 3 work for now
- printf("Invalid scale '%s' - valid values are 1, 2, 3\n", s+1);
- exit(1);
- }
- goto NextArg;
- case 'v':
- printf("ScummVM " SCUMMVM_VERSION "\nBuilt on " __DATE__ " " __TIME__ "\n");
- #ifdef SCUMMVM_PLATFORM_VERSION
- printf(" " SCUMMVM_PLATFORM_VERSION "\n");
- #endif
- exit(1);
- case 'p':
- if (*(s+1) == '\0')
- goto ShowHelpAndExit;
- _gameDataPath = s+1;
- goto NextArg;
- case 't':
- if (*(s+1) == '\0')
- goto ShowHelpAndExit;
- _gameTempo = atoi(s+1);
- goto NextArg;
- case 'm': {
- if (*(s+1) == '\0')
- goto ShowHelpAndExit;
- SoundEngine *se = (SoundEngine*)_soundEngine;
-
- if (se)
- se->set_music_volume(atoi(s+1));
- goto NextArg;
- }
- case 'r': {
- SoundEngine *se = (SoundEngine*)_soundEngine;
-
- if (se)
- se->_mt32emulate = true;
- break;
- }
- case 'e':
- if (*(s+1) == '\0')
- goto ShowHelpAndExit;
- _midi_driver = atoi(s+1);
- goto NextArg;
- case 'g':
- if (*(s+1) == '\0')
- goto ShowHelpAndExit;
- _videoMode = atoi(s+1);
- goto NextArg;
-
- case 'c':
- if (*(s+1) == '\0')
- goto ShowHelpAndExit;
- _cdrom = atoi(s+1);
- goto NextArg;
-
- default:
-ShowHelpAndExit:;
- printf( USAGE_STRING );
- exit(1);
- }
- s++;
- }
-NextArg:;
- } else {
- if (_exe_name) goto ShowHelpAndExit;
- _exe_name = s;
- }
- }
-
- #else
- _midi_driver = 4;
- _exe_name = *argv;
- _gameDataPath = (char*)malloc(strlen(_exe_name) + 3);
- sprintf(_gameDataPath, ":%s:", _exe_name);
- #endif
+void GameDetector::parseCommandLine(int argc, char **argv)
+{
+#if !defined(__APPLE__CW)
+ int i;
+ char *s;
+
+ // check for arguments
+ if (argc < 2) {
+ printf(USAGE_STRING);
+ //exit(1);
+ }
+
+ /* Parse the arguments */
+ for (i = 1; i < argc; i++) {
+ s = argv[i];
+
+ if (s && s[0] == '-') {
+ s++;
+ while (*s) {
+ switch (tolower(*s)) {
+ case 'a':
+ _restore = true;
+ break;
+ case 'b':
+ if (*(s + 1) == '\0')
+ goto ShowHelpAndExit;
+ _bootParam = atoi(s + 1);
+ goto NextArg;
+ case 'f':
+ _fullScreen = true;
+ break;
+ case 'd':
+ _debugMode = true;
+ break;
+ case 'n':
+ _noSubtitles = true;
+ break;
+ case 's':
+ if (*(s + 1) == '\0')
+ goto ShowHelpAndExit;
+ _scale = atoi(s + 1);
+ if (_scale == 0 || _scale > 3) {
+ // bad scale - only 1, 2, 3 work for now
+ printf("Invalid scale '%s' - valid values are 1, 2, 3\n", s + 1);
+ exit(1);
+ }
+ goto NextArg;
+ case 'v':
+ printf("ScummVM " SCUMMVM_VERSION "\nBuilt on " __DATE__ " "
+ __TIME__ "\n");
+#ifdef SCUMMVM_PLATFORM_VERSION
+ printf(" " SCUMMVM_PLATFORM_VERSION "\n");
+#endif
+ exit(1);
+ case 'p':
+ if (*(s + 1) == '\0')
+ goto ShowHelpAndExit;
+ _gameDataPath = s + 1;
+ goto NextArg;
+ case 't':
+ if (*(s + 1) == '\0')
+ goto ShowHelpAndExit;
+ _gameTempo = atoi(s + 1);
+ goto NextArg;
+ case 'm':{
+ if (*(s + 1) == '\0')
+ goto ShowHelpAndExit;
+ SoundEngine *se = (SoundEngine *)_soundEngine;
+
+ if (se)
+ se->set_music_volume(atoi(s + 1));
+ goto NextArg;
+ }
+ case 'r':{
+ SoundEngine *se = (SoundEngine *)_soundEngine;
+
+ if (se)
+ se->_mt32emulate = true;
+ break;
+ }
+ case 'e':
+ if (*(s + 1) == '\0')
+ goto ShowHelpAndExit;
+ _midi_driver = atoi(s + 1);
+ goto NextArg;
+ case 'g':
+ if (*(s + 1) == '\0')
+ goto ShowHelpAndExit;
+ _videoMode = atoi(s + 1);
+ goto NextArg;
+
+ case 'c':
+ if (*(s + 1) == '\0')
+ goto ShowHelpAndExit;
+ _cdrom = atoi(s + 1);
+ goto NextArg;
+
+ default:
+ ShowHelpAndExit:;
+ printf(USAGE_STRING);
+ exit(1);
+ }
+ s++;
+ }
+ NextArg:;
+ } else {
+ if (_exe_name)
+ goto ShowHelpAndExit;
+ _exe_name = s;
+ }
+ }
+
+#else
+ _midi_driver = 4;
+ _exe_name = *argv;
+ _gameDataPath = (char *)malloc(strlen(_exe_name) + 3);
+ sprintf(_gameDataPath, ":%s:", _exe_name);
+#endif
}
struct VersionSettings {
- const char *filename;
- const char *gamename;
- byte id,major,middle,minor;
- uint32 features;
+ const char *filename;
+ const char *gamename;
+ byte id, major, middle, minor;
+ uint32 features;
};
/*
@@ -177,118 +178,140 @@ struct VersionSettings {
supported at this time */
static const VersionSettings version_settings[] = {
- /* Scumm Version 1 */
+ /* Scumm Version 1 */
// {"maniac", "Maniac Mansion (C64)", GID_MANIAC64, 1, 0, 0,},
// {"zak", "Zak McKracken and the Alien Mindbenders (C64)", GID_ZAK64, 1, 0, 0,},
- /* Scumm Version 2 */
+ /* Scumm Version 2 */
// {"maniac", "Maniac Mansion", GID_MANIAC, 2, 0, 0,},
// {"zak", "Zak McKracken and the Alien Mindbenders", GID_ZAK, 2, 0, 0,},
// {"indy3", "Indiana Jones and the Last Crusade", GID_INDY3, 2, 0, 0,},
- /* Scumm Version 3 */
- {"indy3", "Indiana Jones and the Last Crusade (256)", GID_INDY3_256, 3, 0, 22, GF_SMALL_HEADER|GF_USE_KEY|GF_SMALL_NAMES|GF_OLD256|GF_NO_SCALLING},
- {"zak256", "Zak McKracken and the Alien Mindbenders (256)",GID_ZAK256, 3, 0, 0, GF_SMALL_HEADER|GF_USE_KEY|GF_SMALL_NAMES|GF_OLD256|GF_AUDIOTRACKS|GF_NO_SCALLING},
- {"loom", "Loom", GID_LOOM, 3, 5, 40, GF_SMALL_HEADER|GF_USE_KEY|GF_SMALL_NAMES|GF_OLD_BUNDLE|GF_16COLOR|GF_NO_SCALLING},
-
- /* Scumm Version 4 */
- {"monkeyEGA", "Monkey Island 1 (EGA)", GID_MONKEY_EGA, 4, 0, 67, GF_SMALL_HEADER|GF_USE_KEY|GF_16COLOR}, // EGA version
-
- /* Scumm version 5 */
- {"loomcd", "Loom (256 color CD version)", GID_LOOM256, 5, 1, 42, GF_SMALL_HEADER|GF_USE_KEY|GF_AUDIOTRACKS},
- {"monkey", "Monkey Island 1", GID_MONKEY, 5, 2, 2, GF_USE_KEY|GF_AUDIOTRACKS},
- {"monkey1", "Monkey Island 1 (alt)", GID_MONKEY, 5, 2, 2, GF_USE_KEY|GF_AUDIOTRACKS},
- {"monkey2", "Monkey Island 2: LeChuck's revenge", GID_MONKEY2, 5, 2, 2, GF_USE_KEY},
- {"atlantis", "Indiana Jones 4 and the Fate of Atlantis", GID_INDY4, 5, 5, 0, GF_USE_KEY},
- {"playfate", "Indiana Jones 4 and the Fate of Atlantis (Demo)", GID_INDY4, 5, 5, 0, GF_USE_KEY},
-
- /* Scumm Version 6 */
- {"tentacle", "Day Of The Tentacle", GID_TENTACLE, 6, 4, 2, GF_NEW_OPCODES|GF_AFTER_V6|GF_USE_KEY},
- {"dottdemo", "Day Of The Tentacle (Demo)", GID_TENTACLE, 6, 3, 2, GF_NEW_OPCODES|GF_AFTER_V6|GF_USE_KEY},
- {"samnmax", "Sam & Max", GID_SAMNMAX, 6, 4, 2, GF_NEW_OPCODES|GF_AFTER_V6|GF_USE_KEY|GF_DRAWOBJ_OTHER_ORDER},
- {"snmdemo", "Sam & Max (Demo)", GID_SAMNMAX, 6, 3, 0, GF_NEW_OPCODES|GF_AFTER_V6|GF_USE_KEY},
-
- /* Scumm Version 7 */
- {"ft", "Full Throttle", GID_FT, 7, 3, 0, GF_NEW_OPCODES|GF_AFTER_V6|GF_AFTER_V7},
- {"dig", "The Dig", GID_DIG, 7, 5, 0, GF_NEW_OPCODES|GF_AFTER_V6|GF_AFTER_V7},
-
- /* Scumm Version 8 */
-// {"curse", "The Curse of Monkey Island", GID_CMI, 8, 1, 0,},
- {NULL,NULL}
+ /* Scumm Version 3 */
+ {"indy3", "Indiana Jones and the Last Crusade (256)", GID_INDY3_256, 3, 0,
+ 22,
+ GF_SMALL_HEADER | GF_USE_KEY | GF_SMALL_NAMES | GF_OLD256 |
+ GF_NO_SCALLING},
+ {"zak256", "Zak McKracken and the Alien Mindbenders (256)", GID_ZAK256, 3,
+ 0, 0,
+ GF_SMALL_HEADER | GF_USE_KEY | GF_SMALL_NAMES | GF_OLD256 | GF_AUDIOTRACKS
+ | GF_NO_SCALLING},
+ {"loom", "Loom", GID_LOOM, 3, 5, 40,
+ GF_SMALL_HEADER | GF_USE_KEY | GF_SMALL_NAMES | GF_OLD_BUNDLE | GF_16COLOR
+ | GF_NO_SCALLING},
+
+ /* Scumm Version 4 */
+ {"monkeyEGA", "Monkey Island 1 (EGA)", GID_MONKEY_EGA, 4, 0, 67, GF_SMALL_HEADER | GF_USE_KEY | GF_16COLOR}, // EGA version
+
+ /* Scumm version 5 */
+ {"loomcd", "Loom (256 color CD version)", GID_LOOM256, 5, 1, 42,
+ GF_SMALL_HEADER | GF_USE_KEY | GF_AUDIOTRACKS},
+ {"monkey", "Monkey Island 1", GID_MONKEY, 5, 2, 2,
+ GF_USE_KEY | GF_AUDIOTRACKS},
+ {"monkey1", "Monkey Island 1 (alt)", GID_MONKEY, 5, 2, 2,
+ GF_USE_KEY | GF_AUDIOTRACKS},
+ {"monkey2", "Monkey Island 2: LeChuck's revenge", GID_MONKEY2, 5, 2, 2,
+ GF_USE_KEY},
+ {"atlantis", "Indiana Jones 4 and the Fate of Atlantis", GID_INDY4, 5, 5, 0,
+ GF_USE_KEY},
+ {"playfate", "Indiana Jones 4 and the Fate of Atlantis (Demo)", GID_INDY4,
+ 5, 5, 0, GF_USE_KEY},
+
+ /* Scumm Version 6 */
+ {"tentacle", "Day Of The Tentacle", GID_TENTACLE, 6, 4, 2,
+ GF_NEW_OPCODES | GF_AFTER_V6 | GF_USE_KEY},
+ {"dottdemo", "Day Of The Tentacle (Demo)", GID_TENTACLE, 6, 3, 2,
+ GF_NEW_OPCODES | GF_AFTER_V6 | GF_USE_KEY},
+ {"samnmax", "Sam & Max", GID_SAMNMAX, 6, 4, 2,
+ GF_NEW_OPCODES | GF_AFTER_V6 | GF_USE_KEY | GF_DRAWOBJ_OTHER_ORDER},
+ {"snmdemo", "Sam & Max (Demo)", GID_SAMNMAX, 6, 3, 0,
+ GF_NEW_OPCODES | GF_AFTER_V6 | GF_USE_KEY},
+
+ /* Scumm Version 7 */
+ {"ft", "Full Throttle", GID_FT, 7, 3, 0,
+ GF_NEW_OPCODES | GF_AFTER_V6 | GF_AFTER_V7},
+ {"dig", "The Dig", GID_DIG, 7, 5, 0,
+ GF_NEW_OPCODES | GF_AFTER_V6 | GF_AFTER_V7},
+
+ /* Scumm Version 8 */
+// {"curse", "The Curse of Monkey Island", GID_CMI, 8, 1, 0,},
+ {NULL, NULL}
};
-bool GameDetector::detectGame() {
- const VersionSettings *gnl = version_settings;
-
- _gameId = 0;
- _gameText = NULL;
- do {
- if (!scumm_stricmp(_exe_name, gnl->filename)) {
- _gameId = gnl->id;
- _scummVersion = gnl->major;
-
- _features = gnl->features;
- _gameText = gnl->gamename;
- debug(1, "Detected game '%s', version %d.%d.%d",
- gnl->gamename, gnl->major, gnl->middle, gnl->minor);
- return true;
- }
- } while ((++gnl)->filename);
-
- debug(1, "Failed game detection");
-
- return true;
+bool GameDetector::detectGame()
+{
+ const VersionSettings *gnl = version_settings;
+
+ _gameId = 0;
+ _gameText = NULL;
+ do {
+ if (!scumm_stricmp(_exe_name, gnl->filename)) {
+ _gameId = gnl->id;
+ _scummVersion = gnl->major;
+
+ _features = gnl->features;
+ _gameText = gnl->gamename;
+ debug(1, "Detected game '%s', version %d.%d.%d",
+ gnl->gamename, gnl->major, gnl->middle, gnl->minor);
+ return true;
+ }
+ } while ((++gnl)->filename);
+
+ debug(1, "Failed game detection");
+
+ return true;
}
-char *GameDetector::getGameName() {
- if (_gameText==NULL) {
- char buf[256];
- sprintf(buf, "Unknown game: \"%s\"", _exe_name);
- return strdup(buf);
- }
- return strdup(_gameText);
+char *GameDetector::getGameName()
+{
+ if (_gameText == NULL) {
+ char buf[256];
+ sprintf(buf, "Unknown game: \"%s\"", _exe_name);
+ return strdup(buf);
+ }
+ return strdup(_gameText);
}
int GameDetector::detectMain(int argc, char **argv)
{
- _debugMode = 0; // off by default...
-
- _noSubtitles = 0; // use by default - should this depend on soundtrack?
- _scale = 2; // double size by default
-
- _gameDataPath = NULL;
- _gameTempo = 0;
- _videoMode = 0;
- _soundCardType = 3;
-
- #ifdef WIN32
- _midi_driver = MIDI_WINDOWS;
- #else
- _midi_driver = MIDI_NULL;
- #endif
-
+ _debugMode = 0; // off by default...
+
+ _noSubtitles = 0; // use by default - should this depend on soundtrack?
+ _scale = 2; // double size by default
+
+ _gameDataPath = NULL;
+ _gameTempo = 0;
+ _videoMode = 0;
+ _soundCardType = 3;
+
+#ifdef WIN32
+ _midi_driver = MIDI_WINDOWS;
+#else
+ _midi_driver = MIDI_NULL;
+#endif
+
parseCommandLine(argc, argv);
- if (_exe_name==NULL) {
+ if (_exe_name == NULL) {
//launcherLoop();
//setWindowName(this);
warning("No game was specified...");
- return(-1);
+ return (-1);
}
-
- if (!detectGame()) {
- warning("Game detection failed. Using default settings");
- _features = GF_DEFAULT;
- _gameText = "Please choose a game";
- }
- if (!_gameDataPath) {
- warning("No path was provided. Assuming that data file are in the current directory");
- _gameDataPath = (char *)malloc(sizeof(char) * 2);
- strcpy(_gameDataPath, "");
- }
+ if (!detectGame()) {
+ warning("Game detection failed. Using default settings");
+ _features = GF_DEFAULT;
+ _gameText = "Please choose a game";
+ }
- return(0);
-}
+ if (!_gameDataPath) {
+ warning
+ ("No path was provided. Assuming that data file are in the current directory");
+ _gameDataPath = (char *)malloc(sizeof(char) * 2);
+ strcpy(_gameDataPath, "");
+ }
+ return (0);
+}
diff --git a/gfx.cpp b/gfx.cpp
index 4818e66de3..09cf4ac4c7 100644
--- a/gfx.cpp
+++ b/gfx.cpp
@@ -22,56 +22,60 @@
#include "stdafx.h"
#include "scumm.h"
-void Scumm::getGraphicsPerformance() {
+void Scumm::getGraphicsPerformance()
+{
int i;
- for (i=10; i!=0; i--) {
+ for (i = 10; i != 0; i--) {
initScreens(0, 0, 320, 200);
}
- _vars[VAR_PERFORMANCE_1] = 0;//_scummTimer;
+ _vars[VAR_PERFORMANCE_1] = 0; //_scummTimer;
- for (i=10; i!=0; i--) {
+ for (i = 10; i != 0; i--) {
setDirtyRange(0, 0, 200);
drawDirtyScreenParts();
}
- _vars[VAR_PERFORMANCE_2] = 0;//_scummTimer;
+ _vars[VAR_PERFORMANCE_2] = 0; //_scummTimer;
- if(_gameId == GID_DIG)
+ if (_gameId == GID_DIG)
initScreens(0, 0, 320, 200);
else
initScreens(0, 16, 320, 144);
}
-void Scumm::initScreens(int a, int b, int w, int h) {
+void Scumm::initScreens(int a, int b, int w, int h)
+{
int i;
-
- for (i=0; i<3; i++) {
-// nukeResource(rtBuffer, i+1);
- nukeResource(rtBuffer, i+5);
+
+ for (i = 0; i < 3; i++) {
+// nukeResource(rtBuffer, i+1);
+ nukeResource(rtBuffer, i + 5);
}
- if (!getResourceAddress(rtBuffer,4)) {
+ if (!getResourceAddress(rtBuffer, 4)) {
initVirtScreen(3, 80, 13, false, false);
}
- initVirtScreen(0, b, h-b, true, true);
+ initVirtScreen(0, b, h - b, true, true);
initVirtScreen(1, 0, b, false, false);
- initVirtScreen(2, h, 200-h, false, false);
+ initVirtScreen(2, h, 200 - h, false, false);
_screenB = b;
_screenH = h;
}
-void Scumm::initVirtScreen(int slot, int top, int height, bool twobufs, bool fourextra) {
+void Scumm::initVirtScreen(int slot, int top, int height, bool twobufs,
+ bool fourextra)
+{
VirtScreen *vs = &virtscr[slot];
int size;
int i;
byte *ptr;
- assert(height>=0);
- assert(slot>=0 && slot<4);
+ assert(height >= 0);
+ assert(slot >= 0 && slot < 4);
vs->number = slot;
vs->unk1 = 0;
@@ -86,17 +90,17 @@ void Scumm::initVirtScreen(int slot, int top, int height, bool twobufs, bool fou
vs->backBuf = NULL;
if (vs->scrollable)
- size += 320*4;
-// createResource(rtBuffer, slot+1, size);
+ size += 320 * 4;
+// createResource(rtBuffer, slot+1, size);
+
+ vs->screenPtr = _videoBuffer + 328 * top;
- vs->screenPtr = _videoBuffer+328*top;
+ ptr = vs->screenPtr;
+ for (i = 0; i < size; i++) // reset background ?
+ *ptr++ = 0;
- ptr=vs->screenPtr;
- for(i=0;i<size;i++) // reset background ?
- *ptr++=0;
-
if (twobufs) {
- createResource(rtBuffer, slot+5, size);
+ createResource(rtBuffer, slot + 5, size);
}
if (slot != 3) {
@@ -104,10 +108,11 @@ void Scumm::initVirtScreen(int slot, int top, int height, bool twobufs, bool fou
}
}
-void Scumm::setDirtyRange(int slot, int top, int bottom) {
+void Scumm::setDirtyRange(int slot, int top, int bottom)
+{
int i;
VirtScreen *vs = &virtscr[slot];
- for (i=0; i<40; i++) {
+ for (i = 0; i < 40; i++) {
vs->tdirty[i] = top;
vs->bdirty[i] = bottom;
}
@@ -117,27 +122,29 @@ void Scumm::setDirtyRange(int slot, int top, int bottom) {
#define NUM_SHAKE_POSITIONS 8
static const int8 shake_positions[NUM_SHAKE_POSITIONS] = {
- 0,1*2,2*2,1*2,0*2,2*2,3*2,1*2
+ 0, 1 * 2, 2 * 2, 1 * 2, 0 * 2, 2 * 2, 3 * 2, 1 * 2
};
-void Scumm::drawDirtyScreenParts() {
+void Scumm::drawDirtyScreenParts()
+{
int i;
VirtScreen *vs;
updateDirtyScreen(2);
- if (_features & GF_OLD256)
+ if (_features & GF_OLD256)
updateDirtyScreen(1);
- if ((camera._last.x==camera._cur.x &&
- camera._last.y==camera._cur.y && (_features & GF_AFTER_V7)) || (camera._last.x == camera._cur.x)) {
+ if ((camera._last.x == camera._cur.x &&
+ camera._last.y == camera._cur.y && (_features & GF_AFTER_V7))
+ || (camera._last.x == camera._cur.x)) {
updateDirtyScreen(0);
} else {
vs = &virtscr[0];
- blitToScreen(this, vs->screenPtr + _screenStartStrip*8,
- 0, vs->topline, 320, vs->height);
+ blitToScreen(this, vs->screenPtr + _screenStartStrip * 8,
+ 0, vs->topline, 320, vs->height);
- for (i = 0; i<40; i++) {
+ for (i = 0; i < 40; i++) {
vs->tdirty[i] = (byte)vs->height;
vs->bdirty[i] = 0;
}
@@ -145,25 +152,28 @@ void Scumm::drawDirtyScreenParts() {
/* Handle shaking */
if (_shakeEnabled) {
- _shakeFrame = (_shakeFrame + 1) & (NUM_SHAKE_POSITIONS-1);
- setShakePos(this,shake_positions[_shakeFrame]);
+ _shakeFrame = (_shakeFrame + 1) & (NUM_SHAKE_POSITIONS - 1);
+ setShakePos(this, shake_positions[_shakeFrame]);
}
}
-void Scumm::redrawLines(int from, int to) {
+void Scumm::redrawLines(int from, int to)
+{
VirtScreen *vs = virtscr;
- int i,j;
-
- if (to<=from)
+ int i, j;
+
+ if (to <= from)
return;
-
- for(i=0; i!=ARRAYSIZE(virtscr); i++,vs++) {
+
+ for (i = 0; i != ARRAYSIZE(virtscr); i++, vs++) {
if (to > vs->topline && from < vs->topline + vs->height) {
int min = from - vs->topline;
int max = to - vs->topline;
- if (min < 0) min = 0;
- if (max > vs->height) max = vs->height;
- for (j=0; j!=40; j++) {
+ if (min < 0)
+ min = 0;
+ if (max > vs->height)
+ max = vs->height;
+ for (j = 0; j != 40; j++) {
vs->tdirty[j] = min;
vs->bdirty[j] = max;
}
@@ -172,15 +182,17 @@ void Scumm::redrawLines(int from, int to) {
}
}
-void Scumm::updateDirtyScreen(int slot) {
+void Scumm::updateDirtyScreen(int slot)
+{
gdi.updateDirtyScreen(&virtscr[slot]);
}
-void Gdi::updateDirtyScreen(VirtScreen *vs) {
+void Gdi::updateDirtyScreen(VirtScreen * vs)
+{
int i;
- int start,w,top,bottom;
+ int start, w, top, bottom;
- if (vs->height==0)
+ if (vs->height == 0)
return;
_readOffs = 0;
@@ -190,24 +202,26 @@ void Gdi::updateDirtyScreen(VirtScreen *vs) {
w = 8;
start = 0;
- for (i=0; i<40; i++) {
+ 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) {
+ if (i != 39 && vs->bdirty[i + 1] == (byte)bottom
+ && vs->tdirty[i + 1] == (byte)top) {
w += 8;
continue;
}
drawStripToScreen(vs, start, w, top, bottom);
w = 8;
}
- start = i+1;
+ start = i + 1;
}
}
-void Gdi::drawStripToScreen(VirtScreen *vs, int x, int w, int t, int b) {
+void Gdi::drawStripToScreen(VirtScreen * vs, int x, int w, int t, int b)
+{
byte *ptr;
if (b <= t)
@@ -219,12 +233,13 @@ void Gdi::drawStripToScreen(VirtScreen *vs, int x, int w, int t, int b) {
if (b > vs->height)
b = vs->height;
- ptr = vs->screenPtr + (t*40+x)*8 + _readOffs;
- blitToScreen(_vm, ptr, x*8, vs->topline+t, w, b-t);
+ ptr = vs->screenPtr + (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);
+void blit(byte *dst, byte *src, int w, int h)
+{
+ assert(h > 0);
do {
memcpy(dst, src, w);
dst += 320;
@@ -232,13 +247,15 @@ void blit(byte *dst, byte *src, int w, int h) {
} while (--h);
}
-void Scumm::setCursor(int cursor) {
+void Scumm::setCursor(int cursor)
+{
warning("setCursor(%d)", cursor);
}
-void Scumm::setCameraAt(int pos_x, int pos_y) {
+void Scumm::setCameraAt(int pos_x, int pos_y)
+{
- if(_features & GF_AFTER_V7) {
+ if (_features & GF_AFTER_V7) {
CameraData *cd = &camera;
ScummPoint old;
@@ -251,9 +268,10 @@ void Scumm::setCameraAt(int pos_x, int pos_y) {
cd->_dest = cd->_cur;
- assert(cd->_cur.x>=160 && cd->_cur.y>=100);
+ assert(cd->_cur.x >= 160 && cd->_cur.y >= 100);
- if ((cd->_cur.x != old.x || cd->_cur.y != old.y) && _vars[VAR_SCROLL_SCRIPT]) {
+ if ((cd->_cur.x != old.x || cd->_cur.y != old.y)
+ && _vars[VAR_SCROLL_SCRIPT]) {
_vars[VAR_CAMERA_POS_X] = cd->_cur.x;
_vars[VAR_CAMERA_POS_Y] = cd->_cur.y;
runScript(_vars[VAR_SCROLL_SCRIPT], 0, 0, 0);
@@ -262,16 +280,18 @@ void Scumm::setCameraAt(int pos_x, int pos_y) {
int t;
CameraData *cd = &camera;
- if (cd->_mode!=CM_FOLLOW_ACTOR || abs(pos_x - cd->_cur.x) > 160) {
+ if (cd->_mode != CM_FOLLOW_ACTOR || abs(pos_x - cd->_cur.x) > 160) {
cd->_cur.x = pos_x;
}
cd->_dest.x = pos_x;
t = _vars[VAR_CAMERA_MIN_X];
- if (cd->_cur.x < t) cd->_cur.x = t;
+ if (cd->_cur.x < t)
+ cd->_cur.x = t;
t = _vars[VAR_CAMERA_MAX_X];
- if (cd->_cur.x > t) cd->_cur.x = t;
+ if (cd->_cur.x > t)
+ cd->_cur.x = t;
if (_vars[VAR_SCROLL_SCRIPT]) {
_vars[VAR_CAMERA_POS_X] = cd->_cur.x;
@@ -283,106 +303,107 @@ void Scumm::setCameraAt(int pos_x, int pos_y) {
}
}
-void Scumm::setCameraFollows(Actor *a) {
- if(_features & GF_AFTER_V7) {
+void Scumm::setCameraFollows(Actor * a)
+{
+ if (_features & GF_AFTER_V7) {
CameraData *cd = &camera;
byte oldfollow = cd->_follows;
- int ax,ay;
-
+ int ax, ay;
+
cd->_follows = a->number;
if (a->room != _currentRoom) {
startScene(a->room, 0, 0);
}
-
+
ax = abs(a->x - cd->_cur.x);
ay = abs(a->y - cd->_cur.y);
- if ( ax > _vars[VAR_CAMERA_THRESHOLD_X] ||
- ay > _vars[VAR_CAMERA_THRESHOLD_Y] ||
- ax > 160 ||
- ay > 100) {
+ if (ax > _vars[VAR_CAMERA_THRESHOLD_X] ||
+ ay > _vars[VAR_CAMERA_THRESHOLD_Y] || ax > 160 || ay > 100) {
setCameraAt(a->x, a->y);
}
if (a->number != oldfollow)
runHook(0);
} else {
- int t,i;
+ int t, i;
CameraData *cd = &camera;
cd->_mode = CM_FOLLOW_ACTOR;
cd->_follows = a->number;
-
+
if (a->room != _currentRoom) {
startScene(a->room, 0, 0);
cd->_mode = CM_FOLLOW_ACTOR;
cd->_cur.x = a->x;
setCameraAt(cd->_cur.x, 0);
}
-
+
t = (a->x >> 3);
-
- if (t-_screenStartStrip < cd->_leftTrigger ||
- t-_screenStartStrip > cd->_rightTrigger)
+
+ if (t - _screenStartStrip < cd->_leftTrigger ||
+ t - _screenStartStrip > cd->_rightTrigger)
setCameraAt(a->x, 0);
-
- for (i=1,a=getFirstActor(); ++a,i<NUM_ACTORS; i++) {
- if (a->room==_currentRoom)
+
+ for (i = 1, a = getFirstActor(); ++a, i < NUM_ACTORS; i++) {
+ if (a->room == _currentRoom)
a->needRedraw = true;
}
runHook(0);
}
}
-void Scumm::initBGBuffers() {
+void Scumm::initBGBuffers()
+{
byte *ptr;
int size, itemsize, i;
byte *room;
room = getResourceAddress(rtRoom, _roomResource);
- if(_features & GF_SMALL_HEADER) {
- gdi._numZBuffer = 1;
- } else {
- ptr = findResource(MKID('RMIH'), findResource(MKID('RMIM'), room));
- gdi._numZBuffer = READ_LE_UINT16(ptr+8) + 1;
- }
- assert(gdi._numZBuffer>=1 && gdi._numZBuffer<=5);
-
+ if (_features & GF_SMALL_HEADER) {
+ gdi._numZBuffer = 1;
+ } else {
+ ptr = findResource(MKID('RMIH'), findResource(MKID('RMIM'), room));
+ gdi._numZBuffer = READ_LE_UINT16(ptr + 8) + 1;
+ }
+ assert(gdi._numZBuffer >= 1 && gdi._numZBuffer <= 5);
+
itemsize = (_scrHeight + 4) * 40;
size = itemsize * gdi._numZBuffer;
createResource(rtBuffer, 9, size);
-
- for (i=0; i<4; i++)
- gdi._imgBufOffs[i] = i*itemsize;
+
+ for (i = 0; i < 4; i++)
+ gdi._imgBufOffs[i] = i * itemsize;
}
-void Scumm::setPaletteFromPtr(byte *ptr) {
+void Scumm::setPaletteFromPtr(byte *ptr)
+{
int i, r, g, b;
byte *dest;
int numcolor;
- if( _features & GF_SMALL_HEADER ) {
- if (_features & GF_OLD256)
- numcolor = 256;
- else
- numcolor = READ_LE_UINT16(ptr+6) / 3;
- ptr+=8;
- } else {
- numcolor = getResourceDataSize(ptr) / 3;
- }
+ if (_features & GF_SMALL_HEADER) {
+ if (_features & GF_OLD256)
+ numcolor = 256;
+ else
+ numcolor = READ_LE_UINT16(ptr + 6) / 3;
+ ptr += 8;
+ } else {
+ numcolor = getResourceDataSize(ptr) / 3;
+ }
checkRange(256, 0, numcolor, "Too many colors (%d) in Palette");
dest = _currentPalette;
- for (i=0; i<numcolor; i++) {
+ for (i = 0; i < numcolor; i++) {
r = *ptr++;
g = *ptr++;
b = *ptr++;
- if (i<=15 || r<252 || g<252 || b<252) {
+ if (i <= 15 || r < 252 || g < 252 || b < 252) {
*dest++ = r;
*dest++ = g;
*dest++ = b;
@@ -391,34 +412,37 @@ void Scumm::setPaletteFromPtr(byte *ptr) {
}
}
- setDirtyColors(0, numcolor-1);
+ setDirtyColors(0, numcolor - 1);
}
-void Scumm::setPaletteFromRes() {
+void Scumm::setPaletteFromRes()
+{
byte *ptr;
ptr = getResourceAddress(rtRoom, _roomResource) + _CLUT_offs;
setPaletteFromPtr(ptr);
}
-void Scumm::setDirtyColors(int min, int max) {
+void Scumm::setDirtyColors(int min, int max)
+{
if (_palDirtyMin > min)
_palDirtyMin = min;
if (_palDirtyMax < max)
_palDirtyMax = max;
}
-void Scumm::initCycl(byte *ptr) {
+void Scumm::initCycl(byte *ptr)
+{
int j;
ColorCycle *cycl;
memset(_colorCycle, 0, sizeof(_colorCycle));
-
- while ((j=*ptr++) != 0) {
- if (j<1 || j>16) {
+
+ while ((j = *ptr++) != 0) {
+ if (j < 1 || j > 16) {
error("Invalid color cycle index %d", j);
}
- cycl = &_colorCycle[j-1];
+ cycl = &_colorCycle[j - 1];
ptr += 2;
cycl->counter = 0;
@@ -431,20 +455,22 @@ void Scumm::initCycl(byte *ptr) {
}
}
-void Scumm::stopCycle(int i) {
+void Scumm::stopCycle(int i)
+{
ColorCycle *cycl;
checkRange(16, 0, i, "Stop Cycle %d Out Of Range");
- if (i!=0) {
- _colorCycle[i-1].delay = 0;
+ if (i != 0) {
+ _colorCycle[i - 1].delay = 0;
return;
}
- for (i=0,cycl=_colorCycle; i<16; i++,cycl++)
+ for (i = 0, cycl = _colorCycle; i < 16; i++, cycl++)
cycl->delay = 0;
}
-void Scumm::cyclePalette() {
+void Scumm::cyclePalette()
+{
ColorCycle *cycl;
int valueToAdd;
int i, num;
@@ -455,44 +481,44 @@ void Scumm::cyclePalette() {
if (valueToAdd < _vars[VAR_TIMER_NEXT])
valueToAdd = _vars[VAR_TIMER_NEXT];
- if (!_colorCycle) // FIXME
+ if (!_colorCycle) // FIXME
return;
- for (i=0,cycl=_colorCycle; i<16; i++,cycl++) {
- if (cycl->delay &&
- (cycl->counter+=valueToAdd) >= cycl->delay) {
+ for (i = 0, cycl = _colorCycle; i < 16; i++, cycl++) {
+ if (cycl->delay && (cycl->counter += valueToAdd) >= cycl->delay) {
do {
cycl->counter -= cycl->delay;
} while (cycl->delay <= cycl->counter);
setDirtyColors(cycl->start, cycl->end);
- moveMemInPalRes(cycl->start, cycl->end, cycl->flags&2);
- start = &_currentPalette[cycl->start*3];
- end = &_currentPalette[cycl->end*3];
+ moveMemInPalRes(cycl->start, cycl->end, cycl->flags & 2);
+ start = &_currentPalette[cycl->start * 3];
+ end = &_currentPalette[cycl->end * 3];
num = cycl->end - cycl->start;
- if (!(cycl->flags&2)) {
+ if (!(cycl->flags & 2)) {
memmove(tmp, end, 3);
- memmove(start+3, start, num*3);
+ memmove(start + 3, start, num * 3);
memmove(start, tmp, 3);
} else {
memmove(tmp, start, 3);
- memmove(start, start+3, num*3);
+ memmove(start, start + 3, num * 3);
memmove(end, tmp, 3);
}
}
}
}
-void Scumm::moveMemInPalRes(int start, int end, byte direction) {
+void Scumm::moveMemInPalRes(int start, int end, byte direction)
+{
byte *startptr, *endptr;
byte *startptr2, *endptr2;
int num;
byte tmp[6];
byte tmp2[6];
- if (!_palManipCounter)
+ if (!_palManipCounter)
return;
startptr = getResourceAddress(rtTemp, 4) + start * 6;
@@ -510,41 +536,44 @@ void Scumm::moveMemInPalRes(int start, int end, byte direction) {
if (!direction) {
memmove(tmp, endptr, 6);
- memmove(startptr+6, startptr, num*6);
+ memmove(startptr + 6, startptr, num * 6);
memmove(startptr, tmp, 6);
memmove(tmp2, endptr2, 6);
- memmove(startptr2+6, startptr2, num*6);
+ memmove(startptr2 + 6, startptr2, num * 6);
memmove(startptr2, tmp2, 6);
} else {
memmove(tmp, startptr, 6);
- memmove(startptr, startptr+6, num*6);
+ memmove(startptr, startptr + 6, num * 6);
memmove(endptr, tmp, 6);
memmove(tmp2, startptr2, 6);
- memmove(startptr2, startptr2+6, num*6);
+ memmove(startptr2, startptr2 + 6, num * 6);
memmove(endptr2, tmp2, 6);
}
}
-void Scumm::unkVirtScreen4(int a) {
+void Scumm::unkVirtScreen4(int a)
+{
VirtScreen *vs;
setDirtyRange(0, 0, 0);
- if(!(_features & GF_AFTER_V7))
+ if (!(_features & GF_AFTER_V7))
camera._last.x = camera._cur.x;
if (!_screenEffectFlag)
return;
_screenEffectFlag = false;
-
- if (a==0)
+
+ if (a == 0)
return;
vs = &virtscr[0];
gdi._backbuff_ptr = vs->screenPtr + vs->xstart;
memset(gdi._backbuff_ptr, 0, vs->size);
- switch(a) {
- case 1: case 2: case 3:
- unkScreenEffect7(a-1);
+ switch (a) {
+ case 1:
+ case 2:
+ case 3:
+ unkScreenEffect7(a - 1);
break;
case 128:
unkScreenEffect6();
@@ -553,7 +582,7 @@ void Scumm::unkVirtScreen4(int a) {
//setDirtyRange(0, 0, vs->height);
//updateDirtyScreen(0);
/* XXX: EGA_proc4(0); */
- warning("EGA_proc4"); /* FIXME */
+ warning("EGA_proc4"); /* FIXME */
break;
case 134:
unkScreenEffect5(0);
@@ -566,47 +595,48 @@ void Scumm::unkVirtScreen4(int a) {
}
}
-void Scumm::redrawBGAreas() {
+void Scumm::redrawBGAreas()
+{
int i;
int val;
CameraData *cd = &camera;
int diff;
if (!(_features & GF_AFTER_V7))
- if (cd->_cur.x!=cd->_last.x && charset._hasMask)
+ if (cd->_cur.x != cd->_last.x && charset._hasMask)
stopTalk();
val = 0;
if (!_fullRedraw && _BgNeedsRedraw) {
- for (i=0; i!=40; i++) {
- if (gfxUsageBits[_screenStartStrip + i]&0x80000000) {
+ for (i = 0; i != 40; i++) {
+ if (gfxUsageBits[_screenStartStrip + i] & 0x80000000) {
redrawBGStrip(i, 1);
}
}
}
- if(_features & GF_AFTER_V7) {
- diff = (cd->_cur.x>>3) - (cd->_last.x>>3);
- if (_fullRedraw==0 && diff==1) {
+ if (_features & GF_AFTER_V7) {
+ diff = (cd->_cur.x >> 3) - (cd->_last.x >> 3);
+ if (_fullRedraw == 0 && diff == 1) {
val = 2;
redrawBGStrip(39, 1);
- } else if (_fullRedraw==0 && diff==-1) {
+ } else if (_fullRedraw == 0 && diff == -1) {
val = 1;
redrawBGStrip(0, 1);
- } else if (_fullRedraw!=0 || diff!=0) {
+ } else if (_fullRedraw != 0 || diff != 0) {
_BgNeedsRedraw = false;
_fullRedraw = false;
redrawBGStrip(0, 40);
}
} else {
- if (_fullRedraw==0 && cd->_cur.x - cd->_last.x == 8) {
+ if (_fullRedraw == 0 && cd->_cur.x - cd->_last.x == 8) {
val = 2;
redrawBGStrip(39, 1);
- } else if (_fullRedraw==0 && cd->_cur.x - cd->_last.x == -8) {
+ } else if (_fullRedraw == 0 && cd->_cur.x - cd->_last.x == -8) {
val = 1;
redrawBGStrip(0, 1);
- } else if (_fullRedraw!=0 || cd->_cur.x != cd->_last.x) {
+ } else if (_fullRedraw != 0 || cd->_cur.x != cd->_last.x) {
_BgNeedsRedraw = false;
redrawBGStrip(0, 40);
}
@@ -624,8 +654,10 @@ const uint32 zplane_tags[] = {
MKID('ZP04')
};
-void Gdi::drawBitmap(byte *ptr, VirtScreen *vs, int x, int y, int h, int stripnr, int numstrip, byte flag) {
- byte *smap_ptr,*where_draw_ptr;
+void Gdi::drawBitmap(byte *ptr, VirtScreen * vs, int x, int y, int h,
+ int stripnr, int numstrip, byte flag)
+{
+ byte *smap_ptr, *where_draw_ptr;
int i;
byte *zplane_list[4];
int bottom;
@@ -633,24 +665,23 @@ void Gdi::drawBitmap(byte *ptr, VirtScreen *vs, int x, int y, int h, int stripnr
int numzbuf;
int sx;
- CHECK_HEAP
-
- if(_vm->_features & GF_SMALL_HEADER)
- smap_ptr = _smap_ptr = ptr;
- else
- smap_ptr = findResource(MKID('SMAP'), ptr);
+ CHECK_HEAP if (_vm->_features & GF_SMALL_HEADER)
+ smap_ptr = _smap_ptr = ptr;
+ else
+ smap_ptr = findResource(MKID('SMAP'), ptr);
assert(smap_ptr);
numzbuf = _disable_zbuffer ? 0 : _numZBuffer;
- for(i=1; i<numzbuf; i++) {
+ for (i = 1; i < numzbuf; i++) {
zplane_list[i] = findResource(zplane_tags[i], ptr);
}
bottom = y + h;
if (bottom > vs->height) {
- error("Gdi::drawBitmap, strip drawn to %d below window bottom %d", bottom, vs->height);
+ error("Gdi::drawBitmap, strip drawn to %d below window bottom %d", bottom,
+ vs->height);
}
twobufs = vs->alloctwobuffers;
@@ -660,82 +691,80 @@ void Gdi::drawBitmap(byte *ptr, VirtScreen *vs, int x, int y, int h, int stripnr
_numLinesToProcess = h;
do {
- if(_vm->_features & GF_SMALL_HEADER)
- _smap_ptr = smap_ptr + READ_LE_UINT32(smap_ptr + stripnr*4 + 4);
- else
- _smap_ptr = smap_ptr + READ_LE_UINT32(smap_ptr + stripnr*4 + 8);
-
- CHECK_HEAP
+ if (_vm->_features & GF_SMALL_HEADER)
+ _smap_ptr = smap_ptr + READ_LE_UINT32(smap_ptr + stripnr * 4 + 4);
+ else
+ _smap_ptr = smap_ptr + READ_LE_UINT32(smap_ptr + stripnr * 4 + 8);
- sx = x;
+ CHECK_HEAP sx = x;
if (vs->scrollable)
- sx -= vs->xstart>>3;
-
- if ((uint)sx >= 40)
+ sx -= vs->xstart >> 3;
+
+ if ((uint) sx >= 40)
return;
if (y < vs->tdirty[sx])
- vs->tdirty[sx]=y;
+ vs->tdirty[sx] = y;
if (bottom > vs->bdirty[sx])
vs->bdirty[sx] = bottom;
-
- _backbuff_ptr = vs->screenPtr + (y*40+x)*8;
- _bgbak_ptr = _vm->getResourceAddress(rtBuffer, vs->number+5) + (y*40+x)*8;
+
+ _backbuff_ptr = vs->screenPtr + (y * 40 + x) * 8;
+ _bgbak_ptr =
+ _vm->getResourceAddress(rtBuffer, vs->number + 5) + (y * 40 + x) * 8;
if (!twobufs) {
_bgbak_ptr = _backbuff_ptr;
}
- _mask_ptr = _vm->getResourceAddress(rtBuffer, 9) + (y*40+x);
+ _mask_ptr = _vm->getResourceAddress(rtBuffer, 9) + (y * 40 + x);
where_draw_ptr = _bgbak_ptr;
decompressBitmap();
- CHECK_HEAP
-
- if (twobufs) {
+ CHECK_HEAP if (twobufs) {
_bgbak_ptr = where_draw_ptr;
-
- if (_vm->hasCharsetMask(sx<<3, y, (sx+1)<<3, bottom)) {
- if (flag&dbClear)
+
+ if (_vm->hasCharsetMask(sx << 3, y, (sx + 1) << 3, bottom)) {
+ if (flag & dbClear)
clear8ColWithMasking();
else
draw8ColWithMasking();
} else {
- if (flag&dbClear)
+ if (flag & dbClear)
clear8Col();
else
blit(_backbuff_ptr, _bgbak_ptr, 8, h);
}
}
- CHECK_HEAP
-
- if (flag & dbDrawMaskOnBoth) {
- _z_plane_ptr = zplane_list[1] + READ_LE_UINT16(zplane_list[1] + stripnr*2 + 8);
- _mask_ptr_dest = _vm->getResourceAddress(rtBuffer, 9) + y*40 + x;
- if (_useOrDecompress && flag&dbAllowMaskOr)
+ CHECK_HEAP if (flag & dbDrawMaskOnBoth) {
+ _z_plane_ptr =
+ zplane_list[1] + READ_LE_UINT16(zplane_list[1] + stripnr * 2 + 8);
+ _mask_ptr_dest = _vm->getResourceAddress(rtBuffer, 9) + y * 40 + x;
+ if (_useOrDecompress && flag & dbAllowMaskOr)
decompressMaskImgOr();
else
decompressMaskImg();
}
- for (i=1; i<numzbuf; i++) {
+ for (i = 1; i < numzbuf; i++) {
if (!zplane_list[i])
continue;
- _z_plane_ptr = zplane_list[i] + READ_LE_UINT16(zplane_list[i] + stripnr*2 + 8);
- _mask_ptr_dest = _vm->getResourceAddress(rtBuffer, 9) + y*40 + x + _imgBufOffs[i];
- if (_useOrDecompress && flag&dbAllowMaskOr)
+ _z_plane_ptr =
+ zplane_list[i] + READ_LE_UINT16(zplane_list[i] + stripnr * 2 + 8);
+ _mask_ptr_dest =
+ _vm->getResourceAddress(rtBuffer, 9) + y * 40 + x + _imgBufOffs[i];
+ if (_useOrDecompress && flag & dbAllowMaskOr)
decompressMaskImgOr();
else
decompressMaskImg();
}
- CHECK_HEAP
- x++;
+ CHECK_HEAP x++;
stripnr++;
} while (--numstrip);
}
-void Gdi::decompressBitmap() {
+void Gdi::decompressBitmap()
+{
const byte decompress_table[] = {
0x0, 0x1, 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F, 0xFF, 0x0,
};
@@ -746,75 +775,107 @@ void Gdi::decompressBitmap() {
assert(_numLinesToProcess);
- switch(code) {
+ switch (code) {
case 1:
unkDecode7();
break;
- case 2:
- unkDecode8(); /* Ender - Zak256/Indy256 */
- break;
-
- case 3:
- unkDecode9(); /* Ender - Zak256/Indy256 */
- break;
+ case 2:
+ unkDecode8(); /* Ender - Zak256/Indy256 */
+ break;
- case 4:
- unkDecode10(); /* Ender - Zak256/Indy256 */
- break;
+ case 3:
+ unkDecode9(); /* Ender - Zak256/Indy256 */
+ break;
+
+ case 4:
+ unkDecode10(); /* Ender - Zak256/Indy256 */
+ break;
- case 7:
- unkDecode11(); /* Ender - Zak256/Indy256 */
- break;
+ case 7:
+ unkDecode11(); /* Ender - Zak256/Indy256 */
+ break;
- case 14: case 15: case 16: case 17: case 18:
+ case 14:
+ case 15:
+ case 16:
+ case 17:
+ case 18:
_decomp_shr = code - 10;
_decomp_mask = decompress_table[code - 10];
unkDecode6();
break;
- case 24: case 25: case 26: case 27: case 28:
+ case 24:
+ case 25:
+ case 26:
+ case 27:
+ case 28:
_decomp_shr = code - 20;
_decomp_mask = decompress_table[code - 20];
unkDecode5();
break;
-
- case 34: case 35: case 36: case 37: case 38:
+
+ case 34:
+ case 35:
+ case 36:
+ case 37:
+ case 38:
_useOrDecompress = true;
_decomp_shr = code - 30;
- _decomp_mask = decompress_table[code - 30 ];
+ _decomp_mask = decompress_table[code - 30];
unkDecode4();
break;
- case 44: case 45: case 46: case 47: case 48:
+ case 44:
+ case 45:
+ case 46:
+ case 47:
+ case 48:
_useOrDecompress = true;
_decomp_shr = code - 40;
_decomp_mask = decompress_table[code - 40];
unkDecode2();
break;
- case 64: case 65: case 66: case 67: case 68:
+ case 64:
+ case 65:
+ case 66:
+ case 67:
+ case 68:
_decomp_shr = code - 60;
_decomp_mask = decompress_table[code - 60];
unkDecode1();
break;
- case 84: case 85: case 86: case 87: case 88:
+ case 84:
+ case 85:
+ case 86:
+ case 87:
+ case 88:
_useOrDecompress = true;
_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:
+ /* New since version 6 */
+ case 104:
+ case 105:
+ case 106:
+ case 107:
+ case 108:
_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:
+
+ /* New since version 6 */
+ case 124:
+ case 125:
+ case 126:
+ case 127:
+ case 128:
_useOrDecompress = true;
_decomp_shr = code - 120;
_decomp_mask = decompress_table[code - 120];
@@ -826,14 +887,16 @@ void Gdi::decompressBitmap() {
}
}
-int Scumm::hasCharsetMask(int x, int y, int x2, int y2) {
- if (!charset._hasMask || y > gdi._mask_bottom || x > gdi._mask_right ||
- y2 < gdi._mask_top || x2 < gdi._mask_left )
+int Scumm::hasCharsetMask(int x, int y, int x2, int y2)
+{
+ if (!charset._hasMask || y > gdi._mask_bottom || x > gdi._mask_right ||
+ y2 < gdi._mask_top || x2 < gdi._mask_left)
return 0;
return 1;
}
-void Gdi::draw8ColWithMasking() {
+void Gdi::draw8ColWithMasking()
+{
int height = _numLinesToProcess;
byte *mask = _mask_ptr;
byte *dst = _backbuff_ptr;
@@ -843,18 +906,26 @@ void Gdi::draw8ColWithMasking() {
do {
maskbits = *mask;
if (maskbits) {
- if (!(maskbits&0x80)) dst[0] = src[0];
- if (!(maskbits&0x40)) dst[1] = src[1];
- if (!(maskbits&0x20)) dst[2] = src[2];
- if (!(maskbits&0x10)) dst[3] = src[3];
- if (!(maskbits&0x08)) dst[4] = src[4];
- if (!(maskbits&0x04)) dst[5] = src[5];
- if (!(maskbits&0x02)) dst[6] = src[6];
- if (!(maskbits&0x01)) dst[7] = src[7];
+ if (!(maskbits & 0x80))
+ dst[0] = src[0];
+ if (!(maskbits & 0x40))
+ dst[1] = src[1];
+ if (!(maskbits & 0x20))
+ dst[2] = src[2];
+ if (!(maskbits & 0x10))
+ dst[3] = src[3];
+ if (!(maskbits & 0x08))
+ dst[4] = src[4];
+ if (!(maskbits & 0x04))
+ dst[5] = src[5];
+ if (!(maskbits & 0x02))
+ dst[6] = src[6];
+ if (!(maskbits & 0x01))
+ dst[7] = src[7];
} else {
/* alignment safe */
- ((uint32*)dst)[0] = ((uint32*)src)[0];
- ((uint32*)dst)[1] = ((uint32*)src)[1];
+ ((uint32 *)dst)[0] = ((uint32 *)src)[0];
+ ((uint32 *)dst)[1] = ((uint32 *)src)[1];
}
src += 320;
dst += 320;
@@ -862,7 +933,8 @@ void Gdi::draw8ColWithMasking() {
} while (--height);
}
-void Gdi::clear8ColWithMasking() {
+void Gdi::clear8ColWithMasking()
+{
int height = _numLinesToProcess;
byte *mask = _mask_ptr;
byte *dst = _backbuff_ptr;
@@ -871,42 +943,52 @@ void Gdi::clear8ColWithMasking() {
do {
maskbits = *mask;
if (!maskbits) {
- ((uint32*)dst)[1] = ((uint32*)dst)[0] = 0;
+ ((uint32 *)dst)[1] = ((uint32 *)dst)[0] = 0;
} else {
- if (!(maskbits&0x80)) dst[0] = 0;
- if (!(maskbits&0x40)) dst[1] = 0;
- if (!(maskbits&0x20)) dst[2] = 0;
- if (!(maskbits&0x10)) dst[3] = 0;
- if (!(maskbits&0x08)) dst[4] = 0;
- if (!(maskbits&0x04)) dst[5] = 0;
- if (!(maskbits&0x02)) dst[6] = 0;
- if (!(maskbits&0x01)) dst[7] = 0;
+ if (!(maskbits & 0x80))
+ dst[0] = 0;
+ if (!(maskbits & 0x40))
+ dst[1] = 0;
+ if (!(maskbits & 0x20))
+ dst[2] = 0;
+ if (!(maskbits & 0x10))
+ dst[3] = 0;
+ if (!(maskbits & 0x08))
+ dst[4] = 0;
+ if (!(maskbits & 0x04))
+ dst[5] = 0;
+ if (!(maskbits & 0x02))
+ dst[6] = 0;
+ if (!(maskbits & 0x01))
+ dst[7] = 0;
}
dst += 320;
mask += 40;
} while (--height);
}
-void Gdi::clear8Col() {
+void Gdi::clear8Col()
+{
int height = _numLinesToProcess;
byte *dst = _backbuff_ptr;
do {
- ((uint32*)dst)[1] = ((uint32*)dst)[0] = 0;
+ ((uint32 *)dst)[1] = ((uint32 *)dst)[0] = 0;
dst += 320;
} while (--height);
}
-void Gdi::decompressMaskImg() {
+void Gdi::decompressMaskImg()
+{
byte *src = _z_plane_ptr;
byte *dst = _mask_ptr_dest;
int height = _numLinesToProcess;
byte b, c;
- while(1) {
+ while (1) {
b = *src++;
- if (b&0x80) {
- b&=0x7F;
+ if (b & 0x80) {
+ b &= 0x7F;
c = *src++;
do {
@@ -926,16 +1008,17 @@ void Gdi::decompressMaskImg() {
}
}
-void Gdi::decompressMaskImgOr() {
+void Gdi::decompressMaskImgOr()
+{
byte *src = _z_plane_ptr;
byte *dst = _mask_ptr_dest;
int height = _numLinesToProcess;
byte b, c;
- while(1) {
+ while (1) {
b = *src++;
- if (b&0x80) {
- b&=0x7F;
+ if (b & 0x80) {
+ b &= 0x7F;
c = *src++;
do {
@@ -955,54 +1038,55 @@ void Gdi::decompressMaskImgOr() {
}
}
-void Scumm::redrawBGStrip(int start, int num) {
+void Scumm::redrawBGStrip(int start, int num)
+{
int s = _screenStartStrip + start;
- assert(s>=0 && (size_t)s<sizeof(gfxUsageBits)/sizeof(gfxUsageBits[0]));
+ assert(s >= 0
+ && (size_t) s < sizeof(gfxUsageBits) / sizeof(gfxUsageBits[0]));
_curVirtScreen = &virtscr[0];
- gfxUsageBits[s]|=0x80000000;
-
- /*if (_curVirtScreen->height < _scrHeight) {
- warning("Screen Y size %d < Room height %d",
- _curVirtScreen->height,
- _scrHeight);
- }*/
+ gfxUsageBits[s] |= 0x80000000;
+
+ /*if (_curVirtScreen->height < _scrHeight) {
+ warning("Screen Y size %d < Room height %d",
+ _curVirtScreen->height,
+ _scrHeight);
+ } */
- gdi.drawBitmap(getResourceAddress(rtRoom, _roomResource)+_IM00_offs,
- _curVirtScreen, s, 0, _curVirtScreen->height, s, num, 0);
+ gdi.drawBitmap(getResourceAddress(rtRoom, _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 Gdi::unkDecode1() {
+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;
+ byte incm, reps;
_tempNumLines = _numLinesToProcess;
- do {
+ do {
_currentX = 8;
do {
- FILL_BITS
- *dst++=color;
+ FILL_BITS * dst++ = color;
-againPos:;
+ againPos:;
- if (!READ_BIT) {}
- else if (READ_BIT) {
- incm = (bits&7)-4;
- cl-=3;
- bits>>=3;
+ if (!READ_BIT) {
+ } else if (READ_BIT) {
+ incm = (bits & 7) - 4;
+ cl -= 3;
+ bits >>= 3;
if (!incm) {
- FILL_BITS
- reps = bits&0xFF;
+ FILL_BITS reps = bits & 0xFF;
do {
if (!--_currentX) {
_currentX = 8;
@@ -1010,17 +1094,16 @@ againPos:;
if (!--_tempNumLines)
return;
}
- *dst++=color;
+ *dst++ = color;
} while (--reps);
- bits>>=8;
- bits |= (*src++)<<(cl-8);
+ bits >>= 8;
+ bits |= (*src++) << (cl - 8);
goto againPos;
} else {
color += incm;
}
} else {
- FILL_BITS
- color = bits&_decomp_mask;
+ FILL_BITS color = bits & _decomp_mask;
cl -= _decomp_shr;
bits >>= _decomp_shr;
}
@@ -1029,7 +1112,8 @@ againPos:;
} while (--_tempNumLines);
}
-void Gdi::unkDecode2() {
+void Gdi::unkDecode2()
+{
byte *src = _smap_ptr;
byte *dst = _bgbak_ptr;
byte color = *src++;
@@ -1040,17 +1124,15 @@ void Gdi::unkDecode2() {
_tempNumLines = _numLinesToProcess;
- do {
+ do {
_currentX = 8;
do {
- FILL_BITS
- if (color!=_transparency)
- *dst=color;
+ FILL_BITS if (color != _transparency)
+ *dst = color;
dst++;
- if (!READ_BIT) {}
- else if (!READ_BIT) {
- FILL_BITS
- color = bits&_decomp_mask;
+ if (!READ_BIT) {
+ } else if (!READ_BIT) {
+ FILL_BITS color = bits & _decomp_mask;
bits >>= _decomp_shr;
cl -= _decomp_shr;
inc = -1;
@@ -1065,37 +1147,37 @@ void Gdi::unkDecode2() {
} while (--_tempNumLines);
}
-void Gdi::unkDecode3() {
+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;
+ byte incm, reps;
_tempNumLines = _numLinesToProcess;
- do {
+ do {
_currentX = 8;
do {
- FILL_BITS
- if (color!=_transparency) *dst=color;
+ FILL_BITS if (color != _transparency)
+ *dst = color;
dst++;
-againPos:;
- if (!READ_BIT) {}
- else if (READ_BIT) {
- incm = (bits&7)-4;
-
- cl-=3;
- bits>>=3;
+ againPos:;
+ if (!READ_BIT) {
+ } else if (READ_BIT) {
+ incm = (bits & 7) - 4;
+
+ cl -= 3;
+ bits >>= 3;
if (incm) {
color += incm;
} else {
- FILL_BITS
- reps = bits&0xFF;
- if (color==_transparency) {
+ FILL_BITS reps = bits & 0xFF;
+ if (color == _transparency) {
do {
if (!--_currentX) {
_currentX = 8;
@@ -1113,16 +1195,15 @@ againPos:;
if (!--_tempNumLines)
return;
}
- *dst++=color;
+ *dst++ = color;
} while (--reps);
}
- bits>>=8;
- bits |= (*src++)<<(cl-8);
+ bits >>= 8;
+ bits |= (*src++) << (cl - 8);
goto againPos;
}
} else {
- FILL_BITS
- color = bits&_decomp_mask;
+ FILL_BITS color = bits & _decomp_mask;
cl -= _decomp_shr;
bits >>= _decomp_shr;
}
@@ -1132,7 +1213,8 @@ againPos:;
}
-void Gdi::unkDecode4() {
+void Gdi::unkDecode4()
+{
byte *src = _smap_ptr;
byte *dst = _bgbak_ptr;
byte color = *src++;
@@ -1140,19 +1222,17 @@ void Gdi::unkDecode4() {
uint bits = *src++;
byte cl = 8;
byte bit;
-
+
_currentX = 8;
- do {
+ do {
_tempNumLines = _numLinesToProcess;
do {
- FILL_BITS
- if (color!=_transparency)
- *dst=color;
- dst+=320;
- if (!READ_BIT) {}
- else if (!READ_BIT) {
- FILL_BITS
- color = bits&_decomp_mask;
+ FILL_BITS if (color != _transparency)
+ *dst = color;
+ dst += 320;
+ if (!READ_BIT) {
+ } else if (!READ_BIT) {
+ FILL_BITS color = bits & _decomp_mask;
bits >>= _decomp_shr;
cl -= _decomp_shr;
inc = -1;
@@ -1162,12 +1242,13 @@ void Gdi::unkDecode4() {
inc = -inc;
color += inc;
}
- } while (--_tempNumLines);
+ } while (--_tempNumLines);
dst -= _vertStripNextInc;
} while (--_currentX);
}
-void Gdi::unkDecode5() {
+void Gdi::unkDecode5()
+{
byte *src = _smap_ptr;
byte *dst = _bgbak_ptr;
byte color = *src++;
@@ -1178,15 +1259,13 @@ void Gdi::unkDecode5() {
_tempNumLines = _numLinesToProcess;
- do {
+ do {
_currentX = 8;
do {
- FILL_BITS
- *dst++=color;
- if (!READ_BIT) {}
- else if (!READ_BIT) {
- FILL_BITS
- color = bits&_decomp_mask;
+ FILL_BITS * dst++ = color;
+ if (!READ_BIT) {
+ } else if (!READ_BIT) {
+ FILL_BITS color = bits & _decomp_mask;
bits >>= _decomp_shr;
cl -= _decomp_shr;
inc = -1;
@@ -1201,7 +1280,8 @@ void Gdi::unkDecode5() {
} while (--_tempNumLines);
}
-void Gdi::unkDecode6() {
+void Gdi::unkDecode6()
+{
byte *src = _smap_ptr;
byte *dst = _bgbak_ptr;
byte color = *src++;
@@ -1209,18 +1289,16 @@ void Gdi::unkDecode6() {
uint bits = *src++;
byte cl = 8;
byte bit;
-
+
_currentX = 8;
- do {
+ do {
_tempNumLines = _numLinesToProcess;
do {
- FILL_BITS
- *dst=color;
- dst+=320;
- if (!READ_BIT) {}
- else if (!READ_BIT) {
- FILL_BITS
- color = bits&_decomp_mask;
+ FILL_BITS * dst = color;
+ dst += 320;
+ if (!READ_BIT) {
+ } else if (!READ_BIT) {
+ FILL_BITS color = bits & _decomp_mask;
bits >>= _decomp_shr;
cl -= _decomp_shr;
inc = -1;
@@ -1230,7 +1308,7 @@ void Gdi::unkDecode6() {
inc = -inc;
color += inc;
}
- } while (--_tempNumLines);
+ } while (--_tempNumLines);
dst -= _vertStripNextInc;
} while (--_currentX);
}
@@ -1249,160 +1327,172 @@ void Gdi::unkDecode6() {
h = _numLinesToProcess; \
}
-void Gdi::unkDecode7() {
+void Gdi::unkDecode7()
+{
byte *src = _smap_ptr;
byte *dst = _bgbak_ptr;
int height = _numLinesToProcess;
uint h = _numLinesToProcess;
-
-
- if(_vm->_features & GF_OLD256)
- {
- _currentX = 8;
- for(;;) {
- byte color = *src++;
- *dst = color;
- NEXT_ROW
- }
- return;
+
+
+ if (_vm->_features & GF_OLD256) {
+ _currentX = 8;
+ for (;;) {
+ byte color = *src++;
+ *dst = color;
+ NEXT_ROW}
+ return;
}
-
+
do {
/* Endian safe */
#if defined(SCUMM_NEED_ALIGNMENT)
memcpy(dst, src, 8);
#else
- ((uint32*)dst)[0] = ((uint32*)src)[0];
- ((uint32*)dst)[1] = ((uint32*)src)[1];
+ ((uint32 *)dst)[0] = ((uint32 *)src)[0];
+ ((uint32 *)dst)[1] = ((uint32 *)src)[1];
#endif
dst += 320;
src += 8;
} while (--height);
}
-void Gdi::unkDecode8() {
- byte *src = _smap_ptr;
- byte *dst = _bgbak_ptr;
- uint h = _numLinesToProcess;
-
- _currentX = 8;
- for(;;) {
- uint run = (*src++)+1;
- byte color = *src++;
-
- do {
- *dst = color;
- NEXT_ROW
- } while (--run);
- }
-}
-
-void Gdi::unkDecode9() {
- byte *src = _smap_ptr;
- byte *dst = _bgbak_ptr;
- unsigned char c, bits, color, run;
- int x, y, i, z;
- uint buffer=0, mask = 128;
- int h = _numLinesToProcess;
- x = y = i = z = run = 0;
-
- _currentX = 8;
- for(;;) {
- c = 0;
- for (i = 0; i < 4; i++) {READ_256BIT; c+=(bits<<i);}
-
- switch ((c>>2)) {
- case 0:
- color=0;
- for (i=0; i<4; i++) {READ_256BIT; color+=bits<<i;}
- for (i=0; i<((c&3)+2); i++) {
- *dst = (run * 16 + color);
- NEXT_ROW
- }
- break;
-
- case 1:
- for (i=0; i<((c&3)+1); i++) {
- color = 0;
- for (z=0; z < 4; z++) {READ_256BIT; color+=bits<<z;}
- *dst = (run *16 + color);
- NEXT_ROW
- }
- break;
-
- case 2:
- run = 0;
- for (i = 0; i < 4; i++) {READ_256BIT; run+=bits<<i;}
- break;
- }
- }
-}
-
-void Gdi::unkDecode10() {
- byte *src = _smap_ptr;
- byte *dst = _bgbak_ptr;
- int i;
- unsigned char local_palette[256], numcolors = *src++;
- uint h = _numLinesToProcess;
-
- for (i=0; i < numcolors; i++)
- local_palette[i] = *src++;
-
- _currentX = 8;
-
- for(;;) {
- byte color = *src++;
- if (color < numcolors) {
- *dst = local_palette[color];
- NEXT_ROW
- } else {
- uint run = color - numcolors +1;
- color = *src++;
- do {
- *dst = color;
- NEXT_ROW
- } while (--run);
- }
- }
-}
-
-
-void Gdi::unkDecode11() {
- byte *src = _smap_ptr;
- byte *dst = _bgbak_ptr;
- int bits, i;
- uint buffer=0, mask = 128;
- unsigned char inc = 1, color = *src++;
-
- _currentX = 8;
- do {
- _tempNumLines = _numLinesToProcess;
- do {
- *dst = color;
- dst+=320;
- for (i=0; i<3; i++) {READ_256BIT if (!bits) break;}
- switch (i) {
- case 1:
- inc=-inc;
- color-=inc;
- break;
-
- case 2:
- color-=inc;
- break;
-
- case 3:
- color = 0;
- inc = 1;
- for (i=0; i<8; i++) {
- READ_256BIT
- color+= bits<<i;
- }
- break;
- }
- } while (--_tempNumLines);
- dst -= _vertStripNextInc;
- } while (--_currentX);
+void Gdi::unkDecode8()
+{
+ byte *src = _smap_ptr;
+ byte *dst = _bgbak_ptr;
+ uint h = _numLinesToProcess;
+
+ _currentX = 8;
+ for (;;) {
+ uint run = (*src++) + 1;
+ byte color = *src++;
+
+ do {
+ *dst = color;
+ NEXT_ROW} while (--run);
+ }
+}
+
+void Gdi::unkDecode9()
+{
+ byte *src = _smap_ptr;
+ byte *dst = _bgbak_ptr;
+ unsigned char c, bits, color, run;
+ int x, y, i, z;
+ uint buffer = 0, mask = 128;
+ int h = _numLinesToProcess;
+ x = y = i = z = run = 0;
+
+ _currentX = 8;
+ for (;;) {
+ c = 0;
+ for (i = 0; i < 4; i++) {
+ READ_256BIT;
+ c += (bits << i);
+ }
+
+ switch ((c >> 2)) {
+ case 0:
+ color = 0;
+ for (i = 0; i < 4; i++) {
+ READ_256BIT;
+ color += bits << i;
+ }
+ for (i = 0; i < ((c & 3) + 2); i++) {
+ *dst = (run * 16 + color);
+ NEXT_ROW}
+ break;
+
+ case 1:
+ for (i = 0; i < ((c & 3) + 1); i++) {
+ color = 0;
+ for (z = 0; z < 4; z++) {
+ READ_256BIT;
+ color += bits << z;
+ }
+ *dst = (run * 16 + color);
+ NEXT_ROW}
+ break;
+
+ case 2:
+ run = 0;
+ for (i = 0; i < 4; i++) {
+ READ_256BIT;
+ run += bits << i;
+ }
+ break;
+ }
+ }
+}
+
+void Gdi::unkDecode10()
+{
+ byte *src = _smap_ptr;
+ byte *dst = _bgbak_ptr;
+ int i;
+ unsigned char local_palette[256], numcolors = *src++;
+ uint h = _numLinesToProcess;
+
+ for (i = 0; i < numcolors; i++)
+ local_palette[i] = *src++;
+
+ _currentX = 8;
+
+ for (;;) {
+ byte color = *src++;
+ if (color < numcolors) {
+ *dst = local_palette[color];
+ NEXT_ROW} else {
+ uint run = color - numcolors + 1;
+ color = *src++;
+ do {
+ *dst = color;
+ NEXT_ROW} while (--run);
+ }
+ }
+}
+
+
+void Gdi::unkDecode11()
+{
+ byte *src = _smap_ptr;
+ byte *dst = _bgbak_ptr;
+ int bits, i;
+ uint buffer = 0, mask = 128;
+ unsigned char inc = 1, color = *src++;
+
+ _currentX = 8;
+ do {
+ _tempNumLines = _numLinesToProcess;
+ do {
+ *dst = color;
+ dst += 320;
+ for (i = 0; i < 3; i++) {
+ READ_256BIT if (!bits)
+ break;
+ }
+ switch (i) {
+ case 1:
+ inc = -inc;
+ color -= inc;
+ break;
+
+ case 2:
+ color -= inc;
+ break;
+
+ case 3:
+ color = 0;
+ inc = 1;
+ for (i = 0; i < 8; i++) {
+ READ_256BIT color += bits << i;
+ }
+ break;
+ }
+ } while (--_tempNumLines);
+ dst -= _vertStripNextInc;
+ } while (--_currentX);
}
@@ -1411,58 +1501,67 @@ void Gdi::unkDecode11() {
#undef READ_BIT
#undef FILL_BITS
-void Scumm::restoreCharsetBg() {
+void Scumm::restoreCharsetBg()
+{
_bkColor = 0;
-
+
if (gdi._mask_left != -1) {
- restoreBG(gdi._mask_left, gdi._mask_top, gdi._mask_right, gdi._mask_bottom);
+ restoreBG(gdi._mask_left, gdi._mask_top, gdi._mask_right,
+ gdi._mask_bottom);
charset._hasMask = false;
gdi._mask_left = -1;
charset._strLeft = -1;
charset._left = -1;
}
-
+
charset._xpos2 = string[0].xpos;
charset._ypos2 = string[0].ypos;
}
-void Scumm::restoreBG(int left, int top, int right, int bottom) {
+void Scumm::restoreBG(int left, int top, int right, int bottom)
+{
VirtScreen *vs;
int topline, height, width, widthmod;
- byte *backbuff,*bgbak,*mask;
+ byte *backbuff, *bgbak, *mask;
- if (left==right || top==bottom)
+ if (left == right || top == bottom)
return;
- if (top<0) top=0;
-
- if ((vs=findVirtScreen(top)) == NULL)
+ if (top < 0)
+ top = 0;
+
+ if ((vs = findVirtScreen(top)) == NULL)
return;
topline = vs->topline;
height = topline + vs->height;
- if (vs->number==0) {
+ if (vs->number == 0) {
left += _lastXstart - vs->xstart;
right += _lastXstart - vs->xstart;
}
right++;
- if (left<0) left=0;
- if (right<0)right=0;
- if (left>320)
+ if (left < 0)
+ left = 0;
+ if (right < 0)
+ right = 0;
+ if (left > 320)
return;
- if (right>320)
- right=320;
- if (bottom>=height)
- bottom=height;
+ if (right > 320)
+ right = 320;
+ if (bottom >= height)
+ bottom = height;
+
+ updateDirtyRect(vs->number, left, right, top - topline, bottom - topline,
+ 0x40000000);
- updateDirtyRect(vs->number, left, right, top-topline,bottom-topline, 0x40000000);
+ height = (top - topline) * 320 + vs->xstart + left;
- height = (top-topline) * 320 + vs->xstart + left;
-
backbuff = vs->screenPtr + height;
- bgbak = getResourceAddress(rtBuffer, vs->number+5) + height;
- mask = getResourceAddress(rtBuffer, 9) + top * 40 + (left>>3) + _screenStartStrip;
- if (vs->number==0) {
+ bgbak = getResourceAddress(rtBuffer, vs->number + 5) + height;
+ mask =
+ getResourceAddress(rtBuffer,
+ 9) + top * 40 + (left >> 3) + _screenStartStrip;
+ if (vs->number == 0) {
mask += vs->topline * 216;
}
@@ -1470,9 +1569,10 @@ void Scumm::restoreBG(int left, int top, int right, int bottom) {
width = right - left;
widthmod = (width >> 2) + 2;
- if (vs->alloctwobuffers && _currentRoom!=0 /*&& _vars[VAR_V5_DRAWFLAGS]&2*/) {
+ if (vs->alloctwobuffers
+ && _currentRoom != 0 /*&& _vars[VAR_V5_DRAWFLAGS]&2 */ ) {
blit(backbuff, bgbak, width, height);
- if (vs->number==0 && charset._hasMask && height) {
+ if (vs->number == 0 && charset._hasMask && height) {
do {
memset(mask, 0, widthmod);
mask += 40;
@@ -1482,34 +1582,37 @@ void Scumm::restoreBG(int left, int top, int right, int bottom) {
if (height) {
do {
memset(backbuff, _bkColor, width);
- backbuff+=320;
+ backbuff += 320;
} while (--height);
}
}
}
-void Scumm::updateDirtyRect(int virt, int left, int right, int top, int bottom, uint32 dirtybits) {
+void Scumm::updateDirtyRect(int virt, int left, int right, int top,
+ int bottom, uint32 dirtybits)
+{
VirtScreen *vs = &virtscr[virt];
- int lp,rp;
+ int lp, rp;
uint32 *sp;
int num;
if (top > vs->height || left > vs->width || right < 0 || bottom < 0)
return;
-
- if (top<0)
- top=0;
- if (left<0)
- left=0;
+
+ if (top < 0)
+ top = 0;
+ if (left < 0)
+ left = 0;
if (bottom > vs->height)
bottom = vs->height;
if (right > vs->width)
right = vs->width;
- if (virt==0 && dirtybits) {
+ if (virt == 0 && dirtybits) {
rp = (right >> 3) + _screenStartStrip;
lp = (left >> 3) + _screenStartStrip;
- if (lp<0) lp=0;
+ if (lp < 0)
+ lp = 0;
if (rp >= 200)
rp = 200;
if (lp <= rp) {
@@ -1524,156 +1627,167 @@ void Scumm::updateDirtyRect(int virt, int left, int right, int top, int bottom,
setVirtscreenDirty(vs, left, top, right, bottom);
}
-void Scumm::setVirtscreenDirty(VirtScreen *vs, int left, int top, int right, int bottom) {
+void Scumm::setVirtscreenDirty(VirtScreen * vs, int left, int top, int right,
+ int bottom)
+{
int lp = left >> 3;
int rp = right >> 3;
- if (lp>=40 || rp<0)
+ if (lp >= 40 || rp < 0)
return;
- if (lp<0) lp=0;
- if (rp>=40) rp=39;
+ if (lp < 0)
+ lp = 0;
+ if (rp >= 40)
+ rp = 39;
- while (lp<=rp) {
+ while (lp <= rp) {
if (top < vs->tdirty[lp])
vs->tdirty[lp] = top;
if (bottom > vs->bdirty[lp])
vs->bdirty[lp] = bottom;
lp++;
- }
+ }
}
-VirtScreen *Scumm::findVirtScreen(int y) {
+VirtScreen *Scumm::findVirtScreen(int y)
+{
VirtScreen *vs = virtscr;
int i;
-
- for(i=0; i<3; i++,vs++) {
- if (y >= vs->topline && y < vs->topline+vs->height) {
- return _curVirtScreen=vs;
- }
+
+ for (i = 0; i < 3; i++, vs++) {
+ if (y >= vs->topline && y < vs->topline + vs->height) {
+ return _curVirtScreen = vs;
+ }
}
- return _curVirtScreen=NULL;
+ return _curVirtScreen = NULL;
}
-void Scumm::unkScreenEffect1() {
+void Scumm::unkScreenEffect1()
+{
/* XXX: not implemented */
warning("stub unkScreenEffect1()");
}
-void Scumm::unkScreenEffect2() {
+void Scumm::unkScreenEffect2()
+{
/* XXX: not implemented */
warning("stub unkScreenEffect2()");
}
-void Scumm::unkScreenEffect3() {
+void Scumm::unkScreenEffect3()
+{
/* XXX: not implemented */
warning("stub unkScreenEffect3()");
}
-void Scumm::unkScreenEffect4() {
+void Scumm::unkScreenEffect4()
+{
/* XXX: not implemented */
warning("stub unkScreenEffect4()");
}
static const int8 screen_eff7_table1[4][16] = {
- {1,1,-1,1,-1,1,-1,-1,
- 1,-1,-1,-1,1,1,1,-1},
- {0,1,2,1,2,0,2,1,
- 2,0,2,1,0,0,0,0},
- {-2,-1,0,-1,-2,-1,-2,0
- -2,-1,-2,0,0,0,0,0},
- {0,-1,-2,-1,-2,0,-2,-1
- -2,0,-2,-1,0,0,0,0}
+ {1, 1, -1, 1, -1, 1, -1, -1,
+ 1, -1, -1, -1, 1, 1, 1, -1},
+ {0, 1, 2, 1, 2, 0, 2, 1,
+ 2, 0, 2, 1, 0, 0, 0, 0},
+ {-2, -1, 0, -1, -2, -1, -2, 0 - 2, -1, -2, 0, 0, 0, 0, 0},
+ {0, -1, -2, -1, -2, 0, -2, -1 - 2, 0, -2, -1, 0, 0, 0, 0}
};
static const byte screen_eff7_table2[4][16] = {
- {0,0,39,0,39,0,39,24,
- 0,24,39,24,0,0,0,24},
- {0,0,0,0,0,0,0,0,
- 1,0,1,0,255,0,0,0},
- {39,24,39,24,39,24,39,24,
- 38,24,38,24,255,0,0,0},
- {0,24,39,24,39,0,39,24,
- 38,0,38,24,255,0,0,0}
+ {0, 0, 39, 0, 39, 0, 39, 24,
+ 0, 24, 39, 24, 0, 0, 0, 24},
+ {0, 0, 0, 0, 0, 0, 0, 0,
+ 1, 0, 1, 0, 255, 0, 0, 0},
+ {39, 24, 39, 24, 39, 24, 39, 24,
+ 38, 24, 38, 24, 255, 0, 0, 0},
+ {0, 24, 39, 24, 39, 0, 39, 24,
+ 38, 0, 38, 24, 255, 0, 0, 0}
};
static const byte screen_eff7_table3[4] = {
- 13,25,25,25
+ 13, 25, 25, 25
};
-void Scumm::unkScreenEffect7(int a) {
+void Scumm::unkScreenEffect7(int a)
+{
int tab_1[16];
int tab_2[16];
- int i,j;
+ int i, j;
int bottom;
- int l,t,r,b;
+ int l, t, r, b;
- for (i=0; i<16; i++) {
+ for (i = 0; i < 16; i++) {
tab_1[i] = screen_eff7_table1[a][i];
j = screen_eff7_table2[a][i];
- if (j==24)
- j = (virtscr[0].height>>3)-1;
+ if (j == 24)
+ j = (virtscr[0].height >> 3) - 1;
tab_2[i] = j;
}
bottom = virtscr[0].height >> 3;
- for (j=0; j < screen_eff7_table3[a]; j++) {
- for (i=0; i<4; i++) {
- l = tab_2[i*4];
- t = tab_2[i*4+1];
- r = tab_2[i*4+2];
- b = tab_2[i*4+3];
- if (t==b) {
+ for (j = 0; j < screen_eff7_table3[a]; j++) {
+ for (i = 0; i < 4; i++) {
+ l = tab_2[i * 4];
+ t = tab_2[i * 4 + 1];
+ r = tab_2[i * 4 + 2];
+ b = tab_2[i * 4 + 3];
+ if (t == b) {
while (l <= r) {
- if (l>=0 && l<40 && (uint)t<(uint)bottom) {
- virtscr[0].tdirty[l] = t<<3;
- virtscr[0].bdirty[l] = (t+1)<<3;
+ if (l >= 0 && l < 40 && (uint) t < (uint) bottom) {
+ virtscr[0].tdirty[l] = t << 3;
+ virtscr[0].bdirty[l] = (t + 1) << 3;
}
l++;
}
} else {
- if (l<0 || l>=40 || b<=t)
+ if (l < 0 || l >= 40 || b <= t)
continue;
- if (b>bottom)
- b=bottom;
- virtscr[0].tdirty[l] = t<<3;
- virtscr[0].bdirty[l] = (b+1)<<3;
+ if (b > bottom)
+ b = bottom;
+ virtscr[0].tdirty[l] = t << 3;
+ virtscr[0].bdirty[l] = (b + 1) << 3;
}
updateDirtyScreen(0);
}
- for (i=0; i<16; i++)
+ for (i = 0; i < 16; i++)
tab_2[i] += tab_1[i];
-
+
updateScreen(this);
- waitForTimer(this,30);
+ waitForTimer(this, 30);
}
}
-void Scumm::unkScreenEffect6() {
+void Scumm::unkScreenEffect6()
+{
/* XXX: not implemented */
warning("stub unkScreenEffect6");
}
-
-void Scumm::unkScreenEffect5(int a) {
+
+void Scumm::unkScreenEffect5(int a)
+{
/* XXX: not implemented */
- warning("stub unkScreenEffect5(%d)",a);
+ warning("stub unkScreenEffect5(%d)", a);
}
-void Scumm::setShake(int mode) {
+void Scumm::setShake(int mode)
+{
_shakeEnabled = mode != 0;
_shakeFrame = 0;
- setShakePos(this,0);
+ setShakePos(this, 0);
}
-void Gdi::clearUpperMask() {
- memset(
- _vm->getResourceAddress(rtBuffer, 9),
- 0,
- _imgBufOffs[1] - _imgBufOffs[0]
- );
+void Gdi::clearUpperMask()
+{
+ memset(_vm->getResourceAddress(rtBuffer, 9),
+ 0, _imgBufOffs[1] - _imgBufOffs[0]
+ );
}
-void Scumm::clampCameraPos(ScummPoint *pt) {
+void Scumm::clampCameraPos(ScummPoint * pt)
+{
if (pt->x < _vars[VAR_CAMERA_MIN_X])
pt->x = _vars[VAR_CAMERA_MIN_X];
@@ -1688,11 +1802,12 @@ void Scumm::clampCameraPos(ScummPoint *pt) {
}
-void Scumm::moveCamera() {
- if(_features & GF_AFTER_V7) {
+void Scumm::moveCamera()
+{
+ if (_features & GF_AFTER_V7) {
CameraData *cd = &camera;
ScummPoint old = cd->_cur;
- Actor *a=NULL;
+ Actor *a = NULL;
if (cd->_follows) {
a = derefActorSafe(cd->_follows, "moveCamera");
@@ -1708,64 +1823,63 @@ void Scumm::moveCamera() {
} else {
cd->_movingToActor = false;
}
-
+
if (cd->_movingToActor) {
cd->_dest.x = a->x;
cd->_dest.y = a->y;
}
-
- assert(cd->_cur.x>=160 && cd->_cur.y>=100);
-
+
+ assert(cd->_cur.x >= 160 && cd->_cur.y >= 100);
+
clampCameraPos(&cd->_dest);
-
+
if (cd->_cur.x < cd->_dest.x) {
cd->_cur.x += _vars[VAR_CAMERA_SPEED_X];
if (cd->_cur.x > cd->_dest.x)
cd->_cur.x = cd->_dest.x;
}
-
+
if (cd->_cur.x > cd->_dest.x) {
cd->_cur.x -= _vars[VAR_CAMERA_SPEED_X];
if (cd->_cur.x < cd->_dest.x)
cd->_cur.x = cd->_dest.x;
}
-
+
if (cd->_cur.y < cd->_dest.y) {
cd->_cur.y += _vars[VAR_CAMERA_SPEED_Y];
if (cd->_cur.y > cd->_dest.y)
cd->_cur.y = cd->_dest.y;
}
-
+
if (cd->_cur.y > cd->_dest.y) {
cd->_cur.y -= _vars[VAR_CAMERA_SPEED_Y];
if (cd->_cur.y < cd->_dest.y)
cd->_cur.y = cd->_dest.y;
}
-
- if (cd->_cur.x == cd->_dest.x &&
- cd->_cur.y == cd->_dest.y) {
-
+
+ if (cd->_cur.x == cd->_dest.x && cd->_cur.y == cd->_dest.y) {
+
cd->_movingToActor = false;
cd->_accel.x = cd->_accel.y = 0;
_vars[VAR_CAMERA_SPEED_X] = _vars[VAR_CAMERA_SPEED_Y] = 0;
} else {
-
+
cd->_accel.x += _vars[VAR_CAMERA_ACCEL_X];
cd->_accel.y += _vars[VAR_CAMERA_ACCEL_Y];
-
+
_vars[VAR_CAMERA_SPEED_X] += cd->_accel.x / 100;
_vars[VAR_CAMERA_SPEED_Y] += cd->_accel.y / 100;
-
+
if (_vars[VAR_CAMERA_SPEED_X] < 8)
_vars[VAR_CAMERA_SPEED_X] = 8;
-
+
if (_vars[VAR_CAMERA_SPEED_Y] < 8)
_vars[VAR_CAMERA_SPEED_Y] = 8;
-
+
}
-
+
cameraMoved();
-
+
if (cd->_cur.x != old.x || cd->_cur.y != old.y) {
_vars[VAR_CAMERA_POS_X] = cd->_cur.x;
_vars[VAR_CAMERA_POS_Y] = cd->_cur.y;
@@ -1775,72 +1889,72 @@ void Scumm::moveCamera() {
CameraData *cd = &camera;
int pos = cd->_cur.x;
int actorx, t;
- Actor *a=NULL;
-
+ Actor *a = NULL;
+
cd->_cur.x &= 0xFFF8;
-
+
if (cd->_cur.x < _vars[VAR_CAMERA_MIN_X]) {
if (_vars[VAR_CAMERA_FAST_X])
- cd->_cur.x = _vars[VAR_CAMERA_MIN_X];
+ cd->_cur.x = _vars[VAR_CAMERA_MIN_X];
else
- cd->_cur.x += 8;
+ cd->_cur.x += 8;
cameraMoved();
- return;
+ return;
}
-
+
if (cd->_cur.x > _vars[VAR_CAMERA_MAX_X]) {
if (_vars[VAR_CAMERA_FAST_X])
cd->_cur.x = _vars[VAR_CAMERA_MAX_X];
else
- cd->_cur.x-=8;
+ cd->_cur.x -= 8;
cameraMoved();
return;
}
-
- if (cd->_mode==CM_FOLLOW_ACTOR) {
+
+ if (cd->_mode == CM_FOLLOW_ACTOR) {
a = derefActorSafe(cd->_follows, "moveCamera");
-
+
actorx = a->x;
- t = (actorx>>3) - _screenStartStrip;
-
+ t = (actorx >> 3) - _screenStartStrip;
+
if (t < cd->_leftTrigger || t > cd->_rightTrigger) {
if (_vars[VAR_CAMERA_FAST_X]) {
if (t > 35)
cd->_dest.x = actorx + 80;
if (t < 5)
cd->_dest.x = actorx - 80;
- } else
+ } else
cd->_movingToActor = 1;
}
}
-
+
if (cd->_movingToActor) {
a = derefActorSafe(cd->_follows, "moveCamera(2)");
cd->_dest.x = a->x;
}
-
+
if (cd->_dest.x < _vars[VAR_CAMERA_MIN_X])
cd->_dest.x = _vars[VAR_CAMERA_MIN_X];
-
+
if (cd->_dest.x > _vars[VAR_CAMERA_MAX_X])
cd->_dest.x = _vars[VAR_CAMERA_MAX_X];
-
+
if (_vars[VAR_CAMERA_FAST_X]) {
cd->_cur.x = cd->_dest.x;
} else {
if (cd->_cur.x < cd->_dest.x)
- cd->_cur.x+=8;
+ cd->_cur.x += 8;
if (cd->_cur.x > cd->_dest.x)
- cd->_cur.x-=8;
+ cd->_cur.x -= 8;
}
-
+
/* a is set a bit above */
- if (cd->_movingToActor && cd->_cur.x>>3 == a->x>>3) {
+ if (cd->_movingToActor && cd->_cur.x >> 3 == a->x >> 3) {
cd->_movingToActor = 0;
}
-
+
cameraMoved();
-
+
if (pos != cd->_cur.x && _vars[VAR_SCROLL_SCRIPT]) {
_vars[VAR_CAMERA_POS_X] = cd->_cur.x;
runScript(_vars[VAR_SCROLL_SCRIPT], 0, 0, 0);
@@ -1848,16 +1962,17 @@ void Scumm::moveCamera() {
}
}
-void Scumm::cameraMoved() {
- if(_features & GF_AFTER_V7) {
+void Scumm::cameraMoved()
+{
+ if (_features & GF_AFTER_V7) {
CameraData *cd = &camera;
- assert(cd->_cur.x>=160 && cd->_cur.y>=100);
-
- _screenStartStrip = (cd->_cur.x-160) >> 3;
+ assert(cd->_cur.x >= 160 && cd->_cur.y >= 100);
+
+ _screenStartStrip = (cd->_cur.x - 160) >> 3;
_screenEndStrip = _screenStartStrip + 39;
virtscr[0].xstart = _screenStartStrip << 3;
-
+
_screenLeft = cd->_cur.x - 160;
_screenTop = cd->_cur.y - 100;
} else {
@@ -1867,7 +1982,7 @@ void Scumm::cameraMoved() {
if (cd->_cur.x < 160) {
cd->_cur.x = 160;
} else if (cd->_cur.x + 160 >= _scrWidth) {
- cd->_cur.x = _scrWidth-160;
+ cd->_cur.x = _scrWidth - 160;
}
_screenStartStrip = (cd->_cur.x >> 3) - 20;
@@ -1876,8 +1991,9 @@ void Scumm::cameraMoved() {
}
}
-void Scumm::panCameraTo(int x, int y) {
- if(_features & GF_AFTER_V7) {
+void Scumm::panCameraTo(int x, int y)
+{
+ if (_features & GF_AFTER_V7) {
CameraData *cd = &camera;
cd->_follows = 0;
cd->_dest.x = x;
@@ -1891,30 +2007,32 @@ void Scumm::panCameraTo(int x, int y) {
}
}
-void Scumm::actorFollowCamera(int act) {
- if(!(_features & GF_AFTER_V7)) {
+void Scumm::actorFollowCamera(int act)
+{
+ if (!(_features & GF_AFTER_V7)) {
int old;
CameraData *cd = &camera;
/* mi1 compatibilty */
- if (act==0) {
+ if (act == 0) {
cd->_mode = CM_NORMAL;
cd->_follows = 0;
cd->_movingToActor = 0;
return;
}
-
+
old = cd->_follows;
setCameraFollows(derefActorSafe(act, "actorFollowCamera"));
- if (cd->_follows != old)
+ if (cd->_follows != old)
runHook(0);
cd->_movingToActor = 0;
}
}
-void Scumm::setCameraAtEx(int at) {
- if(!(_features & GF_AFTER_V7)) {
+void Scumm::setCameraAtEx(int at)
+{
+ if (!(_features & GF_AFTER_V7)) {
CameraData *cd = &camera;
cd->_mode = CM_NORMAL;
cd->_cur.x = at;
@@ -1923,31 +2041,32 @@ void Scumm::setCameraAtEx(int at) {
}
}
-void Scumm::palManipulate() {
+void Scumm::palManipulate()
+{
byte *srcptr, *destptr;
byte *pal;
- int i,j;
+ int i, j;
if (!_palManipCounter)
return;
- srcptr = getResourceAddress(rtTemp, 4) + _palManipStart*6;
- destptr = getResourceAddress(rtTemp, 5) + _palManipStart*6;
+ srcptr = getResourceAddress(rtTemp, 4) + _palManipStart * 6;
+ destptr = getResourceAddress(rtTemp, 5) + _palManipStart * 6;
pal = _currentPalette + _palManipStart * 3;
i = _palManipStart;
while (i < _palManipEnd) {
- j = (*((uint16*)srcptr) += *(uint16*)destptr );
- *pal++ = j>>8;
+ j = (*((uint16 *)srcptr) += *(uint16 *)destptr);
+ *pal++ = j >> 8;
srcptr += 2;
destptr += 2;
- j = (*((uint16*)srcptr) += *(uint16*)destptr );
- *pal++ = j>>8;
+ j = (*((uint16 *)srcptr) += *(uint16 *)destptr);
+ *pal++ = j >> 8;
srcptr += 2;
destptr += 2;
- j = (*((uint16*)srcptr) += *(uint16*)destptr );
- *pal++ = j>>8;
+ j = (*((uint16 *)srcptr) += *(uint16 *)destptr);
+ *pal++ = j >> 8;
srcptr += 2;
destptr += 2;
@@ -1960,69 +2079,96 @@ void Scumm::palManipulate() {
}
}
-void Scumm::swapPalColors(int a, int b) {
- byte *ap,*bp;
+void Scumm::swapPalColors(int a, int b)
+{
+ byte *ap, *bp;
byte t;
- if ((uint)a>=256 || (uint)b>=256)
+ if ((uint) a >= 256 || (uint) b >= 256)
error("swapPalColors: invalid values, %d, %d", a, b);
-
- ap = &_currentPalette[a*3];
- bp = &_currentPalette[b*3];
- t=ap[0]; ap[0]=bp[0]; bp[0]=t;
- t=ap[1]; ap[1]=bp[1]; bp[1]=t;
- t=ap[2]; ap[2]=bp[2]; bp[2]=t;
+ ap = &_currentPalette[a * 3];
+ bp = &_currentPalette[b * 3];
+
+ t = ap[0];
+ ap[0] = bp[0];
+ bp[0] = t;
+ t = ap[1];
+ ap[1] = bp[1];
+ bp[1] = t;
+ t = ap[2];
+ ap[2] = bp[2];
+ bp[2] = t;
- setDirtyColors(a,b);
+ setDirtyColors(a, b);
}
-void Scumm::screenEffect(int effect) {
- switch(effect) {
+void Scumm::screenEffect(int effect)
+{
+ switch (effect) {
case 1:
case 2:
- case 3: unkScreenEffect7(effect-1); break;
- case 128: unkScreenEffect6(); break;
- case 130: unkScreenEffect1(); break;
- case 131: unkScreenEffect2(); break;
- case 132: unkScreenEffect3(); break;
- case 133: unkScreenEffect4(); break;
- case 134: unkScreenEffect5(0); break;
- case 135: unkScreenEffect5(1); break;
- case 129: break;
+ case 3:
+ unkScreenEffect7(effect - 1);
+ break;
+ case 128:
+ unkScreenEffect6();
+ break;
+ case 130:
+ unkScreenEffect1();
+ break;
+ case 131:
+ unkScreenEffect2();
+ break;
+ case 132:
+ unkScreenEffect3();
+ break;
+ case 133:
+ unkScreenEffect4();
+ break;
+ case 134:
+ unkScreenEffect5(0);
+ break;
+ case 135:
+ unkScreenEffect5(1);
+ break;
+ case 129:
+ break;
default:
warning("Unknown screen effect, %d", effect);
}
_screenEffectFlag = true;
}
-void Scumm::resetActorBgs() {
+void Scumm::resetActorBgs()
+{
Actor *a;
int i;
- uint32 onlyActorFlags,bitpos;
-
- for(i=0; i<40; i++) {
- onlyActorFlags = (gfxUsageBits[_screenStartStrip + i]&=0x3FFFFFFF);
+ uint32 onlyActorFlags, bitpos;
+
+ for (i = 0; i < 40; i++) {
+ onlyActorFlags = (gfxUsageBits[_screenStartStrip + i] &= 0x3FFFFFFF);
a = getFirstActor();
bitpos = 1;
while (onlyActorFlags) {
- if(onlyActorFlags&1 && a->top!=0xFF && a->needBgReset) {
+ if (onlyActorFlags & 1 && a->top != 0xFF && a->needBgReset) {
gfxUsageBits[_screenStartStrip + i] ^= bitpos;
gdi.resetBackground(a->top, a->bottom, i);
}
- bitpos<<=1;
- onlyActorFlags>>=1;
+ bitpos <<= 1;
+ onlyActorFlags >>= 1;
a++;
}
}
- for(i=1,a=getFirstActor(); ++a,i<NUM_ACTORS; i++) {
+ for (i = 1, a = getFirstActor(); ++a, i < NUM_ACTORS; i++) {
a->needBgReset = false;
}
}
-void Gdi::resetBackground(byte top, byte bottom, int strip) {
+void Gdi::resetBackground(byte top, byte bottom, int strip)
+{
VirtScreen *vs = &_vm->virtscr[0];
int offs;
@@ -2031,16 +2177,16 @@ void Gdi::resetBackground(byte top, byte bottom, int strip) {
if (bottom > vs->bdirty[strip])
vs->bdirty[strip] = bottom;
-
+
offs = (top * 40 + _vm->_screenStartStrip + strip);
- _mask_ptr = _vm->getResourceAddress(rtBuffer, 9) + offs;
- _bgbak_ptr = _vm->getResourceAddress(rtBuffer, 5) + (offs<<3);
- _backbuff_ptr = vs->screenPtr + (offs<<3);
-
+ _mask_ptr = _vm->getResourceAddress(rtBuffer, 9) + offs;
+ _bgbak_ptr = _vm->getResourceAddress(rtBuffer, 5) + (offs << 3);
+ _backbuff_ptr = vs->screenPtr + (offs << 3);
+
_numLinesToProcess = bottom - top;
if (_numLinesToProcess) {
- if (1/*_vm->_vars[VAR_V5_DRAWFLAGS]&2*/) {
- if(_vm->hasCharsetMask(strip<<3, top, (strip+1)<<3, bottom))
+ if (1 /*_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);
@@ -2050,95 +2196,102 @@ void Gdi::resetBackground(byte top, byte bottom, int strip) {
}
}
-void Scumm::setPalColor(int idx, int r, int g, int b) {
- _currentPalette[idx*3+0] = r;
- _currentPalette[idx*3+1] = g;
- _currentPalette[idx*3+2] = b;
- setDirtyColors(idx,idx);
+void Scumm::setPalColor(int idx, int r, int g, int b)
+{
+ _currentPalette[idx * 3 + 0] = r;
+ _currentPalette[idx * 3 + 1] = g;
+ _currentPalette[idx * 3 + 2] = b;
+ setDirtyColors(idx, idx);
}
-void Scumm::drawMouse() {
+void Scumm::drawMouse()
+{
/* TODO: handle shake here */
if (_cursorAnimate) {
- if (!(_cursorAnimateIndex&0x3))
- decompressDefaultCursor((_cursorAnimateIndex>>2)&3);
+ if (!(_cursorAnimateIndex & 0x3))
+ decompressDefaultCursor((_cursorAnimateIndex >> 2) & 3);
_cursorAnimateIndex++;
-
+
}
- ::drawMouse(this,
- mouse.x - _cursorHotspotX,
- mouse.y - _cursorHotspotY,
- _cursorWidth,
- _cursorHeight,
- _grabbedCursor,
- gdi._cursorActive>0
- );
+ ::drawMouse(this,
+ mouse.x - _cursorHotspotX,
+ mouse.y - _cursorHotspotY,
+ _cursorWidth,
+ _cursorHeight, _grabbedCursor, gdi._cursorActive > 0);
}
-void Scumm::setCursorHotspot2(int x,int y) {
+void Scumm::setCursorHotspot2(int x, int y)
+{
_cursorHotspotX = x;
_cursorHotspotY = y;
}
-byte Scumm::isMaskActiveAt(int l, int t, int r, int b, byte *mem) {
- int w,h,i;
- if(_features & GF_SMALL_HEADER)
+byte Scumm::isMaskActiveAt(int l, int t, int r, int b, byte *mem)
+{
+ int w, h, i;
+ if (_features & GF_SMALL_HEADER)
return 0;
- l>>=3;
- if (l<0) l = 0;
- if (t<0) t = 0;
+ l >>= 3;
+ if (l < 0)
+ l = 0;
+ if (t < 0)
+ t = 0;
- r>>=3;
- if (r>39) r=39;
+ r >>= 3;
+ if (r > 39)
+ r = 39;
- mem += l + t*40;
+ mem += l + t * 40;
- w = r-l;
- h = b-t+1;
+ w = r - l;
+ h = b - t + 1;
do {
- for(i=0; i<=w; i++)
+ for (i = 0; i <= w; i++)
if (mem[i])
return true;
mem += 40;
} while (--h);
-
+
return false;
}
-void Scumm::setPalette(int palindex) {
+void Scumm::setPalette(int palindex)
+{
byte *pals;
_curPalIndex = palindex;
pals = getPalettePtr();
- if (pals==NULL)
+ if (pals == NULL)
error("invalid palette %d", palindex);
setPaletteFromPtr(pals);
}
-byte *Scumm::findPalInPals(byte *pal, int idx) {
+byte *Scumm::findPalInPals(byte *pal, int idx)
+{
byte *offs;
- uint32 size;
+ uint32 size;
pal = findResource(MKID('WRAP'), pal);
- if (pal==NULL)
+ if (pal == NULL)
return NULL;
- offs = findResourceData(MKID('OFFS'),pal);
- if (offs==NULL)
+ offs = findResourceData(MKID('OFFS'), pal);
+ if (offs == NULL)
return NULL;
size = getResourceDataSize(offs) >> 2;
-
+
if ((uint32)idx >= (uint32)size)
return NULL;
return offs + READ_LE_UINT32(offs + idx * sizeof(uint32));
}
-byte *Scumm::getPalettePtr() {
+byte *Scumm::getPalettePtr()
+{
byte *cptr;
cptr = getResourceAddress(rtRoom, _roomResource);
@@ -2150,13 +2303,14 @@ byte *Scumm::getPalettePtr() {
return cptr;
}
-void Scumm::darkenPalette(int a, int b, int c, int d, int e) {
+void Scumm::darkenPalette(int a, int b, int c, int d, int e)
+{
byte *cptr, *cur;
int num;
int color;
- cptr = getPalettePtr() + a*3;
- cur = _currentPalette + a*3;
+ cptr = getPalettePtr() + a * 3;
+ cur = _currentPalette + a * 3;
if (a <= b) {
num = b - a + 1;
@@ -2164,42 +2318,45 @@ void Scumm::darkenPalette(int a, int b, int c, int d, int e) {
color = *cptr++;
if (c != 0xFF)
color = color * c / 0xFF;
- if(color>255) color = 255;
- *cur++=color;
+ if (color > 255)
+ color = 255;
+ *cur++ = color;
color = *cptr++;
if (d != 0xFF)
color = color * d / 0xFF;
- if(color>255) color = 255;
- *cur++=color;
+ if (color > 255)
+ color = 255;
+ *cur++ = color;
color = *cptr++;
if (e != 0xFF)
color = color * e / 0xFF;
- if(color>255) color = 255;
- *cur++=color;
+ if (color > 255)
+ color = 255;
+ *cur++ = color;
} while (--num);
}
- setDirtyColors(a,b);
+ setDirtyColors(a, b);
}
-void Scumm::grabCursor(int x, int y, int w, int h) {
+void Scumm::grabCursor(int x, int y, int w, int h)
+{
VirtScreen *vs = findVirtScreen(y);
- if (vs==NULL) {
+ if (vs == NULL) {
warning("grabCursor: invalid Y %d", y);
return;
}
- grabCursor(
- vs->screenPtr + (y-vs->topline)*320 + x,
- w,h);
+ grabCursor(vs->screenPtr + (y - vs->topline) * 320 + x, w, h);
}
-void Scumm::decompressBomp(byte *dst, byte *src, int w, int h) {
- int len,num;
- byte code,color;
+void Scumm::decompressBomp(byte *dst, byte *src, int w, int h)
+{
+ int len, num;
+ byte code, color;
src += 8;
@@ -2208,23 +2365,29 @@ void Scumm::decompressBomp(byte *dst, byte *src, int w, int h) {
src += 2;
while (len) {
code = *src++;
- num = (code>>1)+1;
- if (num>len) num=len;
+ num = (code >> 1) + 1;
+ if (num > len)
+ num = len;
len -= num;
- if (code&1) {
+ if (code & 1) {
color = *src++;
- do *dst++ = color; while (--num);
+ do
+ *dst++ = color;
+ while (--num);
} else {
- do *dst++ = *src++; while (--num);
+ do
+ *dst++ = *src++;
+ while (--num);
}
}
} while (--h);
}
-void Scumm::grabCursor(byte *ptr, int width, int height) {
+void Scumm::grabCursor(byte *ptr, int width, int height)
+{
uint size;
byte *dst;
-
+
size = width * height;
if (size > sizeof(_grabbedCursor))
error("grabCursor: grabbed cursor too big");
@@ -2234,7 +2397,7 @@ void Scumm::grabCursor(byte *ptr, int width, int height) {
_cursorAnimate = 0;
dst = _grabbedCursor;
- for(;height;height--) {
+ for (; height; height--) {
memcpy(dst, ptr, width);
dst += width;
ptr += 320;
@@ -2242,31 +2405,34 @@ void Scumm::grabCursor(byte *ptr, int width, int height) {
}
-void Scumm::useIm01Cursor(byte *im, int w, int h) {
+void Scumm::useIm01Cursor(byte *im, int w, int h)
+{
VirtScreen *vs = &virtscr[0];
-
- w<<=3;
- h<<=3;
-
- drawBox(0,0,w-1,h-1,0xFF);
+
+ w <<= 3;
+ h <<= 3;
+
+ drawBox(0, 0, w - 1, h - 1, 0xFF);
vs->alloctwobuffers = false;
gdi._disable_zbuffer = true;
- gdi.drawBitmap(im, vs, _screenStartStrip, 0, h, 0, w>>3, 0);
+ gdi.drawBitmap(im, vs, _screenStartStrip, 0, h, 0, w >> 3, 0);
vs->alloctwobuffers = true;
gdi._disable_zbuffer = false;
grabCursor(vs->screenPtr + vs->xstart, w, h);
-
- blit(vs->screenPtr + vs->xstart, getResourceAddress(rtBuffer, 5) + vs->xstart, w, h);
+
+ blit(vs->screenPtr + vs->xstart,
+ getResourceAddress(rtBuffer, 5) + vs->xstart, w, h);
}
-void Scumm::useBompCursor(byte *im, int width, int height) {
+void Scumm::useBompCursor(byte *im, int width, int height)
+{
uint size;
- width<<=3;
- height<<=3;
-
+ width <<= 3;
+ height <<= 3;
+
size = width * height;
if (size > sizeof(_grabbedCursor))
error("useBompCursor: cursor too big");
@@ -2275,14 +2441,15 @@ void Scumm::useBompCursor(byte *im, int width, int height) {
_cursorHeight = height;
_cursorAnimate = 0;
- decompressBomp(_grabbedCursor, im+10, width, height);
+ decompressBomp(_grabbedCursor, im + 10, width, height);
}
static const byte default_cursor_colors[4] = {
- 15,15,7,8
+ 15, 15, 7, 8
};
-void Scumm::decompressDefaultCursor(int idx) {
+void Scumm::decompressDefaultCursor(int idx)
+{
int i;
byte color;
@@ -2293,43 +2460,47 @@ void Scumm::decompressDefaultCursor(int idx) {
_cursorHotspotY = 7;
color = default_cursor_colors[idx];
-
- for(i=0; i<16; i++) {
- _grabbedCursor[16*8+i] = color;
- _grabbedCursor[16*i+8] = color;
+
+ for (i = 0; i < 16; i++) {
+ _grabbedCursor[16 * 8 + i] = color;
+ _grabbedCursor[16 * i + 8] = color;
}
}
-int Scumm::remapPaletteColor(int r, int g, int b, uint threshold) {
+int Scumm::remapPaletteColor(int r, int g, int b, uint threshold)
+{
int i;
- int ar,ag,ab;
- uint sum,j,bestsum,bestitem=0;
+ int ar, ag, ab;
+ uint sum, j, bestsum, bestitem = 0;
byte *pal = _currentPalette;
- if (r>255) r=255;
- if (g>255) g=255;
- if (b>255) b=255;
+ if (r > 255)
+ r = 255;
+ if (g > 255)
+ g = 255;
+ if (b > 255)
+ b = 255;
- bestsum = (uint)-1;
+ bestsum = (uint) - 1;
r &= ~3;
g &= ~3;
b &= ~3;
- for(i=0; i<256; i++,pal+=3) {
- ar = pal[0]&~3;
- ag = pal[1]&~3;
- ab = pal[2]&~3;
- if (ar==r && ag==g && ab==b)
+ for (i = 0; i < 256; i++, pal += 3) {
+ ar = pal[0] & ~3;
+ ag = pal[1] & ~3;
+ ab = pal[2] & ~3;
+ if (ar == r && ag == g && ab == b)
return i;
- j=abs(ar-r);
- sum = j*j*3;
- j=abs(ag-g);
- sum += j*j*6;
- j=abs(ab-b);
- sum += j*j*2;
+ j = abs(ar - r);
+ sum = j * j * 3;
+ j = abs(ag - g);
+ sum += j * j * 6;
+ j = abs(ab - b);
+ sum += j * j * 2;
if (sum < bestsum) {
bestsum = sum;
@@ -2337,10 +2508,11 @@ int Scumm::remapPaletteColor(int r, int g, int b, uint threshold) {
}
}
- if (threshold != (uint)-1 && bestsum > threshold*threshold*(2+3+6)) {
- pal = _currentPalette + (256-2)*3;
- for(i=254; i>48; i--,pal-=3) {
- if (pal[0]>=252 && pal[1]>=252 && pal[2]>=252) {
+ if (threshold != (uint) - 1
+ && bestsum > threshold * threshold * (2 + 3 + 6)) {
+ pal = _currentPalette + (256 - 2) * 3;
+ for (i = 254; i > 48; i--, pal -= 3) {
+ if (pal[0] >= 252 && pal[1] >= 252 && pal[2] >= 252) {
setPalColor(i, r, g, b);
return i;
}
@@ -2350,93 +2522,96 @@ int Scumm::remapPaletteColor(int r, int g, int b, uint threshold) {
return bestitem;
}
-void Scumm::drawBomp(BompDrawData *bd) {
- byte *dest = bd->out + bd->y * bd->outwidth, *src;
- int h = bd->srcheight;
- bool inside;
-
- if (h==0 || bd->srcwidth==0)
- return;
-
- inside = (bd->x>=0) && (bd->y>=0) &&
- (bd->x <= bd->outwidth - bd->srcwidth) &&
- (bd->y <= bd->outheight - bd->srcheight);
-
- if (1 || bd->scale_x==255 && bd->scale_y==255) {
- /* Routine used when no scaling is needed */
- if (inside) {
- dest += bd->x;
- src = bd->dataptr;
- do {
- byte code,color;
- uint len = bd->srcwidth, num, i;
- byte *d = dest;
- src += 2;
- do {
- code = *src++;
- num = (code>>1)+1;
- if (num>len) num=len;
- len -= num;
- if (code&1) {
- color = *src++;
- if (color!=255) {
- do *d++ = color; while (--num);
- } else {
- d += num;
- }
- } else {
- for(i=0;i<num; i++)
- if ( (color=src[i]) != 255)
- d[i] = color;
- d += num;
- src += num;
- }
- } while (len);
- dest += bd->outwidth;
- } while (--h);
+void Scumm::drawBomp(BompDrawData * bd)
+{
+ byte *dest = bd->out + bd->y * bd->outwidth, *src;
+ int h = bd->srcheight;
+ bool inside;
+
+ if (h == 0 || bd->srcwidth == 0)
+ return;
+
+ inside = (bd->x >= 0) && (bd->y >= 0) &&
+ (bd->x <= bd->outwidth - bd->srcwidth) &&
+ (bd->y <= bd->outheight - bd->srcheight);
+
+ if (1 || bd->scale_x == 255 && bd->scale_y == 255) {
+ /* Routine used when no scaling is needed */
+ if (inside) {
+ dest += bd->x;
+ src = bd->dataptr;
+ do {
+ byte code, color;
+ uint len = bd->srcwidth, num, i;
+ byte *d = dest;
+ src += 2;
+ do {
+ code = *src++;
+ num = (code >> 1) + 1;
+ if (num > len)
+ num = len;
+ len -= num;
+ if (code & 1) {
+ color = *src++;
+ if (color != 255) {
+ do
+ *d++ = color;
+ while (--num);
+ } else {
+ d += num;
+ }
+ } else {
+ for (i = 0; i < num; i++)
+ if ((color = src[i]) != 255)
+ d[i] = color;
+ d += num;
+ src += num;
+ }
+ } while (len);
+ dest += bd->outwidth;
+ } while (--h);
} else {
- uint y = bd->y;
- src = bd->dataptr;
-
- do {
- byte color;
- uint len, num;
- uint x;
- if ((uint)y >= (uint)bd->outheight) {
- src += READ_LE_UINT16(src) + 2;
- continue;
- }
- len = bd->srcwidth;
- x = bd->x;
-
- src += 2;
- do {
- byte code = *src++;
- num = (code>>1)+1;
- if (num>len) num=len;
- len -= num;
- if (code&1) {
- if ((color = *src++)!=255) {
- do {
- if ((uint)x < (uint)bd->outwidth)
- dest[x] = color;
- } while (++x,--num);
- } else {
- x += num;
- }
- } else {
- do {
- if ((color=*src++) != 255 && (uint)x < (uint)bd->outwidth)
- dest[x] = color;
- } while (++x,--num);
- }
- } while (len);
- } while (dest += bd->outwidth,y++,--h);
- }
- } else {
- /* scaling of bomp images not supported yet */
- }
+ uint y = bd->y;
+ src = bd->dataptr;
- CHECK_HEAP
+ do {
+ byte color;
+ uint len, num;
+ uint x;
+ if ((uint) y >= (uint) bd->outheight) {
+ src += READ_LE_UINT16(src) + 2;
+ continue;
+ }
+ len = bd->srcwidth;
+ x = bd->x;
+
+ src += 2;
+ do {
+ byte code = *src++;
+ num = (code >> 1) + 1;
+ if (num > len)
+ num = len;
+ len -= num;
+ if (code & 1) {
+ if ((color = *src++) != 255) {
+ do {
+ if ((uint) x < (uint) bd->outwidth)
+ dest[x] = color;
+ } while (++x, --num);
+ } else {
+ x += num;
+ }
+ } else {
+ do {
+ if ((color = *src++) != 255 && (uint) x < (uint) bd->outwidth)
+ dest[x] = color;
+ } while (++x, --num);
+ }
+ } while (len);
+ } while (dest += bd->outwidth, y++, --h);
+ }
+ } else {
+ /* scaling of bomp images not supported yet */
+ }
-}
+CHECK_HEAP}
diff --git a/gui.cpp b/gui.cpp
index 6625ed53f8..b9b56f1cd7 100644
--- a/gui.cpp
+++ b/gui.cpp
@@ -25,17 +25,17 @@
#ifdef _WIN32_WCE
// Additional variables for Win32 specific GUI
- #include "gapi_keys.h"
- extern bool toolbar_drawn;
- extern bool draw_keyboard;
- extern bool get_key_mapping;
- extern struct keyops keyMapping;
- extern void registry_save(void);
- uint16 _key_mapping_required;
+#include "gapi_keys.h"
+extern bool toolbar_drawn;
+extern bool draw_keyboard;
+extern bool get_key_mapping;
+extern struct keyops keyMapping;
+extern void registry_save(void);
+uint16 _key_mapping_required;
#else
- #define registry_save() ;
- bool get_key_mapping;
- uint16 _key_mapping_required;
+#define registry_save() ;
+bool get_key_mapping;
+uint16 _key_mapping_required;
#endif
enum {
@@ -49,19 +49,20 @@ enum {
};
-void Gui::draw(int start,int end) {
+void Gui::draw(int start, int end)
+{
int i;
- if (end==-1)
- end=start;
+ if (end == -1)
+ end = start;
- for (i=0; i<(int)(sizeof(_widgets) / sizeof(_widgets[0])); i++) {
+ for (i = 0; i < (int)(sizeof(_widgets) / sizeof(_widgets[0])); i++) {
const GuiWidget *w = _widgets[i];
if (w) {
_parentX = 0;
_parentY = 0;
while (w->_type != GUI_NONE) {
- if (w->_id>=start && w->_id<=end && (w->_page&(1<<_cur_page)) ) {
+ if (w->_id >= start && w->_id <= end && (w->_page & (1 << _cur_page))) {
drawWidget(w);
}
if (w->_flags & GWF_PARENT) {
@@ -74,15 +75,16 @@ void Gui::draw(int start,int end) {
}
}
-const GuiWidget *Gui::widgetFromPos(int x, int y) {
+const GuiWidget *Gui::widgetFromPos(int x, int y)
+{
int i;
- for (i=sizeof(_widgets) / sizeof(_widgets[0])-1; i>=0; i--) {
+ for (i = sizeof(_widgets) / sizeof(_widgets[0]) - 1; i >= 0; i--) {
const GuiWidget *w = _widgets[i];
if (w) {
while (w->_type != GUI_NONE) {
- if ((w->_page&(1<<_cur_page)) && w->_id &&
- (uint16)(x-w->_x) < w->_w && (uint16)(y-w->_y) < w->_h)
+ if ((w->_page & (1 << _cur_page)) && w->_id &&
+ (uint16)(x - w->_x) < w->_w && (uint16)(y - w->_y) < w->_h)
return w;
if (w->_flags & GWF_PARENT) {
x -= w->_x;
@@ -95,28 +97,34 @@ const GuiWidget *Gui::widgetFromPos(int x, int y) {
return NULL;
}
-void Gui::drawChar(const char str, int xx, int yy) {
- unsigned int buffer=0, mask = 0, x, y;
- byte *tmp;
- int tempc = _color;
- _color = _textcolor;
-
- tmp = &guifont[0];
- tmp += 224 + (str + 1)*8;
-
- for(y=0;y<8;y++){
- for(x=0;x<8;x++){
- unsigned char color;
- if ((mask >>= 1) == 0) {buffer = *tmp++; mask = 0x80;}
- color = ((buffer & mask) != 0);
- if (color)
+void Gui::drawChar(const char str, int xx, int yy)
+{
+ unsigned int buffer = 0, mask = 0, x, y;
+ byte *tmp;
+ int tempc = _color;
+ _color = _textcolor;
+
+ tmp = &guifont[0];
+ tmp += 224 + (str + 1) * 8;
+
+ for (y = 0; y < 8; y++) {
+ for (x = 0; x < 8; x++) {
+ unsigned char color;
+ if ((mask >>= 1) == 0) {
+ buffer = *tmp++;
+ mask = 0x80;
+ }
+ color = ((buffer & mask) != 0);
+ if (color)
vline(xx + x, yy + y, yy + y);
- }
- }
- _color = tempc;
+ }
+ }
+ _color = tempc;
}
-void Gui::drawString(const char *str, int x, int y, int w, byte color, bool center) {
+void Gui::drawString(const char *str, int x, int y, int w, byte color,
+ bool center)
+{
StringTab *st = &_s->string[5];
st->charset = 1;
st->center = center;
@@ -125,150 +133,164 @@ void Gui::drawString(const char *str, int x, int y, int w, byte color, bool cent
st->ypos = y;
st->right = x + w;
- if (_s->_gameId) { /* If a game is active.. */
- _s->_messagePtr = (byte*)str;
+ if (_s->_gameId) { /* If a game is active.. */
+ _s->_messagePtr = (byte *)str;
_s->drawString(5);
- } else {
+ } else {
for (uint letter = 0; letter < strlen(str); letter++)
- drawChar(str[letter], st->xpos + (letter * 8), st->ypos);
+ drawChar(str[letter], st->xpos + (letter * 8), st->ypos);
}
}
-void Gui::drawWidget(const GuiWidget *w) {
+void Gui::drawWidget(const GuiWidget * w)
+{
const char *s;
- int x,y;
-
+ int x, y;
+
x = w->_x;
y = w->_y;
if (w->_flags & GWF_CLEARBG)
widgetClear(w);
-
+
if (w->_flags & GWF_BORDER) {
widgetBorder(w);
x += 4;
y += 4;
}
- switch(w->_type) {
+ switch (w->_type) {
case GUI_CUSTOMTEXT:
case GUI_VARTEXT:
case GUI_KEYTEXT:
case GUI_ACTIONTEXT:
- case GUI_RESTEXT: {
- char text[500];
- text[0] = '\0';
+ case GUI_RESTEXT:{
+ char text[500];
+ text[0] = '\0';
- switch(w->_type) {
+ switch (w->_type) {
case GUI_CUSTOMTEXT:
strcpy(text, string_map_table_custom[w->_string_number]);
break;
case GUI_RESTEXT:
- s = queryString(w->_string_number,w->_id);
+ s = queryString(w->_string_number, w->_id);
if (s)
strcpy(text, s);
break;
case GUI_VARTEXT:
- sprintf(text, "%s %d", string_map_table_custom[w->_string_number], _gui_variables[w->_string_number]);
+ sprintf(text, "%s %d", string_map_table_custom[w->_string_number],
+ _gui_variables[w->_string_number]);
break;
#ifdef _WIN32_WCE
case GUI_KEYTEXT:
- strcpy(text, getGAPIKeyName(getAction(w->_string_number - 1)->action_key));
+ strcpy(text,
+ getGAPIKeyName(getAction(w->_string_number - 1)->action_key));
break;
case GUI_ACTIONTEXT:
- strcpy(text, getActionName(getAction(w->_string_number - 1)->action_type));
+ strcpy(text,
+ getActionName(getAction(w->_string_number - 1)->action_type));
break;
#endif
+ }
+
+ if (*text) {
+ printf("drawString(%s)\n", text);
+ drawString(text, x + _parentX, y + _parentY, w->_w,
+ (_clickWidget
+ && _clickWidget == w->_id) ? _textcolorhi : _textcolor,
+ false);
+ }
+ break;
}
-
- if (*text) {
- printf("drawString(%s)\n", text);
- drawString(text, x+_parentX, y+_parentY, w->_w,
- (_clickWidget && _clickWidget==w->_id) ? _textcolorhi : _textcolor,
- false);
- }
- break;
- }
case GUI_IMAGE:
;
}
}
-void Gui::widgetClear(const GuiWidget *wid) {
- int x,y,w,h,i;
+void Gui::widgetClear(const GuiWidget * wid)
+{
+ int x, y, w, h, i;
x = wid->_x;
y = wid->_y;
w = wid->_w;
h = wid->_h;
-
- byte *ptr = getBasePtr(x,y);
- if(ptr==NULL)
+
+ byte *ptr = getBasePtr(x, y);
+ if (ptr == NULL)
return;
- _s->setVirtscreenDirty(_vs, x+_parentX, y+_parentY, x+_parentX+w, y+_parentY+h);
+ _s->setVirtscreenDirty(_vs, x + _parentX, y + _parentY, x + _parentX + w,
+ y + _parentY + h);
if (wid->_flags & GWF_BORDER) {
ptr += 320 + 1;
- w-=2;
- h-=2;
+ w -= 2;
+ h -= 2;
}
-
- while (--h>=0) {
- for(i=0; i<w; i++)
+
+ while (--h >= 0) {
+ for (i = 0; i < w; i++)
ptr[i] = _bgcolor;
ptr += 320;
}
}
-void Gui::widgetBorder(const GuiWidget *w) {
+void Gui::widgetBorder(const GuiWidget * w)
+{
int x = w->_x, y = w->_y;
- int x2 = x + w->_w-1, y2 = y + w->_h-1;
+ int x2 = x + w->_w - 1, y2 = y + w->_h - 1;
byte tmp;
-
- hline(x+1,y,x2-1);
- hline(x,y+1,x2);
- vline(x,y+1,y2-1);
- vline(x+1,y,y2);
+
+ hline(x + 1, y, x2 - 1);
+ hline(x, y + 1, x2);
+ vline(x, y + 1, y2 - 1);
+ vline(x + 1, y, y2);
tmp = _color;
_color = _shadowcolor;
- hline(x+1,y2-1,x2);
- hline(x+1,y2,x2-1);
- vline(x2,y+1,y2-1);
- vline(x2-1,y+1,y2);
+ hline(x + 1, y2 - 1, x2);
+ hline(x + 1, y2, x2 - 1);
+ vline(x2, y + 1, y2 - 1);
+ vline(x2 - 1, y + 1, y2);
_color = tmp;
}
-void Gui::hline(int x, int y, int x2) {
- moveto(x,y);
- lineto(x2,y);
+void Gui::hline(int x, int y, int x2)
+{
+ moveto(x, y);
+ lineto(x2, y);
}
-void Gui::vline(int x, int y, int y2) {
- moveto(x,y);
- lineto(x,y2);
+void Gui::vline(int x, int y, int y2)
+{
+ moveto(x, y);
+ lineto(x, y2);
}
-void Gui::moveto(int x, int y) {
+void Gui::moveto(int x, int y)
+{
_curX = x;
_curY = y;
}
-byte *Gui::getBasePtr(int x, int y) {
+byte *Gui::getBasePtr(int x, int y)
+{
x += _parentX;
y += _parentY;
_vs = _s->findVirtScreen(y);
-
- if (_vs==NULL)
+
+ if (_vs == NULL)
return NULL;
-
- return _vs->screenPtr + x + (y-_vs->topline)*320 + _s->_screenStartStrip*8;
+
+ return _vs->screenPtr + x + (y - _vs->topline) * 320 +
+ _s->_screenStartStrip * 8;
}
-void Gui::lineto(int x, int y) {
+void Gui::lineto(int x, int y)
+{
byte *ptr;
int x2 = _curX;
int y2 = _curY;
@@ -277,23 +299,23 @@ void Gui::lineto(int x, int y) {
_curY = y;
if (x2 < x)
- x2^=x^=x2^=x;
+ x2 ^= x ^= x2 ^= x;
if (y2 < y)
- y2^=y^=y2^=y;
+ y2 ^= y ^= y2 ^= y;
ptr = getBasePtr(x, y);
-
- if (ptr==NULL)
+
+ if (ptr == NULL)
return;
- if (x==x2) {
+ if (x == x2) {
/* vertical line */
while (y++ <= y2) {
*ptr = _color;
ptr += 320;
}
- } else if (y==y2) {
+ } else if (y == y2) {
/* horizontal line */
while (x++ <= x2) {
*ptr++ = _color;
@@ -301,221 +323,237 @@ void Gui::lineto(int x, int y) {
}
}
-void Gui::leftMouseClick(int x, int y) {
- const GuiWidget *w = widgetFromPos(x,y);
+void Gui::leftMouseClick(int x, int y)
+{
+ const GuiWidget *w = widgetFromPos(x, y);
int old;
-
+
_clickTimer = 0;
old = _clickWidget;
- _clickWidget = w?w->_id : 0;
+ _clickWidget = w ? w->_id : 0;
if (old)
draw(old);
if (_clickWidget) {
draw(_clickWidget);
- if(w->_flags&GWF_DELAY)
+ if (w->_flags & GWF_DELAY)
_clickTimer = 5;
else
handleCommand(_clickWidget);
}
-
+
if (_dialog == PAUSE_DIALOG)
close();
}
const GuiWidget launcher_dialog[] = {
- {GUI_STAT, 0xFF, GWF_DEFAULT, 0, 0, 320, 200, 0, 0 },
- {GUI_CUSTOMTEXT,0x01,GWF_CLEARBG, 5, 180, 45, 15, 20, 12},
- {GUI_CUSTOMTEXT,0x01,GWF_CLEARBG, 130, 180, 65, 15, 21,17},
- {GUI_CUSTOMTEXT,0x01,GWF_CLEARBG, 265, 180, 50, 15, 22, 7},
- {0,0,0,0,0,0,0,0,0}
+ {GUI_STAT, 0xFF, GWF_DEFAULT, 0, 0, 320, 200, 0, 0},
+ {GUI_CUSTOMTEXT, 0x01, GWF_CLEARBG, 5, 180, 45, 15, 20, 12},
+ {GUI_CUSTOMTEXT, 0x01, GWF_CLEARBG, 130, 180, 65, 15, 21, 17},
+ {GUI_CUSTOMTEXT, 0x01, GWF_CLEARBG, 265, 180, 50, 15, 22, 7},
+ {0, 0, 0, 0, 0, 0, 0, 0, 0}
};
const GuiWidget keys_dialog[] = {
- {GUI_STAT, 0xFF, GWF_DEFAULT, 30, 10, 260, 130, 0, 0 },
+ {GUI_STAT, 0xFF, GWF_DEFAULT, 30, 10, 260, 130, 0, 0},
// First action
- {GUI_CUSTOMTEXT, 0x01, GWF_BUTTON, 30 + 11, 10 + 10, 15, 15, 10, 3}, // CUSTOMTEXT_PLUS
- {GUI_CUSTOMTEXT, 0x01, GWF_BUTTON, 30 + 33, 10 + 10, 15, 15, 11, 4}, // CUSTOMTEXT_MINUS
- {GUI_ACTIONTEXT, 0x01, GWF_BUTTON, 30 + 11 + 33 + 10, 10 + 10, 100, 15, 100, 1},
+ {GUI_CUSTOMTEXT, 0x01, GWF_BUTTON, 30 + 11, 10 + 10, 15, 15, 10, 3}, // CUSTOMTEXT_PLUS
+ {GUI_CUSTOMTEXT, 0x01, GWF_BUTTON, 30 + 33, 10 + 10, 15, 15, 11, 4}, // CUSTOMTEXT_MINUS
+ {GUI_ACTIONTEXT, 0x01, GWF_BUTTON, 30 + 11 + 33 + 10, 10 + 10, 100, 15, 100,
+ 1},
{GUI_KEYTEXT, 0x01, 0, 30 + 11 + 33 + 120, 10 + 10 + 3, 100, 15, 1, 1},
//Second action
- {GUI_CUSTOMTEXT, 0x01, GWF_BUTTON, 30 + 11, 10 + 10 + 15 + 5, 15, 15, 20, 3}, // CUSTOMTEXT_PLUS
- {GUI_CUSTOMTEXT, 0x01, GWF_BUTTON, 30 + 33, 10 + 10 + 15 + 5, 15, 15, 21, 4}, // CUSTOMTEXT_MINUS
- {GUI_ACTIONTEXT, 0x01, GWF_BUTTON, 30 + 10 + 33 + 10, 10 + 10 + 15 + 5, 100, 15, 101, 2},
- {GUI_KEYTEXT, 0x01, 0, 30 + 11 + 33 + 120, 10 + 10 + 15 + 5 + 3, 100, 15, 2, 2},
-
+ {GUI_CUSTOMTEXT, 0x01, GWF_BUTTON, 30 + 11, 10 + 10 + 15 + 5, 15, 15, 20, 3}, // CUSTOMTEXT_PLUS
+ {GUI_CUSTOMTEXT, 0x01, GWF_BUTTON, 30 + 33, 10 + 10 + 15 + 5, 15, 15, 21, 4}, // CUSTOMTEXT_MINUS
+ {GUI_ACTIONTEXT, 0x01, GWF_BUTTON, 30 + 10 + 33 + 10, 10 + 10 + 15 + 5, 100,
+ 15, 101, 2},
+ {GUI_KEYTEXT, 0x01, 0, 30 + 11 + 33 + 120, 10 + 10 + 15 + 5 + 3, 100, 15, 2,
+ 2},
+
//Third action
- {GUI_CUSTOMTEXT, 0x01, GWF_BUTTON, 30 + 11, 10 + 10 + 15 + 5 + 15 + 5, 15, 15, 30, 3},// CUSTOMTEXT_PLUS
- {GUI_CUSTOMTEXT, 0x01, GWF_BUTTON, 30 + 33, 10 + 10 + 15 + 5 + 15 + 5, 15, 15, 31, 4}, // CUSTOMTEXT_MINUS
- {GUI_ACTIONTEXT, 0x01, GWF_BUTTON, 30 + 10 + 33 + 10, 10 + 10 + 15 + 5 + 15 + 5, 100, 15, 102, 3},
- {GUI_KEYTEXT, 0x01, 0, 30 + 11 + 33 + 120, 10 + 10 + 15 + 5 + 15 + 5 + 3, 100, 15, 3, 3},
+ {GUI_CUSTOMTEXT, 0x01, GWF_BUTTON, 30 + 11, 10 + 10 + 15 + 5 + 15 + 5, 15, 15, 30, 3}, // CUSTOMTEXT_PLUS
+ {GUI_CUSTOMTEXT, 0x01, GWF_BUTTON, 30 + 33, 10 + 10 + 15 + 5 + 15 + 5, 15, 15, 31, 4}, // CUSTOMTEXT_MINUS
+ {GUI_ACTIONTEXT, 0x01, GWF_BUTTON, 30 + 10 + 33 + 10,
+ 10 + 10 + 15 + 5 + 15 + 5, 100, 15, 102, 3},
+ {GUI_KEYTEXT, 0x01, 0, 30 + 11 + 33 + 120, 10 + 10 + 15 + 5 + 15 + 5 + 3,
+ 100, 15, 3, 3},
//Fourth action
- {GUI_CUSTOMTEXT, 0x01, GWF_BUTTON, 30 + 11, 10 + 10 + 15 + 5 + 15 + 5 + 15 + 5, 15, 15, 40, 3},
- {GUI_CUSTOMTEXT, 0x01, GWF_BUTTON, 30 + 33, 10 + 10 + 15 + 5 + 15 + 5 + 15 + 5, 15, 15, 41, 4},
- {GUI_ACTIONTEXT, 0x01, GWF_BUTTON, 30 + 10 + 33 + 10, 10 + 10 + 15 + 5 + 15 + 5 + 15 + 5, 100, 15, 103, 4},
- {GUI_KEYTEXT, 0x01, 0, 30 + 11 + 33 + 120, 10 + 10 + 15 + 5 + 15 + 5 + 15 + 5 + 3, 100, 15, 4, 4},
+ {GUI_CUSTOMTEXT, 0x01, GWF_BUTTON, 30 + 11,
+ 10 + 10 + 15 + 5 + 15 + 5 + 15 + 5, 15, 15, 40, 3},
+ {GUI_CUSTOMTEXT, 0x01, GWF_BUTTON, 30 + 33,
+ 10 + 10 + 15 + 5 + 15 + 5 + 15 + 5, 15, 15, 41, 4},
+ {GUI_ACTIONTEXT, 0x01, GWF_BUTTON, 30 + 10 + 33 + 10,
+ 10 + 10 + 15 + 5 + 15 + 5 + 15 + 5, 100, 15, 103, 4},
+ {GUI_KEYTEXT, 0x01, 0, 30 + 11 + 33 + 120,
+ 10 + 10 + 15 + 5 + 15 + 5 + 15 + 5 + 3, 100, 15, 4, 4},
//Fifth action
- {GUI_CUSTOMTEXT, 0x01, GWF_BUTTON, 30 + 11, 10 + 10 + 15 + 5 + 15 + 5 + 15 + 5 + 15 + 5, 15, 15, 50, 3},
- {GUI_CUSTOMTEXT, 0x01, GWF_BUTTON, 30 + 33, 10 + 10 + 15 + 5 + 15 + 5 + 15 + 5 + 15 + 5, 15, 15, 51, 4},
- {GUI_ACTIONTEXT, 0x01, GWF_BUTTON, 30 + 10 + 33 + 10, 10 + 10 + 15 + 5 + 15 + 5 + 15 + 5 + 15 + 5, 100, 15, 104, 5},
- {GUI_KEYTEXT, 0x01, 0, 30 + 11 + 33 + 120, 10 + 10 + 15 + 5 + 15 + 5 + 15 + 5 + 15 + 5 + 3, 100, 15, 5, 5},
+ {GUI_CUSTOMTEXT, 0x01, GWF_BUTTON, 30 + 11,
+ 10 + 10 + 15 + 5 + 15 + 5 + 15 + 5 + 15 + 5, 15, 15, 50, 3},
+ {GUI_CUSTOMTEXT, 0x01, GWF_BUTTON, 30 + 33,
+ 10 + 10 + 15 + 5 + 15 + 5 + 15 + 5 + 15 + 5, 15, 15, 51, 4},
+ {GUI_ACTIONTEXT, 0x01, GWF_BUTTON, 30 + 10 + 33 + 10,
+ 10 + 10 + 15 + 5 + 15 + 5 + 15 + 5 + 15 + 5, 100, 15, 104, 5},
+ {GUI_KEYTEXT, 0x01, 0, 30 + 11 + 33 + 120,
+ 10 + 10 + 15 + 5 + 15 + 5 + 15 + 5 + 15 + 5 + 3, 100, 15, 5, 5},
//OK
- {GUI_RESTEXT, 0x01, GWF_BUTTON, 30 + 113, 10 + 106, 54, 16, 60, 9 },
- {0,0,0,0,0,0,0,0,0}
+ {GUI_RESTEXT, 0x01, GWF_BUTTON, 30 + 113, 10 + 106, 54, 16, 60, 9},
+ {0, 0, 0, 0, 0, 0, 0, 0, 0}
};
const GuiWidget about_dialog[] = {
- {GUI_STAT, 0xFF, GWF_DEFAULT, 30, 20, 260, 120, 0, 0 },
+ {GUI_STAT, 0xFF, GWF_DEFAULT, 30, 20, 260, 120, 0, 0},
// {GUI_CUSTOMTEXT, 0x01, 0, 30 + 95, 20 + 10, 100, 15, 0, }, .. pocketscummvm
- {GUI_CUSTOMTEXT, 0x01, 0, 30 + 68, 20 + 10 + 15 + 5, 160, 15, 0, 9}, // Build
- {GUI_CUSTOMTEXT, 0x01, 0, 30 + 10, 20 + 10 + 15 + 5 + 15, 230, 15, 0, 10}, // ScummVM Url
- {GUI_CUSTOMTEXT, 0x01, 0, 30 + 75, 20 + 10 + 15 + 5 + 15 + 15 + 15, 150, 15, 0, 11}, // Lucasarts
- {GUI_RESTEXT, 0x01, GWF_BUTTON, 30 + 113, 20 + 96, 54, 16, 40, 9 },
- {0,0,0,0,0,0,0,0,0}
+ {GUI_CUSTOMTEXT, 0x01, 0, 30 + 68, 20 + 10 + 15 + 5, 160, 15, 0, 9}, // Build
+ {GUI_CUSTOMTEXT, 0x01, 0, 30 + 10, 20 + 10 + 15 + 5 + 15, 230, 15, 0, 10}, // ScummVM Url
+ {GUI_CUSTOMTEXT, 0x01, 0, 30 + 75, 20 + 10 + 15 + 5 + 15 + 15 + 15, 150, 15, 0, 11}, // Lucasarts
+ {GUI_RESTEXT, 0x01, GWF_BUTTON, 30 + 113, 20 + 96, 54, 16, 40, 9},
+ {0, 0, 0, 0, 0, 0, 0, 0, 0}
};
const GuiWidget options_dialog[] = {
- {GUI_STAT, 0xFF, GWF_DEFAULT, 50, 80, 210, 35, 0, 0 },
- {GUI_CUSTOMTEXT, 0x01, GWF_BUTTON, 50 + 10 , 80 + 10, 40, 15, 1, 5}, // Sound
- {GUI_CUSTOMTEXT, 0x01, GWF_BUTTON, 50 + 10 + 40 + 30 , 80 + 10, 40, 15 , 2, 6}, // Keys
- {GUI_CUSTOMTEXT, 0x01, GWF_BUTTON, 50 + 10 + 40 + 30 + 40 + 30, 80 + 10, 40, 15, 3, 7}, // About
- {0,0,0,0,0,0,0,0,0}
+ {GUI_STAT, 0xFF, GWF_DEFAULT, 50, 80, 210, 35, 0, 0},
+ {GUI_CUSTOMTEXT, 0x01, GWF_BUTTON, 50 + 10, 80 + 10, 40, 15, 1, 5}, // Sound
+ {GUI_CUSTOMTEXT, 0x01, GWF_BUTTON, 50 + 10 + 40 + 30, 80 + 10, 40, 15, 2, 6}, // Keys
+ {GUI_CUSTOMTEXT, 0x01, GWF_BUTTON, 50 + 10 + 40 + 30 + 40 + 30, 80 + 10, 40, 15, 3, 7}, // About
+ {0, 0, 0, 0, 0, 0, 0, 0, 0}
};
const GuiWidget sound_dialog[] = {
- {GUI_STAT, 0xFF, GWF_DEFAULT, 30, 20, 260, 120, 0, 0 },
- {GUI_CUSTOMTEXT, 0x01, GWF_BUTTON, 30 + 11, 20 + 11, 15, 15, 1, 3}, // Plus
- {GUI_CUSTOMTEXT, 0x01, GWF_BUTTON, 30 + 33, 20 + 11, 15, 15, 2, 4}, // Minus
- {GUI_VARTEXT, 0x01, GWF_DEFAULT, 30 + 73, 20 + 11, 128, 15, 3, 0}, // Master
- {GUI_CUSTOMTEXT, 0x01, GWF_BUTTON, 30 + 11, 20 + 25 + 11, 15, 15, 11, 3}, // Plus
- {GUI_CUSTOMTEXT, 0x01, GWF_BUTTON, 30 + 33, 20 + 25 + 11, 15, 15, 12, 4}, // Minus
- {GUI_VARTEXT, 0x01, GWF_BUTTON, 30 + 73, 20 + 25 + 11, 128, 15, 13, 1}, // Music
- {GUI_CUSTOMTEXT, 0x01, GWF_BUTTON, 30 + 11, 20 + 25 + 25 + 11, 15, 15, 21, 3}, // Plus
- {GUI_CUSTOMTEXT, 0x01, GWF_BUTTON, 30 + 33, 20 + 25 + 25 + 11, 15, 15, 22, 4}, // Minus
- {GUI_VARTEXT, 0x01, GWF_BUTTON, 30 + 73, 20 + 25 + 25 + 11, 128, 15, 23, 2}, // SFX
- {GUI_RESTEXT,0x01,GWF_BUTTON,30 + (260 / 2) - 80, 20 + 25 + 25 + 11 + 25 ,54,16,40,9}, /* OK */
- {GUI_RESTEXT,0x01,GWF_BUTTON,30 + (260 / 2), 20 + 25 + 25 + 11 + 25 ,54,16,50,7}, /* Cancel */
- {0,0,0,0,0,0,0,0,0}
+ {GUI_STAT, 0xFF, GWF_DEFAULT, 30, 20, 260, 120, 0, 0},
+ {GUI_CUSTOMTEXT, 0x01, GWF_BUTTON, 30 + 11, 20 + 11, 15, 15, 1, 3}, // Plus
+ {GUI_CUSTOMTEXT, 0x01, GWF_BUTTON, 30 + 33, 20 + 11, 15, 15, 2, 4}, // Minus
+ {GUI_VARTEXT, 0x01, GWF_DEFAULT, 30 + 73, 20 + 11, 128, 15, 3, 0}, // Master
+ {GUI_CUSTOMTEXT, 0x01, GWF_BUTTON, 30 + 11, 20 + 25 + 11, 15, 15, 11, 3}, // Plus
+ {GUI_CUSTOMTEXT, 0x01, GWF_BUTTON, 30 + 33, 20 + 25 + 11, 15, 15, 12, 4}, // Minus
+ {GUI_VARTEXT, 0x01, GWF_BUTTON, 30 + 73, 20 + 25 + 11, 128, 15, 13, 1}, // Music
+ {GUI_CUSTOMTEXT, 0x01, GWF_BUTTON, 30 + 11, 20 + 25 + 25 + 11, 15, 15, 21, 3}, // Plus
+ {GUI_CUSTOMTEXT, 0x01, GWF_BUTTON, 30 + 33, 20 + 25 + 25 + 11, 15, 15, 22, 4}, // Minus
+ {GUI_VARTEXT, 0x01, GWF_BUTTON, 30 + 73, 20 + 25 + 25 + 11, 128, 15, 23, 2}, // SFX
+ {GUI_RESTEXT, 0x01, GWF_BUTTON, 30 + (260 / 2) - 80, 20 + 25 + 25 + 11 + 25, 54, 16, 40, 9}, /* OK */
+ {GUI_RESTEXT, 0x01, GWF_BUTTON, 30 + (260 / 2), 20 + 25 + 25 + 11 + 25, 54, 16, 50, 7}, /* Cancel */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0}
};
const GuiWidget save_load_dialog[] = {
- {GUI_STAT,0xFF,GWF_DEFAULT|GWF_PARENT,30,20,260,125,0,0},
- {GUI_RESTEXT,0x01,0,40,5,128,16,0,1}, /* How may I serve you? */
- {GUI_RESTEXT,0x02,0,40,5,128,16,0,2}, /* Select a game to LOAD */
- {GUI_RESTEXT,0x04,0,40,5,128,16,0,3}, /* Name your SAVE game */
-
- {GUI_STAT,0xFF,GWF_DEFAULT,6,16,170,96,0,0},
- {GUI_RESTEXT,0x01,GWF_DEFAULT,180,20,16,40,0,0},
- {GUI_RESTEXT,0x01,GWF_DEFAULT,180,66,16,40,0,0},
- {GUI_RESTEXT,0xFE,GWF_DEFAULT,180,20,16,40,1,0},
- {GUI_RESTEXT,0xFE,GWF_DEFAULT,180,66,16,40,2,0},
-
- {GUI_RESTEXT,0x06,GWF_CLEARBG,10,20,160,10,20,0},
- {GUI_RESTEXT,0x06,GWF_CLEARBG,10,30,160,10,21,0},
- {GUI_RESTEXT,0x06,GWF_CLEARBG,10,40,160,10,22,0},
- {GUI_RESTEXT,0x06,GWF_CLEARBG,10,50,160,10,23,0},
- {GUI_RESTEXT,0x06,GWF_CLEARBG,10,60,160,10,24,0},
- {GUI_RESTEXT,0x06,GWF_CLEARBG,10,70,160,10,25,0},
- {GUI_RESTEXT,0x06,GWF_CLEARBG,10,80,160,10,26,0},
- {GUI_RESTEXT,0x06,GWF_CLEARBG,10,90,160,10,27,0},
- {GUI_RESTEXT,0x06,GWF_CLEARBG,10,100,160,10,28,0},
-
- {GUI_RESTEXT,0x01,GWF_BUTTON,200,25,54,16,3,4}, /* Save */
- {GUI_RESTEXT,0x01,GWF_BUTTON,200,45,54,16,4,5}, /* Load */
- {GUI_RESTEXT,0x01,GWF_BUTTON,200,65,54,16,5,6}, /* Play */
- {GUI_CUSTOMTEXT,0x01,GWF_BUTTON,200,85,54,16,9,17}, /* Options */
- {GUI_RESTEXT,0x01,GWF_BUTTON,200,105,54,16,6,8}, /* Quit */
-
- {GUI_RESTEXT,0x02,GWF_BUTTON,200,50,54,16,7,7}, /* Cancel */
-
- {GUI_RESTEXT,0x04,GWF_BUTTON,200,45,54,16,8,9}, /* Ok */
- {GUI_RESTEXT,0x04,GWF_BUTTON,200,65,54,16,7,7}, /* Cancel */
- {0,0,0,0,0,0,0,0,0}
+ {GUI_STAT, 0xFF, GWF_DEFAULT | GWF_PARENT, 30, 20, 260, 125, 0, 0},
+ {GUI_RESTEXT, 0x01, 0, 40, 5, 128, 16, 0, 1}, /* How may I serve you? */
+ {GUI_RESTEXT, 0x02, 0, 40, 5, 128, 16, 0, 2}, /* Select a game to LOAD */
+ {GUI_RESTEXT, 0x04, 0, 40, 5, 128, 16, 0, 3}, /* Name your SAVE game */
+
+ {GUI_STAT, 0xFF, GWF_DEFAULT, 6, 16, 170, 96, 0, 0},
+ {GUI_RESTEXT, 0x01, GWF_DEFAULT, 180, 20, 16, 40, 0, 0},
+ {GUI_RESTEXT, 0x01, GWF_DEFAULT, 180, 66, 16, 40, 0, 0},
+ {GUI_RESTEXT, 0xFE, GWF_DEFAULT, 180, 20, 16, 40, 1, 0},
+ {GUI_RESTEXT, 0xFE, GWF_DEFAULT, 180, 66, 16, 40, 2, 0},
+
+ {GUI_RESTEXT, 0x06, GWF_CLEARBG, 10, 20, 160, 10, 20, 0},
+ {GUI_RESTEXT, 0x06, GWF_CLEARBG, 10, 30, 160, 10, 21, 0},
+ {GUI_RESTEXT, 0x06, GWF_CLEARBG, 10, 40, 160, 10, 22, 0},
+ {GUI_RESTEXT, 0x06, GWF_CLEARBG, 10, 50, 160, 10, 23, 0},
+ {GUI_RESTEXT, 0x06, GWF_CLEARBG, 10, 60, 160, 10, 24, 0},
+ {GUI_RESTEXT, 0x06, GWF_CLEARBG, 10, 70, 160, 10, 25, 0},
+ {GUI_RESTEXT, 0x06, GWF_CLEARBG, 10, 80, 160, 10, 26, 0},
+ {GUI_RESTEXT, 0x06, GWF_CLEARBG, 10, 90, 160, 10, 27, 0},
+ {GUI_RESTEXT, 0x06, GWF_CLEARBG, 10, 100, 160, 10, 28, 0},
+
+ {GUI_RESTEXT, 0x01, GWF_BUTTON, 200, 25, 54, 16, 3, 4}, /* Save */
+ {GUI_RESTEXT, 0x01, GWF_BUTTON, 200, 45, 54, 16, 4, 5}, /* Load */
+ {GUI_RESTEXT, 0x01, GWF_BUTTON, 200, 65, 54, 16, 5, 6}, /* Play */
+ {GUI_CUSTOMTEXT, 0x01, GWF_BUTTON, 200, 85, 54, 16, 9, 17}, /* Options */
+ {GUI_RESTEXT, 0x01, GWF_BUTTON, 200, 105, 54, 16, 6, 8}, /* Quit */
+
+ {GUI_RESTEXT, 0x02, GWF_BUTTON, 200, 50, 54, 16, 7, 7}, /* Cancel */
+
+ {GUI_RESTEXT, 0x04, GWF_BUTTON, 200, 45, 54, 16, 8, 9}, /* Ok */
+ {GUI_RESTEXT, 0x04, GWF_BUTTON, 200, 65, 54, 16, 7, 7}, /* Cancel */
+ {0, 0, 0, 0, 0, 0, 0, 0, 0}
};
const GuiWidget pause_dialog[] = {
- {GUI_RESTEXT,0x01,GWF_DEFAULT,50,80,220,16,0,10},
- {0,0,0,0,0,0,0,0,0}
+ {GUI_RESTEXT, 0x01, GWF_DEFAULT, 50, 80, 220, 16, 0, 10},
+ {0, 0, 0, 0, 0, 0, 0, 0, 0}
};
-void Gui::handleSoundDialogCommand(int cmd) {
+void Gui::handleSoundDialogCommand(int cmd)
+{
if (cmd == 40 || cmd == 50) {
if (cmd == 40) {
- SoundEngine *se = (SoundEngine*)_s->_soundEngine;
- _s->_sound_volume_master = _gui_variables[0]; // Master
- _s->_sound_volume_music = _gui_variables[1]; // Music
- _s->_sound_volume_sfx = _gui_variables[2]; // SFX
+ SoundEngine *se = (SoundEngine *)_s->_soundEngine;
+ _s->_sound_volume_master = _gui_variables[0]; // Master
+ _s->_sound_volume_music = _gui_variables[1]; // Music
+ _s->_sound_volume_sfx = _gui_variables[2]; // SFX
se->set_music_volume(_s->_sound_volume_music);
se->set_master_volume(_s->_sound_volume_master);
registry_save();
}
- close();
- return;
+ close();
+ return;
}
if ((cmd % 10) == 1) {
if (_gui_variables[cmd / 10] < 100)
- _gui_variables[cmd / 10]+=5;
- }
- else {
+ _gui_variables[cmd / 10] += 5;
+ } else {
if (_gui_variables[cmd / 10] > 0)
- _gui_variables[cmd / 10]-=5;
+ _gui_variables[cmd / 10] -= 5;
}
-
+
draw((cmd / 10) * 10 + 3, (cmd / 10) * 10 + 3);
}
-void Gui::handleOptionsDialogCommand(int cmd) {
- switch(cmd) {
- case 1:
- _widgets[0] = sound_dialog;
- _gui_variables[0] = _s->_sound_volume_master;
- _gui_variables[1] = _s->_sound_volume_music;
- _gui_variables[2] = _s->_sound_volume_sfx;
- _active = true;
- _cur_page = 0;
- _dialog = SOUND_DIALOG;
- draw(0, 100);
- return;
- case 2:
- _key_mapping_required = 0;
- get_key_mapping = true;
- _widgets[0] = keys_dialog;
- _active = true;
- _cur_page = 0;
- _dialog = KEYS_DIALOG;
- draw(0, 200);
- return;
- case 3:
- _widgets[0] = about_dialog;
- _active = true;
- _cur_page = 0;
- _return_to = 0;
- _dialog = ABOUT_DIALOG;
- draw(0, 100);
- return;
+void Gui::handleOptionsDialogCommand(int cmd)
+{
+ switch (cmd) {
+ case 1:
+ _widgets[0] = sound_dialog;
+ _gui_variables[0] = _s->_sound_volume_master;
+ _gui_variables[1] = _s->_sound_volume_music;
+ _gui_variables[2] = _s->_sound_volume_sfx;
+ _active = true;
+ _cur_page = 0;
+ _dialog = SOUND_DIALOG;
+ draw(0, 100);
+ return;
+ case 2:
+ _key_mapping_required = 0;
+ get_key_mapping = true;
+ _widgets[0] = keys_dialog;
+ _active = true;
+ _cur_page = 0;
+ _dialog = KEYS_DIALOG;
+ draw(0, 200);
+ return;
+ case 3:
+ _widgets[0] = about_dialog;
+ _active = true;
+ _cur_page = 0;
+ _return_to = 0;
+ _dialog = ABOUT_DIALOG;
+ draw(0, 100);
+ return;
}
}
-void Gui::handleKeysDialogCommand(int cmd) {
+void Gui::handleKeysDialogCommand(int cmd)
+{
#ifdef _WIN32_WCE
if (cmd < 100 && cmd != 60) {
- if ((cmd % 10) == 1)
+ if ((cmd % 10) == 1)
setNextType((cmd / 10) - 1);
- else
+ else
setPreviousType((cmd / 10) - 1);
draw(0, 200);
return;
}
-
+
_key_mapping_required = cmd;
if (cmd == 60) {
@@ -528,31 +566,33 @@ void Gui::handleKeysDialogCommand(int cmd) {
#endif
}
-void Gui::handleLauncherDialogCommand(int cmd) {
+void Gui::handleLauncherDialogCommand(int cmd)
+{
printf("handle launcher command\n");
- switch(cmd) {
+ switch (cmd) {
case 20:
close();
- break;
+ break;
case 21:
// Nothing yet
- break;
+ break;
case 22:
- _widgets[0] = about_dialog;
- _active = true;
- _cur_page = 0;
- _return_to = LAUNCHER_DIALOG;
- _dialog = ABOUT_DIALOG;
- draw(0, 100);
- printf("about dialog\n");
- break;
+ _widgets[0] = about_dialog;
+ _active = true;
+ _cur_page = 0;
+ _return_to = LAUNCHER_DIALOG;
+ _dialog = ABOUT_DIALOG;
+ draw(0, 100);
+ printf("about dialog\n");
+ break;
default:
printf("default\n");
close();
- }
+ }
}
-void Gui::handleCommand(int cmd) {
+void Gui::handleCommand(int cmd)
+{
int lastEdit = _editString;
showCaret(false);
@@ -563,9 +603,9 @@ void Gui::handleCommand(int cmd) {
if (_dialog == SOUND_DIALOG) {
handleSoundDialogCommand(cmd);
return;
- }
-
- if (_dialog == OPTIONS_DIALOG) {
+ }
+
+ if (_dialog == OPTIONS_DIALOG) {
handleOptionsDialogCommand(cmd);
return;
}
@@ -582,68 +622,69 @@ void Gui::handleCommand(int cmd) {
_cur_page = 0;
_dialog = LAUNCHER_DIALOG;
draw(0, 100);
- } else
+ } else
close();
return;
}
- switch(cmd) {
- case 1: /* up button */
- if (_slotIndex==0)
+ switch (cmd) {
+ case 1: /* up button */
+ if (_slotIndex == 0)
return;
- getSavegameNames(_slotIndex-9);
- draw(20,28);
+ getSavegameNames(_slotIndex - 9);
+ draw(20, 28);
return;
case 2:
if (_slotIndex > 80)
return;
- getSavegameNames(_slotIndex+9);
- draw(20,28);
+ getSavegameNames(_slotIndex + 9);
+ draw(20, 28);
return;
- case 3: /* save button */
+ case 3: /* save button */
_cur_page = 2;
getSavegameNames(0);
- draw(0,100);
+ draw(0, 100);
return;
- case 4: /* load button */
+ case 4: /* load button */
_cur_page = 1;
getSavegameNames(0);
- draw(0,100);
+ draw(0, 100);
return;
- case 5: /* play button */
+ case 5: /* play button */
close();
return;
- case 6: /* quit button */
+ case 6: /* quit button */
exit(1);
return;
- case 7: /* cancel button */
+ case 7: /* cancel button */
_cur_page = 0;
- draw(0,100);
+ draw(0, 100);
return;
case 8:
- if (lastEdit==-1 || game_names[lastEdit][0]==0)
+ if (lastEdit == -1 || game_names[lastEdit][0] == 0)
return;
_s->_saveLoadSlot = lastEdit + _slotIndex;
_s->_saveLoadCompatible = false;
_s->_saveLoadFlag = 1;
- memcpy(_s->_saveLoadName, game_names[lastEdit], sizeof(_s->_saveLoadName));
+ memcpy(_s->_saveLoadName, game_names[lastEdit],
+ sizeof(_s->_saveLoadName));
close();
return;
- case 9: /* options button */
+ case 9: /* options button */
options(_s);
draw(0, 100);
return;
default:
- if (cmd>=20 && cmd<=28) {
- if(_cur_page==1) {
- if (valid_games[cmd-20]) {
- _s->_saveLoadSlot = cmd-20+_slotIndex;
+ if (cmd >= 20 && cmd <= 28) {
+ if (_cur_page == 1) {
+ if (valid_games[cmd - 20]) {
+ _s->_saveLoadSlot = cmd - 20 + _slotIndex;
_s->_saveLoadCompatible = false;
_s->_saveLoadFlag = 2;
close();
}
return;
- } else if (_cur_page==2) {
+ } else if (_cur_page == 2) {
_clickWidget = cmd;
editString(cmd - 20);
}
@@ -652,73 +693,76 @@ void Gui::handleCommand(int cmd) {
}
-void Gui::getSavegameNames(int start) {
+void Gui::getSavegameNames(int start)
+{
int i;
_slotIndex = start;
- for(i=0; i<9; i++,start++) {
+ for (i = 0; i < 9; i++, start++) {
valid_games[i] = _s->getSavegameName(start, game_names[i]);
}
}
-const char *Gui::queryString(int stringno, int id) {
+const char *Gui::queryString(int stringno, int id)
+{
static char namebuf[64];
char *result;
- int string;
- if (id>=20 && id<=28) {
- sprintf(namebuf, "%2d. %s", id-20+_slotIndex, game_names[id-20]);
+ int string;
+ if (id >= 20 && id <= 28) {
+ sprintf(namebuf, "%2d. %s", id - 20 + _slotIndex, game_names[id - 20]);
return namebuf;
}
if (stringno == 0)
return NULL;
- if (_s->_features&GF_AFTER_V7)
- string = _s->_vars[string_map_table_v7[stringno-1].num];
+ if (_s->_features & GF_AFTER_V7)
+ string = _s->_vars[string_map_table_v7[stringno - 1].num];
+ else if (_s->_features & GF_AFTER_V6)
+ string = _s->_vars[string_map_table_v6[stringno - 1].num];
else
- if (_s->_features&GF_AFTER_V6)
- string = _s->_vars[string_map_table_v6[stringno-1].num];
- else
- string = string_map_table_v5[stringno-1].num;
-
- result = (char*)_s->getStringAddress(string);
+ string = string_map_table_v5[stringno - 1].num;
+
+ result = (char *)_s->getStringAddress(string);
- if (!result) // Gracelessly degrade to english :)
- if (_s->_features&GF_AFTER_V6)
- return string_map_table_v6[stringno-1].string;
+ if (!result) // Gracelessly degrade to english :)
+ if (_s->_features & GF_AFTER_V6)
+ return string_map_table_v6[stringno - 1].string;
else
- return string_map_table_v5[stringno-1].string;
+ return string_map_table_v5[stringno - 1].string;
return result;
}
-void Gui::showCaret(bool show) {
+void Gui::showCaret(bool show)
+{
int i;
char *s;
- if (_editString==-1)
+ if (_editString == -1)
return;
i = _editLen;
s = game_names[_editString];
if (show) {
- if (i < SAVEGAME_NAME_LEN-1) {
+ if (i < SAVEGAME_NAME_LEN - 1) {
s[i] = '_';
- s[i+1] = 0;
+ s[i + 1] = 0;
}
} else {
s[i] = 0;
}
-
+
draw(_editString + 20);
if (!show)
_editString = -1;
}
-void Gui::editString(int i) {
+void Gui::editString(int i)
+{
char *s = game_names[i];
- if(!valid_games[i]) {
+ if (!valid_games[i]) {
valid_games[i] = true;
*s = 0;
}
@@ -727,33 +771,34 @@ void Gui::editString(int i) {
showCaret(true);
}
-void Gui::addLetter(byte letter) {
- switch(_dialog) {
+void Gui::addLetter(byte letter)
+{
+ switch (_dialog) {
case SAVELOAD_DIALOG:
- if (_editString==-1)
+ if (_editString == -1)
return;
- if (letter==13) {
+ if (letter == 13) {
handleCommand(8);
return;
}
- if (letter>=32 && letter<128 && _editLen < SAVEGAME_NAME_LEN-1) {
- game_names[_editString][_editLen++] = letter;
- } else if (letter==8 && _editLen>0) {
+ if (letter >= 32 && letter < 128 && _editLen < SAVEGAME_NAME_LEN - 1) {
+ game_names[_editString][_editLen++] = letter;
+ } else if (letter == 8 && _editLen > 0) {
_editLen--;
}
showCaret(true);
break;
case PAUSE_DIALOG:
- if (letter==32)
+ if (letter == 32)
close();
break;
#ifdef _WIN32_WCE
case KEYS_DIALOG:
clearActionKey(letter);
- if (_key_mapping_required)
+ if (_key_mapping_required)
getAction(_key_mapping_required - 100)->action_key = letter;
_key_mapping_required = 0;
draw(0, 200);
@@ -762,69 +807,75 @@ void Gui::addLetter(byte letter) {
}
}
-byte Gui::getDefaultColor(int color) {
- if((_s->_features & GF_AFTER_V7) || (_s->_features & GF_SMALL_HEADER))
+byte Gui::getDefaultColor(int color)
+{
+ if ((_s->_features & GF_AFTER_V7) || (_s->_features & GF_SMALL_HEADER))
return 0;
- if (_s->_features&GF_AFTER_V6) {
- if (color==8) color=1;
+ if (_s->_features & GF_AFTER_V6) {
+ if (color == 8)
+ color = 1;
return _s->readArray(110, 0, color);
} else {
return _s->getStringAddress(21)[color];
}
}
-void Gui::init(Scumm *s) {
+void Gui::init(Scumm *s)
+{
_s = s;
- if (_s->_gameId && !(_s->_features & GF_SMALL_HEADER) && !(_s->_features & GF_AFTER_V7)) {
- _bgcolor = getDefaultColor(0);
+ if (_s->_gameId && !(_s->_features & GF_SMALL_HEADER)
+ && !(_s->_features & GF_AFTER_V7)) {
+ _bgcolor = getDefaultColor(0);
_color = getDefaultColor(1);
_textcolor = getDefaultColor(2);
_textcolorhi = getDefaultColor(6);
_shadowcolor = getDefaultColor(8);
} else {
_bgcolor = 0;
- _color = 0;
- _textcolor = 8; // 15 is nice
+ _color = 0;
+ _textcolor = 8; // 15 is nice
_textcolorhi = 15;
_shadowcolor = 0;
}
}
-void Gui::loop(Scumm *s) {
+void Gui::loop(Scumm *s)
+{
init(s);
- if (_active==1) {
+ if (_active == 1) {
_active++;
- draw(0,200); // was 100
+ draw(0, 200); // was 100
_s->_cursorAnimate++;
_s->gdi._cursorActive = 1;
_s->pauseSounds(true);
}
-
+
_s->getKeyInput(0);
- if (_s->_mouseButStat&MBS_LEFT_CLICK) {
+ if (_s->_mouseButStat & MBS_LEFT_CLICK) {
leftMouseClick(_s->mouse.x, _s->mouse.y);
} else if (_s->_lastKeyHit) {
if (_dialog != KEYS_DIALOG)
addLetter((unsigned char)_s->_lastKeyHit);
#ifdef _WIN32_WCE
- else if (_s->_lastKeyHit > 1000) // GAPI
+ else if (_s->_lastKeyHit > 1000) // GAPI
addLetter(_s->_lastKeyHit - 1000);
#endif
}
-
+
if (_clickTimer && !--_clickTimer) {
int old = _clickWidget;
_clickWidget = 0;
draw(old);
handleCommand(old);
}
-
+
_s->drawDirtyScreenParts();
_s->_mouseButStat = 0;
}
-void Gui::close() {
+void Gui::close()
+{
_s->_fullRedraw = true;
_s->_completeScreenRedraw = true;
_s->_cursorAnimate--;
@@ -841,7 +892,8 @@ void Gui::close() {
#endif
}
-void Gui::saveLoadDialog(Scumm *s) {
+void Gui::saveLoadDialog(Scumm *s)
+{
init(s);
_widgets[0] = save_load_dialog;
_editString = -1;
@@ -850,7 +902,8 @@ void Gui::saveLoadDialog(Scumm *s) {
_dialog = SAVELOAD_DIALOG;
}
-void Gui::pause(Scumm *s) {
+void Gui::pause(Scumm *s)
+{
init(s);
_widgets[0] = pause_dialog;
_cur_page = 0;
@@ -858,7 +911,8 @@ void Gui::pause(Scumm *s) {
_dialog = PAUSE_DIALOG;
}
-void Gui::options(Scumm *s) {
+void Gui::options(Scumm *s)
+{
init(s);
_widgets[0] = options_dialog;
_active = true;
@@ -866,7 +920,8 @@ void Gui::options(Scumm *s) {
_dialog = OPTIONS_DIALOG;
}
-void Gui::launcher(Scumm *s) {
+void Gui::launcher(Scumm *s)
+{
init(s);
_widgets[0] = launcher_dialog;
_active = true;
diff --git a/init.cpp b/init.cpp
index f103d62ad5..f9672de919 100644
--- a/init.cpp
+++ b/init.cpp
@@ -23,7 +23,6 @@
#include"stdafx.h"
#include"scumm.h"
-Scumm::Scumm(void)
-{
- /* No need to put anything here yet :) */
+Scumm::Scumm (void) {
+ /* No need to put anything here yet :) */
}
diff --git a/insane.cpp b/insane.cpp
index 2d432ac00e..e14062a277 100644
--- a/insane.cpp
+++ b/insane.cpp
@@ -29,69 +29,80 @@
#define SWAP2(a) ((((a)>>24)&0xFF) | (((a)>>8)&0xFF00) | (((a)<<8)&0xFF0000) | (((a)<<24)&0xFF000000))
-void invalidblock(uint32 tag) {
- error("Encountered invalid block %c%c%c%c", tag>>24, tag>>16, tag>>8, tag);
+void invalidblock(uint32 tag)
+{
+ error("Encountered invalid block %c%c%c%c", tag >> 24, tag >> 16, tag >> 8,
+ tag);
}
int _frameChanged;
-uint32 SmushPlayer::nextBE32() {
- uint32 a = *((uint32*)_cur);
+uint32 SmushPlayer::nextBE32()
+{
+ uint32 a = *((uint32 *)_cur);
_cur += sizeof(uint32);
return SWAP2(a);
}
-void SmushPlayer::fileRead(void *mem, int len) {
- if (fread(mem, len,1, _in) != 1)
+void SmushPlayer::fileRead(void *mem, int len)
+{
+ if (fread(mem, len, 1, _in) != 1)
error("EOF while reading");
}
-uint32 SmushPlayer::fileReadBE32() {
+uint32 SmushPlayer::fileReadBE32()
+{
uint32 number;
fileRead(&number, sizeof(number));
return SWAP2(number);
}
-uint32 SmushPlayer::fileReadLE32() {
+uint32 SmushPlayer::fileReadLE32()
+{
uint32 number;
fileRead(&number, sizeof(number));
return number;
}
-void SmushPlayer::openFile(byte* fileName) {
+void SmushPlayer::openFile(byte *fileName)
+{
byte buf[100];
- sprintf((char*)buf,"%sVIDEO/%s",(char*)sm->_gameDataPath,(char*)fileName);
- _in = fopen((char*)buf, "rb");
+ sprintf((char *)buf, "%sVIDEO/%s", (char *)sm->_gameDataPath,
+ (char *)fileName);
+ _in = fopen((char *)buf, "rb");
+
+ if (_in == NULL) {
+ sprintf((char *)buf, "%svideo/%s", (char *)sm->_gameDataPath,
+ (char *)fileName);
+ _in = fopen((char *)buf, "rb");
- if(_in==NULL){
- sprintf((char*)buf,"%svideo/%s",(char*)sm->_gameDataPath,(char*)fileName);
- _in = fopen((char*)buf, "rb");
-
}
}
-void SmushPlayer::nextBlock() {
+void SmushPlayer::nextBlock()
+{
_blockTag = fileReadBE32();
_blockSize = fileReadBE32();
if (_block != NULL)
free(_block);
- _block = (byte*)malloc(_blockSize);
+ _block = (byte *)malloc(_blockSize);
- if (_block==NULL)
+ if (_block == NULL)
error("cannot allocate memory");
fileRead(_block, _blockSize);
}
-bool SmushPlayer::parseTag() {
- switch(nextBlock(), _blockTag) {
+bool SmushPlayer::parseTag()
+{
+ switch (nextBlock(), _blockTag) {
case 'AHDR':
parseAHDR();
@@ -100,7 +111,7 @@ bool SmushPlayer::parseTag() {
case 'FRME':
parseFRME();
break;
-
+
default:
invalidblock(_blockTag);
}
@@ -110,16 +121,18 @@ bool SmushPlayer::parseTag() {
-void SmushPlayer::parseAHDR() {
-// memcpy(_fluPalette, _block, 0x300);
+void SmushPlayer::parseAHDR()
+{
+// memcpy(_fluPalette, _block, 0x300);
_paletteChanged = true;
-// printf("parse AHDR\n");
+// printf("parse AHDR\n");
}
-void SmushPlayer::parseNPAL() {
+void SmushPlayer::parseNPAL()
+{
memcpy(_fluPalette, _cur, 0x300);
_paletteChanged = true;
@@ -127,10 +140,11 @@ void SmushPlayer::parseNPAL() {
-void codec1(CodecData *cd) {
+void codec1(CodecData * cd)
+{
uint y = cd->y;
byte *src = cd->src;
- byte *dest= cd->out;
+ byte *dest = cd->out;
uint h = cd->h;
if (!h || !cd->w)
@@ -143,8 +157,8 @@ void codec1(CodecData *cd) {
uint len, num;
uint x;
- if ((uint)y >= (uint)cd->outheight) {
- src += *(uint16*)(src) + 2;
+ if ((uint) y >= (uint) cd->outheight) {
+ src += *(uint16 *)(src) + 2;
continue;
}
@@ -155,34 +169,36 @@ void codec1(CodecData *cd) {
do {
byte code = *src++;
- num = (code>>1)+1;
- if (num>len) num=len;
+ num = (code >> 1) + 1;
+ if (num > len)
+ num = len;
len -= num;
- if (code&1) {
+ if (code & 1) {
color = *src++;
-// if ((color = *src++)!=0) {
- do {
- if ((uint)x < (uint)cd->outwidth)
- dest[x] = color;
- } while (++x,--num);
-// } else {
-// x += num;
-// }
+// if ((color = *src++)!=0) {
+ do {
+ if ((uint) x < (uint) cd->outwidth)
+ dest[x] = color;
+ } while (++x, --num);
+// } else {
+// x += num;
+// }
} else {
do {
color = *src++;
- if (/*(color=*src++) != 0 &&*/ (uint)x < (uint)cd->outwidth)
+ if ( /*(color=*src++) != 0 && */ (uint) x < (uint) cd->outwidth)
dest[x] = color;
- } while (++x,--num);
+ } while (++x, --num);
}
} while (len);
- } while (dest += cd->pitch,y++,--h);
+ } while (dest += cd->pitch, y++, --h);
}
-void codec37_bompdepack(byte *dst, byte *src, int len) {
+void codec37_bompdepack(byte *dst, byte *src, int len)
+{
byte code;
byte color;
int num;
@@ -190,20 +206,22 @@ void codec37_bompdepack(byte *dst, byte *src, int len) {
do {
code = *src++;
if (code & 1) {
- num = (code>>1) + 1;
+ num = (code >> 1) + 1;
color = *src++;
memset(dst, color, num);
dst += num;
} else {
- num = (code>>1) + 1;
- memcpy(dst,src,num);
+ num = (code >> 1) + 1;
+ memcpy(dst, src, num);
dst += num;
src += num;
}
} while (len -= num);
}
-void codec37_proc5(byte *dst, byte *src, int next_offs, int bw, int bh, int pitch, int16 *table) {
+void codec37_proc5(byte *dst, byte *src, int next_offs, int bw, int bh,
+ int pitch, int16 * table)
+{
byte code, *tmp;
int i;
@@ -213,242 +231,249 @@ void codec37_proc5(byte *dst, byte *src, int next_offs, int bw, int bh, int pitc
}
do {
- i = bw;
+ i = bw;
do {
code = *src++;
- if (code==0xFF) {
- *(uint32*)(dst+0) = ((uint32*)src)[0];
- *(uint32*)(dst+320) = ((uint32*)src)[1];
- *(uint32*)(dst+320*2) = ((uint32*)src)[2];
- *(uint32*)(dst+320*3) = ((uint32*)src)[3];
+ if (code == 0xFF) {
+ *(uint32 *)(dst + 0) = ((uint32 *)src)[0];
+ *(uint32 *)(dst + 320) = ((uint32 *)src)[1];
+ *(uint32 *)(dst + 320 * 2) = ((uint32 *)src)[2];
+ *(uint32 *)(dst + 320 * 3) = ((uint32 *)src)[3];
src += 16;
dst += 4;
} else {
tmp = dst + table[code] + next_offs;
- *(uint32*)(dst+0) = *(uint32*)(tmp);
- *(uint32*)(dst+320) = *(uint32*)(tmp+320);
- *(uint32*)(dst+320*2) = *(uint32*)(tmp+320*2);
- *(uint32*)(dst+320*3) = *(uint32*)(tmp+320*3);
+ *(uint32 *)(dst + 0) = *(uint32 *)(tmp);
+ *(uint32 *)(dst + 320) = *(uint32 *)(tmp + 320);
+ *(uint32 *)(dst + 320 * 2) = *(uint32 *)(tmp + 320 * 2);
+ *(uint32 *)(dst + 320 * 3) = *(uint32 *)(tmp + 320 * 3);
dst += 4;
}
- } while(--i);
- dst += 320*4 - 320;
+ } while (--i);
+ dst += 320 * 4 - 320;
} while (--bh);
-}
+}
static const int8 maketable_bytes[] = {
-0, 0, 1, 0, 2, 0, 3, 0, 5, 0, 8, 0, 13, 0, 21, 0,
--1, 0, -2, 0, -3, 0, -5, 0, -8, 0, -13, 0, -17, 0, -21, 0,
-0, 1, 1, 1, 2, 1, 3, 1, 5, 1, 8, 1, 13, 1, 21, 1,
--1, 1, -2, 1, -3, 1, -5, 1, -8, 1, -13, 1, -17, 1, -21, 1,
-0, 2, 1, 2, 2, 2, 3, 2, 5, 2, 8, 2, 13, 2, 21, 2,
--1, 2, -2, 2, -3, 2, -5, 2, -8, 2, -13, 2, -17, 2, -21, 2,
-0, 3, 1, 3, 2, 3, 3, 3, 5, 3, 8, 3, 13, 3, 21, 3,
--1, 3, -2, 3, -3, 3, -5, 3, -8, 3, -13, 3, -17, 3, -21, 3,
-0, 5, 1, 5, 2, 5, 3, 5, 5, 5, 8, 5, 13, 5, 21, 5,
--1, 5, -2, 5, -3, 5, -5, 5, -8, 5, -13, 5, -17, 5, -21, 5,
-0, 8, 1, 8, 2, 8, 3, 8, 5, 8, 8, 8, 13, 8, 21, 8,
--1, 8, -2, 8, -3, 8, -5, 8, -8, 8, -13, 8, -17, 8, -21, 8,
-0, 13, 1, 13, 2, 13, 3, 13, 5, 13, 8, 13, 13, 13, 21, 13,
--1, 13, -2, 13, -3, 13, -5, 13, -8, 13, -13, 13, -17, 13, -21, 13,
-0, 21, 1, 21, 2, 21, 3, 21, 5, 21, 8, 21, 13, 21, 21, 21,
--1, 21, -2, 21, -3, 21, -5, 21, -8, 21, -13, 21, -17, 21, -21, 21,
-0, -1, 1, -1, 2, -1, 3, -1, 5, -1, 8, -1, 13, -1, 21, -1,
--1, -1, -2, -1, -3, -1, -5, -1, -8, -1, -13, -1, -17, -1, -21, -1,
-0, -2, 1, -2, 2, -2, 3, -2, 5, -2, 8, -2, 13, -2, 21, -2,
--1, -2, -2, -2, -3, -2, -5, -2, -8, -2, -13, -2, -17, -2, -21, -2,
-0, -3, 1, -3, 2, -3, 3, -3, 5, -3, 8, -3, 13, -3, 21, -3,
--1, -3, -2, -3, -3, -3, -5, -3, -8, -3, -13, -3, -17, -3, -21, -3,
-0, -5, 1, -5, 2, -5, 3, -5, 5, -5, 8, -5, 13, -5, 21, -5,
--1, -5, -2, -5, -3, -5, -5, -5, -8, -5, -13, -5, -17, -5, -21, -5,
-0, -8, 1, -8, 2, -8, 3, -8, 5, -8, 8, -8, 13, -8, 21, -8,
--1, -8, -2, -8, -3, -8, -5, -8, -8, -8, -13, -8, -17, -8, -21, -8,
-0, -13, 1, -13, 2, -13, 3, -13, 5, -13, 8, -13, 13, -13, 21, -13,
--1, -13, -2, -13, -3, -13, -5, -13, -8, -13, -13, -13, -17, -13, -21, -13,
-0, -17, 1, -17, 2, -17, 3, -17, 5, -17, 8, -17, 13, -17, 21, -17,
--1, -17, -2, -17, -3, -17, -5, -17, -8, -17, -13, -17, -17, -17, -21, -17,
-0, -21, 1, -21, 2, -21, 3, -21, 5, -21, 8, -21, 13, -21, 21, -21,
--1, -21, -2, -21, -3, -21, -5, -21, -8, -21, -13, -21, -17, -21, 0, 0,
--8, -29, 8, -29, -18, -25, 17, -25, 0, -23, -6, -22, 6, -22, -13, -19,
-12, -19, 0, -18, 25, -18, -25, -17, -5, -17, 5, -17, -10, -15, 10, -15,
-0, -14, -4, -13, 4, -13, 19, -13, -19, -12, -8, -11, -2, -11, 0, -11,
-2, -11, 8, -11, -15, -10, -4, -10, 4, -10, 15, -10, -6, -9, -1, -9,
-1, -9, 6, -9, -29, -8, -11, -8, -8, -8, -3, -8, 3, -8, 8, -8,
-11, -8, 29, -8, -5, -7, -2, -7, 0, -7, 2, -7, 5, -7, -22, -6,
--9, -6, -6, -6, -3, -6, -1, -6, 1, -6, 3, -6, 6, -6, 9, -6,
-22, -6, -17, -5, -7, -5, -4, -5, -2, -5, 0, -5, 2, -5, 4, -5,
-7, -5, 17, -5, -13, -4, -10, -4, -5, -4, -3, -4, -1, -4, 0, -4,
-1, -4, 3, -4, 5, -4, 10, -4, 13, -4, -8, -3, -6, -3, -4, -3,
--3, -3, -2, -3, -1, -3, 0, -3, 1, -3, 2, -3, 4, -3, 6, -3,
-8, -3, -11, -2, -7, -2, -5, -2, -3, -2, -2, -2, -1, -2, 0, -2,
-1, -2, 2, -2, 3, -2, 5, -2, 7, -2, 11, -2, -9, -1, -6, -1,
--4, -1, -3, -1, -2, -1, -1, -1, 0, -1, 1, -1, 2, -1, 3, -1,
-4, -1, 6, -1, 9, -1, -31, 0, -23, 0, -18, 0, -14, 0, -11, 0,
--7, 0, -5, 0, -4, 0, -3, 0, -2, 0, -1, 0, 0, -31, 1, 0,
-2, 0, 3, 0, 4, 0, 5, 0, 7, 0, 11, 0, 14, 0, 18, 0,
-23, 0, 31, 0, -9, 1, -6, 1, -4, 1, -3, 1, -2, 1, -1, 1,
-0, 1, 1, 1, 2, 1, 3, 1, 4, 1, 6, 1, 9, 1, -11, 2,
--7, 2, -5, 2, -3, 2, -2, 2, -1, 2, 0, 2, 1, 2, 2, 2,
-3, 2, 5, 2, 7, 2, 11, 2, -8, 3, -6, 3, -4, 3, -2, 3,
--1, 3, 0, 3, 1, 3, 2, 3, 3, 3, 4, 3, 6, 3, 8, 3,
--13, 4, -10, 4, -5, 4, -3, 4, -1, 4, 0, 4, 1, 4, 3, 4,
-5, 4, 10, 4, 13, 4, -17, 5, -7, 5, -4, 5, -2, 5, 0, 5,
-2, 5, 4, 5, 7, 5, 17, 5, -22, 6, -9, 6, -6, 6, -3, 6,
--1, 6, 1, 6, 3, 6, 6, 6, 9, 6, 22, 6, -5, 7, -2, 7,
-0, 7, 2, 7, 5, 7, -29, 8, -11, 8, -8, 8, -3, 8, 3, 8,
-8, 8, 11, 8, 29, 8, -6, 9, -1, 9, 1, 9, 6, 9, -15, 10,
--4, 10, 4, 10, 15, 10, -8, 11, -2, 11, 0, 11, 2, 11, 8, 11,
-19, 12, -19, 13, -4, 13, 4, 13, 0, 14, -10, 15, 10, 15, -5, 17,
-5, 17, 25, 17, -25, 18, 0, 18, -12, 19, 13, 19, -6, 22, 6, 22,
-0, 23, -17, 25, 18, 25, -8, 29, 8, 29, 0, 31, 0, 0, -6, -22,
-6, -22, -13, -19, 12, -19, 0, -18, -5, -17, 5, -17, -10, -15, 10, -15,
-0, -14, -4, -13, 4, -13, 19, -13, -19, -12, -8, -11, -2, -11, 0, -11,
-2, -11, 8, -11, -15, -10, -4, -10, 4, -10, 15, -10, -6, -9, -1, -9,
-1, -9, 6, -9, -11, -8, -8, -8, -3, -8, 0, -8, 3, -8, 8, -8,
-11, -8, -5, -7, -2, -7, 0, -7, 2, -7, 5, -7, -22, -6, -9, -6,
--6, -6, -3, -6, -1, -6, 1, -6, 3, -6, 6, -6, 9, -6, 22, -6,
--17, -5, -7, -5, -4, -5, -2, -5, -1, -5, 0, -5, 1, -5, 2, -5,
-4, -5, 7, -5, 17, -5, -13, -4, -10, -4, -5, -4, -3, -4, -2, -4,
--1, -4, 0, -4, 1, -4, 2, -4, 3, -4, 5, -4, 10, -4, 13, -4,
--8, -3, -6, -3, -4, -3, -3, -3, -2, -3, -1, -3, 0, -3, 1, -3,
-2, -3, 3, -3, 4, -3, 6, -3, 8, -3, -11, -2, -7, -2, -5, -2,
--4, -2, -3, -2, -2, -2, -1, -2, 0, -2, 1, -2, 2, -2, 3, -2,
-4, -2, 5, -2, 7, -2, 11, -2, -9, -1, -6, -1, -5, -1, -4, -1,
--3, -1, -2, -1, -1, -1, 0, -1, 1, -1, 2, -1, 3, -1, 4, -1,
-5, -1, 6, -1, 9, -1, -23, 0, -18, 0, -14, 0, -11, 0, -7, 0,
--5, 0, -4, 0, -3, 0, -2, 0, -1, 0, 0, -23, 1, 0, 2, 0,
-3, 0, 4, 0, 5, 0, 7, 0, 11, 0, 14, 0, 18, 0, 23, 0,
--9, 1, -6, 1, -5, 1, -4, 1, -3, 1, -2, 1, -1, 1, 0, 1,
-1, 1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 9, 1, -11, 2,
--7, 2, -5, 2, -4, 2, -3, 2, -2, 2, -1, 2, 0, 2, 1, 2,
-2, 2, 3, 2, 4, 2, 5, 2, 7, 2, 11, 2, -8, 3, -6, 3,
--4, 3, -3, 3, -2, 3, -1, 3, 0, 3, 1, 3, 2, 3, 3, 3,
-4, 3, 6, 3, 8, 3, -13, 4, -10, 4, -5, 4, -3, 4, -2, 4,
--1, 4, 0, 4, 1, 4, 2, 4, 3, 4, 5, 4, 10, 4, 13, 4,
--17, 5, -7, 5, -4, 5, -2, 5, -1, 5, 0, 5, 1, 5, 2, 5,
-4, 5, 7, 5, 17, 5, -22, 6, -9, 6, -6, 6, -3, 6, -1, 6,
-1, 6, 3, 6, 6, 6, 9, 6, 22, 6, -5, 7, -2, 7, 0, 7,
-2, 7, 5, 7, -11, 8, -8, 8, -3, 8, 0, 8, 3, 8, 8, 8,
-11, 8, -6, 9, -1, 9, 1, 9, 6, 9, -15, 10, -4, 10, 4, 10,
-15, 10, -8, 11, -2, 11, 0, 11, 2, 11, 8, 11, 19, 12, -19, 13,
--4, 13, 4, 13, 0, 14, -10, 15, 10, 15, -5, 17, 5, 17, 0, 18,
--12, 19, 13, 19, -6, 22, 6, 22, 0, 23,
+ 0, 0, 1, 0, 2, 0, 3, 0, 5, 0, 8, 0, 13, 0, 21, 0,
+ -1, 0, -2, 0, -3, 0, -5, 0, -8, 0, -13, 0, -17, 0, -21, 0,
+ 0, 1, 1, 1, 2, 1, 3, 1, 5, 1, 8, 1, 13, 1, 21, 1,
+ -1, 1, -2, 1, -3, 1, -5, 1, -8, 1, -13, 1, -17, 1, -21, 1,
+ 0, 2, 1, 2, 2, 2, 3, 2, 5, 2, 8, 2, 13, 2, 21, 2,
+ -1, 2, -2, 2, -3, 2, -5, 2, -8, 2, -13, 2, -17, 2, -21, 2,
+ 0, 3, 1, 3, 2, 3, 3, 3, 5, 3, 8, 3, 13, 3, 21, 3,
+ -1, 3, -2, 3, -3, 3, -5, 3, -8, 3, -13, 3, -17, 3, -21, 3,
+ 0, 5, 1, 5, 2, 5, 3, 5, 5, 5, 8, 5, 13, 5, 21, 5,
+ -1, 5, -2, 5, -3, 5, -5, 5, -8, 5, -13, 5, -17, 5, -21, 5,
+ 0, 8, 1, 8, 2, 8, 3, 8, 5, 8, 8, 8, 13, 8, 21, 8,
+ -1, 8, -2, 8, -3, 8, -5, 8, -8, 8, -13, 8, -17, 8, -21, 8,
+ 0, 13, 1, 13, 2, 13, 3, 13, 5, 13, 8, 13, 13, 13, 21, 13,
+ -1, 13, -2, 13, -3, 13, -5, 13, -8, 13, -13, 13, -17, 13, -21, 13,
+ 0, 21, 1, 21, 2, 21, 3, 21, 5, 21, 8, 21, 13, 21, 21, 21,
+ -1, 21, -2, 21, -3, 21, -5, 21, -8, 21, -13, 21, -17, 21, -21, 21,
+ 0, -1, 1, -1, 2, -1, 3, -1, 5, -1, 8, -1, 13, -1, 21, -1,
+ -1, -1, -2, -1, -3, -1, -5, -1, -8, -1, -13, -1, -17, -1, -21, -1,
+ 0, -2, 1, -2, 2, -2, 3, -2, 5, -2, 8, -2, 13, -2, 21, -2,
+ -1, -2, -2, -2, -3, -2, -5, -2, -8, -2, -13, -2, -17, -2, -21, -2,
+ 0, -3, 1, -3, 2, -3, 3, -3, 5, -3, 8, -3, 13, -3, 21, -3,
+ -1, -3, -2, -3, -3, -3, -5, -3, -8, -3, -13, -3, -17, -3, -21, -3,
+ 0, -5, 1, -5, 2, -5, 3, -5, 5, -5, 8, -5, 13, -5, 21, -5,
+ -1, -5, -2, -5, -3, -5, -5, -5, -8, -5, -13, -5, -17, -5, -21, -5,
+ 0, -8, 1, -8, 2, -8, 3, -8, 5, -8, 8, -8, 13, -8, 21, -8,
+ -1, -8, -2, -8, -3, -8, -5, -8, -8, -8, -13, -8, -17, -8, -21, -8,
+ 0, -13, 1, -13, 2, -13, 3, -13, 5, -13, 8, -13, 13, -13, 21, -13,
+ -1, -13, -2, -13, -3, -13, -5, -13, -8, -13, -13, -13, -17, -13, -21, -13,
+ 0, -17, 1, -17, 2, -17, 3, -17, 5, -17, 8, -17, 13, -17, 21, -17,
+ -1, -17, -2, -17, -3, -17, -5, -17, -8, -17, -13, -17, -17, -17, -21, -17,
+ 0, -21, 1, -21, 2, -21, 3, -21, 5, -21, 8, -21, 13, -21, 21, -21,
+ -1, -21, -2, -21, -3, -21, -5, -21, -8, -21, -13, -21, -17, -21, 0, 0,
+ -8, -29, 8, -29, -18, -25, 17, -25, 0, -23, -6, -22, 6, -22, -13, -19,
+ 12, -19, 0, -18, 25, -18, -25, -17, -5, -17, 5, -17, -10, -15, 10, -15,
+ 0, -14, -4, -13, 4, -13, 19, -13, -19, -12, -8, -11, -2, -11, 0, -11,
+ 2, -11, 8, -11, -15, -10, -4, -10, 4, -10, 15, -10, -6, -9, -1, -9,
+ 1, -9, 6, -9, -29, -8, -11, -8, -8, -8, -3, -8, 3, -8, 8, -8,
+ 11, -8, 29, -8, -5, -7, -2, -7, 0, -7, 2, -7, 5, -7, -22, -6,
+ -9, -6, -6, -6, -3, -6, -1, -6, 1, -6, 3, -6, 6, -6, 9, -6,
+ 22, -6, -17, -5, -7, -5, -4, -5, -2, -5, 0, -5, 2, -5, 4, -5,
+ 7, -5, 17, -5, -13, -4, -10, -4, -5, -4, -3, -4, -1, -4, 0, -4,
+ 1, -4, 3, -4, 5, -4, 10, -4, 13, -4, -8, -3, -6, -3, -4, -3,
+ -3, -3, -2, -3, -1, -3, 0, -3, 1, -3, 2, -3, 4, -3, 6, -3,
+ 8, -3, -11, -2, -7, -2, -5, -2, -3, -2, -2, -2, -1, -2, 0, -2,
+ 1, -2, 2, -2, 3, -2, 5, -2, 7, -2, 11, -2, -9, -1, -6, -1,
+ -4, -1, -3, -1, -2, -1, -1, -1, 0, -1, 1, -1, 2, -1, 3, -1,
+ 4, -1, 6, -1, 9, -1, -31, 0, -23, 0, -18, 0, -14, 0, -11, 0,
+ -7, 0, -5, 0, -4, 0, -3, 0, -2, 0, -1, 0, 0, -31, 1, 0,
+ 2, 0, 3, 0, 4, 0, 5, 0, 7, 0, 11, 0, 14, 0, 18, 0,
+ 23, 0, 31, 0, -9, 1, -6, 1, -4, 1, -3, 1, -2, 1, -1, 1,
+ 0, 1, 1, 1, 2, 1, 3, 1, 4, 1, 6, 1, 9, 1, -11, 2,
+ -7, 2, -5, 2, -3, 2, -2, 2, -1, 2, 0, 2, 1, 2, 2, 2,
+ 3, 2, 5, 2, 7, 2, 11, 2, -8, 3, -6, 3, -4, 3, -2, 3,
+ -1, 3, 0, 3, 1, 3, 2, 3, 3, 3, 4, 3, 6, 3, 8, 3,
+ -13, 4, -10, 4, -5, 4, -3, 4, -1, 4, 0, 4, 1, 4, 3, 4,
+ 5, 4, 10, 4, 13, 4, -17, 5, -7, 5, -4, 5, -2, 5, 0, 5,
+ 2, 5, 4, 5, 7, 5, 17, 5, -22, 6, -9, 6, -6, 6, -3, 6,
+ -1, 6, 1, 6, 3, 6, 6, 6, 9, 6, 22, 6, -5, 7, -2, 7,
+ 0, 7, 2, 7, 5, 7, -29, 8, -11, 8, -8, 8, -3, 8, 3, 8,
+ 8, 8, 11, 8, 29, 8, -6, 9, -1, 9, 1, 9, 6, 9, -15, 10,
+ -4, 10, 4, 10, 15, 10, -8, 11, -2, 11, 0, 11, 2, 11, 8, 11,
+ 19, 12, -19, 13, -4, 13, 4, 13, 0, 14, -10, 15, 10, 15, -5, 17,
+ 5, 17, 25, 17, -25, 18, 0, 18, -12, 19, 13, 19, -6, 22, 6, 22,
+ 0, 23, -17, 25, 18, 25, -8, 29, 8, 29, 0, 31, 0, 0, -6, -22,
+ 6, -22, -13, -19, 12, -19, 0, -18, -5, -17, 5, -17, -10, -15, 10, -15,
+ 0, -14, -4, -13, 4, -13, 19, -13, -19, -12, -8, -11, -2, -11, 0, -11,
+ 2, -11, 8, -11, -15, -10, -4, -10, 4, -10, 15, -10, -6, -9, -1, -9,
+ 1, -9, 6, -9, -11, -8, -8, -8, -3, -8, 0, -8, 3, -8, 8, -8,
+ 11, -8, -5, -7, -2, -7, 0, -7, 2, -7, 5, -7, -22, -6, -9, -6,
+ -6, -6, -3, -6, -1, -6, 1, -6, 3, -6, 6, -6, 9, -6, 22, -6,
+ -17, -5, -7, -5, -4, -5, -2, -5, -1, -5, 0, -5, 1, -5, 2, -5,
+ 4, -5, 7, -5, 17, -5, -13, -4, -10, -4, -5, -4, -3, -4, -2, -4,
+ -1, -4, 0, -4, 1, -4, 2, -4, 3, -4, 5, -4, 10, -4, 13, -4,
+ -8, -3, -6, -3, -4, -3, -3, -3, -2, -3, -1, -3, 0, -3, 1, -3,
+ 2, -3, 3, -3, 4, -3, 6, -3, 8, -3, -11, -2, -7, -2, -5, -2,
+ -4, -2, -3, -2, -2, -2, -1, -2, 0, -2, 1, -2, 2, -2, 3, -2,
+ 4, -2, 5, -2, 7, -2, 11, -2, -9, -1, -6, -1, -5, -1, -4, -1,
+ -3, -1, -2, -1, -1, -1, 0, -1, 1, -1, 2, -1, 3, -1, 4, -1,
+ 5, -1, 6, -1, 9, -1, -23, 0, -18, 0, -14, 0, -11, 0, -7, 0,
+ -5, 0, -4, 0, -3, 0, -2, 0, -1, 0, 0, -23, 1, 0, 2, 0,
+ 3, 0, 4, 0, 5, 0, 7, 0, 11, 0, 14, 0, 18, 0, 23, 0,
+ -9, 1, -6, 1, -5, 1, -4, 1, -3, 1, -2, 1, -1, 1, 0, 1,
+ 1, 1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 9, 1, -11, 2,
+ -7, 2, -5, 2, -4, 2, -3, 2, -2, 2, -1, 2, 0, 2, 1, 2,
+ 2, 2, 3, 2, 4, 2, 5, 2, 7, 2, 11, 2, -8, 3, -6, 3,
+ -4, 3, -3, 3, -2, 3, -1, 3, 0, 3, 1, 3, 2, 3, 3, 3,
+ 4, 3, 6, 3, 8, 3, -13, 4, -10, 4, -5, 4, -3, 4, -2, 4,
+ -1, 4, 0, 4, 1, 4, 2, 4, 3, 4, 5, 4, 10, 4, 13, 4,
+ -17, 5, -7, 5, -4, 5, -2, 5, -1, 5, 0, 5, 1, 5, 2, 5,
+ 4, 5, 7, 5, 17, 5, -22, 6, -9, 6, -6, 6, -3, 6, -1, 6,
+ 1, 6, 3, 6, 6, 6, 9, 6, 22, 6, -5, 7, -2, 7, 0, 7,
+ 2, 7, 5, 7, -11, 8, -8, 8, -3, 8, 0, 8, 3, 8, 8, 8,
+ 11, 8, -6, 9, -1, 9, 1, 9, 6, 9, -15, 10, -4, 10, 4, 10,
+ 15, 10, -8, 11, -2, 11, 0, 11, 2, 11, 8, 11, 19, 12, -19, 13,
+ -4, 13, 4, 13, 0, 14, -10, 15, 10, 15, -5, 17, 5, 17, 0, 18,
+ -12, 19, 13, 19, -6, 22, 6, 22, 0, 23,
};
-void codec37_maketable(PersistentCodecData37 *pcd, int pitch, byte idx) {
- int i,j;
+void codec37_maketable(PersistentCodecData37 * pcd, int pitch, byte idx)
+{
+ int i, j;
- if (pcd->table_last_pitch==pitch && pcd->table_last_flags==idx)
+ if (pcd->table_last_pitch == pitch && pcd->table_last_flags == idx)
return;
pcd->table_last_pitch = pitch;
pcd->table_last_flags = idx;
- assert(idx*255 + 254 < (int)(sizeof(maketable_bytes)/2));
+ assert(idx * 255 + 254 < (int)(sizeof(maketable_bytes) / 2));
- for(i=0; i<255; i++) {
- j = i + idx*255;
- pcd->table1[i] = maketable_bytes[j*2+1] * pitch + maketable_bytes[j*2];
+ for (i = 0; i < 255; i++) {
+ j = i + idx * 255;
+ pcd->table1[i] =
+ maketable_bytes[j * 2 + 1] * pitch + maketable_bytes[j * 2];
}
}
-int codec37(CodecData *cd, PersistentCodecData37 *pcd) {
+int codec37(CodecData * cd, PersistentCodecData37 * pcd)
+{
int width_in_blocks, height_in_blocks;
int src_pitch;
byte *curbuf;
uint size;
bool result = false;
- _frameChanged=1;
-
+ _frameChanged = 1;
+
width_in_blocks = (cd->w + 3) >> 2;
height_in_blocks = (cd->h + 3) >> 2;
src_pitch = width_in_blocks * 4;
codec37_maketable(pcd, src_pitch, cd->src[1]);
- switch(cd->src[0]) {
- case 0: {
- curbuf = pcd->deltaBufs[pcd->curtable];
- memset(pcd->deltaBuf, 0, curbuf - pcd->deltaBuf);
- size = *(uint32*)(cd->src + 4);
- memset(curbuf + size, 0, pcd->deltaBuf + pcd->deltaSize - curbuf - size);
- memcpy(curbuf, cd->src + 16, size);
- break;
- }
+ switch (cd->src[0]) {
+ case 0:{
+ curbuf = pcd->deltaBufs[pcd->curtable];
+ memset(pcd->deltaBuf, 0, curbuf - pcd->deltaBuf);
+ size = *(uint32 *)(cd->src + 4);
+ memset(curbuf + size, 0,
+ pcd->deltaBuf + pcd->deltaSize - curbuf - size);
+ memcpy(curbuf, cd->src + 16, size);
+ break;
+ }
- case 2: {
- size = *(uint32*)(cd->src + 4);
- curbuf = pcd->deltaBufs[pcd->curtable];
- if(size==64000)
- codec37_bompdepack(curbuf, cd->src+16, size);
- else
- return(1);
+ case 2:{
+ size = *(uint32 *)(cd->src + 4);
+ curbuf = pcd->deltaBufs[pcd->curtable];
+ if (size == 64000)
+ codec37_bompdepack(curbuf, cd->src + 16, size);
+ else
+ return (1);
+
+ memset(pcd->deltaBuf, 0, curbuf - pcd->deltaBuf);
+ memset(curbuf + size, 0,
+ pcd->deltaBuf + pcd->deltaSize - curbuf - size);
+ break;
+ }
- memset(pcd->deltaBuf, 0, curbuf - pcd->deltaBuf);
- memset(curbuf + size, 0, pcd->deltaBuf + pcd->deltaSize - curbuf - size);
- break;
- }
+ case 3:{
+ uint16 number = *(uint16 *)(cd->src + 2);
- case 3: {
- uint16 number = *(uint16*)(cd->src + 2);
+ if (number && pcd->flags + 1 != number)
+ break;
- if ( number && pcd->flags+1 != number)
- break;
+ if (number & 1 && cd->src[12] & 1 && cd->flags & 0x10) {
+ _frameChanged = 0;
+ result = true;
+ break;
+ }
- if (number&1 && cd->src[12]&1 && cd->flags&0x10) {
- _frameChanged = 0;
- result=true;
- break;
- }
+ if ((number & 1) || !(cd->src[12] & 1)) {
+ pcd->curtable ^= 1;
+ }
- if ((number&1) || !(cd->src[12]&1)) {
- pcd->curtable ^= 1;
+ codec37_proc5(pcd->deltaBufs[pcd->curtable], cd->src + 16,
+ pcd->deltaBufs[pcd->curtable ^ 1] -
+ pcd->deltaBufs[pcd->curtable], width_in_blocks,
+ height_in_blocks, src_pitch, pcd->table1);
+ break;
}
- codec37_proc5(pcd->deltaBufs[pcd->curtable], cd->src+16,
- pcd->deltaBufs[pcd->curtable^1] - pcd->deltaBufs[pcd->curtable],
- width_in_blocks, height_in_blocks, src_pitch,
- pcd->table1);
- break;
- }
-
case 1:
case 4:
warning("code %d", cd->src[0]);
- return(1);
+ return (1);
default:
error("codec37 default case");
}
- pcd->flags = *(uint16*)(cd->src + 2);
+ pcd->flags = *(uint16 *)(cd->src + 2);
if (result) {
pcd->curtable ^= 1;
} else {
- memcpy(cd->out, pcd->deltaBufs[pcd->curtable], 320*200);
+ memcpy(cd->out, pcd->deltaBufs[pcd->curtable], 320 * 200);
}
- return(_frameChanged);
+ return (_frameChanged);
}
-void codec37_init(PersistentCodecData37 *pcd, int width, int height) {
+void codec37_init(PersistentCodecData37 * pcd, int width, int height)
+{
pcd->width = width;
pcd->height = height;
- pcd->deltaSize = width*height*2+0x3E00+0xBA00;
- pcd->deltaBuf = (byte*)calloc(pcd->deltaSize, 1);
+ pcd->deltaSize = width * height * 2 + 0x3E00 + 0xBA00;
+ pcd->deltaBuf = (byte *)calloc(pcd->deltaSize, 1);
pcd->deltaBufs[0] = pcd->deltaBuf + 0x3E00;
pcd->deltaBufs[1] = pcd->deltaBuf + width * height + 0xBA00;
pcd->curtable = 0;
- pcd->table1 = (int16*)calloc(255,sizeof(uint16));
+ pcd->table1 = (int16 *) calloc(255, sizeof(uint16));
}
-void SmushPlayer::parseFOBJ() {
+void SmushPlayer::parseFOBJ()
+{
byte codec;
CodecData cd;
@@ -458,12 +483,12 @@ void SmushPlayer::parseFOBJ() {
cd.y = 0;
cd.x = 0;
cd.src = _cur + 0xE;
- cd.w = *(uint16*)(_cur + 6);
- cd.h = *(uint16*)(_cur + 8);
-
+ cd.w = *(uint16 *)(_cur + 6);
+ cd.h = *(uint16 *)(_cur + 8);
+
codec = _cur[0];
- switch(codec) {
+ switch (codec) {
case 1:
codec1(&cd);
break;
@@ -475,48 +500,52 @@ void SmushPlayer::parseFOBJ() {
}
}
-void SmushPlayer::parsePSAD() {
+void SmushPlayer::parsePSAD()
+{
//printf("parse PSAD\n");
}
-void SmushPlayer::parseTRES() {
-// printf("parse TRES\n");
+void SmushPlayer::parseTRES()
+{
+// printf("parse TRES\n");
}
-void SmushPlayer::parseXPAL() {
+void SmushPlayer::parseXPAL()
+{
int num;
int i;
- num = *(uint16*)(_cur + 2);
- if (num==0 || num==0x200) {
- if (num==0x200)
+ num = *(uint16 *)(_cur + 2);
+ if (num == 0 || num == 0x200) {
+ if (num == 0x200)
memcpy(_fluPalette, _cur + 0x604, 0x300);
- for(i=0; i<0x300; i++) {
+ for (i = 0; i < 0x300; i++) {
_fluPalMul129[i] = _fluPalette[i] * 129;
- _fluPalWords[i] = *(uint16*)(_cur + 4 + i*2);
+ _fluPalWords[i] = *(uint16 *)(_cur + 4 + i * 2);
}
return;
}
parseNPAL();
- for(i=0; i<0x300; i++) {
+ for (i = 0; i < 0x300; i++) {
_fluPalMul129[i] += _fluPalWords[i];
- _fluPalette[i] = _fluPalMul129[i]>>7;
+ _fluPalette[i] = _fluPalMul129[i] >> 7;
}
_paletteChanged = true;
}
-void SmushPlayer::parseFRME() {
+void SmushPlayer::parseFRME()
+{
_cur = _block;
-
+
do {
_frmeTag = nextBE32();
_frmeSize = nextBE32();
- switch(_frmeTag) {
+ switch (_frmeTag) {
case 'NPAL':
parseNPAL();
break;
@@ -547,63 +576,67 @@ void SmushPlayer::parseFRME() {
} while (_cur + 4 < _block + _blockSize);
}
-void SmushPlayer::init() {
+void SmushPlayer::init()
+{
_renderBitmap = sm->_videoBuffer;
codec37_init(&pcd37, 320, 200);
}
-void SmushPlayer::go() {
- while (parseTag()) {}
+void SmushPlayer::go()
+{
+ while (parseTag()) {
+ }
}
-void SmushPlayer::setPalette() {
+void SmushPlayer::setPalette()
+{
int i;
- for(i=0;i<768;i++)
- sm->_currentPalette[i]=_fluPalette[i];
+ for (i = 0; i < 768; i++)
+ sm->_currentPalette[i] = _fluPalette[i];
}
-void SmushPlayer::startVideo(short int arg, byte* videoFile)
+void SmushPlayer::startVideo(short int arg, byte *videoFile)
{
- int frameIndex=0;
-
- _in=NULL;
- _paletteChanged=0;
- _block=NULL;
- _blockTag=0;
- _blockSize=0;
- _cur=NULL;
- _renderBitmap=NULL;
- _frameSize=0;
- _frmeTag=0;
- _frmeSize=0;
- _deltaBuf=NULL;
- _deltaBufSize=0;
-
- pcd37.deltaBuf=NULL;
- pcd37.deltaBufs[0]=NULL;
- pcd37.deltaBufs[1]=NULL;
- pcd37.deltaSize=0;
- pcd37.width=0;
- pcd37.height=0;
- pcd37.curtable=0;
- pcd37.unk2=0;
- pcd37.unk3=0;
- pcd37.flags=0;
- pcd37.table1=NULL;
- pcd37.table_last_pitch=0;
- pcd37.table_last_flags=0;
+ int frameIndex = 0;
+
+ _in = NULL;
+ _paletteChanged = 0;
+ _block = NULL;
+ _blockTag = 0;
+ _blockSize = 0;
+ _cur = NULL;
+ _renderBitmap = NULL;
+ _frameSize = 0;
+ _frmeTag = 0;
+ _frmeSize = 0;
+ _deltaBuf = NULL;
+ _deltaBufSize = 0;
+
+ pcd37.deltaBuf = NULL;
+ pcd37.deltaBufs[0] = NULL;
+ pcd37.deltaBufs[1] = NULL;
+ pcd37.deltaSize = 0;
+ pcd37.width = 0;
+ pcd37.height = 0;
+ pcd37.curtable = 0;
+ pcd37.unk2 = 0;
+ pcd37.unk3 = 0;
+ pcd37.flags = 0;
+ pcd37.table1 = NULL;
+ pcd37.table_last_pitch = 0;
+ pcd37.table_last_flags = 0;
init();
openFile(videoFile);
- if(_in==NULL)
+ if (_in == NULL)
return;
if (fileReadBE32() != 'ANIM')
error("file is not an anim");
- fileSize=fileReadBE32();
+ fileSize = fileReadBE32();
sm->videoFinished = 0;
sm->_insaneState = 1;
@@ -612,13 +645,13 @@ void SmushPlayer::startVideo(short int arg, byte* videoFile)
do {
_frameChanged = 1;
-
- if(ftell(_in)>=fileSize )
+
+ if (ftell(_in) >= fileSize)
return;
#ifdef INSANE_DEBUG
- warning("Playing frame %d",frameIndex);
+ warning("Playing frame %d", frameIndex);
#endif
-
+
parseTag();
frameIndex++;
@@ -628,24 +661,20 @@ void SmushPlayer::startVideo(short int arg, byte* videoFile)
sm->setDirtyColors(0, 255);
}
- if ( _frameChanged)
- {
- blitToScreen(sm,sm->_videoBuffer, 0, 0, 320 ,200);
+ if (_frameChanged) {
+ blitToScreen(sm, sm->_videoBuffer, 0, 0, 320, 200);
updateScreen(sm);
sm->delta = sm->_system->waitTick(sm->delta);
}
-
+
sm->processKbd();
-
+
} while (!sm->videoFinished);
sm->_insaneState = 0;
-// if (sm->_lastKeyHit==sm->_vars[sm->VAR_CUTSCENEEXIT_KEY])
- sm->exitCutscene();
-
-}
-
-
+// if (sm->_lastKeyHit==sm->_vars[sm->VAR_CUTSCENEEXIT_KEY])
+ sm->exitCutscene();
+}
diff --git a/mp3_cd.cpp b/mp3_cd.cpp
index 9ea2d242a0..a70c1792f1 100755
--- a/mp3_cd.cpp
+++ b/mp3_cd.cpp
@@ -37,124 +37,125 @@ MixerChannel *_mc;
int xing_parse(struct xing *xing, struct mad_bitptr ptr, unsigned int bitlen)
{
- xing->flags = 0;
+ xing->flags = 0;
- if (bitlen < 64 || mad_bit_read(&ptr, 32) != XING_MAGIC)
- goto fail;
+ if (bitlen < 64 || mad_bit_read(&ptr, 32) != XING_MAGIC)
+ goto fail;
- xing->flags = mad_bit_read(&ptr, 32);
- bitlen -= 64;
+ xing->flags = mad_bit_read(&ptr, 32);
+ bitlen -= 64;
- if (xing->flags & XING_FRAMES) {
- if (bitlen < 32)
- goto fail;
+ if (xing->flags & XING_FRAMES) {
+ if (bitlen < 32)
+ goto fail;
- xing->frames = mad_bit_read(&ptr, 32);
- bitlen -= 32;
- }
+ xing->frames = mad_bit_read(&ptr, 32);
+ bitlen -= 32;
+ }
- if (xing->flags & XING_BYTES) {
- if (bitlen < 32)
- goto fail;
+ if (xing->flags & XING_BYTES) {
+ if (bitlen < 32)
+ goto fail;
- xing->bytes = mad_bit_read(&ptr, 32);
- bitlen -= 32;
- }
+ xing->bytes = mad_bit_read(&ptr, 32);
+ bitlen -= 32;
+ }
- if (xing->flags & XING_TOC) {
- int i;
+ if (xing->flags & XING_TOC) {
+ int i;
- if (bitlen < 800)
- goto fail;
+ if (bitlen < 800)
+ goto fail;
- for (i = 0; i < 100; ++i)
- xing->toc[i] = (unsigned char)mad_bit_read(&ptr, 8);
+ for (i = 0; i < 100; ++i)
+ xing->toc[i] = (unsigned char)mad_bit_read(&ptr, 8);
- bitlen -= 800;
- }
+ bitlen -= 800;
+ }
- if (xing->flags & XING_SCALE) {
- if (bitlen < 32)
- goto fail;
+ if (xing->flags & XING_SCALE) {
+ if (bitlen < 32)
+ goto fail;
- xing->scale = mad_bit_read(&ptr, 32);
- bitlen -= 32;
- }
+ xing->scale = mad_bit_read(&ptr, 32);
+ bitlen -= 32;
+ }
- return 0;
+ return 0;
- fail:
- xing->flags = 0;
- return -1;
+fail:
+ xing->flags = 0;
+ return -1;
}
// Borrowed from Winamp plugin in_mad.c
bool parse_xing_vbr_tag()
{
- struct mad_stream stream;
- struct mad_frame frame;
- unsigned char buffer[8192];
- unsigned int buflen = 0;
- int count = 0, result = 0;
-
- _vbr_header.flags = 0;
-
- mad_stream_init(&stream);
- mad_frame_init(&frame);
-
- fseek(_mp3_track, 0, SEEK_SET);
-
- while (1) {
- if (buflen < sizeof(buffer)) {
- uint16 bytes;
-
- bytes = fread(buffer + buflen, 1, sizeof(buffer) - buflen, _mp3_track);
- if (bytes <= 0) {
- if (bytes == -1)
- result = -1;
- break;
- }
-
- buflen += bytes;
- }
-
- mad_stream_buffer(&stream, buffer, buflen);
-
- while (1) {
- if (mad_frame_decode(&frame, &stream) == -1) {
- if (!MAD_RECOVERABLE(stream.error))
- break;
-
- if (stream.error != MAD_ERROR_BADCRC)
- continue;
- }
-
- if (count++ ||
- xing_parse(&_vbr_header, stream.anc_ptr, stream.anc_bitlen)
- == -1)
- break;
- }
-
- if (count || stream.error != MAD_ERROR_BUFLEN)
- break;
-
- memmove(buffer, stream.next_frame,
- buflen = &buffer[buflen] - stream.next_frame);
- }
-
- if (count)
- memcpy(&_mad_header, &frame.header, sizeof(mad_header));
- else
- result = -1;
-
- mad_frame_finish(&frame);
- mad_stream_finish(&stream);
-
- return (result != -1);
+ struct mad_stream stream;
+ struct mad_frame frame;
+ unsigned char buffer[8192];
+ unsigned int buflen = 0;
+ int count = 0, result = 0;
+
+ _vbr_header.flags = 0;
+
+ mad_stream_init(&stream);
+ mad_frame_init(&frame);
+
+ fseek(_mp3_track, 0, SEEK_SET);
+
+ while (1) {
+ if (buflen < sizeof(buffer)) {
+ uint16 bytes;
+
+ bytes = fread(buffer + buflen, 1, sizeof(buffer) - buflen, _mp3_track);
+ if (bytes <= 0) {
+ if (bytes == -1)
+ result = -1;
+ break;
+ }
+
+ buflen += bytes;
+ }
+
+ mad_stream_buffer(&stream, buffer, buflen);
+
+ while (1) {
+ if (mad_frame_decode(&frame, &stream) == -1) {
+ if (!MAD_RECOVERABLE(stream.error))
+ break;
+
+ if (stream.error != MAD_ERROR_BADCRC)
+ continue;
+ }
+
+ if (count++ ||
+ xing_parse(&_vbr_header, stream.anc_ptr, stream.anc_bitlen)
+ == -1)
+ break;
+ }
+
+ if (count || stream.error != MAD_ERROR_BUFLEN)
+ break;
+
+ memmove(buffer, stream.next_frame,
+ buflen = &buffer[buflen] - stream.next_frame);
+ }
+
+ if (count)
+ memcpy(&_mad_header, &frame.header, sizeof(mad_header));
+ else
+ result = -1;
+
+ mad_frame_finish(&frame);
+ mad_stream_finish(&stream);
+
+ return (result != -1);
}
-uint32 calc_cd_file_offset(int start_frame) {
+uint32 calc_cd_file_offset(int start_frame)
+{
long offset;
if (!_vbr_header.flags) {
@@ -163,82 +164,82 @@ uint32 calc_cd_file_offset(int start_frame) {
/* Constant bit rate - perhaps not fully accurate */
frame_size = 144 * _mad_header.bitrate / _mad_header.samplerate;
- offset = (long)((float)start_frame / (float)CD_FPS * 1000 /
- (float)((float)1152 / (float)_mad_header.samplerate * 1000) *
- (float)(frame_size + 0.5));
- }
- else {
- /* DOES NOT WORK AT THE MOMENT */
+ offset = (long)((float)start_frame / (float)CD_FPS * 1000 /
+ (float)((float)1152 / (float)_mad_header.samplerate *
+ 1000) * (float)(frame_size + 0.5));
+ } else {
+ /* DOES NOT WORK AT THE MOMENT */
/* see Xing SDK */
long a;
float fa, fb, fx;
float percent = (float)start_frame / (float)CD_FPS * 1000 /
- ((float)((float)1152 / (float)_mad_header.samplerate * 1000) * _vbr_header.frames) *
- 100;
+ ((float)((float)1152 / (float)_mad_header.samplerate * 1000) *
+ _vbr_header.frames) * 100;
- if( percent < 0.0f ) percent = 0.0f;
- if( percent > 100.0f ) percent = 100.0f;
+ if (percent < 0.0f)
+ percent = 0.0f;
+ if (percent > 100.0f)
+ percent = 100.0f;
a = (int)percent;
- if( a > 99 ) a = 99;
+ if (a > 99)
+ a = 99;
fa = _vbr_header.toc[a];
- if( a < 99 ) {
- fb = _vbr_header.toc[a+1];
- }
- else {
+ if (a < 99) {
+ fb = _vbr_header.toc[a + 1];
+ } else {
fb = 256.0f;
}
- fx = fa + (fb-fa)*(percent-a);
+ fx = fa + (fb - fa) * (percent - a);
- offset = (int)((1.0f/256.0f)*fx*_vbr_header.bytes);
+ offset = (int)((1.0f / 256.0f) * fx * _vbr_header.bytes);
}
return offset;
}
-bool mp3_cd_play(Scumm *s, int track, int num_loops, int start_frame, int end_frame) {
+bool mp3_cd_play(Scumm *s, int track, int num_loops, int start_frame,
+ int end_frame)
+{
// See if we are already playing this track, else try to open it
if (_current_mp3_cd_track != track) {
- char track_name[1024];
+ char track_name[1024];
sprintf(track_name, "%strack%d.mp3", s->_gameDataPath, track);
_mp3_track = fopen(track_name, "rb");
if (!_mp3_track) {
warning("No CD and track %d not available in mp3 format", track);
- return false;
+ return false;
}
if (!parse_xing_vbr_tag()) {
- warning("Error parsing file header - ignoring file",
- track);
- fclose(_mp3_track);
- return false;
+ warning("Error parsing file header - ignoring file", track);
+ fclose(_mp3_track);
+ return false;
}
if (_vbr_header.flags) {
- if (!(
- (_vbr_header.flags & XING_TOC) &&
- (_vbr_header.flags & XING_BYTES) &&
- (_vbr_header.flags & XING_FRAMES)
- )) {
+ if (!((_vbr_header.flags & XING_TOC) &&
+ (_vbr_header.flags & XING_BYTES) &&
+ (_vbr_header.flags & XING_FRAMES)
+ )) {
warning("Missing required part of VBR header - ignoring file");
fclose(_mp3_track);
_vbr_header.flags = 0;
- return false;
+ return false;
}
}
-
// Allocate the music mixer if necessary
if (!_mc) {
_mc = s->allocateMixer();
if (!_mc) {
warning("No mixer channel available for MP3 music");
- return false;
+ return false;
}
}
@@ -248,20 +249,20 @@ bool mp3_cd_play(Scumm *s, int track, int num_loops, int start_frame, int end_fr
_mc->type = MIXER_MP3_CDMUSIC;
_mc->sound_data.mp3_cdmusic.file = _mp3_track;
- _mc->sound_data.mp3_cdmusic.playing = false;
+ _mc->sound_data.mp3_cdmusic.playing = false;
_mc->sound_data.mp3_cdmusic.buffer_size = 200000;
- _mc->_sfx_sound = malloc(_mc->sound_data.mp3_cdmusic.buffer_size);
+ _mc->_sfx_sound = malloc(_mc->sound_data.mp3_cdmusic.buffer_size);
- /* see if it's enough */
+ /* see if it's enough */
mad_stream_init(&_mc->sound_data.mp3.stream);
- if (_mad_header.samplerate == 44100)
- mad_stream_options((mad_stream*)&_mc->sound_data.mp3.stream,
- MAD_OPTION_HALFSAMPLERATE);
+ if (_mad_header.samplerate == 44100)
+ mad_stream_options((mad_stream *) & _mc->sound_data.mp3.stream,
+ MAD_OPTION_HALFSAMPLERATE);
mad_frame_init(&_mc->sound_data.mp3.frame);
mad_synth_init(&_mc->sound_data.mp3.synth);
- _current_mp3_cd_track = track;
+ _current_mp3_cd_track = track;
}
@@ -274,22 +275,19 @@ bool mp3_cd_play(Scumm *s, int track, int num_loops, int start_frame, int end_fr
if (start_frame < 0 || end_frame < 0) {
warning("Negative index in frame");
- return false;
+ return false;
}
mad_timer_set(&_mc->sound_data.mp3_cdmusic.duration,
- 0,
- end_frame,
- CD_FPS);
+ 0, end_frame, CD_FPS);
fseek(_mp3_track, where, SEEK_SET);
- _mc->sound_data.mp3_cdmusic.playing = true;
+ _mc->sound_data.mp3_cdmusic.playing = true;
- return true;
+ return true;
}
- return false;
+ return false;
}
#endif
-
diff --git a/object.cpp b/object.cpp
index 8a3aaa6a25..481cf4e305 100644
--- a/object.cpp
+++ b/object.cpp
@@ -23,92 +23,110 @@
#include "stdafx.h"
#include "scumm.h"
-bool Scumm::getClass(int obj, int cls) {
- checkRange(_numGlobalObjects-1, 0, obj, "Object %d out of range in getClass");
+bool Scumm::getClass(int obj, int cls)
+{
+ checkRange(_numGlobalObjects - 1, 0, obj,
+ "Object %d out of range in getClass");
cls &= 0x7F;
- checkRange(32,1,cls,"Class %d out of range in getClass");
+ checkRange(32, 1, cls, "Class %d out of range in getClass");
if (_features & GF_SMALL_HEADER) {
- if (cls == 32) // CLASS_TOUCHABLE
- cls = 23;
+ if (cls == 32) // CLASS_TOUCHABLE
+ cls = 24;
}
- return (_classData[obj] & (1<<(cls-1))) != 0;
+ return (_classData[obj] & (1 << (cls - 1))) != 0;
}
-void Scumm::putClass(int obj, int cls, bool set) {
- checkRange(_numGlobalObjects-1, 0, obj, "Object %d out of range in putClass");
+void Scumm::putClass(int obj, int cls, bool set)
+{
+ checkRange(_numGlobalObjects - 1, 0, obj,
+ "Object %d out of range in putClass");
cls &= 0x7F;
- checkRange(32,1,cls,"Class %d out of range in getClass");
+ checkRange(32, 1, cls, "Class %d out of range in getClass");
if (_features & GF_SMALL_HEADER) {
- if (cls == 32) // CLASS_TOUCHABLE
- cls = 23;
+ if (cls == 32) // CLASS_TOUCHABLE
+ cls = 24;
}
+
+
if (set)
- _classData[obj] |= (1<<(cls-1));
+ _classData[obj] |= (1 << (cls - 1));
else
- _classData[obj] &= ~(1<<(cls-1));
+ _classData[obj] &= ~(1 << (cls - 1));
}
-int Scumm::getOwner(int obj) {
- checkRange(_numGlobalObjects-1, 0, obj, "Object %d out of range in getOwner");
+int Scumm::getOwner(int obj)
+{
+ checkRange(_numGlobalObjects - 1, 0, obj,
+ "Object %d out of range in getOwner");
return _objectOwnerTable[obj];
}
-void Scumm::putOwner(int act, int owner) {
- checkRange(_numGlobalObjects-1, 0, act, "Object %d out of range in putOwner");
+void Scumm::putOwner(int act, int owner)
+{
+ checkRange(_numGlobalObjects - 1, 0, act,
+ "Object %d out of range in putOwner");
checkRange(0xFF, 0, owner, "Owner %d out of range in putOwner");
_objectOwnerTable[act] = owner;
}
-int Scumm::getState(int act) {
- checkRange(_numGlobalObjects-1, 0, act, "Object %d out of range in getState");
+int Scumm::getState(int act)
+{
+ checkRange(_numGlobalObjects - 1, 0, act,
+ "Object %d out of range in getState");
return _objectStateTable[act];
}
-void Scumm::putState(int act, int state) {
- checkRange(_numGlobalObjects-1, 0, act, "Object %d out of range in putState");
+void Scumm::putState(int act, int state)
+{
+ checkRange(_numGlobalObjects - 1, 0, act,
+ "Object %d out of range in putState");
checkRange(0xFF, 0, state, "State %d out of range in putState");
_objectStateTable[act] = state;
}
-int Scumm::getObjectRoom(int obj) {
- checkRange(_numGlobalObjects-1, 0, obj, "Object %d out of range in getObjectRoom");
+int Scumm::getObjectRoom(int obj)
+{
+ checkRange(_numGlobalObjects - 1, 0, obj,
+ "Object %d out of range in getObjectRoom");
return _objectRoomTable[obj];
}
-int Scumm::getObjectIndex(int object) {
+int Scumm::getObjectIndex(int object)
+{
int i;
/* OF_OWNER_ROOM should be 0xFF for full throttle, else 0xF */
if (_objectOwnerTable[object] != OF_OWNER_ROOM) {
- for (i=0; i<_maxInventoryItems; i++)
+ for (i = 0; i < _maxInventoryItems; i++)
if (_inventory[i] == object)
return i;
return -1;
} else {
- for (i=_numObjectsInRoom; i>0; i--) {
- if (_objs[i].obj_nr==object)
+ for (i = _numObjectsInRoom; i > 0; i--) {
+ if (_objs[i].obj_nr == object)
return i;
}
return -1;
}
}
-int Scumm::whereIsObject(int object) {
+int Scumm::whereIsObject(int object)
+{
int i;
if (object >= _numGlobalObjects)
return WIO_NOT_FOUND;
if (_objectOwnerTable[object] != OF_OWNER_ROOM) {
- for (i=0; i<_maxInventoryItems; i++)
+ for (i = 0; i < _maxInventoryItems; i++)
if (_inventory[i] == object)
return WIO_INVENTORY;
return WIO_NOT_FOUND;
}
- for (i=_numObjectsInRoom; i>0; i--)
+ for (i = _numObjectsInRoom; i > 0; i--)
if (_objs[i].obj_nr == object) {
if (_objs[i].fl_object_index)
return WIO_FLOBJECT;
@@ -117,16 +135,19 @@ int Scumm::whereIsObject(int object) {
return WIO_NOT_FOUND;
}
-int Scumm::getObjectOrActorXY(int object) {
+int Scumm::getObjectOrActorXY(int object)
+{
if (object < NUM_ACTORS)
return getActorXYPos(derefActorSafe(object, "getObjectOrActorXY"));
-
- switch(whereIsObject(object)) {
+
+ switch (whereIsObject(object)) {
case WIO_NOT_FOUND:
return -1;
- case WIO_INVENTORY:
+ case WIO_INVENTORY:
if (_objectOwnerTable[object] < NUM_ACTORS)
- return getActorXYPos(derefActorSafe(_objectOwnerTable[object],"getObjectOrActorXY(2)"));
+ return
+ getActorXYPos(derefActorSafe
+ (_objectOwnerTable[object], "getObjectOrActorXY(2)"));
else
return 0xFF;
}
@@ -137,74 +158,76 @@ int Scumm::getObjectOrActorXY(int object) {
/* Return the position of an object.
Returns X, Y and direction in angles
*/
-void Scumm::getObjectXYPos(int object) {
+void Scumm::getObjectXYPos(int object)
+{
ObjectData *od = &_objs[getObjectIndex(object)];
int state;
byte *ptr;
ImageHeader *imhd;
- int x,y;
-
- if(!(_features & GF_SMALL_HEADER)) {
- if (_features&GF_AFTER_V6) {
- state = getState(object)-1;
- if (state<0)
- state = 0;
-
- if (od->fl_object_index) {
- ptr = getResourceAddress(rtFlObject, od->fl_object_index);
- ptr = findResource(MKID('OBIM'), ptr);
- } else {
- ptr = getResourceAddress(rtRoom, _roomResource);
- ptr += od->offs_obim_to_room;
- }
- assert(ptr);
- imhd = (ImageHeader*)findResourceData(MKID('IMHD'), ptr);
- if( _features & GF_AFTER_V7) {
- x = od->x_pos + (int16)READ_LE_UINT16(&imhd->v7.hotspot[state].x);
- y = od->y_pos + (int16)READ_LE_UINT16(&imhd->v7.hotspot[state].y);
+ int x, y;
+
+ if (!(_features & GF_SMALL_HEADER)) {
+ if (_features & GF_AFTER_V6) {
+ state = getState(object) - 1;
+ if (state < 0)
+ state = 0;
+
+ if (od->fl_object_index) {
+ ptr = getResourceAddress(rtFlObject, od->fl_object_index);
+ ptr = findResource(MKID('OBIM'), ptr);
+ } else {
+ ptr = getResourceAddress(rtRoom, _roomResource);
+ ptr += od->offs_obim_to_room;
+ }
+ assert(ptr);
+ imhd = (ImageHeader *)findResourceData(MKID('IMHD'), ptr);
+ if (_features & GF_AFTER_V7) {
+ x = od->x_pos + (int16) READ_LE_UINT16(&imhd->v7.hotspot[state].x);
+ y = od->y_pos + (int16) READ_LE_UINT16(&imhd->v7.hotspot[state].y);
} else {
- x = od->x_pos + (int16)READ_LE_UINT16(&imhd->old.hotspot[state].x);
- y = od->y_pos + (int16)READ_LE_UINT16(&imhd->old.hotspot[state].y);
+ x = od->x_pos + (int16) READ_LE_UINT16(&imhd->old.hotspot[state].x);
+ y = od->y_pos + (int16) READ_LE_UINT16(&imhd->old.hotspot[state].y);
}
- } else {
- x = od->walk_x;
+ } else {
+ x = od->walk_x;
y = od->walk_y;
- }
+ }
_xPos = x;
_yPos = y;
- _dir = oldDirToNewDir(od->actordir&3);
- } else {
- x = od->walk_x;
+ _dir = oldDirToNewDir(od->actordir & 3);
+ } else {
+ x = od->walk_x;
y = od->walk_y;
- _xPos = x;
- _yPos = y;
- _dir= oldDirToNewDir(od->actordir&3);
-
- }
+ _xPos = x;
+ _yPos = y;
+ _dir = oldDirToNewDir(od->actordir & 3);
+
+ }
}
-int Scumm::getObjActToObjActDist(int a, int b) {
- int x,y;
+int Scumm::getObjActToObjActDist(int a, int b)
+{
+ int x, y;
Actor *acta = NULL;
Actor *actb = NULL;
- if (a<NUM_ACTORS)
+ if (a < NUM_ACTORS)
acta = derefActorSafe(a, "getObjActToObjActDist");
- if (b<NUM_ACTORS)
+ if (b < NUM_ACTORS)
actb = derefActorSafe(b, "getObjActToObjActDist(2)");
- if (acta && actb && acta->room==actb->room && acta->room &&
- acta->room != _currentRoom)
- return 0;
+ if (acta && actb && acta->room == actb->room && acta->room &&
+ acta->room != _currentRoom)
+ return 0;
- if (getObjectOrActorXY(a)==-1)
+ if (getObjectOrActorXY(a) == -1)
return 0xFF;
x = _xPos;
y = _yPos;
- if (getObjectOrActorXY(b)==-1)
+ if (getObjectOrActorXY(b) == -1)
return 0xFF;
if (acta) {
@@ -213,38 +236,40 @@ int Scumm::getObjActToObjActDist(int a, int b) {
_yPos = r.y;
}
- y = abs(y-_yPos);
- x = abs(x-_xPos);
+ y = abs(y - _yPos);
+ x = abs(x - _xPos);
- if (y>x) x=y;
+ if (y > x)
+ x = y;
return x;
}
-int Scumm::findObject(int x, int y) {
- int i,b;
+int Scumm::findObject(int x, int y)
+{
+ int i, b;
byte a;
- for (i=1; i<=_numObjectsInRoom; i++) {
+ for (i = 1; i <= _numObjectsInRoom; i++) {
if (!_objs[i].obj_nr || getClass(_objs[i].obj_nr, 32))
continue;
b = i;
do {
a = _objs[b].parentstate;
b = _objs[b].parent;
- if (b==0) {
+ if (b == 0) {
if (_objs[i].x_pos <= x &&
_objs[i].width + _objs[i].x_pos > x &&
- _objs[i].y_pos <= y &&
- _objs[i].height + _objs[i].y_pos > y)
- return _objs[i].obj_nr;
+ _objs[i].y_pos <= y && _objs[i].height + _objs[i].y_pos > y)
+ return _objs[i].obj_nr;
break;
}
- } while ( _objs[b].state == a);
+ } while (_objs[b].state == a);
}
return 0;
}
-void Scumm::drawRoomObject(int i, int arg) {
+void Scumm::drawRoomObject(int i, int arg)
+{
ObjectData *od;
byte a;
@@ -259,18 +284,19 @@ void Scumm::drawRoomObject(int i, int arg) {
break;
}
od = &_objs[od->parent];
- } while (od->state==a);
+ } while (od->state == a);
}
-void Scumm::drawRoomObjects(int arg) {
+void Scumm::drawRoomObjects(int arg)
+{
int i;
if (_features & GF_DRAWOBJ_OTHER_ORDER) {
- for(i=1; i<=_numObjectsInRoom; i++)
- drawRoomObject(i,arg);
+ for (i = 1; i <= _numObjectsInRoom; i++)
+ drawRoomObject(i, arg);
} else {
- for(i=_numObjectsInRoom; i!=0; i--)
- drawRoomObject(i,arg);
+ for (i = _numObjectsInRoom; i != 0; i--)
+ drawRoomObject(i, arg);
}
}
@@ -293,50 +319,52 @@ const uint32 IMxx_tags[] = {
MKID('IM0F')
};
-void Scumm::drawObject(int obj, int arg) {
+void Scumm::drawObject(int obj, int arg)
+{
ObjectData *od;
int xpos, ypos, height, width;
byte *ptr;
- int x,a,numstrip;
+ int x, a, numstrip;
int tmp;
if (_BgNeedsRedraw)
arg = 0;
_curVirtScreen = &virtscr[0];
-
+
od = &_objs[obj];
- xpos = od->x_pos>>3;
+ xpos = od->x_pos >> 3;
ypos = od->y_pos;
- width = od->width>>3;
- height = od->height &= 0xF8; // Ender
+ width = od->width >> 3;
+ height = od->height &= 0xF8; // Ender
- if (width==0 || xpos > _screenEndStrip || xpos + width < _screenStartStrip)
+ if (width == 0 || xpos > _screenEndStrip
+ || xpos + width < _screenStartStrip)
return;
-
+
if (od->fl_object_index) {
ptr = getResourceAddress(rtFlObject, od->fl_object_index);
- ptr = findResource(MKID('OBIM'), ptr);
+ ptr = findResource(MKID('OBIM'), ptr);
} else {
ptr = getResourceAddress(rtRoom, _roomResource);
ptr = ptr + od->offs_obim_to_room;
}
- if(_features & GF_SMALL_HEADER)
- ptr +=8;
- else
- ptr = findResource(IMxx_tags[getState(od->obj_nr)], ptr);
+ if (_features & GF_SMALL_HEADER)
+ ptr += 8;
+ else
+ ptr = findResource(IMxx_tags[getState(od->obj_nr)], ptr);
if (!ptr)
return;
x = 0xFFFF;
- for (a=numstrip=0; a<width; a++) {
+ for (a = numstrip = 0; a < width; a++) {
tmp = xpos + a;
- if (arg==1 && _screenStartStrip!=tmp)
+ if (arg == 1 && _screenStartStrip != tmp)
continue;
- if (arg==2 && _screenEndStrip!=tmp)
+ if (arg == 2 && _screenEndStrip != tmp)
continue;
if (tmp < _screenStartStrip || tmp > _screenEndStrip)
continue;
@@ -346,62 +374,61 @@ void Scumm::drawObject(int obj, int arg) {
numstrip++;
}
- if (numstrip!=0) {
+ if (numstrip != 0) {
byte flags = Gdi::dbAllowMaskOr;
- if (_features&GF_AFTER_V7 && getClass(od->obj_nr, 22))
+ if (_features & GF_AFTER_V7 && getClass(od->obj_nr, 22))
flags |= Gdi::dbDrawMaskOnBoth;
- gdi.drawBitmap(ptr, _curVirtScreen, x, ypos, height, x-xpos, numstrip, flags);
+ gdi.drawBitmap(ptr, _curVirtScreen, x, ypos, height, x - xpos, numstrip,
+ flags);
}
}
-void Scumm::loadRoomObjects() {
- int i,j;
+void Scumm::loadRoomObjects()
+{
+ int i, j;
ObjectData *od;
byte *ptr;
uint16 obim_id;
- byte *room,*searchptr;
+ byte *room, *searchptr;
ImageHeader *imhd;
RoomHeader *roomhdr;
- CodeHeader *cdhd;
+ CodeHeader *cdhd;
- CHECK_HEAP
-
- room = getResourceAddress(rtRoom, _roomResource);
- roomhdr = (RoomHeader*)findResourceData(MKID('RMHD'), room);
+ CHECK_HEAP room = getResourceAddress(rtRoom, _roomResource);
+ roomhdr = (RoomHeader *)findResourceData(MKID('RMHD'), room);
- if(_features & GF_AFTER_V7)
+ if (_features & GF_AFTER_V7)
_numObjectsInRoom = READ_LE_UINT16(&(roomhdr->v7.numObjects));
else
_numObjectsInRoom = READ_LE_UINT16(&(roomhdr->old.numObjects));
-
+
if (_numObjectsInRoom == 0)
return;
-
+
if (_numObjectsInRoom > _numLocalObjects)
error("More than %d objects in room %d", _numLocalObjects, _roomResource);
od = &_objs[1];
searchptr = room;
- for (i=0; i<_numObjectsInRoom; i++,od++) {
+ for (i = 0; i < _numObjectsInRoom; i++, od++) {
ptr = findResource(MKID('OBCD'), searchptr);
- if (ptr==NULL)
+ if (ptr == NULL)
error("Room %d missing object code block(s)", _roomResource);
od->offs_obcd_to_room = ptr - room;
- cdhd = (CodeHeader*)findResourceData(MKID('CDHD'), ptr);
+ cdhd = (CodeHeader *)findResourceData(MKID('CDHD'), ptr);
- if(_features & GF_AFTER_V7)
+ if (_features & GF_AFTER_V7)
od->obj_nr = READ_LE_UINT16(&(cdhd->v7.obj_id));
+ else if (_features & GF_AFTER_V6)
+ od->obj_nr = READ_LE_UINT16(&(cdhd->v6.obj_id));
else
- if(_features & GF_AFTER_V6)
- od->obj_nr = READ_LE_UINT16(&(cdhd->v6.obj_id));
- else
- od->obj_nr = READ_LE_UINT16(&(cdhd->v5.obj_id));
+ od->obj_nr = READ_LE_UINT16(&(cdhd->v5.obj_id));
#ifdef DUMP_SCRIPTS
do {
char buf[32];
- sprintf(buf,"roomobj-%d-",_roomResource);
+ sprintf(buf, "roomobj-%d-", _roomResource);
dumpResource(buf, od->obj_nr, ptr);
} while (0);
#endif
@@ -409,161 +436,160 @@ void Scumm::loadRoomObjects() {
}
searchptr = room;
- for (i=0; i<_numObjectsInRoom; i++) {
+ for (i = 0; i < _numObjectsInRoom; i++) {
ptr = findResource(MKID('OBIM'), searchptr);
- if (ptr==NULL)
+ if (ptr == NULL)
error("Room %d missing image blocks(s)", _roomResource);
- imhd = (ImageHeader*)findResourceData(MKID('IMHD'), ptr);
+ imhd = (ImageHeader *)findResourceData(MKID('IMHD'), ptr);
if (_features & GF_AFTER_V7)
obim_id = READ_LE_UINT16(&imhd->v7.obj_id);
else
obim_id = READ_LE_UINT16(&imhd->old.obj_id);
- for(j=1; j<=_numObjectsInRoom; j++) {
- if (_objs[j].obj_nr==obim_id)
+ for (j = 1; j <= _numObjectsInRoom; j++) {
+ if (_objs[j].obj_nr == obim_id)
_objs[j].offs_obim_to_room = ptr - room;
}
searchptr = NULL;
}
od = &_objs[1];
- for (i=1; i<=_numObjectsInRoom; i++,od++) {
+ for (i = 1; i <= _numObjectsInRoom; i++, od++) {
setupRoomObject(od, room);
}
- CHECK_HEAP
-}
+CHECK_HEAP}
-void Scumm::loadRoomObjectsSmall() {
- int i,j;
- ObjectData *od;
- byte *ptr;
- uint16 obim_id;
- byte *room,*searchptr;
- RoomHeader *roomhdr;
-
- CHECK_HEAP
-
- room = getResourceAddress(rtRoom, _roomResource);
- roomhdr = (RoomHeader*)findResourceData(MKID('RMHD'), room);
-
- _numObjectsInRoom = READ_LE_UINT16(&(roomhdr->old.numObjects));
-
- if (_numObjectsInRoom == 0)
- return;
-
- if (_numObjectsInRoom > _numLocalObjects)
- error("More than %d objects in room %d", _numLocalObjects, _roomResource);
-
- od = &_objs[1];
- searchptr = room;
- for (i=0; i<_numObjectsInRoom; i++,od++) {
- ptr = findResourceSmall(MKID('OBCD'), searchptr);
- if (ptr==NULL)
- error("Room %d missing object code block(s)", _roomResource);
-
- od->offs_obcd_to_room = ptr - room;
- od->obj_nr = READ_LE_UINT16(ptr+6);
+void Scumm::loadRoomObjectsSmall()
+{
+ int i, j;
+ ObjectData *od;
+ byte *ptr;
+ uint16 obim_id;
+ byte *room, *searchptr;
+ RoomHeader *roomhdr;
+
+ CHECK_HEAP room = getResourceAddress(rtRoom, _roomResource);
+ roomhdr = (RoomHeader *)findResourceData(MKID('RMHD'), room);
+
+ _numObjectsInRoom = READ_LE_UINT16(&(roomhdr->old.numObjects));
+
+ if (_numObjectsInRoom == 0)
+ return;
+
+ if (_numObjectsInRoom > _numLocalObjects)
+ error("More than %d objects in room %d", _numLocalObjects, _roomResource);
+
+ od = &_objs[1];
+ searchptr = room;
+ for (i = 0; i < _numObjectsInRoom; i++, od++) {
+ ptr = findResourceSmall(MKID('OBCD'), searchptr);
+ if (ptr == NULL)
+ error("Room %d missing object code block(s)", _roomResource);
+
+ od->offs_obcd_to_room = ptr - room;
+ od->obj_nr = READ_LE_UINT16(ptr + 6);
#ifdef DUMP_SCRIPTS
- do {
- char buf[32];
- sprintf(buf,"roomobj-%d-",_roomResource);
- dumpResource(buf, od->obj_nr, ptr);
- } while (0);
+ do {
+ char buf[32];
+ sprintf(buf, "roomobj-%d-", _roomResource);
+ dumpResource(buf, od->obj_nr, ptr);
+ } while (0);
#endif
- searchptr = NULL;
- }
-
- searchptr = room;
- for (i=0; i<_numObjectsInRoom; i++) {
- ptr = findResourceSmall(MKID('OBIM'), searchptr);
- if (ptr==NULL)
- error("Room %d missing image blocks(s)", _roomResource);
-
- obim_id = READ_LE_UINT16(ptr+6);
-
- for(j=1; j<=_numObjectsInRoom; j++) {
- if (_objs[j].obj_nr==obim_id)
- _objs[j].offs_obim_to_room = ptr - room;
- }
- searchptr = NULL;
- }
-
- od = &_objs[1];
- for (i=1; i<=_numObjectsInRoom; i++,od++) {
- setupRoomObject(od, room);
- }
-
- CHECK_HEAP
-}
+ searchptr = NULL;
+ }
-void Scumm::setupRoomObject(ObjectData *od, byte *room) {
- CodeHeader *cdhd;
- ImageHeader *imhd;
+ searchptr = room;
+ for (i = 0; i < _numObjectsInRoom; i++) {
+ ptr = findResourceSmall(MKID('OBIM'), searchptr);
+ if (ptr == NULL)
+ error("Room %d missing image blocks(s)", _roomResource);
+
+ obim_id = READ_LE_UINT16(ptr + 6);
+
+ for (j = 1; j <= _numObjectsInRoom; j++) {
+ if (_objs[j].obj_nr == obim_id)
+ _objs[j].offs_obim_to_room = ptr - room;
+ }
+ searchptr = NULL;
+ }
+
+ od = &_objs[1];
+ for (i = 1; i <= _numObjectsInRoom; i++, od++) {
+ setupRoomObject(od, room);
+ }
+
+CHECK_HEAP}
+
+void Scumm::setupRoomObject(ObjectData *od, byte *room)
+{
+ CodeHeader *cdhd;
+ ImageHeader *imhd;
+
+ if (_features & GF_SMALL_HEADER) {
- if(_features & GF_SMALL_HEADER) {
-
byte *ptr = room + od->offs_obcd_to_room;
-
- od->obj_nr = READ_LE_UINT16(ptr+6); // ok
-
- od->width = *(ptr+11)<<3; // ok
- od->x_pos = *(ptr+9)<<3; // ok
-
- if(*(ptr+10) & 0x80) {
- od->parentstate = 1; // it's 0x10 in the original code
+
+ od->obj_nr = READ_LE_UINT16(ptr + 6); // ok
+
+ od->width = *(ptr + 11) << 3; // ok
+ od->x_pos = *(ptr + 9) << 3; // ok
+
+ if (*(ptr + 10) & 0x80) {
+ od->parentstate = 1; // it's 0x10 in the original code
} else {
od->parentstate = 0;
}
- od->y_pos = ((*(ptr+10))&0x7F)<<3;
-
- od->parent = *(ptr+12);
- od->walk_x = READ_LE_UINT16(ptr+13);
-
- od->walk_y = READ_LE_UINT16(ptr+15);
-
- od->actordir = (*(ptr+17))&7;
- od->height = *(ptr+17); // ok
-
-
-
- return;
- }
-
- cdhd = (CodeHeader*)findResourceData(MKID('CDHD'), room + od->offs_obcd_to_room);
- if(_features & GF_AFTER_V7)
+ od->y_pos = ((*(ptr + 10)) & 0x7F) << 3;
+
+ od->parent = *(ptr + 12);
+ od->walk_x = READ_LE_UINT16(ptr + 13);
+
+ od->walk_y = READ_LE_UINT16(ptr + 15);
+
+ od->actordir = (*(ptr + 17)) & 7;
+ od->height = *(ptr + 17); // ok
+
+
+
+ return;
+ }
+
+ cdhd =
+ (CodeHeader *)findResourceData(MKID('CDHD'),
+ room + od->offs_obcd_to_room);
+ if (_features & GF_AFTER_V7)
od->obj_nr = READ_LE_UINT16(&(cdhd->v7.obj_id));
+ else if (_features & GF_AFTER_V6)
+ od->obj_nr = READ_LE_UINT16(&(cdhd->v6.obj_id));
else
- if(_features & GF_AFTER_V6)
- od->obj_nr = READ_LE_UINT16(&(cdhd->v6.obj_id));
- else
- od->obj_nr = READ_LE_UINT16(&(cdhd->v5.obj_id));
-
- if(!(_features & GF_AFTER_V7)) {
+ od->obj_nr = READ_LE_UINT16(&(cdhd->v5.obj_id));
+
+ if (!(_features & GF_AFTER_V7)) {
if (_features & GF_AFTER_V6) {
od->width = READ_LE_UINT16(&cdhd->v6.w);
od->height = READ_LE_UINT16(&cdhd->v6.h);
- od->x_pos = ((int16)READ_LE_UINT16(&cdhd->v6.x));
- od->y_pos = ((int16)READ_LE_UINT16(&cdhd->v6.y));
+ od->x_pos = ((int16) READ_LE_UINT16(&cdhd->v6.x));
+ od->y_pos = ((int16) READ_LE_UINT16(&cdhd->v6.y));
if (cdhd->v6.flags == 0x80) {
od->parentstate = 1;
} else {
- od->parentstate = (cdhd->v6.flags&0xF);
+ od->parentstate = (cdhd->v6.flags & 0xF);
}
od->parent = cdhd->v6.parent;
od->actordir = cdhd->v6.actordir;
} else {
- od->width = cdhd->v5.w<<3;
- od->height = cdhd->v5.h<<3;
- od->x_pos = cdhd->v5.x<<3;
- od->y_pos = cdhd->v5.y<<3;
+ od->width = cdhd->v5.w << 3;
+ od->height = cdhd->v5.h << 3;
+ od->x_pos = cdhd->v5.x << 3;
+ od->y_pos = cdhd->v5.y << 3;
if (cdhd->v5.flags == 0x80) {
od->parentstate = 1;
} else {
- od->parentstate = (cdhd->v5.flags&0xF);
+ od->parentstate = (cdhd->v5.flags & 0xF);
}
od->parent = cdhd->v5.parent;
od->walk_x = READ_LE_UINT16(&cdhd->v5.walk_x);
@@ -574,10 +600,12 @@ void Scumm::setupRoomObject(ObjectData *od, byte *room) {
od->parent = cdhd->v7.parent;
od->parentstate = cdhd->v7.parentstate;
- imhd = (ImageHeader*)findResourceData(MKID('IMHD'), room + od->offs_obim_to_room);
+ imhd =
+ (ImageHeader *)findResourceData(MKID('IMHD'),
+ room + od->offs_obim_to_room);
od->x_pos = READ_LE_UINT16(&imhd->v7.x_pos);
od->y_pos = READ_LE_UINT16(&imhd->v7.y_pos);
- od->width = READ_LE_UINT16(&imhd->v7.width);
+ od->width = READ_LE_UINT16(&imhd->v7.width);
od->height = READ_LE_UINT16(&imhd->v7.height);
od->actordir = READ_LE_UINT16(&imhd->v7.actordir);
@@ -585,57 +613,60 @@ void Scumm::setupRoomObject(ObjectData *od, byte *room) {
od->fl_object_index = 0;
}
-void Scumm::fixObjectFlags() {
+void Scumm::fixObjectFlags()
+{
int i;
ObjectData *od = &_objs[1];
- for (i=1; i<=_numObjectsInRoom; i++,od++) {
+ for (i = 1; i <= _numObjectsInRoom; i++, od++) {
od->state = _objectStateTable[od->obj_nr];
}
}
-void Scumm::processDrawQue() {
+void Scumm::processDrawQue()
+{
int i, j;
- for (i=0; i<_drawObjectQueNr; i++) {
+ for (i = 0; i < _drawObjectQueNr; i++) {
j = _drawObjectQue[i];
if (j)
- drawObject(j,0);
+ drawObject(j, 0);
}
_drawObjectQueNr = 0;
}
-void Scumm::clearOwnerOf(int obj) {
- int i,j;
- uint16 *a;
+void Scumm::clearOwnerOf(int obj)
+{
+ int i, j;
+ uint16 *a;
stopObjectScript(obj);
-
- if (getOwner(obj)==OF_OWNER_ROOM) {
+
+ if (getOwner(obj) == OF_OWNER_ROOM) {
i = 0;
do {
- if (_objs[i].obj_nr==obj) {
+ if (_objs[i].obj_nr == obj) {
if (!_objs[i].fl_object_index)
return;
nukeResource(rtFlObject, _objs[i].fl_object_index);
_objs[i].obj_nr = 0;
_objs[i].fl_object_index = 0;
}
- } while(++i <= _numObjectsInRoom);
+ } while (++i <= _numObjectsInRoom);
return;
}
- for (i=1; i<_maxInventoryItems; i++) {
+ for (i = 1; i < _maxInventoryItems; i++) {
if (_inventory[i] == obj) {
j = whereIsObject(obj);
- if (j==WIO_INVENTORY) {
+ if (j == WIO_INVENTORY) {
nukeResource(rtInventory, i);
_inventory[i] = 0;
}
a = &_inventory[1];
- for (i=1; i < _maxInventoryItems-1; i++,a++) {
+ for (i = 1; i < _maxInventoryItems - 1; i++, a++) {
if (!a[0] && a[1]) {
a[0] = a[1];
a[1] = 0;
- _baseInventoryItems[i] = _baseInventoryItems[i+1];
- _baseInventoryItems[i+1] = NULL;
+ _baseInventoryItems[i] = _baseInventoryItems[i + 1];
+ _baseInventoryItems[i + 1] = NULL;
}
}
return;
@@ -643,15 +674,16 @@ void Scumm::clearOwnerOf(int obj) {
}
}
-void Scumm::removeObjectFromRoom(int obj) {
- int i,cnt;
+void Scumm::removeObjectFromRoom(int obj)
+{
+ int i, cnt;
uint32 *ptr;
-
- for(i=1; i<=_numObjectsInRoom; i++) {
- if (_objs[i].obj_nr==(uint16)obj) {
+
+ for (i = 1; i <= _numObjectsInRoom; i++) {
+ if (_objs[i].obj_nr == (uint16)obj) {
if (_objs[i].width != 0) {
- ptr = &gfxUsageBits[_objs[i].x_pos>>3];
- cnt = _objs[i].width>>3;
+ ptr = &gfxUsageBits[_objs[i].x_pos >> 3];
+ cnt = _objs[i].width >> 3;
do {
*ptr++ |= 0x80000000;
} while (--cnt);
@@ -662,46 +694,51 @@ void Scumm::removeObjectFromRoom(int obj) {
}
}
-void Scumm::addObjectToDrawQue(int object) {
+void Scumm::addObjectToDrawQue(int object)
+{
_drawObjectQue[_drawObjectQueNr++] = object;
- if ((unsigned int)_drawObjectQueNr > sizeof(_drawObjectQue)/sizeof(_drawObjectQue[0]))
+ if ((unsigned int)_drawObjectQueNr >
+ sizeof(_drawObjectQue) / sizeof(_drawObjectQue[0]))
error("Draw Object Que overflow");
}
-void Scumm::clearDrawObjectQueue() {
+void Scumm::clearDrawObjectQueue()
+{
_drawObjectQueNr = 0;
}
-byte *Scumm::getObjOrActorName(int obj) {
+byte *Scumm::getObjOrActorName(int obj)
+{
byte *objptr;
if (obj < NUM_ACTORS)
return getActorName(derefActorSafe(obj, "getObjOrActorName"));
- if(_features & GF_SMALL_HEADER) {
- byte offset=0;
+ if (_features & GF_SMALL_HEADER) {
+ byte offset = 0;
objptr = getOBCDFromObject(obj);
if (objptr)
- offset = *(objptr+18);
- return(objptr+offset);
- }
+ offset = *(objptr + 18);
+ return (objptr + offset);
+ }
objptr = getOBCDFromObject(obj);
- if (objptr==NULL)
- return (byte*)" ";
-
+ if (objptr == NULL)
+ return (byte *)" ";
+
return findResourceData(MKID('OBNA'), objptr);
}
-uint32 Scumm::getOBCDOffs(int object) {
+uint32 Scumm::getOBCDOffs(int object)
+{
int i;
if (_objectOwnerTable[object] != OF_OWNER_ROOM)
return 0;
- for (i=_numObjectsInRoom; i>0; i--) {
+ for (i = _numObjectsInRoom; i > 0; i--) {
if (_objs[i].obj_nr == object) {
- if (_objs[i].fl_object_index!=0)
+ if (_objs[i].fl_object_index != 0)
return 8;
return _objs[i].offs_obcd_to_room;
}
@@ -709,40 +746,41 @@ uint32 Scumm::getOBCDOffs(int object) {
return 0;
}
-byte *Scumm::getOBCDFromObject(int obj) {
+byte *Scumm::getOBCDFromObject(int obj)
+{
int i;
if (_objectOwnerTable[obj] != OF_OWNER_ROOM) {
- for(i=0; i<_maxInventoryItems; i++) {
+ for (i = 0; i < _maxInventoryItems; i++) {
if (_inventory[i] == obj)
return getResourceAddress(rtInventory, i);
}
} else {
- for(i=_numObjectsInRoom; i>0; --i) {
- if (_objs[i].obj_nr==obj) {
+ for (i = _numObjectsInRoom; i > 0; --i) {
+ if (_objs[i].obj_nr == obj) {
if (_objs[i].fl_object_index)
- return getResourceAddress(rtFlObject, _objs[i].fl_object_index)+8;
- return getResourceAddress(rtRoom, _roomResource) + _objs[i].offs_obcd_to_room;
+ return getResourceAddress(rtFlObject, _objs[i].fl_object_index) + 8;
+ return getResourceAddress(rtRoom,
+ _roomResource) + _objs[i].offs_obcd_to_room;
}
}
}
return 0;
}
-void Scumm::addObjectToInventory(uint obj, uint room) {
+void Scumm::addObjectToInventory(uint obj, uint room)
+{
int i, slot;
uint32 size;
- byte *obcdptr,*ptr;
+ byte *obcdptr, *ptr;
FindObjectInRoom foir;
- debug(1,"Adding object %d from room %d into inventory", obj, room);
+ debug(1, "Adding object %d from room %d into inventory", obj, room);
- CHECK_HEAP
-
- if (whereIsObject(obj)==WIO_FLOBJECT) {
+ CHECK_HEAP if (whereIsObject(obj) == WIO_FLOBJECT) {
i = getObjectIndex(obj);
ptr = getResourceAddress(rtFlObject, _objs[i].fl_object_index) + 8;
- size = READ_BE_UINT32_UNALIGNED(ptr+4);
+ size = READ_BE_UINT32_UNALIGNED(ptr + 4);
slot = getInventorySlot();
_inventory[slot] = obj;
createResource(rtInventory, slot, size);
@@ -750,86 +788,88 @@ void Scumm::addObjectToInventory(uint obj, uint room) {
memcpy(getResourceAddress(rtInventory, slot), ptr, size);
} else {
findObjectInRoom(&foir, foCodeHeader, obj, room);
- if(_features & GF_SMALL_HEADER )
- size = READ_LE_UINT32(foir.obcd);
- else
- size = READ_BE_UINT32_UNALIGNED(foir.obcd+4);
+ if (_features & GF_SMALL_HEADER)
+ size = READ_LE_UINT32(foir.obcd);
+ else
+ size = READ_BE_UINT32_UNALIGNED(foir.obcd + 4);
slot = getInventorySlot();
_inventory[slot] = obj;
createResource(rtInventory, slot, size);
obcdptr = getResourceAddress(rtRoom, room) - foir.roomptr + foir.obcd;
- memcpy(getResourceAddress(rtInventory,slot),obcdptr,size);
+ memcpy(getResourceAddress(rtInventory, slot), obcdptr, size);
}
- CHECK_HEAP
-}
+CHECK_HEAP}
-void Scumm::findObjectInRoom(FindObjectInRoom *fo, byte findWhat, uint id, uint room) {
+void Scumm::findObjectInRoom(FindObjectInRoom * fo, byte findWhat, uint id,
+ uint room)
+{
CodeHeader *cdhd;
int i, numobj;
- byte *roomptr,*obcdptr,*obimptr,*searchptr;
+ byte *roomptr, *obcdptr, *obimptr, *searchptr;
RoomHeader *roomhdr;
ImageHeader *imhd;
int id2;
int id3;
-
- if (findWhat&foCheckAlreadyLoaded && getObjectIndex(id) != -1) {
+
+ if (findWhat & foCheckAlreadyLoaded && getObjectIndex(id) != -1) {
fo->obcd = obcdptr = getOBCDFromObject(id);
- assert((byte*)obcdptr > (byte*)256);
- fo->obim = obimptr = obcdptr + READ_BE_UINT32_UNALIGNED(&((ResHdr*)obcdptr)->size);
- fo->cdhd = (CodeHeader*)findResourceData(MKID('CDHD'), obcdptr);
- fo->imhd = (ImageHeader*)findResourceData(MKID('IMHD'), obimptr);
+ assert((byte *)obcdptr > (byte *)256);
+ fo->obim = obimptr =
+ obcdptr + READ_BE_UINT32_UNALIGNED(&((ResHdr *)obcdptr)->size);
+ fo->cdhd = (CodeHeader *)findResourceData(MKID('CDHD'), obcdptr);
+ fo->imhd = (ImageHeader *)findResourceData(MKID('IMHD'), obimptr);
return;
}
fo->roomptr = roomptr = getResourceAddress(rtRoom, room);
- if (!roomptr) { // FIXME: ZAK256 AIRPORT WORKAROUND (buying book from devotee)
+ if (!roomptr) { // FIXME: ZAK256 AIRPORT WORKAROUND (buying book from devotee)
warning("findObjectInRoom: failed getting roomptr to %d", room);
return;
}
- roomhdr = (RoomHeader*)findResourceData(MKID('RMHD'), roomptr);
-
- if(_features & GF_AFTER_V7)
+ roomhdr = (RoomHeader *)findResourceData(MKID('RMHD'), roomptr);
+
+ if (_features & GF_AFTER_V7)
numobj = READ_LE_UINT16(&(roomhdr->v7.numObjects));
else
numobj = READ_LE_UINT16(&(roomhdr->old.numObjects));
-
- if (numobj==0)
+
+ if (numobj == 0)
error("findObjectInRoom: No object found in room %d", room);
if (numobj > _numLocalObjects)
- error("findObjectInRoom: More (%d) than %d objects in room %d", numobj, _numLocalObjects, room);
+ error("findObjectInRoom: More (%d) than %d objects in room %d", numobj,
+ _numLocalObjects, room);
if (findWhat & foCodeHeader) {
searchptr = roomptr;
- for (i=0;;) {
- if(_features & GF_SMALL_HEADER)
- obcdptr = findResourceSmall(MKID('OBCD'), searchptr);
- else
- obcdptr = findResource(MKID('OBCD'), searchptr);
- if(obcdptr==NULL)
+ for (i = 0;;) {
+ if (_features & GF_SMALL_HEADER)
+ obcdptr = findResourceSmall(MKID('OBCD'), searchptr);
+ else
+ obcdptr = findResource(MKID('OBCD'), searchptr);
+ if (obcdptr == NULL)
error("findObjectInRoom: Not enough code blocks in room %d", room);
- if ( _features & GF_SMALL_HEADER) {
- if ( READ_LE_UINT16(obcdptr+6) == (uint16)id) {
- fo->cdhd = NULL;
- fo->obcd = obcdptr;
- break;
- }
- } else {
- cdhd = (CodeHeader*)findResourceData(MKID('CDHD'), obcdptr);
- if ( _features & GF_AFTER_V7)
+ if (_features & GF_SMALL_HEADER) {
+ if (READ_LE_UINT16(obcdptr + 6) == (uint16)id) {
+ fo->cdhd = NULL;
+ fo->obcd = obcdptr;
+ break;
+ }
+ } else {
+ cdhd = (CodeHeader *)findResourceData(MKID('CDHD'), obcdptr);
+ if (_features & GF_AFTER_V7)
id2 = READ_LE_UINT16(&(cdhd->v7.obj_id));
+ else if (_features & GF_AFTER_V6)
+ id2 = READ_LE_UINT16(&(cdhd->v6.obj_id));
else
- if( _features & GF_AFTER_V6)
- id2 = READ_LE_UINT16(&(cdhd->v6.obj_id));
- else
- id2 = READ_LE_UINT16(&(cdhd->v5.obj_id));
-
- if ( id2 == (uint16)id) {
- fo->cdhd = cdhd;
- fo->obcd = obcdptr;
- break;
- }
- }
+ id2 = READ_LE_UINT16(&(cdhd->v5.obj_id));
+
+ if (id2 == (uint16)id) {
+ fo->cdhd = cdhd;
+ fo->obcd = obcdptr;
+ break;
+ }
+ }
if (++i == numobj)
error("findObjectInRoom: Object %d not found in room %d", id, room);
searchptr = NULL;
@@ -838,68 +878,73 @@ void Scumm::findObjectInRoom(FindObjectInRoom *fo, byte findWhat, uint id, uint
if (findWhat & foImageHeader) {
searchptr = roomptr;
- for(i=0;;) {
- if(_features & GF_SMALL_HEADER)
- obimptr = findResourceSmall(MKID('OBIM'), searchptr);
- else
- obimptr = findResource(MKID('OBIM'), searchptr);
- if (obimptr==NULL)
+ for (i = 0;;) {
+ if (_features & GF_SMALL_HEADER)
+ obimptr = findResourceSmall(MKID('OBIM'), searchptr);
+ else
+ obimptr = findResource(MKID('OBIM'), searchptr);
+ if (obimptr == NULL)
error("findObjectInRoom: Not enough image blocks in room %d", room);
- imhd = (ImageHeader*)findResourceData(MKID('IMHD'), obimptr);
- if(_features & GF_SMALL_HEADER){
- if (READ_LE_UINT16(obimptr+6) == (uint16)id) {
- fo->obim = obimptr;
- fo->imhd = imhd;
- break;
- }
- } else {
- if(_features & GF_AFTER_V7)
+ imhd = (ImageHeader *)findResourceData(MKID('IMHD'), obimptr);
+ if (_features & GF_SMALL_HEADER) {
+ if (READ_LE_UINT16(obimptr + 6) == (uint16)id) {
+ fo->obim = obimptr;
+ fo->imhd = imhd;
+ break;
+ }
+ } else {
+ if (_features & GF_AFTER_V7)
id3 = READ_LE_UINT16(&imhd->v7.obj_id);
else
id3 = READ_LE_UINT16(&imhd->old.obj_id);
- if (id3 == (uint16)id) {
- fo->obim = obimptr;
- fo->imhd = imhd;
- break;
- }
- }
- if (++i==numobj)
- error("findObjectInRoom: Object %d image not found in room %d", id, room);
+ if (id3 == (uint16)id) {
+ fo->obim = obimptr;
+ fo->imhd = imhd;
+ break;
+ }
+ }
+ if (++i == numobj)
+ error("findObjectInRoom: Object %d image not found in room %d", id,
+ room);
searchptr = NULL;
}
}
}
-int Scumm::getInventorySlot() {
+int Scumm::getInventorySlot()
+{
int i;
- for (i=1; i<=_maxInventoryItems; i++) {
- if (_inventory[i]==0)
+ for (i = 1; i <= _maxInventoryItems; i++) {
+ if (_inventory[i] == 0)
return i;
}
error("Inventory full, %d max items", _maxInventoryItems);
}
-void Scumm::SamInventoryHack(int obj) { // FIXME: Sam and Max hack
+void Scumm::SamInventoryHack(int obj)
+{ // FIXME: Sam and Max hack
int base = 6;
while (base < 80) {
int value = readArray(178, 0, base);
- if (value == obj) return;
+ if (value == obj)
+ return;
if (value == 0) {
- _vars[179]++;
- writeArray(178, 0, base, obj);
- return;
+ _vars[179]++;
+ writeArray(178, 0, base, obj);
+ return;
}
base++;
}
}
-void Scumm::setOwnerOf(int obj, int owner) {
+void Scumm::setOwnerOf(int obj, int owner)
+{
ScriptSlot *ss;
- if (owner==0) {
+ if (owner == 0) {
clearOwnerOf(obj);
ss = &vm.slot[_currentScript];
- if (ss->where==WIO_INVENTORY && _inventory[ss->number]==obj) {
+ if (ss->where == WIO_INVENTORY && _inventory[ss->number] == obj) {
putOwner(obj, 0);
runHook(0);
stopObjectCode();
@@ -913,64 +958,70 @@ void Scumm::setOwnerOf(int obj, int owner) {
runHook(0);
}
-int Scumm::getObjX(int obj) {
+int Scumm::getObjX(int obj)
+{
if (obj < NUM_ACTORS) {
- if (obj<1)
- return 0; /* fix for indy4's map */
- return derefActorSafe(obj,"getObjX")->x;
+ if (obj < 1)
+ return 0; /* fix for indy4's map */
+ return derefActorSafe(obj, "getObjX")->x;
} else {
- if (whereIsObject(obj)==WIO_NOT_FOUND)
+ if (whereIsObject(obj) == WIO_NOT_FOUND)
return -1;
getObjectOrActorXY(obj);
return _xPos;
}
}
-int Scumm::getObjY(int obj) {
+int Scumm::getObjY(int obj)
+{
if (obj < NUM_ACTORS) {
- if (obj<1)
- return 0; /* fix for indy4's map */
- return derefActorSafe(obj,"getObjY")->y;
+ if (obj < 1)
+ return 0; /* fix for indy4's map */
+ return derefActorSafe(obj, "getObjY")->y;
} else {
- if (whereIsObject(obj)==WIO_NOT_FOUND)
+ if (whereIsObject(obj) == WIO_NOT_FOUND)
return -1;
getObjectOrActorXY(obj);
return _yPos;
}
}
-int Scumm::getObjOldDir(int obj) {
+int Scumm::getObjOldDir(int obj)
+{
if (obj < NUM_ACTORS) {
- return newDirToOldDir(derefActorSafe(obj,"getObjOldDir")->facing);
+ return newDirToOldDir(derefActorSafe(obj, "getObjOldDir")->facing);
} else {
getObjectXYPos(obj);
return _dir;
}
}
-int Scumm::getObjNewDir(int obj) {
+int Scumm::getObjNewDir(int obj)
+{
if (obj < NUM_ACTORS) {
- return derefActorSafe(obj,"getObjNewDir")->facing;
+ return derefActorSafe(obj, "getObjNewDir")->facing;
} else {
getObjectXYPos(obj);
return oldDirToNewDir(_dir);
}
}
-int Scumm::findInventory(int owner, int idx) {
+int Scumm::findInventory(int owner, int idx)
+{
int count = 1, i, obj;
- for (i=0; i!=_maxInventoryItems; i++) {
+ for (i = 0; i != _maxInventoryItems; i++) {
obj = _inventory[i];
- if (obj && getOwner(obj)==owner && count++ == idx)
+ if (obj && getOwner(obj) == owner && count++ == idx)
return obj;
}
- return 0;
+ return 0;
}
-int Scumm::getInventoryCount(int owner) {
- int i,obj;
+int Scumm::getInventoryCount(int owner)
+{
+ int i, obj;
int count = 0;
- for (i=0; i!=_maxInventoryItems; i++) {
+ for (i = 0; i != _maxInventoryItems; i++) {
obj = _inventory[i];
if (obj && getOwner(obj) == owner)
count++;
@@ -978,41 +1029,45 @@ int Scumm::getInventoryCount(int owner) {
return count;
}
-void Scumm::setObjectState(int obj, int state, int x, int y) {
+void Scumm::setObjectState(int obj, int state, int x, int y)
+{
int i;
i = getObjectIndex(obj);
- if (i==-1) {
+ if (i == -1) {
warning("setObjectState: no such object");
return;
}
if (x != -1) {
- _objs[i].x_pos = x<<3;
- _objs[i].y_pos = y<<3;
+ _objs[i].x_pos = x << 3;
+ _objs[i].y_pos = y << 3;
}
addObjectToDrawQue(i);
putState(obj, state);
}
-static int getDist(int x, int y, int x2, int y2) {
- int a = abs(y-y2);
- int b = abs(x-x2);
- if (a>b)
+static int getDist(int x, int y, int x2, int y2)
+{
+ int a = abs(y - y2);
+ int b = abs(x - x2);
+ if (a > b)
return a;
return b;
}
-int Scumm::getDistanceBetween(bool is_obj_1, int b, int c, bool is_obj_2, int e, int f) {
- int i,j;
- int x,y;
- int x2,y2;
-
+int Scumm::getDistanceBetween(bool is_obj_1, int b, int c, bool is_obj_2,
+ int e, int f)
+{
+ int i, j;
+ int x, y;
+ int x2, y2;
+
j = i = 0xFF;
if (is_obj_1) {
- if (getObjectOrActorXY(b)==-1)
+ if (getObjectOrActorXY(b) == -1)
return -1;
if (b < NUM_ACTORS)
i = derefActorSafe(b, "unkObjProc1")->scalex;
@@ -1024,7 +1079,7 @@ int Scumm::getDistanceBetween(bool is_obj_1, int b, int c, bool is_obj_2, int e,
}
if (is_obj_2) {
- if (getObjectOrActorXY(e)==-1)
+ if (getObjectOrActorXY(e) == -1)
return -1;
if (e < NUM_ACTORS)
j = derefActorSafe(e, "unkObjProc1(2)")->scalex;
@@ -1035,43 +1090,43 @@ int Scumm::getDistanceBetween(bool is_obj_1, int b, int c, bool is_obj_2, int e,
y2 = f;
}
- return getDist(x,y,x2,y2) * 0xFF / ((i + j)>>1);
+ return getDist(x, y, x2, y2) * 0xFF / ((i + j) >> 1);
}
-void Scumm::setCursorImg(uint img, uint room, uint imgindex) {
- int w,h;
- byte *dataptr,*bomp;
+void Scumm::setCursorImg(uint img, uint room, uint imgindex)
+{
+ int w, h;
+ byte *dataptr, *bomp;
uint32 size;
FindObjectInRoom foir;
-
- if (room==(uint)-1)
+
+ if (room == (uint) - 1)
room = getObjectRoom(img);
- findObjectInRoom(&foir, foCodeHeader | foImageHeader | foCheckAlreadyLoaded, img, room);
+ findObjectInRoom(&foir, foCodeHeader | foImageHeader | foCheckAlreadyLoaded,
+ img, room);
- if(_features & GF_AFTER_V7)
- setCursorHotspot2(
- READ_LE_UINT16(&foir.imhd->v7.hotspot[0].x),
- READ_LE_UINT16(&foir.imhd->v7.hotspot[0].y));
+ if (_features & GF_AFTER_V7)
+ setCursorHotspot2(READ_LE_UINT16(&foir.imhd->v7.hotspot[0].x),
+ READ_LE_UINT16(&foir.imhd->v7.hotspot[0].y));
else
- setCursorHotspot2(
- READ_LE_UINT16(&foir.imhd->old.hotspot[0].x),
- READ_LE_UINT16(&foir.imhd->old.hotspot[0].y));
-
-
- if(!(_features & GF_AFTER_V7)) {
- w = READ_LE_UINT16(&foir.cdhd->v6.w)>>3;
- h = READ_LE_UINT16(&foir.cdhd->v6.h)>>3;
+ setCursorHotspot2(READ_LE_UINT16(&foir.imhd->old.hotspot[0].x),
+ READ_LE_UINT16(&foir.imhd->old.hotspot[0].y));
+
+
+ if (!(_features & GF_AFTER_V7)) {
+ w = READ_LE_UINT16(&foir.cdhd->v6.w) >> 3;
+ h = READ_LE_UINT16(&foir.cdhd->v6.h) >> 3;
} else {
- w = READ_LE_UINT16(&foir.imhd->v7.width)>>3;
- h = READ_LE_UINT16(&foir.imhd->v7.height)>>3;
+ w = READ_LE_UINT16(&foir.imhd->v7.width) >> 3;
+ h = READ_LE_UINT16(&foir.imhd->v7.height) >> 3;
}
- dataptr = findResource(IMxx_tags[imgindex],foir.obim);
- if (dataptr==NULL)
+ dataptr = findResource(IMxx_tags[imgindex], foir.obim);
+ if (dataptr == NULL)
error("setCursorImg: No such image");
- size = READ_BE_UINT32_UNALIGNED(dataptr+4);
+ size = READ_BE_UINT32_UNALIGNED(dataptr + 4);
if (size > sizeof(_grabbedCursor))
error("setCursorImg: Cursor image too large");
@@ -1082,25 +1137,28 @@ void Scumm::setCursorImg(uint img, uint room, uint imgindex) {
}
-void Scumm::nukeFlObjects(int min, int max) {
+void Scumm::nukeFlObjects(int min, int max)
+{
ObjectData *od;
int i;
warning("nukeFlObjects(%d,%d)", min, max);
- for (i=_numObjectsInRoom,od=_objs; --i>=0; od++)
- if (od->fl_object_index && od->obj_nr>=min && od->obj_nr<=max) {
+ for (i = _numObjectsInRoom, od = _objs; --i >= 0; od++)
+ if (od->fl_object_index && od->obj_nr >= min && od->obj_nr <= max) {
nukeResource(rtFlObject, od->fl_object_index);
od->obj_nr = 0;
od->fl_object_index = 0;
}
}
-void Scumm::enqueueObject(int a, int b, int c, int d, int e, int f, int g, int h, int mode) {
+void Scumm::enqueueObject(int a, int b, int c, int d, int e, int f, int g,
+ int h, int mode)
+{
EnqueuedObject *eo;
ObjectData *od;
- if (_enqueuePos==sizeof(_enqueuedObjects)/sizeof(_enqueuedObjects[0]))
+ if (_enqueuePos == sizeof(_enqueuedObjects) / sizeof(_enqueuedObjects[0]))
error("enqueueObject: overflow");
eo = &_enqueuedObjects[_enqueuePos++];
@@ -1111,13 +1169,13 @@ void Scumm::enqueueObject(int a, int b, int c, int d, int e, int f, int g, int h
eo->e = _enqueue_e;
eo->x = b;
eo->y = c;
- if (d==0) {
+ if (d == 0) {
od = &_objs[getObjectIndex(a)];
eo->width = od->width;
} else {
eo->width = d;
}
- if (e==0) {
+ if (e == 0) {
od = &_objs[getObjectIndex(a)];
eo->height = od->height;
} else {
@@ -1129,20 +1187,22 @@ void Scumm::enqueueObject(int a, int b, int c, int d, int e, int f, int g, int h
eo->l = h;
}
-void Scumm::drawEnqueuedObjects() {
+void Scumm::drawEnqueuedObjects()
+{
EnqueuedObject *eo;
int i;
eo = _enqueuedObjects;
- for(i=0; i < _enqueuePos; i++,eo++) {
+ for (i = 0; i < _enqueuePos; i++, eo++) {
drawEnqueuedObject(eo);
}
}
-void Scumm::drawEnqueuedObject(EnqueuedObject *eo) {
+void Scumm::drawEnqueuedObject(EnqueuedObject * eo)
+{
VirtScreen *vs;
- byte *roomptr,*bomp;
+ byte *roomptr, *bomp;
byte *ptr;
int idx;
ObjectData *od;
@@ -1153,12 +1213,12 @@ void Scumm::drawEnqueuedObject(EnqueuedObject *eo) {
_lastXstart = vs->xstart;
- if (eo->l==0) {
+ if (eo->l == 0) {
roomptr = getResourceAddress(1, _roomResource);
idx = getObjectIndex(eo->a);
assert(idx != -1);
ptr = roomptr + _objs[idx].offs_obim_to_room;
- } else if (eo->a!=0) {
+ } else if (eo->a != 0) {
od = &_objs[getObjectIndex(eo->a)];
ptr = getResourceAddress(rtFlObject, od->fl_object_index);
assert(ptr);
@@ -1168,18 +1228,18 @@ void Scumm::drawEnqueuedObject(EnqueuedObject *eo) {
return;
}
- if(eo->l == 0)
+ if (eo->l == 0)
eo->l = 1;
-
+
assert(ptr);
ptr = findResource(IMxx_tags[eo->l], ptr);
// assert(ptr);
- if (!ptr) /* FIXME: Sam and Max highway subgame */
- return;
+ if (!ptr) /* FIXME: Sam and Max highway subgame */
+ return;
bomp = findResourceData(MKID('BOMP'), ptr);
- bdd.srcwidth = READ_LE_UINT16(&((BompHeader*)bomp)->width);
- bdd.srcheight = READ_LE_UINT16(&((BompHeader*)bomp)->height);
+ bdd.srcwidth = READ_LE_UINT16(&((BompHeader *)bomp)->width);
+ bdd.srcheight = READ_LE_UINT16(&((BompHeader *)bomp)->height);
bdd.out = vs->screenPtr + vs->xstart;
bdd.outwidth = 320;
@@ -1190,43 +1250,48 @@ void Scumm::drawEnqueuedObject(EnqueuedObject *eo) {
bdd.scale_x = (unsigned char)eo->j;
bdd.scale_y = (unsigned char)eo->k;
- updateDirtyRect(vs->number, bdd.x, bdd.x+bdd.srcwidth, bdd.y, bdd.y+bdd.srcheight, 0);
+ updateDirtyRect(vs->number, bdd.x, bdd.x + bdd.srcwidth, bdd.y,
+ bdd.y + bdd.srcheight, 0);
if (eo->a) {
drawBomp(&bdd);
}
}
-void Scumm::removeEnqueuedObjects() {
+void Scumm::removeEnqueuedObjects()
+{
EnqueuedObject *eo;
int i;
eo = _enqueuedObjects;
- for(i=0; i < _enqueuePos; i++,eo++) {
+ for (i = 0; i < _enqueuePos; i++, eo++) {
removeEnqueuedObject(eo);
}
clearEnqueue();
}
-void Scumm::removeEnqueuedObject(EnqueuedObject *eo) {
+void Scumm::removeEnqueuedObject(EnqueuedObject * eo)
+{
restoreBG(eo->x, eo->y, eo->x + eo->width, eo->y + eo->height);
}
-int Scumm::findFlObjectSlot() {
+int Scumm::findFlObjectSlot()
+{
int i;
- for(i=1; i<_maxFLObject; i++) {
+ for (i = 1; i < _maxFLObject; i++) {
if (_baseFLObject[i] == NULL)
return i;
}
error("findFlObjectSlot: Out of FLObject slots");
}
-void Scumm::loadFlObject(uint object, uint room) {
+void Scumm::loadFlObject(uint object, uint room)
+{
FindObjectInRoom foir;
int slot;
ObjectData *od;
- byte *flob,*roomptr;
+ byte *flob, *roomptr;
uint32 obcd_size, obim_size, flob_size;
/* Don't load an already loaded object */
@@ -1255,8 +1320,8 @@ void Scumm::loadFlObject(uint object, uint room) {
/* Copy object code + object image to floating object */
roomptr = getResourceAddress(rtRoom, room);
flob = getResourceAddress(rtFlObject, slot);
- ((uint32*)flob)[0] = MKID('FLOB');
- ((uint32*)flob)[1] = TO_BE_32(flob_size);
+ ((uint32 *)flob)[0] = MKID('FLOB');
+ ((uint32 *)flob)[1] = TO_BE_32(flob_size);
memcpy(flob + 8, roomptr - foir.roomptr + foir.obcd, obcd_size);
memcpy(flob + 8 + obcd_size, roomptr - foir.roomptr + foir.obim, obim_size);
diff --git a/readme.txt b/readme.txt
index 588a6468f7..455d78760e 100644
--- a/readme.txt
+++ b/readme.txt
@@ -262,6 +262,19 @@ Windows example:
set SCUMMVM_SAVEPATH=C:\saved_games\
+Coding style:
+------------
+For ScummVM coding, we use hugging braces, and two-space tab indents.
+We occasionally run the following 'indent' parameters to ensure everything
+is kept standard:
+
+-br -bap -nbc -lp -ce -cdw -brs -nbad -nbc -npsl -nip -ts2 -ncs -nbs
+-npcs -nbap -Tbyte -Tvoid -Tuint32 -Tuint8 -Tuint16 -Tint -Tint8
+-Tint16 -Tint32 -TArrayHeader -TMemBlkHeader -TVerbSlot -TObjectData
+-TImageHeader -TRoomHeader -TCodeHeader -TResHdr -TBompHeader
+-TMidiChannelAdl -TGui -TScumm -TSoundEngine -TPart -TPlayer
+
+
------------------------------------------------------------------------
Good Luck and Happy Adventuring!
The ScummVM team.
diff --git a/resource.cpp b/resource.cpp
index 27f6babda8..556450dd90 100644
--- a/resource.cpp
+++ b/resource.cpp
@@ -24,11 +24,12 @@
#include "scumm.h"
/* Open a room */
-void Scumm::openRoom(int room) {
+void Scumm::openRoom(int room)
+{
int room_offs, roomlimit;
char buf[256];
- debug(9, "openRoom(%d)",room);
+ debug(9, "openRoom(%d)", room);
/* Don't load the same room again */
if (_lastLoadedRoom == room)
@@ -36,7 +37,7 @@ void Scumm::openRoom(int room) {
_lastLoadedRoom = room;
/* Room -1 means close file */
- if (room==-1) {
+ if (room == -1) {
_encbyte = 0;
deleteRoomOffsets();
fileClose(_fileHandle);
@@ -49,13 +50,16 @@ void Scumm::openRoom(int room) {
#if REAL_CODE
room_offs = _roomFileOffsets[room];
#else
- if( _features & GF_SMALL_NAMES) roomlimit = 98; else roomlimit=900;
- if(_features & GF_EXTERNAL_CHARSET && room>=roomlimit)
- room_offs = 0;
- else
- room_offs = room ? _roomFileOffsets[room] : 0;
+ if (_features & GF_SMALL_NAMES)
+ roomlimit = 98;
+ else
+ roomlimit = 900;
+ if (_features & GF_EXTERNAL_CHARSET && room >= roomlimit)
+ room_offs = 0;
+ else
+ room_offs = room ? _roomFileOffsets[room] : 0;
#endif
-
+
if (room_offs == (int)0xFFFFFFFF)
break;
@@ -63,15 +67,17 @@ void Scumm::openRoom(int room) {
_fileOffset = _roomFileOffsets[room];
return;
}
- if (!(_features & GF_SMALL_HEADER)) {
- if(_features & GF_AFTER_V7)
- sprintf(buf, "%s%s.la%d", _gameDataPath, _exe_name, room==0 ? 0 : res.roomno[rtRoom][room]);
+ if (!(_features & GF_SMALL_HEADER)) {
+ if (_features & GF_AFTER_V7)
+ sprintf(buf, "%s%s.la%d", _gameDataPath, _exe_name,
+ room == 0 ? 0 : res.roomno[rtRoom][room]);
else
- sprintf(buf, "%s%s.%.3d", _gameDataPath, _exe_name, room==0 ? 0 : res.roomno[rtRoom][room]);
- _encbyte = (_features & GF_USE_KEY) ? 0x69 : 0;
- } else if(!(_features & GF_SMALL_NAMES)) {
- if(room==0 || room>=900) {
- sprintf(buf, "%s%.3d.lfl",_gameDataPath,room);
+ sprintf(buf, "%s%s.%.3d", _gameDataPath, _exe_name,
+ room == 0 ? 0 : res.roomno[rtRoom][room]);
+ _encbyte = (_features & GF_USE_KEY) ? 0x69 : 0;
+ } else if (!(_features & GF_SMALL_NAMES)) {
+ if (room == 0 || room >= 900) {
+ sprintf(buf, "%s%.3d.lfl", _gameDataPath, room);
_encbyte = 0;
if (openResourceFile(buf)) {
return;
@@ -79,21 +85,22 @@ void Scumm::openRoom(int room) {
askForDisk(buf);
} else {
- sprintf(buf, "%sdisk%.2d.lec",_gameDataPath,res.roomno[rtRoom][room]);
+ sprintf(buf, "%sdisk%.2d.lec", _gameDataPath,
+ res.roomno[rtRoom][room]);
_encbyte = 0x69;
}
} else {
- sprintf(buf, "%s%.2d.lfl",_gameDataPath,room);
- if(_features & GF_OLD_BUNDLE)
- _encbyte = 0xFF;
- else
- _encbyte = 0;
+ sprintf(buf, "%s%.2d.lfl", _gameDataPath, room);
+ if (_features & GF_OLD_BUNDLE)
+ _encbyte = 0xFF;
+ else
+ _encbyte = 0;
}
if (openResourceFile(buf)) {
- if (room==0)
+ if (room == 0)
return;
- if (_features & GF_EXTERNAL_CHARSET && room>=roomlimit)
+ if (_features & GF_EXTERNAL_CHARSET && room >= roomlimit)
return;
readRoomsOffsets();
_fileOffset = _roomFileOffsets[room];
@@ -110,51 +117,53 @@ void Scumm::openRoom(int room) {
do {
sprintf(buf, "%.3d.lfl", room);
_encbyte = 0;
- if (openResourceFile(buf))
+ if (openResourceFile(buf))
break;
askForDisk(buf);
- } while(1);
+ } while (1);
deleteRoomOffsets();
- _fileOffset = 0; /* start of file */
+ _fileOffset = 0; /* start of file */
}
/* Delete the currently loaded room offsets */
-void Scumm::deleteRoomOffsets() {
- if (!(_features & GF_SMALL_HEADER) && !_dynamicRoomOffsets)
+void Scumm::deleteRoomOffsets()
+{
+ if (!(_features & GF_SMALL_HEADER) && !_dynamicRoomOffsets)
return;
-
- for (int i=0; i<_maxRooms; i++) {
- if (_roomFileOffsets[i]!=0xFFFFFFFF)
+
+ for (int i = 0; i < _maxRooms; i++) {
+ if (_roomFileOffsets[i] != 0xFFFFFFFF)
_roomFileOffsets[i] = 0;
}
}
/* Read room offsets */
-void Scumm::readRoomsOffsets() {
- int num,room;
+void Scumm::readRoomsOffsets()
+{
+ int num, room;
debug(9, "readRoomOffsets()");
- deleteRoomOffsets();
- if(_features & GF_SMALL_NAMES)
- return;
+ deleteRoomOffsets();
+ if (_features & GF_SMALL_NAMES)
+ return;
+
+ if (!(_features & GF_SMALL_HEADER)) {
+ if (!_dynamicRoomOffsets)
+ return;
- if (!(_features & GF_SMALL_HEADER)) {
- if (!_dynamicRoomOffsets)
- return;
+ fileSeek(_fileHandle, 16, SEEK_SET);
+ } else {
+ fileSeek(_fileHandle, 12, SEEK_SET); // Directlry searching for the room offset block would be more generic...
+ }
- fileSeek(_fileHandle, 16, SEEK_SET);
- } else {
- fileSeek(_fileHandle, 12, SEEK_SET); // Directlry searching for the room offset block would be more generic...
- }
-
num = fileReadByte();
while (num) {
num--;
-
+
room = fileReadByte();
- if (_roomFileOffsets[room]!=0xFFFFFFFF) {
+ if (_roomFileOffsets[room] != 0xFFFFFFFF) {
_roomFileOffsets[room] = fileReadDwordLE();
} else {
fileReadDwordLE();
@@ -162,17 +171,18 @@ void Scumm::readRoomsOffsets() {
}
}
-bool Scumm::openResourceFile(const char *filename) {
+bool Scumm::openResourceFile(const char *filename)
+{
char buf[256];
-
- debug(9, "openResourceFile(%s)",filename);
+
+ debug(9, "openResourceFile(%s)", filename);
if (_resFilePath) {
- #if defined(__APPLE__CW)
+#if defined(__APPLE__CW)
sprintf(buf, ":%s.%d:%s", _resFilePath, _resFilePathId, filename);
- #else
+#else
sprintf(buf, "%s.%d\\%s", _resFilePath, _resFilePathId, filename);
- #endif
+#endif
} else if (_resFilePrefix) {
sprintf(buf, "%s%s", _resFilePrefix, filename);
} else {
@@ -185,16 +195,18 @@ bool Scumm::openResourceFile(const char *filename) {
}
_fileHandle = fileOpen(buf, 1);
-
+
return _fileHandle != NULL;
}
-void Scumm::askForDisk(const char *filename) {
+void Scumm::askForDisk(const char *filename)
+{
error("Cannot find '%s'", filename);
}
-void Scumm::readIndexFile() {
- uint32 blocktype,itemsize;
+void Scumm::readIndexFile()
+{
+ uint32 blocktype, itemsize;
int numblock = 0;
int num, i;
@@ -210,32 +222,32 @@ void Scumm::readIndexFile() {
itemsize = fileReadDwordBE();
if (fileReadFailed(_fileHandle))
break;
- switch(blocktype) {
+ switch (blocktype) {
case MKID('DOBJ'):
_numGlobalObjects = fileReadWordLE();
- itemsize-=2;
+ itemsize -= 2;
break;
case MKID('DROO'):
_numRooms = fileReadWordLE();
- itemsize-=2;
+ itemsize -= 2;
break;
case MKID('DSCR'):
_numScripts = fileReadWordLE();
- itemsize-=2;
+ itemsize -= 2;
break;
case MKID('DCOS'):
_numCostumes = fileReadWordLE();
- itemsize-=2;
+ itemsize -= 2;
break;
case MKID('DSOU'):
_numSounds = fileReadWordLE();
- itemsize-=2;
+ itemsize -= 2;
break;
}
- fileSeek(_fileHandle, itemsize-8,SEEK_CUR);
+ fileSeek(_fileHandle, itemsize - 8, SEEK_CUR);
}
clearFileReadFailed(_fileHandle);
fileSeek(_fileHandle, 0, SEEK_SET);
@@ -250,33 +262,33 @@ void Scumm::readIndexFile() {
numblock++;
- switch(blocktype) {
+ switch (blocktype) {
case MKID('DCHR'):
- readResTypeList(rtCharset,MKID('CHAR'),"charset");
+ readResTypeList(rtCharset, MKID('CHAR'), "charset");
break;
case MKID('DOBJ'):
num = fileReadWordLE();
assert(num == _numGlobalObjects);
-
+
if (_features & GF_AFTER_V7) {
fileRead(_fileHandle, _objectStateTable, num);
fileRead(_fileHandle, _objectRoomTable, num);
memset(_objectOwnerTable, 0xFF, num);
-
+
} else {
fileRead(_fileHandle, _objectOwnerTable, num);
- for (i=0; i<num; i++) {
- _objectStateTable[i] = _objectOwnerTable[i]>>OF_STATE_SHL;
+ for (i = 0; i < num; i++) {
+ _objectStateTable[i] = _objectOwnerTable[i] >> OF_STATE_SHL;
_objectOwnerTable[i] &= OF_OWNER_MASK;
}
}
fileRead(_fileHandle, _classData, num * sizeof(uint32));
/* This code should be here. Otherwise the flags will be swapped for big endian computers.
- * If it doesn't work with this code, something else is wrong */
+ * If it doesn't work with this code, something else is wrong */
#if defined(SCUMM_BIG_ENDIAN)
- for (i=0; i!=num; i++) {
+ for (i = 0; i != num; i++) {
_classData[i] = FROM_LE_32(_classData[i]);
}
#endif
@@ -284,19 +296,19 @@ void Scumm::readIndexFile() {
case MKID('RNAM'):
case MKID('ANAM'):
- fileSeek(_fileHandle, itemsize-8,SEEK_CUR);
+ fileSeek(_fileHandle, itemsize - 8, SEEK_CUR);
break;
case MKID('DROO'):
- readResTypeList(rtRoom,MKID('ROOM'),"room");
+ readResTypeList(rtRoom, MKID('ROOM'), "room");
break;
case MKID('DSCR'):
- readResTypeList(rtScript,MKID('SCRP'),"script");
+ readResTypeList(rtScript, MKID('SCRP'), "script");
break;
case MKID('DCOS'):
- readResTypeList(rtCostume,MKID('COST'),"costume");
+ readResTypeList(rtCostume, MKID('COST'), "costume");
break;
case MKID('MAXS'):
@@ -304,7 +316,7 @@ void Scumm::readIndexFile() {
break;
case MKID('DSOU'):
- readResTypeList(rtSound,MKID('SOUN'),"sound");
+ readResTypeList(rtSound, MKID('SOUN'), "sound");
break;
case MKID('AARY'):
@@ -312,73 +324,79 @@ void Scumm::readIndexFile() {
break;
default:
- error("Bad ID %c%c%c%c found in directory!", blocktype&0xFF, blocktype>>8, blocktype>>16, blocktype>>24);
+ error("Bad ID %c%c%c%c found in directory!", blocktype & 0xFF,
+ blocktype >> 8, blocktype >> 16, blocktype >> 24);
return;
}
}
-// if (numblock!=9)
-// error("Not enough blocks read from directory");
+// if (numblock!=9)
+// error("Not enough blocks read from directory");
openRoom(-1);
}
-void Scumm::readArrayFromIndexFile() {
+void Scumm::readArrayFromIndexFile()
+{
int num;
- int a,b,c;
+ int a, b, c;
while ((num = fileReadWordLE()) != 0) {
a = fileReadWordLE();
b = fileReadWordLE();
c = fileReadWordLE();
- if (c==1)
+ if (c == 1)
defineArray(num, 1, a, b);
else
defineArray(num, 5, a, b);
}
}
-void Scumm::readResTypeList(int id, uint32 tag, const char *name) {
+void Scumm::readResTypeList(int id, uint32 tag, const char *name)
+{
int num;
int i;
-
- debug(9, "readResTypeList(%d,%x,%s)",id,FROM_LE_32(tag),name);
-
+
+ debug(9, "readResTypeList(%d,%x,%s)", id, FROM_LE_32(tag), name);
+
num = fileReadWordLE();
- if (1 || _features&GF_AFTER_V6) {
+ if (1 || _features & GF_AFTER_V6) {
if (num != res.num[id]) {
- error("Invalid number of %ss (%d) in directory", name, num);
+ error("Invalid number of %ss (%d) in directory", name, num);
}
} else {
- if (num>=0xFF) {
+ if (num >= 0xFF) {
error("Too many %ss (%d) in directory", name, num);
}
allocResTypeData(id, tag, num, name, 1);
}
- if (_features & GF_SMALL_HEADER) {
- for (i=0; i<num; i++) {
- res.roomno[id][i] = fileReadByte();
- res.roomoffs[id][i]= fileReadDword();
- }
- } else {
- fileRead(_fileHandle, res.roomno[id], num*sizeof(uint8));
- fileRead(_fileHandle, res.roomoffs[id], num*sizeof(uint32));
- }
+ if (_features & GF_SMALL_HEADER) {
+ for (i = 0; i < num; i++) {
+ res.roomno[id][i] = fileReadByte();
+ res.roomoffs[id][i] = fileReadDword();
+ }
+ } else {
+ fileRead(_fileHandle, res.roomno[id], num * sizeof(uint8));
+ fileRead(_fileHandle, res.roomoffs[id], num * sizeof(uint32));
+ }
#if defined(SCUMM_BIG_ENDIAN)
- for (i=0; i<num; i++)
+ for (i = 0; i < num; i++)
res.roomoffs[id][i] = FROM_LE_32(res.roomoffs[id][i]);
#endif
}
-void Scumm::allocResTypeData(int id, uint32 tag, int num, const char *name, int mode) {
- debug(9, "allocResTypeData(%d,%x,%d,%s,%d)",id,FROM_LE_32(tag),num,name,mode);
- assert(id>=0 && id<(int)(sizeof(res.mode)/sizeof(res.mode[0])));
+void Scumm::allocResTypeData(int id, uint32 tag, int num, const char *name,
+ int mode)
+{
+ debug(9, "allocResTypeData(%d,%x,%d,%s,%d)", id, FROM_LE_32(tag), num, name,
+ mode);
+ assert(id >= 0 && id < (int)(sizeof(res.mode) / sizeof(res.mode[0])));
- if (num>=2000) {
+ if (num >= 2000) {
error("Too many %ss (%d) in directory", name, num);
}
@@ -386,50 +404,53 @@ void Scumm::allocResTypeData(int id, uint32 tag, int num, const char *name, int
res.num[id] = num;
res.tags[id] = tag;
res.name[id] = name;
- res.address[id] = (byte**)alloc(num*sizeof(void*));
- res.flags[id] = (byte*)alloc(num*sizeof(byte));
+ res.address[id] = (byte **)alloc(num * sizeof(void *));
+ res.flags[id] = (byte *)alloc(num * sizeof(byte));
if (mode) {
- res.roomno[id] = (byte*)alloc(num*sizeof(byte));
- res.roomoffs[id] = (uint32*)alloc(num*sizeof(uint32));
+ res.roomno[id] = (byte *)alloc(num * sizeof(byte));
+ res.roomoffs[id] = (uint32 *)alloc(num * sizeof(uint32));
}
}
-void Scumm::loadCharset(int no) {
+void Scumm::loadCharset(int no)
+{
int i, line = 0;
byte *ptr;
-
- debug(9, "loadCharset(%d)",no);
+
+ debug(9, "loadCharset(%d)", no);
memset(_charsetData, 0, sizeof(_charsetData));
-
- checkRange(_maxCharsets-1, 1, no, "Loading illegal charset %d");
-// ensureResourceLoaded(6, no);
+ checkRange(_maxCharsets - 1, 1, no, "Loading illegal charset %d");
+
+// ensureResourceLoaded(6, no);
ptr = getResourceAddress(6, no);
- for (i=0; i<15; i++) {
- _charsetData[no][i+1] = ptr[i+14];
+ for (i = 0; i < 15; i++) {
+ _charsetData[no][i + 1] = ptr[i + 14];
}
}
-void Scumm::nukeCharset(int i) {
- checkRange(_maxCharsets-1, 1, i, "Nuking illegal charset %d");
+void Scumm::nukeCharset(int i)
+{
+ checkRange(_maxCharsets - 1, 1, i, "Nuking illegal charset %d");
nukeResource(rtCharset, i);
}
-void Scumm::ensureResourceLoaded(int type, int i) {
+void Scumm::ensureResourceLoaded(int type, int i)
+{
void *addr;
debug(9, "ensureResourceLoaded(%d,%d)", type, i);
- if (type==rtRoom && i>127) {
- i = _resourceMapper[i&127];
+ if (type == rtRoom && i > 127) {
+ i = _resourceMapper[i & 127];
}
- if (i==0)
+ if (i == 0)
return;
addr = res.address[type][i];
@@ -438,71 +459,71 @@ void Scumm::ensureResourceLoaded(int type, int i) {
loadResource(type, i);
- if(!(_features & GF_AFTER_V7))
- if (type==rtRoom && i==_roomResource)
+ if (!(_features & GF_AFTER_V7))
+ if (type == rtRoom && i == _roomResource)
_vars[VAR_ROOM_FLAG] = 1;
}
-int Scumm::loadResource(int type, int idx) {
+int Scumm::loadResource(int type, int idx)
+{
int roomNr, i;
uint32 fileOffs;
uint32 size, tag;
-
-// debug(1, "loadResource(%d,%d)", type,idx);
- if(type == rtCharset && (_features & GF_SMALL_HEADER)){
- loadCharset(idx);
- return(1);
- }
+// debug(1, "loadResource(%d,%d)", type,idx);
+
+ if (type == rtCharset && (_features & GF_SMALL_HEADER)) {
+ loadCharset(idx);
+ return (1);
+ }
roomNr = getResourceRoomNr(type, idx);
if (roomNr == 0 || idx >= res.num[type]) {
- error("%s %d undefined",
- res.name[type],idx);
+ error("%s %d undefined", res.name[type], idx);
}
- if (type==rtRoom) {
+ if (type == rtRoom) {
fileOffs = 0;
} else {
fileOffs = res.roomoffs[type][idx];
- if (fileOffs==0xFFFFFFFF)
+ if (fileOffs == 0xFFFFFFFF)
return 0;
}
-
+
do {
- for (i=0; i<5; i++) {
+ for (i = 0; i < 5; i++) {
openRoom(roomNr);
fileSeek(_fileHandle, fileOffs + _fileOffset, SEEK_SET);
- if (_features & GF_SMALL_HEADER) {
- if(!(_features & GF_SMALL_NAMES))
- fileSeek(_fileHandle, 8, SEEK_CUR);
- size = fileReadDwordLE();
- tag = fileReadWordLE();
- fileSeek(_fileHandle, -6, SEEK_CUR);
- } else {
- if (type==rtSound) {
- fileReadDwordLE();
- fileReadDwordLE();
- return readSoundResource(type, idx);
- }
-
- tag = fileReadDword();
-
- if (tag != res.tags[type]) {
- error("%s %d not in room %d at %d+%d",
- res.name[type], type, roomNr, _fileOffset, fileOffs);
- }
-
- size = fileReadDwordBE();
- fileSeek(_fileHandle, -8, SEEK_CUR);
- }
+ if (_features & GF_SMALL_HEADER) {
+ if (!(_features & GF_SMALL_NAMES))
+ fileSeek(_fileHandle, 8, SEEK_CUR);
+ size = fileReadDwordLE();
+ tag = fileReadWordLE();
+ fileSeek(_fileHandle, -6, SEEK_CUR);
+ } else {
+ if (type == rtSound) {
+ fileReadDwordLE();
+ fileReadDwordLE();
+ return readSoundResource(type, idx);
+ }
+
+ tag = fileReadDword();
+
+ if (tag != res.tags[type]) {
+ error("%s %d not in room %d at %d+%d",
+ res.name[type], type, roomNr, _fileOffset, fileOffs);
+ }
+
+ size = fileReadDwordBE();
+ fileSeek(_fileHandle, -8, SEEK_CUR);
+ }
fileRead(_fileHandle, createResource(type, idx, size), size);
- /* dump the resource */
+ /* dump the resource */
#ifdef DUMP_SCRIPTS
- if(type==rtScript) {
+ if (type == rtScript) {
dumpResource("script-", idx, getResourceAddress(rtScript, idx));
}
#endif
@@ -515,13 +536,14 @@ int Scumm::loadResource(int type, int idx) {
}
error("Cannot read resource");
- } while(1);
+ } while (1);
}
-int Scumm::readSoundResource(int type, int idx) {
- uint32 pos, total_size, size, tag,basetag;
+int Scumm::readSoundResource(int type, int idx)
+{
+ uint32 pos, total_size, size, tag, basetag;
int pri, best_pri;
- uint32 best_size=0, best_offs=0;
+ uint32 best_size = 0, best_offs = 0;
debug(9, "readSoundResource(%d,%d)", type, idx);
@@ -530,27 +552,35 @@ int Scumm::readSoundResource(int type, int idx) {
basetag = fileReadDword();
total_size = fileReadDwordBE();
- if (_gameId==GID_SAMNMAX || _features & GF_AFTER_V7) {
+ if (_gameId == GID_SAMNMAX || _features & GF_AFTER_V7) {
if (basetag == MKID('MIDI')) {
fileSeek(_fileHandle, -8, SEEK_CUR);
- fileRead(_fileHandle,createResource(type, idx, total_size+8), total_size+8);
+ fileRead(_fileHandle, createResource(type, idx, total_size + 8),
+ total_size + 8);
return 1;
- }
+ }
} else if (basetag == MKID('SOU ')) {
best_pri = -1;
while (pos < total_size) {
tag = fileReadDword();
size = fileReadDwordBE() + 8;
pos += size;
-
- switch(tag) {
+
+ switch (tag) {
#ifdef USE_ADLIB
- case MKID('ADL '): pri = 10; break;
+ case MKID('ADL '):
+ pri = 10;
+ break;
#else
- case MKID('ROL '): pri = 1; break;
- case MKID('GMD '): pri = 2; break;
+ case MKID('ROL '):
+ pri = 1;
+ break;
+ case MKID('GMD '):
+ pri = 2;
+ break;
#endif
- default: pri = -1;
+ default:
+ pri = -1;
}
if (pri > best_pri) {
@@ -558,15 +588,15 @@ int Scumm::readSoundResource(int type, int idx) {
best_size = size;
best_offs = filePos(_fileHandle);
}
-
+
fileSeek(_fileHandle, size - 8, SEEK_CUR);
}
if (best_pri != -1) {
fileSeek(_fileHandle, best_offs - 8, SEEK_SET);
- fileRead(_fileHandle,createResource(type, idx, best_size), best_size);
+ fileRead(_fileHandle, createResource(type, idx, best_size), best_size);
return 1;
- }
+ }
} else if (FROM_LE_32(basetag) == 24) {
fileSeek(_fileHandle, -12, SEEK_CUR);
total_size = fileReadDwordBE();
@@ -575,36 +605,35 @@ int Scumm::readSoundResource(int type, int idx) {
return 1;
} else {
error("Unrecognized base tag %c%c%c%c in sound %d",
- basetag&0xff, basetag>>8, basetag>>16, basetag>>24,
- idx);
+ basetag & 0xff, basetag >> 8, basetag >> 16, basetag >> 24, idx);
}
res.roomoffs[type][idx] = 0xFFFFFFFF;
return 0;
}
-int Scumm::getResourceRoomNr(int type, int idx) {
- if (type==rtRoom)
+int Scumm::getResourceRoomNr(int type, int idx)
+{
+ if (type == rtRoom)
return idx;
return res.roomno[type][idx];
}
-byte *Scumm::getResourceAddress(int type, int idx) {
+byte *Scumm::getResourceAddress(int type, int idx)
+{
byte *ptr;
debug(9, "getResourceAddress(%d,%d)", type, idx);
- CHECK_HEAP
-
- validateResource("getResourceAddress", type, idx);
+ CHECK_HEAP validateResource("getResourceAddress", type, idx);
if (!res.address[type])
return NULL;
if (res.mode[type] && !res.address[type][idx]) {
ensureResourceLoaded(type, idx);
- }
+ }
-
- if (!(ptr = (byte*)res.address[type][idx]))
+
+ if (!(ptr = (byte *)res.address[type][idx]))
return NULL;
setResourceCounter(type, idx, 1);
@@ -612,17 +641,19 @@ byte *Scumm::getResourceAddress(int type, int idx) {
return ptr + sizeof(MemBlkHeader);
}
-byte *Scumm::getStringAddress(int i) {
+byte *Scumm::getStringAddress(int i)
+{
byte *b = getResourceAddress(rtString, i);
if (!b)
return b;
-
+
if (_features & GF_NEW_OPCODES)
- return ((ArrayHeader*)b)->data;
+ return ((ArrayHeader *)b)->data;
return b;
}
-void Scumm::setResourceCounter(int type, int idx, byte flag) {
+void Scumm::setResourceCounter(int type, int idx, byte flag)
+{
res.flags[type][idx] &= ~RF_USAGE;
res.flags[type][idx] |= flag;
}
@@ -630,14 +661,13 @@ void Scumm::setResourceCounter(int type, int idx, byte flag) {
/* 2 bytes safety area to make "precaching" of bytes in the gdi drawer easier */
#define SAFETY_AREA 2
-byte *Scumm::createResource(int type, int idx, uint32 size) {
+byte *Scumm::createResource(int type, int idx, uint32 size)
+{
byte *ptr;
- CHECK_HEAP
-
- debug(9, "createResource(%d,%d,%d)", type, idx,size);
+ CHECK_HEAP debug(9, "createResource(%d,%d,%d)", type, idx, size);
- if (size > 65536*4+37856)
+ if (size > 65536 * 4 + 37856)
warning("Probably invalid size allocating %d", size);
validateResource("allocating", type, idx);
@@ -645,97 +675,99 @@ byte *Scumm::createResource(int type, int idx, uint32 size) {
expireResources(size);
- CHECK_HEAP
-
- ptr = (byte*)alloc(size + sizeof(MemBlkHeader) + SAFETY_AREA);
- if (ptr==NULL) {
+ CHECK_HEAP ptr = (byte *)alloc(size + sizeof(MemBlkHeader) + SAFETY_AREA);
+ if (ptr == NULL) {
error("Out of memory while allocating %d", size);
}
_allocatedSize += size;
res.address[type][idx] = ptr;
- ((MemBlkHeader*)ptr)->size = size;
+ ((MemBlkHeader *)ptr)->size = size;
setResourceCounter(type, idx, 1);
- return ptr + sizeof(MemBlkHeader); /* skip header */
+ return ptr + sizeof(MemBlkHeader); /* skip header */
}
-void Scumm::validateResource(const char *str, int type, int idx) {
- if (type<rtFirst || type>rtLast || (uint)idx >= (uint)res.num[type]) {
+void Scumm::validateResource(const char *str, int type, int idx)
+{
+ if (type < rtFirst || type > rtLast || (uint) idx >= (uint) res.num[type]) {
warning("%s Illegal Glob type %d num %d", str, type, idx);
}
}
-void Scumm::nukeResource(int type, int idx) {
+void Scumm::nukeResource(int type, int idx)
+{
byte *ptr;
debug(9, "nukeResource(%d,%d)", type, idx);
- CHECK_HEAP
- if (!res.address[type])
+ CHECK_HEAP if (!res.address[type])
return;
- assert( idx>=0 && idx < res.num[type]);
+ assert(idx >= 0 && idx < res.num[type]);
if ((ptr = res.address[type][idx]) != NULL) {
res.address[type][idx] = 0;
res.flags[type][idx] = 0;
- _allocatedSize -= ((MemBlkHeader*)ptr)->size;
+ _allocatedSize -= ((MemBlkHeader *)ptr)->size;
free(ptr);
}
}
-byte *Scumm::findResourceData(uint32 tag, byte *ptr) {
- if(_features & GF_SMALL_HEADER) {
- ptr = findResourceSmall(tag,ptr,0);
- if (ptr==NULL)
- return NULL;
- return ptr + 6;
- }
+byte *Scumm::findResourceData(uint32 tag, byte *ptr)
+{
+ if (_features & GF_SMALL_HEADER) {
+ ptr = findResourceSmall(tag, ptr, 0);
+ if (ptr == NULL)
+ return NULL;
+ return ptr + 6;
+ }
- ptr = findResource(tag,ptr,0);
- if (ptr==NULL)
+ ptr = findResource(tag, ptr, 0);
+ if (ptr == NULL)
return NULL;
return ptr + 8;
}
-int Scumm::getResourceDataSize(byte *ptr) {
- if (ptr==NULL)
+int Scumm::getResourceDataSize(byte *ptr)
+{
+ if (ptr == NULL)
return 0;
- if (_features & GF_SMALL_HEADER)
- return READ_LE_UINT32(ptr)-6;
- else
- return READ_BE_UINT32(ptr-4)-8;
+ if (_features & GF_SMALL_HEADER)
+ return READ_LE_UINT32(ptr) - 6;
+ else
+ return READ_BE_UINT32(ptr - 4) - 8;
}
struct FindResourceState {
- uint32 size,pos;
+ uint32 size, pos;
byte *ptr;
};
/* just O(N) complexity when iterating with this function */
-byte *findResource(uint32 tag, byte *searchin) {
+byte *findResource(uint32 tag, byte *searchin)
+{
uint32 size;
static FindResourceState frs;
- FindResourceState *f = &frs; /* easier to make it thread safe like this */
+ FindResourceState *f = &frs; /* easier to make it thread safe like this */
if (searchin) {
- f->size = READ_BE_UINT32_UNALIGNED(searchin+4);
+ f->size = READ_BE_UINT32_UNALIGNED(searchin + 4);
f->pos = 8;
- f->ptr = searchin+8;
+ f->ptr = searchin + 8;
goto StartScan;
}
do {
- size = READ_BE_UINT32_UNALIGNED(f->ptr+4);
- if ((int32)size <= 0)
+ size = READ_BE_UINT32_UNALIGNED(f->ptr + 4);
+ if ((int32) size <= 0)
return NULL;
f->pos += size;
f->ptr += size;
-
-StartScan:
+
+ StartScan:
if (f->pos >= f->size)
return NULL;
} while (READ_UINT32_UNALIGNED(f->ptr) != tag);
@@ -743,39 +775,41 @@ StartScan:
return f->ptr;
}
-byte *findResourceSmall(uint32 tag, byte *searchin) {
- uint32 size;
- static FindResourceState frs;
- FindResourceState *f = &frs; /* easier to make it thread safe like this */
- uint16 smallTag;
-
- smallTag=newTag2Old(tag);
-
- if (searchin) {
- f->size = READ_LE_UINT32(searchin);
- f->pos = 6;
- f->ptr = searchin+6;
- goto StartScan;
- }
-
- do {
- size = READ_LE_UINT32(f->ptr);
- if ((int32)size <= 0)
- return NULL;
-
- f->pos += size;
- f->ptr += size;
-
-StartScan:
- if (f->pos >= f->size)
- return NULL;
- } while (READ_LE_UINT16(f->ptr+4) != smallTag);
-
- return f->ptr;
+byte *findResourceSmall(uint32 tag, byte *searchin)
+{
+ uint32 size;
+ static FindResourceState frs;
+ FindResourceState *f = &frs; /* easier to make it thread safe like this */
+ uint16 smallTag;
+
+ smallTag = newTag2Old(tag);
+
+ if (searchin) {
+ f->size = READ_LE_UINT32(searchin);
+ f->pos = 6;
+ f->ptr = searchin + 6;
+ goto StartScan;
+ }
+
+ do {
+ size = READ_LE_UINT32(f->ptr);
+ if ((int32) size <= 0)
+ return NULL;
+
+ f->pos += size;
+ f->ptr += size;
+
+ StartScan:
+ if (f->pos >= f->size)
+ return NULL;
+ } while (READ_LE_UINT16(f->ptr + 4) != smallTag);
+
+ return f->ptr;
}
-byte *findResource(uint32 tag, byte *searchin, int idx) {
- uint32 curpos,totalsize,size;
+byte *findResource(uint32 tag, byte *searchin, int idx)
+{
+ uint32 curpos, totalsize, size;
assert(searchin);
@@ -784,75 +818,78 @@ byte *findResource(uint32 tag, byte *searchin, int idx) {
curpos = 8;
searchin += 4;
- while (curpos<totalsize) {
- if (READ_UINT32_UNALIGNED(searchin)==tag && !idx--)
+ while (curpos < totalsize) {
+ if (READ_UINT32_UNALIGNED(searchin) == tag && !idx--)
return searchin;
- size = READ_BE_UINT32_UNALIGNED(searchin+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);
+ size = READ_BE_UINT32_UNALIGNED(searchin + 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;
}
curpos += size;
searchin += size;
- }
+ }
return NULL;
}
-byte *findResourceSmall(uint32 tag, byte *searchin, int idx) {
- uint32 curpos,totalsize,size;
- uint16 smallTag;
+byte *findResourceSmall(uint32 tag, byte *searchin, int idx)
+{
+ uint32 curpos, totalsize, size;
+ uint16 smallTag;
- smallTag=newTag2Old(tag);
+ smallTag = newTag2Old(tag);
- assert(searchin);
+ assert(searchin);
- totalsize = READ_LE_UINT32(searchin);
- searchin += 6;
- curpos = 6;
-
- while (curpos<totalsize) {
- size = READ_LE_UINT32(searchin);
+ totalsize = READ_LE_UINT32(searchin);
+ searchin += 6;
+ curpos = 6;
- if (READ_LE_UINT16(searchin+4)==smallTag && !idx--)
- return searchin;
+ while (curpos < totalsize) {
+ size = READ_LE_UINT32(searchin);
- 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;
- }
+ if (READ_LE_UINT16(searchin + 4) == smallTag && !idx--)
+ return searchin;
- curpos += size;
- searchin += size;
- }
+ 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;
+ }
+
+ curpos += size;
+ searchin += size;
+ }
- return NULL;
+ return NULL;
}
-void Scumm::lock(int type, int i) {
+void Scumm::lock(int type, int i)
+{
validateResource("Locking", type, i);
res.flags[type][i] |= RF_LOCK;
-// debug(1, "locking %d,%d", type, i);
+// debug(1, "locking %d,%d", type, i);
}
-void Scumm::unlock(int type, int i) {
+void Scumm::unlock(int type, int i)
+{
validateResource("Unlocking", type, i);
res.flags[type][i] &= ~RF_LOCK;
-// debug(1, "unlocking %d,%d", type, i);
+// debug(1, "unlocking %d,%d", type, i);
}
-bool Scumm::isResourceInUse(int type, int i) {
+bool Scumm::isResourceInUse(int type, int i)
+{
validateResource("isResourceInUse", type, i);
- switch(type) {
+ switch (type) {
case rtRoom:
return _roomResource == (byte)i;
case rtScript:
@@ -860,28 +897,30 @@ bool Scumm::isResourceInUse(int type, int i) {
case rtCostume:
return isCostumeInUse(i);
case rtSound:
- return isSoundRunning(i)!=0;
+ return isSoundRunning(i) != 0;
default:
return false;
}
}
-void Scumm::increaseResourceCounter() {
- int i,j;
+void Scumm::increaseResourceCounter()
+{
+ int i, j;
byte counter;
- for (i=rtFirst; i<=rtLast; i++) {
- for(j=res.num[i]; --j>=0;) {
+ for (i = rtFirst; i <= rtLast; i++) {
+ for (j = res.num[i]; --j >= 0;) {
counter = res.flags[i][j] & RF_USAGE;
if (counter && counter < RF_USAGE_MAX) {
- setResourceCounter(i, j, counter+1);
+ setResourceCounter(i, j, counter + 1);
}
}
}
}
-void Scumm::expireResources(uint32 size) {
- int i,j;
+void Scumm::expireResources(uint32 size)
+{
+ int i, j;
byte flag;
byte best_counter;
int best_type, best_res;
@@ -903,12 +942,12 @@ void Scumm::expireResources(uint32 size) {
best_type = 0;
best_counter = 2;
- for (i=rtFirst; i<=rtLast; i++)
+ for (i = rtFirst; i <= rtLast; i++)
if (res.mode[i]) {
- for(j=res.num[i]; --j>=0;) {
+ for (j = res.num[i]; --j >= 0;) {
flag = res.flags[i][j];
- if (!(flag&0x80) && flag >= best_counter
- && res.address[i][j] && !isResourceInUse(i,j)) {
+ if (!(flag & 0x80) && flag >= best_counter
+ && res.address[i][j] && !isResourceInUse(i, j)) {
best_counter = flag;
best_type = i;
best_res = j;
@@ -923,15 +962,17 @@ void Scumm::expireResources(uint32 size) {
increaseResourceCounter();
- debug(1, "Expired resources, mem %d -> %d", oldAllocatedSize, _allocatedSize);
+ debug(1, "Expired resources, mem %d -> %d", oldAllocatedSize,
+ _allocatedSize);
}
-void Scumm::freeResources() {
- int i,j;
- for (i=rtFirst; i<=rtLast; i++) {
- for(j=res.num[i]; --j>=0;) {
- if (isResourceLoaded(i,j))
- nukeResource(i,j);
+void Scumm::freeResources()
+{
+ int i, j;
+ for (i = rtFirst; i <= rtLast; i++) {
+ for (j = res.num[i]; --j >= 0;) {
+ if (isResourceLoaded(i, j))
+ nukeResource(i, j);
}
free(res.address[i]);
free(res.flags[i]);
@@ -940,9 +981,10 @@ void Scumm::freeResources() {
}
}
-void Scumm::loadPtrToResource(int type, int resindex, byte *source) {
+void Scumm::loadPtrToResource(int type, int resindex, byte *source)
+{
byte *alloced;
- int i,len;
+ int i, len;
nukeResource(type, resindex);
@@ -955,48 +997,54 @@ void Scumm::loadPtrToResource(int type, int resindex, byte *source) {
if (!source) {
alloced[0] = fetchScriptByte();
- for (i=1; i<len; i++)
+ for (i = 1; i < len; i++)
alloced[i] = *_scriptPointer++;
} else {
- for(i=0; i<len; i++)
+ for (i = 0; i < len; i++)
alloced[i] = source[i];
}
}
-bool Scumm::isResourceLoaded(int type, int idx) {
+bool Scumm::isResourceLoaded(int type, int idx)
+{
validateResource("isLoaded", type, idx);
return res.address[type][idx] != NULL;
}
-void Scumm::resourceStats() {
- int i,j;
+void Scumm::resourceStats()
+{
+ int i, j;
uint32 lockedSize = 0, lockedNum = 0;
byte flag;
-
- for (i=rtFirst; i<=rtLast; i++)
- for(j=res.num[i]; --j>=0;) {
+
+ for (i = rtFirst; i <= rtLast; i++)
+ for (j = res.num[i]; --j >= 0;) {
flag = res.flags[i][j];
- if (flag&0x80 && res.address[i][j]) {
- lockedSize += ((MemBlkHeader*)res.address[i][j])->size;
+ if (flag & 0x80 && res.address[i][j]) {
+ lockedSize += ((MemBlkHeader *)res.address[i][j])->size;
lockedNum++;
}
}
-
- printf("Total allocated size=%ld, locked=%ld(%ld)\n", _allocatedSize, lockedSize, lockedNum);
+
+ printf("Total allocated size=%ld, locked=%ld(%ld)\n", _allocatedSize,
+ lockedSize, lockedNum);
}
-void Scumm::heapClear(int mode) {
+void Scumm::heapClear(int mode)
+{
/* TODO: implement this */
warning("heapClear: not implemented");
}
-void Scumm::unkHeapProc2(int a, int b) {
+void Scumm::unkHeapProc2(int a, int b)
+{
warning("unkHeapProc2: not implemented");
-}
+}
-void Scumm::readMAXS() {
+void Scumm::readMAXS()
+{
if (_features & GF_AFTER_V7) {
- fileSeek(_fileHandle, 50+50, SEEK_CUR);
+ fileSeek(_fileHandle, 50 + 50, SEEK_CUR);
_numVariables = fileReadWordLE();
_numBitVariables = fileReadWordLE();
fileReadWordLE();
@@ -1013,7 +1061,7 @@ void Scumm::readMAXS() {
_numCharsets = fileReadWordLE();
_numCostumes = fileReadWordLE();
- _objectRoomTable = (byte*)alloc(_numGlobalObjects);
+ _objectRoomTable = (byte *)alloc(_numGlobalObjects);
_numGlobalScripts = 2000;
_shadowPaletteSize = NUM_SHADOW_PALETTE * 256;
@@ -1040,20 +1088,20 @@ void Scumm::readMAXS() {
_shadowPaletteSize = 256;
} else {
- _numVariables = fileReadWordLE(); /* 800 */
- fileReadWordLE(); /* 16 */
- _numBitVariables = fileReadWordLE(); /* 2048 */
- _numLocalObjects = fileReadWordLE(); /* 200 */
+ _numVariables = fileReadWordLE(); /* 800 */
+ fileReadWordLE(); /* 16 */
+ _numBitVariables = fileReadWordLE(); /* 2048 */
+ _numLocalObjects = fileReadWordLE(); /* 200 */
_numArray = 50;
_numVerbs = 100;
_numNewNames = 0;
_objectRoomTable = NULL;
- fileReadWordLE(); /* 50 */
- _numCharsets = fileReadWordLE(); /* 9 */
- fileReadWordLE(); /* 100 */
- fileReadWordLE(); /* 50 */
- _numInventory = fileReadWordLE(); /* 80 */
+ fileReadWordLE(); /* 50 */
+ _numCharsets = fileReadWordLE(); /* 9 */
+ fileReadWordLE(); /* 100 */
+ fileReadWordLE(); /* 50 */
+ _numInventory = fileReadWordLE(); /* 80 */
_numGlobalScripts = 200;
_shadowPaletteSize = 256;
@@ -1062,84 +1110,85 @@ void Scumm::readMAXS() {
}
if (_shadowPaletteSize)
- _shadowPalette = (byte*)alloc(_shadowPaletteSize);
-
+ _shadowPalette = (byte *)alloc(_shadowPaletteSize);
+
allocateArrays();
_dynamicRoomOffsets = 1;
}
-void Scumm::allocateArrays() {
+void Scumm::allocateArrays()
+{
// Note: Buffers are now allocated in scummMain to allow for
- // early GUI init.
-
- _objectOwnerTable = (byte*)alloc(_numGlobalObjects);
- _objectStateTable = (byte*)alloc(_numGlobalObjects);
- _classData = (uint32*)alloc(_numGlobalObjects * sizeof(uint32));
- _arrays = (byte*)alloc(_numArray);
- _newNames = (uint16*)alloc(_numNewNames * sizeof(uint16));
-
- _inventory = (uint16*)alloc(_numInventory * sizeof(uint16));
- _verbs = (VerbSlot*)alloc(_numVerbs * sizeof(VerbSlot));
- _objs = (ObjectData*)alloc(_numLocalObjects * sizeof(ObjectData));
- _vars = (int16*)alloc(_numVariables * sizeof(int16));
- _bitVars = (byte*)alloc(_numBitVariables >> 3);
-
- allocResTypeData(rtCostume,
- (_features & GF_NEW_COSTUMES) ? MKID('AKOS') : MKID('COST'),
- _numCostumes, "costume", 1);
+ // early GUI init.
+
+ _objectOwnerTable = (byte *)alloc(_numGlobalObjects);
+ _objectStateTable = (byte *)alloc(_numGlobalObjects);
+ _classData = (uint32 *)alloc(_numGlobalObjects * sizeof(uint32));
+ _arrays = (byte *)alloc(_numArray);
+ _newNames = (uint16 *)alloc(_numNewNames * sizeof(uint16));
+
+ _inventory = (uint16 *)alloc(_numInventory * sizeof(uint16));
+ _verbs = (VerbSlot *)alloc(_numVerbs * sizeof(VerbSlot));
+ _objs = (ObjectData *)alloc(_numLocalObjects * sizeof(ObjectData));
+ _vars = (int16 *) alloc(_numVariables * sizeof(int16));
+ _bitVars = (byte *)alloc(_numBitVariables >> 3);
+
+ allocResTypeData(rtCostume,
+ (_features & GF_NEW_COSTUMES) ? MKID('AKOS') :
+ MKID('COST'), _numCostumes, "costume", 1);
allocResTypeData(rtRoom, MKID('ROOM'), _numRooms, "room", 1);
allocResTypeData(rtSound, MKID('SOUN'), _numSounds, "sound", 1);
allocResTypeData(rtScript, MKID('SCRP'), _numScripts, "script", 1);
allocResTypeData(rtCharset, MKID('CHAR'), _numCharsets, "charset", 1);
- allocResTypeData(rtObjectName, MKID('NONE'),_numNewNames,"new name", 0);
- allocResTypeData(rtInventory, MKID('NONE'), _numInventory, "inventory", 0);
- allocResTypeData(rtTemp,MKID('NONE'),10, "temp", 0);
- allocResTypeData(rtScaleTable,MKID('NONE'),5, "scale table", 0);
- allocResTypeData(rtActorName, MKID('NONE'),NUM_ACTORS,"actor name", 0);
- allocResTypeData(rtVerb, MKID('NONE'),_numVerbs,"verb", 0);
- allocResTypeData(rtString, MKID('NONE'),_numArray,"array", 0);
- allocResTypeData(rtFlObject, MKID('NONE'),_numFlObject,"flobject", 0);
- allocResTypeData(rtMatrix, MKID('NONE'),10,"boxes", 0);
+ allocResTypeData(rtObjectName, MKID('NONE'), _numNewNames, "new name", 0);
+ allocResTypeData(rtInventory, MKID('NONE'), _numInventory, "inventory", 0);
+ allocResTypeData(rtTemp, MKID('NONE'), 10, "temp", 0);
+ allocResTypeData(rtScaleTable, MKID('NONE'), 5, "scale table", 0);
+ allocResTypeData(rtActorName, MKID('NONE'), NUM_ACTORS, "actor name", 0);
+ allocResTypeData(rtVerb, MKID('NONE'), _numVerbs, "verb", 0);
+ allocResTypeData(rtString, MKID('NONE'), _numArray, "array", 0);
+ allocResTypeData(rtFlObject, MKID('NONE'), _numFlObject, "flobject", 0);
+ allocResTypeData(rtMatrix, MKID('NONE'), 10, "boxes", 0);
}
-uint16 newTag2Old(uint32 oldTag) {
- switch(oldTag) {
- case(MKID('RMHD')):
- return(0x4448);
- break;
- case(MKID('IM00')):
- return(0x4D42);
- break;
- case(MKID('EXCD')):
- return(0x5845);
- break;
- case(MKID('ENCD')):
- return(0x4E45);
- break;
- case(MKID('SCAL')):
- return(0x4153);
- break;
- case(MKID('LSCR')):
- return(0x534C);
- break;
- case(MKID('OBCD')):
- return(0x434F);
- break;
- case(MKID('OBIM')):
- return(0x494F);
- break;
- case(MKID('SMAP')):
- return(0x4D42);
- break;
- case(MKID('CLUT')):
- return(0x4150);
- break;
- case(MKID('BOXD')):
- return(0x5842);
- break;
- default:
- return(0);
- }
+uint16 newTag2Old(uint32 oldTag)
+{
+ switch (oldTag) {
+ case (MKID('RMHD')):
+ return (0x4448);
+ break;
+ case (MKID('IM00')):
+ return (0x4D42);
+ break;
+ case (MKID('EXCD')):
+ return (0x5845);
+ break;
+ case (MKID('ENCD')):
+ return (0x4E45);
+ break;
+ case (MKID('SCAL')):
+ return (0x4153);
+ break;
+ case (MKID('LSCR')):
+ return (0x534C);
+ break;
+ case (MKID('OBCD')):
+ return (0x434F);
+ break;
+ case (MKID('OBIM')):
+ return (0x494F);
+ break;
+ case (MKID('SMAP')):
+ return (0x4D42);
+ break;
+ case (MKID('CLUT')):
+ return (0x4150);
+ break;
+ case (MKID('BOXD')):
+ return (0x5842);
+ break;
+ default:
+ return (0);
+ }
}
-
diff --git a/saveload.cpp b/saveload.cpp
index 6de4114e4f..89a7a95539 100644
--- a/saveload.cpp
+++ b/saveload.cpp
@@ -52,19 +52,20 @@ static uint32 _current_version = CURRENT_VER;
#endif
-bool Scumm::saveState(int slot, bool compat) {
+bool Scumm::saveState(int slot, bool compat)
+{
char filename[256];
SerializerStream out;
SaveGameHeader hdr;
Serializer ser;
makeSavegameName(filename, slot, compat);
-
- if (!out.fopen(filename,"wb"))
+
+ if (!out.fopen(filename, "wb"))
return false;
memcpy(hdr.name, _saveLoadName, sizeof(hdr.name));
-
+
hdr.type = MKID('SCVM');
hdr.size = 0;
@@ -77,7 +78,7 @@ bool Scumm::saveState(int slot, bool compat) {
hdr.ver = CURRENT_VER;
#endif
-
+
out.fwrite(&hdr, sizeof(hdr), 1);
ser._saveLoadStream = out;
@@ -85,20 +86,21 @@ bool Scumm::saveState(int slot, bool compat) {
saveOrLoad(&ser);
out.fclose();
- debug(1,"State saved as '%s'", filename);
+ debug(1, "State saved as '%s'", filename);
return true;
}
-bool Scumm::loadState(int slot, bool compat) {
+bool Scumm::loadState(int slot, bool compat)
+{
char filename[256];
- SerializerStream out;
- int i,j;
+ SerializerStream out;
+ int i, j;
SaveGameHeader hdr;
Serializer ser;
- int sb,sh;
+ int sb, sh;
makeSavegameName(filename, slot, compat);
- if (!out.fopen(filename,"rb"))
+ if (!out.fopen(filename, "rb"))
return false;
out.fread(&hdr, sizeof(hdr), 1);
@@ -107,8 +109,7 @@ bool Scumm::loadState(int slot, bool compat) {
out.fclose();
return false;
}
-
-#ifdef _MANAGE_OLD_SAVE
+#ifdef _MANAGE_OLD_SAVE
if (hdr.ver != VER_V8 && hdr.ver != VER_V7) {
@@ -122,7 +123,6 @@ bool Scumm::loadState(int slot, bool compat) {
out.fclose();
return false;
}
-
#ifdef _MANAGE_OLD_SAVE
_current_version = hdr.ver;
@@ -133,21 +133,19 @@ bool Scumm::loadState(int slot, bool compat) {
pauseSounds(true);
- CHECK_HEAP
-
- openRoom(-1);
- memset(_inventory, 0, sizeof(_inventory[0])*_numInventory);
+ CHECK_HEAP openRoom(-1);
+ memset(_inventory, 0, sizeof(_inventory[0]) * _numInventory);
/* Nuke all resources */
- for (i=rtFirst; i<=rtLast; i++)
- if (i!=rtTemp && i!=rtBuffer)
- for(j=0; j<res.num[i]; j++) {
- nukeResource(i,j);
+ for (i = rtFirst; i <= rtLast; i++)
+ if (i != rtTemp && i != rtBuffer)
+ for (j = 0; j < res.num[i]; j++) {
+ nukeResource(i, j);
res.flags[i][j] = 0;
}
initScummVars();
-
+
ser._saveLoadStream = out;
ser._saveOrLoad = false;
saveOrLoad(&ser);
@@ -157,7 +155,7 @@ bool Scumm::loadState(int slot, bool compat) {
sh = _screenH;
gdi._mask_left = -1;
-
+
initScreens(0, 0, 320, 200);
_screenEffectFlag = 1;
unkVirtScreen4(129);
@@ -165,21 +163,19 @@ bool Scumm::loadState(int slot, bool compat) {
initScreens(0, sb, 320, sh);
_completeScreenRedraw = true;
- setDirtyColors(0,255);
+ setDirtyColors(0, 255);
_lastCodePtr = NULL;
-
+
_drawObjectQueNr = 0;
_verbMouseOver = 0;
- if(_features & GF_AFTER_V7)
+ if (_features & GF_AFTER_V7)
cameraMoved();
initBGBuffers();
- CHECK_HEAP
-
- debug(1,"State loaded from '%s'", filename);
+ CHECK_HEAP debug(1, "State loaded from '%s'", filename);
pauseSounds(false);
@@ -187,62 +183,65 @@ bool Scumm::loadState(int slot, bool compat) {
return true;
}
-void Scumm::makeSavegameName(char *out, int slot, bool compatible) {
+void Scumm::makeSavegameName(char *out, int slot, bool compatible)
+{
#ifndef _WIN32_WCE
- #if !defined(__APPLE__CW)
+#if !defined(__APPLE__CW)
const char *dir = getenv("SCUMMVM_SAVEPATH");
- if (dir==NULL) dir="";
- #else
+ if (dir == NULL)
+ dir = "";
+#else
const char *dir = "";
- #endif
+#endif
/* snprintf should be used here, but it's not portable enough */
- sprintf(out, "%s%s.%c%.2d", dir, _exe_name, compatible ? 'c': 's', slot);
+ sprintf(out, "%s%s.%c%.2d", dir, _exe_name, compatible ? 'c' : 's', slot);
#else
- sprintf(out, "%s%s.%c%.2d", _savegame_dir, _exe_name, compatible ? 'c': 's', slot);
+ sprintf(out, "%s%s.%c%.2d", _savegame_dir, _exe_name,
+ compatible ? 'c' : 's', slot);
#endif
}
-bool Scumm::getSavegameName(int slot, char *desc) {
+bool Scumm::getSavegameName(int slot, char *desc)
+{
char filename[256];
SerializerStream out;
SaveGameHeader hdr;
int len;
makeSavegameName(filename, slot, false);
- if (!out.fopen(filename,"rb")) {
- strcpy(desc,"");
+ if (!out.fopen(filename, "rb")) {
+ strcpy(desc, "");
return false;
}
len = out.fread(&hdr, sizeof(hdr), 1);
out.fclose();
- if (len!=1 || hdr.type != MKID('SCVM')) {
+ if (len != 1 || hdr.type != MKID('SCVM')) {
strcpy(desc, "Invalid savegame");
return false;
}
-
#ifdef _MANAGE_OLD_SAVE
if (hdr.ver != VER_V8 && hdr.ver != VER_V7) {
#else
- if (hdr.ver != CURRENT_VER) {
+ if (hdr.ver != CURRENT_VER) {
#endif
strcpy(desc, "Invalid version");
return false;
}
-
+
memcpy(desc, hdr.name, sizeof(hdr.name));
- desc[sizeof(hdr.name)-1] = 0;
+ desc[sizeof(hdr.name) - 1] = 0;
return true;
}
@@ -252,339 +251,340 @@ bool Scumm::getSavegameName(int slot, char *desc) {
#define MKARRAY(type,item,saveas,num) {OFFS(type,item),128|saveas,SIZE(type,item)}, {num,0,0}
#define MKEND() {0xFFFF,0xFF,0xFF}
-void Scumm::saveOrLoad(Serializer *s) {
+void Scumm::saveOrLoad(Serializer * s)
+{
const SaveLoadEntry objectEntries[] = {
- MKLINE(ObjectData,offs_obim_to_room,sleUint32),
- MKLINE(ObjectData,offs_obcd_to_room,sleUint32),
- MKLINE(ObjectData,walk_x,sleUint16),
- MKLINE(ObjectData,walk_y,sleUint16),
- MKLINE(ObjectData,obj_nr,sleUint16),
- MKLINE(ObjectData,x_pos,sleInt16),
- MKLINE(ObjectData,y_pos,sleInt16),
- MKLINE(ObjectData,width,sleUint16),
- MKLINE(ObjectData,height,sleUint16),
- MKLINE(ObjectData,actordir,sleByte),
- MKLINE(ObjectData,parentstate,sleByte),
- MKLINE(ObjectData,parent,sleByte),
- MKLINE(ObjectData,state,sleByte),
- MKLINE(ObjectData,fl_object_index,sleByte),
+ MKLINE(ObjectData, offs_obim_to_room, sleUint32),
+ MKLINE(ObjectData, offs_obcd_to_room, sleUint32),
+ MKLINE(ObjectData, walk_x, sleUint16),
+ MKLINE(ObjectData, walk_y, sleUint16),
+ MKLINE(ObjectData, obj_nr, sleUint16),
+ MKLINE(ObjectData, x_pos, sleInt16),
+ MKLINE(ObjectData, y_pos, sleInt16),
+ MKLINE(ObjectData, width, sleUint16),
+ MKLINE(ObjectData, height, sleUint16),
+ MKLINE(ObjectData, actordir, sleByte),
+ MKLINE(ObjectData, parentstate, sleByte),
+ MKLINE(ObjectData, parent, sleByte),
+ MKLINE(ObjectData, state, sleByte),
+ MKLINE(ObjectData, fl_object_index, sleByte),
MKEND()
};
const SaveLoadEntry actorEntries[] = {
- MKLINE(Actor,x,sleInt16),
- MKLINE(Actor,y,sleInt16),
- MKLINE(Actor,top,sleInt16),
- MKLINE(Actor,bottom,sleInt16),
- MKLINE(Actor,elevation,sleInt16),
- MKLINE(Actor,width,sleUint16),
- MKLINE(Actor,facing,sleUint16),
- MKLINE(Actor,costume,sleUint16),
- MKLINE(Actor,room,sleByte),
- MKLINE(Actor,talkColor,sleByte),
- MKLINE(Actor,scalex,sleByte),
- MKLINE(Actor,scaley,sleByte),
- MKLINE(Actor,charset,sleByte),
- MKARRAY(Actor,sound[0],sleByte, 8),
- MKARRAY(Actor,animVariable[0],sleUint16, 8),
- MKLINE(Actor,newDirection,sleUint16),
- MKLINE(Actor,moving,sleByte),
- MKLINE(Actor,ignoreBoxes,sleByte),
- MKLINE(Actor,forceClip,sleByte),
- MKLINE(Actor,initFrame,sleByte),
- MKLINE(Actor,walkFrame,sleByte),
- MKLINE(Actor,standFrame,sleByte),
- MKLINE(Actor,talkFrame1,sleByte),
- MKLINE(Actor,talkFrame2,sleByte),
- MKLINE(Actor,speedx,sleUint16),
- MKLINE(Actor,speedy,sleUint16),
- MKLINE(Actor,cost.animCounter1,sleUint16),
- MKLINE(Actor,cost.animCounter2,sleByte),
- MKARRAY(Actor,palette[0],sleByte,64),
- MKLINE(Actor,mask,sleByte),
- MKLINE(Actor,shadow_mode,sleByte),
- MKLINE(Actor,visible,sleByte),
- MKLINE(Actor,frame,sleByte),
- MKLINE(Actor,animSpeed,sleByte),
- MKLINE(Actor,animProgress,sleByte),
- MKLINE(Actor,walkbox,sleByte),
- MKLINE(Actor,needRedraw,sleByte),
- MKLINE(Actor,needBgReset,sleByte),
- MKLINE(Actor,costumeNeedsInit,sleByte),
-
- MKLINE(Actor,new_1,sleInt16),
- MKLINE(Actor,new_2,sleInt16),
- MKLINE(Actor,new_3,sleByte),
-
- MKLINE(Actor,layer,sleByte),
-
- MKLINE(Actor,talk_script,sleUint16),
- MKLINE(Actor,walk_script,sleUint16),
-
- MKLINE(Actor,walkdata.destx,sleInt16),
- MKLINE(Actor,walkdata.desty,sleInt16),
- MKLINE(Actor,walkdata.destbox,sleByte),
- MKLINE(Actor,walkdata.destdir,sleUint16),
- MKLINE(Actor,walkdata.curbox,sleByte),
- MKLINE(Actor,walkdata.x,sleInt16),
- MKLINE(Actor,walkdata.y,sleInt16),
- MKLINE(Actor,walkdata.newx,sleInt16),
- MKLINE(Actor,walkdata.newy,sleInt16),
- MKLINE(Actor,walkdata.XYFactor,sleInt32),
- MKLINE(Actor,walkdata.YXFactor,sleInt32),
- MKLINE(Actor,walkdata.xfrac,sleUint16),
- MKLINE(Actor,walkdata.yfrac,sleUint16),
-
- MKARRAY(Actor,cost.active[0],sleByte,16),
- MKLINE(Actor,cost.stopped,sleUint16),
- MKARRAY(Actor,cost.curpos[0],sleUint16,16),
- MKARRAY(Actor,cost.start[0],sleUint16,16),
- MKARRAY(Actor,cost.end[0],sleUint16,16),
- MKARRAY(Actor,cost.frame[0],sleUint16,16),
+ MKLINE(Actor, x, sleInt16),
+ MKLINE(Actor, y, sleInt16),
+ MKLINE(Actor, top, sleInt16),
+ MKLINE(Actor, bottom, sleInt16),
+ MKLINE(Actor, elevation, sleInt16),
+ MKLINE(Actor, width, sleUint16),
+ MKLINE(Actor, facing, sleUint16),
+ MKLINE(Actor, costume, sleUint16),
+ MKLINE(Actor, room, sleByte),
+ MKLINE(Actor, talkColor, sleByte),
+ MKLINE(Actor, scalex, sleByte),
+ MKLINE(Actor, scaley, sleByte),
+ MKLINE(Actor, charset, sleByte),
+ MKARRAY(Actor, sound[0], sleByte, 8),
+ MKARRAY(Actor, animVariable[0], sleUint16, 8),
+ MKLINE(Actor, newDirection, sleUint16),
+ MKLINE(Actor, moving, sleByte),
+ MKLINE(Actor, ignoreBoxes, sleByte),
+ MKLINE(Actor, forceClip, sleByte),
+ MKLINE(Actor, initFrame, sleByte),
+ MKLINE(Actor, walkFrame, sleByte),
+ MKLINE(Actor, standFrame, sleByte),
+ MKLINE(Actor, talkFrame1, sleByte),
+ MKLINE(Actor, talkFrame2, sleByte),
+ MKLINE(Actor, speedx, sleUint16),
+ MKLINE(Actor, speedy, sleUint16),
+ MKLINE(Actor, cost.animCounter1, sleUint16),
+ MKLINE(Actor, cost.animCounter2, sleByte),
+ MKARRAY(Actor, palette[0], sleByte, 64),
+ MKLINE(Actor, mask, sleByte),
+ MKLINE(Actor, shadow_mode, sleByte),
+ MKLINE(Actor, visible, sleByte),
+ MKLINE(Actor, frame, sleByte),
+ MKLINE(Actor, animSpeed, sleByte),
+ MKLINE(Actor, animProgress, sleByte),
+ MKLINE(Actor, walkbox, sleByte),
+ MKLINE(Actor, needRedraw, sleByte),
+ MKLINE(Actor, needBgReset, sleByte),
+ MKLINE(Actor, costumeNeedsInit, sleByte),
+
+ MKLINE(Actor, new_1, sleInt16),
+ MKLINE(Actor, new_2, sleInt16),
+ MKLINE(Actor, new_3, sleByte),
+
+ MKLINE(Actor, layer, sleByte),
+
+ MKLINE(Actor, talk_script, sleUint16),
+ MKLINE(Actor, walk_script, sleUint16),
+
+ MKLINE(Actor, walkdata.destx, sleInt16),
+ MKLINE(Actor, walkdata.desty, sleInt16),
+ MKLINE(Actor, walkdata.destbox, sleByte),
+ MKLINE(Actor, walkdata.destdir, sleUint16),
+ MKLINE(Actor, walkdata.curbox, sleByte),
+ MKLINE(Actor, walkdata.x, sleInt16),
+ MKLINE(Actor, walkdata.y, sleInt16),
+ MKLINE(Actor, walkdata.newx, sleInt16),
+ MKLINE(Actor, walkdata.newy, sleInt16),
+ MKLINE(Actor, walkdata.XYFactor, sleInt32),
+ MKLINE(Actor, walkdata.YXFactor, sleInt32),
+ MKLINE(Actor, walkdata.xfrac, sleUint16),
+ MKLINE(Actor, walkdata.yfrac, sleUint16),
+
+ MKARRAY(Actor, cost.active[0], sleByte, 16),
+ MKLINE(Actor, cost.stopped, sleUint16),
+ MKARRAY(Actor, cost.curpos[0], sleUint16, 16),
+ MKARRAY(Actor, cost.start[0], sleUint16, 16),
+ MKARRAY(Actor, cost.end[0], sleUint16, 16),
+ MKARRAY(Actor, cost.frame[0], sleUint16, 16),
MKEND()
};
const SaveLoadEntry verbEntries[] = {
- MKLINE(VerbSlot,x,sleInt16),
- MKLINE(VerbSlot,y,sleInt16),
- MKLINE(VerbSlot,right,sleInt16),
- MKLINE(VerbSlot,bottom,sleInt16),
- MKLINE(VerbSlot,oldleft,sleInt16),
- MKLINE(VerbSlot,oldtop,sleInt16),
- MKLINE(VerbSlot,oldright,sleInt16),
- MKLINE(VerbSlot,oldbottom,sleInt16),
- MKLINE(VerbSlot,verbid,sleByte),
- MKLINE(VerbSlot,color,sleByte),
- MKLINE(VerbSlot,hicolor,sleByte),
- MKLINE(VerbSlot,dimcolor,sleByte),
- MKLINE(VerbSlot,bkcolor,sleByte),
- MKLINE(VerbSlot,type,sleByte),
- MKLINE(VerbSlot,charset_nr,sleByte),
- MKLINE(VerbSlot,curmode,sleByte),
- MKLINE(VerbSlot,saveid,sleByte),
- MKLINE(VerbSlot,key,sleByte),
- MKLINE(VerbSlot,center,sleByte),
- MKLINE(VerbSlot,field_1B,sleByte),
- MKLINE(VerbSlot,imgindex,sleUint16),
+ MKLINE(VerbSlot, x, sleInt16),
+ MKLINE(VerbSlot, y, sleInt16),
+ MKLINE(VerbSlot, right, sleInt16),
+ MKLINE(VerbSlot, bottom, sleInt16),
+ MKLINE(VerbSlot, oldleft, sleInt16),
+ MKLINE(VerbSlot, oldtop, sleInt16),
+ MKLINE(VerbSlot, oldright, sleInt16),
+ MKLINE(VerbSlot, oldbottom, sleInt16),
+ MKLINE(VerbSlot, verbid, sleByte),
+ MKLINE(VerbSlot, color, sleByte),
+ MKLINE(VerbSlot, hicolor, sleByte),
+ MKLINE(VerbSlot, dimcolor, sleByte),
+ MKLINE(VerbSlot, bkcolor, sleByte),
+ MKLINE(VerbSlot, type, sleByte),
+ MKLINE(VerbSlot, charset_nr, sleByte),
+ MKLINE(VerbSlot, curmode, sleByte),
+ MKLINE(VerbSlot, saveid, sleByte),
+ MKLINE(VerbSlot, key, sleByte),
+ MKLINE(VerbSlot, center, sleByte),
+ MKLINE(VerbSlot, field_1B, sleByte),
+ MKLINE(VerbSlot, imgindex, sleUint16),
MKEND()
};
-
+
#ifdef _MANAGE_OLD_SAVE
- const SaveLoadEntry mainEntries1[] = {
- MKLINE(Scumm,_scrWidth,sleUint16),
- MKLINE(Scumm,_scrHeight,sleUint16),
- MKLINE(Scumm,_ENCD_offs,sleUint32),
- MKLINE(Scumm,_EXCD_offs,sleUint32),
- MKLINE(Scumm,_IM00_offs,sleUint32),
- MKLINE(Scumm,_CLUT_offs,sleUint32),
- MKLINE(Scumm,_EPAL_offs,sleUint32),
- MKLINE(Scumm,_PALS_offs,sleUint32),
- MKLINE(Scumm,_curPalIndex,sleByte),
- MKLINE(Scumm,_currentRoom,sleByte),
- MKLINE(Scumm,_roomResource,sleByte),
- MKLINE(Scumm,_numObjectsInRoom,sleByte),
- MKLINE(Scumm,_currentScript,sleByte),
- MKARRAY(Scumm,_localScriptList[0],sleUint32,NUM_LOCALSCRIPT),
- MKARRAY(Scumm,vm.localvar[0][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),
- MKLINE(Scumm,_curExecScript,sleUint16),
+ const SaveLoadEntry mainEntries1[] = {
+ MKLINE(Scumm, _scrWidth, sleUint16),
+ MKLINE(Scumm, _scrHeight, sleUint16),
+ MKLINE(Scumm, _ENCD_offs, sleUint32),
+ MKLINE(Scumm, _EXCD_offs, sleUint32),
+ MKLINE(Scumm, _IM00_offs, sleUint32),
+ MKLINE(Scumm, _CLUT_offs, sleUint32),
+ MKLINE(Scumm, _EPAL_offs, sleUint32),
+ MKLINE(Scumm, _PALS_offs, sleUint32),
+ MKLINE(Scumm, _curPalIndex, sleByte),
+ MKLINE(Scumm, _currentRoom, sleByte),
+ MKLINE(Scumm, _roomResource, sleByte),
+ MKLINE(Scumm, _numObjectsInRoom, sleByte),
+ MKLINE(Scumm, _currentScript, sleByte),
+ MKARRAY(Scumm, _localScriptList[0], sleUint32, NUM_LOCALSCRIPT),
+ MKARRAY(Scumm, vm.localvar[0][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),
+ MKLINE(Scumm, _curExecScript, sleUint16),
MKEND()
};
const SaveLoadEntry mainEntries2V8[] = {
- MKLINE(Scumm,camera._dest.x,sleInt16),
- MKLINE(Scumm,camera._dest.y,sleInt16),
- MKLINE(Scumm,camera._cur.x,sleInt16),
- MKLINE(Scumm,camera._cur.y,sleInt16),
- MKLINE(Scumm,camera._last.x,sleInt16),
- MKLINE(Scumm,camera._last.y,sleInt16),
- MKLINE(Scumm,camera._accel.x,sleInt16),
- MKLINE(Scumm,camera._accel.y,sleInt16),
- MKLINE(Scumm,_screenStartStrip,sleInt16),
- MKLINE(Scumm,_screenEndStrip,sleInt16),
- MKLINE(Scumm,camera._mode,sleByte),
- MKLINE(Scumm,camera._follows,sleByte),
- MKLINE(Scumm,camera._leftTrigger,sleInt16),
- MKLINE(Scumm,camera._rightTrigger,sleInt16),
- MKLINE(Scumm,camera._movingToActor,sleUint16),
+ MKLINE(Scumm, camera._dest.x, sleInt16),
+ MKLINE(Scumm, camera._dest.y, sleInt16),
+ MKLINE(Scumm, camera._cur.x, sleInt16),
+ MKLINE(Scumm, camera._cur.y, sleInt16),
+ MKLINE(Scumm, camera._last.x, sleInt16),
+ MKLINE(Scumm, camera._last.y, sleInt16),
+ MKLINE(Scumm, camera._accel.x, sleInt16),
+ MKLINE(Scumm, camera._accel.y, sleInt16),
+ MKLINE(Scumm, _screenStartStrip, sleInt16),
+ MKLINE(Scumm, _screenEndStrip, sleInt16),
+ MKLINE(Scumm, camera._mode, sleByte),
+ MKLINE(Scumm, camera._follows, sleByte),
+ MKLINE(Scumm, camera._leftTrigger, sleInt16),
+ MKLINE(Scumm, camera._rightTrigger, sleInt16),
+ MKLINE(Scumm, camera._movingToActor, sleUint16),
MKEND()
};
const SaveLoadEntry mainEntries2V7[] = {
- MKLINE(Scumm,camera._dest.x,sleInt16),
- MKLINE(Scumm,camera._cur.x,sleInt16),
- MKLINE(Scumm,camera._last.x,sleInt16),
- MKLINE(Scumm,_screenStartStrip,sleInt16),
- MKLINE(Scumm,_screenEndStrip,sleInt16),
- MKLINE(Scumm,camera._mode,sleByte),
- MKLINE(Scumm,camera._follows,sleByte),
- MKLINE(Scumm,camera._leftTrigger,sleInt16),
- MKLINE(Scumm,camera._rightTrigger,sleInt16),
- MKLINE(Scumm,camera._movingToActor,sleUint16),
+ MKLINE(Scumm, camera._dest.x, sleInt16),
+ MKLINE(Scumm, camera._cur.x, sleInt16),
+ MKLINE(Scumm, camera._last.x, sleInt16),
+ MKLINE(Scumm, _screenStartStrip, sleInt16),
+ MKLINE(Scumm, _screenEndStrip, sleInt16),
+ MKLINE(Scumm, camera._mode, sleByte),
+ MKLINE(Scumm, camera._follows, sleByte),
+ MKLINE(Scumm, camera._leftTrigger, sleInt16),
+ MKLINE(Scumm, camera._rightTrigger, sleInt16),
+ MKLINE(Scumm, camera._movingToActor, sleUint16),
MKEND()
};
const SaveLoadEntry mainEntries3[] = {
-
- MKLINE(Scumm,_actorToPrintStrFor,sleByte),
- MKLINE(Scumm,_charsetColor,sleByte),
+
+ MKLINE(Scumm, _actorToPrintStrFor, sleByte),
+ MKLINE(Scumm, _charsetColor, sleByte),
/* XXX Convert into word next time format changes */
- MKLINE(Scumm,charset._bufPos,sleByte),
- MKLINE(Scumm,_haveMsg,sleByte),
- MKLINE(Scumm,_useTalkAnims,sleByte),
-
- MKLINE(Scumm,_talkDelay,sleInt16),
- MKLINE(Scumm,_defaultTalkDelay,sleInt16),
- MKLINE(Scumm,_numInMsgStack,sleInt16),
- MKLINE(Scumm,_sentenceNum,sleByte),
-
- MKLINE(Scumm,vm.cutSceneStackPointer,sleByte),
- MKARRAY(Scumm,vm.cutScenePtr[0],sleUint32,5),
- MKARRAY(Scumm,vm.cutSceneScript[0],sleByte,5),
- MKARRAY(Scumm,vm.cutSceneData[0],sleInt16,5),
- MKLINE(Scumm,vm.cutSceneScriptIndex,sleInt16),
-
+ MKLINE(Scumm, charset._bufPos, sleByte),
+ MKLINE(Scumm, _haveMsg, sleByte),
+ MKLINE(Scumm, _useTalkAnims, sleByte),
+
+ MKLINE(Scumm, _talkDelay, sleInt16),
+ MKLINE(Scumm, _defaultTalkDelay, sleInt16),
+ MKLINE(Scumm, _numInMsgStack, sleInt16),
+ MKLINE(Scumm, _sentenceNum, sleByte),
+
+ MKLINE(Scumm, vm.cutSceneStackPointer, sleByte),
+ MKARRAY(Scumm, vm.cutScenePtr[0], sleUint32, 5),
+ MKARRAY(Scumm, vm.cutSceneScript[0], sleByte, 5),
+ MKARRAY(Scumm, vm.cutSceneData[0], sleInt16, 5),
+ MKLINE(Scumm, vm.cutSceneScriptIndex, sleInt16),
+
/* nest */
- MKLINE(Scumm,_numNestedScripts,sleByte),
- MKLINE(Scumm,_userPut,sleByte),
- MKLINE(Scumm,_cursorState,sleByte),
- MKLINE(Scumm,gdi._cursorActive,sleByte),
- MKLINE(Scumm,gdi._currentCursor,sleByte),
-
- MKLINE(Scumm,_doEffect,sleByte),
- MKLINE(Scumm,_switchRoomEffect,sleByte),
- MKLINE(Scumm,_newEffect,sleByte),
- MKLINE(Scumm,_switchRoomEffect2,sleByte),
- MKLINE(Scumm,_BgNeedsRedraw,sleByte),
-
- MKARRAY(Scumm,gfxUsageBits[0],sleUint32,200),
- MKLINE(Scumm,gdi._transparency,sleByte),
- MKARRAY(Scumm,_currentPalette[0],sleByte,768),
+ MKLINE(Scumm, _numNestedScripts, sleByte),
+ MKLINE(Scumm, _userPut, sleByte),
+ MKLINE(Scumm, _cursorState, sleByte),
+ MKLINE(Scumm, gdi._cursorActive, sleByte),
+ MKLINE(Scumm, gdi._currentCursor, sleByte),
+
+ MKLINE(Scumm, _doEffect, sleByte),
+ MKLINE(Scumm, _switchRoomEffect, sleByte),
+ MKLINE(Scumm, _newEffect, sleByte),
+ MKLINE(Scumm, _switchRoomEffect2, sleByte),
+ MKLINE(Scumm, _BgNeedsRedraw, sleByte),
+
+ MKARRAY(Scumm, gfxUsageBits[0], sleUint32, 200),
+ MKLINE(Scumm, gdi._transparency, sleByte),
+ MKARRAY(Scumm, _currentPalette[0], sleByte, 768),
/* virtscr */
- MKARRAY(Scumm,charset._buffer[0],sleByte,256),
+ MKARRAY(Scumm, charset._buffer[0], sleByte, 256),
- MKLINE(Scumm,_egoPositioned,sleByte),
+ MKLINE(Scumm, _egoPositioned, sleByte),
- MKARRAY(Scumm,gdi._imgBufOffs[0],sleUint16,4),
- MKLINE(Scumm,gdi._numZBuffer,sleByte),
+ MKARRAY(Scumm, gdi._imgBufOffs[0], sleUint16, 4),
+ MKLINE(Scumm, gdi._numZBuffer, sleByte),
- MKLINE(Scumm,_screenEffectFlag,sleByte),
+ MKLINE(Scumm, _screenEffectFlag, sleByte),
- MKLINE(Scumm,_randSeed1,sleUint32),
- MKLINE(Scumm,_randSeed2,sleUint32),
+ MKLINE(Scumm, _randSeed1, sleUint32),
+ MKLINE(Scumm, _randSeed2, sleUint32),
/* XXX: next time the save game format changes,
* convert _shakeEnabled to boolean and add a _shakeFrame field */
- MKLINE(Scumm,_shakeEnabled,sleInt16),
+ MKLINE(Scumm, _shakeEnabled, sleInt16),
- MKLINE(Scumm,_keepText,sleByte),
+ MKLINE(Scumm, _keepText, sleByte),
- MKLINE(Scumm,_screenB,sleUint16),
- MKLINE(Scumm,_screenH,sleUint16),
+ MKLINE(Scumm, _screenB, sleUint16),
+ MKLINE(Scumm, _screenH, sleUint16),
MKEND()
};
#else
- const SaveLoadEntry mainEntries[] = {
- MKLINE(Scumm,_scrWidth,sleUint16),
- MKLINE(Scumm,_scrHeight,sleUint16),
- MKLINE(Scumm,_ENCD_offs,sleUint32),
- MKLINE(Scumm,_EXCD_offs,sleUint32),
- MKLINE(Scumm,_IM00_offs,sleUint32),
- MKLINE(Scumm,_CLUT_offs,sleUint32),
- MKLINE(Scumm,_EPAL_offs,sleUint32),
- MKLINE(Scumm,_PALS_offs,sleUint32),
- MKLINE(Scumm,_curPalIndex,sleByte),
- MKLINE(Scumm,_currentRoom,sleByte),
- MKLINE(Scumm,_roomResource,sleByte),
- MKLINE(Scumm,_numObjectsInRoom,sleByte),
- MKLINE(Scumm,_currentScript,sleByte),
- MKARRAY(Scumm,_localScriptList[0],sleUint32,NUM_LOCALSCRIPT),
- MKARRAY(Scumm,vm.localvar[0][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),
- MKLINE(Scumm,_curExecScript,sleUint16),
-
- MKLINE(Scumm,camera._dest.x,sleInt16),
- MKLINE(Scumm,camera._dest.y,sleInt16),
- MKLINE(Scumm,camera._cur.x,sleInt16),
- MKLINE(Scumm,camera._cur.y,sleInt16),
- MKLINE(Scumm,camera._last.x,sleInt16),
- MKLINE(Scumm,camera._last.y,sleInt16),
- MKLINE(Scumm,camera._accel.x,sleInt16),
- MKLINE(Scumm,camera._accel.y,sleInt16),
- MKLINE(Scumm,_screenStartStrip,sleInt16),
- MKLINE(Scumm,_screenEndStrip,sleInt16),
- MKLINE(Scumm,camera._mode,sleByte),
- MKLINE(Scumm,camera._follows,sleByte),
- MKLINE(Scumm,camera._leftTrigger,sleInt16),
- MKLINE(Scumm,camera._rightTrigger,sleInt16),
- MKLINE(Scumm,camera._movingToActor,sleUint16),
-
- MKLINE(Scumm,_actorToPrintStrFor,sleByte),
- MKLINE(Scumm,_charsetColor,sleByte),
+ const SaveLoadEntry mainEntries[] = {
+ MKLINE(Scumm, _scrWidth, sleUint16),
+ MKLINE(Scumm, _scrHeight, sleUint16),
+ MKLINE(Scumm, _ENCD_offs, sleUint32),
+ MKLINE(Scumm, _EXCD_offs, sleUint32),
+ MKLINE(Scumm, _IM00_offs, sleUint32),
+ MKLINE(Scumm, _CLUT_offs, sleUint32),
+ MKLINE(Scumm, _EPAL_offs, sleUint32),
+ MKLINE(Scumm, _PALS_offs, sleUint32),
+ MKLINE(Scumm, _curPalIndex, sleByte),
+ MKLINE(Scumm, _currentRoom, sleByte),
+ MKLINE(Scumm, _roomResource, sleByte),
+ MKLINE(Scumm, _numObjectsInRoom, sleByte),
+ MKLINE(Scumm, _currentScript, sleByte),
+ MKARRAY(Scumm, _localScriptList[0], sleUint32, NUM_LOCALSCRIPT),
+ MKARRAY(Scumm, vm.localvar[0][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),
+ MKLINE(Scumm, _curExecScript, sleUint16),
+
+ MKLINE(Scumm, camera._dest.x, sleInt16),
+ MKLINE(Scumm, camera._dest.y, sleInt16),
+ MKLINE(Scumm, camera._cur.x, sleInt16),
+ MKLINE(Scumm, camera._cur.y, sleInt16),
+ MKLINE(Scumm, camera._last.x, sleInt16),
+ MKLINE(Scumm, camera._last.y, sleInt16),
+ MKLINE(Scumm, camera._accel.x, sleInt16),
+ MKLINE(Scumm, camera._accel.y, sleInt16),
+ MKLINE(Scumm, _screenStartStrip, sleInt16),
+ MKLINE(Scumm, _screenEndStrip, sleInt16),
+ MKLINE(Scumm, camera._mode, sleByte),
+ MKLINE(Scumm, camera._follows, sleByte),
+ MKLINE(Scumm, camera._leftTrigger, sleInt16),
+ MKLINE(Scumm, camera._rightTrigger, sleInt16),
+ MKLINE(Scumm, camera._movingToActor, sleUint16),
+
+ MKLINE(Scumm, _actorToPrintStrFor, sleByte),
+ MKLINE(Scumm, _charsetColor, sleByte),
/* XXX Convert into word next time format changes */
- MKLINE(Scumm,charset._bufPos,sleByte),
- MKLINE(Scumm,_haveMsg,sleByte),
- MKLINE(Scumm,_useTalkAnims,sleByte),
-
- MKLINE(Scumm,_talkDelay,sleInt16),
- MKLINE(Scumm,_defaultTalkDelay,sleInt16),
- MKLINE(Scumm,_numInMsgStack,sleInt16),
- MKLINE(Scumm,_sentenceNum,sleByte),
-
- MKLINE(Scumm,vm.cutSceneStackPointer,sleByte),
- MKARRAY(Scumm,vm.cutScenePtr[0],sleUint32,5),
- MKARRAY(Scumm,vm.cutSceneScript[0],sleByte,5),
- MKARRAY(Scumm,vm.cutSceneData[0],sleInt16,5),
- MKLINE(Scumm,vm.cutSceneScriptIndex,sleInt16),
-
+ MKLINE(Scumm, charset._bufPos, sleByte),
+ MKLINE(Scumm, _haveMsg, sleByte),
+ MKLINE(Scumm, _useTalkAnims, sleByte),
+
+ MKLINE(Scumm, _talkDelay, sleInt16),
+ MKLINE(Scumm, _defaultTalkDelay, sleInt16),
+ MKLINE(Scumm, _numInMsgStack, sleInt16),
+ MKLINE(Scumm, _sentenceNum, sleByte),
+
+ MKLINE(Scumm, vm.cutSceneStackPointer, sleByte),
+ MKARRAY(Scumm, vm.cutScenePtr[0], sleUint32, 5),
+ MKARRAY(Scumm, vm.cutSceneScript[0], sleByte, 5),
+ MKARRAY(Scumm, vm.cutSceneData[0], sleInt16, 5),
+ MKLINE(Scumm, vm.cutSceneScriptIndex, sleInt16),
+
/* nest */
- MKLINE(Scumm,_numNestedScripts,sleByte),
- MKLINE(Scumm,_userPut,sleByte),
- MKLINE(Scumm,_cursorState,sleByte),
- MKLINE(Scumm,gdi._cursorActive,sleByte),
- MKLINE(Scumm,gdi._currentCursor,sleByte),
-
- MKLINE(Scumm,_doEffect,sleByte),
- MKLINE(Scumm,_switchRoomEffect,sleByte),
- MKLINE(Scumm,_newEffect,sleByte),
- MKLINE(Scumm,_switchRoomEffect2,sleByte),
- MKLINE(Scumm,_BgNeedsRedraw,sleByte),
-
- MKARRAY(Scumm,gfxUsageBits[0],sleUint32,200),
- MKLINE(Scumm,gdi._transparency,sleByte),
- MKARRAY(Scumm,_currentPalette[0],sleByte,768),
+ MKLINE(Scumm, _numNestedScripts, sleByte),
+ MKLINE(Scumm, _userPut, sleByte),
+ MKLINE(Scumm, _cursorState, sleByte),
+ MKLINE(Scumm, gdi._cursorActive, sleByte),
+ MKLINE(Scumm, gdi._currentCursor, sleByte),
+
+ MKLINE(Scumm, _doEffect, sleByte),
+ MKLINE(Scumm, _switchRoomEffect, sleByte),
+ MKLINE(Scumm, _newEffect, sleByte),
+ MKLINE(Scumm, _switchRoomEffect2, sleByte),
+ MKLINE(Scumm, _BgNeedsRedraw, sleByte),
+
+ MKARRAY(Scumm, gfxUsageBits[0], sleUint32, 200),
+ MKLINE(Scumm, gdi._transparency, sleByte),
+ MKARRAY(Scumm, _currentPalette[0], sleByte, 768),
/* virtscr */
- MKARRAY(Scumm,charset._buffer[0],sleByte,256),
+ MKARRAY(Scumm, charset._buffer[0], sleByte, 256),
- MKLINE(Scumm,_egoPositioned,sleByte),
+ MKLINE(Scumm, _egoPositioned, sleByte),
- MKARRAY(Scumm,gdi._imgBufOffs[0],sleUint16,4),
- MKLINE(Scumm,gdi._numZBuffer,sleByte),
+ MKARRAY(Scumm, gdi._imgBufOffs[0], sleUint16, 4),
+ MKLINE(Scumm, gdi._numZBuffer, sleByte),
- MKLINE(Scumm,_screenEffectFlag,sleByte),
+ MKLINE(Scumm, _screenEffectFlag, sleByte),
- MKLINE(Scumm,_randSeed1,sleUint32),
- MKLINE(Scumm,_randSeed2,sleUint32),
+ MKLINE(Scumm, _randSeed1, sleUint32),
+ MKLINE(Scumm, _randSeed2, sleUint32),
/* XXX: next time the save game format changes,
* convert _shakeEnabled to boolean and add a _shakeFrame field */
- MKLINE(Scumm,_shakeEnabled,sleInt16),
+ MKLINE(Scumm, _shakeEnabled, sleInt16),
- MKLINE(Scumm,_keepText,sleByte),
+ MKLINE(Scumm, _keepText, sleByte),
- MKLINE(Scumm,_screenB,sleUint16),
- MKLINE(Scumm,_screenH,sleUint16),
+ MKLINE(Scumm, _screenB, sleUint16),
+ MKLINE(Scumm, _screenH, sleUint16),
MKEND()
};
@@ -592,79 +592,81 @@ void Scumm::saveOrLoad(Serializer *s) {
#endif
const SaveLoadEntry scriptSlotEntries[] = {
- MKLINE(ScriptSlot,offs,sleUint32),
- MKLINE(ScriptSlot,delay,sleInt32),
- MKLINE(ScriptSlot,number,sleUint16),
- MKLINE(ScriptSlot,newfield,sleUint16),
- MKLINE(ScriptSlot,status,sleByte),
- MKLINE(ScriptSlot,where,sleByte),
- MKLINE(ScriptSlot,unk1,sleByte),
- MKLINE(ScriptSlot,unk2,sleByte),
- MKLINE(ScriptSlot,freezeCount,sleByte),
- MKLINE(ScriptSlot,didexec,sleByte),
- MKLINE(ScriptSlot,cutsceneOverride,sleByte),
- MKLINE(ScriptSlot,unk5,sleByte),
+ MKLINE(ScriptSlot, offs, sleUint32),
+ MKLINE(ScriptSlot, delay, sleInt32),
+ MKLINE(ScriptSlot, number, sleUint16),
+ MKLINE(ScriptSlot, newfield, sleUint16),
+ MKLINE(ScriptSlot, status, sleByte),
+ MKLINE(ScriptSlot, where, sleByte),
+ MKLINE(ScriptSlot, unk1, sleByte),
+ MKLINE(ScriptSlot, unk2, sleByte),
+ MKLINE(ScriptSlot, freezeCount, sleByte),
+ MKLINE(ScriptSlot, didexec, sleByte),
+ MKLINE(ScriptSlot, cutsceneOverride, sleByte),
+ MKLINE(ScriptSlot, unk5, sleByte),
MKEND()
};
const SaveLoadEntry nestedScriptEntries[] = {
- MKLINE(NestedScript,number,sleUint16),
- MKLINE(NestedScript,where,sleByte),
- MKLINE(NestedScript,slot,sleByte),
+ MKLINE(NestedScript, number, sleUint16),
+ MKLINE(NestedScript, where, sleByte),
+ MKLINE(NestedScript, slot, sleByte),
MKEND()
};
const SaveLoadEntry sentenceTabEntries[] = {
- MKLINE(SentenceTab,unk5,sleUint8),
- MKLINE(SentenceTab,unk2,sleUint8),
- MKLINE(SentenceTab,unk4,sleUint16),
- MKLINE(SentenceTab,unk3,sleUint16),
- MKLINE(SentenceTab,unk,sleUint8),
+ MKLINE(SentenceTab, unk5, sleUint8),
+ MKLINE(SentenceTab, unk2, sleUint8),
+ MKLINE(SentenceTab, unk4, sleUint16),
+ MKLINE(SentenceTab, unk3, sleUint16),
+ MKLINE(SentenceTab, unk, sleUint8),
MKEND()
};
const SaveLoadEntry stringTabEntries[] = {
- MKLINE(StringTab,xpos,sleInt16),
- MKLINE(StringTab,t_xpos,sleInt16),
- MKLINE(StringTab,ypos,sleInt16),
- MKLINE(StringTab,t_ypos,sleInt16),
- MKLINE(StringTab,right,sleInt16),
- MKLINE(StringTab,t_right,sleInt16),
- MKLINE(StringTab,color,sleInt8),
- MKLINE(StringTab,t_color,sleInt8),
- MKLINE(StringTab,charset,sleInt8),
- MKLINE(StringTab,t_charset,sleInt8),
- MKLINE(StringTab,center,sleByte),
- MKLINE(StringTab,t_center,sleByte),
- MKLINE(StringTab,overhead,sleByte),
- MKLINE(StringTab,t_overhead,sleByte),
- MKLINE(StringTab,no_talk_anim,sleByte),
- MKLINE(StringTab,t_no_talk_anim,sleByte),
+ MKLINE(StringTab, xpos, sleInt16),
+ MKLINE(StringTab, t_xpos, sleInt16),
+ MKLINE(StringTab, ypos, sleInt16),
+ MKLINE(StringTab, t_ypos, sleInt16),
+ MKLINE(StringTab, right, sleInt16),
+ MKLINE(StringTab, t_right, sleInt16),
+ MKLINE(StringTab, color, sleInt8),
+ MKLINE(StringTab, t_color, sleInt8),
+ MKLINE(StringTab, charset, sleInt8),
+ MKLINE(StringTab, t_charset, sleInt8),
+ MKLINE(StringTab, center, sleByte),
+ MKLINE(StringTab, t_center, sleByte),
+ MKLINE(StringTab, overhead, sleByte),
+ MKLINE(StringTab, t_overhead, sleByte),
+ MKLINE(StringTab, no_talk_anim, sleByte),
+ MKLINE(StringTab, t_no_talk_anim, sleByte),
MKEND()
};
const SaveLoadEntry colorCycleEntries[] = {
- MKLINE(ColorCycle,delay,sleUint16),
- MKLINE(ColorCycle,counter,sleUint16),
- MKLINE(ColorCycle,flags,sleUint16),
- MKLINE(ColorCycle,start,sleByte),
- MKLINE(ColorCycle,end,sleByte),
+ MKLINE(ColorCycle, delay, sleUint16),
+ MKLINE(ColorCycle, counter, sleUint16),
+ MKLINE(ColorCycle, flags, sleUint16),
+ MKLINE(ColorCycle, start, sleByte),
+ MKLINE(ColorCycle, end, sleByte),
MKEND()
};
- int i,j;
+ int i, j;
int var120Backup;
int var98Backup;
-
+
#ifdef _MANAGE_OLD_SAVE
s->saveLoadEntries(this, mainEntries1);
- s->saveLoadEntries(this, (_current_version == VER_V8 ? mainEntries2V8 : mainEntries2V7));
+ s->saveLoadEntries(this,
+ (_current_version ==
+ VER_V8 ? mainEntries2V8 : mainEntries2V7));
s->saveLoadEntries(this, mainEntries3);
#else
- s->saveLoadEntries(this,mainEntries);
+ s->saveLoadEntries(this, mainEntries);
#endif
@@ -672,54 +674,62 @@ void Scumm::saveOrLoad(Serializer *s) {
// Probably not necessary anymore with latest NUM_ACTORS values
- s->saveLoadArrayOf(actor, (_current_version == VER_V8 ? NUM_ACTORS : 13), sizeof(actor[0]), actorEntries);
+ s->saveLoadArrayOf(actor, (_current_version == VER_V8 ? NUM_ACTORS : 13),
+ sizeof(actor[0]), actorEntries);
#else
-
+
s->saveLoadArrayOf(actor, NUM_ACTORS, sizeof(actor[0]), actorEntries);
#endif
- s->saveLoadArrayOf(vm.slot, NUM_SCRIPT_SLOT, sizeof(vm.slot[0]), scriptSlotEntries);
- s->saveLoadArrayOf(_objs, _numLocalObjects, sizeof(_objs[0]), objectEntries);
+ s->saveLoadArrayOf(vm.slot, NUM_SCRIPT_SLOT, sizeof(vm.slot[0]),
+ scriptSlotEntries);
+ s->saveLoadArrayOf(_objs, _numLocalObjects, sizeof(_objs[0]),
+ objectEntries);
s->saveLoadArrayOf(_verbs, _numVerbs, sizeof(_verbs[0]), verbEntries);
s->saveLoadArrayOf(vm.nest, 16, sizeof(vm.nest[0]), nestedScriptEntries);
s->saveLoadArrayOf(sentence, 6, sizeof(sentence[0]), sentenceTabEntries);
s->saveLoadArrayOf(string, 6, sizeof(string[0]), stringTabEntries);
- s->saveLoadArrayOf(_colorCycle, 16, sizeof(_colorCycle[0]), colorCycleEntries);
-
- for (i=rtFirst; i<=rtLast; i++)
- if (res.mode[i]==0)
- for(j=1; j<res.num[i]; j++)
- saveLoadResource(s,i,j);
-
- s->saveLoadArrayOf(_objectOwnerTable, _numGlobalObjects, sizeof(_objectOwnerTable[0]), sleByte);
- s->saveLoadArrayOf(_objectStateTable, _numGlobalObjects, sizeof(_objectStateTable[0]), sleByte);
+ s->saveLoadArrayOf(_colorCycle, 16, sizeof(_colorCycle[0]),
+ colorCycleEntries);
+
+ for (i = rtFirst; i <= rtLast; i++)
+ if (res.mode[i] == 0)
+ for (j = 1; j < res.num[i]; j++)
+ saveLoadResource(s, i, j);
+
+ s->saveLoadArrayOf(_objectOwnerTable, _numGlobalObjects,
+ sizeof(_objectOwnerTable[0]), sleByte);
+ s->saveLoadArrayOf(_objectStateTable, _numGlobalObjects,
+ sizeof(_objectStateTable[0]), sleByte);
if (_objectRoomTable)
- s->saveLoadArrayOf(_objectRoomTable, _numGlobalObjects, sizeof(_objectRoomTable[0]), sleByte);
+ s->saveLoadArrayOf(_objectRoomTable, _numGlobalObjects,
+ sizeof(_objectRoomTable[0]), sleByte);
if (_shadowPaletteSize)
s->saveLoadArrayOf(_shadowPalette, _shadowPaletteSize, 1, sleByte);
- s->saveLoadArrayOf(_classData, _numGlobalObjects, sizeof(_classData[0]), sleUint32);
-
- var120Backup=_vars[120];
- var98Backup=_vars[98];
-
+ s->saveLoadArrayOf(_classData, _numGlobalObjects, sizeof(_classData[0]),
+ sleUint32);
+
+ var120Backup = _vars[120];
+ var98Backup = _vars[98];
+
s->saveLoadArrayOf(_vars, _numVariables, sizeof(_vars[0]), sleInt16);
- if(_gameId == GID_TENTACLE) // Maybe misplaced, but that's the main idea
- _vars[120]=var120Backup;
- if(_gameId == GID_INDY4)
- _vars[98]=var98Backup;;
-
- s->saveLoadArrayOf(_bitVars, _numBitVariables>>3, 1, sleByte);
+ if (_gameId == GID_TENTACLE) // Maybe misplaced, but that's the main idea
+ _vars[120] = var120Backup;
+ if (_gameId == GID_INDY4)
+ _vars[98] = var98Backup;;
+
+ s->saveLoadArrayOf(_bitVars, _numBitVariables >> 3, 1, sleByte);
/* Save or load a list of the locked objects */
if (s->isSaving()) {
- for (i=rtFirst; i<=rtLast; i++)
- for(j=1; j<res.num[i]; j++) {
- if (res.flags[i][j]&RF_LOCK) {
+ for (i = rtFirst; i <= rtLast; i++)
+ for (j = 1; j < res.num[i]; j++) {
+ if (res.flags[i][j] & RF_LOCK) {
s->saveByte(i);
s->saveWord(j);
}
@@ -733,31 +743,32 @@ void Scumm::saveOrLoad(Serializer *s) {
}
if (_soundEngine)
- ((SoundEngine*)_soundEngine)->save_or_load(s);
+ ((SoundEngine *)_soundEngine)->save_or_load(s);
}
-void Scumm::saveLoadResource(Serializer *ser, int type, int idx) {
+void Scumm::saveLoadResource(Serializer * ser, int type, int idx)
+{
byte *ptr;
uint32 size;
/* don't save/load these resource types */
- if (type==rtTemp || type==rtBuffer || res.mode[type])
+ if (type == rtTemp || type == rtBuffer || res.mode[type])
return;
if (ser->isSaving()) {
ptr = res.address[type][idx];
- if (ptr==NULL) {
+ if (ptr == NULL) {
ser->saveUint32(0);
return;
}
- size = ((MemBlkHeader*)ptr)->size;
+ size = ((MemBlkHeader *)ptr)->size;
ser->saveUint32(size);
- ser->saveLoadBytes(ptr+sizeof(MemBlkHeader),size);
+ ser->saveLoadBytes(ptr + sizeof(MemBlkHeader), size);
- if (type==rtInventory) {
+ if (type == rtInventory) {
ser->saveWord(_inventory[idx]);
}
} else {
@@ -765,14 +776,15 @@ void Scumm::saveLoadResource(Serializer *ser, int type, int idx) {
if (size) {
createResource(type, idx, size);
ser->saveLoadBytes(getResourceAddress(type, idx), size);
- if (type==rtInventory) {
+ if (type == rtInventory) {
_inventory[idx] = ser->loadWord();
}
}
}
}
-void Serializer::saveLoadBytes(void *b, int len) {
+void Serializer::saveLoadBytes(void *b, int len)
+{
if (_saveOrLoad)
_saveLoadStream.fwrite(b, 1, len);
else
@@ -783,7 +795,8 @@ void Serializer::saveLoadBytes(void *b, int len) {
// Perhaps not necessary anymore with latest checks
-bool Serializer::checkEOFLoadStream() {
+bool Serializer::checkEOFLoadStream()
+{
if (!fseek(_saveLoadStream.out, 1, SEEK_CUR))
return true;
if (feof(_saveLoadStream.out))
@@ -795,91 +808,115 @@ bool Serializer::checkEOFLoadStream() {
#endif
-void Serializer::saveUint32(uint32 d) {
+void Serializer::saveUint32(uint32 d)
+{
uint32 e = FROM_LE_32(d);
- saveLoadBytes(&e,4);
+ saveLoadBytes(&e, 4);
}
-void Serializer::saveWord(uint16 d) {
+void Serializer::saveWord(uint16 d)
+{
uint16 e = FROM_LE_16(d);
- saveLoadBytes(&e,2);
+ saveLoadBytes(&e, 2);
}
-void Serializer::saveByte(byte b) {
- saveLoadBytes(&b,1);
+void Serializer::saveByte(byte b)
+{
+ saveLoadBytes(&b, 1);
}
-uint32 Serializer::loadUint32() {
+uint32 Serializer::loadUint32()
+{
uint32 e;
- saveLoadBytes(&e,4);
+ saveLoadBytes(&e, 4);
return FROM_LE_32(e);
}
-uint16 Serializer::loadWord() {
+uint16 Serializer::loadWord()
+{
uint16 e;
- saveLoadBytes(&e,2);
+ saveLoadBytes(&e, 2);
return FROM_LE_16(e);
}
-byte Serializer::loadByte() {
+byte Serializer::loadByte()
+{
byte e;
- saveLoadBytes(&e,1);
+ saveLoadBytes(&e, 1);
return e;
}
-void Serializer::saveLoadArrayOf(void *b, int len, int datasize, byte filetype) {
- byte *at = (byte*)b;
+void Serializer::saveLoadArrayOf(void *b, int len, int datasize,
+ byte filetype)
+{
+ byte *at = (byte *)b;
uint32 data;
/* speed up byte arrays */
- if (datasize==1 && filetype==sleByte) {
+ if (datasize == 1 && filetype == sleByte) {
saveLoadBytes(b, len);
return;
}
- while (--len>=0) {
+ while (--len >= 0) {
if (_saveOrLoad) {
/* saving */
- if (datasize==1) {
- data = *(byte*)at;
+ if (datasize == 1) {
+ data = *(byte *)at;
at += 1;
- } else if (datasize==2) {
- data = *(uint16*)at;
+ } else if (datasize == 2) {
+ data = *(uint16 *)at;
at += 2;
- } else if (datasize==4) {
- data = *(uint32*)at;
+ } else if (datasize == 4) {
+ data = *(uint32 *)at;
at += 4;
} else {
error("saveLoadArrayOf: invalid size %d", datasize);
}
- switch(filetype) {
- case sleByte: saveByte((byte)data); break;
+ switch (filetype) {
+ case sleByte:
+ saveByte((byte)data);
+ break;
case sleUint16:
- case sleInt16:saveWord((int16)data); break;
+ case sleInt16:
+ saveWord((int16) data);
+ break;
case sleInt32:
- case sleUint32:saveUint32(data); break;
+ case sleUint32:
+ saveUint32(data);
+ break;
default:
error("saveLoadArrayOf: invalid filetype %d", filetype);
}
} else {
/* loading */
- switch(filetype) {
- case sleByte: data = loadByte(); break;
- case sleUint16: data = loadWord(); break;
- case sleInt16: data = (int16)loadWord(); break;
- case sleUint32: data = loadUint32(); break;
- case sleInt32: data = (int32)loadUint32(); break;
+ switch (filetype) {
+ case sleByte:
+ data = loadByte();
+ break;
+ case sleUint16:
+ data = loadWord();
+ break;
+ case sleInt16:
+ data = (int16) loadWord();
+ break;
+ case sleUint32:
+ data = loadUint32();
+ break;
+ case sleInt32:
+ data = (int32) loadUint32();
+ break;
default:
error("saveLoadArrayOf: invalid filetype %d", filetype);
}
- if (datasize==1) {
- *(byte*)at = (byte)data;
+ if (datasize == 1) {
+ *(byte *)at = (byte)data;
at += 1;
- } else if (datasize==2) {
- *(uint16*)at = (uint16)data;
+ } else if (datasize == 2) {
+ *(uint16 *)at = (uint16)data;
at += 2;
- } else if (datasize==4) {
- *(uint32*)at = data;
+ } else if (datasize == 4) {
+ *(uint32 *)at = data;
at += 4;
} else {
error("saveLoadArrayOf: invalid size %d", datasize);
@@ -888,45 +925,48 @@ void Serializer::saveLoadArrayOf(void *b, int len, int datasize, byte filetype)
}
}
-void Serializer::saveLoadArrayOf(void *b, int num, int datasize, const SaveLoadEntry *sle) {
- byte *data = (byte*)b;
+void Serializer::saveLoadArrayOf(void *b, int num, int datasize,
+ const SaveLoadEntry * sle)
+{
+ byte *data = (byte *)b;
- while (--num>=0) {
- saveLoadEntries(data, sle);
+ while (--num >= 0) {
+ saveLoadEntries(data, sle);
data += datasize;
}
}
-void Serializer::saveLoadEntries(void *d, const SaveLoadEntry *sle) {
+void Serializer::saveLoadEntries(void *d, const SaveLoadEntry * sle)
+{
int replen;
byte type;
byte *at;
int size;
int num;
void *ptr;
-
- while(sle->offs != 0xFFFF) {
- at = (byte*)d + sle->offs;
+
+ while (sle->offs != 0xFFFF) {
+ at = (byte *)d + sle->offs;
size = sle->size;
type = sle->type;
-
- if (size==0xFF) {
+
+ if (size == 0xFF) {
if (_saveOrLoad) {
/* save reference */
- ptr = *((void**)at);
- saveWord(ptr ? ((*_save_ref)(_ref_me, type, ptr ) + 1) : 0);
+ ptr = *((void **)at);
+ saveWord(ptr ? ((*_save_ref) (_ref_me, type, ptr) + 1) : 0);
} else {
/* load reference */
num = loadWord();
- *((void**)at) = num ? (*_load_ref)(_ref_me, type, num-1) : NULL;
+ *((void **)at) = num ? (*_load_ref) (_ref_me, type, num - 1) : NULL;
}
} else {
replen = 1;
- if (type&128) {
+ if (type & 128) {
sle++;
replen = sle->offs;
- type&=~128;
+ type &= ~128;
}
saveLoadArrayOf(at, replen, size, type);
}
diff --git a/script.cpp b/script.cpp
index cc56f83531..53f2754624 100644
--- a/script.cpp
+++ b/script.cpp
@@ -24,19 +24,20 @@
#include "scumm.h"
/* Start executing script 'script' with parameters 'a' and 'b' */
-void Scumm::runScript(int script, int a, int b, int16 *lvarptr) {
+void Scumm::runScript(int script, int a, int b, int16 * lvarptr)
+{
byte *scriptPtr;
uint32 scriptOffs;
byte scriptType;
int slot;
ScriptSlot *s;
- if (script==0)
+ if (script == 0)
return;
- if (b==0)
+ if (b == 0)
stopScriptNr(script);
-
+
if (script < _numGlobalScripts) {
scriptPtr = getResourceAddress(rtScript, script);
scriptOffs = _resourceHeaderSize;
@@ -60,24 +61,25 @@ void Scumm::runScript(int script, int a, int b, int16 *lvarptr) {
s->freezeCount = 0;
initializeLocals(slot, lvarptr);
-
+
runScriptNested(slot);
}
/* Stop script 'script' */
-void Scumm::stopScriptNr(int script) {
+void Scumm::stopScriptNr(int script)
+{
ScriptSlot *ss;
NestedScript *nest;
- int i,num;
+ int i, num;
- if (script==0)
+ if (script == 0)
return;
ss = &vm.slot[1];
-
- for (i=1; i<NUM_SCRIPT_SLOT; i++,ss++) {
- if (script!=ss->number ||
- ss->where!=WIO_GLOBAL && ss->where!=WIO_LOCAL || ss->status==0)
+
+ for (i = 1; i < NUM_SCRIPT_SLOT; i++, ss++) {
+ if (script != ss->number ||
+ ss->where != WIO_GLOBAL && ss->where != WIO_LOCAL || ss->status == 0)
continue;
if (ss->cutsceneOverride)
@@ -88,35 +90,39 @@ void Scumm::stopScriptNr(int script) {
_currentScript = 0xFF;
}
- if (_numNestedScripts==0)
+ if (_numNestedScripts == 0)
return;
nest = &vm.nest[0];
num = _numNestedScripts;
do {
- if (nest->number == script && (nest->where==WIO_GLOBAL || nest->where==WIO_LOCAL)) {
+ if (nest->number == script
+ && (nest->where == WIO_GLOBAL || nest->where == WIO_LOCAL)) {
nest->number = 0xFF;
nest->slot = 0xFF;
nest->where = 0xFF;
}
- } while(nest++,--num);
+ } while (nest++, --num);
}
/* Stop an object script 'script'*/
-void Scumm::stopObjectScript(int script) {
+void Scumm::stopObjectScript(int script)
+{
ScriptSlot *ss;
NestedScript *nest;
- int i,num;
+ int i, num;
- if (script==0)
+ if (script == 0)
return;
ss = &vm.slot[1];
-
- for (i=1; i<NUM_SCRIPT_SLOT; i++,ss++) {
- if (script==ss->number && (ss->where==WIO_ROOM ||
- ss->where==WIO_INVENTORY || ss->where==WIO_FLOBJECT) && ss->status!=0) {
+
+ for (i = 1; i < NUM_SCRIPT_SLOT; i++, ss++) {
+ if (script == ss->number && (ss->where == WIO_ROOM ||
+ ss->where == WIO_INVENTORY
+ || ss->where == WIO_FLOBJECT)
+ && ss->status != 0) {
if (ss->cutsceneOverride)
error("Object %d stopped with active cutscene/override", script);
ss->number = 0;
@@ -126,46 +132,48 @@ void Scumm::stopObjectScript(int script) {
}
}
- if (_numNestedScripts==0)
+ if (_numNestedScripts == 0)
return;
nest = &vm.nest[0];
num = _numNestedScripts;
do {
- if (nest->number == script &&
- (nest->where==WIO_ROOM || nest->where==WIO_FLOBJECT ||
- nest->where==WIO_INVENTORY)) {
+ if (nest->number == script &&
+ (nest->where == WIO_ROOM || nest->where == WIO_FLOBJECT ||
+ nest->where == WIO_INVENTORY)) {
nest->number = 0xFF;
nest->slot = 0xFF;
nest->where = 0xFF;
}
- } while(nest++,--num);
+ } while (nest++, --num);
}
/* Return a free script slot */
-int Scumm::getScriptSlot() {
+int Scumm::getScriptSlot()
+{
ScriptSlot *ss;
int i;
ss = &vm.slot[1];
-
- for (i=1; i<NUM_SCRIPT_SLOT; i++,ss++) {
- if(ss->status==0)
+
+ for (i = 1; i < NUM_SCRIPT_SLOT; i++, ss++) {
+ if (ss->status == 0)
return i;
}
error("Too many scripts running, %d max", NUM_SCRIPT_SLOT);
}
/* Run script 'script' nested - eg, within the parent script.*/
-void Scumm::runScriptNested(int script) {
+void Scumm::runScriptNested(int script)
+{
NestedScript *nest;
ScriptSlot *slot;
updateScriptPtr();
-
+
nest = &vm.nest[_numNestedScripts];
- if (_currentScript==0xFF) {
+ if (_currentScript == 0xFF) {
nest->number = 0xFF;
nest->where = 0xFF;
} else {
@@ -175,7 +183,7 @@ void Scumm::runScriptNested(int script) {
nest->slot = _currentScript;
}
- if (++_numNestedScripts>sizeof(vm.nest)/sizeof(vm.nest[0]))
+ if (++_numNestedScripts > sizeof(vm.nest) / sizeof(vm.nest[0]))
error("Too many nested scripts");
_currentScript = script;
@@ -187,11 +195,11 @@ void Scumm::runScriptNested(int script) {
_numNestedScripts--;
nest = &vm.nest[_numNestedScripts];
-
+
if (nest->number != 0xFF) {
slot = &vm.slot[nest->slot];
- if (slot->number == nest->number && slot->where==nest->where &&
- slot->status != 0 && slot->freezeCount==0) {
+ if (slot->number == nest->number && slot->where == nest->where &&
+ slot->status != 0 && slot->freezeCount == 0) {
_currentScript = nest->slot;
getScriptBaseAddress();
getScriptEntryPoint();
@@ -201,7 +209,8 @@ void Scumm::runScriptNested(int script) {
_currentScript = 0xFF;
}
-void Scumm::updateScriptPtr() {
+void Scumm::updateScriptPtr()
+{
if (_currentScript == 0xFF)
return;
@@ -209,7 +218,8 @@ void Scumm::updateScriptPtr() {
}
/* Get the code pointer to a script */
-void Scumm::getScriptBaseAddress() {
+void Scumm::getScriptBaseAddress()
+{
ScriptSlot *ss;
int idx;
@@ -217,27 +227,28 @@ void Scumm::getScriptBaseAddress() {
return;
ss = &vm.slot[_currentScript];
- switch(ss->where) {
- case WIO_INVENTORY: /* inventory script **/
+ switch (ss->where) {
+ case WIO_INVENTORY: /* inventory script * */
idx = getObjectIndex(ss->number);
_scriptOrgPointer = getResourceAddress(rtInventory, idx);
_lastCodePtr = &_baseInventoryItems[idx];
break;
case 3:
- case WIO_ROOM: /* room script */
+ case WIO_ROOM: /* room script */
_scriptOrgPointer = getResourceAddress(rtRoom, _roomResource);
_lastCodePtr = &_baseRooms[_roomResource];
break;
- case WIO_GLOBAL: /* global script */
+ case WIO_GLOBAL: /* global script */
_scriptOrgPointer = getResourceAddress(rtScript, ss->number);
_lastCodePtr = &_baseScripts[ss->number];
break;
- case WIO_FLOBJECT: /* flobject script */
+ case WIO_FLOBJECT: /* flobject script */
idx = getObjectIndex(ss->number);
- _scriptOrgPointer = getResourceAddress(rtFlObject,_objs[idx].fl_object_index);
+ _scriptOrgPointer =
+ getResourceAddress(rtFlObject, _objs[idx].fl_object_index);
_lastCodePtr = &_baseFLObject[ss->number];
break;
default:
@@ -246,27 +257,29 @@ void Scumm::getScriptBaseAddress() {
}
-void Scumm::getScriptEntryPoint() {
+void Scumm::getScriptEntryPoint()
+{
if (_currentScript == 0xFF)
return;
_scriptPointer = _scriptOrgPointer + vm.slot[_currentScript].offs;
}
/* Execute a script - Read opcode, and execute it from the table */
-void Scumm::executeScript() {
+void Scumm::executeScript()
+{
OpcodeProc op;
while (_currentScript != 0xFF) {
_opcode = fetchScriptByte();
_scriptPointerStart = _scriptPointer;
- vm.slot[_currentScript].didexec = 1;
+ vm.slot[_currentScript].didexec = 1;
//debug(1, "Script %d: [%X] %s()", vm.slot[_currentScript].number, _opcode, _opcodes_lookup[_opcode]);
op = getOpcode(_opcode);
- (this->*op)();
+ (this->*op) ();
}
- CHECK_HEAP
-}
+CHECK_HEAP}
-byte Scumm::fetchScriptByte() {
+byte Scumm::fetchScriptByte()
+{
if (*_lastCodePtr + sizeof(MemBlkHeader) != _scriptOrgPointer) {
uint32 oldoffs = _scriptPointer - _scriptOrgPointer;
getScriptBaseAddress();
@@ -275,7 +288,8 @@ byte Scumm::fetchScriptByte() {
return *_scriptPointer++;
}
-int Scumm::fetchScriptWord() {
+int Scumm::fetchScriptWord()
+{
int a;
if (*_lastCodePtr + sizeof(MemBlkHeader) != _scriptOrgPointer) {
uint32 oldoffs = _scriptPointer - _scriptOrgPointer;
@@ -291,41 +305,43 @@ int Scumm::fetchScriptWord() {
#define BYPASS_COPY_PROT
#endif
-int Scumm::readVar(uint var) {
+int Scumm::readVar(uint var)
+{
int a;
#ifdef BYPASS_COPY_PROT
static byte copyprotbypassed;
#endif
debug(9, "readvar=%d", var);
- if (!(var&0xF000)) {
+ if (!(var & 0xF000)) {
#if defined(BYPASS_COPY_PROT)
- if (var==490 && _gameId == GID_MONKEY2 && !copyprotbypassed) {
+ if (var == 490 && _gameId == GID_MONKEY2 && !copyprotbypassed) {
copyprotbypassed = true;
var = 518;
}
#endif
- checkRange(_numVariables-1, 0, var, "Variable %d out of range(r)");
+ checkRange(_numVariables - 1, 0, var, "Variable %d out of range(r)");
return _vars[var];
}
- if (var&0x2000 && !(_features&GF_NEW_OPCODES)) {
+ if (var & 0x2000 && !(_features & GF_NEW_OPCODES)) {
a = fetchScriptWord();
- if (a&0x2000)
- var = (var+readVar(a&~0x2000))&~0x2000;
+ if (a & 0x2000)
+ var = (var + readVar(a & ~0x2000)) & ~0x2000;
else
- var = (var+(a&0xFFF))&~0x2000;
+ var = (var + (a & 0xFFF)) & ~0x2000;
}
- if (!(var&0xF000))
+ if (!(var & 0xF000))
return _vars[var];
- if (var&0x8000) {
+ if (var & 0x8000) {
var &= 0x7FFF;
- checkRange(_numBitVariables-1, 0, var, "Bit variable %d out of range(r)");
- return (_bitVars[var>>3] & (1<<(var&7))) ? 1 : 0;
+ checkRange(_numBitVariables - 1, 0, var,
+ "Bit variable %d out of range(r)");
+ return (_bitVars[var >> 3] & (1 << (var & 7))) ? 1 : 0;
}
- if (var&0x4000) {
+ if (var & 0x4000) {
var &= 0xFFF;
checkRange(0x10, 0, var, "Local variable %d out of range(r)");
return vm.localvar[_currentScript][var];
@@ -334,27 +350,30 @@ int Scumm::readVar(uint var) {
error("Illegal varbits (r)");
}
-void Scumm::writeVar(uint var, int value) {
- if (!(var&0xF000)) {
- checkRange(_numVariables-1, 0, var, "Variable %d out of range(w)");
+void Scumm::writeVar(uint var, int value)
+{
+ if (!(var & 0xF000)) {
+ checkRange(_numVariables - 1, 0, var, "Variable %d out of range(w)");
_vars[var] = value;
if ((_varwatch == (int)var) || (_varwatch == 0))
- printf("vars[%d] = %d (via script %d)\n", var, value, vm.slot[_currentScript].number);
+ printf("vars[%d] = %d (via script %d)\n", var, value,
+ vm.slot[_currentScript].number);
return;
}
- if (var&0x8000) {
+ if (var & 0x8000) {
var &= 0x7FFF;
- checkRange(_numBitVariables-1, 0, var, "Bit variable %d out of range(w)");
+ checkRange(_numBitVariables - 1, 0, var,
+ "Bit variable %d out of range(w)");
if (value)
- _bitVars[var>>3] |= (1<<(var&7));
+ _bitVars[var >> 3] |= (1 << (var & 7));
else
- _bitVars[var>>3] &= ~(1<<(var&7));
+ _bitVars[var >> 3] &= ~(1 << (var & 7));
return;
}
- if (var&0x4000) {
+ if (var & 0x4000) {
var &= 0xFFF;
checkRange(0x10, 0, var, "Local variable %d out of range(w)");
vm.localvar[_currentScript][var] = value;
@@ -364,60 +383,71 @@ void Scumm::writeVar(uint var, int value) {
error("Illegal varbits (w)");
}
-void Scumm::getResultPos() {
+void Scumm::getResultPos()
+{
int a;
_resultVarNumber = fetchScriptWord();
- if (_resultVarNumber&0x2000) {
+ if (_resultVarNumber & 0x2000) {
a = fetchScriptWord();
- if (a&0x2000) {
- _resultVarNumber += readVar(a&~0x2000);
+ if (a & 0x2000) {
+ _resultVarNumber += readVar(a & ~0x2000);
} else {
- _resultVarNumber += a&0xFFF;
+ _resultVarNumber += a & 0xFFF;
}
- _resultVarNumber&=~0x2000;
+ _resultVarNumber &= ~0x2000;
}
}
-void Scumm::setResult(int value) {
+void Scumm::setResult(int value)
+{
writeVar(_resultVarNumber, value);
}
-void Scumm::drawBox(int x, int y, int x2, int y2, int color) {
- int top,bottom,count;
+void Scumm::drawBox(int x, int y, int x2, int y2, int color)
+{
+ int top, bottom, count;
VirtScreen *vs;
byte *backbuff, *bgbuff;
- if ((vs=findVirtScreen(y)) == NULL)
+ if ((vs = findVirtScreen(y)) == NULL)
return;
top = vs->topline;
bottom = top + vs->height;
if (x > x2)
- SWAP(x,x2);
+ SWAP(x, x2);
if (y > y2)
- SWAP(y,y2);
+ SWAP(y, y2);
x2++;
y2++;
- if (x>319) return;
- if (x<0) x=0;
- if (y<0) y=0;
- if (x2<0) return;
- if (x2>320) x2=320;
- if (y2 > bottom) y2=bottom;
+ if (x > 319)
+ return;
+ if (x < 0)
+ x = 0;
+ if (y < 0)
+ y = 0;
+ if (x2 < 0)
+ return;
+ if (x2 > 320)
+ x2 = 320;
+ if (y2 > bottom)
+ y2 = bottom;
- updateDirtyRect(vs->number, x, x2, y-top, y2-top, 0);
+ updateDirtyRect(vs->number, x, x2, y - top, y2 - top, 0);
- backbuff = vs->screenPtr + vs->xstart + (y-top)*320 + x;
+ backbuff = vs->screenPtr + vs->xstart + (y - top) * 320 + x;
- if (color==-1) {
- if(vs->number!=0)
+ if (color == -1) {
+ if (vs->number != 0)
error("can only copy bg to main window");
- bgbuff = getResourceAddress(rtBuffer, vs->number+5) + vs->xstart + (y-top)*320 + x;
+ bgbuff =
+ getResourceAddress(rtBuffer,
+ vs->number + 5) + vs->xstart + (y - top) * 320 + x;
blit(backbuff, bgbuff, x2 - x, y2 - y);
} else {
count = y2 - y;
@@ -430,7 +460,8 @@ void Scumm::drawBox(int x, int y, int x2, int y2, int color) {
}
-void Scumm::stopObjectCode() {
+void Scumm::stopObjectCode()
+{
ScriptSlot *ss;
ss = &vm.slot[_currentScript];
@@ -439,14 +470,15 @@ void Scumm::stopObjectCode() {
ss->cutsceneOverride = 0;
}
- if (ss->where!=WIO_GLOBAL && ss->where!=WIO_LOCAL) {
+ if (ss->where != WIO_GLOBAL && ss->where != WIO_LOCAL) {
if (ss->cutsceneOverride) {
warning("Object %d ending with active cutscene/override", ss->number);
ss->cutsceneOverride = 0;
}
} else {
if (ss->cutsceneOverride) {
- warning("Script %d ending with active cutscene/override (%d)", ss->number, ss->cutsceneOverride);
+ warning("Script %d ending with active cutscene/override (%d)",
+ ss->number, ss->cutsceneOverride);
ss->cutsceneOverride = 0;
}
}
@@ -455,12 +487,13 @@ void Scumm::stopObjectCode() {
_currentScript = 0xFF;
}
-bool Scumm::isScriptInUse(int script) {
+bool Scumm::isScriptInUse(int script)
+{
ScriptSlot *ss;
int i;
ss = vm.slot;
- for (i=0; i<NUM_SCRIPT_SLOT; i++,ss++) {
+ for (i = 0; i < NUM_SCRIPT_SLOT; i++, ss++) {
if (ss->number == script)
return true;
}
@@ -468,7 +501,8 @@ bool Scumm::isScriptInUse(int script) {
}
-void Scumm::runHook(int i) {
+void Scumm::runHook(int i)
+{
int16 tmp[16];
tmp[0] = i;
if (_vars[VAR_HOOK_SCRIPT]) {
@@ -476,51 +510,55 @@ void Scumm::runHook(int i) {
}
}
-void Scumm::freezeScripts(int flag) {
+void Scumm::freezeScripts(int flag)
+{
int i;
- for(i=1; i<NUM_SCRIPT_SLOT; i++) {
- if (_currentScript!=i && vm.slot[i].status!=ssDead && (vm.slot[i].unk1==0 || flag>=0x80)) {
+ for (i = 1; i < NUM_SCRIPT_SLOT; i++) {
+ if (_currentScript != i && vm.slot[i].status != ssDead
+ && (vm.slot[i].unk1 == 0 || flag >= 0x80)) {
vm.slot[i].status |= 0x80;
vm.slot[i].freezeCount++;
}
}
- for (i=0; i<6; i++)
+ for (i = 0; i < 6; i++)
sentence[i].unk++;
- if(vm.cutSceneScriptIndex != 0xFF) {
- vm.slot[vm.cutSceneScriptIndex].status&=0x7F;
- vm.slot[vm.cutSceneScriptIndex].freezeCount=0;
+ if (vm.cutSceneScriptIndex != 0xFF) {
+ vm.slot[vm.cutSceneScriptIndex].status &= 0x7F;
+ vm.slot[vm.cutSceneScriptIndex].freezeCount = 0;
}
}
-void Scumm::unfreezeScripts() {
+void Scumm::unfreezeScripts()
+{
int i;
- for (i=1; i<NUM_SCRIPT_SLOT; i++) {
- if (vm.slot[i].status&0x80) {
+ for (i = 1; i < NUM_SCRIPT_SLOT; i++) {
+ if (vm.slot[i].status & 0x80) {
if (!--vm.slot[i].freezeCount) {
- vm.slot[i].status&=0x7F;
+ vm.slot[i].status &= 0x7F;
}
}
}
- for (i=0; i<6; i++) {
- if (((int8)--sentence[i].unk)<0)
+ for (i = 0; i < 6; i++) {
+ if (((int8)-- sentence[i].unk) < 0)
sentence[i].unk = 0;
}
}
-void Scumm::runAllScripts() {
+void Scumm::runAllScripts()
+{
int i;
- for (i=0; i<NUM_SCRIPT_SLOT; i++)
+ for (i = 0; i < NUM_SCRIPT_SLOT; i++)
vm.slot[i].didexec = 0;
-
+
_currentScript = 0xFF;
- for(_curExecScript = 0; _curExecScript<NUM_SCRIPT_SLOT; _curExecScript++) {
+ for (_curExecScript = 0; _curExecScript < NUM_SCRIPT_SLOT; _curExecScript++) {
if (vm.slot[_curExecScript].status == ssRunning &&
- vm.slot[_curExecScript].didexec == 0) {
+ vm.slot[_curExecScript].didexec == 0) {
_currentScript = (char)_curExecScript;
getScriptBaseAddress();
getScriptEntryPoint();
@@ -529,7 +567,8 @@ void Scumm::runAllScripts() {
}
}
-void Scumm::runExitScript() {
+void Scumm::runExitScript()
+{
if (_vars[VAR_EXIT_SCRIPT])
runScript(_vars[VAR_EXIT_SCRIPT], 0, 0, 0);
if (_EXCD_offs) {
@@ -547,7 +586,8 @@ void Scumm::runExitScript() {
runScript(_vars[VAR_EXIT_SCRIPT2], 0, 0, 0);
}
-void Scumm::runEntryScript() {
+void Scumm::runEntryScript()
+{
if (_vars[VAR_ENTRY_SCRIPT])
runScript(_vars[VAR_ENTRY_SCRIPT], 0, 0, 0);
if (_ENCD_offs) {
@@ -565,24 +605,27 @@ void Scumm::runEntryScript() {
runScript(_vars[VAR_ENTRY_SCRIPT2], 0, 0, 0);
}
-void Scumm::killScriptsAndResources() {
+void Scumm::killScriptsAndResources()
+{
ScriptSlot *ss;
int i;
ss = &vm.slot[1];
-
- for (i=1; i<NUM_SCRIPT_SLOT; i++,ss++) {
- if (ss->where==WIO_ROOM || ss->where==WIO_FLOBJECT) {
- if(ss->cutsceneOverride)
- error("Object %d stopped with active cutscene/override in exit", ss->number);
+
+ for (i = 1; i < NUM_SCRIPT_SLOT; i++, ss++) {
+ if (ss->where == WIO_ROOM || ss->where == WIO_FLOBJECT) {
+ if (ss->cutsceneOverride)
+ error("Object %d stopped with active cutscene/override in exit",
+ ss->number);
ss->status = 0;
- } else if (ss->where==WIO_LOCAL) {
- if(ss->cutsceneOverride)
- error("Script %d stopped with active cutscene/override in exit", ss->number);
+ } else if (ss->where == WIO_LOCAL) {
+ if (ss->cutsceneOverride)
+ error("Script %d stopped with active cutscene/override in exit",
+ ss->number);
ss->status = 0;
}
}
-
+
/* Nuke FL objects */
i = 0;
do {
@@ -592,7 +635,7 @@ void Scumm::killScriptsAndResources() {
/* Nuke local object names */
if (_newNames) {
- for (i=0; i<_numNewNames; i++) {
+ for (i = 0; i < _numNewNames; i++) {
int j = _newNames[i];
if (j && getOwner(j) == 0) {
_newNames[i] = 0;
@@ -602,26 +645,28 @@ void Scumm::killScriptsAndResources() {
}
}
-void Scumm::checkAndRunVar33() {
+void Scumm::checkAndRunVar33()
+{
int i;
ScriptSlot *ss;
memset(_localParamList, 0, sizeof(_localParamList));
if (isScriptInUse(_vars[VAR_SENTENCE_SCRIPT])) {
ss = vm.slot;
- for (i=0; i<NUM_SCRIPT_SLOT; i++,ss++)
- if (ss->number==_vars[VAR_SENTENCE_SCRIPT] && ss->status!=0 && ss->freezeCount==0)
+ for (i = 0; i < NUM_SCRIPT_SLOT; i++, ss++)
+ if (ss->number == _vars[VAR_SENTENCE_SCRIPT] && ss->status != 0
+ && ss->freezeCount == 0)
return;
}
- if (!_sentenceNum || sentence[_sentenceNum-1].unk)
+ if (!_sentenceNum || sentence[_sentenceNum - 1].unk)
return;
_sentenceNum--;
- if(!(_features & GF_AFTER_V7))
- if (sentence[_sentenceNum].unk2 &&
- sentence[_sentenceNum].unk3==sentence[_sentenceNum].unk4)
+ if (!(_features & GF_AFTER_V7))
+ if (sentence[_sentenceNum].unk2 &&
+ sentence[_sentenceNum].unk3 == sentence[_sentenceNum].unk4)
return;
_localParamList[0] = sentence[_sentenceNum].unk5;
@@ -632,7 +677,8 @@ void Scumm::checkAndRunVar33() {
runScript(_vars[VAR_SENTENCE_SCRIPT], 0, 0, _localParamList);
}
-void Scumm::runInputScript(int a, int cmd, int mode) {
+void Scumm::runInputScript(int a, int cmd, int mode)
+{
int16 args[16];
memset(args, 0, sizeof(args));
args[0] = a;
@@ -642,13 +688,14 @@ void Scumm::runInputScript(int a, int cmd, int mode) {
runScript(_vars[VAR_VERB_SCRIPT], 0, 0, args);
}
-void Scumm::decreaseScriptDelay(int amount) {
+void Scumm::decreaseScriptDelay(int amount)
+{
ScriptSlot *ss = &vm.slot[0];
int i;
- for (i=0; i<NUM_SCRIPT_SLOT; i++,ss++) {
- if(ss->status==1) {
+ for (i = 0; i < NUM_SCRIPT_SLOT; i++, ss++) {
+ if (ss->status == 1) {
ss->delay -= amount;
- if (ss->delay < 0){
+ if (ss->delay < 0) {
ss->status = 2;
ss->delay = 0;
}
@@ -656,13 +703,14 @@ void Scumm::decreaseScriptDelay(int amount) {
}
}
-void Scumm::runVerbCode(int object, int entry, int a, int b, int16 *vars) {
+void Scumm::runVerbCode(int object, int entry, int a, int b, int16 * vars)
+{
uint32 obcd;
int slot, where, offs;
if (!object)
return;
- if (!b)
+ if (!b)
stopObjectScript(object);
where = whereIsObject(object);
@@ -675,7 +723,7 @@ void Scumm::runVerbCode(int object, int entry, int a, int b, int16 *vars) {
slot = getScriptSlot();
offs = getVerbEntrypoint(object, entry);
- if (offs==0)
+ if (offs == 0)
return;
vm.slot[slot].number = object;
@@ -692,76 +740,83 @@ void Scumm::runVerbCode(int object, int entry, int a, int b, int16 *vars) {
runScriptNested(slot);
}
-void Scumm::initializeLocals(int slot, int16 *vars) {
+void Scumm::initializeLocals(int slot, int16 * vars)
+{
int i;
if (!vars) {
- for(i=0; i<16; i++)
+ for (i = 0; i < 16; i++)
vm.localvar[slot][i] = 0;
} else {
- for (i=0; i<16; i++)
+ for (i = 0; i < 16; i++)
vm.localvar[slot][i] = vars[i];
}
}
-int Scumm::getVerbEntrypoint(int obj, int entry) {
+int Scumm::getVerbEntrypoint(int obj, int entry)
+{
byte *objptr, *verbptr;
int verboffs;
- if (whereIsObject(obj)==WIO_NOT_FOUND)
+ if (whereIsObject(obj) == WIO_NOT_FOUND)
return 0;
objptr = getOBCDFromObject(obj);
assert(objptr);
- if(_features & GF_SMALL_HEADER)
- verbptr = objptr+19;
- else
- verbptr = findResource(MKID('VERB'), objptr);
+ if (_features & GF_SMALL_HEADER)
+ verbptr = objptr + 19;
+ else
+ verbptr = findResource(MKID('VERB'), objptr);
- if (verbptr==NULL)
+ if (verbptr == NULL)
error("No verb block in object %d", obj);
verboffs = verbptr - objptr;
- if(!(_features & GF_SMALL_HEADER))
- verbptr += _resourceHeaderSize;
+ if (!(_features & GF_SMALL_HEADER))
+ verbptr += _resourceHeaderSize;
do {
if (!*verbptr)
return 0;
- if (*verbptr==entry || *verbptr==0xFF)
+ if (*verbptr == entry || *verbptr == 0xFF)
break;
verbptr += 3;
} while (1);
- if(_features & GF_SMALL_HEADER)
- return READ_LE_UINT16(verbptr+1);
- else
- return verboffs + READ_LE_UINT16(verbptr+1);
+ if (_features & GF_SMALL_HEADER)
+ return READ_LE_UINT16(verbptr + 1);
+ else
+ return verboffs + READ_LE_UINT16(verbptr + 1);
}
-void Scumm::push(int a) {
- assert(_scummStackPos >=0 && (unsigned int)_scummStackPos <= ARRAYSIZE(_scummStack));
- _scummStack[_scummStackPos++] = a;
+void Scumm::push(int a)
+{
+ assert(_scummStackPos >= 0
+ && (unsigned int)_scummStackPos <= ARRAYSIZE(_scummStack));
+ _scummStack[_scummStackPos++] = a;
}
-int Scumm::pop() {
- assert(_scummStackPos >0 && (unsigned int)_scummStackPos <= ARRAYSIZE(_scummStack));
+int Scumm::pop()
+{
+ assert(_scummStackPos > 0
+ && (unsigned int)_scummStackPos <= ARRAYSIZE(_scummStack));
return _scummStack[--_scummStackPos];
}
-void Scumm::endCutscene() {
+void Scumm::endCutscene()
+{
ScriptSlot *ss = &vm.slot[_currentScript];
uint32 *csptr;
int16 args[16];
- memset(args, 0, sizeof(args));
+ memset(args, 0, sizeof(args));
if (ss->cutsceneOverride > 0) // Only terminate if active
- ss->cutsceneOverride--;
-
+ ss->cutsceneOverride--;
+
args[0] = vm.cutSceneData[vm.cutSceneStackPointer];
_vars[VAR_OVERRIDE] = 0;
@@ -777,11 +832,13 @@ void Scumm::endCutscene() {
runScript(_vars[VAR_CUTSCENE_END_SCRIPT], 0, 0, args);
}
-void Scumm::cutscene(int16 *args) {
+void Scumm::cutscene(int16 * args)
+{
int scr = _currentScript;
vm.slot[scr].cutsceneOverride++;
-
- if (++vm.cutSceneStackPointer > sizeof(vm.cutSceneData)/sizeof(vm.cutSceneData[0]))
+
+ if (++vm.cutSceneStackPointer >
+ sizeof(vm.cutSceneData) / sizeof(vm.cutSceneData[0]))
error("Cutscene stack overflow");
vm.cutSceneData[vm.cutSceneStackPointer] = args[0];
@@ -794,38 +851,40 @@ void Scumm::cutscene(int16 *args) {
vm.cutSceneScriptIndex = 0xFF;
}
-void Scumm::faceActorToObj(int act, int obj) {
- int x,dir;
+void Scumm::faceActorToObj(int act, int obj)
+{
+ int x, dir;
- if (getObjectOrActorXY(act)==-1)
+ if (getObjectOrActorXY(act) == -1)
return;
x = _xPos;
- if (getObjectOrActorXY(obj)==-1)
+ if (getObjectOrActorXY(obj) == -1)
return;
dir = (_xPos > x) ? 90 : 270;
turnToDirection(derefActorSafe(act, "faceActorToObj"), dir);
}
-void Scumm::animateActor(int act, int anim) {
- if(_features & GF_AFTER_V7) {
- int cmd,dir;
+void Scumm::animateActor(int act, int anim)
+{
+ if (_features & GF_AFTER_V7) {
+ int cmd, dir;
Actor *a;
a = derefActorSafe(act, "animateActor");
- if (anim==0xFF)
+ if (anim == 0xFF)
anim = 2000;
- cmd = anim / 1000;
+ cmd = anim / 1000;
dir = anim % 1000;
/* temporary code */
-// dir = newDirToOldDir(dir);
+// dir = newDirToOldDir(dir);
- switch(cmd) {
+ switch (cmd) {
case 2:
stopActorMoving(a);
startAnimActor(a, a->standFrame);
@@ -846,11 +905,12 @@ void Scumm::animateActor(int act, int anim) {
Actor *a;
a = derefActorSafe(act, "animateActor");
- if (!a) return;
-
- dir = anim&3;
+ if (!a)
+ return;
+
+ dir = anim & 3;
- switch(anim>>2) {
+ switch (anim >> 2) {
case 0x3F:
stopActorMoving(a);
startAnimActor(a, a->standFrame);
@@ -865,25 +925,27 @@ void Scumm::animateActor(int act, int anim) {
default:
startAnimActor(a, anim);
}
-
+
}
}
-bool Scumm::isScriptRunning(int script) {
+bool Scumm::isScriptRunning(int script)
+{
int i;
ScriptSlot *ss = vm.slot;
- for (i=0; i<NUM_SCRIPT_SLOT; i++,ss++)
- if (ss->number==script && (ss->where==WIO_GLOBAL ||
- ss->where==WIO_LOCAL) && ss->status)
+ for (i = 0; i < NUM_SCRIPT_SLOT; i++, ss++)
+ if (ss->number == script && (ss->where == WIO_GLOBAL ||
+ ss->where == WIO_LOCAL) && ss->status)
return true;
return false;
}
-bool Scumm::isRoomScriptRunning(int script) {
+bool Scumm::isRoomScriptRunning(int script)
+{
int i;
ScriptSlot *ss = vm.slot;
- for (i=0; i<NUM_SCRIPT_SLOT; i++,ss++)
- if (ss->number==script && ss->where==WIO_ROOM && ss->status)
+ for (i = 0; i < NUM_SCRIPT_SLOT; i++, ss++)
+ if (ss->number == script && ss->where == WIO_ROOM && ss->status)
return true;
return false;
@@ -891,7 +953,8 @@ bool Scumm::isRoomScriptRunning(int script) {
-void Scumm::beginOverride() {
+void Scumm::beginOverride()
+{
int idx;
uint32 *ptr;
@@ -909,7 +972,8 @@ void Scumm::beginOverride() {
_vars[VAR_OVERRIDE] = 0;
}
-void Scumm::endOverride() {
+void Scumm::endOverride()
+{
int idx;
uint32 *ptr;
@@ -925,43 +989,46 @@ void Scumm::endOverride() {
}
-int Scumm::defineArray(int array, int type, int dim2, int dim1) {
+int Scumm::defineArray(int array, int type, int dim2, int dim1)
+{
int id;
int size;
ArrayHeader *ah;
- if (type!=5 && type!=4)
- type=5;
+ if (type != 5 && type != 4)
+ type = 5;
nukeArray(array);
id = getArrayId();
- if (array&0x4000) {
+ if (array & 0x4000) {
_arrays[id] = (char)vm.slot[_currentScript].number;
}
- if (array&0x8000) {
+ if (array & 0x8000) {
error("Can't define bit variable as array pointer");
}
writeVar(array, id);
- size = (type==5) ? 16 : 8;
- size *= dim2+1;
- size *= dim1+1;
+ size = (type == 5) ? 16 : 8;
+ size *= dim2 + 1;
+ size *= dim1 + 1;
size >>= 3;
- ah = (ArrayHeader*)createResource(rtString, id, size+sizeof(ArrayHeader));
+ ah =
+ (ArrayHeader *)createResource(rtString, id, size + sizeof(ArrayHeader));
ah->type = type;
- ah->dim1_size = dim1+1;
- ah->dim2_size = dim2+1;
+ ah->dim1_size = dim1 + 1;
+ ah->dim2_size = dim2 + 1;
return id;
}
-void Scumm::nukeArray(int a) {
+void Scumm::nukeArray(int a)
+{
int data;
data = readVar(a);
@@ -973,38 +1040,42 @@ void Scumm::nukeArray(int a) {
writeVar(a, 0);
}
-int Scumm::getArrayId() {
+int Scumm::getArrayId()
+{
byte **addr = _baseArrays;
int i;
- for (i=1; i<_numArray; i++) {
+ for (i = 1; i < _numArray; i++) {
if (!addr[i])
return i;
}
error("Out of array pointers, %d max", _numArray);
}
-void Scumm::arrayop_1(int a, byte *ptr) {
+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(rtString,r);
- copyString(ah->data,ptr,len);
+ ah = (ArrayHeader *)getResourceAddress(rtString, r);
+ copyString(ah->data, ptr, len);
}
-void Scumm::copyString(byte *dst, byte *src, int len) {
+void Scumm::copyString(byte *dst, byte *src, int len)
+{
if (!src) {
- while (--len>=0)
+ while (--len >= 0)
*dst++ = fetchScriptByte();
} else {
- while (--len>=0)
+ while (--len >= 0)
*dst++ = *src++;
}
}
-int Scumm::getStringLen(byte *ptr) {
+int Scumm::getStringLen(byte *ptr)
+{
int len;
byte c;
if (!ptr)
@@ -1012,15 +1083,17 @@ int Scumm::getStringLen(byte *ptr) {
len = 0;
do {
c = *ptr++;
- if (!c) break;
+ if (!c)
+ break;
len++;
- if (c==0xFF)
+ if (c == 0xFF)
ptr += 3, len += 3;
} while (1);
- return len+1;
+ return len + 1;
}
-void Scumm::exitCutscene() {
+void Scumm::exitCutscene()
+{
uint32 offs = vm.cutScenePtr[vm.cutSceneStackPointer];
if (offs) {
ScriptSlot *ss = &vm.slot[vm.cutSceneScript[vm.cutSceneStackPointer]];
@@ -1029,24 +1102,24 @@ void Scumm::exitCutscene() {
ss->freezeCount = 0;
if (ss->cutsceneOverride > 0)
- ss->cutsceneOverride--;
+ ss->cutsceneOverride--;
_vars[VAR_OVERRIDE] = 1;
vm.cutScenePtr[vm.cutSceneStackPointer] = 0;
}
}
-void Scumm::doSentence(int c, int b, int a) {
- if(_features & GF_AFTER_V7) {
+void Scumm::doSentence(int c, int b, int a)
+{
+ if (_features & GF_AFTER_V7) {
SentenceTab *st;
-
- if (b==a)
+
+ if (b == a)
return;
- st = &sentence[_sentenceNum-1];
+ st = &sentence[_sentenceNum - 1];
- if (_sentenceNum &&
- st->unk5 == c && st->unk4==b && st->unk3==a)
- return;
+ if (_sentenceNum && st->unk5 == c && st->unk4 == b && st->unk3 == a)
+ return;
_sentenceNum++;
st++;
@@ -1055,7 +1128,7 @@ void Scumm::doSentence(int c, int b, int a) {
st->unk4 = b;
st->unk3 = a;
st->unk = 0;
-
+
warning("dosentence(%d,%d,%d)", c, b, a);
} else {
@@ -1068,7 +1141,7 @@ void Scumm::doSentence(int c, int b, int a) {
st->unk4 = b;
st->unk3 = a;
- if (!(st->unk3&0xFF00))
+ if (!(st->unk3 & 0xFF00))
st->unk2 = 0;
else
st->unk2 = 1;
diff --git a/script_v1.cpp b/script_v1.cpp
index 5e7d8c7547..286f55e947 100644
--- a/script_v1.cpp
+++ b/script_v1.cpp
@@ -25,651 +25,652 @@
#include "scumm.h"
#include "cdmusic.h"
-void Scumm::setupOpcodes() {
+void Scumm::setupOpcodes()
+{
static const OpcodeProc opcode_list[] = {
- /* 00 */
- &Scumm::o5_stopObjectCode,
- &Scumm::o5_putActor,
- &Scumm::o5_startMusic,
- &Scumm::o5_getActorRoom,
- /* 04 */
- &Scumm::o5_isGreaterEqual,
- &Scumm::o5_drawObject,
- &Scumm::o5_getActorElevation,
- &Scumm::o5_setState,
- /* 08 */
- &Scumm::o5_isNotEqual,
- &Scumm::o5_faceActor,
- &Scumm::o5_startScript,
- &Scumm::o5_getVerbEntrypoint,
- /* 0C */
- &Scumm::o5_resourceRoutines,
- &Scumm::o5_walkActorToActor,
- &Scumm::o5_putActorAtObject,
- &Scumm::o5_getObjectState,
- /* 10 */
- &Scumm::o5_getObjectOwner,
- &Scumm::o5_animateActor,
- &Scumm::o5_panCameraTo,
- &Scumm::o5_actorSet,
- /* 14 */
- &Scumm::o5_print,
- &Scumm::o5_actorFromPos,
- &Scumm::o5_getRandomNr,
- &Scumm::o5_and,
- /* 18 */
- &Scumm::o5_jumpRelative,
- &Scumm::o5_doSentence,
- &Scumm::o5_move,
- &Scumm::o5_multiply,
- /* 1C */
- &Scumm::o5_startSound,
- &Scumm::o5_ifClassOfIs,
- &Scumm::o5_walkActorTo,
- &Scumm::o5_isActorInBox,
- /* 20 */
- &Scumm::o5_stopMusic,
- &Scumm::o5_putActor,
- &Scumm::o5_getAnimCounter,
- &Scumm::o5_getActorY,
- /* 24 */
- &Scumm::o5_loadRoomWithEgo,
- &Scumm::o5_pickupObject,
- &Scumm::o5_setVarRange,
- &Scumm::o5_stringOps,
- /* 28 */
- &Scumm::o5_equalZero,
- &Scumm::o5_setOwnerOf,
- &Scumm::o5_startScript,
- &Scumm::o5_delayVariable,
- /* 2C */
- &Scumm::o5_cursorCommand,
- &Scumm::o5_putActorInRoom,
- &Scumm::o5_delay,
- &Scumm::o5_getObjectState,
- /* 30 */
- &Scumm::o5_matrixOps,
- &Scumm::o5_getInventoryCount,
- &Scumm::o5_setCameraAt,
- &Scumm::o5_roomOps,
- /* 34 */
- &Scumm::o5_getDist,
- &Scumm::o5_findObject,
- &Scumm::o5_walkActorToObject,
- &Scumm::o5_startObject,
- /* 38 */
- &Scumm::o5_lessOrEqual,
- &Scumm::o5_doSentence,
- &Scumm::o5_subtract,
- &Scumm::o5_getActorScale,
- /* 3C */
- &Scumm::o5_stopSound,
- &Scumm::o5_findInventory,
- &Scumm::o5_walkActorTo,
- &Scumm::o5_drawBox,
- /* 40 */
- &Scumm::o5_cutscene,
- &Scumm::o5_putActor,
- &Scumm::o5_chainScript,
- &Scumm::o5_getActorX,
- /* 44 */
- &Scumm::o5_isLess,
- &Scumm::o5_drawObject,
- &Scumm::o5_increment,
- &Scumm::o5_setState,
- /* 48 */
- &Scumm::o5_isEqual,
- &Scumm::o5_faceActor,
- &Scumm::o5_startScript,
- &Scumm::o5_getVerbEntrypoint,
- /* 4C */
- &Scumm::o5_soundKludge,
- &Scumm::o5_walkActorToActor,
- &Scumm::o5_putActorAtObject,
- &Scumm::o5_badOpcode,
- /* 50 */
- &Scumm::o5_pickupObjectOld,
- &Scumm::o5_animateActor,
- &Scumm::o5_actorFollowCamera,
- &Scumm::o5_actorSet,
- /* 54 */
- &Scumm::o5_setObjectName,
- &Scumm::o5_actorFromPos,
- &Scumm::o5_getActorMoving,
- &Scumm::o5_or,
- /* 58 */
- &Scumm::o5_overRide,
- &Scumm::o5_doSentence,
- &Scumm::o5_add,
- &Scumm::o5_divide,
- /* 5C */
- &Scumm::o5_oldRoomEffect,
- &Scumm::o5_actorSetClass,
- &Scumm::o5_walkActorTo,
- &Scumm::o5_isActorInBox,
- /* 60 */
- &Scumm::o5_freezeScripts,
- &Scumm::o5_putActor,
- &Scumm::o5_stopScript,
- &Scumm::o5_getActorFacing,
- /* 64 */
- &Scumm::o5_loadRoomWithEgo,
- &Scumm::o5_pickupObject,
- &Scumm::o5_getClosestObjActor,
- &Scumm::o5_dummy,
- /* 68 */
- &Scumm::o5_getScriptRunning,
- &Scumm::o5_setOwnerOf,
- &Scumm::o5_startScript,
- &Scumm::o5_debug,
- /* 6C */
- &Scumm::o5_getActorWidth,
- &Scumm::o5_putActorInRoom,
- &Scumm::o5_stopObjectScript,
- &Scumm::o5_badOpcode,
- /* 70 */
- &Scumm::o5_lights,
- &Scumm::o5_getActorCostume,
- &Scumm::o5_loadRoom,
- &Scumm::o5_roomOps,
- /* 74 */
- &Scumm::o5_getDist,
- &Scumm::o5_findObject,
- &Scumm::o5_walkActorToObject,
- &Scumm::o5_startObject,
- /* 78 */
- &Scumm::o5_isGreater, /* less? */
- &Scumm::o5_doSentence,
- &Scumm::o5_verbOps,
- &Scumm::o5_getActorWalkBox,
- /* 7C */
- &Scumm::o5_isSoundRunning,
- &Scumm::o5_findInventory,
- &Scumm::o5_walkActorTo,
- &Scumm::o5_drawBox,
- /* 80 */
- &Scumm::o5_breakHere,
- &Scumm::o5_putActor,
- &Scumm::o5_startMusic,
- &Scumm::o5_getActorRoom,
- /* 84 */
- &Scumm::o5_isGreaterEqual, /* less equal? */
- &Scumm::o5_drawObject,
- &Scumm::o5_getActorElevation,
- &Scumm::o5_setState,
- /* 88 */
- &Scumm::o5_isNotEqual,
- &Scumm::o5_faceActor,
- &Scumm::o5_startScript,
- &Scumm::o5_getVerbEntrypoint,
- /* 8C */
- &Scumm::o5_resourceRoutines,
- &Scumm::o5_walkActorToActor,
- &Scumm::o5_putActorAtObject,
- &Scumm::o5_getObjectState,
- /* 90 */
- &Scumm::o5_getObjectOwner,
- &Scumm::o5_animateActor,
- &Scumm::o5_panCameraTo,
- &Scumm::o5_actorSet,
- /* 94 */
- &Scumm::o5_print,
- &Scumm::o5_actorFromPos,
- &Scumm::o5_getRandomNr,
- &Scumm::o5_and,
- /* 98 */
- &Scumm::o5_quitPauseRestart,
- &Scumm::o5_doSentence,
- &Scumm::o5_move,
- &Scumm::o5_multiply,
- /* 9C */
- &Scumm::o5_startSound,
- &Scumm::o5_ifClassOfIs,
- &Scumm::o5_walkActorTo,
- &Scumm::o5_isActorInBox,
- /* A0 */
- &Scumm::o5_stopObjectCode,
- &Scumm::o5_putActor,
- &Scumm::o5_getAnimCounter,
- &Scumm::o5_getActorY,
- /* A4 */
- &Scumm::o5_loadRoomWithEgo,
- &Scumm::o5_pickupObject,
- &Scumm::o5_setVarRange,
- &Scumm::o5_dummy,
- /* A8 */
- &Scumm::o5_notEqualZero,
- &Scumm::o5_setOwnerOf,
- &Scumm::o5_startScript,
- &Scumm::o5_saveRestoreVerbs,
- /* AC */
- &Scumm::o5_expression,
- &Scumm::o5_putActorInRoom,
- &Scumm::o5_wait,
- &Scumm::o5_badOpcode,
- /* B0 */
- &Scumm::o5_matrixOps,
- &Scumm::o5_getInventoryCount,
- &Scumm::o5_setCameraAt,
- &Scumm::o5_roomOps,
- /* B4 */
- &Scumm::o5_getDist,
- &Scumm::o5_findObject,
- &Scumm::o5_walkActorToObject,
- &Scumm::o5_startObject,
- /* B8 */
- &Scumm::o5_lessOrEqual,
- &Scumm::o5_doSentence,
- &Scumm::o5_subtract,
- &Scumm::o5_getActorScale,
- /* BC */
- &Scumm::o5_stopSound,
- &Scumm::o5_findInventory,
- &Scumm::o5_walkActorTo,
- &Scumm::o5_drawBox,
- /* C0 */
- &Scumm::o5_endCutscene,
- &Scumm::o5_putActor,
- &Scumm::o5_chainScript,
- &Scumm::o5_getActorX,
- /* C4 */
- &Scumm::o5_isLess,
- &Scumm::o5_drawObject,
- &Scumm::o5_decrement,
- &Scumm::o5_setState,
- /* C8 */
- &Scumm::o5_isEqual,
- &Scumm::o5_faceActor,
- &Scumm::o5_startScript,
- &Scumm::o5_getVerbEntrypoint,
- /* CC */
- &Scumm::o5_pseudoRoom,
- &Scumm::o5_walkActorToActor,
- &Scumm::o5_putActorAtObject,
- &Scumm::o5_badOpcode,
- /* D0 */
- &Scumm::o5_pickupObjectOld,
- &Scumm::o5_animateActor,
- &Scumm::o5_actorFollowCamera,
- &Scumm::o5_actorSet,
- /* D4 */
- &Scumm::o5_setObjectName,
- &Scumm::o5_actorFromPos,
- &Scumm::o5_getActorMoving,
- &Scumm::o5_or,
- /* D8 */
- &Scumm::o5_printEgo,
- &Scumm::o5_doSentence,
- &Scumm::o5_add,
- &Scumm::o5_divide,
- /* DC */
- &Scumm::o5_badOpcode,
- &Scumm::o5_actorSetClass,
- &Scumm::o5_walkActorTo,
- &Scumm::o5_isActorInBox,
- /* E0 */
- &Scumm::o5_freezeScripts,
- &Scumm::o5_putActor,
- &Scumm::o5_stopScript,
- &Scumm::o5_getActorFacing,
- /* E4 */
- &Scumm::o5_loadRoomWithEgo,
- &Scumm::o5_pickupObject,
- &Scumm::o5_getClosestObjActor,
- &Scumm::o5_dummy,
- /* E8 */
- &Scumm::o5_getScriptRunning,
- &Scumm::o5_setOwnerOf,
- &Scumm::o5_startScript,
- &Scumm::o5_debug,
- /* EC */
- &Scumm::o5_getActorWidth,
- &Scumm::o5_putActorInRoom,
- &Scumm::o5_stopObjectScript,
- &Scumm::o5_badOpcode,
- /* F0 */
- &Scumm::o5_lights,
- &Scumm::o5_getActorCostume,
- &Scumm::o5_loadRoom,
- &Scumm::o5_roomOps,
- /* F4 */
- &Scumm::o5_getDist,
- &Scumm::o5_findObject,
- &Scumm::o5_walkActorToObject,
- &Scumm::o5_startObject,
- /* F8 */
- &Scumm::o5_isGreater,
- &Scumm::o5_doSentence,
- &Scumm::o5_verbOps,
- &Scumm::o5_getActorWalkBox,
- /* FC */
- &Scumm::o5_isSoundRunning,
- &Scumm::o5_findInventory,
- &Scumm::o5_walkActorTo,
- &Scumm::o5_drawBox
+ /* 00 */
+ &Scumm::o5_stopObjectCode,
+ &Scumm::o5_putActor,
+ &Scumm::o5_startMusic,
+ &Scumm::o5_getActorRoom,
+ /* 04 */
+ &Scumm::o5_isGreaterEqual,
+ &Scumm::o5_drawObject,
+ &Scumm::o5_getActorElevation,
+ &Scumm::o5_setState,
+ /* 08 */
+ &Scumm::o5_isNotEqual,
+ &Scumm::o5_faceActor,
+ &Scumm::o5_startScript,
+ &Scumm::o5_getVerbEntrypoint,
+ /* 0C */
+ &Scumm::o5_resourceRoutines,
+ &Scumm::o5_walkActorToActor,
+ &Scumm::o5_putActorAtObject,
+ &Scumm::o5_getObjectState,
+ /* 10 */
+ &Scumm::o5_getObjectOwner,
+ &Scumm::o5_animateActor,
+ &Scumm::o5_panCameraTo,
+ &Scumm::o5_actorSet,
+ /* 14 */
+ &Scumm::o5_print,
+ &Scumm::o5_actorFromPos,
+ &Scumm::o5_getRandomNr,
+ &Scumm::o5_and,
+ /* 18 */
+ &Scumm::o5_jumpRelative,
+ &Scumm::o5_doSentence,
+ &Scumm::o5_move,
+ &Scumm::o5_multiply,
+ /* 1C */
+ &Scumm::o5_startSound,
+ &Scumm::o5_ifClassOfIs,
+ &Scumm::o5_walkActorTo,
+ &Scumm::o5_isActorInBox,
+ /* 20 */
+ &Scumm::o5_stopMusic,
+ &Scumm::o5_putActor,
+ &Scumm::o5_getAnimCounter,
+ &Scumm::o5_getActorY,
+ /* 24 */
+ &Scumm::o5_loadRoomWithEgo,
+ &Scumm::o5_pickupObject,
+ &Scumm::o5_setVarRange,
+ &Scumm::o5_stringOps,
+ /* 28 */
+ &Scumm::o5_equalZero,
+ &Scumm::o5_setOwnerOf,
+ &Scumm::o5_startScript,
+ &Scumm::o5_delayVariable,
+ /* 2C */
+ &Scumm::o5_cursorCommand,
+ &Scumm::o5_putActorInRoom,
+ &Scumm::o5_delay,
+ &Scumm::o5_getObjectState,
+ /* 30 */
+ &Scumm::o5_matrixOps,
+ &Scumm::o5_getInventoryCount,
+ &Scumm::o5_setCameraAt,
+ &Scumm::o5_roomOps,
+ /* 34 */
+ &Scumm::o5_getDist,
+ &Scumm::o5_findObject,
+ &Scumm::o5_walkActorToObject,
+ &Scumm::o5_startObject,
+ /* 38 */
+ &Scumm::o5_lessOrEqual,
+ &Scumm::o5_doSentence,
+ &Scumm::o5_subtract,
+ &Scumm::o5_getActorScale,
+ /* 3C */
+ &Scumm::o5_stopSound,
+ &Scumm::o5_findInventory,
+ &Scumm::o5_walkActorTo,
+ &Scumm::o5_drawBox,
+ /* 40 */
+ &Scumm::o5_cutscene,
+ &Scumm::o5_putActor,
+ &Scumm::o5_chainScript,
+ &Scumm::o5_getActorX,
+ /* 44 */
+ &Scumm::o5_isLess,
+ &Scumm::o5_drawObject,
+ &Scumm::o5_increment,
+ &Scumm::o5_setState,
+ /* 48 */
+ &Scumm::o5_isEqual,
+ &Scumm::o5_faceActor,
+ &Scumm::o5_startScript,
+ &Scumm::o5_getVerbEntrypoint,
+ /* 4C */
+ &Scumm::o5_soundKludge,
+ &Scumm::o5_walkActorToActor,
+ &Scumm::o5_putActorAtObject,
+ &Scumm::o5_badOpcode,
+ /* 50 */
+ &Scumm::o5_pickupObjectOld,
+ &Scumm::o5_animateActor,
+ &Scumm::o5_actorFollowCamera,
+ &Scumm::o5_actorSet,
+ /* 54 */
+ &Scumm::o5_setObjectName,
+ &Scumm::o5_actorFromPos,
+ &Scumm::o5_getActorMoving,
+ &Scumm::o5_or,
+ /* 58 */
+ &Scumm::o5_overRide,
+ &Scumm::o5_doSentence,
+ &Scumm::o5_add,
+ &Scumm::o5_divide,
+ /* 5C */
+ &Scumm::o5_oldRoomEffect,
+ &Scumm::o5_actorSetClass,
+ &Scumm::o5_walkActorTo,
+ &Scumm::o5_isActorInBox,
+ /* 60 */
+ &Scumm::o5_freezeScripts,
+ &Scumm::o5_putActor,
+ &Scumm::o5_stopScript,
+ &Scumm::o5_getActorFacing,
+ /* 64 */
+ &Scumm::o5_loadRoomWithEgo,
+ &Scumm::o5_pickupObject,
+ &Scumm::o5_getClosestObjActor,
+ &Scumm::o5_dummy,
+ /* 68 */
+ &Scumm::o5_getScriptRunning,
+ &Scumm::o5_setOwnerOf,
+ &Scumm::o5_startScript,
+ &Scumm::o5_debug,
+ /* 6C */
+ &Scumm::o5_getActorWidth,
+ &Scumm::o5_putActorInRoom,
+ &Scumm::o5_stopObjectScript,
+ &Scumm::o5_badOpcode,
+ /* 70 */
+ &Scumm::o5_lights,
+ &Scumm::o5_getActorCostume,
+ &Scumm::o5_loadRoom,
+ &Scumm::o5_roomOps,
+ /* 74 */
+ &Scumm::o5_getDist,
+ &Scumm::o5_findObject,
+ &Scumm::o5_walkActorToObject,
+ &Scumm::o5_startObject,
+ /* 78 */
+ &Scumm::o5_isGreater, /* less? */
+ &Scumm::o5_doSentence,
+ &Scumm::o5_verbOps,
+ &Scumm::o5_getActorWalkBox,
+ /* 7C */
+ &Scumm::o5_isSoundRunning,
+ &Scumm::o5_findInventory,
+ &Scumm::o5_walkActorTo,
+ &Scumm::o5_drawBox,
+ /* 80 */
+ &Scumm::o5_breakHere,
+ &Scumm::o5_putActor,
+ &Scumm::o5_startMusic,
+ &Scumm::o5_getActorRoom,
+ /* 84 */
+ &Scumm::o5_isGreaterEqual, /* less equal? */
+ &Scumm::o5_drawObject,
+ &Scumm::o5_getActorElevation,
+ &Scumm::o5_setState,
+ /* 88 */
+ &Scumm::o5_isNotEqual,
+ &Scumm::o5_faceActor,
+ &Scumm::o5_startScript,
+ &Scumm::o5_getVerbEntrypoint,
+ /* 8C */
+ &Scumm::o5_resourceRoutines,
+ &Scumm::o5_walkActorToActor,
+ &Scumm::o5_putActorAtObject,
+ &Scumm::o5_getObjectState,
+ /* 90 */
+ &Scumm::o5_getObjectOwner,
+ &Scumm::o5_animateActor,
+ &Scumm::o5_panCameraTo,
+ &Scumm::o5_actorSet,
+ /* 94 */
+ &Scumm::o5_print,
+ &Scumm::o5_actorFromPos,
+ &Scumm::o5_getRandomNr,
+ &Scumm::o5_and,
+ /* 98 */
+ &Scumm::o5_quitPauseRestart,
+ &Scumm::o5_doSentence,
+ &Scumm::o5_move,
+ &Scumm::o5_multiply,
+ /* 9C */
+ &Scumm::o5_startSound,
+ &Scumm::o5_ifClassOfIs,
+ &Scumm::o5_walkActorTo,
+ &Scumm::o5_isActorInBox,
+ /* A0 */
+ &Scumm::o5_stopObjectCode,
+ &Scumm::o5_putActor,
+ &Scumm::o5_getAnimCounter,
+ &Scumm::o5_getActorY,
+ /* A4 */
+ &Scumm::o5_loadRoomWithEgo,
+ &Scumm::o5_pickupObject,
+ &Scumm::o5_setVarRange,
+ &Scumm::o5_dummy,
+ /* A8 */
+ &Scumm::o5_notEqualZero,
+ &Scumm::o5_setOwnerOf,
+ &Scumm::o5_startScript,
+ &Scumm::o5_saveRestoreVerbs,
+ /* AC */
+ &Scumm::o5_expression,
+ &Scumm::o5_putActorInRoom,
+ &Scumm::o5_wait,
+ &Scumm::o5_badOpcode,
+ /* B0 */
+ &Scumm::o5_matrixOps,
+ &Scumm::o5_getInventoryCount,
+ &Scumm::o5_setCameraAt,
+ &Scumm::o5_roomOps,
+ /* B4 */
+ &Scumm::o5_getDist,
+ &Scumm::o5_findObject,
+ &Scumm::o5_walkActorToObject,
+ &Scumm::o5_startObject,
+ /* B8 */
+ &Scumm::o5_lessOrEqual,
+ &Scumm::o5_doSentence,
+ &Scumm::o5_subtract,
+ &Scumm::o5_getActorScale,
+ /* BC */
+ &Scumm::o5_stopSound,
+ &Scumm::o5_findInventory,
+ &Scumm::o5_walkActorTo,
+ &Scumm::o5_drawBox,
+ /* C0 */
+ &Scumm::o5_endCutscene,
+ &Scumm::o5_putActor,
+ &Scumm::o5_chainScript,
+ &Scumm::o5_getActorX,
+ /* C4 */
+ &Scumm::o5_isLess,
+ &Scumm::o5_drawObject,
+ &Scumm::o5_decrement,
+ &Scumm::o5_setState,
+ /* C8 */
+ &Scumm::o5_isEqual,
+ &Scumm::o5_faceActor,
+ &Scumm::o5_startScript,
+ &Scumm::o5_getVerbEntrypoint,
+ /* CC */
+ &Scumm::o5_pseudoRoom,
+ &Scumm::o5_walkActorToActor,
+ &Scumm::o5_putActorAtObject,
+ &Scumm::o5_badOpcode,
+ /* D0 */
+ &Scumm::o5_pickupObjectOld,
+ &Scumm::o5_animateActor,
+ &Scumm::o5_actorFollowCamera,
+ &Scumm::o5_actorSet,
+ /* D4 */
+ &Scumm::o5_setObjectName,
+ &Scumm::o5_actorFromPos,
+ &Scumm::o5_getActorMoving,
+ &Scumm::o5_or,
+ /* D8 */
+ &Scumm::o5_printEgo,
+ &Scumm::o5_doSentence,
+ &Scumm::o5_add,
+ &Scumm::o5_divide,
+ /* DC */
+ &Scumm::o5_badOpcode,
+ &Scumm::o5_actorSetClass,
+ &Scumm::o5_walkActorTo,
+ &Scumm::o5_isActorInBox,
+ /* E0 */
+ &Scumm::o5_freezeScripts,
+ &Scumm::o5_putActor,
+ &Scumm::o5_stopScript,
+ &Scumm::o5_getActorFacing,
+ /* E4 */
+ &Scumm::o5_loadRoomWithEgo,
+ &Scumm::o5_pickupObject,
+ &Scumm::o5_getClosestObjActor,
+ &Scumm::o5_dummy,
+ /* E8 */
+ &Scumm::o5_getScriptRunning,
+ &Scumm::o5_setOwnerOf,
+ &Scumm::o5_startScript,
+ &Scumm::o5_debug,
+ /* EC */
+ &Scumm::o5_getActorWidth,
+ &Scumm::o5_putActorInRoom,
+ &Scumm::o5_stopObjectScript,
+ &Scumm::o5_badOpcode,
+ /* F0 */
+ &Scumm::o5_lights,
+ &Scumm::o5_getActorCostume,
+ &Scumm::o5_loadRoom,
+ &Scumm::o5_roomOps,
+ /* F4 */
+ &Scumm::o5_getDist,
+ &Scumm::o5_findObject,
+ &Scumm::o5_walkActorToObject,
+ &Scumm::o5_startObject,
+ /* F8 */
+ &Scumm::o5_isGreater,
+ &Scumm::o5_doSentence,
+ &Scumm::o5_verbOps,
+ &Scumm::o5_getActorWalkBox,
+ /* FC */
+ &Scumm::o5_isSoundRunning,
+ &Scumm::o5_findInventory,
+ &Scumm::o5_walkActorTo,
+ &Scumm::o5_drawBox
};
-static const char* opcode_lookup[] = {
- /* 00 */
- "o5_stopObjectCode",
- "o5_putActor",
- "o5_startMusic",
- "o5_getActorRoom",
- /* 04 */
- "o5_isGreaterEqual",
- "o5_drawObject",
- "o5_getActorElevation",
- "o5_setState",
- /* 08 */
- "o5_isNotEqual",
- "o5_faceActor",
- "o5_startScript",
- "o5_getVerbEntrypoint",
- /* 0C */
- "o5_resourceRoutines",
- "o5_walkActorToActor",
- "o5_putActorAtObject",
- "o5_getObjectState",
- /* 10 */
- "o5_getObjectOwner",
- "o5_animateActor",
- "o5_panCameraTo",
- "o5_actorSet",
- /* 14 */
- "o5_print",
- "o5_actorFromPos",
- "o5_getRandomNr",
- "o5_and",
- /* 18 */
- "o5_jumpRelative",
- "o5_doSentence",
- "o5_move",
- "o5_multiply",
- /* 1C */
- "o5_startSound",
- "o5_ifClassOfIs",
- "o5_walkActorTo",
- "o5_isActorInBox",
- /* 20 */
- "o5_stopMusic",
- "o5_putActor",
- "o5_getAnimCounter",
- "o5_getActorY",
- /* 24 */
- "o5_loadRoomWithEgo",
- "o5_pickupObject",
- "o5_setVarRange",
- "o5_stringOps",
- /* 28 */
- "o5_equalZero",
- "o5_setOwnerOf",
- "o5_startScript",
- "o5_delayVariable",
- /* 2C */
- "o5_cursorCommand",
- "o5_putActorInRoom",
- "o5_delay",
- "o5_badOpcode",
- /* 30 */
- "o5_matrixOps",
- "o5_getInventoryCount",
- "o5_setCameraAt",
- "o5_roomOps",
- /* 34 */
- "o5_getDist",
- "o5_findObject",
- "o5_walkActorToObject",
- "o5_startObject",
- /* 38 */
- "o5_lessOrEqual",
- "o5_doSentence",
- "o5_subtract",
- "o5_getActorScale",
- /* 3C */
- "o5_stopSound",
- "o5_findInventory",
- "o5_walkActorTo",
- "o5_drawBox",
- /* 40 */
- "o5_cutscene",
- "o5_putActor",
- "o5_chainScript",
- "o5_getActorX",
- /* 44 */
- "o5_isLess",
- "o5_badOpcode",
- "o5_increment",
- "o5_setState",
- /* 48 */
- "o5_isEqual",
- "o5_faceActor",
- "o5_startScript",
- "o5_getVerbEntrypoint",
- /* 4C */
- "o5_soundKludge",
- "o5_walkActorToActor",
- "o5_putActorAtObject",
- "o5_badOpcode",
- /* 50 */
- "o5_pickupObjectOld",
- "o5_animateActor",
- "o5_actorFollowCamera",
- "o5_actorSet",
- /* 54 */
- "o5_setObjectName",
- "o5_actorFromPos",
- "o5_getActorMoving",
- "o5_or",
- /* 58 */
- "o5_overRide",
- "o5_doSentence",
- "o5_add",
- "o5_divide",
- /* 5C */
- "o5_oldRoomEffect",
- "o5_actorSetClass",
- "o5_walkActorTo",
- "o5_isActorInBox",
- /* 60 */
- "o5_freezeScripts",
- "o5_putActor",
- "o5_stopScript",
- "o5_getActorFacing",
- /* 64 */
- "o5_loadRoomWithEgo",
- "o5_pickupObject",
- "o5_getClosestObjActor",
- "o5_dummy",
- /* 68 */
- "o5_getScriptRunning",
- "o5_setOwnerOf",
- "o5_startScript",
- "o5_debug",
- /* 6C */
- "o5_getActorWidth",
- "o5_putActorInRoom",
- "o5_stopObjectScript",
- "o5_badOpcode",
- /* 70 */
- "o5_lights",
- "o5_getActorCostume",
- "o5_loadRoom",
- "o5_roomOps",
- /* 74 */
- "o5_getDist",
- "o5_findObject",
- "o5_walkActorToObject",
- "o5_startObject",
- /* 78 */
- "o5_isGreater", /* less? */
- "o5_doSentence",
- "o5_verbOps",
- "o5_getActorWalkBox",
- /* 7C */
- "o5_isSoundRunning",
- "o5_findInventory",
- "o5_walkActorTo",
- "o5_drawBox",
- /* 80 */
- "o5_breakHere",
- "o5_putActor",
- "o5_startMusic",
- "o5_getActorRoom",
- /* 84 */
- "o5_isGreaterEqual", /* less equal? */
- "o5_drawObject",
- "o5_getActorElevation",
- "o5_setState",
- /* 88 */
- "o5_isNotEqual",
- "o5_faceActor",
- "o5_startScript",
- "o5_getVerbEntrypoint",
- /* 8C */
- "o5_resourceRoutines",
- "o5_walkActorToActor",
- "o5_putActorAtObject",
- "o5_getObjectState",
- /* 90 */
- "o5_getObjectOwner",
- "o5_animateActor",
- "o5_panCameraTo",
- "o5_actorSet",
- /* 94 */
- "o5_print",
- "o5_actorFromPos",
- "o5_getRandomNr",
- "o5_and",
- /* 98 */
- "o5_quitPauseRestart",
- "o5_doSentence",
- "o5_move",
- "o5_multiply",
- /* 9C */
- "o5_startSound",
- "o5_ifClassOfIs",
- "o5_walkActorTo",
- "o5_isActorInBox",
- /* A0 */
- "o5_stopObjectCode",
- "o5_putActor",
- "o5_getAnimCounter",
- "o5_getActorY",
- /* A4 */
- "o5_loadRoomWithEgo",
- "o5_pickupObject",
- "o5_setVarRange",
- "o5_dummy",
- /* A8 */
- "o5_notEqualZero",
- "o5_setOwnerOf",
- "o5_startScript",
- "o5_saveRestoreVerbs",
- /* AC */
- "o5_expression",
- "o5_putActorInRoom",
- "o5_wait",
- "o5_badOpcode",
- /* B0 */
- "o5_matrixOps",
- "o5_getInventoryCount",
- "o5_setCameraAt",
- "o5_roomOps",
- /* B4 */
- "o5_getDist",
- "o5_findObject",
- "o5_walkActorToObject",
- "o5_startObject",
- /* B8 */
- "o5_lessOrEqual",
- "o5_doSentence",
- "o5_subtract",
- "o5_getActorScale",
- /* BC */
- "o5_stopSound",
- "o5_findInventory",
- "o5_walkActorTo",
- "o5_drawBox",
- /* C0 */
- "o5_endCutscene",
- "o5_putActor",
- "o5_chainScript",
- "o5_getActorX",
- /* C4 */
- "o5_isLess",
- "o5_badOpcode",
- "o5_decrement",
- "o5_setState",
- /* C8 */
- "o5_isEqual",
- "o5_faceActor",
- "o5_startScript",
- "o5_getVerbEntrypoint",
- /* CC */
- "o5_pseudoRoom",
- "o5_walkActorToActor",
- "o5_putActorAtObject",
- "o5_badOpcode",
- /* D0 */
- "o5_pickupObjectOld",
- "o5_animateActor",
- "o5_actorFollowCamera",
- "o5_actorSet",
- /* D4 */
- "o5_setObjectName",
- "o5_actorFromPos",
- "o5_getActorMoving",
- "o5_or",
- /* D8 */
- "o5_printEgo",
- "o5_doSentence",
- "o5_add",
- "o5_divide",
- /* DC */
- "o5_badOpcode",
- "o5_actorSetClass",
- "o5_walkActorTo",
- "o5_isActorInBox",
- /* E0 */
- "o5_freezeScripts",
- "o5_putActor",
- "o5_stopScript",
- "o5_getActorFacing",
- /* E4 */
- "o5_loadRoomWithEgo",
- "o5_pickupObject",
- "o5_getClosestObjActor",
- "o5_dummy",
- /* E8 */
- "o5_getScriptRunning",
- "o5_setOwnerOf",
- "o5_startScript",
- "o5_debug",
- /* EC */
- "o5_getActorWidth",
- "o5_putActorInRoom",
- "o5_stopObjectScript",
- "o5_badOpcode",
- /* F0 */
- "o5_lights",
- "o5_getActorCostume",
- "o5_loadRoom",
- "o5_roomOps",
- /* F4 */
- "o5_getDist",
- "o5_findObject",
- "o5_walkActorToObject",
- "o5_startObject",
- /* F8 */
- "o5_isGreater",
- "o5_doSentence",
- "o5_verbOps",
- "o5_getActorWalkBox",
- /* FC */
- "o5_isSoundRunning",
- "o5_findInventory",
- "o5_walkActorTo",
- "o5_drawBox",
+ static const char *opcode_lookup[] = {
+ /* 00 */
+ "o5_stopObjectCode",
+ "o5_putActor",
+ "o5_startMusic",
+ "o5_getActorRoom",
+ /* 04 */
+ "o5_isGreaterEqual",
+ "o5_drawObject",
+ "o5_getActorElevation",
+ "o5_setState",
+ /* 08 */
+ "o5_isNotEqual",
+ "o5_faceActor",
+ "o5_startScript",
+ "o5_getVerbEntrypoint",
+ /* 0C */
+ "o5_resourceRoutines",
+ "o5_walkActorToActor",
+ "o5_putActorAtObject",
+ "o5_getObjectState",
+ /* 10 */
+ "o5_getObjectOwner",
+ "o5_animateActor",
+ "o5_panCameraTo",
+ "o5_actorSet",
+ /* 14 */
+ "o5_print",
+ "o5_actorFromPos",
+ "o5_getRandomNr",
+ "o5_and",
+ /* 18 */
+ "o5_jumpRelative",
+ "o5_doSentence",
+ "o5_move",
+ "o5_multiply",
+ /* 1C */
+ "o5_startSound",
+ "o5_ifClassOfIs",
+ "o5_walkActorTo",
+ "o5_isActorInBox",
+ /* 20 */
+ "o5_stopMusic",
+ "o5_putActor",
+ "o5_getAnimCounter",
+ "o5_getActorY",
+ /* 24 */
+ "o5_loadRoomWithEgo",
+ "o5_pickupObject",
+ "o5_setVarRange",
+ "o5_stringOps",
+ /* 28 */
+ "o5_equalZero",
+ "o5_setOwnerOf",
+ "o5_startScript",
+ "o5_delayVariable",
+ /* 2C */
+ "o5_cursorCommand",
+ "o5_putActorInRoom",
+ "o5_delay",
+ "o5_badOpcode",
+ /* 30 */
+ "o5_matrixOps",
+ "o5_getInventoryCount",
+ "o5_setCameraAt",
+ "o5_roomOps",
+ /* 34 */
+ "o5_getDist",
+ "o5_findObject",
+ "o5_walkActorToObject",
+ "o5_startObject",
+ /* 38 */
+ "o5_lessOrEqual",
+ "o5_doSentence",
+ "o5_subtract",
+ "o5_getActorScale",
+ /* 3C */
+ "o5_stopSound",
+ "o5_findInventory",
+ "o5_walkActorTo",
+ "o5_drawBox",
+ /* 40 */
+ "o5_cutscene",
+ "o5_putActor",
+ "o5_chainScript",
+ "o5_getActorX",
+ /* 44 */
+ "o5_isLess",
+ "o5_badOpcode",
+ "o5_increment",
+ "o5_setState",
+ /* 48 */
+ "o5_isEqual",
+ "o5_faceActor",
+ "o5_startScript",
+ "o5_getVerbEntrypoint",
+ /* 4C */
+ "o5_soundKludge",
+ "o5_walkActorToActor",
+ "o5_putActorAtObject",
+ "o5_badOpcode",
+ /* 50 */
+ "o5_pickupObjectOld",
+ "o5_animateActor",
+ "o5_actorFollowCamera",
+ "o5_actorSet",
+ /* 54 */
+ "o5_setObjectName",
+ "o5_actorFromPos",
+ "o5_getActorMoving",
+ "o5_or",
+ /* 58 */
+ "o5_overRide",
+ "o5_doSentence",
+ "o5_add",
+ "o5_divide",
+ /* 5C */
+ "o5_oldRoomEffect",
+ "o5_actorSetClass",
+ "o5_walkActorTo",
+ "o5_isActorInBox",
+ /* 60 */
+ "o5_freezeScripts",
+ "o5_putActor",
+ "o5_stopScript",
+ "o5_getActorFacing",
+ /* 64 */
+ "o5_loadRoomWithEgo",
+ "o5_pickupObject",
+ "o5_getClosestObjActor",
+ "o5_dummy",
+ /* 68 */
+ "o5_getScriptRunning",
+ "o5_setOwnerOf",
+ "o5_startScript",
+ "o5_debug",
+ /* 6C */
+ "o5_getActorWidth",
+ "o5_putActorInRoom",
+ "o5_stopObjectScript",
+ "o5_badOpcode",
+ /* 70 */
+ "o5_lights",
+ "o5_getActorCostume",
+ "o5_loadRoom",
+ "o5_roomOps",
+ /* 74 */
+ "o5_getDist",
+ "o5_findObject",
+ "o5_walkActorToObject",
+ "o5_startObject",
+ /* 78 */
+ "o5_isGreater", /* less? */
+ "o5_doSentence",
+ "o5_verbOps",
+ "o5_getActorWalkBox",
+ /* 7C */
+ "o5_isSoundRunning",
+ "o5_findInventory",
+ "o5_walkActorTo",
+ "o5_drawBox",
+ /* 80 */
+ "o5_breakHere",
+ "o5_putActor",
+ "o5_startMusic",
+ "o5_getActorRoom",
+ /* 84 */
+ "o5_isGreaterEqual", /* less equal? */
+ "o5_drawObject",
+ "o5_getActorElevation",
+ "o5_setState",
+ /* 88 */
+ "o5_isNotEqual",
+ "o5_faceActor",
+ "o5_startScript",
+ "o5_getVerbEntrypoint",
+ /* 8C */
+ "o5_resourceRoutines",
+ "o5_walkActorToActor",
+ "o5_putActorAtObject",
+ "o5_getObjectState",
+ /* 90 */
+ "o5_getObjectOwner",
+ "o5_animateActor",
+ "o5_panCameraTo",
+ "o5_actorSet",
+ /* 94 */
+ "o5_print",
+ "o5_actorFromPos",
+ "o5_getRandomNr",
+ "o5_and",
+ /* 98 */
+ "o5_quitPauseRestart",
+ "o5_doSentence",
+ "o5_move",
+ "o5_multiply",
+ /* 9C */
+ "o5_startSound",
+ "o5_ifClassOfIs",
+ "o5_walkActorTo",
+ "o5_isActorInBox",
+ /* A0 */
+ "o5_stopObjectCode",
+ "o5_putActor",
+ "o5_getAnimCounter",
+ "o5_getActorY",
+ /* A4 */
+ "o5_loadRoomWithEgo",
+ "o5_pickupObject",
+ "o5_setVarRange",
+ "o5_dummy",
+ /* A8 */
+ "o5_notEqualZero",
+ "o5_setOwnerOf",
+ "o5_startScript",
+ "o5_saveRestoreVerbs",
+ /* AC */
+ "o5_expression",
+ "o5_putActorInRoom",
+ "o5_wait",
+ "o5_badOpcode",
+ /* B0 */
+ "o5_matrixOps",
+ "o5_getInventoryCount",
+ "o5_setCameraAt",
+ "o5_roomOps",
+ /* B4 */
+ "o5_getDist",
+ "o5_findObject",
+ "o5_walkActorToObject",
+ "o5_startObject",
+ /* B8 */
+ "o5_lessOrEqual",
+ "o5_doSentence",
+ "o5_subtract",
+ "o5_getActorScale",
+ /* BC */
+ "o5_stopSound",
+ "o5_findInventory",
+ "o5_walkActorTo",
+ "o5_drawBox",
+ /* C0 */
+ "o5_endCutscene",
+ "o5_putActor",
+ "o5_chainScript",
+ "o5_getActorX",
+ /* C4 */
+ "o5_isLess",
+ "o5_badOpcode",
+ "o5_decrement",
+ "o5_setState",
+ /* C8 */
+ "o5_isEqual",
+ "o5_faceActor",
+ "o5_startScript",
+ "o5_getVerbEntrypoint",
+ /* CC */
+ "o5_pseudoRoom",
+ "o5_walkActorToActor",
+ "o5_putActorAtObject",
+ "o5_badOpcode",
+ /* D0 */
+ "o5_pickupObjectOld",
+ "o5_animateActor",
+ "o5_actorFollowCamera",
+ "o5_actorSet",
+ /* D4 */
+ "o5_setObjectName",
+ "o5_actorFromPos",
+ "o5_getActorMoving",
+ "o5_or",
+ /* D8 */
+ "o5_printEgo",
+ "o5_doSentence",
+ "o5_add",
+ "o5_divide",
+ /* DC */
+ "o5_badOpcode",
+ "o5_actorSetClass",
+ "o5_walkActorTo",
+ "o5_isActorInBox",
+ /* E0 */
+ "o5_freezeScripts",
+ "o5_putActor",
+ "o5_stopScript",
+ "o5_getActorFacing",
+ /* E4 */
+ "o5_loadRoomWithEgo",
+ "o5_pickupObject",
+ "o5_getClosestObjActor",
+ "o5_dummy",
+ /* E8 */
+ "o5_getScriptRunning",
+ "o5_setOwnerOf",
+ "o5_startScript",
+ "o5_debug",
+ /* EC */
+ "o5_getActorWidth",
+ "o5_putActorInRoom",
+ "o5_stopObjectScript",
+ "o5_badOpcode",
+ /* F0 */
+ "o5_lights",
+ "o5_getActorCostume",
+ "o5_loadRoom",
+ "o5_roomOps",
+ /* F4 */
+ "o5_getDist",
+ "o5_findObject",
+ "o5_walkActorToObject",
+ "o5_startObject",
+ /* F8 */
+ "o5_isGreater",
+ "o5_doSentence",
+ "o5_verbOps",
+ "o5_getActorWalkBox",
+ /* FC */
+ "o5_isSoundRunning",
+ "o5_findInventory",
+ "o5_walkActorTo",
+ "o5_drawBox",
};
@@ -677,134 +678,139 @@ static const char* opcode_lookup[] = {
_opcodes_lookup = opcode_lookup;
}
-void Scumm::o5_actorFollowCamera() {
+void Scumm::o5_actorFollowCamera()
+{
actorFollowCamera(getVarOrDirectByte(0x80));
}
-void Scumm::o5_actorFromPos() {
- int x,y;
+void Scumm::o5_actorFromPos()
+{
+ int x, y;
getResultPos();
x = getVarOrDirectWord(0x80);
y = getVarOrDirectWord(0x40);
- setResult(getActorFromPos(x,y));
+ setResult(getActorFromPos(x, y));
}
-void Scumm::o5_actorSet() {
- static const byte convertTable[20] = {1,0,0,2,0,4,5,6,7,8,9,10,11,12,13,14,15,16,17,20};
+void Scumm::o5_actorSet()
+{
+ static const byte convertTable[20] =
+ { 1, 0, 0, 2, 0, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 20 };
int act = getVarOrDirectByte(0x80);
Actor *a;
- int i,j;
+ int i, j;
- if (act == 0)
+ if (act == 0)
act = 1;
a = derefActorSafe(act, "actorSet");
-
- while ( (_opcode = fetchScriptByte()) != 0xFF) {
- if(_features & GF_SMALL_HEADER)
- _opcode = (_opcode&0xE0) | convertTable[(_opcode&0x1F)-1];
-
- if (!a) return;
-
- switch(_opcode&0x1F) {
- case 0: /* dummy case */
+
+ while ((_opcode = fetchScriptByte()) != 0xFF) {
+ if (_features & GF_SMALL_HEADER)
+ _opcode = (_opcode & 0xE0) | convertTable[(_opcode & 0x1F) - 1];
+
+ if (!a)
+ return;
+
+ switch (_opcode & 0x1F) {
+ case 0: /* dummy case */
getVarOrDirectByte(0x80);
break;
- case 1: /* costume */
+ case 1: /* costume */
setActorCostume(a, getVarOrDirectByte(0x80));
break;
- case 2: /* walkspeed */
+ case 2: /* walkspeed */
i = getVarOrDirectByte(0x80);
j = getVarOrDirectByte(0x40);
setActorWalkSpeed(a, i, j);
break;
- case 3: /* sound */
+ case 3: /* sound */
a->sound[0] = getVarOrDirectByte(0x80);
break;
- case 4: /* walkanim */
+ case 4: /* walkanim */
a->walkFrame = getVarOrDirectByte(0x80);
break;
- case 5: /* talkanim */
+ case 5: /* talkanim */
a->talkFrame1 = getVarOrDirectByte(0x80);
a->talkFrame2 = getVarOrDirectByte(0x40);
break;
- case 6: /* standanim */
+ case 6: /* standanim */
a->standFrame = getVarOrDirectByte(0x80);
break;
- case 7: /* ignore */
+ case 7: /* ignore */
getVarOrDirectByte(0x80);
getVarOrDirectByte(0x40);
getVarOrDirectByte(0x20);
break;
- case 8: /* init */
+ case 8: /* init */
initActor(a, 0);
break;
- case 9: /* elevation */
+ case 9: /* elevation */
a->elevation = getVarOrDirectWord(0x80);
a->needRedraw = true;
a->needBgReset = true;
break;
- case 10: /* defaultanims */
+ case 10: /* defaultanims */
a->initFrame = 1;
a->walkFrame = 2;
a->standFrame = 3;
a->talkFrame1 = 4;
a->talkFrame2 = 5;
break;
- case 11: /* palette */
+ case 11: /* palette */
i = getVarOrDirectByte(0x80);
j = getVarOrDirectByte(0x40);
checkRange(31, 0, i, "Illegal palet slot %d");
a->palette[i] = j;
a->needRedraw = true;
break;
- case 12: /* talk color */
+ case 12: /* talk color */
a->talkColor = getVarOrDirectByte(0x80);
break;
- case 13: /* name */
+ case 13: /* name */
loadPtrToResource(rtActorName, a->number, NULL);
break;
- case 14: /* initanim */
+ case 14: /* initanim */
a->initFrame = getVarOrDirectByte(0x80);
break;
- case 15: /* unk */
+ case 15: /* unk */
error("o5_actorset:unk not implemented");
break;
- case 16: /* width */
+ case 16: /* width */
a->width = getVarOrDirectByte(0x80);
break;
- case 17: /* scale */
+ case 17: /* scale */
a->scalex = getVarOrDirectByte(0x80);
a->scaley = getVarOrDirectByte(0x40);
- if(a->scalex>255 || a->scaley>255)
+ if (a->scalex > 255 || a->scaley > 255)
error("Setting an bad actor scale!");
a->needRedraw = true;
a->needBgReset = true;
break;
- case 18: /* neverzclip */
+ case 18: /* neverzclip */
a->forceClip = 0;
break;
- case 19: /* setzclip */
+ case 19: /* setzclip */
a->forceClip = getVarOrDirectByte(0x80);
break;
- case 20: /* ignoreboxes */
+ case 20: /* ignoreboxes */
a->ignoreBoxes = 1;
a->forceClip = 0;
-FixRoom:
- if (a->room==_currentRoom)
+ FixRoom:
+ if (a->room == _currentRoom)
putActor(a, a->x, a->y, a->room);
break;
- case 21: /* followboxes */
+ case 21: /* followboxes */
a->ignoreBoxes = 0;
a->forceClip = 0;
goto FixRoom;
- case 22: /* animspeed */
+ case 22: /* animspeed */
a->animSpeed = getVarOrDirectByte(0x80);
a->animProgress = 0;
break;
- case 23: /* unk2 */
- a->shadow_mode = getVarOrDirectByte(0x80); /* shadow mode */
+ case 23: /* unk2 */
+ a->shadow_mode = getVarOrDirectByte(0x80); /* shadow mode */
break;
default:
warning("o5_actorSet: default case");
@@ -812,56 +818,63 @@ FixRoom:
}
}
-void Scumm::o5_actorSetClass() {
+void Scumm::o5_actorSetClass()
+{
int act = getVarOrDirectWord(0x80);
int newClass;
- while ( (_opcode=fetchScriptByte()) != 0xFF) {
+ while ((_opcode = fetchScriptByte()) != 0xFF) {
newClass = getVarOrDirectWord(0x80);
- if (newClass==0) {
+ if (newClass == 0) {
_classData[act] = 0;
continue;
}
- if (newClass&0x80)
+ if (newClass & 0x80)
putClass(act, newClass, 1);
else
putClass(act, newClass, 0);
}
}
-void Scumm::o5_add() {
+void Scumm::o5_add()
+{
int a;
getResultPos();
a = getVarOrDirectWord(0x80);
setResult(readVar(_resultVarNumber) + a);
}
-void Scumm::o5_and() {
+void Scumm::o5_and()
+{
int a;
getResultPos();
a = getVarOrDirectWord(0x80);
setResult(readVar(_resultVarNumber) & a);
}
-void Scumm::o5_animateActor() {
+void Scumm::o5_animateActor()
+{
int act, anim;
act = getVarOrDirectByte(0x80);
anim = getVarOrDirectByte(0x40);
- animateActor(act,anim);
+ animateActor(act, anim);
}
-void Scumm::o5_badOpcode() {
+void Scumm::o5_badOpcode()
+{
error("Scumm opcode %d illegal", _opcode);
}
-void Scumm::o5_breakHere() {
+void Scumm::o5_breakHere()
+{
updateScriptPtr();
_currentScript = 0xFF;
}
-void Scumm::o5_chainScript() {
+void Scumm::o5_chainScript()
+{
int16 vars[16];
int data;
int cur;
@@ -873,7 +886,7 @@ void Scumm::o5_chainScript() {
cur = _currentScript;
if (vm.slot[cur].cutsceneOverride != 0)
- error("Script %d chaining with active cutscene/override");
+ error("Script %d chaining with active cutscene/override");
vm.slot[cur].number = 0;
vm.slot[cur].status = 0;
@@ -882,65 +895,67 @@ void Scumm::o5_chainScript() {
runScript(data, vm.slot[cur].unk1, vm.slot[cur].unk2, vars);
}
-void Scumm::o5_cursorCommand() {
- int i,j,k;
+void Scumm::o5_cursorCommand()
+{
+ int i, j, k;
int16 table[16];
- switch((_opcode=fetchScriptByte())&0x1F) {
- case 1: /* cursor show */
+ switch ((_opcode = fetchScriptByte()) & 0x1F) {
+ case 1: /* cursor show */
_cursorState = 1;
verbMouseOver(0);
break;
- case 2: /* cursor hide */
+ case 2: /* cursor hide */
_cursorState = 0;
verbMouseOver(0);
break;
- case 3: /* userput on */
+ case 3: /* userput on */
_userPut = 1;
break;
- case 4: /* userput off */
+ case 4: /* userput off */
_userPut = 0;
break;
- case 5: /* cursor soft on */
+ case 5: /* cursor soft on */
_cursorState++;
if (_cursorState > 1) {
error("Cursor state greater than 1 in script");
}
verbMouseOver(0);
break;
- case 6: /* cursor soft off */
+ case 6: /* cursor soft off */
_cursorState--;
verbMouseOver(0);
break;
- case 7: /* userput soft on */
+ case 7: /* userput soft on */
_userPut++;
break;
- case 8: /* userput soft off */
+ case 8: /* userput soft off */
_userPut--;
break;
- case 10: /* set cursor img */
+ case 10: /* set cursor img */
i = getVarOrDirectByte(0x80);
j = getVarOrDirectByte(0x40);
- if(_gameId != GID_LOOM256)
- setCursorImg(i, j, 1);
+ if (_gameId != GID_LOOM256)
+ setCursorImg(i, j, 1);
break;
- case 11: /* set cursor hotspot */
+ case 11: /* set cursor hotspot */
i = getVarOrDirectByte(0x80);
j = getVarOrDirectByte(0x40);
k = getVarOrDirectByte(0x20);
setCursorHotspot2(j, k);
break;
- case 12: /* init cursor */
+ case 12: /* init cursor */
setCursor(getVarOrDirectByte(0x80));
break;
- case 13: /* init charset */
+ case 13: /* init charset */
initCharset(getVarOrDirectByte(0x80));
break;
- case 14: /* unk */
+ case 14: /* unk */
getWordVararg(table);
- for (i=0; i<16; i++)
- charset._colorMap[i] = _charsetData[string[1].t_charset][i] = (unsigned char)table[i];
+ for (i = 0; i < 16; i++)
+ charset._colorMap[i] = _charsetData[string[1].t_charset][i] =
+ (unsigned char)table[i];
break;
}
@@ -948,57 +963,65 @@ void Scumm::o5_cursorCommand() {
_vars[VAR_USERPUT] = _userPut;
}
-void Scumm::o5_cutscene() {
+void Scumm::o5_cutscene()
+{
int16 args[16];
getWordVararg(args);
cutscene(args);
}
-void Scumm::o5_endCutscene() {
+void Scumm::o5_endCutscene()
+{
endCutscene();
}
-void Scumm::o5_debug() {
+void Scumm::o5_debug()
+{
getVarOrDirectWord(0x80);
}
-void Scumm::o5_decrement() {
+void Scumm::o5_decrement()
+{
getResultPos();
- setResult(readVar(_resultVarNumber)-1);
+ setResult(readVar(_resultVarNumber) - 1);
}
-void Scumm::o5_delay() {
+void Scumm::o5_delay()
+{
int delay = fetchScriptByte();
- delay |= fetchScriptByte()<<8;
- delay |= fetchScriptByte()<<16;
+ delay |= fetchScriptByte() << 8;
+ delay |= fetchScriptByte() << 16;
vm.slot[_currentScript].delay = delay;
vm.slot[_currentScript].status = 1;
o5_breakHere();
}
-void Scumm::o5_delayVariable() {
+void Scumm::o5_delayVariable()
+{
vm.slot[_currentScript].delay = readVar(fetchScriptWord());
vm.slot[_currentScript].status = 1;
o5_breakHere();
}
-void Scumm::o5_divide() {
+void Scumm::o5_divide()
+{
int a;
getResultPos();
a = getVarOrDirectWord(0x80);
- if(a==0) {
+ if (a == 0) {
error("Divide by zero");
setResult(0);
- } else
+ } else
setResult(readVar(_resultVarNumber) / a);
}
-void Scumm::o5_doSentence() {
- int a,b;
+void Scumm::o5_doSentence()
+{
+ int a, b;
SentenceTab *st;
a = getVarOrDirectByte(0x80);
- if (a==0xFE) {
+ if (a == 0xFE) {
_sentenceNum = 0;
stopScriptNr(_vars[VAR_SENTENCE_SCRIPT]);
clearClickedStatus();
@@ -1010,7 +1033,7 @@ void Scumm::o5_doSentence() {
st->unk5 = a;
st->unk4 = getVarOrDirectWord(0x40);
b = st->unk3 = getVarOrDirectWord(0x20);
- if (b==0) {
+ if (b == 0) {
st->unk2 = 0;
} else {
st->unk2 = 1;
@@ -1018,9 +1041,10 @@ void Scumm::o5_doSentence() {
st->unk = 0;
}
-void Scumm::o5_drawBox() {
- int x,y,x2,y2,color;
-
+void Scumm::o5_drawBox()
+{
+ int x, y, x2, y2, color;
+
x = getVarOrDirectWord(0x80);
y = getVarOrDirectWord(0x40);
@@ -1032,71 +1056,73 @@ void Scumm::o5_drawBox() {
drawBox(x, y, x2, y2, color);
}
-void Scumm::o5_drawObject() {
- int state,obj,idx,i;
+void Scumm::o5_drawObject()
+{
+ int state, obj, idx, i;
ObjectData *od;
- uint16 x,y,w,h;
+ uint16 x, y, w, h;
int xpos, ypos;
state = 1;
xpos = ypos = 255;
obj = getVarOrDirectWord(0x80);
- if (_features & GF_SMALL_HEADER) {
- int temp = getVarOrDirectWord(0x40);
- getVarOrDirectWord(0x20); // Room
-
- idx = getObjectIndex(obj);
- if(idx==-1)
- return;
- od = &_objs[idx];
- xpos = ypos = 255;
- if (temp!=0xFF) {
- od->walk_x += (xpos<<3) - od->x_pos;
- od->x_pos = xpos<<3;
- od->walk_y += (ypos<<3) - od->y_pos;
- od->y_pos = ypos<<3;
- }
- addObjectToDrawQue(idx);
-
- x = od->x_pos;
- y = od->y_pos;
- w = od->width;
- h = od->height;
-
- i = _numObjectsInRoom;
- do {
- if (_objs[i].x_pos == x && _objs[i].y_pos == y && _objs[i].width == w && _objs[i].height==h)
- putState(_objs[i].obj_nr, 0);
- } while (--i);
-
- putState(obj, state);
- return;
- }
-
- switch((_opcode = fetchScriptByte())&0x1F) {
- case 1: /* draw at */
+ if (_features & GF_SMALL_HEADER) {
+ int temp = getVarOrDirectWord(0x40);
+ getVarOrDirectWord(0x20); // Room
+
+ idx = getObjectIndex(obj);
+ if (idx == -1)
+ return;
+ od = &_objs[idx];
+ xpos = ypos = 255;
+ if (temp != 0xFF) {
+ od->walk_x += (xpos << 3) - od->x_pos;
+ od->x_pos = xpos << 3;
+ od->walk_y += (ypos << 3) - od->y_pos;
+ od->y_pos = ypos << 3;
+ }
+ addObjectToDrawQue(idx);
+
+ x = od->x_pos;
+ y = od->y_pos;
+ w = od->width;
+ h = od->height;
+
+ i = _numObjectsInRoom;
+ do {
+ if (_objs[i].x_pos == x && _objs[i].y_pos == y && _objs[i].width == w
+ && _objs[i].height == h)
+ putState(_objs[i].obj_nr, 0);
+ } while (--i);
+
+ putState(obj, state);
+ return;
+ }
+
+ switch ((_opcode = fetchScriptByte()) & 0x1F) {
+ case 1: /* draw at */
xpos = getVarOrDirectWord(0x80);
ypos = getVarOrDirectWord(0x40);
break;
- case 2: /* set state */
+ case 2: /* set state */
state = getVarOrDirectWord(0x80);
break;
- case 0x1F: /* neither */
+ case 0x1F: /* neither */
break;
default:
error("o5_drawObject: default case");
}
idx = getObjectIndex(obj);
- if (idx==-1)
+ if (idx == -1)
return;
od = &_objs[idx];
- if (xpos!=0xFF) {
- od->walk_x += (xpos<<3) - od->x_pos;
- od->x_pos = xpos<<3;
- od->walk_y += (ypos<<3) - od->y_pos;
- od->y_pos = ypos<<3;
+ if (xpos != 0xFF) {
+ od->walk_x += (xpos << 3) - od->x_pos;
+ od->x_pos = xpos << 3;
+ od->walk_y += (ypos << 3) - od->y_pos;
+ od->y_pos = ypos << 3;
}
addObjectToDrawQue(idx);
@@ -1108,51 +1134,53 @@ void Scumm::o5_drawObject() {
i = _numObjectsInRoom;
do {
if (_objs[i].x_pos == x && _objs[i].y_pos == y
- && _objs[i].width == w && _objs[i].height==h)
+ && _objs[i].width == w && _objs[i].height == h)
putState(_objs[i].obj_nr, 0);
} while (--i);
putState(obj, state);
}
-void Scumm::o5_dummy() {
+void Scumm::o5_dummy()
+{
/* nothing */
}
-void Scumm::o5_expression() {
+void Scumm::o5_expression()
+{
int dst, i;
_scummStackPos = 0;
getResultPos();
dst = _resultVarNumber;
- while ((_opcode = fetchScriptByte())!=0xFF) {
- switch(_opcode&0x1F) {
- case 1: /* varordirect */
+ while ((_opcode = fetchScriptByte()) != 0xFF) {
+ switch (_opcode & 0x1F) {
+ case 1: /* varordirect */
push(getVarOrDirectWord(0x80));
break;
- case 2: /* add */
+ case 2: /* add */
i = pop();
push(i + pop());
break;
- case 3: /* sub */
+ case 3: /* sub */
i = pop();
push(pop() - i);
break;
- case 4: /* mul */
+ case 4: /* mul */
i = pop();
push(i * pop());
break;
- case 5: /* div */
+ case 5: /* div */
i = pop();
- if (i==0)
+ if (i == 0)
error("Divide by zero");
push(pop() / i);
break;
- case 6: /* normal opcode */
+ case 6: /* normal opcode */
_opcode = fetchScriptByte();
- (this->*(getOpcode(_opcode)))();
+ (this->*(getOpcode(_opcode))) ();
push(_vars[0]);
break;
}
@@ -1162,174 +1190,208 @@ void Scumm::o5_expression() {
setResult(pop());
}
-void Scumm::o5_faceActor() {
+void Scumm::o5_faceActor()
+{
int act, obj;
act = getVarOrDirectByte(0x80);
obj = getVarOrDirectWord(0x40);
faceActorToObj(act, obj);
}
-void Scumm::o5_findInventory() {
+void Scumm::o5_findInventory()
+{
int t;
getResultPos();
t = getVarOrDirectByte(0x80);
- setResult(findInventory(t,getVarOrDirectByte(0x40)));
+ setResult(findInventory(t, getVarOrDirectByte(0x40)));
}
-void Scumm::o5_findObject() {
+void Scumm::o5_findObject()
+{
int t;
getResultPos();
t = getVarOrDirectWord(0x80);
setResult(findObject(t, getVarOrDirectWord(0x40)));
}
-void Scumm::o5_freezeScripts() {
+void Scumm::o5_freezeScripts()
+{
int scr = getVarOrDirectByte(0x80);
- if (scr!=0)
+ if (scr != 0)
freezeScripts(scr);
else
unfreezeScripts();
}
-void Scumm::o5_getActorCostume() {
+void Scumm::o5_getActorCostume()
+{
getResultPos();
- setResult(derefActorSafe(getVarOrDirectByte(0x80),"o5_getActorCostume")->costume);
+ setResult(derefActorSafe(getVarOrDirectByte(0x80), "o5_getActorCostume")->
+ costume);
}
-void Scumm::o5_getActorElevation() {
+void Scumm::o5_getActorElevation()
+{
getResultPos();
- setResult(derefActorSafe(getVarOrDirectByte(0x80),"o5_getActorElevation")->elevation);
+ setResult(derefActorSafe(getVarOrDirectByte(0x80), "o5_getActorElevation")->
+ elevation);
}
-void Scumm::o5_getActorFacing() {
+void Scumm::o5_getActorFacing()
+{
getResultPos();
- setResult(newDirToOldDir(derefActorSafe(getVarOrDirectByte(0x80),"o5_getActorFacing")->facing));
+ setResult(newDirToOldDir
+ (derefActorSafe(getVarOrDirectByte(0x80), "o5_getActorFacing")->
+ facing));
}
-void Scumm::o5_getActorMoving() {
+void Scumm::o5_getActorMoving()
+{
getResultPos();
- setResult(derefActorSafe(getVarOrDirectByte(0x80),"o5_getActorMoving")->moving);
+ setResult(derefActorSafe(getVarOrDirectByte(0x80), "o5_getActorMoving")->
+ moving);
}
-void Scumm::o5_getActorRoom() {
+void Scumm::o5_getActorRoom()
+{
int temp;
getResultPos();
- temp=getVarOrDirectByte(0x80);
+ temp = getVarOrDirectByte(0x80);
- setResult(derefActorSafe(temp,"o5_getActorRoom")->room);
+ setResult(derefActorSafe(temp, "o5_getActorRoom")->room);
}
-void Scumm::o5_getActorScale() {
- if(_gameId == GID_INDY3_256) {
- getVarOrDirectByte(0x80); /*FIXME: missing stuff here*/
+void Scumm::o5_getActorScale()
+{
+ if (_gameId == GID_INDY3_256) {
+ getVarOrDirectByte(0x80); /*FIXME: missing stuff here */
return;
}
getResultPos();
- setResult(derefActorSafe(getVarOrDirectByte(0x80),"o5_getActorScale")->scalex);
+ setResult(derefActorSafe(getVarOrDirectByte(0x80), "o5_getActorScale")->
+ scalex);
}
-void Scumm::o5_getActorWalkBox() {
+void Scumm::o5_getActorWalkBox()
+{
getResultPos();
- setResult(derefActorSafe(getVarOrDirectByte(0x80),"o5_getActorWalkbox")->walkbox);
+ setResult(derefActorSafe(getVarOrDirectByte(0x80), "o5_getActorWalkbox")->
+ walkbox);
}
-void Scumm::o5_getActorWidth() {
+void Scumm::o5_getActorWidth()
+{
getResultPos();
- setResult(derefActorSafe(getVarOrDirectByte(0x80),"o5_getActorWidth")->width);
+ setResult(derefActorSafe(getVarOrDirectByte(0x80), "o5_getActorWidth")->
+ width);
}
-void Scumm::o5_getActorX() {
+void Scumm::o5_getActorX()
+{
int actor;
getResultPos();
actor = getVarOrDirectWord(0x80);
setResult(getObjX(actor));
}
-void Scumm::o5_getActorY() {
+void Scumm::o5_getActorY()
+{
getResultPos();
setResult(getObjY(getVarOrDirectWord(0x80)));
}
-void Scumm::o5_getAnimCounter() {
+void Scumm::o5_getAnimCounter()
+{
getResultPos();
- setResult(derefActorSafe(getVarOrDirectByte(0x80),"o5_getActorAnimCounter")->cost.animCounter1);
+ setResult(derefActorSafe
+ (getVarOrDirectByte(0x80),
+ "o5_getActorAnimCounter")->cost.animCounter1);
}
-void Scumm::o5_getClosestObjActor() {
+void Scumm::o5_getClosestObjActor()
+{
int obj;
int act;
- int closest_obj=0xFF, closest_dist=0xFF;
+ int closest_obj = 0xFF, closest_dist = 0xFF;
int dist;
getResultPos();
act = getVarOrDirectWord(0x80);
obj = _vars[VAR_V5_OBJECT_HI];
-
- do {
- dist = getObjActToObjActDist(act,obj);
+
+ do {
+ dist = getObjActToObjActDist(act, obj);
if (dist < closest_dist) {
closest_dist = dist;
closest_obj = obj;
}
} while (--obj >= _vars[VAR_V5_OBJECT_LO]);
-
+
setResult(closest_dist);
}
-void Scumm::o5_getDist() {
- int o1,o2;
+void Scumm::o5_getDist()
+{
+ int o1, o2;
int r;
getResultPos();
o1 = getVarOrDirectWord(0x80);
o2 = getVarOrDirectWord(0x40);
- r = getObjActToObjActDist(o1,o2);
+ r = getObjActToObjActDist(o1, o2);
/* Fix for monkey 2, dunno what's wrong in scummvm */
- if (_gameId==GID_MONKEY2 && vm.slot[_currentScript].number==40 && r<60)
- r=60;
+ if (_gameId == GID_MONKEY2 && vm.slot[_currentScript].number == 40
+ && r < 60)
+ r = 60;
setResult(r);
}
-void Scumm::o5_getInventoryCount() {
+void Scumm::o5_getInventoryCount()
+{
getResultPos();
setResult(getInventoryCount(getVarOrDirectByte(0x80)));
}
-void Scumm::o5_getObjectOwner() {
+void Scumm::o5_getObjectOwner()
+{
getResultPos();
setResult(getOwner(getVarOrDirectWord(0x80)));
}
-void Scumm::o5_getObjectState() {
- if(_features & GF_SMALL_HEADER) {
+void Scumm::o5_getObjectState()
+{
+ if (_features & GF_SMALL_HEADER) {
int a = getVarOrDirectWord(0x80);
int b = getVarOrDirectByte(0x40);
-
- if((getState(a) &0xF0 >>4) != b)
+
+ if ((getState(a) & 0xF0 >> 4) != b)
o5_jumpRelative();
else
- ignoreScriptWord();
+ ignoreScriptWord();
} else {
getResultPos();
setResult(getState(getVarOrDirectWord(0x80)));
}
}
-void Scumm::o5_getRandomNr() {
+void Scumm::o5_getRandomNr()
+{
getResultPos();
- setResult(getRandomNumber(getVarOrDirectByte(0x80)+1));
+ setResult(getRandomNumber(getVarOrDirectByte(0x80) + 1));
}
-void Scumm::o5_getScriptRunning() {
+void Scumm::o5_getScriptRunning()
+{
getResultPos();
setResult(isScriptRunning(getVarOrDirectByte(0x80)));
}
-void Scumm::o5_getVerbEntrypoint() {
- int a,b;
+void Scumm::o5_getVerbEntrypoint()
+{
+ int a, b;
getResultPos();
a = getVarOrDirectWord(0x80);
b = getVarOrDirectWord(0x40);
@@ -1337,17 +1399,18 @@ void Scumm::o5_getVerbEntrypoint() {
setResult(getVerbEntrypoint(a, b));
}
-void Scumm::o5_ifClassOfIs() {
- int act,cls, b;
+void Scumm::o5_ifClassOfIs()
+{
+ int act, cls, b;
bool cond = true;
act = getVarOrDirectWord(0x80);
-
- while ( (_opcode = fetchScriptByte()) != 0xFF) {
+
+ while ((_opcode = fetchScriptByte()) != 0xFF) {
cls = getVarOrDirectWord(0x80);
b = getClass(act, cls);
- if (cls&0x80 && !b || !(cls&0x80) && b)
+ if (cls & 0x80 && !b || !(cls & 0x80) && b)
cond = false;
}
if (cond)
@@ -1356,12 +1419,14 @@ void Scumm::o5_ifClassOfIs() {
o5_jumpRelative();
}
-void Scumm::o5_increment() {
+void Scumm::o5_increment()
+{
getResultPos();
- setResult(readVar(_resultVarNumber)+1);
+ setResult(readVar(_resultVarNumber) + 1);
}
-void Scumm::o5_isActorInBox() {
+void Scumm::o5_isActorInBox()
+{
int box;
Actor *a;
@@ -1374,63 +1439,88 @@ void Scumm::o5_isActorInBox() {
ignoreScriptWord();
}
-void Scumm::o5_isEqual() {
+void Scumm::o5_isEqual()
+{
int16 a = readVar(fetchScriptWord());
int16 b = getVarOrDirectWord(0x80);
- if (b == a) ignoreScriptWord();
- else o5_jumpRelative();
+ if (b == a)
+ ignoreScriptWord();
+ else
+ o5_jumpRelative();
}
-void Scumm::o5_isGreater() {
+void Scumm::o5_isGreater()
+{
int16 a = readVar(fetchScriptWord());
int16 b = getVarOrDirectWord(0x80);
- if (b > a) ignoreScriptWord();
- else o5_jumpRelative();
+ if (b > a)
+ ignoreScriptWord();
+ else
+ o5_jumpRelative();
}
-void Scumm::o5_isGreaterEqual() {
+void Scumm::o5_isGreaterEqual()
+{
int16 a = readVar(fetchScriptWord());
int16 b = getVarOrDirectWord(0x80);
- if (b >= a) ignoreScriptWord();
- else o5_jumpRelative();
+ if (b >= a)
+ ignoreScriptWord();
+ else
+ o5_jumpRelative();
}
-void Scumm::o5_isLess() {
+void Scumm::o5_isLess()
+{
int16 a = readVar(fetchScriptWord());
int16 b = getVarOrDirectWord(0x80);
- if (b < a) ignoreScriptWord();
- else o5_jumpRelative();
+ if (b < a)
+ ignoreScriptWord();
+ else
+ o5_jumpRelative();
}
-void Scumm::o5_lessOrEqual() {
+void Scumm::o5_lessOrEqual()
+{
int16 a = readVar(fetchScriptWord());
int16 b = getVarOrDirectWord(0x80);
- if (b <= a) ignoreScriptWord();
- else o5_jumpRelative();
+ if (b <= a)
+ ignoreScriptWord();
+ else
+ o5_jumpRelative();
}
-void Scumm::o5_isNotEqual() {
+void Scumm::o5_isNotEqual()
+{
int16 a = readVar(fetchScriptWord());
int16 b = getVarOrDirectWord(0x80);
- if (b != a) ignoreScriptWord();
- else o5_jumpRelative();
+ if (b != a)
+ ignoreScriptWord();
+ else
+ o5_jumpRelative();
}
-void Scumm::o5_notEqualZero() {
+void Scumm::o5_notEqualZero()
+{
int a = readVar(fetchScriptWord());
- if (a != 0) ignoreScriptWord();
- else o5_jumpRelative();
+ if (a != 0)
+ ignoreScriptWord();
+ else
+ o5_jumpRelative();
}
-void Scumm::o5_equalZero() {
+void Scumm::o5_equalZero()
+{
int a = readVar(fetchScriptWord());
- if (a == 0) ignoreScriptWord();
- else o5_jumpRelative();
+ if (a == 0)
+ ignoreScriptWord();
+ else
+ o5_jumpRelative();
}
-void Scumm::o5_isSoundRunning() {
+void Scumm::o5_isSoundRunning()
+{
int snd;
getResultPos();
snd = getVarOrDirectByte(0x80);
@@ -1439,12 +1529,14 @@ void Scumm::o5_isSoundRunning() {
setResult(snd);
}
-void Scumm::o5_jumpRelative() {
- _scriptPointer += (int16)fetchScriptWord();
+void Scumm::o5_jumpRelative()
+{
+ _scriptPointer += (int16) fetchScriptWord();
}
-void Scumm::o5_lights() {
- int a,b,c;
+void Scumm::o5_lights()
+{
+ int a, b, c;
a = getVarOrDirectByte(0x80);
b = fetchScriptByte();
@@ -1453,37 +1545,39 @@ void Scumm::o5_lights() {
/* if (c==0)
_vars[VAR_V5_DRAWFLAGS] = a;
else if (c==1) {*/
- warning("o5_lights: lights not implemented");
-// }
- _fullRedraw=1;
+ warning("o5_lights: lights not implemented");
+// }
+ _fullRedraw = 1;
}
-void Scumm::o5_loadRoom() {
+void Scumm::o5_loadRoom()
+{
int room;
-
+
/* Begin: Autosave
- _saveLoadSlot = 0;
- sprintf(_saveLoadName, "Autosave", _saveLoadSlot);
- _saveLoadFlag = 1;
- _saveLoadCompatible = false;
- End: Autosave */
+ _saveLoadSlot = 0;
+ sprintf(_saveLoadName, "Autosave", _saveLoadSlot);
+ _saveLoadFlag = 1;
+ _saveLoadCompatible = false;
+ End: Autosave */
room = getVarOrDirectByte(0x80);
startScene(room, 0, 0);
_fullRedraw = 1;
}
-void Scumm::o5_loadRoomWithEgo() {
- int obj, room, x,y;
+void Scumm::o5_loadRoomWithEgo()
+{
+ int obj, room, x, y;
Actor *a;
/* Begin: Autosave
- _saveLoadSlot = 0;
- sprintf(_saveLoadName, "Autosave", _saveLoadSlot);
- _saveLoadFlag = 1;
- _saveLoadCompatible = false;
- End: Autosave */
-
+ _saveLoadSlot = 0;
+ sprintf(_saveLoadName, "Autosave", _saveLoadSlot);
+ _saveLoadFlag = 1;
+ _saveLoadCompatible = false;
+ End: Autosave */
+
obj = getVarOrDirectWord(0x80);
room = getVarOrDirectByte(0x40);
@@ -1492,8 +1586,8 @@ void Scumm::o5_loadRoomWithEgo() {
/* Warning: used previously _xPos, _yPos from a previous update of those */
putActor(a, a->x, a->y, room);
- x = (int16)fetchScriptWord();
- y = (int16)fetchScriptWord();
+ x = (int16) fetchScriptWord();
+ y = (int16) fetchScriptWord();
_egoPositioned = false;
@@ -1504,42 +1598,43 @@ void Scumm::o5_loadRoomWithEgo() {
camera._dest.x = camera._cur.x = a->x;
setCameraFollows(a);
- _fullRedraw=1;
+ _fullRedraw = 1;
if (x != -1) {
startWalkActor(a, x, y, -1);
}
}
-void Scumm::o5_matrixOps() {
- int a,b;
+void Scumm::o5_matrixOps()
+{
+ int a, b;
- if(_features & GF_OLD256) {
+ if (_features & GF_OLD256) {
a = getVarOrDirectByte(0x80);
b = fetchScriptByte();
- if (b == 0x40) // Lock Box
+ if (b == 0x40) // Lock Box
setBoxFlags(a, 0x80);
else
setBoxFlags(a, 0);
return;
}
-
+
_opcode = fetchScriptByte();
- switch(_opcode & 0x1F) {
+ switch (_opcode & 0x1F) {
case 1:
a = getVarOrDirectByte(0x80);
b = getVarOrDirectByte(0x40);
- setBoxFlags(a,b);
+ setBoxFlags(a, b);
break;
case 2:
a = getVarOrDirectByte(0x80);
b = getVarOrDirectByte(0x40);
- setBoxScale(a,b);
+ setBoxScale(a, b);
break;
case 3:
a = getVarOrDirectByte(0x80);
b = getVarOrDirectByte(0x40);
- setBoxScale(a,(b-1)|0x8000);
+ setBoxScale(a, (b - 1) | 0x8000);
break;
case 4:
createBoxMatrix();
@@ -1547,12 +1642,14 @@ void Scumm::o5_matrixOps() {
}
}
-void Scumm::o5_move() {
+void Scumm::o5_move()
+{
getResultPos();
setResult(getVarOrDirectWord(0x80));
}
-void Scumm::o5_multiply() {
+void Scumm::o5_multiply()
+{
int a;
getResultPos();
a = getVarOrDirectWord(0x80);
@@ -1560,30 +1657,34 @@ void Scumm::o5_multiply() {
}
-void Scumm::o5_or() {
+void Scumm::o5_or()
+{
int a;
getResultPos();
a = getVarOrDirectWord(0x80);
setResult(readVar(_resultVarNumber) | a);
}
-void Scumm::o5_overRide() {
- if(fetchScriptByte()!=0)
+void Scumm::o5_overRide()
+{
+ if (fetchScriptByte() != 0)
beginOverride();
else
endOverride();
}
-void Scumm::o5_panCameraTo() {
+void Scumm::o5_panCameraTo()
+{
panCameraTo(getVarOrDirectWord(0x80), 0);
}
-void Scumm::o5_pickupObject() {
+void Scumm::o5_pickupObject()
+{
int obj, room;
obj = getVarOrDirectWord(0x80);
room = getVarOrDirectByte(0x40);
- if (room==0)
+ if (room == 0)
room = _roomResource;
addObjectToInventory(obj, room);
putOwner(obj, _vars[VAR_EGO]);
@@ -1594,45 +1695,51 @@ void Scumm::o5_pickupObject() {
runHook(1);
}
-void Scumm::o5_print() {
+void Scumm::o5_print()
+{
_actorToPrintStrFor = getVarOrDirectByte(0x80);
decodeParseString();
}
-void Scumm::o5_printEgo() {
+void Scumm::o5_printEgo()
+{
_actorToPrintStrFor = (unsigned char)_vars[VAR_EGO];
decodeParseString();
}
-void Scumm::o5_pseudoRoom() {
+void Scumm::o5_pseudoRoom()
+{
int i = fetchScriptByte(), j;
while ((j = fetchScriptByte()) != 0) {
if (j >= 0x80) {
- _resourceMapper[j&0x7F] = i;
+ _resourceMapper[j & 0x7F] = i;
}
}
}
-void Scumm::o5_putActor() {
- int x,y;
+void Scumm::o5_putActor()
+{
+ int x, y;
Actor *a;
a = derefActorSafe(getVarOrDirectByte(0x80), "o5_putActor");
- if (!a) return;
+ if (!a)
+ return;
x = getVarOrDirectWord(0x40);
y = getVarOrDirectWord(0x20);
-
+
putActor(a, x, y, a->room);
}
-void Scumm::o5_putActorAtObject() {
+void Scumm::o5_putActorAtObject()
+{
int obj;
Actor *a;
a = derefActorSafe(getVarOrDirectByte(0x80), "o5_putActorAtObject");
obj = getVarOrDirectWord(0x40);
- if (whereIsObject(obj)!=WIO_NOT_FOUND)
+ if (whereIsObject(obj) != WIO_NOT_FOUND)
getObjectXYPos(obj);
else {
_xPos = 240;
@@ -1641,13 +1748,15 @@ void Scumm::o5_putActorAtObject() {
putActor(a, _xPos, _yPos, a->room);
}
-void Scumm::o5_putActorInRoom() {
+void Scumm::o5_putActorInRoom()
+{
int room;
Actor *a;
a = derefActorSafe(getVarOrDirectByte(0x80), "o5_putActorInRoom");
room = getVarOrDirectByte(0x40);
- if (a->visible && _currentRoom!=room && _vars[VAR_TALK_ACTOR]==a->number) {
+ if (a->visible && _currentRoom != room
+ && _vars[VAR_TALK_ACTOR] == a->number) {
clearMsgQueue();
}
a->room = room;
@@ -1655,8 +1764,9 @@ void Scumm::o5_putActorInRoom() {
putActor(a, 0, 0, 0);
}
-void Scumm::o5_quitPauseRestart() {
- switch(fetchScriptByte()) {
+void Scumm::o5_quitPauseRestart()
+{
+ switch (fetchScriptByte()) {
case 1:
pauseGame(false);
break;
@@ -1666,206 +1776,206 @@ void Scumm::o5_quitPauseRestart() {
}
}
-void Scumm::o5_resourceRoutines() {
- int resid=0;
+void Scumm::o5_resourceRoutines()
+{
+ int resid = 0;
_opcode = fetchScriptByte();
if (_opcode != 17)
resid = getVarOrDirectByte(0x80);
- if(_features & GF_OLD256) /*FIXME: find a better way to implement this */
- _opcode&=0x3F;
- switch(_opcode&0x1F) {
- case 1: /* load script */
+ if (_features & GF_OLD256) /*FIXME: find a better way to implement this */
+ _opcode &= 0x3F;
+ switch (_opcode & 0x1F) {
+ case 1: /* load script */
ensureResourceLoaded(rtScript, resid);
break;
- case 2: /* load sound */
+ case 2: /* load sound */
ensureResourceLoaded(rtSound, resid);
break;
- case 3: /* load costume */
+ case 3: /* load costume */
ensureResourceLoaded(rtCostume, resid);
break;
- case 4: /* load room */
- if(_features & GF_OLD256)
- ensureResourceLoaded(rtScript, resid & 0x7F); /*FIXME: missing stuff...*/
+ case 4: /* load room */
+ if (_features & GF_OLD256)
+ ensureResourceLoaded(rtScript, resid & 0x7F); /*FIXME: missing stuff... */
else
ensureResourceLoaded(rtRoom, resid);
break;
- case 5: /* nuke script */
+ case 5: /* nuke script */
setResourceCounter(rtScript, resid, 0x7F);
break;
- case 6: /* nuke sound */
+ case 6: /* nuke sound */
setResourceCounter(rtSound, resid, 0x7F);
break;
- case 7: /* nuke costume */
+ case 7: /* nuke costume */
setResourceCounter(rtCostume, resid, 0x7F);
break;
- case 8: /* nuke room */
+ case 8: /* nuke room */
setResourceCounter(rtRoom, resid, 0x7F);
break;
- case 9: /* lock script */
+ case 9: /* lock script */
if (resid >= _numGlobalScripts)
break;
- lock(rtScript,resid);
+ lock(rtScript, resid);
break;
- case 10:/* lock sound */
- lock(rtSound,resid);
+ case 10: /* lock sound */
+ lock(rtSound, resid);
break;
- case 11:/* lock costume */
- lock(rtCostume,resid);
+ case 11: /* lock costume */
+ lock(rtCostume, resid);
break;
- case 12:/* lock room */
+ case 12: /* lock room */
if (resid > 0x7F)
- resid = _resourceMapper[resid&0x7F];
- lock(rtRoom,resid);
+ resid = _resourceMapper[resid & 0x7F];
+ lock(rtRoom, resid);
break;
- case 13:/* unlock script */
+ case 13: /* unlock script */
if (resid >= _numGlobalScripts)
break;
- unlock(rtScript,resid);
+ unlock(rtScript, resid);
break;
- case 14:/* unlock sound */
- unlock(rtSound,resid);
+ case 14: /* unlock sound */
+ unlock(rtSound, resid);
break;
- case 15:/* unlock costume */
- unlock(rtCostume,resid);
+ case 15: /* unlock costume */
+ unlock(rtCostume, resid);
break;
- case 16:/* unlock room */
+ case 16: /* unlock room */
if (resid > 0x7F)
- resid = _resourceMapper[resid&0x7F];
- unlock(rtRoom,resid);
+ resid = _resourceMapper[resid & 0x7F];
+ unlock(rtRoom, resid);
break;
- case 17:/* clear heap */
+ case 17: /* clear heap */
heapClear(0);
- unkHeapProc2(0,0);
+ unkHeapProc2(0, 0);
break;
- case 18:/* load charset */
+ case 18: /* load charset */
loadCharset(resid);
break;
- case 19:/* nuke charset */
+ case 19: /* nuke charset */
nukeCharset(resid);
break;
- case 20:/* load fl object */
+ case 20: /* load fl object */
loadFlObject(getVarOrDirectWord(0x40), resid);
break;
- default:
- warning("Unknown o5_resourcesroutine: %d", _opcode&0x1F);
- break;
+ default:
+ warning("Unknown o5_resourcesroutine: %d", _opcode & 0x1F);
+ break;
}
}
-void Scumm::o5_roomOps() {
- int a=0,b=0,c,d,e;
+void Scumm::o5_roomOps()
+{
+ int a = 0, b = 0, c, d, e;
- if(_features & GF_OLD256)
- {
+ if (_features & GF_OLD256) {
a = getVarOrDirectByte(0x80);
b = getVarOrDirectByte(0x40);
- if(_gameId == GID_INDY3_256 && a == 16 && b == 0) /* FIXME */
- {
+ if (_gameId == GID_INDY3_256 && a == 16 && b == 0) { /* FIXME */
// Set screen height
c = fetchScriptByte();
d = fetchScriptByte();
- e = fetchScriptByte();
- initScreens(0,a,320,c);
+ e = fetchScriptByte();
+ initScreens(0, a, 320, c);
return;
}
}
-
+
_opcode = fetchScriptByte();
- switch(_opcode & 0x1F) {
- case 1: /* room scroll */
- if(!(_features & GF_OLD256))
- {
+ switch (_opcode & 0x1F) {
+ case 1: /* room scroll */
+ if (!(_features & GF_OLD256)) {
a = getVarOrDirectWord(0x80);
b = getVarOrDirectWord(0x40);
}
- if (a < 160) a=160;
- if (b < 160) b=160;
- if (a > _scrWidth-160) a=_scrWidth-160;
- if (b > _scrWidth-160) b=_scrWidth-160;
+ if (a < 160)
+ a = 160;
+ if (b < 160)
+ b = 160;
+ if (a > _scrWidth - 160)
+ a = _scrWidth - 160;
+ if (b > _scrWidth - 160)
+ b = _scrWidth - 160;
_vars[VAR_CAMERA_MIN_X] = a;
_vars[VAR_CAMERA_MAX_X] = b;
break;
- case 2: /* room color */
- if(_features & GF_SMALL_HEADER) {
- if(!(_features & GF_OLD256))
- {
- a = getVarOrDirectWord(0x80);
- b = getVarOrDirectWord(0x40);
+ case 2: /* room color */
+ if (_features & GF_SMALL_HEADER) {
+ if (!(_features & GF_OLD256)) {
+ a = getVarOrDirectWord(0x80);
+ b = getVarOrDirectWord(0x40);
}
- checkRange(256, 0, a, "o5_roomOps: 2: Illegal room color slot (%d)");
- _currentPalette[a]=b;
- _fullRedraw = 1;
- } else {
- error("room-color is no longer a valid command");
- }
+ checkRange(256, 0, a, "o5_roomOps: 2: Illegal room color slot (%d)");
+ _currentPalette[a] = b;
+ _fullRedraw = 1;
+ } else {
+ error("room-color is no longer a valid command");
+ }
break;
- case 3: /* set screen */
- if(!(_features & GF_OLD256))
- {
+ case 3: /* set screen */
+ if (!(_features & GF_OLD256)) {
a = getVarOrDirectWord(0x80);
b = getVarOrDirectWord(0x40);
}
- initScreens(0,a,320,b);
- break;
- case 4: /* set palette color */
- if(_features & GF_SMALL_HEADER) {
- if(!(_features & GF_OLD256))
- {
- a = getVarOrDirectWord(0x80);
- b = getVarOrDirectWord(0x40);
+ initScreens(0, a, 320, b);
+ break;
+ case 4: /* set palette color */
+ if (_features & GF_SMALL_HEADER) {
+ if (!(_features & GF_OLD256)) {
+ a = getVarOrDirectWord(0x80);
+ b = getVarOrDirectWord(0x40);
}
- checkRange(256, 0, a, "o5_roomOps: 2: Illegal room color slot (%d)");
- _currentPalette[a]=b; /*FIXME: should be shadow palette */
- // _fullRedraw = 1;
- } else {
- a = getVarOrDirectWord(0x80);
- b = getVarOrDirectWord(0x40);
- c = getVarOrDirectWord(0x20);
- _opcode = fetchScriptByte();
- d = getVarOrDirectByte(0x80);
- setPalColor(d, a, b, c); /* index, r, g, b */
- }
- break;
- case 5: /* shake on */
+ checkRange(256, 0, a, "o5_roomOps: 2: Illegal room color slot (%d)");
+ _currentPalette[a] = b; /*FIXME: should be shadow palette */
+ // _fullRedraw = 1;
+ } else {
+ a = getVarOrDirectWord(0x80);
+ b = getVarOrDirectWord(0x40);
+ c = getVarOrDirectWord(0x20);
+ _opcode = fetchScriptByte();
+ d = getVarOrDirectByte(0x80);
+ setPalColor(d, a, b, c); /* index, r, g, b */
+ }
+ break;
+ case 5: /* shake on */
setShake(1);
break;
- case 6: /* shake off */
+ case 6: /* shake off */
setShake(0);
break;
- case 7: /* room scale for old games */
+ case 7: /* room scale for old games */
a = getVarOrDirectByte(0x80);
b = getVarOrDirectByte(0x40);
- _opcode=fetchScriptByte();
+ _opcode = fetchScriptByte();
c = getVarOrDirectByte(0x80);
d = getVarOrDirectByte(0x40);
- _opcode=fetchScriptByte();
+ _opcode = fetchScriptByte();
e = getVarOrDirectByte(0x40);
- setScaleItem(e-1,b,a,d,c);
- case 8: /* room scale? */
+ setScaleItem(e - 1, b, a, d, c);
+ case 8: /* room scale? */
a = getVarOrDirectByte(0x80);
b = getVarOrDirectByte(0x40);
c = getVarOrDirectByte(0x20);
darkenPalette(b, c, a, a, a);
break;
- case 9: /* ? */
+ case 9: /* ? */
_saveLoadFlag = getVarOrDirectByte(0x80);
_saveLoadSlot = getVarOrDirectByte(0x40);
- _saveLoadSlot = 99; /* use this slot */
+ _saveLoadSlot = 99; /* use this slot */
_saveLoadCompatible = true;
break;
- case 10: /* ? */
+ case 10: /* ? */
a = getVarOrDirectWord(0x80);
if (a) {
_switchRoomEffect = (byte)(a);
- _switchRoomEffect2 = (byte)(a>>8);
+ _switchRoomEffect2 = (byte)(a >> 8);
} else {
screenEffect(_newEffect);
}
break;
- case 11: /* ? */
+ case 11: /* ? */
a = getVarOrDirectWord(0x80);
b = getVarOrDirectWord(0x40);
c = getVarOrDirectWord(0x20);
@@ -1874,7 +1984,7 @@ void Scumm::o5_roomOps() {
e = getVarOrDirectByte(0x40);
darkenPalette(d, e, a, b, c);
break;
- case 12: /* ? */
+ case 12: /* ? */
a = getVarOrDirectWord(0x80);
b = getVarOrDirectWord(0x40);
c = getVarOrDirectWord(0x20);
@@ -1884,22 +1994,22 @@ void Scumm::o5_roomOps() {
unkRoomFunc3(d, e, a, b, c);
break;
- case 13: { /* save-string */
- char buf[256],*s;
- a = getVarOrDirectByte(0x80);
- s = buf;
- while ((*s++=fetchScriptByte()));
- warning("roomops:13 save-string(%d,\"%s\") not implemented", a, buf);
- break;
+ case 13:{ /* save-string */
+ char buf[256], *s;
+ a = getVarOrDirectByte(0x80);
+ s = buf;
+ while ((*s++ = fetchScriptByte()));
+ warning("roomops:13 save-string(%d,\"%s\") not implemented", a, buf);
+ break;
}
- case 14: /* load-string */
- char buf[256],*s;
+ case 14: /* load-string */
+ char buf[256], *s;
a = getVarOrDirectByte(0x80);
s = buf;
- while ((*s++=fetchScriptByte()));
+ while ((*s++ = fetchScriptByte()));
warning("roomops:14 load-string(%d,\"%s\") not implemented", a, buf);
break;
- case 15: /* palmanip? */
+ case 15: /* palmanip? */
a = getVarOrDirectByte(0x80);
_opcode = fetchScriptByte();
b = getVarOrDirectByte(0x80);
@@ -1909,33 +2019,35 @@ void Scumm::o5_roomOps() {
unkRoomFunc4(b, c, a, d, 1);
break;
- case 16: /* ? */
+ case 16: /* ? */
a = getVarOrDirectByte(0x80);
b = getVarOrDirectByte(0x40);
- if (a < 1) a = 1; /* FIXME: ZAK256 */
+ if (a < 1)
+ a = 1; /* FIXME: ZAK256 */
checkRange(16, 1, a, "o5_roomOps: 16: color cycle out of range (%d)");
- _colorCycle[a-1].delay = (b!=0) ? 0x4000 / (b*0x4C) : 0;
+ _colorCycle[a - 1].delay = (b != 0) ? 0x4000 / (b * 0x4C) : 0;
break;
}
}
-void Scumm::o5_saveRestoreVerbs() {
- int a,b,c,slot, slot2;
+void Scumm::o5_saveRestoreVerbs()
+{
+ int a, b, c, slot, slot2;
_opcode = fetchScriptByte();
-
+
a = getVarOrDirectByte(0x80);
b = getVarOrDirectByte(0x40);
c = getVarOrDirectByte(0x20);
- switch(_opcode) {
- case 1: /* hide verbs */
+ switch (_opcode) {
+ case 1: /* hide verbs */
if (_gameId == GID_ZAK256) // FIXME?
return;
- while (a<=b) {
- slot = getVerbSlot(a,0);
- if (slot && _verbs[slot].saveid==0) {
+ while (a <= b) {
+ slot = getVerbSlot(a, 0);
+ if (slot && _verbs[slot].saveid == 0) {
_verbs[slot].saveid = c;
drawVerb(slot, 0);
verbMouseOver(0);
@@ -1943,14 +2055,14 @@ void Scumm::o5_saveRestoreVerbs() {
a++;
}
break;
- case 2: /* show verbs */
- while (a<=b) {
+ case 2: /* show verbs */
+ while (a <= b) {
slot = getVerbSlot(a, c);
if (slot) {
- slot2 = getVerbSlot(a,0);
+ slot2 = getVerbSlot(a, 0);
if (slot2)
killVerb(slot2);
- slot = getVerbSlot(a,c);
+ slot = getVerbSlot(a, c);
_verbs[slot].saveid = 0;
drawVerb(slot, 0);
verbMouseOver(0);
@@ -1958,9 +2070,9 @@ void Scumm::o5_saveRestoreVerbs() {
a++;
}
break;
- case 3: /* kill verbs */
- while (a<=b) {
- slot = getVerbSlot(a,c);
+ case 3: /* kill verbs */
+ while (a <= b) {
+ slot = getVerbSlot(a, c);
if (slot)
killVerb(slot);
a++;
@@ -1971,32 +2083,34 @@ void Scumm::o5_saveRestoreVerbs() {
}
}
-void Scumm::o5_setCameraAt() {
+void Scumm::o5_setCameraAt()
+{
setCameraAtEx(getVarOrDirectWord(0x80));
}
-void Scumm::o5_setObjectName() {
+void Scumm::o5_setObjectName()
+{
int obj = getVarOrDirectWord(0x80);
int size;
int a;
int i;
byte *name;
unsigned char work[255];
-
+
if (obj < NUM_ACTORS)
error("Can't set actor %d name with new-name-of", obj);
if (!getOBCDFromObject(obj))
error("Can't set name of object %d", obj);
- name = getObjOrActorName(obj);
+ name = getObjOrActorName(obj);
size = getResourceDataSize(name);
- i = 0;
+ i = 0;
while ((a = fetchScriptByte()) != 0) {
- work[i++] = a;
+ work[i++] = a;
- if (a==0xFF) {
+ if (a == 0xFF) {
work[i++] = fetchScriptByte();
work[i++] = fetchScriptByte();
work[i++] = fetchScriptByte();
@@ -2006,17 +2120,18 @@ void Scumm::o5_setObjectName() {
if (i >= size) {
work[i] = 0;
- warning("New name of object %d too long (old *%s* new *%s*)",
- obj, name, work);
+ warning("New name of object %d too long (old *%s* new *%s*)",
+ obj, name, work);
i = size - 1;
}
work[i] = 0;
- strcpy((char*)name, (char*)work);
+ strcpy((char *)name, (char *)work);
runHook(0);
}
-void Scumm::o5_setOwnerOf() {
+void Scumm::o5_setOwnerOf()
+{
int obj, owner;
obj = getVarOrDirectWord(0x80);
@@ -2025,7 +2140,8 @@ void Scumm::o5_setOwnerOf() {
setOwnerOf(obj, owner);
}
-void Scumm::o5_setState() {
+void Scumm::o5_setState()
+{
int obj, state;
obj = getVarOrDirectWord(0x80);
state = getVarOrDirectByte(0x40);
@@ -2035,30 +2151,32 @@ void Scumm::o5_setState() {
clearDrawObjectQueue();
}
-void Scumm::o5_setVarRange() {
- int a,b;
+void Scumm::o5_setVarRange()
+{
+ int a, b;
getResultPos();
- a=fetchScriptByte();
+ a = fetchScriptByte();
do {
- if (_opcode&0x80)
- b=fetchScriptWord();
+ if (_opcode & 0x80)
+ b = fetchScriptWord();
else
- b=fetchScriptByte();
-
+ b = fetchScriptByte();
+
setResult(b);
_resultVarNumber++;
} while (--a);
}
-void Scumm::o5_soundKludge() {
+void Scumm::o5_soundKludge()
+{
int16 items[15];
int i;
if (_features & GF_SMALL_HEADER) // Is dummy function in
- return; // SCUMM V3
+ return; // SCUMM V3
- for (i=0; i<15; i++)
+ for (i = 0; i < 15; i++)
items[i] = 0;
getWordVararg(items);
@@ -2066,11 +2184,13 @@ void Scumm::o5_soundKludge() {
soundKludge(items);
}
-void Scumm::o5_startMusic() {
+void Scumm::o5_startMusic()
+{
addSoundToQueue(getVarOrDirectByte(0x80));
}
-void Scumm::o5_startObject() {
+void Scumm::o5_startObject()
+{
int obj, script;
int16 data[16];
@@ -2081,40 +2201,48 @@ void Scumm::o5_startObject() {
runVerbCode(obj, script, 0, 0, data);
}
-void Scumm::o5_startScript() {
- int op,script;
+void Scumm::o5_startScript()
+{
+ int op, script;
int16 data[16];
- int a,b;
-
+ int a, b;
+
op = _opcode;
script = getVarOrDirectByte(0x80);
getWordVararg(data);
a = b = 0;
- if (op&0x40) b=1;
- if (op&0x20) a=1;
+ if (op & 0x40)
+ b = 1;
+ if (op & 0x20)
+ a = 1;
runScript(script, a, b, data);
}
-void Scumm::o5_startSound() {
+void Scumm::o5_startSound()
+{
addSoundToQueue(getVarOrDirectByte(0x80));
}
-void Scumm::o5_stopMusic() {
+void Scumm::o5_stopMusic()
+{
stopAllSounds();
}
-void Scumm::o5_stopObjectCode() {
+void Scumm::o5_stopObjectCode()
+{
stopObjectCode();
}
-void Scumm::o5_stopObjectScript() {
+void Scumm::o5_stopObjectScript()
+{
stopObjectScript(getVarOrDirectWord(0x80));
}
-void Scumm::o5_stopScript() {
+void Scumm::o5_stopScript()
+{
int script;
script = getVarOrDirectByte(0x80);
@@ -2125,32 +2253,36 @@ void Scumm::o5_stopScript() {
stopScriptNr(script);
}
-void Scumm::o5_stopSound() {
+void Scumm::o5_stopSound()
+{
stopSound(getVarOrDirectByte(0x80));
}
-void Scumm::o5_stringOps() {
- int a,b,c,i;
+void Scumm::o5_stringOps()
+{
+ int a, b, c, i;
byte *ptr;
_opcode = fetchScriptByte();
- switch(_opcode&0x1F) {
- case 1: /* loadstring */
+ switch (_opcode & 0x1F) {
+ case 1: /* loadstring */
loadPtrToResource(rtString, getVarOrDirectByte(0x80), NULL);
break;
- case 2: /* copystring */
+ case 2: /* copystring */
a = getVarOrDirectByte(0x80);
b = getVarOrDirectByte(0x40);
nukeResource(rtString, a);
ptr = getResourceAddress(rtString, b);
- if (ptr) loadPtrToResource(rtString, a, ptr);
+ if (ptr)
+ loadPtrToResource(rtString, a, ptr);
break;
- case 3: /* set string char */
+ case 3: /* set string char */
a = getVarOrDirectByte(0x80);
b = getVarOrDirectByte(0x40);
ptr = getResourceAddress(rtString, a);
- if (!(_gameId == GID_LOOM256)) { /* FIXME - LOOM256 */
- if (ptr==NULL) error("String %d does not exist", a);
+ if (!(_gameId == GID_LOOM256)) { /* FIXME - LOOM256 */
+ if (ptr == NULL)
+ error("String %d does not exist", a);
c = getVarOrDirectByte(0x20);
ptr[b] = c;
} else
@@ -2158,23 +2290,24 @@ void Scumm::o5_stringOps() {
break;
- case 4: /* get string char */
+ case 4: /* get string char */
getResultPos();
a = getVarOrDirectByte(0x80);
b = getVarOrDirectByte(0x40);
ptr = getResourceAddress(rtString, a);
- if (ptr==NULL) error("String %d does not exist", a);
+ if (ptr == NULL)
+ error("String %d does not exist", a);
setResult(ptr[b]);
break;
-
- case 5: /* create empty string */
+
+ case 5: /* create empty string */
a = getVarOrDirectByte(0x80);
b = getVarOrDirectByte(0x40);
nukeResource(rtString, a);
if (b) {
ptr = createResource(rtString, a, b);
if (ptr) {
- for(i=0; i<b; i++)
+ for (i = 0; i < b; i++)
ptr[i] = 0;
}
}
@@ -2182,70 +2315,72 @@ void Scumm::o5_stringOps() {
}
}
-void Scumm::o5_subtract() {
+void Scumm::o5_subtract()
+{
int a;
getResultPos();
a = getVarOrDirectWord(0x80);
setResult(readVar(_resultVarNumber) - a);
}
-void Scumm::o5_verbOps() {
- int verb,slot;
+void Scumm::o5_verbOps()
+{
+ int verb, slot;
VerbSlot *vs;
- int a,b;
+ int a, b;
byte *ptr;
verb = getVarOrDirectByte(0x80);
- slot = getVerbSlot(verb,0);
- checkRange(_maxVerbs-1, 0, slot, "Illegal new verb slot %d");
+ slot = getVerbSlot(verb, 0);
+ checkRange(_maxVerbs - 1, 0, slot, "Illegal new verb slot %d");
vs = &_verbs[slot];
vs->verbid = verb;
- while ((_opcode=fetchScriptByte()) != 0xFF) {
- switch(_opcode&0x1F) {
- case 1: /* load image */
+ while ((_opcode = fetchScriptByte()) != 0xFF) {
+ switch (_opcode & 0x1F) {
+ case 1: /* load image */
a = getVarOrDirectWord(0x80);
if (slot) {
setVerbObject(_roomResource, a, slot);
vs->type = 1;
}
break;
- case 2: /* load from code */
+ case 2: /* load from code */
loadPtrToResource(rtVerb, slot, NULL);
- if (slot==0)
+ if (slot == 0)
nukeResource(rtVerb, slot);
vs->type = 0;
vs->imgindex = 0;
break;
- case 3: /* color */
+ case 3: /* color */
vs->color = getVarOrDirectByte(0x80);
break;
- case 4: /* set hi color */
+ case 4: /* set hi color */
vs->hicolor = getVarOrDirectByte(0x80);
break;
- case 5: /* set xy */
+ case 5: /* set xy */
vs->x = getVarOrDirectWord(0x80);
vs->y = getVarOrDirectWord(0x40);
break;
- case 6: /* set on */
- vs->curmode=1;
+ case 6: /* set on */
+ vs->curmode = 1;
break;
- case 7: /* set off */
- vs->curmode=0;
+ case 7: /* set off */
+ vs->curmode = 0;
break;
- case 8: /* delete */
+ case 8: /* delete */
killVerb(slot);
break;
- case 9: /* new */
+ case 9: /* new */
slot = getVerbSlot(verb, 0);
- if (slot==0) {
- for (slot=1; slot<_maxVerbs; slot++) {
- if(_verbs[slot].verbid==0)
+ if (slot == 0) {
+ for (slot = 1; slot < _maxVerbs; slot++) {
+ if (_verbs[slot].verbid == 0)
break;
}
- if (slot==_maxVerbs)
+ if (slot == _maxVerbs)
error("Too many verbs");
}
vs = &_verbs[slot];
@@ -2262,40 +2397,40 @@ void Scumm::o5_verbOps() {
vs->imgindex = 0;
break;
- case 16: /* set dim color */
+ case 16: /* set dim color */
vs->dimcolor = getVarOrDirectByte(0x80);
break;
- case 17: /* dim */
+ case 17: /* dim */
vs->curmode = 2;
break;
- case 18: /* set key */
+ case 18: /* set key */
vs->key = getVarOrDirectByte(0x80);
break;
- case 19: /* set center */
+ case 19: /* set center */
vs->center = 1;
break;
- case 20: /* set to string */
+ case 20: /* set to string */
ptr = getResourceAddress(rtString, getVarOrDirectWord(0x80));
if (!ptr)
nukeResource(rtVerb, slot);
else {
loadPtrToResource(rtVerb, slot, ptr);
}
- if (slot==0)
+ if (slot == 0)
nukeResource(rtVerb, slot);
vs->type = 0;
vs->imgindex = 0;
break;
- case 22: /* assign object */
+ case 22: /* assign object */
a = getVarOrDirectWord(0x80);
b = getVarOrDirectByte(0x40);
- if (slot && vs->imgindex!=a) {
+ if (slot && vs->imgindex != a) {
setVerbObject(b, a, slot);
vs->type = 1;
vs->imgindex = a;
}
break;
- case 23: /* set back color */
+ case 23: /* set back color */
vs->bkcolor = getVarOrDirectByte(0x80);
break;
}
@@ -2304,37 +2439,38 @@ void Scumm::o5_verbOps() {
verbMouseOver(0);
}
-void Scumm::o5_wait() {
+void Scumm::o5_wait()
+{
byte *oldaddr;
oldaddr = _scriptPointer - 1;
- if(_opcode == 0xAE && _gameId == GID_INDY3_256) {
+ if (_opcode == 0xAE && _gameId == GID_INDY3_256) {
_opcode = 2;
} else
_opcode = fetchScriptByte();
-
- switch(_opcode&0x1F) {
- case 1: /* wait for actor */
+
+ switch (_opcode & 0x1F) {
+ case 1: /* wait for actor */
if (derefActorSafe(getVarOrDirectByte(0x80), "o5_wait")->moving)
break;
return;
- case 2: /* wait for message */
+ case 2: /* wait for message */
if ((_currentRoom == 0) && (_gameId == GID_ZAK256)) // Bypass Zak256 script hang
return;
if (_vars[VAR_HAVE_MSG])
break;
return;
- case 3: /* wait for camera */
- if (camera._cur.x>>3 != camera._dest.x>>3)
+ case 3: /* wait for camera */
+ if (camera._cur.x >> 3 != camera._dest.x >> 3)
break;
return;
- case 4: /* wait for sentence */
+ case 4: /* wait for sentence */
if (_sentenceNum) {
- if (sentence[_sentenceNum-1].unk &&
- !isScriptInUse(_vars[VAR_SENTENCE_SCRIPT]) )
+ if (sentence[_sentenceNum - 1].unk &&
+ !isScriptInUse(_vars[VAR_SENTENCE_SCRIPT]))
return;
break;
}
@@ -2350,7 +2486,8 @@ void Scumm::o5_wait() {
o5_breakHere();
}
-void Scumm::o5_walkActorTo() {
+void Scumm::o5_walkActorTo()
+{
int x, y;
Actor *a;
a = derefActorSafe(getVarOrDirectByte(0x80), "o5_walkActorTo");
@@ -2359,8 +2496,9 @@ void Scumm::o5_walkActorTo() {
startWalkActor(a, x, y, -1);
}
-void Scumm::o5_walkActorToActor() {
- int b,x,y;
+void Scumm::o5_walkActorToActor()
+{
+ int b, x, y;
Actor *a, *a2;
int nr;
int nr2 = getVarOrDirectByte(0x80);
@@ -2375,7 +2513,7 @@ void Scumm::o5_walkActorToActor() {
}
nr = getVarOrDirectByte(0x40);
- if (nr==106 && _gameId==GID_INDY4) {
+ if (nr == 106 && _gameId == GID_INDY4) {
warning("Bypassing Indy4 bug");
fetchScriptByte();
return;
@@ -2389,10 +2527,10 @@ void Scumm::o5_walkActorToActor() {
fetchScriptByte();
return;
}
- b = fetchScriptByte(); /* distance from actor */
- if (b==0xFF) {
+ b = fetchScriptByte(); /* distance from actor */
+ if (b == 0xFF) {
b = a2->scalex * a->width / 0xFF;
- b = b + b/2;
+ b = b + b / 2;
}
x = a2->x;
y = a2->y;
@@ -2400,11 +2538,12 @@ void Scumm::o5_walkActorToActor() {
x += b;
else
x -= b;
-
+
startWalkActor(a, x, y, -1);
}
-void Scumm::o5_walkActorToObject() {
+void Scumm::o5_walkActorToObject()
+{
int obj;
Actor *a;
@@ -2412,16 +2551,17 @@ void Scumm::o5_walkActorToObject() {
a = derefActorSafe(getVarOrDirectByte(0x80), "o5_walkActorToObject");
obj = getVarOrDirectWord(0x40);
- if (whereIsObject(obj)!=WIO_NOT_FOUND) {
+ if (whereIsObject(obj) != WIO_NOT_FOUND) {
getObjectXYPos(obj);
startWalkActor(a, _xPos, _yPos, _dir);
}
}
-int Scumm::getWordVararg(int16 *ptr) {
+int Scumm::getWordVararg(int16 * ptr)
+{
int i;
- for (i=0; i<15; i++)
+ for (i = 0; i < 15; i++)
ptr[i] = 0;
i = 0;
@@ -2431,22 +2571,25 @@ int Scumm::getWordVararg(int16 *ptr) {
return i;
}
-int Scumm::getVarOrDirectWord(byte mask) {
- if (_opcode&mask)
+int Scumm::getVarOrDirectWord(byte mask)
+{
+ if (_opcode & mask)
return readVar(fetchScriptWord());
- return (int16)fetchScriptWord();
+ return (int16) fetchScriptWord();
}
-int Scumm::getVarOrDirectByte(byte mask) {
- if (_opcode&mask)
+int Scumm::getVarOrDirectByte(byte mask)
+{
+ if (_opcode & mask)
return readVar(fetchScriptWord());
return fetchScriptByte();
}
-void Scumm::decodeParseString() {
+void Scumm::decodeParseString()
+{
int textSlot;
- switch(_actorToPrintStrFor) {
+ switch (_actorToPrintStrFor) {
case 252:
textSlot = 3;
break;
@@ -2468,53 +2611,61 @@ void Scumm::decodeParseString() {
string[textSlot].color = string[textSlot].t_color;
string[textSlot].charset = string[textSlot].t_charset;
- while((_opcode=fetchScriptByte()) != 0xFF) {
- switch(_opcode&0xF) {
- case 0: /* set string xy */
+ while ((_opcode = fetchScriptByte()) != 0xFF) {
+ switch (_opcode & 0xF) {
+ case 0: /* set string xy */
string[textSlot].xpos = getVarOrDirectWord(0x80);
string[textSlot].ypos = getVarOrDirectWord(0x40);
string[textSlot].overhead = false;
break;
- case 1: /* color */
+ case 1: /* color */
string[textSlot].color = getVarOrDirectByte(0x80);
break;
- case 2: /* right */
+ case 2: /* right */
string[textSlot].right = getVarOrDirectWord(0x80);
break;
- case 4: /* center*/
+ case 4: /* center */
string[textSlot].center = true;
string[textSlot].overhead = false;
break;
- case 6: /* left */
+ case 6: /* left */
string[textSlot].center = false;
string[textSlot].overhead = false;
break;
- case 7: /* overhead */
+ case 7: /* overhead */
string[textSlot].overhead = true;
break;
- case 8: { /* play loom talkie sound - use in other games ? */
- int x = getVarOrDirectWord(0x80);
- int offset;
- int delay;
-
- if (x != 0)
- offset = (int)((x & 0xffff) * 7.5 - 22650);
- else
- offset = 0;
- delay = (int)((getVarOrDirectWord(0x40) & 0xffff) * 7.5);
- if (_gameId == GID_LOOM256)
- cd_play(this, 1, 0, offset, delay);
- else
- warning("parseString: 8");
- }
- break;
+ case 8:{ /* play loom talkie sound - use in other games ? */
+ int x = getVarOrDirectWord(0x80);
+ int offset;
+ int delay;
+
+ if (x != 0)
+ offset = (int)((x & 0xffff) * 7.5 - 22650);
+ else
+ offset = 0;
+ delay = (int)((getVarOrDirectWord(0x40) & 0xffff) * 7.5);
+ if (_gameId == GID_LOOM256)
+ cd_play(this, 1, 0, offset, delay);
+ else
+ warning("parseString: 8");
+ }
+ break;
case 15:
_messagePtr = _scriptPointer;
- switch(textSlot) {
- case 0: actorTalk(); break;
- case 1: drawString(1); break;
- case 2: unkMessage1(); break;
- case 3: unkMessage2(); break;
+ switch (textSlot) {
+ case 0:
+ actorTalk();
+ break;
+ case 1:
+ drawString(1);
+ break;
+ case 2:
+ unkMessage1();
+ break;
+ case 3:
+ unkMessage2();
+ break;
}
_scriptPointer = _messagePtr;
return;
@@ -2532,28 +2683,29 @@ void Scumm::decodeParseString() {
string[textSlot].t_charset = string[textSlot].charset;
}
-void Scumm::o5_oldRoomEffect() {
+void Scumm::o5_oldRoomEffect()
+{
int a;
- _opcode=fetchScriptByte();
- if((_opcode & 0x1F) == 3)
- {
+ _opcode = fetchScriptByte();
+ if ((_opcode & 0x1F) == 3) {
a = getVarOrDirectWord(0x80);
}
warning("Unsupported oldRoomEffect");
}
-void Scumm::o5_pickupObjectOld() {
+void Scumm::o5_pickupObjectOld()
+{
int obj = getVarOrDirectWord(0x80);
-
- if(getObjectIndex(obj) == -1)
+
+ if (getObjectIndex(obj) == -1)
return;
- if(whereIsObject(obj) == WIO_INVENTORY) /* Don't take an */
- return; /* object twice */
+ if (whereIsObject(obj) == WIO_INVENTORY) /* Don't take an */
+ return; /* object twice */
// warning("adding %d from %d to inventoryOld", obj, _currentRoom);
- addObjectToInventory(obj,_currentRoom);
+ addObjectToInventory(obj, _currentRoom);
// warning("added to inventoryOld");
removeObjectFromRoom(obj);
putOwner(obj, _vars[VAR_EGO]);
diff --git a/script_v2.cpp b/script_v2.cpp
index 6e976d3473..7de8a863da 100644
--- a/script_v2.cpp
+++ b/script_v2.cpp
@@ -24,669 +24,672 @@
#include "stdafx.h"
#include "scumm.h"
-void Scumm::setupOpcodes2() {
+void Scumm::setupOpcodes2()
+{
static const OpcodeProc opcode_list[256] = {
- /* 00 */
- &Scumm::o6_pushByte,
- &Scumm::o6_pushWord,
- &Scumm::o6_pushByteVar,
- &Scumm::o6_pushWordVar,
- /* 04 */
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_byteArrayRead,
- &Scumm::o6_wordArrayRead,
- /* 08 */
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_byteArrayIndexedRead,
- &Scumm::o6_wordArrayIndexedRead,
- /* 0C */
- &Scumm::o6_dup,
- &Scumm::o6_zero,
- &Scumm::o6_eq,
- &Scumm::o6_neq,
- /* 10 */
- &Scumm::o6_gt,
- &Scumm::o6_lt,
- &Scumm::o6_le,
- &Scumm::o6_ge,
- /* 14 */
- &Scumm::o6_add,
- &Scumm::o6_sub,
- &Scumm::o6_mul,
- &Scumm::o6_div,
- /* 18 */
- &Scumm::o6_land,
- &Scumm::o6_lor,
- &Scumm::o6_kill,
- &Scumm::o6_invalid,
- /* 1C */
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- /* 20 */
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- /* 24 */
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- /* 28 */
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- /* 2C */
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- /* 30 */
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- /* 34 */
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- /* 38 */
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- /* 3C */
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- /* 40 */
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_writeByteVar,
- &Scumm::o6_writeWordVar,
- /* 44 */
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_byteArrayWrite,
- &Scumm::o6_wordArrayWrite,
- /* 48 */
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_byteArrayIndexedWrite,
- &Scumm::o6_wordArrayIndexedWrite,
- /* 4C */
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_byteVarInc,
- &Scumm::o6_wordVarInc,
- /* 50 */
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_byteArrayInc,
- &Scumm::o6_wordArrayInc,
- /* 54 */
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_byteVarDec,
- &Scumm::o6_wordVarDec,
- /* 58 */
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_byteArrayDec,
- &Scumm::o6_wordArrayDec,
- /* 5C */
- &Scumm::o6_jumpTrue,
- &Scumm::o6_jumpFalse,
- &Scumm::o6_startScriptEx,
- &Scumm::o6_startScript,
- /* 60 */
- &Scumm::o6_startObject,
- &Scumm::o6_setObjectState,
- &Scumm::o6_setObjectXY,
- &Scumm::o6_drawBlastObject,
- /* 64 */
- &Scumm::o6_bompWindow,
- &Scumm::o6_stopObjectCode,
- &Scumm::o6_stopObjectCode,
- &Scumm::o6_endCutscene,
- /* 68 */
- &Scumm::o6_cutScene,
- &Scumm::o6_stopMusic,
- &Scumm::o6_freezeUnfreeze,
- &Scumm::o6_cursorCommand,
- /* 6C */
- &Scumm::o6_breakHere,
- &Scumm::o6_ifClassOfIs,
- &Scumm::o6_setClass,
- &Scumm::o6_getState,
- /* 70 */
- &Scumm::o6_setState,
- &Scumm::o6_setOwner,
- &Scumm::o6_getOwner,
- &Scumm::o6_jump,
- /* 74 */
- &Scumm::o6_startSound,
- &Scumm::o6_stopSound,
- &Scumm::o6_startMusic,
- &Scumm::o6_stopObjectScript,
- /* 78 */
- &Scumm::o6_panCameraTo,
- &Scumm::o6_actorFollowCamera,
- &Scumm::o6_setCameraAt,
- &Scumm::o6_loadRoom,
- /* 7C */
- &Scumm::o6_stopScript,
- &Scumm::o6_walkActorToObj,
- &Scumm::o6_walkActorTo,
- &Scumm::o6_putActorInRoom,
- /* 80 */
- &Scumm::o6_putActorAtObject,
- &Scumm::o6_faceActor,
- &Scumm::o6_animateActor,
- &Scumm::o6_doSentence,
- /* 84 */
- &Scumm::o6_pickupObject,
- &Scumm::o6_loadRoomWithEgo,
- &Scumm::o6_invalid,
- &Scumm::o6_getRandomNumber,
- /* 88 */
- &Scumm::o6_getRandomNumberRange,
- &Scumm::o6_invalid,
- &Scumm::o6_getActorMoving,
- &Scumm::o6_getScriptRunning,
- /* 8C */
- &Scumm::o6_getActorRoom,
- &Scumm::o6_getObjectX,
- &Scumm::o6_getObjectY,
- &Scumm::o6_getObjectOldDir,
- /* 90 */
- &Scumm::o6_getActorWalkBox,
- &Scumm::o6_getActorCostume,
- &Scumm::o6_findInventory,
- &Scumm::o6_getInventoryCount,
- /* 94 */
- &Scumm::o6_getVerbFromXY,
- &Scumm::o6_beginOverride,
- &Scumm::o6_endOverride,
- &Scumm::o6_setObjectName,
- /* 98 */
- &Scumm::o6_isSoundRunning,
- &Scumm::o6_setBoxFlags,
- &Scumm::o6_createBoxMatrix,
- &Scumm::o6_resourceRoutines,
- /* 9C */
- &Scumm::o6_roomOps,
- &Scumm::o6_actorSet,
- &Scumm::o6_verbOps,
- &Scumm::o6_getActorFromXY,
- /* A0 */
- &Scumm::o6_findObject,
- &Scumm::o6_pseudoRoom,
- &Scumm::o6_getActorElevation,
- &Scumm::o6_getVerbEntrypoint,
- /* A4 */
- &Scumm::o6_arrayOps,
- &Scumm::o6_saveRestoreVerbs,
- &Scumm::o6_drawBox,
- &Scumm::o6_invalid,
- /* A8 */
- &Scumm::o6_getActorWidth,
- &Scumm::o6_wait,
- &Scumm::o6_getActorScaleX,
- &Scumm::o6_getActorAnimCounter1,
- /* AC */
- &Scumm::o6_soundKludge,
- &Scumm::o6_isAnyOf,
- &Scumm::o6_quitPauseRestart,
- &Scumm::o6_isActorInBox,
- /* B0 */
- &Scumm::o6_delay,
- &Scumm::o6_delayLonger,
- &Scumm::o6_delayVeryLong,
- &Scumm::o6_stopSentence,
- /* B4 */
- &Scumm::o6_print_0,
- &Scumm::o6_print_1,
- &Scumm::o6_print_2,
- &Scumm::o6_print_3,
- /* B8 */
- &Scumm::o6_printActor,
- &Scumm::o6_printEgo,
- &Scumm::o6_talkActor,
- &Scumm::o6_talkEgo,
- /* BC */
- &Scumm::o6_dim,
- &Scumm::o5_dummy,
- &Scumm::o6_runVerbCodeQuick,
- &Scumm::o6_runScriptQuick,
- /* C0 */
- &Scumm::o6_dim2,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- /* C4 */
- &Scumm::o6_abs,
- &Scumm::o6_distObjectObject,
- &Scumm::o6_distObjectPt,
- &Scumm::o6_distPtPt,
- /* C8 */
- &Scumm::o6_kernelFunction,
- &Scumm::o6_miscOps,
- &Scumm::o6_breakMaybe,
- &Scumm::o6_pickOneOf,
- /* CC */
- &Scumm::o6_pickOneOfDefault,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- /* D0 */
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_getAnimateVariable,
- &Scumm::o6_invalid,
- /* D4 */
- &Scumm::o6_invalid,
- &Scumm::o6_jumpToScript,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- /* D8 */
- &Scumm::o6_isRoomScriptRunning,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- /* DC */
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- /* E0 */
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- /* E4 */
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- /* E8 */
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- /* EC */
- &Scumm::o6_getActorPriority,
- &Scumm::o6_getObjectNewDir,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- /* F0 */
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- /* F4 */
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- /* F8 */
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- /* FC */
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
- &Scumm::o6_invalid,
+ /* 00 */
+ &Scumm::o6_pushByte,
+ &Scumm::o6_pushWord,
+ &Scumm::o6_pushByteVar,
+ &Scumm::o6_pushWordVar,
+ /* 04 */
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_byteArrayRead,
+ &Scumm::o6_wordArrayRead,
+ /* 08 */
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_byteArrayIndexedRead,
+ &Scumm::o6_wordArrayIndexedRead,
+ /* 0C */
+ &Scumm::o6_dup,
+ &Scumm::o6_zero,
+ &Scumm::o6_eq,
+ &Scumm::o6_neq,
+ /* 10 */
+ &Scumm::o6_gt,
+ &Scumm::o6_lt,
+ &Scumm::o6_le,
+ &Scumm::o6_ge,
+ /* 14 */
+ &Scumm::o6_add,
+ &Scumm::o6_sub,
+ &Scumm::o6_mul,
+ &Scumm::o6_div,
+ /* 18 */
+ &Scumm::o6_land,
+ &Scumm::o6_lor,
+ &Scumm::o6_kill,
+ &Scumm::o6_invalid,
+ /* 1C */
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ /* 20 */
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ /* 24 */
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ /* 28 */
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ /* 2C */
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ /* 30 */
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ /* 34 */
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ /* 38 */
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ /* 3C */
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ /* 40 */
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_writeByteVar,
+ &Scumm::o6_writeWordVar,
+ /* 44 */
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_byteArrayWrite,
+ &Scumm::o6_wordArrayWrite,
+ /* 48 */
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_byteArrayIndexedWrite,
+ &Scumm::o6_wordArrayIndexedWrite,
+ /* 4C */
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_byteVarInc,
+ &Scumm::o6_wordVarInc,
+ /* 50 */
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_byteArrayInc,
+ &Scumm::o6_wordArrayInc,
+ /* 54 */
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_byteVarDec,
+ &Scumm::o6_wordVarDec,
+ /* 58 */
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_byteArrayDec,
+ &Scumm::o6_wordArrayDec,
+ /* 5C */
+ &Scumm::o6_jumpTrue,
+ &Scumm::o6_jumpFalse,
+ &Scumm::o6_startScriptEx,
+ &Scumm::o6_startScript,
+ /* 60 */
+ &Scumm::o6_startObject,
+ &Scumm::o6_setObjectState,
+ &Scumm::o6_setObjectXY,
+ &Scumm::o6_drawBlastObject,
+ /* 64 */
+ &Scumm::o6_bompWindow,
+ &Scumm::o6_stopObjectCode,
+ &Scumm::o6_stopObjectCode,
+ &Scumm::o6_endCutscene,
+ /* 68 */
+ &Scumm::o6_cutScene,
+ &Scumm::o6_stopMusic,
+ &Scumm::o6_freezeUnfreeze,
+ &Scumm::o6_cursorCommand,
+ /* 6C */
+ &Scumm::o6_breakHere,
+ &Scumm::o6_ifClassOfIs,
+ &Scumm::o6_setClass,
+ &Scumm::o6_getState,
+ /* 70 */
+ &Scumm::o6_setState,
+ &Scumm::o6_setOwner,
+ &Scumm::o6_getOwner,
+ &Scumm::o6_jump,
+ /* 74 */
+ &Scumm::o6_startSound,
+ &Scumm::o6_stopSound,
+ &Scumm::o6_startMusic,
+ &Scumm::o6_stopObjectScript,
+ /* 78 */
+ &Scumm::o6_panCameraTo,
+ &Scumm::o6_actorFollowCamera,
+ &Scumm::o6_setCameraAt,
+ &Scumm::o6_loadRoom,
+ /* 7C */
+ &Scumm::o6_stopScript,
+ &Scumm::o6_walkActorToObj,
+ &Scumm::o6_walkActorTo,
+ &Scumm::o6_putActorInRoom,
+ /* 80 */
+ &Scumm::o6_putActorAtObject,
+ &Scumm::o6_faceActor,
+ &Scumm::o6_animateActor,
+ &Scumm::o6_doSentence,
+ /* 84 */
+ &Scumm::o6_pickupObject,
+ &Scumm::o6_loadRoomWithEgo,
+ &Scumm::o6_invalid,
+ &Scumm::o6_getRandomNumber,
+ /* 88 */
+ &Scumm::o6_getRandomNumberRange,
+ &Scumm::o6_invalid,
+ &Scumm::o6_getActorMoving,
+ &Scumm::o6_getScriptRunning,
+ /* 8C */
+ &Scumm::o6_getActorRoom,
+ &Scumm::o6_getObjectX,
+ &Scumm::o6_getObjectY,
+ &Scumm::o6_getObjectOldDir,
+ /* 90 */
+ &Scumm::o6_getActorWalkBox,
+ &Scumm::o6_getActorCostume,
+ &Scumm::o6_findInventory,
+ &Scumm::o6_getInventoryCount,
+ /* 94 */
+ &Scumm::o6_getVerbFromXY,
+ &Scumm::o6_beginOverride,
+ &Scumm::o6_endOverride,
+ &Scumm::o6_setObjectName,
+ /* 98 */
+ &Scumm::o6_isSoundRunning,
+ &Scumm::o6_setBoxFlags,
+ &Scumm::o6_createBoxMatrix,
+ &Scumm::o6_resourceRoutines,
+ /* 9C */
+ &Scumm::o6_roomOps,
+ &Scumm::o6_actorSet,
+ &Scumm::o6_verbOps,
+ &Scumm::o6_getActorFromXY,
+ /* A0 */
+ &Scumm::o6_findObject,
+ &Scumm::o6_pseudoRoom,
+ &Scumm::o6_getActorElevation,
+ &Scumm::o6_getVerbEntrypoint,
+ /* A4 */
+ &Scumm::o6_arrayOps,
+ &Scumm::o6_saveRestoreVerbs,
+ &Scumm::o6_drawBox,
+ &Scumm::o6_invalid,
+ /* A8 */
+ &Scumm::o6_getActorWidth,
+ &Scumm::o6_wait,
+ &Scumm::o6_getActorScaleX,
+ &Scumm::o6_getActorAnimCounter1,
+ /* AC */
+ &Scumm::o6_soundKludge,
+ &Scumm::o6_isAnyOf,
+ &Scumm::o6_quitPauseRestart,
+ &Scumm::o6_isActorInBox,
+ /* B0 */
+ &Scumm::o6_delay,
+ &Scumm::o6_delayLonger,
+ &Scumm::o6_delayVeryLong,
+ &Scumm::o6_stopSentence,
+ /* B4 */
+ &Scumm::o6_print_0,
+ &Scumm::o6_print_1,
+ &Scumm::o6_print_2,
+ &Scumm::o6_print_3,
+ /* B8 */
+ &Scumm::o6_printActor,
+ &Scumm::o6_printEgo,
+ &Scumm::o6_talkActor,
+ &Scumm::o6_talkEgo,
+ /* BC */
+ &Scumm::o6_dim,
+ &Scumm::o5_dummy,
+ &Scumm::o6_runVerbCodeQuick,
+ &Scumm::o6_runScriptQuick,
+ /* C0 */
+ &Scumm::o6_dim2,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ /* C4 */
+ &Scumm::o6_abs,
+ &Scumm::o6_distObjectObject,
+ &Scumm::o6_distObjectPt,
+ &Scumm::o6_distPtPt,
+ /* C8 */
+ &Scumm::o6_kernelFunction,
+ &Scumm::o6_miscOps,
+ &Scumm::o6_breakMaybe,
+ &Scumm::o6_pickOneOf,
+ /* CC */
+ &Scumm::o6_pickOneOfDefault,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ /* D0 */
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_getAnimateVariable,
+ &Scumm::o6_invalid,
+ /* D4 */
+ &Scumm::o6_invalid,
+ &Scumm::o6_jumpToScript,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ /* D8 */
+ &Scumm::o6_isRoomScriptRunning,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ /* DC */
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ /* E0 */
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ /* E4 */
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ /* E8 */
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ /* EC */
+ &Scumm::o6_getActorPriority,
+ &Scumm::o6_getObjectNewDir,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ /* F0 */
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ /* F4 */
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ /* F8 */
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ /* FC */
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
+ &Scumm::o6_invalid,
};
- static const char* opcode_lookup[] = {
- /* 00 */
- "o6_pushByte",
- "o6_pushWord",
- "o6_pushByteVar",
- "o6_pushWordVar",
- /* 04 */
- "o6_invalid",
- "o6_invalid",
- "o6_byteArrayRead",
- "o6_wordArrayRead",
- /* 08 */
- "o6_invalid",
- "o6_invalid",
- "o6_byteArrayIndexedRead",
- "o6_wordArrayIndexedRead",
- /* 0C */
- "o6_dup",
- "o6_zero",
- "o6_eq",
- "o6_neq",
- /* 10 */
- "o6_gt",
- "o6_lt",
- "o6_le",
- "o6_ge",
- /* 14 */
- "o6_add",
- "o6_sub",
- "o6_mul",
- "o6_div",
- /* 18 */
- "o6_land",
- "o6_lor",
- "o6_kill",
- "o6_invalid",
- /* 1C */
- "o6_invalid",
- "o6_invalid",
- "o6_invalid",
- "o6_invalid",
- /* 20 */
- "o6_invalid",
- "o6_invalid",
- "o6_invalid",
- "o6_invalid",
- /* 24 */
- "o6_invalid",
- "o6_invalid",
- "o6_invalid",
- "o6_invalid",
- /* 28 */
- "o6_invalid",
- "o6_invalid",
- "o6_invalid",
- "o6_invalid",
- /* 2C */
- "o6_invalid",
- "o6_invalid",
- "o6_invalid",
- "o6_invalid",
- /* 30 */
- "o6_invalid",
- "o6_invalid",
- "o6_invalid",
- "o6_invalid",
- /* 34 */
- "o6_invalid",
- "o6_invalid",
- "o6_invalid",
- "o6_invalid",
- /* 38 */
- "o6_invalid",
- "o6_invalid",
- "o6_invalid",
- "o6_invalid",
- /* 3C */
- "o6_invalid",
- "o6_invalid",
- "o6_invalid",
- "o6_invalid",
- /* 40 */
- "o6_invalid",
- "o6_invalid",
- "o6_writeByteVar",
- "o6_writeWordVar",
- /* 44 */
- "o6_invalid",
- "o6_invalid",
- "o6_byteArrayWrite",
- "o6_wordArrayWrite",
- /* 48 */
- "o6_invalid",
- "o6_invalid",
- "o6_byteArrayIndexedWrite",
- "o6_wordArrayIndexedWrite",
- /* 4C */
- "o6_invalid",
- "o6_invalid",
- "o6_byteVarInc",
- "o6_wordVarInc",
- /* 50 */
- "o6_invalid",
- "o6_invalid",
- "o6_byteArrayInc",
- "o6_wordArrayInc",
- /* 54 */
- "o6_invalid",
- "o6_invalid",
- "o6_byteVarDec",
- "o6_wordVarDec",
- /* 58 */
- "o6_invalid",
- "o6_invalid",
- "o6_byteArrayDec",
- "o6_wordArrayDec",
- /* 5C */
- "o6_jumpTrue",
- "o6_jumpFalse",
- "o6_startScriptEx",
- "o6_startScript",
- /* 60 */
- "o6_startObject",
- "o6_setObjectState",
- "o6_setObjectXY",
- "o6_drawBlastObject",
- /* 64 */
- "o6_invalid",
- "o6_stopObjectCode",
- "o6_stopObjectCode",
- "o6_endCutscene",
- /* 68 */
- "o6_cutScene",
- "o6_stopMusic",
- "o6_freezeUnfreeze",
- "o6_cursorCommand",
- /* 6C */
- "o6_breakHere",
- "o6_ifClassOfIs",
- "o6_setClass",
- "o6_getState",
- /* 70 */
- "o6_setState",
- "o6_setOwner",
- "o6_getOwner",
- "o6_jump",
- /* 74 */
- "o6_startSound",
- "o6_stopSound",
- "o6_startMusic",
- "o6_stopObjectScript",
- /* 78 */
- "o6_panCameraTo",
- "o6_actorFollowCamera",
- "o6_setCameraAt",
- "o6_loadRoom",
- /* 7C */
- "o6_stopScript",
- "o6_walkActorToObj",
- "o6_walkActorTo",
- "o6_putActorInRoom",
- /* 80 */
- "o6_putActorAtObject",
- "o6_faceActor",
- "o6_animateActor",
- "o6_doSentence",
- /* 84 */
- "o6_pickupObject",
- "o6_loadRoomWithEgo",
- "o6_invalid",
- "o6_getRandomNumber",
- /* 88 */
- "o6_getRandomNumberRange",
- "o6_invalid",
- "o6_getActorMoving",
- "o6_getScriptRunning",
- /* 8C */
- "o6_getActorRoom",
- "o6_getObjectX",
- "o6_getObjectY",
- "o6_getObjectOldDir",
- /* 90 */
- "o6_getActorWalkBox",
- "o6_getActorCostume",
- "o6_findInventory",
- "o6_getInventoryCount",
- /* 94 */
- "o6_getVerbFromXY",
- "o6_beginOverride",
- "o6_endOverride",
- "o6_setObjectName",
- /* 98 */
- "o6_isSoundRunning",
- "o6_setBoxFlags",
- "o6_createBoxMatrix",
- "o6_resourceRoutines",
- /* 9C */
- "o6_roomOps",
- "o6_actorSet",
- "o6_verbOps",
- "o6_getActorFromXY",
- /* A0 */
- "o6_findObject",
- "o6_pseudoRoom",
- "o6_getActorElevation",
- "o6_getVerbEntrypoint",
- /* A4 */
- "o6_arrayOps",
- "o6_saveRestoreVerbs",
- "o6_drawBox",
- "o6_invalid",
- /* A8 */
- "o6_getActorWidth",
- "o6_wait",
- "o6_getActorScaleX",
- "o6_getActorAnimCounter1",
- /* AC */
- "o6_soundKludge",
- "o6_isAnyOf",
- "o6_quitPauseRestart",
- "o6_isActorInBox",
- /* B0 */
- "o6_delay",
- "o6_delayLonger",
- "o6_delayVeryLong",
- "o6_stopSentence",
- /* B4 */
- "o6_print_0",
- "o6_print_1",
- "o6_print_2",
- "o6_print_3",
- /* B8 */
- "o6_printActor",
- "o6_printEgo",
- "o6_talkActor",
- "o6_talkEgo",
- /* BC */
- "o6_dim",
- "o6_invalid",
- "o6_runVerbCodeQuick",
- "o6_runScriptQuick",
- /* C0 */
- "o6_dim2",
- "o6_invalid",
- "o6_invalid",
- "o6_invalid",
- /* C4 */
- "o6_abs",
- "o6_distObjectObject",
- "o6_distObjectPt",
- "o6_distPtPt",
- /* C8 */
- "o6_kernelFunction",
- "o6_miscOps",
- "o6_breakMaybe",
- "o6_pickOneOf",
- /* CC */
- "o6_pickOneOfDefault",
- "o6_invalid",
- "o6_invalid",
- "o6_invalid",
- /* D0 */
- "o6_invalid",
- "o6_invalid",
- "o6_getAnimateVariable",
- "o6_invalid",
- /* D4 */
- "o6_invalid",
- "o6_jumpToScript",
- "o6_invalid",
- "o6_invalid",
- /* D8 */
- "o6_isRoomScriptRunning",
- "o6_invalid",
- "o6_invalid",
- "o6_invalid",
- /* DC */
- "o6_invalid",
- "o6_invalid",
- "o6_invalid",
- "o6_invalid",
- /* E0 */
- "o6_invalid",
- "o6_invalid",
- "o6_invalid",
- "o6_invalid",
- /* E4 */
- "o6_invalid",
- "o6_invalid",
- "o6_invalid",
- "o6_invalid",
- /* E8 */
- "o6_invalid",
- "o6_invalid",
- "o6_invalid",
- "o6_invalid",
- /* EC */
- "o6_invalid",
- "o6_getObjectNewDir",
- "o6_invalid",
- "o6_invalid",
- /* F0 */
- "o6_invalid",
- "o6_invalid",
- "o6_invalid",
- "o6_invalid",
- /* F4 */
- "o6_invalid",
- "o6_invalid",
- "o6_invalid",
- "o6_invalid",
- /* F8 */
- "o6_invalid",
- "o6_invalid",
- "o6_invalid",
- "o6_invalid",
- /* FC */
- "o6_invalid",
- "o6_invalid",
- "o6_invalid",
- "o6_invalid"
+ static const char *opcode_lookup[] = {
+ /* 00 */
+ "o6_pushByte",
+ "o6_pushWord",
+ "o6_pushByteVar",
+ "o6_pushWordVar",
+ /* 04 */
+ "o6_invalid",
+ "o6_invalid",
+ "o6_byteArrayRead",
+ "o6_wordArrayRead",
+ /* 08 */
+ "o6_invalid",
+ "o6_invalid",
+ "o6_byteArrayIndexedRead",
+ "o6_wordArrayIndexedRead",
+ /* 0C */
+ "o6_dup",
+ "o6_zero",
+ "o6_eq",
+ "o6_neq",
+ /* 10 */
+ "o6_gt",
+ "o6_lt",
+ "o6_le",
+ "o6_ge",
+ /* 14 */
+ "o6_add",
+ "o6_sub",
+ "o6_mul",
+ "o6_div",
+ /* 18 */
+ "o6_land",
+ "o6_lor",
+ "o6_kill",
+ "o6_invalid",
+ /* 1C */
+ "o6_invalid",
+ "o6_invalid",
+ "o6_invalid",
+ "o6_invalid",
+ /* 20 */
+ "o6_invalid",
+ "o6_invalid",
+ "o6_invalid",
+ "o6_invalid",
+ /* 24 */
+ "o6_invalid",
+ "o6_invalid",
+ "o6_invalid",
+ "o6_invalid",
+ /* 28 */
+ "o6_invalid",
+ "o6_invalid",
+ "o6_invalid",
+ "o6_invalid",
+ /* 2C */
+ "o6_invalid",
+ "o6_invalid",
+ "o6_invalid",
+ "o6_invalid",
+ /* 30 */
+ "o6_invalid",
+ "o6_invalid",
+ "o6_invalid",
+ "o6_invalid",
+ /* 34 */
+ "o6_invalid",
+ "o6_invalid",
+ "o6_invalid",
+ "o6_invalid",
+ /* 38 */
+ "o6_invalid",
+ "o6_invalid",
+ "o6_invalid",
+ "o6_invalid",
+ /* 3C */
+ "o6_invalid",
+ "o6_invalid",
+ "o6_invalid",
+ "o6_invalid",
+ /* 40 */
+ "o6_invalid",
+ "o6_invalid",
+ "o6_writeByteVar",
+ "o6_writeWordVar",
+ /* 44 */
+ "o6_invalid",
+ "o6_invalid",
+ "o6_byteArrayWrite",
+ "o6_wordArrayWrite",
+ /* 48 */
+ "o6_invalid",
+ "o6_invalid",
+ "o6_byteArrayIndexedWrite",
+ "o6_wordArrayIndexedWrite",
+ /* 4C */
+ "o6_invalid",
+ "o6_invalid",
+ "o6_byteVarInc",
+ "o6_wordVarInc",
+ /* 50 */
+ "o6_invalid",
+ "o6_invalid",
+ "o6_byteArrayInc",
+ "o6_wordArrayInc",
+ /* 54 */
+ "o6_invalid",
+ "o6_invalid",
+ "o6_byteVarDec",
+ "o6_wordVarDec",
+ /* 58 */
+ "o6_invalid",
+ "o6_invalid",
+ "o6_byteArrayDec",
+ "o6_wordArrayDec",
+ /* 5C */
+ "o6_jumpTrue",
+ "o6_jumpFalse",
+ "o6_startScriptEx",
+ "o6_startScript",
+ /* 60 */
+ "o6_startObject",
+ "o6_setObjectState",
+ "o6_setObjectXY",
+ "o6_drawBlastObject",
+ /* 64 */
+ "o6_invalid",
+ "o6_stopObjectCode",
+ "o6_stopObjectCode",
+ "o6_endCutscene",
+ /* 68 */
+ "o6_cutScene",
+ "o6_stopMusic",
+ "o6_freezeUnfreeze",
+ "o6_cursorCommand",
+ /* 6C */
+ "o6_breakHere",
+ "o6_ifClassOfIs",
+ "o6_setClass",
+ "o6_getState",
+ /* 70 */
+ "o6_setState",
+ "o6_setOwner",
+ "o6_getOwner",
+ "o6_jump",
+ /* 74 */
+ "o6_startSound",
+ "o6_stopSound",
+ "o6_startMusic",
+ "o6_stopObjectScript",
+ /* 78 */
+ "o6_panCameraTo",
+ "o6_actorFollowCamera",
+ "o6_setCameraAt",
+ "o6_loadRoom",
+ /* 7C */
+ "o6_stopScript",
+ "o6_walkActorToObj",
+ "o6_walkActorTo",
+ "o6_putActorInRoom",
+ /* 80 */
+ "o6_putActorAtObject",
+ "o6_faceActor",
+ "o6_animateActor",
+ "o6_doSentence",
+ /* 84 */
+ "o6_pickupObject",
+ "o6_loadRoomWithEgo",
+ "o6_invalid",
+ "o6_getRandomNumber",
+ /* 88 */
+ "o6_getRandomNumberRange",
+ "o6_invalid",
+ "o6_getActorMoving",
+ "o6_getScriptRunning",
+ /* 8C */
+ "o6_getActorRoom",
+ "o6_getObjectX",
+ "o6_getObjectY",
+ "o6_getObjectOldDir",
+ /* 90 */
+ "o6_getActorWalkBox",
+ "o6_getActorCostume",
+ "o6_findInventory",
+ "o6_getInventoryCount",
+ /* 94 */
+ "o6_getVerbFromXY",
+ "o6_beginOverride",
+ "o6_endOverride",
+ "o6_setObjectName",
+ /* 98 */
+ "o6_isSoundRunning",
+ "o6_setBoxFlags",
+ "o6_createBoxMatrix",
+ "o6_resourceRoutines",
+ /* 9C */
+ "o6_roomOps",
+ "o6_actorSet",
+ "o6_verbOps",
+ "o6_getActorFromXY",
+ /* A0 */
+ "o6_findObject",
+ "o6_pseudoRoom",
+ "o6_getActorElevation",
+ "o6_getVerbEntrypoint",
+ /* A4 */
+ "o6_arrayOps",
+ "o6_saveRestoreVerbs",
+ "o6_drawBox",
+ "o6_invalid",
+ /* A8 */
+ "o6_getActorWidth",
+ "o6_wait",
+ "o6_getActorScaleX",
+ "o6_getActorAnimCounter1",
+ /* AC */
+ "o6_soundKludge",
+ "o6_isAnyOf",
+ "o6_quitPauseRestart",
+ "o6_isActorInBox",
+ /* B0 */
+ "o6_delay",
+ "o6_delayLonger",
+ "o6_delayVeryLong",
+ "o6_stopSentence",
+ /* B4 */
+ "o6_print_0",
+ "o6_print_1",
+ "o6_print_2",
+ "o6_print_3",
+ /* B8 */
+ "o6_printActor",
+ "o6_printEgo",
+ "o6_talkActor",
+ "o6_talkEgo",
+ /* BC */
+ "o6_dim",
+ "o6_invalid",
+ "o6_runVerbCodeQuick",
+ "o6_runScriptQuick",
+ /* C0 */
+ "o6_dim2",
+ "o6_invalid",
+ "o6_invalid",
+ "o6_invalid",
+ /* C4 */
+ "o6_abs",
+ "o6_distObjectObject",
+ "o6_distObjectPt",
+ "o6_distPtPt",
+ /* C8 */
+ "o6_kernelFunction",
+ "o6_miscOps",
+ "o6_breakMaybe",
+ "o6_pickOneOf",
+ /* CC */
+ "o6_pickOneOfDefault",
+ "o6_invalid",
+ "o6_invalid",
+ "o6_invalid",
+ /* D0 */
+ "o6_invalid",
+ "o6_invalid",
+ "o6_getAnimateVariable",
+ "o6_invalid",
+ /* D4 */
+ "o6_invalid",
+ "o6_jumpToScript",
+ "o6_invalid",
+ "o6_invalid",
+ /* D8 */
+ "o6_isRoomScriptRunning",
+ "o6_invalid",
+ "o6_invalid",
+ "o6_invalid",
+ /* DC */
+ "o6_invalid",
+ "o6_invalid",
+ "o6_invalid",
+ "o6_invalid",
+ /* E0 */
+ "o6_invalid",
+ "o6_invalid",
+ "o6_invalid",
+ "o6_invalid",
+ /* E4 */
+ "o6_invalid",
+ "o6_invalid",
+ "o6_invalid",
+ "o6_invalid",
+ /* E8 */
+ "o6_invalid",
+ "o6_invalid",
+ "o6_invalid",
+ "o6_invalid",
+ /* EC */
+ "o6_invalid",
+ "o6_getObjectNewDir",
+ "o6_invalid",
+ "o6_invalid",
+ /* F0 */
+ "o6_invalid",
+ "o6_invalid",
+ "o6_invalid",
+ "o6_invalid",
+ /* F4 */
+ "o6_invalid",
+ "o6_invalid",
+ "o6_invalid",
+ "o6_invalid",
+ /* F8 */
+ "o6_invalid",
+ "o6_invalid",
+ "o6_invalid",
+ "o6_invalid",
+ /* FC */
+ "o6_invalid",
+ "o6_invalid",
+ "o6_invalid",
+ "o6_invalid"
};
_opcodes = opcode_list;
_opcodes_lookup = opcode_lookup;
}
-void Scumm::o6_bompWindow() { // Set BOMP processing window
+void Scumm::o6_bompWindow()
+{ // Set BOMP processing window
int a, b, c, d;
-
+
d = pop();
c = pop();
b = pop();
a = pop();
-
- warning("o6_bompWindow(%d, %d, %d, %d)", a, b, c, d);
+
+ warning("o6_bompWindow(%d, %d, %d, %d)", a, b, c, d);
// sub_274EF(a, b, c, d);
}
-int Scumm::popRoomAndObj(int *room) {
+int Scumm::popRoomAndObj(int *room)
+{
int obj;
if (_features & GF_HAS_ROOMTABLE) {
@@ -701,42 +704,47 @@ int Scumm::popRoomAndObj(int *room) {
}
-int Scumm::readArray(int array, int idx, int base) {
- ArrayHeader *ah = (ArrayHeader*)getResourceAddress(rtString, readVar(array));
+int Scumm::readArray(int array, int idx, int base)
+{
+ ArrayHeader *ah =
+ (ArrayHeader *)getResourceAddress(rtString, readVar(array));
- if (ah==NULL) {
- error("readArray: invalid array %d (%d)", array, readVar(array));
+ if (ah == NULL) {
+ error("readArray: invalid array %d (%d)", array, readVar(array));
}
- base += idx*ah->dim1_size;
+ base += idx * ah->dim1_size;
- assert(base>=0 && base < ah->dim1_size*ah->dim2_size);
+ assert(base >= 0 && base < ah->dim1_size * ah->dim2_size);
- if (ah->type==4) {
+ if (ah->type == 4) {
return ah->data[base];
} else {
- return (int16)READ_LE_UINT16(ah->data + base*2);
+ return (int16) READ_LE_UINT16(ah->data + base * 2);
}
}
-void Scumm::writeArray(int array, int idx, int base, int value) {
- ArrayHeader *ah = (ArrayHeader*)getResourceAddress(rtString, readVar(array));
+void Scumm::writeArray(int array, int idx, int base, int value)
+{
+ ArrayHeader *ah =
+ (ArrayHeader *)getResourceAddress(rtString, readVar(array));
assert(ah);
- base += idx*ah->dim1_size;
+ base += idx * ah->dim1_size;
- assert(base>=0 && base < ah->dim1_size*ah->dim2_size);
+ assert(base >= 0 && base < ah->dim1_size * ah->dim2_size);
- if (ah->type==4) {
+ if (ah->type == 4) {
ah->data[base] = value;
} else {
- ((uint16*)ah->data)[base] = TO_LE_16(value);
+ ((uint16 *)ah->data)[base] = TO_LE_16(value);
}
}
-int Scumm::getStackList(int16 *args, uint maxnum) {
+int Scumm::getStackList(int16 * args, uint maxnum)
+{
uint num, i;
- for (i=0; i<maxnum; i++)
+ for (i = 0; i < maxnum; i++)
args[i] = 0;
num = pop();
@@ -745,297 +753,352 @@ int Scumm::getStackList(int16 *args, uint maxnum) {
error("Too many items %d in stack list, max %d", num, maxnum);
i = num;
- while (((int)--i)>=0) {
+ while (((int)--i) >= 0) {
args[i] = pop();
}
return num;
}
-void Scumm::o6_pushByte() {
+void Scumm::o6_pushByte()
+{
push(fetchScriptByte());
}
-void Scumm::o6_pushWord() {
- push((int16)fetchScriptWord());
+void Scumm::o6_pushWord()
+{
+ push((int16) fetchScriptWord());
}
-void Scumm::o6_pushByteVar() {
+void Scumm::o6_pushByteVar()
+{
push(readVar(fetchScriptByte()));
}
-void Scumm::o6_pushWordVar() {
+void Scumm::o6_pushWordVar()
+{
push(readVar(fetchScriptWord()));
}
-void Scumm::o6_invalid() {
- error("Invalid opcode '%x' at %x", _opcode, _scriptPointer - _scriptOrgPointer);
+void Scumm::o6_invalid()
+{
+ error("Invalid opcode '%x' at %x", _opcode,
+ _scriptPointer - _scriptOrgPointer);
}
-void Scumm::o6_byteArrayRead() {
+void Scumm::o6_byteArrayRead()
+{
int base = pop();
push(readArray(fetchScriptByte(), 0, base));
}
-void Scumm::o6_wordArrayRead() {
+void Scumm::o6_wordArrayRead()
+{
int base = pop();
push(readArray(fetchScriptWord(), 0, base));
}
-void Scumm::o6_byteArrayIndexedRead() {
+void Scumm::o6_byteArrayIndexedRead()
+{
int base = pop();
int idx = pop();
push(readArray(fetchScriptByte(), idx, base));
}
-void Scumm::o6_wordArrayIndexedRead() {
+void Scumm::o6_wordArrayIndexedRead()
+{
int base = pop();
int idx = pop();
push(readArray(fetchScriptWord(), idx, base));
}
-void Scumm::o6_dup() {
+void Scumm::o6_dup()
+{
int a = pop();
push(a);
push(a);
}
-void Scumm::o6_zero() {
- push( pop() == 0 );
+void Scumm::o6_zero()
+{
+ push(pop() == 0);
}
-void Scumm::o6_eq() {
- push( pop() == pop() );
+void Scumm::o6_eq()
+{
+ push(pop() == pop());
}
-void Scumm::o6_neq() {
- push( pop() != pop() );
+void Scumm::o6_neq()
+{
+ push(pop() != pop());
}
-void Scumm::o6_gt() {
+void Scumm::o6_gt()
+{
int a = pop();
- push( pop() > a );
+ push(pop() > a);
}
-void Scumm::o6_lt() {
+void Scumm::o6_lt()
+{
int a = pop();
- push( pop() < a );
+ push(pop() < a);
}
-void Scumm::o6_le() {
+void Scumm::o6_le()
+{
int a = pop();
- push( pop() <= a );
+ push(pop() <= a);
}
-void Scumm::o6_ge() {
+void Scumm::o6_ge()
+{
int a = pop();
- push( pop() >= a );
+ push(pop() >= a);
}
-void Scumm::o6_add() {
+void Scumm::o6_add()
+{
int a = pop();
- push( pop() + a );
+ push(pop() + a);
}
-void Scumm::o6_sub() {
+void Scumm::o6_sub()
+{
int a = pop();
- push( pop() - a );
+ push(pop() - a);
}
-void Scumm::o6_mul() {
+void Scumm::o6_mul()
+{
int a = pop();
- push( pop() * a );
+ push(pop() * a);
}
-void Scumm::o6_div() {
+void Scumm::o6_div()
+{
int a = pop();
- if (a==0) error("division by zero");
- push( pop() / a );
+ if (a == 0)
+ error("division by zero");
+ push(pop() / a);
}
-void Scumm::o6_land() {
+void Scumm::o6_land()
+{
int a = pop();
- push( pop() && a );
+ push(pop() && a);
}
-void Scumm::o6_lor() {
+void Scumm::o6_lor()
+{
int a = pop();
- push( pop() || a );
+ push(pop() || a);
}
-void Scumm::o6_kill() {
+void Scumm::o6_kill()
+{
pop();
}
-void Scumm::o6_writeByteVar() {
+void Scumm::o6_writeByteVar()
+{
writeVar(fetchScriptByte(), pop());
}
-void Scumm::o6_writeWordVar() {
+void Scumm::o6_writeWordVar()
+{
writeVar(fetchScriptWord(), pop());
}
-void Scumm::o6_byteArrayWrite() {
+void Scumm::o6_byteArrayWrite()
+{
int a = pop();
writeArray(fetchScriptByte(), 0, pop(), a);
}
-void Scumm::o6_wordArrayWrite() {
+void Scumm::o6_wordArrayWrite()
+{
int a = pop();
writeArray(fetchScriptWord(), 0, pop(), a);
}
-void Scumm::o6_byteArrayIndexedWrite() {
+void Scumm::o6_byteArrayIndexedWrite()
+{
int val = pop();
int base = pop();
writeArray(fetchScriptByte(), pop(), base, val);
}
-void Scumm::o6_wordArrayIndexedWrite() {
+void Scumm::o6_wordArrayIndexedWrite()
+{
int val = pop();
int base = pop();
writeArray(fetchScriptWord(), pop(), base, val);
}
-void Scumm::o6_byteVarInc() {
+void Scumm::o6_byteVarInc()
+{
int var = fetchScriptByte();
- writeVar(var,readVar(var)+1);
+ writeVar(var, readVar(var) + 1);
}
-void Scumm::o6_wordVarInc() {
+void Scumm::o6_wordVarInc()
+{
int var = fetchScriptWord();
- writeVar(var,readVar(var)+1);
+ writeVar(var, readVar(var) + 1);
}
-void Scumm::o6_byteArrayInc() {
+void Scumm::o6_byteArrayInc()
+{
int var = fetchScriptByte();
int base = pop();
writeArray(var, 0, base, readArray(var, 0, base) + 1);
}
-void Scumm::o6_wordArrayInc() {
+void Scumm::o6_wordArrayInc()
+{
int var = fetchScriptWord();
int base = pop();
writeArray(var, 0, base, readArray(var, 0, base) + 1);
}
-void Scumm::o6_byteVarDec() {
+void Scumm::o6_byteVarDec()
+{
int var = fetchScriptByte();
- writeVar(var,readVar(var)-1);
+ writeVar(var, readVar(var) - 1);
}
-void Scumm::o6_wordVarDec() {
+void Scumm::o6_wordVarDec()
+{
int var = fetchScriptWord();
- writeVar(var,readVar(var)-1);
+ writeVar(var, readVar(var) - 1);
}
-void Scumm::o6_byteArrayDec() {
+void Scumm::o6_byteArrayDec()
+{
int var = fetchScriptByte();
int base = pop();
writeArray(var, 0, base, readArray(var, 0, base) - 1);
}
-void Scumm::o6_wordArrayDec() {
+void Scumm::o6_wordArrayDec()
+{
int var = fetchScriptWord();
int base = pop();
writeArray(var, 0, base, readArray(var, 0, base) - 1);
}
-void Scumm::o6_jumpTrue() {
+void Scumm::o6_jumpTrue()
+{
if (pop())
o6_jump();
else
fetchScriptWord();
}
-void Scumm::o6_jumpFalse() {
+void Scumm::o6_jumpFalse()
+{
if (!pop())
o6_jump();
else
fetchScriptWord();
}
-void Scumm::o6_jump() {
- _scriptPointer += (int16)fetchScriptWord();
+void Scumm::o6_jump()
+{
+ _scriptPointer += (int16) fetchScriptWord();
}
-void Scumm::o6_startScriptEx() {
+void Scumm::o6_startScriptEx()
+{
int16 args[16];
- int script,flags;
+ int script, flags;
- getStackList(args,sizeof(args)/sizeof(args[0]));
+ getStackList(args, sizeof(args) / sizeof(args[0]));
script = pop();
flags = pop();
- runScript(script, flags&1, flags&2, args);
+ runScript(script, flags & 1, flags & 2, args);
}
-void Scumm::o6_jumpToScript() {
+void Scumm::o6_jumpToScript()
+{
int16 args[16];
- int script,flags;
+ int script, flags;
- getStackList(args,sizeof(args)/sizeof(args[0]));
+ getStackList(args, sizeof(args) / sizeof(args[0]));
script = pop();
flags = pop();
o6_stopObjectCode();
- runScript(script, flags&1, flags&2, args);
+ runScript(script, flags & 1, flags & 2, args);
}
-void Scumm::o6_startScript() {
+void Scumm::o6_startScript()
+{
int16 args[16];
int script;
- getStackList(args,sizeof(args)/sizeof(args[0]));
+ getStackList(args, sizeof(args) / sizeof(args[0]));
script = pop();
runScript(script, 0, 0, args);
}
-void Scumm::o6_startObject() {
+void Scumm::o6_startObject()
+{
int16 args[16];
- int script,entryp;
+ int script, entryp;
int flags;
- getStackList(args,sizeof(args)/sizeof(args[0]));
+ getStackList(args, sizeof(args) / sizeof(args[0]));
entryp = pop();
script = pop();
flags = pop();
- runVerbCode(script, entryp, flags&1, flags&2, args);
+ runVerbCode(script, entryp, flags & 1, flags & 2, args);
}
-void Scumm::o6_setObjectState() {
+void Scumm::o6_setObjectState()
+{
int a = pop();
int b = pop();
- if (a==0) a=1;
-// debug(1, "setObjectState(%d,%d)", a, b);
-
+ if (a == 0)
+ a = 1;
+// debug(1, "setObjectState(%d,%d)", a, b);
+
setObjectState(b, a, -1, -1);
}
-void Scumm::o6_setObjectXY() {
+void Scumm::o6_setObjectXY()
+{
int y = pop();
int x = pop();
int obj = pop();
-// debug(1, "setObjectXY(%d,%d,%d)", obj, x, y);
+// debug(1, "setObjectXY(%d,%d,%d)", obj, x, y);
setObjectState(obj, 1, x, y);
}
-void Scumm::o6_stopObjectCode() {
+void Scumm::o6_stopObjectCode()
+{
stopObjectCode();
}
-void Scumm::o6_endCutscene() {
+void Scumm::o6_endCutscene()
+{
endCutscene();
}
-void Scumm::o6_cutScene() {
+void Scumm::o6_cutScene()
+{
int16 args[16];
- getStackList(args,sizeof(args)/sizeof(args[0]));
+ getStackList(args, sizeof(args) / sizeof(args[0]));
cutscene(args);
}
-void Scumm::o6_stopMusic() {
+void Scumm::o6_stopMusic()
+{
stopAllSounds();
}
-void Scumm::o6_freezeUnfreeze() {
+void Scumm::o6_freezeUnfreeze()
+{
int a = pop();
if (a)
freezeScripts(a);
@@ -1043,11 +1106,12 @@ void Scumm::o6_freezeUnfreeze() {
unfreezeScripts();
}
-void Scumm::o6_cursorCommand() {
- int a,i;
+void Scumm::o6_cursorCommand()
+{
+ int a, i;
int16 args[16];
- switch(fetchScriptByte()) {
+ switch (fetchScriptByte()) {
case 0x90:
_cursorState = 1;
verbMouseOver(0);
@@ -1078,22 +1142,23 @@ void Scumm::o6_cursorCommand() {
case 0x97:
_userPut--;
break;
- case 0x99: {
- int room,obj = popRoomAndObj(&room);
- setCursorImg(obj,room, 1);
- break;
- }
+ case 0x99:{
+ int room, obj = popRoomAndObj(&room);
+ setCursorImg(obj, room, 1);
+ break;
+ }
case 0x9A:
a = pop();
- setCursorHotspot2(pop(),a);
+ setCursorHotspot2(pop(), a);
break;
- case 0x9C: /* init charset */
+ case 0x9C: /* init charset */
initCharset(pop());
break;
- case 0x9D: /* set charset colors */
- getStackList(args,sizeof(args)/sizeof(args[0]));
- for (i=0; i<16; i++)
- charset._colorMap[i] = _charsetData[string[1].t_charset][i] = (unsigned char)args[i];
+ case 0x9D: /* set charset colors */
+ getStackList(args, sizeof(args) / sizeof(args[0]));
+ for (i = 0; i < 16; i++)
+ charset._colorMap[i] = _charsetData[string[1].t_charset][i] =
+ (unsigned char)args[i];
break;
case 0xD6:
makeCursorColorTransparent(pop());
@@ -1106,56 +1171,61 @@ void Scumm::o6_cursorCommand() {
_vars[VAR_USERPUT] = _userPut;
}
-void Scumm::o6_breakHere() {
+void Scumm::o6_breakHere()
+{
updateScriptPtr();
_currentScript = 0xFF;
}
-void Scumm::o6_ifClassOfIs() {
+void Scumm::o6_ifClassOfIs()
+{
int16 args[16];
- int num,obj,cls;
+ int num, obj, cls;
bool b;
int cond = 1;
- num = getStackList(args,sizeof(args)/sizeof(args[0]));
+ num = getStackList(args, sizeof(args) / sizeof(args[0]));
obj = pop();
- while (--num>=0) {
+ while (--num >= 0) {
cls = args[num];
b = getClass(obj, cls);
- if (cls&0x80 && !b || !(cls&0x80) && b)
+ if (cls & 0x80 && !b || !(cls & 0x80) && b)
cond = 0;
}
push(cond);
}
-void Scumm::o6_setClass() {
+void Scumm::o6_setClass()
+{
int16 args[16];
- int num,obj,cls;
+ int num, obj, cls;
- num = getStackList(args,sizeof(args)/sizeof(args[0]));
+ num = getStackList(args, sizeof(args) / sizeof(args[0]));
obj = pop();
- while (--num>=0) {
+ while (--num >= 0) {
cls = args[num];
- if (cls==0)
+ if (cls == 0)
_classData[num] = 0;
- else if (cls&0x80)
+ else if (cls & 0x80)
putClass(obj, cls, 1);
else
putClass(obj, cls, 0);
}
}
-void Scumm::o6_getState() {
+void Scumm::o6_getState()
+{
push(getState(pop()));
}
-void Scumm::o6_setState() {
+void Scumm::o6_setState()
+{
int state = pop();
int obj = pop();
-// debug(1, "setState(%d,%d)", obj, state);
+// debug(1, "setState(%d,%d)", obj, state);
putState(obj, state);
removeObjectFromRoom(obj);
@@ -1163,112 +1233,125 @@ void Scumm::o6_setState() {
clearDrawObjectQueue();
}
-void Scumm::o6_setOwner() {
+void Scumm::o6_setOwner()
+{
int owner = pop();
int obj = pop();
setOwnerOf(obj, owner);
}
-void Scumm::o6_getOwner() {
+void Scumm::o6_getOwner()
+{
push(getOwner(pop()));
}
-void Scumm::o6_startSound() {
+void Scumm::o6_startSound()
+{
addSoundToQueue(pop());
}
-void Scumm::o6_stopSound() {
+void Scumm::o6_stopSound()
+{
stopSound(pop());
}
-void Scumm::o6_startMusic() {
+void Scumm::o6_startMusic()
+{
addSoundToQueue(pop());
}
-void Scumm::o6_stopObjectScript() {
+void Scumm::o6_stopObjectScript()
+{
stopObjectScript(pop());
}
-void Scumm::o6_panCameraTo() {
- if(_features & GF_AFTER_V7) {
+void Scumm::o6_panCameraTo()
+{
+ if (_features & GF_AFTER_V7) {
int y = pop();
int x = pop();
- panCameraTo(x,y);
+ panCameraTo(x, y);
} else {
panCameraTo(pop(), 0);
}
}
-void Scumm::o6_actorFollowCamera() {
- if(_features & GF_AFTER_V7)
+void Scumm::o6_actorFollowCamera()
+{
+ if (_features & GF_AFTER_V7)
setCameraFollows(derefActorSafe(pop(), "actorFollowCamera"));
else
actorFollowCamera(pop());
}
-void Scumm::o6_setCameraAt() {
- if(_features & GF_AFTER_V7) {
- int x,y;
+void Scumm::o6_setCameraAt()
+{
+ if (_features & GF_AFTER_V7) {
+ int x, y;
camera._follows = 0;
y = pop();
x = pop();
-
- setCameraAt(x,y);
+
+ setCameraAt(x, y);
} else {
setCameraAtEx(pop());
- }
+ }
}
-void Scumm::o6_loadRoom() {
+void Scumm::o6_loadRoom()
+{
int room;
/* Begin: Autosave
- _saveLoadSlot = 0;
- sprintf(_saveLoadName, "Autosave", _saveLoadSlot);
- _saveLoadFlag = 1;
- _saveLoadCompatible = false;
- End: Autosave */
+ _saveLoadSlot = 0;
+ sprintf(_saveLoadName, "Autosave", _saveLoadSlot);
+ _saveLoadFlag = 1;
+ _saveLoadCompatible = false;
+ End: Autosave */
room = pop();
startScene(room, 0, 0);
_fullRedraw = 1;
}
-void Scumm::o6_stopScript() {
+void Scumm::o6_stopScript()
+{
int script = pop();
- if (script==0)
+ if (script == 0)
stopObjectCode();
else
stopScriptNr(script);
}
-void Scumm::o6_walkActorToObj() {
- int obj,dist;
+void Scumm::o6_walkActorToObj()
+{
+ int obj, dist;
Actor *a, *a2;
int x;
dist = pop();
obj = pop();
a = derefActorSafe(pop(), "o6_walkActorToObj");
- if (!a) return;
+ if (!a)
+ return;
if (obj >= NUM_ACTORS) {
- if (whereIsObject(obj)==WIO_NOT_FOUND)
+ if (whereIsObject(obj) == WIO_NOT_FOUND)
return;
getObjectXYPos(obj);
startWalkActor(a, _xPos, _yPos, _dir);
} else {
a2 = derefActorSafe(obj, "o6_walkActorToObj(2)");
- if (!a2) return;
- if (a2->room != _currentRoom ||
- a->room != _currentRoom)
- return;
- if (dist==0) {
+ if (!a2)
+ return;
+ if (a2->room != _currentRoom || a->room != _currentRoom)
+ return;
+ if (dist == 0) {
dist = a2->scalex * a2->width / 0xFF;
- dist += dist>>1;
+ dist += dist >> 1;
}
x = a2->x;
if (x < a->x)
@@ -1279,14 +1362,16 @@ void Scumm::o6_walkActorToObj() {
}
}
-void Scumm::o6_walkActorTo() {
- int x,y;
+void Scumm::o6_walkActorTo()
+{
+ int x, y;
y = pop();
x = pop();
startWalkActor(derefActorSafe(pop(), "o6_walkActorTo"), x, y, -1);
}
-void Scumm::o6_putActorInRoom() {
+void Scumm::o6_putActorInRoom()
+{
int room, x, y;
Actor *a;
@@ -1297,10 +1382,11 @@ void Scumm::o6_putActorInRoom() {
if (!a)
return;
- if (room==0xFF) {
+ if (room == 0xFF) {
room = a->room;
} else {
- if (a->visible && _currentRoom != room && _vars[VAR_TALK_ACTOR]==a->number) {
+ if (a->visible && _currentRoom != room
+ && _vars[VAR_TALK_ACTOR] == a->number) {
clearMsgQueue();
}
if (room != 0)
@@ -1310,14 +1396,15 @@ void Scumm::o6_putActorInRoom() {
}
-void Scumm::o6_putActorAtObject() {
- int room,obj,x,y;
+void Scumm::o6_putActorAtObject()
+{
+ int room, obj, x, y;
Actor *a;
- obj=popRoomAndObj(&room);
+ obj = popRoomAndObj(&room);
a = derefActorSafe(pop(), "o6_putActorAtObject");
- if (whereIsObject(obj)!=WIO_NOT_FOUND) {
+ if (whereIsObject(obj) != WIO_NOT_FOUND) {
getObjectXYPos(obj);
x = _xPos;
y = _yPos;
@@ -1330,18 +1417,20 @@ void Scumm::o6_putActorAtObject() {
putActor(a, x, y, room);
}
-void Scumm::o6_faceActor() {
- int act,obj;
+void Scumm::o6_faceActor()
+{
+ int act, obj;
obj = pop();
act = pop();
faceActorToObj(act, obj);
}
-void Scumm::o6_animateActor() {
+void Scumm::o6_animateActor()
+{
int anim = pop();
int act = pop();
- if (_gameId==GID_TENTACLE && act==593) {
+ if (_gameId == GID_TENTACLE && act == 593) {
warning("o6_animateActor(%d,%d): fixed tentacle bug", act, anim);
return;
}
@@ -1349,57 +1438,60 @@ void Scumm::o6_animateActor() {
animateActor(act, anim);
}
-void Scumm::o6_doSentence() {
- int a,b,c;
+void Scumm::o6_doSentence()
+{
+ int a, b, c;
a = pop();
- pop(); //dummy pop
+ pop(); //dummy pop
b = pop();
c = pop();
- doSentence(c,b,a);
+ doSentence(c, b, a);
}
-void Scumm::o6_pickupObject() {
+void Scumm::o6_pickupObject()
+{
int obj, room;
int i;
- obj=popRoomAndObj(&room);
- if (room==0)
+ obj = popRoomAndObj(&room);
+ if (room == 0)
room = _roomResource;
- for(i=1; i<_maxInventoryItems; i++) {
+ for (i = 1; i < _maxInventoryItems; i++) {
if (_inventory[i] == (uint16)obj) {
putOwner(obj, _vars[VAR_EGO]);
runHook(obj);
return;
}
}
-
+
addObjectToInventory(obj, room);
putOwner(obj, _vars[VAR_EGO]);
putClass(obj, 32, 1);
putState(obj, 1);
removeObjectFromRoom(obj);
clearDrawObjectQueue();
- runHook(obj); /* Difference */
+ runHook(obj); /* Difference */
}
-void Scumm::o6_loadRoomWithEgo() {
+void Scumm::o6_loadRoomWithEgo()
+{
Actor *a;
- int room,obj,x,y;
+ int room, obj, x, y;
/* Begin: Autosave
- _saveLoadSlot = 0;
- sprintf(_saveLoadName, "Autosave", _saveLoadSlot);
- _saveLoadFlag = 1;
- _saveLoadCompatible = false;
- End: Autosave */
+ _saveLoadSlot = 0;
+ sprintf(_saveLoadName, "Autosave", _saveLoadSlot);
+ _saveLoadFlag = 1;
+ _saveLoadCompatible = false;
+ End: Autosave */
y = pop();
x = pop();
-
- obj=popRoomAndObj(&room);
+
+ obj = popRoomAndObj(&room);
a = derefActorSafe(_vars[VAR_EGO], "o_loadRoomWithEgo");
@@ -1411,101 +1503,119 @@ void Scumm::o6_loadRoomWithEgo() {
_vars[VAR_WALKTO_OBJ] = 0;
/* startScene maybe modifies VAR_EGO, i hope not */
-
- if(!(_features & GF_AFTER_V7)) {
+
+ if (!(_features & GF_AFTER_V7)) {
camera._dest.x = camera._cur.x = a->x;
setCameraFollows(a);
}
- _fullRedraw=1;
+ _fullRedraw = 1;
if (x != -1) {
startWalkActor(a, x, y, -1);
}
}
-void Scumm::o6_getRandomNumber() {
+void Scumm::o6_getRandomNumber()
+{
int rnd;
- rnd = getRandomNumber(pop()+1);
+ rnd = getRandomNumber(pop() + 1);
_vars[VAR_V6_RANDOM_NR] = rnd;
push(rnd);
}
-void Scumm::o6_getRandomNumberRange() {
+void Scumm::o6_getRandomNumberRange()
+{
int max = pop();
int min = pop();
- int rnd = getRandomNumber(max-min+1) + min;
+ int rnd = getRandomNumber(max - min + 1) + min;
_vars[VAR_V6_RANDOM_NR] = rnd;
push(rnd);
}
-void Scumm::o6_getActorMoving() {
- push(derefActorSafe(pop(),"o6_getActorMoving")->moving);
+void Scumm::o6_getActorMoving()
+{
+ push(derefActorSafe(pop(), "o6_getActorMoving")->moving);
}
-void Scumm::o6_getScriptRunning() {
+void Scumm::o6_getScriptRunning()
+{
push(isScriptRunning(pop()));
}
-void Scumm::o6_isRoomScriptRunning() {
+void Scumm::o6_isRoomScriptRunning()
+{
push(isRoomScriptRunning(pop()));
}
-void Scumm::o6_getActorRoom() {
- push(derefActorSafe(pop(),"o6_getActorRoom")->room);
+void Scumm::o6_getActorRoom()
+{
+ push(derefActorSafe(pop(), "o6_getActorRoom")->room);
}
-void Scumm::o6_getObjectX() {
+void Scumm::o6_getObjectX()
+{
push(getObjX(pop()));
}
-void Scumm::o6_getObjectY() {
+void Scumm::o6_getObjectY()
+{
push(getObjY(pop()));
}
-void Scumm::o6_getObjectOldDir() {
+void Scumm::o6_getObjectOldDir()
+{
push(getObjOldDir(pop()));
}
-void Scumm::o6_getObjectNewDir() {
+void Scumm::o6_getObjectNewDir()
+{
push(getObjNewDir(pop()));
}
-void Scumm::o6_getActorWalkBox() {
- Actor *a = derefActorSafe(pop(),"o6_getActorWalkBox");
+void Scumm::o6_getActorWalkBox()
+{
+ Actor *a = derefActorSafe(pop(), "o6_getActorWalkBox");
push(a->ignoreBoxes ? 0 : a->walkbox);
}
-void Scumm::o6_getActorCostume() {
- push(derefActorSafe(pop(),"o6_getActorCostume")->costume);
+void Scumm::o6_getActorCostume()
+{
+ push(derefActorSafe(pop(), "o6_getActorCostume")->costume);
}
-void Scumm::o6_findInventory() {
+void Scumm::o6_findInventory()
+{
int idx = pop();
int owner = pop();
- push(findInventory(owner,idx));
+ push(findInventory(owner, idx));
}
-void Scumm::o6_getInventoryCount() {
+void Scumm::o6_getInventoryCount()
+{
push(getInventoryCount(pop()));
}
-void Scumm::o6_getVerbFromXY() {
+void Scumm::o6_getVerbFromXY()
+{
int y = pop();
int x = pop();
- int over = checkMouseOver(x,y);
+ int over = checkMouseOver(x, y);
if (over)
over = _verbs[over].verbid;
push(over);
}
-void Scumm::o6_beginOverride() {
+void Scumm::o6_beginOverride()
+{
beginOverride();
}
-void Scumm::o6_endOverride() {
+void Scumm::o6_endOverride()
+{
endOverride();
}
-void Scumm::o6_setObjectName() {
+void Scumm::o6_setObjectName()
+{
int obj = pop();
int i;
@@ -1515,7 +1625,7 @@ void Scumm::o6_setObjectName() {
if (!getOBCDFromObject(obj))
error("Can't set name of object %d", obj);
- for (i=1; i<50; i++) {
+ for (i = 1; i < 50; i++) {
if (_newNames[i] == obj) {
nukeResource(rtObjectName, i);
_newNames[i] = 0;
@@ -1523,7 +1633,7 @@ void Scumm::o6_setObjectName() {
}
}
- for (i=1; i<50; i++) {
+ for (i = 1; i < 50; i++) {
if (_newNames[i] == 0) {
loadPtrToResource(rtObjectName, i, NULL);
_newNames[i] = obj;
@@ -1535,157 +1645,166 @@ void Scumm::o6_setObjectName() {
error("New name of %d overflows name table (max = %d)", obj, 50);
}
-void Scumm::o6_isSoundRunning() {
+void Scumm::o6_isSoundRunning()
+{
int snd = pop();
if (snd)
snd = isSoundRunning(snd);
push(snd);
}
-void Scumm::o6_setBoxFlags() {
+void Scumm::o6_setBoxFlags()
+{
int16 table[65];
- int num,value;
+ int num, value;
value = pop();
- num = getStackList(table,sizeof(table)/sizeof(table[0]));
+ num = getStackList(table, sizeof(table) / sizeof(table[0]));
- while (--num>=0) {
+ while (--num >= 0) {
setBoxFlags(table[num], value);
}
}
-void Scumm::o6_createBoxMatrix() {
+void Scumm::o6_createBoxMatrix()
+{
createBoxMatrix();
}
-void Scumm::o6_resourceRoutines() {
+void Scumm::o6_resourceRoutines()
+{
int resid;
- switch(fetchScriptByte()) {
- case 100: /* load script */
+ switch (fetchScriptByte()) {
+ case 100: /* load script */
resid = pop();
- if(_features & GF_AFTER_V7)
+ if (_features & GF_AFTER_V7)
if (resid >= _numGlobalScripts)
break;
ensureResourceLoaded(rtScript, resid);
break;
- case 101: /* load sound */
+ case 101: /* load sound */
resid = pop();
ensureResourceLoaded(rtSound, resid);
break;
- case 102: /* load costume */
+ case 102: /* load costume */
resid = pop();
ensureResourceLoaded(rtCostume, resid);
break;
- case 103: /* load room */
+ case 103: /* load room */
resid = pop();
ensureResourceLoaded(rtRoom, resid);
break;
- case 104: /* nuke script */
+ case 104: /* nuke script */
resid = pop();
- if(_features & GF_AFTER_V7)
+ if (_features & GF_AFTER_V7)
if (resid >= _numGlobalScripts)
break;
setResourceCounter(rtScript, resid, 0x7F);
debug(5, "nuke script %d", resid);
break;
- case 105: /* nuke sound */
+ case 105: /* nuke sound */
resid = pop();
setResourceCounter(rtSound, resid, 0x7F);
break;
- case 106: /* nuke costume */
+ case 106: /* nuke costume */
resid = pop();
setResourceCounter(rtCostume, resid, 0x7F);
break;
- case 107: /* nuke room */
+ case 107: /* nuke room */
resid = pop();
setResourceCounter(rtRoom, resid, 0x7F);
break;
- case 108: /* lock script */
+ case 108: /* lock script */
resid = pop();
if (resid >= _numGlobalScripts)
break;
- lock(rtScript,resid);
+ lock(rtScript, resid);
break;
- case 109:/* lock sound */
+ case 109: /* lock sound */
resid = pop();
- lock(rtSound,resid);
+ lock(rtSound, resid);
break;
- case 110:/* lock costume */
+ case 110: /* lock costume */
resid = pop();
- lock(rtCostume,resid);
+ lock(rtCostume, resid);
break;
- case 111:/* lock room */
+ case 111: /* lock room */
resid = pop();
if (resid > 0x7F)
- resid = _resourceMapper[resid&0x7F];
- lock(rtRoom,resid);
+ resid = _resourceMapper[resid & 0x7F];
+ lock(rtRoom, resid);
break;
- case 112:/* unlock script */
+ case 112: /* unlock script */
resid = pop();
if (resid >= _numGlobalScripts)
break;
- unlock(rtScript,resid);
+ unlock(rtScript, resid);
break;
- case 113:/* unlock sound */
+ case 113: /* unlock sound */
resid = pop();
- unlock(rtSound,resid);
+ unlock(rtSound, resid);
break;
- case 114:/* unlock costume */
+ case 114: /* unlock costume */
resid = pop();
- unlock(rtCostume,resid);
+ unlock(rtCostume, resid);
break;
- case 115:/* unlock room */
+ case 115: /* unlock room */
resid = pop();
if (resid > 0x7F)
- resid = _resourceMapper[resid&0x7F];
- unlock(rtRoom,resid);
+ resid = _resourceMapper[resid & 0x7F];
+ unlock(rtRoom, resid);
break;
- case 116:/* clear heap */
+ case 116: /* clear heap */
/* this is actually a scumm message */
error("clear heap not working yet");
break;
- case 117:/* load charset */
+ case 117: /* load charset */
resid = pop();
loadCharset(resid);
break;
- case 118:/* nuke charset */
+ case 118: /* nuke charset */
warning("popping extra argument in nukeCharset");
resid = pop();
nukeCharset(resid);
break;
- case 119: {/* load fl object */
- int room,obj = popRoomAndObj(&room);
- loadFlObject(obj,room);
- break;
- }
+ case 119:{ /* load fl object */
+ int room, obj = popRoomAndObj(&room);
+ loadFlObject(obj, room);
+ break;
+ }
default:
error("o6_resourceRoutines: default case");
}
}
-void Scumm::o6_roomOps() {
- int a,b,c,d,e;
+void Scumm::o6_roomOps()
+{
+ int a, b, c, d, e;
- switch(fetchScriptByte()) {
- case 172: /* room scroll */
+ switch (fetchScriptByte()) {
+ case 172: /* room scroll */
b = pop();
a = pop();
- if (a < 160) a=160;
- if (b < 160) b=160;
- if (a > _scrWidth-160) a=_scrWidth-160;
- if (b > _scrWidth-160) b=_scrWidth-160;
+ if (a < 160)
+ a = 160;
+ if (b < 160)
+ b = 160;
+ if (a > _scrWidth - 160)
+ a = _scrWidth - 160;
+ if (b > _scrWidth - 160)
+ b = _scrWidth - 160;
_vars[VAR_CAMERA_MIN_X] = a;
_vars[VAR_CAMERA_MAX_X] = b;
break;
- case 174: /* set screen */
+ case 174: /* set screen */
b = pop();
a = pop();
- initScreens(0,a,320,b);
+ initScreens(0, a, 320, b);
break;
- case 175: /* set palette color */
+ case 175: /* set palette color */
d = pop();
c = pop();
b = pop();
@@ -1693,11 +1812,11 @@ void Scumm::o6_roomOps() {
setPalColor(d, a, b, c);
break;
- case 176: /* shake on */
+ case 176: /* shake on */
setShake(1);
break;
- case 177: /* shake off */
+ case 177: /* shake off */
setShake(0);
break;
@@ -1705,7 +1824,7 @@ void Scumm::o6_roomOps() {
c = pop();
b = pop();
a = pop();
- darkenPalette(b,c,a,a,a);
+ darkenPalette(b, c, a, a, a);
break;
case 180:
@@ -1719,7 +1838,7 @@ void Scumm::o6_roomOps() {
a = pop();
if (a) {
_switchRoomEffect = (byte)(a);
- _switchRoomEffect2 = (byte)(a>>8);
+ _switchRoomEffect2 = (byte)(a >> 8);
} else {
screenEffect(_newEffect);
}
@@ -1751,7 +1870,7 @@ void Scumm::o6_roomOps() {
error("load string not implemented");
break;
- case 186: /* palmanip? */
+ case 186: /* palmanip? */
d = pop();
c = pop();
b = pop();
@@ -1759,14 +1878,14 @@ void Scumm::o6_roomOps() {
unkRoomFunc4(a, b, c, d, 1);
break;
- case 187: /* color cycle delay */
+ case 187: /* color cycle delay */
b = pop();
a = pop();
checkRange(16, 1, a, "o6_roomOps: 187: color cycle out of range (%d)");
- _colorCycle[a-1].delay = (b!=0) ? 0x4000 / (b*0x4C) : 0;
+ _colorCycle[a - 1].delay = (b != 0) ? 0x4000 / (b * 0x4C) : 0;
break;
- case 213: /* set palette */
+ case 213: /* set palette */
setPalette(pop());
break;
@@ -1775,43 +1894,45 @@ void Scumm::o6_roomOps() {
}
}
-void Scumm::o6_actorSet() {
+void Scumm::o6_actorSet()
+{
Actor *a;
- int i,j,k;
+ int i, j, k;
int16 args[8];
byte b;
b = fetchScriptByte();
- if (b==197) {
+ if (b == 197) {
_curActor = pop();
return;
}
-
+
a = derefActorSafe(_curActor, "o6_actorSet");
- if (!a) return;
+ if (!a)
+ return;
- switch(b) {
- case 76: /* actor-costume */
+ switch (b) {
+ case 76: /* actor-costume */
setActorCostume(a, pop());
break;
- case 77: /* actor-speed */
+ case 77: /* actor-speed */
j = pop();
i = pop();
setActorWalkSpeed(a, i, j);
break;
- case 78: /* actor-sound */
- k = getStackList(args, sizeof(args)/sizeof(args[0]));
- for (i=0; i<k; i++)
+ case 78: /* actor-sound */
+ k = getStackList(args, sizeof(args) / sizeof(args[0]));
+ for (i = 0; i < k; i++)
a->sound[i] = args[i];
break;
- case 79: /* actor-walkframe */
+ case 79: /* actor-walkframe */
a->walkFrame = pop();
break;
- case 80: /* actor-talkframe */
+ case 80: /* actor-talkframe */
a->talkFrame2 = pop();
a->talkFrame1 = pop();
break;
- case 81: /* actor-standframe */
+ case 81: /* actor-standframe */
a->standFrame = pop();
break;
case 82:
@@ -1822,32 +1943,32 @@ void Scumm::o6_actorSet() {
case 83:
initActor(a, 0);
break;
- case 84: /* actor-elevation */
+ case 84: /* actor-elevation */
a->elevation = pop();
a->needRedraw = true;
a->needBgReset = true;
break;
- case 85: /* actor-defaultanims */
+ case 85: /* actor-defaultanims */
a->initFrame = 1;
a->walkFrame = 2;
a->standFrame = 3;
a->talkFrame1 = 4;
a->talkFrame2 = 5;
break;
- case 86: /* actor-palette */
+ case 86: /* actor-palette */
j = pop();
i = pop();
checkRange(31, 0, i, "Illegal palet slot %d");
a->palette[i] = j;
a->needRedraw = true;
break;
- case 87: /* actor-talkcolor */
+ case 87: /* actor-talkcolor */
a->talkColor = pop();
break;
- case 88: /* actor-name */
+ case 88: /* actor-name */
loadPtrToResource(rtActorName, a->number, NULL);
break;
- case 89: /* actor-initframe */
+ case 89: /* actor-initframe */
a->initFrame = pop();
break;
case 91:
@@ -1868,8 +1989,8 @@ void Scumm::o6_actorSet() {
case 95:
a->ignoreBoxes = 1;
a->forceClip = 0;
-FixRooms:;
- if (a->room==_currentRoom)
+ FixRooms:;
+ if (a->room == _currentRoom)
putActor(a, a->x, a->y, a->room);
break;
case 96:
@@ -1887,70 +2008,71 @@ FixRooms:;
a->new_1 = pop();
a->new_2 = pop();
break;
- case 198: /* set anim variable */
- i = pop(); /* value */
+ case 198: /* set anim variable */
+ i = pop(); /* value */
setAnimVar(a, pop(), i);
break;
case 215:
a->new_3 = 1;
- break;
+ break;
case 216:
a->new_3 = 0;
break;
case 217:
initActor(a, 2);
break;
- case 227: /* actor_layer */
+ case 227: /* actor_layer */
a->layer = pop();
break;
- case 228: /* walk script */
+ case 228: /* walk script */
a->walk_script = pop();
break;
- case 235: /* talk_script */
+ case 235: /* talk_script */
a->talk_script = pop();
break;
- case 229: /* stand */
+ case 229: /* stand */
stopActorMoving(a);
startAnimActor(a, a->standFrame);
break;
- case 230: /* set direction */
- a->moving&=~4;
+ case 230: /* set direction */
+ a->moving &= ~4;
fixActorDirection(a, pop());
break;
- case 231: /* turn to direction */
+ case 231: /* turn to direction */
turnToDirection(a, pop());
break;
- case 233: /* freeze actor */
- a->moving|=0x80;
+ case 233: /* freeze actor */
+ a->moving |= 0x80;
break;
- case 234: /* unfreeze actor */
- a->moving&=~0x7f;
+ case 234: /* unfreeze actor */
+ a->moving &= ~0x7f;
break;
default:
error("o6_actorset: default case %d", b);
}
}
-void Scumm::o6_verbOps() {
- int slot,a,b;
+void Scumm::o6_verbOps()
+{
+ int slot, a, b;
VerbSlot *vs;
byte *ptr, op;
-
+
op = fetchScriptByte();
- if(op==196) {
+ if (op == 196) {
_curVerb = pop();
_curVerbSlot = getVerbSlot(_curVerb, 0);
- checkRange(_maxVerbs-1,0,_curVerbSlot,"Illegal new verb slot %d");
+ checkRange(_maxVerbs - 1, 0, _curVerbSlot, "Illegal new verb slot %d");
return;
}
vs = &_verbs[_curVerbSlot];
slot = _curVerbSlot;
- switch(op) {
- case 124: /* load img */
+ switch (op) {
+ case 124: /* load img */
a = pop();
if (_curVerbSlot) {
- setVerbObject(_roomResource,a,slot);
- vs->type=1;
+ setVerbObject(_roomResource, a, slot);
+ vs->type = 1;
}
break;
case 125:
@@ -1979,12 +2101,12 @@ void Scumm::o6_verbOps() {
break;
case 132:
slot = getVerbSlot(_curVerb, 0);
- if (slot==0) {
- for (slot=1; slot<_maxVerbs; slot++) {
- if(_verbs[slot].verbid==0)
+ if (slot == 0) {
+ for (slot = 1; slot < _maxVerbs; slot++) {
+ if (_verbs[slot].verbid == 0)
break;
}
- if (slot==_maxVerbs)
+ if (slot == _maxVerbs)
error("Too many verbs");
_curVerbSlot = slot;
}
@@ -2015,8 +2137,8 @@ void Scumm::o6_verbOps() {
break;
case 137:
a = pop();
- if (a==0) {
- ptr = (byte*)"";
+ if (a == 0) {
+ ptr = (byte *)"";
} else {
ptr = getStringAddress(a);
}
@@ -2045,48 +2167,54 @@ void Scumm::o6_verbOps() {
}
}
-void Scumm::o6_getActorFromXY() {
+void Scumm::o6_getActorFromXY()
+{
int y = pop();
int x = pop();
- push(getActorFromPos(x,y));
+ push(getActorFromPos(x, y));
}
-void Scumm::o6_findObject() {
+void Scumm::o6_findObject()
+{
int y = pop();
int x = pop();
- int r = findObject(x,y);
+ int r = findObject(x, y);
push(r);
}
-void Scumm::o6_pseudoRoom() {
+void Scumm::o6_pseudoRoom()
+{
int16 list[100];
- int num,a,value;
+ int num, a, value;
- num = getStackList(list,sizeof(list)/sizeof(list[0]));
+ num = getStackList(list, sizeof(list) / sizeof(list[0]));
value = pop();
- while (--num>=0) {
+ while (--num >= 0) {
a = list[num];
if (a > 0x7F)
- _resourceMapper[a&0x7F] = value;
+ _resourceMapper[a & 0x7F] = value;
}
}
-void Scumm::o6_getActorElevation() {
- push(derefActorSafe(pop(),"o6_getActorElevation")->elevation);
+void Scumm::o6_getActorElevation()
+{
+ push(derefActorSafe(pop(), "o6_getActorElevation")->elevation);
}
-void Scumm::o6_getVerbEntrypoint() {
+void Scumm::o6_getVerbEntrypoint()
+{
int e = pop();
int v = pop();
- push(getVerbEntrypoint(v,e));
+ push(getVerbEntrypoint(v, e));
}
-void Scumm::o6_arrayOps() {
- int a,b,c,d,num;
+void Scumm::o6_arrayOps()
+{
+ int a, b, c, d, num;
int16 list[128];
- switch(fetchScriptByte()) {
+ switch (fetchScriptByte()) {
case 205:
a = fetchScriptWord();
pop();
@@ -2097,23 +2225,23 @@ void Scumm::o6_arrayOps() {
b = pop();
c = pop();
d = readVar(a);
- if (d==0) {
- defineArray(a, 5, 0, b+c);
+ if (d == 0) {
+ defineArray(a, 5, 0, b + c);
}
while (c--) {
- writeArray(a, 0, b+c, pop());
+ writeArray(a, 0, b + c, pop());
}
break;
case 212:
a = fetchScriptWord();
b = pop();
- num = getStackList(list,sizeof(list)/sizeof(list[0]));
+ num = getStackList(list, sizeof(list) / sizeof(list[0]));
d = readVar(a);
- if (d==0)
+ if (d == 0)
error("Must DIM a two dimensional array before assigning");
c = pop();
- while (--num>=0) {
- writeArray(a, c, b+num, list[num]);
+ while (--num >= 0) {
+ writeArray(a, c, b + num, list[num]);
}
break;
default:
@@ -2121,19 +2249,20 @@ void Scumm::o6_arrayOps() {
}
}
-void Scumm::o6_saveRestoreVerbs() {
- int a,b,c;
- int slot,slot2;
+void Scumm::o6_saveRestoreVerbs()
+{
+ int a, b, c;
+ int slot, slot2;
c = pop();
b = pop();
a = pop();
- switch(fetchScriptByte()) {
+ switch (fetchScriptByte()) {
case 141:
- while (a<=b) {
- slot = getVerbSlot(a,0);
- if (slot && _verbs[slot].saveid==0) {
+ while (a <= b) {
+ slot = getVerbSlot(a, 0);
+ if (slot && _verbs[slot].saveid == 0) {
_verbs[slot].saveid = c;
drawVerb(slot, 0);
verbMouseOver(0);
@@ -2142,13 +2271,13 @@ void Scumm::o6_saveRestoreVerbs() {
}
break;
case 142:
- while (a<=b) {
+ while (a <= b) {
slot = getVerbSlot(a, c);
if (slot) {
- slot2 = getVerbSlot(a,0);
+ slot2 = getVerbSlot(a, 0);
if (slot2)
killVerb(slot2);
- slot = getVerbSlot(a,c);
+ slot = getVerbSlot(a, c);
_verbs[slot].saveid = 0;
drawVerb(slot, 0);
verbMouseOver(0);
@@ -2157,8 +2286,8 @@ void Scumm::o6_saveRestoreVerbs() {
}
break;
case 143:
- while (a<=b) {
- slot = getVerbSlot(a,c);
+ while (a <= b) {
+ slot = getVerbSlot(a, c);
if (slot)
killVerb(slot);
a++;
@@ -2169,8 +2298,9 @@ void Scumm::o6_saveRestoreVerbs() {
}
}
-void Scumm::o6_drawBox() {
- int x,y,x2,y2,color;
+void Scumm::o6_drawBox()
+{
+ int x, y, x2, y2, color;
color = pop();
y2 = pop();
x2 = pop();
@@ -2179,63 +2309,64 @@ void Scumm::o6_drawBox() {
drawBox(x, y, x2, y2, color);
}
-void Scumm::o6_getActorWidth() {
- push(derefActorSafe(pop(),"o6_getActorWidth")->width);
+void Scumm::o6_getActorWidth()
+{
+ push(derefActorSafe(pop(), "o6_getActorWidth")->width);
}
-void Scumm::o6_wait() {
- switch(fetchScriptByte()) {
- case 168: {
- int offs = (int16)fetchScriptWord();
- if (derefActorSafe(pop(), "o6_wait")->moving) {
- _scriptPointer += offs;
- o6_breakHere();
+void Scumm::o6_wait()
+{
+ switch (fetchScriptByte()) {
+ case 168:{
+ int offs = (int16) fetchScriptWord();
+ if (derefActorSafe(pop(), "o6_wait")->moving) {
+ _scriptPointer += offs;
+ o6_breakHere();
+ }
+ return;
}
- return;
- }
case 169:
if (_vars[VAR_HAVE_MSG])
break;
return;
case 170:
- if(!(_features & GF_AFTER_V7)) {
- if (camera._cur.x>>3 != camera._dest.x>>3)
+ if (!(_features & GF_AFTER_V7)) {
+ if (camera._cur.x >> 3 != camera._dest.x >> 3)
break;
} else {
- if (camera._dest.x != camera._cur.x ||
- camera._dest.y != camera._cur.y)
- break;
+ if (camera._dest.x != camera._cur.x || camera._dest.y != camera._cur.y)
+ break;
}
return;
case 171:
if (_sentenceNum) {
- if (sentence[_sentenceNum-1].unk &&
- !isScriptInUse(_vars[VAR_SENTENCE_SCRIPT]) )
+ if (sentence[_sentenceNum - 1].unk &&
+ !isScriptInUse(_vars[VAR_SENTENCE_SCRIPT]))
return;
break;
}
if (!isScriptInUse(_vars[VAR_SENTENCE_SCRIPT]))
return;
break;
- case 226: { /* wait until actor drawn */
- Actor *a = derefActorSafe(pop(), "o6_wait:226");
- int offs = (int16)fetchScriptWord();
- if (a->room==_currentRoom && a->needRedraw) {
- _scriptPointer += offs;
- o6_breakHere();
+ case 226:{ /* wait until actor drawn */
+ Actor *a = derefActorSafe(pop(), "o6_wait:226");
+ int offs = (int16) fetchScriptWord();
+ if (a->room == _currentRoom && a->needRedraw) {
+ _scriptPointer += offs;
+ o6_breakHere();
+ }
+ return;
}
- return;
- }
- case 232: { /* wait until actor stops turning */
- Actor *a = derefActorSafe(pop(), "o6_wait:226");
- int offs = (int16)fetchScriptWord();
- if (a->room==_currentRoom && a->moving&4) {
- _scriptPointer += offs;
- o6_breakHere();
+ case 232:{ /* wait until actor stops turning */
+ Actor *a = derefActorSafe(pop(), "o6_wait:226");
+ int offs = (int16) fetchScriptWord();
+ if (a->room == _currentRoom && a->moving & 4) {
+ _scriptPointer += offs;
+ o6_breakHere();
+ }
+ return;
}
- return;
- }
default:
error("o6_wait: default case");
}
@@ -2244,34 +2375,39 @@ void Scumm::o6_wait() {
o6_breakHere();
}
-void Scumm::o6_getActorScaleX() {
- push(derefActorSafe(pop(),"o6_getActorScale")->scalex);
+void Scumm::o6_getActorScaleX()
+{
+ push(derefActorSafe(pop(), "o6_getActorScale")->scalex);
}
-void Scumm::o6_getActorAnimCounter1() {
- push(derefActorSafe(pop(),"o6_getActorAnimCounter")->cost.animCounter1);
+void Scumm::o6_getActorAnimCounter1()
+{
+ push(derefActorSafe(pop(), "o6_getActorAnimCounter")->cost.animCounter1);
}
-void Scumm::o6_getAnimateVariable() {
+void Scumm::o6_getAnimateVariable()
+{
int var = pop();
- push(getAnimVar(derefActorSafe(pop(),"o6_getAnimateVariable"), var));
+ push(getAnimVar(derefActorSafe(pop(), "o6_getAnimateVariable"), var));
}
-void Scumm::o6_soundKludge() {
+void Scumm::o6_soundKludge()
+{
int16 list[16];
- getStackList(list,sizeof(list)/sizeof(list[0]));
+ getStackList(list, sizeof(list) / sizeof(list[0]));
soundKludge(list);
}
-void Scumm::o6_isAnyOf() {
+void Scumm::o6_isAnyOf()
+{
int16 list[100];
int num;
int16 val;
- num = getStackList(list,sizeof(list)/sizeof(list[0]));
+ num = getStackList(list, sizeof(list) / sizeof(list[0]));
val = pop();
- while (--num>=0) {
+ while (--num >= 0) {
if (list[num] == val) {
push(1);
return;
@@ -2281,8 +2417,9 @@ void Scumm::o6_isAnyOf() {
return;
}
-void Scumm::o6_quitPauseRestart() {
- switch(fetchScriptByte()) {
+void Scumm::o6_quitPauseRestart()
+{
+ switch (fetchScriptByte()) {
case 158:
pauseGame(false);
break;
@@ -2294,92 +2431,105 @@ void Scumm::o6_quitPauseRestart() {
}
}
-void Scumm::o6_isActorInBox() {
+void Scumm::o6_isActorInBox()
+{
int box = pop();
Actor *a = derefActorSafe(pop(), "o6_isActorInBox");
push(checkXYInBoxBounds(box, a->x, a->y));
}
-void Scumm::o6_delay() {
+void Scumm::o6_delay()
+{
uint32 delay = (uint16)pop();
vm.slot[_currentScript].delay = delay;
vm.slot[_currentScript].status = 1;
o6_breakHere();
}
-void Scumm::o6_delayLonger() {
+void Scumm::o6_delayLonger()
+{
uint32 delay = (uint16)pop() * 60;
vm.slot[_currentScript].delay = delay;
vm.slot[_currentScript].status = 1;
o6_breakHere();
}
-void Scumm::o6_delayVeryLong() {
+void Scumm::o6_delayVeryLong()
+{
uint32 delay = (uint16)pop() * 3600;
vm.slot[_currentScript].delay = delay;
vm.slot[_currentScript].status = 1;
o6_breakHere();
}
-void Scumm::o6_stopSentence() {
+void Scumm::o6_stopSentence()
+{
_sentenceNum = 0;
stopScriptNr(_vars[VAR_SENTENCE_SCRIPT]);
clearClickedStatus();
}
-void Scumm::o6_print_0() {
+void Scumm::o6_print_0()
+{
_actorToPrintStrFor = 0xFF;
- decodeParseString2(0,0);
+ decodeParseString2(0, 0);
}
-void Scumm::o6_print_1() {
- decodeParseString2(1,0);
+void Scumm::o6_print_1()
+{
+ decodeParseString2(1, 0);
}
-void Scumm::o6_print_2() {
- decodeParseString2(2,0);
+void Scumm::o6_print_2()
+{
+ decodeParseString2(2, 0);
}
-void Scumm::o6_print_3() {
- decodeParseString2(3,0);
+void Scumm::o6_print_3()
+{
+ decodeParseString2(3, 0);
}
-void Scumm::o6_printActor() {
- decodeParseString2(0,1);
+void Scumm::o6_printActor()
+{
+ decodeParseString2(0, 1);
}
-void Scumm::o6_printEgo() {
+void Scumm::o6_printEgo()
+{
push(_vars[VAR_EGO]);
- decodeParseString2(0,1);
+ decodeParseString2(0, 1);
}
-void Scumm::o6_talkActor() {
+void Scumm::o6_talkActor()
+{
_actorToPrintStrFor = pop();
_messagePtr = _scriptPointer;
-
+
if (_scriptPointer[0] == '/') {
char *pointer = strtok((char *)_scriptPointer, "/");
int bunsize = strlen(pointer) + 2;
playBundleSound(pointer);
_scriptPointer += bunsize;
- _messagePtr = _scriptPointer;
+ _messagePtr = _scriptPointer;
}
-
+
setStringVars(0);
actorTalk();
_scriptPointer = _messagePtr;
}
-void Scumm::o6_talkEgo() {
+void Scumm::o6_talkEgo()
+{
_actorToPrintStrFor = (unsigned char)_vars[VAR_EGO];
_messagePtr = _scriptPointer;
-
+
if (_scriptPointer[0] == '/') {
char *pointer = strtok((char *)_scriptPointer, "/");
int bunsize = strlen(pointer) + 2;
playBundleSound(pointer);
_scriptPointer += bunsize;
- _messagePtr = _scriptPointer;
+ _messagePtr = _scriptPointer;
}
setStringVars(0);
@@ -2387,10 +2537,11 @@ void Scumm::o6_talkEgo() {
_scriptPointer = _messagePtr;
}
-void Scumm::o6_dim() {
+void Scumm::o6_dim()
+{
int data;
- switch(fetchScriptByte()) {
+ switch (fetchScriptByte()) {
case 199:
data = 5;
break;
@@ -2416,26 +2567,29 @@ void Scumm::o6_dim() {
defineArray(fetchScriptWord(), data, 0, pop());
}
-void Scumm::o6_runVerbCodeQuick() {
+void Scumm::o6_runVerbCodeQuick()
+{
int16 args[16];
- int script,entryp;
- getStackList(args,sizeof(args)/sizeof(args[0]));
+ int script, entryp;
+ getStackList(args, sizeof(args) / sizeof(args[0]));
entryp = pop();
script = pop();
runVerbCode(script, entryp, 0, 1, args);
}
-void Scumm::o6_runScriptQuick() {
+void Scumm::o6_runScriptQuick()
+{
int16 args[16];
int script;
- getStackList(args,sizeof(args)/sizeof(args[0]));
+ getStackList(args, sizeof(args) / sizeof(args[0]));
script = pop();
runScript(script, 0, 1, args);
}
-void Scumm::o6_dim2() {
- int a,b,data;
- switch(fetchScriptByte()) {
+void Scumm::o6_dim2()
+{
+ int a, b, data;
+ switch (fetchScriptByte()) {
case 199:
data = 5;
break;
@@ -2460,28 +2614,32 @@ void Scumm::o6_dim2() {
defineArray(fetchScriptWord(), data, a, b);
}
-void Scumm::o6_abs() {
+void Scumm::o6_abs()
+{
push(abs(pop()));
}
-void Scumm::o6_distObjectObject() {
- int a,b;
+void Scumm::o6_distObjectObject()
+{
+ int a, b;
b = pop();
a = pop();
push(getDistanceBetween(true, a, 0, true, b, 0));
}
-void Scumm::o6_distObjectPt() {
- int a,b,c;
+void Scumm::o6_distObjectPt()
+{
+ int a, b, c;
c = pop();
b = pop();
a = pop();
push(getDistanceBetween(true, a, 0, false, b, c));
}
-void Scumm::o6_distPtPt() {
- int a,b,c,d;
+void Scumm::o6_distPtPt()
+{
+ int a, b, c, d;
d = pop();
c = pop();
b = pop();
@@ -2489,15 +2647,17 @@ void Scumm::o6_distPtPt() {
push(getDistanceBetween(false, a, b, false, c, d));
}
-void Scumm::o6_dummy_stacklist() {
+void Scumm::o6_dummy_stacklist()
+{
error("opcode o6_dummy_stacklist invalid");
}
-void Scumm::o6_drawBlastObject() {
+void Scumm::o6_drawBlastObject()
+{
int16 args[16];
- int a,b,c,d,e;
+ int a, b, c, d, e;
- getStackList(args,sizeof(args)/sizeof(args[0]));
+ getStackList(args, sizeof(args) / sizeof(args[0]));
e = pop();
d = pop();
c = pop();
@@ -2506,40 +2666,44 @@ void Scumm::o6_drawBlastObject() {
enqueueObject(a, b, c, d, e, 0xFF, 0xFF, 1, 0);
}
-void Scumm::o6_miscOps() {
+void Scumm::o6_miscOps()
+{
int16 args[30];
int i;
Actor *a;
- getStackList(args,sizeof(args)/sizeof(args[0]));
+ getStackList(args, sizeof(args) / sizeof(args[0]));
- if(_features & GF_AFTER_V7) {
- switch(args[0]) {
+ if (_features & GF_AFTER_V7) {
+ switch (args[0]) {
case 4:
grabCursor(args[1], args[2], args[3], args[4]);
break;
case 6:
SmushPlayer localSp;
- localSp.sm=this;
- localSp.startVideo(args[1], getStringAddress(_vars[0xf6/2]));
+ localSp.sm = this;
+ localSp.startVideo(args[1], getStringAddress(_vars[0xf6 / 2]));
break;
case 7:
warning("o6_miscOps: stub7()");
break;
case 10:
- warning("o6_miscOps: stub10(%d,%d,%d,%d)",args[1],args[2],args[3],args[4]);
+ warning("o6_miscOps: stub10(%d,%d,%d,%d)", args[1], args[2], args[3],
+ args[4]);
break;
case 11:
warning("o6_miscOps: stub11(%d)", args[1]);
break;
case 12:
- setCursorImg(args[1], (uint) -1, args[2]);
+ setCursorImg(args[1], (uint) - 1, args[2]);
break;
case 13:
- warning("o6_miscOps: stub13(%d,%d,%d,%d)",args[1],args[2],args[3],args[4]);
+ warning("o6_miscOps: stub13(%d,%d,%d,%d)", args[1], args[2], args[3],
+ args[4]);
break;
case 14:
- remapActor(derefActorSafe(args[1], "o6_miscOps:14"), args[2],args[3],args[4],args[5]);
+ remapActor(derefActorSafe(args[1], "o6_miscOps:14"), args[2], args[3],
+ args[4], args[5]);
break;
case 15:
_insaneFlag = args[1];
@@ -2551,7 +2715,8 @@ void Scumm::o6_miscOps() {
//warning("o6_miscOps: drawString(%s,charset=%d,color=%d,x=%d,y=%d)",buf, args[1],args[2],args[3],args[4]);
break;
case 17:
- warning("o6_miscOps: stub17(%d,%d,%d,%d)",args[1],args[2],args[3],args[4]);
+ warning("o6_miscOps: stub17(%d,%d,%d,%d)", args[1], args[2], args[3],
+ args[4]);
break;
case 18:
warning("o6_miscOps: stub18(%d,%d)", args[1], args[2]);
@@ -2563,10 +2728,11 @@ void Scumm::o6_miscOps() {
a->needRedraw = true;
break;
case 108:
- setupShadowPalette(args[1],args[2],args[3],args[4],args[5],args[6]);
+ setupShadowPalette(args[1], args[2], args[3], args[4], args[5],
+ args[6]);
break;
case 109:
- setupShadowPalette(0, args[1],args[2],args[3],args[4],args[5]);
+ setupShadowPalette(0, args[1], args[2], args[3], args[4], args[5]);
break;
case 114:
warning("o6_miscOps: stub114()");
@@ -2575,10 +2741,12 @@ void Scumm::o6_miscOps() {
freezeScripts(2);
break;
case 118:
- enqueueObject(args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8], 3);
+ enqueueObject(args[1], args[2], args[3], args[4], args[5], args[6],
+ args[7], args[8], 3);
break;
case 119:
- enqueueObject(args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8], 0);
+ enqueueObject(args[1], args[2], args[3], args[4], args[5], args[6],
+ args[7], args[8], 0);
break;
case 120:
warning("o6_miscOps: stub120(%d,%d)", args[1], args[2]);
@@ -2588,7 +2756,7 @@ void Scumm::o6_miscOps() {
break;
}
} else {
- switch(args[0]) {
+ switch (args[0]) {
case 3:
warning("o6_miscOps: nothing in 3");
break;
@@ -2601,7 +2769,7 @@ void Scumm::o6_miscOps() {
case 6:
_fullRedraw = 1;
redrawBGAreas();
- for (i=0; i<NUM_ACTORS; i++)
+ for (i = 0; i < NUM_ACTORS; i++)
derefActor(i)->needRedraw = true;
processActors();
screenEffect(args[1]);
@@ -2613,24 +2781,25 @@ void Scumm::o6_miscOps() {
unkMiscOp9();
break;
- case 104: /* samnmax */
+ case 104: /* samnmax */
nukeFlObjects(args[2], args[3]);
break;
-
+
case 106:
error("stub o6_miscOps_106()");
break;
-
- case 107: /* set actor scale */
+
+ case 107: /* set actor scale */
a = derefActorSafe(args[1], "o6_miscops: 107");
a->scalex = (unsigned char)args[2];
a->needBgReset = true;
a->needRedraw = true;
break;
- case 108: /* shadow palette? */
+ case 108: /* shadow palette? */
case 109:
- warning("stub o6_miscOps_108(%d,%d,%d,%d,%d,%d,%d)",args[1], args[2], args[3], args[4], args[5],0,256);
+ warning("stub o6_miscOps_108(%d,%d,%d,%d,%d,%d,%d)", args[1], args[2],
+ args[3], args[4], args[5], 0, 256);
break;
case 110:
@@ -2642,51 +2811,49 @@ void Scumm::o6_miscOps() {
a->shadow_mode = args[2] + args[3];
break;
- case 112: /* palette shift? */
+ case 112: /* palette shift? */
warning("stub o6_miscOps_112(%d,%d,%d,%d,%d,%d,%d)",
- args[1], args[2], args[3], args[4], args[5],
- args[6], args[7]);
+ args[1], args[2], args[3], args[4], args[5], args[6], args[7]);
break;
-
- case 114: /* palette? */
+
+ case 114: /* palette? */
warning("stub o6_miscOps_114()");
break;
-
+
case 117:
warning("stub o6_miscOps_117()");
break;
case 118:
error("stub o6_miscOps_118(%d,%d,%d,%d,%d,%d,%d)",
- args[1], args[2], args[3], args[4], args[5],
- args[6], args[7]);
+ args[1], args[2], args[3], args[4], args[5], args[6], args[7]);
break;
-
+
case 119:
enqueueObject(args[1], args[2], args[3], args[4], args[5],
- args[6], args[7], args[8], 0);
+ args[6], args[7], args[8], 0);
break;
case 120:
- swapPalColors(args[1],args[2]);
+ swapPalColors(args[1], args[2]);
break;
case 121:
error("stub o6_miscOps_121(%d)", args[1]);
- break;
+ break;
case 122:
- warning("stub o6_miscOps_122(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d)",
- args[1],args[2],args[3],args[4],
- args[5],args[6],args[7],args[8],
- args[9],args[10],args[11],args[12]);
+ warning("stub o6_miscOps_122(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d)",
+ args[1], args[2], args[3], args[4],
+ args[5], args[6], args[7], args[8],
+ args[9], args[10], args[11], args[12]);
break;
case 123:
- swapPalColors(args[1],args[2]);
+ swapPalColors(args[1], args[2]);
break;
- case 124: /* samnmax */
+ case 124: /* samnmax */
warning("o6_miscOps: _saveSound=%d", args[1]);
_saveSound = args[1];
break;
@@ -2697,14 +2864,15 @@ void Scumm::o6_miscOps() {
}
}
-void Scumm::o6_kernelFunction() {
+void Scumm::o6_kernelFunction()
+{
int16 args[30];
int i;
Actor *a;
- getStackList(args,sizeof(args)/sizeof(args[0]));
-
- switch(args[0]) {
+ getStackList(args, sizeof(args) / sizeof(args[0]));
+
+ switch (args[0]) {
case 113:
// Do something to [1] x [2] (x/y)
warning("o6_kernelFunction: stub113(%d,%d)", args[1], args[2]);
@@ -2718,7 +2886,7 @@ void Scumm::o6_kernelFunction() {
push(checkXYInBoxBounds(args[3], args[1], args[2]));
break;
case 206:
- push(remapPaletteColor(args[1],args[2],args[3],(uint)-1));
+ push(remapPaletteColor(args[1], args[2], args[3], (uint) - 1));
break;
case 207:
i = getObjectIndex(pop());
@@ -2745,14 +2913,11 @@ void Scumm::o6_kernelFunction() {
push(a->frame);
break;
case 215:
- if(_extraBoxFlags[args[1]]&0x00FF==0x00C0)
- {
+ if (_extraBoxFlags[args[1]] & 0x00FF == 0x00C0) {
push(_extraBoxFlags[args[1]]);
- }
- else
- {
- byte* temp = (byte*)getBoxBaseAddr(args[1]);
- push((byte)(*(temp+17)));
+ } else {
+ byte *temp = (byte *)getBoxBaseAddr(args[1]);
+ push((byte)(*(temp + 17)));
}
break;
default:
@@ -2760,7 +2925,8 @@ void Scumm::o6_kernelFunction() {
}
}
-void Scumm::o6_breakMaybe() {
+void Scumm::o6_breakMaybe()
+{
ScriptSlot *ss = &vm.slot[_currentScript];
if (ss->newfield == 0) {
ss->newfield = pop();
@@ -2773,37 +2939,40 @@ void Scumm::o6_breakMaybe() {
}
}
-void Scumm::o6_pickOneOf() {
+void Scumm::o6_pickOneOf()
+{
int16 args[100];
- int i,num;
+ int i, num;
- num = getStackList(args,sizeof(args)/sizeof(args[0]));
+ num = getStackList(args, sizeof(args) / sizeof(args[0]));
i = pop();
- if (i<0 || i>=num)
+ if (i < 0 || i >= num)
error("o6_pickOneOf: out of range");
push(args[i]);
}
-void Scumm::o6_pickOneOfDefault() {
+void Scumm::o6_pickOneOfDefault()
+{
int16 args[100];
- int i,num,def;
+ int i, num, def;
def = pop();
- num = getStackList(args,sizeof(args)/sizeof(args[0]));
+ num = getStackList(args, sizeof(args) / sizeof(args[0]));
i = pop();
- if (i<0 || i>=num)
+ if (i < 0 || i >= num)
i = def;
else
i = args[i];
push(i);
}
-void Scumm::decodeParseString2(int m, int n) {
+void Scumm::decodeParseString2(int m, int n)
+{
byte b;
b = fetchScriptByte();
-
- switch(b) {
+
+ switch (b) {
case 65:
string[m].ypos = pop();
string[m].xpos = pop();
@@ -2833,26 +3002,34 @@ void Scumm::decodeParseString2(int m, int n) {
case 74:
string[m].no_talk_anim = true;
break;
- case 75: {
- _messagePtr = _scriptPointer;
-
- if (_scriptPointer[0] == '/') {
- char *pointer = strtok((char *)_scriptPointer, "/");
- int bunsize = strlen(pointer) + 2;
- playBundleSound(pointer);
- _scriptPointer += bunsize;
- _messagePtr = _scriptPointer;
- }
-
- switch(m) {
- case 0: actorTalk(); break;
- case 1: drawString(1); break;
- case 2: unkMessage1(); break;
- case 3: unkMessage2(); break;
+ case 75:{
+ _messagePtr = _scriptPointer;
+
+ if (_scriptPointer[0] == '/') {
+ char *pointer = strtok((char *)_scriptPointer, "/");
+ int bunsize = strlen(pointer) + 2;
+ playBundleSound(pointer);
+ _scriptPointer += bunsize;
+ _messagePtr = _scriptPointer;
+ }
+
+ switch (m) {
+ case 0:
+ actorTalk();
+ break;
+ case 1:
+ drawString(1);
+ break;
+ case 2:
+ unkMessage1();
+ break;
+ case 3:
+ unkMessage2();
+ break;
+ }
+ _scriptPointer = _messagePtr;
+ return;
}
- _scriptPointer = _messagePtr;
- return;
- }
case 0xFE:
setStringVars(m);
if (n)
@@ -2877,7 +3054,7 @@ void Scumm::o6_getActorPriority()
{
Actor *a;
- a=derefActorSafe(pop(),"getActorPriority");
+ a = derefActorSafe(pop(), "getActorPriority");
push(a->layer);
}
diff --git a/scummvm.cpp b/scummvm.cpp
index 1ffe921e99..2c3cf3438a 100644
--- a/scummvm.cpp
+++ b/scummvm.cpp
@@ -26,43 +26,47 @@
#include "string.h"
extern void launcherLoop();
-void Scumm::initRandSeeds() {
+void Scumm::initRandSeeds()
+{
_randSeed1 = 0xA943DE35;
_randSeed2 = 0x37A9ED27;
}
-uint Scumm::getRandomNumber(uint max) {
+uint Scumm::getRandomNumber(uint max)
+{
/* TODO: my own random number generator */
_randSeed1 = 0xDEADBEEF * (_randSeed1 + 1);
- _randSeed1 = (_randSeed1>>13) | (_randSeed1<<19);
- return _randSeed1%max;
+ _randSeed1 = (_randSeed1 >> 13) | (_randSeed1 << 19);
+ return _randSeed1 % max;
}
-uint Scumm::getRandomNumberRng(uint min, uint max) {
- return getRandomNumber(max-min+1)+min;
+uint Scumm::getRandomNumberRng(uint min, uint max)
+{
+ return getRandomNumber(max - min + 1) + min;
}
-void Scumm::scummInit() {
+void Scumm::scummInit()
+{
int i;
Actor *a;
debug(9, "scummInit");
- if(_features & GF_SMALL_HEADER)
- _resourceHeaderSize = 6;
- else
- _resourceHeaderSize = 8;
+ if (_features & GF_SMALL_HEADER)
+ _resourceHeaderSize = 6;
+ else
+ _resourceHeaderSize = 8;
- if(!(_features & GF_SMALL_NAMES))
- loadCharset(1);
+ if (!(_features & GF_SMALL_NAMES))
+ loadCharset(1);
initScreens(0, 16, 320, 144);
setShake(0);
setupCursor();
- for (i=1,a=getFirstActor(); ++a,i<NUM_ACTORS; i++) {
+ for (i = 1, a = getFirstActor(); ++a, i < NUM_ACTORS; i++) {
a->number = i;
initActor(a, 1);
}
@@ -76,7 +80,7 @@ void Scumm::scummInit() {
memset(vm.cutScenePtr, 0, sizeof(vm.cutScenePtr));
memset(vm.cutSceneData, 0, sizeof(vm.cutSceneData));
- for (i=0; i<_maxVerbs; i++) {
+ for (i = 0; i < _maxVerbs; i++) {
_verbs[i].verbid = 0;
_verbs[i].right = 319;
_verbs[i].oldleft = -1;
@@ -86,20 +90,20 @@ void Scumm::scummInit() {
_verbs[i].charset_nr = 1;
_verbs[i].curmode = 0;
_verbs[i].saveid = 0;
- _verbs[i].center=0;
+ _verbs[i].center = 0;
_verbs[i].key = 0;
}
- if(!(_features & GF_AFTER_V7)) {
+ if (!(_features & GF_AFTER_V7)) {
camera._leftTrigger = 10;
camera._rightTrigger = 30;
camera._mode = 0;
- }
+ }
camera._follows = 0;
virtscr[0].xstart = 0;
- if(!(_features & GF_AFTER_V7)) {
+ if (!(_features & GF_AFTER_V7)) {
_vars[VAR_V5_DRAWFLAGS] = 11;
_vars[VAR_59] = 3;
}
@@ -130,15 +134,14 @@ void Scumm::scummInit() {
_cursorState = 0;
_userPut = 0;
-
+
_newEffect = 129;
_fullRedraw = true;
clearDrawObjectQueue();
- for (i=0; i<6; i++) {
- if(_features & GF_OLD256)
- {
+ for (i = 0; i < 6; i++) {
+ if (_features & GF_OLD256) {
string[i].t_xpos = 0;
string[i].t_ypos = 0;
} else {
@@ -157,15 +160,16 @@ void Scumm::scummInit() {
initScummVars();
- if (!(_features&GF_AFTER_V6))
+ if (!(_features & GF_AFTER_V6))
_vars[VAR_V5_TALK_STRING_Y] = -0x50;
- getGraphicsPerformance();
+ getGraphicsPerformance();
}
-void Scumm::initScummVars() {
- if(!(_features & GF_AFTER_V7)) {
+void Scumm::initScummVars()
+{
+ if (!(_features & GF_AFTER_V7)) {
_vars[VAR_CURRENTDRIVE] = _currentDrive;
_vars[VAR_FIXEDDISK] = checkFixedDisk();
_vars[VAR_SOUNDCARD] = _soundCardType;
@@ -175,19 +179,22 @@ void Scumm::initScummVars() {
_vars[VAR_SOUNDPARAM] = _soundParam;
_vars[VAR_SOUNDPARAM2] = _soundParam2;
_vars[VAR_SOUNDPARAM3] = _soundParam3;
- if (_features&GF_AFTER_V6)
+ if (_features & GF_AFTER_V6)
_vars[VAR_V6_EMSSPACE] = 10000;
}
}
-void Scumm::checkRange(int max, int min, int no, const char *str) {
+void Scumm::checkRange(int max, int min, int no, const char *str)
+{
if (no < min || no > max) {
- error("Value %d is out of bounds (%d,%d) int script(%d) msg %s", no, min,max, vm.slot[_curExecScript].number, str);
+ error("Value %d is out of bounds (%d,%d) int script(%d) msg %s", no, min,
+ max, vm.slot[_curExecScript].number, str);
}
}
-int Scumm::scummLoop(int delta) {
- static int counter=0;
+int Scumm::scummLoop(int delta)
+{
+ static int counter = 0;
#ifndef _WIN32_WCE
@@ -198,7 +205,7 @@ int Scumm::scummLoop(int delta) {
#endif
-
+
_vars[VAR_TMR_1] += delta;
_vars[VAR_TMR_2] += delta;
_vars[VAR_TMR_3] += delta;
@@ -210,11 +217,12 @@ int Scumm::scummLoop(int delta) {
decreaseScriptDelay(delta);
_talkDelay -= delta;
- if (_talkDelay<0) _talkDelay=0;
+ if (_talkDelay < 0)
+ _talkDelay = 0;
processKbd();
- if(_features & GF_AFTER_V7) {
+ if (_features & GF_AFTER_V7) {
_vars[VAR_CAMERA_POS_X] = camera._cur.x;
_vars[VAR_CAMERA_POS_Y] = camera._cur.y;
} else {
@@ -230,19 +238,17 @@ int Scumm::scummLoop(int delta) {
if (_features & GF_AUDIOTRACKS) {
if (delta) {
if (++counter != 2)
- _vars[VAR_MI1_TIMER]+=5;
+ _vars[VAR_MI1_TIMER] += 5;
else {
counter = 0;
- _vars[VAR_MI1_TIMER]+=6;
+ _vars[VAR_MI1_TIMER] += 6;
}
}
- }
- else
- if(_features & GF_OLD256)
- _vars[VAR_MUSIC_FLAG]++; // ENDERFIX
+ } else if (_features & GF_OLD256)
+ _vars[VAR_MUSIC_FLAG]++; // ENDERFIX
if (_saveLoadFlag) {
- if (_saveLoadFlag==1) {
+ if (_saveLoadFlag == 1) {
saveState(_saveLoadSlot, _saveLoadCompatible);
if (_saveLoadCompatible)
_vars[VAR_GAME_LOADED] = 201;
@@ -263,7 +269,7 @@ int Scumm::scummLoop(int delta) {
charset._hasMask = false;
redrawVerbs();
_fullRedraw = true;
- for (i=0,a=getFirstActor(); i<NUM_ACTORS; i++,a++)
+ for (i = 0, a = getFirstActor(); i < NUM_ACTORS; i++, a++)
a->needRedraw = 1;
}
@@ -271,7 +277,7 @@ int Scumm::scummLoop(int delta) {
checkExecVerbs();
checkAndRunVar33();
- if (_currentRoom==0) {
+ if (_currentRoom == 0) {
gdi._cursorActive = 0;
CHARSET_1();
drawDirtyScreenParts();
@@ -282,12 +288,13 @@ int Scumm::scummLoop(int delta) {
moveCamera();
fixObjectFlags();
CHARSET_1();
- if(!(_features & GF_AFTER_V7)) {
+ if (!(_features & GF_AFTER_V7)) {
if (camera._cur.x != camera._last.x || _BgNeedsRedraw || _fullRedraw) {
redrawBGAreas();
}
} else {
- if (camera._cur.x != camera._last.x || camera._cur.y != camera._last.y || _BgNeedsRedraw || _fullRedraw) {
+ if (camera._cur.x != camera._last.x || camera._cur.y != camera._last.y
+ || _BgNeedsRedraw || _fullRedraw) {
redrawBGAreas();
}
}
@@ -295,9 +302,9 @@ int Scumm::scummLoop(int delta) {
setActorRedrawFlags();
resetActorBgs();
-// if (!(_vars[VAR_V5_DRAWFLAGS]&2) && _vars[VAR_V5_DRAWFLAGS]&4) {
-// error("Flashlight not implemented in this version");
-// }
+// if (!(_vars[VAR_V5_DRAWFLAGS]&2) && _vars[VAR_V5_DRAWFLAGS]&4) {
+// error("Flashlight not implemented in this version");
+// }
processActors();
clear_fullRedraw();
@@ -320,7 +327,7 @@ int Scumm::scummLoop(int delta) {
drawDirtyScreenParts();
removeEnqueuedObjects();
- if (!(_features&GF_AFTER_V6))
+ if (!(_features & GF_AFTER_V6))
playActorSounds();
processSoundQues();
@@ -330,34 +337,35 @@ int Scumm::scummLoop(int delta) {
if (!(++_expire_counter)) {
increaseResourceCounter();
}
-
+
_vars[VAR_TIMER] = 0;
return _vars[VAR_TIMER_NEXT];
}
-void Scumm::startScene(int room, Actor *a, int objectNr) {
- int i,where;
+void Scumm::startScene(int room, Actor * a, int objectNr)
+{
+ int i, where;
Actor *at;
- CHECK_HEAP
-
- debug(1,"Loading room %d", room);
+ CHECK_HEAP debug(1, "Loading room %d", room);
clearMsgQueue();
unkVirtScreen4(_switchRoomEffect2);
_newEffect = _switchRoomEffect;
- if (_currentScript!=0xFF) {
- if (vm.slot[_currentScript].where==WIO_ROOM ||
- vm.slot[_currentScript].where==WIO_FLOBJECT) {
- if(vm.slot[_currentScript].cutsceneOverride!=0)
- error("Object %d stopped with active cutscene/override in exit", vm.slot[_currentScript].number);
+ if (_currentScript != 0xFF) {
+ if (vm.slot[_currentScript].where == WIO_ROOM ||
+ vm.slot[_currentScript].where == WIO_FLOBJECT) {
+ if (vm.slot[_currentScript].cutsceneOverride != 0)
+ error("Object %d stopped with active cutscene/override in exit",
+ vm.slot[_currentScript].number);
_currentScript = 0xFF;
- } else if (vm.slot[_currentScript].where==WIO_LOCAL) {
- if (vm.slot[_currentScript].cutsceneOverride!=0)
- error("Script %d stopped with active cutscene/override in exit", vm.slot[_currentScript].number);
+ } else if (vm.slot[_currentScript].where == WIO_LOCAL) {
+ if (vm.slot[_currentScript].cutsceneOverride != 0)
+ error("Script %d stopped with active cutscene/override in exit",
+ vm.slot[_currentScript].number);
_currentScript = 0xFF;
}
}
@@ -368,13 +376,13 @@ void Scumm::startScene(int room, Actor *a, int objectNr) {
clearEnqueue();
stopCycle(0);
- for(i=1,at=getFirstActor(); ++at,i<NUM_ACTORS; i++) {
+ for (i = 1, at = getFirstActor(); ++at, i < NUM_ACTORS; i++) {
if (at->visible)
hideActor(at);
}
-
+
if (!(_features & GF_AFTER_V7)) {
- for (i=0; i<0x100; i++)
+ for (i = 0; i < 0x100; i++)
_shadowPalette[i] = i;
}
@@ -389,13 +397,13 @@ void Scumm::startScene(int room, Actor *a, int objectNr) {
_vars[VAR_ROOM] = room;
// printf("startscene with room 0x%x\n", room);
if (room >= 0x80)
- _roomResource = _resourceMapper[room&0x7F];
+ _roomResource = _resourceMapper[room & 0x7F];
else
_roomResource = room;
_vars[VAR_ROOM_RESOURCE] = _roomResource;
- if (room!=0)
+ if (room != 0)
ensureResourceLoaded(1, room);
if (_currentRoom == 0) {
@@ -405,22 +413,22 @@ void Scumm::startScene(int room, Actor *a, int objectNr) {
}
initRoomSubBlocks();
- if(_features & GF_SMALL_HEADER)
- loadRoomObjectsSmall();
- else
- loadRoomObjects();
+ if (_features & GF_SMALL_HEADER)
+ loadRoomObjectsSmall();
+ else
+ loadRoomObjects();
- if(!(_features & GF_AFTER_V7)) {
+ if (!(_features & GF_AFTER_V7)) {
camera._mode = CM_NORMAL;
camera._cur.x = camera._dest.x = 160;
}
- if (_features&GF_AFTER_V6) {
+ if (_features & GF_AFTER_V6) {
_vars[VAR_V6_SCREEN_WIDTH] = _scrWidth;
_vars[VAR_V6_SCREEN_HEIGHT] = _scrHeight;
}
- if(_features & GF_AFTER_V7) {
+ if (_features & GF_AFTER_V7) {
_vars[VAR_CAMERA_MIN_X] = 160;
_vars[VAR_CAMERA_MAX_X] = _scrWidth - 160;
_vars[VAR_CAMERA_MIN_Y] = 100;
@@ -439,8 +447,9 @@ void Scumm::startScene(int room, Actor *a, int objectNr) {
if (a) {
where = whereIsObject(objectNr);
- if (where != WIO_ROOM && where!=WIO_FLOBJECT)
- error("startScene: Object %d is not in room %d", objectNr, _currentRoom);
+ if (where != WIO_ROOM && where != WIO_FLOBJECT)
+ error("startScene: Object %d is not in room %d", objectNr,
+ _currentRoom);
getObjectXYPos(objectNr);
putActor(a, _xPos, _yPos, _currentRoom);
fixActorDirection(a, _dir + 180);
@@ -452,7 +461,7 @@ void Scumm::startScene(int room, Actor *a, int objectNr) {
_egoPositioned = false;
runEntryScript();
- if(!(_features & GF_AFTER_V7)) {
+ if (!(_features & GF_AFTER_V7)) {
if (a && !_egoPositioned) {
getObjectXYPos(objectNr);
putActor(a, _xPos, _yPos, _currentRoom);
@@ -467,13 +476,13 @@ void Scumm::startScene(int room, Actor *a, int objectNr) {
_doEffect = true;
- CHECK_HEAP
-}
+CHECK_HEAP}
-void Scumm::initRoomSubBlocks() {
- int i,offs;
+void Scumm::initRoomSubBlocks()
+{
+ int i, offs;
byte *ptr;
- byte *roomptr,*searchptr;
+ byte *roomptr, *searchptr;
RoomHeader *rmhd;
_ENCD_offs = 0;
@@ -483,28 +492,30 @@ void Scumm::initRoomSubBlocks() {
nukeResource(rtMatrix, 1);
nukeResource(rtMatrix, 2);
-
- for (i=1; i<_maxScaleTable; i++)
+
+ for (i = 1; i < _maxScaleTable; i++)
nukeResource(rtScaleTable, i);
roomptr = getResourceAddress(rtRoom, _roomResource);
-
- rmhd = (RoomHeader*)findResourceData(MKID('RMHD'), roomptr);
-
- if(_features & GF_AFTER_V7) {
+
+ rmhd = (RoomHeader *)findResourceData(MKID('RMHD'), roomptr);
+
+ if (_features & GF_AFTER_V7) {
_scrWidth = READ_LE_UINT16(&(rmhd->v7.width));
_scrHeight = READ_LE_UINT16(&(rmhd->v7.height));
} else {
- _scrWidth = READ_LE_UINT16(&(rmhd->old.width));
+ _scrWidth = READ_LE_UINT16(&(rmhd->old.width));
_scrHeight = READ_LE_UINT16(&(rmhd->old.height));
}
-
- if( _features & GF_SMALL_HEADER)
- _IM00_offs = findResourceData(MKID('IM00'), roomptr) - roomptr;
- else
- _IM00_offs = findResource(MKID('IM00'), findResource(MKID('RMIM'), roomptr)) - roomptr;
-
+
+ if (_features & GF_SMALL_HEADER)
+ _IM00_offs = findResourceData(MKID('IM00'), roomptr) - roomptr;
+ else
+ _IM00_offs =
+ findResource(MKID('IM00'),
+ findResource(MKID('RMIM'), roomptr)) - roomptr;
+
ptr = findResourceData(MKID('EXCD'), roomptr);
if (ptr) {
_EXCD_offs = ptr - roomptr;
@@ -521,13 +532,13 @@ void Scumm::initRoomSubBlocks() {
#endif
}
- if(_features & GF_SMALL_HEADER) {
+ if (_features & GF_SMALL_HEADER) {
ptr = findResourceData(MKID('BOXD'), roomptr);
if (ptr) {
- byte numOfBoxes=*(ptr);
- int size;
+ byte numOfBoxes = *(ptr);
+ int size;
if (_features & GF_OLD256)
- size = numOfBoxes * (SIZEOF_BOX-2) + 1;
+ size = numOfBoxes * (SIZEOF_BOX - 2) + 1;
else
size = numOfBoxes * SIZEOF_BOX + 1;
@@ -535,38 +546,38 @@ void Scumm::initRoomSubBlocks() {
createResource(rtMatrix, 2, size);
memcpy(getResourceAddress(rtMatrix, 2), ptr, size);
ptr += size;
- size = getResourceDataSize(ptr-size-6) - size;
+ size = getResourceDataSize(ptr - size - 6) - size;
- if(size>=0) { // do this :)
+ if (size >= 0) { // do this :)
createResource(rtMatrix, 1, size);
memcpy(getResourceAddress(rtMatrix, 1), ptr, size);
}
-
+
}
- } else {
- ptr = findResourceData(MKID('BOXD'), roomptr);
- if (ptr) {
- int size = getResourceDataSize(ptr);
+ } else {
+ ptr = findResourceData(MKID('BOXD'), roomptr);
+ if (ptr) {
+ int size = getResourceDataSize(ptr);
createResource(rtMatrix, 2, size);
- roomptr = getResourceAddress(rtRoom, _roomResource);
- ptr = findResourceData(MKID('BOXD'), roomptr);
- memcpy(getResourceAddress(rtMatrix, 2), ptr, size);
- }
-
- ptr = findResourceData(MKID('BOXM'), roomptr);
- if (ptr) {
- int size = getResourceDataSize(ptr);
- createResource(rtMatrix, 1, size);
- roomptr = getResourceAddress(rtRoom, _roomResource);
- ptr = findResourceData(MKID('BOXM'), roomptr);
- memcpy(getResourceAddress(rtMatrix, 1), ptr, size);
- }
- }
+ roomptr = getResourceAddress(rtRoom, _roomResource);
+ ptr = findResourceData(MKID('BOXD'), roomptr);
+ memcpy(getResourceAddress(rtMatrix, 2), ptr, size);
+ }
+
+ ptr = findResourceData(MKID('BOXM'), roomptr);
+ if (ptr) {
+ int size = getResourceDataSize(ptr);
+ createResource(rtMatrix, 1, size);
+ roomptr = getResourceAddress(rtRoom, _roomResource);
+ ptr = findResourceData(MKID('BOXM'), roomptr);
+ memcpy(getResourceAddress(rtMatrix, 1), ptr, size);
+ }
+ }
ptr = findResourceData(MKID('SCAL'), roomptr);
if (ptr) {
offs = ptr - roomptr;
- for (i=1; i<_maxScaleTable; i++, offs+=8) {
+ for (i = 1; i < _maxScaleTable; i++, offs += 8) {
int a = READ_LE_UINT16(roomptr + offs);
int b = READ_LE_UINT16(roomptr + offs + 2);
int c = READ_LE_UINT16(roomptr + offs + 4);
@@ -580,65 +591,65 @@ void Scumm::initRoomSubBlocks() {
memset(_localScriptList, 0, sizeof(_localScriptList));
searchptr = roomptr = getResourceAddress(rtRoom, _roomResource);
- if(_features & GF_SMALL_HEADER) {
- while( (ptr = findResourceSmall(MKID('LSCR'), searchptr)) != NULL ) {
+ if (_features & GF_SMALL_HEADER) {
+ while ((ptr = findResourceSmall(MKID('LSCR'), searchptr)) != NULL) {
int id = 0;
- ptr += _resourceHeaderSize; /* skip tag & size */
- #ifdef DUMP_SCRIPTS
+ ptr += _resourceHeaderSize; /* skip tag & size */
+#ifdef DUMP_SCRIPTS
do {
char buf[32];
- sprintf(buf,"room-%d-",_roomResource);
+ sprintf(buf, "room-%d-", _roomResource);
dumpResource(buf, id, ptr - 6);
} while (0);
- #endif
+#endif
id = ptr[0];
_localScriptList[id - _numGlobalScripts] = ptr + 1 - roomptr;
searchptr = NULL;
}
} else {
- while( (ptr = findResource(MKID('LSCR'), searchptr)) != NULL ) {
- int id = 0;
+ while ((ptr = findResource(MKID('LSCR'), searchptr)) != NULL) {
+ int id = 0;
+
+ ptr += _resourceHeaderSize; /* skip tag & size */
- ptr += _resourceHeaderSize; /* skip tag & size */
-
- if(_features & GF_AFTER_V7) {
+ if (_features & GF_AFTER_V7) {
id = READ_LE_UINT16(ptr);
checkRange(2050, 2000, id, "Invalid local script %d");
_localScriptList[id - _numGlobalScripts] = ptr + 2 - roomptr;
} else {
- id = ptr[0];
- _localScriptList[id - _numGlobalScripts] = ptr + 1 - roomptr;
+ id = ptr[0];
+ _localScriptList[id - _numGlobalScripts] = ptr + 1 - roomptr;
}
#ifdef DUMP_SCRIPTS
- do {
- char buf[32];
- sprintf(buf,"room-%d-",_roomResource);
- dumpResource(buf, id, ptr - 8);
- } while (0);
+ do {
+ char buf[32];
+ sprintf(buf, "room-%d-", _roomResource);
+ dumpResource(buf, id, ptr - 8);
+ } while (0);
#endif
- searchptr = NULL;
- }
- }
+ searchptr = NULL;
+ }
+ }
- if( _features & GF_SMALL_HEADER)
+ if (_features & GF_SMALL_HEADER)
ptr = findResourceSmall(MKID('EPAL'), roomptr);
- else
- ptr = findResource(MKID('EPAL'), roomptr);
+ else
+ ptr = findResource(MKID('EPAL'), roomptr);
if (ptr)
_EPAL_offs = ptr - roomptr;
- if( _features & GF_SMALL_HEADER)
+ if (_features & GF_SMALL_HEADER)
ptr = findResourceSmall(MKID('CLUT'), roomptr);
else
- ptr = findResourceData(MKID('CLUT'), roomptr);
+ ptr = findResourceData(MKID('CLUT'), roomptr);
if (ptr) {
_CLUT_offs = ptr - roomptr;
setPaletteFromRes();
}
- if (_features&GF_AFTER_V6) {
+ if (_features & GF_AFTER_V6) {
ptr = findResource(MKID('PALS'), roomptr);
if (ptr) {
_PALS_offs = ptr - roomptr;
@@ -646,13 +657,13 @@ void Scumm::initRoomSubBlocks() {
}
}
- if( _features & GF_SMALL_HEADER)
- ptr = findResourceData(MKID('CYCL'), roomptr);
- else
- ptr = findResourceData(MKID('CYCL'), roomptr);
+ if (_features & GF_SMALL_HEADER)
+ ptr = findResourceData(MKID('CYCL'), roomptr);
+ else
+ ptr = findResourceData(MKID('CYCL'), roomptr);
- if (ptr)
- initCycl(findResourceData(MKID('CYCL'), roomptr));
+ if (ptr)
+ initCycl(findResourceData(MKID('CYCL'), roomptr));
ptr = findResourceData(MKID('TRNS'), roomptr);
if (ptr)
@@ -665,44 +676,48 @@ void Scumm::initRoomSubBlocks() {
memset(_extraBoxFlags, 0, sizeof(_extraBoxFlags));
}
-void Scumm::setScaleItem(int slot, int a, int b, int c, int d) {
+void Scumm::setScaleItem(int slot, int a, int b, int c, int d)
+{
byte *ptr;
- int cur,amounttoadd,i,tmp;
+ int cur, amounttoadd, i, tmp;
ptr = createResource(rtScaleTable, slot, 200);
- if (a==c)
+ if (a == c)
return;
-
- cur = (b-d)*a;
+
+ cur = (b - d) * a;
amounttoadd = d - b;
-
- for (i=200; i>0; i--) {
+
+ for (i = 200; i > 0; i--) {
tmp = cur / (c - a) + b;
- if (tmp<1) tmp=1;
- if (tmp>255) tmp=255;
+ if (tmp < 1)
+ tmp = 1;
+ if (tmp > 255)
+ tmp = 255;
*ptr++ = tmp;
cur += amounttoadd;
}
}
-void Scumm::dumpResource(char *tag, int idx, byte *ptr) {
+void Scumm::dumpResource(char *tag, int idx, byte *ptr)
+{
char buf[256];
FILE *out;
-
- uint32 size;
- if( _features & GF_SMALL_HEADER )
- size = READ_LE_UINT32(ptr);
- else
- size = READ_BE_UINT32_UNALIGNED(ptr+4);
-
- #if defined(__APPLE__CW)
- sprintf(buf, ":dumps:%s%d.dmp", tag,idx);
- #else
- sprintf(buf, "dumps/%s%d.dmp", tag,idx);
- #endif
-
- out = fopen(buf,"rb");
+
+ uint32 size;
+ if (_features & GF_SMALL_HEADER)
+ size = READ_LE_UINT32(ptr);
+ else
+ size = READ_BE_UINT32_UNALIGNED(ptr + 4);
+
+#if defined(__APPLE__CW)
+ sprintf(buf, ":dumps:%s%d.dmp", tag, idx);
+#else
+ sprintf(buf, "dumps/%s%d.dmp", tag, idx);
+#endif
+
+ out = fopen(buf, "rb");
if (!out) {
out = fopen(buf, "wb");
if (!out)
@@ -713,59 +728,68 @@ void Scumm::dumpResource(char *tag, int idx, byte *ptr) {
}
-void Scumm::clear_fullRedraw() {
+void Scumm::clear_fullRedraw()
+{
_fullRedraw = 0;
}
-void Scumm::clearClickedStatus() {
+void Scumm::clearClickedStatus()
+{
checkKeyHit();
_mouseButStat = 0;
_leftBtnPressed = 0;
_rightBtnPressed = 0;
}
-int Scumm::checkKeyHit() {
+int Scumm::checkKeyHit()
+{
int a = _keyPressed;
_keyPressed = 0;
return a;
}
-
-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::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::unkRoomFunc4(int a, int b, int c, int d, int e) {
+void Scumm::unkRoomFunc4(int a, int b, int c, int d, int e)
+{
/* TODO: implement this */
warning("unkRoomFunc4: not implemented");
}
-void Scumm::pauseGame(bool user) {
- ((Gui*)_gui)->pause(this);
+void Scumm::pauseGame(bool user)
+{
+ ((Gui *)_gui)->pause(this);
}
-void Scumm::setOptions() {
- ((Gui*)_gui)->options(this);
+void Scumm::setOptions()
+{
+ ((Gui *)_gui)->options(this);
}
-void Scumm::shutDown(int i) {
+void Scumm::shutDown(int i)
+{
/* TODO: implement this */
warning("shutDown: not implemented");
}
-void Scumm::processKbd() {
+void Scumm::processKbd()
+{
getKeyInput(0);
_virtual_mouse_x = mouse.x + virtscr[0].xstart;
_virtual_mouse_y = mouse.y;
-
- if(!(_features & GF_OLD256))
- _virtual_mouse_y+=virtscr[0].topline;
+
+ if (!(_features & GF_OLD256))
+ _virtual_mouse_y += virtscr[0].topline;
else
- _virtual_mouse_y-=16;
-
+ _virtual_mouse_y -= 16;
+
if (_virtual_mouse_y < 0)
- _virtual_mouse_y =-1;
+ _virtual_mouse_y = -1;
if (_features & GF_OLD256) {
if (_virtual_mouse_y >= virtscr[0].height + virtscr[0].topline)
_virtual_mouse_y = -1;
@@ -777,37 +801,38 @@ void Scumm::processKbd() {
if (!_lastKeyHit)
return;
- if (_lastKeyHit==KEY_SET_OPTIONS) {
+ if (_lastKeyHit == KEY_SET_OPTIONS) {
setOptions();
return;
}
- if (_lastKeyHit==_vars[VAR_RESTART_KEY]) {
+ if (_lastKeyHit == _vars[VAR_RESTART_KEY]) {
warning("Restart not implemented");
-// pauseGame(true);
+// pauseGame(true);
return;
}
- if (_lastKeyHit==_vars[VAR_PAUSE_KEY]) {
+ if (_lastKeyHit == _vars[VAR_PAUSE_KEY]) {
pauseGame(true);
/* pause */
return;
}
- if (_lastKeyHit==_vars[VAR_CUTSCENEEXIT_KEY]) {
+ if (_lastKeyHit == _vars[VAR_CUTSCENEEXIT_KEY]) {
if (_insaneState) {
- videoFinished=1;
+ videoFinished = 1;
} else
exitCutscene();
- } else if (_lastKeyHit==_vars[VAR_SAVELOADDIALOG_KEY] && _currentRoom != 0) {
- if ( _features & GF_AFTER_V7)
- runScript(_vars[VAR_UNK_SCRIPT],0,0,0);
- ((Gui*)_gui)->saveLoadDialog(this);
- if ( _features & GF_AFTER_V7)
- runScript(_vars[VAR_UNK_SCRIPT_2],0,0,0);
- } else if (_lastKeyHit==_vars[VAR_TALKSTOP_KEY]) {
+ } else if (_lastKeyHit == _vars[VAR_SAVELOADDIALOG_KEY]
+ && _currentRoom != 0) {
+ if (_features & GF_AFTER_V7)
+ runScript(_vars[VAR_UNK_SCRIPT], 0, 0, 0);
+ ((Gui *)_gui)->saveLoadDialog(this);
+ if (_features & GF_AFTER_V7)
+ runScript(_vars[VAR_UNK_SCRIPT_2], 0, 0, 0);
+ } else if (_lastKeyHit == _vars[VAR_TALKSTOP_KEY]) {
_talkDelay = 0;
- if (_sfxMode==2)
+ if (_sfxMode == 2)
stopTalk();
return;
}
@@ -815,32 +840,37 @@ void Scumm::processKbd() {
_mouseButStat = _lastKeyHit;
}
-int Scumm::getKeyInput(int a) {
+int Scumm::getKeyInput(int a)
+{
_mouseButStat = 0;
_lastKeyHit = checkKeyHit();
- if (a==0)
+ if (a == 0)
convertKeysToClicks();
- if (mouse.x<0) mouse.x=0;
- if (mouse.x>319) mouse.x=319;
- if (mouse.y<0) mouse.y=0;
- if (mouse.y>199) mouse.y=199;
+ if (mouse.x < 0)
+ mouse.x = 0;
+ if (mouse.x > 319)
+ mouse.x = 319;
+ if (mouse.y < 0)
+ mouse.y = 0;
+ if (mouse.y > 199)
+ mouse.y = 199;
- if (_leftBtnPressed&msClicked && _rightBtnPressed&msClicked) {
+ if (_leftBtnPressed & msClicked && _rightBtnPressed & msClicked) {
_mouseButStat = 0;
_lastKeyHit = _vars[VAR_CUTSCENEEXIT_KEY];
- } else if (_leftBtnPressed&msClicked) {
+ } else if (_leftBtnPressed & msClicked) {
_mouseButStat = MBS_LEFT_CLICK;
- } else if (_rightBtnPressed&msClicked) {
+ } else if (_rightBtnPressed & msClicked) {
_mouseButStat = MBS_RIGHT_CLICK;
}
- if(_features & GF_AFTER_V7) {
-// _vars[VAR_LEFTBTN_DOWN] = (_leftBtnPressed&msClicked) != 0;
- _vars[VAR_LEFTBTN_HOLD] = (_leftBtnPressed&msDown) != 0;
-// _vars[VAR_RIGHTBTN_DOWN] = (_rightBtnPressed&msClicked) != 0;
- _vars[VAR_RIGHTBTN_HOLD] = (_rightBtnPressed&msDown) != 0;
+ if (_features & GF_AFTER_V7) {
+// _vars[VAR_LEFTBTN_DOWN] = (_leftBtnPressed&msClicked) != 0;
+ _vars[VAR_LEFTBTN_HOLD] = (_leftBtnPressed & msDown) != 0;
+// _vars[VAR_RIGHTBTN_DOWN] = (_rightBtnPressed&msClicked) != 0;
+ _vars[VAR_RIGHTBTN_HOLD] = (_rightBtnPressed & msDown) != 0;
}
_leftBtnPressed &= ~msClicked;
@@ -849,37 +879,43 @@ int Scumm::getKeyInput(int a) {
return _lastKeyHit;
}
-void Scumm::convertKeysToClicks() {
- if (_lastKeyHit && _cursorState>0) {
- if (_lastKeyHit==9) {
+void Scumm::convertKeysToClicks()
+{
+ if (_lastKeyHit && _cursorState > 0) {
+ if (_lastKeyHit == 9) {
_mouseButStat = MBS_RIGHT_CLICK;
- } else if (_lastKeyHit==13) {
- _mouseButStat = MBS_LEFT_CLICK;
+ } else if (_lastKeyHit == 13) {
+ _mouseButStat = MBS_LEFT_CLICK;
} else
return;
_lastKeyHit = 0;
}
}
-Actor *Scumm::derefActorSafe(int id, const char *errmsg) {
- if (id<1 || id>=NUM_ACTORS) {
- warning("Invalid actor %d in %s (script %d, opcode 0x%x) - This is potentially a BIG problem.", id, errmsg, vm.slot[_curExecScript].number, _opcode);
- return NULL;
+Actor *Scumm::derefActorSafe(int id, const char *errmsg)
+{
+ if (id < 1 || id >= NUM_ACTORS) {
+ warning
+ ("Invalid actor %d in %s (script %d, opcode 0x%x) - This is potentially a BIG problem.",
+ id, errmsg, vm.slot[_curExecScript].number, _opcode);
+ return NULL;
}
return derefActor(id);
}
-void Scumm::makeCursorColorTransparent(int a) {
- int i,size;
+void Scumm::makeCursorColorTransparent(int a)
+{
+ int i, size;
size = _cursorWidth * _cursorHeight;
- for(i=0; i<size; i++)
+ for (i = 0; i < size; i++)
if (_grabbedCursor[i] == (byte)a)
_grabbedCursor[i] = 0xFF;
}
-void Scumm::setStringVars(int slot) {
+void Scumm::setStringVars(int slot)
+{
StringTab *st = &string[slot];
st->xpos = st->t_xpos;
st->ypos = st->t_ypos;
@@ -891,15 +927,18 @@ void Scumm::setStringVars(int slot) {
st->charset = st->t_charset;
}
-void Scumm::unkMiscOp9() {
+void Scumm::unkMiscOp9()
+{
warning("stub unkMiscOp9()");
}
-void Scumm::startManiac() {
+void Scumm::startManiac()
+{
warning("stub startManiac()");
}
-void Scumm::destroy() {
+void Scumm::destroy()
+{
freeResources();
free(_objectStateTable);
@@ -915,12 +954,13 @@ void Scumm::destroy() {
free(_classData);
}
-int Scumm::newDirToOldDir(int dir) {
- if (dir>=71 && dir<=109)
+int Scumm::newDirToOldDir(int dir)
+{
+ if (dir >= 71 && dir <= 109)
return 1;
- if (dir>=109 && dir<=251)
+ if (dir >= 109 && dir <= 251)
return 2;
- if (dir>=251 && dir<=289)
+ if (dir >= 251 && dir <= 289)
return 0;
return 3;
}
@@ -932,20 +972,23 @@ const int new_dir_table[4] = {
0,
};
-int Scumm::oldDirToNewDir(int dir) {
+int Scumm::oldDirToNewDir(int dir)
+{
return new_dir_table[dir];
}
-int Scumm::numSimpleDirDirections(int dirType) {
+int Scumm::numSimpleDirDirections(int dirType)
+{
return dirType ? 8 : 4;
}
/* Convert an angle to a simple direction */
-int Scumm::toSimpleDir(int dirType, int dir) {
+int Scumm::toSimpleDir(int dirType, int dir)
+{
int num = dirType ? 8 : 4, i;
- const uint16 *dirtab = &many_direction_tab[dirType*8+2];
- for(i=1;i<num;i++,dirtab++) {
+ const uint16 *dirtab = &many_direction_tab[dirType * 8 + 2];
+ for (i = 1; i < num; i++, dirtab++) {
if (dir >= dirtab[0] && dir <= dirtab[1])
return i;
}
@@ -954,19 +997,23 @@ int Scumm::toSimpleDir(int dirType, int dir) {
}
/* Convert a simple direction to an angle */
-int Scumm::fromSimpleDir(int dirType, int dir) {
- if (!dirType)dir+=dir;
+int Scumm::fromSimpleDir(int dirType, int dir)
+{
+ if (!dirType)
+ dir += dir;
return dir * 45;
}
-int Scumm::normalizeAngle(int angle) {
- return (angle+360)%360;
+int Scumm::normalizeAngle(int angle)
+{
+ return (angle + 360) % 360;
}
extern Scumm *scumm;
-void NORETURN CDECL error(const char *s, ...) {
+void NORETURN CDECL error(const char *s, ...)
+{
char buf[1024];
va_list va;
@@ -977,10 +1024,9 @@ void NORETURN CDECL error(const char *s, ...) {
if (scumm->_currentScript != 0xFF) {
ScriptSlot *ss = &scumm->vm.slot[scumm->_currentScript];
fprintf(stderr, "Error(%d:%d:0x%X): %s!\n",
- scumm->_roomResource,
- ss->number,
- scumm->_scriptPointer - scumm->_scriptOrgPointer,
- buf);
+ scumm->_roomResource,
+ ss->number,
+ scumm->_scriptPointer - scumm->_scriptOrgPointer, buf);
} else {
fprintf(stderr, "Error: %s!\n", buf);
}
@@ -988,32 +1034,35 @@ void NORETURN CDECL error(const char *s, ...) {
exit(1);
}
-void CDECL warning(const char *s, ...) {
+void CDECL warning(const char *s, ...)
+{
char buf[1024];
va_list va;
-
- va_start(va,s);
+
+ va_start(va, s);
vsprintf(buf, s, va);
va_end(va);
fprintf(stderr, "WARNING: %s!\n", buf);
}
-void CDECL debug(int level, const char *s, ...) {
+void CDECL debug(int level, const char *s, ...)
+{
char buf[1024];
va_list va;
- if (level>5)
+ if (level > 5)
return;
- va_start(va,s);
+ va_start(va, s);
vsprintf(buf, s, va);
va_end(va);
printf("%s\n", buf);
fflush(stdout);
}
-void checkHeap() {
+void checkHeap()
+{
#if defined(WIN32)
if (_heapchk() != _HEAPOK) {
error("Heap is invalid!");
@@ -1021,15 +1070,15 @@ void checkHeap() {
#endif
}
-void Scumm::mainRun() {
-
- delta=0;
-
- do
- {
+void Scumm::mainRun()
+{
+
+ delta = 0;
+
+ do {
_system->waitTick(delta);
delta = scummLoop(delta);
- }while(1);
+ } while (1);
}
void Scumm::launch()
@@ -1042,9 +1091,9 @@ void Scumm::launch()
_minHeapThreshold = 400000;
/* Init graphics and create a primary virtual screen */
-
+
initGraphics(this, _fullScreen, _scale);
- allocResTypeData(rtBuffer, MKID('NONE'),10,"buffer",0);
+ allocResTypeData(rtBuffer, MKID('NONE'), 10, "buffer", 0);
initVirtScreen(0, 0, 200, false, false);
if (_features & GF_AFTER_V7)
@@ -1057,18 +1106,18 @@ void Scumm::launch()
else
NUM_ACTORS = 13;
- if(_features & GF_AFTER_V7)
+ if (_features & GF_AFTER_V7)
OF_OWNER_ROOM = 0xFF;
else
OF_OWNER_ROOM = 0x0F;
-
-// if (_gameId==GID_MONKEY2 && _bootParam == 0)
-// _bootParam = 10001;
- if (_gameId==GID_INDY4 && _bootParam==0) {
+// if (_gameId==GID_MONKEY2 && _bootParam == 0)
+// _bootParam = 10001;
+
+ if (_gameId == GID_INDY4 && _bootParam == 0) {
_bootParam = -7873;
}
-
+
readIndexFile();
initRandSeeds();
@@ -1080,7 +1129,7 @@ void Scumm::launch()
scummInit();
- if(!(_features & GF_AFTER_V7))
+ if (!(_features & GF_AFTER_V7))
_vars[VAR_VERSION] = 21;
_vars[VAR_DEBUGMODE] = _debugMode;
@@ -1090,9 +1139,9 @@ void Scumm::launch()
setupSound();
- runScript(1,0,0,&_bootParam);
-
-// _scummTimer = 0;
+ runScript(1, 0, 0, &_bootParam);
+
+// _scummTimer = 0;
+
-
}
diff --git a/sdl.cpp b/sdl.cpp
index a2096f739d..429a1710c2 100644
--- a/sdl.cpp
+++ b/sdl.cpp
@@ -43,136 +43,144 @@ SoundEngine sound;
SOUND_DRIVER_TYPE snd_driv;
static SDL_Surface *screen;
-static SDL_CD *cdrom;
+static SDL_CD *cdrom;
/* For 2xSAI */
static SDL_Surface *sdl_hwscreen;
static SDL_Surface *sdl_tmpscreen;
-int Init_2xSaI (uint32 BitFormat);
-void _2xSaI (uint8 *srcPtr, uint32 srcPitch, uint8 *deltaPtr, uint8 *dstPtr, uint32 dstPitch, int width, int height);
-void Super2xSaI (uint8 *srcPtr, uint32 srcPitch, uint8 *deltaPtr, uint8 *dstPtr, uint32 dstPitch, int width, int height);
-void SuperEagle(uint8 *srcPtr, uint32 srcPitch, uint8 *deltaPtr, uint8 *dstPtr, uint32 dstPitch, int width, int height);
+int Init_2xSaI(uint32 BitFormat);
+void _2xSaI(uint8 *srcPtr, uint32 srcPitch, uint8 *deltaPtr, uint8 *dstPtr,
+ uint32 dstPitch, int width, int height);
+void Super2xSaI(uint8 *srcPtr, uint32 srcPitch, uint8 *deltaPtr,
+ uint8 *dstPtr, uint32 dstPitch, int width, int height);
+void SuperEagle(uint8 *srcPtr, uint32 srcPitch, uint8 *deltaPtr,
+ uint8 *dstPtr, uint32 dstPitch, int width, int height);
static int current_shake_pos;
-void resetCursor(void) {
+void resetCursor(void)
+{
SDL_ShowCursor(SDL_ENABLE);
}
void updateScreen(Scumm *s);
-void updatePalette(Scumm *s) {
+void updatePalette(Scumm *s)
+{
SDL_Color colors[256];
int first = s->_palDirtyMin;
int num = s->_palDirtyMax - first + 1;
int i;
byte *data = s->_currentPalette;
-
- data += first*3;
- for (i=0; i<num; i++,data+=3) {
+
+ data += first * 3;
+ for (i = 0; i < num; i++, data += 3) {
colors[i].r = data[0];
colors[i].g = data[1];
colors[i].b = data[2];
colors[i].unused = 0;
}
-
+
SDL_SetColors(screen, colors, first, num);
-
+
s->_palDirtyMax = -1;
s->_palDirtyMin = 0x3E8;
}
-int mapKey(int key, byte mod) {
- if (key>=SDLK_F1 && key<=SDLK_F9) {
+int mapKey(int key, byte mod)
+{
+ if (key >= SDLK_F1 && key <= SDLK_F9) {
return key - SDLK_F1 + 315;
- } else if (key>='a' && key<='z' && mod&KMOD_SHIFT) {
- key&=~0x20;
- } else if (key>=SDLK_NUMLOCK && key<=SDLK_EURO)
+ } else if (key >= 'a' && key <= 'z' && mod & KMOD_SHIFT) {
+ key &= ~0x20;
+ } else if (key >= SDLK_NUMLOCK && key <= SDLK_EURO)
return 0;
return key;
}
-void waitForTimer(Scumm *s, int msec_delay) {
+void waitForTimer(Scumm *s, int msec_delay)
+{
SDL_Event event;
uint32 start_time;
- if (s->_fastMode&2)
+ if (s->_fastMode & 2)
msec_delay = 0;
- else if (s->_fastMode&1)
+ else if (s->_fastMode & 1)
msec_delay = 10;
start_time = SDL_GetTicks();
do {
while (SDL_PollEvent(&event)) {
- switch(event.type) {
+ switch (event.type) {
case SDL_KEYDOWN:
s->_keyPressed = mapKey(event.key.keysym.sym, event.key.keysym.mod);
- if (event.key.keysym.sym >= '0' && event.key.keysym.sym<='9') {
+ if (event.key.keysym.sym >= '0' && event.key.keysym.sym <= '9') {
s->_saveLoadSlot = event.key.keysym.sym - '0';
- if (event.key.keysym.mod&KMOD_SHIFT) {
+ if (event.key.keysym.mod & KMOD_SHIFT) {
sprintf(s->_saveLoadName, "Quicksave %d", s->_saveLoadSlot);
s->_saveLoadFlag = 1;
- } else if (event.key.keysym.mod&KMOD_CTRL)
+ } else if (event.key.keysym.mod & KMOD_CTRL)
s->_saveLoadFlag = 2;
s->_saveLoadCompatible = false;
- } else if (event.key.keysym.sym=='z' && event.key.keysym.mod&KMOD_CTRL) {
+ } else if (event.key.keysym.sym == 'z'
+ && event.key.keysym.mod & KMOD_CTRL) {
exit(1);
- } else if (event.key.keysym.sym=='f' && event.key.keysym.mod&KMOD_CTRL) {
+ } else if (event.key.keysym.sym == 'f'
+ && event.key.keysym.mod & KMOD_CTRL) {
s->_fastMode ^= 1;
- } else if (event.key.keysym.sym=='g' && event.key.keysym.mod&KMOD_CTRL) {
+ } else if (event.key.keysym.sym == 'g'
+ && event.key.keysym.mod & KMOD_CTRL) {
s->_fastMode ^= 2;
- } else if (event.key.keysym.sym=='d' && event.key.keysym.mod&KMOD_CTRL) {
+ } else if (event.key.keysym.sym == 'd'
+ && event.key.keysym.mod & KMOD_CTRL) {
debugger.attach(s);
- } else if (event.key.keysym.sym=='s' && event.key.keysym.mod&KMOD_CTRL) {
+ } else if (event.key.keysym.sym == 's'
+ && event.key.keysym.mod & KMOD_CTRL) {
s->resourceStats();
- } else if (event.key.keysym.sym==SDLK_RETURN && event.key.keysym.mod&KMOD_ALT) {
- if(!SDL_WM_ToggleFullScreen(screen))
+ } else if (event.key.keysym.sym == SDLK_RETURN
+ && event.key.keysym.mod & KMOD_ALT) {
+ if (!SDL_WM_ToggleFullScreen(screen))
warning("Full screen failed");
}
-
- #if defined(__APPLE__) || defined(MACOS)
- if (event.key.keysym.sym=='q' && event.key.keysym.mod&KMOD_LMETA) {
+#if defined(__APPLE__) || defined(MACOS)
+ if (event.key.keysym.sym == 'q' && event.key.keysym.mod & KMOD_LMETA) {
exit(1);
- }
- #endif
- break;
- case SDL_MOUSEMOTION: {
- int newx,newy;
- if (scale == 3)
- {
- newx = event.motion.x/3;
- newy = event.motion.y/3;
- } else
- if (scale == 2)
- {
- newx = event.motion.x>>1;
- newy = event.motion.y>>1;
- } else
- {
- newx = event.motion.x;
- newy = event.motion.y;
- }
-
- if (newx != s->mouse.x || newy != s->mouse.y) {
- s->mouse.x = newx;
- s->mouse.y = newy;
- s->drawMouse();
- updateScreen(s);
}
+#endif
break;
+ case SDL_MOUSEMOTION:{
+ int newx, newy;
+ if (scale == 3) {
+ newx = event.motion.x / 3;
+ newy = event.motion.y / 3;
+ } else if (scale == 2) {
+ newx = event.motion.x >> 1;
+ newy = event.motion.y >> 1;
+ } else {
+ newx = event.motion.x;
+ newy = event.motion.y;
+ }
+
+ if (newx != s->mouse.x || newy != s->mouse.y) {
+ s->mouse.x = newx;
+ s->mouse.y = newy;
+ s->drawMouse();
+ updateScreen(s);
+ }
+ break;
}
case SDL_MOUSEBUTTONDOWN:
- if (event.button.button==SDL_BUTTON_LEFT)
- s->_leftBtnPressed |= msClicked|msDown;
- else if (event.button.button==SDL_BUTTON_RIGHT)
- s->_rightBtnPressed |= msClicked|msDown;
+ if (event.button.button == SDL_BUTTON_LEFT)
+ s->_leftBtnPressed |= msClicked | msDown;
+ else if (event.button.button == SDL_BUTTON_RIGHT)
+ s->_rightBtnPressed |= msClicked | msDown;
break;
case SDL_MOUSEBUTTONUP:
- if (event.button.button==SDL_BUTTON_LEFT)
+ if (event.button.button == SDL_BUTTON_LEFT)
s->_leftBtnPressed &= ~msDown;
- else if (event.button.button==SDL_BUTTON_RIGHT)
+ else if (event.button.button == SDL_BUTTON_RIGHT)
s->_rightBtnPressed &= ~msDown;
break;
@@ -182,7 +190,7 @@ void waitForTimer(Scumm *s, int msec_delay) {
}
}
- cd_music_loop(); // Loop CD Music if necessary
+ cd_music_loop(); // Loop CD Music if necessary
if (SDL_GetTicks() >= start_time + msec_delay)
break;
@@ -197,55 +205,62 @@ bool fullRedraw;
int old_mouse_x, old_mouse_y;
int old_mouse_h, old_mouse_w;
-bool has_mouse,hide_mouse;
+bool has_mouse, hide_mouse;
#define BAK_WIDTH 40
#define BAK_HEIGHT 40
-byte old_backup[BAK_WIDTH*BAK_HEIGHT*2];
+byte old_backup[BAK_WIDTH * BAK_HEIGHT * 2];
-void addDirtyRect(int x, int y, int w, int h) {
+void addDirtyRect(int x, int y, int w, int h)
+{
SDL_Rect *r;
- if (numDirtyRects==MAX_DIRTY_RECTS)
+ if (numDirtyRects == MAX_DIRTY_RECTS)
fullRedraw = true;
else if (!fullRedraw) {
r = &dirtyRects[numDirtyRects++];
- if (scale == 3)
- {
- r->x = x*3;
- r->y = y*3;
- r->w = w*3;
- r->h = h*3;
- } else
- if (scale == 2)
- {
- r->x = x*2;
- r->y = y*2;
- r->w = w*2;
- r->h = h*2;
- } else
- {
- r->x = x;
- r->y = y;
- r->w = w;
- r->h = h;
- }
+ if (scale == 3) {
+ r->x = x * 3;
+ r->y = y * 3;
+ r->w = w * 3;
+ r->h = h * 3;
+ } else if (scale == 2) {
+ r->x = x * 2;
+ r->y = y * 2;
+ r->w = w * 2;
+ r->h = h * 2;
+ } else {
+ r->x = x;
+ r->y = y;
+ r->w = w;
+ r->h = h;
+ }
}
}
-void addDirtyRectClipped(int x, int y, int w, int h) {
- if (x<0) { w += x; x=0; }
- if (y<0) { h += y; y=0; }
- if (w >= 320-x) w = 320-x;
- if (h >= 200-y) h = 200-y;
- if (w>0 && h>0)
- addDirtyRect(x,y,w,h);
+void addDirtyRectClipped(int x, int y, int w, int h)
+{
+ if (x < 0) {
+ w += x;
+ x = 0;
+ }
+ if (y < 0) {
+ h += y;
+ y = 0;
+ }
+ if (w >= 320 - x)
+ w = 320 - x;
+ if (h >= 200 - y)
+ h = 200 - y;
+ if (w > 0 && h > 0)
+ addDirtyRect(x, y, w, h);
}
#define MAX(a,b) (((a)<(b)) ? (b) : (a))
#define MIN(a,b) (((a)>(b)) ? (b) : (a))
-void setShakePos(Scumm *s, int shake_pos) {
+void setShakePos(Scumm *s, int shake_pos)
+{
int old_shake_pos = current_shake_pos;
int dirty_height, dirty_blackheight;
int dirty_top, dirty_blacktop;
@@ -253,28 +268,24 @@ void setShakePos(Scumm *s, int shake_pos) {
if (shake_pos != old_shake_pos) {
current_shake_pos = shake_pos;
fullRedraw = true;
-
+
/* Old shake pos was current_shake_pos, new is shake_pos.
* Move the screen up or down to account for the change.
*/
- if (scale == 3)
- {
- SDL_Rect dstr = {0,shake_pos*3,960,600};
- SDL_Rect srcr = {0,old_shake_pos*3,960,600};
- SDL_BlitSurface(screen, &srcr, screen, &dstr);
- } else
- if (scale == 2)
- {
- SDL_Rect dstr = {0,shake_pos*2,640,400};
- SDL_Rect srcr = {0,old_shake_pos*2,640,400};
- SDL_BlitSurface(screen, &srcr, screen, &dstr);
- } else
- {
- SDL_Rect dstr = {0,shake_pos,320,200};
- SDL_Rect srcr = {0,old_shake_pos,320,200};
- SDL_BlitSurface(screen, &srcr, screen, &dstr);
- }
-
+ if (scale == 3) {
+ SDL_Rect dstr = { 0, shake_pos * 3, 960, 600 };
+ SDL_Rect srcr = { 0, old_shake_pos * 3, 960, 600 };
+ SDL_BlitSurface(screen, &srcr, screen, &dstr);
+ } else if (scale == 2) {
+ SDL_Rect dstr = { 0, shake_pos * 2, 640, 400 };
+ SDL_Rect srcr = { 0, old_shake_pos * 2, 640, 400 };
+ SDL_BlitSurface(screen, &srcr, screen, &dstr);
+ } else {
+ SDL_Rect dstr = { 0, shake_pos, 320, 200 };
+ SDL_Rect srcr = { 0, old_shake_pos, 320, 200 };
+ SDL_BlitSurface(screen, &srcr, screen, &dstr);
+ }
+
/* Also adjust the mouse pointer backup Y coordinate.
* There is a minor mouse glitch when the mouse is moved
* at the blackness of the shake area, but it's hardly noticable */
@@ -283,33 +294,31 @@ void setShakePos(Scumm *s, int shake_pos) {
/* Refresh either the upper part of the screen,
* or the lower part */
if (shake_pos > old_shake_pos) {
- dirty_height = MIN(shake_pos, 0) - MIN(old_shake_pos,0);
- dirty_top = -MIN(shake_pos,0);
- dirty_blackheight = MAX(shake_pos,0) - MAX(old_shake_pos,0);
- dirty_blacktop = MAX(old_shake_pos,0);
+ dirty_height = MIN(shake_pos, 0) - MIN(old_shake_pos, 0);
+ dirty_top = -MIN(shake_pos, 0);
+ dirty_blackheight = MAX(shake_pos, 0) - MAX(old_shake_pos, 0);
+ dirty_blacktop = MAX(old_shake_pos, 0);
} else {
- dirty_height = MAX(old_shake_pos,0) - MAX(shake_pos, 0);
- dirty_top = 200 - MAX(old_shake_pos,0);
- dirty_blackheight = MIN(old_shake_pos,0) - MIN(shake_pos,0);
- dirty_blacktop = 200 + MIN(shake_pos,0);
+ dirty_height = MAX(old_shake_pos, 0) - MAX(shake_pos, 0);
+ dirty_top = 200 - MAX(old_shake_pos, 0);
+ dirty_blackheight = MIN(old_shake_pos, 0) - MIN(shake_pos, 0);
+ dirty_blacktop = 200 + MIN(shake_pos, 0);
}
/* Fill the dirty area with blackness or the scumm image */
{
- if (scale == 3)
- {
- SDL_Rect blackrect = {0, dirty_blacktop*3, 960, dirty_blackheight*3};
- SDL_FillRect(screen, &blackrect, 0);
- } else
- if (scale == 2)
- {
- SDL_Rect blackrect = {0, dirty_blacktop*2, 640, dirty_blackheight*2};
- SDL_FillRect(screen, &blackrect, 0);
- } else
- {
- SDL_Rect blackrect = {0, dirty_blacktop, 320, dirty_blackheight};
- SDL_FillRect(screen, &blackrect, 0);
- }
+ if (scale == 3) {
+ SDL_Rect blackrect =
+ { 0, dirty_blacktop * 3, 960, dirty_blackheight * 3 };
+ SDL_FillRect(screen, &blackrect, 0);
+ } else if (scale == 2) {
+ SDL_Rect blackrect =
+ { 0, dirty_blacktop * 2, 640, dirty_blackheight * 2 };
+ SDL_FillRect(screen, &blackrect, 0);
+ } else {
+ SDL_Rect blackrect = { 0, dirty_blacktop, 320, dirty_blackheight };
+ SDL_FillRect(screen, &blackrect, 0);
+ }
s->redrawLines(dirty_top, dirty_top + dirty_height);
}
@@ -317,7 +326,8 @@ void setShakePos(Scumm *s, int shake_pos) {
}
/* Copy part of bitmap */
-void blitToScreen(Scumm *s, byte *src,int x, int y, int w, int h) {
+void blitToScreen(Scumm *s, byte *src, int x, int y, int w, int h)
+{
byte *dst;
int i;
@@ -328,122 +338,130 @@ void blitToScreen(Scumm *s, byte *src,int x, int y, int w, int h) {
/* Account for the shaking and do Y clipping */
y += current_shake_pos;
- if (y < 0 ) { h += y; src -= y*320; y = 0; }
- if (h > 200 - y) { h = 200 - y; }
- if (h<=0) return;
+ if (y < 0) {
+ h += y;
+ src -= y * 320;
+ y = 0;
+ }
+ if (h > 200 - y) {
+ h = 200 - y;
+ }
+ if (h <= 0)
+ return;
- if (SDL_LockSurface(screen)==-1)
+ if (SDL_LockSurface(screen) == -1)
error("SDL_LockSurface failed: %s.\n", SDL_GetError());
- if (scale == 3)
- {
- dst = (byte*)screen->pixels + y*960*3 + x*3;
- addDirtyRect(x,y,w,h);
+ if (scale == 3) {
+ dst = (byte *)screen->pixels + y * 960 * 3 + x * 3;
+ addDirtyRect(x, y, w, h);
#ifdef DEBUG_CODE
- byte black = GetAsyncKeyState(VK_SHIFT)<0 ? 0 : 0xFF;
- do {
- i=0;
+ byte black = GetAsyncKeyState(VK_SHIFT) < 0 ? 0 : 0xFF;
do {
- dst[i*3] = dst[i*3+1] = dst[i*3+2] = src[i] & black;
- } while (++i!=w);
- memcpy(dst+960, dst, w*3);
- memcpy(dst+960+960, dst, w*3);
- dst += 960*3;
- src += 320;
- } while (--h);
+ i = 0;
+ do {
+ dst[i * 3] = dst[i * 3 + 1] = dst[i * 3 + 2] = src[i] & black;
+ } while (++i != w);
+ memcpy(dst + 960, dst, w * 3);
+ memcpy(dst + 960 + 960, dst, w * 3);
+ dst += 960 * 3;
+ src += 320;
+ } while (--h);
#else
- do {
- i=0;
do {
- dst[i*3] = dst[i*3+1] = dst[i*3+2] = src[i];
- } while (++i!=w);
- memcpy(dst+960, dst, w*3);
- memcpy(dst+960+960, dst, w*3);
- dst += 960*3;
- src += 320;
- } while (--h);
+ i = 0;
+ do {
+ dst[i * 3] = dst[i * 3 + 1] = dst[i * 3 + 2] = src[i];
+ } while (++i != w);
+ memcpy(dst + 960, dst, w * 3);
+ memcpy(dst + 960 + 960, dst, w * 3);
+ dst += 960 * 3;
+ src += 320;
+ } while (--h);
#endif
- } else
- if (scale == 2)
- {
- dst = (byte*)screen->pixels + y*640*2 + x*2;
- addDirtyRect(x,y,w,h);
+ } else if (scale == 2) {
+ dst = (byte *)screen->pixels + y * 640 * 2 + x * 2;
+ addDirtyRect(x, y, w, h);
#ifdef DEBUG_CODE
- byte black = GetAsyncKeyState(VK_SHIFT)<0 ? 0 : 0xFF;
- do {
- i=0;
+ byte black = GetAsyncKeyState(VK_SHIFT) < 0 ? 0 : 0xFF;
do {
- dst[i*2] = dst[i*2+1] = src[i] & black;
- } while (++i!=w);
- memcpy(dst+640, dst, w*2);
- dst += 640*2;
- src += 320;
- } while (--h);
+ i = 0;
+ do {
+ dst[i * 2] = dst[i * 2 + 1] = src[i] & black;
+ } while (++i != w);
+ memcpy(dst + 640, dst, w * 2);
+ dst += 640 * 2;
+ src += 320;
+ } while (--h);
#else
- do {
- i=0;
do {
- dst[i*2] = dst[i*2+1] = src[i];
- } while (++i!=w);
- memcpy(dst+640, dst, w*2);
- dst += 640*2;
- src += 320;
- } while (--h);
+ i = 0;
+ do {
+ dst[i * 2] = dst[i * 2 + 1] = src[i];
+ } while (++i != w);
+ memcpy(dst + 640, dst, w * 2);
+ dst += 640 * 2;
+ src += 320;
+ } while (--h);
#endif
- } else
- {
- dst = (byte*)screen->pixels + y*320 + x;
- addDirtyRect(x,y,w,h);
- do {
- memcpy(dst, src, w);
- dst += 320;
- src += 320;
- } while (--h);
+ } else {
+ dst = (byte *)screen->pixels + y * 320 + x;
+ addDirtyRect(x, y, w, h);
+ do {
+ memcpy(dst, src, w);
+ dst += 320;
+ src += 320;
+ } while (--h);
}
SDL_UnlockSurface(screen);
}
-void Draw2xSaI(SDL_Rect *r, int vidmode) {
+void Draw2xSaI(SDL_Rect * r, int vidmode)
+{
if (SDL_BlitSurface(screen, r, sdl_tmpscreen, r) != 0)
error("SDL_BlitSurface failed");
SDL_LockSurface(sdl_tmpscreen);
SDL_LockSurface(sdl_hwscreen);
- switch(vidmode) {
- case VIDEO_2XSAI:
- _2xSaI((byte*)sdl_tmpscreen->pixels + r->x*2 + r->y*640, 640, NULL,
- (byte*)sdl_hwscreen->pixels + r->x*4 + r->y*640*4, 640*2, r->w, r->h);
- break;
- case VIDEO_SUPERSAI:
- Super2xSaI((byte*)sdl_tmpscreen->pixels + r->x*2 + r->y*640, 640, NULL,
- (byte*)sdl_hwscreen->pixels + r->x*4 + r->y*640*4, 640*2, r->w, r->h);
- break;
- case VIDEO_SUPEREAGLE:
- SuperEagle((byte*)sdl_tmpscreen->pixels + r->x*2 + r->y*640, 640, NULL,
- (byte*)sdl_hwscreen->pixels + r->x*4 + r->y*640*4, 640*2, r->w, r->h);
- break;
- default:
- error("Unknown graphics mode %d", vidmode);
- break;
+ switch (vidmode) {
+ case VIDEO_2XSAI:
+ _2xSaI((byte *)sdl_tmpscreen->pixels + r->x * 2 + r->y * 640, 640, NULL,
+ (byte *)sdl_hwscreen->pixels + r->x * 4 + r->y * 640 * 4, 640 * 2,
+ r->w, r->h);
+ break;
+ case VIDEO_SUPERSAI:
+ Super2xSaI((byte *)sdl_tmpscreen->pixels + r->x * 2 + r->y * 640, 640,
+ NULL, (byte *)sdl_hwscreen->pixels + r->x * 4 + r->y * 640 * 4,
+ 640 * 2, r->w, r->h);
+ break;
+ case VIDEO_SUPEREAGLE:
+ SuperEagle((byte *)sdl_tmpscreen->pixels + r->x * 2 + r->y * 640, 640,
+ NULL, (byte *)sdl_hwscreen->pixels + r->x * 4 + r->y * 640 * 4,
+ 640 * 2, r->w, r->h);
+ break;
+ default:
+ error("Unknown graphics mode %d", vidmode);
+ break;
}
-
+
/* scale the rect to fit in SDL_UpdateRects */
r->x <<= 1;
r->y <<= 1;
r->w <<= 1;
r->h <<= 1;
-
+
SDL_UnlockSurface(sdl_tmpscreen);
SDL_UnlockSurface(sdl_hwscreen);
SDL_UpdateRect(sdl_hwscreen, r->x, r->y, r->w, r->h);
}
-void updateScreen2xSaI(Scumm *s) {
+void updateScreen2xSaI(Scumm *s)
+{
SDL_Rect r;
- if (s->_fastMode&2)
+ if (s->_fastMode & 2)
return;
if (hide_mouse) {
@@ -451,9 +469,9 @@ void updateScreen2xSaI(Scumm *s) {
s->drawMouse();
}
- if(s->_palDirtyMax != -1)
+ if (s->_palDirtyMax != -1)
updatePalette(s);
-
+
if (fullRedraw) {
r.x = 0;
r.y = 0;
@@ -466,7 +484,7 @@ void updateScreen2xSaI(Scumm *s) {
} else if (numDirtyRects) {
SDL_Rect *dr;
int i;
-
+
for (i = 0; i <= numDirtyRects; i++) {
dr = &dirtyRects[i];
Draw2xSaI(dr, s->_videoMode);
@@ -477,19 +495,21 @@ void updateScreen2xSaI(Scumm *s) {
}
-void updateScreenScale(Scumm *s) {
+void updateScreenScale(Scumm *s)
+{
if (fullRedraw) {
- SDL_UpdateRect(screen, 0,0,0,0);
+ SDL_UpdateRect(screen, 0, 0, 0, 0);
fullRedraw = false;
} else if (numDirtyRects) {
- SDL_UpdateRects(screen, numDirtyRects, dirtyRects);
+ SDL_UpdateRects(screen, numDirtyRects, dirtyRects);
}
numDirtyRects = 0;
}
-void updateScreen(Scumm *s) {
- if (s->_fastMode&2)
+void updateScreen(Scumm *s)
+{
+ if (s->_fastMode & 2)
return;
if (hide_mouse) {
@@ -497,157 +517,158 @@ void updateScreen(Scumm *s) {
s->drawMouse();
}
- if(s->_palDirtyMax != -1) {
+ if (s->_palDirtyMax != -1) {
updatePalette(s);
}
if (s->_videoMode == VIDEO_SCALE)
updateScreenScale(s);
else
- updateScreen2xSaI(s);
+ updateScreen2xSaI(s);
}
-void drawMouse(Scumm *s, int xdraw, int ydraw, int w, int h, byte *buf, bool visible) {
- int x,y;
- byte *dst,*bak;
+void drawMouse(Scumm *s, int xdraw, int ydraw, int w, int h, byte *buf,
+ bool visible)
+{
+ int x, y;
+ byte *dst, *bak;
byte color;
if (hide_mouse)
visible = false;
- assert(w<=BAK_WIDTH && h<=BAK_HEIGHT);
+ assert(w <= BAK_WIDTH && h <= BAK_HEIGHT);
- if (SDL_LockSurface(screen)==-1)
+ if (SDL_LockSurface(screen) == -1)
error("SDL_LockSurface failed: %s.\n", SDL_GetError());
- if (scale == 3)
- {
-
- if (has_mouse) {
- dst = (byte*)screen->pixels + old_mouse_y*960*3 + old_mouse_x*3;
- bak = old_backup;
-
- for (y=0; y<old_mouse_h; y++,bak+=BAK_WIDTH*3,dst+=960*3) {
- if ( (uint)(old_mouse_y + y) < 200) {
- for (x=0; x<old_mouse_w; x++) {
- if ((uint)(old_mouse_x + x) < 320) {
- dst[x*3+960] = dst[x*3+960+960] = dst[x*3] = bak[x*3];
- dst[x*3+960+1] = dst[x*3+960+960+1] = dst[x*3+1] = bak[x*3+1];
- dst[x*3+960+2] = dst[x*3+960+960+2] = dst[x*3+2] = bak[x*3+2];
+ if (scale == 3) {
+
+ if (has_mouse) {
+ dst = (byte *)screen->pixels + old_mouse_y * 960 * 3 + old_mouse_x * 3;
+ bak = old_backup;
+
+ for (y = 0; y < old_mouse_h; y++, bak += BAK_WIDTH * 3, dst += 960 * 3) {
+ if ((uint) (old_mouse_y + y) < 200) {
+ for (x = 0; x < old_mouse_w; x++) {
+ if ((uint) (old_mouse_x + x) < 320) {
+ dst[x * 3 + 960] = dst[x * 3 + 960 + 960] = dst[x * 3] =
+ bak[x * 3];
+ dst[x * 3 + 960 + 1] = dst[x * 3 + 960 + 960 + 1] =
+ dst[x * 3 + 1] = bak[x * 3 + 1];
+ dst[x * 3 + 960 + 2] = dst[x * 3 + 960 + 960 + 2] =
+ dst[x * 3 + 2] = bak[x * 3 + 2];
+ }
}
}
}
}
- }
- if (visible) {
- ydraw += current_shake_pos;
-
- dst = (byte*)screen->pixels + ydraw*960*3 + xdraw*3;
- bak = old_backup;
-
- for (y=0; y<h; y++,dst+=960*3,bak+=BAK_WIDTH*3,buf+=w) {
- if ((uint)(ydraw+y)<200) {
- for (x=0; x<w; x++) {
- if ((uint)(xdraw+x)<320) {
- bak[x*3] = dst[x*3];
- bak[x*3+1] = dst[x*3+1];
- bak[x*3+2] = dst[x*3+2];
- if ((color=buf[x])!=0xFF) {
- dst[x*3] = color;
- dst[x*3+1] = color;
- dst[x*3+2] = color;
- dst[x*3+960] = color;
- dst[x*3+1+960] = color;
- dst[x*3+2+960] = color;
- dst[x*3+960+960] = color;
- dst[x*3+1+960+960] = color;
- dst[x*3+2+960+960] = color;
+ if (visible) {
+ ydraw += current_shake_pos;
+
+ dst = (byte *)screen->pixels + ydraw * 960 * 3 + xdraw * 3;
+ bak = old_backup;
+
+ for (y = 0; y < h; y++, dst += 960 * 3, bak += BAK_WIDTH * 3, buf += w) {
+ if ((uint) (ydraw + y) < 200) {
+ for (x = 0; x < w; x++) {
+ if ((uint) (xdraw + x) < 320) {
+ bak[x * 3] = dst[x * 3];
+ bak[x * 3 + 1] = dst[x * 3 + 1];
+ bak[x * 3 + 2] = dst[x * 3 + 2];
+ if ((color = buf[x]) != 0xFF) {
+ dst[x * 3] = color;
+ dst[x * 3 + 1] = color;
+ dst[x * 3 + 2] = color;
+ dst[x * 3 + 960] = color;
+ dst[x * 3 + 1 + 960] = color;
+ dst[x * 3 + 2 + 960] = color;
+ dst[x * 3 + 960 + 960] = color;
+ dst[x * 3 + 1 + 960 + 960] = color;
+ dst[x * 3 + 2 + 960 + 960] = color;
+ }
}
}
}
}
}
- }
- } else
- if (scale == 2)
- {
-
- if (has_mouse) {
- dst = (byte*)screen->pixels + old_mouse_y*640*2 + old_mouse_x*2;
- bak = old_backup;
-
- for (y=0; y<old_mouse_h; y++,bak+=BAK_WIDTH*2,dst+=640*2) {
- if ( (uint)(old_mouse_y + y) < 200) {
- for (x=0; x<old_mouse_w; x++) {
- if ((uint)(old_mouse_x + x) < 320) {
- dst[x*2+640] = dst[x*2] = bak[x*2];
- dst[x*2+640+1] = dst[x*2+1] = bak[x*2+1];
+ } else if (scale == 2) {
+
+ if (has_mouse) {
+ dst = (byte *)screen->pixels + old_mouse_y * 640 * 2 + old_mouse_x * 2;
+ bak = old_backup;
+
+ for (y = 0; y < old_mouse_h; y++, bak += BAK_WIDTH * 2, dst += 640 * 2) {
+ if ((uint) (old_mouse_y + y) < 200) {
+ for (x = 0; x < old_mouse_w; x++) {
+ if ((uint) (old_mouse_x + x) < 320) {
+ dst[x * 2 + 640] = dst[x * 2] = bak[x * 2];
+ dst[x * 2 + 640 + 1] = dst[x * 2 + 1] = bak[x * 2 + 1];
+ }
}
}
}
}
- }
- if (visible) {
- ydraw += current_shake_pos;
-
- dst = (byte*)screen->pixels + ydraw*640*2 + xdraw*2;
- bak = old_backup;
-
- for (y=0; y<h; y++,dst+=640*2,bak+=BAK_WIDTH*2,buf+=w) {
- if ((uint)(ydraw+y)<200) {
- for (x=0; x<w; x++) {
- if ((uint)(xdraw+x)<320) {
- bak[x*2] = dst[x*2];
- bak[x*2+1] = dst[x*2+1];
- if ((color=buf[x])!=0xFF) {
- dst[x*2] = color;
- dst[x*2+1] = color;
- dst[x*2+640] = color;
- dst[x*2+1+640] = color;
+ if (visible) {
+ ydraw += current_shake_pos;
+
+ dst = (byte *)screen->pixels + ydraw * 640 * 2 + xdraw * 2;
+ bak = old_backup;
+
+ for (y = 0; y < h; y++, dst += 640 * 2, bak += BAK_WIDTH * 2, buf += w) {
+ if ((uint) (ydraw + y) < 200) {
+ for (x = 0; x < w; x++) {
+ if ((uint) (xdraw + x) < 320) {
+ bak[x * 2] = dst[x * 2];
+ bak[x * 2 + 1] = dst[x * 2 + 1];
+ if ((color = buf[x]) != 0xFF) {
+ dst[x * 2] = color;
+ dst[x * 2 + 1] = color;
+ dst[x * 2 + 640] = color;
+ dst[x * 2 + 1 + 640] = color;
+ }
}
}
}
}
}
- }
- } else
- {
- if (has_mouse) {
- dst = (byte*)screen->pixels + old_mouse_y*320 + old_mouse_x;
- bak = old_backup;
-
- for (y=0; y<old_mouse_h; y++,bak+=BAK_WIDTH,dst+=320) {
- if ( (uint)(old_mouse_y + y) < 200) {
- for (x=0; x<old_mouse_w; x++) {
- if ((uint)(old_mouse_x + x) < 320) {
- dst[x] = bak[x];
+ } else {
+ if (has_mouse) {
+ dst = (byte *)screen->pixels + old_mouse_y * 320 + old_mouse_x;
+ bak = old_backup;
+
+ for (y = 0; y < old_mouse_h; y++, bak += BAK_WIDTH, dst += 320) {
+ if ((uint) (old_mouse_y + y) < 200) {
+ for (x = 0; x < old_mouse_w; x++) {
+ if ((uint) (old_mouse_x + x) < 320) {
+ dst[x] = bak[x];
+ }
}
}
}
}
- }
- if (visible) {
- ydraw += current_shake_pos;
-
- dst = (byte*)screen->pixels + ydraw*320 + xdraw;
- bak = old_backup;
-
- for (y=0; y<h; y++,dst+=320,bak+=BAK_WIDTH,buf+=w) {
- if ((uint)(ydraw+y)<200) {
- for (x=0; x<w; x++) {
- if ((uint)(xdraw+x)<320) {
- bak[x] = dst[x];
- if ((color=buf[x])!=0xFF) {
- dst[x] = color;
+ if (visible) {
+ ydraw += current_shake_pos;
+
+ dst = (byte *)screen->pixels + ydraw * 320 + xdraw;
+ bak = old_backup;
+
+ for (y = 0; y < h; y++, dst += 320, bak += BAK_WIDTH, buf += w) {
+ if ((uint) (ydraw + y) < 200) {
+ for (x = 0; x < w; x++) {
+ if ((uint) (xdraw + x) < 320) {
+ bak[x] = dst[x];
+ if ((color = buf[x]) != 0xFF) {
+ dst[x] = color;
+ }
}
}
}
}
}
}
- }
SDL_UnlockSurface(screen);
@@ -666,8 +687,9 @@ void drawMouse(Scumm *s, int xdraw, int ydraw, int w, int h, byte *buf, bool vis
}
}
-void fill_sound(void *userdata, Uint8 *stream, int len) {
- scumm->mixWaves((int16*)stream, len>>1);
+void fill_sound(void *userdata, Uint8 * stream, int len)
+{
+ scumm->mixWaves((int16 *) stream, len >> 1);
}
static int cd_track, cd_num_loops = 0, cd_start_frame, cd_end_frame;
@@ -677,7 +699,9 @@ static int cd_track, cd_num_loops = 0, cd_start_frame, cd_end_frame;
// time the track is expected to be finished.
static Uint32 cd_end_time, cd_stop_time, cd_next_second;
-void cd_play(Scumm *s, int track, int num_loops, int start_frame, int end_frame) {
+void cd_play(Scumm *s, int track, int num_loops, int start_frame,
+ int end_frame)
+{
scumm->_vars[14] = 0;
@@ -692,120 +716,130 @@ void cd_play(Scumm *s, int track, int num_loops, int start_frame, int end_frame)
#endif
// warning("cd_play(%d,%d,%d,%d)", track, num_loops, start_frame, end_frame);
- if (!cdrom) return;
+ if (!cdrom)
+ return;
cd_track = track;
cd_num_loops = num_loops;
cd_start_frame = start_frame;
-
+
SDL_CDStatus(cdrom);
SDL_CDPlayTracks(cdrom, track, start_frame, 0, end_frame);
cd_end_frame = end_frame;
cd_stop_time = 0;
- cd_end_time = SDL_GetTicks() +
- cdrom->track[track].length * 1000 / CD_FPS;
+ cd_end_time = SDL_GetTicks() + cdrom->track[track].length * 1000 / CD_FPS;
}
// Schedule the music to be stopped after 1/10 sec, unless another
// track is started in the meantime. (On my machine, stopping and
// then restarting the CD takes a few seconds.)
-void cd_stop() {
+void cd_stop()
+{
cd_stop_time = SDL_GetTicks() + 100;
cd_num_loops = 0;
}
-int cd_is_running() {
- if (!cdrom) return 0;
+int cd_is_running()
+{
+ if (!cdrom)
+ return 0;
return (cd_num_loops != 0 && (SDL_GetTicks() < cd_end_time ||
- SDL_CDStatus(cdrom) != CD_STOPPED));
+ SDL_CDStatus(cdrom) != CD_STOPPED));
}
-static void cd_shutdown() {
- if (!cdrom) return;
+static void cd_shutdown()
+{
+ if (!cdrom)
+ return;
if (cd_num_loops != 0)
SDL_CDStop(cdrom);
}
-void cd_music_loop() {
- if (!cdrom) return;
+void cd_music_loop()
+{
+ if (!cdrom)
+ return;
/* if (SDL_GetTicks() >= cd_next_second) {
/ printf("%d started at %d, fps\n", scumm._vars[14], cd_start_frame, CD_FPS);
//scumm._vars[14]++; //varmusicflag
cd_next_second = SDL_GetTicks() + 1;
} */
-
+
if (cd_stop_time != 0 && SDL_GetTicks() >= cd_stop_time) {
SDL_CDStop(cdrom);
cd_num_loops = 0;
cd_stop_time = 0;
return;
}
-
+
if (cd_num_loops == 0 || SDL_GetTicks() < cd_end_time)
return;
-
+
if (cd_num_loops != 1 && SDL_CDStatus(cdrom) != CD_STOPPED) {
// Wait another second for it to be done
cd_end_time += 1000;
return;
}
-
+
if (cd_num_loops > 0)
cd_num_loops--;
if (cd_num_loops != 0) {
SDL_CDPlayTracks(cdrom, cd_track, cd_start_frame, 0, cd_end_frame);
- cd_end_time = SDL_GetTicks() + cdrom->track[cd_track].length * 1000 / CD_FPS;
+ cd_end_time =
+ SDL_GetTicks() + cdrom->track[cd_track].length * 1000 / CD_FPS;
}
}
-int music_thread(Scumm *s) {
+int music_thread(Scumm *s)
+{
int old_time, cur_time;
old_time = SDL_GetTicks();
do {
SDL_Delay(10);
-
+
cur_time = SDL_GetTicks();
while (old_time < cur_time) {
old_time += 10;
- sound.on_timer();
+ sound.on_timer();
}
} while (1);
-
+
return 0;
}
-void initGraphics(Scumm *s, bool fullScreen, unsigned int scaleFactor) {
+void initGraphics(Scumm *s, bool fullScreen, unsigned int scaleFactor)
+{
SDL_AudioSpec desired;
scale = scaleFactor;
- if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO)==-1) {
+ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) == -1) {
error("Could not initialize SDL: %s.\n", SDL_GetError());
- exit(1);
+ exit(1);
}
- if (SDL_InitSubSystem(SDL_INIT_CDROM) == -1)
- cdrom = NULL;
- else {
- cdrom = SDL_CDOpen(s->_cdrom);
+ if (SDL_InitSubSystem(SDL_INIT_CDROM) == -1)
+ cdrom = NULL;
+ else {
+ cdrom = SDL_CDOpen(s->_cdrom);
/* Did if open? Check if cdrom is NULL */
- if(!cdrom){
+ if (!cdrom) {
warning("Couldn't open drive: %s\n", SDL_GetError());
}
}
/* Clean up on exit */
- atexit(SDL_Quit);
+ atexit(SDL_Quit);
atexit(cd_shutdown);
atexit(resetCursor);
char buf[512], *gameName;
-
+
sprintf(buf, "ScummVM - %s", gameName = detector.getGameName());
free(gameName);
@@ -817,7 +851,7 @@ void initGraphics(Scumm *s, bool fullScreen, unsigned int scaleFactor) {
SDL_OpenAudio(&desired, NULL);
SDL_PauseAudio(0);
- SDL_WM_SetCaption(buf,buf);
+ SDL_WM_SetCaption(buf, buf);
SDL_ShowCursor(SDL_DISABLE);
if (!snd_driv.wave_based()) {
@@ -826,51 +860,59 @@ void initGraphics(Scumm *s, bool fullScreen, unsigned int scaleFactor) {
}
if (s->_videoMode == VIDEO_SCALE) {
- screen = SDL_SetVideoMode(320 * scale, 200 * scale, 8, fullScreen ? (SDL_SWSURFACE | SDL_FULLSCREEN) : (SDL_SWSURFACE | SDL_DOUBLEBUF));
+ screen =
+ SDL_SetVideoMode(320 * scale, 200 * scale, 8,
+ fullScreen ? (SDL_SWSURFACE | SDL_FULLSCREEN)
+ : (SDL_SWSURFACE | SDL_DOUBLEBUF));
} else {
- uint16 *tmp_screen = (uint16*)calloc(320*202 + 8,sizeof(uint16));
+ uint16 *tmp_screen = (uint16 *)calloc(320 * 202 + 8, sizeof(uint16));
Init_2xSaI(565);
screen = SDL_CreateRGBSurface(SDL_SWSURFACE, 320, 200, 8, 0, 0, 0, 0);
- sdl_hwscreen = SDL_SetVideoMode(640, 400, 16, fullScreen ? (SDL_SWSURFACE | SDL_FULLSCREEN) : (SDL_SWSURFACE | SDL_DOUBLEBUF));
- sdl_tmpscreen = SDL_CreateRGBSurfaceFrom(tmp_screen + 320 + 4, 320, 200, 16, 320*2, 0,0,0,0);
+ sdl_hwscreen =
+ SDL_SetVideoMode(640, 400, 16,
+ fullScreen ? (SDL_SWSURFACE | SDL_FULLSCREEN)
+ : (SDL_SWSURFACE | SDL_DOUBLEBUF));
+ sdl_tmpscreen =
+ SDL_CreateRGBSurfaceFrom(tmp_screen + 320 + 4, 320, 200, 16, 320 * 2, 0,
+ 0, 0, 0);
if (sdl_tmpscreen == NULL)
error("sdl_tmpscreen failed");
scale = 1;
}
-// SDL_SWSURFACE 0x00000000 /* Surface is in system memory */
-// SDL_HWSURFACE 0x00000001 /* Surface is in video memory */
-// SDL_ASYNCBLIT 0x00000004 /* Use asynchronous blits if possible */
-// SDL_ANYFORMAT 0x10000000 /* Allow any video depth/pixel-format */
-// SDL_HWPALETTE 0x20000000 /* Surface has exclusive palette */
-// SDL_DOUBLEBUF 0x40000000 /* Set up double-buffered video mode */
-// SDL_FULLSCREEN 0x80000000 /* Surface is a full screen display */
-// SDL_OPENGL 0x00000002 /* Create an OpenGL rendering context */
-// SDL_OPENGLBLIT 0x0000000A /* Create an OpenGL rendering context and use it for blitting */
-// SDL_RESIZABLE 0x00000010 /* This video mode may be resized */
-// SDL_NOFRAME 0x00000020 /* No window caption or edge frame */
-
-
-
- printf("%d %d, %d %d, %d %d %d, %d %d %d %d %d\n",
- sizeof(int8), sizeof(uint8),
- sizeof(int16), sizeof(uint16),
- sizeof(int32), sizeof(uint32),
- sizeof(void*),
- sizeof(Box), sizeof(MouseCursor),sizeof(CodeHeader),
- sizeof(ImageHeader),
- sizeof(Scumm)
- );
+// SDL_SWSURFACE 0x00000000 /* Surface is in system memory */
+// SDL_HWSURFACE 0x00000001 /* Surface is in video memory */
+// SDL_ASYNCBLIT 0x00000004 /* Use asynchronous blits if possible */
+// SDL_ANYFORMAT 0x10000000 /* Allow any video depth/pixel-format */
+// SDL_HWPALETTE 0x20000000 /* Surface has exclusive palette */
+// SDL_DOUBLEBUF 0x40000000 /* Set up double-buffered video mode */
+// SDL_FULLSCREEN 0x80000000 /* Surface is a full screen display */
+// SDL_OPENGL 0x00000002 /* Create an OpenGL rendering context */
+// SDL_OPENGLBLIT 0x0000000A /* Create an OpenGL rendering context and use it for blitting */
+// SDL_RESIZABLE 0x00000010 /* This video mode may be resized */
+// SDL_NOFRAME 0x00000020 /* No window caption or edge frame */
+
+
+
+ printf("%d %d, %d %d, %d %d %d, %d %d %d %d %d\n",
+ sizeof(int8), sizeof(uint8),
+ sizeof(int16), sizeof(uint16),
+ sizeof(int32), sizeof(uint32),
+ sizeof(void *),
+ sizeof(Box), sizeof(MouseCursor), sizeof(CodeHeader),
+ sizeof(ImageHeader), sizeof(Scumm)
+ );
}
-void setWindowName(Scumm *s) {
- char buf[512], *gameName;
-
- sprintf(buf, "ScummVM - %s", gameName = detector.getGameName());
- free(gameName);
- SDL_WM_SetCaption(buf,buf);
+void setWindowName(Scumm *s)
+{
+ char buf[512], *gameName;
+
+ sprintf(buf, "ScummVM - %s", gameName = detector.getGameName());
+ free(gameName);
+ SDL_WM_SetCaption(buf, buf);
}
#if !defined(__APPLE__)
@@ -878,7 +920,8 @@ void setWindowName(Scumm *s) {
#endif
-void launcherLoop() {
+void launcherLoop()
+{
int last_time, new_time;
int delta = 0;
last_time = SDL_GetTicks();
@@ -896,59 +939,57 @@ void launcherLoop() {
delta = 5;
} else
error("gui closed!");
- } while(1);
+ } while (1);
};
-int main(int argc, char* argv[]) {
-#if defined(MACOS)
+int main(int argc, char *argv[])
+{
+#if defined(MACOS)
/* support for config file on macos */
-
+
char *argitem;
char *argstr;
FILE *argf;
-
- if (( argf = fopen("configuration.macos", "r")) == NULL) {
+
+ if ((argf = fopen("configuration.macos", "r")) == NULL) {
error("Can't open configuration file.\n");
exit(1);
}
-
- argc=0;
- argstr = (char *) malloc(64);
+
+ argc = 0;
+ argstr = (char *)malloc(64);
argstr = fgets(argstr, 64, argf);
- if ((argitem = strchr(argstr, '\n'))!=NULL)
+ if ((argitem = strchr(argstr, '\n')) != NULL)
*argitem = '\0';
-
+
argitem = strtok(argstr, " ");
-
- while (argitem!=NULL) {
- argv = (char**) realloc(argv, (argc+1)*8);
- argv[argc] = (char *) malloc(64);
+
+ while (argitem != NULL) {
+ argv = (char **)realloc(argv, (argc + 1) * 8);
+ argv[argc] = (char *)malloc(64);
strcpy(argv[argc], argitem);
- argc++;
-
+ argc++;
+
argitem = strtok(NULL, " ");
}
-
+
free(argstr);
fclose(argf);
-
+
#endif
- if(detector.detectMain(argc, argv))
- return(-1);
+ if (detector.detectMain(argc, argv))
+ return (-1);
- if(detector._features & GF_OLD256)
+ if (detector._features & GF_OLD256)
scumm = new Scumm_v3;
- else
- if(detector._features & GF_SMALL_HEADER) // this force loomCD as v4
+ else if (detector._features & GF_SMALL_HEADER) // this force loomCD as v4
scumm = new Scumm_v4;
- else
- if(detector._features & GF_AFTER_V7)
+ else if (detector._features & GF_AFTER_V7)
scumm = new Scumm_v7;
- else
- if(detector._features & GF_AFTER_V6) // this force SamnmaxCD as v6
+ else if (detector._features & GF_AFTER_V6) // this force SamnmaxCD as v6
scumm = new Scumm_v6;
else
scumm = new Scumm_v5;
@@ -970,7 +1011,7 @@ int main(int argc, char* argv[]) {
scumm->_midi_driver = detector._midi_driver;
scumm->_cdrom = detector._cdrom;
- scumm->delta=6;
+ scumm->delta = 6;
if (detector._restore) {
scumm->_saveLoadSlot = 0;
scumm->_saveLoadFlag = 2;
@@ -978,135 +1019,144 @@ int main(int argc, char* argv[]) {
}
scumm->_gui = &gui;
-// gui.init(scumm);
+// gui.init(scumm);
sound.initialize(scumm, &snd_driv);
-
- scumm->delta=0;
+
+ scumm->delta = 0;
scumm->_system = &_system;
- _system.last_time=0;
+ _system.last_time = 0;
scumm->launch();
-// scumm->runScript(1,0,0,&scumm->_bootParam);
-
-// scumm->scummMain(argc, argv); // Todo: need to change that as well
-
- gui.init(scumm); /* Reinit GUI after loading a game */
+// scumm->runScript(1,0,0,&scumm->_bootParam);
+
+// scumm->scummMain(argc, argv); // Todo: need to change that as well
+
+ gui.init(scumm); /* Reinit GUI after loading a game */
scumm->mainRun();
return 0;
}
/************ ENDER: Temporary debug code for boxen **************/
-int hlineColor (SDL_Surface *dst, Sint16 x1, Sint16 x2, Sint16 y, Uint32 color) {
- Sint16 left,right,top,bottom;
- Uint8 *pixel,*pixellast;
- int dx;
- int pixx, pixy;
- Sint16 w;
- Sint16 xtmp;
- int result=-1;
- Uint8 *colorptr;
-
- /* Get clipping boundary */
- left = dst->clip_rect.x;
- right = dst->clip_rect.x+dst->clip_rect.w-1;
- top = dst->clip_rect.y;
- bottom = dst->clip_rect.y+dst->clip_rect.h-1;
-
- /* Swap x1, x2 if required */
- if (x1>x2) {
- xtmp=x1; x1=x2; x2=xtmp;
- }
-
- /* Visible */
- if ((x1>right) || (x2<left) || (y<top) || (y>bottom)) {
- return(0);
- }
-
- /* Clip x */
- if (x1<left) {
- x1=left;
- }
- if (x2>right) {
- x2=right;
- }
-
- /* Calculate width */
- w=x2-x1;
-
- /* Sanity check on width */
- if (w<0) {
- return(0);
- }
-
- /* Setup color */
- colorptr=(Uint8 *)&color;
- if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
- color=SDL_MapRGBA(dst->format, colorptr[0], colorptr[1], colorptr[2], colorptr[3]);
- } else {
- color=SDL_MapRGBA(dst->format, colorptr[3], colorptr[2], colorptr[1], colorptr[0]);
- }
-
- /* Lock surface */
- SDL_LockSurface(dst);
-
- /* More variable setup */
- dx=w;
- pixx = dst->format->BytesPerPixel;
- pixy = dst->pitch;
- pixel = ((Uint8*)dst->pixels) + pixx * (int)x1 + pixy * (int)y;
-
- /* Draw */
- switch(dst->format->BytesPerPixel) {
- case 1:
- memset (pixel, color, dx);
- break;
- case 2:
- pixellast = pixel + dx + dx;
- for (; pixel<=pixellast; pixel += pixx) {
- *(Uint16*)pixel = color;
- }
- break;
- case 3:
- pixellast = pixel + dx + dx + dx;
- for (; pixel<=pixellast; pixel += pixx) {
- if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
- pixel[0] = (color >> 16) & 0xff;
- pixel[1] = (color >> 8) & 0xff;
- pixel[2] = color & 0xff;
- } else {
- pixel[0] = color & 0xff;
- pixel[1] = (color >> 8) & 0xff;
- pixel[2] = (color >> 16) & 0xff;
- }
- }
- break;
- default: /* case 4*/
- dx = dx + dx;
- pixellast = pixel + dx + dx;
- for (; pixel<=pixellast; pixel += pixx) {
- *(Uint32*)pixel = color;
- }
- break;
- }
-
- /* Unlock surface */
- SDL_UnlockSurface(dst);
-
- /* Set result code */
- result=0;
-
- return(result);
+int hlineColor(SDL_Surface * dst, Sint16 x1, Sint16 x2, Sint16 y,
+ Uint32 color)
+{
+ Sint16 left, right, top, bottom;
+ Uint8 *pixel, *pixellast;
+ int dx;
+ int pixx, pixy;
+ Sint16 w;
+ Sint16 xtmp;
+ int result = -1;
+ Uint8 *colorptr;
+
+ /* Get clipping boundary */
+ left = dst->clip_rect.x;
+ right = dst->clip_rect.x + dst->clip_rect.w - 1;
+ top = dst->clip_rect.y;
+ bottom = dst->clip_rect.y + dst->clip_rect.h - 1;
+
+ /* Swap x1, x2 if required */
+ if (x1 > x2) {
+ xtmp = x1;
+ x1 = x2;
+ x2 = xtmp;
+ }
+
+ /* Visible */
+ if ((x1 > right) || (x2 < left) || (y < top) || (y > bottom)) {
+ return (0);
+ }
+
+ /* Clip x */
+ if (x1 < left) {
+ x1 = left;
+ }
+ if (x2 > right) {
+ x2 = right;
+ }
+
+ /* Calculate width */
+ w = x2 - x1;
+
+ /* Sanity check on width */
+ if (w < 0) {
+ return (0);
+ }
+
+ /* Setup color */
+ colorptr = (Uint8 *) & color;
+ if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
+ color =
+ SDL_MapRGBA(dst->format, colorptr[0], colorptr[1], colorptr[2],
+ colorptr[3]);
+ } else {
+ color =
+ SDL_MapRGBA(dst->format, colorptr[3], colorptr[2], colorptr[1],
+ colorptr[0]);
+ }
+
+ /* Lock surface */
+ SDL_LockSurface(dst);
+
+ /* More variable setup */
+ dx = w;
+ pixx = dst->format->BytesPerPixel;
+ pixy = dst->pitch;
+ pixel = ((Uint8 *) dst->pixels) + pixx * (int)x1 + pixy * (int)y;
+
+ /* Draw */
+ switch (dst->format->BytesPerPixel) {
+ case 1:
+ memset(pixel, color, dx);
+ break;
+ case 2:
+ pixellast = pixel + dx + dx;
+ for (; pixel <= pixellast; pixel += pixx) {
+ *(Uint16 *) pixel = color;
+ }
+ break;
+ case 3:
+ pixellast = pixel + dx + dx + dx;
+ for (; pixel <= pixellast; pixel += pixx) {
+ if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
+ pixel[0] = (color >> 16) & 0xff;
+ pixel[1] = (color >> 8) & 0xff;
+ pixel[2] = color & 0xff;
+ } else {
+ pixel[0] = color & 0xff;
+ pixel[1] = (color >> 8) & 0xff;
+ pixel[2] = (color >> 16) & 0xff;
+ }
+ }
+ break;
+ default: /* case 4 */
+ dx = dx + dx;
+ pixellast = pixel + dx + dx;
+ for (; pixel <= pixellast; pixel += pixx) {
+ *(Uint32 *) pixel = color;
+ }
+ break;
+ }
+
+ /* Unlock surface */
+ SDL_UnlockSurface(dst);
+
+ /* Set result code */
+ result = 0;
+
+ return (result);
}
int gfxPrimitivesCompareInt(const void *a, const void *b);
-static int *gfxPrimitivesPolyInts=NULL;
-static int gfxPrimitivesPolyAllocated=0;
+static int *gfxPrimitivesPolyInts = NULL;
+static int gfxPrimitivesPolyAllocated = 0;
-int filledPolygonColor (SDL_Surface *dst, Sint16 *vx, Sint16 *vy, int n, int color)
+int filledPolygonColor(SDL_Surface * dst, Sint16 * vx, Sint16 * vy, int n,
+ int color)
{
int result;
int i;
@@ -1116,44 +1166,45 @@ int filledPolygonColor (SDL_Surface *dst, Sint16 *vx, Sint16 *vy, int n, int col
int x2, y2;
int ind1, ind2;
int ints;
-
+
/* Sanity check */
- if (n<3) {
- return -1;
+ if (n < 3) {
+ return -1;
}
-
+
/* Allocate temp array, only grow array */
if (!gfxPrimitivesPolyAllocated) {
- gfxPrimitivesPolyInts = (int *) malloc(sizeof(int) * n);
- gfxPrimitivesPolyAllocated = n;
+ gfxPrimitivesPolyInts = (int *)malloc(sizeof(int) * n);
+ gfxPrimitivesPolyAllocated = n;
} else {
- if (gfxPrimitivesPolyAllocated<n) {
- gfxPrimitivesPolyInts = (int *) realloc(gfxPrimitivesPolyInts, sizeof(int) * n);
- gfxPrimitivesPolyAllocated = n;
- }
- }
+ if (gfxPrimitivesPolyAllocated < n) {
+ gfxPrimitivesPolyInts =
+ (int *)realloc(gfxPrimitivesPolyInts, sizeof(int) * n);
+ gfxPrimitivesPolyAllocated = n;
+ }
+ }
/* Determine Y maxima */
miny = vy[0];
maxy = vy[0];
- for (i=1; (i < n); i++) {
+ for (i = 1; (i < n); i++) {
if (vy[i] < miny) {
- miny = vy[i];
+ miny = vy[i];
} else if (vy[i] > maxy) {
- maxy = vy[i];
+ maxy = vy[i];
}
}
-
+
/* Draw, scanning y */
- result=0;
- for (y=miny; (y <= maxy); y++) {
+ result = 0;
+ for (y = miny; (y <= maxy); y++) {
ints = 0;
- for (i=0; (i < n); i++) {
+ for (i = 0; (i < n); i++) {
if (!i) {
- ind1 = n-1;
+ ind1 = n - 1;
ind2 = 0;
} else {
- ind1 = i-1;
+ ind1 = i - 1;
ind2 = i;
}
y1 = vy[ind1];
@@ -1170,39 +1221,46 @@ int filledPolygonColor (SDL_Surface *dst, Sint16 *vx, Sint16 *vy, int n, int col
continue;
}
if ((y >= y1) && (y < y2)) {
- gfxPrimitivesPolyInts[ints++] = (y-y1) * (x2-x1) / (y2-y1) + x1;
+ gfxPrimitivesPolyInts[ints++] = (y - y1) * (x2 - x1) / (y2 - y1) + x1;
} else if ((y == maxy) && (y > y1) && (y <= y2)) {
- gfxPrimitivesPolyInts[ints++] = (y-y1) * (x2-x1) / (y2-y1) + x1;
+ gfxPrimitivesPolyInts[ints++] = (y - y1) * (x2 - x1) / (y2 - y1) + x1;
}
}
qsort(gfxPrimitivesPolyInts, ints, sizeof(int), gfxPrimitivesCompareInt);
- for (i=0; (i<ints); i+=2) {
- result |= hlineColor(dst, gfxPrimitivesPolyInts[i], gfxPrimitivesPolyInts[i+1], y, color);
+ for (i = 0; (i < ints); i += 2) {
+ result |=
+ hlineColor(dst, gfxPrimitivesPolyInts[i],
+ gfxPrimitivesPolyInts[i + 1], y, color);
}
}
-
- return (result);
+
+ return (result);
}
int gfxPrimitivesCompareInt(const void *a, const void *b)
{
- return (*(const int *)a) - (*(const int *)b);
+ return (*(const int *)a) - (*(const int *)b);
}
-void BoxTest(int num) {
+void BoxTest(int num)
+{
BoxCoords box;
Sint16 rx1[4], ry1[4];
-
- scumm->getBoxCoordinates(num, &box);
- rx1[0] = box.ul.x*2; ry1[0] = box.ul.y*2+32;
- rx1[1] = box.ur.x*2; ry1[1] = box.ur.y*2+32;
- rx1[2] = box.ll.x*2; ry1[2] = box.ll.y*2+32;
- rx1[3] = box.lr.x*2; ry1[3] = box.lr.y*2+32;
-
+
+ scumm->getBoxCoordinates(num, &box);
+ rx1[0] = box.ul.x * 2;
+ ry1[0] = box.ul.y * 2 + 32;
+ rx1[1] = box.ur.x * 2;
+ ry1[1] = box.ur.y * 2 + 32;
+ rx1[2] = box.ll.x * 2;
+ ry1[2] = box.ll.y * 2 + 32;
+ rx1[3] = box.lr.x * 2;
+ ry1[3] = box.lr.y * 2 + 32;
+
filledPolygonColor(screen, &rx1[0], &ry1[0], 4, 255);
- SDL_UpdateRect(screen, 0,0,0,0);
-
+ SDL_UpdateRect(screen, 0, 0, 0, 0);
+
}
@@ -1216,120 +1274,113 @@ static uint32 qlowpixelMask = 0x18631863;
static uint32 redblueMask = 0xF81F;
static uint32 greenMask = 0x7E0;
-int Init_2xSaI (uint32 BitFormat)
+int Init_2xSaI(uint32 BitFormat)
{
- if (BitFormat == 565)
- {
- colorMask = 0xF7DEF7DE;
- lowPixelMask = 0x08210821;
- qcolorMask = 0xE79CE79C;
- qlowpixelMask = 0x18631863;
- redblueMask = 0xF81F;
- greenMask = 0x7E0;
- }
- else if (BitFormat == 555)
- {
- colorMask = 0x7BDE7BDE;
- lowPixelMask = 0x04210421;
- qcolorMask = 0x739C739C;
- qlowpixelMask = 0x0C630C63;
- redblueMask = 0x7C1F;
- greenMask = 0x3E0;
- }
- else
- {
- return 0;
- }
+ if (BitFormat == 565) {
+ colorMask = 0xF7DEF7DE;
+ lowPixelMask = 0x08210821;
+ qcolorMask = 0xE79CE79C;
+ qlowpixelMask = 0x18631863;
+ redblueMask = 0xF81F;
+ greenMask = 0x7E0;
+ } else if (BitFormat == 555) {
+ colorMask = 0x7BDE7BDE;
+ lowPixelMask = 0x04210421;
+ qcolorMask = 0x739C739C;
+ qlowpixelMask = 0x0C630C63;
+ redblueMask = 0x7C1F;
+ greenMask = 0x3E0;
+ } else {
+ return 0;
+ }
- return 1;
+ return 1;
}
-static inline int GetResult1 (uint32 A, uint32 B, uint32 C, uint32 D,
- uint32 /* E */)
+static inline int GetResult1(uint32 A, uint32 B, uint32 C, uint32 D,
+ uint32 /* E */ )
{
- int x = 0;
- int y = 0;
- int r = 0;
-
- if (A == C)
- x += 1;
- else if (B == C)
- y += 1;
- if (A == D)
- x += 1;
- else if (B == D)
- y += 1;
- if (x <= 1)
- r += 1;
- if (y <= 1)
- r -= 1;
- return r;
+ int x = 0;
+ int y = 0;
+ int r = 0;
+
+ if (A == C)
+ x += 1;
+ else if (B == C)
+ y += 1;
+ if (A == D)
+ x += 1;
+ else if (B == D)
+ y += 1;
+ if (x <= 1)
+ r += 1;
+ if (y <= 1)
+ r -= 1;
+ return r;
}
-static inline int GetResult2 (uint32 A, uint32 B, uint32 C, uint32 D,
- uint32 /* E */)
+static inline int GetResult2(uint32 A, uint32 B, uint32 C, uint32 D,
+ uint32 /* E */ )
{
- int x = 0;
- int y = 0;
- int r = 0;
-
- if (A == C)
- x += 1;
- else if (B == C)
- y += 1;
- if (A == D)
- x += 1;
- else if (B == D)
- y += 1;
- if (x <= 1)
- r -= 1;
- if (y <= 1)
- r += 1;
- return r;
+ int x = 0;
+ int y = 0;
+ int r = 0;
+
+ if (A == C)
+ x += 1;
+ else if (B == C)
+ y += 1;
+ if (A == D)
+ x += 1;
+ else if (B == D)
+ y += 1;
+ if (x <= 1)
+ r -= 1;
+ if (y <= 1)
+ r += 1;
+ return r;
}
-static inline int GetResult (uint32 A, uint32 B, uint32 C, uint32 D)
+static inline int GetResult(uint32 A, uint32 B, uint32 C, uint32 D)
{
- int x = 0;
- int y = 0;
- int r = 0;
-
- if (A == C)
- x += 1;
- else if (B == C)
- y += 1;
- if (A == D)
- x += 1;
- else if (B == D)
- y += 1;
- if (x <= 1)
- r += 1;
- if (y <= 1)
- r -= 1;
- return r;
+ int x = 0;
+ int y = 0;
+ int r = 0;
+
+ if (A == C)
+ x += 1;
+ else if (B == C)
+ y += 1;
+ if (A == D)
+ x += 1;
+ else if (B == D)
+ y += 1;
+ if (x <= 1)
+ r += 1;
+ if (y <= 1)
+ r -= 1;
+ return r;
}
-static inline uint32 INTERPOLATE (uint32 A, uint32 B)
+static inline uint32 INTERPOLATE(uint32 A, uint32 B)
{
- if (A != B)
- {
- return (((A & colorMask) >> 1) + ((B & colorMask) >> 1) +
- (A & B & lowPixelMask));
- }
- else
- return A;
+ if (A != B) {
+ return (((A & colorMask) >> 1) + ((B & colorMask) >> 1) +
+ (A & B & lowPixelMask));
+ } else
+ return A;
}
-static inline uint32 Q_INTERPOLATE (uint32 A, uint32 B, uint32 C, uint32 D)
+static inline uint32 Q_INTERPOLATE(uint32 A, uint32 B, uint32 C, uint32 D)
{
- register uint32 x = ((A & qcolorMask) >> 2) +
- ((B & qcolorMask) >> 2) +
- ((C & qcolorMask) >> 2) + ((D & qcolorMask) >> 2);
- register uint32 y = (A & qlowpixelMask) +
- (B & qlowpixelMask) + (C & qlowpixelMask) + (D & qlowpixelMask);
-
- y = (y >> 2) & qlowpixelMask;
- return x + y;
+ register uint32 x = ((A & qcolorMask) >> 2) +
+ ((B & qcolorMask) >> 2) +
+ ((C & qcolorMask) >> 2) + ((D & qcolorMask) >> 2);
+ register uint32 y = (A & qlowpixelMask) +
+ (B & qlowpixelMask) + (C & qlowpixelMask) + (D & qlowpixelMask);
+
+ y = (y >> 2) & qlowpixelMask;
+ return x + y;
}
#define BLUE_MASK565 0x001F001F
@@ -1340,676 +1391,569 @@ static inline uint32 Q_INTERPOLATE (uint32 A, uint32 B, uint32 C, uint32 D)
#define RED_MASK555 0x7C007C00
#define GREEN_MASK555 0x03E003E0
-void Super2xSaI (uint8 *srcPtr, uint32 srcPitch,
- uint8 *deltaPtr, uint8 *dstPtr, uint32 dstPitch,
- int width, int height)
+void Super2xSaI(uint8 *srcPtr, uint32 srcPitch,
+ uint8 *deltaPtr, uint8 *dstPtr, uint32 dstPitch,
+ int width, int height)
{
- uint16 *bP;
- uint8 *dP;
- uint32 inc_bP;
+ uint16 *bP;
+ uint8 *dP;
+ uint32 inc_bP;
- {
- uint32 Nextline = srcPitch >> 1;
- inc_bP = 1;
-
- while (height--)
{
- bP = (uint16 *) srcPtr;
- dP = (uint8 *) dstPtr;
+ uint32 Nextline = srcPitch >> 1;
+ inc_bP = 1;
+
+ while (height--) {
+ bP = (uint16 *)srcPtr;
+ dP = (uint8 *)dstPtr;
- for (uint32 finish = width; finish; finish -= inc_bP)
- {
- uint32 color4, color5, color6;
- uint32 color1, color2, color3;
- uint32 colorA0, colorA1, colorA2, colorA3,
- colorB0, colorB1, colorB2, colorB3, colorS1, colorS2;
- uint32 product1a, product1b, product2a, product2b;
+ for (uint32 finish = width; finish; finish -= inc_bP) {
+ uint32 color4, color5, color6;
+ uint32 color1, color2, color3;
+ uint32 colorA0, colorA1, colorA2, colorA3,
+ colorB0, colorB1, colorB2, colorB3, colorS1, colorS2;
+ uint32 product1a, product1b, product2a, product2b;
//--------------------------------------- B1 B2
// 4 5 6 S2
// 1 2 3 S1
// A1 A2
- colorB0 = *(bP - Nextline - 1);
- colorB1 = *(bP - Nextline);
- colorB2 = *(bP - Nextline + 1);
- colorB3 = *(bP - Nextline + 2);
+ colorB0 = *(bP - Nextline - 1);
+ colorB1 = *(bP - Nextline);
+ colorB2 = *(bP - Nextline + 1);
+ colorB3 = *(bP - Nextline + 2);
- color4 = *(bP - 1);
- color5 = *(bP);
- color6 = *(bP + 1);
- colorS2 = *(bP + 2);
+ color4 = *(bP - 1);
+ color5 = *(bP);
+ color6 = *(bP + 1);
+ colorS2 = *(bP + 2);
- color1 = *(bP + Nextline - 1);
- color2 = *(bP + Nextline);
- color3 = *(bP + Nextline + 1);
- colorS1 = *(bP + Nextline + 2);
+ color1 = *(bP + Nextline - 1);
+ color2 = *(bP + Nextline);
+ color3 = *(bP + Nextline + 1);
+ colorS1 = *(bP + Nextline + 2);
- colorA0 = *(bP + Nextline + Nextline - 1);
- colorA1 = *(bP + Nextline + Nextline);
- colorA2 = *(bP + Nextline + Nextline + 1);
- colorA3 = *(bP + Nextline + Nextline + 2);
+ colorA0 = *(bP + Nextline + Nextline - 1);
+ colorA1 = *(bP + Nextline + Nextline);
+ colorA2 = *(bP + Nextline + Nextline + 1);
+ colorA3 = *(bP + Nextline + Nextline + 2);
//--------------------------------------
- if (color2 == color6 && color5 != color3)
- {
- product2b = product1b = color2;
- }
- else if (color5 == color3 && color2 != color6)
- {
- product2b = product1b = color5;
- }
- else if (color5 == color3 && color2 == color6)
- {
- register int r = 0;
-
- r += GetResult (color6, color5, color1, colorA1);
- r += GetResult (color6, color5, color4, colorB1);
- r += GetResult (color6, color5, colorA2, colorS1);
- r += GetResult (color6, color5, colorB2, colorS2);
-
- if (r > 0)
- product2b = product1b = color6;
- else if (r < 0)
- product2b = product1b = color5;
- else
- {
- product2b = product1b = INTERPOLATE (color5, color6);
- }
- }
- else
- {
- if (color6 == color3 && color3 == colorA1
- && color2 != colorA2 && color3 != colorA0)
- product2b =
- Q_INTERPOLATE (color3, color3, color3, color2);
- else if (color5 == color2 && color2 == colorA2
- && colorA1 != color3 && color2 != colorA3)
- product2b =
- Q_INTERPOLATE (color2, color2, color2, color3);
- else
- product2b = INTERPOLATE (color2, color3);
-
- if (color6 == color3 && color6 == colorB1
- && color5 != colorB2 && color6 != colorB0)
- product1b =
- Q_INTERPOLATE (color6, color6, color6, color5);
- else if (color5 == color2 && color5 == colorB2
- && colorB1 != color6 && color5 != colorB3)
- product1b =
- Q_INTERPOLATE (color6, color5, color5, color5);
- else
- product1b = INTERPOLATE (color5, color6);
- }
+ if (color2 == color6 && color5 != color3) {
+ product2b = product1b = color2;
+ } else if (color5 == color3 && color2 != color6) {
+ product2b = product1b = color5;
+ } else if (color5 == color3 && color2 == color6) {
+ register int r = 0;
+
+ r += GetResult(color6, color5, color1, colorA1);
+ r += GetResult(color6, color5, color4, colorB1);
+ r += GetResult(color6, color5, colorA2, colorS1);
+ r += GetResult(color6, color5, colorB2, colorS2);
+
+ if (r > 0)
+ product2b = product1b = color6;
+ else if (r < 0)
+ product2b = product1b = color5;
+ else {
+ product2b = product1b = INTERPOLATE(color5, color6);
+ }
+ } else {
+ if (color6 == color3 && color3 == colorA1
+ && color2 != colorA2 && color3 != colorA0)
+ product2b = Q_INTERPOLATE(color3, color3, color3, color2);
+ else if (color5 == color2 && color2 == colorA2
+ && colorA1 != color3 && color2 != colorA3)
+ product2b = Q_INTERPOLATE(color2, color2, color2, color3);
+ else
+ product2b = INTERPOLATE(color2, color3);
+
+ if (color6 == color3 && color6 == colorB1
+ && color5 != colorB2 && color6 != colorB0)
+ product1b = Q_INTERPOLATE(color6, color6, color6, color5);
+ else if (color5 == color2 && color5 == colorB2
+ && colorB1 != color6 && color5 != colorB3)
+ product1b = Q_INTERPOLATE(color6, color5, color5, color5);
+ else
+ product1b = INTERPOLATE(color5, color6);
+ }
- if (color5 == color3 && color2 != color6 && color4 == color5
- && color5 != colorA2)
- product2a = INTERPOLATE (color2, color5);
- else
- if (color5 == color1 && color6 == color5
- && color4 != color2 && color5 != colorA0)
- product2a = INTERPOLATE (color2, color5);
- else
- product2a = color2;
-
- if (color2 == color6 && color5 != color3 && color1 == color2
- && color2 != colorB2)
- product1a = INTERPOLATE (color2, color5);
- else
- if (color4 == color2 && color3 == color2
- && color1 != color5 && color2 != colorB0)
- product1a = INTERPOLATE (color2, color5);
- else
- product1a = color5;
-
- product1a = product1a | (product1b << 16);
- product2a = product2a | (product2b << 16);
-
- *((uint32 *) dP) = product1a;
- *((uint32 *) (dP + dstPitch)) = product2a;
-
- bP += inc_bP;
- dP += sizeof (uint32);
- } // end of for ( finish= width etc..)
-
- srcPtr += srcPitch;
- dstPtr += dstPitch * 2;
- deltaPtr += srcPitch;
- } // while (height--)
- }
+ if (color5 == color3 && color2 != color6 && color4 == color5
+ && color5 != colorA2)
+ product2a = INTERPOLATE(color2, color5);
+ else
+ if (color5 == color1 && color6 == color5
+ && color4 != color2 && color5 != colorA0)
+ product2a = INTERPOLATE(color2, color5);
+ else
+ product2a = color2;
+
+ if (color2 == color6 && color5 != color3 && color1 == color2
+ && color2 != colorB2)
+ product1a = INTERPOLATE(color2, color5);
+ else
+ if (color4 == color2 && color3 == color2
+ && color1 != color5 && color2 != colorB0)
+ product1a = INTERPOLATE(color2, color5);
+ else
+ product1a = color5;
+
+ product1a = product1a | (product1b << 16);
+ product2a = product2a | (product2b << 16);
+
+ *((uint32 *)dP) = product1a;
+ *((uint32 *)(dP + dstPitch)) = product2a;
+
+ bP += inc_bP;
+ dP += sizeof(uint32);
+ } // end of for ( finish= width etc..)
+
+ srcPtr += srcPitch;
+ dstPtr += dstPitch * 2;
+ deltaPtr += srcPitch;
+ } // while (height--)
+ }
}
-void SuperEagle (uint8 *srcPtr, uint32 srcPitch, uint8 *deltaPtr,
- uint8 *dstPtr, uint32 dstPitch, int width, int height)
+void SuperEagle(uint8 *srcPtr, uint32 srcPitch, uint8 *deltaPtr,
+ uint8 *dstPtr, uint32 dstPitch, int width, int height)
{
- uint8 *dP;
- uint16 *bP;
- uint32 inc_bP;
+ uint8 *dP;
+ uint16 *bP;
+ uint32 inc_bP;
- {
- inc_bP = 1;
+ {
+ inc_bP = 1;
+
+ uint32 Nextline = srcPitch >> 1;
+
+ while (height--) {
+ bP = (uint16 *)srcPtr;
+ dP = dstPtr;
+ for (uint32 finish = width; finish; finish -= inc_bP) {
+ uint32 color4, color5, color6;
+ uint32 color1, color2, color3;
+ uint32 colorA1, colorA2, colorB1, colorB2, colorS1, colorS2;
+ uint32 product1a, product1b, product2a, product2b;
+
+ colorB1 = *(bP - Nextline);
+ colorB2 = *(bP - Nextline + 1);
+
+ color4 = *(bP - 1);
+ color5 = *(bP);
+ color6 = *(bP + 1);
+ colorS2 = *(bP + 2);
+
+ color1 = *(bP + Nextline - 1);
+ color2 = *(bP + Nextline);
+ color3 = *(bP + Nextline + 1);
+ colorS1 = *(bP + Nextline + 2);
+
+ colorA1 = *(bP + Nextline + Nextline);
+ colorA2 = *(bP + Nextline + Nextline + 1);
+
+ // --------------------------------------
+ if (color2 == color6 && color5 != color3) {
+ product1b = product2a = color2;
+ if ((color1 == color2) || (color6 == colorB2)) {
+ product1a = INTERPOLATE(color2, color5);
+ product1a = INTERPOLATE(color2, product1a);
+ } else {
+ product1a = INTERPOLATE(color5, color6);
+ }
- uint32 Nextline = srcPitch >> 1;
+ if ((color6 == colorS2) || (color2 == colorA1)) {
+ product2b = INTERPOLATE(color2, color3);
+ product2b = INTERPOLATE(color2, product2b);
+ } else {
+ product2b = INTERPOLATE(color2, color3);
+ }
+ } else if (color5 == color3 && color2 != color6) {
+ product2b = product1a = color5;
+
+ if ((colorB1 == color5) || (color3 == colorS1)) {
+ product1b = INTERPOLATE(color5, color6);
+ product1b = INTERPOLATE(color5, product1b);
+ } else {
+ product1b = INTERPOLATE(color5, color6);
+ }
- while (height--)
- {
- bP = (uint16 *) srcPtr;
- dP = dstPtr;
- for (uint32 finish = width; finish; finish -= inc_bP)
- {
- uint32 color4, color5, color6;
- uint32 color1, color2, color3;
- uint32 colorA1, colorA2, colorB1, colorB2, colorS1, colorS2;
- uint32 product1a, product1b, product2a, product2b;
-
- colorB1 = *(bP - Nextline);
- colorB2 = *(bP - Nextline + 1);
-
- color4 = *(bP - 1);
- color5 = *(bP);
- color6 = *(bP + 1);
- colorS2 = *(bP + 2);
-
- color1 = *(bP + Nextline - 1);
- color2 = *(bP + Nextline);
- color3 = *(bP + Nextline + 1);
- colorS1 = *(bP + Nextline + 2);
-
- colorA1 = *(bP + Nextline + Nextline);
- colorA2 = *(bP + Nextline + Nextline + 1);
-
- // --------------------------------------
- if (color2 == color6 && color5 != color3)
- {
- product1b = product2a = color2;
- if ((color1 == color2) || (color6 == colorB2))
- {
- product1a = INTERPOLATE (color2, color5);
- product1a = INTERPOLATE (color2, product1a);
- }
- else
- {
- product1a = INTERPOLATE (color5, color6);
- }
-
- if ((color6 == colorS2) || (color2 == colorA1))
- {
- product2b = INTERPOLATE (color2, color3);
- product2b = INTERPOLATE (color2, product2b);
- }
- else
- {
- product2b = INTERPOLATE (color2, color3);
- }
- }
- else if (color5 == color3 && color2 != color6)
- {
- product2b = product1a = color5;
-
- if ((colorB1 == color5) || (color3 == colorS1))
- {
- product1b = INTERPOLATE (color5, color6);
- product1b = INTERPOLATE (color5, product1b);
- }
- else
- {
- product1b = INTERPOLATE (color5, color6);
- }
-
- if ((color3 == colorA2) || (color4 == color5))
- {
- product2a = INTERPOLATE (color5, color2);
- product2a = INTERPOLATE (color5, product2a);
- }
- else
- {
- product2a = INTERPOLATE (color2, color3);
- }
+ if ((color3 == colorA2) || (color4 == color5)) {
+ product2a = INTERPOLATE(color5, color2);
+ product2a = INTERPOLATE(color5, product2a);
+ } else {
+ product2a = INTERPOLATE(color2, color3);
+ }
- }
- else if (color5 == color3 && color2 == color6)
- {
- register int r = 0;
-
- r += GetResult (color6, color5, color1, colorA1);
- r += GetResult (color6, color5, color4, colorB1);
- r += GetResult (color6, color5, colorA2, colorS1);
- r += GetResult (color6, color5, colorB2, colorS2);
-
- if (r > 0)
- {
- product1b = product2a = color2;
- product1a = product2b = INTERPOLATE (color5, color6);
- }
- else if (r < 0)
- {
- product2b = product1a = color5;
- product1b = product2a = INTERPOLATE (color5, color6);
- }
- else
- {
- product2b = product1a = color5;
- product1b = product2a = color2;
- }
- }
- else
- {
- product2b = product1a = INTERPOLATE (color2, color6);
- product2b =
- Q_INTERPOLATE (color3, color3, color3, product2b);
- product1a =
- Q_INTERPOLATE (color5, color5, color5, product1a);
-
- product2a = product1b = INTERPOLATE (color5, color3);
- product2a = Q_INTERPOLATE (color2, color2, color2, product2a);
- product1b = Q_INTERPOLATE (color6, color6, color6, product1b);
- }
- product1a = product1a | (product1b << 16);
- product2a = product2a | (product2b << 16);
+ } else if (color5 == color3 && color2 == color6) {
+ register int r = 0;
+
+ r += GetResult(color6, color5, color1, colorA1);
+ r += GetResult(color6, color5, color4, colorB1);
+ r += GetResult(color6, color5, colorA2, colorS1);
+ r += GetResult(color6, color5, colorB2, colorS2);
+
+ if (r > 0) {
+ product1b = product2a = color2;
+ product1a = product2b = INTERPOLATE(color5, color6);
+ } else if (r < 0) {
+ product2b = product1a = color5;
+ product1b = product2a = INTERPOLATE(color5, color6);
+ } else {
+ product2b = product1a = color5;
+ product1b = product2a = color2;
+ }
+ } else {
+ product2b = product1a = INTERPOLATE(color2, color6);
+ product2b = Q_INTERPOLATE(color3, color3, color3, product2b);
+ product1a = Q_INTERPOLATE(color5, color5, color5, product1a);
+
+ product2a = product1b = INTERPOLATE(color5, color3);
+ product2a = Q_INTERPOLATE(color2, color2, color2, product2a);
+ product1b = Q_INTERPOLATE(color6, color6, color6, product1b);
+ }
+ product1a = product1a | (product1b << 16);
+ product2a = product2a | (product2b << 16);
- *((uint32 *) dP) = product1a;
- *((uint32 *) (dP + dstPitch)) = product2a;
+ *((uint32 *)dP) = product1a;
+ *((uint32 *)(dP + dstPitch)) = product2a;
- bP += inc_bP;
- dP += sizeof (uint32);
- } // end of for ( finish= width etc..)
+ bP += inc_bP;
+ dP += sizeof(uint32);
+ } // end of for ( finish= width etc..)
- srcPtr += srcPitch;
- dstPtr += dstPitch * 2;
- deltaPtr += srcPitch;
- } // endof: while (height--)
- }
+ srcPtr += srcPitch;
+ dstPtr += dstPitch * 2;
+ deltaPtr += srcPitch;
+ } // endof: while (height--)
+ }
}
-void _2xSaI (uint8 *srcPtr, uint32 srcPitch, uint8 *deltaPtr,
- uint8 *dstPtr, uint32 dstPitch, int width, int height)
+void _2xSaI(uint8 *srcPtr, uint32 srcPitch, uint8 *deltaPtr,
+ uint8 *dstPtr, uint32 dstPitch, int width, int height)
{
- uint8 *dP;
- uint16 *bP;
- uint32 inc_bP;
+ uint8 *dP;
+ uint16 *bP;
+ uint32 inc_bP;
- {
- inc_bP = 1;
-
- uint32 Nextline = srcPitch >> 1;
-
- while (height--)
{
- bP = (uint16 *) srcPtr;
- dP = dstPtr;
+ inc_bP = 1;
+
+ uint32 Nextline = srcPitch >> 1;
- for (uint32 finish = width; finish; finish -= inc_bP)
- {
+ while (height--) {
+ bP = (uint16 *)srcPtr;
+ dP = dstPtr;
- register uint32 colorA, colorB;
- uint32 colorC, colorD,
- colorE, colorF, colorG, colorH,
- colorI, colorJ, colorK, colorL,
+ for (uint32 finish = width; finish; finish -= inc_bP) {
- colorM, colorN, colorO, colorP;
- uint32 product, product1, product2;
+ register uint32 colorA, colorB;
+ uint32 colorC, colorD,
+ colorE, colorF, colorG, colorH,
+ colorI, colorJ, colorK, colorL, colorM, colorN, colorO, colorP;
+ uint32 product, product1, product2;
//---------------------------------------
// Map of the pixels: I|E F|J
// G|A B|K
// H|C D|L
// M|N O|P
- colorI = *(bP - Nextline - 1);
- colorE = *(bP - Nextline);
- colorF = *(bP - Nextline + 1);
- colorJ = *(bP - Nextline + 2);
-
- colorG = *(bP - 1);
- colorA = *(bP);
- colorB = *(bP + 1);
- colorK = *(bP + 2);
-
- colorH = *(bP + Nextline - 1);
- colorC = *(bP + Nextline);
- colorD = *(bP + Nextline + 1);
- colorL = *(bP + Nextline + 2);
-
- colorM = *(bP + Nextline + Nextline - 1);
- colorN = *(bP + Nextline + Nextline);
- colorO = *(bP + Nextline + Nextline + 1);
- colorP = *(bP + Nextline + Nextline + 2);
-
- if ((colorA == colorD) && (colorB != colorC))
- {
- if (((colorA == colorE) && (colorB == colorL)) ||
- ((colorA == colorC) && (colorA == colorF)
- && (colorB != colorE) && (colorB == colorJ)))
- {
- product = colorA;
- }
- else
- {
- product = INTERPOLATE (colorA, colorB);
- }
-
- if (((colorA == colorG) && (colorC == colorO)) ||
- ((colorA == colorB) && (colorA == colorH)
- && (colorG != colorC) && (colorC == colorM)))
- {
- product1 = colorA;
- }
- else
- {
- product1 = INTERPOLATE (colorA, colorC);
- }
- product2 = colorA;
- }
- else if ((colorB == colorC) && (colorA != colorD))
- {
- if (((colorB == colorF) && (colorA == colorH)) ||
- ((colorB == colorE) && (colorB == colorD)
- && (colorA != colorF) && (colorA == colorI)))
- {
- product = colorB;
- }
- else
- {
- product = INTERPOLATE (colorA, colorB);
- }
-
- if (((colorC == colorH) && (colorA == colorF)) ||
- ((colorC == colorG) && (colorC == colorD)
- && (colorA != colorH) && (colorA == colorI)))
- {
- product1 = colorC;
- }
- else
- {
- product1 = INTERPOLATE (colorA, colorC);
- }
- product2 = colorB;
- }
- else if ((colorA == colorD) && (colorB == colorC))
- {
- if (colorA == colorB)
- {
- product = colorA;
- product1 = colorA;
- product2 = colorA;
- }
- else
- {
- register int r = 0;
-
- product1 = INTERPOLATE (colorA, colorC);
- product = INTERPOLATE (colorA, colorB);
-
- r +=
- GetResult1 (colorA, colorB, colorG, colorE,
- colorI);
- r +=
- GetResult2 (colorB, colorA, colorK, colorF,
- colorJ);
- r +=
- GetResult2 (colorB, colorA, colorH, colorN,
- colorM);
- r +=
- GetResult1 (colorA, colorB, colorL, colorO,
- colorP);
-
- if (r > 0)
- product2 = colorA;
- else if (r < 0)
- product2 = colorB;
- else
- {
- product2 =
- Q_INTERPOLATE (colorA, colorB, colorC,
- colorD);
- }
- }
- }
- else
- {
- product2 = Q_INTERPOLATE (colorA, colorB, colorC, colorD);
-
- if ((colorA == colorC) && (colorA == colorF)
- && (colorB != colorE) && (colorB == colorJ))
- {
- product = colorA;
- }
- else
- if ((colorB == colorE) && (colorB == colorD)
- && (colorA != colorF) && (colorA == colorI))
- {
- product = colorB;
- }
- else
- {
- product = INTERPOLATE (colorA, colorB);
- }
-
- if ((colorA == colorB) && (colorA == colorH)
- && (colorG != colorC) && (colorC == colorM))
- {
- product1 = colorA;
- }
- else
- if ((colorC == colorG) && (colorC == colorD)
- && (colorA != colorH) && (colorA == colorI))
- {
- product1 = colorC;
- }
- else
- {
- product1 = INTERPOLATE (colorA, colorC);
- }
- }
+ colorI = *(bP - Nextline - 1);
+ colorE = *(bP - Nextline);
+ colorF = *(bP - Nextline + 1);
+ colorJ = *(bP - Nextline + 2);
+
+ colorG = *(bP - 1);
+ colorA = *(bP);
+ colorB = *(bP + 1);
+ colorK = *(bP + 2);
+
+ colorH = *(bP + Nextline - 1);
+ colorC = *(bP + Nextline);
+ colorD = *(bP + Nextline + 1);
+ colorL = *(bP + Nextline + 2);
+
+ colorM = *(bP + Nextline + Nextline - 1);
+ colorN = *(bP + Nextline + Nextline);
+ colorO = *(bP + Nextline + Nextline + 1);
+ colorP = *(bP + Nextline + Nextline + 2);
+
+ if ((colorA == colorD) && (colorB != colorC)) {
+ if (((colorA == colorE) && (colorB == colorL)) ||
+ ((colorA == colorC) && (colorA == colorF)
+ && (colorB != colorE) && (colorB == colorJ))) {
+ product = colorA;
+ } else {
+ product = INTERPOLATE(colorA, colorB);
+ }
- product = colorA | (product << 16);
- product1 = product1 | (product2 << 16);
- *((int32 *) dP) = product;
- *((uint32 *) (dP + dstPitch)) = product1;
+ if (((colorA == colorG) && (colorC == colorO)) ||
+ ((colorA == colorB) && (colorA == colorH)
+ && (colorG != colorC) && (colorC == colorM))) {
+ product1 = colorA;
+ } else {
+ product1 = INTERPOLATE(colorA, colorC);
+ }
+ product2 = colorA;
+ } else if ((colorB == colorC) && (colorA != colorD)) {
+ if (((colorB == colorF) && (colorA == colorH)) ||
+ ((colorB == colorE) && (colorB == colorD)
+ && (colorA != colorF) && (colorA == colorI))) {
+ product = colorB;
+ } else {
+ product = INTERPOLATE(colorA, colorB);
+ }
- bP += inc_bP;
- dP += sizeof (uint32);
- } // end of for ( finish= width etc..)
+ if (((colorC == colorH) && (colorA == colorF)) ||
+ ((colorC == colorG) && (colorC == colorD)
+ && (colorA != colorH) && (colorA == colorI))) {
+ product1 = colorC;
+ } else {
+ product1 = INTERPOLATE(colorA, colorC);
+ }
+ product2 = colorB;
+ } else if ((colorA == colorD) && (colorB == colorC)) {
+ if (colorA == colorB) {
+ product = colorA;
+ product1 = colorA;
+ product2 = colorA;
+ } else {
+ register int r = 0;
+
+ product1 = INTERPOLATE(colorA, colorC);
+ product = INTERPOLATE(colorA, colorB);
+
+ r += GetResult1(colorA, colorB, colorG, colorE, colorI);
+ r += GetResult2(colorB, colorA, colorK, colorF, colorJ);
+ r += GetResult2(colorB, colorA, colorH, colorN, colorM);
+ r += GetResult1(colorA, colorB, colorL, colorO, colorP);
+
+ if (r > 0)
+ product2 = colorA;
+ else if (r < 0)
+ product2 = colorB;
+ else {
+ product2 = Q_INTERPOLATE(colorA, colorB, colorC, colorD);
+ }
+ }
+ } else {
+ product2 = Q_INTERPOLATE(colorA, colorB, colorC, colorD);
+
+ if ((colorA == colorC) && (colorA == colorF)
+ && (colorB != colorE) && (colorB == colorJ)) {
+ product = colorA;
+ } else if ((colorB == colorE) && (colorB == colorD)
+ && (colorA != colorF) && (colorA == colorI)) {
+ product = colorB;
+ } else {
+ product = INTERPOLATE(colorA, colorB);
+ }
+
+ if ((colorA == colorB) && (colorA == colorH)
+ && (colorG != colorC) && (colorC == colorM)) {
+ product1 = colorA;
+ } else if ((colorC == colorG) && (colorC == colorD)
+ && (colorA != colorH) && (colorA == colorI)) {
+ product1 = colorC;
+ } else {
+ product1 = INTERPOLATE(colorA, colorC);
+ }
+ }
- srcPtr += srcPitch;
- dstPtr += dstPitch * 2;
- deltaPtr += srcPitch;
- } // endof: while (height--)
- }
+ product = colorA | (product << 16);
+ product1 = product1 | (product2 << 16);
+ *((int32 *) dP) = product;
+ *((uint32 *)(dP + dstPitch)) = product1;
+
+ bP += inc_bP;
+ dP += sizeof(uint32);
+ } // end of for ( finish= width etc..)
+
+ srcPtr += srcPitch;
+ dstPtr += dstPitch * 2;
+ deltaPtr += srcPitch;
+ } // endof: while (height--)
+ }
}
-static uint32 Bilinear (uint32 A, uint32 B, uint32 x)
+static uint32 Bilinear(uint32 A, uint32 B, uint32 x)
{
- unsigned long areaA, areaB;
- unsigned long result;
+ unsigned long areaA, areaB;
+ unsigned long result;
- if (A == B)
- return A;
+ if (A == B)
+ return A;
- areaB = (x >> 11) & 0x1f; // reduce 16 bit fraction to 5 bits
- areaA = 0x20 - areaB;
+ areaB = (x >> 11) & 0x1f; // reduce 16 bit fraction to 5 bits
+ areaA = 0x20 - areaB;
- A = (A & redblueMask) | ((A & greenMask) << 16);
- B = (B & redblueMask) | ((B & greenMask) << 16);
+ A = (A & redblueMask) | ((A & greenMask) << 16);
+ B = (B & redblueMask) | ((B & greenMask) << 16);
- result = ((areaA * A) + (areaB * B)) >> 5;
+ result = ((areaA * A) + (areaB * B)) >> 5;
- return (result & redblueMask) | ((result >> 16) & greenMask);
+ return (result & redblueMask) | ((result >> 16) & greenMask);
}
-static uint32 Bilinear4 (uint32 A, uint32 B, uint32 C, uint32 D, uint32 x,
- uint32 y)
+static uint32 Bilinear4(uint32 A, uint32 B, uint32 C, uint32 D, uint32 x,
+ uint32 y)
{
- unsigned long areaA, areaB, areaC, areaD;
- unsigned long result, xy;
+ unsigned long areaA, areaB, areaC, areaD;
+ unsigned long result, xy;
- x = (x >> 11) & 0x1f;
- y = (y >> 11) & 0x1f;
- xy = (x * y) >> 5;
+ x = (x >> 11) & 0x1f;
+ y = (y >> 11) & 0x1f;
+ xy = (x * y) >> 5;
- A = (A & redblueMask) | ((A & greenMask) << 16);
- B = (B & redblueMask) | ((B & greenMask) << 16);
- C = (C & redblueMask) | ((C & greenMask) << 16);
- D = (D & redblueMask) | ((D & greenMask) << 16);
+ A = (A & redblueMask) | ((A & greenMask) << 16);
+ B = (B & redblueMask) | ((B & greenMask) << 16);
+ C = (C & redblueMask) | ((C & greenMask) << 16);
+ D = (D & redblueMask) | ((D & greenMask) << 16);
- areaA = 0x20 + xy - x - y;
- areaB = x - xy;
- areaC = y - xy;
- areaD = xy;
+ areaA = 0x20 + xy - x - y;
+ areaB = x - xy;
+ areaC = y - xy;
+ areaD = xy;
- result = ((areaA * A) + (areaB * B) + (areaC * C) + (areaD * D)) >> 5;
+ result = ((areaA * A) + (areaB * B) + (areaC * C) + (areaD * D)) >> 5;
- return (result & redblueMask) | ((result >> 16) & greenMask);
+ return (result & redblueMask) | ((result >> 16) & greenMask);
}
-void Scale_2xSaI (uint8 *srcPtr, uint32 srcPitch, uint8 * /* deltaPtr */,
- uint8 *dstPtr, uint32 dstPitch,
- uint32 dstWidth, uint32 dstHeight, int width, int height)
+void Scale_2xSaI(uint8 *srcPtr, uint32 srcPitch, uint8 * /* deltaPtr */ ,
+ uint8 *dstPtr, uint32 dstPitch,
+ uint32 dstWidth, uint32 dstHeight, int width, int height)
{
- uint8 *dP;
- uint16 *bP;
-
- uint32 w;
- uint32 h;
- uint32 dw;
- uint32 dh;
- uint32 hfinish;
- uint32 wfinish;
+ uint8 *dP;
+ uint16 *bP;
- uint32 Nextline = srcPitch >> 1;
+ uint32 w;
+ uint32 h;
+ uint32 dw;
+ uint32 dh;
+ uint32 hfinish;
+ uint32 wfinish;
- wfinish = (width - 1) << 16; // convert to fixed point
- dw = wfinish / (dstWidth - 1);
- hfinish = (height - 1) << 16; // convert to fixed point
- dh = hfinish / (dstHeight - 1);
-
- for (h = 0; h < hfinish; h += dh)
- {
- uint32 y1, y2;
-
- y1 = h & 0xffff; // fraction part of fixed point
- bP = (uint16 *) (srcPtr + ((h >> 16) * srcPitch));
- dP = dstPtr;
- y2 = 0x10000 - y1;
-
- w = 0;
+ uint32 Nextline = srcPitch >> 1;
- for (; w < wfinish;)
- {
- uint32 A, B, C, D;
- uint32 E, F, G, H;
- uint32 I, J, K, L;
- uint32 x1, x2, a1, f1, f2;
- uint32 position, product1;
-
- position = w >> 16;
- A = bP[position]; // current pixel
- B = bP[position + 1]; // next pixel
- C = bP[position + Nextline];
- D = bP[position + Nextline + 1];
- E = bP[position - Nextline];
- F = bP[position - Nextline + 1];
- G = bP[position - 1];
- H = bP[position + Nextline - 1];
- I = bP[position + 2];
- J = bP[position + Nextline + 2];
- K = bP[position + Nextline + Nextline];
- L = bP[position + Nextline + Nextline + 1];
-
- x1 = w & 0xffff; // fraction part of fixed point
- x2 = 0x10000 - x1;
-
- /*0*/
- if (A == B && C == D && A == C)
- product1 = A;
- else
- /*1*/
- if (A == D && B != C)
- {
- f1 = (x1 >> 1) + (0x10000 >> 2);
- f2 = (y1 >> 1) + (0x10000 >> 2);
- if (y1 <= f1 && A == J && A != E) // close to B
- {
- a1 = f1 - y1;
- product1 = Bilinear (A, B, a1);
- }
- else if (y1 >= f1 && A == G && A != L) // close to C
- {
- a1 = y1 - f1;
- product1 = Bilinear (A, C, a1);
- }
- else if (x1 >= f2 && A == E && A != J) // close to B
- {
- a1 = x1 - f2;
- product1 = Bilinear (A, B, a1);
- }
- else if (x1 <= f2 && A == L && A != G) // close to C
- {
- a1 = f2 - x1;
- product1 = Bilinear (A, C, a1);
- }
- else if (y1 >= x1) // close to C
- {
- a1 = y1 - x1;
- product1 = Bilinear (A, C, a1);
- }
- else if (y1 <= x1) // close to B
- {
- a1 = x1 - y1;
- product1 = Bilinear (A, B, a1);
- }
- }
- else
- /*2*/
- if (B == C && A != D)
- {
- f1 = (x1 >> 1) + (0x10000 >> 2);
- f2 = (y1 >> 1) + (0x10000 >> 2);
- if (y2 >= f1 && B == H && B != F) // close to A
- {
- a1 = y2 - f1;
- product1 = Bilinear (B, A, a1);
- }
- else if (y2 <= f1 && B == I && B != K) // close to D
- {
- a1 = f1 - y2;
- product1 = Bilinear (B, D, a1);
- }
- else if (x2 >= f2 && B == F && B != H) // close to A
- {
- a1 = x2 - f2;
- product1 = Bilinear (B, A, a1);
- }
- else if (x2 <= f2 && B == K && B != I) // close to D
- {
- a1 = f2 - x2;
- product1 = Bilinear (B, D, a1);
- }
- else if (y2 >= x1) // close to A
- {
- a1 = y2 - x1;
- product1 = Bilinear (B, A, a1);
- }
- else if (y2 <= x1) // close to D
- {
- a1 = x1 - y2;
- product1 = Bilinear (B, D, a1);
- }
- }
- /*3*/
- else
- {
- product1 = Bilinear4 (A, B, C, D, x1, y1);
- }
+ wfinish = (width - 1) << 16; // convert to fixed point
+ dw = wfinish / (dstWidth - 1);
+ hfinish = (height - 1) << 16; // convert to fixed point
+ dh = hfinish / (dstHeight - 1);
+
+ for (h = 0; h < hfinish; h += dh) {
+ uint32 y1, y2;
+
+ y1 = h & 0xffff; // fraction part of fixed point
+ bP = (uint16 *)(srcPtr + ((h >> 16) * srcPitch));
+ dP = dstPtr;
+ y2 = 0x10000 - y1;
+
+ w = 0;
+
+ for (; w < wfinish;) {
+ uint32 A, B, C, D;
+ uint32 E, F, G, H;
+ uint32 I, J, K, L;
+ uint32 x1, x2, a1, f1, f2;
+ uint32 position, product1;
+
+ position = w >> 16;
+ A = bP[position]; // current pixel
+ B = bP[position + 1]; // next pixel
+ C = bP[position + Nextline];
+ D = bP[position + Nextline + 1];
+ E = bP[position - Nextline];
+ F = bP[position - Nextline + 1];
+ G = bP[position - 1];
+ H = bP[position + Nextline - 1];
+ I = bP[position + 2];
+ J = bP[position + Nextline + 2];
+ K = bP[position + Nextline + Nextline];
+ L = bP[position + Nextline + Nextline + 1];
+
+ x1 = w & 0xffff; // fraction part of fixed point
+ x2 = 0x10000 - x1;
+
+ /*0 */
+ if (A == B && C == D && A == C)
+ product1 = A;
+ else
+ /*1 */
+ if (A == D && B != C) {
+ f1 = (x1 >> 1) + (0x10000 >> 2);
+ f2 = (y1 >> 1) + (0x10000 >> 2);
+ if (y1 <= f1 && A == J && A != E) // close to B
+ {
+ a1 = f1 - y1;
+ product1 = Bilinear(A, B, a1);
+ } else if (y1 >= f1 && A == G && A != L) // close to C
+ {
+ a1 = y1 - f1;
+ product1 = Bilinear(A, C, a1);
+ } else if (x1 >= f2 && A == E && A != J) // close to B
+ {
+ a1 = x1 - f2;
+ product1 = Bilinear(A, B, a1);
+ } else if (x1 <= f2 && A == L && A != G) // close to C
+ {
+ a1 = f2 - x1;
+ product1 = Bilinear(A, C, a1);
+ } else if (y1 >= x1) // close to C
+ {
+ a1 = y1 - x1;
+ product1 = Bilinear(A, C, a1);
+ } else if (y1 <= x1) // close to B
+ {
+ a1 = x1 - y1;
+ product1 = Bilinear(A, B, a1);
+ }
+ } else
+ /*2 */
+ if (B == C && A != D) {
+ f1 = (x1 >> 1) + (0x10000 >> 2);
+ f2 = (y1 >> 1) + (0x10000 >> 2);
+ if (y2 >= f1 && B == H && B != F) // close to A
+ {
+ a1 = y2 - f1;
+ product1 = Bilinear(B, A, a1);
+ } else if (y2 <= f1 && B == I && B != K) // close to D
+ {
+ a1 = f1 - y2;
+ product1 = Bilinear(B, D, a1);
+ } else if (x2 >= f2 && B == F && B != H) // close to A
+ {
+ a1 = x2 - f2;
+ product1 = Bilinear(B, A, a1);
+ } else if (x2 <= f2 && B == K && B != I) // close to D
+ {
+ a1 = f2 - x2;
+ product1 = Bilinear(B, D, a1);
+ } else if (y2 >= x1) // close to A
+ {
+ a1 = y2 - x1;
+ product1 = Bilinear(B, A, a1);
+ } else if (y2 <= x1) // close to D
+ {
+ a1 = x1 - y2;
+ product1 = Bilinear(B, D, a1);
+ }
+ }
+ /*3 */
+ else {
+ product1 = Bilinear4(A, B, C, D, x1, y1);
+ }
//end First Pixel
- *(uint32 *) dP = product1;
- dP += 2;
- w += dw;
+ *(uint32 *)dP = product1;
+ dP += 2;
+ w += dw;
+ }
+ dstPtr += dstPitch;
}
- dstPtr += dstPitch;
- }
}
@@ -2017,21 +1961,21 @@ void Scale_2xSaI (uint8 *srcPtr, uint32 srcPitch, uint8 * /* deltaPtr */,
int OSystem::waitTick(int delta)
{
- do
- {
+ do {
updateScreen(scumm);
new_time = SDL_GetTicks();
waitForTimer(scumm, delta * 15 + last_time - new_time);
last_time = SDL_GetTicks();
- if (gui._active) {
+ if (gui._active) {
gui.loop(scumm);
delta = 5;
}
- }while(gui._active);
+ } while (gui._active);
- return(delta);
+ return (delta);
}
-OSystem::OSystem(){
+OSystem::OSystem()
+{
last_time = SDL_GetTicks();
}
diff --git a/sound.cpp b/sound.cpp
index 398bf647c3..75aa4a187e 100644
--- a/sound.cpp
+++ b/sound.cpp
@@ -25,72 +25,71 @@
#include "cdmusic.h"
#ifdef _WIN32_WCE
-extern void *bsearch(const void *, const void *, size_t,
- size_t, int (*x)(const void *, const void *));
+extern void *bsearch(const void *, const void *, size_t,
+ size_t, int (*x) (const void *, const void *));
#endif
-void Scumm::addSoundToQueue(int sound) {
- if(!(_features & GF_AFTER_V7)) {
+void Scumm::addSoundToQueue(int sound)
+{
+ if (!(_features & GF_AFTER_V7)) {
_vars[VAR_LAST_SOUND] = sound;
ensureResourceLoaded(rtSound, sound);
addSoundToQueue2(sound);
}
-
- if(_features & GF_AUDIOTRACKS)
- warning("Requesting audio track: %d",sound);
+
+ if (_features & GF_AUDIOTRACKS)
+ warning("Requesting audio track: %d", sound);
}
-void Scumm::addSoundToQueue2(int sound) {
+void Scumm::addSoundToQueue2(int sound)
+{
if (_soundQue2Pos < 10) {
_soundQue2[_soundQue2Pos++] = sound;
}
}
-void Scumm::processSoundQues() {
+void Scumm::processSoundQues()
+{
byte d;
- int i,j;
+ int i, j;
int num;
int16 data[16];
SoundEngine *se;
processSfxQueues();
- while (_soundQue2Pos){
- d=_soundQue2[--_soundQue2Pos];
+ while (_soundQue2Pos) {
+ d = _soundQue2[--_soundQue2Pos];
if (d)
playSound(d);
}
- for (i=0; i<_soundQuePos; ) {
+ for (i = 0; i < _soundQuePos;) {
num = _soundQue[i++];
if (i + num > _soundQuePos) {
warning("processSoundQues: invalid num value");
break;
}
- for (j=0; j<16; j++)
+ for (j = 0; j < 16; j++)
data[j] = 0;
- if (num>0) {
- for (j=0; j<num; j++)
- data[j] = _soundQue[i+j];
+ if (num > 0) {
+ for (j = 0; j < num; j++)
+ data[j] = _soundQue[i + j];
i += num;
- se = (SoundEngine*)_soundEngine;
+ se = (SoundEngine *)_soundEngine;
#if 0
- debug(1,"processSoundQues(%d,%d,%d,%d,%d,%d,%d,%d,%d)",
- data[0]>>8,
- data[0]&0xFF,
- data[1],
- data[2],
- data[3],
- data[4],
- data[5],
- data[6],
- data[7]
+ debug(1, "processSoundQues(%d,%d,%d,%d,%d,%d,%d,%d,%d)",
+ data[0] >> 8,
+ data[0] & 0xFF,
+ data[1], data[2], data[3], data[4], data[5], data[6], data[7]
);
#endif
- if(!(_features & GF_AFTER_V7)) {
- if (se)
- _vars[VAR_SOUNDRESULT] = (short)se->do_command(data[0],data[1],data[2],data[3],data[4],data[5],data[6],data[7]);
+ if (!(_features & GF_AFTER_V7)) {
+ if (se)
+ _vars[VAR_SOUNDRESULT] =
+ (short)se->do_command(data[0], data[1], data[2], data[3], data[4],
+ data[5], data[6], data[7]);
}
}
@@ -98,20 +97,22 @@ void Scumm::processSoundQues() {
_soundQuePos = 0;
}
-void Scumm::playSound(int sound) {
+void Scumm::playSound(int sound)
+{
byte *ptr;
- SoundEngine *se = (SoundEngine*)_soundEngine;
+ SoundEngine *se = (SoundEngine *)_soundEngine;
ptr = getResourceAddress(rtSound, sound);
if (ptr != NULL && READ_UINT32_UNALIGNED(ptr) == MKID('SOUN')) {
ptr += 8;
cd_play(this, ptr[16], ptr[17] == 0xff ? -1 : ptr[17],
- (ptr[18] * 60 + ptr[19]) * 75 + ptr[20], 0);
+ (ptr[18] * 60 + ptr[19]) * 75 + ptr[20], 0);
current_cd_sound = sound;
return;
}
- if (_features & GF_OLD256) return; /* FIXME */
+ if (_features & GF_OLD256)
+ return; /* FIXME */
if (se) {
getResourceAddress(rtSound, sound);
@@ -119,23 +120,24 @@ void Scumm::playSound(int sound) {
}
}
-void Scumm::processSfxQueues() {
+void Scumm::processSfxQueues()
+{
Actor *a;
int act;
- bool b,finished;
+ bool b, finished;
if (_talk_sound_mode != 0) {
startTalkSound(_talk_sound_a, _talk_sound_b, _talk_sound_mode);
_talk_sound_mode = 0;
}
-
- if (_sfxMode==2) {
+
+ if (_sfxMode == 2) {
act = _vars[VAR_TALK_ACTOR];
finished = isSfxFinished();
- if (act!=0 && (uint)act<0x80 && !string[0].no_talk_anim) {
+ if (act != 0 && (uint) act < 0x80 && !string[0].no_talk_anim) {
a = derefActorSafe(act, "processSfxQueues");
- if (a->room==_currentRoom && (finished || !_endOfMouthSync)) {
+ if (a->room == _currentRoom && (finished || !_endOfMouthSync)) {
b = true;
if (!finished)
b = isMouthSyncOff(_curSoundPos);
@@ -145,11 +147,11 @@ void Scumm::processSfxQueues() {
}
}
}
- if (finished && _talkDelay==0) {
+ if (finished && _talkDelay == 0) {
stopTalk();
_sfxMode = 0;
}
- } else if (_sfxMode==1) {
+ } else if (_sfxMode == 1) {
if (isSfxFinished()) {
_sfxMode = 0;
}
@@ -157,14 +159,17 @@ void Scumm::processSfxQueues() {
}
#ifdef COMPRESSED_SOUND_FILE
-static int compar(const void *a, const void *b) {
- return ((MP3OffsetTable *) a)->org_offset - ((MP3OffsetTable *) b)->org_offset;
+static int compar(const void *a, const void *b)
+{
+ return ((MP3OffsetTable *) a)->org_offset -
+ ((MP3OffsetTable *) b)->org_offset;
}
#endif
-void Scumm::startTalkSound(uint32 offset, uint32 b, int mode) {
+void Scumm::startTalkSound(uint32 offset, uint32 b, int mode)
+{
int num = 0, i;
- byte file_byte,file_byte_2;
+ byte file_byte, file_byte_2;
int size;
if (!_sfxFile) {
@@ -172,42 +177,44 @@ void Scumm::startTalkSound(uint32 offset, uint32 b, int mode) {
return;
}
- if (b>8) {
- num = (b-8)>>1;
+ if (b > 8) {
+ num = (b - 8) >> 1;
}
-
#ifdef COMPRESSED_SOUND_FILE
if (offset_table != NULL) {
- MP3OffsetTable *result = NULL, key;
-
- key.org_offset = offset;
- result = (MP3OffsetTable *) bsearch(&key, offset_table, num_sound_effects, sizeof(MP3OffsetTable), compar);
-
-
- if (result == NULL) {
- warning("startTalkSound: did not find sound at offset %d !", offset);
- return;
- }
- if (2 * num != result->num_tags) {
- warning("startTalkSound: number of tags do not match (%d - %d) !", b, result->num_tags);
- num = result->num_tags;
- }
- offset = result->new_offset;
- size = result->compressed_size;
+ MP3OffsetTable *result = NULL, key;
+
+ key.org_offset = offset;
+ result =
+ (MP3OffsetTable *) bsearch(&key, offset_table, num_sound_effects,
+ sizeof(MP3OffsetTable), compar);
+
+
+ if (result == NULL) {
+ warning("startTalkSound: did not find sound at offset %d !", offset);
+ return;
+ }
+ if (2 * num != result->num_tags) {
+ warning("startTalkSound: number of tags do not match (%d - %d) !", b,
+ result->num_tags);
+ num = result->num_tags;
+ }
+ offset = result->new_offset;
+ size = result->compressed_size;
} else
#endif
{
- offset += 8;
- size = -1;
+ offset += 8;
+ size = -1;
}
- fileSeek((FILE*)_sfxFile, offset, SEEK_SET);
+ fileSeek((FILE *) _sfxFile, offset, SEEK_SET);
i = 0;
while (num > 0) {
- fileRead((FILE*)_sfxFile, &file_byte, sizeof(file_byte));
- fileRead((FILE*)_sfxFile, &file_byte_2, sizeof(file_byte_2));
- _mouthSyncTimes[i++] = file_byte | (file_byte_2<<8);
- num--;
+ fileRead((FILE *) _sfxFile, &file_byte, sizeof(file_byte));
+ fileRead((FILE *) _sfxFile, &file_byte_2, sizeof(file_byte_2));
+ _mouthSyncTimes[i++] = file_byte | (file_byte_2 << 8);
+ num--;
}
_mouthSyncTimes[i] = 0xFFFF;
_sfxMode = mode;
@@ -217,14 +224,16 @@ void Scumm::startTalkSound(uint32 offset, uint32 b, int mode) {
startSfxSound(_sfxFile, size);
}
-void Scumm::stopTalkSound() {
- if (_sfxMode==2) {
+void Scumm::stopTalkSound()
+{
+ if (_sfxMode == 2) {
stopSfxSound();
_sfxMode = 0;
}
}
-bool Scumm::isMouthSyncOff(uint pos) {
+bool Scumm::isMouthSyncOff(uint pos)
+{
uint j;
bool val = true;
uint16 *ms = _mouthSyncTimes;
@@ -233,7 +242,7 @@ bool Scumm::isMouthSyncOff(uint pos) {
do {
val ^= 1;
j = *ms++;
- if (j==0xFFFF) {
+ if (j == 0xFFFF) {
_endOfMouthSync = true;
break;
}
@@ -242,7 +251,8 @@ bool Scumm::isMouthSyncOff(uint pos) {
}
-int Scumm::isSoundRunning(int sound) {
+int Scumm::isSoundRunning(int sound)
+{
SoundEngine *se;
int i;
@@ -260,15 +270,16 @@ int Scumm::isSoundRunning(int sound) {
if (!isResourceLoaded(rtSound, sound))
return 0;
-
- se = (SoundEngine*)_soundEngine;
+
+ se = (SoundEngine *)_soundEngine;
if (!se)
return 0;
return se->get_sound_status(sound);
}
-bool Scumm::isSoundInQueue(int sound) {
- int i = 0,j, num;
+bool Scumm::isSoundInQueue(int sound)
+{
+ int i = 0, j, num;
int16 table[16];
while (i < _soundQuePos) {
@@ -277,17 +288,18 @@ bool Scumm::isSoundInQueue(int sound) {
memset(table, 0, sizeof(table));
if (num > 0) {
- for (j=0; j<num; j++)
- table[j] = _soundQue[i+j];
+ for (j = 0; j < num; j++)
+ table[j] = _soundQue[i + j];
i += num;
- if (table[0] == 0x10F && table[1]==8 && table[2] == sound)
+ if (table[0] == 0x10F && table[1] == 8 && table[2] == sound)
return 1;
}
}
return 0;
}
-void Scumm::stopSound(int a) {
+void Scumm::stopSound(int a)
+{
SoundEngine *se;
int i;
@@ -296,17 +308,18 @@ void Scumm::stopSound(int a) {
cd_stop();
}
- se = (SoundEngine*)_soundEngine;
+ se = (SoundEngine *)_soundEngine;
if (se)
se->stop_sound(a);
- for (i=0; i<10; i++)
+ for (i = 0; i < 10; i++)
if (_soundQue2[i] == (byte)a)
_soundQue2[i] = 0;
}
-void Scumm::stopAllSounds() {
- SoundEngine *se = (SoundEngine*)_soundEngine;
+void Scumm::stopAllSounds()
+{
+ SoundEngine *se = (SoundEngine *)_soundEngine;
if (current_cd_sound != 0) {
current_cd_sound = 0;
@@ -321,16 +334,18 @@ void Scumm::stopAllSounds() {
stopSfxSound();
}
-void Scumm::clearSoundQue() {
+void Scumm::clearSoundQue()
+{
_soundQue2Pos = 0;
memset(_soundQue2, 0, sizeof(_soundQue2));
}
-void Scumm::soundKludge(int16 *list) {
+void Scumm::soundKludge(int16 * list)
+{
int16 *ptr;
int i;
- if (list[0]==-1) {
+ if (list[0] == -1) {
processSoundQues();
return;
}
@@ -339,13 +354,14 @@ void Scumm::soundKludge(int16 *list) {
ptr = _soundQue + _soundQuePos;
_soundQuePos += 8;
- for (i=0; i<8; i++)
+ for (i = 0; i < 8; i++)
*ptr++ = list[i];
if (_soundQuePos > 0x100)
error("Sound que buffer overflow");
}
-void Scumm::talkSound(uint32 a, uint32 b, int mode) {
+void Scumm::talkSound(uint32 a, uint32 b, int mode)
+{
_talk_sound_a = a;
_talk_sound_b = b;
_talk_sound_mode = mode;
@@ -358,24 +374,27 @@ void Scumm::talkSound(uint32 a, uint32 b, int mode) {
* is needed.
*/
-void Scumm::setupSound() {
- SoundEngine *se = (SoundEngine*)_soundEngine;
+void Scumm::setupSound()
+{
+ SoundEngine *se = (SoundEngine *)_soundEngine;
SOUND_DRIVER_TYPE *driver = se->driver();
if (se) {
se->setBase(res.address[rtSound]);
- if (se->get_music_volume() == 0) se->set_music_volume(60);
+ if (se->get_music_volume() == 0)
+ se->set_music_volume(60);
se->set_master_volume(125);
-
- _sound_volume_sfx = 100;
- _sound_volume_music = se->get_music_volume();
+
+ _sound_volume_sfx = 100;
+ _sound_volume_music = se->get_music_volume();
_sound_volume_master = (se->get_master_volume() / 127);
driver->midiSetDriver(_midi_driver);
}
_sfxFile = openSfxFile();
}
-void Scumm::pauseSounds(bool pause) {
- SoundEngine *se = (SoundEngine*)_soundEngine;
+void Scumm::pauseSounds(bool pause)
+{
+ SoundEngine *se = (SoundEngine *)_soundEngine;
if (se)
se->pause(pause);
_soundsPaused = pause;
@@ -383,99 +402,102 @@ void Scumm::pauseSounds(bool pause) {
enum {
SOUND_HEADER_SIZE = 26,
- SOUND_HEADER_BIG_SIZE = 26+8,
+ SOUND_HEADER_BIG_SIZE = 26 + 8,
};
-void Scumm::startSfxSound(void *file, int file_size) {
+void Scumm::startSfxSound(void *file, int file_size)
+{
char ident[8];
int block_type;
byte work[8];
- uint size = 0,i;
- int rate,comp;
+ uint size = 0, i;
+ int rate, comp;
byte *data;
#ifdef COMPRESSED_SOUND_FILE
if (file_size > 0) {
- data = (byte *) calloc(file_size + MAD_BUFFER_GUARD, 1);
+ data = (byte *)calloc(file_size + MAD_BUFFER_GUARD, 1);
- if (fread(data, file_size, 1, (FILE*) file) != 1) {
- /* no need to free the memory since error will shut down */
- error("startSfxSound: cannot read %d bytes", size);
- return;
- }
- playSfxSound_MP3(data, file_size);
- return;
+ if (fread(data, file_size, 1, (FILE *) file) != 1) {
+ /* no need to free the memory since error will shut down */
+ error("startSfxSound: cannot read %d bytes", size);
+ return;
+ }
+ playSfxSound_MP3(data, file_size);
+ return;
}
#endif
- if ( fread(ident, 8, 1, (FILE*)file) != 1)
+ if (fread(ident, 8, 1, (FILE *) file) != 1)
goto invalid;
if (!memcmp(ident, "VTLK", 4)) {
- fseek((FILE*)file, SOUND_HEADER_BIG_SIZE - 8, SEEK_CUR);
+ fseek((FILE *) file, SOUND_HEADER_BIG_SIZE - 8, SEEK_CUR);
} else if (!memcmp(ident, "Creative", 8)) {
- fseek((FILE*)file, SOUND_HEADER_SIZE - 8, SEEK_CUR);
+ fseek((FILE *) file, SOUND_HEADER_SIZE - 8, SEEK_CUR);
} else {
-invalid:;
+ invalid:;
warning("startSfxSound: invalid header");
return;
}
- block_type = getc( (FILE*)file );
+ block_type = getc((FILE *) file);
if (block_type != 1) {
warning("startSfxSound: Expecting block_type == 1, got %d", block_type);
return;
}
- fread(work, 3, 1, (FILE*)file);
+ fread(work, 3, 1, (FILE *) file);
- size = ( work[0] | ( work[1] << 8 ) | ( work[2] << 16 ) ) - 2;
- rate = getc( (FILE*)file );
- comp = getc( (FILE*)file );
+ size = (work[0] | (work[1] << 8) | (work[2] << 16)) - 2;
+ rate = getc((FILE *) file);
+ comp = getc((FILE *) file);
if (comp != 0) {
warning("startSfxSound: Unsupported compression type %d", comp);
return;
}
-
- data = (byte*) malloc(size);
- if (data==NULL) {
+
+ data = (byte *)malloc(size);
+ if (data == NULL) {
error("startSfxSound: out of memory");
return;
}
-
- if (fread(data, size, 1, (FILE*)file) != 1) {
+
+ if (fread(data, size, 1, (FILE *) file) != 1) {
/* no need to free the memory since error will shut down */
error("startSfxSound: cannot read %d bytes", size);
return;
}
- for(i=0;i<size; i++) {
+ for (i = 0; i < size; i++) {
// Fixme: From WinCE port
if (_sound_volume_sfx != 100)
- data[i] = _sound_volume_sfx * data[i] / 100;
+ data[i] = _sound_volume_sfx * data[i] / 100;
data[i] ^= 0x80;
}
- playSfxSound(data, size, 1000000 / (256 - rate) );
+ playSfxSound(data, size, 1000000 / (256 - rate));
}
#ifdef COMPRESSED_SOUND_FILE
-static int get_int(FILE *f) {
- int ret = 0;
- for (int size = 0; size < 4; size++) {
- int c = fgetc(f);
- if (c == EOF) {
- error("Unexpected end of file !!!");
- }
- ret <<= 8;
- ret |= c;
- }
- return ret;
+static int get_int(FILE * f)
+{
+ int ret = 0;
+ for (int size = 0; size < 4; size++) {
+ int c = fgetc(f);
+ if (c == EOF) {
+ error("Unexpected end of file !!!");
+ }
+ ret <<= 8;
+ ret |= c;
+ }
+ return ret;
}
#endif
-void *Scumm::openSfxFile() {
+void *Scumm::openSfxFile()
+{
char buf[50];
FILE *file = NULL;
@@ -495,132 +517,139 @@ void *Scumm::openSfxFile() {
sprintf(buf, "%s%s.so3", _gameDataPath, _exe_name);
file = fopen(buf, "rb");
if (!file) {
- sprintf(buf, "%smonster.so3", _gameDataPath);
- file = fopen(buf, "rb");
+ sprintf(buf, "%smonster.so3", _gameDataPath);
+ file = fopen(buf, "rb");
}
if (file != NULL) {
- /* Now load the 'offset' index in memory to be able to find the MP3 data
-
- The format of the .SO3 file is easy :
- - number of bytes of the 'index' part
- - N times the following fields (4 bytes each) :
- + offset in the original sound file
- + offset of the MP3 data in the .SO3 file WITHOUT taking into account
- the index field and the 'size' field
- + the number of 'tags'
- + the size of the MP3 data
- - and then N times :
- + the tags
- + the MP3 data
- */
- int size, compressed_offset;
- MP3OffsetTable *cur;
-
- compressed_offset = get_int(file);
- offset_table = (MP3OffsetTable *) malloc(compressed_offset);
- num_sound_effects = compressed_offset / 16;
-
- size = compressed_offset;
- cur = offset_table;
- while (size > 0) {
- cur[0].org_offset = get_int(file);
- cur[0].new_offset = get_int(file) + compressed_offset + 4; /* The + 4 is to take into accound the 'size' field */
- cur[0].num_tags = get_int(file);
- cur[0].compressed_size = get_int(file);
- size -= 4 * 4;
- cur++;
- }
- return file;
+ /* Now load the 'offset' index in memory to be able to find the MP3 data
+
+ The format of the .SO3 file is easy :
+ - number of bytes of the 'index' part
+ - N times the following fields (4 bytes each) :
+ + offset in the original sound file
+ + offset of the MP3 data in the .SO3 file WITHOUT taking into account
+ the index field and the 'size' field
+ + the number of 'tags'
+ + the size of the MP3 data
+ - and then N times :
+ + the tags
+ + the MP3 data
+ */
+ int size, compressed_offset;
+ MP3OffsetTable *cur;
+
+ compressed_offset = get_int(file);
+ offset_table = (MP3OffsetTable *) malloc(compressed_offset);
+ num_sound_effects = compressed_offset / 16;
+
+ size = compressed_offset;
+ cur = offset_table;
+ while (size > 0) {
+ cur[0].org_offset = get_int(file);
+ cur[0].new_offset = get_int(file) + compressed_offset + 4; /* The + 4 is to take into accound the 'size' field */
+ cur[0].num_tags = get_int(file);
+ cur[0].compressed_size = get_int(file);
+ size -= 4 * 4;
+ cur++;
+ }
+ return file;
}
#endif
sprintf(buf, "%s%s.sou", _gameDataPath, _exe_name);
file = fopen(buf, "rb");
if (!file) {
- sprintf(buf, "%smonster.sou", _gameDataPath);
- file = fopen(buf, "rb");
+ sprintf(buf, "%smonster.sou", _gameDataPath);
+ file = fopen(buf, "rb");
}
return file;
}
-MixerChannel *Scumm::allocateMixer() {
+MixerChannel *Scumm::allocateMixer()
+{
int i;
MixerChannel *mc = _mixer_channel;
- for(i=0; i<NUM_MIXER; i++,mc++) {
+ for (i = 0; i < NUM_MIXER; i++, mc++) {
if (!mc->_sfx_sound)
return mc;
}
return NULL;
}
-void Scumm::stopSfxSound() {
+void Scumm::stopSfxSound()
+{
MixerChannel *mc = _mixer_channel;
int i;
- for(i=0; i<NUM_MIXER; i++,mc++) {
+ for (i = 0; i < NUM_MIXER; i++, mc++) {
if (mc->_sfx_sound)
mc->clear();
}
}
-bool Scumm::isSfxFinished() {
+bool Scumm::isSfxFinished()
+{
int i;
- for(i=0; i<NUM_MIXER; i++)
+ for (i = 0; i < NUM_MIXER; i++)
if (_mixer_channel[i]._sfx_sound)
return false;
return true;
}
#ifdef COMPRESSED_SOUND_FILE
-void Scumm::playSfxSound_MP3(void *sound, uint32 size) {
- MixerChannel *mc = allocateMixer();
+void Scumm::playSfxSound_MP3(void *sound, uint32 size)
+{
+ MixerChannel *mc = allocateMixer();
- if (!mc) {
- warning("No mixer channel available");
- return;
- }
+ if (!mc) {
+ warning("No mixer channel available");
+ return;
+ }
- mc->type = MIXER_MP3;
- mc->_sfx_sound = sound;
+ mc->type = MIXER_MP3;
+ mc->_sfx_sound = sound;
- mad_stream_init(&mc->sound_data.mp3.stream);
+ mad_stream_init(&mc->sound_data.mp3.stream);
-#ifdef _WIN32_WCE
+#ifdef _WIN32_WCE
- // 11 kHz on WinCE
+ // 11 kHz on WinCE
- mad_stream_options((mad_stream*)&mc->sound_data.mp3.stream, MAD_OPTION_HALFSAMPLERATE);
+ mad_stream_options((mad_stream *) & mc->sound_data.mp3.stream,
+ MAD_OPTION_HALFSAMPLERATE);
#endif
-
- mad_frame_init(&mc->sound_data.mp3.frame);
- mad_synth_init(&mc->sound_data.mp3.synth);
- mc->sound_data.mp3.position = 0;
- mc->sound_data.mp3.pos_in_frame = 0xFFFFFFFF;
- mc->sound_data.mp3.size = size;
- /* This variable is the number of samples to cut at the start of the MP3
- file. This is needed to have lip-sync as the MP3 file have some miliseconds
- of blank at the start (as, I suppose, the MP3 compression algorithm need to
- have some silence at the start to really be efficient and to not distort
- too much the start of the sample).
-
- This value was found by experimenting out. If you recompress differently your
- .SO3 file, you may have to change this value.
-
- When using Lame, it seems that the sound starts to have some volume about 50 ms
- from the start of the sound => we skip about 1024 samples.
- */
- mc->sound_data.mp3.silence_cut = 1024;
+
+ mad_frame_init(&mc->sound_data.mp3.frame);
+ mad_synth_init(&mc->sound_data.mp3.synth);
+ mc->sound_data.mp3.position = 0;
+ mc->sound_data.mp3.pos_in_frame = 0xFFFFFFFF;
+ mc->sound_data.mp3.size = size;
+ /* This variable is the number of samples to cut at the start of the MP3
+ file. This is needed to have lip-sync as the MP3 file have some miliseconds
+ of blank at the start (as, I suppose, the MP3 compression algorithm need to
+ have some silence at the start to really be efficient and to not distort
+ too much the start of the sample).
+
+ This value was found by experimenting out. If you recompress differently your
+ .SO3 file, you may have to change this value.
+
+ When using Lame, it seems that the sound starts to have some volume about 50 ms
+ from the start of the sound => we skip about 1024 samples.
+ */
+ mc->sound_data.mp3.silence_cut = 1024;
}
#endif
-void Scumm::playBundleSound(char *sound) {
+void Scumm::playBundleSound(char *sound)
+{
warning("playBundleSound: %s", sound);
}
-void Scumm::playSfxSound(void *sound, uint32 size, uint rate) {
+void Scumm::playSfxSound(void *sound, uint32 size, uint rate)
+{
MixerChannel *mc = allocateMixer();
if (!mc) {
@@ -630,20 +659,21 @@ void Scumm::playSfxSound(void *sound, uint32 size, uint rate) {
mc->type = MIXER_STANDARD;
mc->_sfx_sound = sound;
- mc->sound_data.standard._sfx_pos = 0;
+ mc->sound_data.standard._sfx_pos = 0;
mc->sound_data.standard._sfx_fp_pos = 0;
#ifdef _WIN32_WCE
- mc->sound_data.standard._sfx_fp_speed = (1<<16) * rate / 11025;
+ mc->sound_data.standard._sfx_fp_speed = (1 << 16) * rate / 11025;
#else
- mc->sound_data.standard._sfx_fp_speed = (1<<16) * rate /22050;
+ mc->sound_data.standard._sfx_fp_speed = (1 << 16) * rate / 22050;
#endif
- while (size&0xFFFF0000) size>>=1, rate>>=1;
+ while (size & 0xFFFF0000)
+ size >>= 1, rate >>= 1;
+
-
#ifdef _WIN32_WCE
- mc->sound_data.standard._sfx_size = size * 11025 / rate;
-#else
+ mc->sound_data.standard._sfx_size = size * 11025 / rate;
+#else
mc->sound_data.standard._sfx_size = size * 22050 / rate;
#endif
}
@@ -651,265 +681,273 @@ void Scumm::playSfxSound(void *sound, uint32 size, uint rate) {
#ifdef COMPRESSED_SOUND_FILE
static inline int scale_sample(mad_fixed_t sample)
{
- /* round */
- sample += (1L << (MAD_F_FRACBITS - 16));
+ /* round */
+ sample += (1L << (MAD_F_FRACBITS - 16));
- /* clip */
- if (sample >= MAD_F_ONE)
- sample = MAD_F_ONE - 1;
- else if (sample < -MAD_F_ONE)
- sample = -MAD_F_ONE;
+ /* clip */
+ if (sample >= MAD_F_ONE)
+ sample = MAD_F_ONE - 1;
+ else if (sample < -MAD_F_ONE)
+ sample = -MAD_F_ONE;
- /* quantize and scale to not saturate when mixing a lot of channels */
- return sample >> (MAD_F_FRACBITS + 2 - 16);
+ /* quantize and scale to not saturate when mixing a lot of channels */
+ return sample >> (MAD_F_FRACBITS + 2 - 16);
}
#endif
-void MixerChannel::mix(int16 *data, uint32 len) {
+void MixerChannel::mix(int16 * data, uint32 len)
+{
if (!_sfx_sound)
- return;
+ return;
#ifdef COMPRESSED_SOUND_FILE
if (type == MIXER_STANDARD) {
#endif
- int8 *s;
- uint32 fp_pos, fp_speed;
-
- if (len > sound_data.standard._sfx_size)
- len = sound_data.standard._sfx_size;
- sound_data.standard._sfx_size -= len;
-
- s = (int8*)_sfx_sound + sound_data.standard._sfx_pos;
- fp_pos = sound_data.standard._sfx_fp_pos;
- fp_speed = sound_data.standard._sfx_fp_speed;
-
- do {
- fp_pos += fp_speed;
- *data++ += (*s<<6);
- s += fp_pos >> 16;
- fp_pos &= 0x0000FFFF;
- } while (--len);
-
- sound_data.standard._sfx_pos = s - (int8*)_sfx_sound;
- sound_data.standard._sfx_fp_speed = fp_speed;
- sound_data.standard._sfx_fp_pos = fp_pos;
-
- if (!sound_data.standard._sfx_size)
- clear();
+ int8 *s;
+ uint32 fp_pos, fp_speed;
+
+ if (len > sound_data.standard._sfx_size)
+ len = sound_data.standard._sfx_size;
+ sound_data.standard._sfx_size -= len;
+
+ s = (int8 *) _sfx_sound + sound_data.standard._sfx_pos;
+ fp_pos = sound_data.standard._sfx_fp_pos;
+ fp_speed = sound_data.standard._sfx_fp_speed;
+
+ do {
+ fp_pos += fp_speed;
+ *data++ += (*s << 6);
+ s += fp_pos >> 16;
+ fp_pos &= 0x0000FFFF;
+ } while (--len);
+
+ sound_data.standard._sfx_pos = s - (int8 *) _sfx_sound;
+ sound_data.standard._sfx_fp_speed = fp_speed;
+ sound_data.standard._sfx_fp_pos = fp_pos;
+
+ if (!sound_data.standard._sfx_size)
+ clear();
#ifdef COMPRESSED_SOUND_FILE
} else {
- if (type == MIXER_MP3) {
- mad_fixed_t const *ch;
- while (1) {
- ch = sound_data.mp3.synth.pcm.samples[0] + sound_data.mp3.pos_in_frame;
- while ((sound_data.mp3.pos_in_frame < sound_data.mp3.synth.pcm.length) &&
- (len > 0)) {
- if (sound_data.mp3.silence_cut > 0) {
- sound_data.mp3.silence_cut--;
- } else {
- *data++ += scale_sample(*ch++);
- len--;
- }
- sound_data.mp3.pos_in_frame++;
- }
- if (len == 0) return;
-
- if (sound_data.mp3.position >= sound_data.mp3.size) {
- clear();
- return;
- }
-
- mad_stream_buffer(&sound_data.mp3.stream,
- ((unsigned char *) _sfx_sound) + sound_data.mp3.position,
- sound_data.mp3.size + MAD_BUFFER_GUARD - sound_data.mp3.position);
-
- if (mad_frame_decode(&sound_data.mp3.frame, &sound_data.mp3.stream) == -1) {
- /* End of audio... */
- if (sound_data.mp3.stream.error == MAD_ERROR_BUFLEN) {
- clear();
- return;
- } else if (!MAD_RECOVERABLE(sound_data.mp3.stream.error)) {
- error("MAD frame decode error !");
- }
- }
- mad_synth_frame(&sound_data.mp3.synth, &sound_data.mp3.frame);
- sound_data.mp3.pos_in_frame = 0;
- sound_data.mp3.position = (unsigned char *) sound_data.mp3.stream.next_frame - (unsigned char *) _sfx_sound;
- }
- }
- else if (type == MIXER_MP3_CDMUSIC) {
- mad_fixed_t const *ch;
- mad_timer_t frame_duration;
- static long last_pos = 0;
-
- if (!sound_data.mp3_cdmusic.playing)
- return;
-
- while (1) {
-
- // See if we just skipped
- if (ftell(sound_data.mp3_cdmusic.file) != last_pos) {
- int skip_loop;
-
- // Read the new data
- memset(_sfx_sound, 0, sound_data.mp3_cdmusic.buffer_size + MAD_BUFFER_GUARD);
- sound_data.mp3_cdmusic.size =
- fread(_sfx_sound, 1, sound_data.mp3_cdmusic.buffer_size,
- sound_data.mp3_cdmusic.file);
- if (!sound_data.mp3_cdmusic.size) {
- sound_data.mp3_cdmusic.playing = false;
- return;
- }
- last_pos = ftell(sound_data.mp3_cdmusic.file);
- // Resync
- mad_stream_buffer(&sound_data.mp3_cdmusic.stream,
- (unsigned char*)_sfx_sound,
- sound_data.mp3_cdmusic.size
- );
- skip_loop = 2;
- while (skip_loop != 0) {
- if (mad_frame_decode(&sound_data.mp3_cdmusic.frame,
- &sound_data.mp3_cdmusic.stream) == 0) {
- /* Do not decrease duration - see if it's a problem */
- skip_loop--;
- if (skip_loop == 0) {
- mad_synth_frame(&sound_data.mp3_cdmusic.synth,
- &sound_data.mp3_cdmusic.frame);
+ if (type == MIXER_MP3) {
+ mad_fixed_t const *ch;
+ while (1) {
+ ch =
+ sound_data.mp3.synth.pcm.samples[0] + sound_data.mp3.pos_in_frame;
+ while ((sound_data.mp3.pos_in_frame < sound_data.mp3.synth.pcm.length)
+ && (len > 0)) {
+ if (sound_data.mp3.silence_cut > 0) {
+ sound_data.mp3.silence_cut--;
+ } else {
+ *data++ += scale_sample(*ch++);
+ len--;
}
+ sound_data.mp3.pos_in_frame++;
+ }
+ if (len == 0)
+ return;
+
+ if (sound_data.mp3.position >= sound_data.mp3.size) {
+ clear();
+ return;
}
- else {
- if (!MAD_RECOVERABLE(sound_data.mp3_cdmusic.stream.error)) {
- debug(1, "Unrecoverable error while skipping !");
- sound_data.mp3_cdmusic.playing = false;
+
+ mad_stream_buffer(&sound_data.mp3.stream,
+ ((unsigned char *)_sfx_sound) +
+ sound_data.mp3.position,
+ sound_data.mp3.size + MAD_BUFFER_GUARD -
+ sound_data.mp3.position);
+
+ if (mad_frame_decode(&sound_data.mp3.frame, &sound_data.mp3.stream) ==
+ -1) {
+ /* End of audio... */
+ if (sound_data.mp3.stream.error == MAD_ERROR_BUFLEN) {
+ clear();
return;
+ } else if (!MAD_RECOVERABLE(sound_data.mp3.stream.error)) {
+ error("MAD frame decode error !");
}
}
+ mad_synth_frame(&sound_data.mp3.synth, &sound_data.mp3.frame);
+ sound_data.mp3.pos_in_frame = 0;
+ sound_data.mp3.position =
+ (unsigned char *)sound_data.mp3.stream.next_frame -
+ (unsigned char *)_sfx_sound;
}
- // We are supposed to be in synch
- mad_frame_mute(&sound_data.mp3_cdmusic.frame);
- mad_synth_mute(&sound_data.mp3_cdmusic.synth);
- // Resume decoding
- if (mad_frame_decode(&sound_data.mp3_cdmusic.frame,
- &sound_data.mp3_cdmusic.stream) == 0) {
- sound_data.mp3_cdmusic.position =
- (unsigned char *)sound_data.mp3_cdmusic.stream.next_frame -
- (unsigned char *)_sfx_sound;
- sound_data.mp3_cdmusic.pos_in_frame = 0;
- }
- else {
- sound_data.mp3_cdmusic.playing = false;
+ } else if (type == MIXER_MP3_CDMUSIC) {
+ mad_fixed_t const *ch;
+ mad_timer_t frame_duration;
+ static long last_pos = 0;
+
+ if (!sound_data.mp3_cdmusic.playing)
return;
- }
- }
- // Get samples, play samples ...
-
- ch = sound_data.mp3_cdmusic.synth.pcm.samples[0] +
- sound_data.mp3_cdmusic.pos_in_frame;
- while ((sound_data.mp3_cdmusic.pos_in_frame <
- sound_data.mp3_cdmusic.synth.pcm.length) &&
- (len > 0)) {
- *data++ += scale_sample(*ch++);
- len--;
- sound_data.mp3_cdmusic.pos_in_frame++;
- }
- if (len == 0) {
- return;
- }
- // See if we have finished
- // May be incorrect to check the size at the end of a frame but I suppose
- // they are short enough :)
+ while (1) {
- frame_duration = sound_data.mp3_cdmusic.frame.header.duration;
+ // See if we just skipped
+ if (ftell(sound_data.mp3_cdmusic.file) != last_pos) {
+ int skip_loop;
- mad_timer_negate(&frame_duration);
- mad_timer_add(&sound_data.mp3_cdmusic.duration, frame_duration);
- if (mad_timer_compare(sound_data.mp3_cdmusic.duration, mad_timer_zero) < 0) {
- sound_data.mp3_cdmusic.playing = false;
- }
-
- if (mad_frame_decode(&sound_data.mp3_cdmusic.frame,
- &sound_data.mp3_cdmusic.stream) == -1) {
-
- if (sound_data.mp3_cdmusic.stream.error == MAD_ERROR_BUFLEN) {
- int not_decoded;
-
- if (!sound_data.mp3_cdmusic.stream.next_frame) {
- memset(_sfx_sound, 0, sound_data.mp3_cdmusic.buffer_size + MAD_BUFFER_GUARD);
- sound_data.mp3_cdmusic.size =
+ // Read the new data
+ memset(_sfx_sound, 0,
+ sound_data.mp3_cdmusic.buffer_size + MAD_BUFFER_GUARD);
+ sound_data.mp3_cdmusic.size =
fread(_sfx_sound, 1, sound_data.mp3_cdmusic.buffer_size,
- sound_data.mp3_cdmusic.file);
- sound_data.mp3_cdmusic.position = 0;
- not_decoded = 0;
+ sound_data.mp3_cdmusic.file);
+ if (!sound_data.mp3_cdmusic.size) {
+ sound_data.mp3_cdmusic.playing = false;
+ return;
+ }
+ last_pos = ftell(sound_data.mp3_cdmusic.file);
+ // Resync
+ mad_stream_buffer(&sound_data.mp3_cdmusic.stream,
+ (unsigned char *)_sfx_sound,
+ sound_data.mp3_cdmusic.size);
+ skip_loop = 2;
+ while (skip_loop != 0) {
+ if (mad_frame_decode(&sound_data.mp3_cdmusic.frame,
+ &sound_data.mp3_cdmusic.stream) == 0) {
+ /* Do not decrease duration - see if it's a problem */
+ skip_loop--;
+ if (skip_loop == 0) {
+ mad_synth_frame(&sound_data.mp3_cdmusic.synth,
+ &sound_data.mp3_cdmusic.frame);
+ }
+ } else {
+ if (!MAD_RECOVERABLE(sound_data.mp3_cdmusic.stream.error)) {
+ debug(1, "Unrecoverable error while skipping !");
+ sound_data.mp3_cdmusic.playing = false;
+ return;
+ }
+ }
+ }
+ // We are supposed to be in synch
+ mad_frame_mute(&sound_data.mp3_cdmusic.frame);
+ mad_synth_mute(&sound_data.mp3_cdmusic.synth);
+ // Resume decoding
+ if (mad_frame_decode(&sound_data.mp3_cdmusic.frame,
+ &sound_data.mp3_cdmusic.stream) == 0) {
+ sound_data.mp3_cdmusic.position =
+ (unsigned char *)sound_data.mp3_cdmusic.stream.next_frame -
+ (unsigned char *)_sfx_sound;
+ sound_data.mp3_cdmusic.pos_in_frame = 0;
+ } else {
+ sound_data.mp3_cdmusic.playing = false;
+ return;
+ }
+ }
+ // Get samples, play samples ...
+
+ ch = sound_data.mp3_cdmusic.synth.pcm.samples[0] +
+ sound_data.mp3_cdmusic.pos_in_frame;
+ while ((sound_data.mp3_cdmusic.pos_in_frame <
+ sound_data.mp3_cdmusic.synth.pcm.length) && (len > 0)) {
+ *data++ += scale_sample(*ch++);
+ len--;
+ sound_data.mp3_cdmusic.pos_in_frame++;
+ }
+ if (len == 0) {
+ return;
+ }
+ // See if we have finished
+ // May be incorrect to check the size at the end of a frame but I suppose
+ // they are short enough :)
+
+ frame_duration = sound_data.mp3_cdmusic.frame.header.duration;
+
+ mad_timer_negate(&frame_duration);
+ mad_timer_add(&sound_data.mp3_cdmusic.duration, frame_duration);
+ if (mad_timer_compare(sound_data.mp3_cdmusic.duration, mad_timer_zero)
+ < 0) {
+ sound_data.mp3_cdmusic.playing = false;
}
- else {
- not_decoded = sound_data.mp3_cdmusic.stream.bufend -
- sound_data.mp3_cdmusic.stream.next_frame;
- memcpy(_sfx_sound, sound_data.mp3_cdmusic.stream.next_frame,
- not_decoded);
-
- sound_data.mp3_cdmusic.size =
- fread((unsigned char*)_sfx_sound + not_decoded, 1,
- sound_data.mp3_cdmusic.buffer_size - not_decoded,
- sound_data.mp3_cdmusic.file);
+
+ if (mad_frame_decode(&sound_data.mp3_cdmusic.frame,
+ &sound_data.mp3_cdmusic.stream) == -1) {
+
+ if (sound_data.mp3_cdmusic.stream.error == MAD_ERROR_BUFLEN) {
+ int not_decoded;
+
+ if (!sound_data.mp3_cdmusic.stream.next_frame) {
+ memset(_sfx_sound, 0,
+ sound_data.mp3_cdmusic.buffer_size + MAD_BUFFER_GUARD);
+ sound_data.mp3_cdmusic.size =
+ fread(_sfx_sound, 1, sound_data.mp3_cdmusic.buffer_size,
+ sound_data.mp3_cdmusic.file);
+ sound_data.mp3_cdmusic.position = 0;
+ not_decoded = 0;
+ } else {
+ not_decoded = sound_data.mp3_cdmusic.stream.bufend -
+ sound_data.mp3_cdmusic.stream.next_frame;
+ memcpy(_sfx_sound, sound_data.mp3_cdmusic.stream.next_frame,
+ not_decoded);
+
+ sound_data.mp3_cdmusic.size =
+ fread((unsigned char *)_sfx_sound + not_decoded, 1,
+ sound_data.mp3_cdmusic.buffer_size - not_decoded,
+ sound_data.mp3_cdmusic.file);
+ }
+ last_pos = ftell(sound_data.mp3_cdmusic.file);
+ sound_data.mp3_cdmusic.stream.error = MAD_ERROR_NONE;
+ // Restream
+ mad_stream_buffer(&sound_data.mp3_cdmusic.stream,
+ (unsigned char *)_sfx_sound,
+ sound_data.mp3_cdmusic.size + not_decoded);
+ if (mad_frame_decode
+ (&sound_data.mp3_cdmusic.frame,
+ &sound_data.mp3_cdmusic.stream) == -1) {
+ debug(1, "Error decoding after restream %d !",
+ sound_data.mp3.stream.error);
+ }
+ } else if (!MAD_RECOVERABLE(sound_data.mp3.stream.error)) {
+ error("MAD frame decode error in MP3 CDMUSIC !");
+ }
}
- last_pos = ftell(sound_data.mp3_cdmusic.file);
- sound_data.mp3_cdmusic.stream.error = MAD_ERROR_NONE;
- // Restream
- mad_stream_buffer(&sound_data.mp3_cdmusic.stream,
- (unsigned char*)_sfx_sound,
- sound_data.mp3_cdmusic.size + not_decoded
- );
- if (mad_frame_decode(&sound_data.mp3_cdmusic.frame, &sound_data.mp3_cdmusic.stream) == -1) {
- debug(1, "Error decoding after restream %d !", sound_data.mp3.stream.error);
- }
- } else if (!MAD_RECOVERABLE(sound_data.mp3.stream.error)) {
- error("MAD frame decode error in MP3 CDMUSIC !");
- }
- }
-
- mad_synth_frame(&sound_data.mp3_cdmusic.synth, &sound_data.mp3_cdmusic.frame);
- sound_data.mp3_cdmusic.pos_in_frame = 0;
- sound_data.mp3_cdmusic.position =
- (unsigned char *)sound_data.mp3_cdmusic.stream.next_frame -
- (unsigned char *)_sfx_sound;
- }
- }
- }
+
+ mad_synth_frame(&sound_data.mp3_cdmusic.synth,
+ &sound_data.mp3_cdmusic.frame);
+ sound_data.mp3_cdmusic.pos_in_frame = 0;
+ sound_data.mp3_cdmusic.position =
+ (unsigned char *)sound_data.mp3_cdmusic.stream.next_frame -
+ (unsigned char *)_sfx_sound;
+ }
+ }
+ }
#endif
}
-void MixerChannel::clear() {
+void MixerChannel::clear()
+{
free(_sfx_sound);
_sfx_sound = NULL;
#ifdef COMPRESSED_SOUND_FILE
if (type == MIXER_MP3) {
- mad_synth_finish(&sound_data.mp3.synth);
- mad_frame_finish(&sound_data.mp3.frame);
- mad_stream_finish(&sound_data.mp3.stream);
+ mad_synth_finish(&sound_data.mp3.synth);
+ mad_frame_finish(&sound_data.mp3.frame);
+ mad_stream_finish(&sound_data.mp3.stream);
}
#endif
}
-void Scumm::mixWaves(int16 *sounds, int len) {
+void Scumm::mixWaves(int16 * sounds, int len)
+{
int i;
- memset(sounds, 0,len * sizeof(int16));
+ memset(sounds, 0, len * sizeof(int16));
if (_soundsPaused)
return;
-
- SoundEngine *se = (SoundEngine*)_soundEngine;
+
+ SoundEngine *se = (SoundEngine *)_soundEngine;
if (se) {
se->driver()->generate_samples(sounds, len);
}
-
- for(i=NUM_MIXER-1; i>=0;i--) {
+
+ for (i = NUM_MIXER - 1; i >= 0; i--) {
_mixer_channel[i].mix(sounds, len);
}
if (_soundsPaused2)
memset(sounds, 0x0, len * sizeof(int16));
}
-
diff --git a/sound/adlib.cpp b/sound/adlib.cpp
index 57036fd1e4..8fe6f7536e 100644
--- a/sound/adlib.cpp
+++ b/sound/adlib.cpp
@@ -27,43 +27,44 @@
static byte lookup_table[64][32];
const byte volume_table[] = {
-0, 4, 7, 11,
-13, 16, 18, 20,
-22, 24, 26, 27,
-29, 30, 31, 33,
-34, 35, 36, 37,
-38, 39, 40, 41,
-42, 43, 44, 44,
-45, 46, 47, 47,
-48, 49, 49, 50,
-51, 51, 52, 53,
-53, 54, 54, 55,
-55, 56, 56, 57,
-57, 58, 58, 59,
-59, 60, 60, 60,
-61, 61, 62, 62,
-62, 63, 63, 63
+ 0, 4, 7, 11,
+ 13, 16, 18, 20,
+ 22, 24, 26, 27,
+ 29, 30, 31, 33,
+ 34, 35, 36, 37,
+ 38, 39, 40, 41,
+ 42, 43, 44, 44,
+ 45, 46, 47, 47,
+ 48, 49, 49, 50,
+ 51, 51, 52, 53,
+ 53, 54, 54, 55,
+ 55, 56, 56, 57,
+ 57, 58, 58, 59,
+ 59, 60, 60, 60,
+ 61, 61, 62, 62,
+ 62, 63, 63, 63
};
-int lookup_volume(int a, int b) {
- if (b==0)
+int lookup_volume(int a, int b)
+{
+ if (b == 0)
return 0;
- if (b==31)
+ if (b == 31)
return a;
-
- if (a<-63 || a>63) {
- return b * (a+1) >> 5;
+
+ if (a < -63 || a > 63) {
+ return b * (a + 1) >> 5;
}
-
- if (b<0) {
- if (a<0) {
+
+ if (b < 0) {
+ if (a < 0) {
return lookup_table[-a][-b];
} else {
return -lookup_table[a][-b];
}
} else {
- if (a<0) {
+ if (a < 0) {
return -lookup_table[-a][b];
} else {
return lookup_table[a][b];
@@ -71,26 +72,28 @@ int lookup_volume(int a, int b) {
}
}
-void create_lookup_table() {
- int i,j;
+void create_lookup_table()
+{
+ int i, j;
int sum;
- for (i=0; i<64; i++) {
+ for (i = 0; i < 64; i++) {
sum = i;
- for (j=0; j<32; j++) {
+ for (j = 0; j < 32; j++) {
lookup_table[i][j] = sum >> 5;
sum += i;
}
}
- for (i=0; i<64; i++)
+ for (i = 0; i < 64; i++)
lookup_table[i][0] = 0;
}
-MidiChannelAdl *AdlibSoundDriver::allocate_midichan(byte pri) {
- MidiChannelAdl *ac,*best=NULL;
+MidiChannelAdl *AdlibSoundDriver::allocate_midichan(byte pri)
+{
+ MidiChannelAdl *ac, *best = NULL;
int i;
- for (i=0; i<9; i++) {
+ for (i = 0; i < 9; i++) {
if (++_midichan_index >= 9)
_midichan_index = 0;
ac = &_midi_channels[_midichan_index];
@@ -106,37 +109,38 @@ MidiChannelAdl *AdlibSoundDriver::allocate_midichan(byte pri) {
if (best)
mc_off(best);
- else
- ;//debug(1, "Denying adlib channel request");
+ else; //debug(1, "Denying adlib channel request");
return best;
}
-void AdlibSoundDriver::init(SoundEngine *eng) {
+void AdlibSoundDriver::init(SoundEngine *eng)
+{
int i;
MidiChannelAdl *mc;
_se = eng;
- for(i=0,mc=_midi_channels; i!=ARRAYSIZE(_midi_channels);i++,mc++) {
+ for (i = 0, mc = _midi_channels; i != ARRAYSIZE(_midi_channels); i++, mc++) {
mc->_channel = i;
mc->_s11a.s10 = &mc->_s10b;
mc->_s11b.s10 = &mc->_s10a;
}
- _adlib_reg_cache = (byte*)calloc(256,1);
+ _adlib_reg_cache = (byte *)calloc(256, 1);
- #ifdef _WIN32_WCE // Poor WIN32 won't handle 22050 well !
- _opl = OPLCreate(OPL_TYPE_YM3812,3579545,11025);
- #else
- _opl = OPLCreate(OPL_TYPE_YM3812,3579545,22050);
- #endif
- adlib_write(1,0x20);
- adlib_write(8,0x40);
+#ifdef _WIN32_WCE // Poor WIN32 won't handle 22050 well !
+ _opl = OPLCreate(OPL_TYPE_YM3812, 3579545, 11025);
+#else
+ _opl = OPLCreate(OPL_TYPE_YM3812, 3579545, 22050);
+#endif
+ adlib_write(1, 0x20);
+ adlib_write(8, 0x40);
adlib_write(0xBD, 0x00);
create_lookup_table();
}
-void AdlibSoundDriver::adlib_write(byte port, byte value) {
+void AdlibSoundDriver::adlib_write(byte port, byte value)
+{
if (_adlib_reg_cache[port] == value)
return;
_adlib_reg_cache[port] = value;
@@ -144,50 +148,52 @@ void AdlibSoundDriver::adlib_write(byte port, byte value) {
OPLWriteReg(_opl, port, value);
}
-void AdlibSoundDriver::adlib_key_off(int chan) {
+void AdlibSoundDriver::adlib_key_off(int chan)
+{
byte port = chan + 0xB0;
- adlib_write(port, adlib_read(port)&~0x20);
+ adlib_write(port, adlib_read(port) & ~0x20);
}
struct AdlibSetParams {
- byte a,b,c,d;
+ byte a, b, c, d;
};
static const byte channel_mappings[9] = {
0, 1, 2, 8,
- 9,10,16,17,
+ 9, 10, 16, 17,
18
};
static const byte channel_mappings_2[9] = {
3, 4, 5, 11,
- 12,13,19,20,
+ 12, 13, 19, 20,
21
};
static const AdlibSetParams adlib_setparam_table[] = {
-{0x40,0,63,63}, /* level */
-{0xE0,2,0,0}, /* unused */
-{0x40,6,192,0}, /* level key scaling */
-{0x20,0,15,0}, /* modulator frequency multiple */
-{0x60,4,240,15},/* attack rate */
-{0x60,0,15,15}, /* decay rate */
-{0x80,4,240,15}, /* sustain level */
-{0x80,0,15,15}, /* release rate */
-{0xE0,0,3,0}, /* waveform select */
-{0x20,7,128,0}, /* amp mod */
-{0x20,6,64,0}, /* vib */
-{0x20,5,32,0}, /* eg typ */
-{0x20,4,16,0}, /* ksr */
-{0xC0,0,1,0}, /* decay alg */
-{0xC0,1,14,0} /* feedback */
+ {0x40, 0, 63, 63}, /* level */
+ {0xE0, 2, 0, 0}, /* unused */
+ {0x40, 6, 192, 0}, /* level key scaling */
+ {0x20, 0, 15, 0}, /* modulator frequency multiple */
+ {0x60, 4, 240, 15}, /* attack rate */
+ {0x60, 0, 15, 15}, /* decay rate */
+ {0x80, 4, 240, 15}, /* sustain level */
+ {0x80, 0, 15, 15}, /* release rate */
+ {0xE0, 0, 3, 0}, /* waveform select */
+ {0x20, 7, 128, 0}, /* amp mod */
+ {0x20, 6, 64, 0}, /* vib */
+ {0x20, 5, 32, 0}, /* eg typ */
+ {0x20, 4, 16, 0}, /* ksr */
+ {0xC0, 0, 1, 0}, /* decay alg */
+ {0xC0, 1, 14, 0} /* feedback */
};
-void AdlibSoundDriver::adlib_set_param(int channel, byte param, int value) {
+void AdlibSoundDriver::adlib_set_param(int channel, byte param, int value)
+{
const AdlibSetParams *as;
byte port;
- assert(channel>=0 && channel<9);
+ assert(channel >= 0 && channel < 9);
if (param <= 12) {
port = channel_mappings_2[channel];
@@ -197,8 +203,8 @@ void AdlibSoundDriver::adlib_set_param(int channel, byte param, int value) {
} else if (param <= 27) {
param -= 13;
port = channel;
- } else if (param==28 || param==29) {
- if (param==28)
+ } else if (param == 28 || param == 29) {
+ if (param == 28)
value -= 15;
else
value -= 383;
@@ -206,7 +212,7 @@ void AdlibSoundDriver::adlib_set_param(int channel, byte param, int value) {
channel_table_2[channel] = value;
adlib_playnote(channel, curnote_table[channel] + value);
return;
- }else {
+ } else {
return;
}
@@ -214,80 +220,81 @@ void AdlibSoundDriver::adlib_set_param(int channel, byte param, int value) {
if (as->d)
value = as->d - value;
port += as->a;
- adlib_write(port, (adlib_read(port) & ~as->c) | (((byte)value)<<as->b));
+ adlib_write(port, (adlib_read(port) & ~as->c) | (((byte)value) << as->b));
}
static const byte octave_numbers[] = {
-0, 0, 0, 0, 0, 0, 0, 0,
-0, 0, 0, 0, 1, 1, 1, 1,
-1, 1, 1, 1, 1, 1, 1, 1,
-2, 2, 2, 2, 2, 2, 2, 2,
-2, 2, 2, 2, 3, 3, 3, 3,
-3, 3, 3, 3, 3, 3, 3, 3,
-4, 4, 4, 4, 4, 4, 4, 4,
-4, 4, 4, 4, 5, 5, 5, 5,
-5, 5, 5, 5, 5, 5, 5, 5,
-6, 6, 6, 6, 6, 6, 6, 6,
-6, 6, 6, 6, 7, 7, 7, 7,
-7, 7, 7, 7, 7, 7, 7, 7,
-7, 7, 7, 7, 7, 7, 7, 7,
-7, 7, 7, 7, 7, 7, 7, 7,
-7, 7, 7, 7, 7, 7, 7, 7,
-7, 7, 7, 7, 7, 7, 7, 7
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 3, 3, 3, 3,
+ 3, 3, 3, 3, 3, 3, 3, 3,
+ 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 5, 5, 5, 5,
+ 5, 5, 5, 5, 5, 5, 5, 5,
+ 6, 6, 6, 6, 6, 6, 6, 6,
+ 6, 6, 6, 6, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7
};
-static const byte note_numbers[]= {
- 3, 4, 5, 6, 7, 8, 9, 10,
-11, 12, 13, 14, 3, 4, 5, 6,
- 7, 8, 9, 10, 11, 12, 13, 14,
- 3, 4, 5, 6, 7, 8, 9, 10,
-11, 12, 13, 14, 3, 4, 5, 6,
- 7, 8, 9, 10, 11, 12, 13, 14,
- 3, 4, 5, 6, 7, 8, 9, 10,
-11, 12, 13, 14, 3, 4, 5, 6,
- 7, 8, 9, 10, 11, 12, 13, 14,
- 3, 4, 5, 6, 7, 8, 9, 10,
-11, 12, 13, 14, 3, 4, 5, 6,
- 7, 8, 9, 10, 11, 12, 13, 14,
- 3, 4, 5, 6, 7, 8, 9, 10,
-11, 12, 13, 14, 3, 4, 5, 6,
- 7, 8, 9, 10, 11, 12, 13, 14,
- 3, 4, 5, 6, 7, 8, 9, 10
+static const byte note_numbers[] = {
+ 3, 4, 5, 6, 7, 8, 9, 10,
+ 11, 12, 13, 14, 3, 4, 5, 6,
+ 7, 8, 9, 10, 11, 12, 13, 14,
+ 3, 4, 5, 6, 7, 8, 9, 10,
+ 11, 12, 13, 14, 3, 4, 5, 6,
+ 7, 8, 9, 10, 11, 12, 13, 14,
+ 3, 4, 5, 6, 7, 8, 9, 10,
+ 11, 12, 13, 14, 3, 4, 5, 6,
+ 7, 8, 9, 10, 11, 12, 13, 14,
+ 3, 4, 5, 6, 7, 8, 9, 10,
+ 11, 12, 13, 14, 3, 4, 5, 6,
+ 7, 8, 9, 10, 11, 12, 13, 14,
+ 3, 4, 5, 6, 7, 8, 9, 10,
+ 11, 12, 13, 14, 3, 4, 5, 6,
+ 7, 8, 9, 10, 11, 12, 13, 14,
+ 3, 4, 5, 6, 7, 8, 9, 10
};
static const byte note_to_f_num[] = {
- 90, 91, 92, 92, 93, 94, 94, 95,
- 96, 96, 97, 98, 98, 99, 100, 101,
-101, 102, 103, 104, 104, 105, 106, 107,
-107, 108, 109, 110, 111, 111, 112, 113,
-114, 115, 115, 116, 117, 118, 119, 120,
-121, 121, 122, 123, 124, 125, 126, 127,
-128, 129, 130, 131, 132, 132, 133, 134,
-135, 136, 137, 138, 139, 140, 141, 142,
-143, 145, 146, 147, 148, 149, 150, 151,
-152, 153, 154, 155, 157, 158, 159, 160,
-161, 162, 163, 165, 166, 167, 168, 169,
-171, 172, 173, 174, 176, 177, 178, 180,
-181, 182, 184, 185, 186, 188, 189, 190,
-192, 193, 194, 196, 197, 199, 200, 202,
-203, 205, 206, 208, 209, 211, 212, 214,
-215, 217, 218, 220, 222, 223, 225, 226,
-228, 230, 231, 233, 235, 236, 238, 240,
-242, 243, 245, 247, 249, 251, 252, 254,
+ 90, 91, 92, 92, 93, 94, 94, 95,
+ 96, 96, 97, 98, 98, 99, 100, 101,
+ 101, 102, 103, 104, 104, 105, 106, 107,
+ 107, 108, 109, 110, 111, 111, 112, 113,
+ 114, 115, 115, 116, 117, 118, 119, 120,
+ 121, 121, 122, 123, 124, 125, 126, 127,
+ 128, 129, 130, 131, 132, 132, 133, 134,
+ 135, 136, 137, 138, 139, 140, 141, 142,
+ 143, 145, 146, 147, 148, 149, 150, 151,
+ 152, 153, 154, 155, 157, 158, 159, 160,
+ 161, 162, 163, 165, 166, 167, 168, 169,
+ 171, 172, 173, 174, 176, 177, 178, 180,
+ 181, 182, 184, 185, 186, 188, 189, 190,
+ 192, 193, 194, 196, 197, 199, 200, 202,
+ 203, 205, 206, 208, 209, 211, 212, 214,
+ 215, 217, 218, 220, 222, 223, 225, 226,
+ 228, 230, 231, 233, 235, 236, 238, 240,
+ 242, 243, 245, 247, 249, 251, 252, 254,
};
-void AdlibSoundDriver::adlib_playnote(int channel, int note) {
- byte old,oct,notex;
+void AdlibSoundDriver::adlib_playnote(int channel, int note)
+{
+ byte old, oct, notex;
int note2;
int i;
- note2 = (note>>7) - 4;
+ note2 = (note >> 7) - 4;
- oct = octave_numbers[note2]<<2;
+ oct = octave_numbers[note2] << 2;
notex = note_numbers[note2];
old = adlib_read(channel + 0xB0);
- if (old&0x20) {
+ if (old & 0x20) {
old &= ~0x20;
if (oct > old) {
if (notex < 6) {
@@ -301,54 +308,59 @@ void AdlibSoundDriver::adlib_playnote(int channel, int note) {
}
}
}
-
- i = (notex<<3) + ((note>>4)&0x7);
+
+ i = (notex << 3) + ((note >> 4) & 0x7);
adlib_write(channel + 0xA0, note_to_f_num[i]);
- adlib_write(channel + 0xB0, oct|0x20);
+ adlib_write(channel + 0xB0, oct | 0x20);
}
-void AdlibSoundDriver::adlib_note_on(int chan, byte note, int mod) {
+void AdlibSoundDriver::adlib_note_on(int chan, byte note, int mod)
+{
int code;
- assert(chan>=0 && chan<9);
- code = (note<<7) + mod;
+ assert(chan >= 0 && chan < 9);
+ code = (note << 7) + mod;
curnote_table[chan] = code;
adlib_playnote(chan, channel_table_2[chan] + code);
}
-void AdlibSoundDriver::adlib_note_on_ex(int chan, byte note, int mod) {
+void AdlibSoundDriver::adlib_note_on_ex(int chan, byte note, int mod)
+{
int code;
- assert(chan>=0 && chan<9);
- code = (note<<7) + mod;
+ assert(chan >= 0 && chan < 9);
+ code = (note << 7) + mod;
curnote_table[chan] = code;
channel_table_2[chan] = 0;
adlib_playnote(chan, code);
}
-void AdlibSoundDriver::adlib_key_onoff(int channel) {
+void AdlibSoundDriver::adlib_key_onoff(int channel)
+{
byte val;
byte port = channel + 0xB0;
- assert(channel>=0 && channel<9);
+ assert(channel >= 0 && channel < 9);
val = adlib_read(port);
- adlib_write(port, val&~0x20);
- adlib_write(port, val|0x20);
+ adlib_write(port, val & ~0x20);
+ adlib_write(port, val | 0x20);
}
-void AdlibSoundDriver::adlib_setup_channel(int chan, Instrument *instr, byte vol_1, byte vol_2) {
+void AdlibSoundDriver::adlib_setup_channel(int chan, Instrument * instr,
+ byte vol_1, byte vol_2)
+{
byte port;
- assert(chan>=0 && chan<9);
+ assert(chan >= 0 && chan < 9);
port = channel_mappings[chan];
adlib_write(port + 0x20, instr->flags_1);
- adlib_write(port + 0x40, (instr->oplvl_1|0x3F) - vol_1);
+ adlib_write(port + 0x40, (instr->oplvl_1 | 0x3F) - vol_1);
adlib_write(port + 0x60, ~instr->atdec_1);
adlib_write(port + 0x80, ~instr->sustrel_1);
adlib_write(port + 0xE0, instr->waveform_1);
-
+
port = channel_mappings_2[chan];
adlib_write(port + 0x20, instr->flags_2);
- adlib_write(port + 0x40, (instr->oplvl_2|0x3F) - vol_2);
+ adlib_write(port + 0x40, (instr->oplvl_2 | 0x3F) - vol_2);
adlib_write(port + 0x60, ~instr->atdec_2);
adlib_write(port + 0x80, ~instr->sustrel_2);
adlib_write(port + 0xE0, instr->waveform_2);
@@ -356,12 +368,13 @@ void AdlibSoundDriver::adlib_setup_channel(int chan, Instrument *instr, byte vol
adlib_write((byte)chan + 0xC0, instr->feedback);
}
-int AdlibSoundDriver::adlib_read_param(int chan, byte param) {
+int AdlibSoundDriver::adlib_read_param(int chan, byte param)
+{
const AdlibSetParams *as;
byte val;
byte port;
- assert(chan>=0 && chan<9);
+ assert(chan >= 0 && chan < 9);
if (param <= 12) {
port = channel_mappings_2[chan];
@@ -371,9 +384,9 @@ int AdlibSoundDriver::adlib_read_param(int chan, byte param) {
} else if (param <= 27) {
param -= 13;
port = chan;
- } else if (param==28) {
+ } else if (param == 28) {
return 0xF;
- } else if (param==29) {
+ } else if (param == 29) {
return 0x17F;
} else {
return 0;
@@ -389,11 +402,12 @@ int AdlibSoundDriver::adlib_read_param(int chan, byte param) {
return val;
}
-void AdlibSoundDriver::generate_samples(int16 *data, int len) {
+void AdlibSoundDriver::generate_samples(int16 * data, int len)
+{
int step;
if (!_opl) {
- memset(data, 0, len*sizeof(int16));
+ memset(data, 0, len * sizeof(int16));
return;
}
@@ -401,21 +415,23 @@ void AdlibSoundDriver::generate_samples(int16 *data, int len) {
step = len;
if (step > _next_tick)
step = _next_tick;
- YM3812UpdateOne(_opl,data,step);
-
- if(!(_next_tick -= step)) {
+ YM3812UpdateOne(_opl, data, step);
+
+ if (!(_next_tick -= step)) {
_se->on_timer();
reset_tick();
}
data += step;
- } while (len-=step);
+ } while (len -= step);
}
-void AdlibSoundDriver::reset_tick() {
+void AdlibSoundDriver::reset_tick()
+{
_next_tick = 88;
}
-void AdlibSoundDriver::on_timer() {
+void AdlibSoundDriver::on_timer()
+{
MidiChannelAdl *mc;
int i;
@@ -423,7 +439,7 @@ void AdlibSoundDriver::on_timer() {
while (_adlib_timer_counter >= 0x411B) {
_adlib_timer_counter -= 0x411B;
mc = _midi_channels;
- for (i=0; i!=ARRAYSIZE(_midi_channels); i++,mc++) {
+ for (i = 0; i != ARRAYSIZE(_midi_channels); i++, mc++) {
if (!mc->_part)
continue;
if (mc->_duration && (mc->_duration -= 0x11) <= 0) {
@@ -441,71 +457,73 @@ void AdlibSoundDriver::on_timer() {
}
const byte param_table_1[16] = {
-29,28,27,0,
-3,4,7,8,
-13,16,17,20,
-21,30,31,0
+ 29, 28, 27, 0,
+ 3, 4, 7, 8,
+ 13, 16, 17, 20,
+ 21, 30, 31, 0
};
const uint16 param_table_2[16] = {
-0x2FF,0x1F,0x7,0x3F,
-0x0F,0x0F,0x0F,0x3,
-0x3F,0x0F,0x0F,0x0F,
-0x3,0x3E,0x1F, 0
+ 0x2FF, 0x1F, 0x7, 0x3F,
+ 0x0F, 0x0F, 0x0F, 0x3,
+ 0x3F, 0x0F, 0x0F, 0x0F,
+ 0x3, 0x3E, 0x1F, 0
};
static const uint16 num_steps_table[] = {
-1, 2, 4, 5,
-6, 7, 8, 9,
-10, 12, 14, 16,
-18, 21, 24, 30,
-36, 50, 64, 82,
-100, 136, 160, 192,
-240, 276, 340, 460,
-600, 860, 1200, 1600
+ 1, 2, 4, 5,
+ 6, 7, 8, 9,
+ 10, 12, 14, 16,
+ 18, 21, 24, 30,
+ 36, 50, 64, 82,
+ 100, 136, 160, 192,
+ 240, 276, 340, 460,
+ 600, 860, 1200, 1600
};
-int AdlibSoundDriver::random_nr(int a) {
+int AdlibSoundDriver::random_nr(int a)
+{
static byte _rand_seed = 1;
- if (_rand_seed&1) {
- _rand_seed>>=1;
+ if (_rand_seed & 1) {
+ _rand_seed >>= 1;
_rand_seed ^= 0xB8;
} else {
- _rand_seed>>=1;
+ _rand_seed >>= 1;
}
return _rand_seed * a >> 8;
}
-void AdlibSoundDriver::struct10_setup(Struct10 *s10) {
- int b,c,d,e,f,g,h;
+void AdlibSoundDriver::struct10_setup(Struct10 * s10)
+{
+ int b, c, d, e, f, g, h;
byte t;
b = s10->unk3;
f = s10->active - 1;
t = s10->table_a[f];
- e = num_steps_table[lookup_table[t&0x7F][b]];
- if (t&0x80) {
+ e = num_steps_table[lookup_table[t & 0x7F][b]];
+ if (t & 0x80) {
e = random_nr(e);
}
- if (e==0)
+ if (e == 0)
e++;
-
+
s10->num_steps = s10->speed_lo_max = e;
if (f != 2) {
c = s10->param;
g = s10->start_value;
t = s10->table_b[f];
- d = lookup_volume(c, (t&0x7F) - 31);
- if (t&0x80) {
+ d = lookup_volume(c, (t & 0x7F) - 31);
+ if (t & 0x80) {
d = random_nr(d);
}
- if (d+g > c) {
+ if (d + g > c) {
h = c - g;
} else {
h = d;
- if (d+g<0)
+ if (d + g < 0)
h = -g;
}
h -= s10->cur_val;
@@ -514,7 +532,7 @@ void AdlibSoundDriver::struct10_setup(Struct10 *s10) {
}
s10->speed_hi = h / e;
- if (h<0) {
+ if (h < 0) {
h = -h;
s10->direction = -1;
} else {
@@ -525,11 +543,12 @@ void AdlibSoundDriver::struct10_setup(Struct10 *s10) {
s10->speed_lo_counter = 0;
}
-byte AdlibSoundDriver::struct10_ontimer(Struct10 *s10, Struct11 *s11) {
+byte AdlibSoundDriver::struct10_ontimer(Struct10 * s10, Struct11 * s11)
+{
byte result = 0;
int i;
- if (s10->count && (s10->count-=17)<=0) {
+ if (s10->count && (s10->count -= 17) <= 0) {
s10->active = 0;
return 0;
}
@@ -568,7 +587,8 @@ byte AdlibSoundDriver::struct10_ontimer(Struct10 *s10, Struct11 *s11) {
return result;
}
-void AdlibSoundDriver::struct10_init(Struct10 *s10, InstrumentExtra *ie) {
+void AdlibSoundDriver::struct10_init(Struct10 * s10, InstrumentExtra * ie)
+{
s10->active = 1;
s10->cur_val = 0;
s10->modwheel_last = 31;
@@ -584,27 +604,30 @@ void AdlibSoundDriver::struct10_init(Struct10 *s10, InstrumentExtra *ie) {
s10->table_b[1] = ie->e;
s10->table_b[2] = 0;
s10->table_b[3] = ie->h;
-
+
struct10_setup(s10);
}
-void AdlibSoundDriver::mc_init_stuff(MidiChannelAdl *mc, Struct10 *s10, Struct11 *s11, byte flags, InstrumentExtra *ie) {
+void AdlibSoundDriver::mc_init_stuff(MidiChannelAdl *mc, Struct10 * s10,
+ Struct11 * s11, byte flags,
+ InstrumentExtra * ie)
+{
Part *part = mc->_part;
s11->modify_val = 0;
s11->flag0x40 = flags & 0x40;
s10->loop = flags & 0x20;
s11->flag0x10 = flags & 0x10;
- s11->param = param_table_1[flags&0xF];
- s10->param = param_table_2[flags&0xF];
+ s11->param = param_table_1[flags & 0xF];
+ s10->param = param_table_2[flags & 0xF];
s10->unk3 = 31;
if (s11->flag0x40) {
- s10->modwheel = part->_modwheel>>2;
+ s10->modwheel = part->_modwheel >> 2;
} else {
s10->modwheel = 31;
}
- switch(s11->param) {
+ switch (s11->param) {
case 0:
s10->start_value = mc->_vol_2;
break;
@@ -626,22 +649,28 @@ void AdlibSoundDriver::mc_init_stuff(MidiChannelAdl *mc, Struct10 *s10, Struct11
struct10_init(s10, ie);
}
-void AdlibSoundDriver::mc_inc_stuff(MidiChannelAdl *mc, Struct10 *s10, Struct11 *s11) {
+void AdlibSoundDriver::mc_inc_stuff(MidiChannelAdl *mc, Struct10 * s10,
+ Struct11 * s11)
+{
byte code;
- Part *part= mc->_part;
+ Part *part = mc->_part;
- code = struct10_ontimer(s10,s11);
+ code = struct10_ontimer(s10, s11);
- if (code&1) {
- switch(s11->param) {
+ if (code & 1) {
+ switch (s11->param) {
case 0:
mc->_vol_2 = s10->start_value + s11->modify_val;
- part->_drv->adlib_set_param(mc->_channel, 0, volume_table[lookup_table[mc->_vol_2][part->_vol_eff>>2]]);
+ part->_drv->adlib_set_param(mc->_channel, 0,
+ volume_table[lookup_table[mc->_vol_2]
+ [part->_vol_eff >> 2]]);
break;
case 13:
mc->_vol_1 = s10->start_value + s11->modify_val;
if (mc->_twochan) {
- part->_drv->adlib_set_param(mc->_channel, 13, volume_table[lookup_table[mc->_vol_1][part->_vol_eff>>2]]);
+ part->_drv->adlib_set_param(mc->_channel, 13,
+ volume_table[lookup_table[mc->_vol_1]
+ [part->_vol_eff >> 2]]);
} else {
part->_drv->adlib_set_param(mc->_channel, 13, mc->_vol_1);
}
@@ -653,16 +682,18 @@ void AdlibSoundDriver::mc_inc_stuff(MidiChannelAdl *mc, Struct10 *s10, Struct11
s11->s10->unk3 = (char)s11->modify_val;
break;
default:
- part->_drv->adlib_set_param(mc->_channel, s11->param, s10->start_value + s11->modify_val);
+ part->_drv->adlib_set_param(mc->_channel, s11->param,
+ s10->start_value + s11->modify_val);
break;
}
}
- if (code&2 && s11->flag0x10)
+ if (code & 2 && s11->flag0x10)
part->_drv->adlib_key_onoff(mc->_channel);
}
-void AdlibSoundDriver::part_changed(Part *part,byte what) {
+void AdlibSoundDriver::part_changed(Part *part, byte what)
+{
MidiChannelAdl *mc;
if (what & pcProgram) {
@@ -672,23 +703,27 @@ void AdlibSoundDriver::part_changed(Part *part,byte what) {
}
if (what & pcMod) {
- for(mc=part->_mc->adl(); mc; mc=mc->_next) {
- adlib_note_on(mc->_channel, mc->_note + part->_transpose_eff, part->_pitchbend + part->_detune_eff);
+ for (mc = part->_mc->adl(); mc; mc = mc->_next) {
+ adlib_note_on(mc->_channel, mc->_note + part->_transpose_eff,
+ part->_pitchbend + part->_detune_eff);
}
}
if (what & pcVolume) {
- for(mc=part->_mc->adl(); mc; mc=mc->_next) {
- adlib_set_param(mc->_channel, 0, volume_table[lookup_table[mc->_vol_2][part->_vol_eff>>2]]);
+ for (mc = part->_mc->adl(); mc; mc = mc->_next) {
+ adlib_set_param(mc->_channel, 0, volume_table[lookup_table[mc->_vol_2]
+ [part->_vol_eff >> 2]]);
if (mc->_twochan) {
- adlib_set_param(mc->_channel, 13, volume_table[lookup_table[mc->_vol_1][part->_vol_eff>>2]]);
+ adlib_set_param(mc->_channel, 13,
+ volume_table[lookup_table[mc->_vol_1]
+ [part->_vol_eff >> 2]]);
}
}
}
if (what & pcPedal) {
if (!part->_pedal) {
- for(mc=(MidiChannelAdl*)part->_mc; mc; mc=mc->_next) {
+ for (mc = (MidiChannelAdl *)part->_mc; mc; mc = mc->_next) {
if (mc->_waitforpedal)
mc_off(mc);
}
@@ -696,79 +731,90 @@ void AdlibSoundDriver::part_changed(Part *part,byte what) {
}
if (what & pcModwheel) {
- for(mc=(MidiChannelAdl*)part->_mc; mc; mc=mc->_next) {
+ for (mc = (MidiChannelAdl *)part->_mc; mc; mc = mc->_next) {
if (mc->_s10a.active && mc->_s11a.flag0x40)
- mc->_s10a.modwheel = part->_modwheel>>2;
+ mc->_s10a.modwheel = part->_modwheel >> 2;
if (mc->_s10b.active && mc->_s11b.flag0x40)
- mc->_s10b.modwheel = part->_modwheel>>2;
+ mc->_s10b.modwheel = part->_modwheel >> 2;
}
}
}
-void AdlibSoundDriver::mc_key_on(MidiChannel *mc2, byte note, byte velocity) {
- MidiChannelAdl *mc = (MidiChannelAdl*)mc2;
+void AdlibSoundDriver::mc_key_on(MidiChannel * mc2, byte note, byte velocity)
+{
+ MidiChannelAdl *mc = (MidiChannelAdl *)mc2;
Part *part = mc->_part;
Instrument *instr = &_part_instr[part->_slot];
int c;
- byte vol_1,vol_2;
+ byte vol_1, vol_2;
- mc->_twochan = instr->feedback&1;
+ mc->_twochan = instr->feedback & 1;
mc->_note = note;
mc->_waitforpedal = false;
mc->_duration = instr->duration;
if (mc->_duration != 0)
mc->_duration *= 63;
- vol_1 = (instr->oplvl_1&0x3F) + lookup_table[velocity>>1][instr->waveform_1>>2];
+ vol_1 =
+ (instr->oplvl_1 & 0x3F) +
+ lookup_table[velocity >> 1][instr->waveform_1 >> 2];
if (vol_1 > 0x3F)
vol_1 = 0x3F;
mc->_vol_1 = vol_1;
- vol_2 = (instr->oplvl_2&0x3F) + lookup_table[velocity>>1][instr->waveform_2>>2];
+ vol_2 =
+ (instr->oplvl_2 & 0x3F) +
+ lookup_table[velocity >> 1][instr->waveform_2 >> 2];
if (vol_2 > 0x3F)
vol_2 = 0x3F;
mc->_vol_2 = vol_2;
c = part->_vol_eff >> 2;
-
+
vol_2 = volume_table[lookup_table[vol_2][c]];
if (mc->_twochan)
vol_1 = volume_table[lookup_table[vol_1][c]];
-
+
adlib_setup_channel(mc->_channel, instr, vol_1, vol_2);
- adlib_note_on_ex(mc->_channel, part->_transpose_eff + note, part->_detune_eff + part->_pitchbend);
+ adlib_note_on_ex(mc->_channel, part->_transpose_eff + note,
+ part->_detune_eff + part->_pitchbend);
if (instr->flags_a & 0x80) {
- mc_init_stuff(mc, &mc->_s10a, &mc->_s11a, instr->flags_a, &instr->extra_a);
+ mc_init_stuff(mc, &mc->_s10a, &mc->_s11a, instr->flags_a,
+ &instr->extra_a);
} else {
mc->_s10a.active = 0;
}
-
+
if (instr->flags_b & 0x80) {
- mc_init_stuff(mc, &mc->_s10b, &mc->_s11b, instr->flags_b, &instr->extra_b);
+ mc_init_stuff(mc, &mc->_s10b, &mc->_s11b, instr->flags_b,
+ &instr->extra_b);
} else {
mc->_s10b.active = 0;
}
}
-void AdlibSoundDriver::set_instrument(uint slot, byte *data) {
+void AdlibSoundDriver::set_instrument(uint slot, byte *data)
+{
if (slot < 32) {
memcpy(&_glob_instr[slot], data, sizeof(Instrument));
}
}
-void AdlibSoundDriver::link_mc(Part *part, MidiChannelAdl *mc) {
+void AdlibSoundDriver::link_mc(Part *part, MidiChannelAdl *mc)
+{
mc->_part = part;
- mc->_next = (MidiChannelAdl*)part->_mc;
+ mc->_next = (MidiChannelAdl *)part->_mc;
part->_mc = mc;
mc->_prev = NULL;
-
+
if (mc->_next)
mc->_next->_prev = mc;
}
-void AdlibSoundDriver::part_key_on(Part *part, byte note, byte velocity) {
+void AdlibSoundDriver::part_key_on(Part *part, byte note, byte velocity)
+{
MidiChannelAdl *mc;
mc = allocate_midichan(part->_pri_eff);
@@ -776,14 +822,15 @@ void AdlibSoundDriver::part_key_on(Part *part, byte note, byte velocity) {
return;
link_mc(part, mc);
- mc_key_on(mc,note, velocity);
+ mc_key_on(mc, note, velocity);
}
-void AdlibSoundDriver::part_key_off(Part *part, byte note) {
+void AdlibSoundDriver::part_key_off(Part *part, byte note)
+{
MidiChannelAdl *mc;
- for(mc=(MidiChannelAdl*)part->_mc; mc; mc=mc->_next) {
- if (mc->_note==note) {
+ for (mc = (MidiChannelAdl *)part->_mc; mc; mc = mc->_next) {
+ if (mc->_note == note) {
if (part->_pedal)
mc->_waitforpedal = true;
else
@@ -800,107 +847,110 @@ struct AdlibInstrSetParams {
#define MKLINE(_a_,_b_,_c_) { (int)&((Instrument*)0)->_a_, _b_, ((1<<(_c_))-1)<<(_b_) }
static const AdlibInstrSetParams adlib_instr_params[69] = {
- MKLINE(oplvl_2,0,6),
- MKLINE(waveform_2,2,5),
- MKLINE(oplvl_2,6,2),
- MKLINE(flags_2,0,4),
- MKLINE(atdec_2,4,4),
- MKLINE(atdec_2,0,4),
- MKLINE(sustrel_2,4,4),
- MKLINE(sustrel_2,0,4),
- MKLINE(waveform_2,0,2),
- MKLINE(flags_2,7,1),
- MKLINE(flags_2,6,1),
- MKLINE(flags_2,5,1),
- MKLINE(flags_2,4,1),
-
- MKLINE(oplvl_1,0,6),
- MKLINE(waveform_1,2,5),
- MKLINE(oplvl_1,6,2),
- MKLINE(flags_1,0,4),
- MKLINE(atdec_1,4,4),
- MKLINE(atdec_1,0,4),
- MKLINE(sustrel_1,4,4),
- MKLINE(sustrel_1,0,4),
- MKLINE(waveform_1,0,2),
- MKLINE(flags_1,7,1),
- MKLINE(flags_1,6,1),
- MKLINE(flags_1,5,1),
- MKLINE(flags_1,4,1),
-
- MKLINE(feedback,0,1),
- MKLINE(feedback,1,3),
-
- MKLINE(flags_a,7,1),
- MKLINE(flags_a,6,1),
- MKLINE(flags_a,5,1),
- MKLINE(flags_a,4,1),
- MKLINE(flags_a,0,4),
- MKLINE(extra_a.a,0,8),
- MKLINE(extra_a.b,0,7),
- MKLINE(extra_a.c,0,7),
- MKLINE(extra_a.d,0,7),
- MKLINE(extra_a.e,0,7),
- MKLINE(extra_a.f,0,7),
- MKLINE(extra_a.g,0,7),
- MKLINE(extra_a.h,0,7),
- MKLINE(extra_a.b,7,1),
- MKLINE(extra_a.c,7,1),
- MKLINE(extra_a.d,7,1),
- MKLINE(extra_a.e,7,1),
- MKLINE(extra_a.f,7,1),
- MKLINE(extra_a.g,7,1),
- MKLINE(extra_a.h,7,1),
-
- MKLINE(flags_b,7,1),
- MKLINE(flags_b,6,1),
- MKLINE(flags_b,5,1),
- MKLINE(flags_b,4,1),
- MKLINE(flags_b,0,4),
- MKLINE(extra_b.a,0,8),
- MKLINE(extra_b.b,0,7),
- MKLINE(extra_b.c,0,7),
- MKLINE(extra_b.d,0,7),
- MKLINE(extra_b.e,0,7),
- MKLINE(extra_b.f,0,7),
- MKLINE(extra_b.g,0,7),
- MKLINE(extra_b.h,0,7),
- MKLINE(extra_b.b,7,1),
- MKLINE(extra_b.c,7,1),
- MKLINE(extra_b.d,7,1),
- MKLINE(extra_b.e,7,1),
- MKLINE(extra_b.f,7,1),
- MKLINE(extra_b.g,7,1),
- MKLINE(extra_b.h,7,1),
-
- MKLINE(duration,0,8),
+ MKLINE(oplvl_2, 0, 6),
+ MKLINE(waveform_2, 2, 5),
+ MKLINE(oplvl_2, 6, 2),
+ MKLINE(flags_2, 0, 4),
+ MKLINE(atdec_2, 4, 4),
+ MKLINE(atdec_2, 0, 4),
+ MKLINE(sustrel_2, 4, 4),
+ MKLINE(sustrel_2, 0, 4),
+ MKLINE(waveform_2, 0, 2),
+ MKLINE(flags_2, 7, 1),
+ MKLINE(flags_2, 6, 1),
+ MKLINE(flags_2, 5, 1),
+ MKLINE(flags_2, 4, 1),
+
+ MKLINE(oplvl_1, 0, 6),
+ MKLINE(waveform_1, 2, 5),
+ MKLINE(oplvl_1, 6, 2),
+ MKLINE(flags_1, 0, 4),
+ MKLINE(atdec_1, 4, 4),
+ MKLINE(atdec_1, 0, 4),
+ MKLINE(sustrel_1, 4, 4),
+ MKLINE(sustrel_1, 0, 4),
+ MKLINE(waveform_1, 0, 2),
+ MKLINE(flags_1, 7, 1),
+ MKLINE(flags_1, 6, 1),
+ MKLINE(flags_1, 5, 1),
+ MKLINE(flags_1, 4, 1),
+
+ MKLINE(feedback, 0, 1),
+ MKLINE(feedback, 1, 3),
+
+ MKLINE(flags_a, 7, 1),
+ MKLINE(flags_a, 6, 1),
+ MKLINE(flags_a, 5, 1),
+ MKLINE(flags_a, 4, 1),
+ MKLINE(flags_a, 0, 4),
+ MKLINE(extra_a.a, 0, 8),
+ MKLINE(extra_a.b, 0, 7),
+ MKLINE(extra_a.c, 0, 7),
+ MKLINE(extra_a.d, 0, 7),
+ MKLINE(extra_a.e, 0, 7),
+ MKLINE(extra_a.f, 0, 7),
+ MKLINE(extra_a.g, 0, 7),
+ MKLINE(extra_a.h, 0, 7),
+ MKLINE(extra_a.b, 7, 1),
+ MKLINE(extra_a.c, 7, 1),
+ MKLINE(extra_a.d, 7, 1),
+ MKLINE(extra_a.e, 7, 1),
+ MKLINE(extra_a.f, 7, 1),
+ MKLINE(extra_a.g, 7, 1),
+ MKLINE(extra_a.h, 7, 1),
+
+ MKLINE(flags_b, 7, 1),
+ MKLINE(flags_b, 6, 1),
+ MKLINE(flags_b, 5, 1),
+ MKLINE(flags_b, 4, 1),
+ MKLINE(flags_b, 0, 4),
+ MKLINE(extra_b.a, 0, 8),
+ MKLINE(extra_b.b, 0, 7),
+ MKLINE(extra_b.c, 0, 7),
+ MKLINE(extra_b.d, 0, 7),
+ MKLINE(extra_b.e, 0, 7),
+ MKLINE(extra_b.f, 0, 7),
+ MKLINE(extra_b.g, 0, 7),
+ MKLINE(extra_b.h, 0, 7),
+ MKLINE(extra_b.b, 7, 1),
+ MKLINE(extra_b.c, 7, 1),
+ MKLINE(extra_b.d, 7, 1),
+ MKLINE(extra_b.e, 7, 1),
+ MKLINE(extra_b.f, 7, 1),
+ MKLINE(extra_b.g, 7, 1),
+ MKLINE(extra_b.h, 7, 1),
+
+ MKLINE(duration, 0, 8),
};
#undef MKLINE
-void AdlibSoundDriver::part_set_param(Part *part, byte param, int value) {
+void AdlibSoundDriver::part_set_param(Part *part, byte param, int value)
+{
const AdlibInstrSetParams *sp = &adlib_instr_params[param];
- byte *p = (byte*)&_part_instr[part->_slot] + sp->param;
- *p = (*p&~sp->mask) | (value<<sp->shl);
+ byte *p = (byte *)&_part_instr[part->_slot] + sp->param;
+ *p = (*p & ~sp->mask) | (value << sp->shl);
if (param < 28) {
MidiChannelAdl *mc;
- for(mc=(MidiChannelAdl*)part->_mc; mc; mc=mc->_next) {
+ for (mc = (MidiChannelAdl *)part->_mc; mc; mc = mc->_next) {
adlib_set_param(mc->_channel, param, value);
}
}
}
-void AdlibSoundDriver::part_off(Part *part) {
- MidiChannelAdl *mc = (MidiChannelAdl*)part->_mc;
+void AdlibSoundDriver::part_off(Part *part)
+{
+ MidiChannelAdl *mc = (MidiChannelAdl *)part->_mc;
part->_mc = NULL;
- for(; mc; mc=mc->_next) {
+ for (; mc; mc = mc->_next) {
mc_off(mc);
}
}
-void AdlibSoundDriver::mc_off(MidiChannel *mc2) {
- MidiChannelAdl *mc = (MidiChannelAdl*)mc2, *tmp;
+void AdlibSoundDriver::mc_off(MidiChannel * mc2)
+{
+ MidiChannelAdl *mc = (MidiChannelAdl *)mc2, *tmp;
adlib_key_off(mc->_channel);
@@ -915,19 +965,21 @@ void AdlibSoundDriver::mc_off(MidiChannel *mc2) {
mc->_part = NULL;
}
-void AdlibSoundDriver::part_set_instrument(Part *part, Instrument *instr) {
+void AdlibSoundDriver::part_set_instrument(Part *part, Instrument * instr)
+{
Instrument *i = &_part_instr[part->_slot];
memcpy(i, instr, sizeof(Instrument));
}
-int AdlibSoundDriver::part_update_active(Part *part,uint16 *active) {
+int AdlibSoundDriver::part_update_active(Part *part, uint16 *active)
+{
uint16 bits;
int count = 0;
MidiChannelAdl *mc;
- bits = 1<<part->_chan;
+ bits = 1 << part->_chan;
- for(mc=part->_mc->adl(); mc; mc=mc->_next) {
+ for (mc = part->_mc->adl(); mc; mc = mc->_next) {
if (!(active[mc->_note] & bits)) {
active[mc->_note] |= bits;
count++;
diff --git a/sound/fmopl.cpp b/sound/fmopl.cpp
index 880ee992bd..b01ecab0c9 100644
--- a/sound/fmopl.cpp
+++ b/sound/fmopl.cpp
@@ -27,19 +27,19 @@
/* -------------------- preliminary define section --------------------- */
/* attack/decay rate time rate */
-#define OPL_ARRATE 141280 /* RATE 4 = 2826.24ms @ 3.6MHz */
-#define OPL_DRRATE 1956000 /* RATE 4 = 39280.64ms @ 3.6MHz */
+#define OPL_ARRATE 141280 /* RATE 4 = 2826.24ms @ 3.6MHz */
+#define OPL_DRRATE 1956000 /* RATE 4 = 39280.64ms @ 3.6MHz */
-#define DELTAT_MIXING_LEVEL (1) /* DELTA-T ADPCM MIXING LEVEL */
+#define DELTAT_MIXING_LEVEL (1) /* DELTA-T ADPCM MIXING LEVEL */
-#define FREQ_BITS 24 /* frequency turn */
+#define FREQ_BITS 24 /* frequency turn */
/* counter bits = 20 , octerve 7 */
#define FREQ_RATE (1<<(FREQ_BITS-20))
#define TL_BITS (FREQ_BITS+2)
/* final output shift , limit minimum and maximum */
-#define OPL_OUTSB (TL_BITS+3-16) /* OPL output final shift 16bit */
+#define OPL_OUTSB (TL_BITS+3-16) /* OPL output final shift 16bit */
#define OPL_MAXOUT (0x7fff<<OPL_OUTSB)
#define OPL_MINOUT (-0x8000<<OPL_OUTSB)
@@ -57,13 +57,13 @@
/* used dynamic memory = EG_ENT*4*4(byte)or EG_ENT*6*4(byte) */
/* used static memory = EG_ENT*4 (byte) */
-#define EG_OFF ((2*EG_ENT)<<ENV_BITS) /* OFF */
+#define EG_OFF ((2*EG_ENT)<<ENV_BITS) /* OFF */
#define EG_DED EG_OFF
-#define EG_DST (EG_ENT<<ENV_BITS) /* DECAY START */
+#define EG_DST (EG_ENT<<ENV_BITS) /* DECAY START */
#define EG_AED EG_DST
-#define EG_AST 0 /* ATTACK START */
+#define EG_AST 0 /* ATTACK START */
-#define EG_STEP (96.0/EG_ENT) /* OPL is 0.1875 dB step */
+#define EG_STEP (96.0/EG_ENT) /* OPL is 0.1875 dB step */
/* LFO table entries */
#define VIB_ENT 512
@@ -85,12 +85,11 @@
#define ENV_MOD_AR 0x02
/* -------------------- tables --------------------- */
-static const int slot_array[32]=
-{
- 0, 2, 4, 1, 3, 5,-1,-1,
- 6, 8,10, 7, 9,11,-1,-1,
- 12,14,16,13,15,17,-1,-1,
- -1,-1,-1,-1,-1,-1,-1,-1
+static const int slot_array[32] = {
+ 0, 2, 4, 1, 3, 5, -1, -1,
+ 6, 8, 10, 7, 9, 11, -1, -1,
+ 12, 14, 16, 13, 15, 17, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1
};
/* key scale level */
@@ -98,8 +97,7 @@ static const int slot_array[32]=
#define SC(mydb) ((UINT32) (mydb / (EG_STEP/2)))
-static const UINT32 KSL_TABLE[8*16]=
-{
+static const UINT32 KSL_TABLE[8 * 16] = {
/* OCT 0 */
SC(0.000), SC(0.000), SC(0.000), SC(0.000),
SC(0.000), SC(0.000), SC(0.000), SC(0.000),
@@ -123,36 +121,36 @@ static const UINT32 KSL_TABLE[8*16]=
/* OCT 4 */
SC(0.000), SC(0.000), SC(3.000), SC(4.875),
SC(6.000), SC(7.125), SC(7.875), SC(8.625),
- SC(9.000), SC(9.750), SC(10.125),SC(10.500),
- SC(10.875),SC(11.250),SC(11.625),SC(12.000),
+ SC(9.000), SC(9.750), SC(10.125), SC(10.500),
+ SC(10.875), SC(11.250), SC(11.625), SC(12.000),
/* OCT 5 */
SC(0.000), SC(3.000), SC(6.000), SC(7.875),
- SC(9.000), SC(10.125),SC(10.875),SC(11.625),
- SC(12.000),SC(12.750),SC(13.125),SC(13.500),
- SC(13.875),SC(14.250),SC(14.625),SC(15.000),
+ SC(9.000), SC(10.125), SC(10.875), SC(11.625),
+ SC(12.000), SC(12.750), SC(13.125), SC(13.500),
+ SC(13.875), SC(14.250), SC(14.625), SC(15.000),
/* OCT 6 */
SC(0.000), SC(6.000), SC(9.000), SC(10.875),
- SC(12.000),SC(13.125),SC(13.875),SC(14.625),
- SC(15.000),SC(15.750),SC(16.125),SC(16.500),
- SC(16.875),SC(17.250),SC(17.625),SC(18.000),
+ SC(12.000), SC(13.125), SC(13.875), SC(14.625),
+ SC(15.000), SC(15.750), SC(16.125), SC(16.500),
+ SC(16.875), SC(17.250), SC(17.625), SC(18.000),
/* OCT 7 */
- SC(0.000), SC(9.000), SC(12.000),SC(13.875),
- SC(15.000),SC(16.125),SC(16.875),SC(17.625),
- SC(18.000),SC(18.750),SC(19.125),SC(19.500),
- SC(19.875),SC(20.250),SC(20.625),SC(21.000)
+ SC(0.000), SC(9.000), SC(12.000), SC(13.875),
+ SC(15.000), SC(16.125), SC(16.875), SC(17.625),
+ SC(18.000), SC(18.750), SC(19.125), SC(19.500),
+ SC(19.875), SC(20.250), SC(20.625), SC(21.000)
};
#undef SC
/* sustain lebel table (3db per step) */
/* 0 - 15: 0, 3, 6, 9,12,15,18,21,24,27,30,33,36,39,42,93 (dB)*/
#define SC(db) ((int) (db*((3/EG_STEP)*(1<<ENV_BITS)))+EG_DST)
-static const INT32 SL_TABLE[16]={
- SC( 0),SC( 1),SC( 2),SC(3 ),SC(4 ),SC(5 ),SC(6 ),SC( 7),
- SC( 8),SC( 9),SC(10),SC(11),SC(12),SC(13),SC(14),SC(31)
+static const INT32 SL_TABLE[16] = {
+ SC(0), SC(1), SC(2), SC(3), SC(4), SC(5), SC(6), SC(7),
+ SC(8), SC(9), SC(10), SC(11), SC(12), SC(13), SC(14), SC(31)
};
#undef SC
-#define TL_MAX (EG_ENT*2) /* limit(tl + ksr + envelope) + sinwave */
+#define TL_MAX (EG_ENT*2) /* limit(tl + ksr + envelope) + sinwave */
/* TotalLevel : 48 24 12 6 3 1.5 0.75 (dB) */
/* TL_TABLE[ 0 to TL_MAX ] : plus section */
/* TL_TABLE[ TL_MAX to TL_MAX+TL_MAX-1 ] : minus section */
@@ -167,20 +165,21 @@ static INT32 *VIB_TABLE;
/* envelope output curve table */
/* attack + decay + OFF */
-static INT32 ENV_CURVE[2*EG_ENT+1];
+static INT32 ENV_CURVE[2 * EG_ENT + 1];
/* multiple table */
#define ML(x) (UINT32)(2*(x))
-static const UINT32 MUL_TABLE[16]= {
+static const UINT32 MUL_TABLE[16] = {
/* 1/2, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15 */
- ML(0.50), ML(1.00), ML(2.00), ML(3.00), ML(4.00), ML(5.00), ML(6.00), ML(7.00),
- ML(8.00), ML(9.00),ML(10.00),ML(10.00),ML(12.00),ML(12.00),ML(15.00),ML(15.00)
+ ML(0.50), ML(1.00), ML(2.00), ML(3.00), ML(4.00), ML(5.00), ML(6.00),
+ ML(7.00),
+ ML(8.00), ML(9.00), ML(10.00), ML(10.00), ML(12.00), ML(12.00), ML(15.00),
+ ML(15.00)
};
#undef ML
/* dummy attack / decay rate ( when rate == 0 ) */
-static INT32 RATE_0[16]=
-{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+static INT32 RATE_0[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
/* -------------------- static state --------------------- */
@@ -188,76 +187,75 @@ static INT32 RATE_0[16]=
static int num_lock = 0;
/* work table */
-static void *cur_chip = NULL; /* current chip point */
+static void *cur_chip = NULL; /* current chip point */
/* currenct chip state */
/* static OPLSAMPLE *bufL,*bufR; */
static OPL_CH *S_CH;
static OPL_CH *E_CH;
-OPL_SLOT *SLOT7_1,*SLOT7_2,*SLOT8_1,*SLOT8_2;
+OPL_SLOT *SLOT7_1, *SLOT7_2, *SLOT8_1, *SLOT8_2;
static INT32 outd[1];
static INT32 ams;
static INT32 vib;
-INT32 *ams_table;
-INT32 *vib_table;
+INT32 *ams_table;
+INT32 *vib_table;
static INT32 amsIncr;
static INT32 vibIncr;
-static INT32 feedback2; /* connect for SLOT 2 */
+static INT32 feedback2; /* connect for SLOT 2 */
/* --------------------- subroutines --------------------- */
-INLINE int Limit( int val, int max, int min ) {
- if ( val > max )
+INLINE int Limit(int val, int max, int min)
+{
+ if (val > max)
val = max;
- else if ( val < min )
+ else if (val < min)
val = min;
return val;
}
/* status set and IRQ handling */
-INLINE void OPL_STATUS_SET(FM_OPL *OPL,int flag)
+INLINE void OPL_STATUS_SET(FM_OPL * OPL, int flag)
{
/* set status flag */
OPL->status |= flag;
- if(!(OPL->status & 0x80))
- {
- if(OPL->status & OPL->statusmask)
- { /* IRQ on */
+ if (!(OPL->status & 0x80)) {
+ if (OPL->status & OPL->statusmask) { /* IRQ on */
OPL->status |= 0x80;
/* callback user interrupt handler (IRQ is OFF to ON) */
- if(OPL->IRQHandler) (OPL->IRQHandler)(OPL->IRQParam,1);
+ if (OPL->IRQHandler)
+ (OPL->IRQHandler) (OPL->IRQParam, 1);
}
}
}
/* status reset and IRQ handling */
-INLINE void OPL_STATUS_RESET(FM_OPL *OPL,int flag)
+INLINE void OPL_STATUS_RESET(FM_OPL * OPL, int flag)
{
/* reset status flag */
- OPL->status &=~flag;
- if((OPL->status & 0x80))
- {
- if (!(OPL->status & OPL->statusmask) )
- {
+ OPL->status &= ~flag;
+ if ((OPL->status & 0x80)) {
+ if (!(OPL->status & OPL->statusmask)) {
OPL->status &= 0x7f;
/* callback user interrupt handler (IRQ is ON to OFF) */
- if(OPL->IRQHandler) (OPL->IRQHandler)(OPL->IRQParam,0);
+ if (OPL->IRQHandler)
+ (OPL->IRQHandler) (OPL->IRQParam, 0);
}
}
}
/* IRQ mask set */
-INLINE void OPL_STATUSMASK_SET(FM_OPL *OPL,int flag)
+INLINE void OPL_STATUSMASK_SET(FM_OPL * OPL, int flag)
{
OPL->statusmask = flag;
/* IRQ handling check */
- OPL_STATUS_SET(OPL,0);
- OPL_STATUS_RESET(OPL,0);
+ OPL_STATUS_SET(OPL, 0);
+ OPL_STATUS_RESET(OPL, 0);
}
/* ----- key on ----- */
-INLINE void OPL_KEYON(OPL_SLOT *SLOT)
+INLINE void OPL_KEYON(OPL_SLOT * SLOT)
{
/* sin wave restart */
SLOT->Cnt = 0;
@@ -268,13 +266,12 @@ INLINE void OPL_KEYON(OPL_SLOT *SLOT)
SLOT->eve = EG_AED;
}
/* ----- key off ----- */
-INLINE void OPL_KEYOFF(OPL_SLOT *SLOT)
+INLINE void OPL_KEYOFF(OPL_SLOT * SLOT)
{
- if( SLOT->evm > ENV_MOD_RR)
- {
+ if (SLOT->evm > ENV_MOD_RR) {
/* set envelope counter from envleope output */
SLOT->evm = ENV_MOD_RR;
- if( !(SLOT->evc&EG_DST) )
+ if (!(SLOT->evc & EG_DST))
//SLOT->evc = (ENV_CURVE[SLOT->evc>>ENV_BITS]<<ENV_BITS) + EG_DST;
SLOT->evc = EG_DST;
SLOT->eve = EG_DED;
@@ -284,45 +281,41 @@ INLINE void OPL_KEYOFF(OPL_SLOT *SLOT)
/* ---------- calcrate Envelope Generator & Phase Generator ---------- */
/* return : envelope output */
-INLINE UINT32 OPL_CALC_SLOT( OPL_SLOT *SLOT )
+INLINE UINT32 OPL_CALC_SLOT(OPL_SLOT * SLOT)
{
/* calcrate envelope generator */
- if( (SLOT->evc+=SLOT->evs) >= SLOT->eve )
- {
- switch( SLOT->evm ){
- case ENV_MOD_AR: /* ATTACK -> DECAY1 */
+ if ((SLOT->evc += SLOT->evs) >= SLOT->eve) {
+ switch (SLOT->evm) {
+ case ENV_MOD_AR: /* ATTACK -> DECAY1 */
/* next DR */
SLOT->evm = ENV_MOD_DR;
SLOT->evc = EG_DST;
SLOT->eve = SLOT->SL;
SLOT->evs = SLOT->evsd;
break;
- case ENV_MOD_DR: /* DECAY -> SL or RR */
+ case ENV_MOD_DR: /* DECAY -> SL or RR */
SLOT->evc = SLOT->SL;
SLOT->eve = EG_DED;
- if(SLOT->eg_typ)
- {
+ if (SLOT->eg_typ) {
SLOT->evs = 0;
- }
- else
- {
+ } else {
SLOT->evm = ENV_MOD_RR;
SLOT->evs = SLOT->evsr;
}
break;
- case ENV_MOD_RR: /* RR -> OFF */
+ case ENV_MOD_RR: /* RR -> OFF */
SLOT->evc = EG_OFF;
- SLOT->eve = EG_OFF+1;
+ SLOT->eve = EG_OFF + 1;
SLOT->evs = 0;
break;
}
}
/* calcrate envelope */
- return SLOT->TLL+ENV_CURVE[SLOT->evc>>ENV_BITS]+(SLOT->ams ? ams : 0);
+ return SLOT->TLL + ENV_CURVE[SLOT->evc >> ENV_BITS] + (SLOT->ams ? ams : 0);
}
/* set algorythm connection */
-static void set_algorythm( OPL_CH *CH)
+static void set_algorythm(OPL_CH * CH)
{
INT32 *carrier = &outd[0];
CH->connect1 = CH->CON ? carrier : &feedback2;
@@ -330,7 +323,7 @@ static void set_algorythm( OPL_CH *CH)
}
/* ---------- frequency counter for operater update ---------- */
-INLINE void CALC_FCSLOT(OPL_CH *CH,OPL_SLOT *SLOT)
+INLINE void CALC_FCSLOT(OPL_CH * CH, OPL_SLOT * SLOT)
{
int ksr;
@@ -338,83 +331,85 @@ INLINE void CALC_FCSLOT(OPL_CH *CH,OPL_SLOT *SLOT)
SLOT->Incr = CH->fc * SLOT->mul;
ksr = CH->kcode >> SLOT->KSR;
- if( SLOT->ksr != ksr )
- {
+ if (SLOT->ksr != ksr) {
SLOT->ksr = ksr;
/* attack , decay rate recalcration */
SLOT->evsa = SLOT->AR[ksr];
SLOT->evsd = SLOT->DR[ksr];
SLOT->evsr = SLOT->RR[ksr];
}
- SLOT->TLL = SLOT->TL + (CH->ksl_base>>SLOT->ksl);
+ SLOT->TLL = SLOT->TL + (CH->ksl_base >> SLOT->ksl);
}
/* set multi,am,vib,EG-TYP,KSR,mul */
-INLINE void set_mul(FM_OPL *OPL,int slot,int v)
+INLINE void set_mul(FM_OPL * OPL, int slot, int v)
{
- OPL_CH *CH = &OPL->P_CH[slot/2];
- OPL_SLOT *SLOT = &CH->SLOT[slot&1];
-
- SLOT->mul = MUL_TABLE[v&0x0f];
- SLOT->KSR = (v&0x10) ? 0 : 2;
- SLOT->eg_typ = (v&0x20)>>5;
- SLOT->vib = (v&0x40);
- SLOT->ams = (v&0x80);
- CALC_FCSLOT(CH,SLOT);
+ OPL_CH *CH = &OPL->P_CH[slot / 2];
+ OPL_SLOT *SLOT = &CH->SLOT[slot & 1];
+
+ SLOT->mul = MUL_TABLE[v & 0x0f];
+ SLOT->KSR = (v & 0x10) ? 0 : 2;
+ SLOT->eg_typ = (v & 0x20) >> 5;
+ SLOT->vib = (v & 0x40);
+ SLOT->ams = (v & 0x80);
+ CALC_FCSLOT(CH, SLOT);
}
/* set ksl & tl */
-INLINE void set_ksl_tl(FM_OPL *OPL,int slot,int v)
+INLINE void set_ksl_tl(FM_OPL * OPL, int slot, int v)
{
- OPL_CH *CH = &OPL->P_CH[slot/2];
- OPL_SLOT *SLOT = &CH->SLOT[slot&1];
- int ksl = v>>6; /* 0 / 1.5 / 3 / 6 db/OCT */
+ OPL_CH *CH = &OPL->P_CH[slot / 2];
+ OPL_SLOT *SLOT = &CH->SLOT[slot & 1];
+ int ksl = v >> 6; /* 0 / 1.5 / 3 / 6 db/OCT */
- SLOT->ksl = ksl ? 3-ksl : 31;
- SLOT->TL = (INT32) ((v&0x3f)*(0.75/EG_STEP)); /* 0.75db step */
+ SLOT->ksl = ksl ? 3 - ksl : 31;
+ SLOT->TL = (INT32) ((v & 0x3f) * (0.75 / EG_STEP)); /* 0.75db step */
- if( !(OPL->mode&0x80) )
- { /* not CSM latch total level */
- SLOT->TLL = SLOT->TL + (CH->ksl_base>>SLOT->ksl);
+ if (!(OPL->mode & 0x80)) { /* not CSM latch total level */
+ SLOT->TLL = SLOT->TL + (CH->ksl_base >> SLOT->ksl);
}
}
/* set attack rate & decay rate */
-INLINE void set_ar_dr(FM_OPL *OPL,int slot,int v)
+INLINE void set_ar_dr(FM_OPL * OPL, int slot, int v)
{
- OPL_CH *CH = &OPL->P_CH[slot/2];
- OPL_SLOT *SLOT = &CH->SLOT[slot&1];
- int ar = v>>4;
- int dr = v&0x0f;
+ OPL_CH *CH = &OPL->P_CH[slot / 2];
+ OPL_SLOT *SLOT = &CH->SLOT[slot & 1];
+ int ar = v >> 4;
+ int dr = v & 0x0f;
- SLOT->AR = ar ? &OPL->AR_TABLE[ar<<2] : RATE_0;
+ SLOT->AR = ar ? &OPL->AR_TABLE[ar << 2] : RATE_0;
SLOT->evsa = SLOT->AR[SLOT->ksr];
- if( SLOT->evm == ENV_MOD_AR ) SLOT->evs = SLOT->evsa;
+ if (SLOT->evm == ENV_MOD_AR)
+ SLOT->evs = SLOT->evsa;
- SLOT->DR = dr ? &OPL->DR_TABLE[dr<<2] : RATE_0;
+ SLOT->DR = dr ? &OPL->DR_TABLE[dr << 2] : RATE_0;
SLOT->evsd = SLOT->DR[SLOT->ksr];
- if( SLOT->evm == ENV_MOD_DR ) SLOT->evs = SLOT->evsd;
+ if (SLOT->evm == ENV_MOD_DR)
+ SLOT->evs = SLOT->evsd;
}
/* set sustain level & release rate */
-INLINE void set_sl_rr(FM_OPL *OPL,int slot,int v)
+INLINE void set_sl_rr(FM_OPL * OPL, int slot, int v)
{
- OPL_CH *CH = &OPL->P_CH[slot/2];
- OPL_SLOT *SLOT = &CH->SLOT[slot&1];
- int sl = v>>4;
+ OPL_CH *CH = &OPL->P_CH[slot / 2];
+ OPL_SLOT *SLOT = &CH->SLOT[slot & 1];
+ int sl = v >> 4;
int rr = v & 0x0f;
SLOT->SL = SL_TABLE[sl];
- if( SLOT->evm == ENV_MOD_DR ) SLOT->eve = SLOT->SL;
- SLOT->RR = &OPL->DR_TABLE[rr<<2];
+ if (SLOT->evm == ENV_MOD_DR)
+ SLOT->eve = SLOT->SL;
+ SLOT->RR = &OPL->DR_TABLE[rr << 2];
SLOT->evsr = SLOT->RR[SLOT->ksr];
- if( SLOT->evm == ENV_MOD_RR ) SLOT->evs = SLOT->evsr;
+ if (SLOT->evm == ENV_MOD_RR)
+ SLOT->evs = SLOT->evsr;
}
/* operator output calcrator */
#define OP_OUT(slot,env,con) slot->wavetable[((slot->Cnt+con)/(0x1000000/SIN_ENT))&(SIN_ENT-1)][env]
/* ---------- calcrate one of channel ---------- */
-INLINE void OPL_CALC_CH( OPL_CH *CH )
+INLINE void OPL_CALC_CH(OPL_CH * CH)
{
UINT32 env_out;
OPL_SLOT *SLOT;
@@ -422,47 +417,45 @@ INLINE void OPL_CALC_CH( OPL_CH *CH )
feedback2 = 0;
/* SLOT 1 */
SLOT = &CH->SLOT[SLOT1];
- env_out=OPL_CALC_SLOT(SLOT);
- if( env_out < EG_ENT-1 )
- {
+ env_out = OPL_CALC_SLOT(SLOT);
+ if (env_out < EG_ENT - 1) {
/* PG */
- if(SLOT->vib) SLOT->Cnt += (SLOT->Incr*vib/VIB_RATE);
- else SLOT->Cnt += SLOT->Incr;
+ if (SLOT->vib)
+ SLOT->Cnt += (SLOT->Incr * vib / VIB_RATE);
+ else
+ SLOT->Cnt += SLOT->Incr;
/* connectoion */
- if(CH->FB)
- {
- int feedback1 = (CH->op1_out[0]+CH->op1_out[1])>>CH->FB;
+ if (CH->FB) {
+ int feedback1 = (CH->op1_out[0] + CH->op1_out[1]) >> CH->FB;
CH->op1_out[1] = CH->op1_out[0];
- *CH->connect1 += CH->op1_out[0] = OP_OUT(SLOT,env_out,feedback1);
+ *CH->connect1 += CH->op1_out[0] = OP_OUT(SLOT, env_out, feedback1);
+ } else {
+ *CH->connect1 += OP_OUT(SLOT, env_out, 0);
}
- else
- {
- *CH->connect1 += OP_OUT(SLOT,env_out,0);
- }
- }else
- {
+ } else {
CH->op1_out[1] = CH->op1_out[0];
CH->op1_out[0] = 0;
}
/* SLOT 2 */
SLOT = &CH->SLOT[SLOT2];
- env_out=OPL_CALC_SLOT(SLOT);
- if( env_out < EG_ENT-1 )
- {
+ env_out = OPL_CALC_SLOT(SLOT);
+ if (env_out < EG_ENT - 1) {
/* PG */
- if(SLOT->vib) SLOT->Cnt += (SLOT->Incr*vib/VIB_RATE);
- else SLOT->Cnt += SLOT->Incr;
+ if (SLOT->vib)
+ SLOT->Cnt += (SLOT->Incr * vib / VIB_RATE);
+ else
+ SLOT->Cnt += SLOT->Incr;
/* connectoion */
- outd[0] += OP_OUT(SLOT,env_out, feedback2);
+ outd[0] += OP_OUT(SLOT, env_out, feedback2);
}
}
/* ---------- calcrate rythm block ---------- */
#define WHITE_NOISE_db 6.0
-INLINE void OPL_CALC_RH( OPL_CH *CH )
+INLINE void OPL_CALC_RH(OPL_CH * CH)
{
- UINT32 env_tam,env_sd,env_top,env_hh;
- int whitenoise = (int) ((rand()&1)*(WHITE_NOISE_db/EG_STEP));
+ UINT32 env_tam, env_sd, env_top, env_hh;
+ int whitenoise = (int)((rand() & 1) * (WHITE_NOISE_db / EG_STEP));
INT32 tone8;
OPL_SLOT *SLOT;
@@ -472,194 +465,197 @@ INLINE void OPL_CALC_RH( OPL_CH *CH )
feedback2 = 0;
/* SLOT 1 */
SLOT = &CH[6].SLOT[SLOT1];
- env_out=OPL_CALC_SLOT(SLOT);
- if( env_out < EG_ENT-1 )
- {
+ env_out = OPL_CALC_SLOT(SLOT);
+ if (env_out < EG_ENT - 1) {
/* PG */
- if(SLOT->vib) SLOT->Cnt += (SLOT->Incr*vib/VIB_RATE);
- else SLOT->Cnt += SLOT->Incr;
+ if (SLOT->vib)
+ SLOT->Cnt += (SLOT->Incr * vib / VIB_RATE);
+ else
+ SLOT->Cnt += SLOT->Incr;
/* connectoion */
- if(CH[6].FB)
- {
- int feedback1 = (CH[6].op1_out[0]+CH[6].op1_out[1])>>CH[6].FB;
+ if (CH[6].FB) {
+ int feedback1 = (CH[6].op1_out[0] + CH[6].op1_out[1]) >> CH[6].FB;
CH[6].op1_out[1] = CH[6].op1_out[0];
- feedback2 = CH[6].op1_out[0] = OP_OUT(SLOT,env_out,feedback1);
+ feedback2 = CH[6].op1_out[0] = OP_OUT(SLOT, env_out, feedback1);
+ } else {
+ feedback2 = OP_OUT(SLOT, env_out, 0);
}
- else
- {
- feedback2 = OP_OUT(SLOT,env_out,0);
- }
- }else
- {
+ } else {
feedback2 = 0;
CH[6].op1_out[1] = CH[6].op1_out[0];
CH[6].op1_out[0] = 0;
}
/* SLOT 2 */
SLOT = &CH[6].SLOT[SLOT2];
- env_out=OPL_CALC_SLOT(SLOT);
- if( env_out < EG_ENT-1 )
- {
+ env_out = OPL_CALC_SLOT(SLOT);
+ if (env_out < EG_ENT - 1) {
/* PG */
- if(SLOT->vib) SLOT->Cnt += (SLOT->Incr*vib/VIB_RATE);
- else SLOT->Cnt += SLOT->Incr;
+ if (SLOT->vib)
+ SLOT->Cnt += (SLOT->Incr * vib / VIB_RATE);
+ else
+ SLOT->Cnt += SLOT->Incr;
/* connectoion */
- outd[0] += OP_OUT(SLOT,env_out, feedback2)*2;
+ outd[0] += OP_OUT(SLOT, env_out, feedback2) * 2;
}
-
// SD (17) = mul14[fnum7] + white noise
// TAM (15) = mul15[fnum8]
// TOP (18) = fnum6(mul18[fnum8]+whitenoise)
// HH (14) = fnum7(mul18[fnum8]+whitenoise) + white noise
- env_sd =OPL_CALC_SLOT(SLOT7_2) + whitenoise;
- env_tam=OPL_CALC_SLOT(SLOT8_1);
- env_top=OPL_CALC_SLOT(SLOT8_2);
- env_hh =OPL_CALC_SLOT(SLOT7_1) + whitenoise;
+ env_sd = OPL_CALC_SLOT(SLOT7_2) + whitenoise;
+ env_tam = OPL_CALC_SLOT(SLOT8_1);
+ env_top = OPL_CALC_SLOT(SLOT8_2);
+ env_hh = OPL_CALC_SLOT(SLOT7_1) + whitenoise;
/* PG */
- if(SLOT7_1->vib) SLOT7_1->Cnt += (2*SLOT7_1->Incr*vib/VIB_RATE);
- else SLOT7_1->Cnt += 2*SLOT7_1->Incr;
- if(SLOT7_2->vib) SLOT7_2->Cnt += ((CH[7].fc*8)*vib/VIB_RATE);
- else SLOT7_2->Cnt += (CH[7].fc*8);
- if(SLOT8_1->vib) SLOT8_1->Cnt += (SLOT8_1->Incr*vib/VIB_RATE);
- else SLOT8_1->Cnt += SLOT8_1->Incr;
- if(SLOT8_2->vib) SLOT8_2->Cnt += ((CH[8].fc*48)*vib/VIB_RATE);
- else SLOT8_2->Cnt += (CH[8].fc*48);
+ if (SLOT7_1->vib)
+ SLOT7_1->Cnt += (2 * SLOT7_1->Incr * vib / VIB_RATE);
+ else
+ SLOT7_1->Cnt += 2 * SLOT7_1->Incr;
+ if (SLOT7_2->vib)
+ SLOT7_2->Cnt += ((CH[7].fc * 8) * vib / VIB_RATE);
+ else
+ SLOT7_2->Cnt += (CH[7].fc * 8);
+ if (SLOT8_1->vib)
+ SLOT8_1->Cnt += (SLOT8_1->Incr * vib / VIB_RATE);
+ else
+ SLOT8_1->Cnt += SLOT8_1->Incr;
+ if (SLOT8_2->vib)
+ SLOT8_2->Cnt += ((CH[8].fc * 48) * vib / VIB_RATE);
+ else
+ SLOT8_2->Cnt += (CH[8].fc * 48);
- tone8 = OP_OUT(SLOT8_2,whitenoise,0 );
+ tone8 = OP_OUT(SLOT8_2, whitenoise, 0);
/* SD */
- if( env_sd < EG_ENT-1 )
- outd[0] += OP_OUT(SLOT7_1,env_sd, 0)*8;
+ if (env_sd < EG_ENT - 1)
+ outd[0] += OP_OUT(SLOT7_1, env_sd, 0) * 8;
/* TAM */
- if( env_tam < EG_ENT-1 )
- outd[0] += OP_OUT(SLOT8_1,env_tam, 0)*2;
+ if (env_tam < EG_ENT - 1)
+ outd[0] += OP_OUT(SLOT8_1, env_tam, 0) * 2;
/* TOP-CY */
- if( env_top < EG_ENT-1 )
- outd[0] += OP_OUT(SLOT7_2,env_top,tone8)*2;
+ if (env_top < EG_ENT - 1)
+ outd[0] += OP_OUT(SLOT7_2, env_top, tone8) * 2;
/* HH */
- if( env_hh < EG_ENT-1 )
- outd[0] += OP_OUT(SLOT7_2,env_hh,tone8)*2;
+ if (env_hh < EG_ENT - 1)
+ outd[0] += OP_OUT(SLOT7_2, env_hh, tone8) * 2;
}
/* ----------- initialize time tabls ----------- */
-static void init_timetables( FM_OPL *OPL , int ARRATE , int DRRATE )
+static void init_timetables(FM_OPL * OPL, int ARRATE, int DRRATE)
{
int i;
double rate;
/* make attack rate & decay rate tables */
- for (i = 0;i < 4;i++) OPL->AR_TABLE[i] = OPL->DR_TABLE[i] = 0;
- for (i = 4;i <= 60;i++){
- rate = OPL->freqbase; /* frequency rate */
- if( i < 60 ) rate *= 1.0+(i&3)*0.25; /* b0-1 : x1 , x1.25 , x1.5 , x1.75 */
- rate *= 1<<((i>>2)-1); /* b2-5 : shift bit */
- rate *= (double)(EG_ENT<<ENV_BITS);
- OPL->AR_TABLE[i] = (int) (rate / ARRATE);
- OPL->DR_TABLE[i] = (int) (rate / DRRATE);
+ for (i = 0; i < 4; i++)
+ OPL->AR_TABLE[i] = OPL->DR_TABLE[i] = 0;
+ for (i = 4; i <= 60; i++) {
+ rate = OPL->freqbase; /* frequency rate */
+ if (i < 60)
+ rate *= 1.0 + (i & 3) * 0.25; /* b0-1 : x1 , x1.25 , x1.5 , x1.75 */
+ rate *= 1 << ((i >> 2) - 1); /* b2-5 : shift bit */
+ rate *= (double)(EG_ENT << ENV_BITS);
+ OPL->AR_TABLE[i] = (int)(rate / ARRATE);
+ OPL->DR_TABLE[i] = (int)(rate / DRRATE);
}
- for (i = 60;i < 75;i++)
- {
- OPL->AR_TABLE[i] = EG_AED-1;
+ for (i = 60; i < 75; i++) {
+ OPL->AR_TABLE[i] = EG_AED - 1;
OPL->DR_TABLE[i] = OPL->DR_TABLE[60];
}
}
/* ---------- generic table initialize ---------- */
-static int OPLOpenTable( void )
+static int OPLOpenTable(void)
{
- int s,t;
+ int s, t;
double rate;
- int i,j;
+ int i, j;
double pom;
/* allocate dynamic tables */
- if( (TL_TABLE = (INT32*)malloc(TL_MAX*2*sizeof(INT32))) == NULL)
+ if ((TL_TABLE = (INT32 *) malloc(TL_MAX * 2 * sizeof(INT32))) == NULL)
return 0;
- if( (SIN_TABLE = (INT32**)malloc(SIN_ENT*4 *sizeof(INT32 *))) == NULL)
- {
+ if ((SIN_TABLE = (INT32 **) malloc(SIN_ENT * 4 * sizeof(INT32 *))) == NULL) {
free(TL_TABLE);
return 0;
}
- if( (AMS_TABLE = (INT32*)malloc(AMS_ENT*2 *sizeof(INT32))) == NULL)
- {
+ if ((AMS_TABLE = (INT32 *) malloc(AMS_ENT * 2 * sizeof(INT32))) == NULL) {
free(SIN_TABLE);
free(TL_TABLE);
return 0;
}
- if( (VIB_TABLE = (INT32*)malloc(VIB_ENT*2 *sizeof(INT32))) == NULL)
- {
+ if ((VIB_TABLE = (INT32 *) malloc(VIB_ENT * 2 * sizeof(INT32))) == NULL) {
free(AMS_TABLE);
free(TL_TABLE);
free(SIN_TABLE);
return 0;
}
/* make total level table */
- for (t = 0;t < EG_ENT-1 ;t++){
- rate = ((1<<TL_BITS)-1)/pow(10,EG_STEP*t/20); /* dB -> voltage */
- TL_TABLE[ t] = (int)rate;
- TL_TABLE[TL_MAX+t] = -TL_TABLE[t];
+ for (t = 0; t < EG_ENT - 1; t++) {
+ rate = ((1 << TL_BITS) - 1) / pow(10, EG_STEP * t / 20); /* dB -> voltage */
+ TL_TABLE[t] = (int)rate;
+ TL_TABLE[TL_MAX + t] = -TL_TABLE[t];
/* LOG(LOG_INF,("TotalLevel(%3d) = %x\n",t,TL_TABLE[t]));*/
}
/* fill volume off area */
- for ( t = EG_ENT-1; t < TL_MAX ;t++){
- TL_TABLE[t] = TL_TABLE[TL_MAX+t] = 0;
+ for (t = EG_ENT - 1; t < TL_MAX; t++) {
+ TL_TABLE[t] = TL_TABLE[TL_MAX + t] = 0;
}
/* make sinwave table (total level offet) */
/* degree 0 = degree 180 = off */
- SIN_TABLE[0] = SIN_TABLE[SIN_ENT/2] = &TL_TABLE[EG_ENT-1];
- for (s = 1;s <= SIN_ENT/4;s++){
- pom = sin(2*PI*s/SIN_ENT); /* sin */
- pom = 20*log10(1/pom); /* decibel */
- j = (int) (pom / EG_STEP); /* TL_TABLE steps */
-
- /* degree 0 - 90 , degree 180 - 90 : plus section */
- SIN_TABLE[ s] = SIN_TABLE[SIN_ENT/2-s] = &TL_TABLE[j];
- /* degree 180 - 270 , degree 360 - 270 : minus section */
- SIN_TABLE[SIN_ENT/2+s] = SIN_TABLE[SIN_ENT -s] = &TL_TABLE[TL_MAX+j];
+ SIN_TABLE[0] = SIN_TABLE[SIN_ENT / 2] = &TL_TABLE[EG_ENT - 1];
+ for (s = 1; s <= SIN_ENT / 4; s++) {
+ pom = sin(2 * PI * s / SIN_ENT); /* sin */
+ pom = 20 * log10(1 / pom); /* decibel */
+ j = (int)(pom / EG_STEP); /* TL_TABLE steps */
+
+ /* degree 0 - 90 , degree 180 - 90 : plus section */
+ SIN_TABLE[s] = SIN_TABLE[SIN_ENT / 2 - s] = &TL_TABLE[j];
+ /* degree 180 - 270 , degree 360 - 270 : minus section */
+ SIN_TABLE[SIN_ENT / 2 + s] = SIN_TABLE[SIN_ENT - s] =
+ &TL_TABLE[TL_MAX + j];
/* LOG(LOG_INF,("sin(%3d) = %f:%f db\n",s,pom,(double)j * EG_STEP));*/
}
- for (s = 0;s < SIN_ENT;s++)
- {
- SIN_TABLE[SIN_ENT*1+s] = s<(SIN_ENT/2) ? SIN_TABLE[s] : &TL_TABLE[EG_ENT];
- SIN_TABLE[SIN_ENT*2+s] = SIN_TABLE[s % (SIN_ENT/2)];
- SIN_TABLE[SIN_ENT*3+s] = (s/(SIN_ENT/4))&1 ? &TL_TABLE[EG_ENT] : SIN_TABLE[SIN_ENT*2+s];
+ for (s = 0; s < SIN_ENT; s++) {
+ SIN_TABLE[SIN_ENT * 1 + s] =
+ s < (SIN_ENT / 2) ? SIN_TABLE[s] : &TL_TABLE[EG_ENT];
+ SIN_TABLE[SIN_ENT * 2 + s] = SIN_TABLE[s % (SIN_ENT / 2)];
+ SIN_TABLE[SIN_ENT * 3 + s] =
+ (s / (SIN_ENT / 4)) & 1 ? &TL_TABLE[EG_ENT] : SIN_TABLE[SIN_ENT * 2 +
+ s];
}
/* envelope counter -> envelope output table */
- for (i=0; i<EG_ENT; i++)
- {
+ for (i = 0; i < EG_ENT; i++) {
/* ATTACK curve */
- pom = pow( ((double)(EG_ENT-1-i)/EG_ENT) , 8 ) * EG_ENT;
+ pom = pow(((double)(EG_ENT - 1 - i) / EG_ENT), 8) * EG_ENT;
/* if( pom >= EG_ENT ) pom = EG_ENT-1; */
ENV_CURVE[i] = (int)pom;
/* DECAY ,RELEASE curve */
- ENV_CURVE[(EG_DST>>ENV_BITS)+i]= i;
+ ENV_CURVE[(EG_DST >> ENV_BITS) + i] = i;
}
/* off */
- ENV_CURVE[EG_OFF>>ENV_BITS]= EG_ENT-1;
+ ENV_CURVE[EG_OFF >> ENV_BITS] = EG_ENT - 1;
/* make LFO ams table */
- for (i=0; i<AMS_ENT; i++)
- {
- pom = (1.0+sin(2*PI*i/AMS_ENT))/2; /* sin */
- AMS_TABLE[i] = (int) ((1.0/EG_STEP)*pom); /* 1dB */
- AMS_TABLE[AMS_ENT+i] = (int) ((4.8/EG_STEP)*pom); /* 4.8dB */
+ for (i = 0; i < AMS_ENT; i++) {
+ pom = (1.0 + sin(2 * PI * i / AMS_ENT)) / 2; /* sin */
+ AMS_TABLE[i] = (int)((1.0 / EG_STEP) * pom); /* 1dB */
+ AMS_TABLE[AMS_ENT + i] = (int)((4.8 / EG_STEP) * pom); /* 4.8dB */
}
/* make LFO vibrate table */
- for (i=0; i<VIB_ENT; i++)
- {
+ for (i = 0; i < VIB_ENT; i++) {
/* 100cent = 1seminote = 6% ?? */
- pom = (double)VIB_RATE*0.06*sin(2*PI*i/VIB_ENT); /* +-100sect step */
- VIB_TABLE[i] = (int) (VIB_RATE + (pom*0.07)); /* +- 7cent */
- VIB_TABLE[VIB_ENT+i] = (int) (VIB_RATE + (pom*0.14)); /* +-14cent */
+ pom = (double)VIB_RATE *0.06 * sin(2 * PI * i / VIB_ENT); /* +-100sect step */
+ VIB_TABLE[i] = (int)(VIB_RATE + (pom * 0.07)); /* +- 7cent */
+ VIB_TABLE[VIB_ENT + i] = (int)(VIB_RATE + (pom * 0.14)); /* +-14cent */
/* LOG(LOG_INF,("vib %d=%d\n",i,VIB_TABLE[VIB_ENT+i])); */
}
return 1;
}
-static void OPLCloseTable( void )
+static void OPLCloseTable(void)
{
free(TL_TABLE);
free(SIN_TABLE);
@@ -668,7 +664,7 @@ static void OPLCloseTable( void )
}
/* CSM Key Controll */
-INLINE void CSMKeyControll(OPL_CH *CH)
+INLINE void CSMKeyControll(OPL_CH * CH)
{
OPL_SLOT *slot1 = &CH->SLOT[SLOT1];
OPL_SLOT *slot2 = &CH->SLOT[SLOT2];
@@ -676,8 +672,8 @@ INLINE void CSMKeyControll(OPL_CH *CH)
OPL_KEYOFF(slot1);
OPL_KEYOFF(slot2);
/* total level latch */
- slot1->TLL = slot1->TL + (CH->ksl_base>>slot1->ksl);
- slot1->TLL = slot1->TL + (CH->ksl_base>>slot1->ksl);
+ slot1->TLL = slot1->TL + (CH->ksl_base >> slot1->ksl);
+ slot1->TLL = slot1->TL + (CH->ksl_base >> slot1->ksl);
/* key on */
CH->op1_out[0] = CH->op1_out[1] = 0;
OPL_KEYON(slot1);
@@ -685,228 +681,220 @@ INLINE void CSMKeyControll(OPL_CH *CH)
}
/* ---------- opl initialize ---------- */
-static void OPL_initalize(FM_OPL *OPL)
+static void OPL_initalize(FM_OPL * OPL)
{
int fn;
/* frequency base */
- OPL->freqbase = (OPL->rate) ? ((double)OPL->clock / OPL->rate) / 72 : 0;
+ OPL->freqbase = (OPL->rate) ? ((double)OPL->clock / OPL->rate) / 72 : 0;
/* Timer base time */
- OPL->TimerBase = 1.0/((double)OPL->clock / 72.0 );
+ OPL->TimerBase = 1.0 / ((double)OPL->clock / 72.0);
/* make time tables */
- init_timetables( OPL , OPL_ARRATE , OPL_DRRATE );
+ init_timetables(OPL, OPL_ARRATE, OPL_DRRATE);
/* make fnumber -> increment counter table */
- for( fn=0 ; fn < 1024 ; fn++ )
- {
- OPL->FN_TABLE[fn] = (int) (OPL->freqbase * fn * FREQ_RATE * (1<<7) / 2);
+ for (fn = 0; fn < 1024; fn++) {
+ OPL->FN_TABLE[fn] = (int)(OPL->freqbase * fn * FREQ_RATE * (1 << 7) / 2);
}
/* LFO freq.table */
- OPL->amsIncr = (INT32) (OPL->rate ? (double)AMS_ENT*(1<<AMS_SHIFT) / OPL->rate * 3.7 * ((double)OPL->clock/3600000) : 0);
- OPL->vibIncr = (INT32) (OPL->rate ? (double)VIB_ENT*(1<<VIB_SHIFT) / OPL->rate * 6.4 * ((double)OPL->clock/3600000) : 0);
+ OPL->amsIncr =
+ (INT32) (OPL->rate ? (double)AMS_ENT * (1 << AMS_SHIFT) / OPL->rate *
+ 3.7 * ((double)OPL->clock / 3600000) : 0);
+ OPL->vibIncr =
+ (INT32) (OPL->rate ? (double)VIB_ENT * (1 << VIB_SHIFT) / OPL->rate *
+ 6.4 * ((double)OPL->clock / 3600000) : 0);
}
/* ---------- write a OPL registers ---------- */
-void OPLWriteReg(FM_OPL *OPL, int r, int v)
+void OPLWriteReg(FM_OPL * OPL, int r, int v)
{
OPL_CH *CH;
int slot;
unsigned int block_fnum;
- switch(r&0xe0)
- {
- case 0x00: /* 00-1f:controll */
- switch(r&0x1f)
- {
+ switch (r & 0xe0) {
+ case 0x00: /* 00-1f:controll */
+ switch (r & 0x1f) {
case 0x01:
/* wave selector enable */
- if(OPL->type&OPL_TYPE_WAVESEL)
- {
- OPL->wavesel = v&0x20;
- if(!OPL->wavesel)
- {
+ if (OPL->type & OPL_TYPE_WAVESEL) {
+ OPL->wavesel = v & 0x20;
+ if (!OPL->wavesel) {
/* preset compatible mode */
int c;
- for(c=0;c<OPL->max_ch;c++)
- {
+ for (c = 0; c < OPL->max_ch; c++) {
OPL->P_CH[c].SLOT[SLOT1].wavetable = &SIN_TABLE[0];
OPL->P_CH[c].SLOT[SLOT2].wavetable = &SIN_TABLE[0];
}
}
}
return;
- case 0x02: /* Timer 1 */
- OPL->T[0] = (256-v)*4;
+ case 0x02: /* Timer 1 */
+ OPL->T[0] = (256 - v) * 4;
break;
- case 0x03: /* Timer 2 */
- OPL->T[1] = (256-v)*16;
+ case 0x03: /* Timer 2 */
+ OPL->T[1] = (256 - v) * 16;
return;
- case 0x04: /* IRQ clear / mask and Timer enable */
- if(v&0x80)
- { /* IRQ flag clear */
- OPL_STATUS_RESET(OPL,0x7f);
- }
- else
- { /* set IRQ mask ,timer enable*/
- UINT8 st1 = v&1;
- UINT8 st2 = (v>>1)&1;
+ case 0x04: /* IRQ clear / mask and Timer enable */
+ if (v & 0x80) { /* IRQ flag clear */
+ OPL_STATUS_RESET(OPL, 0x7f);
+ } else { /* set IRQ mask ,timer enable */
+ UINT8 st1 = v & 1;
+ UINT8 st2 = (v >> 1) & 1;
/* IRQRST,T1MSK,t2MSK,EOSMSK,BRMSK,x,ST2,ST1 */
- OPL_STATUS_RESET(OPL,v&0x78);
- OPL_STATUSMASK_SET(OPL,((~v)&0x78)|0x01);
+ OPL_STATUS_RESET(OPL, v & 0x78);
+ OPL_STATUSMASK_SET(OPL, ((~v) & 0x78) | 0x01);
/* timer 2 */
- if(OPL->st[1] != st2)
- {
- double interval = st2 ? (double)OPL->T[1]*OPL->TimerBase : 0.0;
+ if (OPL->st[1] != st2) {
+ double interval = st2 ? (double)OPL->T[1] * OPL->TimerBase : 0.0;
OPL->st[1] = st2;
- if (OPL->TimerHandler) (OPL->TimerHandler)(OPL->TimerParam+1,interval);
+ if (OPL->TimerHandler)
+ (OPL->TimerHandler) (OPL->TimerParam + 1, interval);
}
/* timer 1 */
- if(OPL->st[0] != st1)
- {
- double interval = st1 ? (double)OPL->T[0]*OPL->TimerBase : 0.0;
+ if (OPL->st[0] != st1) {
+ double interval = st1 ? (double)OPL->T[0] * OPL->TimerBase : 0.0;
OPL->st[0] = st1;
- if (OPL->TimerHandler) (OPL->TimerHandler)(OPL->TimerParam+0,interval);
+ if (OPL->TimerHandler)
+ (OPL->TimerHandler) (OPL->TimerParam + 0, interval);
}
}
return;
}
break;
- case 0x20: /* am,vib,ksr,eg type,mul */
- slot = slot_array[r&0x1f];
- if(slot == -1) return;
- set_mul(OPL,slot,v);
+ case 0x20: /* am,vib,ksr,eg type,mul */
+ slot = slot_array[r & 0x1f];
+ if (slot == -1)
+ return;
+ set_mul(OPL, slot, v);
return;
case 0x40:
- slot = slot_array[r&0x1f];
- if(slot == -1) return;
- set_ksl_tl(OPL,slot,v);
+ slot = slot_array[r & 0x1f];
+ if (slot == -1)
+ return;
+ set_ksl_tl(OPL, slot, v);
return;
case 0x60:
- slot = slot_array[r&0x1f];
- if(slot == -1) return;
- set_ar_dr(OPL,slot,v);
+ slot = slot_array[r & 0x1f];
+ if (slot == -1)
+ return;
+ set_ar_dr(OPL, slot, v);
return;
case 0x80:
- slot = slot_array[r&0x1f];
- if(slot == -1) return;
- set_sl_rr(OPL,slot,v);
+ slot = slot_array[r & 0x1f];
+ if (slot == -1)
+ return;
+ set_sl_rr(OPL, slot, v);
return;
case 0xa0:
- switch(r)
- {
+ switch (r) {
case 0xbd:
/* amsep,vibdep,r,bd,sd,tom,tc,hh */
{
- UINT8 rkey = OPL->rythm^v;
- OPL->ams_table = &AMS_TABLE[v&0x80 ? AMS_ENT : 0];
- OPL->vib_table = &VIB_TABLE[v&0x40 ? VIB_ENT : 0];
- OPL->rythm = v&0x3f;
- if(OPL->rythm&0x20)
- {
+ UINT8 rkey = OPL->rythm ^ v;
+ OPL->ams_table = &AMS_TABLE[v & 0x80 ? AMS_ENT : 0];
+ OPL->vib_table = &VIB_TABLE[v & 0x40 ? VIB_ENT : 0];
+ OPL->rythm = v & 0x3f;
+ if (OPL->rythm & 0x20) {
#if 0
- usrintf_showmessage("OPL Rythm mode select");
+ usrintf_showmessage("OPL Rythm mode select");
#endif
- /* BD key on/off */
- if(rkey&0x10)
- {
- if(v&0x10)
- {
- OPL->P_CH[6].op1_out[0] = OPL->P_CH[6].op1_out[1] = 0;
- OPL_KEYON(&OPL->P_CH[6].SLOT[SLOT1]);
- OPL_KEYON(&OPL->P_CH[6].SLOT[SLOT2]);
+ /* BD key on/off */
+ if (rkey & 0x10) {
+ if (v & 0x10) {
+ OPL->P_CH[6].op1_out[0] = OPL->P_CH[6].op1_out[1] = 0;
+ OPL_KEYON(&OPL->P_CH[6].SLOT[SLOT1]);
+ OPL_KEYON(&OPL->P_CH[6].SLOT[SLOT2]);
+ } else {
+ OPL_KEYOFF(&OPL->P_CH[6].SLOT[SLOT1]);
+ OPL_KEYOFF(&OPL->P_CH[6].SLOT[SLOT2]);
+ }
}
- else
- {
- OPL_KEYOFF(&OPL->P_CH[6].SLOT[SLOT1]);
- OPL_KEYOFF(&OPL->P_CH[6].SLOT[SLOT2]);
+ /* SD key on/off */
+ if (rkey & 0x08) {
+ if (v & 0x08)
+ OPL_KEYON(&OPL->P_CH[7].SLOT[SLOT2]);
+ else
+ OPL_KEYOFF(&OPL->P_CH[7].SLOT[SLOT2]);
+ } /* TAM key on/off */
+ if (rkey & 0x04) {
+ if (v & 0x04)
+ OPL_KEYON(&OPL->P_CH[8].SLOT[SLOT1]);
+ else
+ OPL_KEYOFF(&OPL->P_CH[8].SLOT[SLOT1]);
+ }
+ /* TOP-CY key on/off */
+ if (rkey & 0x02) {
+ if (v & 0x02)
+ OPL_KEYON(&OPL->P_CH[8].SLOT[SLOT2]);
+ else
+ OPL_KEYOFF(&OPL->P_CH[8].SLOT[SLOT2]);
+ }
+ /* HH key on/off */
+ if (rkey & 0x01) {
+ if (v & 0x01)
+ OPL_KEYON(&OPL->P_CH[7].SLOT[SLOT1]);
+ else
+ OPL_KEYOFF(&OPL->P_CH[7].SLOT[SLOT1]);
}
- }
- /* SD key on/off */
- if(rkey&0x08)
- {
- if(v&0x08) OPL_KEYON(&OPL->P_CH[7].SLOT[SLOT2]);
- else OPL_KEYOFF(&OPL->P_CH[7].SLOT[SLOT2]);
- }/* TAM key on/off */
- if(rkey&0x04)
- {
- if(v&0x04) OPL_KEYON(&OPL->P_CH[8].SLOT[SLOT1]);
- else OPL_KEYOFF(&OPL->P_CH[8].SLOT[SLOT1]);
- }
- /* TOP-CY key on/off */
- if(rkey&0x02)
- {
- if(v&0x02) OPL_KEYON(&OPL->P_CH[8].SLOT[SLOT2]);
- else OPL_KEYOFF(&OPL->P_CH[8].SLOT[SLOT2]);
- }
- /* HH key on/off */
- if(rkey&0x01)
- {
- if(v&0x01) OPL_KEYON(&OPL->P_CH[7].SLOT[SLOT1]);
- else OPL_KEYOFF(&OPL->P_CH[7].SLOT[SLOT1]);
}
}
- }
return;
}
/* keyon,block,fnum */
- if( (r&0x0f) > 8) return;
- CH = &OPL->P_CH[r&0x0f];
- if(!(r&0x10))
- { /* a0-a8 */
- block_fnum = (CH->block_fnum&0x1f00) | v;
- }
- else
- { /* b0-b8 */
- int keyon = (v>>5)&1;
- block_fnum = ((v&0x1f)<<8) | (CH->block_fnum&0xff);
- if(CH->keyon != keyon)
- {
- if( (CH->keyon=keyon) )
- {
+ if ((r & 0x0f) > 8)
+ return;
+ CH = &OPL->P_CH[r & 0x0f];
+ if (!(r & 0x10)) { /* a0-a8 */
+ block_fnum = (CH->block_fnum & 0x1f00) | v;
+ } else { /* b0-b8 */
+ int keyon = (v >> 5) & 1;
+ block_fnum = ((v & 0x1f) << 8) | (CH->block_fnum & 0xff);
+ if (CH->keyon != keyon) {
+ if ((CH->keyon = keyon)) {
CH->op1_out[0] = CH->op1_out[1] = 0;
OPL_KEYON(&CH->SLOT[SLOT1]);
OPL_KEYON(&CH->SLOT[SLOT2]);
- }
- else
- {
+ } else {
OPL_KEYOFF(&CH->SLOT[SLOT1]);
OPL_KEYOFF(&CH->SLOT[SLOT2]);
}
}
}
/* update */
- if(CH->block_fnum != block_fnum)
- {
- int blockRv = 7-(block_fnum>>10);
- int fnum = block_fnum&0x3ff;
+ if (CH->block_fnum != block_fnum) {
+ int blockRv = 7 - (block_fnum >> 10);
+ int fnum = block_fnum & 0x3ff;
CH->block_fnum = block_fnum;
- CH->ksl_base = KSL_TABLE[block_fnum>>6];
- CH->fc = OPL->FN_TABLE[fnum]>>blockRv;
- CH->kcode = CH->block_fnum>>9;
- if( (OPL->mode&0x40) && CH->block_fnum&0x100) CH->kcode |=1;
- CALC_FCSLOT(CH,&CH->SLOT[SLOT1]);
- CALC_FCSLOT(CH,&CH->SLOT[SLOT2]);
+ CH->ksl_base = KSL_TABLE[block_fnum >> 6];
+ CH->fc = OPL->FN_TABLE[fnum] >> blockRv;
+ CH->kcode = CH->block_fnum >> 9;
+ if ((OPL->mode & 0x40) && CH->block_fnum & 0x100)
+ CH->kcode |= 1;
+ CALC_FCSLOT(CH, &CH->SLOT[SLOT1]);
+ CALC_FCSLOT(CH, &CH->SLOT[SLOT2]);
}
return;
case 0xc0:
/* FB,C */
- if( (r&0x0f) > 8) return;
- CH = &OPL->P_CH[r&0x0f];
+ if ((r & 0x0f) > 8)
+ return;
+ CH = &OPL->P_CH[r & 0x0f];
{
- int feedback = (v>>1)&7;
- CH->FB = feedback ? (8+1) - feedback : 0;
- CH->CON = v&1;
- set_algorythm(CH);
+ int feedback = (v >> 1) & 7;
+ CH->FB = feedback ? (8 + 1) - feedback : 0;
+ CH->CON = v & 1;
+ set_algorythm(CH);
}
return;
- case 0xe0: /* wave type */
- slot = slot_array[r&0x1f];
- if(slot == -1) return;
- CH = &OPL->P_CH[slot/2];
- if(OPL->wavesel)
- {
+ case 0xe0: /* wave type */
+ slot = slot_array[r & 0x1f];
+ if (slot == -1)
+ return;
+ CH = &OPL->P_CH[slot / 2];
+ if (OPL->wavesel) {
/* LOG(LOG_INF,("OPL SLOT %d wave select %d\n",slot,v&3)); */
- CH->SLOT[slot&1].wavetable = &SIN_TABLE[(v&0x03)*SIN_ENT];
+ CH->SLOT[slot & 1].wavetable = &SIN_TABLE[(v & 0x03) * SIN_ENT];
}
return;
}
@@ -916,12 +904,12 @@ void OPLWriteReg(FM_OPL *OPL, int r, int v)
static int OPL_LockTable(void)
{
num_lock++;
- if(num_lock>1) return 0;
+ if (num_lock > 1)
+ return 0;
/* first time */
cur_chip = NULL;
/* allocate total level table (128kb space) */
- if( !OPLOpenTable() )
- {
+ if (!OPLOpenTable()) {
num_lock--;
return -1;
}
@@ -930,8 +918,10 @@ static int OPL_LockTable(void)
static void OPL_UnLockTable(void)
{
- if(num_lock) num_lock--;
- if(num_lock) return;
+ if (num_lock)
+ num_lock--;
+ if (num_lock)
+ return;
/* last time */
cur_chip = NULL;
OPLCloseTable();
@@ -942,17 +932,17 @@ static void OPL_UnLockTable(void)
/*******************************************************************************/
/* ---------- update one of chip ----------- */
-void YM3812UpdateOne(FM_OPL *OPL, INT16 *buffer, int length)
+void YM3812UpdateOne(FM_OPL * OPL, INT16 * buffer, int length)
{
- int i;
+ int i;
int data;
OPLSAMPLE *buf = buffer;
- UINT32 amsCnt = OPL->amsCnt;
- UINT32 vibCnt = OPL->vibCnt;
- UINT8 rythm = OPL->rythm&0x20;
- OPL_CH *CH,*R_CH;
+ UINT32 amsCnt = OPL->amsCnt;
+ UINT32 vibCnt = OPL->vibCnt;
+ UINT8 rythm = OPL->rythm & 0x20;
+ OPL_CH *CH, *R_CH;
- if( (void *)OPL != cur_chip ){
+ if ((void *)OPL != cur_chip) {
cur_chip = (void *)OPL;
/* channel pointers */
S_CH = OPL->P_CH;
@@ -969,21 +959,20 @@ void YM3812UpdateOne(FM_OPL *OPL, INT16 *buffer, int length)
vib_table = OPL->vib_table;
}
R_CH = rythm ? &S_CH[6] : E_CH;
- for( i=0; i < length ; i++ )
- {
+ for (i = 0; i < length; i++) {
/* channel A channel B channel C */
/* LFO */
- ams = ams_table[(amsCnt+=amsIncr)>>AMS_SHIFT];
- vib = vib_table[(vibCnt+=vibIncr)>>VIB_SHIFT];
+ ams = ams_table[(amsCnt += amsIncr) >> AMS_SHIFT];
+ vib = vib_table[(vibCnt += vibIncr) >> VIB_SHIFT];
outd[0] = 0;
/* FM part */
- for(CH=S_CH ; CH < R_CH ; CH++)
+ for (CH = S_CH; CH < R_CH; CH++)
OPL_CALC_CH(CH);
/* Rythn part */
- if(rythm)
+ if (rythm)
OPL_CALC_RH(S_CH);
/* limit check */
- data = Limit( outd[0] , OPL_MAXOUT, OPL_MINOUT );
+ data = Limit(outd[0], OPL_MAXOUT, OPL_MINOUT);
/* store to sound buffer */
buf[i] = data >> OPL_OUTSB;
}
@@ -994,32 +983,31 @@ void YM3812UpdateOne(FM_OPL *OPL, INT16 *buffer, int length)
/* ---------- reset one of chip ---------- */
-void OPLResetChip(FM_OPL *OPL)
+void OPLResetChip(FM_OPL * OPL)
{
- int c,s;
+ int c, s;
int i;
/* reset chip */
- OPL->mode = 0; /* normal mode */
- OPL_STATUS_RESET(OPL,0x7f);
+ OPL->mode = 0; /* normal mode */
+ OPL_STATUS_RESET(OPL, 0x7f);
/* reset with register write */
- OPLWriteReg(OPL,0x01,0); /* wabesel disable */
- OPLWriteReg(OPL,0x02,0); /* Timer1 */
- OPLWriteReg(OPL,0x03,0); /* Timer2 */
- OPLWriteReg(OPL,0x04,0); /* IRQ mask clear */
- for(i = 0xff ; i >= 0x20 ; i-- ) OPLWriteReg(OPL,i,0);
+ OPLWriteReg(OPL, 0x01, 0); /* wabesel disable */
+ OPLWriteReg(OPL, 0x02, 0); /* Timer1 */
+ OPLWriteReg(OPL, 0x03, 0); /* Timer2 */
+ OPLWriteReg(OPL, 0x04, 0); /* IRQ mask clear */
+ for (i = 0xff; i >= 0x20; i--)
+ OPLWriteReg(OPL, i, 0);
/* reset OPerator paramater */
- for( c = 0 ; c < OPL->max_ch ; c++ )
- {
+ for (c = 0; c < OPL->max_ch; c++) {
OPL_CH *CH = &OPL->P_CH[c];
/* OPL->P_CH[c].PAN = OPN_CENTER; */
- for(s = 0 ; s < 2 ; s++ )
- {
+ for (s = 0; s < 2; s++) {
/* wave table */
CH->SLOT[s].wavetable = &SIN_TABLE[0];
/* CH->SLOT[s].evm = ENV_MOD_RR; */
CH->SLOT[s].evc = EG_OFF;
- CH->SLOT[s].eve = EG_OFF+1;
+ CH->SLOT[s].eve = EG_OFF + 1;
CH->SLOT[s].evs = 0;
}
}
@@ -1032,23 +1020,27 @@ FM_OPL *OPLCreate(int type, int clock, int rate)
char *ptr;
FM_OPL *OPL;
int state_size;
- int max_ch = 9; /* normaly 9 channels */
+ int max_ch = 9; /* normaly 9 channels */
- if( OPL_LockTable() ==-1) return NULL;
+ if (OPL_LockTable() == -1)
+ return NULL;
/* allocate OPL state space */
- state_size = sizeof(FM_OPL);
- state_size += sizeof(OPL_CH)*max_ch;
+ state_size = sizeof(FM_OPL);
+ state_size += sizeof(OPL_CH) * max_ch;
/* allocate memory block */
- ptr = (char*)malloc(state_size);
- if(ptr==NULL) return NULL;
+ ptr = (char *)malloc(state_size);
+ if (ptr == NULL)
+ return NULL;
/* clear */
- memset(ptr,0,state_size);
- OPL = (FM_OPL *)ptr; ptr+=sizeof(FM_OPL);
- OPL->P_CH = (OPL_CH *)ptr; ptr+=sizeof(OPL_CH)*max_ch;
+ memset(ptr, 0, state_size);
+ OPL = (FM_OPL *) ptr;
+ ptr += sizeof(FM_OPL);
+ OPL->P_CH = (OPL_CH *) ptr;
+ ptr += sizeof(OPL_CH) * max_ch;
/* set channel state pointer */
- OPL->type = type;
+ OPL->type = type;
OPL->clock = clock;
- OPL->rate = rate;
+ OPL->rate = rate;
OPL->max_ch = max_ch;
/* init grobal tables */
OPL_initalize(OPL);
@@ -1058,7 +1050,7 @@ FM_OPL *OPLCreate(int type, int clock, int rate)
}
/* ---------- Destroy one of vietual YM3812 ---------- */
-void OPLDestroy(FM_OPL *OPL)
+void OPLDestroy(FM_OPL * OPL)
{
OPL_UnLockTable();
free(OPL);
@@ -1066,41 +1058,42 @@ void OPLDestroy(FM_OPL *OPL)
/* ---------- Option handlers ---------- */
-void OPLSetTimerHandler(FM_OPL *OPL,OPL_TIMERHANDLER TimerHandler,int channelOffset)
+void OPLSetTimerHandler(FM_OPL * OPL, OPL_TIMERHANDLER TimerHandler,
+ int channelOffset)
{
- OPL->TimerHandler = TimerHandler;
+ OPL->TimerHandler = TimerHandler;
OPL->TimerParam = channelOffset;
}
-void OPLSetIRQHandler(FM_OPL *OPL,OPL_IRQHANDLER IRQHandler,int param)
+void OPLSetIRQHandler(FM_OPL * OPL, OPL_IRQHANDLER IRQHandler, int param)
{
- OPL->IRQHandler = IRQHandler;
+ OPL->IRQHandler = IRQHandler;
OPL->IRQParam = param;
}
-void OPLSetUpdateHandler(FM_OPL *OPL,OPL_UPDATEHANDLER UpdateHandler,int param)
+void OPLSetUpdateHandler(FM_OPL * OPL, OPL_UPDATEHANDLER UpdateHandler,
+ int param)
{
OPL->UpdateHandler = UpdateHandler;
OPL->UpdateParam = param;
}
-int OPLTimerOver(FM_OPL *OPL,int c)
+int OPLTimerOver(FM_OPL * OPL, int c)
{
- if( c )
- { /* Timer B */
- OPL_STATUS_SET(OPL,0x20);
- }
- else
- { /* Timer A */
- OPL_STATUS_SET(OPL,0x40);
+ if (c) { /* Timer B */
+ OPL_STATUS_SET(OPL, 0x20);
+ } else { /* Timer A */
+ OPL_STATUS_SET(OPL, 0x40);
/* CSM mode key,TL controll */
- if( OPL->mode & 0x80 )
- { /* CSM mode total level latch and auto key on */
+ if (OPL->mode & 0x80) { /* CSM mode total level latch and auto key on */
int ch;
- if(OPL->UpdateHandler) OPL->UpdateHandler(OPL->UpdateParam,0);
- for(ch=0;ch<9;ch++)
- CSMKeyControll( &OPL->P_CH[ch] );
+ if (OPL->UpdateHandler)
+ OPL->UpdateHandler(OPL->UpdateParam, 0);
+ for (ch = 0; ch < 9; ch++)
+ CSMKeyControll(&OPL->P_CH[ch]);
}
}
/* reload timer */
- if (OPL->TimerHandler) (OPL->TimerHandler)(OPL->TimerParam+c,(double)OPL->T[c]*OPL->TimerBase);
- return OPL->status>>7;
+ if (OPL->TimerHandler)
+ (OPL->TimerHandler) (OPL->TimerParam + c,
+ (double)OPL->T[c] * OPL->TimerBase);
+ return OPL->status >> 7;
}
diff --git a/sound/gmidi.cpp b/sound/gmidi.cpp
index 92246a4f26..7d90614171 100644
--- a/sound/gmidi.cpp
+++ b/sound/gmidi.cpp
@@ -35,15 +35,17 @@
#include "scumm.h"
#include "gmidi.h"
-void MidiSoundDriver::midiSetDriver(int devicetype) {
+void MidiSoundDriver::midiSetDriver(int devicetype)
+{
_midi_driver.DeviceType = devicetype;
_midi_driver.midiInit();
}
-void MidiDriver::midiInit() {
- if (MidiInitialized != true) {
+void MidiDriver::midiInit()
+{
+ if (MidiInitialized != true) {
switch (DeviceType) {
- case MIDI_NULL:
+ case MIDI_NULL:
midiInitNull();
break;
case MIDI_WINDOWS:
@@ -71,10 +73,11 @@ void MidiDriver::midiInit() {
}
}
-void MidiDriver::MidiOut(int b) {
+void MidiDriver::MidiOut(int b)
+{
if (MidiInitialized != true)
midiInit();
-
+
if (MidiInitialized == true) {
switch (DeviceType) {
case MIDI_NULL:
@@ -102,39 +105,47 @@ void MidiDriver::MidiOut(int b) {
}
/*********** Windows */
-void MidiDriver::midiInitWindows() {
- #ifdef WIN32
- if (midiOutOpen((HMIDIOUT*)&_mo, MIDI_MAPPER, NULL, NULL, 0) != MMSYSERR_NOERROR)
- error("midiOutOpen failed");
- #endif
+void MidiDriver::midiInitWindows()
+{
+#ifdef WIN32
+ if (midiOutOpen((HMIDIOUT *) & _mo, MIDI_MAPPER, NULL, NULL, 0) !=
+ MMSYSERR_NOERROR)
+ error("midiOutOpen failed");
+#endif
}
-void MidiDriver::MidiOutWindows(void *a, int b) {
- #ifdef WIN32
+void MidiDriver::MidiOutWindows(void *a, int b)
+{
+#ifdef WIN32
midiOutShortMsg((HMIDIOUT) a, b);
- #endif
+#endif
}
/*********** Raw midi support */
-void MidiDriver::midiInitSeq() {
+void MidiDriver::midiInitSeq()
+{
int device = open_sequencer_device();
- _mo = (void *) device;
+ _mo = (void *)device;
}
-int MidiDriver::open_sequencer_device() {
+int MidiDriver::open_sequencer_device()
+{
int device = 0;
-#if !defined(__APPLE__CW) // No getenv support on Apple Carbon
+#if !defined(__APPLE__CW) // No getenv support on Apple Carbon
char *device_name = getenv("SCUMMVM_MIDI");
if (device_name != NULL) {
device = (open((device_name), O_RDWR, 0));
} else {
- warning("You need to set-up the SCUMMVM_MIDI environment variable properly (see readme.txt) ");
+ warning
+ ("You need to set-up the SCUMMVM_MIDI environment variable properly (see readme.txt) ");
}
if ((device_name == NULL) || (device < 0)) {
if (device_name == NULL)
warning("Opening /dev/null (no music will be heard) ");
else
- warning("Cannot open rawmidi device %s - using /dev/null (no music will be heard) ", device_name);
+ warning
+ ("Cannot open rawmidi device %s - using /dev/null (no music will be heard) ",
+ device_name);
device = (open(("/dev/null"), O_RDWR, 0));
if (device < 0)
error("Cannot open /dev/null to dump midi output");
@@ -144,220 +155,239 @@ int MidiDriver::open_sequencer_device() {
}
/*********** Timidity */
-int MidiDriver::connect_to_timidity(int port) {
+int MidiDriver::connect_to_timidity(int port)
+{
int s = 0;
-#if !defined(__APPLE__CW) && !defined(__MORPHOS__) // No socket support on Apple Carbon or Morphos
+#if !defined(__APPLE__CW) && !defined(__MORPHOS__) // No socket support on Apple Carbon or Morphos
struct hostent *serverhost;
- struct sockaddr_in sadd;
+ struct sockaddr_in sadd;
serverhost = gethostbyname("localhost");
if (serverhost == NULL)
error("Could not resolve Timidity host ('localhost')");
-
+
sadd.sin_family = serverhost->h_addrtype;
sadd.sin_port = htons(port);
memcpy(&(sadd.sin_addr), serverhost->h_addr_list[0], serverhost->h_length);
- s = socket(AF_INET,SOCK_STREAM,0);
+ s = socket(AF_INET, SOCK_STREAM, 0);
if (s < 0)
error("Could not open Timidity socket");
- if (connect(s, (struct sockaddr *) &sadd, sizeof(struct sockaddr_in)) < 0)
- error("Could not connect to Timidity server");
+ if (connect(s, (struct sockaddr *)&sadd, sizeof(struct sockaddr_in)) < 0)
+ error("Could not connect to Timidity server");
#endif
return s;
}
-void MidiDriver::midiInitTimidity() {
+void MidiDriver::midiInitTimidity()
+{
int s, s2;
int len;
int dummy, newport;
char buf[256];
s = connect_to_timidity(7777);
- len = read(s, buf, 256); // buf[len] = '\0'; printf("%s", buf);
+ len = read(s, buf, 256); // buf[len] = '\0'; printf("%s", buf);
sprintf(buf, "SETBUF %f %f\n", 0.1, 0.15);
write(s, buf, strlen(buf));
- len = read(s, buf, 256); // buf[len] = '\0'; printf("%s", buf);
+ len = read(s, buf, 256); // buf[len] = '\0'; printf("%s", buf);
sprintf(buf, "OPEN lsb\n");
write(s, buf, strlen(buf));
- len = read(s, buf, 256); // buf[len] = '\0'; printf("%s", buf);
+ len = read(s, buf, 256); // buf[len] = '\0'; printf("%s", buf);
sscanf(buf, "%d %d", &dummy, &newport);
printf(" => port = %d\n", newport);
s2 = connect_to_timidity(newport);
- _mo = (void *) s2;
+ _mo = (void *)s2;
}
-void MidiDriver::MidiOutSeq(void *a, int b) {
- int s = (int) a;
+void MidiDriver::MidiOutSeq(void *a, int b)
+{
+ int s = (int)a;
unsigned char buf[256];
int position = 0;
switch (b & 0xF0) {
- case 0x80:
- case 0x90:
- case 0xA0:
- case 0xB0:
- case 0xE0:
- buf[position++] = SEQ_MIDIPUTC;
- buf[position++] = b;
- buf[position++] = DEVICE_NUM;
- buf[position++] = 0;
- buf[position++] = SEQ_MIDIPUTC;
- buf[position++] = (b >> 8) & 0x7F;
- buf[position++] = DEVICE_NUM;
- buf[position++] = 0;
- buf[position++] = SEQ_MIDIPUTC;
- buf[position++] = (b >> 16) & 0x7F;
- buf[position++] = DEVICE_NUM;
- buf[position++] = 0;
+ case 0x80:
+ case 0x90:
+ case 0xA0:
+ case 0xB0:
+ case 0xE0:
+ buf[position++] = SEQ_MIDIPUTC;
+ buf[position++] = b;
+ buf[position++] = DEVICE_NUM;
+ buf[position++] = 0;
+ buf[position++] = SEQ_MIDIPUTC;
+ buf[position++] = (b >> 8) & 0x7F;
+ buf[position++] = DEVICE_NUM;
+ buf[position++] = 0;
+ buf[position++] = SEQ_MIDIPUTC;
+ buf[position++] = (b >> 16) & 0x7F;
+ buf[position++] = DEVICE_NUM;
+ buf[position++] = 0;
break;
- case 0xC0:
- case 0xD0:
- buf[position++] = SEQ_MIDIPUTC;
- buf[position++] = b;
- buf[position++] = DEVICE_NUM;
- buf[position++] = 0;
- buf[position++] = SEQ_MIDIPUTC;
- buf[position++] = (b >> 8) & 0x7F;
- buf[position++] = DEVICE_NUM;
- buf[position++] = 0;
- break;
- default:
- fprintf(stderr, "Unknown : %08x\n", b);
- break;
- }
+ case 0xC0:
+ case 0xD0:
+ buf[position++] = SEQ_MIDIPUTC;
+ buf[position++] = b;
+ buf[position++] = DEVICE_NUM;
+ buf[position++] = 0;
+ buf[position++] = SEQ_MIDIPUTC;
+ buf[position++] = (b >> 8) & 0x7F;
+ buf[position++] = DEVICE_NUM;
+ buf[position++] = 0;
+ break;
+ default:
+ fprintf(stderr, "Unknown : %08x\n", b);
+ break;
+ }
write(s, buf, position);
}
/* Quicktime music support */
-void MidiDriver::midiInitQuicktime() {
+void MidiDriver::midiInitQuicktime()
+{
#ifdef __APPLE__CW
ComponentResult qtErr = noErr;
- qtNoteAllocator = NULL;
-
- for (int i = 0 ; i < 15 ; i++)
- qtNoteChannel[i] = NULL;
-
- qtNoteAllocator = OpenDefaultComponent(kNoteAllocatorComponentType, 0);
- if (qtNoteAllocator == NULL)
- goto bail;
-
- simpleNoteRequest.info.flags = 0;
- *(short *)(&simpleNoteRequest.info.polyphony) = EndianS16_NtoB(15); // simultaneous tones
- *(Fixed *)(&simpleNoteRequest.info.typicalPolyphony) = EndianU32_NtoB(0x00010000);
-
+ qtNoteAllocator = NULL;
+
+ for (int i = 0; i < 15; i++)
+ qtNoteChannel[i] = NULL;
+
+ qtNoteAllocator = OpenDefaultComponent(kNoteAllocatorComponentType, 0);
+ if (qtNoteAllocator == NULL)
+ goto bail;
+
+ simpleNoteRequest.info.flags = 0;
+ *(short *)(&simpleNoteRequest.info.polyphony) = EndianS16_NtoB(15); // simultaneous tones
+ *(Fixed *) (&simpleNoteRequest.info.typicalPolyphony) =
+ EndianU32_NtoB(0x00010000);
+
qtErr = NAStuffToneDescription(qtNoteAllocator, 1, &simpleNoteRequest.tone);
- if (qtErr != noErr)
- goto bail;
-
- for (int i = 0 ; i < 15 ; i++) {
- qtErr = NANewNoteChannel(qtNoteAllocator, &simpleNoteRequest, &(qtNoteChannel[i]));
+ if (qtErr != noErr)
+ goto bail;
+
+ for (int i = 0; i < 15; i++) {
+ qtErr =
+ NANewNoteChannel(qtNoteAllocator, &simpleNoteRequest,
+ &(qtNoteChannel[i]));
if ((qtErr != noErr) || (qtNoteChannel == NULL))
- goto bail;
- }
- return;
-
- bail:
- fprintf(stderr, "Init QT failed %x %x %d\n", qtNoteAllocator, qtNoteChannel, qtErr);
- for (int i = 0 ; i < 15 ; i++) {
- if (qtNoteChannel[i] != NULL)
- NADisposeNoteChannel(qtNoteAllocator, qtNoteChannel[i]);
- }
-
- if (qtNoteAllocator != NULL)
- CloseComponent(qtNoteAllocator);
+ goto bail;
+ }
+ return;
+
+bail:
+ fprintf(stderr, "Init QT failed %x %x %d\n", qtNoteAllocator, qtNoteChannel,
+ qtErr);
+ for (int i = 0; i < 15; i++) {
+ if (qtNoteChannel[i] != NULL)
+ NADisposeNoteChannel(qtNoteAllocator, qtNoteChannel[i]);
+ }
+
+ if (qtNoteAllocator != NULL)
+ CloseComponent(qtNoteAllocator);
#endif
}
-void MidiDriver::MidiOutQuicktime(void *a, int b) {
+void MidiDriver::MidiOutQuicktime(void *a, int b)
+{
#ifdef __APPLE__CW
MusicMIDIPacket midPacket;
unsigned char *midiCmd = midPacket.data;
midPacket.length = 3;
- midiCmd[3] = (b & 0xFF000000)>>24;
- midiCmd[2] = (b & 0x00FF0000)>>16;
- midiCmd[1] = (b & 0x0000FF00)>>8;
+ midiCmd[3] = (b & 0xFF000000) >> 24;
+ midiCmd[2] = (b & 0x00FF0000) >> 16;
+ midiCmd[1] = (b & 0x0000FF00) >> 8;
midiCmd[0] = b;
- unsigned char chanID = midiCmd[0] & 0x0F;
+ unsigned char chanID = midiCmd[0] & 0x0F;
switch (midiCmd[0] & 0xF0) {
- case 0x80: // Note off
- NAPlayNote(qtNoteAllocator, qtNoteChannel[chanID], midiCmd[1], 0);
+ case 0x80: // Note off
+ NAPlayNote(qtNoteAllocator, qtNoteChannel[chanID], midiCmd[1], 0);
break;
-
- case 0x90: // Note on
- NAPlayNote(qtNoteAllocator, qtNoteChannel[chanID], midiCmd[1], midiCmd[2]);
+
+ case 0x90: // Note on
+ NAPlayNote(qtNoteAllocator, qtNoteChannel[chanID], midiCmd[1],
+ midiCmd[2]);
break;
-
- case 0xB0: // Effect
- switch (midiCmd[1]) {
- case 0x01: // Modulation
- NASetController(qtNoteAllocator, qtNoteChannel[chanID], kControllerModulationWheel, midiCmd[2]<<8);
- break;
- case 0x07: // Volume
- NASetController(qtNoteAllocator, qtNoteChannel[chanID], kControllerVolume, midiCmd[2]*300);
- break;
-
- case 0x0A: // Pan
- NASetController(qtNoteAllocator, qtNoteChannel[chanID], kControllerPan, (midiCmd[2]<<1)+0xFF);
- break;
-
- case 0x40: // Sustain on/off
- NASetController(qtNoteAllocator, qtNoteChannel[chanID], kControllerSustain, midiCmd[2]);
- break;
-
- case 0x5b: // ext effect depth
- NASetController(qtNoteAllocator, qtNoteChannel[chanID], kControllerReverb, midiCmd[2]<<8);
- break;
-
- case 0x5d: // chorus depth
- NASetController(qtNoteAllocator, qtNoteChannel[chanID], kControllerChorus, midiCmd[2]<<8);
- break;
-
- case 0x7b: // mode message all notes off
- for (int i = 0 ; i < 128 ; i++)
- NAPlayNote(qtNoteAllocator, qtNoteChannel[chanID], i, 0);
- break;
-
- default:
- fprintf(stderr, "Unknown MIDI effect: %08x\n", b);
- break;
- }
- break;
-
- case 0xC0: // Program change
- NASetInstrumentNumber(qtNoteAllocator, qtNoteChannel[chanID], midiCmd[1]);
- break;
-
- case 0xE0: { // Pitch bend
- long theBend = ((((long)midiCmd[1] + (long)(midiCmd[2] << 8)))-0x4000)/4;
- NASetController(qtNoteAllocator, qtNoteChannel[chanID], kControllerPitchBend, theBend);
- }
- break;
-
+ case 0xB0: // Effect
+ switch (midiCmd[1]) {
+ case 0x01: // Modulation
+ NASetController(qtNoteAllocator, qtNoteChannel[chanID],
+ kControllerModulationWheel, midiCmd[2] << 8);
+ break;
+
+ case 0x07: // Volume
+ NASetController(qtNoteAllocator, qtNoteChannel[chanID],
+ kControllerVolume, midiCmd[2] * 300);
+ break;
+
+ case 0x0A: // Pan
+ NASetController(qtNoteAllocator, qtNoteChannel[chanID], kControllerPan,
+ (midiCmd[2] << 1) + 0xFF);
+ break;
+
+ case 0x40: // Sustain on/off
+ NASetController(qtNoteAllocator, qtNoteChannel[chanID],
+ kControllerSustain, midiCmd[2]);
+ break;
+
+ case 0x5b: // ext effect depth
+ NASetController(qtNoteAllocator, qtNoteChannel[chanID],
+ kControllerReverb, midiCmd[2] << 8);
+ break;
+
+ case 0x5d: // chorus depth
+ NASetController(qtNoteAllocator, qtNoteChannel[chanID],
+ kControllerChorus, midiCmd[2] << 8);
+ break;
+
+ case 0x7b: // mode message all notes off
+ for (int i = 0; i < 128; i++)
+ NAPlayNote(qtNoteAllocator, qtNoteChannel[chanID], i, 0);
+ break;
+
default:
- fprintf(stderr, "Unknown Command: %08x\n", b);
- NASendMIDI(qtNoteAllocator, qtNoteChannel[chanID], &midPacket);
- break;
- }
+ fprintf(stderr, "Unknown MIDI effect: %08x\n", b);
+ break;
+ }
+ break;
+
+ case 0xC0: // Program change
+ NASetInstrumentNumber(qtNoteAllocator, qtNoteChannel[chanID], midiCmd[1]);
+ break;
+
+ case 0xE0:{ // Pitch bend
+ long theBend =
+ ((((long)midiCmd[1] + (long)(midiCmd[2] << 8))) - 0x4000) / 4;
+ NASetController(qtNoteAllocator, qtNoteChannel[chanID],
+ kControllerPitchBend, theBend);
+ }
+ break;
+
+ default:
+ fprintf(stderr, "Unknown Command: %08x\n", b);
+ NASendMIDI(qtNoteAllocator, qtNoteChannel[chanID], &midPacket);
+ break;
+ }
#endif
}
/*********** MorphOS */
-void MidiDriver::MidiOutMorphOS(void *a, int b) {
+void MidiDriver::MidiOutMorphOS(void *a, int b)
+{
#ifdef __MORPHOS__
- if( ScummMidiRequest ) {
- ULONG midi_data = b; // you never know about an int's size ;-)
- ScummMidiRequest->amr_Std.io_Command = CMD_WRITE;
- ScummMidiRequest->amr_Std.io_Data = &midi_data;
- ScummMidiRequest->amr_Std.io_Length = 4;
- DoIO( (struct IORequest *)ScummMidiRequest );
- }
+ if (ScummMidiRequest) {
+ ULONG midi_data = b; // you never know about an int's size ;-)
+ ScummMidiRequest->amr_Std.io_Command = CMD_WRITE;
+ ScummMidiRequest->amr_Std.io_Data = &midi_data;
+ ScummMidiRequest->amr_Std.io_Length = 4;
+ DoIO((struct IORequest *)ScummMidiRequest);
+ }
#endif
}
@@ -367,94 +397,112 @@ void MidiDriver::MidiOutMorphOS(void *a, int b) {
-void MidiDriver::midiInitNull() {warning("Music not enabled - MIDI support selected with no MIDI driver available. Try Adlib");}
+void MidiDriver::midiInitNull()
+{
+ warning
+ ("Music not enabled - MIDI support selected with no MIDI driver available. Try Adlib");
+}
/************************* Common midi code **********************/
-void MidiSoundDriver::midiPitchBend(byte chan, int16 pitchbend) {
+void MidiSoundDriver::midiPitchBend(byte chan, int16 pitchbend)
+{
uint16 tmp;
if (_midi_pitchbend_last[chan] != pitchbend) {
_midi_pitchbend_last[chan] = pitchbend;
- tmp = (pitchbend<<2) + 0x2000;
- _midi_driver.MidiOut(((tmp>>7)&0x7F)<<16 | (tmp&0x7F)<<8 | 0xE0 | chan);
+ tmp = (pitchbend << 2) + 0x2000;
+ _midi_driver.
+ MidiOut(((tmp >> 7) & 0x7F) << 16 | (tmp & 0x7F) << 8 | 0xE0 | chan);
}
}
-void MidiSoundDriver::midiVolume(byte chan, byte volume) {
+void MidiSoundDriver::midiVolume(byte chan, byte volume)
+{
if (_midi_volume_last[chan] != volume) {
_midi_volume_last[chan] = volume;
- _midi_driver.MidiOut(volume<<16 | 7<<8 | 0xB0 | chan);
+ _midi_driver.MidiOut(volume << 16 | 7 << 8 | 0xB0 | chan);
}
}
-void MidiSoundDriver::midiPedal(byte chan, bool pedal) {
+void MidiSoundDriver::midiPedal(byte chan, bool pedal)
+{
if (_midi_pedal_last[chan] != pedal) {
_midi_pedal_last[chan] = pedal;
- _midi_driver.MidiOut(pedal<<16 | 64<<8 | 0xB0 | chan);
+ _midi_driver.MidiOut(pedal << 16 | 64 << 8 | 0xB0 | chan);
}
}
-void MidiSoundDriver::midiModWheel(byte chan, byte modwheel) {
+void MidiSoundDriver::midiModWheel(byte chan, byte modwheel)
+{
if (_midi_modwheel_last[chan] != modwheel) {
_midi_modwheel_last[chan] = modwheel;
- _midi_driver.MidiOut(modwheel<<16 | 1<<8 | 0xB0 | chan);
+ _midi_driver.MidiOut(modwheel << 16 | 1 << 8 | 0xB0 | chan);
}
}
-void MidiSoundDriver::midiEffectLevel(byte chan, byte level) {
+void MidiSoundDriver::midiEffectLevel(byte chan, byte level)
+{
if (_midi_effectlevel_last[chan] != level) {
_midi_effectlevel_last[chan] = level;
- _midi_driver.MidiOut(level<<16 | 91<<8 | 0xB0 | chan);
+ _midi_driver.MidiOut(level << 16 | 91 << 8 | 0xB0 | chan);
}
}
-void MidiSoundDriver::midiChorus(byte chan, byte chorus) {
+void MidiSoundDriver::midiChorus(byte chan, byte chorus)
+{
if (_midi_chorus_last[chan] != chorus) {
_midi_chorus_last[chan] = chorus;
- _midi_driver.MidiOut(chorus<<16 | 93<<8 | 0xB0 | chan);
+ _midi_driver.MidiOut(chorus << 16 | 93 << 8 | 0xB0 | chan);
}
}
-void MidiSoundDriver::midiControl0(byte chan, byte value) {
- _midi_driver.MidiOut(value<<16 | 0<<8 | 0xB0 | chan);
+void MidiSoundDriver::midiControl0(byte chan, byte value)
+{
+ _midi_driver.MidiOut(value << 16 | 0 << 8 | 0xB0 | chan);
}
-void MidiSoundDriver::midiProgram(byte chan, byte program) {
- if ((chan + 1) != 10) { /* Ignore percussion prededed by patch change */
- if (_se->_mt32emulate)
- program=mt32_to_gmidi[program];
-
- _midi_driver.MidiOut(program<<8 | 0xC0 | chan);
+void MidiSoundDriver::midiProgram(byte chan, byte program)
+{
+ if ((chan + 1) != 10) { /* Ignore percussion prededed by patch change */
+ if (_se->_mt32emulate)
+ program = mt32_to_gmidi[program];
+
+ _midi_driver.MidiOut(program << 8 | 0xC0 | chan);
}
}
-void MidiSoundDriver::midiPan(byte chan, int8 pan) {
+void MidiSoundDriver::midiPan(byte chan, int8 pan)
+{
if (_midi_pan_last[chan] != pan) {
_midi_pan_last[chan] = pan;
- _midi_driver.MidiOut(((pan-64)&0x7F)<<16 | 10<<8 | 0xB0 | chan);
+ _midi_driver.MidiOut(((pan - 64) & 0x7F) << 16 | 10 << 8 | 0xB0 | chan);
}
}
-void MidiSoundDriver::midiNoteOn(byte chan, byte note, byte velocity) {
- _midi_driver.MidiOut(velocity<<16 | note<<8 | 0x90 | chan);
+void MidiSoundDriver::midiNoteOn(byte chan, byte note, byte velocity)
+{
+ _midi_driver.MidiOut(velocity << 16 | note << 8 | 0x90 | chan);
}
-void MidiSoundDriver::midiNoteOff(byte chan, byte note) {
- _midi_driver.MidiOut(note<<8 | 0x80 | chan);
+void MidiSoundDriver::midiNoteOff(byte chan, byte note)
+{
+ _midi_driver.MidiOut(note << 8 | 0x80 | chan);
}
-void MidiSoundDriver::midiSilence(byte chan) {
- _midi_driver.MidiOut((64<<8)|0xB0|chan);
- _midi_driver.MidiOut((123<<8)|0xB0|chan);
+void MidiSoundDriver::midiSilence(byte chan)
+{
+ _midi_driver.MidiOut((64 << 8) | 0xB0 | chan);
+ _midi_driver.MidiOut((123 << 8) | 0xB0 | chan);
}
-void MidiSoundDriver::part_key_on(Part *part, byte note, byte velocity) {
+void MidiSoundDriver::part_key_on(Part *part, byte note, byte velocity)
+{
MidiChannelGM *mc = part->_mc->gm();
if (mc) {
- mc->_actives[note>>4] |= (1<<(note&0xF));
+ mc->_actives[note >> 4] |= (1 << (note & 0xF));
midiNoteOn(mc->_chan, note, velocity);
} else if (part->_percussion) {
midiVolume(SPECIAL_CHANNEL, part->_vol_eff);
@@ -463,38 +511,42 @@ void MidiSoundDriver::part_key_on(Part *part, byte note, byte velocity) {
}
}
-void MidiSoundDriver::part_key_off(Part *part, byte note) {
+void MidiSoundDriver::part_key_off(Part *part, byte note)
+{
MidiChannelGM *mc = part->_mc->gm();
if (mc) {
- mc->_actives[note>>4] &= ~(1<<(note&0xF));
+ mc->_actives[note >> 4] &= ~(1 << (note & 0xF));
midiNoteOff(mc->_chan, note);
} else if (part->_percussion) {
midiNoteOff(SPECIAL_CHANNEL, note);
}
}
-void MidiSoundDriver::init(SoundEngine *eng) {
+void MidiSoundDriver::init(SoundEngine *eng)
+{
int i;
MidiChannelGM *mc;
_se = eng;
- for(i=0,mc=_midi_channels; i!=ARRAYSIZE(_midi_channels);i++,mc++)
+ for (i = 0, mc = _midi_channels; i != ARRAYSIZE(_midi_channels); i++, mc++)
mc->_chan = i;
}
-void MidiSoundDriver::update_pris() {
- Part *part,*hipart;
+void MidiSoundDriver::update_pris()
+{
+ Part *part, *hipart;
int i;
- byte hipri,lopri;
- MidiChannelGM *mc,*lomc;
+ byte hipri, lopri;
+ MidiChannelGM *mc, *lomc;
- while(true) {
+ while (true) {
hipri = 0;
hipart = NULL;
- for(i=32,part=_se->parts_ptr(); i; i--,part++) {
- if (part->_player && !part->_percussion && part->_on && !part->_mc && part->_pri_eff>=hipri) {
+ for (i = 32, part = _se->parts_ptr(); i; i--, part++) {
+ if (part->_player && !part->_percussion && part->_on && !part->_mc
+ && part->_pri_eff >= hipri) {
hipri = part->_pri_eff;
hipart = part;
}
@@ -505,12 +557,12 @@ void MidiSoundDriver::update_pris() {
lopri = 255;
lomc = NULL;
- for(i=ARRAYSIZE(_midi_channels),mc=_midi_channels;;mc++) {
+ for (i = ARRAYSIZE(_midi_channels), mc = _midi_channels;; mc++) {
if (!mc->_part) {
lomc = mc;
break;
}
- if (mc->_part->_pri_eff<=lopri) {
+ if (mc->_part->_pri_eff <= lopri) {
lopri = mc->_part->_pri_eff;
lomc = mc;
}
@@ -529,21 +581,22 @@ void MidiSoundDriver::update_pris() {
}
}
-int MidiSoundDriver::part_update_active(Part *part, uint16 *active) {
- int i,j;
- uint16 *act,mask,bits;
+int MidiSoundDriver::part_update_active(Part *part, uint16 *active)
+{
+ int i, j;
+ uint16 *act, mask, bits;
int count = 0;
- bits = 1<<part->_chan;
+ bits = 1 << part->_chan;
act = part->_mc->gm()->_actives;
- for(i=8; i; i--) {
+ for (i = 8; i; i--) {
mask = *act++;
if (mask) {
- for(j=16; j; j--,mask>>=1,active++) {
- if (mask&1 && !(*active&bits)) {
- *active|=bits;
+ for (j = 16; j; j--, mask >>= 1, active++) {
+ if (mask & 1 && !(*active & bits)) {
+ *active |= bits;
count++;
}
}
@@ -554,20 +607,23 @@ int MidiSoundDriver::part_update_active(Part *part, uint16 *active) {
return count;
}
-void MidiSoundDriver::part_changed(Part *part, byte what) {
+void MidiSoundDriver::part_changed(Part *part, byte what)
+{
MidiChannelGM *mc;
/* Mark for re-schedule if program changed when in pre-state */
- if (what&pcProgram && part->_percussion) {
+ if (what & pcProgram && part->_percussion) {
part->_percussion = false;
update_pris();
}
-
+
if (!(mc = part->_mc->gm()))
return;
if (what & pcMod)
- midiPitchBend(mc->_chan, clamp(part->_pitchbend + part->_detune_eff + (part->_transpose_eff<<7), -2048, 2047));
+ midiPitchBend(mc->_chan,
+ clamp(part->_pitchbend + part->_detune_eff +
+ (part->_transpose_eff << 7), -2048, 2047));
if (what & pcVolume)
midiVolume(mc->_chan, part->_vol_eff);
@@ -599,7 +655,8 @@ void MidiSoundDriver::part_changed(Part *part, byte what) {
}
-void MidiSoundDriver::part_off(Part *part) {
+void MidiSoundDriver::part_off(Part *part)
+{
MidiChannelGM *mc = part->_mc->gm();
if (mc) {
part->_mc = NULL;
diff --git a/sound/imuse.cpp b/sound/imuse.cpp
index 6b3352917e..e3068fd367 100644
--- a/sound/imuse.cpp
+++ b/sound/imuse.cpp
@@ -28,15 +28,15 @@ int num_mix;
#define TICKS_PER_BEAT 480
#ifdef USE_ADLIB
- #ifdef _WIN32_WCE
- #define TEMPO_BASE 0x1F0000 * 2 // Sampled down to 11 kHz
- #else
- #define TEMPO_BASE 0x1924E0
- #endif
- #define HARDWARE_TYPE 1
+#ifdef _WIN32_WCE
+#define TEMPO_BASE 0x1F0000 * 2 // Sampled down to 11 kHz
#else
- #define TEMPO_BASE 0x400000
- #define HARDWARE_TYPE 5
+#define TEMPO_BASE 0x1924E0
+#endif
+#define HARDWARE_TYPE 1
+#else
+#define TEMPO_BASE 0x400000
+#define HARDWARE_TYPE 5
#endif
#define SYSEX_ID 0x7D
@@ -48,52 +48,59 @@ int num_mix;
#define MDPG_TAG "MDpg"
#define MDHD_TAG "MDhd"
-int clamp(int val, int min, int max) {
- if (val<min)
+int clamp(int val, int min, int max)
+{
+ if (val < min)
return min;
- if (val>max)
+ if (val > max)
return max;
return val;
}
-int transpose_clamp(int a, int b, int c) {
- if (b>a) a += (b - a + 11) / 12 * 12;
- if (c<a) a -= (a - c + 11) / 12 * 12;
+int transpose_clamp(int a, int b, int c)
+{
+ if (b > a)
+ a += (b - a + 11) / 12 * 12;
+ if (c < a)
+ a -= (a - c + 11) / 12 * 12;
return a;
}
-uint32 get_delta_time(byte **s) {
- byte *d = *s,b;
+uint32 get_delta_time(byte **s)
+{
+ byte *d = *s, b;
uint32 time = 0;
do {
b = *d++;
- time = (time<<7) | (b&0x7F);
- } while (b&0x80);
+ time = (time << 7) | (b & 0x7F);
+ } while (b & 0x80);
*s = d;
return time;
}
-uint read_word(byte *a) {
- return (a[0]<<8) + a[1];
+uint read_word(byte *a)
+{
+ return (a[0] << 8) + a[1];
}
-void skip_midi_cmd(byte **song_ptr) {
+void skip_midi_cmd(byte **song_ptr)
+{
byte *s, code;
const byte num_skip[] = {
- 2,2,2,2,1,1,2
+ 2, 2, 2, 2, 1, 1, 2
};
s = *song_ptr;
code = *s++;
- if (code<0x80) {
+ if (code < 0x80) {
s = NULL;
- } else if (code<0xF0) {
- s += num_skip[(code&0x70)>>4];
+ } else if (code < 0xF0) {
+ s += num_skip[(code & 0x70) >> 4];
} else {
- if (code==0xF0 || code==0xF7 || code==0xFF && *s++ != 0x2F) {
+ if (code == 0xF0 || code == 0xF7 || code == 0xFF && *s++ != 0x2F) {
s += get_delta_time(&s);
} else {
s = NULL;
@@ -102,21 +109,22 @@ void skip_midi_cmd(byte **song_ptr) {
*song_ptr = s;
}
-int is_note_cmd(byte **a, IsNoteCmdData *isnote) {
+int is_note_cmd(byte **a, IsNoteCmdData * isnote)
+{
byte *s = *a;
byte code;
code = *s++;
-
- switch(code>>4) {
- case 8: /* key off */
- isnote->chan = code&0xF;
+
+ switch (code >> 4) {
+ case 8: /* key off */
+ isnote->chan = code & 0xF;
isnote->note = *s++;
isnote->vel = *s++;
*a = s;
return 1;
- case 9: /* key on */
- isnote->chan = code&0xF;
+ case 9: /* key on */
+ isnote->chan = code & 0xF;
isnote->note = *s++;
isnote->vel = *s++;
*a = s;
@@ -132,7 +140,7 @@ int is_note_cmd(byte **a, IsNoteCmdData *isnote) {
s++;
break;
case 0xF:
- if (code==0xF0 || code==0xF7 || code==0xFF && *s++ != 0x2F) {
+ if (code == 0xF0 || code == 0xF7 || code == 0xFF && *s++ != 0x2F) {
s += get_delta_time(&s);
break;
}
@@ -146,23 +154,27 @@ int is_note_cmd(byte **a, IsNoteCmdData *isnote) {
/**********************************************************************/
-void SoundEngine::lock() {
+void SoundEngine::lock()
+{
_locked++;
}
-void SoundEngine::unlock() {
+void SoundEngine::unlock()
+{
_locked--;
}
-byte *SoundEngine::findTag(int sound, char *tag, int index) {
+byte *SoundEngine::findTag(int sound, char *tag, int index)
+{
byte *ptr = NULL;
- int32 size,pos;
+ int32 size, pos;
if (_base_sounds)
- ptr = _base_sounds[sound];
+ ptr = _base_sounds[sound];
- if (ptr==NULL) {
- debug(1, "SoundEngine::findTag completely failed finding sound %d", sound);
+ if (ptr == NULL) {
+ debug(1, "SoundEngine::findTag completely failed finding sound %d",
+ sound);
return 0;
}
@@ -181,12 +193,13 @@ byte *SoundEngine::findTag(int sound, char *tag, int index) {
}
-bool SoundEngine::start_sound(int sound) {
+bool SoundEngine::start_sound(int sound)
+{
Player *player;
void *mdhd;
- mdhd = findTag(sound, MDHD_TAG, 0);
- if (!mdhd) {
+ mdhd = findTag(sound, MDHD_TAG, 0);
+ if (!mdhd) {
mdhd = findTag(sound, MDPG_TAG, 0);
if (!mdhd) {
warning("SE::start_sound failed: Couldn't find %s", MDHD_TAG);
@@ -196,18 +209,19 @@ bool SoundEngine::start_sound(int sound) {
player = allocate_player(128);
if (!player)
return false;
-
+
player->clear();
return player->start_sound(sound);
}
-Player *SoundEngine::allocate_player(byte priority) {
+Player *SoundEngine::allocate_player(byte priority)
+{
Player *player = _players, *best = NULL;
int i;
byte bestpri = 255;
- for (i=ARRAYSIZE(_players); i!=0; i--, player++) {
+ for (i = ARRAYSIZE(_players); i != 0; i--, player++) {
if (!player->_active)
return player;
if (player->_priority < bestpri) {
@@ -223,57 +237,62 @@ Player *SoundEngine::allocate_player(byte priority) {
return NULL;
}
-void SoundEngine::init_players() {
+void SoundEngine::init_players()
+{
Player *player = _players;
int i;
- for (i=ARRAYSIZE(_players); i!=0; i--, player++) {
+ for (i = ARRAYSIZE(_players); i != 0; i--, player++) {
player->_active = false;
- player->_se = this;
+ player->_se = this;
}
}
-void SoundEngine::init_sustaining_notes() {
+void SoundEngine::init_sustaining_notes()
+{
SustainingNotes *next = NULL, *sn = _sustaining_notes;
int i;
_sustain_notes_used = NULL;
_sustain_notes_head = NULL;
- for (i=ARRAYSIZE(_sustaining_notes);i!=0; i--,sn++) {
+ for (i = ARRAYSIZE(_sustaining_notes); i != 0; i--, sn++) {
sn->next = next;
next = sn;
}
_sustain_notes_free = next;
}
-void SoundEngine::init_volume_fader() {
+void SoundEngine::init_volume_fader()
+{
VolumeFader *vf = _volume_fader;
int i;
- for (i=ARRAYSIZE(_volume_fader); i!=0; i--, vf++)
+ for (i = ARRAYSIZE(_volume_fader); i != 0; i--, vf++)
vf->initialize();
_active_volume_faders = false;
}
-void SoundEngine::init_parts() {
+void SoundEngine::init_parts()
+{
Part *part;
int i;
- for (i=0,part=_parts; i!=ARRAYSIZE(_parts); i++, part++) {
+ for (i = 0, part = _parts; i != ARRAYSIZE(_parts); i++, part++) {
part->init(_driver);
part->_slot = i;
}
}
-int SoundEngine::stop_sound(int sound) {
+int SoundEngine::stop_sound(int sound)
+{
Player *player = _players;
int i;
int r = -1;
- for (i=ARRAYSIZE(_players); i!=0; i--,player++) {
- if (player->_active && player->_id==sound) {
+ for (i = ARRAYSIZE(_players); i != 0; i--, player++) {
+ if (player->_active && player->_id == sound) {
player->clear();
r = 0;
}
@@ -281,23 +300,25 @@ int SoundEngine::stop_sound(int sound) {
return r;
}
-int SoundEngine::stop_all_sounds() {
+int SoundEngine::stop_all_sounds()
+{
Player *player = _players;
int i;
- for (i=ARRAYSIZE(_players); i!=0; i--,player++) {
+ for (i = ARRAYSIZE(_players); i != 0; i--, player++) {
if (player->_active)
player->clear();
}
return 0;
}
-void SoundEngine::on_timer() {
+void SoundEngine::on_timer()
+{
if (_locked || _paused)
return;
-
+
lock();
-
+
sequencer_timers();
expire_sustain_notes();
expire_volume_faders();
@@ -306,31 +327,34 @@ void SoundEngine::on_timer() {
unlock();
}
-void SoundEngine::sequencer_timers() {
+void SoundEngine::sequencer_timers()
+{
Player *player = _players;
int i;
- for (i=ARRAYSIZE(_players); i!=0; i--,player++) {
+ for (i = ARRAYSIZE(_players); i != 0; i--, player++) {
if (player->_active)
player->sequencer_timer();
}
}
-void Player::sequencer_timer() {
+void Player::sequencer_timer()
+{
byte *mtrk;
uint32 counter;
byte *song_ptr;
counter = _timer_counter + _timer_speed;
- _timer_counter = counter&0xFFFF;
- _cur_pos += counter>>16;
- _tick_index += counter>>16;
+ _timer_counter = counter & 0xFFFF;
+ _cur_pos += counter >> 16;
+ _tick_index += counter >> 16;
- if (_tick_index>=_ticks_per_beat) {
- _beat_index += _tick_index/_ticks_per_beat;
+ if (_tick_index >= _ticks_per_beat) {
+ _beat_index += _tick_index / _ticks_per_beat;
_tick_index %= _ticks_per_beat;
}
- if (_loop_counter && _beat_index >= _loop_from_beat && _tick_index >= _loop_from_tick) {
+ if (_loop_counter && _beat_index >= _loop_from_beat
+ && _tick_index >= _loop_from_tick) {
_loop_counter--;
jump(_track_index, _loop_to_beat, _loop_to_tick);
}
@@ -354,15 +378,16 @@ void Player::sequencer_timer() {
}
}
-void SoundEngine::handle_marker(uint id, byte data) {
+void SoundEngine::handle_marker(uint id, byte data)
+{
uint16 *p;
- uint pos;
-
+ uint pos;
+
pos = _queue_end;
if (pos == _queue_pos)
return;
-
- if (_queue_adding && _queue_sound==id && data==_queue_marker)
+
+ if (_queue_adding && _queue_sound == id && data == _queue_marker)
return;
p = _cmd_queue[pos].array;
@@ -373,7 +398,7 @@ void SoundEngine::handle_marker(uint id, byte data) {
_trigger_count--;
_queue_cleared = false;
do {
- pos = (pos+1) & (ARRAYSIZE(_cmd_queue)-1);
+ pos = (pos + 1) & (ARRAYSIZE(_cmd_queue) - 1);
if (_queue_pos == pos)
break;
p = _cmd_queue[pos].array;
@@ -381,7 +406,7 @@ void SoundEngine::handle_marker(uint id, byte data) {
break;
_queue_end = pos;
- do_command(p[0],p[1],p[2],p[3],p[4],p[5],p[6],0);
+ do_command(p[0], p[1], p[2], p[3], p[4], p[5], p[6], 0);
if (_queue_cleared)
return;
@@ -391,17 +416,19 @@ void SoundEngine::handle_marker(uint id, byte data) {
_queue_end = pos;
}
-int SoundEngine::get_channel_volume(uint a) {
- if (a<8)
+int SoundEngine::get_channel_volume(uint a)
+{
+ if (a < 8)
return _channel_volume_eff[a];
return _master_volume;
}
-Part *SoundEngine::allocate_part(byte pri) {
- Part *part,*best=NULL;
+Part *SoundEngine::allocate_part(byte pri)
+{
+ Part *part, *best = NULL;
int i;
- for (i=ARRAYSIZE(_parts),part=_parts; i!=0; i--,part++) {
+ for (i = ARRAYSIZE(_parts), part = _parts; i != 0; i--, part++) {
if (!part->_player)
return part;
if (pri >= part->_pri_eff) {
@@ -417,17 +444,18 @@ Part *SoundEngine::allocate_part(byte pri) {
return best;
}
-void SoundEngine::expire_sustain_notes() {
- SustainingNotes *sn,*next;
+void SoundEngine::expire_sustain_notes()
+{
+ SustainingNotes *sn, *next;
Player *player;
uint32 counter;
- for(sn=_sustain_notes_head; sn; sn = next) {
+ for (sn = _sustain_notes_head; sn; sn = next) {
next = sn->next;
player = sn->player;
counter = sn->counter + player->_timer_speed;
- sn->pos += counter>>16;
+ sn->pos += counter >> 16;
sn->counter = (unsigned short)counter & 0xFFFF;
if (sn->pos >= sn->off_pos) {
@@ -448,7 +476,8 @@ void SoundEngine::expire_sustain_notes() {
}
}
-void SoundEngine::expire_volume_faders() {
+void SoundEngine::expire_volume_faders()
+{
VolumeFader *vf;
int i;
@@ -460,7 +489,7 @@ void SoundEngine::expire_volume_faders() {
_active_volume_faders = false;
vf = _volume_fader;
- for (i=ARRAYSIZE(_volume_fader); i!=0; i--,vf++) {
+ for (i = ARRAYSIZE(_volume_fader); i != 0; i--, vf++) {
if (vf->active) {
_active_volume_faders = true;
vf->on_timer();
@@ -468,9 +497,10 @@ void SoundEngine::expire_volume_faders() {
}
}
-void VolumeFader::on_timer() {
+void VolumeFader::on_timer()
+{
byte newvol;
-
+
newvol = curvol + speed_hi;
speed_lo_counter += speed_lo;
@@ -478,8 +508,8 @@ void VolumeFader::on_timer() {
speed_lo_counter -= speed_lo_max;
newvol += direction;
}
-
- if (curvol!=newvol) {
+
+ if (curvol != newvol) {
if (!newvol) {
player->clear();
active = false;
@@ -488,52 +518,56 @@ void VolumeFader::on_timer() {
curvol = newvol;
player->set_vol(newvol);
}
-
+
if (!--num_steps) {
active = false;
}
}
-int SoundEngine::get_sound_status(int sound) {
+int SoundEngine::get_sound_status(int sound)
+{
int i;
Player *player;
- for (i=ARRAYSIZE(_players),player=_players; i!=0; i--,player++) {
- if (player->_active && player->_id==(uint16)sound)
+ for (i = ARRAYSIZE(_players), player = _players; i != 0; i--, player++) {
+ if (player->_active && player->_id == (uint16)sound)
return 1;
}
return get_queue_sound_status(sound);
}
-int SoundEngine::get_queue_sound_status(int sound) {
+int SoundEngine::get_queue_sound_status(int sound)
+{
uint16 *a;
- int i,j;
-
+ int i, j;
+
j = _queue_pos;
i = _queue_end;
- while (i!=j) {
+ while (i != j) {
a = _cmd_queue[i].array;
if (a[0] == COMMAND_ID && a[1] == 8 && a[2] == (uint16)sound)
return 2;
- i = (i+1) & (ARRAYSIZE(_cmd_queue)-1);
+ i = (i + 1) & (ARRAYSIZE(_cmd_queue) - 1);
}
return 0;
}
-int SoundEngine::set_volchan(int sound, int volchan) {
+int SoundEngine::set_volchan(int sound, int volchan)
+{
int r;
int i;
int num;
- Player *player,*best,*sameid;
+ Player *player, *best, *sameid;
r = get_volchan_entry(volchan);
- if (r==-1)
+ if (r == -1)
return -1;
if (r >= 8) {
- for(i=ARRAYSIZE(_players),player=_players; i!=0; i--,player++) {
- if (player->_active && player->_id==(uint16)sound && player->_vol_chan!=(uint16)volchan) {
+ for (i = ARRAYSIZE(_players), player = _players; i != 0; i--, player++) {
+ if (player->_active && player->_id == (uint16)sound
+ && player->_vol_chan != (uint16)volchan) {
player->_vol_chan = volchan;
player->set_vol(player->_volume);
return 0;
@@ -544,9 +578,9 @@ int SoundEngine::set_volchan(int sound, int volchan) {
best = NULL;
num = 0;
sameid = NULL;
- for(i=ARRAYSIZE(_players),player=_players; i!=0; i--,player++) {
+ for (i = ARRAYSIZE(_players), player = _players; i != 0; i--, player++) {
if (player->_active) {
- if (player->_vol_chan==(uint16)volchan) {
+ if (player->_vol_chan == (uint16)volchan) {
num++;
if (!best || player->_priority <= best->_priority)
best = player;
@@ -555,7 +589,7 @@ int SoundEngine::set_volchan(int sound, int volchan) {
}
}
}
- if (sameid==NULL)
+ if (sameid == NULL)
return -1;
if (num >= r)
best->clear();
@@ -565,7 +599,8 @@ int SoundEngine::set_volchan(int sound, int volchan) {
}
}
-int SoundEngine::clear_queue() {
+int SoundEngine::clear_queue()
+{
_queue_adding = false;
_queue_cleared = true;
_queue_pos = 0;
@@ -574,7 +609,9 @@ int SoundEngine::clear_queue() {
return 0;
}
-int SoundEngine::enqueue_command(int a, int b, int c, int d, int e, int f, int g) {
+int SoundEngine::enqueue_command(int a, int b, int c, int d, int e, int f,
+ int g)
+{
uint16 *p;
uint i;
@@ -583,7 +620,7 @@ int SoundEngine::enqueue_command(int a, int b, int c, int d, int e, int f, int g
if (i == _queue_end)
return -1;
- if (a==-1) {
+ if (a == -1) {
_queue_adding = false;
_trigger_count++;
return 0;
@@ -599,27 +636,28 @@ int SoundEngine::enqueue_command(int a, int b, int c, int d, int e, int f, int g
p[6] = f;
p[7] = g;
- i = (i+1) & (ARRAYSIZE(_cmd_queue)-1);
+ i = (i + 1) & (ARRAYSIZE(_cmd_queue) - 1);
- if (_queue_end!=i) {
+ if (_queue_end != i) {
_queue_pos = i;
return 0;
} else {
- _queue_pos = (i-1) & (ARRAYSIZE(_cmd_queue)-1);
+ _queue_pos = (i - 1) & (ARRAYSIZE(_cmd_queue) - 1);
return -1;
}
}
-int SoundEngine::query_queue(int param) {
- switch(param) {
- case 0: /* get trigger count */
+int SoundEngine::query_queue(int param)
+{
+ switch (param) {
+ case 0: /* get trigger count */
return _trigger_count;
- case 1: /* get trigger type */
- if (_queue_end==_queue_pos)
+ case 1: /* get trigger type */
+ if (_queue_end == _queue_pos)
return -1;
return _cmd_queue[_queue_end].array[1];
- case 2: /* get trigger sound */
- if (_queue_end==_queue_pos)
+ case 2: /* get trigger sound */
+ if (_queue_end == _queue_pos)
return 0xFF;
return _cmd_queue[_queue_end].array[2];
default:
@@ -627,48 +665,54 @@ int SoundEngine::query_queue(int param) {
}
}
-int SoundEngine::get_music_volume() {
+int SoundEngine::get_music_volume()
+{
return _music_volume;
}
-int SoundEngine::set_music_volume(uint vol) {
- if (vol > 100)
+int SoundEngine::set_music_volume(uint vol)
+{
+ if (vol > 100)
vol = 100;
if (vol < 1)
vol = 1;
-
- _music_volume = vol;
+
+ _music_volume = vol;
return 0;
}
-int SoundEngine::set_master_volume(uint vol) {
- int i;
+int SoundEngine::set_master_volume(uint vol)
+{
+ int i;
if (vol > 127)
return -1;
if (_music_volume > 0)
vol = vol / (100 / _music_volume);
- _master_volume = vol;
+ _master_volume = vol;
_s->_sound_volume_master = vol;
- for (i=0; i!=8; i++)
- _channel_volume_eff[i] = (_channel_volume[i]+1) * vol >> 7;
+ for (i = 0; i != 8; i++)
+ _channel_volume_eff[i] = (_channel_volume[i] + 1) * vol >> 7;
update_volumes();
return 0;
}
-int SoundEngine::get_master_volume() {
+int SoundEngine::get_master_volume()
+{
return _master_volume;
}
-int SoundEngine::terminate() {
+int SoundEngine::terminate()
+{
return 0;
/* not implemented */
}
-int SoundEngine::enqueue_trigger(int sound, int marker) {
+int SoundEngine::enqueue_trigger(int sound, int marker)
+{
uint16 *p;
uint pos;
@@ -679,12 +723,12 @@ int SoundEngine::enqueue_trigger(int sound, int marker) {
p[1] = sound;
p[2] = marker;
- pos = (pos+1) & (ARRAYSIZE(_cmd_queue)-1);
- if (_queue_end==pos) {
- _queue_pos = (pos-1) & (ARRAYSIZE(_cmd_queue)-1);
+ pos = (pos + 1) & (ARRAYSIZE(_cmd_queue) - 1);
+ if (_queue_end == pos) {
+ _queue_pos = (pos - 1) & (ARRAYSIZE(_cmd_queue) - 1);
return -1;
}
-
+
_queue_pos = pos;
_queue_adding = true;
_queue_sound = sound;
@@ -692,16 +736,18 @@ int SoundEngine::enqueue_trigger(int sound, int marker) {
return 0;
}
-int32 SoundEngine::do_command(int a, int b, int c, int d, int e, int f, int g, int h) {
- byte cmd = a&0xFF;
- byte param = a>>8;
- Player *player=NULL;
+int32 SoundEngine::do_command(int a, int b, int c, int d, int e, int f, int g,
+ int h)
+{
+ byte cmd = a & 0xFF;
+ byte param = a >> 8;
+ Player *player = NULL;
if (!_initialized && (cmd || param))
return -1;
- if (param==0) {
- switch(cmd) {
+ if (param == 0) {
+ switch (cmd) {
case 6:
return set_master_volume(b);
case 7:
@@ -715,29 +761,29 @@ int32 SoundEngine::do_command(int a, int b, int c, int d, int e, int f, int g, i
case 13:
return get_sound_status(b);
case 16:
- return set_volchan(b,c);
+ return set_volchan(b, c);
case 17:
- return set_channel_volume(b,c);
+ return set_channel_volume(b, c);
case 18:
- return set_volchan_entry(b,c);
+ return set_volchan_entry(b, c);
default:
warning("SoundEngine::do_command invalid command %d", cmd);
}
- } else if (param==1) {
-
- if ( (1<<cmd) & (0x783FFF)) {
+ } else if (param == 1) {
+
+ if ((1 << cmd) & (0x783FFF)) {
player = get_player_byid(b);
if (!player)
return -1;
- if ( (1<<cmd) & (1<<11 | 1<<22) ) {
- assert(c>=0 && c<=15);
- player = (Player*)player->get_part(c);
- if(!player)
+ if ((1 << cmd) & (1 << 11 | 1 << 22)) {
+ assert(c >= 0 && c <= 15);
+ player = (Player *)player->get_part(c);
+ if (!player)
return -1;
}
}
-
- switch(cmd) {
+
+ switch (cmd) {
case 0:
return player->get_param(c, d);
case 1:
@@ -757,35 +803,35 @@ int32 SoundEngine::do_command(int a, int b, int c, int d, int e, int f, int g, i
player->set_speed(c);
return 0;
case 7:
- return player->jump(c,d,e) ? 0 : -1;
+ return player->jump(c, d, e) ? 0 : -1;
case 8:
- return player->scan(c,d,e);
+ return player->scan(c, d, e);
case 9:
- return player->set_loop(c,d,e,f,g) ? 0 : -1;
+ return player->set_loop(c, d, e, f, g) ? 0 : -1;
case 10:
player->clear_loop();
return 0;
case 11:
- ((Part*)player)->set_onoff(d!=0);
+ ((Part *)player)->set_onoff(d != 0);
return 0;
case 12:
return player->_hook.set(c, d, e);
case 13:
- return player->fade_vol(c,d);
+ return player->fade_vol(c, d);
case 14:
- return enqueue_trigger(b,c);
+ return enqueue_trigger(b, c);
case 15:
- return enqueue_command(b,c,d,e,f,g,h);
+ return enqueue_command(b, c, d, e, f, g, h);
case 16:
return clear_queue();
case 19:
- return player->get_param(c,d);
+ return player->get_param(c, d);
case 20:
- return player->_hook.set(c,d,e);
+ return player->_hook.set(c, d, e);
case 21:
return -1;
case 22:
- ((Part*)player)->set_vol(d);
+ ((Part *)player)->set_vol(d);
return 0;
case 23:
return query_queue(b);
@@ -800,35 +846,39 @@ int32 SoundEngine::do_command(int a, int b, int c, int d, int e, int f, int g, i
return -1;
}
-int SoundEngine::set_channel_volume(uint chan, uint vol) {
- if (chan>=8 || vol>127)
+int SoundEngine::set_channel_volume(uint chan, uint vol)
+{
+ if (chan >= 8 || vol > 127)
return -1;
_channel_volume[chan] = vol;
- _channel_volume_eff[chan] = _master_volume * (vol+1) >> 7;
+ _channel_volume_eff[chan] = _master_volume * (vol + 1) >> 7;
update_volumes();
return 0;
}
-void SoundEngine::update_volumes() {
+void SoundEngine::update_volumes()
+{
Player *player;
int i;
- for(i=ARRAYSIZE(_players),player=_players; i!=0; i--,player++) {
+ for (i = ARRAYSIZE(_players), player = _players; i != 0; i--, player++) {
if (player->_active)
player->set_vol(player->_volume);
}
}
-int SoundEngine::set_volchan_entry(uint a, uint b) {
+int SoundEngine::set_volchan_entry(uint a, uint b)
+{
if (a >= 8)
return -1;
_volchan_table[a] = b;
return 0;
}
-int HookDatas::query_param(int param, byte chan) {
- switch(param) {
+int HookDatas::query_param(int param, byte chan)
+{
+ switch (param) {
case 18:
return _jump;
case 19:
@@ -846,8 +896,9 @@ int HookDatas::query_param(int param, byte chan) {
}
}
-int HookDatas::set(byte cls, byte value, byte chan) {
- switch(cls) {
+int HookDatas::set(byte cls, byte value, byte chan)
+{
+ switch (cls) {
case 0:
_jump = value;
break;
@@ -855,27 +906,27 @@ int HookDatas::set(byte cls, byte value, byte chan) {
_transpose = value;
break;
case 2:
- if (chan<16)
+ if (chan < 16)
_part_onoff[chan] = value;
- else if (chan==16)
+ else if (chan == 16)
memset(_part_onoff, value, 16);
break;
case 3:
- if (chan<16)
+ if (chan < 16)
_part_volume[chan] = value;
- else if (chan==16)
+ else if (chan == 16)
memset(_part_volume, value, 16);
break;
case 4:
- if (chan<16)
+ if (chan < 16)
_part_program[chan] = value;
- else if (chan==16)
+ else if (chan == 16)
memset(_part_program, value, 16);
break;
case 5:
- if (chan<16)
+ if (chan < 16)
_part_transpose[chan] = value;
- else if (chan==16)
+ else if (chan == 16)
memset(_part_transpose, value, 16);
break;
default:
@@ -885,12 +936,13 @@ int HookDatas::set(byte cls, byte value, byte chan) {
}
-VolumeFader *SoundEngine::allocate_volume_fader() {
+VolumeFader *SoundEngine::allocate_volume_fader()
+{
VolumeFader *vf;
int i;
vf = _volume_fader;
- for(i=ARRAYSIZE(_volume_fader); vf->active; ) {
+ for (i = ARRAYSIZE(_volume_fader); vf->active;) {
vf++;
if (!--i)
return NULL;
@@ -901,13 +953,14 @@ VolumeFader *SoundEngine::allocate_volume_fader() {
return vf;
}
-Player *SoundEngine::get_player_byid(int id) {
+Player *SoundEngine::get_player_byid(int id)
+{
int i;
- Player *player,*found=NULL;
+ Player *player, *found = NULL;
- for(i=ARRAYSIZE(_players),player=_players; i!=0; i--,player++) {
- if (player->_active && player->_id==(uint16)id) {
- if(found)
+ for (i = ARRAYSIZE(_players), player = _players; i != 0; i--, player++) {
+ if (player->_active && player->_id == (uint16)id) {
+ if (found)
return NULL;
found = player;
}
@@ -915,13 +968,15 @@ Player *SoundEngine::get_player_byid(int id) {
return found;
}
-int SoundEngine::get_volchan_entry(uint a) {
- if (a<8)
+int SoundEngine::get_volchan_entry(uint a)
+{
+ if (a < 8)
return _volchan_table[a];
return -1;
}
-int SoundEngine::initialize(Scumm *scumm, SoundDriver *driver) {
+int SoundEngine::initialize(Scumm *scumm, SoundDriver * driver)
+{
int i;
if (_initialized)
return -1;
@@ -929,12 +984,13 @@ int SoundEngine::initialize(Scumm *scumm, SoundDriver *driver) {
scumm->_soundEngine = this;
_s = scumm;
- _driver = (SOUND_DRIVER_TYPE*)driver;
-
+ _driver = (SOUND_DRIVER_TYPE *) driver;
+
_master_volume = 127;
- if (_music_volume < 1) _music_volume = 60;
+ if (_music_volume < 1)
+ _music_volume = 60;
- for (i=0; i!=8; i++)
+ for (i = 0; i != 8; i++)
_channel_volume[i] = _channel_volume_eff[i] = _volchan_table[i] = 127;
init_players();
@@ -946,18 +1002,20 @@ int SoundEngine::initialize(Scumm *scumm, SoundDriver *driver) {
_driver->init(this);
_initialized = true;
-
+
return 0;
}
-void SoundEngine::init_queue() {
+void SoundEngine::init_queue()
+{
_queue_adding = false;
_queue_pos = 0;
_queue_end = 0;
_trigger_count = 0;
}
-void SoundEngine::pause(bool paused) {
+void SoundEngine::pause(bool paused)
+{
lock();
#if 0
@@ -965,7 +1023,7 @@ void SoundEngine::pause(bool paused) {
Part *part;
MidiChannel *mc;
- for (i=ARRAYSIZE(_parts),part=_parts; i!=0; i--, part++) {
+ for (i = ARRAYSIZE(_parts), part = _parts; i != 0; i--, part++) {
if (part->_player) {
if (paused) {
part->_vol_eff = 0;
@@ -985,18 +1043,19 @@ void SoundEngine::pause(bool paused) {
/*************************************************************************/
-int Player::fade_vol(byte vol, int time) {
+int Player::fade_vol(byte vol, int time)
+{
VolumeFader *vf;
int i;
cancel_volume_fade();
- if (time==0) {
+ if (time == 0) {
set_vol(vol);
return 0;
}
-
+
vf = _se->allocate_volume_fader();
- if (vf==NULL)
+ if (vf == NULL)
return -1;
vf->player = this;
@@ -1004,7 +1063,7 @@ int Player::fade_vol(byte vol, int time) {
vf->curvol = _volume;
i = (vol - vf->curvol);
vf->speed_hi = i / time;
- if (i<0) {
+ if (i < 0) {
i = -i;
vf->direction = -1;
} else {
@@ -1015,7 +1074,8 @@ int Player::fade_vol(byte vol, int time) {
return 0;
}
-void Player::clear() {
+void Player::clear()
+{
uninit_seq();
cancel_volume_fade();
uninit_parts();
@@ -1023,13 +1083,14 @@ void Player::clear() {
_ticks_per_beat = TICKS_PER_BEAT;
}
-bool Player::start_sound(int sound) {
+bool Player::start_sound(int sound)
+{
void *mdhd;
-
+
mdhd = _se->findTag(sound, MDHD_TAG, 0);
- if (mdhd==NULL) {
+ if (mdhd == NULL) {
mdhd = _se->findTag(sound, MDPG_TAG, 0);
- if (mdhd==NULL) {
+ if (mdhd == NULL) {
warning("P::start_sound failed: Couldn't find %s", MDHD_TAG);
return false;
}
@@ -1041,7 +1102,7 @@ bool Player::start_sound(int sound) {
_volume = 0x7F;
_vol_chan = 0xFFFF;
- _vol_eff = (_se->get_channel_volume(0xFFFF)<<7)>>7;
+ _vol_eff = (_se->get_channel_volume(0xFFFF) << 7) >> 7;
_pan = 0;
_transpose = 0;
@@ -1055,11 +1116,13 @@ bool Player::start_sound(int sound) {
return true;
}
-void Player::hook_clear() {
+void Player::hook_clear()
+{
memset(&_hook, 0, sizeof(_hook));
}
-int Player::start_seq_sound(int sound) {
+int Player::start_seq_sound(int sound)
+{
byte *ptr, *track_ptr;
_song_index = sound;
@@ -1074,141 +1137,150 @@ int Player::start_seq_sound(int sound) {
set_tempo(500000);
set_speed(128);
ptr = _se->findTag(sound, "MTrk", _track_index);
- if (ptr==NULL)
+ if (ptr == NULL)
return -1;
-
+
track_ptr = ptr;
_cur_pos = _next_pos = get_delta_time(&track_ptr);
_song_offset = track_ptr - ptr;
-
+
_tick_index = _cur_pos;
_beat_index = 1;
if (_tick_index >= _ticks_per_beat) {
- _beat_index += _tick_index/_ticks_per_beat;
+ _beat_index += _tick_index / _ticks_per_beat;
_tick_index %= _ticks_per_beat;
}
return 0;
}
-void Player::set_tempo(uint32 b) {
- uint32 i,j;
+void Player::set_tempo(uint32 b)
+{
+ uint32 i, j;
- if (_se->_s->_gameTempo < 1000)
- i = TEMPO_BASE;
- else
- i = _se->_s->_gameTempo;
+ if (_se->_s->_gameTempo < 1000)
+ i = TEMPO_BASE;
+ else
+ i = _se->_s->_gameTempo;
j = _tempo = b;
- while (i&0xFFFF0000 || j&0xFFFF0000) { i>>=1; j>>=1; }
+ while (i & 0xFFFF0000 || j & 0xFFFF0000) {
+ i >>= 1;
+ j >>= 1;
+ }
- _tempo_eff = (i<<16) / j;
+ _tempo_eff = (i << 16) / j;
set_speed(_speed);
}
-void Player::cancel_volume_fade() {
+void Player::cancel_volume_fade()
+{
VolumeFader *vf = _se->_volume_fader;
int i;
- for (i=0; i<8; i++,vf++) {
- if (vf->active && vf->player==this)
+ for (i = 0; i < 8; i++, vf++) {
+ if (vf->active && vf->player == this)
vf->active = false;
}
}
-void Player::uninit_parts() {
+void Player::uninit_parts()
+{
if (_parts && _parts->_player != this)
error("asd");
- while(_parts)
+ while (_parts)
_parts->uninit();
}
-void Player::uninit_seq() {
+void Player::uninit_seq()
+{
_abort = true;
}
-void Player::set_speed(byte speed) {
+void Player::set_speed(byte speed)
+{
_speed = speed;
_timer_speed = (_tempo_eff * speed >> 7);
}
-byte *Player::parse_midi(byte *s) {
- byte cmd,chan,note,velocity,control;
+byte *Player::parse_midi(byte *s)
+{
+ byte cmd, chan, note, velocity, control;
uint value;
Part *part;
-
+
cmd = *s++;
- chan = cmd&0xF;
+ chan = cmd & 0xF;
- switch(cmd>>4) {
- case 0x8: /* key off */
+ switch (cmd >> 4) {
+ case 0x8: /* key off */
note = *s++;
if (!_scanning) {
key_off(chan, note);
} else {
clear_active_note(chan, note);
}
- s++; /* skip velocity */
+ s++; /* skip velocity */
break;
- case 0x9: /* key on */
+ case 0x9: /* key on */
note = *s++;
velocity = *s++;
if (velocity) {
if (!_scanning)
- key_on(chan, note,velocity);
+ key_on(chan, note, velocity);
else
- set_active_note(chan,note);
+ set_active_note(chan, note);
} else {
if (!_scanning)
key_off(chan, note);
else
- clear_active_note(chan,note);
+ clear_active_note(chan, note);
}
break;
- case 0xA: /* aftertouch */
+ case 0xA: /* aftertouch */
s += 2;
break;
- case 0xB: /* control change */
+ case 0xB: /* control change */
control = *s++;
value = *s++;
part = get_part(chan);
if (!part)
break;
-
- switch(control) {
- case 1: /* modulation wheel */
+
+ switch (control) {
+ case 1: /* modulation wheel */
part->set_modwheel(value);
break;
- case 7: /* volume */
+ case 7: /* volume */
part->set_vol(value);
break;
- case 10: /* pan position */
+ case 10: /* pan position */
part->set_pan(value - 0x40);
break;
- case 16: /* pitchbend factor */
+ case 16: /* pitchbend factor */
part->set_pitchbend_factor(value);
break;
- case 17: /* gp slider 2 */
+ case 17: /* gp slider 2 */
part->set_detune(value - 0x40);
break;
- case 18: /* gp slider 3 */
+ case 18: /* gp slider 3 */
part->set_pri(value - 0x40);
_se->_driver->update_pris();
break;
- case 64: /* hold pedal */
- part->set_pedal(value!=0);
+ case 64: /* hold pedal */
+ part->set_pedal(value != 0);
break;
- case 91: /* effects level */
+ case 91: /* effects level */
part->set_effect_level(value);
break;
- case 93: /* chorus */
+ case 93: /* chorus */
part->set_chorus(value);
break;
default:
@@ -1216,41 +1288,41 @@ byte *Player::parse_midi(byte *s) {
}
break;
- case 0xC: /* program change */
+ case 0xC: /* program change */
value = *s++;
part = get_part(chan);
if (part)
part->set_program(value);
break;
- case 0xD: /* channel pressure */
+ case 0xD: /* channel pressure */
s++;
break;
- case 0xE: /* pitch bend */
+ case 0xE: /* pitch bend */
part = get_part(chan);
if (part)
- part->set_pitchbend(((s[1]-0x40)<<7)|s[0]);
- s+=2;
+ part->set_pitchbend(((s[1] - 0x40) << 7) | s[0]);
+ s += 2;
break;
case 0xF:
- if (chan==0) {
+ if (chan == 0) {
uint size = get_delta_time(&s);
- if (*s==SYSEX_ID)
- parse_sysex(s,size);
+ if (*s == SYSEX_ID)
+ parse_sysex(s, size);
s += size;
- } else if (chan==0xF) {
+ } else if (chan == 0xF) {
cmd = *s++;
- if (cmd==47)
- goto Error; /* end of song */
- if (cmd==81) {
- set_tempo((s[1]<<16) | (s[2]<<8) | s[3]);
- s+=4;
+ if (cmd == 47)
+ goto Error; /* end of song */
+ if (cmd == 81) {
+ set_tempo((s[1] << 16) | (s[2] << 8) | s[3]);
+ s += 4;
break;
}
s += get_delta_time(&s);
- } else if (chan==0x7) {
+ } else if (chan == 0x7) {
s += get_delta_time(&s);
} else {
goto Error;
@@ -1258,15 +1330,16 @@ byte *Player::parse_midi(byte *s) {
break;
default:
-Error:;
- if(!_scanning)
+ Error:;
+ if (!_scanning)
clear();
return NULL;
}
return s;
}
-void Player::parse_sysex(byte *p, uint len) {
+void Player::parse_sysex(byte *p, uint len)
+{
byte code;
byte a;
uint b;
@@ -1274,80 +1347,80 @@ void Player::parse_sysex(byte *p, uint len) {
Part *part;
/* too big? */
- if (len>=sizeof(buf)*2)
+ if (len >= sizeof(buf) * 2)
return;
/* skip sysex manufacturer */
p++;
len -= 2;
-
- switch(code=*p++) {
- case 16: /* set instrument in part */
+
+ switch (code = *p++) {
+ case 16: /* set instrument in part */
a = *p++ & 0x0F;
if (HARDWARE_TYPE != *p++)
break;
decode_sysex_bytes(p, buf, len - 3);
part = get_part(a);
- if(part)
- part->set_instrument((Instrument*)buf);
+ if (part)
+ part->set_instrument((Instrument *) buf);
break;
- case 17: /* set global instrument */
+ case 17: /* set global instrument */
p++;
if (HARDWARE_TYPE != *p++)
break;
- a=*p++;
+ a = *p++;
decode_sysex_bytes(p, buf, len - 4);
_se->_driver->set_instrument(a, buf);
break;
- case 33: /* param adjust */
+ case 33: /* param adjust */
a = *p++ & 0x0F;
if (HARDWARE_TYPE != *p++)
break;
decode_sysex_bytes(p, buf, len - 3);
part = get_part(a);
if (part)
- part->set_param(read_word(buf),read_word(buf+2));
+ part->set_param(read_word(buf), read_word(buf + 2));
break;
- case 48: /* hook - jump */
+ case 48: /* hook - jump */
if (_scanning)
break;
- decode_sysex_bytes(p+1,buf,len-2);
+ decode_sysex_bytes(p + 1, buf, len - 2);
maybe_jump(buf);
break;
- case 49: /* hook - global transpose */
- decode_sysex_bytes(p+1,buf,len-2);
+ case 49: /* hook - global transpose */
+ decode_sysex_bytes(p + 1, buf, len - 2);
maybe_set_transpose(buf);
break;
- case 50: /* hook - part on/off */
+ case 50: /* hook - part on/off */
buf[0] = *p++ & 0x0F;
- decode_sysex_bytes(p,buf+1,len-2);
+ decode_sysex_bytes(p, buf + 1, len - 2);
maybe_part_onoff(buf);
break;
- case 51: /* hook - set volume */
+ case 51: /* hook - set volume */
buf[0] = *p++ & 0x0F;
- decode_sysex_bytes(p,buf+1,len-2);
+ decode_sysex_bytes(p, buf + 1, len - 2);
maybe_set_volume(buf);
break;
- case 52: /* hook - set program */
+ case 52: /* hook - set program */
buf[0] = *p++ & 0x0F;
- decode_sysex_bytes(p,buf+1,len-2);
+ decode_sysex_bytes(p, buf + 1, len - 2);
maybe_set_program(buf);
break;
-
- case 53: /* hook - set transpose */
+
+ case 53: /* hook - set transpose */
buf[0] = *p++ & 0x0F;
- decode_sysex_bytes(p,buf+1,len-2);
+ decode_sysex_bytes(p, buf + 1, len - 2);
maybe_set_transpose_part(buf);
break;
- case 64: /* marker */
+ case 64: /* marker */
p++;
len -= 2;
while (len--) {
@@ -1355,75 +1428,78 @@ void Player::parse_sysex(byte *p, uint len) {
}
break;
- case 80: /* loop */
- decode_sysex_bytes(p+1,buf,len-2);
- set_loop(
- read_word(buf),
- read_word(buf+2),
- read_word(buf+4),
- read_word(buf+6),
- read_word(buf+8)
- );
+ case 80: /* loop */
+ decode_sysex_bytes(p + 1, buf, len - 2);
+ set_loop(read_word(buf),
+ read_word(buf + 2),
+ read_word(buf + 4), read_word(buf + 6), read_word(buf + 8)
+ );
break;
- case 81: /* end loop */
+ case 81: /* end loop */
clear_loop();
break;
- case 96: /* set instrument */
+ case 96: /* set instrument */
part = get_part(p[0] & 0x0F);
- b = (p[1]&0x0F)<<12 | (p[2]&0x0F)<<8 | (p[4]&0x0F)<<4 | (p[4]&0x0F);
- if(part)
+ b =
+ (p[1] & 0x0F) << 12 | (p[2] & 0x0F) << 8 | (p[4] & 0x0F) << 4 | (p[4] &
+ 0x0F);
+ if (part)
part->set_instrument(b);
break;
default:
- debug(6,"unknown sysex %d", code);
+ debug(6, "unknown sysex %d", code);
}
}
-void Player::decode_sysex_bytes(byte *src, byte *dst, int len) {
- while(len>=0) {
- *dst++ = (src[0]<<4)|(src[1]&0xF);
+void Player::decode_sysex_bytes(byte *src, byte *dst, int len)
+{
+ while (len >= 0) {
+ *dst++ = (src[0] << 4) | (src[1] & 0xF);
src += 2;
len -= 2;
}
}
-void Player::maybe_jump(byte *data) {
+void Player::maybe_jump(byte *data)
+{
byte cmd;
cmd = data[0];
/* is this the hook i'm waiting for? */
- if (cmd && _hook._jump!=cmd)
+ if (cmd && _hook._jump != cmd)
return;
/* reset hook? */
- if(cmd!=0 && cmd<0x80)
+ if (cmd != 0 && cmd < 0x80)
_hook._jump = 0;
- jump(read_word(data+1), read_word(data+3), read_word(data+5));
+ jump(read_word(data + 1), read_word(data + 3), read_word(data + 5));
}
-void Player::maybe_set_transpose(byte *data) {
+void Player::maybe_set_transpose(byte *data)
+{
byte cmd;
cmd = data[0];
/* is this the hook i'm waiting for? */
- if (cmd && _hook._transpose!=cmd)
+ if (cmd && _hook._transpose != cmd)
return;
/* reset hook? */
- if(cmd!=0 && cmd<0x80)
+ if (cmd != 0 && cmd < 0x80)
_hook._transpose = 0;
- set_transpose(data[1], (int8)data[2]);
+ set_transpose(data[1], (int8) data[2]);
}
-void Player::maybe_part_onoff(byte *data) {
- byte cmd,*p;
+void Player::maybe_part_onoff(byte *data)
+{
+ byte cmd, *p;
uint chan;
Part *part;
@@ -1433,18 +1509,19 @@ void Player::maybe_part_onoff(byte *data) {
p = &_hook._part_onoff[chan];
/* is this the hook i'm waiting for? */
- if (cmd && *p!=cmd)
+ if (cmd && *p != cmd)
return;
- if (cmd!=0 && cmd<0x80)
+ if (cmd != 0 && cmd < 0x80)
*p = 0;
part = get_part(chan);
if (part)
- part->set_onoff(data[2]!=0);
+ part->set_onoff(data[2] != 0);
}
-void Player::maybe_set_volume(byte *data) {
+void Player::maybe_set_volume(byte *data)
+{
byte cmd;
byte *p;
uint chan;
@@ -1456,11 +1533,11 @@ void Player::maybe_set_volume(byte *data) {
p = &_hook._part_volume[chan];
/* is this the hook i'm waiting for? */
- if (cmd && *p!=cmd)
+ if (cmd && *p != cmd)
return;
/* reset hook? */
- if (cmd!=0 && cmd<0x80)
+ if (cmd != 0 && cmd < 0x80)
*p = 0;
part = get_part(chan);
@@ -1468,7 +1545,8 @@ void Player::maybe_set_volume(byte *data) {
part->set_vol(data[2]);
}
-void Player::maybe_set_program(byte *data) {
+void Player::maybe_set_program(byte *data)
+{
byte cmd;
byte *p;
uint chan;
@@ -1480,10 +1558,10 @@ void Player::maybe_set_program(byte *data) {
/* is this the hook i'm waiting for? */
p = &_hook._part_program[chan];
- if (cmd && *p!=cmd)
+ if (cmd && *p != cmd)
return;
- if (cmd!=0 && cmd<0x80)
+ if (cmd != 0 && cmd < 0x80)
*p = 0;
part = get_part(chan);
@@ -1491,7 +1569,8 @@ void Player::maybe_set_program(byte *data) {
part->set_program(data[2]);
}
-void Player::maybe_set_transpose_part(byte *data) {
+void Player::maybe_set_transpose_part(byte *data)
+{
byte cmd;
byte *p;
uint chan;
@@ -1502,49 +1581,54 @@ void Player::maybe_set_transpose_part(byte *data) {
/* is this the hook i'm waiting for? */
p = &_hook._part_transpose[chan];
- if (cmd && *p!=cmd)
+ if (cmd && *p != cmd)
return;
/* reset hook? */
- if (cmd!=0 && cmd<0x80)
+ if (cmd != 0 && cmd < 0x80)
*p = 0;
- part_set_transpose(chan, data[2], (int8)data[3]);
+ part_set_transpose(chan, data[2], (int8) data[3]);
}
-int Player::set_transpose(byte relative, int b) {
+int Player::set_transpose(byte relative, int b)
+{
Part *part;
- if (b>24 || b<-24 || relative>1)
+ if (b > 24 || b < -24 || relative > 1)
return -1;
if (relative)
b = transpose_clamp(_transpose + b, -7, 7);
_transpose = b;
- for(part=_parts; part; part=part->_next) {
+ for (part = _parts; part; part = part->_next) {
part->set_transpose(part->_transpose);
}
return 0;
}
-void Player::clear_active_notes() {
+void Player::clear_active_notes()
+{
memset(_se->_active_notes, 0, sizeof(_se->_active_notes));
}
-void Player::clear_active_note(int chan, byte note) {
- _se->_active_notes[note] &= ~(1<<chan);
+void Player::clear_active_note(int chan, byte note)
+{
+ _se->_active_notes[note] &= ~(1 << chan);
}
-void Player::set_active_note(int chan, byte note) {
- _se->_active_notes[note] |= (1<<chan);
+void Player::set_active_note(int chan, byte note)
+{
+ _se->_active_notes[note] |= (1 << chan);
}
-void Player::part_set_transpose(uint8 chan, byte relative, int8 b) {
+void Player::part_set_transpose(uint8 chan, byte relative, int8 b)
+{
Part *part;
- if (b>24 || b<-24)
+ if (b > 24 || b < -24)
return;
part = get_part(chan);
@@ -1555,7 +1639,8 @@ void Player::part_set_transpose(uint8 chan, byte relative, int8 b) {
part->set_transpose(b);
}
-void Player::key_on(uint8 chan, uint8 note, uint8 velocity) {
+void Player::key_on(uint8 chan, uint8 note, uint8 velocity)
+{
Part *part;
part = get_part(chan);
@@ -1565,18 +1650,20 @@ void Player::key_on(uint8 chan, uint8 note, uint8 velocity) {
part->key_on(note, velocity);
}
-void Player::key_off(uint8 chan, uint8 note) {
+void Player::key_off(uint8 chan, uint8 note)
+{
Part *part;
- for(part=_parts; part; part = part->_next) {
- if (part->_chan==(byte)chan && part->_on)
+ for (part = _parts; part; part = part->_next) {
+ if (part->_chan == (byte)chan && part->_on)
part->key_off(note);
}
}
-bool Player::jump(uint track, uint beat, uint tick) {
+bool Player::jump(uint track, uint beat, uint tick)
+{
byte *mtrk, *cur_mtrk, *scanpos;
- uint32 topos,curpos,track_offs;
+ uint32 topos, curpos, track_offs;
if (!_active)
return false;
@@ -1585,16 +1672,16 @@ bool Player::jump(uint track, uint beat, uint tick) {
if (!mtrk)
return false;
- cur_mtrk = _se->findTag(_song_index,"MTrk", _track_index);
+ cur_mtrk = _se->findTag(_song_index, "MTrk", _track_index);
if (!cur_mtrk)
return false;
_se->lock();
- if (beat==0)
- beat=1;
+ if (beat == 0)
+ beat = 1;
- topos = (beat-1) * _ticks_per_beat + tick;
+ topos = (beat - 1) * _ticks_per_beat + tick;
if (track == _track_index && topos >= _cur_pos) {
scanpos = _song_offset + mtrk;
@@ -1617,7 +1704,8 @@ bool Player::jump(uint track, uint beat, uint tick) {
turn_off_pedals();
- find_sustaining_notes(cur_mtrk+_song_offset, mtrk+track_offs, curpos-topos);
+ find_sustaining_notes(cur_mtrk + _song_offset, mtrk + track_offs,
+ curpos - topos);
_beat_index = beat;
_tick_index = tick;
@@ -1634,14 +1722,16 @@ bool Player::jump(uint track, uint beat, uint tick) {
return true;
}
-bool Player::set_loop(uint count, uint tobeat, uint totick, uint frombeat, uint fromtick) {
- if (tobeat+1 >= frombeat)
+bool Player::set_loop(uint count, uint tobeat, uint totick, uint frombeat,
+ uint fromtick)
+{
+ if (tobeat + 1 >= frombeat)
return false;
- if (tobeat==0)
- tobeat=1;
+ if (tobeat == 0)
+ tobeat = 1;
- _loop_counter = 0; /* because of possible interrupts */
+ _loop_counter = 0; /* because of possible interrupts */
_loop_to_beat = tobeat;
_loop_to_tick = totick;
_loop_from_beat = frombeat;
@@ -1651,24 +1741,27 @@ bool Player::set_loop(uint count, uint tobeat, uint totick, uint frombeat, uint
return true;
}
-void Player::clear_loop() {
+void Player::clear_loop()
+{
_loop_counter = 0;
}
-void Player::turn_off_pedals() {
+void Player::turn_off_pedals()
+{
Part *part;
- for(part=_parts; part; part = part->_next) {
+ for (part = _parts; part; part = part->_next) {
if (part->_pedal)
part->set_pedal(false);
}
}
-void Player::find_sustaining_notes(byte *a, byte *b, uint32 l) {
+void Player::find_sustaining_notes(byte *a, byte *b, uint32 l)
+{
uint32 pos;
uint16 mask;
uint16 *bitlist_ptr;
- SustainingNotes *sn,*next;
+ SustainingNotes *sn, *next;
IsNoteCmdData isnote;
int j;
uint num_active;
@@ -1678,7 +1771,7 @@ void Player::find_sustaining_notes(byte *a, byte *b, uint32 l) {
/* pos contains number of ticks since current position */
pos = _next_pos - _cur_pos;
- if ((int32)pos<0)
+ if ((int32) pos < 0)
pos = 0;
/* locate the positions where the notes are turned off.
@@ -1686,20 +1779,20 @@ void Player::find_sustaining_notes(byte *a, byte *b, uint32 l) {
*/
while (num_active != 0) {
/* is note off? */
- j = is_note_cmd(&a,&isnote);
- if (j==-1)
+ j = is_note_cmd(&a, &isnote);
+ if (j == -1)
break;
if (j == 1) {
- mask = 1<<isnote.chan;
+ mask = 1 << isnote.chan;
bitlist_ptr = _se->_active_notes + isnote.note;
if (*bitlist_ptr & mask) {
*bitlist_ptr &= ~mask;
num_active--;
/* Get a node from the free list */
- if ((sn=_se->_sustain_notes_free) == NULL)
+ if ((sn = _se->_sustain_notes_free) == NULL)
return;
_se->_sustain_notes_free = sn->next;
-
+
/* Insert it in the beginning of the used list */
sn->next = _se->_sustain_notes_used;
_se->_sustain_notes_used = sn;
@@ -1720,8 +1813,8 @@ void Player::find_sustaining_notes(byte *a, byte *b, uint32 l) {
/* find the maximum position where a note was turned off */
max_off_pos = 0;
- for(sn=_se->_sustain_notes_used; sn; sn = sn->next) {
- _se->_active_notes[sn->note] |= (1<<sn->chan);
+ for (sn = _se->_sustain_notes_used; sn; sn = sn->next) {
+ _se->_active_notes[sn->note] |= (1 << sn->chan);
if (sn->off_pos > max_off_pos) {
max_off_pos = sn->off_pos;
}
@@ -1730,18 +1823,19 @@ void Player::find_sustaining_notes(byte *a, byte *b, uint32 l) {
/* locate positions where notes are turned on */
pos = l;
while (pos < max_off_pos) {
- j = is_note_cmd(&b,&isnote);
- if (j==-1)
+ j = is_note_cmd(&b, &isnote);
+ if (j == -1)
break;
if (j == 2) {
- mask = 1<<isnote.chan;
+ mask = 1 << isnote.chan;
bitlist_ptr = _se->_active_notes + isnote.note;
- if (*bitlist_ptr&mask) {
+ if (*bitlist_ptr & mask) {
sn = _se->_sustain_notes_used;
while (sn) {
next = sn->next;
- if (sn->note==isnote.note && sn->chan==isnote.chan && pos < sn->off_pos) {
+ if (sn->note == isnote.note && sn->chan == isnote.chan
+ && pos < sn->off_pos) {
*bitlist_ptr &= ~mask;
/* Unlink from the sustain list */
if (next)
@@ -1768,14 +1862,16 @@ void Player::find_sustaining_notes(byte *a, byte *b, uint32 l) {
return;
}
sn = _se->_sustain_notes_head;
- while (sn->next) sn = sn->next;
+ while (sn->next)
+ sn = sn->next;
sn->next = _se->_sustain_notes_used;
_se->_sustain_notes_used = NULL;
if (sn->next)
sn->next->prev = sn;
}
-Part *Player::get_part(uint8 chan) {
+Part *Player::get_part(uint8 chan)
+{
Part *part;
part = _parts;
@@ -1790,61 +1886,66 @@ Part *Player::get_part(uint8 chan) {
warning("no parts available");
return NULL;
}
-
+
part->_chan = chan;
part->setup(this);
return part;
}
-uint Player::update_actives() {
+uint Player::update_actives()
+{
Part *part;
uint16 *active;
int count = 0;
-
- clear_active_notes();
+
+ clear_active_notes();
active = _se->_active_notes;
- for(part=_parts; part; part = part->_next) {
+ for (part = _parts; part; part = part->_next) {
if (part->_mc)
count += part->update_actives(active);
}
return count;
}
-void Player::set_priority(int pri) {
+void Player::set_priority(int pri)
+{
Part *part;
_priority = pri;
- for(part=_parts; part; part = part->_next) {
+ for (part = _parts; part; part = part->_next) {
part->set_pri(part->_pri);
}
_se->_driver->update_pris();
}
-void Player::set_pan(int pan) {
+void Player::set_pan(int pan)
+{
Part *part;
_pan = pan;
- for(part=_parts; part; part = part->_next) {
+ for (part = _parts; part; part = part->_next) {
part->set_pan(part->_pan);
}
}
-void Player::set_detune(int detune) {
+void Player::set_detune(int detune)
+{
Part *part;
_detune = detune;
- for(part=_parts; part; part = part->_next) {
+ for (part = _parts; part; part = part->_next) {
part->set_detune(part->_detune);
}
}
-int Player::scan(uint totrack, uint tobeat, uint totick) {
- byte *mtrk,*scanptr;
- uint32 curpos,topos;
+int Player::scan(uint totrack, uint tobeat, uint totick)
+{
+ byte *mtrk, *scanptr;
+ uint32 curpos, topos;
uint32 pos;
- assert(totrack>=0 && tobeat>=0 && totick>=0);
+ assert(totrack >= 0 && tobeat >= 0 && totick >= 0);
if (!_active)
return -1;
@@ -1854,21 +1955,21 @@ int Player::scan(uint totrack, uint tobeat, uint totick) {
return -1;
_se->lock();
- if (tobeat==0)
+ if (tobeat == 0)
tobeat++;
turn_off_parts();
clear_active_notes();
scanptr = mtrk;
curpos = get_delta_time(&scanptr);
- _scanning=true;
+ _scanning = true;
- topos = (tobeat-1) * _ticks_per_beat + totick;
+ topos = (tobeat - 1) * _ticks_per_beat + totick;
while (curpos < topos) {
scanptr = parse_midi(scanptr);
if (!scanptr) {
- _scanning=false;
+ _scanning = false;
_se->unlock();
return -1;
}
@@ -1876,7 +1977,7 @@ int Player::scan(uint totrack, uint tobeat, uint totick) {
}
pos = scanptr - mtrk;
- _scanning=false;
+ _scanning = false;
_se->driver()->update_pris();
play_active_notes();
_beat_index = tobeat;
@@ -1893,28 +1994,31 @@ int Player::scan(uint totrack, uint tobeat, uint totick) {
return 0;
}
-void Player::turn_off_parts() {
+void Player::turn_off_parts()
+{
Part *part;
- for(part=_parts; part; part = part->_next)
+ for (part = _parts; part; part = part->_next)
part->off();
}
-void Player::play_active_notes() {
- int i,j;
+void Player::play_active_notes()
+{
+ int i, j;
uint mask;
- for (i=0; i!=128; i++) {
+ for (i = 0; i != 128; i++) {
mask = _se->_active_notes[i];
- for (j=0; j!=16; j++,mask>>=1) {
- if (mask&1) {
+ for (j = 0; j != 16; j++, mask >>= 1) {
+ if (mask & 1) {
key_on(j, i, 80);
}
}
}
}
-int Player::set_vol(byte vol) {
+int Player::set_vol(byte vol)
+{
Part *part;
if (vol > 127)
@@ -1923,15 +2027,16 @@ int Player::set_vol(byte vol) {
_volume = vol;
_vol_eff = _se->get_channel_volume(_vol_chan) * (vol + 1) >> 7;
- for(part=_parts; part; part=part->_next) {
+ for (part = _parts; part; part = part->_next) {
part->set_vol(part->_vol);
}
return 0;
}
-int Player::get_param(int param, byte chan) {
- switch(param) {
+int Player::get_param(int param, byte chan)
+{
+ switch (param) {
case 0:
return (byte)_priority;
case 1:
@@ -1960,22 +2065,31 @@ int Player::get_param(int param, byte chan) {
return _loop_from_beat;
case 13:
return _loop_from_tick;
- case 14: case 15: case 16: case 17:
+ case 14:
+ case 15:
+ case 16:
+ case 17:
return query_part_param(param, chan);
- case 18: case 19: case 20: case 21: case 22: case 23:
+ case 18:
+ case 19:
+ case 20:
+ case 21:
+ case 22:
+ case 23:
return _hook.query_param(param, chan);
default:
return -1;
}
}
-int Player::query_part_param(int param, byte chan) {
+int Player::query_part_param(int param, byte chan)
+{
Part *part;
part = _parts;
while (part) {
- if(part->_chan==chan) {
- switch(param) {
+ if (part->_chan == chan) {
+ switch (param) {
case 14:
return part->_on;
case 15:
@@ -2008,128 +2122,137 @@ enum {
TYPE_PLAYER = 2,
};
-int SoundEngine::saveReference(SoundEngine *me, byte type, void*ref) {
- switch(type) {
- case TYPE_PART: return (Part*)ref - me->_parts;
- case TYPE_PLAYER: return (Player*)ref - me->_players;
+int SoundEngine::saveReference(SoundEngine *me, byte type, void *ref)
+{
+ switch (type) {
+ case TYPE_PART:
+ return (Part *)ref - me->_parts;
+ case TYPE_PLAYER:
+ return (Player *)ref - me->_players;
default:
error("saveReference: invalid type");
}
}
-void *SoundEngine::loadReference(SoundEngine *me, byte type, int ref) {
- switch(type) {
- case TYPE_PART: return &me->_parts[ref];
- case TYPE_PLAYER: return &me->_players[ref];
+void *SoundEngine::loadReference(SoundEngine *me, byte type, int ref)
+{
+ switch (type) {
+ case TYPE_PART:
+ return &me->_parts[ref];
+ case TYPE_PLAYER:
+ return &me->_players[ref];
default:
error("loadReference: invalid type");
}
}
-int SoundEngine::save_or_load(Serializer *ser) {
+int SoundEngine::save_or_load(Serializer * ser)
+{
const SaveLoadEntry mainEntries[] = {
- MKLINE(SoundEngine,_queue_end, sleUint8),
- MKLINE(SoundEngine,_queue_pos, sleUint8),
- MKLINE(SoundEngine,_queue_sound, sleUint16),
- MKLINE(SoundEngine,_queue_adding, sleByte),
- MKLINE(SoundEngine,_queue_marker, sleByte),
- MKLINE(SoundEngine,_queue_cleared, sleByte),
- MKLINE(SoundEngine,_master_volume, sleByte),
- MKLINE(SoundEngine,_trigger_count, sleUint16),
- MKARRAY(SoundEngine,_channel_volume[0], sleUint16, 8),
- MKARRAY(SoundEngine,_volchan_table[0], sleUint16, 8),
+ MKLINE(SoundEngine, _queue_end, sleUint8),
+ MKLINE(SoundEngine, _queue_pos, sleUint8),
+ MKLINE(SoundEngine, _queue_sound, sleUint16),
+ MKLINE(SoundEngine, _queue_adding, sleByte),
+ MKLINE(SoundEngine, _queue_marker, sleByte),
+ MKLINE(SoundEngine, _queue_cleared, sleByte),
+ MKLINE(SoundEngine, _master_volume, sleByte),
+ MKLINE(SoundEngine, _trigger_count, sleUint16),
+ MKARRAY(SoundEngine, _channel_volume[0], sleUint16, 8),
+ MKARRAY(SoundEngine, _volchan_table[0], sleUint16, 8),
MKEND()
};
-
+
const SaveLoadEntry playerEntries[] = {
- MKREF(Player,_parts,TYPE_PART),
- MKLINE(Player,_active,sleByte),
- MKLINE(Player,_id,sleUint16),
- MKLINE(Player,_priority,sleByte),
- MKLINE(Player,_volume,sleByte),
- MKLINE(Player,_pan,sleInt8),
- MKLINE(Player,_transpose,sleByte),
- MKLINE(Player,_detune,sleInt8),
- MKLINE(Player,_vol_chan,sleUint16),
- MKLINE(Player,_vol_eff,sleByte),
- MKLINE(Player,_speed,sleByte),
- MKLINE(Player,_song_index,sleUint16),
- MKLINE(Player,_track_index,sleUint16),
- MKLINE(Player,_timer_counter,sleUint16),
- MKLINE(Player,_loop_to_beat,sleUint16),
- MKLINE(Player,_loop_from_beat,sleUint16),
- MKLINE(Player,_loop_counter,sleUint16),
- MKLINE(Player,_loop_to_tick,sleUint16),
- MKLINE(Player,_loop_from_tick,sleUint16),
- MKLINE(Player,_tempo,sleUint32),
- MKLINE(Player,_cur_pos,sleUint32),
- MKLINE(Player,_next_pos,sleUint32),
- MKLINE(Player,_song_offset,sleUint32),
- MKLINE(Player,_tick_index,sleUint16),
- MKLINE(Player,_beat_index,sleUint16),
- MKLINE(Player,_ticks_per_beat,sleUint16),
- MKLINE(Player,_hook._jump,sleByte),
- MKLINE(Player,_hook._transpose,sleByte),
- MKARRAY(Player,_hook._part_onoff[0],sleByte,16),
- MKARRAY(Player,_hook._part_volume[0],sleByte,16),
- MKARRAY(Player,_hook._part_program[0],sleByte,16),
- MKARRAY(Player,_hook._part_transpose[0],sleByte,16),
+ MKREF(Player, _parts, TYPE_PART),
+ MKLINE(Player, _active, sleByte),
+ MKLINE(Player, _id, sleUint16),
+ MKLINE(Player, _priority, sleByte),
+ MKLINE(Player, _volume, sleByte),
+ MKLINE(Player, _pan, sleInt8),
+ MKLINE(Player, _transpose, sleByte),
+ MKLINE(Player, _detune, sleInt8),
+ MKLINE(Player, _vol_chan, sleUint16),
+ MKLINE(Player, _vol_eff, sleByte),
+ MKLINE(Player, _speed, sleByte),
+ MKLINE(Player, _song_index, sleUint16),
+ MKLINE(Player, _track_index, sleUint16),
+ MKLINE(Player, _timer_counter, sleUint16),
+ MKLINE(Player, _loop_to_beat, sleUint16),
+ MKLINE(Player, _loop_from_beat, sleUint16),
+ MKLINE(Player, _loop_counter, sleUint16),
+ MKLINE(Player, _loop_to_tick, sleUint16),
+ MKLINE(Player, _loop_from_tick, sleUint16),
+ MKLINE(Player, _tempo, sleUint32),
+ MKLINE(Player, _cur_pos, sleUint32),
+ MKLINE(Player, _next_pos, sleUint32),
+ MKLINE(Player, _song_offset, sleUint32),
+ MKLINE(Player, _tick_index, sleUint16),
+ MKLINE(Player, _beat_index, sleUint16),
+ MKLINE(Player, _ticks_per_beat, sleUint16),
+ MKLINE(Player, _hook._jump, sleByte),
+ MKLINE(Player, _hook._transpose, sleByte),
+ MKARRAY(Player, _hook._part_onoff[0], sleByte, 16),
+ MKARRAY(Player, _hook._part_volume[0], sleByte, 16),
+ MKARRAY(Player, _hook._part_program[0], sleByte, 16),
+ MKARRAY(Player, _hook._part_transpose[0], sleByte, 16),
MKEND()
};
const SaveLoadEntry volumeFaderEntries[] = {
- MKREF(VolumeFader,player,TYPE_PLAYER),
- MKLINE(VolumeFader,active,sleUint8),
- MKLINE(VolumeFader,curvol,sleUint8),
- MKLINE(VolumeFader,speed_lo_max,sleUint16),
- MKLINE(VolumeFader,num_steps,sleUint16),
- MKLINE(VolumeFader,speed_hi,sleInt8),
- MKLINE(VolumeFader,direction,sleInt8),
- MKLINE(VolumeFader,speed_lo,sleInt8),
- MKLINE(VolumeFader,speed_lo_counter,sleUint16),
+ MKREF(VolumeFader, player, TYPE_PLAYER),
+ MKLINE(VolumeFader, active, sleUint8),
+ MKLINE(VolumeFader, curvol, sleUint8),
+ MKLINE(VolumeFader, speed_lo_max, sleUint16),
+ MKLINE(VolumeFader, num_steps, sleUint16),
+ MKLINE(VolumeFader, speed_hi, sleInt8),
+ MKLINE(VolumeFader, direction, sleInt8),
+ MKLINE(VolumeFader, speed_lo, sleInt8),
+ MKLINE(VolumeFader, speed_lo_counter, sleUint16),
MKEND()
};
const SaveLoadEntry partEntries[] = {
- MKREF(Part,_next,TYPE_PART),
- MKREF(Part,_prev,TYPE_PART),
- MKREF(Part,_player,TYPE_PLAYER),
- MKLINE(Part,_pitchbend,sleInt16),
- MKLINE(Part,_pitchbend_factor,sleUint8),
- MKLINE(Part,_transpose,sleInt8),
- MKLINE(Part,_vol,sleUint8),
- MKLINE(Part,_detune,sleInt8),
- MKLINE(Part,_pan,sleInt8),
- MKLINE(Part,_on,sleUint8),
- MKLINE(Part,_modwheel,sleUint8),
- MKLINE(Part,_pedal,sleUint8),
- MKLINE(Part,_program,sleUint8),
- MKLINE(Part,_pri,sleUint8),
- MKLINE(Part,_chan,sleUint8),
- MKLINE(Part,_effect_level,sleUint8),
- MKLINE(Part,_chorus,sleUint8),
- MKLINE(Part,_percussion,sleUint8),
- MKLINE(Part,_bank,sleUint8),
+ MKREF(Part, _next, TYPE_PART),
+ MKREF(Part, _prev, TYPE_PART),
+ MKREF(Part, _player, TYPE_PLAYER),
+ MKLINE(Part, _pitchbend, sleInt16),
+ MKLINE(Part, _pitchbend_factor, sleUint8),
+ MKLINE(Part, _transpose, sleInt8),
+ MKLINE(Part, _vol, sleUint8),
+ MKLINE(Part, _detune, sleInt8),
+ MKLINE(Part, _pan, sleInt8),
+ MKLINE(Part, _on, sleUint8),
+ MKLINE(Part, _modwheel, sleUint8),
+ MKLINE(Part, _pedal, sleUint8),
+ MKLINE(Part, _program, sleUint8),
+ MKLINE(Part, _pri, sleUint8),
+ MKLINE(Part, _chan, sleUint8),
+ MKLINE(Part, _effect_level, sleUint8),
+ MKLINE(Part, _chorus, sleUint8),
+ MKLINE(Part, _percussion, sleUint8),
+ MKLINE(Part, _bank, sleUint8),
MKEND()
};
if (!ser->isSaving()) {
stop_all_sounds();
}
-
- #ifdef _WIN32_WCE // Don't break savegames made with andys' build
- if (!ser->isSaving() && ser->checkEOFLoadStream())
- return 0;
- #endif
+#ifdef _WIN32_WCE // Don't break savegames made with andys' build
+ if (!ser->isSaving() && ser->checkEOFLoadStream())
+ return 0;
+#endif
ser->_ref_me = this;
- ser->_saveload_ref = ser->isSaving() ? ((void*)&saveReference) : ((void*)&loadReference);
+ ser->_saveload_ref =
+ ser->isSaving()? ((void *)&saveReference) : ((void *)&loadReference);
ser->saveLoadEntries(this, mainEntries);
- ser->saveLoadArrayOf(_players, ARRAYSIZE(_players), sizeof(_players[0]), playerEntries);
- ser->saveLoadArrayOf(_parts, ARRAYSIZE(_parts),sizeof(_parts[0]), partEntries);
- ser->saveLoadArrayOf(_volume_fader,ARRAYSIZE(_volume_fader),
- sizeof(_volume_fader[0]), volumeFaderEntries);
+ ser->saveLoadArrayOf(_players, ARRAYSIZE(_players), sizeof(_players[0]),
+ playerEntries);
+ ser->saveLoadArrayOf(_parts, ARRAYSIZE(_parts), sizeof(_parts[0]),
+ partEntries);
+ ser->saveLoadArrayOf(_volume_fader, ARRAYSIZE(_volume_fader),
+ sizeof(_volume_fader[0]), volumeFaderEntries);
if (!ser->isSaving()) {
/* Load all sounds that we need */
@@ -2146,11 +2269,12 @@ int SoundEngine::save_or_load(Serializer *ser) {
#undef MKLINE
#undef MKEND
-void SoundEngine::fix_parts_after_load() {
+void SoundEngine::fix_parts_after_load()
+{
Part *part;
int i;
- for (i=ARRAYSIZE(_parts),part=_parts; i!=0; i--, part++) {
+ for (i = ARRAYSIZE(_parts), part = _parts; i != 0; i--, part++) {
if (part->_player)
part->fix_after_load();
}
@@ -2158,11 +2282,12 @@ void SoundEngine::fix_parts_after_load() {
/* Only call this routine from the main thread,
* since it uses getResourceAddress */
-void SoundEngine::fix_players_after_load() {
+void SoundEngine::fix_players_after_load()
+{
Player *player = _players;
int i;
- for (i=ARRAYSIZE(_players); i!=0; i--, player++) {
+ for (i = ARRAYSIZE(_players); i != 0; i--, player++) {
if (player->_active) {
player->set_tempo(player->_tempo);
_s->getResourceAddress(rtSound, player->_id);
@@ -2170,57 +2295,68 @@ void SoundEngine::fix_players_after_load() {
}
}
-void Part::set_detune(int8 detune) {
- _detune_eff = clamp((_detune=detune) + _player->_detune, -128, 127);
+void Part::set_detune(int8 detune)
+{
+ _detune_eff = clamp((_detune = detune) + _player->_detune, -128, 127);
changed(SoundDriver::pcMod);
}
-void Part::set_pitchbend(int value) {
+void Part::set_pitchbend(int value)
+{
_pitchbend = value * _pitchbend_factor >> 6;
changed(SoundDriver::pcMod);
}
-void Part::set_vol(uint8 vol) {
- _vol_eff = ((_vol=vol)+1)*_player->_vol_eff >> 7;
+void Part::set_vol(uint8 vol)
+{
+ _vol_eff = ((_vol = vol) + 1) * _player->_vol_eff >> 7;
changed(SoundDriver::pcVolume);
}
-void Part::set_pri(int8 pri) {
- _pri_eff = clamp((_pri=pri) + _player->_priority, 0, 255);
+void Part::set_pri(int8 pri)
+{
+ _pri_eff = clamp((_pri = pri) + _player->_priority, 0, 255);
}
-void Part::set_pan(int8 pan) {
- _pan_eff = clamp((_pan=pan) + _player->_pan, -64, 63);
+void Part::set_pan(int8 pan)
+{
+ _pan_eff = clamp((_pan = pan) + _player->_pan, -64, 63);
changed(SoundDriver::pcPan);
}
-void Part::set_transpose(int8 transpose) {
- _transpose_eff = transpose_clamp((_transpose=transpose) +
- _player->_transpose, -12, 12);
+void Part::set_transpose(int8 transpose)
+{
+ _transpose_eff = transpose_clamp((_transpose = transpose) +
+ _player->_transpose, -12, 12);
changed(SoundDriver::pcMod);
}
-void Part::set_pedal(bool value) {
+void Part::set_pedal(bool value)
+{
_pedal = value;
changed(SoundDriver::pcPedal);
}
-void Part::set_modwheel(uint value) {
+void Part::set_modwheel(uint value)
+{
_modwheel = value;
changed(SoundDriver::pcModwheel);
}
-void Part::set_chorus(uint chorus) {
+void Part::set_chorus(uint chorus)
+{
_chorus = chorus;
changed(SoundDriver::pcChorus);
}
-void Part::set_effect_level(uint level) {
+void Part::set_effect_level(uint level)
+{
_effect_level = level;
changed(SoundDriver::pcEffectLevel);
}
-void Part::fix_after_load() {
+void Part::fix_after_load()
+{
set_transpose(_transpose);
set_vol(_vol);
set_detune(_detune);
@@ -2228,14 +2364,16 @@ void Part::fix_after_load() {
set_pan(_pan);
}
-void Part::set_pitchbend_factor(uint8 value) {
+void Part::set_pitchbend_factor(uint8 value)
+{
if (value > 12)
return;
set_pitchbend(0);
_pitchbend_factor = value;
}
-void Part::set_onoff(bool on) {
+void Part::set_onoff(bool on)
+{
if (_on != on) {
_on = on;
if (!on)
@@ -2245,32 +2383,37 @@ void Part::set_onoff(bool on) {
}
}
-void Part::set_instrument(Instrument *data) {
+void Part::set_instrument(Instrument * data)
+{
_drv->part_set_instrument(this, data);
}
-void Part::key_on(byte note, byte velocity) {
+void Part::key_on(byte note, byte velocity)
+{
_drv->part_key_on(this, note, velocity);
}
-void Part::key_off(byte note) {
+void Part::key_off(byte note)
+{
_drv->part_key_off(this, note);
}
-void Part::init(SoundDriver *driver) {
- _drv = (SOUND_DRIVER_TYPE*)driver;
+void Part::init(SoundDriver * driver)
+{
+ _drv = (SOUND_DRIVER_TYPE *) driver;
_player = NULL;
_next = NULL;
_prev = NULL;
_mc = NULL;
}
-void Part::setup(Player *player) {
+void Part::setup(Player *player)
+{
_player = player;
-
+
/* Insert first into player's list */
_prev = NULL;
- _next = player->_parts;
+ _next = player->_parts;
if (player->_parts)
player->_parts->_prev = this;
player->_parts = this;
@@ -2297,11 +2440,12 @@ void Part::setup(Player *player) {
_mc = NULL;
}
-void Part::uninit() {
+void Part::uninit()
+{
if (!_player)
return;
off();
-
+
/* unlink */
if (_next)
_next->_prev = _prev;
@@ -2314,37 +2458,43 @@ void Part::uninit() {
_prev = NULL;
}
-void Part::off() {
+void Part::off()
+{
_drv->part_off(this);
}
-void Part::changed(byte what) {
+void Part::changed(byte what)
+{
_drv->part_changed(this, what);
}
-void Part::set_param(byte param, int value) {
- _drv->part_set_param(this,param,value);
+void Part::set_param(byte param, int value)
+{
+ _drv->part_set_param(this, param, value);
}
-void Part::update_pris() {
+void Part::update_pris()
+{
_drv->update_pris();
}
-int Part::update_actives(uint16 *active) {
+int Part::update_actives(uint16 *active)
+{
return _drv->part_update_active(this, active);
}
-void Part::set_program(byte program) {
- if (_program!=program || _bank!=0) {
+void Part::set_program(byte program)
+{
+ if (_program != program || _bank != 0) {
_program = program;
_bank = 0;
changed(SoundDriver::pcProgram);
}
}
-void Part::set_instrument(uint b) {
- _bank = (byte)(b>>8);
+void Part::set_instrument(uint b)
+{
+ _bank = (byte)(b >> 8);
_program = (byte)b;
changed(SoundDriver::pcProgram);
}
-
diff --git a/string.cpp b/string.cpp
index b51e209388..7c63fec2ed 100644
--- a/string.cpp
+++ b/string.cpp
@@ -23,57 +23,59 @@
#include "stdafx.h"
#include "scumm.h"
-int CharsetRenderer::getStringWidth(int arg, byte *text, int pos) {
+int CharsetRenderer::getStringWidth(int arg, byte *text, int pos)
+{
byte *ptr;
- int width,offs,w;
+ int width, offs, w;
byte chr;
width = 1;
ptr = _vm->getResourceAddress(rtCharset, _curId) + 29;
- if(_vm->_features & GF_SMALL_HEADER)
- ptr-=12;
+ if (_vm->_features & GF_SMALL_HEADER)
+ ptr -= 12;
while ((chr = text[pos++]) != 0) {
- if (chr==0xD)
+ if (chr == 0xD)
break;
- if (chr=='@')
+ if (chr == '@')
continue;
- if (chr==254) chr=255;
- if (chr==255) {
- chr=text[pos++];
- if (chr==3)
+ if (chr == 254)
+ chr = 255;
+ if (chr == 255) {
+ chr = text[pos++];
+ if (chr == 3)
break;
- if (chr==8) {
- if (arg==1)
+ if (chr == 8) {
+ if (arg == 1)
break;
- while (text[pos]==' ')
+ while (text[pos] == ' ')
text[pos++] = '@';
continue;
}
- if (chr==10 || chr==21 || chr==12 || chr==13) {
+ if (chr == 10 || chr == 21 || chr == 12 || chr == 13) {
pos += 2;
continue;
}
- if (chr==9 || chr==1 || chr==2)
+ if (chr == 9 || chr == 1 || chr == 2)
break;
- if (chr==14) {
- int set = text[pos] | (text[pos+1]<<8);
- pos+=2;
+ if (chr == 14) {
+ int set = text[pos] | (text[pos + 1] << 8);
+ pos += 2;
ptr = _vm->getResourceAddress(rtCharset, set) + 29;
- if(_vm->_features & GF_SMALL_HEADER)
- ptr-=12;
+ if (_vm->_features & GF_SMALL_HEADER)
+ ptr -= 12;
continue;
}
}
- if(_vm->_features & GF_OLD256) {
+ if (_vm->_features & GF_OLD256) {
width += 8;
} else {
- offs = READ_LE_UINT32(ptr + chr*4 + 4);
+ offs = READ_LE_UINT32(ptr + chr * 4 + 4);
if (offs) {
- if (ptr[offs+2]>=0x80) {
- w = ptr[offs+2] - 0x100;
+ if (ptr[offs + 2] >= 0x80) {
+ w = ptr[offs + 2] - 0x100;
} else {
- w = ptr[offs+2];
+ w = ptr[offs + 2];
}
width += ptr[offs] + w;
}
@@ -82,71 +84,73 @@ int CharsetRenderer::getStringWidth(int arg, byte *text, int pos) {
return width;
}
-void CharsetRenderer::addLinebreaks(int a, byte *str, int pos, int maxwidth) {
+void CharsetRenderer::addLinebreaks(int a, byte *str, int pos, int maxwidth)
+{
int lastspace = -1;
int curw = 1;
- int offs,w;
+ int offs, w;
byte *ptr;
byte chr;
ptr = _vm->getResourceAddress(rtCharset, _curId) + 29;
- if(_vm->_features & GF_SMALL_HEADER)
- ptr-=12;
+ if (_vm->_features & GF_SMALL_HEADER)
+ ptr -= 12;
- while ( (chr=str[pos++]) != 0) {
- if (chr=='@')
+ while ((chr = str[pos++]) != 0) {
+ if (chr == '@')
continue;
- if (chr==254) chr=255;
- if (chr==255) {
+ if (chr == 254)
+ chr = 255;
+ if (chr == 255) {
chr = str[pos++];
- if (chr==3)
+ if (chr == 3)
break;
- if (chr==8) {
- if (a==1) {
+ if (chr == 8) {
+ if (a == 1) {
curw = 1;
} else {
- while (str[pos]==' ')
+ while (str[pos] == ' ')
str[pos++] = '@';
}
continue;
}
- if (chr==10 || chr==21 || chr==12 || chr==13) {
+ if (chr == 10 || chr == 21 || chr == 12 || chr == 13) {
pos += 2;
continue;
}
- if (chr==1) {
+ if (chr == 1) {
curw = 1;
continue;
}
- if (chr==2)
+ if (chr == 2)
break;
- if (chr==14) {
- int set = str[pos] | (str[pos+1]<<8);
- pos+=2;
+ if (chr == 14) {
+ int set = str[pos] | (str[pos + 1] << 8);
+ pos += 2;
ptr = _vm->getResourceAddress(rtCharset, set) + 29;
- if(_vm->_features & GF_SMALL_HEADER)
- ptr-=12;
+ if (_vm->_features & GF_SMALL_HEADER)
+ ptr -= 12;
continue;
}
}
- if (chr==' ')
+ if (chr == ' ')
lastspace = pos - 1;
- if(_vm->_features & GF_OLD256) {
+ if (_vm->_features & GF_OLD256) {
curw += getSpacing(chr);
} else {
- offs = READ_LE_UINT32(ptr + chr*4 + 4);
+ offs = READ_LE_UINT32(ptr + chr * 4 + 4);
if (offs) {
- if (ptr[offs+2]>=0x80) {
- w = ptr[offs+2] - 0x100;
+ if (ptr[offs + 2] >= 0x80) {
+ w = ptr[offs + 2] - 0x100;
} else {
- w = ptr[offs+2];
+ w = ptr[offs + 2];
}
curw += w + ptr[offs];
}
}
- if (lastspace==-1)
- continue;
+ if (lastspace == -1)
+ continue;
if (curw > maxwidth) {
str[lastspace] = 0xD;
curw = 1;
@@ -156,30 +160,33 @@ void CharsetRenderer::addLinebreaks(int a, byte *str, int pos, int maxwidth) {
}
}
-void Scumm::unkMessage1() {
+void Scumm::unkMessage1()
+{
byte buffer[100];
_msgPtrToAdd = buffer;
_messagePtr = addMessageToStack(_messagePtr);
- if (buffer[0] == 0xFF && buffer[1]==10) {
- uint32 a,b;
+ if (buffer[0] == 0xFF && buffer[1] == 10) {
+ uint32 a, b;
- a = buffer[2] | (buffer[3]<<8) | (buffer[6]<<16) | (buffer[7]<<24);
- b = buffer[10] | (buffer[11]<<8) | (buffer[14]<<16) | (buffer[15]<<24);
-// if (_saveSound != 1)
- talkSound(a,b,1);
+ a = buffer[2] | (buffer[3] << 8) | (buffer[6] << 16) | (buffer[7] << 24);
+ b =
+ buffer[10] | (buffer[11] << 8) | (buffer[14] << 16) | (buffer[15] <<
+ 24);
+// if (_saveSound != 1)
+ talkSound(a, b, 1);
}
-
-// warning("unkMessage1(\"%s\")", buffer);
+// warning("unkMessage1(\"%s\")", buffer);
}
-void Scumm::unkMessage2() {
+void Scumm::unkMessage2()
+{
byte buf[100], *tmp;
_msgPtrToAdd = buf;
tmp = _messagePtr = addMessageToStack(_messagePtr);
- if (string[3].color==0)
+ if (string[3].color == 0)
string[3].color = 4;
warning("unkMessage2(\"%s\")", buf);
@@ -187,16 +194,17 @@ void Scumm::unkMessage2() {
}
-void Scumm::CHARSET_1() {
+void Scumm::CHARSET_1()
+{
int s, i, t, c;
int frme;
Actor *a;
- byte *buffer;
+ byte *buffer;
- if(!(_features & GF_AFTER_V7)) {
- if (!_haveMsg || (camera._dest.x>>3) != (camera._cur.x>>3) ||
- camera._cur.x != camera._last.x
- ) return;
+ if (!(_features & GF_AFTER_V7)) {
+ if (!_haveMsg || (camera._dest.x >> 3) != (camera._cur.x >> 3) ||
+ camera._cur.x != camera._last.x)
+ return;
} else {
if (!_haveMsg)
return;
@@ -206,13 +214,14 @@ void Scumm::CHARSET_1() {
if (_vars[VAR_TALK_ACTOR] != 0xFF)
a = derefActorSafe(_vars[VAR_TALK_ACTOR], "CHARSET_1");
- if (a && string[0].overhead!=0) {
+ if (a && string[0].overhead != 0) {
if (!(_features & GF_AFTER_V6)) {
string[0].xpos = a->x - camera._cur.x + 160;
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;
+ string[0].ypos =
+ ((_vars[VAR_V5_TALK_STRING_Y] - s) >> 1) + s - a->elevation + a->y;
} else {
string[0].ypos = _vars[VAR_V5_TALK_STRING_Y];
}
@@ -225,12 +234,12 @@ void Scumm::CHARSET_1() {
string[0].xpos = 240;
} else {
s = a->scaley * a->new_1 / 0xFF;
- string[0].ypos = ((a->new_1 - s)>>1) + s - a->elevation + a->y;
- if (string[0].ypos<1)
+ string[0].ypos = ((a->new_1 - s) >> 1) + s - a->elevation + a->y;
+ if (string[0].ypos < 1)
string[0].ypos = 1;
-
+
s = a->scalex * a->new_2 / 0xFF;
- string[0].xpos = ((a->new_2 - s)>>1) + s + a->x - camera._cur.x + 160;
+ string[0].xpos = ((a->new_2 - s) >> 1) + s + a->x - camera._cur.x + 160;
if (string[0].xpos < 80)
string[0].xpos = 80;
if (string[0].xpos > 240)
@@ -250,14 +259,14 @@ void Scumm::CHARSET_1() {
charset._right = string[0].right;
charset._color = _charsetColor;
_bkColor = 0;
-
- if(!(_features & GF_OLD256)) // FIXME
- for (i=0; i<4; i++)
- if(_features & GF_SMALL_HEADER)
- charset._colorMap[i] = _charsetData[charset._curId][i-12];
- else
- charset._colorMap[i] = _charsetData[charset._curId][i];
-
+
+ if (!(_features & GF_OLD256)) // FIXME
+ for (i = 0; i < 4; i++)
+ if (_features & GF_SMALL_HEADER)
+ charset._colorMap[i] = _charsetData[charset._curId][i - 12];
+ else
+ charset._colorMap[i] = _charsetData[charset._curId][i];
+
if (_keepText) {
charset._strLeft = gdi._mask_left;
charset._strRight = gdi._mask_right;
@@ -267,9 +276,9 @@ void Scumm::CHARSET_1() {
if (!_haveMsg || _talkDelay)
return;
-
- if (_haveMsg!=0xFF) {
- if (_sfxMode==0)
+
+ if (_haveMsg != 0xFF) {
+ if (_sfxMode == 0)
stopTalk();
return;
}
@@ -282,19 +291,19 @@ void Scumm::CHARSET_1() {
_talkDelay = _defaultTalkDelay;
if (!_keepText) {
- if(_features & GF_OLD256) {
+ if (_features & GF_OLD256) {
gdi._mask_left = string[0].xpos;
gdi._mask_top = string[0].ypos;
- gdi._mask_bottom = string[0].ypos+8;
+ gdi._mask_bottom = string[0].ypos + 8;
gdi._mask_right = 320;
- if(string[0].ypos <= 16) // If we are cleaning the text line, clean 2 lines.
+ if (string[0].ypos <= 16) // If we are cleaning the text line, clean 2 lines.
gdi._mask_bottom = 16;
}
restoreCharsetBg();
charset._xpos2 = string[0].xpos;
charset._ypos2 = string[0].ypos;
}
-
+
t = charset._right - string[0].xpos - 1;
if (charset._center) {
if (t > charset._xpos2)
@@ -302,13 +311,13 @@ void Scumm::CHARSET_1() {
t <<= 1;
}
- buffer = charset._buffer + charset._bufPos;
- charset.addLinebreaks(0, buffer,0, t);
+ buffer = charset._buffer + charset._bufPos;
+ charset.addLinebreaks(0, buffer, 0, t);
_lastXstart = virtscr[0].xstart;
if (charset._center) {
- charset._xpos2 -= charset.getStringWidth(0, buffer,0) >> 1;
- if (charset._xpos2<0)
+ charset._xpos2 -= charset.getStringWidth(0, buffer, 0) >> 1;
+ if (charset._xpos2 < 0)
charset._xpos2 = 0;
}
@@ -316,47 +325,47 @@ void Scumm::CHARSET_1() {
do {
c = *buffer++;
- if (c==0) {
+ if (c == 0) {
_haveMsg = 1;
_keepText = false;
break;
}
if (c == 13) {
-newLine:;
- if(_features & GF_OLD256)
- {
+ newLine:;
+ if (_features & GF_OLD256) {
charset._ypos2 = 8;
charset._xpos2 = 0;
continue;
} else {
charset._xpos2 = string[0].xpos;
if (charset._center) {
- charset._xpos2 -= charset.getStringWidth(0, buffer, 0)>>1;
+ charset._xpos2 -= charset.getStringWidth(0, buffer, 0) >> 1;
}
- if(_features & GF_SMALL_HEADER)
- charset._ypos2 += getResourceAddress(rtCharset,charset._curId)[18];
+ if (_features & GF_SMALL_HEADER)
+ charset._ypos2 += getResourceAddress(rtCharset, charset._curId)[18];
else
- charset._ypos2 += getResourceAddress(rtCharset,charset._curId)[30];
+ charset._ypos2 += getResourceAddress(rtCharset, charset._curId)[30];
charset._disableOffsX = 1;
continue;
}
}
- if (c==0xFE) c=0xFF;
+ if (c == 0xFE)
+ c = 0xFF;
- if (c!=0xFF) {
+ if (c != 0xFF) {
charset._left = charset._xpos2;
charset._top = charset._ypos2;
- if (_features & GF_OLD256)
+ if (_features & GF_OLD256)
charset.printCharOld(c);
- else if (!(_features&GF_AFTER_V6)) {
+ else if (!(_features & GF_AFTER_V6)) {
// if (!_vars[VAR_V5_CHARFLAG]) { /* FIXME */
- if (!(a && _noSubtitles))
+ if (!(a && _noSubtitles))
charset.printChar(c);
// }
} else {
if (!(a && _noSubtitles))
- charset.printChar(c);
+ charset.printChar(c);
}
charset._xpos2 = charset._left;
@@ -367,48 +376,52 @@ newLine:;
}
c = *buffer++;
- if (c==3) {
+ if (c == 3) {
_haveMsg = 0xFF;
_keepText = false;
break;
- } else if (c==1) {
+ } else if (c == 1) {
goto newLine;
- } else if (c==2) {
+ } else if (c == 2) {
_haveMsg = 0;
_keepText = true;
break;
- } else if (c==9) {
+ } else if (c == 9) {
frme = *buffer++;
- frme |= *buffer++<<8;
+ frme |= *buffer++ << 8;
if (a)
startAnimActor(a, frme);
- } else if (c==10) {
- uint32 a,b;
-
- a = buffer[0] | (buffer[1]<<8) | (buffer[4]<<16) | (buffer[5]<<24);
- b = buffer[8] | (buffer[9]<<8) | (buffer[12]<<16) | (buffer[13]<<24);
- talkSound(a,b,2);
+ } else if (c == 10) {
+ uint32 a, b;
+
+ a =
+ buffer[0] | (buffer[1] << 8) | (buffer[4] << 16) | (buffer[5] << 24);
+ b =
+ buffer[8] | (buffer[9] << 8) | (buffer[12] << 16) | (buffer[13] <<
+ 24);
+ talkSound(a, b, 2);
buffer += 14;
- } else if (c==14) {
- int oldy = getResourceAddress(rtCharset,charset._curId)[30];
+ } else if (c == 14) {
+ int oldy = getResourceAddress(rtCharset, charset._curId)[30];
charset._curId = *buffer++;
buffer += 2;
- for (i=0; i<4; i++)
- if(_features & GF_SMALL_HEADER)
- charset._colorMap[i] = _charsetData[charset._curId][i-12];
- else
- charset._colorMap[i] = _charsetData[charset._curId][i];
- charset._ypos2 -= getResourceAddress(rtCharset,charset._curId)[30] - oldy;
- } else if (c==12) {
+ for (i = 0; i < 4; i++)
+ if (_features & GF_SMALL_HEADER)
+ charset._colorMap[i] = _charsetData[charset._curId][i - 12];
+ else
+ charset._colorMap[i] = _charsetData[charset._curId][i];
+ charset._ypos2 -=
+ getResourceAddress(rtCharset, charset._curId)[30] - oldy;
+ } else if (c == 12) {
int color;
color = *buffer++;
- color |= *buffer++<<8;
- if (color==0xFF)
+ color |= *buffer++ << 8;
+ if (color == 0xFF)
charset._color = _charsetColor;
else
charset._color = color;
- } else if (c==13) {
+ } else if (c == 13) {
buffer += 2;
} else {
warning("CHARSET_1: invalid code %d", c);
@@ -423,13 +436,14 @@ newLine:;
gdi._mask_bottom = charset._strBottom;
}
-void Scumm::drawString(int a) {
+void Scumm::drawString(int a)
+{
byte buf[256];
- byte *charsetptr,*space;
+ byte *charsetptr, *space;
int i;
- byte byte1=0, chr;
+ byte byte1 = 0, chr;
uint color;
-
+
_msgPtrToAdd = buf;
_messagePtr = addMessageToStack(_messagePtr);
@@ -443,18 +457,18 @@ void Scumm::drawString(int a) {
charset._unk12 = 1;
charset._disableOffsX = 1;
- if(!(_features & GF_OLD256)) {
+ if (!(_features & GF_OLD256)) {
charsetptr = getResourceAddress(rtCharset, charset._curId);
assert(charsetptr);
charsetptr += 29;
- if(_features & GF_SMALL_HEADER)
- charsetptr-=12;
+ if (_features & GF_SMALL_HEADER)
+ charsetptr -= 12;
- for(i=0; i<4; i++)
- if(_features & GF_SMALL_HEADER)
- charset._colorMap[i] = _charsetData[charset._curId][i-12];
- else
- charset._colorMap[i] = _charsetData[charset._curId][i];
+ for (i = 0; i < 4; i++)
+ if (_features & GF_SMALL_HEADER)
+ charset._colorMap[i] = _charsetData[charset._curId][i - 12];
+ else
+ charset._colorMap[i] = _charsetData[charset._curId][i];
byte1 = charsetptr[1];
}
@@ -463,15 +477,17 @@ void Scumm::drawString(int a) {
/* trim from the right */
space = NULL;
- while (*_msgPtrToAdd){
- if (*_msgPtrToAdd==' ') {
- if (!space) space = _msgPtrToAdd;
+ while (*_msgPtrToAdd) {
+ if (*_msgPtrToAdd == ' ') {
+ if (!space)
+ space = _msgPtrToAdd;
} else {
space = NULL;
}
_msgPtrToAdd++;
}
- if(space) *space='\0';
+ if (space)
+ *space = '\0';
if (charset._center) {
charset._left -= charset.getStringWidth(a, buf, 0) >> 1;
}
@@ -483,16 +499,20 @@ void Scumm::drawString(int a) {
buf[1] = 0;
}
- for (i=0; (chr=buf[i++]) != 0; ) {
- if (chr==254) chr=255;
- if (chr==255) {
+ for (i = 0; (chr = buf[i++]) != 0;) {
+ if (chr == 254)
+ chr = 255;
+ if (chr == 255) {
chr = buf[i++];
- switch(chr) {
+ switch (chr) {
case 9:
- case 10: case 13: case 14:
+ case 10:
+ case 13:
+ case 14:
i += 2;
break;
- case 1: case 8:
+ case 1:
+ case 8:
if (charset._center) {
charset._left = charset._left2 - charset.getStringWidth(a, buf, i);
} else {
@@ -501,16 +521,16 @@ void Scumm::drawString(int a) {
charset._top += byte1;
break;
case 12:
- color = buf[i] + (buf[i+1]<<8);
- i+=2;
- if (color==0xFF)
+ 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 && (_features&GF_AFTER_V6))
+ if (a == 1 && (_features & GF_AFTER_V6))
charset._blitAlso = true;
if (_features & GF_OLD256)
charset.printCharOld(chr);
@@ -521,73 +541,77 @@ void Scumm::drawString(int a) {
}
charset._ignoreCharsetMask = 0;
-
- if (a==0) {
+
+ if (a == 0) {
charset._xpos2 = charset._left;
charset._ypos2 = charset._top;
}
}
-byte *Scumm::addMessageToStack(byte *msg) {
+byte *Scumm::addMessageToStack(byte *msg)
+{
int num, numorg;
byte *ptr, chr;
numorg = num = _numInMsgStack;
ptr = getResourceAddress(rtTemp, 6);
- if (ptr==NULL)
+ if (ptr == NULL)
error("Message stack not allocated");
- if (msg==NULL)
- error("Bad message in addMessageToStack");
+ if (msg == NULL)
+ error("Bad message in addMessageToStack");
- while ( (chr=*msg++) != 0) {
+ while ((chr = *msg++) != 0) {
if (num > 500)
error("Message stack overflow");
ptr[num++] = chr;
-
- if (chr==255) {
+
+ if (chr == 255) {
ptr[num++] = chr = *msg++;
- if (chr!=1 && chr!=2 && chr!=3 && chr!=8) {
+ if (chr != 1 && chr != 2 && chr != 3 && chr != 8) {
ptr[num++] = chr = *msg++;
ptr[num++] = chr = *msg++;
}
}
}
ptr[num++] = 0;
-
+
_numInMsgStack = num;
num = numorg;
while (1) {
ptr = getResourceAddress(rtTemp, 6);
chr = ptr[num++];
- if (chr == 0)
+ if (chr == 0)
break;
if (chr == 0xFF) {
chr = ptr[num++];
- switch(chr) {
+ switch (chr) {
case 4:
unkAddMsgToStack2(READ_LE_UINT16(ptr + num));
- num+=2;
+ num += 2;
break;
case 5:
unkAddMsgToStack3(READ_LE_UINT16(ptr + num));
- num+=2;
+ num += 2;
break;
case 6:
unkAddMsgToStack4(READ_LE_UINT16(ptr + num));
- num+=2;
+ num += 2;
break;
case 7:
unkAddMsgToStack5(READ_LE_UINT16(ptr + num));
- num+=2;
+ num += 2;
break;
- case 9:
+ case 9:
//#if defined(DOTT)
- case 10: case 12: case 13: case 14:
+ case 10:
+ case 12:
+ case 13:
+ case 14:
//#endif
*_msgPtrToAdd++ = 0xFF;
*_msgPtrToAdd++ = chr;
@@ -599,21 +623,22 @@ byte *Scumm::addMessageToStack(byte *msg) {
*_msgPtrToAdd++ = chr;
}
} else {
- if (chr!='@') {
+ if (chr != '@') {
*_msgPtrToAdd++ = chr;
}
}
}
*_msgPtrToAdd = 0;
_numInMsgStack = numorg;
-
+
return msg;
}
-void Scumm::unkAddMsgToStack2(int var) {
- int num,max;
+void Scumm::unkAddMsgToStack2(int var)
+{
+ int num, max;
byte flag;
-
+
num = readVar(var);
if (num < 0) {
*_msgPtrToAdd++ = '-';
@@ -623,49 +648,53 @@ void Scumm::unkAddMsgToStack2(int var) {
flag = 0;
max = 10000;
do {
- if (num>=max || flag) {
- *_msgPtrToAdd++ = num/max + '0';
- num -= (num/max)*max;
- flag=1;
+ if (num >= max || flag) {
+ *_msgPtrToAdd++ = num / max + '0';
+ num -= (num / max) * max;
+ flag = 1;
}
- max/=10;
- if (max==1) flag=1;
+ max /= 10;
+ if (max == 1)
+ flag = 1;
} while (max);
}
-void Scumm::unkAddMsgToStack3(int var) {
- int num,i;
-
+void Scumm::unkAddMsgToStack3(int var)
+{
+ int num, i;
+
num = readVar(var);
if (num) {
- for (i=1; i<_maxVerbs; i++) {
- if (num==_verbs[i].verbid && !_verbs[i].type && !_verbs[i].saveid) {
+ for (i = 1; i < _maxVerbs; i++) {
+ if (num == _verbs[i].verbid && !_verbs[i].type && !_verbs[i].saveid) {
addMessageToStack(getResourceAddress(rtVerb, i));
break;
}
}
} else {
- addMessageToStack((byte*)"");
+ addMessageToStack((byte *)"");
}
}
-void Scumm::unkAddMsgToStack4(int var) {
+void Scumm::unkAddMsgToStack4(int var)
+{
int num;
num = readVar(var);
if (num) {
- addMessageToStack(getObjOrActorName(num));
+ addMessageToStack(getObjOrActorName(num));
} else {
- addMessageToStack((byte*)"");
+ addMessageToStack((byte *)"");
}
}
-void Scumm::unkAddMsgToStack5(int var) {
+void Scumm::unkAddMsgToStack5(int var)
+{
byte *ptr;
- if (_features&GF_AFTER_V6)
+ if (_features & GF_AFTER_V6)
var = readVar(var);
-
+
if (var) {
ptr = getStringAddress(var);
if (ptr) {
@@ -673,43 +702,45 @@ void Scumm::unkAddMsgToStack5(int var) {
return;
}
}
- addMessageToStack((byte*)"");
+ addMessageToStack((byte *)"");
}
-void Scumm::initCharset(int charsetno) {
+void Scumm::initCharset(int charsetno)
+{
int i;
if (_features & GF_OLD256)
- charsetno = !charsetno;
+ charsetno = !charsetno;
- if (_features & GF_SMALL_HEADER)
- loadCharset(charsetno);
- else
- if (!getResourceAddress(rtCharset, charsetno))
- loadCharset(charsetno);
+ if (_features & GF_SMALL_HEADER)
+ loadCharset(charsetno);
+ else if (!getResourceAddress(rtCharset, charsetno))
+ loadCharset(charsetno);
string[0].t_charset = charsetno;
string[1].t_charset = charsetno;
- for (i=0; i<0x10; i++)
- if(_features & GF_SMALL_HEADER)
- charset._colorMap[i] = _charsetData[charset._curId][i-12];
- else
- charset._colorMap[i] = _charsetData[charset._curId][i];
+ for (i = 0; i < 0x10; i++)
+ if (_features & GF_SMALL_HEADER)
+ charset._colorMap[i] = _charsetData[charset._curId][i - 12];
+ else
+ charset._colorMap[i] = _charsetData[charset._curId][i];
}
-void CharsetRenderer::printCharOld(int chr) { // Loom3 / Zak256
+void CharsetRenderer::printCharOld(int chr)
+{ // Loom3 / Zak256
VirtScreen *vs;
byte *char_ptr, *dest_ptr;
- unsigned int buffer=0, mask=0, x = 0, y = 0;
+ unsigned int buffer = 0, mask = 0, x = 0, y = 0;
unsigned char color;
- _vm->checkRange(_vm->_maxCharsets-1, 0, _curId, "Printing with bad charset %d");
-
- if ((vs=_vm->findVirtScreen(_top)) == NULL)
+ _vm->checkRange(_vm->_maxCharsets - 1, 0, _curId,
+ "Printing with bad charset %d");
+
+ if ((vs = _vm->findVirtScreen(_top)) == NULL)
return;
- if (chr=='@')
+ if (chr == '@')
return;
if (_unk12) {
@@ -719,22 +750,26 @@ void CharsetRenderer::printCharOld(int chr) { // Loom3 / Zak256
_strBottom = _top;
_unk12 = 0;
}
- char_ptr = _vm->getResourceAddress(rtCharset, _curId) + 224 + (chr + 1)*8;
+ char_ptr = _vm->getResourceAddress(rtCharset, _curId) + 224 + (chr + 1) * 8;
dest_ptr = vs->screenPtr + vs->xstart + (_top - vs->topline) * 320 + _left;
- _vm->updateDirtyRect(vs->number, _left, _left + 8, _top - vs->topline, _top - vs->topline + 8, 0);
-
- for(y=0;y<8;y++) {
- for(x=0;x<8;x++) {
- if ((mask >>= 1) == 0) {buffer = *char_ptr++; mask = 0x80;}
+ _vm->updateDirtyRect(vs->number, _left, _left + 8, _top - vs->topline,
+ _top - vs->topline + 8, 0);
+
+ for (y = 0; y < 8; y++) {
+ for (x = 0; x < 8; x++) {
+ if ((mask >>= 1) == 0) {
+ buffer = *char_ptr++;
+ mask = 0x80;
+ }
color = ((buffer & mask) != 0);
if (color)
- *(dest_ptr + y*320 + x) = _color;
+ *(dest_ptr + y * 320 + x) = _color;
}
}
- _left+= getSpacing(chr);
+ _left += getSpacing(chr);
- if (_left > _strRight)
+ if (_left > _strRight)
_strRight = _left;
if (_top + 8 > _strBottom)
@@ -743,27 +778,29 @@ void CharsetRenderer::printCharOld(int chr) { // Loom3 / Zak256
}
-void CharsetRenderer::printChar(int chr) {
- int d,right;
+void CharsetRenderer::printChar(int chr)
+{
+ int d, right;
VirtScreen *vs;
-
- _vm->checkRange(_vm->_maxCharsets-1, 1, _curId, "Printing with bad charset %d");
- if ((vs=_vm->findVirtScreen(_top)) == NULL)
+
+ _vm->checkRange(_vm->_maxCharsets - 1, 1, _curId,
+ "Printing with bad charset %d");
+ if ((vs = _vm->findVirtScreen(_top)) == NULL)
return;
- if (chr=='@')
+ if (chr == '@')
return;
_ptr = _vm->getResourceAddress(rtCharset, _curId) + 29;
if (_vm->_features & GF_SMALL_HEADER)
- _ptr -=12;
-
+ _ptr -= 12;
+
_bpp = _unk2 = *_ptr;
_invNumBits = 8 - _bpp;
_bitMask = 0xFF << _invNumBits;
_colorMap[1] = _color;
- _charOffs = READ_LE_UINT32(_ptr + chr*4 + 4);
+ _charOffs = READ_LE_UINT32(_ptr + chr * 4 + 4);
if (!_charOffs)
return;
@@ -785,13 +822,13 @@ void CharsetRenderer::printChar(int chr) {
_offsX = 0;
} else {
d = _charPtr[2];
- if (d>=0x80)
+ if (d >= 0x80)
d -= 0x100;
_offsX = d;
}
d = _charPtr[3];
- if(d>=0x80)
+ if (d >= 0x80)
d -= 0x100;
_offsY = d;
@@ -800,7 +837,7 @@ void CharsetRenderer::printChar(int chr) {
right = _left + _width;
- if (right>_right+1 || _left < 0) {
+ if (right > _right + 1 || _left < 0) {
_left = right;
_top -= _offsY;
return;
@@ -823,23 +860,24 @@ void CharsetRenderer::printChar(int chr) {
_strTop = _top;
_drawTop = _top - vs->topline;
- if (_drawTop<0) _drawTop = 0;
+ if (_drawTop < 0)
+ _drawTop = 0;
_bottom = _drawTop + _height + _offsY;
_vm->updateDirtyRect(vs->number, _left, right, _drawTop, _bottom, 0);
#if defined(OLD)
- if (vs->number==0)
+ if (vs->number == 0)
_hasMask = true;
#else
- if (vs->number!=0)
+ if (vs->number != 0)
_blitAlso = false;
- if (vs->number==0 && _blitAlso==0)
+ if (vs->number == 0 && _blitAlso == 0)
_hasMask = true;
#endif
- _dest_ptr = _backbuff_ptr = vs->screenPtr
+ _dest_ptr = _backbuff_ptr = vs->screenPtr
+ vs->xstart + _drawTop * 320 + _left;
#if !defined(OLD)
@@ -847,15 +885,14 @@ void CharsetRenderer::printChar(int chr) {
#else
if (1) {
#endif
- _dest_ptr = _bgbak_ptr = _vm->getResourceAddress(rtBuffer, vs->number+5)
+ _dest_ptr = _bgbak_ptr = _vm->getResourceAddress(rtBuffer, vs->number + 5)
+ vs->xstart + _drawTop * 320 + _left;
}
_mask_ptr = _vm->getResourceAddress(rtBuffer, 9)
- + _drawTop * 40 + _left/8
- + _vm->_screenStartStrip;
+ + _drawTop * 40 + _left / 8 + _vm->_screenStartStrip;
- _revBitMask = revBitMask[_left&7];
+ _revBitMask = revBitMask[_left & 7];
_virtScreenHeight = vs->height;
_charPtr += 4;
@@ -868,7 +905,7 @@ void CharsetRenderer::printChar(int chr) {
#endif
_left += _width;
- if (_left > _strRight)
+ if (_left > _strRight)
_strRight = _left;
if (_top + _height > _strBottom)
@@ -877,15 +914,16 @@ void CharsetRenderer::printChar(int chr) {
_top -= _offsY;
}
-void CharsetRenderer::drawBits() {
+void CharsetRenderer::drawBits()
+{
bool usemask;
- byte *dst, *mask,maskmask;
- int y,x;
+ byte *dst, *mask, maskmask;
+ int y, x;
int maskpos;
int color;
- byte numbits,bits;
+ byte numbits, bits;
- usemask = (_vm->_curVirtScreen->number==0 && _ignoreCharsetMask==0);
+ usemask = (_vm->_curVirtScreen->number == 0 && _ignoreCharsetMask == 0);
bits = *_charPtr++;
numbits = 8;
@@ -894,12 +932,12 @@ void CharsetRenderer::drawBits() {
mask = _mask_ptr;
y = 0;
- for(y=0; y<_height && y+_drawTop < _virtScreenHeight;) {
+ for (y = 0; y < _height && y + _drawTop < _virtScreenHeight;) {
maskmask = _revBitMask;
maskpos = 0;
- for (x=0; x<_width; x++) {
- color = (bits&_bitMask)>>_invNumBits;
+ for (x = 0; x < _width; x++) {
+ color = (bits & _bitMask) >> _invNumBits;
if (color) {
if (usemask) {
mask[maskpos] |= maskmask;
@@ -908,11 +946,11 @@ void CharsetRenderer::drawBits() {
}
dst++;
bits <<= _bpp;
- if ((numbits -= _bpp)==0) {
+ if ((numbits -= _bpp) == 0) {
bits = *_charPtr++;
numbits = 8;
}
- if ((maskmask>>=1)==0) {
+ if ((maskmask >>= 1) == 0) {
maskmask = 0x80;
maskpos++;
}
@@ -923,38 +961,38 @@ void CharsetRenderer::drawBits() {
}
}
-int CharsetRenderer::getSpacing(char chr) {
+int CharsetRenderer::getSpacing(char chr)
+{
int space;
- if (_curId == 1) { // do spacing for variable width old-style font
- switch(chr) {
- case '.':
- space=1;
- break;
- case 'i':
- case '\'':
- case 'I':
- case '!':
- space=2;
- break;
- case 'l':
- space=3;
- break;
- case ' ':
- space=4;
- break;
- case 'W':
- case 'w':
- case 'N':
- case 'M':
- case 'm':
- space=8;
- break;
- default:
- space=6;
+ if (_curId == 1) { // do spacing for variable width old-style font
+ switch (chr) {
+ case '.':
+ space = 1;
+ break;
+ case 'i':
+ case '\'':
+ case 'I':
+ case '!':
+ space = 2;
+ break;
+ case 'l':
+ space = 3;
+ break;
+ case ' ':
+ space = 4;
+ break;
+ case 'W':
+ case 'w':
+ case 'N':
+ case 'M':
+ case 'm':
+ space = 8;
+ break;
+ default:
+ space = 6;
}
- }
- else
- space=7;
+ } else
+ space = 7;
return space;
}
diff --git a/sys.cpp b/sys.cpp
index c7f6dbe2d1..56c1516ad8 100644
--- a/sys.cpp
+++ b/sys.cpp
@@ -23,47 +23,55 @@
#include "stdafx.h"
#include "scumm.h"
-void *Scumm::fileOpen(const char *filename, int mode) {
+void *Scumm::fileOpen(const char *filename, int mode)
+{
_fileMode = mode;
- _whereInResToRead = 0;
+ _whereInResToRead = 0;
clearFileReadFailed(_fileHandle);
- if (mode==1)
+ if (mode == 1)
return fopen(filename, "rb");
-
- if (mode==2) {
+
+ if (mode == 2) {
error("fileOpen: write not supported");
}
-
+
return NULL;
}
-void Scumm::fileClose(void *file) {
- if (_fileMode==1 || _fileMode==2)
- fclose((FILE*)file);
+void Scumm::fileClose(void *file)
+{
+ if (_fileMode == 1 || _fileMode == 2)
+ fclose((FILE *) file);
}
-bool Scumm::fileReadFailed(void *file) {
+bool Scumm::fileReadFailed(void *file)
+{
return _fileReadFailed != 0;
}
-void Scumm::clearFileReadFailed(void *file) {
+void Scumm::clearFileReadFailed(void *file)
+{
_fileReadFailed = false;
}
-bool Scumm::fileEof(void *file) {
- return feof((FILE*)file) != 0;
+bool Scumm::fileEof(void *file)
+{
+ return feof((FILE *) file) != 0;
}
-uint32 Scumm::filePos(void *handle) {
- return ftell((FILE*)handle);
+uint32 Scumm::filePos(void *handle)
+{
+ return ftell((FILE *) handle);
}
-void Scumm::fileSeek(void *file, long offs, int whence) {
- switch(_fileMode) {
- case 1: case 2:
- if (fseek((FILE*)file, offs, whence)!=0)
- clearerr((FILE*)file);
+void Scumm::fileSeek(void *file, long offs, int whence)
+{
+ switch (_fileMode) {
+ case 1:
+ case 2:
+ if (fseek((FILE *) file, offs, whence) != 0)
+ clearerr((FILE *) file);
return;
case 3:
_whereInResToRead = offs;
@@ -71,27 +79,28 @@ void Scumm::fileSeek(void *file, long offs, int whence) {
}
}
-void Scumm::fileRead(void *file, void *ptr, uint32 size) {
- byte *ptr2 = (byte*)ptr, *src;
+void Scumm::fileRead(void *file, void *ptr, uint32 size)
+{
+ byte *ptr2 = (byte *)ptr, *src;
- switch(_fileMode) {
+ switch (_fileMode) {
case 1:
- if (size==0)
+ if (size == 0)
return;
- if ((uint32)fread(ptr2, size, 1, (FILE*)file) != 1) {
- clearerr((FILE*)file);
+ if ((uint32)fread(ptr2, size, 1, (FILE *) file) != 1) {
+ clearerr((FILE *) file);
_fileReadFailed = true;
}
do {
- *ptr2++ ^= _encbyte;
- } while(--size);
+ *ptr2++ ^= _encbyte;
+ } while (--size);
return;
case 3:
- if (size==0)
+ if (size == 0)
return;
src = getResourceAddress(rtTemp, 3) + _whereInResToRead;
@@ -103,14 +112,15 @@ void Scumm::fileRead(void *file, void *ptr, uint32 size) {
}
}
-int Scumm::fileReadByte() {
+int Scumm::fileReadByte()
+{
byte b;
byte *src;
- switch(_fileMode) {
+ switch (_fileMode) {
case 1:
- if (fread(&b,1,1,(FILE*)_fileHandle) != 1) {
- clearerr((FILE*)_fileHandle);
+ if (fread(&b, 1, 1, (FILE *) _fileHandle) != 1) {
+ clearerr((FILE *) _fileHandle);
_fileReadFailed = true;
}
return b ^ _encbyte;
@@ -123,66 +133,76 @@ int Scumm::fileReadByte() {
return 0;
}
-uint Scumm::fileReadWordLE() {
+uint Scumm::fileReadWordLE()
+{
uint a = fileReadByte();
uint b = fileReadByte();
- return a|(b<<8);
+ return a | (b << 8);
}
-uint32 Scumm::fileReadDwordLE() {
+uint32 Scumm::fileReadDwordLE()
+{
uint a = fileReadWordLE();
uint b = fileReadWordLE();
- return (b<<16)|a;
+ return (b << 16) | a;
}
-uint Scumm::fileReadWordBE() {
+uint Scumm::fileReadWordBE()
+{
uint b = fileReadByte();
uint a = fileReadByte();
- return a|(b<<8);
+ return a | (b << 8);
}
-uint32 Scumm::fileReadDwordBE() {
+uint32 Scumm::fileReadDwordBE()
+{
uint b = fileReadWordBE();
uint a = fileReadWordBE();
- return (b<<16)|a;
+ return (b << 16) | a;
}
-byte *Scumm::alloc(int size) {
- byte *me = (byte*)::calloc(size+4,1);
- if (me==NULL)
+byte *Scumm::alloc(int size)
+{
+ byte *me = (byte *)::calloc(size + 4, 1);
+ if (me == NULL)
return NULL;
- *((uint32*)me) = 0xDEADBEEF;
+ *((uint32 *)me) = 0xDEADBEEF;
return me + 4;
}
-void Scumm::free(void *mem) {
+void Scumm::free(void *mem)
+{
if (mem) {
- byte *me = (byte*)mem - 4;
- if ( *((uint32*)me) != 0xDEADBEEF) {
+ byte *me = (byte *)mem - 4;
+ if (*((uint32 *)me) != 0xDEADBEEF) {
error("Freeing invalid block.");
}
- *((uint32*)me) = 0xC007CAFE;
+ *((uint32 *)me) = 0xC007CAFE;
::free(me);
}
}
-bool Scumm::checkFixedDisk() {
+bool Scumm::checkFixedDisk()
+{
return true;
}
#ifdef NEED_STRDUP
-char *strdup(const char *s) {
+char *strdup(const char *s)
+{
int len = strlen(s) + 1;
- char *d = (char*)malloc(len);
- if (d) memcpy(d, s, len);
+ char *d = (char *)malloc(len);
+ if (d)
+ memcpy(d, s, len);
return d;
}
#endif /* NEED_STRDUP */
-void *operator new(size_t size) {
- return calloc(size,1);
+void *operator new(size_t size)
+{
+ return calloc(size, 1);
}
diff --git a/v3/resource_v3.cpp b/v3/resource_v3.cpp
index 31988ac732..c4ea3e7296 100644
--- a/v3/resource_v3.cpp
+++ b/v3/resource_v3.cpp
@@ -24,7 +24,8 @@
#include "scumm.h"
-void Scumm_v3::readIndexFile() {
+void Scumm_v3::readIndexFile()
+{
uint16 blocktype;
uint32 itemsize;
int numblock = 0;
@@ -37,122 +38,124 @@ void Scumm_v3::readIndexFile() {
while (!fileEof(_fileHandle)) {
itemsize = fileReadDwordLE();
- blocktype = fileReadWordLE();
- if (fileReadFailed(_fileHandle))
- break;
-
- switch(blocktype) {
- case 0x4E52:
- fileReadWordLE();
- break;
- case 0x5230:
- _numRooms = fileReadWordLE();
- break;
- case 0x5330:
- _numScripts = fileReadWordLE();
- break;
- case 0x4E30:
- _numSounds = fileReadWordLE();
- break;
- case 0x4330:
- _numCostumes = fileReadWordLE();
- break;
- case 0x4F30:
- _numGlobalObjects = fileReadWordLE();
- break;
- }
- fileSeek(_fileHandle, itemsize-8,SEEK_CUR);
+ blocktype = fileReadWordLE();
+ if (fileReadFailed(_fileHandle))
+ break;
+
+ switch (blocktype) {
+ case 0x4E52:
+ fileReadWordLE();
+ break;
+ case 0x5230:
+ _numRooms = fileReadWordLE();
+ break;
+ case 0x5330:
+ _numScripts = fileReadWordLE();
+ break;
+ case 0x4E30:
+ _numSounds = fileReadWordLE();
+ break;
+ case 0x4330:
+ _numCostumes = fileReadWordLE();
+ break;
+ case 0x4F30:
+ _numGlobalObjects = fileReadWordLE();
+ break;
+ }
+ fileSeek(_fileHandle, itemsize - 8, SEEK_CUR);
}
-
+
clearFileReadFailed(_fileHandle);
fileSeek(_fileHandle, 0, SEEK_SET);
- /* I'm not sure for those values yet, they will have to be rechecked */
-
- _numVariables = 800; /* 800 */
- _numBitVariables = 4096; /* 2048 */
- _numLocalObjects = 200; /* 200 */
- _numArray = 50;
- _numVerbs = 100;
- _numNewNames = 0;
- _objectRoomTable = NULL;
- _numCharsets = 9; /* 9 */
- _numInventory = 80; /* 80 */
- _numGlobalScripts = 200;
-
- _shadowPaletteSize = 256;
- _shadowPalette = (byte*)alloc(_shadowPaletteSize); // stupid for now. Need to be removed later
- _numFlObject = 50;
- allocateArrays();
-
- while (1) {
- itemsize = fileReadDwordLE();
-
- if (fileReadFailed(_fileHandle))
- break;
-
- blocktype = fileReadWordLE();
-
- numblock++;
-
- switch(blocktype) {
-
- case 0x4E52:
- fileSeek(_fileHandle, itemsize-6,SEEK_CUR);
- break;
-
- case 0x5230:
- readResTypeList(rtRoom,MKID('ROOM'),"room");
- break;
-
- case 0x5330:
- readResTypeList(rtScript,MKID('SCRP'),"script");
- break;
-
- case 0x4E30:
- readResTypeList(rtSound,MKID('SOUN'),"sound");
- break;
-
- case 0x4330:
- readResTypeList(rtCostume,MKID('COST'),"costume");
- break;
-
- case 0x4F30:
- num = fileReadWordLE();
- assert(num == _numGlobalObjects);
- for (i=0; i!=num; i++) {
- uint32 bits = fileReadByte();
- byte tmp;
- bits |= fileReadByte() << 8;
- bits |= fileReadByte() << 16;
- _classData[i] = bits;
- tmp = fileReadByte();
- _objectOwnerTable[i] = tmp & OF_OWNER_MASK;
- _objectStateTable[i] = tmp >> OF_STATE_SHL;
- }
-
- break;
-
- default:
- error("Bad ID %c%c found in directory!", blocktype&0xFF, blocktype>>8);
- return;
- }
- }
-
- openRoom(-1);
+ /* I'm not sure for those values yet, they will have to be rechecked */
+
+ _numVariables = 800; /* 800 */
+ _numBitVariables = 4096; /* 2048 */
+ _numLocalObjects = 200; /* 200 */
+ _numArray = 50;
+ _numVerbs = 100;
+ _numNewNames = 0;
+ _objectRoomTable = NULL;
+ _numCharsets = 9; /* 9 */
+ _numInventory = 80; /* 80 */
+ _numGlobalScripts = 200;
+
+ _shadowPaletteSize = 256;
+ _shadowPalette = (byte *)alloc(_shadowPaletteSize); // stupid for now. Need to be removed later
+ _numFlObject = 50;
+ allocateArrays();
+
+ while (1) {
+ itemsize = fileReadDwordLE();
+
+ if (fileReadFailed(_fileHandle))
+ break;
+
+ blocktype = fileReadWordLE();
+
+ numblock++;
+
+ switch (blocktype) {
+
+ case 0x4E52:
+ fileSeek(_fileHandle, itemsize - 6, SEEK_CUR);
+ break;
+
+ case 0x5230:
+ readResTypeList(rtRoom, MKID('ROOM'), "room");
+ break;
+
+ case 0x5330:
+ readResTypeList(rtScript, MKID('SCRP'), "script");
+ break;
+
+ case 0x4E30:
+ readResTypeList(rtSound, MKID('SOUN'), "sound");
+ break;
+
+ case 0x4330:
+ readResTypeList(rtCostume, MKID('COST'), "costume");
+ break;
+
+ case 0x4F30:
+ num = fileReadWordLE();
+ assert(num == _numGlobalObjects);
+ for (i = 0; i != num; i++) {
+ uint32 bits = fileReadByte();
+ byte tmp;
+ bits |= fileReadByte() << 8;
+ bits |= fileReadByte() << 16;
+ _classData[i] = bits;
+ tmp = fileReadByte();
+ _objectOwnerTable[i] = tmp & OF_OWNER_MASK;
+ _objectStateTable[i] = tmp >> OF_STATE_SHL;
+ }
+
+ break;
+
+ default:
+ error("Bad ID %c%c found in directory!", blocktype & 0xFF,
+ blocktype >> 8);
+ return;
+ }
+ }
+
+ openRoom(-1);
}
-void Scumm_v3::loadCharset(int no){
- uint32 size;
+void Scumm_v3::loadCharset(int no)
+{
+ uint32 size;
memset(_charsetData, 0, sizeof(_charsetData));
- checkRange(4 ,0 ,no , "Loading illegal charset %d");
- openRoom(-1);
-
- openRoom(98+no);
+ checkRange(4, 0, no, "Loading illegal charset %d");
+ openRoom(-1);
+
+ openRoom(98 + no);
+
+ size = fileReadWordLE();
- size = fileReadWordLE();
-
fileRead(_fileHandle, createResource(6, no, size), size);
- openRoom(-1);
+ openRoom(-1);
}
diff --git a/v4/resource_v4.cpp b/v4/resource_v4.cpp
index d2e63e8221..2514641020 100644
--- a/v4/resource_v4.cpp
+++ b/v4/resource_v4.cpp
@@ -23,15 +23,17 @@
#include "stdafx.h"
#include "scumm.h"
-void Scumm_v4::loadCharset(int no) {
+void Scumm_v4::loadCharset(int no)
+{
uint32 size;
+
- memset(_charsetData, 0, sizeof(_charsetData));
+memset(_charsetData, 0, sizeof(_charsetData));
- checkRange(4 ,0 ,no , "Loading illegal charset %d");
+ checkRange(4, 0, no, "Loading illegal charset %d");
openRoom(-1);
- openRoom(900+no);
+ openRoom(900 + no);
size = fileReadDwordLE();
diff --git a/vars.cpp b/vars.cpp
index 366c52ead4..22b7916f8b 100644
--- a/vars.cpp
+++ b/vars.cpp
@@ -24,7 +24,8 @@
#include "stdafx.h"
#include "scumm.h"
-void Scumm::setupScummVarsOld(){
+void Scumm::setupScummVarsOld()
+{
VAR_EGO = 1;
VAR_CAMERA_POS_X = 2;
@@ -81,7 +82,7 @@ void Scumm::setupScummVarsOld(){
VAR_SOUNDRESULT = 56;
VAR_TALKSTOP_KEY = 57;
VAR_59 = 59;
-
+
VAR_SOUNDPARAM = 64;
VAR_SOUNDPARAM2 = 65;
VAR_SOUNDPARAM3 = 66;
@@ -97,12 +98,12 @@ void Scumm::setupScummVarsOld(){
VAR_MI1_TIMER = 14;
//if (_features & GF_OLD256) {
- VAR_V5_OBJECT_LO = 15;
- VAR_V5_OBJECT_HI = 16;
+ VAR_V5_OBJECT_LO = 15;
+ VAR_V5_OBJECT_HI = 16;
/*} else {
- VAR_V5_OBJECT_LO = 16;
- VAR_V5_OBJECT_HI = 15;
- } */
+ VAR_V5_OBJECT_LO = 16;
+ VAR_V5_OBJECT_HI = 15;
+ } */
VAR_V5_TALK_STRING_Y = 54;
VAR_V5_CHARFLAG = 60;
@@ -114,7 +115,8 @@ void Scumm::setupScummVarsOld(){
}
-void Scumm::setupScummVarsNew() {
+void Scumm::setupScummVarsNew()
+{
VAR_MOUSE_X = 1;
VAR_MOUSE_Y = 2;
@@ -155,11 +157,11 @@ void Scumm::setupScummVarsNew() {
VAR_CUTSCENE_END_SCRIPT = 59;
VAR_UNK_SCRIPT = 60;
VAR_UNK_SCRIPT_2 = 61;
-
+
VAR_PAUSE_KEY = 64;
- VAR_RESTART_KEY = 63; /* ?? */
- VAR_TALKSTOP_KEY = 66; /* ?? */
- VAR_SAVELOADDIALOG_KEY = 65; /* ?? */
+ VAR_RESTART_KEY = 63; /* ?? */
+ VAR_TALKSTOP_KEY = 66; /* ?? */
+ VAR_SAVELOADDIALOG_KEY = 65; /* ?? */
VAR_CUTSCENEEXIT_KEY = 62;
VAR_TIMER_NEXT = 97;
@@ -177,7 +179,7 @@ void Scumm::setupScummVarsNew() {
VAR_CAMERA_SPEED_Y = 108;
VAR_CAMERA_ACCEL_X = 109;
VAR_CAMERA_ACCEL_Y = 110;
-
+
VAR_EGO = 111;
VAR_CURSORSTATE = 112;
@@ -187,7 +189,7 @@ void Scumm::setupScummVarsNew() {
VAR_DEBUGMODE = 116;
VAR_CHARSET_MASK = 119;
-
+
//VAR_V5_DRAWFLAGS = 9;
VAR_MI1_TIMER = 14;
VAR_V5_OBJECT_LO = 15;
diff --git a/verbs.cpp b/verbs.cpp
index 8482be3443..04e14af15a 100644
--- a/verbs.cpp
+++ b/verbs.cpp
@@ -23,25 +23,27 @@
#include "stdafx.h"
#include "scumm.h"
-void Scumm::redrawVerbs() {
+void Scumm::redrawVerbs()
+{
int i;
- for (i=0; i<_maxVerbs; i++)
+ for (i = 0; i < _maxVerbs; i++)
drawVerb(i, 0);
verbMouseOver(0);
}
-void Scumm::checkExecVerbs() {
- int i,over;
+void Scumm::checkExecVerbs()
+{
+ int i, over;
VerbSlot *vs;
- if (_userPut<=0 || _mouseButStat==0)
+ if (_userPut <= 0 || _mouseButStat == 0)
return;
if (_mouseButStat < MBS_MAX_KEY) {
/* Check keypresses */
vs = &_verbs[1];
- for (i=1; i<_maxVerbs; i++,vs++) {
- if (vs->verbid && vs->saveid==0 && vs->curmode==1) {
+ for (i = 1; i < _maxVerbs; i++, vs++) {
+ if (vs->verbid && vs->saveid == 0 && vs->curmode == 1) {
if (_mouseButStat == vs->key) {
runInputScript(1, vs->verbid, 1);
return;
@@ -49,60 +51,64 @@ void Scumm::checkExecVerbs() {
}
}
runInputScript(4, _mouseButStat, 1);
- } else if (_mouseButStat&MBS_MOUSE_MASK) {
- byte code = _mouseButStat&MBS_LEFT_CLICK ? 1 : 2;
- if (mouse.y >= virtscr[0].topline && mouse.y < virtscr[0].topline + virtscr[0].height) {
+ } else if (_mouseButStat & MBS_MOUSE_MASK) {
+ byte code = _mouseButStat & MBS_LEFT_CLICK ? 1 : 2;
+ if (mouse.y >= virtscr[0].topline
+ && mouse.y < virtscr[0].topline + virtscr[0].height) {
over = checkMouseOver(mouse.x, mouse.y);
if (over != 0) {
- runInputScript(1,_verbs[over].verbid,code);
+ runInputScript(1, _verbs[over].verbid, code);
return;
}
runInputScript(2, 0, code);
} else {
- over=checkMouseOver(mouse.x, mouse.y);
- runInputScript(1, over!=0 ? _verbs[over].verbid : 0, code);
+ over = checkMouseOver(mouse.x, mouse.y);
+ runInputScript(1, over != 0 ? _verbs[over].verbid : 0, code);
}
}
}
-void Scumm::verbMouseOver(int verb) {
- if (_verbMouseOver==verb)
+void Scumm::verbMouseOver(int verb)
+{
+ if (_verbMouseOver == verb)
return;
-
- if (_verbs[_verbMouseOver].type!=1) {
+
+ if (_verbs[_verbMouseOver].type != 1) {
drawVerb(_verbMouseOver, 0);
_verbMouseOver = verb;
}
- if (_verbs[verb].type!=1 && _verbs[verb].hicolor) {
- drawVerb(verb, 1);
+ if (_verbs[verb].type != 1 && _verbs[verb].hicolor) {
+ drawVerb(verb, 1);
_verbMouseOver = verb;
}
}
-int Scumm::checkMouseOver(int x, int y) {
+int Scumm::checkMouseOver(int x, int y)
+{
VerbSlot *vs;
- int i = _maxVerbs-1;
+ int i = _maxVerbs - 1;
vs = &_verbs[i];
do {
- if (vs->curmode!=1 || !vs->verbid || vs->saveid ||
- y < vs->y || y >= vs->bottom)
- continue;
+ if (vs->curmode != 1 || !vs->verbid || vs->saveid ||
+ y < vs->y || y >= vs->bottom)
+ continue;
if (vs->center) {
if (x < -(vs->right - vs->x - vs->x) || x >= vs->right)
continue;
- } else {
+ } else {
if (x < vs->x || x >= vs->right)
continue;
}
-
+
return i;
- } while (--vs,--i);
+ } while (--vs, --i);
return 0;
}
-void Scumm::drawVerb(int vrb, int mode) {
+void Scumm::drawVerb(int vrb, int mode)
+{
VerbSlot *vs;
byte color;
byte tmp;
@@ -111,9 +117,9 @@ void Scumm::drawVerb(int vrb, int mode) {
return;
vs = &_verbs[vrb];
-
+
if (!vs->saveid && vs->curmode && vs->verbid) {
- if (vs->type==1) {
+ if (vs->type == 1) {
drawVerbBitmap(vrb, vs->x, vs->y);
return;
}
@@ -129,30 +135,31 @@ void Scumm::drawVerb(int vrb, int mode) {
else
color = vs->color;
string[4].color = color;
- if (vs->curmode==2)
+ if (vs->curmode == 2)
string[4].color = vs->dimcolor;
_messagePtr = getResourceAddress(rtVerb, vrb);
assert(_messagePtr);
-
+
tmp = charset._center;
charset._center = 0;
drawString(4);
charset._center = tmp;
-
+
vs->right = charset._strRight;
vs->bottom = charset._strBottom;
vs->oldleft = charset._strLeft;
vs->oldright = charset._strRight;
vs->oldtop = charset._strTop;
vs->oldbottom = charset._strBottom;
- charset._strLeft = charset._strRight;
+ charset._strLeft = charset._strRight;
} else {
restoreVerbBG(vrb);
}
}
-void Scumm::restoreVerbBG(int verb) {
+void Scumm::restoreVerbBG(int verb)
+{
VerbSlot *vs;
vs = &_verbs[verb];
@@ -164,75 +171,77 @@ void Scumm::restoreVerbBG(int verb) {
}
}
-void Scumm::drawVerbBitmap(int vrb, int x, int y) {
+void Scumm::drawVerbBitmap(int vrb, int x, int y)
+{
VirtScreen *vs;
VerbSlot *vst;
byte twobufs, *imptr;
int ydiff, xstrip;
int imgw, imgh;
- int i,tmp;
+ int i, tmp;
byte *obim;
ImageHeader *imhd;
uint32 size;
- if ((vs=findVirtScreen(y)) == NULL)
+ if ((vs = findVirtScreen(y)) == NULL)
return;
_lastXstart = virtscr[0].xstart;
-
+
gdi.disableZBuffer();
twobufs = vs->alloctwobuffers;
vs->alloctwobuffers = 0;
- xstrip = x>>3;
+ xstrip = x >> 3;
ydiff = y - vs->topline;
obim = getResourceAddress(rtVerb, vrb);
- if (_features & GF_SMALL_HEADER) {
- int obj;
- obj = READ_LE_UINT16(obim+6);
- size = READ_LE_UINT32(obim);
-
- imgw = (*(obim+size+11)) ;
- imgh = (*(obim+size+17))>>3 ;
- imptr = (obim+8);
- } else {
- imhd = (ImageHeader*)findResourceData(MKID('IMHD'), obim);
+ if (_features & GF_SMALL_HEADER) {
+ int obj;
+ obj = READ_LE_UINT16(obim + 6);
+ size = READ_LE_UINT32(obim);
+
+ imgw = (*(obim + size + 11));
+ imgh = (*(obim + size + 17)) >> 3;
+ imptr = (obim + 8);
+ } else {
+ imhd = (ImageHeader *)findResourceData(MKID('IMHD'), obim);
if (_features & GF_AFTER_V7) {
imgw = READ_LE_UINT16(&imhd->v7.width) >> 3;
imgh = READ_LE_UINT16(&imhd->v7.height) >> 3;
} else {
- imgw = READ_LE_UINT16(&imhd->old.width) >> 3;
- imgh = READ_LE_UINT16(&imhd->old.height) >> 3;
+ imgw = READ_LE_UINT16(&imhd->old.width) >> 3;
+ imgh = READ_LE_UINT16(&imhd->old.height) >> 3;
}
-
- imptr = findResource(MKID('IM01'), obim);
- if (!imptr)
- error("No image for verb %d", vrb);
- }
- for (i=0; i<imgw; i++) {
+
+ imptr = findResource(MKID('IM01'), obim);
+ if (!imptr)
+ error("No image for verb %d", vrb);
+ }
+ for (i = 0; i < imgw; i++) {
tmp = xstrip + i;
- if ((uint)tmp < 40)
- gdi.drawBitmap(imptr, vs, tmp, ydiff, imgh<<3, i, 1, true);
+ if ((uint) tmp < 40)
+ gdi.drawBitmap(imptr, vs, tmp, ydiff, imgh << 3, i, 1, true);
}
vst = &_verbs[vrb];
- vst->right = vst->x + imgw*8;
- vst->bottom = vst->y + imgh*8;
+ vst->right = vst->x + imgw * 8;
+ vst->bottom = vst->y + imgh * 8;
vst->oldleft = vst->x;
vst->oldright = vst->right;
vst->oldtop = vst->y;
vst->oldbottom = vst->bottom;
-
+
gdi.enableZBuffer();
vs->alloctwobuffers = twobufs;
}
-int Scumm::getVerbSlot(int id, int mode) {
+int Scumm::getVerbSlot(int id, int mode)
+{
int i;
- for (i=1; i<_maxVerbs; i++) {
+ for (i = 1; i < _maxVerbs; i++) {
if (_verbs[i].verbid == id && _verbs[i].saveid == mode) {
return i;
}
@@ -240,10 +249,11 @@ int Scumm::getVerbSlot(int id, int mode) {
return 0;
}
-void Scumm::killVerb(int slot) {
+void Scumm::killVerb(int slot)
+{
VerbSlot *vs;
- if (slot==0)
+ if (slot == 0)
return;
vs = &_verbs[slot];
@@ -252,16 +262,17 @@ void Scumm::killVerb(int slot) {
nukeResource(rtVerb, slot);
- if (vs->saveid==0){
+ if (vs->saveid == 0) {
drawVerb(slot, 0);
verbMouseOver(0);
}
vs->saveid = 0;
}
-void Scumm::setVerbObject(uint room, uint object, uint verb) {
- byte *obimptr;
- byte *obcdptr;
+void Scumm::setVerbObject(uint room, uint object, uint verb)
+{
+ byte *obimptr;
+ byte *obcdptr;
uint32 size, size2;
FindObjectInRoom foir;
int i;
@@ -269,23 +280,23 @@ void Scumm::setVerbObject(uint room, uint object, uint verb) {
if (whereIsObject(object) == WIO_FLOBJECT)
error("Can't grab verb image from flobject");
- if(_features & GF_SMALL_HEADER) {
- for(i = _numObjectsInRoom; i>0; i--) {
- if(_objs[i].obj_nr == object) {
+ if (_features & GF_SMALL_HEADER) {
+ for (i = _numObjectsInRoom; i > 0; i--) {
+ if (_objs[i].obj_nr == object) {
findObjectInRoom(&foir, foImageHeader, object, room);
size = READ_LE_UINT32(foir.obim);
obcdptr = getResourceAddress(rtRoom, room) + getOBCDOffs(object);
size2 = READ_LE_UINT32(obcdptr);
- createResource(rtVerb, verb, size+size2);
+ createResource(rtVerb, verb, size + size2);
obimptr = getResourceAddress(rtRoom, room) - foir.roomptr + foir.obim;
obcdptr = getResourceAddress(rtRoom, room) + getOBCDOffs(object);
memcpy(getResourceAddress(rtVerb, verb), obimptr, size);
- memcpy(getResourceAddress(rtVerb, verb)+size, obcdptr, size2);
+ memcpy(getResourceAddress(rtVerb, verb) + size, obcdptr, size2);
}
}
} else {
findObjectInRoom(&foir, foImageHeader, object, room);
- size = READ_BE_UINT32_UNALIGNED(foir.obim+4);
+ size = READ_BE_UINT32_UNALIGNED(foir.obim + 4);
createResource(rtVerb, verb, size);
obimptr = getResourceAddress(rtRoom, room) - foir.roomptr + foir.obim;
memcpy(getResourceAddress(rtVerb, verb), obimptr, size);
diff --git a/windows.cpp b/windows.cpp
index 10afbec668..34373046bf 100644
--- a/windows.cpp
+++ b/windows.cpp
@@ -62,11 +62,11 @@ class WndMan {
HWND hWnd;
- bool terminated;
+ bool terminated;
#if USE_GDI
public:
- DIB dib;
+ DIB dib;
private:
#endif
@@ -88,16 +88,17 @@ public:
void setPalette(byte *ctab, int first, int num);
void writeToScreen();
- void prepare_header(WAVEHDR *wh, int i);
+ void prepare_header(WAVEHDR * wh, int i);
void sound_init();
- static DWORD _stdcall sound_thread(WndMan *wm);
+ static DWORD _stdcall sound_thread(WndMan * wm);
#if USE_GDI
bool allocateDIB(int w, int h);
#endif
};
-void Error(const char *msg) {
+void Error(const char *msg)
+{
OutputDebugString(msg);
MessageBoxA(0, msg, "Error", MB_ICONSTOP);
exit(1);
@@ -114,88 +115,103 @@ WndMan wm[1];
byte veryFastMode;
void modifyslot(int sel, int what);
-void launcherLoop() {;}
+void launcherLoop()
+{;
+}
-int mapKey(int key) {
- if (key>=VK_F1 && key<=VK_F9) {
+int mapKey(int key)
+{
+ if (key >= VK_F1 && key <= VK_F9) {
return key - VK_F1 + 315;
}
return key;
}
// FIXME: CD Music Stubs
-void cd_playtrack(int track, int offset, int delay) {;}
-void cd_play(Scumm *s, int track, int num_loops, int start_frame) {;}
-void cd_stop() {;}
-int cd_is_running() {return 0;}
-
-static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
- WndMan *wm = (WndMan*)GetWindowLong(hWnd, GWL_USERDATA);
-
- switch (message)
- {
- case WM_DESTROY:
- case WM_CLOSE:
- exit(0);
- break;
-
- case WM_KEYDOWN:
- if (wParam>='0' && wParam<='9') {
- wm->_scumm->_saveLoadSlot = wParam - '0';
- if (GetAsyncKeyState(VK_SHIFT)<0) {
- sprintf(wm->_scumm->_saveLoadName, "Quicksave %d", wm->_scumm->_saveLoadSlot);
- wm->_scumm->_saveLoadFlag = 1;
- } else if (GetAsyncKeyState(VK_CONTROL)<0)
- wm->_scumm->_saveLoadFlag = 2;
- wm->_scumm->_saveLoadCompatible = false;
+void cd_playtrack(int track, int offset, int delay)
+{;
+}
+void cd_play(Scumm *s, int track, int num_loops, int start_frame)
+{;
+}
+void cd_stop()
+{;
+}
+int cd_is_running()
+{
+ return 0;
+}
+
+static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
+ LPARAM lParam)
+{
+ WndMan *wm = (WndMan *) GetWindowLong(hWnd, GWL_USERDATA);
+
+ switch (message) {
+ case WM_DESTROY:
+ case WM_CLOSE:
+ exit(0);
+ break;
+
+ case WM_KEYDOWN:
+ if (wParam >= '0' && wParam <= '9') {
+ wm->_scumm->_saveLoadSlot = wParam - '0';
+ if (GetAsyncKeyState(VK_SHIFT) < 0) {
+ sprintf(wm->_scumm->_saveLoadName, "Quicksave %d",
+ wm->_scumm->_saveLoadSlot);
+ wm->_scumm->_saveLoadFlag = 1;
+ } else if (GetAsyncKeyState(VK_CONTROL) < 0)
+ wm->_scumm->_saveLoadFlag = 2;
+ wm->_scumm->_saveLoadCompatible = false;
+ }
+
+ if (GetAsyncKeyState(VK_CONTROL) < 0) {
+ if (wParam == 'F') {
+ wm->_scumm->_fastMode ^= 1;
}
- if (GetAsyncKeyState(VK_CONTROL)<0) {
- if (wParam=='F') {
- wm->_scumm->_fastMode ^= 1;
- }
+ if (wParam == 'G') {
+ veryFastMode ^= 1;
+ }
- if (wParam=='G') {
- veryFastMode ^= 1;
- }
+ if (wParam == 'D') {
+ debugger.attach(wm->_scumm);
+ }
- if (wParam=='D') {
- debugger.attach(wm->_scumm);
- }
-
- if (wParam=='S') {
- wm->_scumm->resourceStats();
- }
+ if (wParam == 'S') {
+ wm->_scumm->resourceStats();
}
+ }
- wm->_scumm->_keyPressed = mapKey(wParam);
- break;
-
- case WM_MOUSEMOVE:
- wm->_scumm->mouse.x = ((int16*)&lParam)[0];
- wm->_scumm->mouse.y = ((int16*)&lParam)[1];
- break;
- case WM_LBUTTONDOWN:
- wm->_scumm->_leftBtnPressed |= msClicked|msDown;
- break;
- case WM_LBUTTONUP:
- wm->_scumm->_leftBtnPressed &= ~msDown;
- break;
- case WM_RBUTTONDOWN:
- wm->_scumm->_rightBtnPressed |= msClicked|msDown;
- break;
- case WM_RBUTTONUP:
- wm->_scumm->_rightBtnPressed &= ~msDown;
- break;
- default:
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
- return 0;
+ wm->_scumm->_keyPressed = mapKey(wParam);
+ break;
+
+ case WM_MOUSEMOVE:
+ wm->_scumm->mouse.x = ((int16 *) & lParam)[0];
+ wm->_scumm->mouse.y = ((int16 *) & lParam)[1];
+ break;
+ case WM_LBUTTONDOWN:
+ wm->_scumm->_leftBtnPressed |= msClicked | msDown;
+ break;
+ case WM_LBUTTONUP:
+ wm->_scumm->_leftBtnPressed &= ~msDown;
+ break;
+ case WM_RBUTTONDOWN:
+ wm->_scumm->_rightBtnPressed |= msClicked | msDown;
+ break;
+ case WM_RBUTTONUP:
+ wm->_scumm->_rightBtnPressed &= ~msDown;
+ break;
+ default:
+ return DefWindowProc(hWnd, message, wParam, lParam);
+ }
+ return 0;
}
#if USE_GDI
-bool WndMan::allocateDIB(int w, int h) {
+bool WndMan::allocateDIB(int w, int h)
+{
struct {
BITMAPINFOHEADER bih;
RGBQUAD rgb[256];
@@ -212,23 +228,25 @@ bool WndMan::allocateDIB(int w, int h) {
d.bih.biBitCount = 8;
d.bih.biCompression = BI_RGB;
- memcpy(d.rgb, dib.pal, 256*sizeof(RGBQUAD));
- dib.new_pal=false;
+ memcpy(d.rgb, dib.pal, 256 * sizeof(RGBQUAD));
+ dib.new_pal = false;
- dib.hSect = CreateDIBSection(0, (BITMAPINFO*)&d, DIB_RGB_COLORS, (void**)&dib.buf,
- NULL, NULL);
+ dib.hSect =
+ CreateDIBSection(0, (BITMAPINFO *) & d, DIB_RGB_COLORS, (void **)&dib.buf,
+ NULL, NULL);
return dib.hSect != NULL;
}
-void WndMan::writeToScreen() {
+void WndMan::writeToScreen()
+{
RECT r;
- HDC dc,bmpdc;
+ HDC dc, bmpdc;
HBITMAP bmpOld;
#if DEST_WIDTH==320
if (_vgabuf) {
- for (int y=0; y<200; y++) {
- memcpy(dib.buf + y*320,_vgabuf + y*320, 320);
+ for (int y = 0; y < 200; y++) {
+ memcpy(dib.buf + y * 320, _vgabuf + y * 320, 320);
}
}
#endif
@@ -238,9 +256,9 @@ void WndMan::writeToScreen() {
r.bottom = DEST_HEIGHT;
dc = GetDC(hWnd);
-
+
bmpdc = CreateCompatibleDC(dc);
- bmpOld = (HBITMAP)SelectObject(bmpdc, dib.hSect);
+ bmpOld = (HBITMAP) SelectObject(bmpdc, dib.hSect);
if (dib.new_pal) {
dib.new_pal = false;
@@ -250,7 +268,8 @@ void WndMan::writeToScreen() {
SetStretchBltMode(dc, BLACKONWHITE);
#if DEST_WIDTH==320
- StretchBlt(dc, r.left, r.top, r.right-r.left, r.bottom-r.top, bmpdc, 0, 0, 320,200, SRCCOPY);
+ StretchBlt(dc, r.left, r.top, r.right - r.left, r.bottom - r.top, bmpdc, 0,
+ 0, 320, 200, SRCCOPY);
#endif
@@ -259,13 +278,14 @@ void WndMan::writeToScreen() {
ReleaseDC(hWnd, dc);
}
-void WndMan::setPalette(byte *ctab, int first, int num) {
+void WndMan::setPalette(byte *ctab, int first, int num)
+{
int i;
- for (i=0; i<256; i++) {
- dib.pal[i].rgbRed = ctab[i*3+0];
- dib.pal[i].rgbGreen = ctab[i*3+1];
- dib.pal[i].rgbBlue = ctab[i*3+2];
+ for (i = 0; i < 256; i++) {
+ dib.pal[i].rgbRed = ctab[i * 3 + 0];
+ dib.pal[i].rgbGreen = ctab[i * 3 + 1];
+ dib.pal[i].rgbBlue = ctab[i * 3 + 2];
}
dib.new_pal = true;
@@ -275,34 +295,36 @@ void WndMan::setPalette(byte *ctab, int first, int num) {
HWND globWnd;
-void WndMan::init() {
+void WndMan::init()
+{
/* Retrieve the handle of this module */
hInst = GetModuleHandle(NULL);
/* Register the window class */
WNDCLASSEX wcex;
- wcex.cbSize = sizeof(WNDCLASSEX);
- wcex.style = CS_HREDRAW | CS_VREDRAW;
- wcex.lpfnWndProc = (WNDPROC)WndProc;
- wcex.cbClsExtra = 0;
- wcex.cbWndExtra = 0;
- wcex.hInstance = hInst;
- wcex.hIcon = 0;
- wcex.hCursor = ::LoadCursor(NULL, IDC_ARROW);
- wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
- wcex.lpszMenuName = 0;
- wcex.lpszClassName = "ScummVM";
- wcex.hIconSm = 0;
+ wcex.cbSize = sizeof(WNDCLASSEX);
+ wcex.style = CS_HREDRAW | CS_VREDRAW;
+ wcex.lpfnWndProc = (WNDPROC) WndProc;
+ wcex.cbClsExtra = 0;
+ wcex.cbWndExtra = 0;
+ wcex.hInstance = hInst;
+ wcex.hIcon = 0;
+ wcex.hCursor =::LoadCursor(NULL, IDC_ARROW);
+ wcex.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
+ wcex.lpszMenuName = 0;
+ wcex.lpszClassName = "ScummVM";
+ wcex.hIconSm = 0;
if (!RegisterClassEx(&wcex))
Error("Cannot register window class!");
#if USE_GDI
globWnd = hWnd = CreateWindow("ScummVM", "ScummVM", WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, CW_USEDEFAULT, DEST_WIDTH+10, DEST_HEIGHT+30, NULL, NULL, hInst, NULL);
+ CW_USEDEFAULT, CW_USEDEFAULT, DEST_WIDTH + 10,
+ DEST_HEIGHT + 30, NULL, NULL, hInst, NULL);
SetWindowLong(hWnd, GWL_USERDATA, (long)this);
- dib.pal = (RGBQUAD*)calloc(sizeof(RGBQUAD),256);
+ dib.pal = (RGBQUAD *) calloc(sizeof(RGBQUAD), 256);
dib.new_pal = false;
if (!allocateDIB(DEST_WIDTH, DEST_HEIGHT))
@@ -314,14 +336,15 @@ void WndMan::init() {
}
-bool WndMan::handleMessage() {
+bool WndMan::handleMessage()
+{
MSG msg;
if (!PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
return false;
- if (msg.message==WM_QUIT) {
- terminated=true;
+ if (msg.message == WM_QUIT) {
+ terminated = true;
exit(1);
return true;
}
@@ -335,90 +358,99 @@ bool WndMan::handleMessage() {
unsigned long rdtsc_timer;
-void _declspec(naked) beginpentiumtest() {
+void _declspec(naked) beginpentiumtest()
+{
_asm {
- rdtsc
- mov rdtsc_timer,eax
- ret
- }
+ rdtsc mov rdtsc_timer, eax ret}
}
-int _declspec(naked) endpentiumtest() {
+int _declspec(naked) endpentiumtest()
+{
_asm {
- rdtsc
- sub eax,rdtsc_timer
- ret
- }
+ rdtsc sub eax, rdtsc_timer ret}
}
-void decompressMask(byte *d, byte *s, int w=320, int h=144) {
- int x,y;
-
- for (y=0; y<h; y++) {
- byte *p = s+y*40;
- byte *pd = d + y*320;
+void decompressMask(byte *d, byte *s, int w = 320, int h = 144)
+{
+ int x, y;
+
+ for (y = 0; y < h; y++) {
+ byte *p = s + y * 40;
+ byte *pd = d + y * 320;
byte bits = 0x80, bdata = *p++;
- for (x=0; x<w; x++) {
+ for (x = 0; x < w; x++) {
*pd++ = (bdata & bits) ? 128 : 0;
- bits>>=1;
+ bits >>= 1;
if (!bits) {
bdata = *p++;
- bits=0x80;
+ bits = 0x80;
}
}
}
}
-void outputlittlemask(byte *mask, int w, int h) {
+void outputlittlemask(byte *mask, int w, int h)
+{
byte *old = wm->_vgabuf;
wm->_vgabuf = NULL;
decompressMask(wm->dib.buf, mask, w, h);
- wm->writeToScreen();
+ wm->writeToScreen();
wm->_vgabuf = old;
}
-void outputdisplay2(Scumm *s, int disp) {
+void outputdisplay2(Scumm *s, int disp)
+{
byte *old = wm->_vgabuf;
byte buf[64000];
- switch(disp) {
+ switch (disp) {
case 0:
wm->_vgabuf = buf;
memcpy(buf, wm->_vgabuf, 64000);
- memcpy(buf,s->getResourceAddress(rtBuffer, 5),320*200);
+ memcpy(buf, s->getResourceAddress(rtBuffer, 5), 320 * 200);
break;
case 1:
wm->_vgabuf = buf;
memcpy(buf, wm->_vgabuf, 64000);
- memcpy(buf,s->getResourceAddress(rtBuffer, 1),320*200);
+ memcpy(buf, s->getResourceAddress(rtBuffer, 1), 320 * 200);
break;
case 2:
wm->_vgabuf = NULL;
- decompressMask(wm->dib.buf, s->getResourceAddress(rtBuffer, 9)+s->_screenStartStrip);
+ decompressMask(wm->dib.buf,
+ s->getResourceAddress(rtBuffer, 9) + s->_screenStartStrip);
break;
case 3:
wm->_vgabuf = NULL;
- decompressMask(wm->dib.buf, s->getResourceAddress(rtBuffer, 9)+8160+s->_screenStartStrip);
+ decompressMask(wm->dib.buf,
+ s->getResourceAddress(rtBuffer,
+ 9) + 8160 + s->_screenStartStrip);
break;
case 4:
wm->_vgabuf = NULL;
- decompressMask(wm->dib.buf, s->getResourceAddress(rtBuffer, 9)+8160*2+s->_screenStartStrip);
+ decompressMask(wm->dib.buf,
+ s->getResourceAddress(rtBuffer,
+ 9) + 8160 * 2 +
+ s->_screenStartStrip);
break;
case 5:
wm->_vgabuf = NULL;
- decompressMask(wm->dib.buf, s->getResourceAddress(rtBuffer, 9)+8160*3+s->_screenStartStrip);
+ decompressMask(wm->dib.buf,
+ s->getResourceAddress(rtBuffer,
+ 9) + 8160 * 3 +
+ s->_screenStartStrip);
break;
}
- wm->writeToScreen();
+ wm->writeToScreen();
wm->_vgabuf = old;
}
-void blitToScreen(Scumm *s, byte *src,int x, int y, int w, int h) {
- byte *dst;
+void blitToScreen(Scumm *s, byte *src, int x, int y, int w, int h)
+{
+ byte *dst;
- dst = (byte*)wm->_vgabuf + y*320 + x;
+ dst = (byte *)wm->_vgabuf + y * 320 + x;
do {
memcpy(dst, src, w);
@@ -428,58 +460,68 @@ void blitToScreen(Scumm *s, byte *src,int x, int y, int w, int h) {
}
-void setShakePos(Scumm *s, int shake_pos) {}
+void setShakePos(Scumm *s, int shake_pos)
+{
+}
int clock;
-void updateScreen(Scumm *s) {
+void updateScreen(Scumm *s)
+{
if (s->_palDirtyMax != -1) {
- wm->setPalette(s->_currentPalette, 0, 256);
+ wm->setPalette(s->_currentPalette, 0, 256);
s->_palDirtyMax = -1;
}
wm->writeToScreen();
}
-void waitForTimer(Scumm *s, int delay) {
+void waitForTimer(Scumm *s, int delay)
+{
wm->handleMessage();
if (!veryFastMode) {
- assert(delay<5000);
+ assert(delay < 5000);
if (s->_fastMode)
- delay=10;
+ delay = 10;
Sleep(delay);
- }
+ }
}
-void initGraphics(Scumm *s, bool fullScreen, unsigned int scaleFactor) {
- if(fullScreen)
+void initGraphics(Scumm *s, bool fullScreen, unsigned int scaleFactor)
+{
+ if (fullScreen)
warning("Use SDL for fullscreen support");
- scale = scaleFactor; // not supported yet! ignored.
+ scale = scaleFactor; // not supported yet! ignored.
}
-void drawMouse(Scumm *s, int, int, int, byte*, bool) {
+void drawMouse(Scumm *s, int, int, int, byte *, bool)
+{
}
-void drawMouse(Scumm *s, int x, int y, int w, int h, byte *buf, bool visible) {
+void drawMouse(Scumm *s, int x, int y, int w, int h, byte *buf, bool visible)
+{
}
-void fill_buffer(int16 *buf, int len) {
+void fill_buffer(int16 * buf, int len)
+{
scumm.mixWaves(buf, len);
}
-void WndMan::prepare_header(WAVEHDR *wh, int i) {
+void WndMan::prepare_header(WAVEHDR * wh, int i)
+{
memset(wh, 0, sizeof(WAVEHDR));
- wh->lpData = (char*)malloc(BUFFER_SIZE);
+ wh->lpData = (char *)malloc(BUFFER_SIZE);
wh->dwBufferLength = BUFFER_SIZE;
waveOutPrepareHeader(_handle, wh, sizeof(WAVEHDR));
- fill_buffer((int16*)wh->lpData, wh->dwBufferLength>>1);
+ fill_buffer((int16 *) wh->lpData, wh->dwBufferLength >> 1);
waveOutWrite(_handle, wh, sizeof(WAVEHDR));
}
-void WndMan::sound_init() {
+void WndMan::sound_init()
+{
WAVEFORMATEX wfx;
memset(&wfx, 0, sizeof(wfx));
@@ -490,20 +532,23 @@ void WndMan::sound_init() {
wfx.wBitsPerSample = BITS_PER_SAMPLE;
wfx.nBlockAlign = BITS_PER_SAMPLE * 1 / 8;
- CreateThread(NULL, 0, (unsigned long (__stdcall *)(void *))&sound_thread, this, 0, &_threadId);
- SetThreadPriority((void*)_threadId, THREAD_PRIORITY_HIGHEST);
+ CreateThread(NULL, 0, (unsigned long (__stdcall *) (void *))&sound_thread,
+ this, 0, &_threadId);
+ SetThreadPriority((void *)_threadId, THREAD_PRIORITY_HIGHEST);
_event = CreateEvent(NULL, false, false, NULL);
- memset(_hdr,0,sizeof(_hdr));
-
- waveOutOpen(&_handle, WAVE_MAPPER, &wfx, (long)_event, (long)this, CALLBACK_EVENT );
+ memset(_hdr, 0, sizeof(_hdr));
+
+ waveOutOpen(&_handle, WAVE_MAPPER, &wfx, (long)_event, (long)this,
+ CALLBACK_EVENT);
prepare_header(&_hdr[0], 0);
prepare_header(&_hdr[1], 1);
}
-DWORD _stdcall WndMan::sound_thread(WndMan *wm) {
+DWORD _stdcall WndMan::sound_thread(WndMan * wm)
+{
int i;
bool signaled;
int time = GetTickCount(), cur;
@@ -521,10 +566,10 @@ DWORD _stdcall WndMan::sound_thread(WndMan *wm) {
signaled = WaitForSingleObject(wm->_event, time - cur) == WAIT_OBJECT_0;
if (signaled) {
- for(i=0; i<2; i++) {
+ for (i = 0; i < 2; i++) {
WAVEHDR *hdr = &wm->_hdr[i];
if (hdr->dwFlags & WHDR_DONE) {
- fill_buffer((int16*)hdr->lpData, hdr->dwBufferLength>>1);
+ fill_buffer((int16 *) hdr->lpData, hdr->dwBufferLength >> 1);
waveOutWrite(wm->_handle, hdr, sizeof(WAVEHDR));
}
}
@@ -534,28 +579,29 @@ DWORD _stdcall WndMan::sound_thread(WndMan *wm) {
#undef main
-int main(int argc, char* argv[]) {
+int main(int argc, char *argv[])
+{
int delta;
wm->init();
- wm->_vgabuf = (byte*)calloc(320,200);
+ wm->_vgabuf = (byte *)calloc(320, 200);
wm->_scumm = &scumm;
- sound.initialize(&scumm,&snd_driv);
+ sound.initialize(&scumm, &snd_driv);
wm->sound_init();
scumm._gui = &gui;
scumm.scummMain(argc, argv);
- if (!(scumm._features & GF_SMALL_HEADER))
- gui.init(&scumm);
+ if (!(scumm._features & GF_SMALL_HEADER))
+ gui.init(&scumm);
delta = 0;
do {
updateScreen(&scumm);
- waitForTimer(&scumm, delta*15);
+ waitForTimer(&scumm, delta * 15);
if (gui._active) {
gui.loop();
@@ -563,9 +609,11 @@ int main(int argc, char* argv[]) {
} else {
delta = scumm.scummLoop(delta);
}
- } while(1);
+ } while (1);
return 0;
}
-void BoxTest(int num) {;} // Test code
+void BoxTest(int num)
+{;
+} // Test code
diff --git a/x11.cpp b/x11.cpp
index 292234d691..72fc31f1da 100644
--- a/x11.cpp
+++ b/x11.cpp
@@ -75,303 +75,319 @@ static int current_shake_pos = 0;
#define MAX_NUMBER_OF_DIRTY_SQUARES 32
typedef struct {
- int x, y, w, h;
+ int x, y, w, h;
} dirty_square;
static dirty_square ds[MAX_NUMBER_OF_DIRTY_SQUARES];
static int num_of_dirty_square;
/* Milisecond-based timer management */
static struct timeval start_time;
-static void init_timer(void) {
- gettimeofday(&start_time, NULL);
+static void init_timer(void)
+{
+ gettimeofday(&start_time, NULL);
}
-static unsigned int get_ms_from_start(void) {
- struct timeval current_time;
- gettimeofday(&current_time, NULL);
- return (((current_time.tv_sec - start_time.tv_sec ) * 1000) +
- ((current_time.tv_usec - start_time.tv_usec) / 1000));
+static unsigned int get_ms_from_start(void)
+{
+ struct timeval current_time;
+ gettimeofday(&current_time, NULL);
+ return (((current_time.tv_sec - start_time.tv_sec) * 1000) +
+ ((current_time.tv_usec - start_time.tv_usec) / 1000));
}
#define FRAG_SIZE 4096
-static void *sound_and_music_thread(void *params) {
- /* Init sound */
- int sound_fd, param, frag_size;
- unsigned char sound_buffer[FRAG_SIZE];
-
- sound_fd = open("/dev/dsp", O_WRONLY);
- audio_buf_info info;
- if (sound_fd < 0) {
- error("Error opening sound device !\n");
- exit(1);
- }
- param = 0;
- frag_size = FRAG_SIZE /* audio fragment size */;
- while (frag_size) {
- frag_size >>= 1;
- param++;
- }
- param--;
- param |= /* audio_fragment_num */ 3 << 16;
- if (ioctl(sound_fd, SNDCTL_DSP_SETFRAGMENT, &param) != 0) {
- error("Error in the SNDCTL_DSP_SETFRAGMENT ioctl !\n");
- exit(1);
- }
- param = AFMT_S16_LE;
- if (ioctl(sound_fd, SNDCTL_DSP_SETFMT, &param) == -1) {
- perror("Error in the SNDCTL_DSP_SETFMT ioctl !\n");
- exit(1);
- }
- if (param != AFMT_S16_LE) {
- error("AFMT_S16_LE not supported !\n");
- exit(1);
- }
- param = 2;
- if (ioctl(sound_fd, SNDCTL_DSP_CHANNELS, &param) == -1) {
- error("Error in the SNDCTL_DSP_CHANNELS ioctl !\n");
- exit(1);
- }
- if (param != 2) {
- error("Stereo mode not supported !\n");
- exit(1);
- }
- param = 22050;
- if (ioctl(sound_fd, SNDCTL_DSP_SPEED, &param) == -1) {
- perror("Error in the SNDCTL_DSP_SPEED ioctl !\n");
- exit(1);
- }
- if (param != 22050) {
- error("22050 kHz not supported !\n");
- exit(1);
- }
- if (ioctl(sound_fd, SNDCTL_DSP_GETOSPACE, &info) != 0) {
- perror("SNDCTL_DSP_GETOSPACE");
- exit(-1);
- }
+static void *sound_and_music_thread(void *params)
+{
+ /* Init sound */
+ int sound_fd, param, frag_size;
+ unsigned char sound_buffer[FRAG_SIZE];
+
+ sound_fd = open("/dev/dsp", O_WRONLY);
+ audio_buf_info info;
+ if (sound_fd < 0) {
+ error("Error opening sound device !\n");
+ exit(1);
+ }
+ param = 0;
+ frag_size = FRAG_SIZE /* audio fragment size */ ;
+ while (frag_size) {
+ frag_size >>= 1;
+ param++;
+ }
+ param--;
+ param |= /* audio_fragment_num */ 3 << 16;
+ if (ioctl(sound_fd, SNDCTL_DSP_SETFRAGMENT, &param) != 0) {
+ error("Error in the SNDCTL_DSP_SETFRAGMENT ioctl !\n");
+ exit(1);
+ }
+ param = AFMT_S16_LE;
+ if (ioctl(sound_fd, SNDCTL_DSP_SETFMT, &param) == -1) {
+ perror("Error in the SNDCTL_DSP_SETFMT ioctl !\n");
+ exit(1);
+ }
+ if (param != AFMT_S16_LE) {
+ error("AFMT_S16_LE not supported !\n");
+ exit(1);
+ }
+ param = 2;
+ if (ioctl(sound_fd, SNDCTL_DSP_CHANNELS, &param) == -1) {
+ error("Error in the SNDCTL_DSP_CHANNELS ioctl !\n");
+ exit(1);
+ }
+ if (param != 2) {
+ error("Stereo mode not supported !\n");
+ exit(1);
+ }
+ param = 22050;
+ if (ioctl(sound_fd, SNDCTL_DSP_SPEED, &param) == -1) {
+ perror("Error in the SNDCTL_DSP_SPEED ioctl !\n");
+ exit(1);
+ }
+ if (param != 22050) {
+ error("22050 kHz not supported !\n");
+ exit(1);
+ }
+ if (ioctl(sound_fd, SNDCTL_DSP_GETOSPACE, &info) != 0) {
+ perror("SNDCTL_DSP_GETOSPACE");
+ exit(-1);
+ }
- while (1) {
- unsigned short *buf = (unsigned short *) sound_buffer;
- int size, written;
-
- scumm.mixWaves((short *) sound_buffer, FRAG_SIZE >> 2);
- /* Now convert to stereo */
- for (int i = ((FRAG_SIZE >> 2) - 1); i >= 0; i--) {
- buf[2 * i + 1] = buf[2 * i] = buf[i];
- }
- size = FRAG_SIZE;
- while (size > 0) {
- written = write(sound_fd, sound_buffer, size);
- size -= written;
- }
- }
+ while (1) {
+ unsigned short *buf = (unsigned short *)sound_buffer;
+ int size, written;
+
+ scumm.mixWaves((short *)sound_buffer, FRAG_SIZE >> 2);
+ /* Now convert to stereo */
+ for (int i = ((FRAG_SIZE >> 2) - 1); i >= 0; i--) {
+ buf[2 * i + 1] = buf[2 * i] = buf[i];
+ }
+ size = FRAG_SIZE;
+ while (size > 0) {
+ written = write(sound_fd, sound_buffer, size);
+ size -= written;
+ }
+ }
- return NULL;
+ return NULL;
}
/* Function used to hide the mouse cursor */
-static void create_empty_cursor(Display *display,
- int screen,
- Window window) {
- XColor bg;
- Pixmap pixmapBits;
- Cursor cursor = None;
- static const char data[] = { 0 };
-
- bg.red = bg.green = bg.blue = 0x0000;
- pixmapBits = XCreateBitmapFromData(display, XRootWindow(display, screen), data, 1, 1);
- if (pixmapBits) {
- cursor = XCreatePixmapCursor(display, pixmapBits, pixmapBits,
- &bg, &bg, 0, 0 );
- XFreePixmap(display, pixmapBits);
- }
- XDefineCursor(display, window, cursor);
+static void create_empty_cursor(Display * display, int screen, Window window)
+{
+ XColor bg;
+ Pixmap pixmapBits;
+ Cursor cursor = None;
+ static const char data[] = { 0 };
+
+ bg.red = bg.green = bg.blue = 0x0000;
+ pixmapBits =
+ XCreateBitmapFromData(display, XRootWindow(display, screen), data, 1, 1);
+ if (pixmapBits) {
+ cursor = XCreatePixmapCursor(display, pixmapBits, pixmapBits,
+ &bg, &bg, 0, 0);
+ XFreePixmap(display, pixmapBits);
+ }
+ XDefineCursor(display, window, cursor);
}
/* No CD on the iPAQ => stub functions */
-void cd_play(Scumm *s, int track, int num_loops, int start_frame, int end_frame) {
+void cd_play(Scumm *s, int track, int num_loops, int start_frame,
+ int end_frame)
+{
#ifdef COMPRESSED_SOUND_FILE
mp3_cd_play(s, track, num_loops, start_frame, end_frame);
#endif
}
-int cd_is_running(void) {
- return 1;
+int cd_is_running(void)
+{
+ return 1;
}
-void cd_stop(void) {
+void cd_stop(void)
+{
}
/* No debugger on the iPAQ => stub function */
-void BoxTest(int num) {
+void BoxTest(int num)
+{
}
/* Initialize the graphics sub-system */
-void initGraphics(Scumm *s, bool fullScreen, unsigned int scaleFactor) {
- char buf[512], *gameName;
- static XShmSegmentInfo shminfo;
- XWMHints *wm_hints;
- XGCValues values;
- XTextProperty window_name;
- char *name = (char *) &buf;
-
- scale = scaleFactor; // not implemented yet! ignored.
-
- /* For the window title */
- sprintf(buf, "ScummVM - %s", gameName = s->getGameName());
- free(gameName);
-
- display = XOpenDisplay(NULL);
- if (display == NULL) {
- error("Could not open display !\n");
- exit(1);
- }
- screen = DefaultScreen(display);
- x11_socket = ConnectionNumber(display);
-
- window_width = 320;
- window_height = 200;
- scumm_x = 0;
- scumm_y = 0;
- window = XCreateSimpleWindow(display, XRootWindow(display, screen), 0, 0,
- 320, 200, 0, 0, 0);
- wm_hints = XAllocWMHints();
- if (wm_hints == NULL) {
- error("Not enough memory to allocate Hints !\n");
- exit(1);
- }
- wm_hints->flags = InputHint | StateHint;
- wm_hints->input = True;
- wm_hints->initial_state = NormalState;
- XStringListToTextProperty( &name, 1, &window_name );
- XSetWMProperties(display, window, &window_name, &window_name,
- NULL /* argv */, 0 /* argc */, NULL /* size hints */, wm_hints, NULL /* class hints */ );
-
- XSelectInput(display, window,
- ExposureMask | KeyPressMask | KeyReleaseMask | PointerMotionMask |
- ButtonPressMask | ButtonReleaseMask | StructureNotifyMask);
- image = XShmCreateImage(display, DefaultVisual(display, screen), 16, ZPixmap, NULL, &shminfo, 320, 200);
- shminfo.shmid = shmget(IPC_PRIVATE, 320 * 200 * 2, IPC_CREAT | 0700);
- shminfo.shmaddr = (char *) shmat(shminfo.shmid, 0, 0);
- image->data = shminfo.shmaddr;
- shminfo.readOnly = False;
- if (XShmAttach(display, &shminfo) == 0) {
- error("Could not attach shared memory segment !\n");
- exit(1);
- }
- shmctl(shminfo.shmid, IPC_RMID, 0);
+void initGraphics(Scumm *s, bool fullScreen, unsigned int scaleFactor)
+{
+ char buf[512], *gameName;
+ static XShmSegmentInfo shminfo;
+ XWMHints *wm_hints;
+ XGCValues values;
+ XTextProperty window_name;
+ char *name = (char *)&buf;
+
+ scale = scaleFactor; // not implemented yet! ignored.
+
+ /* For the window title */
+ sprintf(buf, "ScummVM - %s", gameName = s->getGameName());
+ free(gameName);
+
+ display = XOpenDisplay(NULL);
+ if (display == NULL) {
+ error("Could not open display !\n");
+ exit(1);
+ }
+ screen = DefaultScreen(display);
+ x11_socket = ConnectionNumber(display);
+
+ window_width = 320;
+ window_height = 200;
+ scumm_x = 0;
+ scumm_y = 0;
+ window = XCreateSimpleWindow(display, XRootWindow(display, screen), 0, 0,
+ 320, 200, 0, 0, 0);
+ wm_hints = XAllocWMHints();
+ if (wm_hints == NULL) {
+ error("Not enough memory to allocate Hints !\n");
+ exit(1);
+ }
+ wm_hints->flags = InputHint | StateHint;
+ wm_hints->input = True;
+ wm_hints->initial_state = NormalState;
+ XStringListToTextProperty(&name, 1, &window_name);
+ XSetWMProperties(display, window, &window_name, &window_name,
+ NULL /* argv */ , 0 /* argc */ , NULL /* size hints */ ,
+ wm_hints, NULL /* class hints */ );
+
+ XSelectInput(display, window,
+ ExposureMask | KeyPressMask | KeyReleaseMask |
+ PointerMotionMask | ButtonPressMask | ButtonReleaseMask |
+ StructureNotifyMask);
+ image =
+ XShmCreateImage(display, DefaultVisual(display, screen), 16, ZPixmap,
+ NULL, &shminfo, 320, 200);
+ shminfo.shmid = shmget(IPC_PRIVATE, 320 * 200 * 2, IPC_CREAT | 0700);
+ shminfo.shmaddr = (char *)shmat(shminfo.shmid, 0, 0);
+ image->data = shminfo.shmaddr;
+ shminfo.readOnly = False;
+ if (XShmAttach(display, &shminfo) == 0) {
+ error("Could not attach shared memory segment !\n");
+ exit(1);
+ }
+ shmctl(shminfo.shmid, IPC_RMID, 0);
- values.foreground = BlackPixel(display, screen);
- black_gc = XCreateGC(display, window, GCForeground, &values);
+ values.foreground = BlackPixel(display, screen);
+ black_gc = XCreateGC(display, window, GCForeground, &values);
- XMapWindow(display, window);
- XFlush(display);
+ XMapWindow(display, window);
+ XFlush(display);
- while (1) {
- XEvent event;
- XNextEvent(display, &event);
- switch (event.type) {
- case Expose:
- goto out_of_loop;
- }
- }
- out_of_loop:
- create_empty_cursor(display, screen, window);
+ while (1) {
+ XEvent event;
+ XNextEvent(display, &event);
+ switch (event.type) {
+ case Expose:
+ goto out_of_loop;
+ }
+ }
+out_of_loop:
+ create_empty_cursor(display, screen, window);
- /* And finally start the music thread */
- pthread_create(&sound_thread, NULL, sound_and_music_thread, NULL);
+ /* And finally start the music thread */
+ pthread_create(&sound_thread, NULL, sound_and_music_thread, NULL);
- /* Initialize the 'local' frame buffer */
- local_fb = (unsigned char *) malloc(320 * 200 * sizeof(unsigned char));
+ /* Initialize the 'local' frame buffer */
+ local_fb = (unsigned char *)malloc(320 * 200 * sizeof(unsigned char));
}
-void setWindowName(Scumm *s) {
- char buf[512], *gameName;
- XTextProperty window_name;
- char *name = (char *) &buf;
-
- /* For the window title */
- sprintf(buf, "ScummVM - %s", gameName = s->getGameName());
- free(gameName);
-
- XStringListToTextProperty( &name, 1, &window_name );
- XSetWMProperties(display, window, &window_name, &window_name,
- NULL /* argv */, 0 /* argc */, NULL /* size hints */, NULL /* WM hints */, NULL /* class hints */ );
+void setWindowName(Scumm *s)
+{
+ char buf[512], *gameName;
+ XTextProperty window_name;
+ char *name = (char *)&buf;
+
+ /* For the window title */
+ sprintf(buf, "ScummVM - %s", gameName = s->getGameName());
+ free(gameName);
+
+ XStringListToTextProperty(&name, 1, &window_name);
+ XSetWMProperties(display, window, &window_name, &window_name,
+ NULL /* argv */ , 0 /* argc */ , NULL /* size hints */ ,
+ NULL /* WM hints */ , NULL /* class hints */ );
}
/* This simply shifts up or down the screen by 'shake pos' */
-void setShakePos(Scumm *s, int shake_pos) {
- if (shake_pos != current_shake_pos) {
- int dirty_top = 0, dirty_height = 0;
- int line;
-
- /* This is to provoke a full redraw */
- num_of_dirty_square = MAX_NUMBER_OF_DIRTY_SQUARES;
-
- /* Update the mouse to prevent 'mouse droppings' */
- old_mouse_y += shake_pos - current_shake_pos;
-
- /* Handle the 'dirty part' of the screen */
- if (shake_pos > current_shake_pos) {
- for (line = 199 + shake_pos; line >= -shake_pos; line--) {
- int cur_pos, new_pos;
- int cur_OK, new_OK;
-
- cur_pos = line + current_shake_pos;
- new_pos = line + shake_pos;
-
- cur_OK = (cur_pos >= 0) && (cur_pos < 200);
- new_OK = (new_pos >= 0) && (new_pos < 200);
- if (cur_OK && new_OK)
- memcpy(local_fb + new_pos * 320, local_fb + cur_pos * 320, 320);
- else if (cur_OK)
- memset(local_fb + cur_pos * 320, 0, 320);
- else if (new_OK)
- memset(local_fb + new_pos * 320, 0, 320);
- }
-
- if (current_shake_pos < 0) {
- dirty_top = -shake_pos;
- dirty_height = shake_pos - current_shake_pos;
- if (dirty_top < 0) {
- dirty_height += dirty_top;
- dirty_top = 0;
- }
- if ((dirty_height + dirty_top) > 200)
- dirty_height = 200 - dirty_top;
- } else {
- dirty_height = 0;
- }
- } else {
- for (line = -current_shake_pos; line < 200 + current_shake_pos; line++) {
- int cur_pos, new_pos;
- int cur_OK, new_OK;
-
- cur_pos = line + current_shake_pos;
- new_pos = line + shake_pos;
- cur_OK = (cur_pos >= 0) && (cur_pos < 200);
- new_OK = (new_pos >= 0) && (new_pos < 200);
-
- if (cur_OK && new_OK)
- memcpy(local_fb + new_pos * 320, local_fb + cur_pos * 320, 320);
- else if (cur_OK)
- memset(local_fb + cur_pos * 320, 0, 320);
- else if (new_OK)
- memset(local_fb + new_pos * 320, 0, 320);
- }
-
- if (current_shake_pos <= 0) {
- dirty_height = 0;
- } else {
- dirty_top = 200 - current_shake_pos;
- dirty_height = current_shake_pos - shake_pos;
- if ((dirty_height + dirty_top) > 200)
- dirty_height = 200 - dirty_top;
- }
- }
-
- /* And save the new shake position */
- current_shake_pos = shake_pos;
- if (dirty_height > 0)
- s->redrawLines(dirty_top, dirty_top + dirty_height);
- }
+void setShakePos(Scumm *s, int shake_pos)
+{
+ if (shake_pos != current_shake_pos) {
+ int dirty_top = 0, dirty_height = 0;
+ int line;
+
+ /* This is to provoke a full redraw */
+ num_of_dirty_square = MAX_NUMBER_OF_DIRTY_SQUARES;
+
+ /* Update the mouse to prevent 'mouse droppings' */
+ old_mouse_y += shake_pos - current_shake_pos;
+
+ /* Handle the 'dirty part' of the screen */
+ if (shake_pos > current_shake_pos) {
+ for (line = 199 + shake_pos; line >= -shake_pos; line--) {
+ int cur_pos, new_pos;
+ int cur_OK, new_OK;
+
+ cur_pos = line + current_shake_pos;
+ new_pos = line + shake_pos;
+
+ cur_OK = (cur_pos >= 0) && (cur_pos < 200);
+ new_OK = (new_pos >= 0) && (new_pos < 200);
+ if (cur_OK && new_OK)
+ memcpy(local_fb + new_pos * 320, local_fb + cur_pos * 320, 320);
+ else if (cur_OK)
+ memset(local_fb + cur_pos * 320, 0, 320);
+ else if (new_OK)
+ memset(local_fb + new_pos * 320, 0, 320);
+ }
+
+ if (current_shake_pos < 0) {
+ dirty_top = -shake_pos;
+ dirty_height = shake_pos - current_shake_pos;
+ if (dirty_top < 0) {
+ dirty_height += dirty_top;
+ dirty_top = 0;
+ }
+ if ((dirty_height + dirty_top) > 200)
+ dirty_height = 200 - dirty_top;
+ } else {
+ dirty_height = 0;
+ }
+ } else {
+ for (line = -current_shake_pos; line < 200 + current_shake_pos; line++) {
+ int cur_pos, new_pos;
+ int cur_OK, new_OK;
+
+ cur_pos = line + current_shake_pos;
+ new_pos = line + shake_pos;
+ cur_OK = (cur_pos >= 0) && (cur_pos < 200);
+ new_OK = (new_pos >= 0) && (new_pos < 200);
+
+ if (cur_OK && new_OK)
+ memcpy(local_fb + new_pos * 320, local_fb + cur_pos * 320, 320);
+ else if (cur_OK)
+ memset(local_fb + cur_pos * 320, 0, 320);
+ else if (new_OK)
+ memset(local_fb + new_pos * 320, 0, 320);
+ }
+
+ if (current_shake_pos <= 0) {
+ dirty_height = 0;
+ } else {
+ dirty_top = 200 - current_shake_pos;
+ dirty_height = current_shake_pos - shake_pos;
+ if ((dirty_height + dirty_top) > 200)
+ dirty_height = 200 - dirty_top;
+ }
+ }
+
+ /* And save the new shake position */
+ current_shake_pos = shake_pos;
+ if (dirty_height > 0)
+ s->redrawLines(dirty_top, dirty_top + dirty_height);
+ }
}
#define AddDirtyRec(xi,yi,wi,hi) \
@@ -382,400 +398,425 @@ void setShakePos(Scumm *s, int shake_pos) {
ds[num_of_dirty_square].h = hi; \
num_of_dirty_square++; \
}
-void blitToScreen(Scumm *s, byte *src, int x, int y, int w, int h) {
- unsigned char *dst;
-
- y += current_shake_pos;
- if (y < 0) {
- h += y;
- src -= y * 320;
- y = 0;
- }
- if (h > (200 - y)) {
- h = 200 - y;
- }
+void blitToScreen(Scumm *s, byte *src, int x, int y, int w, int h)
+{
+ unsigned char *dst;
- dst = local_fb + 320 * y + x;
+ y += current_shake_pos;
+ if (y < 0) {
+ h += y;
+ src -= y * 320;
+ y = 0;
+ }
+ if (h > (200 - y)) {
+ h = 200 - y;
+ }
- if (h<=0) return;
+ dst = local_fb + 320 * y + x;
- hide_mouse = true;
- if (has_mouse) {
- s->drawMouse();
- }
-
- AddDirtyRec(x, y, w, h);
- while (h-- > 0) {
- memcpy(dst, src, w);
- dst += 320;
- src += 320;
- }
+ if (h <= 0)
+ return;
+
+ hide_mouse = true;
+ if (has_mouse) {
+ s->drawMouse();
+ }
+
+ AddDirtyRec(x, y, w, h);
+ while (h-- > 0) {
+ memcpy(dst, src, w);
+ dst += 320;
+ src += 320;
+ }
}
#define BAK_WIDTH 40
#define BAK_HEIGHT 40
unsigned char old_backup[BAK_WIDTH * BAK_HEIGHT];
-void drawMouse(Scumm *s, int xdraw, int ydraw, int w, int h, byte *buf, bool visible) {
- unsigned char *dst,*bak;
+void drawMouse(Scumm *s, int xdraw, int ydraw, int w, int h, byte *buf,
+ bool visible)
+{
+ unsigned char *dst, *bak;
+
+ ydraw += current_shake_pos;
+
+ if ((xdraw >= 320) || ((xdraw + w) <= 0) ||
+ (ydraw >= 200) || ((ydraw + h) <= 0)) {
+ if (hide_mouse)
+ visible = false;
+ if (has_mouse)
+ has_mouse = false;
+ if (visible)
+ has_mouse = true;
+ return;
+ }
- ydraw += current_shake_pos;
+ if (hide_mouse)
+ visible = false;
- if ((xdraw >= 320) || ((xdraw + w) <= 0) ||
- (ydraw >= 200) || ((ydraw + h) <= 0)) {
- if (hide_mouse) visible = false;
- if (has_mouse) has_mouse = false;
- if (visible) has_mouse = true;
- return;
- }
+ assert(w <= BAK_WIDTH && h <= BAK_HEIGHT);
- if (hide_mouse)
- visible = false;
-
- assert(w<=BAK_WIDTH && h<=BAK_HEIGHT);
-
- if (has_mouse) {
- int old_h = old_mouse_h;
-
- has_mouse = false;
- AddDirtyRec(old_mouse_x, old_mouse_y, old_mouse_w, old_mouse_h);
-
- dst = local_fb + (old_mouse_y * 320) + old_mouse_x;
- bak = old_backup;
-
- while (old_h > 0) {
- memcpy(dst, bak, old_mouse_w);
- bak += BAK_WIDTH;
- dst += 320;
- old_h--;
- }
- }
+ if (has_mouse) {
+ int old_h = old_mouse_h;
- if (visible) {
- int real_w;
- int real_h;
- int real_h_2;
- unsigned char *dst2;
-
- if (ydraw < 0) {
- real_h = h + ydraw;
- buf += (-ydraw) * w;
- ydraw = 0;
- } else {
- real_h = (ydraw + h) > 200 ? (200 - ydraw) : h;
- }
- if (xdraw < 0) {
- real_w = w + xdraw;
- buf += (-xdraw);
- xdraw = 0;
- } else {
- real_w = (xdraw + w) > 320 ? (320 - xdraw) : w;
- }
-
- dst = local_fb + (ydraw * 320) + xdraw;
- dst2 = dst;
- bak = old_backup;
-
- has_mouse = true;
-
- AddDirtyRec(xdraw, ydraw, real_w, real_h);
- old_mouse_x = xdraw;
- old_mouse_y = ydraw;
- old_mouse_w = real_w;
- old_mouse_h = real_h;
-
- real_h_2 = real_h;
- while (real_h_2 > 0) {
- memcpy(bak, dst, real_w);
- bak += BAK_WIDTH;
- dst += 320;
- real_h_2--;
- }
- while (real_h > 0) {
- int width = real_w;
- while (width > 0) {
- unsigned char color = *buf;
- if (color != 0xFF) {
- *dst2 = color;
- }
- buf++;
- dst2++;
- width--;
- }
- buf += w - real_w;
- dst2 += 320 - real_w;
- real_h--;
- }
- }
+ has_mouse = false;
+ AddDirtyRec(old_mouse_x, old_mouse_y, old_mouse_w, old_mouse_h);
+
+ dst = local_fb + (old_mouse_y * 320) + old_mouse_x;
+ bak = old_backup;
+
+ while (old_h > 0) {
+ memcpy(dst, bak, old_mouse_w);
+ bak += BAK_WIDTH;
+ dst += 320;
+ old_h--;
+ }
+ }
+
+ if (visible) {
+ int real_w;
+ int real_h;
+ int real_h_2;
+ unsigned char *dst2;
+
+ if (ydraw < 0) {
+ real_h = h + ydraw;
+ buf += (-ydraw) * w;
+ ydraw = 0;
+ } else {
+ real_h = (ydraw + h) > 200 ? (200 - ydraw) : h;
+ }
+ if (xdraw < 0) {
+ real_w = w + xdraw;
+ buf += (-xdraw);
+ xdraw = 0;
+ } else {
+ real_w = (xdraw + w) > 320 ? (320 - xdraw) : w;
+ }
+
+ dst = local_fb + (ydraw * 320) + xdraw;
+ dst2 = dst;
+ bak = old_backup;
+
+ has_mouse = true;
+
+ AddDirtyRec(xdraw, ydraw, real_w, real_h);
+ old_mouse_x = xdraw;
+ old_mouse_y = ydraw;
+ old_mouse_w = real_w;
+ old_mouse_h = real_h;
+
+ real_h_2 = real_h;
+ while (real_h_2 > 0) {
+ memcpy(bak, dst, real_w);
+ bak += BAK_WIDTH;
+ dst += 320;
+ real_h_2--;
+ }
+ while (real_h > 0) {
+ int width = real_w;
+ while (width > 0) {
+ unsigned char color = *buf;
+ if (color != 0xFF) {
+ *dst2 = color;
+ }
+ buf++;
+ dst2++;
+ width--;
+ }
+ buf += w - real_w;
+ dst2 += 320 - real_w;
+ real_h--;
+ }
+ }
}
static unsigned short palette[256];
-static void update_palette(Scumm *s) {
- int first = s->_palDirtyMin;
- int num = s->_palDirtyMax - first + 1;
- int i;
- unsigned char *data = s->_currentPalette;
- unsigned short *pal = &(palette[first]);
-
- data += first*3;
- for (i = 0; i < num; i++, data += 3) {
- *pal++ = ((data[0] & 0xF8) << 8) | ((data[1] & 0xFC) << 3) | (data[2] >> 3);
- }
- s->_palDirtyMax = -1;
- s->_palDirtyMin = 0x3E8;
+static void update_palette(Scumm *s)
+{
+ int first = s->_palDirtyMin;
+ int num = s->_palDirtyMax - first + 1;
+ int i;
+ unsigned char *data = s->_currentPalette;
+ unsigned short *pal = &(palette[first]);
+
+ data += first * 3;
+ for (i = 0; i < num; i++, data += 3) {
+ *pal++ =
+ ((data[0] & 0xF8) << 8) | ((data[1] & 0xFC) << 3) | (data[2] >> 3);
+ }
+ s->_palDirtyMax = -1;
+ s->_palDirtyMin = 0x3E8;
}
-static void update_screen(Scumm *s, const dirty_square *d, dirty_square *dout) {
- int x, y;
- unsigned char *ptr_src = local_fb + (320 * d->y) + d->x;
- unsigned short *ptr_dst = ((unsigned short *) image->data) + (320 * d->y) + d->x;
- for (y = 0; y < d->h; y++) {
- for (x = 0; x < d->w; x++) {
- *ptr_dst++ = palette[*ptr_src++];
- }
- ptr_dst += 320 - d->w;
- ptr_src += 320 - d->w;
- }
- if (d->x < dout->x) dout->x = d->x;
- if (d->y < dout->y) dout->y = d->y;
- if ((d->x + d->w) > dout->w) dout->w = d->x + d->w;
- if ((d->y + d->h) > dout->h) dout->h = d->y + d->h;
+static void update_screen(Scumm *s, const dirty_square * d,
+ dirty_square * dout)
+{
+ int x, y;
+ unsigned char *ptr_src = local_fb + (320 * d->y) + d->x;
+ unsigned short *ptr_dst =
+ ((unsigned short *)image->data) + (320 * d->y) + d->x;
+ for (y = 0; y < d->h; y++) {
+ for (x = 0; x < d->w; x++) {
+ *ptr_dst++ = palette[*ptr_src++];
+ }
+ ptr_dst += 320 - d->w;
+ ptr_src += 320 - d->w;
+ }
+ if (d->x < dout->x)
+ dout->x = d->x;
+ if (d->y < dout->y)
+ dout->y = d->y;
+ if ((d->x + d->w) > dout->w)
+ dout->w = d->x + d->w;
+ if ((d->y + d->h) > dout->h)
+ dout->h = d->y + d->h;
}
-void updateScreen(Scumm *s) {
- bool full_redraw = false;
- bool need_redraw = false;
- static const dirty_square ds_full = { 0, 0, 320, 200 };
- dirty_square dout = {320, 200, 0, 0 };
-
- if (s->_fastMode&2)
- return;
-
- if (hide_mouse) {
- hide_mouse = false;
- s->drawMouse();
- }
+void updateScreen(Scumm *s)
+{
+ bool full_redraw = false;
+ bool need_redraw = false;
+ static const dirty_square ds_full = { 0, 0, 320, 200 };
+ dirty_square dout = { 320, 200, 0, 0 };
- if (s->_palDirtyMax != -1) {
- update_palette(s);
- full_redraw = true;
- num_of_dirty_square = 0;
- } else if (num_of_dirty_square >= MAX_NUMBER_OF_DIRTY_SQUARES) {
- full_redraw = true;
- num_of_dirty_square = 0;
- }
+ if (s->_fastMode & 2)
+ return;
- if (full_redraw) {
- update_screen(s, &ds_full, &dout);
- need_redraw = true;
- } else if (num_of_dirty_square > 0) {
- need_redraw = true;
- while (num_of_dirty_square > 0) {
- num_of_dirty_square--;
- update_screen(s, &(ds[num_of_dirty_square]), &dout);
- }
- }
- if (need_redraw == true) {
- XShmPutImage(display, window, DefaultGC(display, screen), image,
- dout.x, dout.y,
- scumm_x + dout.x, scumm_y + dout.y,
- dout.w - dout.x, dout.h - dout.y,
- 0);
- XFlush(display);
- }
+ if (hide_mouse) {
+ hide_mouse = false;
+ s->drawMouse();
+ }
+
+ if (s->_palDirtyMax != -1) {
+ update_palette(s);
+ full_redraw = true;
+ num_of_dirty_square = 0;
+ } else if (num_of_dirty_square >= MAX_NUMBER_OF_DIRTY_SQUARES) {
+ full_redraw = true;
+ num_of_dirty_square = 0;
+ }
+
+ if (full_redraw) {
+ update_screen(s, &ds_full, &dout);
+ need_redraw = true;
+ } else if (num_of_dirty_square > 0) {
+ need_redraw = true;
+ while (num_of_dirty_square > 0) {
+ num_of_dirty_square--;
+ update_screen(s, &(ds[num_of_dirty_square]), &dout);
+ }
+ }
+ if (need_redraw == true) {
+ XShmPutImage(display, window, DefaultGC(display, screen), image,
+ dout.x, dout.y,
+ scumm_x + dout.x, scumm_y + dout.y,
+ dout.w - dout.x, dout.h - dout.y, 0);
+ XFlush(display);
+ }
}
-void launcherLoop() {
- int last_time, new_time;
- int delta = 0;
- last_time = get_ms_from_start();
-
- gui.launcher();
- while (1) {
- updateScreen(&scumm);
-
- new_time = get_ms_from_start();
- waitForTimer(&scumm, delta * 15 + last_time - new_time);
- last_time = get_ms_from_start();
-
- if (gui._active) {
- gui.loop();
- delta = 5;
- } else {
- error("gui closed!");
- }
- }
+void launcherLoop()
+{
+ int last_time, new_time;
+ int delta = 0;
+ last_time = get_ms_from_start();
+
+ gui.launcher();
+ while (1) {
+ updateScreen(&scumm);
+
+ new_time = get_ms_from_start();
+ waitForTimer(&scumm, delta * 15 + last_time - new_time);
+ last_time = get_ms_from_start();
+
+ if (gui._active) {
+ gui.loop();
+ delta = 5;
+ } else {
+ error("gui closed!");
+ }
+ }
}
/* This function waits for 'msec_delay' miliseconds and handles external events */
-void waitForTimer(Scumm *s, int msec_delay) {
- int start_time = get_ms_from_start();
- int end_time;
- fd_set rfds;
- struct timeval tv;
- XEvent event;
-
- if (s->_fastMode&2)
- msec_delay = 0;
- else if (s->_fastMode&1)
- msec_delay = 10;
- end_time = start_time + msec_delay;
-
-
- while (1) {
- FD_ZERO(&rfds);
- FD_SET(x11_socket, &rfds);
-
- msec_delay = end_time - get_ms_from_start();
- tv.tv_sec = 0;
- if (msec_delay <= 0) {
- tv.tv_usec = 0;
- } else {
- tv.tv_usec = msec_delay * 1000;
- }
- if (select(x11_socket + 1, &rfds, NULL, NULL, &tv) == 0)
- break; /* This is the timeout */
- while (XPending(display)) {
- XNextEvent(display,&event);
- switch (event.type) {
- case Expose: {
- int real_w, real_h;
- int real_x, real_y;
- real_x = event.xexpose.x;
- real_y = event.xexpose.y;
- real_w = event.xexpose.width;
- real_h = event.xexpose.height;
-
- if (real_x < scumm_x) {
- real_w -= scumm_x - real_x;
- real_x = 0;
- } else {
- real_x -= scumm_x;
- }
- if (real_y < scumm_y) {
- real_h -= scumm_y - real_y;
- real_y = 0;
- } else {
- real_y -= scumm_y;
- }
- if ((real_h <= 0) || (real_w <= 0)) break;
- if ((real_x >= 320) || (real_y >= 200)) break;
-
- if ((real_x + real_w) >= 320) {
- real_w = 320 - real_x;
- }
- if ((real_y + real_h) >= 200) {
- real_h = 200 - real_y;
- }
-
- /* Compute the intersection of the expose event with the real ScummVM display zone */
- AddDirtyRec(real_x, real_y, real_w, real_h);
- } break;
-
- case KeyPress:
- switch (event.xkey.keycode) {
- case 132:
- report_presses = 0;
- break;
-
- case 133:
- fake_right_mouse = 1;
- break;
- }
- break;
-
- case KeyRelease:
- /* I am using keycodes here and NOT keysyms to be sure that even if the user
- remaps his iPAQ's keyboard, it will still work.
- */
- switch (event.xkey.keycode) {
- case 9: /* Escape on my PC */
- case 130: /* Calendar on the iPAQ */
- s->_keyPressed = 27;
- break;
-
- case 71: /* F5 on my PC */
- case 128: /* Record on the iPAQ */
- s->_keyPressed = 319;
- break;
-
- case 65: /* Space on my PC */
- case 131: /* Schedule on the iPAQ */
- s->_keyPressed = 32;
- break;
-
- case 132: /* 'Q' on the iPAQ */
- report_presses = 1;
- break;
-
- case 133: /* Arrow on the iPAQ */
- fake_right_mouse = 0;
- break;
-
- default: {
- KeySym xsym;
- xsym = XKeycodeToKeysym(display, event.xkey.keycode, 0);
- if ((xsym >= 'a') && (xsym <= 'z') && (event.xkey.state & 0x01)) xsym &= ~0x20; /* Handle shifted keys */
- s->_keyPressed = xsym;
- }
- }
- break;
-
- case ButtonPress:
- if (report_presses != 0) {
- if (event.xbutton.button == 1) {
- if (fake_right_mouse == 0) {
- s->_leftBtnPressed |= msClicked|msDown;
- } else {
- s->_rightBtnPressed |= msClicked|msDown;
- }
- } else if (event.xbutton.button == 3)
- s->_rightBtnPressed |= msClicked|msDown;
- }
- break;
-
- case ButtonRelease:
- if (report_presses != 0) {
- if (event.xbutton.button == 1) {
- if (fake_right_mouse == 0) {
- s->_leftBtnPressed &= ~msDown;
- } else {
- s->_rightBtnPressed &= ~msDown;
- }
- } else if (event.xbutton.button == 3)
- s->_rightBtnPressed &= ~msDown;
- }
- break;
-
- case MotionNotify: {
- int newx,newy;
- newx = event.xmotion.x - scumm_x;
- newy = event.xmotion.y - scumm_y;
- if ((newx != s->mouse.x) || (newy != s->mouse.y)) {
- s->mouse.x = newx;
- s->mouse.y = newy;
- s->drawMouse();
- updateScreen(s);
- }
- } break;
-
- case ConfigureNotify: {
- if ((window_width != event.xconfigure.width) ||
- (window_height != event.xconfigure.height)) {
- window_width = event.xconfigure.width;
- window_height = event.xconfigure.height;
- scumm_x = (window_width - 320) / 2;
- scumm_y = (window_height - 200) / 2;
- XFillRectangle(display, window, black_gc, 0, 0, window_width, window_height);
- }
- } break;
-
- default:
- printf("%d\n", event.type);
- break;
- }
- }
- }
+void waitForTimer(Scumm *s, int msec_delay)
+{
+ int start_time = get_ms_from_start();
+ int end_time;
+ fd_set rfds;
+ struct timeval tv;
+ XEvent event;
+
+ if (s->_fastMode & 2)
+ msec_delay = 0;
+ else if (s->_fastMode & 1)
+ msec_delay = 10;
+ end_time = start_time + msec_delay;
+
+
+ while (1) {
+ FD_ZERO(&rfds);
+ FD_SET(x11_socket, &rfds);
+
+ msec_delay = end_time - get_ms_from_start();
+ tv.tv_sec = 0;
+ if (msec_delay <= 0) {
+ tv.tv_usec = 0;
+ } else {
+ tv.tv_usec = msec_delay * 1000;
+ }
+ if (select(x11_socket + 1, &rfds, NULL, NULL, &tv) == 0)
+ break; /* This is the timeout */
+ while (XPending(display)) {
+ XNextEvent(display, &event);
+ switch (event.type) {
+ case Expose:{
+ int real_w, real_h;
+ int real_x, real_y;
+ real_x = event.xexpose.x;
+ real_y = event.xexpose.y;
+ real_w = event.xexpose.width;
+ real_h = event.xexpose.height;
+
+ if (real_x < scumm_x) {
+ real_w -= scumm_x - real_x;
+ real_x = 0;
+ } else {
+ real_x -= scumm_x;
+ }
+ if (real_y < scumm_y) {
+ real_h -= scumm_y - real_y;
+ real_y = 0;
+ } else {
+ real_y -= scumm_y;
+ }
+ if ((real_h <= 0) || (real_w <= 0))
+ break;
+ if ((real_x >= 320) || (real_y >= 200))
+ break;
+
+ if ((real_x + real_w) >= 320) {
+ real_w = 320 - real_x;
+ }
+ if ((real_y + real_h) >= 200) {
+ real_h = 200 - real_y;
+ }
+
+ /* Compute the intersection of the expose event with the real ScummVM display zone */
+ AddDirtyRec(real_x, real_y, real_w, real_h);
+ }
+ break;
+
+ case KeyPress:
+ switch (event.xkey.keycode) {
+ case 132:
+ report_presses = 0;
+ break;
+
+ case 133:
+ fake_right_mouse = 1;
+ break;
+ }
+ break;
+
+ case KeyRelease:
+ /* I am using keycodes here and NOT keysyms to be sure that even if the user
+ remaps his iPAQ's keyboard, it will still work.
+ */
+ switch (event.xkey.keycode) {
+ case 9: /* Escape on my PC */
+ case 130: /* Calendar on the iPAQ */
+ s->_keyPressed = 27;
+ break;
+
+ case 71: /* F5 on my PC */
+ case 128: /* Record on the iPAQ */
+ s->_keyPressed = 319;
+ break;
+
+ case 65: /* Space on my PC */
+ case 131: /* Schedule on the iPAQ */
+ s->_keyPressed = 32;
+ break;
+
+ case 132: /* 'Q' on the iPAQ */
+ report_presses = 1;
+ break;
+
+ case 133: /* Arrow on the iPAQ */
+ fake_right_mouse = 0;
+ break;
+
+ default:{
+ KeySym xsym;
+ xsym = XKeycodeToKeysym(display, event.xkey.keycode, 0);
+ if ((xsym >= 'a') && (xsym <= 'z') && (event.xkey.state & 0x01))
+ xsym &= ~0x20; /* Handle shifted keys */
+ s->_keyPressed = xsym;
+ }
+ }
+ break;
+
+ case ButtonPress:
+ if (report_presses != 0) {
+ if (event.xbutton.button == 1) {
+ if (fake_right_mouse == 0) {
+ s->_leftBtnPressed |= msClicked | msDown;
+ } else {
+ s->_rightBtnPressed |= msClicked | msDown;
+ }
+ } else if (event.xbutton.button == 3)
+ s->_rightBtnPressed |= msClicked | msDown;
+ }
+ break;
+
+ case ButtonRelease:
+ if (report_presses != 0) {
+ if (event.xbutton.button == 1) {
+ if (fake_right_mouse == 0) {
+ s->_leftBtnPressed &= ~msDown;
+ } else {
+ s->_rightBtnPressed &= ~msDown;
+ }
+ } else if (event.xbutton.button == 3)
+ s->_rightBtnPressed &= ~msDown;
+ }
+ break;
+
+ case MotionNotify:{
+ int newx, newy;
+ newx = event.xmotion.x - scumm_x;
+ newy = event.xmotion.y - scumm_y;
+ if ((newx != s->mouse.x) || (newy != s->mouse.y)) {
+ s->mouse.x = newx;
+ s->mouse.y = newy;
+ s->drawMouse();
+ updateScreen(s);
+ }
+ }
+ break;
+
+ case ConfigureNotify:{
+ if ((window_width != event.xconfigure.width) ||
+ (window_height != event.xconfigure.height)) {
+ window_width = event.xconfigure.width;
+ window_height = event.xconfigure.height;
+ scumm_x = (window_width - 320) / 2;
+ scumm_y = (window_height - 200) / 2;
+ XFillRectangle(display, window, black_gc, 0, 0, window_width,
+ window_height);
+ }
+ }
+ break;
+
+ default:
+ printf("%d\n", event.type);
+ break;
+ }
+ }
+ }
}
/* Main function for the system-dependent part. Needs to handle :
@@ -783,36 +824,37 @@ void waitForTimer(Scumm *s, int msec_delay) {
- initialize all the 'globals' (sound driver, Scumm object, ...)
- do the main loop of the game
*/
-int main(int argc, char* argv[]) {
- int delta;
- int last_time, new_time;
-
- scumm._gui = &gui;
- gui.init(&scumm);
- sound.initialize(&scumm, &snd_driv);
- scumm.scummMain(argc, argv);
- gui.init(&scumm); /* Reinit GUI after loading a game */
-
- num_of_dirty_square = 0;
-
- /* Start the milisecond counter */
- init_timer();
- last_time = 0;
- delta = 0;
- while (1) {
- updateScreen(&scumm);
-
- new_time = get_ms_from_start();
- waitForTimer(&scumm, delta * 15 + last_time - new_time);
- last_time = get_ms_from_start();
-
- if (gui._active) {
- gui.loop();
- delta = 5;
- } else {
- delta = scumm.scummLoop(delta);
- }
- }
-
- return 0;
+int main(int argc, char *argv[])
+{
+ int delta;
+ int last_time, new_time;
+
+ scumm._gui = &gui;
+ gui.init(&scumm);
+ sound.initialize(&scumm, &snd_driv);
+ scumm.scummMain(argc, argv);
+ gui.init(&scumm); /* Reinit GUI after loading a game */
+
+ num_of_dirty_square = 0;
+
+ /* Start the milisecond counter */
+ init_timer();
+ last_time = 0;
+ delta = 0;
+ while (1) {
+ updateScreen(&scumm);
+
+ new_time = get_ms_from_start();
+ waitForTimer(&scumm, delta * 15 + last_time - new_time);
+ last_time = get_ms_from_start();
+
+ if (gui._active) {
+ gui.loop();
+ delta = 5;
+ } else {
+ delta = scumm.scummLoop(delta);
+ }
+ }
+
+ return 0;
}