diff options
Diffstat (limited to 'engines/cruise')
57 files changed, 10094 insertions, 10541 deletions
diff --git a/engines/cruise/actor.cpp b/engines/cruise/actor.cpp index 2e953b72df..29c818d15f 100644 --- a/engines/cruise/actor.cpp +++ b/engines/cruise/actor.cpp @@ -26,90 +26,85 @@ namespace Cruise { -int16 mainProc13(int overlayIdx, int param1, actorStruct* pStartEntry, int param2) -{ - actorStruct* pCurrentEntry = pStartEntry->next; - - while(pCurrentEntry) - { - if( (pCurrentEntry->overlayNumber == overlayIdx || overlayIdx == -1) && - (pCurrentEntry->idx == param1 || param1 == -1) && - (pCurrentEntry->type == param2 || param2 == -1) && - (pCurrentEntry->pathId != -2)) - { - return 0; +int16 mainProc13(int overlayIdx, int param1, actorStruct *pStartEntry, + int param2) { + actorStruct *pCurrentEntry = pStartEntry->next; + + while (pCurrentEntry) { + if ((pCurrentEntry->overlayNumber == overlayIdx + || overlayIdx == -1) && (pCurrentEntry->idx == param1 + || param1 == -1) && (pCurrentEntry->type == param2 + || param2 == -1) && (pCurrentEntry->pathId != -2)) { + return 0; + } + + pCurrentEntry = pCurrentEntry->next; } - - pCurrentEntry = pCurrentEntry->next; - } - return 1; + return 1; } -actorStruct* findActor(int overlayIdx, int param1, actorStruct* pStartEntry, int param2) -{ - actorStruct* pCurrentEntry = pStartEntry->next; +actorStruct *findActor(int overlayIdx, int param1, actorStruct *pStartEntry, + int param2) { + actorStruct *pCurrentEntry = pStartEntry->next; - while(pCurrentEntry) - { - if( (pCurrentEntry->overlayNumber == overlayIdx || overlayIdx == -1) && - (pCurrentEntry->idx == param1 || param1 == -1) && - (pCurrentEntry->type == param2 || param2 == -1) ) - { - return pCurrentEntry; + while (pCurrentEntry) { + if ((pCurrentEntry->overlayNumber == overlayIdx + || overlayIdx == -1) && (pCurrentEntry->idx == param1 + || param1 == -1) && (pCurrentEntry->type == param2 + || param2 == -1)) { + return pCurrentEntry; + } + + pCurrentEntry = pCurrentEntry->next; } - - pCurrentEntry = pCurrentEntry->next; - } - return NULL; + return NULL; } int nclick_noeud; int flag_aff_chemin; -void getPixel(int x, int y) -{ - int x_min, x_max, y_min, y_max; +void getPixel(int x, int y) { + int x_min, x_max, y_min, y_max; - ctpVar19Struct *polygone; - ctpVar19SubStruct *tableau; + ctpVar19Struct *polygone; + ctpVar19SubStruct *tableau; - polygone = ctpVar19; /* adr structure polygone */ + polygone = ctpVar19; /* adr structure polygone */ - while ( polygone->field_0 != (ctpVar19Struct*)-1) - { - tableau = &polygone->subStruct; + while (polygone->field_0 != (ctpVar19Struct *) - 1) { + tableau = &polygone->subStruct; - x_min = tableau->minX; - x_max = tableau->maxX; - y_min = tableau->minY; - y_max = tableau->maxY; + x_min = tableau->minX; + x_max = tableau->maxX; + y_min = tableau->minY; + y_max = tableau->maxY; - computedVar14 = tableau->boxIdx; /* numero polygone */ + computedVar14 = tableau->boxIdx; /* numero polygone */ - if ( walkboxChange[computedVar14]==0 && ((x>=x_min && x<=x_max) && (y>=y_min && y<=y_max)) ) - { - // click was in given box - /* u = y-y_min; - - //tableau+=u; - tableau = &polygone[u].subStruct; - - x_min = tableau->minX; - x_max = tableau->maxX; - - if ( (x>=x_min && x<=x_max) ) */ - { - flag_obstacle=walkboxType[computedVar14]; /* sa couleur */ + if (walkboxChange[computedVar14] == 0 && ((x >= x_min + && x <= x_max) && (y >= y_min && y <= y_max))) { + // click was in given box + /* u = y-y_min; + * + * //tableau+=u; + * tableau = &polygone[u].subStruct; + * + * x_min = tableau->minX; + * x_max = tableau->maxX; + * + * if ( (x>=x_min && x<=x_max) ) */ + { + flag_obstacle = walkboxType[computedVar14]; /* sa couleur */ - return; - } + return; + } + } + polygone = polygone->field_0; } - polygone = polygone->field_0; - } - flag_obstacle=0; + flag_obstacle = 0; } int x_mouse; @@ -125,281 +120,249 @@ int Y; int modelVar9; int modelVar10; -void polydroite(int x1, int y1, int x2, int y2) -{ - int dx; - int dy; - - int mD0; - int mD1; +void polydroite(int x1, int y1, int x2, int y2) { + int dx; + int dy; - int mA0; - int mA1; + int mD0; + int mD1; - int bp; - int cx; - int si; + int mA0; + int mA1; - int ax; - int bx; + int bp; + int cx; + int si; - modelVar9 = x1; - modelVar10 = y1; + int ax; + int bx; - dx = x2-x1; - dy = y2-y1; + modelVar9 = x1; + modelVar10 = y1; - mD0 = mD1 = 1; + dx = x2 - x1; + dy = y2 - y1; - if(dx<0) - { - dx = -dx; - mD0 = -1; - } + mD0 = mD1 = 1; - if(dy<0) - { - dy = -dy; - mD1 = -1; - } + if (dx < 0) { + dx = -dx; + mD0 = -1; + } - if(dx<dy) - { - mA0 = 0; - bp = dx; - cx = dy; + if (dy < 0) { + dy = -dy; + mD1 = -1; + } - mA1 = mD1; - } - else - { - mA1 = 0; - bp = dy; - cx = dx; + if (dx < dy) { + mA0 = 0; + bp = dx; + cx = dy; - mA0 = mD0; - } + mA1 = mD1; + } else { + mA1 = 0; + bp = dy; + cx = dx; - bp=bp*2; - dx=bp-cx; - si=dx-cx; + mA0 = mD0; + } - ax = modelVar9; - bx = modelVar10; + bp = bp * 2; + dx = bp - cx; + si = dx - cx; - getPixel(modelVar9, modelVar10); + ax = modelVar9; + bx = modelVar10; - X = modelVar9; - Y = modelVar10; + getPixel(modelVar9, modelVar10); - if(flag_obstacle==0) - { - flag_obstacle = 1; - return; - } + X = modelVar9; + Y = modelVar10; - while(--cx) - { - if(dx>0) - { - ax+=mD0; - bx+=mD1; - dx+=si; - } - else - { - ax+=mA0; - bx+=mA1; - dx+=bp; + if (flag_obstacle == 0) { + flag_obstacle = 1; + return; } - getPixel(ax, bx); + while (--cx) { + if (dx > 0) { + ax += mD0; + bx += mD1; + dx += si; + } else { + ax += mA0; + bx += mA1; + dx += bp; + } - X = ax; - Y = bx; + getPixel(ax, bx); - if(flag_obstacle==0) - { - flag_obstacle = 1; - return; + X = ax; + Y = bx; + + if (flag_obstacle == 0) { + flag_obstacle = 1; + return; + } } - } - flag_obstacle = 0; + flag_obstacle = 0; } -void poly2(int x1, int y1, int x2, int y2) -{ - int dx; - int dy; +void poly2(int x1, int y1, int x2, int y2) { + int dx; + int dy; - int mD0; - int mD1; + int mD0; + int mD1; - int mA0; - int mA1; + int mA0; + int mA1; - int bp; - int cx; - int si; + int bp; + int cx; + int si; - int ax; - int bx; + int ax; + int bx; - modelVar9 = x1; - modelVar10 = y1; + modelVar9 = x1; + modelVar10 = y1; - dx = x2-x1; - dy = y2-y1; + dx = x2 - x1; + dy = y2 - y1; - mD0 = mD1 = 1; + mD0 = mD1 = 1; - if(dx<0) - { - dx = -dx; - mD0 = -1; - } - - if(dy<0) - { - dy = -dy; - mD1 = -1; - } + if (dx < 0) { + dx = -dx; + mD0 = -1; + } - if(dx<dy) - { - mA0 = 0; - bp = dx; - cx = dy; + if (dy < 0) { + dy = -dy; + mD1 = -1; + } - mA1 = mD1; - } - else - { - mA1 = 0; - bp = dy; - cx = dx; + if (dx < dy) { + mA0 = 0; + bp = dx; + cx = dy; - mA0 = mD0; - } + mA1 = mD1; + } else { + mA1 = 0; + bp = dy; + cx = dx; - bp=bp*2; - dx=bp-cx; - si=dx-cx; + mA0 = mD0; + } - ax = modelVar9; - bx = modelVar10; + bp = bp * 2; + dx = bp - cx; + si = dx - cx; - getPixel(modelVar9, modelVar10); + ax = modelVar9; + bx = modelVar10; - X = modelVar9; - Y = modelVar10; + getPixel(modelVar9, modelVar10); - if(flag_obstacle!=0) - { - flag_obstacle = 1; - return; - } + X = modelVar9; + Y = modelVar10; - while(--cx) - { - if(dx>0) - { - ax+=mD0; - bx+=mD1; - dx+=si; - } - else - { - ax+=mA0; - bx+=mA1; - dx+=bp; + if (flag_obstacle != 0) { + flag_obstacle = 1; + return; } - getPixel(ax, bx); + while (--cx) { + if (dx > 0) { + ax += mD0; + bx += mD1; + dx += si; + } else { + ax += mA0; + bx += mA1; + dx += bp; + } + + getPixel(ax, bx); - X = ax; - Y = bx; + X = ax; + Y = bx; - if(flag_obstacle!=0) - { - flag_obstacle = 1; - return; + if (flag_obstacle != 0) { + flag_obstacle = 1; + return; + } } - } - flag_obstacle = 0; + flag_obstacle = 0; } -int point_proche( int16 table[][2] ) -{ - int x1, y1, i, x, y, p; - int d1=1000; +int point_proche(int16 table[][2]) { + int x1, y1, i, x, y, p; + int d1 = 1000; + + ctpVar19 = ctpVar11; - ctpVar19 = ctpVar11; + if (nclick_noeud == 1) { + x = x_mouse; + y = y_mouse; + x1 = table_ptselect[0][0]; + y1 = table_ptselect[0][1]; - if ( nclick_noeud == 1 ) - { - x = x_mouse; - y = y_mouse; - x1 = table_ptselect[0][0]; - y1 = table_ptselect[0][1]; + ctpVar19 = ctpVar15; - ctpVar19 = ctpVar15; + getPixel(x, y); - getPixel( x, y ); + if (!flag_obstacle) { + ctpVar19 = ctpVar11; - if ( !flag_obstacle ) - { - ctpVar19 = ctpVar11; + getPixel(x, y); + + if (flag_obstacle) { + polydroite(x1, y1, x, y); + } + ctpVar19 = ctpVar15; + } + if (!flag_obstacle) { /* dans flag_obstacle --> couleur du point */ + x1 = table_ptselect[0][0]; + y1 = table_ptselect[0][1]; - getPixel( x, y ); + poly2(x, y, x1, y1); - if ( flag_obstacle ) - { - polydroite( x1, y1, x, y ); - } - ctpVar19 = ctpVar15; + x_mouse = X; + y_mouse = Y; + } } - if ( !flag_obstacle ) /* dans flag_obstacle --> couleur du point */ - { - x1 = table_ptselect[0][0]; - y1 = table_ptselect[0][1]; - - poly2( x, y, x1, y1 ); - - x_mouse = X; - y_mouse = Y; - } - } - ctpVar19 = ctpVar11; - - p = -1; - for ( i=0; i < ctp_routeCoordCount; i++ ) - { - x = table[i][0]; - y = table[i][1]; - - ctpProc2( x_mouse, y_mouse, x, y ); - if ( ctpVar14 < d1 ) - { - polydroite( x_mouse, y_mouse, x, y ); + ctpVar19 = ctpVar11; - if ( !flag_obstacle && ctp_routes[i][0] > 0 ) - { - d1 = ctpVar14; - p = i; - } + p = -1; + for (i = 0; i < ctp_routeCoordCount; i++) { + x = table[i][0]; + y = table[i][1]; + + ctpProc2(x_mouse, y_mouse, x, y); + if (ctpVar14 < d1) { + polydroite(x_mouse, y_mouse, x, y); + + if (!flag_obstacle && ctp_routes[i][0] > 0) { + d1 = ctpVar14; + p = i; + } + } } - } - return ( p ); + return (p); } #define NBNOEUD 20 int16 select_noeud[3]; -char solution[20+1]; +char solution[20 + 1]; int prem; int prem2; @@ -407,77 +370,66 @@ int dist_chemin; int idsol; int solmax; -char fl[NBNOEUD+1]; -char sol[NBNOEUD+1]; -char Fsol[NBNOEUD+1]; +char fl[NBNOEUD + 1]; +char sol[NBNOEUD + 1]; +char Fsol[NBNOEUD + 1]; int D; -void explore( int depart, int arrivee ) -{ - int id1, id2, i; +void explore(int depart, int arrivee) { + int id1, id2, i; id1 = depart; fl[id1]++; sol[idsol++] = (char)id1; - if ( idsol > solmax ) - { - fl[id1]=-1; + if (idsol > solmax) { + fl[id1] = -1; idsol--; return; } - while ( (i=fl[id1]) < 20 ) - { - id2 = ctp_routes[id1][i+1]; + while ((i = fl[id1]) < 20) { + id2 = ctp_routes[id1][i + 1]; - if ( id2 == arrivee ) - { - if ( idsol < solmax ) - { + if (id2 == arrivee) { + if (idsol < solmax) { sol[idsol] = (char)arrivee; - D=0; - for ( i=0; i < idsol; i++ ) - { - D = D+ctp_routeCoords[(int)sol[i]][(int)sol[i+1]]; - Fsol[i]=sol[i]; + D = 0; + for (i = 0; i < idsol; i++) { + D = D + + ctp_routeCoords[(int)sol[i]][(int) + sol[i + 1]]; + Fsol[i] = sol[i]; } - prem2=0; - if (!prem) - { + prem2 = 0; + if (!prem) { dist_chemin = D; prem = 1; - for ( i=0; i <= idsol; i++ ) - { + for (i = 0; i <= idsol; i++) { solution[i] = sol[i]; } - solution[i++]=-1; - solution[i]=-1; - } - else if ( D < dist_chemin ) - { + solution[i++] = -1; + solution[i] = -1; + } else if (D < dist_chemin) { dist_chemin = D; - for ( i=0; i <= idsol; i++ ) - { + for (i = 0; i <= idsol; i++) { solution[i] = sol[i]; } - solution[i++]=-1; - solution[i]=-1; + solution[i++] = -1; + solution[i] = -1; } } - fl[id1]=-1; + fl[id1] = -1; idsol--; return; - } - else if ((id2!=-1) && ((int)fl[id2]==-1) ) - explore(id2,arrivee); - else if (id2==-1) - { - fl[id1]=-1; + } else if ((id2 != -1) && ((int)fl[id2] == -1)) + explore(id2, arrivee); + else if (id2 == -1) { + fl[id1] = -1; idsol--; return; @@ -485,598 +437,737 @@ void explore( int depart, int arrivee ) fl[id1]++; } - fl[id1]=-1; + fl[id1] = -1; idsol--; } -void chemin0( int depart, int arrivee ) -{ - int i; - //int y=30; - - prem = 0; +void chemin0(int depart, int arrivee) { + int i; + //int y=30; + + prem = 0; prem2 = 0; - dist_chemin=0; + dist_chemin = 0; idsol = 0; - solmax=999; + solmax = 999; - for ( i=0; i < 20+1; i++ ) fl[i] = -1; + for (i = 0; i < 20 + 1; i++) + fl[i] = -1; - X=0,Y=30; + X = 0, Y = 30; - explore( depart, arrivee ); + explore(depart, arrivee); } -void valide_noeud( int16 table[], int16 p, int *nclick, int16 solution0[20+3][2] ) -{ - int a, b, d, i, p1, x1, x2, y1, y2; - //int y=30; +void valide_noeud(int16 table[], int16 p, int *nclick, int16 solution0[20 + 3][2]) { + int a, b, d, i, p1, x1, x2, y1, y2; + //int y=30; - table[*nclick]=p; - table[(*nclick)+1]=-1; - table_ptselect[*nclick][0]=x_mouse; - table_ptselect[*nclick][1]=y_mouse; + table[*nclick] = p; + table[(*nclick) + 1] = -1; + table_ptselect[*nclick][0] = x_mouse; + table_ptselect[*nclick][1] = y_mouse; (*nclick)++; - ctpVar19=ctpVar11; + ctpVar19 = ctpVar11; - if (*nclick==2) // second point + if (*nclick == 2) // second point { - x1=table_ptselect[0][0]; - y1=table_ptselect[0][1]; - x2=table_ptselect[1][0]; - y2=table_ptselect[1][1]; - if ( (x1==x2) && (y1==y2)) - { + x1 = table_ptselect[0][0]; + y1 = table_ptselect[0][1]; + x2 = table_ptselect[1][0]; + y2 = table_ptselect[1][1]; + if ((x1 == x2) && (y1 == y2)) { return; } - flag_aff_chemin=1; - ctpVar19=ctpVar15; - - // can we go there directly ? - polydroite(x1,y1,x2,y2); - //////////////// - flag_obstacle = 0; - //////////////// - if (!flag_obstacle) - { - solution0[0][0]=x1; - solution0[0][1]=y1; - ctpVar19=ctpVar15; - - poly2(x2,y2,ctp_routeCoords[select_noeud[1]][0],ctp_routeCoords[select_noeud[1]][1]); - - solution0[1][0]=table_ptselect[1][0]=X; - solution0[1][1]=table_ptselect[1][1]=Y; - solution0[2][0]=-1; - - if ( (x1==X) && (y1==Y)) - { - flag_aff_chemin=0; + flag_aff_chemin = 1; + ctpVar19 = ctpVar15; + + // can we go there directly ? + polydroite(x1, y1, x2, y2); + //////////////// + flag_obstacle = 0; + //////////////// + if (!flag_obstacle) { + solution0[0][0] = x1; + solution0[0][1] = y1; + ctpVar19 = ctpVar15; + + poly2(x2, y2, ctp_routeCoords[select_noeud[1]][0], + ctp_routeCoords[select_noeud[1]][1]); + + solution0[1][0] = table_ptselect[1][0] = X; + solution0[1][1] = table_ptselect[1][1] = Y; + solution0[2][0] = -1; + + if ((x1 == X) && (y1 == Y)) { + flag_aff_chemin = 0; return; } - } - else - { - // no, we take the fastest way - solution[0]=-1; - if (ctp_routes[select_noeud[0]][0]>0) - chemin0(table[0],table[1]); - - if (solution[0]==-1) - { - x1=table_ptselect[0][0]; - y1=table_ptselect[0][1]; - polydroite(x1,y1,x_mouse,y_mouse); - solution0[0][0]=x1; - solution0[0][1]=y1; - solution0[1][0]=X; - solution0[1][1]=Y; - - solution0[2][0]=-1; - if ( (x1==X) && (y1==Y)) - { - flag_aff_chemin=0; + } else { + // no, we take the fastest way + solution[0] = -1; + if (ctp_routes[select_noeud[0]][0] > 0) + chemin0(table[0], table[1]); + + if (solution[0] == -1) { + x1 = table_ptselect[0][0]; + y1 = table_ptselect[0][1]; + polydroite(x1, y1, x_mouse, y_mouse); + solution0[0][0] = x1; + solution0[0][1] = y1; + solution0[1][0] = X; + solution0[1][1] = Y; + + solution0[2][0] = -1; + if ((x1 == X) && (y1 == Y)) { + flag_aff_chemin = 0; return; } - } - else - { - solution0[0][0]=x1; - solution0[0][1]=y1; - i=0; - while (solution[i]!=-1) - { - p1=solution[i]; - solution0[i+1][0]=ctp_routeCoords[p1][0]; - solution0[++i][1]=ctp_routeCoords[p1][1]; + } else { + solution0[0][0] = x1; + solution0[0][1] = y1; + i = 0; + while (solution[i] != -1) { + p1 = solution[i]; + solution0[i + 1][0] = + ctp_routeCoords[p1][0]; + solution0[++i][1] = + ctp_routeCoords[p1][1]; } - ctpVar19=ctpVar15; - poly2(x2,y2,ctp_routeCoords[select_noeud[1]][0],ctp_routeCoords[select_noeud[1]][1]); - solution0[i+1][0]=table_ptselect[1][0]=X; - solution0[i+1][1]=table_ptselect[1][1]=Y; - solution0[i+2][0]=-1; - if ( (x1==X) && (y1==Y)) - { - flag_aff_chemin=0; + ctpVar19 = ctpVar15; + poly2(x2, y2, + ctp_routeCoords[select_noeud[1]][0], + ctp_routeCoords[select_noeud[1]][1]); + solution0[i + 1][0] = table_ptselect[1][0] = X; + solution0[i + 1][1] = table_ptselect[1][1] = Y; + solution0[i + 2][0] = -1; + if ((x1 == X) && (y1 == Y)) { + flag_aff_chemin = 0; return; } - /****** COUPE LE CHEMIN ******/ + /****** COUPE LE CHEMIN ******/ i++; - d=0; - a=i; - flag_obstacle=1; - while (d!=a) - { - x1=solution0[d][0]; - y1=solution0[d][1]; - - while (flag_obstacle && i!=d) - { - x2=solution0[i][0]; - y2=solution0[i][1]; - ctpVar19=ctpVar15; - polydroite(x1,y1,x2,y2); + d = 0; + a = i; + flag_obstacle = 1; + while (d != a) { + x1 = solution0[d][0]; + y1 = solution0[d][1]; + + while (flag_obstacle && i != d) { + x2 = solution0[i][0]; + y2 = solution0[i][1]; + ctpVar19 = ctpVar15; + polydroite(x1, y1, x2, y2); i--; } - flag_obstacle=1; - if (d!=i) - { + flag_obstacle = 1; + if (d != i) { i++; - for (b=d+1;b<i;b++) - { - solution0[b][0]=-2; + for (b = d + 1; b < i; b++) { + solution0[b][0] = -2; } - } - else i++; - d=i; - i=a; - } - flag_obstacle=0; + } else + i++; + d = i; + i = a; + } + flag_obstacle = 0; } } } } //computePathfinding(returnVar2, params.X, params.Y, var34, var35, currentActor->stepX, currentActor->stepY); -int16 computePathfinding(int16* pSolution, int16 _X, int16 _Y, int16 destX, int16 destY, int16 stepX, int16 stepY, int16 oldPathId) -{ - persoStruct* perso; - int num; - - if(!polyStruct) - { - pSolution[0] = -1; - pSolution[1] = -1; - - return -1; - } - - if(oldPathId >= 0) - { - if(persoTable[oldPathId]) - { - freePerso(oldPathId); - } - } +int16 computePathfinding(int16 *pSolution, int16 _X, int16 _Y, int16 destX, + int16 destY, int16 stepX, int16 stepY, int16 oldPathId) { + persoStruct *perso; + int num; - if(!flagCt) - { - int i; - int16* ptr; + if (!polyStruct) { + pSolution[0] = -1; + pSolution[1] = -1; - for(i=0;i<10;i++) // 10 = num perso - { - if(!persoTable[i]) - { - break; - } + return -1; } - if(i == 10) - { - pSolution[0] = -1; - pSolution[1] = -1; - - return -1; + if (oldPathId >= 0) { + if (persoTable[oldPathId]) { + freePerso(oldPathId); + } } - perso = persoTable[i] = (persoStruct*)malloc(sizeof(persoStruct)); + if (!flagCt) { + int i; + int16 *ptr; - ptr = perso->solution[0]; + for (i = 0; i < 10; i++) // 10 = num perso + { + if (!persoTable[i]) { + break; + } + } - perso->inc_jo1 = stepX; - perso->inc_jo2 = stepY; + if (i == 10) { + pSolution[0] = -1; + pSolution[1] = -1; - *(ptr++) = _X; - *(ptr++) = _Y; - *(ptr++) = pSolution[0] = destX; - *(ptr++) = pSolution[1] = destY; - *(ptr++) = -1; + return -1; + } - pSolution[4] = computedVar14; + perso = persoTable[i] = + (persoStruct *) malloc(sizeof(persoStruct)); - perso->inc_droite = 0; - perso->inc_chemin = 0; + ptr = perso->solution[0]; - return i; - } + perso->inc_jo1 = stepX; + perso->inc_jo2 = stepY; - nclick_noeud=0; - ctpVar19=ctpVar11; - flag_aff_chemin=0; + *(ptr++) = _X; + *(ptr++) = _Y; + *(ptr++) = pSolution[0] = destX; + *(ptr++) = pSolution[1] = destY; + *(ptr++) = -1; - if (_X==destX && _Y==destY) - { - pSolution[0]=-1; - pSolution[1]=-1; + pSolution[4] = computedVar14; + + perso->inc_droite = 0; + perso->inc_chemin = 0; + + return i; + } + + nclick_noeud = 0; + ctpVar19 = ctpVar11; + flag_aff_chemin = 0; - return(-1); + if (_X == destX && _Y == destY) { + pSolution[0] = -1; + pSolution[1] = -1; + + return (-1); } /******* cherche le premier noeud ******/ - getPixel(_X,_Y); + getPixel(_X, _Y); - pSolution[4] = computedVar14; + pSolution[4] = computedVar14; - x_mouse = _X; - y_mouse = _Y; + x_mouse = _X; + y_mouse = _Y; - if (!flag_obstacle || (point_select=point_proche(ctp_routeCoords))==-1) - { - pSolution[0]=-1; - pSolution[1]=-1; + if (!flag_obstacle + || (point_select = point_proche(ctp_routeCoords)) == -1) { + pSolution[0] = -1; + pSolution[1] = -1; - return(-1); + return (-1); } - valide_noeud(select_noeud,point_select,&nclick_noeud,NULL); + valide_noeud(select_noeud, point_select, &nclick_noeud, NULL); - flag_aff_chemin=0; + flag_aff_chemin = 0; /******* cherche le deuxieme noeud ******/ - num=0; - while ( num < 10 && persoTable[num] != NULL ) num++; + num = 0; + while (num < 10 && persoTable[num] != NULL) + num++; - if (num==10) - { - pSolution[0]=-1; - pSolution[1]=-1; - return(-1); + if (num == 10) { + pSolution[0] = -1; + pSolution[1] = -1; + return (-1); } - - perso = persoTable[num] = (persoStruct*)malloc(sizeof(persoStruct)); - perso->inc_jo1 = stepX; - perso->inc_jo2 = stepY; + perso = persoTable[num] = (persoStruct *) malloc(sizeof(persoStruct)); + + perso->inc_jo1 = stepX; + perso->inc_jo2 = stepY; - x_mouse = destX; - y_mouse = destY; + x_mouse = destX; + y_mouse = destY; - if((point_select=point_proche(ctp_routeCoords))!=-1) - valide_noeud(select_noeud,point_select,&nclick_noeud,perso->solution); + if ((point_select = point_proche(ctp_routeCoords)) != -1) + valide_noeud(select_noeud, point_select, &nclick_noeud, + perso->solution); - if ( (!flag_aff_chemin) || ((table_ptselect[0][0]==table_ptselect[1][0]) && (table_ptselect[0][1]==table_ptselect[1][1]) )) - { - pSolution[0]=-1; - pSolution[1]=-1; + if ((!flag_aff_chemin) + || ((table_ptselect[0][0] == table_ptselect[1][0]) + && (table_ptselect[0][1] == table_ptselect[1][1]))) { + pSolution[0] = -1; + pSolution[1] = -1; freePerso(num); - return(-1); + return (-1); } - - pSolution[0]=table_ptselect[1][0]; - pSolution[1]=table_ptselect[1][1]; - pSolution[4]=computedVar14; - perso->inc_chemin=0; - perso->inc_droite=0; + + pSolution[0] = table_ptselect[1][0]; + pSolution[1] = table_ptselect[1][1]; + pSolution[4] = computedVar14; + perso->inc_chemin = 0; + perso->inc_droite = 0; return (num); } -void set_anim( int ovl, int obj, int start, int x, int y, int mat, int state ) -{ - int newf, zoom; +void set_anim(int ovl, int obj, int start, int x, int y, int mat, int state) { + int newf, zoom; - newf = abs(mat)-1; + newf = abs(mat) - 1; zoom = computeZoom(y); - if (mat<0) zoom=-zoom; - - setObjectPosition(ovl,obj,0, x); - setObjectPosition(ovl,obj,1, y); - setObjectPosition(ovl,obj,2, y); - setObjectPosition(ovl,obj,4, zoom); - setObjectPosition(ovl,obj,3, newf+start); - setObjectPosition(ovl,obj,5, state); + if (mat < 0) + zoom = -zoom; + + setObjectPosition(ovl, obj, 0, x); + setObjectPosition(ovl, obj, 1, y); + setObjectPosition(ovl, obj, 2, y); + setObjectPosition(ovl, obj, 4, zoom); + setObjectPosition(ovl, obj, 3, newf + start); + setObjectPosition(ovl, obj, 5, state); } -int raoul_move[][13] = -{ - { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0 }, /* dos */ - { 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 0 }, /* droite */ - { 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 0 }, /* face */ - {-13,-14,-15,-16,-17,-18,-19,-20,-21,-22,-23,-24, 0 } /* gauche */ +int raoul_move[][13] = { + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0}, /* dos */ + {13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 0}, /* droite */ + {25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 0}, /* face */ + {-13, -14, -15, -16, -17, -18, -19, -20, -21, -22, -23, -24, 0} /* gauche */ }; -int raoul_end[][13] = -{ - { 37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* stat dos */ - { 38, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* stat droite */ - { 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* stat face */ - {-38, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } /* stat gauche */ +int raoul_end[][13] = { + {37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* stat dos */ + {38, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* stat droite */ + {39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* stat face */ + {-38, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} /* stat gauche */ }; -int raoul_stat[][13]= -{ - { 53, 54, 55, 56, 57, 0, 0, 0, 0, 0, 0, 0, 0 }, /* ret dos-dr */ - { 59, 60, 62, 63, 78, 0, 0, 0, 0, 0, 0, 0, 0 }, /* ret dr-face */ - {-78,-63,-62,-60,-59, 0, 0, 0, 0, 0, 0, 0, 0 }, /* ret face-ga */ - {-57,-56,-55,-54,-53, 0, 0, 0, 0, 0, 0, 0, 0 } /* ret ga-dos */ +int raoul_stat[][13] = { + {53, 54, 55, 56, 57, 0, 0, 0, 0, 0, 0, 0, 0}, /* ret dos-dr */ + {59, 60, 62, 63, 78, 0, 0, 0, 0, 0, 0, 0, 0}, /* ret dr-face */ + {-78, -63, -62, -60, -59, 0, 0, 0, 0, 0, 0, 0, 0}, /* ret face-ga */ + {-57, -56, -55, -54, -53, 0, 0, 0, 0, 0, 0, 0, 0} /* ret ga-dos */ }; -int raoul_invstat[][13]= -{ - {-53,-54,-55,-56,-57, 0, 0, 0, 0, 0, 0, 0, 0 }, /* ret dos-dr */ - { 57, 56, 55, 54, 53, 0, 0, 0, 0, 0, 0, 0, 0 }, /* ret ga-dos */ - { 78, 63, 62, 60, 59, 0, 0, 0, 0, 0, 0, 0, 0 }, /* ret face-ga */ - {-59,-60,-62,-63,-78, 0, 0, 0, 0, 0, 0, 0, 0 } /* ret dr-face */ +int raoul_invstat[][13] = { + {-53, -54, -55, -56, -57, 0, 0, 0, 0, 0, 0, 0, 0}, /* ret dos-dr */ + {57, 56, 55, 54, 53, 0, 0, 0, 0, 0, 0, 0, 0}, /* ret ga-dos */ + {78, 63, 62, 60, 59, 0, 0, 0, 0, 0, 0, 0, 0}, /* ret face-ga */ + {-59, -60, -62, -63, -78, 0, 0, 0, 0, 0, 0, 0, 0} /* ret dr-face */ }; -void processAnimation(void) -{ - objectParamsQuery params; - int16 returnVar2[5]; - actorStruct* currentActor = &actorHead; - actorStruct* nextActor; - - while(currentActor) - { - nextActor = currentActor->next; - - if(!currentActor->freeze && ((currentActor->type == 0) || (currentActor->type == 1))) - { - getMultipleObjectParam(currentActor->overlayNumber,currentActor->idx,¶ms); - - if(((animationStart && !currentActor->flag) || (!animationStart && currentActor->x_dest != -1 && currentActor->y_dest != -1)) && (currentActor->type == 0)) - { - // mouse animation - if(!animationStart) - { - var34 = currentActor->x_dest; - var35 = currentActor->y_dest; - - currentActor->x_dest = -1; - currentActor->y_dest = -1; - - currentActor->flag = 1; - } - - currentActor->pathId = computePathfinding(returnVar2, params.X, params.Y, var34, var35, currentActor->stepX, currentActor->stepY, currentActor->pathId); - - if(currentActor->pathId == -1) - { - if((currentActor->endDirection != -1) && (currentActor->endDirection != currentActor->startDirection)) - { - currentActor->phase = ANIM_PHASE_STATIC_END; - currentActor->nextDirection = currentActor->endDirection; - currentActor->endDirection = -1; - currentActor->counter = 0; - } - else - { - currentActor->pathId = -2; - currentActor->flag = 0; - currentActor->endDirection = -1; - currentActor->phase = ANIM_PHASE_WAIT; - } - } - else - { - currentActor->phase = ANIM_PHASE_STATIC; - currentActor->counter = -1; - } - } - else - if((currentActor->type == 1) && (currentActor->x_dest != -1) && (currentActor->y_dest != -1)) - { - // track animation - currentActor->pathId = computePathfinding(returnVar2, params.X, params.Y, currentActor->x_dest, currentActor->y_dest, currentActor->stepX, currentActor->stepY, currentActor->pathId); - - currentActor->x_dest = -1; - currentActor->y_dest = -1; - - if(currentActor->pathId == -1) - { - if((currentActor->endDirection != -1) && (currentActor->endDirection != currentActor->startDirection)) - { - currentActor->phase = ANIM_PHASE_STATIC_END; - currentActor->nextDirection = currentActor->endDirection; - currentActor->endDirection = -1; - currentActor->counter = 0; - } - else - { - currentActor->pathId = -2; - currentActor->flag = 0; - currentActor->endDirection = -1; - currentActor->phase = ANIM_PHASE_WAIT; - } - } - else - { - currentActor->phase = ANIM_PHASE_STATIC; - currentActor->counter = -1; - } - } - - animationStart = false; - - if(currentActor->pathId >= 0 || currentActor->phase == ANIM_PHASE_STATIC_END) - { - switch(currentActor->phase) - { - case ANIM_PHASE_STATIC_END: - case ANIM_PHASE_STATIC: - { - if(currentActor->counter == -1 && currentActor->phase == ANIM_PHASE_STATIC) - { - affiche_chemin(currentActor->pathId, returnVar2); - - if(returnVar2[0] == -1) - { - currentActor->pathId = -2; - currentActor->flag = 0; - currentActor->endDirection = -1; - currentActor->phase = ANIM_PHASE_WAIT; - break; - } - - currentActor->x = returnVar2[0]; - currentActor->y = returnVar2[1]; - currentActor->nextDirection = returnVar2[2]; - currentActor->poly = returnVar2[4]; - currentActor->counter = 0; +void processAnimation(void) { + objectParamsQuery params; + int16 returnVar2[5]; + actorStruct *currentActor = &actorHead; + actorStruct *nextActor; + + while (currentActor) { + nextActor = currentActor->next; + + if (!currentActor->freeze && ((currentActor->type == 0) + || (currentActor->type == 1))) { + getMultipleObjectParam(currentActor->overlayNumber, + currentActor->idx, ¶ms); + + if (((animationStart && !currentActor->flag) + || (!animationStart + && currentActor->x_dest != -1 + && currentActor->y_dest != -1)) + && (currentActor->type == 0)) { + // mouse animation + if (!animationStart) { + var34 = currentActor->x_dest; + var35 = currentActor->y_dest; + + currentActor->x_dest = -1; + currentActor->y_dest = -1; + + currentActor->flag = 1; + } - if (currentActor->startDirection == currentActor->nextDirection) - currentActor->phase = ANIM_PHASE_MOVE; + currentActor->pathId = + computePathfinding(returnVar2, params.X, + params.Y, var34, var35, + currentActor->stepX, currentActor->stepY, + currentActor->pathId); + + if (currentActor->pathId == -1) { + if ((currentActor->endDirection != -1) + && (currentActor->endDirection != + currentActor-> + startDirection)) { + currentActor->phase = + ANIM_PHASE_STATIC_END; + currentActor->nextDirection = + currentActor->endDirection; + currentActor->endDirection = + -1; + currentActor->counter = 0; + } else { + currentActor->pathId = -2; + currentActor->flag = 0; + currentActor->endDirection = + -1; + currentActor->phase = + ANIM_PHASE_WAIT; + } + } else { + currentActor->phase = + ANIM_PHASE_STATIC; + currentActor->counter = -1; + } + } else + if ((currentActor->type == 1) + && (currentActor->x_dest != -1) + && (currentActor->y_dest != -1)) { + // track animation + currentActor->pathId = + computePathfinding(returnVar2, params.X, + params.Y, currentActor->x_dest, + currentActor->y_dest, currentActor->stepX, + currentActor->stepY, currentActor->pathId); + + currentActor->x_dest = -1; + currentActor->y_dest = -1; + + if (currentActor->pathId == -1) { + if ((currentActor->endDirection != -1) + && (currentActor->endDirection != + currentActor-> + startDirection)) { + currentActor->phase = + ANIM_PHASE_STATIC_END; + currentActor->nextDirection = + currentActor->endDirection; + currentActor->endDirection = + -1; + currentActor->counter = 0; + } else { + currentActor->pathId = -2; + currentActor->flag = 0; + currentActor->endDirection = + -1; + currentActor->phase = + ANIM_PHASE_WAIT; + } + } else { + currentActor->phase = + ANIM_PHASE_STATIC; + currentActor->counter = -1; + } } - if ((currentActor->counter>=0) && ((currentActor->phase==ANIM_PHASE_STATIC_END) || (currentActor->phase==ANIM_PHASE_STATIC))) - { - int newA; - int inc = 1; - int t_inc = currentActor->startDirection-1; + animationStart = false; - if (t_inc<0) - t_inc=3; + if (currentActor->pathId >= 0 + || currentActor->phase == ANIM_PHASE_STATIC_END) { + switch (currentActor->phase) { + case ANIM_PHASE_STATIC_END: + case ANIM_PHASE_STATIC: + { + if (currentActor->counter == -1 + && currentActor->phase == + ANIM_PHASE_STATIC) { + affiche_chemin + (currentActor-> + pathId, + returnVar2); + + if (returnVar2[0] == + -1) { + currentActor-> + pathId = + -2; + currentActor-> + flag = 0; + currentActor-> + endDirection + = -1; + currentActor-> + phase = + ANIM_PHASE_WAIT; + break; + } - if (currentActor->nextDirection==t_inc) - inc=-1; + currentActor->x = + returnVar2[0]; + currentActor->y = + returnVar2[1]; + currentActor-> + nextDirection = + returnVar2[2]; + currentActor->poly = + returnVar2[4]; + currentActor->counter = + 0; + + if (currentActor-> + startDirection == + currentActor-> + nextDirection) + currentActor-> + phase = + ANIM_PHASE_MOVE; + } - if (inc>0) - newA = raoul_stat[currentActor->startDirection][currentActor->counter++]; + if ((currentActor->counter >= + 0) + && ((currentActor->phase == + ANIM_PHASE_STATIC_END) + || (currentActor-> + phase == + ANIM_PHASE_STATIC))) + { + int newA; + int inc = 1; + int t_inc = + currentActor-> + startDirection - 1; + + if (t_inc < 0) + t_inc = 3; + + if (currentActor-> + nextDirection == + t_inc) + inc = -1; + + if (inc > 0) + newA = + raoul_stat + [currentActor-> + startDirection] + [currentActor-> + counter++]; else - newA = raoul_invstat[currentActor->startDirection][currentActor->counter++]; - - if (newA==0) - { - currentActor->startDirection = currentActor->startDirection+inc; - - if (currentActor->startDirection>3) - currentActor->startDirection=0; - - if (currentActor->startDirection<0) - currentActor->startDirection=3; - - currentActor->counter=0; - - if (currentActor->startDirection==currentActor->nextDirection) - { + newA = + raoul_invstat + [currentActor-> + startDirection] + [currentActor-> + counter++]; + + if (newA == 0) { + currentActor-> + startDirection + = + currentActor-> + startDirection + + inc; + + if (currentActor->startDirection > 3) + currentActor-> + startDirection + = + 0; + + if (currentActor->startDirection < 0) + currentActor-> + startDirection + = + 3; + + currentActor-> + counter = + 0; + + if (currentActor->startDirection == currentActor->nextDirection) { if (currentActor->phase == ANIM_PHASE_STATIC) - currentActor->phase = ANIM_PHASE_MOVE; + currentActor-> + phase + = + ANIM_PHASE_MOVE; else - currentActor->phase = ANIM_PHASE_END; - } - else - { - newA = raoul_stat[currentActor->startDirection][currentActor->counter++]; - - if (inc==-1) - newA=-newA; - - set_anim(currentActor->overlayNumber,currentActor->idx,currentActor->start,params.X,params.Y,newA,currentActor->poly); + currentActor-> + phase + = + ANIM_PHASE_END; + } else { + newA = + raoul_stat + [currentActor-> + startDirection] + [currentActor-> + counter++]; + + if (inc + == + -1) + newA = -newA; + + set_anim + (currentActor-> + overlayNumber, + currentActor-> + idx, + currentActor-> + start, + params. + X, + params. + Y, + newA, + currentActor-> + poly); break; } - } - else - { - set_anim(currentActor->overlayNumber,currentActor->idx,currentActor->start,params.X,params.Y,newA,currentActor->poly); + } else { + set_anim + (currentActor-> + overlayNumber, + currentActor-> + idx, + currentActor-> + start, + params.X, + params.Y, + newA, + currentActor-> + poly); break; } - } - break; - } - case ANIM_PHASE_MOVE: - { - if (currentActor->counter>=1) - { - affiche_chemin(currentActor->pathId,returnVar2); - if (returnVar2[0]==-1) - { - if ((currentActor->endDirection==-1) || (currentActor->endDirection==currentActor->nextDirection)) - { - currentActor->phase=ANIM_PHASE_END; - } - else - { - currentActor->phase = ANIM_PHASE_STATIC_END; - currentActor->nextDirection=currentActor->endDirection; - } - currentActor->counter=0; - break; - } - else - { - currentActor->x = returnVar2[0]; - currentActor->y = returnVar2[1]; - currentActor->nextDirection = returnVar2[2]; - currentActor->poly = returnVar2[4]; - - /* - if (pl->next_dir!=pl->start_dir) - { - pl->phase=PHASE_STATIC; - pl->cnt=0; - break; - } - */ + } + break; + } + case ANIM_PHASE_MOVE: + { + if (currentActor->counter >= 1) { + affiche_chemin + (currentActor-> + pathId, + returnVar2); + if (returnVar2[0] == + -1) { + if ((currentActor->endDirection == -1) || (currentActor->endDirection == currentActor->nextDirection)) { + currentActor-> + phase + = + ANIM_PHASE_END; + } else { + currentActor-> + phase + = + ANIM_PHASE_STATIC_END; + currentActor-> + nextDirection + = + currentActor-> + endDirection; } - } - - if (currentActor->phase==ANIM_PHASE_MOVE) - { - int newA; + currentActor-> + counter = + 0; + break; + } else { + currentActor-> + x = + returnVar2 + [0]; + currentActor-> + y = + returnVar2 + [1]; + currentActor-> + nextDirection + = + returnVar2 + [2]; + currentActor-> + poly = + returnVar2 + [4]; + + /* + * if (pl->next_dir!=pl->start_dir) + * { + * pl->phase=PHASE_STATIC; + * pl->cnt=0; + * break; + * } + */ + } + } - currentActor->startDirection = currentActor->nextDirection; + if (currentActor->phase == + ANIM_PHASE_MOVE) { + int newA; + + currentActor-> + startDirection = + currentActor-> + nextDirection; + + newA = + raoul_move + [currentActor-> + startDirection] + [currentActor-> + counter++]; + if (!newA) { + currentActor-> + counter = + 0; + newA = + raoul_move + [currentActor-> + startDirection] + [currentActor-> + counter++]; + } + set_anim(currentActor-> + overlayNumber, + currentActor->idx, + currentActor-> + start, + currentActor->x, + currentActor->y, + newA, + currentActor-> + poly); + break; + } - newA = raoul_move[currentActor->startDirection][currentActor->counter++]; - if (!newA) - { - currentActor->counter=0; - newA = raoul_move[currentActor->startDirection][currentActor->counter++]; - } - set_anim(currentActor->overlayNumber,currentActor->idx,currentActor->start,currentActor->x,currentActor->y,newA,currentActor->poly); - break; + break; + } + case ANIM_PHASE_END: + { + int newA = + raoul_end[currentActor-> + startDirection][0]; + + set_anim(currentActor-> + overlayNumber, + currentActor->idx, + currentActor->start, + currentActor->x, + currentActor->y, newA, + currentActor->poly); + + currentActor->pathId = -2; + currentActor->phase = + ANIM_PHASE_WAIT; + currentActor->flag = 0; + currentActor->endDirection = + -1; + break; + } + default: + { + printf + ("Unimplemented currentActor->phase=%d in processAnimation()\n", + currentActor->phase); + // exit(1); + } + } } - - break; - } - case ANIM_PHASE_END: - { - int newA = raoul_end[currentActor->startDirection][0]; - - set_anim(currentActor->overlayNumber,currentActor->idx,currentActor->start,currentActor->x,currentActor->y,newA,currentActor->poly); - - currentActor->pathId = -2; - currentActor->phase=ANIM_PHASE_WAIT; - currentActor->flag=0; - currentActor->endDirection=-1; - break; - } - default: - { - printf("Unimplemented currentActor->phase=%d in processAnimation()\n", currentActor->phase); - // exit(1); - } } - } + currentActor = nextActor; } - currentActor = nextActor; - } } + } // End of namespace Cruise diff --git a/engines/cruise/actor.h b/engines/cruise/actor.h index 3c2f2a5037..7b8a5752dd 100644 --- a/engines/cruise/actor.h +++ b/engines/cruise/actor.h @@ -22,25 +22,24 @@ * */ -#ifndef _ACTOR_H_ -#define _ACTOR_H_ +#ifndef CRUISE_ACTOR_H +#define CRUISE_ACTOR_H namespace Cruise { -enum animPhase -{ - ANIM_PHASE_WAIT = 0, - ANIM_PHASE_STATIC = 1, - ANIM_PHASE_MOVE = 2, - ANIM_PHASE_STATIC_END = 3, - ANIM_PHASE_END = 4 +enum animPhase { + ANIM_PHASE_WAIT = 0, + ANIM_PHASE_STATIC = 1, + ANIM_PHASE_MOVE = 2, + ANIM_PHASE_STATIC_END = 3, + ANIM_PHASE_END = 4 }; typedef enum animPhase animPhase; struct actorStruct { - struct actorStruct* next; - struct actorStruct* prev; + struct actorStruct *next; + struct actorStruct *prev; int16 idx; int16 type; @@ -65,10 +64,13 @@ struct actorStruct { typedef struct actorStruct actorStruct; -int16 mainProc13(int overlayIdx, int param1, actorStruct* pStartEntry, int param2); -actorStruct* findActor(int overlayIdx, int param1, actorStruct* pStartEntry, int param2); +int16 mainProc13(int overlayIdx, int param1, actorStruct * pStartEntry, + int param2); +actorStruct *findActor(int overlayIdx, int param1, actorStruct * pStartEntry, + int param2); void processAnimation(void); void getPixel(int x, int y); + } // End of namespace Cruise #endif diff --git a/engines/cruise/background.cpp b/engines/cruise/background.cpp index 02312d1224..0d5b8d4fbb 100644 --- a/engines/cruise/background.cpp +++ b/engines/cruise/background.cpp @@ -28,193 +28,166 @@ namespace Cruise { uint8 colorMode = 0; -uint8* backgroundPtrtable[8] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; // wasn't initialized in original, but it's probably better +uint8 *backgroundPtrtable[8] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; // wasn't initialized in original, but it's probably better backgroundTableStruct backgroundTable[8]; char hwPage[64000]; -char* hwMemAddr[] = -{ +char *hwMemAddr[] = { hwPage, }; short int cvtPalette[0x20]; -int loadMEN(uint8** ptr) -{ - char* localPtr = (char*)*ptr; +int loadMEN(uint8 **ptr) { + char *localPtr = (char *)*ptr; - if(!strcmp(localPtr,"MEN")) - { - localPtr+=4; + if (!strcmp(localPtr, "MEN")) { + localPtr += 4; - video4 = *(localPtr++); - video3 = *(localPtr++); - video2 = *(localPtr++); - colorOfSelectedSaveDrive = *(localPtr++); + video4 = *(localPtr++); + video3 = *(localPtr++); + video2 = *(localPtr++); + colorOfSelectedSaveDrive = *(localPtr++); - *ptr = (uint8*)localPtr; + *ptr = (uint8 *) localPtr; - return 1; - } - else - { - return 0; - } + return 1; + } else { + return 0; + } } int CVTLoaded; -int loadCVT(uint8** ptr) -{ - char* localPtr = (char*)*ptr; +int loadCVT(uint8 **ptr) { + char *localPtr = (char *)*ptr; - if(!strcmp(localPtr,"CVT")) - { - int i; - localPtr+=4; + if (!strcmp(localPtr, "CVT")) { + int i; + localPtr += 4; - for(i=0;i<0x20;i++) - { - cvtPalette[i] = *(localPtr++); - } + for (i = 0; i < 0x20; i++) { + cvtPalette[i] = *(localPtr++); + } - *ptr = (uint8*)localPtr; + *ptr = (uint8 *) localPtr; - CVTLoaded = 1; + CVTLoaded = 1; - return 1; - } - else - { - CVTLoaded = 0; - return 0; - } + return 1; + } else { + CVTLoaded = 0; + return 0; + } } extern int lastFileSize; -int loadBackground(char* name, int idx) -{ - uint8* ptr; - uint8* ptr2; - uint8* ptrToFree; +int loadBackground(char *name, int idx) { + uint8 *ptr; + uint8 *ptr2; + uint8 *ptrToFree; - printf("Loading BG: %s\n",name); + printf("Loading BG: %s\n", name); - if(!backgroundPtrtable[idx]) - { + if (!backgroundPtrtable[idx]) { //if(!gfxModuleData.useEGA && !gfxModuleData.useVGA) { - backgroundPtrtable[idx] = (uint8*)mallocAndZero(320*200/*64000*/); + backgroundPtrtable[idx] = + (uint8 *) mallocAndZero(320 * 200 /*64000 */ ); } /* else { backgroundPtrtable[idx] = hwMemAddr[idx]; } */ - } + } - if(!backgroundPtrtable[idx]) - { - backgroundTable[idx].name[0] = 0; - return(-2); - } + if (!backgroundPtrtable[idx]) { + backgroundTable[idx].name[0] = 0; + return (-2); + } ptrToFree = gfxModuleData.pPage10; - if(loadFileSub1(&ptrToFree,(uint8*)name,NULL)<0) - { - if(ptrToFree != gfxModuleData.pPage10) - free(ptrToFree); + if (loadFileSub1(&ptrToFree, (uint8 *) name, NULL) < 0) { + if (ptrToFree != gfxModuleData.pPage10) + free(ptrToFree); - return(-18); + return (-18); } - if(lastFileSize == 32078 || lastFileSize == 32080 || lastFileSize == 32034) - { + if (lastFileSize == 32078 || lastFileSize == 32080 + || lastFileSize == 32034) { colorMode = 0; - } - else - { + } else { colorMode = 1; } ptr = ptrToFree; - ptr2 = ptrToFree; - - if(!strcmpuint8(name,"LOGO.PI1")) - { - bgVar3=bgVar2; - bgVar1=1; - bgVar2=1; - } - else - { - if(bgVar1) - { - bgVar2=bgVar3; - bgVar1=0; - } - } - - if(!strcmpuint8(ptr,"PAL")) - { - printf("Pal loading unsupported !\n"); - exit(1); - } - else - { - if(!colorMode || ptr2[1] == 5) - { - ptr2+=2; + ptr2 = ptrToFree; + + if (!strcmpuint8(name, "LOGO.PI1")) { + bgVar3 = bgVar2; + bgVar1 = 1; + bgVar2 = 1; + } else { + if (bgVar1) { + bgVar2 = bgVar3; + bgVar1 = 0; + } + } + + if (!strcmpuint8(ptr, "PAL")) { + printf("Pal loading unsupported !\n"); + exit(1); + } else { + if (!colorMode || ptr2[1] == 5) { + ptr2 += 2; - memcpy(palette,ptr2,0x20); - ptr2+=0x20; - flipGen(palette,0x20); + memcpy(palette, ptr2, 0x20); + ptr2 += 0x20; + flipGen(palette, 0x20); ptr2 += 0x7D00; loadMEN(&ptr2); loadCVT(&ptr2); - gfxModuleData_gfxClearFrameBuffer(backgroundPtrtable[idx]); - gfxModuleData_field_60((char*)ptrToFree+34, 20, 200, (char*)backgroundPtrtable[idx], 0, 0); + gfxModuleData_gfxClearFrameBuffer(backgroundPtrtable + [idx]); + gfxModuleData_field_60((char *)ptrToFree + 34, 20, 200, + (char *)backgroundPtrtable[idx], 0, 0); - gfxModuleData_setPal((uint8*)(palette + (idx << 6))); - } - else - if(ptr2[1] == 8) - { + gfxModuleData_setPal((uint8 *) (palette + (idx << 6))); + } else if (ptr2[1] == 8) { int i; - ptr2+=2; + ptr2 += 2; - for(i=0;i<256*3;i++) - { + for (i = 0; i < 256 * 3; i++) { palette[i] = ptr2[i]; } //memcpy(palette,ptr2,256*3); - ptr2+=256*3; + ptr2 += 256 * 3; - memcpy(backgroundPtrtable[idx], ptr2, 320*200); + memcpy(backgroundPtrtable[idx], ptr2, 320 * 200); gfxModuleData_setPal256(palette); } - } + } - //if(ptrToFree != gfxModuleData.pPage10) - // free(ptrToFree); + //if(ptrToFree != gfxModuleData.pPage10) + // free(ptrToFree); - if(gfxModuleData.useEGA || gfxModuleData.useTandy) - { + if (gfxModuleData.useEGA || gfxModuleData.useTandy) { ASSERT(0); } - if(gfxModuleData.useEGA || gfxModuleData.useTandy) - { + if (gfxModuleData.useEGA || gfxModuleData.useTandy) { ASSERT(0); } strcpy(backgroundTable[idx].name, name); - return(0); + return (0); } } // End of namespace Cruise diff --git a/engines/cruise/background.h b/engines/cruise/background.h index f458bc19d7..c5299b2b16 100644 --- a/engines/cruise/background.h +++ b/engines/cruise/background.h @@ -21,13 +21,13 @@ * $Id$ * */ -#ifndef _BACKGROUND_H_ -#define _BACKGROUND_H_ + +#ifndef CRUISE_BACKGROUND_H +#define CRUISE_BACKGROUND_H namespace Cruise { -struct backgroundTableStruct -{ +struct backgroundTableStruct { char name[9]; char extention[6]; }; @@ -36,11 +36,11 @@ typedef struct backgroundTableStruct backgroundTableStruct; extern short int cvtPalette[0x20]; extern int CVTLoaded; -extern uint8* backgroundPtrtable[8]; +extern uint8 *backgroundPtrtable[8]; extern backgroundTableStruct backgroundTable[8]; -int loadBackground(char* name, int idx); +int loadBackground(char *name, int idx); + } // End of namespace Cruise #endif - diff --git a/engines/cruise/backgroundIncrust.cpp b/engines/cruise/backgroundIncrust.cpp index 9f108072fa..8547823a7c 100644 --- a/engines/cruise/backgroundIncrust.cpp +++ b/engines/cruise/backgroundIncrust.cpp @@ -28,195 +28,192 @@ namespace Cruise { backgroundIncrustStruct backgroundIncrustHead; -void resetBackgroundIncrustList(backgroundIncrustStruct* pHead) -{ - pHead->next = NULL; - pHead->prev = NULL; +void resetBackgroundIncrustList(backgroundIncrustStruct *pHead) { + pHead->next = NULL; + pHead->prev = NULL; } // blit background to another one -void addBackgroundIncrustSub1(int fileIdx, int X, int Y, char* ptr2, int16 scale, char* destBuffer, char* dataPtr) -{ - if(*dataPtr == 0) - { - ASSERT(0); - } - - buildPolyModel(X, Y, scale, ptr2, destBuffer, dataPtr); +void addBackgroundIncrustSub1(int fileIdx, int X, int Y, char *ptr2, + int16 scale, char *destBuffer, char *dataPtr) { + if (*dataPtr == 0) { + ASSERT(0); + } + + buildPolyModel(X, Y, scale, ptr2, destBuffer, dataPtr); } -backgroundIncrustStruct* addBackgroundIncrust(int16 overlayIdx,int16 objectIdx,backgroundIncrustStruct* pHead,int16 scriptNumber,int16 scriptOverlay, int16 backgroundIdx, int16 param4) -{ - uint8* backgroundPtr; - uint8* ptr; - objectParamsQuery params; - backgroundIncrustStruct* newElement; - backgroundIncrustStruct* currentHead; - backgroundIncrustStruct* currentHead2; - - getMultipleObjectParam(overlayIdx,objectIdx,¶ms); - - ptr = filesDatabase[params.fileIdx].subData.ptr; - - if(!ptr) - { - return NULL; - } - - if(filesDatabase[params.fileIdx].subData.resourceType != 4 && filesDatabase[params.fileIdx].subData.resourceType != 8) - { - return NULL; - } - - backgroundPtr = backgroundPtrtable[backgroundIdx]; - - if(!backgroundPtr) - { - ASSERT(0); - return NULL; - } - - currentHead = pHead; - currentHead2 = currentHead->next; - - while(currentHead2) - { - currentHead = currentHead2; - currentHead2 = currentHead->next; - } - - newElement = (backgroundIncrustStruct*)mallocAndZero(sizeof(backgroundIncrustStruct)); - - if(!newElement) - return NULL; - - newElement->next = currentHead->next; - currentHead->next = newElement; - - if(!currentHead2) - { - currentHead2 = pHead; - } - - newElement->prev = currentHead2->prev; - currentHead2->prev = newElement; - - newElement->objectIdx = objectIdx; - newElement->field_6 = param4; - newElement->backgroundIdx = backgroundIdx; - newElement->overlayIdx = overlayIdx; - newElement->scriptNumber = scriptNumber; - newElement->scriptOverlayIdx = scriptOverlay; - newElement->X = params.X; - newElement->Y = params.Y; - newElement->scale = params.scale; - newElement->field_E = params.fileIdx; - newElement->var34 = filesDatabase[params.fileIdx].subData.index; - newElement->ptr = NULL; - strcpy(newElement->name, filesDatabase[params.fileIdx].subData.name); - - if(filesDatabase[params.fileIdx].subData.resourceType == 4) // sprite - { - int width = filesDatabase[params.fileIdx].width; - int height = filesDatabase[params.fileIdx].height; - - currentTransparent = filesDatabase[params.fileIdx].subData.transparency; - mainDrawSub4(width, height, NULL, (char*)filesDatabase[params.fileIdx].subData.ptr, newElement->Y, newElement->X, (char*)backgroundPtr, (char*)filesDatabase[params.fileIdx].subData.ptr); - // ASSERT(0); - } - else // poly - { - /* if(param4 == 1) - { - int var_A; - int var_8; - int var_6; - char* var_10; - - mainDrawSub1Sub1(lvar[3], newElement->X, newElement->Y, &var_A, &var_8, &var_6, &var_10, lvar[4], filesDatabase[lvar[3]].subData.ptr); - ASSERT(0); - }*/ - - addBackgroundIncrustSub1(params.fileIdx, newElement->X, newElement->Y, NULL, params.scale, (char*)backgroundPtr, (char*)filesDatabase[params.fileIdx].subData.ptr ); - } - - return newElement; +backgroundIncrustStruct *addBackgroundIncrust(int16 overlayIdx, + int16 objectIdx, backgroundIncrustStruct *pHead, int16 scriptNumber, + int16 scriptOverlay, int16 backgroundIdx, int16 param4) { + uint8 *backgroundPtr; + uint8 *ptr; + objectParamsQuery params; + backgroundIncrustStruct *newElement; + backgroundIncrustStruct *currentHead; + backgroundIncrustStruct *currentHead2; + + getMultipleObjectParam(overlayIdx, objectIdx, ¶ms); + + ptr = filesDatabase[params.fileIdx].subData.ptr; + + if (!ptr) { + return NULL; + } + + if (filesDatabase[params.fileIdx].subData.resourceType != 4 + && filesDatabase[params.fileIdx].subData.resourceType != 8) { + return NULL; + } + + backgroundPtr = backgroundPtrtable[backgroundIdx]; + + if (!backgroundPtr) { + ASSERT(0); + return NULL; + } + + currentHead = pHead; + currentHead2 = currentHead->next; + + while (currentHead2) { + currentHead = currentHead2; + currentHead2 = currentHead->next; + } + + newElement = + (backgroundIncrustStruct *) + mallocAndZero(sizeof(backgroundIncrustStruct)); + + if (!newElement) + return NULL; + + newElement->next = currentHead->next; + currentHead->next = newElement; + + if (!currentHead2) { + currentHead2 = pHead; + } + + newElement->prev = currentHead2->prev; + currentHead2->prev = newElement; + + newElement->objectIdx = objectIdx; + newElement->field_6 = param4; + newElement->backgroundIdx = backgroundIdx; + newElement->overlayIdx = overlayIdx; + newElement->scriptNumber = scriptNumber; + newElement->scriptOverlayIdx = scriptOverlay; + newElement->X = params.X; + newElement->Y = params.Y; + newElement->scale = params.scale; + newElement->field_E = params.fileIdx; + newElement->var34 = filesDatabase[params.fileIdx].subData.index; + newElement->ptr = NULL; + strcpy(newElement->name, filesDatabase[params.fileIdx].subData.name); + + if (filesDatabase[params.fileIdx].subData.resourceType == 4) // sprite + { + int width = filesDatabase[params.fileIdx].width; + int height = filesDatabase[params.fileIdx].height; + + currentTransparent = + filesDatabase[params.fileIdx].subData.transparency; + mainDrawSub4(width, height, NULL, + (char *)filesDatabase[params.fileIdx].subData.ptr, + newElement->Y, newElement->X, (char *)backgroundPtr, + (char *)filesDatabase[params.fileIdx].subData.ptr); + // ASSERT(0); + } else // poly + { + /* if(param4 == 1) + * { + * int var_A; + * int var_8; + * int var_6; + * char* var_10; + * + * mainDrawSub1Sub1(lvar[3], newElement->X, newElement->Y, &var_A, &var_8, &var_6, &var_10, lvar[4], filesDatabase[lvar[3]].subData.ptr); + * ASSERT(0); + * } */ + + addBackgroundIncrustSub1(params.fileIdx, newElement->X, + newElement->Y, NULL, params.scale, (char *)backgroundPtr, + (char *)filesDatabase[params.fileIdx].subData.ptr); + } + + return newElement; } -void loadBackgroundIncrustFromSave(FILE* fileHandle) -{ - int16 numEntry; - backgroundIncrustStruct* ptr1; - backgroundIncrustStruct* ptr2; - int32 i; - - fread(&numEntry,2,1,fileHandle); - - ptr1 = &backgroundIncrustHead; - ptr2 = &backgroundIncrustHead; - - for(i=0;i<numEntry;i++) - { - backgroundIncrustStruct* current = (backgroundIncrustStruct*)mallocAndZero(sizeof(backgroundIncrustStruct)); - - fseek(fileHandle, 4, SEEK_CUR); - - fread(¤t->objectIdx,2,1,fileHandle); - fread(¤t->field_6,2,1,fileHandle); - fread(¤t->overlayIdx,2,1,fileHandle); - fread(¤t->X,2,1,fileHandle); - fread(¤t->Y,2,1,fileHandle); - fread(¤t->field_E,2,1,fileHandle); - fread(¤t->scale,2,1,fileHandle); - fread(¤t->backgroundIdx,2,1,fileHandle); - fread(¤t->scriptNumber,2,1,fileHandle); - fread(¤t->scriptOverlayIdx,2,1,fileHandle); - fread(¤t->ptr,4,1,fileHandle); - fread(¤t->field_1C,4,1,fileHandle); - fread(¤t->size,2,1,fileHandle); - fread(¤t->field_22,2,1,fileHandle); - fread(¤t->field_24,2,1,fileHandle); - fread(current->name,14,1,fileHandle); - fread(¤t->var34,2,1,fileHandle); - - if(current->size) - { - current->ptr = (uint8*)mallocAndZero(current->size); - fread(current->ptr,current->size,1,fileHandle); - } - - current->next = NULL; - ptr2 = current; - current->prev = backgroundIncrustHead.prev; - backgroundIncrustHead.prev = current; - ptr2 = current->next; - } +void loadBackgroundIncrustFromSave(FILE *fileHandle) { + int16 numEntry; + backgroundIncrustStruct *ptr1; + backgroundIncrustStruct *ptr2; + int32 i; + + fread(&numEntry, 2, 1, fileHandle); + + ptr1 = &backgroundIncrustHead; + ptr2 = &backgroundIncrustHead; + + for (i = 0; i < numEntry; i++) { + backgroundIncrustStruct *current = + (backgroundIncrustStruct *) + mallocAndZero(sizeof(backgroundIncrustStruct)); + + fseek(fileHandle, 4, SEEK_CUR); + + fread(¤t->objectIdx, 2, 1, fileHandle); + fread(¤t->field_6, 2, 1, fileHandle); + fread(¤t->overlayIdx, 2, 1, fileHandle); + fread(¤t->X, 2, 1, fileHandle); + fread(¤t->Y, 2, 1, fileHandle); + fread(¤t->field_E, 2, 1, fileHandle); + fread(¤t->scale, 2, 1, fileHandle); + fread(¤t->backgroundIdx, 2, 1, fileHandle); + fread(¤t->scriptNumber, 2, 1, fileHandle); + fread(¤t->scriptOverlayIdx, 2, 1, fileHandle); + fread(¤t->ptr, 4, 1, fileHandle); + fread(¤t->field_1C, 4, 1, fileHandle); + fread(¤t->size, 2, 1, fileHandle); + fread(¤t->field_22, 2, 1, fileHandle); + fread(¤t->field_24, 2, 1, fileHandle); + fread(current->name, 14, 1, fileHandle); + fread(¤t->var34, 2, 1, fileHandle); + + if (current->size) { + current->ptr = (uint8 *) mallocAndZero(current->size); + fread(current->ptr, current->size, 1, fileHandle); + } + + current->next = NULL; + ptr2 = current; + current->prev = backgroundIncrustHead.prev; + backgroundIncrustHead.prev = current; + ptr2 = current->next; + } } -void regenerateBackgroundIncrust(backgroundIncrustStruct* pHead) -{ - printf("Need to regenerate backgroundIncrust\n"); +void regenerateBackgroundIncrust(backgroundIncrustStruct *pHead) { + printf("Need to regenerate backgroundIncrust\n"); } -void freeBackgroundIncrustList(backgroundIncrustStruct* pHead) -{ - backgroundIncrustStruct* pCurrent = pHead->next; +void freeBackgroundIncrustList(backgroundIncrustStruct *pHead) { + backgroundIncrustStruct *pCurrent = pHead->next; - while(pCurrent) - { - backgroundIncrustStruct* pNext = pCurrent->next; + while (pCurrent) { + backgroundIncrustStruct *pNext = pCurrent->next; - if(pCurrent->ptr) - { - free(pCurrent->ptr); - } + if (pCurrent->ptr) { + free(pCurrent->ptr); + } - free(pCurrent); + free(pCurrent); - pCurrent = pNext; - } + pCurrent = pNext; + } - resetBackgroundIncrustList(pHead); + resetBackgroundIncrustList(pHead); } } // End of namespace Cruise diff --git a/engines/cruise/backgroundIncrust.h b/engines/cruise/backgroundIncrust.h index 1f5fd756b2..576cb8ec8b 100644 --- a/engines/cruise/backgroundIncrust.h +++ b/engines/cruise/backgroundIncrust.h @@ -22,14 +22,14 @@ * */ -#ifndef _BACKGROUNDINCRUST_H_ -#define _BACKGROUNDINCRUST_H_ +#ifndef CRUISE_BACKGROUNDINCRUST_H +#define CRUISE_BACKGROUNDINCRUST_H namespace Cruise { struct backgroundIncrustStruct { - struct backgroundIncrustStruct* next; - struct backgroundIncrustStruct* prev; + struct backgroundIncrustStruct *next; + struct backgroundIncrustStruct *prev; uint16 objectIdx; uint16 field_6; @@ -41,7 +41,7 @@ struct backgroundIncrustStruct { uint16 backgroundIdx; uint16 scriptNumber; uint16 scriptOverlayIdx; - uint8* ptr; + uint8 *ptr; int32 field_1C; int16 size; uint16 field_22; @@ -54,13 +54,14 @@ typedef struct backgroundIncrustStruct backgroundIncrustStruct; extern backgroundIncrustStruct backgroundIncrustHead; -void resetBackgroundIncrustList(backgroundIncrustStruct* pHead); -backgroundIncrustStruct* addBackgroundIncrust(int16 overlayIdx,int16 param2,backgroundIncrustStruct* pHead,int16 scriptNumber,int16 scriptOverlay, int16 backgroundIdx, int16 param4); -void loadBackgroundIncrustFromSave(FILE* fileHandle); -void regenerateBackgroundIncrust(backgroundIncrustStruct* pHead); -void freeBackgroundIncrustList(backgroundIncrustStruct* pHead); +void resetBackgroundIncrustList(backgroundIncrustStruct * pHead); +backgroundIncrustStruct *addBackgroundIncrust(int16 overlayIdx, int16 param2, + backgroundIncrustStruct * pHead, int16 scriptNumber, int16 scriptOverlay, + int16 backgroundIdx, int16 param4); +void loadBackgroundIncrustFromSave(FILE * fileHandle); +void regenerateBackgroundIncrust(backgroundIncrustStruct * pHead); +void freeBackgroundIncrustList(backgroundIncrustStruct * pHead); } // End of namespace Cruise #endif - diff --git a/engines/cruise/cell.cpp b/engines/cruise/cell.cpp index 1920926b6d..c2a4f66d38 100644 --- a/engines/cruise/cell.cpp +++ b/engines/cruise/cell.cpp @@ -27,133 +27,123 @@ namespace Cruise { -void resetPtr(cellStruct* ptr) -{ - ptr->next = NULL; - ptr->prev = NULL; +void resetPtr(cellStruct *ptr) { + ptr->next = NULL; + ptr->prev = NULL; } -void loadSavegameDataSub2(FILE * f) -{ - unsigned short int n_chunks; - int i; - cellStruct *p; - cellStruct *t; +void loadSavegameDataSub2(FILE *f) { + unsigned short int n_chunks; + int i; + cellStruct *p; + cellStruct *t; - cellHead.next = NULL; // Not in ASM code, but I guess the variable is defaulted - // to this value in the .exe + cellHead.next = NULL; // Not in ASM code, but I guess the variable is defaulted + // to this value in the .exe - fread(&n_chunks, 2, 1, f); - // BIG ENDIAN MACHINES, PLEASE SWAP IT + fread(&n_chunks, 2, 1, f); + // BIG ENDIAN MACHINES, PLEASE SWAP IT - p = &cellHead; + p = &cellHead; - for (i = 0; i < n_chunks; i++) - { - t = (cellStruct *) mallocAndZero(sizeof(cellStruct)); + for (i = 0; i < n_chunks; i++) { + t = (cellStruct *) mallocAndZero(sizeof(cellStruct)); - fseek(f, 4, SEEK_CUR); - fread(&t->idx, 1, 0x30, f); + fseek(f, 4, SEEK_CUR); + fread(&t->idx, 1, 0x30, f); - t->next = NULL; + t->next = NULL; p->next = t; - t->prev = cellHead.prev; - cellHead.prev = t; - p = t; - } + t->prev = cellHead.prev; + cellHead.prev = t; + p = t; + } } -cellStruct* addCell(int16 overlayIdx,int16 param2,cellStruct* pHead,int16 scriptType,int16 scriptNumber,int16 scriptOverlay, int16 param3, int16 param4) -{ - int16 var; - - cellStruct* newElement; - cellStruct* currentHead = pHead; - cellStruct* currentHead2; - cellStruct* currentHead3; - - if(getSingleObjectParam(overlayIdx,param2,2,&var)<0) - { - return 0; - } - - currentHead3 = currentHead; - currentHead2 = currentHead->next; - - while(currentHead2) - { - if(currentHead2->type == 3) - { - break; - } - - if(currentHead2->type != 5) - { - int16 lvar2; - - getSingleObjectParam(currentHead2->overlay,currentHead2->idx,2,&lvar2); - - if(lvar2 > var) - break; - } - - currentHead3 = currentHead2; - currentHead2 = currentHead2->next; - } - - if(currentHead2) - { - if( (currentHead2->overlay == overlayIdx) && - (currentHead2->backgroundPlane == param3) && - (currentHead2->idx == param2) && - (currentHead2->type == param4)) - - return NULL; - } - - currentHead = currentHead2; - - newElement = (cellStruct*)mallocAndZero(sizeof(cellStruct)); - - if(!newElement) - return 0; - - newElement->next = currentHead3->next; - currentHead3->next = newElement; - - newElement->idx = param2; - newElement->type = param4; - newElement->backgroundPlane = param3; - newElement->overlay = overlayIdx; - newElement->freeze = 0; - newElement->field_16 = scriptNumber; - newElement->field_18 = scriptOverlay; - newElement->gfxPtr = NULL; - newElement->followObjectIdx = param2; - newElement->followObjectOverlayIdx = overlayIdx; - newElement->field_1A = scriptType; - newElement->field_20 = 0; - newElement->field_22 = 0; - newElement->nextAnimDelay = 0; - newElement->field_2C = 0; - newElement->currentAnimDelay = 0; - newElement->field_2A = 0; - newElement->animStep = 0; - newElement->field_30 = 0; - - if(currentHead) - { - newElement->prev = currentHead->prev; - currentHead->prev = newElement; - } - else - { - newElement->prev = pHead->prev; - pHead->prev = newElement; - } - - return newElement; +cellStruct *addCell(int16 overlayIdx, int16 param2, cellStruct *pHead, + int16 scriptType, int16 scriptNumber, int16 scriptOverlay, int16 param3, + int16 param4) { + int16 var; + + cellStruct *newElement; + cellStruct *currentHead = pHead; + cellStruct *currentHead2; + cellStruct *currentHead3; + + if (getSingleObjectParam(overlayIdx, param2, 2, &var) < 0) { + return 0; + } + + currentHead3 = currentHead; + currentHead2 = currentHead->next; + + while (currentHead2) { + if (currentHead2->type == 3) { + break; + } + + if (currentHead2->type != 5) { + int16 lvar2; + + getSingleObjectParam(currentHead2->overlay, + currentHead2->idx, 2, &lvar2); + + if (lvar2 > var) + break; + } + + currentHead3 = currentHead2; + currentHead2 = currentHead2->next; + } + + if (currentHead2) { + if ((currentHead2->overlay == overlayIdx) && + (currentHead2->backgroundPlane == param3) && + (currentHead2->idx == param2) && + (currentHead2->type == param4)) + + return NULL; + } + + currentHead = currentHead2; + + newElement = (cellStruct *) mallocAndZero(sizeof(cellStruct)); + + if (!newElement) + return 0; + + newElement->next = currentHead3->next; + currentHead3->next = newElement; + + newElement->idx = param2; + newElement->type = param4; + newElement->backgroundPlane = param3; + newElement->overlay = overlayIdx; + newElement->freeze = 0; + newElement->field_16 = scriptNumber; + newElement->field_18 = scriptOverlay; + newElement->gfxPtr = NULL; + newElement->followObjectIdx = param2; + newElement->followObjectOverlayIdx = overlayIdx; + newElement->field_1A = scriptType; + newElement->field_20 = 0; + newElement->field_22 = 0; + newElement->nextAnimDelay = 0; + newElement->field_2C = 0; + newElement->currentAnimDelay = 0; + newElement->field_2A = 0; + newElement->animStep = 0; + newElement->field_30 = 0; + + if (currentHead) { + newElement->prev = currentHead->prev; + currentHead->prev = newElement; + } else { + newElement->prev = pHead->prev; + pHead->prev = newElement; + } + + return newElement; } - -} +} // End of namespace Cruise diff --git a/engines/cruise/cell.h b/engines/cruise/cell.h index e03953b6e9..3f7b947e75 100644 --- a/engines/cruise/cell.h +++ b/engines/cruise/cell.h @@ -22,8 +22,8 @@ * */ -#ifndef _CELL_H_ -#define _CELL_H_ +#ifndef CRUISE_CELL_H +#define CRUISE_CELL_H #include "common/stdafx.h" #include "common/scummsys.h" @@ -32,16 +32,15 @@ namespace Cruise { struct gfxEntryStruct; -struct cellStruct -{ - struct cellStruct* next; - struct cellStruct* prev; +struct cellStruct { + struct cellStruct *next; + struct cellStruct *prev; int16 idx; int16 type; - int16 overlay ; - int16 field_A ; - int16 field_C ; - int16 spriteIdx ; + int16 overlay; + int16 field_A; + int16 field_C; + int16 spriteIdx; int16 field_10; int16 backgroundPlane; int16 freeze; @@ -59,15 +58,17 @@ struct cellStruct int16 field_2C; int16 currentAnimDelay; int16 field_30; - gfxEntryStruct* gfxPtr; + gfxEntryStruct *gfxPtr; }; extern cellStruct cellHead; -void resetPtr(cellStruct* ptr); +void resetPtr(cellStruct * ptr); void loadSavegameDataSub2(FILE * f); -cellStruct* addCell(int16 overlayIdx,int16 param2,cellStruct* pHead,int16 scriptType,int16 scriptNumber,int16 scriptOverlay, int16 param3, int16 param4); +cellStruct *addCell(int16 overlayIdx, int16 param2, cellStruct * pHead, + int16 scriptType, int16 scriptNumber, int16 scriptOverlay, int16 param3, + int16 param4); -} +} // End of namespace Cruise #endif diff --git a/engines/cruise/cruise.cpp b/engines/cruise/cruise.cpp index 35298e2bbb..ccb89ce049 100644 --- a/engines/cruise/cruise.cpp +++ b/engines/cruise/cruise.cpp @@ -40,20 +40,23 @@ namespace Cruise { //SoundDriver *g_soundDriver; //SfxPlayer *g_sfxPlayer; -Common::SaveFileManager *g_saveFileMan; +Common::SaveFileManager * g_saveFileMan; CruiseEngine *g_cruise; -CruiseEngine::CruiseEngine(OSystem *syst) : Engine(syst) { - Common::addSpecialDebugLevel(kCruiseDebugScript, "Script", "Script debug level"); +CruiseEngine::CruiseEngine(OSystem * syst) : Engine(syst) { + Common::addSpecialDebugLevel(kCruiseDebugScript, "Script", + "Script debug level"); // Setup mixer if (!_mixer->isReady()) { warning("Sound initialization failed."); } - _mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, ConfMan.getInt("sfx_volume")); - _mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, ConfMan.getInt("music_volume")); + _mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, + ConfMan.getInt("sfx_volume")); + _mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, + ConfMan.getInt("music_volume")); g_cruise = this; } @@ -64,10 +67,10 @@ CruiseEngine::~CruiseEngine() { int CruiseEngine::init() { // Detect game if (!initGame()) { - GUIErrorMessage("No valid games were found in the specified directory."); + GUIErrorMessage + ("No valid games were found in the specified directory."); return -1; } - // Initialize backend _system->beginGFXTransaction(); initCommonGFX(false); @@ -87,16 +90,16 @@ int CruiseEngine::go() { return 0; } - void CruiseEngine::initialize() { fadeVar = 0; - ptr_something = (ctpVar19Struct*)mallocAndZero(sizeof(ctpVar19Struct)*0x200); + ptr_something = + (ctpVar19Struct *) mallocAndZero(sizeof(ctpVar19Struct) * 0x200); /*volVar1 = 0; - fileData1 = 0;*/ + * fileData1 = 0; */ - /*PAL_fileHandle = -1;*/ + /*PAL_fileHandle = -1; */ // video init stuff diff --git a/engines/cruise/cruise.h b/engines/cruise/cruise.h index 50d65cc0e9..144a7fdd12 100644 --- a/engines/cruise/cruise.h +++ b/engines/cruise/cruise.h @@ -22,8 +22,8 @@ * */ -#ifndef CRUISE_H -#define CRUISE_H +#ifndef CRUISE_CRUISE_H +#define CRUISE_CRUISE_H #include "common/stdafx.h" #include "common/scummsys.h" @@ -41,30 +41,30 @@ enum CruiseGameType { struct CRUISEGameDescription; -class CruiseEngine : public Engine { +class CruiseEngine:public Engine { -protected: + protected: int init(); int go(); void shutdown(); - + bool initGame(); -public: - CruiseEngine(OSystem *syst); - virtual ~CruiseEngine(); + public: + CruiseEngine(OSystem * syst); + virtual ~ CruiseEngine(); int getGameType() const; uint32 getFeatures() const; - Common::Language getLanguage() const; - Common::Platform getPlatform() const; + Common::Language getLanguage() const; + Common::Platform getPlatform() const; bool loadSaveDirectory(void); void makeSystemMenu(void); const CRUISEGameDescription *_gameDescription; -private: + private: void initialize(void); bool makeLoad(char *saveName); void mainLoop(int bootScriptIdx); @@ -99,8 +99,7 @@ enum { kCmpLT = (1 << 2) }; - -extern Common::SaveFileManager *g_saveFileMan; // TEMP +extern Common::SaveFileManager * g_saveFileMan; // TEMP } // End of namespace Cruise diff --git a/engines/cruise/cruise_main.cpp b/engines/cruise/cruise_main.cpp index 9353a2d61f..9784963315 100644 --- a/engines/cruise/cruise_main.cpp +++ b/engines/cruise/cruise_main.cpp @@ -32,514 +32,463 @@ namespace Cruise { unsigned int timer = 0; -void drawSolidBox(int32 x1, int32 y1, int32 x2, int32 y2, uint8 color) -{ - int32 i; - int32 j; - - for(i=x1;i<x2;i++) - { - for(j=y1;j<y2;j++) - { - globalScreen[j*320+i] = color; - } - } +void drawSolidBox(int32 x1, int32 y1, int32 x2, int32 y2, uint8 color) { + int32 i; + int32 j; + + for (i = x1; i < x2; i++) { + for (j = y1; j < y2; j++) { + globalScreen[j * 320 + i] = color; + } + } } -void drawBlackSolidBoxSmall() -{ +void drawBlackSolidBoxSmall() { // gfxModuleData.drawSolidBox(64,100,256,117,0); - drawSolidBox(64,100,256,117,0); + drawSolidBox(64, 100, 256, 117, 0); } -void resetRaster(uint8* rasterPtr, int32 rasterSize) -{ - memset(rasterPtr,0,rasterSize); +void resetRaster(uint8 *rasterPtr, int32 rasterSize) { + memset(rasterPtr, 0, rasterSize); } +void drawInfoStringSmallBlackBox(uint8 *string) { + //uint8 buffer[256]; -void drawInfoStringSmallBlackBox(uint8* string) -{ - //uint8 buffer[256]; - - gfxModuleData_field_90(); - gfxModuleData_gfxWaitVSync(); - drawBlackSolidBoxSmall(); + gfxModuleData_field_90(); + gfxModuleData_gfxWaitVSync(); + drawBlackSolidBoxSmall(); - drawString(10,100,string,gfxModuleData.pPage10,video4,300); + drawString(10, 100, string, gfxModuleData.pPage10, video4, 300); - gfxModuleData_flip(); + gfxModuleData_flip(); flipScreen(); - while(1); + while (1); } -void loadPakedFileToMem(int fileIdx, uint8* buffer) -{ - //changeCursor(1); +void loadPakedFileToMem(int fileIdx, uint8 *buffer) { + //changeCursor(1); - currentVolumeFile.seek(volumePtrToFileDescriptor[fileIdx].offset,SEEK_SET); - currentVolumeFile.read(buffer,volumePtrToFileDescriptor[fileIdx].size); + currentVolumeFile.seek(volumePtrToFileDescriptor[fileIdx].offset, + SEEK_SET); + currentVolumeFile.read(buffer, + volumePtrToFileDescriptor[fileIdx].size); } -int loadScriptSub1(int scriptIdx, int param) -{ - objDataStruct* ptr2; - int counter; - int i; - - if(!overlayTable[scriptIdx].ovlData) - return(0); +int loadScriptSub1(int scriptIdx, int param) { + objDataStruct *ptr2; + int counter; + int i; - ptr2 = overlayTable[scriptIdx].ovlData->objDataTable; + if (!overlayTable[scriptIdx].ovlData) + return (0); - if(!ptr2) - return(0); + ptr2 = overlayTable[scriptIdx].ovlData->objDataTable; - if(overlayTable[scriptIdx].ovlData->numObjData==0) - return(0); + if (!ptr2) + return (0); - counter = 0; + if (overlayTable[scriptIdx].ovlData->numObjData == 0) + return (0); - for(i=0;i<overlayTable[scriptIdx].ovlData->numObjData;i++) - { - if(ptr2[i].var0 == param) - { - counter++; - } - } + counter = 0; + + for (i = 0; i < overlayTable[scriptIdx].ovlData->numObjData; i++) { + if (ptr2[i].var0 == param) { + counter++; + } + } - return(counter); + return (counter); } -void saveShort(void* ptr, short int var) -{ - *(int16*)ptr = var; +void saveShort(void *ptr, short int var) { + *(int16 *) ptr = var; - flipShort((int16*)ptr); + flipShort((int16 *) ptr); } -int16 loadShort(void* ptr) -{ - short int temp; +int16 loadShort(void *ptr) { + short int temp; - temp = *(int16*)ptr; + temp = *(int16 *) ptr; - flipShort(&temp); + flipShort(&temp); - return(temp); + return (temp); } +void resetFileEntryRange(int param1, int param2) { + int i; -void resetFileEntryRange(int param1, int param2) -{ - int i; - - for(i=param1;i<param2;i++) - { - resetFileEntry(i); - } + for (i = param1; i < param2; i++) { + resetFileEntry(i); + } } -int getProcParam(int overlayIdx, int param2, uint8* name) -{ - int numExport; - int i; - exportEntryStruct* exportDataPtr; - uint8* exportNamePtr; - uint8 exportName[80]; - - if(!overlayTable[overlayIdx].alreadyLoaded) - return 0; - - if(!overlayTable[overlayIdx].ovlData) - return 0; - - numExport = overlayTable[overlayIdx].ovlData->numExport; - exportDataPtr = overlayTable[overlayIdx].ovlData->exportDataPtr; - exportNamePtr = overlayTable[overlayIdx].ovlData->exportNamesPtr; - - if(!exportNamePtr) - return 0; - - for(i=0;i<numExport;i++) - { - if(exportDataPtr[i].var4 == param2) - { - strcpyuint8(exportName,exportDataPtr[i].offsetToName+exportNamePtr); - - if(!strcmpuint8(exportName,name)) - { - return(exportDataPtr[i].idx); - } - } - } - - return 0; -} +int getProcParam(int overlayIdx, int param2, uint8 *name) { + int numExport; + int i; + exportEntryStruct *exportDataPtr; + uint8 *exportNamePtr; + uint8 exportName[80]; + + if (!overlayTable[overlayIdx].alreadyLoaded) + return 0; -void changeScriptParamInList(int param1, int param2, scriptInstanceStruct* pScriptInstance,int newValue, int param3) -{ - pScriptInstance = pScriptInstance->nextScriptPtr; - while(pScriptInstance) - { - if( (pScriptInstance->overlayNumber == param1 || param1 == -1) - &&(pScriptInstance->scriptNumber == param2 || param2 == -1) - &&(pScriptInstance->var12 == param3 || param3 == -1)) - { - pScriptInstance->var12 = newValue; - } - - pScriptInstance = pScriptInstance->nextScriptPtr; - } + if (!overlayTable[overlayIdx].ovlData) + return 0; + + numExport = overlayTable[overlayIdx].ovlData->numExport; + exportDataPtr = overlayTable[overlayIdx].ovlData->exportDataPtr; + exportNamePtr = overlayTable[overlayIdx].ovlData->exportNamesPtr; + + if (!exportNamePtr) + return 0; + + for (i = 0; i < numExport; i++) { + if (exportDataPtr[i].var4 == param2) { + strcpyuint8(exportName, + exportDataPtr[i].offsetToName + exportNamePtr); + + if (!strcmpuint8(exportName, name)) { + return (exportDataPtr[i].idx); + } + } + } + + return 0; } +void changeScriptParamInList(int param1, int param2, + scriptInstanceStruct *pScriptInstance, int newValue, int param3) { + pScriptInstance = pScriptInstance->nextScriptPtr; + while (pScriptInstance) { + if ((pScriptInstance->overlayNumber == param1 || param1 == -1) + && (pScriptInstance->scriptNumber == param2 + || param2 == -1) + && (pScriptInstance->var12 == param3 || param3 == -1)) { + pScriptInstance->var12 = newValue; + } -void initBigVar3() -{ - int i; + pScriptInstance = pScriptInstance->nextScriptPtr; + } +} - for(i=0;i<257;i++) - { - if(filesDatabase[i].subData.ptr) - { - free(filesDatabase[i].subData.ptr); - } +void initBigVar3() { + int i; - filesDatabase[i].subData.ptr = NULL; - filesDatabase[i].subData.ptr2 = NULL; + for (i = 0; i < 257; i++) { + if (filesDatabase[i].subData.ptr) { + free(filesDatabase[i].subData.ptr); + } + + filesDatabase[i].subData.ptr = NULL; + filesDatabase[i].subData.ptr2 = NULL; - filesDatabase[i].subData.index = -1; - filesDatabase[i].subData.resourceType = 0; - } + filesDatabase[i].subData.index = -1; + filesDatabase[i].subData.resourceType = 0; + } } -void resetPtr2(scriptInstanceStruct* ptr) -{ - ptr->nextScriptPtr = NULL; - ptr->scriptNumber = -1; +void resetPtr2(scriptInstanceStruct *ptr) { + ptr->nextScriptPtr = NULL; + ptr->scriptNumber = -1; } -void resetActorPtr(actorStruct* ptr) -{ - ptr->next = NULL; - ptr->prev = NULL; +void resetActorPtr(actorStruct *ptr) { + ptr->next = NULL; + ptr->prev = NULL; } -ovlData3Struct* getOvlData3Entry(int32 scriptNumber, int32 param) -{ - ovlDataStruct* ovlData = overlayTable[scriptNumber].ovlData; +ovlData3Struct *getOvlData3Entry(int32 scriptNumber, int32 param) { + ovlDataStruct *ovlData = overlayTable[scriptNumber].ovlData; - if(!ovlData) - { - return NULL; - } + if (!ovlData) { + return NULL; + } - if(param<0) - { - return NULL; - } + if (param < 0) { + return NULL; + } - if(ovlData->numScripts1 <= param) - { - return NULL; - } + if (ovlData->numScripts1 <= param) { + return NULL; + } - if(!ovlData->data3Table) - { - return NULL; - } + if (!ovlData->data3Table) { + return NULL; + } - return(&ovlData->data3Table[param]); + return (&ovlData->data3Table[param]); } -ovlData3Struct* scriptFunc1Sub2(int32 scriptNumber, int32 param) -{ - ovlDataStruct* ovlData = overlayTable[scriptNumber].ovlData; +ovlData3Struct *scriptFunc1Sub2(int32 scriptNumber, int32 param) { + ovlDataStruct *ovlData = overlayTable[scriptNumber].ovlData; - if(!ovlData) - { - return NULL; - } + if (!ovlData) { + return NULL; + } - if(param<0) - { - return NULL; - } + if (param < 0) { + return NULL; + } - if(ovlData->numScripts2 <= param) - { - return NULL; - } + if (ovlData->numScripts2 <= param) { + return NULL; + } - if(!ovlData->ptr1) - { - return NULL; - } + if (!ovlData->ptr1) { + return NULL; + } - return((ovlData3Struct*)(ovlData->ptr1+param*0x1C)); + return ((ovlData3Struct *) (ovlData->ptr1 + param * 0x1C)); } -void scriptFunc2(int scriptNumber,scriptInstanceStruct* scriptHandle, int param, int param2) -{ - if(scriptHandle->nextScriptPtr) - { - if(scriptNumber == scriptHandle->nextScriptPtr->overlayNumber || scriptNumber != -1) - { - if(param2 == scriptHandle->nextScriptPtr->scriptNumber || param2 != -1) - { - scriptHandle->nextScriptPtr->sysKey = param; - } - } - } +void scriptFunc2(int scriptNumber, scriptInstanceStruct * scriptHandle, + int param, int param2) { + if (scriptHandle->nextScriptPtr) { + if (scriptNumber == scriptHandle->nextScriptPtr->overlayNumber + || scriptNumber != -1) { + if (param2 == scriptHandle->nextScriptPtr->scriptNumber + || param2 != -1) { + scriptHandle->nextScriptPtr->sysKey = param; + } + } + } } -uint8* getDataFromData3(ovlData3Struct* ptr, int param) -{ - uint8* dataPtr; - - if(!ptr) - return(NULL); - - dataPtr = ptr->dataPtr; - - if(!dataPtr) - return(NULL); - - switch(param) - { - case 0: - { - return(dataPtr); - } - case 1: - { - return(dataPtr + ptr->offsetToSubData3); // strings - } - case 2: - { - return(dataPtr + ptr->offsetToSubData2); - } - case 3: - { - return(dataPtr + ptr->offsetToImportData); // import data - } - case 4: - { - return(dataPtr + ptr->offsetToImportName); // import names - } - case 5: - { - return(dataPtr + ptr->offsetToSubData5); - } - default: - { - return(NULL); - } - } +uint8 *getDataFromData3(ovlData3Struct *ptr, int param) { + uint8 *dataPtr; + + if (!ptr) + return (NULL); + + dataPtr = ptr->dataPtr; + + if (!dataPtr) + return (NULL); + + switch (param) { + case 0: + { + return (dataPtr); + } + case 1: + { + return (dataPtr + ptr->offsetToSubData3); // strings + } + case 2: + { + return (dataPtr + ptr->offsetToSubData2); + } + case 3: + { + return (dataPtr + ptr->offsetToImportData); // import data + } + case 4: + { + return (dataPtr + ptr->offsetToImportName); // import names + } + case 5: + { + return (dataPtr + ptr->offsetToSubData5); + } + default: + { + return (NULL); + } + } } -void printInfoBlackBox(const char* string) -{ +void printInfoBlackBox(const char *string) { } -void waitForPlayerInput() -{ +void waitForPlayerInput() { } -void getFileExtention(const char* name,char* buffer) -{ - while(*name != '.' && *name) - { - name++; - } +void getFileExtention(const char *name, char *buffer) { + while (*name != '.' && *name) { + name++; + } - strcpy(buffer,name); + strcpy(buffer, name); } -void removeExtention(const char* name, char* buffer) // not like in original -{ - char* ptr; - - strcpy(buffer,name); +void removeExtention(const char *name, char *buffer) { // not like in original + char *ptr; + + strcpy(buffer, name); - ptr = strchr(buffer,'.'); + ptr = strchr(buffer, '.'); - if(ptr) - *ptr = 0; + if (ptr) + *ptr = 0; } int lastFileSize; -int loadFileSub1(uint8** ptr, uint8* name, uint8* ptr2) -{ - int i; - char buffer[256]; - int fileIdx; - int unpackedSize; - uint8* unpackedBuffer; - - for(i=0;i<64;i++) - { - if(mediumVar[i].ptr) - { - if(!strcmpuint8(mediumVar[i].name,name)) - { - printf("Unsupported code in loadFIleSub1 !\n"); - exit(1); - } - } - } - - getFileExtention((char*)name,buffer); - - if(!strcmp(buffer,".SPL")) - { - removeExtention((char*)name,buffer); - - // if(useH32) - { - strcatuint8(buffer,".H32"); - } - /* else - if(useAdlib) - { - strcatuint8(buffer,".ADL"); - } - else - { - strcatuint8(buffer,".HP"); - }*/ - } - else - { - strcpyuint8(buffer,name); - } - - fileIdx = findFileInDisks((uint8*)buffer); - - if(fileIdx<0) - return(-18); - - unpackedSize = loadFileVar1 = volumePtrToFileDescriptor[fileIdx].extSize + 2; - - // TODO: here, can unpack in gfx module buffer - unpackedBuffer = (uint8*)mallocAndZero(unpackedSize); - - if(!unpackedBuffer) - { - return(-2); - } +int loadFileSub1(uint8 **ptr, uint8 *name, uint8 *ptr2) { + int i; + char buffer[256]; + int fileIdx; + int unpackedSize; + uint8 *unpackedBuffer; + + for (i = 0; i < 64; i++) { + if (mediumVar[i].ptr) { + if (!strcmpuint8(mediumVar[i].name, name)) { + printf("Unsupported code in loadFIleSub1 !\n"); + exit(1); + } + } + } + + getFileExtention((char *)name, buffer); + + if (!strcmp(buffer, ".SPL")) { + removeExtention((char *)name, buffer); + + // if(useH32) + { + strcatuint8(buffer, ".H32"); + } + /* else + * if(useAdlib) + * { + * strcatuint8(buffer,".ADL"); + * } + * else + * { + * strcatuint8(buffer,".HP"); + * } */ + } else { + strcpyuint8(buffer, name); + } + + fileIdx = findFileInDisks((uint8 *) buffer); + + if (fileIdx < 0) + return (-18); + + unpackedSize = loadFileVar1 = + volumePtrToFileDescriptor[fileIdx].extSize + 2; + + // TODO: here, can unpack in gfx module buffer + unpackedBuffer = (uint8 *) mallocAndZero(unpackedSize); + + if (!unpackedBuffer) { + return (-2); + } lastFileSize = unpackedSize; - if(volumePtrToFileDescriptor[fileIdx].size +2 != unpackedSize) - { - unsigned short int realUnpackedSize; - uint8* tempBuffer; - uint8* pakedBuffer = (uint8*) mallocAndZero(volumePtrToFileDescriptor[fileIdx].size +2); + if (volumePtrToFileDescriptor[fileIdx].size + 2 != unpackedSize) { + unsigned short int realUnpackedSize; + uint8 *tempBuffer; + uint8 *pakedBuffer = + (uint8 *) mallocAndZero(volumePtrToFileDescriptor[fileIdx]. + size + 2); - loadPakedFileToMem(fileIdx,pakedBuffer); + loadPakedFileToMem(fileIdx, pakedBuffer); - realUnpackedSize = *(uint16*)(pakedBuffer+volumePtrToFileDescriptor[fileIdx].size-2); - flipShort((int16*)&realUnpackedSize); + realUnpackedSize = + *(uint16 *) (pakedBuffer + + volumePtrToFileDescriptor[fileIdx].size - 2); + flipShort((int16 *) & realUnpackedSize); - lastFileSize = realUnpackedSize; + lastFileSize = realUnpackedSize; - tempBuffer = (uint8*)mallocAndZero(realUnpackedSize); + tempBuffer = (uint8 *) mallocAndZero(realUnpackedSize); - decomp((uint8*)pakedBuffer+volumePtrToFileDescriptor[fileIdx].size-4,(uint8*)unpackedBuffer+realUnpackedSize,realUnpackedSize); + decomp((uint8 *) pakedBuffer + + volumePtrToFileDescriptor[fileIdx].size - 4, + (uint8 *) unpackedBuffer + realUnpackedSize, + realUnpackedSize); - free(pakedBuffer); - } - else - { - loadPakedFileToMem(fileIdx,unpackedBuffer); - } + free(pakedBuffer); + } else { + loadPakedFileToMem(fileIdx, unpackedBuffer); + } - *ptr = unpackedBuffer; + *ptr = unpackedBuffer; - return(1); + return (1); } -void resetFileEntry(int32 entryNumber) -{ - if(entryNumber>=257) - return; +void resetFileEntry(int32 entryNumber) { + if (entryNumber >= 257) + return; - if(!filesDatabase[entryNumber].subData.ptr) - return; + if (!filesDatabase[entryNumber].subData.ptr) + return; - free(filesDatabase[entryNumber].subData.ptr); + free(filesDatabase[entryNumber].subData.ptr); - filesDatabase[entryNumber].subData.ptr = NULL; - filesDatabase[entryNumber].subData.ptr2 = NULL; - filesDatabase[entryNumber].widthInColumn = 0; - filesDatabase[entryNumber].width = 0; - filesDatabase[entryNumber].resType = 0; - filesDatabase[entryNumber].height = 0; - filesDatabase[entryNumber].subData.index = -1; - filesDatabase[entryNumber].subData.resourceType = 0; - filesDatabase[entryNumber].subData.field_1C = 0; - filesDatabase[entryNumber].subData.name[0] = 0; + filesDatabase[entryNumber].subData.ptr = NULL; + filesDatabase[entryNumber].subData.ptr2 = NULL; + filesDatabase[entryNumber].widthInColumn = 0; + filesDatabase[entryNumber].width = 0; + filesDatabase[entryNumber].resType = 0; + filesDatabase[entryNumber].height = 0; + filesDatabase[entryNumber].subData.index = -1; + filesDatabase[entryNumber].subData.resourceType = 0; + filesDatabase[entryNumber].subData.field_1C = 0; + filesDatabase[entryNumber].subData.name[0] = 0; } -uint8* mainProc14(uint16 overlay, uint16 idx) -{ - ASSERT(0); - - return NULL; +uint8 *mainProc14(uint16 overlay, uint16 idx) { + ASSERT(0); + + return NULL; } -int initAllData(void) -{ - int i; - - setupFuncArray(); - setupOpcodeTable(); - initOverlayTable(); +int initAllData(void) { + int i; - setup1 = 0; - currentActiveBackgroundPlane = 0; + setupFuncArray(); + setupOpcodeTable(); + initOverlayTable(); - freeDisk(); + setup1 = 0; + currentActiveBackgroundPlane = 0; - initVar5[0] = -1; - initVar5[3] = -1; - initVar5[6] = -1; - initVar5[9] = -1; + freeDisk(); - menuTable[0] = NULL; + initVar5[0] = -1; + initVar5[3] = -1; + initVar5[6] = -1; + initVar5[9] = -1; - for(i=0;i<2000;i++) - { - globalVars[i] = 0; - } + menuTable[0] = NULL; - for(i=0;i<8;i++) - { - backgroundTable[i].name[0] = 0; - } + for (i = 0; i < 2000; i++) { + globalVars[i] = 0; + } - for(i=0;i<257;i++) - { - filesDatabase[i].subData.ptr = NULL; - filesDatabase[i].subData.ptr2 = NULL; - } + for (i = 0; i < 8; i++) { + backgroundTable[i].name[0] = 0; + } - initBigVar3(); + for (i = 0; i < 257; i++) { + filesDatabase[i].subData.ptr = NULL; + filesDatabase[i].subData.ptr2 = NULL; + } - resetPtr2(&scriptHandle2); - resetPtr2(&scriptHandle1); + initBigVar3(); - resetPtr(&cellHead); + resetPtr2(&scriptHandle2); + resetPtr2(&scriptHandle1); - resetActorPtr(&actorHead); - resetBackgroundIncrustList(&backgroundIncrustHead); + resetPtr(&cellHead); - bootOverlayNumber = loadOverlay((uint8*)"AUTO00"); + resetActorPtr(&actorHead); + resetBackgroundIncrustList(&backgroundIncrustHead); + + bootOverlayNumber = loadOverlay((uint8 *) "AUTO00"); #ifdef DUMP_SCRIPT loadOverlay("TITRE"); @@ -627,724 +576,801 @@ int initAllData(void) //exit(1); #endif - if(bootOverlayNumber) - { - positionInStack = 0; + if (bootOverlayNumber) { + positionInStack = 0; - attacheNewScriptToTail(bootOverlayNumber,&scriptHandle2,0,20,0,0,scriptType_20); - scriptFunc2(bootOverlayNumber,&scriptHandle2,1,0); - } + attacheNewScriptToTail(bootOverlayNumber, &scriptHandle2, 0, + 20, 0, 0, scriptType_20); + scriptFunc2(bootOverlayNumber, &scriptHandle2, 1, 0); + } - strcpyuint8(systemStrings.bootScriptName,"AUTO00"); + strcpyuint8(systemStrings.bootScriptName, "AUTO00"); - return(bootOverlayNumber); + return (bootOverlayNumber); } -int removeFinishedScripts(scriptInstanceStruct* ptrHandle) -{ - scriptInstanceStruct* ptr = ptrHandle->nextScriptPtr; // can't destruct the head - scriptInstanceStruct* oldPtr = ptrHandle; - - if(!ptr) - return(0); - - do - { - if(ptr->scriptNumber == -1) - { - oldPtr->nextScriptPtr = ptr->nextScriptPtr; - - if(ptr->var6 && ptr->varA) - { - // free(ptr->var6); - } - - free(ptr); - - ptr = oldPtr->nextScriptPtr; - } - else - { - oldPtr = ptr; - ptr = ptr->nextScriptPtr; - } - }while(ptr); - - return(0); +int removeFinishedScripts(scriptInstanceStruct *ptrHandle) { + scriptInstanceStruct *ptr = ptrHandle->nextScriptPtr; // can't destruct the head + scriptInstanceStruct *oldPtr = ptrHandle; + + if (!ptr) + return (0); + + do { + if (ptr->scriptNumber == -1) { + oldPtr->nextScriptPtr = ptr->nextScriptPtr; + + if (ptr->var6 && ptr->varA) { + // free(ptr->var6); + } + + free(ptr); + + ptr = oldPtr->nextScriptPtr; + } else { + oldPtr = ptr; + ptr = ptr->nextScriptPtr; + } + } while (ptr); + + return (0); } int nePasAffichierMenuDialogue; int var37 = 0; int var38 = 0; -int getCursorFromObject(int mouseX, int mouseY, int* outX, int* outY) -{ - int16 var_2; - int16 var_4; - int16 var_14; - int16 var_16; - objectParamsQuery params; - int16 var_10; - int16 var_E; - int16 var_C; +int getCursorFromObject(int mouseX, int mouseY, int *outX, int *outY) { + int16 var_2; + int16 var_4; + int16 var_14; + int16 var_16; + objectParamsQuery params; + int16 var_10; + int16 var_E; + int16 var_C; // int16 var_42; - int16 var_A; - int16 var_6; - - char objectName[80]; - - cellStruct* currentObject = cellHead.prev; - - while(currentObject) - { - if(currentObject->overlay >= 0) - { - if(overlayTable[currentObject->overlay].alreadyLoaded) - { - if(currentObject->type == 4 || currentObject->type == 1 || currentObject->type == 9 || currentObject->type == 3) - { - strcpy(objectName, getObjectName(currentObject->idx, overlayTable[currentObject->overlay].ovlData->specialString2)); - - if(strlen(objectName)) - { - if(currentObject->freeze == 0) - { - var_2 = currentObject->idx; - var_4 = currentObject->overlay; - var_14 = currentObject->followObjectIdx; - var_16 = currentObject->followObjectOverlayIdx; - - getMultipleObjectParam(currentObject->overlay, currentObject->idx, ¶ms); - - var_10 = 0; - var_E = 0; - var_C = 0; - - if((var_4 != var_16) && (var_2 != var_14)) - { - getMultipleObjectParam(var_16, var_14, ¶ms); - - var_C = params.X; - var_E = params.Y; - var_10 = params.fileIdx; - } - - if(params.var5 >= 0 && params.fileIdx >= 0) - { - if(currentObject->type == 3) - { - assert(0); - - var_2 = params.scale; - var_A = params.X + var_C; - - // TODO: this var3 is stupid, investigate... - if((var_A <= mouseX) && (var_A + params.fileIdx >= mouseX) && (mouseY >= params.Y + var_E) && (params.Y + var_E + var2 >= mouseY)) - { - *outX = var_16; - *outY = var_14; - - return(currentObject->type); - } - } - else - if(currentObject->type == 4 || currentObject->type == 1 || currentObject->type == 9 ) - { - int si; - int var_8; - int di; - - var_A = params.X + var_C; - var_6 = params.Y + var_E; - - di = params.fileIdx; - - if(di<0) - { - di += var_10; - } + int16 var_A; + int16 var_6; + + char objectName[80]; + + cellStruct *currentObject = cellHead.prev; + + while (currentObject) { + if (currentObject->overlay >= 0) { + if (overlayTable[currentObject->overlay].alreadyLoaded) { + if (currentObject->type == 4 + || currentObject->type == 1 + || currentObject->type == 9 + || currentObject->type == 3) { + strcpy(objectName, + getObjectName(currentObject->idx, + overlayTable[currentObject-> + overlay].ovlData-> + specialString2)); + + if (strlen(objectName)) { + if (currentObject->freeze == 0) { + var_2 = + currentObject->idx; + var_4 = + currentObject-> + overlay; + var_14 = + currentObject-> + followObjectIdx; + var_16 = + currentObject-> + followObjectOverlayIdx; + + getMultipleObjectParam + (currentObject-> + overlay, + currentObject->idx, + ¶ms); + + var_10 = 0; + var_E = 0; + var_C = 0; + + if ((var_4 != var_16) + && (var_2 != + var_14)) { + getMultipleObjectParam + (var_16, + var_14, + ¶ms); + + var_C = + params.X; + var_E = + params.Y; + var_10 = + params. + fileIdx; + } + + if (params.var5 >= 0 + && params. + fileIdx >= 0) { + if (currentObject->type == 3) { + assert + (0); + + var_2 = + params. + scale; + var_A = + params. + X + + var_C; + + // TODO: this var3 is stupid, investigate... + if ((var_A <= mouseX) && (var_A + params.fileIdx >= mouseX) && (mouseY >= params.Y + var_E) && (params.Y + var_E + var2 >= mouseY)) { + *outX + = + var_16; + *outY + = + var_14; + + return + (currentObject-> + type); + } + } else + if + (currentObject-> + type == 4 + || + currentObject-> + type == 1 + || + currentObject-> + type == + 9) { + int si; + int var_8; + int di; + + var_A = + params. + X + + var_C; + var_6 = + params. + Y + + var_E; + + di = params.fileIdx; + + if (di + < + 0) + { + di += var_10; + } /* if((filesDatabase[di].subData.resourceType == 8) && (filesDatabase[di].subData.ptr)) { assert(0); } else */ - { - var_4 = filesDatabase[di].resType; - - if(var_4 == 1) - { - var_C = filesDatabase[di].widthInColumn/2; - } - else - { - var_C = filesDatabase[di].width; - } - - var_8 = filesDatabase[di].height; - - var_2 = mouseX - var_A; - si = mouseY - var_6; - - if(var_2>0) - { - if(var_C>var_2) - { - if(si>0) - { - if(var_8>=si) - { - if(filesDatabase[di].subData.ptr) - { - if(var_4 == 1) - { - } - else - { - } - - printf("should compare to mask in getCursorFromObject...\n"); - - *outX = var_16; - *outY = var_14; - - printf("Selected: %s\n", objectName); - - return currentObject->type; - } - } - } - } - } - } - } - } - } - } - } - } - } + { + var_4 + = + filesDatabase + [di]. + resType; + + if (var_4 == 1) { + var_C + = + filesDatabase + [di]. + widthInColumn + / + 2; + } else { + var_C + = + filesDatabase + [di]. + width; + } + + var_8 + = + filesDatabase + [di]. + height; + + var_2 + = + mouseX + - + var_A; + si = mouseY - var_6; + + if (var_2 > 0) { + if (var_C > var_2) { + if (si > 0) { + if (var_8 >= si) { + if (filesDatabase[di].subData.ptr) { + if (var_4 == 1) { + } else { + } + + printf + ("should compare to mask in getCursorFromObject...\n"); + + *outX + = + var_16; + *outY + = + var_14; + + printf + ("Selected: %s\n", + objectName); + + return + currentObject-> + type; + } + } + } + } + } + } + } + } + } + } + } + } + } - currentObject = currentObject->prev; - } + currentObject = currentObject->prev; + } - *outX = 0; - *outY = 0; + *outX = 0; + *outY = 0; - return -1; + return -1; } char keyboardVar = 0; -void freeStuff2(void) -{ - printf("implement freeStuff2\n"); +void freeStuff2(void) { + printf("implement freeStuff2\n"); } -void *allocAndZero(int size) -{ - void *ptr; +void *allocAndZero(int size) { + void *ptr; - ptr = malloc(size); - memset(ptr,0,size); + ptr = malloc(size); + memset(ptr, 0, size); - return ptr; + return ptr; } -char* getObjectName(int index, uint8* string) -{ - int i; - char* ptr = (char*)string; - - if(!string) - return NULL; - - for(i=0;i<index;i++) - { - while(*ptr) - { - ptr++; - } - ptr++; - } - return ptr; +char *getObjectName(int index, uint8 *string) { + int i; + char *ptr = (char *)string; + + if (!string) + return NULL; + + for (i = 0; i < index; i++) { + while (*ptr) { + ptr++; + } + ptr++; + } + return ptr; } -int buildInventorySub1(int overlayIdx, int objIdx) -{ - objDataStruct* pObjectData = getObjectDataFromOverlay(overlayIdx, objIdx); - - if(pObjectData) - { - return pObjectData->var1; - } - else - { - return -11; - } +int buildInventorySub1(int overlayIdx, int objIdx) { + objDataStruct *pObjectData = + getObjectDataFromOverlay(overlayIdx, objIdx); + + if (pObjectData) { + return pObjectData->var1; + } else { + return -11; + } } -void buildInventory(int X, int Y) -{ - int numObjectInInventory = 0; - menuStruct* pMenu; - - pMenu = createMenu(X, Y, "Inventaire"); - - menuTable[1] = pMenu; - - if(pMenu) - { - numObjectInInventory = 0; - - if(numOfLoadedOverlay > 1) - { - int i; - - for(i=1;i<numOfLoadedOverlay;i++) - { - ovlDataStruct* pOvlData = overlayTable[i].ovlData; - - if(pOvlData && pOvlData->objDataTable) - { - int var_2; - - var_2 = 0; - - if(pOvlData->numObjData) - { - int j; - - for(j=0;j<pOvlData->numObjData;j++) - { - if(buildInventorySub1(i,j) != 3) - { - int16 returnVar; - - getSingleObjectParam(i,j,5,&returnVar); - - if(returnVar<-1) - { - addSelectableMenuEntry(i,j,pMenu,1,-1,getObjectName(j, pOvlData->specialString2)); - numObjectInInventory++; - } - } - } - } - } - } - } - } - - if(numObjectInInventory == 0) - { - freeMenu(menuTable[1]); - menuTable[1] = NULL; - } +void buildInventory(int X, int Y) { + int numObjectInInventory = 0; + menuStruct *pMenu; + + pMenu = createMenu(X, Y, "Inventaire"); + + menuTable[1] = pMenu; + + if (pMenu) { + numObjectInInventory = 0; + + if (numOfLoadedOverlay > 1) { + int i; + + for (i = 1; i < numOfLoadedOverlay; i++) { + ovlDataStruct *pOvlData = + overlayTable[i].ovlData; + + if (pOvlData && pOvlData->objDataTable) { + int var_2; + + var_2 = 0; + + if (pOvlData->numObjData) { + int j; + + for (j = 0; + j < pOvlData->numObjData; + j++) { + if (buildInventorySub1 + (i, j) != 3) { + int16 + returnVar; + + getSingleObjectParam + (i, j, 5, + &returnVar); + + if (returnVar < + -1) { + addSelectableMenuEntry + (i, + j, + pMenu, + 1, + -1, + getObjectName + (j, pOvlData->specialString2)); + numObjectInInventory++; + } + } + } + } + } + } + } + } + + if (numObjectInInventory == 0) { + freeMenu(menuTable[1]); + menuTable[1] = NULL; + } } int currentMenuElementX; int currentMenuElementY; -menuElementStruct* currentMenuElement; +menuElementStruct *currentMenuElement; -menuElementSubStruct* getSelectedEntryInMenu(menuStruct* pMenu) -{ - menuElementStruct* pMenuElement; +menuElementSubStruct *getSelectedEntryInMenu(menuStruct *pMenu) { + menuElementStruct *pMenuElement; - if(pMenu == NULL) - { - return NULL; - } + if (pMenu == NULL) { + return NULL; + } - if(pMenu->numElements == 0) - { - return NULL; - } + if (pMenu->numElements == 0) { + return NULL; + } - pMenuElement = pMenu->ptrNextElement; + pMenuElement = pMenu->ptrNextElement; - while(pMenuElement) - { - if(pMenuElement->varC) - { - currentMenuElementX = pMenuElement->x; - currentMenuElementY = pMenuElement->y; - currentMenuElement = pMenuElement; + while (pMenuElement) { + if (pMenuElement->varC) { + currentMenuElementX = pMenuElement->x; + currentMenuElementY = pMenuElement->y; + currentMenuElement = pMenuElement; - return pMenuElement->ptrSub; - } + return pMenuElement->ptrSub; + } - pMenuElement = pMenuElement->next; - } + pMenuElement = pMenuElement->next; + } - return NULL; + return NULL; } -int callInventoryObject(int param0, int param1, int x, int y) -{ - int var_2C; - int var_30; - int var_28; - int var_1E; - int16 returnVar; - - var_30 = -1; - - getSingleObjectParam(param0,param1,5,&returnVar); - - var_2C = 0; - var_28 = 1; - - for(var_1E=1;var_1E<numOfLoadedOverlay;var_1E++) - { - ovlDataStruct* var_2A = overlayTable[var_1E].ovlData; - if(var_2A->ptr1) - { - int var_18; - int var_14; - - var_18 = var_2A->numLinkData; - - if(var_18) - { - int var_16; - - var_16 = 0; - - for(var_14 = 0; var_14 < var_18;var_14++) - { - objDataStruct* pObject; - linkDataStruct* var_34; - int var_2; - - var_34 = &var_2A->linkDataPtr[var_14]; - - var_2 = var_34->stringIdx; - - if(!var_2) - { - var_2 = var_1E; - } - - pObject = getObjectDataFromOverlay(var_2,var_34->stringNameOffset); - - if(var_2 == param0) - { - if(param1 == var_34->stringNameOffset) - { - if(pObject) - { - if(pObject->var1 != 3) - { - char var_214[80]; - char var_1C4[80]; - char var_174[80]; - char var_124[80]; - char var_D4[80]; - char var_84[80]; - - ovlDataStruct* var_12; - ovlDataStruct* var_22; - - int var_E = var_34->varIdx; - int cx = var_34->stringIdx; - int var_C = var_34->procIdx; - - int di = var_E; - if(var_E == 0) - di = var_1E; - - var_2 = cx; - if(cx == 0) - var_2 = var_1E; - - if(var_C == 0) - var_C = var_1E; - - var_12 = NULL; - var_22 = NULL; - - var_214[0] = 0; - var_1C4[0] = 0; - var_174[0] = 0; - var_124[0] = 0; - var_D4[0] = 0; - var_84[0] = 0; - - if(di>0) - { - var_22 = overlayTable[di].ovlData; - } +int callInventoryObject(int param0, int param1, int x, int y) { + int var_2C; + int var_30; + int var_28; + int var_1E; + int16 returnVar; + + var_30 = -1; + + getSingleObjectParam(param0, param1, 5, &returnVar); + + var_2C = 0; + var_28 = 1; + + for (var_1E = 1; var_1E < numOfLoadedOverlay; var_1E++) { + ovlDataStruct *var_2A = overlayTable[var_1E].ovlData; + if (var_2A->ptr1) { + int var_18; + int var_14; + + var_18 = var_2A->numLinkData; + + if (var_18) { + int var_16; + + var_16 = 0; + + for (var_14 = 0; var_14 < var_18; var_14++) { + objDataStruct *pObject; + linkDataStruct *var_34; + int var_2; + + var_34 = &var_2A->linkDataPtr[var_14]; + + var_2 = var_34->stringIdx; + + if (!var_2) { + var_2 = var_1E; + } + + pObject = + getObjectDataFromOverlay(var_2, + var_34->stringNameOffset); + + if (var_2 == param0) { + if (param1 == + var_34->stringNameOffset) { + if (pObject) { + if (pObject-> + var1 != + 3) { + char var_214[80]; + char var_1C4[80]; + char var_174[80]; + char var_124[80]; + char var_D4[80]; + char var_84[80]; + + ovlDataStruct + *var_12; + ovlDataStruct + *var_22; + + int var_E = var_34->varIdx; + int cx + = + var_34-> + stringIdx; + int var_C = var_34->procIdx; + + int di + = + var_E; + if (var_E == 0) + di = var_1E; + + var_2 = + cx; + if (cx + == + 0) + var_2 + = + var_1E; + + if (var_C == 0) + var_C + = + var_1E; + + var_12 + = + NULL; + var_22 + = + NULL; + + var_214 + [0] + = + 0; + var_1C4 + [0] + = + 0; + var_174 + [0] + = + 0; + var_124 + [0] + = + 0; + var_D4 + [0] + = + 0; + var_84 + [0] + = + 0; + + if (di + > + 0) + { + var_22 + = + overlayTable + [di]. + ovlData; + } + + if (var_2 > 0) { + var_12 + = + overlayTable + [var_2]. + ovlData; + } + + if (var_12) { + if (var_34->stringNameOffset) { + var_30 + = + var_34-> + field_1A; + if (var_28) { + if (var_12->specialString2) { + if (var_30 == -1 || var_30 == returnVar) { + char *ptrName = getObjectName(var_34->stringNameOffset, var_12->specialString2); + + menuTable + [0] + = + createMenu + (x, + y, + ptrName); + var_28 + = + 0; + } + } + } + } + } + + if (var_22) { + if (true /*var_34->varNameOffset>=0 */ ) // FIXME: This check is always true since varNameOffset is unsigned + { + if (var_22->specialString1) { + char *ptr = getObjectName(var_34->varNameOffset, var_22->specialString1); + + strcpy + (var_214, + ptr); + + if (var_28 == 0) { + if (var_30 == -1 || var_30 == returnVar) { + if (strlen(var_214)) { + attacheNewScriptToTail + (var_1E, + &scriptHandle1, + var_34-> + field_2, + 30, + currentScriptPtr-> + scriptNumber, + currentScriptPtr-> + overlayNumber, + scriptType_30); + } else { + if (var_22->specialString1) { + ptr = getObjectName(var_34->varNameOffset, var_22->specialString1); + + var_2C + = + 1; + + addSelectableMenuEntry + (var_1E, + var_14, + menuTable + [0], + 1, + -1, + ptr); + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } - if(var_2>0) - { - var_12 = overlayTable[var_2].ovlData; - } + return var_2C; +} - if(var_12) - { - if(var_34->stringNameOffset) - { - var_30 = var_34->field_1A; - if(var_28) - { - if(var_12->specialString2) - { - if(var_30==-1 || var_30 == returnVar) - { - char* ptrName = getObjectName(var_34->stringNameOffset, var_12->specialString2); - - menuTable[0] = createMenu(x,y,ptrName); - var_28 = 0; - } - } - } - } - } +int processInventory(void) { + if (menuTable[1]) { + menuElementSubStruct *pMenuElementSub = + getSelectedEntryInMenu(menuTable[1]); - if(var_22) - { - if(true /*var_34->varNameOffset>=0*/) // FIXME: This check is always true since varNameOffset is unsigned - { - if(var_22->specialString1) - { - char* ptr = getObjectName(var_34->varNameOffset, var_22->specialString1); - - strcpy(var_214, ptr); - - if(var_28 == 0) - { - if(var_30 ==-1 || var_30 == returnVar) - { - if(strlen(var_214)) - { - attacheNewScriptToTail(var_1E,&scriptHandle1,var_34->field_2, 30, currentScriptPtr->scriptNumber,currentScriptPtr->overlayNumber, scriptType_30); - } - else - { - if(var_22->specialString1) - { - ptr = getObjectName(var_34->varNameOffset, var_22->specialString1); - - var_2C = 1; - - addSelectableMenuEntry(var_1E, var_14, menuTable[0], 1, -1, ptr); - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - - return var_2C; + if (pMenuElementSub) { + //int var2; + //int var4; + + var2 = pMenuElementSub->var2; + var4 = pMenuElementSub->var4; + + freeMenu(menuTable[1]); + menuTable[1] = NULL; + + callInventoryObject(var2, var4, + currentMenuElementX + 80, currentMenuElementY); + + return 1; + } else { + freeMenu(menuTable[1]); + menuTable[1] = NULL; + } + } + + return 0; } -int processInventory(void) -{ - if(menuTable[1]) - { - menuElementSubStruct* pMenuElementSub = getSelectedEntryInMenu(menuTable[1]); +int processInput(void) { + menuStruct *var_5C; - if(pMenuElementSub) - { - //int var2; - //int var4; + int16 mouseX = 0; + int16 mouseY = 0; + int16 button = 0; - var2 = pMenuElementSub->var2; - var4 = pMenuElementSub->var4; + /*if(inputSub1keyboad()) + * { + * return 1; + * } */ - freeMenu(menuTable[1]); - menuTable[1] = NULL; + button = 0; - callInventoryObject(var2, var4, currentMenuElementX+80, currentMenuElementY); + if (sysKey != -1) { + button = sysKey; + mouseX = var11; + mouseY = var12; + sysKey = -1; + } else { + if (automaticMode == 0) { + getMouseStatus(&main10, &mouseX, &button, &mouseY); + } + } - return 1; - } - else - { - freeMenu(menuTable[1]); - menuTable[1] = NULL; - } - } + if (button) { + nePasAffichierMenuDialogue = 0; + } - return 0; -} + if (userDelay) { + userDelay--; + return 0; + } + // test both buttons + + if (((button & 3) == 3) || keyboardVar == 0x44 || keyboardVar == 0x53) { + changeCursor(0); + keyboardVar = 0; + return (playerMenu(mouseX, mouseY)); + } + + if (!userEnabled) { + return 0; + } + + if (currentActiveMenu != -1) { + var_5C = menuTable[currentActiveMenu]; + + if (var_5C) { + updateMenuMouse(mouseX, mouseY, var_5C); + } + } + + if (var6) { + ASSERT(0); + } + + if (button & 1) { + if (nePasAffichierMenuDialogue == 0) { + nePasAffichierMenuDialogue = 1; -int processInput(void) -{ - menuStruct* var_5C; - - int16 mouseX = 0; - int16 mouseY = 0; - int16 button = 0; - - /*if(inputSub1keyboad()) - { - return 1; - }*/ - - button = 0; - - if(sysKey != -1) - { - button = sysKey; - mouseX = var11; - mouseY = var12; - sysKey = -1; - } - else - { - if(automaticMode == 0) - { - getMouseStatus(&main10, &mouseX, &button, &mouseY); - } - } - - if(button) - { - nePasAffichierMenuDialogue = 0; - } - - if(userDelay) - { - userDelay--; - return 0; - } - - // test both buttons - - if(((button&3) == 3) || keyboardVar == 0x44 || keyboardVar == 0x53) - { - changeCursor(0); - keyboardVar = 0; - return(playerMenu(mouseX, mouseY)); - } - - if(!userEnabled) - { - return 0; - } - - if(currentActiveMenu != -1) - { - var_5C = menuTable[currentActiveMenu]; - - if(var_5C) - { - updateMenuMouse(mouseX,mouseY,var_5C); - } - } - - if(var6) - { - ASSERT(0); - } - - if(button & 1) - { - if(nePasAffichierMenuDialogue == 0) - { - nePasAffichierMenuDialogue = 1; - - if(mouseVar1) - { - ASSERT(0); - } - - if(var38 == 0) // are we in inventory mode ? - { - if(menuTable[0] == 0) - { - int X; - int Y; - int objIdx; - - objIdx = getCursorFromObject(mouseX, mouseY, &X, &Y); - - if(objIdx != -1) - { - //ASSERT(0); - //moveActor(X,Y,mouseVar1); - } - else - { - var34 = mouseX; - var35 = mouseY; - animationStart=true; - var38=0; - } - } - //ASSERT(0); - } - else - { - if(processInventory()) - { - var37 = 1; - currentActiveMenu = 0; - var38 = 0; - } - else - { - currentActiveMenu = -1; - var38 = 0; - } - - return 0; - } - - //ASSERT(0); - } - } - - if((button & 2) || (keyboardVar == 0x43) || (keyboardVar == 0x52)) - { - if(nePasAffichierMenuDialogue == 0) - { - keyboardVar = 0; - - if((mouseVar1 == 0) && (menuTable[0])) - { - ASSERT(0); - freeMenu(menuTable[0]); - menuTable[0] = NULL; - var37 = 0; - var38 = 0; - currentActiveMenu = -1; - } - - if(var37 || var38 || menuTable[1]) - { - nePasAffichierMenuDialogue = 1; - return 0; - } - - buildInventory(mouseX, mouseY); - - if(menuTable[1]) - { - currentActiveMenu = 1; - var38 = 1; - } - else - { - var38 = 1; - } - - nePasAffichierMenuDialogue = 1; - return 0; - } - } - return 0; + if (mouseVar1) { + ASSERT(0); + } + + if (var38 == 0) // are we in inventory mode ? + { + if (menuTable[0] == 0) { + int X; + int Y; + int objIdx; + + objIdx = + getCursorFromObject(mouseX, mouseY, + &X, &Y); + + if (objIdx != -1) { + //ASSERT(0); + //moveActor(X,Y,mouseVar1); + } else { + var34 = mouseX; + var35 = mouseY; + animationStart = true; + var38 = 0; + } + } + //ASSERT(0); + } else { + if (processInventory()) { + var37 = 1; + currentActiveMenu = 0; + var38 = 0; + } else { + currentActiveMenu = -1; + var38 = 0; + } + + return 0; + } + + //ASSERT(0); + } + } + + if ((button & 2) || (keyboardVar == 0x43) || (keyboardVar == 0x52)) { + if (nePasAffichierMenuDialogue == 0) { + keyboardVar = 0; + + if ((mouseVar1 == 0) && (menuTable[0])) { + ASSERT(0); + freeMenu(menuTable[0]); + menuTable[0] = NULL; + var37 = 0; + var38 = 0; + currentActiveMenu = -1; + } + + if (var37 || var38 || menuTable[1]) { + nePasAffichierMenuDialogue = 1; + return 0; + } + + buildInventory(mouseX, mouseY); + + if (menuTable[1]) { + currentActiveMenu = 1; + var38 = 1; + } else { + var38 = 1; + } + + nePasAffichierMenuDialogue = 1; + return 0; + } + } + return 0; } int oldMouseX; @@ -1353,98 +1379,98 @@ int oldMouseY; void manageEvents(int count) { Common::Event event; - Common::EventManager *eventMan = g_system->getEventManager(); + Common::EventManager * eventMan = g_system->getEventManager(); while (eventMan->pollEvent(event)) { switch (event.type) { - /* case Common::EVENT_LBUTTONDOWN: - mouseLeft = 1; - break; - case Common::EVENT_RBUTTONDOWN: - mouseRight = 1; - break; - case Common::EVENT_MOUSEMOVE: - break;*/ + /* case Common::EVENT_LBUTTONDOWN: + * mouseLeft = 1; + * break; + * case Common::EVENT_RBUTTONDOWN: + * mouseRight = 1; + * break; + * case Common::EVENT_MOUSEMOVE: + * break; */ case Common::EVENT_QUIT: g_system->quit(); break; - /* case Common::EVENT_KEYDOWN: - switch (event.kbd.keycode) { - case '\n': - case '\r': - case 261: // Keypad 5 - if (allowPlayerInput) { - mouseLeft = 1; - } - break; - case 27: // ESC - if (allowPlayerInput) { - mouseRight = 1; - } - break; - case 282: // F1 - if (allowPlayerInput) { - playerCommand = 0; // EXAMINE - makeCommandLine(); - } - break; - case 283: // F2 - if (allowPlayerInput) { - playerCommand = 1; // TAKE - makeCommandLine(); - } - break; - case 284: // F3 - if (allowPlayerInput) { - playerCommand = 2; // INVENTORY - makeCommandLine(); - } - break; - case 285: // F4 - if (allowPlayerInput) { - playerCommand = 3; // USE - makeCommandLine(); - } - break; - case 286: // F5 - if (allowPlayerInput) { - playerCommand = 4; // ACTIVATE - makeCommandLine(); - } - break; - case 287: // F6 - if (allowPlayerInput) { - playerCommand = 5; // SPEAK - makeCommandLine(); - } - break; - case 290: // F9 - if (allowPlayerInput && !inMenu) { - makeActionMenu(); - makeCommandLine(); - } - break; - case 291: // F10 - if (!disableSystemMenu && !inMenu) { - g_cine->makeSystemMenu(); - } - break; - default: - //lastKeyStroke = event.kbd.keycode; - break; - } - break; */ + /* case Common::EVENT_KEYDOWN: + * switch (event.kbd.keycode) { + * case '\n': + * case '\r': + * case 261: // Keypad 5 + * if (allowPlayerInput) { + * mouseLeft = 1; + * } + * break; + * case 27: // ESC + * if (allowPlayerInput) { + * mouseRight = 1; + * } + * break; + * case 282: // F1 + * if (allowPlayerInput) { + * playerCommand = 0; // EXAMINE + * makeCommandLine(); + * } + * break; + * case 283: // F2 + * if (allowPlayerInput) { + * playerCommand = 1; // TAKE + * makeCommandLine(); + * } + * break; + * case 284: // F3 + * if (allowPlayerInput) { + * playerCommand = 2; // INVENTORY + * makeCommandLine(); + * } + * break; + * case 285: // F4 + * if (allowPlayerInput) { + * playerCommand = 3; // USE + * makeCommandLine(); + * } + * break; + * case 286: // F5 + * if (allowPlayerInput) { + * playerCommand = 4; // ACTIVATE + * makeCommandLine(); + * } + * break; + * case 287: // F6 + * if (allowPlayerInput) { + * playerCommand = 5; // SPEAK + * makeCommandLine(); + * } + * break; + * case 290: // F9 + * if (allowPlayerInput && !inMenu) { + * makeActionMenu(); + * makeCommandLine(); + * } + * break; + * case 291: // F10 + * if (!disableSystemMenu && !inMenu) { + * g_cine->makeSystemMenu(); + * } + * break; + * default: + * //lastKeyStroke = event.kbd.keycode; + * break; + * } + * break; */ default: break; } } /*if (count) { - mouseData.left = mouseLeft; - mouseData.right = mouseRight; - mouseLeft = 0; - mouseRight = 0; - } -*/ + * mouseData.left = mouseLeft; + * mouseData.right = mouseRight; + * mouseLeft = 0; + * mouseRight = 0; + * } + */ int i; for (i = 0; i < count; i++) { @@ -1457,225 +1483,212 @@ void manageEvents(int count) { g_system->updateScreen(); g_system->delayMillis(10); manageEvents(0); - } + } } -void mainLoop(void) -{ - #define SPEED 40 /* Ticks per Frame */ - #define SLEEP_MIN 20 /* Minimum time a sleep takes, usually 2*GRAN */ - #define SLEEP_GRAN 1 /* Granularity of sleep */ - - int frames=0; /* Number of frames displayed */ - //int32 t_start,t_left; - //uint32 t_end; - //int32 q=0; /* Dummy */ - - int enableUser = 0; - //int16 mouseX; - //int16 mouseY; - //int16 mouseButton; - - scriptNameBuffer[0] = 0; - systemStrings.bootScriptName[0] = 0; - initVar4[0] = 0; - currentActiveMenu = -1; - main14 = -1; - mouseVar1 = 0; - main21 = 0; - main22 = 0; - main7 = 0; - main8 = 0; - main15 = 0; - - if(initAllData()) - { - int playerDontAskQuit = 1; - int quitValue2 = 1; - int quitValue = 0; - - do - { - frames++; +void mainLoop(void) { +#define SPEED 40 /* Ticks per Frame */ +#define SLEEP_MIN 20 /* Minimum time a sleep takes, usually 2*GRAN */ +#define SLEEP_GRAN 1 /* Granularity of sleep */ + + int frames = 0; /* Number of frames displayed */ + //int32 t_start,t_left; + //uint32 t_end; + //int32 q=0; /* Dummy */ + + int enableUser = 0; + //int16 mouseX; + //int16 mouseY; + //int16 mouseButton; + + scriptNameBuffer[0] = 0; + systemStrings.bootScriptName[0] = 0; + initVar4[0] = 0; + currentActiveMenu = -1; + main14 = -1; + mouseVar1 = 0; + main21 = 0; + main22 = 0; + main7 = 0; + main8 = 0; + main15 = 0; + + if (initAllData()) { + int playerDontAskQuit = 1; + int quitValue2 = 1; + int quitValue = 0; + + do { + frames++; // t_start=Osystem_GetTicks(); // readKeyboard(); - playerDontAskQuit = processInput(); + playerDontAskQuit = processInput(); - //if(enableUser) - { - userEnabled = 1; - enableUser = 0; - } - - manageScripts(&scriptHandle1); - manageScripts(&scriptHandle2); + //if(enableUser) + { + userEnabled = 1; + enableUser = 0; + } - removeFinishedScripts(&scriptHandle1); - removeFinishedScripts(&scriptHandle2); + manageScripts(&scriptHandle1); + manageScripts(&scriptHandle2); - processAnimation(); + removeFinishedScripts(&scriptHandle1); + removeFinishedScripts(&scriptHandle2); - if(var0) - { - // ASSERT(0); - /* main3 = 0; - var24 = 0; - var23 = 0; + processAnimation(); - freeStuff2(); */ - } + if (var0) { + // ASSERT(0); + /* main3 = 0; + * var24 = 0; + * var23 = 0; + * + * freeStuff2(); */ + } - if(initVar4[0]) - { - ASSERT(0); + if (initVar4[0]) { + ASSERT(0); /* redrawStrings(0,&initVar4,8); waitForPlayerInput(); initVar4 = 0; */ - } + } - if(affichePasMenuJoueur) - { - if(main5) - fadeVar = 0; + if (affichePasMenuJoueur) { + if (main5) + fadeVar = 0; - /*if(fadeVar) - { - // TODO! - }*/ + /*if(fadeVar) + * { + * // TODO! + * } */ mainDraw(0); flipScreen(); - /* if(userEnabled && !main7 && !main15 && currentActiveMenu == -1) - { - getMouseStatus(&main10, &mouseX, &mouseButton, &mouseY); - - if(mouseX != oldMouseX && mouseY != oldMouseY) - { - int cursorType; - int newCursor1; - int newCursor2; - - oldMouseX = mouseX; - oldMouseY = mouseY; - - cursorType = getCursorFromObject(mouseX, mouseY, &newCursor1, &newCursor2); - - if(cursorType == 9) - { - changeCursor(5); - } - else - if(cursorType == -1) - { - changeCursor(6); - } - else - { - changeCursor(4); - } - - } - } - else*/ - { - changeCursor(0); - } - - if(main7) - { - ASSERT(0); - } - - if(main15) - { - ASSERT(0); - } - - if(main14 != -1) - { - ASSERT(0); - } - } - - // t_end = t_start+SPEED; + /* if(userEnabled && !main7 && !main15 && currentActiveMenu == -1) + * { + * getMouseStatus(&main10, &mouseX, &mouseButton, &mouseY); + * + * if(mouseX != oldMouseX && mouseY != oldMouseY) + * { + * int cursorType; + * int newCursor1; + * int newCursor2; + * + * oldMouseX = mouseX; + * oldMouseY = mouseY; + * + * cursorType = getCursorFromObject(mouseX, mouseY, &newCursor1, &newCursor2); + * + * if(cursorType == 9) + * { + * changeCursor(5); + * } + * else + * if(cursorType == -1) + * { + * changeCursor(6); + * } + * else + * { + * changeCursor(4); + * } + * + * } + * } + * else */ + { + changeCursor(0); + } + + if (main7) { + ASSERT(0); + } + + if (main15) { + ASSERT(0); + } + + if (main14 != -1) { + ASSERT(0); + } + } + // t_end = t_start+SPEED; // t_left=t_start-Osystem_GetTicks()+SPEED; #ifndef FASTDEBUG - /* if(t_left>0) - if(t_left>SLEEP_MIN) - Osystem_Delay(t_left-SLEEP_GRAN); - while(Osystem_GetTicks()<t_end){q++;}; */ + /* if(t_left>0) + * if(t_left>SLEEP_MIN) + * Osystem_Delay(t_left-SLEEP_GRAN); + * while(Osystem_GetTicks()<t_end){q++;}; */ #endif - manageEvents(4); + manageEvents(4); - }while(!playerDontAskQuit && quitValue2 && quitValue != 7); - } + } while (!playerDontAskQuit && quitValue2 && quitValue != 7); + } } -int oldmain(int argc, char* argv[]) -{ - printf("Cruise for a corpse recode\n"); +int oldmain(int argc, char *argv[]) { + printf("Cruise for a corpse recode\n"); // OSystemInit(); // osystem = new OSystem; - printf("Osystem Initialized\n"); + printf("Osystem Initialized\n"); + + printf("Initializing engine...\n"); - printf("Initializing engine...\n"); - // initBuffer(scaledScreen,640,400); - fadeVar = 0; + fadeVar = 0; - //lowLevelInit(); + //lowLevelInit(); - // arg parser stuff + // arg parser stuff - ptr_something = (ctpVar19Struct*)mallocAndZero(sizeof(ctpVar19Struct)*0x200); + ptr_something = + (ctpVar19Struct *) mallocAndZero(sizeof(ctpVar19Struct) * 0x200); - /*volVar1 = 0; - fileData1 = 0;*/ + /*volVar1 = 0; + * fileData1 = 0; */ - /*PAL_fileHandle = -1;*/ + /*PAL_fileHandle = -1; */ - // video init stuff + // video init stuff - loadSystemFont(); + loadSystemFont(); - // another bit of video init + // another bit of video init - if(!readVolCnf()) - { - printf("Fatal: unable to load vol.cnf !\n"); - return(-1); - } + if (!readVolCnf()) { + printf("Fatal: unable to load vol.cnf !\n"); + return (-1); + } - printf("Entering main loop...\n"); - mainLoop(); + printf("Entering main loop...\n"); + mainLoop(); - //freeStuff(); + //freeStuff(); - //freePtr(ptr_something); + //freePtr(ptr_something); - return(0); + return (0); } -void changeCursor(uint16 cursorType) -{ - //printf("changeCursor %d\n", cursorType); +void changeCursor(uint16 cursorType) { + //printf("changeCursor %d\n", cursorType); } -void* mallocAndZero(int32 size) -{ - void* ptr; +void *mallocAndZero(int32 size) { + void *ptr; - ptr = malloc(size); - memset(ptr,0,size); - return ptr; + ptr = malloc(size); + memset(ptr, 0, size); + return ptr; } } // End of namespace Cruise diff --git a/engines/cruise/cruise_main.h b/engines/cruise/cruise_main.h index bea26ed79a..df8550e1a1 100644 --- a/engines/cruise/cruise_main.h +++ b/engines/cruise/cruise_main.h @@ -22,8 +22,8 @@ * */ -#ifndef _CRUISE_H_ -#define _CRUISE_H_ +#ifndef CRUISE_CRUISE_MAIN_H +#define CRUISE_CRUISE_MAIN_H #include <string.h> #include <stdlib.h> @@ -66,35 +66,37 @@ namespace Cruise { #define ASSERT_PTR assert #define ASSERT assert - int32 decomp(uint8 * in, uint8 * out, int32 size); -ovlData3Struct* getOvlData3Entry(int32 scriptNumber, int32 param); -ovlData3Struct* scriptFunc1Sub2(int32 scriptNumber, int32 param); -int16 loadShort(void* ptr); +ovlData3Struct *getOvlData3Entry(int32 scriptNumber, int32 param); +ovlData3Struct *scriptFunc1Sub2(int32 scriptNumber, int32 param); +int16 loadShort(void *ptr); void resetFileEntry(int32 entryNumber); -void saveShort(void* ptr, int16 var); -void* mallocAndZero(int32 size); -uint8* mainProc14(uint16 overlay, uint16 idx); -void printInfoBlackBox(const char* string); +void saveShort(void *ptr, int16 var); +void *mallocAndZero(int32 size); +uint8 *mainProc14(uint16 overlay, uint16 idx); +void printInfoBlackBox(const char *string); void waitForPlayerInput(void); -int loadCtp(uint8* ctpName); -void loadPakedFileToMem(int fileIdx, uint8* buffer); +int loadCtp(uint8 * ctpName); +void loadPakedFileToMem(int fileIdx, uint8 * buffer); int loadScriptSub1(int scriptIdx, int param); void resetFileEntryRange(int param1, int param2); -int getProcParam(int overlayIdx, int param2, uint8* name); -void changeScriptParamInList(int param1, int param2, scriptInstanceStruct* pScriptInstance,int newValue, int param3); -uint8* getDataFromData3(ovlData3Struct* ptr, int param); -int32 prepareWordRender(int32 param, int32 var1,int16* out2, uint8* ptr3,uint8* string); -void removeExtention(const char* name, char* buffer); -void resetRaster(uint8* rasterPtr, int32 rasterSize); +int getProcParam(int overlayIdx, int param2, uint8 * name); +void changeScriptParamInList(int param1, int param2, + scriptInstanceStruct * pScriptInstance, int newValue, int param3); +uint8 *getDataFromData3(ovlData3Struct * ptr, int param); +int32 prepareWordRender(int32 param, int32 var1, int16 * out2, uint8 * ptr3, + uint8 * string); +void removeExtention(const char *name, char *buffer); +void resetRaster(uint8 * rasterPtr, int32 rasterSize); void changeCursor(uint16 cursorType); -void resetPtr2(scriptInstanceStruct* ptr); -void getFileExtention(const char* name,char* buffer); +void resetPtr2(scriptInstanceStruct * ptr); +void getFileExtention(const char *name, char *buffer); void *allocAndZero(int size); void freeStuff2(void); -char* getObjectName(int index, uint8* string); +char *getObjectName(int index, uint8 * string); void mainLoop(void); + } // End of namespace Cruise #endif diff --git a/engines/cruise/ctp.cpp b/engines/cruise/ctp.cpp index b0fadc765f..f916a3f8a2 100644 --- a/engines/cruise/ctp.cpp +++ b/engines/cruise/ctp.cpp @@ -26,14 +26,14 @@ namespace Cruise { -ctpVar19Struct* ptr_something; -ctpVar19Struct* polyStruct; -ctpVar19Struct* ctpVar11; -ctpVar19Struct* ctpVar13; -ctpVar19Struct* ctpVar15; +ctpVar19Struct *ptr_something; +ctpVar19Struct *polyStruct; +ctpVar19Struct *ctpVar11; +ctpVar19Struct *ctpVar13; +ctpVar19Struct *ctpVar15; -uint8* ctpVar17; -ctpVar19Struct* ctpVar19; +uint8 *ctpVar17; +ctpVar19Struct *ctpVar19; int currentWalkBoxCenterX; int currentWalkBoxCenterY; @@ -41,43 +41,43 @@ int currentWalkBoxCenterXBis; int currentWalkBoxCenterYBis; int ctpVarUnk; -uint8 walkboxTable[0x12]; +uint8 walkboxTable[0x12]; -int ctpProc2(int varX, int varY, int paramX, int paramY) -{ - int diffX = abs(paramX - varX); +int ctpProc2(int varX, int varY, int paramX, int paramY) { + int diffX = abs(paramX - varX); int diffY = abs(paramY - varY); - if(diffX > diffY) - { + if (diffX > diffY) { diffY = diffX; } - ctpVar14 = diffY; // highest difference - return(diffY); + ctpVar14 = diffY; // highest difference + return (diffY); } // this function process path finding coordinates -void loadCtpSub2(short int coordCount, short int* ptr) // coordCount = ctp_routeCoordCount, ptr = ctpVar8 -{ +void loadCtpSub2(short int coordCount, short int *ptr) { +// coordCount = ctp_routeCoordCount, ptr = ctpVar8 int i; int offset = 0; - short int* cur_ctp_routeCoords = (short int*)ctp_routeCoords; // coordinates table - int8* cur_ctp_routes = (int8*)ctp_routes; + short int *cur_ctp_routeCoords = (short int *)ctp_routeCoords; // coordinates table + int8 *cur_ctp_routes = (int8 *) ctp_routes; - for(i = 0; i < coordCount; i++) // for i < ctp_routeCoordCount + for (i = 0; i < coordCount; i++) // for i < ctp_routeCoordCount { - int varX = cur_ctp_routeCoords[0]; // x - int varY = cur_ctp_routeCoords[1]; // y + int varX = cur_ctp_routeCoords[0]; // x + int varY = cur_ctp_routeCoords[1]; // y int di = 0; int var4Offset = 2; - while(*(int16*) cur_ctp_routes > di) // while (coordCount > counter++) + while (*(int16 *) cur_ctp_routes > di) // while (coordCount > counter++) { - int idx = *(int16*)(cur_ctp_routes + var4Offset); - ptr[offset + idx] = ctpProc2(varX , varY, ctp_routeCoords[idx][0], ctp_routeCoords[idx * 2][1]); + int idx = *(int16 *) (cur_ctp_routes + var4Offset); + ptr[offset + idx] = + ctpProc2(varX, varY, ctp_routeCoords[idx][0], + ctp_routeCoords[idx * 2][1]); var4Offset += 2; di++; @@ -89,38 +89,35 @@ void loadCtpSub2(short int coordCount, short int* ptr) // coordCount = ctp_r } } -void getWalkBoxCenter(int boxIdx, uint16* _walkboxTable) -{ +void getWalkBoxCenter(int boxIdx, uint16 *_walkboxTable) { int minX = 1000; int minY = 1000; int maxX = -1; int maxY = -1; - ASSERT(boxIdx <= 15); // max number of walkboxes is 16 + ASSERT(boxIdx <= 15); // max number of walkboxes is 16 ASSERT(_walkboxTable[boxIdx * 40]); // we should never have an empty walk box - if(_walkboxTable[boxIdx * 40] > 0) - { - int numPoints = _walkboxTable[boxIdx * 40]; - uint16* pCurrentPtr = _walkboxTable + (boxIdx * 40) + 1; + if (_walkboxTable[boxIdx * 40] > 0) { + int numPoints = _walkboxTable[boxIdx * 40]; + uint16 *pCurrentPtr = _walkboxTable + (boxIdx * 40) + 1; int i; - for(i = 0; i < numPoints; i++) - { + for (i = 0; i < numPoints; i++) { int X = *(pCurrentPtr++); int Y = *(pCurrentPtr++);; - if(X < minX) + if (X < minX) minX = X; - if(X > maxX) + if (X > maxX) maxX = X; - if(Y < minY) + if (Y < minY) minY = Y; - if(Y > maxY) + if (Y > maxY) maxY = Y; } } @@ -130,13 +127,13 @@ void getWalkBoxCenter(int boxIdx, uint16* _walkboxTable) } // ax dx bx -void renderCTPWalkBox(int X1, int Y1, int X2, int scale, int Y2, uint16* walkboxData) -{ +void renderCTPWalkBox(int X1, int Y1, int X2, int scale, int Y2, + uint16 *walkboxData) { int numPoints; int wbSelf1; int wbSelf2; int i; - int16* destination; + int16 *destination; wbSelf1 = upscaleValue(X1, scale) - X2; wbSelf2 = upscaleValue(Y1, scale) - Y2; @@ -145,8 +142,7 @@ void renderCTPWalkBox(int X1, int Y1, int X2, int scale, int Y2, uint16* walkbox destination = polyBuffer2; - for(i = 0; i < numPoints; i++) - { + for (i = 0; i < numPoints; i++) { int pointX = *(walkboxData++); int pointY = *(walkboxData++); @@ -160,26 +156,25 @@ void renderCTPWalkBox(int X1, int Y1, int X2, int scale, int Y2, uint16* walkbox m_color = 0; ctpVarUnk = 0; - for(i = 0; i < numPoints; i++) - { + for (i = 0; i < numPoints; i++) { walkboxTable[i] = i; } - drawPolyMode2((char*)walkboxTable, numPoints); + drawPolyMode2((char *)walkboxTable, numPoints); } // this process the walkboxes -void loadCtpSub1(int boxIdx, int scale, uint16* _walkboxTable, ctpVar19Struct* param4) -{ +void loadCtpSub1(int boxIdx, int scale, uint16 *_walkboxTable, + ctpVar19Struct *param4) { int minX = 1000; int minY = 1000; int maxX = -1; int maxY = -1; - ctpVar19Struct* var_1C; - ctpVar19Struct* var_12; - int16* var_18; - int16* si; + ctpVar19Struct *var_1C; + ctpVar19Struct *var_12; + int16 *var_18; + int16 *si; // int16* di; // uint8* cx; // int bx; @@ -188,236 +183,229 @@ void loadCtpSub1(int boxIdx, int scale, uint16* _walkboxTable, ctpVar19Struct* p int var_E; //int var_C = 1000; //int var_A = 0; - ctpVar19SubStruct* subStruct; + ctpVar19SubStruct *subStruct; ASSERT(boxIdx <= 15); - if(_walkboxTable[boxIdx * 40] > 0) // is walkbox used ? + if (_walkboxTable[boxIdx * 40] > 0) // is walkbox used ? { getWalkBoxCenter(boxIdx, _walkboxTable); currentWalkBoxCenterYBis = currentWalkBoxCenterY; currentWalkBoxCenterXBis = currentWalkBoxCenterX; // + 512 - renderCTPWalkBox(currentWalkBoxCenterX, currentWalkBoxCenterY, currentWalkBoxCenterX, scale + 0x200, currentWalkBoxCenterY, _walkboxTable + boxIdx * 40); + renderCTPWalkBox(currentWalkBoxCenterX, currentWalkBoxCenterY, + currentWalkBoxCenterX, scale + 0x200, + currentWalkBoxCenterY, _walkboxTable + boxIdx * 40); var_1C = param4; - var_12 = var_1C + 1; // next + var_12 = var_1C + 1; // next var_18 = polyBuffer3; - var_E = 0; + var_E = 0; si = &polyBuffer3[1]; /* if(*si>=0) - { - di = si; - cx = var_12; - - do - { - di++; - bx = di[-1]; - ax = di[0]; - di++; - - var_2 = ax; - if(var_C < bx) - { - var_C = bx; - } - - if(var_2 < var_A) - { - var_A = var_2; - } - - *cx = bx; - cx++; - *cx = var_2; - cx++; - var_E ++; - }while(di); - - var_12 = cx; - }*/ + * { + * di = si; + * cx = var_12; + * + * do + * { + * di++; + * bx = di[-1]; + * ax = di[0]; + * di++; + * + * var_2 = ax; + * if(var_C < bx) + * { + * var_C = bx; + * } + * + * if(var_2 < var_A) + * { + * var_A = var_2; + * } + * + * *cx = bx; + * cx++; + * *cx = var_2; + * cx++; + * var_E ++; + * }while(di); + * + * var_12 = cx; + * } */ /*************/ { int i; int numPoints; - uint16* pCurrentPtr = _walkboxTable + boxIdx * 40; + uint16 *pCurrentPtr = _walkboxTable + boxIdx * 40; numPoints = *(pCurrentPtr++); - for(i = 0; i < numPoints; i++) - { + for (i = 0; i < numPoints; i++) { int X = *(pCurrentPtr++); int Y = *(pCurrentPtr++); - if(X < minX) + if (X < minX) minX = X; - if(X > maxX) + if (X > maxX) maxX = X; - if(Y < minY) + if (Y < minY) minY = Y; - if(Y > maxY) + if (Y > maxY) maxY = Y; } } /************/ var_1C->field_0 = var_12; - ctpVar13 = var_12; - var_12->field_0 = (ctpVar19Struct*)(-1); + ctpVar13 = var_12; + var_12->field_0 = (ctpVar19Struct *) (-1); subStruct = &var_1C->subStruct; subStruct->boxIdx = boxIdx; - subStruct->type = walkboxType[boxIdx]; - subStruct->minX = minX; - subStruct->maxX = maxX; - subStruct->minY = minY; - subStruct->maxY = maxY; + subStruct->type = walkboxType[boxIdx]; + subStruct->minX = minX; + subStruct->maxX = maxX; + subStruct->minY = minY; + subStruct->maxY = maxY; } } -int loadCtp(uint8* ctpName) -{ - int walkboxCounter; // si - uint8* ptr; - uint8* dataPointer; // ptr2 - char fileType[5]; // string2 +int loadCtp(uint8 *ctpName) { + int walkboxCounter; // si + uint8 *ptr; + uint8 *dataPointer; // ptr2 + char fileType[5]; // string2 short int segementSizeTable[7]; // tempTable char string[32]; - if(ctpVar1 == 0) - { + if (ctpVar1 == 0) { int i; - for(i = 0; i < 10; i++) - { + for (i = 0; i < 10; i++) { persoTable[i] = NULL; } } - if(!loadFileSub1(&ptr,ctpName,0)) - { + if (!loadFileSub1(&ptr, ctpName, 0)) { free(ptr); - return(-18); + return (-18); } dataPointer = ptr; fileType[4] = 0; - memcpy(fileType, dataPointer, 4); // get the file type, first 4 bytes of the CTP file + memcpy(fileType, dataPointer, 4); // get the file type, first 4 bytes of the CTP file dataPointer += 4; - if(strcmp(fileType, "CTP ")) - { + if (strcmp(fileType, "CTP ")) { free(ptr); - return(0); + return (0); } - memcpy(&ctp_routeCoordCount , dataPointer, 2); // get the number of path-finding coordinates + memcpy(&ctp_routeCoordCount, dataPointer, 2); // get the number of path-finding coordinates dataPointer += 2; flipShort(&ctp_routeCoordCount); memcpy(segementSizeTable, dataPointer, 0xE); - dataPointer += 0xE; // + 14 + dataPointer += 0xE; // + 14 flipGen(segementSizeTable, 0xE); memcpy(ctp_routeCoords, dataPointer, segementSizeTable[0]); // get the path-finding coordinates dataPointer += segementSizeTable[0]; flipGen(ctp_routeCoords, segementSizeTable[0]); - memcpy(ctp_routes, dataPointer, segementSizeTable[1]); // get the path-finding line informations (indexing the routeCoords array) + memcpy(ctp_routes, dataPointer, segementSizeTable[1]); // get the path-finding line informations (indexing the routeCoords array) dataPointer += segementSizeTable[1]; flipGen(ctp_routes, segementSizeTable[1]); - memcpy(ctp_walkboxTable, dataPointer, segementSizeTable[2]);// get the walkbox coordinates and lines + memcpy(ctp_walkboxTable, dataPointer, segementSizeTable[2]); // get the walkbox coordinates and lines dataPointer += segementSizeTable[2]; flipGen(ctp_walkboxTable, segementSizeTable[2]); - if(ctpVar1) - { + if (ctpVar1) { dataPointer += segementSizeTable[3]; dataPointer += segementSizeTable[4]; - } - else - { + } else { memcpy(walkboxType, dataPointer, segementSizeTable[3]); // get the walkbox type dataPointer += segementSizeTable[3]; - flipGen(walkboxType, segementSizeTable[3]); // Type: 0x00 - non walkable, 0x01 - walkable, 0x02 - exit zone + flipGen(walkboxType, segementSizeTable[3]); // Type: 0x00 - non walkable, 0x01 - walkable, 0x02 - exit zone memcpy(walkboxChange, dataPointer, segementSizeTable[4]); // change indicator, walkbox type can change, i.e. blocked by object (values are either 0x00 or 0x01) dataPointer += segementSizeTable[4]; flipGen(walkboxChange, segementSizeTable[4]); } - memcpy(ctpVar6, dataPointer, segementSizeTable[5]); // unknown? always 2*16 bytes (used by S24.CTP, S33.CTP, S33_2.CTP, S34.CTP, S35.CTP, S36.CTP; values can be 0x00, 0x01, 0x03, 0x05) + memcpy(ctpVar6, dataPointer, segementSizeTable[5]); // unknown? always 2*16 bytes (used by S24.CTP, S33.CTP, S33_2.CTP, S34.CTP, S35.CTP, S36.CTP; values can be 0x00, 0x01, 0x03, 0x05) dataPointer += segementSizeTable[5]; - flipGen(ctpVar6,segementSizeTable[5]); + flipGen(ctpVar6, segementSizeTable[5]); - memcpy(ctp_scale, dataPointer, segementSizeTable[6]); // scale values for the walkbox coordinates (don't know why there is a need for scaling walkboxes) + memcpy(ctp_scale, dataPointer, segementSizeTable[6]); // scale values for the walkbox coordinates (don't know why there is a need for scaling walkboxes) dataPointer += segementSizeTable[6]; - flipGen(ctp_scale, segementSizeTable[6]); // ok + flipGen(ctp_scale, segementSizeTable[6]); // ok free(ptr); strcpyuint8(string, currentCtpName); - numberOfWalkboxes = segementSizeTable[6] / 2; // get the number of walkboxes + numberOfWalkboxes = segementSizeTable[6] / 2; // get the number of walkboxes - loadCtpSub2(ctp_routeCoordCount, ctpVar8); // process path-finding stuff + loadCtpSub2(ctp_routeCoordCount, ctpVar8); // process path-finding stuff polyStruct = ctpVar11 = ctpVar13 = ptr_something; - ptr = (uint8*) polyStruct; + ptr = (uint8 *) polyStruct; walkboxCounter = numberOfWalkboxes; - while((--walkboxCounter) >= 0) - { + while ((--walkboxCounter) >= 0) { loadCtpSub1(walkboxCounter, 0, ctp_walkboxTable, ctpVar13); } - ctpVar15 = ctpVar13 + 1; // was after the -1 thing + ctpVar15 = ctpVar13 + 1; // was after the -1 thing walkboxCounter = numberOfWalkboxes; - while(--walkboxCounter) - { - loadCtpSub1(walkboxCounter, ctp_scale[walkboxCounter] * 20, ctp_walkboxTable, ctpVar13); + while (--walkboxCounter) { + loadCtpSub1(walkboxCounter, ctp_scale[walkboxCounter] * 20, + ctp_walkboxTable, ctpVar13); } //ctpVar17 = ctpVar13 - ptr + 4; { - int numOfUsedEntries = ctpVar13 - (ctpVar19Struct*) ptr; - numOfUsedEntries++;// there is a -1 entry at the end... Original was only mallocing numOfUsedEntries*sizeof(ctpVar19Struct)+4, but this is a bit ugly... - ctpVar13 = ctpVar11 = polyStruct = (ctpVar19Struct*)malloc(numOfUsedEntries * sizeof(ctpVar19Struct)); + int numOfUsedEntries = ctpVar13 - (ctpVar19Struct *) ptr; + numOfUsedEntries++; // there is a -1 entry at the end... Original was only mallocing numOfUsedEntries*sizeof(ctpVar19Struct)+4, but this is a bit ugly... + ctpVar13 = ctpVar11 = polyStruct = + (ctpVar19Struct *) malloc(numOfUsedEntries * + sizeof(ctpVar19Struct)); } walkboxCounter = numberOfWalkboxes; - while((--walkboxCounter) >= 0) - { + while ((--walkboxCounter) >= 0) { loadCtpSub1(walkboxCounter, 0, ctp_walkboxTable, ctpVar13); } ctpVar15 = ctpVar13 + 1; walkboxCounter = numberOfWalkboxes; - while(--walkboxCounter) - { - loadCtpSub1(walkboxCounter, ctp_scale[walkboxCounter] * 20, ctp_walkboxTable, ctpVar13); + while (--walkboxCounter) { + loadCtpSub1(walkboxCounter, ctp_scale[walkboxCounter] * 20, + ctp_walkboxTable, ctpVar13); } ctpVar19 = ctpVar11; - return(1); + return (1); } } // End of namespace Cruise diff --git a/engines/cruise/ctp.h b/engines/cruise/ctp.h index b1a7449c87..dcde2cced8 100644 --- a/engines/cruise/ctp.h +++ b/engines/cruise/ctp.h @@ -22,41 +22,39 @@ * */ -#ifndef _CTP_H_ -#define _CTP_H_ +#ifndef CRUISE_CTP_H +#define CRUISE_CTP_H namespace Cruise { -struct ctpVar19SubStruct -{ - uint16 boxIdx; //0 - uint16 type; //2 - uint16 minX; //4 - uint16 maxX; //6 - uint16 minY; //8 - uint16 maxY; //A +struct ctpVar19SubStruct { + uint16 boxIdx; //0 + uint16 type; //2 + uint16 minX; //4 + uint16 maxX; //6 + uint16 minY; //8 + uint16 maxY; //A }; typedef struct ctpVar19SubStruct ctpVar19SubStruct; -struct ctpVar19Struct -{ - struct ctpVar19Struct* field_0; //0 - ctpVar19SubStruct subStruct; +struct ctpVar19Struct { + struct ctpVar19Struct *field_0; //0 + ctpVar19SubStruct subStruct; }; typedef struct ctpVar19Struct ctpVar19Struct; -extern ctpVar19Struct* ptr_something; -extern ctpVar19Struct* polyStruct; -extern ctpVar19Struct* ctpVar11; -extern ctpVar19Struct* ctpVar13; -extern ctpVar19Struct* ctpVar15; +extern ctpVar19Struct *ptr_something; +extern ctpVar19Struct *polyStruct; +extern ctpVar19Struct *ctpVar11; +extern ctpVar19Struct *ctpVar13; +extern ctpVar19Struct *ctpVar15; -extern uint8* ctpVar17; -extern ctpVar19Struct* ctpVar19; +extern uint8 *ctpVar17; +extern ctpVar19Struct *ctpVar19; -int loadCtp(uint8* ctpName); +int loadCtp(uint8 * ctpName); int ctpProc2(int varX, int varY, int paramX, int paramY); } // End of namespace Cruise diff --git a/engines/cruise/dataLoader.cpp b/engines/cruise/dataLoader.cpp index f56fd73fd4..774262aef0 100644 --- a/engines/cruise/dataLoader.cpp +++ b/engines/cruise/dataLoader.cpp @@ -26,15 +26,15 @@ namespace Cruise { -void loadSetEntry(uint8* name, uint8* ptr, int currentEntryIdx, int currentDestEntry); -void loadFNTSub(uint8* ptr, int destIdx); - -enum fileTypeEnum -{ - type_UNK, - type_SPL, - type_SET, - type_FNT +void loadSetEntry(uint8 * name, uint8 * ptr, int currentEntryIdx, + int currentDestEntry); +void loadFNTSub(uint8 * ptr, int destIdx); + +enum fileTypeEnum { + type_UNK, + type_SPL, + type_SET, + type_FNT }; typedef enum fileTypeEnum fileTypeEnum; @@ -43,384 +43,352 @@ int loadSingleFile; // TODO: Unify decodeGfxFormat1, decodeGfxFormat4 and decodeGfxFormat5 -void decodeGfxFormat1(dataFileEntry* pCurrentFileEntry) -{ - uint8* buffer; - uint8* dataPtr = pCurrentFileEntry->subData.ptr; +void decodeGfxFormat1(dataFileEntry *pCurrentFileEntry) { + uint8 *buffer; + uint8 *dataPtr = pCurrentFileEntry->subData.ptr; - int spriteSize = pCurrentFileEntry->height * pCurrentFileEntry->widthInColumn * 8; - int x = 0; + int spriteSize = + pCurrentFileEntry->height * pCurrentFileEntry->widthInColumn * 8; + int x = 0; - buffer = (uint8*)malloc(spriteSize); + buffer = (uint8 *) malloc(spriteSize); - while (x < spriteSize) - { - uint8 c; - uint16 p0; + while (x < spriteSize) { + uint8 c; + uint16 p0; - p0 = (dataPtr[0] << 8) | dataPtr[1]; + p0 = (dataPtr[0] << 8) | dataPtr[1]; - /* decode planes */ - for (c = 0; c < 16; c++) - { - buffer[x+c] = ((p0 >> 15) & 1); + /* decode planes */ + for (c = 0; c < 16; c++) { + buffer[x + c] = ((p0 >> 15) & 1); - p0 <<= 1; - } + p0 <<= 1; + } - x+=16; + x += 16; - dataPtr+=2; - } + dataPtr += 2; + } - pCurrentFileEntry->subData.ptr = buffer; + pCurrentFileEntry->subData.ptr = buffer; } +void decodeGfxFormat4(dataFileEntry *pCurrentFileEntry) { + uint8 *buffer; + uint8 *dataPtr = pCurrentFileEntry->subData.ptr; + + int spriteSize = + pCurrentFileEntry->height * pCurrentFileEntry->widthInColumn * 2; + int x = 0; + + buffer = (uint8 *) malloc(spriteSize); + + while (x < spriteSize) { + uint8 c; + uint16 p0; + uint16 p1; + uint16 p2; + uint16 p3; + + p0 = (dataPtr[0] << 8) | dataPtr[1]; + p1 = (dataPtr[2] << 8) | dataPtr[3]; + p2 = (dataPtr[4] << 8) | dataPtr[5]; + p3 = (dataPtr[6] << 8) | dataPtr[7]; + + /* decode planes */ + for (c = 0; c < 16; c++) { + buffer[x + c] = + ((p0 >> 15) & 1) | ((p1 >> 14) & 2) | ((p2 >> 13) & + 4) | ((p3 >> 12) & 8); + + p0 <<= 1; + p1 <<= 1; + p2 <<= 1; + p3 <<= 1; + } -void decodeGfxFormat4(dataFileEntry* pCurrentFileEntry) -{ - uint8* buffer; - uint8* dataPtr = pCurrentFileEntry->subData.ptr; - - int spriteSize = pCurrentFileEntry->height * pCurrentFileEntry->widthInColumn * 2; - int x = 0; - - buffer = (uint8*)malloc(spriteSize); - - while (x < spriteSize) - { - uint8 c; - uint16 p0; - uint16 p1; - uint16 p2; - uint16 p3; - - p0 = (dataPtr[0] << 8) | dataPtr[1]; - p1 = (dataPtr[2] << 8) | dataPtr[3]; - p2 = (dataPtr[4] << 8) | dataPtr[5]; - p3 = (dataPtr[6] << 8) | dataPtr[7]; + x += 16; - /* decode planes */ - for (c = 0; c < 16; c++) - { - buffer[x+c] = ((p0 >> 15) & 1) | ((p1 >> 14) & 2) | ((p2 >> 13) & 4) | ((p3 >> 12) & 8); + dataPtr += 8; + } - p0 <<= 1; - p1 <<= 1; - p2 <<= 1; - p3 <<= 1; - } + pCurrentFileEntry->subData.ptr = buffer; +} - x+=16; +void decodeGfxFormat5(dataFileEntry *pCurrentFileEntry) { + uint8 *buffer; + uint8 *dataPtr = pCurrentFileEntry->subData.ptr; + + int spriteSize = + pCurrentFileEntry->height * pCurrentFileEntry->widthInColumn; + int x = 0; + int range = pCurrentFileEntry->height * pCurrentFileEntry->width; + + buffer = (uint8 *) malloc(spriteSize); + + while (x < spriteSize) { + uint8 c; + uint16 p0; + uint16 p1; + uint16 p2; + uint16 p3; + uint16 p4; + + p0 = (dataPtr[0 + range * 0] << 8) | dataPtr[1 + range * 0]; + p1 = (dataPtr[0 + range * 1] << 8) | dataPtr[1 + range * 1]; + p2 = (dataPtr[0 + range * 2] << 8) | dataPtr[1 + range * 2]; + p3 = (dataPtr[0 + range * 3] << 8) | dataPtr[1 + range * 3]; + p4 = (dataPtr[0 + range * 4] << 8) | dataPtr[1 + range * 4]; + + /* decode planes */ + for (c = 0; c < 16; c++) { + buffer[x + c] = + ((p0 >> 15) & 1) | ((p1 >> 14) & 2) | ((p2 >> 13) & + 4) | ((p3 >> 12) & 8) | ((p4 >> 11) & 16); + + p0 <<= 1; + p1 <<= 1; + p2 <<= 1; + p3 <<= 1; + p4 <<= 1; + } - dataPtr+=8; - } + x += 16; - pCurrentFileEntry->subData.ptr = buffer; -} + dataPtr += 2; + } -void decodeGfxFormat5(dataFileEntry* pCurrentFileEntry) -{ - uint8* buffer; - uint8* dataPtr = pCurrentFileEntry->subData.ptr; - - int spriteSize = pCurrentFileEntry->height * pCurrentFileEntry->widthInColumn; - int x = 0; - int range = pCurrentFileEntry->height * pCurrentFileEntry->width; - - buffer = (uint8*)malloc(spriteSize); - - while (x < spriteSize) - { - uint8 c; - uint16 p0; - uint16 p1; - uint16 p2; - uint16 p3; - uint16 p4; - - p0 = (dataPtr[0 + range * 0] << 8) | dataPtr[1 + range * 0]; - p1 = (dataPtr[0 + range * 1] << 8) | dataPtr[1 + range * 1]; - p2 = (dataPtr[0 + range * 2] << 8) | dataPtr[1 + range * 2]; - p3 = (dataPtr[0 + range * 3] << 8) | dataPtr[1 + range * 3]; - p4 = (dataPtr[0 + range * 4] << 8) | dataPtr[1 + range * 4]; - - /* decode planes */ - for (c = 0; c < 16; c++) - { - buffer[x+c] = ((p0 >> 15) & 1) | ((p1 >> 14) & 2) | ((p2 >> 13) & 4) | ((p3 >> 12) & 8) | ((p4 >> 11) & 16); - - p0 <<= 1; - p1 <<= 1; - p2 <<= 1; - p3 <<= 1; - p4 <<= 1; - } - - x+=16; - - dataPtr+=2; - } - - pCurrentFileEntry->subData.ptr = buffer; + pCurrentFileEntry->subData.ptr = buffer; } -int updateResFileEntry(int height, int width, int entryNumber, int resType) -{ - int div = 0; - int size; +int updateResFileEntry(int height, int width, int entryNumber, int resType) { + int div = 0; + int size; - resetFileEntry(entryNumber); + resetFileEntry(entryNumber); - filesDatabase[entryNumber].subData.field_1C = 0; + filesDatabase[entryNumber].subData.field_1C = 0; - size = height * width; // for sprites: width * height + size = height * width; // for sprites: width * height - if(resType == 4) - { - div = size / 4; - } - else if (resType == 5) - { - width = (width * 8) / 5; - } + if (resType == 4) { + div = size / 4; + } else if (resType == 5) { + width = (width * 8) / 5; + } - filesDatabase[entryNumber].subData.ptr = (uint8*)mallocAndZero(size + div); + filesDatabase[entryNumber].subData.ptr = + (uint8 *) mallocAndZero(size + div); - if(!filesDatabase[entryNumber].subData.ptr) - return(-2); + if (!filesDatabase[entryNumber].subData.ptr) + return (-2); - filesDatabase[entryNumber].widthInColumn = width; - filesDatabase[entryNumber].subData.ptr2 = filesDatabase[entryNumber].subData.ptr+size; - filesDatabase[entryNumber].width = width / 8; - filesDatabase[entryNumber].resType = resType; - filesDatabase[entryNumber].height = height; - filesDatabase[entryNumber].subData.index = -1; + filesDatabase[entryNumber].widthInColumn = width; + filesDatabase[entryNumber].subData.ptr2 = + filesDatabase[entryNumber].subData.ptr + size; + filesDatabase[entryNumber].width = width / 8; + filesDatabase[entryNumber].resType = resType; + filesDatabase[entryNumber].height = height; + filesDatabase[entryNumber].subData.index = -1; - return entryNumber; + return entryNumber; } +int createResFileEntry(int width, int height, int resType) { + int i; + int entryNumber; + int div = 0; + int size; -int createResFileEntry(int width, int height, int resType) -{ - int i; - int entryNumber; - int div = 0; - int size; - - printf("Executing untested createResFileEntry!\n"); - exit(1); + printf("Executing untested createResFileEntry!\n"); + exit(1); - for(i = 0; i < 257; i++) - { - if(!filesDatabase[i].subData.ptr) - break; - } + for (i = 0; i < 257; i++) { + if (!filesDatabase[i].subData.ptr) + break; + } - if(i >= 257) - { - return(-19); - } + if (i >= 257) { + return (-19); + } - entryNumber = i; + entryNumber = i; - filesDatabase[entryNumber].subData.field_1C = 0; + filesDatabase[entryNumber].subData.field_1C = 0; - size = width * height; // for sprites: width * height + size = width * height; // for sprites: width * height - if(resType == 4) - { - div = size / 4; - } - else if (resType == 5) - { - width = (width * 8) / 5; - } + if (resType == 4) { + div = size / 4; + } else if (resType == 5) { + width = (width * 8) / 5; + } - filesDatabase[entryNumber].subData.ptr = (uint8*)mallocAndZero(size + div); + filesDatabase[entryNumber].subData.ptr = + (uint8 *) mallocAndZero(size + div); - if(filesDatabase[entryNumber].subData.ptr) - { - return(-2); - } + if (filesDatabase[entryNumber].subData.ptr) { + return (-2); + } - filesDatabase[entryNumber].widthInColumn = width; - filesDatabase[entryNumber].subData.ptr2 = filesDatabase[entryNumber].subData.ptr + size; - filesDatabase[entryNumber].width = width / 8; - filesDatabase[entryNumber].resType = resType; - filesDatabase[entryNumber].height = height; - filesDatabase[entryNumber].subData.index = -1; + filesDatabase[entryNumber].widthInColumn = width; + filesDatabase[entryNumber].subData.ptr2 = + filesDatabase[entryNumber].subData.ptr + size; + filesDatabase[entryNumber].width = width / 8; + filesDatabase[entryNumber].resType = resType; + filesDatabase[entryNumber].height = height; + filesDatabase[entryNumber].subData.index = -1; - return entryNumber; + return entryNumber; } -fileTypeEnum getFileType(uint8* name) -{ - char extentionBuffer[16]; +fileTypeEnum getFileType(uint8 *name) { + char extentionBuffer[16]; - fileTypeEnum newFileType = type_UNK; + fileTypeEnum newFileType = type_UNK; - getFileExtention((char*)name,extentionBuffer); + getFileExtention((char *)name, extentionBuffer); - if(!strcmp(extentionBuffer,".SPL")) - { - newFileType = type_SPL; - } - else - if(!strcmp(extentionBuffer,".SET")) - { - newFileType = type_SET; - } - else - if(!strcmp(extentionBuffer,".FNT")) - { - newFileType = type_FNT; - } + if (!strcmp(extentionBuffer, ".SPL")) { + newFileType = type_SPL; + } else if (!strcmp(extentionBuffer, ".SET")) { + newFileType = type_SET; + } else if (!strcmp(extentionBuffer, ".FNT")) { + newFileType = type_FNT; + } - ASSERT(newFileType != type_UNK); + ASSERT(newFileType != type_UNK); - return newFileType; + return newFileType; } -int getNumMaxEntiresInSet(uint8* ptr) -{ - uint16 numEntries = *(uint16*)(ptr + 4); - flipShort(&numEntries); +int getNumMaxEntiresInSet(uint8 *ptr) { + uint16 numEntries = *(uint16 *) (ptr + 4); + flipShort(&numEntries); - return numEntries; + return numEntries; } -int loadFileMode2(uint8* name, int startIdx, int currentEntryIdx, int numIdx) -{ - uint8* ptr = NULL; - fileTypeEnum fileType; - - fileType = getFileType(name); - - loadFileSub1(&ptr, name, NULL); - - switch(fileType) - { - case type_SET: - { - int i; - int numMaxEntriesInSet = getNumMaxEntiresInSet(ptr); - - for(i = 0; i < numIdx; i++) - { - if ((currentEntryIdx + i) > numMaxEntriesInSet) +int loadFileMode2(uint8 *name, int startIdx, int currentEntryIdx, int numIdx) { + uint8 *ptr = NULL; + fileTypeEnum fileType; + + fileType = getFileType(name); + + loadFileSub1(&ptr, name, NULL); + + switch (fileType) { + case type_SET: { - return 0; // exit if limit is reached + int i; + int numMaxEntriesInSet = getNumMaxEntiresInSet(ptr); + + for (i = 0; i < numIdx; i++) { + if ((currentEntryIdx + i) > numMaxEntriesInSet) { + return 0; // exit if limit is reached + } + loadSetEntry(name, ptr, currentEntryIdx + i, + startIdx + i); + } + + break; + } + case type_FNT: + { + loadFNTSub(ptr, startIdx); + break; + } + case type_UNK: + { + break; + } + case type_SPL: + { + break; } - loadSetEntry(name, ptr, currentEntryIdx + i, startIdx + i); - } - - break; - } - case type_FNT: - { - loadFNTSub(ptr, startIdx); - break; - } - case type_UNK: - { - break; - } - case type_SPL: - { - break; } - } - return 0; + return 0; } -int loadFullBundle(uint8* name, int startIdx) -{ - uint8* ptr = NULL; - fileTypeEnum fileType; - - fileType = getFileType(name); - - loadFileSub1(&ptr,name,NULL); - - switch(fileType) - { - case type_SET: - { - int i; - int numMaxEntriesInSet; - - numMaxEntriesInSet = getNumMaxEntiresInSet(ptr); // get maximum number of sprites/animations in SET file - - for(i = 0; i < numMaxEntriesInSet; i++) - { - loadSetEntry(name, ptr, i, startIdx+i); - } - - break; - } - case type_FNT: - { - loadFNTSub(ptr, startIdx); - break; - } - case type_UNK: - { - break; - } - case type_SPL: - { - break; +int loadFullBundle(uint8 *name, int startIdx) { + uint8 *ptr = NULL; + fileTypeEnum fileType; + + fileType = getFileType(name); + + loadFileSub1(&ptr, name, NULL); + + switch (fileType) { + case type_SET: + { + int i; + int numMaxEntriesInSet; + + numMaxEntriesInSet = getNumMaxEntiresInSet(ptr); // get maximum number of sprites/animations in SET file + + for (i = 0; i < numMaxEntriesInSet; i++) { + loadSetEntry(name, ptr, i, startIdx + i); + } + + break; + } + case type_FNT: + { + loadFNTSub(ptr, startIdx); + break; + } + case type_UNK: + { + break; + } + case type_SPL: + { + break; + } } - } - return 0; + return 0; } -void loadFNTSub(uint8* ptr, int destIdx) -{ - uint8* ptr2 = ptr; - uint8* destPtr; - int fileIndex; - uint32 fontSize; - - ptr2 += 4; - memcpy(&loadFileVar1, ptr2, 4); +void loadFNTSub(uint8 *ptr, int destIdx) { + uint8 *ptr2 = ptr; + uint8 *destPtr; + int fileIndex; + uint32 fontSize; - flipLong(&loadFileVar1); + ptr2 += 4; + memcpy(&loadFileVar1, ptr2, 4); - if(destIdx == -1) - { - fileIndex = createResFileEntry(loadFileVar1, 1 ,1); - } - else - { - fileIndex = updateResFileEntry(loadFileVar1, 1, destIdx, 1); - } + flipLong(&loadFileVar1); - destPtr = filesDatabase[fileIndex].subData.ptr; + if (destIdx == -1) { + fileIndex = createResFileEntry(loadFileVar1, 1, 1); + } else { + fileIndex = updateResFileEntry(loadFileVar1, 1, destIdx, 1); + } - memcpy(destPtr, ptr2, loadFileVar1); + destPtr = filesDatabase[fileIndex].subData.ptr; - memcpy(&fontSize,ptr2,4); - flipLong(&fontSize); + memcpy(destPtr, ptr2, loadFileVar1); - if(destPtr!=NULL) - { + memcpy(&fontSize, ptr2, 4); + flipLong(&fontSize); + + if (destPtr != NULL) { int32 i; - uint8* currentPtr; + uint8 *currentPtr; destPtr = filesDatabase[fileIndex].subData.ptr; - flipLong((int32*) destPtr); - flipLong((int32*) (destPtr + 4)); + flipLong((int32 *) destPtr); + flipLong((int32 *) (destPtr + 4)); flipGen(destPtr + 8, 6); currentPtr = destPtr + 14; - for(i = 0; i < *(int16*) (destPtr + 8); i++) - { - flipLong((int32*) currentPtr); + for (i = 0; i < *(int16 *) (destPtr + 8); i++) { + flipLong((int32 *) currentPtr); currentPtr += 4; flipGen(currentPtr, 8); @@ -429,120 +397,124 @@ void loadFNTSub(uint8* ptr, int destIdx) } } -void loadSetEntry(uint8* name, uint8* ptr, int currentEntryIdx, int currentDestEntry) -{ - uint8* ptr2; - uint8* ptr3; - int offset; - int sec = 0; - uint16 numIdx; - - if (!strcmpuint8(ptr,"SEC")) - { - sec = 1; - } - - ptr2 = ptr + 4; - - memcpy(&numIdx,ptr2,2); - flipShort(&numIdx); - - ptr3 = ptr + 6; - - offset = currentEntryIdx*16; - - { - uint8* ptr4; - int resourceSize; - int fileIndex; - setHeaderEntry localBuffer; - uint8* ptr5; - - ptr4 = ptr + offset + 6; - - memcpy(&localBuffer, ptr4, sizeof(setHeaderEntry)); - - flipLong((int32*) &localBuffer.field_0); - flipGen(&localBuffer.width, 12); - - if ((sec == 1) || (localBuffer.type == 5)) - { - localBuffer.width = localBuffer.width - (localBuffer.type * 2); // Type 1: Width - (1*2) , Type 5: Width - (5*2) - } - - resourceSize = localBuffer.width * localBuffer.height; - - if(currentDestEntry == -1) - { - fileIndex = createResFileEntry(localBuffer.width,localBuffer.height,localBuffer.type); - } - else - { - fileIndex = updateResFileEntry(localBuffer.height, localBuffer.width, currentDestEntry, localBuffer.type); - } - - if(fileIndex < 0) - { - return; // TODO: buffer is not freed - } - - ptr5 = ptr3 + localBuffer.field_0 + numIdx * 16; - - memcpy(filesDatabase[fileIndex].subData.ptr,ptr5, resourceSize); - ptr5 += resourceSize; - - switch(localBuffer.type) - { - case 0: - { - filesDatabase[fileIndex].subData.resourceType = 8; - break; - } - case 1: - { - filesDatabase[fileIndex].subData.resourceType = 2; - decodeGfxFormat1(&filesDatabase[fileIndex]); - break; - } - case 4: - { - filesDatabase[fileIndex].width *= 2; - filesDatabase[fileIndex].subData.resourceType = 4; - decodeGfxFormat4(&filesDatabase[fileIndex]); - break; - } - case 5: - { - if (sec == 0) - { - // TODO sec type 5 needs special conversion. cut out 2 bytes at every width/5 position. - return; - } - filesDatabase[fileIndex].subData.resourceType = 4; - decodeGfxFormat5(&filesDatabase[fileIndex]); - break; - } - case 8: - { - filesDatabase[fileIndex].subData.resourceType = 4; // dummy ! - break; - } - default: - { - printf("Unsuported gfx loading type: %d\n", localBuffer.type); - break; - } - } - - filesDatabase[fileIndex].subData.index = currentDestEntry; - filesDatabase[fileIndex].subData.transparency = localBuffer.transparency; /*% 0x10*/; - - strcpyuint8(filesDatabase[fileIndex].subData.name,name); - } - - // TODO: free - - return; +void loadSetEntry(uint8 *name, uint8 *ptr, int currentEntryIdx, + int currentDestEntry) { + uint8 *ptr2; + uint8 *ptr3; + int offset; + int sec = 0; + uint16 numIdx; + + if (!strcmpuint8(ptr, "SEC")) { + sec = 1; + } + + ptr2 = ptr + 4; + + memcpy(&numIdx, ptr2, 2); + flipShort(&numIdx); + + ptr3 = ptr + 6; + + offset = currentEntryIdx * 16; + + { + uint8 *ptr4; + int resourceSize; + int fileIndex; + setHeaderEntry localBuffer; + uint8 *ptr5; + + ptr4 = ptr + offset + 6; + + memcpy(&localBuffer, ptr4, sizeof(setHeaderEntry)); + + flipLong((int32 *) & localBuffer.field_0); + flipGen(&localBuffer.width, 12); + + if ((sec == 1) || (localBuffer.type == 5)) { + localBuffer.width = localBuffer.width - (localBuffer.type * 2); // Type 1: Width - (1*2) , Type 5: Width - (5*2) + } + + resourceSize = localBuffer.width * localBuffer.height; + + if (currentDestEntry == -1) { + fileIndex = + createResFileEntry(localBuffer.width, + localBuffer.height, localBuffer.type); + } else { + fileIndex = + updateResFileEntry(localBuffer.height, + localBuffer.width, currentDestEntry, + localBuffer.type); + } + + if (fileIndex < 0) { + return; // TODO: buffer is not freed + } + + ptr5 = ptr3 + localBuffer.field_0 + numIdx * 16; + + memcpy(filesDatabase[fileIndex].subData.ptr, ptr5, + resourceSize); + ptr5 += resourceSize; + + switch (localBuffer.type) { + case 0: + { + filesDatabase[fileIndex].subData.resourceType = + 8; + break; + } + case 1: + { + filesDatabase[fileIndex].subData.resourceType = + 2; + decodeGfxFormat1(&filesDatabase[fileIndex]); + break; + } + case 4: + { + filesDatabase[fileIndex].width *= 2; + filesDatabase[fileIndex].subData.resourceType = + 4; + decodeGfxFormat4(&filesDatabase[fileIndex]); + break; + } + case 5: + { + if (sec == 0) { + // TODO sec type 5 needs special conversion. cut out 2 bytes at every width/5 position. + return; + } + filesDatabase[fileIndex].subData.resourceType = + 4; + decodeGfxFormat5(&filesDatabase[fileIndex]); + break; + } + case 8: + { + filesDatabase[fileIndex].subData.resourceType = 4; // dummy ! + break; + } + default: + { + printf("Unsuported gfx loading type: %d\n", + localBuffer.type); + break; + } + } + + filesDatabase[fileIndex].subData.index = currentDestEntry; + filesDatabase[fileIndex].subData.transparency = + localBuffer.transparency; /*% 0x10 */ ; + + strcpyuint8(filesDatabase[fileIndex].subData.name, name); + } + + // TODO: free + + return; } } // End of namespace Cruise diff --git a/engines/cruise/dataLoader.h b/engines/cruise/dataLoader.h index b52aa96dae..8c8e6bd301 100644 --- a/engines/cruise/dataLoader.h +++ b/engines/cruise/dataLoader.h @@ -22,16 +22,16 @@ * */ -#ifndef _DATALOADER_H_ -#define _DATALOADER_H_ +#ifndef CRUISE_DATALOADER_H +#define CRUISE_DATALOADER_H namespace Cruise { -int loadData(uint8* name, int startIdx); -int loadFileMode2(uint8* name, int param, int startIdx, int numIdx); -int loadFileSub1(uint8** ptr, uint8* name, uint8* ptr2); +int loadData(uint8 * name, int startIdx); +int loadFileMode2(uint8 * name, int param, int startIdx, int numIdx); +int loadFileSub1(uint8 ** ptr, uint8 * name, uint8 * ptr2); -int loadFullBundle(uint8* name, int startIdx); +int loadFullBundle(uint8 * name, int startIdx); } // End of namespace Cruise diff --git a/engines/cruise/decompiler.cpp b/engines/cruise/decompiler.cpp index 5e32374e3d..a2a554aedf 100644 --- a/engines/cruise/decompiler.cpp +++ b/engines/cruise/decompiler.cpp @@ -35,13 +35,12 @@ namespace Cruise { int currentLineType = 0; -struct decompileLineStruct -{ - int lineOffset; - char line[lineMaxSize]; - int indent; - int type; - int pendingElse; +struct decompileLineStruct { + int lineOffset; + char line[lineMaxSize]; + int indent; + int type; + int pendingElse; }; struct decompileLineStruct decompileLineTable[numMaxLignes]; @@ -50,11 +49,11 @@ int positionInDecompileLineTable; int failed; -char* currentDecompScript; +char *currentDecompScript; scriptInstanceStruct dummy; -scriptInstanceStruct* currentDecompScriptPtr = &dummy; +scriptInstanceStruct *currentDecompScriptPtr = &dummy; -uint8* getDataFromData3(ovlData3Struct* ptr, int param); +uint8 *getDataFromData3(ovlData3Struct * ptr, int param); opcodeTypeFunction decompOpcodeTypeTable[64]; @@ -64,7 +63,7 @@ unsigned long int currentOffset; unsigned long int dumpIdx = 0; -FILE* fHandle = NULL; +FILE *fHandle = NULL; #define DECOMPILER_STACK_DEPTH 100 #define DECOMPILER_STACK_ENTRY_SIZE 5000 @@ -77,645 +76,648 @@ unsigned long int decompileStackPosition = 0; uint8 stringName[256]; -ovlData3Struct* currentScript; +ovlData3Struct *currentScript; -ovlDataStruct* currentDecompOvl; +ovlDataStruct *currentDecompOvl; int currentDecompScriptIdx; char decompSaveOpcodeVar[256]; -uint8* getStringNameFromIdx(uint16 stringTypeIdx, char* offset) -{ - switch(stringTypeIdx&7) - { - case 2: - { - sprintf(stringName,"\"%s\"",currentScript->dataPtr+currentScript->offsetToSubData3 + atoi(offset)); - break; - } - case 5: - { - sprintf(stringName,"vars[%s]",offset); - break; - } - default: - { - sprintf(stringName,"string[%d][%s]",stringTypeIdx&7,offset); - break; - } - } +uint8 *getStringNameFromIdx(uint16 stringTypeIdx, char *offset) { + switch (stringTypeIdx & 7) { + case 2: + { + sprintf(stringName, "\"%s\"", + currentScript->dataPtr + + currentScript->offsetToSubData3 + atoi(offset)); + break; + } + case 5: + { + sprintf(stringName, "vars[%s]", offset); + break; + } + default: + { + sprintf(stringName, "string[%d][%s]", + stringTypeIdx & 7, offset); + break; + } + } - return stringName; + return stringName; } -char* resolveMessage(char* messageIdxString) -{ - char buffer[500]; - int variable; +char *resolveMessage(char *messageIdxString) { + char buffer[500]; + int variable; - variable = atoi(messageIdxString); - sprintf(buffer,"%d",variable); + variable = atoi(messageIdxString); + sprintf(buffer, "%d", variable); - if(strcmp(buffer,messageIdxString)) - { - return messageIdxString; - } - else - { - return currentDecompOvl->stringTable[atoi(messageIdxString)].string; - } + if (strcmp(buffer, messageIdxString)) { + return messageIdxString; + } else { + return currentDecompOvl->stringTable[atoi(messageIdxString)]. + string; + } } -void pushDecomp(char* string, ...) -{ - va_list va; +void pushDecomp(char *string, ...) { + va_list va; - va_start(va,string); - vsprintf(decompileStack[decompileStackPosition],string,va); - va_end(va); + va_start(va, string); + vsprintf(decompileStack[decompileStackPosition], string, va); + va_end(va); - // fprintf(fHandle, "----> %s\n",decompileStack[decompileStackPosition]); + // fprintf(fHandle, "----> %s\n",decompileStack[decompileStackPosition]); - decompileStackPosition++; + decompileStackPosition++; } -void resolveDecompShort(char* buffer) -{ - ovlData3Struct* data3Ptr = currentScript; +void resolveDecompShort(char *buffer) { + ovlData3Struct *data3Ptr = currentScript; - { - int i; - - importScriptStruct* importEntry = (importScriptStruct*) (data3Ptr->dataPtr + data3Ptr->offsetToImportData); - - for(i=0;i<data3Ptr->numImport;i++) - { - switch(importEntry->type) - { - case 20: // script - case 30: - case 40: - case 50: - { - if(importEntry->offset == currentDecompScriptPtr->var4 - 3) // param1 - { - sprintf(buffer,data3Ptr->dataPtr+data3Ptr->offsetToImportName+importEntry->offsetToName); - return; - } - if(importEntry->offset == currentDecompScriptPtr->var4 - 6) // param2 - { - sprintf(buffer,"linkedIdx"); - return; - } - break; - } - default: - { - if(importEntry->offset == currentDecompScriptPtr->var4 - 4) - { - sprintf(buffer,data3Ptr->dataPtr+data3Ptr->offsetToImportName+importEntry->offsetToName); - return; - } - } - } - importEntry++; - } - } + { + int i; + + importScriptStruct *importEntry = + (importScriptStruct *) (data3Ptr->dataPtr + + data3Ptr->offsetToImportData); + + for (i = 0; i < data3Ptr->numImport; i++) { + switch (importEntry->type) { + case 20: // script + case 30: + case 40: + case 50: + { + if (importEntry->offset == currentDecompScriptPtr->var4 - 3) // param1 + { + sprintf(buffer, + data3Ptr->dataPtr + + data3Ptr-> + offsetToImportName + + importEntry->offsetToName); + return; + } + if (importEntry->offset == currentDecompScriptPtr->var4 - 6) // param2 + { + sprintf(buffer, "linkedIdx"); + return; + } + break; + } + default: + { + if (importEntry->offset == + currentDecompScriptPtr->var4 - 4) { + sprintf(buffer, + data3Ptr->dataPtr + + data3Ptr-> + offsetToImportName + + importEntry->offsetToName); + return; + } + } + } + importEntry++; + } + } - buffer[0] = 0; + buffer[0] = 0; } -void resolveDecompChar(char* buffer) -{ - ovlData3Struct* data3Ptr = currentScript; +void resolveDecompChar(char *buffer) { + ovlData3Struct *data3Ptr = currentScript; - { - int i; - - importScriptStruct* importEntry = (importScriptStruct*) (data3Ptr->dataPtr + data3Ptr->offsetToImportData); - - for(i=0;i<data3Ptr->numImport;i++) - { - switch(importEntry->type) - { - default: - { - if(importEntry->offset == currentDecompScriptPtr->var4 - 2) - { - sprintf(buffer,data3Ptr->dataPtr+data3Ptr->offsetToImportName+importEntry->offsetToName); - return; - } - } - } - importEntry++; - } - } + { + int i; - buffer[0] = 0; + importScriptStruct *importEntry = + (importScriptStruct *) (data3Ptr->dataPtr + + data3Ptr->offsetToImportData); + + for (i = 0; i < data3Ptr->numImport; i++) { + switch (importEntry->type) { + default: + { + if (importEntry->offset == + currentDecompScriptPtr->var4 - 2) { + sprintf(buffer, + data3Ptr->dataPtr + + data3Ptr-> + offsetToImportName + + importEntry->offsetToName); + return; + } + } + } + importEntry++; + } + } + + buffer[0] = 0; } -char* popDecomp() -{ - // printf("<----\n"); +char *popDecomp() { + // printf("<----\n"); - if(!decompileStackPosition) - { - return(""); - } + if (!decompileStackPosition) { + return (""); + } - decompileStackPosition--; + decompileStackPosition--; - return decompileStack[decompileStackPosition]; + return decompileStack[decompileStackPosition]; } -void getByteFromDecompScript(char* buffer) -{ +void getByteFromDecompScript(char *buffer) { short int var = currentDecompScript[currentDecompScriptPtr->var4]; - currentDecompScriptPtr->var4 = currentDecompScriptPtr->var4+1; + currentDecompScriptPtr->var4 = currentDecompScriptPtr->var4 + 1; - if(var==-1) - { - resolveDecompChar(buffer); + if (var == -1) { + resolveDecompChar(buffer); - if(buffer[0]) - return; - } + if (buffer[0]) + return; + } - sprintf(buffer,"%d",var); + sprintf(buffer, "%d", var); } -char getByteFromDecompScriptReal(void) -{ +char getByteFromDecompScriptReal(void) { short int var = currentDecompScript[currentDecompScriptPtr->var4]; - currentDecompScriptPtr->var4 = currentDecompScriptPtr->var4+1; + currentDecompScriptPtr->var4 = currentDecompScriptPtr->var4 + 1; return var; } -void getShortFromDecompScript(char* buffer) -{ - short int var = *(int16*)(currentDecompScript+currentDecompScriptPtr->var4); +void getShortFromDecompScript(char *buffer) { + short int var = + *(int16 *) (currentDecompScript + currentDecompScriptPtr->var4); - currentDecompScriptPtr->var4 = currentDecompScriptPtr->var4+2; + currentDecompScriptPtr->var4 = currentDecompScriptPtr->var4 + 2; flipShort(&var); - if(var == -1) - { - resolveDecompShort(buffer); + if (var == -1) { + resolveDecompShort(buffer); - if(buffer[0]) - return; - } + if (buffer[0]) + return; + } - sprintf(buffer,"%d",var); + sprintf(buffer, "%d", var); } -short int getShortFromDecompScriptReal(void) -{ - short int var = *(int16*)(currentDecompScript+currentDecompScriptPtr->var4); +short int getShortFromDecompScriptReal(void) { + short int var = + *(int16 *) (currentDecompScript + currentDecompScriptPtr->var4); - currentDecompScriptPtr->var4 = currentDecompScriptPtr->var4+2; + currentDecompScriptPtr->var4 = currentDecompScriptPtr->var4 + 2; flipShort(&var); return var; } -void addDecomp(char* string, ...) -{ - va_list va; - - /* fprintf(fHandle,"%d: ",currentLineIdx); - - va_start(va,string); - vfprintf(fHandle,string,va); - va_end(va); - - fprintf(fHandle,"\n"); */ - - struct decompileLineStruct* pLineStruct = &decompileLineTable[positionInDecompileLineTable++]; - - pLineStruct->lineOffset = currentLineIdx; - pLineStruct->indent = 0; - pLineStruct->type = currentLineType; - pLineStruct->line[0] = 0; - pLineStruct->pendingElse = 0; - - va_start(va,string); - vsprintf(pLineStruct->line, string,va); - va_end(va); - - currentLineIdx = currentDecompScriptPtr->var4; - currentLineType = 0; - - /*printf("%d: ",currentOffset); - - va_start(va,string); - vprintf(string,va); - va_end(va); - - printf("\n");*/ +void addDecomp(char *string, ...) { + va_list va; + + /* fprintf(fHandle,"%d: ",currentLineIdx); + * + * va_start(va,string); + * vfprintf(fHandle,string,va); + * va_end(va); + * + * fprintf(fHandle,"\n"); */ + + struct decompileLineStruct *pLineStruct = + &decompileLineTable[positionInDecompileLineTable++]; + + pLineStruct->lineOffset = currentLineIdx; + pLineStruct->indent = 0; + pLineStruct->type = currentLineType; + pLineStruct->line[0] = 0; + pLineStruct->pendingElse = 0; + + va_start(va, string); + vsprintf(pLineStruct->line, string, va); + va_end(va); + + currentLineIdx = currentDecompScriptPtr->var4; + currentLineType = 0; + + /*printf("%d: ",currentOffset); + * + * va_start(va,string); + * vprintf(string,va); + * va_end(va); + * + * printf("\n"); */ } -void resolveVarName(char* ovlIdxString, int varType, char* varIdxString, char* outputName) -{ +void resolveVarName(char *ovlIdxString, int varType, char *varIdxString, + char *outputName) { int varIdx = atoi(varIdxString); - strcpy(outputName,""); + strcpy(outputName, ""); - if(varType == 2) - { - strcpy(outputName, getStringNameFromIdx(varType, varIdxString)); + if (varType == 2) { + strcpy(outputName, getStringNameFromIdx(varType, + varIdxString)); return; } - if(varType == 1) - { + if (varType == 1) { sprintf(outputName, "localVar_%s", varIdxString); return; } - if(!strcmp(ovlIdxString,"0")) - { + if (!strcmp(ovlIdxString, "0")) { int i; - for(i=0;i<currentDecompOvl->numExport;i++) - { - if(varIdx == currentDecompOvl->exportDataPtr[i].idx) - { - if( ((currentDecompOvl->exportDataPtr[i].var4&0xF0) == 0) && varType != 0x20) // var + for (i = 0; i < currentDecompOvl->numExport; i++) { + if (varIdx == currentDecompOvl->exportDataPtr[i].idx) { + if (((currentDecompOvl->exportDataPtr[i].var4 & 0xF0) == 0) && varType != 0x20) // var { - strcpy(outputName, currentDecompOvl->exportNamesPtr + currentDecompOvl->exportDataPtr[i].offsetToName); + strcpy(outputName, + currentDecompOvl->exportNamesPtr + + currentDecompOvl->exportDataPtr[i]. + offsetToName); return; } - if( (currentDecompOvl->exportDataPtr[i].var4) == 20 && varType == 0x20) // script + if ((currentDecompOvl->exportDataPtr[i].var4) == 20 && varType == 0x20) // script { - strcpy(outputName, currentDecompOvl->exportNamesPtr + currentDecompOvl->exportDataPtr[i].offsetToName); + strcpy(outputName, + currentDecompOvl->exportNamesPtr + + currentDecompOvl->exportDataPtr[i]. + offsetToName); return; } } } - sprintf(outputName, "ovl(%s).[%d][%s]", ovlIdxString, varType, varIdxString); - } - else - { + sprintf(outputName, "ovl(%s).[%d][%s]", ovlIdxString, varType, + varIdxString); + } else { strcpy(outputName, ovlIdxString); } } -int decompLoadVar(void) -{ - switch(currentScriptOpcodeType) - { +int decompLoadVar(void) { + switch (currentScriptOpcodeType) { case 0: { - char buffer[256]; + char buffer[256]; - getShortFromDecompScript(buffer); + getShortFromDecompScript(buffer); - pushDecomp(buffer); + pushDecomp(buffer); - return(0); + return (0); } - // string - case 1: - { - char buffer1[256]; - char buffer2[256]; - char buffer3[256]; + // string + case 1: + { + char buffer1[256]; + char buffer2[256]; + char buffer3[256]; char varName[256]; - getByteFromDecompScript(buffer1); + getByteFromDecompScript(buffer1); getByteFromDecompScript(buffer2); getShortFromDecompScript(buffer3); - resolveVarName(buffer2,atoi(buffer1) & 7,buffer3, varName); + resolveVarName(buffer2, atoi(buffer1) & 7, buffer3, + varName); - pushDecomp("%s",varName); - return(0); - } - case 2: - { - char buffer1[256]; - char buffer2[256]; - char buffer3[256]; + pushDecomp("%s", varName); + return (0); + } + case 2: + { + char buffer1[256]; + char buffer2[256]; + char buffer3[256]; char varName[256]; - getByteFromDecompScript(buffer1); + getByteFromDecompScript(buffer1); getByteFromDecompScript(buffer2); getShortFromDecompScript(buffer3); - resolveVarName(buffer2,atoi(buffer1) & 7,buffer3, varName); + resolveVarName(buffer2, atoi(buffer1) & 7, buffer3, + varName); - pushDecomp("%s",varName); - return(0); - } - case 5: - { - char buffer1[256]; - char buffer2[256]; - char buffer3[256]; + pushDecomp("%s", varName); + return (0); + } + case 5: + { + char buffer1[256]; + char buffer2[256]; + char buffer3[256]; char varName[256]; - getByteFromDecompScript(buffer1); + getByteFromDecompScript(buffer1); getByteFromDecompScript(buffer2); getShortFromDecompScript(buffer3); - resolveVarName(buffer2,atoi(buffer1) & 7,buffer3, varName); + resolveVarName(buffer2, atoi(buffer1) & 7, buffer3, + varName); - pushDecomp("%s[%s]",varName,decompSaveOpcodeVar); - return(0); - } + pushDecomp("%s[%s]", varName, decompSaveOpcodeVar); + return (0); + } default: { - printf("Unsupported type %d in opcodeType0\n",currentScriptOpcodeType); - failed = 1; + printf("Unsupported type %d in opcodeType0\n", + currentScriptOpcodeType); + failed = 1; } } } -int decompSaveVar(void) -{ -// int var = popVar(); +int decompSaveVar(void) { +// int var = popVar(); - switch(currentScriptOpcodeType) - { - case 0: - { - addDecomp(popDecomp()); - return(0); - } - // modify string - case 1: - { - char buffer1[256]; - char buffer2[256]; - char buffer3[256]; + switch (currentScriptOpcodeType) { + case 0: + { + addDecomp(popDecomp()); + return (0); + } + // modify string + case 1: + { + char buffer1[256]; + char buffer2[256]; + char buffer3[256]; char varName[256]; - uint8 type; + uint8 type; - getByteFromDecompScript(buffer1); + getByteFromDecompScript(buffer1); getByteFromDecompScript(buffer2); getShortFromDecompScript(buffer3); - type = atoi(buffer1) & 7; + type = atoi(buffer1) & 7; - resolveVarName(buffer2,type,buffer3, varName); + resolveVarName(buffer2, type, buffer3, varName); - addDecomp("%s = %s",varName,popDecomp()); - break; + addDecomp("%s = %s", varName, popDecomp()); + break; } - case 2: + case 2: { - char buffer1[256]; - char buffer2[256]; - char buffer3[256]; + char buffer1[256]; + char buffer2[256]; + char buffer3[256]; - getByteFromDecompScript(buffer1); + getByteFromDecompScript(buffer1); getByteFromDecompScript(buffer2); getShortFromDecompScript(buffer3); - addDecomp("ovl(%s).setVar(%s,%s) = %s",buffer2,buffer1,buffer3,popDecomp()); - break; + addDecomp("ovl(%s).setVar(%s,%s) = %s", buffer2, + buffer1, buffer3, popDecomp()); + break; } - case 4: - { - strcpy(decompSaveOpcodeVar,popDecomp()); - break; - } - case 5: + case 4: { - char buffer1[256]; - char buffer2[256]; - char buffer3[256]; + strcpy(decompSaveOpcodeVar, popDecomp()); + break; + } + case 5: + { + char buffer1[256]; + char buffer2[256]; + char buffer3[256]; char varName[256]; - uint8 type; + uint8 type; - getByteFromDecompScript(buffer1); + getByteFromDecompScript(buffer1); getByteFromDecompScript(buffer2); getShortFromDecompScript(buffer3); - type = atoi(buffer1) & 7; + type = atoi(buffer1) & 7; - resolveVarName(buffer2,type,buffer3, varName); + resolveVarName(buffer2, type, buffer3, varName); - addDecomp("%s[%s] = %s",varName,decompSaveOpcodeVar,popDecomp()); - break; + addDecomp("%s[%s] = %s", varName, decompSaveOpcodeVar, + popDecomp()); + break; } default: { - printf("Unsupported type %d in opcodeType1\n",currentScriptOpcodeType); - failed = 1; + printf("Unsupported type %d in opcodeType1\n", + currentScriptOpcodeType); + failed = 1; } } - return(0); + return (0); } -int decompOpcodeType2(void) -{ - switch(currentScriptOpcodeType) - { - case 1: - { - char buffer3[256]; - char varName[256]; - int byte1 = getByteFromDecompScriptReal(); - int byte2 = getByteFromDecompScriptReal(); - getShortFromDecompScript(buffer3); - - resolveVarName("0",byte1 & 7,buffer3, varName); - - pushDecomp(varName); - - break; - } - case 5: - { +int decompOpcodeType2(void) { + switch (currentScriptOpcodeType) { + case 1: + { + char buffer3[256]; + char varName[256]; + int byte1 = getByteFromDecompScriptReal(); + int byte2 = getByteFromDecompScriptReal(); + getShortFromDecompScript(buffer3); + + resolveVarName("0", byte1 & 7, buffer3, varName); + + pushDecomp(varName); + + break; + } + case 5: + { int byte1 = getByteFromDecompScriptReal(); int byte2 = getByteFromDecompScriptReal(); short int short1 = getShortFromDecompScriptReal(); - int8* ptr = scriptDataPtrTable[byte1 & 7] + short1; - - if((byte1&7) == 2) - { - pushDecomp("\"%s\"[%s]",ptr,decompSaveOpcodeVar); - } - else - if((byte1&7) == 5) - { - pushDecomp("freeString[%d][%s]",short1,decompSaveOpcodeVar); - } - else - { - printf("Unsupported type %d in opcodeType2\n",byte1 & 7); - failed = 1; - } - break; - } + int8 *ptr = scriptDataPtrTable[byte1 & 7] + short1; + + if ((byte1 & 7) == 2) { + pushDecomp("\"%s\"[%s]", ptr, + decompSaveOpcodeVar); + } else if ((byte1 & 7) == 5) { + pushDecomp("freeString[%d][%s]", short1, + decompSaveOpcodeVar); + } else { + printf("Unsupported type %d in opcodeType2\n", + byte1 & 7); + failed = 1; + } + break; + } default: { - printf("Unsupported type %d in opcodeType2\n",currentScriptOpcodeType); - failed = 1; + printf("Unsupported type %d in opcodeType2\n", + currentScriptOpcodeType); + failed = 1; } - } - return(0); + } + return (0); } -int decompMath(void) -{ - char* param1 = popDecomp(); - char* param2 = popDecomp(); - - switch(currentScriptOpcodeType) - { - case 0: - { - sprintf(tempbuffer,"%s+%s",param1,param2); - pushDecomp(tempbuffer); - break; - } - case 1: - { - sprintf(tempbuffer,"%s/%s",param1,param2); - pushDecomp(tempbuffer); - break; - } - case 2: - { - sprintf(tempbuffer,"%s-%s",param1,param2); - pushDecomp(tempbuffer); - break; - } - case 3: - { - sprintf(tempbuffer,"%s*%s",param1,param2); - pushDecomp(tempbuffer); - break; - } - case 4: - { - sprintf(tempbuffer,"%s\%%s",param1,param2); - pushDecomp(tempbuffer); - break; - } - case 5: - case 7: - { - sprintf(tempbuffer,"%s|%s",param1,param2); - pushDecomp(tempbuffer); - break; - } - case 6: - { - sprintf(tempbuffer,"%s&%s",param1,param2); - pushDecomp(tempbuffer); - break; - } - +int decompMath(void) { + char *param1 = popDecomp(); + char *param2 = popDecomp(); + + switch (currentScriptOpcodeType) { + case 0: + { + sprintf(tempbuffer, "%s+%s", param1, param2); + pushDecomp(tempbuffer); + break; + } + case 1: + { + sprintf(tempbuffer, "%s/%s", param1, param2); + pushDecomp(tempbuffer); + break; + } + case 2: + { + sprintf(tempbuffer, "%s-%s", param1, param2); + pushDecomp(tempbuffer); + break; + } + case 3: + { + sprintf(tempbuffer, "%s*%s", param1, param2); + pushDecomp(tempbuffer); + break; + } + case 4: + { + sprintf(tempbuffer, "%s\%%s", param1, param2); + pushDecomp(tempbuffer); + break; + } + case 5: + case 7: + { + sprintf(tempbuffer, "%s|%s", param1, param2); + pushDecomp(tempbuffer); + break; + } + case 6: + { + sprintf(tempbuffer, "%s&%s", param1, param2); + pushDecomp(tempbuffer); + break; + } + default: { - sprintf(tempbuffer,"decompMath(%d,%s,%s)",currentScriptOpcodeType,param1,param2); - pushDecomp(tempbuffer); + sprintf(tempbuffer, "decompMath(%d,%s,%s)", + currentScriptOpcodeType, param1, param2); + pushDecomp(tempbuffer); break; } - } - return(0); + } + return (0); } -int decompBoolCompare(void) -{ - char* param1; - char* param2; +int decompBoolCompare(void) { + char *param1; + char *param2; - param1 = popDecomp(); - param2 = popDecomp(); + param1 = popDecomp(); + param2 = popDecomp(); - sprintf(tempbuffer,"compare(%s,%s)",param1,param2); - pushDecomp(tempbuffer); + sprintf(tempbuffer, "compare(%s,%s)", param1, param2); + pushDecomp(tempbuffer); - return 0; + return 0; } -int decompTest(void) -{ - unsigned long int oldOffset = currentDecompScriptPtr->var4; - short int offset = getShortFromDecompScriptReal(); - - switch(currentScriptOpcodeType) - { - case 0: - { - currentLineType = 1; - addDecomp("test '!(bitMask & 1)' and goto %d",offset+oldOffset); - break; - } - case 1: - { - currentLineType = 1; - addDecomp("test '(bitMask & 1)' and goto %d",offset+oldOffset); - break; - } - case 2: - { - currentLineType = 1; - addDecomp("test '(bitMask & 2)' and goto %d",offset+oldOffset); - break; - } - case 3: - { - currentLineType = 1; - addDecomp("test '(bitMask & 3)' and goto %d",offset+oldOffset); - break; - } - case 4: - { - currentLineType = 1; - addDecomp("test '(bitMask & 4)' and goto %d",offset+oldOffset); - break; - } - case 5: - { - currentLineType = 1; - addDecomp("test '(bitMask & 5)' and goto %d",offset+oldOffset); - break; - } - case 6: - { - currentLineType = 2; - addDecomp("test 'never' and goto %d",offset+oldOffset); - break; - } - case 7: - { - currentLineType = 3; - addDecomp("goto %d",offset+oldOffset); - break; - } - - } - - return 0; +int decompTest(void) { + unsigned long int oldOffset = currentDecompScriptPtr->var4; + short int offset = getShortFromDecompScriptReal(); + + switch (currentScriptOpcodeType) { + case 0: + { + currentLineType = 1; + addDecomp("test '!(bitMask & 1)' and goto %d", + offset + oldOffset); + break; + } + case 1: + { + currentLineType = 1; + addDecomp("test '(bitMask & 1)' and goto %d", + offset + oldOffset); + break; + } + case 2: + { + currentLineType = 1; + addDecomp("test '(bitMask & 2)' and goto %d", + offset + oldOffset); + break; + } + case 3: + { + currentLineType = 1; + addDecomp("test '(bitMask & 3)' and goto %d", + offset + oldOffset); + break; + } + case 4: + { + currentLineType = 1; + addDecomp("test '(bitMask & 4)' and goto %d", + offset + oldOffset); + break; + } + case 5: + { + currentLineType = 1; + addDecomp("test '(bitMask & 5)' and goto %d", + offset + oldOffset); + break; + } + case 6: + { + currentLineType = 2; + addDecomp("test 'never' and goto %d", + offset + oldOffset); + break; + } + case 7: + { + currentLineType = 3; + addDecomp("goto %d", offset + oldOffset); + break; + } + + } + + return 0; } -int decompCompare(void) -{ - char* param; +int decompCompare(void) { + char *param; - param = popDecomp(); + param = popDecomp(); - addDecomp("sign(%s)",param); + addDecomp("sign(%s)", param); /* if(!pop) @@ -734,816 +736,865 @@ int decompCompare(void) currentScriptPtr->bitMask = si; */ - return 0; + return 0; } +int decompSwapStack(void) { + char *stack1; + char *stack2; + char buffer1[4000]; + char buffer2[4000]; -int decompSwapStack(void) -{ - char* stack1; - char* stack2; - char buffer1[4000]; - char buffer2[4000]; - - stack1 = popDecomp(); - stack2 = popDecomp(); + stack1 = popDecomp(); + stack2 = popDecomp(); - strcpyuint8(buffer1,stack1); - strcpyuint8(buffer2,stack2); + strcpyuint8(buffer1, stack1); + strcpyuint8(buffer2, stack2); - pushDecomp(buffer1); - pushDecomp(buffer2); + pushDecomp(buffer1); + pushDecomp(buffer2); - return 0; + return 0; } -int decompFunction(void) -{ - currentScriptOpcodeType = getByteFromDecompScriptReal(); +int decompFunction(void) { + currentScriptOpcodeType = getByteFromDecompScriptReal(); // addDecomp("OP_%X", currentScriptOpcodeType); - switch(currentScriptOpcodeType) - { - case 0x1: - { - pushDecomp("_setMain5()"); - break; - } - case 0x2: - { - pushDecomp("_prepareFade()"); - break; - } - case 0x3: - { - sprintf(tempbuffer,"_loadBackground(%s,%s)",popDecomp(),popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x4: - { - sprintf(tempbuffer,"_loadFullBundle(%s,%s)",popDecomp(),popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x5: - { - sprintf(tempbuffer,"_addCell(%s,%s,%s)",popDecomp(),popDecomp(),popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x6: - { - unsigned long int numArg = atoi(popDecomp()); - char* ovlStr; - char* idxStr; - int i; - char functionName[100]; - - idxStr = popDecomp(); - ovlStr = popDecomp(); - - resolveVarName(ovlStr, 0x20, idxStr, functionName); - - sprintf(tempbuffer,"_startASync(%s",functionName); - - for(i=0;i<numArg;i++) - { - strcatuint8(tempbuffer,","); - strcatuint8(tempbuffer,popDecomp()); - } - - strcatuint8(tempbuffer,")"); - - pushDecomp(tempbuffer); - break; - } - case 0x7: - { - char* var1; - char* objIdxStr; - char* ovlStr; - char varName[256]; - int i; - - var1 = popDecomp(); - objIdxStr = popDecomp(); - ovlStr = popDecomp(); - - sprintf(tempbuffer,"_createObjectFromOvlData(ovl:%s,dataIdx:%s,%s)",ovlStr,objIdxStr,var1); - pushDecomp(tempbuffer); - break; - } - case 0x8: - { - sprintf(tempbuffer,"_removeObjectFromList(%s,%s,%s)",popDecomp(),popDecomp(),popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x9: - { - pushDecomp("_freeobjectList()"); - break; - } - case 0xA: - { - sprintf(tempbuffer,"_removeScript(ovl(%s),%s)",popDecomp(),popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0xB: - { - sprintf(tempbuffer,"_resetFilesEntries(%s,%s)",popDecomp(),popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0xC: - { - sprintf(tempbuffer,"_loadOverlay(%s)",popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0xD: - { - sprintf(tempbuffer,"_palManipulation(%s,%s,%s,%s,%s)",popDecomp(),popDecomp(),popDecomp(),popDecomp(),popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0xE: - { - sprintf(tempbuffer,"_playSample(%s,%s,%s,%s)",popDecomp(),popDecomp(),popDecomp(),popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x10: - { - sprintf(tempbuffer,"_releaseScript2(%s)",popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x11: - { - sprintf(tempbuffer,"_getOverlayIdx(%s)",popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x13: - { - sprintf(tempbuffer,"_displayMessage(%s,\"%s\",%s,%s,%s,%s)",popDecomp(),resolveMessage(popDecomp()),popDecomp(),popDecomp(),popDecomp(),popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x14: - { - sprintf(tempbuffer,"_removeObject(ovl(%s),%s)",popDecomp(),popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x15: - { - pushDecomp("_pauseScript()"); - break; - } - case 0x16: - { - sprintf(tempbuffer,"_Op_FreezeCell(%s,%s,%s,%s,%s,%s)",popDecomp(),popDecomp(),popDecomp(),popDecomp(),popDecomp(),popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x17: - { - sprintf(tempbuffer,"_loadCtp(%s)",popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x18: - { - sprintf(tempbuffer,"_Op_AddAnimation(%s,%s,%s,%s,%s,%s,%s)",popDecomp(),popDecomp(),popDecomp(),popDecomp(),popDecomp(),popDecomp(),popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x19: - { - sprintf(tempbuffer,"_Op_RemoveAnimation(%s,%s,%s)",popDecomp(),popDecomp(),popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x1A: - { - sprintf(tempbuffer,"_setupScaleFormula(%s,%s,%s,%s)",popDecomp(),popDecomp(),popDecomp(),popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x1E: - { - sprintf(tempbuffer,"_op_1E(%s,%s,%s,%s,%s,%s)",popDecomp(),popDecomp(),popDecomp(),popDecomp(),popDecomp(),popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x21: - { - sprintf(tempbuffer,"_isActorLoaded(%s,%s,%s)",popDecomp(),popDecomp(),popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x22: - { - sprintf(tempbuffer,"_computeScale(%s)",popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x23: - { - sprintf(tempbuffer,"_convertToScale(%s,%s)",popDecomp(),popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x24: - { - sprintf(tempbuffer,"_op_24(%s,%s,%s,%s)",popDecomp(),popDecomp(),popDecomp(),popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x27: - { - sprintf(tempbuffer,"_getWalkBoxCollision(%s,%s)",popDecomp(),popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x28: - { - sprintf(tempbuffer,"_changeSaveAllowedState(%s)",popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x29: - { - pushDecomp("_freeAllPerso()"); - break; - } - case 0x2B: - { - sprintf(tempbuffer,"_getProcIdx(%s,%s)",popDecomp(),popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x2C: - { - sprintf(tempbuffer,"_setObjectPosition(%s,%s,%s)",popDecomp(),popDecomp(),popDecomp()); - pushDecomp(tempbuffer); - break; + switch (currentScriptOpcodeType) { + case 0x1: + { + pushDecomp("_setMain5()"); + break; + } + case 0x2: + { + pushDecomp("_prepareFade()"); + break; + } + case 0x3: + { + sprintf(tempbuffer, "_loadBackground(%s,%s)", + popDecomp(), popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x4: + { + sprintf(tempbuffer, "_loadFullBundle(%s,%s)", + popDecomp(), popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x5: + { + sprintf(tempbuffer, "_addCell(%s,%s,%s)", popDecomp(), + popDecomp(), popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x6: + { + unsigned long int numArg = atoi(popDecomp()); + char *ovlStr; + char *idxStr; + int i; + char functionName[100]; + + idxStr = popDecomp(); + ovlStr = popDecomp(); + + resolveVarName(ovlStr, 0x20, idxStr, functionName); + + sprintf(tempbuffer, "_startASync(%s", functionName); + + for (i = 0; i < numArg; i++) { + strcatuint8(tempbuffer, ","); + strcatuint8(tempbuffer, popDecomp()); + } + + strcatuint8(tempbuffer, ")"); + + pushDecomp(tempbuffer); + break; + } + case 0x7: + { + char *var1; + char *objIdxStr; + char *ovlStr; + char varName[256]; + int i; + + var1 = popDecomp(); + objIdxStr = popDecomp(); + ovlStr = popDecomp(); + + sprintf(tempbuffer, + "_createObjectFromOvlData(ovl:%s,dataIdx:%s,%s)", + ovlStr, objIdxStr, var1); + pushDecomp(tempbuffer); + break; + } + case 0x8: + { + sprintf(tempbuffer, "_removeObjectFromList(%s,%s,%s)", + popDecomp(), popDecomp(), popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x9: + { + pushDecomp("_freeobjectList()"); + break; + } + case 0xA: + { + sprintf(tempbuffer, "_removeScript(ovl(%s),%s)", + popDecomp(), popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0xB: + { + sprintf(tempbuffer, "_resetFilesEntries(%s,%s)", + popDecomp(), popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0xC: + { + sprintf(tempbuffer, "_loadOverlay(%s)", popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0xD: + { + sprintf(tempbuffer, "_palManipulation(%s,%s,%s,%s,%s)", + popDecomp(), popDecomp(), popDecomp(), popDecomp(), + popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0xE: + { + sprintf(tempbuffer, "_playSample(%s,%s,%s,%s)", + popDecomp(), popDecomp(), popDecomp(), + popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x10: + { + sprintf(tempbuffer, "_releaseScript2(%s)", + popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x11: + { + sprintf(tempbuffer, "_getOverlayIdx(%s)", popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x13: + { + sprintf(tempbuffer, + "_displayMessage(%s,\"%s\",%s,%s,%s,%s)", + popDecomp(), resolveMessage(popDecomp()), + popDecomp(), popDecomp(), popDecomp(), + popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x14: + { + sprintf(tempbuffer, "_removeObject(ovl(%s),%s)", + popDecomp(), popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x15: + { + pushDecomp("_pauseScript()"); + break; + } + case 0x16: + { + sprintf(tempbuffer, + "_Op_FreezeCell(%s,%s,%s,%s,%s,%s)", popDecomp(), + popDecomp(), popDecomp(), popDecomp(), popDecomp(), + popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x17: + { + sprintf(tempbuffer, "_loadCtp(%s)", popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x18: + { + sprintf(tempbuffer, + "_Op_AddAnimation(%s,%s,%s,%s,%s,%s,%s)", + popDecomp(), popDecomp(), popDecomp(), popDecomp(), + popDecomp(), popDecomp(), popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x19: + { + sprintf(tempbuffer, "_Op_RemoveAnimation(%s,%s,%s)", + popDecomp(), popDecomp(), popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x1A: + { + sprintf(tempbuffer, "_setupScaleFormula(%s,%s,%s,%s)", + popDecomp(), popDecomp(), popDecomp(), + popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x1E: + { + sprintf(tempbuffer, "_op_1E(%s,%s,%s,%s,%s,%s)", + popDecomp(), popDecomp(), popDecomp(), popDecomp(), + popDecomp(), popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x21: + { + sprintf(tempbuffer, "_isActorLoaded(%s,%s,%s)", + popDecomp(), popDecomp(), popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x22: + { + sprintf(tempbuffer, "_computeScale(%s)", popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x23: + { + sprintf(tempbuffer, "_convertToScale(%s,%s)", + popDecomp(), popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x24: + { + sprintf(tempbuffer, "_op_24(%s,%s,%s,%s)", popDecomp(), + popDecomp(), popDecomp(), popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x27: + { + sprintf(tempbuffer, "_getWalkBoxCollision(%s,%s)", + popDecomp(), popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x28: + { + sprintf(tempbuffer, "_changeSaveAllowedState(%s)", + popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x29: + { + pushDecomp("_freeAllPerso()"); + break; + } + case 0x2B: + { + sprintf(tempbuffer, "_getProcIdx(%s,%s)", popDecomp(), + popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x2C: + { + sprintf(tempbuffer, "_setObjectPosition(%s,%s,%s)", + popDecomp(), popDecomp(), popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x2E: + { + sprintf(tempbuffer, "_releaseScript(%s)", popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x2F: + { + sprintf(tempbuffer, "_addBackgroundIncrust(%s,%s,%s)", + popDecomp(), popDecomp(), popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x30: + { + sprintf(tempbuffer, "_removeBackgroundIncrust(%s,%s)", + popDecomp(), popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x31: + { + sprintf(tempbuffer, "_op_31(%s,%s)", popDecomp(), + popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x32: + { + pushDecomp("_freeBackgroundInscrustList()"); + break; + } + case 0x35: + { + sprintf(tempbuffer, "_op35(%s)", popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x37: + { + sprintf(tempbuffer, "_op37(%s,%s)", popDecomp(), + popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x38: + { + sprintf(tempbuffer, "_removeBackground(%s)", + popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x39: + { + sprintf(tempbuffer, "_SetActiveBackgroundPlane(%s)", + popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x3A: + { + sprintf(tempbuffer, "_setVar49(%s)", popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x3B: + { + pushDecomp("_op3B()"); + break; + } + case 0x3C: + { + sprintf(tempbuffer, "_rand(%s)", popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x3D: + { + sprintf(tempbuffer, "_loadMusic(%s)", popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x3E: + { + pushDecomp("_op_3E()"); + break; + } + case 0x3F: + { + pushDecomp("_op_3F()"); + break; + } + case 0x40: + { + pushDecomp("_op_40()"); + break; + } + case 0x41: + { + sprintf(tempbuffer, "_isFileLoaded2(%s)", popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x45: + { + pushDecomp("_stopSound()"); + break; + } + case 0x49: + { + sprintf(tempbuffer, "_op49(%s)", popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x54: + { + sprintf(tempbuffer, "_setFontVar(%s)", popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x56: + { + sprintf(tempbuffer, "_changeCutSceneState(%s)", + popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x57: + { + pushDecomp("_getMouseX()"); + break; + } + case 0x58: + { + pushDecomp("_getMouseY()"); + break; + } + case 0x59: + { + pushDecomp("_getMouse3()"); + break; + } + case 0x5A: + { + sprintf(tempbuffer, "_isFileLoaded(%s)", popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x5B: + { + pushDecomp("_regenerateBackgroundIncrust()"); + break; + } + case 0x5C: + { + sprintf(tempbuffer, "_Op_AddCellC(%s,%s)", popDecomp(), + popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x5E: + { + sprintf(tempbuffer, "_Op_AddCellE(%s)", popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x60: + { + sprintf(tempbuffer, "_op_60(%s,%s,%s,%s,%s)", + popDecomp(), popDecomp(), popDecomp(), popDecomp(), + popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x61: + { + sprintf(tempbuffer, "_op61(%s,%s)", popDecomp(), + popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x62: + { + pushDecomp("_pauseCallingScript()"); + break; + } + case 0x63: + { + pushDecomp("_resumeScript()"); + break; + } + case 0x64: + { + unsigned long int numArg = atoi(popDecomp()); + char *ovlStr; + char *idxStr; + int i; + char functionName[256]; + + idxStr = popDecomp(); + ovlStr = popDecomp(); + + resolveVarName(ovlStr, 0x20, idxStr, functionName); + + sprintf(tempbuffer, "%s(", functionName); + + for (i = 0; i < numArg; i++) { + if (i) + strcatuint8(tempbuffer, ","); + strcatuint8(tempbuffer, popDecomp()); + } + + strcatuint8(tempbuffer, ")"); + + pushDecomp(tempbuffer); + break; + } + case 0x65: + { + sprintf(tempbuffer, + "_addWaitObject(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)", + popDecomp(), popDecomp(), popDecomp(), popDecomp(), + popDecomp(), popDecomp(), popDecomp(), popDecomp(), + popDecomp(), popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x66: + { + sprintf(tempbuffer, "_op_66(%s,%s)", popDecomp(), + popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x67: + { + sprintf(tempbuffer, "_loadAudioResource(%s,%s)", + popDecomp(), popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x68: + { + pushDecomp("_freeMediumVar()"); + break; + } + case 0x6A: + { + sprintf(tempbuffer, "_op_6A(%s)", popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x6B: + { + sprintf(tempbuffer, "_loadData(%s,%s,%s,%s)", + popDecomp(), popDecomp(), popDecomp(), + popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x6C: + { + sprintf(tempbuffer, "_op_6C(%s,%s)", popDecomp(), + popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x6D: + { + sprintf(tempbuffer, "_strcpy(%s,%s)", popDecomp(), + popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x6E: + { + sprintf(tempbuffer, "_op_6E(%s,%s)", popDecomp(), + popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x6F: + { + unsigned long int numArg = atoi(popDecomp()); + char *ovlStr; + char *idxStr; + int i; + + idxStr = popDecomp(); + ovlStr = popDecomp(); + + sprintf(tempbuffer, "_op_6F(%s,%s", idxStr, ovlStr); + + for (i = 0; i < numArg; i++) { + strcatuint8(tempbuffer, ","); + strcatuint8(tempbuffer, popDecomp()); } - case 0x2E: - { - sprintf(tempbuffer,"_releaseScript(%s)",popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x2F: - { - sprintf(tempbuffer,"_addBackgroundIncrust(%s,%s,%s)",popDecomp(),popDecomp(),popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x30: - { - sprintf(tempbuffer,"_removeBackgroundIncrust(%s,%s)",popDecomp(),popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x31: - { - sprintf(tempbuffer,"_op_31(%s,%s)",popDecomp(),popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x32: - { - pushDecomp("_freeBackgroundInscrustList()"); - break; - } - case 0x35: - { - sprintf(tempbuffer,"_op35(%s)",popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x37: - { - sprintf(tempbuffer,"_op37(%s,%s)",popDecomp(),popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x38: - { - sprintf(tempbuffer,"_removeBackground(%s)",popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x39: - { - sprintf(tempbuffer,"_SetActiveBackgroundPlane(%s)",popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x3A: - { - sprintf(tempbuffer,"_setVar49(%s)",popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x3B: - { - pushDecomp("_op3B()"); - break; - } - case 0x3C: - { - sprintf(tempbuffer,"_rand(%s)",popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x3D: - { - sprintf(tempbuffer,"_loadMusic(%s)",popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x3E: - { - pushDecomp("_op_3E()"); - break; - } - case 0x3F: - { - pushDecomp("_op_3F()"); - break; - } - case 0x40: - { - pushDecomp("_op_40()"); - break; - } - case 0x41: - { - sprintf(tempbuffer,"_isFileLoaded2(%s)",popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x45: - { - pushDecomp("_stopSound()"); - break; - } - case 0x49: - { - sprintf(tempbuffer,"_op49(%s)",popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x54: - { - sprintf(tempbuffer,"_setFontVar(%s)",popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x56: - { - sprintf(tempbuffer,"_changeCutSceneState(%s)",popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x57: - { - pushDecomp("_getMouseX()"); - break; - } - case 0x58: - { - pushDecomp("_getMouseY()"); - break; - } - case 0x59: - { - pushDecomp("_getMouse3()"); - break; - } - case 0x5A: - { - sprintf(tempbuffer,"_isFileLoaded(%s)",popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x5B: - { - pushDecomp("_regenerateBackgroundIncrust()"); - break; - } - case 0x5C: - { - sprintf(tempbuffer,"_Op_AddCellC(%s,%s)",popDecomp(),popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x5E: - { - sprintf(tempbuffer,"_Op_AddCellE(%s)",popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x60: - { - sprintf(tempbuffer,"_op_60(%s,%s,%s,%s,%s)",popDecomp(),popDecomp(),popDecomp(),popDecomp(),popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x61: - { - sprintf(tempbuffer,"_op61(%s,%s)",popDecomp(),popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x62: - { - pushDecomp("_pauseCallingScript()"); - break; - } - case 0x63: - { - pushDecomp("_resumeScript()"); - break; - } - case 0x64: - { - unsigned long int numArg = atoi(popDecomp()); - char* ovlStr; - char* idxStr; - int i; - char functionName[256]; - - idxStr = popDecomp(); - ovlStr = popDecomp(); - - resolveVarName(ovlStr, 0x20, idxStr, functionName); - - sprintf(tempbuffer,"%s(",functionName); - - for(i=0;i<numArg;i++) - { - if(i) - strcatuint8(tempbuffer,","); - strcatuint8(tempbuffer,popDecomp()); - } - - strcatuint8(tempbuffer,")"); - - pushDecomp(tempbuffer); - break; - } - case 0x65: - { - sprintf(tempbuffer,"_addWaitObject(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",popDecomp(),popDecomp(),popDecomp(),popDecomp(),popDecomp(),popDecomp(),popDecomp(),popDecomp(),popDecomp(),popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x66: - { - sprintf(tempbuffer,"_op_66(%s,%s)",popDecomp(),popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x67: - { - sprintf(tempbuffer,"_loadAudioResource(%s,%s)",popDecomp(),popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x68: - { - pushDecomp("_freeMediumVar()"); - break; - } - case 0x6A: - { - sprintf(tempbuffer,"_op_6A(%s)",popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x6B: - { - sprintf(tempbuffer,"_loadData(%s,%s,%s,%s)",popDecomp(),popDecomp(),popDecomp(),popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x6C: - { - sprintf(tempbuffer,"_op_6C(%s,%s)",popDecomp(),popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x6D: - { - sprintf(tempbuffer,"_strcpy(%s,%s)",popDecomp(),popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x6E: - { - sprintf(tempbuffer,"_op_6E(%s,%s)",popDecomp(),popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x6F: - { - unsigned long int numArg = atoi(popDecomp()); - char* ovlStr; - char* idxStr; - int i; - - idxStr = popDecomp(); - ovlStr = popDecomp(); - - sprintf(tempbuffer,"_op_6F(%s,%s",idxStr,ovlStr); - - for(i=0;i<numArg;i++) - { - strcatuint8(tempbuffer,","); - strcatuint8(tempbuffer,popDecomp()); - } - - strcatuint8(tempbuffer,")"); - - pushDecomp(tempbuffer); - break; - } - case 0x70: - { - sprintf(tempbuffer,"_comment(%s)",popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x71: - { - sprintf(tempbuffer,"_op71(%s,%s,%s,%s,%s)",popDecomp(),popDecomp(),popDecomp(),popDecomp(),popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x72: - { - sprintf(tempbuffer,"_op72(%s,%s)",popDecomp(),popDecomp(),popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x73: - { - sprintf(tempbuffer,"_op73(%s)",popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x74: - { - sprintf(tempbuffer,"_getInitVar1()"); - pushDecomp(tempbuffer); - break; - } - case 0x76: - { - sprintf(tempbuffer,"_Op_InitializeState6(%s,%s)",popDecomp(),popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x77: - { - sprintf(tempbuffer,"_Op_InitializeState7(%s)",popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x78: - { - sprintf(tempbuffer,"_Op_InitializeState8(%s)",popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x79: - { - sprintf(tempbuffer,"_EnterPlayerMenu(%s)",popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x7B: - { - sprintf(tempbuffer,"_Op_InitializeStateB(%s)",popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x7C: - { - sprintf(tempbuffer,"_Op_InitializeStateC(%s)",popDecomp()); - pushDecomp(tempbuffer); - break; - } - case 0x7D: - { - pushDecomp("_freeAllMenu()"); - break; - } + + strcatuint8(tempbuffer, ")"); + + pushDecomp(tempbuffer); + break; + } + case 0x70: + { + sprintf(tempbuffer, "_comment(%s)", popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x71: + { + sprintf(tempbuffer, "_op71(%s,%s,%s,%s,%s)", + popDecomp(), popDecomp(), popDecomp(), popDecomp(), + popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x72: + { + sprintf(tempbuffer, "_op72(%s,%s)", popDecomp(), + popDecomp(), popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x73: + { + sprintf(tempbuffer, "_op73(%s)", popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x74: + { + sprintf(tempbuffer, "_getInitVar1()"); + pushDecomp(tempbuffer); + break; + } + case 0x76: + { + sprintf(tempbuffer, "_Op_InitializeState6(%s,%s)", + popDecomp(), popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x77: + { + sprintf(tempbuffer, "_Op_InitializeState7(%s)", + popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x78: + { + sprintf(tempbuffer, "_Op_InitializeState8(%s)", + popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x79: + { + sprintf(tempbuffer, "_EnterPlayerMenu(%s)", + popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x7B: + { + sprintf(tempbuffer, "_Op_InitializeStateB(%s)", + popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x7C: + { + sprintf(tempbuffer, "_Op_InitializeStateC(%s)", + popDecomp()); + pushDecomp(tempbuffer); + break; + } + case 0x7D: + { + pushDecomp("_freeAllMenu()"); + break; + } default: { addDecomp("OP_%X", currentScriptOpcodeType); - printf("OPCODE: %X\n",currentScriptOpcodeType); - failed = 1; + printf("OPCODE: %X\n", currentScriptOpcodeType); + failed = 1; break; } - } - + } + // pushDecomp("functionDummyPush"); - return(0); + return (0); } uint8 stop = 0; -int decompStop(void) -{ - stop = 1; - addDecomp("stop\n"); - return 0; +int decompStop(void) { + stop = 1; + addDecomp("stop\n"); + return 0; } -int decompBreak(void) -{ - addDecomp("break"); - return 0; +int decompBreak(void) { + addDecomp("break"); + return 0; } -void generateIndentation(void) -{ - int i; +void generateIndentation(void) { + int i; - for(i=0;i<positionInDecompileLineTable;i++) - { - if(decompileLineTable[i].type != 0) - { - char* gotoStatement; - int destLine; - int destLineIdx; - - gotoStatement = strstr(decompileLineTable[i].line,"goto"); - assert(gotoStatement); - gotoStatement = strchr(gotoStatement,' ')+1; - - destLine = atoi(gotoStatement); - - { - int j; - - destLineIdx = -1; - - for(j=0;j<positionInDecompileLineTable;j++) - { - if(decompileLineTable[j].lineOffset == destLine) - { - destLineIdx = j; - break; - } - } - - assert(destLineIdx != -1); - - if(destLineIdx>i) - { - int j; - - for(j=i+1;j<destLineIdx;j++) - { - decompileLineTable[j].indent++; - } - - if(strstr(decompileLineTable[destLineIdx-1].line,"goto") == decompileLineTable[destLineIdx-1].line) - { - //decompileLineTable[destLineIdx-1].pendingElse = 1; - } - } - } - } - } + for (i = 0; i < positionInDecompileLineTable; i++) { + if (decompileLineTable[i].type != 0) { + char *gotoStatement; + int destLine; + int destLineIdx; + + gotoStatement = + strstr(decompileLineTable[i].line, "goto"); + assert(gotoStatement); + gotoStatement = strchr(gotoStatement, ' ') + 1; + + destLine = atoi(gotoStatement); + + { + int j; + + destLineIdx = -1; + + for (j = 0; j < positionInDecompileLineTable; + j++) { + if (decompileLineTable[j].lineOffset == + destLine) { + destLineIdx = j; + break; + } + } + + assert(destLineIdx != -1); + + if (destLineIdx > i) { + int j; + + for (j = i + 1; j < destLineIdx; j++) { + decompileLineTable[j].indent++; + } + + if (strstr(decompileLineTable + [destLineIdx - 1].line, + "goto") == + decompileLineTable[destLineIdx - + 1].line) { + //decompileLineTable[destLineIdx-1].pendingElse = 1; + } + } + } + } + } } -void dumpScript(uint8* ovlName, ovlDataStruct* ovlData,int idx) -{ +void dumpScript(uint8 *ovlName, ovlDataStruct *ovlData, int idx) { uint8 opcodeType; char buffer[256]; int i; - + char temp[256]; char scriptName[256]; - sprintf(temp,"%d",idx); + sprintf(temp, "%d", idx); - failed = 0; - - currentScript = &ovlData->data3Table[idx]; + failed = 0; - currentDecompScript = currentScript->dataPtr; - currentDecompScriptPtr->var4 = 0; + currentScript = &ovlData->data3Table[idx]; - currentDecompOvl = ovlData; - currentDecompScriptIdx = idx; + currentDecompScript = currentScript->dataPtr; + currentDecompScriptPtr->var4 = 0; - currentLineIdx = 0; - positionInDecompileLineTable = 0; - currentLineType = 0; + currentDecompOvl = ovlData; + currentDecompScriptIdx = idx; - resolveVarName("0",0x20,temp, scriptName); + currentLineIdx = 0; + positionInDecompileLineTable = 0; + currentLineType = 0; - printf("decompiling script %d - %s\n",idx,scriptName); + resolveVarName("0", 0x20, temp, scriptName); - // return; + printf("decompiling script %d - %s\n", idx, scriptName); -// scriptDataPtrTable[1] = *(char**)(ptr+0x6); - scriptDataPtrTable[2] = getDataFromData3(currentScript, 1); // strings - scriptDataPtrTable[5] = ovlData->data4Ptr; // free strings + // return; + +// scriptDataPtrTable[1] = *(char**)(ptr+0x6); + scriptDataPtrTable[2] = getDataFromData3(currentScript, 1); // strings + scriptDataPtrTable[5] = ovlData->data4Ptr; // free strings scriptDataPtrTable[6] = ovlData->ptr8; - stop = 0; + stop = 0; - sprintf(buffer,"%s-%02d-%s.txt",ovlName,idx,scriptName); - fHandle = fopen(buffer,"w+"); + sprintf(buffer, "%s-%02d-%s.txt", ovlName, idx, scriptName); + fHandle = fopen(buffer, "w+"); - decompileStackPosition = 0; + decompileStackPosition = 0; - for(i=0;i<64;i++) - { + for (i = 0; i < 64; i++) { decompOpcodeTypeTable[i] = NULL; } - decompOpcodeTypeTable[1] = decompLoadVar; - decompOpcodeTypeTable[2] = decompSaveVar; - decompOpcodeTypeTable[3] = decompOpcodeType2; - decompOpcodeTypeTable[4] = decompMath; - decompOpcodeTypeTable[5] = decompBoolCompare; - decompOpcodeTypeTable[6] = decompTest; - decompOpcodeTypeTable[7] = decompCompare; - decompOpcodeTypeTable[8] = decompSwapStack; - decompOpcodeTypeTable[9] = decompFunction; - decompOpcodeTypeTable[10] = decompStop; - decompOpcodeTypeTable[12] = decompBreak; - - do - { - currentOffset = currentDecompScriptPtr->var4; + decompOpcodeTypeTable[1] = decompLoadVar; + decompOpcodeTypeTable[2] = decompSaveVar; + decompOpcodeTypeTable[3] = decompOpcodeType2; + decompOpcodeTypeTable[4] = decompMath; + decompOpcodeTypeTable[5] = decompBoolCompare; + decompOpcodeTypeTable[6] = decompTest; + decompOpcodeTypeTable[7] = decompCompare; + decompOpcodeTypeTable[8] = decompSwapStack; + decompOpcodeTypeTable[9] = decompFunction; + decompOpcodeTypeTable[10] = decompStop; + decompOpcodeTypeTable[12] = decompBreak; + + do { + currentOffset = currentDecompScriptPtr->var4; opcodeType = getByteFromDecompScriptReal(); currentScriptOpcodeType = opcodeType & 7; - if(!decompOpcodeTypeTable[(opcodeType&0xFB)>>3]) - { - printf("Unsupported opcode type %d in decomp\n",(opcodeType&0xFB)>>3); + if (!decompOpcodeTypeTable[(opcodeType & 0xFB) >> 3]) { + printf("Unsupported opcode type %d in decomp\n", + (opcodeType & 0xFB) >> 3); return; } - - //printf("Optype: %d\n",(opcodeType&0xFB)>>3); + //printf("Optype: %d\n",(opcodeType&0xFB)>>3); - decompOpcodeTypeTable[(opcodeType&0xFB)>>3](); + decompOpcodeTypeTable[(opcodeType & 0xFB) >> 3] (); - if(failed) - { + if (failed) { printf("Aborting decompilation..\n"); fclose(fHandle); return; } - }while(!stop); + } while (!stop); - dumpIdx++; + dumpIdx++; - generateIndentation(); + generateIndentation(); - for(i=0;i<positionInDecompileLineTable;i++) - { - int j; - - if(decompileLineTable[i].pendingElse) - { - fprintf(fHandle,"%05d:\t", decompileLineTable[i].lineOffset); - fprintf(fHandle,"else", decompileLineTable[i].line); - fprintf(fHandle,"\n"); - } - - fprintf(fHandle,"%05d:\t", decompileLineTable[i].lineOffset); - for(j=0;j<decompileLineTable[i].indent;j++) - { - fprintf(fHandle,"\t"); - } - fprintf(fHandle,"%s", decompileLineTable[i].line); - fprintf(fHandle,"\n"); - } + for (i = 0; i < positionInDecompileLineTable; i++) { + int j; + + if (decompileLineTable[i].pendingElse) { + fprintf(fHandle, "%05d:\t", + decompileLineTable[i].lineOffset); + fprintf(fHandle, "else", decompileLineTable[i].line); + fprintf(fHandle, "\n"); + } - fclose(fHandle); + fprintf(fHandle, "%05d:\t", decompileLineTable[i].lineOffset); + for (j = 0; j < decompileLineTable[i].indent; j++) { + fprintf(fHandle, "\t"); + } + fprintf(fHandle, "%s", decompileLineTable[i].line); + fprintf(fHandle, "\n"); + } + + fclose(fHandle); } #endif } // End of namespace Cruise - diff --git a/engines/cruise/delphine-unpack.cpp b/engines/cruise/delphine-unpack.cpp index 6d21527481..fe32cbb018 100644 --- a/engines/cruise/delphine-unpack.cpp +++ b/engines/cruise/delphine-unpack.cpp @@ -26,12 +26,11 @@ namespace Cruise { -uint32 crc; // variable at 5C5A -uint32 bitbucket; // dx:bx +uint32 crc; // variable at 5C5A +uint32 bitbucket; // dx:bx -uint16 swap16(uint16 r) -{ - return (r >> 8) | (r << 8); +uint16 swap16(uint16 r) { + return (r >> 8) | (r << 8); } #define loadd(p, d) {\ @@ -64,90 +63,91 @@ uint16 swap16(uint16 r) } while (nbits);\ } -int32 decomp(uint8 * in, uint8 * out, int32 size) { - uint8 bit = 0; // Carry flag - uint8 nbits = 0; // cl - uint8 byte = 0; // ch - uint16 counter = 0; // bp - uint16 var = 0; // variable at 5C58 - uint16 ptr = 0; - uint16 flags = 0; - enum { - DO_COPY, - DO_UNPACK - } action; - - loadd(in, crc); - loadd(in, bitbucket); - crc ^= bitbucket; - - do { // 5A4C - getbit(in, bit); - if (!bit) { // 5A94 - getbit(in, bit); - if (!bit) { // 5AC8 - nbits = 3; - byte = 0; - action = DO_COPY; - } else { // 5ACA - var = 1; - nbits = 8; - action = DO_UNPACK; - } - } else { // 5B4F - nbits = 2; - loadbits(in, flags); - if (flags < 2) { - nbits = flags + 9; // 5BC3 - var = flags + 2; - action = DO_UNPACK; - } else if (flags == 3) { - nbits = 8; // 5B4A - byte = 8; - action = DO_COPY; - } else { - nbits = 8; - loadbits(in, var); - nbits = 12; - action = DO_UNPACK; - } +int32 decomp(uint8 *in, uint8 *out, int32 size) { + uint8 bit = 0; // Carry flag + uint8 nbits = 0; // cl + uint8 byte = 0; // ch + uint16 counter = 0; // bp + uint16 var = 0; // variable at 5C58 + uint16 ptr = 0; + uint16 flags = 0; + enum { + DO_COPY, + DO_UNPACK + } action; + + loadd(in, crc); + loadd(in, bitbucket); + crc ^= bitbucket; + + do { // 5A4C + getbit(in, bit); + if (!bit) { // 5A94 + getbit(in, bit); + if (!bit) { // 5AC8 + nbits = 3; + byte = 0; + action = DO_COPY; + } else { // 5ACA + var = 1; + nbits = 8; + action = DO_UNPACK; + } + } else { // 5B4F + nbits = 2; + loadbits(in, flags); + if (flags < 2) { + nbits = flags + 9; // 5BC3 + var = flags + 2; + action = DO_UNPACK; + } else if (flags == 3) { + nbits = 8; // 5B4A + byte = 8; + action = DO_COPY; + } else { + nbits = 8; + loadbits(in, var); + nbits = 12; + action = DO_UNPACK; + } + } + + switch (action) { + case DO_COPY: + // 5AD1 + loadbits(in, counter); // 5AFD + counter += byte; + counter++; + size -= counter; + do { + nbits = 8; + loadbits(in, byte); // 5B3F + store(out, byte); + counter--; + } while (counter); // 5B45 + break; + case DO_UNPACK: + // 5BD3 + loadbits(in, ptr); // 5BFF + counter = var + 1; + size -= counter; + do { + byte = *(out + ptr - 1); + store(out, byte); + counter--; + } while (counter); + } + } while (size > 0); + // 5C32 + // ??? + + if (crc) { + return -1; + } else { + return 0; } - - switch (action) { - case DO_COPY: - // 5AD1 - loadbits(in, counter); // 5AFD - counter += byte; - counter++; - size -= counter; - do { - nbits = 8; - loadbits(in, byte); // 5B3F - store(out, byte); - counter--; - } while (counter); // 5B45 - break; - case DO_UNPACK: - // 5BD3 - loadbits(in, ptr); // 5BFF - counter = var + 1; - size -= counter; - do { - byte = *(out + ptr - 1); - store(out, byte); - counter--; - } while(counter); - } - } while (size > 0); - // 5C32 - // ??? - - if (crc) { - return -1; - } else { - return 0; - } } + /* int main(void) { FILE * in, * out; @@ -172,5 +172,4 @@ int main(void) { fclose(in); }*/ - } // End of namespace Cruise diff --git a/engines/cruise/detection.cpp b/engines/cruise/detection.cpp index 8ee866e233..d40f98f067 100644 --- a/engines/cruise/detection.cpp +++ b/engines/cruise/detection.cpp @@ -31,6 +31,7 @@ #include "cruise/cruise.h" namespace Cruise { + struct CRUISEGameDescription { Common::ADGameDescription desc; @@ -60,7 +61,7 @@ namespace Cruise { static const CRUISEGameDescription gameDescriptions[] = { { - { + { "cruise", "", AD_ENTRY1("D1", "41a7a4d426dbd048eb369cfee4bb2717"), @@ -70,9 +71,9 @@ static const CRUISEGameDescription gameDescriptions[] = { }, GType_CRUISE, 0, - }, + }, { - { + { "cruise", "", AD_ENTRY1("D1", "a90d2b9ead6b4d812cd14268672cf178"), @@ -83,7 +84,7 @@ static const CRUISEGameDescription gameDescriptions[] = { GType_CRUISE, 0, }, - { AD_TABLE_END_MARKER, 0, 0 } + {AD_TABLE_END_MARKER, 0, 0} }; } @@ -117,6 +118,7 @@ namespace Cruise { bool CruiseEngine::initGame() { _gameDescription = (const CRUISEGameDescription *)Common::AdvancedDetector::detectBestMatchingGame(detectionParams); + return (_gameDescription != 0); } diff --git a/engines/cruise/font.cpp b/engines/cruise/font.cpp index 5792f3f9ef..a5758db361 100644 --- a/engines/cruise/font.cpp +++ b/engines/cruise/font.cpp @@ -29,23 +29,19 @@ namespace Cruise { // (old: fontProc1(int16 param, uint8* ptr1, uint8* ptr2)) -int32 getLineHeight(int16 charCount, uint8* fontPtr, uint8* fontPrt_Desc) -{ - uint8* dest; +int32 getLineHeight(int16 charCount, uint8 * fontPtr, uint8 * fontPrt_Desc) { + uint8 *dest; int32 highestChar = 0; int32 i; - if(!charCount) - { - return(0); + if (!charCount) { + return (0); } - dest = fontPrt_Desc + 6; // fontPtr + 20 // char height + dest = fontPrt_Desc + 6; // fontPtr + 20 // char height - for(i = 0; i < charCount; i++) - { - if((*(int16*) dest) > highestChar) - { - highestChar = *(int16*) dest; + for (i = 0; i < charCount; i++) { + if ((*(int16 *) dest) > highestChar) { + highestChar = *(int16 *) dest; } dest += 12; } @@ -53,43 +49,36 @@ int32 getLineHeight(int16 charCount, uint8* fontPtr, uint8* fontPrt_Desc) } // this function determins how many lines the text will have (old: fontProc2(int32 param1, int32 param2, uint8* ptr, uint8* string)) -int32 getTextLineCount(int32 rightBorder_X, int32 wordSpacingWidth, uint8* ptr, uint8* textString) -{ - uint8* localString = textString; - uint8* currentStringPtr; - uint8 character; +int32 getTextLineCount(int32 rightBorder_X, int32 wordSpacingWidth, + uint8 *ptr, uint8 *textString) { + uint8 *localString = textString; + uint8 *currentStringPtr; + uint8 character; - int32 var_6 = 0; + int32 var_6 = 0; int32 lineLength = 0; - uint8* tempPtr = 0; + uint8 *tempPtr = 0; - if(!*localString) - { - return(0); + if (!*localString) { + return (0); } currentStringPtr = localString; - character = *localString; + character = *localString; - do - { + do { int32 charData = fontCharacterTable[character]; - if(character == '|') - { - lineLength = rightBorder_X; + if (character == '|') { + lineLength = rightBorder_X; localString = tempPtr; - } - else - { - if(charData >= 0) - { // + 0xA jump to last 2 bytes of the 12 bytes slice = letter width - lineLength += wordSpacingWidth + *(int16*) (ptr + 0xA + charData * 12); - } - else - { - if(character == ' ') - { + } else { + if (charData >= 0) { // + 0xA jump to last 2 bytes of the 12 bytes slice = letter width + lineLength += + wordSpacingWidth + *(int16 *) (ptr + 0xA + + charData * 12); + } else { + if (character == ' ') { lineLength += wordSpacingWidth + 5; localString = currentStringPtr; } @@ -98,81 +87,72 @@ int32 getTextLineCount(int32 rightBorder_X, int32 wordSpacingWidth, uint8* ptr, tempPtr = currentStringPtr; - if(rightBorder_X <= lineLength) - { - var_6 += rightBorder_X; + if (rightBorder_X <= lineLength) { + var_6 += rightBorder_X; currentStringPtr = localString; - tempPtr = localString; - lineLength = 0; - } + tempPtr = localString; + lineLength = 0; + } - character = *(tempPtr++); + character = *(tempPtr++); currentStringPtr = tempPtr; - } while(character); + } while (character); - if(lineLength == 0) - { + if (lineLength == 0) { return (var_6 / rightBorder_X); - } - else - { + } else { return ((var_6 + rightBorder_X) / rightBorder_X); } } -void loadFNT(const void* fileNameChar) -{ - uint8 header[6]; - int32 fontSize; - int32 data2; - uint8 data3[6]; - uint8* fileName = (uint8*) fileNameChar; - _systemFNT = NULL; +void loadFNT(const void *fileNameChar) { + uint8 header[6]; + int32 fontSize; + int32 data2; + uint8 data3[6]; + uint8 *fileName = (uint8 *) fileNameChar; + _systemFNT = NULL; Common::File fontFileHandle; - - if(!fontFileHandle.exists((char*)fileName)) - { + + if (!fontFileHandle.exists((char *)fileName)) { return; } - fontFileHandle.open((char*)fileName); + fontFileHandle.open((char *)fileName); fontFileHandle.read(header, 4); - if(strcmpuint8(header, "FNT") == 0) - { + if (strcmpuint8(header, "FNT") == 0) { fontFileHandle.read(&fontSize, 4); flipLong(&fontSize); fontFileHandle.read(&data2, 4); flipLong(&data2); - fontFileHandle.read(data3, 6); // may need an endian flip ? + fontFileHandle.read(data3, 6); // may need an endian flip ? flipGen(&data3, 6); - _systemFNT = (uint8*) mallocAndZero(fontSize); + _systemFNT = (uint8 *) mallocAndZero(fontSize); - if(_systemFNT != NULL) - { + if (_systemFNT != NULL) { int32 i; - uint8* currentPtr; + uint8 *currentPtr; fontFileHandle.seek(0); fontFileHandle.read(header, 4); // not really require, we could fseek to 4 fontFileHandle.read(_systemFNT, fontSize); - flipLong((int32*) _systemFNT); - flipLong((int32*) (_systemFNT + 4)); + flipLong((int32 *) _systemFNT); + flipLong((int32 *) (_systemFNT + 4)); flipGen(_systemFNT + 8, 6); currentPtr = _systemFNT + 14; - for(i = 0; i < *(int16*) (_systemFNT + 8); i++) - { - flipLong((int32*) currentPtr); + for (i = 0; i < *(int16 *) (_systemFNT + 8); i++) { + flipLong((int32 *) currentPtr); currentPtr += 4; flipGen(currentPtr, 8); @@ -184,8 +164,7 @@ void loadFNT(const void* fileNameChar) fontFileHandle.close(); } -void loadSystemFont(void) -{ +void loadSystemFont(void) { int32 i; video2 = 15; @@ -193,15 +172,14 @@ void loadSystemFont(void) video3 = 13; colorOfSelectedSaveDrive = 10; - for(i = 0; i < 64; i++) - { - mediumVar[i].ptr = 0; + for (i = 0; i < 64; i++) { + mediumVar[i].ptr = 0; mediumVar[i].field_1C = 0; } initVar1 = 0; - main5 = 0; - var22 = 0; + main5 = 0; + var22 = 0; initVar2 = 0; initVar3 = 0; currentActiveBackgroundPlane = 0; @@ -213,344 +191,311 @@ void loadSystemFont(void) loadFNT("system.fnt"); } -void flipShort(int16* var) -{ - uint8* varPtr = (uint8*) var; - uint8 temp = varPtr[0]; +void flipShort(int16 *var) { + uint8 *varPtr = (uint8 *) var; + uint8 temp = varPtr[0]; varPtr[0] = varPtr[1]; varPtr[1] = temp; } -void flipShort(uint16* var) -{ - uint8* varPtr = (uint8*) var; - uint8 temp = varPtr[0]; +void flipShort(uint16 *var) { + uint8 *varPtr = (uint8 *) var; + uint8 temp = varPtr[0]; varPtr[0] = varPtr[1]; varPtr[1] = temp; } -void flipLong(int32* var) -{ +void flipLong(int32 *var) { char swap1; char swap2; - char* varPtr = (char*) var; + char *varPtr = (char *)var; - swap1 = varPtr[0]; + swap1 = varPtr[0]; varPtr[0] = varPtr[3]; varPtr[3] = swap1; - swap2 = varPtr[1]; + swap2 = varPtr[1]; varPtr[1] = varPtr[2]; varPtr[2] = swap2; } -void flipLong(uint32* var) -{ +void flipLong(uint32 *var) { char swap1; char swap2; - char* varPtr = (char*) var; + char *varPtr = (char *)var; - swap1 = varPtr[0]; + swap1 = varPtr[0]; varPtr[0] = varPtr[3]; varPtr[3] = swap1; - swap2 = varPtr[1]; + swap2 = varPtr[1]; varPtr[1] = varPtr[2]; varPtr[2] = swap2; } -void flipGen(void* var, int32 length) -{ +void flipGen(void *var, int32 length) { int i; - short int* varPtr = (int16*) var; + short int *varPtr = (int16 *) var; - for(i = 0; i < (length / 2); i++) - { + for (i = 0; i < (length / 2); i++) { flipShort(&varPtr[i]); } } - -void renderWord(uint8* fontPtr_Data, uint8* outBufferPtr, int32 drawPosPixel_X, int32 heightOff, int32 height, int32 param4, int32 stringRenderBufferSize, int32 width, int32 charWidth) -{ +void renderWord(uint8 * fontPtr_Data, uint8 * outBufferPtr, + int32 drawPosPixel_X, int32 heightOff, int32 height, int32 param4, + int32 stringRenderBufferSize, int32 width, int32 charWidth) { int i; int j; - uint8* fontPtr_Data2 = fontPtr_Data + height * 2; + uint8 *fontPtr_Data2 = fontPtr_Data + height * 2; - outBufferPtr += heightOff * width * 2; // param2 = height , param6 = width - outBufferPtr += drawPosPixel_X; // param1 = drawPosPixel_X + outBufferPtr += heightOff * width * 2; // param2 = height , param6 = width + outBufferPtr += drawPosPixel_X; // param1 = drawPosPixel_X - for(i = 0; i < height; i++) // y++ + for (i = 0; i < height; i++) // y++ { - uint16 currentColor1 = (*(fontPtr_Data) << 8) | *(fontPtr_Data + 1); - uint16 currentColor2 = (*(fontPtr_Data2) << 8) | *(fontPtr_Data2 + 1); + uint16 currentColor1 = + (*(fontPtr_Data) << 8) | *(fontPtr_Data + 1); + uint16 currentColor2 = + (*(fontPtr_Data2) << 8) | *(fontPtr_Data2 + 1); - fontPtr_Data += 2; + fontPtr_Data += 2; fontPtr_Data2 += 2; - for (j = 0; j < charWidth; j++) - { - *outBufferPtr = ((currentColor1 >> 15) & 1) | ((currentColor2 >> 14) & 2); + for (j = 0; j < charWidth; j++) { + *outBufferPtr = + ((currentColor1 >> 15) & 1) | ((currentColor2 >> + 14) & 2); outBufferPtr++; - - currentColor1 <<= 1; - currentColor2 <<= 1; + + currentColor1 <<= 1; + currentColor2 <<= 1; } outBufferPtr += (width * 2) - charWidth; } } // returns character count and pixel size (via pointer) per line of the string (old: prepareWordRender(int32 param, int32 var1, int16* out2, uint8* ptr3, uint8* string)) -int32 prepareWordRender(int32 inRightBorder_X, int32 wordSpacingWidth, int16* strPixelLength, uint8* ptr3, uint8* textString) -{ - uint8* localString = textString; +int32 prepareWordRender(int32 inRightBorder_X, int32 wordSpacingWidth, + int16 * strPixelLength, uint8 * ptr3, uint8 * textString) { + uint8 *localString = textString; - int32 counter = 0; - int32 finish = 0; - int32 temp_pc = 0; // var_A // temporary pixel count save - int32 temp_cc = 0; // var_C // temporary char count save - int32 pixelCount = 0; // si + int32 counter = 0; + int32 finish = 0; + int32 temp_pc = 0; // var_A // temporary pixel count save + int32 temp_cc = 0; // var_C // temporary char count save + int32 pixelCount = 0; // si - do - { + do { uint8 character = *(localString++); int16 charData = fontCharacterTable[character]; - if(character == ' ') - { + if (character == ' ') { temp_cc = counter; temp_pc = pixelCount; - if(pixelCount + wordSpacingWidth + 5 >= inRightBorder_X) - { + if (pixelCount + wordSpacingWidth + 5 >= + inRightBorder_X) { finish = 1; + } else { + pixelCount += wordSpacingWidth + 5; } - else - { - pixelCount += wordSpacingWidth + 5 ; - } - } - else - { - if(character == '|' || !character) - { + } else { + if (character == '|' || !character) { finish = 1; - } - else - { - if(charData) - { - if(pixelCount + wordSpacingWidth + *(int16*) ((ptr3 + charData * 12) + 0xA) >= inRightBorder_X) - { + } else { + if (charData) { + if (pixelCount + wordSpacingWidth + + *(int16 *) ((ptr3 + + charData * 12) + 0xA) >= + inRightBorder_X) { finish = 1; - if(temp_pc) - { + if (temp_pc) { pixelCount = temp_pc; - counter = temp_cc; + counter = temp_cc; } - } - else - { - pixelCount += wordSpacingWidth + *(int16*) ((ptr3 + charData * 12) + 0xA); + } else { + pixelCount += + wordSpacingWidth + + *(int16 *) ((ptr3 + + charData * 12) + 0xA); } } } } counter++; - } while(!finish); + } while (!finish); *strPixelLength = (int16) pixelCount; return counter; } - -void drawString(int32 x, int32 y, uint8* string, uint8* buffer, uint8 color, int32 inRightBorder_X) -{ - uint8* fontPtr; - uint8* fontPtr_Data; // ptr2 - uint8* fontPtr_Desc; // ptr3 - int32 wordSpacingWidth; // var1 - int32 wordSpacingHeight; // var2 - int32 rightBorder_X; // param2 - int32 lineHeight; // fontProc1result +void drawString(int32 x, int32 y, uint8 *string, uint8 *buffer, uint8 color, + int32 inRightBorder_X) { + uint8 *fontPtr; + uint8 *fontPtr_Data; // ptr2 + uint8 *fontPtr_Desc; // ptr3 + int32 wordSpacingWidth; // var1 + int32 wordSpacingHeight; // var2 + int32 rightBorder_X; // param2 + int32 lineHeight; // fontProc1result int32 numLines; int32 stringHeight; int32 stringFinished; - int32 stringWidth; // var_1C + int32 stringWidth; // var_1C int32 stringRenderBufferSize; int32 useDynamicBuffer; - uint8* currentStrRenderBuffer; - // int32 var_8; // don't need that on - int32 heightOffset; // var_12 - int32 renderBufferSize; // var_1E + uint8 *currentStrRenderBuffer; + // int32 var_8; // don't need that on + int32 heightOffset; // var_12 + int32 renderBufferSize; // var_1E int needFlip; - if(!buffer || !string) - { + if (!buffer || !string) { return; } - if(fontFileIndex != -1) - { + if (fontFileIndex != -1) { fontPtr = filesDatabase[fontFileIndex].subData.ptr; - if(!fontPtr) - { + if (!fontPtr) { fontPtr = _systemFNT; } - } - else - { + } else { fontPtr = _systemFNT; } - if(!fontPtr) - { + if (!fontPtr) { return; } - fontPtr_Data = fontPtr + *(int16*) (fontPtr + 4); + fontPtr_Data = fontPtr + *(int16 *) (fontPtr + 4); fontPtr_Desc = fontPtr + 14; - lineHeight = getLineHeight(*(int16*) (fontPtr + 8), fontPtr, fontPtr_Desc); // ok + lineHeight = getLineHeight(*(int16 *) (fontPtr + 8), fontPtr, fontPtr_Desc); // ok - wordSpacingWidth = *(int16*) (fontPtr + 10); - wordSpacingHeight = *(int16*) (fontPtr + 12); + wordSpacingWidth = *(int16 *) (fontPtr + 10); + wordSpacingHeight = *(int16 *) (fontPtr + 12); - if(inRightBorder_X > 310) - { + if (inRightBorder_X > 310) { rightBorder_X = 310; - } - else - { + } else { rightBorder_X = inRightBorder_X; } - if(x + rightBorder_X > 319) - { + if (x + rightBorder_X > 319) { x = 319 - rightBorder_X; } - if(y < 0) - { + if (y < 0) { y = 0; } - if(x < 0) - { + if (x < 0) { x = 0; } - numLines = getTextLineCount(rightBorder_X, wordSpacingWidth, fontPtr_Desc, string); // ok + numLines = getTextLineCount(rightBorder_X, wordSpacingWidth, fontPtr_Desc, string); // ok - if(!numLines) - { + if (!numLines) { return; } stringHeight = ((wordSpacingHeight + lineHeight + 2) * numLines) + 1; - if (y + stringHeight > 199) - { + if (y + stringHeight > 199) { y = 200 - stringHeight; } - stringFinished = 0; - stringWidth = (rightBorder_X / 16) + 2; + stringFinished = 0; + stringWidth = (rightBorder_X / 16) + 2; stringRenderBufferSize = stringWidth * stringHeight * 4; - inRightBorder_X = rightBorder_X; + inRightBorder_X = rightBorder_X; - if(stringRenderBufferSize > 0x2000) - { - currentStrRenderBuffer = (uint8*) mallocAndZero(stringRenderBufferSize); + if (stringRenderBufferSize > 0x2000) { + currentStrRenderBuffer = + (uint8 *) mallocAndZero(stringRenderBufferSize); - if(!currentStrRenderBuffer) - { + if (!currentStrRenderBuffer) { return; } useDynamicBuffer = 1; - } - else - { - currentStrRenderBuffer = (uint8*) ptr_something; - useDynamicBuffer = 0; + } else { + currentStrRenderBuffer = (uint8 *) ptr_something; + useDynamicBuffer = 0; } resetRaster(currentStrRenderBuffer, stringRenderBufferSize); // var_8 = 0; heightOffset = 0; - renderBufferSize = stringRenderBufferSize; + renderBufferSize = stringRenderBufferSize; - do - { - int spacesCount = 0; // si - char character = *(string); - short int strPixelLength; // var_16; - uint8* ptrStringEnd; // var_4 //ok - int drawPosPixel_X; // di - - while(character == ' ') - { + do { + int spacesCount = 0; // si + char character = *(string); + short int strPixelLength; // var_16; + uint8 *ptrStringEnd; // var_4 //ok + int drawPosPixel_X; // di + + while (character == ' ') { spacesCount++; character = *(string + spacesCount); } - string += spacesCount; - ptrStringEnd = string + prepareWordRender(inRightBorder_X, wordSpacingWidth, &strPixelLength, fontPtr_Desc, string); //ok + string += spacesCount; + ptrStringEnd = string + prepareWordRender(inRightBorder_X, wordSpacingWidth, &strPixelLength, fontPtr_Desc, string); //ok - if(inRightBorder_X > strPixelLength) - { - drawPosPixel_X = (inRightBorder_X - strPixelLength) / 2; - } - else - { + if (inRightBorder_X > strPixelLength) { + drawPosPixel_X = + (inRightBorder_X - strPixelLength) / 2; + } else { drawPosPixel_X = 0; } // drawPosPixel_X = var_8; - do - { + do { character = *(string++); short int data = fontCharacterTable[(int)character]; - if(character) - { - if(character == ' ' || character == 0x7D) - { + if (character) { + if (character == ' ' || character == 0x7D) { drawPosPixel_X += var1 + 5; - } - else - { - if(data) - { - short int* si = (int16*) (fontPtr_Desc + data * 12); + } else { + if (data) { + short int *si = + (int16 *) (fontPtr_Desc + + data * 12); //int var_2 = si[5]; - renderWord(fontPtr_Data + si[0], currentStrRenderBuffer, drawPosPixel_X, si[4] - si[3] + lineHeight + heightOffset, si[3], si[2], renderBufferSize / 2, stringWidth * 2, si[5]); - - drawPosPixel_X += wordSpacingWidth + si[5]; + renderWord(fontPtr_Data + + si[0], + currentStrRenderBuffer, + drawPosPixel_X, + si[4] - si[3] + + lineHeight + heightOffset, + si[3], si[2], + renderBufferSize / 2, + stringWidth * 2, si[5]); + + drawPosPixel_X += + wordSpacingWidth + si[5]; } } - } - else - { + } else { stringFinished = 1; } - if(ptrStringEnd <= string) - { + if (ptrStringEnd <= string) { break; } - } while(!stringFinished); + } while (!stringFinished); // var_8 = 0; heightOffset = wordSpacingHeight + lineHeight; - } while(!stringFinished); + } while (!stringFinished); needFlip = 0; - if(buffer == gfxModuleData.pPage00) - { - if(gfxModuleData.field_1 != 0) - { + if (buffer == gfxModuleData.pPage00) { + if (gfxModuleData.field_1 != 0) { needFlip = 1; gfxModuleData_field_90(); } @@ -558,188 +503,171 @@ void drawString(int32 x, int32 y, uint8* string, uint8* buffer, uint8 color, int gfxModuleData_gfxWaitVSync(); } - gfxModuleData_field_64((char*)currentStrRenderBuffer, stringWidth, stringHeight, (char*)buffer, x, y, 0); - gfxModuleData_field_64((char*)currentStrRenderBuffer, stringWidth, stringHeight, (char*)buffer, x, y, color); + gfxModuleData_field_64((char *)currentStrRenderBuffer, stringWidth, + stringHeight, (char *)buffer, x, y, 0); + gfxModuleData_field_64((char *)currentStrRenderBuffer, stringWidth, + stringHeight, (char *)buffer, x, y, color); - if(needFlip) - { + if (needFlip) { gfxModuleData_flip(); } - if(useDynamicBuffer) - { + if (useDynamicBuffer) { free(currentStrRenderBuffer); } } - // calculates all necessary datas and renders text -gfxEntryStruct* renderText(int inRightBorder_X, uint8* string) -{ - uint8* fontPtr; - uint8* fontPtr_Data; // pt2 - uint8* fontPtr_Desc; // ptr3 - int32 wordSpacingWidth; // var1 //0 or -1 - int32 wordSpacingHeight; // var2 //0 or -1 +gfxEntryStruct *renderText(int inRightBorder_X, uint8 *string) { + uint8 *fontPtr; + uint8 *fontPtr_Data; // pt2 + uint8 *fontPtr_Desc; // ptr3 + int32 wordSpacingWidth; // var1 //0 or -1 + int32 wordSpacingHeight; // var2 //0 or -1 int32 rightBorder_X; - int32 lineHeight; // fontProc1result + int32 lineHeight; // fontProc1result int32 numLines; int32 stringHeight; int32 stringFinished; - int32 stringWidth; // var_1C + int32 stringWidth; // var_1C int32 stringRenderBufferSize; // int32 useDynamicBuffer; - uint8* currentStrRenderBuffer; - // int32 var_8; // don't need that one - int32 heightOffset; // var_12 // how much pixel-lines have already been drawn + uint8 *currentStrRenderBuffer; + // int32 var_8; // don't need that one + int32 heightOffset; // var_12 // how much pixel-lines have already been drawn // int32 var_1E; - gfxEntryStruct* generatedGfxEntry; + gfxEntryStruct *generatedGfxEntry; - // check if string is empty - if(!string) - { + // check if string is empty + if (!string) { return NULL; } - - // check if font has been loaded, else get system font - if(fontFileIndex != -1) - { + // check if font has been loaded, else get system font + if (fontFileIndex != -1) { fontPtr = filesDatabase[fontFileIndex].subData.ptr; - if(!fontPtr) - { + if (!fontPtr) { fontPtr = _systemFNT; } - } - else - { + } else { fontPtr = _systemFNT; } - if(!fontPtr) - { + if (!fontPtr) { return NULL; - } - fontPtr_Data = fontPtr + *(int16*) (fontPtr + 4); // offset to char data - fontPtr_Desc = fontPtr + 14; // offset to char description + } + fontPtr_Data = fontPtr + *(int16 *) (fontPtr + 4); // offset to char data + fontPtr_Desc = fontPtr + 14; // offset to char description - lineHeight = getLineHeight(*(int16*) (fontPtr + 8), fontPtr, fontPtr_Desc); // ok + lineHeight = getLineHeight(*(int16 *) (fontPtr + 8), fontPtr, fontPtr_Desc); // ok - wordSpacingWidth = *(int16*) (fontPtr + 10); - wordSpacingHeight = *(int16*) (fontPtr + 12); + wordSpacingWidth = *(int16 *) (fontPtr + 10); + wordSpacingHeight = *(int16 *) (fontPtr + 12); // if right border is higher then screenwidth (+ spacing), adjust border - if(inRightBorder_X > 310) - { + if (inRightBorder_X > 310) { rightBorder_X = 310; - } - else - { + } else { rightBorder_X = inRightBorder_X; - } - numLines = getTextLineCount(rightBorder_X, wordSpacingWidth, fontPtr_Desc, string); // ok + } + numLines = getTextLineCount(rightBorder_X, wordSpacingWidth, fontPtr_Desc, string); // ok - if(!numLines) - { + if (!numLines) { return NULL; - } - - stringHeight = ((wordSpacingHeight + lineHeight + 2) * numLines) + 1; - stringFinished = 0; - stringWidth = rightBorder_X + 2; // max render width to the right + } + + stringHeight = ((wordSpacingHeight + lineHeight + 2) * numLines) + 1; + stringFinished = 0; + stringWidth = rightBorder_X + 2; // max render width to the right stringRenderBufferSize = stringWidth * stringHeight * 4; - inRightBorder_X = rightBorder_X; + inRightBorder_X = rightBorder_X; - currentStrRenderBuffer = (uint8*) mallocAndZero(stringRenderBufferSize); + currentStrRenderBuffer = + (uint8 *) mallocAndZero(stringRenderBufferSize); resetRaster(currentStrRenderBuffer, stringRenderBufferSize); - generatedGfxEntry = (gfxEntryStruct*) malloc(sizeof(gfxEntryStruct)); - generatedGfxEntry->imagePtr = currentStrRenderBuffer; + generatedGfxEntry = (gfxEntryStruct *) malloc(sizeof(gfxEntryStruct)); + generatedGfxEntry->imagePtr = currentStrRenderBuffer; generatedGfxEntry->imageSize = stringRenderBufferSize / 2; generatedGfxEntry->fontIndex = fontFileIndex; - generatedGfxEntry->height = stringHeight; - generatedGfxEntry->width = stringWidth; // maximum render width to the right + generatedGfxEntry->height = stringHeight; + generatedGfxEntry->width = stringWidth; // maximum render width to the right // var_8 = 0; heightOffset = 0; - do - { - int spacesCount = 0; // si - char character = *string; - short int strPixelLength; // var_16 - uint8* ptrStringEnd; // var_4 //ok - int drawPosPixel_X; // di - - // find first letter in string, skip all spaces - while(character == ' ') - { + do { + int spacesCount = 0; // si + char character = *string; + short int strPixelLength; // var_16 + uint8 *ptrStringEnd; // var_4 //ok + int drawPosPixel_X; // di + + // find first letter in string, skip all spaces + while (character == ' ') { spacesCount++; character = *(string + spacesCount); } string += spacesCount; - - // returns character count and pixel length (via pointer) per line of the text string - ptrStringEnd = string + prepareWordRender(inRightBorder_X, wordSpacingWidth, &strPixelLength, fontPtr_Desc, string); //ok - // determine how much space is left to the right and left (center text) - if(inRightBorder_X > strPixelLength) - { + // returns character count and pixel length (via pointer) per line of the text string + ptrStringEnd = string + prepareWordRender(inRightBorder_X, wordSpacingWidth, &strPixelLength, fontPtr_Desc, string); //ok + + // determine how much space is left to the right and left (center text) + if (inRightBorder_X > strPixelLength) { //var_8 = (inRightBorder_X - strPixelLength) / 2; - drawPosPixel_X = (inRightBorder_X - strPixelLength) / 2; - } - else - { + drawPosPixel_X = + (inRightBorder_X - strPixelLength) / 2; + } else { drawPosPixel_X = 0; } //drawPosPixel_X = var_8; // draw textline, character wise - do - { + do { character = *(string++); - short int charData = fontCharacterTable[(int)character]; // get character position + short int charData = fontCharacterTable[(int)character]; // get character position - if(character) - { - if(character == ' ' || character == 0x7C) - { - drawPosPixel_X += wordSpacingWidth + 5; // if char = "space" adjust word starting postion (don't render space though); - } - else - { - if(charData >= 0) - { - short int* si = (int16*) (fontPtr_Desc + charData * 12); // offset font data + if (character) { + if (character == ' ' || character == 0x7C) { + drawPosPixel_X += wordSpacingWidth + 5; // if char = "space" adjust word starting postion (don't render space though); + } else { + if (charData >= 0) { + short int *si = (int16 *) (fontPtr_Desc + charData * 12); // offset font data // int var_2 = si[5]; // don't need this - - // should ist be stringRenderBufferSize/2 for the second last param? - renderWord(fontPtr_Data + si[0], currentStrRenderBuffer, drawPosPixel_X, si[4] - si[3] + lineHeight + heightOffset, si[3], si[2], stringRenderBufferSize, stringWidth / 2, si[5]); - drawPosPixel_X += wordSpacingWidth + si[5]; + // should ist be stringRenderBufferSize/2 for the second last param? + renderWord(fontPtr_Data + + si[0], + currentStrRenderBuffer, + drawPosPixel_X, + si[4] - si[3] + + lineHeight + heightOffset, + si[3], si[2], + stringRenderBufferSize, + stringWidth / 2, si[5]); + + drawPosPixel_X += + wordSpacingWidth + si[5]; } } + } else { + stringFinished = 1; // character = 0x00 } - else - { - stringFinished = 1; // character = 0x00 - } - - // check if string already reached the end - if(ptrStringEnd <= string) - { + + // check if string already reached the end + if (ptrStringEnd <= string) { break; - } - } while(!stringFinished); + } + } while (!stringFinished); // var_8 = 0; heightOffset += wordSpacingHeight + lineHeight; - }while(!stringFinished); + } while (!stringFinished); return generatedGfxEntry; } - } // End of namespace Cruise diff --git a/engines/cruise/font.h b/engines/cruise/font.h index 6946be9639..b4533f2e43 100644 --- a/engines/cruise/font.h +++ b/engines/cruise/font.h @@ -22,27 +22,30 @@ * */ -#ifndef _FONT_H_ -#define _FONT_H_ +#ifndef CRUISE_FONT_H +#define CRUISE_FONT_H namespace Cruise { -void loadFNT(const void* fileName); +void loadFNT(const void *fileName); void loadSystemFont(void); ////////////////////////////////////////////////// -void flipShort(int16* var); -void flipShort(uint16* var); -void flipLong(int32* var); // TODO: move away -void flipLong(uint32* var); // TODO: move away -void flipGen(void* var, int32 length); - -int32 getLineHeight(int16 charCount, uint8* fontPtr, uint8* fontPrt_Desc); // fontProc1 -int32 getTextLineCount(int32 rightBorder_X, int32 wordSpacingWidth, uint8* ptr, uint8* textString); // fontProc2 - -void renderWord(uint8* fontPtr_Data, uint8* outBufferPtr, int32 drawPosPixel_X, int32 heightOff, int32 height, int32 param4, int32 stringRenderBufferSize, int32 width , int32 charWidth); -gfxEntryStruct* renderText(int inRightBorder_X, uint8* string); -void drawString(int32 x, int32 y, uint8* string, uint8* buffer, uint8 color, int32 inRightBorder_X); +void flipShort(int16 * var); +void flipShort(uint16 * var); +void flipLong(int32 * var); // TODO: move away +void flipLong(uint32 * var); // TODO: move away +void flipGen(void *var, int32 length); + +int32 getLineHeight(int16 charCount, uint8 * fontPtr, uint8 * fontPrt_Desc); // fontProc1 +int32 getTextLineCount(int32 rightBorder_X, int32 wordSpacingWidth, uint8 * ptr, uint8 * textString); // fontProc2 + +void renderWord(uint8 * fontPtr_Data, uint8 * outBufferPtr, + int32 drawPosPixel_X, int32 heightOff, int32 height, int32 param4, + int32 stringRenderBufferSize, int32 width, int32 charWidth); +gfxEntryStruct *renderText(int inRightBorder_X, uint8 * string); +void drawString(int32 x, int32 y, uint8 * string, uint8 * buffer, uint8 color, + int32 inRightBorder_X); } // End of namespace Cruise diff --git a/engines/cruise/fontCharacterTable.cpp b/engines/cruise/fontCharacterTable.cpp index 06bea3f601..20badd7953 100644 --- a/engines/cruise/fontCharacterTable.cpp +++ b/engines/cruise/fontCharacterTable.cpp @@ -26,170 +26,169 @@ namespace Cruise { -int16 fontCharacterTable[256]={ --1, --1, --1, --1, --1, --1, --1, --1, --1, --1, --1, --1, --1, --1, --1, --1, --1, --1, --1, --1, --1, --1, --1, --1, --1, --1, --1, --1, --1, --1, --1, --1, --1, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, - 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, - 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, - 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, - 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, - 86, 87, 88, 89, 90, 91, 92, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - 106, 105, - -1, - -1, - -1, - -1, - 107, 108, - -1,-1, - 109, 110, - -1, - -1, - -1, - -1, - -1,-1, - 111, -1, - 112, - -1,-1, - 113, - 114, - -1, - -1, - 116, 93, - -1, - 118, - -1, - 94, - -1, - 117, - 115, - 96, - 95, - 97, - 98, - -1, - -1, - 99, - 100, - -1, - -1, - -1, - -1, - 101, - -1, - 102, - -1, - -1, - 103, - -1, - 104, - -1, - -1, - -1, - -1, +int16 fontCharacterTable[256] = { + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, + 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, + 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, + 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, + 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, + 86, 87, 88, 89, 90, 91, 92, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + 106, 105, + -1, + -1, + -1, + -1, + 107, 108, + -1, -1, + 109, 110, + -1, + -1, + -1, + -1, + -1, -1, + 111, -1, + 112, + -1, -1, + 113, + 114, + -1, + -1, + 116, 93, + -1, + 118, + -1, + 94, + -1, + 117, + 115, + 96, + 95, + 97, + 98, + -1, + -1, + 99, + 100, + -1, + -1, + -1, + -1, + 101, + -1, + 102, + -1, + -1, + 103, + -1, + 104, + -1, + -1, + -1, + -1, }; - } // End of namespace Cruise diff --git a/engines/cruise/fontCharacterTable.h b/engines/cruise/fontCharacterTable.h index 79f1647707..b45a47e89d 100644 --- a/engines/cruise/fontCharacterTable.h +++ b/engines/cruise/fontCharacterTable.h @@ -22,14 +22,12 @@ * */ -#ifndef _FONTCHARACTERTABLE_H_ -#define _FONTCHARACTERTABLE_H_ +#ifndef CRUISE_FONTCHARACTERTABLE_H +#define CRUISE_FONTCHARACTERTABLE_H namespace Cruise { extern short int fontCharacterTable[256]; -} // End of namespace Cruise - +} // End of namespace Cruise #endif - diff --git a/engines/cruise/function.cpp b/engines/cruise/function.cpp index 5603cdd68e..e8e86d82b6 100644 --- a/engines/cruise/function.cpp +++ b/engines/cruise/function.cpp @@ -29,724 +29,649 @@ namespace Cruise { opcodeFunction opcodeTablePtr[256]; -struct actorTableStruct -{ - int data[13]; +struct actorTableStruct { + int data[13]; }; typedef struct actorTableStruct actorTableStruct; -actorTableStruct actorTable1[] = { - { - 37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }, - { - 38, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }, - { - 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }, - { - -38, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - } +actorTableStruct actorTable1[] = { + { 37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + { 38, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + { 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {-38, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }; -int16 Op_LoadOverlay(void) -{ - uint8* originalScriptName; - uint8 scriptName[38]; - int returnValue; +int16 Op_LoadOverlay(void) { + uint8 *originalScriptName; + uint8 scriptName[38]; + int returnValue; - scriptName[0] = 0; + scriptName[0] = 0; - originalScriptName = (uint8*)popPtr(); + originalScriptName = (uint8 *) popPtr(); - if(originalScriptName) - { - strcpyuint8(scriptName,originalScriptName); - } + if (originalScriptName) { + strcpyuint8(scriptName, originalScriptName); + } - if(!scriptName[0] || !originalScriptName) - { - return(0); - } + if (!scriptName[0] || !originalScriptName) { + return (0); + } - strToUpper(scriptName); + strToUpper(scriptName); - //gfxModuleData.field_84(); - //gfxModuleData.field_84(); + //gfxModuleData.field_84(); + //gfxModuleData.field_84(); - returnValue = loadOverlay(scriptName); + returnValue = loadOverlay(scriptName); - updateAllScriptsImports(); + updateAllScriptsImports(); - strcpyuint8(scriptNameBuffer,scriptName); + strcpyuint8(scriptNameBuffer, scriptName); - return(returnValue); + return (returnValue); } -int16 Op_strcpy(void) -{ - char* ptr1 = (char*)popPtr(); - char* ptr2 = (char*)popPtr(); +int16 Op_strcpy(void) { + char *ptr1 = (char *)popPtr(); + char *ptr2 = (char *)popPtr(); - //printf("strcpy %s\n",ptr1); + //printf("strcpy %s\n",ptr1); - while(*ptr1) - { - *ptr2 = *ptr1; + while (*ptr1) { + *ptr2 = *ptr1; - ptr2++; - ptr1++; - } + ptr2++; + ptr1++; + } - *ptr2 = 0; + *ptr2 = 0; - return(0); + return (0); } -int16 Op_startScript(void) -{ - int scriptIdx; - int ovlIdx; - uint8* ptr; - uint8* ptr2; +int16 Op_startScript(void) { + int scriptIdx; + int ovlIdx; + uint8 *ptr; + uint8 *ptr2; - short int popTable[256]; // TODO: check original size; + short int popTable[256]; // TODO: check original size; - int numOfArgToPop = popVar(); + int numOfArgToPop = popVar(); - int i=0; + int i = 0; - for(i=0;i<numOfArgToPop;i++) - { - popTable[numOfArgToPop-i-1] = popVar(); - } + for (i = 0; i < numOfArgToPop; i++) { + popTable[numOfArgToPop - i - 1] = popVar(); + } - scriptIdx = popVar(); - ovlIdx = popVar(); + scriptIdx = popVar(); + ovlIdx = popVar(); - if(!ovlIdx) - { - ovlIdx = currentScriptPtr->overlayNumber; - } + if (!ovlIdx) { + ovlIdx = currentScriptPtr->overlayNumber; + } - ptr = attacheNewScriptToTail(ovlIdx,&scriptHandle2,scriptIdx,currentScriptPtr->type,currentScriptPtr->scriptNumber,currentScriptPtr->overlayNumber,scriptType_Minus20); + ptr = + attacheNewScriptToTail(ovlIdx, &scriptHandle2, scriptIdx, + currentScriptPtr->type, currentScriptPtr->scriptNumber, + currentScriptPtr->overlayNumber, scriptType_Minus20); - if(!ptr) - return(0); + if (!ptr) + return (0); - if(numOfArgToPop<=0) - { - return(0); - } + if (numOfArgToPop <= 0) { + return (0); + } - ptr2 = ptr; + ptr2 = ptr; - for(i=0;i<numOfArgToPop;i++) - { - saveShort(ptr2,popTable[i]); - ptr2+=2; - } + for (i = 0; i < numOfArgToPop; i++) { + saveShort(ptr2, popTable[i]); + ptr2 += 2; + } - return(0); + return (0); } -int16 Op_AddProc(void) -{ - int pop1 = popVar(); - int pop2; - int overlay; +int16 Op_AddProc(void) { + int pop1 = popVar(); + int pop2; + int overlay; - if(pop1-1>0) - { - printf("Unsuported arg pop in Op_6!\n"); - exit(1); - } + if (pop1 - 1 > 0) { + printf("Unsuported arg pop in Op_6!\n"); + exit(1); + } - pop2 = popVar(); - overlay = popVar(); + pop2 = popVar(); + overlay = popVar(); - if(!overlay) - overlay = currentScriptPtr->overlayNumber; + if (!overlay) + overlay = currentScriptPtr->overlayNumber; - if(!overlay) - return(0); + if (!overlay) + return (0); - attacheNewScriptToTail(overlay,&scriptHandle2,pop2,currentScriptPtr->type,currentScriptPtr->scriptNumber,currentScriptPtr->overlayNumber,scriptType_20); + attacheNewScriptToTail(overlay, &scriptHandle2, pop2, + currentScriptPtr->type, currentScriptPtr->scriptNumber, + currentScriptPtr->overlayNumber, scriptType_20); - if(pop1>0) - { - printf("Unsupported art send in op6!\n"); - exit(1); - } + if (pop1 > 0) { + printf("Unsupported art send in op6!\n"); + exit(1); + } - return(0); + return (0); } -int16 Op_37(void) -{ - int pop1 = popVar(); - int pop2 = popVar(); +int16 Op_37(void) { + int pop1 = popVar(); + int pop2 = popVar(); - if(!pop2) - pop2 = currentScriptPtr->overlayNumber; + if (!pop2) + pop2 = currentScriptPtr->overlayNumber; - var30 = pop2; - var31 = pop1; + var30 = pop2; + var31 = pop1; - return(0); + return (0); } -int16 Op_GetMouseX(void) // TODO: implement properly -{ - int16 dummy; - int16 mouseX; - int16 mouseY; - int16 mouseButton; +int16 Op_GetMouseX(void) { // TODO: implement properly + int16 dummy; + int16 mouseX; + int16 mouseY; + int16 mouseButton; - getMouseStatus(&dummy, &mouseX, &mouseButton, &mouseY); + getMouseStatus(&dummy, &mouseX, &mouseButton, &mouseY); - return(mouseX); + return (mouseX); } -int16 Op_GetMouseY(void) // TODO: implement properly -{ - int16 dummy; - int16 mouseX; - int16 mouseY; - int16 mouseButton; +int16 Op_GetMouseY(void) { // TODO: implement properly + int16 dummy; + int16 mouseX; + int16 mouseY; + int16 mouseButton; - getMouseStatus(&dummy, &mouseX, &mouseButton, &mouseY); + getMouseStatus(&dummy, &mouseX, &mouseButton, &mouseY); - return(mouseY); + return (mouseY); } -int16 Op_rand(void) // TODO: implement -{ - int var = popVar(); - - if(var<2) - { - return(0); - } +int16 Op_rand(void) { // TODO: implement + int var = popVar(); -// return(8); - return(rand()%var); + if (var < 2) { + return (0); + } +// return(8); + return (rand() % var); } -int16 Op_PlayFX(void) // TODO: implement -{ - popVar(); - popVar(); - popVar(); - popVar(); +int16 Op_PlayFX(void) { // TODO: implement + popVar(); + popVar(); + popVar(); + popVar(); - // printf("Op_PlayFX, implement (sound related)\n"); + // printf("Op_PlayFX, implement (sound related)\n"); - return(0); + return (0); } -int16 Op_freeAllPerso(void) -{ - freeAllPerso(); - return(0); +int16 Op_freeAllPerso(void) { + freeAllPerso(); + return (0); } -void freeObjectList(cellStruct* pListHead) -{ - int var_2 = 0; - cellStruct* pCurrent = pListHead->next; +void freeObjectList(cellStruct *pListHead) { + int var_2 = 0; + cellStruct *pCurrent = pListHead->next; - while(pCurrent) - { - cellStruct* pNext = pCurrent->next; + while (pCurrent) { + cellStruct *pNext = pCurrent->next; - if(pCurrent->freeze == 0) - { - free(pCurrent->gfxPtr); - free(pCurrent); - } + if (pCurrent->freeze == 0) { + free(pCurrent->gfxPtr); + free(pCurrent); + } - var_2 = 1; + var_2 = 1; - pCurrent = pNext; - } + pCurrent = pNext; + } - if(var_2) - { - resetPtr(pListHead); - } + if (var_2) { + resetPtr(pListHead); + } } -int16 Op_FreeCell(void) -{ - freeObjectList(&cellHead); - return(0); +int16 Op_FreeCell(void) { + freeObjectList(&cellHead); + return (0); } -int16 Op_freeBackgroundInscrustList(void) -{ - freeBackgroundIncrustList(&backgroundIncrustHead); - return(0); +int16 Op_freeBackgroundInscrustList(void) { + freeBackgroundIncrustList(&backgroundIncrustHead); + return (0); } -int16 Op_removeBackground(void) -{ - int backgroundIdx; +int16 Op_removeBackground(void) { + int backgroundIdx; - backgroundIdx = popVar(); + backgroundIdx = popVar(); - printf("Op_removeBackground: remove background %d\n",backgroundIdx); - return(0); + printf("Op_removeBackground: remove background %d\n", backgroundIdx); + return (0); } -int16 Op_freeMediumVar(void) -{ - // TODO: implement - printf("Op_freeMediumVar, implement\n"); - return(0); +int16 Op_freeMediumVar(void) { + // TODO: implement + printf("Op_freeMediumVar, implement\n"); + return (0); } -int16 Op_RemoveMessage(void) -{ - int idx; - int overlay; +int16 Op_RemoveMessage(void) { + int idx; + int overlay; + + idx = popVar(); + overlay = popVar(); - idx = popVar(); - overlay = popVar(); + if (!overlay) { + overlay = currentScriptPtr->overlayNumber; + } - if(!overlay) - { - overlay = currentScriptPtr->overlayNumber; - } + removeObjectFromList(overlay, idx, &cellHead, + currentActiveBackgroundPlane, 5); - removeObjectFromList(overlay, idx, &cellHead, currentActiveBackgroundPlane, 5); - - return(0); + return (0); } -int16 Op_isFileLoaded(void) -{ - int16 i; - uint8 name[36] = ""; - uint8* ptr; +int16 Op_isFileLoaded(void) { + int16 i; + uint8 name[36] = ""; + uint8 *ptr; - ptr = (uint8*)popPtr(); + ptr = (uint8 *) popPtr(); - if(!ptr) - { - return -1; - } + if (!ptr) { + return -1; + } - strcpyuint8(name,ptr); - strToUpper(name); + strcpyuint8(name, ptr); + strToUpper(name); - for(i=0;i<257;i++) - { - if(!strcmpuint8(name,filesDatabase[i].subData.name)) - { - return(i); - } - } + for (i = 0; i < 257; i++) { + if (!strcmpuint8(name, filesDatabase[i].subData.name)) { + return (i); + } + } - return -1; + return -1; } -int16 Op_RemoveFrame(void) -{ - //int var1; - //int var2; +int16 Op_RemoveFrame(void) { + //int var1; + //int var2; - var1 = popVar(); - var2 = popVar(); + var1 = popVar(); + var2 = popVar(); - resetFileEntryRange(var2,var1); + resetFileEntryRange(var2, var1); - return(0); + return (0); } -int16 Op_comment(void) -{ - char* var; +int16 Op_comment(void) { + char *var; - var = (char*)popPtr(); + var = (char *)popPtr(); - printf("COMMENT: \"%s\"\n",var); + printf("COMMENT: \"%s\"\n", var); - return(0); + return (0); } -int16 Op_RemoveProc(void) -{ - int idx; - int overlay; +int16 Op_RemoveProc(void) { + int idx; + int overlay; - idx = popVar(); - overlay = popVar(); + idx = popVar(); + overlay = popVar(); - if(!overlay) - { - overlay = currentScriptPtr->overlayNumber; - } + if (!overlay) { + overlay = currentScriptPtr->overlayNumber; + } - removeScript(overlay,idx,&scriptHandle2); + removeScript(overlay, idx, &scriptHandle2); - return(0); + return (0); } -int16 Op_FreeOverlay(void) -{ - uint8 localName[36] = ""; - uint8* namePtr; +int16 Op_FreeOverlay(void) { + uint8 localName[36] = ""; + uint8 *namePtr; - namePtr = (uint8*)popPtr(); + namePtr = (uint8 *) popPtr(); - strcpyuint8(localName,namePtr); + strcpyuint8(localName, namePtr); - if(localName[0]) - { - strToUpper(localName); - releaseOverlay((char*)localName); - } + if (localName[0]) { + strToUpper(localName); + releaseOverlay((char *)localName); + } - return 0; + return 0; } -int16 Op_2B(void) -{ - uint8 name[36] = ""; - uint8* ptr; - int param; +int16 Op_2B(void) { + uint8 name[36] = ""; + uint8 *ptr; + int param; - ptr = (uint8*)popPtr(); + ptr = (uint8 *) popPtr(); - strcpyuint8(name,ptr); + strcpyuint8(name, ptr); - param = getProcParam(popVar(),20,name); + param = getProcParam(popVar(), 20, name); - return param; + return param; } -int16 Op_freeAllMenu(void) -{ - // TODO: implement - printf("Op_freeAllMenu, implement\n"); +int16 Op_freeAllMenu(void) { + // TODO: implement + printf("Op_freeAllMenu, implement\n"); - return 0; + return 0; } -int16 Op_PlayFXnterPlayerMenu(void) -{ - int oldValue = entrerMenuJoueur; - entrerMenuJoueur = popVar(); +int16 Op_PlayFXnterPlayerMenu(void) { + int oldValue = entrerMenuJoueur; + entrerMenuJoueur = popVar(); - return oldValue; + return oldValue; } -int16 Op_ChangeSaveAllowedState(void) -{ - int oldValue = userEnabled; - int newValue = popVar(); +int16 Op_ChangeSaveAllowedState(void) { + int oldValue = userEnabled; + int newValue = popVar(); - if(newValue != -1) - { - userEnabled = newValue; - } + if (newValue != -1) { + userEnabled = newValue; + } - return oldValue; + return oldValue; } -int16 Op_changeCutSceneState(void) -{ - int oldValue = affichePasMenuJoueur; - int newValue = popVar(); +int16 Op_changeCutSceneState(void) { + int oldValue = affichePasMenuJoueur; + int newValue = popVar(); - if(newValue != -1) - { - affichePasMenuJoueur = newValue; - } + if (newValue != -1) { + affichePasMenuJoueur = newValue; + } - return oldValue; + return oldValue; } -int16 Op_62(void) -{ - if(currentScriptPtr->var1A == 20) - { - changeScriptParamInList(currentScriptPtr->var18,currentScriptPtr->var16,&scriptHandle2,9997,-1); - } - else - if(currentScriptPtr->var1A == 30) - { - changeScriptParamInList(currentScriptPtr->var18,currentScriptPtr->var16,&scriptHandle1,9997,-1); - } +int16 Op_62(void) { + if (currentScriptPtr->var1A == 20) { + changeScriptParamInList(currentScriptPtr->var18, + currentScriptPtr->var16, &scriptHandle2, 9997, -1); + } else if (currentScriptPtr->var1A == 30) { + changeScriptParamInList(currentScriptPtr->var18, + currentScriptPtr->var16, &scriptHandle1, 9997, -1); + } - return 0; + return 0; } -int16 Op_LoadBackground(void) -{ - int result = 0; - uint8 bgName[36] = ""; - uint8* ptr; - int bgIdx; +int16 Op_LoadBackground(void) { + int result = 0; + uint8 bgName[36] = ""; + uint8 *ptr; + int bgIdx; - ptr = (uint8*)popPtr(); + ptr = (uint8 *) popPtr(); - strcpyuint8(bgName,ptr); + strcpyuint8(bgName, ptr); - bgIdx = popVar(); + bgIdx = popVar(); - if(bgIdx >= 0 || bgIdx < 8) - { - strToUpper(bgName); + if (bgIdx >= 0 || bgIdx < 8) { + strToUpper(bgName); - gfxModuleData_gfxWaitVSync(); - gfxModuleData_gfxWaitVSync(); + gfxModuleData_gfxWaitVSync(); + gfxModuleData_gfxWaitVSync(); - result = loadBackground((char*)bgName,bgIdx); - } + result = loadBackground((char *)bgName, bgIdx); + } - changeCursor(0); + changeCursor(0); - return result; + return result; } -int16 Op_isFileLoaded2(void) -{ - int param; +int16 Op_isFileLoaded2(void) { + int param; - param = popVar(); + param = popVar(); - if(param<0 || param>255) - { - return 0; - } + if (param < 0 || param > 255) { + return 0; + } - if(filesDatabase[param].subData.ptr) - { - return 1; - } + if (filesDatabase[param].subData.ptr) { + return 1; + } - return 0; + return 0; } -int16 Op_loadFile(void) -{ - int param1; - int param2; - int param3; - uint8 name[36] = ""; - uint8* ptr; +int16 Op_loadFile(void) { + int param1; + int param2; + int param3; + uint8 name[36] = ""; + uint8 *ptr; + + ptr = (uint8 *) popPtr(); - ptr = (uint8*)popPtr(); + strcpyuint8(name, ptr); - strcpyuint8(name,ptr); + param1 = popVar(); + param2 = popVar(); + param3 = popVar(); - param1 = popVar(); - param2 = popVar(); - param3 = popVar(); - - if(param3 >= 0 || param3 < 257) - { - strToUpper(name); + if (param3 >= 0 || param3 < 257) { + strToUpper(name); - gfxModuleData_gfxWaitVSync(); - gfxModuleData_gfxWaitVSync(); + gfxModuleData_gfxWaitVSync(); + gfxModuleData_gfxWaitVSync(); - saveVar6[0] = 0; + saveVar6[0] = 0; - loadFileMode2(name,param3,param2,param1); + loadFileMode2(name, param3, param2, param1); - saveVar6[0] = 0; - } + saveVar6[0] = 0; + } - changeCursor(0); - return 0; + changeCursor(0); + return 0; } -int16 Op_LoadAbs(void) -{ - int param1; +int16 Op_LoadAbs(void) { + int param1; // int param2; // int param3; - uint8 name[36] = ""; - uint8* ptr; - int result = 0; + uint8 name[36] = ""; + uint8 *ptr; + int result = 0; - ptr = (uint8*)popPtr(); + ptr = (uint8 *) popPtr(); - strcpyuint8(name,ptr); + strcpyuint8(name, ptr); - param1 = popVar(); - - if(param1 >= 0 || param1 < 257) - { - strToUpper(name); + param1 = popVar(); - gfxModuleData_gfxWaitVSync(); - gfxModuleData_gfxWaitVSync(); + if (param1 >= 0 || param1 < 257) { + strToUpper(name); - result = loadFullBundle(name,param1); - } + gfxModuleData_gfxWaitVSync(); + gfxModuleData_gfxWaitVSync(); - changeCursor(0); - return result; + result = loadFullBundle(name, param1); + } + + changeCursor(0); + return result; } -int16 Op_InitializeState(void) -{ - int param1 = popVar(); - int objIdx = popVar(); - int ovlIdx = popVar(); +int16 Op_InitializeState(void) { + int param1 = popVar(); + int objIdx = popVar(); + int ovlIdx = popVar(); - if(!ovlIdx) - ovlIdx = currentScriptPtr->overlayNumber; + if (!ovlIdx) + ovlIdx = currentScriptPtr->overlayNumber; - Op_InitializeStateSub(ovlIdx,objIdx,param1); + Op_InitializeStateSub(ovlIdx, objIdx, param1); - return(0); + return (0); } -int16 Op_GetInitVar1(void) -{ - return initVar1; +int16 Op_GetInitVar1(void) { + return initVar1; } -int16 Op_FadeOut(void) -{ - printf("Op_FadeOut dummy\n"); - return 0; +int16 Op_FadeOut(void) { + printf("Op_FadeOut dummy\n"); + return 0; } -int16 isOverlayLoaded(uint8* name) -{ - int16 i; +int16 isOverlayLoaded(uint8 * name) { + int16 i; + + for (i = 1; i < numOfLoadedOverlay; i++) { + if (!strcmpuint8(overlayTable[i].overlayName, name) + && overlayTable[i].alreadyLoaded) { + return i; + } + } - for(i=1;i<numOfLoadedOverlay;i++) - { - if(!strcmpuint8(overlayTable[i].overlayName,name) && overlayTable[i].alreadyLoaded) - { - return i; - } - } - - return 0; + return 0; } -int16 Op_FindOverlay(void) -{ - uint8 name[36] = ""; - uint8* ptr; +int16 Op_FindOverlay(void) { + uint8 name[36] = ""; + uint8 *ptr; - ptr = (uint8*)popPtr(); + ptr = (uint8 *) popPtr(); - strcpyuint8(name,ptr); - strToUpper(name); + strcpyuint8(name, ptr); + strToUpper(name); - return(isOverlayLoaded(name)); + return (isOverlayLoaded(name)); } -int16 Op_2C(void) -{ - int16 returnParam; +int16 Op_2C(void) { + int16 returnParam; - int16 param1 = popVar(); - int16 param2 = popVar(); - int16 param3 = popVar(); - int16 param4 = popVar(); + int16 param1 = popVar(); + int16 param2 = popVar(); + int16 param3 = popVar(); + int16 param4 = popVar(); - getSingleObjectParam(param4,param3,param2,&returnParam); - setObjectPosition(param4,param3,param2,param1); - - return returnParam; + getSingleObjectParam(param4, param3, param2, &returnParam); + setObjectPosition(param4, param3, param2, param1); + + return returnParam; } -int16 Op_FadeIn(void) -{ - main5 = 1; - return 0; +int16 Op_FadeIn(void) { + main5 = 1; + return 0; } -int16 Op_GetMouseClick3(void) -{ - int16 dummy; - int16 mouseX; - int16 mouseY; - int16 mouseButton; +int16 Op_GetMouseClick3(void) { + int16 dummy; + int16 mouseX; + int16 mouseY; + int16 mouseButton; - getMouseStatus(&dummy, &mouseX, &mouseButton, &mouseY); + getMouseStatus(&dummy, &mouseX, &mouseButton, &mouseY); - if(mouseButton&4) - return 1; - return 0; + if (mouseButton & 4) + return 1; + return 0; } -int16 Op_AddCell(void) -{ - int16 param1 = popVar(); - int16 param2 = popVar(); - int16 overlayIdx = popVar(); +int16 Op_AddCell(void) { + int16 param1 = popVar(); + int16 param2 = popVar(); + int16 overlayIdx = popVar(); - if(!overlayIdx) - overlayIdx = currentScriptPtr->overlayNumber; + if (!overlayIdx) + overlayIdx = currentScriptPtr->overlayNumber; - addCell(overlayIdx,param2,&cellHead,currentScriptPtr->type,currentScriptPtr->scriptNumber,currentScriptPtr->overlayNumber,currentActiveBackgroundPlane,param1); + addCell(overlayIdx, param2, &cellHead, currentScriptPtr->type, + currentScriptPtr->scriptNumber, currentScriptPtr->overlayNumber, + currentActiveBackgroundPlane, param1); - return 0; + return 0; } -int16 Op_2F(void) -{ - int16 param1 = popVar(); - int16 param2 = popVar(); +int16 Op_2F(void) { + int16 param1 = popVar(); + int16 param2 = popVar(); - int16 overlayIdx = popVar(); + int16 overlayIdx = popVar(); - if(!overlayIdx) - overlayIdx = currentScriptPtr->overlayNumber; + if (!overlayIdx) + overlayIdx = currentScriptPtr->overlayNumber; - addBackgroundIncrust(overlayIdx,param2,&backgroundIncrustHead,currentScriptPtr->scriptNumber,currentScriptPtr->overlayNumber,currentActiveBackgroundPlane,param1); + addBackgroundIncrust(overlayIdx, param2, &backgroundIncrustHead, + currentScriptPtr->scriptNumber, currentScriptPtr->overlayNumber, + currentActiveBackgroundPlane, param1); - return 0; + return 0; } -int16 Op_RemoveCell(void) -{ - var1 = popVar(); - int objectIdx = popVar(); - int ovlNumber = popVar(); +int16 Op_RemoveCell(void) { + var1 = popVar(); + int objectIdx = popVar(); + int ovlNumber = popVar(); - if(!ovlNumber) - { - ovlNumber = currentScriptPtr->overlayNumber; - } + if (!ovlNumber) { + ovlNumber = currentScriptPtr->overlayNumber; + } - removeObjectFromList(ovlNumber, objectIdx, &cellHead, currentActiveBackgroundPlane, var1); + removeObjectFromList(ovlNumber, objectIdx, &cellHead, + currentActiveBackgroundPlane, var1); - return 0; + return 0; } int16 fontFileIndex; -int16 Op_SetFontFileIndex(void) -{ +int16 Op_SetFontFileIndex(void) { fontFileIndex = popVar(); return 0; } -int16 Op_63(void) -{ - if(currentScriptPtr->var1A == 0x14) - { - changeScriptParamInList(currentScriptPtr->var18,currentScriptPtr->var16,&scriptHandle2,0,-1); - } - else - if(currentScriptPtr->var1A == 0x1E) - { - changeScriptParamInList(currentScriptPtr->var18,currentScriptPtr->var16,&scriptHandle1,0,-1); +int16 Op_63(void) { + if (currentScriptPtr->var1A == 0x14) { + changeScriptParamInList(currentScriptPtr->var18, + currentScriptPtr->var16, &scriptHandle2, 0, -1); + } else if (currentScriptPtr->var1A == 0x1E) { + changeScriptParamInList(currentScriptPtr->var18, + currentScriptPtr->var16, &scriptHandle1, 0, -1); } return 0; @@ -754,428 +679,382 @@ int16 Op_63(void) int16 op7CVar = 0; -int16 Op_InitializeStateC(void) -{ +int16 Op_InitializeStateC(void) { int16 temp = op7CVar; int16 newVar; newVar = popVar(); - if(newVar != -1) - { + if (newVar != -1) { op7CVar = newVar; } return temp; } -int16 Op_AddMessage(void) -{ - int16 color = popVar(); - int16 var_2 = popVar(); - int16 var_4 = popVar(); - int16 var_6 = popVar(); - int16 var_8 = popVar(); - int16 overlayIdx = popVar(); - - if(!overlayIdx) - overlayIdx = currentScriptPtr->overlayNumber; - - if( color == -1 ) - { - color = 0; - //ASSERT(0); - //color = calcTabSomething(); - } - else - { - if(CVTLoaded) - { - color = cvtPalette[color]; - } - } - - createTextObject(overlayIdx, var_8, &cellHead, currentScriptPtr->scriptNumber, currentScriptPtr->overlayNumber, currentActiveBackgroundPlane, color, var_2, var_4, var_6); - - return 0; -} - -int16 Op_loadAudioResource(void) -{ - popPtr(); - popVar(); +int16 Op_AddMessage(void) { + int16 color = popVar(); + int16 var_2 = popVar(); + int16 var_4 = popVar(); + int16 var_6 = popVar(); + int16 var_8 = popVar(); + int16 overlayIdx = popVar(); + + if (!overlayIdx) + overlayIdx = currentScriptPtr->overlayNumber; + + if (color == -1) { + color = 0; + //ASSERT(0); + //color = calcTabSomething(); + } else { + if (CVTLoaded) { + color = cvtPalette[color]; + } + } - return 0; -} - -int16 Op_LoadCt(void) -{ - return loadCtp((uint8*)popPtr()); -} + createTextObject(overlayIdx, var_8, &cellHead, + currentScriptPtr->scriptNumber, currentScriptPtr->overlayNumber, + currentActiveBackgroundPlane, color, var_2, var_4, var_6); -int16 Op_loadMusic(void) -{ - popPtr(); - return 0; + return 0; } -int16 Op_21(void) -{ - int param1 = popVar(); - int param2 = popVar(); - int overlay = popVar(); - - if(!overlay) - overlay = currentScriptPtr->overlayNumber; +int16 Op_loadAudioResource(void) { + popPtr(); + popVar(); - return mainProc13(overlay, param2, &actorHead, param1); + return 0; } -int16 Op_InitializeState6(void) -{ - popPtr(); - popVar(); - - return 0; +int16 Op_LoadCt(void) { + return loadCtp((uint8 *) popPtr()); } -int16 Op_AutoCell(void) -{ - cellStruct* pObject; +int16 Op_loadMusic(void) { + popPtr(); + return 0; +} - int signal = popVar(); - int loop = popVar(); - int wait = popVar(); - int animStep = popVar(); - int end = popVar(); - int start = popVar(); - int type = popVar(); - int change = popVar(); - int obj = popVar(); - int overlay = popVar(); +int16 Op_21(void) { + int param1 = popVar(); + int param2 = popVar(); + int overlay = popVar(); - if(!overlay) - overlay = currentScriptPtr->overlayNumber; + if (!overlay) + overlay = currentScriptPtr->overlayNumber; - pObject = addCell(overlay, obj, &cellHead, currentScriptPtr->type, currentScriptPtr->scriptNumber, currentScriptPtr->overlayNumber, currentActiveBackgroundPlane, 4); + return mainProc13(overlay, param2, &actorHead, param1); +} - if(!pObject) - return 0; +int16 Op_InitializeState6(void) { + popPtr(); + popVar(); - pObject->field_2C = signal; - pObject->field_30 = loop; - pObject->nextAnimDelay = wait; - pObject->animStep = animStep; - pObject->field_22 = end; - pObject->field_20 = start; - pObject->field_2A = type; - pObject->field_28 = change; + return 0; +} - if(type) - { - if(currentScriptPtr->type == 20) - { - changeScriptParamInList(currentScriptPtr->overlayNumber, currentScriptPtr->scriptNumber, &scriptHandle2, 9996, -1); - } - else - if(currentScriptPtr->type == 30) - { - changeScriptParamInList(currentScriptPtr->overlayNumber, currentScriptPtr->scriptNumber, &scriptHandle1, 9996, -1); - } - } +int16 Op_AutoCell(void) { + cellStruct *pObject; + + int signal = popVar(); + int loop = popVar(); + int wait = popVar(); + int animStep = popVar(); + int end = popVar(); + int start = popVar(); + int type = popVar(); + int change = popVar(); + int obj = popVar(); + int overlay = popVar(); + + if (!overlay) + overlay = currentScriptPtr->overlayNumber; + + pObject = + addCell(overlay, obj, &cellHead, currentScriptPtr->type, + currentScriptPtr->scriptNumber, currentScriptPtr->overlayNumber, + currentActiveBackgroundPlane, 4); + + if (!pObject) + return 0; + + pObject->field_2C = signal; + pObject->field_30 = loop; + pObject->nextAnimDelay = wait; + pObject->animStep = animStep; + pObject->field_22 = end; + pObject->field_20 = start; + pObject->field_2A = type; + pObject->field_28 = change; + + if (type) { + if (currentScriptPtr->type == 20) { + changeScriptParamInList(currentScriptPtr-> + overlayNumber, currentScriptPtr->scriptNumber, + &scriptHandle2, 9996, -1); + } else if (currentScriptPtr->type == 30) { + changeScriptParamInList(currentScriptPtr-> + overlayNumber, currentScriptPtr->scriptNumber, + &scriptHandle1, 9996, -1); + } + } - if(change == 5) - { - Op_InitializeStateSub(pObject->overlay, pObject->idx, start); - } - else - { - setObjectPosition(pObject->overlay, pObject->idx, pObject->field_28, start); - } + if (change == 5) { + Op_InitializeStateSub(pObject->overlay, pObject->idx, start); + } else { + setObjectPosition(pObject->overlay, pObject->idx, + pObject->field_28, start); + } - if(wait < 0) - { - objectParamsQuery params; + if (wait < 0) { + objectParamsQuery params; - getMultipleObjectParam(overlay, obj, ¶ms); - pObject->currentAnimDelay = params.var6-1; - } + getMultipleObjectParam(overlay, obj, ¶ms); + pObject->currentAnimDelay = params.var6 - 1; + } - return 0; + return 0; } -int16 Op_66(void) -{ - objectParamsQuery params; - int index = popVar(); - int overlay = popVar(); +int16 Op_66(void) { + objectParamsQuery params; + int index = popVar(); + int overlay = popVar(); - if(!overlay) - overlay = currentScriptPtr->overlayNumber; + if (!overlay) + overlay = currentScriptPtr->overlayNumber; - getMultipleObjectParam(overlay, index, ¶ms); + getMultipleObjectParam(overlay, index, ¶ms); - return params.var7; + return params.var7; } -int16 Op_SetActiveBackgroundPlane(void) -{ - int currentPlane = currentActiveBackgroundPlane; - int newPlane = popVar(); +int16 Op_SetActiveBackgroundPlane(void) { + int currentPlane = currentActiveBackgroundPlane; + int newPlane = popVar(); + + if (newPlane >= 0 && newPlane < 8) { + if (backgroundPtrtable[newPlane]) { + currentActiveBackgroundPlane = newPlane; + initVar3 = 1; + } + } - if(newPlane >= 0 && newPlane < 8) - { - if(backgroundPtrtable[newPlane]) - { - currentActiveBackgroundPlane = newPlane; - initVar3 = 1; - } - } - - return currentPlane; + return currentPlane; } int op6AVar; -int16 Op_6A(void) -{ - op6AVar = popVar(); - return 0; +int16 Op_6A(void) { + op6AVar = popVar(); + return 0; } int op7BVar = 0; -int16 Op_InitializeStateB(void) -{ - int di = popVar(); - int si = 1 - op7BVar; - int sign; - - if(di) - { - sign = di/(abs(di)); - } - else - { - sign = 0; - } - - op7BVar = -sign; - - return si; -} - -void removeBackgroundIncrust(int overlay, int idx, backgroundIncrustStruct* pHead) -{ - objectParamsQuery params; - int var_4; - int var_6; +int16 Op_InitializeStateB(void) { + int di = popVar(); + int si = 1 - op7BVar; + int sign; - backgroundIncrustStruct* pCurrent; - backgroundIncrustStruct* pCurrentHead; - - getMultipleObjectParam(overlay, idx, ¶ms); + if (di) { + sign = di / (abs(di)); + } else { + sign = 0; + } - var_4 = params.X; - var_6 = params.Y; + op7BVar = -sign; - pCurrent = pHead->next; + return si; +} - while(pCurrent) - { - if( (pCurrent->overlayIdx == overlay || overlay == -1) && - (pCurrent->objectIdx == idx || idx == -1) && - (pCurrent->X == var_4) && - (pCurrent->Y == var_6)) - { - pCurrent->field_6 = (uint16)-1; - } +void removeBackgroundIncrust(int overlay, int idx, + backgroundIncrustStruct * pHead) { + objectParamsQuery params; + int var_4; + int var_6; - pCurrent = pCurrent->next; - } + backgroundIncrustStruct *pCurrent; + backgroundIncrustStruct *pCurrentHead; - pCurrentHead = pHead; - pCurrent = pHead->next; + getMultipleObjectParam(overlay, idx, ¶ms); - while(pCurrent) - { - if(pCurrent->field_6 == (uint16)-1) - { - backgroundIncrustStruct* pNext = pCurrent->next; - backgroundIncrustStruct* bx = pCurrentHead; - backgroundIncrustStruct* cx; + var_4 = params.X; + var_6 = params.Y; - bx->next = pNext; - cx = pNext; + pCurrent = pHead->next; - if(!pNext) - { - cx = pHead; - } + while (pCurrent) { + if ((pCurrent->overlayIdx == overlay || overlay == -1) && + (pCurrent->objectIdx == idx || idx == -1) && + (pCurrent->X == var_4) && (pCurrent->Y == var_6)) { + pCurrent->field_6 = (uint16) - 1; + } - bx = cx; - bx->prev = pCurrent->next; + pCurrent = pCurrent->next; + } - if(pCurrent->ptr) - { - free(pCurrent->ptr); - } + pCurrentHead = pHead; + pCurrent = pHead->next; - free(pCurrent); + while (pCurrent) { + if (pCurrent->field_6 == (uint16) - 1) { + backgroundIncrustStruct *pNext = pCurrent->next; + backgroundIncrustStruct *bx = pCurrentHead; + backgroundIncrustStruct *cx; - pCurrent = pNext; - } - else - { - pCurrentHead = pCurrent; - pCurrent = pCurrent->next; - } - } -} + bx->next = pNext; + cx = pNext; + if (!pNext) { + cx = pHead; + } -int16 Op_removeBackgroundIncrust(void) -{ - int idx = popVar(); - int overlay = popVar(); + bx = cx; + bx->prev = pCurrent->next; - if(!overlay) - { - overlay = currentScriptPtr->overlayNumber; - } + if (pCurrent->ptr) { + free(pCurrent->ptr); + } - removeBackgroundIncrust(overlay, idx, &backgroundIncrustHead); + free(pCurrent); - return 0; + pCurrent = pNext; + } else { + pCurrentHead = pCurrent; + pCurrent = pCurrent->next; + } + } +} + +int16 Op_removeBackgroundIncrust(void) { + int idx = popVar(); + int overlay = popVar(); + + if (!overlay) { + overlay = currentScriptPtr->overlayNumber; + } + + removeBackgroundIncrust(overlay, idx, &backgroundIncrustHead); + + return 0; } -int16 Op_SetColor(void) // TODO: palette manipulation -{ - //var_4 = popVar(); - //var_6 = popVar(); - //var_8 = popVar(); - //int si = popVar(); - //int di = popVar(); - popVar(); - popVar(); - popVar(); - popVar(); - popVar(); +int16 Op_SetColor(void) { // TODO: palette manipulation + //var_4 = popVar(); + //var_6 = popVar(); + //var_8 = popVar(); + //int si = popVar(); + //int di = popVar(); + popVar(); + popVar(); + popVar(); + popVar(); + popVar(); - return 0; + return 0; } -int16 Op_InitializeState8(void) -{ - int si = var41; +int16 Op_InitializeState8(void) { + int si = var41; - var41 = popVar(); + var41 = popVar(); - return si; + return si; } -int16 Op_releaseOverlay(void) -{ - int overlayIdx; +int16 Op_releaseOverlay(void) { + int overlayIdx; - overlayIdx = popVar(); + overlayIdx = popVar(); - if(strlen(overlayTable[overlayIdx].overlayName)) - { - releaseOverlay(overlayTable[overlayIdx].overlayName); - } + if (strlen(overlayTable[overlayIdx].overlayName)) { + releaseOverlay(overlayTable[overlayIdx].overlayName); + } - return 0; + return 0; } -int16 Op_SetColorrawLine(void) -{ - /* - int di = popVar(); - int var_2 = popVar(); - int var_4 = popVar(); - int var_6 = popVar(); - uint8* ptr = (uint8*)popPtr(); - */ +int16 Op_SetColorrawLine(void) { + /* + * int di = popVar(); + * int var_2 = popVar(); + * int var_4 = popVar(); + * int var_6 = popVar(); + * uint8* ptr = (uint8*)popPtr(); + */ - popVar(); - popVar(); - popVar(); - popVar(); - popPtr(); + popVar(); + popVar(); + popVar(); + popVar(); + popPtr(); - //drawLinePtr(var_6, var_4, var_2, ptr); + //drawLinePtr(var_6, var_4, var_2, ptr); - // flipGen(ptr); + // flipGen(ptr); - return 0; + return 0; } -int16 Op_61(void) -{ - int si = popVar(); - popVar(); +int16 Op_61(void) { + int si = popVar(); + popVar(); - return si; + return si; } -int16 Op_1A(void) -{ - var46 = popVar(); - var45 = popVar(); - var42 = popVar(); - var39 = popVar(); - return 0; +int16 Op_1A(void) { + var46 = popVar(); + var45 = popVar(); + var42 = popVar(); + var39 = popVar(); + return 0; } -int16 computeZoom(int param) -{ - return (((param - var46)*(var39-var42))/(var45 - var46))+var42; +int16 computeZoom(int param) { + return (((param - var46) * (var39 - var42)) / (var45 - var46)) + var42; } -int16 subOp23(int param1, int param2) -{ - return (param1*param2)>>8; +int16 subOp23(int param1, int param2) { + return (param1 * param2) >> 8; } -int16 Op_23(void) -{ - int si = popVar(); - int dx = popVar(); +int16 Op_23(void) { + int si = popVar(); + int dx = popVar(); - return subOp23(dx,si); + return subOp23(dx, si); } -int16 Op_22(void) -{ - return(computeZoom(popVar())); +int16 Op_22(void) { + return (computeZoom(popVar())); } -actorStruct* addAnimation(actorStruct* pHead, int overlay, int objIdx, int param, int param2) -{ - actorStruct* pPrevious = pHead; - actorStruct* pCurrent = pHead->next; +actorStruct *addAnimation(actorStruct * pHead, int overlay, int objIdx, + int param, int param2) { + actorStruct *pPrevious = pHead; + actorStruct *pCurrent = pHead->next; // go to the end of the list - while(pCurrent) - { + while (pCurrent) { pPrevious = pCurrent; pCurrent = pPrevious->next; } - if(pCurrent && (pCurrent->overlayNumber == overlay) && (pCurrent->idx == objIdx) && (pCurrent->type == param2)) - { + if (pCurrent && (pCurrent->overlayNumber == overlay) + && (pCurrent->idx == objIdx) && (pCurrent->type == param2)) { return NULL; } - actorStruct* pNewElement = (actorStruct*)malloc(sizeof(actorStruct)); - if(!pNewElement) + actorStruct *pNewElement = (actorStruct *) malloc(sizeof(actorStruct)); + if (!pNewElement) return NULL; pNewElement->next = pPrevious->next; pPrevious->next = pNewElement; - if(!pCurrent) - { - pCurrent = pHead; + if (!pCurrent) { + pCurrent = pHead; } pNewElement->prev = pCurrent->prev; @@ -1196,418 +1075,376 @@ actorStruct* addAnimation(actorStruct* pHead, int overlay, int objIdx, int param return pNewElement; } -int flag_obstacle; // computedVar14Bis +int flag_obstacle; // computedVar14Bis -void checkCollisionWithWalkBoxesBoundingBoxes(int x, int y) -{ - ctpVar19Struct* di = ctpVar19; +void checkCollisionWithWalkBoxesBoundingBoxes(int x, int y) { + ctpVar19Struct *di = ctpVar19; - do - { - int minX; - int maxX; - int minY; - int maxY; + do { + int minX; + int maxX; + int minY; + int maxY; - ctpVar19SubStruct* subStruct; + ctpVar19SubStruct *subStruct; - if(-1 == (int) di->field_0) // ok, ugly, but it's in the original - { - flag_obstacle = 0; - return; - } + if (-1 == (int)di->field_0) // ok, ugly, but it's in the original + { + flag_obstacle = 0; + return; + } - subStruct = &di->subStruct; + subStruct = &di->subStruct; - minX = subStruct->minX; - maxX = subStruct->maxX; - minY = subStruct->minY; - maxY = subStruct->maxY; + minX = subStruct->minX; + maxX = subStruct->maxX; + minY = subStruct->minY; + maxY = subStruct->maxY; - computedVar14 = subStruct->boxIdx; // Box index + computedVar14 = subStruct->boxIdx; // Box index - if(!(walkboxChange[subStruct->boxIdx]) && (minY >= x) && (maxY <= x) && (minX >= y) && (maxX <= y)) - { + if (!(walkboxChange[subStruct->boxIdx]) && (minY >= x) + && (maxY <= x) && (minX >= y) && (maxX <= y)) { /**************/ - flag_obstacle = walkboxType[computedVar14]; + flag_obstacle = walkboxType[computedVar14]; /**************/ - } + } - di = di->field_0; - } while(1); + di = di->field_0; + } while (1); - flag_obstacle = 0; + flag_obstacle = 0; } // add animation -int16 Op_AddAnimation(void) -{ - int stepY = popVar(); - int stepX = popVar(); - int direction = popVar(); - int start = popVar(); - int type = popVar(); - int obj = popVar(); - int overlay = popVar(); - - if(!overlay) - { - overlay = currentScriptPtr->overlayNumber; - } +int16 Op_AddAnimation(void) { + int stepY = popVar(); + int stepX = popVar(); + int direction = popVar(); + int start = popVar(); + int type = popVar(); + int obj = popVar(); + int overlay = popVar(); + + if (!overlay) { + overlay = currentScriptPtr->overlayNumber; + } - if(direction>=0 && direction<=3) - { - actorStruct* si; + if (direction >= 0 && direction <= 3) { + actorStruct *si; - si = addAnimation(&actorHead, overlay, obj, direction, type); + si = addAnimation(&actorHead, overlay, obj, direction, type); - if(si) - { - objectParamsQuery params; + if (si) { + objectParamsQuery params; - getMultipleObjectParam(overlay, obj, ¶ms); + getMultipleObjectParam(overlay, obj, ¶ms); - si->x = params.X; - si->y = params.Y; - si->x_dest = -1; - si->y_dest = -1; - si->endDirection = -1; - si->start = start; - si->stepX = stepX; - si->stepY = stepY; + si->x = params.X; + si->y = params.Y; + si->x_dest = -1; + si->y_dest = -1; + si->endDirection = -1; + si->start = start; + si->stepX = stepX; + si->stepY = stepY; - int newFrame = abs(actorTable1[direction].data[0]) - 1; + int newFrame = abs(actorTable1[direction].data[0]) - 1; - int zoom = computeZoom(params.Y); + int zoom = computeZoom(params.Y); - if(actorTable1[direction].data[0] < 0) - { - zoom = -zoom; - } + if (actorTable1[direction].data[0] < 0) { + zoom = -zoom; + } - checkCollisionWithWalkBoxesBoundingBoxes(params.X, params.Y); + checkCollisionWithWalkBoxesBoundingBoxes(params.X, + params.Y); - setObjectPosition(overlay, obj, 3, newFrame + start); - setObjectPosition(overlay, obj, 4, zoom); - setObjectPosition(overlay, obj, 5, computedVar14); + setObjectPosition(overlay, obj, 3, newFrame + start); + setObjectPosition(overlay, obj, 4, zoom); + setObjectPosition(overlay, obj, 5, computedVar14); - animationStart = false; - } - } + animationStart = false; + } + } - return 0; + return 0; } -int16 Op_RemoveAnimation(void) -{ - popVar(); - popVar(); - popVar(); +int16 Op_RemoveAnimation(void) { + popVar(); + popVar(); + popVar(); - printf("Partial op 19 (remove actor)\n"); + printf("Partial op 19 (remove actor)\n"); - return 0; + return 0; } -int16 Op_regenerateBackgroundIncrust(void) -{ - regenerateBackgroundIncrust(&backgroundIncrustHead); - return 0; +int16 Op_regenerateBackgroundIncrust(void) { + regenerateBackgroundIncrust(&backgroundIncrustHead); + return 0; } -int16 Op_SetStringColors(void) -{ - // TODO: here ignore if low color mode +int16 Op_SetStringColors(void) { + // TODO: here ignore if low color mode - colorOfSelectedSaveDrive = (uint8)popVar(); - video2 = (uint8)popVar(); - video3 = (uint8)popVar(); - video4 = (uint8)popVar(); + colorOfSelectedSaveDrive = (uint8) popVar(); + video2 = (uint8) popVar(); + video3 = (uint8) popVar(); + video4 = (uint8) popVar(); - return 0; + return 0; } -int16 Op_1E(void) // setup actor position -{ - actorStruct* pActor; +int16 Op_1E(void) { // setup actor position + actorStruct *pActor; - var0 = popVar(); - int actorY = popVar(); - int actorX = popVar(); - var1 = popVar(); - var2 = popVar(); - int overlay = popVar(); + var0 = popVar(); + int actorY = popVar(); + int actorX = popVar(); + var1 = popVar(); + var2 = popVar(); + int overlay = popVar(); - if(!overlay) - { - overlay = currentScriptPtr->overlayNumber; - } + if (!overlay) { + overlay = currentScriptPtr->overlayNumber; + } - pActor = findActor(overlay,var2,&actorHead,var1); + pActor = findActor(overlay, var2, &actorHead, var1); - if(!pActor) - { - return 1; - } + if (!pActor) { + return 1; + } - animationStart = false; + animationStart = false; - pActor->x_dest = actorX; - pActor->y_dest = actorY; - pActor->flag = 1; - pActor->endDirection = var0; + pActor->x_dest = actorX; + pActor->y_dest = actorY; + pActor->flag = 1; + pActor->endDirection = var0; - return 0; + return 0; } -int16 Op_45(void) -{ - printf("Partial op 45 stop sound\n"); +int16 Op_45(void) { + printf("Partial op 45 stop sound\n"); - return 0; + return 0; } -int16 Op_AddCellC(void) -{ - popPtr(); - popVar(); +int16 Op_AddCellC(void) { + popPtr(); + popVar(); - printf("Partial op 5C\n"); + printf("Partial op 5C\n"); - return 0; + return 0; } -int16 Op_AddCellE(void) -{ - popVar(); +int16 Op_AddCellE(void) { + popVar(); - printf("Partial op 5E (sound related)\n"); + printf("Partial op 5E (sound related)\n"); - return 0; + return 0; } -int16 Op_3E(void) -{ - printf("Partial op 3E (sound related)\n"); +int16 Op_3E(void) { + printf("Partial op 3E (sound related)\n"); - return 0; + return 0; } -void setVar49Value(int value) -{ - flagCt = value; +void setVar49Value(int value) { + flagCt = value; } -int16 Op_3A(void) -{ - setVar49Value(1); - return 0; +int16 Op_3A(void) { + setVar49Value(1); + return 0; } -int16 Op_3B(void) -{ - setVar49Value(0); - return 0; +int16 Op_3B(void) { + setVar49Value(0); + return 0; } -int16 Op_3F(void) -{ - printf("Partial op 3F (sound related)\n"); - return 0; +int16 Op_3F(void) { + printf("Partial op 3F (sound related)\n"); + return 0; } -int16 Op_40(void) -{ - printf("Partial op 40 (sound related)\n"); - //freeStuff1(); - freeStuff2(); +int16 Op_40(void) { + printf("Partial op 40 (sound related)\n"); + //freeStuff1(); + freeStuff2(); - var24 = 0; - var23 = 0; - return 0; + var24 = 0; + var23 = 0; + return 0; } -int16 Op_6C(void) -{ - //int var0; - //int var1; - int temp; +int16 Op_6C(void) { + //int var0; + //int var1; + int temp; - var0 = popVar(); - var1 = popVar(); + var0 = popVar(); + var1 = popVar(); - if(!var1) - { - var1 = currentScriptPtr->overlayNumber; - } + if (!var1) { + var1 = currentScriptPtr->overlayNumber; + } - temp = overlayTable[var1].executeScripts; - overlayTable[var1].executeScripts = var0; + temp = overlayTable[var1].executeScripts; + overlayTable[var1].executeScripts = var0; - return temp; + return temp; } -void configureAllObjects(int overlayIdx, cellStruct* pObject, int _var4, int _var0, int _var1, int _var2, int _var3) -{ - while(pObject) - { - if((pObject->overlay == overlayIdx) || (overlayIdx == -1)) - { - if((pObject->idx == _var4) || (_var4 == -1)) - { - if((pObject->type == _var3) || (_var3 == -1)) - { - if((pObject->backgroundPlane == _var2) || (_var2 == -1)) - { - if((pObject->freeze == _var1) || (_var1 == -1)) - { - pObject->freeze = _var0; - } - } - } - } - } - - pObject = pObject->next; - } +void configureAllObjects(int overlayIdx, cellStruct * pObject, int _var4, + int _var0, int _var1, int _var2, int _var3) { + while (pObject) { + if ((pObject->overlay == overlayIdx) || (overlayIdx == -1)) { + if ((pObject->idx == _var4) || (_var4 == -1)) { + if ((pObject->type == _var3) || (_var3 == -1)) { + if ((pObject->backgroundPlane == _var2) || (_var2 == -1)) { + if ((pObject->freeze == _var1) || (_var1 == -1)) { + pObject->freeze = _var0; + } + } + } + } + } + + pObject = pObject->next; + } } -int16 Op_FreezeCell(void) -{ - /* - int var0; - int var1; - int var2; - int var3; - int var4; - int var5; - */ - - var0 = popVar(); - var1 = popVar(); - var2 = popVar(); - var3 = popVar(); - var4 = popVar(); - var5 = popVar(); - - if(!var5) - { - var5 = currentScriptPtr->overlayNumber; - } +int16 Op_FreezeCell(void) { + /* + * int var0; + * int var1; + * int var2; + * int var3; + * int var4; + * int var5; + */ + + var0 = popVar(); + var1 = popVar(); + var2 = popVar(); + var3 = popVar(); + var4 = popVar(); + var5 = popVar(); + + if (!var5) { + var5 = currentScriptPtr->overlayNumber; + } - configureAllObjects(var5, &cellHead, var4, var0, var1, var2, var3); + configureAllObjects(var5, &cellHead, var4, var0, var1, var2, var3); - return 0; + return 0; } -void Op_60Sub(int overlayIdx, actorStruct* pActorHead, int _var0, int _var1, int _var2, int _var3) -{ - actorStruct* pActor = findActor(overlayIdx, _var0, pActorHead, _var3); +void Op_60Sub(int overlayIdx, actorStruct * pActorHead, int _var0, int _var1, + int _var2, int _var3) { + actorStruct *pActor = findActor(overlayIdx, _var0, pActorHead, _var3); - if(pActor) - { - if((pActor->freeze == _var2) || (_var2 == -1)) - { - pActor->freeze = _var1; - } - } + if (pActor) { + if ((pActor->freeze == _var2) || (_var2 == -1)) { + pActor->freeze = _var1; + } + } } -int16 Op_60(void) -{ - /* - int var0; - int var1; - int var2; - int var3; - int var4; - */ +int16 Op_60(void) { + /* + * int var0; + * int var1; + * int var2; + * int var3; + * int var4; + */ - var0 = popVar(); - var1 = popVar(); - var2 = popVar(); - var3 = popVar(); - var4 = popVar(); + var0 = popVar(); + var1 = popVar(); + var2 = popVar(); + var3 = popVar(); + var4 = popVar(); - if(!var4) - { - var4 = currentScriptPtr->overlayNumber; - } + if (!var4) { + var4 = currentScriptPtr->overlayNumber; + } - Op_60Sub(var4, &actorHead, var3, var0, var1, var2); + Op_60Sub(var4, &actorHead, var3, var0, var1, var2); - return 0; + return 0; } -int16 Op_6F(void) -{ - int numArgs = popVar(); +int16 Op_6F(void) { + int numArgs = popVar(); - assert(numArgs == 0); + assert(numArgs == 0); - { - popVar(); - char* string = (char*)popPtr(); + { + popVar(); + char *string = (char *)popPtr(); - printf("partial opcode 6F sprintf (%s)\n", string); - } + printf("partial opcode 6F sprintf (%s)\n", string); + } - return 0; + return 0; } -int16 Op_6E(void) -{ - char* ptr0 = (char*)popPtr(); - char* ptr1 = (char*)popPtr(); +int16 Op_6E(void) { + char *ptr0 = (char *)popPtr(); + char *ptr1 = (char *)popPtr(); - printf("partial opcode 6E (%s)(%s)\n", ptr0, ptr1); + printf("partial opcode 6E (%s)(%s)\n", ptr0, ptr1); - return 0; + return 0; } -int16 Op_InitializeState2(void) -{ - var0 = popVar(); - char* ptr = (char*)popPtr(); - var1 = popVar(); +int16 Op_InitializeState2(void) { + var0 = popVar(); + char *ptr = (char *)popPtr(); + var1 = popVar(); - if(!var1) - var1 = currentScriptPtr->overlayNumber; + if (!var1) + var1 = currentScriptPtr->overlayNumber; - return getProcParam(var1, var0, (uint8*)ptr); + return getProcParam(var1, var0, (uint8 *) ptr); } -int16 Op_2A(void) -{ - char var_26[36]; - char* ptr = (char*)popPtr(); - int overlayIdx; +int16 Op_2A(void) { + char var_26[36]; + char *ptr = (char *)popPtr(); + int overlayIdx; - var_26[0] = 0; + var_26[0] = 0; - if(ptr) - { - strcpy(var_26, ptr); - } + if (ptr) { + strcpy(var_26, ptr); + } - overlayIdx = popVar(); + overlayIdx = popVar(); - if(!overlayIdx) - overlayIdx = currentScriptPtr->overlayNumber; + if (!overlayIdx) + overlayIdx = currentScriptPtr->overlayNumber; - return getProcParam(overlayIdx, 40, (uint8*)var_26); + return getProcParam(overlayIdx, 40, (uint8 *) var_26); } -void setupOpcodeTable(void) -{ - int i; +void setupOpcodeTable(void) { + int i; - for(i=0;i<256;i++) - { - opcodeTablePtr[i] = NULL; - } + for (i = 0; i < 256; i++) { + opcodeTablePtr[i] = NULL; + } opcodeTablePtr[0x1] = Op_FadeIn; opcodeTablePtr[0x2] = Op_FadeOut; @@ -1623,13 +1460,13 @@ void setupOpcodeTable(void) opcodeTablePtr[0xC] = Op_LoadOverlay; opcodeTablePtr[0xD] = Op_SetColor; opcodeTablePtr[0xE] = Op_PlayFX; - opcodeTablePtr[0xF] = NULL; // used to be debug + opcodeTablePtr[0xF] = NULL; // used to be debug opcodeTablePtr[0x10] = Op_FreeOverlay; opcodeTablePtr[0x11] = Op_FindOverlay; - opcodeTablePtr[0x12] = NULL; // used to be exec debug + opcodeTablePtr[0x12] = NULL; // used to be exec debug opcodeTablePtr[0x13] = Op_AddMessage; opcodeTablePtr[0x14] = Op_RemoveMessage; - opcodeTablePtr[0x15] = NULL; // user wait + opcodeTablePtr[0x15] = NULL; // user wait opcodeTablePtr[0x16] = Op_FreezeCell; opcodeTablePtr[0x17] = Op_LoadCt; opcodeTablePtr[0x18] = Op_AddAnimation; @@ -1697,31 +1534,26 @@ void setupOpcodeTable(void) // TODO: copy the opcodes here } -int32 opcodeType8(void) -{ - int opcode = getByteFromScript(); +int32 opcodeType8(void) { + int opcode = getByteFromScript(); - if(!opcode) - return(-21); + if (!opcode) + return (-21); - if(opcode>0x100) - return(-21); + if (opcode > 0x100) + return (-21); - if(opcodeTablePtr[opcode]) - { - //printf("Function: %X\n",opcode); - pushVar(opcodeTablePtr[opcode]()); - return(0); - } - else - { - printf("Unsupported opcode %X in opcode type 8\n",opcode); - // exit(1); - } - - return 0; + if (opcodeTablePtr[opcode]) { + //printf("Function: %X\n",opcode); + pushVar(opcodeTablePtr[opcode] ()); + return (0); + } else { + printf("Unsupported opcode %X in opcode type 8\n", opcode); + // exit(1); + } -} + return 0; +} } // End of namespace Cruise diff --git a/engines/cruise/function.h b/engines/cruise/function.h index c71ef6bbea..68fdfed6d0 100644 --- a/engines/cruise/function.h +++ b/engines/cruise/function.h @@ -22,8 +22,8 @@ * */ -#ifndef _FUNCTION_H_ -#define _FUNCTION_H_ +#ifndef CRUISE_FUNCTION_H +#define CRUISE_FUNCTION_H namespace Cruise { @@ -36,4 +36,3 @@ int16 subOp23(int param1, int param2); } // End of namespace Cruise #endif - diff --git a/engines/cruise/gfxModule.cpp b/engines/cruise/gfxModule.cpp index 1a3240fe97..2b5690466c 100644 --- a/engines/cruise/gfxModule.cpp +++ b/engines/cruise/gfxModule.cpp @@ -36,453 +36,449 @@ char screen[320 * 200]; palEntry lpalette[256]; short globalAtariScreen[320 * 200 / 4]; -gfxModuleDataStruct gfxModuleData = -{ - 0, // field_1 - 0, // use Tandy - 0, // use EGA - 1, // use VGA - - page00, // pPage00 - page10, // pPage10 +gfxModuleDataStruct gfxModuleData = { + 0, // field_1 + 0, // use Tandy + 0, // use EGA + 1, // use VGA + + page00, // pPage00 + page10, // pPage10 }; -void gfxModuleData_gfxClearFrameBuffer(uint8* ptr) -{ +void gfxModuleData_gfxClearFrameBuffer(uint8 *ptr) { memset(ptr, 0, 64000); } -void gfxModuleData_gfxCopyScreen(char* sourcePtr, char* destPtr) -{ +void gfxModuleData_gfxCopyScreen(char *sourcePtr, char *destPtr) { memcpy(destPtr, sourcePtr, 64000); } -void outputBit(char* buffer, int bitPlaneNumber, uint8 data) -{ - *(buffer +(8000 * bitPlaneNumber)) = data; +void outputBit(char *buffer, int bitPlaneNumber, uint8 data) { + *(buffer + (8000 * bitPlaneNumber)) = data; } - -void gfxModuleData_field_60(char* sourcePtr, int width, int height, char* destPtr, int x, int y) -{/* - int loc_1064; - int loc_10AA; - int loc_10AD; - int loc_10C5; - int loc_10DF; - int loc_10EC; - int loc_1147; - int loc_114B; - int loc_117C = 0xF8; - int loc_11DC; - int loc_1277; - int loc_12D9; - int loc_12DD; - - int loc_11E7; - int loc_127A; - int loc_1203; - int loc_122B; - int loc_117F; - int loc_11EF; - int loc_1217; - int loc_12E1; - - int tempSwap; - - int cx; - int bp; - int bpSave; - - char* diPtr; - char* siPtr; - - int direction = 1; - int dx = height; - int ax = width; - int es = ax << 1; - int bx = 0; - int di = 199; - int si; - - ax = y; - si = 0; - - if(y>199) // out of screen vertically - return; - - if(y<0) // cropped on the top - { - cx = bx; - bx -= ax; - dx -= bx; - if(dx <= 0) - { - return; - } - ax = es; // es = size of a line ? - ax*=(bx&0xFF); // bx number of lines to skip vertically - si+=ax; - ax = cx; - } - - bx = ax; - ax += dx; - ax--; - - if(ax > di) - { - ax -= di; - dx -= ax; - - if(dx <= 0) - { - return; - } - } - - ax = dx; - loc_10DF = ax; - ax = bx; - loc_10AD = ax; - - bx = 0; - di = 319; - - ax = x; - dx = ax; - cx = ax&0xFF; - cx &= 7; - { - int cl = cx; - int ch = cl; - - cl-=8; - cl=-cl; - cl&=7; - ax = (ch<<8) | (cl); - } - loc_1064 = ax; - ax = es; - ax <<= 3; - - tempSwap = dx; - dx = ax; - ax = tempSwap; - - if(ax > di) - { - return; - } - - cx = ax; - cx += dx; - cx --; - - dx >>= 3; - - dx = dx&0xFF; - - if(cx<bx) - { - return; - } - - if(cx>di) - { - cx -= di; - cx >>= 3; - dx = (dx&0xFF00) | (((dx&0xFF) - (cx&0xFF))&0xFF); - dx = ((cx&0xFF)<<8) | (dx&0xFF); - di = 0xF8F9; - } - else - { - di = 0xF8F8; - } - - if(ax<bx) - { - ax -= bx; - ax = -ax; - ax >>= 3; - - si += ax; - dx = (dx&0xFF00) | (((dx&0xFF)-(ax&0xFF))&0xFF); - dx = (((dx&0xFF00) + ((ax&0xFF)<<8))&0xFF00) | (dx&0xFF); - ax = bx; - cx = di; - cx = (248<<8)|(cx&0xFF); - di = cx; - } - - loc_10AA = ax; - ax = (ax&0xFF00) | (((dx&0xFF00)>>8)&0xFF); - ax = ax&0xFF; - loc_10C5 = ax; - ax = (ax&0xFF00) | (dx&0xFF); - - dx = loc_1064; - - if(dx) - { - if(di&1) - { - loc_10C5++; - } - - bx = ax; - ax--; - loc_11DC = ax; - - if(di&0x100) - { - bx--; - } - - ax = bx; - ax -= 40; - ax = -ax; - loc_12D9 = ax; - ax = di; - loc_1277 = ax&0xFF; - ax = (ax&0xFF00) | (((ax&0xFF00)>>8)&0xFF); - loc_117C = ax&0xFF; - } - else - { - loc_10EC = ax; - ax -= 40; - ax = -ax; - loc_1147 = ax; - } - - bx = loc_10AA; - ax = loc_10AD; - bx = ((((((bx&0xFF00)>>8)&0xFF) + (ax&0xFF))<<8)&0xFF00) | (bx&0xFF); - - bx>>=3; - ax<<=3; - - bx+=ax; - - diPtr = destPtr; - diPtr += bx; - - ax = loc_10C5; - ax<<=2; - loc_114B = ax; - loc_12DD = ax; - ax = si; - ax <<=2; - siPtr = sourcePtr; - - siPtr+=ax; - - bp = loc_10DF; - bx = dx; - dx = 974; - - if(!bx) // no crop ? - { - do // for each line - { - bpSave = bp; - cx = loc_10EC; - - do // for the line - { - outputBit(diPtr,0,*(siPtr)); - outputBit(diPtr,1,*(siPtr+1)); - outputBit(diPtr,2,*(siPtr+2)); - outputBit(diPtr,3,*(siPtr+3)); - - siPtr+=4; - diPtr++; - }while(--cx); - - diPtr += loc_1147; // interline - siPtr += loc_114B; - bp = bpSave; - }while(--bp); - } - else // croped - { - ASSERT(0); - loc_1156: - ax = (ax&0xFF00) | bx&0xFF; - loc_11E7 = ax&0xFF; - loc_127A = ax&0xFF; - loc_1203 = ax&0xFF; - loc_122B = ax&0xFF; - - ax = (ax&0xFF00) | (((bx&0xFF00)>>8)&0xFF); - loc_117F = ax&0xFF; - loc_11EF = ax&0xFF; - loc_1217 = ax&0xFF; - - do // main copy loop - { - ax = bp; - loc_12E1 = ax; - - if(loc_117C == 0xF8) - { - direction = 1; - } - else - { - direction = -1; - } - - if(direction == -1) - { - goto label_11DC; - } - - cx = loc_117F; - - ax = (ax&0xFF00) | (((*siPtr)&0xFF)>>cx)&0xFF; - dx = (((ax&0xFF)<<8)&0xFF00) | (dx&0xFF); - ax = (((ax&0xFF)<<8)&0xFF00) | (ax&0xFF); - - ax = (ax&0xFF00) | (((*(siPtr+1))&0xFF)>>cx)&0xFF; - dx = (dx&0xFF00) | (ax&0xFF); - ax = ((((((ax&0xFF00)>>8)&0xFF) | (ax&0xFF))<<8)&0xFF00) | (ax&0xFF); - - ax = (ax&0xFF00) | (((*(siPtr+2))&0xFF)>>cx)&0xFF; - bx = (((ax&0xFF)<<8)&0xFF00) | (bx&0xFF); - ax = ((((((ax&0xFF00)>>8)&0xFF) | (ax&0xFF))<<8)&0xFF00) | (ax&0xFF); - - ax = (ax&0xFF00) | (((*(siPtr+3))&0xFF)>>cx)&0xFF; - bx = (bx&0xFF00) | (ax&0xFF); - ax = ((((((ax&0xFF00)>>8)&0xFF) | (ax&0xFF))<<8)&0xFF00) | (ax&0xFF); - - if(ax) - { - bp = dx; - ax = (ax&0xFF00) | (*diPtr)&0xFF; - ax = (ax&0xFF00) | 8; - - outputBit(diPtr,0,(bp>>8)&0xFF); - outputBit(diPtr,1,(bp&0xFF)); - outputBit(diPtr,2,(bx>>8)&0xFF); - outputBit(diPtr,3,(bx&0xFF)); - } - - diPtr++; - - label_11DC: - - bp = loc_11DC; - if(bp >0) - { - do - { - cx = loc_11E7; - - ax = (ax&0xFF00) | (((*siPtr)&0xFF)>>cx)&0xFF; - dx = (((ax&0xFF)<<8)&0xFF00) | (dx&0xFF); - cx = loc_11EF; - ax = (ax&0xFF00) | (((*(siPtr+4))&0xFF)>>cx)&0xFF; - dx = (((dx&0xFF00) | (((ax&0xFF)<<8)&0xFF00))&0xFF00) | (dx&0xFF); - ax = (ax&0xFF00) | (((ax&0xFF) | (((dx&0xFF00)>>8)&0xFF))&0xFF); - ax = ((ax&0xFF)<<8) | (ax&0xFF); - - ax = (ax&0xFF00) | (((*(siPtr+5))&0xFF)>>cx)&0xFF; - dx = (dx&0xFF00) | (ax&0xFF); - cx = loc_1203; - ax = (ax&0xFF00) | (((*(siPtr+1))&0xFF)>>cx)&0xFF; - dx = (dx&0xFF00) | ((dx&0xFF) | (ax&0xFF)); - ax = (ax&0xFF00) | ((ax&0xFF) | dx&0xFF); - ax = (ax&0xFF00) | ((ax&0xFF)<<8) | (ax&0xFF); - - ax = (ax&0xFF00) | (((*(siPtr+2))&0xFF)>>cx)&0xFF; - bx = (((ax&0xFF)<<8)&0xFF00) | (bx&0xFF); - cx = loc_1217; - ax = (ax&0xFF00) | (((*(siPtr+7))&0xFF)>>cx)&0xFF; - bx = (((bx&0xFF00) | (((ax&0xFF)<<8)&0xFF00))&0xFF00) | (bx&0xFF); - ax = (ax&0xFF00) | ((ax&0xFF) | ((bx&0xFF00)>>8)); - ax = (ax&0xFF00) | ((ax&0xFF)<<8) | (ax&0xFF); - - ax = (ax&0xFF00) | (((*(siPtr+7))&0xFF)>>cx)&0xFF; - bx = (bx&0xFF00) | (ax&0xFF); - cx = loc_122B; - ax = (ax&0xFF00) | (((*(siPtr+3))&0xFF)>>cx)&0xFF; - bx = (bx&0xFF00) | ((bx&0xFF) | (ax&0xFF)); - ax = (ax&0xFF00) | ((ax&0xFF) | bx&0xFF); - ax = (ax&0xFF00) | ((ax&0xFF)<<8) | (ax&0xFF); - - if(ax) - { - cx = dx; - ax = (ax&0xFF00) | (*diPtr)&0xFF; - ax = (ax&0xFF00) | 8; - - outputBit(diPtr,0,(cx>>8)&0xFF); - outputBit(diPtr,1,(cx&0xFF)); - outputBit(diPtr,2,(cx>>8)&0xFF); - outputBit(diPtr,3,(cx&0xFF)); - } - - siPtr += 4; - diPtr++; - }while(--bp); - } - - if(loc_122B == 0xF8) - { - direction = 1; - } - else - { - direction = -1; - } - - if(direction == -1) - { - goto label_12D9; - } - - cx = loc_127A; - - ax = (ax&0xFF00) | (((*siPtr)&0xFF)>>cx)&0xFF; - dx = (((ax&0xFF)<<8)&0xFF00) | (dx&0xFF); - ax = (((ax&0xFF)<<8)&0xFF00) | (ax&0xFF); - - ax = (ax&0xFF00) | (((*(siPtr+1))&0xFF)>>cx)&0xFF; - dx = (dx&0xFF00) | (ax&0xFF); - ax = ((((((ax&0xFF00)>>8)&0xFF) | (ax&0xFF))<<8)&0xFF00) | (ax&0xFF); - - ax = (ax&0xFF00) | (((*(siPtr+2))&0xFF)>>cx)&0xFF; - bx = (((ax&0xFF)<<8)&0xFF00) | (bx&0xFF); - ax = ((((((ax&0xFF00)>>8)&0xFF) | (ax&0xFF))<<8)&0xFF00) | (ax&0xFF); - - ax = (ax&0xFF00) | (((*(siPtr+3))&0xFF)>>cx)&0xFF; - bx = (bx&0xFF00) | (ax&0xFF); - ax = ((((((ax&0xFF00)>>8)&0xFF) | (ax&0xFF))<<8)&0xFF00) | (ax&0xFF); - - if(ax) - { - bp = dx; - ax = (ax&0xFF00) | (*diPtr)&0xFF; - ax = (ax&0xFF00) | 8; - - outputBit(diPtr,0,(bp>>8)&0xFF); - outputBit(diPtr,1,(bp&0xFF)); - outputBit(diPtr,2,(bx>>8)&0xFF); - outputBit(diPtr,3,(bx&0xFF)); - } - - siPtr+=4; - - label_12D9: - diPtr+=loc_12D9; - siPtr+=loc_12DD; - bp = loc_12E1; - - }while(--bp); - }*/ +void gfxModuleData_field_60(char *sourcePtr, int width, int height, + char *destPtr, int x, int y) { + /* + * int loc_1064; + * int loc_10AA; + * int loc_10AD; + * int loc_10C5; + * int loc_10DF; + * int loc_10EC; + * int loc_1147; + * int loc_114B; + * int loc_117C = 0xF8; + * int loc_11DC; + * int loc_1277; + * int loc_12D9; + * int loc_12DD; + * + * int loc_11E7; + * int loc_127A; + * int loc_1203; + * int loc_122B; + * int loc_117F; + * int loc_11EF; + * int loc_1217; + * int loc_12E1; + * + * int tempSwap; + * + * int cx; + * int bp; + * int bpSave; + * + * char* diPtr; + * char* siPtr; + * + * int direction = 1; + * int dx = height; + * int ax = width; + * int es = ax << 1; + * int bx = 0; + * int di = 199; + * int si; + * + * ax = y; + * si = 0; + * + * if(y>199) // out of screen vertically + * return; + * + * if(y<0) // cropped on the top + * { + * cx = bx; + * bx -= ax; + * dx -= bx; + * if(dx <= 0) + * { + * return; + * } + * ax = es; // es = size of a line ? + * ax*=(bx&0xFF); // bx number of lines to skip vertically + * si+=ax; + * ax = cx; + * } + * + * bx = ax; + * ax += dx; + * ax--; + * + * if(ax > di) + * { + * ax -= di; + * dx -= ax; + * + * if(dx <= 0) + * { + * return; + * } + * } + * + * ax = dx; + * loc_10DF = ax; + * ax = bx; + * loc_10AD = ax; + * + * bx = 0; + * di = 319; + * + * ax = x; + * dx = ax; + * cx = ax&0xFF; + * cx &= 7; + * { + * int cl = cx; + * int ch = cl; + * + * cl-=8; + * cl=-cl; + * cl&=7; + * ax = (ch<<8) | (cl); + * } + * loc_1064 = ax; + * ax = es; + * ax <<= 3; + * + * tempSwap = dx; + * dx = ax; + * ax = tempSwap; + * + * if(ax > di) + * { + * return; + * } + * + * cx = ax; + * cx += dx; + * cx --; + * + * dx >>= 3; + * + * dx = dx&0xFF; + * + * if(cx<bx) + * { + * return; + * } + * + * if(cx>di) + * { + * cx -= di; + * cx >>= 3; + * dx = (dx&0xFF00) | (((dx&0xFF) - (cx&0xFF))&0xFF); + * dx = ((cx&0xFF)<<8) | (dx&0xFF); + * di = 0xF8F9; + * } + * else + * { + * di = 0xF8F8; + * } + * + * if(ax<bx) + * { + * ax -= bx; + * ax = -ax; + * ax >>= 3; + * + * si += ax; + * dx = (dx&0xFF00) | (((dx&0xFF)-(ax&0xFF))&0xFF); + * dx = (((dx&0xFF00) + ((ax&0xFF)<<8))&0xFF00) | (dx&0xFF); + * ax = bx; + * cx = di; + * cx = (248<<8)|(cx&0xFF); + * di = cx; + * } + * + * loc_10AA = ax; + * ax = (ax&0xFF00) | (((dx&0xFF00)>>8)&0xFF); + * ax = ax&0xFF; + * loc_10C5 = ax; + * ax = (ax&0xFF00) | (dx&0xFF); + * + * dx = loc_1064; + * + * if(dx) + * { + * if(di&1) + * { + * loc_10C5++; + * } + * + * bx = ax; + * ax--; + * loc_11DC = ax; + * + * if(di&0x100) + * { + * bx--; + * } + * + * ax = bx; + * ax -= 40; + * ax = -ax; + * loc_12D9 = ax; + * ax = di; + * loc_1277 = ax&0xFF; + * ax = (ax&0xFF00) | (((ax&0xFF00)>>8)&0xFF); + * loc_117C = ax&0xFF; + * } + * else + * { + * loc_10EC = ax; + * ax -= 40; + * ax = -ax; + * loc_1147 = ax; + * } + * + * bx = loc_10AA; + * ax = loc_10AD; + * bx = ((((((bx&0xFF00)>>8)&0xFF) + (ax&0xFF))<<8)&0xFF00) | (bx&0xFF); + * + * bx>>=3; + * ax<<=3; + * + * bx+=ax; + * + * diPtr = destPtr; + * diPtr += bx; + * + * ax = loc_10C5; + * ax<<=2; + * loc_114B = ax; + * loc_12DD = ax; + * ax = si; + * ax <<=2; + * siPtr = sourcePtr; + * + * siPtr+=ax; + * + * bp = loc_10DF; + * bx = dx; + * dx = 974; + * + * if(!bx) // no crop ? + * { + * do // for each line + * { + * bpSave = bp; + * cx = loc_10EC; + * + * do // for the line + * { + * outputBit(diPtr,0,*(siPtr)); + * outputBit(diPtr,1,*(siPtr+1)); + * outputBit(diPtr,2,*(siPtr+2)); + * outputBit(diPtr,3,*(siPtr+3)); + * + * siPtr+=4; + * diPtr++; + * }while(--cx); + * + * diPtr += loc_1147; // interline + * siPtr += loc_114B; + * bp = bpSave; + * }while(--bp); + * } + * else // croped + * { + * ASSERT(0); + * loc_1156: + * ax = (ax&0xFF00) | bx&0xFF; + * loc_11E7 = ax&0xFF; + * loc_127A = ax&0xFF; + * loc_1203 = ax&0xFF; + * loc_122B = ax&0xFF; + * + * ax = (ax&0xFF00) | (((bx&0xFF00)>>8)&0xFF); + * loc_117F = ax&0xFF; + * loc_11EF = ax&0xFF; + * loc_1217 = ax&0xFF; + * + * do // main copy loop + * { + * ax = bp; + * loc_12E1 = ax; + * + * if(loc_117C == 0xF8) + * { + * direction = 1; + * } + * else + * { + * direction = -1; + * } + * + * if(direction == -1) + * { + * goto label_11DC; + * } + * + * cx = loc_117F; + * + * ax = (ax&0xFF00) | (((*siPtr)&0xFF)>>cx)&0xFF; + * dx = (((ax&0xFF)<<8)&0xFF00) | (dx&0xFF); + * ax = (((ax&0xFF)<<8)&0xFF00) | (ax&0xFF); + * + * ax = (ax&0xFF00) | (((*(siPtr+1))&0xFF)>>cx)&0xFF; + * dx = (dx&0xFF00) | (ax&0xFF); + * ax = ((((((ax&0xFF00)>>8)&0xFF) | (ax&0xFF))<<8)&0xFF00) | (ax&0xFF); + * + * ax = (ax&0xFF00) | (((*(siPtr+2))&0xFF)>>cx)&0xFF; + * bx = (((ax&0xFF)<<8)&0xFF00) | (bx&0xFF); + * ax = ((((((ax&0xFF00)>>8)&0xFF) | (ax&0xFF))<<8)&0xFF00) | (ax&0xFF); + * + * ax = (ax&0xFF00) | (((*(siPtr+3))&0xFF)>>cx)&0xFF; + * bx = (bx&0xFF00) | (ax&0xFF); + * ax = ((((((ax&0xFF00)>>8)&0xFF) | (ax&0xFF))<<8)&0xFF00) | (ax&0xFF); + * + * if(ax) + * { + * bp = dx; + * ax = (ax&0xFF00) | (*diPtr)&0xFF; + * ax = (ax&0xFF00) | 8; + * + * outputBit(diPtr,0,(bp>>8)&0xFF); + * outputBit(diPtr,1,(bp&0xFF)); + * outputBit(diPtr,2,(bx>>8)&0xFF); + * outputBit(diPtr,3,(bx&0xFF)); + * } + * + * diPtr++; + * + * label_11DC: + * + * bp = loc_11DC; + * if(bp >0) + * { + * do + * { + * cx = loc_11E7; + * + * ax = (ax&0xFF00) | (((*siPtr)&0xFF)>>cx)&0xFF; + * dx = (((ax&0xFF)<<8)&0xFF00) | (dx&0xFF); + * cx = loc_11EF; + * ax = (ax&0xFF00) | (((*(siPtr+4))&0xFF)>>cx)&0xFF; + * dx = (((dx&0xFF00) | (((ax&0xFF)<<8)&0xFF00))&0xFF00) | (dx&0xFF); + * ax = (ax&0xFF00) | (((ax&0xFF) | (((dx&0xFF00)>>8)&0xFF))&0xFF); + * ax = ((ax&0xFF)<<8) | (ax&0xFF); + * + * ax = (ax&0xFF00) | (((*(siPtr+5))&0xFF)>>cx)&0xFF; + * dx = (dx&0xFF00) | (ax&0xFF); + * cx = loc_1203; + * ax = (ax&0xFF00) | (((*(siPtr+1))&0xFF)>>cx)&0xFF; + * dx = (dx&0xFF00) | ((dx&0xFF) | (ax&0xFF)); + * ax = (ax&0xFF00) | ((ax&0xFF) | dx&0xFF); + * ax = (ax&0xFF00) | ((ax&0xFF)<<8) | (ax&0xFF); + * + * ax = (ax&0xFF00) | (((*(siPtr+2))&0xFF)>>cx)&0xFF; + * bx = (((ax&0xFF)<<8)&0xFF00) | (bx&0xFF); + * cx = loc_1217; + * ax = (ax&0xFF00) | (((*(siPtr+7))&0xFF)>>cx)&0xFF; + * bx = (((bx&0xFF00) | (((ax&0xFF)<<8)&0xFF00))&0xFF00) | (bx&0xFF); + * ax = (ax&0xFF00) | ((ax&0xFF) | ((bx&0xFF00)>>8)); + * ax = (ax&0xFF00) | ((ax&0xFF)<<8) | (ax&0xFF); + * + * ax = (ax&0xFF00) | (((*(siPtr+7))&0xFF)>>cx)&0xFF; + * bx = (bx&0xFF00) | (ax&0xFF); + * cx = loc_122B; + * ax = (ax&0xFF00) | (((*(siPtr+3))&0xFF)>>cx)&0xFF; + * bx = (bx&0xFF00) | ((bx&0xFF) | (ax&0xFF)); + * ax = (ax&0xFF00) | ((ax&0xFF) | bx&0xFF); + * ax = (ax&0xFF00) | ((ax&0xFF)<<8) | (ax&0xFF); + * + * if(ax) + * { + * cx = dx; + * ax = (ax&0xFF00) | (*diPtr)&0xFF; + * ax = (ax&0xFF00) | 8; + * + * outputBit(diPtr,0,(cx>>8)&0xFF); + * outputBit(diPtr,1,(cx&0xFF)); + * outputBit(diPtr,2,(cx>>8)&0xFF); + * outputBit(diPtr,3,(cx&0xFF)); + * } + * + * siPtr += 4; + * diPtr++; + * }while(--bp); + * } + * + * if(loc_122B == 0xF8) + * { + * direction = 1; + * } + * else + * { + * direction = -1; + * } + * + * if(direction == -1) + * { + * goto label_12D9; + * } + * + * cx = loc_127A; + * + * ax = (ax&0xFF00) | (((*siPtr)&0xFF)>>cx)&0xFF; + * dx = (((ax&0xFF)<<8)&0xFF00) | (dx&0xFF); + * ax = (((ax&0xFF)<<8)&0xFF00) | (ax&0xFF); + * + * ax = (ax&0xFF00) | (((*(siPtr+1))&0xFF)>>cx)&0xFF; + * dx = (dx&0xFF00) | (ax&0xFF); + * ax = ((((((ax&0xFF00)>>8)&0xFF) | (ax&0xFF))<<8)&0xFF00) | (ax&0xFF); + * + * ax = (ax&0xFF00) | (((*(siPtr+2))&0xFF)>>cx)&0xFF; + * bx = (((ax&0xFF)<<8)&0xFF00) | (bx&0xFF); + * ax = ((((((ax&0xFF00)>>8)&0xFF) | (ax&0xFF))<<8)&0xFF00) | (ax&0xFF); + * + * ax = (ax&0xFF00) | (((*(siPtr+3))&0xFF)>>cx)&0xFF; + * bx = (bx&0xFF00) | (ax&0xFF); + * ax = ((((((ax&0xFF00)>>8)&0xFF) | (ax&0xFF))<<8)&0xFF00) | (ax&0xFF); + * + * if(ax) + * { + * bp = dx; + * ax = (ax&0xFF00) | (*diPtr)&0xFF; + * ax = (ax&0xFF00) | 8; + * + * outputBit(diPtr,0,(bp>>8)&0xFF); + * outputBit(diPtr,1,(bp&0xFF)); + * outputBit(diPtr,2,(bx>>8)&0xFF); + * outputBit(diPtr,3,(bx&0xFF)); + * } + * + * siPtr+=4; + * + * label_12D9: + * diPtr+=loc_12D9; + * siPtr+=loc_12DD; + * bp = loc_12E1; + * + * }while(--bp); + * } */ { int cols = 320; @@ -490,39 +486,34 @@ void gfxModuleData_field_60(char* sourcePtr, int width, int height, char* destPt int row; int col; int i; - uint8* pP; - short atariScreen[320*200/4]; + uint8 *pP; + short atariScreen[320 * 200 / 4]; - for(i=0;i<rows*cols/4;i++) - { - atariScreen[i] = *(int16*)sourcePtr; + for (i = 0; i < rows * cols / 4; i++) { + atariScreen[i] = *(int16 *) sourcePtr; flipShort(&atariScreen[i]); - sourcePtr+=2; + sourcePtr += 2; } - memcpy(globalAtariScreen,atariScreen,sizeof(atariScreen)); + memcpy(globalAtariScreen, atariScreen, sizeof(atariScreen)); - pP = (uint8*)destPtr; + pP = (uint8 *) destPtr; - for ( row = 0; row < rows; ++row ) - { - for ( col = 0; col < cols; ++col, ++pP ) - { + for (row = 0; row < rows; ++row) { + for (col = 0; col < cols; ++col, ++pP) { long int c, ind, b, plane; - ind = 80 * row + ( ( col >> 4 ) << 2 ); - b = 0x8000 >> ( col & 0xf ); + ind = 80 * row + ((col >> 4) << 2); + b = 0x8000 >> (col & 0xf); c = 0; - for ( plane = 0; plane < 4; ++plane ) - { - if ( b & atariScreen[ind+plane] ) - { + for (plane = 0; plane < 4; ++plane) { + if (b & atariScreen[ind + plane]) { c |= (1 << plane); } } - *pP = (uint8)c; + *pP = (uint8) c; } } } @@ -542,18 +533,16 @@ void gfxModuleData_field_60(char* sourcePtr, int width, int height, char* destPt }*/ } -void gfxModuleData_setPal256(int16* ptr) -{ +void gfxModuleData_setPal256(int16 *ptr) { int R; int G; int B; int i; - for(i = 0; i < 256;i++) - { - R=*(ptr++); - G=*(ptr++); - B=*(ptr++); + for (i = 0; i < 256; i++) { + R = *(ptr++); + G = *(ptr++); + B = *(ptr++); lpalette[i].R = R; lpalette[i].G = G; @@ -562,29 +551,27 @@ void gfxModuleData_setPal256(int16* ptr) } } -void gfxModuleData_setPal(uint8* ptr) -{ +void gfxModuleData_setPal(uint8 *ptr) { int i; int R; int G; int B; - for(i = 0; i < 16; i++) - { + for (i = 0; i < 16; i++) { #define convertRatio 36.571428571428571428571428571429 - short int atariColor = *(int16*)ptr; + short int atariColor = *(int16 *) ptr; //flipShort(&atariColor); ptr += 2; - R = (int)(convertRatio*((atariColor & 0x700) >> 8)); - G = (int)(convertRatio*((atariColor & 0x070) >> 4)); - B = (int)(convertRatio*((atariColor & 0x007))); + R = (int)(convertRatio * ((atariColor & 0x700) >> 8)); + G = (int)(convertRatio * ((atariColor & 0x070) >> 4)); + B = (int)(convertRatio * ((atariColor & 0x007))); - if(R > 0xFF) + if (R > 0xFF) R = 0xFF; - if(G> 0xFF) + if (G > 0xFF) G = 0xFF; - if(B >0xFF) + if (B > 0xFF) B = 0xFF; lpalette[i].R = R; @@ -595,52 +582,44 @@ void gfxModuleData_setPal(uint8* ptr) } } -void gfxModuleData_field_90(void) -{ +void gfxModuleData_field_90(void) { } -void gfxModuleData_gfxWaitVSync(void) -{ +void gfxModuleData_gfxWaitVSync(void) { } -void gfxModuleData_flip(void) -{ +void gfxModuleData_flip(void) { } -void gfxModuleData_field_64(char* sourceBuffer, int width, int height, char* dest, int x, int y, int color) -{ +void gfxModuleData_field_64(char *sourceBuffer, int width, int height, + char *dest, int x, int y, int color) { int i; int j; x = 0; y = 0; - for(i = 0; i < height; i++) - { - for(j = 0; j < width; j++) - { - dest[(y + i) * 320 / 4 + x + j] = sourceBuffer[i * width + j]; + for (i = 0; i < height; i++) { + for (j = 0; j < width; j++) { + dest[(y + i) * 320 / 4 + x + j] = + sourceBuffer[i * width + j]; } } } -void gfxModuleData_flipScreen(void) -{ - memcpy(globalScreen, gfxModuleData.pPage00,320*200); +void gfxModuleData_flipScreen(void) { + memcpy(globalScreen, gfxModuleData.pPage00, 320 * 200); flip(); } -void flip() -{ +void flip() { int i; byte paletteRGBA[256 * 4]; //uint8* outPtr = scaledScreen; //uint8* inPtr = globalScreen; - - for(i=0;i<256;i++) - { + for (i = 0; i < 256; i++) { paletteRGBA[i * 4 + 0] = lpalette[i].R; paletteRGBA[i * 4 + 1] = lpalette[i].G; paletteRGBA[i * 4 + 2] = lpalette[i].B; @@ -653,5 +632,4 @@ void flip() } - } // End of namespace Cruise diff --git a/engines/cruise/gfxModule.h b/engines/cruise/gfxModule.h index 7fa4a5a888..a05fc02c33 100644 --- a/engines/cruise/gfxModule.h +++ b/engines/cruise/gfxModule.h @@ -22,24 +22,22 @@ * */ -#ifndef _GFXMODULE_H_ -#define _GFXMODULE_H_ +#ifndef CRUISE_GFXMODULE_H +#define CRUISE_GFXMODULE_H namespace Cruise { -struct gfxModuleDataStruct -{ +struct gfxModuleDataStruct { int field_1; int useTandy; int useEGA; int useVGA; - uint8* pPage00; - uint8* pPage10; + uint8 *pPage00; + uint8 *pPage10; }; -struct palEntry -{ +struct palEntry { uint8 R; uint8 G; uint8 B; @@ -51,22 +49,22 @@ typedef struct palEntry palEntry; extern gfxModuleDataStruct gfxModuleData; extern palEntry lpalette[256]; -extern short globalAtariScreen[320*200/4]; +extern short globalAtariScreen[320 * 200 / 4]; -void gfxModuleData_gfxClearFrameBuffer(uint8* ptr); -void gfxModuleData_setPal(uint8* ptr); +void gfxModuleData_gfxClearFrameBuffer(uint8 * ptr); +void gfxModuleData_setPal(uint8 * ptr); void gfxModuleData_field_90(void); void gfxModuleData_gfxWaitVSync(void); void gfxModuleData_flip(void); -void gfxModuleData_field_64(char* sourceBuffer, int width, int height, char* dest, int x, int y, int color); -void gfxModuleData_gfxCopyScreen(char* sourcePtr,char* destPtr); -void gfxModuleData_field_60(char* sourcePtr, int width, int height, char* destPtr, int x, int y); +void gfxModuleData_field_64(char *sourceBuffer, int width, int height, + char *dest, int x, int y, int color); +void gfxModuleData_gfxCopyScreen(char *sourcePtr, char *destPtr); +void gfxModuleData_field_60(char *sourcePtr, int width, int height, + char *destPtr, int x, int y); void gfxModuleData_flipScreen(void); -void gfxModuleData_setPal256(int16* ptr); +void gfxModuleData_setPal256(int16 * ptr); void flip(void); - } // End of namespace Cruise #endif - diff --git a/engines/cruise/linker.cpp b/engines/cruise/linker.cpp index 465248f606..914a571394 100644 --- a/engines/cruise/linker.cpp +++ b/engines/cruise/linker.cpp @@ -26,304 +26,333 @@ namespace Cruise { -exportEntryStruct* parseExport(int* out1, int* pExportedFuncionIdx, char* buffer) -{ - char localBuffer[256]; - uint8 functionName[256]; - uint8 overlayName[256]; - char* dotPtr; - char* ptr2; - int idx; - int numExport; - exportEntryStruct* currentExportEntry; - uint8* entity1Name; - int i; - - *out1 = 0; - *pExportedFuncionIdx = 0; - - strcpyuint8(localBuffer, buffer); - dotPtr = strchr(localBuffer,'.'); - - if(dotPtr) - { - strcpyuint8(functionName,dotPtr+1); - *dotPtr = 0; - - strcpyuint8(overlayName,localBuffer); - } - else - { - overlayName[0] = 0; - - strcpyuint8(functionName,buffer); - } - - ptr2 = strchr((char*)functionName,':'); - - if(ptr2) - { - *ptr2 = 0; - - *out1 = 1; - } - - strToUpper(overlayName); - strToUpper(functionName); - if(strlen((char*)overlayName) == 0) - return NULL; - - idx = findOverlayByName2(overlayName); - - if(idx == -4) - return(NULL); - - if(overlayTable[idx].alreadyLoaded == 0) - return(NULL); - - if(!overlayTable[idx].ovlData) - return(NULL); - - numExport = overlayTable[idx].ovlData->numExport; - currentExportEntry = overlayTable[idx].ovlData->exportDataPtr; - entity1Name = overlayTable[idx].ovlData->exportNamesPtr; - - if(!entity1Name) - return(0); - - for(i=0;i<numExport;i++) - { - uint8 exportedName[256]; - uint8* name = entity1Name + currentExportEntry->offsetToName; - - strcpyuint8(exportedName,name); - strToUpper(exportedName); - - if(!strcmpuint8(functionName,exportedName)) - { - *pExportedFuncionIdx = idx; - - return(currentExportEntry); - } - - currentExportEntry++; - } - - return(NULL); -} +exportEntryStruct *parseExport(int *out1, int *pExportedFuncionIdx, + char *buffer) { + char localBuffer[256]; + uint8 functionName[256]; + uint8 overlayName[256]; + char *dotPtr; + char *ptr2; + int idx; + int numExport; + exportEntryStruct *currentExportEntry; + uint8 *entity1Name; + int i; + + *out1 = 0; + *pExportedFuncionIdx = 0; + + strcpyuint8(localBuffer, buffer); + dotPtr = strchr(localBuffer, '.'); + + if (dotPtr) { + strcpyuint8(functionName, dotPtr + 1); + *dotPtr = 0; + + strcpyuint8(overlayName, localBuffer); + } else { + overlayName[0] = 0; + + strcpyuint8(functionName, buffer); + } + + ptr2 = strchr((char *)functionName, ':'); + + if (ptr2) { + *ptr2 = 0; + + *out1 = 1; + } + + strToUpper(overlayName); + strToUpper(functionName); + if (strlen((char *)overlayName) == 0) + return NULL; + + idx = findOverlayByName2(overlayName); + + if (idx == -4) + return (NULL); + if (overlayTable[idx].alreadyLoaded == 0) + return (NULL); -int updateScriptImport(int ovlIdx) -{ - char buffer[256]; - ovlDataStruct* ovlData; - int numData3; - int size5; - int numImport; - int param; - int var_32; - ovlData3Struct* pScript; + if (!overlayTable[idx].ovlData) + return (NULL); + + numExport = overlayTable[idx].ovlData->numExport; + currentExportEntry = overlayTable[idx].ovlData->exportDataPtr; + entity1Name = overlayTable[idx].ovlData->exportNamesPtr; + + if (!entity1Name) + return (0); + + for (i = 0; i < numExport; i++) { + uint8 exportedName[256]; + uint8 *name = entity1Name + currentExportEntry->offsetToName; + + strcpyuint8(exportedName, name); + strToUpper(exportedName); + + if (!strcmpuint8(functionName, exportedName)) { + *pExportedFuncionIdx = idx; + + return (currentExportEntry); + } + + currentExportEntry++; + } + + return (NULL); +} + +int updateScriptImport(int ovlIdx) { + char buffer[256]; + ovlDataStruct *ovlData; + int numData3; + int size5; + int numImport; + int param; + int var_32; + ovlData3Struct *pScript; // char* importDataPtr; // char* namePtr; // char* linkDataPtr; - - if(!overlayTable[ovlIdx].ovlData) - return(-4); - - ovlData = overlayTable[ovlIdx].ovlData; - - numData3 = ovlData->numScripts1; - size5 = ovlData->numScripts2; - numImport = ovlData->numImport; - param = 0; - - // do it for the 2 first string types - do - { - - int i = 0; - - if(param == 0) - { - var_32 = numData3; - } - else - { - var_32 = size5; - } - - if(var_32) - { - do - { - importScriptStruct* ptrImportData; - uint8* ptrImportName; - uint8* ptrData; - - int var_22 = 0; - - if(param == 0) - { - pScript = getOvlData3Entry(ovlIdx, i); - } - else - { - pScript = scriptFunc1Sub2(ovlIdx, i); - } - - ptrImportData = (importScriptStruct*) (pScript->dataPtr + pScript->offsetToImportData); // import data - ptrImportName = pScript->dataPtr + pScript->offsetToImportName; // import name - ptrData = pScript->dataPtr; - - var_22 = 0; - - if(pScript->numImport > 0) - { - int counter = pScript->numImport; - - do - { - int param2 = ptrImportData->type; - - if(param2 != 70) - { - exportEntryStruct* ptrDest2; - int out1; - int out2; - - strcpyuint8(buffer,ptrImportName + ptrImportData->offsetToName); - ptrDest2 = parseExport(&out1,&out2,buffer); - - if(ptrDest2 && out2) - { - int temp = ptrImportData->offset; - if(out1) //is sub function... (ie 'invent.livre:s') - { - uint8* ptr = ptrData + temp; - - *(ptr+1) = out2; - *(int16*)(ptr+2) = ptrDest2->idx; - - flipShort((int16*)(ptr+2)); - } - else - { - if(param2 == 20 || param2 == 30 || param2 == 40 || param2 == 50 ) // this patch a double push - { - uint8* ptr = ptrData + temp; - - *(ptr+1) = 0; - *(ptr+2) = out2; // update the overlay number - - *(int16*)(ptr+4) = ptrDest2->idx; - - flipShort((int16*)(ptr+4)); - } - else - { - int var_4 = ptrDest2->var4; - - if(var_4&1) - { - param2 = 8; - } - else - { - param2 = 16; - } - - if(var_4>=0 && var_4<=3) - { - param2 |= 5; - } - else - { - param2 |= 6; - } - - *(ptrData + temp) = param2; - *(ptrData + temp + 1 ) = out2; - - *(int16*)(ptrData + temp + 2) = ptrDest2->idx; - - flipShort((int16*)(ptrData + temp + 2)); - } - } - } - } - - ptrImportData++; - }while(--counter); - } - - }while(++i<var_32); - - } - - }while(++param<2); - - if(ovlData->importDataPtr && ovlData->importNamePtr && numImport) - { - int numImport2 = numImport; - int i; - - for(i=0;i<numImport2;i++) - { - int out1; - int foundExportIdx; - exportEntryStruct* pFoundExport; - int linkType; - int linkEntryIdx; - - strcpyuint8(buffer,ovlData->importNamePtr + ovlData->importDataPtr[i].nameOffset); - - pFoundExport = parseExport(&out1,&foundExportIdx,buffer); - - linkType = ovlData->importDataPtr[i].linkType; - linkEntryIdx = ovlData->importDataPtr[i].linkIdx; - - if(pFoundExport && foundExportIdx) - { - switch(linkType) - { - case 0: // var - { - ovlData->linkDataPtr[linkEntryIdx].varIdx = foundExportIdx; - ovlData->linkDataPtr[linkEntryIdx].varNameOffset = pFoundExport->offsetToName; - break; - } - case 1: // string - { - ovlData->linkDataPtr[linkEntryIdx].stringIdx = foundExportIdx; - ovlData->linkDataPtr[linkEntryIdx].stringNameOffset = pFoundExport->offsetToName; - break; - } - case 2: // proc - { - ovlData->linkDataPtr[linkEntryIdx].procIdx = foundExportIdx; - ovlData->linkDataPtr[linkEntryIdx].procNameOffset = pFoundExport->offsetToName; - break; - } - } - } - } - } - - return(0); + + if (!overlayTable[ovlIdx].ovlData) + return (-4); + + ovlData = overlayTable[ovlIdx].ovlData; + + numData3 = ovlData->numScripts1; + size5 = ovlData->numScripts2; + numImport = ovlData->numImport; + param = 0; + + // do it for the 2 first string types + do { + + int i = 0; + + if (param == 0) { + var_32 = numData3; + } else { + var_32 = size5; + } + + if (var_32) { + do { + importScriptStruct *ptrImportData; + uint8 *ptrImportName; + uint8 *ptrData; + + int var_22 = 0; + + if (param == 0) { + pScript = getOvlData3Entry(ovlIdx, i); + } else { + pScript = scriptFunc1Sub2(ovlIdx, i); + } + + ptrImportData = (importScriptStruct *) (pScript->dataPtr + pScript->offsetToImportData); // import data + ptrImportName = pScript->dataPtr + pScript->offsetToImportName; // import name + ptrData = pScript->dataPtr; + + var_22 = 0; + + if (pScript->numImport > 0) { + int counter = pScript->numImport; + + do { + int param2 = + ptrImportData->type; + + if (param2 != 70) { + exportEntryStruct + * ptrDest2; + int out1; + int out2; + + strcpyuint8(buffer, + ptrImportName + + ptrImportData-> + offsetToName); + ptrDest2 = + parseExport(&out1, + &out2, buffer); + + if (ptrDest2 && out2) { + int temp = + ptrImportData-> + offset; + if (out1) //is sub function... (ie 'invent.livre:s') + { + uint8 *ptr = ptrData + temp; + + *(ptr + + 1) + = + out2; + *(int16 + *) + (ptr + + + 2) + = + ptrDest2-> + idx; + + flipShort + ( + (int16 + *) + (ptr + 2)); + } else { + if (param2 == 20 || param2 == 30 || param2 == 40 || param2 == 50) // this patch a double push + { + uint8 + * + ptr + = + ptrData + + + temp; + + *(ptr + 1) = 0; + *(ptr + 2) = out2; // update the overlay number + + *(int16 *) (ptr + 4) = ptrDest2->idx; + + flipShort + ( + (int16 + *) + (ptr + 4)); + } else { + int var_4 = ptrDest2->var4; + + if (var_4 & 1) { + param2 + = + 8; + } else { + param2 + = + 16; + } + + if (var_4 >= 0 && var_4 <= 3) { + param2 + |= + 5; + } else { + param2 + |= + 6; + } + + *(ptrData + temp) = param2; + *(ptrData + temp + 1) = out2; + + *(int16 *) (ptrData + temp + 2) = ptrDest2->idx; + + flipShort + ( + (int16 + *) + (ptrData + + + temp + + + 2)); + } + } + } + } + + ptrImportData++; + } while (--counter); + } + + } while (++i < var_32); + + } + + } while (++param < 2); + + if (ovlData->importDataPtr && ovlData->importNamePtr && numImport) { + int numImport2 = numImport; + int i; + + for (i = 0; i < numImport2; i++) { + int out1; + int foundExportIdx; + exportEntryStruct *pFoundExport; + int linkType; + int linkEntryIdx; + + strcpyuint8(buffer, + ovlData->importNamePtr + + ovlData->importDataPtr[i].nameOffset); + + pFoundExport = + parseExport(&out1, &foundExportIdx, buffer); + + linkType = ovlData->importDataPtr[i].linkType; + linkEntryIdx = ovlData->importDataPtr[i].linkIdx; + + if (pFoundExport && foundExportIdx) { + switch (linkType) { + case 0: // var + { + ovlData-> + linkDataPtr[linkEntryIdx]. + varIdx = foundExportIdx; + ovlData-> + linkDataPtr[linkEntryIdx]. + varNameOffset = + pFoundExport->offsetToName; + break; + } + case 1: // string + { + ovlData-> + linkDataPtr[linkEntryIdx]. + stringIdx = foundExportIdx; + ovlData-> + linkDataPtr[linkEntryIdx]. + stringNameOffset = + pFoundExport->offsetToName; + break; + } + case 2: // proc + { + ovlData-> + linkDataPtr[linkEntryIdx]. + procIdx = foundExportIdx; + ovlData-> + linkDataPtr[linkEntryIdx]. + procNameOffset = + pFoundExport->offsetToName; + break; + } + } + } + } + } + + return (0); } // check that the newly loaded isn't used by the already loaded overlays -void updateAllScriptsImports(void) -{ - int i; - - for(i=0;i<90;i++) - { - if(overlayTable[i].ovlData && overlayTable[i].alreadyLoaded) - { - updateScriptImport(i); - } - } +void updateAllScriptsImports(void) { + int i; + + for (i = 0; i < 90; i++) { + if (overlayTable[i].ovlData && overlayTable[i].alreadyLoaded) { + updateScriptImport(i); + } + } } } // End of namespace Cruise diff --git a/engines/cruise/linker.h b/engines/cruise/linker.h index 13c40bbd3a..1f3cd045f2 100644 --- a/engines/cruise/linker.h +++ b/engines/cruise/linker.h @@ -22,13 +22,12 @@ * */ -#ifndef _LINKER_H_ -#define _LINKER_H_ +#ifndef CRUISE_LINKER_H +#define CRUISE_LINKER_H namespace Cruise { void updateAllScriptsImports(void); -} // End of namespace Cruise - +} // End of namespace Cruise #endif diff --git a/engines/cruise/mainDraw.cpp b/engines/cruise/mainDraw.cpp index ae189dd8aa..6804075a07 100644 --- a/engines/cruise/mainDraw.cpp +++ b/engines/cruise/mainDraw.cpp @@ -29,45 +29,40 @@ namespace Cruise { int currentTransparent; -struct drawVar1Struct -{ - struct drawVar1Struct* next; +struct drawVar1Struct { + struct drawVar1Struct *next; short int field_2; short int field_4; short int field_6; short int field_8; - cellStruct* field_A; + cellStruct *field_A; }; typedef struct drawVar1Struct drawVar1Struct; drawVar1Struct drawVar1; +void mainDraw6(void) { + drawVar1Struct *pCurrent = drawVar1.next; -void mainDraw6(void) -{ - drawVar1Struct* pCurrent = drawVar1.next; + while (pCurrent) { + drawVar1Struct *next = pCurrent->next; - while(pCurrent) - { - drawVar1Struct* next = pCurrent->next; - - if(pCurrent->field_6 == 5) - { - Op_InitializeStateSub(pCurrent->field_2, pCurrent->field_4, pCurrent->field_8); - } - else - { - setObjectPosition(pCurrent->field_2, pCurrent->field_4, pCurrent->field_6, pCurrent->field_8); + if (pCurrent->field_6 == 5) { + Op_InitializeStateSub(pCurrent->field_2, + pCurrent->field_4, pCurrent->field_8); + } else { + setObjectPosition(pCurrent->field_2, pCurrent->field_4, + pCurrent->field_6, pCurrent->field_8); } - if(pCurrent->field_A->nextAnimDelay < 0) - { + if (pCurrent->field_A->nextAnimDelay < 0) { objectParamsQuery params; - getMultipleObjectParam(pCurrent->field_2, pCurrent->field_4, ¶ms); + getMultipleObjectParam(pCurrent->field_2, + pCurrent->field_4, ¶ms); - pCurrent->field_A->currentAnimDelay = params.var6-1; + pCurrent->field_A->currentAnimDelay = params.var6 - 1; } free(pCurrent); @@ -76,9 +71,8 @@ void mainDraw6(void) } } -void flipScreen(void) -{ - uint8* swapPtr; +void flipScreen(void) { + uint8 *swapPtr; swapPtr = gfxModuleData.pPage00; gfxModuleData.pPage00 = gfxModuleData.pPage10; @@ -87,7 +81,7 @@ void flipScreen(void) gfxModuleData_flipScreen(); /*memcpy(globalAtariScreen, gfxModuleData.pPage00, 16000); - convertAtariToRaw(gfxModuleData.pPage00,globalScreen,200,320);*/ + * convertAtariToRaw(gfxModuleData.pPage00,globalScreen,200,320); */ } int spriteX1; @@ -95,60 +89,59 @@ int spriteX2; int spriteY1; int spriteY2; -char* polyOutputBuffer; +char *polyOutputBuffer; -void pixel(int x, int y, char color) -{ - if(x >= 0 && x < 320 && y >= 0 && y < 200) - polyOutputBuffer[320*y+x] = color; +void pixel(int x, int y, char color) { + if (x >= 0 && x < 320 && y >= 0 && y < 200) + polyOutputBuffer[320 * y + x] = color; } // this function checks if the dataPtr is not 0, else it retrives the data for X, Y, scale and DataPtr again (OLD: mainDrawSub1Sub1) -void getPolyData(int fileIndex, int X, int Y, int *outScale, int *outY, int *outX, char **outDataPtr, int scale, char* dataPtr) -{ - if(*(uint16*) dataPtr == 0) - { - uint16 newFileIndex; - uint16 newX; - char* newDataPtr; // this one is quite useless - uint16 newY; +void getPolyData(int fileIndex, int X, int Y, int *outScale, int *outY, + int *outX, char **outDataPtr, int scale, char *dataPtr) { + if (*(uint16 *) dataPtr == 0) { + uint16 newFileIndex; + uint16 newX; + char *newDataPtr; // this one is quite useless + uint16 newY; - dataPtr += 2; - newFileIndex = *(uint16*) dataPtr; + dataPtr += 2; + newFileIndex = *(uint16 *) dataPtr; flipShort(&newFileIndex); dataPtr += 2; - newX = *(uint16*) dataPtr; + newX = *(uint16 *) dataPtr; flipShort(&newX); - newDataPtr = dataPtr; // useless + newDataPtr = dataPtr; // useless - newY = *(uint16*) (newDataPtr + 2); + newY = *(uint16 *) (newDataPtr + 2); flipShort(&newY); newFileIndex += fileIndex; - if(true /*newFileIndex >= 0*/) // FIXME: comparison is always true due to limited range of data type + if (true /*newFileIndex >= 0 */ ) // FIXME: comparison is always true due to limited range of data type { - if(filesDatabase[newFileIndex].resType == 0 && filesDatabase[newFileIndex].subData.ptr) - { - dataPtr = (char*)filesDatabase[newFileIndex].subData.ptr; + if (filesDatabase[newFileIndex].resType == 0 + && filesDatabase[newFileIndex].subData.ptr) { + dataPtr = + (char *)filesDatabase[newFileIndex]. + subData.ptr; } } scale = -scale; - X -= newX; - Y -= newY; + X -= newX; + Y -= newY; } *outDataPtr = dataPtr; - *outX = X; - *outY = Y; - *outScale = scale; + *outX = X; + *outY = Y; + *outScale = scale; } -int upscaleValue(int value, int scale) -{ +int upscaleValue(int value, int scale) { return (((value * scale) << 8) / 2); } @@ -170,83 +163,78 @@ int16 polyBuffer3[404]; int16 polyBuffer4[512]; // this function fills the sizeTable for the poly (OLD: mainDrawSub1Sub2) -void getPolySize(int positionX, int positionY, int scale, int sizeTable[4], unsigned char* dataPtr) -{ +void getPolySize(int positionX, int positionY, int scale, int sizeTable[4], + unsigned char *dataPtr) { int upperBorder; int lowerBorder; m_flipLeftRight = 0; - if(scale < 0) // flip left right + if (scale < 0) // flip left right { m_flipLeftRight = 1; - scale = -scale; + scale = -scale; } - // X1 upperBorder = *(dataPtr + 3); - if(m_flipLeftRight) - { + if (m_flipLeftRight) { upperBorder = -upperBorder; } - - upperBorder = (upscaleValue(upperBorder, scale) + 0x8000) >> 16; - upperBorder = -upperBorder; - lowerBorder = upperBorder; + + upperBorder = (upscaleValue(upperBorder, scale) + 0x8000) >> 16; + upperBorder = -upperBorder; + lowerBorder = upperBorder; // X2 - upperBorder = *(dataPtr + 1); + upperBorder = *(dataPtr + 1); upperBorder -= *(dataPtr + 3); - if(m_flipLeftRight) - { + if (m_flipLeftRight) { upperBorder = -upperBorder; } - upperBorder = (upscaleValue(upperBorder, scale) + 0x8000) >> 16; + upperBorder = (upscaleValue(upperBorder, scale) + 0x8000) >> 16; - if(upperBorder < lowerBorder) // exchange borders if lower > upper + if (upperBorder < lowerBorder) // exchange borders if lower > upper { - int temp = upperBorder; + int temp = upperBorder; upperBorder = lowerBorder; lowerBorder = temp; } - sizeTable[0] = lowerBorder; // left - sizeTable[1] = upperBorder; // right + sizeTable[0] = lowerBorder; // left + sizeTable[1] = upperBorder; // right // Y1 - upperBorder = *(dataPtr + 4); - upperBorder = (upscaleValue(upperBorder, scale) + 0x8000) >> 16; - upperBorder = -upperBorder; - lowerBorder = upperBorder; + upperBorder = *(dataPtr + 4); + upperBorder = (upscaleValue(upperBorder, scale) + 0x8000) >> 16; + upperBorder = -upperBorder; + lowerBorder = upperBorder; // Y2 - upperBorder = *(dataPtr + 2); + upperBorder = *(dataPtr + 2); upperBorder -= *(dataPtr + 4); - upperBorder = (upscaleValue(upperBorder, scale) + 0x8000) >> 16; + upperBorder = (upscaleValue(upperBorder, scale) + 0x8000) >> 16; - if(upperBorder < lowerBorder) // exchange borders if lower > upper + if (upperBorder < lowerBorder) // exchange borders if lower > upper { - int temp = upperBorder; + int temp = upperBorder; upperBorder = lowerBorder; lowerBorder = temp; } - sizeTable[2] = lowerBorder; // bottom - sizeTable[3] = upperBorder; // top + sizeTable[2] = lowerBorder; // bottom + sizeTable[3] = upperBorder; // top } -void blitPolyMode1(char* dest, char* ptr, int16* buffer, char color) -{ +void blitPolyMode1(char *dest, char *ptr, int16 * buffer, char color) { } -void blitPolyMode2(char* dest, int16* buffer, char color) -{ +void blitPolyMode2(char *dest, int16 * buffer, char color) { } int polySize1; @@ -255,31 +243,32 @@ int polySize3; int polySize4; int polyVar1; -int16* polyVar2; +int16 *polyVar2; -void drawPolySub(void) -{ +void drawPolySub(void) { int i; - for(i = 0; i < polyVar1; i++) - { - line(polyBuffer4[i * 2], polyBuffer4[i * 2 + 1], polyBuffer4[(i + 1) * 2], polyBuffer4[(i + 1) * 2 + 1], m_color & 0xF); + for (i = 0; i < polyVar1; i++) { + line(polyBuffer4[i * 2], polyBuffer4[i * 2 + 1], + polyBuffer4[(i + 1) * 2], polyBuffer4[(i + 1) * 2 + 1], + m_color & 0xF); } fillpoly(polyBuffer4, polyVar1, m_color & 0xF); } -char* drawPolyMode1(char* dataPointer, int linesToDraw) -{ +char *drawPolyMode1(char *dataPointer, int linesToDraw) { int index; - int16* pBufferDest; + int16 *pBufferDest; - polyVar1 = linesToDraw; + polyVar1 = linesToDraw; pBufferDest = &polyBuffer4[polyVar1 * 2]; - index = *(dataPointer++); + index = *(dataPointer++); - polySize1 = polySize2 = pBufferDest[-2] = pBufferDest[-2 + linesToDraw * 2] = polyBuffer2[index * 2]; - polySize1 = polySize2 = pBufferDest[-1] = pBufferDest[-1 + linesToDraw * 2] = polyBuffer2[(index * 2) + 1]; + polySize1 = polySize2 = pBufferDest[-2] = + pBufferDest[-2 + linesToDraw * 2] = polyBuffer2[index * 2]; + polySize1 = polySize2 = pBufferDest[-1] = + pBufferDest[-1 + linesToDraw * 2] = polyBuffer2[(index * 2) + 1]; linesToDraw--; @@ -287,90 +276,85 @@ char* drawPolyMode1(char* dataPointer, int linesToDraw) polyVar2 = pBufferDest; - do - { + do { int value; index = *(dataPointer++); - value = pBufferDest[-2] = pBufferDest[-2 + polyVar1 * 2] = polyBuffer2[index * 2]; - - if(value < polySize1) - { + value = pBufferDest[-2] = pBufferDest[-2 + polyVar1 * 2] = + polyBuffer2[index * 2]; + + if (value < polySize1) { polySize1 = value; } - if(value > polySize2) - { + if (value > polySize2) { polySize2 = value; } - value = pBufferDest[-1] = pBufferDest[-1 + polyVar1 * 2] = polyBuffer2[(index * 2) + 1]; - - if(value > polySize4) - { + value = pBufferDest[-1] = pBufferDest[-1 + polyVar1 * 2] = + polyBuffer2[(index * 2) + 1]; + + if (value > polySize4) { polySize4 = value; } - if(value < polySize3) - { + if (value < polySize3) { polySize3 = value; polyVar2 = pBufferDest - 4; } pBufferDest -= 2; - } while(--linesToDraw); + } while (--linesToDraw); drawPolySub(); return dataPointer; } -char* drawPolyMode2(char* dataPointer, int linesToDraw) -{ +char *drawPolyMode2(char *dataPointer, int linesToDraw) { int index; - int16* pBufferDest; + int16 *pBufferDest; pBufferDest = polyBuffer4; - polyVar1 = linesToDraw; - polyVar2 = polyBuffer4; - index = *(dataPointer++); + polyVar1 = linesToDraw; + polyVar2 = polyBuffer4; + index = *(dataPointer++); - polySize1 = polySize2 = pBufferDest[0] = pBufferDest[linesToDraw * 2] = polyBuffer2[index * 2]; - polySize1 = polySize2 = pBufferDest[1] = pBufferDest[linesToDraw * 2 + 1] = polyBuffer2[(index * 2) + 1]; + polySize1 = polySize2 = pBufferDest[0] = pBufferDest[linesToDraw * 2] = + polyBuffer2[index * 2]; + polySize1 = polySize2 = pBufferDest[1] = + pBufferDest[linesToDraw * 2 + 1] = polyBuffer2[(index * 2) + 1]; linesToDraw--; pBufferDest += 2; - do - { + do { int value; index = *(dataPointer++); - value = pBufferDest[0] = pBufferDest[polyVar1 * 2] = polyBuffer2[index * 2]; - - if(value < polySize1) - { + value = pBufferDest[0] = pBufferDest[polyVar1 * 2] = + polyBuffer2[index * 2]; + + if (value < polySize1) { polySize1 = value; } - if(value > polySize2) - { + if (value > polySize2) { polySize2 = value; } - value = pBufferDest[1] = pBufferDest[polyVar1 * 2 + 1] = polyBuffer2[(index * 2) + 1]; + value = pBufferDest[1] = pBufferDest[polyVar1 * 2 + 1] = + polyBuffer2[(index * 2) + 1]; - if(value > polySize4) - { + if (value > polySize4) { polySize4 = value; } - if(value < polySize3) - { + if (value < polySize3) { polySize3 = value; polyVar2 = pBufferDest; } pBufferDest += 2; - } while(--linesToDraw); + } while (--linesToDraw); drawPolySub(); @@ -378,86 +362,82 @@ char* drawPolyMode2(char* dataPointer, int linesToDraw) } // this function builds the poly model and then calls the draw functions (OLD: mainDrawSub1Sub5) -void buildPolyModel(int positionX, int positionY, int scale, char* ptr2, char* destBuffer, char* dataPtr) -{ - int counter = 0; // numbers of coordinates to process - int startX = 0; // first X in model - int startY = 0; // first Y in model - int x = 0; // current X - int y = 0; // current Y - int offsetXinModel = 0; // offset of the X value in the model - int offsetYinModel = 0; // offset of the Y value in the model - unsigned char* dataPointer = (unsigned char*)dataPtr; - int16* ptrPoly_1_Buf = polyBuffer; - int16* ptrPoly_2_Buf; - polyOutputBuffer = destBuffer; // global +void buildPolyModel(int positionX, int positionY, int scale, char *ptr2, + char *destBuffer, char *dataPtr) { + int counter = 0; // numbers of coordinates to process + int startX = 0; // first X in model + int startY = 0; // first Y in model + int x = 0; // current X + int y = 0; // current Y + int offsetXinModel = 0; // offset of the X value in the model + int offsetYinModel = 0; // offset of the Y value in the model + unsigned char *dataPointer = (unsigned char *)dataPtr; + int16 *ptrPoly_1_Buf = polyBuffer; + int16 *ptrPoly_2_Buf; + polyOutputBuffer = destBuffer; // global m_flipLeftRight = 0; m_useSmallScale = 0; - m_lowerX = *(dataPointer + 3); - m_lowerY = *(dataPointer + 4); + m_lowerX = *(dataPointer + 3); + m_lowerY = *(dataPointer + 4); - if(scale < 0) - { - scale = -scale; // flip left right + if (scale < 0) { + scale = -scale; // flip left right m_flipLeftRight = 1; } - if(scale < 0x180) // If scale is smaller than 384 + if (scale < 0x180) // If scale is smaller than 384 { m_useSmallScale = 1; - m_scaleValue = scale << 1; // double scale - } - else - { + m_scaleValue = scale << 1; // double scale + } else { m_scaleValue = scale; } dataPointer += 5; m_coordCount = (*(dataPointer++)) + 1; // original uses +1 here but its later substracted again, we could skip it - m_first_X = *(dataPointer++); - m_first_Y = *(dataPointer++); - startX = m_lowerX - m_first_X; - startY = m_lowerY - m_first_Y; + m_first_X = *(dataPointer++); + m_first_Y = *(dataPointer++); + startX = m_lowerX - m_first_X; + startY = m_lowerY - m_first_Y; - if(m_useSmallScale) - { + if (m_useSmallScale) { startX >>= 1; startY >>= 1; } - - if(m_flipLeftRight) - { + + if (m_flipLeftRight) { startX = -startX; } /* - NOTE: - - The original code continues here with using X, Y instead of startX and StartY. - - Original code: - positionX -= (upscaleValue(startX, m_scaleValue) + 0x8000) >> 16; - positionY -= (upscaleValue(startX, m_scaleValue) + 0x8000) >> 16; - */ - + * NOTE: + * + * The original code continues here with using X, Y instead of startX and StartY. + * + * Original code: + * positionX -= (upscaleValue(startX, m_scaleValue) + 0x8000) >> 16; + * positionY -= (upscaleValue(startX, m_scaleValue) + 0x8000) >> 16; + */ + // get coordinates from data - startX = positionX - ((upscaleValue(startX, m_scaleValue) + 0x8000) >> 16); - startY = positionY - ((upscaleValue(startY, m_scaleValue) + 0x8000) >> 16); - + startX = + positionX - ((upscaleValue(startX, m_scaleValue) + 0x8000) >> 16); + startY = + positionY - ((upscaleValue(startY, m_scaleValue) + 0x8000) >> 16); + ptrPoly_1_Buf[0] = 0; ptrPoly_1_Buf[1] = 0; - ptrPoly_1_Buf += 2; - counter = m_coordCount - 1 - 1; // skip the first pair, we already have the values + ptrPoly_1_Buf += 2; + counter = m_coordCount - 1 - 1; // skip the first pair, we already have the values - do - { + do { x = *(dataPointer++) - m_first_X; y = *(dataPointer++) - m_first_Y; - - if(m_useSmallScale) // shrink all coordinates by factor 2 if a scale smaller than 384 is used + + if (m_useSmallScale) // shrink all coordinates by factor 2 if a scale smaller than 384 is used { x >>= 1; y >>= 1; @@ -466,232 +446,213 @@ void buildPolyModel(int positionX, int positionY, int scale, char* ptr2, char* d ptrPoly_1_Buf[0] = offsetXinModel - x; ptrPoly_1_Buf++; offsetXinModel = x; - + ptrPoly_1_Buf[0] = -(offsetYinModel - y); ptrPoly_1_Buf++; offsetYinModel = y; - } while(--counter); + } while (--counter); // scale and adjust coordinates with offset (using two polybuffers by doing that) /* - NOTE: Is there a need for having two, a scaled and unscaled polybuffer? - */ - + * NOTE: Is there a need for having two, a scaled and unscaled polybuffer? + */ + ptrPoly_2_Buf = polyBuffer; ptrPoly_1_Buf = polyBuffer2; - counter = m_coordCount - 1; // reset counter // process first pair two - m_current_X = 0; - m_current_Y = 0; + counter = m_coordCount - 1; // reset counter // process first pair two + m_current_X = 0; + m_current_Y = 0; - do - { + do { x = ptrPoly_2_Buf[0]; - - if(m_flipLeftRight == 0) - { - x = -x; - } + if (m_flipLeftRight == 0) { + x = -x; + } ////////////////// - m_current_X += upscaleValue(x, m_scaleValue); - ptrPoly_1_Buf[0] = ((m_current_X + 0x8000) >> 16) + startX; // adjust X value with start offset + m_current_X += upscaleValue(x, m_scaleValue); + ptrPoly_1_Buf[0] = ((m_current_X + 0x8000) >> 16) + startX; // adjust X value with start offset + + m_current_Y += upscaleValue(ptrPoly_2_Buf[1], m_scaleValue); + ptrPoly_1_Buf[1] = ((m_current_Y + 0x8000) >> 16) + startY; // adjust Y value with start offset - m_current_Y += upscaleValue(ptrPoly_2_Buf[1], m_scaleValue); - ptrPoly_1_Buf[1] = ((m_current_Y + 0x8000) >> 16) + startY; // adjust Y value with start offset - ///////////////// ptrPoly_1_Buf += 2; ptrPoly_2_Buf += 2; - } while(--counter); + } while (--counter); // position of the dataPointer is m_coordCount * 2 - do - { + do { int linesToDraw = *dataPointer++; - if(linesToDraw > 1) // if value not zero + if (linesToDraw > 1) // if value not zero { uint16 minimumScale; - m_color = *dataPointer; // color + m_color = *dataPointer; // color dataPointer += 2; - minimumScale = *(uint16*) (dataPointer); + minimumScale = *(uint16 *) (dataPointer); dataPointer += 2; flipShort(&minimumScale); - if(minimumScale > scale) // if the scale is too small, for the model to be drawn ... - { - dataPointer += linesToDraw; // ... skip ahead - } - else + if (minimumScale > scale) // if the scale is too small, for the model to be drawn ... { - if(m_flipLeftRight) - { - dataPointer = (unsigned char*)drawPolyMode1((char*)dataPointer, linesToDraw); - } - else - { - dataPointer = (unsigned char*)drawPolyMode2((char*)dataPointer, linesToDraw); + dataPointer += linesToDraw; // ... skip ahead + } else { + if (m_flipLeftRight) { + dataPointer = + (unsigned char *) + drawPolyMode1((char *)dataPointer, + linesToDraw); + } else { + dataPointer = + (unsigned char *) + drawPolyMode2((char *)dataPointer, + linesToDraw); } - if(destBuffer) - { - if(ptr2) - { - blitPolyMode1(destBuffer, ptr2, polyBuffer3, m_color & 0xF); - } - else - { - blitPolyMode2(destBuffer, polyBuffer3, m_color & 0xF); + if (destBuffer) { + if (ptr2) { + blitPolyMode1(destBuffer, ptr2, + polyBuffer3, + m_color & 0xF); + } else { + blitPolyMode2(destBuffer, + polyBuffer3, + m_color & 0xF); } } } - } - else - { + } else { dataPointer += 4; } - } while(*dataPointer != 0xFF); + } while (*dataPointer != 0xFF); } // draw poly sprite (OLD: mainDrawSub1) -void mainDrawPolygons(int fileIndex, cellStruct* pObject, int X, int scale, int Y, char* destBuffer, char* dataPtr) -{ - int newX; - int newY; - int newScale; - char* newDataPtr; - char* ptr2; // unused - int var_8; // unused +void mainDrawPolygons(int fileIndex, cellStruct *pObject, int X, int scale, + int Y, char *destBuffer, char *dataPtr) { + int newX; + int newY; + int newScale; + char *newDataPtr; + char *ptr2; // unused + int var_8; // unused - int sizeTable[4]; // 0 = left, 1 = right, 2 = bottom, 3 = top + int sizeTable[4]; // 0 = left, 1 = right, 2 = bottom, 3 = top // this function checks if the dataPtr is not 0, else it retrives the data for X, Y, scale and DataPtr again (OLD: mainDrawSub1Sub1) - getPolyData(fileIndex, X, Y, &newScale, &newY, &newX, &newDataPtr, scale, dataPtr); - + getPolyData(fileIndex, X, Y, &newScale, &newY, &newX, &newDataPtr, + scale, dataPtr); + // this function fills the sizeTable for the poly (OLD: mainDrawSub1Sub2) - getPolySize(newX, newY, newScale, sizeTable, (unsigned char*)newDataPtr); + getPolySize(newX, newY, newScale, sizeTable, + (unsigned char *)newDataPtr); - spriteX2 = sizeTable[0] - 2; // left border + spriteX2 = sizeTable[0] - 2; // left border spriteX1 = sizeTable[1] + 18; // right border - spriteY2 = sizeTable[2] - 2; // bottom border - spriteY1 = sizeTable[3] + 2; // top border - + spriteY2 = sizeTable[2] - 2; // bottom border + spriteY1 = sizeTable[3] + 2; // top border + /* if (X == 28 && Y == 80 && scale == 1024) { printf("0--> x1: %i, y1: %i, x2: %i, y2: %i\n", sizeTable[1], sizeTable[3], sizeTable[0], sizeTable[2]); printf("1--> x1: %i, y1: %i, x2: %i, y2: %i\n", spriteX1, spriteY1, spriteX2, spriteY2); } */ - if(spriteX2 >= 320) + if (spriteX2 >= 320) return; - if(spriteX1 < 0) + if (spriteX1 < 0) return; - if(spriteY2 >= 200) + if (spriteY2 >= 200) return; - if(spriteY1 < 0) + if (spriteY1 < 0) return; - if(spriteX2 < 0) - { + if (spriteX2 < 0) { spriteX2 = 0; } - if(spriteX1 > 320) - { + if (spriteX1 > 320) { spriteX1 = 320; } - if(spriteY2 < 0) - { + if (spriteY2 < 0) { spriteY2 = 0; } - if(spriteY1 > 200) - { + if (spriteY1 > 200) { spriteY1 = 200; } - if(spriteX1 == spriteX2) + if (spriteX1 == spriteX2) return; - if(spriteY1 == spriteY2) + if (spriteY1 == spriteY2) return; ptr2 = NULL; var_8 = 0; - if(pObject) - { - cellStruct* pCurrentObject = pObject; + if (pObject) { + cellStruct *pCurrentObject = pObject; - do - { - if(pCurrentObject->type == 2) - { + do { + if (pCurrentObject->type == 2) { // ASSERT(0); } pCurrentObject = pCurrentObject->next; - } while(pCurrentObject); + } while (pCurrentObject); } - // this function builds the poly model and then calls the draw functions (OLD: mainDrawSub1Sub5) buildPolyModel(newX, newY, newScale, ptr2, destBuffer, newDataPtr); } -void mainSprite(int globalX, int globalY, gfxEntryStruct* pGfxPtr, uint8* ouputPtr, int newColor, int idx) -{ +void mainSprite(int globalX, int globalY, gfxEntryStruct *pGfxPtr, + uint8 *ouputPtr, int newColor, int idx) { // this is used for font only - if(pGfxPtr) - { - uint8* initialOuput; - uint8* output; + if (pGfxPtr) { + uint8 *initialOuput; + uint8 *output; int i; int j; int x; int y; - uint8* ptr = pGfxPtr->imagePtr; + uint8 *ptr = pGfxPtr->imagePtr; int height = pGfxPtr->height; - int width = pGfxPtr->width; + int width = pGfxPtr->width; - if(globalY < 0) - { + if (globalY < 0) { globalY = 0; } - if(globalY + pGfxPtr->height >= 198) - { + if (globalY + pGfxPtr->height >= 198) { globalY = 198 - pGfxPtr->height; } - initialOuput = ouputPtr + (globalY*320) + globalX; + initialOuput = ouputPtr + (globalY * 320) + globalX; y = globalY; x = globalX; - for(i = 0; i < height; i++) - { + for (i = 0; i < height; i++) { output = initialOuput + 320 * i; - - for(j = 0; j < width; j++) - { + + for (j = 0; j < width; j++) { uint8 color = *(ptr++); - if(color) - { - if((x >= 0) && (x < 320) && (y >= 0) && (y < 200)) - { - if(color == 1) - { + if (color) { + if ((x >= 0) && (x < 320) && (y >= 0) + && (y < 200)) { + if (color == 1) { *output = (uint8) 0; - } - else - { - *output = (uint8) newColor; + } else { + *output = + (uint8) newColor; } } } @@ -701,37 +662,35 @@ void mainSprite(int globalX, int globalY, gfxEntryStruct* pGfxPtr, uint8* ouputP } } -void mainDrawSub4(int objX1, int var_6, cellStruct* currentObjPtr, char* data1, int objY2, int objX2, char* output, char* data2) -{ +void mainDrawSub4(int objX1, int var_6, cellStruct *currentObjPtr, + char *data1, int objY2, int objX2, char *output, char *data2) { int x = 0; int y = 0; - for(y = 0; y < var_6; y++) - { - for(x = 0; x < (objX1 * 8); x++) - { + for (y = 0; y < var_6; y++) { + for (x = 0; x < (objX1 * 8); x++) { uint8 color = (data1[0]); data1++; - if((x + objX2) >= 0 && (x + objX2) < 320 && (y + objY2) >= 0 && (y + objY2) < 200) - { - if(color != currentTransparent) - { - output[320 * (y + objY2) + x + objX2] = color; + if ((x + objX2) >= 0 && (x + objX2) < 320 + && (y + objY2) >= 0 && (y + objY2) < 200) { + if (color != currentTransparent) { + output[320 * (y + objY2) + x + objX2] = + color; } } } } } -void mainDraw5(int overlayIdx, int idx, int field_28, cellStruct* pObject, int newVal) -{ - drawVar1Struct* pNewEntry; +void mainDraw5(int overlayIdx, int idx, int field_28, cellStruct *pObject, + int newVal) { + drawVar1Struct *pNewEntry; - pNewEntry = (drawVar1Struct*)malloc(sizeof(drawVar1Struct)); + pNewEntry = (drawVar1Struct *) malloc(sizeof(drawVar1Struct)); pNewEntry->next = drawVar1.next; - drawVar1.next = pNewEntry; + drawVar1.next = pNewEntry; pNewEntry->field_2 = overlayIdx; pNewEntry->field_4 = idx; @@ -741,38 +700,36 @@ void mainDraw5(int overlayIdx, int idx, int field_28, cellStruct* pObject, int n } #ifdef _DEBUG -void drawCtp(void) -{ +void drawCtp(void) { int i; - if(ctp_walkboxTable) - { - for(i = 0; i < 15; i++) - { - uint16* dataPtr = &ctp_walkboxTable[i * 40]; - int type = walkboxType[i]; // show different types in different colors + if (ctp_walkboxTable) { + for (i = 0; i < 15; i++) { + uint16 *dataPtr = &ctp_walkboxTable[i * 40]; + int type = walkboxType[i]; // show different types in different colors - if(*dataPtr) - { + if (*dataPtr) { int j; - fillpoly((short*)dataPtr+1, *dataPtr, type); + fillpoly((short *)dataPtr + 1, *dataPtr, type); - for(j = 0; j < (*dataPtr - 1); j++) - { - line(dataPtr[1 + j * 2], dataPtr[1 + j * 2 + 1], dataPtr[1 + (j + 1) * 2], dataPtr[1 + ( j + 1) * 2 + 1], 0); + for (j = 0; j < (*dataPtr - 1); j++) { + line(dataPtr[1 + j * 2], + dataPtr[1 + j * 2 + 1], + dataPtr[1 + (j + 1) * 2], + dataPtr[1 + (j + 1) * 2 + 1], 0); } - line(dataPtr[1 + j * 2], dataPtr[1 + j * 2 + 1], dataPtr[1], dataPtr[2], 0); + line(dataPtr[1 + j * 2], + dataPtr[1 + j * 2 + 1], dataPtr[1], + dataPtr[2], 0); } } } } #endif -void drawMenu(menuStruct* pMenu) -{ - if(pMenu && pMenu->numElements) - { +void drawMenu(menuStruct *pMenu) { + if (pMenu && pMenu->numElements) { int height; int x; int y; @@ -783,29 +740,24 @@ void drawMenu(menuStruct* pMenu) int currentY; int var_8; int di; - menuElementStruct* si; + menuElementStruct *si; height = pMenu->gfx->height; - x = pMenu->x; - y = pMenu->y; + x = pMenu->x; + y = pMenu->y; var_10 = pMenu->gfx->width / (199 - (pMenu->gfx->width * 2)); - bx = var_10 / (pMenu->numElements + 1); // rustine... + bx = var_10 / (pMenu->numElements + 1); // rustine... - if(!bx) - { + if (!bx) { bx++; - if((pMenu->numElements * height) + y > 199 - height) - { + if ((pMenu->numElements * height) + y > 199 - height) { y = ((-1 - pMenu->numElements) * height) + 200; } - } - else - { - if(var_10 % pMenu->numElements) - { + } else { + if (var_10 % pMenu->numElements) { bx++; } @@ -814,21 +766,19 @@ void drawMenu(menuStruct* pMenu) newX = 320 * (2 - bx); - if(newX < x) - { + if (newX < x) { x = newX; } - if(x < 0) - { + if (x < 0) { x = 0; } - var_6 = (80 * (bx-1)) + x; + var_6 = (80 * (bx - 1)) + x; - if(var_6 <= 320) - { - mainSprite(var_6, y - height, pMenu->gfx, gfxModuleData.pPage10, video4, 320); + if (var_6 <= 320) { + mainSprite(var_6, y - height, pMenu->gfx, + gfxModuleData.pPage10, video4, 320); } currentY = y; @@ -837,59 +787,48 @@ void drawMenu(menuStruct* pMenu) si = pMenu->ptrNextElement; - if(si) - { - do - { + if (si) { + do { int color; - gfxEntryStruct* var_2 = si->gfx; + gfxEntryStruct *var_2 = si->gfx; - si->x = di; - si->y = currentY; + si->x = di; + si->y = currentY; si->varA = 320; - if(si->varC) - { + if (si->varC) { color = video3; - } - else - { - if(si->color != 255) - { + } else { + if (si->color != 255) { color = si->color; - } - else - { + } else { color = video2; } } - if(di < 320) - { - mainSprite(di, currentY, var_2, gfxModuleData.pPage10, color, 320); + if (di < 320) { + mainSprite(di, currentY, var_2, + gfxModuleData.pPage10, color, 320); } currentY += height; var_8++; - if(var_8 == var_10) - { - var_8 = 0; - di += 320; + if (var_8 == var_10) { + var_8 = 0; + di += 320; currentY = y; } si = si->next; - } while(si); + } while (si); } } } -int getValueFromObjectQuerry(objectParamsQuery* params, int idx) -{ - switch(idx) - { +int getValueFromObjectQuerry(objectParamsQuery *params, int idx) { + switch (idx) { case 0: return params->X; case 1: @@ -913,10 +852,9 @@ int getValueFromObjectQuerry(objectParamsQuery* params, int idx) return 0; } -void mainDraw(int16 param) -{ - uint8* bgPtr; - cellStruct* currentObjPtr; +void mainDraw(int16 param) { + uint8 *bgPtr; + cellStruct *currentObjPtr; int16 currentObjIdx; int16 objX1 = 0; int16 objY1 = 0; @@ -926,17 +864,15 @@ void mainDraw(int16 param) int16 objZ2; int16 spriteHeight; - - if(fadeVar) - { + if (fadeVar) { return; } bgPtr = backgroundPtrtable[currentActiveBackgroundPlane]; - if(bgPtr) - { - gfxModuleData_gfxCopyScreen((char*)bgPtr,(char*)gfxModuleData.pPage10); + if (bgPtr) { + gfxModuleData_gfxCopyScreen((char *)bgPtr, + (char *)gfxModuleData.pPage10); } drawVar1.next = NULL; @@ -950,144 +886,192 @@ void mainDraw(int16 param) //-------------------------------------------------- PROCESS SPRITES -----------------------------------------// - while(currentObjPtr) - { - if((currentActiveBackgroundPlane == currentObjPtr->backgroundPlane) && (currentObjPtr->freeze == 0) && (currentObjPtr->type == OBJ_SPRITE)) - { + while (currentObjPtr) { + if ((currentActiveBackgroundPlane == + currentObjPtr->backgroundPlane) + && (currentObjPtr->freeze == 0) + && (currentObjPtr->type == OBJ_SPRITE)) { objectParamsQuery params; currentObjIdx = currentObjPtr->idx; - if((currentObjPtr->followObjectOverlayIdx != currentObjPtr->overlay) || (currentObjPtr->followObjectIdx != currentObjPtr->idx)) - { + if ((currentObjPtr->followObjectOverlayIdx != + currentObjPtr->overlay) + || (currentObjPtr->followObjectIdx != + currentObjPtr->idx)) { // Declaring this twice ? // objectParamsQuery params; - getMultipleObjectParam(currentObjPtr->followObjectOverlayIdx, currentObjPtr->followObjectIdx, ¶ms); + getMultipleObjectParam(currentObjPtr-> + followObjectOverlayIdx, + currentObjPtr->followObjectIdx, ¶ms); objX1 = params.X; objY1 = params.Y; objZ1 = params.fileIdx; - } - else - { + } else { objX1 = 0; objY1 = 0; objZ1 = 0; } - getMultipleObjectParam(currentObjPtr->overlay, currentObjIdx, ¶ms); + getMultipleObjectParam(currentObjPtr->overlay, + currentObjIdx, ¶ms); objX2 = objX1 + params.X; objY2 = objY1 + params.Y; objZ2 = params.fileIdx; - if(objZ2 >= 0) - { + if (objZ2 >= 0) { objZ2 += objZ1; } - if((params.var5 >= 0) && (objZ2 >= 0) && filesDatabase[objZ2].subData.ptr) - { - if(filesDatabase[objZ2].subData.resourceType == 8) // Poly + if ((params.var5 >= 0) && (objZ2 >= 0) + && filesDatabase[objZ2].subData.ptr) { + if (filesDatabase[objZ2].subData.resourceType == 8) // Poly { - mainDrawPolygons(objZ2, currentObjPtr, objX2, params.scale, objY2, (char*)gfxModuleData.pPage10, (char*)filesDatabase[objZ2].subData.ptr); // poly - } - else if(filesDatabase[objZ2].subData.resourceType == 6) // sound - { - } - else if(filesDatabase[objZ2].resType == 1) //(num plan == 1) + mainDrawPolygons(objZ2, currentObjPtr, objX2, params.scale, objY2, (char *)gfxModuleData.pPage10, (char *)filesDatabase[objZ2].subData.ptr); // poly + } else if (filesDatabase[objZ2].subData.resourceType == 6) // sound { - } - else if(filesDatabase[objZ2].subData.resourceType == 4) + } else if (filesDatabase[objZ2].resType == 1) //(num plan == 1) { - objX1 = filesDatabase[objZ2].width; // width + } else if (filesDatabase[objZ2].subData. + resourceType == 4) { + objX1 = filesDatabase[objZ2].width; // width spriteHeight = filesDatabase[objZ2].height; // height - if(filesDatabase[objZ2].subData.ptr) - { - currentTransparent = filesDatabase[objZ2].subData.transparency; - - mainDrawSub4(objX1, spriteHeight, currentObjPtr, (char*)filesDatabase[objZ2].subData.ptr, objY2, objX2, (char*)gfxModuleData.pPage10, (char*)filesDatabase[objZ2].subData.ptr); + if (filesDatabase[objZ2].subData.ptr) { + currentTransparent = + filesDatabase[objZ2]. + subData.transparency; + + mainDrawSub4(objX1, + spriteHeight, + currentObjPtr, + (char *) + filesDatabase[objZ2]. + subData.ptr, objY2, objX2, + (char *)gfxModuleData. + pPage10, + (char *) + filesDatabase[objZ2]. + subData.ptr); } } } - if((currentObjPtr->animStep != 0) && (param == 0)) - { - if(currentObjPtr->currentAnimDelay <= 0) - { + if ((currentObjPtr->animStep != 0) && (param == 0)) { + if (currentObjPtr->currentAnimDelay <= 0) { int newVal; bool change = true; - newVal = getValueFromObjectQuerry(¶ms,currentObjPtr->field_28) + currentObjPtr->animStep; - - if(currentObjPtr->animStep > 0) - { - if(newVal > currentObjPtr->field_22) - { - if(currentObjPtr->field_30) - { - newVal = currentObjPtr->field_20; - currentObjPtr->field_30--; - } - else - { + newVal = + getValueFromObjectQuerry(¶ms, + currentObjPtr->field_28) + + currentObjPtr->animStep; + + if (currentObjPtr->animStep > 0) { + if (newVal > + currentObjPtr->field_22) { + if (currentObjPtr-> + field_30) { + newVal = + currentObjPtr-> + field_20; + currentObjPtr-> + field_30--; + } else { int16 data2; - data2 = currentObjPtr->field_20; + data2 = + currentObjPtr-> + field_20; change = false; - currentObjPtr->animStep = 0; + currentObjPtr-> + animStep = + 0; - if(currentObjPtr->field_2A) // should we resume the script ? + if (currentObjPtr->field_2A) // should we resume the script ? { - if(currentObjPtr->field_1A == 20) - { - changeScriptParamInList(currentObjPtr->field_18, currentObjPtr->field_16, &scriptHandle2, 0, -1); - } - else if(currentObjPtr->field_1A == 30) + if (currentObjPtr->field_1A == 20) { + changeScriptParamInList + (currentObjPtr-> + field_18, + currentObjPtr-> + field_16, + &scriptHandle2, + 0, + -1); + } else + if + (currentObjPtr-> + field_1A + == + 30) { - changeScriptParamInList(currentObjPtr->field_18, currentObjPtr->field_16, &scriptHandle1, 0, -1); + changeScriptParamInList + (currentObjPtr-> + field_18, + currentObjPtr-> + field_16, + &scriptHandle1, + 0, + -1); } } newVal = data2; } } - } - else - { + } else { ASSERT(0); /* if(currentObjPtr->field_22>newVal) - { - } */ + * { + * } */ } - if(currentObjPtr->nextAnimDelay >= 0) - { - currentObjPtr->currentAnimDelay = currentObjPtr->nextAnimDelay; + if (currentObjPtr->nextAnimDelay >= 0) { + currentObjPtr-> + currentAnimDelay = + currentObjPtr-> + nextAnimDelay; } - if((currentObjPtr->field_2C >= 0) && (currentObjPtr->field_2C == newVal) && (currentObjPtr->field_2A != 0)) - { - if(currentObjPtr->field_1A == 20) - { - changeScriptParamInList(currentObjPtr->field_18, currentObjPtr->field_16, &scriptHandle2, 0, -1); - } - else if(currentObjPtr->field_1A == 30) - { - changeScriptParamInList(currentObjPtr->field_18, currentObjPtr->field_16, &scriptHandle1, 0, -1); + if ((currentObjPtr->field_2C >= 0) + && (currentObjPtr->field_2C == + newVal) + && (currentObjPtr->field_2A != + 0)) { + if (currentObjPtr->field_1A == + 20) { + changeScriptParamInList + (currentObjPtr-> + field_18, + currentObjPtr-> + field_16, + &scriptHandle2, 0, + -1); + } else if (currentObjPtr-> + field_1A == 30) { + changeScriptParamInList + (currentObjPtr-> + field_18, + currentObjPtr-> + field_16, + &scriptHandle1, 0, + -1); } currentObjPtr->field_2A = 0; } - if(change) - { - mainDraw5(currentObjPtr->overlay, currentObjPtr->idx, currentObjPtr->field_28, currentObjPtr, newVal); + if (change) { + mainDraw5(currentObjPtr-> + overlay, + currentObjPtr->idx, + currentObjPtr->field_28, + currentObjPtr, newVal); } - } - else - { + } else { currentObjPtr->currentAnimDelay--; } } @@ -1105,11 +1089,12 @@ void mainDraw(int16 param) currentObjPtr = cellHead.next; - while(currentObjPtr) - { - if(currentObjPtr->type == 5 && currentObjPtr->freeze == 0) - { - mainSprite(currentObjPtr->field_A, currentObjPtr->field_C, currentObjPtr->gfxPtr, gfxModuleData.pPage10, currentObjPtr->field_10, currentObjPtr->spriteIdx); + while (currentObjPtr) { + if (currentObjPtr->type == 5 && currentObjPtr->freeze == 0) { + mainSprite(currentObjPtr->field_A, + currentObjPtr->field_C, currentObjPtr->gfxPtr, + gfxModuleData.pPage10, currentObjPtr->field_10, + currentObjPtr->spriteIdx); var20 = 1; } currentObjPtr = currentObjPtr->next; @@ -1117,17 +1102,14 @@ void mainDraw(int16 param) //----------------------------------------------------------------------------------------------------------------// - if(currentActiveMenu != -1) - { - if(menuTable[currentActiveMenu]) - { + if (currentActiveMenu != -1) { + if (menuTable[currentActiveMenu]) { drawMenu(menuTable[currentActiveMenu]); return; } } - if(mouseVar1) - { + if (mouseVar1) { ASSERT(0); // TODO: draw mouse here } diff --git a/engines/cruise/mainDraw.h b/engines/cruise/mainDraw.h index be26cc7cb2..ae6194a568 100644 --- a/engines/cruise/mainDraw.h +++ b/engines/cruise/mainDraw.h @@ -22,8 +22,8 @@ * */ -#ifndef _MAINDRAW_H_ -#define _MAINDRAW_H_ +#ifndef CRUISE_MAINDRAW_H +#define CRUISE_MAINDRAW_H namespace Cruise { @@ -37,12 +37,14 @@ int upscaleValue(int value, int scale); void pixel(int x, int y, char color); void mainDraw(int16 param); void flipScreen(void); -void buildPolyModel(int X, int Y, int scale, char* ptr2, char* destBuffer, char* dataPtr); -void getPolyData(int fileIndex, int X, int Y, int *newScale, int *newY, int *newX, char **newDataPtr, int scale, char* dataPtr); -void mainDrawSub4(int objX1, int var_6, cellStruct* currentObjPtr, char* data1, int objY2, int objX2, char* output, char* data2); -char* drawPolyMode2(char* si, int cx); +void buildPolyModel(int X, int Y, int scale, char *ptr2, char *destBuffer, + char *dataPtr); +void getPolyData(int fileIndex, int X, int Y, int *newScale, int *newY, + int *newX, char **newDataPtr, int scale, char *dataPtr); +void mainDrawSub4(int objX1, int var_6, cellStruct * currentObjPtr, + char *data1, int objY2, int objX2, char *output, char *data2); +char *drawPolyMode2(char *si, int cx); } // End of namespace Cruise #endif - diff --git a/engines/cruise/menu.cpp b/engines/cruise/menu.cpp index aaf28bcfd5..d76934439b 100644 --- a/engines/cruise/menu.cpp +++ b/engines/cruise/menu.cpp @@ -26,205 +26,199 @@ namespace Cruise { -menuStruct* menuTable[8]; +menuStruct *menuTable[8]; -menuStruct* createMenu(int X, int Y, const char* menuName) -{ - menuStruct* entry; +menuStruct *createMenu(int X, int Y, const char *menuName) { + menuStruct *entry; - entry = (menuStruct*)malloc(sizeof(menuStruct)); - ASSERT(entry); + entry = (menuStruct *) malloc(sizeof(menuStruct)); + ASSERT(entry); - entry->x = X - 80; - entry->y = Y; - entry->stringPtr = menuName; - entry->numElements = 0; - entry->ptrNextElement = NULL; - entry->gfx = renderText(160, (uint8*)menuName); + entry->x = X - 80; + entry->y = Y; + entry->stringPtr = menuName; + entry->numElements = 0; + entry->ptrNextElement = NULL; + entry->gfx = renderText(160, (uint8 *) menuName); - return entry; + return entry; } // TODO: rewrite to remove the goto -void addSelectableMenuEntry(int param0, int param1, menuStruct* pMenu, int param2, int color, const char* menuText) -{ - menuElementStruct* di; - menuElementStruct* var_6; - menuElementStruct* pNewElement; - menuElementSubStruct* pSubStruct; - menuElementSubStruct* pSubStructCurrent; - - if(pMenu->numElements <= 48) - { - var_6 = pMenu->ptrNextElement; - - if(var_6) - { - do - { - di = var_6; - if(param2) - { - if(!strcmp(var_6->string, menuText)) - { - pNewElement = var_6; - pSubStruct = (menuElementSubStruct*)allocAndZero(sizeof(menuElementSubStruct)); - ASSERT(pSubStruct); - - pSubStruct->pNext = NULL; - pSubStruct->var2 = param0; - pSubStruct->var4 = param1; - - pSubStructCurrent = pNewElement->ptrSub; - - if(!pSubStructCurrent) - { - pNewElement->ptrSub = pSubStruct; - return; - } - - if(pSubStructCurrent->pNext) - { - do - { - pSubStructCurrent = pSubStructCurrent->pNext; - }while(pSubStructCurrent->pNext); - } - - pSubStructCurrent->pNext = pSubStruct; - return; - } - } - var_6 = var_6->next; - } - while(var_6); - - var_6 = di; - } - - pNewElement = (menuElementStruct*)allocAndZero(sizeof(menuElementStruct)); - ASSERT(pNewElement); - pSubStruct = (menuElementSubStruct*)allocAndZero(sizeof(menuElementSubStruct)); - ASSERT(pSubStruct); - - pNewElement->string = menuText; - pNewElement->next = NULL; - pNewElement->varC = 0; - pNewElement->color = color; - pNewElement->gfx = renderText(160,(uint8*)menuText); - - if(var_6 == NULL) - { - pMenu->ptrNextElement = pNewElement; - } - else - { - var_6->next = pNewElement; - } - - pNewElement->ptrSub = pSubStruct; - - pSubStruct->pNext = NULL; - pSubStruct->var2 = param0; - pSubStruct->var4 = param1; - - pMenu->numElements++; - } +void addSelectableMenuEntry(int param0, int param1, menuStruct *pMenu, + int param2, int color, const char *menuText) { + menuElementStruct *di; + menuElementStruct *var_6; + menuElementStruct *pNewElement; + menuElementSubStruct *pSubStruct; + menuElementSubStruct *pSubStructCurrent; + + if (pMenu->numElements <= 48) { + var_6 = pMenu->ptrNextElement; + + if (var_6) { + do { + di = var_6; + if (param2) { + if (!strcmp(var_6->string, menuText)) { + pNewElement = var_6; + pSubStruct = + (menuElementSubStruct *) + allocAndZero(sizeof + (menuElementSubStruct)); + ASSERT(pSubStruct); + + pSubStruct->pNext = NULL; + pSubStruct->var2 = param0; + pSubStruct->var4 = param1; + + pSubStructCurrent = + pNewElement->ptrSub; + + if (!pSubStructCurrent) { + pNewElement->ptrSub = + pSubStruct; + return; + } + + if (pSubStructCurrent->pNext) { + do { + pSubStructCurrent + = + pSubStructCurrent-> + pNext; + } while + (pSubStructCurrent-> + pNext); + } + + pSubStructCurrent->pNext = + pSubStruct; + return; + } + } + var_6 = var_6->next; + } + while (var_6); + + var_6 = di; + } + + pNewElement = + (menuElementStruct *) + allocAndZero(sizeof(menuElementStruct)); + ASSERT(pNewElement); + pSubStruct = + (menuElementSubStruct *) + allocAndZero(sizeof(menuElementSubStruct)); + ASSERT(pSubStruct); + + pNewElement->string = menuText; + pNewElement->next = NULL; + pNewElement->varC = 0; + pNewElement->color = color; + pNewElement->gfx = renderText(160, (uint8 *) menuText); + + if (var_6 == NULL) { + pMenu->ptrNextElement = pNewElement; + } else { + var_6->next = pNewElement; + } + + pNewElement->ptrSub = pSubStruct; + + pSubStruct->pNext = NULL; + pSubStruct->var2 = param0; + pSubStruct->var4 = param1; + + pMenu->numElements++; + } } -void updateMenuMouse(int mouseX, int mouseY, menuStruct* pMenu) -{ - if(pMenu) - { - if(pMenu->gfx) - { - int height = pMenu->gfx->height; // rustine - int var_2 = 0; - menuElementStruct* pCurrentEntry = pMenu->ptrNextElement; - - while(pCurrentEntry) - { - pCurrentEntry->varC = 0; - - if(var_2 == 0) - { - if((mouseX > pCurrentEntry->x) && ((pCurrentEntry->x + 160) >= mouseX)) - { - if((mouseY > pCurrentEntry->y) && ((pCurrentEntry->y + height) >= mouseY)) - { - var_2 = 1; - pCurrentEntry->varC = 1; - } - } - } - - pCurrentEntry = pCurrentEntry->next; - } - } - } +void updateMenuMouse(int mouseX, int mouseY, menuStruct *pMenu) { + if (pMenu) { + if (pMenu->gfx) { + int height = pMenu->gfx->height; // rustine + int var_2 = 0; + menuElementStruct *pCurrentEntry = + pMenu->ptrNextElement; + + while (pCurrentEntry) { + pCurrentEntry->varC = 0; + + if (var_2 == 0) { + if ((mouseX > pCurrentEntry->x) + && ((pCurrentEntry->x + 160) >= + mouseX)) { + if ((mouseY > pCurrentEntry->y) + && ((pCurrentEntry->y + + height) >= + mouseY)) { + var_2 = 1; + pCurrentEntry->varC = + 1; + } + } + } + + pCurrentEntry = pCurrentEntry->next; + } + } + } } -int processMenu(menuStruct* pMenu) -{ - int16 mouseX; - int16 mouseY; - int16 mouseButton; - int di; - int si; - currentActiveMenu = 0; +int processMenu(menuStruct *pMenu) { + int16 mouseX; + int16 mouseY; + int16 mouseButton; + int di; + int si; + currentActiveMenu = 0; - mainDraw(1); - flipScreen(); + mainDraw(1); + flipScreen(); - di = 0; - si = 0; + di = 0; + si = 0; - do - { - getMouseStatus(&main10, &mouseX, &mouseButton, &mouseY); + do { + getMouseStatus(&main10, &mouseX, &mouseButton, &mouseY); - updateMenuMouse(mouseX, mouseY, pMenu); + updateMenuMouse(mouseX, mouseY, pMenu); - if(mouseButton) - { - if(di) - { - si = 1; - } - } - else - { - di = 1; - } + if (mouseButton) { + if (di) { + si = 1; + } + } else { + di = 1; + } - mainDraw(1); - flipScreen(); + mainDraw(1); + flipScreen(); // readKeyboard(); - }while(!si); + } while (!si); - currentActiveMenu = -1; + currentActiveMenu = -1; - mainDraw(1); - flipScreen(); + mainDraw(1); + flipScreen(); - return 0; + return 0; } -int playerMenu(int menuX, int menuY) -{ - int retourMenu; - //int restartGame = 0; - - if(entrerMenuJoueur && affichePasMenuJoueur) - { - if(var0) - { - systemStrings.param = 0; - var24 = 0; - var23 = 0; - freeStuff2(); - } +int playerMenu(int menuX, int menuY) { + int retourMenu; + //int restartGame = 0; + + if (entrerMenuJoueur && affichePasMenuJoueur) { + if (var0) { + systemStrings.param = 0; + var24 = 0; + var23 = 0; + freeStuff2(); + } /* if(currentMenu) { @@ -251,71 +245,68 @@ int playerMenu(int menuX, int menuY) /* mouseVar2 = 0; mouseVar1 = 0; */ - freeDisk(); - - menuTable[0] = createMenu(menuX, menuY, "Menu Joueur"); - ASSERT(menuTable[0]); - - addSelectableMenuEntry(0, 3, menuTable[0], 1, -1, "Lecteur de Sauvegarde"); - if(userEnabled) - { - addSelectableMenuEntry(0, 4, menuTable[0], 1, -1, "Sauvegarde"); - } - addSelectableMenuEntry(0, 5, menuTable[0], 1, -1, "Chargement"); - addSelectableMenuEntry(0, 6, menuTable[0], 1, -1, "Recommencer le jeu"); - addSelectableMenuEntry(0, 7, menuTable[0], 1, -1, "Chargement"); - - retourMenu = processMenu(menuTable[0]); - } - - return 0; + freeDisk(); + + menuTable[0] = createMenu(menuX, menuY, "Menu Joueur"); + ASSERT(menuTable[0]); + + addSelectableMenuEntry(0, 3, menuTable[0], 1, -1, + "Lecteur de Sauvegarde"); + if (userEnabled) { + addSelectableMenuEntry(0, 4, menuTable[0], 1, -1, + "Sauvegarde"); + } + addSelectableMenuEntry(0, 5, menuTable[0], 1, -1, + "Chargement"); + addSelectableMenuEntry(0, 6, menuTable[0], 1, -1, + "Recommencer le jeu"); + addSelectableMenuEntry(0, 7, menuTable[0], 1, -1, + "Chargement"); + + retourMenu = processMenu(menuTable[0]); + } + + return 0; } -void freeGfx(gfxEntryStruct* pGfx) -{ - if(pGfx->imagePtr) - { - free(pGfx->imagePtr); - } +void freeGfx(gfxEntryStruct *pGfx) { + if (pGfx->imagePtr) { + free(pGfx->imagePtr); + } - free(pGfx); + free(pGfx); } -void freeMenu(menuStruct* pMenu) -{ - menuElementStruct* pElement = pMenu->ptrNextElement; +void freeMenu(menuStruct *pMenu) { + menuElementStruct *pElement = pMenu->ptrNextElement; - while(pElement) - { - menuElementStruct* next; - menuElementSubStruct* pSub = pElement->ptrSub; + while (pElement) { + menuElementStruct *next; + menuElementSubStruct *pSub = pElement->ptrSub; - next = pElement->next; + next = pElement->next; - while(pSub) - { - menuElementSubStruct* nextSub; + while (pSub) { + menuElementSubStruct *nextSub; - nextSub = pSub->pNext; + nextSub = pSub->pNext; - free(pSub); + free(pSub); - pSub=nextSub; - } + pSub = nextSub; + } - if(pElement->gfx) - { - freeGfx(pElement->gfx); - } + if (pElement->gfx) { + freeGfx(pElement->gfx); + } - free(pElement); + free(pElement); - pElement = next; - } + pElement = next; + } - freeGfx(pMenu->gfx); - free(pMenu); + freeGfx(pMenu->gfx); + free(pMenu); } } // End of namespace Cruise - diff --git a/engines/cruise/menu.h b/engines/cruise/menu.h index 83226189db..9fb477556c 100644 --- a/engines/cruise/menu.h +++ b/engines/cruise/menu.h @@ -22,28 +22,32 @@ * */ +#ifndef CRUISE_MENU_H +#define CRUISE_MENU_H + namespace Cruise { -struct menuStruct -{ - const char* stringPtr; - gfxEntryStruct* gfx; - int x; - int y; - int numElements; - menuElementStruct* ptrNextElement; +struct menuStruct { + const char *stringPtr; + gfxEntryStruct *gfx; + int x; + int y; + int numElements; + menuElementStruct *ptrNextElement; }; typedef struct menuStruct menuStruct; -extern menuStruct* menuTable[8]; +extern menuStruct *menuTable[8]; -menuStruct* createMenu(int X, int Y, const char* menuName); -void addSelectableMenuEntry(int var0, int var1, menuStruct* pMenu, int var2, int color, const char* menuText); -void updateMenuMouse(int mouseX, int mouseY, menuStruct* pMenu); -int processMenu(menuStruct* pMenu); -void freeMenu(menuStruct* pMenu); +menuStruct *createMenu(int X, int Y, const char *menuName); +void addSelectableMenuEntry(int var0, int var1, menuStruct * pMenu, int var2, + int color, const char *menuText); +void updateMenuMouse(int mouseX, int mouseY, menuStruct * pMenu); +int processMenu(menuStruct * pMenu); +void freeMenu(menuStruct * pMenu); int playerMenu(int menuX, int menuY); - } // End of namespace Cruise + +#endif diff --git a/engines/cruise/mouse.cpp b/engines/cruise/mouse.cpp index 801f2dc63d..9d296b9c77 100644 --- a/engines/cruise/mouse.cpp +++ b/engines/cruise/mouse.cpp @@ -28,16 +28,16 @@ namespace Cruise { int16 main10; -void getMouseStatus(int16* pMouseVar, int16* pMouseX, int16* pMouseButton, int16* pMouseY) -{ - // mouseStatusStruct localStatus; +void getMouseStatus(int16 *pMouseVar, int16 *pMouseX, int16 *pMouseButton, + int16 *pMouseY) { + // mouseStatusStruct localStatus; - // OSystem_GetMouseStatus(&localStatus); + // OSystem_GetMouseStatus(&localStatus); - *pMouseX = 0; - *pMouseY = 0; + *pMouseX = 0; + *pMouseY = 0; - *pMouseButton = 0; + *pMouseButton = 0; /* if(localStatus.left) *pMouseButton |= 1; diff --git a/engines/cruise/mouse.h b/engines/cruise/mouse.h index fb72c111ba..12d3ba2ba0 100644 --- a/engines/cruise/mouse.h +++ b/engines/cruise/mouse.h @@ -22,16 +22,16 @@ * */ -#ifndef _MOUSE_H_ -#define _MOUSE_H_ +#ifndef CRUISE_MOUSE_H +#define CRUISE_MOUSE_H namespace Cruise { extern int16 main10; -void getMouseStatus(int16* pMouseVar, int16* pMouseX, int16* pMouseButton, int16* pMouseY); +void getMouseStatus(int16 * pMouseVar, int16 * pMouseX, int16 * pMouseButton, + int16 * pMouseY); } // End of namespace Cruise #endif - diff --git a/engines/cruise/object.cpp b/engines/cruise/object.cpp index 8f4b0eda47..e4500d9683 100644 --- a/engines/cruise/object.cpp +++ b/engines/cruise/object.cpp @@ -36,141 +36,133 @@ namespace Cruise { */ -objDataStruct* getObjectDataFromOverlay(int ovlIdx,int objIdx) -{ - objDataStruct* var_6; +objDataStruct *getObjectDataFromOverlay(int ovlIdx, int objIdx) { + objDataStruct *var_6; - if(ovlIdx<1 || objIdx <0) - return NULL; + if (ovlIdx < 1 || objIdx < 0) + return NULL; - if(!overlayTable[ovlIdx].ovlData) - return NULL; + if (!overlayTable[ovlIdx].ovlData) + return NULL; - if(overlayTable[ovlIdx].ovlData->numObjData <= objIdx) - return NULL; + if (overlayTable[ovlIdx].ovlData->numObjData <= objIdx) + return NULL; - var_6 = overlayTable[ovlIdx].ovlData->objDataTable; + var_6 = overlayTable[ovlIdx].ovlData->objDataTable; - if(!var_6) - return NULL; + if (!var_6) + return NULL; - return (&var_6[objIdx]); + return (&var_6[objIdx]); } -int16 getMultipleObjectParam(int16 overlayIdx,int16 objectIdx,objectParamsQuery* returnParam) -{ - int16 size; - int16 var_A; - int16 var_14; - objectParams* ptr2; - objDataStruct* ptr; - ovlDataStruct* ovlData; +int16 getMultipleObjectParam(int16 overlayIdx, int16 objectIdx, + objectParamsQuery *returnParam) { + int16 size; + int16 var_A; + int16 var_14; + objectParams *ptr2; + objDataStruct *ptr; + ovlDataStruct *ovlData; // int16 type; - ptr = getObjectDataFromOverlay(overlayIdx,objectIdx); + ptr = getObjectDataFromOverlay(overlayIdx, objectIdx); - if(!ptr) - return -11; + if (!ptr) + return -11; - ovlData = overlayTable[overlayIdx].ovlData; + ovlData = overlayTable[overlayIdx].ovlData; - switch(ptr->var1) - { + switch (ptr->var1) { case 0: { ptr2 = &ovlData->objData2SourceTable[ptr->var5]; - var_14 = globalVars[*(int16*)(&overlayTable[overlayIdx].field_14 + ptr->var6)]; + var_14 = globalVars[*(int16 *) (&overlayTable[overlayIdx].field_14 + ptr->var6)]; var_A = ptr2->var5; break; } - case 1: - { + case 1: + { ptr2 = &ovlData->objData2WorkTable[ptr->var4]; - var_A = var_14 = ptr2->var5; - size = var_A + ptr->var5; + var_A = var_14 = ptr2->var5; + size = var_A + ptr->var5; - if(ptr->var5 + var_14<=ovlData->size8) - { + if (ptr->var5 + var_14 <= ovlData->size8) { var_A = ovlData->objData2SourceTable[ptr->var5 + var_14].var5; - } - break; - } - default: - { - printf("unsupported case %d in getMultipleObjectParam\n", ptr->var1); - exit(1); - } - } + } + break; + } + default: + { + printf("unsupported case %d in getMultipleObjectParam\n", ptr->var1); + exit(1); + } + } returnParam->X = ptr2->X; - returnParam->Y = ptr2->Y; - returnParam->baseFileIdx = ptr2->baseFileIdx; - returnParam->fileIdx = ptr2->var3; - returnParam->scale = ptr2->scale; - returnParam->var5 = var_14; - returnParam->var6 = var_A; - returnParam->var7 = ptr->var3; - - return 0; + returnParam->Y = ptr2->Y; + returnParam->baseFileIdx = ptr2->baseFileIdx; + returnParam->fileIdx = ptr2->var3; + returnParam->scale = ptr2->scale; + returnParam->var5 = var_14; + returnParam->var6 = var_A; + returnParam->var7 = ptr->var3; + + return 0; } -void setObjectPosition(int16 param1,int16 objIdx,int16 param3,int16 param4) -{ - objDataStruct* ptr; - objectParams* ptr2; +void setObjectPosition(int16 param1, int16 objIdx, int16 param3, int16 param4) { + objDataStruct *ptr; + objectParams *ptr2; ptr = getObjectDataFromOverlay(param1, objIdx); - if(!ptr) - { + if (!ptr) { return; ASSERT(0); } - //overlayTable[param1].ovlData - switch(ptr->var1) - { + switch (ptr->var1) { case 1: { - ptr2 = &overlayTable[param1].ovlData->objData2WorkTable[ptr->var4]; - - switch(param3) - { - case 0: // x - { - ptr2->X = param4; - break; - } - case 1: // y - { - ptr2->Y = param4; - break; - } - case 2: // base file - { - ptr2->baseFileIdx = param4; - break; - } - case 3: - { - ptr2->var3 = param4; - break; - } - case 4: // scale + ptr2 = &overlayTable[param1].ovlData->objData2WorkTable[ptr->var4]; + + switch (param3) { + case 0: // x + { + ptr2->X = param4; + break; + } + case 1: // y + { + ptr2->Y = param4; + break; + } + case 2: // base file + { + ptr2->baseFileIdx = param4; + break; + } + case 3: + { + ptr2->var3 = param4; + break; + } + case 4: // scale { ptr2->scale = param4; break; } - case 5: // box colision - { - ptr2->var5 = param4; - break; - } + case 5: // box colision + { + ptr2->var5 = param4; + break; + } default: { ASSERT(0); @@ -186,212 +178,195 @@ void setObjectPosition(int16 param1,int16 objIdx,int16 param3,int16 param4) } } -void Op_InitializeStateSub1(int16 param1, int16 param2, cellStruct* objPtr) -{ - int16 var; - cellStruct* var8_; - cellStruct* var40; - cellStruct* var3E; - cellStruct* currentObjPtrPrevious; - cellStruct* currentObjPtr2; - cellStruct* match; - - getSingleObjectParam(param1,param2,2,&var); - - currentObjPtrPrevious = objPtr; - currentObjPtr2 = objPtr->next; - - match = NULL; - var40 = NULL; - var3E = NULL; - var8_ = objPtr; - - while(currentObjPtr2) - { - if((currentObjPtr2->overlay == param1) && (currentObjPtr2->idx == param2)) // found - { - currentObjPtrPrevious->next = currentObjPtr2->next; - - if(currentObjPtr2->next) - { - currentObjPtr2->next->prev = currentObjPtr2->prev; - } - else - { - objPtr->prev = currentObjPtr2->prev; - } - - if(var40) - { - var40->prev = currentObjPtr2; - } - else - { - var3E = currentObjPtr2; - } - - currentObjPtr2->prev = NULL; - - currentObjPtr2->next = var40; - - var40 = currentObjPtr2; - - if(match == NULL) - { - match = currentObjPtr2; - } - } - else - { - if(currentObjPtr2->type == 5) - { - var2 = 32000; - } - else - { - int16 varC; - - getSingleObjectParam(currentObjPtr2->overlay,currentObjPtr2->idx,2,&varC); - - var2 = varC; - } - - if(var>var2) - { - var8_ = currentObjPtr2; - } - - currentObjPtrPrevious=currentObjPtrPrevious->next; - } - - currentObjPtr2 = currentObjPtr2->next; - } - - if(match) - { - cellStruct* temp; - - temp = var8_->next; - - var8_->next = var40; - match->next = temp; - - if(objPtr!=var8_) - { - var40->prev = var8_; - } - - if(!temp) - { - temp = match; - } - - temp->prev = match; - } +void Op_InitializeStateSub1(int16 param1, int16 param2, cellStruct *objPtr) { + int16 var; + cellStruct *var8_; + cellStruct *var40; + cellStruct *var3E; + cellStruct *currentObjPtrPrevious; + cellStruct *currentObjPtr2; + cellStruct *match; + + getSingleObjectParam(param1, param2, 2, &var); + + currentObjPtrPrevious = objPtr; + currentObjPtr2 = objPtr->next; + + match = NULL; + var40 = NULL; + var3E = NULL; + var8_ = objPtr; + + while (currentObjPtr2) { + if ((currentObjPtr2->overlay == param1) && (currentObjPtr2->idx == param2)) {// found + currentObjPtrPrevious->next = currentObjPtr2->next; + + if (currentObjPtr2->next) { + currentObjPtr2->next->prev = + currentObjPtr2->prev; + } else { + objPtr->prev = currentObjPtr2->prev; + } + + if (var40) { + var40->prev = currentObjPtr2; + } else { + var3E = currentObjPtr2; + } + + currentObjPtr2->prev = NULL; + + currentObjPtr2->next = var40; + + var40 = currentObjPtr2; + + if (match == NULL) { + match = currentObjPtr2; + } + } else { + if (currentObjPtr2->type == 5) { + var2 = 32000; + } else { + int16 varC; + + getSingleObjectParam(currentObjPtr2->overlay, + currentObjPtr2->idx, 2, &varC); + + var2 = varC; + } + + if (var > var2) { + var8_ = currentObjPtr2; + } + + currentObjPtrPrevious = currentObjPtrPrevious->next; + } + + currentObjPtr2 = currentObjPtr2->next; + } + + if (match) { + cellStruct *temp; + + temp = var8_->next; + + var8_->next = var40; + match->next = temp; + + if (objPtr != var8_) { + var40->prev = var8_; + } + + if (!temp) { + temp = match; + } + + temp->prev = match; + } } -int16 Op_InitializeStateSub(int ovlIdx,int objIdx,int param2) -{ - objDataStruct* ptr; +int16 Op_InitializeStateSub(int ovlIdx, int objIdx, int param2) { + objDataStruct *ptr; // uint16 param; - ovlDataStruct* ovlData; - - ptr = getObjectDataFromOverlay(ovlIdx,objIdx); - - if(!ptr) - return -11; - - ovlData = overlayTable[ovlIdx].ovlData; - - switch(ptr->var1) - { - case 0: - { - globalVars[overlayTable[ovlIdx].field_14 + ptr->var6] = param2; - Op_InitializeStateSub1(ovlIdx,param2,&cellHead); - break; - } - case 1: - { - objectParams* destEntry; - objectParams* sourceEntry; - - if(ptr->var5+param2 > ovlData->size8) - { - return 0; - } + ovlDataStruct *ovlData; + + ptr = getObjectDataFromOverlay(ovlIdx, objIdx); + + if (!ptr) + return -11; + + ovlData = overlayTable[ovlIdx].ovlData; + + switch (ptr->var1) { + case 0: + { + globalVars[overlayTable[ovlIdx].field_14 + ptr->var6] = + param2; + Op_InitializeStateSub1(ovlIdx, param2, &cellHead); + break; + } + case 1: + { + objectParams *destEntry; + objectParams *sourceEntry; + + if (ptr->var5 + param2 > ovlData->size8) { + return 0; + } destEntry = &ovlData->objData2WorkTable[ptr->var4]; - sourceEntry = &ovlData->objData2SourceTable[ptr->var5 + param2]; + sourceEntry = + &ovlData->objData2SourceTable[ptr->var5 + param2]; - memcpy(destEntry,sourceEntry,sizeof(objectParams)); + memcpy(destEntry, sourceEntry, sizeof(objectParams)); - destEntry->var5 = param2; + destEntry->var5 = param2; - Op_InitializeStateSub1(ovlIdx,param2,&cellHead); - break; - } - default: - { - printf("Unsupported param = %d in Op_InitializeStateSub\n",ptr->var1); - // exit(1); - } - } + Op_InitializeStateSub1(ovlIdx, param2, &cellHead); + break; + } + default: + { + printf + ("Unsupported param = %d in Op_InitializeStateSub\n", + ptr->var1); + // exit(1); + } + } - return 0; + return 0; } -int16 getSingleObjectParam(int16 overlayIdx,int16 param2,int16 param3,int16* returnParam) -{ +int16 getSingleObjectParam(int16 overlayIdx, int16 param2, int16 param3, + int16 *returnParam) { int var_A = 0; //char* ptr3 = NULL; - objDataStruct* ptr; - ovlDataStruct* ovlData; - objectParams* ptr2; + objDataStruct *ptr; + ovlDataStruct *ovlData; + objectParams *ptr2; - ptr = getObjectDataFromOverlay(overlayIdx,param2); + ptr = getObjectDataFromOverlay(overlayIdx, param2); - if(!ptr) - return -11; + if (!ptr) + return -11; - ovlData = overlayTable[overlayIdx].ovlData; + ovlData = overlayTable[overlayIdx].ovlData; - switch(ptr->var1) - { + switch (ptr->var1) { case 0: - case 3: + case 3: { var_A = globalVars[ptr->var6]; ptr2 = &ovlData->objData2SourceTable[ptr->var5]; - break; + break; } - case 1: - { + case 1: + { ptr2 = &ovlData->objData2WorkTable[ptr->var4]; - var_A = ptr2->var5; - break; - } - default: - { - printf("Unsupported case %d in getSingleObjectParam\n",ptr->var1); - exit(1); - } - } - - switch(param3) - { - case 0: - { - *returnParam = ptr2->X; - break; - } - case 1: - { - *returnParam = ptr2->Y; - break; - } + var_A = ptr2->var5; + break; + } + default: + { + printf("Unsupported case %d in getSingleObjectParam\n", + ptr->var1); + exit(1); + } + } + + switch (param3) { + case 0: + { + *returnParam = ptr2->X; + break; + } + case 1: + { + *returnParam = ptr2->Y; + break; + } case 2: { *returnParam = ptr2->baseFileIdx; @@ -399,7 +374,7 @@ int16 getSingleObjectParam(int16 overlayIdx,int16 param2,int16 param3,int16* ret } case 3: { - *returnParam = ptr2->var3; + *returnParam = ptr2->var3; break; } case 4: @@ -409,18 +384,19 @@ int16 getSingleObjectParam(int16 overlayIdx,int16 param2,int16 param3,int16* ret } case 5: { - *returnParam = var_A; + *returnParam = var_A; break; } default: { - printf("Unsupported case %d in getSingleObjectParam case 1\n",param3); + printf + ("Unsupported case %d in getSingleObjectParam case 1\n", + param3); exit(1); } } - return 0; + return 0; } - } // End of namespace Cruise diff --git a/engines/cruise/object.h b/engines/cruise/object.h index ca736143a2..24b8461851 100644 --- a/engines/cruise/object.h +++ b/engines/cruise/object.h @@ -22,41 +22,41 @@ * */ -#ifndef _OBJECT_H_ -#define _OBJECT_H_ +#ifndef CRUISE_OBJECT_H +#define CRUISE_OBJECT_H namespace Cruise { -struct gfxEntryStruct -{ - uint8* imagePtr; - int imageSize; - int fontIndex; - int height; - int width; // for font: max right border; for sprite: just width +struct gfxEntryStruct { + uint8 *imagePtr; + int imageSize; + int fontIndex; + int height; + int width; // for font: max right border; for sprite: just width }; typedef struct gfxEntryStruct gfxEntryStruct; #define OBJ_SPRITE 4 -struct objectParamsQuery -{ +struct objectParamsQuery { int16 X; int16 Y; int16 baseFileIdx; int16 fileIdx; int16 scale; int16 var5; - int16 var6; - int16 var7; + int16 var6; + int16 var7; }; typedef struct objectParamsQuery objectParamsQuery; -objDataStruct* getObjectDataFromOverlay(int ovlIdx,int objIdx); -int16 getSingleObjectParam(int16 overlayIdx,int16 param2,int16 param3,int16* returnParam); -int16 getMultipleObjectParam(int16 overlayIdx,int16 objectIdx,objectParamsQuery* returnParam); +objDataStruct *getObjectDataFromOverlay(int ovlIdx, int objIdx); +int16 getSingleObjectParam(int16 overlayIdx, int16 param2, int16 param3, + int16 * returnParam); +int16 getMultipleObjectParam(int16 overlayIdx, int16 objectIdx, + objectParamsQuery * returnParam); } // End of namespace Cruise diff --git a/engines/cruise/overlay.cpp b/engines/cruise/overlay.cpp index ff7711b8ea..c221d07a0b 100644 --- a/engines/cruise/overlay.cpp +++ b/engines/cruise/overlay.cpp @@ -29,122 +29,120 @@ namespace Cruise { overlayStruct overlayTable[90]; int numOfLoadedOverlay; -void initOverlayTable(void) -{ - int i; - - for(i=0;i<90;i++) - { - overlayTable[i].overlayName[0] = 0; - overlayTable[i].ovlData = NULL; - overlayTable[i].alreadyLoaded = 0; - overlayTable[i].executeScripts = 0; - } +void initOverlayTable(void) { + int i; + + for (i = 0; i < 90; i++) { + overlayTable[i].overlayName[0] = 0; + overlayTable[i].ovlData = NULL; + overlayTable[i].alreadyLoaded = 0; + overlayTable[i].executeScripts = 0; + } - numOfLoadedOverlay = 1; + numOfLoadedOverlay = 1; } -int loadOverlay(uint8* scriptName) -{ - int newNumberOfScript; - bool scriptNotLoadedBefore; - int scriptIdx; - uint8 fileName[50]; - int fileIdx; - int unpackedSize; - char* unpackedBuffer; - char* scriptPtr; - ovlDataStruct* ovlData; +int loadOverlay(uint8 *scriptName) { + int newNumberOfScript; + bool scriptNotLoadedBefore; + int scriptIdx; + uint8 fileName[50]; + int fileIdx; + int unpackedSize; + char *unpackedBuffer; + char *scriptPtr; + ovlDataStruct *ovlData; - printf("Load overlay: %s\n",scriptName); + printf("Load overlay: %s\n", scriptName); - newNumberOfScript = numOfLoadedOverlay; + newNumberOfScript = numOfLoadedOverlay; - scriptNotLoadedBefore = false; + scriptNotLoadedBefore = false; - scriptIdx = findOverlayByName((char*)scriptName); + scriptIdx = findOverlayByName((char *)scriptName); - if(scriptIdx == -4) - { - scriptIdx = numOfLoadedOverlay; + if (scriptIdx == -4) { + scriptIdx = numOfLoadedOverlay; - newNumberOfScript++; + newNumberOfScript++; - scriptNotLoadedBefore = true; - } + scriptNotLoadedBefore = true; + } - if(overlayTable[scriptIdx].alreadyLoaded) - { - return (scriptIdx); - } + if (overlayTable[scriptIdx].alreadyLoaded) { + return (scriptIdx); + } - overlayTable[scriptIdx].ovlData = (ovlDataStruct*) mallocAndZero(sizeof(ovlDataStruct)); + overlayTable[scriptIdx].ovlData = + (ovlDataStruct *) mallocAndZero(sizeof(ovlDataStruct)); - if(!overlayTable[scriptIdx].ovlData) - return(-2); + if (!overlayTable[scriptIdx].ovlData) + return (-2); - strcpyuint8(overlayTable[scriptIdx].overlayName, scriptName); + strcpyuint8(overlayTable[scriptIdx].overlayName, scriptName); - overlayTable[scriptIdx].alreadyLoaded = 1; + overlayTable[scriptIdx].alreadyLoaded = 1; - numOfLoadedOverlay = newNumberOfScript; + numOfLoadedOverlay = newNumberOfScript; - overlayTable[scriptIdx].ovlData->scriptNumber = scriptIdx; - - strcpyuint8(fileName,scriptName); + overlayTable[scriptIdx].ovlData->scriptNumber = scriptIdx; - strcatuint8(fileName,".OVL"); + strcpyuint8(fileName, scriptName); - printf("Attempting to load overlay file %s...\n", fileName); - - fileIdx = findFileInDisks(fileName); + strcatuint8(fileName, ".OVL"); - if(fileIdx<0) - { - printf("Unable to load overlay %s !\n", scriptName); - //releaseScript(scriptName); - return(-18); - } + printf("Attempting to load overlay file %s...\n", fileName); - unpackedSize = volumePtrToFileDescriptor[fileIdx].extSize + 2; - - // TODO: here, can unpack in gfx module buffer - unpackedBuffer = (char*)mallocAndZero(unpackedSize); + fileIdx = findFileInDisks(fileName); - if(!unpackedBuffer) - { - return(-2); - } + if (fileIdx < 0) { + printf("Unable to load overlay %s !\n", scriptName); + //releaseScript(scriptName); + return (-18); + } - if(volumePtrToFileDescriptor[fileIdx].size +2 != unpackedSize) - { - char* tempBuffer; - uint16 realUnpackedSize; - char* pakedBuffer = (char*) mallocAndZero(volumePtrToFileDescriptor[fileIdx].size +2); + unpackedSize = volumePtrToFileDescriptor[fileIdx].extSize + 2; - loadPakedFileToMem(fileIdx,(uint8*)pakedBuffer); + // TODO: here, can unpack in gfx module buffer + unpackedBuffer = (char *)mallocAndZero(unpackedSize); - realUnpackedSize = *(int16*)(pakedBuffer+volumePtrToFileDescriptor[fileIdx].size-2); - flipShort(&realUnpackedSize); + if (!unpackedBuffer) { + return (-2); + } - tempBuffer = (char*)mallocAndZero(realUnpackedSize); + if (volumePtrToFileDescriptor[fileIdx].size + 2 != unpackedSize) { + char *tempBuffer; + uint16 realUnpackedSize; + char *pakedBuffer = + (char *)mallocAndZero(volumePtrToFileDescriptor[fileIdx]. + size + 2); - decomp((uint8*)pakedBuffer+volumePtrToFileDescriptor[fileIdx].size-4,(uint8*)unpackedBuffer+realUnpackedSize,realUnpackedSize); + loadPakedFileToMem(fileIdx, (uint8 *) pakedBuffer); - free(pakedBuffer); - } - else - { - loadPakedFileToMem(fileIdx,(uint8*)unpackedBuffer); - } + realUnpackedSize = + *(int16 *) (pakedBuffer + + volumePtrToFileDescriptor[fileIdx].size - 2); + flipShort(&realUnpackedSize); + + tempBuffer = (char *)mallocAndZero(realUnpackedSize); - printf("OVL loading done...\n"); + decomp((uint8 *) pakedBuffer + + volumePtrToFileDescriptor[fileIdx].size - 4, + (uint8 *) unpackedBuffer + realUnpackedSize, + realUnpackedSize); + + free(pakedBuffer); + } else { + loadPakedFileToMem(fileIdx, (uint8 *) unpackedBuffer); + } - scriptPtr = unpackedBuffer; + printf("OVL loading done...\n"); - ovlData = overlayTable[scriptIdx].ovlData; + scriptPtr = unpackedBuffer; - memcpy(ovlData,scriptPtr, sizeof(ovlDataStruct)); + ovlData = overlayTable[scriptIdx].ovlData; + + memcpy(ovlData, scriptPtr, sizeof(ovlDataStruct)); ovlData->data3Table = NULL; ovlData->ptr1 = NULL; @@ -161,228 +159,231 @@ int loadOverlay(uint8* scriptName) ovlData->exportNamesPtr = NULL; ovlData->data4Ptr = NULL; ovlData->ptr8 = NULL; - ovlData->numScripts1 = readB16(scriptPtr+60); - ovlData->numScripts2 = readB16(scriptPtr+62); - ovlData->numExport = readB16(scriptPtr+64); - ovlData->numImport = readB16(scriptPtr+66); - ovlData->numLinkData = readB16(scriptPtr+68); - ovlData->numObjData = readB16(scriptPtr+70); - ovlData->numStrings = readB16(scriptPtr+72); - ovlData->size8 = readB16(scriptPtr+74); - ovlData->size9 = readB16(scriptPtr+76); - ovlData->nameExportSize = readB16(scriptPtr+78); - ovlData->exportNamesSize = readB16(scriptPtr+80); - ovlData->specialString2Length = readB16(scriptPtr+82); - ovlData->sizeOfData4 = readB16(scriptPtr+84); - ovlData->size12 = readB16(scriptPtr+86); - ovlData->specialString1Length = readB16(scriptPtr+88); - ovlData->scriptNumber = readB16(scriptPtr+90); - - scriptPtr += 92; - - if(ovlData->numExport) // export data - { + ovlData->numScripts1 = readB16(scriptPtr + 60); + ovlData->numScripts2 = readB16(scriptPtr + 62); + ovlData->numExport = readB16(scriptPtr + 64); + ovlData->numImport = readB16(scriptPtr + 66); + ovlData->numLinkData = readB16(scriptPtr + 68); + ovlData->numObjData = readB16(scriptPtr + 70); + ovlData->numStrings = readB16(scriptPtr + 72); + ovlData->size8 = readB16(scriptPtr + 74); + ovlData->size9 = readB16(scriptPtr + 76); + ovlData->nameExportSize = readB16(scriptPtr + 78); + ovlData->exportNamesSize = readB16(scriptPtr + 80); + ovlData->specialString2Length = readB16(scriptPtr + 82); + ovlData->sizeOfData4 = readB16(scriptPtr + 84); + ovlData->size12 = readB16(scriptPtr + 86); + ovlData->specialString1Length = readB16(scriptPtr + 88); + ovlData->scriptNumber = readB16(scriptPtr + 90); + + scriptPtr += 92; + + if (ovlData->numExport) { // export data int i; - ovlData->exportDataPtr = (exportEntryStruct*)mallocAndZero(ovlData->numExport*sizeof(exportEntryStruct)); + ovlData->exportDataPtr = + (exportEntryStruct *) mallocAndZero(ovlData->numExport * + sizeof(exportEntryStruct)); - if(!ovlData->exportDataPtr) - { - return(-2); - } + if (!ovlData->exportDataPtr) { + return (-2); + } - for(i=0;i<ovlData->numExport;i++) - { + for (i = 0; i < ovlData->numExport; i++) { ovlData->exportDataPtr[i].var0 = readB16(scriptPtr); - ovlData->exportDataPtr[i].var2 = readB16(scriptPtr+2); - ovlData->exportDataPtr[i].var4 = readB16(scriptPtr+4); - ovlData->exportDataPtr[i].idx = readB16(scriptPtr+6); - ovlData->exportDataPtr[i].offsetToName = readB16(scriptPtr+8); - - scriptPtr+=10; + ovlData->exportDataPtr[i].var2 = + readB16(scriptPtr + 2); + ovlData->exportDataPtr[i].var4 = + readB16(scriptPtr + 4); + ovlData->exportDataPtr[i].idx = readB16(scriptPtr + 6); + ovlData->exportDataPtr[i].offsetToName = + readB16(scriptPtr + 8); + + scriptPtr += 10; } - } - - if(ovlData->exportNamesSize) // export names - { - ovlData->exportNamesPtr = (uint8*)mallocAndZero(ovlData->exportNamesSize); + } - if(!ovlData->exportNamesPtr) - { - return(-2); - } + if (ovlData->exportNamesSize) { // export names + ovlData->exportNamesPtr = + (uint8 *) mallocAndZero(ovlData->exportNamesSize); - memcpy(ovlData->exportNamesPtr, scriptPtr, ovlData->exportNamesSize); - scriptPtr += ovlData->exportNamesSize; - } + if (!ovlData->exportNamesPtr) { + return (-2); + } - if(ovlData->numImport) // import data - { + memcpy(ovlData->exportNamesPtr, scriptPtr, + ovlData->exportNamesSize); + scriptPtr += ovlData->exportNamesSize; + } + + if (ovlData->numImport) { // import data int i; - ovlData->importDataPtr = (importDataStruct*)mallocAndZero(ovlData->numImport * sizeof(importDataStruct)); + ovlData->importDataPtr = + (importDataStruct *) mallocAndZero(ovlData->numImport * + sizeof(importDataStruct)); - if(!ovlData->importDataPtr) - { - return(-2); - } + if (!ovlData->importDataPtr) { + return (-2); + } - for(i=0;i<ovlData->numImport;i++) - { + for (i = 0; i < ovlData->numImport; i++) { ovlData->importDataPtr[i].var0 = readB16(scriptPtr); - ovlData->importDataPtr[i].var1 = readB16(scriptPtr+2); - ovlData->importDataPtr[i].linkType = readB16(scriptPtr+4); - ovlData->importDataPtr[i].linkIdx = readB16(scriptPtr+6); - ovlData->importDataPtr[i].nameOffset = readB16(scriptPtr+8); - - scriptPtr+=10; + ovlData->importDataPtr[i].var1 = + readB16(scriptPtr + 2); + ovlData->importDataPtr[i].linkType = + readB16(scriptPtr + 4); + ovlData->importDataPtr[i].linkIdx = + readB16(scriptPtr + 6); + ovlData->importDataPtr[i].nameOffset = + readB16(scriptPtr + 8); + + scriptPtr += 10; } } - - if(ovlData->nameExportSize) // import name - { - ovlData->importNamePtr = (uint8*)mallocAndZero(ovlData->nameExportSize); - if(!ovlData->importNamePtr) - { - return(-2); - } + if (ovlData->nameExportSize) { // import name + ovlData->importNamePtr = + (uint8 *) mallocAndZero(ovlData->nameExportSize); - memcpy(ovlData->importNamePtr, scriptPtr, ovlData->nameExportSize); - scriptPtr += ovlData->nameExportSize; - } + if (!ovlData->importNamePtr) { + return (-2); + } - if(ovlData->numLinkData) // link data - { - ASSERT(sizeof(linkDataStruct) == 0x22); + memcpy(ovlData->importNamePtr, scriptPtr, + ovlData->nameExportSize); + scriptPtr += ovlData->nameExportSize; + } - ovlData->linkDataPtr = (linkDataStruct*)mallocAndZero(ovlData->numLinkData*sizeof(linkDataStruct)); + if (ovlData->numLinkData) { // link data + ASSERT(sizeof(linkDataStruct) == 0x22); - if(!ovlData->linkDataPtr) - { - return(-2); - } + ovlData->linkDataPtr = + (linkDataStruct *) mallocAndZero(ovlData->numLinkData * + sizeof(linkDataStruct)); - memcpy(ovlData->linkDataPtr, scriptPtr, ovlData->numLinkData*sizeof(linkDataStruct)); - scriptPtr += ovlData->numLinkData*sizeof(linkDataStruct); - flipGen(ovlData->linkDataPtr,ovlData->numLinkData*sizeof(linkDataStruct)); - } + if (!ovlData->linkDataPtr) { + return (-2); + } - if(ovlData->numScripts1) // script - { - ovlData3Struct* tempPtr; - int i; + memcpy(ovlData->linkDataPtr, scriptPtr, + ovlData->numLinkData * sizeof(linkDataStruct)); + scriptPtr += ovlData->numLinkData * sizeof(linkDataStruct); + flipGen(ovlData->linkDataPtr, + ovlData->numLinkData * sizeof(linkDataStruct)); + } + + if (ovlData->numScripts1) { // script + ovlData3Struct *tempPtr; + int i; - ovlData->data3Table = (ovlData3Struct*)mallocAndZero(ovlData->numScripts1 * sizeof(ovlData3Struct)); + ovlData->data3Table = + (ovlData3Struct *) mallocAndZero(ovlData->numScripts1 * + sizeof(ovlData3Struct)); - if(!ovlData->data3Table) - { + if (!ovlData->data3Table) { /* releaseScript(scriptIdx,scriptName); - if(freeIsNeeded) - { + if(freeIsNeeded) { freePtr(unpackedBuffer); } */ - return(-2); - } + return (-2); + } - memcpy(ovlData->data3Table, scriptPtr, ovlData->numScripts1 * sizeof(ovlData3Struct)); - scriptPtr += ovlData->numScripts1 * 0x1C; + memcpy(ovlData->data3Table, scriptPtr, + ovlData->numScripts1 * sizeof(ovlData3Struct)); + scriptPtr += ovlData->numScripts1 * 0x1C; - flipGen(ovlData->data3Table,ovlData->numScripts1 * sizeof(ovlData3Struct)); + flipGen(ovlData->data3Table, + ovlData->numScripts1 * sizeof(ovlData3Struct)); - tempPtr = ovlData->data3Table; + tempPtr = ovlData->data3Table; - for(i=0;i<ovlData->numScripts1;i++) - { - uint8* ptr = tempPtr->dataPtr = (uint8*) mallocAndZero(tempPtr->sizeOfData); + for (i = 0; i < ovlData->numScripts1; i++) { + uint8 *ptr = tempPtr->dataPtr = + (uint8 *) mallocAndZero(tempPtr->sizeOfData); - if(!ptr) - { - /* releaseScript(scriptIdx,scriptName); + if (!ptr) { + /* releaseScript(scriptIdx,scriptName); + * + * if(freeIsNeeded) + * { + * freePtr(unpackedBuffer); + * } */ - if(freeIsNeeded) - { - freePtr(unpackedBuffer); - } */ + return (-2); + } - return(-2); - } + memcpy(ptr, scriptPtr, tempPtr->sizeOfData); + scriptPtr += tempPtr->sizeOfData; - memcpy( ptr, scriptPtr, tempPtr->sizeOfData ); - scriptPtr+= tempPtr->sizeOfData; + if (tempPtr->offsetToImportData) { + flipGen(ptr + tempPtr->offsetToImportData, + tempPtr->numImport * 10); + } - if(tempPtr->offsetToImportData) - { - flipGen(ptr+tempPtr->offsetToImportData,tempPtr->numImport*10); - } + if (tempPtr->offsetToSubData2) { + flipGen(ptr + tempPtr->offsetToImportData, + tempPtr->subData2Size * 10); + } - if(tempPtr->offsetToSubData2) - { - flipGen(ptr+tempPtr->offsetToImportData,tempPtr->subData2Size*10); - } + tempPtr++; + } + } - tempPtr++; - } - } + if (ovlData->numScripts2) { + ovlData3Struct *tempPtr; + int i; - if(ovlData->numScripts2) - { - ovlData3Struct* tempPtr; - int i; - - ovlData->ptr1 = (uint8*)mallocAndZero(ovlData->numScripts2*0x1C); + ovlData->ptr1 = + (uint8 *) mallocAndZero(ovlData->numScripts2 * 0x1C); - if(!ovlData->ptr1) - { - return(-2); - } + if (!ovlData->ptr1) { + return (-2); + } - memcpy(ovlData->ptr1, scriptPtr, ovlData->numScripts2 * 0x1C); - scriptPtr += ovlData->numScripts2*0x1C; - flipGen(ovlData->ptr1,ovlData->numScripts2*0x1C); + memcpy(ovlData->ptr1, scriptPtr, ovlData->numScripts2 * 0x1C); + scriptPtr += ovlData->numScripts2 * 0x1C; + flipGen(ovlData->ptr1, ovlData->numScripts2 * 0x1C); - tempPtr = (ovlData3Struct*)ovlData->ptr1; + tempPtr = (ovlData3Struct *) ovlData->ptr1; - for(i=0;i<ovlData->numScripts2;i++) - { - uint8* ptr = tempPtr->dataPtr = (uint8*) mallocAndZero(tempPtr->sizeOfData); + for (i = 0; i < ovlData->numScripts2; i++) { + uint8 *ptr = tempPtr->dataPtr = + (uint8 *) mallocAndZero(tempPtr->sizeOfData); - if(!ptr) - { - /* releaseScript(scriptIdx,scriptName); + if (!ptr) { + /* releaseScript(scriptIdx,scriptName); + * + * if(freeIsNeeded) + * { + * freePtr(unpackedBuffer); + * } */ - if(freeIsNeeded) - { - freePtr(unpackedBuffer); - } */ + return (-2); + } - return(-2); - } + memcpy(ptr, scriptPtr, tempPtr->sizeOfData); + scriptPtr += tempPtr->sizeOfData; - memcpy( ptr, scriptPtr, tempPtr->sizeOfData ); - scriptPtr+= tempPtr->sizeOfData; + if (tempPtr->offsetToImportData) { + flipGen(ptr + tempPtr->offsetToImportData, + tempPtr->numImport * 10); + } - if(tempPtr->offsetToImportData) - { - flipGen(ptr+tempPtr->offsetToImportData,tempPtr->numImport*10); - } + if (tempPtr->offsetToSubData2) { + flipGen(ptr + tempPtr->offsetToImportData, + tempPtr->subData2Size * 10); + } - if(tempPtr->offsetToSubData2) - { - flipGen(ptr+tempPtr->offsetToImportData,tempPtr->subData2Size*10); - } - - tempPtr++; - } - } + tempPtr++; + } + } - if(ovlData->size12) - { - ovlData->ptr8 = (uint8*)mallocAndZero(ovlData->size12); + if (ovlData->size12) { + ovlData->ptr8 = (uint8 *) mallocAndZero(ovlData->size12); - if(!ovlData->ptr8) - { + if (!ovlData->ptr8) { /* releaseScript(scriptIdx,scriptName); if(freeIsNeeded) @@ -390,20 +391,20 @@ int loadOverlay(uint8* scriptName) freePtr(unpackedBuffer); } */ - return(-2); - } + return (-2); + } - memcpy(ovlData->ptr8, scriptPtr, ovlData->size12); - scriptPtr += ovlData->size12; - } + memcpy(ovlData->ptr8, scriptPtr, ovlData->size12); + scriptPtr += ovlData->size12; + } - if(ovlData->numObjData) - { + if (ovlData->numObjData) { int i; - ovlData->objDataTable = (objDataStruct*)mallocAndZero(ovlData->numObjData*sizeof(objDataStruct)); + ovlData->objDataTable = + (objDataStruct *) mallocAndZero(ovlData->numObjData * + sizeof(objDataStruct)); - if(!ovlData->objDataTable) - { + if (!ovlData->objDataTable) { /* releaseScript(scriptIdx,scriptName); if(freeIsNeeded) @@ -411,61 +412,60 @@ int loadOverlay(uint8* scriptName) freePtr(unpackedBuffer); } */ - return(-2); - } + return (-2); + } - for(i=0;i<ovlData->numObjData;i++) - { - ovlData->objDataTable[i].var0 = *(int16*)scriptPtr; - scriptPtr+=2; + for (i = 0; i < ovlData->numObjData; i++) { + ovlData->objDataTable[i].var0 = *(int16 *) scriptPtr; + scriptPtr += 2; flipShort(&ovlData->objDataTable[i].var0); - ovlData->objDataTable[i].var1 = *(int16*)scriptPtr; - scriptPtr+=2; + ovlData->objDataTable[i].var1 = *(int16 *) scriptPtr; + scriptPtr += 2; flipShort(&ovlData->objDataTable[i].var1); - ovlData->objDataTable[i].var2 = *(int16*)scriptPtr; - scriptPtr+=2; + ovlData->objDataTable[i].var2 = *(int16 *) scriptPtr; + scriptPtr += 2; flipShort(&ovlData->objDataTable[i].var2); - ovlData->objDataTable[i].var3 = *(int16*)scriptPtr; - scriptPtr+=2; + ovlData->objDataTable[i].var3 = *(int16 *) scriptPtr; + scriptPtr += 2; flipShort(&ovlData->objDataTable[i].var3); - ovlData->objDataTable[i].var4 = *(int16*)scriptPtr; - scriptPtr+=2; + ovlData->objDataTable[i].var4 = *(int16 *) scriptPtr; + scriptPtr += 2; flipShort(&ovlData->objDataTable[i].var4); - ovlData->objDataTable[i].var5 = *(int16*)scriptPtr; - scriptPtr+=2; + ovlData->objDataTable[i].var5 = *(int16 *) scriptPtr; + scriptPtr += 2; flipShort(&ovlData->objDataTable[i].var5); - ovlData->objDataTable[i].var6 = *(int16*)scriptPtr; - scriptPtr+=2; + ovlData->objDataTable[i].var6 = *(int16 *) scriptPtr; + scriptPtr += 2; flipShort(&ovlData->objDataTable[i].var6); } - if(scriptNotLoadedBefore) - { - //int var1; - //int var2; - - overlayTable[scriptIdx].field_14 = (char)setup1; + if (scriptNotLoadedBefore) { + //int var1; + //int var2; - var1 = loadScriptSub1(scriptIdx,3); - var2 = loadScriptSub1(scriptIdx,0); + overlayTable[scriptIdx].field_14 = (char)setup1; - setup1 = var1 + var2; - } - } + var1 = loadScriptSub1(scriptIdx, 3); + var2 = loadScriptSub1(scriptIdx, 0); - if(ovlData->size9) - { - ovlData->objData2WorkTable = (objectParams*)mallocAndZero(ovlData->size9 * sizeof(objectParams)); - memset(ovlData->objData2WorkTable, 0, ovlData->size9 * sizeof(objectParams)); + setup1 = var1 + var2; + } + } + + if (ovlData->size9) { + ovlData->objData2WorkTable = + (objectParams *) mallocAndZero(ovlData->size9 * + sizeof(objectParams)); + memset(ovlData->objData2WorkTable, 0, + ovlData->size9 * sizeof(objectParams)); - if(!ovlData->objData2WorkTable) - { + if (!ovlData->objData2WorkTable) { /* releaseScript(scriptIdx,scriptName); if(freeIsNeeded) @@ -473,16 +473,16 @@ int loadOverlay(uint8* scriptName) freePtr(unpackedBuffer); } */ - return(-2); - } - } + return (-2); + } + } - if(ovlData->size8) - { - ovlData->objData2SourceTable = (objectParams*)mallocAndZero(ovlData->size8 * sizeof(objectParams)); + if (ovlData->size8) { + ovlData->objData2SourceTable = + (objectParams *) mallocAndZero(ovlData->size8 * + sizeof(objectParams)); - if(!ovlData->objData2SourceTable) - { + if (!ovlData->objData2SourceTable) { /* releaseScript(scriptIdx,scriptName); if(freeIsNeeded) @@ -490,232 +490,236 @@ int loadOverlay(uint8* scriptName) freePtr(unpackedBuffer); } */ - return(-2); - } + return (-2); + } - memcpy(ovlData->objData2SourceTable, scriptPtr, ovlData->size8*12); // TODO: made read item by item - scriptPtr += ovlData->size8*12; - flipGen(ovlData->objData2SourceTable,ovlData->size8*12); - } + memcpy(ovlData->objData2SourceTable, scriptPtr, ovlData->size8 * 12); // TODO: made read item by item + scriptPtr += ovlData->size8 * 12; + flipGen(ovlData->objData2SourceTable, ovlData->size8 * 12); + } - if(ovlData->numStrings) - { - int i; - - ovlData->stringTable = (stringEntryStruct*)mallocAndZero(ovlData->numStrings*sizeof(stringEntryStruct)); - - for(i=0;i<ovlData->numStrings;i++) - { - ovlData->stringTable[i].idx = *(int16*)scriptPtr; - flipShort(&ovlData->stringTable[i].idx); - scriptPtr+=2; - } - } + if (ovlData->numStrings) { + int i; + + ovlData->stringTable = + (stringEntryStruct *) mallocAndZero(ovlData->numStrings * + sizeof(stringEntryStruct)); + + for (i = 0; i < ovlData->numStrings; i++) { + ovlData->stringTable[i].idx = *(int16 *) scriptPtr; + flipShort(&ovlData->stringTable[i].idx); + scriptPtr += 2; + } + } /* if(freeIsNeeded) { freePtr(unpackedBuffer); } */ - if(ovlData->sizeOfData4) - { - ovlData->data4Ptr = (uint8*)mallocAndZero(ovlData->sizeOfData4); - memset(ovlData->data4Ptr,0,ovlData->sizeOfData4); - - if(!ovlData->data4Ptr) - { - //releaseScript(scriptIdx,scriptName); - return(-2); - } - } - - if(ovlData->specialString1Length /*|| ovlData->specialString2Length*/ || ovlData->stringTable) - { - int i; - //int unpackedSize; - //int fileIdx; - //uint8 fileName[50]; - //char* unpackedBuffer; - - strcpyuint8(fileName,scriptName); - - strcatuint8(fileName,".FR"); - - fileIdx = findFileInDisks(fileName); - - if(fileIdx<0) - { - //releaseScript(scriptName); - return(-18); - } - - unpackedSize = volumePtrToFileDescriptor[fileIdx].extSize + 2; - - // TODO: here, can unpack in gfx module buffer - unpackedBuffer = (char*)mallocAndZero(unpackedSize); - - if(!unpackedBuffer) - { - return(-2); - } - - if(volumePtrToFileDescriptor[fileIdx].size +2 != unpackedSize) - { - short int realUnpackedSize; - char* pakedBuffer = (char*) mallocAndZero(volumePtrToFileDescriptor[fileIdx].size +2); - - loadPakedFileToMem(fileIdx,(uint8*)pakedBuffer); - - realUnpackedSize = *(int16*)(pakedBuffer+volumePtrToFileDescriptor[fileIdx].size-2); - flipShort(&realUnpackedSize); - - decomp((uint8*)pakedBuffer+volumePtrToFileDescriptor[fileIdx].size-4,(uint8*)unpackedBuffer+realUnpackedSize,realUnpackedSize); + if (ovlData->sizeOfData4) { + ovlData->data4Ptr = + (uint8 *) mallocAndZero(ovlData->sizeOfData4); + memset(ovlData->data4Ptr, 0, ovlData->sizeOfData4); - free(pakedBuffer); - } - else - { - loadPakedFileToMem(fileIdx,(uint8*)unpackedBuffer); - } - - scriptPtr = unpackedBuffer; - - memcpy(&ovlData->specialString1Length,scriptPtr,2); - scriptPtr+=2; - flipShort(&ovlData->specialString1Length); // recheck if needed - - if(ovlData->specialString1Length) - { - ovlData->specialString1 = (uint8*)mallocAndZero(ovlData->specialString1Length); + if (!ovlData->data4Ptr) { + //releaseScript(scriptIdx,scriptName); + return (-2); + } + } - if(!ovlData->specialString1) - { - /* releaseScript(scriptIdx,scriptName); + if (ovlData-> + specialString1Length /*|| ovlData->specialString2Length */ + || ovlData->stringTable) { + int i; + //int unpackedSize; + //int fileIdx; + //uint8 fileName[50]; + //char* unpackedBuffer; - if(freeIsNeeded) - { - freePtr(unpackedBuffer); - } */ + strcpyuint8(fileName, scriptName); - return(-2); - } + strcatuint8(fileName, ".FR"); - memcpy(ovlData->specialString1, scriptPtr, ovlData->specialString1Length); - scriptPtr += ovlData->specialString1Length; - } + fileIdx = findFileInDisks(fileName); - memcpy(&ovlData->specialString2Length,scriptPtr,2); - scriptPtr+=2; - flipShort(&ovlData->specialString2Length); // recheck if needed + if (fileIdx < 0) { + //releaseScript(scriptName); + return (-18); + } - if(ovlData->specialString2Length) - { - ovlData->specialString2 = (uint8*)mallocAndZero(ovlData->specialString2Length); + unpackedSize = volumePtrToFileDescriptor[fileIdx].extSize + 2; - if(!ovlData->specialString2) - { - /* releaseScript(scriptIdx,scriptName); + // TODO: here, can unpack in gfx module buffer + unpackedBuffer = (char *)mallocAndZero(unpackedSize); - if(freeIsNeeded) - { - freePtr(unpackedBuffer); - } */ + if (!unpackedBuffer) { + return (-2); + } - return(-2); - } + if (volumePtrToFileDescriptor[fileIdx].size + 2 != + unpackedSize) { + short int realUnpackedSize; + char *pakedBuffer = + (char *) + mallocAndZero(volumePtrToFileDescriptor[fileIdx]. + size + 2); + + loadPakedFileToMem(fileIdx, (uint8 *) pakedBuffer); + + realUnpackedSize = + *(int16 *) (pakedBuffer + + volumePtrToFileDescriptor[fileIdx].size - 2); + flipShort(&realUnpackedSize); + + decomp((uint8 *) pakedBuffer + + volumePtrToFileDescriptor[fileIdx].size - 4, + (uint8 *) unpackedBuffer + realUnpackedSize, + realUnpackedSize); + + free(pakedBuffer); + } else { + loadPakedFileToMem(fileIdx, (uint8 *) unpackedBuffer); + } - memcpy(ovlData->specialString2, scriptPtr, ovlData->specialString2Length); - scriptPtr += ovlData->specialString2Length; - } + scriptPtr = unpackedBuffer; - for(i=0;i<ovlData->numStrings;i++) - { - ovlData->stringTable[i].length = *(int16*)scriptPtr; - scriptPtr +=2; - flipShort(&ovlData->stringTable[i].length); + memcpy(&ovlData->specialString1Length, scriptPtr, 2); + scriptPtr += 2; + flipShort(&ovlData->specialString1Length); // recheck if needed - if(ovlData->stringTable[i].length) - { - ovlData->stringTable[i].string = (char*)mallocAndZero(ovlData->stringTable[i].length); + if (ovlData->specialString1Length) { + ovlData->specialString1 = + (uint8 *) mallocAndZero(ovlData-> + specialString1Length); - if(!ovlData->stringTable[i].string) - { - /* releaseScript(scriptIdx,scriptName); + if (!ovlData->specialString1) { + /* releaseScript(scriptIdx,scriptName); + * + * if(freeIsNeeded) + * { + * freePtr(unpackedBuffer); + * } */ - if(freeIsNeeded) - { - freePtr(unpackedBuffer); - } */ + return (-2); + } - return(-2); - } + memcpy(ovlData->specialString1, scriptPtr, + ovlData->specialString1Length); + scriptPtr += ovlData->specialString1Length; + } - memcpy(ovlData->stringTable[i].string,scriptPtr,ovlData->stringTable[i].length); - scriptPtr += ovlData->stringTable[i].length; - } - } - } + memcpy(&ovlData->specialString2Length, scriptPtr, 2); + scriptPtr += 2; + flipShort(&ovlData->specialString2Length); // recheck if needed + + if (ovlData->specialString2Length) { + ovlData->specialString2 = + (uint8 *) mallocAndZero(ovlData-> + specialString2Length); + + if (!ovlData->specialString2) { + /* releaseScript(scriptIdx,scriptName); + * + * if(freeIsNeeded) + * { + * freePtr(unpackedBuffer); + * } */ + + return (-2); + } + + memcpy(ovlData->specialString2, scriptPtr, + ovlData->specialString2Length); + scriptPtr += ovlData->specialString2Length; + } + for (i = 0; i < ovlData->numStrings; i++) { + ovlData->stringTable[i].length = *(int16 *) scriptPtr; + scriptPtr += 2; + flipShort(&ovlData->stringTable[i].length); + + if (ovlData->stringTable[i].length) { + ovlData->stringTable[i].string = + (char *)mallocAndZero(ovlData-> + stringTable[i].length); + + if (!ovlData->stringTable[i].string) { + /* releaseScript(scriptIdx,scriptName); + * + * if(freeIsNeeded) + * { + * freePtr(unpackedBuffer); + * } */ + + return (-2); + } + + memcpy(ovlData->stringTable[i].string, + scriptPtr, ovlData->stringTable[i].length); + scriptPtr += ovlData->stringTable[i].length; + } + } + } #ifdef DUMP_SCRIPT - { - int i; - for(i=0;i<ovlData->numScripts1;i++) - { - dumpScript(scriptName,ovlData,i); - } - } + { + int i; + for (i = 0; i < ovlData->numScripts1; i++) { + dumpScript(scriptName, ovlData, i); + } + } #endif #ifdef DUMP_OBJECT - { - int i; - FILE* fHandle; - char nameBundle[100]; - sprintf(nameBundle, "%s-objs.txt",scriptName); - - fHandle = fopen(nameBundle, "w+"); - ASSERT(fHandle); + { + int i; + FILE *fHandle; + char nameBundle[100]; + sprintf(nameBundle, "%s-objs.txt", scriptName); + + fHandle = fopen(nameBundle, "w+"); + ASSERT(fHandle); + + for (i = 0; i < ovlData->numLinkData; i++) { + linkDataStruct *var_34; + var_34 = &ovlData->linkDataPtr[i]; + + if (ovlData->specialString2) { + fprintf(fHandle, "----- object %02d -----\n", + i); + if (var_34->stringNameOffset != 0xFFFF) { + fprintf(fHandle, "name: %s\n", + getObjectName(var_34-> + stringNameOffset, + ovlData->specialString2)); + } + } + } - for(i=0;i<ovlData->numLinkData;i++) - { - linkDataStruct* var_34; - var_34 = &ovlData->linkDataPtr[i]; - - if(ovlData->specialString2) - { - fprintf(fHandle,"----- object %02d -----\n", i); - if(var_34->stringNameOffset != 0xFFFF) - { - fprintf(fHandle,"name: %s\n",getObjectName(var_34->stringNameOffset, ovlData->specialString2)); - } - } - } - - fclose(fHandle); - } + fclose(fHandle); + } #endif - return(scriptIdx); + return (scriptIdx); } -int releaseOverlay(const char* name) -{ - int overlayIdx; - ovlDataStruct* ovlDataPtr; - - overlayIdx = findOverlayByName(name); +int releaseOverlay(const char *name) { + int overlayIdx; + ovlDataStruct *ovlDataPtr; - if(overlayIdx == -4) - return -4; + overlayIdx = findOverlayByName(name); - if(overlayTable[overlayIdx].alreadyLoaded == 0) - return -4; + if (overlayIdx == -4) + return -4; - overlayTable[overlayIdx].alreadyLoaded = 0; + if (overlayTable[overlayIdx].alreadyLoaded == 0) + return -4; - ovlDataPtr = overlayTable[overlayIdx].ovlData; + overlayTable[overlayIdx].alreadyLoaded = 0; - if(!ovlDataPtr) - return -4; + ovlDataPtr = overlayTable[overlayIdx].ovlData; + + if (!ovlDataPtr) + return -4; /* if(overlayTable[overlayIdx].var1E) { @@ -729,44 +733,38 @@ int releaseOverlay(const char* name) overlayTable[overlayIdx].var16 = NULL; } */ - removeScript(overlayIdx,-1,&scriptHandle2); - removeScript(overlayIdx,-1,&scriptHandle2); + removeScript(overlayIdx, -1, &scriptHandle2); + removeScript(overlayIdx, -1, &scriptHandle2); + + removeScript(overlayIdx, -1, &scriptHandle1); + removeScript(overlayIdx, -1, &scriptHandle1); - removeScript(overlayIdx,-1,&scriptHandle1); - removeScript(overlayIdx,-1,&scriptHandle1); + printf("releaseOverlay: finish !\n"); - printf("releaseOverlay: finish !\n"); - - return 0; + return 0; } -int32 findOverlayByName2(uint8* name) -{ - int i; +int32 findOverlayByName2(uint8 *name) { + int i; - for(i=1;i<numOfLoadedOverlay;i++) - { - if(!strcmpuint8(overlayTable[i].overlayName,name)) - return(i); - } + for (i = 1; i < numOfLoadedOverlay; i++) { + if (!strcmpuint8(overlayTable[i].overlayName, name)) + return (i); + } - return(-4); + return (-4); } -int findOverlayByName(const char* overlayName) -{ - int i; +int findOverlayByName(const char *overlayName) { + int i; - for(i=1;i<numOfLoadedOverlay;i++) - { - if(!strcmp(overlayTable[i].overlayName,overlayName)) - { - return(i); - } - } + for (i = 1; i < numOfLoadedOverlay; i++) { + if (!strcmp(overlayTable[i].overlayName, overlayName)) { + return (i); + } + } - return(-4); + return (-4); } - } // End of namespace Cruise diff --git a/engines/cruise/overlay.h b/engines/cruise/overlay.h index f5e3ec4fdc..d09f79fcd4 100644 --- a/engines/cruise/overlay.h +++ b/engines/cruise/overlay.h @@ -22,39 +22,36 @@ * */ -#ifndef _OVERLAY_H_ -#define _OVERLAY_H_ +#ifndef CRUISE_OVERLAY_H +#define CRUISE_OVERLAY_H namespace Cruise { -struct importScriptStruct -{ - uint16 var0; - uint16 var1; - uint16 type; - uint16 offset; - uint16 offsetToName; +struct importScriptStruct { + uint16 var0; + uint16 var1; + uint16 type; + uint16 offset; + uint16 offsetToName; }; typedef struct importScriptStruct importScriptStruct; -struct exportEntryStruct -{ - uint16 var0; - uint16 var2; - uint16 var4; - uint16 idx; - uint16 offsetToName; +struct exportEntryStruct { + uint16 var0; + uint16 var2; + uint16 var4; + uint16 idx; + uint16 offsetToName; }; typedef struct exportEntryStruct exportEntryStruct; -struct ovlData3Struct -{ - uint8* dataPtr; //0 - short int sizeOfData; //4 - short int offsetToSubData3; //6 - short int offsetToImportData; //8 +struct ovlData3Struct { + uint8 *dataPtr; //0 + short int sizeOfData; //4 + short int offsetToSubData3; //6 + short int offsetToImportData; //8 short int offsetToSubData2; short int offsetToImportName; short int offsetToSubData5; @@ -68,52 +65,48 @@ struct ovlData3Struct typedef struct ovlData3Struct ovlData3Struct; -struct stringEntryStruct -{ - char* string; +struct stringEntryStruct { + char *string; short int length; short int idx; }; typedef struct stringEntryStruct stringEntryStruct; -struct linkDataStruct -{ - uint16 field_0; - uint16 field_2; - uint16 field_4; - uint16 varIdx; - uint16 varNameOffset; - uint16 stringIdx; - uint16 stringNameOffset; - uint16 procIdx; - uint16 procNameOffset; - - int16 field_12; - int16 field_14; - int16 field_16; - int16 field_18; - int16 field_1A; - int16 field_1C; - int16 field_1E; - int16 field_20; +struct linkDataStruct { + uint16 field_0; + uint16 field_2; + uint16 field_4; + uint16 varIdx; + uint16 varNameOffset; + uint16 stringIdx; + uint16 stringNameOffset; + uint16 procIdx; + uint16 procNameOffset; + + int16 field_12; + int16 field_14; + int16 field_16; + int16 field_18; + int16 field_1A; + int16 field_1C; + int16 field_1E; + int16 field_20; }; typedef struct linkDataStruct linkDataStruct; -struct importDataStruct -{ - uint16 var0; // 0 - uint16 var1; // 2 - uint16 linkType; // 4 - uint16 linkIdx; // 6 - uint16 nameOffset; +struct importDataStruct { + uint16 var0; // 0 + uint16 var1; // 2 + uint16 linkType; // 4 + uint16 linkIdx; // 6 + uint16 nameOffset; }; typedef struct importDataStruct importDataStruct; -struct objDataStruct -{ +struct objDataStruct { int16 var0; int16 var1; int16 var2; @@ -125,8 +118,7 @@ struct objDataStruct typedef struct objDataStruct objDataStruct; -struct objectParams -{ +struct objectParams { int16 X; int16 Y; int16 baseFileIdx; @@ -137,23 +129,22 @@ struct objectParams typedef struct objectParams objectParams; -struct ovlDataStruct -{ - ovlData3Struct* data3Table; - uint8* ptr1; - objDataStruct* objDataTable; - objectParams* objData2SourceTable; - objectParams* objData2WorkTable; - stringEntryStruct* stringTable; - exportEntryStruct* exportDataPtr; - importDataStruct* importDataPtr; - linkDataStruct* linkDataPtr; - uint8* specialString1; - uint8* specialString2; - uint8* importNamePtr; - uint8* exportNamesPtr; - uint8* data4Ptr; - uint8* ptr8; +struct ovlDataStruct { + ovlData3Struct *data3Table; + uint8 *ptr1; + objDataStruct *objDataTable; + objectParams *objData2SourceTable; + objectParams *objData2WorkTable; + stringEntryStruct *stringTable; + exportEntryStruct *exportDataPtr; + importDataStruct *importDataPtr; + linkDataStruct *linkDataPtr; + uint8 *specialString1; + uint8 *specialString2; + uint8 *importNamePtr; + uint8 *exportNamesPtr; + uint8 *data4Ptr; + uint8 *ptr8; unsigned short int numScripts1; unsigned short int numScripts2; unsigned short int numExport; @@ -174,10 +165,9 @@ struct ovlDataStruct typedef struct ovlDataStruct ovlDataStruct; -struct overlayStruct -{ +struct overlayStruct { char overlayName[14]; - ovlDataStruct* ovlData; + ovlDataStruct *ovlData; short int alreadyLoaded; char field_14; char field_15; @@ -206,11 +196,10 @@ extern overlayStruct overlayTable[90]; extern int numOfLoadedOverlay; void initOverlayTable(void); -int loadOverlay(uint8* scriptName); -int32 findOverlayByName2(uint8* name); -int findOverlayByName(const char* overlayName); -int releaseOverlay(const char* name); - +int loadOverlay(uint8 * scriptName); +int32 findOverlayByName2(uint8 * name); +int findOverlayByName(const char *overlayName); +int releaseOverlay(const char *name); } // End of namespace Cruise diff --git a/engines/cruise/perso.cpp b/engines/cruise/perso.cpp index 6f9c2d54f3..b1b5ab4068 100644 --- a/engines/cruise/perso.cpp +++ b/engines/cruise/perso.cpp @@ -26,235 +26,224 @@ namespace Cruise { -persoStruct* persoTable[10]; +persoStruct *persoTable[10]; int16 computedVar14; -void freePerso(int persoIdx) -{ - if(persoTable[persoIdx]) - { - free(persoTable[persoIdx]); - persoTable[persoIdx] = NULL; - } +void freePerso(int persoIdx) { + if (persoTable[persoIdx]) { + free(persoTable[persoIdx]); + persoTable[persoIdx] = NULL; + } } -void freeAllPerso(void) -{ - int i; +void freeAllPerso(void) { + int i; - for(i=0;i<10;i++) - { - freePerso(i); - } + for (i = 0; i < 10; i++) { + freePerso(i); + } - if(polyStruct) - { - free(polyStruct); - } + if (polyStruct) { + free(polyStruct); + } - ctpVar17 = NULL; - polyStruct = NULL; + ctpVar17 = NULL; + polyStruct = NULL; - strcpy((char*)currentCtpName, ""); + strcpy((char *)currentCtpName, ""); } int pathVar0; -unsigned int inc_droite2,inc_jo; +unsigned int inc_droite2, inc_jo; -int direction( int x1, int y1, int x2, int y2, int inc_jo1, int inc_jo2 ) -{ - int h, v, h1, v1; +int direction(int x1, int y1, int x2, int y2, int inc_jo1, int inc_jo2) { + int h, v, h1, v1; - h1 = x1-x2; h = abs(h1); - v1 = y1-y2; v = abs(v1); - - if ( v > h ) - { - if ( h > 30 ) inc_jo = inc_jo1-inc_jo2; - else inc_jo = inc_jo2; + h1 = x1 - x2; + h = abs(h1); + v1 = y1 - y2; + v = abs(v1); - if ( v1 < 0 ) return ( 2 ); - else return ( 0 ); - } - else - { + if (v > h) { + if (h > 30) + inc_jo = inc_jo1 - inc_jo2; + else + inc_jo = inc_jo2; + + if (v1 < 0) + return (2); + else + return (0); + } else { inc_jo = inc_jo1; - if ( h1 < 0 ) return ( 1 ); - else return ( 3 ); + if (h1 < 0) + return (1); + else + return (3); } } -void cor_droite(int x1,int y1,int x2,int y2, int16 cor_joueur[400][2]) -{ - int16* di = (int16*)cor_joueur; - int dx; - int dy; - - int mD0; - int mD1; - - int mA0; - int mA1; - - int bp; - int cx; - int si; - - int ax; - int bx; - - di[0] = x1; - di[1] = y1; - di+=2; - - dx = x2-x1; - dy = y2-y1; - - mD0 = mD1 = 1; - - if(dx<0) - { - dx = -dx; - mD0 = -1; - } - - if(dy<0) - { - dy = -dy; - mD1 = -1; - } - - if(dx<dy) - { - mA0 = 0; - bp = dx; - cx = dy; - - mA1 = mD1; - } - else - { - mA1 = 0; - bp = dy; - cx = dx; - - mA0 = mD0; - } - - bp=bp*2; - dx=bp-cx; - si=dx-cx; - - ax = x1; - bx = y1; - - while(--cx) - { - if(dx>0) - { - ax+=mD0; - bx+=mD1; - dx+=si; - } - else - { - ax+=mA0; - bx+=mA1; - dx+=bp; - } - - di[0] = ax; - di[1] = bx; - di+=2; - } - - flag_obstacle = 0; - inc_droite2 = (di-(int16*)cor_joueur)/2; +void cor_droite(int x1, int y1, int x2, int y2, int16 cor_joueur[400][2]) { + int16 *di = (int16 *) cor_joueur; + int dx; + int dy; + + int mD0; + int mD1; + + int mA0; + int mA1; + + int bp; + int cx; + int si; + + int ax; + int bx; + + di[0] = x1; + di[1] = y1; + di += 2; + + dx = x2 - x1; + dy = y2 - y1; + + mD0 = mD1 = 1; + + if (dx < 0) { + dx = -dx; + mD0 = -1; + } + + if (dy < 0) { + dy = -dy; + mD1 = -1; + } + + if (dx < dy) { + mA0 = 0; + bp = dx; + cx = dy; + + mA1 = mD1; + } else { + mA1 = 0; + bp = dy; + cx = dx; + + mA0 = mD0; + } + + bp = bp * 2; + dx = bp - cx; + si = dx - cx; + + ax = x1; + bx = y1; + + while (--cx) { + if (dx > 0) { + ax += mD0; + bx += mD1; + dx += si; + } else { + ax += mA0; + bx += mA1; + dx += bp; + } + + di[0] = ax; + di[1] = bx; + di += 2; + } + + flag_obstacle = 0; + inc_droite2 = (di - (int16 *) cor_joueur) / 2; } -void processActorWalk(int16 resx_y[4], int16* inc_droite, int16* inc_droite0, int16* inc_chemin, int16 cor_joueur[400][2], int16 solution0[NUM_NODES+3][2], int16* inc_jo1, int16* inc_jo2, int16* dir_perso, int16* inc_jo0, int16 num) -{ - int x1, x2, y1, y2; - int i, u; - +void processActorWalk(int16 resx_y[4], int16 *inc_droite, int16 *inc_droite0, + int16 *inc_chemin, int16 cor_joueur[400][2], + int16 solution0[NUM_NODES + 3][2], int16 *inc_jo1, int16 *inc_jo2, + int16 *dir_perso, int16 *inc_jo0, int16 num) { + int x1, x2, y1, y2; + int i, u; + u = 0; inc_jo = *inc_jo0; i = *inc_chemin; - - if ( ! *inc_droite ) - { + + if (!*inc_droite) { x1 = solution0[i][0]; y1 = solution0[i][1]; i++; - if ( solution0[i][0] != -1 ) - { - do - { - if (solution0[i][0]!=-2) - { + if (solution0[i][0] != -1) { + do { + if (solution0[i][0] != -2) { x2 = solution0[i][0]; y2 = solution0[i][1]; - if ( (x1==x2) && (y1==y2)) - { - resx_y[0]=-1; - resx_y[1]=-1; + if ((x1 == x2) && (y1 == y2)) { + resx_y[0] = -1; + resx_y[1] = -1; freePerso(num); return; } - cor_droite(x1,y1,x2,y2,cor_joueur); - *inc_droite0=inc_droite2; - *dir_perso=resx_y[2]=direction(x1,y1,x2,y2,*inc_jo1,*inc_jo2); - *inc_jo0=inc_jo; - u=1; - } - else i++; - - } while ( solution0[i][0] !=-1 && !u ); + cor_droite(x1, y1, x2, y2, cor_joueur); + *inc_droite0 = inc_droite2; + *dir_perso = resx_y[2] = + direction(x1, y1, x2, y2, *inc_jo1, + *inc_jo2); + *inc_jo0 = inc_jo; + u = 1; + } else + i++; + + } while (solution0[i][0] != -1 && !u); } - if ( !u ) - { - resx_y[0]=-1; - resx_y[1]=-1; + if (!u) { + resx_y[0] = -1; + resx_y[1] = -1; freePerso(num); return; } - *inc_chemin=i; - } - - resx_y[0]=cor_joueur[*inc_droite][0]; - resx_y[1]=cor_joueur[*inc_droite][1]; - resx_y[2]=*dir_perso; - resx_y[3]=computeZoom(resx_y[1]); - - getPixel(resx_y[0],resx_y[1]); - resx_y[4]=computedVar14; - - u=subOp23(resx_y[3],inc_jo); - if (!u) u=1; - *inc_droite+=u; - - if ((*inc_droite)>=(*inc_droite0)) - { - *inc_droite=0; - resx_y[0]=solution0[*inc_chemin][0]; - resx_y[1]=solution0[*inc_chemin][1]; + *inc_chemin = i; + } + + resx_y[0] = cor_joueur[*inc_droite][0]; + resx_y[1] = cor_joueur[*inc_droite][1]; + resx_y[2] = *dir_perso; + resx_y[3] = computeZoom(resx_y[1]); + + getPixel(resx_y[0], resx_y[1]); + resx_y[4] = computedVar14; + + u = subOp23(resx_y[3], inc_jo); + if (!u) + u = 1; + *inc_droite += u; + + if ((*inc_droite) >= (*inc_droite0)) { + *inc_droite = 0; + resx_y[0] = solution0[*inc_chemin][0]; + resx_y[1] = solution0[*inc_chemin][1]; } } -void affiche_chemin(int16 persoIdx, int16* returnVar) -{ - persoStruct* pPerso = persoTable[persoIdx]; +void affiche_chemin(int16 persoIdx, int16 *returnVar) { + persoStruct *pPerso = persoTable[persoIdx]; - ASSERT(pPerso); + ASSERT(pPerso); - processActorWalk(returnVar, &pPerso->inc_droite, &pPerso->inc_droite0, &pPerso->inc_chemin, pPerso->coordinates, pPerso->solution, &pPerso->inc_jo1, &pPerso->inc_jo2, &pPerso->dir_perso, &pPerso->inc_jo0, persoIdx); + processActorWalk(returnVar, &pPerso->inc_droite, &pPerso->inc_droite0, + &pPerso->inc_chemin, pPerso->coordinates, pPerso->solution, + &pPerso->inc_jo1, &pPerso->inc_jo2, &pPerso->dir_perso, + &pPerso->inc_jo0, persoIdx); } } // End of namespace Cruise diff --git a/engines/cruise/perso.h b/engines/cruise/perso.h index e90fbd075e..b26b85f634 100644 --- a/engines/cruise/perso.h +++ b/engines/cruise/perso.h @@ -22,34 +22,33 @@ * */ -#ifndef _PERSO_H_ -#define _PERSO_H_ +#ifndef CRUISE_PERSO_H +#define CRUISE_PERSO_H namespace Cruise { #define NUM_NODES 20 -struct persoStruct -{ - int16 inc_droite; // 2 - int16 inc_droite0; // 2 - int16 inc_chemin; // 2 - int16 coordinates[400][2]; // 1600 - int16 solution[NUM_NODES+3][2]; //((20+3)*2*2) - int16 inc_jo1; // 2 - int16 inc_jo2; // 2 - int16 dir_perso; // 2 - int16 inc_jo0; // 2 +struct persoStruct { + int16 inc_droite; // 2 + int16 inc_droite0; // 2 + int16 inc_chemin; // 2 + int16 coordinates[400][2]; // 1600 + int16 solution[NUM_NODES + 3][2]; //((20+3)*2*2) + int16 inc_jo1; // 2 + int16 inc_jo2; // 2 + int16 dir_perso; // 2 + int16 inc_jo0; // 2 }; typedef struct persoStruct persoStruct; -extern persoStruct* persoTable[10]; +extern persoStruct *persoTable[10]; extern int16 computedVar14; void freePerso(int persoIdx); void freeAllPerso(void); -void affiche_chemin(int16 persoIdx, int16* returnVar); +void affiche_chemin(int16 persoIdx, int16 * returnVar); } // End of namespace Cruise diff --git a/engines/cruise/polys.cpp b/engines/cruise/polys.cpp index 664b2dc004..98d64cdeba 100644 --- a/engines/cruise/polys.cpp +++ b/engines/cruise/polys.cpp @@ -23,6 +23,7 @@ */ #include "cruise/cruise_main.h" +#include "common/util.h" namespace Cruise { @@ -34,10 +35,6 @@ typedef char ColorP; #define SCREENHEIGHT 200 #define MAXPTS 10 #define putdot(x,y) {if ((y >= 0) && (y < SCREENHEIGHT)) dots[y][counters[y]++] = x;} -#define SWAP(x,y) {int temp = x; x = y; y = temp;} - -int MAX(int x, int y) {if(x>y){return x;}else{return y;}} -int MIN(int x, int y) {if(x<y){return x;}else{return y;}} void hline(int x1, int x2, int y, char c) { for (; x1 <= x2; x1++) { @@ -75,6 +72,7 @@ void bsubline_1(int x1, int y1, int x2, int y2, char c) { } } + void bsubline_2(int x1, int y1, int x2, int y2, char c) { int x, y, ddx, ddy, e; @@ -88,7 +86,6 @@ void bsubline_2(int x1, int y1, int x2, int y2, char c) { SWAP(y1, y2); } - for (y = y1, x = x1; y <= y2; y++) { pixel(x, y, c); @@ -108,7 +105,7 @@ void bsubline_3(int x1, int y1, int x2, int y2, char c) { ddx = abs(x1 - x2) << 1; ddy = abs(y2 - y1); - e = ddy - ddx; + e = ddy - ddx; ddy <<= 1; if (y1 > y2) { @@ -116,7 +113,6 @@ void bsubline_3(int x1, int y1, int x2, int y2, char c) { SWAP(y1, y2); } - for (y = y1, x = x1; y <= y2; y++) { pixel(x, y, c); @@ -136,7 +132,7 @@ void bsubline_4(int x1, int y1, int x2, int y2, char c) { ddy = abs(y2 - y1) << 1; ddx = abs(x1 - x2); - e = ddx - ddy; + e = ddx - ddy; ddx <<= 1; if (x1 > x2) { @@ -185,35 +181,32 @@ void line(int x1, int y1, int x2, int y2, char c) { bsubline_4(x1, y1, x2, y2, c); } else { bsubline_3(x1, y1, x2, y2, c); - } + } } -void fillpoly(short int* datas, int lineCount, ColorP color) -{ +void fillpoly(short int *datas, int lineCount, ColorP color) { static int dots[SCREENHEIGHT][MAXPTS]; static int counters[SCREENHEIGHT]; short int x1, y1, x2, y2; int i, j, k, dir = -2; double step, curx; - switch (lineCount) - { - case 0: // do nothing - return; - case 1: // draw pixel - pixel(datas[0], datas[1], color); - return; - case 2: // draw line - line(datas[0], datas[1], datas[2], datas[3], color); - return; - default: // go on and draw polygon - break; + switch (lineCount) { + case 0: // do nothing + return; + case 1: // draw pixel + pixel(datas[0], datas[1], color); + return; + case 2: // draw line + line(datas[0], datas[1], datas[2], datas[3], color); + return; + default: // go on and draw polygon + break; } // Reinit array counters - for (i = 0; i < SCREENHEIGHT; i++) - { + for (i = 0; i < SCREENHEIGHT; i++) { counters[i] = 0; } // Drawing lines @@ -230,18 +223,14 @@ void fillpoly(short int* datas, int lineCount, ColorP color) // line(x1, y1, x2, y2, color); // continue; - if (y1 == y2) - { + if (y1 == y2) { // printf("Horizontal line. x1: %i, y1: %i, x2: %i, y2: %i\n", x1, y1, x2, y2); - if (dir) - { + if (dir) { putdot(x1, y1); dir = 0; } - } - else - { - step = (double) (x2 - x1) / (y2 - y1); + } else { + step = (double)(x2 - x1) / (y2 - y1); // printf("x1: %i, y1 = %i, x2 = %i, y2 = %i, step: %f\n", x1, y1, x2, y2, step); @@ -276,11 +265,11 @@ void fillpoly(short int* datas, int lineCount, ColorP color) x2 = datas[0]; y2 = datas[1]; - if (((y1 < y2) && (dir == -1)) || ((y1 > y2) && (dir == 1)) || ((y1 == y2) && (dir == 0))) { + if (((y1 < y2) && (dir == -1)) || ((y1 > y2) && (dir == 1)) + || ((y1 == y2) && (dir == 0))) { // printf("Adding final extra (%i, %i)\n", x1, y1); putdot(x1, y1); } - // NOTE: all counters should be even now. If not, this is a bad (color) thing :-P // Sorting datas @@ -289,8 +278,7 @@ void fillpoly(short int* datas, int lineCount, ColorP color) // Very bad sorting... but arrays are very small (0, 2 or 4), so it's no quite use... for (j = 0; j < (counters[i] - 1); j++) { for (k = 0; k < (counters[i] - 1); k++) { - if (dots[i][k] > dots[i][k + 1]) - { + if (dots[i][k] > dots[i][k + 1]) { int temp; temp = dots[i][k]; dots[i][k] = dots[i][k + 1]; @@ -320,4 +308,3 @@ void fillpoly(short int* datas, int lineCount, ColorP color) } } // End of namespace Cruise - diff --git a/engines/cruise/polys.h b/engines/cruise/polys.h index 902085fd45..9c3d17bfa8 100644 --- a/engines/cruise/polys.h +++ b/engines/cruise/polys.h @@ -22,11 +22,16 @@ * */ +#ifndef CRUISE_POLYS_H +#define CRUISE_POLYS_H + namespace Cruise { typedef char ColorP; -void fillpoly(short int * datas, int n, ColorP c); +void fillpoly(short int *datas, int n, ColorP c); void line(int x1, int y1, int x2, int y2, ColorP color); } // End of namespace Cruise + +#endif diff --git a/engines/cruise/saveload.cpp b/engines/cruise/saveload.cpp index fc5c07bca4..a903a293d3 100644 --- a/engines/cruise/saveload.cpp +++ b/engines/cruise/saveload.cpp @@ -26,418 +26,388 @@ namespace Cruise { -void loadSavegameDataSub1(FILE* fileHandle) -{ - int i; - - for(i=1;i<numOfLoadedOverlay;i++) - { - filesData[i].field_4 = NULL; - filesData[i].field_0 = NULL; - filesData2[i].field_0 = 0; - - if(overlayTable[i].alreadyLoaded) - { - fread(&filesData2[i].field_0,2,1,fileHandle); - - if(filesData2[i].field_0) - { - filesData[i].field_0 = (uint8*)mallocAndZero(filesData2[i].field_0); - if(filesData[i].field_0) - { - fread(filesData[i].field_0,filesData2[i].field_0,1,fileHandle); - } - } - - fread(&filesData2[i].field_2,2,1,fileHandle); - - if(filesData2[i].field_2) - { - filesData[i].field_4 = (uint8*)mallocAndZero(filesData2[i].field_2*12); - if(filesData[i].field_4) - { - fread(filesData[i].field_4,filesData2[i].field_2*12,1,fileHandle); - } - } - } - } +void loadSavegameDataSub1(FILE *fileHandle) { + int i; + + for (i = 1; i < numOfLoadedOverlay; i++) { + filesData[i].field_4 = NULL; + filesData[i].field_0 = NULL; + filesData2[i].field_0 = 0; + + if (overlayTable[i].alreadyLoaded) { + fread(&filesData2[i].field_0, 2, 1, fileHandle); + + if (filesData2[i].field_0) { + filesData[i].field_0 = + (uint8 *) mallocAndZero(filesData2[i]. + field_0); + if (filesData[i].field_0) { + fread(filesData[i].field_0, + filesData2[i].field_0, 1, + fileHandle); + } + } + + fread(&filesData2[i].field_2, 2, 1, fileHandle); + + if (filesData2[i].field_2) { + filesData[i].field_4 = + (uint8 *) mallocAndZero(filesData2[i]. + field_2 * 12); + if (filesData[i].field_4) { + fread(filesData[i].field_4, + filesData2[i].field_2 * 12, 1, + fileHandle); + } + } + } + } } -void loadScriptsFromSave(FILE* fileHandle,scriptInstanceStruct* entry) -{ - short int numScripts; - int i; +void loadScriptsFromSave(FILE *fileHandle, scriptInstanceStruct *entry) { + short int numScripts; + int i; - fread(&numScripts,2,1,fileHandle); + fread(&numScripts, 2, 1, fileHandle); - for(i=0;i<numScripts;i++) - { - scriptInstanceStruct* ptr = (scriptInstanceStruct*)mallocAndZero(sizeof(scriptInstanceStruct)); + for (i = 0; i < numScripts; i++) { + scriptInstanceStruct *ptr = + (scriptInstanceStruct *) + mallocAndZero(sizeof(scriptInstanceStruct)); - fread(ptr,0x1C,1,fileHandle); // use 0x1C as our scriptInstanceStruct is bigger than in original because of cross platform problems + fread(ptr, 0x1C, 1, fileHandle); // use 0x1C as our scriptInstanceStruct is bigger than in original because of cross platform problems - fread(&ptr->varA,2,1,fileHandle); + fread(&ptr->varA, 2, 1, fileHandle); - if(ptr->varA) - { - ptr->var6 = (uint8*)mallocAndZero(ptr->varA); + if (ptr->varA) { + ptr->var6 = (uint8 *) mallocAndZero(ptr->varA); - fread(ptr->var6,ptr->varA,1,fileHandle); - } + fread(ptr->var6, ptr->varA, 1, fileHandle); + } + ///////// + ptr->bitMask = *((int16 *) ptr + 1); + ///////// - ///////// - ptr->bitMask = *((int16*)ptr+1); - ///////// + ptr->nextScriptPtr = 0; - ptr->nextScriptPtr = 0; - - entry->nextScriptPtr = ptr; - entry = ptr; - } + entry->nextScriptPtr = ptr; + entry = ptr; + } } -void loadSavegameActor(FILE* fileHandle) -{ - short int numEntry; - actorStruct* ptr; - int i; +void loadSavegameActor(FILE *fileHandle) { + short int numEntry; + actorStruct *ptr; + int i; - fread(&numEntry,2,1,fileHandle); + fread(&numEntry, 2, 1, fileHandle); - ptr = &actorHead; + ptr = &actorHead; - for(i=0;i<numEntry;i++) - { - actorStruct* current = (actorStruct*)mallocAndZero(sizeof(actorStruct)); - fseek(fileHandle, 4, SEEK_CUR); - fread(current,0x26,1,fileHandle); + for (i = 0; i < numEntry; i++) { + actorStruct *current = + (actorStruct *) mallocAndZero(sizeof(actorStruct)); + fseek(fileHandle, 4, SEEK_CUR); + fread(current, 0x26, 1, fileHandle); - current->next = NULL; - ptr->next = current; - current->prev = actorHead.prev; - actorHead.prev = current; - ptr = current->next; - } + current->next = NULL; + ptr->next = current; + current->prev = actorHead.prev; + actorHead.prev = current; + ptr = current->next; + } } -void loadSavegameDataSub5(FILE* fileHandle) -{ - if(var1) - { - fread(&saveVar1,1,1,fileHandle); - - if(saveVar1) - { - fread(saveVar2,saveVar1,1,fileHandle); - } - } - else - { - fread(&saveVar1,1,1,fileHandle); - } +void loadSavegameDataSub5(FILE *fileHandle) { + if (var1) { + fread(&saveVar1, 1, 1, fileHandle); -} + if (saveVar1) { + fread(saveVar2, saveVar1, 1, fileHandle); + } + } else { + fread(&saveVar1, 1, 1, fileHandle); + } -void loadSavegameDataSub6(FILE* fileHandle) -{ - int32 var; - - fread(&var,4,1,fileHandle); - flipLong(&var); - - if(var) - { - int i; - - fread(&numberOfWalkboxes, 2, 1, fileHandle); - - if(numberOfWalkboxes) - { - fread(walkboxType, numberOfWalkboxes * 2, 1, fileHandle); - fread(walkboxType, numberOfWalkboxes * 2, 1, fileHandle); - } - - for(i=0;i<10;i++) - { - fread(&persoTable[i],4,1,fileHandle); - - if(persoTable[i]) - { - assert(sizeof(persoStruct) == 0x6AA); - persoTable[i] = (persoStruct*)mallocAndZero(sizeof(persoStruct)); - fread(persoTable[i],0x6AA,1,fileHandle); - } - } - } } +void loadSavegameDataSub6(FILE *fileHandle) { + int32 var; + + fread(&var, 4, 1, fileHandle); + flipLong(&var); + + if (var) { + int i; + + fread(&numberOfWalkboxes, 2, 1, fileHandle); + + if (numberOfWalkboxes) { + fread(walkboxType, numberOfWalkboxes * 2, 1, + fileHandle); + fread(walkboxType, numberOfWalkboxes * 2, 1, + fileHandle); + } + + for (i = 0; i < 10; i++) { + fread(&persoTable[i], 4, 1, fileHandle); + + if (persoTable[i]) { + assert(sizeof(persoStruct) == 0x6AA); + persoTable[i] = + (persoStruct *) + mallocAndZero(sizeof(persoStruct)); + fread(persoTable[i], 0x6AA, 1, fileHandle); + } + } + } +} -int loadSavegameData(int saveGameIdx) -{ - char buffer[256]; - FILE* fileHandle; - char saveIdentBuffer[6]; - int j; - int initVar1Save; - cellStruct* currentcellHead; - - sprintf(buffer,"CR.%d",saveGameIdx); - - fileHandle = fopen(buffer,"rb"); - - if(!fileHandle) - { - printInfoBlackBox("Sauvegarde non trouvée..."); - waitForPlayerInput(); - return(-1); - } - - printInfoBlackBox("Chargement en cours..."); - - fread(saveIdentBuffer,6,1,fileHandle); - - if(strcmp(saveIdentBuffer,"SAVPC")) - { - fclose(fileHandle); - return(-1); - } - - //initVars(); - - fread(&var1,2,1,fileHandle); - fread(&var2,2,1,fileHandle); - fread(&var3,2,1,fileHandle); - fread(&var4,2,1,fileHandle); - fread(&userEnabled,2,1,fileHandle); - fread(&var6,2,1,fileHandle); - fread(&var7,2,1,fileHandle); - fread(&var8,2,1,fileHandle); - fread(&userDelay,2,1,fileHandle); - fread(&sysKey,2,1,fileHandle); - fread(&var11,2,1,fileHandle); - fread(&var12,2,1,fileHandle); - fread(&var13,2,1,fileHandle); - fread(&var14,2,1,fileHandle); - fread(&affichePasMenuJoueur,2,1,fileHandle); - fread(&var20,2,1,fileHandle); - fread(&var22,2,1,fileHandle); - fread(&var23,2,1,fileHandle); - fread(&var24,2,1,fileHandle); - fread(&automaticMode,2,1,fileHandle); - - // video param (not loaded in EGA mode) - - fread(&video4,2,1,fileHandle); - fread(&video2,2,1,fileHandle); - fread(&video3,2,1,fileHandle); - fread(&colorOfSelectedSaveDrive,2,1,fileHandle); - - // - - fread(&var30,2,1,fileHandle); - fread(&var31,2,1,fileHandle); - fread(&var34,2,1,fileHandle); - fread(&var35,2,1,fileHandle); - int16 bTemp; - fread(&bTemp,2,1,fileHandle); - animationStart = bTemp; - fread(¤tActiveBackgroundPlane,2,1,fileHandle); - fread(&initVar3,2,1,fileHandle); - fread(&initVar2,2,1,fileHandle); - fread(&var22,2,1,fileHandle); - fread(&main5,2,1,fileHandle); - fread(&numOfLoadedOverlay,2,1,fileHandle); - fread(&setup1,2,1,fileHandle); - fread(&fontFileIndex,2,1,fileHandle); - fread(¤tActiveMenu,2,1,fileHandle); - fread(&main7,2,1,fileHandle); // ok - fread(&main17,2,1,fileHandle); - fread(&main14,2,1,fileHandle); - fread(&main8,2,1,fileHandle); - fread(&var39,2,1,fileHandle); - fread(&var42,2,1,fileHandle); - fread(&var45,2,1,fileHandle); - fread(&var46,2,1,fileHandle); - fread(&var47,2,1,fileHandle); - fread(&var48,2,1,fileHandle); - fread(&flagCt,2,1,fileHandle); - fread(&var41,2,1,fileHandle); - fread(&entrerMenuJoueur,2,1,fileHandle); - - fread(var50,64,1,fileHandle); - fread(var50,64,1,fileHandle); // Hu ? why 2 times ? - fread(&systemStrings,sizeof(systemStrings),1,fileHandle); // ok - fread(currentCtpName,40,1,fileHandle); - fread(backgroundTable,120,1,fileHandle); - fread(palette,256,2,fileHandle); // ok - fread(initVar5,24,1,fileHandle); - fread(globalVars,setup1*2,1,fileHandle); - fread(filesDatabase,9766,1,fileHandle); - fread(overlayTable,40*numOfLoadedOverlay,1,fileHandle); // ok - fread(mediumVar,0x880,1,fileHandle); - - loadSavegameDataSub1(fileHandle); - loadScriptsFromSave(fileHandle,&scriptHandle2); - loadScriptsFromSave(fileHandle,&scriptHandle1); - - loadSavegameDataSub2(fileHandle); - loadBackgroundIncrustFromSave(fileHandle); - loadSavegameActor(fileHandle); - loadSavegameDataSub5(fileHandle); - loadSavegameDataSub6(fileHandle); - - fclose(fileHandle); // finished with loading !!!!! Yatta ! - - for(j=0;j<64;j++) - { - mediumVar[j].ptr=NULL; - } - - for(j=1;j<numOfLoadedOverlay;j++) - { - if(overlayTable[j].alreadyLoaded) - { - overlayTable[j].alreadyLoaded = 0; - loadOverlay((uint8*)overlayTable[j].overlayName); - - if(overlayTable[j].alreadyLoaded) - { - ovlDataStruct* ovlData = overlayTable[j].ovlData; - - if(filesData[j].field_0) - { - if(ovlData->data4Ptr) - { - free(ovlData->data4Ptr); - } - - ovlData->data4Ptr = (uint8*)filesData[j].field_0; - ovlData->sizeOfData4 = filesData2[j].field_0; - } - - if(filesData[j].field_4) - { - if(ovlData->objData2WorkTable) - { - free(ovlData->objData2WorkTable); - } - - ovlData->objData2WorkTable = (objectParams*)filesData[j].field_4; // TODO: fix ! - ovlData->size9 = filesData2[j].field_2; - } - - } - } - } - - updateAllScriptsImports(); - - saveVar6[0] = 0; - - initVar1Save = initVar1; - - for(j=0;j<257;j++) - { - if(filesDatabase[j].subData.ptr) - { - int i; - int k; - - for(i=j+1;i<257;i++) - { - if(filesDatabase[i].subData.ptr) - { - if(strcmpuint8(filesDatabase[j].subData.name,filesDatabase[i].subData.name)) - { - break; - } - } - else - { - break; - } - } - - for(k=j;k<i;k++) - { - if(filesDatabase[k].subData.ptr2) - initVar1 = 0; - - filesDatabase[k].subData.ptr = NULL; - filesDatabase[k].subData.ptr2 = NULL; - } - - if(i<2) - { - printf("Unsupported mono file load!\n"); - exit(1); - //loadFileMode1(filesDatabase[j].subData.name,filesDatabase[j].subData.var4); - } - else - { - loadFileMode2((uint8*)filesDatabase[j].subData.name,filesDatabase[j].subData.index, j, i-j); - j = i-1; - } - - initVar1 = initVar1Save; - } - } - - saveVar6[0] = 0; - - currentcellHead = cellHead.next; - - while(currentcellHead) - { - if(currentcellHead->type == 5) - { - uint8* ptr = mainProc14(currentcellHead->overlay,currentcellHead->idx); - - ASSERT(0); - - if(ptr) - { - ASSERT(0); - //*(int16*)(currentcellHead->datas+0x2E) = getSprite(ptr,*(int16*)(currentcellHead->datas+0xE)); - } - else - { - //*(int16*)(currentcellHead->datas+0x2E) = 0; - } - } - - currentcellHead = currentcellHead->next; - } - - //TODO: here, restart music - - if(strlen((char*)currentCtpName)) - { - ctpVar1 = 1; - loadCtp(currentCtpName); - ctpVar1 = 0; - } - - //prepareFadeOut(); - //gfxModuleData.gfxFunction8(); - - for(j=0;j<8;j++) - { - if(strlen((char*)backgroundTable[j].name)) - { - loadBackground(backgroundTable[j].name,j); - } - } - - regenerateBackgroundIncrust(&backgroundIncrustHead); - - // to finish - - changeCursor(0); - mainDraw(1); - flipScreen(); - - return(0); +int loadSavegameData(int saveGameIdx) { + char buffer[256]; + FILE *fileHandle; + char saveIdentBuffer[6]; + int j; + int initVar1Save; + cellStruct *currentcellHead; + + sprintf(buffer, "CR.%d", saveGameIdx); + + fileHandle = fopen(buffer, "rb"); + + if (!fileHandle) { + printInfoBlackBox("Sauvegarde non trouvée..."); + waitForPlayerInput(); + return (-1); + } + + printInfoBlackBox("Chargement en cours..."); + + fread(saveIdentBuffer, 6, 1, fileHandle); + + if (strcmp(saveIdentBuffer, "SAVPC")) { + fclose(fileHandle); + return (-1); + } + //initVars(); + + fread(&var1, 2, 1, fileHandle); + fread(&var2, 2, 1, fileHandle); + fread(&var3, 2, 1, fileHandle); + fread(&var4, 2, 1, fileHandle); + fread(&userEnabled, 2, 1, fileHandle); + fread(&var6, 2, 1, fileHandle); + fread(&var7, 2, 1, fileHandle); + fread(&var8, 2, 1, fileHandle); + fread(&userDelay, 2, 1, fileHandle); + fread(&sysKey, 2, 1, fileHandle); + fread(&var11, 2, 1, fileHandle); + fread(&var12, 2, 1, fileHandle); + fread(&var13, 2, 1, fileHandle); + fread(&var14, 2, 1, fileHandle); + fread(&affichePasMenuJoueur, 2, 1, fileHandle); + fread(&var20, 2, 1, fileHandle); + fread(&var22, 2, 1, fileHandle); + fread(&var23, 2, 1, fileHandle); + fread(&var24, 2, 1, fileHandle); + fread(&automaticMode, 2, 1, fileHandle); + + // video param (not loaded in EGA mode) + + fread(&video4, 2, 1, fileHandle); + fread(&video2, 2, 1, fileHandle); + fread(&video3, 2, 1, fileHandle); + fread(&colorOfSelectedSaveDrive, 2, 1, fileHandle); + + // + + fread(&var30, 2, 1, fileHandle); + fread(&var31, 2, 1, fileHandle); + fread(&var34, 2, 1, fileHandle); + fread(&var35, 2, 1, fileHandle); + int16 bTemp; + fread(&bTemp, 2, 1, fileHandle); + animationStart = bTemp; + fread(¤tActiveBackgroundPlane, 2, 1, fileHandle); + fread(&initVar3, 2, 1, fileHandle); + fread(&initVar2, 2, 1, fileHandle); + fread(&var22, 2, 1, fileHandle); + fread(&main5, 2, 1, fileHandle); + fread(&numOfLoadedOverlay, 2, 1, fileHandle); + fread(&setup1, 2, 1, fileHandle); + fread(&fontFileIndex, 2, 1, fileHandle); + fread(¤tActiveMenu, 2, 1, fileHandle); + fread(&main7, 2, 1, fileHandle); // ok + fread(&main17, 2, 1, fileHandle); + fread(&main14, 2, 1, fileHandle); + fread(&main8, 2, 1, fileHandle); + fread(&var39, 2, 1, fileHandle); + fread(&var42, 2, 1, fileHandle); + fread(&var45, 2, 1, fileHandle); + fread(&var46, 2, 1, fileHandle); + fread(&var47, 2, 1, fileHandle); + fread(&var48, 2, 1, fileHandle); + fread(&flagCt, 2, 1, fileHandle); + fread(&var41, 2, 1, fileHandle); + fread(&entrerMenuJoueur, 2, 1, fileHandle); + + fread(var50, 64, 1, fileHandle); + fread(var50, 64, 1, fileHandle); // Hu ? why 2 times ? + fread(&systemStrings, sizeof(systemStrings), 1, fileHandle); // ok + fread(currentCtpName, 40, 1, fileHandle); + fread(backgroundTable, 120, 1, fileHandle); + fread(palette, 256, 2, fileHandle); // ok + fread(initVar5, 24, 1, fileHandle); + fread(globalVars, setup1 * 2, 1, fileHandle); + fread(filesDatabase, 9766, 1, fileHandle); + fread(overlayTable, 40 * numOfLoadedOverlay, 1, fileHandle); // ok + fread(mediumVar, 0x880, 1, fileHandle); + + loadSavegameDataSub1(fileHandle); + loadScriptsFromSave(fileHandle, &scriptHandle2); + loadScriptsFromSave(fileHandle, &scriptHandle1); + + loadSavegameDataSub2(fileHandle); + loadBackgroundIncrustFromSave(fileHandle); + loadSavegameActor(fileHandle); + loadSavegameDataSub5(fileHandle); + loadSavegameDataSub6(fileHandle); + + fclose(fileHandle); // finished with loading !!!!! Yatta ! + + for (j = 0; j < 64; j++) { + mediumVar[j].ptr = NULL; + } + + for (j = 1; j < numOfLoadedOverlay; j++) { + if (overlayTable[j].alreadyLoaded) { + overlayTable[j].alreadyLoaded = 0; + loadOverlay((uint8 *) overlayTable[j].overlayName); + + if (overlayTable[j].alreadyLoaded) { + ovlDataStruct *ovlData = + overlayTable[j].ovlData; + + if (filesData[j].field_0) { + if (ovlData->data4Ptr) { + free(ovlData->data4Ptr); + } + + ovlData->data4Ptr = + (uint8 *) filesData[j].field_0; + ovlData->sizeOfData4 = + filesData2[j].field_0; + } + + if (filesData[j].field_4) { + if (ovlData->objData2WorkTable) { + free(ovlData-> + objData2WorkTable); + } + + ovlData->objData2WorkTable = (objectParams *) filesData[j].field_4; // TODO: fix ! + ovlData->size9 = filesData2[j].field_2; + } + + } + } + } + + updateAllScriptsImports(); + + saveVar6[0] = 0; + + initVar1Save = initVar1; + + for (j = 0; j < 257; j++) { + if (filesDatabase[j].subData.ptr) { + int i; + int k; + + for (i = j + 1; i < 257; i++) { + if (filesDatabase[i].subData.ptr) { + if (strcmpuint8(filesDatabase[j]. + subData.name, + filesDatabase[i].subData. + name)) { + break; + } + } else { + break; + } + } + + for (k = j; k < i; k++) { + if (filesDatabase[k].subData.ptr2) + initVar1 = 0; + + filesDatabase[k].subData.ptr = NULL; + filesDatabase[k].subData.ptr2 = NULL; + } + + if (i < 2) { + printf("Unsupported mono file load!\n"); + exit(1); + //loadFileMode1(filesDatabase[j].subData.name,filesDatabase[j].subData.var4); + } else { + loadFileMode2((uint8 *) filesDatabase[j]. + subData.name, + filesDatabase[j].subData.index, j, i - j); + j = i - 1; + } + + initVar1 = initVar1Save; + } + } + + saveVar6[0] = 0; + + currentcellHead = cellHead.next; + + while (currentcellHead) { + if (currentcellHead->type == 5) { + uint8 *ptr = + mainProc14(currentcellHead->overlay, + currentcellHead->idx); + + ASSERT(0); + + if (ptr) { + ASSERT(0); + //*(int16*)(currentcellHead->datas+0x2E) = getSprite(ptr,*(int16*)(currentcellHead->datas+0xE)); + } else { + //*(int16*)(currentcellHead->datas+0x2E) = 0; + } + } + + currentcellHead = currentcellHead->next; + } + + //TODO: here, restart music + + if (strlen((char *)currentCtpName)) { + ctpVar1 = 1; + loadCtp(currentCtpName); + ctpVar1 = 0; + } + //prepareFadeOut(); + //gfxModuleData.gfxFunction8(); + + for (j = 0; j < 8; j++) { + if (strlen((char *)backgroundTable[j].name)) { + loadBackground(backgroundTable[j].name, j); + } + } + + regenerateBackgroundIncrust(&backgroundIncrustHead); + + // to finish + + changeCursor(0); + mainDraw(1); + flipScreen(); + + return (0); } } // End of namespace Cruise diff --git a/engines/cruise/saveload.h b/engines/cruise/saveload.h index 8acacaf36e..179c0a78f1 100644 --- a/engines/cruise/saveload.h +++ b/engines/cruise/saveload.h @@ -22,8 +22,8 @@ * */ -#ifndef _LOADSAVE_H_ -#define _LOADSAVE_H_ +#ifndef CRUISE_SAVELOAD_H +#define CRUISE_SAVELOAD_H namespace Cruise { diff --git a/engines/cruise/script.cpp b/engines/cruise/script.cpp index eedcfe58e6..fbc3a4decc 100644 --- a/engines/cruise/script.cpp +++ b/engines/cruise/script.cpp @@ -29,833 +29,744 @@ namespace Cruise { scriptInstanceStruct scriptHandle1; scriptInstanceStruct scriptHandle2; -scriptInstanceStruct* currentScriptPtr; +scriptInstanceStruct *currentScriptPtr; +uint8 getByteFromScript(void) { + uint8 var = currentData3DataPtr[currentScriptPtr->var4]; -uint8 getByteFromScript(void) -{ - uint8 var = currentData3DataPtr[currentScriptPtr->var4]; + currentScriptPtr->var4 = currentScriptPtr->var4 + 1; - currentScriptPtr->var4 = currentScriptPtr->var4+1; - - return(var); + return (var); } -short int getShortFromScript(void) -{ - short int var = *(int16*)(currentData3DataPtr+currentScriptPtr->var4); +short int getShortFromScript(void) { + short int var = *(int16 *) (currentData3DataPtr + currentScriptPtr->var4); - currentScriptPtr->var4 = currentScriptPtr->var4+2; + currentScriptPtr->var4 = currentScriptPtr->var4 + 2; - flipShort(&var); + flipShort(&var); - return(var); + return (var); } -int32 opcodeType0(void) // load opcode -{ - switch(currentScriptOpcodeType) - { - case 0: - { - pushVar(getShortFromScript()); - return(0); - } - case 1: - { - uint8* ptr = 0; - int byte1 = getByteFromScript(); - int byte2 = getByteFromScript(); - short int short1 = getShortFromScript(); - - int var_E = byte1 & 7; - - if(!var_E) - { - return(-10); - } - - if(!byte2) - { - ptr = scriptDataPtrTable[var_E] + short1; - } - else // TODO: - { - if(!overlayTable[byte2].alreadyLoaded) - { - return(-7); - } - - if(!overlayTable[byte2].ovlData) - { - return(-4); - } - - if(var_E == 5) - { - ptr = overlayTable[byte2].ovlData->data4Ptr + short1; - } - else - { +// load opcode +int32 opcodeType0(void) { + switch (currentScriptOpcodeType) { + case 0: + { + pushVar(getShortFromScript()); + return (0); + } + case 1: + { + uint8 *ptr = 0; + int byte1 = getByteFromScript(); + int byte2 = getByteFromScript(); + short int short1 = getShortFromScript(); + + int var_E = byte1 & 7; + + if (!var_E) { + return (-10); + } + + if (!byte2) { + ptr = scriptDataPtrTable[var_E] + short1; + } else // TODO: + { + if (!overlayTable[byte2].alreadyLoaded) { + return (-7); + } + + if (!overlayTable[byte2].ovlData) { + return (-4); + } + + if (var_E == 5) { + ptr = + overlayTable[byte2].ovlData-> + data4Ptr + short1; + } else { assert(0); } } - if(((byte1 & 0x18)>>3)==1) - { - pushVar(loadShort(ptr)); - return(0); - } - else - if(((byte1 & 0x18)>>3)==2) - { - pushVar(*ptr); - return(0); - } - else - { - printf("Unsupported code in opcodeType0 case 1!\n"); - exit(1); - } - - return(0); - } - case 2: - { - int16 var_16; - int di = getByteFromScript(); - int si = getByteFromScript(); - int var_2 = getShortFromScript(); - - if(!si) - { - si = currentScriptPtr->overlayNumber; - } - - if(getSingleObjectParam(si, var_2, di, &var_16)) - { - return -10; - } - - pushVar(var_16); - return(0); - - break; - } - case 5: - { - int byte1 = getByteFromScript(); - int byte2 = getByteFromScript(); - short int short1 = getShortFromScript(); - - short int var_12 = short1; - // short int var_10 = saveOpcodeVar; - - int var_E = byte1 & 7; - - uint8* ptr = 0; - - if(!var_E) - { - return(-10); - } - - if(!byte2) - { - ptr = scriptDataPtrTable[var_E] + var_12; - } - else // TODO: - { - if(!overlayTable[byte2].alreadyLoaded) - { - return(-7); - } - - if(!overlayTable[byte2].ovlData) - { - return(-4); - } - - if(var_E == 5) - { - ptr = overlayTable[byte2].ovlData->data4Ptr + var_12; - } - else - { + if (((byte1 & 0x18) >> 3) == 1) { + pushVar(loadShort(ptr)); + return (0); + } else if (((byte1 & 0x18) >> 3) == 2) { + pushVar(*ptr); + return (0); + } else { + printf + ("Unsupported code in opcodeType0 case 1!\n"); + exit(1); + } + + return (0); + } + case 2: + { + int16 var_16; + int di = getByteFromScript(); + int si = getByteFromScript(); + int var_2 = getShortFromScript(); + + if (!si) { + si = currentScriptPtr->overlayNumber; + } + + if (getSingleObjectParam(si, var_2, di, &var_16)) { + return -10; + } + + pushVar(var_16); + return (0); + + break; + } + case 5: + { + int byte1 = getByteFromScript(); + int byte2 = getByteFromScript(); + short int short1 = getShortFromScript(); + + short int var_12 = short1; + // short int var_10 = saveOpcodeVar; + + int var_E = byte1 & 7; + + uint8 *ptr = 0; + + if (!var_E) { + return (-10); + } + + if (!byte2) { + ptr = scriptDataPtrTable[var_E] + var_12; + } else // TODO: + { + if (!overlayTable[byte2].alreadyLoaded) { + return (-7); + } + + if (!overlayTable[byte2].ovlData) { + return (-4); + } + + if (var_E == 5) { + ptr = + overlayTable[byte2].ovlData-> + data4Ptr + var_12; + } else { assert(0); } } - if(((byte1 & 0x18)>>3)==1) - { - pushVar(loadShort(ptr+saveOpcodeVar*2)); // TODO: check this ! - return(0); - } - else - if(((byte1 & 0x18)>>3)==2) - { - pushVar(*(ptr+saveOpcodeVar)); - return(0); - } - else - { - printf("Unsupported code in opcodeType0 case 1!\n"); - exit(1); - } - - return(0); - } - default: - { - printf("Unsupported type %d in opcodeType0\n",currentScriptOpcodeType); - exit(1); - } - } - - return 0; + if (((byte1 & 0x18) >> 3) == 1) { + pushVar(loadShort(ptr + saveOpcodeVar * 2)); // TODO: check this ! + return (0); + } else if (((byte1 & 0x18) >> 3) == 2) { + pushVar(*(ptr + saveOpcodeVar)); + return (0); + } else { + printf + ("Unsupported code in opcodeType0 case 1!\n"); + exit(1); + } + + return (0); + } + default: + { + printf("Unsupported type %d in opcodeType0\n", + currentScriptOpcodeType); + exit(1); + } + } + + return 0; } -int32 opcodeType1(void) // save opcode -{ - int var = popVar(); - int offset = 0; - - switch(currentScriptOpcodeType) - { - case 0: - { - return(0); // strange, but happens also in original interpreter - } - case 5: - { - offset = saveOpcodeVar; - } - case 1: - { - int var_A = 0; - - int byte1 = getByteFromScript(); - int byte2 = getByteFromScript(); - - int short1 = getShortFromScript(); - - int var_6 = byte1 & 7; - - int var_C = short1; - - uint8* ptr = 0; - int type2; - - if(!var_6) - return(-10); - - var_C = short1; - - if(byte2) - { - if(!overlayTable[byte2].alreadyLoaded) - { - return(-7); - } - - if(!overlayTable[byte2].ovlData) - { - return(-4); - } - - if(var_6 == 5) - { - ptr = overlayTable[byte2].ovlData->data4Ptr + var_C; - } - else - { - ASSERT(0); - } - } - else - { - ptr = scriptDataPtrTable[var_6] + var_C; - } - - type2 = ((byte1 & 0x18)>>3); - - switch(type2) - { - case 1: - { - saveShort(ptr+var_A+offset*2,var); - return 0; - } - case 2: - { - *(ptr+var_A+offset) = var; - return(0); - } - default: - { - printf("Unsupported code in opcodeType1 case 1!\n"); - exit(1); - } - } - - break; - } - case 2: - { - int mode = getByteFromScript(); - int di = getByteFromScript(); - int var_4 = getShortFromScript(); - - if(!di) - { - di = currentScriptPtr->overlayNumber; - } - - if(var == 0x85) // Special case to handle... - { - ASSERT(0); - } - - setObjectPosition(di, var_4, mode, var); - - break; - } - case 4: - { - saveOpcodeVar = var; - break; - } - default: - { - printf("Unsupported type %d in opcodeType1\n",currentScriptOpcodeType); - exit(1); - } - } - - return(0); +// save opcode +int32 opcodeType1(void) { + int var = popVar(); + int offset = 0; + + switch (currentScriptOpcodeType) { + case 0: + { + return (0); // strange, but happens also in original interpreter + } + case 5: + { + offset = saveOpcodeVar; + } + case 1: + { + int var_A = 0; + + int byte1 = getByteFromScript(); + int byte2 = getByteFromScript(); + + int short1 = getShortFromScript(); + + int var_6 = byte1 & 7; + + int var_C = short1; + + uint8 *ptr = 0; + int type2; + + if (!var_6) + return (-10); + + var_C = short1; + + if (byte2) { + if (!overlayTable[byte2].alreadyLoaded) { + return (-7); + } + + if (!overlayTable[byte2].ovlData) { + return (-4); + } + + if (var_6 == 5) { + ptr = + overlayTable[byte2].ovlData-> + data4Ptr + var_C; + } else { + ASSERT(0); + } + } else { + ptr = scriptDataPtrTable[var_6] + var_C; + } + + type2 = ((byte1 & 0x18) >> 3); + + switch (type2) { + case 1: + { + saveShort(ptr + var_A + offset * 2, + var); + return 0; + } + case 2: + { + *(ptr + var_A + offset) = var; + return (0); + } + default: + { + printf + ("Unsupported code in opcodeType1 case 1!\n"); + exit(1); + } + } + + break; + } + case 2: + { + int mode = getByteFromScript(); + int di = getByteFromScript(); + int var_4 = getShortFromScript(); + + if (!di) { + di = currentScriptPtr->overlayNumber; + } + + if (var == 0x85) // Special case to handle... + { + ASSERT(0); + } + + setObjectPosition(di, var_4, mode, var); + + break; + } + case 4: + { + saveOpcodeVar = var; + break; + } + default: + { + printf("Unsupported type %d in opcodeType1\n", + currentScriptOpcodeType); + exit(1); + } + } + + return (0); } +int32 opcodeType2(void) { + int offset = saveOpcodeVar; + int byte1 = getByteFromScript(); + int byte2 = getByteFromScript(); + short int short1 = getShortFromScript(); + + ASSERT(currentScriptOpcodeType == 1 || currentScriptOpcodeType == 5); + + if (currentScriptOpcodeType == 5) + short1 += saveOpcodeVar; + + ASSERT(byte1 & 7); + + if (!(byte1 & 7)) { + return (-10); + } + + if (!byte2) { + int type2; + uint8 *ptr = scriptDataPtrTable[byte1 & 7] + short1; + + type2 = ((byte1 & 0x18) >> 3); -int32 opcodeType2(void) -{ - int offset = saveOpcodeVar; - int byte1 = getByteFromScript(); - int byte2 = getByteFromScript(); - short int short1 = getShortFromScript(); - - ASSERT(currentScriptOpcodeType == 1 || currentScriptOpcodeType == 5); - - if(currentScriptOpcodeType == 5) - short1 += saveOpcodeVar; - - ASSERT(byte1 & 7); - - if(!(byte1 & 7)) - { - return(-10); - } - - if(!byte2) - { - int type2; - uint8* ptr = scriptDataPtrTable[byte1 & 7] + short1; - - type2 = ((byte1&0x18)>>3); - - ASSERT(type2 == 1 || type2 == 2); - - switch(type2) - { - case 1: - { - pushPtr(ptr + offset); - return(0); - } - case 2: - { - pushPtr(ptr); - return(0); - } - default : - { - return(-10); - } - } - } - else - { - printf("Unsupported code in opcodeType2 case 1!\n"); - exit(1); - } - - return 0; + ASSERT(type2 == 1 || type2 == 2); + + switch (type2) { + case 1: + { + pushPtr(ptr + offset); + return (0); + } + case 2: + { + pushPtr(ptr); + return (0); + } + default: + { + return (-10); + } + } + } else { + printf("Unsupported code in opcodeType2 case 1!\n"); + exit(1); + } + + return 0; } -int32 opcodeType10(void) // break -{ - return(0); +int32 opcodeType10(void) { // break + return (0); } -int32 opcodeType11(void) // break -{ - return(1); +int32 opcodeType11(void) { // break + return (1); } -int32 opcodeType4(void) // test -{ - int boolVar = 0; - - var1 = popVar(); - var2 = popVar(); - - switch(currentScriptOpcodeType) - { - case 0: - { - if(var2!=var1) - boolVar = 1; - break; - } - case 1: - { - if(var2==var1) - boolVar = 1; - break; - } - case 2: - { - if(var2<var1) - boolVar = 1; - break; - } - case 3: - { - if(var2<=var1) - boolVar = 1; - break; - } - case 4: - { - if(var2>var1) - boolVar = 1; - break; - } - case 5: - { - if(var2>=var1) - boolVar = 1; - break; - } - - } - - pushVar(boolVar); - - return(0); +int32 opcodeType4(void) { // test + int boolVar = 0; + + var1 = popVar(); + var2 = popVar(); + + switch (currentScriptOpcodeType) { + case 0: + { + if (var2 != var1) + boolVar = 1; + break; + } + case 1: + { + if (var2 == var1) + boolVar = 1; + break; + } + case 2: + { + if (var2 < var1) + boolVar = 1; + break; + } + case 3: + { + if (var2 <= var1) + boolVar = 1; + break; + } + case 4: + { + if (var2 > var1) + boolVar = 1; + break; + } + case 5: + { + if (var2 >= var1) + boolVar = 1; + break; + } + + } + + pushVar(boolVar); + + return (0); } -int32 opcodeType6(void) -{ - int si = 0; +int32 opcodeType6(void) { + int si = 0; - int pop = popVar(); + int pop = popVar(); - if(!pop) - si = 1; + if (!pop) + si = 1; - if(pop<0) - { - si |= 4; - } + if (pop < 0) { + si |= 4; + } - if(pop>0) - { - si |= 2; - } + if (pop > 0) { + si |= 2; + } - currentScriptPtr->bitMask = si; + currentScriptPtr->bitMask = si; - return(0); + return (0); } -int32 opcodeType7(void) -{ - var1 = popVar(); - var2 = popVar(); +int32 opcodeType7(void) { + var1 = popVar(); + var2 = popVar(); - pushVar(var1); - pushVar(var2); + pushVar(var1); + pushVar(var2); - return(0); + return (0); } -int32 opcodeType5(void) -{ - int offset = currentScriptPtr->var4; - int short1 = getShortFromScript(); - int newSi = short1 + offset; - int bitMask = currentScriptPtr->bitMask; - - switch(currentScriptOpcodeType) - { - case 0: - { - if(!(bitMask & 1)) - { - currentScriptPtr->var4 = newSi; - } - break; - } - case 1: - { - if(bitMask & 1) - { - currentScriptPtr->var4 = newSi; - } - break; - } - case 2: - { - if(bitMask & 2) - { - currentScriptPtr->var4 = newSi; - } - break; - } - case 3: - { - if(bitMask & 3) - { - currentScriptPtr->var4 = newSi; - } - break; - } - case 4: - { - if(bitMask & 4) - { - currentScriptPtr->var4 = newSi; - } - break; - } - case 5: - { - if(bitMask & 5) - { - currentScriptPtr->var4 = newSi; - } - break; - } - case 6: - { - break; // never - } - case 7: - { - currentScriptPtr->var4 = newSi; //always - } - } - - return(0); +int32 opcodeType5(void) { + int offset = currentScriptPtr->var4; + int short1 = getShortFromScript(); + int newSi = short1 + offset; + int bitMask = currentScriptPtr->bitMask; + + switch (currentScriptOpcodeType) { + case 0: + { + if (!(bitMask & 1)) { + currentScriptPtr->var4 = newSi; + } + break; + } + case 1: + { + if (bitMask & 1) { + currentScriptPtr->var4 = newSi; + } + break; + } + case 2: + { + if (bitMask & 2) { + currentScriptPtr->var4 = newSi; + } + break; + } + case 3: + { + if (bitMask & 3) { + currentScriptPtr->var4 = newSi; + } + break; + } + case 4: + { + if (bitMask & 4) { + currentScriptPtr->var4 = newSi; + } + break; + } + case 5: + { + if (bitMask & 5) { + currentScriptPtr->var4 = newSi; + } + break; + } + case 6: + { + break; // never + } + case 7: + { + currentScriptPtr->var4 = newSi; //always + } + } + + return (0); } -int32 opcodeType3(void) // math -{ - int pop1 = popVar(); - int pop2 = popVar(); - - switch(currentScriptOpcodeType) - { - case 0: - { - pushVar(pop1+pop2); - return(0); - } - case 1: - { - pushVar(pop1/pop2); - return(0); - } - case 2: - { - pushVar(pop1-pop2); - return(0); - } - case 3: - { - pushVar(pop1*pop2); - return(0); - } - case 4: - { - pushVar(pop1%pop2); - return(0); - } - case 7: - case 5: - { - pushVar(pop2|pop1); - return(0); - } - case 6: - { - pushVar(pop2&pop1); - return(0); - } - } - - return 0; +int32 opcodeType3(void) { // math + int pop1 = popVar(); + int pop2 = popVar(); + + switch (currentScriptOpcodeType) { + case 0: + { + pushVar(pop1 + pop2); + return (0); + } + case 1: + { + pushVar(pop1 / pop2); + return (0); + } + case 2: + { + pushVar(pop1 - pop2); + return (0); + } + case 3: + { + pushVar(pop1 * pop2); + return (0); + } + case 4: + { + pushVar(pop1 % pop2); + return (0); + } + case 7: + case 5: + { + pushVar(pop2 | pop1); + return (0); + } + case 6: + { + pushVar(pop2 & pop1); + return (0); + } + } + + return 0; } -int32 opcodeType9(void) // stop script -{ - //printf("Stop a script of overlay %s\n",overlayTable[currentScriptPtr->overlayNumber].overlayName); - currentScriptPtr->scriptNumber = -1; - return(1); +int32 opcodeType9(void) { // stop script + //printf("Stop a script of overlay %s\n",overlayTable[currentScriptPtr->overlayNumber].overlayName); + currentScriptPtr->scriptNumber = -1; + return (1); } - -void setupFuncArray() -{ - int i; - - for(i=0;i<64;i++) - { - opcodeTypeTable[i] = NULL; - } - - opcodeTypeTable[1] = opcodeType0; - opcodeTypeTable[2] = opcodeType1; - opcodeTypeTable[3] = opcodeType2; - opcodeTypeTable[4] = opcodeType3; - opcodeTypeTable[5] = opcodeType4; - opcodeTypeTable[6] = opcodeType5; - opcodeTypeTable[7] = opcodeType6; - opcodeTypeTable[8] = opcodeType7; - opcodeTypeTable[9] = opcodeType8; - opcodeTypeTable[10] = opcodeType9; - opcodeTypeTable[11] = opcodeType10; - opcodeTypeTable[12] = opcodeType11; +void setupFuncArray() { + int i; + + for (i = 0; i < 64; i++) { + opcodeTypeTable[i] = NULL; + } + + opcodeTypeTable[1] = opcodeType0; + opcodeTypeTable[2] = opcodeType1; + opcodeTypeTable[3] = opcodeType2; + opcodeTypeTable[4] = opcodeType3; + opcodeTypeTable[5] = opcodeType4; + opcodeTypeTable[6] = opcodeType5; + opcodeTypeTable[7] = opcodeType6; + opcodeTypeTable[8] = opcodeType7; + opcodeTypeTable[9] = opcodeType8; + opcodeTypeTable[10] = opcodeType9; + opcodeTypeTable[11] = opcodeType10; + opcodeTypeTable[12] = opcodeType11; } -int removeScript(int overlay,int idx,scriptInstanceStruct* headPtr) -{ - scriptInstanceStruct* scriptPtr; +int removeScript(int overlay, int idx, scriptInstanceStruct *headPtr) { + scriptInstanceStruct *scriptPtr; - scriptPtr = headPtr->nextScriptPtr; + scriptPtr = headPtr->nextScriptPtr; - if(scriptPtr) - { - do - { - if(scriptPtr->overlayNumber == overlay && (scriptPtr->scriptNumber == idx || idx == -1)) - { - scriptPtr->scriptNumber = -1; - } + if (scriptPtr) { + do { + if (scriptPtr->overlayNumber == overlay + && (scriptPtr->scriptNumber == idx || idx == -1)) { + scriptPtr->scriptNumber = -1; + } - scriptPtr = scriptPtr->nextScriptPtr; - } - while(scriptPtr); - } + scriptPtr = scriptPtr->nextScriptPtr; + } + while (scriptPtr); + } - return(0); + return (0); } -uint8* attacheNewScriptToTail(int16 overlayNumber,scriptInstanceStruct* scriptHandlePtr,int16 param, int16 arg0, int16 arg1, int16 arg2, scriptTypeEnum scriptType) -{ - int useArg3Neg = 0; - ovlData3Struct* data3Ptr; - scriptInstanceStruct* tempPtr; - int var_C; - scriptInstanceStruct* oldTail; - - //printf("Starting script %d of overlay %s\n",param,overlayTable[overlayNumber].overlayName); - - if(scriptType<0) - { - useArg3Neg = 1; - scriptType = (scriptTypeEnum)-scriptType; - } - - if(scriptType == 20) - { - data3Ptr = getOvlData3Entry(overlayNumber,param); - } - else - { - if(scriptType == 30) - { - data3Ptr = scriptFunc1Sub2(overlayNumber,param); - } - else - { - return(NULL); - } - } - - if(!data3Ptr) - { - return(NULL); - } - - if(!data3Ptr->dataPtr) - { - return(NULL); - } - - var_C = data3Ptr->sysKey; - - oldTail = scriptHandlePtr; - - while(oldTail->nextScriptPtr) // go to the end of the list - { - oldTail=oldTail->nextScriptPtr; - } - - tempPtr = (scriptInstanceStruct*)mallocAndZero(sizeof(scriptInstanceStruct)); - - if(!tempPtr) - return(NULL); - - tempPtr->var6 = NULL; - - if(var_C) - { - tempPtr->var6 = (uint8*)mallocAndZero(var_C); - } - - tempPtr->varA = var_C; - tempPtr->nextScriptPtr = NULL; - tempPtr->var4 = 0; - - tempPtr->scriptNumber = param; - tempPtr->overlayNumber = overlayNumber; - - if(scriptType == 20) // Obj or not ? - { - tempPtr->sysKey = useArg3Neg; - } - else - { - tempPtr->sysKey = 1; - } - - tempPtr->var12 = 0; - tempPtr->type = scriptType; - tempPtr->var18 = arg2; - tempPtr->var16 = arg1; - tempPtr->var1A = arg0; - tempPtr->nextScriptPtr = oldTail->nextScriptPtr; // should always be NULL as it's the tail - - oldTail->nextScriptPtr = tempPtr; // attache the new node to the list - - return(tempPtr->var6); +uint8 *attacheNewScriptToTail(int16 overlayNumber, + scriptInstanceStruct *scriptHandlePtr, int16 param, int16 arg0, + int16 arg1, int16 arg2, scriptTypeEnum scriptType) { + int useArg3Neg = 0; + ovlData3Struct *data3Ptr; + scriptInstanceStruct *tempPtr; + int var_C; + scriptInstanceStruct *oldTail; + + //printf("Starting script %d of overlay %s\n",param,overlayTable[overlayNumber].overlayName); + + if (scriptType < 0) { + useArg3Neg = 1; + scriptType = (scriptTypeEnum) - scriptType; + } + + if (scriptType == 20) { + data3Ptr = getOvlData3Entry(overlayNumber, param); + } else { + if (scriptType == 30) { + data3Ptr = scriptFunc1Sub2(overlayNumber, param); + } else { + return (NULL); + } + } + + if (!data3Ptr) { + return (NULL); + } + + if (!data3Ptr->dataPtr) { + return (NULL); + } + + var_C = data3Ptr->sysKey; + + oldTail = scriptHandlePtr; + + while (oldTail->nextScriptPtr) // go to the end of the list + { + oldTail = oldTail->nextScriptPtr; + } + + tempPtr = + (scriptInstanceStruct *) + mallocAndZero(sizeof(scriptInstanceStruct)); + + if (!tempPtr) + return (NULL); + + tempPtr->var6 = NULL; + + if (var_C) { + tempPtr->var6 = (uint8 *) mallocAndZero(var_C); + } + + tempPtr->varA = var_C; + tempPtr->nextScriptPtr = NULL; + tempPtr->var4 = 0; + + tempPtr->scriptNumber = param; + tempPtr->overlayNumber = overlayNumber; + + if (scriptType == 20) // Obj or not ? + { + tempPtr->sysKey = useArg3Neg; + } else { + tempPtr->sysKey = 1; + } + + tempPtr->var12 = 0; + tempPtr->type = scriptType; + tempPtr->var18 = arg2; + tempPtr->var16 = arg1; + tempPtr->var1A = arg0; + tempPtr->nextScriptPtr = oldTail->nextScriptPtr; // should always be NULL as it's the tail + + oldTail->nextScriptPtr = tempPtr; // attache the new node to the list + + return (tempPtr->var6); } -int executeScripts(scriptInstanceStruct* ptr) -{ - int numScript2; - ovlData3Struct* ptr2; - ovlDataStruct* ovlData; - uint8 opcodeType; - - numScript2 = ptr->scriptNumber; - - if(ptr->type == 20) - { - ptr2 = getOvlData3Entry(ptr->overlayNumber,numScript2); - - if(!ptr2) - { - return(-4); - } - } - else - { - if(ptr->type == 30) - { - ptr2 = scriptFunc1Sub2(ptr->overlayNumber,numScript2); - - if(!ptr2) - { - return(-4); - } - } - else - { - return(-6); - } - } - - if(!overlayTable[ptr->overlayNumber].alreadyLoaded) - { - return(-7); - } - - ovlData = overlayTable[ptr->overlayNumber].ovlData; - - if(!ovlData) - return(-4); - - currentData3DataPtr = ptr2->dataPtr; - - scriptDataPtrTable[1] = (uint8*)ptr->var6; - scriptDataPtrTable[2] = getDataFromData3(ptr2, 1); - scriptDataPtrTable[5] = ovlData->data4Ptr; // free strings - scriptDataPtrTable[6] = ovlData->ptr8; - - currentScriptPtr = ptr; - - positionInStack = 0; - - do - { - if(currentScriptPtr->var4 == 290 && currentScriptPtr->overlayNumber == 4 && currentScriptPtr->scriptNumber == 0) - { - currentScriptPtr->var4 = 923; - } - opcodeType = getByteFromScript(); - - //printf("opType: %d\n",(opcodeType&0xFB)>>3); - - currentScriptOpcodeType = opcodeType & 7; - - if(!opcodeTypeTable[(opcodeType&0xFB)>>3]) - { - printf("Unsupported opcode type %d\n",(opcodeType&0xFB)>>3); - exit(1); - return(-21); - } - }while(!opcodeTypeTable[(opcodeType&0xFB)>>3]()); - - return(0); +int executeScripts(scriptInstanceStruct *ptr) { + int numScript2; + ovlData3Struct *ptr2; + ovlDataStruct *ovlData; + uint8 opcodeType; + + numScript2 = ptr->scriptNumber; + + if (ptr->type == 20) { + ptr2 = getOvlData3Entry(ptr->overlayNumber, numScript2); + + if (!ptr2) { + return (-4); + } + } else { + if (ptr->type == 30) { + ptr2 = scriptFunc1Sub2(ptr->overlayNumber, numScript2); + + if (!ptr2) { + return (-4); + } + } else { + return (-6); + } + } + + if (!overlayTable[ptr->overlayNumber].alreadyLoaded) { + return (-7); + } + + ovlData = overlayTable[ptr->overlayNumber].ovlData; + + if (!ovlData) + return (-4); + + currentData3DataPtr = ptr2->dataPtr; + + scriptDataPtrTable[1] = (uint8 *) ptr->var6; + scriptDataPtrTable[2] = getDataFromData3(ptr2, 1); + scriptDataPtrTable[5] = ovlData->data4Ptr; // free strings + scriptDataPtrTable[6] = ovlData->ptr8; + + currentScriptPtr = ptr; + + positionInStack = 0; + + do { + if (currentScriptPtr->var4 == 290 + && currentScriptPtr->overlayNumber == 4 + && currentScriptPtr->scriptNumber == 0) { + currentScriptPtr->var4 = 923; + } + opcodeType = getByteFromScript(); + + //printf("opType: %d\n",(opcodeType&0xFB)>>3); + + currentScriptOpcodeType = opcodeType & 7; + + if (!opcodeTypeTable[(opcodeType & 0xFB) >> 3]) { + printf("Unsupported opcode type %d\n", + (opcodeType & 0xFB) >> 3); + exit(1); + return (-21); + } + } while (!opcodeTypeTable[(opcodeType & 0xFB) >> 3] ()); + + return (0); } -void manageScripts(scriptInstanceStruct* scriptHandle) -{ - scriptInstanceStruct* ptr = scriptHandle; - - if(ptr) - { - do - { - if(!overlayTable[ptr->overlayNumber].executeScripts) - { - if(ptr->scriptNumber != -1 && ptr->var12 == 0 && ptr->sysKey != 0) - { - executeScripts(ptr); - } - - if(ptr->sysKey == 0) - { - ptr->sysKey = 1; - } - } - - ptr = ptr->nextScriptPtr; - - }while(ptr); - } +void manageScripts(scriptInstanceStruct *scriptHandle) { + scriptInstanceStruct *ptr = scriptHandle; + + if (ptr) { + do { + if (!overlayTable[ptr->overlayNumber].executeScripts) { + if (ptr->scriptNumber != -1 && ptr->var12 == 0 + && ptr->sysKey != 0) { + executeScripts(ptr); + } + + if (ptr->sysKey == 0) { + ptr->sysKey = 1; + } + } + + ptr = ptr->nextScriptPtr; + + } while (ptr); + } } } // End of namespace Cruise diff --git a/engines/cruise/script.h b/engines/cruise/script.h index dd3f671a8c..574eae49bc 100644 --- a/engines/cruise/script.h +++ b/engines/cruise/script.h @@ -22,26 +22,24 @@ * */ -#ifndef _SCRIPT_H_ -#define _SCRIPT_H_ +#ifndef CRUISE_SCRIPT_H +#define CRUISE_SCRIPT_H namespace Cruise { -enum scriptTypeEnum -{ - scriptType_Minus20 = -20, - scriptType_Minus30 = -30, - scriptType_20 = 20, - scriptType_30 = 30 +enum scriptTypeEnum { + scriptType_Minus20 = -20, + scriptType_Minus30 = -30, + scriptType_20 = 20, + scriptType_30 = 30 }; typedef enum scriptTypeEnum scriptTypeEnum; -struct scriptInstanceStruct -{ - struct scriptInstanceStruct* nextScriptPtr; +struct scriptInstanceStruct { + struct scriptInstanceStruct *nextScriptPtr; int16 var4; - uint8* var6; + uint8 *var6; int16 varA; int16 scriptNumber; int16 overlayNumber; @@ -59,14 +57,16 @@ typedef struct scriptInstanceStruct scriptInstanceStruct; extern scriptInstanceStruct scriptHandle1; extern scriptInstanceStruct scriptHandle2; -extern scriptInstanceStruct* currentScriptPtr; +extern scriptInstanceStruct *currentScriptPtr; void setupFuncArray(void); uint8 getByteFromScript(void); -int removeScript(int overlay,int idx,scriptInstanceStruct* headPtr); -uint8* attacheNewScriptToTail(int16 overlayNumber,scriptInstanceStruct* scriptHandlePtr,int16 param, int16 arg0, int16 arg1, int16 arg2, scriptTypeEnum scriptType); -void manageScripts(scriptInstanceStruct* scriptHandle); +int removeScript(int overlay, int idx, scriptInstanceStruct * headPtr); +uint8 *attacheNewScriptToTail(int16 overlayNumber, + scriptInstanceStruct * scriptHandlePtr, int16 param, int16 arg0, + int16 arg1, int16 arg2, scriptTypeEnum scriptType); +void manageScripts(scriptInstanceStruct * scriptHandle); } // End of namespace Cruise diff --git a/engines/cruise/stack.cpp b/engines/cruise/stack.cpp index d83a496281..6cce7579ed 100644 --- a/engines/cruise/stack.cpp +++ b/engines/cruise/stack.cpp @@ -31,55 +31,46 @@ stackElementStruct scriptStack[SIZE_STACK]; // VAR -void pushVar(int16 var) -{ - if(positionInStack<SIZE_STACK) - { - scriptStack[positionInStack].data.shortVar = var; - scriptStack[positionInStack].type = STACK_SHORT; - positionInStack++; - } +void pushVar(int16 var) { + if (positionInStack < SIZE_STACK) { + scriptStack[positionInStack].data.shortVar = var; + scriptStack[positionInStack].type = STACK_SHORT; + positionInStack++; + } } -int16 popVar(void) -{ - if(positionInStack<=0) - { - return(0); - } +int16 popVar(void) { + if (positionInStack <= 0) { + return (0); + } - positionInStack--; - - ASSERT(scriptStack[positionInStack].type == STACK_SHORT); + positionInStack--; - return(scriptStack[positionInStack].data.shortVar); + ASSERT(scriptStack[positionInStack].type == STACK_SHORT); + + return (scriptStack[positionInStack].data.shortVar); } //// PTR -void pushPtr(void* ptr) -{ - if(positionInStack<SIZE_STACK) - { - scriptStack[positionInStack].data.ptrVar = ptr; - scriptStack[positionInStack].type = STACK_PTR; - positionInStack++; - } +void pushPtr(void *ptr) { + if (positionInStack < SIZE_STACK) { + scriptStack[positionInStack].data.ptrVar = ptr; + scriptStack[positionInStack].type = STACK_PTR; + positionInStack++; + } } -void* popPtr() -{ - if(positionInStack<=0) - { - return(0); - } +void *popPtr() { + if (positionInStack <= 0) { + return (0); + } + + positionInStack--; - positionInStack--; - - ASSERT(scriptStack[positionInStack].type == STACK_PTR); + ASSERT(scriptStack[positionInStack].type == STACK_PTR); - return(scriptStack[positionInStack].data.ptrVar); + return (scriptStack[positionInStack].data.ptrVar); } } // End of namespace Cruise - diff --git a/engines/cruise/stack.h b/engines/cruise/stack.h index 0d04bb0318..e3973b8e74 100644 --- a/engines/cruise/stack.h +++ b/engines/cruise/stack.h @@ -22,30 +22,27 @@ * */ -#ifndef _STACK_H_ -#define _STACK_H_ +#ifndef CRUISE_STACK_H +#define CRUISE_STACK_H namespace Cruise { #define SIZE_STACK 0x200 -enum stackElementTypeEnum -{ - STACK_SHORT, - STACK_PTR +enum stackElementTypeEnum { + STACK_SHORT, + STACK_PTR }; typedef enum stackElementTypeEnum stackElementTypeEnum; -struct stackElementStruct -{ - stackElementTypeEnum type; - - union - { - void* ptrVar; - int16 shortVar; - } data; +struct stackElementStruct { + stackElementTypeEnum type; + + union { + void *ptrVar; + int16 shortVar; + } data; }; typedef struct stackElementStruct stackElementStruct; @@ -53,8 +50,8 @@ typedef struct stackElementStruct stackElementStruct; int16 popVar(void); void pushVar(int16 var); -void pushPtr(void* ptr); -void* popPtr(void); +void pushPtr(void *ptr); +void *popPtr(void); } // End of namespace Cruise diff --git a/engines/cruise/stringSupport.cpp b/engines/cruise/stringSupport.cpp index 1421ba7943..b618d16f55 100644 --- a/engines/cruise/stringSupport.cpp +++ b/engines/cruise/stringSupport.cpp @@ -26,24 +26,20 @@ namespace Cruise { -void strcpyuint8(void* dest, const void* source) -{ - strcpy((char*)dest,(const char*)source); +void strcpyuint8(void *dest, const void *source) { + strcpy((char *)dest, (const char *)source); } -void strcatuint8(void* dest, const void* source) -{ - strcat((char*)dest,(const char*)source); +void strcatuint8(void *dest, const void *source) { + strcat((char *)dest, (const char *)source); } -uint8 strcmpuint8(const void* string1, const void* string2) -{ - return strcmp((char*)string1,(char*)string2); +uint8 strcmpuint8(const void *string1, const void *string2) { + return strcmp((char *)string1, (char *)string2); } -FILE* fopenuint8(void* name, const void* param) -{ - return fopen((char*)name,(const char*)param); +FILE *fopenuint8(void *name, const void *param) { + return fopen((char *)name, (const char *)param); } } // End of namespace Cruise diff --git a/engines/cruise/stringSupport.h b/engines/cruise/stringSupport.h index d5d9b33702..d685940233 100644 --- a/engines/cruise/stringSupport.h +++ b/engines/cruise/stringSupport.h @@ -22,15 +22,15 @@ * */ -#ifndef _STRING_SUPPORT_H_ -#define _STRING_SUPPORT_H_ +#ifndef CRUISE_STRING_SUPPORT_H +#define CRSUIE_STRING_SUPPORT_H namespace Cruise { -void strcpyuint8(void* dest, const void* source); -void strcatuint8(void* dest, const void* source); -uint8 strcmpuint8(const void* string1, const void* string2); -FILE* fopenuint8(void* name, const void* param); +void strcpyuint8(void *dest, const void *source); +void strcatuint8(void *dest, const void *source); +uint8 strcmpuint8(const void *string1, const void *string2); +FILE *fopenuint8(void *name, const void *param); } // End of namespace Cruise diff --git a/engines/cruise/various.cpp b/engines/cruise/various.cpp index a6d33c1030..52b204dbf5 100644 --- a/engines/cruise/various.cpp +++ b/engines/cruise/various.cpp @@ -30,158 +30,140 @@ uint16 var0 = 0; uint16 fadeVar; uint16 main15; -int16 readB16(void* ptr) -{ +int16 readB16(void *ptr) { int16 temp; - temp = *(int16*)ptr; + temp = *(int16 *) ptr; flipShort(&temp); return temp; } -void freeObject(cellStruct* objPtr) -{ - if(objPtr) - { - /* if(objPtr->next) - free(objPtr->next); */ +void freeObject(cellStruct *objPtr) { + if (objPtr) { + /* if(objPtr->next) + * free(objPtr->next); */ - //free(objPtr); - } + //free(objPtr); + } } -void removeObjectFromList(int ovlNumber, int objectIdx, cellStruct* objPtr, int backgroundPlane, int arg) -{ - cellStruct* currentObj = objPtr->next; - cellStruct* previous; +void removeObjectFromList(int ovlNumber, int objectIdx, cellStruct *objPtr, + int backgroundPlane, int arg) { + cellStruct *currentObj = objPtr->next; + cellStruct *previous; - while(currentObj) - { - cellStruct* si; + while (currentObj) { + cellStruct *si; - si = currentObj; + si = currentObj; - if( (si->overlay == ovlNumber || ovlNumber == -1) && - (si->idx == objectIdx || objectIdx == -1) && - (si->type == arg || arg == -1) && - (si->backgroundPlane == backgroundPlane || backgroundPlane == -1) ) - { - si->type = -1; - } + if ((si->overlay == ovlNumber || ovlNumber == -1) && + (si->idx == objectIdx || objectIdx == -1) && + (si->type == arg || arg == -1) && + (si->backgroundPlane == backgroundPlane + || backgroundPlane == -1)) { + si->type = -1; + } - currentObj = si->next; - } + currentObj = si->next; + } - previous = objPtr; - currentObj = objPtr->next; + previous = objPtr; + currentObj = objPtr->next; - while(currentObj) - { - cellStruct* si; + while (currentObj) { + cellStruct *si; - si = currentObj; + si = currentObj; - if(si->type == -1) - { - cellStruct* dx; - previous->next = si->next; + if (si->type == -1) { + cellStruct *dx; + previous->next = si->next; - dx = si->next; + dx = si->next; - if(!si->next) - { - dx = objPtr; - } + if (!si->next) { + dx = objPtr; + } - dx->prev = si->prev; + dx->prev = si->prev; - freeObject(si); + freeObject(si); - free(si); + free(si); - currentObj = dx; - } - else - { - currentObj = si->next; - previous = si; - } - } + currentObj = dx; + } else { + currentObj = si->next; + previous = si; + } + } } -char* getText(int textIndex, int overlayIndex) -{ - if(!overlayTable[overlayIndex].ovlData) - { - return NULL; - } +char *getText(int textIndex, int overlayIndex) { + if (!overlayTable[overlayIndex].ovlData) { + return NULL; + } - if(!overlayTable[overlayIndex].ovlData->stringTable) - { - return NULL; - } + if (!overlayTable[overlayIndex].ovlData->stringTable) { + return NULL; + } - return overlayTable[overlayIndex].ovlData->stringTable[textIndex].string; + return overlayTable[overlayIndex].ovlData->stringTable[textIndex]. + string; } -void createTextObject(int overlayIdx, int oldVar8, cellStruct *pObject, int scriptNumber, int scriptOverlayNumber, int backgroundPlane, int16 color, int oldVar2, int oldVar4, int oldVar6) -{ - char* ax; - cellStruct* savePObject = pObject; - cellStruct* cx; - - cellStruct* pNewElement; - cellStruct* si = pObject->next; - cellStruct* var_2; - - while(si) - { - pObject = si; - si = si->next; - } - - var_2 = si; - - pNewElement = (cellStruct*)malloc(sizeof(cellStruct)); - - pNewElement->next = pObject->next; - pObject->next = pNewElement; - - pNewElement->idx = oldVar8; - pNewElement->type = 5; - pNewElement->backgroundPlane = backgroundPlane; - pNewElement->overlay = overlayIdx; - pNewElement->field_A = oldVar6; - pNewElement->field_C = oldVar4; - pNewElement->spriteIdx = oldVar2; - pNewElement->field_10 = color; - pNewElement->freeze = 0; - pNewElement->field_16 = scriptNumber; - pNewElement->field_18 = scriptOverlayNumber; - pNewElement->gfxPtr = NULL; - - if(var_2) - { - cx = var_2; - } - else - { - cx = savePObject; - } - - pNewElement->prev = cx->prev; - cx->prev = pNewElement; - - ax = getText(oldVar8, overlayIdx); - - if(ax) - { - pNewElement->gfxPtr = renderText(oldVar2, (uint8*)ax); - } +void createTextObject(int overlayIdx, int oldVar8, cellStruct *pObject, + int scriptNumber, int scriptOverlayNumber, int backgroundPlane, + int16 color, int oldVar2, int oldVar4, int oldVar6) { + char *ax; + cellStruct *savePObject = pObject; + cellStruct *cx; + + cellStruct *pNewElement; + cellStruct *si = pObject->next; + cellStruct *var_2; + + while (si) { + pObject = si; + si = si->next; + } + + var_2 = si; + + pNewElement = (cellStruct *) malloc(sizeof(cellStruct)); + + pNewElement->next = pObject->next; + pObject->next = pNewElement; + + pNewElement->idx = oldVar8; + pNewElement->type = 5; + pNewElement->backgroundPlane = backgroundPlane; + pNewElement->overlay = overlayIdx; + pNewElement->field_A = oldVar6; + pNewElement->field_C = oldVar4; + pNewElement->spriteIdx = oldVar2; + pNewElement->field_10 = color; + pNewElement->freeze = 0; + pNewElement->field_16 = scriptNumber; + pNewElement->field_18 = scriptOverlayNumber; + pNewElement->gfxPtr = NULL; + + if (var_2) { + cx = var_2; + } else { + cx = savePObject; + } + + pNewElement->prev = cx->prev; + cx->prev = pNewElement; + + ax = getText(oldVar8, overlayIdx); + + if (ax) { + pNewElement->gfxPtr = renderText(oldVar2, (uint8 *) ax); + } } } // End of namespace Cruise - - - diff --git a/engines/cruise/various.h b/engines/cruise/various.h index 437967b135..990a21f0c5 100644 --- a/engines/cruise/various.h +++ b/engines/cruise/various.h @@ -22,8 +22,8 @@ * */ -#ifndef _VARIOUS_H_ -#define _VARIOUS_H_ +#ifndef CRUISE_VARIOUS_H +#define CRUISE_VARIOUS_H #include "cruise/cell.h" @@ -33,11 +33,14 @@ extern uint16 var0; extern uint16 fadeVar; extern uint16 main15; -int16 readB16(void* ptr); +int16 readB16(void *ptr); -void createTextObject(int overlayIdx, int oldVar8, cellStruct *pObject, int scriptNumber, int scriptOverlayNumber, int backgroundPlane, int16 color, int oldVar2, int oldVar4, int oldVar6); -void removeObjectFromList(int ovlNumber, int objectIdx, cellStruct* objPtr, int backgroundPlane, int arg); -int16 Op_InitializeStateSub(int ovlIdx,int param1,int param2); +void createTextObject(int overlayIdx, int oldVar8, cellStruct * pObject, + int scriptNumber, int scriptOverlayNumber, int backgroundPlane, + int16 color, int oldVar2, int oldVar4, int oldVar6); +void removeObjectFromList(int ovlNumber, int objectIdx, cellStruct * objPtr, + int backgroundPlane, int arg); +int16 Op_InitializeStateSub(int ovlIdx, int param1, int param2); } // End of namespace Cruise diff --git a/engines/cruise/vars.cpp b/engines/cruise/vars.cpp index 5ca64055fb..f37595afa2 100644 --- a/engines/cruise/vars.cpp +++ b/engines/cruise/vars.cpp @@ -26,7 +26,7 @@ namespace Cruise { -uint8* _systemFNT; +uint8 *_systemFNT; uint8 video2 = 1; uint8 video3 = 3; @@ -69,7 +69,7 @@ Common::File currentVolumeFile; int16 currentCursor; int16 volumeNumEntry; -fileEntry* volumePtrToFileDescriptor = NULL; +fileEntry *volumePtrToFileDescriptor = NULL; uint32 volumeFileDescriptorSize; int16 volumeSizeOfEntry; @@ -89,16 +89,14 @@ cellStruct cellHead; opcodeTypeFunction opcodeTypeTable[64]; - int16 positionInStack; actorStruct actorHead; - int16 setup1; -uint8* currentData3DataPtr; -uint8* scriptDataPtrTable[7]; +uint8 *currentData3DataPtr; +uint8 *scriptDataPtrTable[7]; int16 currentScriptOpcodeType; @@ -142,30 +140,30 @@ int16 var48; int16 flagCt; int8 var50[64]; -int16 palette[256*3]; +int16 palette[256 * 3]; systemStringsStruct systemStrings; uint8 currentCtpName[40]; int16 saveVar1; -uint8 saveVar2[97]; // recheck size +uint8 saveVar2[97]; // recheck size -int16 numberOfWalkboxes; // saveVar3 +int16 numberOfWalkboxes; // saveVar3 int16 walkboxType[15]; // saveVar4 -int16 walkboxChange[15]; // saveVar5 +int16 walkboxChange[15]; // saveVar5 uint8 saveVar6[16]; int32 loadFileVar1; int16 ctpVar1 = 0; -int16 ctp_routeCoordCount; // ctpVar2 -int16 ctp_routeCoords[20][2]; // ctpVar3 -int16 ctp_routes[20][10]; +int16 ctp_routeCoordCount; // ctpVar2 +int16 ctp_routeCoords[20][2]; // ctpVar3 +int16 ctp_routes[20][10]; uint16 ctp_walkboxTable[15 * 40]; // ctpVar5 -int8 ctpVar6[32]; -int16 ctp_scale[15]; // ctpVar7 +int8 ctpVar6[32]; +int16 ctp_scale[15]; // ctpVar7 int16 ctpVar8[200]; int16 ctpVar14; @@ -174,8 +172,8 @@ int16 bgVar1; int16 bgVar2; int16 bgVar3; -uint8 globalScreen[320*200]; -uint8 scaledScreen[640*400]; +uint8 globalScreen[320 * 200]; +uint8 scaledScreen[640 * 400]; //OSystem *osystem; diff --git a/engines/cruise/vars.h b/engines/cruise/vars.h index 8ed5e88494..31ec0365f6 100644 --- a/engines/cruise/vars.h +++ b/engines/cruise/vars.h @@ -22,42 +22,39 @@ * */ -#ifndef _VARS_H_ -#define _VARS_H_ +#ifndef CRUISE_VARS_H +#define CRUISE_VARS_H #include "common/file.h" namespace Cruise { -struct menuElementSubStruct -{ - struct menuElementSubStruct* pNext; - int16 var2; - int16 var4; +struct menuElementSubStruct { + struct menuElementSubStruct *pNext; + int16 var2; + int16 var4; }; typedef struct menuElementSubStruct menuElementSubStruct; -struct menuElementStruct -{ - struct menuElementStruct* next; - const char* string; - int x; - int y; - int varA; - int varC; - unsigned char color; - gfxEntryStruct* gfx; - menuElementSubStruct* ptrSub; +struct menuElementStruct { + struct menuElementStruct *next; + const char *string; + int x; + int y; + int varA; + int varC; + unsigned char color; + gfxEntryStruct *gfx; + menuElementSubStruct *ptrSub; }; typedef struct menuElementStruct menuElementStruct; -typedef int32(*opcodeTypeFunction)(void); -typedef int16(*opcodeFunction)(void); +typedef int32(*opcodeTypeFunction) (void); +typedef int16(*opcodeFunction) (void); - -extern uint8* _systemFNT; +extern uint8 *_systemFNT; extern int16 fontFileIndex; extern uint8 video2; @@ -74,15 +71,13 @@ extern int16 currentActiveBackgroundPlane; extern int16 main5; extern int16 var22; - -struct mediumVarStruct -{ +struct mediumVarStruct { uint8 name[16]; int16 field_10; int16 field_12; int16 field_14; int16 field_16; - uint8* ptr; + uint8 *ptr; int16 field_1C; int16 field_1E; int16 field_20; @@ -90,36 +85,32 @@ struct mediumVarStruct typedef struct mediumVarStruct mediumVarStruct; -struct filesDataStruct -{ - uint8* field_0; - uint8* field_4; +struct filesDataStruct { + uint8 *field_0; + uint8 *field_4; }; typedef struct filesDataStruct filesDataStruct; -struct filesData2Struct -{ +struct filesData2Struct { int16 field_0; int16 field_2; }; typedef struct filesData2Struct filesData2Struct; -struct fileName -{ +struct fileName { uint8 name[13]; }; typedef struct fileName fileName; -struct setHeaderEntry -{ - int16 field_0; // offset ptr part 1 - int16 field_2; // offset ptr part 2 +struct setHeaderEntry { + int16 field_0; // offset ptr part 1 + int16 field_2; // offset ptr part 2 int16 width; int16 height; - int16 type; // resource type, ie. sprites 0,1,4,5 and 8 + int16 type; // resource type, ie. sprites 0,1,4,5 and 8 int16 transparency; int16 field_C; int16 field_E; @@ -127,43 +118,39 @@ struct setHeaderEntry typedef struct setHeaderEntry setHeaderEntry; -struct volumeDataStruct -{ +struct volumeDataStruct { char ident[10]; - fileName* ptr; + fileName *ptr; int16 diskNumber; int32 size; }; typedef struct volumeDataStruct volumeDataStruct; -struct fileEntry -{ +struct fileEntry { uint8 name[14]; int32 offset; int32 size; int32 extSize; - int32 unk3; // unused + int32 unk3; // unused }; typedef struct fileEntry fileEntry; -struct dataFileEntrySub -{ - uint8* ptr; - int16 index; // sprite index - char name[14]; - int16 transparency; // sprite transparency - uint8* ptr2; - uint8 resourceType; // sprite and image type 2,4,8 , fnt = 7, spl = 6 - uint8 field_1B; +struct dataFileEntrySub { + uint8 *ptr; + int16 index; // sprite index + char name[14]; + int16 transparency; // sprite transparency + uint8 *ptr2; + uint8 resourceType; // sprite and image type 2,4,8 , fnt = 7, spl = 6 + uint8 field_1B; int16 field_1C; }; typedef struct dataFileEntrySub dataFileEntrySub; -struct dataFileEntry -{ +struct dataFileEntry { int16 widthInColumn; int16 width; int16 resType; @@ -173,8 +160,7 @@ struct dataFileEntry typedef struct dataFileEntry dataFileEntry; -struct systemStringsStruct -{ +struct systemStringsStruct { int8 param; uint8 string[12]; uint8 bootScriptName[8]; @@ -202,7 +188,6 @@ extern int16 main22; extern int16 main7; extern int16 main8; - extern int16 currentDiskNumber; extern Common::File currentVolumeFile; @@ -210,7 +195,7 @@ extern Common::File currentVolumeFile; extern int16 currentCursor; extern int16 volumeNumEntry; -extern fileEntry* volumePtrToFileDescriptor; +extern fileEntry *volumePtrToFileDescriptor; extern uint32 volumeFileDescriptorSize; extern int16 volumeSizeOfEntry; @@ -232,8 +217,8 @@ extern actorStruct actorHead; extern int16 setup1; -extern uint8* currentData3DataPtr; -extern uint8* scriptDataPtrTable[7]; +extern uint8 *currentData3DataPtr; +extern uint8 *scriptDataPtrTable[7]; extern int16 currentScriptOpcodeType; @@ -278,26 +263,26 @@ extern int16 var48; extern int16 flagCt; extern int8 var50[64]; -extern int16 palette[256*3]; +extern int16 palette[256 * 3]; extern systemStringsStruct systemStrings; extern uint8 currentCtpName[40]; extern int16 saveVar1; -extern uint8 saveVar2[97]; // recheck size +extern uint8 saveVar2[97]; // recheck size -extern int16 numberOfWalkboxes; // saveVar3 -extern int16 walkboxType[15]; // saveVar4 // Type: 0x00 - non walkable, 0x01 - walkable, 0x02 - exit zone -extern int16 walkboxChange[15]; // saveVar5 // walkbox can change its type: 0x00 - not changeable, 0x01 - changeable +extern int16 numberOfWalkboxes; // saveVar3 +extern int16 walkboxType[15]; // saveVar4 // Type: 0x00 - non walkable, 0x01 - walkable, 0x02 - exit zone +extern int16 walkboxChange[15]; // saveVar5 // walkbox can change its type: 0x00 - not changeable, 0x01 - changeable // Assumption: To change the type: walkboxType[i] -= walkboxChane[i] and vice versa extern uint8 saveVar6[16]; extern int32 loadFileVar1; extern int16 ctpVar1; -extern int16 ctp_routeCoordCount; // ctpVar2 // number of path-finding coordinates -extern int16 ctp_routeCoords[20][2]; // ctpVar3 // path-finding coordinates array +extern int16 ctp_routeCoordCount; // ctpVar2 // number of path-finding coordinates +extern int16 ctp_routeCoords[20][2]; // ctpVar3 // path-finding coordinates array /* ctp_routeCoords: @@ -305,7 +290,7 @@ extern int16 ctp_routeCoords[20][2]; // ctpVar3 // path-finding coordinates ar coordinate information with x (2 bytes) and y (2 bytes) */ -extern int16 ctp_routes[20][10]; // path-finding line information +extern int16 ctp_routes[20][10]; // path-finding line information /* ctp_routes: @@ -317,9 +302,9 @@ extern int16 ctp_routes[20][10]; // path-finding line information for the 20 * i slice the root x,y is routeCoords[i], routeCoords[i+2] the unused rest of the slice if filled up with 0xFF */ -extern uint16 ctp_walkboxTable[15 * 40]; // ctpVar5 // walkboxes coordinates and lines -extern int8 ctpVar6[32]; -extern int16 ctp_scale[15]; // ctpVar7 // scaling information for walkboxes +extern uint16 ctp_walkboxTable[15 * 40]; // ctpVar5 // walkboxes coordinates and lines +extern int8 ctpVar6[32]; +extern int16 ctp_scale[15]; // ctpVar7 // scaling information for walkboxes extern int16 ctpVar8[200]; extern int16 ctpVar14; @@ -328,8 +313,8 @@ extern int16 bgVar1; extern int16 bgVar2; extern int16 bgVar3; -extern uint8 globalScreen[320*200]; -extern uint8 scaledScreen[640*400]; +extern uint8 globalScreen[320 * 200]; +extern uint8 scaledScreen[640 * 400]; //extern OSystem *osystem; diff --git a/engines/cruise/volume.cpp b/engines/cruise/volume.cpp index ef877d6026..a31178a0cd 100644 --- a/engines/cruise/volume.cpp +++ b/engines/cruise/volume.cpp @@ -26,77 +26,72 @@ namespace Cruise { -FILE* PAL_fileHandle = NULL; -uint8* PAL_ptr = NULL; +FILE *PAL_fileHandle = NULL; +uint8 *PAL_ptr = NULL; int16 numLoadedPal; int16 fileData2; -void loadPal(volumeDataStruct* entry) -{ - char name[20]; +void loadPal(volumeDataStruct *entry) { + char name[20]; return; - if(PAL_fileHandle) - { - fclose(PAL_fileHandle); - } + if (PAL_fileHandle) { + fclose(PAL_fileHandle); + } + + removeExtention(entry->ident, name); + strcat(name, ".PAL"); - removeExtention(entry->ident, name); - strcat(name,".PAL"); - - PAL_fileHandle = fopen(name,"rb"); + PAL_fileHandle = fopen(name, "rb"); - fread(&numLoadedPal, 2, 1, PAL_fileHandle); - fread(&fileData2, 2, 1, PAL_fileHandle); + fread(&numLoadedPal, 2, 1, PAL_fileHandle); + fread(&fileData2, 2, 1, PAL_fileHandle); - flipShort(&numLoadedPal); - flipShort(&fileData2); + flipShort(&numLoadedPal); + flipShort(&fileData2); - PAL_ptr = (uint8*)malloc(numLoadedPal*fileData2); + PAL_ptr = (uint8 *) malloc(numLoadedPal * fileData2); } -int getVolumeDataEntry(volumeDataStruct* entry) -{ +int getVolumeDataEntry(volumeDataStruct *entry) { char buffer[256]; int i; volumeNumEntry = 0; volumeNumberOfEntry = 0; - if(currentVolumeFile.isOpen()) - { + if (currentVolumeFile.isOpen()) { freeDisk(); } askDisk(-1); - strcpyuint8(buffer,entry->ident); + strcpyuint8(buffer, entry->ident); currentVolumeFile.open(buffer); - if(!currentVolumeFile.isOpen()) - { - return(-14); + if (!currentVolumeFile.isOpen()) { + return (-14); } changeCursor(1); - currentVolumeFile.read(&volumeNumberOfEntry,2); - currentVolumeFile.read(&volumeSizeOfEntry,2); + currentVolumeFile.read(&volumeNumberOfEntry, 2); + currentVolumeFile.read(&volumeSizeOfEntry, 2); flipShort(&volumeNumberOfEntry); flipShort(&volumeSizeOfEntry); volumeNumEntry = volumeNumberOfEntry; - assert(volumeSizeOfEntry == 14+4+4+4+4); + assert(volumeSizeOfEntry == 14 + 4 + 4 + 4 + 4); - volumePtrToFileDescriptor = (fileEntry*)mallocAndZero(sizeof(fileEntry) * volumeNumEntry); + volumePtrToFileDescriptor = + (fileEntry *) mallocAndZero(sizeof(fileEntry) * volumeNumEntry); - for(i=0;i<volumeNumEntry;i++) - { + for (i = 0; i < volumeNumEntry; i++) { volumePtrToFileDescriptor[i].name[0] = 0; volumePtrToFileDescriptor[i].offset = 0; volumePtrToFileDescriptor[i].size = 0; @@ -104,177 +99,153 @@ int getVolumeDataEntry(volumeDataStruct* entry) volumePtrToFileDescriptor[i].unk3 = 0; } - for(i=0;i<volumeNumEntry;i++) - { + for (i = 0; i < volumeNumEntry; i++) { currentVolumeFile.read(&volumePtrToFileDescriptor[i].name, 14); - currentVolumeFile.read(&volumePtrToFileDescriptor[i].offset, 4); + currentVolumeFile.read(&volumePtrToFileDescriptor[i].offset, + 4); currentVolumeFile.read(&volumePtrToFileDescriptor[i].size, 4); - currentVolumeFile.read(&volumePtrToFileDescriptor[i].extSize, 4); + currentVolumeFile.read(&volumePtrToFileDescriptor[i].extSize, + 4); currentVolumeFile.read(&volumePtrToFileDescriptor[i].unk3, 4); } - for(i=0;i<volumeNumEntry;i++) - { + for (i = 0; i < volumeNumEntry; i++) { flipLong(&volumePtrToFileDescriptor[i].offset); flipLong(&volumePtrToFileDescriptor[i].size); flipLong(&volumePtrToFileDescriptor[i].extSize); } loadPal(entry); - + return 0; } -int searchFileInVolCnf(uint8* fileName,int32 diskNumber) -{ +int searchFileInVolCnf(uint8 *fileName, int32 diskNumber) { int foundDisk = -1; int i; - for(i=0;i<numOfDisks;i++) - { - if(volumeData[i].diskNumber == diskNumber) - { + for (i = 0; i < numOfDisks; i++) { + if (volumeData[i].diskNumber == diskNumber) { int j; int numOfEntry = volumeData[i].size / 13; - for(j=0;j<numOfEntry;j++) - { - if(!strcmpuint8(volumeData[i].ptr[j].name,fileName)) - { - return(i); + for (j = 0; j < numOfEntry; j++) { + if (!strcmpuint8(volumeData[i].ptr[j].name, + fileName)) { + return (i); } } } } - return(foundDisk); + return (foundDisk); } -int32 findFileInDisksSub1(uint8* fileName) -{ +int32 findFileInDisksSub1(uint8 *fileName) { int foundDisk = -1; int i; - for(i=0;i<numOfDisks;i++) - { + for (i = 0; i < numOfDisks; i++) { int j; int numOfEntry = volumeData[i].size / 13; - for(j=0;j<numOfEntry;j++) - { - if(!strcmpuint8(volumeData[i].ptr[j].name,fileName)) - { - return(i); + for (j = 0; j < numOfEntry; j++) { + if (!strcmpuint8(volumeData[i].ptr[j].name, fileName)) { + return (i); } } } - return(foundDisk); + return (foundDisk); } -void strToUpper(uint8* fileName) -{ +void strToUpper(uint8 *fileName) { char character; - do - { + do { character = *fileName; - if(character>='a' && character<='z') - { - character&=0xDF; + if (character >= 'a' && character <= 'z') { + character &= 0xDF; *fileName = character; } fileName++; - }while(character); + } while (character); } -int16 fileExist(uint8* fileName) -{ - FILE* fHandle; +int16 fileExist(uint8 *fileName) { + FILE *fHandle; - fHandle = fopenuint8(fileName,"rb"); + fHandle = fopenuint8(fileName, "rb"); - if(fHandle) - { + if (fHandle) { fclose(fHandle); - return(0); + return (0); } - - return(1); + + return (1); } -void freeDisk(void) -{ - if(currentVolumeFile.isOpen()) - { +void freeDisk(void) { + if (currentVolumeFile.isOpen()) { currentVolumeFile.close(); free(volumePtrToFileDescriptor); } /* TODO - if(PAL_fileHandle) - { - freeAllDataPtr(); - } - */ + * if(PAL_fileHandle) + * { + * freeAllDataPtr(); + * } + */ } -int16 findFileInList(uint8* fileName) -{ +int16 findFileInList(uint8 *fileName) { int i; - - if(!currentVolumeFile.isOpen()) - { - return(-1); + + if (!currentVolumeFile.isOpen()) { + return (-1); } strToUpper(fileName); - if(volumeNumEntry<=0) - { - return(-1); + if (volumeNumEntry <= 0) { + return (-1); } - for(i=0;i<volumeNumEntry;i++) - { - if(!strcmpuint8(volumePtrToFileDescriptor[i].name,fileName)) - { - return(i); + for (i = 0; i < volumeNumEntry; i++) { + if (!strcmpuint8(volumePtrToFileDescriptor[i].name, fileName)) { + return (i); } } - return(-1); + return (-1); } -void askDisk(int16 discNumber) -{ +void askDisk(int16 discNumber) { char diskNumberString[256]; uint8 fileName[256]; uint8 string[256]; char messageDrawn = 0; - if(discNumber != -1) - { + if (discNumber != -1) { currentDiskNumber = discNumber; } - // skip drive selection stuff - strcpyuint8(fileName,"VOL."); - sprintf(diskNumberString,"%d",currentDiskNumber); - strcatuint8(fileName,diskNumberString); + strcpyuint8(fileName, "VOL."); + sprintf(diskNumberString, "%d", currentDiskNumber); + strcatuint8(fileName, diskNumberString); - strcpyuint8(string,"INSERER LE DISQUE "); - strcatuint8(string,diskNumberString); - strcatuint8(string," EN "); + strcpyuint8(string, "INSERER LE DISQUE "); + strcatuint8(string, diskNumberString); + strcatuint8(string, " EN "); -// while(fileExist(fileName)) +// while(fileExist(fileName)) { - if(!messageDrawn) - { + if (!messageDrawn) { drawMsgString(string); messageDrawn = 1; } @@ -283,20 +254,15 @@ void askDisk(int16 discNumber) changeCursor(currentCursor); } - - -int16 findFileInDisks(uint8* fileName) -{ +int16 findFileInDisks(uint8 *fileName) { int disk; int fileIdx; - + strToUpper(fileName); - if(!volumeDataLoaded) - { + if (!volumeDataLoaded) { printf("CNF wasn't loaded, reading now...\n"); - if(currentVolumeFile.isOpen()) - { + if (currentVolumeFile.isOpen()) { askDisk(-1); freeDisk(); } @@ -305,28 +271,24 @@ int16 findFileInDisks(uint8* fileName) readVolCnf(); } - if(currentVolumeFile.isOpen()) - { + if (currentVolumeFile.isOpen()) { askDisk(-1); } fileIdx = findFileInList(fileName); - if(fileIdx>=0) - { - return(fileIdx); + if (fileIdx >= 0) { + return (fileIdx); } - disk = searchFileInVolCnf(fileName,currentDiskNumber); + disk = searchFileInVolCnf(fileName, currentDiskNumber); - if(disk>=0) - { + if (disk >= 0) { int temp; printf("File found on disk %d\n", disk); - - if(currentVolumeFile.isOpen()) - { + + if (currentVolumeFile.isOpen()) { askDisk(-1); } @@ -338,69 +300,61 @@ int16 findFileInDisks(uint8* fileName) temp = findFileInList(fileName); - if(temp>=0) - return(temp); + if (temp >= 0) + return (temp); - return(-1); + return (-1); - } - else - { + } else { int temp; temp = findFileInDisksSub1(fileName); - if(temp>=0) - { + if (temp >= 0) { int temp2; - + askDisk(volumeData[temp].diskNumber); getVolumeDataEntry(&volumeData[temp]); temp2 = findFileInList(fileName); - if(temp2>=0) - return(temp2); + if (temp2 >= 0) + return (temp2); } - - return(-1); + return (-1); } } -int16 readVolCnf(void) -{ +int16 readVolCnf(void) { int i; Common::File fileHandle; short int sizeHEntry; volumeDataLoaded = 0; - for(i=0;i<20;i++) - { + for (i = 0; i < 20; i++) { volumeData[i].ident[0] = 0; volumeData[i].ptr = NULL; - volumeData[i].diskNumber = i+1; + volumeData[i].diskNumber = i + 1; volumeData[i].size = 0; } fileHandle.open("VOL.CNF"); - if(!fileHandle.isOpen()) - { - return(0); + if (!fileHandle.isOpen()) { + return (0); } - fileHandle.read(&numOfDisks,2); + fileHandle.read(&numOfDisks, 2); flipShort(&numOfDisks); - fileHandle.read(&sizeHEntry,2); - flipShort(&sizeHEntry); // size of one header entry - 20 bytes + fileHandle.read(&sizeHEntry, 2); + flipShort(&sizeHEntry); // size of one header entry - 20 bytes - for(i=0;i<numOfDisks;i++) - { - // fread(&volumeData[i],20,1,fileHandle); + for (i = 0; i < numOfDisks; i++) { + // fread(&volumeData[i],20,1,fileHandle); fileHandle.read(&volumeData[i].ident, 10); fileHandle.read(&volumeData[i].ptr, 4); fileHandle.read(&volumeData[i].diskNumber, 2); @@ -411,24 +365,22 @@ int16 readVolCnf(void) flipLong(&volumeData[i].size); } - for(i=0;i<numOfDisks;i++) - { - fileName* ptr; - - fileHandle.read(&volumeData[i].size,4); + for (i = 0; i < numOfDisks; i++) { + fileName *ptr; + + fileHandle.read(&volumeData[i].size, 4); flipLong(&volumeData[i].size); - ptr = (fileName*)mallocAndZero(volumeData[i].size); + ptr = (fileName *) mallocAndZero(volumeData[i].size); volumeData[i].ptr = ptr; - if(!ptr) - { + if (!ptr) { fileHandle.close(); - return(-2); + return (-2); } - fileHandle.read(ptr,volumeData[i].size); + fileHandle.read(ptr, volumeData[i].size); } fileHandle.close(); @@ -438,31 +390,29 @@ int16 readVolCnf(void) //#define dumpResources #ifdef dumpResources - for(i=0;i<numOfDisks;i++) - { + for (i = 0; i < numOfDisks; i++) { int j; char nameBuffer[256]; - fileEntry* buffer; + fileEntry *buffer; - sprintf(nameBuffer,"D%d.",i+1); + sprintf(nameBuffer, "D%d.", i + 1); - fileHandle = fopen(nameBuffer,"rb"); + fileHandle = fopen(nameBuffer, "rb"); short int numEntry; short int sizeEntry; - fread(&numEntry,2,1,fileHandle); - fread(&sizeEntry,2,1,fileHandle); + fread(&numEntry, 2, 1, fileHandle); + fread(&sizeEntry, 2, 1, fileHandle); flipShort(&numEntry); flipShort(&sizeEntry); - buffer = (fileEntry*)mallocAndZero(numEntry*sizeEntry); + buffer = (fileEntry *) mallocAndZero(numEntry * sizeEntry); - fread(buffer,numEntry*sizeEntry,1,fileHandle); + fread(buffer, numEntry * sizeEntry, 1, fileHandle); - for(j=0;j<numEntry;j++) - { + for (j = 0; j < numEntry; j++) { flipLong(&buffer[j].offset); flipLong(&buffer[j].size); flipLong(&buffer[j].unk2); @@ -470,29 +420,33 @@ int16 readVolCnf(void) fseek(fileHandle, buffer[j].offset, SEEK_SET); - char* bufferLocal; - bufferLocal = (char*)mallocAndZero(buffer[j].size); + char *bufferLocal; + bufferLocal = (char *)mallocAndZero(buffer[j].size); - fread(bufferLocal,buffer[j].size,1,fileHandle); + fread(bufferLocal, buffer[j].size, 1, fileHandle); char nameBuffer[256]; - sprintf(nameBuffer,"D%d.dmp/%s",i+1,buffer[j].name); + sprintf(nameBuffer, "D%d.dmp/%s", i + 1, + buffer[j].name); - if(buffer[j].size == buffer[j].unk2) - { - FILE* fOut = fopen(nameBuffer,"wb+"); - fwrite(bufferLocal,buffer[j].size,1,fOut); + if (buffer[j].size == buffer[j].unk2) { + FILE *fOut = fopen(nameBuffer, "wb+"); + fwrite(bufferLocal, buffer[j].size, 1, fOut); fclose(fOut); - } - else - { - char* uncompBuffer = (char*)mallocAndZero(buffer[j].unk2+500); - - decomp((uint8*)bufferLocal+buffer[j].size-4,(uint8*)uncompBuffer+buffer[j].unk2+500,buffer[j].unk2); - - FILE* fOut = fopen(nameBuffer,"wb+"); - fwrite(uncompBuffer+500,buffer[j].unk2,1,fOut); + } else { + char *uncompBuffer = + (char *)mallocAndZero(buffer[j].unk2 + + 500); + + decomp((uint8 *) bufferLocal + buffer[j].size - + 4, + (uint8 *) uncompBuffer + buffer[j].unk2 + + 500, buffer[j].unk2); + + FILE *fOut = fopen(nameBuffer, "wb+"); + fwrite(uncompBuffer + 500, buffer[j].unk2, 1, + fOut); fclose(fOut); //free(uncompBuffer); @@ -505,13 +459,12 @@ int16 readVolCnf(void) #endif - return(1); + return (1); } ///////////////////////////:: -void drawMsgString(uint8* string) -{ +void drawMsgString(uint8 *string) { //printf("%s\n",string); } diff --git a/engines/cruise/volume.h b/engines/cruise/volume.h index 4e057a4773..c5e536fda6 100644 --- a/engines/cruise/volume.h +++ b/engines/cruise/volume.h @@ -22,23 +22,23 @@ * */ -#ifndef _VOLUME_H_ -#define _VOLUME_H_ +#ifndef CRUISE_VOLUME_H +#define CRUISE_VOLUME_H namespace Cruise { int16 readVolCnf(void); -int16 findFileInDisks(uint8* fileName); -int16 fileExist(uint8* fileName); +int16 findFileInDisks(uint8 * fileName); +int16 fileExist(uint8 * fileName); void freeDisk(void); -int16 findFileInList(uint8* fileName); +int16 findFileInList(uint8 * fileName); //////////////// -void strToUpper(uint8* fileName); -void drawMsgString(uint8* string); +void strToUpper(uint8 * fileName); +void drawMsgString(uint8 * string); void askDisk(int16 discNumber); -void setObjectPosition(int16 param1,int16 param2,int16 param3,int16 param4); +void setObjectPosition(int16 param1, int16 param2, int16 param3, int16 param4); } // End of namespace Cruise |