TITLE=DOSLIB ROUTE=/dos/doslib LOCALE=en MODIFIED=1792180394 URL=https://wiki.teletypegames.org/dos/doslib L=1 #16 L=2 #18 L=3 #15 L=4 #49 L=5 https://git.teletypegames.org/dos/doslib q│ DOSLIB is the code that the DOS programs 1DOSINST, 2GMENU, 3BMAGIC and 4TTGWIKI q│ share (C++, Open Watcom, 16-bit DOS and Win32), and the rules their code q│ follows. Each program has it in its cSOURCE/libq folder as a git subtree, so q│ it builds on its own. • bRepository:0 5git.teletypegames.org/dos/doslib 1What is in it 1═════════════ t┌──────────────────────────────┬─────────────────────────────────────────────┐ t│h Folder t│h What t│ t├──────────────────────────────┼─────────────────────────────────────────────┤ t│0 ccore0 t│0 No I/O: strings and 8.3 names, INI files, t│ t│0 t│0 UTF-8 and code page 437, the code pages 437 t│ t│0 t│0 and 852 with one byte a character t│ t│0 t│0 (ccode_page0), CRC-32, the shared cError0. t│ t├──────────────────────────────┼─────────────────────────────────────────────┤ t│0 cplatform0 t│0 The interfaces of the machine: cScreen0, t│ t│0 t│0 cKeyboard0, cMouse0, cClock0, cFileSystem0, t│ t│0 t│0 cNetwork0, ... t│ t├──────────────────────────────┼─────────────────────────────────────────────┤ t│0 cplatform/dos0, cplatform/win320 t│0 Their implementations: video memory, BIOS, t│ t│0 t│0 INT 33h, the Watcom C library; the Win32 t│ t│0 t│0 console. t│ t├──────────────────────────────┼─────────────────────────────────────────────┤ t│0 cnet0 t│0 An FTP client on the cNetwork0 interface. t│ t├──────────────────────────────┼─────────────────────────────────────────────┤ t│0 cui0 t│0 Drawing on a cScreen0, the BIOS key codes, a t│ t│0 t│0 list cursor. t│ t├──────────────────────────────┼─────────────────────────────────────────────┤ t│0 ctesting0 t│0 The hooks of the test builds (scripted t│ t│0 t│0 keys, screen dump), and test doubles for t│ t│0 t│0 the unit tests on the host. t│ t├──────────────────────────────┼─────────────────────────────────────────────┤ t│0 ctools0 t│0 The Watcom build helper, the layer check, t│ t│0 t│0 the unit test runner, the formatter. t│ t└──────────────────────────────┴─────────────────────────────────────────────┘ 1Layers 1══════ A program is built in layers; each uses only the ones below it, and only through their interfaces: p main_*.cpp the machine: picks the platform implementations p app/ puts the layers together p controller/ keys and commands -> service calls p view/ draws p service/ what the program does p repository/ interfaces of the storage; repository// implements them p model/ the data and its rules, no I/O p platform/ the program's own machine interfaces and their implementation» p s p lib/ DOSLIB ctools/check_layers.py0 checks it in CI: which folder may include which, that the DOS and Windows headers are only in the platform code, no cgoto0, no cexit() outside cmain0. Everything above the platform also compiles on the host, so it is unit tested there, without DOSBox. 1The code 1════════ • C++98, the part Open Watcom compiles: classes, pure virtual interfaces, references, simple templates; no exceptions, RTTI, STL or C++11. • Interfaces are named by what they are (cFileSystem0), implementations by how (cDosFileSystem0, cFakeFileSystem0). Dependencies come in through the constructor; only capp/0 and cmain_*.cpp0 create concrete objects. • Failures are a cbool0 and a shared cError0; no global state outside the platform code. • Files csnake_case0, types cPascalCase0, functions ccamelCase0, members cname_0; clang-format 18 with the repository's c.clang-format0. 1Updating a program 1══════════════════ p git subtree pull --prefix=SOURCE/lib ssh://git@git.teletypegames.org:2222/do» p s/doslib master --squash A change made in a program's cSOURCE/lib0 goes back with cgit subtree push c--prefix=SOURCE/lib ... master0. 1Open Watcom notes 1═════════════════ • The 16-bit compiler of the large model crashes on a module name longer than 25 characters; the build cuts it with c-nm0. • A static object over 32 KB ends up in the EXE file: big objects are allocated on the heap. • On 16 bits the layers cost size (far pointers, constructors, virtual tables): GMENU grew from 30 to 45 KB, DOSINST from 77 to 90 KB.