瀏覽代碼

* moved to own module

peter 24 年之前
父節點
當前提交
39a54db48b

+ 1099 - 0
demo/Makefile

@@ -0,0 +1,1099 @@
+#
+# Don't edit, this file is generated by fpcmake v1.99.0 [2001/05/03]
+#
+default: all
+override PATH:=$(subst \,/,$(PATH))
+ifeq ($(findstring ;,$(PATH)),)
+inUnix=1
+SEARCHPATH:=$(subst :, ,$(PATH))
+else
+SEARCHPATH:=$(subst ;, ,$(PATH))
+endif
+PWD:=$(strip $(wildcard $(addsuffix /pwd.exe,$(SEARCHPATH))))
+ifeq ($(PWD),)
+PWD:=$(strip $(wildcard $(addsuffix /pwd,$(SEARCHPATH))))
+ifeq ($(PWD),)
+nopwd:
+	@echo You need the GNU utils package to use this Makefile!
+	@echo Get ftp://ftp.freepascal.org/pub/fpc/dist/go32v2/utilgo32.zip
+	@exit
+else
+PWD:=$(firstword $(PWD))
+SRCEXEEXT=
+endif
+else
+PWD:=$(firstword $(PWD))
+SRCEXEEXT=.exe
+endif
+ifndef inUnix
+ifeq ($(OS),Windows_NT)
+inWinNT=1
+else
+ifdef OS2_SHELL
+inOS2=1
+endif
+endif
+else
+ifneq ($(findstring cygwin,$(MACH_TYPE)),)
+inCygWin=1
+endif
+endif
+ifdef inUnix
+BATCHEXT=.sh
+else
+ifdef inOS2
+BATCHEXT=.cmd
+else
+BATCHEXT=.bat
+endif
+endif
+ifdef inUnix
+PATHSEP=/
+else
+PATHSEP:=$(subst /,\,/)
+endif
+ifdef PWD
+BASEDIR:=$(shell $(PWD))
+else
+BASEDIR=.
+endif
+ifndef FPC
+ifdef PP
+FPC=$(PP)
+else
+FPC=ppc386
+endif
+endif
+override FPC:=$(subst $(SRCEXEEXT),,$(FPC))
+override FPC:=$(subst \,/,$(FPC))$(SRCEXEEXT)
+ifndef OS_TARGET
+OS_TARGET:=$(shell $(FPC) -iTO)
+endif
+ifndef OS_SOURCE
+OS_SOURCE:=$(shell $(FPC) -iSO)
+endif
+ifndef CPU_TARGET
+CPU_TARGET:=$(shell $(FPC) -iTP)
+endif
+ifndef CPU_SOURCE
+CPU_SOURCE:=$(shell $(FPC) -iSP)
+endif
+ifndef FPC_VERSION
+FPC_VERSION:=$(shell $(FPC) -iV)
+endif
+export FPC OS_TARGET OS_SOURCE CPU_TARGET CPU_SOURCE FPC_VERSION
+ifdef FPCDIR
+override FPCDIR:=$(subst \,/,$(FPCDIR))
+ifeq ($(wildcard $(addprefix $(FPCDIR)/,rtl units)),)
+override FPCDIR=wrong
+endif
+else
+override FPCDIR=wrong
+endif
+ifeq ($(FPCDIR),wrong)
+ifdef inUnix
+override FPCDIR=/usr/local/lib/fpc/$(FPC_VERSION)
+ifeq ($(wildcard $(FPCDIR)/units),)
+override FPCDIR=/usr/lib/fpc/$(FPC_VERSION)
+endif
+else
+override FPCDIR:=$(subst /$(FPC),,$(firstword $(strip $(wildcard $(addsuffix /$(FPC),$(SEARCHPATH))))))
+override FPCDIR:=$(FPCDIR)/..
+ifeq ($(wildcard $(addprefix $(FPCDIR)/,rtl units)),)
+override FPCDIR:=$(FPCDIR)/..
+ifeq ($(wildcard $(addprefix $(FPCDIR)/,rtl units)),)
+override FPCDIR=c:/pp
+endif
+endif
+endif
+endif
+UNITSDIR:=$(wildcard $(FPCDIR)/units/$(OS_TARGET))
+PACKAGESDIR:=$(wildcard $(FPCDIR) $(FPCDIR)/packages)
+override PACKAGE_NAME=demo
+override PACKAGE_VERSION=1.0.5
+override TARGET_DIRS+=text graph
+ifeq ($(OS_TARGET),linux)
+override TARGET_DIRS+=linux
+endif
+ifeq ($(OS_TARGET),go32v2)
+override TARGET_DIRS+=modex
+endif
+ifeq ($(OS_TARGET),win32)
+override TARGET_DIRS+=win32
+endif
+ifeq ($(OS_TARGET),os2)
+override TARGET_DIRS+=os2
+endif
+ifndef ECHO
+ECHO:=$(strip $(wildcard $(addsuffix /gecho$(EXEEXT),$(SEARCHPATH))))
+ifeq ($(ECHO),)
+ECHO:=$(strip $(wildcard $(addsuffix /echo$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(ECHO),)
+ECHO:=echo
+else
+ECHO:=$(firstword $(ECHO))
+endif
+else
+ECHO:=$(firstword $(ECHO))
+endif
+endif
+ifndef COPY
+COPY:=cp -fp
+endif
+ifndef COPYTREE
+COPYTREE:=cp -rfp
+endif
+ifndef MOVE
+MOVE:=mv -f
+endif
+ifndef DEL
+DEL:=rm -f
+endif
+ifndef DELTREE
+DELTREE:=rm -rf
+endif
+ifndef INSTALL
+ifdef inUnix
+INSTALL:=install -c -m 644
+else
+INSTALL:=$(COPY)
+endif
+endif
+ifndef INSTALLEXE
+ifdef inUnix
+INSTALLEXE:=install -c -m 755
+else
+INSTALLEXE:=$(COPY)
+endif
+endif
+ifndef MKDIR
+ifdef inUnix
+MKDIR:=install -m 755 -d
+else
+MKDIR:=ginstall -m 755 -d
+endif
+endif
+export ECHO COPY COPYTREE MOVE DEL DELTREE INSTALL INSTALLEXE MKDIR
+ifndef AS
+AS=as
+endif
+ifndef LD
+LD=ld
+endif
+ifndef RC
+RC=rc
+endif
+PPAS=ppas$(BATCHEXT)
+ifdef inUnix
+LDCONFIG=ldconfig
+else
+LDCONFIG=
+endif
+ifndef PPUMOVE
+PPUMOVE:=$(strip $(wildcard $(addsuffix /ppumove$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(PPUMOVE),)
+PPUMOVE=
+else
+PPUMOVE:=$(firstword $(PPUMOVE))
+endif
+endif
+export PPUMOVE
+ifndef PPUFILES
+PPUFILES:=$(strip $(wildcard $(addsuffix /ppufiles$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(PPUFILES),)
+PPUFILES=
+else
+PPUFILES:=$(firstword $(PPUFILES))
+endif
+endif
+export PPUFILES
+ifndef DATE
+DATE:=$(strip $(wildcard $(addsuffix /date$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(DATE),)
+DATE:=$(strip $(wildcard $(addsuffix /gdate$(SRCEXEEXT),$(SEACHPATH))))
+ifeq ($(DATE),)
+DATE=
+else
+DATE:=$(firstword $(DATE))
+endif
+else
+DATE:=$(firstword $(DATE))
+endif
+endif
+export DATE
+ifdef DATE
+DATESTR:=$(shell $(DATE) +%Y%m%d)
+else
+DATESTR=
+endif
+ifndef UPXPROG
+ifeq ($(OS_TARGET),go32v2)
+UPXPROG:=1
+endif
+ifeq ($(OS_TARGET),win32)
+UPXPROG:=1
+endif
+ifdef UPXPROG
+UPXPROG:=$(strip $(wildcard $(addsuffix /upx$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(UPXPROG),)
+UPXPROG=
+else
+UPXPROG:=$(firstword $(UPXPROG))
+endif
+else
+UPXPROG=
+endif
+endif
+export UPXPROG
+ifndef ZIPPROG
+ZIPPROG:=$(strip $(wildcard $(addsuffix /zip$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(ZIPPROG),)
+ZIPPROG=
+else
+ZIPPROG:=$(firstword $(ZIPPROG))
+endif
+endif
+export ZIPPROG
+ZIPOPT=-9
+ZIPEXT=.zip
+ifndef TARPROG
+TARPROG:=$(strip $(wildcard $(addsuffix /tar$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(TARPROG),)
+TARPROG=
+else
+TARPROG:=$(firstword $(TARPROG))
+endif
+endif
+export TARPROG
+ifeq ($(USETAR),bz2)
+TAROPT=vI
+TAREXT=.tar.bz2
+else
+TAROPT=vz
+TAREXT=.tar.gz
+endif
+LOADEREXT=.as
+EXEEXT=.exe
+PPLEXT=.ppl
+PPUEXT=.ppu
+OEXT=.o
+ASMEXT=.s
+SMARTEXT=.sl
+STATICLIBEXT=.a
+SHAREDLIBEXT=.so
+LIBPREFIX=lib
+RSTEXT=.rst
+FPCMADE=fpcmade
+ifeq ($(OS_TARGET),go32v1)
+PPUEXT=.pp1
+OEXT=.o1
+ASMEXT=.s1
+SMARTEXT=.sl1
+STATICLIBEXT=.a1
+SHAREDLIBEXT=.so1
+LIBPREFIX=
+FPCMADE=fpcmade.v1
+PACKAGESUFFIX=v1
+endif
+ifeq ($(OS_TARGET),go32v2)
+LIBPREFIX=
+FPCMADE=fpcmade.dos
+ZIPSUFFIX=go32
+endif
+ifeq ($(OS_TARGET),linux)
+EXEEXT=
+HASSHAREDLIB=1
+FPCMADE=fpcmade.lnx
+ZIPSUFFIX=linux
+endif
+ifeq ($(OS_TARGET),freebsd)
+EXEEXT=
+HASSHAREDLIB=1
+FPCMADE=fpcmade.freebsd
+ZIPSUFFIX=freebsd
+endif
+ifeq ($(OS_TARGET),win32)
+PPUEXT=.ppw
+OEXT=.ow
+ASMEXT=.sw
+SMARTEXT=.slw
+STATICLIBEXT=.aw
+SHAREDLIBEXT=.dll
+FPCMADE=fpcmade.w32
+ZIPSUFFIX=w32
+endif
+ifeq ($(OS_TARGET),os2)
+PPUEXT=.ppo
+ASMEXT=.so2
+OEXT=.oo2
+AOUTEXT=.out
+SMARTEXT=.so
+STATICLIBEXT=.ao2
+SHAREDLIBEXT=.dll
+FPCMADE=fpcmade.os2
+ZIPSUFFIX=emx
+endif
+ifdef REQUIRE_UNITSDIR
+override UNITSDIR+=$(REQUIRE_UNITSDIR)
+endif
+ifdef REQUIRE_PACKAGESDIR
+override PACKAGESDIR+=$(REQUIRE_PACKAGESDIR)
+endif
+ifdef ZIPINSTALL
+ifeq ($(OS_TARGET),linux)
+UNIXINSTALLDIR=1
+endif
+ifeq ($(OS_TARGET),freebsd)
+UNIXINSTALLDIR=1
+endif
+else
+ifeq ($(OS_SOURCE),linux)
+UNIXINSTALLDIR=1
+endif
+ifeq ($(OS_SOURCE),freebsd)
+UNIXINSTALLDIR=1
+endif
+endif
+ifndef INSTALL_PREFIX
+ifdef UNIXINSTALLDIR
+INSTALL_PREFIX=/usr/local
+else
+ifdef INSTALL_FPCPACKAGE
+INSTALL_BASEDIR:=/pp
+else
+INSTALL_BASEDIR:=/$(PACKAGE_NAME)
+endif
+endif
+endif
+export INSTALL_PREFIX
+ifndef DIST_DESTDIR
+DIST_DESTDIR:=$(BASEDIR)
+endif
+export DIST_DESTDIR
+ifndef INSTALL_BASEDIR
+ifdef UNIXINSTALLDIR
+ifdef INSTALL_FPCPACKAGE
+INSTALL_BASEDIR:=$(INSTALL_PREFIX)/lib/fpc/$(FPC_VERSION)
+else
+INSTALL_BASEDIR:=$(INSTALL_PREFIX)/lib/$(PACKAGE_NAME)
+endif
+else
+INSTALL_BASEDIR:=$(INSTALL_PREFIX)
+endif
+endif
+ifndef INSTALL_BINDIR
+ifdef UNIXINSTALLDIR
+INSTALL_BINDIR:=$(INSTALL_PREFIX)/bin
+else
+INSTALL_BINDIR:=$(INSTALL_BASEDIR)/bin
+ifdef INSTALL_FPCPACKAGE
+INSTALL_BINDIR:=$(INSTALL_BINDIR)/$(OS_TARGET)
+endif
+endif
+endif
+ifndef INSTALL_UNITDIR
+INSTALL_UNITDIR:=$(INSTALL_BASEDIR)/units/$(OS_TARGET)
+ifdef INSTALL_FPCPACKAGE
+INSTALL_UNITDIR:=$(INSTALL_UNITDIR)/$(PACKAGE_NAME)
+endif
+endif
+ifndef INSTALL_LIBDIR
+ifdef UNIXINSTALLDIR
+INSTALL_LIBDIR:=$(INSTALL_PREFIX)/lib
+else
+INSTALL_LIBDIR:=$(INSTALL_UNITDIR)
+endif
+endif
+ifndef INSTALL_SOURCEDIR
+ifdef UNIXINSTALLDIR
+ifdef INSTALL_FPCPACKAGE
+INSTALL_SOURCEDIR:=$(INSTALL_PREFIX)/src/fpc-$(FPC_VERSION)/$(PACKAGE_NAME)
+else
+INSTALL_SOURCEDIR:=$(INSTALL_PREFIX)/src/$(PACKAGE_NAME)-$(PACKAGE_VERSION)
+endif
+else
+ifdef INSTALL_FPCPACKAGE
+INSTALL_SOURCEDIR:=$(INSTALL_BASEDIR)/source/$(PACKAGE_NAME)
+else
+INSTALL_SOURCEDIRL:=$(INSTALL_BASEDIR)/source
+endif
+endif
+endif
+ifndef INSTALL_DOCDIR
+ifdef UNIXINSTALLDIR
+ifdef INSTALL_FPCPACKAGE
+INSTALL_DOCDIR:=$(INSTALL_PREFIX)/doc/fpc-$(FPC_VERSION)/$(PACKAGE_NAME)
+else
+INSTALL_DOCDIR:=$(INSTALL_PREFIX)/doc/$(PACKAGE_NAME)-$(PACKAGE_VERSION)
+endif
+else
+ifdef INSTALL_FPCPACKAGE
+INSTALL_DOCDIR:=$(INSTALL_BASEDIR)/doc/$(PACKAGE_NAME)
+else
+INSTALL_DOCDIR:=$(INSTALL_BASEDIR)/doc
+endif
+endif
+endif
+ifndef INSTALL_EXAMPLEDIR
+ifdef UNIXINSTALLDIR
+ifdef INSTALL_FPCPACKAGE
+INSTALL_EXAMPLEDIR:=$(INSTALL_PREFIX)/doc/fpc-$(FPC_VERSION)/examples/$(PACKAGE_NAME)
+else
+INSTALL_EXAMPLEDIR:=$(INSTALL_PREFIX)/doc/$(PACKAGE_NAME)-$(PACKAGE_VERSION)
+endif
+else
+ifdef INSTALL_FPCPACKAGE
+INSTALL_EXAMPLEDIR:=$(INSTALL_BASEDIR)/examples/$(PACKAGE_NAME)
+else
+INSTALL_EXAMPLEDIR:=$(INSTALL_BASEDIR)/examples
+endif
+endif
+endif
+ifndef INSTALL_DATADIR
+INSTALL_DATADIR=$(INSTALL_BASEDIR)
+endif
+override FPCOPTDEF=$(CPU_TARGET)
+ifneq ($(OS_TARGET),$(OS_SOURCE))
+override FPCOPT+=-T$(OS_TARGET)
+endif
+ifdef UNITDIR
+override FPCOPT+=$(addprefix -Fu,$(UNITDIR))
+endif
+ifdef LIBDIR
+override FPCOPT+=$(addprefix -Fl,$(LIBDIR))
+endif
+ifdef OBJDIR
+override FPCOPT+=$(addprefix -Fo,$(OBJDIR))
+endif
+ifdef INCDIR
+override FPCOPT+=$(addprefix -Fi,$(INCDIR))
+endif
+ifdef LINKSMART
+override FPCOPT+=-XX
+endif
+ifdef CREATESMART
+override FPCOPT+=-CX
+endif
+ifdef DEBUG
+override FPCOPT+=-gl
+override FPCOPTDEF+=DEBUG
+endif
+ifdef RELEASE
+override FPCOPT+=-Xs -OG2p3 -n
+override FPCOPTDEF+=RELEASE
+endif
+ifdef STRIP
+override FPCOPT+=-Xs
+endif
+ifdef OPTIMIZE
+override FPCOPT+=-OG2p3
+endif
+ifdef VERBOSE
+override FPCOPT+=-vwni
+endif
+ifdef COMPILER_OPTIONS
+override FPCOPT+=$(COMPILER_OPTIONS)
+endif
+ifdef COMPILER_UNITDIR
+override FPCOPT+=$(addprefix -Fu,$(COMPILER_UNITDIR))
+endif
+ifdef COMPILER_LIBRARYDIR
+override FPCOPT+=$(addprefix -Fl,$(COMPILER_LIBRARYDIR))
+endif
+ifdef COMPILER_OBJECTDIR
+override FPCOPT+=$(addprefix -Fo,$(COMPILER_OBJECTDIR))
+endif
+ifdef COMPILER_INCLUDEDIR
+override FPCOPT+=$(addprefix -Fi,$(COMPILER_INCLUDEDIR))
+endif
+ifdef COMPILER_TARGETDIR
+override FPCOPT+=-FE$(COMPILER_TARGETDIR)
+ifeq ($(COMPILER_TARGETDIR),.)
+override TARGETDIRPREFIX=
+else
+override TARGETDIRPREFIX=$(COMPILER_TARGETDIR)/
+endif
+endif
+ifdef COMPILER_UNITTARGETDIR
+override FPCOPT+=-FU$(COMPILER_UNITTARGETDIR)
+ifeq ($(COMPILER_UNITTARGETDIR),.)
+override UNITTARGETDIRPREFIX=
+else
+override UNITTARGETDIRPREFIX=$(COMPILER_TARGETDIR)/
+endif
+else
+ifdef COMPILER_TARGETDIR
+override COMPILER_UNITTARGETDIR=$(COMPILER_TARGETDIR)
+override UNITTARGETDIRPREFIX=$(TARGETDIRPREFIX)
+endif
+endif
+ifdef OPT
+override FPCOPT+=$(OPT)
+endif
+ifdef FPCOPTDEF
+override FPCOPT+=$(addprefix -d,$(FPCOPTDEF))
+endif
+ifdef CFGFILE
+override FPCOPT+=@$(CFGFILE)
+endif
+ifeq ($(OS_SOURCE),win32)
+USEENV=1
+endif
+ifdef USEENV
+override FPCEXTCMD:=$(FPCOPT)
+override FPCOPT:=!FPCEXTCMD
+export FPCEXTCMD
+endif
+override COMPILER:=$(FPC) $(FPCOPT)
+ifeq (,$(findstring -s ,$(COMPILER)))
+EXECPPAS=
+else
+ifeq ($(OS_SOURCE),$(OS_TARGET))
+EXECPPAS:=@$(PPAS)
+endif
+endif
+.PHONY: fpc_packages fpc_all fpc_smart fpc_debug
+$(FPCMADE): $(ALLTARGET)
+	@$(ECHO) Compiled > $(FPCMADE)
+fpc_packages: $(COMPILEPACKAGES)
+fpc_all: fpc_packages $(FPCMADE)
+fpc_smart:
+	$(MAKE) all LINKSMART=1 CREATESMART=1
+fpc_debug:
+	$(MAKE) all DEBUG=1
+.SUFFIXES: $(EXEEXT) $(PPUEXT) $(OEXT) .pas .pp
+%$(PPUEXT): %.pp
+	$(COMPILER) $<
+	$(EXECPPAS)
+%$(PPUEXT): %.pas
+	$(COMPILER) $<
+	$(EXECPPAS)
+%$(EXEEXT): %.pp
+	$(COMPILER) $<
+	$(EXECPPAS)
+%$(EXEEXT): %.pas
+	$(COMPILER) $<
+	$(EXECPPAS)
+vpath %.pp $(COMPILER_SOURCEDIR) $(COMPILER_INCLUDEDIR)
+vpath %.pas $(COMPILER_SOURCEDIR) $(COMPILER_INCLUDEDIR)
+vpath %$(PPUEXT) $(COMPILER_UNITTARGETDIR)
+.PHONY: fpc_install fpc_sourceinstall fpc_exampleinstall
+ifdef INSTALL_UNITS
+override INSTALLPPUFILES+=$(addsuffix $(PPUEXT),$(INSTALL_UNITS))
+endif
+ifdef INSTALLPPUFILES
+ifdef PPUFILES
+override INSTALLPPUFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(INSTALLPPUFILES))
+override INSTALLPPULINKFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(shell $(PPUFILES) -S -O $(INSTALLPPUFILES)))
+else
+override INSTALLPPULINKFILES:=$(subst $(PPUEXT),$(OEXT),$(INSTALLPPUFILES)) $(addprefix $(LIBPREFIX),$(subst $(PPUEXT),$(STATICLIBEXT),$(INSTALLPPUFILES)))
+override INSTALLPPUFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(INSTALLPPUFILES))
+override INSTALLPPULINKFILES:=$(wildcard $(addprefix $(UNITTARGETDIRPREFIX),$(INSTALLPPULINKFILES)))
+endif
+endif
+ifdef INSTALLEXEFILES
+override INSTALLEXEFILES:=$(addprefix $(TARGETDIRPREFIX),$(INSTALLEXEFILES))
+endif
+fpc_install: $(INSTALLTARGET)
+ifdef INSTALLEXEFILES
+	$(MKDIR) $(INSTALL_BINDIR)
+ifdef UPXPROG
+	-$(UPXPROG) $(INSTALLEXEFILES)
+endif
+	$(INSTALLEXE) $(INSTALLEXEFILES) $(INSTALL_BINDIR)
+endif
+ifdef INSTALLPPUFILES
+	$(MKDIR) $(INSTALL_UNITDIR)
+	$(INSTALL) $(INSTALLPPUFILES) $(INSTALL_UNITDIR)
+ifneq ($(INSTALLPPULINKFILES),)
+	$(INSTALL) $(INSTALLPPULINKFILES) $(INSTALL_UNITDIR)
+endif
+ifneq ($(wildcard $(LIB_FULLNAME)),)
+	$(MKDIR) $(INSTALL_LIBDIR)
+	$(INSTALL) $(LIB_FULLNAME) $(INSTALL_LIBDIR)
+ifdef inUnix
+	ln -sf $(LIB_FULLNAME) $(INSTALL_LIBDIR)/$(LIB_NAME)
+endif
+endif
+endif
+ifdef INSTALL_FILES
+	$(MKDIR) $(INSTALL_DATADIR)
+	$(INSTALL) $(INSTALL_FILES) $(INSTALL_DATADIR)
+endif
+fpc_sourceinstall: distclean
+	$(MKDIR) $(INSTALL_SOURCEDIR)
+	$(COPYTREE) $(BASEDIR) $(INSTALL_SOURCEDIR)
+fpc_exampleinstall: $(addsuffix _distclean,$(TARGET_EXAMPLEDIRS))
+ifdef HASEXAMPLES
+	$(MKDIR) $(INSTALL_EXAMPLEDIR)
+endif
+ifdef EXAMPLESOURCEFILES
+	$(COPY) $(EXAMPLESOURCEFILES) $(INSTALL_EXAMPLEDIR)
+endif
+ifdef TARGET_EXAMPLEDIRS
+	$(COPYTREE) $(addsuffix /*,$(TARGET_EXAMPLEDIRS)) $(INSTALL_EXAMPLEDIR)
+endif
+fpc_distinstall: install exampleinstall
+.PHONY: fpc_zipinstall fpc_zipsourceinstall fpc_zipexampleinstall
+ifndef PACKDIR
+ifndef inUnix
+PACKDIR=$(BASEDIR)/../fpc-pack
+else
+PACKDIR=/tmp/fpc-pack
+endif
+endif
+ifndef ZIPNAME
+ifdef DIST_ZIPNAME
+ZIPNAME=$(DIST_ZIPNAME)
+else
+ZIPNAME=$(ZIPPREFIX)$(PACKAGE_NAME)$(ZIPSUFFIX)
+endif
+endif
+ifndef ZIPTARGET
+ifdef DIST_ZIPTARGET
+ZIPTARGET=DIST_ZIPTARGET
+else
+ZIPTARGET=install
+endif
+endif
+ifndef USEZIP
+ifdef inUnix
+USETAR=1
+endif
+endif
+ifdef inOS2
+USEZIPWRAPPER=1
+endif
+ZIPWRAPPER=$(DIST_DESTDIR)/fpczip$(BATCHEXT)
+ZIPCMD_CDPACK:=cd $(subst /,$(PATHSEP),$(PACKDIR))
+ZIPCMD_CDBASE:=cd $(subst /,$(PATHSEP),$(BASEDIR))
+ifdef USETAR
+ZIPDESTFILE:=$(DIST_DESTDIR)/$(ZIPNAME)$(TAREXT)
+ZIPCMD_ZIP:=$(TARPROG) cf$(TAROPT) $(ZIPDESTFILE) *
+else
+ZIPDESTFILE:=$(DIST_DESTDIR)/$(ZIPNAME)$(ZIPEXT)
+ZIPCMD_ZIP:=$(subst /,$(PATHSEP),$(ZIPPROG)) -Dr $(ZIPOPT) $(ZIPDESTFILE) *
+endif
+fpc_zipinstall:
+	$(MAKE) $(ZIPTARGET) INSTALL_PREFIX=$(PACKDIR) ZIPINSTALL=1
+	$(DEL) $(ZIPDESTFILE)
+ifdef USEZIPWRAPPER
+ifneq ($(ECHO),echo)
+	$(ECHO) "$(ZIPCMD_CDPACK)" > $(ZIPWRAPPER)
+	$(ECHO) "$(ZIPCMD_ZIP)" >> $(ZIPWRAPPER)
+	$(ECHO) "$(ZIPCMD_CDBASE)" >> $(ZIPWRAPPER)
+else
+	$(ECHO) $(ZIPCMD_CDPACK) > $(ZIPWRAPPER)
+	$(ECHO) $(ZIPCMD_ZIP) >> $(ZIPWRAPPER)
+	$(ECHO) $(ZIPCMD_CDBASE) >> $(ZIPWRAPPER)
+endif
+ifdef inUnix
+	/bin/sh $(ZIPWRAPPER)
+else
+	$(ZIPWRAPPER)
+endif
+	$(DEL) $(ZIPWRAPPER)
+else
+	$(ZIPCMD_CDPACK) ; $(ZIPCMD_ZIP) ; $(ZIPCMD_CDBASE)
+endif
+	$(DELTREE) $(PACKDIR)
+fpc_zipsourceinstall:
+	$(MAKE) fpc_zipinstall ZIPTARGET=sourceinstall ZIPSUFFIX=src
+fpc_zipexampleinstall:
+ifdef HASEXAMPLES
+	$(MAKE) fpc_zipinstall ZIPTARGET=exampleinstall ZIPSUFFIX=exm
+endif
+fpc_zipdistinstall:
+	$(MAKE) fpc_zipinstall ZIPTARGET=distinstall
+.PHONY: fpc_clean fpc_cleanall fpc_distclean
+ifdef EXEFILES
+override CLEANEXEFILES:=$(addprefix $(TARGETDIRPREFIX),$(CLEANEXEFILES))
+endif
+ifdef CLEAN_UNITS
+override CLEANPPUFILES+=$(addsuffix $(PPUEXT),$(CLEAN_UNITS))
+endif
+ifdef CLEANPPUFILES
+override CLEANPPUFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(CLEANPPUFILES))
+ifdef PPUFILES
+CLEANPPULINKFILES:=$(shell $(PPUFILES) $(CLEANPPUFILES))
+else
+CLEANPPULINKFILES:=$(wildcard $(subst $(PPUEXT),$(OEXT),$(CLEANPPUFILES)) $(addprefix $(LIBPREFIX),$(subst $(PPUEXT),$(STATICLIBEXT),$(CLEANPPUFILES))))
+endif
+override CLEANPPULINKFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(CLEANPPULINKFILES))
+endif
+fpc_clean: $(CLEANTARGET)
+ifdef CLEANEXEFILES
+	-$(DEL) $(CLEANEXEFILES)
+endif
+ifdef CLEANPPUFILES
+	-$(DEL) $(CLEANPPUFILES)
+endif
+ifneq ($(CLEANPPULINKFILES),)
+	-$(DEL) $(CLEANPPULINKFILES)
+endif
+ifdef CLEANRSTFILES
+	-$(DEL) $(addprefix $(UNITTARGETDIRPREFIX),$(CLEANRSTFILES))
+endif
+ifdef CLEAN_FILES
+	-$(DEL) $(CLEAN_FILES)
+endif
+ifdef LIB_NAME
+	-$(DEL) $(LIB_NAME) $(LIB_FULLNAME)
+endif
+	-$(DEL) $(FPCMADE) $(PPAS) link.res $(FPCEXTFILE) $(REDIRFILE)
+fpc_distclean: clean
+ifdef COMPILER_UNITTARGETDIR
+TARGETDIRCLEAN=fpc_clean
+endif
+fpc_cleanall: $(CLEANTARGET) $(TARGETDIRCLEAN)
+ifdef CLEANEXEFILES
+	-$(DEL) $(CLEANEXEFILES)
+endif
+	-$(DEL) *$(OEXT) *$(PPUEXT) *$(RSTEXT) *$(ASMEXT) *$(STATICLIBEXT) *$(SHAREDLIBEXT) *$(PPLEXT)
+	-$(DELTREE) *$(SMARTEXT)
+	-$(DEL) $(FPCMADE) $(PPAS) link.res $(FPCEXTFILE) $(REDIRFILE)
+ifdef AOUTEXT
+	-$(DEL) *$(AOUTEXT)
+endif
+.PHONY: fpc_info
+fpc_info:
+	@$(ECHO)
+	@$(ECHO)  == Package info ==
+	@$(ECHO)  Package Name..... $(PACKAGE_NAME)
+	@$(ECHO)  Package Version.. $(PACKAGE_VERSION)
+	@$(ECHO)
+	@$(ECHO)  == Configuration info ==
+	@$(ECHO)
+	@$(ECHO)  FPC.......... $(FPC)
+	@$(ECHO)  FPC Version.. $(FPC_VERSION)
+	@$(ECHO)  Source CPU... $(CPU_SOURCE)
+	@$(ECHO)  Target CPU... $(CPU_TARGET)
+	@$(ECHO)  Source OS.... $(OS_SOURCE)
+	@$(ECHO)  Target OS.... $(OS_TARGET)
+	@$(ECHO)
+	@$(ECHO)  == Directory info ==
+	@$(ECHO)
+	@$(ECHO)  Basedir......... $(BASEDIR)
+	@$(ECHO)  FPCDir.......... $(FPCDIR)
+	@$(ECHO)  UnitsDir........ $(UNITSDIR)
+	@$(ECHO)  PackagesDir..... $(PACKAGESDIR)
+	@$(ECHO)
+	@$(ECHO)  GCC library..... $(GCCLIBDIR)
+	@$(ECHO)  Other library... $(OTHERLIBDIR)
+	@$(ECHO)
+	@$(ECHO)  == Tools info ==
+	@$(ECHO)
+	@$(ECHO)  Pwd....... $(PWD)
+	@$(ECHO)  Echo...... $(ECHO)
+	@$(ECHO)  PPUMove... $(PPUMOVE)
+	@$(ECHO)  PPUFiles.. $(PPUFILES)
+	@$(ECHO)  Date...... $(DATE)
+	@$(ECHO)  Upx....... $(UPXPROG)
+	@$(ECHO)  Zip....... $(ZIPPROG)
+	@$(ECHO)
+	@$(ECHO)  == Object info ==
+	@$(ECHO)
+	@$(ECHO)  Target Loaders...... $(TARGET_LOADERS)
+	@$(ECHO)  Target Units........ $(TARGET_UNITS)
+	@$(ECHO)  Target Programs..... $(TARGET_PROGRAMS)
+	@$(ECHO)  Target Dirs......... $(TARGET_DIRS)
+	@$(ECHO)  Target Examples..... $(TARGET_EXAMPLES)
+	@$(ECHO)  Target ExampleDirs.. $(TARGET_EXAMPLEDIRS)
+	@$(ECHO)
+	@$(ECHO)  Clean Units......... $(CLEAN_UNITS)
+	@$(ECHO)  Clean Files......... $(CLEAN_FILES)
+	@$(ECHO)
+	@$(ECHO)  Install Units....... $(INSTALL_UNITS)
+	@$(ECHO)  Install Files....... $(INSTALL_FILES)
+	@$(ECHO)
+	@$(ECHO)  == Install info ==
+	@$(ECHO)
+	@$(ECHO)  DateStr.............. $(DATESTR)
+	@$(ECHO)  ZipPrefix............ $(ZIPPREFIX)
+	@$(ECHO)  ZipSuffix............ $(ZIPSUFFIX)
+	@$(ECHO)  Install FPC Package.. $(INSTALL_FPCPACKAGE)
+	@$(ECHO)
+	@$(ECHO)  Install base dir..... $(INSTALL_BASEDIR)
+	@$(ECHO)  Install binary dir... $(INSTALL_BINDIR)
+	@$(ECHO)  Install library dir.. $(INSTALL_LIBDIR)
+	@$(ECHO)  Install units dir.... $(INSTALL_UNITDIR)
+	@$(ECHO)  Install source dir... $(INSTALL_SOURCEDIR)
+	@$(ECHO)  Install doc dir...... $(INSTALL_DOCDIR)
+	@$(ECHO)  Install example dir.. $(INSTALL_EXAMPLEDIR)
+	@$(ECHO)  Install data dir..... $(INSTALL_DATADIR)
+	@$(ECHO)
+	@$(ECHO)  Dist destination dir. $(DIST_DESTDIR)
+	@$(ECHO)  Dist zip name........ $(DIST_ZIPNAME)
+	@$(ECHO)
+TARGET_DIRS_TEXT=1
+TARGET_DIRS_GRAPH=1
+ifeq ($(OS_TARGET),linux)
+TARGET_DIRS_LINUX=1
+endif
+ifeq ($(OS_TARGET),go32v2)
+TARGET_DIRS_MODEX=1
+endif
+ifeq ($(OS_TARGET),win32)
+TARGET_DIRS_WIN32=1
+endif
+ifeq ($(OS_TARGET),os2)
+TARGET_DIRS_OS2=1
+endif
+ifdef TARGET_DIRS_TEXT
+text_all:
+	$(MAKE) -C text all
+text_debug:
+	$(MAKE) -C text debug
+text_examples:
+	$(MAKE) -C text examples
+text_smart:
+	$(MAKE) -C text smart
+text_shared:
+	$(MAKE) -C text shared
+text_install:
+	$(MAKE) -C text install
+text_sourceinstall:
+	$(MAKE) -C text sourceinstall
+text_exampleinstall:
+	$(MAKE) -C text exampleinstall
+text_distinstall:
+	$(MAKE) -C text distinstall
+text_zipinstall:
+	$(MAKE) -C text zipinstall
+text_zipsourceinstall:
+	$(MAKE) -C text zipsourceinstall
+text_zipexampleinstall:
+	$(MAKE) -C text zipexampleinstall
+text_zipdistinstall:
+	$(MAKE) -C text zipdistinstall
+text_clean:
+	$(MAKE) -C text clean
+text_distclean:
+	$(MAKE) -C text distclean
+text_cleanall:
+	$(MAKE) -C text cleanall
+text_info:
+	$(MAKE) -C text info
+text:
+	$(MAKE) -C text all
+.PHONY: text_all text_debug text_examples text_smart text_shared text_install text_sourceinstall text_exampleinstall text_distinstall text_zipinstall text_zipsourceinstall text_zipexampleinstall text_zipdistinstall text_clean text_distclean text_cleanall text_info text
+endif
+ifdef TARGET_DIRS_GRAPH
+graph_all:
+	$(MAKE) -C graph all
+graph_debug:
+	$(MAKE) -C graph debug
+graph_examples:
+	$(MAKE) -C graph examples
+graph_smart:
+	$(MAKE) -C graph smart
+graph_shared:
+	$(MAKE) -C graph shared
+graph_install:
+	$(MAKE) -C graph install
+graph_sourceinstall:
+	$(MAKE) -C graph sourceinstall
+graph_exampleinstall:
+	$(MAKE) -C graph exampleinstall
+graph_distinstall:
+	$(MAKE) -C graph distinstall
+graph_zipinstall:
+	$(MAKE) -C graph zipinstall
+graph_zipsourceinstall:
+	$(MAKE) -C graph zipsourceinstall
+graph_zipexampleinstall:
+	$(MAKE) -C graph zipexampleinstall
+graph_zipdistinstall:
+	$(MAKE) -C graph zipdistinstall
+graph_clean:
+	$(MAKE) -C graph clean
+graph_distclean:
+	$(MAKE) -C graph distclean
+graph_cleanall:
+	$(MAKE) -C graph cleanall
+graph_info:
+	$(MAKE) -C graph info
+graph:
+	$(MAKE) -C graph all
+.PHONY: graph_all graph_debug graph_examples graph_smart graph_shared graph_install graph_sourceinstall graph_exampleinstall graph_distinstall graph_zipinstall graph_zipsourceinstall graph_zipexampleinstall graph_zipdistinstall graph_clean graph_distclean graph_cleanall graph_info graph
+endif
+ifdef TARGET_DIRS_LINUX
+linux_all:
+	$(MAKE) -C linux all
+linux_debug:
+	$(MAKE) -C linux debug
+linux_examples:
+	$(MAKE) -C linux examples
+linux_smart:
+	$(MAKE) -C linux smart
+linux_shared:
+	$(MAKE) -C linux shared
+linux_install:
+	$(MAKE) -C linux install
+linux_sourceinstall:
+	$(MAKE) -C linux sourceinstall
+linux_exampleinstall:
+	$(MAKE) -C linux exampleinstall
+linux_distinstall:
+	$(MAKE) -C linux distinstall
+linux_zipinstall:
+	$(MAKE) -C linux zipinstall
+linux_zipsourceinstall:
+	$(MAKE) -C linux zipsourceinstall
+linux_zipexampleinstall:
+	$(MAKE) -C linux zipexampleinstall
+linux_zipdistinstall:
+	$(MAKE) -C linux zipdistinstall
+linux_clean:
+	$(MAKE) -C linux clean
+linux_distclean:
+	$(MAKE) -C linux distclean
+linux_cleanall:
+	$(MAKE) -C linux cleanall
+linux_info:
+	$(MAKE) -C linux info
+linux:
+	$(MAKE) -C linux all
+.PHONY: linux_all linux_debug linux_examples linux_smart linux_shared linux_install linux_sourceinstall linux_exampleinstall linux_distinstall linux_zipinstall linux_zipsourceinstall linux_zipexampleinstall linux_zipdistinstall linux_clean linux_distclean linux_cleanall linux_info linux
+endif
+ifdef TARGET_DIRS_MODEX
+modex_all:
+	$(MAKE) -C modex all
+modex_debug:
+	$(MAKE) -C modex debug
+modex_examples:
+	$(MAKE) -C modex examples
+modex_smart:
+	$(MAKE) -C modex smart
+modex_shared:
+	$(MAKE) -C modex shared
+modex_install:
+	$(MAKE) -C modex install
+modex_sourceinstall:
+	$(MAKE) -C modex sourceinstall
+modex_exampleinstall:
+	$(MAKE) -C modex exampleinstall
+modex_distinstall:
+	$(MAKE) -C modex distinstall
+modex_zipinstall:
+	$(MAKE) -C modex zipinstall
+modex_zipsourceinstall:
+	$(MAKE) -C modex zipsourceinstall
+modex_zipexampleinstall:
+	$(MAKE) -C modex zipexampleinstall
+modex_zipdistinstall:
+	$(MAKE) -C modex zipdistinstall
+modex_clean:
+	$(MAKE) -C modex clean
+modex_distclean:
+	$(MAKE) -C modex distclean
+modex_cleanall:
+	$(MAKE) -C modex cleanall
+modex_info:
+	$(MAKE) -C modex info
+modex:
+	$(MAKE) -C modex all
+.PHONY: modex_all modex_debug modex_examples modex_smart modex_shared modex_install modex_sourceinstall modex_exampleinstall modex_distinstall modex_zipinstall modex_zipsourceinstall modex_zipexampleinstall modex_zipdistinstall modex_clean modex_distclean modex_cleanall modex_info modex
+endif
+ifdef TARGET_DIRS_WIN32
+win32_all:
+	$(MAKE) -C win32 all
+win32_debug:
+	$(MAKE) -C win32 debug
+win32_examples:
+	$(MAKE) -C win32 examples
+win32_smart:
+	$(MAKE) -C win32 smart
+win32_shared:
+	$(MAKE) -C win32 shared
+win32_install:
+	$(MAKE) -C win32 install
+win32_sourceinstall:
+	$(MAKE) -C win32 sourceinstall
+win32_exampleinstall:
+	$(MAKE) -C win32 exampleinstall
+win32_distinstall:
+	$(MAKE) -C win32 distinstall
+win32_zipinstall:
+	$(MAKE) -C win32 zipinstall
+win32_zipsourceinstall:
+	$(MAKE) -C win32 zipsourceinstall
+win32_zipexampleinstall:
+	$(MAKE) -C win32 zipexampleinstall
+win32_zipdistinstall:
+	$(MAKE) -C win32 zipdistinstall
+win32_clean:
+	$(MAKE) -C win32 clean
+win32_distclean:
+	$(MAKE) -C win32 distclean
+win32_cleanall:
+	$(MAKE) -C win32 cleanall
+win32_info:
+	$(MAKE) -C win32 info
+win32:
+	$(MAKE) -C win32 all
+.PHONY: win32_all win32_debug win32_examples win32_smart win32_shared win32_install win32_sourceinstall win32_exampleinstall win32_distinstall win32_zipinstall win32_zipsourceinstall win32_zipexampleinstall win32_zipdistinstall win32_clean win32_distclean win32_cleanall win32_info win32
+endif
+ifdef TARGET_DIRS_OS2
+os2_all:
+	$(MAKE) -C os2 all
+os2_debug:
+	$(MAKE) -C os2 debug
+os2_examples:
+	$(MAKE) -C os2 examples
+os2_smart:
+	$(MAKE) -C os2 smart
+os2_shared:
+	$(MAKE) -C os2 shared
+os2_install:
+	$(MAKE) -C os2 install
+os2_sourceinstall:
+	$(MAKE) -C os2 sourceinstall
+os2_exampleinstall:
+	$(MAKE) -C os2 exampleinstall
+os2_distinstall:
+	$(MAKE) -C os2 distinstall
+os2_zipinstall:
+	$(MAKE) -C os2 zipinstall
+os2_zipsourceinstall:
+	$(MAKE) -C os2 zipsourceinstall
+os2_zipexampleinstall:
+	$(MAKE) -C os2 zipexampleinstall
+os2_zipdistinstall:
+	$(MAKE) -C os2 zipdistinstall
+os2_clean:
+	$(MAKE) -C os2 clean
+os2_distclean:
+	$(MAKE) -C os2 distclean
+os2_cleanall:
+	$(MAKE) -C os2 cleanall
+os2_info:
+	$(MAKE) -C os2 info
+os2:
+	$(MAKE) -C os2 all
+.PHONY: os2_all os2_debug os2_examples os2_smart os2_shared os2_install os2_sourceinstall os2_exampleinstall os2_distinstall os2_zipinstall os2_zipsourceinstall os2_zipexampleinstall os2_zipdistinstall os2_clean os2_distclean os2_cleanall os2_info os2
+endif
+all: fpc_all $(addsuffix _all,$(TARGET_DIRS))
+debug: fpc_debug $(addsuffix _debug,$(TARGET_DIRS))
+examples: fpc_examples $(addsuffix _examples,$(TARGET_DIRS))
+smart: fpc_smart $(addsuffix _smart,$(TARGET_DIRS))
+shared: fpc_shared $(addsuffix _shared,$(TARGET_DIRS))
+install: fpc_install $(addsuffix _install,$(TARGET_DIRS))
+sourceinstall: fpc_sourceinstall
+exampleinstall: fpc_exampleinstall $(addsuffix _exampleinstall,$(TARGET_DIRS))
+distinstall: fpc_distinstall $(addsuffix _distinstall,$(TARGET_DIRS))
+zipinstall: fpc_zipinstall
+zipsourceinstall: fpc_zipsourceinstall
+zipexampleinstall: fpc_zipexampleinstall $(addsuffix _zipexampleinstall,$(TARGET_DIRS))
+zipdistinstall: fpc_zipdistinstall $(addsuffix _zipdistinstall,$(TARGET_DIRS))
+clean: fpc_clean $(addsuffix _clean,$(TARGET_DIRS))
+distclean: fpc_distclean $(addsuffix _distclean,$(TARGET_DIRS))
+cleanall: fpc_cleanall $(addsuffix _cleanall,$(TARGET_DIRS))
+info: fpc_info $(addsuffix _info,$(TARGET_DIRS))
+.PHONY: all debug examples smart shared install sourceinstall exampleinstall distinstall zipinstall zipsourceinstall zipexampleinstall zipdistinstall clean distclean cleanall info
+ifneq ($(wildcard fpcmake.loc),)
+include fpcmake.loc
+endif
+.PHONY: installexamples
+installexamples:
+	$(MAKE) sourceinstall SOURCEINSTALLDIR=$(EXAMPLEINSTALLDIR)

+ 25 - 0
demo/Makefile.fpc

@@ -0,0 +1,25 @@
+#
+#   Makefile.fpc for FPC demo package
+#
+
+[package]
+name=demo
+version=1.0.5
+
+[target]
+dirs=text graph
+dirs_go32v2=modex
+dirs_win32=win32
+dirs_linux=linux
+dirs_os2=os2
+
+
+[rules]
+#################################
+# Demo installation for linux
+#
+
+.PHONY: installexamples
+
+installexamples:
+        $(MAKE) sourceinstall SOURCEINSTALLDIR=$(EXAMPLEINSTALLDIR)

+ 18 - 0
demo/fpcdemos.txt

@@ -0,0 +1,18 @@
+FPC demo package
+================
+This packages contains the following subdirs:
+
+- text   text mode demos (should run everywhere)
+- graph  demos those use the graph unit (runs nearly everywhere)
+         includes gameunit (text&graph), outputs to another subdir level
+- modex  demos those make extensive use of modeX (runs with go32v2 only)
+- win32  demos those are win32 specific
+- linux  demos those are linux specific
+- os2    demos those are OS/2 specific
+
+To build the programs simply type 'make' in the base dir.
+
+If you want to add further samples, edit Makefile.fpc
+and rebuild the real Makefile by entering 'fpcmake'.
+This is a special fpc generic utility to simplify
+platform independent makefile generation for the user.

+ 851 - 0
demo/graph/Makefile

@@ -0,0 +1,851 @@
+#
+# Don't edit, this file is generated by fpcmake v1.99.0 [2001/05/03]
+#
+default: all
+override PATH:=$(subst \,/,$(PATH))
+ifeq ($(findstring ;,$(PATH)),)
+inUnix=1
+SEARCHPATH:=$(subst :, ,$(PATH))
+else
+SEARCHPATH:=$(subst ;, ,$(PATH))
+endif
+PWD:=$(strip $(wildcard $(addsuffix /pwd.exe,$(SEARCHPATH))))
+ifeq ($(PWD),)
+PWD:=$(strip $(wildcard $(addsuffix /pwd,$(SEARCHPATH))))
+ifeq ($(PWD),)
+nopwd:
+	@echo You need the GNU utils package to use this Makefile!
+	@echo Get ftp://ftp.freepascal.org/pub/fpc/dist/go32v2/utilgo32.zip
+	@exit
+else
+PWD:=$(firstword $(PWD))
+SRCEXEEXT=
+endif
+else
+PWD:=$(firstword $(PWD))
+SRCEXEEXT=.exe
+endif
+ifndef inUnix
+ifeq ($(OS),Windows_NT)
+inWinNT=1
+else
+ifdef OS2_SHELL
+inOS2=1
+endif
+endif
+else
+ifneq ($(findstring cygwin,$(MACH_TYPE)),)
+inCygWin=1
+endif
+endif
+ifdef inUnix
+BATCHEXT=.sh
+else
+ifdef inOS2
+BATCHEXT=.cmd
+else
+BATCHEXT=.bat
+endif
+endif
+ifdef inUnix
+PATHSEP=/
+else
+PATHSEP:=$(subst /,\,/)
+endif
+ifdef PWD
+BASEDIR:=$(shell $(PWD))
+else
+BASEDIR=.
+endif
+ifndef FPC
+ifdef PP
+FPC=$(PP)
+else
+FPC=ppc386
+endif
+endif
+override FPC:=$(subst $(SRCEXEEXT),,$(FPC))
+override FPC:=$(subst \,/,$(FPC))$(SRCEXEEXT)
+ifndef OS_TARGET
+OS_TARGET:=$(shell $(FPC) -iTO)
+endif
+ifndef OS_SOURCE
+OS_SOURCE:=$(shell $(FPC) -iSO)
+endif
+ifndef CPU_TARGET
+CPU_TARGET:=$(shell $(FPC) -iTP)
+endif
+ifndef CPU_SOURCE
+CPU_SOURCE:=$(shell $(FPC) -iSP)
+endif
+ifndef FPC_VERSION
+FPC_VERSION:=$(shell $(FPC) -iV)
+endif
+export FPC OS_TARGET OS_SOURCE CPU_TARGET CPU_SOURCE FPC_VERSION
+ifdef FPCDIR
+override FPCDIR:=$(subst \,/,$(FPCDIR))
+ifeq ($(wildcard $(addprefix $(FPCDIR)/,rtl units)),)
+override FPCDIR=wrong
+endif
+else
+override FPCDIR=wrong
+endif
+ifeq ($(FPCDIR),wrong)
+override FPCDIR=../..
+ifeq ($(wildcard $(FPCDIR)/rtl),)
+ifeq ($(wildcard $(FPCDIR)/units),)
+override FPCDIR=wrong
+endif
+endif
+endif
+ifeq ($(FPCDIR),wrong)
+ifdef inUnix
+override FPCDIR=/usr/local/lib/fpc/$(FPC_VERSION)
+ifeq ($(wildcard $(FPCDIR)/units),)
+override FPCDIR=/usr/lib/fpc/$(FPC_VERSION)
+endif
+else
+override FPCDIR:=$(subst /$(FPC),,$(firstword $(strip $(wildcard $(addsuffix /$(FPC),$(SEARCHPATH))))))
+override FPCDIR:=$(FPCDIR)/..
+ifeq ($(wildcard $(addprefix $(FPCDIR)/,rtl units)),)
+override FPCDIR:=$(FPCDIR)/..
+ifeq ($(wildcard $(addprefix $(FPCDIR)/,rtl units)),)
+override FPCDIR=c:/pp
+endif
+endif
+endif
+endif
+UNITSDIR:=$(wildcard $(FPCDIR)/units/$(OS_TARGET))
+PACKAGESDIR:=$(wildcard $(FPCDIR) $(FPCDIR)/packages)
+ifdef GRAPHICS
+override FPCOPT+=-dUSEGRAPHICS
+endif
+override TARGET_PROGRAMS+=fpctris mandel samegame quad maze gravwars
+override TARGET_UNITS+=gameunit
+ifndef ECHO
+ECHO:=$(strip $(wildcard $(addsuffix /gecho$(EXEEXT),$(SEARCHPATH))))
+ifeq ($(ECHO),)
+ECHO:=$(strip $(wildcard $(addsuffix /echo$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(ECHO),)
+ECHO:=echo
+else
+ECHO:=$(firstword $(ECHO))
+endif
+else
+ECHO:=$(firstword $(ECHO))
+endif
+endif
+ifndef COPY
+COPY:=cp -fp
+endif
+ifndef COPYTREE
+COPYTREE:=cp -rfp
+endif
+ifndef MOVE
+MOVE:=mv -f
+endif
+ifndef DEL
+DEL:=rm -f
+endif
+ifndef DELTREE
+DELTREE:=rm -rf
+endif
+ifndef INSTALL
+ifdef inUnix
+INSTALL:=install -c -m 644
+else
+INSTALL:=$(COPY)
+endif
+endif
+ifndef INSTALLEXE
+ifdef inUnix
+INSTALLEXE:=install -c -m 755
+else
+INSTALLEXE:=$(COPY)
+endif
+endif
+ifndef MKDIR
+ifdef inUnix
+MKDIR:=install -m 755 -d
+else
+MKDIR:=ginstall -m 755 -d
+endif
+endif
+export ECHO COPY COPYTREE MOVE DEL DELTREE INSTALL INSTALLEXE MKDIR
+ifndef AS
+AS=as
+endif
+ifndef LD
+LD=ld
+endif
+ifndef RC
+RC=rc
+endif
+PPAS=ppas$(BATCHEXT)
+ifdef inUnix
+LDCONFIG=ldconfig
+else
+LDCONFIG=
+endif
+ifndef PPUMOVE
+PPUMOVE:=$(strip $(wildcard $(addsuffix /ppumove$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(PPUMOVE),)
+PPUMOVE=
+else
+PPUMOVE:=$(firstword $(PPUMOVE))
+endif
+endif
+export PPUMOVE
+ifndef PPUFILES
+PPUFILES:=$(strip $(wildcard $(addsuffix /ppufiles$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(PPUFILES),)
+PPUFILES=
+else
+PPUFILES:=$(firstword $(PPUFILES))
+endif
+endif
+export PPUFILES
+ifndef DATE
+DATE:=$(strip $(wildcard $(addsuffix /date$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(DATE),)
+DATE:=$(strip $(wildcard $(addsuffix /gdate$(SRCEXEEXT),$(SEACHPATH))))
+ifeq ($(DATE),)
+DATE=
+else
+DATE:=$(firstword $(DATE))
+endif
+else
+DATE:=$(firstword $(DATE))
+endif
+endif
+export DATE
+ifdef DATE
+DATESTR:=$(shell $(DATE) +%Y%m%d)
+else
+DATESTR=
+endif
+ifndef UPXPROG
+ifeq ($(OS_TARGET),go32v2)
+UPXPROG:=1
+endif
+ifeq ($(OS_TARGET),win32)
+UPXPROG:=1
+endif
+ifdef UPXPROG
+UPXPROG:=$(strip $(wildcard $(addsuffix /upx$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(UPXPROG),)
+UPXPROG=
+else
+UPXPROG:=$(firstword $(UPXPROG))
+endif
+else
+UPXPROG=
+endif
+endif
+export UPXPROG
+ifndef ZIPPROG
+ZIPPROG:=$(strip $(wildcard $(addsuffix /zip$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(ZIPPROG),)
+ZIPPROG=
+else
+ZIPPROG:=$(firstword $(ZIPPROG))
+endif
+endif
+export ZIPPROG
+ZIPOPT=-9
+ZIPEXT=.zip
+ifndef TARPROG
+TARPROG:=$(strip $(wildcard $(addsuffix /tar$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(TARPROG),)
+TARPROG=
+else
+TARPROG:=$(firstword $(TARPROG))
+endif
+endif
+export TARPROG
+ifeq ($(USETAR),bz2)
+TAROPT=vI
+TAREXT=.tar.bz2
+else
+TAROPT=vz
+TAREXT=.tar.gz
+endif
+LOADEREXT=.as
+EXEEXT=.exe
+PPLEXT=.ppl
+PPUEXT=.ppu
+OEXT=.o
+ASMEXT=.s
+SMARTEXT=.sl
+STATICLIBEXT=.a
+SHAREDLIBEXT=.so
+LIBPREFIX=lib
+RSTEXT=.rst
+FPCMADE=fpcmade
+ifeq ($(OS_TARGET),go32v1)
+PPUEXT=.pp1
+OEXT=.o1
+ASMEXT=.s1
+SMARTEXT=.sl1
+STATICLIBEXT=.a1
+SHAREDLIBEXT=.so1
+LIBPREFIX=
+FPCMADE=fpcmade.v1
+PACKAGESUFFIX=v1
+endif
+ifeq ($(OS_TARGET),go32v2)
+LIBPREFIX=
+FPCMADE=fpcmade.dos
+ZIPSUFFIX=go32
+endif
+ifeq ($(OS_TARGET),linux)
+EXEEXT=
+HASSHAREDLIB=1
+FPCMADE=fpcmade.lnx
+ZIPSUFFIX=linux
+endif
+ifeq ($(OS_TARGET),freebsd)
+EXEEXT=
+HASSHAREDLIB=1
+FPCMADE=fpcmade.freebsd
+ZIPSUFFIX=freebsd
+endif
+ifeq ($(OS_TARGET),win32)
+PPUEXT=.ppw
+OEXT=.ow
+ASMEXT=.sw
+SMARTEXT=.slw
+STATICLIBEXT=.aw
+SHAREDLIBEXT=.dll
+FPCMADE=fpcmade.w32
+ZIPSUFFIX=w32
+endif
+ifeq ($(OS_TARGET),os2)
+PPUEXT=.ppo
+ASMEXT=.so2
+OEXT=.oo2
+AOUTEXT=.out
+SMARTEXT=.so
+STATICLIBEXT=.ao2
+SHAREDLIBEXT=.dll
+FPCMADE=fpcmade.os2
+ZIPSUFFIX=emx
+endif
+ifdef REQUIRE_UNITSDIR
+override UNITSDIR+=$(REQUIRE_UNITSDIR)
+endif
+ifdef REQUIRE_PACKAGESDIR
+override PACKAGESDIR+=$(REQUIRE_PACKAGESDIR)
+endif
+ifdef ZIPINSTALL
+ifeq ($(OS_TARGET),linux)
+UNIXINSTALLDIR=1
+endif
+ifeq ($(OS_TARGET),freebsd)
+UNIXINSTALLDIR=1
+endif
+else
+ifeq ($(OS_SOURCE),linux)
+UNIXINSTALLDIR=1
+endif
+ifeq ($(OS_SOURCE),freebsd)
+UNIXINSTALLDIR=1
+endif
+endif
+ifndef INSTALL_PREFIX
+ifdef UNIXINSTALLDIR
+INSTALL_PREFIX=/usr/local
+else
+ifdef INSTALL_FPCPACKAGE
+INSTALL_BASEDIR:=/pp
+else
+INSTALL_BASEDIR:=/$(PACKAGE_NAME)
+endif
+endif
+endif
+export INSTALL_PREFIX
+ifndef DIST_DESTDIR
+DIST_DESTDIR:=$(BASEDIR)
+endif
+export DIST_DESTDIR
+ifndef INSTALL_BASEDIR
+ifdef UNIXINSTALLDIR
+ifdef INSTALL_FPCPACKAGE
+INSTALL_BASEDIR:=$(INSTALL_PREFIX)/lib/fpc/$(FPC_VERSION)
+else
+INSTALL_BASEDIR:=$(INSTALL_PREFIX)/lib/$(PACKAGE_NAME)
+endif
+else
+INSTALL_BASEDIR:=$(INSTALL_PREFIX)
+endif
+endif
+ifndef INSTALL_BINDIR
+ifdef UNIXINSTALLDIR
+INSTALL_BINDIR:=$(INSTALL_PREFIX)/bin
+else
+INSTALL_BINDIR:=$(INSTALL_BASEDIR)/bin
+ifdef INSTALL_FPCPACKAGE
+INSTALL_BINDIR:=$(INSTALL_BINDIR)/$(OS_TARGET)
+endif
+endif
+endif
+ifndef INSTALL_UNITDIR
+INSTALL_UNITDIR:=$(INSTALL_BASEDIR)/units/$(OS_TARGET)
+ifdef INSTALL_FPCPACKAGE
+INSTALL_UNITDIR:=$(INSTALL_UNITDIR)/$(PACKAGE_NAME)
+endif
+endif
+ifndef INSTALL_LIBDIR
+ifdef UNIXINSTALLDIR
+INSTALL_LIBDIR:=$(INSTALL_PREFIX)/lib
+else
+INSTALL_LIBDIR:=$(INSTALL_UNITDIR)
+endif
+endif
+ifndef INSTALL_SOURCEDIR
+ifdef UNIXINSTALLDIR
+ifdef INSTALL_FPCPACKAGE
+INSTALL_SOURCEDIR:=$(INSTALL_PREFIX)/src/fpc-$(FPC_VERSION)/$(PACKAGE_NAME)
+else
+INSTALL_SOURCEDIR:=$(INSTALL_PREFIX)/src/$(PACKAGE_NAME)-$(PACKAGE_VERSION)
+endif
+else
+ifdef INSTALL_FPCPACKAGE
+INSTALL_SOURCEDIR:=$(INSTALL_BASEDIR)/source/$(PACKAGE_NAME)
+else
+INSTALL_SOURCEDIRL:=$(INSTALL_BASEDIR)/source
+endif
+endif
+endif
+ifndef INSTALL_DOCDIR
+ifdef UNIXINSTALLDIR
+ifdef INSTALL_FPCPACKAGE
+INSTALL_DOCDIR:=$(INSTALL_PREFIX)/doc/fpc-$(FPC_VERSION)/$(PACKAGE_NAME)
+else
+INSTALL_DOCDIR:=$(INSTALL_PREFIX)/doc/$(PACKAGE_NAME)-$(PACKAGE_VERSION)
+endif
+else
+ifdef INSTALL_FPCPACKAGE
+INSTALL_DOCDIR:=$(INSTALL_BASEDIR)/doc/$(PACKAGE_NAME)
+else
+INSTALL_DOCDIR:=$(INSTALL_BASEDIR)/doc
+endif
+endif
+endif
+ifndef INSTALL_EXAMPLEDIR
+ifdef UNIXINSTALLDIR
+ifdef INSTALL_FPCPACKAGE
+INSTALL_EXAMPLEDIR:=$(INSTALL_PREFIX)/doc/fpc-$(FPC_VERSION)/examples/$(PACKAGE_NAME)
+else
+INSTALL_EXAMPLEDIR:=$(INSTALL_PREFIX)/doc/$(PACKAGE_NAME)-$(PACKAGE_VERSION)
+endif
+else
+ifdef INSTALL_FPCPACKAGE
+INSTALL_EXAMPLEDIR:=$(INSTALL_BASEDIR)/examples/$(PACKAGE_NAME)
+else
+INSTALL_EXAMPLEDIR:=$(INSTALL_BASEDIR)/examples
+endif
+endif
+endif
+ifndef INSTALL_DATADIR
+INSTALL_DATADIR=$(INSTALL_BASEDIR)
+endif
+ifeq ($(OS_TARGET),linux)
+REQUIRE_PACKAGES_RTL=1
+endif
+ifeq ($(OS_TARGET),go32v2)
+REQUIRE_PACKAGES_RTL=1
+endif
+ifeq ($(OS_TARGET),win32)
+REQUIRE_PACKAGES_RTL=1
+endif
+ifeq ($(OS_TARGET),os2)
+REQUIRE_PACKAGES_RTL=1
+endif
+ifeq ($(OS_TARGET),freebsd)
+REQUIRE_PACKAGES_RTL=1
+endif
+ifdef REQUIRE_PACKAGES_RTL
+PACKAGEDIR_RTL:=$(subst /Makefile.fpc,,$(strip $(wildcard $(addsuffix /rtl/Makefile.fpc,$(PACKAGESDIR)))))
+ifneq ($(PACKAGEDIR_RTL),)
+PACKAGEDIR_RTL:=$(firstword $(PACKAGEDIR_RTL))
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=package_rtl
+package_rtl:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+ifneq ($(wildcard $(PACKAGEDIR_RTL)/$(OS_TARGET)),)
+UNITDIR_RTL=$(PACKAGEDIR_RTL)/$(OS_TARGET)
+else
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+endif
+else
+PACKAGEDIR_RTL=
+UNITDIR_RTL:=$(subst /Package.fpc,,$(strip $(wildcard $(addsuffix /rtl/Package.fpc,$(UNITSDIR)))))
+ifneq ($(UNITDIR_RTL),)
+UNITDIR_RTL:=$(firstword $(UNITDIR_RTL))
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override COMPILER_UNITDIR+=$(UNITDIR_RTL)
+endif
+endif
+.PHONY: package_rtl
+override FPCOPTDEF=$(CPU_TARGET)
+ifneq ($(OS_TARGET),$(OS_SOURCE))
+override FPCOPT+=-T$(OS_TARGET)
+endif
+ifdef UNITDIR
+override FPCOPT+=$(addprefix -Fu,$(UNITDIR))
+endif
+ifdef LIBDIR
+override FPCOPT+=$(addprefix -Fl,$(LIBDIR))
+endif
+ifdef OBJDIR
+override FPCOPT+=$(addprefix -Fo,$(OBJDIR))
+endif
+ifdef INCDIR
+override FPCOPT+=$(addprefix -Fi,$(INCDIR))
+endif
+ifdef LINKSMART
+override FPCOPT+=-XX
+endif
+ifdef CREATESMART
+override FPCOPT+=-CX
+endif
+ifdef DEBUG
+override FPCOPT+=-gl
+override FPCOPTDEF+=DEBUG
+endif
+ifdef RELEASE
+override FPCOPT+=-Xs -OG2p3 -n
+override FPCOPTDEF+=RELEASE
+endif
+ifdef STRIP
+override FPCOPT+=-Xs
+endif
+ifdef OPTIMIZE
+override FPCOPT+=-OG2p3
+endif
+ifdef VERBOSE
+override FPCOPT+=-vwni
+endif
+ifdef COMPILER_OPTIONS
+override FPCOPT+=$(COMPILER_OPTIONS)
+endif
+ifdef COMPILER_UNITDIR
+override FPCOPT+=$(addprefix -Fu,$(COMPILER_UNITDIR))
+endif
+ifdef COMPILER_LIBRARYDIR
+override FPCOPT+=$(addprefix -Fl,$(COMPILER_LIBRARYDIR))
+endif
+ifdef COMPILER_OBJECTDIR
+override FPCOPT+=$(addprefix -Fo,$(COMPILER_OBJECTDIR))
+endif
+ifdef COMPILER_INCLUDEDIR
+override FPCOPT+=$(addprefix -Fi,$(COMPILER_INCLUDEDIR))
+endif
+ifdef COMPILER_TARGETDIR
+override FPCOPT+=-FE$(COMPILER_TARGETDIR)
+ifeq ($(COMPILER_TARGETDIR),.)
+override TARGETDIRPREFIX=
+else
+override TARGETDIRPREFIX=$(COMPILER_TARGETDIR)/
+endif
+endif
+ifdef COMPILER_UNITTARGETDIR
+override FPCOPT+=-FU$(COMPILER_UNITTARGETDIR)
+ifeq ($(COMPILER_UNITTARGETDIR),.)
+override UNITTARGETDIRPREFIX=
+else
+override UNITTARGETDIRPREFIX=$(COMPILER_TARGETDIR)/
+endif
+else
+ifdef COMPILER_TARGETDIR
+override COMPILER_UNITTARGETDIR=$(COMPILER_TARGETDIR)
+override UNITTARGETDIRPREFIX=$(TARGETDIRPREFIX)
+endif
+endif
+ifdef OPT
+override FPCOPT+=$(OPT)
+endif
+ifdef FPCOPTDEF
+override FPCOPT+=$(addprefix -d,$(FPCOPTDEF))
+endif
+ifdef CFGFILE
+override FPCOPT+=@$(CFGFILE)
+endif
+ifeq ($(OS_SOURCE),win32)
+USEENV=1
+endif
+ifdef USEENV
+override FPCEXTCMD:=$(FPCOPT)
+override FPCOPT:=!FPCEXTCMD
+export FPCEXTCMD
+endif
+override COMPILER:=$(FPC) $(FPCOPT)
+ifeq (,$(findstring -s ,$(COMPILER)))
+EXECPPAS=
+else
+ifeq ($(OS_SOURCE),$(OS_TARGET))
+EXECPPAS:=@$(PPAS)
+endif
+endif
+.PHONY: fpc_units
+ifdef TARGET_UNITS
+override ALLTARGET+=fpc_units
+override UNITPPUFILES=$(addsuffix $(PPUEXT),$(TARGET_UNITS))
+override INSTALLPPUFILES+=$(UNITPPUFILES)
+override CLEANPPUFILES+=$(UNITPPUFILES)
+endif
+fpc_units: $(UNITPPUFILES)
+.PHONY: fpc_exes
+ifdef TARGET_PROGRAMS
+override EXEFILES=$(addsuffix $(EXEEXT),$(TARGET_PROGRAMS))
+override EXEOFILES:=$(addsuffix $(OEXT),$(TARGET_PROGRAMS)) $(addprefix $(LIBPREFIX),$(addsuffix $(STATICLIBEXT),$(TARGET_PROGRAMS)))
+override ALLTARGET+=fpc_exes
+override INSTALLEXEFILES+=$(EXEFILES)
+override CLEANEXEFILES+=$(EXEFILES) $(EXEOFILES)
+ifeq ($(OS_TARGET),os2)
+override CLEANEXEFILES+=$(addsuffix $(AOUTEXT),$(TARGET_PROGRAMS))
+endif
+endif
+fpc_exes: $(EXEFILES)
+.PHONY: fpc_packages fpc_all fpc_smart fpc_debug
+$(FPCMADE): $(ALLTARGET)
+	@$(ECHO) Compiled > $(FPCMADE)
+fpc_packages: $(COMPILEPACKAGES)
+fpc_all: fpc_packages $(FPCMADE)
+fpc_smart:
+	$(MAKE) all LINKSMART=1 CREATESMART=1
+fpc_debug:
+	$(MAKE) all DEBUG=1
+.SUFFIXES: $(EXEEXT) $(PPUEXT) $(OEXT) .pas .pp
+%$(PPUEXT): %.pp
+	$(COMPILER) $<
+	$(EXECPPAS)
+%$(PPUEXT): %.pas
+	$(COMPILER) $<
+	$(EXECPPAS)
+%$(EXEEXT): %.pp
+	$(COMPILER) $<
+	$(EXECPPAS)
+%$(EXEEXT): %.pas
+	$(COMPILER) $<
+	$(EXECPPAS)
+vpath %.pp $(COMPILER_SOURCEDIR) $(COMPILER_INCLUDEDIR)
+vpath %.pas $(COMPILER_SOURCEDIR) $(COMPILER_INCLUDEDIR)
+vpath %$(PPUEXT) $(COMPILER_UNITTARGETDIR)
+.PHONY: fpc_install fpc_sourceinstall fpc_exampleinstall
+ifdef INSTALL_UNITS
+override INSTALLPPUFILES+=$(addsuffix $(PPUEXT),$(INSTALL_UNITS))
+endif
+ifdef INSTALLPPUFILES
+ifdef PPUFILES
+override INSTALLPPUFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(INSTALLPPUFILES))
+override INSTALLPPULINKFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(shell $(PPUFILES) -S -O $(INSTALLPPUFILES)))
+else
+override INSTALLPPULINKFILES:=$(subst $(PPUEXT),$(OEXT),$(INSTALLPPUFILES)) $(addprefix $(LIBPREFIX),$(subst $(PPUEXT),$(STATICLIBEXT),$(INSTALLPPUFILES)))
+override INSTALLPPUFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(INSTALLPPUFILES))
+override INSTALLPPULINKFILES:=$(wildcard $(addprefix $(UNITTARGETDIRPREFIX),$(INSTALLPPULINKFILES)))
+endif
+endif
+ifdef INSTALLEXEFILES
+override INSTALLEXEFILES:=$(addprefix $(TARGETDIRPREFIX),$(INSTALLEXEFILES))
+endif
+fpc_install: $(INSTALLTARGET)
+ifdef INSTALLEXEFILES
+	$(MKDIR) $(INSTALL_BINDIR)
+ifdef UPXPROG
+	-$(UPXPROG) $(INSTALLEXEFILES)
+endif
+	$(INSTALLEXE) $(INSTALLEXEFILES) $(INSTALL_BINDIR)
+endif
+ifdef INSTALLPPUFILES
+	$(MKDIR) $(INSTALL_UNITDIR)
+	$(INSTALL) $(INSTALLPPUFILES) $(INSTALL_UNITDIR)
+ifneq ($(INSTALLPPULINKFILES),)
+	$(INSTALL) $(INSTALLPPULINKFILES) $(INSTALL_UNITDIR)
+endif
+ifneq ($(wildcard $(LIB_FULLNAME)),)
+	$(MKDIR) $(INSTALL_LIBDIR)
+	$(INSTALL) $(LIB_FULLNAME) $(INSTALL_LIBDIR)
+ifdef inUnix
+	ln -sf $(LIB_FULLNAME) $(INSTALL_LIBDIR)/$(LIB_NAME)
+endif
+endif
+endif
+ifdef INSTALL_FILES
+	$(MKDIR) $(INSTALL_DATADIR)
+	$(INSTALL) $(INSTALL_FILES) $(INSTALL_DATADIR)
+endif
+fpc_sourceinstall: distclean
+	$(MKDIR) $(INSTALL_SOURCEDIR)
+	$(COPYTREE) $(BASEDIR) $(INSTALL_SOURCEDIR)
+fpc_exampleinstall: $(addsuffix _distclean,$(TARGET_EXAMPLEDIRS))
+ifdef HASEXAMPLES
+	$(MKDIR) $(INSTALL_EXAMPLEDIR)
+endif
+ifdef EXAMPLESOURCEFILES
+	$(COPY) $(EXAMPLESOURCEFILES) $(INSTALL_EXAMPLEDIR)
+endif
+ifdef TARGET_EXAMPLEDIRS
+	$(COPYTREE) $(addsuffix /*,$(TARGET_EXAMPLEDIRS)) $(INSTALL_EXAMPLEDIR)
+endif
+fpc_distinstall: install exampleinstall
+.PHONY: fpc_clean fpc_cleanall fpc_distclean
+ifdef EXEFILES
+override CLEANEXEFILES:=$(addprefix $(TARGETDIRPREFIX),$(CLEANEXEFILES))
+endif
+ifdef CLEAN_UNITS
+override CLEANPPUFILES+=$(addsuffix $(PPUEXT),$(CLEAN_UNITS))
+endif
+ifdef CLEANPPUFILES
+override CLEANPPUFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(CLEANPPUFILES))
+ifdef PPUFILES
+CLEANPPULINKFILES:=$(shell $(PPUFILES) $(CLEANPPUFILES))
+else
+CLEANPPULINKFILES:=$(wildcard $(subst $(PPUEXT),$(OEXT),$(CLEANPPUFILES)) $(addprefix $(LIBPREFIX),$(subst $(PPUEXT),$(STATICLIBEXT),$(CLEANPPUFILES))))
+endif
+override CLEANPPULINKFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(CLEANPPULINKFILES))
+endif
+fpc_clean: $(CLEANTARGET)
+ifdef CLEANEXEFILES
+	-$(DEL) $(CLEANEXEFILES)
+endif
+ifdef CLEANPPUFILES
+	-$(DEL) $(CLEANPPUFILES)
+endif
+ifneq ($(CLEANPPULINKFILES),)
+	-$(DEL) $(CLEANPPULINKFILES)
+endif
+ifdef CLEANRSTFILES
+	-$(DEL) $(addprefix $(UNITTARGETDIRPREFIX),$(CLEANRSTFILES))
+endif
+ifdef CLEAN_FILES
+	-$(DEL) $(CLEAN_FILES)
+endif
+ifdef LIB_NAME
+	-$(DEL) $(LIB_NAME) $(LIB_FULLNAME)
+endif
+	-$(DEL) $(FPCMADE) $(PPAS) link.res $(FPCEXTFILE) $(REDIRFILE)
+fpc_distclean: clean
+ifdef COMPILER_UNITTARGETDIR
+TARGETDIRCLEAN=fpc_clean
+endif
+fpc_cleanall: $(CLEANTARGET) $(TARGETDIRCLEAN)
+ifdef CLEANEXEFILES
+	-$(DEL) $(CLEANEXEFILES)
+endif
+	-$(DEL) *$(OEXT) *$(PPUEXT) *$(RSTEXT) *$(ASMEXT) *$(STATICLIBEXT) *$(SHAREDLIBEXT) *$(PPLEXT)
+	-$(DELTREE) *$(SMARTEXT)
+	-$(DEL) $(FPCMADE) $(PPAS) link.res $(FPCEXTFILE) $(REDIRFILE)
+ifdef AOUTEXT
+	-$(DEL) *$(AOUTEXT)
+endif
+.PHONY: fpc_info
+fpc_info:
+	@$(ECHO)
+	@$(ECHO)  == Package info ==
+	@$(ECHO)  Package Name..... $(PACKAGE_NAME)
+	@$(ECHO)  Package Version.. $(PACKAGE_VERSION)
+	@$(ECHO)
+	@$(ECHO)  == Configuration info ==
+	@$(ECHO)
+	@$(ECHO)  FPC.......... $(FPC)
+	@$(ECHO)  FPC Version.. $(FPC_VERSION)
+	@$(ECHO)  Source CPU... $(CPU_SOURCE)
+	@$(ECHO)  Target CPU... $(CPU_TARGET)
+	@$(ECHO)  Source OS.... $(OS_SOURCE)
+	@$(ECHO)  Target OS.... $(OS_TARGET)
+	@$(ECHO)
+	@$(ECHO)  == Directory info ==
+	@$(ECHO)
+	@$(ECHO)  Basedir......... $(BASEDIR)
+	@$(ECHO)  FPCDir.......... $(FPCDIR)
+	@$(ECHO)  UnitsDir........ $(UNITSDIR)
+	@$(ECHO)  PackagesDir..... $(PACKAGESDIR)
+	@$(ECHO)
+	@$(ECHO)  GCC library..... $(GCCLIBDIR)
+	@$(ECHO)  Other library... $(OTHERLIBDIR)
+	@$(ECHO)
+	@$(ECHO)  == Tools info ==
+	@$(ECHO)
+	@$(ECHO)  Pwd....... $(PWD)
+	@$(ECHO)  Echo...... $(ECHO)
+	@$(ECHO)  PPUMove... $(PPUMOVE)
+	@$(ECHO)  PPUFiles.. $(PPUFILES)
+	@$(ECHO)  Date...... $(DATE)
+	@$(ECHO)  Upx....... $(UPXPROG)
+	@$(ECHO)  Zip....... $(ZIPPROG)
+	@$(ECHO)
+	@$(ECHO)  == Object info ==
+	@$(ECHO)
+	@$(ECHO)  Target Loaders...... $(TARGET_LOADERS)
+	@$(ECHO)  Target Units........ $(TARGET_UNITS)
+	@$(ECHO)  Target Programs..... $(TARGET_PROGRAMS)
+	@$(ECHO)  Target Dirs......... $(TARGET_DIRS)
+	@$(ECHO)  Target Examples..... $(TARGET_EXAMPLES)
+	@$(ECHO)  Target ExampleDirs.. $(TARGET_EXAMPLEDIRS)
+	@$(ECHO)
+	@$(ECHO)  Clean Units......... $(CLEAN_UNITS)
+	@$(ECHO)  Clean Files......... $(CLEAN_FILES)
+	@$(ECHO)
+	@$(ECHO)  Install Units....... $(INSTALL_UNITS)
+	@$(ECHO)  Install Files....... $(INSTALL_FILES)
+	@$(ECHO)
+	@$(ECHO)  == Install info ==
+	@$(ECHO)
+	@$(ECHO)  DateStr.............. $(DATESTR)
+	@$(ECHO)  ZipPrefix............ $(ZIPPREFIX)
+	@$(ECHO)  ZipSuffix............ $(ZIPSUFFIX)
+	@$(ECHO)  Install FPC Package.. $(INSTALL_FPCPACKAGE)
+	@$(ECHO)
+	@$(ECHO)  Install base dir..... $(INSTALL_BASEDIR)
+	@$(ECHO)  Install binary dir... $(INSTALL_BINDIR)
+	@$(ECHO)  Install library dir.. $(INSTALL_LIBDIR)
+	@$(ECHO)  Install units dir.... $(INSTALL_UNITDIR)
+	@$(ECHO)  Install source dir... $(INSTALL_SOURCEDIR)
+	@$(ECHO)  Install doc dir...... $(INSTALL_DOCDIR)
+	@$(ECHO)  Install example dir.. $(INSTALL_EXAMPLEDIR)
+	@$(ECHO)  Install data dir..... $(INSTALL_DATADIR)
+	@$(ECHO)
+	@$(ECHO)  Dist destination dir. $(DIST_DESTDIR)
+	@$(ECHO)  Dist zip name........ $(DIST_ZIPNAME)
+	@$(ECHO)
+debug: fpc_debug
+examples: fpc_examples
+smart: fpc_smart
+shared: fpc_shared
+install: fpc_install
+sourceinstall: fpc_sourceinstall
+exampleinstall: fpc_exampleinstall
+distinstall: fpc_distinstall
+zipinstall:
+zipsourceinstall:
+zipexampleinstall:
+zipdistinstall:
+distclean: fpc_distclean
+cleanall: fpc_cleanall
+info: fpc_info
+.PHONY: debug examples smart shared install sourceinstall exampleinstall distinstall zipinstall zipsourceinstall zipexampleinstall zipdistinstall distclean cleanall info
+ifneq ($(wildcard fpcmake.loc),)
+include fpcmake.loc
+endif
+.PHONY: text gfx both
+all: both
+clean : execlean fpc_cleanall
+execlean :
+	$(DELTREE) text
+	$(DELTREE) graph
+text:
+	$(MKDIR) text
+	$(MAKE) fpc_all COMPILER_TARGETDIR=text
+graph:
+	$(MKDIR) graph
+	$(MAKE) fpc_all COMPILER_TARGETDIR=graph GRAPHICS=1
+both:
+	$(MAKE) text
+	$(MAKE) graph

+ 40 - 0
demo/graph/Makefile.fpc

@@ -0,0 +1,40 @@
+#
+#   Makefile.fpc for FPC graph demos (part of FPC demo package)
+#
+
+[target]
+units=gameunit
+programs=fpctris mandel samegame quad maze gravwars
+
+[default]
+fpcdir=../..
+
+[prerules]
+ifdef GRAPHICS
+override FPCOPT+=-dUSEGRAPHICS
+endif
+
+[rules]
+.PHONY: text gfx both
+
+all: both
+
+clean : execlean fpc_cleanall
+
+execlean :
+        $(DELTREE) text
+        $(DELTREE) graph
+
+# below projects will call ourselves recursive
+
+text:
+        $(MKDIR) text
+        $(MAKE) fpc_all COMPILER_TARGETDIR=text
+
+graph:
+        $(MKDIR) graph
+        $(MAKE) fpc_all COMPILER_TARGETDIR=graph GRAPHICS=1
+
+both:
+        $(MAKE) text
+        $(MAKE) graph

+ 279 - 0
demo/graph/fpcgames.txt

@@ -0,0 +1,279 @@
+The FPC ModeX docs...
+
+--------------------------------------------------------------------
+NOTICE:
+
+The ported games (see below) were found on a site that claims to only have
+PD stuff, and the webmaster said that everything he published was sent to
+him with that purpose. We tried finding the persons mentioned in the mail
+over internet, but that failed.
+
+If there is somebody that claims authorship of these programs, please mail
[email protected], and the sources will be removed from our websites.
+
+SameGame can also use the API for mousecontrol. This because the RTL mouseunit
+MsMouse only exists under Go32V2. The API mouse routines work with Linux, but
+have (right now) a problem with GPM version 1.17. Use a different version if
+you can 1.15 works according to the developpers.
+
+The source code of FPCTRIS and SAMEGAME) are written by Marco van de Voort
+and are donated to the FPC project. The FPC project distributes all sources
+under a modified GNU license (much like the so called LGPL) see copying.fpc.
+--------------------------------------------------------------------
+REQUEST:
+
+As a developper team, we don't want spend 90% of our time in creating demoes.
+If you have something nice, which explains not yet demonstrated features or
+technicques, mail contact us via [email protected], or add it to the
+contrib page.
+The readers are also encouraged to explore FPC's excellent documentation
+with many examples!!!!!
+
+------------------------------------------------------------------------------
+What are the FPC games?
+
+The FPC-games are a series of simple, small games written or ported by
+Marco van de Voort ([email protected]) as demos for the
+Free Pascal compiler (FPC) and its Run Time Libraries (RTL).
+The "ported" games were first used to test the compability of the GRAPH
+unit. Since we had them, and they were very likely PD or GPL, we decided
+to use them when we couldn't contact the authors
+
+Currently the games are
+
+  (Games written by Marco van de Voort)
+- FPCTris (v0.08)                       Tetr'ish game.
+- Samegame (v0.03)                      As found on e.g. GNOME.
+
+ Other games:
+- Gravwars (Sohrab Ismail-Beigi?)       Simple angle and shoot game
+                                        (like TANK distributed with QBasic)
+- Maze (Randy Ding)                     Maze generator and "game"
+- Quad (Justin and Whitney Pierce)      Memory game but with 4 cards each.
+                                        move.
+
+All "other games" games are simpler than my ones, though Quad has overall
+the most sophisticated graphics, and Maze a reasonably complicated algoritm
+(compared to the other ones)
+
+Most of these games use Gameunit.pp which contains some very simple
+generic routines:
+- textual and graphics mode safe input dialogue (replacement for readkey)
+- highscores (show, helper routines for entering scores etc)
+- wrappers for mouse via msmouse or API on other targets
+- Some routines needed for BP compability. (Go32 and cursor routines in Crt)
+
+To compile the games on non dos targets you have to change DEFINE the
+MouseAPI conditional in gameunit.pp (automatical for Linux).
+
+To get the graphics versions of fpctris and samegame, compile using
+-dUsegraphics, the makefile should automatically build both.
+
+Future
+--------
+
+- Some cards games (BlackJack, Poker, and two Dutch games called "Rikken" and
+   "Toepen") are in preparation
+- A server for Linux, so that Linux clients can connect to it for multiplayer
+   services. One server for all games, otherwise small games like this clog up
+   the number of free ports ;-)
+   This is also important because most of the cardsgames (except BlackJack)
+   can't be played against the computer, the AI is to difficult. (Poker is maybe
+   also possible)
+- More games
+- A fortune clone (far more sophisticated than everything here) to complete
+  the BSD games analogy
+
+---------
+FPCTRIS
+
+Fpctris is a tetris class game, originally designed
+
+- to be distributed with FPC as Crt demo,
+- Keeping possible integration in the IDE in mind (would add 15k or so)
+- Svgalib version etc etc. Anyway, the engine is quite platform independant,
+   and can be ported to different platforms (also TUI,GUI) if needed.
+   (this has now be done. Graph seems fast enough)
+
+The current versions are still under development, but already playable even
+under telnet.
+
+TODO list:
+
+- (difficult, also interesting for Crt and IDE), get more terminals supported
+  under Linux. Specially I don't want to issue the escape sequence that rapes
+  your console to an IBM compat charset. Linux users don't like that.
+  (temporarily solved by doing this only on user request)
+
+- (Linux) Sockets multiplayer client system :-). Have actually started on it,
+   but are getting nowhere. The server will be separate and support more than
+   one game. So you get one port for several games.
+
+- Setup screen ((create) alternate blocks etc)
+
+- Commandline options/config file. (.rctetris per user :-))
+
+KNOWN BUGS:
+
+ - Upperrow not used with some chars. (Requires shifting up). Possibly related
+   that very rarely "game over" appears when there's still one or two rows to
+   go. (Since the 5x5 version some of this has been removed. If you get a
+   L-shaped character and immediately rotate, the upper line is used)
+ - Biggest problem at the moment is the delay procedure and its init on machines
+    under heavy load. Can't change that though. Only under heavy load, so a
+    less big problem on heavy machines.
+ - Selection of colors don't take screen attribs into account. So figures can
+    seem to disappear on weird TTY's or 4Dos people using strange ANSI prompts.
+
+History:
+
+v0.00    First version with working gameplay, created during the Brussels
+          meeting. published on tflily.
+v0.01    Some work done, first version on my page. Most improvements done in
+         Brussels, too many to name here.
+v0.02  - Got rid of binary encoding, and calculating shapes etc when a new
+         figure is created. All is done on startup now. Adding characters
+         is simpler now.
+      - A lot of parameters are variables instead of constants.
+      - Experienced tetrissers press "e" once.
+      - Colors! Linux has the color default off (press "C")
+v0.03  (Only used at Stack, not on web)
+      - Keep on pushing arrow down no longer freezes FPCTris.
+      - Basic level system implemented.
+      - High ascii background in color mode.
+v0.04  (Only used at Stack, not on web)
+      - The push-down arrow fix removed the possibility to move the character
+         after arrow-down, which I liked much. Fixed. # of possible moves after
+         arrow-down also adjustable.
+      - Tried compiling with W32 compiler. RTE 216 (which is gpf I believe)
+         Is Crt unit. Hello World "Use crt" also gpf's.
+      - Removed the first, forgotten bugfix for the hickup problem. Now the
+         "feel" of the game is ok. When you push down, it goes down, but you
+         have the change to do one more move.
+v0.05  (Never used anywere, backup version before movement to 5x5 figures)
+      - More Score info
+      - Help possiblity
+      - Highscores. (also saved to file, and searched in the path)
+      - Entering highscores uses inputstr. Size boosts to 1200 lines. Yuck.
+      - Most functionality now implemented.
+v0.06 (To Peter)
+      - 5x5 figures including "The Cross". Worked almost rightaway, but figures
+         rotate a bit weird.
+      - Better rotation 5x5 system. Only smallest square around figure is
+         rotated.
+      - Better scores. Incl quadratic (progressive is a better word) scores for
+         multiple lines. Now it does matter if you remove 2 x 1 line or 2
+         lines at once.
+      - Some small other fixes.
+      - 'q' is also exit.
+
+v0.07  - Highscore table routines moved to gameunit. Gameunit.pp now required.
+
+v0.08 - FileMode in GameUnit fixed.
+      - Small error that never popped up fixed. Pierre found it by compiling with
+         checks on.
+      - Graph mode implemented. Hopefully it also works under Linux (read the
+        Graph unit is platform independant enough) Compile with -dUseGraphics.
+
+----------
+SameGame.
+
+Principle copied from KDE/GNOME.
+
+The principle: The playfield is a grid consisting out of 3 colors.
+You can mark a certain spot on the playfield, and all adjacent grid-cubes
+(horizontally or vertically) will also get marked by the computer.
+When you press the left button, and two or more cubes are marked, the marked
+cubes will disappear, and the playfield will colapse to the bottom left.
+This can be repeated until there are no more agregates. If the field is empty
+then, you receive a bonus.
+
+The trick is that the score for each disappearing aggregate of cubes is more
+than linear (0.25* quadratic right now) dependant on the number of cubes it
+contains.
+
+This means that removing 5 times an aggregate of 2 cubes will result in a far
+smaller score than one aggregate of 10 cubes. ( 5*2^2 < 10^2)
+
+TODO:
+
+[none]
+
+BUGS:
+
+- Maybe better algoritm for initial filling of playfield.
+- Runtime sizable playfield.
+
+HISTORY:
+
+v0.01 :
+       - Initial version.
+       - Slightly improved initial algoritm.
+
+v0.02  - Using gameunit. GPM support via API, but whole thing GPF's under Linux,
+          but works under Go32V2.
+       - Highscores,helpscreen, all small things that come with a decent finishing
+         of the concept
+v0.03  - Fix to game unit that upset configuration files under 0.99.13
+       - q,x and Escape now exit.
+       - Weirdly enough, mouse cursor disappears when moving over a black spot.
+          Playing with delays was unsuccesfull.
+       - Graphical support. Compile with -dUseGraphics
+
+----------
+Gravwars (author:Sohrab Ismail-Beigi)
+
+Specify angle and speed, and try to hit the other spaceship. Some planetoids
+exist that can bend the curve of the bullet/ray.
+The game uses is designed for TP4.0 and uses Turtle'ish drawing. So we
+use it as a test for TP4.0 Graph compability.
+
+TODO:
+- Use InputStr for input.
+
+BUGS/FLAWS : None, except that it is very basic (and not worth extending)
+
+HISTORY:
+
+v0.01 :
+       - Initial FPC port.
+----------
+MAZE    (Author Randy Ding)
+
+Nothing special, but from all FPC-games the one with a real algoritm.
+(some form of shortest path through a maze I guess) The others are much
+simpler as far as algoritms are concerned.
+
+The programs asks some simple parameters, and creates a more or less complex
+MAZE. The task for the player is to go from one side to the other:
+
+Use I,J,K,M or arrow keys to walk through the maze
+Hit X when you give up!
+
+TODO:
+- Use InputStr for input.
+- Help on screen if there is enough room?
+- Big mazes/very high resolutions?
+   (bigger than the current max 200x200 is unreadable on 1024/768)
+
+HISTORY
+ v0.01 :
+       - Initial FPC port.
+
+------------
+QUAD
+
+My favorite of the other games, and by far the most work to port/clean up.
+
+The program deals some cards blind. It flips over maximal 4 cards, and if
+the 4 turned are the same, it removes them. (the game exists as a card game
+called MEMORY too, but only with two cards at the same time)
+You have to remove all the cards to win, and the highscore record
+the time. QUAD loads some pictures from quaddata.dat.
+
+TODO:
+- Use graphical versions of highscore.
+
+HISTORY
+ v0.01 :
+       - Initial FPC port.

+ 838 - 0
demo/graph/fpctris.pp

@@ -0,0 +1,838 @@
+{
+    $Id$
+
+    This program is both available in XTDFPC as in the FPC demoes.
+    Copyright (C) 1999 by Marco van de Voort
+
+    FPCTris implements a simple Crt driven Tetrisish game to demonstrate the
+    Crt unit. (KeyPressed, ReadKey, GotoXY, Delay,TextColor,TextBackground)
+    Quality games cost money, so that's why this one is free.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+
+PROGRAM FPCTris;
+{ Trying to make a tetris from zero as a demo for FPC.
+  Problems: - Colorsupport is a hack which handicaps creating a better
+               update mechanism. (is done now)
+            - Graph version input command has no cursor.
+            - Graph or text isn't decided runtime, but compilertime.
+            - Linux status graph version unknown at this moment.
+            - Graphic and textmode speed of the game is not the same.
+               The delay is fixed, and the time required to update is
+               not constant due to optimisations.
+
+  Coordinate system:
+
+   0  ->   TheWidth-1            A figure is coded in a LONGINT like this:
+   ---------
+0 |   *     |                    ..*.            00100000    MSB
+| |   **    |                    ..*.            00100000
+V |   *     |                    .**.            01100000
+  |         |                    ....            00000000    LSB
+  |+   ++ ++|
+  |++ ++++++|                  so  00100000001000000110000000000000b
+  |+++++++++|
+   ---------
+TheHeight-1
+
+}
+
+Uses Crt,Dos,
+{$IFDEF UseGraphics}
+ Graph,
+{$ENDIF}
+ GameUnit;
+
+{$DEFINE DoubleCache}
+
+CONST TheWidth  = 11; {Watch out, also correct RowMask!}
+      TheHeight = 20;
+{$IFNDEF UseGraphics}
+      PosXField = 10; { Upper X,Y coordinates of playfield}
+      PosYField = 3;
+{$ENDIF}
+      MaxFigures= 16; {Maximum # figures place is reserved for.}
+      NrLevels  = 12; {Number of levels currenty defined}
+{      FieldSpace= 177;}
+
+{$IFDEF UseGraphics}
+      DisplGrX=110;
+      DisplGrY=90;
+      DisplGrScale=16;
+      HelpY=130;
+{$ENDIF}
+
+      {$IFDEF UseGraphics}
+       BaseX     =300;   {Coordinates of highscores}
+       BaseY     =HelpY+20+8*LineDistY;  {y coordinate relative to other options}
+      {$ELSE}
+       BaseX     =40;
+       BaseY     =9;
+      {$ENDIF}
+
+TYPE TetrisFieldType = ARRAY [0..25] OF LONGINT;
+     LevelInfoType   = ARRAY [0..NrLevels-1] OF LONGINT;
+     FigureType      = LONGINT;    { actually array[0..4][0..4] of bit rounded up to a longint}
+{     CHARSET         = SET OF CHAR;}
+
+{The figures, are converted to binary bitmaps on startup.}
+
+CONST GraphFigures : ARRAY[0..4] OF String[80] =(
+'.*... .*... .*... ..*.. .*... .*... **... **... ..**. .**.. ..*.. *....',
+'.*... .*... .**.. .**.. .*... .**.. **... .*... ..*.. .**.. ..*.. **...',
+'**... .**.. ..*.. .*... .*... .*... ..... .*... ..*.. .**.. **.** .**..',
+'..... ..... ..... ..... .*... ..... ..... .***. ***.. .**.. ..*.. ..**.',
+'..... ..... ..... ..... ..... ..... ..... ..... ..... .**.. ..*.. .....');
+
+{Their relative occurance : }
+
+      FigureChance : ARRAY[0..MaxFigures-1] OF LONGINT =(
+  8,     8,    8,    8,     8,   8,   10,    1,   1,     1,    1,    1,0,0,0,0 );
+
+{Scores per figure. Not necessarily used. Just for future use}
+
+      FigureScore  : ARRAY[0..MaxFigures-1] OF LONGINT =(
+  2,     2,    4,    4,     1,   2,    2,   10,  10,    10,   20,   10,0,0,0,0 );
+
+{Diverse AND/OR masks to manipulate graphics}
+
+{general table to mask out a bit 31=msb 0=lsb}
+ AndTable : ARRAY[0..31] OF LONGINT=($80000000,$40000000,$20000000,$10000000,
+    $8000000,$4000000,$2000000,$1000000,$800000,$400000,$200000,$100000,
+    $80000,$40000,$20000,$10000,$8000,$4000,$2000,$1000,$800,$400,$200,$100,
+    $80,$40,$20,$10,8,4,2,1);
+
+{Mask to isolate a row of a (FigureType)}
+
+ MagicMasks : ARRAY[0..4] OF LONGINT = ($F8000000,$07C00000,$003E0000,$0001F000,$00000F80);
+
+{Mask to check if a line is full; a bit for every column aligned to left.}
+ RowMask    = $FFE00000;
+
+{Masks to calculate if the left or rightside is partially empty, write them
+in binary, and put 5 bits on a row. }
+
+ LeftMask : ARRAY[0..4] OF LONGINT = ($84210800,$C6318C00,$E739CE00,$F7BDEF00,$FFFFFFE0);
+ RightMask: ARRAY[0..4] OF LONGINT = ($08421080,$18C63180,$39CE7380,$7BDEF780,$FFFFFF80);
+
+{Allowed characters entering highscores}
+
+{This constant/parameter is used to detect a certain bug. The bug was fixed, but
+I use the constant to remind where the bug was, and what is related to eachother.}
+
+   Tune=-1;
+
+{First array is a table to find the level for a given number of dissappeared lines
+ the second and third are the delaytime and iterationlevel per level.  }
+
+  LevelBorders  : LevelInfoType = ( 10, 20, 30, 45, 60, 80,100,130,160,200,240,280);
+  DelayLevel    : LevelInfoType = (100, 90, 80, 70, 60, 60, 50, 40, 40, 20, 20,10);
+  IterationLevel: LevelInfoType = (  5,  5,  5,  5,  5,  4,  4,  4,  3,  3,  2, 2);
+
+{Some frequently used chars in high-ascii and low-ascii. UseColor selects between
+them}
+  ColorString = #196#179#192#217#219;
+  DumbTermStr = '-|..*';
+
+{ A multiplication factor to reward killing more then one line with one figure}
+
+  ProgressiveFactor :  ARRAY[1..5] OF LONGINT = (10,12,16,22,30);
+
+VAR
+    TopX,TopY   : LONGINT;                      {Coordinates figure relative
+                                                  to left top of playfield}
+    FigureNr    : LONGINT;                      {Nr in Figure cache, second
+                                                  index in Figures}
+    {$IFDEF DoubleCache}
+    BackField,                                  {Copy of the screen for faster matching}
+    {$ENDIF}
+    MainField   : TetrisFieldType;              {The screen grid}
+    ColorField  : ARRAY[0..TheHeight-1,0..TheWidth-1] OF LONGINT; {The color info}
+    DelayTime   : LONGINT;                      {Delay time, can be used for
+                                                  implementing levels}
+    IterationPerDelay : LONGINT;                {Iterations of mainloop (incl delay)
+                                                 before the piece falls down a row}
+    TotalChance : LONGINT;                      {Sum of FigureChange array}
+    Lines       : LONGINT;                      {Completed lines}
+    NrFigures   : LONGINT;                      {# Figures currently used}
+    RightSizeArray,                             {Nunber of empty columns to the left }
+    LeftSizeArray,                              {or right of the figure/piece}
+    Figures     : ARRAY[0..MaxFigures-1,0..3] OF LONGINT; {All bitmap info of figures}
+
+    NrFiguresLoaded : LONGINT;                  {Total figures available in GraphFigures}
+    CurrentCol  : LONGINT;                      {Color of current falling piece}
+    UseColor    : BOOLEAN;                      {Color/Mono mode}
+    Level       : LONGINT;                      {The current level number}
+{$IFNDEF UseGraphics}
+    Style       : String;                       {Contains all chars to create the field}
+{$ENDIF}
+    nonupdatemode  : BOOLEAN;                   {Helpmode/highscore screen or game mode}
+{$IFNDEF UseGraphics}
+    HelpMode    : BOOLEAN;
+{$ENDIF}
+    NextFigure  : LONGINT;                      {Next figure to fall}
+    Score       : LONGINT;                      {The score}
+
+
+FUNCTION RRotate(Figure:FigureType;ColumnsToDo:LONGINT):FigureType;
+{Rotate a figure to the right (=clockwise).
+
+This new (v0.06) routine performs a ColumnsTodo x ColumnsToDo rotation,
+instead of always a 4x4 (v0.04) or 5x5 (v0.05) rotation.
+
+This avoids weird, jumpy behaviour when rotating small pieces.}
+
+VAR I,J, NewFig:LONGINT;
+
+BEGIN
+ NewFig:=0;
+ FOR I:=0 TO ColumnsToDo-1 DO
+  FOR J:=0 TO ColumnsToDo-1 DO
+   IF Figure AND AndTable[I*5+J]<>0 THEN
+    NewFig:=NewFig OR AndTable[(ColumnsToDo-1-I)+5*(J)]; {}
+ RRotate:=NewFig;
+END;
+
+{ LeftSize and RightSize count the number of empty lines to the left and
+right of the character. On the below character LeftSize will return 2 and
+RightSize will return 1.
+
+        ..*.
+        ..*.
+        ..*.
+        ..*.
+}
+FUNCTION RightSize(Fig:FigureType):LONGINT;
+
+VAR I : LONGINT;
+
+BEGIN
+ I:=0;
+ WHILE ((Fig AND RightMask[I])=0) AND (I<5) DO
+  INC(I);
+  IF I>4 THEN
+   HALT;
+ Rightsize:=I;
+END;
+
+FUNCTION Leftsize(Fig:FigureType):LONGINT;
+
+VAR I : LONGINT;
+
+BEGIN
+ I:=0;
+ WHILE ((Fig AND LeftMask[I])=0)  AND (I<5) DO
+  INC(I);
+  IF I>4 THEN
+   HALT;
+ Leftsize:=I;
+END;
+
+FUNCTION FigSym(Figure:LONGINT;RightSizeFig:LONGINT):LONGINT;
+ {Try to find the "symmetry" of a figure, the smallest square (1x1,2x2,3x3 etc)
+ in which the figure fits. This requires all figures designed to be aligned to
+ topleft.}
+
+VAR ColumnsToDo : LONGINT;
+
+BEGIN
+ {Determine which bottom rows aren't used}
+
+ ColumnsToDo:=5;
+ WHILE ((Figure AND MagicMasks[ColumnsToDo-1])=0) AND (ColumnsToDo>1) DO
+  DEC(ColumnsToDo);
+
+ {Compare with columns used, already calculated, and take the biggest}
+ IF ColumnsToDo<(5-RightSizeFig) THEN
+  ColumnsToDo:=5-RightSizeFig;
+ FigSym:=ColumnsToDo;
+END;
+
+
+PROCEDURE CreateFiguresArray;
+{Reads figures from ASCII representation into binary form, and creates the
+ rotated representations, and the number of empty columns to the right and
+ left per figure. }
+
+VAR I,J,K,L,Symmetry : LONGINT;
+
+BEGIN
+ NrFigures:=0; K:=1;
+ WHILE K<Length(GraphFigures[0]) DO
+  BEGIN
+   IF GraphFigures[0][K]=' ' THEN
+    INC(K);
+   L:=0;
+   FOR I:=0 TO 4 DO   {Rows}
+    FOR J:=0 TO 4 DO {Columns}
+     IF GraphFigures[I][K+J]='*' THEN
+      L:=L OR AndTable[I*5+J];
+    Figures[NrFigures][0]:=L;
+    INC(NrFigures);
+    INC(K,5);
+  END;
+ NrFiguresLoaded:=NrFigures;
+ FOR I:= 0 TO NrFigures-1 DO
+  BEGIN
+   RightSizeArray[I][0]:=RightSize(Figures[I][0]);
+   LeftSizeArray[I][0]:=LeftSize(Figures[I][0]);
+   Symmetry:=FigSym(Figures[I][0],RightSizeArray[I][0]);
+   FOR J:=0 TO 2 DO                              {Create the other 3 by rotating}
+    BEGIN
+     Figures[I][J+1]:=RRotate(Figures[I][J],Symmetry);
+     RightSizeArray[I][J+1]:=RightSize(Figures[I][J+1]);
+     LeftSizeArray[I][J+1]:=LeftSize(Figures[I][J+1]);
+    END;
+   END;
+{Clear main grid}
+ FillChar(MainField,SIZEOF(TetrisFieldType),0);
+END;
+
+PROCEDURE CalculateTotalChance;
+{Called after a change in the the number of figures, normally 7 (standard)
+or NrFiguresLoaded (10 right now) to recalculate the total of the chance table}
+
+VAR Temp:LONGINT;
+
+BEGIN
+ TotalChance:=0;
+ FOR Temp:=0 TO NrFigures-1 DO INC(TotalChance,FigureChance[Temp]);
+END;
+
+FUNCTION MatchPosition(Fig:FigureType;X,Y:LONGINT): BOOLEAN;
+{Most important routine. Tries to position the figure on the position
+IF it returns FALSE then the piece overlaps something on the background,
+or the lower limit of the playfield
+}
+
+VAR I,J,K  : LONGINT;
+    Match: BOOLEAN;
+
+BEGIN
+ Match:=TRUE;
+ FOR I:=0 TO 4 DO
+  BEGIN
+   K:=Fig;
+   K:=K AND MagicMasks[I];
+   IF K<>0 THEN
+    BEGIN
+     J:=5*(I)-X+Tune;
+     IF J>0 THEN
+      K:=K SHL J
+     ELSE
+      IF J<0 THEN
+       K:=K SHR -J;
+     IF (MainField[Y+I] AND K)<>0 THEN
+      Match:=FALSE;
+   END;
+  END;
+ I:=4;
+ IF (Fig AND MagicMasks[4])=0 THEN
+  DEC(I);
+ IF (Fig AND MagicMasks[3])=0 THEN
+  DEC(I);
+ IF (Fig AND MagicMasks[2])=0 THEN
+  DEC(I);
+ IF (Y+I)>=TheHeight THEN
+  Match:=FALSE;
+ MatchPosition:=Match;
+END;
+
+PROCEDURE FixFigureInField(Fig:FigureType;X,Y:LONGINT;Clear:BOOLEAN);
+{Blends the figure into the background, or erases the figure from the
+background}
+
+VAR I,J,K  : LONGINT;
+
+BEGIN
+ FOR I:=0 TO 4 DO
+  BEGIN
+   K:=Fig;
+    K:=K AND MagicMasks[I];
+   IF K<>0 THEN
+    BEGIN
+     J:=5*I-X+Tune;
+     IF J>0 THEN
+      K:=K SHL J
+     ELSE
+      IF J<0 THEN
+       K:=K SHR (-J);
+     IF Clear THEN
+      BEGIN
+       K:=K XOR -1;
+       MainField[Y+I]:= MainField[Y+I] AND K;
+      END
+     ELSE
+      MainField[Y+I]:= MainField[Y+I] OR K;
+    END;
+ END;
+END;
+
+PROCEDURE FixColField(ThisFig:LONGINT);
+{Puts color info of a figure into the colorgrid, simplified
+FixFigureInField on byte instead of bit manipulation basis.}
+
+VAR I,J,K  : LONGINT;
+
+BEGIN
+ FOR I:=0 TO 4 DO
+  BEGIN
+   K:=Figures[ThisFig][FigureNr];
+   IF (I+TopY)<=TheHeight THEN
+    FOR J:=0 TO 4 DO
+     BEGIN
+      IF (K AND AndTable[J+5*I])<>0 THEN
+       ColorField[TopY+I,TopX-Tune+J]:=CurrentCol
+     END;
+  END;
+END;
+
+PROCEDURE RedrawScreen;
+{Frustrates the caching system so that the entire screen is redrawn}
+
+VAR I : LONGINT;
+
+BEGIN
+ FOR I:=0 TO TheHeight-1 DO
+  BackField[I]:=MainField[I] XOR -1;    {backup copy is opposite of MainField}
+END;
+
+FUNCTION GetNextFigure:LONGINT;
+
+VAR IndTotal,Temp,TheFigure : LONGINT;
+
+BEGIN
+Temp:=RANDOM(TotalChance);
+ IndTotal:=0;
+ TheFigure:=0;
+ WHILE Temp>=IndTotal DO
+  BEGIN
+   INC(IndTotal,FigureChance[TheFigure]);
+   INC(TheFigure);
+  END;
+ dec(thefigure);
+ GetNextFigure:=TheFigure;
+END;
+
+{$IFDEF UseGraphics}
+ {$I ftrisgr.inc}
+{$ELSE}
+ {$I ftristxt.inc}
+{$ENDIF}
+
+
+FUNCTION InitAFigure(VAR TheFigure:LONGINT) : BOOLEAN;
+{A new figure appears in the top of the screen. If return value=FALSE then
+the piece couldn't be created (when it is overlapping with the background.
+That's the game-over condition)}
+
+VAR Temp : LONGINT;
+
+BEGIN
+ TopX:=(TheWidth-4) DIV 2;             { Middle of Screen}
+ TopY:=0;
+ FigureNr:=1;
+ IF TheFigure<>-1 THEN
+  INC(Score,FigureScore[TheFigure]);
+ IF NOT NonUpdateMode THEN
+  FixScores;
+ Temp:=GetNextFigure;                   {Determine next char (after the one this
+                                      initafigure created has got down)}
+ TheFigure:=NextFigure;                 {Previous NextFigure becomes active now.}
+ NextFigure:=Temp;
+ InitAFigure:=MatchPosition(Figures[TheFigure][0],TopX,TopY);
+ ShowNextFigure(NextFigure);
+ CurrentCol:=RANDOM(14)+1;
+END;
+
+PROCEDURE FixLevel(Lines:LONGINT);
+
+
+BEGIN
+ Level:=0;
+ WHILE (Lines>LevelBorders[Level]) AND (Level<HIGH(LevelBorders)) DO
+  INC(Level);
+ DelayTime:=DelayLevel[Level];
+ IterationPerDelay:=IterationLevel[Level];
+END;
+
+PROCEDURE FixMainFieldLines;
+{Deletes full horizontal lines from the playfield will also get some
+score-keeping code in the future.}
+
+VAR I,LocalLines : LONGINT;
+
+BEGIN
+ I:=TheHeight-1;
+ LocalLines:=0;
+ WHILE I>=0 DO
+  BEGIN
+   IF (MainField[I] XOR RowMask)=0 THEN
+    BEGIN
+     Move(MainField[0],MainField[1],I*4);
+     Move(ColorField[0,0],ColorField[1,0],4*I*TheWidth);
+     MainField[0]:=0;
+     FillChar(ColorField[0,0],0,TheWidth);
+     INC(LocalLines);
+    END
+   ELSE
+    DEC(I);
+  END;
+
+ INC(Lines,LocalLines);
+
+ I:=Level;
+ FixLevel(Lines);
+ IF LocalLines<>0 THEN
+  BEGIN
+   INC(Score,ProgressiveFactor[LocalLines]*LocalLines);
+   ShowLines;
+  END;
+ {$IFDEF DoubleCache}
+  IF UseColor THEN
+   RedrawScreen;
+ {$ENDIF}
+END;
+
+PROCEDURE DoFPCTris;
+{The main routine. Initialisation, keyboard loop}
+
+VAR EndGame   : BOOLEAN;
+    FixHickup : LONGINT;
+    Counter   : LONGINT;
+    Temp,Key  : LONGINT;
+    TheFigure : LONGINT;                      {Current first index in Figures}
+
+PROCEDURE TurnFigure;
+{Erases a figure from the grid, turns it if possible, and puts it back on
+again}
+
+BEGIN
+  FixFigureInField(Figures[TheFigure][FigureNr],TopX,TopY,TRUE);
+  IF MatchPosition(Figures[TheFigure][Temp],TopX,TopY) THEN
+   FigureNr:=Temp;
+  FixFigureInField(Figures[TheFigure][FigureNr],TopX,TopY,FALSE);
+END;
+
+PROCEDURE FixHighScores;
+
+VAR I : LONGINT;
+{$IFNDEF UseGraphics}
+    J : LONGINT;
+{$ENDIF}
+    S : String;
+
+BEGIN
+{$IFDEF UseGraphics}
+  Str(Score:5,S);
+  SetFillStyle(SolidFill,0);            {Clear part of playfield}
+  Bar(DisplGrX+DisplGrScale,DisplGrY + ((TheHeight DIV 2)-2)*DisplGrScale,
+      DisplGrX+(TheWidth-1)*(DisplGrScale), DisplGrY + DisplGrScale*((TheHeight DIV 2)+5));
+  SetTextStyle(0,Horizdir,2);
+  OuttextXY(DisplGrX+DisplGrScale,DisplGrY+ DisplGrScale*((TheHeight DIV 2)-1),'GAME OVER');
+  SetTextStyle(0,Horizdir,1);
+  OutTextXY(DisplGrX+DisplGrScale,DisplGrY+ DisplGrScale*((TheHeight DIV 2)+3),'Score= '+S);
+{$ELSE}
+ FOR J:=9 TO 22 DO
+    BEGIN
+     GotoXY(40,J);
+     Write(' ':38);
+    END;
+ IF UseColor THEN
+  TextColor(White);
+ GotoXY(40,23);
+ Writeln('Game Over, score = ',Score);
+{$ENDIF}
+ I:=SlipInScore(Score);
+ IF I<>0 THEN
+  BEGIN
+   NonUpdateMode:=TRUE;
+{$IFNDEF UseGraphics}
+   HelpMode:=FALSE;
+{$ENDIF}
+   ShowHighScore;
+   {$IFDEF UseGraphics}
+    OutTextXY(450,HelpY+20+(17-I+1)*LineDistY,S);
+    GrInputStr(S,300,HelpY+20+(17-I+1)*LineDistY,16,12,10,FALSE,AlfaBeta);
+   {$ELSE}
+    InputStr(S,40,21-I,10,FALSE,AlfaBeta);
+   {$ENDIF}
+   HighScore[I-1].Name:=S;
+  END;
+ ShowHighScore;
+END;
+
+{$IFDEF UseGraphics}
+VAR
+    gd,gm : INTEGER;
+    Pal   : PaletteType;
+{$ENDIF}
+
+BEGIN
+{$IFDEF UseGraphics}
+  gm:=vgahi;
+  gd:=vga;
+  InitGraph(gd,gm,'');
+  if GraphResult <> grOk then
+    begin
+      Writeln('Graph driver ',gd,' graph mode ',gm,' not supported');
+      Halt(1);
+    end;
+  SetFillStyle(SolidFill,1);
+  GetDefaultPalette(Pal);
+  SetAllPalette(Pal);
+{$ENDIF}
+
+ {Here should be some terminal-detection for Linux}
+ nonupdatemode:=FALSE;
+{$IFNDEF UseGraphics}
+ HelpMode :=TRUE;
+{$ENDIF}
+ {$IFDEF Linux}
+  UseColor:=FALSE;
+ {$ELSE}
+  UseColor:=TRUE;
+ {$ENDIF}
+ ClrScr;
+ CursorOff;
+ RANDOMIZE;
+ HighX:=BaseX;
+ HighY:=BaseY;
+ CreateFiguresArray;                  { Load and precalculate a lot of stuff}
+{$IFNDEF UseGraphics}
+ IF UseColor THEN
+  Style:= ColorString
+ ELSE
+  Style:=DumbTermStr;
+{$ENDIF}
+
+ NrFigures:=7;                        {Default standard tetris mode, only use
+                                        the first 7 standard figures}
+ CalculateTotalChance;                {Calculated the total of all weightfactors}
+ EndGame:=FALSE;                      {When TRUE, end of game has been detected}
+ FixHickup:=0;                        {Used to avoid unnecessary pauses with the "down key"}
+ CreateFrame;                         {Draws all background garbadge}
+
+ TheFigure:=-1;
+ NextFigure:=GetNextFigure;              {Two figures have to be inited. The first
+                                        figure starts dropping, and that is this
+                                        one}
+ InitAFigure(TheFigure);              {The second figure is the figure to be
+                                       displayed as NEXT. That's this char :-)}
+ DisplMainField;                  {Display/update the grid}
+ Counter:=0;                          {counts up to IterationPerDelay}
+ DelayTime:=200;                      {Time of delay}
+ IterationPerDelay:=4;                {= # Delays per shift down of figure}
+ Lines:=0;                            {Lines that have disappeared}
+ Score:=0;
+ ShowLines;
+ REPEAT
+  IF KeyPressed THEN                  {The function name says it all}
+   BEGIN
+    Key:=ORD(READKEY);
+    IF Key=0 THEN                     {Function key?}
+     Key:=ORD(READKEY) SHL 8;
+    CASE Key OF                       {Check for all keys}
+     ArrU : BEGIN
+             Temp:=(FigureNr+3) AND 3;
+             IF ((TopX+LeftSizeArray[TheFigure][FigureNr])<0) THEN
+              BEGIN
+              IF  (LeftSizeArray[TheFigure][FigureNr]<=LeftSizeArray[TheFigure][Temp]) THEN
+               TurnFigure;
+              END
+             ELSE
+             IF (TopX+7-RightSizeArray[TheFigure][FigureNr])>TheWidth THEN
+              BEGIN
+              IF  (RightSizeArray[TheFigure][FigureNr]<=RightSizeArray[TheFigure][Temp]) THEN
+               TurnFigure;
+              END
+             ELSE
+              TurnFigure;
+           END;
+
+    ArrL  : BEGIN
+             IF (TopX+LeftSizeArray[TheFigure][FigureNr])>=0 THEN
+              BEGIN
+               Temp:=TopX+1-LeftSizeArray[TheFigure][FigureNr];
+               FixFigureInField(Figures[TheFigure][FigureNr],TopX,TopY,TRUE);
+               IF MatchPosition(Figures[TheFigure][FigureNr],TopX-1,TopY) THEN
+                DEC(TopX);
+               FixFigureInField(Figures[TheFigure][FigureNr],TopX,TopY,FALSE);
+              END;
+             END;
+
+    ArrR  : BEGIN
+             IF (TopX+7-RightSizeArray[TheFigure][FigureNr])<=TheWidth THEN
+              BEGIN
+               FixFigureInField(Figures[TheFigure][FigureNr],TopX,TopY,TRUE);
+               IF MatchPosition(Figures[TheFigure][FigureNr],TopX+1,TopY) THEN
+                INC(TopX);
+               FixFigureInField(Figures[TheFigure][FigureNr],TopX,TopY,FALSE);
+              END;
+             END;
+
+    ArrD  : BEGIN
+             IF FixHickup=0 THEN
+              BEGIN
+             FixFigureInField(Figures[TheFigure][FigureNr],TopX,TopY,TRUE);
+             Temp:=TopY;
+             WHILE MatchPosition(Figures[TheFigure][FigureNr],TopX,TopY+1) DO
+              INC(TopY);
+             Temp:=TopY-Temp;
+             INC(Score,Temp DIV 2);
+             FixFigureInField(Figures[TheFigure][FigureNr],TopX,TopY,FALSE);
+             FixHickUp:=4;
+             END;
+            END;
+
+ORD('q'),
+   ESC     : BEGIN
+             SetDefaultColor;
+             GotoXY(1,25);
+             EndGame:=TRUE;
+            END;
+
+{$IFNDEF UseGraphics}
+ORD('C'),
+ ORD('c') : BEGIN
+             UseColor:=NOT UseColor;
+             IF UseColor THEN
+              Style:= ColorString
+             ELSE
+              BEGIN
+               SetDefaultColor;
+               Style:=DumbTermStr;
+              END;
+             CreateFrame;
+             RedrawScreen;
+             DisplMainField;
+            END;
+ ORD('S'),
+  ORD('s') : BEGIN
+              IF NOT nonupdatemode THEN
+               BEGIN
+                NonUpdateMode:=TRUE;
+                helpmode:=NOT helpmode;
+               END
+              ELSE
+                HelpMode:=NOT helpmode;
+               CreateFrame;
+               ShowLines;
+               ShowNextFigure(NextFigure);
+              END;
+{$ENDIF}
+ORD('H'),
+ ORD('h') : BEGIN
+             nonupdatemode:=NOT nonupdatemode;
+             CreateFrame;
+             ShowLines;
+             ShowNextFigure(NextFigure);
+            END;
+ORD('E'),
+ ORD('e'): BEGIN                            {Extra figures on/off}
+            IF NrFigures<>NrFiguresLoaded THEN
+              NrFigures:=NrFiguresLoaded     {Extra figures}
+            ELSE
+              NrFigures:=7;                   {Standard Tetris figures}
+            CalculateTotalChance;             {Recalculate weight-totals}
+            IF UseColor THEN
+             SetDefaultColor;
+            ShowGameMode;
+           END;
+
+ORD('p') : BEGIN                             {"p" : Pause}
+             Key:=ORD(ReadKey);
+            IF Key=0 THEN
+             Key:=ORD(ReadKey);
+           END;
+{$IFNDEF UseGraphics}
+{$IFDEF Linux}
+ ORD('i')  : write(#27+'(K');
+{$ENDIF}
+{$ENDIF}
+        END; {END OF Key CASE}
+      END { OF If KeyPressed}
+
+  ELSE
+   BEGIN
+    {$IFDEF Linux}
+     GotoXY(50,10);      {Get cursor out of the way, CursorOn/Off
+                            doesn't work on telnet-terminals}
+    {$ENDIF}
+    Delay(DelayTime);
+   END;
+
+  INC(Counter);
+  IF (Counter=IterationPerDelay) OR (FixHickup=1) THEN
+   BEGIN
+    IF FixHickup=1 THEN
+      Counter:=IterationPerDelay-1
+    ELSE
+     Counter:=0;
+    FixFigureInField(Figures[TheFigure][FigureNr],TopX,TopY,TRUE);
+    FixHickup:=0;
+    IF MatchPosition(Figures[TheFigure][FigureNr],TopX,TopY+1) THEN
+     BEGIN
+      INC(TopY);
+      FixFigureInField(Figures[TheFigure][FigureNr],TopX,TopY,FALSE);
+     END
+    ELSE
+    BEGIN
+      FixFigureInField(Figures[TheFigure][FigureNr],TopX,TopY,FALSE);
+      FixColField(TheFigure);
+      IF InitAFigure(TheFigure) THEN
+        BEGIN
+         FixMainFieldLines;
+         FixFigureInField(Figures[TheFigure][FigureNr],TopX,TopY,FALSE);
+         DisplMainField;
+         Delay(DelayTime*IterationPerDelay);
+        END
+      ELSE
+       BEGIN
+        FixFigureInField(Figures[TheFigure][FigureNr],TopX,TopY,FALSE);
+        EndGame:=TRUE;
+       END;
+    END;
+   END
+  ELSE
+   IF FixHickup>1 THEN
+    DEC(FixHickup);
+ DisplMainField;
+ UNTIL EndGame;
+ FixHighScores;
+ CursorOn;
+ SetDefaultColor;
+ GotoXY(1,25);
+ {$IFDEF UseGraphics}
+  TextMode(CO80);
+ {$ENDIF}
+END;
+
+CONST FileName='fpctris.scr';
+
+VAR I : LONGINT;
+
+BEGIN
+ FOR I:=0 TO 9 DO
+  HighScore[I].Score:=(I+1)*750;
+ LoadHighScore(FileName);
+ DoFpcTris;
+ SaveHighScore;
+END.
+
+{
+  $Log$
+  Revision 1.1  2001-05-03 21:39:33  peter
+    * moved to own module
+
+  Revision 1.2  2000/07/13 11:33:08  michael
+  + removed logs
+ 
+}

+ 156 - 0
demo/graph/ftrisgr.inc

@@ -0,0 +1,156 @@
+PROCEDURE ShowLines;
+
+VAR S,S2 : String;
+
+BEGIN
+  SetFillStyle(SolidFill,0);
+  Bar(300,460,550,478);
+  Str(Lines:4,S2);
+  S:='Lines : ';
+  S:=S+S2+'   Level: ';
+  Str(Level:4,S2);
+  S:=S+S2;
+  OutTextXY(300,460,S);
+END;
+
+PROCEDURE ShowGameMode;
+
+BEGIN
+   SetFillStyle(SolidFill,0);
+   Bar(20,440,154,458);
+   IF NrFigures<>7 THEN
+    OutTextXY(20,440,'GameMode: Extended')
+   ELSE
+    OutTextXY(20,440,'GameMode: Standard')
+END;
+
+PROCEDURE CreateFrame;
+{Used once to print the "background" of the screen (not the background grid,
+but the text, and the cadre around the playfield)}
+
+BEGIN
+ setbkcolor(black);
+ setviewport(0,0,getmaxx,getmaxy,clipoff);
+ clearviewport;
+ SetTextStyle(0,Horizdir,2);
+ OuttextXY(30,50,'FPCTris v0.08, (C) by Marco v/d Voort.');
+ SetTextStyle(0,Horizdir,1);
+ OutTextXY(300,HelpY-30,'A demo of the FPC Graph unit');
+
+ VLine(DisplGrX-1,DisplGrY,DisplGrY+DisplGrScale*TheHeight);
+ VLine(DisplGrX+TheWidth*DisplGrScale,DisplGrY,DisplGrY+DisplGrScale*TheHeight);
+ HLine(DisplGrX-1,DisplGrX+TheWidth*DisplGrScale,DisplGrY+DisplGrScale*TheHeight);
+
+ {Clean below area}
+ ShowGameMode;
+ OutTextXY(300,HelpY,'Arrow left/right to move, down to drop');
+ OutTextXY(300,HelpY+LineDistY,'arrow-up to rotate the piece');
+ OutTextXY(300,HelpY+2*LineDistY,'"P" to pause');
+ OutTextXY(300,HelpY+3*LineDistY,'"E" Mode (standard or extended)');
+ OutTextXY(300,HelpY+5*LineDistY,'Escape to quit');
+ OutTextXY(300,HelpY+20+6*LineDistY,'The Highscores');
+ ShowHighScore;
+END;
+
+PROCEDURE DisplMainField;
+{Graph mode version. Always caches.}
+
+
+VAR Row,Column,Difference,StartRow,EndRow,
+    L : LONGINT;
+{    LastCol : LONGINT; }
+
+BEGIN
+ FOR Row:=0 TO TheHeight-1 DO
+  BEGIN
+   IF BackField[Row]<>MainField[Row] THEN
+    BEGIN
+     StartRow:=0;
+     EndRow:=TheWidth-1;
+     Difference:=MainField[Row] XOR BackField[Row];     {Calc differences in line}
+     WHILE ((Difference AND AndTable[StartRow])=0) AND
+        (StartRow<(TheWidth-1)) DO
+      INC(StartRow);
+     WHILE ((Difference AND AndTable[EndRow])=0) AND (EndRow>0) DO
+      DEC(EndRow);
+     FOR Column:=StartRow To EndRow DO
+      BEGIN
+       IF (MainField[Row] AND AndTable[Column])<>0 THEN
+       BEGIN
+         L:=ColorField[Row,Column];
+         IF L=0 THEN
+          L:=CurrentCol;
+         IF L<>255 THEN
+          BEGIN
+           L:=L AND 15;
+           SetFillStyle(SolidFill,L);
+           Bar((Column)*DisplGrScale+DisplGrX,DisplGrY+DisplGrScale*Row,(Column+1)*DisplGrScale-1+DisplGrX,DisplGrY+DisplGrScale*(Row)+DisplGrScale-1);
+          END;
+        END
+       ELSE
+        BEGIN
+           SetFillStyle(SolidFill,0);
+           Bar((Column)*DisplGrScale+DisplGrX,DisplGrY+DisplGrScale*Row,(Column+1)*DisplGrScale-1+DisplGrX,DisplGrY+DisplGrScale*(Row)+DisplGrScale-1);
+        END
+      END;
+   END;
+  END;
+  BackField:=MainField;     {Keep a copy of the screen for faster updates
+                              of terminals, for next DisplMainField.}
+END;
+
+PROCEDURE ShowNextFigure(ThisFig:LONGINT);
+
+CONST NextFigX=10;
+      NextFigY=120;
+      NextFigDim=16;
+
+VAR I,J,K  : LONGINT;
+
+BEGIN
+ IF NOT nonupdatemode THEN
+  BEGIN
+   FOR I:=0 TO 4 DO
+    BEGIN
+     K:=Figures[ThisFig][FigureNr] AND MagicMasks[I];
+     IF K=0 THEN
+      BEGIN
+       SetFillStyle(SolidFill,0);
+       Bar(NextFigX,NextFigY+I*NextFigDim,NextFigX+5*NextFigDim-1,NextFigY+(I+1)*NextFigDim);
+      END
+     ELSE
+      BEGIN
+       FOR J:=0 TO 5 DO
+         IF (K And AndTable[J+5*I])=0 THEN
+          BEGIN
+           SetFillStyle(SolidFill,0);
+           Bar(NextFigX+J*NextFigDim,NextFigY+I*NextFigDim,NextFigX++(J+1)*NextFigDim,NextFigY+(I+1)*NextFigDim);
+          END
+         ELSE
+          BEGIN
+           SetFillStyle(SolidFill,1);
+           Bar(NextFigX+J*NextFigDim,NextFigY+I*NextFigDim,NextFigX++(J+1)*NextFigDim,NextFigY+(I+1)*NextFigDim);
+          END;
+       END;
+    END;
+  END;
+END;
+
+PROCEDURE FixScores;
+
+VAR S : String;
+
+BEGIN
+   Str(Score:5,S);
+   SetFillStyle(SolidFill,0);
+   Bar(300,440,450,458);
+   OutTextXY(300,440,'Score :'+S);
+END;
+  $Log$
+  Revision 1.1  2001-05-03 21:39:33  peter
+    * moved to own module
+
+  Revision 1.2  2000/07/13 11:33:08  michael
+  + removed logs
+ 
+}

+ 246 - 0
demo/graph/ftristxt.inc

@@ -0,0 +1,246 @@
+PROCEDURE ShowLines;
+
+BEGIN
+ IF NOT nonupdatemode THEN
+  BEGIN
+   IF UseColor THEN
+    TextColor(Yellow);
+   GotoXY(40,16); Write('Lines: ',Lines:4,'    Level: ',Level);
+  END;
+END;
+
+PROCEDURE ShowGameMode;
+
+BEGIN
+ IF NOT nonupdatemode THEN
+  BEGIN
+   GotoXY(61,13);
+   IF NrFigures<>7 THEN
+    write('Extended')
+   ELSE
+    write('Standard');
+  END;
+END;
+
+
+PROCEDURE CreateFrame;
+{Used once to print the "background" of the screen (not the background grid,
+but the text, and the cadre around the playfield}
+
+VAR I : LONGINT;
+
+BEGIN
+ SetDefaultColor;
+ GotoXY(40,4);
+ Write('FPCTris v0.08, (C) by Marco van de Voort');
+ GotoXY(40,6);
+ Write('A demo of the FPC Crt unit, and');
+ GotoXY(40,7);
+ Write(' its portability');
+ FOR I:=9 TO 24 DO
+  BEGIN
+   GotoXY(40,I);
+   Write(' ':38);
+  END;
+ ShowGameMode;
+ IF nonupdatemode THEN
+  BEGIN
+   IF HelpMode THEN
+    BEGIN
+   GotoXY(40,9);
+   Write('Arrow left/right to move, down to drop');
+   GotoXY(40,10);
+   Write('arrow-up to rotate the piece');
+   GotoXY(40,11);
+   Write('"P" to pause');
+   GotoXY(40,12);
+   Write('"E" Mode (standard or extended)');
+   GotoXY(40,13);
+   Write('"C" switches between color/mono mode');
+   GotoXY(40,14);
+   Write('Escape to quit');
+   GotoXY(40,15);
+   Write('"S" to show the highscores');
+   {$IFDEF Linux}
+   GotoXY(40,16);
+   Write('"i" try to switch to IBM character set');
+   {$ENDIF}
+   END
+   ELSE
+    ShowHighScore;
+  END
+ ELSE
+  BEGIN
+   GotoXY(40,9);
+   Write('"h" to display the helpscreen');
+  END;
+
+ FOR I :=0 TO TheHeight-1 DO
+  BEGIN
+   GotoXY(PosXField-1 ,PosYField+I); Write(Style[2]);
+   GotoXY(PosXField+2*TheWidth ,PosYField+I); Write(Style[2]);
+  END;
+ GotoXY(PosXField-1,PosYField+TheHeight);
+ Write(Style[3]);
+ FOR I:=0 TO (2*TheWidth)-1 DO
+  Write(Style[1]);
+ Write(Style[4]);
+END;
+PROCEDURE DisplMainFieldMono;
+{Displays the grid with a simple buffering algoritm, depending on
+conditional DoubleBuffer}
+
+VAR Row,Column,Difference,StartRow,EndRow : LONGINT;
+    S : String;
+
+BEGIN
+ FOR Row:=0 TO TheHeight-1 DO
+  BEGIN
+   {$IFDEF DoubleCache}
+    IF BackField[Row]<>MainField[Row] THEN
+     BEGIN
+    {$ENDIF}
+   FillChar(S[1],2*TheWidth,#32);
+   StartRow:=0;
+   EndRow:=TheWidth-1;
+   {$IFDEF DoubleCache}
+    Difference:=MainField[Row] XOR BackField[Row];     {Calc differences in line}
+    {Search for first and last bit changed}
+    WHILE ((Difference AND AndTable[StartRow])=0) AND (StartRow<(TheWidth-1)) DO
+     INC(StartRow);
+    WHILE ((Difference AND AndTable[EndRow])=0) AND (EndRow>0) DO
+     DEC(EndRow);
+   {$ENDIF}
+   {Prepare a string}
+   GotoXY(PosXField+2*StartRow,PosYField+Row);
+   S[0]:=CHR(2*(EndRow-StartRow+1));
+   FOR Column:=0 TO EndRow-StartRow DO
+    BEGIN
+     IF (MainField[Row] AND AndTable[StartRow+Column])<>0 THEN
+      BEGIN
+       S[Column*2+1]:=Style[5];
+       S[Column*2+2]:=Style[5];
+      END;
+    END;
+   {Write the string}
+   Write(S);
+   {$IFDEF DoubleCache}
+    END;
+   {$ENDIF}
+  END;
+ {$IFDEF DoubleCache}
+  BackField:=MainField;     {Keep a copy of the screen for faster updates
+                              of terminals, for next DisplMainField.}
+ {$ENDIF}
+END;
+
+PROCEDURE DisplMainFieldColor;
+{Same as above, but also use ColorField to output colors,
+ the buffering is the same, but the colors make it less efficient.}
+
+VAR Row,Column,Difference,StartRow,EndRow,
+    L : LONGINT;
+    S   : String;
+    LastCol : LONGINT;
+
+BEGIN
+ LastCol:=255;
+ FOR Row:=0 TO TheHeight-1 DO
+  BEGIN
+   {$IFDEF DoubleCache}
+    IF BackField[Row]<>MainField[Row] THEN
+     BEGIN
+    {$ENDIF}
+   FillChar(S[1],2*TheWidth,#32);
+   StartRow:=0;
+   EndRow:=TheWidth-1;
+   {$IFDEF DoubleCache}
+    Difference:=MainField[Row] XOR BackField[Row];     {Calc differences in line}
+    WHILE ((Difference AND AndTable[StartRow])=0) AND (StartRow<(TheWidth-1)) DO
+     INC(StartRow);
+    WHILE ((Difference AND AndTable[EndRow])=0) AND (EndRow>0) DO
+     DEC(EndRow);
+   {$ENDIF}
+   GotoXY(PosXField+2*StartRow,PosYField+Row);
+   FOR Column:=0 TO EndRow-StartRow DO
+    BEGIN
+     IF (MainField[Row] AND AndTable[StartRow+Column])<>0 THEN
+      BEGIN
+       L:=ColorField[Row,StartRow+Column];
+       IF L=0 THEN
+        L:=CurrentCol;
+       IF L<>LastCol THEN
+        BEGIN
+         TextColor(L);
+         Write(Style[5],Style[5]);
+        END;
+      END
+     ELSE
+      Write('  ');
+    END;
+   {$IFDEF DoubleCache}
+    END;
+   {$ENDIF}
+  END;
+ {$IFDEF DoubleCache}
+  BackField:=MainField;     {Keep a copy of the screen for faster updates
+                              of terminals, for next DisplMainField.}
+ {$ENDIF}
+END;
+
+PROCEDURE DisplMainField;
+{Main redraw routine; Check in what mode we are and call appropriate routine}
+
+BEGIN
+   IF UseColor THEN
+    DisplMainFieldColor
+   ELSE
+    DisplMainFieldMono;
+END;
+
+
+PROCEDURE ShowNextFigure(ThisFig:LONGINT);
+
+VAR I,J,K  : LONGINT;
+    S      : String[8];
+
+BEGIN
+ IF UseColor THEN
+  TextColor(White);
+ IF NOT nonupdatemode THEN
+  BEGIN
+   FOR I:=0 TO 4 DO
+    BEGIN
+     FillChar(S,9,' ');
+     S[0]:=#8;
+     K:=Figures[ThisFig][FigureNr];
+     IF (I+TopY)<=TheHeight THEN
+      FOR J:=0 TO 4 DO
+       BEGIN
+        IF (K AND AndTable[J+5*I])<>0 THEN
+         BEGIN
+          S[J*2+1]:=Style[5];
+          S[J*2+2]:=Style[5];
+         END
+       END;
+     GotoXY(50,11+I); Write(S);
+    END;
+  END;
+END;
+
+PROCEDURE FixScores;
+
+BEGIN
+   IF UseColor THEN
+    SetDefaultColor;
+   GotoXY(40,18);
+   Write('Score :',Score);
+END;
+  $Log$
+  Revision 1.1  2001-05-03 21:39:33  peter
+    * moved to own module
+
+  Revision 1.2  2000/07/13 11:33:08  michael
+  + removed logs
+ 
+}

+ 867 - 0
demo/graph/gameunit.pp

@@ -0,0 +1,867 @@
+{
+    $Id$
+
+    A simple unit with some common used routines for FPCGames (FpcTris and
+      SameGame)
+
+    Contains
+     - Highscore routines "developped" for FPCTris, but now also used by SameGame
+     - "Dummy" mouse routines which either shell to API units or to MSMouse.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+UNIT GameUnit;
+
+INTERFACE
+
+{MouseAPI defined : unit unes API mouse units, which requires that package,
+                    but also works under Linux
+ MouseAPI undef   : RTL unit MsMouse. API not required, but doesn't work under
+                    Linux }
+
+
+{$ifdef linux}
+  {$define MouseAPI}
+{$endif}
+{$ifdef win32}
+  {$define MouseAPI}
+{$endif}
+{$IFDEF Ver70}
+  {$define MouseAPI}
+  {$G+}
+{$endif}
+{$IFDEF Ver60}
+  {$define MouseAPI}
+  {$G+}
+{$endif}
+{$IFDEF Ver55}
+  {$define MouseAPI}
+  {$G+}
+{$endif}
+CONST  LineDistY=13;
+
+
+TYPE CHARSET=SET OF CHAR;
+
+{----   Unified Mouse procedures. ---- }
+
+FUNCTION MousePresent : BOOLEAN;
+
+PROCEDURE HideMouse;
+PROCEDURE ShowMouse;
+PROCEDURE GetMouseState(VAR MX,MY,MState : LONGINT);
+PROCEDURE DoneMouse;
+PROCEDURE InitMouse;
+PROCEDURE SetMousePosition(X,Y:LONGINT);
+
+
+Const LButton = 1; {left button}
+      RButton = 2; {right button}
+      MButton = 4; {middle button}
+
+
+{---- Standard Highscore procedures ----}
+
+TYPE  HighScoreType   = Packed RECORD
+                        Name : String[15];
+                        Score: LONGINT;
+                       END;
+     HighScoreArr    = ARRAY[0..9] OF HighScoreType;
+
+VAR HighScore   : HighScoreArr;
+    ScorePath   : String;
+    HighX,HighY : LONGINT;
+    Negative    : BOOLEAN;      { Negative=true-> better scores are lower}
+
+PROCEDURE LoadHighScore(FileName:STRING);
+PROCEDURE SaveHighScore;
+PROCEDURE ShowHighScore;
+
+FUNCTION  SlipInScore(Score:LONGINT):LONGINT;
+
+{---- Keyboard routines ----}
+
+CONST {Constants for GetKey}
+   ArrU   = $04800;    ArrL   = $04B00;    ArrR   = $04D00;   BS  = $08;  (* Backspace *)
+   ArrD   = $05000;    CR     = $0D;       ESC    = $1B;      KDelete= $05300;
+   KInsert= $05200;    Home   = $04700;    KEnd   = $04F00;   CtrlY = $19;
+   CtrlT = $14;
+
+CONST FieldSpace : CHAR = #177;
+      AlfaBeta : CHARSET= [' '..'z'];
+
+FUNCTION GetKey:LONGINT;
+
+{Generic string input routine}
+{$IFDEF UseGraphics}
+FUNCTION  GrInputStr(VAR S:String;X,Y,Len,dX,dY:LONGINT;TextIn:BOOLEAN;CharAllow:CHARSET):BOOLEAN;
+{$ELSE}
+FUNCTION  InputStr(VAR S:String;X,Y,Len:LONGINT;TextIn:BOOLEAN;CharAllow:CHARSET):BOOLEAN;
+{$ENDIF}
+
+{---- Misc ----}
+
+PROCEDURE SetDefaultColor; {Restore the attribs saved on startup}
+
+{BP compability}
+
+{$IFNDEF FPC}
+PROCEDURE SetCursorSize(CurDat:WORD);
+FUNCTION  GetCursorSize:WORD;
+PROCEDURE CursorOn;
+PROCEDURE CursorOff;
+
+{Non Go32 but not existant in BP}
+PROCEDURE FillWord(VAR Data;Count,Value:WORD);
+
+PROCEDURE dosmemfillword(Segx,xofs,Count,Value:WORD);
+PROCEDURE dosmemput(Segx,xofs:WORD;VAR Data;Count:WORD);
+PROCEDURE dosmemget(Segx,xofs:WORD;VAR Data;Count:WORD);
+
+FUNCTION  inportb(portx : word) : byte;
+PROCEDURE outportb(portx : word;data : byte);
+
+FUNCTION  inportw(portx : word) : word;
+PROCEDURE outportw(portx : word;data : word);
+
+FUNCTION  inportl(portx : word) : longint;
+PROCEDURE outportl(portx : word;data : longint);
+{$ENDIF}
+
+IMPLEMENTATION
+
+{$IFDEF MouseAPI}
+ {$IFDEF UseGraphics}
+  Uses Mouse,Dos,Crt,Graph;
+ {$ELSE}
+  Uses Mouse,Dos,Crt;
+ {$ENDIF}
+{$ELSE}
+  {$IFDEF UseGraphics}
+  Uses MsMouse,Dos,Crt,Graph;
+ {$ELSE}
+  Uses MsMouse,Dos,Crt;
+ {$ENDIF}
+{$ENDIF}
+
+VAR  DefColor    : BYTE;                         {Backup of startup colors}
+
+CONST
+
+{The initial names. If people feel they are missing, I first checked the Alias,
+  and then filled with names of the FPC-Devel list, and arranged them alfabetically}
+  InitNames : ARRAY[0..9] OF String[12] = ('Carl','Daniel','Florian','Jonas','John','Marco','Michael (3x)',
+                                           'Peter','Pierre','Thomas' );
+
+FUNCTION MousePresent : BOOLEAN;
+
+BEGIN
+ {$IFDEF MouseAPI}
+  MousePresent:=DetectMouse<>0;
+ {$ELSE}
+  MousePresent:=MouseFound;
+ {$ENDIF}
+END;
+
+PROCEDURE ShowMouse;
+
+BEGIN
+  {$IFDEF MouseAPI}
+  Mouse.ShowMouse;
+ {$ELSE}
+  MsMouse.ShowMouse;
+ {$ENDIF}
+END;
+
+PROCEDURE HideMouse;
+
+BEGIN
+ {$IFDEF MouseAPI}
+  Mouse.HideMouse;
+ {$ELSE}
+  MsMouse.HideMouse;
+ {$ENDIF}
+END;
+
+PROCEDURE InitMouse;
+
+BEGIN
+ {$IFDEF MouseAPI}
+  Mouse.InitMouse;
+ {$ELSE}
+  MsMouse.InitMouse;
+ {$ENDIF}
+END;
+
+PROCEDURE DoneMouse;
+
+BEGIN
+ {$IFDEF MouseAPI}
+  Mouse.DoneMouse;
+ {$ENDIF}
+END;
+
+PROCEDURE GetMouseState(VAR MX,MY,MState : LONGINT);
+
+  {$IFDEF MouseAPI}
+   VAR MouseEvent : TMouseEvent;
+  {$ENDIF}
+
+BEGIN
+  {$IFDEF MouseAPI}
+   GetMouseEvent(MouseEvent);
+   MX:=MouseEvent.X SHL 3;
+   MY:=MouseEvent.Y SHL 3;
+   MState:=MouseEvent.Buttons;
+ {$ELSE}
+  MsMouse.GetMouseState(MX,MY,MState);
+ {$ENDIF}
+END;
+
+PROCEDURE SetMousePosition(X,Y:LONGINT);
+
+BEGIN
+ {$IFDEF MouseAPI}
+  SetMouseXY(x,y);
+ {$ELSE}
+  SetMousePos(X,Y);
+ {$ENDIF}
+END;
+
+Procedure LoadHighScore(FileName:STRING);
+
+var
+ F: File;
+ I : LONGINT;
+ OFileMode : LONGINT;
+
+BEGIN
+ {$I-}
+ Assign(F, FileName);
+ OFileMode:=FileMode;
+ FileMode := 0;  {Set file access to read only }
+ Reset(F);
+ Close(F);
+ {$I+}
+ IF IOResult=0 THEN
+  ScorePath:=FileName
+ ELSE
+  ScorePath:=FSearch(FileName,GetEnv('PATH'));
+ IF ScorePath='' THEN
+  BEGIN
+   FOR I:=0 TO 9 DO
+    BEGIN
+     HighScore[I].Name:=InitNames[I];
+     HighScore[I].Score:=(I+1)*750;
+    END;
+   ScorePath:=FileName;
+  END
+ ELSE
+  BEGIN
+   Assign(F,ScorePath);
+   Reset(F,1);
+   BlockRead(F,HighScore,SIZEOF(HighScoreArr));
+   Close(F);
+  END;
+ FileMode:=OFileMode;
+END;
+
+Procedure SaveHighScore;
+
+var
+ F: File;
+
+BEGIN
+ Assign(F,ScorePath);
+ Rewrite(F,1);
+ BlockWrite(F,HighScore,SIZEOF(HighScoreArr));
+ Close(F);
+END;
+
+FUNCTION  SlipInScore(Score:LONGINT):LONGINT;
+
+VAR I,J : LONGINT;
+
+BEGIN
+ IF Negative THEN
+  Score:=-Score;
+ I:=0;
+ WHILE (Score>HighScore[I].Score) AND (I<10) DO
+  INC(I);
+ IF I<>0 THEN
+  BEGIN
+   IF I>1 THEN
+    FOR J:=0 TO I-2 DO
+     HighScore[J]:=HighScore[J+1];
+    HighScore[I-1].Score:=Score;
+    HighScore[I-1].Name:='';
+  END;
+ SlipInScore:=I;
+END;
+
+{$IFDEF UseGraphics}
+
+PROCEDURE ShowHighScore;
+
+VAR I : LONGINT;
+    S : String;
+
+BEGIN
+ SetFillStyle(SolidFill,0);            {Clear part of playfield}
+ Bar(HighX,HighY, 638, HighY+20+18*LineDistY);
+ FOR I:=0 TO 9 DO
+  BEGIN
+   OutTextXY(HighX,HighY+(9-I)*LineDistY,HighScore[I].Name);
+   IF Negative THEN
+    Str(-HighScore[I].Score:5,S)
+   ELSE
+    Str(HighScore[I].Score:5,S);
+   OutTextXY(HighX+150,HighY+(9-I)*LineDistY,S);
+  END;
+END;
+
+{$ELSE}
+PROCEDURE ShowHighScore;
+
+VAR I : LONGINT;
+
+{HighX=40 HighY=9}
+
+BEGIN
+ GotoXY(HighX+5,9); Write('The Highscores');
+ FOR I:=0 TO 9 DO
+  BEGIN
+   GotoXY(HighX,HighY+11-I);
+   Write(HighScore[I].Name,' ':(13-Length(HighScore[I].Name)),' ');
+   IF NOT Negative THEN     { Negative=true-> better scores are lower}
+    Write(HighScore[I].Score:5)
+   ELSE
+    Write(-HighScore[I].Score:5)
+  END;
+END;
+{$ENDIF}
+
+FUNCTION GetKey:LONGINT;
+
+VAR InKey: LONGINT;
+
+BEGIN
+ InKey:=ORD(ReadKey);
+ IF InKey=0 THEN InKey:=ORD(ReadKey) SHL 8;
+ GetKey:=InKey;
+END;
+
+{$IFNDEF UseGraphics}
+FUNCTION  InputStr(VAR S:String;X,Y,Len:LONGINT;TextIn:BOOLEAN;CharAllow:CHARSET):BOOLEAN;
+{
+  Input a string from keyboard, in a nice way,
+   allowed characters are in CHARSET CharAllow, but several editting
+   keys are always allowed, see CASE loop.
+
+Parameters:
+
+   X,Y       Coordinates field
+   Len       Length field
+   TextIn    S already filled?}
+
+VAR
+    InGev                     : LONGINT; { No. of chars inputted }
+    Posi                      : LONGINT; { Cursorposition}
+    Ins                       : BOOLEAN;  { Insert yes/no}
+    Key                       : LONGINT; { Last key as ELib.GetKey
+                                            code <255 if normal key,
+                                            >256 if special/function
+                                            key. See keys.inc}
+    Uitg                      : String;    {The inputted string}
+    Full                      : BOOLEAN;   { Is the string full? }
+    EndVal                    : WORD;
+
+PROCEDURE ReWr; { Rewrite the field, using Uitg}
+
+VAR    I                         : LONGINT;  { Temporary variabele }
+
+BEGIN
+ IF Length(Uitg)>Len THEN
+  Uitg[0]:=CHR(Len);
+ IF Length(Uitg)>0 THEN
+  FOR I:= 1 TO Length(Uitg) DO
+   BEGIN
+    GotoXY(X+I-1,Y);
+    IF Uitg[I]=CHR(32) THEN
+     Write(FieldSpace)
+    ELSE
+     Write(Uitg[I]);
+   END;
+ IF Len<>Length(Uitg) THEN
+  BEGIN
+   GotoXY(X+Length(Uitg),Y);
+   FOR I:= Length(Uitg) TO Len-1 DO
+    Write(FieldSpace);
+  END;
+END;
+
+PROCEDURE DoCursor; { Put Cursor in/out insert-mode }
+
+BEGIN
+ {$IFNDEF Linux}
+{ IF Ins THEN
+  SetCursorSize($11E)
+ ELSE
+  SetCursorSize($71E); }
+ {$ENDIF}
+
+END;
+
+BEGIN
+    { Init }
+
+  InGev :=0;              { 0 chars untill now }
+  Posi  :=1;               { Cursorposition 0 }
+  Ins   :=TRUE;            { Insert according to parameters }
+  DoCursor;        { Set cursor accordingly }
+  Key   :=0;
+
+       { put ±±± padded field on screen }
+
+  FillChar(Uitg,Len+1,FieldSpace);
+  Uitg[0]:=CHR(Len);
+  ReWr;
+  GotoXY(X,Y);
+
+  FillChar(Uitg,Len,32);
+  UitG[0]:=#0;
+
+  IF TextIn THEN
+   BEGIN
+    Uitg:=S;
+    Posi:=Length(Uitg)+1;                        { Put a predefined }
+    ReWr;                                   {  String on screen if specified }
+   END;
+
+  EndVal:=0;
+  WHILE EndVal=0 DO
+   BEGIN
+    Full:=FALSE;
+    IF ((Posi)>=Len) THEN
+     BEGIN
+      Full:=TRUE;
+      Posi:=Len;
+     END;
+    GotoXY(X+Posi-1,Y);
+    {$IFNDEF Linux}
+     {$IFDEF FPC}
+      CursorOn;
+     {$ENDIF}
+    DoCursor;
+    {$ENDIF}
+    Key:=GetKey;
+   {$IFNDEF Linux}
+    {$IFDEF FPC}
+    CursorOff;
+    {$ENDIF}
+   {$ENDIF}
+    CASE Key OF
+          CR              : BEGIN
+                             EndVal:=1;
+                             S:=UitG;
+                            END;
+          ESC             : EndVal:=2;
+          BS              : IF Posi>1 THEN       { BackSpace }
+                              BEGIN
+                               DEC(Posi);
+                               Delete(Uitg,Posi,1);
+                               DEC(InGev);
+                               ReWr;
+                              END;
+          KDelete          : BEGIN
+                              Delete(Uitg,Posi,1);
+                              DEC(InGev);
+                              ReWr;
+                             END;
+          ArrR            : IF (NOT Full) AND ((Posi-1)<InGev) THEN
+                              BEGIN
+                               INC (Posi);
+                               GotoXY(X+Posi-1,Y);
+                               END;
+          KInsert          : BEGIN
+                               Ins:= NOT Ins;
+                               DoCursor;
+                              END;
+          ArrL            : IF (NOT (Posi=1)) THEN
+                              BEGIN
+                               DEC (Posi);
+                               GotoXY(X+Posi-1,Y);
+                              END;
+          Home            : Posi:=1;
+          KEnd            : Posi:=InGev-1;
+          CtrlY           : BEGIN
+                             Delete(Uitg,Posi,Length(Uitg)-Posi);
+                             ReWr;
+                            END;
+          CtrlT           : BEGIN
+                             Uitg[0]:=#0; Posi:=1; ReWr;
+                            END;
+    END; {Case}
+   IF EndVal=0 THEN
+    BEGIN
+     IF (CHR(Key) IN CharAllow) THEN
+      BEGIN
+       IF Posi>Len THEN
+        Posi:=Len;
+       IF (Ins=FALSE) OR Full THEN
+        BEGIN
+         IF (ORD(Uitg[0])<Posi) THEN
+           Uitg[0]:=CHR(Posi);
+         Uitg[Posi]:=CHR(Key);
+        END
+       ELSE
+        BEGIN
+         Insert(CHR(Key),Uitg,Posi);
+        END;
+       ReWr;
+       INC(Posi);
+      END;
+     END;
+    InGev:=Length(Uitg);
+   END;
+  InputStr:=Endval=1;
+END;
+{$ENDIF}
+
+{$IFDEF UseGraphics}
+FUNCTION  GrInputStr(VAR S:String;X,Y,Len,dX,dY:LONGINT;TextIn:BOOLEAN;CharAllow:CHARSET):BOOLEAN;
+{As the (older) textversion except:
+    -  oX,oY are in pixels.
+    -  dX,dY are the dimensions of the font.
+    -  Len is still characters ( length in pixels/dX)
+}
+
+
+VAR
+    InGev                     : LONGINT; { No. of chars inputted }
+    Posi                      : LONGINT; { Cursorposition}
+    Ins                       : BOOLEAN;  { Insert yes/no}
+    Key                       : LONGINT; { Last key as ELib.GetKey
+                                            code <255 if normal key,
+                                            >256 if special/function
+                                            key. See keys.inc}
+    Uitg                      : String;    {The inputted string}
+    Full                      : BOOLEAN;   { Is the string full? }
+    EndVal                    : WORD;
+
+PROCEDURE ReWr; { Rewrite the field, using Uitg}
+
+VAR    I                         : LONGINT;  { Temporary variabele }
+       S                         : String;
+
+BEGIN
+ FillChar(S[1],Len,FieldSpace);
+ S:=Uitg;
+ IF Length(Uitg)>Len THEN
+  SetLength(Uitg,Len);
+ SetLength(S,Len);
+ IF Length(S)>0 THEN
+  BEGIN
+   FOR I:= 1 TO Length(S) DO
+    IF S[I]=CHR(32) THEN
+     S[I]:=FieldSpace;
+   SetFillStyle(SolidFill,0);
+   Bar(X,Y,X+Len*Dx+5,Y+Dy+1);
+   OutTextXY(X,Y,S);
+  END;
+END;
+
+PROCEDURE DoCursor; { Put Cursor in/out insert-mode }
+
+BEGIN
+ {$IFNDEF Linux}
+{ IF Ins THEN
+  SetCursorSize($11E)
+ ELSE
+  SetCursorSize($71E); }
+ {$ENDIF}
+END;
+
+BEGIN
+    { Init }
+
+  InGev :=0;              { 0 chars untill now }
+  Posi  :=1;               { Cursorposition 0 }
+  Ins   :=TRUE;            { Insert according to parameters }
+  DoCursor;        { Set cursor accordingly }
+  Key   :=0;
+//  SetFillStyle(SolidFill,0);
+//  Bar(X,Y,X+Len*Dx+5,Y+Dy+1);
+       { put ±±± padded field on screen }
+
+  FillChar(Uitg,Len+1,FieldSpace);
+  Uitg[0]:=CHR(Len);
+  ReWr;
+//  GotoXY(X,Y);
+  FillChar(Uitg,Len,32);
+  SetLength(UitG,0);
+
+  IF TextIn THEN
+   BEGIN
+    Uitg:=S;
+    Posi:=Length(Uitg)+1;                        { Put a predefined }
+    ReWr;                                   {  String on screen if specified }
+   END;
+
+  EndVal:=0;
+  WHILE EndVal=0 DO
+   BEGIN
+    Full:=FALSE;
+    IF ((Posi)>=Len) THEN
+     BEGIN
+      Full:=TRUE;
+      Posi:=Len;
+     END;
+    {$IFNDEF Linux}
+     {$IFDEF FPC}
+      CursorOn;
+     {$ENDIF}
+    DoCursor;
+    {$ENDIF}
+    Key:=GetKey;
+   {$IFNDEF Linux}
+    {$IFDEF FPC}
+    CursorOff;
+    {$ENDIF}
+   {$ENDIF}
+    CASE Key OF
+          CR              : BEGIN
+                             EndVal:=1;
+                             S:=UitG;
+                            END;
+          ESC             : EndVal:=2;
+          BS              : IF Posi>1 THEN       { BackSpace }
+                              BEGIN
+                               DEC(Posi);
+                               Delete(Uitg,Posi,1);
+                               DEC(InGev);
+                               ReWr;
+                              END;
+          KDelete          : BEGIN
+                              Delete(Uitg,Posi,1);
+                              DEC(InGev);
+                              ReWr;
+                             END;
+          ArrR            : IF (NOT Full) AND ((Posi-1)<InGev) THEN
+                              BEGIN
+                               INC (Posi);
+  //                             GotoXY(X+Posi-1,Y);
+                               END;
+          KInsert          : BEGIN
+                               Ins:= NOT Ins;
+                               DoCursor;
+                              END;
+          ArrL            : IF (NOT (Posi=1)) THEN
+                              BEGIN
+                               DEC (Posi);
+                              END;
+          Home            : Posi:=1;
+          KEnd            : Posi:=InGev-1;
+          CtrlY           : BEGIN
+                             Delete(Uitg,Posi,Length(Uitg)-Posi);
+                             ReWr;
+                            END;
+          CtrlT           : BEGIN
+                             Uitg[0]:=#0; Posi:=1; ReWr;
+                            END;
+    END; {Case}
+   IF EndVal=0 THEN
+    BEGIN
+     IF (CHR(Key) IN CharAllow) THEN
+      BEGIN
+       IF Posi>Len THEN
+        Posi:=Len;
+       IF (Ins=FALSE) OR Full THEN
+        BEGIN
+         IF (Length(Uitg)<Posi) THEN
+          SetLength(UitG,Posi);
+         Uitg[Posi]:=CHR(Key);
+        END
+       ELSE
+         Insert(CHR(Key),Uitg,Posi);
+       ReWr;
+       INC(Posi);
+      END;
+     END;
+    InGev:=Length(Uitg);
+   END;
+  GrInputStr:=Endval=1;
+END;
+{$ENDIF}
+
+PROCEDURE SetDefaultColor;
+
+BEGIN
+ TextColor(DefColor AND 15);
+ TextBackground(DefColor SHR 4);
+END;
+
+
+{$IFNDEF FPC}
+PROCEDURE SetCursorSize(CurDat:WORD);ASSEMBLER;
+ASM
+  mov ah,1
+  mov cx,CurDat
+  int $10
+END;
+
+{The two procedures below are standard (and os-independant) in FPC's Crt}
+PROCEDURE CursorOn;
+BEGIN
+  SetCursorSize($090A);
+END;
+
+PROCEDURE CursorOff;
+BEGIN
+  SetCursorSize($FFFF);
+END;
+
+PROCEDURE dosmemfillword(Segx,xofs,Count,Value:WORD); ASSEMBLER;
+{VAR A:WORD;
+BEGIN
+  FOR A :=0 TO Count-1 DO
+    MemW[Seg:xofs+2*A]:=Value;
+END;
+}
+ASM
+  mov  ax,segx
+  mov  es,ax
+  mov  di,xofs
+  mov  cx,count
+  mov  ax,value
+  rep
+    stosw
+end;
+
+{TYPE VetteArray=ARRAY[0..9999] OF BYTE;}
+
+PROCEDURE dosmemput(Segx,xofs:WORD;VAR Data;Count:WORD); assembler;
+{VAR A:WORD;
+    L:^VetteArray;
+BEGIN
+  L:=@Data;
+  FOR A :=0 TO Count-1 DO
+    Mem[Segx:xofs+A]:=L^[A];
+END;
+}
+asm
+  lds si,Data
+  mov ax,segx
+  mov es,ax
+  mov di,xofs
+  mov cx,count
+  rep
+    movsw
+end;
+
+PROCEDURE dosmemget(Segx,xofs:WORD;VAR Data;Count:WORD); ASSEMBLER;
+{VAR A:WORD;
+    L:^VetteArray;
+BEGIN
+  L:=@Data;
+  FOR A :=0 TO Count-1 DO
+    L^[A]:=Mem[Segx:xofs+A];
+END;
+}
+asm
+  les di,Data
+  mov ax,segx
+  mov ds,ax
+  mov si,xofs
+  mov cx,count
+  rep
+    movsw
+end;
+
+PROCEDURE FillWord(VAR Data;Count,Value:WORD); ASSEMBLER;
+{VAR A :WORD;
+    L:^VetteArray;
+BEGIN
+  L:=@Data;
+  FOR A:=0 TO Count-1 DO
+  Begin
+    L^[2*A]:=Value AND 255;
+    L^[2*A+1]:=Value shr 8;
+  END;
+END;}
+
+asm
+  les di,Data
+  mov cx,count
+  mov ax,Value
+  rep
+    movsw
+end;
+
+FUNCTION GetCursorSize:WORD;ASSEMBLER;
+ASM
+  mov ah,3
+  xor bh,bh
+  int $10
+  mov ax,cx
+END;
+
+FUNCTION  inportb(portx : word) : byte;
+BEGIN
+  Inportb:=Port[PortX];
+END;
+
+PROCEDURE outportb(portx : word;data : byte);
+BEGIN
+  Port[portx]:=Data;
+END;
+
+FUNCTION  inportw(portx : word) : word;
+BEGIN
+  Inportw:=Portw[PortX];
+END;
+
+PROCEDURE outportw(portx : word;data : word);
+BEGIN
+  PortW[portx]:=Data;
+END;
+
+ FUNCTION  inportl(portx : word) : longint; ASSEMBLER;
+ ASM
+   mov dx,portx                   { load port address }
+   db $66; in  ax,dx              { in  eax,dx }
+   db $66; mov dx,ax              { mov edx, eax }
+   db $66; shr dx,16              { shr edx, 16 }
+   { return: ax=low word, dx=hi word }
+ END;
+
+ PROCEDURE  outportl(portx : word;data : longint); ASSEMBLER;
+ ASM
+   { we cant use the 32 bit operand prefix for loading the longint -
+     therefore we have to do that in two chunks }
+     mov dx, portx
+     db $66; mov ax, Word(Data)  { mov eax, Data }
+   db $66; out dx,ax              { out dx, eax }
+ END;
+
+{$ENDIF}
+
+BEGIN
+  DefColor:=TextAttr;                { Save the current attributes, to restore}
+  Negative:=FALSE;                    { Negative=true-> better scores are lower}
+END.
+{
+  $Log$
+  Revision 1.1  2001-05-03 21:39:33  peter
+    * moved to own module
+
+  Revision 1.2  2000/07/13 11:33:08  michael
+  + removed logs
+ 
+}

+ 918 - 0
demo/graph/gravwars.pp

@@ -0,0 +1,918 @@
+Program GravityWars;
+{A demo for TP 4.0 compability of Graph.
+
+The sources for this game was found on a site that claims to only have
+PD stuff with the below header(which was only reindented), and the webmaster
+said that everything he published was sent to him with that purpose. We tried
+to contact the authors mentioned below via mail over internet, but that
+failed. If there is somebody that claims authorship of these programs,
+please mail [email protected], and the sources will be removed from our
+websites.
+
+------------------------------------------------------------------------
+
+ORIGINAL Header:
+
+     by Sohrab Ismail-Beigi     Completed 4/23/89
+     SYSOP of The 3D Graphics BBS
+     300/1200/2400 baud, N-8-1 Full duplex
+     (201) 444-4154
+
+     Turbo Pascal 4.0 source code.  Requires VGA 640x480x16 display.
+     Note: pix=pixels in the comments}
+
+Uses Crt,Graph;
+
+Type
+    spacecraft=Record                       {used for ships and pointer}
+                 coffx,coffy,r : longint;   {center offsets and radius in pix}
+                 imagex,imagey : longint;   {upper left of image}
+                 imagepointr   : pointer;   {pointer to image data}
+                 imagesize     : word;      {size in bytes}
+               end;
+    planettype=Record
+                 cx,cy,r : longint;         {planet center and radius}
+                 d,GM    : real;            {density and G*M product}
+               end;
+
+Const
+     color : array[1..3] of byte=(Red,Green,LightBlue); {colors for planets}
+     G=0.1;                                             {gravity constant}
+     bhr=15;                                            {black hole radius}
+     Esc=#27;                                           {ASCII for Esc}
+     Return=#13;                                        { "     "  RETURN}
+
+Var
+  ship      : array[1..2] of spacecraft;    {2 ships}
+  tp,pointr : spacecraft;                   {tp is temporary, 1 pointer}
+  pl        : array[1..9] of planettype;    {the 9 planets}
+  screen    : Record                        {the game area}
+                sx,ex,sy,ey,cx,cy,lx,ly : longint; {start x/y, end x/y, center}
+              end;                                 {x/y, length x/y}
+  np,GraphDriver,GraphMode : integer;              {# of planets}
+  criticaldist : real;                             {for escape velocity calc}
+  playsong  : boolean;                             {play the songs?}
+
+Procedure Init;              {initialize everything}
+begin
+  //SetGraphBufSize(10);
+  GraphDriver:=VGA;
+  GraphMode:=VGAHi;
+  InitGraph(GraphDriver,GraphMode,'');
+  setbkcolor(black);
+  setviewport(0,0,getmaxx,getmaxy,clipoff);
+  clearviewport;
+  SetColor(LightGray);
+  SetFillStyle(SolidFill,LightGray);      {Hull of ships}
+  Circle(100,100,9);
+  FloodFill(100,100,LightGray);
+  Bar(77,98,100,102);
+  MoveTo(82,98);
+  LineRel(-3,-8);
+  LineRel(-13,0);               LineRel(0,-3);
+  LineRel(24,0);                LineRel(0,3);
+  LineRel(-7,0);                LineRel(3,8);
+  FloodFill(83,97,LightGray);
+  MoveTo(82,101);               LineRel(-3,8);
+  LineRel(-13,0);               LineRel(0,3);
+  LineRel(24,0);                LineRel(0,-3);
+  LineRel(-7,0);                LineRel(3,-8);
+  FloodFill(83,103,LightGray);
+  MoveTo(200,200);              LineRel(5,-5);
+  LineRel(5,5);                 LineRel(10,0);
+  LineRel(5,-8);                LineRel(15,0);
+  LineRel(-6,9);                LineRel(6,9);
+  LineRel(-15,0);               LineRel(-5,-7);
+  LineRel(-10,0);               LineRel(-5,5);
+  LineRel(-6,-7);               LineRel(2,-2);
+  FloodFill(201,201,LightGray);
+  SetColor(LightRed);
+  SetFillStyle(SolidFill,LightRed); {Red lights on ships}
+  Circle(100,100,2);
+  FloodFill(100,100,LightRed);
+  Bar(89,87,91,90);             Bar(89,109,91,112);
+  Bar(224,200,226,203);         Bar(240,192,242,194);
+  Bar(240,208,242,210);
+  SetColor(Yellow);
+  MoveTo(0,0);                  LineRel(0,10);
+  MoveTo(0,0);                  LineRel(10,0);
+  MoveTo(0,0);                  LineRel(15,15);   {pointer}
+  tp.imagesize:=ImageSize(0,0,16,16);     {kludge to subdue compiler bug}
+  GetMem(tp.imagepointr,tp.imagesize);
+  GetImage(0,0,16,16,tp.imagepointr^);
+  pointr.imagesize:=ImageSize(0,0,16,16);
+  GetMem(pointr.imagepointr,pointr.imagesize);
+  GetImage(0,0,16,16,pointr.imagepointr^);           {get pointer}
+  pointr.coffx:=7;
+  pointr.coffy:=7;
+  pointr.r:=9;
+  ship[1].imagesize:=ImageSize(66,87,110,113);
+  GetMem(ship[1].imagepointr,ship[1].imagesize);
+  GetImage(66,87,110,113,ship[1].imagepointr^);      {enterprise}
+  ship[1].coffx:=22; ship[1].coffy:=13; ship[1].r:=26;
+  ship[2].imagesize:=ImageSize(199,192,242,210);
+  GetMem(ship[2].imagepointr,ship[2].imagesize);
+  GetImage(199,192,242,210,ship[2].imagepointr^);     {klingon}
+  ship[2].coffx:=21; ship[2].coffy:=9; ship[2].r:=23;
+  ClearDevice;
+  screen.sx:=1;
+  screen.ex:=638;
+  screen.sy:=33;
+  screen.ey:=478;
+  screen.cx:=(screen.sx+screen.ex) div 2;                 {initialize screen}
+  screen.cy:=(screen.sy+screen.ey) div 2;                            {bounds}
+  screen.lx:=screen.ex-screen.sx+1;
+  screen.ly:=screen.ey-screen.sy+1;
+  criticaldist:=2.0*sqrt(sqr(screen.lx)+sqr(screen.ly)); {critical distance}
+  playsong:=true;                                    {for escape vel. calc}
+end;
+
+Procedure Finish;   {free memory and end}
+begin
+  FreeMem(ship[1].imagepointr,ship[1].imagesize);
+  FreeMem(ship[2].imagepointr,ship[2].imagesize);
+  FreeMem(pointr.imagepointr,pointr.imagesize);
+  FreeMem(tp.imagepointr,tp.imagesize);
+  CloseGraph;
+end;
+
+Function InBounds(cx,cy,r:longint):boolean; {is the point with radius}
+begin                                       {completely in screen bounds?}
+   InBounds:=true;
+   if r<>0 then
+     if (cx-r<=screen.sx) or (cx+r>=screen.ex) or
+        (cy-r<=screen.sy) or (cy+r>=screen.ey) then
+          InBounds:=false
+   else
+     if (cx-bhr<=screen.sx) or (cx+bhr>=screen.ex) or
+        (cy-bhr<=screen.sy) or (cy+bhr>=screen.ey) then
+          InBounds:=false;
+end;
+
+Procedure RandomSetup;   {make a random setup}
+var i,j : integer;
+    a,b : longint;
+    ok  : boolean;
+begin
+  Randomize;
+  np:=Random(9)+1;   {random # of planets 1-9}
+  for i:=1 to np do  {pick planet positions}
+    Repeat
+      ok:=true;
+      pl[i].cx:=Random(screen.lx)+screen.sx;
+      pl[i].cy:=Random(screen.ly)+screen.sy;
+      pl[i].d:=(Random(3)+2)/2.0;
+      pl[i].r:=0;
+      if Random>0.05 then pl[i].r:=Random(70)+20; {5% chance of blackhole}
+      if pl[i].r<>0 then
+        pl[i].GM:=G*2*pi*sqr(pl[i].r)*pl[i].d
+      else
+        pl[i].GM:=G*2*pi*sqr(30)*1.0;
+      ok:=InBounds(pl[i].cx,pl[i].cy,pl[i].r);
+      if (i>1) and (ok) then          {any collisions with existing planets?}
+        for j:=1 to i-1 do
+          begin
+          if sqrt(sqr(pl[i].cx-pl[j].cx)+sqr(pl[i].cy-pl[j].cy))<=
+            pl[i].r+pl[j].r+2*bhr then
+               ok:=false;
+          end;
+    Until ok;
+  for i:=1 to 2 do   {pick ship positions}
+    Repeat
+      ok:=true;
+      ship[i].imagex:=Random(screen.lx div 2)+screen.sx; {enterprise to the}
+      if i=2 then ship[2].imagex:=ship[i].imagex+screen.lx div 2; {left and}
+      ship[i].imagey:=Random(screen.ly)+screen.sy;      {klingon to the right}
+      a:=ship[i].imagex+ship[i].coffx; b:=ship[i].imagey+ship[i].coffy;
+      ok:=InBounds(a,b,ship[i].r);
+      for j:=1 to np do           {any collisions with planets?}
+        if sqrt(sqr(a-pl[j].cx)+sqr(b-pl[j].cy))<=pl[j].r+ship[i].r+bhr then
+           ok:=false;
+    Until ok;
+end;
+
+Procedure DrawSetup;  {draw current setup}
+var i,j : integer;
+begin
+  ClearDevice;
+  SetColor(White);
+  Rectangle(screen.sx-1,screen.sy-1,screen.ex-1,screen.ey-1); {game box}
+  for i:=1 to 2000 do             {2000 random stars}
+    PutPixel(Random(screen.lx)+screen.sx,Random(screen.ly)+screen.sy,White);
+  for i:=1 to 2 do  {2 ships}
+    PutImage(ship[i].imagex,ship[i].imagey,ship[i].imagepointr^,NormalPut);
+  for i:=1 to np do  {np planets}
+    if pl[i].r>0 then   {normal}
+      begin
+        SetColor(color[trunc(pl[i].d*2-1)]);
+        Circle(pl[i].cx,pl[i].cy,pl[i].r);
+        SetFillStyle(SolidFill,color[trunc(pl[i].d*2-1)]);
+        FloodFill(pl[i].cx,pl[i].cy,color[trunc(pl[i].d*2-1)]);
+      end
+    else               {black hole}
+      begin
+        SetColor(Black);
+        for j:=0 to bhr do
+          Circle(pl[i].cx,pl[i].cy,j);
+      end;
+end;
+
+Procedure ClearDialogBox;  {clear text message area}
+begin
+  SetFillStyle(SolidFill,Black);
+  Bar(0,0,screen.ex-1,screen.sy-2);
+end;
+
+Function GetString:string;  {get a string until RETURN is pressed}
+var s : string;
+    c : char;
+begin
+  s:='';
+  Repeat
+    c:=ReadKey;
+    if (c=chr(8)) and (length(s)>0) then          {backspace key}
+        begin
+          delete(s,length(s),1);
+          MoveRel(-8,0);                          {delete last char}
+          SetFillStyle(SolidFill,Black);
+          Bar(GetX,GetY,GetX+8,GetY+8);
+        end
+    else if c<>Return then
+      begin
+        s:=concat(s,c);                           {get and draw char}
+        SetColor(LightGray);
+        OutText(c);
+      end;
+  Until c=Return;
+  GetString:=s;
+end;
+
+Procedure PlayGame;
+Const number_of_explosion_dots=20;   {# dots for explosion with planet surface}
+Var vx,vy,vc,x,y,dt,ax,ay,dx,dy,dr,k : real;
+    v0,angle : array[1..2] of real;
+    s : string;
+    ch : char;
+    i,event,player,winner : integer;
+    ok,donecritical,offscreen : boolean;
+    buffer : array[1..number_of_explosion_dots] of Record  {for explosion}
+                                                     x,y,color : integer;
+                                                   end;
+begin
+  v0[1]:=0; v0[2]:=0; angle[1]:=0; angle[2]:=0;
+  player:=1;
+  donecritical:=false;
+  Repeat                               {infinite loop}
+    ClearDialogBox;
+    SetColor(LightGray);
+    str(player,s);
+    s:=concat('Player ',s);        {player #}
+    OutTextXY(0,0,s);
+    Repeat                         {get angle}
+      MoveTo(0,10);
+      str(angle[player]:3:5,s);
+      s:=concat('Angle: [',s,']: ');
+      OutText(s);
+      s:=GetString;
+      if (s[1]='Q') or (s[1]='q') then exit;
+      i:=0;
+      if s<>'' then Val(s,angle[player],i);
+      SetFillStyle(SolidFill,Black);
+      ok:=(i=0) and (angle[player]>=0.0) and (angle[player]<=360);
+      if not ok then Bar(0,10,screen.ex-1,18);
+    Until ok;
+    Repeat                        {get initial velocity}
+      MoveTo(0,20);
+      str(v0[player]:2:5,s);
+      s:=concat('Initial Velocity: [',s,']: ');
+      OutText(s);
+      s:=GetString;
+      if (s[1]='Q') or (s[1]='q') then exit;
+      i:=0;
+      if s<>'' then Val(s,v0[player],i);
+      SetFillStyle(SolidFill,Black);
+      ok:=(i=0) and (v0[player]>=0.0) and (v0[player]<=10.0);
+      if not ok then Bar(0,20,screen.ex-1,28);
+    Until ok;
+    k:=pi*angle[player]/180.0;   {angle in radians}
+    vx:=v0[player]*cos(k);
+    vy:=-v0[player]*sin(k);
+    x:=ship[player].imagex+ship[player].coffx+ship[player].r*cos(k);
+    y:=ship[player].imagey+ship[player].coffy-ship[player].r*sin(k);
+    ClearDialogBox;
+    MoveTo(round(x),round(y));
+    SetColor(White);
+    offscreen:=false;
+    Repeat                       {calculate and draw trajectory}
+      dt:=0.25;                  {time interval [vel. is in pix/time]}
+      x:=x+vx*dt; y:=y+vy*dt;
+      ax:=0; ay:=0;
+      for i:=1 to np do          {calc accel. due to gravity}
+        begin
+          dx:=x-pl[i].cx; dy:=y-pl[i].cy; dr:=sqrt(sqr(dx)+sqr(dy));
+          k:=1/(sqr(dr)*dr);
+          if pl[i].r<>0 then       {normal}
+            begin
+              ax:=ax-pl[i].GM*dx*k;
+              ay:=ay-pl[i].GM*dy*k
+            end
+          else                     {black hole}
+            begin
+              ax:=ax-pl[i].GM*dx*(k+sqr(k*dr));
+              ay:=ay-pl[i].GM*dy*(k+sqr(k*dr));
+            end;
+        end;
+      vx:=vx+ax*dt; vy:=vy+ay*dt;
+      event:=0;
+      if keypressed then
+        event:=1
+      else if (x>=screen.sx) and (x<=screen.ex) and        {in screen bounds?}
+              (y>=screen.sy) and (y<=screen.ey) then
+         begin
+           donecritical:=false;
+           i:=GetPixel(round(x),round(y));
+           if (i=color[1]) or (i=color[2]) or (i=color[3]) or
+              (i=LightRed) or (i=LightGray) then event:=2
+           else
+             if offscreen then
+               MoveTo(round(x),round(y))
+             else
+               LineTo(round(x),round(y));
+           offscreen:=false;
+         end                                               {off screen}
+      else if not donecritical then
+        begin
+          offscreen:=true;               {offscreen and critical distance}
+          dx:=x-screen.cx; dy:=y-screen.cy; dr:=sqrt(sqr(dx)+sqr(dy));
+          if dr>=criticaldist then
+            begin
+              vc:=(dx*vx+dy*vy)/dr;
+              k:=0; for i:=1 to np do k:=k+pl[i].GM;
+              if 0.5*sqr(vc)>=k/dr then     {do we have escape velocity?}
+                event:=3;
+            end;
+        end;
+    Until event<>0;
+    if event=1 then          {a key was pressed for a break}
+      begin
+        ClearDialogBox;
+        ch:=ReadKey; {one already in buffer}
+        SetColor(LightGray);
+        OutTextXY(0,0,'Break... Esc to break, any other key to continue');
+        ch:=ReadKey;
+        if ch=Esc then exit;
+      end
+    else if event=3 then       {missile escaped the universe}
+      begin
+        ClearDialogBox;
+        SetColor(LightGray);
+        OutTextXY(0,0,'Missile left the galaxy...');
+        delay(2000);
+      end
+    else           {event=2}   {hit something}
+      begin
+        if (i=color[1]) or (i=color[2]) or (i=color[3]) then  {hit a planet}
+          begin
+            for i:=1 to number_of_explosion_dots do     {draw explosion}
+              begin
+                buffer[i].x:=trunc(x+20*(Random-0.5));
+                buffer[i].y:=trunc(y+20*(Random-0.5));
+                buffer[i].color:=GetPixel(buffer[i].x,buffer[i].y);
+                PutPixel(buffer[i].x,buffer[i].y,LightRed);
+                delay(25);
+              end;
+            delay(1000);
+            for i:=1 to number_of_explosion_dots do     {erase explosion}
+              PutPixel(buffer[i].x,buffer[i].y,buffer[i].color);
+          end
+        else    {hit a ship!}
+          begin
+            if sqrt(sqr(x-ship[1].imagex-ship[1].coffx)+ {which one won?}
+                    sqr(y-ship[1].imagey-ship[1].coffy))<=ship[1].r+5 then
+                      winner:=2
+            else winner:=1;
+            for event:=1 to 100 do          {flash the screen}
+              SetPalette(Black,Random(16));
+            SetPalette(Black,Black);
+            for i:=1 to 1000 do    {put some white and red points}
+              begin
+                k:=Random*2*pi;
+                event:=Random(3);
+                if event=0 then
+                  PutPixel(trunc(x+30*Random*cos(k)),trunc(y+30*Random*sin(k)),Black)
+                else if event=1 then
+                  PutPixel(trunc(x+30*Random*cos(k)),trunc(y+30*Random*sin(k)),Red)
+                else
+                  PutPixel(trunc(x+20*Random*cos(k)),trunc(y+20*Random*sin(k)),White);
+              end;
+            ClearDialogBox;
+            SetColor(LightGray);
+            str(winner,s);
+            s:=concat('Player ',s,' wins!!!');    {announce}
+            OutTextXY(0,0,s);
+            if playsong then                      {play a tune}
+              begin
+                Sound(440); delay(150);
+                Nosound; delay(50);
+                Sound(440); delay(150);
+                Sound(554); delay(150);
+                Sound(659); delay(350);
+                Sound(554); delay(150);
+                Sound(659); delay(450);
+                Nosound; delay(500);
+                Sound(880); delay(800);
+                Nosound;
+              end;
+            delay(3000);
+            exit;
+          end;
+      end; {if event=3}
+    Inc(player); if player=3 then player:=1;    {next player}
+  Until true=false; {infinite loop}
+end;
+
+Procedure PlayingtheGame;     {playing the game menu}
+var option : char;
+begin
+  Repeat
+    ClearDialogBox;
+    SetColor(LightGray);
+    OutTextXY(0,0,'1. Random setup   2. Play game    Esc quits menu');
+    OutTextXY(0,10,'Option: ');
+    option:=ReadKey;
+    Case option of
+      '1' : begin
+              ClearDialogBox;
+              RandomSetup;
+              DrawSetup;
+            end;
+      '2' : PlayGame;
+    end;
+  Until option=Esc;
+end;
+
+Procedure Options;   {options menu}
+var option : char;
+begin
+  Repeat
+    ClearDialogBox;
+    SetColor(LightGray);
+    OutTextXY(0,0,'1. Redraw screen   2. Sound on/off     Esc quits menu');
+    OutTextXY(0,10,'Option: ');
+    option:=ReadKey;
+    Case option of
+      '1' : DrawSetUp;
+      '2' : playsong:=not playsong;
+    end;
+  Until option=Esc;
+end;
+
+Procedure InterpKey(c:char; var x,y,coffx,coffy,r:longint;
+                            var jump:integer; var moveit:boolean);
+begin              {interprets keys for movement of pointer, mainly to save}
+  Case c of                {space due to shared code in many Change routines}
+    '+' : if jump<49 then Inc(jump,2);
+    '-' : if jump>2 then Dec(jump,2);
+    '8' : begin                              {up}
+            Dec(y,jump);
+            if InBounds(x+coffx,y+coffy,r) then
+              moveit:=true
+            else
+              Inc(y,jump);
+          end;
+    '2' : begin                              {down}
+            Inc(y,jump);
+            if InBounds(x+coffx,y+coffy,r) then
+              moveit:=true
+            else
+              Dec(y,jump);
+          end;
+    '4' : begin                              {left}
+            Dec(x,jump);
+            if InBounds(x+coffx,y+coffy,r) then
+              moveit:=true
+            else
+              Inc(x,jump);
+          end;
+    '6' : begin                              {right}
+            Inc(x,jump);
+            if InBounds(x+coffx,y+coffy,r) then
+              moveit:=true
+            else
+              Dec(x,jump);
+          end;
+  end; {case c of}
+end;
+
+Procedure MoveShip;    {move a given ship to a new legal position}
+var c : char;
+    s,jump,j : integer;
+    x,y,xold,yold,a,b : longint;
+    legal,moveit : boolean;
+begin
+  ClearDialogBox;
+  SetColor(LightGray);
+  OutTextXY(0, 0,'Ships:  1. Enterprise   2. Klingon    Esc aborts');
+  OutTextXY(0,10,'Which ship? ');     {get the proper ship}
+  Repeat
+    c:=ReadKey;
+  Until (c='1') or (c='2') or (c=Esc);
+  if c=Esc then exit;
+  if c='1' then s:=1 else s:=2;
+  ClearDialogBox;
+  OutTextXY(0, 0,'Use cursors to move ship. (Num Lock on)   Esc aborts');
+  OutTextXY(0,10,'Enter to place, + and - to change size of jumps.');
+  jump:=30;
+  x:=ship[s].imagex; y:=ship[s].imagey;
+  Repeat    {loop until Esc or somewhere legal}
+    Repeat    {loop until Esc or RETURN}
+      Repeat c:=ReadKey; Until (c='4') or (c='8') or (c='6') or (c='2') or
+                               (c='+') or (c='-') or (c=Return) or (c=Esc);
+      moveit:=false; xold:=x; yold:=y;
+      InterpKey(c,x,y,ship[s].coffx,ship[s].coffy,ship[s].r,jump,moveit);
+      if moveit then  {if can move the image,}
+        begin
+          PutImage(xold,yold,ship[s].imagepointr^,XORPut); {erase old}
+          PutImage(x,y,ship[s].imagepointr^,XORPut);       {draw new}
+          moveit:=false;
+        end;
+    Until (c=Return) or (c=Esc);
+    if c=Esc then                     {abort}
+      begin
+        PutImage(x,y,ship[s].imagepointr^,XORPut);
+        PutImage(ship[s].imagex,ship[s].imagey,ship[s].imagepointr^,NormalPut);
+        exit;
+      end;
+    a:=x+ship[s].coffx; b:=y+ship[s].coffy;
+    legal:=InBounds(a,b,ship[s].r);     {in bounds?}
+    for j:=1 to np do                   {in collision with any planets?}
+      if sqrt(sqr(a-pl[j].cx)+sqr(b-pl[j].cy))<=pl[j].r+ship[s].r+bhr then
+         legal:=false;
+    if not legal then                   {oops! not legal!}
+      begin
+        SetPalette(Black,White);
+        SetFillStyle(SolidFill,Black);
+        Bar(0,20,screen.ex,screen.sy-2);
+        delay(100);
+        SetPalette(Black,Black);
+        SetColor(LightGray);
+        OutTextXY(0,20,'Illegal ship position!');
+      end;
+  Until legal;
+  ship[s].imagex:=x; ship[s].imagey:=y;    {ok, place it there}
+end;
+
+Procedure MovePlanet;   {move a planet}
+var c : char;
+    i,p,jump : integer;
+    x,y,xold,yold,minr,t,cxorig,cyorig : longint;
+    moveit,legal : boolean;
+begin
+  ClearDialogBox;
+  if np=0 then         {no planets!}
+    begin
+      OutTextXY(0,0,'No planets to move!');
+      delay(2000);
+      exit;
+    end;
+  OutTextXY(0, 0,'Use cursors to move pointer. (Num Lock on)   Esc aborts');
+  OutTextXY(0,10,'Enter to pick planet, + and - to change size of jumps.');
+  jump:=30;
+  x:=100; y:=100; PutImage(x,y,pointr.imagepointr^,XORPut);
+  Repeat    {loop until Esc or RETURN}
+    Repeat c:=ReadKey; Until (c='4') or (c='8') or (c='6') or (c='2') or
+                             (c='+') or (c='-') or (c=Return) or (c=Esc);
+    moveit:=false; xold:=x; yold:=y;
+    InterpKey(c,x,y,pointr.coffx,pointr.coffy,pointr.r,jump,moveit);
+    if moveit then
+      begin
+        PutImage(xold,yold,pointr.imagepointr^,XORPut);
+        PutImage(x,y,pointr.imagepointr^,XORPut);
+        moveit:=false;
+      end;
+  Until (c=Return) or (c=Esc);
+  PutImage(x,y,pointr.imagepointr^,XORPut);   {erase pointer}
+  if c=Esc then exit;
+  p:=0; minr:=trunc(sqrt(sqr(screen.lx)+sqr(screen.ly)));
+  for i:=1 to np do   {find the closest planet/black hole}
+    begin
+      t:=trunc(sqrt(sqr(x-pl[i].cx)+sqr(y-pl[i].cy)));
+      if t<minr then begin minr:=t; p:=i; end;
+    end;
+  SetColor(LightGreen);                      {clear it out}
+  Circle(pl[p].cx,pl[p].cy,pl[p].r);
+  SetFillStyle(SolidFill,Black);
+  FloodFill(pl[p].cx,pl[p].cy,LightGreen);
+  SetColor(Black);
+  Circle(pl[p].cx,pl[p].cy,pl[p].r);
+  ClearDialogBox;
+  SetColor(LightGray);
+  OutTextXY(0, 0,'Use cursors to move pointer. (Num Lock on)   Esc aborts');
+  OutTextXY(0,10,'Enter to place planet center, + - change size of jumps.');
+  jump:=30;
+  x:=100; y:=100; PutImage(x,y,pointr.imagepointr^,XORPut);
+  cxorig:=pl[p].cx; cyorig:=pl[p].cy;   {save them as they may change later}
+  Repeat    {loop until Esc or legal position}
+    Repeat
+      Repeat c:=ReadKey; Until (c='4') or (c='8') or (c='6') or (c='2') or
+                               (c='+') or (c='-') or (c=Return) or (c=Esc);
+      moveit:=false; xold:=x; yold:=y;
+      InterpKey(c,x,y,pointr.coffx,pointr.coffy,pointr.r,jump,moveit);
+      if moveit then
+        begin
+          PutImage(xold,yold,pointr.imagepointr^,XORPut);
+          PutImage(x,y,pointr.imagepointr^,XORPut);
+          moveit:=false;
+        end;
+    Until (c=Return) or (c=Esc);
+    legal:=true;
+    if c<>Esc then    {ok, RETURN pressed}
+      begin
+        pl[p].cx:=-1000; pl[p].cy:=-1000;  {so it won't collide with itself!}
+        for i:=1 to np do   {any collisions with other planets?}
+          if sqrt(sqr(x-pl[i].cx)+sqr(y-pl[i].cy))<=pl[i].r+pl[p].r+2*bhr then
+            legal:=false;
+        for i:=1 to 2 do    {any collisions with other ships?}
+          if sqrt(sqr(x-ship[i].imagex-ship[i].coffx)+
+                  sqr(y-ship[i].imagey-ship[i].coffy))<=pl[p].r+ship[i].r+bhr
+             then legal:=false;
+      end;
+    if not legal then      {oops!}
+      begin
+        SetPalette(Black,White);
+        SetFillStyle(SolidFill,Black);
+        Bar(0,20,screen.ex,screen.sy-2);
+        delay(100);
+        SetPalette(Black,Black);
+        SetColor(LightGray);
+        OutTextXY(0,20,'Illegal planet position!');
+      end;
+  Until legal;
+  pl[p].cx:=x; pl[p].cy:=y; {put it there}
+  if c=Esc then             {abort and restore}
+    begin
+      pl[p].cx:=cxorig;
+      pl[p].cy:=cyorig;
+    end;
+  DrawSetUp;                {redraw screen}
+end;
+
+Procedure MakePlanet;       {make a planet given center and radius}
+var c : char;
+    i,p,jump : integer;
+    x,y,xold,yold : longint;
+    moveit,legal : boolean;
+begin
+  ClearDialogBox;
+  if np=9 then       {too many planets already!}
+    begin
+      OutTextXY(0,0,'Can not make any more planets!');
+      delay(2000);
+      exit;
+    end;
+  OutTextXY(0, 0,'Use cursors to move pointer. (Num Lock on)   Esc aborts');
+  OutTextXY(0,10,'Enter to place center, + and - to change size of jumps.');
+  jump:=30;
+  x:=100; y:=100; PutImage(x,y,pointr.imagepointr^,XORPut);
+  Repeat   {loop until a legal center is picked or Esc}
+    Repeat
+      Repeat c:=ReadKey; Until (c='4') or (c='8') or (c='6') or (c='2') or
+                               (c='+') or (c='-') or (c=Return) or (c=Esc);
+      moveit:=false; xold:=x; yold:=y;
+      InterpKey(c,x,y,pointr.coffx,pointr.coffy,pointr.r,jump,moveit);
+      if moveit then
+        begin
+          PutImage(xold,yold,pointr.imagepointr^,XORPut);
+          PutImage(x,y,pointr.imagepointr^,XORPut);
+          moveit:=false;
+        end;
+    Until (c=Return) or (c=Esc);
+    if c=Esc then exit;
+    legal:=true;
+    for i:=1 to np do    {any collisions with planets?}
+      if sqrt(sqr(x-pl[i].cx)+sqr(y-pl[i].cy))<=pl[i].r+2*bhr then
+        legal:=false;
+    for i:=1 to 2 do     {any collisions with ships?}
+      if sqrt(sqr(x-ship[i].imagex-ship[i].coffx)+
+              sqr(y-ship[i].imagey-ship[i].coffy))<=ship[i].r+bhr
+         then legal:=false;
+    if not legal then                    {uh oh!}
+      begin
+        SetPalette(Black,White);
+        SetFillStyle(SolidFill,Black);
+        Bar(0,20,screen.ex,screen.sy-2);
+        delay(100);
+        SetPalette(Black,Black);
+        SetColor(LightGray);
+        OutTextXY(0,20,'Illegal planet center!');
+      end;
+  Until legal;
+  p:=np+1; pl[p].cx:=x; pl[p].cy:=y;   {ok, store the info}
+  ClearDialogBox;
+  OutTextXY(0, 0,'Use cursors to move pointer. (Num Lock on)   Esc aborts');
+  OutTextXY(0,10,'Enter to radius, + and - change size of jumps.');
+  jump:=30;
+  Repeat     {loop until a legal radius is entered or Esc}
+    Repeat
+      Repeat c:=ReadKey; Until (c='4') or (c='8') or (c='6') or (c='2') or
+                               (c='+') or (c='-') or (c=Return) or (c=Esc);
+      moveit:=false; xold:=x; yold:=y;
+      InterpKey(c,x,y,pointr.coffx,pointr.coffy,pointr.r,jump,moveit);
+      if moveit then
+        begin
+          PutImage(xold,yold,pointr.imagepointr^,XORPut);
+          PutImage(x,y,pointr.imagepointr^,XORPut);
+          moveit:=false;
+        end;
+    Until (c=Return) or (c=Esc);
+    if c=Esc then exit;
+    legal:=true;
+    pl[p].r:=round(sqrt(sqr(x-pl[p].cx)+sqr(y-pl[p].cy))); {find radius}
+    for i:=1 to np do    {planet collisions?}
+      if sqrt(sqr(x-pl[i].cx)+sqr(y-pl[i].cy))<=pl[p].r+pl[i].r+2*bhr then
+        legal:=false;
+    for i:=1 to 2 do     {ship collisions?}
+      if sqrt(sqr(x-ship[i].imagex-ship[i].coffx)+
+              sqr(y-ship[i].imagey-ship[i].coffy))<=pl[p].r+ship[i].r+bhr
+         then legal:=false;
+    if not legal then    {oh no!}
+      begin
+        SetPalette(Black,White);
+        SetFillStyle(SolidFill,Black);
+        Bar(0,20,screen.ex,screen.sy-2);
+        delay(100);
+        SetPalette(Black,Black);
+        SetColor(LightGray);
+        OutTextXY(0,20,'Illegal planet radius!');
+      end;
+  Until legal;
+  PutImage(x,y,pointr.imagepointr^,XORPut); {kill the pointer}
+  Inc(np);    {actually add the new planet info}
+  pl[p].d:=1.0; pl[p].GM:=G*2*pi*sqr(pl[p].r)*1.0; {initialize it}
+  SetColor(color[1]);                      {draw it}
+  Circle(pl[p].cx,pl[p].cy,pl[p].r);
+  SetFillStyle(SolidFill,color[1]);
+  FloodFill(pl[p].cx,pl[p].cy,color[1]);
+end;
+
+Procedure ChangePlanet;   {change density [color] of a planet}
+var c : char;               {will not change black holes}
+    i,p,jump : integer;
+    x,y,xold,yold,minr,t : longint;
+    moveit,legal : boolean;
+begin
+  ClearDialogBox;
+  legal:=false;
+  if np>0 then             {see if any non-black holes exist}
+    for i:=1 to np do
+      if pl[i].r<>0 then legal:=true;
+  if (np=0) or (not legal) then   {sorry!}
+    begin
+      OutTextXY(0,0,'No planets to change!');
+      delay(2000);
+      exit;
+    end;
+  OutTextXY(0, 0,'Use cursors to move pointer. (Num Lock on)   Esc aborts');
+  OutTextXY(0,10,'Enter to pick planet, + and - to change size of jumps.');
+  jump:=30;
+  x:=100; y:=100; PutImage(x,y,pointr.imagepointr^,XORPut);
+  Repeat   {repeat until RETURN or Esc}
+    Repeat c:=ReadKey; Until (c='4') or (c='8') or (c='6') or (c='2') or
+                             (c='+') or (c='-') or (c=Return) or (c=Esc);
+    moveit:=false; xold:=x; yold:=y;
+    InterpKey(c,x,y,pointr.coffx,pointr.coffy,pointr.r,jump,moveit);
+    if moveit then
+      begin
+        PutImage(xold,yold,pointr.imagepointr^,XORPut);
+        PutImage(x,y,pointr.imagepointr^,XORPut);
+        moveit:=false;
+      end;
+  Until (c=Return) or (c=Esc);
+  PutImage(x,y,pointr.imagepointr^,XORPut);  {kill the pointer}
+  if c=Esc then exit;
+  p:=0; minr:=trunc(sqrt(sqr(screen.lx)+sqr(screen.ly)));
+  for i:=1 to np do   {find closest non-black hole planet}
+    begin
+      t:=trunc(sqrt(sqr(x-pl[i].cx)+sqr(y-pl[i].cy)));
+      if (t<minr) and (pl[i].r<>0) then begin minr:=t; p:=i; end;
+    end;
+  ClearDialogBox;
+  OutTextXY(0, 0,'Change to: 1. Red   2. Green   3. Blue    Esc aborts');
+  OutTextXY(0,10,'Option: ');    {get a density}
+  Repeat c:=ReadKey; Until (c='1') or (c='2') or (c='3') or (c=Esc);
+  if c=Esc then exit;
+  i:=Ord(c)-48;
+  pl[p].d:=(i+1)/2.0;       {new density}
+  SetColor(color[i]);       {redraw}
+  Circle(pl[p].cx,pl[p].cy,pl[p].r);
+  SetFillStyle(SolidFill,color[i]);
+  FloodFill(pl[p].cx,pl[p].cy,color[i]);
+end;
+
+Procedure DeletePlanet;   {kill a planet/black hole}
+var c : char;
+    i,p,jump : integer;
+    x,y,xold,yold,minr,t : longint;
+    moveit : boolean;
+begin
+  ClearDialogBox;
+  if np=0 then    {nobody there!}
+    begin
+      OutTextXY(0,0,'No planets to delete!');
+      delay(2000);
+      exit;
+    end;
+  OutTextXY(0, 0,'Use cursors to move pointer. (Num Lock on)   Esc aborts');
+  OutTextXY(0,10,'Enter to pick planet, + and - to change size of jumps.');
+  jump:=30;
+  x:=100; y:=100; PutImage(x,y,pointr.imagepointr^,XORPut);
+  Repeat
+    Repeat c:=ReadKey; Until (c='4') or (c='8') or (c='6') or (c='2') or
+                             (c='+') or (c='-') or (c=Return) or (c=Esc);
+    moveit:=false; xold:=x; yold:=y;
+    InterpKey(c,x,y,pointr.coffx,pointr.coffy,pointr.r,jump,moveit);
+    if moveit then
+      begin
+        PutImage(xold,yold,pointr.imagepointr^,XORPut);
+        PutImage(x,y,pointr.imagepointr^,XORPut);
+        moveit:=false;
+      end;
+  Until (c=Return) or (c=Esc);
+  PutImage(x,y,pointr.imagepointr^,XORPut);
+  if c=Esc then exit;
+  p:=0; minr:=trunc(sqrt(sqr(screen.lx)+sqr(screen.ly)));
+  for i:=1 to np do  {find the closest planet/black hole}
+    begin
+      t:=trunc(sqrt(sqr(x-pl[i].cx)+sqr(y-pl[i].cy)));
+      if t<minr then begin minr:=t; p:=i; end;
+    end;
+  if p<9 then           {move everybody above the one deleted one down}
+    for i:=p to np-1 do
+      pl[i]:=pl[i+1];
+  Dec(np);         {delete}
+  DrawSetup;       {redraw}
+end;
+
+Procedure Changes;   {changes menu}
+var option : char;
+begin
+  Repeat
+    ClearDialogBox;
+    SetColor(LightGray);
+    OutTextXY(0, 0,'1. Move ship       2. Move planet    3. Make planet');
+    OutTextXY(0,10,'4. Change planet   5. Delete planet     Esc quits menu');
+    OutTextXY(0,20,'Option: ');
+    option:=ReadKey;
+    Case option of
+      '1' : MoveShip;
+      '2' : MovePlanet;
+      '3' : MakePlanet;
+      '4' : ChangePlanet;
+      '5' : DeletePlanet;
+    end;
+  Until option=Esc;
+end;
+
+Procedure MainMenu;   {main menu}
+var option : char;
+begin
+  Repeat
+    ClearDialogBox;
+    SetColor(LightGray);
+    OutTextXY(0,0,'1. Playing the game   2. Options   3. Changes   4. Quit');
+    OutTextXY(0,10,'Option: ');
+    option:=ReadKey;
+    Case option of
+      '1' : PlayingtheGame;
+      '2' : Options;
+      '3' : Changes;
+    end;
+  Until option='4';
+end;
+
+Procedure Title;   {title screen and credits}
+begin
+  SetTextStyle(SansSerifFont,HorizDir,9);
+  OutTextXY(25,100,'Gravity Wars');
+  SetTextStyle(SansSerifFont,HorizDir,2);
+  OutTextXY(300,300,'by Sohrab Ismail-Beigi');
+  delay(3000);
+  SetTextStyle(DefaultFont,HorizDir,0);
+end;
+
+BEGIN
+  Init;
+  Title;
+  RandomSetup;
+  DrawSetup;
+  MainMenu;
+  Finish;
+END.
+  $Log$
+  Revision 1.1  2001-05-03 21:39:33  peter
+    * moved to own module
+
+  Revision 1.2  2000/07/13 11:33:08  michael
+  + removed logs
+ 
+}

+ 348 - 0
demo/graph/mandel.pp

@@ -0,0 +1,348 @@
+{
+    $Id$
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 1993-98 by Gernot Tenchio
+
+    Mandelbrot Example using the Graph unit
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+program mandel;
+
+{
+  Mandelbrot example using the graph unit.
+
+  Note: For linux you need to run this program as root !!
+}
+
+uses
+  dos,Graph;
+
+{
+const
+  shift:byte=12;
+}
+
+var
+  SearchPoint,ActualPoint,NextPoint       : PointType;
+  LastColor                              : longint;
+  Gd,Gm                                  : smallint;
+  Max_Color,Max_X_Width,
+  Max_Y_Width,Y_Width                    : word;
+  Y1,Y2,X1,X2,Dy,Dx                      : Real;
+  Zm                                     : Integer;
+  SymetricCase                                   : boolean;
+  LineY                                  : array [0..600] OF BYTE;
+  LineX                                  : array [0..100,0..600] OF INTEGER;
+const
+    SX : array [0..7] OF SHORTINT=(-1, 0, 1, 1, 1, 0,-1,-1);
+    SY : array [0..7] OF SHORTINT=(-1,-1,-1, 0, 1, 1, 1, 0);
+type
+    arrayType = array[1..50] of integer;
+
+{------------------------------------------------------------------------------}
+  function ColorsEqual(c1, c2 : longint) : boolean;
+    begin
+       ColorsEqual:=((GetMaxColor=$FF) and ((c1 and $FF)=(c2 and $FF))) or
+         ((GetMaxColor=$7FFF) and ((c1 and $F8F8F8)=(c2 and $F8F8F8))) or
+         ((GetMaxColor=$FFFF) and ((c1 and $F8FCF8)=(c2 and $F8FCF8))) or
+         ((GetMaxColor>$10000) and ((c1 and $FFFFFF)=(c2 and $FFFFFF)));
+    end;
+
+{------------------------------------------------------------------------------}
+function CalcMandel(Point:PointType; z:integer) : Longint ;
+var
+  x,y,xq,yq,Cx,Cy : real ;
+begin
+  Cy:=y2 + dy*Point.y ;
+  Cx:=x2 + dx*Point.x ;
+  X:=-Cx ; Y:=-Cy ;
+  repeat
+    xq:=x * x;
+    yq:=y * y  ;
+    y :=x * y;
+    y :=y + y - cy;
+    x :=xq - yq - cx ;
+    z :=z -1;
+  until (Z=0) or (Xq + Yq > 4 );
+  if Z=0 Then
+    CalcMandel:=(blue and $FFFFFF)
+  else
+    CalcMandel:={DefaultColors[}(z mod Max_Color) + 1 {]};
+end;
+
+{-----------------------------------------------------------------------------}
+procedure Partition(var A : arrayType; First, Last : Byte);
+var
+  Right,Left : byte ;
+  V,Temp     : integer;
+begin
+    V := A[(First + Last) SHR 1];
+    Right := First;
+    Left := Last;
+    repeat
+      while (A[Right] < V) do
+        inc(Right);
+      while (A[Left] > V) do
+        Dec(Left);
+      if (Right <= Left) then
+        begin
+          Temp:=A[Left];
+          A[Left]:=A[Right];
+          A[Right]:=Temp;
+          Right:=Right+1;
+          Left:=Left-1;
+        end;
+    until Right > Left;
+    if (First < Left) then
+      Partition(A, First, Left);
+    if (Right < Last) then
+      Partition(A, Right, Last)
+end;
+
+{-----------------------------------------------------------------------------}
+function BlackScan(var NextPoint:PointType) : boolean;
+begin
+  BlackScan:=true;
+  repeat
+    if NextPoint.X=Max_X_Width then
+      begin
+        if NextPoint.Y < Y_Width then
+          begin
+            NextPoint.X:=0 ;
+            NextPoint.Y:=NextPoint.Y+1;
+          end
+        else
+          begin
+            BlackScan:=false;
+            exit;
+          end ; { IF }
+      end ; { IF }
+    NextPoint.X:=NextPoint.X+1;
+  until GetPixel(NextPoint.X,NextPoint.Y)=0;
+end ;
+
+{------------------------------------------------------------------------------}
+procedure Fill(Ymin,Ymax,LastColor:integer);
+var
+ P1,P3,P4,P    : integer ;
+ Len,P2        : byte ;
+ Darray        : arraytype;
+begin
+  SetColor(LastColor);
+  for P1:=Ymin+1 to Ymax-1 do
+   begin
+     Len:=LineY[P1] ;
+     if Len >= 2 then
+      begin
+        for P2:=1 to Len do
+          Darray[P2]:=LineX[P2,P1] ;
+        if Len > 2 then
+          Partition(Darray,1,len);
+        P2:=1;
+        repeat
+          P3:= Darray[P2] ; P4:= Darray[P2 + 1];
+          if P3 <> P4 then
+           begin
+             line ( P3 , P1 , P4 , P1) ;
+             if SymetricCase then
+              begin
+                P:=Max_Y_Width-P1;
+                line ( P3 , P , P4 , P ) ;
+              end;
+           end; { IF }
+          P2:=P2+2;
+        until P2 >= Len ;
+      end; { IF }
+   end; { FOR }
+end;
+
+{-----------------------------------------------------------------------------}
+Function NewPosition(Last:Byte):Byte;
+begin
+  newposition:=(((last+1) and 254)+6) and 7;
+end;
+
+{-----------------------------------------------------------------------------}
+procedure CalcBounds;
+var
+  lastOperation,KK,
+  Position                     : Byte ;
+  foundcolor                   : longint;
+  Start,Found,NotFound         : boolean ;
+  MerkY,Ymax                   : Integer ;
+label
+  L;
+begin
+  repeat
+    FillChar(LineY,SizeOf(LineY),0) ;
+    ActualPoint:=NextPoint;
+    LastColor:=CalcMandel(NextPoint,Zm) ;
+    putpixel (ActualPoint.X,ActualPoint.Y,LastColor);
+    if SymetricCase then
+      putpixel (ActualPoint.X,Max_Y_Width-ActualPoint.Y,LastColor) ;
+    Ymax:=NextPoint.Y ;
+    MerkY:=NextPoint.Y ;
+    NotFound:=false ;
+    Start:=false ;
+    LastOperation:=4 ;
+    repeat
+      Found:=false ;
+      KK:=0 ;
+      Position:=NewPosition(LastOperation);
+      repeat
+        LastOperation:=(Position+KK) and 7 ;
+        SearchPoint.X:=ActualPoint.X+Sx[LastOperation];
+        SearchPoint.Y:=ActualPoint.Y+Sy[LastOperation];
+        if ((SearchPoint.X < 0) or
+            (SearchPoint.X > Max_X_Width) or
+            (SearchPoint.Y < NextPoint.Y) or
+            (SearchPoint.Y > Y_Width)) then
+          goto L;
+        if (SearchPoint.X=NextPoint.X) and (SearchPoint.Y=NextPoint.Y) then
+          begin
+            Start:=true ;
+            Found:=true ;
+          end
+        else
+          begin
+            FoundColor:=GetPixel(SearchPoint.X,SearchPoint.Y) ;
+            if FoundColor = 0 then
+              begin
+                FoundColor:= CalcMandel (SearchPoint,Zm) ;
+                Putpixel (SearchPoint.X,SearchPoint.Y,FoundColor) ;
+                if SymetricCase then
+                  PutPixel (SearchPoint.X,Max_Y_Width-SearchPoint.Y,FoundColor) ;
+              end ;
+            if ColorsEqual(FoundColor,LastColor) then
+              begin
+                if ActualPoint.Y <> SearchPoint.Y then
+                  begin
+                    if SearchPoint.Y = MerkY then
+                      LineY[ActualPoint.Y]:=LineY[ActualPoint.Y]-1;
+                    MerkY:= ActualPoint.Y ;
+                    LineY[SearchPoint.Y]:=LineY[SearchPoint.Y]+1;
+                  end ;
+                LineX[LineY[SearchPoint.Y],SearchPoint.Y]:=SearchPoint.X ;
+                if SearchPoint.Y > Ymax then Ymax:= SearchPoint.Y ;
+                  Found:=true ;
+                ActualPoint:=SearchPoint ;
+              end;
+L:
+            KK:=KK+1;
+            if KK > 8 then
+              begin
+                Start:=true ;
+                NotFound:=true ;
+              end;
+          end;
+      until Found or (KK > 8);
+    until Start ;
+    if not NotFound then
+      Fill(NextPoint.Y,Ymax,LastColor) ;
+  until not BlackScan(NextPoint);
+end ;
+
+
+{------------------------------------------------------------------------------
+                              MAINROUTINE
+------------------------------------------------------------------------------}
+  var
+     error,dummy : smallint;
+
+var i,neededtime,starttime : longint;
+  hour, minute, second, sec100 : word;
+
+const
+  count : longint = 1;
+  gmdefault = m640x480;
+
+begin
+  gm:=$ffff;
+  if paramcount>0 then
+    begin
+       val(paramstr(1),gm,error);
+       if error<>0 then
+         gm:=gmdefault;
+{$ifdef go32v2}
+       if paramcount>1 then
+         begin
+           Val(paramstr(2),count,error);
+           if error<>0 then
+             count:=1;
+         end;
+       if paramcount>2 then
+         UseLFB:=true;
+       if paramcount>3 then
+         UseNoSelector:=true;
+{$endif go32v2}
+    end;
+  gd:=d8bit;
+  if gm=-1 then
+    GetModeRange(gd,dummy,gm);
+  GetTime(hour, minute, second, sec100);
+  starttime:=((hour*60+minute)*60+second)*100+sec100;
+  InitGraph(gd,gm,'');
+  if GraphResult <> grOk then
+    begin
+      Writeln('Graph driver ',gd,' graph mode ',gm,' not supported');
+      Halt(1);
+    end;
+  for i:=1 to count do
+    begin
+      Max_X_Width:=GetMaxX;
+      Max_y_Width:=GetMaxY;
+      Max_Color:=GetMaxColor-1;
+      if Max_Color>255 then
+        Max_Color:=255;
+      ClearViewPort;
+
+      x1:=-0.9;
+      x2:= 2.2;
+      y1:= 1.25;
+      y2:=-1.25;
+      zm:=90;
+      dx:=(x1 - x2) / Max_X_Width ;
+      dy:=(y1 - y2) / Max_Y_Width ;
+      if abs(y1) = abs(y2) then
+       begin
+         SymetricCase:=true;
+         Y_Width:=Max_Y_Width shr 1
+       end
+      else
+       begin
+         SymetricCase:=false;
+         Y_Width:=Max_Y_Width;
+       end;
+      NextPoint.X:=0;
+      NextPoint.Y:=0;
+      LastColor:=CalcMandel(SearchPoint,zm);
+      CalcBounds ;
+    end;
+  GetTime(hour, minute, second, sec100);
+  neededtime:=((hour*60+minute)*60+second)*100+sec100-starttime;
+{$ifndef fpc_profile}
+  readln;
+{$endif fpc_profile}
+  CloseGraph;
+  Writeln('Mandel took ',Real(neededtime)/100/count:0:3,' secs to generate mandel graph');
+  Writeln('With graph driver ',gd,' and graph mode ',gm);
+end.
+{
+  $Log$
+  Revision 1.1  2001-05-03 21:39:33  peter
+    * moved to own module
+
+  Revision 1.3  2001/04/25 22:45:41  peter
+    * regenerated
+
+  Revision 1.2  2000/07/13 11:33:08  michael
+  + removed logs
+
+}

+ 486 - 0
demo/graph/maze.pp

@@ -0,0 +1,486 @@
+{A demo with some interesting algoritms, and for Graph.
+
+The sources for this game was found on a site that claims to only have
+PD stuff with the below header(which was only reindented), and the webmaster
+said that everything he published was sent to him with that purpose. We tried
+to contact the authors mentioned below via mail over internet, but that
+failed. If there is somebody that claims authorship of these programs,
+please mail [email protected], and the sources will be removed from our
+websites.
+
+------------------------------------------------------------------------
+
+ORIGINAL Header:
+
+created by Randy Ding July 16,1983   <April 21,1992>
+
+Very small FPC fixes by Marco van de Voort (EgaHi to vgahi), and tried
+setting the maze dimensions maxx and maxy to a bigger size.
+Won't work, you'll have to update all vars to al least word to increase the
+complexity of the grid further. I didn't do it, since 200x200 is already
+unreadable to me.
+
+Don't forget the BGIPATH of InitGraph.
+}
+
+{$R-}   { range checking }
+
+program makemaze;
+
+uses
+  crt, graph;
+
+const
+  screenwidth   = 640;
+  screenheight  = 480;
+  minblockwidth = 2;
+  maxx = 200;   { BP: [3 * maxx * maxy] must be less than 65520 (memory segment) }
+                { FPC: Normally no problem. ( even if you'd use 1600x1200x3< 6MB)}
+  maxy = 200;   { here maxx/maxy about equil to screenwidth/screenheight }
+  flistsize = maxx*maxy DIV 2; { flist size (fnum max, about 1/3 of maxx * maxy) }
+
+  background = black;
+  gridcolor  = green;
+  solvecolor = white;
+
+  rightdir = $01;
+  updir    = $02;
+  leftdir  = $04;
+  downdir  = $08;
+
+  unused   = $00;    { cell types used as flag bits }
+  frontier = $10;
+{  reserved = $20; }
+  tree     = $30;
+
+
+type
+  frec = record
+          column, row : byte;
+         end;
+  farr = array [1..flistsize] of frec;
+
+  cellrec = record
+              point : word;  { pointer to flist record }
+              flags : byte;
+            end;
+  cellarr = array [1..maxx,1..maxy] of cellrec;
+
+  {
+    one byte per cell, flag bits...
+
+    0: right, 1 = barrier removed
+    1: top    "
+    2: left   "
+    3: bottom "
+    5,4: 0,0 = unused cell type
+         0,1 = frontier "
+         1,1 = tree     "
+         1,0 = reserved "
+    6: (not used)
+    7: solve path, 1 = this cell part of solve path
+  }
+
+
+var
+  flist     : farr;         { list of frontier cells in random order }
+  cell      : ^cellarr;      { pointers and flags, on heap }
+  fnum,
+  width,
+  height,
+  blockwidth,
+  halfblock,
+  maxrun    : word;
+  runset    : byte;
+  ch        : char;
+
+procedure initbgi;
+var
+  grdriver,
+  grmode,
+  errcode : integer;
+begin
+  grdriver := vga;
+  grmode   := vgahi;
+  initgraph(grdriver, grmode, 'd:\pp\bp\bgi');
+  errcode:= graphresult;
+  if errcode <> grok then
+  begin
+    CloseGraph;
+    writeln('Graphics error: ', grapherrormsg(errcode));
+    halt(1);
+  end;
+end;
+
+
+function adjust(var x, y : word; d : byte) : boolean;
+begin                              { take x,y to next cell in direction d }
+  case d of                        { returns false if new x,y is off grid }
+    rightdir:
+    begin
+      inc (x);
+      adjust:= x <= width;
+    end;
+
+    updir:
+    begin
+      dec (y);
+      adjust:= y > 0;
+    end;
+
+    leftdir:
+    begin
+      dec (x);
+      adjust:= x > 0;
+    end;
+
+    downdir:
+    begin
+      inc (y);
+      adjust:= y <= height;
+    end;
+  end;
+end;
+
+
+procedure remove(x, y : word);      { remove a frontier cell from flist }
+var
+  i : word; { done by moving last entry in flist into it's place }
+begin
+  i := cell^[x,y].point;          { old pointer }
+  with flist[fnum] do
+    cell^[column,row].point := i;   { move pointer }
+  flist[i] := flist[fnum];        { move data }
+  dec(fnum);                    { one less to worry about }
+end;
+
+
+procedure add(x, y : word; d : byte);  { add a frontier cell to flist }
+var
+  i : byte;
+begin
+  i := cell^[x,y].flags;
+  case i and $30 of   { check cell type }
+    unused :
+    begin
+      cell^[x,y].flags := i or frontier;  { change to frontier cell }
+      inc(fnum);                        { have one more to worry about }
+      if fnum > flistsize then
+      begin     { flist overflow error! }
+        dispose(cell);  { clean up memory }
+        closegraph;
+        writeln('flist overflow! - To correct, increase "flistsize"');
+        write('hit return to halt program ');
+        readln;
+        halt(1);        { exit program }
+      end;
+      with flist[fnum] do
+      begin    { copy data into last entry of flist }
+        column := x;
+        row    := y;
+      end;
+      cell^[x,y].point := fnum; { make the pointer point to the new cell }
+      runset := runset or d;   { indicate that a cell in direction d was }
+    end;                      {    added to the flist }
+
+    frontier : runset := runset or d;     { allready in flist }
+  end;
+end;
+
+
+procedure addfront(x, y : word);    { change all unused cells around this }
+var                              {    base cell to frontier cells }
+  j, k : word;
+  d    : byte;
+begin
+  remove(x, y);       { first remove base cell from flist, it is now }
+  runset := 0;         {    part of the tree }
+  cell^[x,y].flags := cell^[x,y].flags or tree;   { change to tree cell }
+  d := $01;            { look in all four directions- $01,$02,$04,$08 }
+  while d <= $08 do
+  begin
+    j := x;
+    k := y;
+    if adjust(j, k, d) then
+      add(j, k, d);  { add only if still in bounds }
+    d := d shl 1;    { try next direction }
+  end;
+end;
+
+
+procedure remline(x, y : word; d : byte);  { erase line connecting two blocks }
+begin
+  setcolor(background);
+  x := (x - 1) * blockwidth;
+  y := (y - 1) * blockwidth;
+  case d of
+    rightdir : line (x + blockwidth, y + 1, x + blockwidth, y + blockwidth - 1);
+    updir    : line (x + 1, y, x + blockwidth - 1, y);
+    leftdir  : line (x, y + 1, x, y + blockwidth - 1);
+    downdir  : line (x + 1, y + blockwidth, x + blockwidth - 1, y + blockwidth);
+  end;
+end;
+
+
+{ erase line and update flags to indicate the barrier has been removed }
+procedure rembar(x, y : word; d : byte);
+var
+  d2 : byte;
+begin
+  remline(x, y, d);       { erase line }
+  cell^[x,y].flags := cell^[x,y].flags or d; { show barrier removed dir. d }
+  d2 := d shl 2;  { shift left twice to reverse direction }
+  if d2 > $08 then
+    d2 := d2 shr 4;  { wrap around }
+  if adjust(x, y, d) then  { do again from adjacent cell back to base cell }
+    cell^[x,y].flags := cell^[x,y].flags or d2;    { skip if out of bounds }
+end;
+
+
+function randomdir : byte;  { get a random direction }
+begin
+  case random(4) of
+    0 : randomdir := rightdir;
+    1 : randomdir := updir;
+    2 : randomdir := leftdir;
+    3 : randomdir := downdir;
+  end;
+end;
+
+
+procedure connect(x, y : word);    { connect this new branch to the tree }
+var                             {    in a random direction }
+  j, k  : word;
+  d     : byte;
+  found : boolean;
+begin
+  found := false;
+  while not found do
+  begin { loop until we find a tree cell to connect to }
+    j := x;
+    k := y;
+    d := randomdir;
+    if adjust(j, k, d) then
+      found := cell^[j,k].flags and $30 = tree;
+  end;
+  rembar(x, y, d);   { remove barrier connecting the cells }
+end;
+
+
+procedure branch(x, y : word);  { make a new branch of the tree }
+var
+  runnum : word;
+  d      : byte;
+begin
+  runnum := maxrun;      { max number of tree cells to add to a branch }
+  connect(x, y);        { first connect frontier cell to the tree }
+  addfront(x, y);       { convert neighboring unused cells to frontier }
+  dec(runnum);         { number of tree cells left to add to this branch }
+  while (runnum > 0) and (fnum > 0) and (runset > 0) do
+  begin
+    repeat
+      d := randomdir;
+    until d and runset > 0;  { pick random direction to known frontier }
+    rembar(x, y, d);          {    and make it part of the tree }
+    adjust(x, y, d);
+    addfront(x, y);      { then pick up the neighboring frontier cells }
+    dec(runnum);
+  end;
+end;
+
+
+procedure drawmaze;
+var
+  x, y, i : word;
+begin
+  setcolor(gridcolor);    { draw the grid }
+  y := height * blockwidth;
+  for i := 0 to width do
+  begin
+    x := i * blockwidth;
+    line(x, 0, x, y);
+  end;
+  x := width * blockwidth;
+  for i := 0 to height do
+  begin
+    y := i * blockwidth;
+    line (0, y, x, y);
+  end;
+  fillchar(cell^, sizeof(cell^), chr(0));    { zero flags }
+  fnum   := 0;   { number of frontier cells in flist }
+  runset := 0; { directions to known frontier cells from a base cell }
+  randomize;
+  x := random(width) + 1;   { pick random start cell }
+  y := random(height) + 1;
+  add(x, y, rightdir);       { direction ignored }
+  addfront(x, y);      { start with 1 tree cell and some frontier cells }
+  while (fnum > 0) do
+  with flist[random(fnum) + 1] do
+    branch(column, row);
+end;
+
+procedure dot(x, y, colr : word);
+begin
+  putpixel(blockwidth * x - halfblock, blockwidth * y - halfblock, colr);
+end;
+
+procedure solve(x, y, endx, endy : word);
+var
+  j, k : word;
+  d    : byte;
+begin
+  d := rightdir;  { starting from left side of maze going right }
+  while (x <> endx) or (y <> endy) do
+  begin
+    if d = $01 then
+      d := $08
+    else
+      d := d shr 1; { look right, hug right wall }
+    while cell^[x,y].flags and d = 0 do
+    begin { look for an opening }
+      d := d shl 1;                            { if no opening, turn left }
+      if d > $08 then
+        d := d shr 4;
+    end;
+    j := x;
+    k := y;
+    adjust(x, y, d);         { go in that direction }
+    with cell^[j,k] do
+    begin    { turn on dot, off if we were here before }
+      flags := ((((cell^[x,y].flags xor $80) xor flags) and $80) xor flags);
+      if flags and $80 <> 0 then
+        dot(j, k, solvecolor)
+      else
+        dot(j, k, background);
+    end;
+  end;
+  dot(endx, endy, solvecolor);    { dot last cell on }
+end;
+
+procedure mansolve (x,y,endx,endy: word);
+var
+  j, k : word;
+  d    : byte;
+  ch   : char;
+begin
+  ch := ' ';
+  while ((x <> endx) or (y <> endy)) and (ch <> 'X') and (ch <> #27) do
+  begin
+    dot(x, y, solvecolor);    { dot man on, show where we are in maze }
+    ch := upcase(readkey);
+    dot(x, y, background);    { dot man off after keypress }
+    d := 0;
+    case ch of
+      #0:
+      begin
+        ch := readkey;
+        case ch of
+          #72 : d := updir;
+          #75 : d := leftdir;
+          #77 : d := rightdir;
+          #80 : d := downdir;
+        end;
+      end;
+
+      'I' : d := updir;
+      'J' : d := leftdir;
+      'K' : d := rightdir;
+      'M' : d := downdir;
+    end;
+
+    if d > 0 then
+    begin
+      j := x;
+      k := y;    { move if no wall and still in bounds }
+      if (cell^[x,y].flags and d > 0) and adjust(j, k, d) then
+      begin
+        x := j;
+        y := k;
+      end;
+    end;
+  end;
+end;
+
+procedure solvemaze;
+var
+  x, y,
+  endx,
+  endy : word;
+begin
+  x := 1;                         { pick random start on left side wall }
+  y := random(height) + 1;
+  endx := width;                  { pick random end on right side wall }
+  endy := random(height) + 1;
+  remline(x, y, leftdir);         { show start and end by erasing line }
+  remline(endx, endy, rightdir);
+  mansolve(x, y, endx, endy);      { try it manually }
+  solve(x, y, endx, endy);         { show how when he gives up }
+  while keypressed do
+   readkey;
+  readkey;
+end;
+
+
+procedure getsize;
+var
+  j, k : real;
+begin
+  clrscr;
+  writeln('       Mind');
+  writeln('       Over');
+  writeln('       Maze');
+  writeln;
+  writeln('   by Randy Ding');
+  writeln;
+  writeln('Use I,J,K,M or arrow keys to walk thru maze,');
+  writeln('then hit X when you give up!');
+  repeat
+    writeln;
+    write('Maze size: ', minblockwidth, ' (hard) .. 95 (easy) ');
+    readln(blockwidth);
+  until (blockwidth >= minblockwidth) and (blockwidth < 96);
+  writeln;
+  write('Maximum branch length: 1 easy .. 50 harder, (0 unlimited) ');
+  readln(maxrun);
+  if maxrun <= 0 then
+    maxrun := 65535;  { infinite }
+  j := Real(screenwidth) / blockwidth;
+  k := Real(screenheight) / blockwidth;
+  if j = int(j) then
+    j := j - 1;
+  if k = int(k) then
+    k := k - 1;
+  width  := trunc(j);
+  height := trunc(k);
+  if (width > maxx) or (height > maxy) then
+  begin
+    width  := maxx;
+    height := maxy;
+  end;
+  halfblock := blockwidth div 2;
+end;
+
+begin
+  repeat
+    getsize;
+    initbgi;
+    new(cell);    { allocate this large array on heap }
+    drawmaze;
+    solvemaze;
+    dispose(cell);
+    closegraph;
+    while keypressed do
+      ch := readkey;
+    write ('another one? ');
+    ch := upcase (readkey);
+  until (ch = 'N') or (ch = #27);
+end.
+
+  $Log$
+  Revision 1.1  2001-05-03 21:39:33  peter
+    * moved to own module
+
+  Revision 1.2  2000/07/13 11:33:08  michael
+  + removed logs
+ 
+}

+ 690 - 0
demo/graph/quad.pp

@@ -0,0 +1,690 @@
+PROGRAM Quad;
+{A demo which loads some graphics etc. Nice. Don't forget to distribute
+quaddata.inc!
+
+The sources for this game was found on a site that claims to only have
+PD stuff with the below header(which was only reindented), and the webmaster
+said that everything he published was sent to him with that purpose. We tried
+to contact the authors mentioned below via mail over internet, but that
+failed. If there is somebody that claims authorship of these programs,
+please mail [email protected], and the sources will be removed from our
+websites.
+
+------------------------------------------------------------------------
+
+ORIGINAL Header:
+
+Programmed by: Justin Pierce
+Graphics by: Whitney Pierce
+Inspired by: Jos Dickman''s triple memory!
+-----
+
+Old version requires egavga.bgi. FPC doesn't require BGI's (VGA and VESA
+support are built in the Graph, others are ignored).}
+
+Uses Crt,Dos,Graph,
+      GameUnit;         {Supplied with FPC demoes package. Wrapper for
+                          mousesupport (via msmouse or api), and contains
+                          highscore routines}
+
+Const nox             = 10;
+      noy             = 8;
+      card_border     = red;
+      PicBufferSize   = 64000;  {Buffersize for deRLE'ed picture data}
+      ComprBufferSize = 20000;  {Buffer for diskread- RLE'ed data}
+      PicsFilename    = 'quaddata.dat';  {Name of picturesfile}
+      ScoreFileName   = 'quad.scr';
+
+Type
+    pByte           = ^Byte;                  {BufferTypes}
+    Card            = Record
+                       exposed: boolean;
+                       pic: byte;
+                      End;
+
+            {Assigns an enumeration to each picture}
+    PictureEnum= (zero,one,two,three,four,five,six,seven,eight,nine,colon,
+                  back,score,exit_b,score_b,chunk,p1,p2,p3,p4,p5,p6,p7,p8,
+                  p9,p10,p11,p12,p13,p14,p15,p16,p17,p18,p19,p20);
+
+            {A pictures definition;
+              x and y dimensions and offset in PicData buffer}
+
+    Picture = packed Record
+                start: longint;
+                x,y: byte;
+                End;
+
+    {All pictures. This array, and the data in PicData is all pic info.}
+    PictureArray= ARRAY[zero..p20] OF Picture;
+
+    selected = Record
+                 x,y: byte;
+                 pic: byte;
+                End;
+    time_record = Record
+                    o_hr,o_min,o_sec,o_sec100: word;
+                    hr,min,sec,sec100: word;
+                    a_sec,a_min: word;
+    End;
+
+Var b           : array[1..nox,1..noy] Of card;
+    Pics        : PictureArray;
+    PicData     : PByte;
+    s           : array[1..4] Of selected;
+    os          : byte;
+    turns       : integer;
+    off,ok,exit1: boolean;
+    opened      : byte;
+    bgidirec    : string;
+    time        : time_record;
+
+{
+Procedure fatal(fcall:String);
+Begin
+  textmode(CO80);
+  clrscr;
+  Writeln('A fatal error has occured');
+  Writeln('Error: ',fcall);
+  Writeln;
+  Write('Hit enter to halt program--');
+  readln;
+  halt;
+End;
+}
+
+Procedure ginit640x480x16(direc:String);
+
+Var grd,grmode: integer;
+Begin
+  closegraph;
+  grd := 9;{ detect;}
+  grmode := 2;{ m800x600x16;}
+  initgraph(grd,grmode,direc);
+  setgraphmode(2);
+End;
+
+Procedure clean_board;
+
+Var x,y: byte;
+Begin
+  y := 1;
+  Repeat
+    x := 1;
+    Repeat
+      b[x,y].pic := 0;
+      b[x,y].exposed := false;
+      inc(x);
+    Until x>nox;
+    inc(y);
+  Until y>noy
+End;
+
+Procedure showpic(xp,yp:integer; tp:pictureenum);
+
+Var x,y,x1,y1: byte;
+    tx: integer;
+Begin
+  x := pics[tp].x; {mb[tp.start];}
+  y := pics[tp].y; {mb[tp.start+1];}
+  y1 := 1;
+  tx := 0;
+  Repeat
+    x1 := 1;
+    Repeat
+      putpixel(xp+(x1-1),yp+(y1-1),picdata[pics[tp].start-1+tx]);
+      inc(x1);
+      inc(tx);
+    Until x1>x;
+    inc(y1);
+  Until y1>y;
+End;
+
+Procedure NumberOutput(X,Y,Number:LONGINT;RightY:BOOLEAN);
+
+Var num: string;
+    plc: byte;
+
+Begin
+  str(number,num);
+  If length(num)=1 Then
+   insert('0',num,0);
+  IF RightY THEN
+   dec (x,length(num)*11);
+  plc := 1;
+  Repeat
+   IF (Num[plc]>CHR(47)) AND (Num[plc]<CHR(58)) THEN
+    showpic(((plc-1)*11)+X,Y,pictureenum(ORD(Zero)+ORD(Num[plc])-48));
+   inc(plc);
+  Until plc>length(num);
+End;
+
+Procedure update_secs;
+
+Begin
+ showpic(605,453,colon);
+ NumberOutput(615,453,time.a_sec,FALSE);
+End;
+
+Procedure showturn(x,y:integer);
+
+Begin
+  hidemouse;
+  If (x=0) And (y=0) Then
+   NumberOutput(4,453,Turns,FALSE)
+  ELSE
+   NumberOutput(x,y,Turns,FALSE);
+  showmouse;
+End;
+
+Procedure get_original_time;
+Begin
+  With time Do
+    Begin
+      a_sec := 0;
+      a_min := 0;
+      gettime(o_hr,o_min,o_sec,o_sec100);
+      gettime(hr,min,sec,sec100);
+    End;
+End;
+
+Procedure update_time(ForcedUpdate:BOOLEAN);
+Begin
+  With time Do
+    Begin
+      gettime(hr,min,sec,sec100);
+
+      If sec<>o_sec Then
+        Begin
+          inc(a_sec);
+          If a_sec<=60 Then update_secs;
+        End;
+      If a_sec>60 Then
+        Begin
+          a_sec := 0;
+          inc(a_min);
+          ForcedUpdate:=TRUE;
+        End;
+      IF ForcedUpdate THEN
+       BEGIN
+        Update_secs;
+        showpic(606,453,colon);
+        NumberOutput(606,453,time.a_min,TRUE);
+       END;
+      o_hr := hr;
+      o_min := min;
+      o_sec := sec;
+      o_sec100 := sec;
+    End;
+End;
+
+
+Procedure makecard(x,y:byte);
+
+Var xp,yp: integer;
+Begin
+  hidemouse;
+  xp := ((x-1)*63);
+  yp := ((y-1)*56);
+  setcolor(card_border);
+  setfillstyle(1,0);
+  bar(xp+1,yp+1,xp+62,yp+55);
+  rectangle(xp,yp,xp+63,yp+56);
+  If b[x,y].exposed=false Then
+    Begin
+      showpic(xp+1,yp+1,back);
+    End;
+  showmouse;
+  If b[x,y].exposed=true Then
+    Begin
+      hidemouse;
+      showpic(xp+7,yp+4,pictureenum(ORD(b[x,y].pic)+ORD(p1)-1));
+      showmouse;
+    End;
+End;
+
+Function used(pic:byte): byte;
+
+Var cx,cy,u: byte;
+Begin
+  used := 0;
+  u := 0;
+  cy := 1;
+  Repeat
+    cx := 1;
+    Repeat
+      If b[cx,cy].pic=pic Then inc(u);
+      inc(cx);
+    Until cx>nox;
+    inc(cy);
+  Until cy>noy;
+  used := u;
+End;
+
+Procedure set_board;
+
+CONST Outstr=#219+#219+#219+#219+#219+#219+#219+#219+#219+#219+#219+#219+#219+
+             #219+#219+#219+#219+#219+#219+#219+#219+#219+#219+#219+#219+
+             #219+#219+#219+#219;
+
+Var cx,cy,pic: byte;
+Begin
+  setcolor(0);
+  outtextxy(0,470,OutStr);
+  setcolor(green);
+  outtextxy(0,470,'Dealing board, please wait...');
+  Delay(1000);
+  cy := 1;
+  Repeat
+    cx := 1;
+    Repeat
+      Repeat
+        pic := random(20)+1;
+      Until used(pic)<4;
+      b[cx,cy].pic := pic;
+      makecard(cx,cy);
+      inc(cx);
+    Until cx>nox;
+    inc(cy);
+  Until cy>noy;
+  setcolor(0);
+  outtextxy(0,470,OutStr);
+End;
+
+Procedure fire_works;
+
+Const
+  nof = 30;
+
+Type
+  fires = Record
+            x,y: Longint;
+            direct: longint;
+            speed: Longint;
+            explode: boolean;
+            color: byte;
+            oex: longint;
+End;
+
+Var fire: array[1..nof] Of fires;
+
+Procedure clean_fires;
+
+Var c: longint;
+Begin
+  c := 1;
+  Repeat
+    fire[c].direct := random(2)+1;
+    fire[c].color := random(15)+1;
+    fire[c].x := random(639);
+    fire[c].y := 479;
+    fire[c].explode := false;
+    fire[c].speed := random(20)+15;
+    fire[c].oex := 1;
+    inc(c);
+  Until c>nof;
+End;
+
+Procedure inact;
+
+Var c: longint;
+Begin
+  c := 1;
+  Repeat
+    If fire[c].explode=false Then
+      Begin
+        setcolor(fire[c].color);
+        circle(fire[c].x,fire[c].y,1);
+      End;
+
+    If (fire[c].explode=true) And (fire[c].oex<10) Then
+      Begin
+        setcolor(fire[c].color);
+        circle(fire[c].x,fire[c].y,fire[c].oex);
+        setcolor(random(15)+1);
+        circle(fire[c].x,fire[c].y,fire[c].oex-1);
+      End;
+
+    inc(c);
+  Until c>nof;
+
+  delay(75);
+  gotoxy(1,1);
+
+  c := 1;
+  Repeat
+    setcolor(0);
+    circle(fire[c].x,fire[c].y,1);
+
+    If (fire[c].explode=true) And (fire[c].oex<10) Then
+      Begin
+        circle(fire[c].x,fire[c].y,fire[c].oex);
+        circle(fire[c].x,fire[c].y,fire[c].oex-1);
+        inc(fire[c].oex);
+      End;
+
+    If fire[c].explode=false Then
+      Begin
+        dec(fire[c].speed,1);
+        dec(fire[c].y,fire[c].speed);
+        If fire[c].direct=1 Then inc(fire[c].x,2);
+        If fire[c].direct=2 Then dec(fire[c].x,2);
+        If fire[c].speed<=(-1*LONGINT(random(11))) Then
+         fire[c].explode := true;
+      End;
+
+    inc(c);
+  Until c>nof;
+  c := 1;
+End;
+
+Function exploded: boolean;
+
+Var c: longint;
+    m: boolean;
+Begin
+  c := 1;
+  m := true;
+  Repeat
+    If fire[c].oex<6 Then m := false;
+    inc(c);
+  Until (c>nof);
+  exploded := m;
+End;
+
+Begin
+  cleardevice;
+  Repeat
+    clean_fires;
+    Repeat
+      inact;
+    Until (exploded=true) Or (keypressed);
+  Until keypressed;
+End;
+
+Procedure win;
+
+Var m,s: string;
+    I,J   : LONGINT;
+
+Begin
+  hidemouse;
+  fire_works;
+  cleardevice;
+  closegraph;
+  textmode(co80+font8x8);
+  clrscr;
+  I:=SlipInScore(Turns);
+  GotoXY(1,23);
+  Writeln('Game Over, turns needed = ',Turns);
+  FOR J:=9 TO 22 DO
+   BEGIN
+    GotoXY(20,J);
+    Write(' ':38);
+   END;
+ IF I<>0 THEN
+  BEGIN
+   ShowHighScore;
+{$IFDEF USEGRAPHICS}
+   GrInputStr(S,20,21-I,16,12,10,FALSE,AlfaBeta);
+{$ELSE}
+   InputStr(S,20,21-I,10,FALSE,AlfaBeta);
+{$ENDIF}
+   IF Length(S)<12 THEN
+    BEGIN
+     str(time.a_min,m);
+     S:=S+'['+m+':';
+     str(time.a_sec,m);
+     S:=S+'m'+']';
+    END;
+   HighScore[I-1].Name:=S;
+  END;
+  ShowHighScore;
+  ginit640x480x16(bgidirec);
+  off := false;
+  clean_board;
+  set_board;
+  turns := 0;
+  showpic(0,450,score);
+  showpic(80,450,score_b);
+  showpic(150,450,exit_b);
+  showpic(569,450,score);
+  showturn(0,0);
+  exit1 := false;
+  get_original_time;
+  update_time(True);
+  SetMousePosition(0,0);
+  showmouse;
+End;
+
+Procedure show_scores;
+
+Var x,y,c: byte;
+Begin
+  hidemouse;
+
+  y := 1;
+  Repeat
+    x := 1;
+    showpic(x+135,(y-1)*21,score);
+    showpic(x,(y-1)*21,score);
+    showpic(x+204,(y-1)*21,score);
+    Repeat
+      showpic(((x-1)*10)+3,(y-1)*21,chunk);
+      inc(x);
+    Until x>20;
+    inc(y);
+  Until y>10;
+
+  c := 0;
+  Repeat
+    If HighScore[c].name<>'' Then
+      Begin
+        setcolor(white);
+        outtextxy(4,7+(c*21),HighScore[c].name);
+        turns := HighScore[c].Score;
+        showturn(211,3+(c*21));
+      End;
+    inc(c);
+  Until c>9;
+  turns := 0;
+  gotoxy(1,1);
+  readln;
+
+  off := false;
+  clean_board;
+  set_board;
+  turns := 0;
+  showpic(0,450,score);
+  showpic(80,450,score_b);
+  showpic(150,450,exit_b);
+  showpic(569,450,score);
+  showturn(0,0);
+  exit1 := false;
+  get_original_time;
+  update_time(True);
+  SetMousePosition(0,0);
+  showmouse;
+End;
+
+Procedure interpret;
+
+Var mpx,mpy: byte;
+    ms_mx,ms_my,ms_but : LONGINT;
+Begin
+  GetMouseState(ms_mx,ms_my,ms_but);
+  ms_mx:=ms_mx shr 1;;
+
+  If ms_but=0 Then off := false;
+
+  If ((ms_but AND 1)=1) And (off=false) Then
+    Begin
+      off := true;
+      mpx := ms_mx*2 Div 63;
+      mpy := (ms_my) Div 56;
+
+      If (ms_mx*2>=80) And (ms_mx*2<=129) And (ms_my>=450) And (ms_my<=466)
+         And (ok=true) Then show_scores;
+      If (ms_mx*2>=150) And (ms_mx*2<=199) And (ms_my>=450) And (ms_my<=466)
+        Then
+        Begin
+          exit1 := true;
+        End;
+
+      inc(mpx);
+      inc(mpy);
+      If (b[mpx,mpy].exposed=false) And (mpx>=1) And (mpy>=1) And (mpx<=10) And (mpy<=8)
+        Then
+        Begin
+          setfillstyle(1,0);
+          bar(80,450,130,466);
+          ok := false;
+          b[mpx,mpy].exposed := true;
+          makecard(mpx,mpy);
+          inc(os);
+          s[os].x := mpx;
+          s[os].y := mpy;
+          s[os].pic := b[mpx,mpy].pic;
+        End;
+    End;
+
+  If os=4 Then
+    Begin
+      inc(turns);
+      showturn(0,0);
+      os := 0;
+      delay(700);
+      inc(opened);
+      If Not((s[1].pic=s[2].pic) And (s[1].pic=s[3].pic) And (s[1].pic=s[4].pic)) Then
+        Begin
+          dec(opened);
+          b[s[1].x,s[1].y].exposed := false;
+          b[s[2].x,s[2].y].exposed := false;
+          b[s[3].x,s[3].y].exposed := false;
+          b[s[4].x,s[4].y].exposed := false;
+          makecard(s[1].x,s[1].y);
+          makecard(s[2].x,s[2].y);
+          makecard(s[3].x,s[3].y);
+          makecard(s[4].x,s[4].y);
+        End;
+      If opened=20 Then win;
+    End;
+
+  If NOT ok Then
+   update_time(FALSE);
+End;
+
+Procedure load_pics(PicBuf:PByte);
+{loads picture structures from disc}
+
+VAR  F           : File;
+     Buf1Ind,
+     I,J,K       : LONGINT;
+     TData       : PByte;
+
+Begin
+  GetMem(TData,ComprBufferSize);        { allocate buffer}
+  Assign(F,Picsfilename);             { Open file}
+  {$I-}
+  Reset(F,1);
+  {$I+}
+  If ioresult<>0 Then
+   BEGIN
+    TextMode(CO80);
+    Writeln('Fatal error, couldn''t find graphics data file quaddata.dat');
+    HALT;
+   END;
+
+  {Read the array with picture information; (X,Y dimensions and offset in
+          binary data)}
+  BlockRead(F,pics,SIZEOF(Picture)*(ORD(p20)-ORD(zero)+1),I);
+
+  {Read some slackspace which shouldn't be in the file ;-)}
+  blockread(F,TData[0],6,Buf1ind);
+
+  {Read the real, RLE'ed graphics data}
+  BlockRead(F,TData[0],ComprBufferSize,Buf1Ind);
+  Close(F);
+
+  {Expand the RLE data. Of each byte, the high nibble is the count-1, low
+    nibble is the value}
+
+  I:=0; J:=0;
+  REPEAT
+   K:=(TData[I] SHR 4) +1;
+   FillChar(PicBuf[J],K,TData [I] AND 15);
+   INC(J,K);
+   INC(I);
+  UNTIL I>=Buf1Ind;
+
+  {Release the temporary buffer (the compressed data isn't necesary anymore)}
+  Freemem(TData,ComprBufferSize);
+End;
+
+Procedure clean;
+
+VAR I : LONGINT;
+
+Begin
+  Randomize;                                    {Initialize random generator}
+  Negative:=TRUE;                               {Higher highscore is worse}
+  HighX:=20;   HighY:=9;                        {coordinates for highscores}
+
+  GetMem(PicData,PicBufferSize);                {Allocate room for pictures}
+  load_pics(PicData);                           {Load picture data from file}
+  FOR I:=0 TO 9 DO                              {Create default scores}
+   HighScore[I].Score:=-100*I;                  {Negative, because then the
+                                                  "highest" score is best}
+  LoadHighScore(ScoreFileName);                 {Try to load highscore file}
+  closegraph;
+  bgidirec := 'd:\prog\bp\bgi';
+  ginit640x480x16(bgidirec);
+  setcolor(card_border);
+  ok := true;
+  opened := 0;
+  os := 0;
+  s[1].x := 0;
+  s[2].x := 0;
+  s[3].x := 0;
+  off := false;
+  clean_board;
+  set_board;
+  turns := 0;
+  showpic(0,450,score);        showpic(80,450,score_b);
+  showpic(150,450,exit_b);     showpic(569,450,score);
+  showturn(0,0);
+  exit1 := false;
+  SetMousePosition(0,0);
+  get_original_time;
+  update_time(True);
+  showmouse;
+End;
+
+Begin
+
+  clean;
+  Repeat
+    interpret;
+  Until exit1=true;
+  closegraph;
+  textmode(co80);
+  Freemem(PicData,PicBufferSize);
+  clrscr;
+  SaveHighScore;
+  Writeln('Thanks for playing Quadruple Memory');
+  Writeln('Feel free to distribute this software.');
+  Writeln;
+  Writeln('Programmed by: Justin Pierce');
+  Writeln('Graphics by: Whitney Pierce');
+  Writeln('Inspired by: Jos Dickman''s triple memory!');
+  Writeln('FPC conversion and cleanup by Marco van de Voort');
+  Writeln;
+End.
+  $Log$
+  Revision 1.1  2001-05-03 21:39:33  peter
+    * moved to own module
+
+  Revision 1.2  2000/07/13 11:33:08  michael
+  + removed logs
+ 
+}

二進制
demo/graph/quaddata.dat


+ 560 - 0
demo/graph/samegame.pp

@@ -0,0 +1,560 @@
+{
+    $Id$
+
+    This program is both available in XTDFPC as in the FPC demoes.
+    Copyright (C) 1999 by Marco van de Voort
+
+    SameGame is a standard game in GNOME and KDE. I liked it, and I
+    automatically brainstormed how I would implement it.
+    It turned out to be really easy, and is basically only 100 lines or so,
+    the rest is scorekeeping, helptext, menu etc.
+
+    The game demonstrates some features of the MSMOUSE unit, and some of
+    the Crt and Graph units. (depending whether it is compiled with
+    UseGraphics or not)
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+PROGRAM SameGame;
+
+Uses Crt,Dos,
+{$IFDEF UseGraphics}
+ Graph,
+{$ENDIF}
+ GameUnit;
+
+CONST
+   {$IFDEF UseGraphics}
+        GrFieldX                          = 10; {X topleft of playfield}
+        GrFieldY                          = 70; {Y topleft of playfield}
+        ScalerX                           = 22; {ScalerX x Scaler y dots
+                                                  must be approx a square}
+        ScalerY                           = 20;
+   {$ENDIF}
+        FieldX                            = 10; {Top left playfield
+                                                 coordinates in squares(textmode)}
+        FieldY                            =  3; {Top left playfield coordinates}
+        PlayFieldXDimension               = 20; {Dimensions of playfield}
+        PlayFieldYDimension               = 15;
+   {$IFDEF UseGraphics}
+        RowDispl                          = 15;
+        MenuX                             = 480;
+        MenuY                             = 120;
+        grNewGameLine                     = 'NEW GAME';
+        grHelpLine                        = 'HELP';
+        grEndGame                         = 'END GAME';
+   {$ENDIF}
+
+
+       {Used colors. Colors[0..2] are the colors used on the playfield, Colors[3]
+          is the background and Colors[4] is the color used to mark the pieces}
+        Colors : ARRAY [0..4] OF LONGINT  = (White,Blue,Red,Black,LightMagenta);
+
+
+TYPE PlayFieldType=ARRAY[0..PlayFieldXDimension-1,0..PlayFieldYDimension-1] OF BYTE;
+
+{$IFDEF UseGraphics}
+PROCEDURE DisplayPlayField(CONST PlayField:PlayFieldType);
+{Screen routine, simply puts the array Playfield on screen.
+Both used for displaying the normal grid as the grid with a certain area marked}
+
+VAR X,Y : LONGINT;
+    LastOne,
+    NumbLast : LONGINT;
+
+BEGIN
+ HideMouse;
+ FOR Y:=0 TO PlayFieldYDimension-1 DO
+  BEGIN
+   X:=0;
+   REPEAT
+    LastOne:=PlayField[X,Y];
+    NumbLast:=X;
+    WHILE (PlayField[X,Y]=LastOne) AND (X<(PlayFieldXDimension-1))DO
+     INC(X);
+    SetFillStyle(SolidFill,Colors[LastOne]);
+    Bar(GrFieldX+NumbLast*ScalerX,GrFieldY+Y*ScalerY,GrFieldX+X*ScalerX-1,GrFieldY+(Y+1)*ScalerY-1);
+   UNTIL X>=(PlayFieldXDimension-1);
+  END;
+ ShowMouse;
+END;
+{$ELSE}
+
+PROCEDURE DisplayPlayField(CONST PlayField:PlayFieldType);
+{Screen routine, simply puts the array Playfield on screen.
+Both used for displaying the normal grid as the grid with a certain area marked}
+
+VAR X,Y : LONGINT;
+
+BEGIN
+ FOR Y:=0 TO PlayFieldYDimension-1 DO
+  BEGIN
+   GotoXY(FieldX,Y+FieldY);
+   FOR X:=0 TO PlayFieldXDimension-1 DO
+    BEGIN
+     TextColor(Colors[PlayField[X,Y]]);
+     Write(#219#219);
+    END;
+   END;
+END;
+{$ENDIF}
+
+PROCEDURE ShowHelp;
+{Shows some explanation of the game and waits for a key}
+
+{$ifndef UseGraphics}
+VAR I : LONGINT;
+{$endif}
+
+BEGIN
+ {$IFDEF UseGraphics}
+  HideMouse;
+  SetbkColor(black);
+  SetViewPort(0,0,getmaxx,getmaxy,clipoff);
+  ClearViewPort;
+  SetTextStyle(0,Horizdir,2);
+  OutTextXY(220,10,'SAMEGAME');
+  SetTextStyle(0,Horizdir,1);
+  OutTextXY(5,40+1*LineDistY,' is a small game, with a principle copied from some KDE game');
+  OutTextXY(5,40+3*LineDistY,'I tried to implement it under Go32V2 to demonstrate the MsMouse unit');
+  OutTextXY(5,40+4*LineDistY,'When it worked, I tried to get it running under Linux. I succeeded,');
+  OutTextXY(5,40+5*LineDistY,'but the mouse unit of the API doesn'#39't work with GPM 1.17');
+  OutTextXY(5,40+7*LineDistY,'If you move over the playfield, aggregates of one color will be marked');
+  OutTextXY(5,40+8*LineDistY,'in purple. If you then press the left mouse button, that aggregate will');
+  OutTextXY(5,40+9*LineDistY,'disappear, and the playfield will collapse to the bottom-left. Please');
+  OutTextXY(5,40+10*LineDistY,'keep in mind that only an aggregate of two blocks or more will disappear.');
+  OutTextXY(5,40+12*LineDistY,'For every aggregate you let disappear you get points, but the score is');
+  OutTextXY(5,40+13*LineDistY,'quadratic proportional to the number of blocks killed. So 4 times killing');
+  OutTextXY(5,40+14*LineDistY,' a 4 block aggregate scores 4 points, and one time 16 blocks will score 64');
+  OutTextXY(5,40+15*LineDistY,'blocks. The purpose of the game is obtaining the highscore');
+  OutTextXY(5,40+17*LineDistY,'If you manage to empty the entire playfield, you'#39'll get a bonus');
+  OutTextXY(5,40+19*LineDistY,'Press any key to get back to the game');
+  ShowMouse;
+ {$ELSE}
+  FOR I:=2 TO 24 DO
+   BEGIN
+    GotoXY(1,I);
+    ClrEol;
+   END;
+  GotoXY(1,3); TextColor(White);
+  Write('SAMEGAME');
+  SetDefaultColor;
+  WriteLn(' is a small game, with a principle copied from some KDE game');
+  WriteLn;
+  WriteLn('I tried to implement it under Go32V2 to demonstrate the MsMouse unit');
+  Writeln('When it worked, I tried to get it running under Linux. I succeeded,');
+  Writeln('but the mouse unit of the API doesn'#39't work with GPM 1.17');
+  Writeln;
+  WriteLn('If you move over the playfield, aggregates of one color will be marked');
+  Writeln('in purple. If you then press the left mouse button, that aggregate will');
+  Writeln('disappear, and the playfield will collapse to the bottom-left. Please');
+  Writeln('keep in mind that only an aggregate of two blocks or more will disappear.');
+  Writeln;
+  Writeln('For every aggregate you let disappear you get points, but the score is');
+  Writeln('quadratic proportional to the number of blocks killed. So 4 times killing');
+  Writeln(' a 4 block aggregate scores 4 points, and one time 16 blocks will score 64');
+  Writeln('blocks. The purpose of the game is obtaining the highscore');
+  Writeln;
+  Writeln('If you manage to empty the entire playfield, you'#39'll get a bonus');
+  Writeln;
+  WriteLn('Press any key to get back to the game');
+ {$ENDIF}
+  GetKey;
+END;
+
+VAR MarkField,PlayField : PlayFieldType; {The playfield, and the marked form}
+    CubesMarked         : LONGINT;       {Cubes currently marked}
+    Score               : LONGINT;       {The current score}
+    LastScore           : LONGINT;
+
+PROCEDURE ShowButtons;
+{Shows the clickable buttons}
+
+BEGIN
+ {$IFNDEF UseGraphics}
+ TextColor(Yellow); TextBackGround(Blue);
+ GotoXY(60,5);   Write('NEW game');
+ GotoXY(60,6);   Write('HELP');
+ GotoXY(60,7);   Write('END game');
+ {$IFDEF Linux}
+  GotoXY(60,8);   Write('Force IBM charset');
+ {$ENDIF}
+  SetDefaultColor;
+ {$ELSE}
+ SetTextStyle(0,Horizdir,1);
+ OutTextXY(MenuX,MenuY,grNewGameLine);
+ OutTextXY(MenuX,MenuY+RowDispl,grHelpLine);
+ OutTextXY(MenuX,MenuY+2*RowDispl,grEndGame);
+  {$ENDIF}
+
+END;
+
+FUNCTION PlayFieldPiecesLeft:LONGINT;
+{Counts pieces/cubes/blocks left on the playfield}
+
+VAR I,J,K : LONGINT;
+
+BEGIN
+ K:=0;
+ FOR I:=0 TO PlayFieldXDimension-1 DO
+  FOR J:=0 TO PlayFieldYDimension-1 DO
+   IF PlayField[I,J]<>3 THEN
+    INC(K);
+ PlayFieldPiecesLeft:=K;
+END;
+
+PROCEDURE ShowScore;
+{Simply procedure to update the score}
+
+{$IFDEF UseGraphics}
+VAR S : String;
+{$ENDIF}
+BEGIN
+ {$IFDEF UseGraphics}
+  Str(Score:5,S);
+  SetFillStyle(SolidFill,0);
+  Bar(300,440,450,458);
+  OutTextXY(300,440,'Score :'+S);
+ {$ELSE}
+ TextColor(White);
+ GotoXY(20,23);   Write(' ':20);
+ GotoXY(20,23);   Write('Score : ',Score);
+ SetDefaultColor;
+ {$ENDIF}
+END;
+
+FUNCTION CubesToScore : LONGINT;
+{Function to calculate score from the number of cubes. Should have a higher
+order than linear, or the purpose of the game disappears}
+
+BEGIN
+ CubesToScore:=(CubesMarked*CubesMarked) DIV 4;
+END;
+
+PROCEDURE MarkAfield(X,Y:LONGINT);
+{Recursively marks the area adjacent to (X,Y);}
+
+VAR TargetColor : LONGINT;
+
+PROCEDURE MarkRecur(X1,Y1:LONGINT);
+{Marks X1,Y1, checks if neighbours (horizontally or vertically) are the
+same color}
+
+BEGIN
+ IF (PlayField[X1,Y1]=TargetColor) AND (MarkField[X1,Y1]<>4) THEN
+  BEGIN
+   MarkField[X1,Y1]:=4;
+   INC(CubesMarked);
+  IF X1>0 THEN
+   MarkRecur(X1-1,Y1);
+  IF Y1>0 THEN
+   MarkRecur(X1,Y1-1);
+  IF X1<(PlayFieldXDimension-1) THEN
+   MarkRecur(X1+1,Y1);
+  IF Y1<(PlayFieldYDimension-1) THEN
+   MarkRecur(X1,Y1+1);
+  END;
+END;
+
+BEGIN
+ CubesMarked:=0;
+ TargetColor:=PlayField[X,Y];
+ IF TargetColor<>3 THEN         {Can't mark black space}
+  MarkRecur(X,Y);
+END;
+
+PROCEDURE FillPlayfield;
+{Initial version, probably not nice to play with.
+Some Life'ish algoritm would be better I think. (so that more aggregates exist)}
+
+VAR X,Y,Last,Now : LONGINT;
+
+BEGIN
+ Last:=0;
+ FOR X:=0 TO PlayFieldXDimension-1 DO
+  FOR Y:=0 TO PlayFieldYDimension-1 DO
+   BEGIN
+    Now:=RANDOM(4);
+    IF Now=3 THEN
+     Now:=Last;
+    PlayField[X,Y]:=Now;
+    Last:=Now;
+   END;
+  MarkField:=PlayField;
+END;
+
+PROCEDURE Colapse;
+{Processes the playfield if the mouse button is used.
+
+  First the procedure deletes the marked area, and let gravity do its work
+  Second the procedure uses as if some gravity existed on the left of the
+  playfield }
+
+VAR X, Y,J :LONGINT;
+
+BEGIN
+ {Vertical colapse: All marked pieces are deleted, and let gravity do it's work}
+ IF CubesMarked>1 THEN
+  BEGIN
+   FOR X:=0 TO PlayFieldXDimension-1 DO
+    BEGIN
+     Y:=PlayFieldYDimension-1; J:=Y;
+     REPEAT
+       IF MarkField[X,Y]<>4 THEN
+        BEGIN
+         PlayField[X,J]:=PlayField[X,Y];
+         DEC(J);
+        END;
+       DEC(Y);
+      UNTIL Y<0;
+    FOR Y:=0 TO J  DO
+     PlayField[X,Y]:=3;
+    END;
+   J:=0;
+   FOR X:=PlayFieldXDimension-2 DOWNTO 0  DO
+    BEGIN
+     IF PlayfIeld[X,PlayFieldYDimension-1]=3 THEN
+      BEGIN
+       Move(PlayfIeld[X+1,0],PlayField[X,0],PlayFieldYDimension*(PlayFieldXDimension-X-1));
+       INC(J);
+      END;
+    END;
+   IF J<>0 THEN
+    FillChar(PlayField[PlayFieldXDimension-J,0],J*PlayFieldYDimension,#3);
+   INC(Score,CubesToScore);
+   ShowScore;
+  END;
+END;
+
+PROCEDURE BuildScreen;
+{Some procedures that build the screen}
+
+BEGIN
+  {$IFDEF UseGraphics}
+   setbkcolor(black);
+   setviewport(0,0,getmaxx,getmaxy,clipoff);
+   clearviewport;
+  {$ELSE}
+   ClrScr;
+  {$ENDIF}
+  Score:=0;
+  ShowScore;
+  ShowButtons;
+  ShowHighScore;
+  ShowMouse;
+  {$IFDEF UseGraphics}
+
+   SetTextStyle(0,Horizdir,2);
+   OuttextXY(10,10,'SameGame v0.03, (C) by Marco v/d Voort. ');
+   SetTextStyle(0,Horizdir,1);
+   OuttextXY(50,40,'A demo for the FPC RTL and API units Crt,(MS)Mouse and Graph');
+  {$ELSE}
+  GotoXY(1,1);
+  TextColor(Yellow);
+  Write('SameGame v0.02');
+  TextColor(White);
+  Write('   A demo for the ');
+  TextColor(Yellow); Write('FPC');
+  TextColor(White); Write(' API or MsMouse unit. By Marco van de Voort');
+  SetDefaultColor;
+  {$ENDIF}
+  IF LastScore<>0 THEN
+   BEGIN
+    GotoXY(10,20);
+    Write('The score in the last game was :',LastScore);
+   END;
+  DisplayPlayField(PlayField);
+ MarkField:=PlayField;
+END;
+
+PROCEDURE DoMainLoopMouse;
+{The main game loop. The entire game runs in this procedure, the rest is
+    initialisation/finalisation (like loading and saving highscores etc etc)}
+
+VAR X,Y,
+    MX,MY,MState,Dummy : LONGINT;
+    EndOfGame          : LONGINT;
+    S                  : String;
+
+BEGIN
+ RANDOMIZE;
+ REPEAT
+  FillPlayField;
+  BuildScreen;
+  EndOfGame:=0;
+  REPEAT
+   GetMouseState(MX,MY,MState);
+   {$IFDEF UseGraphics}
+    X:=2*((MX-GrFieldX) DIV ScalerX) +FieldX;
+    Y:=((MY-GrFieldY) DIV ScalerY) +FieldY-1;
+   {$ELSE}
+    X:=MX SHR 3;
+    Y:=MY SHR 3;
+   {$ENDIF}
+   IF PlayFieldPiecesLeft=0 THEN
+    BEGIN
+     INC(Score,1000);
+     EndOfGame:=1;
+    END
+   ELSE
+    BEGIN
+     {$IFDEF UseGraphics}
+      IF (MX>=MenuX) AND (MX<(MenuX+16*Length(GrNewGameLine))) THEN
+       BEGIN {X in clickable area}
+        IF (MY>=MenuY) AND (MY<(MenuY+RowDispl*3+2)) THEN
+         BEGIN
+          X:=65; {X doesn't matter as long as it is 60..69}
+          Y:=((MY-MenuY) DIV RowDispl)+4;
+         END;
+       END;
+     {$ENDIF}
+     IF (X>=60) AND (X<=69) THEN
+      BEGIN
+         IF (MState AND LButton) <>0 THEN {If leftbutton pressed,}
+          BEGIN
+           IF Y=4 THEN
+            EndOfGame:=1;
+           IF Y=6 THEN
+            EndOfGame:=2;
+           IF (EndOfGame>0) AND (PlayFieldPiecesLeft=0) THEN
+            INC(Score,1000);
+           IF Y=5 THEN
+            BEGIN
+             ShowHelp;
+             BuildScreen;
+            END;
+           {$IFDEF Linux}
+           IF Y=7 THEN
+            BEGIN
+             write(#27+'(K');
+             BuildScreen;
+            END;
+           {$ENDIF}
+        END;
+      END;
+    IF (X>=(FieldX-2)) AND (Y>=(FieldY-2)) THEN
+     BEGIN
+
+      DEC(X,FieldX-1);
+      DEC(Y,FieldY-1);
+      X:=X SHR 1;
+      IF (X<PlayFieldXDimension) AND (Y<PlayFieldYDimension) THEN
+       BEGIN
+        IF MarkField[X,Y]<>4 THEN
+         BEGIN
+          MarkField:=PlayField;
+          MarkAfield(X,Y);
+          DisplayPlayField(MarkField);
+          TextColor(White);
+          GotoXY(20,22);
+          Write(' ':20);
+          GotoXY(20,22);
+          Write('Marked :',CubesToScore);
+         END;
+        IF (MarkField[X,Y]=4) AND ((MState AND LButton) <>0) THEN
+                                   {If leftbutton pressed,}
+         BEGIN
+          REPEAT                            {wait untill it's released.
+                                           The moment of pressing counts}
+           GetMouseState(X,Y,Dummy);
+          UNTIL (Dummy AND LButton)=0;
+          Colapse;
+          MarkField:=PlayField;
+          DisplayPlayField(MarkField);
+        END
+      END
+    END;
+   IF KeyPressed THEN
+    BEGIN
+     X:=GetKey;
+     IF (CHR(X) IN ['X','x','Q','q']) OR (X=27) THEN
+      EndOfGame:=2;
+    END;
+   END;
+  UNTIL EndOfGame>0;
+  ShowScore;
+  X:=SlipInScore(Score);
+  IF X<>0 THEN
+   BEGIN
+    HideMouse;
+    ShowHighScore;
+    {$IFDEF UseGraphics}
+     Str(Score:5,S);
+     OutTextXY(HighX+150,HighY+LineDistY*(10-X),S);
+     GrInputStr(S,HighX,HighY+LineDistY*(10-X),16,12,10,FALSE,AlfaBeta);
+    {$ELSE}
+     InputStr(S,HighX,HighY+12-X,10,FALSE,AlfaBeta);
+    {$ENDIF}
+    HighScore[X-1].Name:=S;
+    ShowMouse;
+   END;
+  LastScore:=Score;
+  UNTIL EndOFGame=2;
+END;
+
+CONST FileName='samegame.scr';
+
+VAR I : LONGINT;
+    {$IFDEF UseGraphics}
+    gd,gm : INTEGER;
+    Pal   : PaletteType;
+    {$ENDIF}
+
+BEGIN
+ {$IFDEF UseGraphics}
+  gm:=vgahi;
+  gd:=vga;
+  InitGraph(gd,gm,'');
+  if GraphResult <> grOk then
+    begin
+      Writeln('Graph driver ',gd,' graph mode ',gm,' not supported');
+      Halt(1);
+    end;
+  SetFillStyle(SolidFill,1);
+  GetDefaultPalette(Pal);
+  SetAllPalette(Pal);
+ {$ENDIF}
+  IF NOT MousePresent THEN
+   BEGIN
+    Writeln('No mouse found. A mouse is required!');
+    HALT;
+   END;
+  FOR I:=1 TO 10 DO
+   HighScore[I].Score:=I*1500;
+  LoadHighScore(FileName);
+  InitMouse;
+  CursorOff;
+ {$IFDEF UseGraphics}
+    HighX:=450;   HighY:=220; {the position of the highscore table}
+ {$else}
+    HighX:=52;   HighY:=10; {the position of the highscore table}
+  {$endif}
+
+  DoMainLoopMouse;
+
+  HideMouse;
+  DoneMouse;
+  CursorOn;
+  SaveHighScore;
+  {$IFDEF UseGraphics}
+   CloseGraph;
+  {$ENDIF}
+  ClrScr;
+  Writeln;
+  Writeln('Last games'#39' score was : ',Score);
+END.
+{
+  $Log$
+  Revision 1.1  2001-05-03 21:39:33  peter
+    * moved to own module
+
+  Revision 1.2  2000/07/13 11:33:09  michael
+  + removed logs
+ 
+}

+ 828 - 0
demo/linux/Makefile

@@ -0,0 +1,828 @@
+#
+# Don't edit, this file is generated by fpcmake v1.99.0 [2001/05/03]
+#
+default: all
+override PATH:=$(subst \,/,$(PATH))
+ifeq ($(findstring ;,$(PATH)),)
+inUnix=1
+SEARCHPATH:=$(subst :, ,$(PATH))
+else
+SEARCHPATH:=$(subst ;, ,$(PATH))
+endif
+PWD:=$(strip $(wildcard $(addsuffix /pwd.exe,$(SEARCHPATH))))
+ifeq ($(PWD),)
+PWD:=$(strip $(wildcard $(addsuffix /pwd,$(SEARCHPATH))))
+ifeq ($(PWD),)
+nopwd:
+	@echo You need the GNU utils package to use this Makefile!
+	@echo Get ftp://ftp.freepascal.org/pub/fpc/dist/go32v2/utilgo32.zip
+	@exit
+else
+PWD:=$(firstword $(PWD))
+SRCEXEEXT=
+endif
+else
+PWD:=$(firstword $(PWD))
+SRCEXEEXT=.exe
+endif
+ifndef inUnix
+ifeq ($(OS),Windows_NT)
+inWinNT=1
+else
+ifdef OS2_SHELL
+inOS2=1
+endif
+endif
+else
+ifneq ($(findstring cygwin,$(MACH_TYPE)),)
+inCygWin=1
+endif
+endif
+ifdef inUnix
+BATCHEXT=.sh
+else
+ifdef inOS2
+BATCHEXT=.cmd
+else
+BATCHEXT=.bat
+endif
+endif
+ifdef inUnix
+PATHSEP=/
+else
+PATHSEP:=$(subst /,\,/)
+endif
+ifdef PWD
+BASEDIR:=$(shell $(PWD))
+else
+BASEDIR=.
+endif
+ifndef FPC
+ifdef PP
+FPC=$(PP)
+else
+FPC=ppc386
+endif
+endif
+override FPC:=$(subst $(SRCEXEEXT),,$(FPC))
+override FPC:=$(subst \,/,$(FPC))$(SRCEXEEXT)
+ifndef OS_TARGET
+OS_TARGET:=$(shell $(FPC) -iTO)
+endif
+ifndef OS_SOURCE
+OS_SOURCE:=$(shell $(FPC) -iSO)
+endif
+ifndef CPU_TARGET
+CPU_TARGET:=$(shell $(FPC) -iTP)
+endif
+ifndef CPU_SOURCE
+CPU_SOURCE:=$(shell $(FPC) -iSP)
+endif
+ifndef FPC_VERSION
+FPC_VERSION:=$(shell $(FPC) -iV)
+endif
+export FPC OS_TARGET OS_SOURCE CPU_TARGET CPU_SOURCE FPC_VERSION
+ifdef FPCDIR
+override FPCDIR:=$(subst \,/,$(FPCDIR))
+ifeq ($(wildcard $(addprefix $(FPCDIR)/,rtl units)),)
+override FPCDIR=wrong
+endif
+else
+override FPCDIR=wrong
+endif
+ifeq ($(FPCDIR),wrong)
+override FPCDIR=../..
+ifeq ($(wildcard $(FPCDIR)/rtl),)
+ifeq ($(wildcard $(FPCDIR)/units),)
+override FPCDIR=wrong
+endif
+endif
+endif
+ifeq ($(FPCDIR),wrong)
+ifdef inUnix
+override FPCDIR=/usr/local/lib/fpc/$(FPC_VERSION)
+ifeq ($(wildcard $(FPCDIR)/units),)
+override FPCDIR=/usr/lib/fpc/$(FPC_VERSION)
+endif
+else
+override FPCDIR:=$(subst /$(FPC),,$(firstword $(strip $(wildcard $(addsuffix /$(FPC),$(SEARCHPATH))))))
+override FPCDIR:=$(FPCDIR)/..
+ifeq ($(wildcard $(addprefix $(FPCDIR)/,rtl units)),)
+override FPCDIR:=$(FPCDIR)/..
+ifeq ($(wildcard $(addprefix $(FPCDIR)/,rtl units)),)
+override FPCDIR=c:/pp
+endif
+endif
+endif
+endif
+UNITSDIR:=$(wildcard $(FPCDIR)/units/$(OS_TARGET))
+PACKAGESDIR:=$(wildcard $(FPCDIR) $(FPCDIR)/packages)
+ifeq ($(OS_TARGET),linux)
+override TARGET_PROGRAMS+=daemon
+endif
+ifndef ECHO
+ECHO:=$(strip $(wildcard $(addsuffix /gecho$(EXEEXT),$(SEARCHPATH))))
+ifeq ($(ECHO),)
+ECHO:=$(strip $(wildcard $(addsuffix /echo$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(ECHO),)
+ECHO:=echo
+else
+ECHO:=$(firstword $(ECHO))
+endif
+else
+ECHO:=$(firstword $(ECHO))
+endif
+endif
+ifndef COPY
+COPY:=cp -fp
+endif
+ifndef COPYTREE
+COPYTREE:=cp -rfp
+endif
+ifndef MOVE
+MOVE:=mv -f
+endif
+ifndef DEL
+DEL:=rm -f
+endif
+ifndef DELTREE
+DELTREE:=rm -rf
+endif
+ifndef INSTALL
+ifdef inUnix
+INSTALL:=install -c -m 644
+else
+INSTALL:=$(COPY)
+endif
+endif
+ifndef INSTALLEXE
+ifdef inUnix
+INSTALLEXE:=install -c -m 755
+else
+INSTALLEXE:=$(COPY)
+endif
+endif
+ifndef MKDIR
+ifdef inUnix
+MKDIR:=install -m 755 -d
+else
+MKDIR:=ginstall -m 755 -d
+endif
+endif
+export ECHO COPY COPYTREE MOVE DEL DELTREE INSTALL INSTALLEXE MKDIR
+ifndef AS
+AS=as
+endif
+ifndef LD
+LD=ld
+endif
+ifndef RC
+RC=rc
+endif
+PPAS=ppas$(BATCHEXT)
+ifdef inUnix
+LDCONFIG=ldconfig
+else
+LDCONFIG=
+endif
+ifndef PPUMOVE
+PPUMOVE:=$(strip $(wildcard $(addsuffix /ppumove$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(PPUMOVE),)
+PPUMOVE=
+else
+PPUMOVE:=$(firstword $(PPUMOVE))
+endif
+endif
+export PPUMOVE
+ifndef PPUFILES
+PPUFILES:=$(strip $(wildcard $(addsuffix /ppufiles$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(PPUFILES),)
+PPUFILES=
+else
+PPUFILES:=$(firstword $(PPUFILES))
+endif
+endif
+export PPUFILES
+ifndef DATE
+DATE:=$(strip $(wildcard $(addsuffix /date$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(DATE),)
+DATE:=$(strip $(wildcard $(addsuffix /gdate$(SRCEXEEXT),$(SEACHPATH))))
+ifeq ($(DATE),)
+DATE=
+else
+DATE:=$(firstword $(DATE))
+endif
+else
+DATE:=$(firstword $(DATE))
+endif
+endif
+export DATE
+ifdef DATE
+DATESTR:=$(shell $(DATE) +%Y%m%d)
+else
+DATESTR=
+endif
+ifndef UPXPROG
+ifeq ($(OS_TARGET),go32v2)
+UPXPROG:=1
+endif
+ifeq ($(OS_TARGET),win32)
+UPXPROG:=1
+endif
+ifdef UPXPROG
+UPXPROG:=$(strip $(wildcard $(addsuffix /upx$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(UPXPROG),)
+UPXPROG=
+else
+UPXPROG:=$(firstword $(UPXPROG))
+endif
+else
+UPXPROG=
+endif
+endif
+export UPXPROG
+ifndef ZIPPROG
+ZIPPROG:=$(strip $(wildcard $(addsuffix /zip$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(ZIPPROG),)
+ZIPPROG=
+else
+ZIPPROG:=$(firstword $(ZIPPROG))
+endif
+endif
+export ZIPPROG
+ZIPOPT=-9
+ZIPEXT=.zip
+ifndef TARPROG
+TARPROG:=$(strip $(wildcard $(addsuffix /tar$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(TARPROG),)
+TARPROG=
+else
+TARPROG:=$(firstword $(TARPROG))
+endif
+endif
+export TARPROG
+ifeq ($(USETAR),bz2)
+TAROPT=vI
+TAREXT=.tar.bz2
+else
+TAROPT=vz
+TAREXT=.tar.gz
+endif
+LOADEREXT=.as
+EXEEXT=.exe
+PPLEXT=.ppl
+PPUEXT=.ppu
+OEXT=.o
+ASMEXT=.s
+SMARTEXT=.sl
+STATICLIBEXT=.a
+SHAREDLIBEXT=.so
+LIBPREFIX=lib
+RSTEXT=.rst
+FPCMADE=fpcmade
+ifeq ($(OS_TARGET),go32v1)
+PPUEXT=.pp1
+OEXT=.o1
+ASMEXT=.s1
+SMARTEXT=.sl1
+STATICLIBEXT=.a1
+SHAREDLIBEXT=.so1
+LIBPREFIX=
+FPCMADE=fpcmade.v1
+PACKAGESUFFIX=v1
+endif
+ifeq ($(OS_TARGET),go32v2)
+LIBPREFIX=
+FPCMADE=fpcmade.dos
+ZIPSUFFIX=go32
+endif
+ifeq ($(OS_TARGET),linux)
+EXEEXT=
+HASSHAREDLIB=1
+FPCMADE=fpcmade.lnx
+ZIPSUFFIX=linux
+endif
+ifeq ($(OS_TARGET),freebsd)
+EXEEXT=
+HASSHAREDLIB=1
+FPCMADE=fpcmade.freebsd
+ZIPSUFFIX=freebsd
+endif
+ifeq ($(OS_TARGET),win32)
+PPUEXT=.ppw
+OEXT=.ow
+ASMEXT=.sw
+SMARTEXT=.slw
+STATICLIBEXT=.aw
+SHAREDLIBEXT=.dll
+FPCMADE=fpcmade.w32
+ZIPSUFFIX=w32
+endif
+ifeq ($(OS_TARGET),os2)
+PPUEXT=.ppo
+ASMEXT=.so2
+OEXT=.oo2
+AOUTEXT=.out
+SMARTEXT=.so
+STATICLIBEXT=.ao2
+SHAREDLIBEXT=.dll
+FPCMADE=fpcmade.os2
+ZIPSUFFIX=emx
+endif
+ifdef REQUIRE_UNITSDIR
+override UNITSDIR+=$(REQUIRE_UNITSDIR)
+endif
+ifdef REQUIRE_PACKAGESDIR
+override PACKAGESDIR+=$(REQUIRE_PACKAGESDIR)
+endif
+ifdef ZIPINSTALL
+ifeq ($(OS_TARGET),linux)
+UNIXINSTALLDIR=1
+endif
+ifeq ($(OS_TARGET),freebsd)
+UNIXINSTALLDIR=1
+endif
+else
+ifeq ($(OS_SOURCE),linux)
+UNIXINSTALLDIR=1
+endif
+ifeq ($(OS_SOURCE),freebsd)
+UNIXINSTALLDIR=1
+endif
+endif
+ifndef INSTALL_PREFIX
+ifdef UNIXINSTALLDIR
+INSTALL_PREFIX=/usr/local
+else
+ifdef INSTALL_FPCPACKAGE
+INSTALL_BASEDIR:=/pp
+else
+INSTALL_BASEDIR:=/$(PACKAGE_NAME)
+endif
+endif
+endif
+export INSTALL_PREFIX
+ifndef DIST_DESTDIR
+DIST_DESTDIR:=$(BASEDIR)
+endif
+export DIST_DESTDIR
+ifndef INSTALL_BASEDIR
+ifdef UNIXINSTALLDIR
+ifdef INSTALL_FPCPACKAGE
+INSTALL_BASEDIR:=$(INSTALL_PREFIX)/lib/fpc/$(FPC_VERSION)
+else
+INSTALL_BASEDIR:=$(INSTALL_PREFIX)/lib/$(PACKAGE_NAME)
+endif
+else
+INSTALL_BASEDIR:=$(INSTALL_PREFIX)
+endif
+endif
+ifndef INSTALL_BINDIR
+ifdef UNIXINSTALLDIR
+INSTALL_BINDIR:=$(INSTALL_PREFIX)/bin
+else
+INSTALL_BINDIR:=$(INSTALL_BASEDIR)/bin
+ifdef INSTALL_FPCPACKAGE
+INSTALL_BINDIR:=$(INSTALL_BINDIR)/$(OS_TARGET)
+endif
+endif
+endif
+ifndef INSTALL_UNITDIR
+INSTALL_UNITDIR:=$(INSTALL_BASEDIR)/units/$(OS_TARGET)
+ifdef INSTALL_FPCPACKAGE
+INSTALL_UNITDIR:=$(INSTALL_UNITDIR)/$(PACKAGE_NAME)
+endif
+endif
+ifndef INSTALL_LIBDIR
+ifdef UNIXINSTALLDIR
+INSTALL_LIBDIR:=$(INSTALL_PREFIX)/lib
+else
+INSTALL_LIBDIR:=$(INSTALL_UNITDIR)
+endif
+endif
+ifndef INSTALL_SOURCEDIR
+ifdef UNIXINSTALLDIR
+ifdef INSTALL_FPCPACKAGE
+INSTALL_SOURCEDIR:=$(INSTALL_PREFIX)/src/fpc-$(FPC_VERSION)/$(PACKAGE_NAME)
+else
+INSTALL_SOURCEDIR:=$(INSTALL_PREFIX)/src/$(PACKAGE_NAME)-$(PACKAGE_VERSION)
+endif
+else
+ifdef INSTALL_FPCPACKAGE
+INSTALL_SOURCEDIR:=$(INSTALL_BASEDIR)/source/$(PACKAGE_NAME)
+else
+INSTALL_SOURCEDIRL:=$(INSTALL_BASEDIR)/source
+endif
+endif
+endif
+ifndef INSTALL_DOCDIR
+ifdef UNIXINSTALLDIR
+ifdef INSTALL_FPCPACKAGE
+INSTALL_DOCDIR:=$(INSTALL_PREFIX)/doc/fpc-$(FPC_VERSION)/$(PACKAGE_NAME)
+else
+INSTALL_DOCDIR:=$(INSTALL_PREFIX)/doc/$(PACKAGE_NAME)-$(PACKAGE_VERSION)
+endif
+else
+ifdef INSTALL_FPCPACKAGE
+INSTALL_DOCDIR:=$(INSTALL_BASEDIR)/doc/$(PACKAGE_NAME)
+else
+INSTALL_DOCDIR:=$(INSTALL_BASEDIR)/doc
+endif
+endif
+endif
+ifndef INSTALL_EXAMPLEDIR
+ifdef UNIXINSTALLDIR
+ifdef INSTALL_FPCPACKAGE
+INSTALL_EXAMPLEDIR:=$(INSTALL_PREFIX)/doc/fpc-$(FPC_VERSION)/examples/$(PACKAGE_NAME)
+else
+INSTALL_EXAMPLEDIR:=$(INSTALL_PREFIX)/doc/$(PACKAGE_NAME)-$(PACKAGE_VERSION)
+endif
+else
+ifdef INSTALL_FPCPACKAGE
+INSTALL_EXAMPLEDIR:=$(INSTALL_BASEDIR)/examples/$(PACKAGE_NAME)
+else
+INSTALL_EXAMPLEDIR:=$(INSTALL_BASEDIR)/examples
+endif
+endif
+endif
+ifndef INSTALL_DATADIR
+INSTALL_DATADIR=$(INSTALL_BASEDIR)
+endif
+ifeq ($(OS_TARGET),linux)
+REQUIRE_PACKAGES_RTL=1
+endif
+ifeq ($(OS_TARGET),go32v2)
+REQUIRE_PACKAGES_RTL=1
+endif
+ifeq ($(OS_TARGET),win32)
+REQUIRE_PACKAGES_RTL=1
+endif
+ifeq ($(OS_TARGET),os2)
+REQUIRE_PACKAGES_RTL=1
+endif
+ifeq ($(OS_TARGET),freebsd)
+REQUIRE_PACKAGES_RTL=1
+endif
+ifdef REQUIRE_PACKAGES_RTL
+PACKAGEDIR_RTL:=$(subst /Makefile.fpc,,$(strip $(wildcard $(addsuffix /rtl/Makefile.fpc,$(PACKAGESDIR)))))
+ifneq ($(PACKAGEDIR_RTL),)
+PACKAGEDIR_RTL:=$(firstword $(PACKAGEDIR_RTL))
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=package_rtl
+package_rtl:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+ifneq ($(wildcard $(PACKAGEDIR_RTL)/$(OS_TARGET)),)
+UNITDIR_RTL=$(PACKAGEDIR_RTL)/$(OS_TARGET)
+else
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+endif
+else
+PACKAGEDIR_RTL=
+UNITDIR_RTL:=$(subst /Package.fpc,,$(strip $(wildcard $(addsuffix /rtl/Package.fpc,$(UNITSDIR)))))
+ifneq ($(UNITDIR_RTL),)
+UNITDIR_RTL:=$(firstword $(UNITDIR_RTL))
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override COMPILER_UNITDIR+=$(UNITDIR_RTL)
+endif
+endif
+.PHONY: package_rtl
+override FPCOPTDEF=$(CPU_TARGET)
+ifneq ($(OS_TARGET),$(OS_SOURCE))
+override FPCOPT+=-T$(OS_TARGET)
+endif
+ifdef UNITDIR
+override FPCOPT+=$(addprefix -Fu,$(UNITDIR))
+endif
+ifdef LIBDIR
+override FPCOPT+=$(addprefix -Fl,$(LIBDIR))
+endif
+ifdef OBJDIR
+override FPCOPT+=$(addprefix -Fo,$(OBJDIR))
+endif
+ifdef INCDIR
+override FPCOPT+=$(addprefix -Fi,$(INCDIR))
+endif
+ifdef LINKSMART
+override FPCOPT+=-XX
+endif
+ifdef CREATESMART
+override FPCOPT+=-CX
+endif
+ifdef DEBUG
+override FPCOPT+=-gl
+override FPCOPTDEF+=DEBUG
+endif
+ifdef RELEASE
+override FPCOPT+=-Xs -OG2p3 -n
+override FPCOPTDEF+=RELEASE
+endif
+ifdef STRIP
+override FPCOPT+=-Xs
+endif
+ifdef OPTIMIZE
+override FPCOPT+=-OG2p3
+endif
+ifdef VERBOSE
+override FPCOPT+=-vwni
+endif
+ifdef COMPILER_OPTIONS
+override FPCOPT+=$(COMPILER_OPTIONS)
+endif
+ifdef COMPILER_UNITDIR
+override FPCOPT+=$(addprefix -Fu,$(COMPILER_UNITDIR))
+endif
+ifdef COMPILER_LIBRARYDIR
+override FPCOPT+=$(addprefix -Fl,$(COMPILER_LIBRARYDIR))
+endif
+ifdef COMPILER_OBJECTDIR
+override FPCOPT+=$(addprefix -Fo,$(COMPILER_OBJECTDIR))
+endif
+ifdef COMPILER_INCLUDEDIR
+override FPCOPT+=$(addprefix -Fi,$(COMPILER_INCLUDEDIR))
+endif
+ifdef COMPILER_TARGETDIR
+override FPCOPT+=-FE$(COMPILER_TARGETDIR)
+ifeq ($(COMPILER_TARGETDIR),.)
+override TARGETDIRPREFIX=
+else
+override TARGETDIRPREFIX=$(COMPILER_TARGETDIR)/
+endif
+endif
+ifdef COMPILER_UNITTARGETDIR
+override FPCOPT+=-FU$(COMPILER_UNITTARGETDIR)
+ifeq ($(COMPILER_UNITTARGETDIR),.)
+override UNITTARGETDIRPREFIX=
+else
+override UNITTARGETDIRPREFIX=$(COMPILER_TARGETDIR)/
+endif
+else
+ifdef COMPILER_TARGETDIR
+override COMPILER_UNITTARGETDIR=$(COMPILER_TARGETDIR)
+override UNITTARGETDIRPREFIX=$(TARGETDIRPREFIX)
+endif
+endif
+ifdef OPT
+override FPCOPT+=$(OPT)
+endif
+ifdef FPCOPTDEF
+override FPCOPT+=$(addprefix -d,$(FPCOPTDEF))
+endif
+ifdef CFGFILE
+override FPCOPT+=@$(CFGFILE)
+endif
+ifeq ($(OS_SOURCE),win32)
+USEENV=1
+endif
+ifdef USEENV
+override FPCEXTCMD:=$(FPCOPT)
+override FPCOPT:=!FPCEXTCMD
+export FPCEXTCMD
+endif
+override COMPILER:=$(FPC) $(FPCOPT)
+ifeq (,$(findstring -s ,$(COMPILER)))
+EXECPPAS=
+else
+ifeq ($(OS_SOURCE),$(OS_TARGET))
+EXECPPAS:=@$(PPAS)
+endif
+endif
+.PHONY: fpc_exes
+ifdef TARGET_PROGRAMS
+override EXEFILES=$(addsuffix $(EXEEXT),$(TARGET_PROGRAMS))
+override EXEOFILES:=$(addsuffix $(OEXT),$(TARGET_PROGRAMS)) $(addprefix $(LIBPREFIX),$(addsuffix $(STATICLIBEXT),$(TARGET_PROGRAMS)))
+override ALLTARGET+=fpc_exes
+override INSTALLEXEFILES+=$(EXEFILES)
+override CLEANEXEFILES+=$(EXEFILES) $(EXEOFILES)
+ifeq ($(OS_TARGET),os2)
+override CLEANEXEFILES+=$(addsuffix $(AOUTEXT),$(TARGET_PROGRAMS))
+endif
+endif
+fpc_exes: $(EXEFILES)
+.PHONY: fpc_packages fpc_all fpc_smart fpc_debug
+$(FPCMADE): $(ALLTARGET)
+	@$(ECHO) Compiled > $(FPCMADE)
+fpc_packages: $(COMPILEPACKAGES)
+fpc_all: fpc_packages $(FPCMADE)
+fpc_smart:
+	$(MAKE) all LINKSMART=1 CREATESMART=1
+fpc_debug:
+	$(MAKE) all DEBUG=1
+.SUFFIXES: $(EXEEXT) $(PPUEXT) $(OEXT) .pas .pp
+%$(PPUEXT): %.pp
+	$(COMPILER) $<
+	$(EXECPPAS)
+%$(PPUEXT): %.pas
+	$(COMPILER) $<
+	$(EXECPPAS)
+%$(EXEEXT): %.pp
+	$(COMPILER) $<
+	$(EXECPPAS)
+%$(EXEEXT): %.pas
+	$(COMPILER) $<
+	$(EXECPPAS)
+vpath %.pp $(COMPILER_SOURCEDIR) $(COMPILER_INCLUDEDIR)
+vpath %.pas $(COMPILER_SOURCEDIR) $(COMPILER_INCLUDEDIR)
+vpath %$(PPUEXT) $(COMPILER_UNITTARGETDIR)
+.PHONY: fpc_install fpc_sourceinstall fpc_exampleinstall
+ifdef INSTALL_UNITS
+override INSTALLPPUFILES+=$(addsuffix $(PPUEXT),$(INSTALL_UNITS))
+endif
+ifdef INSTALLPPUFILES
+ifdef PPUFILES
+override INSTALLPPUFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(INSTALLPPUFILES))
+override INSTALLPPULINKFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(shell $(PPUFILES) -S -O $(INSTALLPPUFILES)))
+else
+override INSTALLPPULINKFILES:=$(subst $(PPUEXT),$(OEXT),$(INSTALLPPUFILES)) $(addprefix $(LIBPREFIX),$(subst $(PPUEXT),$(STATICLIBEXT),$(INSTALLPPUFILES)))
+override INSTALLPPUFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(INSTALLPPUFILES))
+override INSTALLPPULINKFILES:=$(wildcard $(addprefix $(UNITTARGETDIRPREFIX),$(INSTALLPPULINKFILES)))
+endif
+endif
+ifdef INSTALLEXEFILES
+override INSTALLEXEFILES:=$(addprefix $(TARGETDIRPREFIX),$(INSTALLEXEFILES))
+endif
+fpc_install: $(INSTALLTARGET)
+ifdef INSTALLEXEFILES
+	$(MKDIR) $(INSTALL_BINDIR)
+ifdef UPXPROG
+	-$(UPXPROG) $(INSTALLEXEFILES)
+endif
+	$(INSTALLEXE) $(INSTALLEXEFILES) $(INSTALL_BINDIR)
+endif
+ifdef INSTALLPPUFILES
+	$(MKDIR) $(INSTALL_UNITDIR)
+	$(INSTALL) $(INSTALLPPUFILES) $(INSTALL_UNITDIR)
+ifneq ($(INSTALLPPULINKFILES),)
+	$(INSTALL) $(INSTALLPPULINKFILES) $(INSTALL_UNITDIR)
+endif
+ifneq ($(wildcard $(LIB_FULLNAME)),)
+	$(MKDIR) $(INSTALL_LIBDIR)
+	$(INSTALL) $(LIB_FULLNAME) $(INSTALL_LIBDIR)
+ifdef inUnix
+	ln -sf $(LIB_FULLNAME) $(INSTALL_LIBDIR)/$(LIB_NAME)
+endif
+endif
+endif
+ifdef INSTALL_FILES
+	$(MKDIR) $(INSTALL_DATADIR)
+	$(INSTALL) $(INSTALL_FILES) $(INSTALL_DATADIR)
+endif
+fpc_sourceinstall: distclean
+	$(MKDIR) $(INSTALL_SOURCEDIR)
+	$(COPYTREE) $(BASEDIR) $(INSTALL_SOURCEDIR)
+fpc_exampleinstall: $(addsuffix _distclean,$(TARGET_EXAMPLEDIRS))
+ifdef HASEXAMPLES
+	$(MKDIR) $(INSTALL_EXAMPLEDIR)
+endif
+ifdef EXAMPLESOURCEFILES
+	$(COPY) $(EXAMPLESOURCEFILES) $(INSTALL_EXAMPLEDIR)
+endif
+ifdef TARGET_EXAMPLEDIRS
+	$(COPYTREE) $(addsuffix /*,$(TARGET_EXAMPLEDIRS)) $(INSTALL_EXAMPLEDIR)
+endif
+fpc_distinstall: install exampleinstall
+.PHONY: fpc_clean fpc_cleanall fpc_distclean
+ifdef EXEFILES
+override CLEANEXEFILES:=$(addprefix $(TARGETDIRPREFIX),$(CLEANEXEFILES))
+endif
+ifdef CLEAN_UNITS
+override CLEANPPUFILES+=$(addsuffix $(PPUEXT),$(CLEAN_UNITS))
+endif
+ifdef CLEANPPUFILES
+override CLEANPPUFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(CLEANPPUFILES))
+ifdef PPUFILES
+CLEANPPULINKFILES:=$(shell $(PPUFILES) $(CLEANPPUFILES))
+else
+CLEANPPULINKFILES:=$(wildcard $(subst $(PPUEXT),$(OEXT),$(CLEANPPUFILES)) $(addprefix $(LIBPREFIX),$(subst $(PPUEXT),$(STATICLIBEXT),$(CLEANPPUFILES))))
+endif
+override CLEANPPULINKFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(CLEANPPULINKFILES))
+endif
+fpc_clean: $(CLEANTARGET)
+ifdef CLEANEXEFILES
+	-$(DEL) $(CLEANEXEFILES)
+endif
+ifdef CLEANPPUFILES
+	-$(DEL) $(CLEANPPUFILES)
+endif
+ifneq ($(CLEANPPULINKFILES),)
+	-$(DEL) $(CLEANPPULINKFILES)
+endif
+ifdef CLEANRSTFILES
+	-$(DEL) $(addprefix $(UNITTARGETDIRPREFIX),$(CLEANRSTFILES))
+endif
+ifdef CLEAN_FILES
+	-$(DEL) $(CLEAN_FILES)
+endif
+ifdef LIB_NAME
+	-$(DEL) $(LIB_NAME) $(LIB_FULLNAME)
+endif
+	-$(DEL) $(FPCMADE) $(PPAS) link.res $(FPCEXTFILE) $(REDIRFILE)
+fpc_distclean: clean
+ifdef COMPILER_UNITTARGETDIR
+TARGETDIRCLEAN=fpc_clean
+endif
+fpc_cleanall: $(CLEANTARGET) $(TARGETDIRCLEAN)
+ifdef CLEANEXEFILES
+	-$(DEL) $(CLEANEXEFILES)
+endif
+	-$(DEL) *$(OEXT) *$(PPUEXT) *$(RSTEXT) *$(ASMEXT) *$(STATICLIBEXT) *$(SHAREDLIBEXT) *$(PPLEXT)
+	-$(DELTREE) *$(SMARTEXT)
+	-$(DEL) $(FPCMADE) $(PPAS) link.res $(FPCEXTFILE) $(REDIRFILE)
+ifdef AOUTEXT
+	-$(DEL) *$(AOUTEXT)
+endif
+.PHONY: fpc_info
+fpc_info:
+	@$(ECHO)
+	@$(ECHO)  == Package info ==
+	@$(ECHO)  Package Name..... $(PACKAGE_NAME)
+	@$(ECHO)  Package Version.. $(PACKAGE_VERSION)
+	@$(ECHO)
+	@$(ECHO)  == Configuration info ==
+	@$(ECHO)
+	@$(ECHO)  FPC.......... $(FPC)
+	@$(ECHO)  FPC Version.. $(FPC_VERSION)
+	@$(ECHO)  Source CPU... $(CPU_SOURCE)
+	@$(ECHO)  Target CPU... $(CPU_TARGET)
+	@$(ECHO)  Source OS.... $(OS_SOURCE)
+	@$(ECHO)  Target OS.... $(OS_TARGET)
+	@$(ECHO)
+	@$(ECHO)  == Directory info ==
+	@$(ECHO)
+	@$(ECHO)  Basedir......... $(BASEDIR)
+	@$(ECHO)  FPCDir.......... $(FPCDIR)
+	@$(ECHO)  UnitsDir........ $(UNITSDIR)
+	@$(ECHO)  PackagesDir..... $(PACKAGESDIR)
+	@$(ECHO)
+	@$(ECHO)  GCC library..... $(GCCLIBDIR)
+	@$(ECHO)  Other library... $(OTHERLIBDIR)
+	@$(ECHO)
+	@$(ECHO)  == Tools info ==
+	@$(ECHO)
+	@$(ECHO)  Pwd....... $(PWD)
+	@$(ECHO)  Echo...... $(ECHO)
+	@$(ECHO)  PPUMove... $(PPUMOVE)
+	@$(ECHO)  PPUFiles.. $(PPUFILES)
+	@$(ECHO)  Date...... $(DATE)
+	@$(ECHO)  Upx....... $(UPXPROG)
+	@$(ECHO)  Zip....... $(ZIPPROG)
+	@$(ECHO)
+	@$(ECHO)  == Object info ==
+	@$(ECHO)
+	@$(ECHO)  Target Loaders...... $(TARGET_LOADERS)
+	@$(ECHO)  Target Units........ $(TARGET_UNITS)
+	@$(ECHO)  Target Programs..... $(TARGET_PROGRAMS)
+	@$(ECHO)  Target Dirs......... $(TARGET_DIRS)
+	@$(ECHO)  Target Examples..... $(TARGET_EXAMPLES)
+	@$(ECHO)  Target ExampleDirs.. $(TARGET_EXAMPLEDIRS)
+	@$(ECHO)
+	@$(ECHO)  Clean Units......... $(CLEAN_UNITS)
+	@$(ECHO)  Clean Files......... $(CLEAN_FILES)
+	@$(ECHO)
+	@$(ECHO)  Install Units....... $(INSTALL_UNITS)
+	@$(ECHO)  Install Files....... $(INSTALL_FILES)
+	@$(ECHO)
+	@$(ECHO)  == Install info ==
+	@$(ECHO)
+	@$(ECHO)  DateStr.............. $(DATESTR)
+	@$(ECHO)  ZipPrefix............ $(ZIPPREFIX)
+	@$(ECHO)  ZipSuffix............ $(ZIPSUFFIX)
+	@$(ECHO)  Install FPC Package.. $(INSTALL_FPCPACKAGE)
+	@$(ECHO)
+	@$(ECHO)  Install base dir..... $(INSTALL_BASEDIR)
+	@$(ECHO)  Install binary dir... $(INSTALL_BINDIR)
+	@$(ECHO)  Install library dir.. $(INSTALL_LIBDIR)
+	@$(ECHO)  Install units dir.... $(INSTALL_UNITDIR)
+	@$(ECHO)  Install source dir... $(INSTALL_SOURCEDIR)
+	@$(ECHO)  Install doc dir...... $(INSTALL_DOCDIR)
+	@$(ECHO)  Install example dir.. $(INSTALL_EXAMPLEDIR)
+	@$(ECHO)  Install data dir..... $(INSTALL_DATADIR)
+	@$(ECHO)
+	@$(ECHO)  Dist destination dir. $(DIST_DESTDIR)
+	@$(ECHO)  Dist zip name........ $(DIST_ZIPNAME)
+	@$(ECHO)
+all: fpc_all
+debug: fpc_debug
+examples: fpc_examples
+smart: fpc_smart
+shared: fpc_shared
+install: fpc_install
+sourceinstall: fpc_sourceinstall
+exampleinstall: fpc_exampleinstall
+distinstall: fpc_distinstall
+zipinstall:
+zipsourceinstall:
+zipexampleinstall:
+zipdistinstall:
+clean: fpc_clean
+distclean: fpc_distclean
+cleanall: fpc_cleanall
+info: fpc_info
+.PHONY: all debug examples smart shared install sourceinstall exampleinstall distinstall zipinstall zipsourceinstall zipexampleinstall zipdistinstall clean distclean cleanall info
+ifneq ($(wildcard fpcmake.loc),)
+include fpcmake.loc
+endif

+ 9 - 0
demo/linux/Makefile.fpc

@@ -0,0 +1,9 @@
+#
+#   Makefile.fpc for FPC linux demos (part of FPC demo package)
+#
+
+[target]
+programs_linux=daemon
+
+[default]
+fpcdir=../..

+ 145 - 0
demo/linux/daemon.pp

@@ -0,0 +1,145 @@
+{---------------------------------------------------------------------------
+                                 CncWare
+                           (c) Copyright 2000
+ ---------------------------------------------------------------------------
+  $Id$
+  Filename..: daemon.pp
+  Programmer: Ken J. Wright
+  Date......: 03/21/2000
+
+  Purpose - Program to demonstrate construction of a Linux daemon.
+
+  Usage:
+    1) Compile this program.
+    2) Run it. You will be immediately returned to a command prompt.
+    3) Issue the command: ps ax|grep daemon. This will show you the process
+       id of the program "daemon" that you just ran.
+    4) Issue the command: tail -f daemon.log. This let's you watch the log file
+       being filled with the message in the code below. Press Ctrl/c to break
+       out of the tail command.
+    5) Issue the command: kill -HUP pid. pid is the process number you saw with
+       the ps command above. You will see that a new log file has been created.
+    6) Issue the command: kill -TERM pid. This will stop the daemon. Issuing the
+       ps command above, you will see that the daemon is no longer running.
+
+-------------------------------<< REVISIONS >>--------------------------------
+  Ver  |    Date    | Prog | Decription
+-------+------------+------+--------------------------------------------------
+  1.00 | 03/21/2000 | kjw  | Initial release.
+  1.01 | 03/21/2000 | kjw  | Forgot to close input, output, & stderr.
+------------------------------------------------------------------------------
+}
+Program Daemon;
+uses linux;
+Var
+   { vars for daemonizing }
+   bHup,
+   bTerm : boolean;
+   fLog : text;
+   logname : string;
+   aOld,
+   aTerm,
+   aHup : pSigActionRec;
+   ps1  : psigset;
+   sSet : cardinal;
+   pid : longint;
+   secs : longint;
+   hr,mn,sc,sc100 : word;
+
+{ handle SIGHUP & SIGTERM }
+procedure DoSig(sig : longint);cdecl;
+begin
+   case sig of
+      SIGHUP : bHup := true;
+      SIGTERM : bTerm := true;
+   end;
+end;
+
+{ open the log file }
+Procedure NewLog;
+Begin
+   Assign(fLog,logname);
+   Rewrite(fLog);
+   GetTime(hr,mn,sc,sc100);
+   Writeln(flog,'Log created at ',hr:0,':',mn:0,':',sc:0);
+   Close(fLog);
+End;
+
+Begin
+   logname := 'daemon.log';
+   secs := 10;
+
+   { set global daemon booleans }
+   bHup := true; { to open log file }
+   bTerm := false;
+
+   { block all signals except -HUP & -TERM }
+   sSet := $ffffbffe;
+   ps1 := @sSet;
+   sigprocmask(sig_block,ps1,nil);
+
+   { setup the signal handlers }
+   new(aOld);
+   new(aHup);
+   new(aTerm);
+   aTerm^.handler.sh := @DoSig;
+   aTerm^.sa_mask := 0;
+   aTerm^.sa_flags := 0;
+   aTerm^.sa_restorer := nil;
+   aHup^.handler.sh := @DoSig;
+   aHup^.sa_mask := 0;
+   aHup^.sa_flags := 0;
+   aHup^.sa_restorer := nil;
+   SigAction(SIGTERM,aTerm,aOld);
+   SigAction(SIGHUP,aHup,aOld);
+
+   { daemonize }
+   pid := Fork;
+   Case pid of
+      0 : Begin { we are in the child }
+         Close(input);  { close standard in }
+         Close(output); { close standard out }
+         Assign(output,'/dev/null');
+         ReWrite(output);
+         Close(stderr); { close standard error }
+         Assign(stderr,'/dev/null');
+         ReWrite(stderr);
+      End;
+      -1 : secs := 0;     { forking error, so run as non-daemon }
+      Else Halt;          { successful fork, so parent dies }
+   End;
+
+   { begin processing loop }
+   Repeat
+      If bHup Then Begin
+         {$I-}
+         Close(fLog);
+         {$I+}
+         NewLog;
+         bHup := false;
+      End;
+      {----------------------}
+      { Do your daemon stuff }
+      GetTime(hr,mn,sc,sc100);
+      Append(flog);
+      Writeln(flog,'daemon code activated at ',hr:0,':',mn:0,':',sc:0);
+      Close(fLog);
+      { the following output goes to the bit bucket }
+      Writeln('daemon code activated at ',hr:0,':',mn:0,':',sc:0);
+      {----------------------}
+      If bTerm Then
+         BREAK
+      Else
+         { wait a while }
+         Select(0,nil,nil,nil,secs*1000);
+   Until bTerm;
+End.
+{
+  $Log$
+  Revision 1.1  2001-05-03 21:39:33  peter
+    * moved to own module
+
+  Revision 1.2  2000/07/13 11:33:09  michael
+  + removed logs
+ 
+}

+ 828 - 0
demo/modex/Makefile

@@ -0,0 +1,828 @@
+#
+# Don't edit, this file is generated by fpcmake v1.99.0 [2001/05/03]
+#
+default: all
+override PATH:=$(subst \,/,$(PATH))
+ifeq ($(findstring ;,$(PATH)),)
+inUnix=1
+SEARCHPATH:=$(subst :, ,$(PATH))
+else
+SEARCHPATH:=$(subst ;, ,$(PATH))
+endif
+PWD:=$(strip $(wildcard $(addsuffix /pwd.exe,$(SEARCHPATH))))
+ifeq ($(PWD),)
+PWD:=$(strip $(wildcard $(addsuffix /pwd,$(SEARCHPATH))))
+ifeq ($(PWD),)
+nopwd:
+	@echo You need the GNU utils package to use this Makefile!
+	@echo Get ftp://ftp.freepascal.org/pub/fpc/dist/go32v2/utilgo32.zip
+	@exit
+else
+PWD:=$(firstword $(PWD))
+SRCEXEEXT=
+endif
+else
+PWD:=$(firstword $(PWD))
+SRCEXEEXT=.exe
+endif
+ifndef inUnix
+ifeq ($(OS),Windows_NT)
+inWinNT=1
+else
+ifdef OS2_SHELL
+inOS2=1
+endif
+endif
+else
+ifneq ($(findstring cygwin,$(MACH_TYPE)),)
+inCygWin=1
+endif
+endif
+ifdef inUnix
+BATCHEXT=.sh
+else
+ifdef inOS2
+BATCHEXT=.cmd
+else
+BATCHEXT=.bat
+endif
+endif
+ifdef inUnix
+PATHSEP=/
+else
+PATHSEP:=$(subst /,\,/)
+endif
+ifdef PWD
+BASEDIR:=$(shell $(PWD))
+else
+BASEDIR=.
+endif
+ifndef FPC
+ifdef PP
+FPC=$(PP)
+else
+FPC=ppc386
+endif
+endif
+override FPC:=$(subst $(SRCEXEEXT),,$(FPC))
+override FPC:=$(subst \,/,$(FPC))$(SRCEXEEXT)
+ifndef OS_TARGET
+OS_TARGET:=$(shell $(FPC) -iTO)
+endif
+ifndef OS_SOURCE
+OS_SOURCE:=$(shell $(FPC) -iSO)
+endif
+ifndef CPU_TARGET
+CPU_TARGET:=$(shell $(FPC) -iTP)
+endif
+ifndef CPU_SOURCE
+CPU_SOURCE:=$(shell $(FPC) -iSP)
+endif
+ifndef FPC_VERSION
+FPC_VERSION:=$(shell $(FPC) -iV)
+endif
+export FPC OS_TARGET OS_SOURCE CPU_TARGET CPU_SOURCE FPC_VERSION
+ifdef FPCDIR
+override FPCDIR:=$(subst \,/,$(FPCDIR))
+ifeq ($(wildcard $(addprefix $(FPCDIR)/,rtl units)),)
+override FPCDIR=wrong
+endif
+else
+override FPCDIR=wrong
+endif
+ifeq ($(FPCDIR),wrong)
+override FPCDIR=../..
+ifeq ($(wildcard $(FPCDIR)/rtl),)
+ifeq ($(wildcard $(FPCDIR)/units),)
+override FPCDIR=wrong
+endif
+endif
+endif
+ifeq ($(FPCDIR),wrong)
+ifdef inUnix
+override FPCDIR=/usr/local/lib/fpc/$(FPC_VERSION)
+ifeq ($(wildcard $(FPCDIR)/units),)
+override FPCDIR=/usr/lib/fpc/$(FPC_VERSION)
+endif
+else
+override FPCDIR:=$(subst /$(FPC),,$(firstword $(strip $(wildcard $(addsuffix /$(FPC),$(SEARCHPATH))))))
+override FPCDIR:=$(FPCDIR)/..
+ifeq ($(wildcard $(addprefix $(FPCDIR)/,rtl units)),)
+override FPCDIR:=$(FPCDIR)/..
+ifeq ($(wildcard $(addprefix $(FPCDIR)/,rtl units)),)
+override FPCDIR=c:/pp
+endif
+endif
+endif
+endif
+UNITSDIR:=$(wildcard $(FPCDIR)/units/$(OS_TARGET))
+PACKAGESDIR:=$(wildcard $(FPCDIR) $(FPCDIR)/packages)
+ifeq ($(OS_TARGET),go32v2)
+override TARGET_PROGRAMS+=voxel
+endif
+ifndef ECHO
+ECHO:=$(strip $(wildcard $(addsuffix /gecho$(EXEEXT),$(SEARCHPATH))))
+ifeq ($(ECHO),)
+ECHO:=$(strip $(wildcard $(addsuffix /echo$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(ECHO),)
+ECHO:=echo
+else
+ECHO:=$(firstword $(ECHO))
+endif
+else
+ECHO:=$(firstword $(ECHO))
+endif
+endif
+ifndef COPY
+COPY:=cp -fp
+endif
+ifndef COPYTREE
+COPYTREE:=cp -rfp
+endif
+ifndef MOVE
+MOVE:=mv -f
+endif
+ifndef DEL
+DEL:=rm -f
+endif
+ifndef DELTREE
+DELTREE:=rm -rf
+endif
+ifndef INSTALL
+ifdef inUnix
+INSTALL:=install -c -m 644
+else
+INSTALL:=$(COPY)
+endif
+endif
+ifndef INSTALLEXE
+ifdef inUnix
+INSTALLEXE:=install -c -m 755
+else
+INSTALLEXE:=$(COPY)
+endif
+endif
+ifndef MKDIR
+ifdef inUnix
+MKDIR:=install -m 755 -d
+else
+MKDIR:=ginstall -m 755 -d
+endif
+endif
+export ECHO COPY COPYTREE MOVE DEL DELTREE INSTALL INSTALLEXE MKDIR
+ifndef AS
+AS=as
+endif
+ifndef LD
+LD=ld
+endif
+ifndef RC
+RC=rc
+endif
+PPAS=ppas$(BATCHEXT)
+ifdef inUnix
+LDCONFIG=ldconfig
+else
+LDCONFIG=
+endif
+ifndef PPUMOVE
+PPUMOVE:=$(strip $(wildcard $(addsuffix /ppumove$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(PPUMOVE),)
+PPUMOVE=
+else
+PPUMOVE:=$(firstword $(PPUMOVE))
+endif
+endif
+export PPUMOVE
+ifndef PPUFILES
+PPUFILES:=$(strip $(wildcard $(addsuffix /ppufiles$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(PPUFILES),)
+PPUFILES=
+else
+PPUFILES:=$(firstword $(PPUFILES))
+endif
+endif
+export PPUFILES
+ifndef DATE
+DATE:=$(strip $(wildcard $(addsuffix /date$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(DATE),)
+DATE:=$(strip $(wildcard $(addsuffix /gdate$(SRCEXEEXT),$(SEACHPATH))))
+ifeq ($(DATE),)
+DATE=
+else
+DATE:=$(firstword $(DATE))
+endif
+else
+DATE:=$(firstword $(DATE))
+endif
+endif
+export DATE
+ifdef DATE
+DATESTR:=$(shell $(DATE) +%Y%m%d)
+else
+DATESTR=
+endif
+ifndef UPXPROG
+ifeq ($(OS_TARGET),go32v2)
+UPXPROG:=1
+endif
+ifeq ($(OS_TARGET),win32)
+UPXPROG:=1
+endif
+ifdef UPXPROG
+UPXPROG:=$(strip $(wildcard $(addsuffix /upx$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(UPXPROG),)
+UPXPROG=
+else
+UPXPROG:=$(firstword $(UPXPROG))
+endif
+else
+UPXPROG=
+endif
+endif
+export UPXPROG
+ifndef ZIPPROG
+ZIPPROG:=$(strip $(wildcard $(addsuffix /zip$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(ZIPPROG),)
+ZIPPROG=
+else
+ZIPPROG:=$(firstword $(ZIPPROG))
+endif
+endif
+export ZIPPROG
+ZIPOPT=-9
+ZIPEXT=.zip
+ifndef TARPROG
+TARPROG:=$(strip $(wildcard $(addsuffix /tar$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(TARPROG),)
+TARPROG=
+else
+TARPROG:=$(firstword $(TARPROG))
+endif
+endif
+export TARPROG
+ifeq ($(USETAR),bz2)
+TAROPT=vI
+TAREXT=.tar.bz2
+else
+TAROPT=vz
+TAREXT=.tar.gz
+endif
+LOADEREXT=.as
+EXEEXT=.exe
+PPLEXT=.ppl
+PPUEXT=.ppu
+OEXT=.o
+ASMEXT=.s
+SMARTEXT=.sl
+STATICLIBEXT=.a
+SHAREDLIBEXT=.so
+LIBPREFIX=lib
+RSTEXT=.rst
+FPCMADE=fpcmade
+ifeq ($(OS_TARGET),go32v1)
+PPUEXT=.pp1
+OEXT=.o1
+ASMEXT=.s1
+SMARTEXT=.sl1
+STATICLIBEXT=.a1
+SHAREDLIBEXT=.so1
+LIBPREFIX=
+FPCMADE=fpcmade.v1
+PACKAGESUFFIX=v1
+endif
+ifeq ($(OS_TARGET),go32v2)
+LIBPREFIX=
+FPCMADE=fpcmade.dos
+ZIPSUFFIX=go32
+endif
+ifeq ($(OS_TARGET),linux)
+EXEEXT=
+HASSHAREDLIB=1
+FPCMADE=fpcmade.lnx
+ZIPSUFFIX=linux
+endif
+ifeq ($(OS_TARGET),freebsd)
+EXEEXT=
+HASSHAREDLIB=1
+FPCMADE=fpcmade.freebsd
+ZIPSUFFIX=freebsd
+endif
+ifeq ($(OS_TARGET),win32)
+PPUEXT=.ppw
+OEXT=.ow
+ASMEXT=.sw
+SMARTEXT=.slw
+STATICLIBEXT=.aw
+SHAREDLIBEXT=.dll
+FPCMADE=fpcmade.w32
+ZIPSUFFIX=w32
+endif
+ifeq ($(OS_TARGET),os2)
+PPUEXT=.ppo
+ASMEXT=.so2
+OEXT=.oo2
+AOUTEXT=.out
+SMARTEXT=.so
+STATICLIBEXT=.ao2
+SHAREDLIBEXT=.dll
+FPCMADE=fpcmade.os2
+ZIPSUFFIX=emx
+endif
+ifdef REQUIRE_UNITSDIR
+override UNITSDIR+=$(REQUIRE_UNITSDIR)
+endif
+ifdef REQUIRE_PACKAGESDIR
+override PACKAGESDIR+=$(REQUIRE_PACKAGESDIR)
+endif
+ifdef ZIPINSTALL
+ifeq ($(OS_TARGET),linux)
+UNIXINSTALLDIR=1
+endif
+ifeq ($(OS_TARGET),freebsd)
+UNIXINSTALLDIR=1
+endif
+else
+ifeq ($(OS_SOURCE),linux)
+UNIXINSTALLDIR=1
+endif
+ifeq ($(OS_SOURCE),freebsd)
+UNIXINSTALLDIR=1
+endif
+endif
+ifndef INSTALL_PREFIX
+ifdef UNIXINSTALLDIR
+INSTALL_PREFIX=/usr/local
+else
+ifdef INSTALL_FPCPACKAGE
+INSTALL_BASEDIR:=/pp
+else
+INSTALL_BASEDIR:=/$(PACKAGE_NAME)
+endif
+endif
+endif
+export INSTALL_PREFIX
+ifndef DIST_DESTDIR
+DIST_DESTDIR:=$(BASEDIR)
+endif
+export DIST_DESTDIR
+ifndef INSTALL_BASEDIR
+ifdef UNIXINSTALLDIR
+ifdef INSTALL_FPCPACKAGE
+INSTALL_BASEDIR:=$(INSTALL_PREFIX)/lib/fpc/$(FPC_VERSION)
+else
+INSTALL_BASEDIR:=$(INSTALL_PREFIX)/lib/$(PACKAGE_NAME)
+endif
+else
+INSTALL_BASEDIR:=$(INSTALL_PREFIX)
+endif
+endif
+ifndef INSTALL_BINDIR
+ifdef UNIXINSTALLDIR
+INSTALL_BINDIR:=$(INSTALL_PREFIX)/bin
+else
+INSTALL_BINDIR:=$(INSTALL_BASEDIR)/bin
+ifdef INSTALL_FPCPACKAGE
+INSTALL_BINDIR:=$(INSTALL_BINDIR)/$(OS_TARGET)
+endif
+endif
+endif
+ifndef INSTALL_UNITDIR
+INSTALL_UNITDIR:=$(INSTALL_BASEDIR)/units/$(OS_TARGET)
+ifdef INSTALL_FPCPACKAGE
+INSTALL_UNITDIR:=$(INSTALL_UNITDIR)/$(PACKAGE_NAME)
+endif
+endif
+ifndef INSTALL_LIBDIR
+ifdef UNIXINSTALLDIR
+INSTALL_LIBDIR:=$(INSTALL_PREFIX)/lib
+else
+INSTALL_LIBDIR:=$(INSTALL_UNITDIR)
+endif
+endif
+ifndef INSTALL_SOURCEDIR
+ifdef UNIXINSTALLDIR
+ifdef INSTALL_FPCPACKAGE
+INSTALL_SOURCEDIR:=$(INSTALL_PREFIX)/src/fpc-$(FPC_VERSION)/$(PACKAGE_NAME)
+else
+INSTALL_SOURCEDIR:=$(INSTALL_PREFIX)/src/$(PACKAGE_NAME)-$(PACKAGE_VERSION)
+endif
+else
+ifdef INSTALL_FPCPACKAGE
+INSTALL_SOURCEDIR:=$(INSTALL_BASEDIR)/source/$(PACKAGE_NAME)
+else
+INSTALL_SOURCEDIRL:=$(INSTALL_BASEDIR)/source
+endif
+endif
+endif
+ifndef INSTALL_DOCDIR
+ifdef UNIXINSTALLDIR
+ifdef INSTALL_FPCPACKAGE
+INSTALL_DOCDIR:=$(INSTALL_PREFIX)/doc/fpc-$(FPC_VERSION)/$(PACKAGE_NAME)
+else
+INSTALL_DOCDIR:=$(INSTALL_PREFIX)/doc/$(PACKAGE_NAME)-$(PACKAGE_VERSION)
+endif
+else
+ifdef INSTALL_FPCPACKAGE
+INSTALL_DOCDIR:=$(INSTALL_BASEDIR)/doc/$(PACKAGE_NAME)
+else
+INSTALL_DOCDIR:=$(INSTALL_BASEDIR)/doc
+endif
+endif
+endif
+ifndef INSTALL_EXAMPLEDIR
+ifdef UNIXINSTALLDIR
+ifdef INSTALL_FPCPACKAGE
+INSTALL_EXAMPLEDIR:=$(INSTALL_PREFIX)/doc/fpc-$(FPC_VERSION)/examples/$(PACKAGE_NAME)
+else
+INSTALL_EXAMPLEDIR:=$(INSTALL_PREFIX)/doc/$(PACKAGE_NAME)-$(PACKAGE_VERSION)
+endif
+else
+ifdef INSTALL_FPCPACKAGE
+INSTALL_EXAMPLEDIR:=$(INSTALL_BASEDIR)/examples/$(PACKAGE_NAME)
+else
+INSTALL_EXAMPLEDIR:=$(INSTALL_BASEDIR)/examples
+endif
+endif
+endif
+ifndef INSTALL_DATADIR
+INSTALL_DATADIR=$(INSTALL_BASEDIR)
+endif
+ifeq ($(OS_TARGET),linux)
+REQUIRE_PACKAGES_RTL=1
+endif
+ifeq ($(OS_TARGET),go32v2)
+REQUIRE_PACKAGES_RTL=1
+endif
+ifeq ($(OS_TARGET),win32)
+REQUIRE_PACKAGES_RTL=1
+endif
+ifeq ($(OS_TARGET),os2)
+REQUIRE_PACKAGES_RTL=1
+endif
+ifeq ($(OS_TARGET),freebsd)
+REQUIRE_PACKAGES_RTL=1
+endif
+ifdef REQUIRE_PACKAGES_RTL
+PACKAGEDIR_RTL:=$(subst /Makefile.fpc,,$(strip $(wildcard $(addsuffix /rtl/Makefile.fpc,$(PACKAGESDIR)))))
+ifneq ($(PACKAGEDIR_RTL),)
+PACKAGEDIR_RTL:=$(firstword $(PACKAGEDIR_RTL))
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=package_rtl
+package_rtl:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+ifneq ($(wildcard $(PACKAGEDIR_RTL)/$(OS_TARGET)),)
+UNITDIR_RTL=$(PACKAGEDIR_RTL)/$(OS_TARGET)
+else
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+endif
+else
+PACKAGEDIR_RTL=
+UNITDIR_RTL:=$(subst /Package.fpc,,$(strip $(wildcard $(addsuffix /rtl/Package.fpc,$(UNITSDIR)))))
+ifneq ($(UNITDIR_RTL),)
+UNITDIR_RTL:=$(firstword $(UNITDIR_RTL))
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override COMPILER_UNITDIR+=$(UNITDIR_RTL)
+endif
+endif
+.PHONY: package_rtl
+override FPCOPTDEF=$(CPU_TARGET)
+ifneq ($(OS_TARGET),$(OS_SOURCE))
+override FPCOPT+=-T$(OS_TARGET)
+endif
+ifdef UNITDIR
+override FPCOPT+=$(addprefix -Fu,$(UNITDIR))
+endif
+ifdef LIBDIR
+override FPCOPT+=$(addprefix -Fl,$(LIBDIR))
+endif
+ifdef OBJDIR
+override FPCOPT+=$(addprefix -Fo,$(OBJDIR))
+endif
+ifdef INCDIR
+override FPCOPT+=$(addprefix -Fi,$(INCDIR))
+endif
+ifdef LINKSMART
+override FPCOPT+=-XX
+endif
+ifdef CREATESMART
+override FPCOPT+=-CX
+endif
+ifdef DEBUG
+override FPCOPT+=-gl
+override FPCOPTDEF+=DEBUG
+endif
+ifdef RELEASE
+override FPCOPT+=-Xs -OG2p3 -n
+override FPCOPTDEF+=RELEASE
+endif
+ifdef STRIP
+override FPCOPT+=-Xs
+endif
+ifdef OPTIMIZE
+override FPCOPT+=-OG2p3
+endif
+ifdef VERBOSE
+override FPCOPT+=-vwni
+endif
+ifdef COMPILER_OPTIONS
+override FPCOPT+=$(COMPILER_OPTIONS)
+endif
+ifdef COMPILER_UNITDIR
+override FPCOPT+=$(addprefix -Fu,$(COMPILER_UNITDIR))
+endif
+ifdef COMPILER_LIBRARYDIR
+override FPCOPT+=$(addprefix -Fl,$(COMPILER_LIBRARYDIR))
+endif
+ifdef COMPILER_OBJECTDIR
+override FPCOPT+=$(addprefix -Fo,$(COMPILER_OBJECTDIR))
+endif
+ifdef COMPILER_INCLUDEDIR
+override FPCOPT+=$(addprefix -Fi,$(COMPILER_INCLUDEDIR))
+endif
+ifdef COMPILER_TARGETDIR
+override FPCOPT+=-FE$(COMPILER_TARGETDIR)
+ifeq ($(COMPILER_TARGETDIR),.)
+override TARGETDIRPREFIX=
+else
+override TARGETDIRPREFIX=$(COMPILER_TARGETDIR)/
+endif
+endif
+ifdef COMPILER_UNITTARGETDIR
+override FPCOPT+=-FU$(COMPILER_UNITTARGETDIR)
+ifeq ($(COMPILER_UNITTARGETDIR),.)
+override UNITTARGETDIRPREFIX=
+else
+override UNITTARGETDIRPREFIX=$(COMPILER_TARGETDIR)/
+endif
+else
+ifdef COMPILER_TARGETDIR
+override COMPILER_UNITTARGETDIR=$(COMPILER_TARGETDIR)
+override UNITTARGETDIRPREFIX=$(TARGETDIRPREFIX)
+endif
+endif
+ifdef OPT
+override FPCOPT+=$(OPT)
+endif
+ifdef FPCOPTDEF
+override FPCOPT+=$(addprefix -d,$(FPCOPTDEF))
+endif
+ifdef CFGFILE
+override FPCOPT+=@$(CFGFILE)
+endif
+ifeq ($(OS_SOURCE),win32)
+USEENV=1
+endif
+ifdef USEENV
+override FPCEXTCMD:=$(FPCOPT)
+override FPCOPT:=!FPCEXTCMD
+export FPCEXTCMD
+endif
+override COMPILER:=$(FPC) $(FPCOPT)
+ifeq (,$(findstring -s ,$(COMPILER)))
+EXECPPAS=
+else
+ifeq ($(OS_SOURCE),$(OS_TARGET))
+EXECPPAS:=@$(PPAS)
+endif
+endif
+.PHONY: fpc_exes
+ifdef TARGET_PROGRAMS
+override EXEFILES=$(addsuffix $(EXEEXT),$(TARGET_PROGRAMS))
+override EXEOFILES:=$(addsuffix $(OEXT),$(TARGET_PROGRAMS)) $(addprefix $(LIBPREFIX),$(addsuffix $(STATICLIBEXT),$(TARGET_PROGRAMS)))
+override ALLTARGET+=fpc_exes
+override INSTALLEXEFILES+=$(EXEFILES)
+override CLEANEXEFILES+=$(EXEFILES) $(EXEOFILES)
+ifeq ($(OS_TARGET),os2)
+override CLEANEXEFILES+=$(addsuffix $(AOUTEXT),$(TARGET_PROGRAMS))
+endif
+endif
+fpc_exes: $(EXEFILES)
+.PHONY: fpc_packages fpc_all fpc_smart fpc_debug
+$(FPCMADE): $(ALLTARGET)
+	@$(ECHO) Compiled > $(FPCMADE)
+fpc_packages: $(COMPILEPACKAGES)
+fpc_all: fpc_packages $(FPCMADE)
+fpc_smart:
+	$(MAKE) all LINKSMART=1 CREATESMART=1
+fpc_debug:
+	$(MAKE) all DEBUG=1
+.SUFFIXES: $(EXEEXT) $(PPUEXT) $(OEXT) .pas .pp
+%$(PPUEXT): %.pp
+	$(COMPILER) $<
+	$(EXECPPAS)
+%$(PPUEXT): %.pas
+	$(COMPILER) $<
+	$(EXECPPAS)
+%$(EXEEXT): %.pp
+	$(COMPILER) $<
+	$(EXECPPAS)
+%$(EXEEXT): %.pas
+	$(COMPILER) $<
+	$(EXECPPAS)
+vpath %.pp $(COMPILER_SOURCEDIR) $(COMPILER_INCLUDEDIR)
+vpath %.pas $(COMPILER_SOURCEDIR) $(COMPILER_INCLUDEDIR)
+vpath %$(PPUEXT) $(COMPILER_UNITTARGETDIR)
+.PHONY: fpc_install fpc_sourceinstall fpc_exampleinstall
+ifdef INSTALL_UNITS
+override INSTALLPPUFILES+=$(addsuffix $(PPUEXT),$(INSTALL_UNITS))
+endif
+ifdef INSTALLPPUFILES
+ifdef PPUFILES
+override INSTALLPPUFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(INSTALLPPUFILES))
+override INSTALLPPULINKFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(shell $(PPUFILES) -S -O $(INSTALLPPUFILES)))
+else
+override INSTALLPPULINKFILES:=$(subst $(PPUEXT),$(OEXT),$(INSTALLPPUFILES)) $(addprefix $(LIBPREFIX),$(subst $(PPUEXT),$(STATICLIBEXT),$(INSTALLPPUFILES)))
+override INSTALLPPUFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(INSTALLPPUFILES))
+override INSTALLPPULINKFILES:=$(wildcard $(addprefix $(UNITTARGETDIRPREFIX),$(INSTALLPPULINKFILES)))
+endif
+endif
+ifdef INSTALLEXEFILES
+override INSTALLEXEFILES:=$(addprefix $(TARGETDIRPREFIX),$(INSTALLEXEFILES))
+endif
+fpc_install: $(INSTALLTARGET)
+ifdef INSTALLEXEFILES
+	$(MKDIR) $(INSTALL_BINDIR)
+ifdef UPXPROG
+	-$(UPXPROG) $(INSTALLEXEFILES)
+endif
+	$(INSTALLEXE) $(INSTALLEXEFILES) $(INSTALL_BINDIR)
+endif
+ifdef INSTALLPPUFILES
+	$(MKDIR) $(INSTALL_UNITDIR)
+	$(INSTALL) $(INSTALLPPUFILES) $(INSTALL_UNITDIR)
+ifneq ($(INSTALLPPULINKFILES),)
+	$(INSTALL) $(INSTALLPPULINKFILES) $(INSTALL_UNITDIR)
+endif
+ifneq ($(wildcard $(LIB_FULLNAME)),)
+	$(MKDIR) $(INSTALL_LIBDIR)
+	$(INSTALL) $(LIB_FULLNAME) $(INSTALL_LIBDIR)
+ifdef inUnix
+	ln -sf $(LIB_FULLNAME) $(INSTALL_LIBDIR)/$(LIB_NAME)
+endif
+endif
+endif
+ifdef INSTALL_FILES
+	$(MKDIR) $(INSTALL_DATADIR)
+	$(INSTALL) $(INSTALL_FILES) $(INSTALL_DATADIR)
+endif
+fpc_sourceinstall: distclean
+	$(MKDIR) $(INSTALL_SOURCEDIR)
+	$(COPYTREE) $(BASEDIR) $(INSTALL_SOURCEDIR)
+fpc_exampleinstall: $(addsuffix _distclean,$(TARGET_EXAMPLEDIRS))
+ifdef HASEXAMPLES
+	$(MKDIR) $(INSTALL_EXAMPLEDIR)
+endif
+ifdef EXAMPLESOURCEFILES
+	$(COPY) $(EXAMPLESOURCEFILES) $(INSTALL_EXAMPLEDIR)
+endif
+ifdef TARGET_EXAMPLEDIRS
+	$(COPYTREE) $(addsuffix /*,$(TARGET_EXAMPLEDIRS)) $(INSTALL_EXAMPLEDIR)
+endif
+fpc_distinstall: install exampleinstall
+.PHONY: fpc_clean fpc_cleanall fpc_distclean
+ifdef EXEFILES
+override CLEANEXEFILES:=$(addprefix $(TARGETDIRPREFIX),$(CLEANEXEFILES))
+endif
+ifdef CLEAN_UNITS
+override CLEANPPUFILES+=$(addsuffix $(PPUEXT),$(CLEAN_UNITS))
+endif
+ifdef CLEANPPUFILES
+override CLEANPPUFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(CLEANPPUFILES))
+ifdef PPUFILES
+CLEANPPULINKFILES:=$(shell $(PPUFILES) $(CLEANPPUFILES))
+else
+CLEANPPULINKFILES:=$(wildcard $(subst $(PPUEXT),$(OEXT),$(CLEANPPUFILES)) $(addprefix $(LIBPREFIX),$(subst $(PPUEXT),$(STATICLIBEXT),$(CLEANPPUFILES))))
+endif
+override CLEANPPULINKFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(CLEANPPULINKFILES))
+endif
+fpc_clean: $(CLEANTARGET)
+ifdef CLEANEXEFILES
+	-$(DEL) $(CLEANEXEFILES)
+endif
+ifdef CLEANPPUFILES
+	-$(DEL) $(CLEANPPUFILES)
+endif
+ifneq ($(CLEANPPULINKFILES),)
+	-$(DEL) $(CLEANPPULINKFILES)
+endif
+ifdef CLEANRSTFILES
+	-$(DEL) $(addprefix $(UNITTARGETDIRPREFIX),$(CLEANRSTFILES))
+endif
+ifdef CLEAN_FILES
+	-$(DEL) $(CLEAN_FILES)
+endif
+ifdef LIB_NAME
+	-$(DEL) $(LIB_NAME) $(LIB_FULLNAME)
+endif
+	-$(DEL) $(FPCMADE) $(PPAS) link.res $(FPCEXTFILE) $(REDIRFILE)
+fpc_distclean: clean
+ifdef COMPILER_UNITTARGETDIR
+TARGETDIRCLEAN=fpc_clean
+endif
+fpc_cleanall: $(CLEANTARGET) $(TARGETDIRCLEAN)
+ifdef CLEANEXEFILES
+	-$(DEL) $(CLEANEXEFILES)
+endif
+	-$(DEL) *$(OEXT) *$(PPUEXT) *$(RSTEXT) *$(ASMEXT) *$(STATICLIBEXT) *$(SHAREDLIBEXT) *$(PPLEXT)
+	-$(DELTREE) *$(SMARTEXT)
+	-$(DEL) $(FPCMADE) $(PPAS) link.res $(FPCEXTFILE) $(REDIRFILE)
+ifdef AOUTEXT
+	-$(DEL) *$(AOUTEXT)
+endif
+.PHONY: fpc_info
+fpc_info:
+	@$(ECHO)
+	@$(ECHO)  == Package info ==
+	@$(ECHO)  Package Name..... $(PACKAGE_NAME)
+	@$(ECHO)  Package Version.. $(PACKAGE_VERSION)
+	@$(ECHO)
+	@$(ECHO)  == Configuration info ==
+	@$(ECHO)
+	@$(ECHO)  FPC.......... $(FPC)
+	@$(ECHO)  FPC Version.. $(FPC_VERSION)
+	@$(ECHO)  Source CPU... $(CPU_SOURCE)
+	@$(ECHO)  Target CPU... $(CPU_TARGET)
+	@$(ECHO)  Source OS.... $(OS_SOURCE)
+	@$(ECHO)  Target OS.... $(OS_TARGET)
+	@$(ECHO)
+	@$(ECHO)  == Directory info ==
+	@$(ECHO)
+	@$(ECHO)  Basedir......... $(BASEDIR)
+	@$(ECHO)  FPCDir.......... $(FPCDIR)
+	@$(ECHO)  UnitsDir........ $(UNITSDIR)
+	@$(ECHO)  PackagesDir..... $(PACKAGESDIR)
+	@$(ECHO)
+	@$(ECHO)  GCC library..... $(GCCLIBDIR)
+	@$(ECHO)  Other library... $(OTHERLIBDIR)
+	@$(ECHO)
+	@$(ECHO)  == Tools info ==
+	@$(ECHO)
+	@$(ECHO)  Pwd....... $(PWD)
+	@$(ECHO)  Echo...... $(ECHO)
+	@$(ECHO)  PPUMove... $(PPUMOVE)
+	@$(ECHO)  PPUFiles.. $(PPUFILES)
+	@$(ECHO)  Date...... $(DATE)
+	@$(ECHO)  Upx....... $(UPXPROG)
+	@$(ECHO)  Zip....... $(ZIPPROG)
+	@$(ECHO)
+	@$(ECHO)  == Object info ==
+	@$(ECHO)
+	@$(ECHO)  Target Loaders...... $(TARGET_LOADERS)
+	@$(ECHO)  Target Units........ $(TARGET_UNITS)
+	@$(ECHO)  Target Programs..... $(TARGET_PROGRAMS)
+	@$(ECHO)  Target Dirs......... $(TARGET_DIRS)
+	@$(ECHO)  Target Examples..... $(TARGET_EXAMPLES)
+	@$(ECHO)  Target ExampleDirs.. $(TARGET_EXAMPLEDIRS)
+	@$(ECHO)
+	@$(ECHO)  Clean Units......... $(CLEAN_UNITS)
+	@$(ECHO)  Clean Files......... $(CLEAN_FILES)
+	@$(ECHO)
+	@$(ECHO)  Install Units....... $(INSTALL_UNITS)
+	@$(ECHO)  Install Files....... $(INSTALL_FILES)
+	@$(ECHO)
+	@$(ECHO)  == Install info ==
+	@$(ECHO)
+	@$(ECHO)  DateStr.............. $(DATESTR)
+	@$(ECHO)  ZipPrefix............ $(ZIPPREFIX)
+	@$(ECHO)  ZipSuffix............ $(ZIPSUFFIX)
+	@$(ECHO)  Install FPC Package.. $(INSTALL_FPCPACKAGE)
+	@$(ECHO)
+	@$(ECHO)  Install base dir..... $(INSTALL_BASEDIR)
+	@$(ECHO)  Install binary dir... $(INSTALL_BINDIR)
+	@$(ECHO)  Install library dir.. $(INSTALL_LIBDIR)
+	@$(ECHO)  Install units dir.... $(INSTALL_UNITDIR)
+	@$(ECHO)  Install source dir... $(INSTALL_SOURCEDIR)
+	@$(ECHO)  Install doc dir...... $(INSTALL_DOCDIR)
+	@$(ECHO)  Install example dir.. $(INSTALL_EXAMPLEDIR)
+	@$(ECHO)  Install data dir..... $(INSTALL_DATADIR)
+	@$(ECHO)
+	@$(ECHO)  Dist destination dir. $(DIST_DESTDIR)
+	@$(ECHO)  Dist zip name........ $(DIST_ZIPNAME)
+	@$(ECHO)
+all: fpc_all
+debug: fpc_debug
+examples: fpc_examples
+smart: fpc_smart
+shared: fpc_shared
+install: fpc_install
+sourceinstall: fpc_sourceinstall
+exampleinstall: fpc_exampleinstall
+distinstall: fpc_distinstall
+zipinstall:
+zipsourceinstall:
+zipexampleinstall:
+zipdistinstall:
+clean: fpc_clean
+distclean: fpc_distclean
+cleanall: fpc_cleanall
+info: fpc_info
+.PHONY: all debug examples smart shared install sourceinstall exampleinstall distinstall zipinstall zipsourceinstall zipexampleinstall zipdistinstall clean distclean cleanall info
+ifneq ($(wildcard fpcmake.loc),)
+include fpcmake.loc
+endif

+ 9 - 0
demo/modex/Makefile.fpc

@@ -0,0 +1,9 @@
+#
+#   Makefile.fpc for FPC modex demos (part of FPC demo paackage)
+#
+
+[target]
+programs_go32v2=voxel
+
+[default]
+fpcdir=../..

+ 52 - 0
demo/modex/fpcmodex.txt

@@ -0,0 +1,52 @@
+The FPC ModeX docs...
+
+--------------------------------------------------------------------
+NOTICE:
+
+The ported programs (see below) were found on a site that claims to only have
+PD stuff, and the webmaster said that everything he published was sent to
+him with that purpose. We tried finding the persons mentioned in the mail
+over internet, but that failed.
+
+If there is somebody that claims authorship of these programs, please mail
[email protected], and the sources will be removed from our websites.
+
+--------------------------------------------------------------------
+REQUEST:
+
+As a developper team, we don't want spend 90% of our time in creating demoes.
+If you have something nice, which explains not yet demonstrated features or
+technicques, mail contact us via [email protected], or add it to the
+contrib page.
+The readers are also encouraged to explore FPC's excellent documentation
+with many examples!!!!!
+
+------------------------------------------------------------------------------
+What are the FPC ModeX programs?
+
+The FPC ModeX programs are a series of simple, small programs written or
+ported by Marco van de Voort ([email protected]) as demos for the
+Free Pascal compiler (FPC) and its Run Time Libraries (RTL).
+The "ported" programs were first used to test the compability of the GRAPH
+unit. Since we had them, and they were very likely PD or GPL, we decided
+to use them when we couldn't contact the authors
+
+- Voxel (Marcin Borkowski or Bas van Gaalen, depends on src)
+  Displays a landscape in which you can move.
+
+-------------
+Voxel, more a demo than a game.
+
+A program I already ported to M2 once. Also from SWAG I believe, but it
+has been cycling FIDOnets Pascal areas for years.
+
+The program displays a landscape in which you can move with the cursor keys.
+Exit with ESCAPE. A flabbergasting effect in just 150 lines.
+
+TODO:
+- Higher resolution (LFB) graphics?
+
+HISTORY
+ v0.01 :
+       - Initial FPC port.
+

+ 179 - 0
demo/modex/voxel.pp

@@ -0,0 +1,179 @@
+{
+    $Id$
+
+    This program is part of the FPC demoes.
+    Copyright (C) 1999 by Marco van de Voort
+
+    A port of a more "dirty" graphical program, to demonstrate
+    some Go32 features. The program displays a landscape in which
+    you can move with the cursorkeys
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************
+
+The sources for this game was found in SWAG, and was also posted to the
+International FIDO Pascal area.
+I assume that it is PD (both sources said nothing about the form of copyrights,
+but it was contributed to SWAG, which is generally PD)
+
+If there is somebody that claims authorship of these programs,
+please mail [email protected], and the sources will be removed from our
+websites.
+
+------------------------------------------------------------------------
+There was no real original, I reconstructed some from several versions.
+
+A voxel source from Swag patched for FPC.
+
+- The original author was unknown. I saw a different version which named
+  "Borek" (Marcin Borkowski), 2:480/25  as author.
+- Bas van Gaalen donated it to SWAG.
+- I, Marco van de Voort made some small FPC adjustments.
+- However one problem remained (wrapping of arrays), and Jonas Maebe mailed me
+   that glitch to me. This practically meant putting all those WORD()
+   typecasts in the array-parameters.
+
+Still BP compatible, Gameunit contains some BP alternatives for Go32
+procedures needed.}
+
+PROGRAM voxel;
+
+
+USES Crt,Dos {$IFDEF FPC}, Go32{$ENDIF};
+
+type lrgarr=array[0..65534] of byte;
+const
+ pal:array[1..384] of byte=(
+  0,0,0,48,48,48,1,0,43,1,3,43,2,5,44,2,7,44,3,9,45,4,11,46,5,13,47,6,15,48,
+  7,17,49,8,19,50,9,21,51,10,22,52,11,24,52,12,26,54,13,28,54,14,30,56,15,32,
+  56,16,34,58,17,34,58,17,36,58,18,38,60,19,40,60,20,42,62,21,44,62,10,31,0,
+  11,31,0,11,31,1,11,32,1,12,32,1,12,32,2,12,33,2,13,33,2,14,33,3,15,33,3,15,
+  34,3,15,34,4,15,35,4,16,35,4,16,35,5,16,36,5,17,36,5,17,36,6,18,37,6,18,38,
+  7,19,38,8,20,39,8,20,40,9,21,40,10,22,41,10,22,42,11,23,42,12,24,43,12,24,
+  44,13,25,44,14,25,45,14,26,46,15,27,46,16,27,47,17,28,47,18,28,48,19,29,49,
+  19,30,49,20,30,50,21,31,51,21,32,51,22,32,52,23,33,53,23,34,53,24,34,54,25,
+  35,55,25,36,55,26,36,56,27,37,57,27,38,57,27,39,57,27,41,57,27,42,57,27,43,
+  57,27,44,57,27,45,57,27,46,57,27,47,57,27,49,57,27,50,57,27,51,57,27,52,57,
+  27,53,57,27,55,57,27,56,57,27,57,57,27,58,57,27,58,57,26,58,57,25,58,57,24,
+  58,56,23,58,55,22,58,54,20,58,53,19,58,51,18,58,50,17,58,50,16,58,49,15,58,
+  48,14,58,47,13,58,46,12,58,45,11,58,44,11,58,44,10,58,43,10,58,42,9,57,41,
+  8,57,40,8,56,39,7,56,38,6,55,37,5,55,35,4,54,33,4,54,31,2,32,32,32,63,63,63,
+  63,63,63,63,63,63,63,63,63,48,48,48,63,63,63,63,63,63);
+
+VAR
+  MP,Scr      : ^lrgarr;
+  rng         : array[0..320] of byte;
+  dir,i,x,y   : integer;
+
+function ncol(mc,n,dvd:integer):integer;
+var loc:integer;
+begin
+  loc:=(mc+n-random(2*n)) div dvd; ncol:=loc;
+  if loc>250 then ncol:=250; if loc<5 then ncol:=5
+end;
+
+procedure plasma(x1,y1,x2,y2:word);
+var xn,yn,dxy,p1,p2,p3,p4:word;
+begin
+  if (x2-x1<2) and (y2-y1<2) then
+   exit;
+  p1:=mp^[WORD(256*y1+x1)]; p2:=mp^[WORD(256*y2+x1)]; p3:=mp^[WORD(256*y1+x2)];
+  p4:=mp^[WORD(256*y2+x2)]; xn:=(x2+x1) shr 1; yn:=(y2+y1) shr 1;
+  dxy:=5*(x2-x1+y2-y1) div 3;
+  if mp^[WORD(256*y1+xn)]=0 then mp^[WORD(256*y1+xn)]:=ncol(p1+p3,dxy,2);
+  if mp^[WORD(256*yn+x1)]=0 then mp^[WORD(256*yn+x1)]:=ncol(p1+p2,dxy,2);
+  if mp^[WORD(256*yn+x2)]=0 then mp^[WORD(256*yn+x2)]:=ncol(p3+p4,dxy,2);
+  if mp^[WORD(256*y2+xn)]=0 then mp^[WORD(256*y2+xn)]:=ncol(p2+p4,dxy,2);
+  mp^[WORD(256*yn+xn)]:=ncol(p1+p2+p3+p4,dxy,4);
+  plasma(x1,y1,xn,yn); plasma(xn,y1,x2,yn);
+  plasma(x1,yn,xn,y2); plasma(xn,yn,x2,y2);
+end;
+
+procedure draw(xp,yp,dir:integer);
+var z,zobs,ix,iy,iy1,iyp,ixp,x,y,s,csf,snf,mpc,i,j:integer;
+begin
+  fillchar(rng,sizeof(rng),200); zobs:=100+mp^[WORD(256*yp+xp)];
+  csf:=round(256*cos(Real(dir)/180*pi)); snf:=round(256*sin(Real(dir)/180*pi));
+  fillchar(scr^,64000,0);
+  for iy:=yp to yp+55 do
+   begin
+    iy1:=1+2*(iy-yp); s:=4+300 div iy1;
+    for ix:=xp+yp-iy to xp-yp+iy do
+     begin
+      ixp:=xp+((ix-xp)*csf+(iy-yp)*snf) shr 8;
+      iyp:=yp+((iy-yp)*csf-(ix-xp)*snf) shr 8;
+      x:=160+360*(ix-xp) div iy1;
+      if (x>=0) and (x+s<=318) then
+       begin
+        z:=mp^[WORD(iyp shl 8+ixp)]; mpc:=z shr 1;
+        if z<47 then z:=46;  y:=100+(zobs-z)*30 div iy1;
+        if (y<=199) and (y>=0) then
+         for j:=x to x+s do
+          begin
+           for i:=y to rng[j] do
+            scr^[WORD(320*i+j)]:=mpc;
+           if y<rng[WORD(j)] then rng[WORD(j)]:=y
+          end;
+      end;
+    end;
+  end;
+  {$IFDEF FPC}
+   DosMemPut($A000,0,Scr^,64000);
+  {$ELSE}
+   Move(Scr^,mem[$A000:0],64000);
+  {$ENDIF}
+end;
+
+VAR Reg : Registers;
+
+begin
+  writeln('creating landscape...');
+  randomize; x:=0; y:=0; dir:=0; new(mp); fillchar(mp^,65535,0);
+  new(scr); mp^[$0000]:=128; plasma(0,0,256,256);
+  Reg.ax:=$13;  Intr($10,Reg);
+{$IFDEF FPC}
+  Outportb($3C8,0);
+  for i:=1 to 384 do OutPortb($3c9,pal[i]);
+{$ELSE}
+  Port[$3C8] := 0;
+  for i:=1 to 384 do Port[$3c9] := pal[i];
+{$ENDIF}
+  repeat
+    dir:=dir mod 360;
+    draw(x,y,dir);
+    case readkey of
+      #0:case readkey of
+         #75:dec(dir,10);
+         #77:inc(dir,10);
+         #72:begin
+              y:=y+round(5*cos(Real(dir)/180*pi));
+              x:=x+round(5*sin(Real(dir)/180*pi));
+             end;
+         #80:begin
+              y:=y-round(5*cos(Real(dir)/180*pi));
+              x:=x-round(5*sin(Real(dir)/180*pi));
+             end;
+          end;
+      #27: begin
+            Reg.ax:=$3;
+            Intr($10,Reg);
+            halt
+          end
+    end
+  until false;
+end.
+{
+  $Log$
+  Revision 1.1  2001-05-03 21:39:33  peter
+    * moved to own module
+
+  Revision 1.2  2000/07/13 11:33:09  michael
+  + removed logs
+ 
+}

+ 834 - 0
demo/os2/Makefile

@@ -0,0 +1,834 @@
+#
+# Don't edit, this file is generated by fpcmake v1.99.0 [2001/05/03]
+#
+default: all
+override PATH:=$(subst \,/,$(PATH))
+ifeq ($(findstring ;,$(PATH)),)
+inUnix=1
+SEARCHPATH:=$(subst :, ,$(PATH))
+else
+SEARCHPATH:=$(subst ;, ,$(PATH))
+endif
+PWD:=$(strip $(wildcard $(addsuffix /pwd.exe,$(SEARCHPATH))))
+ifeq ($(PWD),)
+PWD:=$(strip $(wildcard $(addsuffix /pwd,$(SEARCHPATH))))
+ifeq ($(PWD),)
+nopwd:
+	@echo You need the GNU utils package to use this Makefile!
+	@echo Get ftp://ftp.freepascal.org/pub/fpc/dist/go32v2/utilgo32.zip
+	@exit
+else
+PWD:=$(firstword $(PWD))
+SRCEXEEXT=
+endif
+else
+PWD:=$(firstword $(PWD))
+SRCEXEEXT=.exe
+endif
+ifndef inUnix
+ifeq ($(OS),Windows_NT)
+inWinNT=1
+else
+ifdef OS2_SHELL
+inOS2=1
+endif
+endif
+else
+ifneq ($(findstring cygwin,$(MACH_TYPE)),)
+inCygWin=1
+endif
+endif
+ifdef inUnix
+BATCHEXT=.sh
+else
+ifdef inOS2
+BATCHEXT=.cmd
+else
+BATCHEXT=.bat
+endif
+endif
+ifdef inUnix
+PATHSEP=/
+else
+PATHSEP:=$(subst /,\,/)
+endif
+ifdef PWD
+BASEDIR:=$(shell $(PWD))
+else
+BASEDIR=.
+endif
+ifndef FPC
+ifdef PP
+FPC=$(PP)
+else
+FPC=ppc386
+endif
+endif
+override FPC:=$(subst $(SRCEXEEXT),,$(FPC))
+override FPC:=$(subst \,/,$(FPC))$(SRCEXEEXT)
+ifndef OS_TARGET
+OS_TARGET:=$(shell $(FPC) -iTO)
+endif
+ifndef OS_SOURCE
+OS_SOURCE:=$(shell $(FPC) -iSO)
+endif
+ifndef CPU_TARGET
+CPU_TARGET:=$(shell $(FPC) -iTP)
+endif
+ifndef CPU_SOURCE
+CPU_SOURCE:=$(shell $(FPC) -iSP)
+endif
+ifndef FPC_VERSION
+FPC_VERSION:=$(shell $(FPC) -iV)
+endif
+export FPC OS_TARGET OS_SOURCE CPU_TARGET CPU_SOURCE FPC_VERSION
+ifdef FPCDIR
+override FPCDIR:=$(subst \,/,$(FPCDIR))
+ifeq ($(wildcard $(addprefix $(FPCDIR)/,rtl units)),)
+override FPCDIR=wrong
+endif
+else
+override FPCDIR=wrong
+endif
+ifeq ($(FPCDIR),wrong)
+override FPCDIR=../..
+ifeq ($(wildcard $(FPCDIR)/rtl),)
+ifeq ($(wildcard $(FPCDIR)/units),)
+override FPCDIR=wrong
+endif
+endif
+endif
+ifeq ($(FPCDIR),wrong)
+ifdef inUnix
+override FPCDIR=/usr/local/lib/fpc/$(FPC_VERSION)
+ifeq ($(wildcard $(FPCDIR)/units),)
+override FPCDIR=/usr/lib/fpc/$(FPC_VERSION)
+endif
+else
+override FPCDIR:=$(subst /$(FPC),,$(firstword $(strip $(wildcard $(addsuffix /$(FPC),$(SEARCHPATH))))))
+override FPCDIR:=$(FPCDIR)/..
+ifeq ($(wildcard $(addprefix $(FPCDIR)/,rtl units)),)
+override FPCDIR:=$(FPCDIR)/..
+ifeq ($(wildcard $(addprefix $(FPCDIR)/,rtl units)),)
+override FPCDIR=c:/pp
+endif
+endif
+endif
+endif
+UNITSDIR:=$(wildcard $(FPCDIR)/units/$(OS_TARGET))
+PACKAGESDIR:=$(wildcard $(FPCDIR) $(FPCDIR)/packages)
+ifeq ($(OS_TARGET),os2)
+override TARGET_PROGRAMS+=basicpm pmdemo1 getctry
+endif
+ifndef ECHO
+ECHO:=$(strip $(wildcard $(addsuffix /gecho$(EXEEXT),$(SEARCHPATH))))
+ifeq ($(ECHO),)
+ECHO:=$(strip $(wildcard $(addsuffix /echo$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(ECHO),)
+ECHO:=echo
+else
+ECHO:=$(firstword $(ECHO))
+endif
+else
+ECHO:=$(firstword $(ECHO))
+endif
+endif
+ifndef COPY
+COPY:=cp -fp
+endif
+ifndef COPYTREE
+COPYTREE:=cp -rfp
+endif
+ifndef MOVE
+MOVE:=mv -f
+endif
+ifndef DEL
+DEL:=rm -f
+endif
+ifndef DELTREE
+DELTREE:=rm -rf
+endif
+ifndef INSTALL
+ifdef inUnix
+INSTALL:=install -c -m 644
+else
+INSTALL:=$(COPY)
+endif
+endif
+ifndef INSTALLEXE
+ifdef inUnix
+INSTALLEXE:=install -c -m 755
+else
+INSTALLEXE:=$(COPY)
+endif
+endif
+ifndef MKDIR
+ifdef inUnix
+MKDIR:=install -m 755 -d
+else
+MKDIR:=ginstall -m 755 -d
+endif
+endif
+export ECHO COPY COPYTREE MOVE DEL DELTREE INSTALL INSTALLEXE MKDIR
+ifndef AS
+AS=as
+endif
+ifndef LD
+LD=ld
+endif
+ifndef RC
+RC=rc
+endif
+PPAS=ppas$(BATCHEXT)
+ifdef inUnix
+LDCONFIG=ldconfig
+else
+LDCONFIG=
+endif
+ifndef PPUMOVE
+PPUMOVE:=$(strip $(wildcard $(addsuffix /ppumove$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(PPUMOVE),)
+PPUMOVE=
+else
+PPUMOVE:=$(firstword $(PPUMOVE))
+endif
+endif
+export PPUMOVE
+ifndef PPUFILES
+PPUFILES:=$(strip $(wildcard $(addsuffix /ppufiles$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(PPUFILES),)
+PPUFILES=
+else
+PPUFILES:=$(firstword $(PPUFILES))
+endif
+endif
+export PPUFILES
+ifndef DATE
+DATE:=$(strip $(wildcard $(addsuffix /date$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(DATE),)
+DATE:=$(strip $(wildcard $(addsuffix /gdate$(SRCEXEEXT),$(SEACHPATH))))
+ifeq ($(DATE),)
+DATE=
+else
+DATE:=$(firstword $(DATE))
+endif
+else
+DATE:=$(firstword $(DATE))
+endif
+endif
+export DATE
+ifdef DATE
+DATESTR:=$(shell $(DATE) +%Y%m%d)
+else
+DATESTR=
+endif
+ifndef UPXPROG
+ifeq ($(OS_TARGET),go32v2)
+UPXPROG:=1
+endif
+ifeq ($(OS_TARGET),win32)
+UPXPROG:=1
+endif
+ifdef UPXPROG
+UPXPROG:=$(strip $(wildcard $(addsuffix /upx$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(UPXPROG),)
+UPXPROG=
+else
+UPXPROG:=$(firstword $(UPXPROG))
+endif
+else
+UPXPROG=
+endif
+endif
+export UPXPROG
+ifndef ZIPPROG
+ZIPPROG:=$(strip $(wildcard $(addsuffix /zip$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(ZIPPROG),)
+ZIPPROG=
+else
+ZIPPROG:=$(firstword $(ZIPPROG))
+endif
+endif
+export ZIPPROG
+ZIPOPT=-9
+ZIPEXT=.zip
+ifndef TARPROG
+TARPROG:=$(strip $(wildcard $(addsuffix /tar$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(TARPROG),)
+TARPROG=
+else
+TARPROG:=$(firstword $(TARPROG))
+endif
+endif
+export TARPROG
+ifeq ($(USETAR),bz2)
+TAROPT=vI
+TAREXT=.tar.bz2
+else
+TAROPT=vz
+TAREXT=.tar.gz
+endif
+LOADEREXT=.as
+EXEEXT=.exe
+PPLEXT=.ppl
+PPUEXT=.ppu
+OEXT=.o
+ASMEXT=.s
+SMARTEXT=.sl
+STATICLIBEXT=.a
+SHAREDLIBEXT=.so
+LIBPREFIX=lib
+RSTEXT=.rst
+FPCMADE=fpcmade
+ifeq ($(OS_TARGET),go32v1)
+PPUEXT=.pp1
+OEXT=.o1
+ASMEXT=.s1
+SMARTEXT=.sl1
+STATICLIBEXT=.a1
+SHAREDLIBEXT=.so1
+LIBPREFIX=
+FPCMADE=fpcmade.v1
+PACKAGESUFFIX=v1
+endif
+ifeq ($(OS_TARGET),go32v2)
+LIBPREFIX=
+FPCMADE=fpcmade.dos
+ZIPSUFFIX=go32
+endif
+ifeq ($(OS_TARGET),linux)
+EXEEXT=
+HASSHAREDLIB=1
+FPCMADE=fpcmade.lnx
+ZIPSUFFIX=linux
+endif
+ifeq ($(OS_TARGET),freebsd)
+EXEEXT=
+HASSHAREDLIB=1
+FPCMADE=fpcmade.freebsd
+ZIPSUFFIX=freebsd
+endif
+ifeq ($(OS_TARGET),win32)
+PPUEXT=.ppw
+OEXT=.ow
+ASMEXT=.sw
+SMARTEXT=.slw
+STATICLIBEXT=.aw
+SHAREDLIBEXT=.dll
+FPCMADE=fpcmade.w32
+ZIPSUFFIX=w32
+endif
+ifeq ($(OS_TARGET),os2)
+PPUEXT=.ppo
+ASMEXT=.so2
+OEXT=.oo2
+AOUTEXT=.out
+SMARTEXT=.so
+STATICLIBEXT=.ao2
+SHAREDLIBEXT=.dll
+FPCMADE=fpcmade.os2
+ZIPSUFFIX=emx
+endif
+ifdef REQUIRE_UNITSDIR
+override UNITSDIR+=$(REQUIRE_UNITSDIR)
+endif
+ifdef REQUIRE_PACKAGESDIR
+override PACKAGESDIR+=$(REQUIRE_PACKAGESDIR)
+endif
+ifdef ZIPINSTALL
+ifeq ($(OS_TARGET),linux)
+UNIXINSTALLDIR=1
+endif
+ifeq ($(OS_TARGET),freebsd)
+UNIXINSTALLDIR=1
+endif
+else
+ifeq ($(OS_SOURCE),linux)
+UNIXINSTALLDIR=1
+endif
+ifeq ($(OS_SOURCE),freebsd)
+UNIXINSTALLDIR=1
+endif
+endif
+ifndef INSTALL_PREFIX
+ifdef UNIXINSTALLDIR
+INSTALL_PREFIX=/usr/local
+else
+ifdef INSTALL_FPCPACKAGE
+INSTALL_BASEDIR:=/pp
+else
+INSTALL_BASEDIR:=/$(PACKAGE_NAME)
+endif
+endif
+endif
+export INSTALL_PREFIX
+ifndef DIST_DESTDIR
+DIST_DESTDIR:=$(BASEDIR)
+endif
+export DIST_DESTDIR
+ifndef INSTALL_BASEDIR
+ifdef UNIXINSTALLDIR
+ifdef INSTALL_FPCPACKAGE
+INSTALL_BASEDIR:=$(INSTALL_PREFIX)/lib/fpc/$(FPC_VERSION)
+else
+INSTALL_BASEDIR:=$(INSTALL_PREFIX)/lib/$(PACKAGE_NAME)
+endif
+else
+INSTALL_BASEDIR:=$(INSTALL_PREFIX)
+endif
+endif
+ifndef INSTALL_BINDIR
+ifdef UNIXINSTALLDIR
+INSTALL_BINDIR:=$(INSTALL_PREFIX)/bin
+else
+INSTALL_BINDIR:=$(INSTALL_BASEDIR)/bin
+ifdef INSTALL_FPCPACKAGE
+INSTALL_BINDIR:=$(INSTALL_BINDIR)/$(OS_TARGET)
+endif
+endif
+endif
+ifndef INSTALL_UNITDIR
+INSTALL_UNITDIR:=$(INSTALL_BASEDIR)/units/$(OS_TARGET)
+ifdef INSTALL_FPCPACKAGE
+INSTALL_UNITDIR:=$(INSTALL_UNITDIR)/$(PACKAGE_NAME)
+endif
+endif
+ifndef INSTALL_LIBDIR
+ifdef UNIXINSTALLDIR
+INSTALL_LIBDIR:=$(INSTALL_PREFIX)/lib
+else
+INSTALL_LIBDIR:=$(INSTALL_UNITDIR)
+endif
+endif
+ifndef INSTALL_SOURCEDIR
+ifdef UNIXINSTALLDIR
+ifdef INSTALL_FPCPACKAGE
+INSTALL_SOURCEDIR:=$(INSTALL_PREFIX)/src/fpc-$(FPC_VERSION)/$(PACKAGE_NAME)
+else
+INSTALL_SOURCEDIR:=$(INSTALL_PREFIX)/src/$(PACKAGE_NAME)-$(PACKAGE_VERSION)
+endif
+else
+ifdef INSTALL_FPCPACKAGE
+INSTALL_SOURCEDIR:=$(INSTALL_BASEDIR)/source/$(PACKAGE_NAME)
+else
+INSTALL_SOURCEDIRL:=$(INSTALL_BASEDIR)/source
+endif
+endif
+endif
+ifndef INSTALL_DOCDIR
+ifdef UNIXINSTALLDIR
+ifdef INSTALL_FPCPACKAGE
+INSTALL_DOCDIR:=$(INSTALL_PREFIX)/doc/fpc-$(FPC_VERSION)/$(PACKAGE_NAME)
+else
+INSTALL_DOCDIR:=$(INSTALL_PREFIX)/doc/$(PACKAGE_NAME)-$(PACKAGE_VERSION)
+endif
+else
+ifdef INSTALL_FPCPACKAGE
+INSTALL_DOCDIR:=$(INSTALL_BASEDIR)/doc/$(PACKAGE_NAME)
+else
+INSTALL_DOCDIR:=$(INSTALL_BASEDIR)/doc
+endif
+endif
+endif
+ifndef INSTALL_EXAMPLEDIR
+ifdef UNIXINSTALLDIR
+ifdef INSTALL_FPCPACKAGE
+INSTALL_EXAMPLEDIR:=$(INSTALL_PREFIX)/doc/fpc-$(FPC_VERSION)/examples/$(PACKAGE_NAME)
+else
+INSTALL_EXAMPLEDIR:=$(INSTALL_PREFIX)/doc/$(PACKAGE_NAME)-$(PACKAGE_VERSION)
+endif
+else
+ifdef INSTALL_FPCPACKAGE
+INSTALL_EXAMPLEDIR:=$(INSTALL_BASEDIR)/examples/$(PACKAGE_NAME)
+else
+INSTALL_EXAMPLEDIR:=$(INSTALL_BASEDIR)/examples
+endif
+endif
+endif
+ifndef INSTALL_DATADIR
+INSTALL_DATADIR=$(INSTALL_BASEDIR)
+endif
+ifeq ($(OS_TARGET),linux)
+REQUIRE_PACKAGES_RTL=1
+endif
+ifeq ($(OS_TARGET),go32v2)
+REQUIRE_PACKAGES_RTL=1
+endif
+ifeq ($(OS_TARGET),win32)
+REQUIRE_PACKAGES_RTL=1
+endif
+ifeq ($(OS_TARGET),os2)
+REQUIRE_PACKAGES_RTL=1
+endif
+ifeq ($(OS_TARGET),freebsd)
+REQUIRE_PACKAGES_RTL=1
+endif
+ifdef REQUIRE_PACKAGES_RTL
+PACKAGEDIR_RTL:=$(subst /Makefile.fpc,,$(strip $(wildcard $(addsuffix /rtl/Makefile.fpc,$(PACKAGESDIR)))))
+ifneq ($(PACKAGEDIR_RTL),)
+PACKAGEDIR_RTL:=$(firstword $(PACKAGEDIR_RTL))
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=package_rtl
+package_rtl:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+ifneq ($(wildcard $(PACKAGEDIR_RTL)/$(OS_TARGET)),)
+UNITDIR_RTL=$(PACKAGEDIR_RTL)/$(OS_TARGET)
+else
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+endif
+else
+PACKAGEDIR_RTL=
+UNITDIR_RTL:=$(subst /Package.fpc,,$(strip $(wildcard $(addsuffix /rtl/Package.fpc,$(UNITSDIR)))))
+ifneq ($(UNITDIR_RTL),)
+UNITDIR_RTL:=$(firstword $(UNITDIR_RTL))
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override COMPILER_UNITDIR+=$(UNITDIR_RTL)
+endif
+endif
+.PHONY: package_rtl
+override FPCOPTDEF=$(CPU_TARGET)
+ifneq ($(OS_TARGET),$(OS_SOURCE))
+override FPCOPT+=-T$(OS_TARGET)
+endif
+ifdef UNITDIR
+override FPCOPT+=$(addprefix -Fu,$(UNITDIR))
+endif
+ifdef LIBDIR
+override FPCOPT+=$(addprefix -Fl,$(LIBDIR))
+endif
+ifdef OBJDIR
+override FPCOPT+=$(addprefix -Fo,$(OBJDIR))
+endif
+ifdef INCDIR
+override FPCOPT+=$(addprefix -Fi,$(INCDIR))
+endif
+ifdef LINKSMART
+override FPCOPT+=-XX
+endif
+ifdef CREATESMART
+override FPCOPT+=-CX
+endif
+ifdef DEBUG
+override FPCOPT+=-gl
+override FPCOPTDEF+=DEBUG
+endif
+ifdef RELEASE
+override FPCOPT+=-Xs -OG2p3 -n
+override FPCOPTDEF+=RELEASE
+endif
+ifdef STRIP
+override FPCOPT+=-Xs
+endif
+ifdef OPTIMIZE
+override FPCOPT+=-OG2p3
+endif
+ifdef VERBOSE
+override FPCOPT+=-vwni
+endif
+ifdef COMPILER_OPTIONS
+override FPCOPT+=$(COMPILER_OPTIONS)
+endif
+ifdef COMPILER_UNITDIR
+override FPCOPT+=$(addprefix -Fu,$(COMPILER_UNITDIR))
+endif
+ifdef COMPILER_LIBRARYDIR
+override FPCOPT+=$(addprefix -Fl,$(COMPILER_LIBRARYDIR))
+endif
+ifdef COMPILER_OBJECTDIR
+override FPCOPT+=$(addprefix -Fo,$(COMPILER_OBJECTDIR))
+endif
+ifdef COMPILER_INCLUDEDIR
+override FPCOPT+=$(addprefix -Fi,$(COMPILER_INCLUDEDIR))
+endif
+ifdef COMPILER_TARGETDIR
+override FPCOPT+=-FE$(COMPILER_TARGETDIR)
+ifeq ($(COMPILER_TARGETDIR),.)
+override TARGETDIRPREFIX=
+else
+override TARGETDIRPREFIX=$(COMPILER_TARGETDIR)/
+endif
+endif
+ifdef COMPILER_UNITTARGETDIR
+override FPCOPT+=-FU$(COMPILER_UNITTARGETDIR)
+ifeq ($(COMPILER_UNITTARGETDIR),.)
+override UNITTARGETDIRPREFIX=
+else
+override UNITTARGETDIRPREFIX=$(COMPILER_TARGETDIR)/
+endif
+else
+ifdef COMPILER_TARGETDIR
+override COMPILER_UNITTARGETDIR=$(COMPILER_TARGETDIR)
+override UNITTARGETDIRPREFIX=$(TARGETDIRPREFIX)
+endif
+endif
+ifdef OPT
+override FPCOPT+=$(OPT)
+endif
+ifdef FPCOPTDEF
+override FPCOPT+=$(addprefix -d,$(FPCOPTDEF))
+endif
+ifdef CFGFILE
+override FPCOPT+=@$(CFGFILE)
+endif
+ifeq ($(OS_SOURCE),win32)
+USEENV=1
+endif
+ifdef USEENV
+override FPCEXTCMD:=$(FPCOPT)
+override FPCOPT:=!FPCEXTCMD
+export FPCEXTCMD
+endif
+override COMPILER:=$(FPC) $(FPCOPT)
+ifeq (,$(findstring -s ,$(COMPILER)))
+EXECPPAS=
+else
+ifeq ($(OS_SOURCE),$(OS_TARGET))
+EXECPPAS:=@$(PPAS)
+endif
+endif
+.PHONY: fpc_exes
+ifdef TARGET_PROGRAMS
+override EXEFILES=$(addsuffix $(EXEEXT),$(TARGET_PROGRAMS))
+override EXEOFILES:=$(addsuffix $(OEXT),$(TARGET_PROGRAMS)) $(addprefix $(LIBPREFIX),$(addsuffix $(STATICLIBEXT),$(TARGET_PROGRAMS)))
+override ALLTARGET+=fpc_exes
+override INSTALLEXEFILES+=$(EXEFILES)
+override CLEANEXEFILES+=$(EXEFILES) $(EXEOFILES)
+ifeq ($(OS_TARGET),os2)
+override CLEANEXEFILES+=$(addsuffix $(AOUTEXT),$(TARGET_PROGRAMS))
+endif
+endif
+fpc_exes: $(EXEFILES)
+.PHONY: fpc_packages fpc_all fpc_smart fpc_debug
+$(FPCMADE): $(ALLTARGET)
+	@$(ECHO) Compiled > $(FPCMADE)
+fpc_packages: $(COMPILEPACKAGES)
+fpc_all: fpc_packages $(FPCMADE)
+fpc_smart:
+	$(MAKE) all LINKSMART=1 CREATESMART=1
+fpc_debug:
+	$(MAKE) all DEBUG=1
+.SUFFIXES: $(EXEEXT) $(PPUEXT) $(OEXT) .pas .pp
+%$(PPUEXT): %.pp
+	$(COMPILER) $<
+	$(EXECPPAS)
+%$(PPUEXT): %.pas
+	$(COMPILER) $<
+	$(EXECPPAS)
+%$(EXEEXT): %.pp
+	$(COMPILER) $<
+	$(EXECPPAS)
+%$(EXEEXT): %.pas
+	$(COMPILER) $<
+	$(EXECPPAS)
+vpath %.pp $(COMPILER_SOURCEDIR) $(COMPILER_INCLUDEDIR)
+vpath %.pas $(COMPILER_SOURCEDIR) $(COMPILER_INCLUDEDIR)
+vpath %$(PPUEXT) $(COMPILER_UNITTARGETDIR)
+.PHONY: fpc_install fpc_sourceinstall fpc_exampleinstall
+ifdef INSTALL_UNITS
+override INSTALLPPUFILES+=$(addsuffix $(PPUEXT),$(INSTALL_UNITS))
+endif
+ifdef INSTALLPPUFILES
+ifdef PPUFILES
+override INSTALLPPUFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(INSTALLPPUFILES))
+override INSTALLPPULINKFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(shell $(PPUFILES) -S -O $(INSTALLPPUFILES)))
+else
+override INSTALLPPULINKFILES:=$(subst $(PPUEXT),$(OEXT),$(INSTALLPPUFILES)) $(addprefix $(LIBPREFIX),$(subst $(PPUEXT),$(STATICLIBEXT),$(INSTALLPPUFILES)))
+override INSTALLPPUFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(INSTALLPPUFILES))
+override INSTALLPPULINKFILES:=$(wildcard $(addprefix $(UNITTARGETDIRPREFIX),$(INSTALLPPULINKFILES)))
+endif
+endif
+ifdef INSTALLEXEFILES
+override INSTALLEXEFILES:=$(addprefix $(TARGETDIRPREFIX),$(INSTALLEXEFILES))
+endif
+fpc_install: $(INSTALLTARGET)
+ifdef INSTALLEXEFILES
+	$(MKDIR) $(INSTALL_BINDIR)
+ifdef UPXPROG
+	-$(UPXPROG) $(INSTALLEXEFILES)
+endif
+	$(INSTALLEXE) $(INSTALLEXEFILES) $(INSTALL_BINDIR)
+endif
+ifdef INSTALLPPUFILES
+	$(MKDIR) $(INSTALL_UNITDIR)
+	$(INSTALL) $(INSTALLPPUFILES) $(INSTALL_UNITDIR)
+ifneq ($(INSTALLPPULINKFILES),)
+	$(INSTALL) $(INSTALLPPULINKFILES) $(INSTALL_UNITDIR)
+endif
+ifneq ($(wildcard $(LIB_FULLNAME)),)
+	$(MKDIR) $(INSTALL_LIBDIR)
+	$(INSTALL) $(LIB_FULLNAME) $(INSTALL_LIBDIR)
+ifdef inUnix
+	ln -sf $(LIB_FULLNAME) $(INSTALL_LIBDIR)/$(LIB_NAME)
+endif
+endif
+endif
+ifdef INSTALL_FILES
+	$(MKDIR) $(INSTALL_DATADIR)
+	$(INSTALL) $(INSTALL_FILES) $(INSTALL_DATADIR)
+endif
+fpc_sourceinstall: distclean
+	$(MKDIR) $(INSTALL_SOURCEDIR)
+	$(COPYTREE) $(BASEDIR) $(INSTALL_SOURCEDIR)
+fpc_exampleinstall: $(addsuffix _distclean,$(TARGET_EXAMPLEDIRS))
+ifdef HASEXAMPLES
+	$(MKDIR) $(INSTALL_EXAMPLEDIR)
+endif
+ifdef EXAMPLESOURCEFILES
+	$(COPY) $(EXAMPLESOURCEFILES) $(INSTALL_EXAMPLEDIR)
+endif
+ifdef TARGET_EXAMPLEDIRS
+	$(COPYTREE) $(addsuffix /*,$(TARGET_EXAMPLEDIRS)) $(INSTALL_EXAMPLEDIR)
+endif
+fpc_distinstall: install exampleinstall
+.PHONY: fpc_clean fpc_cleanall fpc_distclean
+ifdef EXEFILES
+override CLEANEXEFILES:=$(addprefix $(TARGETDIRPREFIX),$(CLEANEXEFILES))
+endif
+ifdef CLEAN_UNITS
+override CLEANPPUFILES+=$(addsuffix $(PPUEXT),$(CLEAN_UNITS))
+endif
+ifdef CLEANPPUFILES
+override CLEANPPUFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(CLEANPPUFILES))
+ifdef PPUFILES
+CLEANPPULINKFILES:=$(shell $(PPUFILES) $(CLEANPPUFILES))
+else
+CLEANPPULINKFILES:=$(wildcard $(subst $(PPUEXT),$(OEXT),$(CLEANPPUFILES)) $(addprefix $(LIBPREFIX),$(subst $(PPUEXT),$(STATICLIBEXT),$(CLEANPPUFILES))))
+endif
+override CLEANPPULINKFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(CLEANPPULINKFILES))
+endif
+fpc_clean: $(CLEANTARGET)
+ifdef CLEANEXEFILES
+	-$(DEL) $(CLEANEXEFILES)
+endif
+ifdef CLEANPPUFILES
+	-$(DEL) $(CLEANPPUFILES)
+endif
+ifneq ($(CLEANPPULINKFILES),)
+	-$(DEL) $(CLEANPPULINKFILES)
+endif
+ifdef CLEANRSTFILES
+	-$(DEL) $(addprefix $(UNITTARGETDIRPREFIX),$(CLEANRSTFILES))
+endif
+ifdef CLEAN_FILES
+	-$(DEL) $(CLEAN_FILES)
+endif
+ifdef LIB_NAME
+	-$(DEL) $(LIB_NAME) $(LIB_FULLNAME)
+endif
+	-$(DEL) $(FPCMADE) $(PPAS) link.res $(FPCEXTFILE) $(REDIRFILE)
+fpc_distclean: clean
+ifdef COMPILER_UNITTARGETDIR
+TARGETDIRCLEAN=fpc_clean
+endif
+fpc_cleanall: $(CLEANTARGET) $(TARGETDIRCLEAN)
+ifdef CLEANEXEFILES
+	-$(DEL) $(CLEANEXEFILES)
+endif
+	-$(DEL) *$(OEXT) *$(PPUEXT) *$(RSTEXT) *$(ASMEXT) *$(STATICLIBEXT) *$(SHAREDLIBEXT) *$(PPLEXT)
+	-$(DELTREE) *$(SMARTEXT)
+	-$(DEL) $(FPCMADE) $(PPAS) link.res $(FPCEXTFILE) $(REDIRFILE)
+ifdef AOUTEXT
+	-$(DEL) *$(AOUTEXT)
+endif
+.PHONY: fpc_info
+fpc_info:
+	@$(ECHO)
+	@$(ECHO)  == Package info ==
+	@$(ECHO)  Package Name..... $(PACKAGE_NAME)
+	@$(ECHO)  Package Version.. $(PACKAGE_VERSION)
+	@$(ECHO)
+	@$(ECHO)  == Configuration info ==
+	@$(ECHO)
+	@$(ECHO)  FPC.......... $(FPC)
+	@$(ECHO)  FPC Version.. $(FPC_VERSION)
+	@$(ECHO)  Source CPU... $(CPU_SOURCE)
+	@$(ECHO)  Target CPU... $(CPU_TARGET)
+	@$(ECHO)  Source OS.... $(OS_SOURCE)
+	@$(ECHO)  Target OS.... $(OS_TARGET)
+	@$(ECHO)
+	@$(ECHO)  == Directory info ==
+	@$(ECHO)
+	@$(ECHO)  Basedir......... $(BASEDIR)
+	@$(ECHO)  FPCDir.......... $(FPCDIR)
+	@$(ECHO)  UnitsDir........ $(UNITSDIR)
+	@$(ECHO)  PackagesDir..... $(PACKAGESDIR)
+	@$(ECHO)
+	@$(ECHO)  GCC library..... $(GCCLIBDIR)
+	@$(ECHO)  Other library... $(OTHERLIBDIR)
+	@$(ECHO)
+	@$(ECHO)  == Tools info ==
+	@$(ECHO)
+	@$(ECHO)  Pwd....... $(PWD)
+	@$(ECHO)  Echo...... $(ECHO)
+	@$(ECHO)  PPUMove... $(PPUMOVE)
+	@$(ECHO)  PPUFiles.. $(PPUFILES)
+	@$(ECHO)  Date...... $(DATE)
+	@$(ECHO)  Upx....... $(UPXPROG)
+	@$(ECHO)  Zip....... $(ZIPPROG)
+	@$(ECHO)
+	@$(ECHO)  == Object info ==
+	@$(ECHO)
+	@$(ECHO)  Target Loaders...... $(TARGET_LOADERS)
+	@$(ECHO)  Target Units........ $(TARGET_UNITS)
+	@$(ECHO)  Target Programs..... $(TARGET_PROGRAMS)
+	@$(ECHO)  Target Dirs......... $(TARGET_DIRS)
+	@$(ECHO)  Target Examples..... $(TARGET_EXAMPLES)
+	@$(ECHO)  Target ExampleDirs.. $(TARGET_EXAMPLEDIRS)
+	@$(ECHO)
+	@$(ECHO)  Clean Units......... $(CLEAN_UNITS)
+	@$(ECHO)  Clean Files......... $(CLEAN_FILES)
+	@$(ECHO)
+	@$(ECHO)  Install Units....... $(INSTALL_UNITS)
+	@$(ECHO)  Install Files....... $(INSTALL_FILES)
+	@$(ECHO)
+	@$(ECHO)  == Install info ==
+	@$(ECHO)
+	@$(ECHO)  DateStr.............. $(DATESTR)
+	@$(ECHO)  ZipPrefix............ $(ZIPPREFIX)
+	@$(ECHO)  ZipSuffix............ $(ZIPSUFFIX)
+	@$(ECHO)  Install FPC Package.. $(INSTALL_FPCPACKAGE)
+	@$(ECHO)
+	@$(ECHO)  Install base dir..... $(INSTALL_BASEDIR)
+	@$(ECHO)  Install binary dir... $(INSTALL_BINDIR)
+	@$(ECHO)  Install library dir.. $(INSTALL_LIBDIR)
+	@$(ECHO)  Install units dir.... $(INSTALL_UNITDIR)
+	@$(ECHO)  Install source dir... $(INSTALL_SOURCEDIR)
+	@$(ECHO)  Install doc dir...... $(INSTALL_DOCDIR)
+	@$(ECHO)  Install example dir.. $(INSTALL_EXAMPLEDIR)
+	@$(ECHO)  Install data dir..... $(INSTALL_DATADIR)
+	@$(ECHO)
+	@$(ECHO)  Dist destination dir. $(DIST_DESTDIR)
+	@$(ECHO)  Dist zip name........ $(DIST_ZIPNAME)
+	@$(ECHO)
+all: fpc_all
+debug: fpc_debug
+examples: fpc_examples
+smart: fpc_smart
+shared: fpc_shared
+install: fpc_install
+sourceinstall: fpc_sourceinstall
+exampleinstall: fpc_exampleinstall
+distinstall: fpc_distinstall
+zipinstall:
+zipsourceinstall:
+zipexampleinstall:
+zipdistinstall:
+clean: fpc_clean
+distclean: fpc_distclean
+cleanall: fpc_cleanall
+info: fpc_info
+.PHONY: all debug examples smart shared install sourceinstall exampleinstall distinstall zipinstall zipsourceinstall zipexampleinstall zipdistinstall clean distclean cleanall info
+ifneq ($(wildcard fpcmake.loc),)
+include fpcmake.loc
+endif
+basicpm.exe: basicpm.pas
+	$(COMPILER) -Dw -Ch8096 -Cs32728 basicpm.pas
+pmdemo1.exe: pmdemo1.pp pmdemo1.res
+	$(COMPILER) -Dw -Ch8096 -Cs32728 pmdemo1.pp
+pmdemo1.res: pmdemo1.rc pmdemo1.h
+	$(RC) -r pmdemo1

+ 19 - 0
demo/os2/Makefile.fpc

@@ -0,0 +1,19 @@
+#
+#   Makefile.fpc for FPC OS/2 demos (part of FPC demo package)
+#
+
+[target]
+programs_os2=basicpm pmdemo1 getctry
+
+[default]
+fpcdir=../..
+
+[rules]
+basicpm.exe: basicpm.pas
+        $(COMPILER) -Dw -Ch8096 -Cs32728 basicpm.pas
+
+pmdemo1.exe: pmdemo1.pp pmdemo1.res
+        $(COMPILER) -Dw -Ch8096 -Cs32728 pmdemo1.pp
+
+pmdemo1.res: pmdemo1.rc pmdemo1.h
+        $(RC) -r pmdemo1

+ 92 - 0
demo/os2/basicpm.pas

@@ -0,0 +1,92 @@
+{
+    $Id$
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 1993-2001 by Free Pascal team
+
+    The most basic Presentation Mode example.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+program BasicPM;
+
+{$APPTYPE GUI}
+
+uses
+ Os2Def, PMWin;
+
+function ClientWindowProc (Window, Msg: cardinal; MP1, MP2: pointer): pointer;
+                                                                 cdecl; export;
+var
+ Li: longint;
+ Ps: cardinal;
+ R: TRectL;
+ P: TPointL;
+ Rgn: cardinal;
+begin
+ ClientWindowProc := nil;
+ case Msg of
+  wm_Paint: begin
+             PS := WinBeginPaint (Window, 0, @R);
+             WinFillRect (PS, @R, SYSCLR_WINDOW);
+             WinEndPaint (PS);
+            end;
+  else ClientWindowProc := WinDefWindowProc (Window, Msg, MP1, MP2);
+ end;
+end;
+
+const
+ idClientWindow = 11000;
+ WinFlags: cardinal = fcf_TitleBar + fcf_SysMenu + fcf_SizeBorder +
+                                   fcf_MinMax + fcf_TaskList + fcf_NoByteAlign;
+ ClassName = 'MYVIEW';
+
+var
+ Anchor, MsgQue: cardinal;
+ Message: TQMsg;
+ Frame, Client: cardinal;
+begin
+ Anchor := WinInitialize(0);
+ { It might be beneficial to set the second parameter of the following }
+ { call to something large, such as 1000.  The OS/2 documentation does }
+ { not recommend this, however } MsgQue := WinCreateMsgQueue (Anchor, 0);
+ if MsgQue = 0 then Halt (254);
+
+ WinMessageBox (HWND_DESKTOP, HWND_DESKTOP, 'FPC test', 'Basic PM', 0,
+                                                      MB_OK or MB_INFORMATION);
+
+ WinRegisterClass (Anchor, ClassName, proc (@ClientWindowProc), cs_SizeRedraw,
+                                                             SizeOf (pointer));
+ Frame := WinCreateStdWindow (hwnd_Desktop, 0, WinFlags, ClassName,
+                                     'BASIC PM', 0, 0, idClientWindow, Client);
+ if (Frame <> 0) then
+ begin
+  WinSetWindowPos (Frame, 0, 0, WinQuerySysValue (hwnd_Desktop,
+         sv_CyScreen) - 200, 200, 200, swp_Move + swp_Size + swp_Activate +
+                                                                     swp_Show);
+  while WinGetMsg (Anchor, Message, 0, 0, 0) do
+                                              WinDispatchMsg (Anchor, Message);
+
+  WinDestroyWindow (Frame);
+ end;
+ WinDestroyMsgQueue (MsgQue);
+ WinTerminate (Anchor);
+end.
+
+{
+  $Log$
+  Revision 1.1  2001-05-03 21:39:34  peter
+    * moved to own module
+
+  Revision 1.2  2001/04/22 10:13:14  hajny
+    * APPTYPE specified within the source files, RC called from makefiles
+
+  Revision 1.1  2001/01/14 19:02:14  hajny
+    + OS/2 demos added
+
+}

+ 50 - 0
demo/os2/getctry.pas

@@ -0,0 +1,50 @@
+{
+    $Id$
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 1993-2001 by Free Pascal team
+
+    A little example of using OS/2 API calls.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+program GetCountryInfo;
+
+uses
+ OS2Def, DosCalls;
+
+var
+ Country: TCountryCode;  (* Country code info (0 = current country) *)
+ CtryInfo: TCountryInfo; (* Buffer for country-specific information *)
+ Size: cardinal;         (* Real size of returned data              *)
+ W: word;
+
+begin
+ WriteLn;
+ Size := 0;
+ FillChar (Country, SizeOf (Country), 0);
+ FillChar (CtryInfo, SizeOf (CtryInfo), 0);
+ W := DosQueryCtryInfo (SizeOf (CtryInfo), Country, CtryInfo, Size);
+ if (W <> NO_ERROR) then
+ begin
+  WriteLn ('DosQueryCtryInfo error: return code = ', W);
+  Halt (1);
+ end;
+ WriteLn ('Code of the country is ', CtryInfo.Country,
+                             ', current codepage is ', CtryInfo.CodePage, '.');
+end.
+
+{
+  $Log$
+  Revision 1.1  2001-05-03 21:39:34  peter
+    * moved to own module
+
+  Revision 1.1  2001/01/14 19:02:14  hajny
+    + OS/2 demos added
+
+}

+ 25 - 0
demo/os2/pmdemo1.h

@@ -0,0 +1,25 @@
+/*******************************************
+
+  Header f�r den Ressourcecompiler
+
+********************************************/
+#define ID_ClientWindow	1
+
+/*
+  $Log$
+  Revision 1.1  2001-05-03 21:39:34  peter
+    * moved to own module
+
+  Revision 1.1  2001/01/14 19:02:14  hajny
+    + OS/2 demos added
+
+  Revision 1.1  2000/07/13 06:31:08  michael
+  + Initial import
+
+  Revision 1.1  2000/07/09 10:37:50  peter
+    * renamed to lowercase names
+
+  Revision 1.1  1999/06/02 16:01:35  hajny
+    * changes by Ramon Bosque
+
+*/

+ 113 - 0
demo/os2/pmdemo1.pp

@@ -0,0 +1,113 @@
+{****************************************************************************
+
+    $Id$
+
+                   Copyright (c) 1999-2000 by Florian Klaempfl
+
+ ****************************************************************************}
+
+{ Sample program for FPC under OS/2 }
+{ Classic Hello world in PM version }
+
+{$APPTYPE GUI}
+
+{$R pmdemo1.res}
+
+(* PMDEMO1.RES has to be compiled from PMDEMO1.RC using "rc -r PMDEMO1.RC". *)
+
+program pmdemo1;
+
+  uses
+     os2def,pmwin;
+
+  var
+     frame,client : cardinal;
+     ab : cardinal;
+     mq : cardinal;
+     msg : QMSG;
+     
+  const
+     frameflags : longint = FCF_TITLEBAR+FCF_SYSMENU+FCF_SIZEBORDER+
+                            FCF_MINBUTTON+FCF_MAXBUTTON+FCF_SHELLPOSITION+
+                            FCF_TASKLIST+FCF_MENU;
+
+  function clientwndproc(window : cardinal;msg : longint;mp1,mp2 : pointer) :
+    pointer; cdecl; export;
+  
+    const
+       text = 'Hello world by OS/2 and FPC';
+       
+    var
+       ps : cardinal;
+       rcl : RECTL;
+
+    begin
+       {clientwndproc:=nil;      }
+       case msg of
+{         WM_CREATE : DosBeep(200,500);}
+          WM_PAINT : begin
+                        ps:=WinBeginPaint(window,0,nil);
+                        WinQueryWindowRect(window,@rcl);
+                        WinDrawText(ps,-1,text,@rcl,0,7,$8500); 
+                        WinEndPaint(ps);
+                     end;
+          WM_COMMAND : case lo(longint(mp1)) of
+                          {101 : DosBeep(4500,1000);}
+                          109 : WinPostMsg(0,WM_QUIT,nil,nil);
+                          201 : WinMessageBox(cardinal(1),cardinal(1),
+                             'HelloPM from FPC',
+                             'About',0,MB_ICONEXCLAMATION+MB_MOVEABLE);
+                       end;
+       else
+          clientwndproc:=WinDefWindowProc(window,msg,mp1,mp2);
+       end;                                                        
+    end;
+
+ begin
+    ab:=WinInitialize(0);
+    mq:=WinCreateMsgQueue(ab,0);
+    WinRegisterClass(ab,'HELLOPM',proc(@clientwndproc),4,0);    
+    frame:=WinCreateStdWindow(cardinal(1),WS_VISIBLE,@frameflags,'HELLOPM',
+      'PMDemo 1',WS_VISIBLE,0,1,@client);
+    while WinGetMsg(ab,@msg,0,0,0) do
+      WinDispatchMsg(ab,@msg);
+    WinDestroyWindow(frame);
+    WinDestroyMsgQueue(mq);
+    WinTerminate(ab);
+ end.
+{
+  $Log$
+  Revision 1.1  2001-05-03 21:39:34  peter
+    * moved to own module
+
+  Revision 1.2  2001/04/22 10:13:14  hajny
+    * APPTYPE specified within the source files, RC called from makefiles
+
+  Revision 1.1  2001/01/14 19:02:14  hajny
+    + OS/2 demos added
+
+  Revision 1.1  2000/07/13 06:31:08  michael
+  + Initial import
+
+  Revision 1.1  2000/07/09 10:37:50  peter
+    * renamed to lowercase names
+
+  Revision 1.6  2000/07/09 07:49:34  hajny
+    * $R used now
+
+  Revision 1.5  2000/06/18 18:37:17  hajny
+   * cdecl added
+
+  Revision 1.4  2000/01/07 16:41:50  daniel
+    * copyright 2000
+
+  Revision 1.3  2000/01/07 16:32:34  daniel
+    * copyright 2000 added
+
+  Revision 1.2  1999/08/10 14:33:51  hajny
+    * PM samples
+
+  Revision 1.1  1999/06/02 16:01:35  hajny
+    * changes by Ramon Bosque
+
+}

+ 36 - 0
demo/os2/pmdemo1.rc

@@ -0,0 +1,36 @@
+/******************
+ * Name : TEXT.RC *
+ ******************/
+
+#include "PMDEMO1.H"
+
+MENU    ID_ClientWindow
+  BEGIN
+     SUBMENU "~File",100
+       BEGIN
+          MENUITEM "~Open...",101
+          MENUITEM "~Exit",109
+       END
+     SUBMENU "~Help",200
+       BEGIN
+          MENUITEM "~About...",201
+       END
+  END
+/*
+  $Log$
+  Revision 1.1  2001-05-03 21:39:34  peter
+    * moved to own module
+
+  Revision 1.1  2001/01/14 19:02:14  hajny
+    + OS/2 demos added
+
+  Revision 1.1  2000/07/13 06:31:10  michael
+  + Initial import
+
+  Revision 1.1  2000/07/09 10:37:50  peter
+    * renamed to lowercase names
+
+  Revision 1.1  1999/06/02 16:01:35  hajny
+    * changes by Ramon Bosque
+
+*/

+ 826 - 0
demo/text/Makefile

@@ -0,0 +1,826 @@
+#
+# Don't edit, this file is generated by fpcmake v1.99.0 [2001/05/03]
+#
+default: all
+override PATH:=$(subst \,/,$(PATH))
+ifeq ($(findstring ;,$(PATH)),)
+inUnix=1
+SEARCHPATH:=$(subst :, ,$(PATH))
+else
+SEARCHPATH:=$(subst ;, ,$(PATH))
+endif
+PWD:=$(strip $(wildcard $(addsuffix /pwd.exe,$(SEARCHPATH))))
+ifeq ($(PWD),)
+PWD:=$(strip $(wildcard $(addsuffix /pwd,$(SEARCHPATH))))
+ifeq ($(PWD),)
+nopwd:
+	@echo You need the GNU utils package to use this Makefile!
+	@echo Get ftp://ftp.freepascal.org/pub/fpc/dist/go32v2/utilgo32.zip
+	@exit
+else
+PWD:=$(firstword $(PWD))
+SRCEXEEXT=
+endif
+else
+PWD:=$(firstword $(PWD))
+SRCEXEEXT=.exe
+endif
+ifndef inUnix
+ifeq ($(OS),Windows_NT)
+inWinNT=1
+else
+ifdef OS2_SHELL
+inOS2=1
+endif
+endif
+else
+ifneq ($(findstring cygwin,$(MACH_TYPE)),)
+inCygWin=1
+endif
+endif
+ifdef inUnix
+BATCHEXT=.sh
+else
+ifdef inOS2
+BATCHEXT=.cmd
+else
+BATCHEXT=.bat
+endif
+endif
+ifdef inUnix
+PATHSEP=/
+else
+PATHSEP:=$(subst /,\,/)
+endif
+ifdef PWD
+BASEDIR:=$(shell $(PWD))
+else
+BASEDIR=.
+endif
+ifndef FPC
+ifdef PP
+FPC=$(PP)
+else
+FPC=ppc386
+endif
+endif
+override FPC:=$(subst $(SRCEXEEXT),,$(FPC))
+override FPC:=$(subst \,/,$(FPC))$(SRCEXEEXT)
+ifndef OS_TARGET
+OS_TARGET:=$(shell $(FPC) -iTO)
+endif
+ifndef OS_SOURCE
+OS_SOURCE:=$(shell $(FPC) -iSO)
+endif
+ifndef CPU_TARGET
+CPU_TARGET:=$(shell $(FPC) -iTP)
+endif
+ifndef CPU_SOURCE
+CPU_SOURCE:=$(shell $(FPC) -iSP)
+endif
+ifndef FPC_VERSION
+FPC_VERSION:=$(shell $(FPC) -iV)
+endif
+export FPC OS_TARGET OS_SOURCE CPU_TARGET CPU_SOURCE FPC_VERSION
+ifdef FPCDIR
+override FPCDIR:=$(subst \,/,$(FPCDIR))
+ifeq ($(wildcard $(addprefix $(FPCDIR)/,rtl units)),)
+override FPCDIR=wrong
+endif
+else
+override FPCDIR=wrong
+endif
+ifeq ($(FPCDIR),wrong)
+override FPCDIR=../..
+ifeq ($(wildcard $(FPCDIR)/rtl),)
+ifeq ($(wildcard $(FPCDIR)/units),)
+override FPCDIR=wrong
+endif
+endif
+endif
+ifeq ($(FPCDIR),wrong)
+ifdef inUnix
+override FPCDIR=/usr/local/lib/fpc/$(FPC_VERSION)
+ifeq ($(wildcard $(FPCDIR)/units),)
+override FPCDIR=/usr/lib/fpc/$(FPC_VERSION)
+endif
+else
+override FPCDIR:=$(subst /$(FPC),,$(firstword $(strip $(wildcard $(addsuffix /$(FPC),$(SEARCHPATH))))))
+override FPCDIR:=$(FPCDIR)/..
+ifeq ($(wildcard $(addprefix $(FPCDIR)/,rtl units)),)
+override FPCDIR:=$(FPCDIR)/..
+ifeq ($(wildcard $(addprefix $(FPCDIR)/,rtl units)),)
+override FPCDIR=c:/pp
+endif
+endif
+endif
+endif
+UNITSDIR:=$(wildcard $(FPCDIR)/units/$(OS_TARGET))
+PACKAGESDIR:=$(wildcard $(FPCDIR) $(FPCDIR)/packages)
+override TARGET_PROGRAMS+=eratos qsort hello blackbox magic lines
+ifndef ECHO
+ECHO:=$(strip $(wildcard $(addsuffix /gecho$(EXEEXT),$(SEARCHPATH))))
+ifeq ($(ECHO),)
+ECHO:=$(strip $(wildcard $(addsuffix /echo$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(ECHO),)
+ECHO:=echo
+else
+ECHO:=$(firstword $(ECHO))
+endif
+else
+ECHO:=$(firstword $(ECHO))
+endif
+endif
+ifndef COPY
+COPY:=cp -fp
+endif
+ifndef COPYTREE
+COPYTREE:=cp -rfp
+endif
+ifndef MOVE
+MOVE:=mv -f
+endif
+ifndef DEL
+DEL:=rm -f
+endif
+ifndef DELTREE
+DELTREE:=rm -rf
+endif
+ifndef INSTALL
+ifdef inUnix
+INSTALL:=install -c -m 644
+else
+INSTALL:=$(COPY)
+endif
+endif
+ifndef INSTALLEXE
+ifdef inUnix
+INSTALLEXE:=install -c -m 755
+else
+INSTALLEXE:=$(COPY)
+endif
+endif
+ifndef MKDIR
+ifdef inUnix
+MKDIR:=install -m 755 -d
+else
+MKDIR:=ginstall -m 755 -d
+endif
+endif
+export ECHO COPY COPYTREE MOVE DEL DELTREE INSTALL INSTALLEXE MKDIR
+ifndef AS
+AS=as
+endif
+ifndef LD
+LD=ld
+endif
+ifndef RC
+RC=rc
+endif
+PPAS=ppas$(BATCHEXT)
+ifdef inUnix
+LDCONFIG=ldconfig
+else
+LDCONFIG=
+endif
+ifndef PPUMOVE
+PPUMOVE:=$(strip $(wildcard $(addsuffix /ppumove$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(PPUMOVE),)
+PPUMOVE=
+else
+PPUMOVE:=$(firstword $(PPUMOVE))
+endif
+endif
+export PPUMOVE
+ifndef PPUFILES
+PPUFILES:=$(strip $(wildcard $(addsuffix /ppufiles$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(PPUFILES),)
+PPUFILES=
+else
+PPUFILES:=$(firstword $(PPUFILES))
+endif
+endif
+export PPUFILES
+ifndef DATE
+DATE:=$(strip $(wildcard $(addsuffix /date$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(DATE),)
+DATE:=$(strip $(wildcard $(addsuffix /gdate$(SRCEXEEXT),$(SEACHPATH))))
+ifeq ($(DATE),)
+DATE=
+else
+DATE:=$(firstword $(DATE))
+endif
+else
+DATE:=$(firstword $(DATE))
+endif
+endif
+export DATE
+ifdef DATE
+DATESTR:=$(shell $(DATE) +%Y%m%d)
+else
+DATESTR=
+endif
+ifndef UPXPROG
+ifeq ($(OS_TARGET),go32v2)
+UPXPROG:=1
+endif
+ifeq ($(OS_TARGET),win32)
+UPXPROG:=1
+endif
+ifdef UPXPROG
+UPXPROG:=$(strip $(wildcard $(addsuffix /upx$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(UPXPROG),)
+UPXPROG=
+else
+UPXPROG:=$(firstword $(UPXPROG))
+endif
+else
+UPXPROG=
+endif
+endif
+export UPXPROG
+ifndef ZIPPROG
+ZIPPROG:=$(strip $(wildcard $(addsuffix /zip$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(ZIPPROG),)
+ZIPPROG=
+else
+ZIPPROG:=$(firstword $(ZIPPROG))
+endif
+endif
+export ZIPPROG
+ZIPOPT=-9
+ZIPEXT=.zip
+ifndef TARPROG
+TARPROG:=$(strip $(wildcard $(addsuffix /tar$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(TARPROG),)
+TARPROG=
+else
+TARPROG:=$(firstword $(TARPROG))
+endif
+endif
+export TARPROG
+ifeq ($(USETAR),bz2)
+TAROPT=vI
+TAREXT=.tar.bz2
+else
+TAROPT=vz
+TAREXT=.tar.gz
+endif
+LOADEREXT=.as
+EXEEXT=.exe
+PPLEXT=.ppl
+PPUEXT=.ppu
+OEXT=.o
+ASMEXT=.s
+SMARTEXT=.sl
+STATICLIBEXT=.a
+SHAREDLIBEXT=.so
+LIBPREFIX=lib
+RSTEXT=.rst
+FPCMADE=fpcmade
+ifeq ($(OS_TARGET),go32v1)
+PPUEXT=.pp1
+OEXT=.o1
+ASMEXT=.s1
+SMARTEXT=.sl1
+STATICLIBEXT=.a1
+SHAREDLIBEXT=.so1
+LIBPREFIX=
+FPCMADE=fpcmade.v1
+PACKAGESUFFIX=v1
+endif
+ifeq ($(OS_TARGET),go32v2)
+LIBPREFIX=
+FPCMADE=fpcmade.dos
+ZIPSUFFIX=go32
+endif
+ifeq ($(OS_TARGET),linux)
+EXEEXT=
+HASSHAREDLIB=1
+FPCMADE=fpcmade.lnx
+ZIPSUFFIX=linux
+endif
+ifeq ($(OS_TARGET),freebsd)
+EXEEXT=
+HASSHAREDLIB=1
+FPCMADE=fpcmade.freebsd
+ZIPSUFFIX=freebsd
+endif
+ifeq ($(OS_TARGET),win32)
+PPUEXT=.ppw
+OEXT=.ow
+ASMEXT=.sw
+SMARTEXT=.slw
+STATICLIBEXT=.aw
+SHAREDLIBEXT=.dll
+FPCMADE=fpcmade.w32
+ZIPSUFFIX=w32
+endif
+ifeq ($(OS_TARGET),os2)
+PPUEXT=.ppo
+ASMEXT=.so2
+OEXT=.oo2
+AOUTEXT=.out
+SMARTEXT=.so
+STATICLIBEXT=.ao2
+SHAREDLIBEXT=.dll
+FPCMADE=fpcmade.os2
+ZIPSUFFIX=emx
+endif
+ifdef REQUIRE_UNITSDIR
+override UNITSDIR+=$(REQUIRE_UNITSDIR)
+endif
+ifdef REQUIRE_PACKAGESDIR
+override PACKAGESDIR+=$(REQUIRE_PACKAGESDIR)
+endif
+ifdef ZIPINSTALL
+ifeq ($(OS_TARGET),linux)
+UNIXINSTALLDIR=1
+endif
+ifeq ($(OS_TARGET),freebsd)
+UNIXINSTALLDIR=1
+endif
+else
+ifeq ($(OS_SOURCE),linux)
+UNIXINSTALLDIR=1
+endif
+ifeq ($(OS_SOURCE),freebsd)
+UNIXINSTALLDIR=1
+endif
+endif
+ifndef INSTALL_PREFIX
+ifdef UNIXINSTALLDIR
+INSTALL_PREFIX=/usr/local
+else
+ifdef INSTALL_FPCPACKAGE
+INSTALL_BASEDIR:=/pp
+else
+INSTALL_BASEDIR:=/$(PACKAGE_NAME)
+endif
+endif
+endif
+export INSTALL_PREFIX
+ifndef DIST_DESTDIR
+DIST_DESTDIR:=$(BASEDIR)
+endif
+export DIST_DESTDIR
+ifndef INSTALL_BASEDIR
+ifdef UNIXINSTALLDIR
+ifdef INSTALL_FPCPACKAGE
+INSTALL_BASEDIR:=$(INSTALL_PREFIX)/lib/fpc/$(FPC_VERSION)
+else
+INSTALL_BASEDIR:=$(INSTALL_PREFIX)/lib/$(PACKAGE_NAME)
+endif
+else
+INSTALL_BASEDIR:=$(INSTALL_PREFIX)
+endif
+endif
+ifndef INSTALL_BINDIR
+ifdef UNIXINSTALLDIR
+INSTALL_BINDIR:=$(INSTALL_PREFIX)/bin
+else
+INSTALL_BINDIR:=$(INSTALL_BASEDIR)/bin
+ifdef INSTALL_FPCPACKAGE
+INSTALL_BINDIR:=$(INSTALL_BINDIR)/$(OS_TARGET)
+endif
+endif
+endif
+ifndef INSTALL_UNITDIR
+INSTALL_UNITDIR:=$(INSTALL_BASEDIR)/units/$(OS_TARGET)
+ifdef INSTALL_FPCPACKAGE
+INSTALL_UNITDIR:=$(INSTALL_UNITDIR)/$(PACKAGE_NAME)
+endif
+endif
+ifndef INSTALL_LIBDIR
+ifdef UNIXINSTALLDIR
+INSTALL_LIBDIR:=$(INSTALL_PREFIX)/lib
+else
+INSTALL_LIBDIR:=$(INSTALL_UNITDIR)
+endif
+endif
+ifndef INSTALL_SOURCEDIR
+ifdef UNIXINSTALLDIR
+ifdef INSTALL_FPCPACKAGE
+INSTALL_SOURCEDIR:=$(INSTALL_PREFIX)/src/fpc-$(FPC_VERSION)/$(PACKAGE_NAME)
+else
+INSTALL_SOURCEDIR:=$(INSTALL_PREFIX)/src/$(PACKAGE_NAME)-$(PACKAGE_VERSION)
+endif
+else
+ifdef INSTALL_FPCPACKAGE
+INSTALL_SOURCEDIR:=$(INSTALL_BASEDIR)/source/$(PACKAGE_NAME)
+else
+INSTALL_SOURCEDIRL:=$(INSTALL_BASEDIR)/source
+endif
+endif
+endif
+ifndef INSTALL_DOCDIR
+ifdef UNIXINSTALLDIR
+ifdef INSTALL_FPCPACKAGE
+INSTALL_DOCDIR:=$(INSTALL_PREFIX)/doc/fpc-$(FPC_VERSION)/$(PACKAGE_NAME)
+else
+INSTALL_DOCDIR:=$(INSTALL_PREFIX)/doc/$(PACKAGE_NAME)-$(PACKAGE_VERSION)
+endif
+else
+ifdef INSTALL_FPCPACKAGE
+INSTALL_DOCDIR:=$(INSTALL_BASEDIR)/doc/$(PACKAGE_NAME)
+else
+INSTALL_DOCDIR:=$(INSTALL_BASEDIR)/doc
+endif
+endif
+endif
+ifndef INSTALL_EXAMPLEDIR
+ifdef UNIXINSTALLDIR
+ifdef INSTALL_FPCPACKAGE
+INSTALL_EXAMPLEDIR:=$(INSTALL_PREFIX)/doc/fpc-$(FPC_VERSION)/examples/$(PACKAGE_NAME)
+else
+INSTALL_EXAMPLEDIR:=$(INSTALL_PREFIX)/doc/$(PACKAGE_NAME)-$(PACKAGE_VERSION)
+endif
+else
+ifdef INSTALL_FPCPACKAGE
+INSTALL_EXAMPLEDIR:=$(INSTALL_BASEDIR)/examples/$(PACKAGE_NAME)
+else
+INSTALL_EXAMPLEDIR:=$(INSTALL_BASEDIR)/examples
+endif
+endif
+endif
+ifndef INSTALL_DATADIR
+INSTALL_DATADIR=$(INSTALL_BASEDIR)
+endif
+ifeq ($(OS_TARGET),linux)
+REQUIRE_PACKAGES_RTL=1
+endif
+ifeq ($(OS_TARGET),go32v2)
+REQUIRE_PACKAGES_RTL=1
+endif
+ifeq ($(OS_TARGET),win32)
+REQUIRE_PACKAGES_RTL=1
+endif
+ifeq ($(OS_TARGET),os2)
+REQUIRE_PACKAGES_RTL=1
+endif
+ifeq ($(OS_TARGET),freebsd)
+REQUIRE_PACKAGES_RTL=1
+endif
+ifdef REQUIRE_PACKAGES_RTL
+PACKAGEDIR_RTL:=$(subst /Makefile.fpc,,$(strip $(wildcard $(addsuffix /rtl/Makefile.fpc,$(PACKAGESDIR)))))
+ifneq ($(PACKAGEDIR_RTL),)
+PACKAGEDIR_RTL:=$(firstword $(PACKAGEDIR_RTL))
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=package_rtl
+package_rtl:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+ifneq ($(wildcard $(PACKAGEDIR_RTL)/$(OS_TARGET)),)
+UNITDIR_RTL=$(PACKAGEDIR_RTL)/$(OS_TARGET)
+else
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+endif
+else
+PACKAGEDIR_RTL=
+UNITDIR_RTL:=$(subst /Package.fpc,,$(strip $(wildcard $(addsuffix /rtl/Package.fpc,$(UNITSDIR)))))
+ifneq ($(UNITDIR_RTL),)
+UNITDIR_RTL:=$(firstword $(UNITDIR_RTL))
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override COMPILER_UNITDIR+=$(UNITDIR_RTL)
+endif
+endif
+.PHONY: package_rtl
+override FPCOPTDEF=$(CPU_TARGET)
+ifneq ($(OS_TARGET),$(OS_SOURCE))
+override FPCOPT+=-T$(OS_TARGET)
+endif
+ifdef UNITDIR
+override FPCOPT+=$(addprefix -Fu,$(UNITDIR))
+endif
+ifdef LIBDIR
+override FPCOPT+=$(addprefix -Fl,$(LIBDIR))
+endif
+ifdef OBJDIR
+override FPCOPT+=$(addprefix -Fo,$(OBJDIR))
+endif
+ifdef INCDIR
+override FPCOPT+=$(addprefix -Fi,$(INCDIR))
+endif
+ifdef LINKSMART
+override FPCOPT+=-XX
+endif
+ifdef CREATESMART
+override FPCOPT+=-CX
+endif
+ifdef DEBUG
+override FPCOPT+=-gl
+override FPCOPTDEF+=DEBUG
+endif
+ifdef RELEASE
+override FPCOPT+=-Xs -OG2p3 -n
+override FPCOPTDEF+=RELEASE
+endif
+ifdef STRIP
+override FPCOPT+=-Xs
+endif
+ifdef OPTIMIZE
+override FPCOPT+=-OG2p3
+endif
+ifdef VERBOSE
+override FPCOPT+=-vwni
+endif
+ifdef COMPILER_OPTIONS
+override FPCOPT+=$(COMPILER_OPTIONS)
+endif
+ifdef COMPILER_UNITDIR
+override FPCOPT+=$(addprefix -Fu,$(COMPILER_UNITDIR))
+endif
+ifdef COMPILER_LIBRARYDIR
+override FPCOPT+=$(addprefix -Fl,$(COMPILER_LIBRARYDIR))
+endif
+ifdef COMPILER_OBJECTDIR
+override FPCOPT+=$(addprefix -Fo,$(COMPILER_OBJECTDIR))
+endif
+ifdef COMPILER_INCLUDEDIR
+override FPCOPT+=$(addprefix -Fi,$(COMPILER_INCLUDEDIR))
+endif
+ifdef COMPILER_TARGETDIR
+override FPCOPT+=-FE$(COMPILER_TARGETDIR)
+ifeq ($(COMPILER_TARGETDIR),.)
+override TARGETDIRPREFIX=
+else
+override TARGETDIRPREFIX=$(COMPILER_TARGETDIR)/
+endif
+endif
+ifdef COMPILER_UNITTARGETDIR
+override FPCOPT+=-FU$(COMPILER_UNITTARGETDIR)
+ifeq ($(COMPILER_UNITTARGETDIR),.)
+override UNITTARGETDIRPREFIX=
+else
+override UNITTARGETDIRPREFIX=$(COMPILER_TARGETDIR)/
+endif
+else
+ifdef COMPILER_TARGETDIR
+override COMPILER_UNITTARGETDIR=$(COMPILER_TARGETDIR)
+override UNITTARGETDIRPREFIX=$(TARGETDIRPREFIX)
+endif
+endif
+ifdef OPT
+override FPCOPT+=$(OPT)
+endif
+ifdef FPCOPTDEF
+override FPCOPT+=$(addprefix -d,$(FPCOPTDEF))
+endif
+ifdef CFGFILE
+override FPCOPT+=@$(CFGFILE)
+endif
+ifeq ($(OS_SOURCE),win32)
+USEENV=1
+endif
+ifdef USEENV
+override FPCEXTCMD:=$(FPCOPT)
+override FPCOPT:=!FPCEXTCMD
+export FPCEXTCMD
+endif
+override COMPILER:=$(FPC) $(FPCOPT)
+ifeq (,$(findstring -s ,$(COMPILER)))
+EXECPPAS=
+else
+ifeq ($(OS_SOURCE),$(OS_TARGET))
+EXECPPAS:=@$(PPAS)
+endif
+endif
+.PHONY: fpc_exes
+ifdef TARGET_PROGRAMS
+override EXEFILES=$(addsuffix $(EXEEXT),$(TARGET_PROGRAMS))
+override EXEOFILES:=$(addsuffix $(OEXT),$(TARGET_PROGRAMS)) $(addprefix $(LIBPREFIX),$(addsuffix $(STATICLIBEXT),$(TARGET_PROGRAMS)))
+override ALLTARGET+=fpc_exes
+override INSTALLEXEFILES+=$(EXEFILES)
+override CLEANEXEFILES+=$(EXEFILES) $(EXEOFILES)
+ifeq ($(OS_TARGET),os2)
+override CLEANEXEFILES+=$(addsuffix $(AOUTEXT),$(TARGET_PROGRAMS))
+endif
+endif
+fpc_exes: $(EXEFILES)
+.PHONY: fpc_packages fpc_all fpc_smart fpc_debug
+$(FPCMADE): $(ALLTARGET)
+	@$(ECHO) Compiled > $(FPCMADE)
+fpc_packages: $(COMPILEPACKAGES)
+fpc_all: fpc_packages $(FPCMADE)
+fpc_smart:
+	$(MAKE) all LINKSMART=1 CREATESMART=1
+fpc_debug:
+	$(MAKE) all DEBUG=1
+.SUFFIXES: $(EXEEXT) $(PPUEXT) $(OEXT) .pas .pp
+%$(PPUEXT): %.pp
+	$(COMPILER) $<
+	$(EXECPPAS)
+%$(PPUEXT): %.pas
+	$(COMPILER) $<
+	$(EXECPPAS)
+%$(EXEEXT): %.pp
+	$(COMPILER) $<
+	$(EXECPPAS)
+%$(EXEEXT): %.pas
+	$(COMPILER) $<
+	$(EXECPPAS)
+vpath %.pp $(COMPILER_SOURCEDIR) $(COMPILER_INCLUDEDIR)
+vpath %.pas $(COMPILER_SOURCEDIR) $(COMPILER_INCLUDEDIR)
+vpath %$(PPUEXT) $(COMPILER_UNITTARGETDIR)
+.PHONY: fpc_install fpc_sourceinstall fpc_exampleinstall
+ifdef INSTALL_UNITS
+override INSTALLPPUFILES+=$(addsuffix $(PPUEXT),$(INSTALL_UNITS))
+endif
+ifdef INSTALLPPUFILES
+ifdef PPUFILES
+override INSTALLPPUFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(INSTALLPPUFILES))
+override INSTALLPPULINKFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(shell $(PPUFILES) -S -O $(INSTALLPPUFILES)))
+else
+override INSTALLPPULINKFILES:=$(subst $(PPUEXT),$(OEXT),$(INSTALLPPUFILES)) $(addprefix $(LIBPREFIX),$(subst $(PPUEXT),$(STATICLIBEXT),$(INSTALLPPUFILES)))
+override INSTALLPPUFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(INSTALLPPUFILES))
+override INSTALLPPULINKFILES:=$(wildcard $(addprefix $(UNITTARGETDIRPREFIX),$(INSTALLPPULINKFILES)))
+endif
+endif
+ifdef INSTALLEXEFILES
+override INSTALLEXEFILES:=$(addprefix $(TARGETDIRPREFIX),$(INSTALLEXEFILES))
+endif
+fpc_install: $(INSTALLTARGET)
+ifdef INSTALLEXEFILES
+	$(MKDIR) $(INSTALL_BINDIR)
+ifdef UPXPROG
+	-$(UPXPROG) $(INSTALLEXEFILES)
+endif
+	$(INSTALLEXE) $(INSTALLEXEFILES) $(INSTALL_BINDIR)
+endif
+ifdef INSTALLPPUFILES
+	$(MKDIR) $(INSTALL_UNITDIR)
+	$(INSTALL) $(INSTALLPPUFILES) $(INSTALL_UNITDIR)
+ifneq ($(INSTALLPPULINKFILES),)
+	$(INSTALL) $(INSTALLPPULINKFILES) $(INSTALL_UNITDIR)
+endif
+ifneq ($(wildcard $(LIB_FULLNAME)),)
+	$(MKDIR) $(INSTALL_LIBDIR)
+	$(INSTALL) $(LIB_FULLNAME) $(INSTALL_LIBDIR)
+ifdef inUnix
+	ln -sf $(LIB_FULLNAME) $(INSTALL_LIBDIR)/$(LIB_NAME)
+endif
+endif
+endif
+ifdef INSTALL_FILES
+	$(MKDIR) $(INSTALL_DATADIR)
+	$(INSTALL) $(INSTALL_FILES) $(INSTALL_DATADIR)
+endif
+fpc_sourceinstall: distclean
+	$(MKDIR) $(INSTALL_SOURCEDIR)
+	$(COPYTREE) $(BASEDIR) $(INSTALL_SOURCEDIR)
+fpc_exampleinstall: $(addsuffix _distclean,$(TARGET_EXAMPLEDIRS))
+ifdef HASEXAMPLES
+	$(MKDIR) $(INSTALL_EXAMPLEDIR)
+endif
+ifdef EXAMPLESOURCEFILES
+	$(COPY) $(EXAMPLESOURCEFILES) $(INSTALL_EXAMPLEDIR)
+endif
+ifdef TARGET_EXAMPLEDIRS
+	$(COPYTREE) $(addsuffix /*,$(TARGET_EXAMPLEDIRS)) $(INSTALL_EXAMPLEDIR)
+endif
+fpc_distinstall: install exampleinstall
+.PHONY: fpc_clean fpc_cleanall fpc_distclean
+ifdef EXEFILES
+override CLEANEXEFILES:=$(addprefix $(TARGETDIRPREFIX),$(CLEANEXEFILES))
+endif
+ifdef CLEAN_UNITS
+override CLEANPPUFILES+=$(addsuffix $(PPUEXT),$(CLEAN_UNITS))
+endif
+ifdef CLEANPPUFILES
+override CLEANPPUFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(CLEANPPUFILES))
+ifdef PPUFILES
+CLEANPPULINKFILES:=$(shell $(PPUFILES) $(CLEANPPUFILES))
+else
+CLEANPPULINKFILES:=$(wildcard $(subst $(PPUEXT),$(OEXT),$(CLEANPPUFILES)) $(addprefix $(LIBPREFIX),$(subst $(PPUEXT),$(STATICLIBEXT),$(CLEANPPUFILES))))
+endif
+override CLEANPPULINKFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(CLEANPPULINKFILES))
+endif
+fpc_clean: $(CLEANTARGET)
+ifdef CLEANEXEFILES
+	-$(DEL) $(CLEANEXEFILES)
+endif
+ifdef CLEANPPUFILES
+	-$(DEL) $(CLEANPPUFILES)
+endif
+ifneq ($(CLEANPPULINKFILES),)
+	-$(DEL) $(CLEANPPULINKFILES)
+endif
+ifdef CLEANRSTFILES
+	-$(DEL) $(addprefix $(UNITTARGETDIRPREFIX),$(CLEANRSTFILES))
+endif
+ifdef CLEAN_FILES
+	-$(DEL) $(CLEAN_FILES)
+endif
+ifdef LIB_NAME
+	-$(DEL) $(LIB_NAME) $(LIB_FULLNAME)
+endif
+	-$(DEL) $(FPCMADE) $(PPAS) link.res $(FPCEXTFILE) $(REDIRFILE)
+fpc_distclean: clean
+ifdef COMPILER_UNITTARGETDIR
+TARGETDIRCLEAN=fpc_clean
+endif
+fpc_cleanall: $(CLEANTARGET) $(TARGETDIRCLEAN)
+ifdef CLEANEXEFILES
+	-$(DEL) $(CLEANEXEFILES)
+endif
+	-$(DEL) *$(OEXT) *$(PPUEXT) *$(RSTEXT) *$(ASMEXT) *$(STATICLIBEXT) *$(SHAREDLIBEXT) *$(PPLEXT)
+	-$(DELTREE) *$(SMARTEXT)
+	-$(DEL) $(FPCMADE) $(PPAS) link.res $(FPCEXTFILE) $(REDIRFILE)
+ifdef AOUTEXT
+	-$(DEL) *$(AOUTEXT)
+endif
+.PHONY: fpc_info
+fpc_info:
+	@$(ECHO)
+	@$(ECHO)  == Package info ==
+	@$(ECHO)  Package Name..... $(PACKAGE_NAME)
+	@$(ECHO)  Package Version.. $(PACKAGE_VERSION)
+	@$(ECHO)
+	@$(ECHO)  == Configuration info ==
+	@$(ECHO)
+	@$(ECHO)  FPC.......... $(FPC)
+	@$(ECHO)  FPC Version.. $(FPC_VERSION)
+	@$(ECHO)  Source CPU... $(CPU_SOURCE)
+	@$(ECHO)  Target CPU... $(CPU_TARGET)
+	@$(ECHO)  Source OS.... $(OS_SOURCE)
+	@$(ECHO)  Target OS.... $(OS_TARGET)
+	@$(ECHO)
+	@$(ECHO)  == Directory info ==
+	@$(ECHO)
+	@$(ECHO)  Basedir......... $(BASEDIR)
+	@$(ECHO)  FPCDir.......... $(FPCDIR)
+	@$(ECHO)  UnitsDir........ $(UNITSDIR)
+	@$(ECHO)  PackagesDir..... $(PACKAGESDIR)
+	@$(ECHO)
+	@$(ECHO)  GCC library..... $(GCCLIBDIR)
+	@$(ECHO)  Other library... $(OTHERLIBDIR)
+	@$(ECHO)
+	@$(ECHO)  == Tools info ==
+	@$(ECHO)
+	@$(ECHO)  Pwd....... $(PWD)
+	@$(ECHO)  Echo...... $(ECHO)
+	@$(ECHO)  PPUMove... $(PPUMOVE)
+	@$(ECHO)  PPUFiles.. $(PPUFILES)
+	@$(ECHO)  Date...... $(DATE)
+	@$(ECHO)  Upx....... $(UPXPROG)
+	@$(ECHO)  Zip....... $(ZIPPROG)
+	@$(ECHO)
+	@$(ECHO)  == Object info ==
+	@$(ECHO)
+	@$(ECHO)  Target Loaders...... $(TARGET_LOADERS)
+	@$(ECHO)  Target Units........ $(TARGET_UNITS)
+	@$(ECHO)  Target Programs..... $(TARGET_PROGRAMS)
+	@$(ECHO)  Target Dirs......... $(TARGET_DIRS)
+	@$(ECHO)  Target Examples..... $(TARGET_EXAMPLES)
+	@$(ECHO)  Target ExampleDirs.. $(TARGET_EXAMPLEDIRS)
+	@$(ECHO)
+	@$(ECHO)  Clean Units......... $(CLEAN_UNITS)
+	@$(ECHO)  Clean Files......... $(CLEAN_FILES)
+	@$(ECHO)
+	@$(ECHO)  Install Units....... $(INSTALL_UNITS)
+	@$(ECHO)  Install Files....... $(INSTALL_FILES)
+	@$(ECHO)
+	@$(ECHO)  == Install info ==
+	@$(ECHO)
+	@$(ECHO)  DateStr.............. $(DATESTR)
+	@$(ECHO)  ZipPrefix............ $(ZIPPREFIX)
+	@$(ECHO)  ZipSuffix............ $(ZIPSUFFIX)
+	@$(ECHO)  Install FPC Package.. $(INSTALL_FPCPACKAGE)
+	@$(ECHO)
+	@$(ECHO)  Install base dir..... $(INSTALL_BASEDIR)
+	@$(ECHO)  Install binary dir... $(INSTALL_BINDIR)
+	@$(ECHO)  Install library dir.. $(INSTALL_LIBDIR)
+	@$(ECHO)  Install units dir.... $(INSTALL_UNITDIR)
+	@$(ECHO)  Install source dir... $(INSTALL_SOURCEDIR)
+	@$(ECHO)  Install doc dir...... $(INSTALL_DOCDIR)
+	@$(ECHO)  Install example dir.. $(INSTALL_EXAMPLEDIR)
+	@$(ECHO)  Install data dir..... $(INSTALL_DATADIR)
+	@$(ECHO)
+	@$(ECHO)  Dist destination dir. $(DIST_DESTDIR)
+	@$(ECHO)  Dist zip name........ $(DIST_ZIPNAME)
+	@$(ECHO)
+all: fpc_all
+debug: fpc_debug
+examples: fpc_examples
+smart: fpc_smart
+shared: fpc_shared
+install: fpc_install
+sourceinstall: fpc_sourceinstall
+exampleinstall: fpc_exampleinstall
+distinstall: fpc_distinstall
+zipinstall:
+zipsourceinstall:
+zipexampleinstall:
+zipdistinstall:
+clean: fpc_clean
+distclean: fpc_distclean
+cleanall: fpc_cleanall
+info: fpc_info
+.PHONY: all debug examples smart shared install sourceinstall exampleinstall distinstall zipinstall zipsourceinstall zipexampleinstall zipdistinstall clean distclean cleanall info
+ifneq ($(wildcard fpcmake.loc),)
+include fpcmake.loc
+endif

+ 9 - 0
demo/text/Makefile.fpc

@@ -0,0 +1,9 @@
+#
+#   Makefile.fpc for FPC text demos (part of FPC demo package)
+#
+
+[target]
+programs=eratos qsort hello blackbox magic lines
+
+[default]
+fpcdir=../..

+ 198 - 0
demo/text/blackbox.pp

@@ -0,0 +1,198 @@
+{
+    $Id$
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 1993-98 by Michael Van Canneyt
+
+    Blackbox Game Example
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+Program blackbox;
+
+{
+  The object of the game is simple : You have a box of 9x9x9 cells.
+  you can enter a number of atoms that will be put in the box.
+  Then you can start shooting in the box with a laser beam.
+  You enter the coordinates where the beam enters the box.
+  (this must be on the edges, this means that one of the coordinates
+  must be 1 or 9...)
+  The beam will bounce off the atoms (using normal bouncing), and you
+  will be told where the beam exits.
+  From this you must guess where the atoms are...
+}
+
+Const MaxSize = 9;
+      MaxAtom = 10;
+
+Type TRow   = Array [0..MaxSize+1] of byte;
+     TPlane = Array [0..MaxSize+1] of TRow;
+     TCube  = Array [0..MaxSize+1] of TPlane;
+
+Var
+  Cube                 : TCube;
+  Count,Guessed,x,y,z  : Longint;
+  ans : string;
+
+Procedure FillCube;
+
+var i,x,y,z : longint;
+
+begin
+  randomize;
+  for x:=0 to maxsize+1 do
+    for y:=0 to maxsize+1 do
+      for z:=0 to maxsize+1 do
+        Cube[x,y,z]:=0;
+  repeat
+    Write ('Enter number of atoms (1-',maxatom,') : ');
+    readln (count);
+    if (count<1) or (count>MaxAtom) then
+      writeln ('Invalid value entered. Please try again.');
+  until (count>0) and (count<=MaxAtom);
+  for I:=1 to count do
+     begin
+     repeat
+       x:=Random(MaxSize)+1;
+       y:=Random(MaxSize)+1;
+       z:=Random(MaxSize)+1;
+     until Cube[x,y,z]=0;
+     Cube[x,y,z]:=1;
+     end;
+end;
+
+Procedure GetCoords (Var X,y,z : longint);
+
+begin
+  Write ('X : ');
+  readln (x);
+  write ('Y : ');
+  readln (y);
+  write ('z : ');
+  readln (z);
+end;
+
+Procedure GetStart (Var x,y,z : longint);
+
+Var OK : boolean;
+
+begin
+  Writeln ('Please enter beam start coordinates : ');
+  Repeat
+    GetCoords (x,y,z);
+    OK:=((X=1) or (X=MaxSize)) or ((y=1) or (Y=MaxSize)) or
+        ((Z=1) or (z=maxsize));
+    if Not OK then
+      writeln ('The beam should enter at an edge. Please try again');
+  until OK;
+end;
+
+Function GetGuess : boolean;
+
+Var OK : boolean;
+    x,y,z : longint;
+
+begin
+  Writeln ('Please enter atom coordinates : ');
+  Repeat
+    getcoords (x,y,z);
+    OK:=((X>=1) or (X<=MaxSize)) or ((y>=1) or (Y<=MaxSize)) or
+        ((Z>=1) or (z<=maxsize));
+    if Not OK then
+      writeln ('These are not valid coordinates. Please try again');
+  until OK;
+  GetGuess:=False;
+  If Cube[x,y,z]<0 then
+    Writeln ('You already had this one ! Trying to be clever, eh ?')
+  else if Cube[x,y,z]>0 then
+    begin
+    Writeln ('Correct guess !');
+    Cube[x,y,z]:=-Cube[x,y,z];
+    getguess:=true;
+    end
+  else
+    Writeln ('Wrong guess !');
+end;
+
+Procedure CalcExit (X,Y,Z : longint);
+
+var tx,ty,tz,dx,dy,dz : longint;
+
+begin
+  dx:=0;dy:=0;dz:=0;
+  if x=1 then dx:=1 else if x=MaxSize then dx:=-1;
+  if y=1 then dy:=1 else if y=MaxSize then dy:=-1;
+  if z=1 then dz:=1 else if z=MaxSize then dz:=-1;
+  writeln ('Direction : ',dx,',',dy,',',dz);
+  repeat
+  for tx:=-1 to 1 do
+    for ty:=-1 to 1 do
+      for tz:=-1 to 1 do
+        if Cube [X+tx,y+ty,z+tz]<>0 then
+          begin
+          dx:=dx-tx;
+          dy:=dy-ty;
+          dz:=dz-tz;
+          end;
+  if dx<>0 then dx:=dx div abs(dx);
+  if dz<>0 then dz:=dz div abs(dz);
+  if dy<>0 then dy:=dy div abs(dy);
+  x:=x+dx;y:=y+dy;z:=z+dz;
+  until ((x=0) or (x=MaxSize+1)) or ((y=0) or (y=maxsize+1)) or
+        ((z=0) or (z=maxsize+1));
+  Writeln ('Beam exited at : (',x-dx,',',y-dy,',',z-dz,')');
+end;
+
+{
+Procedure DumpCube ;
+
+Var x,y,z : longint;
+
+begin
+  for x:=1 to MaxSize do
+    for y:=1 to maxsize do
+      for z:=1 to maxsize do
+        if Cube[x,y,z]<>0 then
+          writeln ('Atom at (',x,',',y,',',z,')');
+end;
+}
+
+begin
+  FillCube;
+  Guessed:=0;
+  Repeat
+    repeat
+      Write ('Shoot, guess or quit (s/g/q) : ');
+      readln (ans);
+      ans[1]:=Upcase(ans[1]);
+      if not (ans[1] in ['S','G','Q']) then
+        writeln ('Invalid entry. Please try again.');
+    until ans[1] in ['S','G','Q'];
+    Case ans[1] of
+     'S' : begin
+           getstart (x,y,z);
+           calcexit (x,y,z);
+           end;
+     'G' : If GetGuess then Inc(Guessed);
+    end;
+  until (ans[1]='Q') or (guessed=count);
+  If Guessed=count then
+    Writeln ('Congratulations! All ',Count,' correct !')
+  else
+    Writeln ('Only ',guessed,' out of ',count,' correct...');
+end.
+
+{
+  $Log$
+  Revision 1.1  2001-05-03 21:39:34  peter
+    * moved to own module
+
+  Revision 1.2  2000/07/13 11:33:10  michael
+  + removed logs
+ 
+}

+ 64 - 0
demo/text/eratos.pp

@@ -0,0 +1,64 @@
+{
+    $Id$
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 1993-98 by Florian Klaempfl
+
+    Eratos Example, Calculates all Prime Numbers from 1 to max
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+program eratosthenes;
+
+  const
+     max = 1000000;
+  var
+     a : array[1..max] of boolean;
+
+  procedure eratos;
+
+    var
+       i,j : longint;
+
+    begin
+       a[1]:=false;
+       for i:=2 to max do
+         a[i]:=true;
+       for i:=2 to max div 2 do
+         if a[i] then
+           for j:=2 to max div i do
+             a[i*j]:=false;
+       writeln;
+       j:=0;
+       for i:=1 to max do
+        begin
+          if a[i] then
+           begin
+             write(i:7);
+             inc(j);
+             if (j mod 10)=0 then
+              writeln;
+           end;
+        end;
+       writeln;
+    end;
+
+  begin
+     write('Calculating the Prime Numbers from 1 to ',max,'...');
+     eratos;
+  end.
+
+{
+  $Log$
+  Revision 1.1  2001-05-03 21:39:34  peter
+    * moved to own module
+
+  Revision 1.2  2000/07/13 11:33:10  michael
+  + removed logs
+ 
+}

+ 29 - 0
demo/text/hello.pp

@@ -0,0 +1,29 @@
+{
+    $Id$
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 1993-98 by the Free Pascal Development Team
+
+    Hello World Example
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+
+program hello;
+
+  begin
+     writeln('Hello world');
+  end.
+    $Log$
+    Revision 1.1  2001-05-03 21:39:34  peter
+      * moved to own module
+
+    Revision 1.2  2000/07/13 11:33:10  michael
+    + removed logs
+ 
+}

+ 84 - 0
demo/text/lines.pp

@@ -0,0 +1,84 @@
+{
+    $Id$
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 1993-98 by Florian Klaempfl
+
+    Line Counter Example
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+program count_lines;
+{
+  Program that counts number of Lines in a file
+}
+
+  uses
+     dos,crt;
+
+  type
+     td = array[1..10000] of byte;
+
+  var
+     lines : longint;
+     s : searchrec;
+     f : file;
+     d : ^td;
+{$ifdef tp}
+     count : word;
+     i,z   : integer;
+{$else}
+     count,i,z : longint;
+{$endif}
+
+  begin
+     lines:=0;
+     new(d);
+     if paramcount<1 then
+       begin
+          writeln('Usage: ',paramstr(0),' filename.ext [filename.ext] ...');
+          writeln('  Multiple File Names and Wild Cards Allowed:');
+          writeln('  Example: lines *.cpp stdio.h *.asm');
+          halt(1);
+       end;
+     for i:=1 to paramcount do
+       begin
+          findfirst(paramstr(i),archive,s);
+          while (doserror=0) do
+            begin
+               gotoxy(1,wherey);
+               write('                               ');
+               gotoxy(1,wherey);
+               write('Scanning: ',s.name);
+               assign(f,s.name);
+               reset(f,1);
+               while not(eof(f)) do
+                 begin
+                    blockread(f,d^,10000,count);
+                    for z:=1 to count do
+                      if d^[z]=10 then inc(lines);
+                 end;
+               close(f);
+               findnext(s);
+            end;
+       end;
+     dispose(d);
+     gotoxy(1,wherey);
+     write('                               ');
+     gotoxy(1,wherey);
+     if lines=1 then writeln('1 Line') else writeln(lines,' Lines');
+  end.
+{
+  $Log$
+  Revision 1.1  2001-05-03 21:39:34  peter
+    * moved to own module
+
+  Revision 1.2  2000/07/13 11:33:10  michael
+  + removed logs
+ 
+}

+ 107 - 0
demo/text/magic.pp

@@ -0,0 +1,107 @@
+{
+    $Id$
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 1993-98 by Florian Klaempfl
+
+    Magic Square Example
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+program magic;
+
+{
+  Calculate a magic square (sum of the row, colums and diagonals is equal
+}
+
+  const
+     maxsize = 11;
+
+  type
+     sqrtype = array[1..maxsize, 1..maxsize] of longint;
+
+  var
+     square : sqrtype;
+     size, row, sum : longint;
+
+  procedure makesquare(var sq : sqrtype;limit : longint);
+
+    var
+       num,r,c : longint;
+
+    begin
+       for r:=1 to limit do
+         for c:=1 to limit do
+           sq[r, c] := 0;
+       if (limit and 1)<>0 then
+         begin
+            r:=(limit+1) div 2;
+            c:=limit;
+            for num:=1 to limit*limit do
+              begin
+                 if sq[r,c]<>0 then
+                   begin
+                      dec(r);
+                      if r<1 then
+                        inc(r,limit);
+                      dec(c,2);
+                      if c<1 then
+                        inc(c,limit);
+                   end;
+                 sq[r,c]:=num;
+                 inc(r);
+                 if r>limit then
+                   dec(r,limit);
+                 inc(c);
+                 if c>limit then
+                   dec(c,limit);
+              end;
+         end;
+     end;
+
+  procedure writesquare(var sq : sqrtype;limit : longint);
+
+    var
+       row,col : longint;
+
+    begin
+       for row:=1 to Limit do
+         begin
+            for col:=1 to (limit div 2) do
+              write(sq[row,2*col-1]:4,' ',sq[row,2*col]:4,' ');
+            writeln(sq[row,limit]:4);
+         end;
+    end;
+
+begin
+  size:=3;
+  while (size<=maxsize) do
+    begin
+       writeln('Magic Square with size ',size);
+       writeln;
+       makesquare(square,size);
+       writesquare(square,size);
+       writeln;
+       sum:=0;
+       for row:=1 to size do
+         inc(sum,square[row,1]);
+       writeln('Sum of the rows,columns and diagonals = ', sum);
+       writeln;
+       writeln;
+       inc(size,2);
+    end;
+end.
+{
+  $Log$
+  Revision 1.1  2001-05-03 21:39:34  peter
+    * moved to own module
+
+  Revision 1.2  2000/07/13 11:33:10  michael
+  + removed logs
+ 
+}

+ 87 - 0
demo/text/qsort.pp

@@ -0,0 +1,87 @@
+{
+    $Id$
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 1993-98 by the Free Pascal Development Team
+
+    QuickSort Example
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+program quicksort;
+
+  const
+     max = 100000;
+
+  type
+     tlist = array[1..max] of longint;
+
+  var
+     data : tlist;
+
+
+procedure qsort(var a : tlist);
+
+    procedure sort(l,r: longint);
+      var
+         i,j,x,y: longint;
+      begin
+         i:=l;
+         j:=r;
+         x:=a[(l+r) div 2];
+         repeat
+           while a[i]<x do
+            inc(i);
+           while x<a[j] do
+            dec(j);
+           if not(i>j) then
+             begin
+                y:=a[i];
+                a[i]:=a[j];
+                a[j]:=y;
+                inc(i);
+                j:=j-1;
+             end;
+         until i>j;
+         if l<j then
+           sort(l,j);
+         if i<r then
+           sort(i,r);
+      end;
+
+    begin
+       sort(1,max);
+    end;
+
+var
+  i : longint;
+begin
+  write('Creating ',Max,' random numbers between 1 and 500000');
+  randomize;
+  for i:=1 to max do
+    data[i]:=random(500000);
+  writeln;
+  writeln('Sorting...');
+  qsort(data);
+  writeln;
+  for i:=1 to max do
+   begin
+     write(data[i]:7);
+     if (i mod 10)=0 then
+      writeln;
+   end;
+end.
+{
+  $Log$
+  Revision 1.1  2001-05-03 21:39:34  peter
+    * moved to own module
+
+  Revision 1.2  2000/07/13 11:33:10  michael
+  + removed logs
+ 
+}

+ 828 - 0
demo/win32/Makefile

@@ -0,0 +1,828 @@
+#
+# Don't edit, this file is generated by fpcmake v1.99.0 [2001/05/03]
+#
+default: all
+override PATH:=$(subst \,/,$(PATH))
+ifeq ($(findstring ;,$(PATH)),)
+inUnix=1
+SEARCHPATH:=$(subst :, ,$(PATH))
+else
+SEARCHPATH:=$(subst ;, ,$(PATH))
+endif
+PWD:=$(strip $(wildcard $(addsuffix /pwd.exe,$(SEARCHPATH))))
+ifeq ($(PWD),)
+PWD:=$(strip $(wildcard $(addsuffix /pwd,$(SEARCHPATH))))
+ifeq ($(PWD),)
+nopwd:
+	@echo You need the GNU utils package to use this Makefile!
+	@echo Get ftp://ftp.freepascal.org/pub/fpc/dist/go32v2/utilgo32.zip
+	@exit
+else
+PWD:=$(firstword $(PWD))
+SRCEXEEXT=
+endif
+else
+PWD:=$(firstword $(PWD))
+SRCEXEEXT=.exe
+endif
+ifndef inUnix
+ifeq ($(OS),Windows_NT)
+inWinNT=1
+else
+ifdef OS2_SHELL
+inOS2=1
+endif
+endif
+else
+ifneq ($(findstring cygwin,$(MACH_TYPE)),)
+inCygWin=1
+endif
+endif
+ifdef inUnix
+BATCHEXT=.sh
+else
+ifdef inOS2
+BATCHEXT=.cmd
+else
+BATCHEXT=.bat
+endif
+endif
+ifdef inUnix
+PATHSEP=/
+else
+PATHSEP:=$(subst /,\,/)
+endif
+ifdef PWD
+BASEDIR:=$(shell $(PWD))
+else
+BASEDIR=.
+endif
+ifndef FPC
+ifdef PP
+FPC=$(PP)
+else
+FPC=ppc386
+endif
+endif
+override FPC:=$(subst $(SRCEXEEXT),,$(FPC))
+override FPC:=$(subst \,/,$(FPC))$(SRCEXEEXT)
+ifndef OS_TARGET
+OS_TARGET:=$(shell $(FPC) -iTO)
+endif
+ifndef OS_SOURCE
+OS_SOURCE:=$(shell $(FPC) -iSO)
+endif
+ifndef CPU_TARGET
+CPU_TARGET:=$(shell $(FPC) -iTP)
+endif
+ifndef CPU_SOURCE
+CPU_SOURCE:=$(shell $(FPC) -iSP)
+endif
+ifndef FPC_VERSION
+FPC_VERSION:=$(shell $(FPC) -iV)
+endif
+export FPC OS_TARGET OS_SOURCE CPU_TARGET CPU_SOURCE FPC_VERSION
+ifdef FPCDIR
+override FPCDIR:=$(subst \,/,$(FPCDIR))
+ifeq ($(wildcard $(addprefix $(FPCDIR)/,rtl units)),)
+override FPCDIR=wrong
+endif
+else
+override FPCDIR=wrong
+endif
+ifeq ($(FPCDIR),wrong)
+override FPCDIR=../..
+ifeq ($(wildcard $(FPCDIR)/rtl),)
+ifeq ($(wildcard $(FPCDIR)/units),)
+override FPCDIR=wrong
+endif
+endif
+endif
+ifeq ($(FPCDIR),wrong)
+ifdef inUnix
+override FPCDIR=/usr/local/lib/fpc/$(FPC_VERSION)
+ifeq ($(wildcard $(FPCDIR)/units),)
+override FPCDIR=/usr/lib/fpc/$(FPC_VERSION)
+endif
+else
+override FPCDIR:=$(subst /$(FPC),,$(firstword $(strip $(wildcard $(addsuffix /$(FPC),$(SEARCHPATH))))))
+override FPCDIR:=$(FPCDIR)/..
+ifeq ($(wildcard $(addprefix $(FPCDIR)/,rtl units)),)
+override FPCDIR:=$(FPCDIR)/..
+ifeq ($(wildcard $(addprefix $(FPCDIR)/,rtl units)),)
+override FPCDIR=c:/pp
+endif
+endif
+endif
+endif
+UNITSDIR:=$(wildcard $(FPCDIR)/units/$(OS_TARGET))
+PACKAGESDIR:=$(wildcard $(FPCDIR) $(FPCDIR)/packages)
+ifeq ($(OS_TARGET),win32)
+override TARGET_PROGRAMS+=winhello menu dlltest testdll edit
+endif
+ifndef ECHO
+ECHO:=$(strip $(wildcard $(addsuffix /gecho$(EXEEXT),$(SEARCHPATH))))
+ifeq ($(ECHO),)
+ECHO:=$(strip $(wildcard $(addsuffix /echo$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(ECHO),)
+ECHO:=echo
+else
+ECHO:=$(firstword $(ECHO))
+endif
+else
+ECHO:=$(firstword $(ECHO))
+endif
+endif
+ifndef COPY
+COPY:=cp -fp
+endif
+ifndef COPYTREE
+COPYTREE:=cp -rfp
+endif
+ifndef MOVE
+MOVE:=mv -f
+endif
+ifndef DEL
+DEL:=rm -f
+endif
+ifndef DELTREE
+DELTREE:=rm -rf
+endif
+ifndef INSTALL
+ifdef inUnix
+INSTALL:=install -c -m 644
+else
+INSTALL:=$(COPY)
+endif
+endif
+ifndef INSTALLEXE
+ifdef inUnix
+INSTALLEXE:=install -c -m 755
+else
+INSTALLEXE:=$(COPY)
+endif
+endif
+ifndef MKDIR
+ifdef inUnix
+MKDIR:=install -m 755 -d
+else
+MKDIR:=ginstall -m 755 -d
+endif
+endif
+export ECHO COPY COPYTREE MOVE DEL DELTREE INSTALL INSTALLEXE MKDIR
+ifndef AS
+AS=as
+endif
+ifndef LD
+LD=ld
+endif
+ifndef RC
+RC=rc
+endif
+PPAS=ppas$(BATCHEXT)
+ifdef inUnix
+LDCONFIG=ldconfig
+else
+LDCONFIG=
+endif
+ifndef PPUMOVE
+PPUMOVE:=$(strip $(wildcard $(addsuffix /ppumove$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(PPUMOVE),)
+PPUMOVE=
+else
+PPUMOVE:=$(firstword $(PPUMOVE))
+endif
+endif
+export PPUMOVE
+ifndef PPUFILES
+PPUFILES:=$(strip $(wildcard $(addsuffix /ppufiles$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(PPUFILES),)
+PPUFILES=
+else
+PPUFILES:=$(firstword $(PPUFILES))
+endif
+endif
+export PPUFILES
+ifndef DATE
+DATE:=$(strip $(wildcard $(addsuffix /date$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(DATE),)
+DATE:=$(strip $(wildcard $(addsuffix /gdate$(SRCEXEEXT),$(SEACHPATH))))
+ifeq ($(DATE),)
+DATE=
+else
+DATE:=$(firstword $(DATE))
+endif
+else
+DATE:=$(firstword $(DATE))
+endif
+endif
+export DATE
+ifdef DATE
+DATESTR:=$(shell $(DATE) +%Y%m%d)
+else
+DATESTR=
+endif
+ifndef UPXPROG
+ifeq ($(OS_TARGET),go32v2)
+UPXPROG:=1
+endif
+ifeq ($(OS_TARGET),win32)
+UPXPROG:=1
+endif
+ifdef UPXPROG
+UPXPROG:=$(strip $(wildcard $(addsuffix /upx$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(UPXPROG),)
+UPXPROG=
+else
+UPXPROG:=$(firstword $(UPXPROG))
+endif
+else
+UPXPROG=
+endif
+endif
+export UPXPROG
+ifndef ZIPPROG
+ZIPPROG:=$(strip $(wildcard $(addsuffix /zip$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(ZIPPROG),)
+ZIPPROG=
+else
+ZIPPROG:=$(firstword $(ZIPPROG))
+endif
+endif
+export ZIPPROG
+ZIPOPT=-9
+ZIPEXT=.zip
+ifndef TARPROG
+TARPROG:=$(strip $(wildcard $(addsuffix /tar$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(TARPROG),)
+TARPROG=
+else
+TARPROG:=$(firstword $(TARPROG))
+endif
+endif
+export TARPROG
+ifeq ($(USETAR),bz2)
+TAROPT=vI
+TAREXT=.tar.bz2
+else
+TAROPT=vz
+TAREXT=.tar.gz
+endif
+LOADEREXT=.as
+EXEEXT=.exe
+PPLEXT=.ppl
+PPUEXT=.ppu
+OEXT=.o
+ASMEXT=.s
+SMARTEXT=.sl
+STATICLIBEXT=.a
+SHAREDLIBEXT=.so
+LIBPREFIX=lib
+RSTEXT=.rst
+FPCMADE=fpcmade
+ifeq ($(OS_TARGET),go32v1)
+PPUEXT=.pp1
+OEXT=.o1
+ASMEXT=.s1
+SMARTEXT=.sl1
+STATICLIBEXT=.a1
+SHAREDLIBEXT=.so1
+LIBPREFIX=
+FPCMADE=fpcmade.v1
+PACKAGESUFFIX=v1
+endif
+ifeq ($(OS_TARGET),go32v2)
+LIBPREFIX=
+FPCMADE=fpcmade.dos
+ZIPSUFFIX=go32
+endif
+ifeq ($(OS_TARGET),linux)
+EXEEXT=
+HASSHAREDLIB=1
+FPCMADE=fpcmade.lnx
+ZIPSUFFIX=linux
+endif
+ifeq ($(OS_TARGET),freebsd)
+EXEEXT=
+HASSHAREDLIB=1
+FPCMADE=fpcmade.freebsd
+ZIPSUFFIX=freebsd
+endif
+ifeq ($(OS_TARGET),win32)
+PPUEXT=.ppw
+OEXT=.ow
+ASMEXT=.sw
+SMARTEXT=.slw
+STATICLIBEXT=.aw
+SHAREDLIBEXT=.dll
+FPCMADE=fpcmade.w32
+ZIPSUFFIX=w32
+endif
+ifeq ($(OS_TARGET),os2)
+PPUEXT=.ppo
+ASMEXT=.so2
+OEXT=.oo2
+AOUTEXT=.out
+SMARTEXT=.so
+STATICLIBEXT=.ao2
+SHAREDLIBEXT=.dll
+FPCMADE=fpcmade.os2
+ZIPSUFFIX=emx
+endif
+ifdef REQUIRE_UNITSDIR
+override UNITSDIR+=$(REQUIRE_UNITSDIR)
+endif
+ifdef REQUIRE_PACKAGESDIR
+override PACKAGESDIR+=$(REQUIRE_PACKAGESDIR)
+endif
+ifdef ZIPINSTALL
+ifeq ($(OS_TARGET),linux)
+UNIXINSTALLDIR=1
+endif
+ifeq ($(OS_TARGET),freebsd)
+UNIXINSTALLDIR=1
+endif
+else
+ifeq ($(OS_SOURCE),linux)
+UNIXINSTALLDIR=1
+endif
+ifeq ($(OS_SOURCE),freebsd)
+UNIXINSTALLDIR=1
+endif
+endif
+ifndef INSTALL_PREFIX
+ifdef UNIXINSTALLDIR
+INSTALL_PREFIX=/usr/local
+else
+ifdef INSTALL_FPCPACKAGE
+INSTALL_BASEDIR:=/pp
+else
+INSTALL_BASEDIR:=/$(PACKAGE_NAME)
+endif
+endif
+endif
+export INSTALL_PREFIX
+ifndef DIST_DESTDIR
+DIST_DESTDIR:=$(BASEDIR)
+endif
+export DIST_DESTDIR
+ifndef INSTALL_BASEDIR
+ifdef UNIXINSTALLDIR
+ifdef INSTALL_FPCPACKAGE
+INSTALL_BASEDIR:=$(INSTALL_PREFIX)/lib/fpc/$(FPC_VERSION)
+else
+INSTALL_BASEDIR:=$(INSTALL_PREFIX)/lib/$(PACKAGE_NAME)
+endif
+else
+INSTALL_BASEDIR:=$(INSTALL_PREFIX)
+endif
+endif
+ifndef INSTALL_BINDIR
+ifdef UNIXINSTALLDIR
+INSTALL_BINDIR:=$(INSTALL_PREFIX)/bin
+else
+INSTALL_BINDIR:=$(INSTALL_BASEDIR)/bin
+ifdef INSTALL_FPCPACKAGE
+INSTALL_BINDIR:=$(INSTALL_BINDIR)/$(OS_TARGET)
+endif
+endif
+endif
+ifndef INSTALL_UNITDIR
+INSTALL_UNITDIR:=$(INSTALL_BASEDIR)/units/$(OS_TARGET)
+ifdef INSTALL_FPCPACKAGE
+INSTALL_UNITDIR:=$(INSTALL_UNITDIR)/$(PACKAGE_NAME)
+endif
+endif
+ifndef INSTALL_LIBDIR
+ifdef UNIXINSTALLDIR
+INSTALL_LIBDIR:=$(INSTALL_PREFIX)/lib
+else
+INSTALL_LIBDIR:=$(INSTALL_UNITDIR)
+endif
+endif
+ifndef INSTALL_SOURCEDIR
+ifdef UNIXINSTALLDIR
+ifdef INSTALL_FPCPACKAGE
+INSTALL_SOURCEDIR:=$(INSTALL_PREFIX)/src/fpc-$(FPC_VERSION)/$(PACKAGE_NAME)
+else
+INSTALL_SOURCEDIR:=$(INSTALL_PREFIX)/src/$(PACKAGE_NAME)-$(PACKAGE_VERSION)
+endif
+else
+ifdef INSTALL_FPCPACKAGE
+INSTALL_SOURCEDIR:=$(INSTALL_BASEDIR)/source/$(PACKAGE_NAME)
+else
+INSTALL_SOURCEDIRL:=$(INSTALL_BASEDIR)/source
+endif
+endif
+endif
+ifndef INSTALL_DOCDIR
+ifdef UNIXINSTALLDIR
+ifdef INSTALL_FPCPACKAGE
+INSTALL_DOCDIR:=$(INSTALL_PREFIX)/doc/fpc-$(FPC_VERSION)/$(PACKAGE_NAME)
+else
+INSTALL_DOCDIR:=$(INSTALL_PREFIX)/doc/$(PACKAGE_NAME)-$(PACKAGE_VERSION)
+endif
+else
+ifdef INSTALL_FPCPACKAGE
+INSTALL_DOCDIR:=$(INSTALL_BASEDIR)/doc/$(PACKAGE_NAME)
+else
+INSTALL_DOCDIR:=$(INSTALL_BASEDIR)/doc
+endif
+endif
+endif
+ifndef INSTALL_EXAMPLEDIR
+ifdef UNIXINSTALLDIR
+ifdef INSTALL_FPCPACKAGE
+INSTALL_EXAMPLEDIR:=$(INSTALL_PREFIX)/doc/fpc-$(FPC_VERSION)/examples/$(PACKAGE_NAME)
+else
+INSTALL_EXAMPLEDIR:=$(INSTALL_PREFIX)/doc/$(PACKAGE_NAME)-$(PACKAGE_VERSION)
+endif
+else
+ifdef INSTALL_FPCPACKAGE
+INSTALL_EXAMPLEDIR:=$(INSTALL_BASEDIR)/examples/$(PACKAGE_NAME)
+else
+INSTALL_EXAMPLEDIR:=$(INSTALL_BASEDIR)/examples
+endif
+endif
+endif
+ifndef INSTALL_DATADIR
+INSTALL_DATADIR=$(INSTALL_BASEDIR)
+endif
+ifeq ($(OS_TARGET),linux)
+REQUIRE_PACKAGES_RTL=1
+endif
+ifeq ($(OS_TARGET),go32v2)
+REQUIRE_PACKAGES_RTL=1
+endif
+ifeq ($(OS_TARGET),win32)
+REQUIRE_PACKAGES_RTL=1
+endif
+ifeq ($(OS_TARGET),os2)
+REQUIRE_PACKAGES_RTL=1
+endif
+ifeq ($(OS_TARGET),freebsd)
+REQUIRE_PACKAGES_RTL=1
+endif
+ifdef REQUIRE_PACKAGES_RTL
+PACKAGEDIR_RTL:=$(subst /Makefile.fpc,,$(strip $(wildcard $(addsuffix /rtl/Makefile.fpc,$(PACKAGESDIR)))))
+ifneq ($(PACKAGEDIR_RTL),)
+PACKAGEDIR_RTL:=$(firstword $(PACKAGEDIR_RTL))
+ifeq ($(wildcard $(PACKAGEDIR_RTL)/$(FPCMADE)),)
+override COMPILEPACKAGES+=package_rtl
+package_rtl:
+	$(MAKE) -C $(PACKAGEDIR_RTL) all
+endif
+ifneq ($(wildcard $(PACKAGEDIR_RTL)/$(OS_TARGET)),)
+UNITDIR_RTL=$(PACKAGEDIR_RTL)/$(OS_TARGET)
+else
+UNITDIR_RTL=$(PACKAGEDIR_RTL)
+endif
+else
+PACKAGEDIR_RTL=
+UNITDIR_RTL:=$(subst /Package.fpc,,$(strip $(wildcard $(addsuffix /rtl/Package.fpc,$(UNITSDIR)))))
+ifneq ($(UNITDIR_RTL),)
+UNITDIR_RTL:=$(firstword $(UNITDIR_RTL))
+else
+UNITDIR_RTL=
+endif
+endif
+ifdef UNITDIR_RTL
+override COMPILER_UNITDIR+=$(UNITDIR_RTL)
+endif
+endif
+.PHONY: package_rtl
+override FPCOPTDEF=$(CPU_TARGET)
+ifneq ($(OS_TARGET),$(OS_SOURCE))
+override FPCOPT+=-T$(OS_TARGET)
+endif
+ifdef UNITDIR
+override FPCOPT+=$(addprefix -Fu,$(UNITDIR))
+endif
+ifdef LIBDIR
+override FPCOPT+=$(addprefix -Fl,$(LIBDIR))
+endif
+ifdef OBJDIR
+override FPCOPT+=$(addprefix -Fo,$(OBJDIR))
+endif
+ifdef INCDIR
+override FPCOPT+=$(addprefix -Fi,$(INCDIR))
+endif
+ifdef LINKSMART
+override FPCOPT+=-XX
+endif
+ifdef CREATESMART
+override FPCOPT+=-CX
+endif
+ifdef DEBUG
+override FPCOPT+=-gl
+override FPCOPTDEF+=DEBUG
+endif
+ifdef RELEASE
+override FPCOPT+=-Xs -OG2p3 -n
+override FPCOPTDEF+=RELEASE
+endif
+ifdef STRIP
+override FPCOPT+=-Xs
+endif
+ifdef OPTIMIZE
+override FPCOPT+=-OG2p3
+endif
+ifdef VERBOSE
+override FPCOPT+=-vwni
+endif
+ifdef COMPILER_OPTIONS
+override FPCOPT+=$(COMPILER_OPTIONS)
+endif
+ifdef COMPILER_UNITDIR
+override FPCOPT+=$(addprefix -Fu,$(COMPILER_UNITDIR))
+endif
+ifdef COMPILER_LIBRARYDIR
+override FPCOPT+=$(addprefix -Fl,$(COMPILER_LIBRARYDIR))
+endif
+ifdef COMPILER_OBJECTDIR
+override FPCOPT+=$(addprefix -Fo,$(COMPILER_OBJECTDIR))
+endif
+ifdef COMPILER_INCLUDEDIR
+override FPCOPT+=$(addprefix -Fi,$(COMPILER_INCLUDEDIR))
+endif
+ifdef COMPILER_TARGETDIR
+override FPCOPT+=-FE$(COMPILER_TARGETDIR)
+ifeq ($(COMPILER_TARGETDIR),.)
+override TARGETDIRPREFIX=
+else
+override TARGETDIRPREFIX=$(COMPILER_TARGETDIR)/
+endif
+endif
+ifdef COMPILER_UNITTARGETDIR
+override FPCOPT+=-FU$(COMPILER_UNITTARGETDIR)
+ifeq ($(COMPILER_UNITTARGETDIR),.)
+override UNITTARGETDIRPREFIX=
+else
+override UNITTARGETDIRPREFIX=$(COMPILER_TARGETDIR)/
+endif
+else
+ifdef COMPILER_TARGETDIR
+override COMPILER_UNITTARGETDIR=$(COMPILER_TARGETDIR)
+override UNITTARGETDIRPREFIX=$(TARGETDIRPREFIX)
+endif
+endif
+ifdef OPT
+override FPCOPT+=$(OPT)
+endif
+ifdef FPCOPTDEF
+override FPCOPT+=$(addprefix -d,$(FPCOPTDEF))
+endif
+ifdef CFGFILE
+override FPCOPT+=@$(CFGFILE)
+endif
+ifeq ($(OS_SOURCE),win32)
+USEENV=1
+endif
+ifdef USEENV
+override FPCEXTCMD:=$(FPCOPT)
+override FPCOPT:=!FPCEXTCMD
+export FPCEXTCMD
+endif
+override COMPILER:=$(FPC) $(FPCOPT)
+ifeq (,$(findstring -s ,$(COMPILER)))
+EXECPPAS=
+else
+ifeq ($(OS_SOURCE),$(OS_TARGET))
+EXECPPAS:=@$(PPAS)
+endif
+endif
+.PHONY: fpc_exes
+ifdef TARGET_PROGRAMS
+override EXEFILES=$(addsuffix $(EXEEXT),$(TARGET_PROGRAMS))
+override EXEOFILES:=$(addsuffix $(OEXT),$(TARGET_PROGRAMS)) $(addprefix $(LIBPREFIX),$(addsuffix $(STATICLIBEXT),$(TARGET_PROGRAMS)))
+override ALLTARGET+=fpc_exes
+override INSTALLEXEFILES+=$(EXEFILES)
+override CLEANEXEFILES+=$(EXEFILES) $(EXEOFILES)
+ifeq ($(OS_TARGET),os2)
+override CLEANEXEFILES+=$(addsuffix $(AOUTEXT),$(TARGET_PROGRAMS))
+endif
+endif
+fpc_exes: $(EXEFILES)
+.PHONY: fpc_packages fpc_all fpc_smart fpc_debug
+$(FPCMADE): $(ALLTARGET)
+	@$(ECHO) Compiled > $(FPCMADE)
+fpc_packages: $(COMPILEPACKAGES)
+fpc_all: fpc_packages $(FPCMADE)
+fpc_smart:
+	$(MAKE) all LINKSMART=1 CREATESMART=1
+fpc_debug:
+	$(MAKE) all DEBUG=1
+.SUFFIXES: $(EXEEXT) $(PPUEXT) $(OEXT) .pas .pp
+%$(PPUEXT): %.pp
+	$(COMPILER) $<
+	$(EXECPPAS)
+%$(PPUEXT): %.pas
+	$(COMPILER) $<
+	$(EXECPPAS)
+%$(EXEEXT): %.pp
+	$(COMPILER) $<
+	$(EXECPPAS)
+%$(EXEEXT): %.pas
+	$(COMPILER) $<
+	$(EXECPPAS)
+vpath %.pp $(COMPILER_SOURCEDIR) $(COMPILER_INCLUDEDIR)
+vpath %.pas $(COMPILER_SOURCEDIR) $(COMPILER_INCLUDEDIR)
+vpath %$(PPUEXT) $(COMPILER_UNITTARGETDIR)
+.PHONY: fpc_install fpc_sourceinstall fpc_exampleinstall
+ifdef INSTALL_UNITS
+override INSTALLPPUFILES+=$(addsuffix $(PPUEXT),$(INSTALL_UNITS))
+endif
+ifdef INSTALLPPUFILES
+ifdef PPUFILES
+override INSTALLPPUFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(INSTALLPPUFILES))
+override INSTALLPPULINKFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(shell $(PPUFILES) -S -O $(INSTALLPPUFILES)))
+else
+override INSTALLPPULINKFILES:=$(subst $(PPUEXT),$(OEXT),$(INSTALLPPUFILES)) $(addprefix $(LIBPREFIX),$(subst $(PPUEXT),$(STATICLIBEXT),$(INSTALLPPUFILES)))
+override INSTALLPPUFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(INSTALLPPUFILES))
+override INSTALLPPULINKFILES:=$(wildcard $(addprefix $(UNITTARGETDIRPREFIX),$(INSTALLPPULINKFILES)))
+endif
+endif
+ifdef INSTALLEXEFILES
+override INSTALLEXEFILES:=$(addprefix $(TARGETDIRPREFIX),$(INSTALLEXEFILES))
+endif
+fpc_install: $(INSTALLTARGET)
+ifdef INSTALLEXEFILES
+	$(MKDIR) $(INSTALL_BINDIR)
+ifdef UPXPROG
+	-$(UPXPROG) $(INSTALLEXEFILES)
+endif
+	$(INSTALLEXE) $(INSTALLEXEFILES) $(INSTALL_BINDIR)
+endif
+ifdef INSTALLPPUFILES
+	$(MKDIR) $(INSTALL_UNITDIR)
+	$(INSTALL) $(INSTALLPPUFILES) $(INSTALL_UNITDIR)
+ifneq ($(INSTALLPPULINKFILES),)
+	$(INSTALL) $(INSTALLPPULINKFILES) $(INSTALL_UNITDIR)
+endif
+ifneq ($(wildcard $(LIB_FULLNAME)),)
+	$(MKDIR) $(INSTALL_LIBDIR)
+	$(INSTALL) $(LIB_FULLNAME) $(INSTALL_LIBDIR)
+ifdef inUnix
+	ln -sf $(LIB_FULLNAME) $(INSTALL_LIBDIR)/$(LIB_NAME)
+endif
+endif
+endif
+ifdef INSTALL_FILES
+	$(MKDIR) $(INSTALL_DATADIR)
+	$(INSTALL) $(INSTALL_FILES) $(INSTALL_DATADIR)
+endif
+fpc_sourceinstall: distclean
+	$(MKDIR) $(INSTALL_SOURCEDIR)
+	$(COPYTREE) $(BASEDIR) $(INSTALL_SOURCEDIR)
+fpc_exampleinstall: $(addsuffix _distclean,$(TARGET_EXAMPLEDIRS))
+ifdef HASEXAMPLES
+	$(MKDIR) $(INSTALL_EXAMPLEDIR)
+endif
+ifdef EXAMPLESOURCEFILES
+	$(COPY) $(EXAMPLESOURCEFILES) $(INSTALL_EXAMPLEDIR)
+endif
+ifdef TARGET_EXAMPLEDIRS
+	$(COPYTREE) $(addsuffix /*,$(TARGET_EXAMPLEDIRS)) $(INSTALL_EXAMPLEDIR)
+endif
+fpc_distinstall: install exampleinstall
+.PHONY: fpc_clean fpc_cleanall fpc_distclean
+ifdef EXEFILES
+override CLEANEXEFILES:=$(addprefix $(TARGETDIRPREFIX),$(CLEANEXEFILES))
+endif
+ifdef CLEAN_UNITS
+override CLEANPPUFILES+=$(addsuffix $(PPUEXT),$(CLEAN_UNITS))
+endif
+ifdef CLEANPPUFILES
+override CLEANPPUFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(CLEANPPUFILES))
+ifdef PPUFILES
+CLEANPPULINKFILES:=$(shell $(PPUFILES) $(CLEANPPUFILES))
+else
+CLEANPPULINKFILES:=$(wildcard $(subst $(PPUEXT),$(OEXT),$(CLEANPPUFILES)) $(addprefix $(LIBPREFIX),$(subst $(PPUEXT),$(STATICLIBEXT),$(CLEANPPUFILES))))
+endif
+override CLEANPPULINKFILES:=$(addprefix $(UNITTARGETDIRPREFIX),$(CLEANPPULINKFILES))
+endif
+fpc_clean: $(CLEANTARGET)
+ifdef CLEANEXEFILES
+	-$(DEL) $(CLEANEXEFILES)
+endif
+ifdef CLEANPPUFILES
+	-$(DEL) $(CLEANPPUFILES)
+endif
+ifneq ($(CLEANPPULINKFILES),)
+	-$(DEL) $(CLEANPPULINKFILES)
+endif
+ifdef CLEANRSTFILES
+	-$(DEL) $(addprefix $(UNITTARGETDIRPREFIX),$(CLEANRSTFILES))
+endif
+ifdef CLEAN_FILES
+	-$(DEL) $(CLEAN_FILES)
+endif
+ifdef LIB_NAME
+	-$(DEL) $(LIB_NAME) $(LIB_FULLNAME)
+endif
+	-$(DEL) $(FPCMADE) $(PPAS) link.res $(FPCEXTFILE) $(REDIRFILE)
+fpc_distclean: clean
+ifdef COMPILER_UNITTARGETDIR
+TARGETDIRCLEAN=fpc_clean
+endif
+fpc_cleanall: $(CLEANTARGET) $(TARGETDIRCLEAN)
+ifdef CLEANEXEFILES
+	-$(DEL) $(CLEANEXEFILES)
+endif
+	-$(DEL) *$(OEXT) *$(PPUEXT) *$(RSTEXT) *$(ASMEXT) *$(STATICLIBEXT) *$(SHAREDLIBEXT) *$(PPLEXT)
+	-$(DELTREE) *$(SMARTEXT)
+	-$(DEL) $(FPCMADE) $(PPAS) link.res $(FPCEXTFILE) $(REDIRFILE)
+ifdef AOUTEXT
+	-$(DEL) *$(AOUTEXT)
+endif
+.PHONY: fpc_info
+fpc_info:
+	@$(ECHO)
+	@$(ECHO)  == Package info ==
+	@$(ECHO)  Package Name..... $(PACKAGE_NAME)
+	@$(ECHO)  Package Version.. $(PACKAGE_VERSION)
+	@$(ECHO)
+	@$(ECHO)  == Configuration info ==
+	@$(ECHO)
+	@$(ECHO)  FPC.......... $(FPC)
+	@$(ECHO)  FPC Version.. $(FPC_VERSION)
+	@$(ECHO)  Source CPU... $(CPU_SOURCE)
+	@$(ECHO)  Target CPU... $(CPU_TARGET)
+	@$(ECHO)  Source OS.... $(OS_SOURCE)
+	@$(ECHO)  Target OS.... $(OS_TARGET)
+	@$(ECHO)
+	@$(ECHO)  == Directory info ==
+	@$(ECHO)
+	@$(ECHO)  Basedir......... $(BASEDIR)
+	@$(ECHO)  FPCDir.......... $(FPCDIR)
+	@$(ECHO)  UnitsDir........ $(UNITSDIR)
+	@$(ECHO)  PackagesDir..... $(PACKAGESDIR)
+	@$(ECHO)
+	@$(ECHO)  GCC library..... $(GCCLIBDIR)
+	@$(ECHO)  Other library... $(OTHERLIBDIR)
+	@$(ECHO)
+	@$(ECHO)  == Tools info ==
+	@$(ECHO)
+	@$(ECHO)  Pwd....... $(PWD)
+	@$(ECHO)  Echo...... $(ECHO)
+	@$(ECHO)  PPUMove... $(PPUMOVE)
+	@$(ECHO)  PPUFiles.. $(PPUFILES)
+	@$(ECHO)  Date...... $(DATE)
+	@$(ECHO)  Upx....... $(UPXPROG)
+	@$(ECHO)  Zip....... $(ZIPPROG)
+	@$(ECHO)
+	@$(ECHO)  == Object info ==
+	@$(ECHO)
+	@$(ECHO)  Target Loaders...... $(TARGET_LOADERS)
+	@$(ECHO)  Target Units........ $(TARGET_UNITS)
+	@$(ECHO)  Target Programs..... $(TARGET_PROGRAMS)
+	@$(ECHO)  Target Dirs......... $(TARGET_DIRS)
+	@$(ECHO)  Target Examples..... $(TARGET_EXAMPLES)
+	@$(ECHO)  Target ExampleDirs.. $(TARGET_EXAMPLEDIRS)
+	@$(ECHO)
+	@$(ECHO)  Clean Units......... $(CLEAN_UNITS)
+	@$(ECHO)  Clean Files......... $(CLEAN_FILES)
+	@$(ECHO)
+	@$(ECHO)  Install Units....... $(INSTALL_UNITS)
+	@$(ECHO)  Install Files....... $(INSTALL_FILES)
+	@$(ECHO)
+	@$(ECHO)  == Install info ==
+	@$(ECHO)
+	@$(ECHO)  DateStr.............. $(DATESTR)
+	@$(ECHO)  ZipPrefix............ $(ZIPPREFIX)
+	@$(ECHO)  ZipSuffix............ $(ZIPSUFFIX)
+	@$(ECHO)  Install FPC Package.. $(INSTALL_FPCPACKAGE)
+	@$(ECHO)
+	@$(ECHO)  Install base dir..... $(INSTALL_BASEDIR)
+	@$(ECHO)  Install binary dir... $(INSTALL_BINDIR)
+	@$(ECHO)  Install library dir.. $(INSTALL_LIBDIR)
+	@$(ECHO)  Install units dir.... $(INSTALL_UNITDIR)
+	@$(ECHO)  Install source dir... $(INSTALL_SOURCEDIR)
+	@$(ECHO)  Install doc dir...... $(INSTALL_DOCDIR)
+	@$(ECHO)  Install example dir.. $(INSTALL_EXAMPLEDIR)
+	@$(ECHO)  Install data dir..... $(INSTALL_DATADIR)
+	@$(ECHO)
+	@$(ECHO)  Dist destination dir. $(DIST_DESTDIR)
+	@$(ECHO)  Dist zip name........ $(DIST_ZIPNAME)
+	@$(ECHO)
+all: fpc_all
+debug: fpc_debug
+examples: fpc_examples
+smart: fpc_smart
+shared: fpc_shared
+install: fpc_install
+sourceinstall: fpc_sourceinstall
+exampleinstall: fpc_exampleinstall
+distinstall: fpc_distinstall
+zipinstall:
+zipsourceinstall:
+zipexampleinstall:
+zipdistinstall:
+clean: fpc_clean
+distclean: fpc_distclean
+cleanall: fpc_cleanall
+info: fpc_info
+.PHONY: all debug examples smart shared install sourceinstall exampleinstall distinstall zipinstall zipsourceinstall zipexampleinstall zipdistinstall clean distclean cleanall info
+ifneq ($(wildcard fpcmake.loc),)
+include fpcmake.loc
+endif

+ 9 - 0
demo/win32/Makefile.fpc

@@ -0,0 +1,9 @@
+#
+#   Makefile.fpc for FPC win32 demos (part of FPC demo package)
+#
+
+[target]
+programs_win32=winhello menu dlltest testdll edit
+
+[default]
+fpcdir=../..

+ 35 - 0
demo/win32/dlltest.pp

@@ -0,0 +1,35 @@
+{
+  $Id$
+  Copyright (c) 1998 by Pierre Muller
+
+  Win32 DLL usage example. It needs testdll.pp
+}
+program dlltest;
+
+procedure p1(x:pointer);
+ external 'testdll' name 'P1';
+procedure proc2(x:longint);
+ external 'testdll' name 'Proc2';
+
+var
+   s : string;external 'testdll' name 'FPC_string';
+
+begin
+  writeln('Main: Hello!');
+  p1(nil);
+  writeln('Main: ',Hinstance,' ',Hprevinst);
+  writeln('Main: testdll s string = ',s);
+  s:='Changed by program';
+  proc2(1234);
+  writeln('Main: press enter');
+  readln;
+end.
+{
+  $Log$
+  Revision 1.1  2001-05-03 21:39:34  peter
+    * moved to own module
+
+  Revision 1.2  2000/07/13 11:33:10  michael
+  + removed logs
+ 
+}

+ 470 - 0
demo/win32/edit.pp

@@ -0,0 +1,470 @@
+{
+  $Id$
+  Copyright (c) 1999 by Michael van Canneyt and Goran Andersson
+
+  Win32 editor example.
+}
+
+{ Derived from menu.pp
+
+Changes by Goeran Andersson:
+
+  2000.02.24
+    Handles WM_DrawBkgnd to reduce flicker
+    Changes to also compile in FPC mode
+
+Changes by Morten Skovrup:
+
+  2000-02-21
+    Change font
+    Modified statusbar
+
+Changes by Goeran Andersson:
+
+  2000.02.20
+    Sends focus to editor
+
+  2000.02.19
+    Client edge added to editor
+    Changes to also compile in FPC mode
+    Handles Edit modify flag
+    Undo menu item added
+    Key codes added to edit menu
+    Undo, Cut, Copy & Paste implemented
+    WM_Paint sections commented
+
+  1999.08.10
+    LoadText() added
+    NewText() added
+    File selector added
+    Asks to save file
+    Empty files works
+    EditCreate styles corrected
+}
+
+Program editdemo;
+
+{$APPTYPE GUI}
+
+Uses
+  Strings,Windows;
+
+Const
+  AppName = 'EditDemo';
+
+Type
+  TFileName = Array[0..Max_Path] Of Char;
+
+Var
+  AMessage              : Msg;
+  HWindow,HStatus,HEdit : HWnd;
+  TheFont               : HFont;
+  TheLogFont            : TLogFont;
+  TheColor              : DWORD;
+  FileName              : TFileName;
+
+{********************************************************************}
+
+Procedure SetStatusText(Num : Integer; Const Text : string);
+var
+  StatText : array[0..255] of Char;
+begin
+  if Num = 0 then
+    StatText[0] := ' '  // Add space to text in first item
+  else
+    StatText[0] := #9;  // Center the rest
+  StrPCopy(@StatText[1],Text);
+  SendMessage(HStatus,SB_SETTEXT,Num,LongInt(@StatText));
+end;
+
+{********************************************************************}
+
+Function SelectFile(Var FName:TFileName; Open:Boolean): Boolean;
+Const
+  Filter : PChar = 'Text files (*.txt)'#0'*.txt'#0+
+                   'All files (*.*)'#0'*.*'#0#0;
+  Ext    : PChar = 'txt';
+Var
+  NameRec : OpenFileName;
+Begin
+  FillChar(NameRec,SizeOf(NameRec),0);
+  FName[0] := #0;
+  With NameRec Do
+    Begin
+      LStructSize := SizeOf(NameRec);
+      HWndOwner   := HWindow;
+      LpStrFilter := Filter;
+      LpStrFile   := @FName;
+      NMaxFile    := Max_Path;
+      Flags       := OFN_Explorer Or OFN_HideReadOnly;
+      If Open Then
+        Begin
+          Flags := Flags Or OFN_FileMustExist;
+        End;
+      LpStrDefExt := Ext;
+    End;
+  If Open Then
+      SelectFile := GetOpenFileName(@NameRec)
+  Else
+      SelectFile := GetSaveFileName(@NameRec);
+End;
+
+{********************************************************************}
+
+Procedure SaveText;
+Var
+  Len   : Longint;
+  P     : PChar;
+  F     : File;
+  FName : TFileName;
+Begin
+  If SelectFile(FName,False) Then
+    Begin
+      Assign(F,@FName);
+      Rewrite(F,1);
+      Len := GetWindowTextLength(HEdit);
+      GetMem(P,Len+1);
+      P[Len] := #0;
+      If Len>0 Then
+        Begin
+          GetWindowText(HEdit,P,Len+1);
+          BlockWrite(F,P^,Len);
+        End;
+      Close(F);
+      FreeMem(P,Len+1);
+      StrCopy(FileName,FName);
+      SetStatusText(0,StrPas(FileName));
+      SetStatusText(1,'');
+      SendMessage(HEdit,EM_SetModify,0,0);
+    End;
+End;
+
+{********************************************************************}
+
+Procedure AskSave;
+Const
+  BoxType = MB_IconQuestion Or MB_YesNo;
+Begin
+  If SendMessage(HEdit,EM_GetModify,0,0)<>0 Then
+    Begin
+      If MessageBox(HWindow,'Save text?','Edited',BoxType)=IdYes Then
+        Begin
+          SaveText;
+        End;
+    End;
+End;
+
+{********************************************************************}
+
+Procedure LoadText;
+Var
+  F     : File;
+  Len   : LongInt;
+  P     : PChar;
+Begin
+  AskSave;
+  If SelectFile(FileName,True) Then
+    Begin
+      Assign(F,@FileName);
+      Reset(F,1);
+      Len := FileSize(F);
+      GetMem(P,Len+1);
+      P[Len] := #0;
+      If Len>0 Then BlockRead(F,P^,Len);
+      Close(F);
+      SetWindowText(HEdit,P);
+      SendMessage(HEdit,EM_SetModify,0,0);
+      FreeMem(P,Len+1);
+      SetStatusText(0,StrPas(FileName));
+      SetStatusText(1,'');
+    End;
+End;
+
+{********************************************************************}
+
+Procedure NewText;
+Const
+  Empty : PChar = '';
+Begin
+  AskSave;
+  FileName := 'Unsaved';
+  SetStatusText(0,StrPas(FileName));
+  SendMessage(HEdit,WM_SetText,1,LongInt(Empty));
+  SendMessage(HEdit,EM_SetModify,0,0);
+End;
+
+{********************************************************************}
+
+procedure SelectFont;
+var
+  ChooseFontRec : TChooseFont;
+begin
+  with ChooseFontRec do
+    begin
+      lStructSize    := SizeOf(ChooseFontRec);
+      hwndOwner      := HWindow;
+      hDC            := 0;
+      lpLogFont      := @TheLogFont;
+      iPointSize     := 0;
+      Flags          := CF_INITTOLOGFONTSTRUCT or CF_SCREENFONTS or CF_EFFECTS;
+      rgbColors      := TheColor;
+      lCustData      := 0;
+      lpfnHook       := nil;
+      lpTemplateName := nil;
+      hInstance      := 0;
+      lpszStyle      := nil;
+      nFontType      := 0;
+      nSizeMin       := 0;
+      nSizeMax       := 0;
+    end;
+  if ChooseFont(@ChooseFontRec) then
+    begin
+      DeleteObject(TheFont);
+      TheColor := ChooseFontRec.rgbColors;
+      TheFont  := CreateFontIndirect(@TheLogFont);
+      SendMessage(HEdit,WM_SETFONT,TheFont,1);
+    end;
+end;
+
+{********************************************************************}
+
+Function WindowProc (Window:HWnd;AMessage,WParam,LParam:Longint): Longint;
+stdcall; export;
+Var
+  R        : rect;
+  StatH    : Word;
+  NrMenu   : Longint;
+  NotiCode : LongInt;
+Begin
+  WindowProc := 0;
+  Case AMessage Of
+    wm_Close:
+      Begin
+        AskSave;
+      End;
+    wm_Destroy:
+      Begin
+        PostQuitMessage (0);
+        Exit;
+      End;
+    wm_SetFocus:
+      Begin
+        SetFocus(HEdit);
+      End;
+    WM_EraseBkgnd:
+      Begin
+        Exit(1);
+      End;
+    wm_Size:
+      Begin
+        GetClientRect(HStatus,@R);
+        StatH := R.Bottom-R.Top;
+        GetClientRect(Window,@R);
+        MoveWindow (HEdit,0,0,R.Right,R.Bottom-StatH,False);
+        MoveWindow (HStatus,0,R.Bottom-StatH,R.Right,R.Bottom,False);
+      End;
+    wm_Command:
+      Begin
+        NotiCode := HiWord(WParam);
+        Case NotiCode of
+          en_Change	: //Editor has changed
+            Begin
+              If SendMessage(HEdit,EM_GetModify,0,0)<>0 then
+                SetStatusText(1,'Modified')
+              Else
+                SetStatusText(1,'');
+            End;
+          Else
+            Begin //Menu item
+              NrMenu := LoWord(WParam);
+              Case NrMenu Of
+                101 : NewText;
+                102 : LoadText;
+                103 : SaveText;
+                104 : PostMessage(Window,WM_Close,0,0);
+                201 : SendMessage(HEdit,WM_Undo,0,0);
+                202 : SendMessage(HEdit,WM_Cut,0,0);
+                203 : SendMessage(HEdit,WM_Copy,0,0);
+                204 : SendMessage(HEdit,WM_Paste,0,0);
+                301 : SelectFont;
+                401 : MessageBox(Window,'Help','Not implemented',
+                                 MB_OK Or MB_IconInformation);
+              End;
+            End;
+        End;
+      End;
+    wm_CtlColorEdit :
+      Begin
+        SetTextColor(WParam,TheColor);
+        Exit(GetSysColorBrush(COLOR_WINDOW));
+      End;
+  End;
+  WindowProc := DefWindowProc(Window,AMessage,WParam,LParam);
+End;
+
+{********************************************************************}
+
+Function WinRegister: Boolean;
+Var
+  WindowClass : WndClass;
+Begin
+  With WindowClass Do
+    Begin
+      Style         := cs_hRedraw Or cs_vRedraw;
+      lpfnWndProc   := WndProc(@WindowProc);
+      cbClsExtra    := 0;
+      cbWndExtra    := 0;
+      hInstance     := system.MainInstance;
+      hIcon         := LoadIcon (0,idi_Application);
+      hCursor       := LoadCursor (0,idc_Arrow);
+      hbrBackground := GetStockObject(GRAY_BRUSH);
+      lpszMenuName  := Nil;
+      lpszClassName := AppName;
+    End;
+  WinRegister := RegisterClass (WindowClass)<>0;
+End;
+
+{********************************************************************}
+
+Function EditCreate(ParentWindow,Status:HWnd): HWnd;
+Const
+  CS_Start = WS_Child or WS_HScroll or WS_VScroll or ES_MultiLine or ES_Left;
+  CS_Ex    = WS_EX_ClientEdge;
+  EdiTText : PChar = '';
+Var
+  HEdit : HWND;
+  R     : TRect;
+  StatH : Word;
+Begin
+  GetClientRect(Status,@R);
+  StatH := R.Bottom-R.Top;
+  GetClientRect(ParentWindow,@R);
+  HEdit := CreateWindowEx (CS_Ex,'EDIT',EditText,CS_Start,0,0,
+                           R.Right-R.Left,R.Bottom-R.Top-StatH,ParentWindow,0,
+                           MainInstance,Nil);
+  If HEdit<>0 Then
+    Begin
+      //Set Courier new as default font
+      with TheLogFont do
+        begin
+          lfHeight         := 0;                // Default logical height of font
+          lfWidth          := 0;                // Default logical average character width
+          lfEscapement     := 0;                // angle of escapement
+          lfOrientation    := 0;                // base-line orientation angle
+          lfWeight         := FW_NORMAL;        // font weight
+          lfItalic         := 0;                // italic attribute flag
+          lfUnderline      := 0;                // underline attribute flag
+          lfStrikeOut      := 0;                // strikeout attribute flag
+          lfCharSet        := DEFAULT_CHARSET;  // character set identifier
+          lfOutPrecision   := OUT_DEFAULT_PRECIS;  // output precision
+          lfClipPrecision  := CLIP_DEFAULT_PRECIS; // clipping precision
+          lfQuality        := DEFAULT_QUALITY;     // output quality
+          lfPitchAndFamily := DEFAULT_PITCH;    // pitch and family
+          Strcopy(lfFaceName,'Courier New');    // pointer to typeface name string
+        end;
+      TheColor := GetSysColor(COLOR_WINDOWTEXT);
+      TheFont  := CreateFontIndirect(@TheLogFont);
+      SendMessage(HEdit,WM_SETFONT,TheFont,1);
+      ShowWindow(Hedit,SW_Show);
+      UpdateWindow(HEdit);
+    End;
+  EditCreate := HEdit;
+End;
+
+{********************************************************************}
+
+Function WinCreate: HWnd;
+
+Var hWindow : HWnd;
+    Menu    : hMenu;
+    SubMenu : hMenu;
+Begin
+  hWindow := CreateWindow (AppName,'EditDemo',ws_OverlappedWindow,
+                           cw_UseDefault,cw_UseDefault,cw_UseDefault,
+                           cw_UseDefault,0,0,MainInstance,Nil);
+  If hWindow<>0 Then
+    Begin
+      Menu := CreateMenu;
+      SubMenu := CreateMenu;
+      AppendMenu(Submenu,MF_STRING,101,'&New...');
+      AppendMenu(Submenu,MF_STRING,102,'&Open...');
+      AppendMenu(Submenu,MF_STRING,103,'&Save...');
+      AppendMenu(Submenu,MF_SEPARATOR,0,Nil);
+      AppendMenu(SubMenu,MF_String,104,'E&xit');
+      AppendMenu(Menu,MF_POPUP,SubMenu,'&File');
+      SubMenu := CreateMenu;
+      AppendMenu(SubMenu,MF_String,201,'&Undo'#8'Ctrl+Z');
+      AppendMenu(Submenu,MF_SEPARATOR,0,Nil);
+      AppendMenu(SubMenu,MF_String,202,'&Cut'#8'Ctrl+X');
+      AppendMenu(SubMenu,MF_String,203,'&Copy'#8'Ctrl+C');
+      AppendMenu(SubMenu,MF_STRING,204,'&Paste'#8'Ctrl+V');
+      AppendMenu(Menu,MF_POPUP,SubMenu,'&Edit');
+      SubMenu := CreateMenu;
+      AppendMenu(SubMenu,MF_String,301,'&Font...');
+      AppendMenu(Menu,MF_POPUP,SubMenu,'&Options');
+      AppendMenu(Menu,MF_STRING,401,'&Help');
+      SetMenu(hWindow,menu);
+      ShowWindow(hWindow,SW_Show);
+      UpdateWindow(hWindow);
+    End;
+  WinCreate := hWindow;
+End;
+
+{********************************************************************}
+
+Function StatusCreate (parent:hwnd): HWnd;
+var
+  AWnd   : HWnd;
+  Edges  : array[1..2] of LongInt;
+Begin
+  FileName := 'Unsaved';
+  AWnd := CreateStatusWindow(WS_CHILD or WS_VISIBLE,FileName,Parent,$7712);
+  // Create items:
+  if AWnd <> 0 then
+    begin
+      Edges[1] := 400;
+      Edges[2] := 500;
+      SendMessage(AWnd,SB_SETPARTS,2,LongInt(@Edges));
+    end;
+  StatusCreate := AWnd;
+End;
+
+{********************************************************************}
+
+Begin
+  If Not WinRegister Then
+    Begin
+      MessageBox (0,'Register failed',Nil, mb_Ok);
+    End
+  Else
+    Begin
+      hWindow := WinCreate;
+      If longint(hWindow)=0 Then
+        Begin
+          MessageBox (0,'WinCreate failed',Nil,MB_OK);
+        End
+      Else
+        Begin
+          HStatus := statuscreate(hwindow);
+          HEdit := EditCreate(HWindow,HStatus);
+          SetFocus(HEdit);
+          While GetMessage(@AMessage,0,0,0) Do
+            Begin
+              TranslateMessage(AMessage);
+              DispatchMessage(AMessage);
+            End;
+          DeleteObject(TheFont);
+          Halt(AMessage.wParam);
+        End;
+    End;
+End.
+
+{
+  $Log$
+  Revision 1.1  2001-05-03 21:39:34  peter
+    * moved to own module
+
+  Revision 1.2  2000/07/13 11:33:10  michael
+  + removed logs
+ 
+}

+ 345 - 0
demo/win32/menu.pp

@@ -0,0 +1,345 @@
+{   $Id$
+  Copyright (c) 1999 by Michael van Canneyt
+
+  Win32 menu creation example.
+}
+
+{ Changes by G”ran Andersson:                                  major
+  const FileMenus[] removed
+  const filename removed
+  type TFileName added
+  SelectFile() added                                           *
+  LoadText() added                                             *
+  SaveText():
+    SelectFile used                                            *
+    uses GetWindowTextLength & GetWindowText
+    also saves empty files
+    uses untyped file
+    FreeMem frees Len+1, not Len
+  AskSave() added                                              *
+  NewText() added                                              *
+  WindowProc():
+    WM_Close added
+    WM_Size don't assumes StatH=16
+    WM_Command 101 calls NewText
+    WM_Command 102 calls LoadText
+    WM_Command 104 issues a WM_Close instead of doing a Halt
+  WinRegister():
+    with structure used
+  EditCreate():
+    takes Status object as parameter
+    const EditText changed to empty string
+    unused variable DC removed
+    WS_HScroll & WS_VScroll added to const CS_Start
+    ES_AutoHScroll & ES_AutoVScroll removed from CS_Start
+    don't assumes StatH=16
+    AddText() commented out
+  WinCreate():
+    menu creation moved inside if structure
+    Options menu item uses the newly created SubMenu
+  main:
+    slight structure change (avoid unneccesary Exit)
+    call to StatusCreate before EditCreate
+
+2do:
+  make edit panel always active
+  add 3d inner bevel to edit panel
+  window background color : white
+  only ask to save if edited
+  cut
+  copy
+  paste
+  settings
+  help
+}
+
+Program menudemo;
+{$APPTYPE GUI}
+{$MODE DELPHI}
+
+Uses Strings,Windows;
+
+Const AppName = 'MenuDemo';
+
+Var AMessage: Msg;
+    hWindow,hStatus,Hedit: HWnd;
+    WindowClass: WndClass;
+    Menu: hMenu;
+
+Const
+  EditMenus: Array[201..203] Of pchar = ('Cut','copy','paste');
+
+Type
+  TFileName = Array[0..Max_Path] Of Char;
+
+Function SelectFile(Var FName:TFileName; Open:Boolean): Boolean;
+
+Const
+  Filter: PChar = 'Text files (*.txt)'#0'*.txt'#0'All files (*.*)'#0'*.*'#0;
+  Ext: PChar = 'txt';
+
+Var
+  NameRec: OpenFileName;
+Begin
+  FillChar(NameRec,SizeOf(NameRec),0);
+  FName[0] := #0;
+  With NameRec Do
+    Begin
+      LStructSize := SizeOf(NameRec);
+      HWndOwner := HWindow;
+      LpStrFilter := Filter;
+      LpStrFile := @FName;
+      NMaxFile := Max_Path;
+      Flags := OFN_Explorer Or OFN_HideReadOnly;
+      If Open Then
+        Begin
+          Flags := Flags Or OFN_FileMustExist;
+        End;
+      LpStrDefExt := Ext;
+    End;
+  If Open Then
+      SelectFile := GetOpenFileName(@NameRec)
+  Else
+      SelectFile := GetSaveFileName(@NameRec);
+End;
+
+Procedure SaveText;
+
+Var Len: Longint;
+    P: PChar;
+    F: File;
+    FName: TFileName;
+Begin
+  If SelectFile(FName,False) Then
+    Begin
+      Assign(F,@FName);
+      Rewrite(F,1);
+      Len := GetWindowTextLength(HEdit);
+      GetMem(P,Len+1);
+      P[Len] := #0;
+      If Len>0 Then
+        Begin
+          GetWindowText(HEdit,P,Len+1);
+          BlockWrite(F,P^,Len);
+        End;
+      Close(F);
+      FreeMem(P,Len+1);
+    End;
+End;
+
+Procedure AskSave;
+Begin
+  If MessageBox(HWindow,'Save text?','Edited',MB_IconQuestion Or MB_YesNo)=IdYes Then
+    Begin
+      SaveText;
+    End;
+End;
+
+Procedure LoadText;
+
+Var
+  FName: TFileName;
+  F: File;
+  Len: LongInt;
+  P: PChar;
+Begin
+  AskSave;
+  If SelectFile(FName,True) Then
+    Begin
+      Assign(F,@FName);
+      Reset(F,1);
+      Len := FileSize(F);
+      GetMem(P,Len+1);
+      P[Len] := #0;
+      If Len>0 Then BlockRead(F,P^,Len);
+      Close(F);
+      SetWindowText(HEdit,P);
+      FreeMem(P,Len+1);
+    End;
+End;
+
+Procedure NewText;
+
+Const
+  Empty: PChar = '';
+Begin
+  AskSave;
+  SendMessage(HEdit,WM_SetText,1,LongInt(Empty));
+End;
+
+Function WindowProc (Window:HWnd;AMessage,WParam,LParam:Longint): Longint;
+stdcall;
+export;
+
+Var ps: paintstruct;
+    r: rect;
+    StatH: Word;
+    nrmenu : longint;
+Begin
+  WindowProc := 0;
+  Case AMessage Of
+    wm_Paint:
+              Begin
+                BeginPaint(Window,@ps);
+                GetClientRect(Window,@r);
+                EndPaint(Window,ps);
+                Exit;
+              End;
+    wm_Close:
+              Begin
+                AskSave;
+              End;
+    wm_Destroy:
+                Begin
+                  PostQuitMessage (0);
+                  Exit;
+                End;
+    wm_Size:
+             Begin
+               GetClientRect(HStatus,@R);
+               StatH := R.Bottom-R.Top;
+               GetClientRect(Window,@R);
+               MoveWindow (hStatus,r.left,r.bottom-StatH,r.right,r.bottom,true);
+               MoveWindow (HEdit,0,0,r.right-r.left,r.bottom-r.top-StatH,true);
+             End;
+    wm_Command:
+                Begin
+                  NrMenu := WParam And $FFFF;
+                  Case NrMenu Of
+                    101 : NewText;
+                    102 : LoadText;
+                    103 : SaveText;
+                    104 : PostMessage(Window,WM_Close,0,0);
+                    201..203: MessageBox(Window,EditMenus[NrMenu],
+                                         'Edit operation not implemented',MB_OK Or
+                                         MB_IconInformation);
+                  End;
+                End;
+  End;
+  WindowProc := DefWindowProc(Window,AMessage,WParam,LParam);
+End;
+
+Function WinRegister: Boolean;
+Begin
+  With WindowClass Do
+    Begin
+      Style := cs_hRedraw Or cs_vRedraw;
+      lpfnWndProc := WndProc(@WindowProc);
+      cbClsExtra := 0;
+      cbWndExtra := 0;
+      hInstance := system.MainInstance;
+      hIcon := LoadIcon (0,idi_Application);
+      hCursor := LoadCursor (0,idc_Arrow);
+      hbrBackground := GetStockObject(GRAY_BRUSH);
+      lpszMenuName := 'Files';
+      lpszClassName := AppName;
+    End;
+  Result := RegisterClass (WindowClass)<>0;
+End;
+
+Function EditCreate(ParentWindow,Status:HWnd): HWnd;
+
+Const
+  CS_Start = WS_Child or WS_HScroll or WS_VScroll or ES_MultiLine or ES_Left;
+  EdiTText: PChar = '';
+
+Var
+  HEdit: HWND;
+  R: TRect;
+  StatH: Word;
+{                                             rev 1.5 : comment out
+  Procedure AddText (S:String);
+  begin
+    S:=S+#0;
+    SendMessage(HEdit,em_replacesel,0,longint(pchar(@S[1])));
+  end;
+}
+Begin
+  GetClientRect(Status,@R);
+  StatH := R.Bottom-R.Top;
+  GetClientRect(ParentWindow,@R);
+  HEdit := CreateWindow ('EDIT',EditText,CS_Start,0,0,
+                       R.Right-R.Left,R.Bottom-R.top-StatH,ParentWindow,0,
+                       System.MainInstance,Nil);
+  If HEdit<>0 Then
+    Begin
+      ShowWindow(Hedit,cmdShow);
+      UpdateWindow(HEdit);
+    End;
+  Result := HEdit;
+End;
+
+Function WinCreate: HWnd;
+
+Var hWindow: HWnd;
+    SubMenu: hMenu;
+Begin
+  hWindow := CreateWindow (AppName,'MenuDemo',ws_OverlappedWindow,
+                         cw_UseDefault,cw_UseDefault,cw_UseDefault,
+                         cw_UseDefault,0,0,system.MainInstance,Nil);
+  If hWindow<>0 Then
+    Begin
+      Menu := CreateMenu;
+      SubMenu := CreateMenu;
+      AppendMenu(Submenu,MF_STRING,101,'&New...');
+      AppendMenu(Submenu,MF_STRING,102,'&Open...');
+      AppendMenu(Submenu,MF_STRING,103,'&Save...');
+      AppendMenu(Submenu,MF_SEPARATOR,0,Nil);
+      AppendMenu(SubMenu,MF_String,104,'E&xit');
+      AppendMenu(Menu,MF_POPUP,SubMenu,'&Files');
+      SubMenu := CreateMenu;
+      AppendMenu(SubMenu,MF_String,201,'&Cut');
+      AppendMenu(SubMenu,MF_String,202,'&Copy');
+      AppendMenu(SubMenu,MF_STRING,203,'&Paste');
+      AppendMenu(Menu,MF_POPUP,SubMenu,'&Edit');
+      SubMenu := CreateMenu;
+      AppendMenu(SubMenu,MF_String,301,'&Settings');
+      AppendMenu(Menu,MF_POPUP,SubMenu,'&Options');
+      AppendMenu(Menu,MF_STRING,0,'&Help');
+      SetMenu(hWindow,menu);
+      ShowWindow(hWindow,CmdShow);
+      UpdateWindow(hWindow);
+    End;
+  Result := hWindow;
+End;
+
+Function StatusCreate (parent:hwnd): HWnd;
+Begin
+  StatusCreate := CreateStatusWindow (WS_CHILD Or WS_VISIBLE,'Ready...',parent,$7712);
+End;
+
+Begin
+  If Not WinRegister Then
+    Begin
+      MessageBox (0,'Register failed',Nil, mb_Ok);
+    End
+  Else
+    Begin
+      hWindow := WinCreate;
+      If longint(hWindow)=0 Then
+        Begin
+          MessageBox (0,'WinCreate failed',Nil,MB_OK);
+        End
+      Else
+        Begin
+          HStatus := statuscreate(hwindow);
+          HEdit := EditCreate(HWindow,HStatus);
+          While GetMessage(@AMessage,0,0,0) Do
+          Begin
+            TranslateMessage(AMessage);
+            DispatchMessage(AMessage);
+          End;
+          Halt(AMessage.wParam);
+        End;
+    End;
+End.
+
+{
+  $Log$
+  Revision 1.1  2001-05-03 21:39:34  peter
+    * moved to own module
+
+  Revision 1.2  2000/07/13 11:33:10  michael
+  + removed logs
+ 
+}

+ 71 - 0
demo/win32/testdll.pp

@@ -0,0 +1,71 @@
+{
+  $Id$
+  Copyright (c) 1998 by Pierre Muller
+
+  Win32 DLL usage example. It needs dlltest.pp
+}
+library testdll;
+
+function GetModuleFileName(hModule:longint;lpszPath:pchar;cchPath:longint):longint;
+ external 'kernel32' name 'GetModuleFileNameA';
+procedure beep(ID:longint);
+ external 'user32' name 'MessageBeep';
+
+var
+  teststr : string;
+
+procedure P1(var s:string);export;
+var
+  p:array[0..255] of char;
+begin
+  length(s);
+  getmodulefilename(Hinstance,@p,255);
+  writeln('DLL: Hello, I''m DLL ',pchar(@p));
+end;
+
+procedure P2(x:longint);export;
+begin
+  writeln('DLL: Argument X=',x);
+  writeln('DLL: New teststr="',teststr,'"');
+end;
+
+procedure P3(var t);export;
+var
+  p : pointer;
+begin
+  p:=Addr(T);
+  p:=p;
+end;
+
+procedure P4(x1:pointer);export;
+begin
+  Inc(x1);
+end;
+
+procedure NewExit;
+begin
+  beep(0);
+  writeln('DLL: Exit from testdll');
+end;
+
+exports
+ P1 index 1,
+ P2 name 'Proc2',
+ P3,
+ P4 resident,
+ teststr name 'FPC_string';
+
+begin
+  writeln('DLL: HInstance ',Hinstance,'  PrevInst ',Hprevinst,'  DLLReason ',DLLreason,'  DLLParam ',DLLparam);
+  teststr:='DLL init done';
+  exitproc:=@newExit;
+end.
+{
+  $Log$
+  Revision 1.1  2001-05-03 21:39:34  peter
+    * moved to own module
+
+  Revision 1.2  2000/07/13 11:33:10  michael
+  + removed logs
+ 
+}

+ 119 - 0
demo/win32/winhello.pp

@@ -0,0 +1,119 @@
+{
+  $Id$
+  Copyright (c) 1996 by Charlie Calvert
+  Modifications by Florian Klaempfl
+
+  Standard Windows API application written in Object Pascal.
+  No VCL code included. This is all done on the Windows API
+  level.
+}
+
+{$APPTYPE GUI}
+{$MODE DELPHI}
+program WinHello;
+
+uses
+  Strings, Windows;
+
+const
+  AppName = 'WinHello';
+
+function WindowProc(Window: HWnd; AMessage, WParam,
+                    LParam: Longint): Longint; stdcall; export;
+
+  var
+     dc : hdc;
+     ps : paintstruct;
+     r : rect;
+
+begin
+  WindowProc := 0;
+
+  case AMessage of
+    wm_paint:
+      begin
+         dc:=BeginPaint(Window,@ps);
+         GetClientRect(Window,@r);
+         DrawText(dc,'Hello world by Free Pascal',-1,@r,
+           DT_SINGLELINE or DT_CENTER or DT_VCENTER);
+         EndPaint(Window,ps);
+         Exit;
+      end;
+    wm_Destroy:
+      begin
+         PostQuitMessage(0);
+         Exit;
+      end;
+  end;
+
+  WindowProc := DefWindowProc(Window, AMessage, WParam, LParam);
+end;
+
+ { Register the Window Class }
+function WinRegister: Boolean;
+var
+  WindowClass: WndClass;
+begin
+  WindowClass.Style := cs_hRedraw or cs_vRedraw;
+  WindowClass.lpfnWndProc := WndProc(@WindowProc);
+  WindowClass.cbClsExtra := 0;
+  WindowClass.cbWndExtra := 0;
+  WindowClass.hInstance := system.MainInstance;
+  WindowClass.hIcon := LoadIcon(0, idi_Application);
+  WindowClass.hCursor := LoadCursor(0, idc_Arrow);
+  WindowClass.hbrBackground := GetStockObject(WHITE_BRUSH);
+  WindowClass.lpszMenuName := nil;
+  WindowClass.lpszClassName := AppName;
+
+  Result := RegisterClass(WindowClass) <> 0;
+end;
+
+ { Create the Window Class }
+function WinCreate: HWnd;
+var
+  hWindow: HWnd;
+begin
+  hWindow := CreateWindow(AppName, 'Hello world program',
+              ws_OverlappedWindow, cw_UseDefault, cw_UseDefault,
+              cw_UseDefault, cw_UseDefault, 0, 0, system.MainInstance, nil);
+
+  if hWindow <> 0 then begin
+    ShowWindow(hWindow, CmdShow);
+    UpdateWindow(hWindow);
+  end;
+
+  Result := hWindow;
+end;
+
+
+var
+  AMessage: Msg;
+  hWindow: HWnd;
+
+begin
+  if not WinRegister then begin
+    MessageBox(0, 'Register failed', nil, mb_Ok);
+    Exit;
+  end;
+  hWindow := WinCreate;
+  if longint(hWindow) = 0 then begin
+    MessageBox(0, 'WinCreate failed', nil, mb_Ok);
+    Exit;
+  end;
+
+  while GetMessage(@AMessage, 0, 0, 0) do begin
+    TranslateMessage(AMessage);
+    DispatchMessage(AMessage);
+  end;
+  Halt(AMessage.wParam);
+end.
+
+{
+  $Log$
+  Revision 1.1  2001-05-03 21:39:34  peter
+    * moved to own module
+
+  Revision 1.2  2000/07/13 11:33:10  michael
+  + removed logs
+ 
+}