From 6a4d11f3dee819ebe98db05fc585f8de0c93640b Mon Sep 17 00:00:00 2001 From: Nunuhara Cabbage Date: Tue, 7 Jan 2020 22:48:29 -0800 Subject: [PATCH] Use libffi for library calls Use libffi to portably call arbitrary functions at runtime, rather than forcing library functions to use a standard prototype. --- README.md | 12 +- include/sact.h | 36 +- include/savedata.h | 1 + include/system4/ain.h | 11 + include/system4/string.h | 1 + include/vm.h | 12 +- meson.build | 1 + src/ffi.c | 235 +++++++++ src/hll/ACXLoader.c | 68 ++- src/hll/AliceLogo.c | 19 +- src/hll/AliceLogo2.c | 19 +- src/hll/AliceLogo3.c | 19 +- src/hll/Confirm2.c | 24 +- src/hll/DrawGraph.c | 572 ++++++++++----------- src/hll/DrawPluginManager.c | 12 +- src/hll/File.c | 118 ++--- src/hll/Math.c | 148 ++---- src/hll/MsgLogManager.c | 44 +- src/hll/MsgSkip.c | 69 ++- src/hll/OutputLog.c | 32 +- src/hll/PlayMovie.c | 34 +- src/hll/SACT2.c | 999 +++++++++++++----------------------- src/hll/SystemServiceEx.c | 38 +- src/hll/hll.h | 72 +-- src/meson.build | 3 +- src/resume.c | 4 +- src/sact_graphics.c | 209 +++++++- src/savedata.c | 5 +- src/string.c | 6 + src/vm.c | 124 ----- 30 files changed, 1425 insertions(+), 1522 deletions(-) create mode 100644 src/ffi.c diff --git a/README.md b/README.md index a99f618..bef0bd9 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,17 @@ NOTE: This is a work in progress. Some simple ADV games run more or less okay, Building -------- -xsystem4 uses the meson build system. +First install the dependencies (corresponding Debian package in parentheses): + +* chibi-scheme [optional, for debugger] +* meson (meson) +* libffi (libffi-dev) +* SDL2 (libsdl2-dev) +* SDL2_mixer (libsdl2-mixer-dev) +* SDL2_ttf (libsdl2-ttf-dev) +* zlib (zlib1g-dev) + +Then build the xsystem4 executable with meson, mkdir build meson build diff --git a/include/sact.h b/include/sact.h index 9edaf25..56e2466 100644 --- a/include/sact.h +++ b/include/sact.h @@ -25,6 +25,7 @@ #include "gfx/types.h" struct string; +struct page; union vm_value; struct sact_sprite { @@ -51,30 +52,57 @@ struct texture *sact_get_texture(int sp_no); void sact_render_scene(void); -int sact_Init(void); +int sact_Init(void *_, int cg_cache_size); int sact_SetWP(int cg_no); +int sact_SetWP_Color(int r, int g, int b); +int sact_GetScreenWidth(void); +int sact_GetScreenHeight(void); +int sact_GetMainSurfaceNumber(void); int sact_Update(void); int sact_Effect(int type, int time, int key); int sact_SP_GetUnuseNum(int min); int sact_SP_Count(void); -int sact_SP_Enum(union vm_value *array, int size); +int sact_SP_Enum(struct page **array); int sact_SP_GetMaxZ(void); int sact_SP_SetCG(int sp, int cg); int sact_SP_Create(int sp, int width, int height, int r, int g, int b, int a); int sact_SP_CreatePixelOnly(int sp, int width, int height); int sact_SP_Delete(int sp); +int sact_SP_SetPos(int sp_no, int x, int y); +int sact_SP_SetX(int sp_no, int x); +int sact_SP_SetY(int sp_no, int y); int sact_SP_SetZ(int sp, int z); int sact_SP_GetBlendRate(int sp_no); int sact_SP_SetBlendRate(int sp_no, int rate); int sact_SP_SetShow(int sp_no, bool show); int sact_SP_SetDrawMethod(int sp_no, int method); int sact_SP_GetDrawMethod(int sp_no); +int sact_SP_IsUsing(int sp_no); int sact_SP_ExistsAlpha(int sp_no); -int sact_SP_TextDraw(int sp_no, struct string *text, union vm_value *tm); +int sact_SP_GetPosX(int sp_no); +int sact_SP_GetPosY(int sp_no); +int sact_SP_GetWidth(int sp_no); +int sact_SP_GetHeight(int sp_no); +int sact_SP_GetZ(int sp_no); +int sact_SP_GetShow(int sp_no); +int sact_SP_SetTextHome(int sp_no, int x, int y); +int sact_SP_SetTextLineSpace(int sp_no, int px); +int sact_SP_SetTextCharSpace(int sp_no, int px); +int sact_SP_SetTextPos(int sp_no, int x, int y); +int sact_SP_TextDraw(int sp_no, struct string *text, struct page *tm); int sact_SP_TextClear(int sp_no); +int sact_SP_TextHome(int sp_no, int size); +int sact_SP_TextNewLine(int sp_no, int size); int sact_SP_TextCopy(int dno, int sno); +int sact_SP_GetTextHomeX(int sp_no); +int sact_SP_GetTextHomeY(int sp_no); +int sact_SP_GetTextCharSpace(int sp_no); +int sact_SP_GetTextPosX(int sp_no); +int sact_SP_GetTextPosY(int sp_no); +int sact_SP_GetTextLineSpace(int sp_no); int sact_SP_IsPtIn(int sp_no, int x, int y); -int sact_CG_GetMetrics(int cg_no, union vm_value *cgm); +int sact_SP_IsPtInRect(int sp_no, int x, int y); +int sact_CG_GetMetrics(int cg_no, struct page **page); int sact_SP_GetAMapValue(int sp_no, int x, int y); int sact_SP_GetPixelValue(int sp_no, int x, int y, int *r, int *g, int *b); diff --git a/include/savedata.h b/include/savedata.h index 4d64c80..757e6aa 100644 --- a/include/savedata.h +++ b/include/savedata.h @@ -20,6 +20,7 @@ #include "cJSON.h" #include "vm.h" +cJSON *page_to_json(struct page *page); cJSON *vm_value_to_json(enum ain_data_type type, union vm_value val); void json_load_page(struct page *page, cJSON *vars); union vm_value json_to_vm_value(enum ain_data_type type, enum ain_data_type struct_type, int array_rank, cJSON *json); diff --git a/include/system4/ain.h b/include/system4/ain.h index d937dec..d94391c 100644 --- a/include/system4/ain.h +++ b/include/system4/ain.h @@ -83,6 +83,17 @@ enum ain_data_type { case AIN_ARRAY_LONG_INT: \ case AIN_ARRAY_DELEGATE +#define AIN_REF_ARRAY_TYPE \ + AIN_REF_ARRAY_INT: \ + case AIN_REF_ARRAY_FLOAT: \ + case AIN_REF_ARRAY_STRING: \ + case AIN_REF_ARRAY_STRUCT: \ + case AIN_REF_ARRAY_FUNC_TYPE: \ + case AIN_REF_ARRAY_BOOL: \ + case AIN_REF_ARRAY_LONG_INT: \ + case AIN_REF_ARRAY_DELEGATE + + #define AIN_REF_TYPE \ AIN_REF_INT: \ case AIN_REF_FLOAT: \ diff --git a/include/system4/string.h b/include/system4/string.h index 8282bb4..de19cdf 100644 --- a/include/system4/string.h +++ b/include/system4/string.h @@ -50,6 +50,7 @@ void string_append_cstr(struct string **a, const char *b, size_t b_size); void string_push_back(struct string **s, int c); void string_pop_back(struct string **s); void string_erase(struct string **s, int index); +void string_clear(struct string *s); // queries int string_find(const struct string *haystack, const struct string *needle); diff --git a/include/vm.h b/include/vm.h index 13a2244..2ab0bd1 100644 --- a/include/vm.h +++ b/include/vm.h @@ -31,20 +31,17 @@ union vm_value { int32_t i; int64_t li; float f; - // HLL only - void *ref; - int *iref; - float *fref; + void *ref; // for casting HLL return value }; struct static_hll_function { char *name; - union vm_value (*fun)(union vm_value *_args); + void *fun; }; struct static_library { char *name; - struct static_hll_function **functions; + struct static_hll_function functions[]; }; struct ain *ain; @@ -111,6 +108,9 @@ void vm_execute_ain(struct ain *program); void vm_call(int fno, int struct_page); int vm_time(void); +void hll_call(int libno, int fno); +void link_libraries(void); + void vm_stack_trace(void); noreturn void _vm_error(const char *fmt, ...); noreturn void vm_exit(int code); diff --git a/meson.build b/meson.build index ceffa9b..908acfe 100644 --- a/meson.build +++ b/meson.build @@ -7,6 +7,7 @@ libm = meson.get_compiler('c').find_library('m', required: false) sdl2 = dependency('sdl2') sdl2ttf = dependency('SDL2_ttf') sdl2mixer = dependency('SDL2_mixer') +ffi = dependency('libffi') gl = dependency('GL') glew = dependency('glew') chibi = dependency('chibi-scheme', required : get_option('debugger')) diff --git a/src/ffi.c b/src/ffi.c new file mode 100644 index 0000000..ac2677f --- /dev/null +++ b/src/ffi.c @@ -0,0 +1,235 @@ +/* Copyright (C) 2019 Nunuhara Cabbage + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include "system4/ain.h" +#include "vm.h" +#include "vm/heap.h" +#include "vm/page.h" + +#define HLL_MAX_ARGS 64 + +struct hll_function { + void *fun; + ffi_cif cif; + unsigned int nr_args; + ffi_type **args; + ffi_type *return_type; +}; + +static struct hll_function **libraries; + +void hll_call(int libno, int fno) +{ + struct ain_hll_function *f = &ain->libraries[libno].functions[fno]; + + if (!libraries[libno]) + VM_ERROR("Unimplemented HLL function: %s.%s", ain->libraries[libno].name, f->name); + + struct hll_function *fun = &libraries[libno][fno]; + if (!fun->fun) + VM_ERROR("Unimplemented HLL function: %s.%s", ain->libraries[libno].name, f->name); + + void *args[HLL_MAX_ARGS]; + void *ptrs[HLL_MAX_ARGS]; + for (int i = f->nr_arguments - 1; i >= 0; i--) { + switch (f->arguments[i].data_type) { + case AIN_REF_INT: + case AIN_REF_LONG_INT: + case AIN_REF_BOOL: + case AIN_REF_FLOAT: { + // need to create pointer for immediate ref types + stack_ptr -= 2; + int pageno = stack[stack_ptr].i; + int varno = stack[stack_ptr+1].i; + ptrs[i] = &heap[pageno].page->values[varno]; + args[i] = &ptrs[i]; + break; + } + case AIN_STRING: + stack_ptr--; + args[i] = &heap[stack[stack_ptr].i].s; + break; + case AIN_REF_STRING: + stack_ptr--; + ptrs[i] = &heap[stack[stack_ptr].i].s; + args[i] = &ptrs[i]; + break; + case AIN_STRUCT: + case AIN_ARRAY_TYPE: + stack_ptr--; + args[i] = &heap[stack[stack_ptr].i].page; + break; + case AIN_REF_STRUCT: + case AIN_REF_ARRAY_TYPE: + stack_ptr--; + ptrs[i] = &heap[stack[stack_ptr].i].page; + args[i] = &ptrs[i]; + break; + default: + stack_ptr--; + args[i] = &stack[stack_ptr]; + break; + } + } + + union vm_value r; + ffi_call(&fun->cif, (void*)fun->fun, &r, args); + + for (int i = 0, j = 0; i < f->nr_arguments; i++, j++) { + // XXX: We don't increase the ref count when passing ref arguments to HLL + // functions, so we need to avoid decreasing it via variable_fini + switch (f->arguments[i].data_type) { + case AIN_REF_INT: + case AIN_REF_LONG_INT: + case AIN_REF_BOOL: + case AIN_REF_FLOAT: + j++; + break; + case AIN_REF_STRING: + case AIN_REF_STRUCT: + case AIN_REF_FUNC_TYPE: + case AIN_REF_ARRAY_TYPE: + break; + default: + variable_fini(stack[stack_ptr+j], f->arguments[i].data_type); + break; + } + } + + if (f->data_type != AIN_VOID) { + if (f->data_type == AIN_STRING) { + int slot = heap_alloc_slot(VM_STRING); + heap[slot].s = r.ref; + } else { + stack_push(r); + } + } +} + +extern struct static_library lib_ACXLoader; +extern struct static_library lib_AliceLogo; +extern struct static_library lib_AliceLogo2; +extern struct static_library lib_AliceLogo3; +extern struct static_library lib_Confirm2; +extern struct static_library lib_DrawGraph; +extern struct static_library lib_DrawPluginManager; +extern struct static_library lib_File; +extern struct static_library lib_Math; +extern struct static_library lib_MsgLogManager; +extern struct static_library lib_MsgSkip; +extern struct static_library lib_OutputLog; +extern struct static_library lib_PlayMovie; +extern struct static_library lib_SACT2; +extern struct static_library lib_SystemServiceEx; + +static struct static_library *static_libraries[] = { + &lib_ACXLoader, + &lib_AliceLogo, + &lib_AliceLogo2, + &lib_AliceLogo3, + &lib_Confirm2, + &lib_DrawGraph, + &lib_DrawPluginManager, + &lib_File, + &lib_Math, + &lib_MsgLogManager, + &lib_MsgSkip, + &lib_OutputLog, + &lib_PlayMovie, + &lib_SACT2, + &lib_SystemServiceEx, + NULL +}; + +static ffi_type *ain_to_ffi_type(enum ain_data_type type) +{ + switch (type) { + case AIN_VOID: + return &ffi_type_void; + case AIN_INT: + case AIN_BOOL: + return &ffi_type_sint32; + case AIN_LONG_INT: + return &ffi_type_sint64; + case AIN_FLOAT: + return &ffi_type_float; + case AIN_STRING: + case AIN_STRUCT: + case AIN_FUNC_TYPE: + case AIN_DELEGATE: + case AIN_ARRAY_TYPE: + case AIN_REF_TYPE: + case AIN_IMAIN_SYSTEM: // ??? + return &ffi_type_pointer; + default: + ERROR("Unhandled type in HLL function: %s", ain_strtype(ain, type, -1)); + } +} + +static void link_static_library_function(struct hll_function *dst, struct ain_hll_function *src, void *funcptr) +{ + dst->fun = funcptr; + dst->nr_args = src->nr_arguments; + dst->args = xcalloc(dst->nr_args, sizeof(ffi_type*)); + + for (unsigned int i = 0; i < dst->nr_args; i++) { + dst->args[i] = ain_to_ffi_type(src->arguments[i].data_type); + } + dst->return_type = ain_to_ffi_type(src->data_type); + + if (ffi_prep_cif(&dst->cif, FFI_DEFAULT_ABI, dst->nr_args, dst->return_type, dst->args) != FFI_OK) + ERROR("Failed to link HLL function"); +} + +/* + * "Link" a library that has been compiled into the xsystem4 executable. + */ +static struct hll_function *link_static_library(struct ain_library *ainlib, struct static_library *lib) +{ + struct hll_function *dst = xcalloc(ainlib->nr_functions, sizeof(struct hll_function)); + + for (int i = 0; i < ainlib->nr_functions; i++) { + for (int j = 0; lib->functions[j].name; j++) { + if (!strcmp(ainlib->functions[i].name, lib->functions[j].name)) { + link_static_library_function(&dst[i], &ainlib->functions[i], lib->functions[j].fun); + break; + } + } + if (!dst[i].fun) + WARNING("Unimplemented library function: %s.%s", ainlib->name, ainlib->functions[i].name); + else if (ainlib->functions[i].nr_arguments >= HLL_MAX_ARGS) + ERROR("Too many arguments to library function: %s", ainlib->functions[i].name); + } + return dst; +} + +void link_libraries(void) +{ + libraries = xcalloc(ain->nr_libraries, sizeof(struct hll_function*)); + + for (int i = 0; i < ain->nr_libraries; i++) { + for (int j = 0; static_libraries[j]; j++) { + if (!strcmp(ain->libraries[i].name, static_libraries[j]->name)) { + libraries[i] = link_static_library(&ain->libraries[i], static_libraries[j]); + break; + } + } + if (!libraries[i]) + WARNING("Unimplemented library: %s", ain->libraries[i].name); + } +} diff --git a/src/hll/ACXLoader.c b/src/hll/ACXLoader.c index b89b0c7..360d29d 100644 --- a/src/hll/ACXLoader.c +++ b/src/hll/ACXLoader.c @@ -20,6 +20,7 @@ #include "hll.h" #include "little_endian.h" #include "system4/string.h" +#include "vm/page.h" struct acx_file { int compressed_size; @@ -33,17 +34,17 @@ struct acx_file { static struct acx_file acx; //bool Load(string pIFileName) -hll_defun(Load, args) +bool ACXLoader_Load(struct string *filename) { FILE *fp; long len; uint8_t *buf = NULL; - char *path = gamedir_path(heap[args[0].i].s->text); + char *path = gamedir_path(filename->text); if (!(fp = fopen(path, "rb"))) { WARNING("ACXLoader.Load: Failed to open %s", path); free(path); - hll_return(false); + return false; } free(path); @@ -60,7 +61,7 @@ hll_defun(Load, args) // check magic if (strncmp((char*)buf, "ACX\0\0\0\0", 0)) { free(buf); - hll_return(false); + return false; } acx.compressed_size = LittleEndian_getDW(buf, 8); @@ -71,7 +72,7 @@ hll_defun(Load, args) if (Z_OK != uncompress(acx.data_raw, &size, buf+16, len-16)) { WARNING("ACXLoader.Load: uncompress failed"); free(buf); - hll_return(false); + return false; } acx.nr_columns = LittleEndian_getDW(acx.data_raw, 0); @@ -79,70 +80,59 @@ hll_defun(Load, args) acx.data = acx.data_raw + (8 + acx.nr_columns * 4); free(buf); - hll_return(true); + return true; } -//void Release() -hll_defun(Release, args) +void ACXLoader_Release(void) { free(acx.data_raw); memset(&acx, 0, sizeof(struct acx_file)); - hll_return(0); } -//int GetNumofLine() -hll_defun(GetNumofLine, args) +int ACXLoader_GetNumofLine(void) { - hll_return(acx.nr_lines); + return acx.nr_lines; } -//int GetNumofColumn() -hll_defun(GetNumofColumn, args) +int ACXLoader_GetNumofColumn(void) { - hll_return(acx.nr_columns); + return acx.nr_columns; } -//bool GetDataInt(int nLine, int nColumn, ref int pnData) -hll_defun(GetDataInt, args) +bool ACXLoader_GetDataInt(int line, int col, int *ptr) { - int line = args[0].i; - int col = args[1].i; if (line < 0 || line >= acx.nr_lines || col < 0 || col >= acx.nr_columns) - hll_return(false); + return false; uint8_t *data = acx.data + (line * acx.nr_columns * 4) + (col * 4); - *args[2].iref = LittleEndian_getDW(data, 0); + *ptr = LittleEndian_getDW(data, 0); - hll_return(true); + return true; } -//bool GetDataString(int nLine, int nColumn, ref string pIData) -hll_unimplemented(ACXLoader, GetDataString); +HLL_UNIMPLEMENTED(bool, ACXLoader, GetDataString, int line, int col, struct string *data); -//bool GetDataStruct(int nLine, ref struct pIVMStruct2) -hll_defun(GetDataStruct, args) +bool ACXLoader_GetDataStruct(int line, struct page **page) { - int line = args[0].i; - union vm_value *s = hll_struct_ref(args[1].i); + union vm_value *s = (*page)->values; if (line >= acx.nr_lines) - hll_return(false); + return false; uint8_t *data = acx.data + (line * acx.nr_columns * 4); for (int i = 0; i < acx.nr_columns; i++) { s[i].i = LittleEndian_getDW(data, i*4); } - hll_return(true); + return true; } -hll_deflib(ACXLoader) { - hll_export(Load), - hll_export(Release), - hll_export(GetNumofLine), - hll_export(GetNumofColumn), - hll_export(GetDataInt), - hll_export(GetDataString), - hll_export(GetDataStruct) -}; +HLL_LIBRARY(ACXLoader, + HLL_EXPORT(Load, ACXLoader_Load), + HLL_EXPORT(Release, ACXLoader_Release), + HLL_EXPORT(GetNumofLine, ACXLoader_GetNumofLine), + HLL_EXPORT(GetNumofColumn, ACXLoader_GetNumofColumn), + HLL_EXPORT(GetDataInt, ACXLoader_GetDataInt), + HLL_EXPORT(GetDataString, ACXLoader_GetDataString), + HLL_EXPORT(GetDataStruct, ACXLoader_GetDataStruct)); diff --git a/src/hll/AliceLogo.c b/src/hll/AliceLogo.c index 366deb4..1b4c0e6 100644 --- a/src/hll/AliceLogo.c +++ b/src/hll/AliceLogo.c @@ -16,16 +16,11 @@ #include "hll.h" -// int Init(imain_system pIMainSystem) -hll_warn_unimplemented(AliceLogo, Init, 1); -// void SetWaveNum(int nNum, int nWave) -hll_warn_unimplemented(AliceLogo, SetWaveNum, 0); -// void Run(int nType, int nLoopFlag) -hll_warn_unimplemented(AliceLogo, Run, 0); +HLL_WARN_UNIMPLEMENTED(1, int, AliceLogo, Init, void *imainsystem); +HLL_WARN_UNIMPLEMENTED( , void, AliceLogo, SetWaveNum, int n, int wave); +HLL_WARN_UNIMPLEMENTED( , void, AliceLogo, Run, int type, int loop_flag); -hll_deflib(AliceLogo) { - hll_export(Init), - hll_export(SetWaveNum), - hll_export(Run), - NULL -}; +HLL_LIBRARY(AliceLogo, + HLL_EXPORT(Init, AliceLogo_Init), + HLL_EXPORT(SetWaveNum, AliceLogo_SetWaveNum), + HLL_EXPORT(Run, AliceLogo_Run)); diff --git a/src/hll/AliceLogo2.c b/src/hll/AliceLogo2.c index 2d44269..c4610f9 100644 --- a/src/hll/AliceLogo2.c +++ b/src/hll/AliceLogo2.c @@ -16,16 +16,11 @@ #include "hll.h" -// int Init(imain_system pIMainSystem) -hll_warn_unimplemented(AliceLogo2, Init, 1); -// void SetWaveNum(int nNum, int nWave) -hll_warn_unimplemented(AliceLogo2, SetWaveNum, 0); -// void Run(int nType, int nLoopFlag) -hll_warn_unimplemented(AliceLogo2, Run, 0); +HLL_WARN_UNIMPLEMENTED(1, int, AliceLogo2, Init, void *imainsystem); +HLL_WARN_UNIMPLEMENTED( , void, AliceLogo2, SetWaveNum, int n, int wave); +HLL_WARN_UNIMPLEMENTED( , void, AliceLogo2, Run, int type, int loop_flag); -hll_deflib(AliceLogo2) { - hll_export(Init), - hll_export(SetWaveNum), - hll_export(Run), - NULL -}; +HLL_LIBRARY(AliceLogo2, + HLL_EXPORT(Init, AliceLogo2_Init), + HLL_EXPORT(SetWaveNum, AliceLogo2_SetWaveNum), + HLL_EXPORT(Run, AliceLogo2_Run)); diff --git a/src/hll/AliceLogo3.c b/src/hll/AliceLogo3.c index 6d18871..32669d7 100644 --- a/src/hll/AliceLogo3.c +++ b/src/hll/AliceLogo3.c @@ -16,16 +16,11 @@ #include "hll.h" -// int Init(imain_system pIMainSystem) -hll_warn_unimplemented(AliceLogo3, Init, 1); -// void SetWaveNum(int nNum, int nWave) -hll_warn_unimplemented(AliceLogo3, SetWaveNum, 0); -// void Run(int nType, int nLoopFlag) -hll_warn_unimplemented(AliceLogo3, Run, 0); +HLL_WARN_UNIMPLEMENTED(1, int, AliceLogo3, Init, void *imainsystem); +HLL_WARN_UNIMPLEMENTED( , void, AliceLogo3, SetWaveNum, int n, int wave); +HLL_WARN_UNIMPLEMENTED( , void, AliceLogo3, Run, int type, int loop_flag); -hll_deflib(AliceLogo3) { - hll_export(Init), - hll_export(SetWaveNum), - hll_export(Run), - NULL -}; +HLL_LIBRARY(AliceLogo3, + HLL_EXPORT(Init, AliceLogo3_Init), + HLL_EXPORT(SetWaveNum, AliceLogo3_SetWaveNum), + HLL_EXPORT(Run, AliceLogo3_Run)); diff --git a/src/hll/Confirm2.c b/src/hll/Confirm2.c index 93178d9..7ff24c6 100644 --- a/src/hll/Confirm2.c +++ b/src/hll/Confirm2.c @@ -16,19 +16,13 @@ #include "hll.h" -// void Init(imain_system pIMainSystem) -hll_warn_unimplemented(Confirm2, Init, 0); -// int ExistKeyFile(string pIFileName, int nKeyNum) -hll_warn_unimplemented(Confirm2, ExistKeyFile, 1); -// int CheckProtectFile(string pIFileName, int nKeyNum) -hll_unimplemented(Confirm2, CheckProtectFile); -// int CreateKeyFile(string pIFileName, int nKeyNum) -hll_unimplemented(Confirm2, CreateKeyFile); +HLL_WARN_UNIMPLEMENTED( , void, Confirm2, Init, void *imainsystem); +HLL_WARN_UNIMPLEMENTED(1, int, Confirm2, ExistKeyFile, struct string *filename, int keynum); +HLL_UNIMPLEMENTED(int, Confirm2, CheckProtectFile, struct string *filename, int keynum); +HLL_UNIMPLEMENTED(int, Confirm2, CreateKeyFile, struct string *filename, int keynum); -hll_deflib(Confirm2) { - hll_export(Init), - hll_export(ExistKeyFile), - hll_export(CheckProtectFile), - hll_export(CreateKeyFile), - NULL -}; +HLL_LIBRARY(Confirm2, + HLL_EXPORT(Init, Confirm2_Init), + HLL_EXPORT(ExistKeyFile, Confirm2_ExistKeyFile), + HLL_EXPORT(CheckProtectFile, Confirm2_CheckProtectFile), + HLL_EXPORT(CreateKeyFile, Confirm2_CreateKeyFile)); diff --git a/src/hll/DrawGraph.c b/src/hll/DrawGraph.c index 993f1c9..c97034d 100644 --- a/src/hll/DrawGraph.c +++ b/src/hll/DrawGraph.c @@ -21,298 +21,288 @@ #define TEX(sp_no) sact_get_texture(sp_no) -//void Copy(int nDest, int nDx, int nDy, int nSrc, int nSx, int nSy, int nWidth, int nHeight) -hll_defun_inline(Copy, (gfx_copy(TEX(a[0].i), a[1].i, a[2].i, TEX(a[3].i), a[4].i, a[5].i, a[6].i, a[7].i), 0)); -//void CopyBright(int nDest, int nDx, int nDy, int nSrc, int nSx, int nSy, int nWidth, int nHeight, int nRate) -hll_defun_inline(CopyBright, (gfx_copy_bright(TEX(a[0].i), a[1].i, a[2].i, TEX(a[3].i), a[4].i, a[5].i, a[6].i, a[7].i, a[8].i), 0)); -//void CopyAMap(int nDest, int nDx, int nDy, int nSrc, int nSx, int nSy, int nWidth, int nHeight) -hll_defun_inline(CopyAMap, (gfx_copy_amap(TEX(a[0].i), a[1].i, a[2].i, TEX(a[3].i), a[4].i, a[5].i, a[6].i, a[7].i), 0)); -//void CopySprite(int nDest, int nDx, int nDy, int nSrc, int nSx, int nSy, int nWidth, int nHeight, int nR, int nG, int nB) -hll_defun_inline(CopySprite, (gfx_copy_sprite(TEX(a[0].i), a[1].i, a[2].i, TEX(a[3].i), a[4].i, a[5].i, a[6].i, a[7].i, COLOR(a[8].i, a[9].i, a[10].i, 0)), 0)); -//void CopyColorReverse(int nDest, int nDx, int nDy, int nSrc, int nSx, int nSy, int nWidth, int nHeight) -hll_unimplemented(DrawGraph, CopyColorReverse); -//void CopyUseAMapUnder(int nDest, int nDx, int nDy, int nSrc, int nSx, int nSy, int nWidth, int nHeight, int nAlpha) -hll_defun_inline(CopyUseAMapUnder, (gfx_copy_use_amap_under(TEX(a[0].i), a[1].i, a[2].i, TEX(a[3].i), a[4].i, a[5].i, a[6].i, a[7].i, a[8].i), 0)); -//void CopyUseAMapBorder(int nDest, int nDx, int nDy, int nSrc, int nSx, int nSy, int nWidth, int nHeight, int nAlpha) -hll_defun_inline(CopyUseAMapBorder, (gfx_copy_use_amap_border(TEX(a[0].i), a[1].i, a[2].i, TEX(a[3].i), a[4].i, a[5].i, a[6].i, a[7].i, a[8].i), 0)); -//void CopyAMapMax(int nDest, int nDx, int nDy, int nSrc, int nSx, int nSy, int nWidth, int nHeight) -hll_defun_inline(CopyAMapMax, (gfx_copy_amap_max(TEX(a[0].i), a[1].i, a[2].i, TEX(a[3].i), a[4].i, a[5].i, a[6].i, a[7].i), 0)); -//void CopyAMapMin(int nDest, int nDx, int nDy, int nSrc, int nSx, int nSy, int nWidth, int nHeight) -hll_defun_inline(CopyAMapMin, (gfx_copy_amap_min(TEX(a[0].i), a[1].i, a[2].i, TEX(a[3].i), a[4].i, a[5].i, a[6].i, a[7].i), 0)); -//void Blend(int nDest, int nDx, int nDy, int nSrc, int nSx, int nSy, int nWidth, int nHeight, int nAlpha) -hll_unimplemented(DrawGraph, Blend); -//void BlendSrcBright(int nDest, int nDx, int nDy, int nSrc, int nSx, int nSy, int nWidth, int nHeight, int nAlpha, int nRate) -hll_unimplemented(DrawGraph, BlendSrcBright); -//void BlendAddSatur(int nDest, int nDx, int nDy, int nSrc, int nSx, int nSy, int nWidth, int nHeight) -hll_unimplemented(DrawGraph, BlendAddSatur); -//void BlendAMap(int nDest, int nDx, int nDy, int nSrc, int nSx, int nSy, int nWidth, int nHeight) -hll_defun_inline(BlendAMap, (gfx_blend_amap(TEX(a[0].i), a[1].i, a[2].i, TEX(a[3].i), a[4].i, a[5].i, a[6].i, a[7].i), 0)); -//void BlendAMapSrcOnly(int nDest, int nDx, int nDy, int nSrc, int nSx, int nSy, int nWidth, int nHeight) -hll_unimplemented(DrawGraph, BlendAMapSrcOnly); -//void BlendAMapColor(int nDest, int nDx, int nDy, int nSrc, int nSx, int nSy, int nWidth, int nHeight, int nR, int nG, int nB) -hll_unimplemented(DrawGraph, BlendAMapColor); -//void BlendAMapColorAlpha(int nDest, int nDx, int nDy, int nSrc, int nSx, int nSy, int nWidth, int nHeight, int nR, int nG, int nB, int nAlpha) -hll_unimplemented(DrawGraph, BlendAMapColorAlpha); -//void BlendAMapAlpha(int nDest, int nDx, int nDy, int nSrc, int nSx, int nSy, int nWidth, int nHeight, int nAlpha) -hll_defun_inline(BlendAMapAlpha, (gfx_blend_amap_alpha(TEX(a[0].i), a[1].i, a[2].i, TEX(a[3].i), a[4].i, a[5].i, a[6].i, a[7].i, a[8].i), 0)); -//void BlendAMapBright(int nDest, int nDx, int nDy, int nSrc, int nSx, int nSy, int nWidth, int nHeight, int nRate) -hll_unimplemented(DrawGraph, BlendAMapBright); -//void BlendAMapAlphaSrcBright(int nDest, int nDx, int nDy, int nSrc, int nSx, int nSy, int nWidth, int nHeight, int nAlpha, int nRate) -hll_unimplemented(DrawGraph, BlendAMapAlphaSrcBright); -//void BlendUseAMapColor(int nDest, int nDx, int nDy, int nAlpha, int nAx, int nAy, int nWidth, int nHeight, int nR, int nG, int nB, int nRate) -hll_unimplemented(DrawGraph, BlendUseAMapColor); -//void BlendScreen(int nDest, int nDx, int nDy, int nSrc, int nSx, int nSy, int nWidth, int nHeight) -hll_unimplemented(DrawGraph, BlendScreen); -//void BlendMultiply(int nDest, int nDx, int nDy, int nSrc, int nSx, int nSy, int nWidth, int nHeight) -hll_unimplemented(DrawGraph, BlendMultiply); -//void BlendScreenAlpha(int nDest, int nDx, int nDy, int nSrc, int nSx, int nSy, int nWidth, int nHeight, int nAlpha) -hll_unimplemented(DrawGraph, BlendScreenAlpha); -//void Fill(int nDest, int nX, int nY, int nWidth, int nHeight, int nR, int nG, int nB) -hll_defun_inline(Fill, (gfx_fill(TEX(a[0].i), a[1].i, a[2].i, a[3].i, a[4].i, a[5].i, a[6].i, a[7].i), 0)); -//void FillAlphaColor(int nDest, int nX, int nY, int nWidth, int nHeight, int nR, int nG, int nB, int nRate) -hll_defun_inline(FillAlphaColor, (gfx_fill_alpha_color(TEX(a[0].i), a[1].i, a[2].i, a[3].i, a[4].i, a[5].i, a[6].i, a[7].i, a[8].i), 0)); -//void FillAMap(int nDest, int nX, int nY, int nWidth, int nHeight, int nAlpha) -hll_defun_inline(FillAMap, (gfx_fill_amap(TEX(a[0].i), a[1].i, a[2].i, a[3].i, a[4].i, a[5].i), 0)); -//void FillAMapOverBorder(int nDest, int nX, int nY, int nWidth, int nHeight, int nAlpha, int nBorder) -hll_unimplemented(DrawGraph, FillAMapOverBorder); -//void FillAMapUnderBorder(int nDest, int nX, int nY, int nWidth, int nHeight, int nAlpha, int nBorder) -hll_unimplemented(DrawGraph, FillAMapUnderBorder); -//void FillAMapGradationUD(int nDest, int nX, int nY, int nWidth, int nHeight, int nUpA, int nDownA) -hll_unimplemented(DrawGraph, FillAMapGradationUD); -//void FillScreen(int nDest, int nX, int nY, int nWidth, int nHeight, int nR, int nG, int nB) -hll_unimplemented(DrawGraph, FillScreen); -//void FillMultiply(int nDest, int nX, int nY, int nWidth, int nHeight, int nR, int nG, int nB) -hll_unimplemented(DrawGraph, FillMultiply); -//void SaturDP_DPxSA(int nDest, int nDx, int nDy, int nSrc, int nSx, int nSy, int nWidth, int nHeight) -hll_unimplemented(DrawGraph, SaturDP); -//void ScreenDA_DAxSA(int nDest, int nDx, int nDy, int nSrc, int nSx, int nSy, int nWidth, int nHeight) -hll_unimplemented(DrawGraph, ScreenDA_DAxSA); -//void AddDA_DAxSA(int nDest, int nDx, int nDy, int nSrc, int nSx, int nSy, int nWidth, int nHeight) -hll_defun_inline(AddDA_DAxSA, (gfx_add_da_daxsa(TEX(a[0].i), a[1].i, a[2].i, TEX(a[3].i), a[4].i, a[5].i, a[6].i, a[7].i), 0)); -//void SpriteCopyAMap(int nDest, int nDx, int nDy, int nSrc, int nSx, int nSy, int nWidth, int nHeight, int nColorKey) -hll_unimplemented(DrawGraph, SpriteCopyAMap); -//void BlendDA_DAxSA(int nDest, int nDx, int nDy, int nSrc, int nSx, int nSy, int nWidth, int nHeight) -hll_unimplemented(DrawGraph, BlendDA); -//void SubDA_DAxSA(int nDest, int nDx, int nDy, int nSrc, int nSx, int nSy, int nWidth, int nHeight) -hll_unimplemented(DrawGraph, SubDA); -//void BrightDestOnly(int nDest, int nX, int nY, int nWidth, int nHeight, int nRate) -hll_unimplemented(DrawGraph, BrightDestOnly); -//void CopyTextureWrap(int nDest, int nDx, int nDy, int nDWidth, int nDHeight, int nSrc, int nSx, int nSy, int nSWidth, int nSHeight, int nU, int nV) -hll_unimplemented(DrawGraph, CopyTextureWrap); -//void CopyTextureWrapAlpha(int nDest, int nDx, int nDy, int nDWidth, int nDHeight, int nSrc, int nSx, int nSy, int nSWidth, int nSHeight, int nU, int nV, int nAlpha) -hll_unimplemented(DrawGraph, CopyTextureWrapAlpha); -//void CopyStretch(int nDest, int nDx, int nDy, int nDWidth, int nDHeight, int nSrc, int nSx, int nSy, int nSWidth, int nSHeight) -hll_defun_inline(CopyStretch, (gfx_copy_stretch(TEX(a[0].i), a[1].i, a[2].i, a[3].i, a[4].i, TEX(a[5].i), a[6].i, a[7].i, a[8].i, a[9].i), 0)); -//void CopyStretchBlend(int nDest, int nDx, int nDy, int nDWidth, int nDHeight, int nSrc, int nSx, int nSy, int nSWidth, int nSHeight, int nAlpha) -hll_unimplemented(DrawGraph, CopyStretchBlend); -//void CopyStretchBlendAMap(int nDest, int nDx, int nDy, int nDWidth, int nDHeight, int nSrc, int nSx, int nSy, int nSWidth, int nSHeight) -hll_unimplemented(DrawGraph, CopyStretchBlendAMap); -//void CopyStretchAMap(int nDest, int nDx, int nDy, int nDWidth, int nDHeight, int nSrc, int nSx, int nSy, int nSWidth, int nSHeight) -hll_defun_inline(CopyStretchAMap, (gfx_copy_stretch_amap(TEX(a[0].i), a[1].i, a[2].i, a[3].i, a[4].i, TEX(a[5].i), a[6].i, a[7].i, a[8].i, a[9].i), 0)); -//void CopyStretchInterp(int nDest, int nDx, int nDy, int nDWidth, int nDHeight, int nSrc, int nSx, int nSy, int nSWidth, int nSHeight) -hll_unimplemented(DrawGraph, CopyStretchInterp); -//void CopyStretchAMapInterp(int nDest, int nDx, int nDy, int nDWidth, int nDHeight, int nSrc, int nSx, int nSy, int nSWidth, int nSHeight) -hll_unimplemented(DrawGraph, CopyStretchAMapInterp); -//void CopyReduce(int nDest, int nDx, int nDy, int nDWidth, int nDHeight, int nSrc, int nSx, int nSy, int nSWidth, int nSHeight) -hll_defun_inline(CopyReduce, (gfx_copy_stretch(TEX(a[0].i), a[1].i, a[2].i, a[3].i, a[4].i, TEX(a[5].i), a[6].i, a[7].i, a[8].i, a[9].i), 0)); -//void CopyReduceAMap(int nDest, int nDx, int nDy, int nDWidth, int nDHeight, int nSrc, int nSx, int nSy, int nSWidth, int nSHeight) -hll_defun_inline(CopyReduceAMap, (gfx_copy_stretch_amap(TEX(a[0].i), a[1].i, a[2].i, a[3].i, a[4].i, TEX(a[5].i), a[6].i, a[7].i, a[8].i, a[9].i), 0)); -//void DrawTextToPMap(int nDest, int nX, int nY, string szText) -hll_defun_inline(DrawTextToPMap, (gfx_draw_text_to_pmap(TEX(a[0].i), a[1].i, a[2].i, hll_string_ref(a[3].i)->text), 0)); -//void DrawTextToAMap(int nDest, int nX, int nY, string szText) -hll_defun_inline(DrawTextToAMap, (gfx_draw_text_to_amap(TEX(a[0].i), a[1].i, a[2].i, hll_string_ref(a[3].i)->text), 0)); -//void SetFontSize(int nSize) -hll_defun_inline(SetFontSize, gfx_set_font_size(a[0].i)); -//void SetFontName(string pIText) -hll_warn_unimplemented(DrawGraph, SetFontName, 0); -//void SetFontWeight(int nWeight) -hll_defun_inline(SetFontWeight, gfx_set_font_weight(a[0].i)); -//void SetFontUnderline(int nFlag) -hll_defun_inline(SetFontUnderline, gfx_set_font_underline(a[0].i)); -//void SetFontStrikeOut(int nFlag) -hll_defun_inline(SetFontStrikeOut, gfx_set_font_strikeout(a[0].i)); -//void SetFontSpace(int nSpace) -hll_defun_inline(SetFontSpace, gfx_set_font_space(a[0].i)); -//void SetFontColor(int nR, int nG, int nB) -hll_defun_inline(SetFontColor, gfx_set_font_color(COLOR(a[0].i, a[1].i, a[2].i, 255))); -//int GetFontSize() -hll_defun_inline(GetFontSize, gfx_get_font_size()); -//string GetFontName() -hll_warn_unimplemented(DrawGraph, GetFontName, vm_string_ref(&EMPTY_STRING)); // FIXME -//int GetFontWeight() -hll_defun_inline(GetFontWeight, (int)gfx_get_font_weight()); -//int GetFontUnderline() -hll_defun_inline(GetFontUnderline, gfx_get_font_underline()); -//int GetFontStrikeOut() -hll_defun_inline(GetFontStrikeOut, gfx_get_font_strikeout()); -//int GetFontSpace() -hll_defun_inline(GetFontSpace, gfx_get_font_space()); - -//void GetFontColor(ref int pnR, ref int pnG, ref int pnB) -hll_defun(GetFontColor, args) +void DrawGraph_Copy(int dst, int dx, int dy, int src, int sx, int sy, int w, int h) { - SDL_Color c = gfx_get_font_color(); - *args[0].iref = c.r; - *args[1].iref = c.g; - *args[2].iref = c.b; - hll_return(0); + gfx_copy(TEX(dst), dx, dy, TEX(src), sx, sy, w, h); } -//void CopyRotZoom(int nDest, int nSrc, int nSx, int nSy, int nWidth, int nHeight, float fRotate, float fMag) -hll_defun_inline(CopyRotZoom, (gfx_copy_rot_zoom(TEX(a[0].i), TEX(a[1].i), a[2].i, a[3].i, a[4].i, a[5].i, a[6].f, a[7].f), 0)); -//void CopyRotZoomAMap(int nDest, int nSrc, int nSx, int nSy, int nWidth, int nHeight, float fRotate, float fMag) -hll_defun_inline(CopyRotZoomAMap, (gfx_copy_rot_zoom_amap(TEX(a[0].i), TEX(a[1].i), a[2].i, a[3].i, a[4].i, a[5].i, a[6].f, a[7].f), 0)); -//void CopyRotZoomUseAMap(int nDest, int nSrc, int nSx, int nSy, int nWidth, int nHeight, float fRotate, float fMag) -hll_defun_inline(CopyRotZoomUseAMap, (gfx_copy_rot_zoom_use_amap(TEX(a[0].i), TEX(a[1].i), a[2].i, a[3].i, a[4].i, a[5].i, a[6].f, a[7].f), 0)); -//void CopyRotZoom2Bilinear(int nDest, float fCx, float fCy, int nSrc, float fSrcCx, float fSrcCy, float fRotate, float fMag) -hll_unimplemented(DrawGraph, CopyRotZoom2Bilinear); -//void CopyRotateY(int nWrite, int nDest, int nSrc, int nSx, int nSy, int nWidth, int nHeight, float fRotate, float fMag) -hll_unimplemented(DrawGraph, CopyRotateY); -//void CopyRotateYUseAMap(int nWrite, int nDest, int nSrc, int nSx, int nSy, int nWidth, int nHeight, float fRotate, float fMag) -hll_unimplemented(DrawGraph, CopyRotateYUseAMap); -//void CopyRotateYFixL(int nWrite, int nDest, int nSrc, int nSx, int nSy, int nWidth, int nHeight, float fRotate, float fMag) -hll_unimplemented(DrawGraph, CopyRotateYFixL); -//void CopyRotateYFixR(int nWrite, int nDest, int nSrc, int nSx, int nSy, int nWidth, int nHeight, float fRotate, float fMag) -hll_unimplemented(DrawGraph, CopyRotateYFixR); -//void CopyRotateYFixLUseAMap(int nWrite, int nDest, int nSrc, int nSx, int nSy, int nWidth, int nHeight, float fRotate, float fMag) -hll_unimplemented(DrawGraph, CopyRotateYFixLUseAMap); -//void CopyRotateYFixRUseAMap(int nWrite, int nDest, int nSrc, int nSx, int nSy, int nWidth, int nHeight, float fRotate, float fMag) -hll_unimplemented(DrawGraph, CopyRotateYFixRUseAMap); -//void CopyRotatex(int nWrite, int nDest, int nSrc, int nSx, int nSy, int nWidth, int nHeight, float fRotate, float fMag) -hll_unimplemented(DrawGraph, CopyRotateX); -//void CopyRotateXUseAMap(int nWrite, int nDest, int nSrc, int nSx, int nSy, int nWidth, int nHeight, float fRotate, float fMag) -hll_unimplemented(DrawGraph, CopyRotateXUseAMap); -//void CopyRotateXFixU(int nWrite, int nDest, int nSrc, int nSx, int nSy, int nWidth, int nHeight, float fRotate, float fMag) -hll_unimplemented(DrawGraph, CopyRotateXFixU); -//void CopyRotateXFixD(int nWrite, int nDest, int nSrc, int nSx, int nSy, int nWidth, int nHeight, float fRotate, float fMag) -hll_unimplemented(DrawGraph, CopyRotateXFixD); -//void CopyRotateXFixUUseAMap(int nWrite, int nDest, int nSrc, int nSx, int nSy, int nWidth, int nHeight, float fRotate, float fMag) -hll_unimplemented(DrawGraph, CopyRotateXFixUUseAMap); -//void CopyRotateXFixDUseAMap(int nWrite, int nDest, int nSrc, int nSx, int nSy, int nWidth, int nHeight, float fRotate, float fMag) -hll_unimplemented(DrawGraph, CopyRotateXFixDUseAMap); -//void CopyReverseLR(int nDest, int nDx, int nDy, int nSrc, int nSx, int nSy, int nWidth, int nHeight) -hll_defun_inline(CopyReverseLR, (gfx_copy_reverse_LR(TEX(a[0].i), a[1].i, a[2].i, TEX(a[3].i), a[4].i, a[5].i, a[6].i, a[7].i), 0)); -//void CopyReverseUD(int nDest, int nDx, int nDy, int nSrc, int nSx, int nSy, int nWidth, int nHeight) -hll_unimplemented(DrawGraph, CopyReverseUD); -//void CopyReverseAMapLR(int nDest, int nDx, int nDy, int nSrc, int nSx, int nSy, int nWidth, int nHeight) -hll_defun_inline(CopyReverseAMapLR, (gfx_copy_reverse_amap_LR(TEX(a[0].i), a[1].i, a[2].i, TEX(a[3].i), a[4].i, a[5].i, a[6].i, a[7].i), 0)); -//void CopyReverseAMapUD(int nDest, int nDx, int nDy, int nSrc, int nSx, int nSy, int nWidth, int nHeight) -hll_unimplemented(DrawGraph, CopyReverseAMapUD); -//void CopyWidthBlur(int nDest, int nDx, int nDy, int nSrc, int nSx, int nSy, int nWidth, int nHeight, int nBlur) -hll_unimplemented(DrawGraph, CopyWidthBlur); -//void CopyHeightBlur(int nDest, int nDx, int nDy, int nSrc, int nSx, int nSy, int nWidth, int nHeight, int nBlur) -hll_unimplemented(DrawGraph, CopyHeightBlur); -//void CopyAMapWidthBlur(int nDest, int nDx, int nDy, int nSrc, int nSx, int nSy, int nWidth, int nHeight, int nBlur) -hll_unimplemented(DrawGraph, CopyAMapWidthBlur); -//void CopyAMapHeightBlur(int nDest, int nDx, int nDy, int nSrc, int nSx, int nSy, int nWidth, int nHeight, int nBlur) -hll_unimplemented(DrawGraph, CopyAMapHeightBlur); -//void DrawLine(int nDest, int nX0, int nY0, int nX1, int nY1, int nR, int nG, int nB) -hll_unimplemented(DrawGraph, DrawLine); -//void DrawLineToAMap(int nDest, int nX0, int nY0, int nX1, int nY1, int nAlpha) -hll_unimplemented(DrawGraph, DrawLineToAMap); -//bool GetPixelColor(int nSurface, int nX, int nY, ref int nR, ref int nG, ref int nB) -hll_defun_inline(GetPixelColor, sact_SP_GetPixelValue(a[0].i, a[1].i, a[2].i, a[3].iref, a[4].iref, a[5].iref)); -//bool GetAlphaColor(int nSurface, int nX, int nY, ref int nA) -hll_defun_inline(GetAlphaColor, (*a[3].iref = sact_SP_GetAMapValue(a[0].i, a[1].i, a[2].i), 1)); -//void DrawPolygon(int nDest, int nTex, float fX0, float fY0, float fZ0, float fU0, float fV0, float fX1, float fY1, float fZ1, float fU1, float fV1, float fX2, float fY2, float fZ2, float fU2, float fV2) -hll_unimplemented(DrawGraph, DrawPolygon); -//void DrawColorPolygon(int nDest, float fX0, float fY0, float fZ0, int nR0, int nG0, int nB0, int nA0, float fX1, float fY1, float fZ1, int nR1, int nG1, int nB1, int nA1, float fX2, float fY2, float fZ2, int nR2, int nG2, int nB2, int nA2) -hll_unimplemented(DrawGraph, DrawColorPolygon); +void DrawGraph_CopyBright(int dst, int dx, int dy, int src, int sx, int sy, int w, int h, int rate) +{ + gfx_copy_bright(TEX(dst), dx, dy, TEX(src), sx, sy, w, h, rate); +} -hll_deflib(DrawGraph) { - hll_export(Copy), - hll_export(CopyBright), - hll_export(CopyAMap), - hll_export(CopySprite), - hll_export(CopyColorReverse), - hll_export(CopyUseAMapUnder), - hll_export(CopyUseAMapBorder), - hll_export(CopyAMapMax), - hll_export(CopyAMapMin), - hll_export(Blend), - hll_export(BlendSrcBright), - hll_export(BlendAddSatur), - hll_export(BlendAMap), - hll_export(BlendAMapSrcOnly), - hll_export(BlendAMapColor), - hll_export(BlendAMapColorAlpha), - hll_export(BlendAMapAlpha), - hll_export(BlendAMapBright), - hll_export(BlendAMapAlphaSrcBright), - hll_export(BlendUseAMapColor), - hll_export(BlendScreen), - hll_export(BlendMultiply), - hll_export(BlendScreenAlpha), - hll_export(Fill), - hll_export(FillAlphaColor), - hll_export(FillAMap), - hll_export(FillAMapOverBorder), - hll_export(FillAMapUnderBorder), - hll_export(FillAMapGradationUD), - hll_export(FillScreen), - hll_export(FillMultiply), - hll_export(SaturDP), - hll_export(ScreenDA_DAxSA), - hll_export(AddDA_DAxSA), - hll_export(SpriteCopyAMap), - hll_export(BlendDA), - hll_export(SubDA), - hll_export(BrightDestOnly), - hll_export(CopyTextureWrap), - hll_export(CopyTextureWrapAlpha), - hll_export(CopyStretch), - hll_export(CopyStretchBlend), - hll_export(CopyStretchBlendAMap), - hll_export(CopyStretchAMap), - hll_export(CopyStretchInterp), - hll_export(CopyStretchAMapInterp), - hll_export(CopyReduce), - hll_export(CopyReduceAMap), - hll_export(DrawTextToPMap), - hll_export(DrawTextToAMap), - hll_export(SetFontSize), - hll_export(SetFontName), - hll_export(SetFontWeight), - hll_export(SetFontUnderline), - hll_export(SetFontStrikeOut), - hll_export(SetFontSpace), - hll_export(SetFontColor), - hll_export(GetFontSize), - hll_export(GetFontName), - hll_export(GetFontWeight), - hll_export(GetFontUnderline), - hll_export(GetFontStrikeOut), - hll_export(GetFontSpace), - hll_export(GetFontColor), - hll_export(CopyRotZoom), - hll_export(CopyRotZoomAMap), - hll_export(CopyRotZoomUseAMap), - hll_export(CopyRotZoom2Bilinear), - hll_export(CopyRotateY), - hll_export(CopyRotateYUseAMap), - hll_export(CopyRotateYFixL), - hll_export(CopyRotateYFixR), - hll_export(CopyRotateYFixLUseAMap), - hll_export(CopyRotateYFixRUseAMap), - hll_export(CopyRotateX), - hll_export(CopyRotateXUseAMap), - hll_export(CopyRotateXFixU), - hll_export(CopyRotateXFixD), - hll_export(CopyRotateXFixUUseAMap), - hll_export(CopyRotateXFixDUseAMap), - hll_export(CopyReverseLR), - hll_export(CopyReverseUD), - hll_export(CopyReverseAMapLR), - hll_export(CopyReverseAMapUD), - hll_export(CopyWidthBlur), - hll_export(CopyHeightBlur), - hll_export(CopyAMapWidthBlur), - hll_export(CopyAMapHeightBlur), - hll_export(DrawLine), - hll_export(DrawLineToAMap), - hll_export(GetPixelColor), - hll_export(GetAlphaColor), - hll_export(DrawPolygon), - hll_export(DrawColorPolygon), - NULL -}; +void DrawGraph_CopyAMap(int dst, int dx, int dy, int src, int sx, int sy, int w, int h) +{ + gfx_copy_amap(TEX(dst), dx, dy, TEX(src), sx, sy, w, h); +} + +void DrawGraph_CopySprite(int dst, int dx, int dy, int src, int sx, int sy, int w, int h, int r, int g, int b) +{ + gfx_copy_sprite(TEX(dst), dx, dy, TEX(src), sx, sy, w, h, COLOR(r, g, b, 0)); +} + +void DrawGraph_CopyUseAMapUnder(int dst, int dx, int dy, int src, int sx, int sy, int w, int h, int alpha) +{ + gfx_copy_use_amap_under(TEX(dst), dx, dy, TEX(src), sx, sy, w, h, alpha); +} + +void DrawGraph_CopyUseAMapBorder(int dst, int dx, int dy, int src, int sx, int sy, int w, int h, int alpha) +{ + gfx_copy_use_amap_border(TEX(dst), dx, dy, TEX(src), sx, sy, w, h, alpha); +} + +void DrawGraph_CopyAMapMax(int dst, int dx, int dy, int src, int sx, int sy, int w, int h) +{ + gfx_copy_amap_max(TEX(dst), dx, dy, TEX(src), sx, sy, w, h); +} + +void DrawGraph_CopyAMapMin(int dst, int dx, int dy, int src, int sx, int sy, int w, int h) +{ + gfx_copy_amap_min(TEX(dst), dx, dy, TEX(src), sx, sy, w, h); +} + +void DrawGraph_BlendAMap(int dst, int dx, int dy, int src, int sx, int sy, int w, int h) +{ + gfx_blend_amap(TEX(dst), dx, dy, TEX(src), sx, sy, w, h); +} + +void DrawGraph_BlendAMapAlpha(int dst, int dx, int dy, int src, int sx, int sy, int w, int h, int alpha) +{ + gfx_blend_amap_alpha(TEX(dst), dx, dy, TEX(src), sx, sy, w, h, alpha); +} + +void DrawGraph_Fill(int dst, int x, int y, int w, int h, int r, int g, int b) +{ + gfx_fill(TEX(dst), x, y, w, h, r, g, b); +} + +void DrawGraph_FillAlphaColor(int dst, int x, int y, int w, int h, int r, int g, int b, int rate) +{ + gfx_fill_alpha_color(TEX(dst), x, y, w, h, r, g, b, rate); +} + +void DrawGraph_FillAMap(int dst, int x, int y, int w, int h, int alpha) +{ + gfx_fill_amap(TEX(dst), x, y, w, h, alpha); +} + +void DrawGraph_AddDA_DAxSA(int dst, int dx, int dy, int src, int sx, int sy, int w, int h) +{ + gfx_add_da_daxsa(TEX(dst), dx, dy, TEX(src), sx, sy, w, h); +} + +void DrawGraph_CopyStretch(int dst, int dx, int dy, int dw, int dh, int src, int sx, int sy, int sw, int sh) +{ + gfx_copy_stretch(TEX(dst), dx, dy, dw, dh, TEX(src), sx, sy, sw, sh); +} + +void DrawGraph_CopyStretchAMap(int dst, int dx, int dy, int dw, int dh, int src, int sx, int sy, int sw, int sh) +{ + gfx_copy_stretch_amap(TEX(dst), dx, dy, dw, dh, TEX(src), sx, sy, sw, sh); +} + +void DrawGraph_DrawTextToPMap(int dst, int x, int y, struct string *s) +{ + gfx_draw_text_to_pmap(TEX(dst), x, y, s->text); +} + +void DrawGraph_DrawTextToAMap(int dst, int x, int y, struct string *s) +{ + gfx_draw_text_to_amap(TEX(dst), x, y, s->text); +} + +void DrawGraph_SetFontColor(int r, int g, int b) +{ + gfx_set_font_color(COLOR(r, g, b, 255)); +} + +void DrawGraph_GetFontColor(int *r, int *g, int *b) +{ + SDL_Color c = gfx_get_font_color(); + *r = c.r; + *g = c.g; + *b = c.b; +} + +void DrawGraph_CopyRotZoom(int dst, int src, int sx, int sy, int w, int h, float rotate, float mag) +{ + gfx_copy_rot_zoom(TEX(dst), TEX(src), sx, sy, w, h, rotate, mag); +} + +void DrawGraph_CopyRotZoomAMap(int dst, int src, int sx, int sy, int w, int h, float rotate, float mag) +{ + gfx_copy_rot_zoom_amap(TEX(dst), TEX(src), sx, sy, w, h, rotate, mag); +} + +void DrawGraph_CopyRotZoomUseAMap(int dst, int src, int sx, int sy, int w, int h, float rotate, float mag) +{ + gfx_copy_rot_zoom_use_amap(TEX(dst), TEX(src), sx, sy, w, h, rotate, mag); +} + +void DrawGraph_CopyReverseLR(int dst, int dx, int dy, int src, int sx, int sy, int w, int h) +{ + gfx_copy_reverse_LR(TEX(dst), dx, dy, TEX(src), sx, sy, w, h); +} + +void DrawGraph_CopyReverseAMapLR(int dst, int dx, int dy, int src, int sx, int sy, int w, int h) +{ + gfx_copy_reverse_amap_LR(TEX(dst), dx, dy, TEX(src), sx, sy, w, h); +} + +bool DrawGraph_GetAlphaColor(int surface, int x, int y, int *a) +{ + *a = sact_SP_GetAMapValue(surface, x, y); + return true; +} + +HLL_UNIMPLEMENTED(void, DrawGraph, CopyColorReverse, int dst, int dx, int dy, int src, int sx, int sy, int w, int h); +HLL_UNIMPLEMENTED(void, DrawGraph, Blend, int dst, int dx, int dy, int src, int sx, int sy, int w, int h, int alpha); +HLL_UNIMPLEMENTED(void, DrawGraph, BlendSrcBright, int dst, int dx, int dy, int src, int sx, int sy, int w, int h, int alpha, int rate); +HLL_UNIMPLEMENTED(void, DrawGraph, BlendAddSatur, int dst, int dx, int dy, int src, int sx, int sy, int w, int h); +HLL_UNIMPLEMENTED(void, DrawGraph, BlendAMapSrcOnly, int dst, int dx, int dy, int src, int sx, int sy, int w, int h); +HLL_UNIMPLEMENTED(void, DrawGraph, BlendAMapColor, int dst, int dx, int dy, int src, int sx, int sy, int w, int h, int r, int g, int b); +HLL_UNIMPLEMENTED(void, DrawGraph, BlendAMapColorAlpha, int dst, int dx, int dy, int src, int sx, int sy, int w, int h, int r, int g, int b, int a); +HLL_UNIMPLEMENTED(void, DrawGraph, BlendAMapBright, int dst, int dx, int dy, int src, int sx, int sy, int w, int h, int rate); +HLL_UNIMPLEMENTED(void, DrawGraph, BlendAMapAlphaSrcBright, int dst, int dx, int dy, int src, int sx, int sy, int w, int h, int alpha, int rate); +HLL_UNIMPLEMENTED(void, DrawGraph, BlendUseAMapColor, int dst, int dx, int dy, int alpha, int ax, int ay, int w, int h, int r, int g, int b, int rate); +HLL_UNIMPLEMENTED(void, DrawGraph, BlendScreen, int dst, int dx, int dy, int src, int sx, int sy, int w, int h); +HLL_UNIMPLEMENTED(void, DrawGraph, BlendMultiply, int dst, int dx, int dy, int src, int sx, int sy, int w, int h); +HLL_UNIMPLEMENTED(void, DrawGraph, BlendScreenAlpha, int dst, int dx, int dy, int src, int sx, int sy, int w, int h, int alpha); +HLL_UNIMPLEMENTED(void, DrawGraph, FillAMapOverBorder, int dst, int x, int y, int w, int h, int alpha, int border); +HLL_UNIMPLEMENTED(void, DrawGraph, FillAMapUnderBorder, int dst, int x, int y, int w, int h, int alpha, int border); +HLL_UNIMPLEMENTED(void, DrawGraph, FillAMapGradationUD, int dst, int x, int y, int w, int h, int up_a, int down_a); +HLL_UNIMPLEMENTED(void, DrawGraph, FillScreen, int dst, int x, int y, int w, int h, int r, int g, int b); +HLL_UNIMPLEMENTED(void, DrawGraph, FillMultiply, int dst, int x, int y, int w, int h, int r, int g, int b); +HLL_UNIMPLEMENTED(void, DrawGraph, SaturDP_DPxSA, int dst, int dx, int dy, int src, int sx, int sy, int w, int h); +HLL_UNIMPLEMENTED(void, DrawGraph, ScreenDA_DAxSA, int dst, int dx, int dy, int src, int sx, int sy, int w, int h); +HLL_UNIMPLEMENTED(void, DrawGraph, SpriteCopyAMap, int dst, int dx, int dy, int src, int sx, int sy, int w, int h, int key); +HLL_UNIMPLEMENTED(void, DrawGraph, BlendDA_DAxSA, int dst, int dx, int dy, int src, int sx, int sy, int w, int h); +HLL_UNIMPLEMENTED(void, DrawGraph, SubDA_DAxSA, int dst, int dx, int dy, int src, int sx, int sy, int w, int h); +HLL_UNIMPLEMENTED(void, DrawGraph, BrightDestOnly, int dst, int x, int y, int w, int h, int rate); +HLL_UNIMPLEMENTED(void, DrawGraph, CopyTextureWrap, int dst, int dx, int dy, int dw, int dh, int src, int sx, int sy, int sw, int sh, int u, int v); +HLL_UNIMPLEMENTED(void, DrawGraph, CopyTextureWrapAlpha, int dst, int dx, int dy, int dw, int dh, int src, int sx, int sy, int sw, int sh, int u, int v, int alpha); +HLL_UNIMPLEMENTED(void, DrawGraph, CopyStretchBlend, int dst, int dx, int dy, int dw, int dh, int src, int sx, int sy, int sw, int sh, int alpha); +HLL_UNIMPLEMENTED(void, DrawGraph, CopyStretchBlendAMap, int dst, int dx, int dy, int dw, int dh, int src, int sx, int sy, int sw, int sh); +HLL_UNIMPLEMENTED(void, DrawGraph, CopyStretchInterp, int dst, int dx, int dy, int dw, int dh, int src, int sx, int sy, int sw, int sh); +HLL_UNIMPLEMENTED(void, DrawGraph, CopyStretchAMapInterp, int dst, int dx, int dy, int dw, int dh, int src, int sx, int sy, int sw, int sh); +HLL_WARN_UNIMPLEMENTED( , void, DrawGraph, SetFontName, struct string *text); +HLL_WARN_UNIMPLEMENTED(&EMPTY_STRING, struct string*, DrawGraph, GetFontName, void); +HLL_UNIMPLEMENTED(void, DrawGraph, CopyRotZoom2Bilinear, int dst, float cx, float cy, int src, float scx, float scy, float rot, float mag); +HLL_UNIMPLEMENTED(void, DrawGraph, CopyRotateY, int write, int dst, int src, int sx, int sy, int w, int h, float rot, float mag); +HLL_UNIMPLEMENTED(void, DrawGraph, CopyRotateYUseAMap, int write, int dst, int src, int sx, int sy, int w, int h, float rot, float mag); +HLL_UNIMPLEMENTED(void, DrawGraph, CopyRotateYFixL, int write, int dst, int src, int sx, int sy, int w, int h, float rot, float mag); +HLL_UNIMPLEMENTED(void, DrawGraph, CopyRotateYFixR, int write, int dst, int src, int sx, int sy, int w, int h, float rot, float mag); +HLL_UNIMPLEMENTED(void, DrawGraph, CopyRotateYFixLUseAMap, int write, int dst, int src, int sx, int sy, int w, int h, float rot, float mag); +HLL_UNIMPLEMENTED(void, DrawGraph, CopyRotateYFixRUseAMap, int write, int dst, int src, int sx, int sy, int w, int h, float rot, float mag); +HLL_UNIMPLEMENTED(void, DrawGraph, CopyRotateX, int write, int dst, int src, int sx, int sy, int w, int h, float rot, float mag); +HLL_UNIMPLEMENTED(void, DrawGraph, CopyRotateXUseAMap, int write, int dst, int src, int sx, int sy, int w, int h, float rot, float mag); +HLL_UNIMPLEMENTED(void, DrawGraph, CopyRotateXFixU, int write, int dst, int src, int sx, int sy, int w, int h, float rot, float mag); +HLL_UNIMPLEMENTED(void, DrawGraph, CopyRotateXFixD, int write, int dst, int src, int sx, int sy, int w, int h, float rot, float mag); +HLL_UNIMPLEMENTED(void, DrawGraph, CopyRotateXFixUUseAMap, int write, int dst, int src, int sx, int sy, int w, int h, float rot, float mag); +HLL_UNIMPLEMENTED(void, DrawGraph, CopyRotateXFixDUseAMap, int write, int dst, int src, int sx, int sy, int w, int h, float rot, float mag); +HLL_UNIMPLEMENTED(void, DrawGraph, CopyReverseUD, int dst, int dx, int dy, int src, int sx, int sy, int w, int h); +HLL_UNIMPLEMENTED(void, DrawGraph, CopyReverseAMapUD, int dst, int dx, int dy, int src, int sx, int sy, int w, int h); +HLL_UNIMPLEMENTED(void, DrawGraph, CopyWidthBlur, int dst, int dx, int dy, int src, int sx, int sy, int w, int h, int blur); +HLL_UNIMPLEMENTED(void, DrawGraph, CopyHeightBlur, int dst, int dx, int dy, int src, int sx, int sy, int w, int h, int blur); +HLL_UNIMPLEMENTED(void, DrawGraph, CopyAMapWidthBlur, int dst, int dx, int dy, int src, int sx, int sy, int w, int h, int blur); +HLL_UNIMPLEMENTED(void, DrawGraph, CopyAMapHeightBlur, int dst, int dx, int dy, int src, int sx, int sy, int w, int h, int blur); +HLL_UNIMPLEMENTED(void, DrawGraph, DrawLine, int dst, int x0, int y0, int x1, int y1, int r, int g, int b); +HLL_UNIMPLEMENTED(void, DrawGraph, DrawLineToAMap, int dst, int x0, int y0, int x1, int y1, int alpha); +HLL_UNIMPLEMENTED(void, DrawGraph, DrawPolygon, int dst, int tex, float x0, float y0, float z0, float u0, float v0, float x1, float y1, float z1, float u1, float v1, float x2, float y2, float z2, float u2, float v2); +HLL_UNIMPLEMENTED(void, DrawGraph, DrawColorPolygon, int dst, int tex, float x0, float y0, float z0, int r0, int g0, int b0, int a0, float x1, float y1, float z1, int r1, int g1, int b1, int a1, float x2, float y2, float z2, int r2, int g2, int b2, int a2); + +HLL_LIBRARY(DrawGraph, + HLL_EXPORT(Copy, DrawGraph_Copy), + HLL_EXPORT(CopyBright, DrawGraph_CopyBright), + HLL_EXPORT(CopyAMap, DrawGraph_CopyAMap), + HLL_EXPORT(CopySprite, DrawGraph_CopySprite), + HLL_EXPORT(CopyColorReverse, DrawGraph_CopyColorReverse), + HLL_EXPORT(CopyUseAMapUnder, DrawGraph_CopyUseAMapUnder), + HLL_EXPORT(CopyUseAMapBorder, DrawGraph_CopyUseAMapBorder), + HLL_EXPORT(CopyAMapMax, DrawGraph_CopyAMapMax), + HLL_EXPORT(CopyAMapMin, DrawGraph_CopyAMapMin), + HLL_EXPORT(Blend, DrawGraph_Blend), + HLL_EXPORT(BlendSrcBright, DrawGraph_BlendSrcBright), + HLL_EXPORT(BlendAddSatur, DrawGraph_BlendAddSatur), + HLL_EXPORT(BlendAMap, DrawGraph_BlendAMap), + HLL_EXPORT(BlendAMapSrcOnly, DrawGraph_BlendAMapSrcOnly), + HLL_EXPORT(BlendAMapColor, DrawGraph_BlendAMapColor), + HLL_EXPORT(BlendAMapColorAlpha, DrawGraph_BlendAMapColorAlpha), + HLL_EXPORT(BlendAMapAlpha, DrawGraph_BlendAMapAlpha), + HLL_EXPORT(BlendAMapBright, DrawGraph_BlendAMapBright), + HLL_EXPORT(BlendAMapAlphaSrcBright, DrawGraph_BlendAMapAlphaSrcBright), + HLL_EXPORT(BlendUseAMapColor, DrawGraph_BlendUseAMapColor), + HLL_EXPORT(BlendScreen, DrawGraph_BlendScreen), + HLL_EXPORT(BlendMultiply, DrawGraph_BlendMultiply), + HLL_EXPORT(BlendScreenAlpha, DrawGraph_BlendScreenAlpha), + HLL_EXPORT(Fill, DrawGraph_Fill), + HLL_EXPORT(FillAlphaColor, DrawGraph_FillAlphaColor), + HLL_EXPORT(FillAMap, DrawGraph_FillAMap), + HLL_EXPORT(FillAMapOverBorder, DrawGraph_FillAMapOverBorder), + HLL_EXPORT(FillAMapUnderBorder, DrawGraph_FillAMapUnderBorder), + HLL_EXPORT(FillAMapGradationUD, DrawGraph_FillAMapGradationUD), + HLL_EXPORT(FillScreen, DrawGraph_FillScreen), + HLL_EXPORT(FillMultiply, DrawGraph_FillMultiply), + HLL_EXPORT(SaturDP_DPxSA, DrawGraph_SaturDP_DPxSA), + HLL_EXPORT(ScreenDA_DAxSA, DrawGraph_ScreenDA_DAxSA), + HLL_EXPORT(AddDA_DAxSA, DrawGraph_AddDA_DAxSA), + HLL_EXPORT(SpriteCopyAMap, DrawGraph_SpriteCopyAMap), + HLL_EXPORT(BlendDA_DAxSA, DrawGraph_BlendDA_DAxSA), + HLL_EXPORT(SubDA_DAxSA, DrawGraph_SubDA_DAxSA), + HLL_EXPORT(BrightDestOnly, DrawGraph_BrightDestOnly), + HLL_EXPORT(CopyTextureWrap, DrawGraph_CopyTextureWrap), + HLL_EXPORT(CopyTextureWrapAlpha, DrawGraph_CopyTextureWrapAlpha), + HLL_EXPORT(CopyStretch, DrawGraph_CopyStretch), + HLL_EXPORT(CopyStretchBlend, DrawGraph_CopyStretchBlend), + HLL_EXPORT(CopyStretchBlendAMap, DrawGraph_CopyStretchBlendAMap), + HLL_EXPORT(CopyStretchAMap, DrawGraph_CopyStretchAMap), + HLL_EXPORT(CopyStretchInterp, DrawGraph_CopyStretchInterp), + HLL_EXPORT(CopyStretchAMapInterp, DrawGraph_CopyStretchAMapInterp), + HLL_EXPORT(CopyReduce, DrawGraph_CopyStretch), + HLL_EXPORT(CopyReduceAMap, DrawGraph_CopyStretchAMap), + HLL_EXPORT(DrawTextToPMap, DrawGraph_DrawTextToPMap), + HLL_EXPORT(DrawTextToAMap, DrawGraph_DrawTextToAMap), + HLL_EXPORT(SetFontSize, gfx_set_font_size), + HLL_EXPORT(SetFontName, DrawGraph_SetFontName), + HLL_EXPORT(SetFontWeight, gfx_set_font_weight), + HLL_EXPORT(SetFontUnderline, gfx_set_font_underline), + HLL_EXPORT(SetFontStrikeOut, gfx_set_font_strikeout), + HLL_EXPORT(SetFontSpace, gfx_set_font_space), + HLL_EXPORT(SetFontColor, DrawGraph_SetFontColor), + HLL_EXPORT(GetFontSize, gfx_get_font_size), + HLL_EXPORT(GetFontName, DrawGraph_GetFontName), + HLL_EXPORT(GetFontWeight, gfx_get_font_weight), + HLL_EXPORT(GetFontUnderline, gfx_get_font_underline), + HLL_EXPORT(GetFontStrikeOut, gfx_get_font_strikeout), + HLL_EXPORT(GetFontSpace, gfx_get_font_space), + HLL_EXPORT(GetFontColor, DrawGraph_GetFontColor), + HLL_EXPORT(CopyRotZoom, DrawGraph_CopyRotZoom), + HLL_EXPORT(CopyRotZoomAMap, DrawGraph_CopyRotZoomAMap), + HLL_EXPORT(CopyRotZoomUseAMap, DrawGraph_CopyRotZoomUseAMap), + HLL_EXPORT(CopyRotZoom2Bilinear, DrawGraph_CopyRotZoom2Bilinear), + HLL_EXPORT(CopyRotateY, DrawGraph_CopyRotateY), + HLL_EXPORT(CopyRotateYUseAMap, DrawGraph_CopyRotateYUseAMap), + HLL_EXPORT(CopyRotateYFixL, DrawGraph_CopyRotateYFixL), + HLL_EXPORT(CopyRotateYFixR, DrawGraph_CopyRotateYFixR), + HLL_EXPORT(CopyRotateYFixLUseAMap, DrawGraph_CopyRotateYFixLUseAMap), + HLL_EXPORT(CopyRotateYFixRUseAMap, DrawGraph_CopyRotateYFixRUseAMap), + HLL_EXPORT(CopyRotateX, DrawGraph_CopyRotateX), + HLL_EXPORT(CopyRotateXUseAMap, DrawGraph_CopyRotateXUseAMap), + HLL_EXPORT(CopyRotateXFixU, DrawGraph_CopyRotateXFixU), + HLL_EXPORT(CopyRotateXFixD, DrawGraph_CopyRotateXFixD), + HLL_EXPORT(CopyRotateXFixUUseAMap, DrawGraph_CopyRotateXFixUUseAMap), + HLL_EXPORT(CopyRotateXFixDUseAMap, DrawGraph_CopyRotateXFixDUseAMap), + HLL_EXPORT(CopyReverseLR, DrawGraph_CopyReverseLR), + HLL_EXPORT(CopyReverseUD, DrawGraph_CopyReverseUD), + HLL_EXPORT(CopyReverseAMapLR, DrawGraph_CopyReverseAMapLR), + HLL_EXPORT(CopyReverseAMapUD, DrawGraph_CopyReverseAMapUD), + HLL_EXPORT(CopyWidthBlur, DrawGraph_CopyWidthBlur), + HLL_EXPORT(CopyHeightBlur, DrawGraph_CopyHeightBlur), + HLL_EXPORT(CopyAMapWidthBlur, DrawGraph_CopyAMapWidthBlur), + HLL_EXPORT(CopyAMapHeightBlur, DrawGraph_CopyAMapHeightBlur), + HLL_EXPORT(DrawLine, DrawGraph_DrawLine), + HLL_EXPORT(DrawLineToAMap, DrawGraph_DrawLineToAMap), + HLL_EXPORT(GetPixelColor, sact_SP_GetPixelValue), + HLL_EXPORT(GetAlphaColor, DrawGraph_GetAlphaColor), + HLL_EXPORT(DrawPolygon, DrawGraph_DrawPolygon), + HLL_EXPORT(DrawColorPolygon, DrawGraph_DrawColorPolygon)); diff --git a/src/hll/DrawPluginManager.c b/src/hll/DrawPluginManager.c index 58cb689..c109003 100644 --- a/src/hll/DrawPluginManager.c +++ b/src/hll/DrawPluginManager.c @@ -16,11 +16,9 @@ #include "hll.h" -hll_warn_unimplemented(DrawPluginManager, Load, 1); -hll_warn_unimplemented(DrawPluginManager, IsLoad, 1); +HLL_WARN_UNIMPLEMENTED(1, int, DrawPluginManager, Load, struct string *plugin_name); +HLL_WARN_UNIMPLEMENTED(1, int, DrawPluginManager, IsLoad, struct string *plugin_name); -hll_deflib(DrawPluginManager) { - hll_export(Load), - hll_export(IsLoad), - NULL -}; +HLL_LIBRARY(DrawPluginManager, + HLL_EXPORT(Load, DrawPluginManager_Load), + HLL_EXPORT(IsLoad, DrawPluginManager_IsLoad)); diff --git a/src/hll/File.c b/src/hll/File.c index 670cf17..5b50c68 100644 --- a/src/hll/File.c +++ b/src/hll/File.c @@ -26,41 +26,40 @@ #include "system4.h" #include "system4/string.h" #include "vm/heap.h" +#include "vm/page.h" static FILE *current_file = NULL; static char *file_contents = NULL; static size_t file_size = 0; static size_t file_cursor = 0; -//int Open(string szName, int nType) -hll_defun(Open, args) +int File_Open(struct string *filename, int type) { const char *mode; - if (args[1].i == 1) { + if (type == 1) { mode = "r"; - } else if (args[1].i == 2) { + } else if (type == 2) { mode = "w"; } else { - WARNING("Unknown mode in File.Open: %d", args[1].i); - hll_return(0); + WARNING("Unknown mode in File.Open: %d", type); + return 0; } if (current_file) { WARNING("Previously opened file wasn't closed"); fclose(current_file); } - char *path = unix_path(hll_string_ref(args[0].i)->text); + char *path = unix_path(filename->text); current_file = fopen(path, mode); if (!current_file) { WARNING("Failed to open file '%s': %s", path, strerror(errno)); } free(path); - hll_return(!!current_file); + return !!current_file; } -//int Close() -hll_defun(Close, args) +int File_Close(void) { if (!current_file) { VM_ERROR("File.Close called, but no open file"); @@ -72,13 +71,12 @@ hll_defun(Close, args) file_contents = NULL; file_size = 0; file_cursor = 0; - hll_return(r); + return r; } -//int Read(ref struct pIVMStruct) -hll_defun(Read, args) +int File_Read(struct page **_page) { - struct page *page = heap_get_page(args[0].i); + struct page *page = *_page; if (page->type != STRUCT_PAGE) { VM_ERROR("File.Read of non-struct"); } @@ -97,7 +95,7 @@ hll_defun(Read, args) if (fread(file_contents, file_size, 1, current_file) != 1) { WARNING("File.Read failed (fread): %s", strerror(errno)); free(file_contents); - hll_return(0); + return 0; } file_contents[file_size] = '\0'; } @@ -106,81 +104,73 @@ hll_defun(Read, args) cJSON *json = cJSON_ParseWithOpts(file_contents+file_cursor, &end, false); if (!json) { WARNING("File.Read failed to parse JSON"); - hll_return(0); + return 0; } if (!cJSON_IsArray(json)) { WARNING("File.Read incorrect type in parsed JSON"); - hll_return(0); + return 0; } file_cursor = end - file_contents; json_load_page(page, json); cJSON_Delete(json); - hll_return(0); + return 1; } -//int Write(struct pIVMStruct) -hll_defun(Write, args) +int File_Write(struct page *page) { if (!current_file) { VM_ERROR("File.Write called, but no open file"); - hll_return(0); + return 0; } - cJSON *json = vm_value_to_json(AIN_STRUCT, args[0]); + cJSON *json = page_to_json(page); char *str = cJSON_Print(json); cJSON_Delete(json); if (fwrite(str, strlen(str), 1, current_file) != 1) { WARNING("File.Write failed (fwrite): %s", strerror(errno)); free(str); - hll_return(0); + return 0; } fflush(current_file); free(str); - hll_return(1); + return 1; } -//int Copy(string szSrcName, string szDstName) -hll_unimplemented(File, Copy); - -//int Delete(string szName) -hll_unimplemented(File, Delete); - /* - struct tagSaveDate { - int m_nYear; - int m_nMonth; - int m_nDay; - int m_nHour; - int m_nMinute; - int m_nSecond; - int m_nDayOfWeek; - }; +struct tagSaveDate { + int m_nYear; + int m_nMonth; + int m_nDay; + int m_nHour; + int m_nMinute; + int m_nSecond; + int m_nDayOfWeek; +}; */ -//int GetTime(string szName, ref struct pIVMStruct) -hll_defun(GetTime, args) +int File_GetTime(struct string *filename, struct page **page) { struct stat s; - char *path = unix_path(hll_string_ref(args[0].i)->text); - union vm_value *date = hll_struct_ref(args[1].i); + char *path = unix_path(filename->text); + union vm_value *date = (*page)->values; if (stat(path, &s) < 0) { WARNING("stat failed: %s", strerror(errno)); free(path); - hll_return(0); + return 0; } free(path); struct tm *tm = localtime(&s.st_mtime); if (!tm) { WARNING("localtime failed: %s", strerror(errno)); - hll_return(0); + return 0; } date[0].i = tm->tm_year; @@ -191,26 +181,24 @@ hll_defun(GetTime, args) date[5].i = tm->tm_sec; date[6].i = tm->tm_wday; - hll_return(1); + return 1; } -//int SetFind(string szName) -hll_unimplemented(File, SetFind); -//int GetFind(ref string szName) -hll_unimplemented(File, GetFind); -//int MakeDirectory(string szName) -hll_unimplemented(File, MakeDirectory); +HLL_UNIMPLEMENTED(int, File, Copy, struct string *src, struct string *dst); +HLL_UNIMPLEMENTED(int, File, Delete, struct string *name); +HLL_UNIMPLEMENTED(int, File, SetFind, struct string *name); +HLL_UNIMPLEMENTED(int, File, GetFind, struct string **name); +HLL_UNIMPLEMENTED(int, File, MakeDirectory, struct string *name); + +HLL_LIBRARY(File, + HLL_EXPORT(Open, File_Open), + HLL_EXPORT(Close, File_Close), + HLL_EXPORT(Read, File_Read), + HLL_EXPORT(Write, File_Write), + HLL_EXPORT(File, File_Copy), + HLL_EXPORT(File, File_Delete), + HLL_EXPORT(GetTime, File_GetTime), + HLL_EXPORT(File, File_SetFind), + HLL_EXPORT(File, File_GetFind), + HLL_EXPORT(File, File_MakeDirectory)); -hll_deflib(File) { - hll_export(Open), - hll_export(Close), - hll_export(Read), - hll_export(Write), - hll_export(Copy), - hll_export(Delete), - hll_export(GetTime), - hll_export(SetFind), - hll_export(GetFind), - hll_export(MakeDirectory), - NULL -}; diff --git a/src/hll/Math.c b/src/hll/Math.c index abec50b..aa147df 100644 --- a/src/hll/Math.c +++ b/src/hll/Math.c @@ -28,128 +28,78 @@ static inline float deg2rad(float deg) return deg * (M_PI / 180.0); } -hll_defun(Cos, args) +float Math_Cos(float x) { - hll_return(cosf(deg2rad(args[0].f))); + return cosf(deg2rad(x)); } -hll_defun(Sin, args) +float Math_Sin(float x) { - hll_return(sinf(deg2rad(args[0].f))); + return sinf(deg2rad(x)); } -hll_defun(Sqrt, args) +int Math_Min(int a, int b) { - hll_return(sqrtf(args[0].f)); + return a < b ? a : b; } -hll_defun(Atan, args) +float Math_MinF(float a, float b) { - hll_return(atanf(args[0].f)); + return a < b ? a : b; } -hll_defun(Atan2, args) +int Math_Max(int a, int b) { - hll_return(atan2f(args[0].f, args[1].f)); + return a > b ? a : b; } -hll_defun(Abs, args) +float Math_MaxF(float a, float b) { - hll_return(abs(args[0].i)); + return a > b ? a : b; } -hll_defun(AbsF, args) +void Math_Swap(int *a, int *b) { - hll_return(fabsf(args[0].f)); + int tmp = *a; + *a = *b; + *b = tmp; } -hll_defun(Pow, args) +void Math_SwapF(float *a, float *b) { - hll_return(powf(args[0].f, args[1].f)); + float tmp = *a; + *a = *b; + *b = tmp; } -hll_defun(SetSeed, args) -{ - srand(args[0].i); - hll_return(0); -} +HLL_UNIMPLEMENTED(void, Math, SetRandMode, int mode); +HLL_UNIMPLEMENTED(float, Math, RandF, void); +HLL_UNIMPLEMENTED(void, Math, RandTableInit, int num, int size); +HLL_UNIMPLEMENTED(int, Math, RandTable, int num); +HLL_UNIMPLEMENTED(void, Math, RandTable2Init, int num, struct page *array); +HLL_UNIMPLEMENTED(int, Math, RandTable2, int num); -hll_unimplemented(Math, SetRandMode) +HLL_LIBRARY(Math, + HLL_EXPORT(Cos, Math_Cos), + HLL_EXPORT(Sin, Math_Sin), + HLL_EXPORT(Sqrt, sqrtf), + HLL_EXPORT(Atan, atanf), + HLL_EXPORT(Atan2, atan2f), + HLL_EXPORT(Abs, abs), + HLL_EXPORT(AbsF, fabsf), + HLL_EXPORT(Pow, powf), + HLL_EXPORT(SetSeed, srand), + HLL_EXPORT(SetRandMode, Math_SetRandMode), + HLL_EXPORT(Rand, rand), + HLL_EXPORT(RandF, Math_RandF), + HLL_EXPORT(RandTableInit, Math_RandTableInit), + HLL_EXPORT(RandTable, Math_RandTable), + HLL_EXPORT(RandTable2Init, Math_RandTable2Init), + HLL_EXPORT(RandTable2, Math_RandTable2), + HLL_EXPORT(Min, Math_Min), + HLL_EXPORT(MinF, Math_MinF), + HLL_EXPORT(Max, Math_Max), + HLL_EXPORT(MaxF, Math_MaxF), + HLL_EXPORT(Swap, Math_Swap), + HLL_EXPORT(SwapF, Math_SwapF)); -hll_defun(Rand, args) -{ - hll_return(rand()); -} - -// TODO -hll_unimplemented(Math, RandF) -hll_unimplemented(Math, RandTableInit) -hll_unimplemented(Math, RandTable) -hll_unimplemented(Math, RandTable2Init) -hll_unimplemented(Math, RandTable2) - -hll_defun(Min, args) -{ - int a = args[0].i, b = args[1].i; - hll_return(a < b ? a : b); -} - -hll_defun(MinF, args) -{ - float a = args[0].f, b = args[1].f; - hll_return(a < b ? a : b); -} - -hll_defun(Max, args) -{ - int a = args[0].i, b = args[1].i; - hll_return(a > b ? a : b); -} - -hll_defun(MaxF, args) -{ - float a = args[0].f, b = args[1].f; - hll_return(a > b ? a : b); -} - -hll_defun(Swap, args) -{ - int tmp = *args[0].iref; - *args[0].iref = *args[1].iref; - *args[1].iref = tmp; - hll_return(0); -} - -hll_defun(SwapF, args) -{ - float tmp = *args[0].fref; - *args[0].fref = *args[1].fref; - *args[1].fref = tmp; - hll_return(0); -} - -hll_deflib(Math) { - hll_export(Cos), - hll_export(Sin), - hll_export(Sqrt), - hll_export(Atan), - hll_export(Atan2), - hll_export(Abs), - hll_export(AbsF), - hll_export(Pow), - hll_export(SetSeed), - hll_export(SetRandMode), - hll_export(Rand), - hll_export(RandF), - hll_export(RandTableInit), - hll_export(RandTable), - hll_export(RandTable2Init), - hll_export(RandTable2), - hll_export(Min), - hll_export(MinF), - hll_export(Max), - hll_export(MaxF), - hll_export(Swap), - hll_export(SwapF), - NULL -}; diff --git a/src/hll/MsgLogManager.c b/src/hll/MsgLogManager.c index 82f16ee..a2b1d66 100644 --- a/src/hll/MsgLogManager.c +++ b/src/hll/MsgLogManager.c @@ -16,27 +16,25 @@ #include "hll.h" -hll_warn_unimplemented(MsgLogManager, Numof, 0); -hll_warn_unimplemented(MsgLogManager, AddInt, 0); -hll_warn_unimplemented(MsgLogManager, AddString, 0); -hll_warn_unimplemented(MsgLogManager, GetType, 0); -hll_warn_unimplemented(MsgLogManager, GetInt, 0); -hll_warn_unimplemented(MsgLogManager, GetString, 0); -hll_warn_unimplemented(MsgLogManager, Save, 0); -hll_warn_unimplemented(MsgLogManager, Load, 0); -hll_warn_unimplemented(MsgLogManager, SetLineMax, 0); -hll_warn_unimplemented(MsgLogManager, GetInterface, 0); +HLL_WARN_UNIMPLEMENTED(0, int, MsgLogManager, Numof, void); +HLL_WARN_UNIMPLEMENTED( , void, MsgLogManager, AddInt, int type, int value); +HLL_WARN_UNIMPLEMENTED( , void, MsgLogManager, AddString, int type, struct string *str); +HLL_WARN_UNIMPLEMENTED(0, int, MsgLogManager, GetType, int index); +HLL_WARN_UNIMPLEMENTED(0, int, MsgLogManager, GetInt, int index); +HLL_WARN_UNIMPLEMENTED( , void, MsgLogManager, GetString, int index, struct string **str); +HLL_WARN_UNIMPLEMENTED(0, int, MsgLogManager, Save, struct string *filename); +HLL_WARN_UNIMPLEMENTED(0, int, MsgLogManager, Load, struct string *filename); +HLL_WARN_UNIMPLEMENTED( , void, MsgLogManager, SetLineMax, int line_max); +HLL_WARN_UNIMPLEMENTED(0, int, MsgLogManager, GetInterface, void); -hll_deflib(MsgLogManager) { - hll_export(Numof), - hll_export(AddInt), - hll_export(AddString), - hll_export(GetType), - hll_export(GetInt), - hll_export(GetString), - hll_export(Save), - hll_export(Load), - hll_export(SetLineMax), - hll_export(GetInterface), - NULL -}; +HLL_LIBRARY(MsgLogManager, + HLL_EXPORT(Numof, MsgLogManager_Numof), + HLL_EXPORT(AddInt, MsgLogManager_AddInt), + HLL_EXPORT(AddString, MsgLogManager_AddString), + HLL_EXPORT(GetType, MsgLogManager_GetType), + HLL_EXPORT(GetInt, MsgLogManager_GetInt), + HLL_EXPORT(GetString, MsgLogManager_GetString), + HLL_EXPORT(Save, MsgLogManager_Save), + HLL_EXPORT(Load, MsgLogManager_Load), + HLL_EXPORT(SetLineMax, MsgLogManager_SetLineMax), + HLL_EXPORT(GetInterface, MsgLogManager_GetInterface)); diff --git a/src/hll/MsgSkip.c b/src/hll/MsgSkip.c index 17f2dac..4bbe50a 100644 --- a/src/hll/MsgSkip.c +++ b/src/hll/MsgSkip.c @@ -18,48 +18,43 @@ #include "hll.h" static bool enabled = false; -//int Init(string szName) -hll_warn_unimplemented(MsgSkip, Init, 1); -//void UseFlag(int nUse) -hll_warn_unimplemented(MsgSkip, UseFlag, 0); +static int state = 0; -//void SetEnable(int nEnable) -hll_defun(SetEnable, args) +void MsgSkip_SetEnable(int enable) { - enabled = !!args[0].i; - hll_return(0); + enabled = !!enable; } -//void SetState(int nState) -hll_warn_unimplemented(MsgSkip, SetState, 0); -//void SetFlag(int nMsgNum) -hll_warn_unimplemented(MsgSkip, SetFlag, 0); - -//int GetEnable(void) -hll_defun(GetEnable, args) +int MsgSkip_GetEnable(void) { - hll_return(enabled); + return enabled; } -//int GetState(void) -hll_ignore_unimplemented(GetState, 0); -//int GetFlag(int nMsgNum) -hll_warn_unimplemented(MsgSkip, GetFlag, 0); -//int GetNumofMsg(void) -hll_warn_unimplemented(MsgSkip, GetNumofMsg, 0); -//int GetNumofFlag(void) -hll_warn_unimplemented(MsgSkip, GetNumofFlag, 0); +void MsgSkip_SetState(int _state) +{ + state = _state; +} -hll_deflib(MsgSkip) { - hll_export(Init), - hll_export(UseFlag), - hll_export(SetEnable), - hll_export(SetState), - hll_export(SetFlag), - hll_export(GetEnable), - hll_export(GetState), - hll_export(GetFlag), - hll_export(GetNumofMsg), - hll_export(GetNumofFlag), - NULL -}; +int MsgSkip_GetState(void) +{ + return state; +} + +HLL_WARN_UNIMPLEMENTED(1, int, MsgSkip, Init, struct string *name); +HLL_WARN_UNIMPLEMENTED( , void, MsgSkip, UseFlag, int use); +HLL_WARN_UNIMPLEMENTED( , void, MsgSkip, SetFlag, int msgnum); +HLL_WARN_UNIMPLEMENTED(0, int, MsgSkip, GetFlag, int msgnum); +HLL_WARN_UNIMPLEMENTED(0, int, MsgSkip, GetNumofMsg, void); +HLL_WARN_UNIMPLEMENTED(0, int, MsgSkip, GetNumofFlag, void); + +HLL_LIBRARY(MsgSkip, + HLL_EXPORT(Init, MsgSkip_Init), + HLL_EXPORT(UseFlag, MsgSkip_UseFlag), + HLL_EXPORT(SetEnable, MsgSkip_SetEnable), + HLL_EXPORT(SetState, MsgSkip_SetState), + HLL_EXPORT(SetFlag, MsgSkip_SetFlag), + HLL_EXPORT(GetEnable, MsgSkip_GetEnable), + HLL_EXPORT(GetState, MsgSkip_GetState), + HLL_EXPORT(GetFlag, MsgSkip_GetFlag), + HLL_EXPORT(GetNumofMsg, MsgSkip_GetNumofMsg), + HLL_EXPORT(GetNumofFlag, MsgSkip_GetNumofFlag)); diff --git a/src/hll/OutputLog.c b/src/hll/OutputLog.c index 40cd0ef..d15ce04 100644 --- a/src/hll/OutputLog.c +++ b/src/hll/OutputLog.c @@ -19,27 +19,23 @@ #include "system4/string.h" #include "system4/utfsjis.h" -hll_warn_unimplemented(OutputLog, Create, 0) - -hll_defun(Output, args) { - struct string *s = heap[args[1].i].s; +void OutputLog_Output(int handle, struct string *s) +{ char *u = sjis2utf(s->text, s->size); printf("%s", u); free(u); - hll_return(0); } -hll_warn_unimplemented(OutputLog, Clear, 0) -hll_warn_unimplemented(OutputLog, Save, 0) -hll_warn_unimplemented(OutputLog, EnableAutoSave, 0) -hll_warn_unimplemented(OutputLog, DisableAutoSave, 0) +HLL_WARN_UNIMPLEMENTED(0, int, OutputLog, Create, struct string *name); +HLL_WARN_UNIMPLEMENTED( , void, OutputLog, Clear, int handle); +HLL_WARN_UNIMPLEMENTED(0, int, OutputLog, Save, int handle, struct string *filename); +HLL_WARN_UNIMPLEMENTED(0, bool, OutputLog, EnableAutoSave, int handle, struct string *filename); +HLL_WARN_UNIMPLEMENTED(0, bool, OutputLog, DisableAutoSave, int handle); -hll_deflib(OutputLog) { - hll_export(Create), - hll_export(Output), - hll_export(Clear), - hll_export(Save), - hll_export(EnableAutoSave), - hll_export(DisableAutoSave), - NULL -}; +HLL_LIBRARY(OutputLog, + HLL_EXPORT(Create, OutputLog_Create), + HLL_EXPORT(Output, OutputLog_Output), + HLL_EXPORT(Clear, OutputLog_Clear), + HLL_EXPORT(Save, OutputLog_Save), + HLL_EXPORT(EnableAutoSave, OutputLog_EnableAutoSave), + HLL_EXPORT(DisableAutoSave, OutputLog_DisableAutoSave)); diff --git a/src/hll/PlayMovie.c b/src/hll/PlayMovie.c index d08dcf6..54a9df1 100644 --- a/src/hll/PlayMovie.c +++ b/src/hll/PlayMovie.c @@ -16,25 +16,17 @@ #include "hll.h" -// int Init() -hll_warn_unimplemented(PlayMovie, Init, 0); -// int Load(string pIFileName) -hll_unimplemented(PlayMovie, Load); -// int Play() -hll_unimplemented(PlayMovie, Play); -// void Stop() -hll_unimplemented(PlayMovie, Stop); -// int IsPlay() -hll_unimplemented(PlayMovie, IsPlay); -// void Release() -hll_unimplemented(PlayMovie, Release); +HLL_WARN_UNIMPLEMENTED(0, int, PlayMovie, Init, void); +HLL_UNIMPLEMENTED(int, PlayMovie, Load, struct string *filename); +HLL_UNIMPLEMENTED(int, PlayMovie, Play, void); +HLL_UNIMPLEMENTED(void, PlayMovie, Stop, void); +HLL_UNIMPLEMENTED(int, PlayMovie, IsPlay, void); +HLL_UNIMPLEMENTED(void, PlayMovie, Release, void); -hll_deflib(PlayMovie) { - hll_export(Init), - hll_export(Load), - hll_export(Play), - hll_export(Stop), - hll_export(IsPlay), - hll_export(Release), - NULL -}; +HLL_LIBRARY(PlayMovie, + HLL_EXPORT(Init, PlayMovie_Init), + HLL_EXPORT(Load, PlayMovie_Load), + HLL_EXPORT(Play, PlayMovie_Play), + HLL_EXPORT(Stop, PlayMovie_Stop), + HLL_EXPORT(IsPlay, PlayMovie_IsPlay), + HLL_EXPORT(Release, PlayMovie_Release)); diff --git a/src/hll/SACT2.c b/src/hll/SACT2.c index e343e78..8030194 100644 --- a/src/hll/SACT2.c +++ b/src/hll/SACT2.c @@ -23,691 +23,406 @@ #include "gfx/gfx.h" #include "sact.h" #include "system4.h" +#include "system4/ain.h" #include "system4/ald.h" #include "system4/cg.h" #include "system4/string.h" -// int Init(imain_system pIMainSystem, int nCGCacheSize) -hll_defun_inline(Init, sact_Init()); -// int Error(string strErr) -hll_unimplemented(SACT2, Error); -// int SetWP(int nCG) -hll_defun_inline(SetWP, sact_SetWP(a[0].i)); -// int SetWP_Color(int nR, int nG, int nB) -hll_defun_inline(SetWP_Color, (gfx_set_clear_color(a[0].i, a[1].i, a[2].i, 255), 1)); -// int WP_GetSP(int nSP) -hll_unimplemented(SACT2, WP_GetSP); -// int WP_SetSP(int nSP) -hll_unimplemented(SACT2, WP_SetSP); -// int GetScreenWidth(void) -hll_defun_inline(GetScreenWidth, config.view_width); -// int GetScreenHeight(void) -hll_defun_inline(GetScreenHeight, config.view_height); -// int GetMainSurfaceNumber(void) -hll_defun_inline(GetMainSurfaceNumber, -1); -// int Update(void) -hll_defun_inline(Update, sact_Update()); -// int Effect(int nType, int nTime, int nfKey) -hll_defun_inline(Effect, sact_Effect(a[0].i, a[1].i, a[2].i)); -// int EffectSetMask(int nCG) -hll_warn_unimplemented(SACT2, EffectSetMask, 1); -// int EffectSetMaskSP(int nSP) -hll_unimplemented(SACT2, EffectSetMaskSP); -// void QuakeScreen(int nAmplitudeX, int nAmplitudeY, int nTime, int nfKey) -hll_warn_unimplemented(SACT2, QuakeScreen, 0); -// void QUAKE_SET_CROSS(int nAmpX, int nAmpY) -hll_unimplemented(SACT2, QUAKE_SET_CROSS); -// void QUAKE_SET_ROTATION(int nAmp, int nCycle) -hll_unimplemented(SACT2, QUAKE_SET_ROTATION); -// int SP_GetUnuseNum(int nMin) -hll_defun_inline(SP_GetUnuseNum, sact_SP_GetUnuseNum(a[0].i)); -// int SP_Count(void) -hll_defun_inline(SP_Count, sact_SP_Count()); - -// int SP_Enum(ref array@int anSP) -hll_defun(SP_Enum, args) +int sact_GAME_MSG_GetNumOf(void) { - int size; - union vm_value *array = hll_array_ref(args[0].i, &size); - hll_return(sact_SP_Enum(array, size)); + return ain->nr_messages; } -// int SP_GetMaxZ(void) -hll_defun_inline(SP_GetMaxZ, sact_SP_GetMaxZ()); -// int SP_SetCG(int nSP, int nCG) -hll_defun_inline(SP_SetCG, sact_SP_SetCG(a[0].i, a[1].i)); -// int SP_SetCGFromFile(int nSP, string pIStringFileName) -hll_unimplemented(SACT2, SP_SetCGFromFile); -// int SP_SaveCG(int nSP, string pIStringFileName) -hll_unimplemented(SACT2, SP_SaveCG); -// int SP_Create(int nSP, int nWidth, int nHeight, int nR, int nG, int nB, int nBlendRate) -hll_defun_inline(SP_Create, sact_SP_Create(a[0].i, a[1].i, a[2].i, a[3].i, a[4].i, a[5].i, a[6].i)); -// int SP_CreatePixelOnly(int nSP, int nWidth, int nHeight) -hll_defun_inline(SP_CreatePixelOnly, sact_SP_CreatePixelOnly(a[0].i, a[1].i, a[2].i)); -// int SP_CreateCustom(int nSP) -hll_unimplemented(SACT2, SP_CreateCustom); -// int SP_Delete(int nSP) -hll_defun_inline(SP_Delete, sact_SP_Delete(a[0].i)); - -// int SP_SetPos(int nSP, int nX, int nY) -hll_defun(SP_SetPos, args) +void sact_IntToZenkaku(struct string **s, int value, int figures, int zero_pad) { - struct sact_sprite *sp = sact_get_sprite(args[0].i); - if (!sp) hll_return(1); - sp->rect.x = args[1].i; - sp->rect.y = args[2].i; - hll_return(1); -} - -// int SP_SetX(int nSP, int nX) -hll_defun(SP_SetX, args) -{ - struct sact_sprite *sp = sact_get_sprite(args[0].i); - if (!sp) hll_return(0); - sp->rect.x = args[1].i; - hll_return(1); -} - -// int SP_SetY(int nSP, int nY) -hll_defun(SP_SetY, args) -{ - struct sact_sprite *sp = sact_get_sprite(args[0].i); - if (!sp) hll_return(0); - sp->rect.y = args[1].i; - hll_return(1); -} - -// int SP_SetZ(int nSP, int nZ) -hll_defun_inline(SP_SetZ, sact_SP_SetZ(a[0].i, a[1].i)); - -// int SP_SetBlendRate(int nSP, int nBlendRate) -hll_defun_inline(SP_SetBlendRate, sact_SP_SetBlendRate(a[0].i, a[1].i)); - -// int SP_SetShow(int nSP, int nfShow) -hll_defun_inline(SP_SetShow, sact_SP_SetShow(a[0].i, a[1].i)); -// int SP_SetDrawMethod(int nSP, int nMethod) -hll_defun_inline(SP_SetDrawMethod, sact_SP_SetDrawMethod(a[0].i, a[1].i)); - -// int SP_IsUsing(int nSP) -hll_defun_inline(SP_IsUsing, sact_get_sprite(a[0].i) != NULL); - -// int SP_ExistAlpha(int nSP) -hll_defun_inline(SP_ExistAlpha, sact_SP_ExistsAlpha(a[0].i)); - -// int SP_GetPosX(int nSP) -hll_defun(SP_GetPosX, args) -{ - struct sact_sprite *sp = sact_get_sprite(args[0].i); - if (!sp) hll_return(0); - hll_return(sp->rect.x); -} - -// int SP_GetPosY(int nSP) -hll_defun(SP_GetPosY, args) -{ - struct sact_sprite *sp = sact_get_sprite(args[0].i); - if (!sp) hll_return(0); - hll_return(sp->rect.y); -} - -// int SP_GetWidth(int nSP) -hll_defun(SP_GetWidth, args) -{ - struct sact_sprite *sp = sact_get_sprite(args[0].i); - if (!sp) hll_return(0); - hll_return(sp->rect.w); -} - -// int SP_GetHeight(int nSP) -hll_defun(SP_GetHeight, args) -{ - struct sact_sprite *sp = sact_get_sprite(args[0].i); - if (!sp) hll_return(0); - hll_return(sp->rect.h); -} - -// int SP_GetZ(int nSP) -hll_defun(SP_GetZ, args) -{ - struct sact_sprite *sp = sact_get_sprite(args[0].i); - if (!sp) hll_return(0); - hll_return(sp->z); -} - -// int SP_GetBlendRate(int nSP) -hll_defun_inline(SP_GetBlendRate, sact_SP_GetBlendRate(a[0].i)); - -// int SP_GetShow(int nSP) -hll_defun(SP_GetShow, args) -{ - struct sact_sprite *sp = sact_get_sprite(args[0].i); - if (!sp) hll_return(0); - hll_return(sp->show); -} - -// int SP_GetDrawMethod(int nSP) -hll_defun_inline(SP_GetDrawMethod, sact_SP_GetDrawMethod(a[0].i)); - -// int SP_SetTextHome(int nSP, int nX, int nY) -hll_defun(SP_SetTextHome, args) -{ - struct sact_sprite *sp = sact_get_sprite(args[0].i); - if (!sp) hll_return(0); - sp->text.home = (Point) { .x = args[1].i, .y = args[2].i }; - hll_return(1); -} - -// int SP_SetTextLineSpace(int nSP, int nPx) -hll_defun(SP_SetTextLineSpace, args) -{ - struct sact_sprite *sp = sact_get_sprite(args[0].i); - if (!sp) hll_return(1); - sp->text.line_space = args[1].i; - hll_return(1); -} - -// int SP_SetTextCharSpace(int nSP, int nPx) -hll_defun(SP_SetTextCharSpace, args) -{ - struct sact_sprite *sp = sact_get_sprite(args[0].i); - if (!sp) hll_return(1); - sp->text.char_space = args[1].i; - hll_return(1); -} - -// int SP_SetTextPos(int nSP, int nX, int nY) -hll_defun(SP_SetTextPos, args) -{ - struct sact_sprite *sp = sact_get_sprite(args[0].i); - if (!sp) hll_return(0); - sp->text.pos = (Point) { .x = args[1].i, .y = args[2].i }; - hll_return(1); -} - -// int SP_TextDraw(int nSP, string text, struct tm) -hll_defun_inline(SP_TextDraw, sact_SP_TextDraw(a[0].i, heap[a[1].i].s, heap[a[2].i].page->values)); -// int SP_TextClear(int nSP) -hll_defun_inline(SP_TextClear, sact_SP_TextClear(a[0].i)); - -// int SP_TextHome(int nSP, int nTextSize) -hll_defun(SP_TextHome, args) -{ - struct sact_sprite *sp = sact_get_sprite(args[0].i); - if (!sp) hll_return(0); - // FIXME: do something with nTextSize - sp->text.pos = sp->text.home; - hll_return(1); -} - -// int SP_TextNewLine(int nSP, int nTextSize) -hll_defun(SP_TextNewLine, args) -{ - struct sact_sprite *sp = sact_get_sprite(args[0].i); - if (!sp) hll_return(0); - sp->text.pos = POINT(sp->text.home.x, sp->text.home.y + args[0].i); - hll_return(1); -} - -// int SP_TextBackSpace(int nSP) -hll_unimplemented(SACT2, SP_TextBackSpace); -// int SP_TextCopy(int nDstSP, int nSrcSP) -hll_defun_inline(SP_TextCopy, sact_SP_TextCopy(a[0].i, a[1].i)); - -// int SP_GetTextHomeX(int nSP) -hll_defun(SP_GetTextHomeX, args) -{ - struct sact_sprite *sp = sact_get_sprite(args[0].i); - if (!sp) hll_return(0); - hll_return(sp->text.home.x); -} - -// int SP_GetTextHomeY(int nSP) -hll_defun(SP_GetTextHomeY, args) -{ - struct sact_sprite *sp = sact_get_sprite(args[0].i); - if (!sp) hll_return(0); - hll_return(sp->text.home.y); -} - -// int SP_GetTextCharSpace(int nSP) -hll_defun(SP_GetTextCharSpace, args) -{ - struct sact_sprite *sp = sact_get_sprite(args[0].i); - if (!sp) hll_return(0); - hll_return(sp->text.char_space); -} - -// int SP_GetTextPosX(int nSP) -hll_defun(SP_GetTextPosX, args) -{ - struct sact_sprite *sp = sact_get_sprite(args[0].i); - if (!sp) hll_return(0); - hll_return(sp->text.pos.x); -} - -// int SP_GetTextPosY(int nSP) -hll_defun(SP_GetTextPosY, args) -{ - struct sact_sprite *sp = sact_get_sprite(args[0].i); - if (!sp) hll_return(0); - hll_return(sp->text.pos.y); -} - -// int SP_GetTextLineSpace(int nSP) -hll_defun(SP_GetTextLineSpace, args) -{ - struct sact_sprite *sp = sact_get_sprite(args[0].i); - if (!sp) hll_return(0); - hll_return(sp->text.line_space); -} -// int SP_IsPtIn(int nSP, int nX, int nY) -hll_defun_inline(SP_IsPtIn, sact_SP_IsPtIn(a[0].i, a[1].i, a[2].i)); - -// int SP_IsPtInRect(int nSP, int nX, int nY) -hll_defun(SP_IsPtInRect, args) -{ - struct sact_sprite *sp = sact_get_sprite(args[0].i); - Point p = { .x = args[1].i, .y = args[2].i }; - if (!sp) hll_return(0); - hll_return(!!SDL_PointInRect(&p, &sp->rect)); -} - -// int GAME_MSG_GetNumof(void) -hll_defun_inline(GAME_MSG_GetNumof, ain->nr_messages); -// void GAME_MSG_Get(int nIndex, ref string text) -hll_unimplemented(SACT2, GAME_MSG_Get); - -// void IntToZenkaku(ref string s, int nValue, int nFigures, int nfZeroPadding) -hll_defun(IntToZenkaku, args) -{ - int slot = args[0].i; - int val = args[1].i; - int fig = args[2].i; - bool zero_pad = args[3].i; - char buf[512]; int i; - - if (heap[slot].s) - free_string(heap[slot].s); - - i = int_to_cstr(buf, 1024, val, fig, zero_pad, true); - heap[slot].s = make_string(buf, i); - hll_return(0); -} - -// void IntToHankaku(ref string s, int nValue, int nFigures, int nfZeroPadding) -hll_defun(IntToHankaku, args) -{ - int slot = args[0].i; - int val = args[1].i; - int fig = args[2].i; - bool zero_pad = args[3].i; char buf[512]; - int i; - if (heap[slot].s) - free_string(heap[slot].s); - - i = int_to_cstr(buf, 1024, val, fig, zero_pad, false); - heap[slot].s = make_string(buf, i); - hll_return(0); + string_clear(*s); + i = int_to_cstr(buf, 512, value, figures, zero_pad, true); + string_append_cstr(s, buf, i); } -// int StringPopFront(ref string sDst, ref string sSrc) -hll_unimplemented(SACT2, StringPopFront); +void sact_IntToHankaku(struct string **s, int value, int figures, int zero_pad) +{ + int i; + char buf[512]; -// int Mouse_GetPos(ref int pnX, ref int pnY) -hll_defun(Mouse_GetPos, args) + string_clear(*s); + i = int_to_cstr(buf, 512, value, figures, zero_pad, false); + string_append_cstr(s, buf, i); +} + +int sact_Mouse_GetPos(int *x, int *y) { handle_events(); - mouse_get_pos(args[0].iref, args[1].iref); - hll_return(mouse_focus && keyboard_focus); + mouse_get_pos(x, y); + return mouse_focus && keyboard_focus; } -// int Mouse_SetPos(int nX, int nY) -hll_warn_unimplemented(SACT2, Mouse_SetPos, 1); -// void Mouse_ClearWheel(void) -hll_defun_inline(Mouse_ClearWheel, 0); - -// void Mouse_GetWheel(ref int pnForward, ref int pnBack) -hll_defun(Mouse_GetWheel, args) +void sact_Mouse_ClearWheel(void) { - //hll_unimplemented_warning(SACT2, Mouse_GetWheel); - *args[0].iref = 0; - *args[1].iref = 0; - hll_return(0); + // TODO } -// void Joypad_ClearKeyDownFlag(int nNum) -hll_defun_inline(Joypad_ClearKeyDownFlag, 0); -// int Joypad_IsKeyDown(int nNum, int nKey) -hll_defun_inline(Joypad_IsKeyDown, 0); -// int Joypad_GetNumof(void) -hll_unimplemented(SACT2, Joypad_GetNumof); -// void JoypadQuake_Set(int nNum, int nType, int nMagnitude) -hll_warn_unimplemented(SACT2, JoypadQuake_Set, 0); - -// bool Joypad_GetAnalogStickStatus(int nNum, int nType, ref float pfDegree, ref float pfPower) -hll_defun(Joypad_GetAnalogStickStatus, args) +void sact_Mouse_GetWheel(int *forward, int *back) { - hll_unimplemented_warning(SACT2, Joypad_GetAnalogStickStatus); - *args[2].fref = 0.0; - *args[3].fref = 0.0; - hll_return(1); + // TODO + *forward = 0; + *back = 0; } -// bool Joypad_GetDigitalStickStatus(int nNum, int nType, ref bool pbLeft, ref bool pbRight, ref bool pbUp, ref bool pbDown) -hll_defun(Joypad_GetDigitalStickStatus, args) +void sact_Joypad_ClearKeyDownFlag(int n) +{ + // TODO +} + +int sact_Joypad_IsKeyDown(int num, int key) +{ + return 0; // TODO +} + +bool sact_Joypad_GetAnalogStickStatus(int num, int type, float *degree, float *power) +{ + //hll_unimplemented_warning(SACT2, Joypad_GetAnalogStickStatus); + *degree = 0.0; + *power = 0.0; + return true; +} + +bool sact_Joypad_GetDigitalStickStatus(int num, int type, bool *left, bool *right, bool *up, bool *down) { //hll_unimplemented_warning(SACT2, Joypad_GetDigitalStickStatus); - *args[2].iref = 0; - *args[3].iref = 0; - *args[4].iref = 0; - *args[5].iref = 0; - hll_return(1); + *left = false; + *right = false; + *up = false; + *down = false; + return 1; } -// int Key_ClearFlag(void) -hll_defun_inline(Key_ClearFlag, (key_clear_flag(), 1)); -// int Key_IsDown(int nKeyCode) -hll_defun_inline(Key_IsDown, (handle_events(), key_is_down(a[0].i))); -// int Timer_Get(void) -hll_defun_inline(Timer_Get, vm_time()); -// int CG_IsExist(int nCG) -hll_defun(CG_IsExist, args) +int sact_Key_ClearFlag(void) { - hll_return(ald[ALDFILE_CG] && ald_data_exists(ald[ALDFILE_CG], args[0].i - 1)); + key_clear_flag(); + return 1; } -// int CG_GetMetrics(int nCG, ref struct cm) -hll_defun_inline(CG_GetMetrics, sact_CG_GetMetrics(a[0].i - 1, heap[a[1].i].page->values)); -// int CSV_Load(string pIStringFileName) -hll_unimplemented(SACT2, CSV_Load); -// int CSV_Save(void) -hll_unimplemented(SACT2, CSV_Save); -// int CSV_SaveAs(string pIStringFileName) -hll_unimplemented(SACT2, CSV_SaveAs); -// int CSV_CountLines(void) -hll_unimplemented(SACT2, CSV_CountLines); -// int CSV_CountColumns(void) -hll_unimplemented(SACT2, CSV_CountColumns); -// void CSV_Get(ref string pIString, int nLine, int nColumn) -hll_unimplemented(SACT2, CSV_Get); -// int CSV_Set(int nLine, int nColumn, string pIStringData) -hll_unimplemented(SACT2, CSV_Set); -// int CSV_GetInt(int nLine, int nColumn) -hll_unimplemented(SACT2, CSV_GetInt); -// void CSV_SetInt(int nLine, int nColumn, int nData) -hll_unimplemented(SACT2, CSV_SetInt); -// void CSV_Realloc(int nLines, int nColumns) -hll_unimplemented(SACT2, CSV_Realloc); -// int Music_IsExist(int nNum) -hll_defun_inline(Music_IsExist, audio_exists(AUDIO_MUSIC, a[0].i - 1)); -// int Music_Prepare(int nCh, int nNum) -hll_defun_inline(Music_Prepare, audio_prepare(AUDIO_MUSIC, a[0].i, a[1].i - 1)); -// int Music_Unprepare(int nCh) -hll_defun_inline(Music_Unprepare, audio_unprepare(AUDIO_MUSIC, a[0].i)); -// int Music_Play(int nCh) -hll_defun_inline(Music_Play, audio_play(AUDIO_MUSIC, a[0].i)); -// int Music_Stop(int nCh) -hll_defun_inline(Music_Stop, audio_stop(AUDIO_MUSIC, a[0].i)); -// int Music_IsPlay(int nCh) -hll_defun_inline(Music_IsPlay, audio_is_playing(AUDIO_MUSIC, a[0].i)); -// int Music_SetLoopCount(int nCh, int nCount) -hll_warn_unimplemented(SACT2, Music_SetLoopCount, 1); -// int Music_GetLoopCount(int nCh) -hll_warn_unimplemented(SACT2, Music_GetLoopCount, 1); -// int Music_SetLoopStartPos(int nCh, int dwPos) -hll_unimplemented(SACT2, Music_SetLoopStartPos); -// int Music_SetLoopEndPos(int nCh, int dwPos) -hll_unimplemented(SACT2, Music_SetLoopEndPos); -// int Music_Fade(int nCh, int nTime, int nVolume, int bStop) -hll_defun_inline(Music_Fade, audio_fade(AUDIO_MUSIC, a[0].i, a[1].i, a[2].i, a[3].i)); -// int Music_StopFade(int nCh) -hll_warn_unimplemented(SACT2, Music_StopFade, 1); -// int Music_IsFade(int nCh) -hll_warn_unimplemented(SACT2, Music_IsFade, 0); -// int Music_Pause(int nCh) -hll_warn_unimplemented(SACT2, Music_Pause, 1); -// int Music_Restart(int nCh) -hll_warn_unimplemented(SACT2, Music_Restart, 1); -// int Music_IsPause(int nCh) -hll_warn_unimplemented(SACT2, Music_IsPause, 1); -// int Music_GetPos(int nCh) -hll_warn_unimplemented(SACT2, Music_GetPos, 1); -// int Music_GetLength(int nCh) -hll_warn_unimplemented(SACT2, Music_GetLength, 1); -// int Music_GetSamplePos(int nCh) -hll_warn_unimplemented(SACT2, Music_GetSamplePos, 1); -// int Music_GetSampleLength(int nCh) -hll_warn_unimplemented(SACT2, Music_GetSampleLength, 1); -// int Music_Seek(int nCh, int dwPos) -hll_warn_unimplemented(SACT2, Music_Seek, 1); -// int Sound_IsExist(int nNum) -hll_defun_inline(Sound_IsExist, audio_exists(AUDIO_SOUND, a[0].i - 1)); -// int Sound_GetUnuseChannel(void) -hll_defun_inline(Sound_GetUnuseChannel, audio_get_unused_channel(AUDIO_SOUND)); -// int Sound_Prepare(int nCh, int nNum) -hll_defun_inline(Sound_Prepare, audio_prepare(AUDIO_SOUND, a[0].i, a[1].i - 1)); -// int Sound_Unprepare(int nCh) -hll_defun_inline(Sound_Unprepare, audio_unprepare(AUDIO_SOUND, a[0].i)); -// int Sound_Play(int nCh) -hll_defun_inline(Sound_Play, audio_play(AUDIO_SOUND, a[0].i)); -// int Sound_Stop(int nCh) -hll_defun_inline(Sound_Stop, audio_stop(AUDIO_SOUND, a[0].i)); -// int Sound_IsPlay(int nCh) -hll_defun_inline(Sound_IsPlay, audio_is_playing(AUDIO_SOUND, a[0].i)); -// int Sound_SetLoopCount(int nCh, int nCount) -hll_unimplemented(SACT2, Sound_SetLoopCount); -// int Sound_GetLoopCount(int nCh) -hll_unimplemented(SACT2, Sound_GetLoopCount); -// int Sound_Fade(int nCh, int nTime, int nVolume, int bStop) -hll_defun_inline(Sound_Fade, audio_fade(AUDIO_SOUND, a[0].i, a[1].i, a[2].i, a[3].i)); -// int Sound_StopFade(int nCh) -hll_unimplemented(SACT2, Sound_StopFade); -// int Sound_IsFade(int nCh) -hll_unimplemented(SACT2, Sound_IsFade); -// int Sound_GetPos(int nCh) -hll_unimplemented(SACT2, Sound_GetPos); -// int Sound_GetLength(int nCh) -hll_unimplemented(SACT2, Sound_GetLength); -// int Sound_ReverseLR(int nCh) -hll_warn_unimplemented(SACT2, Sound_ReverseLR, 1); -// int Sound_GetVolume(int nCh) -hll_unimplemented(SACT2, Sound_GetVolume); -// int Sound_GetTimeLength(int nCh) -hll_defun_inline(Sound_GetTimeLength, audio_get_time_length(AUDIO_SOUND, a[0].i)); -// int Sound_GetGroupNum(int nCh) -hll_unimplemented(SACT2, Sound_GetGroupNum); -// bool Sound_PrepareFromFile(int nCh, string szFileName) -hll_unimplemented(SACT2, Sound_PrepareFromFile); -// void System_GetDate(ref int pnYear, ref int pnMonth, ref int pnDay, ref int pnDayOfWeek) -hll_defun(System_GetDate, args) +int sact_Key_IsDown(int keycode) +{ + handle_events(); + return key_is_down(keycode); +} + +int sact_CG_IsExist(int cg_no) +{ + return ald[ALDFILE_CG] && ald_data_exists(ald[ALDFILE_CG], cg_no - 1); +} + +int sact_Music_IsExist(int n) +{ + return audio_exists(AUDIO_MUSIC, n - 1); +} + +int sact_Music_Prepare(int ch, int n) +{ + return audio_prepare(AUDIO_MUSIC, ch, n - 1); +} + +int sact_Music_Unprepare(int ch) +{ + return audio_unprepare(AUDIO_MUSIC, ch); +} + +int sact_Music_Play(int ch) +{ + return audio_play(AUDIO_MUSIC, ch); +} + +int sact_Music_Stop(int ch) +{ + return audio_stop(AUDIO_MUSIC, ch); +} + +int sact_Music_IsPlay(int ch) +{ + return audio_is_playing(AUDIO_MUSIC, ch); +} + +int sact_Music_Fade(int ch, int time, int volume, int stop) +{ + return audio_fade(AUDIO_MUSIC, ch, time, volume, stop); +} + +int sact_Sound_IsExist(int n) +{ + return audio_exists(AUDIO_SOUND, n - 1); +} + +int sact_Sound_GetUnuseChannel(void) +{ + return audio_get_unused_channel(AUDIO_SOUND); +} + +int sact_Sound_Prepare(int ch, int n) +{ + return audio_prepare(AUDIO_SOUND, ch, n - 1); +} + +int sact_Sound_Unprepare(int ch) +{ + return audio_unprepare(AUDIO_SOUND, ch); +} + +int sact_Sound_Play(int ch) +{ + return audio_play(AUDIO_SOUND, ch); +} + +int sact_Sound_Stop(int ch) +{ + return audio_stop(AUDIO_SOUND, ch); +} + +int sact_Sound_IsPlay(int ch) +{ + return audio_is_playing(AUDIO_SOUND, ch); +} + +int sact_Sound_Fade(int ch, int time, int volume, int stop) +{ + return audio_fade(AUDIO_SOUND, ch, time, volume, stop); +} + +int sact_Sound_GetTimeLength(int ch) +{ + return audio_get_time_length(AUDIO_SOUND, ch); +} + +void sact_System_GetDate(int *year, int *month, int *mday, int *wday) { time_t t = time(NULL); struct tm *tm = localtime(&t); - *args[0].iref = tm->tm_year; - *args[1].iref = tm->tm_mon; - *args[2].iref = tm->tm_mday; - *args[3].iref = tm->tm_wday; - hll_return(0); + *year = tm->tm_year; + *month = tm->tm_mon; + *mday = tm->tm_mday; + *wday = tm->tm_wday; } -// void System_GetTime(ref int pnHour, ref int pnMinute, ref int pnSecond, ref int pnMilliSeconds) -hll_defun(System_GetTime, args) +void sact_System_GetTime(int *hour, int *min, int *sec, int *ms) { time_t t = time(NULL); struct tm *tm = localtime(&t); struct timespec ts; clock_gettime(CLOCK_REALTIME, &ts); - *args[0].iref = tm->tm_hour; - *args[1].iref = tm->tm_min; - *args[2].iref = ts.tv_sec; - *args[3].iref = ts.tv_nsec / 1000000; - hll_return(0); + *hour = tm->tm_hour; + *min = tm->tm_min; + *sec = ts.tv_sec; + *ms = ts.tv_nsec / 1000000; } -// void CG_RotateRGB(int nDest, int nDx, int nDy, int nWidth, int nHeight, int nRotateType) -hll_unimplemented(SACT2, CG_RotateRGB); -// void CG_BlendAMapBin(int nDest, int nDx, int nDy, int nSrc, int nSx, int nSy, int nWidth, int nHeight, int nBorder) -hll_defun_inline(CG_BlendAMapBin, (gfx_copy_use_amap_border(sact_get_texture(a[0].i), a[1].i, a[2].i, sact_get_texture(a[3].i), a[4].i, a[5].i, a[6].i, a[7].i, a[8].i), 0)); -// void Debug_Pause(void) -hll_unimplemented(SACT2, Debug_Pause); -// void Debug_GetFuncStack(ref string sz, int nNest) -hll_unimplemented(SACT2, Debug_GetFuncStack); -// int SP_GetAMapValue(int nSP, int nX, int nY) -hll_defun_inline(SP_GetAMapValue, sact_SP_GetAMapValue(a[0].i, a[1].i, a[2].i)); -// bool SP_GetPixelValue(int nSP, int nX, int nY, ref int pnR, ref int pnG, ref int pnB) -hll_defun_inline(SP_GetPixelValue, sact_SP_GetPixelValue(a[0].i, a[1].i, a[2].i, a[3].iref, a[4].iref, a[5].iref)); -// int SP_SetBrightness(int nSP, int nBrightness) -hll_unimplemented(SACT2, SP_SetBrightness); -// int SP_GetBrightness(int nSP) -hll_unimplemented(SACT2, SP_GetBrightness); +void sact_CG_BlendAMapBin(int dst, int dx, int dy, int src, int sx, int sy, int w, int h, int border) +{ + gfx_copy_use_amap_border(sact_get_texture(dst), dx, dy, sact_get_texture(src), sx, sy, w, h, border); +} -hll_deflib(SACT2) { - hll_export(Init), - hll_export(Error), - hll_export(SetWP), - hll_export(SetWP_Color), - hll_export(WP_GetSP), - hll_export(WP_SetSP), - hll_export(GetScreenWidth), - hll_export(GetScreenHeight), - hll_export(GetMainSurfaceNumber), - hll_export(Update), - hll_export(Effect), - hll_export(EffectSetMask), - hll_export(EffectSetMaskSP), - hll_export(QuakeScreen), - hll_export(QUAKE_SET_CROSS), - hll_export(QUAKE_SET_ROTATION), - hll_export(SP_GetUnuseNum), - hll_export(SP_Count), - hll_export(SP_Enum), - hll_export(SP_GetMaxZ), - hll_export(SP_SetCG), - hll_export(SP_SetCGFromFile), - hll_export(SP_SaveCG), - hll_export(SP_Create), - hll_export(SP_CreatePixelOnly), - hll_export(SP_CreateCustom), - hll_export(SP_Delete), - hll_export(SP_SetPos), - hll_export(SP_SetX), - hll_export(SP_SetY), - hll_export(SP_SetZ), - hll_export(SP_SetBlendRate), - hll_export(SP_SetShow), - hll_export(SP_SetDrawMethod), - hll_export(SP_IsUsing), - hll_export(SP_ExistAlpha), - hll_export(SP_GetPosX), - hll_export(SP_GetPosY), - hll_export(SP_GetWidth), - hll_export(SP_GetHeight), - hll_export(SP_GetZ), - hll_export(SP_GetBlendRate), - hll_export(SP_GetShow), - hll_export(SP_GetDrawMethod), - hll_export(SP_SetTextHome), - hll_export(SP_SetTextLineSpace), - hll_export(SP_SetTextCharSpace), - hll_export(SP_SetTextPos), - hll_export(SP_TextDraw), - hll_export(SP_TextClear), - hll_export(SP_TextHome), - hll_export(SP_TextNewLine), - hll_export(SP_TextBackSpace), - hll_export(SP_TextCopy), - hll_export(SP_GetTextHomeX), - hll_export(SP_GetTextHomeY), - hll_export(SP_GetTextCharSpace), - hll_export(SP_GetTextPosX), - hll_export(SP_GetTextPosY), - hll_export(SP_GetTextLineSpace), - hll_export(SP_IsPtIn), - hll_export(SP_IsPtInRect), - hll_export(GAME_MSG_GetNumof), - hll_export(GAME_MSG_Get), - hll_export(IntToZenkaku), - hll_export(IntToHankaku), - hll_export(StringPopFront), - hll_export(Mouse_GetPos), - hll_export(Mouse_SetPos), - hll_export(Mouse_ClearWheel), - hll_export(Mouse_GetWheel), - hll_export(Joypad_ClearKeyDownFlag), - hll_export(Joypad_IsKeyDown), - hll_export(Joypad_GetNumof), - hll_export(JoypadQuake_Set), - hll_export(Joypad_GetAnalogStickStatus), - hll_export(Joypad_GetDigitalStickStatus), - hll_export(Key_ClearFlag), - hll_export(Key_IsDown), - hll_export(Timer_Get), - hll_export(CG_IsExist), - hll_export(CG_GetMetrics), - hll_export(CSV_Load), - hll_export(CSV_Save), - hll_export(CSV_SaveAs), - hll_export(CSV_CountLines), - hll_export(CSV_CountColumns), - hll_export(CSV_Get), - hll_export(CSV_Set), - hll_export(CSV_GetInt), - hll_export(CSV_SetInt), - hll_export(CSV_Realloc), - hll_export(Music_IsExist), - hll_export(Music_Prepare), - hll_export(Music_Unprepare), - hll_export(Music_Play), - hll_export(Music_Stop), - hll_export(Music_IsPlay), - hll_export(Music_SetLoopCount), - hll_export(Music_GetLoopCount), - hll_export(Music_SetLoopStartPos), - hll_export(Music_SetLoopEndPos), - hll_export(Music_Fade), - hll_export(Music_StopFade), - hll_export(Music_IsFade), - hll_export(Music_Pause), - hll_export(Music_Restart), - hll_export(Music_IsPause), - hll_export(Music_GetPos), - hll_export(Music_GetLength), - hll_export(Music_GetSamplePos), - hll_export(Music_GetSampleLength), - hll_export(Music_Seek), - hll_export(Sound_IsExist), - hll_export(Sound_GetUnuseChannel), - hll_export(Sound_Prepare), - hll_export(Sound_Unprepare), - hll_export(Sound_Play), - hll_export(Sound_Stop), - hll_export(Sound_IsPlay), - hll_export(Sound_SetLoopCount), - hll_export(Sound_GetLoopCount), - hll_export(Sound_Fade), - hll_export(Sound_StopFade), - hll_export(Sound_IsFade), - hll_export(Sound_GetPos), - hll_export(Sound_GetLength), - hll_export(Sound_ReverseLR), - hll_export(Sound_GetVolume), - hll_export(Sound_GetTimeLength), - hll_export(Sound_GetGroupNum), - hll_export(Sound_PrepareFromFile), - hll_export(System_GetDate), - hll_export(System_GetTime), - hll_export(CG_RotateRGB), - hll_export(CG_BlendAMapBin), - hll_export(Debug_Pause), - hll_export(Debug_GetFuncStack), - hll_export(SP_GetAMapValue), - hll_export(SP_GetPixelValue), - hll_export(SP_SetBrightness), - hll_export(SP_GetBrightness), - NULL -}; +HLL_UNIMPLEMENTED(int, SACT2, Error, struct string *err); +HLL_UNIMPLEMENTED(int, SACT2, WP_GetSP, int sp); +HLL_UNIMPLEMENTED(int, SACT2, WP_SetSP, int sp); +HLL_WARN_UNIMPLEMENTED(1, int, SACT2, EffectSetMask, int cg); +HLL_UNIMPLEMENTED(int, SACT2, EffectSetMaskSP, int sp); +HLL_WARN_UNIMPLEMENTED( , void, SACT2, QuakeScreen, int amp_x, int amp_y, int time, int key); +HLL_UNIMPLEMENTED(void, SACT2, QUAKE_SET_CROSS, int amp_x, int amp_y); +HLL_UNIMPLEMENTED(void, SACT2, QUAKE_SET_ROTATION, int amp, int cycle); +HLL_UNIMPLEMENTED(int, SACT2, SP_SetCGFromFile, int sp, struct string *filename); +HLL_UNIMPLEMENTED(int, SACT2, SP_SaveCG, int sp, struct string *filename); +HLL_UNIMPLEMENTED(int, SACT2, SP_CreateCustom, int sp); +HLL_UNIMPLEMENTED(int, SACT2, SP_TextBackSpace, int sp_no); +HLL_UNIMPLEMENTED(void, SACT2, GAME_MSG_Get, int index, struct string **text); +HLL_UNIMPLEMENTED(int, SACT2, StringPopFront, struct string **dst, struct string **src); +HLL_WARN_UNIMPLEMENTED(1, int, SACT2, Mouse_SetPos, int x, int y); +HLL_UNIMPLEMENTED(int, SACT2, Joypad_GetNumof, void); +HLL_WARN_UNIMPLEMENTED( , void, SACT2, JoypadQuake_Set, int num, int type, int magnitude); +HLL_UNIMPLEMENTED(int, SACT2, CSV_Load, struct string *filename); +HLL_UNIMPLEMENTED(int, SACT2, CSV_Save, void); +HLL_UNIMPLEMENTED(int, SACT2, CSV_SaveAs, struct string *filename); +HLL_UNIMPLEMENTED(int, SACT2, CSV_CountLines, void); +HLL_UNIMPLEMENTED(int, SACT2, CSV_CountColumns, void); +HLL_UNIMPLEMENTED(void, SACT2, CSV_Get, struct string **s, int line, int column); +HLL_UNIMPLEMENTED(int, SACT2, CSV_Set, int line, int column, struct string *data); +HLL_UNIMPLEMENTED(int, SACT2, CSV_GetInt, int line, int column); +HLL_UNIMPLEMENTED(void, SACT2, CSV_SetInt, int line, int column, int data); +HLL_UNIMPLEMENTED(void, SACT2, CSV_Realloc, int lines, int columns); +HLL_WARN_UNIMPLEMENTED(1, int, SACT2, Music_SetLoopCount, int ch, int count); +HLL_WARN_UNIMPLEMENTED(1, int, SACT2, Music_GetLoopCount, int ch); +HLL_UNIMPLEMENTED(int, SACT2, Music_SetLoopStartPos, int ch, int pos); +HLL_UNIMPLEMENTED(int, SACT2, Music_SetLoopEndPos, int ch, int pos); +HLL_WARN_UNIMPLEMENTED(1, int, SACT2, Music_StopFade, int ch); +HLL_WARN_UNIMPLEMENTED(0, int, SACT2, Music_IsFade, int ch); +HLL_WARN_UNIMPLEMENTED(1, int, SACT2, Music_Pause, int ch); +HLL_WARN_UNIMPLEMENTED(1, int, SACT2, Music_Restart, int ch); +HLL_WARN_UNIMPLEMENTED(1, int, SACT2, Music_IsPause, int ch); +HLL_WARN_UNIMPLEMENTED(1, int, SACT2, Music_GetPos, int ch); +HLL_WARN_UNIMPLEMENTED(1, int, SACT2, Music_GetLength, int ch); +HLL_WARN_UNIMPLEMENTED(1, int, SACT2, Music_GetSamplePos, int ch); +HLL_WARN_UNIMPLEMENTED(1, int, SACT2, Music_GetSampleLength, int ch); +HLL_WARN_UNIMPLEMENTED(1, int, SACT2, Music_Seek, int ch, int pos); +HLL_UNIMPLEMENTED(int, SACT2, Sound_SetLoopCount, int ch, int count); +HLL_UNIMPLEMENTED(int, SACT2, Sound_GetLoopCount, int ch); +HLL_UNIMPLEMENTED(int, SACT2, Sound_StopFade, int ch); +HLL_UNIMPLEMENTED(int, SACT2, Sound_IsFade, int ch); +HLL_UNIMPLEMENTED(int, SACT2, Sound_GetPos, int ch); +HLL_UNIMPLEMENTED(int, SACT2, Sound_GetLength, int ch); +HLL_WARN_UNIMPLEMENTED(1, int, SACT2, Sound_ReverseLR, int ch); +HLL_UNIMPLEMENTED(int, SACT2, Sound_GetVolume, int ch); +HLL_UNIMPLEMENTED(int, SACT2, Sound_GetGroupNum, int ch); +HLL_UNIMPLEMENTED(bool, SACT2, Sound_PrepareFromFile, int ch, struct string *filename); +HLL_UNIMPLEMENTED(void, SACT2, CG_RotateRGB, int dst, int dx, int dy, int w, int h, int rotate_type); +HLL_UNIMPLEMENTED(void, SACT2, Debug_Pause, void); +HLL_UNIMPLEMENTED(void, SACT2, Debug_GetFuncStack, struct string **s, int nest); +HLL_UNIMPLEMENTED(int, SACT2, SP_SetBrightness, int sp_no, int brightness); +HLL_UNIMPLEMENTED(int, SACT2, SP_GetBrightness, int sp_no); + +HLL_LIBRARY(SACT2, + HLL_EXPORT(Init, sact_Init), + HLL_EXPORT(Error, SACT2_Error), + HLL_EXPORT(SetWP, sact_SetWP), + HLL_EXPORT(SetWP_Color, sact_SetWP_Color), + HLL_EXPORT(WP_GetSP, SACT2_WP_GetSP), + HLL_EXPORT(WP_SetSP, SACT2_WP_SetSP), + HLL_EXPORT(GetScreenWidth, sact_GetScreenWidth), + HLL_EXPORT(GetScreenHeight, sact_GetScreenHeight), + HLL_EXPORT(GetMainSurfaceNumber, sact_GetMainSurfaceNumber), + HLL_EXPORT(Update, sact_Update), + HLL_EXPORT(Effect, sact_Effect), + HLL_EXPORT(EffectSetMask, SACT2_EffectSetMask), + HLL_EXPORT(EffectSetMaskSP, SACT2_EffectSetMaskSP), + HLL_EXPORT(QuakeScreen, SACT2_QuakeScreen), + HLL_EXPORT(QUAKE_SET_CROSS, SACT2_QUAKE_SET_CROSS), + HLL_EXPORT(QUAKE_SET_ROTATION, SACT2_QUAKE_SET_ROTATION), + HLL_EXPORT(SP_GetUnuseNum, sact_SP_GetUnuseNum), + HLL_EXPORT(SP_Count, sact_SP_Count), + HLL_EXPORT(SP_Enum, sact_SP_Enum), + HLL_EXPORT(SP_GetMaxZ, sact_SP_GetMaxZ), + HLL_EXPORT(SP_SetCG, sact_SP_SetCG), + HLL_EXPORT(SP_SetCGFromFile, SACT2_SP_SetCGFromFile), + HLL_EXPORT(SP_SaveCG, SACT2_SP_SaveCG), + HLL_EXPORT(SP_Create, sact_SP_Create), + HLL_EXPORT(SP_CreatePixelOnly, sact_SP_CreatePixelOnly), + HLL_EXPORT(SP_CreateCustom, SACT2_SP_CreateCustom), + HLL_EXPORT(SP_Delete, sact_SP_Delete), + HLL_EXPORT(SP_SetPos, sact_SP_SetPos), + HLL_EXPORT(SP_SetX, sact_SP_SetX), + HLL_EXPORT(SP_SetY, sact_SP_SetY), + HLL_EXPORT(SP_SetZ, sact_SP_SetZ), + HLL_EXPORT(SP_SetBlendRate, sact_SP_SetBlendRate), + HLL_EXPORT(SP_SetShow, sact_SP_SetShow), + HLL_EXPORT(SP_SetDrawMethod, sact_SP_SetDrawMethod), + HLL_EXPORT(SP_IsUsing, sact_SP_IsUsing), + HLL_EXPORT(SP_ExistAlpha, sact_SP_ExistsAlpha), + HLL_EXPORT(SP_GetPosX, sact_SP_GetPosX), + HLL_EXPORT(SP_GetPosY, sact_SP_GetPosY), + HLL_EXPORT(SP_GetWidth, sact_SP_GetWidth), + HLL_EXPORT(SP_GetHeight, sact_SP_GetHeight), + HLL_EXPORT(SP_GetZ, sact_SP_GetZ), + HLL_EXPORT(SP_GetBlendRate, sact_SP_GetBlendRate), + HLL_EXPORT(SP_GetShow, sact_SP_GetShow), + HLL_EXPORT(SP_GetDrawMethod, sact_SP_GetDrawMethod), + HLL_EXPORT(SP_SetTextHome, sact_SP_SetTextHome), + HLL_EXPORT(SP_SetTextLineSpace, sact_SP_SetTextLineSpace), + HLL_EXPORT(SP_SetTextCharSpace, sact_SP_SetTextCharSpace), + HLL_EXPORT(SP_SetTextPos, sact_SP_SetTextPos), + HLL_EXPORT(SP_TextDraw, sact_SP_TextDraw), + HLL_EXPORT(SP_TextClear, sact_SP_TextClear), + HLL_EXPORT(SP_TextHome, sact_SP_TextHome), + HLL_EXPORT(SP_TextNewLine, sact_SP_TextNewLine), + HLL_EXPORT(SP_TextBackSpace, SACT2_SP_TextBackSpace), + HLL_EXPORT(SP_TextCopy, sact_SP_TextCopy), + HLL_EXPORT(SP_GetTextHomeX, sact_SP_GetTextHomeX), + HLL_EXPORT(SP_GetTextHomeY, sact_SP_GetTextHomeY), + HLL_EXPORT(SP_GetTextCharSpace, sact_SP_GetTextCharSpace), + HLL_EXPORT(SP_GetTextPosX, sact_SP_GetTextPosX), + HLL_EXPORT(SP_GetTextPosY, sact_SP_GetTextPosY), + HLL_EXPORT(SP_GetTextLineSpace, sact_SP_GetTextLineSpace), + HLL_EXPORT(SP_IsPtIn, sact_SP_IsPtIn), + HLL_EXPORT(SP_IsPtInRect, sact_SP_IsPtInRect), + HLL_EXPORT(GAME_MSG_GetNumof, sact_GAME_MSG_GetNumOf), + HLL_EXPORT(GAME_MSG_Get, SACT2_GAME_MSG_Get), + HLL_EXPORT(IntToZenkaku, sact_IntToZenkaku), + HLL_EXPORT(IntToHankaku, sact_IntToHankaku), + HLL_EXPORT(StringPopFront, SACT2_StringPopFront), + HLL_EXPORT(Mouse_GetPos, sact_Mouse_GetPos), + HLL_EXPORT(Mouse_SetPos, SACT2_Mouse_SetPos), + HLL_EXPORT(Mouse_ClearWheel, sact_Mouse_ClearWheel), + HLL_EXPORT(Mouse_GetWheel, sact_Mouse_GetWheel), + HLL_EXPORT(Joypad_ClearKeyDownFlag, sact_Joypad_ClearKeyDownFlag), + HLL_EXPORT(Joypad_IsKeyDown, sact_Joypad_IsKeyDown), + HLL_EXPORT(Joypad_GetNumof, SACT2_Joypad_GetNumof), + HLL_EXPORT(JoypadQuake_Set, SACT2_JoypadQuake_Set), + HLL_EXPORT(Joypad_GetAnalogStickStatus, sact_Joypad_GetAnalogStickStatus), + HLL_EXPORT(Joypad_GetDigitalStickStatus, sact_Joypad_GetDigitalStickStatus), + HLL_EXPORT(Key_ClearFlag, sact_Key_ClearFlag), + HLL_EXPORT(Key_IsDown, sact_Key_IsDown), + HLL_EXPORT(Timer_Get, vm_time), + HLL_EXPORT(CG_IsExist, sact_CG_IsExist), + HLL_EXPORT(CG_GetMetrics, sact_CG_GetMetrics), + HLL_EXPORT(CSV_Load, SACT2_CSV_Load), + HLL_EXPORT(CSV_Save, SACT2_CSV_Save), + HLL_EXPORT(CSV_SaveAs, SACT2_CSV_SaveAs), + HLL_EXPORT(CSV_CountLines, SACT2_CSV_CountLines), + HLL_EXPORT(CSV_CountColumns, SACT2_CSV_CountColumns), + HLL_EXPORT(CSV_Get, SACT2_CSV_Get), + HLL_EXPORT(CSV_Set, SACT2_CSV_Set), + HLL_EXPORT(CSV_GetInt, SACT2_CSV_GetInt), + HLL_EXPORT(CSV_SetInt, SACT2_CSV_SetInt), + HLL_EXPORT(CSV_Realloc, SACT2_CSV_Realloc), + HLL_EXPORT(Music_IsExist, sact_Music_IsExist), + HLL_EXPORT(Music_Prepare, sact_Music_Prepare), + HLL_EXPORT(Music_Unprepare, sact_Music_Unprepare), + HLL_EXPORT(Music_Play, sact_Music_Play), + HLL_EXPORT(Music_Stop, sact_Music_Stop), + HLL_EXPORT(Music_IsPlay, sact_Music_IsPlay), + HLL_EXPORT(Music_SetLoopCount, SACT2_Music_SetLoopCount), + HLL_EXPORT(Music_GetLoopCount, SACT2_Music_GetLoopCount), + HLL_EXPORT(Music_SetLoopStartPos, SACT2_Music_SetLoopStartPos), + HLL_EXPORT(Music_SetLoopEndPos, SACT2_Music_SetLoopEndPos), + HLL_EXPORT(Music_Fade, sact_Music_Fade), + HLL_EXPORT(Music_StopFade, SACT2_Music_StopFade), + HLL_EXPORT(Music_IsFade, SACT2_Music_IsFade), + HLL_EXPORT(Music_Pause, SACT2_Music_Pause), + HLL_EXPORT(Music_Restart, SACT2_Music_Restart), + HLL_EXPORT(Music_IsPause, SACT2_Music_IsPause), + HLL_EXPORT(Music_GetPos, SACT2_Music_GetPos), + HLL_EXPORT(Music_GetLength, SACT2_Music_GetLength), + HLL_EXPORT(Music_GetSamplePos, SACT2_Music_GetSamplePos), + HLL_EXPORT(Music_GetSampleLength, SACT2_Music_GetSampleLength), + HLL_EXPORT(Music_Seek, SACT2_Music_Seek), + HLL_EXPORT(Sound_IsExist, sact_Sound_IsExist), + HLL_EXPORT(Sound_GetUnuseChannel, sact_Sound_GetUnuseChannel), + HLL_EXPORT(Sound_Prepare, sact_Sound_Prepare), + HLL_EXPORT(Sound_Unprepare, sact_Sound_Unprepare), + HLL_EXPORT(Sound_Play, sact_Sound_Play), + HLL_EXPORT(Sound_Stop, sact_Sound_Stop), + HLL_EXPORT(Sound_IsPlay, sact_Sound_IsPlay), + HLL_EXPORT(Sound_SetLoopCount, SACT2_Sound_SetLoopCount), + HLL_EXPORT(Sound_GetLoopCount, SACT2_Sound_GetLoopCount), + HLL_EXPORT(Sound_Fade, sact_Sound_Fade), + HLL_EXPORT(Sound_StopFade, SACT2_Sound_StopFade), + HLL_EXPORT(Sound_IsFade, SACT2_Sound_IsFade), + HLL_EXPORT(Sound_GetPos, SACT2_Sound_GetPos), + HLL_EXPORT(Sound_GetLength, SACT2_Sound_GetLength), + HLL_EXPORT(Sound_ReverseLR, SACT2_Sound_ReverseLR), + HLL_EXPORT(Sound_GetVolume, SACT2_Sound_GetVolume), + HLL_EXPORT(Sound_GetTimeLength, sact_Sound_GetTimeLength), + HLL_EXPORT(Sound_GetGroupNum, SACT2_Sound_GetGroupNum), + HLL_EXPORT(Sound_PrepareFromFile, SACT2_Sound_PrepareFromFile), + HLL_EXPORT(System_GetDate, sact_System_GetDate), + HLL_EXPORT(System_GetTime, sact_System_GetTime), + HLL_EXPORT(CG_RotateRGB, SACT2_CG_RotateRGB), + HLL_EXPORT(CG_BlendAMapBin, sact_CG_BlendAMapBin), + HLL_EXPORT(Debug_Pause, SACT2_Debug_Pause), + HLL_EXPORT(Debug_GetFuncStack, SACT2_Debug_GetFuncStack), + HLL_EXPORT(SP_GetAMapValue, sact_SP_GetAMapValue), + HLL_EXPORT(SP_GetPixelValue, sact_SP_GetPixelValue), + HLL_EXPORT(SP_SetBrightness, SACT2_SP_SetBrightness), + HLL_EXPORT(SP_GetBrightness, SACT2_SP_GetBrightness)); diff --git a/src/hll/SystemServiceEx.c b/src/hll/SystemServiceEx.c index b8dd1e8..f32d55d 100644 --- a/src/hll/SystemServiceEx.c +++ b/src/hll/SystemServiceEx.c @@ -17,29 +17,19 @@ #include "hll.h" #include "gfx/gfx.h" -// int GetUpdateResult() -hll_unimplemented(SystemServiceEx, GetUpdateResult); -// int GetOverlayPresent() -hll_warn_unimplemented(SystemServiceEx, GetOverlayPresent, 0); -// int GetOverlayActive() -hll_warn_unimplemented(SystemServiceEx, GetOverlayActive, 0); -// void UpdateMainSurface(int nX, int nY, int nWidth, int nHeight) -hll_unimplemented(SystemServiceEx, UpdateMainSurface); -// void SetWaitVSync(int bWaitVSync) -hll_defun_inline(SetWaitVSync, (gfx_set_wait_vsync(a[0].i), 0)); -// int GetHasPresented() -hll_unimplemented(SystemServiceEx, GetHasPresented); -// void ClearHasPresented() -hll_unimplemented(SystemServiceEx, ClearHasPresented); +HLL_UNIMPLEMENTED(int, SystemServiceEx, GetUpdateResult, void); +HLL_WARN_UNIMPLEMENTED(0, int, SystemServiceEx, GetOverlayPresent, void); +HLL_WARN_UNIMPLEMENTED(0, int, SystemServiceEx, GetOverlayActive, void); +HLL_UNIMPLEMENTED(void, SystemServiceEx, UpdateMainSurface, int x, int y, int w, int h); +HLL_UNIMPLEMENTED(int, SystemServiceEx, GetHasPresented, void); +HLL_UNIMPLEMENTED(void, SystemServiceEx, ClearHasPresented, void); -hll_deflib(SystemServiceEx) { - hll_export(GetUpdateResult), - hll_export(GetOverlayPresent), - hll_export(GetOverlayActive), - hll_export(UpdateMainSurface), - hll_export(SetWaitVSync), - hll_export(GetHasPresented), - hll_export(ClearHasPresented), - NULL -}; +HLL_LIBRARY(SystemServiceEx, + HLL_EXPORT(GetUpdateResult, SystemServiceEx_GetUpdateResult), + HLL_EXPORT(GetOverlayPresent, SystemServiceEx_GetOverlayPresent), + HLL_EXPORT(GetOverlayActive, SystemServiceEx_GetOverlayActive), + HLL_EXPORT(UpdateMainSurface, SystemServiceEx_UpdateMainSurface), + HLL_EXPORT(SetWaitVSync, gfx_set_wait_vsync), + HLL_EXPORT(GetHasPresented, SystemServiceEx_GetHasPresented), + HLL_EXPORT(ClearHasPresented, SystemServiceEx_ClearHasPresented)); diff --git a/src/hll/hll.h b/src/hll/hll.h index b517695..05ed8f3 100644 --- a/src/hll/hll.h +++ b/src/hll/hll.h @@ -22,70 +22,28 @@ */ #include "vm.h" -#include "vm/heap.h" -#include "vm/page.h" #include "system4.h" -#define hll_defun(fname, args) \ - static union vm_value _hllfun_ ## fname(possibly_unused union vm_value *args); \ - static struct static_hll_function _hllstruct_ ## fname = { \ - .name = #fname, \ - .fun = _hllfun_ ## fname \ - }; \ - static union vm_value _hllfun_ ## fname(possibly_unused union vm_value *args) - -#define hll_defun_inline(fname, expr) \ - hll_defun(fname, a) { hll_return(expr); } - -#define hll_unimplemented(libname, fname) \ - hll_defun(fname, args) { \ +#define HLL_UNIMPLEMENTED(rtype, libname, fname, ...) \ + static rtype libname ## _ ## fname(__VA_ARGS__) { \ VM_ERROR("Unimplemented HLL function: " #libname "." #fname); \ } -#define hll_unimplemented_warning(libname, fname) \ - WARNING("Unimplemented HLL function: " #libname "." #fname) - -#define hll_warn_unimplemented(libname, fname, rval) \ - hll_defun(fname, args) { \ - hll_unimplemented_warning(libname, fname); \ - hll_return(rval); \ +#define HLL_WARN_UNIMPLEMENTED(rval, rtype, libname, fname, ...)\ + static rtype libname ## _ ## fname(__VA_ARGS__) { \ + WARNING("Unimplemented HLL function: " #libname "." #fname); \ + return rval; \ } -#define hll_ignore_unimplemented(fname, rval) hll_defun_inline(fname, rval) +#define HLL_EXPORT(fname, funptr) { .name = #fname, .fun = funptr } -#define hll_export(fname) &_hllstruct_ ## fname - -#define hll_deflib(lname, ...) \ - static struct static_hll_function *_lib_ ## lname[]; \ - struct static_library lib_ ## lname = { \ - .name = #lname, \ - .functions = _lib_ ## lname \ - }; \ - static struct static_hll_function *_lib_ ## lname[] = - -#define hll_return(v) return vm_value_cast(v) - -static inline union vm_value *hll_struct_ref(int pageno) -{ - if (pageno < 0 || heap[pageno].type != VM_PAGE || !heap[pageno].page || heap[pageno].page->type != STRUCT_PAGE) - return NULL; - return heap[pageno].page->values; -} - -static inline union vm_value *hll_array_ref(int pageno, int *size) -{ - if (pageno < 0 || heap[pageno].type != VM_PAGE || !heap[pageno].page || heap[pageno].page->type != ARRAY_PAGE) - return NULL; - if (size) - *size = heap[pageno].page->nr_vars; - return heap[pageno].page->values; -} - -static inline struct string *hll_string_ref(int slot) -{ - if (slot < 0 || heap[slot].type != VM_STRING) - return NULL; - return heap[slot].s; -} +#define HLL_LIBRARY(lname, ...) \ + struct static_library lib_ ## lname = { \ + .name = #lname, \ + .functions = { \ + __VA_ARGS__, \ + { .name = NULL, .fun = NULL } \ + } \ + } #endif /* SYSTEM4_HLL_H */ diff --git a/src/meson.build b/src/meson.build index 59c0c28..fdf7280 100644 --- a/src/meson.build +++ b/src/meson.build @@ -14,6 +14,7 @@ xsystem4 = ['audio.c', 'cJSON.c', 'draw.c', 'effect.c', + 'ffi.c', 'file.c', 'format.c', 'heap.c', @@ -45,7 +46,7 @@ xsystem4 = ['audio.c', 'hll/SystemServiceEx.c', ] -xsystem4_deps = [libm, zlib, sdl2, sdl2ttf, sdl2mixer, gl, glew] +xsystem4_deps = [libm, zlib, sdl2, sdl2ttf, sdl2mixer, ffi, gl, glew] if chibi.found() xsystem4_deps += chibi xsystem4 += 'debugger.c' diff --git a/src/resume.c b/src/resume.c index 3cab86b..7cd1f9e 100644 --- a/src/resume.c +++ b/src/resume.c @@ -54,7 +54,7 @@ static cJSON *value_to_json(union vm_value v) return cJSON_CreateNumber(v.li); } -static cJSON *page_to_json(struct page *page) +static cJSON *resume_page_to_json(struct page *page) { if (!page) return cJSON_CreateNull(); @@ -89,7 +89,7 @@ static cJSON *heap_to_json(void) cJSON_AddItemToArray(item, cJSON_CreateNumber(heap[i].ref)); switch (heap[i].type) { case VM_PAGE: - cJSON_AddItemToArray(item, page_to_json(heap[i].page)); + cJSON_AddItemToArray(item, resume_page_to_json(heap[i].page)); break; case VM_STRING: cJSON_AddItemToArray(item, cJSON_CreateString(heap[i].s->text)); diff --git a/src/sact_graphics.c b/src/sact_graphics.c index 88f5303..a15b5b0 100644 --- a/src/sact_graphics.c +++ b/src/sact_graphics.c @@ -24,6 +24,7 @@ #include "system4/string.h" #include "system4/utfsjis.h" #include "vm.h" +#include "vm/page.h" static struct sact_sprite *create_sprite(int sp_no, int width, int height, int r, int g, int b, int a); @@ -99,7 +100,7 @@ static void realloc_sprite_table(int n) memset(sprites + old_nr_sprites, 0, sizeof(struct sact_sprite*) * (nr_sprites - old_nr_sprites)); } -int sact_Init(void) +int sact_Init(possibly_unused void *_, possibly_unused int cg_cache_size) { gfx_init(); gfx_font_init(); @@ -135,6 +136,27 @@ int sact_SetWP(int cg_no) return 1; } +int sact_SetWP_Color(int r, int g, int b) +{ + gfx_set_clear_color(r, g, b, 255); + return 1; +} + +int sact_GetScreenWidth(void) +{ + return config.view_width; +} + +int sact_GetScreenHeight(void) +{ + return config.view_height; +} + +int sact_GetMainSurfaceNumber(void) +{ + return -1; +} + void sact_render_scene(void) { gfx_clear(); @@ -184,12 +206,13 @@ int sact_SP_Count(void) return count; } -int sact_SP_Enum(union vm_value *array, int size) +int sact_SP_Enum(struct page **array) { int count = 0; + int size = (*array)->nr_vars; for (int i = 0; i < nr_sprites && count < size; i++) { if (sprites[i]) { - array[count++].i = i; + (*array)->values[count++].i = i; } } return count; @@ -262,6 +285,31 @@ int sact_SP_Delete(int sp_no) return 1; } +int sact_SP_SetPos(int sp_no, int x, int y) +{ + struct sact_sprite *sp = sact_get_sprite(sp_no); + if (!sp) return 1; + sp->rect.x = x; + sp->rect.y = y; + return 1; +} + +int sact_SP_SetX(int sp_no, int x) +{ + struct sact_sprite *sp = sact_get_sprite(sp_no); + if (!sp) return 0; + sp->rect.x = x; + return 1; +} + +int sact_SP_SetY(int sp_no, int y) +{ + struct sact_sprite *sp = sact_get_sprite(sp_no); + if (!sp) return 0; + sp->rect.y = y; + return 1; +} + int sact_SP_SetZ(int sp_no, int z) { struct sact_sprite *sp = sact_get_sprite(sp_no); @@ -322,6 +370,11 @@ int sact_SP_GetDrawMethod(int sp_no) return t->draw_method; } +int sact_SP_IsUsing(int sp_no) +{ + return sact_get_sprite(sp_no) != NULL; +} + int sact_SP_ExistsAlpha(int sp_no) { struct sact_sprite *sp = sact_get_sprite(sp_no); @@ -329,6 +382,80 @@ int sact_SP_ExistsAlpha(int sp_no) return sp->texture.has_alpha; } +int sact_SP_GetPosX(int sp_no) +{ + struct sact_sprite *sp = sact_get_sprite(sp_no); + if (!sp) return 0; + return sp->rect.x; +} + +int sact_SP_GetPosY(int sp_no) +{ + struct sact_sprite *sp = sact_get_sprite(sp_no); + if (!sp) return 0; + return sp->rect.y; +} + +int sact_SP_GetWidth(int sp_no) +{ + struct sact_sprite *sp = sact_get_sprite(sp_no); + if (!sp) return 0; + return sp->rect.w; +} + +int sact_SP_GetHeight(int sp_no) +{ + struct sact_sprite *sp = sact_get_sprite(sp_no); + if (!sp) return 0; + return sp->rect.h; +} + +int sact_SP_GetZ(int sp_no) +{ + struct sact_sprite *sp = sact_get_sprite(sp_no); + if (!sp) return 0; + return sp->z; +} + +int sact_SP_GetShow(int sp_no) +{ + struct sact_sprite *sp = sact_get_sprite(sp_no); + if (!sp) return 0; + return sp->show; +} + +int sact_SP_SetTextHome(int sp_no, int x, int y) +{ + struct sact_sprite *sp = sact_get_sprite(sp_no); + if (!sp) return 0; + sp->text.home = (Point) { .x = x, .y = y }; + return 1; +} + +int sact_SP_SetTextLineSpace(int sp_no, int px) +{ + struct sact_sprite *sp = sact_get_sprite(sp_no); + if (!sp) return 1; + sp->text.line_space = px; + return 1; +} + +int sact_SP_SetTextCharSpace(int sp_no, int px) +{ + struct sact_sprite *sp = sact_get_sprite(sp_no); + if (!sp) return 1; + sp->text.char_space = px; + return 1; +} + +int sact_SP_SetTextPos(int sp_no, int x, int y) +{ + struct sact_sprite *sp = sact_get_sprite(sp_no); + if (!sp) return 0; + sp->text.pos = (Point) { .x = x, .y = y }; + return 1; +} + static void init_text_metrics(struct text_metrics *tm, union vm_value *_tm) { *tm = (struct text_metrics) { @@ -354,14 +481,14 @@ static void init_text_metrics(struct text_metrics *tm, union vm_value *_tm) }; } -int sact_SP_TextDraw(int sp_no, struct string *text, union vm_value *_tm) +int sact_SP_TextDraw(int sp_no, struct string *text, struct page *_tm) { struct text_metrics tm; struct sact_sprite *sp = sact_get_sprite(sp_no); if (!sp) return 0; - init_text_metrics(&tm, _tm); + init_text_metrics(&tm, _tm->values); if (!sp->text.texture.handle) { SDL_Color c; @@ -390,6 +517,23 @@ int sact_SP_TextClear(int sp_no) return 1; } +int sact_SP_TextHome(int sp_no, possibly_unused int size) +{ + struct sact_sprite *sp = sact_get_sprite(sp_no); + if (!sp) return 0; + // FIXME: do something with nTextSize + sp->text.pos = sp->text.home; + return 1; +} + +int sact_SP_TextNewLine(int sp_no, int size) +{ + struct sact_sprite *sp = sact_get_sprite(sp_no); + if (!sp) return 0; + sp->text.pos = POINT(sp->text.home.x, sp->text.home.y + size); + return 1; +} + int sact_SP_TextCopy(int dno, int sno) { struct sact_sprite *dsp = sact_get_sprite(dno); @@ -418,6 +562,48 @@ int sact_SP_TextCopy(int dno, int sno) return 1; } +int sact_SP_GetTextHomeX(int sp_no) +{ + struct sact_sprite *sp = sact_get_sprite(sp_no); + if (!sp) return 0; + return sp->text.home.x; +} + +int sact_SP_GetTextHomeY(int sp_no) +{ + struct sact_sprite *sp = sact_get_sprite(sp_no); + if (!sp) return 0; + return sp->text.home.y; +} + +int sact_SP_GetTextCharSpace(int sp_no) +{ + struct sact_sprite *sp = sact_get_sprite(sp_no); + if (!sp) return 0; + return sp->text.char_space; +} + +int sact_SP_GetTextPosX(int sp_no) +{ + struct sact_sprite *sp = sact_get_sprite(sp_no); + if (!sp) return 0; + return sp->text.pos.x; +} + +int sact_SP_GetTextPosY(int sp_no) +{ + struct sact_sprite *sp = sact_get_sprite(sp_no); + if (!sp) return 0; + return sp->text.pos.y; +} + +int sact_SP_GetTextLineSpace(int sp_no) +{ + struct sact_sprite *sp = sact_get_sprite(sp_no); + if (!sp) return 0; + return sp->text.line_space; +} + int sact_SP_IsPtIn(int sp_no, int x, int y) { Point p = POINT(x, y); @@ -431,10 +617,19 @@ int sact_SP_IsPtIn(int sp_no, int x, int y) return !!c.a; } -int sact_CG_GetMetrics(int cg_no, union vm_value *cgm) +int sact_SP_IsPtInRect(int sp_no, int x, int y) { + struct sact_sprite *sp = sact_get_sprite(sp_no); + Point p = { .x = x, .y = y }; + if (!sp) return 0; + return !!SDL_PointInRect(&p, &sp->rect); +} + +int sact_CG_GetMetrics(int cg_no, struct page **page) +{ + union vm_value *cgm = (*page)->values; struct cg_metrics metrics; - if (!cg_get_metrics(ald[ALDFILE_CG], cg_no, &metrics)) + if (!cg_get_metrics(ald[ALDFILE_CG], cg_no - 1, &metrics)) return 0; cgm[0].i = metrics.w; cgm[1].i = metrics.h; diff --git a/src/savedata.c b/src/savedata.c index 9a20e82..8b9a43b 100644 --- a/src/savedata.c +++ b/src/savedata.c @@ -36,9 +36,8 @@ static int current_global; free(str); \ } -static cJSON *page_to_json(int index) +cJSON *page_to_json(struct page *page) { - struct page *page = heap_get_page(index); if (!page) return cJSON_CreateNull(); @@ -66,7 +65,7 @@ cJSON *vm_value_to_json(enum ain_data_type type, union vm_value val) return cJSON_CreateString(heap[val.i].s->text); case AIN_STRUCT: case AIN_ARRAY_TYPE: - return page_to_json(val.i); + return page_to_json(heap_get_page(val.i)); case AIN_REF_TYPE: return cJSON_CreateNumber(-1); default: diff --git a/src/string.c b/src/string.c index 22d9eba..9b5b863 100644 --- a/src/string.c +++ b/src/string.c @@ -235,6 +235,12 @@ void string_erase(struct string **s, int index) (*s)->text[(*s)->size] = '\0'; } +void string_clear(struct string *s) +{ + s->size = 0; + s->text[0] = '\0'; +} + int string_find(const struct string *haystack, const struct string *needle) { int c = 0; diff --git a/src/vm.c b/src/vm.c index a0afbe8..15ddd95 100644 --- a/src/vm.c +++ b/src/vm.c @@ -36,17 +36,10 @@ #include "vm/page.h" #define INITIAL_STACK_SIZE 4096 -#define HLL_MAX_ARGS 64 // When the IP is set to VM_RETURN, the VM halts #define VM_RETURN 0xFFFFFFFF -struct hll_function { - union vm_value (*fun)(union vm_value *_args); -}; - -static struct hll_function **libraries; - /* * NOTE: The current implementation is a simple bytecode interpreter. * System40.exe uses a JIT compiler, and we should too. @@ -314,50 +307,6 @@ void vm_call(int fno, int struct_page) instr_ptr = saved_ip; } -static void hll_call(int libno, int fno) -{ - struct ain_hll_function *f = &ain->libraries[libno].functions[fno]; - - if (!libraries[libno]) - VM_ERROR("Unimplemented HLL function: %s.%s", ain->libraries[libno].name, f->name); - - struct hll_function *fun = &libraries[libno][fno]; - if (!fun->fun) - VM_ERROR("Unimplemented HLL function: %s.%s", ain->libraries[libno].name, f->name); - - union vm_value args[HLL_MAX_ARGS]; - for (int i = f->nr_arguments - 1; i >= 0; i--) { - int pageno, varno; - switch(f->arguments[i].data_type) { - case AIN_REF_INT: - case AIN_REF_BOOL: - case AIN_REF_FLOAT: - stack_ptr -= 2; - pageno = stack[stack_ptr].i; - varno = stack[stack_ptr+1].i; - args[i].ref = &heap[pageno].page->values[varno]; - break; - default: - stack_ptr--; - args[i] = stack[stack_ptr]; - } - } - union vm_value r = fun->fun(args); - for (int i = 0; i < f->nr_arguments; i++) { - // XXX: We don't increase the ref count when passing ref arguments to HLL - // functions, so we need to avoid decreasing it via variable_fini - switch (f->arguments[i].data_type) { - case AIN_REF_TYPE: - break; - default: - variable_fini(stack[stack_ptr + i], f->arguments[i].data_type); - break; - } - } - if (f->data_type != AIN_VOID) - stack_push(r); -} - static void function_return(void) { heap_unref(call_stack[call_stack_ptr-1].page_slot); @@ -1534,79 +1483,6 @@ static void vm_execute(void) } } -extern struct static_library lib_ACXLoader; -extern struct static_library lib_AliceLogo; -extern struct static_library lib_AliceLogo2; -extern struct static_library lib_AliceLogo3; -extern struct static_library lib_Confirm2; -extern struct static_library lib_DrawGraph; -extern struct static_library lib_DrawPluginManager; -extern struct static_library lib_File; -extern struct static_library lib_Math; -extern struct static_library lib_MsgLogManager; -extern struct static_library lib_MsgSkip; -extern struct static_library lib_OutputLog; -extern struct static_library lib_PlayMovie; -extern struct static_library lib_SACT2; -extern struct static_library lib_SystemServiceEx; - -static struct static_library *static_libraries[] = { - &lib_ACXLoader, - &lib_AliceLogo, - &lib_AliceLogo2, - &lib_AliceLogo3, - &lib_Confirm2, - &lib_DrawGraph, - &lib_DrawPluginManager, - &lib_File, - &lib_Math, - &lib_MsgLogManager, - &lib_MsgSkip, - &lib_OutputLog, - &lib_PlayMovie, - &lib_SACT2, - &lib_SystemServiceEx, - NULL -}; - -/* - * "Link" a library that has been compiled into the xsystem4 executable. - */ -static struct hll_function *link_static_library(struct ain_library *ainlib, struct static_library *lib) -{ - struct hll_function *dst = xcalloc(ainlib->nr_functions, sizeof(struct hll_function)); - - for (int i = 0; i < ainlib->nr_functions; i++) { - for (int j = 0; lib->functions[j]; j++) { - if (!strcmp(ainlib->functions[i].name, lib->functions[j]->name)) { - dst[i].fun = lib->functions[j]->fun; - break; - } - } - if (!dst[i].fun) - WARNING("Unimplemented library function: %s", ainlib->functions[i].name); - else if (ainlib->functions[i].nr_arguments >= HLL_MAX_ARGS) - ERROR("Too many arguments to library function: %s", ainlib->functions[i].name); - } - return dst; -} - -static void link_libraries(void) -{ - libraries = xcalloc(ain->nr_libraries, sizeof(struct hll_function*)); - - for (int i = 0; i < ain->nr_libraries; i++) { - for (int j = 0; static_libraries[j]; j++) { - if (!strcmp(ain->libraries[i].name, static_libraries[j]->name)) { - libraries[i] = link_static_library(&ain->libraries[i], static_libraries[j]); - break; - } - } - if (!libraries[i]) - WARNING("Unimplemented library: %s", ain->libraries[i].name); - } -} - void vm_execute_ain(struct ain *program) { // initialize VM state