aboutsummaryrefslogtreecommitdiff
path: root/engines/tinsel/pcode.h
blob: 46ba2b10f3cabc91db2972ff580b868b054408dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * Virtual processor definitions
 */

#ifndef TINSEL_PCODE_H     // prevent multiple includes
#define TINSEL_PCODE_H

#include "tinsel/events.h"	// for TINSEL_EVENT
#include "tinsel/sched.h"	// for Common::PROCESS

namespace Common {
class Serializer;
}

namespace Tinsel {

// forward declaration
struct INV_OBJECT;

enum RESUME_STATE {
	RES_NOT, RES_1, RES_2, RES_SAVEGAME
};

enum {
	PCODE_STACK_SIZE	= 128	///< interpeters stack size
};

enum GSORT {
	GS_NONE, GS_ACTOR, GS_MASTER, GS_POLYGON, GS_INVENTORY, GS_SCENE,
	GS_PROCESS, GS_GPROCESS
};

enum RESCODE {RES_WAITING, RES_FINISHED, RES_CUTSHORT};

struct WorkaroundEntry;

struct INT_CONTEXT {

	// Elements for interpret context management
	Common::PROCESS *pProc;			///< processes owning this context
	GSORT	GSort;			///< sort of this context

	// Previously parameters to Interpret()
	SCNHANDLE	hCode;		///< scene handle of the code to execute
	byte		*code;		///< pointer to the code to execute
	TINSEL_EVENT	event;		///< causal event
	HPOLYGON	hPoly;		///< associated polygon (if any)
	int			idActor;	///< associated actor (if any)
	INV_OBJECT	*pinvo;		///< associated inventory object

	// Previously local variables in Interpret()
	int32 stack[PCODE_STACK_SIZE];	///< interpeters run time stack
	int sp;				///< stack pointer
	int bp;				///< base pointer
	int ip;				///< instruction pointer
	bool bHalt;			///< set to exit interpeter
	bool escOn;
	int myEscape;		///< only initialized to prevent compiler warning!

	uint32 waitNumber1;		// The waiting numbert
	uint32 waitNumber2;		// The wait for number
	RESCODE resumeCode;
	RESUME_STATE resumeState;

	// Used to store execution state within a script workaround fragment
	const WorkaroundEntry *fragmentPtr;

	void syncWithSerializer(Common::Serializer &s);
};
typedef INT_CONTEXT *PINT_CONTEXT;

/*----------------------------------------------------------------------*\
|*			Interpreter Function Prototypes			*|
\*----------------------------------------------------------------------*/

// Interprets the PCODE instructions in the code array
void Interpret(CORO_PARAM, INT_CONTEXT *ic);

INT_CONTEXT *InitInterpretContext(
	GSORT		gsort,
	SCNHANDLE	hCode,		// code to execute
	TINSEL_EVENT	event,		// causal event
	HPOLYGON	hpoly,		// associated polygon (if any)
	int		actorid,	// associated actor (if any)
	INV_OBJECT	*pinvo,
	int myEscape = -1);		// associated inventory object

INT_CONTEXT *RestoreInterpretContext(INT_CONTEXT *ric);

void FreeMostInterpretContexts();
void FreeMasterInterpretContext();

void SaveInterpretContexts(INT_CONTEXT *sICInfo);

void RegisterGlobals(int num);
void FreeGlobals();

void AttachInterpret(INT_CONTEXT *pic, Common::PROCESS *pProc);

void WaitInterpret(CORO_PARAM, Common::PPROCESS pWaitProc, bool *result);

#define NUM_INTERPRET	(CORO_NUM_PROCESS - 20)
#define MAX_INTERPRET	(CORO_MAX_PROCESSES - 20)

/*----------------------------------------------------------------------*\
|*	Library Procedure and Function codes parameter enums		*|
\*----------------------------------------------------------------------*/

#define TAG_DEF		0	// For tagactor()
#define TAG_Q1TO3	1	//	tag types
#define TAG_Q1TO4	2	//	tag types

#define CONV_DEF	0	//
#define CONV_BOTTOM	1	// conversation() parameter
#define CONV_END	2	//

#define CONTROL_OFF	0	// control()
#define CONTROL_ON	1	//	parameter
#define CONTROL_OFFV	2	//
#define CONTROL_OFFV2	3	//
#define CONTROL_STARTOFF 4	//

#define NULL_ACTOR (-1)		// For actor parameters
#define LEAD_ACTOR (-2)		//

#define RAND_NORM	0	// For random() frills
#define RAND_NORPT	1	//

#define D_UP		1
#define D_DOWN		0

#define TW_START	1	// topwindow() parameter
#define TW_END		2	//

#define MIDI_DEF	0
#define MIDI_LOOP	1

#define FM_IN		0	//
#define FM_OUT		1	// fademidi()

#define FG_ON		0	//
#define FG_OFF		1	// FrameGrab()

#define ST_ON		0	//
#define ST_OFF		1	// SubTitles()

} // End of namespace Tinsel

#endif		// TINSEL_PCODE_H