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