From 4ff6f926f0041381c2963ebfb4b9088ab30846a3 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Mon, 5 Feb 2018 16:52:55 +0300 Subject: [PATCH] Wren Support #392 --- .gitignore | 7 + 3rd-party | 2 +- Makefile | 20 +- bin/assets/wrendemo.tic.dat | 1 + build/android/jni/src/Android.mk | 4 +- build/android/jni/wren/Android.mk | 6 + build/android/src/com/nesbox/tic/TIC.java | 1 + build/uwp/tic/tic.sln | 14 + build/uwp/tic/tic.vcxproj.user | 2 +- build/uwp/tic80/tic80.vcxproj | 16 +- build/uwp/tic80/tic80.vcxproj.filters | 3 + build/uwp/wren/wren.vcxproj | 210 +++ build/uwp/wren/wren.vcxproj.filters | 43 + build/windows/example/example.vcxproj | 18 +- build/windows/lua/lua.vcxproj.user | 4 + build/windows/tic/tic.sln | 31 +- build/windows/tic/tic.vcxproj | 16 +- build/windows/tic80/tic80.vcxproj | 20 +- build/windows/tic80/tic80.vcxproj.filters | 3 + build/windows/tic80/tic80.vcxproj.user | 4 + build/windows/wren/wren_lib.vcxproj | 194 +++ build/windows/wren/wren_lib.vcxproj.filters | 75 + build/windows/wren/wren_lib.vcxproj.user | 4 + demos/wrendemo.tic | Bin 0 -> 1272 bytes src/console.c | 31 +- src/machine.h | 2 + src/studio.h | 1 + src/surf.c | 1 + src/tic.c | 7 + src/wrenapi.c | 1423 +++++++++++++++++++ 30 files changed, 2120 insertions(+), 43 deletions(-) create mode 100644 bin/assets/wrendemo.tic.dat create mode 100644 build/android/jni/wren/Android.mk create mode 100644 build/uwp/wren/wren.vcxproj create mode 100644 build/uwp/wren/wren.vcxproj.filters create mode 100644 build/windows/lua/lua.vcxproj.user create mode 100644 build/windows/tic80/tic80.vcxproj.user create mode 100644 build/windows/wren/wren_lib.vcxproj create mode 100644 build/windows/wren/wren_lib.vcxproj.filters create mode 100644 build/windows/wren/wren_lib.vcxproj.user create mode 100644 demos/wrendemo.tic create mode 100644 src/wrenapi.c diff --git a/.gitignore b/.gitignore index e5296e6..27f87e3 100644 --- a/.gitignore +++ b/.gitignore @@ -95,3 +95,10 @@ build/windows/example/Release Pro/ build/windows/example/Debug Pro/ TIC80.sublime-project TIC80.sublime-workspace +build/windows/wren/Release/ +build/windows/wren/Debug/ +build/windows/wren/x64/ +build/uwp/wren/x64/ +build/uwp/wren/Release/ +build/uwp/wren/ARM/ +build/uwp/wren/Debug/ diff --git a/3rd-party b/3rd-party index c3f37f4..b21ee19 160000 --- a/3rd-party +++ b/3rd-party @@ -1 +1 @@ -Subproject commit c3f37f4431282db7f1a99a89f90767fa20481a84 +Subproject commit b21ee19badc2c4f315df49ecbfc7830517b98955 diff --git a/Makefile b/Makefile index 0ad4e13..18dcc53 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,7 @@ INCLUDES= \ -I$(3RD_PARTY)/zlib-1.2.8 \ -I$(3RD_PARTY)/giflib-5.1.4/lib \ -I$(3RD_PARTY)/SDL2-2.0.7/include \ + -I$(3RD_PARTY)/wren-0.1.0/src/include \ -I$(3RD_PARTY)/moonscript \ -I$(BLIPBUF_LIB) \ -I$(DUKTAPE_LIB) \ @@ -31,6 +32,7 @@ MINGW_LINKER_FLAGS= \ -lz \ -lgif \ -llua \ + -lwren \ -lcomdlg32 \ -lws2_32 \ -mwindows @@ -61,6 +63,7 @@ LINUX_LINKER_LTO_FLAGS= \ -D_GNU_SOURCE \ -lSDL2 \ -llua \ + -lwren \ -lgif \ -ldl \ -lm \ @@ -71,6 +74,7 @@ LINUX_LINKER_LTO_FLAGS= \ LINUX_LINKER_FLAGS= \ -D_GNU_SOURCE \ -llua5.3 \ + -lwren \ -ldl \ -lm \ -lpthread \ @@ -93,6 +97,7 @@ EMS_OPT= \ EMS_LINKER_FLAGS= \ -L$(PRE_BUILT)/emscripten \ -llua \ + -lwren \ -lgif \ -lz @@ -105,7 +110,7 @@ MACOSX_OPT= \ MACOSX_LIBS= \ -L$(PRE_BUILT)/macos \ -L/usr/local/lib \ - -lSDL2 -lm -liconv -lobjc -llua -lz -lgif \ + -lSDL2 -lm -liconv -lobjc -llua -lwren -lz -lgif \ -Wl,-framework,CoreAudio \ -Wl,-framework,AudioToolbox \ -Wl,-framework,ForceFeedback \ @@ -159,6 +164,7 @@ DEMO_ASSETS= \ bin/assets/jsdemo.tic.dat \ bin/assets/luademo.tic.dat \ bin/assets/moondemo.tic.dat \ + bin/assets/wrendemo.tic.dat \ bin/assets/benchmark.tic.dat \ bin/assets/config.tic.dat @@ -282,16 +288,19 @@ bin/jsapi.o: src/jsapi.c $(TIC80_H) bin/luaapi.o: src/luaapi.c $(TIC80_H) $(CC) $< $(OPT) $(INCLUDES) -c -o $@ +bin/wrenapi.o: src/wrenapi.c $(TIC80_H) + $(CC) $< $(OPT) $(INCLUDES) -c -o $@ + bin/duktape.o: $(DUKTAPE_LIB)/duktape.c $(TIC80_H) $(CC) $< $(OPT) $(INCLUDES) -c -o $@ -TIC80_SRC = src/tic80.c src/tic.c $(BLIP_SRC) src/jsapi.c src/luaapi.c $(DUKTAPE_LIB)/duktape.c -TIC80_O = bin/tic80.o bin/tic.o bin/tools.o bin/blip_buf.o bin/jsapi.o bin/luaapi.o bin/duktape.o bin/gif.o +TIC80_SRC = src/tic80.c src/tic.c $(BLIP_SRC) src/jsapi.c src/luaapi.c src/wrenapi.c $(DUKTAPE_LIB)/duktape.c +TIC80_O = bin/tic80.o bin/tic.o bin/tools.o bin/blip_buf.o bin/jsapi.o bin/luaapi.o bin/wrenapi.o bin/duktape.o bin/gif.o TIC80_A = bin/libtic80.a TIC80_DLL = bin/tic80.dll $(TIC80_DLL): $(TIC80_O) - $(CC) $(OPT) -shared $(TIC80_O) -L$(PRE_BUILT)/mingw -llua -lgif -Wl,--out-implib,$(TIC80_A) -o $@ + $(CC) $(OPT) -shared $(TIC80_O) -L$(PRE_BUILT)/mingw -llua -lwren -lgif -Wl,--out-implib,$(TIC80_A) -o $@ emscripten: $(EMS_CC) $(SOURCES) $(TIC80_SRC) $(OPT) $(INCLUDES) $(EMS_OPT) $(EMS_LINKER_FLAGS) -o build/html/tic.js @@ -387,6 +396,9 @@ bin/assets/jsdemo.tic.dat: demos/jsdemo.tic bin/assets/luademo.tic.dat: demos/luademo.tic $(BIN2TXT) $< $@ -z +bin/assets/wrendemo.tic.dat: demos/wrendemo.tic + $(BIN2TXT) $< $@ -z + bin/assets/moondemo.tic.dat: demos/moondemo.tic $(BIN2TXT) $< $@ -z diff --git a/bin/assets/wrendemo.tic.dat b/bin/assets/wrendemo.tic.dat new file mode 100644 index 0000000..1a5d05e --- /dev/null +++ b/bin/assets/wrendemo.tic.dat @@ -0,0 +1 @@ +0x78, 0xda, 0x63, 0x5c, 0xc0, 0xc4, 0x40, 0x08, 0xfc, 0xfb, 0x0f, 0x04, 0x4a, 0x4a, 0x4a, 0xfd, 0x1d, 0x1d, 0x1d, 0xfd, 0x20, 0x1a, 0xc8, 0xed, 0xff, 0xff, 0x01, 0x8e, 0xff, 0xff, 0x7f, 0xff, 0x4e, 0x49, 0xe9, 0xff, 0xbb, 0x8e, 0x8e, 0x0f, 0xef, 0x94, 0x9a, 0x3e, 0xbc, 0xfb, 0xdf, 0xff, 0xe1, 0xff, 0x87, 0xfe, 0x0f, 0x1f, 0x60, 0x18, 0xbb, 0xfe, 0xff, 0x78, 0xf5, 0xff, 0x47, 0xd2, 0xcf, 0x30, 0x0a, 0x06, 0x14, 0x80, 0xe3, 0x0a, 0x14, 0x77, 0x60, 0xf8, 0x03, 0xcc, 0xd6, 0x07, 0xc6, 0xe3, 0x7f, 0x86, 0x0f, 0xff, 0x81, 0x71, 0xfb, 0xef, 0x7f, 0x3f, 0xc3, 0x7f, 0x60, 0xdc, 0xbd, 0xef, 0x07, 0xc6, 0x5f, 0x07, 0x14, 0x83, 0xe2, 0x93, 0xe1, 0xc3, 0xfb, 0x77, 0xff, 0xff, 0xbf, 0x7b, 0x47, 0xa9, 0x7e, 0xd6, 0x65, 0x8c, 0x0c, 0xfa, 0xfa, 0x0a, 0x25, 0x99, 0x25, 0x39, 0xa9, 0x56, 0x0a, 0x0a, 0xe9, 0x89, 0xb9, 0xa9, 0x10, 0x0e, 0x17, 0x50, 0x34, 0xb1, 0xb4, 0x24, 0x23, 0xbf, 0xc8, 0x0a, 0x22, 0x9a, 0x92, 0x5a, 0x96, 0x9a, 0x93, 0x5f, 0x90, 0x5a, 0x04, 0x92, 0x49, 0x49, 0x2d, 0x4e, 0x06, 0x2a, 0x57, 0x28, 0x06, 0xca, 0x97, 0x80, 0x79, 0x45, 0x99, 0x05, 0x25, 0x99, 0xf9, 0x79, 0x20, 0x49, 0x08, 0xc7, 0x4a, 0xa1, 0xbc, 0x28, 0x35, 0x8f, 0x8b, 0x2b, 0x39, 0x27, 0xb1, 0xb8, 0x58, 0xc1, 0x1d, 0x64, 0x44, 0x66, 0xb1, 0x82, 0x6b, 0x5e, 0x7a, 0x66, 0x5e, 0xaa, 0x42, 0x35, 0x17, 0x17, 0x67, 0x72, 0x7e, 0x5e, 0x71, 0x49, 0x51, 0x69, 0x72, 0x89, 0x42, 0x5e, 0x6a, 0xb9, 0x86, 0x66, 0x35, 0x17, 0x27, 0x67, 0x7c, 0x89, 0xad, 0x01, 0x88, 0xaa, 0xb0, 0xb5, 0x34, 0x03, 0xd1, 0x95, 0xb6, 0x46, 0x26, 0x5c, 0x9c, 0xb5, 0x5c, 0x9c, 0x5c, 0x9c, 0xa5, 0x05, 0x29, 0x89, 0x25, 0xa9, 0x10, 0x65, 0x99, 0x69, 0x1a, 0x21, 0x99, 0xc9, 0x7a, 0x49, 0x25, 0x79, 0x1a, 0x06, 0x9a, 0x60, 0x11, 0x90, 0xd2, 0xf8, 0x4a, 0x5d, 0x43, 0x20, 0xb3, 0x16, 0x55, 0x81, 0x21, 0xb2, 0x02, 0x6d, 0x2c, 0x0a, 0x8c, 0x60, 0x0a, 0x2a, 0x6c, 0xe3, 0x2b, 0xb0, 0x99, 0x60, 0x8c, 0xac, 0x00, 0x6a, 0x02, 0x90, 0x00, 0x49, 0x27, 0xe7, 0x14, 0x6b, 0x18, 0x1a, 0x6b, 0x72, 0x29, 0x28, 0x80, 0x78, 0xc5, 0x05, 0x45, 0x1a, 0x86, 0xda, 0x1a, 0x1a, 0xf1, 0x25, 0xaa, 0x66, 0x06, 0x9a, 0xfa, 0xc6, 0x06, 0x35, 0x06, 0x9a, 0x5a, 0x46, 0x3a, 0xf1, 0x15, 0x3a, 0xf1, 0x95, 0x3a, 0x86, 0x26, 0x3a, 0xc6, 0x3a, 0x06, 0x40, 0x68, 0xa4, 0x63, 0x04, 0xd3, 0x50, 0x50, 0x94, 0x99, 0x57, 0xa2, 0xa1, 0xe4, 0xe1, 0xea, 0xe3, 0xe3, 0xaf, 0x10, 0xee, 0x1f, 0xe4, 0xe3, 0xa2, 0xa8, 0xa4, 0x63, 0x61, 0x02, 0x44, 0x9a, 0x90, 0xc0, 0x88, 0x2f, 0x01, 0xd9, 0x07, 0xb4, 0x0e, 0x64, 0xa3, 0x1d, 0x65, 0x29, 0x8d, 0x99, 0x85, 0xcb, 0x00, 0xc2, 0x02, 0x15, 0x19, 0x30, 0x5a, 0xc0, 0x28, 0xa4, 0x6c, 0xc6, 0xae, 0x3b, 0xff, 0xde, 0x9f, 0x5d, 0xdd, 0x99, 0xee, 0xaa, 0xcc, 0x08, 0xe3, 0xc3, 0x68, 0x1e, 0xa0, 0x1e, 0x11, 0x1e, 0x19, 0x17, 0x15, 0x13, 0x03, 0x93, 0x5c, 0x3f, 0x2f, 0xbf, 0x56, 0x1f, 0x03, 0x93, 0x54, 0x95, 0x0b, 0x6e, 0x1e, 0xa5, 0x85, 0x89, 0x91, 0xb5, 0xe7, 0x2e, 0xd5, 0xea, 0xb4, 0x4e, 0x5d, 0x98, 0xbb, 0x4a, 0xe7, 0xd2, 0xaa, 0x99, 0xb9, 0x87, 0x4e, 0xdd, 0xba, 0x12, 0x77, 0xef, 0xdd, 0x35, 0x00, 0x03, 0x53, 0x57, 0x24, \ No newline at end of file diff --git a/build/android/jni/src/Android.mk b/build/android/jni/src/Android.mk index 6b456a1..a73a590 100644 --- a/build/android/jni/src/Android.mk +++ b/build/android/jni/src/Android.mk @@ -16,6 +16,7 @@ LOCAL_C_INCLUDES := \ $(LOCAL_PATH)/$(THIRD_PARTY_PATH)/blip-buf \ $(LOCAL_PATH)/$(THIRD_PARTY_PATH)/SDL2_net-2.0.1 \ $(LOCAL_PATH)/$(THIRD_PARTY_PATH)/moonscript \ + $(LOCAL_PATH)/$(THIRD_PARTY_PATH)/wren-0.1.0\src\include \ $(LOCAL_PATH)/../../../../include # Add your application source files here... @@ -46,13 +47,14 @@ LOCAL_SRC_FILES := \ $(SRC_PATH)/net.c \ $(SRC_PATH)/luaapi.c \ $(SRC_PATH)/jsapi.c \ + $(SRC_PATH)/wrenapi.c \ $(SRC_PATH)/tic.c \ $(SRC_PATH)/dialog.c \ $(SRC_PATH)/menu.c \ $(SRC_PATH)/surf.c \ $(SRC_PATH)/tic80.c -LOCAL_SHARED_LIBRARIES := SDL2 lua z gif +LOCAL_SHARED_LIBRARIES := SDL2 lua z gif wren LOCAL_LDLIBS := -lGLESv1_CM -lGLESv2 -llog diff --git a/build/android/jni/wren/Android.mk b/build/android/jni/wren/Android.mk new file mode 100644 index 0000000..1e101a6 --- /dev/null +++ b/build/android/jni/wren/Android.mk @@ -0,0 +1,6 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) +LOCAL_MODULE := wren +LOCAL_SRC_FILES := ../../../../3rd-party/pre-built/android/wren/$(TARGET_ARCH_ABI)/libwren.so +include $(PREBUILT_SHARED_LIBRARY) diff --git a/build/android/src/com/nesbox/tic/TIC.java b/build/android/src/com/nesbox/tic/TIC.java index 35723d8..7320c68 100644 --- a/build/android/src/com/nesbox/tic/TIC.java +++ b/build/android/src/com/nesbox/tic/TIC.java @@ -13,6 +13,7 @@ public class TIC extends SDLActivity return new String[] { "SDL2", "lua", + "wren", "z", "gif", "main" diff --git a/build/uwp/tic/tic.sln b/build/uwp/tic/tic.sln index dc4ac55..acd7e65 100644 --- a/build/uwp/tic/tic.sln +++ b/build/uwp/tic/tic.sln @@ -15,6 +15,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SDL2-UWP", "..\..\..\3rd-pa EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlib-uwp", "..\..\..\3rd-party\zlib-1.2.8\winrt\zlib-uwp\zlib-uwp.vcxproj", "{978F53DB-F959-4CB4-84A7-463AF29949BE}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wren", "..\wren\wren.vcxproj", "{BBB0D01A-B124-416C-BE26-E6993154A555}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|ARM = Debug|ARM @@ -103,6 +105,18 @@ Global {978F53DB-F959-4CB4-84A7-463AF29949BE}.Release|x64.Build.0 = Release|x64 {978F53DB-F959-4CB4-84A7-463AF29949BE}.Release|x86.ActiveCfg = Release|Win32 {978F53DB-F959-4CB4-84A7-463AF29949BE}.Release|x86.Build.0 = Release|Win32 + {BBB0D01A-B124-416C-BE26-E6993154A555}.Debug|ARM.ActiveCfg = Debug|ARM + {BBB0D01A-B124-416C-BE26-E6993154A555}.Debug|ARM.Build.0 = Debug|ARM + {BBB0D01A-B124-416C-BE26-E6993154A555}.Debug|x64.ActiveCfg = Debug|x64 + {BBB0D01A-B124-416C-BE26-E6993154A555}.Debug|x64.Build.0 = Debug|x64 + {BBB0D01A-B124-416C-BE26-E6993154A555}.Debug|x86.ActiveCfg = Debug|Win32 + {BBB0D01A-B124-416C-BE26-E6993154A555}.Debug|x86.Build.0 = Debug|Win32 + {BBB0D01A-B124-416C-BE26-E6993154A555}.Release|ARM.ActiveCfg = Release|ARM + {BBB0D01A-B124-416C-BE26-E6993154A555}.Release|ARM.Build.0 = Release|ARM + {BBB0D01A-B124-416C-BE26-E6993154A555}.Release|x64.ActiveCfg = Release|x64 + {BBB0D01A-B124-416C-BE26-E6993154A555}.Release|x64.Build.0 = Release|x64 + {BBB0D01A-B124-416C-BE26-E6993154A555}.Release|x86.ActiveCfg = Release|Win32 + {BBB0D01A-B124-416C-BE26-E6993154A555}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/build/uwp/tic/tic.vcxproj.user b/build/uwp/tic/tic.vcxproj.user index 92e604f..2eac851 100644 --- a/build/uwp/tic/tic.vcxproj.user +++ b/build/uwp/tic/tic.vcxproj.user @@ -15,7 +15,7 @@ XboxOne - UWPRemoteDebugger + AppHostLocalDebugger XboxOne diff --git a/build/uwp/tic80/tic80.vcxproj b/build/uwp/tic80/tic80.vcxproj index a020cad..344f5e0 100644 --- a/build/uwp/tic80/tic80.vcxproj +++ b/build/uwp/tic80/tic80.vcxproj @@ -35,6 +35,7 @@ + @@ -43,6 +44,9 @@ {53802f21-41da-4ac1-8b62-0dac2ccb8af8} + + {bbb0d01a-b124-416c-be26-e6993154a555} + {9c39acf1-5f52-4a2b-a467-9f2805d6174b} @@ -143,7 +147,7 @@ NotUsing false - ..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\duktape-2.2.0\src;..\..\..\3rd-party\blip-buf;..\..\..\3rd-party\moonscript;$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories) + ..\..\..\include;..\..\..\3rd-party\wren-0.1.0\src\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\duktape-2.2.0\src;..\..\..\3rd-party\blip-buf;..\..\..\3rd-party\moonscript;$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories) LUA_COMPAT_5_2;_CRT_SECURE_NO_WARNINGS;TIC80_SHARED;_WINDLL;%(PreprocessorDefinitions) false @@ -159,7 +163,7 @@ NotUsing false - ..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\duktape-2.2.0\src;..\..\..\3rd-party\blip-buf;..\..\..\3rd-party\moonscript;$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories) + ..\..\..\include;..\..\..\3rd-party\wren-0.1.0\src\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\duktape-2.2.0\src;..\..\..\3rd-party\blip-buf;..\..\..\3rd-party\moonscript;$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories) LUA_COMPAT_5_2;_CRT_SECURE_NO_WARNINGS;TIC80_SHARED;_WINDLL;%(PreprocessorDefinitions) false @@ -175,7 +179,7 @@ NotUsing false - ..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\duktape-2.2.0\src;..\..\..\3rd-party\blip-buf;..\..\..\3rd-party\moonscript;$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories) + ..\..\..\include;..\..\..\3rd-party\wren-0.1.0\src\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\duktape-2.2.0\src;..\..\..\3rd-party\blip-buf;..\..\..\3rd-party\moonscript;$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories) LUA_COMPAT_5_2;_CRT_SECURE_NO_WARNINGS;TIC80_SHARED;_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE=1;%(ClCompile.PreprocessorDefinitions) false @@ -191,7 +195,7 @@ NotUsing false - ..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\duktape-2.2.0\src;..\..\..\3rd-party\blip-buf;..\..\..\3rd-party\moonscript;$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories) + ..\..\..\include;..\..\..\3rd-party\wren-0.1.0\src\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\duktape-2.2.0\src;..\..\..\3rd-party\blip-buf;..\..\..\3rd-party\moonscript;$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories) LUA_COMPAT_5_2;_CRT_SECURE_NO_WARNINGS;TIC80_SHARED;_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE=1;%(ClCompile.PreprocessorDefinitions) false @@ -207,7 +211,7 @@ NotUsing false - ..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\duktape-2.2.0\src;..\..\..\3rd-party\blip-buf;..\..\..\3rd-party\moonscript;$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories) + ..\..\..\include;..\..\..\3rd-party\wren-0.1.0\src\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\duktape-2.2.0\src;..\..\..\3rd-party\blip-buf;..\..\..\3rd-party\moonscript;$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories) LUA_COMPAT_5_2;_CRT_SECURE_NO_WARNINGS;TIC80_SHARED;_WINDLL;%(PreprocessorDefinitions) false @@ -223,7 +227,7 @@ NotUsing false - ..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\duktape-2.2.0\src;..\..\..\3rd-party\blip-buf;..\..\..\3rd-party\moonscript;$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories) + ..\..\..\include;..\..\..\3rd-party\wren-0.1.0\src\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\duktape-2.2.0\src;..\..\..\3rd-party\blip-buf;..\..\..\3rd-party\moonscript;$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories) LUA_COMPAT_5_2;_CRT_SECURE_NO_WARNINGS;TIC80_SHARED;_WINDLL;%(PreprocessorDefinitions) false diff --git a/build/uwp/tic80/tic80.vcxproj.filters b/build/uwp/tic80/tic80.vcxproj.filters index 2dc1824..ef8abed 100644 --- a/build/uwp/tic80/tic80.vcxproj.filters +++ b/build/uwp/tic80/tic80.vcxproj.filters @@ -36,5 +36,8 @@ src\ext + + src + \ No newline at end of file diff --git a/build/uwp/wren/wren.vcxproj b/build/uwp/wren/wren.vcxproj new file mode 100644 index 0000000..901b188 --- /dev/null +++ b/build/uwp/wren/wren.vcxproj @@ -0,0 +1,210 @@ + + + + + Debug + ARM + + + Debug + Win32 + + + Debug + x64 + + + Release + ARM + + + Release + Win32 + + + Release + x64 + + + + + + + + + + + + + + + {bbb0d01a-b124-416c-be26-e6993154a555} + StaticLibrary + wren + en-US + 14.0 + true + Windows Store + 10.0.14393.0 + 10.0.14393.0 + 10.0 + + + + StaticLibrary + true + v140 + + + StaticLibrary + true + v140 + + + StaticLibrary + true + v140 + + + StaticLibrary + false + true + v140 + + + StaticLibrary + false + true + v140 + + + StaticLibrary + false + true + v140 + + + + + + + + + + + + + + + + + + + + + + + + + + + + false + + + false + + + false + + + false + + + false + + + false + + + + NotUsing + false + false + ..\..\..\3rd-party\wren-0.1.0\src\include;..\..\..\3rd-party\wren-0.1.0\src\optional;..\..\..\3rd-party\wren-0.1.0\src\vm;$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories) + + + Console + false + false + + + + + NotUsing + false + false + ..\..\..\3rd-party\wren-0.1.0\src\include;..\..\..\3rd-party\wren-0.1.0\src\optional;..\..\..\3rd-party\wren-0.1.0\src\vm;$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories) + + + Console + false + false + + + + + NotUsing + false + false + ..\..\..\3rd-party\wren-0.1.0\src\include;..\..\..\3rd-party\wren-0.1.0\src\optional;..\..\..\3rd-party\wren-0.1.0\src\vm;$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories) + + + Console + false + false + + + + + NotUsing + false + false + ..\..\..\3rd-party\wren-0.1.0\src\include;..\..\..\3rd-party\wren-0.1.0\src\optional;..\..\..\3rd-party\wren-0.1.0\src\vm;$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories) + + + Console + false + false + + + + + NotUsing + false + false + ..\..\..\3rd-party\wren-0.1.0\src\include;..\..\..\3rd-party\wren-0.1.0\src\optional;..\..\..\3rd-party\wren-0.1.0\src\vm;$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories) + + + Console + false + false + + + + + NotUsing + false + false + ..\..\..\3rd-party\wren-0.1.0\src\include;..\..\..\3rd-party\wren-0.1.0\src\optional;..\..\..\3rd-party\wren-0.1.0\src\vm;$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories) + + + Console + false + false + + + + + + \ No newline at end of file diff --git a/build/uwp/wren/wren.vcxproj.filters b/build/uwp/wren/wren.vcxproj.filters new file mode 100644 index 0000000..360f98c --- /dev/null +++ b/build/uwp/wren/wren.vcxproj.filters @@ -0,0 +1,43 @@ + + + + + {7ad0ea3c-f232-4a85-aa42-acd2fd0f1d6b} + + + {530552c5-b8aa-496d-8bd6-255dc647f6b8} + + + {9e502f35-bbe6-4594-980c-c1645d31225e} + + + + + src\vm + + + src\vm + + + src\vm + + + src\vm + + + src\vm + + + src\vm + + + src\vm + + + src\optional + + + src\optional + + + \ No newline at end of file diff --git a/build/windows/example/example.vcxproj b/build/windows/example/example.vcxproj index 8982b6b..ab0a909 100644 --- a/build/windows/example/example.vcxproj +++ b/build/windows/example/example.vcxproj @@ -1,5 +1,5 @@  - + Debug Pro @@ -58,52 +58,52 @@ Application true - v140 + v140_xp Unicode Application true - v140 + v140_xp Unicode Application false - v140 + v140_xp true Unicode Application false - v140 + v140_xp true Unicode Application true - v140 + v140_xp Unicode Application true - v140 + v140_xp Unicode Application false - v140 + v140_xp true Unicode Application false - v140 + v140_xp true Unicode diff --git a/build/windows/lua/lua.vcxproj.user b/build/windows/lua/lua.vcxproj.user new file mode 100644 index 0000000..be25078 --- /dev/null +++ b/build/windows/lua/lua.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/build/windows/tic/tic.sln b/build/windows/tic/tic.sln index 6e45ff4..8fa78d5 100644 --- a/build/windows/tic/tic.sln +++ b/build/windows/tic/tic.sln @@ -1,9 +1,12 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25420.1 +# Visual Studio 15 +VisualStudioVersion = 15.0.27130.2024 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tic", "tic.vcxproj", "{B6ECC66E-26FA-42C2-8F6C-E4338424F38A}" + ProjectSection(ProjectDependencies) = postProject + {D7CC5189-C399-AC94-ECB2-9A3CD8DEE122} = {D7CC5189-C399-AC94-ECB2-9A3CD8DEE122} + EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lua", "..\lua\lua.vcxproj", "{57D2471B-3138-495E-AF18-6E290D098FFC}" EndProject @@ -12,6 +15,9 @@ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gif", "..\gif\gif.vcxproj", "{6EA9D998-7557-4AED-ABFC-142F9960C9B6}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tic80", "..\tic80\tic80.vcxproj", "{C4D8BC10-EBF6-42BB-9B5D-6712FB428A50}" + ProjectSection(ProjectDependencies) = postProject + {D7CC5189-C399-AC94-ECB2-9A3CD8DEE122} = {D7CC5189-C399-AC94-ECB2-9A3CD8DEE122} + EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example", "..\example\example.vcxproj", "{86CAA9C1-C61A-40D8-AC77-33D94754C824}" EndProject @@ -19,6 +25,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SDL2", "..\..\..\3rd-party\ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SDL2main", "..\..\..\3rd-party\SDL2-2.0.7\VisualC\SDLmain\SDLmain.vcxproj", "{DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wren_lib", "..\wren\wren_lib.vcxproj", "{D7CC5189-C399-AC94-ECB2-9A3CD8DEE122}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug Pro|x64 = Debug Pro|x64 @@ -159,8 +167,27 @@ Global {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Release|x64.Build.0 = Release|x64 {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Release|x86.ActiveCfg = Release|Win32 {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}.Release|x86.Build.0 = Release|Win32 + {D7CC5189-C399-AC94-ECB2-9A3CD8DEE122}.Debug Pro|x64.ActiveCfg = Debug|x64 + {D7CC5189-C399-AC94-ECB2-9A3CD8DEE122}.Debug Pro|x64.Build.0 = Debug|x64 + {D7CC5189-C399-AC94-ECB2-9A3CD8DEE122}.Debug Pro|x86.ActiveCfg = Debug|Win32 + {D7CC5189-C399-AC94-ECB2-9A3CD8DEE122}.Debug Pro|x86.Build.0 = Debug|Win32 + {D7CC5189-C399-AC94-ECB2-9A3CD8DEE122}.Debug|x64.ActiveCfg = Debug|x64 + {D7CC5189-C399-AC94-ECB2-9A3CD8DEE122}.Debug|x64.Build.0 = Debug|x64 + {D7CC5189-C399-AC94-ECB2-9A3CD8DEE122}.Debug|x86.ActiveCfg = Debug|Win32 + {D7CC5189-C399-AC94-ECB2-9A3CD8DEE122}.Debug|x86.Build.0 = Debug|Win32 + {D7CC5189-C399-AC94-ECB2-9A3CD8DEE122}.Release Pro|x64.ActiveCfg = Release|x64 + {D7CC5189-C399-AC94-ECB2-9A3CD8DEE122}.Release Pro|x64.Build.0 = Release|x64 + {D7CC5189-C399-AC94-ECB2-9A3CD8DEE122}.Release Pro|x86.ActiveCfg = Release|Win32 + {D7CC5189-C399-AC94-ECB2-9A3CD8DEE122}.Release Pro|x86.Build.0 = Release|Win32 + {D7CC5189-C399-AC94-ECB2-9A3CD8DEE122}.Release|x64.ActiveCfg = Release|x64 + {D7CC5189-C399-AC94-ECB2-9A3CD8DEE122}.Release|x64.Build.0 = Release|x64 + {D7CC5189-C399-AC94-ECB2-9A3CD8DEE122}.Release|x86.ActiveCfg = Release|Win32 + {D7CC5189-C399-AC94-ECB2-9A3CD8DEE122}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {00596857-9AA6-41D1-915F-305DA18C13AE} + EndGlobalSection EndGlobal diff --git a/build/windows/tic/tic.vcxproj b/build/windows/tic/tic.vcxproj index 38b4606..e5a5593 100644 --- a/build/windows/tic/tic.vcxproj +++ b/build/windows/tic/tic.vcxproj @@ -210,7 +210,7 @@ Disabled _CRT_SECURE_NO_WARNINGS;LUA_COMPAT_5_2;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) MultiThreadedDebug - ..\include;..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\zlib-1.2.8;..\..\..\3rd-party\SDL2-2.0.7\include;..\..\..\3rd-party\SDL2_net-2.0.1 + ..\include;..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\zlib-1.2.8;..\..\..\3rd-party\SDL2-2.0.7\include;..\..\..\3rd-party\SDL2_net-2.0.1;..\..\..\3rd-party\wren-0.1.0\src\include Windows @@ -227,7 +227,7 @@ Disabled TIC80_PRO;_CRT_SECURE_NO_WARNINGS;LUA_COMPAT_5_2;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) MultiThreadedDebug - ..\include;..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\zlib-1.2.8;..\..\..\3rd-party\SDL2-2.0.7\include;..\..\..\3rd-party\SDL2_net-2.0.1 + ..\include;..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\zlib-1.2.8;..\..\..\3rd-party\SDL2-2.0.7\include;..\..\..\3rd-party\SDL2_net-2.0.1;..\..\..\3rd-party\wren-0.1.0\src\include Windows @@ -244,7 +244,7 @@ Disabled _CRT_SECURE_NO_WARNINGS;LUA_COMPAT_5_2;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) MultiThreadedDebug - ..\include;..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\zlib-1.2.8;..\..\..\3rd-party\SDL2-2.0.7\include;..\..\..\3rd-party\SDL2_net-2.0.1 + ..\include;..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\zlib-1.2.8;..\..\..\3rd-party\SDL2-2.0.7\include;..\..\..\3rd-party\SDL2_net-2.0.1;..\..\..\3rd-party\wren-0.1.0\src\include Windows @@ -261,7 +261,7 @@ Disabled TIC80_PRO;_CRT_SECURE_NO_WARNINGS;LUA_COMPAT_5_2;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) MultiThreadedDebug - ..\include;..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\zlib-1.2.8;..\..\..\3rd-party\SDL2-2.0.7\include;..\..\..\3rd-party\SDL2_net-2.0.1 + ..\include;..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\zlib-1.2.8;..\..\..\3rd-party\SDL2-2.0.7\include;..\..\..\3rd-party\SDL2_net-2.0.1;..\..\..\3rd-party\wren-0.1.0\src\include Windows @@ -280,7 +280,7 @@ true _CRT_SECURE_NO_WARNINGS;LUA_COMPAT_5_2;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) MultiThreaded - ..\include;..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\zlib-1.2.8;..\..\..\3rd-party\SDL2-2.0.7\include;..\..\..\3rd-party\SDL2_net-2.0.1 + ..\include;..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\zlib-1.2.8;..\..\..\3rd-party\SDL2-2.0.7\include;..\..\..\3rd-party\SDL2_net-2.0.1;..\..\..\3rd-party\wren-0.1.0\src\include Windows @@ -301,7 +301,7 @@ true TIC80_PRO;_CRT_SECURE_NO_WARNINGS;LUA_COMPAT_5_2;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) MultiThreaded - ..\include;..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\zlib-1.2.8;..\..\..\3rd-party\SDL2-2.0.7\include;..\..\..\3rd-party\SDL2_net-2.0.1 + ..\include;..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\zlib-1.2.8;..\..\..\3rd-party\SDL2-2.0.7\include;..\..\..\3rd-party\SDL2_net-2.0.1;..\..\..\3rd-party\wren-0.1.0\src\include Windows @@ -322,7 +322,7 @@ true _CRT_SECURE_NO_WARNINGS;LUA_COMPAT_5_2;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) MultiThreaded - ..\include;..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\zlib-1.2.8;..\..\..\3rd-party\SDL2-2.0.7\include;..\..\..\3rd-party\SDL2_net-2.0.1 + ..\include;..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\zlib-1.2.8;..\..\..\3rd-party\SDL2-2.0.7\include;..\..\..\3rd-party\SDL2_net-2.0.1;..\..\..\3rd-party\wren-0.1.0\src\include Windows @@ -343,7 +343,7 @@ true TIC80_PRO;_CRT_SECURE_NO_WARNINGS;LUA_COMPAT_5_2;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) MultiThreaded - ..\include;..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\zlib-1.2.8;..\..\..\3rd-party\SDL2-2.0.7\include;..\..\..\3rd-party\SDL2_net-2.0.1 + ..\include;..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\zlib-1.2.8;..\..\..\3rd-party\SDL2-2.0.7\include;..\..\..\3rd-party\SDL2_net-2.0.1;..\..\..\3rd-party\wren-0.1.0\src\include Windows diff --git a/build/windows/tic80/tic80.vcxproj b/build/windows/tic80/tic80.vcxproj index a0cc0e2..ddfff3b 100644 --- a/build/windows/tic80/tic80.vcxproj +++ b/build/windows/tic80/tic80.vcxproj @@ -43,6 +43,7 @@ + @@ -51,6 +52,9 @@ {57d2471b-3138-495e-af18-6e290d098ffc} + + {d7cc5189-c399-ac94-ecb2-9a3cd8dee122} + {C4D8BC10-EBF6-42BB-9B5D-6712FB428A50} @@ -172,7 +176,7 @@ Level3 Disabled WIN32;_DEBUG;_WINDOWS;_USRDLL;TIC80_EXPORTS;%(PreprocessorDefinitions) - ..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\duktape-2.2.0\src;..\..\..\3rd-party\blip-buf;..\..\..\3rd-party\moonscript + ..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\duktape-2.2.0\src;..\..\..\3rd-party\blip-buf;..\..\..\3rd-party\moonscript;..\..\..\3rd-party\wren-0.1.0\src\include MultiThreadedDebug @@ -187,7 +191,7 @@ Level3 Disabled TIC80_PRO;WIN32;_DEBUG;_WINDOWS;_USRDLL;TIC80_EXPORTS;%(PreprocessorDefinitions) - ..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\duktape-2.2.0\src;..\..\..\3rd-party\blip-buf;..\..\..\3rd-party\moonscript + ..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\duktape-2.2.0\src;..\..\..\3rd-party\blip-buf;..\..\..\3rd-party\moonscript;..\..\..\3rd-party\wren-0.1.0\src\include MultiThreadedDebug @@ -202,7 +206,7 @@ Level3 Disabled _DEBUG;_WINDOWS;_USRDLL;TIC80_EXPORTS;%(PreprocessorDefinitions) - ..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\duktape-2.2.0\src;..\..\..\3rd-party\blip-buf;..\..\..\3rd-party\moonscript + ..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\duktape-2.2.0\src;..\..\..\3rd-party\blip-buf;..\..\..\3rd-party\moonscript;..\..\..\3rd-party\wren-0.1.0\src\include MultiThreadedDebug @@ -217,7 +221,7 @@ Level3 Disabled TIC80_PRO;_DEBUG;_WINDOWS;_USRDLL;TIC80_EXPORTS;%(PreprocessorDefinitions) - ..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\duktape-2.2.0\src;..\..\..\3rd-party\blip-buf;..\..\..\3rd-party\moonscript + ..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\duktape-2.2.0\src;..\..\..\3rd-party\blip-buf;..\..\..\3rd-party\moonscript;..\..\..\3rd-party\wren-0.1.0\src\include MultiThreadedDebug @@ -234,7 +238,7 @@ true true WIN32;NDEBUG;_WINDOWS;_USRDLL;TIC80_EXPORTS;%(PreprocessorDefinitions) - ..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\duktape-2.2.0\src;..\..\..\3rd-party\blip-buf;..\..\..\3rd-party\moonscript + ..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\duktape-2.2.0\src;..\..\..\3rd-party\blip-buf;..\..\..\3rd-party\moonscript;..\..\..\3rd-party\wren-0.1.0\src\include MultiThreaded @@ -253,7 +257,7 @@ true true TIC80_PRO;WIN32;NDEBUG;_WINDOWS;_USRDLL;TIC80_EXPORTS;%(PreprocessorDefinitions) - ..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\duktape-2.2.0\src;..\..\..\3rd-party\blip-buf;..\..\..\3rd-party\moonscript + ..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\duktape-2.2.0\src;..\..\..\3rd-party\blip-buf;..\..\..\3rd-party\moonscript;..\..\..\3rd-party\wren-0.1.0\src\include MultiThreaded @@ -272,7 +276,7 @@ true true NDEBUG;_WINDOWS;_USRDLL;TIC80_EXPORTS;%(PreprocessorDefinitions) - ..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\duktape-2.2.0\src;..\..\..\3rd-party\blip-buf;..\..\..\3rd-party\moonscript + ..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\duktape-2.2.0\src;..\..\..\3rd-party\blip-buf;..\..\..\3rd-party\moonscript;..\..\..\3rd-party\wren-0.1.0\src\include MultiThreaded @@ -291,7 +295,7 @@ true true TIC80_PRO;NDEBUG;_WINDOWS;_USRDLL;TIC80_EXPORTS;%(PreprocessorDefinitions) - ..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\duktape-2.2.0\src;..\..\..\3rd-party\blip-buf;..\..\..\3rd-party\moonscript + ..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\duktape-2.2.0\src;..\..\..\3rd-party\blip-buf;..\..\..\3rd-party\moonscript;..\..\..\3rd-party\wren-0.1.0\src\include MultiThreaded diff --git a/build/windows/tic80/tic80.vcxproj.filters b/build/windows/tic80/tic80.vcxproj.filters index 4f9b12f..b2f865e 100644 --- a/build/windows/tic80/tic80.vcxproj.filters +++ b/build/windows/tic80/tic80.vcxproj.filters @@ -36,5 +36,8 @@ src\ext + + src + \ No newline at end of file diff --git a/build/windows/tic80/tic80.vcxproj.user b/build/windows/tic80/tic80.vcxproj.user new file mode 100644 index 0000000..be25078 --- /dev/null +++ b/build/windows/tic80/tic80.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/build/windows/wren/wren_lib.vcxproj b/build/windows/wren/wren_lib.vcxproj new file mode 100644 index 0000000..edeb00b --- /dev/null +++ b/build/windows/wren/wren_lib.vcxproj @@ -0,0 +1,194 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {D7CC5189-C399-AC94-ECB2-9A3CD8DEE122} + true + Win32Proj + wren_lib + 8.1 + + + + StaticLibrary + true + MultiByte + v140_xp + + + StaticLibrary + true + MultiByte + v140_xp + + + StaticLibrary + false + MultiByte + v140_xp + true + + + StaticLibrary + false + MultiByte + v140_xp + true + + + + + + + + + + + + + + + + + + + $(SolutionDir)$(Configuration)\ + $(Configuration)\ + $(ProjectName) + .lib + + + $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ + $(ProjectName) + .lib + + + $(SolutionDir)$(Configuration)\ + $(Configuration)\ + $(ProjectName) + .lib + + + $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ + $(ProjectName) + .lib + + + + NotUsing + Level3 + _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + ..\..\..\3rd-party\wren-0.1.0\src\include;..\..\..\3rd-party\wren-0.1.0\src\vm;..\..\..\3rd-party\wren-0.1.0\src\optional;%(AdditionalIncludeDirectories) + EditAndContinue + Disabled + CompileAsC + MultiThreadedDebug + + + Windows + true + + + + + NotUsing + Level3 + _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + ..\..\..\3rd-party\wren-0.1.0\src\include;..\..\..\3rd-party\wren-0.1.0\src\vm;..\..\..\3rd-party\wren-0.1.0\src\optional;%(AdditionalIncludeDirectories) + EditAndContinue + Disabled + CompileAsC + MultiThreadedDebug + + + Windows + true + + + + + NotUsing + Level3 + NDEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + ..\..\..\3rd-party\wren-0.1.0\src\include;..\..\..\3rd-party\wren-0.1.0\src\vm;..\..\..\3rd-party\wren-0.1.0\src\optional;%(AdditionalIncludeDirectories) + Full + true + true + false + true + CompileAsC + MultiThreaded + + + Windows + true + true + + + + + NotUsing + Level3 + NDEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + ..\..\..\3rd-party\wren-0.1.0\src\include;..\..\..\3rd-party\wren-0.1.0\src\vm;..\..\..\3rd-party\wren-0.1.0\src\optional;%(AdditionalIncludeDirectories) + Full + true + true + false + true + CompileAsC + MultiThreaded + + + Windows + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/build/windows/wren/wren_lib.vcxproj.filters b/build/windows/wren/wren_lib.vcxproj.filters new file mode 100644 index 0000000..f90565f --- /dev/null +++ b/build/windows/wren/wren_lib.vcxproj.filters @@ -0,0 +1,75 @@ + + + + + {CB60FAAF-B72D-55BB-E046-4363CC728A49} + + + {E8795900-D405-880B-3DB4-880B295F880B} + + + + + optional + + + optional + + + vm + + + vm + + + vm + + + vm + + + vm + + + vm + + + vm + + + vm + + + vm + + + + + optional + + + optional + + + vm + + + vm + + + vm + + + vm + + + vm + + + vm + + + vm + + + \ No newline at end of file diff --git a/build/windows/wren/wren_lib.vcxproj.user b/build/windows/wren/wren_lib.vcxproj.user new file mode 100644 index 0000000..be25078 --- /dev/null +++ b/build/windows/wren/wren_lib.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/demos/wrendemo.tic b/demos/wrendemo.tic new file mode 100644 index 0000000000000000000000000000000000000000..1252e9e91e726f7e11a5a530ab7339f29e535c3b GIT binary patch literal 1272 zcmeHHzi-n(6n6MA_|$=ck>N0{WVZ*g9jk&!?$kh4MXiJ?Ar>s-9KllJ7~iE$RI(sd zGLt7Hx|M~Y{0EGTNFY=p288$%oEw>P+&Q>ph}5BC<9_Jfcklb&-T6Jaa&$pCt4+9Q znxMy^oDAg*YA?@Hggl)fz zrvQjuzfYg`lKOPFg?DkM7vn^FT9^ca4vFy70wrNg!(JqvB#@vE_Yxcd5OjP(;5`{Q zB(M>+!wAED0Mwut5t{S^3M0Iy8~Z?2J?fg$4BR`b(hgnQ0qO{-K<&pZpW-Pke4_7! z!L7$M(oLffN~$-!X$g^Ft1|>^masC1V3&k}>kZ~bsLc}oL=b1l8w4GqTQvhfC=rPh z-CEIgk1nm6Mzv->H;rW*c?0APk>#KoGDWwMT?*nPjHs?{G@8wA_+a~fbN#x8ZaZQa z^7Yj9s61~3fEeo9`6}_^C16e?$X||JNqfcK*?s-~$7KBJ-OG04My151T@ae93)j{c u9nfs, name)) name = getName(param, PROJECT_JS_EXT); + if(!fsExistsFile(console->fs, name)) + name = getName(param, PROJECT_WREN_EXT); + void* data = fsLoadFile(console->fs, name, &size); if(data) @@ -1053,6 +1072,8 @@ static void onConsoleNewCommandConfirmed(Console* console, const char* param) loadDemo(console, MoonScript); else if(strcmp(param, "js") == 0 || strcmp(param, "javascript") == 0) loadDemo(console, JavaScript); + else if(strcmp(param, "wren") == 0) + loadDemo(console, WrenScript); else { printError(console, "\nunknown parameter: "); @@ -1317,6 +1338,10 @@ static void onConsoleConfigCommand(Console* console, const char* param) { onConsoleLoadDemoCommand(console, DefaultJSTicPath); } + else if(strcmp(param, "default wren") == 0) + { + onConsoleLoadDemoCommand(console, DefaultWrenTicPath); + } else { printError(console, "\nunknown parameter: "); diff --git a/src/machine.h b/src/machine.h index b2c073b..da89f4b 100644 --- a/src/machine.h +++ b/src/machine.h @@ -121,6 +121,7 @@ typedef struct { struct duk_hthread* js; struct lua_State* lua; + struct WrenVM* wren; }; blip_buffer_t* blip; @@ -159,3 +160,4 @@ void parseCode(const tic_script_config* config, const char* start, u8* color, co const tic_script_config* getLuaScriptConfig(); const tic_script_config* getMoonScriptConfig(); const tic_script_config* getJsScriptConfig(); +const tic_script_config* getWrenScriptConfig(); diff --git a/src/studio.h b/src/studio.h index 09e099c..67ef33b 100644 --- a/src/studio.h +++ b/src/studio.h @@ -64,6 +64,7 @@ #define PROJECT_LUA_EXT ".lua" #define PROJECT_MOON_EXT ".moon" #define PROJECT_JS_EXT ".js" +#define PROJECT_WREN_EXT ".wren" typedef struct { diff --git a/src/surf.c b/src/surf.c index 07d714e..002de04 100644 --- a/src/surf.c +++ b/src/surf.c @@ -395,6 +395,7 @@ static bool addMenuItem(const char* name, const char* info, s32 id, void* ptr, b || hasExt(name, PROJECT_LUA_EXT) || hasExt(name, PROJECT_MOON_EXT) || hasExt(name, PROJECT_JS_EXT) + || hasExt(name, PROJECT_WREN_EXT) #endif ) { diff --git a/src/tic.c b/src/tic.c index 852ea31..5f45390 100644 --- a/src/tic.c +++ b/src/tic.c @@ -561,6 +561,7 @@ void tic_close(tic_mem* memory) getLuaScriptConfig()->close(memory); getMoonScriptConfig()->close(memory); getJsScriptConfig()->close(memory); + getWrenScriptConfig()->close(memory); blip_delete(machine->blip); @@ -1528,10 +1529,16 @@ static bool isJavascript(const char* code) || compareMetatag(code, "script", "javascript", getJsScriptConfig()->singleComment); } +static bool isWren(const char* code) +{ + return compareMetatag(code, "script", "wren", getWrenScriptConfig()->singleComment); +} + static const tic_script_config* getScriptConfig(const char* code) { if(isMoonscript(code)) return getMoonScriptConfig(); if(isJavascript(code)) return getJsScriptConfig(); + if(isWren(code)) return getWrenScriptConfig(); return getLuaScriptConfig(); } diff --git a/src/wrenapi.c b/src/wrenapi.c new file mode 100644 index 0000000..8f190a4 --- /dev/null +++ b/src/wrenapi.c @@ -0,0 +1,1423 @@ +// MIT License + +// Copyright (c) 2017 Vadim Grigoruk @nesbox // grigoruk@gmail.com + +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: + +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#include +#include +#include +#include + +#include "machine.h" +#include "tools.h" +#include "wren.h" + +static WrenHandle* game_class; +static WrenHandle* new_handle; +static WrenHandle* update_handle; +static WrenHandle* scanline_handle; +static WrenHandle* overlap_handle; + +static bool loaded = false; + +static char const* tic_wren_api = " \n" +"class Tic { \n" +" foreign static btn(id) \n" +" foreign static btnp(id) \n" +" foreign static btnp(id, hold, period) \n" +" foreign static key(id) \n" +" foreign static keyp(id) \n" +" foreign static keyp(id, hold, period) \n" +" foreign static mouse() \n" +" foreign static font(text) \n" +" foreign static font(text, x, y) \n" +" foreign static font(text, x, y, alpha_color) \n" +" foreign static font(text, x, y, alpha_color, w, h) \n" +" foreign static font(text, x, y, alpha_color, w, h, fixed) \n" +" foreign static font(text, x, y, alpha_color, w, h, fixed, scale) \n" +" foreign static spr(id) \n" +" foreign static spr(id, x, y) \n" +" foreign static spr(id, x, y, alpha_color) \n" +" foreign static spr(id, x, y, alpha_color, scale) \n" +" foreign static spr(id, x, y, alpha_color, scale, flip) \n" +" foreign static spr(id, x, y, alpha_color, scale, flip, rotate) \n" +" foreign static spr(id, x, y, alpha_color, scale, flip, rotate, cell_width, cell_height) \n" +" foreign static map(cell_x, cell_y) \n" +" foreign static map(cell_x, cell_y, cell_w, cell_h) \n" +" foreign static map(cell_x, cell_y, cell_w, cell_h, x, y) \n" +" foreign static map(cell_x, cell_y, cell_w, cell_h, x, y, alpha_color) \n" +" foreign static map(cell_x, cell_y, cell_w, cell_h, x, y, alpha_color, scale) \n" +" foreign static mset(cell_x, cell_y) \n" +" foreign static mset(cell_x, cell_y, index) \n" +" foreign static mget(cell_x, cell_y) \n" +" foreign static textri(x1, y1, x2, y2, x3, y3, u1, v1, u2, v2, u3, v3) \n" +" foreign static textri(x1, y1, x2, y2, x3, y3, u1, v1, u2, v2, u3, v3, use_map) \n" +" foreign static textri(x1, y1, x2, y2, x3, y3, u1, v1, u2, v2, u3, v3, use_map, alpha_color) \n" +" foreign static pix(x, y) \n" +" foreign static pix(x, y, color) \n" +" foreign static line(x0, y0, x1, y1, color) \n" +" foreign static circ(x, y, radius, color) \n" +" foreign static circb(x, y, radius, color) \n" +" foreign static rect(x, y, w, h, color) \n" +" foreign static rectb(x, y, w, h, color) \n" +" foreign static tri(x1, y1, x2, y2, x3, y3, color) \n" +" foreign static cls() \n" +" foreign static cls(color) \n" +" foreign static clip() \n" +" foreign static clip(x, y, w, h) \n" +" foreign static peek(addr) \n" +" foreign static poke(addr, val) \n" +" foreign static peek4(addr) \n" +" foreign static poke4(addr, val) \n" +" foreign static memcpy(dst, src, size) \n" +" foreign static memset(dst, src, size) \n" +" foreign static pmem(index, val) \n" +" foreign static sfx(id) \n" +" foreign static sfx(id, note) \n" +" foreign static sfx(id, note, duration) \n" +" foreign static sfx(id, note, duration, channel) \n" +" foreign static sfx(id, note, duration, channel, volume) \n" +" foreign static sfx(id, note, duration, channel, volume, speed) \n" +" foreign static music() \n" +" foreign static music(track) \n" +" foreign static music(track, frame) \n" +" foreign static music(track, frame, loop) \n" +" foreign static time() \n" +" foreign static sync() \n" +" foreign static sync(mask) \n" +" foreign static sync(mask, bank) \n" +" foreign static sync(mask, bank, tocart) \n" +" foreign static reset() \n" +" foreign static exit() \n" +" foreign static map_width__ \n" +" foreign static map_height__ \n" +" foreign static spritesize__ \n" +" foreign static print__(v, x, y, color, fixed, scale) \n" +" foreign static trace__(msg, color) \n" +" foreign static spr__(id, x, y, alpha_color, scale, flip, rotate) \n" +" foreign static mgeti__(index) \n" +" static print(v) { Tic.print__(v.toString, 0, 0, 15, false, 1) } \n" +" static print(v,x,y) { Tic.print__(v.toString, x, y, 15, false, 1) } \n" +" static print(v,x,y,color) { Tic.print__(v.toString, x, y, color, false, 1) } \n" +" static print(v,x,y,color,fixed) { Tic.print__(v.toString, x, y, color, fixed, 1) } \n" +" static print(v,x,y,color,fixed,scale) { Tic.print__(v.toString, x, y, color, fixed, scale) } \n" +" static trace(v) { Tic.trace__(v.toString, 15) } \n" +" static trace(v,color) { Tic.trace__(v.toString, color) } \n" +" static map(cell_x, cell_y, cell_w, cell_h, x, y, alpha_color, scale, remap) { \n" +" var map_w = Tic.map_width__ \n" +" var map_h = Tic.map_height__ \n" +" var size = Tic.spritesize__ * scale \n" +" var jj = y \n" +" var ii = x \n" +" var flip = 0 \n" +" var rotate = 0 \n" +" for (j in cell_y...cell_y+cell_h) { \n" +" ii = x \n" +" for (i in cell_x...cell_x+cell_w) { \n" +" var mi = i \n" +" var mj = j \n" +" while(mi < 0) mi = mi + map_w \n" +" while(mj < 0) mj = mj + map_h \n" +" while(mi >= map_w) mi = mi - map_w \n" +" while(mj >= map_h) mj = mj - map_h \n" +" var index = mi + mj * map_w \n" +" var tile_index = Tic.mgeti__(index) \n" +" var ret = remap.call(tile_index, mi, mj) \n" +" if (ret.type == List) { \n" +" tile_index = ret[0] \n" +" flip = ret[1] \n" +" rotate = ret[2] \n" +" } else if (ret.type == Num) { \n" +" tile_index = ret \n" +" } \n" +" Tic.spr__(tile_index, ii, jj, alpha_color, scale, flip, rotate) \n" +" ii = ii + size \n" +" } \n" +" jj = jj + size \n" +" } \n" +" } \n" +"} \n" +"class Engine { \n" +" update(){} \n" +" scanline(row){} \n" +" overlap(){} \n" +"} \n" +""; + +static inline void wrenError(WrenVM* vm, const char* msg) +{ + wrenEnsureSlots(vm, 1); + wrenSetSlotString(vm, 0, msg); + wrenAbortFiber(vm, 0); +} + +static inline s32 getWrenNumber(WrenVM* vm, s32 index) +{ + return (s32)wrenGetSlotDouble(vm, index); +} + +static inline bool isNumber(WrenVM* vm, s32 index) +{ + return wrenGetSlotType(vm, index) == WREN_TYPE_NUM; +} + +static inline bool isString(WrenVM* vm, s32 index) +{ + return wrenGetSlotType(vm, index) == WREN_TYPE_STRING; +} + +static inline bool isList(WrenVM* vm, s32 index) +{ + return wrenGetSlotType(vm, index) == WREN_TYPE_LIST; +} + +static void closeWren(tic_mem* tic) +{ + tic_machine* machine = (tic_machine*)tic; + if(machine->wren) + { + // release handles + if (loaded) + { + wrenReleaseHandle(machine->wren, new_handle); + wrenReleaseHandle(machine->wren, update_handle); + wrenReleaseHandle(machine->wren, scanline_handle); + wrenReleaseHandle(machine->wren, overlap_handle); + if (game_class != NULL) { + wrenReleaseHandle(machine->wren, game_class); + } + } + + wrenFreeVM(machine->wren); + machine->wren = NULL; + + } + loaded = false; +} + +static tic_machine* getWrenMachine(WrenVM* vm) +{ + tic_machine* machine = wrenGetUserData(vm); + + return machine; +} + +static void wren_map_width(WrenVM* vm) +{ + wrenSetSlotDouble(vm, 0, TIC_MAP_WIDTH); +} + +static void wren_map_height(WrenVM* vm) +{ + wrenSetSlotDouble(vm, 0, TIC_MAP_HEIGHT); +} + +static void wren_mgeti(WrenVM* vm) +{ + + s32 index = getWrenNumber(vm, 1); + + if(index < 0 || index >= TIC_MAP_WIDTH * TIC_MAP_HEIGHT) { + wrenSetSlotDouble(vm, 0, 0); + return; + } + + tic_mem* memory = (tic_mem*)getWrenMachine(vm); + wrenSetSlotDouble(vm, 0, *(memory->ram.map.data + index)); +} + +static void wren_spritesize(WrenVM* vm) +{ + wrenSetSlotDouble(vm, 0, TIC_SPRITESIZE); +} + +static void wren_btn(WrenVM* vm) +{ + tic_machine* machine = getWrenMachine(vm); + + s32 top = wrenGetSlotCount(vm); + + if (top == 1) + { + wrenSetSlotBool(vm, 0, machine->memory.ram.input.gamepads.data); + } + else if (top == 2) + { + s32 index = getWrenNumber(vm, 1) & 0xf; + wrenSetSlotBool(vm, 0, machine->memory.ram.input.gamepads.data & (1 << index)); + } + +} + +static void wren_btnp(WrenVM* vm) +{ + tic_machine* machine = getWrenMachine(vm); + tic_mem* memory = (tic_mem*)machine; + + s32 top = wrenGetSlotCount(vm); + + if (top == 1) + { + wrenSetSlotBool(vm, 0, memory->api.btnp(memory, -1, -1, -1)); + } + else if(top == 2) + { + s32 index = getWrenNumber(vm, 1) & 0xf; + + wrenSetSlotBool(vm, 0, memory->api.btnp(memory, index, -1, -1)); + } + else if (top == 4) + { + s32 index = getWrenNumber(vm, 1) & 0xf; + u32 hold = getWrenNumber(vm, 2); + u32 period = getWrenNumber(vm, 3); + + wrenSetSlotBool(vm, 0, memory->api.btnp(memory, index, hold, period)); + } +} + +static void wren_key(WrenVM* vm) +{ + tic_machine* machine = getWrenMachine(vm); + tic_mem* tic = &machine->memory; + + s32 top = wrenGetSlotCount(vm); + + if (top == 1) + { + wrenSetSlotBool(vm, 0, tic->api.key(tic, tic_key_unknown)); + } + else if (top == 2) + { + tic_key key = getWrenNumber(vm, 1); + + if(key < tic_keys_count) + wrenSetSlotBool(vm, 0, tic->api.key(tic, key)); + else + { + wrenError(vm, "unknown keyboard code\n"); + return; + } + } +} + +static void wren_keyp(WrenVM* vm) +{ + tic_machine* machine = getWrenMachine(vm); + tic_mem* tic = &machine->memory; + + s32 top = wrenGetSlotCount(vm); + + if (top == 1) + { + wrenSetSlotBool(vm, 0, tic->api.keyp(tic, tic_key_unknown, -1, -1)); + } + else + { + tic_key key = getWrenNumber(vm, 1); + + if(key >= tic_keys_count) + { + wrenError(vm, "unknown keyboard code\n"); + } + else + { + if(top == 2) + { + wrenSetSlotBool(vm, 0, tic->api.keyp(tic, key, -1, -1)); + } + else if(top == 4) + { + u32 hold = getWrenNumber(vm, 2); + u32 period = getWrenNumber(vm, 3); + + wrenSetSlotBool(vm, 0, tic->api.keyp(tic, key, hold, period)); + } + } + } +} + + +static void wren_mouse(WrenVM* vm) +{ + tic_machine* machine = getWrenMachine(vm); + + const tic80_mouse* mouse = &machine->memory.ram.input.mouse; + + wrenEnsureSlots(vm, 4); + wrenSetSlotNewList(vm, 0); + wrenSetSlotDouble(vm, 1, mouse->x); + wrenInsertInList(vm, 0, 0, 1); + wrenSetSlotDouble(vm, 1, mouse->y); + wrenInsertInList(vm, 0, 1, 1); + wrenSetSlotBool(vm, 1, mouse->left); + wrenInsertInList(vm, 0, 2, 1); + wrenSetSlotBool(vm, 1, mouse->middle); + wrenInsertInList(vm, 0, 3, 1); + wrenSetSlotBool(vm, 1, mouse->right); + wrenInsertInList(vm, 0, 4, 1); +} + +static void wren_print(WrenVM* vm) +{ + tic_mem* memory = (tic_mem*)getWrenMachine(vm); + + const char* text = wrenGetSlotString(vm, 1); + + s32 x = getWrenNumber(vm, 2); + s32 y = getWrenNumber(vm, 3); + + s32 color = getWrenNumber(vm, 4) % TIC_PALETTE_SIZE; + + bool fixed = wrenGetSlotBool(vm, 5); + + s32 scale = getWrenNumber(vm, 6); + + if(scale == 0) + { + wrenSetSlotDouble(vm, 0, 0); + return; + } + + s32 size = memory->api.text_ex(memory, text, x, y, color, fixed, scale); + + wrenSetSlotDouble(vm, 0, size); +} + +static void wren_font(WrenVM* vm) +{ + tic_mem* memory = (tic_mem*)getWrenMachine(vm); + s32 top = wrenGetSlotCount(vm); + + if(top > 1) + { + const char* text = NULL; + if (isString(vm, 1)) + { + text = wrenGetSlotString(vm, 1); + } + + s32 x = 0; + s32 y = 0; + s32 width = TIC_SPRITESIZE; + s32 height = TIC_SPRITESIZE; + u8 chromakey = 0; + bool fixed = false; + s32 scale = 1; + + if(top > 3) + { + x = getWrenNumber(vm, 2); + y = getWrenNumber(vm, 3); + + if(top > 4) + { + chromakey = getWrenNumber(vm, 4); + + if(top > 6) + { + width = getWrenNumber(vm, 5); + height = getWrenNumber(vm, 6); + + if(top > 7) + { + fixed = wrenGetSlotBool(vm, 7); + + if(top > 8) + { + scale = getWrenNumber(vm, 8); + } + } + } + } + } + + if(scale == 0) + { + wrenSetSlotDouble(vm, 0, 0); + return; + } + + s32 size = drawText(memory, text ? text : "null", x, y, width, height, chromakey, scale, fixed ? drawSpriteFont : drawFixedSpriteFont); + wrenSetSlotDouble(vm, 0, size); + } +} + +static void wren_trace(WrenVM* vm) +{ + tic_machine* machine = getWrenMachine(vm); + + const char* text = wrenGetSlotString(vm, 1); + u8 color = (u8)getWrenNumber(vm, 2); + + machine->data->trace(machine->data->data, text, color); +} + +static void wren_spr(WrenVM* vm) +{ + s32 top = wrenGetSlotCount(vm); + + s32 index = 0; + s32 x = 0; + s32 y = 0; + s32 w = 1; + s32 h = 1; + s32 scale = 1; + tic_flip flip = tic_no_flip; + tic_rotate rotate = tic_no_rotate; + static u8 colors[TIC_PALETTE_SIZE]; + s32 count = 0; + + if(top > 1) + { + index = getWrenNumber(vm, 1); + + if(top > 3) + { + x = getWrenNumber(vm, 2); + y = getWrenNumber(vm, 3); + + if(top > 4) + { + if(isList(vm, 4)) + { + for(s32 i = 0; i < TIC_PALETTE_SIZE; i++) + { + wrenGetListElement(vm, 4, i, 0); // todo, can be bug cause in slot 0 is object? + if(isNumber(vm, 0)) + { + colors[i] = getWrenNumber(vm, 0); + count++; + } + else + { + break; + } + } + } + else + { + colors[0] = getWrenNumber(vm, 4); + count = 1; + } + + if(top > 5) + { + scale = getWrenNumber(vm, 5); + + if(top > 6) + { + flip = getWrenNumber(vm, 6); + + if(top > 7) + { + rotate = getWrenNumber(vm, 7); + + if(top > 9) + { + w = getWrenNumber(vm, 8); + h = getWrenNumber(vm, 9); + } + } + } + } + } + } + } + + tic_mem* memory = (tic_mem*)getWrenMachine(vm); + + memory->api.sprite_ex(memory, &memory->ram.tiles, index, x, y, w, h, colors, count, scale, flip, rotate); +} + +static void wren_spr_internal(WrenVM* vm) +{ + s32 index = getWrenNumber(vm, 1); + s32 x = getWrenNumber(vm, 2); + s32 y = getWrenNumber(vm, 3); + + static u8 colors[TIC_PALETTE_SIZE]; + s32 count = 0; + + if(isList(vm, 4)) { + for(s32 i = 0; i < TIC_PALETTE_SIZE; i++) { + wrenGetListElement(vm, 4, i, 0); // todo, can be bug cause in slot 0 is object? + if(isNumber(vm, 0)) { + colors[i] = getWrenNumber(vm, 0); + count++; + } else { + break; + } + } + } + else + { + colors[0] = getWrenNumber(vm, 4); + count = 1; + } + + s32 scale = getWrenNumber(vm, 5); + s32 flip = getWrenNumber(vm, 6); + s32 rotate = getWrenNumber(vm, 7); + + tic_mem* memory = (tic_mem*)getWrenMachine(vm); + + memory->api.sprite_ex(memory, &memory->ram.tiles, index, x, y, 1, 1, colors, count, scale, flip, rotate); +} + +static void wren_map(WrenVM* vm) +{ + s32 x = 0; + s32 y = 0; + s32 w = TIC_MAP_SCREEN_WIDTH; + s32 h = TIC_MAP_SCREEN_HEIGHT; + s32 sx = 0; + s32 sy = 0; + u8 chromakey = -1; + s32 scale = 1; + + s32 top = wrenGetSlotCount(vm); + + if(top > 2) + { + x = getWrenNumber(vm, 1); + y = getWrenNumber(vm, 2); + + if(top > 4) + { + w = getWrenNumber(vm, 3); + h = getWrenNumber(vm, 4); + + if(top > 6) + { + sx = getWrenNumber(vm, 5); + sy = getWrenNumber(vm, 6); + + if(top > 7) + { + chromakey = getWrenNumber(vm, 7); + + if(top > 8) + { + scale = getWrenNumber(vm, 8); + } + } + } + } + } + + tic_mem* memory = (tic_mem*)getWrenMachine(vm); + + memory->api.map(memory, &memory->ram.map, &memory->ram.tiles, x, y, w, h, sx, sy, chromakey, scale); +} + +static void wren_mset(WrenVM* vm) +{ + + s32 x = getWrenNumber(vm, 1); + s32 y = getWrenNumber(vm, 2); + u8 value = getWrenNumber(vm, 3); + + tic_mem* memory = (tic_mem*)getWrenMachine(vm); + + memory->api.map_set(memory, &memory->ram.map, x, y, value); +} + +static void wren_mget(WrenVM* vm) +{ + s32 x = getWrenNumber(vm, 1); + s32 y = getWrenNumber(vm, 2); + + tic_mem* memory = (tic_mem*)getWrenMachine(vm); + + u8 value = memory->api.map_get(memory, &memory->ram.map, x, y); + wrenSetSlotDouble(vm, 0, value); +} + +static void wren_textri(WrenVM* vm) +{ + int top = wrenGetSlotCount(vm); + + float pt[12]; + + for (s32 i = 0; i < COUNT_OF(pt); i++){ + pt[i] = (float)getWrenNumber(vm, i + 1); + } + + tic_mem* memory = (tic_mem*)getWrenMachine(vm); + u8 chroma = 0xff; + bool use_map = false; + + // check for use map + if (top > 13){ + use_map = wrenGetSlotBool(vm, 13); + } + + // check for chroma + if (top > 14){ + chroma = (u8)getWrenNumber(vm, 14); + } + + memory->api.textri(memory, pt[0], pt[1], // xy 1 + pt[2], pt[3], // xy 2 + pt[4], pt[5], // xy 3 + pt[6], pt[7], // uv 1 + pt[8], pt[9], // uv 2 + pt[10], pt[11], // uv 3 + use_map, // use map + chroma); // chroma +} + +static void wren_pix(WrenVM* vm) +{ + int top = wrenGetSlotCount(vm); + + s32 x = getWrenNumber(vm, 1); + s32 y = getWrenNumber(vm, 2); + + tic_mem* memory = (tic_mem*)getWrenMachine(vm); + + if(top > 3) + { + s32 color = getWrenNumber(vm, 3); + memory->api.pixel(memory, x, y, color); + } + else + { + wrenSetSlotDouble(vm, 0, memory->api.get_pixel(memory, x, y)); + } +} + +static void wren_line(WrenVM* vm) +{ + s32 x0 = getWrenNumber(vm, 1); + s32 y0 = getWrenNumber(vm, 2); + s32 x1 = getWrenNumber(vm, 3); + s32 y1 = getWrenNumber(vm, 4); + s32 color = getWrenNumber(vm, 5); + + tic_mem* memory = (tic_mem*)getWrenMachine(vm); + + memory->api.line(memory, x0, y0, x1, y1, color); +} + +static void wren_circ(WrenVM* vm) +{ + s32 radius = getWrenNumber(vm, 3); + if(radius < 0) { + return; + } + + s32 x = getWrenNumber(vm, 1); + s32 y = getWrenNumber(vm, 2); + s32 color = getWrenNumber(vm, 4); + + tic_mem* memory = (tic_mem*)getWrenMachine(vm); + + memory->api.circle(memory, x, y, radius, color); +} + +static void wren_circb(WrenVM* vm) +{ + s32 radius = getWrenNumber(vm, 3); + if(radius < 0) return; + + s32 x = getWrenNumber(vm, 1); + s32 y = getWrenNumber(vm, 2); + s32 color = getWrenNumber(vm, 4); + + tic_mem* memory = (tic_mem*)getWrenMachine(vm); + + memory->api.circle_border(memory, x, y, radius, color); +} + +static void wren_rect(WrenVM* vm) +{ + s32 x = getWrenNumber(vm, 1); + s32 y = getWrenNumber(vm, 2); + s32 w = getWrenNumber(vm, 3); + s32 h = getWrenNumber(vm, 4); + s32 color = getWrenNumber(vm, 5); + + tic_mem* memory = (tic_mem*)getWrenMachine(vm); + + memory->api.rect(memory, x, y, w, h, color); +} + +static void wren_rectb(WrenVM* vm) +{ + s32 x = getWrenNumber(vm, 1); + s32 y = getWrenNumber(vm, 2); + s32 w = getWrenNumber(vm, 3); + s32 h = getWrenNumber(vm, 4); + s32 color = getWrenNumber(vm, 5); + + tic_mem* memory = (tic_mem*)getWrenMachine(vm); + + memory->api.rect_border(memory, x, y, w, h, color); +} + +static void wren_tri(WrenVM* vm) +{ + s32 pt[6]; + + for(s32 i = 0; i < COUNT_OF(pt); i++){ + pt[i] = getWrenNumber(vm, i+1); + } + + s32 color = getWrenNumber(vm, 7); + + tic_mem* memory = (tic_mem*)getWrenMachine(vm); + + memory->api.tri(memory, pt[0], pt[1], pt[2], pt[3], pt[4], pt[5], color); +} + +static void wren_cls(WrenVM* vm) +{ + int top = wrenGetSlotCount(vm); + + tic_mem* memory = (tic_mem*)getWrenMachine(vm); + + memory->api.clear(memory, top == 1 ? 0 : getWrenNumber(vm, 1)); +} + +static void wren_clip(WrenVM* vm) +{ + s32 top = wrenGetSlotCount(vm); + + tic_mem* memory = (tic_mem*)getWrenMachine(vm); + + if(top == 1) + { + memory->api.clip(memory, 0, 0, TIC80_WIDTH, TIC80_HEIGHT); + } + else + { + s32 x = getWrenNumber(vm, 1); + s32 y = getWrenNumber(vm, 2); + s32 w = getWrenNumber(vm, 3); + s32 h = getWrenNumber(vm, 4); + + memory->api.clip(memory, x, y, w, h); + } +} + +static void wren_peek(WrenVM* vm) +{ + tic_machine* machine = getWrenMachine(vm); + + s32 address = getWrenNumber(vm, 1); + + if(address >= 0 && address < sizeof(tic_ram)) + { + wrenSetSlotDouble(vm, 0, *((u8*)&machine->memory.ram + address)); + } +} + +static void wren_poke(WrenVM* vm) +{ + tic_machine* machine = getWrenMachine(vm); + + s32 address = getWrenNumber(vm, 1); + u8 value = getWrenNumber(vm, 2) & 0xff; + + if(address >= 0 && address < sizeof(tic_ram)) + { + *((u8*)&machine->memory.ram + address) = value; + } +} + +static void wren_peek4(WrenVM* vm) +{ + s32 address = getWrenNumber(vm, 1); + + if(address >= 0 && address < sizeof(tic_ram)*2) + { + wrenSetSlotDouble(vm, 0, tic_tool_peek4((u8*)&getWrenMachine(vm)->memory.ram, address)); + } +} + +static void wren_poke4(WrenVM* vm) +{ + s32 address = getWrenNumber(vm, 1); + u8 value = getWrenNumber(vm, 2); + + if(address >= 0 && address < sizeof(tic_ram)*2) + { + tic_tool_poke4((u8*)&getWrenMachine(vm)->memory.ram, address, value); + } +} + +static void wren_memcpy(WrenVM* vm) +{ + s32 dest = getWrenNumber(vm, 1); + s32 src = getWrenNumber(vm, 2); + s32 size = getWrenNumber(vm, 3); + s32 bound = sizeof(tic_ram) - size; + + if(size >= 0 && size <= sizeof(tic_ram) && dest >= 0 && src >= 0 && dest <= bound && src <= bound) + { + u8* base = (u8*)&getWrenMachine(vm)->memory; + memcpy(base + dest, base + src, size); + } +} + +static void wren_memset(WrenVM* vm) +{ + s32 dest = getWrenNumber(vm, 1); + u8 value = getWrenNumber(vm, 2); + s32 size = getWrenNumber(vm, 3); + s32 bound = sizeof(tic_ram) - size; + + if(size >= 0 && size <= sizeof(tic_ram) && dest >= 0 && dest <= bound) + { + u8* base = (u8*)&getWrenMachine(vm)->memory; + memset(base + dest, value, size); + } +} + +static void wren_pmem(WrenVM* vm) +{ + s32 top = wrenGetSlotCount(vm); + tic_machine* machine = getWrenMachine(vm); + tic_mem* memory = &machine->memory; + + u32 index = getWrenNumber(vm, 1); + + if(index < TIC_PERSISTENT_SIZE) + { + s32 val = memory->persistent.data[index]; + + if(top > 2) + { + memory->persistent.data[index] = getWrenNumber(vm, 2); + } + + wrenSetSlotDouble(vm, 0, val); + } + else wrenError(vm, "invalid persistent memory index\n"); +} + +static void wren_sfx(WrenVM* vm) +{ + s32 top = wrenGetSlotCount(vm); + + tic_mem* memory = (tic_mem*)getWrenMachine(vm); + + s32 index = getWrenNumber(vm, 1); + + if(index < SFX_COUNT) + { + + s32 note = -1; + s32 octave = -1; + s32 duration = -1; + s32 channel = 0; + s32 volume = MAX_VOLUME; + s32 speed = SFX_DEF_SPEED; + + if (index >= 0) + { + tic_sample* effect = memory->ram.sfx.samples.data + index; + + note = effect->note; + octave = effect->octave; + speed = effect->speed; + } + + if(top > 2) + { + if(isNumber(vm, 2)) + { + s32 id = getWrenNumber(vm, 2); + note = id % NOTES; + octave = id / NOTES; + } + else if(isString(vm, 2)) + { + const char* noteStr = wrenGetSlotString(vm, 2); + + if(!tic_tool_parse_note(noteStr, ¬e, &octave)) + { + wrenError(vm, "invalid note, should be like C#4\n"); + return; + } + } + + if(top > 3) + { + duration = getWrenNumber(vm, 3); + + if(top > 4) + { + channel = getWrenNumber(vm, 4); + + if(top > 5) + { + volume = getWrenNumber(vm, 5); + + if(top > 6) + { + speed = getWrenNumber(vm, 6); + } + } + } + } + } + + if (channel >= 0 && channel < TIC_SOUND_CHANNELS) + { + memory->api.sfx_stop(memory, channel); + memory->api.sfx_ex(memory, index, note, octave, duration, channel, volume & 0xf, speed); + } + else wrenError(vm, "unknown channel\n"); + } + else wrenError(vm, "unknown sfx index\n"); +} + +static void wren_music(WrenVM* vm) +{ + s32 top = wrenGetSlotCount(vm); + + tic_mem* memory = (tic_mem*)getWrenMachine(vm); + + s32 track = -1; + s32 frame = -1; + s32 row = -1; + bool loop = true; + + if(top > 1) + { + track = getWrenNumber(vm, 1); + + if(top > 2) + { + frame = getWrenNumber(vm, 2); + + if(top > 3) + { + row = getWrenNumber(vm, 3); + + if(top > 4) + { + loop = wrenGetSlotBool(vm, 4); + } + } + } + } + + memory->api.music(memory, track, frame, row, loop); +} + +static void wren_time(WrenVM* vm) +{ + tic_mem* memory = (tic_mem*)getWrenMachine(vm); + + wrenSetSlotDouble(vm, 0, memory->api.time(memory)); +} + +static void wren_sync(WrenVM* vm) +{ + tic_mem* memory = (tic_mem*)getWrenMachine(vm); + + bool toCart = true; + u32 mask = 0; + s32 bank = 0; + + s32 top = wrenGetSlotCount(vm); + + if(top > 1) + { + mask = getWrenNumber(vm, 1); + + if(top > 2) + { + bank = getWrenNumber(vm, 2); + + if(top > 3) + { + toCart = wrenGetSlotBool(vm, 3); + } + } + } + + if(bank >= 0 && bank < TIC_BANKS) + memory->api.sync(memory, mask, bank, toCart); + else wrenError(vm, "sync() error, invalid bank"); +} + +static void wren_reset(WrenVM* vm) +{ + tic_machine* machine = getWrenMachine(vm); + + machine->state.initialized = false; +} + +static void wren_exit(WrenVM* vm) +{ + tic_machine* machine = getWrenMachine(vm); + + machine->data->exit(machine->data->data); +} + +static const char* const ApiKeywords[] = API_KEYWORDS; + +WrenForeignMethodFn foreignTicMethods(const char* signature){ + + if (strcmp(signature, "static Tic.btn(_)" ) == 0) return wren_btn; + if (strcmp(signature, "static Tic.btnp(_)" ) == 0) return wren_btnp; + if (strcmp(signature, "static Tic.btnp(_,_,_)" ) == 0) return wren_btnp; + if (strcmp(signature, "static Tic.key(_)" ) == 0) return wren_key; + if (strcmp(signature, "static Tic.keyp(_)" ) == 0) return wren_keyp; + if (strcmp(signature, "static Tic.keyp(_,_,_)" ) == 0) return wren_keyp; + if (strcmp(signature, "static Tic.mouse()" ) == 0) return wren_mouse; + + if (strcmp(signature, "static Tic.font(_)" ) == 0) return wren_font; + if (strcmp(signature, "static Tic.font(_,_,_)" ) == 0) return wren_font; + if (strcmp(signature, "static Tic.font(_,_,_,_)" ) == 0) return wren_font; + if (strcmp(signature, "static Tic.font(_,_,_,_,_,_)" ) == 0) return wren_font; + if (strcmp(signature, "static Tic.font(_,_,_,_,_,_,_)" ) == 0) return wren_font; + if (strcmp(signature, "static Tic.font(_,_,_,_,_,_,_,_)" ) == 0) return wren_font; + + if (strcmp(signature, "static Tic.spr(_)" ) == 0) return wren_spr; + if (strcmp(signature, "static Tic.spr(_,_,_)" ) == 0) return wren_spr; + if (strcmp(signature, "static Tic.spr(_,_,_,_)" ) == 0) return wren_spr; + if (strcmp(signature, "static Tic.spr(_,_,_,_,_)" ) == 0) return wren_spr; + if (strcmp(signature, "static Tic.spr(_,_,_,_,_,_)" ) == 0) return wren_spr; + if (strcmp(signature, "static Tic.spr(_,_,_,_,_,_,_)" ) == 0) return wren_spr; + if (strcmp(signature, "static Tic.spr(_,_,_,_,_,_,_,_,_)" ) == 0) return wren_spr; + + if (strcmp(signature, "static Tic.map(_,_)" ) == 0) return wren_map; + if (strcmp(signature, "static Tic.map(_,_,_,_)" ) == 0) return wren_map; + if (strcmp(signature, "static Tic.map(_,_,_,_,_,_)" ) == 0) return wren_map; + if (strcmp(signature, "static Tic.map(_,_,_,_,_,_,_)" ) == 0) return wren_map; + if (strcmp(signature, "static Tic.map(_,_,_,_,_,_,_,_)" ) == 0) return wren_map; + + if (strcmp(signature, "static Tic.mset(_,_)" ) == 0) return wren_mset; + if (strcmp(signature, "static Tic.mset(_,_,_)" ) == 0) return wren_mset; + if (strcmp(signature, "static Tic.mget(_,_)" ) == 0) return wren_mget; + + if (strcmp(signature, "static Tic.textri(_,_,_,_,_,_,_,_,_,_,_,_)" ) == 0) return wren_textri; + if (strcmp(signature, "static Tic.textri(_,_,_,_,_,_,_,_,_,_,_,_,_)" ) == 0) return wren_textri; + if (strcmp(signature, "static Tic.textri(_,_,_,_,_,_,_,_,_,_,_,_,_,_)" ) == 0) return wren_textri; + + if (strcmp(signature, "static Tic.pix(_,_)" ) == 0) return wren_pix; + if (strcmp(signature, "static Tic.pix(_,_,_)" ) == 0) return wren_pix; + if (strcmp(signature, "static Tic.line(_,_,_,_,_)" ) == 0) return wren_line; + if (strcmp(signature, "static Tic.circ(_,_,_,_)" ) == 0) return wren_circ; + if (strcmp(signature, "static Tic.circb(_,_,_,_)" ) == 0) return wren_circb; + if (strcmp(signature, "static Tic.rect(_,_,_,_,_)" ) == 0) return wren_rect; + if (strcmp(signature, "static Tic.rectb(_,_,_,_,_)" ) == 0) return wren_rectb; + if (strcmp(signature, "static Tic.tri(_,_,_,_,_,_,_)" ) == 0) return wren_tri; + + if (strcmp(signature, "static Tic.cls()" ) == 0) return wren_cls; + if (strcmp(signature, "static Tic.cls(_)" ) == 0) return wren_cls; + if (strcmp(signature, "static Tic.clip()" ) == 0) return wren_clip; + if (strcmp(signature, "static Tic.clip(_,_,_,_)" ) == 0) return wren_clip; + + if (strcmp(signature, "static Tic.peek(_)" ) == 0) return wren_peek; + if (strcmp(signature, "static Tic.poke(_,_)" ) == 0) return wren_poke; + if (strcmp(signature, "static Tic.peek4(_)" ) == 0) return wren_peek4; + if (strcmp(signature, "static Tic.poke4(_,_)" ) == 0) return wren_poke4; + if (strcmp(signature, "static Tic.memcpy(_,_,_)" ) == 0) return wren_memcpy; + if (strcmp(signature, "static Tic.memset(_,_,_)" ) == 0) return wren_memset; + if (strcmp(signature, "static Tic.pmem(_,_)" ) == 0) return wren_pmem; + + if (strcmp(signature, "static Tic.sfx(_)" ) == 0) return wren_sfx; + if (strcmp(signature, "static Tic.sfx(_,_)" ) == 0) return wren_sfx; + if (strcmp(signature, "static Tic.sfx(_,_,_)" ) == 0) return wren_sfx; + if (strcmp(signature, "static Tic.sfx(_,_,_,_)" ) == 0) return wren_sfx; + if (strcmp(signature, "static Tic.sfx(_,_,_,_,_)" ) == 0) return wren_sfx; + if (strcmp(signature, "static Tic.sfx(_,_,_,_,_,_)" ) == 0) return wren_sfx; + if (strcmp(signature, "static Tic.music()" ) == 0) return wren_music; + if (strcmp(signature, "static Tic.music(_)" ) == 0) return wren_music; + if (strcmp(signature, "static Tic.music(_,_)" ) == 0) return wren_music; + if (strcmp(signature, "static Tic.music(_,_,_)" ) == 0) return wren_music; + + if (strcmp(signature, "static Tic.time()" ) == 0) return wren_time; + if (strcmp(signature, "static Tic.sync()" ) == 0) return wren_sync; + if (strcmp(signature, "static Tic.sync(_)" ) == 0) return wren_sync; + if (strcmp(signature, "static Tic.sync(_,_)" ) == 0) return wren_sync; + if (strcmp(signature, "static Tic.sync(_,_,_)" ) == 0) return wren_sync; + if (strcmp(signature, "static Tic.reset()" ) == 0) return wren_reset; + if (strcmp(signature, "static Tic.exit()" ) == 0) return wren_exit; + + // internal functions + if (strcmp(signature, "static Tic.map_width__" ) == 0) return wren_map_width; + if (strcmp(signature, "static Tic.map_height__" ) == 0) return wren_map_height; + if (strcmp(signature, "static Tic.spritesize__" ) == 0) return wren_spritesize; + if (strcmp(signature, "static Tic.print__(_,_,_,_,_,_)" ) == 0) return wren_print; + if (strcmp(signature, "static Tic.trace__(_,_)" ) == 0) return wren_trace; + if (strcmp(signature, "static Tic.spr__(_,_,_,_,_,_,_)" ) == 0) return wren_spr_internal; + if (strcmp(signature, "static Tic.mgeti__(_)" ) == 0) return wren_mgeti; + + return NULL; +} + +static WrenForeignMethodFn bindForeignMethod( + WrenVM* vm, const char* module, const char* className, + bool isStatic, const char* signature) +{ + + if (strcmp(module, "main") != 0) return NULL; + + // For convenience, concatenate all of the method qualifiers into a single + // signature string. + char fullName[256]; + fullName[0] = '\0'; + if (isStatic) { + strcat(fullName, "static "); + } + + strcat(fullName, className); + strcat(fullName, "."); + strcat(fullName, signature); + + WrenForeignMethodFn method = NULL; + + method = foreignTicMethods(fullName); + + return method; +} + +static void initAPI(tic_machine* machine) +{ + wrenSetUserData(machine->wren, machine); + + if (wrenInterpret(machine->wren, tic_wren_api) != WREN_RESULT_SUCCESS) + { + machine->data->error(machine->data->data, "can't load Tic wren api"); + } +} + +static void reportError(WrenVM* vm, WrenErrorType type, const char* module, int line, const char* message) +{ + tic_machine* machine = getWrenMachine(vm); + + char buffer[1024]; + + if (module) + { + snprintf(buffer, sizeof buffer, "\"%s\", %d ,\"%s\"",module, line, message); + } else { + snprintf(buffer, sizeof buffer, "%d, \"%s\"",line, message); + } + + machine->data->error(machine->data->data, buffer); +} + +static void writeFn(WrenVM* vm, const char* text) +{ + tic_machine* machine = getWrenMachine(vm); + u8 color = tic_color_blue; + machine->data->trace(machine->data->data, text ? text : "null", color); +} + +static bool initWren(tic_mem* tic, const char* code) +{ + tic_machine* machine = (tic_machine*)tic; + closeWren(tic); + + WrenConfiguration config; + wrenInitConfiguration(&config); + + config.bindForeignMethodFn = bindForeignMethod; + + config.errorFn = reportError; + config.writeFn = writeFn; + + WrenVM* vm = machine->wren = wrenNewVM(&config); + + initAPI(machine); + + if (wrenInterpret(machine->wren, code) != WREN_RESULT_SUCCESS){ + return false; + } + + loaded = true; + + // make handles + wrenEnsureSlots(vm, 1); + wrenGetVariable(vm, "main", "Game", 0); + game_class = wrenGetSlotHandle(vm, 0); // handle from game class + + new_handle = wrenMakeCallHandle(vm, "new()"); + update_handle = wrenMakeCallHandle(vm, "update()"); + scanline_handle = wrenMakeCallHandle(vm, "scanline(_)"); + overlap_handle = wrenMakeCallHandle(vm, "overlap()"); + + // create game class + if (game_class) + { + wrenEnsureSlots(vm, 1); + wrenSetSlotHandle(vm, 0, game_class); + wrenCall(vm, new_handle); + wrenReleaseHandle(machine->wren, game_class); // release game class handle + game_class = NULL; + if (wrenGetSlotCount(vm) == 0) { + machine->data->error(machine->data->data, "Error in game class :("); + return false; + } + game_class = wrenGetSlotHandle(vm, 0); // handle from game object + } else { + machine->data->error(machine->data->data, "'Game class' isn't found :("); + return false; + } + + return true; +} + +static void callWrenTick(tic_mem* tic) +{ + tic_machine* machine = (tic_machine*)tic; + WrenVM* vm = machine->wren; + + if(vm && game_class) + { + wrenEnsureSlots(vm, 1); + wrenSetSlotHandle(vm, 0, game_class); + wrenCall(vm, update_handle); + } +} + +static void callWrenScanline(tic_mem* memory, s32 row, void* data) +{ + tic_machine* machine = (tic_machine*)memory; + WrenVM* vm = machine->wren; + + if(vm && game_class) + { + wrenEnsureSlots(vm, 2); + wrenSetSlotHandle(vm, 0, game_class); + wrenSetSlotDouble(vm, 1, row); + wrenCall(vm, scanline_handle); + } +} + +static void callWrenOverlap(tic_mem* memory, void* data) +{ + tic_machine* machine = (tic_machine*)memory; + WrenVM* vm = machine->wren; + + if (vm && game_class) + { + wrenEnsureSlots(vm, 1); + wrenSetSlotHandle(vm, 0, game_class); + wrenCall(vm, overlap_handle); + } +} + +static const char* const WrenKeywords [] = +{ + "false", "true", "null", "break", "class", "construct", + "else", "for", "foreign", "if", "import", "in", "is", + "return", "static", "super", "var", "while", "this" +}; + +static inline bool isalnum_(char c) {return isalnum(c) || c == '_';} + +static const tic_outline_item* getWrenOutline(const char* code, s32* size) +{ + enum{Size = sizeof(tic_outline_item)}; + + *size = 0; + + static tic_outline_item* items = NULL; + + if(items) + { + free(items); + items = NULL; + } + + const char* ptr = code; + + while(true) + { + static const char FuncString[] = "function "; + + ptr = strstr(ptr, FuncString); + + if(ptr) + { + ptr += sizeof FuncString - 1; + + const char* start = ptr; + const char* end = start; + + while(*ptr) + { + char c = *ptr; + + if(isalnum_(c)); + else if(c == '(') + { + end = ptr; + break; + } + else break; + + ptr++; + } + + if(end > start) + { + items = items ? realloc(items, (*size + 1) * Size) : malloc(Size); + + items[*size].pos = start - code; + items[*size].size = end - start; + + (*size)++; + } + } + else break; + } + + return items; +} + +static const tic_script_config WrenSyntaxConfig = +{ + .init = initWren, + .close = closeWren, + .tick = callWrenTick, + .scanline = callWrenScanline, + .overlap = callWrenOverlap, + + .getOutline = getWrenOutline, + .parse = parseCode, + + .blockCommentStart = "/*", + .blockCommentEnd = "*/", + .blockStringStart = NULL, + .blockStringEnd = NULL, + .singleComment = "//", + + .keywords = WrenKeywords, + .keywordsCount = COUNT_OF(WrenKeywords), + + .api = ApiKeywords, + .apiCount = COUNT_OF(ApiKeywords), +}; + +const tic_script_config* getWrenScriptConfig() +{ + return &WrenSyntaxConfig; +}