Merge branch '#514'

This commit is contained in:
BADIM-PC\Vadim 2018-02-15 17:23:36 +03:00
commit fd3f316b1d
58 changed files with 4118 additions and 3621 deletions

8
.gitignore vendored
View File

@ -101,3 +101,11 @@ build/uwp/wren/x64/
build/uwp/wren/Release/ build/uwp/wren/Release/
build/uwp/wren/ARM/ build/uwp/wren/ARM/
build/uwp/wren/Debug/ build/uwp/wren/Debug/
build/windows/studio/Debug/
build/windows/studio/Debug Pro/
build/windows/studio/Release/
build/windows/studio/Release Pro/
build/uwp/studio/Debug/
build/uwp/studio/Debug Pro/
build/uwp/studio/Release/
build/uwp/studio/Release Pro/

View File

@ -29,10 +29,6 @@ MINGW_LINKER_FLAGS= \
-lmingw32 \ -lmingw32 \
-lSDL2main \ -lSDL2main \
-lSDL2 \ -lSDL2 \
-lz \
-lgif \
-llua \
-lwren \
-lcomdlg32 \ -lcomdlg32 \
-lws2_32 \ -lws2_32 \
-mwindows -mwindows
@ -144,7 +140,8 @@ SOURCES=\
src/dialog.c \ src/dialog.c \
src/menu.c \ src/menu.c \
src/net.c \ src/net.c \
src/surf.c src/surf.c \
src/system.c
SOURCES_EXT= \ SOURCES_EXT= \
src/html.c src/html.c
@ -248,16 +245,24 @@ bin/menu.o: src/menu.c $(TIC80_H) $(TIC_H)
bin/surf.o: src/surf.c $(TIC80_H) $(TIC_H) bin/surf.o: src/surf.c $(TIC80_H) $(TIC_H)
$(CC) $< $(OPT) $(INCLUDES) -c -o $@ $(CC) $< $(OPT) $(INCLUDES) -c -o $@
bin/system.o: src/system.c src/keycodes.c $(TIC80_H) $(TIC_H)
$(CC) $< $(OPT) $(INCLUDES) -c -o $@
SDL_NET = \
bin/SDLnet.o \
bin/SDLnetTCP.o \
bin/SDLnetselect.o \
bin/net.o
FILE_DIALOG = \
bin/file_dialog.o
TIC_O=\ TIC_O=\
bin/studio.o \ bin/studio.o \
bin/console.o \ bin/console.o \
bin/run.o \ bin/run.o \
bin/file_dialog.o \
bin/md5.o \ bin/md5.o \
bin/gif.o \ bin/gif.o \
bin/SDLnet.o \
bin/SDLnetTCP.o \
bin/SDLnetselect.o \
bin/fs.o \ bin/fs.o \
bin/tools.o \ bin/tools.o \
bin/start.o \ bin/start.o \
@ -269,7 +274,6 @@ TIC_O=\
bin/world.o \ bin/world.o \
bin/config.o \ bin/config.o \
bin/code.o \ bin/code.o \
bin/net.o \
bin/dialog.o \ bin/dialog.o \
bin/menu.o \ bin/menu.o \
bin/surf.o bin/surf.o
@ -300,17 +304,23 @@ TIC80_O = bin/tic80.o bin/tic.o bin/tools.o bin/blip_buf.o bin/jsapi.o bin/luaap
TIC80_A = bin/libtic80.a TIC80_A = bin/libtic80.a
TIC80_DLL = bin/tic80.dll TIC80_DLL = bin/tic80.dll
STUDIO_A = bin/libstudio.a
STUDIO_DLL = bin/studio.dll
$(TIC80_DLL): $(TIC80_O) $(TIC80_DLL): $(TIC80_O)
$(CC) $(OPT) -shared $(TIC80_O) -L$(PRE_BUILT)/mingw -llua -lwren -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 $@
$(STUDIO_DLL): $(DEMO_ASSETS) $(TIC80_DLL) $(TIC_O) bin/html.o
$(CC) $(TIC_O) bin/html.o $(TIC80_A) $(OPT) -shared $(INCLUDES) -L$(PRE_BUILT)/mingw -llua -lz -lgif -Wl,--out-implib,$(STUDIO_A) -o $@
emscripten: emscripten:
$(EMS_CC) $(SOURCES) $(TIC80_SRC) $(OPT) $(INCLUDES) $(EMS_OPT) $(EMS_LINKER_FLAGS) -o build/html/tic.js $(EMS_CC) $(SOURCES) $(TIC80_SRC) $(OPT) $(INCLUDES) $(EMS_OPT) $(EMS_LINKER_FLAGS) -o build/html/tic.js
wasm: wasm:
$(EMS_CC) $(SOURCES) $(TIC80_SRC) $(OPT) $(INCLUDES) $(EMS_OPT) -s WASM=1 $(EMS_LINKER_FLAGS) -o build/html/tic.js $(EMS_CC) $(SOURCES) $(TIC80_SRC) $(OPT) $(INCLUDES) $(EMS_OPT) -s WASM=1 $(EMS_LINKER_FLAGS) -o build/html/tic.js
mingw: $(DEMO_ASSETS) $(TIC80_DLL) $(TIC_O) bin/html.o bin/res.o mingw: $(STUDIO_DLL) $(SDL_NET) $(FILE_DIALOG) bin/system.o bin/res.o
$(CC) $(TIC_O) bin/html.o bin/res.o $(TIC80_A) $(OPT) $(INCLUDES) $(MINGW_LINKER_FLAGS) -o $(MINGW_OUTPUT) $(CC) bin/system.o bin/res.o $(STUDIO_A) $(SDL_NET) $(FILE_DIALOG) $(OPT) $(INCLUDES) $(MINGW_LINKER_FLAGS) -o $(MINGW_OUTPUT)
mingw-pro: mingw-pro:
$(eval OPT += $(OPT_PRO)) $(eval OPT += $(OPT_PRO))

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -52,7 +52,8 @@ LOCAL_SRC_FILES := \
$(SRC_PATH)/dialog.c \ $(SRC_PATH)/dialog.c \
$(SRC_PATH)/menu.c \ $(SRC_PATH)/menu.c \
$(SRC_PATH)/surf.c \ $(SRC_PATH)/surf.c \
$(SRC_PATH)/tic80.c $(SRC_PATH)/tic80.c \
$(SRC_PATH)/system.c
LOCAL_SHARED_LIBRARIES := SDL2 lua z gif wren LOCAL_SHARED_LIBRARIES := SDL2 lua z gif wren

View File

