ScummVM API documentation
pcode.h
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 modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (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, see <http://www.gnu.org/licenses/>.
19 *
20 * Virtual processor definitions
21 */
22
23#ifndef TINSEL_PCODE_H // prevent multiple includes
24#define TINSEL_PCODE_H
25
26#include "tinsel/events.h" // for TINSEL_EVENT
27#include "tinsel/sched.h" // for Common::PROCESS
28
29namespace Common {
30class Serializer;
31}
32
33namespace Tinsel {
34
35class InventoryObject;
36
37enum RESUME_STATE {
38 RES_NOT, RES_1, RES_2, RES_SAVEGAME
39};
40
41enum {
42 PCODE_STACK_SIZE = 128
43};
44
45enum GSORT {
46 GS_NONE, GS_ACTOR, GS_MASTER, GS_POLYGON, GS_INVENTORY, GS_SCENE,
47 GS_PROCESS, GS_GPROCESS
48};
49
50enum RESCODE {RES_WAITING, RES_FINISHED, RES_CUTSHORT};
51
52struct WorkaroundEntry;
53
55
56 // Elements for interpret context management
58 GSORT GSort;
59
60 // Previously parameters to Interpret()
62 byte *code;
65 int idActor;
67
68 // Previously local variables in Interpret()
70 int sp;
71 int bp;
72 int ip;
73 bool bHalt;
74 bool escOn;
76
77 uint32 waitNumber1; // The waiting numbert
78 uint32 waitNumber2; // The wait for number
79 RESCODE resumeCode;
80 RESUME_STATE resumeState;
81
82 // Used to store execution state within a script workaround fragment
83 const WorkaroundEntry *fragmentPtr;
84
85 void syncWithSerializer(Common::Serializer &s);
86};
87
88/*----------------------------------------------------------------------*\
89|* Interpreter Function Prototypes *|
90\*----------------------------------------------------------------------*/
91
92// Interprets the PCODE instructions in the code array
93void Interpret(CORO_PARAM, INT_CONTEXT *ic);
94
95INT_CONTEXT *InitInterpretContext(
96 GSORT gsort,
97 SCNHANDLE hCode, // code to execute
98 TINSEL_EVENT event, // causal event
99 HPOLYGON hpoly, // associated polygon (if any)
100 int actorid, // associated actor (if any)
101 const InventoryObject *pinvo,
102 int myEscape = -1); // associated inventory object
103
104INT_CONTEXT *RestoreInterpretContext(INT_CONTEXT *ric);
105
106void FreeMostInterpretContexts();
107void FreeMasterInterpretContext();
108
109void SaveInterpretContexts(INT_CONTEXT *sICInfo);
110
111void RegisterGlobals(int num);
112void FreeGlobals();
113
114// Used by debugger
115int GetGlobalCount();
116int32 GetGlobal(int g);
117void SetGlobal(int g, int32 value);
118
119void AttachInterpret(INT_CONTEXT *pic, Common::PROCESS *pProc);
120
121void WaitInterpret(CORO_PARAM, Common::PPROCESS pWaitProc, bool *result);
122
123#define NUM_INTERPRET (CORO_NUM_PROCESS - 20)
124#define MAX_INTERPRET (CORO_MAX_PROCESSES - 20)
125
126/*----------------------------------------------------------------------*\
127|* Library Procedure and Function codes parameter enums *|
128\*----------------------------------------------------------------------*/
129
130#define TAG_DEF 0 // For tagactor()
131#define TAG_Q1TO3 1 // tag types
132#define TAG_Q1TO4 2 // tag types
133
134#define CONV_DEF 0 //
135#define CONV_BOTTOM 1 // conversation() parameter
136#define CONV_END 2 //
137
138#define CONTROL_OFF 0 // control()
139#define CONTROL_ON 1 // parameter
140#define CONTROL_OFFV 2 //
141#define CONTROL_OFFV2 3 //
142#define CONTROL_STARTOFF 4 //
143
144#define NULL_ACTOR (-1) // For actor parameters
145#define LEAD_ACTOR (-2) //
146
147#define RAND_NORM 0 // For random() frills
148#define RAND_NORPT 1 //
149
150#define D_UP 1
151#define D_DOWN 0
152
153#define TW_START 1 // topwindow() parameter
154#define TW_END 2 //
155
156#define MIDI_DEF 0
157#define MIDI_LOOP 1
158
159#define FM_IN 0 //
160#define FM_OUT 1 // fademidi()
161
162#define FG_ON 0 //
163#define FG_OFF 1 // FrameGrab()
164
165#define ST_ON 0 //
166#define ST_OFF 1 // SubTitles()
167
168} // End of namespace Tinsel
169
170#endif // TINSEL_PCODE_H
Definition: serializer.h:80
Definition: inv_objects.h:50
#define CORO_PARAM
Definition: coroutines.h:107
Definition: algorithm.h:29
Definition: actors.h:36
uint32 SCNHANDLE
Definition: dw.h:31
int HPOLYGON
Definition: dw.h:34
@ PCODE_STACK_SIZE
interpeters stack size
Definition: pcode.h:42
TINSEL_EVENT
Definition: events.h:91
Definition: coroutines.h:300
Definition: pcode.h:54
bool bHalt
set to exit interpeter
Definition: pcode.h:73
int myEscape
only initialized to prevent compiler warning!
Definition: pcode.h:75
const InventoryObject * pinvo
associated inventory object
Definition: pcode.h:66
HPOLYGON hPoly
associated polygon (if any)
Definition: pcode.h:64
int32 stack[PCODE_STACK_SIZE]
interpeters run time stack
Definition: pcode.h:69
GSORT GSort
sort of this context
Definition: pcode.h:58
TINSEL_EVENT event
causal event
Definition: pcode.h:63
int ip
instruction pointer
Definition: pcode.h:72
int sp
stack pointer
Definition: pcode.h:70
int bp
base pointer
Definition: pcode.h:71
int idActor
associated actor (if any)
Definition: pcode.h:65
Common::PROCESS * pProc
processes owning this context
Definition: pcode.h:57
SCNHANDLE hCode
scene handle of the code to execute
Definition: pcode.h:61
byte * code
pointer to the code to execute
Definition: pcode.h:62