diff --git a/Makefile b/Makefile index 7846348..37641f3 100755 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ LUATOOLS="" ISCC := iscc ifdef SystemRoot - MAKE := mingw32-make + MAKE := make RM := rm -f CP := copy LUATOOLS := win32lua diff --git a/externals/installer/openvsm.iss b/externals/installer/openvsm.iss index f8ae380..445f88a 100644 --- a/externals/installer/openvsm.iss +++ b/externals/installer/openvsm.iss @@ -38,6 +38,9 @@ Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}" [Registry] Root: "HKCU"; Subkey: "Environment"; ValueType: expandsz; ValueName: "LUAVSM"; ValueData: "{app}\LuaScripts"; Flags: deletevalue +Root: "HKLM"; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; \ + ValueType: expandsz; ValueName: "Path"; ValueData: "{olddata};{app}\LuaScripts"; \ + Check: NeedsAddPath('{app}\LuaScripts') [Dirs] Name: "{app}\LuaScripts"; Flags: uninsneveruninstall diff --git a/externals/lua/src/Makefile b/externals/lua/src/Makefile index 1907381..97eb4cb 100644 --- a/externals/lua/src/Makefile +++ b/externals/lua/src/Makefile @@ -6,7 +6,7 @@ # Your platform. See PLATS for possible values. PLAT= guess -CC= gcc -std=gnu99 +CC= i686-w64-mingw32-cc -std=gnu99 CFLAGS= -O2 -Wall -Wextra -DLUA_COMPAT_5_3 $(SYSCFLAGS) $(MYCFLAGS) LDFLAGS= $(SYSLDFLAGS) $(MYLDFLAGS) LIBS= -lm $(SYSLIBS) $(MYLIBS) diff --git a/include/version.h b/include/version.h index 8949c82..3fd79d4 100755 --- a/include/version.h +++ b/include/version.h @@ -1,4 +1,4 @@ #define FILEVER 1,0,0,0 #define PRODUCTVER 1,0,0,0 -#define STRFILEVER "0.5.211\0" -#define STRPRODUCTVER "0.5.211\0" +#define STRFILEVER "0.6.213\0" +#define STRPRODUCTVER "0.6.213\0" diff --git a/src/Makefile b/src/Makefile index bfcaa0f..4fba442 100755 --- a/src/Makefile +++ b/src/Makefile @@ -1,19 +1,11 @@ RELEASE=`../relgen.sh` -ifdef SystemRoot - MAKE=make - CC:=gcc - AR:=ar - OBJCOPY:=objcopy - STRIP:=strip - WINRES:=windres -else - MAKE=make - CC:=i686-w64-mingw32-gcc - AR:=i686-w64-mingw32-ar - OBJCOPY:=i686-w64-mingw32-objcopy - STRIP:=i686-w64-mingw32-strip - WINRES:=i686-w64-mingw32-windres -endif + +MAKE=make +CC:= i686-w64-mingw32-cc +AR:= i686-w64-mingw32-ar +OBJCOPY:= objcopy +STRIP:= strip +WINRES:= windres LIBDIR=../dll @@ -22,7 +14,7 @@ DEV=device XXD=../tools/bin2source.exe LUAC=../tools/luac.exe OPENVSMLIB?=$(LIBDIR)/openvsm -LIADIR=lua +LUADIR=lua SRC:=vsmapi.c \ lua_pin.c \ @@ -44,12 +36,12 @@ $(MOD)/module_pin.lua DEVICE=\ $(DEV)/device.lua -CFLAGS:=-O3 -gdwarf-2 -fgnu89-inline -std=gnu99 -g3 -Wno-unused-variable -static-libgcc -static-libstdc++ -I../include -Imodules \ --I../externals/$(LIADIR)/src -D__VERSION=\"$(shell ../relgen.sh)\" +CFLAGS:=-O3 -m32 -gdwarf-2 -fgnu89-inline -std=gnu99 -g3 -Wno-unused-variable -static-libgcc -static-libstdc++ -I../include -Imodules \ +-I../externals/$(LUADIR)/src -D__VERSION=\"$(shell ../relgen.sh)\" SLIB_CFLAGS:=-Wl,--export-all-symbols,--enable-auto-import -LDFLAGS:=../externals/$(LIADIR)/src/liblua.a -lm -static-libgcc -static-libstdc++ +LDFLAGS:=-m32 ../externals/$(LUADIR)/src/liblua.a -lm -static-libgcc -static-libstdc++ OBJ=$(SRC:%.c=%.o) openvsm.res \ $(MOD)/module_bus.c.o $(MOD)/module_custom.c.o \ @@ -67,7 +59,7 @@ all: modules $(OPENVSMLIB).dll $(XXD) $@ > $@.c openvsm.res: - $(WINRES) openvsm.rc -O coff -o openvsm.res + $(WINRES) openvsm.rc --output-format=coff --target=pe-i386 -o openvsm.res $(DEV)/device.c.o: $(CC) -c -o $@ $(DEV)/device.mod.c $(CFLAGS) @@ -102,12 +94,13 @@ $(OPENVSMLIB).dll: $(OBJ) modules: $(LOBJ) @echo "Lua modules compiled" -SUBDIRS:= . modules device bindings +SUBDIRS:= . modules device bindings ../externals/$(LUADIR)/src/ clean: rm -f $(OPENVSMLIB).* for dir in $(SUBDIRS); do \ rm -f $$dir/*.o; \ + rm -f $$dir/*.res; \ rm -f $$dir/*.mod; \ rm -f $$dir/*.mod.c; \ done \ No newline at end of file diff --git a/src/bindings/cbind.c b/src/bindings/cbind.c index 0c531d0..131f41a 100644 --- a/src/bindings/cbind.c +++ b/src/bindings/cbind.c @@ -25,39 +25,39 @@ const char *state_to_string(STATE pinstate) { - switch (pinstate) - { - case UNDEFINED: - return "UNDEFINED"; - case TSTATE: - return "TSTATE"; - case FSTATE: - return "FSTATE"; - case PLO: - return "PLO"; - case ILO: - return "ILO"; - case SLO: - return "SLO"; - case WLO: - return "WLO"; - case FLT: - return "FLT"; - case WHI: - return "WHI"; - case SHI: - return "SHI"; - case IHI: - return "IHI"; - case PHI: - return "PHI"; - case WUD: - return "WUD"; - case SUD: - return "SUD"; - default: - return "wrong state"; - } + switch (pinstate) + { + case UNDEFINED: + return "UNDEFINED"; + case TSTATE: + return "TSTATE"; + case FSTATE: + return "FSTATE"; + case PLO: + return "PLO"; + case ILO: + return "ILO"; + case SLO: + return "SLO"; + case WLO: + return "WLO"; + case FLT: + return "FLT"; + case WHI: + return "WHI"; + case SHI: + return "SHI"; + case IHI: + return "IHI"; + case PHI: + return "PHI"; + case WUD: + return "WUD"; + case SUD: + return "SUD"; + default: + return "wrong state"; + } } /** @@ -76,11 +76,11 @@ const char *state_to_string(STATE pinstate) bool vsm_register(ILICENCESERVER *ils) { - if (FALSE == ils->vtable->authorize(ils, 0, model_key, VSM_API_VERSION)) - { - return FALSE; - } - return TRUE; + if (FALSE == ils->vtable->authorize(ils, 0, model_key, VSM_API_VERSION)) + { + return FALSE; + } + return TRUE; } /** @@ -98,9 +98,9 @@ bool vsm_register(ILICENCESERVER *ils) void set_pin_state(IDSIMMODEL *model, VSM_PIN pin, STATE state) { - ABSTIME curtime = 0; - systime(model, &curtime); - pin.pin->vtable->setstate2(pin.pin, 0, curtime, pin.on_time, state); + ABSTIME curtime = 0; + systime(model, &curtime); + pin.pin->vtable->setstate2(pin.pin, 0, curtime, pin.on_time, state); } /** @@ -118,9 +118,9 @@ void set_pin_state(IDSIMMODEL *model, VSM_PIN pin, STATE state) void set_pin_bool(IDSIMMODEL *model, VSM_PIN pin, bool level) { - ABSTIME curtime = 0; - systime(model, &curtime); - pin.pin->vtable->setstate2(pin.pin, 0, curtime, pin.on_time, level ? LOGIC_HI : LOGIC_LO); + ABSTIME curtime = 0; + systime(model, &curtime); + pin.pin->vtable->setstate2(pin.pin, 0, curtime, pin.on_time, level ? LOGIC_HI : LOGIC_LO); } /** @@ -137,7 +137,7 @@ void set_pin_bool(IDSIMMODEL *model, VSM_PIN pin, bool level) void systime(IDSIMMODEL *model, ABSTIME *at) { - model->model_dsim->vtable->sysvar(model->model_dsim, 0, (DOUBLE *)at, DSIMTIMENOW); + model->model_dsim->vtable->sysvar(model->model_dsim, 0, (DOUBLE *)at, DSIMTIMENOW); } /* \fn char* get_device_id ( IDSIMMODEL* model ) @@ -154,7 +154,7 @@ void systime(IDSIMMODEL *model, ABSTIME *at) char *get_device_id(IDSIMMODEL *model) { - return model->model_instance->vtable->id(model->model_instance, 0); + return model->model_instance->vtable->id(model->model_instance, 0); } /* \fn char* get_string_param ( IDSIMMODEL* model, char* field_name ) @@ -172,7 +172,7 @@ char *get_device_id(IDSIMMODEL *model) char *get_string_param(IDSIMMODEL *model, char *field_name) { - return model->model_instance->vtable->getstrval(model->model_instance, 0, field_name, "?"); + return model->model_instance->vtable->getstrval(model->model_instance, 0, field_name, "?"); } /** @@ -191,7 +191,7 @@ char *get_string_param(IDSIMMODEL *model, char *field_name) bool get_bool_param(IDSIMMODEL *model, char *field_name) { - return model->model_instance->vtable->getboolval(model->model_instance, 0, field_name, FALSE); + return model->model_instance->vtable->getboolval(model->model_instance, 0, field_name, FALSE); } /** @@ -210,9 +210,9 @@ bool get_bool_param(IDSIMMODEL *model, char *field_name) double get_num_param(IDSIMMODEL *model, char *field_name) { - double result = 0; - model->model_instance->vtable->getnumval(model->model_instance, 0, &result, field_name, 0.0); - return result; + double result = 0; + model->model_instance->vtable->getnumval(model->model_instance, 0, &result, field_name, 0.0); + return result; } /** @@ -231,7 +231,7 @@ double get_num_param(IDSIMMODEL *model, char *field_name) int32_t get_hex_param(IDSIMMODEL *model, char *field_name) { - return (int32_t)model->model_instance->vtable->gethexval(model->model_instance, 0, field_name, 0); + return (int32_t)model->model_instance->vtable->gethexval(model->model_instance, 0, field_name, 0); } /** @@ -250,7 +250,7 @@ int32_t get_hex_param(IDSIMMODEL *model, char *field_name) int64_t get_init_param(IDSIMMODEL *model, char *field_name) { - return (int64_t)model->model_instance->vtable->getinitval(model->model_instance, 0, field_name, 0); + return (int64_t)model->model_instance->vtable->getinitval(model->model_instance, 0, field_name, 0); } /** @@ -269,7 +269,7 @@ int64_t get_init_param(IDSIMMODEL *model, char *field_name) void load_image(IDSIMMODEL *model, char *filename, uint8_t *buffer, uint32_t buffer_size) { - model->model_instance->vtable->loadmemory(model->model_instance, 0, filename, buffer, buffer_size, 0, 0); + model->model_instance->vtable->loadmemory(model->model_instance, 0, filename, buffer, buffer_size, 0, 0); } /** @@ -288,7 +288,7 @@ void load_image(IDSIMMODEL *model, char *filename, uint8_t *buffer, uint32_t buf IPOPUP *create_popup(IDSIMMODEL *model, CREATEPOPUPSTRUCT *cps) { - return ((IPOPUP *)model->model_instance->vtable->createpopup(model->model_instance, 0, cps)); + return ((IPOPUP *)model->model_instance->vtable->createpopup(model->model_instance, 0, cps)); } /** @@ -308,16 +308,16 @@ IPOPUP *create_popup(IDSIMMODEL *model, CREATEPOPUPSTRUCT *cps) IMEMORYPOPUP *create_memory_popup(IDSIMMODEL *model, const char *title, const int32_t id) { - CREATEPOPUPSTRUCT *cps = malloc(sizeof *cps); - cps->caption = (char *)title; - cps->flags = PWF_VISIBLE | PWF_HIDEONANIMATE | PWF_SIZEABLE | PWF_AUTOREFRESH; - cps->type = PWT_MEMORY; - cps->height = 32; //-V112 - cps->width = 16; - cps->id = id; - IMEMORYPOPUP *popup = (IMEMORYPOPUP *)create_popup(model, cps); - free(cps); - return popup; + CREATEPOPUPSTRUCT *cps = malloc(sizeof *cps); + cps->caption = (char *)title; + cps->flags = PWF_VISIBLE | PWF_HIDEONANIMATE | PWF_SIZEABLE | PWF_AUTOREFRESH; + cps->type = PWT_MEMORY; + cps->height = 32; //-V112 + cps->width = 16; + cps->id = id; + IMEMORYPOPUP *popup = (IMEMORYPOPUP *)create_popup(model, cps); + free(cps); + return popup; } /** @@ -337,16 +337,16 @@ IMEMORYPOPUP *create_memory_popup(IDSIMMODEL *model, const char *title, const in IDEBUGPOPUP *create_debug_popup(IDSIMMODEL *model, const char *title, const int32_t id) { - CREATEPOPUPSTRUCT *cps = malloc(sizeof *cps); - cps->caption = (char *)title; - cps->flags = PWF_VISIBLE | PWF_HIDEONANIMATE | PWF_SIZEABLE | PWF_AUTOREFRESH; - cps->type = PWT_DEBUG; - cps->height = 200; - cps->width = 640; - cps->id = id; - IDEBUGPOPUP *popup = create_popup(model, cps); - free(cps); - return popup; + CREATEPOPUPSTRUCT *cps = malloc(sizeof *cps); + cps->caption = (char *)title; + cps->flags = PWF_VISIBLE | PWF_HIDEONANIMATE | PWF_SIZEABLE | PWF_AUTOREFRESH; + cps->type = PWT_DEBUG; + cps->height = 200; + cps->width = 640; + cps->id = id; + IDEBUGPOPUP *popup = create_popup(model, cps); + free(cps); + return popup; } /** @@ -366,16 +366,16 @@ IDEBUGPOPUP *create_debug_popup(IDSIMMODEL *model, const char *title, const int3 IDEBUGPOPUP *create_source_popup(IDSIMMODEL *model, const char *title, const int32_t id) { - CREATEPOPUPSTRUCT *cps = malloc(sizeof *cps); - cps->caption = (char *)title; - cps->flags = PWF_VISIBLE | PWF_HIDEONANIMATE | PWF_SIZEABLE | PWF_AUTOREFRESH; - cps->type = PWT_SOURCE; - cps->height = 200; - cps->width = 640; - cps->id = id; - IDEBUGPOPUP *popup = create_popup(model, cps); - free(cps); - return popup; + CREATEPOPUPSTRUCT *cps = malloc(sizeof *cps); + cps->caption = (char *)title; + cps->flags = PWF_VISIBLE | PWF_HIDEONANIMATE | PWF_SIZEABLE | PWF_AUTOREFRESH; + cps->type = PWT_SOURCE; + cps->height = 200; + cps->width = 640; + cps->id = id; + IDEBUGPOPUP *popup = create_popup(model, cps); + free(cps); + return popup; } /** @@ -395,16 +395,16 @@ IDEBUGPOPUP *create_source_popup(IDSIMMODEL *model, const char *title, const int IDEBUGPOPUP *create_status_popup(IDSIMMODEL *model, const char *title, const int32_t id) { - CREATEPOPUPSTRUCT *cps = malloc(sizeof *cps); - cps->caption = (char *)title; - cps->flags = PWF_VISIBLE | PWF_HIDEONANIMATE | PWF_SIZEABLE | PWF_AUTOREFRESH; - cps->type = PWT_STATUS; - cps->height = 200; - cps->width = 200; - cps->id = id; - IDEBUGPOPUP *popup = create_popup(model, cps); - free(cps); - return popup; + CREATEPOPUPSTRUCT *cps = malloc(sizeof *cps); + cps->caption = (char *)title; + cps->flags = PWF_VISIBLE | PWF_HIDEONANIMATE | PWF_SIZEABLE | PWF_AUTOREFRESH; + cps->type = PWT_STATUS; + cps->height = 200; + cps->width = 200; + cps->id = id; + IDEBUGPOPUP *popup = create_popup(model, cps); + free(cps); + return popup; } /** @@ -424,16 +424,16 @@ IDEBUGPOPUP *create_status_popup(IDSIMMODEL *model, const char *title, const int IDEBUGPOPUP *create_var_popup(IDSIMMODEL *model, const char *title, const int32_t id) { - CREATEPOPUPSTRUCT *cps = malloc(sizeof *cps); - cps->caption = (char *)title; - cps->flags = PWF_VISIBLE | PWF_HIDEONANIMATE | PWF_SIZEABLE | PWF_AUTOREFRESH; - cps->type = PWT_VAR; - cps->height = 200; - cps->width = 200; - cps->id = id; - IDEBUGPOPUP *popup = create_popup(model, cps); - free(cps); - return popup; + CREATEPOPUPSTRUCT *cps = malloc(sizeof *cps); + cps->caption = (char *)title; + cps->flags = PWF_VISIBLE | PWF_HIDEONANIMATE | PWF_SIZEABLE | PWF_AUTOREFRESH; + cps->type = PWT_VAR; + cps->height = 200; + cps->width = 200; + cps->id = id; + IDEBUGPOPUP *popup = create_popup(model, cps); + free(cps); + return popup; } /** @@ -450,7 +450,7 @@ IDEBUGPOPUP *create_var_popup(IDSIMMODEL *model, const char *title, const int32_ void delete_popup(IDSIMMODEL *model, POPUPID id) { - model->model_instance->vtable->deletepopup(model->model_instance, 0, id); + model->model_instance->vtable->deletepopup(model->model_instance, 0, id); } /** @@ -469,7 +469,7 @@ void delete_popup(IDSIMMODEL *model, POPUPID id) void set_memory_popup(IMEMORYPOPUP *popup, uint32_t offset, void *buffer, size_t size) { - popup->vtable->setmemory(popup, 0, offset, buffer, size); + popup->vtable->setmemory(popup, 0, offset, buffer, size); } /** @@ -489,9 +489,9 @@ void set_memory_popup(IMEMORYPOPUP *popup, uint32_t offset, void *buffer, size_t bool add_source_file(ISOURCEPOPUP *popup, char *filename, bool lowlevel) { - bool result = popup->vtable->addsrcfile(popup, 0, filename, lowlevel); - popup->vtable->setpcaddress(popup, 0, 0); - return result; + bool result = popup->vtable->addsrcfile(popup, 0, filename, lowlevel); + popup->vtable->setpcaddress(popup, 0, 0); + return result; } /** @@ -509,7 +509,7 @@ bool add_source_file(ISOURCEPOPUP *popup, char *filename, bool lowlevel) bool set_vdm_handler(IDSIMMODEL *model) { - return model->model_instance->vtable->setvdmhlr(model->model_instance, 0, &ICPU_DEVICE); + return model->model_instance->vtable->setvdmhlr(model->model_instance, 0, &ICPU_DEVICE); } /** @@ -526,7 +526,7 @@ bool set_vdm_handler(IDSIMMODEL *model) void set_pc_address(ISOURCEPOPUP *popup, uint32_t address) { - popup->vtable->setpcaddress(popup, 0, address); + popup->vtable->setpcaddress(popup, 0, address); } /** @@ -542,7 +542,7 @@ void set_pc_address(ISOURCEPOPUP *popup, uint32_t address) void repaint_memory_popup(IMEMORYPOPUP *popup) { - popup->vtable->repaint(popup, 0); + popup->vtable->repaint(popup, 0); } /** @@ -559,7 +559,7 @@ void repaint_memory_popup(IMEMORYPOPUP *popup) void print_to_debug_popup(IDEBUGPOPUP *popup, const char *message) { - popup->vtable->print(popup, (char *)message); + popup->vtable->print(popup, (char *)message); } /** @@ -578,7 +578,7 @@ void print_to_debug_popup(IDEBUGPOPUP *popup, const char *message) void dump_to_debug_popup(IDEBUGPOPUP *popup, const uint8_t *buf, uint32_t offset, uint32_t size) { - popup->vtable->dump(popup, 0, buf + offset, size, 16); + popup->vtable->dump(popup, 0, buf + offset, size, 16); } /** @@ -596,17 +596,17 @@ void dump_to_debug_popup(IDEBUGPOPUP *popup, const uint8_t *buf, uint32_t offset const char *logic_type_to_string(LOGIC_TYPE type) { - switch (type) - { - case TTL: - return "TTL"; - case CMOS: - return "CMOS"; - case I2L: - return "I2L"; - default: - return "Unknown"; - } + switch (type) + { + case TTL: + return "TTL"; + case CMOS: + return "CMOS"; + case I2L: + return "I2L"; + default: + return "Unknown"; + } } /** @@ -623,28 +623,28 @@ const char *logic_type_to_string(LOGIC_TYPE type) void set_logic_type(IDSIMMODEL *model, LOGIC_TYPE type) { - model->ltype = type; - switch (type) - { - case TTL: - model->logic_high = SHI; - model->logic_low = SLO; - model->logic_flt = FLT; - break; - case CMOS: - model->logic_high = IHI; - model->logic_low = ILO; - model->logic_flt = FLT; - break; - case I2L: - model->logic_high = WHI; - model->logic_low = WLO; - model->logic_flt = FLT; - break; - default: - print_error(model, "Unknown logic type specified: %d", type); - break; - } + model->ltype = type; + switch (type) + { + case TTL: + model->logic_high = SHI; + model->logic_low = SLO; + model->logic_flt = FLT; + break; + case CMOS: + model->logic_high = IHI; + model->logic_low = ILO; + model->logic_flt = FLT; + break; + case I2L: + model->logic_high = WHI; + model->logic_low = WLO; + model->logic_flt = FLT; + break; + default: + print_error(model, "Unknown logic type specified: %d", type); + break; + } } /** @@ -661,16 +661,16 @@ void set_logic_type(IDSIMMODEL *model, LOGIC_TYPE type) void toggle_pin_state(IDSIMMODEL *model, VSM_PIN pin) { - if (TRUE == is_pin_high(pin.pin)) - { - set_pin_state(model, pin, LOGIC_LO); - return; - } - else if (TRUE == is_pin_low(pin.pin)) - { - set_pin_state(model, pin, LOGIC_HI); - return; - } + if (TRUE == is_pin_high(pin.pin)) + { + set_pin_state(model, pin, LOGIC_LO); + return; + } + else if (TRUE == is_pin_low(pin.pin)) + { + set_pin_state(model, pin, LOGIC_HI); + return; + } } /** @@ -688,7 +688,7 @@ void toggle_pin_state(IDSIMMODEL *model, VSM_PIN pin) STATE get_pin_state(IDSIMPIN *pin) { - return pin->vtable->getstate(pin, 0); + return pin->vtable->getstate(pin, 0); } /** @@ -706,16 +706,16 @@ STATE get_pin_state(IDSIMPIN *pin) int get_pin_bool(VSM_PIN pin) { - if (TRUE == is_pin_high(pin.pin)) - { - return 1; - } - else if (TRUE == is_pin_low(pin.pin)) - { - return 0; - } - /* return -1 if floating */ - return -1; + if (TRUE == is_pin_high(pin.pin)) + { + return 1; + } + else if (TRUE == is_pin_low(pin.pin)) + { + return 0; + } + /* return -1 if floating */ + return -1; } /** @@ -733,7 +733,7 @@ int get_pin_bool(VSM_PIN pin) bool is_pin_active(IDSIMPIN *pin) { - return pin->vtable->isactive(pin, 0); + return pin->vtable->isactive(pin, 0); } /** @@ -751,7 +751,7 @@ bool is_pin_active(IDSIMPIN *pin) bool is_pin_inactive(IDSIMPIN *pin) { - return pin->vtable->isinactive(pin, 0); + return pin->vtable->isinactive(pin, 0); } /** @@ -769,7 +769,7 @@ bool is_pin_inactive(IDSIMPIN *pin) bool is_pin_posedge(IDSIMPIN *pin) { - return pin->vtable->isposedge(pin, 0); + return pin->vtable->isposedge(pin, 0); } /** @@ -787,7 +787,7 @@ bool is_pin_posedge(IDSIMPIN *pin) bool is_pin_negedge(IDSIMPIN *pin) { - return pin->vtable->isnegedge(pin, 0); + return pin->vtable->isnegedge(pin, 0); } /** @@ -805,7 +805,7 @@ bool is_pin_negedge(IDSIMPIN *pin) bool is_pin_edge(IDSIMPIN *pin) { - return pin->vtable->isedge(pin, 0); + return pin->vtable->isedge(pin, 0); } /** @@ -823,8 +823,8 @@ bool is_pin_edge(IDSIMPIN *pin) void set_callback(IDSIMMODEL *model, RELTIME picotime, EVENTID id) { - /* Add event to the model's hash table in order to keep count of registered events */ - model->model_dsim->vtable->setcallback(model->model_dsim, 0, picotime, model, id); + /* Add event to the model's hash table in order to keep count of registered events */ + model->model_dsim->vtable->setcallback(model->model_dsim, 0, picotime, model, id); } /** @@ -842,14 +842,14 @@ void set_callback(IDSIMMODEL *model, RELTIME picotime, EVENTID id) void print_info(IDSIMMODEL *model, const char *format, ...) { - char *string; - va_list args; - va_start(args, format); - if (0 > vasprintf(&string, (char *)format, args)) - string = NULL; - va_end(args); - model->model_instance->vtable->log(model->model_instance, string); - free(string); + char *string; + va_list args; + va_start(args, format); + if (0 > vasprintf(&string, (char *)format, args)) + string = NULL; + va_end(args); + model->model_instance->vtable->log(model->model_instance, string); + free(string); } /** @@ -867,14 +867,14 @@ void print_info(IDSIMMODEL *model, const char *format, ...) void print_message(IDSIMMODEL *model, const char *format, ...) { - char *string; - va_list args; - va_start(args, format); - if (0 > vasprintf(&string, (char *)format, args)) - string = NULL; - va_end(args); - model->model_instance->vtable->message(model->model_instance, string); - free(string); + char *string; + va_list args; + va_start(args, format); + if (0 > vasprintf(&string, (char *)format, args)) + string = NULL; + va_end(args); + model->model_instance->vtable->message(model->model_instance, string); + free(string); } /** @@ -892,14 +892,14 @@ void print_message(IDSIMMODEL *model, const char *format, ...) void print_warning(IDSIMMODEL *model, const char *format, ...) { - char *string; - va_list args; - va_start(args, format); - if (0 > vasprintf(&string, (char *)format, args)) - string = NULL; - va_end(args); - model->model_instance->vtable->warning(model->model_instance, string); - free(string); + char *string; + va_list args; + va_start(args, format); + if (0 > vasprintf(&string, (char *)format, args)) + string = NULL; + va_end(args); + model->model_instance->vtable->warning(model->model_instance, string); + free(string); } /** @@ -917,14 +917,14 @@ void print_warning(IDSIMMODEL *model, const char *format, ...) void print_error(IDSIMMODEL *model, const char *format, ...) { - char *string; - va_list args; - va_start(args, format); - if (0 > vasprintf(&string, (char *)format, args)) - string = NULL; - va_end(args); - model->model_instance->vtable->error(model->model_instance, string); - free(string); + char *string; + va_list args; + va_start(args, format); + if (0 > vasprintf(&string, (char *)format, args)) + string = NULL; + va_end(args); + model->model_instance->vtable->error(model->model_instance, string); + free(string); } /** @@ -943,7 +943,7 @@ void print_error(IDSIMMODEL *model, const char *format, ...) IDSIMPIN *get_pin(IDSIMMODEL *model, char *pin_name) { - return model->model_instance->vtable->getdsimpin(model->model_instance, 0, pin_name, TRUE); + return model->model_instance->vtable->getdsimpin(model->model_instance, 0, pin_name, TRUE); } /** @@ -961,7 +961,7 @@ IDSIMPIN *get_pin(IDSIMMODEL *model, char *pin_name) bool is_pin_low(IDSIMPIN *pin) { - return islow(pin->vtable->istate(pin, 0)); + return islow(pin->vtable->istate(pin, 0)); } /** @@ -979,7 +979,7 @@ bool is_pin_low(IDSIMPIN *pin) bool is_pin_high(IDSIMPIN *pin) { - return ishigh(pin->vtable->istate(pin, 0)); + return ishigh(pin->vtable->istate(pin, 0)); } /** @@ -997,7 +997,7 @@ bool is_pin_high(IDSIMPIN *pin) bool is_pin_floating(IDSIMPIN *pin) { - return isfloating(pin->vtable->istate(pin, 0)); + return isfloating(pin->vtable->istate(pin, 0)); } /** @@ -1015,7 +1015,7 @@ bool is_pin_floating(IDSIMPIN *pin) bool is_pin_steady(IDSIMPIN *pin) { - return pin->vtable->issteady(pin, 0); + return pin->vtable->issteady(pin, 0); } /** @@ -1033,7 +1033,7 @@ bool is_pin_steady(IDSIMPIN *pin) bool is_pin_inverted(IDSIMPIN *pin) { - return pin->vtable->invert(pin, 0); + return pin->vtable->invert(pin, 0); } /** @@ -1051,7 +1051,7 @@ bool is_pin_inverted(IDSIMPIN *pin) __INLINE__ bool islow(STATE pinstate) { - return (pinstate & SP_MASK) == SP_LOW; + return (pinstate & SP_MASK) == SP_LOW; } /** @@ -1070,7 +1070,7 @@ __INLINE__ bool islow(STATE pinstate) __INLINE__ bool ishigh(STATE pinstate) { - return (pinstate & SP_MASK) == SP_HIGH; + return (pinstate & SP_MASK) == SP_HIGH; } /** @@ -1089,7 +1089,7 @@ ishigh(STATE pinstate) __INLINE__ bool isfloating(STATE pinstate) { - return (pinstate & SP_MASK) == SP_FLOAT; + return (pinstate & SP_MASK) == SP_FLOAT; } /** @@ -1108,7 +1108,7 @@ isfloating(STATE pinstate) __INLINE__ bool iscontention(STATE pinstate) { - return pinstate & SF_CONTENTION; + return pinstate & SF_CONTENTION; } /** @@ -1127,7 +1127,7 @@ iscontention(STATE pinstate) __INLINE__ bool isdefined(STATE pinstate) { - return pinstate != SP_UNDEFINED; + return pinstate != SP_UNDEFINED; } /** @@ -1146,7 +1146,7 @@ isdefined(STATE pinstate) __INLINE__ bool ishighlow(STATE pinstate) { - return pinstate & 1; + return pinstate & 1; } /** @@ -1165,7 +1165,7 @@ ishighlow(STATE pinstate) __INLINE__ INT polarity(STATE pinstate) { - return pinstate & SP_MASK; + return pinstate & SP_MASK; } /** @@ -1184,5 +1184,5 @@ polarity(STATE pinstate) __INLINE__ INT strength(STATE pinstate) { - return pinstate & SS_MASK; + return pinstate & SS_MASK; } diff --git a/src/bindings/luabind.c b/src/bindings/luabind.c index bf89020..c69aed2 100644 --- a/src/bindings/luabind.c +++ b/src/bindings/luabind.c @@ -17,64 +17,64 @@ /// @brief The lua variable API list[]=. static const lua_bind_var lua_var_api_list[] = ///< The lua variable API list[]= - { - /* Logic states */ - {.var_name = "SHI", .var_value = SHI}, - {.var_name = "SLO", .var_value = SLO}, - {.var_name = "FLT", .var_value = FLT}, - {.var_name = "PLO", .var_value = PLO}, - {.var_name = "ILO", .var_value = ILO}, - {.var_name = "WLO", .var_value = WLO}, - {.var_name = "WHI", .var_value = WHI}, - {.var_name = "IHI", .var_value = IHI}, - {.var_name = "PHI", .var_value = PHI}, - {.var_name = "WUD", .var_value = WUD}, - {.var_name = "SUD", .var_value = SUD}, - {.var_name = "TSTATE", .var_value = TSTATE}, - {.var_name = "FSTATE", .var_value = FSTATE}, - {.var_name = "UNDEFINED", .var_value = UNDEFINED}, - /* Time suffixes */ - {.var_name = "MSEC", .var_value = 1000000000L}, - {.var_name = "NSEC", .var_value = 100000000L}, - {.var_name = "USEC", .var_value = 1000000L}, - {.var_name = "SEC", .var_value = 1000000000000L}, - {.var_name = "NOW", .var_value = 0L}, - /* Logic types */ - {.var_name = "TTL", .var_value = TTL}, - {.var_name = "CMOS", .var_value = CMOS}, - {.var_name = "I2L", .var_value = I2L}, - {.var_name = NULL}, + { + /* Logic states */ + {.var_name = "SHI", .var_value = SHI}, + {.var_name = "SLO", .var_value = SLO}, + {.var_name = "FLT", .var_value = FLT}, + {.var_name = "PLO", .var_value = PLO}, + {.var_name = "ILO", .var_value = ILO}, + {.var_name = "WLO", .var_value = WLO}, + {.var_name = "WHI", .var_value = WHI}, + {.var_name = "IHI", .var_value = IHI}, + {.var_name = "PHI", .var_value = PHI}, + {.var_name = "WUD", .var_value = WUD}, + {.var_name = "SUD", .var_value = SUD}, + {.var_name = "TSTATE", .var_value = TSTATE}, + {.var_name = "FSTATE", .var_value = FSTATE}, + {.var_name = "UNDEFINED", .var_value = UNDEFINED}, + /* Time suffixes */ + {.var_name = "MSEC", .var_value = 1000000000L}, + {.var_name = "NSEC", .var_value = 100000000L}, + {.var_name = "USEC", .var_value = 1000000L}, + {.var_name = "SEC", .var_value = 1000000000000L}, + {.var_name = "NOW", .var_value = 0L}, + /* Logic types */ + {.var_name = "TTL", .var_value = TTL}, + {.var_name = "CMOS", .var_value = CMOS}, + {.var_name = "I2L", .var_value = I2L}, + {.var_name = NULL}, }; /// @brief The lua c API list[]. static const lua_bind_func lua_c_api_list[] = ///< The lua c API list[] - { - {.lua_func_name = "state_to_string", .lua_c_api = &lua_state_to_string, .args = {LSTRING}}, - {.lua_func_name = "info", .lua_c_api = &lua_print_info, .args = {LSTRING}}, - {.lua_func_name = "message", .lua_c_api = &lua_print_message, .args = {LSTRING}}, - {.lua_func_name = "warning", .lua_c_api = &lua_print_warning, .args = {LSTRING}}, - {.lua_func_name = "error", .lua_c_api = &lua_print_error, .args = {LSTRING}}, - {.lua_func_name = "set_callback", .lua_c_api = &lua_set_callback, .args = {LINT, LINT}}, - {.lua_func_name = "create_debug_popup", .lua_c_api = &lua_create_debug_popup, .args = {LSTRING}}, - {.lua_func_name = "create_memory_popup", .lua_c_api = &lua_create_memory_popup, .args = {LSTRING}}, - {.lua_func_name = "create_source_popup", .lua_c_api = &lua_create_source_popup, .args = {LSTRING}}, - {.lua_func_name = "create_status_popup", .lua_c_api = &lua_create_status_popup, .args = {LSTRING}}, - {.lua_func_name = "create_var_popup", .lua_c_api = &lua_create_var_popup, .args = {LSTRING}}, - {.lua_func_name = "delete_popup", .lua_c_api = &lua_delete_popup, .args = {LINT}}, - {.lua_func_name = "set_memory_popup", .lua_c_api = &lua_set_memory_popup}, - {.lua_func_name = "repaint_memory_popup", .lua_c_api = &lua_repaint_memory_popup}, - {.lua_func_name = "print_to_debug_popup", .lua_c_api = &lua_print_to_debug_popup}, - {.lua_func_name = "dump_to_debug_popup", .lua_c_api = &lua_dump_to_debug_popup}, - {.lua_func_name = "get_string_param", .lua_c_api = &lua_get_string_param}, - {.lua_func_name = "get_num_param", .lua_c_api = &lua_get_num_param}, - {.lua_func_name = "get_bool_param", .lua_c_api = &lua_get_bool_param}, - {.lua_func_name = "get_init_param", .lua_c_api = &lua_get_init_param}, - {.lua_func_name = "get_hex_param", .lua_c_api = &lua_get_hex_param}, - {.lua_func_name = "add_source_file", .lua_c_api = &lua_add_source_file}, - {.lua_func_name = "systime", .lua_c_api = &lua_get_systime}, - {.lua_func_name = "set_bus", .lua_c_api = &lua_set_bus}, - {.lua_func_name = "get_bus", .lua_c_api = &lua_get_bus}, - {NULL, NULL}, + { + {.lua_func_name = "state_to_string", .lua_c_api = &lua_state_to_string, .args = {LSTRING}}, + {.lua_func_name = "info", .lua_c_api = &lua_print_info, .args = {LSTRING}}, + {.lua_func_name = "message", .lua_c_api = &lua_print_message, .args = {LSTRING}}, + {.lua_func_name = "warning", .lua_c_api = &lua_print_warning, .args = {LSTRING}}, + {.lua_func_name = "error", .lua_c_api = &lua_print_error, .args = {LSTRING}}, + {.lua_func_name = "set_callback", .lua_c_api = &lua_set_callback, .args = {LINT, LINT}}, + {.lua_func_name = "create_debug_popup", .lua_c_api = &lua_create_debug_popup, .args = {LSTRING}}, + {.lua_func_name = "create_memory_popup", .lua_c_api = &lua_create_memory_popup, .args = {LSTRING}}, + {.lua_func_name = "create_source_popup", .lua_c_api = &lua_create_source_popup, .args = {LSTRING}}, + {.lua_func_name = "create_status_popup", .lua_c_api = &lua_create_status_popup, .args = {LSTRING}}, + {.lua_func_name = "create_var_popup", .lua_c_api = &lua_create_var_popup, .args = {LSTRING}}, + {.lua_func_name = "delete_popup", .lua_c_api = &lua_delete_popup, .args = {LINT}}, + {.lua_func_name = "set_memory_popup", .lua_c_api = &lua_set_memory_popup}, + {.lua_func_name = "repaint_memory_popup", .lua_c_api = &lua_repaint_memory_popup}, + {.lua_func_name = "print_to_debug_popup", .lua_c_api = &lua_print_to_debug_popup}, + {.lua_func_name = "dump_to_debug_popup", .lua_c_api = &lua_dump_to_debug_popup}, + {.lua_func_name = "get_string_param", .lua_c_api = &lua_get_string_param}, + {.lua_func_name = "get_num_param", .lua_c_api = &lua_get_num_param}, + {.lua_func_name = "get_bool_param", .lua_c_api = &lua_get_bool_param}, + {.lua_func_name = "get_init_param", .lua_c_api = &lua_get_init_param}, + {.lua_func_name = "get_hex_param", .lua_c_api = &lua_get_hex_param}, + {.lua_func_name = "add_source_file", .lua_c_api = &lua_add_source_file}, + {.lua_func_name = "systime", .lua_c_api = &lua_get_systime}, + {.lua_func_name = "set_bus", .lua_c_api = &lua_set_bus}, + {.lua_func_name = "get_bus", .lua_c_api = &lua_get_bus}, + {NULL, NULL}, }; /** @@ -92,54 +92,54 @@ static const lua_bind_func lua_c_api_list[] = ///< The lua c API list[] void lua_load_modules(IDSIMMODEL *this) { - if (luaL_loadbuffer(this->luactx, module_custom_mod, module_custom_mod_len, "custom_assignments")) - { - PRINT(this, "Failed to load CUSTOM module"); - } - if (0 != lua_pcall(this->luactx, 0, 0, 0)) - { - print_error(this, "Failed to precompile module"); - } - if (luaL_loadbuffer(this->luactx, module_bus_mod, module_bus_mod_len, "bus_class")) - { - PRINT(this, "Failed to load BUS module"); - } - if (0 != lua_pcall(this->luactx, 0, 0, 0)) - { - print_error(this, "Failed to precompile module"); - } - if (luaL_loadbuffer(this->luactx, module_events_mod, module_events_mod_len, "events_class")) - { - PRINT(this, "Failed to load EVENTS module"); - } - if (0 != lua_pcall(this->luactx, 0, 0, 0)) - { - print_error(this, "Failed to precompile module"); - } - if (luaL_loadbuffer(this->luactx, device_mod, device_mod_len, "precompiled_device")) - { - PRINT(this, "Failed to load DEVICE module"); - } - if (0 != lua_pcall(this->luactx, 0, 0, 0)) - { - print_error(this, "Failed to precompile module"); - } - if (luaL_loadbuffer(this->luactx, module_fifo_mod, module_fifo_mod_len, "fifo_class")) - { - PRINT(this, "Failed to load FIFO module"); - } - if (0 != lua_pcall(this->luactx, 0, 0, 0)) - { - print_error(this, "Failed to precompile module"); - } - if (luaL_loadbuffer(this->luactx, module_uart_mod, module_uart_mod_len, "uart_class")) - { - PRINT(this, "Failed to load UART module"); - } - if (0 != lua_pcall(this->luactx, 0, 0, 0)) - { - print_error(this, "Failed to precompile module"); - } + if (luaL_loadbuffer(this->luactx, module_custom_mod, module_custom_mod_len, "custom_assignments")) + { + PRINT(this, "Failed to load CUSTOM module"); + } + if (0 != lua_pcall(this->luactx, 0, 0, 0)) + { + print_error(this, "Failed to precompile module"); + } + if (luaL_loadbuffer(this->luactx, module_bus_mod, module_bus_mod_len, "bus_class")) + { + PRINT(this, "Failed to load BUS module"); + } + if (0 != lua_pcall(this->luactx, 0, 0, 0)) + { + print_error(this, "Failed to precompile module"); + } + if (luaL_loadbuffer(this->luactx, module_events_mod, module_events_mod_len, "events_class")) + { + PRINT(this, "Failed to load EVENTS module"); + } + if (0 != lua_pcall(this->luactx, 0, 0, 0)) + { + print_error(this, "Failed to precompile module"); + } + if (luaL_loadbuffer(this->luactx, device_mod, device_mod_len, "precompiled_device")) + { + PRINT(this, "Failed to load DEVICE module"); + } + if (0 != lua_pcall(this->luactx, 0, 0, 0)) + { + print_error(this, "Failed to precompile module"); + } + if (luaL_loadbuffer(this->luactx, module_fifo_mod, module_fifo_mod_len, "fifo_class")) + { + PRINT(this, "Failed to load FIFO module"); + } + if (0 != lua_pcall(this->luactx, 0, 0, 0)) + { + print_error(this, "Failed to precompile module"); + } + if (luaL_loadbuffer(this->luactx, module_uart_mod, module_uart_mod_len, "uart_class")) + { + PRINT(this, "Failed to load UART module"); + } + if (0 != lua_pcall(this->luactx, 0, 0, 0)) + { + print_error(this, "Failed to precompile module"); + } } /** @@ -159,56 +159,56 @@ void lua_load_modules(IDSIMMODEL *this) static void safe_execute(lua_State *L, void *curfunc) { - /* Call trace */ - /*calltrace* new = NULL; - HASH_FIND_INT ( this->trace, &curfunc, new ); - if ( !new ) - { - new = malloc ( sizeof *new ); - new->func_addr = curfunc; - HASH_ADD_INT ( this->trace, func_addr, new ); - }*/ - /*=============*/ - IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); - if (!this->safe_mode) - return; - - int argnum = lua_gettop(L); - for (int i = 0; lua_c_api_list[i].lua_func_name; i++) - { - if (curfunc == lua_c_api_list[i].lua_c_api) - { - int argcount = 0; - for (argcount = 0; lua_c_api_list[i].args[argcount]; argcount++) - { - if (argnum < argcount + 1) - { - lua_Debug ar; - lua_getstack(L, 1, &ar); - lua_getinfo(L, "nSl", &ar); - int line = ar.currentline; - - print_error(this, "Line %d: Too few arguments passed to the function \"%s\"", line, lua_c_api_list[i].lua_func_name); - } - else if (!lua_c_api_list[i].args[argcount](L, argcount + 1)) - { - lua_Debug ar; - lua_getstack(L, 1, &ar); - lua_getinfo(L, "nSl", &ar); - int line = ar.currentline; - print_error(this, "Line %d: Argument %d of \"%s\" is of wrong type [%s]", line, argcount + 1, lua_c_api_list[i].lua_func_name, lua_typename(L, argcount + 1)); - } - } - if (lua_c_api_list[i].args[argcount + 2]) - { - lua_Debug ar; - lua_getstack(L, 1, &ar); - lua_getinfo(L, "nSl", &ar); - int line = ar.currentline; - print_error(this, "Line %d: extra arguments passed to \"%s\"", line, argcount + 1, lua_c_api_list[i].lua_func_name); - } - } - } + /* Call trace */ + /*calltrace* new = NULL; + HASH_FIND_INT ( this->trace, &curfunc, new ); + if ( !new ) + { + new = malloc ( sizeof *new ); + new->func_addr = curfunc; + HASH_ADD_INT ( this->trace, func_addr, new ); + }*/ + /*=============*/ + IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); + if (!this->safe_mode) + return; + + int argnum = lua_gettop(L); + for (int i = 0; lua_c_api_list[i].lua_func_name; i++) + { + if (curfunc == lua_c_api_list[i].lua_c_api) + { + int argcount = 0; + for (argcount = 0; lua_c_api_list[i].args[argcount]; argcount++) + { + if (argnum < argcount + 1) + { + lua_Debug ar; + lua_getstack(L, 1, &ar); + lua_getinfo(L, "nSl", &ar); + int line = ar.currentline; + + print_error(this, "Line %d: Too few arguments passed to the function \"%s\"", line, lua_c_api_list[i].lua_func_name); + } + else if (!lua_c_api_list[i].args[argcount](L, argcount + 1)) + { + lua_Debug ar; + lua_getstack(L, 1, &ar); + lua_getinfo(L, "nSl", &ar); + int line = ar.currentline; + print_error(this, "Line %d: Argument %d of \"%s\" is of wrong type [%s]", line, argcount + 1, lua_c_api_list[i].lua_func_name, lua_typename(L, argcount + 1)); + } + } + if (lua_c_api_list[i].args[argcount + 2]) + { + lua_Debug ar; + lua_getstack(L, 1, &ar); + lua_getinfo(L, "nSl", &ar); + int line = ar.currentline; + print_error(this, "Line %d: extra arguments passed to \"%s\"", line, argcount + 1, lua_c_api_list[i].lua_func_name); + } + } + } } /** @@ -227,18 +227,18 @@ safe_execute(lua_State *L, void *curfunc) void register_functions(IDSIMMODEL *this, lua_State *L) { - /* Declare functions */ - for (int i = 0; lua_c_api_list[i].lua_func_name; i++) - { - lua_pushcfunction(L, lua_c_api_list[i].lua_c_api); - lua_setglobal(L, lua_c_api_list[i].lua_func_name); - } - /* Declare variables */ - for (int i = 0; lua_var_api_list[i].var_name; i++) - { - lua_pushinteger(L, lua_var_api_list[i].var_value); - lua_setglobal(L, lua_var_api_list[i].var_name); - } + /* Declare functions */ + for (int i = 0; lua_c_api_list[i].lua_func_name; i++) + { + lua_pushcfunction(L, lua_c_api_list[i].lua_c_api); + lua_setglobal(L, lua_c_api_list[i].lua_func_name); + } + /* Declare variables */ + for (int i = 0; lua_var_api_list[i].var_name; i++) + { + lua_pushinteger(L, lua_var_api_list[i].var_value); + lua_setglobal(L, lua_var_api_list[i].var_name); + } } /** @@ -259,46 +259,46 @@ void register_functions(IDSIMMODEL *this, lua_State *L) bool load_device_script(IDSIMMODEL *this, const char *device_name) { - char spath[512] = {0}; - if (0 == GetEnvironmentVariable("LUAVSM", spath, sizeof spath)) - { - print_error(this, "LUAVSM environment variable is not set"); - return false; - } - char *script = NULL; - asprintf(&script, "%s%s%s", spath, '\\' == spath[strlen(spath) - 1] ? "" : "\\", device_name); - - int lua_err = luaL_loadfile(this->luactx, script); - - if (0 != lua_err) - { - const char *mess = NULL; - switch (lua_err) - { - case LUA_ERRSYNTAX: - mess = lua_tostring(this->luactx, FIRST_ARG); - print_error(this, "Syntax error in Lua script\n%s", mess); - return false; - case LUA_ERRMEM: - print_error(this, "Not enough memory to load script \"%s\"", script); - return false; - case LUA_ERRFILE: - print_error(this, "Error opening/loading script file \"%s\"", script); - return false; - default: - print_error(this, "Unknown error, shouldn't happen"); - assert(0); - } - } - /* Primer run, if not run it - nothing works, need for parse */ - if (0 != lua_pcall(this->luactx, 0, 0, 0)) - { - print_error(this, "Failed to load the script \"%s\"", script); - free(script); - return false; - } - free(script); - return true; + char spath[512] = {0}; + if (0 == GetEnvironmentVariable("LUAVSM", spath, sizeof spath)) + { + print_error(this, "LUAVSM environment variable is not set"); + return false; + } + char *script = NULL; + asprintf(&script, "%s%s%s", spath, '\\' == spath[strlen(spath) - 1] ? "" : "\\", device_name); + + int lua_err = luaL_loadfile(this->luactx, script); + + if (0 != lua_err) + { + const char *mess = NULL; + switch (lua_err) + { + case LUA_ERRSYNTAX: + mess = lua_tostring(this->luactx, FIRST_ARG); + print_error(this, "Syntax error in Lua script\n%s", mess); + return false; + case LUA_ERRMEM: + print_error(this, "Not enough memory to load script \"%s\"", script); + return false; + case LUA_ERRFILE: + print_error(this, "Error opening/loading script file \"%s\"", script); + return false; + default: + print_error(this, "Unknown error, shouldn't happen"); + assert(0); + } + } + /* Primer run, if not run it - nothing works, need for parse */ + if (0 != lua_pcall(this->luactx, 0, 0, 0)) + { + print_error(this, "Failed to load the script \"%s\"", script); + free(script); + return false; + } + free(script); + return true; } /** @@ -319,11 +319,11 @@ bool load_device_script(IDSIMMODEL *this, const char *device_name) static int lua_get_string_param(lua_State *L) { - safe_execute(L, &lua_get_string_param); - char *str = (char *)lua_tostring(L, FIRST_ARG); - IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); - lua_pushstring(L, get_string_param(this, str)); - return 1; + safe_execute(L, &lua_get_string_param); + char *str = (char *)lua_tostring(L, FIRST_ARG); + IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); + lua_pushstring(L, get_string_param(this, str)); + return 1; } /** @@ -344,11 +344,11 @@ lua_get_string_param(lua_State *L) static int lua_get_bool_param(lua_State *L) { - safe_execute(L, &lua_get_bool_param); - char *str = (char *)lua_tostring(L, FIRST_ARG); - IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); - lua_pushinteger(L, get_bool_param(this, str)); - return 1; + safe_execute(L, &lua_get_bool_param); + char *str = (char *)lua_tostring(L, FIRST_ARG); + IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); + lua_pushinteger(L, get_bool_param(this, str)); + return 1; } /** @@ -369,11 +369,11 @@ lua_get_bool_param(lua_State *L) static int lua_get_num_param(lua_State *L) { - safe_execute(L, &lua_get_num_param); - char *str = (char *)lua_tostring(L, FIRST_ARG); - IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); - lua_pushinteger(L, get_num_param(this, str)); - return 1; + safe_execute(L, &lua_get_num_param); + char *str = (char *)lua_tostring(L, FIRST_ARG); + IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); + lua_pushinteger(L, get_num_param(this, str)); + return 1; } /** @@ -394,11 +394,11 @@ lua_get_num_param(lua_State *L) static int lua_get_hex_param(lua_State *L) { - safe_execute(L, &lua_get_hex_param); - char *str = (char *)lua_tostring(L, FIRST_ARG); - IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); - lua_pushinteger(L, get_hex_param(this, str)); - return 1; + safe_execute(L, &lua_get_hex_param); + char *str = (char *)lua_tostring(L, FIRST_ARG); + IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); + lua_pushinteger(L, get_hex_param(this, str)); + return 1; } /** @@ -419,11 +419,11 @@ lua_get_hex_param(lua_State *L) static int lua_get_init_param(lua_State *L) { - safe_execute(L, &lua_get_init_param); - char *str = (char *)lua_tostring(L, FIRST_ARG); - IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); - lua_pushinteger(L, get_init_param(this, str)); - return 1; + safe_execute(L, &lua_get_init_param); + char *str = (char *)lua_tostring(L, FIRST_ARG); + IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); + lua_pushinteger(L, get_init_param(this, str)); + return 1; } /** @@ -444,11 +444,11 @@ lua_get_init_param(lua_State *L) static int lua_delete_popup(lua_State *L) { - safe_execute(L, &lua_delete_popup); - ptrdiff_t id = lua_tointeger(L, FIRST_ARG); - IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); - delete_popup(this, id); - return 0; + safe_execute(L, &lua_delete_popup); + ptrdiff_t id = lua_tointeger(L, FIRST_ARG); + IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); + delete_popup(this, id); + return 0; } /** @@ -469,12 +469,12 @@ lua_delete_popup(lua_State *L) static int lua_create_debug_popup(lua_State *L) { - safe_execute(L, &lua_create_debug_popup); - const char *text = lua_tostring(L, FIRST_ARG); - IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); - lua_pushlightuserdata(L, create_debug_popup(this, text, ++this->popup_id)); - lua_pushinteger(L, this->popup_id); - return 2; + safe_execute(L, &lua_create_debug_popup); + const char *text = lua_tostring(L, FIRST_ARG); + IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); + lua_pushlightuserdata(L, create_debug_popup(this, text, ++this->popup_id)); + lua_pushinteger(L, this->popup_id); + return 2; } /** @@ -495,11 +495,11 @@ lua_create_debug_popup(lua_State *L) static int lua_print_to_debug_popup(lua_State *L) { - safe_execute(L, &lua_print_to_debug_popup); - const char *str = lua_tostring(L, FIRST_ARG); - void *popup = lua_touserdata(L, SECOND_ARG); - print_to_debug_popup(popup, str); - return 0; + safe_execute(L, &lua_print_to_debug_popup); + const char *str = lua_tostring(L, FIRST_ARG); + void *popup = lua_touserdata(L, SECOND_ARG); + print_to_debug_popup(popup, str); + return 0; } /** @@ -520,13 +520,13 @@ lua_print_to_debug_popup(lua_State *L) static int lua_dump_to_debug_popup(lua_State *L) { - safe_execute(L, &lua_dump_to_debug_popup); - lua_Number offset = luaL_checknumber(L, FIRST_ARG); - lua_Number size = luaL_checknumber(L, SECOND_ARG); - const char *buf = luaL_checkstring(L, THIRD_ARG); - void *popup = lua_touserdata(L, FORTH_ARG); - dump_to_debug_popup(popup, (BYTE *)buf, offset, size); - return 0; + safe_execute(L, &lua_dump_to_debug_popup); + lua_Number offset = luaL_checknumber(L, FIRST_ARG); + lua_Number size = luaL_checknumber(L, SECOND_ARG); + const char *buf = luaL_checkstring(L, THIRD_ARG); + void *popup = lua_touserdata(L, FORTH_ARG); + dump_to_debug_popup(popup, (BYTE *)buf, offset, size); + return 0; } /** @@ -547,12 +547,12 @@ lua_dump_to_debug_popup(lua_State *L) static int lua_create_source_popup(lua_State *L) { - safe_execute(L, &lua_create_source_popup); - const char *text = lua_tostring(L, FIRST_ARG); - IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); - lua_pushlightuserdata(L, create_source_popup(this, text, ++this->popup_id)); - lua_pushinteger(L, this->popup_id); - return 2; + safe_execute(L, &lua_create_source_popup); + const char *text = lua_tostring(L, FIRST_ARG); + IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); + lua_pushlightuserdata(L, create_source_popup(this, text, ++this->popup_id)); + lua_pushinteger(L, this->popup_id); + return 2; } /** @@ -573,12 +573,12 @@ lua_create_source_popup(lua_State *L) static int lua_create_status_popup(lua_State *L) { - safe_execute(L, &lua_create_status_popup); - const char *text = lua_tostring(L, FIRST_ARG); - IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); - lua_pushlightuserdata(L, create_status_popup(this, text, ++this->popup_id)); - lua_pushinteger(L, this->popup_id); - return 2; + safe_execute(L, &lua_create_status_popup); + const char *text = lua_tostring(L, FIRST_ARG); + IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); + lua_pushlightuserdata(L, create_status_popup(this, text, ++this->popup_id)); + lua_pushinteger(L, this->popup_id); + return 2; } /** @@ -599,12 +599,12 @@ lua_create_status_popup(lua_State *L) static int lua_create_var_popup(lua_State *L) { - safe_execute(L, &lua_create_var_popup); - const char *text = lua_tostring(L, FIRST_ARG); - IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); - lua_pushlightuserdata(L, create_var_popup(this, text, ++this->popup_id)); - lua_pushinteger(L, this->popup_id); - return 2; + safe_execute(L, &lua_create_var_popup); + const char *text = lua_tostring(L, FIRST_ARG); + IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); + lua_pushlightuserdata(L, create_var_popup(this, text, ++this->popup_id)); + lua_pushinteger(L, this->popup_id); + return 2; } /** @@ -625,12 +625,12 @@ lua_create_var_popup(lua_State *L) static int lua_create_memory_popup(lua_State *L) { - safe_execute(L, &lua_create_memory_popup); - const char *text = lua_tostring(L, FIRST_ARG); - IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); - lua_pushlightuserdata(L, create_memory_popup(this, text, ++this->popup_id)); - lua_pushinteger(L, this->popup_id); - return 2; + safe_execute(L, &lua_create_memory_popup); + const char *text = lua_tostring(L, FIRST_ARG); + IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); + lua_pushlightuserdata(L, create_memory_popup(this, text, ++this->popup_id)); + lua_pushinteger(L, this->popup_id); + return 2; } /** @@ -651,13 +651,13 @@ lua_create_memory_popup(lua_State *L) static int lua_set_memory_popup(lua_State *L) { - safe_execute(L, &lua_set_memory_popup); - lua_Number size = luaL_checknumber(L, FIRST_ARG); - const char *buf = luaL_checkstring(L, SECOND_ARG); - void *popup = lua_touserdata(L, THIRD_ARG); - set_memory_popup(popup, 0, (void *)buf, size); + safe_execute(L, &lua_set_memory_popup); + lua_Number size = luaL_checknumber(L, FIRST_ARG); + const char *buf = luaL_checkstring(L, SECOND_ARG); + void *popup = lua_touserdata(L, THIRD_ARG); + set_memory_popup(popup, 0, (void *)buf, size); - return 0; + return 0; } /** @@ -678,14 +678,14 @@ lua_set_memory_popup(lua_State *L) static int lua_add_source_file(lua_State *L) { - safe_execute(L, &lua_add_source_file); - if (false == add_source_file(lua_touserdata(L, THIRD_ARG), (char *)lua_tostring(L, SECOND_ARG), lua_tointeger(L, FIRST_ARG))) - { - IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); - print_info(this, "Fail to load source file"); - } - - return 0; + safe_execute(L, &lua_add_source_file); + if (false == add_source_file(lua_touserdata(L, THIRD_ARG), (char *)lua_tostring(L, SECOND_ARG), lua_tointeger(L, FIRST_ARG))) + { + IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); + print_info(this, "Fail to load source file"); + } + + return 0; } /** @@ -706,10 +706,10 @@ lua_add_source_file(lua_State *L) static int lua_repaint_memory_popup(lua_State *L) { - safe_execute(L, &lua_repaint_memory_popup); - void *popup = lua_touserdata(L, FIRST_ARG); - repaint_memory_popup(popup); - return 0; + safe_execute(L, &lua_repaint_memory_popup); + void *popup = lua_touserdata(L, FIRST_ARG); + repaint_memory_popup(popup); + return 0; } /** @@ -730,12 +730,12 @@ lua_repaint_memory_popup(lua_State *L) static int lua_state_to_string(lua_State *L) { - safe_execute(L, &lua_state_to_string); - ptrdiff_t state = lua_tointeger(L, FIRST_ARG); - IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); + safe_execute(L, &lua_state_to_string); + ptrdiff_t state = lua_tointeger(L, FIRST_ARG); + IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); - lua_pushstring(L, state_to_string(state)); - return 1; + lua_pushstring(L, state_to_string(state)); + return 1; } /** @@ -756,11 +756,11 @@ lua_state_to_string(lua_State *L) static int lua_print_info(lua_State *L) { - safe_execute(L, &lua_print_info); - const char *text = lua_tostring(L, FIRST_ARG); - IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); - print_info(this, text); - return 0; + safe_execute(L, &lua_print_info); + const char *text = lua_tostring(L, FIRST_ARG); + IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); + print_info(this, text); + return 0; } /** @@ -781,11 +781,11 @@ lua_print_info(lua_State *L) static int lua_print_message(lua_State *L) { - safe_execute(L, &lua_print_message); - const char *text = lua_tostring(L, FIRST_ARG); - IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); - print_message(this, text); - return 0; + safe_execute(L, &lua_print_message); + const char *text = lua_tostring(L, FIRST_ARG); + IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); + print_message(this, text); + return 0; } /** @@ -806,11 +806,11 @@ lua_print_message(lua_State *L) static int lua_print_warning(lua_State *L) { - safe_execute(L, &lua_print_warning); - const char *text = lua_tostring(L, FIRST_ARG); - IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); - print_warning(this, text); - return 0; + safe_execute(L, &lua_print_warning); + const char *text = lua_tostring(L, FIRST_ARG); + IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); + print_warning(this, text); + return 0; } /** @@ -831,11 +831,11 @@ lua_print_warning(lua_State *L) static int lua_print_error(lua_State *L) { - safe_execute(L, &lua_print_error); - const char *text = lua_tostring(L, FIRST_ARG); - IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); - print_error(this, text); - return 0; + safe_execute(L, &lua_print_error); + const char *text = lua_tostring(L, FIRST_ARG); + IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); + print_error(this, text); + return 0; } /** @@ -856,12 +856,12 @@ lua_print_error(lua_State *L) static int lua_set_callback(lua_State *L) { - safe_execute(L, &lua_set_callback); - lua_Number picotime = lua_tointeger(L, SECOND_ARG); - lua_Number eventid = lua_tointeger(L, FIRST_ARG); - IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); - set_callback(this, picotime, eventid); - return 0; + safe_execute(L, &lua_set_callback); + lua_Number picotime = lua_tointeger(L, SECOND_ARG); + lua_Number eventid = lua_tointeger(L, FIRST_ARG); + IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); + set_callback(this, picotime, eventid); + return 0; } /** @@ -882,9 +882,9 @@ lua_set_callback(lua_State *L) static int lua_get_systime(lua_State *L) { - ABSTIME curtime = 0; - IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); - systime(this, &curtime); - lua_pushinteger(L, curtime); - return 1; + ABSTIME curtime = 0; + IDSIMMODEL *this = (IDSIMMODEL *)lua_get_model_obj(L); + systime(this, &curtime); + lua_pushinteger(L, curtime); + return 1; } diff --git a/src/lua_pin.c b/src/lua_pin.c index 27c3f0b..1cc6a05 100755 --- a/src/lua_pin.c +++ b/src/lua_pin.c @@ -27,67 +27,67 @@ void register_pin_obj(lua_State *L, int num, char *name) { - lua_newtable(L); - lua_pushstring(L, TEXT_PIN_FIELD); - lua_pushinteger(L, num); - lua_rawset(L, -3); - lua_pushstring(L, TEXT_HI_FIELD); - lua_pushcfunction(L, pin_set_hi); - lua_rawset(L, -3); - lua_pushstring(L, TEXT_LO_FIELD); - lua_pushcfunction(L, pin_set_lo); - lua_rawset(L, -3); - lua_pushstring(L, TEXT_FL_FIELD); - lua_pushcfunction(L, pin_set_fl); - lua_rawset(L, -3); - lua_pushstring(L, TEXT_TOGGLE_FIELD); - lua_pushcfunction(L, pin_toggle); - lua_rawset(L, -3); - lua_pushstring(L, TEXT_SET_FIELD); - lua_pushcfunction(L, pin_set); - lua_rawset(L, -3); - lua_pushstring(L, TEXT_GET_FIELD); - lua_pushcfunction(L, pin_get); - lua_rawset(L, -3); - lua_pushstring(L, TEXT_IS_HI_FIELD); - lua_pushcfunction(L, pin_is_hi); - lua_rawset(L, -3); - lua_pushstring(L, TEXT_IS_LO_FIELD); - lua_pushcfunction(L, pin_is_lo); - lua_rawset(L, -3); - lua_pushstring(L, TEXT_IS_FL_FIELD); - lua_pushcfunction(L, pin_is_fl); - lua_rawset(L, -3); - lua_pushstring(L, TEXT_IS_EDGE_FIELD); - lua_pushcfunction(L, pin_is_edge); - lua_rawset(L, -3); - lua_pushstring(L, TEXT_IS_PEDGE_FIELD); - lua_pushcfunction(L, pin_is_pedge); - lua_rawset(L, -3); - lua_pushstring(L, TEXT_IS_NEDGE_FIELD); - lua_pushcfunction(L, pin_is_nedge); - lua_rawset(L, -3); - lua_pushstring(L, TEXT_IS_STEADY_FIELD); - lua_pushcfunction(L, pin_is_steady); - lua_rawset(L, -3); - lua_pushstring(L, TEXT_IS_ACTIVE_FIELD); - lua_pushcfunction(L, pin_is_active); - lua_rawset(L, -3); - lua_pushstring(L, TEXT_IS_INACTIVE_FIELD); - lua_pushcfunction(L, pin_is_inactive); - lua_rawset(L, -3); - lua_pushstring(L, TEXT_IS_INVERTED_FIELD); - lua_pushcfunction(L, pin_is_inverted); - lua_rawset(L, -3); - lua_pushstring(L, TEXT_SET_STATE_FIELD); - lua_pushcfunction(L, pin_set_state); - lua_rawset(L, -3); - lua_pushstring(L, TEXT_GET_STATE_FIELD); - lua_pushcfunction(L, pin_get_state); - lua_rawset(L, -3); - - lua_setglobal(L, name); - lua_pop(L, 1); + lua_newtable(L); + lua_pushstring(L, TEXT_PIN_FIELD); + lua_pushinteger(L, num); + lua_rawset(L, -3); + lua_pushstring(L, TEXT_HI_FIELD); + lua_pushcfunction(L, pin_set_hi); + lua_rawset(L, -3); + lua_pushstring(L, TEXT_LO_FIELD); + lua_pushcfunction(L, pin_set_lo); + lua_rawset(L, -3); + lua_pushstring(L, TEXT_FL_FIELD); + lua_pushcfunction(L, pin_set_fl); + lua_rawset(L, -3); + lua_pushstring(L, TEXT_TOGGLE_FIELD); + lua_pushcfunction(L, pin_toggle); + lua_rawset(L, -3); + lua_pushstring(L, TEXT_SET_FIELD); + lua_pushcfunction(L, pin_set); + lua_rawset(L, -3); + lua_pushstring(L, TEXT_GET_FIELD); + lua_pushcfunction(L, pin_get); + lua_rawset(L, -3); + lua_pushstring(L, TEXT_IS_HI_FIELD); + lua_pushcfunction(L, pin_is_hi); + lua_rawset(L, -3); + lua_pushstring(L, TEXT_IS_LO_FIELD); + lua_pushcfunction(L, pin_is_lo); + lua_rawset(L, -3); + lua_pushstring(L, TEXT_IS_FL_FIELD); + lua_pushcfunction(L, pin_is_fl); + lua_rawset(L, -3); + lua_pushstring(L, TEXT_IS_EDGE_FIELD); + lua_pushcfunction(L, pin_is_edge); + lua_rawset(L, -3); + lua_pushstring(L, TEXT_IS_PEDGE_FIELD); + lua_pushcfunction(L, pin_is_pedge); + lua_rawset(L, -3); + lua_pushstring(L, TEXT_IS_NEDGE_FIELD); + lua_pushcfunction(L, pin_is_nedge); + lua_rawset(L, -3); + lua_pushstring(L, TEXT_IS_STEADY_FIELD); + lua_pushcfunction(L, pin_is_steady); + lua_rawset(L, -3); + lua_pushstring(L, TEXT_IS_ACTIVE_FIELD); + lua_pushcfunction(L, pin_is_active); + lua_rawset(L, -3); + lua_pushstring(L, TEXT_IS_INACTIVE_FIELD); + lua_pushcfunction(L, pin_is_inactive); + lua_rawset(L, -3); + lua_pushstring(L, TEXT_IS_INVERTED_FIELD); + lua_pushcfunction(L, pin_is_inverted); + lua_rawset(L, -3); + lua_pushstring(L, TEXT_SET_STATE_FIELD); + lua_pushcfunction(L, pin_set_state); + lua_rawset(L, -3); + lua_pushstring(L, TEXT_GET_STATE_FIELD); + lua_pushcfunction(L, pin_get_state); + lua_rawset(L, -3); + + lua_setglobal(L, name); + lua_pop(L, 1); } /** @@ -105,14 +105,14 @@ void register_pin_obj(lua_State *L, int num, char *name) static int get_pin_self(lua_State *L) { - IDSIMMODEL *model = (IDSIMMODEL *)lua_get_model_obj(L); - if (0 == lua_istable(L, -lua_gettop(L))) // take the first element - { - print_error(model, TEXT_NO_PIN_OBJECT_FOUND); - } - lua_pushstring(L, TEXT_PIN_FIELD); /// this fields contains pin index - lua_gettable(L, -lua_gettop(L)); // take the first element - return lua_tointeger(L, -1); + IDSIMMODEL *model = (IDSIMMODEL *)lua_get_model_obj(L); + if (0 == lua_istable(L, -lua_gettop(L))) // take the first element + { + print_error(model, TEXT_NO_PIN_OBJECT_FOUND); + } + lua_pushstring(L, TEXT_PIN_FIELD); /// this fields contains pin index + lua_gettable(L, -lua_gettop(L)); // take the first element + return lua_tointeger(L, -1); } /** @@ -130,10 +130,10 @@ static int get_pin_self(lua_State *L) static int pin_set_hi(lua_State *L) { - IDSIMMODEL *model = (IDSIMMODEL *)lua_get_model_obj(L); - int pin_num = get_pin_self(L); - set_pin_state(model, model->device_pins[pin_num], LOGIC_HI); - return 0; + IDSIMMODEL *model = (IDSIMMODEL *)lua_get_model_obj(L); + int pin_num = get_pin_self(L); + set_pin_state(model, model->device_pins[pin_num], LOGIC_HI); + return 0; } /** @@ -151,10 +151,10 @@ static int pin_set_hi(lua_State *L) static int pin_set_lo(lua_State *L) { - IDSIMMODEL *model = (IDSIMMODEL *)lua_get_model_obj(L); - int pin_num = get_pin_self(L); - set_pin_state(model, model->device_pins[pin_num], LOGIC_LO); - return 0; + IDSIMMODEL *model = (IDSIMMODEL *)lua_get_model_obj(L); + int pin_num = get_pin_self(L); + set_pin_state(model, model->device_pins[pin_num], LOGIC_LO); + return 0; } /** @@ -172,10 +172,10 @@ static int pin_set_lo(lua_State *L) static int pin_set_fl(lua_State *L) { - IDSIMMODEL *model = (IDSIMMODEL *)lua_get_model_obj(L); - int pin_num = get_pin_self(L); - set_pin_state(model, model->device_pins[pin_num], LOGIC_FLT); - return 0; + IDSIMMODEL *model = (IDSIMMODEL *)lua_get_model_obj(L); + int pin_num = get_pin_self(L); + set_pin_state(model, model->device_pins[pin_num], LOGIC_FLT); + return 0; } /** @@ -193,11 +193,11 @@ static int pin_set_fl(lua_State *L) static int pin_get(lua_State *L) { - IDSIMMODEL *model = (IDSIMMODEL *)lua_get_model_obj(L); - int pin_num = get_pin_self(L); - int result = get_pin_bool(model->device_pins[pin_num]); - lua_pushinteger(L, result); - return 1; + IDSIMMODEL *model = (IDSIMMODEL *)lua_get_model_obj(L); + int pin_num = get_pin_self(L); + int result = get_pin_bool(model->device_pins[pin_num]); + lua_pushinteger(L, result); + return 1; } /** @@ -215,11 +215,11 @@ static int pin_get(lua_State *L) static int pin_set(lua_State *L) { - IDSIMMODEL *model = (IDSIMMODEL *)lua_get_model_obj(L); - int pin_num = get_pin_self(L); - int value = lua_tointeger(L, -2); - set_pin_bool(model, model->device_pins[pin_num], value); - return 0; + IDSIMMODEL *model = (IDSIMMODEL *)lua_get_model_obj(L); + int pin_num = get_pin_self(L); + int value = lua_tointeger(L, -2); + set_pin_bool(model, model->device_pins[pin_num], value); + return 0; } /** @@ -237,10 +237,10 @@ static int pin_set(lua_State *L) static int pin_is_edge(lua_State *L) { - IDSIMMODEL *model = (IDSIMMODEL *)lua_get_model_obj(L); - int pin_num = get_pin_self(L); - lua_pushinteger(L, is_pin_edge(model->device_pins[pin_num].pin)); - return 1; + IDSIMMODEL *model = (IDSIMMODEL *)lua_get_model_obj(L); + int pin_num = get_pin_self(L); + lua_pushinteger(L, is_pin_edge(model->device_pins[pin_num].pin)); + return 1; } /** @@ -258,10 +258,10 @@ static int pin_is_edge(lua_State *L) static int pin_is_pedge(lua_State *L) { - IDSIMMODEL *model = (IDSIMMODEL *)lua_get_model_obj(L); - int pin_num = get_pin_self(L); - lua_pushinteger(L, is_pin_posedge(model->device_pins[pin_num].pin)); - return 1; + IDSIMMODEL *model = (IDSIMMODEL *)lua_get_model_obj(L); + int pin_num = get_pin_self(L); + lua_pushinteger(L, is_pin_posedge(model->device_pins[pin_num].pin)); + return 1; } /** @@ -279,10 +279,10 @@ static int pin_is_pedge(lua_State *L) static int pin_is_nedge(lua_State *L) { - IDSIMMODEL *model = (IDSIMMODEL *)lua_get_model_obj(L); - int pin_num = get_pin_self(L); - lua_pushinteger(L, is_pin_negedge(model->device_pins[pin_num].pin)); - return 1; + IDSIMMODEL *model = (IDSIMMODEL *)lua_get_model_obj(L); + int pin_num = get_pin_self(L); + lua_pushinteger(L, is_pin_negedge(model->device_pins[pin_num].pin)); + return 1; } /** @@ -300,10 +300,10 @@ static int pin_is_nedge(lua_State *L) static int pin_is_inverted(lua_State *L) { - IDSIMMODEL *model = (IDSIMMODEL *)lua_get_model_obj(L); - int pin_num = get_pin_self(L); - lua_pushinteger(L, is_pin_inverted(model->device_pins[pin_num].pin)); - return 1; + IDSIMMODEL *model = (IDSIMMODEL *)lua_get_model_obj(L); + int pin_num = get_pin_self(L); + lua_pushinteger(L, is_pin_inverted(model->device_pins[pin_num].pin)); + return 1; } /** @@ -321,10 +321,10 @@ static int pin_is_inverted(lua_State *L) static int pin_is_steady(lua_State *L) { - IDSIMMODEL *model = (IDSIMMODEL *)lua_get_model_obj(L); - int pin_num = get_pin_self(L); - lua_pushinteger(L, is_pin_steady(model->device_pins[pin_num].pin)); - return 1; + IDSIMMODEL *model = (IDSIMMODEL *)lua_get_model_obj(L); + int pin_num = get_pin_self(L); + lua_pushinteger(L, is_pin_steady(model->device_pins[pin_num].pin)); + return 1; } /** @@ -342,10 +342,10 @@ static int pin_is_steady(lua_State *L) static int pin_is_active(lua_State *L) { - IDSIMMODEL *model = (IDSIMMODEL *)lua_get_model_obj(L); - int pin_num = get_pin_self(L); - lua_pushinteger(L, is_pin_active(model->device_pins[pin_num].pin)); - return 1; + IDSIMMODEL *model = (IDSIMMODEL *)lua_get_model_obj(L); + int pin_num = get_pin_self(L); + lua_pushinteger(L, is_pin_active(model->device_pins[pin_num].pin)); + return 1; } /** @@ -363,10 +363,10 @@ static int pin_is_active(lua_State *L) static int pin_is_inactive(lua_State *L) { - IDSIMMODEL *model = (IDSIMMODEL *)lua_get_model_obj(L); - int pin_num = get_pin_self(L); - lua_pushinteger(L, is_pin_inactive(model->device_pins[pin_num].pin)); - return 1; + IDSIMMODEL *model = (IDSIMMODEL *)lua_get_model_obj(L); + int pin_num = get_pin_self(L); + lua_pushinteger(L, is_pin_inactive(model->device_pins[pin_num].pin)); + return 1; } /** @@ -384,11 +384,11 @@ static int pin_is_inactive(lua_State *L) static int pin_set_state(lua_State *L) { - IDSIMMODEL *model = (IDSIMMODEL *)lua_get_model_obj(L); - int pin_num = get_pin_self(L); - int pin_state = lua_tointeger(L, -1); - set_pin_state(model, model->device_pins[pin_num], pin_state); - return 0; + IDSIMMODEL *model = (IDSIMMODEL *)lua_get_model_obj(L); + int pin_num = get_pin_self(L); + int pin_state = lua_tointeger(L, -1); + set_pin_state(model, model->device_pins[pin_num], pin_state); + return 0; } /** @@ -406,10 +406,10 @@ static int pin_set_state(lua_State *L) static int pin_get_state(lua_State *L) { - IDSIMMODEL *model = (IDSIMMODEL *)lua_get_model_obj(L); - int pin_num = get_pin_self(L); - lua_pushinteger(L, get_pin_state(model->device_pins[pin_num].pin)); - return 1; + IDSIMMODEL *model = (IDSIMMODEL *)lua_get_model_obj(L); + int pin_num = get_pin_self(L); + lua_pushinteger(L, get_pin_state(model->device_pins[pin_num].pin)); + return 1; } /** @@ -427,10 +427,10 @@ static int pin_get_state(lua_State *L) static int pin_is_hi(lua_State *L) { - IDSIMMODEL *model = (IDSIMMODEL *)lua_get_model_obj(L); - int pin_num = get_pin_self(L); - lua_pushinteger(L, is_pin_high(model->device_pins[pin_num].pin)); - return 1; + IDSIMMODEL *model = (IDSIMMODEL *)lua_get_model_obj(L); + int pin_num = get_pin_self(L); + lua_pushinteger(L, is_pin_high(model->device_pins[pin_num].pin)); + return 1; } /** @@ -448,10 +448,10 @@ static int pin_is_hi(lua_State *L) static int pin_is_lo(lua_State *L) { - IDSIMMODEL *model = (IDSIMMODEL *)lua_get_model_obj(L); - int pin_num = get_pin_self(L); - lua_pushinteger(L, is_pin_low(model->device_pins[pin_num].pin)); - return 1; + IDSIMMODEL *model = (IDSIMMODEL *)lua_get_model_obj(L); + int pin_num = get_pin_self(L); + lua_pushinteger(L, is_pin_low(model->device_pins[pin_num].pin)); + return 1; } /** @@ -469,10 +469,10 @@ static int pin_is_lo(lua_State *L) static int pin_is_fl(lua_State *L) { - IDSIMMODEL *model = (IDSIMMODEL *)lua_get_model_obj(L); - int pin_num = get_pin_self(L); - lua_pushinteger(L, is_pin_floating(model->device_pins[pin_num].pin)); - return 1; + IDSIMMODEL *model = (IDSIMMODEL *)lua_get_model_obj(L); + int pin_num = get_pin_self(L); + lua_pushinteger(L, is_pin_floating(model->device_pins[pin_num].pin)); + return 1; } /** @@ -490,16 +490,16 @@ static int pin_is_fl(lua_State *L) static int pin_toggle(lua_State *L) { - IDSIMMODEL *model = (IDSIMMODEL *)lua_get_model_obj(L); - int pin_num = get_pin_self(L); - int val = get_pin_bool(model->device_pins[pin_num]); - if (val > 0) - { - set_pin_bool(model, model->device_pins[pin_num], 0); - } - else - { - set_pin_bool(model, model->device_pins[pin_num], 1); - } - return 0; + IDSIMMODEL *model = (IDSIMMODEL *)lua_get_model_obj(L); + int pin_num = get_pin_self(L); + int val = get_pin_bool(model->device_pins[pin_num]); + if (val > 0) + { + set_pin_bool(model, model->device_pins[pin_num], 0); + } + else + { + set_pin_bool(model, model->device_pins[pin_num], 1); + } + return 0; } diff --git a/src/lua_vsmobj.c b/src/lua_vsmobj.c index 37cc83c..5146bca 100755 --- a/src/lua_vsmobj.c +++ b/src/lua_vsmobj.c @@ -10,24 +10,11 @@ #include -/**********************************************************************************************/ /** - * \fn void* lua_get_model_obj ( lua_State* L ) - * - * \brief Lua get model object. - * - * \author Pugnator - * \date 11/22/2015 - * - * \param [in,out] L If non-null, the lua_State to process. - * - * \return null if it fails, else a void*. - **/ - void *lua_get_model_obj(lua_State *L) { - lua_pushliteral(L, "__this"); - lua_gettable(L, LUA_REGISTRYINDEX); - void *this = lua_touserdata(L, -1); - lua_pop(L, 1); - return this; + lua_pushliteral(L, "__this"); + lua_gettable(L, LUA_REGISTRYINDEX); + void *this = lua_touserdata(L, -1); + lua_pop(L, 1); + return this; } diff --git a/src/vsmapi.c b/src/vsmapi.c index 812d079..a462a5b 100755 --- a/src/vsmapi.c +++ b/src/vsmapi.c @@ -16,108 +16,108 @@ /** \brief The vsm device vtable. */ IDSIMMODEL_vtable VSM_DEVICE_vtable = - { - .isdigital = vsm_isdigital, - .setup = vsm_setup, - .runctrl = vsm_runctrl, - .actuate = vsm_actuate, - .indicate = vsm_indicate, - .simulate = vsm_simulate, - .callback = vsm_timer_callback, + { + .isdigital = vsm_isdigital, + .setup = vsm_setup, + .runctrl = vsm_runctrl, + .actuate = vsm_actuate, + .indicate = vsm_indicate, + .simulate = vsm_simulate, + .callback = vsm_timer_callback, }; /** \brief The icpu device vtable. */ ICPU_vtable ICPU_DEVICE_vtable = - { - .vdmhlr = icpu_vdmhlr, - .loaddata = icpu_loaddata, - .disassemble = icpu_disassemble, - .getvardata = icpu_getvardata, + { + .vdmhlr = icpu_vdmhlr, + .loaddata = icpu_loaddata, + .disassemble = icpu_disassemble, + .getvardata = icpu_getvardata, }; /** \brief The icpu device. */ ICPU ICPU_DEVICE = - { - .vtable = &ICPU_DEVICE_vtable, + { + .vtable = &ICPU_DEVICE_vtable, }; #ifdef _MSC_VER __declspec(dllexport) #endif - /** - * \fn IDSIMMODEL* __CDECL__ createdsimmodel ( char* device, ILICENCESERVER* ils ) - * - * \brief Createdsimmodels. - * - * \author Pugnator - * \date 11/21/2015 - * - * \param [in,out] device If non-null, the device. - * \param [in,out] ils If non-null, the ils. - * - * \return null if it fails, else an IDSIMMODEL*. - * - * ### remarks Pugnator, 11/21/2015. - */ - - IDSIMMODEL *__CDECL__ - createdsimmodel(char *device, ILICENCESERVER *ils) + /** + * \fn IDSIMMODEL* __CDECL__ createdsimmodel ( char* device, ILICENCESERVER* ils ) + * + * \brief Createdsimmodels. + * + * \author Pugnator + * \date 11/21/2015 + * + * \param [in,out] device If non-null, the device. + * \param [in,out] ils If non-null, the ils. + * + * \return null if it fails, else an IDSIMMODEL*. + * + * ### remarks Pugnator, 11/21/2015. + */ + + IDSIMMODEL *__CDECL__ + createdsimmodel(char *device, ILICENCESERVER *ils) { - (void)device; - srand(time(0)); - if (0 == vsm_register(ils)) - { - return NULL; - } - - IDSIMMODEL *vdev = malloc(sizeof *vdev); - /* Assign virtual table to the object */ - vdev->vtable = &VSM_DEVICE_vtable; - /* Init Lua */ - vdev->luactx = luaL_newstate(); - /* Open Lua libraries */ - vdev->trace = NULL; - vdev->popup_id = 0; - luaL_openlibs(vdev->luactx); - register_functions(vdev, vdev->luactx); - return vdev; + (void)device; + srand(time(0)); + if (0 == vsm_register(ils)) + { + return NULL; + } + + IDSIMMODEL *vdev = malloc(sizeof *vdev); + /* Assign virtual table to the object */ + vdev->vtable = &VSM_DEVICE_vtable; + /* Init Lua */ + vdev->luactx = luaL_newstate(); + /* Open Lua libraries */ + vdev->trace = NULL; + vdev->popup_id = 0; + luaL_openlibs(vdev->luactx); + register_functions(vdev, vdev->luactx); + return vdev; } #ifdef _MSC_VER __declspec(dllexport) #endif - /** - * \fn void __CDECL__ deletedsimmodel ( IDSIMMODEL* model ) - * - * \brief Deletedsimmodels the given model. - * - * \author Pugnator - * \date 11/21/2015 - * - * \param [in,out] model If non-null, the model. - * - * ### remarks Pugnator, 11/21/2015. - */ - - void __CDECL__ - deletedsimmodel(IDSIMMODEL *model) + /** + * \fn void __CDECL__ deletedsimmodel ( IDSIMMODEL* model ) + * + * \brief Deletedsimmodels the given model. + * + * \author Pugnator + * \date 11/21/2015 + * + * \param [in,out] model If non-null, the model. + * + * ### remarks Pugnator, 11/21/2015. + */ + + void __CDECL__ + deletedsimmodel(IDSIMMODEL *model) { - /* Close Lua */ - // lua_close ( model->luactx ); - /* Remove device object */ - free(model); + /* Close Lua */ + // lua_close ( model->luactx ); + /* Remove device object */ + free(model); } int32_t __FASTCALL__ vsm_isdigital(IDSIMMODEL *this, uint32_t edx, char *pinname) { - (void)this; - (void)edx; - (void)pinname; - /* Always true at the moment */ - return 1; + (void)this; + (void)edx; + (void)pinname; + /* Always true at the moment */ + return 1; } /** @@ -155,163 +155,163 @@ pinhandler(IDSIMPIN *pin, uint32_t edx) void __FASTCALL__ vsm_setup(IDSIMMODEL *this, uint32_t edx, IINSTANCE *instance, IDSIMCKT *dsimckt) { - (void)edx; - - this->model_instance = instance; - this->model_dsim = dsimckt; - /*Init xor shift PRNG*/ - this->xorseed[0] = rand64bits(); - this->xorseed[1] = rand64bits(); - - lua_load_modules(this); - - char *device_script = get_string_param(this, "lua"); - /* If user uses precompiled device script - don't load external script */ - lua_getglobal(this->luactx, "__USE_PRECOMPILED"); - if (0xDEADC0DE == lua_tointeger(this->luactx, lua_gettop(this->luactx)) || '?' == *device_script) - { - print_info(this, "%s started [OpenVSM %s, precompiled device script] %s", get_device_id(this), __VERSION, LUA_RELEASE); - } - else - { - if (!load_device_script(this, device_script)) - { - return; - } - print_info(this, "%s started [OpenVSM %s, %s] %s", get_device_id(this), __VERSION, device_script, LUA_RELEASE); - } - - lua_getglobal(this->luactx, "device_init"); - if (lua_isfunction(this->luactx, lua_gettop(this->luactx))) - { - this->device_init_declared = true; - } - - lua_getglobal(this->luactx, "timer_callback"); - if (lua_isfunction(this->luactx, lua_gettop(this->luactx))) - { - this->timer_callback_declared = true; - } - - lua_getglobal(this->luactx, "device_simulate"); - if (lua_isfunction(this->luactx, lua_gettop(this->luactx))) - { - this->device_simulate_declared = true; - } - - lua_getglobal(this->luactx, "device_pins"); - if (0 == lua_istable(this->luactx, -1)) - { - print_error(this, "Fatal error, no pin assignments found in script"); - return; - } - lua_len(this->luactx, -1); - int32_t pin_number = lua_tointeger(this->luactx, -1); - if (!pin_number) - { - print_warning(this, "IC has no pins"); - } - lua_pop(this->luactx, 1); - /* Pins initialization */ - char name_orig[64] = {0}; - for (int i = 1; i <= pin_number; i++) - { - lua_rawgeti(this->luactx, -1, i); - ////////////// - // set pin // - ////////////// - lua_getfield(this->luactx, -1, PIN_NAME); - char *pin_name = (char *)lua_tostring(this->luactx, -1); - strcpy(name_orig, pin_name); - /* Replace leading AND trailing underscore with $ sign */ - if ('$' == pin_name[0] || '$' == pin_name[strlen(pin_name)]) - { - memmove(name_orig, name_orig + 1, sizeof name_orig - 1); - name_orig[strlen(pin_name) - 2] = 0; - } - this->device_pins[i].pin = get_pin(this, pin_name); - strncpy(this->device_pins[i].name, pin_name, sizeof *this->device_pins[i].name); - lua_pop(this->luactx, 1); - ////////////////////// - // set pin on time // - ////////////////////// - lua_getfield(this->luactx, -1, PIN_ON_TIME); - this->device_pins[i].on_time = lua_tointeger(this->luactx, -1); - lua_pop(this->luactx, 1); - /////////////////////// - // set pin off time // - /////////////////////// - lua_getfield(this->luactx, -1, PIN_OFF_TIME); - this->device_pins[i].off_time = lua_tointeger(this->luactx, -1); - lua_pop(this->luactx, 1); - /* - * At this point we will create table, named after the pin name - * that will contain pin index in device table and several methods - */ - register_pin_obj(this->luactx, i, name_orig); - } - - /* Check and set IC type (TTL/CMOS/I2L) */ - lua_getglobal(this->luactx, "LOGIC_TYPE"); - if (0 == lua_isinteger(this->luactx, -1)) - { - print_warning(this, "No or wrong IC type specified. TTL type will be set"); - set_logic_type(this, TTL); - } - else - { - int ltype = lua_tointeger(this->luactx, -1); + (void)edx; + + this->model_instance = instance; + this->model_dsim = dsimckt; + /*Init xor shift PRNG*/ + this->xorseed[0] = rand64bits(); + this->xorseed[1] = rand64bits(); + + lua_load_modules(this); + + char *device_script = get_string_param(this, "lua"); + /* If user uses precompiled device script - don't load external script */ + lua_getglobal(this->luactx, "__USE_PRECOMPILED"); + if (0xDEADC0DE == lua_tointeger(this->luactx, lua_gettop(this->luactx)) || '?' == *device_script) + { + print_info(this, "%s started [OpenVSM %s, precompiled device script] %s", get_device_id(this), __VERSION, LUA_RELEASE); + } + else + { + if (!load_device_script(this, device_script)) + { + return; + } + print_info(this, "%s started [OpenVSM %s, %s] %s", get_device_id(this), __VERSION, device_script, LUA_RELEASE); + } + + lua_getglobal(this->luactx, "device_init"); + if (lua_isfunction(this->luactx, lua_gettop(this->luactx))) + { + this->device_init_declared = true; + } + + lua_getglobal(this->luactx, "timer_callback"); + if (lua_isfunction(this->luactx, lua_gettop(this->luactx))) + { + this->timer_callback_declared = true; + } + + lua_getglobal(this->luactx, "device_simulate"); + if (lua_isfunction(this->luactx, lua_gettop(this->luactx))) + { + this->device_simulate_declared = true; + } + + lua_getglobal(this->luactx, "device_pins"); + if (0 == lua_istable(this->luactx, -1)) + { + print_error(this, "Fatal error, no pin assignments found in script"); + return; + } + lua_len(this->luactx, -1); + int32_t pin_number = lua_tointeger(this->luactx, -1); + if (!pin_number) + { + print_warning(this, "IC has no pins"); + } + lua_pop(this->luactx, 1); + /* Pins initialization */ + char name_orig[64] = {0}; + for (int i = 1; i <= pin_number; i++) + { + lua_rawgeti(this->luactx, -1, i); + ////////////// + // set pin // + ////////////// + lua_getfield(this->luactx, -1, PIN_NAME); + char *pin_name = (char *)lua_tostring(this->luactx, -1); + strcpy(name_orig, pin_name); + /* Replace leading AND trailing underscore with $ sign */ + if ('$' == pin_name[0] || '$' == pin_name[strlen(pin_name)]) + { + memmove(name_orig, name_orig + 1, sizeof name_orig - 1); + name_orig[strlen(pin_name) - 2] = 0; + } + this->device_pins[i].pin = get_pin(this, pin_name); + strncpy(this->device_pins[i].name, pin_name, sizeof *this->device_pins[i].name); + lua_pop(this->luactx, 1); + ////////////////////// + // set pin on time // + ////////////////////// + lua_getfield(this->luactx, -1, PIN_ON_TIME); + this->device_pins[i].on_time = lua_tointeger(this->luactx, -1); + lua_pop(this->luactx, 1); + /////////////////////// + // set pin off time // + /////////////////////// + lua_getfield(this->luactx, -1, PIN_OFF_TIME); + this->device_pins[i].off_time = lua_tointeger(this->luactx, -1); + lua_pop(this->luactx, 1); + /* + * At this point we will create table, named after the pin name + * that will contain pin index in device table and several methods + */ + register_pin_obj(this->luactx, i, name_orig); + } + + /* Check and set IC type (TTL/CMOS/I2L) */ + lua_getglobal(this->luactx, "LOGIC_TYPE"); + if (0 == lua_isinteger(this->luactx, -1)) + { + print_warning(this, "No or wrong IC type specified. TTL type will be set"); + set_logic_type(this, TTL); + } + else + { + int ltype = lua_tointeger(this->luactx, -1); #ifdef __DEBUG - print_info(this, "IC type was set to %s", logic_type_to_string(ltype)); + print_info(this, "IC type was set to %s", logic_type_to_string(ltype)); #endif - set_logic_type(this, ltype); - } - - /* Does safe mode should be enabled? */ - lua_getglobal(this->luactx, "SAFE_MODE"); - if (lua_isboolean(this->luactx, -1)) - { - this->safe_mode = lua_toboolean(this->luactx, -1); + set_logic_type(this, ltype); + } + + /* Does safe mode should be enabled? */ + lua_getglobal(this->luactx, "SAFE_MODE"); + if (lua_isboolean(this->luactx, -1)) + { + this->safe_mode = lua_toboolean(this->luactx, -1); #ifdef __DEBUG - print_info(this, "Safe mode was %s", this->safe_mode ? "enabled" : "disabled"); + print_info(this, "Safe mode was %s", this->safe_mode ? "enabled" : "disabled"); #endif - } - else - { - this->safe_mode = false; + } + else + { + this->safe_mode = false; #ifdef __DEBUG - print_info(this, "Safe mode was disabled or incorrectly set"); + print_info(this, "Safe mode was disabled or incorrectly set"); #endif - } + } - /* Pass model object pointer to Lua - it is safer there ;) */ - lua_pushliteral(this->luactx, "__this"); - lua_pushlightuserdata(this->luactx, this); - lua_settable(this->luactx, LUA_REGISTRYINDEX); + /* Pass model object pointer to Lua - it is safer there ;) */ + lua_pushliteral(this->luactx, "__this"); + lua_pushlightuserdata(this->luactx, this); + lua_settable(this->luactx, LUA_REGISTRYINDEX); #ifdef __DEBUG - print_info(this, "User defined functions: %s%s%s", - this->device_init_declared ? "device_init() " : "", - this->timer_callback_declared ? "timer_callback() " : "", - this->device_simulate_declared ? "device_simulate()" : ""); + print_info(this, "User defined functions: %s%s%s", + this->device_init_declared ? "device_init() " : "", + this->timer_callback_declared ? "timer_callback() " : "", + this->device_simulate_declared ? "device_simulate()" : ""); #endif - /* Call device_init() function in Lua if it's exists */ - - if (this->device_init_declared) - { - lua_getglobal(this->luactx, "device_init"); - if (lua_isfunction(this->luactx, lua_gettop(this->luactx))) - { - if (lua_pcall(this->luactx, 0, 0, 0)) - { - const char *err = lua_tostring(this->luactx, -1); - print_error(this, "Error during device init: %s", err); - } - } - } - - // this->device_pins[1].pin->vtable->sethandler(this->device_pins[1].pin, 0, this, &pinhandler); + /* Call device_init() function in Lua if it's exists */ + + if (this->device_init_declared) + { + lua_getglobal(this->luactx, "device_init"); + if (lua_isfunction(this->luactx, lua_gettop(this->luactx))) + { + if (lua_pcall(this->luactx, 0, 0, 0)) + { + const char *err = lua_tostring(this->luactx, -1); + print_error(this, "Error during device init: %s", err); + } + } + } + + // this->device_pins[1].pin->vtable->sethandler(this->device_pins[1].pin, 0, this, &pinhandler); } /** @@ -330,47 +330,47 @@ vsm_setup(IDSIMMODEL *this, uint32_t edx, IINSTANCE *instance, IDSIMCKT *dsimckt void __FASTCALL__ vsm_runctrl(IDSIMMODEL *this, uint32_t edx, RUNMODES mode) { - (void)this; - (void)edx; - (void)mode; + (void)this; + (void)edx; + (void)mode; - /// FIXIT: Create full set of flags for each simulator step - switch (mode) - { - case RM_BATCH: + /// FIXIT: Create full set of flags for each simulator step + switch (mode) + { + case RM_BATCH: - break; - case RM_START: + break; + case RM_START: - break; - case RM_STOP: - break; - case RM_SUSPEND: - break; - case RM_ANIMATE: - break; - case RM_STEPTIME: + break; + case RM_STOP: + break; + case RM_SUSPEND: + break; + case RM_ANIMATE: + break; + case RM_STEPTIME: - break; - case RM_STEPOVER: + break; + case RM_STEPOVER: - break; - case RM_STEPINTO: + break; + case RM_STEPINTO: - break; - case RM_STEPOUT: + break; + case RM_STEPOUT: - break; - case RM_STEPTO: + break; + case RM_STEPTO: - break; - case RM_META: + break; + case RM_META: - break; - case RM_DUMP: + break; + case RM_DUMP: - break; - } + break; + } } /** @@ -390,10 +390,10 @@ vsm_runctrl(IDSIMMODEL *this, uint32_t edx, RUNMODES mode) void __FASTCALL__ vsm_actuate(IDSIMMODEL *this, uint32_t edx, REALTIME atime, ACTIVESTATE newstate) { - (void)this; - (void)edx; - (void)atime; - (void)newstate; + (void)this; + (void)edx; + (void)atime; + (void)newstate; } /** @@ -415,11 +415,11 @@ vsm_actuate(IDSIMMODEL *this, uint32_t edx, REALTIME atime, ACTIVESTATE newstate bool __FASTCALL__ vsm_indicate(IDSIMMODEL *this, uint32_t edx, REALTIME atime, ACTIVEDATA *newstate) { - (void)this; - (void)edx; - (void)atime; - (void)newstate; - return false; + (void)this; + (void)edx; + (void)atime; + (void)newstate; + return false; } /** @@ -439,25 +439,28 @@ vsm_indicate(IDSIMMODEL *this, uint32_t edx, REALTIME atime, ACTIVEDATA *newstat void __FASTCALL__ vsm_simulate(IDSIMMODEL *this, uint32_t edx, ABSTIME atime, DSIMMODES mode) { - (void)edx; - (void)atime; - (void)mode; + (void)edx; + (void)atime; + (void)mode; #if 0 - /* C model speed benchmark as for NAND gate */ - set_pin_bool ( this, this->device_pins[3], ( 1- ( get_pin_bool ( this->device_pins[1] ) * get_pin_bool ( this->device_pins[2] ) ) ) ); + /* C model speed benchmark as for NAND gate */ + set_pin_bool ( this, this->device_pins[3], ( 1- ( get_pin_bool ( this->device_pins[1] ) * get_pin_bool ( this->device_pins[2] ) ) ) ); #else - if (this->device_simulate_declared) - { - lua_getglobal(this->luactx, "device_simulate"); - if (lua_isfunction(this->luactx, lua_gettop(this->luactx))) - { - if (lua_pcall(this->luactx, 0, 0, 0)) - { - const char *err = lua_tostring(this->luactx, -1); - print_error(this, "Simulation failed with \"%s\"", err); - } - } - } + if (!this->device_simulate_declared) + { + return; + } + + lua_getglobal(this->luactx, "device_simulate"); + if (lua_isfunction(this->luactx, lua_gettop(this->luactx))) + { + if (lua_pcall(this->luactx, 0, 0, 0)) + { + const char *err = lua_tostring(this->luactx, -1); + print_error(this, "Simulation failed with \"%s\"", err); + } + } + #endif } @@ -478,32 +481,31 @@ vsm_simulate(IDSIMMODEL *this, uint32_t edx, ABSTIME atime, DSIMMODES mode) void __FASTCALL__ vsm_timer_callback(IDSIMMODEL *this, uint32_t edx, ABSTIME atime, EVENTID eventid) { - (void)edx; - - /* Ignore Lua call if it not declared in the script */ - if (this->timer_callback_declared) - { - /*callback_events* curevent = NULL; - HASH_FIND_INT ( this->events, &eventid, curevent ); - if ( curevent ) - {*/ - lua_getglobal(this->luactx, "timer_callback"); - if (lua_isfunction(this->luactx, lua_gettop(this->luactx))) - { - lua_pushinteger(this->luactx, atime); - lua_pushinteger(this->luactx, eventid); - if (lua_pcall(this->luactx, 2, 0, 0)) - { - const char *err = lua_tostring(this->luactx, -1); - print_error(this, "Timer callback failed with \"%s\"", err); - } - } - //} - } + (void)edx; + + /* Ignore Lua call if it not declared in the script */ + if (!this->timer_callback_declared) + { + return; + } + /*callback_events* curevent = NULL; + HASH_FIND_INT ( this->events, &eventid, curevent ); + if ( curevent ) + {*/ + lua_getglobal(this->luactx, "timer_callback"); + if (lua_isfunction(this->luactx, lua_gettop(this->luactx))) + { + lua_pushinteger(this->luactx, atime); + lua_pushinteger(this->luactx, eventid); + if (lua_pcall(this->luactx, 2, 0, 0)) + { + const char *err = lua_tostring(this->luactx, -1); + print_error(this, "Timer callback failed with \"%s\"", err); + } + } + //} } -#ifndef __MINGW32__ - /** * \fn bool APIENTRY DllMain ( HINSTANCE hInstDLL, uint32_t fdwReason, LPVOID lpvReserved ) * @@ -522,12 +524,11 @@ vsm_timer_callback(IDSIMMODEL *this, uint32_t edx, ABSTIME atime, EVENTID eventi bool APIENTRY DllMain(HINSTANCE hInstDLL, uint32_t fdwReason, LPVOID lpvReserved) { - (void)hInstDLL; - (void)fdwReason; - (void)lpvReserved; - return true; + (void)hInstDLL; + (void)fdwReason; + (void)lpvReserved; + return true; } -#endif /** * \fn LRESULT __FASTCALL__ icpu_vdmhlr ( ICPU* this, uint32_t edx, VDM_COMMAND* cmd, uint8_t* data ) @@ -547,11 +548,11 @@ DllMain(HINSTANCE hInstDLL, uint32_t fdwReason, LPVOID lpvReserved) LRESULT __FASTCALL__ icpu_vdmhlr(ICPU *this, uint32_t edx, VDM_COMMAND *cmd, uint8_t *data) { - (void)this; - (void)edx; - (void)cmd; - (void)data; - return 0; + (void)this; + (void)edx; + (void)cmd; + (void)data; + return 0; } /** @@ -573,13 +574,13 @@ LRESULT __FASTCALL__ icpu_vdmhlr(ICPU *this, uint32_t edx, VDM_COMMAND *cmd, uin void __FASTCALL__ icpu_loaddata(ICPU *this, uint32_t edx, int32_t format, int32_t seg, ADDRESS address, uint8_t *data, int32_t numbytes) { - (void)this; - (void)edx; - (void)format; - (void)seg; - (void)address; - (void)data; - (void)numbytes; + (void)this; + (void)edx; + (void)format; + (void)seg; + (void)address; + (void)data; + (void)numbytes; } /** @@ -598,10 +599,10 @@ void __FASTCALL__ icpu_loaddata(ICPU *this, uint32_t edx, int32_t format, int32_ void __FASTCALL__ icpu_disassemble(ICPU *this, uint32_t edx, ADDRESS address, int32_t numbytes) { - (void)this; - (void)edx; - (void)address; - (void)numbytes; + (void)this; + (void)edx; + (void)address; + (void)numbytes; } /** @@ -622,9 +623,9 @@ void __FASTCALL__ icpu_disassemble(ICPU *this, uint32_t edx, ADDRESS address, in bool __FASTCALL__ icpu_getvardata(ICPU *this, uint32_t edx, VARITEM *vip, VARDATA *vdp) { - (void)this; - (void)edx; - (void)vip; - (void)vdp; - return true; + (void)this; + (void)edx; + (void)vip; + (void)vdp; + return true; } \ No newline at end of file