TARGET=i386-pc-msdos builds the library and the portable layer for 32-bit DOS with the i386-msdos sysroot of clang-retro/dos-sdk. - backend_dos.cpp: windows on a VESA 2.0 linear frame buffer (or VGA mode 13h), the mouse through INT 33h and the keyboard through the BIOS. - compat_dos.cpp: the POSIX functions that DOS does not have, and binary file mode by default. - port/compat/dos: the POSIX headers that the DOS C library does not have. - Fonts from FONTS next to the program and from the Windows fonts folder; temporary files in the current folder when TMP and TEMP are not set. - tests/run-dos-tests.sh: core, memtest, sstest and gltest in DOSBox. - build-sdk-samples.py: DOS builds of the SDK samples. - docs/dos.md, and DOS sections in the README and sdk-samples.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B82eRQsZdxGFrvneupPSAK
8.1 KiB
Samples of the Win32 SDK
tools/build-sdk-samples.py builds samples of a Win32 SDK over the
portable layer. The samples are C and C++ programs for Windows NT and
Windows 95. They build without changes to their files.
The SDK is not part of this project. Use the samples of your own copy of the SDK.
The samples
| Name | Sample | Program |
|---|---|---|
multipad |
MULTIPAD, an MDI text editor like Notepad | multipad |
3dfo |
The OpenGL screen saver 3D Flying Objects | ss3dfo.scr |
flwbox |
The OpenGL screen saver Flower Box | ssflwbox.scr |
maze |
The OpenGL screen saver Maze | ssmaze.scr |
pipes |
The OpenGL screen saver Pipes | sspipes.scr |
text3d |
The OpenGL screen saver 3D Text | sstext3d.scr |
The screen savers use the code of the SCRSAVE/COMMON folder of the SDK.
That code has its own WinMain and does not use libscrnsave.a.
Build the samples
-
Build the library for the target (
make ... static). -
Set the compiler and the flags in the environment:
Variable Value CC,CXXThe C and C++ compilers. The default is clangandclang++inBIN, or onPATH.CFLAGSThe flags for C and C++: the target, the SDK of the system and the optimization. CXXFLAGSMore flags for C++: the headers of the C++ library. LDFLAGSThe flags for the link: the target, the linker and the C++ library. MFC_OUTThe directory with libwinport.aandlibglaux.a.SYSLIBSThe system libraries. The default is -framework Cocoa -framework OpenGL -framework GLUTfor Mac OS X, and-ldl -lpthread -lmfor the other systems.MACSDKclang-retro/mac-sdk, for the classic Mac OS. Its tools/macapp.pylinks the programs. The default is../mac-sdk.HOST_CXXA C++ compiler for the host. res2cpp.pyuses it to read the macros of the layer. The default isCXX. -
Run the script:
python3 tools/build-sdk-samples.py --sdk path/to/SDK --out out--sdkis the SDK or itsSAMPLESfolder.--only pipes,mazebuilds only these samples.
The programs go into out/bin. The log of the commands goes into
out/build.log.
For Mac OS X 10.4 on PowerPC, see macosx-10.4.md for the values of the variables.
Linux and the classic Mac OS on 68k
On Linux and on the 68k Mac, the screen savers draw with the generic
implementation of OpenGL, a software renderer in libwinport.a. See
software-opengl.md. The script adds the headers
of the renderer (port/softgl/include) itself.
For Linux:
make static TARGET=x86_64-linux-gnu STDLIB= AR=ar
CFLAGS="--target=x86_64-linux-gnu" MFC_OUT=build/x86_64-linux-gnu \
python3 tools/build-sdk-samples.py --sdk path/to/SDK --out out
For the classic Mac OS on 68k (MS is the folder of mac-sdk):
make static TARGET=m68k-apple-macos BIN=path/to/llvm/bin MACSDK=$MS
L=$MS/lib
export BIN=path/to/llvm/bin MACSDK=$MS MFC_OUT=build/m68k-apple-macos HOST_CXX=clang++
export CFLAGS="--target=m68k-apple-macos -Os -mcmodel=large -femulated-tls \
-ffunction-sections -fdata-sections -D_GNU_SOURCE -isystem $PWD/port/compat/macos \
-isystem $L/include -isystem $MS/include"
export CXXFLAGS="-nostdinc++ -isystem $L/include/c++/15.2.0/m68k-apple-macos \
-isystem $L/include/c++/15.2.0 -fexceptions -frtti"
python3 tools/build-sdk-samples.py --sdk path/to/SDK --out out --only 3dfo,flwbox,maze,pipes,text3d
The programs are applications in MacBinary (out/bin/*.scr.bin). Use
-isystem, not -I, for the headers of mac-sdk. Then the GL headers
of the renderer come before the GL headers of mac-sdk, which are for
Apple OpenGL on PowerPC.
32-bit DOS
On 32-bit DOS, the screen savers draw with the generic implementation of
OpenGL. Each program is one .exe with the DOS/32A extender in it. See
dos.md.
make static TARGET=i386-pc-msdos BIN=path/to/clang-dos/bin
export BIN=path/to/clang-dos/bin MFC_OUT=build/i386-pc-msdos HOST_CXX=clang++
export CFLAGS="--target=i386-pc-msdos -O2 -ffunction-sections -fdata-sections \
-D_GNU_SOURCE -isystem $PWD/port/compat/dos"
export LDFLAGS="--target=i386-pc-msdos"
python3 tools/build-sdk-samples.py --sdk path/to/SDK --out out --only 3dfo,flwbox,maze,pipes,text3d
The programs are out/bin/*.exe. A screen saver with no arguments
starts as with /s. The 3D text saver needs a TrueType font in a
FONTS folder next to the program.
Universal programs for current macOS
A universal program for macOS 11 and later has an Intel (x86_64) part and
an Apple silicon (arm64) part. The macOS SDK has the C++ library, so you
do not need one of your own. Clang and ld64.lld can do the build on
Linux too.
-
Build the library two times, once for each processor:
for a in x86_64 arm64; do make static TARGET=$a-apple-macos11 STDLIB= AR=llvm-ar \ CXXFLAGS="-O2 -isysroot path/to/MacOSX11.sdk" done -
Build the samples two times, with these variables (
Aisx86_64, thenarm64):export CFLAGS="--target=$A-apple-macos11 -isysroot path/to/MacOSX11.sdk -O2" export CXXFLAGS="-std=c++17" export LDFLAGS="--target=$A-apple-macos11 -isysroot path/to/MacOSX11.sdk -fuse-ld=lld" export MFC_OUT=build/$A-apple-macos11 python3 tools/build-sdk-samples.py --sdk path/to/SDK --out out-$A -
Join the two parts of each program with
lipo:lipo -create out-x86_64/bin/ssmaze.scr out-arm64/bin/ssmaze.scr -output ssmaze.scr
On a Mac, you can leave out -fuse-ld=lld and the -isysroot flags.
The linker signs the arm64 part with an ad-hoc signature, which Apple
silicon needs.
What the script changes
The script copies the files of a sample into out/src. It changes the
copies, not the files of the SDK. Where the layer or a compiler flag can
give a sample what it expects, the script does not change its code. It
changes the code only where clang has no flag for an old idiom:
- It makes the file names lower case, and the
#includepaths use/. - It adds the commas that old resource scripts do not have after a
string.
llvm-rcneeds them. - It changes the cast-as-lvalue idiom
*((TYPE *)p)++to standard C. - It gives the type
intto the old declarationsstatic name;in C++. - For a 64-bit target only, it gives the type
LRESULTto window procedures that the samples declare asLONG. On a 32-bit target the layer makesLRESULTthe same type asLONG, as on Win32. - When the compiler finds a variable that is not declared, it moves the
declaration of a
forvariable out of its loop. The old C++ compilers kept such a variable after the loop. - For a big-endian target, it writes the numbers of the texture files
(
.bmpand.a8) of the screen savers in the order of the processor. The savers keep these files as resources of their own types (100 and 101), and the layer does not change such resources. The code of the savers reads the numbers of these files in the order of the processor. - It declares a structure before a prototype that names it first
(
maze.h). The list isPATCHESin the script.
The script compiles C with -std=gnu89 and -fcommon, and with
NO_STRICT, as the compilers of the time did. It makes the release build
(NDEBUG). rand gives numbers up to 0x7FFF, as in the C library of
Visual C++: the samples compute RAND_MAX + 1 in an int.
The layer and the flags give the samples what the headers and compilers of their time gave:
| What | How |
|---|---|
HIMC is a DWORD |
imm.h declares it so when WINVER is less than 0x040A. The script sets WINVER to 0x0400. |
index and rindex are not functions |
string.h and strings.h of the layer hide them. C compiles with -fno-builtin-index -fno-builtin-rindex. |
A main that returns void |
The screen savers compile with -Dmain=ss_old_main. The layer has the main of the program. |
The resource compiler reads the headers of a sample. The script gives it copies of the headers that keep only the preprocessor lines, as the resource compiler of Windows does.
Run the programs
Run a screen saver with /s. Run it without an argument to see the
configuration dialog.