From 70840d8bc35584e91aabe94d0759dd93594a91f0 Mon Sep 17 00:00:00 2001 From: Paul Date: Tue, 12 Dec 2000 20:55:10 +0000 Subject: [PATCH] --- source/script/script.cpp | 374 +++++++++++++++++++++++++++++++++++++++ source/script/script.h | 135 ++++++++++++++ 2 files changed, 509 insertions(+) create mode 100644 source/script/script.cpp create mode 100644 source/script/script.h diff --git a/source/script/script.cpp b/source/script/script.cpp new file mode 100644 index 000000000..683caddbe --- /dev/null +++ b/source/script/script.cpp @@ -0,0 +1,374 @@ +/*========================================================================= + + script.cpp + + Author: PKG + Created: + Project: Spongebob + Purpose: + + Copyright (c) 2000 Climax Development Ltd + +===========================================================================*/ + + +/*---------------------------------------------------------------------- + Includes + -------- */ + +#include "paul\script.h" + +#ifndef __SYSTEM_DBG_H__ +#include "system\dbg.h" +#endif + +#ifndef __MEMORY_HEADER__ +#include "mem\memory.h" +#endif + + +/* Std Lib + ------- */ + +/* Data + ---- */ + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ + +//#define FULL_CODE_OUTPUT +//#define SHOW_RUN_COUNT + + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ + +/*---------------------------------------------------------------------- + Function Prototypes + ------------------- */ + +/*---------------------------------------------------------------------- + Vars + ---- */ + +signed short CScript::s_globalVars[NUM_GLOBAL_VARS]= +{ + 0, // LIVES +}; + + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +void CScript::initialise(FileEquate _fe) +{ + m_code=(unsigned short*)CFileIO::loadFile(_fe); + m_stack=(unsigned short*)MemAlloc(sizeof(unsigned short)*STACK_SIZE,"ScriptStack"); + reset(); +} + + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +void CScript::run() +{ +#ifdef SHOW_RUN_COUNT + int run=0; +#endif + if(m_state<=RUNNING) + { + m_state=RUNNING; + do + { + executeNextInstruction(); +#ifdef SHOW_RUN_COUNT + run++; +#endif + } + while(m_state==RUNNING); + } +#ifdef SHOW_RUN_COUNT + if(run) + { + PAUL_DBGMSG("ran %d instructions",run); + } +#endif +} + + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +int testval=2; +void CScript::reset() +{ + int i; + m_pc=0; + m_sp=0; + for(i=0;i=1); // Stack underflow about to occur :( + return(m_stack[--m_sp]); +} + + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +void CScript::setVar(int _varIdx,signed short _value) +{ + ASSERT(_varIdx>=0&&_varIdx<=NUM_GLOBAL_VARS+NUM_LOCAL_VARS-1); + + if(_varIdx=0&&_varIdx<=NUM_GLOBAL_VARS+NUM_LOCAL_VARS-1); + + int ret=0; + + if(_varIdx