SBSPSS/source/script/script.h

155 lines
3.1 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);
2001-01-23 22:05:48 +01:00
void dump();
2000-12-12 21:55:10 +01:00
void reset();
void run();
int isFinished();
private:
// Global vars
enum
{
LIVES,
NUM_GLOBAL_VARS,
};
// Local vars
enum
{
2000-12-20 21:15:24 +01:00
TMP0,
2000-12-12 21:55:10 +01:00
TMP1,
TMP2,
TMP3,
2000-12-20 21:15:24 +01:00
TMP4,
TMP5,
TMP6,
TMP7,
TMP8,
TMP9,
2000-12-12 21:55:10 +01:00
NUM_LOCAL_VARS,
};
typedef enum
{
RESET,
PAUSED,
RUNNING,
STOPPED,
STOPPED_STACK_NOT_EMPTY,
CRASHED_ILLEGAL_OPCODE,
2000-12-22 18:10:46 +01:00
CRASHED_DIVIDE_BY_ZERO,
2000-12-12 21:55:10 +01:00
}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
2000-12-20 21:15:24 +01:00
OP_IS_LESSTHAN_VALUE, // value, value pushes result ( 0 or 1 ) to stack
OP_IS_GREATERTHAN_VALUE,// value, value pushes result ( 0 or 1 ) to stack
2000-12-15 21:29:33 +01:00
OP_ASSIGN, // varidx, value
OP_ADD, // value, value pushes result to stack
2000-12-22 18:10:46 +01:00
OP_MULTIPLY, // value, value pushes result to stack
OP_DIVIDE, // value, value pushes result to stack
2000-12-20 21:15:24 +01:00
OP_NEG, // value pushes result to stack
2000-12-15 21:29:33 +01:00
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 */