diff options
Diffstat (limited to 'engines/macventure/script.h')
-rw-r--r-- | engines/macventure/script.h | 188 |
1 files changed, 181 insertions, 7 deletions
diff --git a/engines/macventure/script.h b/engines/macventure/script.h index d66a867eca..e56c6e7440 100644 --- a/engines/macventure/script.h +++ b/engines/macventure/script.h @@ -51,6 +51,7 @@ enum ControlAction { }; typedef uint32 ObjID; +typedef int16 word; class ScriptAsset { public: @@ -58,7 +59,9 @@ public: ~ScriptAsset() {} void reset(); - uint8 fecth(); + uint8 fetch(); + bool hasNext(); + void branch(word amount); private: @@ -72,13 +75,61 @@ private: uint32 _ip; // Instruction pointer }; -struct EngineState { - uint8 stack[0x80]; - uint8 sp; - +class EngineState { +public: EngineState() { + clear(); + } + + void push(word data) { + stack[sp] = unneg16(data); + sp--; + } + + word pop() { + byte v = stack[sp]; + sp++; + return v; + } + + word peek(word off) { + return stack[sp + off]; + } + + void poke(word off, word val) { + stack[sp + off] = unneg16(val); + } + + void clear() { sp = 0x80; } + + word size() { + return 0x80 - sp; + } + +private: + word unneg16(word data) { + if (data < 0) + data = ((-data) ^ 0xFFFF) + 1; + + return data; + } + +private: + + word stack[0x80]; + word sp; +}; + +struct FunCall { + word func; + word rank; + + FunCall(word f, word r) { + func = f; + rank = r; + } }; struct EngineFrame { @@ -89,6 +140,7 @@ struct EngineFrame { int y; EngineState state; Common::Array<ScriptAsset> scripts; + Common::Array<FunCall> saves; uint32 familyIdx; bool haltedInFirst; @@ -98,7 +150,7 @@ struct EngineFrame { class ScriptEngine { public: - ScriptEngine(World *world); + ScriptEngine(MacVentureEngine *engine, World *world); ~ScriptEngine(); public: @@ -110,9 +162,131 @@ private: bool execFrame(bool execAll); bool loadScript(EngineFrame * frame, uint32 scriptID); bool resumeFunc(EngineFrame * frame); - bool runFunc(); + bool runFunc(EngineFrame * frame); + +private: + + // Aux + word neg16(word val); + word neg8(word val); + word sumChildrenAttr(word obj, word attr, bool recursive); + + // Opcodes + void op80GATT(EngineState *state, EngineFrame *frame); //get attribute + void op81SATT(EngineState *state, EngineFrame *frame); //set attribute + void op82SUCH(EngineState *state, EngineFrame *frame); //sum children attribute + void op83PUCT(EngineState *state, EngineFrame *frame); //push selected control + void op84PUOB(EngineState *state, EngineFrame *frame); //push selected object + void op85PUTA(EngineState *state, EngineFrame *frame); //push target + void op86PUDX(EngineState *state, EngineFrame *frame); //push deltax + void op87PUDY(EngineState *state, EngineFrame *frame); //push deltay + void op88PUIB(EngineState *state, EngineFrame *frame, ScriptAsset *asset);//push immediate.b + void op89PUI(EngineState *state, EngineFrame *frame, ScriptAsset *asset);//push immediate + void op8aGGLO(EngineState *state, EngineFrame *frame); //get global + void op8bSGLO(EngineState *state, EngineFrame *frame); //set global + void op8cRAND(EngineState *state, EngineFrame *frame); //random + void op8dCOPY(EngineState *state, EngineFrame *frame); //copy + void op8eCOPYN(EngineState *state, EngineFrame *frame); //copyn + void op8fSWAP(EngineState *state, EngineFrame *frame); //swap + + void op90SWAPN(EngineState *state, EngineFrame *frame); //swapn + void op91POP(EngineState *state, EngineFrame *frame); //pop + void op92COPYP(EngineState *state, EngineFrame *frame); //copy+1 + void op93COPYPN(EngineState *state, EngineFrame *frame);//copy+n + void op94SHUFF(EngineState *state, EngineFrame *frame); //shuffle + void op95SORT(EngineState *state, EngineFrame *frame); //sort + void op96CLEAR(EngineState *state, EngineFrame *frame); //clear stack + void op97SIZE(EngineState *state, EngineFrame *frame); //get stack size + void op98ADD(EngineState *state, EngineFrame *frame); //add + void op99SUB(EngineState *state, EngineFrame *frame); //subtract + void op9aMUL(EngineState *state, EngineFrame *frame); //multiply + void op9bDIV(EngineState *state, EngineFrame *frame); //divide + void op9cMOD(EngineState *state, EngineFrame *frame); //mod + void op9dDMOD(EngineState *state, EngineFrame *frame); //divmod + void op9eABS(EngineState *state, EngineFrame *frame); //abs + void op9fNEG(EngineState *state, EngineFrame *frame); //neg + + void opa0AND(EngineState *state, EngineFrame *frame); //and + void opa1OR(EngineState *state, EngineFrame *frame); //or + void opa2XOR(EngineState *state, EngineFrame *frame); //xor + void opa3NOT(EngineState *state, EngineFrame *frame); //not + void opa4LAND(EngineState *state, EngineFrame *frame); //logical and + void opa5LOR(EngineState *state, EngineFrame *frame); //logical or + void opa6LXOR(EngineState *state, EngineFrame *frame); //logical xor + void opa7LNOT(EngineState *state, EngineFrame *frame); //logical not + void opa8GTU(EngineState *state, EngineFrame *frame); //gt? unsigned + void opa9LTU(EngineState *state, EngineFrame *frame); //lt? unsigned + void opaaGTS(EngineState *state, EngineFrame *frame); //gt? signed + void opabLTS(EngineState *state, EngineFrame *frame); //lt? signed + void opacEQ(EngineState *state, EngineFrame *frame); //eq? + void opadEQS(EngineState *state, EngineFrame *frame); //eq string? + void opaeCONT(EngineState *state, EngineFrame *frame); //contains + void opafCONTW(EngineState *state, EngineFrame *frame); //contains word + + void opb0BRA(EngineState *state, EngineFrame *frame, ScriptAsset *asset); //bra + void opb1BRAB(EngineState *state, EngineFrame *frame, ScriptAsset *asset); //bra.b + void opb2BEQ(EngineState *state, EngineFrame *frame, ScriptAsset *asset); //beq + void opb3BEQB(EngineState *state, EngineFrame *frame, ScriptAsset *asset); //beq.b + void opb4BNE(EngineState *state, EngineFrame *frame, ScriptAsset *asset); //bne + void opb5BNEB(EngineState *state, EngineFrame *frame, ScriptAsset *asset); //bne.b + void opb6CLAT(EngineState *state, EngineFrame *frame); //call later + void opb7CCA(EngineState *state, EngineFrame *frame); //cancel call + void opb8CLOW(EngineState *state, EngineFrame *frame); //cancel low priority + void opb9CHI(EngineState *state, EngineFrame *frame); //cancel high priority + void opbaCRAN(EngineState *state, EngineFrame *frame); //cancel priority range + void opbbFORK(EngineState *state, EngineFrame *frame); //fork + void opbcCALL(EngineState *state, EngineFrame *frame, ScriptAsset *script); //call + void opbdFOOB(EngineState *state, EngineFrame *frame); //focus object + void opbeSWOB(EngineState *state, EngineFrame *frame); //swap objects + void opbfSNOB(EngineState *state, EngineFrame *frame); //snap object + + void opc0TEXI(EngineState *state, EngineFrame *frame); //toggle exits + void opc1PTXT(EngineState *state, EngineFrame *frame); //print text + void opc2PNEW(EngineState *state, EngineFrame *frame); //print newline + void opc3PTNE(EngineState *state, EngineFrame *frame); //print text+nl + void opc4PNTN(EngineState *state, EngineFrame *frame); //print nl+text+nl + void opc5PNUM(EngineState *state, EngineFrame *frame); //print number + void opc6P2(EngineState *state, EngineFrame *frame); //push 2 + void opc7PLBG(EngineState *state, EngineFrame *frame); //play sound in background + void opc8PLAW(EngineState *state, EngineFrame *frame); //play sound and wait + void opc9WAIT(EngineState *state, EngineFrame *frame); //wait for sound to finish? + void opcaTIME(EngineState *state, EngineFrame *frame); //get current time + void opcbDAY(EngineState *state, EngineFrame *frame); //get current day + void opccCHLD(EngineState *state, EngineFrame *frame); //get children + void opcdNCHLD(EngineState *state, EngineFrame *frame); //get num children + void opceVERS(EngineState *state, EngineFrame *frame); //get engine version + void opcfPSCE(EngineState *state, EngineFrame *frame); //push scenario number + + void opd0P1(EngineState *state, EngineFrame *frame); //push 1 + void opd1GOBD(EngineState *state, EngineFrame *frame); //get object dimensions + void opd2GOVP(EngineState *state, EngineFrame *frame); //get overlap percent + void opd3CAPC(EngineState *state, EngineFrame *frame); //capture children + void opd4RELC(EngineState *state, EngineFrame *frame); //release children + void opd5DLOG(EngineState *state, EngineFrame *frame); //show speech dialog + void opd6ACMD(EngineState *state, EngineFrame *frame); //activate command + void opd7LOSE(EngineState *state, EngineFrame *frame); //lose game + void opd8WIN(EngineState *state, EngineFrame *frame); //win game + void opd9SLEEP(EngineState *state, EngineFrame *frame); //sleep + void opdaCLICK(EngineState *state, EngineFrame *frame); //click to continue + void opdbROBQ(EngineState *state, EngineFrame *frame); //run queue + void opdcRSQ(EngineState *state, EngineFrame *frame); //run sound queue + void opddRTQ(EngineState *state, EngineFrame *frame); //run text queue + void opdeUPSC(EngineState *state, EngineFrame *frame); //update screen + void opdfFMAI(EngineState *state, EngineFrame *frame); //flash main window + + void ope0CHGR(EngineState *state, EngineFrame *frame); //cache graphic and object + void ope1CHSO(EngineState *state, EngineFrame *frame); //cache sound + void ope2MDIV(EngineState *state, EngineFrame *frame); //muldiv + void ope3UPOB(EngineState *state, EngineFrame *frame); //update object + void ope4PLEV(EngineState *state, EngineFrame *frame); //currently playing event? + void ope5WEV(EngineState *state, EngineFrame *frame); //wait for event to finish + void ope6GFIB(EngineState *state, EngineFrame *frame); //get fibonacci (joke) + void ope7CFIB(EngineState *state, EngineFrame *frame); //calc fibonacci + + void op00NOOP(byte op); private: + MacVentureEngine *_engine; World *_world; Common::Array<EngineFrame> _frames; Container *_scripts; |