SBSPSS/source/script/script.h

141 lines
2.7 KiB
C
Raw Normal View History

2000-12-12 21:55:10 +01:00
/*=========================================================================
script.h
Author: PKG
Created:
Project: Spongebob
Purpose:
Copyright (c) 2000 Climax Development Ltd
===========================================================================*/
2000-12-12 22:33:19 +01:00
#ifndef __SCRIPT_SCRIPT_H__
#define __SCRIPT_SCRIPT_H__
2000-12-12 21:55:10 +01:00
/*----------------------------------------------------------------------
Includes
-------- */
#ifndef _FILEIO_HEADER_
#include "fileio\fileio.h"
#endif
/* Std Lib
------- */
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
class CScript
{
public:
void initialise(FileEquate _fe);
void reset();
void run();
int isFinished();
private:
// Global vars
enum
{
LIVES,
NUM_GLOBAL_VARS,
};
// Local vars
enum
{
TMP1,
TMP2,
TMP3,
NUM_LOCAL_VARS,
};
typedef enum
{
RESET,
PAUSED,
RUNNING,
STOPPED,
STOPPED_STACK_NOT_EMPTY,
CRASHED_ILLEGAL_OPCODE,
}ScriptState;
enum
{
2000-12-15 21:29:33 +01:00
STACK_SIZE=10,
MAX_FUNCTION_ARGS=5,
2000-12-12 21:55:10 +01:00
};
enum
{
2000-12-15 21:29:33 +01:00
// args stack data result
2000-12-12 21:55:10 +01:00
OP_NOP=0x1100, //
OP_STOP, //
OP_PAUSE,
OP_PUSHVALUE, // value
OP_PUSHVARVALUE, // varidx
2000-12-15 21:29:33 +01:00
OP_POP, // value
OP_JMP, // jump
OP_JMPF, // jump, value
OP_JMPT, // jump, value
OP_IS_EQUAL_VALUE, // value, value pushes result ( 0 or 1 ) to stack
OP_IS_NOTEQUAL_VALUE, // value, value pushes result ( 0 or 1 ) to stack
OP_ASSIGN, // varidx, value
OP_ADD, // value, value pushes result to stack
OP_PRINT, // value
OP_CALL_FUNCTION, // functionnumber, argcount args pushes return value to stack
2000-12-12 21:55:10 +01:00
};
void executeNextInstruction();
unsigned short readNextInstruction();
void jump(signed short _distance);
void push(unsigned short _data);
unsigned short pop();
void setVar(int _varIdx,signed short _value);
signed short getVar(int _varIdx);
unsigned short *m_code;
int m_pc;
unsigned short *m_stack;
int m_sp;
static signed short s_globalVars[NUM_GLOBAL_VARS];
signed short m_localVars[NUM_LOCAL_VARS];
2000-12-15 21:29:33 +01:00
static unsigned short s_argBuffer[MAX_FUNCTION_ARGS];
2000-12-12 21:55:10 +01:00
ScriptState m_state;
};
/*----------------------------------------------------------------------
Globals
------- */
/*----------------------------------------------------------------------
Functions
--------- */
/*---------------------------------------------------------------------- */
2000-12-12 22:33:19 +01:00
#endif /* __SCRIPT_SCRIPT_H__ */
2000-12-12 21:55:10 +01:00
/*===========================================================================
end */