#!/bin/bash # Build G.EXE (16-bit DOS, compact model) with Open Watcom 1.9 against the mTCP library, and the v86-patched # XIAOMAO.EXE (Big5 display + Zhuyin input; needs nasm). Needs deps/ (tools/fetch_deps.sh). Output: build/G.EXE, build/XIAOMAO.EXE # NOTE: do NOT use Open Watcom 2.0 beta: EXEs it builds print "End: heap is corrupted!". set -euo pipefail ROOT="$(cd "$(dirname "$0")/.." && pwd)"; D="${DEPS:-$ROOT/deps}"; HERE="$ROOT/src" export WATCOM="$D/ow19" PATH="$D/ow19/binl:$PATH" INCLUDE="$D/ow19/h" MTCP_SRC="$(echo "$D"/mtcp-src/mTCP-src_*)" OUT="$ROOT/build"; rm -rf "$OUT/mtcp" "$OUT/g"; mkdir -p "$OUT/mtcp" # Lowercase mirror of the mTCP sources (Linux is case sensitive, mTCP is not). for d in TCPINC TCPLIB INCLUDE; do l="$(echo $d | tr A-Z a-z)"; mkdir -p "$OUT/mtcp/$l" for f in "$MTCP_SRC/$d"/*; do sed -E 's/^(\s*#\s*include\s+["<])([^">]+)([">])/\1\L\2\3/' "$f" > "$OUT/mtcp/$l/$(basename "$f" | tr A-Z a-z)" done done LIBS="packet arp eth ip tcp tcpsockm udp utils dns timer trace" B="$OUT/g"; mkdir -p "$B"; cp "$HERE/g.cfg" "$HERE/g.cpp" "$HERE/dosnet.h" "$B/" FLAGS="-0 -mc -DCFG_H=\"g.cfg\" -oh -os -s -zp2 -zpw -we -i=$OUT/mtcp/tcpinc -i=$OUT/mtcp/include -i=$B" ( cd "$B" for l in $LIBS; do wpp "$OUT/mtcp/tcplib/$l.cpp" $FLAGS -fo=$l.obj >/dev/null; done wasm -0 -mc "$OUT/mtcp/tcplib/ipasm.asm" -fo=ipasm.obj >/dev/null wpp g.cpp $FLAGS -fo=g.obj | grep -v "^Open Watcom\|^Version\|^Copyright\|^Portions\|^Source code\|^See https" || true wlink system dos option map option eliminate option stack=4096 name g.exe \ file $(for l in $LIBS ipasm g; do printf "$l.obj,"; done | sed 's/,$//') >link.log 2>&1 || { cat link.log; exit 1; } ) cp "$B/g.exe" "$OUT/G.EXE"; ls -l "$OUT/G.EXE" # ---- XIAOMAO.EXE (patched for v86, see src/xiaomao/xiaomao-v86.patch) ------------------------------- command -v nasm >/dev/null || { echo "nasm is required to build XIAOMAO.EXE (apt-get install nasm)"; exit 1; } XB="$OUT/xiaomao"; rm -rf "$XB"; mkdir -p "$XB" nasm -f obj -o "$XB/xms.obj" "$HERE/xiaomao/xms.asm" CF="-q -bt=dos -ml -0 -os -s -zu -k10240" ( cd "$XB" wcl $CF -DTSR_PARAS=0x1000 -fe=XIAOMAO.EXE -fm=XIAOMAO.map "$HERE/xiaomao/xiaomao.c" xms.obj >/dev/null # resident image = PSP (0x10 paragraphs) + everything below the STACK segment; the program is built twice for that SEG=$(awk '$1=="STACK"{split($4,a,":"); print a[1]}' XIAOMAO.map); TSR=$(printf '0x%X' $((0x$SEG + 0x10))) wcl $CF -DTSR_PARAS=$TSR -fe=XIAOMAO.EXE -fm=XIAOMAO.map "$HERE/xiaomao/xiaomao.c" xms.obj >/dev/null ) cp "$XB/XIAOMAO.EXE" "$OUT/XIAOMAO.EXE"; ls -l "$OUT/XIAOMAO.EXE"