@ -0,0 +1,247 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|ARM">
<Configuration>Debug</Configuration>
<Platform>ARM</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|ARM">
<Configuration>Release</Configuration>
<Platform>ARM</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\src\code.c" />
<ClCompile Include="..\..\..\src\config.c" />
<ClCompile Include="..\..\..\src\console.c" />
<ClCompile Include="..\..\..\src\dialog.c" />
<ClCompile Include="..\..\..\src\ext\gif.c" />
<ClCompile Include="..\..\..\src\ext\md5.c" />
<ClCompile Include="..\..\..\src\fs.c" />
<ClCompile Include="..\..\..\src\history.c" />
<ClCompile Include="..\..\..\src\html.c" />
<ClCompile Include="..\..\..\src\map.c" />
<ClCompile Include="..\..\..\src\menu.c" />
<ClCompile Include="..\..\..\src\music.c" />
<ClCompile Include="..\..\..\src\run.c" />
<ClCompile Include="..\..\..\src\sfx.c" />
<ClCompile Include="..\..\..\src\sprite.c" />
<ClCompile Include="..\..\..\src\start.c" />
<ClCompile Include="..\..\..\src\studio.c" />
<ClCompile Include="..\..\..\src\surf.c" />
<ClCompile Include="..\..\..\src\tools.c" />
<ClCompile Include="..\..\..\src\world.c" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\3rd-party\zlib-1.2.8\winrt\zlib-uwp\zlib-uwp.vcxproj">
<Project>{978f53db-f959-4cb4-84a7-463af29949be}</Project>
</ProjectReference>
<ProjectReference Include="..\gif\gif.vcxproj">
<Project>{bc1084df-210a-48d6-a077-761d8c16947b}</Project>
</ProjectReference>
<ProjectReference Include="..\lua\lua.vcxproj">
<Project>{53802f21-41da-4ac1-8b62-0dac2ccb8af8}</Project>
</ProjectReference>
<ProjectReference Include="..\tic80\tic80.vcxproj">
<Project>{9c39acf1-5f52-4a2b-a467-9f2805d6174b}</Project>
</ProjectReference>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{6a22403a-6cf5-49f2-a012-ec04c9496306}</ProjectGuid>
<Keyword>DynamicLibrary</Keyword>
<RootNamespace>studio</RootNamespace>
<DefaultLanguage>en-US</DefaultLanguage>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
<AppContainerApplication>true</AppContainerApplication>
<ApplicationType>Windows Store</ApplicationType>
<WindowsTargetPlatformVersion>10.0.14393.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformMinVersion>10.0.14393.0</WindowsTargetPlatformMinVersion>
<ApplicationTypeRevision>10.0</ApplicationTypeRevision>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<GenerateManifest>false</GenerateManifest>
<IgnoreImportLibrary>false</IgnoreImportLibrary>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<GenerateManifest>false</GenerateManifest>
<IgnoreImportLibrary>false</IgnoreImportLibrary>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">
<GenerateManifest>false</GenerateManifest>
<IgnoreImportLibrary>false</IgnoreImportLibrary>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">
<GenerateManifest>false</GenerateManifest>
<IgnoreImportLibrary>false</IgnoreImportLibrary>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<GenerateManifest>false</GenerateManifest>
<IgnoreImportLibrary>false</IgnoreImportLibrary>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<GenerateManifest>false</GenerateManifest>
<IgnoreImportLibrary>false</IgnoreImportLibrary>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<CompileAsWinRT>false</CompileAsWinRT>
<PreprocessorDefinitions>TIC80_SHARED;_WINDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\include;..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\zlib-1.2.8;$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<SDLCheck>false</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
<GenerateWindowsMetadata>false</GenerateWindowsMetadata>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<CompileAsWinRT>false</CompileAsWinRT>
<PreprocessorDefinitions>TIC80_SHARED;_WINDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\include;..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\zlib-1.2.8;$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<SDLCheck>false</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
<GenerateWindowsMetadata>false</GenerateWindowsMetadata>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|arm'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<CompileAsWinRT>false</CompileAsWinRT>
<PreprocessorDefinitions>TIC80_SHARED;_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE=1;%(ClCompile.PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\include;..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\zlib-1.2.8;$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<SDLCheck>false</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
<GenerateWindowsMetadata>false</GenerateWindowsMetadata>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|arm'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<CompileAsWinRT>false</CompileAsWinRT>
<PreprocessorDefinitions>TIC80_SHARED;_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE=1;%(ClCompile.PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\include;..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\zlib-1.2.8;$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<SDLCheck>false</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
<GenerateWindowsMetadata>false</GenerateWindowsMetadata>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<CompileAsWinRT>false</CompileAsWinRT>
<PreprocessorDefinitions>TIC80_SHARED;_WINDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\include;..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\zlib-1.2.8;$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<SDLCheck>false</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
<GenerateWindowsMetadata>false</GenerateWindowsMetadata>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<CompileAsWinRT>false</CompileAsWinRT>
<PreprocessorDefinitions>TIC80_SHARED;_WINDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\include;..\..\..\include;..\..\..\3rd-party\lua-5.3.1\src;..\..\..\3rd-party\giflib-5.1.4\lib;..\..\..\3rd-party\zlib-1.2.8;$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<SDLCheck>false</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
<GenerateWindowsMetadata>false</GenerateWindowsMetadata>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="src">
<UniqueIdentifier>{fd391d6f-58f5-4aba-a1f1-41bf34081296}</UniqueIdentifier>
</Filter>
<Filter Include="src\ext">
<UniqueIdentifier>{cf22f775-8c8b-4047-a23c-fa216fa3b08f}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\src\code.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\config.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\console.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\dialog.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\fs.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\history.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\html.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\map.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\menu.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\music.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\run.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\sfx.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\sprite.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\start.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\studio.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\surf.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\tools.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\world.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\ext\gif.c">
<Filter>src\ext</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\ext\md5.c">
<Filter>src\ext</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -17,6 +17,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlib-uwp", "..\..\..\3rd-pa
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wren", "..\wren\wren.vcxproj", "{BBB0D01A-B124-416C-BE26-E6993154A555}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wren", "..\wren\wren.vcxproj", "{BBB0D01A-B124-416C-BE26-E6993154A555}"
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "studio", "..\studio\studio.vcxproj", "{6A22403A-6CF5-49F2-A012-EC04C9496306}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM = Debug|ARM Debug|ARM = Debug|ARM
@ -117,6 +119,18 @@ Global
{BBB0D01A-B124-416C-BE26-E6993154A555}.Release|x64.Build.0 = 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.ActiveCfg = Release|Win32
{BBB0D01A-B124-416C-BE26-E6993154A555}.Release|x86.Build.0 = Release|Win32 {BBB0D01A-B124-416C-BE26-E6993154A555}.Release|x86.Build.0 = Release|Win32
{6A22403A-6CF5-49F2-A012-EC04C9496306}.Debug|ARM.ActiveCfg = Debug|ARM
{6A22403A-6CF5-49F2-A012-EC04C9496306}.Debug|ARM.Build.0 = Debug|ARM
{6A22403A-6CF5-49F2-A012-EC04C9496306}.Debug|x64.ActiveCfg = Debug|x64
{6A22403A-6CF5-49F2-A012-EC04C9496306}.Debug|x64.Build.0 = Debug|x64
{6A22403A-6CF5-49F2-A012-EC04C9496306}.Debug|x86.ActiveCfg = Debug|Win32
{6A22403A-6CF5-49F2-A012-EC04C9496306}.Debug|x86.Build.0 = Debug|Win32
{6A22403A-6CF5-49F2-A012-EC04C9496306}.Release|ARM.ActiveCfg = Release|ARM
{6A22403A-6CF5-49F2-A012-EC04C9496306}.Release|ARM.Build.0 = Release|ARM
{6A22403A-6CF5-49F2-A012-EC04C9496306}.Release|x64.ActiveCfg = Release|x64
{6A22403A-6CF5-49F2-A012-EC04C9496306}.Release|x64.Build.0 = Release|x64
{6A22403A-6CF5-49F2-A012-EC04C9496306}.Release|x86.ActiveCfg = Release|Win32
{6A22403A-6CF5-49F2-A012-EC04C9496306}.Release|x86.Build.0 = Release|Win32
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -219,17 +219,8 @@
<ProjectReference Include="..\..\..\3rd-party\SDL2-2.0.7\VisualC-WinRT\UWP_VS2015\SDL-UWP.vcxproj"> <ProjectReference Include="..\..\..\3rd-party\SDL2-2.0.7\VisualC-WinRT\UWP_VS2015\SDL-UWP.vcxproj">
<Project>{89e9b32e-a86a-47c3-a948-d2b1622925ce}</Project> <Project>{89e9b32e-a86a-47c3-a948-d2b1622925ce}</Project>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\..\..\3rd-party\zlib-1.2.8\winrt\zlib-uwp\zlib-uwp.vcxproj"> <ProjectReference Include="..\studio\studio.vcxproj">
<Project>{978f53db-f959-4cb4-84a7-463af29949be}</Project> <Project>{6a22403a-6cf5-49f2-a012-ec04c9496306}</Project>
</ProjectReference>
<ProjectReference Include="..\gif\gif.vcxproj">
<Project>{bc1084df-210a-48d6-a077-761d8c16947b}</Project>
</ProjectReference>
<ProjectReference Include="..\lua\lua.vcxproj">
<Project>{53802f21-41da-4ac1-8b62-0dac2ccb8af8}</Project>
</ProjectReference>
<ProjectReference Include="..\tic80\tic80.vcxproj">
<Project>{9c39acf1-5f52-4a2b-a467-9f2805d6174b}</Project>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -244,10 +235,6 @@
<ClCompile Include="..\..\..\3rd-party\SDL2_net-2.0.1\SDLnet.c" /> <ClCompile Include="..\..\..\3rd-party\SDL2_net-2.0.1\SDLnet.c" />
<ClCompile Include="..\..\..\3rd-party\SDL2_net-2.0.1\SDLnetselect.c" /> <ClCompile Include="..\..\..\3rd-party\SDL2_net-2.0.1\SDLnetselect.c" />
<ClCompile Include="..\..\..\3rd-party\SDL2_net-2.0.1\SDLnetTCP.c" /> <ClCompile Include="..\..\..\3rd-party\SDL2_net-2.0.1\SDLnetTCP.c" />
<ClCompile Include="..\..\..\src\code.c" />
<ClCompile Include="..\..\..\src\config.c" />
<ClCompile Include="..\..\..\src\console.c" />
<ClCompile Include="..\..\..\src\dialog.c" />
<ClCompile Include="..\..\..\src\ext\file_dialog.cpp"> <ClCompile Include="..\..\..\src\ext\file_dialog.cpp">
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT> <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT> <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
@ -256,23 +243,9 @@
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT> <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT> <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\..\src\ext\gif.c" />
<ClCompile Include="..\..\..\src\ext\md5.c" />
<ClCompile Include="..\..\..\src\fs.c" />
<ClCompile Include="..\..\..\src\history.c" />
<ClCompile Include="..\..\..\src\html.c" />
<ClCompile Include="..\..\..\src\map.c" />
<ClCompile Include="..\..\..\src\menu.c" />
<ClCompile Include="..\..\..\src\music.c" />
<ClCompile Include="..\..\..\src\net.c" /> <ClCompile Include="..\..\..\src\net.c" />
<ClCompile Include="..\..\..\src\run.c" /> <ClCompile Include="..\..\..\src\system.c" />
<ClCompile Include="..\..\..\src\sfx.c" />
<ClCompile Include="..\..\..\src\sprite.c" />
<ClCompile Include="..\..\..\src\start.c" />
<ClCompile Include="..\..\..\src\studio.c" />
<ClCompile Include="..\..\..\src\surf.c" />
<ClCompile Include="..\..\..\src\tools.c" /> <ClCompile Include="..\..\..\src\tools.c" />
<ClCompile Include="..\..\..\src\world.c" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="Package.StoreAssociation.xml" /> <None Include="Package.StoreAssociation.xml" />

View File

@ -47,72 +47,12 @@
<None Include="tic_StoreKey.pfx" /> <None Include="tic_StoreKey.pfx" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\..\..\src\console.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\fs.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\map.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\music.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\run.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\sfx.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\sprite.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\start.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\studio.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\ext\file_dialog.cpp"> <ClCompile Include="..\..\..\src\ext\file_dialog.cpp">
<Filter>src\ext</Filter> <Filter>src\ext</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\..\src\history.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\world.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\html.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\code.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\config.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\ext\gif.c">
<Filter>src\ext</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\ext\md5.c">
<Filter>src\ext</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\net.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\tools.c"> <ClCompile Include="..\..\..\src\tools.c">
<Filter>src</Filter> <Filter>src</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\..\src\dialog.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\menu.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\surf.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\3rd-party\SDL2-2.0.7\src\main\winrt\SDL_winrt_main_NonXAML.cpp" /> <ClCompile Include="..\..\..\3rd-party\SDL2-2.0.7\src\main\winrt\SDL_winrt_main_NonXAML.cpp" />
<ClCompile Include="..\..\..\3rd-party\SDL2_net-2.0.1\SDLnetTCP.c"> <ClCompile Include="..\..\..\3rd-party\SDL2_net-2.0.1\SDLnetTCP.c">
<Filter>src\ext\net</Filter> <Filter>src\ext\net</Filter>
@ -123,6 +63,12 @@
<ClCompile Include="..\..\..\3rd-party\SDL2_net-2.0.1\SDLnetselect.c"> <ClCompile Include="..\..\..\3rd-party\SDL2_net-2.0.1\SDLnetselect.c">
<Filter>src\ext\net</Filter> <Filter>src\ext\net</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\..\src\system.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\net.c">
<Filter>src</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ResourceCompile Include="..\..\..\3rd-party\SDL2-2.0.7\src\main\winrt\SDL2-WinRTResources.rc" /> <ResourceCompile Include="..\..\..\3rd-party\SDL2-2.0.7\src\main\winrt\SDL2-WinRTResources.rc" />

View File

@ -0,0 +1,325 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug Pro|Win32">
<Configuration>Debug Pro</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug Pro|x64">
<Configuration>Debug Pro</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release Pro|Win32">
<Configuration>Release Pro</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release Pro|x64">
<Configuration>Release Pro</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{6181F6A6-AA1B-4CD2-B306-E242CFDE9B20}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>studio</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140_xp</PlatformToolset>
<CharacterSet>NotSet</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug Pro|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140_xp</PlatformToolset>
<CharacterSet>NotSet</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140_xp</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>NotSet</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Pro|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140_xp</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>NotSet</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140_xp</PlatformToolset>
<CharacterSet>NotSet</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug Pro|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140_xp</PlatformToolset>
<CharacterSet>NotSet</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140_xp</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>NotSet</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Pro|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140_xp</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>NotSet</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug Pro|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release Pro|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug Pro|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release Pro|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug Pro|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug Pro|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Pro|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Pro|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;STUDIO_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\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\wren-0.1.0\src\include</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug Pro|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;STUDIO_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\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\wren-0.1.0\src\include</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;_WINDOWS;_USRDLL;STUDIO_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\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\wren-0.1.0\src\include</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug Pro|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;_WINDOWS;_USRDLL;STUDIO_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\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\wren-0.1.0\src\include</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;STUDIO_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\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\wren-0.1.0\src\include</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release Pro|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;STUDIO_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\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\wren-0.1.0\src\include</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>NDEBUG;_WINDOWS;_USRDLL;STUDIO_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\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\wren-0.1.0\src\include</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release Pro|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>NDEBUG;_WINDOWS;_USRDLL;STUDIO_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\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\wren-0.1.0\src\include</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\..\src\code.c" />
<ClCompile Include="..\..\..\src\config.c" />
<ClCompile Include="..\..\..\src\console.c" />
<ClCompile Include="..\..\..\src\dialog.c" />
<ClCompile Include="..\..\..\src\ext\gif.c" />
<ClCompile Include="..\..\..\src\ext\md5.c" />
<ClCompile Include="..\..\..\src\fs.c" />
<ClCompile Include="..\..\..\src\history.c" />
<ClCompile Include="..\..\..\src\html.c" />
<ClCompile Include="..\..\..\src\map.c" />
<ClCompile Include="..\..\..\src\menu.c" />
<ClCompile Include="..\..\..\src\music.c" />
<ClCompile Include="..\..\..\src\run.c" />
<ClCompile Include="..\..\..\src\sfx.c" />
<ClCompile Include="..\..\..\src\sprite.c" />
<ClCompile Include="..\..\..\src\start.c" />
<ClCompile Include="..\..\..\src\studio.c" />
<ClCompile Include="..\..\..\src\surf.c" />
<ClCompile Include="..\..\..\src\tools.c" />
<ClCompile Include="..\..\..\src\world.c" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\gif\gif.vcxproj">
<Project>{6ea9d998-7557-4aed-abfc-142f9960c9b6}</Project>
</ProjectReference>
<ProjectReference Include="..\lua\lua.vcxproj">
<Project>{57d2471b-3138-495e-af18-6e290d098ffc}</Project>
</ProjectReference>
<ProjectReference Include="..\tic80\tic80.vcxproj">
<Project>{c4d8bc10-ebf6-42bb-9b5d-6712fb428a50}</Project>
</ProjectReference>
<ProjectReference Include="..\zlib\zlib.vcxproj">
<Project>{1dfbdfa2-f204-42ff-b99e-250e4b2eba04}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="src">
<UniqueIdentifier>{6c183603-0dc2-4093-91e5-1aba3b2b5d08}</UniqueIdentifier>
</Filter>
<Filter Include="src\ext">
<UniqueIdentifier>{1410c434-08eb-4b70-a278-14955c0ecb28}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\src\code.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\config.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\console.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\dialog.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\fs.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\history.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\html.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\map.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\menu.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\music.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\run.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\sfx.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\sprite.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\start.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\studio.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\surf.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\tools.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\world.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\ext\md5.c">
<Filter>src\ext</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\ext\gif.c">
<Filter>src\ext</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -1,7 +1,7 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15 # Visual Studio 14
VisualStudioVersion = 15.0.27130.2024 VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tic", "tic.vcxproj", "{B6ECC66E-26FA-42C2-8F6C-E4338424F38A}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tic", "tic.vcxproj", "{B6ECC66E-26FA-42C2-8F6C-E4338424F38A}"
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
@ -27,6 +27,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SDL2main", "..\..\..\3rd-pa
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wren_lib", "..\wren\wren_lib.vcxproj", "{D7CC5189-C399-AC94-ECB2-9A3CD8DEE122}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wren_lib", "..\wren\wren_lib.vcxproj", "{D7CC5189-C399-AC94-ECB2-9A3CD8DEE122}"
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "studio", "..\studio\studio.vcxproj", "{6181F6A6-AA1B-4CD2-B306-E242CFDE9B20}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug Pro|x64 = Debug Pro|x64 Debug Pro|x64 = Debug Pro|x64
@ -183,6 +185,22 @@ Global
{D7CC5189-C399-AC94-ECB2-9A3CD8DEE122}.Release|x64.Build.0 = 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.ActiveCfg = Release|Win32
{D7CC5189-C399-AC94-ECB2-9A3CD8DEE122}.Release|x86.Build.0 = Release|Win32 {D7CC5189-C399-AC94-ECB2-9A3CD8DEE122}.Release|x86.Build.0 = Release|Win32
{6181F6A6-AA1B-4CD2-B306-E242CFDE9B20}.Debug Pro|x64.ActiveCfg = Debug Pro|x64
{6181F6A6-AA1B-4CD2-B306-E242CFDE9B20}.Debug Pro|x64.Build.0 = Debug Pro|x64
{6181F6A6-AA1B-4CD2-B306-E242CFDE9B20}.Debug Pro|x86.ActiveCfg = Debug Pro|Win32
{6181F6A6-AA1B-4CD2-B306-E242CFDE9B20}.Debug Pro|x86.Build.0 = Debug Pro|Win32
{6181F6A6-AA1B-4CD2-B306-E242CFDE9B20}.Debug|x64.ActiveCfg = Debug|x64
{6181F6A6-AA1B-4CD2-B306-E242CFDE9B20}.Debug|x64.Build.0 = Debug|x64
{6181F6A6-AA1B-4CD2-B306-E242CFDE9B20}.Debug|x86.ActiveCfg = Debug|Win32
{6181F6A6-AA1B-4CD2-B306-E242CFDE9B20}.Debug|x86.Build.0 = Debug|Win32
{6181F6A6-AA1B-4CD2-B306-E242CFDE9B20}.Release Pro|x64.ActiveCfg = Release Pro|x64
{6181F6A6-AA1B-4CD2-B306-E242CFDE9B20}.Release Pro|x64.Build.0 = Release Pro|x64
{6181F6A6-AA1B-4CD2-B306-E242CFDE9B20}.Release Pro|x86.ActiveCfg = Release Pro|Win32
{6181F6A6-AA1B-4CD2-B306-E242CFDE9B20}.Release Pro|x86.Build.0 = Release Pro|Win32
{6181F6A6-AA1B-4CD2-B306-E242CFDE9B20}.Release|x64.ActiveCfg = Release|x64
{6181F6A6-AA1B-4CD2-B306-E242CFDE9B20}.Release|x64.Build.0 = Release|x64
{6181F6A6-AA1B-4CD2-B306-E242CFDE9B20}.Release|x86.ActiveCfg = Release|Win32
{6181F6A6-AA1B-4CD2-B306-E242CFDE9B20}.Release|x86.Build.0 = Release|Win32
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -41,45 +41,18 @@
<ProjectReference Include="..\..\..\3rd-party\SDL2-2.0.7\VisualC\SDL\SDL.vcxproj"> <ProjectReference Include="..\..\..\3rd-party\SDL2-2.0.7\VisualC\SDL\SDL.vcxproj">
<Project>{81ce8daf-ebb2-4761-8e45-b71abcca8c68}</Project> <Project>{81ce8daf-ebb2-4761-8e45-b71abcca8c68}</Project>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\gif\gif.vcxproj"> <ProjectReference Include="..\studio\studio.vcxproj">
<Project>{6ea9d998-7557-4aed-abfc-142f9960c9b6}</Project> <Project>{6181f6a6-aa1b-4cd2-b306-e242cfde9b20}</Project>
</ProjectReference>
<ProjectReference Include="..\lua\lua.vcxproj">
<Project>{57d2471b-3138-495e-af18-6e290d098ffc}</Project>
</ProjectReference>
<ProjectReference Include="..\tic80\tic80.vcxproj">
<Project>{c4d8bc10-ebf6-42bb-9b5d-6712fb428a50}</Project>
</ProjectReference>
<ProjectReference Include="..\zlib\zlib.vcxproj">
<Project>{1dfbdfa2-f204-42ff-b99e-250e4b2eba04}</Project>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\..\..\3rd-party\SDL2_net-2.0.1\SDLnet.c" /> <ClCompile Include="..\..\..\3rd-party\SDL2_net-2.0.1\SDLnet.c" />
<ClCompile Include="..\..\..\3rd-party\SDL2_net-2.0.1\SDLnetselect.c" /> <ClCompile Include="..\..\..\3rd-party\SDL2_net-2.0.1\SDLnetselect.c" />
<ClCompile Include="..\..\..\3rd-party\SDL2_net-2.0.1\SDLnetTCP.c" /> <ClCompile Include="..\..\..\3rd-party\SDL2_net-2.0.1\SDLnetTCP.c" />
<ClCompile Include="..\..\..\src\code.c" />
<ClCompile Include="..\..\..\src\config.c" />
<ClCompile Include="..\..\..\src\console.c" />
<ClCompile Include="..\..\..\src\dialog.c" />
<ClCompile Include="..\..\..\src\ext\file_dialog.c" /> <ClCompile Include="..\..\..\src\ext\file_dialog.c" />
<ClCompile Include="..\..\..\src\ext\gif.c" />
<ClCompile Include="..\..\..\src\ext\md5.c" />
<ClCompile Include="..\..\..\src\fs.c" />
<ClCompile Include="..\..\..\src\history.c" />
<ClCompile Include="..\..\..\src\html.c" />
<ClCompile Include="..\..\..\src\map.c" />
<ClCompile Include="..\..\..\src\menu.c" />
<ClCompile Include="..\..\..\src\music.c" />
<ClCompile Include="..\..\..\src\net.c" /> <ClCompile Include="..\..\..\src\net.c" />
<ClCompile Include="..\..\..\src\run.c" /> <ClCompile Include="..\..\..\src\system.c" />
<ClCompile Include="..\..\..\src\sfx.c" />
<ClCompile Include="..\..\..\src\sprite.c" />
<ClCompile Include="..\..\..\src\start.c" />
<ClCompile Include="..\..\..\src\studio.c" />
<ClCompile Include="..\..\..\src\surf.c" />
<ClCompile Include="..\..\..\src\tools.c" /> <ClCompile Include="..\..\..\src\tools.c" />
<ClCompile Include="..\..\..\src\world.c" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Image Include="icon.ico" /> <Image Include="icon.ico" />

View File

@ -15,72 +15,6 @@
</Filter> </Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\..\..\src\console.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\fs.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\history.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\map.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\music.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\run.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\sfx.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\sprite.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\start.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\studio.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\world.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\ext\file_dialog.c">
<Filter>src\ext</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\ext\md5.c">
<Filter>src\ext</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\html.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\code.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\config.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\ext\gif.c">
<Filter>src\ext</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\net.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\tools.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\dialog.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\menu.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\surf.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\3rd-party\SDL2_net-2.0.1\SDLnet.c"> <ClCompile Include="..\..\..\3rd-party\SDL2_net-2.0.1\SDLnet.c">
<Filter>src\ext\net</Filter> <Filter>src\ext\net</Filter>
</ClCompile> </ClCompile>
@ -90,6 +24,18 @@
<ClCompile Include="..\..\..\3rd-party\SDL2_net-2.0.1\SDLnetTCP.c"> <ClCompile Include="..\..\..\3rd-party\SDL2_net-2.0.1\SDLnetTCP.c">
<Filter>src\ext\net</Filter> <Filter>src\ext\net</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\..\src\net.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\ext\file_dialog.c">
<Filter>src\ext</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\system.c">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\tools.c">
<Filter>src</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Image Include="icon.ico"> <Image Include="icon.ico">

Binary file not shown.

View File

@ -34,7 +34,7 @@ extern "C" {
#define TIC80_FULLWIDTH_BITS 8 #define TIC80_FULLWIDTH_BITS 8
#define TIC80_FULLWIDTH (1 << TIC80_FULLWIDTH_BITS) #define TIC80_FULLWIDTH (1 << TIC80_FULLWIDTH_BITS)
#define TIC80_FULLHEIGHT (TIC80_FULLWIDTH*9/16) #define TIC80_FULLHEIGHT (TIC80_FULLWIDTH*9/16)
#define TIC_KEY_BUFFER 4 #define TIC80_KEY_BUFFER 4
typedef struct typedef struct
{ {
@ -98,7 +98,10 @@ typedef struct
u16 middle:1; u16 middle:1;
u16 right:1; u16 right:1;
u16 scroll:13; s16 scrollx:6;
s16 scrolly:6;
u16 temp:1;
}; };
u16 btns; u16 btns;
@ -109,7 +112,7 @@ typedef u8 tic_key;
typedef union typedef union
{ {
tic_key keys[TIC_KEY_BUFFER]; tic_key keys[TIC80_KEY_BUFFER];
u32 data; u32 data;
} tic80_keyboard; } tic80_keyboard;

View File

@ -22,11 +22,48 @@
#pragma once #pragma once
#if (defined(WIN32) || defined(_WIN32) || defined(__MINGW32__)) #if defined(__APPLE__)
# undef __TIC_WINDOWS__ /* lets us know what version of Mac OS X we're compiling on */
# define __TIC_WINDOWS__ 1 #include "AvailabilityMacros.h"
#include "TargetConditionals.h"
#ifndef TARGET_OS_IPHONE
#undef __TIC_MACOSX__
#define __TIC_MACOSX__ 1
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
# error SDL for Mac OS X only supports deploying on 10.6 and above.
#endif /* MAC_OS_X_VERSION_MIN_REQUIRED < 1060 */
#endif /* TARGET_OS_IPHONE */
#endif /* defined(__APPLE__) */
#if defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__)
/* Try to find out if we're compiling for WinRT or non-WinRT */
#if defined(_MSC_VER) && defined(__has_include)
#define HAVE_WINAPIFAMILY_H __has_include(<winapifamily.h>)
/* If _USING_V110_SDK71_ is defined it means we are using the Windows XP toolset. */
#elif defined(_MSC_VER) && (_MSC_VER >= 1700 && !_USING_V110_SDK71_) /* _MSC_VER == 1700 for Visual Studio 2012 */
#define HAVE_WINAPIFAMILY_H 1
#else
#define HAVE_WINAPIFAMILY_H 0
#endif #endif
#if HAVE_WINAPIFAMILY_H
#include <winapifamily.h>
#define WINAPI_FAMILY_WINRT (!WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP))
#else
#define WINAPI_FAMILY_WINRT 0
#endif /* HAVE_WINAPIFAMILY_H */
#if WINAPI_FAMILY_WINRT
#undef __TIC_WINRT__
#define __TIC_WINRT__ 1
#else
#undef __TIC_WINDOWS__
#define __TIC_WINDOWS__ 1
#endif
#endif
#if (defined(linux) || defined(__linux) || defined(__linux__)) #if (defined(linux) || defined(__linux) || defined(__linux__))
# undef __TIC_LINUX__ # undef __TIC_LINUX__
# define __TIC_LINUX__ 1 # define __TIC_LINUX__ 1
@ -34,7 +71,7 @@
#ifndef TIC80_API #ifndef TIC80_API
# if defined(TIC80_SHARED) # if defined(TIC80_SHARED)
# if defined(__TIC_WINDOWS__) # if defined(__TIC_WINDOWS__) || defined(__TIC_WINRT__)
# define TIC80_API __declspec(dllexport) # define TIC80_API __declspec(dllexport)
# elif defined(__TIC_LINUX__) # elif defined(__TIC_LINUX__)
# define TIC80_API __attribute__ ((visibility("default"))) # define TIC80_API __attribute__ ((visibility("default")))

View File

@ -74,8 +74,8 @@ static void drawCode(Code* code, bool withCursor)
u8* colorPointer = code->colorBuffer; u8* colorPointer = code->colorBuffer;
struct { char* start; char* end; } selection = {SDL_min(code->cursor.selection, code->cursor.position), struct { char* start; char* end; } selection = {MIN(code->cursor.selection, code->cursor.position),
SDL_max(code->cursor.selection, code->cursor.position)}; MAX(code->cursor.selection, code->cursor.position)};
struct { s32 x; s32 y; char symbol; } cursor = {-1, -1, 0}; struct { s32 x; s32 y; char symbol; } cursor = {-1, -1, 0};
@ -425,8 +425,8 @@ static bool replaceSelection(Code* code)
if(sel && sel != pos) if(sel && sel != pos)
{ {
char* start = SDL_min(sel, pos); char* start = MIN(sel, pos);
char* end = SDL_max(sel, pos); char* end = MAX(sel, pos);
memmove(start, end, strlen(end) + 1); memmove(start, end, strlen(end) + 1);
@ -525,8 +525,8 @@ static void copyToClipboard(Code* code)
if(sel && sel != pos) if(sel && sel != pos)
{ {
start = SDL_min(sel, pos); start = MIN(sel, pos);
size = SDL_max(sel, pos) - start; size = MAX(sel, pos) - start;
} }
else else
{ {
@ -534,14 +534,14 @@ static void copyToClipboard(Code* code)
size = getNextLine(code) - start; size = getNextLine(code) - start;
} }
char* clipboard = (char*)SDL_malloc(size+1); char* clipboard = (char*)malloc(size+1);
if(clipboard) if(clipboard)
{ {
memcpy(clipboard, start, size); memcpy(clipboard, start, size);
clipboard[size] = '\0'; clipboard[size] = '\0';
SDL_SetClipboardText(clipboard); getSystem()->setClipboardText(clipboard);
SDL_free(clipboard); free(clipboard);
} }
} }
@ -554,9 +554,9 @@ static void cutToClipboard(Code* code)
static void copyFromClipboard(Code* code) static void copyFromClipboard(Code* code)
{ {
if(SDL_HasClipboardText()) if(getSystem()->hasClipboardText())
{ {
char* clipboard = SDL_GetClipboardText(); char* clipboard = getSystem()->getClipboardText();
if(clipboard) if(clipboard)
{ {
@ -590,7 +590,7 @@ static void copyFromClipboard(Code* code)
parseSyntaxColor(code); parseSyntaxColor(code);
} }
SDL_free(clipboard); free(clipboard);
} }
} }
} }
@ -633,8 +633,8 @@ static void doTab(Code* code, bool shift, bool crtl)
bool changed = false; bool changed = false;
if(cursor_selection) { if(cursor_selection) {
start = SDL_min(cursor_selection, cursor_position); start = MIN(cursor_selection, cursor_position);
end = SDL_max(cursor_selection, cursor_position); end = MAX(cursor_selection, cursor_position);
} else { } else {
start = end = cursor_position; start = end = cursor_position;
} }
@ -684,8 +684,8 @@ static void setFindMode(Code* code)
{ {
if(code->cursor.selection) if(code->cursor.selection)
{ {
const char* end = SDL_max(code->cursor.position, code->cursor.selection); const char* end = MAX(code->cursor.position, code->cursor.selection);
const char* start = SDL_min(code->cursor.position, code->cursor.selection); const char* start = MIN(code->cursor.position, code->cursor.selection);
size_t len = end - start; size_t len = end - start;
if(len > 0 && len < sizeof code->popup.text - 1) if(len > 0 && len < sizeof code->popup.text - 1)
@ -709,7 +709,8 @@ static int funcCompare(const void* a, const void* b)
if(item1->pos == NULL) return 1; if(item1->pos == NULL) return 1;
if(item2->pos == NULL) return -1; if(item2->pos == NULL) return -1;
return SDL_strcasecmp(item1->name, item2->name); // return SDL_strcasecmp(item1->name, item2->name);
return strcmp(item1->name, item2->name);
} }
static void normalizeScroll(Code* code) static void normalizeScroll(Code* code)
@ -752,6 +753,18 @@ static void updateOutlineCode(Code* code)
updateEditor(code); updateEditor(code);
} }
static char* ticStrlwr(char *string)
{
char *bufp = string;
while (*bufp)
{
*bufp = tolower((u8)*bufp);
++bufp;
}
return string;
}
static void initOutlineMode(Code* code) static void initOutlineMode(Code* code)
{ {
OutlineItem* out = code->outline.items; OutlineItem* out = code->outline.items;
@ -761,8 +774,9 @@ static void initOutlineMode(Code* code)
char buffer[STUDIO_TEXT_BUFFER_WIDTH] = {0}; char buffer[STUDIO_TEXT_BUFFER_WIDTH] = {0};
char filter[STUDIO_TEXT_BUFFER_WIDTH] = {0}; char filter[STUDIO_TEXT_BUFFER_WIDTH] = {0};
SDL_strlcpy(filter, code->popup.text, sizeof(filter)); strncpy(filter, code->popup.text, sizeof(filter));
SDL_strlwr(filter);
ticStrlwr(filter);
const tic_script_config* config = tic->api.get_script_config(tic); const tic_script_config* config = tic->api.get_script_config(tic);
@ -779,12 +793,13 @@ static void initOutlineMode(Code* code)
{ {
out->pos = code->src + item->pos; out->pos = code->src + item->pos;
memset(out->name, 0, STUDIO_TEXT_BUFFER_WIDTH); memset(out->name, 0, STUDIO_TEXT_BUFFER_WIDTH);
memcpy(out->name, out->pos, SDL_min(item->size, STUDIO_TEXT_BUFFER_WIDTH-1)); memcpy(out->name, out->pos, MIN(item->size, STUDIO_TEXT_BUFFER_WIDTH-1));
if(*filter) if(*filter)
{ {
SDL_strlcpy(buffer, out->name, sizeof(buffer)); strncpy(buffer, out->name, sizeof(buffer));
SDL_strlwr(buffer);
ticStrlwr(buffer);
if(strstr(buffer, filter)) out++; if(strstr(buffer, filter)) out++;
else out->pos = NULL; else out->pos = NULL;
@ -865,20 +880,13 @@ static void commentLine(Code* code)
parseSyntaxColor(code); parseSyntaxColor(code);
} }
static void processKeydown(Code* code, SDL_Keycode keycode) static void processKeyboard(Code* code)
{ {
switch(keycode) tic_mem* tic = code->tic;
{
case SDLK_LCTRL:
case SDLK_RCTRL:
case SDLK_LSHIFT:
case SDLK_RSHIFT:
case SDLK_LALT:
case SDLK_RALT:
return;
}
switch(getClipboardEvent(keycode)) if(tic->ram.input.keyboard.data == 0) return;
switch(getClipboardEvent(0))
{ {
case TIC_CLIPBOARD_CUT: cutToClipboard(code); break; case TIC_CLIPBOARD_CUT: cutToClipboard(code); break;
case TIC_CLIPBOARD_COPY: copyToClipboard(code); break; case TIC_CLIPBOARD_COPY: copyToClipboard(code); break;
@ -886,118 +894,77 @@ static void processKeydown(Code* code, SDL_Keycode keycode)
default: break; default: break;
} }
SDL_Keymod keymod = SDL_GetModState(); bool shift = tic->api.key(tic, tic_key_shift);
bool ctrl = tic->api.key(tic, tic_key_ctrl);
bool alt = tic->api.key(tic, tic_key_alt);
switch(keycode) if(keyWasPressed(tic_key_up)
|| keyWasPressed(tic_key_down)
|| keyWasPressed(tic_key_left)
|| keyWasPressed(tic_key_right)
|| keyWasPressed(tic_key_home)
|| keyWasPressed(tic_key_end)
|| keyWasPressed(tic_key_pageup)
|| keyWasPressed(tic_key_pagedown))
{ {
case SDLK_UP: if(!shift) code->cursor.selection = NULL;
case SDLK_DOWN:
case SDLK_LEFT:
case SDLK_RIGHT:
case SDLK_HOME:
case SDLK_END:
case SDLK_PAGEUP:
case SDLK_PAGEDOWN:
if(!(keymod & KMOD_SHIFT)) code->cursor.selection = NULL;
else if(code->cursor.selection == NULL) code->cursor.selection = code->cursor.position; else if(code->cursor.selection == NULL) code->cursor.selection = code->cursor.position;
} }
if(keymod & TIC_MOD_CTRL) if(ctrl)
{ {
if(keymod & KMOD_CTRL) if(ctrl)
{ {
switch(keycode) if(keyWasPressed(tic_key_left)) leftWord(code);
{ else if(keyWasPressed(tic_key_right)) rightWord(code);
case SDLK_LEFT: leftWord(code); break; else if(keyWasPressed(tic_key_tab)) doTab(code, shift, ctrl);
case SDLK_RIGHT: rightWord(code); break;
case SDLK_TAB: doTab(code, keymod & KMOD_SHIFT, keymod & KMOD_CTRL); break;
}
}
else if(keymod & KMOD_GUI)
{
switch(keycode)
{
case SDLK_LEFT: goHome(code); break;
case SDLK_RIGHT: goEnd(code); break;
}
} }
switch(keycode) if(keyWasPressed(tic_key_a)) selectAll(code);
{ else if(keyWasPressed(tic_key_z)) undo(code);
case SDLK_a: selectAll(code); break; else if(keyWasPressed(tic_key_y)) redo(code);
case SDLK_z: undo(code); break; else if(keyWasPressed(tic_key_f)) setCodeMode(code, TEXT_FIND_MODE);
case SDLK_y: redo(code); break; else if(keyWasPressed(tic_key_g)) setCodeMode(code, TEXT_GOTO_MODE);
case SDLK_f: setCodeMode(code, TEXT_FIND_MODE); break; else if(keyWasPressed(tic_key_o)) setCodeMode(code, TEXT_OUTLINE_MODE);
case SDLK_g: setCodeMode(code, TEXT_GOTO_MODE); break; else if(keyWasPressed(tic_key_slash)) commentLine(code);
case SDLK_o: setCodeMode(code, TEXT_OUTLINE_MODE); break; else if(keyWasPressed(tic_key_home)) goCodeHome(code);
case SDLK_SLASH: commentLine(code); break; else if(keyWasPressed(tic_key_end)) goCodeEnd(code);
case SDLK_HOME: goCodeHome(code); break;
case SDLK_END: goCodeEnd(code); break;
}
} }
else if(keymod & KMOD_ALT) else if(alt)
{ {
switch(keycode) if(keyWasPressed(tic_key_left)) leftWord(code);
{ else if(keyWasPressed(tic_key_right)) rightWord(code);
case SDLK_LEFT: leftWord(code); break;
case SDLK_RIGHT: rightWord(code); break;
}
} }
else else
{ {
switch(keycode) if(keyWasPressed(tic_key_up)) upLine(code);
{ else if(keyWasPressed(tic_key_down)) downLine(code);
case SDLK_UP: upLine(code); break; else if(keyWasPressed(tic_key_left)) leftColumn(code);
case SDLK_DOWN: downLine(code); break; else if(keyWasPressed(tic_key_right)) rightColumn(code);
case SDLK_LEFT: leftColumn(code); break; else if(keyWasPressed(tic_key_home)) goHome(code);
case SDLK_RIGHT: rightColumn(code); break; else if(keyWasPressed(tic_key_end)) goEnd(code);
case SDLK_HOME: goHome(code); break; else if(keyWasPressed(tic_key_pageup)) pageUp(code);
case SDLK_END: goEnd(code); break; else if(keyWasPressed(tic_key_pagedown)) pageDown(code);
case SDLK_PAGEUP: pageUp(code); break; else if(keyWasPressed(tic_key_delete)) deleteChar(code);
case SDLK_PAGEDOWN: pageDown(code); break; else if(keyWasPressed(tic_key_backspace)) backspaceChar(code);
case SDLK_DELETE: deleteChar(code); break; else if(keyWasPressed(tic_key_return)) newLine(code);
case SDLK_BACKSPACE: backspaceChar(code); break; else if(keyWasPressed(tic_key_tab)) doTab(code, shift, ctrl);
case SDLK_RETURN: newLine(code); break;
case SDLK_TAB: doTab(code, keymod & KMOD_SHIFT, keymod & KMOD_CTRL); break;
}
} }
updateEditor(code); updateEditor(code);
} }
static void processGestures(Code* code)
{
SDL_Point point = {0, 0};
if(getGesturePos(&point))
{
if(code->scroll.gesture)
{
code->scroll.x = (code->scroll.start.x - point.x) / STUDIO_TEXT_WIDTH;
code->scroll.y = (code->scroll.start.y - point.y) / STUDIO_TEXT_HEIGHT;
normalizeScroll(code);
}
else
{
code->scroll.start.x = point.x + code->scroll.x * STUDIO_TEXT_WIDTH;
code->scroll.start.y = point.y + code->scroll.y * STUDIO_TEXT_HEIGHT;
code->scroll.gesture = true;
}
}
else code->scroll.gesture = false;
}
static void processMouse(Code* code) static void processMouse(Code* code)
{ {
tic_mem* tic = code->tic;
if(checkMousePos(&code->rect)) if(checkMousePos(&code->rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_IBEAM); setCursor(tic_cursor_ibeam);
if(code->scroll.active) if(code->scroll.active)
{ {
if(checkMouseDown(&code->rect, SDL_BUTTON_RIGHT)) if(checkMouseDown(&code->rect, tic_mouse_right))
{ {
code->scroll.x = (code->scroll.start.x - getMouseX()) / STUDIO_TEXT_WIDTH; code->scroll.x = (code->scroll.start.x - getMouseX()) / STUDIO_TEXT_WIDTH;
code->scroll.y = (code->scroll.start.y - getMouseY()) / STUDIO_TEXT_HEIGHT; code->scroll.y = (code->scroll.start.y - getMouseY()) / STUDIO_TEXT_HEIGHT;
@ -1008,7 +975,7 @@ static void processMouse(Code* code)
} }
else else
{ {
if(checkMouseDown(&code->rect, SDL_BUTTON_LEFT)) if(checkMouseDown(&code->rect, tic_mouse_left))
{ {
s32 mx = getMouseX(); s32 mx = getMouseX();
s32 my = getMouseY(); s32 my = getMouseY();
@ -1019,7 +986,7 @@ static void processMouse(Code* code)
char* position = code->cursor.position; char* position = code->cursor.position;
setCursorPosition(code, x + code->scroll.x, y + code->scroll.y); setCursorPosition(code, x + code->scroll.x, y + code->scroll.y);
if(SDL_GetModState() & KMOD_SHIFT) if(tic->api.key(tic, tic_key_shift))
{ {
code->cursor.selection = code->cursor.position; code->cursor.selection = code->cursor.position;
code->cursor.position = position; code->cursor.position = position;
@ -1038,7 +1005,7 @@ static void processMouse(Code* code)
code->cursor.mouseDownPosition = NULL; code->cursor.mouseDownPosition = NULL;
} }
if(checkMouseDown(&code->rect, SDL_BUTTON_RIGHT)) if(checkMouseDown(&code->rect, tic_mouse_right))
{ {
code->scroll.active = true; code->scroll.active = true;
@ -1052,42 +1019,35 @@ static void processMouse(Code* code)
static void textEditTick(Code* code) static void textEditTick(Code* code)
{ {
SDL_Event* event = NULL; tic_mem* tic = code->tic;
while ((event = pollEvent()))
// process scroll
{ {
switch(event->type) tic80_input* input = &code->tic->ram.input;
if(input->mouse.scrolly)
{ {
case SDL_MOUSEWHEEL: enum{Scroll = 3};
{ s32 delta = input->mouse.scrolly > 0 ? -Scroll : Scroll;
enum{Scroll = 3}; code->scroll.y += delta;
s32 delta = event->wheel.y > 0 ? -Scroll : Scroll;
code->scroll.y += delta; normalizeScroll(code);
}
normalizeScroll(code); }
}
break; processKeyboard(code);
case SDL_KEYDOWN:
processKeydown(code, event->key.keysym.sym); if(!tic->api.key(tic, tic_key_ctrl) && !tic->api.key(tic, tic_key_alt))
break; {
case SDL_TEXTINPUT: char sym = getKeyboardText();
#if defined(__LINUX__) if(sym)
if(!(SDL_GetModState() & KMOD_LALT)) {
#endif inputSymbol(code, sym);
updateEditor(code);
if(strlen(event->text.text) == 1)
{
inputSymbol(code, *event->text.text);
updateEditor(code);
}
break;
} }
} }
processGestures(code);
processMouse(code); processMouse(code);
code->tic->api.clear(code->tic, getConfig()->theme.code.bg); code->tic->api.clear(code->tic, getConfig()->theme.code.bg);
@ -1146,52 +1106,39 @@ static char* downStrStr(const char* start, const char* from, const char* substr)
static void textFindTick(Code* code) static void textFindTick(Code* code)
{ {
SDL_Event* event = NULL; if(keyWasPressed(tic_key_return)) setCodeMode(code, TEXT_EDIT_MODE);
while ((event = pollEvent())) else if(keyWasPressed(tic_key_up)
|| keyWasPressed(tic_key_down)
|| keyWasPressed(tic_key_left)
|| keyWasPressed(tic_key_right))
{ {
switch(event->type) if(*code->popup.text)
{ {
case SDL_KEYDOWN: bool reverse = keyWasPressed(tic_key_up) || keyWasPressed(tic_key_left);
switch(event->key.keysym.sym) char* (*func)(const char*, const char*, const char*) = reverse ? upStrStr : downStrStr;
{ char* from = reverse ? MIN(code->cursor.position, code->cursor.selection) : MAX(code->cursor.position, code->cursor.selection);
case SDLK_RETURN: char* pos = func(code->src, from, code->popup.text);
setCodeMode(code, TEXT_EDIT_MODE); updateFindCode(code, pos);
break; }
case SDLK_UP: }
case SDLK_LEFT: else if(keyWasPressed(tic_key_backspace))
case SDLK_DOWN: {
case SDLK_RIGHT: if(*code->popup.text)
if(*code->popup.text) {
{ code->popup.text[strlen(code->popup.text)-1] = '\0';
SDL_Keycode keycode = event->key.keysym.sym; updateFindCode(code, strstr(code->src, code->popup.text));
bool reverse = keycode == SDLK_UP || keycode == SDLK_LEFT; }
char* (*func)(const char*, const char*, const char*) = reverse ? upStrStr : downStrStr; }
char* from = reverse ? SDL_min(code->cursor.position, code->cursor.selection) : SDL_max(code->cursor.position, code->cursor.selection);
char* pos = func(code->src, from, code->popup.text); char sym = getKeyboardText();
updateFindCode(code, pos);
} if(sym)
break; {
case SDLK_BACKSPACE: if(strlen(code->popup.text) + 1 < sizeof code->popup.text)
if(*code->popup.text) {
{ char str[] = {sym , 0};
code->popup.text[strlen(code->popup.text)-1] = '\0'; strcat(code->popup.text, str);
updateFindCode(code, strstr(code->src, code->popup.text)); updateFindCode(code, strstr(code->src, code->popup.text));
}
break;
default: break;
}
break;
case SDL_TEXTINPUT:
if(strlen(event->text.text) == 1)
{
if(strlen(code->popup.text) + 1 < sizeof code->popup.text)
{
strcat(code->popup.text, event->text.text);
updateFindCode(code, strstr(code->src, code->popup.text));
}
}
break;
default: break;
} }
} }
@ -1223,51 +1170,41 @@ static void updateGotoCode(Code* code)
static void textGoToTick(Code* code) static void textGoToTick(Code* code)
{ {
SDL_Event* event = NULL; tic_mem* tic = code->tic;
while ((event = pollEvent()))
if(keyWasPressed(tic_key_return))
{ {
switch(event->type) if(*code->popup.text)
updateGotoCode(code);
setCodeMode(code, TEXT_EDIT_MODE);
}
else if(keyWasPressed(tic_key_backspace))
{
if(*code->popup.text)
{ {
case SDL_KEYDOWN: code->popup.text[strlen(code->popup.text)-1] = '\0';
switch(event->key.keysym.sym) updateGotoCode(code);
{
case SDLK_RETURN:
if(*code->popup.text)
updateGotoCode(code);
setCodeMode(code, TEXT_EDIT_MODE);
break;
case SDLK_BACKSPACE:
if(*code->popup.text)
{
code->popup.text[strlen(code->popup.text)-1] = '\0';
updateGotoCode(code);
}
break;
default: break;
}
break;
case SDL_TEXTINPUT:
if(strlen(event->text.text) == 1)
{
char sym = *event->text.text;
if(strlen(code->popup.text)+1 < sizeof code->popup.text && sym >= '0' && sym <= '9')
{
strcat(code->popup.text, event->text.text);
updateGotoCode(code);
}
}
break;
default: break;
} }
} }
code->tic->api.clear(code->tic, getConfig()->theme.code.bg); char sym = getKeyboardText();
if(sym)
{
if(strlen(code->popup.text)+1 < sizeof code->popup.text && sym >= '0' && sym <= '9')
{
char str[] = {sym, 0};
strcat(code->popup.text, str);
updateGotoCode(code);
}
}
tic->api.clear(tic, getConfig()->theme.code.bg);
if(code->jump.line >= 0) if(code->jump.line >= 0)
code->tic->api.rect(code->tic, 0, (code->jump.line - code->scroll.y) * TIC_FONT_HEIGHT + TOOLBAR_SIZE + 1, tic->api.rect(tic, 0, (code->jump.line - code->scroll.y) * (TIC_FONT_HEIGHT+1) + TOOLBAR_SIZE,
TIC80_WIDTH, TIC_FONT_HEIGHT+1, getConfig()->theme.code.select); TIC80_WIDTH, TIC_FONT_HEIGHT+2, getConfig()->theme.code.select);
drawCode(code, false); drawCode(code, false);
drawPopupBar(code, " GOTO:"); drawPopupBar(code, " GOTO:");
@ -1276,7 +1213,7 @@ static void textGoToTick(Code* code)
static void drawOutlineBar(Code* code, s32 x, s32 y) static void drawOutlineBar(Code* code, s32 x, s32 y)
{ {
SDL_Rect rect = {x, y, TIC80_WIDTH - x, TIC80_HEIGHT - y}; tic_rect rect = {x, y, TIC80_WIDTH - x, TIC80_HEIGHT - y};
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
@ -1285,16 +1222,16 @@ static void drawOutlineBar(Code* code, s32 x, s32 y)
if(mx < OUTLINE_SIZE && code->outline.items[mx].pos) if(mx < OUTLINE_SIZE && code->outline.items[mx].pos)
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
if(checkMouseDown(&rect, SDL_BUTTON_LEFT)) if(checkMouseDown(&rect, tic_mouse_left))
{ {
code->outline.index = mx; code->outline.index = mx;
updateOutlineCode(code); updateOutlineCode(code);
} }
if(checkMouseClick(&rect, SDL_BUTTON_LEFT)) if(checkMouseClick(&rect, tic_mouse_left))
setCodeMode(code, TEXT_EDIT_MODE); setCodeMode(code, TEXT_EDIT_MODE);
} }
} }
@ -1321,53 +1258,45 @@ static void drawOutlineBar(Code* code, s32 x, s32 y)
static void textOutlineTick(Code* code) static void textOutlineTick(Code* code)
{ {
SDL_Event* event = NULL; if(keyWasPressed(tic_key_up))
while ((event = pollEvent()))
{ {
switch(event->type) if(code->outline.index > 0)
{ {
case SDL_KEYDOWN: code->outline.index--;
switch(event->key.keysym.sym) updateOutlineCode(code);
{ }
case SDLK_UP: }
if(code->outline.index > 0) else if(keyWasPressed(tic_key_down))
{ {
code->outline.index--; if(code->outline.index < OUTLINE_SIZE - 1 && code->outline.items[code->outline.index + 1].pos)
updateOutlineCode(code); {
} code->outline.index++;
break; updateOutlineCode(code);
case SDLK_DOWN: }
if(code->outline.index < OUTLINE_SIZE - 1 && code->outline.items[code->outline.index + 1].pos) }
{ else if(keyWasPressed(tic_key_return))
code->outline.index++; {
updateOutlineCode(code); updateOutlineCode(code);
} setCodeMode(code, TEXT_EDIT_MODE);
break; }
case SDLK_RETURN: else if(keyWasPressed(tic_key_backspace))
updateOutlineCode(code); {
setCodeMode(code, TEXT_EDIT_MODE); if(*code->popup.text)
break; {
case SDLK_BACKSPACE: code->popup.text[strlen(code->popup.text)-1] = '\0';
if(*code->popup.text) setOutlineMode(code);
{ }
code->popup.text[strlen(code->popup.text)-1] = '\0'; }
setOutlineMode(code);
} char sym = getKeyboardText();
break;
default: break; if(sym)
} {
break; if(strlen(code->popup.text) + 1 < sizeof code->popup.text)
case SDL_TEXTINPUT: {
if(strlen(event->text.text) == 1) char str[] = {sym, 0};
{ strcat(code->popup.text, str);
if(strlen(code->popup.text) + 1 < sizeof code->popup.text) setOutlineMode(code);
{
strcat(code->popup.text, event->text.text);
setOutlineMode(code);
}
}
break;
default: break;
} }
} }
@ -1429,18 +1358,18 @@ static void drawCodeToolbar(Code* code)
for(s32 i = 0; i < Count; i++) for(s32 i = 0; i < Count; i++)
{ {
SDL_Rect rect = {TIC80_WIDTH + (i - Count) * Size, 0, Size, Size}; tic_rect rect = {TIC80_WIDTH + (i - Count) * Size, 0, Size, Size};
bool over = false; bool over = false;
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
showTooltip(Tips[i]); showTooltip(Tips[i]);
over = true; over = true;
if(checkMouseClick(&rect, SDL_BUTTON_LEFT)) if(checkMouseClick(&rect, tic_mouse_left))
{ {
if (i == TEXT_RUN_CODE) if (i == TEXT_RUN_CODE)
{ {
@ -1471,8 +1400,6 @@ static void tick(Code* code)
if(code->cursor.delay) if(code->cursor.delay)
code->cursor.delay--; code->cursor.delay--;
code->cursor.tick++;
switch(code->mode) switch(code->mode)
{ {
case TEXT_RUN_CODE: runProject(); break; case TEXT_RUN_CODE: runProject(); break;
@ -1516,7 +1443,7 @@ static void onStudioEvent(Code* code, StudioEvent event)
void initCode(Code* code, tic_mem* tic, tic_code* src) void initCode(Code* code, tic_mem* tic, tic_code* src)
{ {
if(code->outline.items == NULL) if(code->outline.items == NULL)
code->outline.items = (OutlineItem*)SDL_malloc(OUTLINE_ITEMS_SIZE); code->outline.items = (OutlineItem*)malloc(OUTLINE_ITEMS_SIZE);
if(code->history) history_delete(code->history); if(code->history) history_delete(code->history);
if(code->cursorHistory) history_delete(code->cursorHistory); if(code->cursorHistory) history_delete(code->cursorHistory);
@ -1527,7 +1454,7 @@ void initCode(Code* code, tic_mem* tic, tic_code* src)
.src = src->data, .src = src->data,
.tick = tick, .tick = tick,
.escape = escape, .escape = escape,
.cursor = {{src->data, NULL, 0, 0}, NULL, 0}, .cursor = {{src->data, NULL, 0}, NULL, 0},
.rect = {0, TOOLBAR_SIZE + 1, TIC80_WIDTH, TIC80_HEIGHT - TOOLBAR_SIZE - TIC_FONT_HEIGHT - 1}, .rect = {0, TOOLBAR_SIZE + 1, TIC80_WIDTH, TIC80_HEIGHT - TOOLBAR_SIZE - TIC_FONT_HEIGHT - 1},
.scroll = {0, 0, {0, 0}, false}, .scroll = {0, 0, {0, 0}, false},
.tickCounter = 0, .tickCounter = 0,

View File

@ -39,7 +39,6 @@ struct Code
{ {
char* position; char* position;
char* selection; char* selection;
s32 tick;
s32 column; s32 column;
}; };
@ -47,14 +46,14 @@ struct Code
s32 delay; s32 delay;
} cursor; } cursor;
SDL_Rect rect; tic_rect rect;
struct struct
{ {
s32 x; s32 x;
s32 y; s32 y;
SDL_Point start; tic_point start;
bool active; bool active;
bool gesture; bool gesture;

View File

@ -93,14 +93,36 @@ static void readCursorTheme(Config* config, lua_State* lua)
if(lua_type(lua, -1) == LUA_TTABLE) if(lua_type(lua, -1) == LUA_TTABLE)
{ {
{ {
lua_getfield(lua, -1, "SPRITE"); lua_getfield(lua, -1, "ARROW");
if(lua_isinteger(lua, -1)) if(lua_isinteger(lua, -1))
{ {
config->data.theme.cursor.sprite = (s32)lua_tointeger(lua, -1); config->data.theme.cursor.arrow = (s32)lua_tointeger(lua, -1);
} }
lua_pop(lua, 1); lua_pop(lua, 1);
}
{
lua_getfield(lua, -1, "HAND");
if(lua_isinteger(lua, -1))
{
config->data.theme.cursor.hand = (s32)lua_tointeger(lua, -1);
}
lua_pop(lua, 1);
}
{
lua_getfield(lua, -1, "IBEAM");
if(lua_isinteger(lua, -1))
{
config->data.theme.cursor.ibeam = (s32)lua_tointeger(lua, -1);
}
lua_pop(lua, 1);
} }
{ {
@ -228,7 +250,7 @@ static void update(Config* config, const u8* buffer, size_t size)
static void setDefault(Config* config) static void setDefault(Config* config)
{ {
SDL_memset(&config->data, 0, sizeof(StudioConfig)); memset(&config->data, 0, sizeof(StudioConfig));
{ {
static const u8 DefaultBiosZip[] = static const u8 DefaultBiosZip[] =
@ -243,14 +265,14 @@ static void setDefault(Config* config)
{ {
update(config, embedBios, size); update(config, embedBios, size);
SDL_free(embedBios); free(embedBios);
} }
} }
} }
static void saveConfig(Config* config, bool overwrite) static void saveConfig(Config* config, bool overwrite)
{ {
u8* buffer = SDL_malloc(sizeof(tic_cartridge)); u8* buffer = malloc(sizeof(tic_cartridge));
if(buffer) if(buffer)
{ {
@ -258,7 +280,7 @@ static void saveConfig(Config* config, bool overwrite)
fsSaveRootFile(config->fs, CONFIG_TIC_PATH, buffer, size, overwrite); fsSaveRootFile(config->fs, CONFIG_TIC_PATH, buffer, size, overwrite);
SDL_free(buffer); free(buffer);
} }
} }
@ -270,7 +292,7 @@ static void reset(Config* config)
static void save(Config* config) static void save(Config* config)
{ {
SDL_memcpy(&config->tic->config, &config->tic->cart, sizeof(tic_cartridge)); memcpy(&config->tic->config, &config->tic->cart, sizeof(tic_cartridge));
readConfig(config); readConfig(config);
saveConfig(config, true); saveConfig(config, true);
@ -296,7 +318,7 @@ void initConfig(Config* config, tic_mem* tic, FileSystem* fs)
{ {
update(config, data, size); update(config, data, size);
SDL_free(data); free(data);
} }
else saveConfig(config, false); else saveConfig(config, false);

View File

@ -23,12 +23,21 @@
#include "console.h" #include "console.h"
#include "fs.h" #include "fs.h"
#include "config.h" #include "config.h"
#include "net.h"
#include "ext/gif.h" #include "ext/gif.h"
#include "ext/file_dialog.h" #include "ext/file_dialog.h"
#include <zlib.h> #include <zlib.h>
#include <ctype.h> #include <ctype.h>
#include <string.h>
#include <stddef.h>
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
#if defined(__EMSCRIPTEN__)
#include <emscripten.h>
#endif
#define CONSOLE_CURSOR_COLOR ((tic_color_red)) #define CONSOLE_CURSOR_COLOR ((tic_color_red))
#define CONSOLE_BACK_TEXT_COLOR ((tic_color_dark_gray)) #define CONSOLE_BACK_TEXT_COLOR ((tic_color_dark_gray))
@ -49,7 +58,7 @@ typedef enum
WrenScript, WrenScript,
} ScriptLang; } ScriptLang;
#if defined(__WINDOWS__) || defined(__LINUX__) || defined(__MACOSX__) #if defined(__TIC_WINDOWS__) || defined(__TIC_LINUX__) || defined(__TIC_MACOSX__)
#define CAN_EXPORT 1 #define CAN_EXPORT 1
#endif #endif
@ -67,7 +76,7 @@ typedef struct
#endif #endif
#if defined(__WINDOWS__) #if defined(__TIC_WINDOWS__)
static const char* ExeExt = ".exe"; static const char* ExeExt = ".exe";
#endif #endif
@ -297,7 +306,7 @@ static void onConsoleExitCommand(Console* console, const char* param)
static s32 writeGifData(const tic_mem* tic, u8* dst, const u8* src, s32 width, s32 height) static s32 writeGifData(const tic_mem* tic, u8* dst, const u8* src, s32 width, s32 height)
{ {
s32 size = 0; s32 size = 0;
gif_color* palette = (gif_color*)SDL_malloc(sizeof(gif_color) * TIC_PALETTE_SIZE); gif_color* palette = (gif_color*)malloc(sizeof(gif_color) * TIC_PALETTE_SIZE);
if(palette) if(palette)
{ {
@ -307,7 +316,7 @@ static s32 writeGifData(const tic_mem* tic, u8* dst, const u8* src, s32 width, s
gif_write_data(dst, &size, width, height, src, palette, TIC_PALETTE_BPP); gif_write_data(dst, &size, width, height, src, palette, TIC_PALETTE_BPP);
SDL_free(palette); free(palette);
} }
return size; return size;
@ -351,7 +360,7 @@ static bool onConsoleLoadSectionCommand(Console* console, const char* param)
for(s32 i = 0; i < COUNT_OF(Sections); i++) for(s32 i = 0; i < COUNT_OF(Sections); i++)
{ {
sprintf(buf, "%s %s", CART_EXT, Sections[i]); sprintf(buf, "%s %s", CART_EXT, Sections[i]);
char* pos = SDL_strstr(param, buf); char* pos = strstr(param, buf);
if(pos) if(pos)
{ {
@ -362,7 +371,7 @@ static bool onConsoleLoadSectionCommand(Console* console, const char* param)
if(data) if(data)
{ {
tic_cartridge* cart = (tic_cartridge*)SDL_malloc(sizeof(tic_cartridge)); tic_cartridge* cart = (tic_cartridge*)malloc(sizeof(tic_cartridge));
if(cart) if(cart)
{ {
@ -388,12 +397,12 @@ static bool onConsoleLoadSectionCommand(Console* console, const char* param)
printFront(console, name); printFront(console, name);
printLine(console); printLine(console);
SDL_free(cart); free(cart);
result = true; result = true;
} }
SDL_free(data); free(data);
} }
else printBack(console, "\ncart loading error"); else printBack(console, "\ncart loading error");
@ -520,7 +529,7 @@ static void onConsoleLoadDemoCommandConfirmed(Console* console, const char* para
printFront(console, console->romName); printFront(console, console->romName);
printBack(console, " loaded!\n"); printBack(console, " loaded!\n");
SDL_free(data); free(data);
} }
static void onCartLoaded(Console* console, const char* name) static void onCartLoaded(Console* console, const char* name)
@ -703,7 +712,7 @@ static bool loadTextSection(const char* project, const char* comment, char* dst,
char tagstart[16]; char tagstart[16];
sprintf(tagstart, "\n%s <", comment); sprintf(tagstart, "\n%s <", comment);
const char* ptr = SDL_strstr(project, tagstart); const char* ptr = strstr(project, tagstart);
if(ptr && ptr < end) if(ptr && ptr < end)
end = ptr; end = ptr;
@ -711,7 +720,7 @@ static bool loadTextSection(const char* project, const char* comment, char* dst,
if(end > start) if(end > start)
{ {
SDL_memcpy(dst, start, SDL_min(size, end - start)); memcpy(dst, start, MIN(size, end - start));
done = true; done = true;
} }
@ -730,7 +739,7 @@ static bool loadTextSectionBank(const char* project, const char* comment, const
char tagbuf[64]; char tagbuf[64];
sprintf(tagbuf, "%s <%s>", comment, tag); sprintf(tagbuf, "%s <%s>", comment, tag);
const char* start = SDL_strstr(project, tagbuf); const char* start = strstr(project, tagbuf);
bool done = false; bool done = false;
if(start) if(start)
@ -739,11 +748,11 @@ static bool loadTextSectionBank(const char* project, const char* comment, const
start = getLineEnd(start); start = getLineEnd(start);
sprintf(tagbuf, "\n%s </%s>", comment, tag); sprintf(tagbuf, "\n%s </%s>", comment, tag);
const char* end = SDL_strstr(start, tagbuf); const char* end = strstr(start, tagbuf);
if(end > start) if(end > start)
{ {
SDL_memcpy(dst, start, SDL_min(size, end - start)); memcpy(dst, start, MIN(size, end - start));
done = true; done = true;
} }
@ -757,7 +766,7 @@ static bool loadBinarySection(const char* project, const char* comment, const ch
char tagbuf[64]; char tagbuf[64];
sprintf(tagbuf, "%s <%s>", comment, tag); sprintf(tagbuf, "%s <%s>", comment, tag);
const char* start = SDL_strstr(project, tagbuf); const char* start = strstr(project, tagbuf);
bool done = false; bool done = false;
if(start) if(start)
@ -766,7 +775,7 @@ static bool loadBinarySection(const char* project, const char* comment, const ch
start = getLineEnd(start); start = getLineEnd(start);
sprintf(tagbuf, "\n%s </%s>", comment, tag); sprintf(tagbuf, "\n%s </%s>", comment, tag);
const char* end = SDL_strstr(start, tagbuf); const char* end = strstr(start, tagbuf);
if(end > start) if(end > start)
{ {
@ -779,7 +788,7 @@ static bool loadBinarySection(const char* project, const char* comment, const ch
static char lineStr[] = "999"; static char lineStr[] = "999";
memcpy(lineStr, ptr + sizeof("-- ") - 1, sizeof lineStr - 1); memcpy(lineStr, ptr + sizeof("-- ") - 1, sizeof lineStr - 1);
s32 index = SDL_atoi(lineStr); s32 index = atoi(lineStr);
if(index < count) if(index < count)
{ {
@ -809,13 +818,13 @@ static bool loadProject(Console* console, const char* name, const char* data, s3
{ {
tic_mem* tic = console->tic; tic_mem* tic = console->tic;
char* project = (char*)SDL_malloc(size+1); char* project = (char*)malloc(size+1);
bool done = false; bool done = false;
if(project) if(project)
{ {
SDL_memcpy(project, data, size); memcpy(project, data, size);
project[size] = '\0'; project[size] = '\0';
// remove all the '\r' chars // remove all the '\r' chars
@ -824,12 +833,12 @@ static bool loadProject(Console* console, const char* name, const char* data, s3
for(s = d = project; (*d = *s); d += (*s++ != '\r')); for(s = d = project; (*d = *s); d += (*s++ != '\r'));
} }
tic_cartridge* cart = (tic_cartridge*)SDL_malloc(sizeof(tic_cartridge)); tic_cartridge* cart = (tic_cartridge*)malloc(sizeof(tic_cartridge));
if(cart) if(cart)
{ {
SDL_memset(cart, 0, sizeof(tic_cartridge)); memset(cart, 0, sizeof(tic_cartridge));
SDL_memcpy(&cart->palette, &tic->config.palette.data, sizeof(tic_palette)); memcpy(&cart->palette, &tic->config.palette.data, sizeof(tic_palette));
const char* comment = projectComment(name); const char* comment = projectComment(name);
char tag[16]; char tag[16];
@ -864,12 +873,12 @@ static bool loadProject(Console* console, const char* name, const char* data, s3
if(loadBinarySection(project, comment, "COVER", 1, &cart->cover, -1, true)) if(loadBinarySection(project, comment, "COVER", 1, &cart->cover, -1, true))
done = true; done = true;
SDL_memcpy(dst, cart, sizeof(tic_cartridge)); memcpy(dst, cart, sizeof(tic_cartridge));
SDL_free(cart); free(cart);
} }
SDL_free(project); free(project);
} }
return done; return done;
@ -886,20 +895,20 @@ static void updateProject(Console* console)
if(data) if(data)
{ {
tic_cartridge* cart = SDL_malloc(sizeof(tic_cartridge)); tic_cartridge* cart = malloc(sizeof(tic_cartridge));
if(cart) if(cart)
{ {
if(loadProject(console, console->romName, data, size, cart)) if(loadProject(console, console->romName, data, size, cart))
{ {
SDL_memcpy(&tic->cart, cart, sizeof(tic_cartridge)); memcpy(&tic->cart, cart, sizeof(tic_cartridge));
studioRomLoaded(); studioRomLoaded();
} }
SDL_free(cart); free(cart);
} }
SDL_free(data); free(data);
} }
} }
@ -928,7 +937,7 @@ static void onConsoleLoadCommandConfirmed(Console* console, const char* param)
onCartLoaded(console, name); onCartLoaded(console, name);
SDL_free(data); free(data);
} }
else else
{ {
@ -951,7 +960,7 @@ static void onConsoleLoadCommandConfirmed(Console* console, const char* param)
loadProject(console, name, data, size, &console->tic->cart); loadProject(console, name, data, size, &console->tic->cart);
onCartLoaded(console, name); onCartLoaded(console, name);
SDL_free(data); free(data);
} }
else else
{ {
@ -988,16 +997,16 @@ static void onConfirm(bool yes, void* data)
else commandDone(confirmData->console); else commandDone(confirmData->console);
if(confirmData->param) if(confirmData->param)
SDL_free(confirmData->param); free(confirmData->param);
SDL_free(confirmData); free(confirmData);
} }
static void confirmCommand(Console* console, const char** text, s32 rows, const char* param, ConfirmCallback callback) static void confirmCommand(Console* console, const char** text, s32 rows, const char* param, ConfirmCallback callback)
{ {
CommandConfirmData* data = SDL_malloc(sizeof(CommandConfirmData)); CommandConfirmData* data = malloc(sizeof(CommandConfirmData));
data->console = console; data->console = console;
data->param = param ? SDL_strdup(param) : NULL; data->param = param ? strdup(param) : NULL;
data->callback = callback; data->callback = callback;
showDialog(text, rows, onConfirm, data); showDialog(text, rows, onConfirm, data);
@ -1054,10 +1063,10 @@ static void loadDemo(Console* console, ScriptLang script)
{ {
loadRom(console->tic, data, size, false); loadRom(console->tic, data, size, false);
SDL_free(data); free(data);
} }
SDL_memset(console->romName, 0, sizeof console->romName); memset(console->romName, 0, sizeof console->romName);
studioRomLoaded(); studioRomLoaded();
} }
@ -1217,7 +1226,7 @@ static void installDemoCart(FileSystem* fs, const char* name, const void* cart,
u8* data = NULL; u8* data = NULL;
s32 dataSize = unzip(&data, cart, size); s32 dataSize = unzip(&data, cart, size);
fsSaveFile(fs, name, data, dataSize, true); fsSaveFile(fs, name, data, dataSize, true);
SDL_free(data); free(data);
} }
static void onConsoleInstallDemosCommand(Console* console, const char* param) static void onConsoleInstallDemosCommand(Console* console, const char* param)
@ -1391,7 +1400,7 @@ static void onImportCover(const char* name, const void* buffer, size_t size, voi
if(size <= sizeof console->tic->cart.cover.data) if(size <= sizeof console->tic->cart.cover.data)
{ {
console->tic->cart.cover.size = size; console->tic->cart.cover.size = size;
SDL_memcpy(console->tic->cart.cover.data, buffer, size); memcpy(console->tic->cart.cover.data, buffer, size);
printLine(console); printLine(console);
printBack(console, name); printBack(console, name);
@ -1434,8 +1443,8 @@ static void onImportSprites(const char* name, const void* buffer, size_t size, v
Height = TIC_SPRITESHEET_SIZE*2, Height = TIC_SPRITESHEET_SIZE*2,
}; };
s32 w = SDL_min(Width, image->width); s32 w = MIN(Width, image->width);
s32 h = SDL_min(Height, image->height); s32 h = MIN(Height, image->height);
for (s32 y = 0; y < h; y++) for (s32 y = 0; y < h; y++)
for (s32 x = 0; x < w; x++) for (s32 x = 0; x < w; x++)
@ -1467,8 +1476,8 @@ static void injectMap(Console* console, const void* buffer, s32 size)
{ {
enum {Size = sizeof(tic_map)}; enum {Size = sizeof(tic_map)};
SDL_memset(getBankMap(), 0, Size); memset(getBankMap(), 0, Size);
SDL_memcpy(getBankMap(), buffer, SDL_min(size, Size)); memcpy(getBankMap(), buffer, MIN(size, Size));
} }
static void onImportMap(const char* name, const void* buffer, size_t size, void* data) static void onImportMap(const char* name, const void* buffer, size_t size, void* data)
@ -1538,7 +1547,7 @@ static void exportCover(Console* console)
if(cover->size) if(cover->size)
{ {
void* data = SDL_malloc(cover->size); void* data = malloc(cover->size);
memcpy(data, cover->data, cover->size); memcpy(data, cover->data, cover->size);
fsGetFileData(onCoverExported, "cover.gif", data, cover->size, DEFAULT_CHMOD, console); fsGetFileData(onCoverExported, "cover.gif", data, cover->size, DEFAULT_CHMOD, console);
} }
@ -1558,11 +1567,11 @@ static void exportSprites(Console* console)
}; };
enum{ Size = Width * Height * sizeof(gif_color)}; enum{ Size = Width * Height * sizeof(gif_color)};
u8* buffer = (u8*)SDL_malloc(Size); u8* buffer = (u8*)malloc(Size);
if(buffer) if(buffer)
{ {
u8* data = (u8*)SDL_malloc(Width * Height); u8* data = (u8*)malloc(Width * Height);
if(data) if(data)
{ {
@ -1580,10 +1589,10 @@ static void exportSprites(Console* console)
{ {
printError(console, "\nsprite export error :("); printError(console, "\nsprite export error :(");
commandDone(console); commandDone(console);
SDL_free(buffer); free(buffer);
} }
SDL_free(data); free(data);
} }
} }
} }
@ -1604,11 +1613,11 @@ static void exportMap(Console* console)
{ {
enum{Size = sizeof(tic_map)}; enum{Size = sizeof(tic_map)};
void* buffer = SDL_malloc(Size); void* buffer = malloc(Size);
if(buffer) if(buffer)
{ {
SDL_memcpy(buffer, getBankMap()->data, Size); memcpy(buffer, getBankMap()->data, Size);
fsGetFileData(onMapExported, "world.map", buffer, Size, DEFAULT_CHMOD, console); fsGetFileData(onMapExported, "world.map", buffer, Size, DEFAULT_CHMOD, console);
} }
} }
@ -1639,9 +1648,7 @@ static void onConsoleExportCommand(Console* console, const char* param)
#else #else
#if !defined(__ANDROID__) && !defined(__MACOSX__) && !defined(__LINUX__) static void *ticMemmem(const void* haystack, size_t hlen, const void* needle, size_t nlen)
static void *memmem(const void* haystack, size_t hlen, const void* needle, size_t nlen)
{ {
const u8* p = haystack; const u8* p = haystack;
size_t plen = hlen; size_t plen = hlen;
@ -1662,8 +1669,6 @@ static void *memmem(const void* haystack, size_t hlen, const void* needle, size_
return NULL; return NULL;
} }
#endif
typedef struct typedef struct
{ {
Console* console; Console* console;
@ -1717,18 +1722,18 @@ static void onConsoleExportHtmlCommand(Console* console, const char* name)
u8* EmbedTicJs = NULL; u8* EmbedTicJs = NULL;
u32 EmbedTicJsSize = unzip(&EmbedTicJs, EmbedTicJsZip, EmbedTicJsZipSize); u32 EmbedTicJsSize = unzip(&EmbedTicJs, EmbedTicJsZip, EmbedTicJsZipSize);
u8* ptr = memmem(EmbedIndex, EmbedIndexSize, Placeholder, sizeof(Placeholder)-1); u8* ptr = ticMemmem(EmbedIndex, EmbedIndexSize, Placeholder, sizeof(Placeholder)-1);
if(ptr) if(ptr)
{ {
MemoryBuffer output = {(u8*)SDL_malloc(EmbedTicJsSize * 2), 0}; MemoryBuffer output = {(u8*)malloc(EmbedTicJsSize * 2), 0};
if(output.data) if(output.data)
{ {
writeMemoryData(&output, EmbedIndex, ptr - EmbedIndex); writeMemoryData(&output, EmbedIndex, ptr - EmbedIndex);
writeMemoryString(&output, "<script type='text/javascript'>\n"); writeMemoryString(&output, "<script type='text/javascript'>\n");
u8* buffer = (u8*)SDL_malloc(sizeof(tic_cartridge)); u8* buffer = (u8*)malloc(sizeof(tic_cartridge));
if(buffer) if(buffer)
{ {
@ -1741,10 +1746,10 @@ static void onConsoleExportHtmlCommand(Console* console, const char* name)
// zip buffer // zip buffer
{ {
unsigned long outSize = sizeof(tic_cartridge); unsigned long outSize = sizeof(tic_cartridge);
u8* output = (u8*)SDL_malloc(outSize); u8* output = (u8*)malloc(outSize);
compress2(output, &outSize, buffer, size, Z_BEST_COMPRESSION); compress2(output, &outSize, buffer, size, Z_BEST_COMPRESSION);
SDL_free(buffer); free(buffer);
buffer = output; buffer = output;
size = outSize; size = outSize;
@ -1762,7 +1767,7 @@ static void onConsoleExportHtmlCommand(Console* console, const char* name)
} }
} }
SDL_free(buffer); free(buffer);
writeMemoryString(&output, "];\n"); writeMemoryString(&output, "];\n");
@ -1778,8 +1783,8 @@ static void onConsoleExportHtmlCommand(Console* console, const char* name)
} }
} }
SDL_free(EmbedIndex); free(EmbedIndex);
SDL_free(EmbedTicJs); free(EmbedTicJs);
} }
#if defined(CAN_EXPORT) #if defined(CAN_EXPORT)
@ -1794,7 +1799,7 @@ static void* embedCart(Console* console, s32* size)
if(app) if(app)
{ {
void* cart = SDL_malloc(sizeof(tic_cartridge)); void* cart = malloc(sizeof(tic_cartridge));
if(cart) if(cart)
{ {
@ -1802,7 +1807,7 @@ static void* embedCart(Console* console, s32* size)
{ {
unsigned long zipSize = sizeof(tic_cartridge); unsigned long zipSize = sizeof(tic_cartridge);
u8* zip = (u8*)SDL_malloc(zipSize); u8* zip = (u8*)malloc(zipSize);
if(zip) if(zip)
{ {
@ -1815,29 +1820,29 @@ static void* embedCart(Console* console, s32* size)
.cartSize = zipSize, .cartSize = zipSize,
}; };
SDL_memcpy(header.sig, TicCartSig, SIG_SIZE); memcpy(header.sig, TicCartSig, SIG_SIZE);
s32 finalSize = appSize + sizeof header + header.cartSize; s32 finalSize = appSize + sizeof header + header.cartSize;
data = SDL_malloc(finalSize); data = malloc(finalSize);
if(data) if(data)
{ {
SDL_memcpy(data, app, appSize); memcpy(data, app, appSize);
SDL_memcpy(data + appSize, &header, sizeof header); memcpy(data + appSize, &header, sizeof header);
SDL_memcpy(data + appSize + sizeof header, zip, header.cartSize); memcpy(data + appSize + sizeof header, zip, header.cartSize);
*size = finalSize; *size = finalSize;
} }
} }
SDL_free(zip); free(zip);
} }
} }
SDL_free(cart); free(cart);
} }
SDL_free(app); free(app);
} }
return data; return data;
@ -1870,7 +1875,7 @@ static const char* getExportName(Console* console, bool html)
strcat(name, ".html"); strcat(name, ".html");
else else
{ {
#if defined(__WINDOWS__) #if defined(__TIC_WINDOWS__)
strcat(name, ExeExt); strcat(name, ExeExt);
#endif #endif
} }
@ -1931,7 +1936,7 @@ static CartSaveResult saveCartName(Console* console, const char* name)
if(name && strlen(name)) if(name && strlen(name))
{ {
u8* buffer = (u8*)SDL_malloc(sizeof(tic_cartridge) * 3); u8* buffer = (u8*)malloc(sizeof(tic_cartridge) * 3);
if(buffer) if(buffer)
{ {
@ -1966,7 +1971,7 @@ static CartSaveResult saveCartName(Console* console, const char* name)
} }
} }
SDL_free(buffer); free(buffer);
} }
} }
else if (strlen(console->romName)) else if (strlen(console->romName))
@ -2277,7 +2282,7 @@ static void processConsoleTab(Console* console)
if(strlen(input)) if(strlen(input))
{ {
char* param = SDL_strchr(input, ' '); char* param = strchr(input, ' ');
if(param && strlen(++param)) if(param && strlen(++param))
{ {
@ -2305,7 +2310,7 @@ static void toUpperStr(char* str)
{ {
while(*str) while(*str)
{ {
*str = SDL_toupper(*str); *str = toupper(*str);
str++; str++;
} }
} }
@ -2358,13 +2363,7 @@ static void onConsoleHelpCommand(Console* console, const char* param)
} }
printBack(console, "\npress "); printBack(console, "\npress ");
#if defined(__ANDROID__)
printFront(console, "BACK");
#else
printFront(console, "ESC"); printFront(console, "ESC");
#endif
printBack(console, " to enter UI mode\n"); printBack(console, " to enter UI mode\n");
commandDone(console); commandDone(console);
@ -2375,15 +2374,15 @@ static s32 tic_strcasecmp(const char *str1, const char *str2)
char a = 0; char a = 0;
char b = 0; char b = 0;
while (*str1 && *str2) { while (*str1 && *str2) {
a = SDL_toupper((unsigned char) *str1); a = toupper((unsigned char) *str1);
b = SDL_toupper((unsigned char) *str2); b = toupper((unsigned char) *str2);
if (a != b) if (a != b)
break; break;
++str1; ++str1;
++str2; ++str2;
} }
a = SDL_toupper(*str1); a = toupper(*str1);
b = SDL_toupper(*str2); b = toupper(*str2);
return (int) ((unsigned char) a - (unsigned char) b); return (int) ((unsigned char) a - (unsigned char) b);
} }
@ -2397,7 +2396,7 @@ static void processCommand(Console* console, const char* command)
while(*end == ' ' && end > command) while(*end == ' ' && end > command)
*end-- = '\0'; *end-- = '\0';
char* param = SDL_strchr(command, ' '); char* param = strchr(command, ' ');
if(param) if(param)
*param++ = '\0'; *param++ = '\0';
@ -2458,8 +2457,8 @@ static void onHistoryDown(Console* console)
static void appendHistory(Console* console, const char* value) static void appendHistory(Console* console, const char* value)
{ {
HistoryItem* item = (HistoryItem*)SDL_malloc(sizeof(HistoryItem)); HistoryItem* item = (HistoryItem*)malloc(sizeof(HistoryItem));
item->value = SDL_strdup(value); item->value = strdup(value);
item->next = NULL; item->next = NULL;
item->prev = NULL; item->prev = NULL;
@ -2516,122 +2515,146 @@ static void setScroll(Console* console, s32 val)
} }
} }
static void processGesture(Console* console) typedef struct
{ {
SDL_Point point = {0, 0}; s32 major;
s32 minor;
s32 patch;
} NetVersion;
if(getGesturePos(&point)) static lua_State* netLuaInit(u8* buffer, s32 size)
{
if (buffer && size)
{ {
if(console->scroll.active) lua_State* lua = luaL_newstate();
setScroll(console, (console->scroll.start - point.y) / STUDIO_TEXT_HEIGHT);
else if(lua)
{ {
console->scroll.start = point.y + console->scroll.pos * STUDIO_TEXT_HEIGHT; if(luaL_loadstring(lua, (char*)buffer) == LUA_OK && lua_pcall(lua, 0, LUA_MULTRET, 0) == LUA_OK)
console->scroll.active = true; return lua;
else lua_close(lua);
} }
} }
else console->scroll.active = false;
return NULL;
}
static NetVersion netVersionRequest()
{
NetVersion version =
{
.major = TIC_VERSION_MAJOR,
.minor = TIC_VERSION_MINOR,
.patch = TIC_VERSION_PATCH,
};
s32 size = 0;
void* buffer = getSystem()->getUrlRequest("/api?fn=version", &size);
if(buffer && size)
{
lua_State* lua = netLuaInit(buffer, size);
if(lua)
{
static const char* Fields[] = {"major", "minor", "patch"};
for(s32 i = 0; i < COUNT_OF(Fields); i++)
{
lua_getglobal(lua, Fields[i]);
if(lua_isinteger(lua, -1))
((s32*)&version)[i] = (s32)lua_tointeger(lua, -1);
lua_pop(lua, 1);
}
lua_close(lua);
}
}
return version;
} }
static void checkNewVersion(Console* console) static void checkNewVersion(Console* console)
{ {
Net* net = createNet();
if(net) NetVersion version = netVersionRequest();
if((version.major > TIC_VERSION_MAJOR) ||
(version.major == TIC_VERSION_MAJOR && version.minor > TIC_VERSION_MINOR) ||
(version.major == TIC_VERSION_MAJOR && version.minor == TIC_VERSION_MINOR && version.patch > TIC_VERSION_PATCH))
{ {
NetVersion version = netVersionRequest(net); char msg[FILENAME_MAX] = {0};
SDL_free(net); sprintf(msg, "\n A new version %i.%i.%i is available.\n", version.major, version.minor, version.patch);
consolePrint(console, msg, (tic_color_light_green));
if((version.major > TIC_VERSION_MAJOR) ||
(version.major == TIC_VERSION_MAJOR && version.minor > TIC_VERSION_MINOR) ||
(version.major == TIC_VERSION_MAJOR && version.minor == TIC_VERSION_MINOR && version.patch > TIC_VERSION_PATCH))
{
char msg[FILENAME_MAX] = {0};
sprintf(msg, "\n A new version %i.%i.%i is available.\n", version.major, version.minor, version.patch);
consolePrint(console, msg, (tic_color_light_green));
}
} }
} }
static void tick(Console* console) static void tick(Console* console)
{ {
SDL_Event* event = NULL; tic_mem* tic = console->tic;
while ((event = pollEvent()))
// process scroll
{ {
switch(event->type) tic80_input* input = &console->tic->ram.input;
if(input->mouse.scrolly)
{ {
case SDL_MOUSEWHEEL: enum{Scroll = 3};
{ s32 delta = input->mouse.scrolly > 0 ? -Scroll : Scroll;
enum{Scroll = 3}; setScroll(console, console->scroll.pos + delta);
s32 delta = event->wheel.y > 0 ? -Scroll : Scroll;
setScroll(console, console->scroll.pos + delta);
}
break;
case SDL_KEYDOWN:
{
switch(event->key.keysym.sym)
{
case SDLK_UP:
onHistoryUp(console);
break;
case SDLK_DOWN:
onHistoryDown(console);
break;
case SDLK_RIGHT:
{
console->inputPosition++;
size_t len = strlen(console->inputBuffer);
if(console->inputPosition > len)
console->inputPosition = len;
}
break;
case SDLK_LEFT:
{
if(console->inputPosition > 0)
console->inputPosition--;
}
break;
case SDLK_RETURN: processConsoleCommand(console); break;
case SDLK_BACKSPACE: processConsoleBackspace(console); break;
case SDLK_DELETE: processConsoleDel(console); break;
case SDLK_HOME: processConsoleHome(console); break;
case SDLK_END: processConsoleEnd(console); break;
case SDLK_TAB: processConsoleTab(console); break;
default: break;
}
scrollConsole(console);
console->cursor.delay = CONSOLE_CURSOR_DELAY;
}
break;
case SDL_TEXTINPUT:
{
const char* symbol = event->text.text;
if(strlen(symbol) == 1)
{
char sym = *symbol;
size_t size = strlen(console->inputBuffer);
if(size < sizeof(console->inputBuffer))
{
char* pos = console->inputBuffer + console->inputPosition;
memmove(pos + 1, pos, strlen(pos));
*(console->inputBuffer + console->inputPosition) = sym;
console->inputPosition++;
}
}
console->cursor.delay = CONSOLE_CURSOR_DELAY;
}
break;
} }
} }
processGesture(console); if(tic->ram.input.keyboard.data != 0)
{
if(keyWasPressed(tic_key_up)) onHistoryUp(console);
else if(keyWasPressed(tic_key_down)) onHistoryDown(console);
else if(keyWasPressed(tic_key_left))
{
if(console->inputPosition > 0)
console->inputPosition--;
}
else if(keyWasPressed(tic_key_right))
{
console->inputPosition++;
size_t len = strlen(console->inputBuffer);
if(console->inputPosition > len)
console->inputPosition = len;
}
else if(keyWasPressed(tic_key_return)) processConsoleCommand(console);
else if(keyWasPressed(tic_key_backspace)) processConsoleBackspace(console);
else if(keyWasPressed(tic_key_delete)) processConsoleDel(console);
else if(keyWasPressed(tic_key_home)) processConsoleHome(console);
else if(keyWasPressed(tic_key_end)) processConsoleEnd(console);
else if(keyWasPressed(tic_key_tab)) processConsoleTab(console);
if(anyKeyWasPressed())
{
scrollConsole(console);
console->cursor.delay = CONSOLE_CURSOR_DELAY;
}
char sym = getKeyboardText();
if(sym)
{
size_t size = strlen(console->inputBuffer);
if(size < sizeof(console->inputBuffer))
{
char* pos = console->inputBuffer + console->inputPosition;
memmove(pos + 1, pos, strlen(pos));
*(console->inputBuffer + console->inputPosition) = sym;
console->inputPosition++;
}
console->cursor.delay = CONSOLE_CURSOR_DELAY;
}
}
if(console->tickCounter == 0) if(console->tickCounter == 0)
{ {
@ -2651,7 +2674,7 @@ static void tick(Console* console)
else printBack(console, "\n loading cart..."); else printBack(console, "\n loading cart...");
} }
console->tic->api.clear(console->tic, TIC_COLOR_BG); tic->api.clear(tic, TIC_COLOR_BG);
drawConsoleText(console); drawConsoleText(console);
if(console->embed.yes) if(console->embed.yes)
@ -2661,13 +2684,13 @@ static void tick(Console* console)
if(!console->skipStart) if(!console->skipStart)
console->showGameMenu = true; console->showGameMenu = true;
memcpy(&console->tic->cart, console->embed.file, sizeof(tic_cartridge)); memcpy(&tic->cart, console->embed.file, sizeof(tic_cartridge));
setStudioMode(TIC_RUN_MODE); setStudioMode(TIC_RUN_MODE);
console->embed.yes = false; console->embed.yes = false;
console->skipStart = false; console->skipStart = false;
studioRomLoaded(); studioRomLoaded();
console->tic->api.reset(console->tic); tic->api.reset(tic);
printLine(console); printLine(console);
commandDone(console); commandDone(console);
@ -2724,7 +2747,7 @@ static bool cmdLoadCart(Console* console, const char* name)
done = true; done = true;
} }
SDL_free(data); free(data);
} }
return done; return done;
@ -2747,8 +2770,8 @@ static bool loadFileIntoBuffer(Console* console, char* buffer, const char* fileN
printError(console, messageBuffer); printError(console, messageBuffer);
} }
memcpy(buffer, contents, SDL_min(size, TIC_CODE_SIZE-1)); memcpy(buffer, contents, MIN(size, TIC_CODE_SIZE-1));
SDL_free(contents); free(contents);
return true; return true;
} }
@ -2812,8 +2835,8 @@ static bool cmdInjectSprites(Console* console, const char* param, const char* na
Height = TIC_SPRITESHEET_SIZE*2, Height = TIC_SPRITESHEET_SIZE*2,
}; };
s32 w = SDL_min(Width, image->width); s32 w = MIN(Width, image->width);
s32 h = SDL_min(Height, image->height); s32 h = MIN(Height, image->height);
for (s32 y = 0; y < h; y++) for (s32 y = 0; y < h; y++)
for (s32 x = 0; x < w; x++) for (s32 x = 0; x < w; x++)
@ -2829,7 +2852,7 @@ static bool cmdInjectSprites(Console* console, const char* param, const char* na
gif_close(image); gif_close(image);
} }
SDL_free(sprites); free(sprites);
console->embed.yes = true; console->embed.yes = true;
console->skipStart = true; console->skipStart = true;
@ -2861,7 +2884,7 @@ static bool cmdInjectMap(Console* console, const char* param, const char* name)
done = true; done = true;
} }
SDL_free(map); free(map);
} }
} }
@ -2870,9 +2893,9 @@ static bool cmdInjectMap(Console* console, const char* param, const char* name)
void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config, s32 argc, char **argv) void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config, s32 argc, char **argv)
{ {
if(!console->buffer) console->buffer = SDL_malloc(CONSOLE_BUFFER_SIZE); if(!console->buffer) console->buffer = malloc(CONSOLE_BUFFER_SIZE);
if(!console->colorBuffer) console->colorBuffer = SDL_malloc(CONSOLE_BUFFER_SIZE); if(!console->colorBuffer) console->colorBuffer = malloc(CONSOLE_BUFFER_SIZE);
if(!console->embed.file) console->embed.file = SDL_malloc(sizeof(tic_cartridge)); if(!console->embed.file) console->embed.file = malloc(sizeof(tic_cartridge));
*console = (Console) *console = (Console)
{ {
@ -2931,7 +2954,7 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config,
{ {
strcpy(console->appPath, argv[0]); strcpy(console->appPath, argv[0]);
#if defined(__WINDOWS__) #if defined(__TIC_WINDOWS__)
if(!strstr(console->appPath, ExeExt)) if(!strstr(console->appPath, ExeExt))
strcat(console->appPath, ExeExt); strcat(console->appPath, ExeExt);
#endif #endif
@ -3008,7 +3031,7 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config,
{ {
char buf[256]; char buf[256];
sprintf(buf, "parameter or file not processed: %s\n", argv[i]); sprintf(buf, "parameter or file not processed: %s\n", argv[i]);
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, "Warning", buf, NULL); getSystem()->showMessageBox("Warning", buf);
} }
} }
} }
@ -3040,7 +3063,7 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config,
s32 size = unzip(&data, cartPtr, cartSize); s32 size = unzip(&data, cartPtr, cartSize);
loadCart(tic, console->embed.file, data, size, true); loadCart(tic, console->embed.file, data, size, true);
SDL_free(data); free(data);
EM_ASM_({Module._free($0);}, cartPtr); EM_ASM_({Module._free($0);}, cartPtr);
} }
@ -3061,7 +3084,7 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config,
while(true) while(true)
{ {
const EmbedHeader* header = (const EmbedHeader*)memmem(ptr, size, TicCartSig, SIG_SIZE); const EmbedHeader* header = (const EmbedHeader*)ticMemmem(ptr, size, TicCartSig, SIG_SIZE);
if(header) if(header)
{ {
@ -3075,7 +3098,7 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config,
loadCart(tic, console->embed.file, data, dataSize, true); loadCart(tic, console->embed.file, data, dataSize, true);
console->embed.yes = true; console->embed.yes = true;
SDL_free(data); free(data);
} }
break; break;
@ -3089,7 +3112,7 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config,
else break; else break;
} }
SDL_free(app); free(app);
} }
} }

View File

@ -24,3 +24,5 @@
#define COUNT_OF(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x]))))) #define COUNT_OF(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
#define STATIC_ASSERT(name, condition) typedef char static_assert_dummy_ ## name[(condition) ? 1 : -1] #define STATIC_ASSERT(name, condition) typedef char static_assert_dummy_ ## name[(condition) ? 1 : -1]
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define MAX(a,b) ((a) > (b) ? (a) : (b))

View File

@ -28,22 +28,22 @@ static void drawButton(Dialog* dlg, const char* label, s32 x, s32 y, u8 color, u
enum {BtnWidth = 20, BtnHeight = 9}; enum {BtnWidth = 20, BtnHeight = 9};
SDL_Rect rect = {x, y, BtnWidth, BtnHeight}; tic_rect rect = {x, y, BtnWidth, BtnHeight};
bool down = false; bool down = false;
bool over = false; bool over = false;
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
over = true; over = true;
if(checkMouseDown(&rect, SDL_BUTTON_LEFT)) if(checkMouseDown(&rect, tic_mouse_left))
{ {
down = true; down = true;
dlg->focus = id; dlg->focus = id;
} }
if(checkMouseClick(&rect, SDL_BUTTON_LEFT)) if(checkMouseClick(&rect, tic_mouse_left))
callback(dlg); callback(dlg);
} }
@ -91,27 +91,25 @@ static void onNo(Dialog* dlg)
hideDialog(); hideDialog();
} }
static void processKeydown(Dialog* dlg, SDL_Keysym* keysum) static void processKeyboard(Dialog* dlg)
{ {
SDL_Scancode scancode = keysum->scancode; tic_mem* tic = dlg->tic;
if(tic->ram.input.keyboard.data == 0) return;
switch(scancode) if(keyWasPressed(tic_key_left))
{ {
case SDL_SCANCODE_LEFT:
dlg->focus = (dlg->focus-1) % 2; dlg->focus = (dlg->focus-1) % 2;
playSystemSfx(2); playSystemSfx(2);
break; }
case SDL_SCANCODE_RIGHT: else if(keyWasPressed(tic_key_right) || keyWasPressed(tic_key_tab))
case SDL_SCANCODE_TAB: {
dlg->focus = (dlg->focus+1) % 2; dlg->focus = (dlg->focus+1) % 2;
playSystemSfx(2); playSystemSfx(2);
break; }
case SDL_SCANCODE_RETURN: else if(keyWasPressed(tic_key_return) || keyWasPressed(tic_key_space))
case SDL_SCANCODE_SPACE: {
dlg->focus == 0 ? onYes(dlg) : onNo(dlg); dlg->focus == 0 ? onYes(dlg) : onNo(dlg);
break;
default:
break;
} }
} }
@ -121,18 +119,18 @@ static void drawDialog(Dialog* dlg)
tic_mem* tic = dlg->tic; tic_mem* tic = dlg->tic;
SDL_Rect rect = {(TIC80_WIDTH - Width)/2, (TIC80_HEIGHT - Height)/2, Width, Height}; tic_rect rect = {(TIC80_WIDTH - Width)/2, (TIC80_HEIGHT - Height)/2, Width, Height};
rect.x -= dlg->pos.x; rect.x -= dlg->pos.x;
rect.y -= dlg->pos.y; rect.y -= dlg->pos.y;
SDL_Rect header = {rect.x, rect.y-(TOOLBAR_SIZE-1), rect.w, TOOLBAR_SIZE}; tic_rect header = {rect.x, rect.y-(TOOLBAR_SIZE-1), rect.w, TOOLBAR_SIZE};
if(checkMousePos(&header)) if(checkMousePos(&header))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
if(checkMouseDown(&header, SDL_BUTTON_LEFT)) if(checkMouseDown(&header, tic_mouse_left))
{ {
if(!dlg->drag.active) if(!dlg->drag.active)
{ {
@ -146,13 +144,13 @@ static void drawDialog(Dialog* dlg)
if(dlg->drag.active) if(dlg->drag.active)
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
dlg->pos.x = dlg->drag.start.x - getMouseX(); dlg->pos.x = dlg->drag.start.x - getMouseX();
dlg->pos.y = dlg->drag.start.y - getMouseY(); dlg->pos.y = dlg->drag.start.y - getMouseY();
SDL_Rect rect = {0, 0, TIC80_WIDTH, TIC80_HEIGHT}; tic_rect rect = {0, 0, TIC80_WIDTH, TIC80_HEIGHT};
if(!checkMouseDown(&rect, SDL_BUTTON_LEFT)) if(!checkMouseDown(&rect, tic_mouse_left))
dlg->drag.active = false; dlg->drag.active = false;
} }
@ -191,16 +189,7 @@ static void drawDialog(Dialog* dlg)
static void tick(Dialog* dlg) static void tick(Dialog* dlg)
{ {
SDL_Event* event = NULL; processKeyboard(dlg);
while ((event = pollEvent()))
{
switch(event->type)
{
case SDL_KEYDOWN:
processKeydown(dlg, &event->key.keysym);
break;
}
}
if(!dlg->init) if(!dlg->init)
{ {
@ -209,7 +198,7 @@ static void tick(Dialog* dlg)
dlg->init = true; dlg->init = true;
} }
SDL_memcpy(dlg->tic->ram.vram.screen.data, dlg->bg, sizeof dlg->tic->ram.vram.screen.data); memcpy(dlg->tic->ram.vram.screen.data, dlg->bg, sizeof dlg->tic->ram.vram.screen.data);
drawDialog(dlg); drawDialog(dlg);
} }
@ -245,8 +234,8 @@ void initDialog(Dialog* dlg, tic_mem* tic, const char** text, s32 rows, DialogCa
enum{Size = sizeof tic->ram.vram.screen.data}; enum{Size = sizeof tic->ram.vram.screen.data};
if(!dlg->bg) if(!dlg->bg)
dlg->bg = SDL_malloc(Size); dlg->bg = malloc(Size);
if(dlg->bg) if(dlg->bg)
SDL_memcpy(dlg->bg, tic->ram.vram.screen.data, Size); memcpy(dlg->bg, tic->ram.vram.screen.data, Size);
} }

View File

@ -39,11 +39,11 @@ struct Dialog
u32 focus; u32 focus;
SDL_Point pos; tic_point pos;
struct struct
{ {
SDL_Point start; tic_point start;
bool active; bool active;
} drag; } drag;

View File

@ -115,40 +115,6 @@ void file_dialog_save(file_dialog_save_callback callback, const char* name, cons
callback(false, data); callback(false, data);
} }
#include <shlobj.h>
const char* folder_dialog(void* data)
{
BROWSEINFOW bi = { 0 };
bi.lpszTitle = L"Browse for folder...";
bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
bi.lParam = (LPARAM) NULL;
LPITEMIDLIST pidl = SHBrowseForFolderW ( &bi );
if ( pidl != 0 )
{
wchar_t path[MAX_PATH];
SHGetPathFromIDListW (pidl, path);
LPMALLOC imalloc = NULL;
if ( SUCCEEDED( SHGetMalloc ( &imalloc )) )
{
imalloc->lpVtbl->Free (imalloc, pidl );
imalloc->lpVtbl->Release (imalloc);
}
{
static char result[MAX_PATH];
strcpy(result, StringToUTF8(path));
return result;
}
}
return NULL;
}
#elif defined(__EMSCRIPTEN__) #elif defined(__EMSCRIPTEN__)
#include <emscripten.h> #include <emscripten.h>

View File

@ -34,7 +34,6 @@ typedef void(*file_dialog_save_callback)(bool result, void* data);
void file_dialog_load(file_dialog_load_callback callback, void* data); void file_dialog_load(file_dialog_load_callback callback, void* data);
void file_dialog_save(file_dialog_save_callback callback, const char* name, const u8* buffer, size_t size, void* data, u32 mode); void file_dialog_save(file_dialog_save_callback callback, const char* name, const u8* buffer, size_t size, void* data, u32 mode);
const char* folder_dialog(void* data);
#ifdef __cplusplus #ifdef __cplusplus
} }

318
src/fs.c
View File

@ -22,14 +22,17 @@
#include "studio.h" #include "studio.h"
#include "fs.h" #include "fs.h"
#include "net.h"
#include "ext/file_dialog.h" #include "ext/file_dialog.h"
#include <dirent.h> #include <dirent.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#if defined(__WINRT__) || defined(__WINDOWS__) #include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
#if defined(__TIC_WINRT__) || defined(__TIC_WINDOWS__)
#include <direct.h> #include <direct.h>
#include <windows.h> #include <windows.h>
#else #else
@ -49,8 +52,6 @@ struct FileSystem
{ {
char dir[FILENAME_MAX]; char dir[FILENAME_MAX];
char work[FILENAME_MAX]; char work[FILENAME_MAX];
Net* net;
}; };
static const char* getFilePath(FileSystem* fs, const char* name) static const char* getFilePath(FileSystem* fs, const char* name)
@ -67,7 +68,7 @@ static const char* getFilePath(FileSystem* fs, const char* name)
strcat(path, name); strcat(path, name);
#if defined(__WINDOWS__) #if defined(__TIC_WINDOWS__)
char* ptr = path; char* ptr = path;
while (*ptr) while (*ptr)
{ {
@ -103,10 +104,28 @@ bool fsIsInPublicDir(FileSystem* fs)
return isPublic(fs); return isPublic(fs);
} }
#if defined(__WINDOWS__) || defined(__WINRT__) #if defined(__TIC_WINDOWS__) || defined(__TIC_WINRT__)
#define UTF8ToString(S) (wchar_t *)SDL_iconv_string("UTF-16LE", "UTF-8", (char *)(S), SDL_strlen(S)+1) #define __S(x) L ## x
#define StringToUTF8(S) SDL_iconv_string("UTF-8", "UTF-16LE", (char *)(S), (SDL_wcslen(S)+1)*sizeof(wchar_t)) #define _S(x) __S(x)
static const wchar_t* UTF8ToString(const char* str)
{
static wchar_t wstr[FILENAME_MAX];
mbstowcs(wstr, str, FILENAME_MAX);
return wstr;
}
static char* StringToUTF8(const wchar_t* wstr)
{
static char str[FILENAME_MAX];
wcstombs(str, wstr, FILENAME_MAX);
return str;
}
FILE* _wfopen(const wchar_t *, const wchar_t *); FILE* _wfopen(const wchar_t *, const wchar_t *);
int _wremove(const wchar_t *); int _wremove(const wchar_t *);
@ -123,10 +142,11 @@ int _wremove(const wchar_t *);
#define tic_remove _wremove #define tic_remove _wremove
#define tic_fopen _wfopen #define tic_fopen _wfopen
#define tic_mkdir(name) _wmkdir(name) #define tic_mkdir(name) _wmkdir(name)
#define tic_system _wsystem
#else #else
#define _S(x) (x)
#define UTF8ToString(S) (S) #define UTF8ToString(S) (S)
#define StringToUTF8(S) (S) #define StringToUTF8(S) (S)
@ -142,7 +162,131 @@ int _wremove(const wchar_t *);
#define tic_remove remove #define tic_remove remove
#define tic_fopen fopen #define tic_fopen fopen
#define tic_mkdir(name) mkdir(name, 0700) #define tic_mkdir(name) mkdir(name, 0700)
#define tic_system system
#endif
#if !defined(__EMSCRIPTEN__)
typedef struct
{
ListCallback callback;
void* data;
} NetDirData;
static lua_State* netLuaInit(u8* buffer, s32 size)
{
if (buffer && size)
{
lua_State* lua = luaL_newstate();
if(lua)
{
if(luaL_loadstring(lua, (char*)buffer) == LUA_OK && lua_pcall(lua, 0, LUA_MULTRET, 0) == LUA_OK)
return lua;
else lua_close(lua);
}
}
return NULL;
}
static void onDirResponse(u8* buffer, s32 size, void* data)
{
NetDirData* netDirData = (NetDirData*)data;
lua_State* lua = netLuaInit(buffer, size);
if(lua)
{
{
lua_getglobal(lua, "folders");
if(lua_type(lua, -1) == LUA_TTABLE)
{
s32 count = (s32)lua_rawlen(lua, -1);
for(s32 i = 1; i <= count; i++)
{
lua_geti(lua, -1, i);
{
lua_getfield(lua, -1, "name");
if(lua_isstring(lua, -1))
netDirData->callback(lua_tostring(lua, -1), NULL, 0, netDirData->data, true);
lua_pop(lua, 1);
}
lua_pop(lua, 1);
}
}
lua_pop(lua, 1);
}
{
lua_getglobal(lua, "files");
if(lua_type(lua, -1) == LUA_TTABLE)
{
s32 count = (s32)lua_rawlen(lua, -1);
for(s32 i = 1; i <= count; i++)
{
lua_geti(lua, -1, i);
char hash[FILENAME_MAX] = {0};
char name[FILENAME_MAX] = {0};
{
lua_getfield(lua, -1, "hash");
if(lua_isstring(lua, -1))
strcpy(hash, lua_tostring(lua, -1));
lua_pop(lua, 1);
}
{
lua_getfield(lua, -1, "name");
if(lua_isstring(lua, -1))
strcpy(name, lua_tostring(lua, -1));
lua_pop(lua, 1);
}
{
lua_getfield(lua, -1, "id");
if(lua_isinteger(lua, -1))
netDirData->callback(name, hash, lua_tointeger(lua, -1), netDirData->data, false);
lua_pop(lua, 1);
}
lua_pop(lua, 1);
}
}
lua_pop(lua, 1);
}
lua_close(lua);
}
}
static void netDirRequest(const char* path, ListCallback callback, void* data)
{
char request[FILENAME_MAX] = {'\0'};
sprintf(request, "/api?fn=dir&path=%s", path);
s32 size = 0;
void* buffer = getSystem()->getUrlRequest(request, &size);
NetDirData netDirData = {callback, data};
onDirResponse(buffer, size, &netDirData);
}
#endif #endif
@ -154,7 +298,7 @@ void fsEnumFiles(FileSystem* fs, ListCallback callback, void* data)
if(isPublic(fs)) if(isPublic(fs))
{ {
netDirRequest(fs->net, fs->work + sizeof(TIC_HOST), callback, data); netDirRequest(fs->work + sizeof(TIC_HOST), callback, data);
return; return;
} }
@ -194,7 +338,7 @@ void fsEnumFiles(FileSystem* fs, ListCallback callback, void* data)
bool fsDeleteDir(FileSystem* fs, const char* name) bool fsDeleteDir(FileSystem* fs, const char* name)
{ {
#if defined(__WINRT__) || defined(__WINDOWS__) #if defined(__TIC_WINRT__) || defined(__TIC_WINDOWS__)
const char* path = getFilePath(fs, name); const char* path = getFilePath(fs, name);
bool result = tic_rmdir(UTF8ToString(path)); bool result = tic_rmdir(UTF8ToString(path));
#else #else
@ -236,7 +380,7 @@ static void onAddFile(const char* name, const u8* buffer, s32 size, void* data,
{ {
const char* destname = getFilePath(fs, name); const char* destname = getFilePath(fs, name);
FILE* file = tic_fopen(UTF8ToString(destname), UTF8ToString("rb")); FILE* file = tic_fopen(UTF8ToString(destname), _S("rb"));
if(file) if(file)
{ {
fclose(file); fclose(file);
@ -246,14 +390,14 @@ static void onAddFile(const char* name, const u8* buffer, s32 size, void* data,
else else
{ {
const char* path = getFilePath(fs, name); const char* path = getFilePath(fs, name);
FILE* dest = tic_fopen(UTF8ToString(path), UTF8ToString("wb")); FILE* dest = tic_fopen(UTF8ToString(path), _S("wb"));
if (dest) if (dest)
{ {
fwrite(buffer, 1, size, dest); fwrite(buffer, 1, size, dest);
fclose(dest); fclose(dest);
#if !defined(__WINRT__) && !defined(__WINDOWS__) #if !defined(__TIC_WINRT__) && !defined(__TIC_WINDOWS__)
if(mode) if(mode)
chmod(path, mode); chmod(path, mode);
#endif #endif
@ -271,16 +415,16 @@ static void onAddFile(const char* name, const u8* buffer, s32 size, void* data,
addFileData->callback(name, FS_FILE_NOT_ADDED, addFileData->data); addFileData->callback(name, FS_FILE_NOT_ADDED, addFileData->data);
} }
SDL_free(addFileData); free(addFileData);
} }
void fsAddFile(FileSystem* fs, AddCallback callback, void* data) void fsAddFile(FileSystem* fs, AddCallback callback, void* data)
{ {
AddFileData* addFileData = (AddFileData*)SDL_malloc(sizeof(AddFileData)); AddFileData* addFileData = (AddFileData*)malloc(sizeof(AddFileData));
*addFileData = (AddFileData) { fs, callback, data }; *addFileData = (AddFileData) { fs, callback, data };
file_dialog_load(&onAddFile, addFileData); getSystem()->fileDialogLoad(&onAddFile, addFileData);
} }
typedef struct typedef struct
@ -296,14 +440,14 @@ static void onGetFile(bool result, void* data)
command->callback(result ? FS_FILE_DOWNLOADED : FS_FILE_NOT_DOWNLOADED, command->data); command->callback(result ? FS_FILE_DOWNLOADED : FS_FILE_NOT_DOWNLOADED, command->data);
SDL_free(command->buffer); free(command->buffer);
SDL_free(command); free(command);
} }
static u32 fsGetMode(FileSystem* fs, const char* name) static u32 fsGetMode(FileSystem* fs, const char* name)
{ {
#if defined(__WINRT__) || defined(__WINDOWS__) #if defined(__TIC_WINRT__) || defined(__TIC_WINDOWS__)
return 0; return 0;
#else #else
const char* path = getFilePath(fs, name); const char* path = getFilePath(fs, name);
@ -409,10 +553,10 @@ bool fsIsDir(FileSystem* fs, const char* name)
void fsGetFileData(GetCallback callback, const char* name, void* buffer, size_t size, u32 mode, void* data) void fsGetFileData(GetCallback callback, const char* name, void* buffer, size_t size, u32 mode, void* data)
{ {
GetFileData* command = (GetFileData*)SDL_malloc(sizeof(GetFileData)); GetFileData* command = (GetFileData*)malloc(sizeof(GetFileData));
*command = (GetFileData) {callback, data, buffer}; *command = (GetFileData) {callback, data, buffer};
file_dialog_save(onGetFile, name, buffer, size, command, mode); getSystem()->fileDialogSave(onGetFile, name, buffer, size, command, mode);
} }
typedef struct typedef struct
@ -427,16 +571,16 @@ static void onOpenFileData(const char* name, const u8* buffer, s32 size, void* d
command->callback(name, buffer, size, command->data); command->callback(name, buffer, size, command->data);
SDL_free(command); free(command);
} }
void fsOpenFileData(OpenCallback callback, void* data) void fsOpenFileData(OpenCallback callback, void* data)
{ {
OpenFileData* command = (OpenFileData*)SDL_malloc(sizeof(OpenFileData)); OpenFileData* command = (OpenFileData*)malloc(sizeof(OpenFileData));
*command = (OpenFileData){callback, data}; *command = (OpenFileData){callback, data};
file_dialog_load(onOpenFileData, command); getSystem()->fileDialogLoad(onOpenFileData, command);
} }
void fsGetFile(FileSystem* fs, GetCallback callback, const char* name, void* data) void fsGetFile(FileSystem* fs, GetCallback callback, const char* name, void* data)
@ -446,18 +590,18 @@ void fsGetFile(FileSystem* fs, GetCallback callback, const char* name, void* dat
if(buffer) if(buffer)
{ {
GetFileData* command = (GetFileData*)SDL_malloc(sizeof(GetFileData)); GetFileData* command = (GetFileData*)malloc(sizeof(GetFileData));
*command = (GetFileData) {callback, data, buffer}; *command = (GetFileData) {callback, data, buffer};
s32 mode = fsGetMode(fs, name); s32 mode = fsGetMode(fs, name);
file_dialog_save(onGetFile, name, buffer, size, command, mode); getSystem()->fileDialogSave(onGetFile, name, buffer, size, command, mode);
} }
else callback(FS_FILE_NOT_DOWNLOADED, data); else callback(FS_FILE_NOT_DOWNLOADED, data);
} }
bool fsWriteFile(const char* name, const void* buffer, s32 size) bool fsWriteFile(const char* name, const void* buffer, s32 size)
{ {
FILE* file = tic_fopen(UTF8ToString(name), UTF8ToString("wb")); FILE* file = tic_fopen(UTF8ToString(name), _S("wb"));
if(file) if(file)
{ {
@ -482,14 +626,14 @@ bool fsCopyFile(const char* src, const char* dst)
s32 size = 0; s32 size = 0;
{ {
FILE* file = tic_fopen(UTF8ToString(src), UTF8ToString("rb")); FILE* file = tic_fopen(UTF8ToString(src), _S("rb"));
if(file) if(file)
{ {
fseek(file, 0, SEEK_END); fseek(file, 0, SEEK_END);
size = ftell(file); size = ftell(file);
fseek(file, 0, SEEK_SET); fseek(file, 0, SEEK_SET);
if((buffer = SDL_malloc(size)) && fread(buffer, size, 1, file)) {} if((buffer = malloc(size)) && fread(buffer, size, 1, file)) {}
fclose(file); fclose(file);
} }
@ -497,7 +641,7 @@ bool fsCopyFile(const char* src, const char* dst)
if(buffer) if(buffer)
{ {
FILE* file = tic_fopen(UTF8ToString(dst), UTF8ToString("wb")); FILE* file = tic_fopen(UTF8ToString(dst), _S("wb"));
if(file) if(file)
{ {
@ -507,7 +651,7 @@ bool fsCopyFile(const char* src, const char* dst)
done = true; done = true;
} }
SDL_free(buffer); free(buffer);
} }
return done; return done;
@ -515,7 +659,7 @@ bool fsCopyFile(const char* src, const char* dst)
void* fsReadFile(const char* path, s32* size) void* fsReadFile(const char* path, s32* size)
{ {
FILE* file = tic_fopen(UTF8ToString(path), UTF8ToString("rb")); FILE* file = tic_fopen(UTF8ToString(path), _S("rb"));
void* buffer = NULL; void* buffer = NULL;
if(file) if(file)
@ -525,7 +669,7 @@ void* fsReadFile(const char* path, s32* size)
*size = ftell(file); *size = ftell(file);
fseek(file, 0, SEEK_SET); fseek(file, 0, SEEK_SET);
if((buffer = SDL_malloc(*size)) && fread(buffer, *size, 1, file)) {} if((buffer = malloc(*size)) && fread(buffer, *size, 1, file)) {}
fclose(file); fclose(file);
} }
@ -554,7 +698,7 @@ const char* fsFullname(const char *path)
{ {
char* result = NULL; char* result = NULL;
#if defined(__WINDOWS__) || defined(__WINRT__) #if defined(__TIC_WINDOWS__) || defined(__TIC_WINRT__)
static wchar_t wpath[FILENAME_MAX]; static wchar_t wpath[FILENAME_MAX];
GetFullPathNameW(UTF8ToString(path), sizeof(wpath), wpath, NULL); GetFullPathNameW(UTF8ToString(path), sizeof(wpath), wpath, NULL);
@ -572,7 +716,7 @@ const char* fsBasename(const char *path)
{ {
char* result = NULL; char* result = NULL;
#if defined(__WINDOWS__) || defined(__WINRT__) #if defined(__TIC_WINDOWS__) || defined(__TIC_WINRT__)
#define SEP "\\" #define SEP "\\"
#else #else
#define SEP "/" #define SEP "/"
@ -701,7 +845,7 @@ void* fsLoadFile(FileSystem* fs, const char* name, s32* size)
char path[FILENAME_MAX] = {0}; char path[FILENAME_MAX] = {0};
sprintf(path, "/cart/%s/cart.tic", loadPublicCartData.hash); sprintf(path, "/cart/%s/cart.tic", loadPublicCartData.hash);
void* data = netGetRequest(fs->net, path, size); void* data = getSystem()->getUrlRequest(path, size);
if(data) if(data)
fsSaveRootFile(fs, cachePath, data, *size, false); fsSaveRootFile(fs, cachePath, data, *size, false);
@ -711,7 +855,7 @@ void* fsLoadFile(FileSystem* fs, const char* name, s32* size)
} }
else else
{ {
FILE* file = tic_fopen(UTF8ToString(getFilePath(fs, name)), UTF8ToString("rb")); FILE* file = tic_fopen(UTF8ToString(getFilePath(fs, name)), _S("rb"));
void* ptr = NULL; void* ptr = NULL;
if(file) if(file)
@ -720,7 +864,7 @@ void* fsLoadFile(FileSystem* fs, const char* name, s32* size)
*size = ftell(file); *size = ftell(file);
fseek(file, 0, SEEK_SET); fseek(file, 0, SEEK_SET);
u8* buffer = SDL_malloc(*size); u8* buffer = malloc(*size);
if(buffer && fread(buffer, *size, 1, file)) ptr = buffer; if(buffer && fread(buffer, *size, 1, file)) ptr = buffer;
@ -751,38 +895,6 @@ void fsMakeDir(FileSystem* fs, const char* name)
makeDir(getFilePath(fs, name)); makeDir(getFilePath(fs, name));
} }
#if defined(__WINDOWS__) || defined(__LINUX__) || defined(__MACOSX__)
s32 fsOpenSystemPath(FileSystem* fs, const char* path)
{
char command[FILENAME_MAX];
#if defined(__WINDOWS__)
sprintf(command, "explorer \"%s\"", path);
#elif defined(__LINUX__)
sprintf(command, "xdg-open \"%s\"", path);
#elif defined(__MACOSX__)
sprintf(command, "open \"%s\"", path);
#endif
return tic_system(UTF8ToString(command));
}
#else
s32 fsOpenSystemPath(FileSystem* fs, const char* path)
{
return 0;
}
#endif
void fsOpenWorkingFolder(FileSystem* fs) void fsOpenWorkingFolder(FileSystem* fs)
{ {
const char* path = getFilePath(fs, ""); const char* path = getFilePath(fs, "");
@ -790,67 +902,15 @@ void fsOpenWorkingFolder(FileSystem* fs)
if(isPublic(fs)) if(isPublic(fs))
path = fs->dir; path = fs->dir;
fsOpenSystemPath(fs, path); getSystem()->openSystemPath(path);
} }
void createFileSystem(const char* path, void(*callback)(FileSystem*)) FileSystem* createFileSystem(const char* path)
{ {
FileSystem* fs = (FileSystem*)SDL_malloc(sizeof(FileSystem)); FileSystem* fs = (FileSystem*)malloc(sizeof(FileSystem));
memset(fs, 0, sizeof(FileSystem)); memset(fs, 0, sizeof(FileSystem));
fs->net = createNet(); strcpy(fs->dir, path);
if(path) return fs;
{
strcpy(fs->dir, path);
callback(fs);
}
else
{
#if defined(__EMSCRIPTEN__)
strcpy(fs->dir, "/" TIC_PACKAGE "/" TIC_NAME "/");
#elif defined(__ANDROID__)
strcpy(fs->dir, SDL_AndroidGetExternalStoragePath());
const char AppFolder[] = "/" TIC_NAME "/";
strcat(fs->dir, AppFolder);
mkdir(fs->dir, 0700);
#else
char* path = SDL_GetPrefPath(TIC_PACKAGE, TIC_NAME);
strcpy(fs->dir, path);
SDL_free(path);
#endif
#if defined(__EMSCRIPTEN__)
EM_ASM_
(
{
var dir = "";
Module.Pointer_stringify($0).split("/").forEach(function(val)
{
if(val.length)
{
dir += "/" + val;
FS.mkdir(dir);
}
});
FS.mount(IDBFS, {}, dir);
FS.syncfs(true, function(error)
{
if(error) console.log(error);
else Runtime.dynCall('vi', $1, [$2]);
});
}, fs->dir, callback, fs
);
#else
callback(fs);
#endif
}
} }

View File

@ -47,7 +47,7 @@ typedef void(*OpenCallback)(const char* name, const void* buffer, size_t size, v
typedef struct FileSystem FileSystem; typedef struct FileSystem FileSystem;
void createFileSystem(const char* path, void(*callback)(FileSystem*)); FileSystem* createFileSystem(const char* path);
void fsEnumFiles(FileSystem* fs, ListCallback callback, void* data); void fsEnumFiles(FileSystem* fs, ListCallback callback, void* data);
void fsAddFile(FileSystem* fs, AddCallback callback, void* data); void fsAddFile(FileSystem* fs, AddCallback callback, void* data);
@ -72,7 +72,6 @@ bool fsCopyFile(const char* src, const char* dst);
void fsGetFileData(GetCallback callback, const char* name, void* buffer, size_t size, u32 mode, void* data); void fsGetFileData(GetCallback callback, const char* name, void* buffer, size_t size, u32 mode, void* data);
void fsOpenFileData(OpenCallback callback, void* data); void fsOpenFileData(OpenCallback callback, void* data);
void fsOpenWorkingFolder(FileSystem* fs); void fsOpenWorkingFolder(FileSystem* fs);
s32 fsOpenSystemPath(FileSystem* fs, const char* path);
bool fsIsDir(FileSystem* fs, const char* dir); bool fsIsDir(FileSystem* fs, const char* dir);
bool fsIsInPublicDir(FileSystem* fs); bool fsIsInPublicDir(FileSystem* fs);
bool fsChangeDir(FileSystem* fs, const char* dir); bool fsChangeDir(FileSystem* fs, const char* dir);

View File

@ -248,13 +248,9 @@ static s32 duk_key(duk_context* duk)
{ {
tic_key key = duk_to_int(duk, 0); tic_key key = duk_to_int(duk, 0);
if(key < tic_keys_count) if(key < tic_key_escape)
duk_push_boolean(duk, tic->api.key(tic, key)); duk_push_boolean(duk, tic->api.key(tic, key));
else else return duk_error(duk, DUK_ERR_ERROR, "unknown keyboard code\n");
{
duk_error(duk, DUK_ERR_ERROR, "unknown keyboard code\n");
return 0;
}
} }
return 1; return 1;
@ -273,10 +269,9 @@ static s32 duk_keyp(duk_context* duk)
{ {
tic_key key = duk_to_int(duk, 0); tic_key key = duk_to_int(duk, 0);
if(key >= tic_keys_count) if(key >= tic_key_escape)
{ {
duk_error(duk, DUK_ERR_ERROR, "unknown keyboard code\n"); return duk_error(duk, DUK_ERR_ERROR, "unknown keyboard code\n");
return 0;
} }
else else
{ {
@ -325,8 +320,7 @@ static duk_ret_t duk_sfx(duk_context* duk)
if(!tic_tool_parse_note(noteStr, &note, &octave)) if(!tic_tool_parse_note(noteStr, &note, &octave))
{ {
duk_error(duk, DUK_ERR_ERROR, "invalid note, should be like C#4\n"); return duk_error(duk, DUK_ERR_ERROR, "invalid note, should be like C#4\n");
return 0;
} }
} }
else else
@ -340,8 +334,7 @@ static duk_ret_t duk_sfx(duk_context* duk)
} }
else else
{ {
duk_error(duk, DUK_ERR_ERROR, "unknown sfx index\n"); return duk_error(duk, DUK_ERR_ERROR, "unknown sfx index\n");
return 0;
} }
s32 duration = duk_is_null_or_undefined(duk, 2) ? -1 : duk_to_int(duk, 2); s32 duration = duk_is_null_or_undefined(duk, 2) ? -1 : duk_to_int(duk, 2);
@ -356,7 +349,7 @@ static duk_ret_t duk_sfx(duk_context* duk)
memory->api.sfx_stop(memory, channel); memory->api.sfx_stop(memory, channel);
memory->api.sfx_ex(memory, index, note, octave, duration, channel, volume & 0xf, speed); memory->api.sfx_ex(memory, index, note, octave, duration, channel, volume & 0xf, speed);
} }
else duk_error(duk, DUK_ERR_ERROR, "unknown channel\n"); else return duk_error(duk, DUK_ERR_ERROR, "unknown channel\n");
return 0; return 0;
} }
@ -571,13 +564,16 @@ static duk_ret_t duk_pmem(duk_context* duk)
s32 val = memory->persistent.data[index]; s32 val = memory->persistent.data[index];
if(!duk_is_null_or_undefined(duk, 1)) if(!duk_is_null_or_undefined(duk, 1))
{
memory->persistent.data[index] = duk_to_int(duk, 1); memory->persistent.data[index] = duk_to_int(duk, 1);
machine->data->syncPMEM = true;
}
duk_push_int(duk, val); duk_push_int(duk, val);
return 1; return 1;
} }
else duk_error(duk, DUK_ERR_ERROR, "invalid persistent memory index\n"); else return duk_error(duk, DUK_ERR_ERROR, "invalid persistent memory index\n");
return 0; return 0;
} }
@ -762,7 +758,7 @@ static duk_ret_t duk_sync(duk_context* duk)
if(bank >= 0 && bank < TIC_BANKS) if(bank >= 0 && bank < TIC_BANKS)
memory->api.sync(memory, mask, bank, toCart); memory->api.sync(memory, mask, bank, toCart);
else else
duk_error(duk, DUK_ERR_ERROR, "sync() error, invalid bank"); return duk_error(duk, DUK_ERR_ERROR, "sync() error, invalid bank");
return 0; return 0;
} }

View File

@ -39,7 +39,7 @@
[SDL_SCANCODE_9] = tic_key_9, [SDL_SCANCODE_9] = tic_key_9,
[SDL_SCANCODE_0] = tic_key_0, [SDL_SCANCODE_0] = tic_key_0,
[SDL_SCANCODE_RETURN] = tic_key_return, [SDL_SCANCODE_RETURN] = tic_key_return,
[SDL_SCANCODE_ESCAPE] = tic_key_unknown, [SDL_SCANCODE_ESCAPE] = tic_key_escape,
[SDL_SCANCODE_BACKSPACE] = tic_key_backspace, [SDL_SCANCODE_BACKSPACE] = tic_key_backspace,
[SDL_SCANCODE_TAB] = tic_key_tab, [SDL_SCANCODE_TAB] = tic_key_tab,
[SDL_SCANCODE_SPACE] = tic_key_space, [SDL_SCANCODE_SPACE] = tic_key_space,
@ -56,18 +56,18 @@
[SDL_SCANCODE_PERIOD] = tic_key_period, [SDL_SCANCODE_PERIOD] = tic_key_period,
[SDL_SCANCODE_SLASH] = tic_key_slash, [SDL_SCANCODE_SLASH] = tic_key_slash,
[SDL_SCANCODE_CAPSLOCK] = tic_key_capslock, [SDL_SCANCODE_CAPSLOCK] = tic_key_capslock,
[SDL_SCANCODE_F1] = tic_key_unknown, [SDL_SCANCODE_F1] = tic_key_f1,
[SDL_SCANCODE_F2] = tic_key_unknown, [SDL_SCANCODE_F2] = tic_key_f2,
[SDL_SCANCODE_F3] = tic_key_unknown, [SDL_SCANCODE_F3] = tic_key_f3,
[SDL_SCANCODE_F4] = tic_key_unknown, [SDL_SCANCODE_F4] = tic_key_f4,
[SDL_SCANCODE_F5] = tic_key_unknown, [SDL_SCANCODE_F5] = tic_key_f5,
[SDL_SCANCODE_F6] = tic_key_unknown, [SDL_SCANCODE_F6] = tic_key_f6,
[SDL_SCANCODE_F7] = tic_key_unknown, [SDL_SCANCODE_F7] = tic_key_f7,
[SDL_SCANCODE_F8] = tic_key_unknown, [SDL_SCANCODE_F8] = tic_key_f8,
[SDL_SCANCODE_F9] = tic_key_unknown, [SDL_SCANCODE_F9] = tic_key_f9,
[SDL_SCANCODE_F10] = tic_key_unknown, [SDL_SCANCODE_F10] = tic_key_f10,
[SDL_SCANCODE_F11] = tic_key_unknown, [SDL_SCANCODE_F11] = tic_key_f11,
[SDL_SCANCODE_F12] = tic_key_unknown, [SDL_SCANCODE_F12] = tic_key_f12,
[70] = tic_key_unknown, [70] = tic_key_unknown,
[71] = tic_key_unknown, [71] = tic_key_unknown,
[72] = tic_key_unknown, [72] = tic_key_unknown,

View File

@ -795,7 +795,7 @@ static s32 lua_key(lua_State* lua)
{ {
tic_key key = getLuaNumber(lua, 1); tic_key key = getLuaNumber(lua, 1);
if(key < tic_keys_count) if(key < tic_key_escape)
lua_pushboolean(lua, tic->api.key(tic, key)); lua_pushboolean(lua, tic->api.key(tic, key));
else else
{ {
@ -827,7 +827,7 @@ static s32 lua_keyp(lua_State* lua)
{ {
tic_key key = getLuaNumber(lua, 1); tic_key key = getLuaNumber(lua, 1);
if(key >= tic_keys_count) if(key >= tic_key_escape)
{ {
luaL_error(lua, "unknown keyboard code\n"); luaL_error(lua, "unknown keyboard code\n");
} }
@ -1069,6 +1069,7 @@ static s32 lua_pmem(lua_State *lua)
if(top >= 2) if(top >= 2)
{ {
memory->persistent.data[index] = getLuaNumber(lua, 2); memory->persistent.data[index] = getLuaNumber(lua, 2);
machine->data->syncPMEM = true;
} }
lua_pushinteger(lua, val); lua_pushinteger(lua, val);

265
src/map.c
View File

@ -47,14 +47,14 @@ static void normalizeMap(s32* x, s32* y)
while(*y >= MAX_SCROLL_Y) *y -= MAX_SCROLL_Y; while(*y >= MAX_SCROLL_Y) *y -= MAX_SCROLL_Y;
} }
static SDL_Point getTileOffset(Map* map) static tic_point getTileOffset(Map* map)
{ {
return (SDL_Point){(map->sheet.rect.w - 1)*TIC_SPRITESIZE / 2, (map->sheet.rect.h - 1)*TIC_SPRITESIZE / 2}; return (tic_point){(map->sheet.rect.w - 1)*TIC_SPRITESIZE / 2, (map->sheet.rect.h - 1)*TIC_SPRITESIZE / 2};
} }
static void getMouseMap(Map* map, s32* x, s32* y) static void getMouseMap(Map* map, s32* x, s32* y)
{ {
SDL_Point offset = getTileOffset(map); tic_point offset = getTileOffset(map);
s32 mx = getMouseX() + map->scroll.x - offset.x; s32 mx = getMouseX() + map->scroll.x - offset.x;
s32 my = getMouseY() + map->scroll.y - offset.y; s32 my = getMouseY() + map->scroll.y - offset.y;
@ -83,19 +83,19 @@ static s32 drawWorldButton(Map* map, s32 x, s32 y)
x -= Size; x -= Size;
SDL_Rect rect = {x, y, Size, ICON_SIZE}; tic_rect rect = {x, y, Size, ICON_SIZE};
bool over = false; bool over = false;
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
over = true; over = true;
showTooltip("WORLD MAP [tab]"); showTooltip("WORLD MAP [tab]");
if(checkMouseClick(&rect, SDL_BUTTON_LEFT)) if(checkMouseClick(&rect, tic_mouse_left))
setStudioMode(TIC_WORLD_MODE); setStudioMode(TIC_WORLD_MODE);
} }
@ -121,19 +121,19 @@ static s32 drawGridButton(Map* map, s32 x, s32 y)
x -= ICON_SIZE; x -= ICON_SIZE;
SDL_Rect rect = {x, y, ICON_SIZE, ICON_SIZE}; tic_rect rect = {x, y, ICON_SIZE, ICON_SIZE};
bool over = false; bool over = false;
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
over = true; over = true;
showTooltip("SHOW/HIDE GRID [`]"); showTooltip("SHOW/HIDE GRID [`]");
if(checkMouseClick(&rect, SDL_BUTTON_LEFT)) if(checkMouseClick(&rect, tic_mouse_left))
map->canvas.grid = !map->canvas.grid; map->canvas.grid = !map->canvas.grid;
} }
@ -170,17 +170,17 @@ static s32 drawSheetButton(Map* map, s32 x, s32 y)
x -= ICON_SIZE; x -= ICON_SIZE;
SDL_Rect rect = {x, y, ICON_SIZE, ICON_SIZE}; tic_rect rect = {x, y, ICON_SIZE, ICON_SIZE};
bool over = false; bool over = false;
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
over = true; over = true;
showTooltip("SHOW TILES [shift]"); showTooltip("SHOW TILES [shift]");
if(checkMouseClick(&rect, SDL_BUTTON_LEFT)) if(checkMouseClick(&rect, tic_mouse_left))
{ {
map->sheet.show = !map->sheet.show; map->sheet.show = !map->sheet.show;
} }
@ -195,18 +195,18 @@ static s32 drawToolButton(Map* map, s32 x, s32 y, const u8* Icon, s32 width, con
{ {
x -= width; x -= width;
SDL_Rect rect = {x, y, width, ICON_SIZE}; tic_rect rect = {x, y, width, ICON_SIZE};
bool over = false; bool over = false;
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
over = true; over = true;
showTooltip(tip); showTooltip(tip);
if(checkMouseClick(&rect, SDL_BUTTON_LEFT)) if(checkMouseClick(&rect, tic_mouse_left))
{ {
map->mode = mode; map->mode = mode;
} }
@ -293,7 +293,7 @@ static void drawTileIndex(Map* map, s32 x, s32 y)
if(map->sheet.show) if(map->sheet.show)
{ {
SDL_Rect rect = {TIC80_WIDTH - TIC_SPRITESHEET_SIZE - 1, TOOLBAR_SIZE, TIC_SPRITESHEET_SIZE, TIC_SPRITESHEET_SIZE}; tic_rect rect = {TIC80_WIDTH - TIC_SPRITESHEET_SIZE - 1, TOOLBAR_SIZE, TIC_SPRITESHEET_SIZE, TIC_SPRITESHEET_SIZE};
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
@ -308,7 +308,7 @@ static void drawTileIndex(Map* map, s32 x, s32 y)
} }
else else
{ {
SDL_Rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT}; tic_rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT};
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
@ -346,7 +346,7 @@ static void drawSheet(Map* map, s32 x, s32 y)
{ {
if(!map->sheet.show)return; if(!map->sheet.show)return;
SDL_Rect rect = {x, y, TIC_SPRITESHEET_SIZE, TIC_SPRITESHEET_SIZE}; tic_rect rect = {x, y, TIC_SPRITESHEET_SIZE, TIC_SPRITESHEET_SIZE};
map->tic->api.rect_border(map->tic, rect.x - 1, rect.y - 1, rect.w + 2, rect.h + 2, (tic_color_white)); map->tic->api.rect_border(map->tic, rect.x - 1, rect.y - 1, rect.w + 2, rect.h + 2, (tic_color_white));
} }
@ -355,13 +355,13 @@ static void drawSheetOvr(Map* map, s32 x, s32 y)
{ {
if(!map->sheet.show)return; if(!map->sheet.show)return;
SDL_Rect rect = {x, y, TIC_SPRITESHEET_SIZE, TIC_SPRITESHEET_SIZE}; tic_rect rect = {x, y, TIC_SPRITESHEET_SIZE, TIC_SPRITESHEET_SIZE};
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
if(checkMouseDown(&rect, SDL_BUTTON_LEFT)) if(checkMouseDown(&rect, tic_mouse_left))
{ {
s32 mx = getMouseX() - rect.x; s32 mx = getMouseX() - rect.x;
s32 my = getMouseY() - rect.y; s32 my = getMouseY() - rect.y;
@ -371,19 +371,19 @@ static void drawSheetOvr(Map* map, s32 x, s32 y)
if(map->sheet.drag) if(map->sheet.drag)
{ {
s32 rl = SDL_min(mx, map->sheet.start.x); s32 rl = MIN(mx, map->sheet.start.x);
s32 rt = SDL_min(my, map->sheet.start.y); s32 rt = MIN(my, map->sheet.start.y);
s32 rr = SDL_max(mx, map->sheet.start.x); s32 rr = MAX(mx, map->sheet.start.x);
s32 rb = SDL_max(my, map->sheet.start.y); s32 rb = MAX(my, map->sheet.start.y);
map->sheet.rect = (SDL_Rect){rl, rt, rr-rl+1, rb-rt+1}; map->sheet.rect = (tic_rect){rl, rt, rr-rl+1, rb-rt+1};
map->mode = MAP_DRAW_MODE; map->mode = MAP_DRAW_MODE;
} }
else else
{ {
map->sheet.drag = true; map->sheet.drag = true;
map->sheet.start = (SDL_Point){mx, my}; map->sheet.start = (tic_point){mx, my};
} }
} }
else else
@ -447,7 +447,7 @@ static void drawTileCursor(Map* map)
if(map->scroll.active) if(map->scroll.active)
return; return;
SDL_Point offset = getTileOffset(map); tic_point offset = getTileOffset(map);
s32 mx = getMouseX() + map->scroll.x - offset.x; s32 mx = getMouseX() + map->scroll.x - offset.x;
s32 my = getMouseY() + map->scroll.y - offset.y; s32 my = getMouseY() + map->scroll.y - offset.y;
@ -478,13 +478,13 @@ static void drawTileCursor(Map* map)
static void processMouseDrawMode(Map* map) static void processMouseDrawMode(Map* map)
{ {
SDL_Rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT}; tic_rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT};
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
drawTileCursor(map); drawTileCursor(map);
if(checkMouseDown(&rect, SDL_BUTTON_LEFT)) if(checkMouseDown(&rect, tic_mouse_left))
{ {
s32 tx = 0, ty = 0; s32 tx = 0, ty = 0;
getMouseMap(map, &tx, &ty); getMouseMap(map, &tx, &ty);
@ -500,7 +500,7 @@ static void processMouseDrawMode(Map* map)
else else
{ {
map->canvas.draw = true; map->canvas.draw = true;
map->canvas.start = (SDL_Point){tx, ty}; map->canvas.start = (tic_point){tx, ty};
} }
} }
else else
@ -508,19 +508,19 @@ static void processMouseDrawMode(Map* map)
map->canvas.draw = false; map->canvas.draw = false;
} }
if(checkMouseDown(&rect, SDL_BUTTON_MIDDLE)) if(checkMouseDown(&rect, tic_mouse_middle))
{ {
s32 tx = 0, ty = 0; s32 tx = 0, ty = 0;
getMouseMap(map, &tx, &ty); getMouseMap(map, &tx, &ty);
s32 index = map->tic->api.map_get(map->tic, map->src, tx, ty); s32 index = map->tic->api.map_get(map->tic, map->src, tx, ty);
map->sheet.rect = (SDL_Rect){index % SHEET_COLS, index / SHEET_COLS, 1, 1}; map->sheet.rect = (tic_rect){index % SHEET_COLS, index / SHEET_COLS, 1, 1};
} }
} }
static void processScrolling(Map* map, bool pressed) static void processScrolling(Map* map, bool pressed)
{ {
SDL_Rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT}; tic_rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT};
if(map->scroll.active) if(map->scroll.active)
{ {
@ -531,7 +531,7 @@ static void processScrolling(Map* map, bool pressed)
normalizeMap(&map->scroll.x, &map->scroll.y); normalizeMap(&map->scroll.x, &map->scroll.y);
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
} }
else map->scroll.active = false; else map->scroll.active = false;
} }
@ -549,15 +549,15 @@ static void processScrolling(Map* map, bool pressed)
static void processMouseDragMode(Map* map) static void processMouseDragMode(Map* map)
{ {
SDL_Rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT}; tic_rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT};
processScrolling(map, checkMouseDown(&rect, SDL_BUTTON_LEFT) || processScrolling(map, checkMouseDown(&rect, tic_mouse_left) ||
checkMouseDown(&rect, SDL_BUTTON_RIGHT)); checkMouseDown(&rect, tic_mouse_right));
} }
static void resetSelection(Map* map) static void resetSelection(Map* map)
{ {
map->select.rect = (SDL_Rect){0,0,0,0}; map->select.rect = (tic_rect){0,0,0,0};
} }
static void drawSelectionRect(Map* map, s32 x, s32 y, s32 w, s32 h) static void drawSelectionRect(Map* map, s32 x, s32 y, s32 w, s32 h)
@ -582,9 +582,9 @@ static void drawPasteData(Map* map)
s32 mx = getMouseX() + map->scroll.x - (w - 1)*TIC_SPRITESIZE / 2; s32 mx = getMouseX() + map->scroll.x - (w - 1)*TIC_SPRITESIZE / 2;
s32 my = getMouseY() + map->scroll.y - (h - 1)*TIC_SPRITESIZE / 2; s32 my = getMouseY() + map->scroll.y - (h - 1)*TIC_SPRITESIZE / 2;
SDL_Rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT}; tic_rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT};
if(checkMouseClick(&rect, SDL_BUTTON_LEFT)) if(checkMouseClick(&rect, tic_mouse_left))
{ {
normalizeMap(&mx, &my); normalizeMap(&mx, &my);
@ -597,7 +597,7 @@ static void drawPasteData(Map* map)
history_add(map->history); history_add(map->history);
SDL_free(map->paste); free(map->paste);
map->paste = NULL; map->paste = NULL;
} }
else else
@ -626,7 +626,7 @@ static void normalizeMapRect(s32* x, s32* y)
static void processMouseSelectMode(Map* map) static void processMouseSelectMode(Map* map)
{ {
SDL_Rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT}; tic_rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT};
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
@ -634,7 +634,7 @@ static void processMouseSelectMode(Map* map)
drawPasteData(map); drawPasteData(map);
else else
{ {
if(checkMouseDown(&rect, SDL_BUTTON_LEFT)) if(checkMouseDown(&rect, tic_mouse_left))
{ {
s32 mx = getMouseX() + map->scroll.x; s32 mx = getMouseX() + map->scroll.x;
s32 my = getMouseY() + map->scroll.y; s32 my = getMouseY() + map->scroll.y;
@ -646,18 +646,18 @@ static void processMouseSelectMode(Map* map)
if(map->select.drag) if(map->select.drag)
{ {
s32 rl = SDL_min(mx, map->select.start.x); s32 rl = MIN(mx, map->select.start.x);
s32 rt = SDL_min(my, map->select.start.y); s32 rt = MIN(my, map->select.start.y);
s32 rr = SDL_max(mx, map->select.start.x); s32 rr = MAX(mx, map->select.start.x);
s32 rb = SDL_max(my, map->select.start.y); s32 rb = MAX(my, map->select.start.y);
map->select.rect = (SDL_Rect){rl, rt, rr - rl + 1, rb - rt + 1}; map->select.rect = (tic_rect){rl, rt, rr - rl + 1, rb - rt + 1};
} }
else else
{ {
map->select.drag = true; map->select.drag = true;
map->select.start = (SDL_Point){mx, my}; map->select.start = (tic_point){mx, my};
map->select.rect = (SDL_Rect){map->select.start.x, map->select.start.y, 1, 1}; map->select.rect = (tic_rect){map->select.start.x, map->select.start.y, 1, 1};
} }
} }
else if(map->select.drag) else if(map->select.drag)
@ -673,8 +673,8 @@ static void processMouseSelectMode(Map* map)
typedef struct typedef struct
{ {
SDL_Point* data; tic_point* data;
SDL_Point* head; tic_point* head;
} FillStack; } FillStack;
static bool push(FillStack* stack, s32 x, s32 y) static bool push(FillStack* stack, s32 x, s32 y)
@ -732,7 +732,7 @@ static void fillMap(Map* map, s32 x, s32 y, u8 tile)
static FillStack stack = {NULL, NULL}; static FillStack stack = {NULL, NULL};
if(!stack.data) if(!stack.data)
stack.data = (SDL_Point*)SDL_malloc(FILL_STACK_SIZE * sizeof(SDL_Point)); stack.data = (tic_point*)malloc(FILL_STACK_SIZE * sizeof(tic_point));
stack.head = NULL; stack.head = NULL;
@ -790,13 +790,13 @@ static void fillMap(Map* map, s32 x, s32 y, u8 tile)
static void processMouseFillMode(Map* map) static void processMouseFillMode(Map* map)
{ {
SDL_Rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT}; tic_rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT};
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
drawTileCursor(map); drawTileCursor(map);
if(checkMouseClick(&rect, SDL_BUTTON_LEFT)) if(checkMouseClick(&rect, tic_mouse_left))
{ {
s32 tx = 0, ty = 0; s32 tx = 0, ty = 0;
getMouseMap(map, &tx, &ty); getMouseMap(map, &tx, &ty);
@ -808,7 +808,7 @@ static void processMouseFillMode(Map* map)
static void drawSelection(Map* map) static void drawSelection(Map* map)
{ {
SDL_Rect* sel = &map->select.rect; tic_rect* sel = &map->select.rect;
if(sel->w > 0 && sel->h > 0) if(sel->w > 0 && sel->h > 0)
{ {
@ -859,12 +859,13 @@ static void drawGrid(Map* map)
static void drawMapOvr(Map* map) static void drawMapOvr(Map* map)
{ {
SDL_Rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT}; tic_rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT};
s32 scrollX = map->scroll.x % TIC_SPRITESIZE; s32 scrollX = map->scroll.x % TIC_SPRITESIZE;
s32 scrollY = map->scroll.y % TIC_SPRITESIZE; s32 scrollY = map->scroll.y % TIC_SPRITESIZE;
map->tic->api.map(map->tic, map->src, getBankTiles(), map->scroll.x / TIC_SPRITESIZE, map->scroll.y / TIC_SPRITESIZE, tic_mem* tic = map->tic;
tic->api.map(tic, map->src, getBankTiles(), map->scroll.x / TIC_SPRITESIZE, map->scroll.y / TIC_SPRITESIZE,
TIC_MAP_SCREEN_WIDTH + 1, TIC_MAP_SCREEN_HEIGHT + 1, -scrollX, -scrollY, -1, 1); TIC_MAP_SCREEN_WIDTH + 1, TIC_MAP_SCREEN_HEIGHT + 1, -scrollX, -scrollY, -1, 1);
if(map->canvas.grid || map->scroll.active) if(map->canvas.grid || map->scroll.active)
@ -874,15 +875,15 @@ static void drawMapOvr(Map* map)
s32 screenScrollX = map->scroll.x % TIC80_WIDTH; s32 screenScrollX = map->scroll.x % TIC80_WIDTH;
s32 screenScrollY = map->scroll.y % TIC80_HEIGHT; s32 screenScrollY = map->scroll.y % TIC80_HEIGHT;
map->tic->api.line(map->tic, 0, TIC80_HEIGHT - screenScrollY, TIC80_WIDTH, TIC80_HEIGHT - screenScrollY, (tic_color_gray)); tic->api.line(tic, 0, TIC80_HEIGHT - screenScrollY, TIC80_WIDTH, TIC80_HEIGHT - screenScrollY, (tic_color_gray));
map->tic->api.line(map->tic, TIC80_WIDTH - screenScrollX, 0, TIC80_WIDTH - screenScrollX, TIC80_HEIGHT, (tic_color_gray)); tic->api.line(tic, TIC80_WIDTH - screenScrollX, 0, TIC80_WIDTH - screenScrollX, TIC80_HEIGHT, (tic_color_gray));
} }
if(!map->sheet.show && checkMousePos(&rect)) if(!map->sheet.show && checkMousePos(&rect))
{ {
if(getKeyboard()[SDL_SCANCODE_SPACE]) if(tic->api.key(tic, tic_key_space))
{ {
processScrolling(map, checkMouseDown(&rect, SDL_BUTTON_LEFT) || checkMouseDown(&rect, SDL_BUTTON_RIGHT)); processScrolling(map, checkMouseDown(&rect, tic_mouse_left) || checkMouseDown(&rect, tic_mouse_right));
} }
else else
{ {
@ -891,32 +892,13 @@ static void drawMapOvr(Map* map)
Handlers[map->mode](map); Handlers[map->mode](map);
if(map->mode != MAP_DRAG_MODE) if(map->mode != MAP_DRAG_MODE)
processScrolling(map, checkMouseDown(&rect, SDL_BUTTON_RIGHT)); processScrolling(map, checkMouseDown(&rect, tic_mouse_right));
} }
} }
drawSelection(map); drawSelection(map);
} }
static void processKeyboard(Map* map)
{
enum{Step = 1};
if(getKeyboard()[SDL_SCANCODE_UP]) map->scroll.y -= Step;
if(getKeyboard()[SDL_SCANCODE_DOWN]) map->scroll.y += Step;
if(getKeyboard()[SDL_SCANCODE_LEFT]) map->scroll.x -= Step;
if(getKeyboard()[SDL_SCANCODE_RIGHT]) map->scroll.x += Step;
static const u8 Scancodes[] = {SDL_SCANCODE_UP, SDL_SCANCODE_DOWN, SDL_SCANCODE_LEFT, SDL_SCANCODE_RIGHT};
for(s32 i = 0; i < COUNT_OF(Scancodes); i++)
if(getKeyboard()[Scancodes[i]])
{
normalizeMap(&map->scroll.x, &map->scroll.y);
break;
}
}
static void undo(Map* map) static void undo(Map* map)
{ {
history_undo(map->history); history_undo(map->history);
@ -929,12 +911,12 @@ static void redo(Map* map)
static void copySelectionToClipboard(Map* map) static void copySelectionToClipboard(Map* map)
{ {
SDL_Rect* sel = &map->select.rect; tic_rect* sel = &map->select.rect;
if(sel->w > 0 && sel->h > 0) if(sel->w > 0 && sel->h > 0)
{ {
s32 size = sel->w * sel->h + 2; s32 size = sel->w * sel->h + 2;
u8* buffer = SDL_malloc(size); u8* buffer = malloc(size);
if(buffer) if(buffer)
{ {
@ -954,7 +936,7 @@ static void copySelectionToClipboard(Map* map)
} }
toClipboard(buffer, size, true); toClipboard(buffer, size, true);
SDL_free(buffer); free(buffer);
} }
} }
} }
@ -967,7 +949,7 @@ static void copyToClipboard(Map* map)
static void deleteSelection(Map* map) static void deleteSelection(Map* map)
{ {
SDL_Rect* sel = &map->select.rect; tic_rect* sel = &map->select.rect;
if(sel->w > 0 && sel->h > 0) if(sel->w > 0 && sel->h > 0)
{ {
@ -994,9 +976,9 @@ static void cutToClipboard(Map* map)
static void copyFromClipboard(Map* map) static void copyFromClipboard(Map* map)
{ {
if(SDL_HasClipboardText()) if(getSystem()->hasClipboardText())
{ {
char* clipboard = SDL_GetClipboardText(); char* clipboard = getSystem()->getClipboardText();
if(clipboard) if(clipboard)
{ {
@ -1004,7 +986,7 @@ static void copyFromClipboard(Map* map)
if(size > 2) if(size > 2)
{ {
u8* data = SDL_malloc(size); u8* data = malloc(size);
str2buf(clipboard, strlen(clipboard), data, true); str2buf(clipboard, strlen(clipboard), data, true);
@ -1013,19 +995,25 @@ static void copyFromClipboard(Map* map)
map->paste = data; map->paste = data;
map->mode = MAP_SELECT_MODE; map->mode = MAP_SELECT_MODE;
} }
else SDL_free(data); else free(data);
} }
SDL_free(clipboard); free(clipboard);
} }
} }
} }
static void processKeydown(Map* map, SDL_Keycode keycode) static void processKeyboard(Map* map)
{ {
SDL_Keymod keymod = SDL_GetModState(); tic_mem* tic = map->tic;
map->sheet.show = false;
switch(getClipboardEvent(keycode)) if(tic->ram.input.keyboard.data == 0) return;
bool shift = tic->api.key(tic, tic_key_shift);
bool ctrl = tic->api.key(tic, tic_key_ctrl);
switch(getClipboardEvent())
{ {
case TIC_CLIPBOARD_CUT: cutToClipboard(map); break; case TIC_CLIPBOARD_CUT: cutToClipboard(map); break;
case TIC_CLIPBOARD_COPY: copyToClipboard(map); break; case TIC_CLIPBOARD_COPY: copyToClipboard(map); break;
@ -1033,90 +1021,47 @@ static void processKeydown(Map* map, SDL_Keycode keycode)
default: break; default: break;
} }
if(keymod & TIC_MOD_CTRL) if(ctrl)
{ {
switch(keycode) if(keyWasPressed(tic_key_z)) undo(map);
{ else if(keyWasPressed(tic_key_y)) redo(map);
case SDLK_z: undo(map); break;
case SDLK_y: redo(map); break;
}
} }
else else
{ {
switch(keycode) if(keyWasPressed(tic_key_tab)) setStudioMode(TIC_WORLD_MODE);
{ else if(keyWasPressed(tic_key_1)) map->mode = MAP_DRAW_MODE;
case SDLK_TAB: setStudioMode(TIC_WORLD_MODE); break; else if(keyWasPressed(tic_key_2)) map->mode = MAP_DRAG_MODE;
case SDLK_1: else if(keyWasPressed(tic_key_3)) map->mode = MAP_SELECT_MODE;
case SDLK_2: else if(keyWasPressed(tic_key_4)) map->mode = MAP_FILL_MODE;
case SDLK_3: else if(keyWasPressed(tic_key_delete)) deleteSelection(map);
case SDLK_4: else if(keyWasPressed(tic_key_grave)) map->canvas.grid = !map->canvas.grid;
map->mode = keycode - SDLK_1;
break;
case SDLK_DELETE:
deleteSelection(map);
break;
case SDLK_BACKQUOTE:
map->canvas.grid = !map->canvas.grid;
break;
}
} }
if(keymod & KMOD_SHIFT) if(shift)
map->sheet.show = true; map->sheet.show = true;
}
static void processKeyup(Map* map, SDL_Keycode keycode) enum{Step = 1};
{
SDL_Keymod keymod = SDL_GetModState();
if(!(keymod & KMOD_SHIFT)) if(tic->api.key(tic, tic_key_up)) map->scroll.y -= Step;
map->sheet.show = false; if(tic->api.key(tic, tic_key_down)) map->scroll.y += Step;
} if(tic->api.key(tic, tic_key_left)) map->scroll.x -= Step;
if(tic->api.key(tic, tic_key_right)) map->scroll.x += Step;
static void processGesture(Map* map) static const tic_key Keycodes[] = {tic_key_up, tic_key_down, tic_key_left, tic_key_right};
{
SDL_Point point = {0, 0};
if(getGesturePos(&point)) for(s32 i = 0; i < COUNT_OF(Keycodes); i++)
{ if(tic->api.key(tic, Keycodes[i]))
if(map->scroll.gesture)
{ {
map->scroll.x = map->scroll.start.x - point.x;
map->scroll.y = map->scroll.start.y - point.y;
normalizeMap(&map->scroll.x, &map->scroll.y); normalizeMap(&map->scroll.x, &map->scroll.y);
break;
} }
else
{
map->scroll.start.x = point.x + map->scroll.x;
map->scroll.start.y = point.y + map->scroll.y;
map->scroll.gesture = true;
}
}
else map->scroll.gesture = false;
} }
static void tick(Map* map) static void tick(Map* map)
{ {
map->tickCounter++; map->tickCounter++;
SDL_Event* event = NULL;
while ((event = pollEvent()))
{
switch(event->type)
{
case SDL_KEYDOWN:
processKeydown(map, event->key.keysym.sym);
break;
case SDL_KEYUP:
processKeyup(map, event->key.keysym.sym);
break;
}
}
processKeyboard(map); processKeyboard(map);
processGesture(map);
map->tic->api.clear(map->tic, TIC_COLOR_BG); map->tic->api.clear(map->tic, TIC_COLOR_BG);
drawSheet(map, TIC80_WIDTH - TIC_SPRITESHEET_SIZE - 1, TOOLBAR_SIZE); drawSheet(map, TIC80_WIDTH - TIC_SPRITESHEET_SIZE - 1, TOOLBAR_SIZE);

View File

@ -46,14 +46,14 @@ struct Map
{ {
bool grid; bool grid;
bool draw; bool draw;
SDL_Point start; tic_point start;
} canvas; } canvas;
struct struct
{ {
bool show; bool show;
SDL_Rect rect; tic_rect rect;
SDL_Point start; tic_point start;
bool drag; bool drag;
} sheet; } sheet;
@ -62,7 +62,7 @@ struct Map
s32 x; s32 x;
s32 y; s32 y;
SDL_Point start; tic_point start;
bool active; bool active;
bool gesture; bool gesture;
@ -71,8 +71,8 @@ struct Map
struct struct
{ {
SDL_Rect rect; tic_rect rect;
SDL_Point start; tic_point start;
bool drag; bool drag;
} select; } select;

View File

@ -63,9 +63,9 @@ static void exitToTIC(Menu* menu)
static void(*const MenuHandlers[])(Menu*) = {resumeGame, resetGame, gamepadConfig, NULL, exitToTIC}; static void(*const MenuHandlers[])(Menu*) = {resumeGame, resetGame, gamepadConfig, NULL, exitToTIC};
static SDL_Rect getRect(Menu* menu) static tic_rect getRect(Menu* menu)
{ {
SDL_Rect rect = {(TIC80_WIDTH - DIALOG_WIDTH)/2, (TIC80_HEIGHT - DIALOG_HEIGHT)/2, DIALOG_WIDTH, DIALOG_HEIGHT}; tic_rect rect = {(TIC80_WIDTH - DIALOG_WIDTH)/2, (TIC80_HEIGHT - DIALOG_HEIGHT)/2, DIALOG_WIDTH, DIALOG_HEIGHT};
rect.x -= menu->pos.x; rect.x -= menu->pos.x;
rect.y -= menu->pos.y; rect.y -= menu->pos.y;
@ -74,17 +74,17 @@ static SDL_Rect getRect(Menu* menu)
} }
static void drawDialog(Menu* menu) static void drawDialog(Menu* menu)
{ {
SDL_Rect rect = getRect(menu); tic_rect rect = getRect(menu);
tic_mem* tic = menu->tic; tic_mem* tic = menu->tic;
SDL_Rect header = {rect.x, rect.y-(TOOLBAR_SIZE-1), rect.w, TOOLBAR_SIZE}; tic_rect header = {rect.x, rect.y-(TOOLBAR_SIZE-1), rect.w, TOOLBAR_SIZE};
if(checkMousePos(&header)) if(checkMousePos(&header))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
if(checkMouseDown(&header, SDL_BUTTON_LEFT)) if(checkMouseDown(&header, tic_mouse_left))
{ {
if(!menu->drag.active) if(!menu->drag.active)
{ {
@ -98,13 +98,13 @@ static void drawDialog(Menu* menu)
if(menu->drag.active) if(menu->drag.active)
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
menu->pos.x = menu->drag.start.x - getMouseX(); menu->pos.x = menu->drag.start.x - getMouseX();
menu->pos.y = menu->drag.start.y - getMouseY(); menu->pos.y = menu->drag.start.y - getMouseY();
SDL_Rect rect = {0, 0, TIC80_WIDTH, TIC80_HEIGHT}; tic_rect rect = {0, 0, TIC80_WIDTH, TIC80_HEIGHT};
if(!checkMouseDown(&rect, SDL_BUTTON_LEFT)) if(!checkMouseDown(&rect, tic_mouse_left))
menu->drag.active = false; menu->drag.active = false;
} }
@ -133,15 +133,15 @@ static void drawTabDisabled(Menu* menu, s32 x, s32 y, s32 id)
enum{Width = 15, Height = 7}; enum{Width = 15, Height = 7};
tic_mem* tic = menu->tic; tic_mem* tic = menu->tic;
SDL_Rect rect = {x, y, Width, Height}; tic_rect rect = {x, y, Width, Height};
bool over = false; bool over = false;
if(menu->gamepad.tab != id && checkMousePos(&rect)) if(menu->gamepad.tab != id && checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
over = true; over = true;
if(checkMouseDown(&rect, SDL_BUTTON_LEFT)) if(checkMouseDown(&rect, tic_mouse_left))
{ {
menu->gamepad.tab = id; menu->gamepad.tab = id;
menu->gamepad.selected = -1; menu->gamepad.selected = -1;
@ -183,24 +183,24 @@ static void drawPlayerButtons(Menu* menu, s32 x, s32 y)
u8 chromakey = 0; u8 chromakey = 0;
SDL_Scancode* codes = getKeymap(); tic_key* codes = getKeymap();
enum {Width = 41, Height = TIC_SPRITESIZE, Rows = 4, Cols = 2, MaxChars = 5, Buttons = 8}; enum {Width = 41, Height = TIC_SPRITESIZE, Rows = 4, Cols = 2, MaxChars = 5, Buttons = 8};
for(s32 i = 0; i < Buttons; i++) for(s32 i = 0; i < Buttons; i++)
{ {
SDL_Rect rect = {x + i / Rows * (Width+2), y + (i%Rows)*(Height+1), Width, TIC_SPRITESIZE}; tic_rect rect = {x + i / Rows * (Width+2), y + (i%Rows)*(Height+1), Width, TIC_SPRITESIZE};
bool over = false; bool over = false;
s32 index = i+menu->gamepad.tab * Buttons; s32 index = i+menu->gamepad.tab * Buttons;
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
over = true; over = true;
if(checkMouseClick(&rect, SDL_BUTTON_LEFT)) if(checkMouseClick(&rect, tic_mouse_left))
{ {
menu->gamepad.selected = menu->gamepad.selected != index ? index : -1; menu->gamepad.selected = menu->gamepad.selected != index ? index : -1;
} }
@ -211,9 +211,11 @@ static void drawPlayerButtons(Menu* menu, s32 x, s32 y)
tic->api.sprite_ex(tic, &tic->config.bank0.tiles, 8+i, rect.x, rect.y, 1, 1, &chromakey, 1, 1, tic_no_flip, tic_no_rotate); tic->api.sprite_ex(tic, &tic->config.bank0.tiles, 8+i, rect.x, rect.y, 1, 1, &chromakey, 1, 1, tic_no_flip, tic_no_rotate);
static const char const * Names[tic_keys_count] = {"...", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "minus", "equals", "leftbracket", "rightbracket", "backslash", "semicolon", "apostrophe", "grave", "comma", "period", "slash", "space", "tab", "return", "backspace", "delete", "insert", "pageup", "pagedown", "home", "end", "up", "down", "left", "right", "capslock", "ctrl", "shift", "alt", "escape", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", "f11", "f12"};
s32 code = codes[index]; s32 code = codes[index];
char label[32]; char label[32];
strcpy(label, code ? SDL_GetKeyName(SDL_GetKeyFromScancode(code)) : "..."); strcpy(label, Names[code]);
if(strlen(label) > MaxChars) if(strlen(label) > MaxChars)
label[MaxChars] = '\0'; label[MaxChars] = '\0';
@ -246,27 +248,27 @@ static void drawGamepadMenu(Menu* menu)
tic_mem* tic = menu->tic; tic_mem* tic = menu->tic;
SDL_Rect dlgRect = getRect(menu); tic_rect dlgRect = getRect(menu);
static const char Label[] = "BACK"; static const char Label[] = "BACK";
SDL_Rect rect = {dlgRect.x + 25, dlgRect.y + 49, (sizeof(Label)-1)*TIC_FONT_WIDTH, TIC_FONT_HEIGHT}; tic_rect rect = {dlgRect.x + 25, dlgRect.y + 49, (sizeof(Label)-1)*TIC_FONT_WIDTH, TIC_FONT_HEIGHT};
bool over = false; bool over = false;
bool down = false; bool down = false;
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
over = true; over = true;
if(checkMouseDown(&rect, SDL_BUTTON_LEFT)) if(checkMouseDown(&rect, tic_mouse_left))
{ {
down = true; down = true;
} }
if(checkMouseClick(&rect, SDL_BUTTON_LEFT)) if(checkMouseClick(&rect, tic_mouse_left))
{ {
menu->gamepad.selected = -1; menu->gamepad.selected = -1;
menu->mode = MAIN_MENU_MODE; menu->mode = MAIN_MENU_MODE;
@ -311,30 +313,30 @@ static void drawMainMenu(Menu* menu)
drawDialog(menu); drawDialog(menu);
SDL_Rect rect = getRect(menu); tic_rect rect = getRect(menu);
{ {
for(s32 i = 0; i < COUNT_OF(Rows); i++) for(s32 i = 0; i < COUNT_OF(Rows); i++)
{ {
if(!*Rows[i])continue; if(!*Rows[i])continue;
SDL_Rect label = {rect.x + 22, rect.y + (TIC_FONT_HEIGHT+1)*i + 16, 86, TIC_FONT_HEIGHT+1}; tic_rect label = {rect.x + 22, rect.y + (TIC_FONT_HEIGHT+1)*i + 16, 86, TIC_FONT_HEIGHT+1};
bool over = false; bool over = false;
bool down = false; bool down = false;
if(checkMousePos(&label)) if(checkMousePos(&label))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
over = true; over = true;
if(checkMouseDown(&label, SDL_BUTTON_LEFT)) if(checkMouseDown(&label, tic_mouse_left))
{ {
down = true; down = true;
menu->main.focus = i; menu->main.focus = i;
} }
if(checkMouseClick(&label, SDL_BUTTON_LEFT)) if(checkMouseClick(&label, tic_mouse_left))
{ {
MenuHandlers[i](menu); MenuHandlers[i](menu);
return; return;
@ -432,22 +434,29 @@ static void saveMapping(Menu* menu)
fsSaveRootFile(menu->fs, KEYMAP_DAT_PATH, getKeymap(), KEYMAP_SIZE, true); fsSaveRootFile(menu->fs, KEYMAP_DAT_PATH, getKeymap(), KEYMAP_SIZE, true);
} }
static void processKeydown(Menu* menu, SDL_Keysym* keysum) static void processKeyboard(Menu* menu)
{ {
tic_mem* tic = menu->tic;
if(tic->ram.input.keyboard.data == 0) return;
if(menu->gamepad.selected < 0) if(menu->gamepad.selected < 0)
return; return;
SDL_Scancode scancode = keysum->scancode; if(keyWasPressed(tic_key_escape));
else if(anyKeyWasPressed())
switch(scancode)
{ {
case SDL_SCANCODE_ESCAPE: break; for(s32 i = 0; i < TIC80_KEY_BUFFER; i++)
default:
{ {
SDL_Scancode* codes = getKeymap(); tic_key key = tic->ram.input.keyboard.keys[i];
codes[menu->gamepad.selected] = scancode;
saveMapping(menu); if(tic->api.keyp(tic, key, -1, -1))
{
tic_key* codes = getKeymap();
codes[menu->gamepad.selected] = key;
saveMapping(menu);
break;
}
} }
} }
@ -458,16 +467,7 @@ static void tick(Menu* menu)
{ {
menu->ticks++; menu->ticks++;
SDL_Event* event = NULL; processKeyboard(menu);
while ((event = pollEvent()))
{
switch(event->type)
{
case SDL_KEYUP:
processKeydown(menu, &event->key.keysym);
break;
}
}
if(getStudioMode() != TIC_MENU_MODE) if(getStudioMode() != TIC_MENU_MODE)
return; return;
@ -479,7 +479,7 @@ static void tick(Menu* menu)
menu->init = true; menu->init = true;
} }
SDL_memcpy(menu->tic->ram.vram.screen.data, menu->bg, sizeof menu->tic->ram.vram.screen.data); memcpy(menu->tic->ram.vram.screen.data, menu->bg, sizeof menu->tic->ram.vram.screen.data);
switch(menu->mode) switch(menu->mode)
{ {
@ -525,8 +525,8 @@ void initMenu(Menu* menu, tic_mem* tic, FileSystem* fs)
enum{Size = sizeof tic->ram.vram.screen.data}; enum{Size = sizeof tic->ram.vram.screen.data};
if(!menu->bg) if(!menu->bg)
menu->bg = SDL_malloc(Size); menu->bg = malloc(Size);
if(menu->bg) if(menu->bg)
SDL_memcpy(menu->bg, tic->ram.vram.screen.data, Size); memcpy(menu->bg, tic->ram.vram.screen.data, Size);
} }

View File

@ -46,11 +46,11 @@ struct Menu
s32 selected; s32 selected;
} gamepad; } gamepad;
SDL_Point pos; tic_point pos;
struct struct
{ {
SDL_Point start; tic_point start;
bool active; bool active;
} drag; } drag;

View File

@ -91,19 +91,19 @@ static void drawEditbox(Music* music, s32 x, s32 y, s32 value, void(*set)(Music*
}; };
{ {
SDL_Rect rect = { x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT }; tic_rect rect = { x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT };
bool over = false; bool over = false;
bool down = false; bool down = false;
if (checkMousePos(&rect)) if (checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
over = true; over = true;
if (checkMouseDown(&rect, SDL_BUTTON_LEFT)) if (checkMouseDown(&rect, tic_mouse_left))
down = true; down = true;
if (checkMouseClick(&rect, SDL_BUTTON_LEFT)) if (checkMouseClick(&rect, tic_mouse_left))
set(music, -1, channel); set(music, -1, channel);
} }
@ -113,13 +113,13 @@ static void drawEditbox(Music* music, s32 x, s32 y, s32 value, void(*set)(Music*
{ {
x += TIC_FONT_WIDTH; x += TIC_FONT_WIDTH;
SDL_Rect rect = { x-1, y-1, TIC_FONT_WIDTH*2+1, TIC_FONT_HEIGHT+1 }; tic_rect rect = { x-1, y-1, TIC_FONT_WIDTH*2+1, TIC_FONT_HEIGHT+1 };
if (checkMousePos(&rect)) if (checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
if (checkMouseClick(&rect, SDL_BUTTON_LEFT)) if (checkMouseClick(&rect, tic_mouse_left))
{ {
music->tracker.row = -1; music->tracker.row = -1;
music->tracker.col = channel * CHANNEL_COLS; music->tracker.col = channel * CHANNEL_COLS;
@ -145,19 +145,19 @@ static void drawEditbox(Music* music, s32 x, s32 y, s32 value, void(*set)(Music*
{ {
x += 2*TIC_FONT_WIDTH; x += 2*TIC_FONT_WIDTH;
SDL_Rect rect = { x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT }; tic_rect rect = { x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT };
bool over = false; bool over = false;
bool down = false; bool down = false;
if (checkMousePos(&rect)) if (checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
over = true; over = true;
if (checkMouseDown(&rect, SDL_BUTTON_LEFT)) if (checkMouseDown(&rect, tic_mouse_left))
down = true; down = true;
if (checkMouseClick(&rect, SDL_BUTTON_LEFT)) if (checkMouseClick(&rect, tic_mouse_left))
set(music, +1, channel); set(music, +1, channel);
} }
@ -197,20 +197,20 @@ static void drawSwitch(Music* music, s32 x, s32 y, const char* label, s32 value,
{ {
x += (s32)strlen(label)*TIC_FONT_WIDTH; x += (s32)strlen(label)*TIC_FONT_WIDTH;
SDL_Rect rect = { x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT }; tic_rect rect = { x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT };
bool over = false; bool over = false;
bool down = false; bool down = false;
if (checkMousePos(&rect)) if (checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
over = true; over = true;
if (checkMouseDown(&rect, SDL_BUTTON_LEFT)) if (checkMouseDown(&rect, tic_mouse_left))
down = true; down = true;
if (checkMouseClick(&rect, SDL_BUTTON_LEFT)) if (checkMouseClick(&rect, tic_mouse_left))
set(music, -1, data); set(music, -1, data);
} }
@ -227,20 +227,20 @@ static void drawSwitch(Music* music, s32 x, s32 y, const char* label, s32 value,
{ {
x += (value > 99 ? 3 : 2)*TIC_FONT_WIDTH; x += (value > 99 ? 3 : 2)*TIC_FONT_WIDTH;
SDL_Rect rect = { x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT }; tic_rect rect = { x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT };
bool over = false; bool over = false;
bool down = false; bool down = false;
if (checkMousePos(&rect)) if (checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
over = true; over = true;
if (checkMouseDown(&rect, SDL_BUTTON_LEFT)) if (checkMouseDown(&rect, tic_mouse_left))
down = true; down = true;
if (checkMouseClick(&rect, SDL_BUTTON_LEFT)) if (checkMouseClick(&rect, tic_mouse_left))
set(music, +1, data); set(music, +1, data);
} }
@ -546,8 +546,8 @@ static void stopTrack(Music* music)
static void resetSelection(Music* music) static void resetSelection(Music* music)
{ {
music->tracker.select.start = (SDL_Point){-1, -1}; music->tracker.select.start = (tic_point){-1, -1};
music->tracker.select.rect = (SDL_Rect){0, 0, 0, 0}; music->tracker.select.rect = (tic_rect){0, 0, 0, 0};
} }
static void deleteSelection(Music* music) static void deleteSelection(Music* music)
@ -556,7 +556,7 @@ static void deleteSelection(Music* music)
if(pattern) if(pattern)
{ {
SDL_Rect rect = music->tracker.select.rect; tic_rect rect = music->tracker.select.rect;
if(rect.h <= 0) if(rect.h <= 0)
{ {
@ -565,7 +565,7 @@ static void deleteSelection(Music* music)
} }
enum{RowSize = sizeof(tic_track_pattern) / MUSIC_PATTERN_ROWS}; enum{RowSize = sizeof(tic_track_pattern) / MUSIC_PATTERN_ROWS};
SDL_memset(&pattern->rows[rect.y], 0, RowSize * rect.h); memset(&pattern->rows[rect.y], 0, RowSize * rect.h);
} }
} }
@ -580,7 +580,7 @@ static void copyToClipboard(Music* music, bool cut)
if(pattern) if(pattern)
{ {
SDL_Rect rect = music->tracker.select.rect; tic_rect rect = music->tracker.select.rect;
if(rect.h <= 0) if(rect.h <= 0)
{ {
@ -593,16 +593,16 @@ static void copyToClipboard(Music* music, bool cut)
enum{RowSize = sizeof(tic_track_pattern) / MUSIC_PATTERN_ROWS, HeaderSize = sizeof(ClipboardHeader)}; enum{RowSize = sizeof(tic_track_pattern) / MUSIC_PATTERN_ROWS, HeaderSize = sizeof(ClipboardHeader)};
s32 size = rect.h * RowSize + HeaderSize; s32 size = rect.h * RowSize + HeaderSize;
u8* data = SDL_malloc(size); u8* data = malloc(size);
if(data) if(data)
{ {
SDL_memcpy(data, &header, HeaderSize); memcpy(data, &header, HeaderSize);
SDL_memcpy(data + HeaderSize, &pattern->rows[rect.y], RowSize * rect.h); memcpy(data + HeaderSize, &pattern->rows[rect.y], RowSize * rect.h);
toClipboard(data, size, true); toClipboard(data, size, true);
SDL_free(data); free(data);
if(cut) if(cut)
{ {
@ -619,9 +619,9 @@ static void copyFromClipboard(Music* music)
{ {
tic_track_pattern* pattern = getChannelPattern(music); tic_track_pattern* pattern = getChannelPattern(music);
if(pattern && SDL_HasClipboardText()) if(pattern && getSystem()->hasClipboardText())
{ {
char* clipboard = SDL_GetClipboardText(); char* clipboard = getSystem()->getClipboardText();
if(clipboard) if(clipboard)
{ {
@ -631,27 +631,27 @@ static void copyFromClipboard(Music* music)
if(size > HeaderSize) if(size > HeaderSize)
{ {
u8* data = SDL_malloc(size); u8* data = malloc(size);
str2buf(clipboard, strlen(clipboard), data, true); str2buf(clipboard, strlen(clipboard), data, true);
ClipboardHeader header = {0}; ClipboardHeader header = {0};
SDL_memcpy(&header, data, HeaderSize); memcpy(&header, data, HeaderSize);
if(header.size * RowSize == size - HeaderSize) if(header.size * RowSize == size - HeaderSize)
{ {
if(header.size + music->tracker.row > MUSIC_PATTERN_ROWS) if(header.size + music->tracker.row > MUSIC_PATTERN_ROWS)
header.size = MUSIC_PATTERN_ROWS - music->tracker.row; header.size = MUSIC_PATTERN_ROWS - music->tracker.row;
SDL_memcpy(&pattern->rows[music->tracker.row], data + HeaderSize, header.size * RowSize); memcpy(&pattern->rows[music->tracker.row], data + HeaderSize, header.size * RowSize);
history_add(music->history); history_add(music->history);
} }
SDL_free(data); free(data);
} }
SDL_free(clipboard); free(clipboard);
} }
} }
} }
@ -726,116 +726,117 @@ static void checkSelection(Music* music)
static void updateSelection(Music* music) static void updateSelection(Music* music)
{ {
s32 rl = SDL_min(music->tracker.col, music->tracker.select.start.x); s32 rl = MIN(music->tracker.col, music->tracker.select.start.x);
s32 rt = SDL_min(music->tracker.row, music->tracker.select.start.y); s32 rt = MIN(music->tracker.row, music->tracker.select.start.y);
s32 rr = SDL_max(music->tracker.col, music->tracker.select.start.x); s32 rr = MAX(music->tracker.col, music->tracker.select.start.x);
s32 rb = SDL_max(music->tracker.row, music->tracker.select.start.y); s32 rb = MAX(music->tracker.row, music->tracker.select.start.y);
SDL_Rect* rect = &music->tracker.select.rect; tic_rect* rect = &music->tracker.select.rect;
*rect = (SDL_Rect){rl, rt, rr - rl + 1, rb - rt + 1}; *rect = (tic_rect){rl, rt, rr - rl + 1, rb - rt + 1};
if(rect->x % CHANNEL_COLS + rect->w > CHANNEL_COLS) if(rect->x % CHANNEL_COLS + rect->w > CHANNEL_COLS)
resetSelection(music); resetSelection(music);
} }
static void processTrackerKeydown(Music* music, SDL_Keysym* keysum) static void processTrackerKeyboard(Music* music)
{ {
SDL_Keycode keycode = keysum->sym; tic_mem* tic = music->tic;
SDL_Scancode scancode = keysum->scancode;
bool shift = SDL_GetModState() & KMOD_SHIFT; if(tic->ram.input.keyboard.data == 0)
{
music->tracker.note = -1;
s32 channel = music->tracker.col / CHANNEL_COLS;
music->tic->api.sfx_stop(music->tic, channel);
return;
}
bool shift = tic->api.key(tic, tic_key_shift);
if(shift) if(shift)
{ {
switch (keycode) if(keyWasPressed(tic_key_up)
|| keyWasPressed(tic_key_down)
|| keyWasPressed(tic_key_left)
|| keyWasPressed(tic_key_right)
|| keyWasPressed(tic_key_home)
|| keyWasPressed(tic_key_end)
|| keyWasPressed(tic_key_pageup)
|| keyWasPressed(tic_key_pagedown)
|| keyWasPressed(tic_key_tab))
{ {
case SDLK_UP:
case SDLK_DOWN:
case SDLK_LEFT:
case SDLK_RIGHT:
case SDLK_HOME:
case SDLK_END:
case SDLK_PAGEUP:
case SDLK_PAGEDOWN:
case SDLK_TAB:
checkSelection(music); checkSelection(music);
} }
} }
switch (keycode) if(keyWasPressed(tic_key_up)) upRow(music);
else if(keyWasPressed(tic_key_down)) downRow(music);
else if(keyWasPressed(tic_key_left)) leftCol(music);
else if(keyWasPressed(tic_key_right)) rightCol(music);
else if(keyWasPressed(tic_key_home)) goHome(music);
else if(keyWasPressed(tic_key_end)) goEnd(music);
else if(keyWasPressed(tic_key_pageup)) pageUp(music);
else if(keyWasPressed(tic_key_pagedown)) pageDown(music);
else if(keyWasPressed(tic_key_tab)) doTab(music);
else if(keyWasPressed(tic_key_delete))
{ {
case SDLK_UP: upRow(music); break;
case SDLK_DOWN: downRow(music); break;
case SDLK_LEFT: leftCol(music); break;
case SDLK_RIGHT: rightCol(music); break;
case SDLK_HOME: goHome(music); break;
case SDLK_END: goEnd(music); break;
case SDLK_PAGEUP: pageUp(music); break;
case SDLK_PAGEDOWN: pageDown(music); break;
case SDLK_TAB: doTab(music); break;
case SDLK_DELETE:
deleteSelection(music); deleteSelection(music);
history_add(music->history); history_add(music->history);
downRow(music); downRow(music);
break; }
case SDLK_SPACE: playNote(music); break; else if(keyWasPressed(tic_key_space)) playNote(music);
case SDLK_RETURN: else if(keyWasPressed(tic_key_return))
case SDLK_KP_ENTER: {
{
const tic_music_pos* pos = getMusicPos(music); const tic_music_pos* pos = getMusicPos(music);
pos->track < 0 pos->track < 0
? (shift ? playFrameRow(music) : playFrame(music)) ? (shift ? playFrameRow(music) : playFrame(music))
: stopTrack(music); : stopTrack(music);
}
break;
} }
if(shift) if(shift)
{ {
switch (keycode) if(keyWasPressed(tic_key_up)
|| keyWasPressed(tic_key_down)
|| keyWasPressed(tic_key_left)
|| keyWasPressed(tic_key_right)
|| keyWasPressed(tic_key_home)
|| keyWasPressed(tic_key_end)
|| keyWasPressed(tic_key_pageup)
|| keyWasPressed(tic_key_pagedown)
|| keyWasPressed(tic_key_tab))
{ {
case SDLK_UP:
case SDLK_DOWN:
case SDLK_LEFT:
case SDLK_RIGHT:
case SDLK_HOME:
case SDLK_END:
case SDLK_PAGEUP:
case SDLK_PAGEDOWN:
case SDLK_TAB:
updateSelection(music); updateSelection(music);
} }
} }
else resetSelection(music); else resetSelection(music);
static const SDL_Scancode Piano[] = static const tic_keycode Piano[] =
{ {
SDL_SCANCODE_Z, tic_key_z,
SDL_SCANCODE_S, tic_key_s,
SDL_SCANCODE_X, tic_key_x,
SDL_SCANCODE_D, tic_key_d,
SDL_SCANCODE_C, tic_key_c,
SDL_SCANCODE_V, tic_key_v,
SDL_SCANCODE_G, tic_key_g,
SDL_SCANCODE_B, tic_key_b,
SDL_SCANCODE_H, tic_key_h,
SDL_SCANCODE_N, tic_key_n,
SDL_SCANCODE_J, tic_key_j,
SDL_SCANCODE_M, tic_key_m,
// octave +1 // octave +1
SDL_SCANCODE_Q, tic_key_q,
SDL_SCANCODE_2, tic_key_2,
SDL_SCANCODE_W, tic_key_w,
SDL_SCANCODE_3, tic_key_3,
SDL_SCANCODE_E, tic_key_e,
SDL_SCANCODE_R, tic_key_r,
SDL_SCANCODE_5, tic_key_5,
SDL_SCANCODE_T, tic_key_t,
SDL_SCANCODE_6, tic_key_6,
SDL_SCANCODE_Y, tic_key_y,
SDL_SCANCODE_7, tic_key_7,
SDL_SCANCODE_U, tic_key_u,
}; };
if (getChannelPattern(music)) if (getChannelPattern(music))
@ -846,7 +847,7 @@ static void processTrackerKeydown(Music* music, SDL_Keysym* keysum)
{ {
case ColumnNote: case ColumnNote:
case ColumnSemitone: case ColumnSemitone:
if (scancode == SDL_SCANCODE_1 || scancode == SDL_SCANCODE_A) if (keyWasPressed(tic_key_1) || keyWasPressed(tic_key_a))
{ {
setStopNote(music); setStopNote(music);
downRow(music); downRow(music);
@ -857,7 +858,7 @@ static void processTrackerKeydown(Music* music, SDL_Keysym* keysum)
for (s32 i = 0; i < COUNT_OF(Piano); i++) for (s32 i = 0; i < COUNT_OF(Piano); i++)
{ {
if (scancode == Piano[i]) if (keyWasPressed(Piano[i]))
{ {
s32 note = i % NOTES; s32 note = i % NOTES;
@ -877,8 +878,7 @@ static void processTrackerKeydown(Music* music, SDL_Keysym* keysum)
downRow(music); downRow(music);
break; break;
} }
} }
} }
break; break;
@ -886,8 +886,10 @@ static void processTrackerKeydown(Music* music, SDL_Keysym* keysum)
if(getNote(music) >= 0) if(getNote(music) >= 0)
{ {
s32 octave = -1; s32 octave = -1;
if (keycode >= SDLK_1 && keycode <= SDLK_8) octave = keycode - SDLK_1;
if (keycode >= SDLK_KP_1 && keycode <= SDLK_KP_8) octave = keycode - SDLK_KP_1; char sym = getKeyboardText();
if(sym >= '1' && sym <= '8') octave = sym - '1';
if(octave >= 0) if(octave >= 0)
{ {
@ -901,10 +903,10 @@ static void processTrackerKeydown(Music* music, SDL_Keysym* keysum)
if(getNote(music) >= 0) if(getNote(music) >= 0)
{ {
s32 val = -1; s32 val = -1;
char sym = getKeyboardText();
if (keycode >= SDLK_0 && keycode <= SDLK_9) val = keycode - SDLK_0; if (sym >= '0' && sym <= '9') val = sym - '0';
if (keycode >= SDLK_KP_1 && keycode <= SDLK_KP_9) val = keycode - SDLK_KP_1 + 1;
if (keycode == SDLK_KP_0) val = 0;
if(val >= 0) if(val >= 0)
{ {
@ -927,10 +929,10 @@ static void processTrackerKeydown(Music* music, SDL_Keysym* keysum)
{ {
s32 val = -1; s32 val = -1;
if(keycode >= SDLK_0 && keycode <= SDLK_9) val = keycode - SDLK_0; char sym = getKeyboardText();
if(keycode >= SDLK_a && keycode <= SDLK_f) val = keycode - SDLK_a + 10;
if(keycode >= SDLK_KP_1 && keycode <= SDLK_KP_9) val = keycode - SDLK_KP_1 + 1; if(sym >= '0' && sym <= '9') val = sym - '0';
if(keycode == SDLK_KP_0) val = 0; if(sym >= 'a' && sym <= 'f') val = sym - 'a' + 10;
if(val >= 0) if(val >= 0)
{ {
@ -945,46 +947,40 @@ static void processTrackerKeydown(Music* music, SDL_Keysym* keysum)
} }
} }
static void processPatternKeydown(Music* music, SDL_Keysym* keysum) static void processPatternKeyboard(Music* music)
{ {
SDL_Keycode keycode = keysum->sym;
s32 channel = music->tracker.col / CHANNEL_COLS; s32 channel = music->tracker.col / CHANNEL_COLS;
switch (keycode) if(keyWasPressed(tic_key_delete)) setChannelPatternValue(music, 0, channel);
else if(keyWasPressed(tic_key_tab)) nextPattern(music);
else if(keyWasPressed(tic_key_left)) patternColLeft(music);
else if(keyWasPressed(tic_key_right)) patternColRight(music);
else if(keyWasPressed(tic_key_down)
|| keyWasPressed(tic_key_return))
music->tracker.row = music->tracker.scroll;
else
{ {
case SDLK_DELETE: setChannelPatternValue(music, 0, channel); break; s32 val = -1;
case SDLK_TAB: nextPattern(music); break;
case SDLK_DOWN: char sym = getKeyboardText();
case SDLK_KP_ENTER:
case SDLK_RETURN: music->tracker.row = music->tracker.scroll; break; if(sym >= '0' && sym <= '9') val = sym - '0';
case SDLK_LEFT: patternColLeft(music); break;
case SDLK_RIGHT: patternColRight(music); break; if(val >= 0)
default:
{ {
s32 val = -1; enum {Base = 10};
s32 patternId = tic_tool_get_pattern_id(getTrack(music), music->tracker.frame, channel);
if(keycode >= SDLK_0 && keycode <= SDLK_9) val = keycode - SDLK_0; patternId = music->tracker.patternCol == 0
if(keycode >= SDLK_KP_1 && keycode <= SDLK_KP_9) val = keycode - SDLK_KP_1 + 1; ? val * Base + patternId % Base
if(keycode == SDLK_KP_0) val = 0; : patternId / Base * Base + val % Base;
if(patternId <= MUSIC_PATTERNS)
if(val >= 0)
{ {
enum {Base = 10}; setChannelPatternValue(music, patternId, channel);
s32 patternId = tic_tool_get_pattern_id(getTrack(music), music->tracker.frame, channel);
patternId = music->tracker.patternCol == 0 if(music->tracker.patternCol == 0)
? val * Base + patternId % Base patternColRight(music);
: patternId / Base * Base + val % Base;
if(patternId <= MUSIC_PATTERNS)
{
setChannelPatternValue(music, patternId, channel);
if(music->tracker.patternCol == 0)
patternColRight(music);
}
} }
} }
} }
@ -996,18 +992,20 @@ static void selectAll(Music* music)
s32 col = music->tracker.col - music->tracker.col % CHANNEL_COLS; s32 col = music->tracker.col - music->tracker.col % CHANNEL_COLS;
music->tracker.select.start = (SDL_Point){col, 0}; music->tracker.select.start = (tic_point){col, 0};
music->tracker.col = col + CHANNEL_COLS-1; music->tracker.col = col + CHANNEL_COLS-1;
music->tracker.row = MUSIC_PATTERN_ROWS-1; music->tracker.row = MUSIC_PATTERN_ROWS-1;
updateSelection(music); updateSelection(music);
} }
static void processKeydown(Music* music, SDL_Keysym* keysum) static void processKeyboard(Music* music)
{ {
SDL_Keycode keycode = keysum->sym; tic_mem* tic = music->tic;
switch(getClipboardEvent(keycode)) if(tic->ram.input.keyboard.data == 0) return;
switch(getClipboardEvent())
{ {
case TIC_CLIPBOARD_CUT: copyToClipboard(music, true); break; case TIC_CLIPBOARD_CUT: copyToClipboard(music, true); break;
case TIC_CLIPBOARD_COPY: copyToClipboard(music, false); break; case TIC_CLIPBOARD_COPY: copyToClipboard(music, false); break;
@ -1015,34 +1013,24 @@ static void processKeydown(Music* music, SDL_Keysym* keysum)
default: break; default: break;
} }
SDL_Keymod keymod = SDL_GetModState(); bool ctrl = tic->api.key(tic, tic_key_ctrl);
if (keymod & TIC_MOD_CTRL) if (ctrl)
{ {
switch (keycode) if(keyWasPressed(tic_key_a)) selectAll(music);
{ else if(keyWasPressed(tic_key_z)) undo(music);
case SDLK_a: selectAll(music); break; else if(keyWasPressed(tic_key_y)) redo(music);
case SDLK_z: undo(music); break; else if(keyWasPressed(tic_key_up)) upFrame(music);
case SDLK_y: redo(music); break; else if(keyWasPressed(tic_key_down)) downFrame(music);
case SDLK_UP: upFrame(music); break;
case SDLK_DOWN: downFrame(music); break;
}
} }
else else
{ {
music->tracker.row >= 0 music->tracker.row >= 0
? processTrackerKeydown(music, keysum) ? processTrackerKeyboard(music)
: processPatternKeydown(music, keysum); : processPatternKeyboard(music);
} }
} }
static void processKeyup(Music* music, SDL_Keysym* keysum)
{
music->tracker.note = -1;
s32 channel = music->tracker.col / CHANNEL_COLS;
music->tic->api.sfx_stop(music->tic, channel);
}
static void setIndex(Music* music, s32 delta, void* data) static void setIndex(Music* music, s32 delta, void* data)
{ {
music->track += delta; music->track += delta;
@ -1134,13 +1122,13 @@ static void drawTrackerFrames(Music* music, s32 x, s32 y)
}; };
{ {
SDL_Rect rect = { x - Border, y - Border, Width, MUSIC_FRAMES * TIC_FONT_HEIGHT + Border }; tic_rect rect = { x - Border, y - Border, Width, MUSIC_FRAMES * TIC_FONT_HEIGHT + Border };
if (checkMousePos(&rect)) if (checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
if (checkMouseDown(&rect, SDL_BUTTON_LEFT)) if (checkMouseDown(&rect, tic_mouse_left))
{ {
s32 my = getMouseY() - rect.y - Border; s32 my = getMouseY() - rect.y - Border;
music->tracker.frame = my / TIC_FONT_HEIGHT; music->tracker.frame = my / TIC_FONT_HEIGHT;
@ -1216,13 +1204,13 @@ static void drawTrackerChannel(Music* music, s32 x, s32 y, s32 channel)
Width = TIC_FONT_WIDTH * 8 + Border, Width = TIC_FONT_WIDTH * 8 + Border,
}; };
SDL_Rect rect = {x - Border, y - Border, Width, Rows*TIC_FONT_HEIGHT + Border}; tic_rect rect = {x - Border, y - Border, Width, Rows*TIC_FONT_HEIGHT + Border};
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
if(checkMouseDown(&rect, SDL_BUTTON_LEFT)) if(checkMouseDown(&rect, tic_mouse_left))
{ {
s32 mx = getMouseX() - rect.x - Border; s32 mx = getMouseX() - rect.x - Border;
s32 my = getMouseY() - rect.y - Border; s32 my = getMouseY() - rect.y - Border;
@ -1237,7 +1225,7 @@ static void drawTrackerChannel(Music* music, s32 x, s32 y, s32 channel)
else else
{ {
resetSelection(music); resetSelection(music);
music->tracker.select.start = (SDL_Point){col, row}; music->tracker.select.start = (tic_point){col, row};
music->tracker.select.drag = true; music->tracker.select.drag = true;
} }
@ -1246,8 +1234,8 @@ static void drawTrackerChannel(Music* music, s32 x, s32 y, s32 channel)
if(music->tracker.select.drag) if(music->tracker.select.drag)
{ {
SDL_Rect rect = {0, 0, TIC80_WIDTH, TIC80_HEIGHT}; tic_rect rect = {0, 0, TIC80_WIDTH, TIC80_HEIGHT};
if(!checkMouseDown(&rect, SDL_BUTTON_LEFT)) if(!checkMouseDown(&rect, tic_mouse_left))
{ {
music->tracker.select.drag = false; music->tracker.select.drag = false;
} }
@ -1274,7 +1262,7 @@ static void drawTrackerChannel(Music* music, s32 x, s32 y, s32 channel)
// draw selection // draw selection
if (selectedChannel) if (selectedChannel)
{ {
SDL_Rect rect = music->tracker.select.rect; tic_rect rect = music->tracker.select.rect;
if (rect.h > 1 && i >= rect.y && i < rect.y + rect.h) if (rect.h > 1 && i >= rect.y && i < rect.y + rect.h)
{ {
s32 sx = x - 1; s32 sx = x - 1;
@ -1346,22 +1334,22 @@ static void drawTumbler(Music* music, s32 x, s32 y, s32 index)
enum{On=36, Off = 52, Size=5, Chroma=14}; enum{On=36, Off = 52, Size=5, Chroma=14};
SDL_Rect rect = {x, y, Size, Size}; tic_rect rect = {x, y, Size, Size};
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
showTooltip("on/off channel"); showTooltip("on/off channel");
if(checkMouseClick(&rect, SDL_BUTTON_LEFT)) if(checkMouseClick(&rect, tic_mouse_left))
{ {
if (SDL_GetModState() & KMOD_CTRL) // if (SDL_GetModState() & KMOD_CTRL)
{ // {
for (s32 i = 0; i < TIC_SOUND_CHANNELS; i++) // for (s32 i = 0; i < TIC_SOUND_CHANNELS; i++)
music->tracker.patterns[i] = i == index; // music->tracker.patterns[i] = i == index;
} // }
else music->tracker.patterns[index] = !music->tracker.patterns[index]; // else music->tracker.patterns[index] = !music->tracker.patterns[index];
} }
} }
@ -1438,13 +1426,13 @@ static void drawPlayButtons(Music* music)
for (s32 i = 0; i < Count; i++) for (s32 i = 0; i < Count; i++)
{ {
SDL_Rect rect = { Offset + Width * i, 0, Width, Height }; tic_rect rect = { Offset + Width * i, 0, Width, Height };
bool over = false; bool over = false;
if (checkMousePos(&rect)) if (checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
over = true; over = true;
static const char* Tooltips[] = { "RECORD MUSIC", "PLAY FRAME [enter]", "PLAY TRACK", "STOP [enter]" }; static const char* Tooltips[] = { "RECORD MUSIC", "PLAY FRAME [enter]", "PLAY TRACK", "STOP [enter]" };
@ -1452,7 +1440,7 @@ static void drawPlayButtons(Music* music)
static void(*const Handlers[])(Music*) = { enableFollowMode, playFrame, playTrack, stopTrack }; static void(*const Handlers[])(Music*) = { enableFollowMode, playFrame, playTrack, stopTrack };
if (checkMouseClick(&rect, SDL_BUTTON_LEFT)) if (checkMouseClick(&rect, tic_mouse_left))
Handlers[i](music); Handlers[i](music);
} }
@ -1490,7 +1478,7 @@ static void drawModeTabs(Music* music)
for (s32 i = 0; i < Count; i++) for (s32 i = 0; i < Count; i++)
{ {
SDL_Rect rect = { TIC80_WIDTH - Width * (Count - i), 0, Width, Height }; tic_rect rect = { TIC80_WIDTH - Width * (Count - i), 0, Width, Height };
static const s32 Tabs[] = { MUSIC_PIANO_TAB, MUSIC_TRACKER_TAB }; static const s32 Tabs[] = { MUSIC_PIANO_TAB, MUSIC_TRACKER_TAB };
@ -1499,13 +1487,13 @@ static void drawModeTabs(Music* music)
if (checkMousePos(&rect)) if (checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
over = true; over = true;
static const char* Tooltips[] = { "PIANO MODE", "TRACKER MODE" }; static const char* Tooltips[] = { "PIANO MODE", "TRACKER MODE" };
showTooltip(Tooltips[i]); showTooltip(Tooltips[i]);
if (checkMouseClick(&rect, SDL_BUTTON_LEFT)) if (checkMouseClick(&rect, tic_mouse_left))
music->tab = Tabs[i]; music->tab = Tabs[i];
} }
@ -1529,9 +1517,6 @@ static void drawMusicToolbar(Music* music)
static void drawPianoLayout(Music* music) static void drawPianoLayout(Music* music)
{ {
SDL_Event* event = NULL;
while ((event = pollEvent())){}
music->tic->api.clear(music->tic, (tic_color_gray)); music->tic->api.clear(music->tic, (tic_color_gray));
static const char Wip[] = "PIANO MODE - WORK IN PROGRESS..."; static const char Wip[] = "PIANO MODE - WORK IN PROGRESS...";
@ -1544,7 +1529,7 @@ static void scrollNotes(Music* music, s32 delta)
if(pattern) if(pattern)
{ {
SDL_Rect rect = music->tracker.select.rect; tic_rect rect = music->tracker.select.rect;
if(rect.h <= 0) if(rect.h <= 0)
{ {
@ -1571,35 +1556,32 @@ static void scrollNotes(Music* music, s32 delta)
static void drawTrackerLayout(Music* music) static void drawTrackerLayout(Music* music)
{ {
SDL_Event* event = NULL; tic_mem* tic = music->tic;
while ((event = pollEvent()))
// process scroll
{ {
switch (event->type) tic80_input* input = &tic->ram.input;
if(input->mouse.scrolly)
{ {
case SDL_MOUSEWHEEL: if(tic->api.key(tic, tic_key_ctrl))
if(SDL_GetModState() & TIC_MOD_CTRL)
{ {
scrollNotes(music, event->wheel.y > 0 ? 1 : -1); scrollNotes(music, input->mouse.scrolly > 0 ? 1 : -1);
} }
else else
{ {
enum{Scroll = NOTES_PER_BEET}; enum{Scroll = NOTES_PER_BEET};
s32 delta = event->wheel.y > 0 ? -Scroll : Scroll; s32 delta = input->mouse.scrolly > 0 ? -Scroll : Scroll;
music->tracker.scroll += delta; music->tracker.scroll += delta;
updateScroll(music); updateScroll(music);
} }
break;
case SDL_KEYDOWN:
processKeydown(music, &event->key.keysym);
break;
case SDL_KEYUP:
processKeyup(music, &event->key.keysym);
break;
} }
} }
processKeyboard(music);
if(music->tracker.follow) if(music->tracker.follow)
{ {
const tic_music_pos* pos = getMusicPos(music); const tic_music_pos* pos = getMusicPos(music);

View File

@ -54,8 +54,8 @@ struct Music
struct struct
{ {
SDL_Point start; tic_point start;
SDL_Rect rect; tic_rect rect;
bool drag; bool drag;
} select; } select;

188
src/net.c
View File

@ -24,9 +24,8 @@
#include "tic.h" #include "tic.h"
#include "SDL_net.h" #include "SDL_net.h"
#include <lua.h> #include <stdlib.h>
#include <lauxlib.h> #include <stdio.h>
#include <lualib.h>
struct Net struct Net
{ {
@ -53,7 +52,7 @@ static void getRequest(Net* net, const char* path, NetResponse callback, void* d
static void netClearCache(Net* net) static void netClearCache(Net* net)
{ {
if(net->cache.buffer) if(net->cache.buffer)
SDL_free(net->cache.buffer); free(net->cache.buffer);
net->cache.buffer = NULL; net->cache.buffer = NULL;
net->cache.size = 0; net->cache.size = 0;
@ -95,7 +94,7 @@ static Buffer httpRequest(const char* path, s32 timeout)
if(SDLNet_CheckSockets(set, timeout) == 1 && SDLNet_SocketReady(sock)) if(SDLNet_CheckSockets(set, timeout) == 1 && SDLNet_SocketReady(sock))
{ {
enum {Size = 4*1024+1}; enum {Size = 4*1024+1};
buffer.data = SDL_malloc(Size); buffer.data = malloc(Size);
s32 size = 0; s32 size = 0;
for(;;) for(;;)
@ -105,7 +104,7 @@ static Buffer httpRequest(const char* path, s32 timeout)
if(size > 0) if(size > 0)
{ {
buffer.size += size; buffer.size += size;
buffer.data = SDL_realloc(buffer.data, buffer.size + Size); buffer.data = realloc(buffer.data, buffer.size + Size);
} }
else break; else break;
} }
@ -141,34 +140,34 @@ static void getRequest(Net* net, const char* path, NetResponse callback, void* d
if(buffer.data && buffer.size) if(buffer.data && buffer.size)
{ {
if(SDL_strstr((char*)buffer.data, "200 OK")) if(strstr((char*)buffer.data, "200 OK"))
{ {
s32 contentLength = 0; s32 contentLength = 0;
{ {
static const char ContentLength[] = "Content-Length:"; static const char ContentLength[] = "Content-Length:";
char* start = SDL_strstr((char*)buffer.data, ContentLength); char* start = strstr((char*)buffer.data, ContentLength);
if(start) if(start)
contentLength = SDL_atoi(start + sizeof(ContentLength)); contentLength = atoi(start + sizeof(ContentLength));
} }
static const char Start[] = "\r\n\r\n"; static const char Start[] = "\r\n\r\n";
u8* start = (u8*)SDL_strstr((char*)buffer.data, Start); u8* start = (u8*)strstr((char*)buffer.data, Start);
if(start) if(start)
{ {
strcpy(net->cache.path, path); strcpy(net->cache.path, path);
net->cache.size = contentLength ? contentLength : buffer.size - (s32)(start - buffer.data); net->cache.size = contentLength ? contentLength : buffer.size - (s32)(start - buffer.data);
net->cache.buffer = (u8*)SDL_malloc(net->cache.size); net->cache.buffer = (u8*)malloc(net->cache.size);
SDL_memcpy(net->cache.buffer, start + sizeof Start - 1, net->cache.size); memcpy(net->cache.buffer, start + sizeof Start - 1, net->cache.size);
callback(net->cache.buffer, net->cache.size, data); callback(net->cache.buffer, net->cache.size, data);
done = true; done = true;
} }
} }
SDL_free(buffer.data); free(buffer.data);
} }
if(!done) if(!done)
@ -178,124 +177,6 @@ static void getRequest(Net* net, const char* path, NetResponse callback, void* d
#endif #endif
static lua_State* netLuaInit(u8* buffer, s32 size)
{
if (buffer && size)
{
lua_State* lua = luaL_newstate();
if(lua)
{
if(luaL_loadstring(lua, (char*)buffer) == LUA_OK && lua_pcall(lua, 0, LUA_MULTRET, 0) == LUA_OK)
return lua;
else lua_close(lua);
}
}
return NULL;
}
typedef struct
{
ListCallback callback;
void* data;
} NetDirData;
static void onDirResponse(u8* buffer, s32 size, void* data)
{
NetDirData* netDirData = (NetDirData*)data;
lua_State* lua = netLuaInit(buffer, size);
if(lua)
{
{
lua_getglobal(lua, "folders");
if(lua_type(lua, -1) == LUA_TTABLE)
{
s32 count = (s32)lua_rawlen(lua, -1);
for(s32 i = 1; i <= count; i++)
{
lua_geti(lua, -1, i);
{
lua_getfield(lua, -1, "name");
if(lua_isstring(lua, -1))
netDirData->callback(lua_tostring(lua, -1), NULL, 0, netDirData->data, true);
lua_pop(lua, 1);
}
lua_pop(lua, 1);
}
}
lua_pop(lua, 1);
}
{
lua_getglobal(lua, "files");
if(lua_type(lua, -1) == LUA_TTABLE)
{
s32 count = (s32)lua_rawlen(lua, -1);
for(s32 i = 1; i <= count; i++)
{
lua_geti(lua, -1, i);
char hash[FILENAME_MAX] = {0};
char name[FILENAME_MAX] = {0};
{
lua_getfield(lua, -1, "hash");
if(lua_isstring(lua, -1))
strcpy(hash, lua_tostring(lua, -1));
lua_pop(lua, 1);
}
{
lua_getfield(lua, -1, "name");
if(lua_isstring(lua, -1))
strcpy(name, lua_tostring(lua, -1));
lua_pop(lua, 1);
}
{
lua_getfield(lua, -1, "id");
if(lua_isinteger(lua, -1))
netDirData->callback(name, hash, lua_tointeger(lua, -1), netDirData->data, false);
lua_pop(lua, 1);
}
lua_pop(lua, 1);
}
}
lua_pop(lua, 1);
}
lua_close(lua);
}
}
void netDirRequest(Net* net, const char* path, ListCallback callback, void* data)
{
char request[FILENAME_MAX] = {'\0'};
sprintf(request, "/api?fn=dir&path=%s", path);
NetDirData netDirData = {callback, data};
getRequest(net, request, onDirResponse, &netDirData);
}
typedef struct typedef struct
{ {
void* buffer; void* buffer;
@ -306,9 +187,9 @@ static void onGetResponse(u8* buffer, s32 size, void* data)
{ {
NetGetData* netGetData = (NetGetData*)data; NetGetData* netGetData = (NetGetData*)data;
netGetData->buffer = SDL_malloc(size); netGetData->buffer = malloc(size);
*netGetData->size = size; *netGetData->size = size;
SDL_memcpy(netGetData->buffer, buffer, size); memcpy(netGetData->buffer, buffer, size);
} }
void* netGetRequest(Net* net, const char* path, s32* size) void* netGetRequest(Net* net, const char* path, s32* size)
@ -319,48 +200,11 @@ void* netGetRequest(Net* net, const char* path, s32* size)
return netGetData.buffer; return netGetData.buffer;
} }
NetVersion netVersionRequest(Net* net)
{
NetVersion version =
{
.major = TIC_VERSION_MAJOR,
.minor = TIC_VERSION_MINOR,
.patch = TIC_VERSION_PATCH,
};
s32 size = 0;
void* buffer = netGetRequest(net, "/api?fn=version", &size);
if(buffer && size)
{
lua_State* lua = netLuaInit(buffer, size);
if(lua)
{
static const char* Fields[] = {"major", "minor", "patch"};
for(s32 i = 0; i < COUNT_OF(Fields); i++)
{
lua_getglobal(lua, Fields[i]);
if(lua_isinteger(lua, -1))
((s32*)&version)[i] = (s32)lua_tointeger(lua, -1);
lua_pop(lua, 1);
}
lua_close(lua);
}
}
return version;
}
Net* createNet() Net* createNet()
{ {
SDLNet_Init(); SDLNet_Init();
Net* net = (Net*)SDL_malloc(sizeof(Net)); Net* net = (Net*)malloc(sizeof(Net));
*net = (Net) *net = (Net)
{ {
@ -377,7 +221,7 @@ Net* createNet()
void closeNet(Net* net) void closeNet(Net* net)
{ {
SDL_free(net); free(net);
SDLNet_Quit(); SDLNet_Quit();
} }

View File

@ -26,16 +26,6 @@
typedef struct Net Net; typedef struct Net Net;
typedef struct
{
s32 major;
s32 minor;
s32 patch;
} NetVersion;
NetVersion netVersionRequest(Net* net);
void netDirRequest(Net* net, const char* path, ListCallback callback, void* data);
void* netGetRequest(Net* net, const char* path, s32* size);
Net* createNet(); Net* createNet();
void* netGetRequest(Net* net, const char* path, s32* size);
void closeNet(Net* net); void closeNet(Net* net);

View File

@ -86,8 +86,6 @@ static void initPMemName(Run* run)
static void tick(Run* run) static void tick(Run* run)
{ {
while(pollEvent());
if (getStudioMode() != TIC_RUN_MODE) if (getStudioMode() != TIC_RUN_MODE)
return; return;
@ -95,10 +93,11 @@ static void tick(Run* run)
enum {Size = sizeof(tic_persistent)}; enum {Size = sizeof(tic_persistent)};
if(SDL_memcmp(&run->tic->persistent, &run->persistent, Size) != 0) if(run->tickData.syncPMEM)
{ {
fsSaveRootFile(run->console->fs, run->saveid, &run->tic->persistent, Size, true); fsSaveRootFile(run->console->fs, run->saveid, &run->tic->persistent, Size, true);
SDL_memcpy(&run->persistent, &run->tic->persistent, Size); memcpy(&run->persistent, &run->tic->persistent, Size);
run->tickData.syncPMEM = false;
} }
if(run->exit) if(run->exit)
@ -139,7 +138,7 @@ static void processDoFile(void* data, char* dst)
return; return;
} }
else SDL_memcpy(dst, buffer, size); else memcpy(dst, buffer, size);
} }
} }
else else
@ -156,22 +155,14 @@ static void processDoFile(void* data, char* dst)
return; return;
} }
static void preseed()
{
#if defined(__MACOSX__)
srandom(time(NULL));
random();
#else
srand(time(NULL));
rand();
#endif
}
static bool forceExit(void* data) static bool forceExit(void* data)
{ {
while(pollEvent()); getSystem()->poll();
return getStudioMode() != TIC_RUN_MODE; tic_mem* tic = ((Run*)data)->tic;
return tic->api.key(tic, tic_key_escape);
} }
void initRun(Run* run, Console* console, tic_mem* tic) void initRun(Run* run, Console* console, tic_mem* tic)
@ -186,19 +177,20 @@ void initRun(Run* run, Console* console, tic_mem* tic)
{ {
.error = onError, .error = onError,
.trace = onTrace, .trace = onTrace,
.counter = SDL_GetPerformanceCounter, .counter = getSystem()->getPerformanceCounter,
.freq = SDL_GetPerformanceFrequency, .freq = getSystem()->getPerformanceFrequency,
.start = 0, .start = 0,
.data = run, .data = run,
.exit = onExit, .exit = onExit,
.preprocessor = processDoFile, .preprocessor = processDoFile,
.forceExit = forceExit, .forceExit = forceExit,
.syncPMEM = false,
}, },
}; };
{ {
enum {Size = sizeof(tic_persistent)}; enum {Size = sizeof(tic_persistent)};
SDL_memset(&run->tic->persistent, 0, Size); memset(&run->tic->persistent, 0, Size);
initPMemName(run); initPMemName(run);
@ -209,12 +201,12 @@ void initRun(Run* run, Console* console, tic_mem* tic)
if(data) if(data)
{ {
SDL_memcpy(&run->tic->persistent, data, size); memcpy(&run->tic->persistent, data, size);
SDL_memcpy(&run->persistent, data, size); memcpy(&run->persistent, data, size);
} }
if(data) SDL_free(data); if(data) free(data);
} }
preseed(); getSystem()->preseed();
} }

223
src/sfx.c
View File

@ -68,13 +68,13 @@ static void drawSwitch(Sfx* sfx, s32 x, s32 y, const char* label, s32 value, voi
{ {
x += (s32)strlen(label)*TIC_FONT_WIDTH; x += (s32)strlen(label)*TIC_FONT_WIDTH;
SDL_Rect rect = {x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT}; tic_rect rect = {x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT};
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
if(checkMouseClick(&rect, SDL_BUTTON_LEFT)) if(checkMouseClick(&rect, tic_mouse_left))
set(sfx, -1); set(sfx, -1);
} }
@ -90,13 +90,13 @@ static void drawSwitch(Sfx* sfx, s32 x, s32 y, const char* label, s32 value, voi
{ {
x += 2*TIC_FONT_WIDTH; x += 2*TIC_FONT_WIDTH;
SDL_Rect rect = {x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT}; tic_rect rect = {x, y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT};
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
if(checkMouseClick(&rect, SDL_BUTTON_LEFT)) if(checkMouseClick(&rect, tic_mouse_left))
set(sfx, +1); set(sfx, +1);
} }
@ -207,16 +207,16 @@ static void drawWaveButtons(Sfx* sfx, s32 x, s32 y)
for(s32 i = 0; i < Count; i++) for(s32 i = 0; i < Count; i++)
{ {
SDL_Rect rect = {x, y + (Count - i - 1)*(Height+Gap), Width, Height}; tic_rect rect = {x, y + (Count - i - 1)*(Height+Gap), Width, Height};
bool over = false; bool over = false;
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
over = true; over = true;
if(checkMouseClick(&rect, SDL_BUTTON_LEFT)) if(checkMouseClick(&rect, tic_mouse_left))
{ {
sfx->waveform.index = i; sfx->waveform.index = i;
sfx->tab = SFX_WAVEFORM_TAB; sfx->tab = SFX_WAVEFORM_TAB;
@ -238,15 +238,15 @@ static void drawWaveButtons(Sfx* sfx, s32 x, s32 y)
{ {
enum{Size = 5}; enum{Size = 5};
SDL_Rect iconRect = {x+Width+HGap, y + (Count - i - 1)*(Height+Gap), Size, Size}; tic_rect iconRect = {x+Width+HGap, y + (Count - i - 1)*(Height+Gap), Size, Size};
bool over = false; bool over = false;
if(checkMousePos(&iconRect)) if(checkMousePos(&iconRect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
over = true; over = true;
if(checkMouseClick(&iconRect, SDL_BUTTON_LEFT)) if(checkMouseClick(&iconRect, tic_mouse_left))
{ {
tic_sample* effect = getEffect(sfx); tic_sample* effect = getEffect(sfx);
for(s32 c = 0; c < SFX_TICKS; c++) for(s32 c = 0; c < SFX_TICKS; c++)
@ -295,13 +295,13 @@ static void drawCanvasTabs(Sfx* sfx, s32 x, s32 y)
{ {
s32 size = sfx->tic->api.text(sfx->tic, Labels[i], 0, -TIC_FONT_HEIGHT, (tic_color_black)); s32 size = sfx->tic->api.text(sfx->tic, Labels[i], 0, -TIC_FONT_HEIGHT, (tic_color_black));
SDL_Rect rect = {x - size, sy, size, TIC_FONT_HEIGHT}; tic_rect rect = {x - size, sy, size, TIC_FONT_HEIGHT};
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
if(checkMouseClick(&rect, SDL_BUTTON_LEFT)) if(checkMouseClick(&rect, tic_mouse_left))
{ {
sfx->canvasTab = i; sfx->canvasTab = i;
} }
@ -318,13 +318,13 @@ static void drawCanvasTabs(Sfx* sfx, s32 x, s32 y)
{ {
static const char Label[] = "x16"; static const char Label[] = "x16";
enum{Width = (sizeof Label - 1) * TIC_FONT_WIDTH}; enum{Width = (sizeof Label - 1) * TIC_FONT_WIDTH};
SDL_Rect rect = {(x - Width)/2, y + Height * 6, Width, TIC_FONT_HEIGHT}; tic_rect rect = {(x - Width)/2, y + Height * 6, Width, TIC_FONT_HEIGHT};
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
if(checkMouseClick(&rect, SDL_BUTTON_LEFT)) if(checkMouseClick(&rect, tic_mouse_left))
effect->pitch16x++; effect->pitch16x++;
} }
@ -335,13 +335,13 @@ static void drawCanvasTabs(Sfx* sfx, s32 x, s32 y)
{ {
static const char Label[] = "DOWN"; static const char Label[] = "DOWN";
enum{Width = (sizeof Label - 1) * TIC_FONT_WIDTH}; enum{Width = (sizeof Label - 1) * TIC_FONT_WIDTH};
SDL_Rect rect = {(x - Width)/2, y + Height * 6, Width, TIC_FONT_HEIGHT}; tic_rect rect = {(x - Width)/2, y + Height * 6, Width, TIC_FONT_HEIGHT};
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
if(checkMouseClick(&rect, SDL_BUTTON_LEFT)) if(checkMouseClick(&rect, tic_mouse_left))
effect->reverse++; effect->reverse++;
} }
@ -370,13 +370,13 @@ static void drawCanvas(Sfx* sfx, s32 x, s32 y)
sfx->tic->api.rect(sfx->tic, x + tickIndex * CANVAS_SIZE, y, CANVAS_SIZE + 1, CANVAS_HEIGHT + 1, (tic_color_white)); sfx->tic->api.rect(sfx->tic, x + tickIndex * CANVAS_SIZE, y, CANVAS_SIZE + 1, CANVAS_HEIGHT + 1, (tic_color_white));
} }
SDL_Rect rect = {x, y, CANVAS_WIDTH, CANVAS_HEIGHT}; tic_rect rect = {x, y, CANVAS_WIDTH, CANVAS_HEIGHT};
tic_sample* effect = getEffect(sfx); tic_sample* effect = getEffect(sfx);
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
s32 mx = getMouseX() - x; s32 mx = getMouseX() - x;
s32 my = getMouseY() - y; s32 my = getMouseY() - y;
@ -384,7 +384,7 @@ static void drawCanvas(Sfx* sfx, s32 x, s32 y)
mx -= mx % CANVAS_SIZE; mx -= mx % CANVAS_SIZE;
my -= my % CANVAS_SIZE; my -= my % CANVAS_SIZE;
if(checkMouseDown(&rect, SDL_BUTTON_LEFT)) if(checkMouseDown(&rect, tic_mouse_left))
{ {
mx /= CANVAS_SIZE; mx /= CANVAS_SIZE;
my /= CANVAS_SIZE; my /= CANVAS_SIZE;
@ -420,7 +420,7 @@ static void drawCanvas(Sfx* sfx, s32 x, s32 y)
break; break;
case SFX_PITCH_TAB: case SFX_PITCH_TAB:
{ {
for(s32 j = SDL_min(0, effect->data[i].pitch); j <= SDL_max(0, effect->data[i].pitch); j++) for(s32 j = MIN(0, effect->data[i].pitch); j <= MAX(0, effect->data[i].pitch); j++)
sfx->tic->api.rect(sfx->tic, x + i * CANVAS_SIZE + 1, y + 1 + (CANVAS_HEIGHT/2 - (j+1)*CANVAS_SIZE), sfx->tic->api.rect(sfx->tic, x + i * CANVAS_SIZE + 1, y + 1 + (CANVAS_HEIGHT/2 - (j+1)*CANVAS_SIZE),
CANVAS_SIZE-1, CANVAS_SIZE-1, (tic_color_red)); CANVAS_SIZE-1, CANVAS_SIZE-1, (tic_color_red));
} }
@ -451,26 +451,26 @@ static void drawPiano(Sfx* sfx, s32 x, s32 y)
static const s32 ButtonIndixes[] = {0, 2, 4, 5, 7, 9, 11, 1, 3, -1, 6, 8, 10}; static const s32 ButtonIndixes[] = {0, 2, 4, 5, 7, 9, 11, 1, 3, -1, 6, 8, 10};
SDL_Rect buttons[COUNT_OF(ButtonIndixes)]; tic_rect buttons[COUNT_OF(ButtonIndixes)];
for(s32 i = 0; i < COUNT_OF(buttons); i++) for(s32 i = 0; i < COUNT_OF(buttons); i++)
{ {
buttons[i] = i < PIANO_WHITE_BUTTONS buttons[i] = i < PIANO_WHITE_BUTTONS
? (SDL_Rect){x + (PIANO_BUTTON_WIDTH+1)*i, y, PIANO_BUTTON_WIDTH + 1, PIANO_BUTTON_HEIGHT} ? (tic_rect){x + (PIANO_BUTTON_WIDTH+1)*i, y, PIANO_BUTTON_WIDTH + 1, PIANO_BUTTON_HEIGHT}
: (SDL_Rect){x + (7 + 3) * (i - PIANO_WHITE_BUTTONS) + 6, y, 7, 8}; : (tic_rect){x + (7 + 3) * (i - PIANO_WHITE_BUTTONS) + 6, y, 7, 8};
} }
SDL_Rect rect = {x, y, PIANO_WIDTH, PIANO_HEIGHT}; tic_rect rect = {x, y, PIANO_WIDTH, PIANO_HEIGHT};
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
static const char* Tooltips[] = {"C [z]", "C# [s]", "D [x]", "D# [d]", "E [c]", "F [v]", "F# [g]", "G [b]", "G# [h]", "A [n]", "A# [j]", "B [m]" }; static const char* Tooltips[] = {"C [z]", "C# [s]", "D [x]", "D# [d]", "E [c]", "F [v]", "F# [g]", "G [b]", "G# [h]", "A [n]", "A# [j]", "B [m]" };
for(s32 i = COUNT_OF(buttons) - 1; i >= 0; i--) for(s32 i = COUNT_OF(buttons) - 1; i >= 0; i--)
{ {
SDL_Rect* rect = buttons + i; tic_rect* rect = buttons + i;
if(checkMousePos(rect)) if(checkMousePos(rect))
if(ButtonIndixes[i] >= 0) if(ButtonIndixes[i] >= 0)
@ -480,11 +480,11 @@ static void drawPiano(Sfx* sfx, s32 x, s32 y)
} }
} }
if(checkMouseDown(&rect, SDL_BUTTON_LEFT)) if(checkMouseDown(&rect, tic_mouse_left))
{ {
for(s32 i = COUNT_OF(buttons) - 1; i >= 0; i--) for(s32 i = COUNT_OF(buttons) - 1; i >= 0; i--)
{ {
SDL_Rect* rect = buttons + i; tic_rect* rect = buttons + i;
s32 index = ButtonIndixes[i]; s32 index = ButtonIndixes[i];
if(index >= 0) if(index >= 0)
@ -502,7 +502,7 @@ static void drawPiano(Sfx* sfx, s32 x, s32 y)
for(s32 i = 0; i < COUNT_OF(buttons); i++) for(s32 i = 0; i < COUNT_OF(buttons); i++)
{ {
SDL_Rect* rect = buttons + i; tic_rect* rect = buttons + i;
bool white = i < PIANO_WHITE_BUTTONS; bool white = i < PIANO_WHITE_BUTTONS;
s32 index = ButtonIndixes[i]; s32 index = ButtonIndixes[i];
@ -525,13 +525,13 @@ static void drawOctavePanel(Sfx* sfx, s32 x, s32 y)
for(s32 i = 0; i < OCTAVES; i++) for(s32 i = 0; i < OCTAVES; i++)
{ {
SDL_Rect rect = {x + i * (TIC_FONT_WIDTH + Gap), y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT}; tic_rect rect = {x + i * (TIC_FONT_WIDTH + Gap), y, TIC_FONT_WIDTH, TIC_FONT_HEIGHT};
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
if(checkMouseClick(&rect, SDL_BUTTON_LEFT)) if(checkMouseClick(&rect, tic_mouse_left))
{ {
effect->octave = i; effect->octave = i;
} }
@ -629,34 +629,38 @@ static void copyWaveFromClipboard(Sfx* sfx)
static void processKeyboard(Sfx* sfx) static void processKeyboard(Sfx* sfx)
{ {
tic_mem* tic = sfx->tic;
if(tic->ram.input.keyboard.data == 0) return;
bool ctrl = tic->api.key(tic, tic_key_ctrl);
s32 keyboardButton = -1; s32 keyboardButton = -1;
static const s32 Scancodes[] = static const s32 Keycodes[] =
{ {
SDL_SCANCODE_Z, tic_key_z,
SDL_SCANCODE_S, tic_key_s,
SDL_SCANCODE_X, tic_key_x,
SDL_SCANCODE_D, tic_key_d,
SDL_SCANCODE_C, tic_key_c,
SDL_SCANCODE_V, tic_key_v,
SDL_SCANCODE_G, tic_key_g,
SDL_SCANCODE_B, tic_key_b,
SDL_SCANCODE_H, tic_key_h,
SDL_SCANCODE_N, tic_key_n,
SDL_SCANCODE_J, tic_key_j,
SDL_SCANCODE_M, tic_key_m,
}; };
SDL_Keymod keymod = SDL_GetModState(); if(ctrl)
if(keymod & TIC_MOD_CTRL)
{ {
} }
else else
{ {
for(int i = 0; i < COUNT_OF(Scancodes); i++) for(int i = 0; i < COUNT_OF(Keycodes); i++)
if(getKeyboard()[Scancodes[i]]) if(tic->api.key(tic, Keycodes[i]))
keyboardButton = i; keyboardButton = i;
} }
@ -668,13 +672,16 @@ static void processKeyboard(Sfx* sfx)
sfx->play.active = true; sfx->play.active = true;
} }
if(getKeyboard()[SDL_SCANCODE_SPACE]) if(tic->api.key(tic, tic_key_space))
sfx->play.active = true; sfx->play.active = true;
} }
static void processKeydown(Sfx* sfx, SDL_Keycode keycode) static void processEnvelopesKeyboard(Sfx* sfx)
{ {
switch(getClipboardEvent(keycode)) tic_mem* tic = sfx->tic;
bool ctrl = tic->api.key(tic, tic_key_ctrl);
switch(getClipboardEvent())
{ {
case TIC_CLIPBOARD_CUT: cutToClipboard(sfx); break; case TIC_CLIPBOARD_CUT: cutToClipboard(sfx); break;
case TIC_CLIPBOARD_COPY: copyToClipboard(sfx); break; case TIC_CLIPBOARD_COPY: copyToClipboard(sfx); break;
@ -682,29 +689,25 @@ static void processKeydown(Sfx* sfx, SDL_Keycode keycode)
default: break; default: break;
} }
SDL_Keymod keymod = SDL_GetModState(); if(ctrl)
if(keymod & TIC_MOD_CTRL)
{ {
switch(keycode) if(keyWasPressed(tic_key_z)) undo(sfx);
{ else if(keyWasPressed(tic_key_y)) redo(sfx);
case SDLK_z: undo(sfx); break;
case SDLK_y: redo(sfx); break;
}
} }
switch(keycode) if(keyWasPressed(tic_key_tab)) sfx->tab = SFX_WAVEFORM_TAB;
{ else if(keyWasPressed(tic_key_left)) sfx->index--;
case SDLK_TAB: sfx->tab = SFX_WAVEFORM_TAB; break; else if(keyWasPressed(tic_key_right)) sfx->index++;
case SDLK_LEFT: sfx->index--; break; else if(keyWasPressed(tic_key_delete)) resetSfx(sfx);
case SDLK_RIGHT: sfx->index++; break;
case SDLK_DELETE: resetSfx(sfx); break;
}
} }
static void processWaveformKeydown(Sfx* sfx, SDL_Keycode keycode) static void processWaveformKeyboard(Sfx* sfx)
{ {
switch(getClipboardEvent(keycode)) tic_mem* tic = sfx->tic;
bool ctrl = tic->api.key(tic, tic_key_ctrl);
switch(getClipboardEvent())
{ {
case TIC_CLIPBOARD_CUT: cutWaveToClipboard(sfx); break; case TIC_CLIPBOARD_CUT: cutWaveToClipboard(sfx); break;
case TIC_CLIPBOARD_COPY: copyWaveToClipboard(sfx); break; case TIC_CLIPBOARD_COPY: copyWaveToClipboard(sfx); break;
@ -712,24 +715,16 @@ static void processWaveformKeydown(Sfx* sfx, SDL_Keycode keycode)
default: break; default: break;
} }
SDL_Keymod keymod = SDL_GetModState(); if(ctrl)
if(keymod & TIC_MOD_CTRL)
{ {
switch(keycode) if(keyWasPressed(tic_key_z)) undo(sfx);
{ else if(keyWasPressed(tic_key_y)) redo(sfx);
case SDLK_z: undo(sfx); break;
case SDLK_y: redo(sfx); break;
}
} }
switch(keycode) if(keyWasPressed(tic_key_tab)) sfx->tab = SFX_ENVELOPES_TAB;
{ else if(keyWasPressed(tic_key_left)) sfx->waveform.index--;
case SDLK_TAB: sfx->tab = SFX_ENVELOPES_TAB; break; else if(keyWasPressed(tic_key_right)) sfx->waveform.index++;
case SDLK_LEFT: sfx->waveform.index--; break; else if(keyWasPressed(tic_key_delete)) resetWave(sfx);
case SDLK_RIGHT: sfx->waveform.index++; break;
case SDLK_DELETE: resetWave(sfx); break;
}
} }
static void drawModeTabs(Sfx* sfx) static void drawModeTabs(Sfx* sfx)
@ -759,7 +754,7 @@ static void drawModeTabs(Sfx* sfx)
for (s32 i = 0; i < Count; i++) for (s32 i = 0; i < Count; i++)
{ {
SDL_Rect rect = { TIC80_WIDTH - Width * (Count - i), 0, Width, Height }; tic_rect rect = { TIC80_WIDTH - Width * (Count - i), 0, Width, Height };
bool over = false; bool over = false;
@ -767,13 +762,13 @@ static void drawModeTabs(Sfx* sfx)
if (checkMousePos(&rect)) if (checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
over = true; over = true;
static const char* Tooltips[] = { "WAVEFORMS [tab]", "ENVELOPES [tab]" }; static const char* Tooltips[] = { "WAVEFORMS [tab]", "ENVELOPES [tab]" };
showTooltip(Tooltips[i]); showTooltip(Tooltips[i]);
if (checkMouseClick(&rect, SDL_BUTTON_LEFT)) if (checkMouseClick(&rect, tic_mouse_left))
sfx->tab = Tabs[i]; sfx->tab = Tabs[i];
} }
@ -792,17 +787,17 @@ static void drawSfxToolbar(Sfx* sfx)
s32 x = TIC80_WIDTH - Width - TIC_SPRITESIZE*3; s32 x = TIC80_WIDTH - Width - TIC_SPRITESIZE*3;
s32 y = 1; s32 y = 1;
SDL_Rect rect = {x, y, Width, TIC_FONT_HEIGHT}; tic_rect rect = {x, y, Width, TIC_FONT_HEIGHT};
bool over = false; bool over = false;
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
over = true; over = true;
showTooltip("PLAY SFX [space]"); showTooltip("PLAY SFX [space]");
if(checkMouseDown(&rect, SDL_BUTTON_LEFT)) if(checkMouseDown(&rect, tic_mouse_left))
{ {
sfx->play.active = true; sfx->play.active = true;
} }
@ -823,18 +818,8 @@ static void drawSfxToolbar(Sfx* sfx)
static void envelopesTick(Sfx* sfx) static void envelopesTick(Sfx* sfx)
{ {
SDL_Event* event = NULL;
while ((event = pollEvent()))
{
switch(event->type)
{
case SDL_KEYDOWN:
processKeydown(sfx, event->key.keysym.sym);
break;
}
}
processKeyboard(sfx); processKeyboard(sfx);
processEnvelopesKeyboard(sfx);
sfx->tic->api.clear(sfx->tic, TIC_COLOR_BG); sfx->tic->api.clear(sfx->tic, TIC_COLOR_BG);
@ -869,13 +854,13 @@ static void drawWaveformBar(Sfx* sfx, s32 x, s32 y)
for(s32 i = 0; i < ENVELOPES_COUNT; i++) for(s32 i = 0; i < ENVELOPES_COUNT; i++)
{ {
SDL_Rect rect = {x + (i%Cols)*(Width+Gap), y + (i/Cols)*(Height+Gap), Width, Height}; tic_rect rect = {x + (i%Cols)*(Width+Gap), y + (i/Cols)*(Height+Gap), Width, Height};
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
if(checkMouseClick(&rect, SDL_BUTTON_LEFT)) if(checkMouseClick(&rect, tic_mouse_left))
sfx->waveform.index = i; sfx->waveform.index = i;
} }
@ -909,7 +894,7 @@ static void drawWaveformCanvas(Sfx* sfx, s32 x, s32 y)
{ {
enum {Rows = CANVAS_ROWS, Width = ENVELOPE_VALUES * CANVAS_SIZE, Height = CANVAS_HEIGHT}; enum {Rows = CANVAS_ROWS, Width = ENVELOPE_VALUES * CANVAS_SIZE, Height = CANVAS_HEIGHT};
SDL_Rect rect = {x, y, Width, Height}; tic_rect rect = {x, y, Width, Height};
sfx->tic->api.rect(sfx->tic, rect.x, rect.y, rect.w, rect.h, (tic_color_dark_red)); sfx->tic->api.rect(sfx->tic, rect.x, rect.y, rect.w, rect.h, (tic_color_dark_red));
@ -921,9 +906,9 @@ static void drawWaveformCanvas(Sfx* sfx, s32 x, s32 y)
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
if(checkMouseDown(&rect, SDL_BUTTON_LEFT)) if(checkMouseDown(&rect, tic_mouse_left))
{ {
s32 mx = getMouseX() - x; s32 mx = getMouseX() - x;
s32 my = getMouseY() - y; s32 my = getMouseY() - y;
@ -954,18 +939,8 @@ static void drawWaveformCanvas(Sfx* sfx, s32 x, s32 y)
static void waveformTick(Sfx* sfx) static void waveformTick(Sfx* sfx)
{ {
SDL_Event* event = NULL;
while ((event = pollEvent()))
{
switch(event->type)
{
case SDL_KEYDOWN:
processWaveformKeydown(sfx, event->key.keysym.sym);
break;
}
}
processKeyboard(sfx); processKeyboard(sfx);
processWaveformKeyboard(sfx);
sfx->tic->api.clear(sfx->tic, TIC_COLOR_BG); sfx->tic->api.clear(sfx->tic, TIC_COLOR_BG);

View File

@ -33,7 +33,7 @@
static void clearCanvasSelection(Sprite* sprite) static void clearCanvasSelection(Sprite* sprite)
{ {
SDL_memset(&sprite->select.rect, 0, sizeof(SDL_Rect)); memset(&sprite->select.rect, 0, sizeof(tic_rect));
} }
static u8 getSheetPixel(Sprite* sprite, s32 x, s32 y) static u8 getSheetPixel(Sprite* sprite, s32 x, s32 y)
@ -70,12 +70,12 @@ static void drawSelection(Sprite* sprite, s32 x, s32 y, s32 w, s32 h)
for(s32 i = (y+h-1); i >= y; i--) { sprite->tic->api.pixel(sprite->tic, x, i, index++ % Step ? color : 0);} for(s32 i = (y+h-1); i >= y; i--) { sprite->tic->api.pixel(sprite->tic, x, i, index++ % Step ? color : 0);}
} }
static SDL_Rect getSpriteRect(Sprite* sprite) static tic_rect getSpriteRect(Sprite* sprite)
{ {
s32 x = getIndexPosX(sprite); s32 x = getIndexPosX(sprite);
s32 y = getIndexPosY(sprite); s32 y = getIndexPosY(sprite);
return (SDL_Rect){x, y, sprite->size, sprite->size}; return (tic_rect){x, y, sprite->size, sprite->size};
} }
static void drawCursorBorder(Sprite* sprite, s32 x, s32 y, s32 w, s32 h) static void drawCursorBorder(Sprite* sprite, s32 x, s32 y, s32 w, s32 h)
@ -86,12 +86,12 @@ static void drawCursorBorder(Sprite* sprite, s32 x, s32 y, s32 w, s32 h)
static void processPickerCanvasMouse(Sprite* sprite, s32 x, s32 y, s32 sx, s32 sy) static void processPickerCanvasMouse(Sprite* sprite, s32 x, s32 y, s32 sx, s32 sy)
{ {
SDL_Rect rect = {x, y, CANVAS_SIZE, CANVAS_SIZE}; tic_rect rect = {x, y, CANVAS_SIZE, CANVAS_SIZE};
const s32 Size = CANVAS_SIZE / sprite->size; const s32 Size = CANVAS_SIZE / sprite->size;
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
s32 mx = getMouseX() - x; s32 mx = getMouseX() - x;
s32 my = getMouseY() - y; s32 my = getMouseY() - y;
@ -101,22 +101,22 @@ static void processPickerCanvasMouse(Sprite* sprite, s32 x, s32 y, s32 sx, s32 s
drawCursorBorder(sprite, x + mx, y + my, Size, Size); drawCursorBorder(sprite, x + mx, y + my, Size, Size);
if(checkMouseDown(&rect, SDL_BUTTON_LEFT)) if(checkMouseDown(&rect, tic_mouse_left))
sprite->color = getSheetPixel(sprite, sx + mx / Size, sy + my / Size); sprite->color = getSheetPixel(sprite, sx + mx / Size, sy + my / Size);
if(checkMouseDown(&rect, SDL_BUTTON_RIGHT)) if(checkMouseDown(&rect, tic_mouse_right))
sprite->color2 = getSheetPixel(sprite, sx + mx / Size, sy + my / Size); sprite->color2 = getSheetPixel(sprite, sx + mx / Size, sy + my / Size);
} }
} }
static void processDrawCanvasMouse(Sprite* sprite, s32 x, s32 y, s32 sx, s32 sy) static void processDrawCanvasMouse(Sprite* sprite, s32 x, s32 y, s32 sx, s32 sy)
{ {
SDL_Rect rect = {x, y, CANVAS_SIZE, CANVAS_SIZE}; tic_rect rect = {x, y, CANVAS_SIZE, CANVAS_SIZE};
const s32 Size = CANVAS_SIZE / sprite->size; const s32 Size = CANVAS_SIZE / sprite->size;
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
s32 mx = getMouseX() - x; s32 mx = getMouseX() - x;
s32 my = getMouseY() - y; s32 my = getMouseY() - y;
@ -137,8 +137,8 @@ static void processDrawCanvasMouse(Sprite* sprite, s32 x, s32 y, s32 sx, s32 sy)
drawCursorBorder(sprite, x + mx, y + my, brushSize, brushSize); drawCursorBorder(sprite, x + mx, y + my, brushSize, brushSize);
bool left = checkMouseDown(&rect, SDL_BUTTON_LEFT); bool left = checkMouseDown(&rect, tic_mouse_left);
bool right = checkMouseDown(&rect, SDL_BUTTON_RIGHT); bool right = checkMouseDown(&rect, tic_mouse_right);
if(left || right) if(left || right)
{ {
@ -167,7 +167,7 @@ static void pasteSelection(Sprite* sprite)
for(s32 sx = l; sx < r; sx++) for(s32 sx = l; sx < r; sx++)
setSheetPixel(sprite, sx, sy, sprite->select.back[i++]); setSheetPixel(sprite, sx, sy, sprite->select.back[i++]);
SDL_Rect* rect = &sprite->select.rect; tic_rect* rect = &sprite->select.rect;
l += rect->x; l += rect->x;
t += rect->y; t += rect->y;
@ -183,7 +183,7 @@ static void pasteSelection(Sprite* sprite)
static void copySelection(Sprite* sprite) static void copySelection(Sprite* sprite)
{ {
SDL_Rect rect = getSpriteRect(sprite); tic_rect rect = getSpriteRect(sprite);
s32 r = rect.x + rect.w; s32 r = rect.x + rect.w;
s32 b = rect.y + rect.h; s32 b = rect.y + rect.h;
@ -192,8 +192,8 @@ static void copySelection(Sprite* sprite)
sprite->select.back[i++] = getSheetPixel(sprite, sx, sy); sprite->select.back[i++] = getSheetPixel(sprite, sx, sy);
{ {
SDL_Rect* rect = &sprite->select.rect; tic_rect* rect = &sprite->select.rect;
SDL_memset(sprite->select.front, 0, CANVAS_SIZE * CANVAS_SIZE); memset(sprite->select.front, 0, CANVAS_SIZE * CANVAS_SIZE);
for(s32 j = rect->y, index = 0; j < (rect->y + rect->h); j++) for(s32 j = rect->y, index = 0; j < (rect->y + rect->h); j++)
for(s32 i = rect->x; i < (rect->x + rect->w); i++) for(s32 i = rect->x; i < (rect->x + rect->w); i++)
@ -207,12 +207,12 @@ static void copySelection(Sprite* sprite)
static void processSelectCanvasMouse(Sprite* sprite, s32 x, s32 y) static void processSelectCanvasMouse(Sprite* sprite, s32 x, s32 y)
{ {
SDL_Rect rect = {x, y, CANVAS_SIZE, CANVAS_SIZE}; tic_rect rect = {x, y, CANVAS_SIZE, CANVAS_SIZE};
const s32 Size = CANVAS_SIZE / sprite->size; const s32 Size = CANVAS_SIZE / sprite->size;
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
s32 mx = getMouseX() - x; s32 mx = getMouseX() - x;
s32 my = getMouseY() - y; s32 my = getMouseY() - y;
@ -222,25 +222,25 @@ static void processSelectCanvasMouse(Sprite* sprite, s32 x, s32 y)
drawCursorBorder(sprite, x + mx, y + my, Size, Size); drawCursorBorder(sprite, x + mx, y + my, Size, Size);
if(checkMouseDown(&rect, SDL_BUTTON_LEFT)) if(checkMouseDown(&rect, tic_mouse_left))
{ {
if(sprite->select.drag) if(sprite->select.drag)
{ {
s32 x = mx / Size; s32 x = mx / Size;
s32 y = my / Size; s32 y = my / Size;
s32 rl = SDL_min(x, sprite->select.start.x); s32 rl = MIN(x, sprite->select.start.x);
s32 rt = SDL_min(y, sprite->select.start.y); s32 rt = MIN(y, sprite->select.start.y);
s32 rr = SDL_max(x, sprite->select.start.x); s32 rr = MAX(x, sprite->select.start.x);
s32 rb = SDL_max(y, sprite->select.start.y); s32 rb = MAX(y, sprite->select.start.y);
sprite->select.rect = (SDL_Rect){rl, rt, rr - rl + 1, rb - rt + 1}; sprite->select.rect = (tic_rect){rl, rt, rr - rl + 1, rb - rt + 1};
} }
else else
{ {
sprite->select.drag = true; sprite->select.drag = true;
sprite->select.start = (SDL_Point){mx / Size, my / Size}; sprite->select.start = (tic_point){mx / Size, my / Size};
sprite->select.rect = (SDL_Rect){sprite->select.start.x, sprite->select.start.y, 1, 1}; sprite->select.rect = (tic_rect){sprite->select.start.x, sprite->select.start.y, 1, 1};
} }
} }
else if(sprite->select.drag) else if(sprite->select.drag)
@ -274,12 +274,13 @@ static void replaceColor(Sprite* sprite, s32 l, s32 t, s32 r, s32 b, s32 x, s32
static void processFillCanvasMouse(Sprite* sprite, s32 x, s32 y, s32 l, s32 t) static void processFillCanvasMouse(Sprite* sprite, s32 x, s32 y, s32 l, s32 t)
{ {
SDL_Rect rect = {x, y, CANVAS_SIZE, CANVAS_SIZE}; tic_mem* tic = sprite->tic;
tic_rect rect = {x, y, CANVAS_SIZE, CANVAS_SIZE};
const s32 Size = CANVAS_SIZE / sprite->size; const s32 Size = CANVAS_SIZE / sprite->size;
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
s32 mx = getMouseX() - x; s32 mx = getMouseX() - x;
s32 my = getMouseY() - y; s32 my = getMouseY() - y;
@ -289,8 +290,8 @@ static void processFillCanvasMouse(Sprite* sprite, s32 x, s32 y, s32 l, s32 t)
drawCursorBorder(sprite, x + mx, y + my, Size, Size); drawCursorBorder(sprite, x + mx, y + my, Size, Size);
bool left = checkMouseClick(&rect, SDL_BUTTON_LEFT); bool left = checkMouseClick(&rect, tic_mouse_left);
bool right = checkMouseClick(&rect, SDL_BUTTON_RIGHT); bool right = checkMouseClick(&rect, tic_mouse_right);
if(left || right) if(left || right)
{ {
@ -302,9 +303,7 @@ static void processFillCanvasMouse(Sprite* sprite, s32 x, s32 y, s32 l, s32 t)
if(color != fill) if(color != fill)
{ {
SDL_Keymod keymod = SDL_GetModState(); tic->api.key(tic, tic_key_ctrl)
keymod & TIC_MOD_CTRL
? replaceColor(sprite, l, t, l + sprite->size-1, t + sprite->size-1, sx, sy, color, fill) ? replaceColor(sprite, l, t, l + sprite->size-1, t + sprite->size-1, sx, sy, color, fill)
: floodFill(sprite, l, t, l + sprite->size-1, t + sprite->size-1, sx, sy, color, fill); : floodFill(sprite, l, t, l + sprite->size-1, t + sprite->size-1, sx, sy, color, fill);
} }
@ -323,17 +322,17 @@ static void drawBrushSlider(Sprite* sprite, s32 x, s32 y)
{ {
enum {Count = 4, Size = 5}; enum {Count = 4, Size = 5};
SDL_Rect rect = {x, y, Size, (Size+1)*Count}; tic_rect rect = {x, y, Size, (Size+1)*Count};
bool over = false; bool over = false;
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
showTooltip("BRUSH SIZE"); showTooltip("BRUSH SIZE");
over = true; over = true;
if(checkMouseDown(&rect, SDL_BUTTON_LEFT)) if(checkMouseDown(&rect, tic_mouse_left))
{ {
s32 my = getMouseY() - y; s32 my = getMouseY() - y;
@ -386,7 +385,7 @@ static void drawCanvas(Sprite* sprite, s32 x, s32 y)
static void drawCanvasOvr(Sprite* sprite, s32 x, s32 y) static void drawCanvasOvr(Sprite* sprite, s32 x, s32 y)
{ {
SDL_Rect rect = getSpriteRect(sprite); tic_rect rect = getSpriteRect(sprite);
s32 r = rect.x + rect.w; s32 r = rect.x + rect.w;
s32 b = rect.y + rect.h; s32 b = rect.y + rect.h;
@ -414,8 +413,8 @@ static void drawCanvasOvr(Sprite* sprite, s32 x, s32 y)
} }
} }
SDL_Rect canvasRect = {x, y, CANVAS_SIZE, CANVAS_SIZE}; tic_rect canvasRect = {x, y, CANVAS_SIZE, CANVAS_SIZE};
if(checkMouseDown(&canvasRect, SDL_BUTTON_MIDDLE)) if(checkMouseDown(&canvasRect, tic_mouse_middle))
{ {
s32 mx = getMouseX() - x; s32 mx = getMouseX() - x;
s32 my = getMouseY() - y; s32 my = getMouseY() - y;
@ -425,35 +424,35 @@ static void drawCanvasOvr(Sprite* sprite, s32 x, s32 y)
static void upCanvas(Sprite* sprite) static void upCanvas(Sprite* sprite)
{ {
SDL_Rect* rect = &sprite->select.rect; tic_rect* rect = &sprite->select.rect;
if(rect->y > 0) rect->y--; if(rect->y > 0) rect->y--;
pasteSelection(sprite); pasteSelection(sprite);
} }
static void downCanvas(Sprite* sprite) static void downCanvas(Sprite* sprite)
{ {
SDL_Rect* rect = &sprite->select.rect; tic_rect* rect = &sprite->select.rect;
if(rect->y + rect->h < sprite->size) rect->y++; if(rect->y + rect->h < sprite->size) rect->y++;
pasteSelection(sprite); pasteSelection(sprite);
} }
static void leftCanvas(Sprite* sprite) static void leftCanvas(Sprite* sprite)
{ {
SDL_Rect* rect = &sprite->select.rect; tic_rect* rect = &sprite->select.rect;
if(rect->x > 0) rect->x--; if(rect->x > 0) rect->x--;
pasteSelection(sprite); pasteSelection(sprite);
} }
static void rightCanvas(Sprite* sprite) static void rightCanvas(Sprite* sprite)
{ {
SDL_Rect* rect = &sprite->select.rect; tic_rect* rect = &sprite->select.rect;
if(rect->x + rect->w < sprite->size) rect->x++; if(rect->x + rect->w < sprite->size) rect->x++;
pasteSelection(sprite); pasteSelection(sprite);
} }
static void rotateSelectRect(Sprite* sprite) static void rotateSelectRect(Sprite* sprite)
{ {
SDL_Rect rect = sprite->select.rect; tic_rect rect = sprite->select.rect;
s32 selection_center_x = rect.x + rect.w/2; s32 selection_center_x = rect.x + rect.w/2;
s32 selection_center_y = rect.y + rect.h/2; s32 selection_center_y = rect.y + rect.h/2;
@ -483,12 +482,12 @@ static void rotateSelectRect(Sprite* sprite)
static void rotateCanvas(Sprite* sprite) static void rotateCanvas(Sprite* sprite)
{ {
u8* buffer = (u8*)SDL_malloc(CANVAS_SIZE*CANVAS_SIZE); u8* buffer = (u8*)malloc(CANVAS_SIZE*CANVAS_SIZE);
if(buffer) if(buffer)
{ {
{ {
SDL_Rect rect = sprite->select.rect; tic_rect rect = sprite->select.rect;
const s32 Size = rect.h * rect.w; const s32 Size = rect.h * rect.w;
s32 diff = 0; s32 diff = 0;
@ -507,13 +506,13 @@ static void rotateCanvas(Sprite* sprite)
history_add(sprite->history); history_add(sprite->history);
} }
SDL_free(buffer); free(buffer);
} }
} }
static void deleteCanvas(Sprite* sprite) static void deleteCanvas(Sprite* sprite)
{ {
SDL_Rect* rect = &sprite->select.rect; tic_rect* rect = &sprite->select.rect;
s32 left = getIndexPosX(sprite) + rect->x; s32 left = getIndexPosX(sprite) + rect->x;
s32 top = getIndexPosY(sprite) + rect->y; s32 top = getIndexPosY(sprite) + rect->y;
@ -531,7 +530,7 @@ static void deleteCanvas(Sprite* sprite)
static void flipCanvasHorz(Sprite* sprite) static void flipCanvasHorz(Sprite* sprite)
{ {
SDL_Rect* rect = &sprite->select.rect; tic_rect* rect = &sprite->select.rect;
s32 sprite_x = getIndexPosX(sprite); s32 sprite_x = getIndexPosX(sprite);
s32 sprite_y = getIndexPosY(sprite); s32 sprite_y = getIndexPosY(sprite);
@ -553,7 +552,7 @@ static void flipCanvasHorz(Sprite* sprite)
static void flipCanvasVert(Sprite* sprite) static void flipCanvasVert(Sprite* sprite)
{ {
SDL_Rect* rect = &sprite->select.rect; tic_rect* rect = &sprite->select.rect;
s32 sprite_x = getIndexPosX(sprite); s32 sprite_x = getIndexPosX(sprite);
s32 sprite_y = getIndexPosY(sprite); s32 sprite_y = getIndexPosY(sprite);
@ -619,7 +618,7 @@ static void drawMoveButtons(Sprite* sprite)
0b00000000, 0b00000000,
}; };
static const SDL_Rect Rects[] = static const tic_rect Rects[] =
{ {
{x + (CANVAS_SIZE - TIC_SPRITESIZE)/2, y - TIC_SPRITESIZE, TIC_SPRITESIZE, TIC_SPRITESIZE/2}, {x + (CANVAS_SIZE - TIC_SPRITESIZE)/2, y - TIC_SPRITESIZE, TIC_SPRITESIZE, TIC_SPRITESIZE/2},
{x + (CANVAS_SIZE - TIC_SPRITESIZE)/2, y + CANVAS_SIZE + TIC_SPRITESIZE/2, TIC_SPRITESIZE, TIC_SPRITESIZE/2}, {x + (CANVAS_SIZE - TIC_SPRITESIZE)/2, y + CANVAS_SIZE + TIC_SPRITESIZE/2, TIC_SPRITESIZE, TIC_SPRITESIZE/2},
@ -636,11 +635,11 @@ static void drawMoveButtons(Sprite* sprite)
if(checkMousePos(&Rects[i])) if(checkMousePos(&Rects[i]))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
if(checkMouseDown(&Rects[i], SDL_BUTTON_LEFT)) down = true; if(checkMouseDown(&Rects[i], tic_mouse_left)) down = true;
if(checkMouseClick(&Rects[i], SDL_BUTTON_LEFT)) if(checkMouseClick(&Rects[i], tic_mouse_left))
Func[i](sprite); Func[i](sprite);
} }
@ -668,13 +667,13 @@ static void drawRGBSlider(Sprite* sprite, s32 x, s32 y, u8* value)
0b00000000, 0b00000000,
}; };
SDL_Rect rect = {x, y-2, Size, 5}; tic_rect rect = {x, y-2, Size, 5};
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
if(checkMouseDown(&rect, SDL_BUTTON_LEFT)) if(checkMouseDown(&rect, tic_mouse_left))
{ {
s32 mx = getMouseX() - x; s32 mx = getMouseX() - x;
*value = mx * Max / (Size-1); *value = mx * Max / (Size-1);
@ -710,17 +709,17 @@ static void drawRGBSlider(Sprite* sprite, s32 x, s32 y, u8* value)
0b00000000, 0b00000000,
}; };
SDL_Rect rect = {x - 4, y - 1, 2, 3}; tic_rect rect = {x - 4, y - 1, 2, 3};
bool down = false; bool down = false;
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
if(checkMouseDown(&rect, SDL_BUTTON_LEFT)) if(checkMouseDown(&rect, tic_mouse_left))
down = true; down = true;
if(checkMouseClick(&rect, SDL_BUTTON_LEFT)) if(checkMouseClick(&rect, tic_mouse_left))
(*value)--; (*value)--;
} }
@ -748,17 +747,17 @@ static void drawRGBSlider(Sprite* sprite, s32 x, s32 y, u8* value)
0b00000000, 0b00000000,
}; };
SDL_Rect rect = {x + Size + 2, y - 1, 2, 3}; tic_rect rect = {x + Size + 2, y - 1, 2, 3};
bool down = false; bool down = false;
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
if(checkMouseDown(&rect, SDL_BUTTON_LEFT)) if(checkMouseDown(&rect, tic_mouse_left))
down = true; down = true;
if(checkMouseClick(&rect, SDL_BUTTON_LEFT)) if(checkMouseClick(&rect, tic_mouse_left))
(*value)++; (*value)++;
} }
@ -796,22 +795,22 @@ static void drawRGBTools(Sprite* sprite, s32 x, s32 y)
0b00000000, 0b00000000,
}; };
SDL_Rect rect = {x, y, Size, Size}; tic_rect rect = {x, y, Size, Size};
bool over = false; bool over = false;
bool down = false; bool down = false;
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
showTooltip("COPY PALETTE"); showTooltip("COPY PALETTE");
over = true; over = true;
if(checkMouseDown(&rect, SDL_BUTTON_LEFT)) if(checkMouseDown(&rect, tic_mouse_left))
down = true; down = true;
if(checkMouseClick(&rect, SDL_BUTTON_LEFT)) if(checkMouseClick(&rect, tic_mouse_left))
toClipboard(sprite->tic->cart.palette.data, sizeof(tic_palette), false); toClipboard(sprite->tic->cart.palette.data, sizeof(tic_palette), false);
} }
@ -840,21 +839,21 @@ static void drawRGBTools(Sprite* sprite, s32 x, s32 y)
0b00000000, 0b00000000,
}; };
SDL_Rect rect = {x + 8, y, Size, Size}; tic_rect rect = {x + 8, y, Size, Size};
bool over = false; bool over = false;
bool down = false; bool down = false;
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
showTooltip("PASTE PALETTE"); showTooltip("PASTE PALETTE");
over = true; over = true;
if(checkMouseDown(&rect, SDL_BUTTON_LEFT)) if(checkMouseDown(&rect, tic_mouse_left))
down = true; down = true;
if(checkMouseClick(&rect, SDL_BUTTON_LEFT)) if(checkMouseClick(&rect, tic_mouse_left))
{ {
pasteColor(sprite); pasteColor(sprite);
} }
@ -898,14 +897,14 @@ static void drawRGBSlidersOvr(Sprite* sprite, s32 x, s32 y)
static void drawPalette(Sprite* sprite, s32 x, s32 y) static void drawPalette(Sprite* sprite, s32 x, s32 y)
{ {
SDL_Rect rect = {x, y, PALETTE_WIDTH-1, PALETTE_HEIGHT-1}; tic_rect rect = {x, y, PALETTE_WIDTH-1, PALETTE_HEIGHT-1};
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
bool left = checkMouseDown(&rect, SDL_BUTTON_LEFT); bool left = checkMouseDown(&rect, tic_mouse_left);
bool right = checkMouseDown(&rect, SDL_BUTTON_RIGHT); bool right = checkMouseDown(&rect, tic_mouse_right);
if(left || right) if(left || right)
{ {
@ -946,21 +945,21 @@ static void drawPalette(Sprite* sprite, s32 x, s32 y)
0b11111111, 0b11111111,
}; };
SDL_Rect rect = {x + PALETTE_WIDTH + 3, y + (PALETTE_HEIGHT-8)/2-1, 8, 8}; tic_rect rect = {x + PALETTE_WIDTH + 3, y + (PALETTE_HEIGHT-8)/2-1, 8, 8};
bool down = false; bool down = false;
bool over = false; bool over = false;
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
over = true; over = true;
showTooltip("EDIT PALETTE"); showTooltip("EDIT PALETTE");
if(checkMouseDown(&rect, SDL_BUTTON_LEFT)) if(checkMouseDown(&rect, tic_mouse_left))
down = true; down = true;
if(checkMouseClick(&rect, SDL_BUTTON_LEFT)) if(checkMouseClick(&rect, tic_mouse_left))
sprite->editPalette = !sprite->editPalette; sprite->editPalette = !sprite->editPalette;
} }
@ -1040,16 +1039,16 @@ static void updateSpriteSize(Sprite* sprite, s32 size)
static void drawSheet(Sprite* sprite, s32 x, s32 y) static void drawSheet(Sprite* sprite, s32 x, s32 y)
{ {
SDL_Rect rect = {x, y, TIC_SPRITESHEET_SIZE, TIC_SPRITESHEET_SIZE}; tic_rect rect = {x, y, TIC_SPRITESHEET_SIZE, TIC_SPRITESHEET_SIZE};
sprite->tic->api.rect_border(sprite->tic, rect.x - 1, rect.y - 1, rect.w + 2, rect.h + 2, (tic_color_white)); sprite->tic->api.rect_border(sprite->tic, rect.x - 1, rect.y - 1, rect.w + 2, rect.h + 2, (tic_color_white));
sprite->tic->api.rect(sprite->tic, rect.x, rect.y, rect.w, rect.h, (tic_color_black)); sprite->tic->api.rect(sprite->tic, rect.x, rect.y, rect.w, rect.h, (tic_color_black));
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
if(checkMouseDown(&rect, SDL_BUTTON_LEFT)) if(checkMouseDown(&rect, tic_mouse_left))
{ {
s32 offset = (sprite->size - TIC_SPRITESIZE) / 2; s32 offset = (sprite->size - TIC_SPRITESIZE) / 2;
selectSprite(sprite, getMouseX() - x - offset, getMouseY() - y - offset); selectSprite(sprite, getMouseX() - x - offset, getMouseY() - y - offset);
@ -1059,7 +1058,7 @@ static void drawSheet(Sprite* sprite, s32 x, s32 y)
static void drawSheetOvr(Sprite* sprite, s32 x, s32 y) static void drawSheetOvr(Sprite* sprite, s32 x, s32 y)
{ {
SDL_Rect rect = {x, y, TIC_SPRITESHEET_SIZE, TIC_SPRITESHEET_SIZE}; tic_rect rect = {x, y, TIC_SPRITESHEET_SIZE, TIC_SPRITESHEET_SIZE};
for(s32 j = 0, index = (sprite->index - sprite->index % TIC_BANK_SPRITES); j < rect.h; j += TIC_SPRITESIZE) for(s32 j = 0, index = (sprite->index - sprite->index % TIC_BANK_SPRITES); j < rect.h; j += TIC_SPRITESIZE)
for(s32 i = 0; i < rect.w; i += TIC_SPRITESIZE, index++) for(s32 i = 0; i < rect.w; i += TIC_SPRITESIZE, index++)
@ -1074,7 +1073,7 @@ static void drawSheetOvr(Sprite* sprite, s32 x, s32 y)
static void flipSpriteHorz(Sprite* sprite) static void flipSpriteHorz(Sprite* sprite)
{ {
SDL_Rect rect = getSpriteRect(sprite); tic_rect rect = getSpriteRect(sprite);
s32 r = rect.x + rect.w/2; s32 r = rect.x + rect.w/2;
s32 b = rect.y + rect.h; s32 b = rect.y + rect.h;
@ -1091,7 +1090,7 @@ static void flipSpriteHorz(Sprite* sprite)
static void flipSpriteVert(Sprite* sprite) static void flipSpriteVert(Sprite* sprite)
{ {
SDL_Rect rect = getSpriteRect(sprite); tic_rect rect = getSpriteRect(sprite);
s32 r = rect.x + rect.w; s32 r = rect.x + rect.w;
s32 b = rect.y + rect.h/2; s32 b = rect.y + rect.h/2;
@ -1109,12 +1108,12 @@ static void flipSpriteVert(Sprite* sprite)
static void rotateSprite(Sprite* sprite) static void rotateSprite(Sprite* sprite)
{ {
const s32 Size = sprite->size; const s32 Size = sprite->size;
u8* buffer = (u8*)SDL_malloc(Size * Size); u8* buffer = (u8*)malloc(Size * Size);
if(buffer) if(buffer)
{ {
{ {
SDL_Rect rect = getSpriteRect(sprite); tic_rect rect = getSpriteRect(sprite);
s32 r = rect.x + rect.w; s32 r = rect.x + rect.w;
s32 b = rect.y + rect.h; s32 b = rect.y + rect.h;
@ -1129,13 +1128,13 @@ static void rotateSprite(Sprite* sprite)
history_add(sprite->history); history_add(sprite->history);
} }
SDL_free(buffer); free(buffer);
} }
} }
static void deleteSprite(Sprite* sprite) static void deleteSprite(Sprite* sprite)
{ {
SDL_Rect rect = getSpriteRect(sprite); tic_rect rect = getSpriteRect(sprite);
s32 r = rect.x + rect.w; s32 r = rect.x + rect.w;
s32 b = rect.y + rect.h; s32 b = rect.y + rect.h;
@ -1200,19 +1199,19 @@ static void drawSpriteTools(Sprite* sprite, s32 x, s32 y)
bool pushed = false; bool pushed = false;
bool over = false; bool over = false;
SDL_Rect rect = {x + i * Gap, y, TIC_SPRITESIZE, TIC_SPRITESIZE}; tic_rect rect = {x + i * Gap, y, TIC_SPRITESIZE, TIC_SPRITESIZE};
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
over = true; over = true;
showTooltip(Tooltips[i]); showTooltip(Tooltips[i]);
if(checkMouseDown(&rect, SDL_BUTTON_LEFT)) pushed = true; if(checkMouseDown(&rect, tic_mouse_left)) pushed = true;
if(checkMouseClick(&rect, SDL_BUTTON_LEFT)) if(checkMouseClick(&rect, tic_mouse_left))
{ {
if(hasCanvasSelection(sprite)) if(hasCanvasSelection(sprite))
{ {
@ -1283,19 +1282,19 @@ static void drawTools(Sprite* sprite, s32 x, s32 y)
for(s32 i = 0; i < COUNT_OF(Icons)/BITS_IN_BYTE; i++) for(s32 i = 0; i < COUNT_OF(Icons)/BITS_IN_BYTE; i++)
{ {
SDL_Rect rect = {x + i * Gap, y, TIC_SPRITESIZE, TIC_SPRITESIZE}; tic_rect rect = {x + i * Gap, y, TIC_SPRITESIZE, TIC_SPRITESIZE};
bool over = false; bool over = false;
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
over = true; over = true;
static const char* Tooltips[] = {"BRUSH [1]", "COLOR PICKER [2]", "SELECT [3]", "FILL [4]"}; static const char* Tooltips[] = {"BRUSH [1]", "COLOR PICKER [2]", "SELECT [3]", "FILL [4]"};
showTooltip(Tooltips[i]); showTooltip(Tooltips[i]);
if(checkMouseClick(&rect, SDL_BUTTON_LEFT)) if(checkMouseClick(&rect, tic_mouse_left))
{ {
sprite->mode = i; sprite->mode = i;
@ -1337,11 +1336,11 @@ static void drawTools(Sprite* sprite, s32 x, s32 y)
static void copyToClipboard(Sprite* sprite) static void copyToClipboard(Sprite* sprite)
{ {
s32 size = sprite->size * sprite->size * TIC_PALETTE_BPP / BITS_IN_BYTE; s32 size = sprite->size * sprite->size * TIC_PALETTE_BPP / BITS_IN_BYTE;
u8* buffer = SDL_malloc(size); u8* buffer = malloc(size);
if(buffer) if(buffer)
{ {
SDL_Rect rect = getSpriteRect(sprite); tic_rect rect = getSpriteRect(sprite);
s32 r = rect.x + rect.w; s32 r = rect.x + rect.w;
s32 b = rect.y + rect.h; s32 b = rect.y + rect.h;
@ -1351,7 +1350,7 @@ static void copyToClipboard(Sprite* sprite)
toClipboard(buffer, size, true); toClipboard(buffer, size, true);
SDL_free(buffer); free(buffer);
} }
} }
@ -1367,13 +1366,13 @@ static void copyFromClipboard(Sprite* sprite)
pasteColor(sprite); pasteColor(sprite);
s32 size = sprite->size * sprite->size * TIC_PALETTE_BPP / BITS_IN_BYTE; s32 size = sprite->size * sprite->size * TIC_PALETTE_BPP / BITS_IN_BYTE;
u8* buffer = SDL_malloc(size); u8* buffer = malloc(size);
if(buffer) if(buffer)
{ {
if(fromClipboard(buffer, size, true, false)) if(fromClipboard(buffer, size, true, false))
{ {
SDL_Rect rect = getSpriteRect(sprite); tic_rect rect = getSpriteRect(sprite);
s32 r = rect.x + rect.w; s32 r = rect.x + rect.w;
s32 b = rect.y + rect.h; s32 b = rect.y + rect.h;
@ -1384,7 +1383,7 @@ static void copyFromClipboard(Sprite* sprite)
history_add(sprite->history); history_add(sprite->history);
} }
SDL_free(buffer); free(buffer);
} }
} }
@ -1428,9 +1427,13 @@ static void switchBanks(Sprite* sprite)
clearCanvasSelection(sprite); clearCanvasSelection(sprite);
} }
static void processKeydown(Sprite* sprite, SDL_Keycode keycode) static void processKeyboard(Sprite* sprite)
{ {
switch(getClipboardEvent(keycode)) tic_mem* tic = sprite->tic;
if(tic->ram.input.keyboard.data == 0) return;
switch(getClipboardEvent())
{ {
case TIC_CLIPBOARD_CUT: cutToClipboard(sprite); break; case TIC_CLIPBOARD_CUT: cutToClipboard(sprite); break;
case TIC_CLIPBOARD_COPY: copyToClipboard(sprite); break; case TIC_CLIPBOARD_COPY: copyToClipboard(sprite); break;
@ -1438,66 +1441,49 @@ static void processKeydown(Sprite* sprite, SDL_Keycode keycode)
default: break; default: break;
} }
SDL_Keymod keymod = SDL_GetModState(); bool ctrl = tic->api.key(tic, tic_key_ctrl);
if(keymod & TIC_MOD_CTRL) if(ctrl)
{ {
switch(keycode) if(keyWasPressed(tic_key_z)) undo(sprite);
{ else if(keyWasPressed(tic_key_y)) redo(sprite);
case SDLK_z: undo(sprite); break;
case SDLK_y: redo(sprite); break;
}
} }
else else
{ {
if(hasCanvasSelection(sprite)) if(hasCanvasSelection(sprite))
{ {
switch(keycode) if(keyWasPressed(tic_key_up)) upCanvas(sprite);
{ else if(keyWasPressed(tic_key_down)) downCanvas(sprite);
case SDLK_UP: upCanvas(sprite); break; else if(keyWasPressed(tic_key_left)) leftCanvas(sprite);
case SDLK_DOWN: downCanvas(sprite); break; else if(keyWasPressed(tic_key_right)) rightCanvas(sprite);
case SDLK_LEFT: leftCanvas(sprite); break; else if(keyWasPressed(tic_key_delete)) deleteCanvas(sprite);
case SDLK_RIGHT: rightCanvas(sprite); break;
case SDLK_DELETE: deleteCanvas(sprite); break;
}
} }
else else
{ {
switch(keycode) if(keyWasPressed(tic_key_up)) upSprite(sprite);
{ else if(keyWasPressed(tic_key_down)) downSprite(sprite);
case SDLK_DELETE: deleteSprite(sprite); break; else if(keyWasPressed(tic_key_left)) leftSprite(sprite);
case SDLK_UP: upSprite(sprite); break; else if(keyWasPressed(tic_key_right)) rightSprite(sprite);
case SDLK_DOWN: downSprite(sprite); break; else if(keyWasPressed(tic_key_delete)) deleteSprite(sprite);
case SDLK_LEFT: leftSprite(sprite); break; else if(keyWasPressed(tic_key_tab)) switchBanks(sprite);
case SDLK_RIGHT: rightSprite(sprite); break;
case SDLK_TAB: switchBanks(sprite); break;
}
if(!sprite->editPalette) if(!sprite->editPalette)
{ {
switch(keycode)
{ if(keyWasPressed(tic_key_1)) sprite->mode = SPRITE_DRAW_MODE;
case SDLK_1: else if(keyWasPressed(tic_key_2)) sprite->mode = SPRITE_PICK_MODE;
case SDLK_2: else if(keyWasPressed(tic_key_3)) sprite->mode = SPRITE_SELECT_MODE;
case SDLK_3: else if(keyWasPressed(tic_key_4)) sprite->mode = SPRITE_FILL_MODE;
case SDLK_4:
sprite->mode = keycode - SDLK_1; else if(keyWasPressed(tic_key_5)) flipSpriteHorz(sprite);
break; else if(keyWasPressed(tic_key_6)) flipSpriteVert(sprite);
case SDLK_5: else if(keyWasPressed(tic_key_7)) rotateSprite(sprite);
case SDLK_6: else if(keyWasPressed(tic_key_8)) deleteSprite(sprite);
case SDLK_7:
case SDLK_8:
SpriteToolsFunc[keycode - SDLK_5](sprite);
break;
}
if(sprite->mode == SPRITE_DRAW_MODE) if(sprite->mode == SPRITE_DRAW_MODE)
{ {
switch(keycode) if(keyWasPressed(tic_key_leftbracket)) {if(sprite->brushSize > 1) sprite->brushSize--;}
{ else if(keyWasPressed(tic_key_rightbracket)) {if(sprite->brushSize < 4) sprite->brushSize++;}
case SDLK_LEFTBRACKET: if(sprite->brushSize > 1) sprite->brushSize--; break;
case SDLK_RIGHTBRACKET: if(sprite->brushSize < 4) sprite->brushSize++; break;
}
} }
} }
} }
@ -1510,15 +1496,15 @@ static void drawSpriteToolbar(Sprite* sprite)
// draw sprite size control // draw sprite size control
{ {
SDL_Rect rect = {TIC80_WIDTH - 58, 1, 23, 5}; tic_rect rect = {TIC80_WIDTH - 58, 1, 23, 5};
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
showTooltip("CANVAS ZOOM"); showTooltip("CANVAS ZOOM");
if(checkMouseDown(&rect, SDL_BUTTON_LEFT)) if(checkMouseDown(&rect, tic_mouse_left))
{ {
s32 mx = getMouseX() - rect.x; s32 mx = getMouseX() - rect.x;
mx /= 6; mx /= 6;
@ -1547,17 +1533,17 @@ static void drawSpriteToolbar(Sprite* sprite)
{ {
static const char Label[] = "BG"; static const char Label[] = "BG";
SDL_Rect rect = {TIC80_WIDTH - 2 * TIC_FONT_WIDTH - 2, 0, 2 * TIC_FONT_WIDTH + 1, TIC_SPRITESIZE-1}; tic_rect rect = {TIC80_WIDTH - 2 * TIC_FONT_WIDTH - 2, 0, 2 * TIC_FONT_WIDTH + 1, TIC_SPRITESIZE-1};
sprite->tic->api.rect(sprite->tic, rect.x, rect.y, rect.w, rect.h, bg ? (tic_color_black) : (tic_color_gray)); sprite->tic->api.rect(sprite->tic, rect.x, rect.y, rect.w, rect.h, bg ? (tic_color_black) : (tic_color_gray));
sprite->tic->api.fixed_text(sprite->tic, Label, rect.x+1, rect.y+1, (tic_color_white)); sprite->tic->api.fixed_text(sprite->tic, Label, rect.x+1, rect.y+1, (tic_color_white));
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
showTooltip("TILES [tab]"); showTooltip("TILES [tab]");
if(!bg && checkMouseClick(&rect, SDL_BUTTON_LEFT)) if(!bg && checkMouseClick(&rect, tic_mouse_left))
{ {
sprite->index -= TIC_BANK_SPRITES; sprite->index -= TIC_BANK_SPRITES;
clearCanvasSelection(sprite); clearCanvasSelection(sprite);
@ -1567,17 +1553,17 @@ static void drawSpriteToolbar(Sprite* sprite)
{ {
static const char Label[] = "FG"; static const char Label[] = "FG";
SDL_Rect rect = {TIC80_WIDTH - 4 * TIC_FONT_WIDTH - 4, 0, 2 * TIC_FONT_WIDTH + 1, TIC_SPRITESIZE-1}; tic_rect rect = {TIC80_WIDTH - 4 * TIC_FONT_WIDTH - 4, 0, 2 * TIC_FONT_WIDTH + 1, TIC_SPRITESIZE-1};
sprite->tic->api.rect(sprite->tic, rect.x, rect.y, rect.w, rect.h, bg ? (tic_color_gray) : (tic_color_black)); sprite->tic->api.rect(sprite->tic, rect.x, rect.y, rect.w, rect.h, bg ? (tic_color_gray) : (tic_color_black));
sprite->tic->api.fixed_text(sprite->tic, Label, rect.x+1, rect.y+1, (tic_color_white)); sprite->tic->api.fixed_text(sprite->tic, Label, rect.x+1, rect.y+1, (tic_color_white));
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
showTooltip("SPRITES [tab]"); showTooltip("SPRITES [tab]");
if(bg && checkMouseClick(&rect, SDL_BUTTON_LEFT)) if(bg && checkMouseClick(&rect, tic_mouse_left))
{ {
sprite->index += TIC_BANK_SPRITES; sprite->index += TIC_BANK_SPRITES;
clearCanvasSelection(sprite); clearCanvasSelection(sprite);
@ -1588,32 +1574,27 @@ static void drawSpriteToolbar(Sprite* sprite)
static void tick(Sprite* sprite) static void tick(Sprite* sprite)
{ {
// process scroll
SDL_Event* event = NULL;
while ((event = pollEvent()))
{ {
switch(event->type) tic80_input* input = &sprite->tic->ram.input;
if(input->mouse.scrolly)
{ {
case SDL_KEYDOWN: s32 size = sprite->size;
processKeydown(sprite, event->key.keysym.sym); s32 delta = input->mouse.scrolly;
break;
case SDL_MOUSEWHEEL: if(delta > 0)
{ {
s32 size = sprite->size; if(size < (TIC_SPRITESIZE * TIC_SPRITESIZE)) size <<= 1;
s32 delta = event->wheel.y;
if(delta > 0)
{
if(size < (TIC_SPRITESIZE * TIC_SPRITESIZE)) size <<= 1;
}
else if(size > TIC_SPRITESIZE) size >>= 1;
updateSpriteSize(sprite, size);
} }
break; else if(size > TIC_SPRITESIZE) size >>= 1;
updateSpriteSize(sprite, size);
} }
} }
processKeyboard(sprite);
sprite->tic->api.clear(sprite->tic, (tic_color_gray)); sprite->tic->api.clear(sprite->tic, (tic_color_gray));
drawCanvas(sprite, 24, 20); drawCanvas(sprite, 24, 20);
@ -1658,8 +1639,8 @@ static void overlap(tic_mem* tic, void* data)
void initSprite(Sprite* sprite, tic_mem* tic, tic_tiles* src) void initSprite(Sprite* sprite, tic_mem* tic, tic_tiles* src)
{ {
if(sprite->select.back == NULL) sprite->select.back = (u8*)SDL_malloc(CANVAS_SIZE*CANVAS_SIZE); if(sprite->select.back == NULL) sprite->select.back = (u8*)malloc(CANVAS_SIZE*CANVAS_SIZE);
if(sprite->select.front == NULL) sprite->select.front = (u8*)SDL_malloc(CANVAS_SIZE*CANVAS_SIZE); if(sprite->select.front == NULL) sprite->select.front = (u8*)malloc(CANVAS_SIZE*CANVAS_SIZE);
if(sprite->history) history_delete(sprite->history); if(sprite->history) history_delete(sprite->history);
*sprite = (Sprite) *sprite = (Sprite)

View File

@ -44,8 +44,8 @@ struct Sprite
struct struct
{ {
SDL_Rect rect; tic_rect rect;
SDL_Point start; tic_point start;
bool drag; bool drag;
u8* back; u8* back;
u8* front; u8* front;

View File

@ -78,8 +78,6 @@ static void tick(Start* start)
start->initialized = true; start->initialized = true;
} }
while (pollEvent());
start->tic->api.clear(start->tic, TIC_COLOR_BG); start->tic->api.clear(start->tic, TIC_COLOR_BG);
static void(*const steps[])(Start*) = {reset, header, end}; static void(*const steps[])(Start*) = {reset, header, end};

File diff suppressed because it is too large Load Diff

View File

@ -27,22 +27,16 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <SDL.h>
#if defined(__EMSCRIPTEN__)
#include <emscripten.h>
#endif
#include "tic.h" #include "tic.h"
#include "ticapi.h" #include "ticapi.h"
#include "defines.h" #include "defines.h"
#include "tools.h" #include "tools.h"
#include "ext/file_dialog.h"
#include "system.h"
#define TIC_LOCAL ".local/" #define TIC_LOCAL ".local/"
#define TIC_CACHE TIC_LOCAL "cache/" #define TIC_CACHE TIC_LOCAL "cache/"
#define TIC_MOD_CTRL (KMOD_GUI|KMOD_CTRL)
#define TOOLBAR_SIZE 7 #define TOOLBAR_SIZE 7
#define STUDIO_TEXT_WIDTH (TIC_FONT_WIDTH) #define STUDIO_TEXT_WIDTH (TIC_FONT_WIDTH)
#define STUDIO_TEXT_HEIGHT (TIC_FONT_HEIGHT+1) #define STUDIO_TEXT_HEIGHT (TIC_FONT_HEIGHT+1)
@ -55,8 +49,8 @@
#define CONFIG_TIC "config " TIC_VERSION_LABEL ".tic" #define CONFIG_TIC "config " TIC_VERSION_LABEL ".tic"
#define CONFIG_TIC_PATH TIC_LOCAL CONFIG_TIC #define CONFIG_TIC_PATH TIC_LOCAL CONFIG_TIC
#define KEYMAP_COUNT (sizeof(tic80_input) * BITS_IN_BYTE) #define KEYMAP_COUNT (sizeof(tic80_gamepads) * BITS_IN_BYTE)
#define KEYMAP_SIZE (KEYMAP_COUNT * sizeof(SDL_Scancode)) #define KEYMAP_SIZE (KEYMAP_COUNT)
#define KEYMAP_DAT "keymap.dat" #define KEYMAP_DAT "keymap.dat"
#define KEYMAP_DAT_PATH TIC_LOCAL KEYMAP_DAT #define KEYMAP_DAT_PATH TIC_LOCAL KEYMAP_DAT
@ -66,47 +60,6 @@
#define PROJECT_JS_EXT ".js" #define PROJECT_JS_EXT ".js"
#define PROJECT_WREN_EXT ".wren" #define PROJECT_WREN_EXT ".wren"
typedef struct
{
struct
{
struct
{
s32 sprite;
bool pixelPerfect;
} cursor;
struct
{
tic_code_theme syntax;
u8 bg;
u8 select;
u8 cursor;
bool shadow;
} code;
struct
{
struct
{
u8 alpha;
} touch;
} gamepad;
} theme;
s32 gifScale;
s32 gifLength;
bool checkNewVersion;
bool noSound;
bool useVsync;
bool showSync;
} StudioConfig;
typedef enum typedef enum
{ {
TIC_START_MODE, TIC_START_MODE,
@ -123,18 +76,23 @@ typedef enum
TIC_SURF_MODE, TIC_SURF_MODE,
} EditorMode; } EditorMode;
SDL_Event* pollEvent(); typedef struct
void setCursor(SDL_SystemCursor id); {
s32 x, y;
} tic_point;
typedef struct
{
s32 x, y, w, h;
} tic_rect;
void setCursor(tic_cursor id);
s32 getMouseX(); s32 getMouseX();
s32 getMouseY(); s32 getMouseY();
bool checkMousePos(const SDL_Rect* rect); bool checkMousePos(const tic_rect* rect);
bool checkMouseClick(const SDL_Rect* rect, s32 button); bool checkMouseClick(const tic_rect* rect, tic_mouse_btn button);
bool checkMouseDown(const SDL_Rect* rect, s32 button); bool checkMouseDown(const tic_rect* rect, tic_mouse_btn button);
bool getGesturePos(SDL_Point* pos);
const u8* getKeyboard();
void drawToolbar(tic_mem* tic, u8 color, bool bg); void drawToolbar(tic_mem* tic, u8 color, bool bg);
void drawBitIcon(s32 x, s32 y, const u8* ptr, u8 color); void drawBitIcon(s32 x, s32 y, const u8* ptr, u8 color);
@ -161,7 +119,7 @@ typedef enum
TIC_CLIPBOARD_PASTE, TIC_CLIPBOARD_PASTE,
} ClipboardEvent; } ClipboardEvent;
ClipboardEvent getClipboardEvent(SDL_Keycode keycode); ClipboardEvent getClipboardEvent();
typedef enum typedef enum
{ {
@ -175,9 +133,7 @@ typedef enum
void setStudioEvent(StudioEvent event); void setStudioEvent(StudioEvent event);
void showTooltip(const char* text); void showTooltip(const char* text);
SDL_Scancode* getKeymap(); tic_key* getKeymap();
const StudioConfig* getConfig();
void setSpritePixel(tic_tile* tiles, s32 x, s32 y, u8 color); void setSpritePixel(tic_tile* tiles, s32 x, s32 y, u8 color);
u8 getSpritePixel(tic_tile* tiles, s32 x, s32 y); u8 getSpritePixel(tic_tile* tiles, s32 x, s32 y);
@ -199,3 +155,10 @@ void runProject();
tic_tiles* getBankTiles(); tic_tiles* getBankTiles();
tic_map* getBankMap(); tic_map* getBankMap();
char getKeyboardText();
bool keyWasPressed(tic_key key);
bool anyKeyWasPressed();
const StudioConfig* getConfig();
System* getSystem();

View File

@ -22,7 +22,6 @@
#include "surf.h" #include "surf.h"
#include "fs.h" #include "fs.h"
#include "net.h"
#include "console.h" #include "console.h"
#include "ext/gif.h" #include "ext/gif.h"
@ -38,7 +37,7 @@
#define COVER_Y 5 #define COVER_Y 5
#define COVER_X (TIC80_WIDTH - COVER_WIDTH - COVER_Y) #define COVER_X (TIC80_WIDTH - COVER_WIDTH - COVER_Y)
#if defined(__WINDOWS__) || defined(__LINUX__) || defined(__MACOSX__) #if defined(__TIC_WINDOWS__) || defined(__TIC_LINUX__) || defined(__TIC_MACOSX__)
#define CAN_OPEN_URL 1 #define CAN_OPEN_URL 1
#endif #endif
@ -401,18 +400,18 @@ static bool addMenuItem(const char* name, const char* info, s32 id, void* ptr, b
{ {
MenuItem* item = &data->items[data->count++]; MenuItem* item = &data->items[data->count++];
item->name = SDL_strdup(name); item->name = strdup(name);
bool project = false; bool project = false;
if(dir) if(dir)
{ {
char folder[FILENAME_MAX]; char folder[FILENAME_MAX];
sprintf(folder, "[%s]", name); sprintf(folder, "[%s]", name);
item->label = SDL_strdup(folder); item->label = strdup(folder);
} }
else else
{ {
item->label = SDL_strdup(name); item->label = strdup(name);
if(hasExt(name, CartExt)) if(hasExt(name, CartExt))
cutExt(item->label, CartExt); cutExt(item->label, CartExt);
@ -426,7 +425,7 @@ static bool addMenuItem(const char* name, const char* info, s32 id, void* ptr, b
replace(item->label, "&#39;", "'"); replace(item->label, "&#39;", "'");
} }
item->hash = info ? SDL_strdup(info) : NULL; item->hash = info ? strdup(info) : NULL;
item->id = id; item->id = id;
item->dir = dir; item->dir = dir;
item->cover = NULL; item->cover = NULL;
@ -442,19 +441,19 @@ static void resetMenu(Surf* surf)
{ {
for(s32 i = 0; i < surf->menu.count; i++) for(s32 i = 0; i < surf->menu.count; i++)
{ {
SDL_free((void*)surf->menu.items[i].name); free((void*)surf->menu.items[i].name);
const char* hash = surf->menu.items[i].hash; const char* hash = surf->menu.items[i].hash;
if(hash) SDL_free((void*)hash); if(hash) free((void*)hash);
tic_screen* cover = surf->menu.items[i].cover; tic_screen* cover = surf->menu.items[i].cover;
if(cover) SDL_free(cover); if(cover) free(cover);
const char* label = surf->menu.items[i].label; const char* label = surf->menu.items[i].label;
if(label) SDL_free((void*)label); if(label) free((void*)label);
} }
SDL_free(surf->menu.items); free(surf->menu.items);
surf->menu.items = NULL; surf->menu.items = NULL;
surf->menu.count = 0; surf->menu.count = 0;
@ -478,7 +477,7 @@ static void* requestCover(Surf* surf, const char* hash, s32* size)
char path[FILENAME_MAX] = {0}; char path[FILENAME_MAX] = {0};
sprintf(path, "/cart/%s/cover.gif", hash); sprintf(path, "/cart/%s/cover.gif", hash);
void* data = netGetRequest(surf->net, path, size); void* data = getSystem()->getUrlRequest(path, size);
if(data) if(data)
{ {
@ -494,8 +493,7 @@ static void updateMenuItemCover(Surf* surf, const u8* cover, s32 size)
MenuItem* item = &surf->menu.items[surf->menu.pos]; MenuItem* item = &surf->menu.items[surf->menu.pos];
item->cover = malloc(sizeof(tic_screen));
item->cover = SDL_malloc(sizeof(tic_screen));
gif_image* image = gif_read_data(cover, size); gif_image* image = gif_read_data(cover, size);
@ -532,7 +530,7 @@ static void loadCover(Surf* surf)
if(data) if(data)
{ {
tic_cartridge* cart = (tic_cartridge*)SDL_malloc(sizeof(tic_cartridge)); tic_cartridge* cart = (tic_cartridge*)malloc(sizeof(tic_cartridge));
if(cart) if(cart)
{ {
@ -544,10 +542,10 @@ static void loadCover(Surf* surf)
if(cart->cover.size) if(cart->cover.size)
updateMenuItemCover(surf, cart->cover.data, cart->cover.size); updateMenuItemCover(surf, cart->cover.data, cart->cover.size);
SDL_free(cart); free(cart);
} }
SDL_free(data); free(data);
} }
} }
else if(item->hash && !item->cover) else if(item->hash && !item->cover)
@ -559,7 +557,7 @@ static void loadCover(Surf* surf)
if(cover) if(cover)
{ {
updateMenuItemCover(surf, cover, size); updateMenuItemCover(surf, cover, size);
SDL_free(cover); free(cover);
} }
} }
} }
@ -573,7 +571,7 @@ static void initMenu(Surf* surf)
AddMenuItem data = AddMenuItem data =
{ {
.items = SDL_malloc(Size), .items = malloc(Size),
.count = 0, .count = 0,
.surf = surf, .surf = surf,
}; };
@ -649,7 +647,7 @@ static void onPlayCart(Surf* surf)
if(item->project) if(item->project)
{ {
tic_cartridge* cart = SDL_malloc(sizeof(tic_cartridge)); tic_cartridge* cart = malloc(sizeof(tic_cartridge));
if(cart) if(cart)
{ {
@ -658,11 +656,11 @@ static void onPlayCart(Surf* surf)
surf->console->loadProject(surf->console, item->name, data, size, cart); surf->console->loadProject(surf->console, item->name, data, size, cart);
SDL_memcpy(&surf->tic->cart, cart, sizeof(tic_cartridge)); memcpy(&surf->tic->cart, cart, sizeof(tic_cartridge));
studioRomLoaded(); studioRomLoaded();
SDL_free(cart); free(cart);
} }
} }
else else
@ -782,7 +780,7 @@ static void processGamepad(Surf* surf)
{ {
char url[FILENAME_MAX]; char url[FILENAME_MAX];
sprintf(url, "https://" TIC_HOST "/play?cart=%i", item->id); sprintf(url, "https://" TIC_HOST "/play?cart=%i", item->id);
fsOpenSystemPath(surf->fs, url); getSystem()->openSystemPath(url);
} }
} }
#endif #endif
@ -804,9 +802,6 @@ static void tick(Surf* surf)
surf->ticks++; surf->ticks++;
while (pollEvent());
tic_mem* tic = surf->tic; tic_mem* tic = surf->tic;
tic->api.clear(tic, TIC_COLOR_BG); tic->api.clear(tic, TIC_COLOR_BG);
@ -865,7 +860,6 @@ void initSurf(Surf* surf, tic_mem* tic, struct Console* console)
.items = NULL, .items = NULL,
.count = 0, .count = 0,
}, },
.net = createNet(),
}; };
fsMakeDir(surf->fs, TIC_CACHE); fsMakeDir(surf->fs, TIC_CACHE);

View File

@ -31,7 +31,6 @@ struct Surf
tic_mem* tic; tic_mem* tic;
struct FileSystem* fs; struct FileSystem* fs;
struct Console* console; struct Console* console;
struct Net* net;
struct Movie* state; struct Movie* state;
bool init; bool init;

1157
src/system.c Normal file

File diff suppressed because it is too large Load Diff

87
src/system.h Normal file
View File

@ -0,0 +1,87 @@
#pragma once
#include "ticapi.h"
#include "ext/file_dialog.h"
typedef struct
{
void (*setClipboardText)(const char* text);
bool (*hasClipboardText)();
char* (*getClipboardText)();
u64 (*getPerformanceCounter)();
u64 (*getPerformanceFrequency)();
void* (*getUrlRequest)(const char* url, s32* size);
void (*fileDialogLoad)(file_dialog_load_callback callback, void* data);
void (*fileDialogSave)(file_dialog_save_callback callback, const char* name, const u8* buffer, size_t size, void* data, u32 mode);
void (*goFullscreen)();
void (*showMessageBox)(const char* title, const char* message);
void (*setWindowTitle)(const char* title);
void (*openSystemPath)(const char* path);
void (*preseed)();
void (*poll)();
} System;
typedef struct
{
struct
{
struct
{
s32 arrow;
s32 hand;
s32 ibeam;
bool pixelPerfect;
} cursor;
struct
{
tic_code_theme syntax;
u8 bg;
u8 select;
u8 cursor;
bool shadow;
} code;
struct
{
struct
{
u8 alpha;
} touch;
} gamepad;
} theme;
s32 gifScale;
s32 gifLength;
bool checkNewVersion;
bool noSound;
bool useVsync;
bool showSync;
} StudioConfig;
typedef struct
{
tic_mem* tic;
bool quit;
void (*tick)(void* pixels);
void (*exit)();
void (*close)();
void (*updateProject)();
const StudioConfig* (*config)();
} Studio;
TIC80_API Studio* studioInit(s32 argc, char **argv, s32 samplerate, const char* appFolder, System* system);

View File

@ -1264,7 +1264,7 @@ static bool isNoiseWaveform(const tic_waveform* wave)
static bool isKeyPressed(const tic80_keyboard* input, tic_key key) static bool isKeyPressed(const tic80_keyboard* input, tic_key key)
{ {
for(s32 i = 0; i < TIC_KEY_BUFFER; i++) for(s32 i = 0; i < TIC80_KEY_BUFFER; i++)
if(input->keys[i] == key) if(input->keys[i] == key)
return true; return true;
@ -1696,7 +1696,7 @@ static bool api_keyp(tic_mem* tic, tic_key key, s32 hold, s32 period)
return !prevDown && down; return !prevDown && down;
} }
for(s32 i = 0; i < TIC_KEY_BUFFER; i++) for(s32 i = 0; i < TIC80_KEY_BUFFER; i++)
{ {
tic_key key = tic->ram.input.keyboard.keys[i]; tic_key key = tic->ram.input.keyboard.keys[i];
@ -1704,7 +1704,7 @@ static bool api_keyp(tic_mem* tic, tic_key key, s32 hold, s32 period)
{ {
bool wasPressed = false; bool wasPressed = false;
for(s32 p = 0; p < TIC_KEY_BUFFER; p++) for(s32 p = 0; p < TIC80_KEY_BUFFER; p++)
{ {
if(machine->state.keyboard.previous.keys[p] == key) if(machine->state.keyboard.previous.keys[p] == key)
{ {
@ -1721,7 +1721,6 @@ static bool api_keyp(tic_mem* tic, tic_key key, s32 hold, s32 period)
return false; return false;
} }
static void api_load(tic_cartridge* cart, const u8* buffer, s32 size, bool palette) static void api_load(tic_cartridge* cart, const u8* buffer, s32 size, bool palette)
{ {
const u8* end = buffer + size; const u8* end = buffer + size;

View File

@ -385,7 +385,12 @@ typedef union
s8 y; s8 y;
} offset; } offset;
u8 cursor; struct
{
u8 sprite:7;
bool system:1;
} cursor;
} vars; } vars;
u8 reserved[4]; u8 reserved[4];
@ -418,7 +423,7 @@ typedef union
u8 data[TIC_RAM_SIZE]; u8 data[TIC_RAM_SIZE];
} tic_ram; } tic_ram;
enum typedef enum
{ {
tic_key_unknown, tic_key_unknown,
@ -511,4 +516,18 @@ enum
//////////////// ////////////////
tic_keys_count tic_keys_count
}; } tic_keycode;
typedef enum
{
tic_mouse_left,
tic_mouse_middle,
tic_mouse_right,
} tic_mouse_btn;
typedef enum
{
tic_cursor_arrow,
tic_cursor_hand,
tic_cursor_ibeam,
} tic_cursor;

View File

@ -104,6 +104,7 @@ TIC80_API void tic80_load(tic80* tic, void* cart, s32 size)
tic80->tickData.start = 0; tic80->tickData.start = 0;
tic80->tickData.freq = getFreq; tic80->tickData.freq = getFreq;
tic80->tickData.counter = getCounter; tic80->tickData.counter = getCounter;
tic80->tickData.syncPMEM = false;
TickCounter = 0; TickCounter = 0;
} }

View File

@ -58,6 +58,8 @@ typedef struct
u64 (*freq)(); u64 (*freq)();
u64 start; u64 start;
bool syncPMEM;
void (*preprocessor)(void* data, char* dst); void (*preprocessor)(void* data, char* dst);
void* data; void* data;

View File

@ -51,4 +51,4 @@ bool tic_tool_parse_note(const char* noteStr, s32* note, s32* octave);
s32 tic_tool_get_pattern_id(const tic_track* track, s32 frame, s32 channel); s32 tic_tool_get_pattern_id(const tic_track* track, s32 frame, s32 channel);
void tic_tool_set_pattern_id(tic_track* track, s32 frame, s32 channel, s32 id); void tic_tool_set_pattern_id(tic_track* track, s32 frame, s32 channel, s32 id);
u32 tic_tool_find_closest_color(const tic_rgb* palette, const tic_rgb* color); u32 tic_tool_find_closest_color(const tic_rgb* palette, const tic_rgb* color);
u32* tic_palette_blit(const tic_palette* src); u32* tic_palette_blit(const tic_palette* src);

View File

@ -38,22 +38,22 @@ static void drawGrid(World* world)
world->tic->api.rect_border(world->tic, 0, 0, TIC80_WIDTH, TIC80_HEIGHT, color); world->tic->api.rect_border(world->tic, 0, 0, TIC80_WIDTH, TIC80_HEIGHT, color);
SDL_Rect rect = {0, 0, TIC80_WIDTH, TIC80_HEIGHT}; tic_rect rect = {0, 0, TIC80_WIDTH, TIC80_HEIGHT};
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
setCursor(SDL_SYSTEM_CURSOR_HAND); setCursor(tic_cursor_hand);
s32 mx = getMouseX(); s32 mx = getMouseX();
s32 my = getMouseY(); s32 my = getMouseY();
if(checkMouseDown(&rect, SDL_BUTTON_LEFT)) if(checkMouseDown(&rect, tic_mouse_left))
{ {
map->scroll.x = (mx - TIC_MAP_SCREEN_WIDTH/2) * TIC_SPRITESIZE; map->scroll.x = (mx - TIC_MAP_SCREEN_WIDTH/2) * TIC_SPRITESIZE;
map->scroll.y = (my - TIC_MAP_SCREEN_HEIGHT/2) * TIC_SPRITESIZE; map->scroll.y = (my - TIC_MAP_SCREEN_HEIGHT/2) * TIC_SPRITESIZE;
} }
if(checkMouseClick(&rect, SDL_BUTTON_LEFT)) if(checkMouseClick(&rect, tic_mouse_left))
setStudioMode(TIC_MAP_MODE); setStudioMode(TIC_MAP_MODE);
} }
@ -61,28 +61,11 @@ static void drawGrid(World* world)
TIC_MAP_SCREEN_WIDTH+1, TIC_MAP_SCREEN_HEIGHT+1, (tic_color_red)); TIC_MAP_SCREEN_WIDTH+1, TIC_MAP_SCREEN_HEIGHT+1, (tic_color_red));
} }
static void processKeydown(World* world, SDL_Keycode keycode)
{
switch(keycode)
{
case SDLK_TAB: setStudioMode(TIC_MAP_MODE); break;
}
}
static void tick(World* world) static void tick(World* world)
{ {
SDL_Event* event = NULL; if(keyWasPressed(tic_key_tab)) setStudioMode(TIC_MAP_MODE);
while ((event = pollEvent()))
{
switch(event->type)
{
case SDL_KEYDOWN:
processKeydown(world, event->key.keysym.sym);
break;
}
}
SDL_memcpy(&world->tic->ram.vram, world->preview, PREVIEW_SIZE); memcpy(&world->tic->ram.vram, world->preview, PREVIEW_SIZE);
drawGrid(world); drawGrid(world);
} }
@ -90,7 +73,7 @@ static void tick(World* world)
void initWorld(World* world, tic_mem* tic, Map* map) void initWorld(World* world, tic_mem* tic, Map* map)
{ {
if(!world->preview) if(!world->preview)
world->preview = SDL_malloc(PREVIEW_SIZE); world->preview = malloc(PREVIEW_SIZE);
*world = (World) *world = (World)
{ {
@ -100,7 +83,7 @@ void initWorld(World* world, tic_mem* tic, Map* map)
.preview = world->preview, .preview = world->preview,
}; };
SDL_memset(world->preview, 0, PREVIEW_SIZE); memset(world->preview, 0, PREVIEW_SIZE);
s32 colors[TIC_PALETTE_SIZE]; s32 colors[TIC_PALETTE_SIZE];
for(s32 i = 0; i < TIC80_WIDTH * TIC80_HEIGHT; i++) for(s32 i = 0; i < TIC80_WIDTH * TIC80_HEIGHT; i++)
@ -109,7 +92,7 @@ void initWorld(World* world, tic_mem* tic, Map* map)
if(index) if(index)
{ {
SDL_memset(colors, 0, sizeof colors); memset(colors, 0, sizeof colors);
tic_tile* tile = &getBankTiles()->data[index]; tic_tile* tile = &getBankTiles()->data[index];
@ -123,11 +106,10 @@ void initWorld(World* world, tic_mem* tic, Map* map)
s32 max = 0; s32 max = 0;
for(s32 c = 0; c < SDL_arraysize(colors); c++) for(s32 c = 0; c < COUNT_OF(colors); c++)
if(colors[c] > colors[max]) max = c; if(colors[c] > colors[max]) max = c;
tic_tool_poke4(world->preview, i, max); tic_tool_poke4(world->preview, i, max);
} }
} }
} }

View File

@ -905,6 +905,7 @@ static void wren_pmem(WrenVM* vm)
if(top > 2) if(top > 2)
{ {
memory->persistent.data[index] = getWrenNumber(vm, 2); memory->persistent.data[index] = getWrenNumber(vm, 2);
machine->data->syncPMEM = true;
} }
wrenSetSlotDouble(vm, 0, val); wrenSetSlotDouble(vm, 0, val);