diff --git a/platforms/dos/.gitignore b/platforms/dos/.gitignore new file mode 100644 index 0000000..8368546 --- /dev/null +++ b/platforms/dos/.gitignore @@ -0,0 +1,2 @@ +y* +src/ \ No newline at end of file diff --git a/platforms/dos/Makefile.mk b/platforms/dos/Makefile.mk new file mode 100644 index 0000000..7879900 --- /dev/null +++ b/platforms/dos/Makefile.mk @@ -0,0 +1,38 @@ +# run with wmake from OpenWatcomC + +coreObjFiles = PFCOMPIL.OBJ PF_CGLUE.OBJ PF_CLIB.OBJ PF_CORE.OBJ PF_INNER.OBJ PF_IO.OBJ PF_MAIN.OBJ PF_MEM.OBJ PF_SAVE.OBJ PF_TEXT.OBJ PF_WORDS.OBJ +ioObjFiles = +customObjFiles = PFCUSTOM.OBJ +allObjFiles = $(coreObjFiles) $(ioObjFiles) $(customObjFiles) missing.obj + +.c.obj + wcc386 -fp3 -fpi87 -I. -DPF_SUPPORT_FP $< + +pforth.dic: pforth.exe + cd ..\fth + ..\csrc\pforth -i system.fth + cd ..\csrc + move ..\fth\pforth.dic . + +pforth.exe: $(allObjFiles) + %write pforth.lnk NAME $@ + %write pforth.lnk SYSTEM DOS4G + %write pforth.lnk FILE {$(allObjFiles)} + wlink @pforth.lnk + +clean: .symbolic + del *.dic *.exe *.lnk *.obj *.err + +test: pforth.dic .symbolic + copy pforth.dic ..\fth\ + cd ..\fth + ..\csrc\pforth -q t_corex.fth + ..\csrc\pforth -q tstrings.fth + ..\csrc\pforth -q t_locals.fth + ..\csrc\pforth -q t_alloc.fth + ..\csrc\pforth -q t_floats.fth +# this will not succeed: ..\csrc\pforth -q t_file.fth + del pforth.dic + cd ..\csrc\ + echo + echo "all tests PASSED" diff --git a/platforms/dos/README b/platforms/dos/README new file mode 100644 index 0000000..2da4a04 --- /dev/null +++ b/platforms/dos/README @@ -0,0 +1,47 @@ +Build environment +----------------- +PForth has been build (and run) under both FreeDos and DosBox. +Others (DR-DOS, MS-DOS...) might work as well. + + +Preparation steps +----------------- +DOS limits file names to 8+3 characters. +Currently 19 relevant files in the PForth source tree violate this rule (see rename.txt for details). +It is recommended to perform the following steps on a POSIX system (tested under MSYS2/Cygwin): + 1) run ./step-1-prepare-sourceTree.sh to rename all files to 8+3 characters convention. + It will check that no new files violate the convention and abort if so. + In that case extend rename.txt. + 2) Select OS-specific routine and run appropriate script, e.g.: + ./step-2a-select-stdio.sh + For now only stdio is tested. + 3) Create an archive and transfer it to the build environment. + Both FreeDos and Linux-hosts for DosBox provide tar, so you can: + tar cf pf-dos.tar src/ + FreeDos also provides unzip.exe if you want to create a ZIP file instead. + + +Compiler +-------- +FreeDos developers seem to prefer OpenWatcomC (install it via fdimples on FreeDos). +It has been used to compile PForth successfully under both FreeDos and DosBox. +(The latter does not provide a "move" command, so the build needs a bit of help at 1 point after pforth.dic has been created). +This build targets 386 hardware and and a DOS extender (DOS4GW) since the standard 16-bit build (via owcc) failed. +OpenWatcomC does not implement two required functions for floating point operation, missing.c fixes that. +The test suite runs fine except for unimplemtented stuff in t_file.fth. + +Potentially you could build pforth using DJGPP (gcc and gnu-make). +Unfortunately I found it unusable (it crashed way too often). + +PForth assumes 32bit several times in the source code. +Thus not 16 bit compilers (like Turbo C) were tried. + + +where / how to build? +--------------------- +Extract the prepared sources to a drive with sufficient free space and execute: +cd .\src\csrc +wmake + +If that worked fine, try this next: +wmake test diff --git a/platforms/dos/missing.c b/platforms/dos/missing.c new file mode 100644 index 0000000..5fc4ba7 --- /dev/null +++ b/platforms/dos/missing.c @@ -0,0 +1,23 @@ + #include "missing.h" + +double round(double x) { + double i, s; + if( x>=0 ) { + i = floor(x); + s = 1.0; + } else { + i = ceil(x); + s = -1.0; + } + if( fabs(x - i) < 0.5 ) + return i; /* round down */ + else + return i + s; /* round up */ +} + +double log1p(double x) { + if( -1.0 < x && x <= 1.0 ) + return x - 0.5*x*x + 1.0/3.0*x*x*x - 0.25*x*x*x*x + 0.20*x*x*x*x*x; + else + return log( 1.0 + x ); +} diff --git a/platforms/dos/missing.h b/platforms/dos/missing.h new file mode 100644 index 0000000..b382c46 --- /dev/null +++ b/platforms/dos/missing.h @@ -0,0 +1,10 @@ +/* include this in pf_inner.c !! */ + +#ifndef PF_MISSING_H +#define PF_MISSING_H + +#include +double round(double x); +double log1p(double x); + +#endif /* PF_MISSING_H */ diff --git a/platforms/dos/rename.txt b/platforms/dos/rename.txt new file mode 100644 index 0000000..2893426 --- /dev/null +++ b/platforms/dos/rename.txt @@ -0,0 +1,19 @@ +src/csrc/pf_io_none.c src/csrc/ionone.c +src/csrc/posix/pf_io_posix.c src/csrc/posix/ioposix.c +src/csrc/stdio/pf_fileio_stdio.c src/csrc/stdio/fiostdio.c +src/csrc/stdio/pf_io_stdio.c src/csrc/stdio/iostdio.c +src/csrc/win32/pf_io_win32.c src/csrc/win32/iowin32.c +src/csrc/win32csl/pf_io_win32_console.c src/csrc/win32csl/iowin32c.c +src/fth/save-input.fth src/fth/savinput.fth +src/fth/structure.fth src/fth/structur.fth +src/fth/t_include.fth src/fth/tinclude.fth +src/fth/t_load_defer.fth src/fth/tlddefer.fth +src/fth/t_load_pairs.fth src/fth/tldpairs.fth +src/fth/t_load_semi.fth src/fth/tldsemi.fth +src/fth/t_load_undef.fth src/fth/tldundef.fth +src/fth/t_required_helper1.fth src/fth/treqhlp1.fth +src/fth/t_required_helper2.fth src/fth/treqhlp2.fth +src/fth/t_strings.fth src/fth/tstrings.fth +src/fth/utils/dump_struct.fth src/fth/utils/dumpstru.fth +src/fth/utils/load_file.fth src/fth/utils/loadfile.fth +src/fth/utils/make_all256.fth src/fth/utils/make_all.fth diff --git a/platforms/dos/step-1-prepare-sourceTree.sh b/platforms/dos/step-1-prepare-sourceTree.sh new file mode 100644 index 0000000..853a7cd --- /dev/null +++ b/platforms/dos/step-1-prepare-sourceTree.sh @@ -0,0 +1,62 @@ +#!/bin/sh + +echo +echo "0) clean previous build folder" +echo "------------------------------" +rm -rf ./src/ + +echo +echo "1) copy sources here" +echo "--------------------" +mkdir src +mkdir src/csrc +mkdir src/fth +cp -r ../../csrc/ ./src/ +cp -r ../../fth/ ./src/ +cp missing.* ./src/csrc/ +cp Makefile.mk ./src/csrc/ +find . | grep -i cmake | xargs rm # Nobody likes CMake!!! +mv ./src/csrc/win32_console/ ./src/csrc/win32csl/ + +echo +echo "2a) rename files to 8+3 filename convention" +echo "-------------------------------------------" +cat rename.txt | awk '{if( NF==2 ) print "mv " $1 " " $2}' | sh +echo "2b) verify that 8+3 filename convention is kept." +echo "-----------------------------------------------" +find src/ -type f | awk -f too-long-filenames.awk | tee yMissingRenames +echo "-----------------------------------------------" +if test -s yMissingRenames +then + echo "ABORT: more files need to be renamed!" +else # yMissingRenames + + echo + echo "3) extract list of filenames to substitute from 'rename.txt'" + echo "-------------------------------------------------------------" + cat rename.txt | awk '{if( NF==2 ) print "echo s#`basename " $1 "`#`basename " $2 "`#g" }' | sh | sed -e 's#\.#\\\.#g' > yFileNames + + echo + echo "4) patch file contents" + echo "----------------------" + for curFile in `find src/ -type f` + do + sed -f yFileNames -i $curFile + done + rm yFileNames + + echo + echo "4) include missing.h in pf_inner.c" + echo "----------------------------------" + mv ./src/csrc/pf_inner.c tmp.c + cat - tmp.c > ./src/csrc/pf_inner.c << EOF +#include "missing.h" +EOF + rm tmp.c + + echo + echo "99) done" + echo "--------" + rm yMissingRenames + +fi # yMissingRenames diff --git a/platforms/dos/step-2a-select-stdio.sh b/platforms/dos/step-2a-select-stdio.sh new file mode 100644 index 0000000..47544fe --- /dev/null +++ b/platforms/dos/step-2a-select-stdio.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +ioSources="fiostdio.c iostdio.c" + +cd ./src/csrc/ + +# 1) copy ioSources to parent dir (so all sources are in 1 folder) and patch the include statements accordingly +for srcFile in $ioSources +do + cat "./stdio/$srcFile" | sed -e 's#\.\./##g' > $srcFile +done + +# 2) include ioSources in Makefile +objFiles=`echo $ioSources | sed -e 's#\.c#\\\.obj#g' ` +cat Makefile.mk | sed -e "s/ioObjFiles =/ioObjFiles = $objFiles/g" > Makefile +rm Makefile.mk + +cd ../../ +echo "done" diff --git a/platforms/dos/too-long-filenames.awk b/platforms/dos/too-long-filenames.awk new file mode 100644 index 0000000..ad81c2e --- /dev/null +++ b/platforms/dos/too-long-filenames.awk @@ -0,0 +1,22 @@ +# call via: +# find csrc/ fth/ -type f | awk -f too-long-filenames.awk + + +BEGIN { + FS="/" # separate by directory +} + + +{ + noParts = split( $NF, parts, "." ) + if ( noParts!=2 ) + { + if ( noParts>2 ) + print "----> invalid noParts=" noParts " for file='" $0 "'" + } + else + { + if( length(parts[1]) > 8 || length(parts[2]) > 3 ) + print $0; + } +}