renamed some parameters, and made them optional. if you don't provide the syscall function pointers, you can't load the vm as either dll or qvm (handy for when sv_pure stuff works properly)
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@1288 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
parent
1fec8005e7
commit
158163b29c
2 changed files with 34 additions and 28 deletions
|
@ -55,8 +55,8 @@ struct vm_s {
|
||||||
// common
|
// common
|
||||||
vm_type_t type;
|
vm_type_t type;
|
||||||
char name[MAX_QPATH];
|
char name[MAX_QPATH];
|
||||||
sys_call_t syscall;
|
sys_calldll_t syscalldll;
|
||||||
sys_callex_t syscallex;
|
sys_callqvm_t syscallqvm;
|
||||||
|
|
||||||
// shared
|
// shared
|
||||||
void *hInst;
|
void *hInst;
|
||||||
|
@ -68,9 +68,9 @@ struct vm_s {
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include "winquake.h"
|
#include "winquake.h"
|
||||||
void *Sys_LoadDLL(const char *name, void **vmMain, int (EXPORT_FN *syscall)(int arg, ... ))
|
void *Sys_LoadDLL(const char *name, void **vmMain, sys_calldll_t syscall)
|
||||||
{
|
{
|
||||||
void (VARGS *dllEntry)(int (EXPORT_FN *syscall)(int arg, ... ));
|
void (VARGS *dllEntry)(sys_calldll_t syscall);
|
||||||
char dllname[MAX_OSPATH];
|
char dllname[MAX_OSPATH];
|
||||||
HINSTANCE hVM;
|
HINSTANCE hVM;
|
||||||
|
|
||||||
|
@ -264,10 +264,10 @@ typedef struct qvm_s
|
||||||
qbyte *mem_ptr;
|
qbyte *mem_ptr;
|
||||||
|
|
||||||
// unsigned int cycles; // command cicles executed
|
// unsigned int cycles; // command cicles executed
|
||||||
sys_callex_t syscall;
|
sys_callqvm_t syscall;
|
||||||
} qvm_t;
|
} qvm_t;
|
||||||
|
|
||||||
qvm_t *QVM_Load(const char *name, sys_callex_t syscall);
|
qvm_t *QVM_Load(const char *name, sys_callqvm_t syscall);
|
||||||
void QVM_UnLoad(qvm_t *qvm);
|
void QVM_UnLoad(qvm_t *qvm);
|
||||||
int QVM_Exec(qvm_t *qvm, int command, int arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7);
|
int QVM_Exec(qvm_t *qvm, int command, int arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7);
|
||||||
|
|
||||||
|
@ -372,7 +372,7 @@ typedef enum qvm_op_e
|
||||||
/*
|
/*
|
||||||
** QVM_Load
|
** QVM_Load
|
||||||
*/
|
*/
|
||||||
qvm_t *QVM_Load(const char *name, sys_callex_t syscall)
|
qvm_t *QVM_Load(const char *name, sys_callqvm_t syscall)
|
||||||
{
|
{
|
||||||
char path[MAX_QPATH];
|
char path[MAX_QPATH];
|
||||||
vmHeader_t *header;
|
vmHeader_t *header;
|
||||||
|
@ -972,9 +972,9 @@ void VM_PrintInfo(vm_t *vm)
|
||||||
/*
|
/*
|
||||||
** VM_Create
|
** VM_Create
|
||||||
*/
|
*/
|
||||||
vm_t *VM_Create(vm_t *vm, const char *name, sys_call_t syscall, sys_callex_t syscallex)
|
vm_t *VM_Create(vm_t *vm, const char *name, sys_calldll_t syscalldll, sys_callqvm_t syscallqvm)
|
||||||
{
|
{
|
||||||
if(!name || !*name || !syscall || !syscallex)
|
if(!name || !*name)
|
||||||
Sys_Error("VM_Create: bad parms");
|
Sys_Error("VM_Create: bad parms");
|
||||||
|
|
||||||
if (!vm)
|
if (!vm)
|
||||||
|
@ -983,27 +983,33 @@ vm_t *VM_Create(vm_t *vm, const char *name, sys_call_t syscall, sys_callex_t sys
|
||||||
// prepare vm struct
|
// prepare vm struct
|
||||||
memset(vm, 0, sizeof(vm_t));
|
memset(vm, 0, sizeof(vm_t));
|
||||||
Q_strncpyz(vm->name, name, sizeof(vm->name));
|
Q_strncpyz(vm->name, name, sizeof(vm->name));
|
||||||
vm->syscall=syscall;
|
vm->syscalldll=syscalldll;
|
||||||
vm->syscallex=syscallex;
|
vm->syscallqvm=syscallqvm;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (!COM_CheckParm("-nodlls") && !COM_CheckParm("-nosos")) //:)
|
if (syscalldll)
|
||||||
{
|
{
|
||||||
if((vm->hInst=Sys_LoadDLL(name, (void**)&vm->vmMain, syscall)))
|
if (!COM_CheckParm("-nodlls") && !COM_CheckParm("-nosos")) //:)
|
||||||
{
|
{
|
||||||
Con_DPrintf("Creating native machine \"%s\"\n", name);
|
if((vm->hInst=Sys_LoadDLL(name, (void**)&vm->vmMain, syscalldll)))
|
||||||
vm->type=VM_NATIVE;
|
{
|
||||||
return vm;
|
Con_DPrintf("Creating native machine \"%s\"\n", name);
|
||||||
|
vm->type=VM_NATIVE;
|
||||||
|
return vm;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if((vm->hInst=QVM_Load(name, syscallex)))
|
if (syscallqvm)
|
||||||
{
|
{
|
||||||
Con_DPrintf("Creating virtual machine \"%s\"\n", name);
|
if((vm->hInst=QVM_Load(name, syscallqvm)))
|
||||||
vm->type=VM_BYTECODE;
|
{
|
||||||
return vm;
|
Con_DPrintf("Creating virtual machine \"%s\"\n", name);
|
||||||
|
vm->type=VM_BYTECODE;
|
||||||
|
return vm;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Z_Free(vm);
|
Z_Free(vm);
|
||||||
|
@ -1040,15 +1046,15 @@ void VM_Destroy(vm_t *vm)
|
||||||
qboolean VM_Restart(vm_t *vm)
|
qboolean VM_Restart(vm_t *vm)
|
||||||
{
|
{
|
||||||
char name[MAX_QPATH];
|
char name[MAX_QPATH];
|
||||||
sys_call_t syscall;
|
sys_calldll_t syscalldll;
|
||||||
sys_callex_t syscallex;
|
sys_callqvm_t syscallqvm;
|
||||||
|
|
||||||
if(!vm) return false;
|
if(!vm) return false;
|
||||||
|
|
||||||
// save params
|
// save params
|
||||||
Q_strncpyz(name, vm->name, sizeof(name));
|
Q_strncpyz(name, vm->name, sizeof(name));
|
||||||
syscall=vm->syscall;
|
syscalldll=vm->syscalldll;
|
||||||
syscallex=vm->syscallex;
|
syscallqvm=vm->syscallqvm;
|
||||||
|
|
||||||
// restart
|
// restart
|
||||||
switch(vm->type)
|
switch(vm->type)
|
||||||
|
@ -1065,7 +1071,7 @@ qboolean VM_Restart(vm_t *vm)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return VM_Create(vm, name, syscall, syscallex)!=NULL;
|
return VM_Create(vm, name, syscalldll, syscallqvm)!=NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *VM_MemoryBase(vm_t *vm)
|
void *VM_MemoryBase(vm_t *vm)
|
||||||
|
|
|
@ -10,8 +10,8 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef int (EXPORT_FN *sys_call_t) (int arg, ...);
|
typedef int (EXPORT_FN *sys_calldll_t) (int arg, ...);
|
||||||
typedef long (*sys_callex_t) (void *offset, unsigned int mask, int fn, const long *arg);
|
typedef long (*sys_callqvm_t) (void *offset, unsigned int mask, int fn, const long *arg);
|
||||||
|
|
||||||
typedef struct vm_s vm_t;
|
typedef struct vm_s vm_t;
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ typedef struct vm_s vm_t;
|
||||||
// ------------------------- * interface * -------------------------
|
// ------------------------- * interface * -------------------------
|
||||||
|
|
||||||
void VM_PrintInfo(vm_t *vm);
|
void VM_PrintInfo(vm_t *vm);
|
||||||
vm_t *VM_Create(vm_t *vm, const char *name, sys_call_t syscall, sys_callex_t syscallex);
|
vm_t *VM_Create(vm_t *vm, const char *name, sys_calldll_t syscalldll, sys_callqvm_t syscallqvm);
|
||||||
void VM_Destroy(vm_t *vm);
|
void VM_Destroy(vm_t *vm);
|
||||||
qboolean VM_Restart(vm_t *vm);
|
qboolean VM_Restart(vm_t *vm);
|
||||||
int VARGS VM_Call(vm_t *vm, int instruction, ...);
|
int VARGS VM_Call(vm_t *vm, int instruction, ...);
|
||||||
|
|
Loading…
Reference in a new issue