ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 
29 namespace Common {
30 class Serializer;
31 }
32 
33 namespace Tinsel {
34 
35 class InventoryObject;
36 
37 enum RESUME_STATE {
38  RES_NOT, RES_1, RES_2, RES_SAVEGAME
39 };
40 
41 enum {
43 };
44 
45 enum GSORT {
46  GS_NONE, GS_ACTOR, GS_MASTER, GS_POLYGON, GS_INVENTORY, GS_SCENE,
47  GS_PROCESS, GS_GPROCESS
48 };
49 
50 enum RESCODE {RES_WAITING, RES_FINISHED, RES_CUTSHORT};
51 
52 struct WorkaroundEntry;
53 
54 struct INT_CONTEXT {
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()
69  int32 stack[PCODE_STACK_SIZE];
70  int sp;
71  int bp;
72  int ip;
73  bool bHalt;
74  bool escOn;
75  int myEscape;
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
93 void Interpret(CORO_PARAM, INT_CONTEXT *ic);
94 
95 INT_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 
104 INT_CONTEXT *RestoreInterpretContext(INT_CONTEXT *ric);
105 
106 void FreeMostInterpretContexts();
107 void FreeMasterInterpretContext();
108 
109 void SaveInterpretContexts(INT_CONTEXT *sICInfo);
110 
111 void RegisterGlobals(int num);
112 void FreeGlobals();
113 
114 void AttachInterpret(INT_CONTEXT *pic, Common::PROCESS *pProc);
115 
116 void WaitInterpret(CORO_PARAM, Common::PPROCESS pWaitProc, bool *result);
117 
118 #define NUM_INTERPRET (CORO_NUM_PROCESS - 20)
119 #define MAX_INTERPRET (CORO_MAX_PROCESSES - 20)
120 
121 /*----------------------------------------------------------------------*\
122 |* Library Procedure and Function codes parameter enums *|
123 \*----------------------------------------------------------------------*/
124 
125 #define TAG_DEF 0 // For tagactor()
126 #define TAG_Q1TO3 1 // tag types
127 #define TAG_Q1TO4 2 // tag types
128 
129 #define CONV_DEF 0 //
130 #define CONV_BOTTOM 1 // conversation() parameter
131 #define CONV_END 2 //
132 
133 #define CONTROL_OFF 0 // control()
134 #define CONTROL_ON 1 // parameter
135 #define CONTROL_OFFV 2 //
136 #define CONTROL_OFFV2 3 //
137 #define CONTROL_STARTOFF 4 //
138 
139 #define NULL_ACTOR (-1) // For actor parameters
140 #define LEAD_ACTOR (-2) //
141 
142 #define RAND_NORM 0 // For random() frills
143 #define RAND_NORPT 1 //
144 
145 #define D_UP 1
146 #define D_DOWN 0
147 
148 #define TW_START 1 // topwindow() parameter
149 #define TW_END 2 //
150 
151 #define MIDI_DEF 0
152 #define MIDI_LOOP 1
153 
154 #define FM_IN 0 //
155 #define FM_OUT 1 // fademidi()
156 
157 #define FG_ON 0 //
158 #define FG_OFF 1 // FrameGrab()
159 
160 #define ST_ON 0 //
161 #define ST_OFF 1 // SubTitles()
162 
163 } // End of namespace Tinsel
164 
165 #endif // TINSEL_PCODE_H
byte * code
pointer to the code to execute
Definition: pcode.h:62
SCNHANDLE hCode
scene handle of the code to execute
Definition: pcode.h:61
const InventoryObject * pinvo
associated inventory object
Definition: pcode.h:66
uint32 SCNHANDLE
Definition: dw.h:31
int bp
base pointer
Definition: pcode.h:71
int idActor
associated actor (if any)
Definition: pcode.h:65
int ip
instruction pointer
Definition: pcode.h:72
GSORT GSort
sort of this context
Definition: pcode.h:58
Definition: serializer.h:79
TINSEL_EVENT
Definition: events.h:91
int sp
stack pointer
Definition: pcode.h:70
#define CORO_PARAM
Definition: coroutines.h:107
Definition: coroutines.h:300
Definition: algorithm.h:29
HPOLYGON hPoly
associated polygon (if any)
Definition: pcode.h:64
Definition: actors.h:36
TINSEL_EVENT event
causal event
Definition: pcode.h:63
bool bHalt
set to exit interpeter
Definition: pcode.h:73
int myEscape
only initialized to prevent compiler warning!
Definition: pcode.h:75
Definition: inv_objects.h:50
interpeters stack size
Definition: pcode.h:42
Common::PROCESS * pProc
processes owning this context
Definition: pcode.h:57
Definition: pcode.h:54
int HPOLYGON
Definition: dw.h:34