[Scummvm-git-logs] scummvm master -> 832bae6a4806f3c172da64b3b181854c61c9a8a2
Strangerke
noreply at scummvm.org
Fri May 30 06:37:13 UTC 2025
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://api.github.com/repos/scummvm/scummvm .
Summary:
832bae6a48 M4: More cleanup in ws_cruncher and ws_hal
Commit: 832bae6a4806f3c172da64b3b181854c61c9a8a2
https://github.com/scummvm/scummvm/commit/832bae6a4806f3c172da64b3b181854c61c9a8a2
Author: Strangerke (arnaud.boutonne at gmail.com)
Date: 2025-05-30T07:37:07+01:00
Commit Message:
M4: More cleanup in ws_cruncher and ws_hal
Changed paths:
engines/m4/wscript/ws_cruncher.cpp
engines/m4/wscript/ws_hal.cpp
diff --git a/engines/m4/wscript/ws_cruncher.cpp b/engines/m4/wscript/ws_cruncher.cpp
index eb5d1ed5ef2..9442a3cc660 100644
--- a/engines/m4/wscript/ws_cruncher.cpp
+++ b/engines/m4/wscript/ws_cruncher.cpp
@@ -176,26 +176,26 @@ void ws_KillCruncher() {
}
Anim8 *ws_AddAnim8ToCruncher(machine *m, int32 sequHash) {
- Anim8 *myAnim8;
- frac16 *my_regs;
- int32 numLocalVars;
-
// Make sure the cruncher has been initialized
VERIFY_INTIALIZED("ws_AddAnim8ToCruncher()");
// Allocate an anim8 structure
- if ((myAnim8 = (Anim8 *)mem_alloc(sizeof(Anim8), "Anim8")) == nullptr) {
+ Anim8 *myAnim8 = (Anim8 *)mem_alloc(sizeof(Anim8), "Anim8");
+ if (myAnim8 == nullptr) {
ws_LogErrorMsg(FL, "Out of memory - mem requested: %d.", sizeof(Anim8));
return nullptr;
}
// Find the sequence
- if ((myAnim8->sequHandle = ws_GetSEQU((uint32)sequHash, &numLocalVars, &myAnim8->pcOffset)) == nullptr) {
+ int32 numLocalVars;
+ myAnim8->sequHandle = ws_GetSEQU((uint32)sequHash, &numLocalVars, &myAnim8->pcOffset);
+ if (myAnim8->sequHandle == nullptr) {
return nullptr;
}
// Allocate an array of registers
- if ((my_regs = (frac16 *)mem_alloc(sizeof(frac16) * (IDX_COUNT + numLocalVars), "Anim8 regs")) == nullptr) {
+ frac16 *my_regs = (frac16 *)mem_alloc(sizeof(frac16) * (IDX_COUNT + numLocalVars), "Anim8 regs");
+ if (my_regs == nullptr) {
ws_LogErrorMsg(FL, "Out of memory - mem requested: %d.", sizeof(frac16) * (IDX_COUNT + numLocalVars));
return nullptr;
}
@@ -249,8 +249,6 @@ Anim8 *ws_AddAnim8ToCruncher(machine *m, int32 sequHash) {
}
bool ws_ChangeAnim8Program(machine *m, int32 newSequHash) {
- int32 numLocalVars;
-
// Make sure the cruncher has been initialized
VERIFY_INTIALIZED("ws_ChangeAnim8Program()");
@@ -262,7 +260,9 @@ bool ws_ChangeAnim8Program(machine *m, int32 newSequHash) {
Anim8 *myAnim8 = m->myAnim8;
// Find the sequence
- if ((myAnim8->sequHandle = ws_GetSEQU((uint32)newSequHash, &numLocalVars, &myAnim8->pcOffset)) == nullptr) {
+ int32 numLocalVars;
+ myAnim8->sequHandle = ws_GetSEQU((uint32)newSequHash, &numLocalVars, &myAnim8->pcOffset);
+ if (myAnim8->sequHandle == nullptr) {
return false;
}
@@ -971,13 +971,12 @@ static void op_SEQ_SEND_MSG(Anim8 *myAnim8) {
static void op_PUSH(Anim8 *myAnim8) {
- uint32 *data;
- int32 direction, numOfArgs, i; //,startReg
+ int32 numOfArgs;
if (!_GWS(myArg1)) {
ws_Error(myAnim8->myMachine, ERR_SEQU, 0x0250, "functionality: push arg1 or start with arg1, and push a total of arg2 values");
}
- direction = 1;
+ int32 direction = 1;
if (_GWS(myArg2)) {
if (*_GWS(myArg2) > 0) numOfArgs = (*_GWS(myArg2)) >> 16;
else {
@@ -993,8 +992,8 @@ static void op_PUSH(Anim8 *myAnim8) {
return;
}
if (_GWS(myArg2)) {
- data = (uint32 *)_GWS(myArg1);
- for (i = 0; i < numOfArgs; i++) {
+ uint32 *data = (uint32 *)_GWS(myArg1);
+ for (int32 i = 0; i < numOfArgs; i++) {
*_GWS(stackTop)++ = *data;
data += direction;
}
@@ -1004,26 +1003,26 @@ static void op_PUSH(Anim8 *myAnim8) {
}
static void op_POP(Anim8 *myAnim8) {
- uint32 *data;
- int32 direction, numOfArgs, i; // startReg,
+ int32 numOfArgs;
if (!_GWS(myArg1)) {
ws_Error(myAnim8->myMachine, ERR_SEQU, 0x0250, "functionality: pop into arg1 or start with arg1, and pop a total of arg2 values");
}
- direction = 1;
+ int32 direction = 1;
if (_GWS(myArg2)) {
if (*_GWS(myArg2) > 0) numOfArgs = (*_GWS(myArg2)) >> 16;
else {
numOfArgs = -(int)(*_GWS(myArg2)) >> 16;
direction = -1;
}
- } else numOfArgs = 1;
+ } else
+ numOfArgs = 1;
if (((byte *)_GWS(stackTop) - (byte *)_GWS(stackBase)) < (numOfArgs << 2)) {
ws_Error(myAnim8->myMachine, ERR_SEQU, 0x0255, "underflow during pop instruction");
}
if (_GWS(myArg2)) {
- data = (uint32 *)_GWS(myArg1);
- for (i = 0; i < numOfArgs; i++) {
+ uint32 *data = (uint32 *)_GWS(myArg1);
+ for (int32 i = 0; i < numOfArgs; i++) {
*data = *(--_GWS(stackTop));
data += direction;
}
@@ -1033,8 +1032,6 @@ static void op_POP(Anim8 *myAnim8) {
}
static void op_JSR(Anim8 *myAnim8) {
- int32 dummy;
-
if (myAnim8->returnStackIndex >= JSR_STACK_MAX) {
ws_LogErrorMsg(FL, "Max number of nested jsr instructions is: %d", JSR_STACK_MAX);
ws_Error(myAnim8->myMachine, ERR_SEQU, 0x0256, "jsr() failed");
@@ -1044,7 +1041,9 @@ static void op_JSR(Anim8 *myAnim8) {
myAnim8->returnStackIndex++;
// Find the sequence
- if ((myAnim8->sequHandle = ws_GetSEQU((uint32)*_GWS(myArg1) >> 16, &dummy, &myAnim8->pcOffset)) == nullptr) {
+ int32 dummy;
+ myAnim8->sequHandle = ws_GetSEQU((uint32)*_GWS(myArg1) >> 16, &dummy, &myAnim8->pcOffset);
+ if (myAnim8->sequHandle == nullptr) {
ws_Error(myAnim8->myMachine, ERR_SEQU, 0x025f, "jsr() failed");
}
myAnim8->sequHash = (uint32)*_GWS(myArg1) >> 16;
@@ -1053,20 +1052,19 @@ static void op_JSR(Anim8 *myAnim8) {
}
static void op_RETURN(Anim8 *myAnim8) {
- int32 dummy, dummy2;
- uint32 returnSequHash, returnOffset;
-
if (myAnim8->returnStackIndex <= 0) {
op_END(myAnim8);
return;
}
myAnim8->returnStackIndex--;
- returnSequHash = myAnim8->returnHashes[myAnim8->returnStackIndex];
- returnOffset = myAnim8->returnOffsets[myAnim8->returnStackIndex];
+ uint32 returnSequHash = myAnim8->returnHashes[myAnim8->returnStackIndex];
+ uint32 returnOffset = myAnim8->returnOffsets[myAnim8->returnStackIndex];
// Find the sequence
- if ((myAnim8->sequHandle = ws_GetSEQU((uint32)returnSequHash, &dummy, &dummy2)) == nullptr) {
+ int32 dummy, dummy2;
+ myAnim8->sequHandle = ws_GetSEQU((uint32)returnSequHash, &dummy, &dummy2);
+ if (myAnim8->sequHandle == nullptr) {
ws_Error(myAnim8->myMachine, ERR_SEQU, 0x025f, "return() failed");
}
myAnim8->sequHash = returnSequHash;
@@ -1105,13 +1103,12 @@ static void op_SET_INDEX(Anim8 *myAnim8) {
static void op_SET_LAYER(Anim8 *myAnim8) {
Anim8 *tempAnim8;
- int32 myLayer, newLayer;
if (!_GWS(myArg1)) {
ws_Error(myAnim8->myMachine, ERR_SEQU, 0x0250, "functionality: set_layer(arg1)");
}
- newLayer = *_GWS(myArg1) >> 16;
- myLayer = myAnim8->myLayer;
+ int32 newLayer = *_GWS(myArg1) >> 16;
+ int32 myLayer = myAnim8->myLayer;
if (myLayer == newLayer) {
return;
@@ -1503,7 +1500,6 @@ bool CrunchAnim8(Anim8 *myAnim8) {
}
void ws_CrunchAnim8s(int16 *depth_table) {
- EOSreq *tempEOSreq;
// Make sure the cruncher has been initialized
VERIFY_INTIALIZED("ws_CrunchAnim8s()");
@@ -1523,7 +1519,9 @@ void ws_CrunchAnim8s(int16 *depth_table) {
if (currAnim8->eosReqOffset >= 0) {
// If the above field has a value, this implies that an On end sequence
//signal has been requested. If so, report back to the machine.
- if ((tempEOSreq = (EOSreq *)mem_get_from_stash(_GWS(memtypeEOS), "+EOS")) == nullptr) return;
+ EOSreq *tempEOSreq = (EOSreq *)mem_get_from_stash(_GWS(memtypeEOS), "+EOS");
+ if (tempEOSreq == nullptr)
+ return;
tempEOSreq->myAnim8 = currAnim8;
tempEOSreq->prev = nullptr;
tempEOSreq->next = _GWS(EOSreqList);
diff --git a/engines/m4/wscript/ws_hal.cpp b/engines/m4/wscript/ws_hal.cpp
index 4c59d169866..3c7ada16271 100644
--- a/engines/m4/wscript/ws_hal.cpp
+++ b/engines/m4/wscript/ws_hal.cpp
@@ -44,11 +44,8 @@ void ws_KillHAL() {
}
void ws_DumpMachine(machine *m, Common::WriteStream *logFile) {
- Anim8 *myAnim8;
- CCB *myCCB;
- frac16 *myRegs;
int32 i;
- double tempFloat;
+ double tempFloat;
if (!m || !logFile)
return;
@@ -58,14 +55,14 @@ void ws_DumpMachine(machine *m, Common::WriteStream *logFile) {
// If we have an anim8 for this machine
if (m->myAnim8) {
- myAnim8 = m->myAnim8;
+ Anim8 *myAnim8 = m->myAnim8;
// Print out the anim8 hash, and physical address
logFile->writeString(Common::String::format("Sequence Hash: %d\n\tAddress: %p\n\n", myAnim8->sequHash, (void *)myAnim8));
// And if this anim8 has registers
if (myAnim8->myRegs) {
- myRegs = myAnim8->myRegs;
+ frac16 *myRegs = myAnim8->myRegs;
logFile->writeString("Registers:\n");
// Loop through the main set of registers, and dump out the contents
@@ -86,7 +83,7 @@ void ws_DumpMachine(machine *m, Common::WriteStream *logFile) {
// If this anim8 has a CCB
if (myAnim8->myCCB) {
- myCCB = myAnim8->myCCB;
+ CCB *myCCB = myAnim8->myCCB;
logFile->writeString(Common::String::format("Sprite Series Name: %s\tAddress:%p\tFlags0x%08x\n", myCCB->seriesName, (void *)myCCB, myCCB->flags));
logFile->writeString(Common::String::format("\tCurrent Location: (%d, %d), (%d, %d)\n", myCCB->currLocation->x1, myCCB->currLocation->y1,
@@ -100,14 +97,13 @@ void ws_DumpMachine(machine *m, Common::WriteStream *logFile) {
}
void ws_Error(machine *m, int32 errorType, trigraph errorCode, const char *errMsg) {
- Common::OutSaveFile *logFile;
char description[MAX_STRING_SIZE];
// Find the error description
error_look_up(errorCode, description);
// Open the logFile
- logFile = g_system->getSavefileManager()->openForSaving("ws_mach.log");
+ Common::OutSaveFile *logFile = g_system->getSavefileManager()->openForSaving("ws_mach.log");
// Give the WS debugger a chance to indicate the error to the apps programmer
dbg_WSError(logFile, m, errorType, description, errMsg, _GWS(pcOffsetOld));
@@ -142,10 +138,9 @@ machine *kernel_timer_callback(int32 ticks, int16 trigger, MessageCB callMe) {
static void drawSprite(CCB *myCCB, Anim8 *myAnim8, Buffer *halScrnBuf, Buffer *screenCodeBuff,
uint8 *myPalette, uint8 *ICT) {
- M4sprite *source;
// Temporary var to prevent excessive dereferences
- source = myCCB->source;
+ M4sprite *source = myCCB->source;
if (!(myCCB->flags & CCB_DISC_STREAM)) {
// Make sure the sprite is still in memory
@@ -194,12 +189,11 @@ void ws_DoDisplay(Buffer *background, int16 *depth_table, Buffer *screenCodeBuff
CCB *myCCB;
ScreenContext *myScreen;
RectList *myRect;
- RectList *drawRectList = nullptr;
- int32 status, scrnX1, scrnY1;
+ RectList *drawRectList;
+ int32 status;
int32 restoreBgndX1, restoreBgndY1, restoreBgndX2, restoreBgndY2;
- Anim8 *myAnim8;
- M4Rect *currRect, *newRect;
- bool greyMode, breakFlag;
+ M4Rect *currRect;
+ bool breakFlag;
if (((myScreen = vmng_screen_find(_G(gameDrawBuff), &status)) == nullptr) || (status != SCRN_ACTIVE)) {
return;
@@ -207,23 +201,23 @@ void ws_DoDisplay(Buffer *background, int16 *depth_table, Buffer *screenCodeBuff
Buffer *halScrnBuf = _G(gameDrawBuff)->get_buffer();
- scrnX1 = myScreen->x1;
- scrnY1 = myScreen->y1;
+ int32 scrnX1 = myScreen->x1;
+ int32 scrnY1 = myScreen->y1;
- greyMode = krn_GetGreyMode();
+ bool greyMode = krn_GetGreyMode();
- // Intialize the drawRectList to the deadRectList
+ // Initialize the drawRectList to the deadRectList
drawRectList = _GWS(deadRectList);
_GWS(deadRectList) = nullptr;
// Now we loop back to front and set up a list of drawing areas
- myAnim8 = _GWS(myCruncher)->backLayerAnim8;
+ Anim8 *myAnim8 = _GWS(myCruncher)->backLayerAnim8;
while (myAnim8) {
myCCB = myAnim8->myCCB;
if (myCCB && myCCB->source && (!(myCCB->flags & CCB_NO_DRAW)) && (myCCB->flags & CCB_REDRAW)) {
currRect = myCCB->currLocation;
- newRect = myCCB->newLocation;
+ M4Rect *newRect = myCCB->newLocation;
if (!(myCCB->flags & CCB_STREAM) && (!greyMode || !(myCCB->source->encoding & 0x80))) {
vmng_AddRectToRectList(&drawRectList, currRect->x1, currRect->y1,
@@ -367,8 +361,6 @@ void ws_DoDisplay(Buffer *background, int16 *depth_table, Buffer *screenCodeBuff
void ws_hal_RefreshWoodscriptBuffer(cruncher *myCruncher, Buffer *background,
int16 *depth_table, Buffer *screenCodes, uint8 *myPalette, uint8 *ICT) {
- Anim8 *myAnim8;
- CCB *myCCB;
uint8 myDepth;
Buffer drawSpriteBuff;
DrawRequest spriteDrawReq;
@@ -383,10 +375,10 @@ void ws_hal_RefreshWoodscriptBuffer(cruncher *myCruncher, Buffer *background,
gr_buffer_rect_copy(background, halScrnBuf, 0, 0, halScrnBuf->w, halScrnBuf->h);
// Now draw all the sprites that are not hidden
- myAnim8 = myCruncher->backLayerAnim8;
+ Anim8 *myAnim8 = myCruncher->backLayerAnim8;
while (myAnim8) {
- myCCB = myAnim8->myCCB;
+ CCB *myCCB = myAnim8->myCCB;
if (myCCB && (myCCB->source != nullptr) && (!(myCCB->flags & CCB_SKIP)) && (!(myCCB->flags & CCB_HIDE))) {
if (!(myCCB->flags & CCB_DISC_STREAM)) {
// Make sure the series is still in memory
@@ -445,22 +437,19 @@ void ws_hal_RefreshWoodscriptBuffer(cruncher *myCruncher, Buffer *background,
}
void GetBezCoeffs(frac16 *ctrlPoints, frac16 *coeffs) {
- frac16 x0, x0mult3, x1mult3, x1mult6, x2mult3, x3;
- frac16 y0, y0mult3, y1mult3, y1mult6, y2mult3, y3;
-
- x0 = ctrlPoints[0];
- x0mult3 = (x0 << 1) + x0;
- x1mult3 = (ctrlPoints[2] << 1) + ctrlPoints[2];
- x1mult6 = x1mult3 << 1;
- x2mult3 = (ctrlPoints[4] << 1) + ctrlPoints[4];
- x3 = ctrlPoints[6];
-
- y0 = ctrlPoints[1];
- y0mult3 = (y0 << 1) + y0;
- y1mult3 = (ctrlPoints[3] << 1) + ctrlPoints[3];
- y1mult6 = y1mult3 << 1;
- y2mult3 = (ctrlPoints[5] << 1) + ctrlPoints[5];
- y3 = ctrlPoints[7];
+ frac16 x0 = ctrlPoints[0];
+ frac16 x0mult3 = (x0 << 1) + x0;
+ frac16 x1mult3 = (ctrlPoints[2] << 1) + ctrlPoints[2];
+ frac16 x1mult6 = x1mult3 << 1;
+ frac16 x2mult3 = (ctrlPoints[4] << 1) + ctrlPoints[4];
+ frac16 x3 = ctrlPoints[6];
+
+ frac16 y0 = ctrlPoints[1];
+ frac16 y0mult3 = (y0 << 1) + y0;
+ frac16 y1mult3 = (ctrlPoints[3] << 1) + ctrlPoints[3];
+ frac16 y1mult6 = y1mult3 << 1;
+ frac16 y2mult3 = (ctrlPoints[5] << 1) + ctrlPoints[5];
+ frac16 y3 = ctrlPoints[7];
coeffs[0] = -(int)x0 + x1mult3 - x2mult3 + x3;
coeffs[2] = x0mult3 - x1mult6 + x2mult3;
@@ -486,8 +475,6 @@ void GetBezPoint(frac16 *x, frac16 *y, frac16 *coeffs, frac16 tVal) {
MulSF16(tVal, (coeffs[5] +
MulSF16(tVal, (coeffs[3] +
MulSF16(tVal, coeffs[1])))));
-
- return;
}
bool InitCCB(CCB *myCCB) {
@@ -606,15 +593,11 @@ void KillCCB(CCB *myCCB, bool restoreFlag) {
}
void Cel_msr(Anim8 *myAnim8) {
- CCB *myCCB;
- frac16 *myRegs;
- int32 scaler;
-
if (!myAnim8) {
error_show(FL, 'WSAI');
}
- myCCB = myAnim8->myCCB;
+ CCB *myCCB = myAnim8->myCCB;
if ((!myCCB) || (!myCCB->source)) {
error_show(FL, 'WSIC');
}
@@ -623,12 +606,12 @@ void Cel_msr(Anim8 *myAnim8) {
return;
}
- myRegs = myAnim8->myRegs;
+ frac16 *myRegs = myAnim8->myRegs;
if (!myRegs) {
error_show(FL, 'WSAI');
}
- scaler = FixedMul(myRegs[IDX_S], 100 << 16) >> 16;
+ int32 scaler = FixedMul(myRegs[IDX_S], 100 << 16) >> 16;
myCCB->scaleX = myRegs[IDX_W] < 0 ? -scaler : scaler;
myCCB->scaleY = scaler;
More information about the Scummvm-git-logs
mailing list