From 921978c3d72c4167332cf4fcca9a68bd40e74de8 Mon Sep 17 00:00:00 2001 From: mandel99 <4213037+mandel99@users.noreply.github.com> Date: Thu, 2 Jul 2026 21:35:26 +0200 Subject: [PATCH] Improve build scripts and lower Crinkler hash size --- build-tiny.bat | 66 ++++++++++++++++++++++++++++++++++++++++++++++ build.bat | 71 +++++++++++++++++++++++++++++++++++++++++--------- trpad.asm | 18 +++++-------- 3 files changed, 130 insertions(+), 25 deletions(-) create mode 100644 build-tiny.bat diff --git a/build-tiny.bat b/build-tiny.bat new file mode 100644 index 0000000..1049843 --- /dev/null +++ b/build-tiny.bat @@ -0,0 +1,66 @@ +@echo off +setlocal + +set "INCDIR=C:\masm32\include" +if not exist "%INCDIR%\windows.inc" ( + echo Missing MASM include dir: "%INCDIR%" + exit /b 1 +) + +set "MLCMD=" +for /f "delims=" %%I in ('where ml 2^>nul') do ( + set "MLCMD=%%I" + goto :found_ml +) +if exist "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" ( + for /f "delims=" %%I in ('"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -find VC\Tools\MSVC\**\bin\Hostx64\x86\ml.exe 2^>nul') do ( + set "MLCMD=%%I" + goto :found_ml + ) +) +echo Could not find ml.exe +exit /b 1 + +:found_ml +set "CRINKLER=" +for /f "delims=" %%I in ('where crinkler 2^>nul') do ( + set "CRINKLER=%%I" + goto :found_crinkler +) +if exist "%LOCALAPPDATA%\Tools\Crinkler\crinkler30a\Win32\Crinkler.exe" ( + set "CRINKLER=%LOCALAPPDATA%\Tools\Crinkler\crinkler30a\Win32\Crinkler.exe" + goto :found_crinkler +) +echo Could not find Crinkler.exe +exit /b 1 + +:found_crinkler +set "SDKLIB=" +for /f "delims=" %%I in ('dir /b /ad /o-n "C:\Program Files (x86)\Windows Kits\10\Lib" 2^>nul') do ( + if exist "C:\Program Files (x86)\Windows Kits\10\Lib\%%I\um\x86\kernel32.lib" ( + set "SDKLIB=C:\Program Files (x86)\Windows Kits\10\Lib\%%I\um\x86" + goto :found_sdklib + ) +) +echo Could not find Windows SDK x86 libs +exit /b 1 + +:found_sdklib +"%MLCMD%" /nologo /c /coff /Cp /I"%INCDIR%" /Fotrpad.obj trpad.asm +if errorlevel 1 exit /b 1 + +"%CRINKLER%" trpad.obj ^ + /OUT:trpad-tiny.exe ^ + /ENTRY:MainEntry ^ + /SUBSYSTEM:WINDOWS ^ + /NOINITIALIZERS ^ + /TINYIMPORT ^ + /TRANSFORM:CALLS ^ + /HASHSIZE:32 ^ + /ORDERTRIES:2000 ^ + /LIBPATH:"%SDKLIB%" ^ + kernel32.lib user32.lib shell32.lib comdlg32.lib gdi32.lib +if errorlevel 1 exit /b 1 + +del trpad.obj +endlocal diff --git a/build.bat b/build.bat index 24d507b..373c046 100644 --- a/build.bat +++ b/build.bat @@ -1,13 +1,58 @@ -ml /nologo /c /coff /Cp /IC:\masm32\include trpad.asm - -crinkler trpad.obj ^ - /OUT:trpad.exe ^ - /ENTRY:MainEntry ^ - /SUBSYSTEM:WINDOWS ^ - /NOINITIALIZERS ^ - /TINYIMPORT ^ - /ORDERTRIES:2000 ^ - /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.20348.0\um\x86" ^ - kernel32.lib user32.lib shell32.lib comdlg32.lib gdi32.lib - -del trpad.obj \ No newline at end of file +@echo off +setlocal + +set "INCDIR=C:\masm32\include" +if not exist "%INCDIR%\windows.inc" ( + echo Missing MASM include dir: "%INCDIR%" + exit /b 1 +) + +set "MLCMD=" +for /f "delims=" %%I in ('where ml 2^>nul') do ( + set "MLCMD=%%I" + goto :found_ml +) +if exist "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" ( + for /f "delims=" %%I in ('"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -find VC\Tools\MSVC\**\bin\Hostx64\x86\ml.exe 2^>nul') do ( + set "MLCMD=%%I" + goto :found_ml + ) +) +echo Could not find ml.exe +exit /b 1 + +:found_ml +set "LINKCMD=" +for /f "delims=" %%I in ('where link 2^>nul') do ( + set "LINKCMD=%%I" + goto :found_link +) +if exist "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" ( + for /f "delims=" %%I in ('"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -find VC\Tools\MSVC\**\bin\Hostx64\x86\link.exe 2^>nul') do ( + set "LINKCMD=%%I" + goto :found_link + ) +) +echo Could not find link.exe +exit /b 1 + +:found_link +set "SDKLIB=" +for /f "delims=" %%I in ('dir /b /ad /o-n "C:\Program Files (x86)\Windows Kits\10\Lib" 2^>nul') do ( + if exist "C:\Program Files (x86)\Windows Kits\10\Lib\%%I\um\x86\kernel32.lib" ( + set "SDKLIB=C:\Program Files (x86)\Windows Kits\10\Lib\%%I\um\x86" + goto :found_sdklib + ) +) +echo Could not find Windows SDK x86 libs +exit /b 1 + +:found_sdklib +"%MLCMD%" /nologo /c /coff /Cp /I"%INCDIR%" /Fotrpad.obj trpad.asm +if errorlevel 1 exit /b 1 + +"%LINKCMD%" /NOLOGO /SUBSYSTEM:WINDOWS /ENTRY:MainEntry@0 /OUT:trpad.exe trpad.obj /LIBPATH:"%SDKLIB%" kernel32.lib user32.lib shell32.lib comdlg32.lib gdi32.lib +if errorlevel 1 exit /b 1 + +del trpad.obj +endlocal diff --git a/trpad.asm b/trpad.asm index 3110396..c841883 100644 --- a/trpad.asm +++ b/trpad.asm @@ -224,7 +224,6 @@ ENDIF ClassName db ".",0 ; save bytes here (seems to work) RichDll db "Msftedit",0 ; Rich Edit DLL (no ext saves those bytes) EditClass db "RICHEDIT50W",0 ; modern Rich Edit control from WinAPI -SaveText db "Save",0 ; button added to system menu EmptyText db 0 hMain dd 0 ; main window handle @@ -271,9 +270,7 @@ MStatusBar db "&Status Bar",0 MViewHelp db "&View Help",0 MAbout db "&About TinyRetroPad",0 -AboutCap db "TinyRetroPad",0 AboutText db "TinyRetroPad - tiny notepad-style editor",0 -SaveCap db "TinyRetroPad",0 SaveAskText db "Save changes?",0 SpaceText db " ",0 DateBuf db 32 dup (0) @@ -287,8 +284,6 @@ fr FINDREPLACEA <> ; shared find/replace request hFindDlg dd 0 ; modeless find/replace dialog HWND uFindMsg dd 0 ; registered FINDMSGSTRING message -StaticClass db "STATIC",0 ; built-in class for status bar pane -DocName db "TinyRetroPad",0 ; print job document name LnColFmt db " Ln %d, Col %d",0 ; status bar Ln/Col format StatusBuf db 48 dup (0) ; formatted Ln/Col text hStatus dd 0 ; status bar window handle @@ -306,7 +301,6 @@ MDarkMode db "Dark &Mode",0 ; View menu label ENDIF hInst dd 0 ; module handle (for dialogs) -OpenVerb db "open",0 ; ShellExecute verb HelpUrl db "https://github.com/davepl",0 ; in-memory Go To dialog template (no font block to stay compact) @@ -625,7 +619,7 @@ MaybeSaveChanges proc NEAR AskSave: push MB_YESNOCANCEL or MB_ICONQUESTION - push OFFSET SaveCap + push OFFSET MAbout+7 push OFFSET SaveAskText mov eax, hMain push eax @@ -1012,7 +1006,7 @@ PrintDoc proc NEAR mov ecx, SIZEOF DOCINFOA rep stosb mov docInf.cbSize, SIZEOF DOCINFOA - mov docInf.lpszDocName, OFFSET DocName + mov docInf.lpszDocName, OFFSET MAbout+7 lea eax, docInf push eax push hPrnDC @@ -2059,7 +2053,7 @@ ENDIF push FALSE push hWnd call [_imp__GetSystemMenu@8] - push OFFSET SaveText + push OFFSET MSaveMenu+1 push IDM_SAVE push MF_STRING push eax @@ -2080,7 +2074,7 @@ ENDIF push 0 push WS_CHILD or WS_VISIBLE push OFFSET StatusBuf - push OFFSET StaticClass + push 0082h push WS_EX_STATICEDGE call [_imp__CreateWindowExA@48] mov hStatus, eax @@ -2542,7 +2536,7 @@ ENDIF CmdHelpAbout: push MB_OK or MB_ICONINFORMATION - push OFFSET AboutCap + push OFFSET MAbout+7 push OFFSET AboutText push hWnd call [_imp__MessageBoxA@16] @@ -2554,7 +2548,7 @@ ENDIF push 0 push 0 push OFFSET HelpUrl - push OFFSET OpenVerb + push 0 push 0 call [_imp__ShellExecuteA@24] xor eax, eax