1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  * Virtual processor definitions
22  */
23 
24 #ifndef TINSEL_PCODE_H     // prevent multiple includes
25 #define TINSEL_PCODE_H
26 
27 #include "tinsel/events.h"	// for TINSEL_EVENT
28 #include "tinsel/sched.h"	// for Common::PROCESS
29 
30 namespace Common {
31 class Serializer;
32 }
33 
34 namespace Tinsel {
35 
36 // forward declaration
37 struct INV_OBJECT;
38 
39 enum RESUME_STATE {
40 	RES_NOT, RES_1, RES_2, RES_SAVEGAME
41 };
42 
43 enum {
44 	PCODE_STACK_SIZE	= 128	///< interpeters stack size
45 };
46 
47 enum GSORT {
48 	GS_NONE, GS_ACTOR, GS_MASTER, GS_POLYGON, GS_INVENTORY, GS_SCENE,
49 	GS_PROCESS, GS_GPROCESS
50 };
51 
52 enum RESCODE {RES_WAITING, RES_FINISHED, RES_CUTSHORT};
53 
54 struct WorkaroundEntry;
55 
56 struct INT_CONTEXT {
57 
58 	// Elements for interpret context management
59 	Common::PROCESS *pProc;			///< processes owning this context
60 	GSORT	GSort;			///< sort of this context
61 
62 	// Previously parameters to Interpret()
63 	SCNHANDLE	hCode;		///< scene handle of the code to execute
64 	byte		*code;		///< pointer to the code to execute
65 	TINSEL_EVENT	event;		///< causal event
66 	HPOLYGON	hPoly;		///< associated polygon (if any)
67 	int			idActor;	///< associated actor (if any)
68 	INV_OBJECT	*pinvo;		///< associated inventory object
69 
70 	// Previously local variables in Interpret()
71 	int32 stack[PCODE_STACK_SIZE];	///< interpeters run time stack
72 	int sp;				///< stack pointer
73 	int bp;				///< base pointer
74 	int ip;				///< instruction pointer
75 	bool bHalt;			///< set to exit interpeter
76 	bool escOn;
77 	int myEscape;		///< only initialized to prevent compiler warning!
78 
79 	uint32 waitNumber1;		// The waiting numbert
80 	uint32 waitNumber2;		// The wait for number
81 	RESCODE resumeCode;
82 	RESUME_STATE resumeState;
83 
84 	// Used to store execution state within a script workaround fragment
85 	const WorkaroundEntry *fragmentPtr;
86 
87 	void syncWithSerializer(Common::Serializer &s);
88 };
89 typedef INT_CONTEXT *PINT_CONTEXT;
90 
91 /*----------------------------------------------------------------------*\
92 |*			Interpreter Function Prototypes			*|
93 \*----------------------------------------------------------------------*/
94 
95 // Interprets the PCODE instructions in the code array
96 void Interpret(CORO_PARAM, INT_CONTEXT *ic);
97 
98 INT_CONTEXT *InitInterpretContext(
99 	GSORT		gsort,
100 	SCNHANDLE	hCode,		// code to execute
101 	TINSEL_EVENT	event,		// causal event
102 	HPOLYGON	hpoly,		// associated polygon (if any)
103 	int		actorid,	// associated actor (if any)
104 	INV_OBJECT	*pinvo,
105 	int myEscape = -1);		// associated inventory object
106 
107 INT_CONTEXT *RestoreInterpretContext(INT_CONTEXT *ric);
108 
109 void FreeMostInterpretContexts();
110 void FreeMasterInterpretContext();
111 
112 void SaveInterpretContexts(INT_CONTEXT *sICInfo);
113 
114 void RegisterGlobals(int num);
115 void FreeGlobals();
116 
117 void AttachInterpret(INT_CONTEXT *pic, Common::PROCESS *pProc);
118 
119 void WaitInterpret(CORO_PARAM, Common::PPROCESS pWaitProc, bool *result);
120 
121 #define NUM_INTERPRET	(CORO_NUM_PROCESS - 20)
122 #define MAX_INTERPRET	(CORO_MAX_PROCESSES - 20)
123 
124 /*----------------------------------------------------------------------*\
125 |*	Library Procedure and Function codes parameter enums		*|
126 \*----------------------------------------------------------------------*/
127 
128 #define TAG_DEF		0	// For tagactor()
129 #define TAG_Q1TO3	1	//	tag types
130 #define TAG_Q1TO4	2	//	tag types
131 
132 #define CONV_DEF	0	//
133 #define CONV_BOTTOM	1	// conversation() parameter
134 #define CONV_END	2	//
135 
136 #define CONTROL_OFF	0	// control()
137 #define CONTROL_ON	1	//	parameter
138 #define CONTROL_OFFV	2	//
139 #define CONTROL_OFFV2	3	//
140 #define CONTROL_STARTOFF 4	//
141 
142 #define NULL_ACTOR (-1)		// For actor parameters
143 #define LEAD_ACTOR (-2)		//
144 
145 #define RAND_NORM	0	// For random() frills
146 #define RAND_NORPT	1	//
147 
148 #define D_UP		1
149 #define D_DOWN		0
150 
151 #define TW_START	1	// topwindow() parameter
152 #define TW_END		2	//
153 
154 #define MIDI_DEF	0
155 #define MIDI_LOOP	1
156 
157 #define FM_IN		0	//
158 #define FM_OUT		1	// fademidi()
159 
160 #define FG_ON		0	//
161 #define FG_OFF		1	// FrameGrab()
162 
163 #define ST_ON		0	//
164 #define ST_OFF		1	// SubTitles()
165 
166 } // End of namespace Tinsel
167 
168 #endif		// TINSEL_PCODE_H
169