ScummVM API documentation
intrinsics.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  */
21 
22 #ifndef ULTIMA8_USECODE_INTRINSICS_H
23 #define ULTIMA8_USECODE_INTRINSICS_H
24 
25 #include "common/scummsys.h"
26 
27 namespace Ultima {
28 namespace Ultima8 {
29 
30 typedef uint32(*Intrinsic)(const uint8 *args, unsigned int argsize);
31 
32 #define INTRINSIC(x) static uint32 x (const uint8* args, unsigned int argsize)
33 
34 // TODO: range checking on args
35 
36 // UINT8s are pushed on the stack as words (see push byte opcodes),
37 // so we ignore the top byte when popping.
38 #define ARG_UINT8(x) uint8 x = (*args++); args++;
39 #define ARG_UINT16(x) uint16 x = (*args++); x += ((*args++) << 8);
40 #define ARG_UINT32(x) uint32 x = (*args++); x += ((*args++) << 8); \
41  x+= ((*args++) << 16); x += ((*args++) << 24);
42 #define ARG_SINT8(x) int8 x = (*args++);
43 #define ARG_SINT16(x) int16 x = (*args++); x += ((*args++) << 8);
44 #define ARG_SINT32(x) int32 x = (*args++); x += ((*args++) << 8); \
45  x+= ((*args++) << 16); x += ((*args++) << 24);
46 #define ARG_UC_PTR(x) uint32 x = (*args++); x += ((*args++) << 8); \
47  x+= ((*args++) << 16); x += ((*args++) << 24);
48 #define ARG_OBJID(x) ObjId x = (*args++); x += ((*args++) << 8);
49 #define ARG_PROCID(x) ProcId x = (*args++); x += ((*args++) << 8);
50 
51 #define ARG_OBJECT_FROM_PTR(x) ARG_UC_PTR(ucptr_##x); \
52  uint16 id_##x = UCMachine::ptrToObject(ucptr_##x); \
53  Object* x = getObject(id_##x);
54 #define ARG_OBJECT_FROM_ID(x) ARG_OBJID(id_##x); \
55  Object* x = getObject(id_##x);
56 
57 #define ARG_ITEM_FROM_PTR(x) ARG_UC_PTR(ucptr_##x); \
58  uint16 id_##x = UCMachine::ptrToObject(ucptr_##x); \
59  Item* x = getItem(id_##x);
60 #define ARG_ITEM_FROM_ID(x) ARG_OBJID(id_##x); \
61  Item* x = getItem(id_##x);
62 
63 #define ARG_CONTAINER_FROM_PTR(x) ARG_UC_PTR(ucptr_##x); \
64  uint16 id_##x = UCMachine::ptrToObject(ucptr_##x); \
65  Container* x = getContainer(id_##x);
66 #define ARG_CONTAINER_FROM_ID(x) ARG_OBJID(id_##x); \
67  Container* x = getContainer(id_##x);
68 
69 #define ARG_ACTOR_FROM_PTR(x) ARG_UC_PTR(ucptr_##x); \
70  uint16 id_##x = UCMachine::ptrToObject(ucptr_##x); \
71  Actor* x = getActor(id_##x);
72 #define ARG_ACTOR_FROM_ID(x) ARG_OBJID(id_##x); \
73  Actor* x = getActor(id_##x);
74 
75 #define ARG_EGG_FROM_PTR(x) ARG_UC_PTR(ucptr_##x); \
76  uint16 id_##x = UCMachine::ptrToObject(ucptr_##x); \
77  Egg* x = dynamic_cast<Egg*>(getObject(id_##x));
78 #define ARG_EGG_FROM_ID(x) ARG_OBJID(id_##x); \
79  Egg* x = dynamic_cast<Egg*>(getObject(id_##x));
80 
81 #define ARG_STRING(x) ARG_UC_PTR(ucptr_##x); \
82  uint16 id_##x = UCMachine::ptrToObject(ucptr_##x); \
83  Std::string x = UCMachine::get_instance()->getString(id_##x);
84 
85 #define ARG_LIST(x) ARG_UINT16(id_##x); \
86  UCList* x = UCMachine::get_instance()->getList(id_##x);
87 
88 #define ARG_WORLDPOINT(x) ARG_UC_PTR(ucptr_##x); \
89  WorldPoint x; \
90  UCMachine::get_instance()->dereferencePointer(ucptr_##x, x._buf, 5);
91 
92 // See comment on ARG_UINT8 for why +2 on NULL8
93 #define ARG_NULL8() args+=2;
94 #define ARG_NULL16() args+=2;
95 #define ARG_NULL32() args+=4;
96 
97 } // End of namespace Ultima8
98 } // End of namespace Ultima
99 
100 #endif
Definition: detection.h:27