Clear out entire repository for move of codebase from BerliOS to Gna! repository hosting.

git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@361 4a71c877-e1ca-e34f-864e-861f7616d084
No Author 2007-06-28 17:09:32 +00:00
parent 84ef68c532
commit d17e78a713
1587 changed files with 0 additions and 760728 deletions

View File

@ -1,17 +0,0 @@
Original game developed by Pumpkin Studios, and published by EIDOS Interactive.
The GPL project team, in alphabetical order :
Roman C.
Denis Dupeyron
Mike Gilmore
Marcus Hast
Adam Holland
Kevin Malec
Per I Mathisen
Dion Mendel
Kim Metcalfe
Christian Ohm
Victor Qamly
Ben Russon
Rodolphe Suescun

View File

@ -1,57 +0,0 @@
0.2.2 - 20050728
* More Compiler warning fixes.
* Fixed a few assert-related problems.
* Lots of lex/yacc related fixes.
* Fixed a crash with missing videos
* Fixed a wrong function definition / call in multiint.c.
* Fixed crash with international characters.
* Fixed memory release crash.
* Removed the last traces of stubs.c in both ivis directories (and thus fixed
building the software renderer with automake).
* Check that video mode can actually be set.
* Changed the static makefiles to build the OpenGL version by default. Use
GFX=software for the software renderer.
* It is now possible to compile the game with g++ using the -fpermissive
compiler flag.
0.2.1 - 20050716
* .net bug fixes.
* Music sample rate fix.
* New: Shuffle mode for playlists.
* Fixed tile-related crash.
* Removed useless culling code.
* Moved MatScale function into the ivis lib.
* Configure fix: OpenAL is required, not optional.
* More code cleanup.
* gcc4 fixes (thanks to Matze Braun).
* Fixed problem with power plant effect.
* Now use rand() for shuffle mode in playlist on all platforms.
* Fixed sound-related crash on exit.
* Fixed crash when saving without any available sound device.
* Fixed a division by zero.
* Made the banner ad only display on pause, since having it on all the time is
really annoying.
* --enable-debug removed from configuration options for the time being.
* Changed playlist syntax. Replaced '[track1]' and '[track2]' with less cryptic
'[game]' and '[menu]' tags.
* Removed some no-more-needed verbosity during playlist parsing.
* Reverted to wdg data file format, which re-enabled technology levels 2 and
3, plus more maps.
* More sample musics from Neos in order to demo the new shuffle mode.
* Cleaned-up (kinda...) JPEG backdrops used for backgrounds in OpenGL.
0.2 - 20050625
* Code cleanups and minor bug corrections.
* Correction of a bug that prevented network games between Windows and Linux
machines. Windows-only or Linux-only network games were unaffected.
* Music support added. See README.
* Merge of source and data tarballs.
* Video sequences removed (they can't be used anyway).
* "Thump-thump" of the oil-pumps toned down a bit.
* COPYING (oops !), README, CHANGELOG and AUTHORS added to base directory.
0.1 - Initial release
* Based on the code liberated on December 6th, 2004.
* Proprietary technologies replaced by SDL, OpenGL and OpenAL.
* Network implemented using SDL-net.
* Zoom enhancements (increased range and control using the mouse wheel).

View File

@ -1,340 +0,0 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
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. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.

View File

@ -1,8 +0,0 @@
SUBDIRS = lib src
EXTRA_DIST= \
autogen.sh \
configure.ac \
m4/ogg.m4 \
m4/sdl.m4 \
m4/sdl_net.m4 \
m4/vorbis.m4

View File

@ -1,5 +0,0 @@
SUBDIRS=lib src
all clean dep:
@for i in $(SUBDIRS); do (cd $$i; $(MAKE) -f Makefile.raw $@); done

View File

@ -1,103 +0,0 @@
Warzone 2100 ReDev
0) Welcome back !
Warzone 2100 was an innovative 3D real-time strategy game back in 1999, and most
will agree it didn't enjoy the commercial success it should have had. The game's
source code was liberated on December 6th, 2004, under a GPL license (see
COPYING in this directory for details). Soon after that, the Warzone 2100 ReDev
project was formed to take care of its future.
Our goal is to make warzone run on all possible platforms. Therefore, we
stripped the original code of all proprietary technologies and replaced them
with cross-platform and free equivalents, like OpenGL, OpenAL, etc... Right
now, Warzone 2100 works very well on Windows and GNU/Linux, and we have even
heard of it running on BSD with no particular issue.
What you get here is the early product of our collective work. We're not pros,
we just like the game, so bear with us, and feel free to join us if you think
you can do better. We can be found at :
http://www.realtimestrategies.net/forums/index.php
You'll have most chances to find us in the development section.
1) Command-line options.
Once the game is installed (see INSTALL in this directory), you can run it by
changing to its directory and typing './warzone'. Here's a few of the most
common command line options :
-fullscreen : runs in a full-screen window
-window : runs in a window
-WIDTHxHEIGHT : runs at WIDTH times HEIGHT resolution, replace WIDTH
and HEIGHT with your dimensions of choice. Beware, though,
as it needs to be a resolution supported by your X server.
Note that you do need to type the dash in front of the option, like this :
./warzone -fullscreen -1280x960
(this is my prefered mode).
The fullscreen/window modes and the resolution are stored, so they only need to
be specified once, or when you want to change them. So,
./warzone
will start in fullscreen and in 1280x960 because this is what I specified just
before (remember ?).
For more groovy command-line options, check src/clparse.c (yes, we promise we'll
document this properly some day).
2) Configuration
When you start Warzone 2100 for the first time, a '.warzone2100' directory
is created in your home directory. A certain number of files are also created in
it, the most important being the one called 'config'. In case you are upgrading
from a previous version and experience problems, try and remove this
'~/.warzone2100/config' file.
3) Music
As the original game music is part of the data that was not liberated, we are
reintroducing music, but in a different way. We use a playlist system that can
point to any ogg or mp3 file in you filesystem. This is still experimental, and
we are gradually making this more useable.
The following playlists are read, in this order, and only the first playlist
found is used :
- ~/.warzone2100/music/music.wpl
- <whereverwarzoneisinstalled>/music/music.wpl
Playlist example :
--------------------------------------------------------------------------------
[game]
path=.
shuffle=yes
neos_aurore.ogg
neos_chocolat.ogg
neos_down.ogg
neos_esperance.ogg
neos_indy.ogg
[menu]
path=.
neos_symphonie_du_vide.ogg
--------------------------------------------------------------------------------
In this example, there are 6 songs played in random order while playing a game,
and one song only when going around in the menu.
"shuffle=yes" specifies you want the songs for a given category (game or menu)
to be played in random order. If you want it for both categories, you need to
specify it in both of them.
"path" can be anything you wish. If it's ".", the path is the directory where
the playlist is found. If no path is set, all filenames must be given with
absolute path.
ogg and mp3 files are supported (provided all necessary libs are installed).
The Warzone 2100 ReDev team.

View File

@ -1,60 +0,0 @@
#!/bin/sh
# Run this to generate all the initial makefiles, etc.
# This is a kludge to make Gentoo behave and select the
# correct version of automake to use.
WANT_AUTOMAKE=1.8
export WANT_AUTOMAKE
SRCDIR=`dirname $0`
BUILDDIR=`pwd`
srcfile=src/action.c
# Chdir to the srcdir, then run auto* tools.
cd $SRCDIR
[ -f $srcfile ] || {
echo "Are you sure $SRCDIR is a valid source directory?"
exit 1
}
echo "+ creating acinclude.m4"
cat m4/*.m4 > acinclude.m4
echo "+ running aclocal ..."
aclocal $ACLOCAL_FLAGS || {
echo
echo "aclocal failed - check that all needed development files are present on system"
exit 1
}
echo "+ running autoheader ... "
autoheader || {
echo
echo "autoheader failed"
exit 1
}
echo "+ running autoconf ... "
autoconf || {
echo
echo "autoconf failed"
exit 1
}
echo "+ running automake ... "
automake -a -c --foreign || {
echo
echo "automake failed"
exit 1
}
# Chdir back to the builddir before the configure step.
cd $BUILDDIR
# now remove the cache, because it can be considered dangerous in this case
echo "+ removing config.cache ... "
rm -f config.cache
echo
echo "Now type './configure && make' to compile."
exit 0

View File

@ -1,254 +0,0 @@
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.56)
AC_INIT([warzone], [1.3], [http://developer.berlios.de/projects/warzone/])
AC_CONFIG_SRCDIR([lib/gamelib/parser.h])
AC_CONFIG_HEADER([config.h])
AC_CANONICAL_TARGET
AM_INIT_AUTOMAKE
AM_MAINTAINER_MODE
# Checks for programs.
AC_PROG_CC
AC_PROG_RANLIB
# Checks for libraries.
# Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_CHECK_HEADERS([limits.h malloc.h memory.h stddef.h stdint.h stdlib.h string.h unistd.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
AC_C_CONST
AC_C_INLINE
AC_TYPE_SIZE_T
AC_STRUCT_TM
# Checks for library functions.
AC_FUNC_CLOSEDIR_VOID
AC_FUNC_MALLOC
AC_FUNC_MEMCMP
AC_FUNC_REALLOC
AC_FUNC_STAT
AC_FUNC_VPRINTF
AC_CHECK_FUNCS([gethostname memmove memset sqrt strchr strdup strncasecmp strrchr strstr])
AC_HEADER_STDBOOL
AC_HEADER_TIME
AC_ARG_ENABLE(debug,
[ --enable-debug run in debug mode],
[ debug=$enableval ], [ debug=no ])
AC_MSG_CHECKING([debug mode])
if test "$debug" = yes; then
# -O0 turns off all optimizations; this is necessary for accurate debugging
CFLAGS="-O0 -g"
AC_DEFINE(DEBUG, 1, [Define if you want extra debugging.])
AC_MSG_RESULT([yes])
else
AC_MSG_RESULT([no])
fi
# --without-opengl will build without opengl
AC_ARG_WITH(opengl,
[ --with-opengl use OpenGL to accelerate graphics (default)],
[ opengl=$withval ], [ opengl=maybe ])
# --without-openal will build without OpenAL
# Commented out as OpenAL is not curently an option,
# but it will need to become optional someday.
#AC_ARG_WITH(openal,
#[ --with-openal use OpenAL for sound (default)],
#[ openal=$withval ], [ openal=yes ])
# --with-cda will build with audio CD support
AC_ARG_WITH(cda,
[ --with-cda built support for audio CD],
[ cda=$withval ], [ cda=no ])
# --without-ogg will build without Ogg vorbis support
AC_ARG_WITH(ogg,
[ --with-ogg built support for Ogg files (default)],
[ ogg=$withval ], [ ogg=yes ])
# --without-mp3 will build without MP3 support
AC_ARG_WITH(mp3,
[ --with-mp3 built support for Mp3 files (default)],
[ mp3=$withval ], [ mp3=yes ])
# windows conditional
case $host_os in
*mingw32* ) MINGW32=yes;;
* ) MINGW32=no;;
esac
if test x"$MINGW32" = "xyes"; then
AC_DEFINE(WIN32, 1, [Windows build])
LIBS="$LIBS -lmingw32"
fi
AM_PATH_SDL([1.1.4], [sdl_found="yes"], [sdl_found="no"])
if test "$sdl_found" = yes; then
WZ_CPPFLAGS="$CPPFLAGS $SDL_CFLAGS"
WZ_CFLAGS="$CFLAGS $SDL_CFLAGS"
WZ_LIBS="$WZ_LIBS $SDL_LIBS"
else
AC_MSG_ERROR([You need to install SDL (http://www.libsdl.org/).])
fi
AC_PATH_SDLNET([
WZ_CPPFLAGS="$WZ_CPPFLAGS $SDLNETINC" WZ_LIBS="$WZ_LIBS $SDLNETLIB"],
AC_MSG_ERROR(SDL_net is not installed))
if test "x$opengl" != xno; then
AC_CHECK_HEADER(GL/gl.h, GL_h=yes, GL_h=no)
GL_lib=yes
AC_CHECK_LIB(GL, main, GLLIB=GL,
[AC_CHECK_LIB(opengl32, main, GLLIB=opengl32, GL_lib=no)])
if test "x$GL_lib" = "xno"; then
if test "x$opengl" = xyes; then
AC_MSG_ERROR([You need to install OpenGL.])
else
opengl=no
fi
else
if test "x$GL_h" = "xno"; then
if test "x$opengl" = xyes; then
AC_MSG_ERROR([You need to install OpenGL header files (usually a -dev package).])
else
opengl=no
fi
else
opengl=yes
fi
fi
fi
AC_CHECK_LIB(jpeg, main, , [AC_MSG_ERROR([You need to install the jpeg library.])])
AC_MSG_CHECKING([OpenGL])
if test "x$opengl" = xyes; then
AC_DEFINE(WZ_OPENGL, 1, [OpenGL acceleration])
WZ_LIBS="$WZ_LIBS -l$GLLIB -ljpeg"
AC_SUBST(RENDERER, "ivis_opengl")
AC_MSG_RESULT([yes])
else
AC_SUBST(RENDERER, "ivis02")
AC_MSG_RESULT([no])
fi
if test "x$openal" != xno; then
AC_CHECK_HEADER(AL/al.h, AL_h=yes, AL_h=no)
AL_lib=yes
AC_CHECK_LIB(openal, main, ALLIB=openal,
[AC_CHECK_LIB(openal32, main, ALLIB=openal32, AL_lib=no)])
# On Windows (and perhaps some other platforms), Alut is a separate library
AC_CHECK_LIB(alut, main, ALUTLIB="-lalut", ALUTLIB="")
AC_CHECK_HEADER(AL/alut.h, ALUT_H=yes, ALUT_H=no)
if test "x$AL_lib" = "xno"; then
if test "x$openal" = xyes; then
AC_MSG_ERROR([You need to install OpenAL.])
else
openal=no
fi
else
if test "x$AL_h" = "xno"; then
if test "x$openal" = xyes; then
AC_MSG_ERROR([You need to install OpenAL header files (usually a -dev package).])
else
openal=no
fi
else
openal=yes
fi
fi
fi
AC_MSG_CHECKING([OpenAL])
if test "x$ALUT_H" = "xyes"; then
AC_DEFINE(WZ_ALUT_H, 1, [Use Alut headers])
fi
if test "x$openal" = xyes; then
WZ_LIBS="$WZ_LIBS -l$ALLIB $ALUTLIB"
AC_DEFINE(WZ_OPENAL, 1, [OpenAL support])
AC_MSG_RESULT([yes])
else
AC_MSG_RESULT([no])
AC_MSG_ERROR([OpenAL is currently mandatory])
fi
oggmusic=no
mp3music=no
if test "x$cda" = "xyes"
then
AC_DEFINE(WZ_CDA, 1, [Audio CD support])
else
if test "x$ogg" = "xyes"
then
AM_PATH_OGG(have_ogg=yes, have_ogg=no)
AM_PATH_VORBIS(have_vorbis=yes, have_vorbis=no)
if test "x$have_ogg" = "xyes"
then
if test "x$have_vorbis" = "xyes"
then
oggmusic=yes
WZ_LIBS="$WZ_LIBS -lvorbisfile -lvorbis -logg"
else
AC_DEFINE(WZ_NOOGG, 1, [Disable ogg vorbis support])
fi
else
AC_DEFINE(WZ_NOOGG, 1, [Disable ogg vorbis support])
fi
else
AC_DEFINE(WZ_NOOGG, 1, [Disable ogg vorbis support])
fi
if test "x$mp3" = "xyes"
then
AC_CHECK_LIB(mad,
mad_stream_init,
LIBS="$LIBS -lmad"; mp3music=yes,
AC_DEFINE(WZ_NOMP3, 1, [Disable mp3 support]),)
else
AC_DEFINE(WZ_NOMP3, 1, [Disable mp3 support])
fi
fi
# add some required C flags here
# -DYY_STATIC is required by flex
# -m32 forces 32-bit compile, since code is not clean enough for 64-bit yet
CFLAGS="$CFLAGS -Wall -DYY_STATIC -m32"
# only now set the LIBS/CFLAGS/CPPFLAGS lines, if set earlier it will give
# strange error messages when something is wrong
LIBS="$LIBS $WZ_LIBS"
CFLAGS="$CFLAGS $WZ_CFLAGS"
CPPFLAGS="$CPPFLAGS $WZ_CPPFLAGS"
AC_CONFIG_FILES([Makefile
lib/Makefile
lib/framework/Makefile
lib/gamelib/Makefile
lib/ivis_opengl/Makefile
lib/ivis02/Makefile
lib/ivis_common/Makefile
lib/netplay/Makefile
lib/script/Makefile
lib/sequence/Makefile
lib/sound/Makefile
lib/widget/Makefile
src/Makefile])
AC_OUTPUT
echo ""
echo "Warzone will compile with the following components:"
echo ""
echo " OpenGL acceleration: $opengl"
echo " OpenAL sound system: $openal"
echo " Audio CD support: $cda"
echo " MP3 music support: $mp3music"
echo " OGG music support: $oggmusic"
echo ""
if test "x$debug" = xyes; then
echo " *** Running in debug mode! ***"
echo ""
fi

View File

@ -1,10 +0,0 @@
SUBDIRS = framework \
script \
sequence \
ivis_common \
ivis_opengl \
ivis02 \
gamelib \
sound \
netplay \
widget

View File

@ -1,32 +0,0 @@
SUBDIRS=framework \
gamelib \
netplay \
script \
sequence \
sound \
ivis_common \
widget
ifeq ($(GFX), software)
SUBDIRS+=ivis02
else
SUBDIRS+=ivis_opengl
endif
SUBDIRS_CLEAN= framework \
gamelib \
netplay \
script \
sequence \
sound \
widget \
ivis_common \
ivis02 \
ivis_opengl
all dep:
@for i in $(SUBDIRS); do (cd $$i; $(MAKE) -f Makefile.raw $@); done
clean:
@for i in $(SUBDIRS_CLEAN); do (cd $$i; $(MAKE) -f Makefile.raw $@); done

View File

@ -1,29 +0,0 @@
noinst_LIBRARIES = libframework.a
AM_CPPFLAGS = -I../..
libframework_a_SOURCES = \
block.c \
configfile.c \
debug.c \
frame_stub.c \
frameresource.c \
heap.c \
input_stub.c \
mem.c \
multiwdg.c \
resource_l.c \
resource_y.c \
strres.c \
strres_l.c \
strres_y.c \
treap.c \
trig.c \
wdg.c \
block.h font.h heap.h memint.h resource_y.h treap.h \
cursor.h fractions.h image.h mono.h strres.h treapint.h \
dderror.h frame.h input.h multiwdg.h strresly.h trig.h \
debug.h frameint.h listmacs.h resly.h strres_y.h types.h \
dxinput.h frameresource.h mem.h resource.h surface.h w95trace.h \
wdg.h
# ugly hack to circumvent ugly hack
EXTRA_DIST= cursors.c

View File

@ -1,49 +0,0 @@
SRC_FILES= block.c \
configfile.c \
debug.c \
frame_stub.c \
frameresource.c \
heap.c \
input_stub.c \
mem.c \
mono.c \
multiwdg.c \
resource_l.c \
resource_y.c \
strres.c \
strres_l.c \
strres_y.c \
treap.c \
trig.c \
wdg.c
#GENERATED_SRC= resource_l.c \
# resource_y.c \
# resource_y.h \
# strres_l.c \
# strres_y.c \
# strres_y.h
LIB=framework
MAKERULES=../../makerules
include $(MAKERULES)/lib.mk
#resource_l.c: resource_lexer.l
# flex -l -Pres_ $(<)
# mv lex.res_.c $@
#
#resource_y.c resource_y.h: resource_parser.y
# bison -d -pres_ resource_parser.y
# mv resource_parser.tab.c resource_y.c
# mv resource_parser.tab.h resource_y.h
#
#strres_l.c: strres_lexer.l
# flex -l -Pstrres_ $(<)
# mv lex.strres_.c $@
#
#strres_y.c strres_y.h: strres_parser.y
# bison -d -pstrres_ strres_parser.y
# mv strres_parser.tab.c strres_y.c
# mv strres_parser.tab.h strres_y.h

View File

@ -1,652 +0,0 @@
/*
* Block.c
*
* Routines to allocate memory from one large block.
* Any memory allocated is only available to reallocated after
* the whole block has been reset.
*
*/
#include <string.h>
/* Allow frame header files to be singly included */
#define FRAME_LIB_INCLUDE
// memory usage printf's
#define DEBUG_GROUP0
#include "types.h"
#include "debug.h"
#include "mem.h"
#include "heap.h"
#include "treap.h"
#include "treapint.h"
#include "memint.h"
#include "listmacs.h"
#include "block.h"
/* What functions to use for the real malloc and free */
#define RMALLOC malloc
#define RFREE free
/* Whether allocated memory is initialised to a value and whether the memory
* is trashed before it is freed.
* This is done automatically by Visual C's memory routines.
*/
#define MEMORY_SET TRUE
// the filename and line number of the last call to the block functions
STRING *pCallFileName;
SDWORD callLine;
// the list of allocated blocks
static BLOCK_HEAP *psBlockList=NULL;
// initialise the block system
BOOL blkInitialise(void)
{
ASSERT((psBlockList==NULL, "blkInitialise: Blocks already initialised")); // blkShutDown() needs to be called
LIST_INIT(psBlockList);
return TRUE;
}
// shutdown the block system
void blkShutDown(void)
{
BLOCK_HEAP *psNext;
if (psBlockList)
{
DBPRINTF(("blkShutDown: blocks still allocated:\n"));
while (psBlockList)
{
psNext = psBlockList->psNext;
blkDestroy(psBlockList);
psBlockList = psNext;
}
}
}
// Note the call position for a blkAlloc or blkFree
void blkCallPos(STRING *pFileName, SDWORD line)
{
pCallFileName = pFileName;
callLine = line;
}
// Create a new block heap
BOOL blkCreate(BLOCK_HEAP **ppsHeap, SDWORD init, SDWORD ext)
{
DBPRINTF(("BLKCREATE CALLED !!!!!!!!!!!!!!!!!!!!!!\n"));
*ppsHeap = (BLOCK_HEAP*)RMALLOC(sizeof(BLOCK_HEAP));
if (!*ppsHeap)
{
DBERROR(("blkCreate: Out of memory"));
return FALSE;
}
(*ppsHeap)->psBlocks = (BLOCK_HEAP_MEM*)RMALLOC(sizeof(BLOCK_HEAP_MEM));
if (!(*ppsHeap)->psBlocks)
{
DBERROR(("blkCreate: Out of memory"));
return FALSE;
}
(*ppsHeap)->psBlocks->pMem = (UBYTE*)RMALLOC(init);
if (!(*ppsHeap)->psBlocks->pMem)
{
DBERROR(("blkCreate: Out of memory"));
return FALSE;
}
(*ppsHeap)->init = init;
(*ppsHeap)->ext = ext;
(*ppsHeap)->psBlocks->size = init;
(*ppsHeap)->psBlocks->pFree = (*ppsHeap)->psBlocks->pMem;
(*ppsHeap)->psBlocks->psNext = NULL;
#ifdef DEBUG_BLOCK
(*ppsHeap)->pFileName = pCallFileName;
(*ppsHeap)->line = callLine;
(*ppsHeap)->psMemTreap = NULL;
(*ppsHeap)->free = FALSE;
(*ppsHeap)->TotalAllocated=0;
#endif
LIST_ADD(psBlockList, *ppsHeap);
return TRUE;
}
// Release a block heap
void blkDestroy(BLOCK_HEAP *psHeap)
{
BLOCK_HEAP_MEM *psCurr, *psNext;
#ifdef DEBUG_BLOCK
if (psHeap->psMemTreap != NULL)
{
DBPRINTF(("blkDestroy: %s at %d: memory allocated :\n",
psHeap->pFileName, psHeap->line));
memRecReport(psHeap->psMemTreap);
}
#endif
LIST_REMOVE(psBlockList, psHeap, BLOCK_HEAP);
for(psCurr=psHeap->psBlocks; psCurr; psCurr=psNext)
{
RFREE(psCurr->pMem);
psNext = psCurr->psNext;
RFREE(psCurr);
}
RFREE(psHeap);
}
void memMemoryDump(MEM_NODE *Node);
void blkPrintDetails(BLOCK_HEAP *psHeap)
{
if (psHeap!=NULL)
{
#ifdef DEBUG_BLOCK
UDWORD Left=(UDWORD)((psHeap->psBlocks->pMem)+(psHeap->psBlocks->size)-(psHeap->psBlocks->pFree));
DBPRINTF(("ptr=%p init=%d ext=%d used=%d (Start=$%x Free=$%x Left=%d)\n",psHeap,psHeap->init,psHeap->ext,psHeap->TotalAllocated,psHeap->psBlocks->pMem,psHeap->psBlocks->pFree,Left));
memMemoryDump(psHeap->psMemTreap);
#else
DBPRINTF(("ptr=%p init=%d ext=%d\n",psHeap,psHeap->init,psHeap->ext));
#endif
}
else
{
DBPRINTF(("NULL POINTER IN BLOCK LIST\n"));
}
}
// report on the blocks
void blkReport(void)
{
#ifdef DEBUG
UDWORD BlockNumber=0;
BLOCK_HEAP *psCurHeap;
DBPRINTF(("\n\nBlock Report. Current Block=%x:\n",memGetBlockHeap() ));
psCurHeap=psBlockList;
while (psCurHeap)
{
DBPRINTF(("Block %d) ",BlockNumber++));
blkPrintDetails(psCurHeap);
psCurHeap = psCurHeap->psNext;
}
DBPRINTF(("\n\n"));
#endif
}
#if(0) // no longer used - uploaded in small chunks
// This is a special free that checks to see if we can free up the memory
// We can only do this if it is the last allocated memory in the block
//
// This can be used for scratch memory ... Critical on the Playstation where memory is so tight
//
// - e.g. The sound data must be stored as one 400k file. This must be loaded into scratch memory
// we clearly do not have 400k of spare memory around.
//
//
// Returns true or false
//
BOOL blkSpecialFree(BLOCK_HEAP *psHeap, void *Ptr)
{
BLOCK_HEAP_MEM *psCurr;
UDWORD RequestedFreeMem=(UDWORD)Ptr;
for(psCurr = psHeap->psBlocks; psCurr; psCurr = psCurr->psNext)
{
if ((UDWORD)psCurr->pLastAllocated == RequestedFreeMem)
{
#ifdef DEBUG_BLOCK
UDWORD BlockSize=((UDWORD)psCurr->pFree)-RequestedFreeMem;
DBPRINTF(("FREED %d block bytes\n",BlockSize)); // /// del me now !
psHeap->TotalAllocated-=BlockSize;
#endif
psCurr->pFree = psCurr->pLastAllocated;
psCurr->pLastAllocated=0; // remove pointer so that it cant be allocated again
return(TRUE); // able to return mem
}
}
return(FALSE); // unable to free mem
}
#endif
// Allocate some memory from a block heap
void *blkAlloc(BLOCK_HEAP *psHeap, SDWORD size)
{
void *pAlloc;
BLOCK_HEAP_MEM *psCurr, *psNew;
#ifdef DEBUG_BLOCK
SDWORD allocSize;
MEM_NODE *psNode;
#endif
// Round up to nearest 4 bytes ( 32 bit align ).. Neaded for Playstation.. PD.
size = (size + 3) & 0xfffffffc;
// can't allocate 0 bytes
if (size <= 0)
{
ASSERT((FALSE, "blkAlloc: cannot allocate 0 bytes"));
return NULL;
}
#ifdef DEBUG_BLOCK
// see if free has been called for this block
if (psHeap->free)
{
DBPRINTF(("Block Heap: %s at %d: Alloc after free:\n free %s at %d\n alloc %s at %d\n",
psHeap->pFileName, psHeap->line, psHeap->pFreeFile, psHeap->freeLine,
pCallFileName, callLine));
psHeap->free = FALSE;
}
// increase the size of the block to allow for the treap entry and overwrite blocks
allocSize = size;
size += sizeof(MEM_NODE) + 2 * SAFETY_ZONE_SIZE;
psHeap->TotalAllocated+=allocSize;
#endif
// find a block with a large enough segment free
pAlloc = NULL;
for(psCurr = psHeap->psBlocks; psCurr; psCurr = psCurr->psNext)
{
if (psCurr->pFree + size <= psCurr->pMem + psCurr->size)
{
pAlloc = psCurr->pFree;
psCurr->pFree += size;
break;
}
}
// if there wasn't a block try to allocate a new one
if ((psCurr == NULL) && (psHeap->ext != 0))
{
psNew = (BLOCK_HEAP_MEM*)RMALLOC(sizeof(BLOCK_HEAP_MEM));
if (!psNew)
{
ASSERT((FALSE, "blkAlloc: warning out of memory"));
// Out of memory
return NULL;
}
if (size < psHeap->ext)
{
psNew->pMem = (UBYTE*)RMALLOC(psHeap->ext);
psNew->size = psHeap->ext;
}
else
{
psNew->pMem = (UBYTE*)RMALLOC(size);
psNew->size = size;
}
if (!psNew->pMem)
{
// Out of memory
RFREE(psNew);
ASSERT((FALSE, "blkAlloc: warning out of memory"));
return NULL;
}
psNew->psNext = NULL;
psNew->pFree = psNew->pMem + size;
pAlloc = psNew->pMem;
// Add the block to the end of the list
for(psCurr=psHeap->psBlocks; psCurr->psNext != NULL; psCurr = psCurr->psNext)
;
psCurr->psNext = psNew;
}
#ifdef DEBUG_BLOCK
if (!pAlloc)
{
// failed to allocate the memory
ASSERT((FALSE, "Warning: malloc returning NULL - [%s - %d] %d bytes",pCallFileName,callLine, size));
return NULL;
}
// add the allocated memory into the treap
psNode = (MEM_NODE *)pAlloc;
psNode->pFile = pCallFileName;
psNode->line = callLine;
psNode->size = allocSize;
/* Store the new entry in the memory treap */
psNode->priority = (UDWORD)rand();
psNode->key = (UDWORD)psNode;
psNode->pObj = psNode;
psNode->psLeft = NULL;
psNode->psRight = NULL;
treapAddNode((TREAP_NODE **)&psHeap->psMemTreap, (TREAP_NODE *)psNode, memBlockCmp);
/* Now initialise the memory - try to catch unitialised variables */
memset((UBYTE *)(psNode) + sizeof(MEM_NODE),
SAFETY_ZONE_BYTE, SAFETY_ZONE_SIZE);
memset((UBYTE *)(psNode) + sizeof(MEM_NODE) + SAFETY_ZONE_SIZE + allocSize,
SAFETY_ZONE_BYTE, SAFETY_ZONE_SIZE);
#if MEMORY_SET
/* The PC initialises malloc'ed memory already, no need to do it again */
memset((UBYTE *)(psNode) + sizeof(MEM_NODE) + SAFETY_ZONE_SIZE,
INITIALISE_BYTE, allocSize);
#endif
// offset the return value by the header size
pAlloc = ((UBYTE *)(pAlloc) + sizeof(MEM_NODE) + SAFETY_ZONE_SIZE);
#endif
psCurr->pLastAllocated=(UBYTE*)pAlloc;
///* - error trapping an out-of-mem allocation !!!
//NoMemChk:
return pAlloc;
}
//*/
// return a chunk of memory to the block
// this only does anything whith DEBUG_BLOCK defined
void blkFree(BLOCK_HEAP *psHeap, void *pMemToFree)
{
#ifdef DEBUG_BLOCK
MEM_NODE sNode, *psDeleted;
SDWORD i, InvalidBottom, InvalidTop;
UBYTE *pMemBase;
#if MEMORY_SET
SDWORD Size;
#endif
// note the call to free
psHeap->free = TRUE;
psHeap->pFreeFile = pCallFileName;
psHeap->freeLine = callLine;
// Create a dummy node for the search
// This is only looked at by memBlockCmp so only need to set the object and size
sNode.pObj = ((UBYTE *)pMemToFree) - sizeof(MEM_NODE) - SAFETY_ZONE_SIZE;
sNode.size = 1;
/* Get the node for the memory block */
psDeleted = (MEM_NODE *)treapDelRec((TREAP_NODE **)&psHeap->psMemTreap,
(UDWORD)&sNode, memBlockCmp);
ASSERT((psDeleted != NULL,
"Invalid pointer passed to mem_Free by:\n"
"File: %s\nLine: %d\n\n"
"Attempt to free already freed pointer?",
pCallFileName, callLine));
if (psDeleted)
{
/* The pointer is valid, check the buffer zones */
pMemBase = (UBYTE *)(pMemToFree) - SAFETY_ZONE_SIZE;
InvalidBottom = InvalidTop = 0;
for(i=0; i<SAFETY_ZONE_SIZE; i++)
{
if (pMemBase[i] != SAFETY_ZONE_BYTE)
{
InvalidBottom++;
}
if (pMemBase[i + psDeleted->size + SAFETY_ZONE_SIZE] != SAFETY_ZONE_BYTE)
{
InvalidTop++;
}
}
ASSERT(( !InvalidBottom && !InvalidTop,
"Safety zone on memory overwritten.\n"
"%d Invalid bytes (of %d) found below memory buffer.\n"
"%d Invalid bytes (of %d) found above memory buffer.\n\n"
"Memory allocated by:\nFile: %s\nLine: %d\n"
"Memory freed by:\nFile: %s\nLine: %d\n",
InvalidBottom, SAFETY_ZONE_SIZE, InvalidTop, SAFETY_ZONE_SIZE,
psDeleted->pFile, psDeleted->line,
pCallFileName, callLine));
/* Trash the memory before it is freed */
#if MEMORY_SET
Size = psDeleted->size;
memset(pMemToFree, FREE_BYTE, Size);
#endif
}
#else
// non debug free !
// psHeap = psHeap;
// pMemToFree = pMemToFree;
#endif
{
// BOOL bRes;
#if(1)
//DBPRINTF(("UNABLE TO FREE MEMORY\n"));
#else
bRes=blkSpecialFree(psHeap, pMemToFree); // Free it up if we can ! - we can only free the last entry
#ifdef DEBUG
if (bRes==TRUE)
{
DBPRINTF(("blkFree called - memory successfully released\n"));
}
else
{
// DBPRINTF(("blkFree called - memory NOT released\n"));
}
#endif
#endif
}
}
// Reset a block heap
void blkReset(BLOCK_HEAP *psHeap)
{
BLOCK_HEAP_MEM *psCurr;
#ifdef DEBUG_GROUP0
SDWORD block=0, alloc=0;
#endif
#ifdef DEBUG_BLOCK
if (psHeap->psMemTreap != NULL)
{
DBPRINTF(("blkReset: %s at %d: memory allocated :\n",
psHeap->pFileName, psHeap->line));
memRecReport(psHeap->psMemTreap);
}
psHeap->psMemTreap = NULL;
psHeap->free = FALSE;
psHeap->TotalAllocated=0;
DBP0(("blkReset: %s at %d: memory usage:\n",
psHeap->pFileName, psHeap->line));
#else
DBP0(("blkReset: memory usage:\n"));
#endif
psCurr = psHeap->psBlocks;
while(psCurr)
{
#ifdef DEBUG_GROUP0
alloc += psCurr->pFree - psCurr->pMem;
block += psCurr->size;
#endif
#if defined(DEBUG_BLOCK) && MEMORY_SET
memset(psCurr->pMem, FREE_BYTE, psCurr->size);
#endif
psCurr->pFree = psCurr->pMem;
psCurr = psCurr->psNext;
}
DBP0((" Blocks allocated %dk, Memory allocated %dk\n",
block/1024, alloc/1024));
}
// Find which block a pointer is from if any
BLOCK_HEAP *blkFind(void *pPtr)
{
BLOCK_HEAP *psHeap;
BLOCK_HEAP_MEM *psMem;
for(psHeap=psBlockList; psHeap; psHeap=psHeap->psNext)
{
for(psMem=psHeap->psBlocks; psMem; psMem=psMem->psNext)
{
if ((UBYTE *)pPtr >= psMem->pMem &&
(UBYTE *)pPtr < psMem->pMem + psMem->size)
{
return psHeap;
}
}
}
return NULL;
}
// check if a pointer is valid in a block
BOOL blkPointerValid(BLOCK_HEAP *psHeap, void *pData, SDWORD size)
{
#ifdef DEBUG_BLOCK
MEM_NODE sNode;
void *Tmp;
ASSERT((size, "blkPointerValid: cannot check a pointer with zero size"));
if (pData == NULL)
{
return FALSE;
}
// Create a dummy node for the search
// This is only looked at by memBlockCmp so only need to set the object and size
sNode.pObj = ((UBYTE *)pData) - sizeof(MEM_NODE) - SAFETY_ZONE_SIZE;
sNode.size = size;
// See if the block is in the treap
Tmp = treapFindRec((TREAP_NODE *)psHeap->psMemTreap, (UDWORD)&sNode, memBlockCmp);
if (Tmp != NULL)
// if (treapFindRec((TREAP_NODE *)psHeap->psMemTreap, (UDWORD)&sNode, memBlockCmp))
{
return TRUE;
}
return FALSE;
#else
psHeap = psHeap;
pData = pData;
size = size;
return TRUE;
#endif
}
// check if a pointer is valid in any currently allocated block
BOOL blkPointerValidAll(void *pData, SDWORD size)
{
#ifdef DEBUG_BLOCK
BLOCK_HEAP *psCurr;
for(psCurr=psBlockList; psCurr; psCurr=psCurr->psNext)
{
if (blkPointerValid(psCurr, pData, size))
{
return TRUE;
}
}
return FALSE;
#else
pData = pData;
size = size;
return TRUE;
#endif
}
BLOCK_HEAP *psSuspendedHeap=NULL;
// suspend the current block ... all allocations pass though to system memory allocation
// if a block is already suspended then an assertion will occur.
void blockSuspendUsage(void)
{
ASSERT((psSuspendedHeap==NULL, "a memory block is already suspended"));
psSuspendedHeap = memGetBlockHeap();
memSetBlockHeap(NULL);
}
// restore the current block - if there is one
void blockUnsuspendUsage(void)
{
memSetBlockHeap(psSuspendedHeap);
psSuspendedHeap=NULL;
}
void blockCurrentBlockInfo(void)
{
#ifdef DEBUG
BLOCK_HEAP *psCurHeap;
psCurHeap=memGetBlockHeap();
if (psCurHeap==NULL)
{
DBPRINTF(("*** No current block defined\n"));
}
else
{
UDWORD Left=(UDWORD)((psCurHeap->psBlocks->pMem)+(psCurHeap->psBlocks->size)-(psCurHeap->psBlocks->pFree));
DBPRINTF(("ptr=%p init=%d ext=%d used=%d (Start=$%x Free=$%x Left=%d)\n",psCurHeap,psCurHeap->init,psCurHeap->ext,psCurHeap->TotalAllocated,psCurHeap->psBlocks->pMem,psCurHeap->psBlocks->pFree,Left));
}
#endif
}

View File

@ -1,147 +0,0 @@
/*
* Block.h
*
* Routines to allocate memory from one large block.
* Any memory allocated is only available to be reallocated after
* the whole block has been reset.
*/
#ifndef _block_h
#define _block_h
#include "mem.h"
#include "memint.h"
// control whether the debugging block malloc is used
#if DEBUG_MALLOC
#define DEBUG_BLOCK
#endif
/**********************************************************************************/
/* type definitions */
typedef struct _block_heap_mem
{
SDWORD size; // size of block
UBYTE *pFree; // pointer to the start of the free memory section
UBYTE *pMem; // pointer to the base of the memory block
UBYTE *pLastAllocated; // The start of the last allocated block (so that it can be freed by blkSpecialFree
struct _block_heap_mem *psNext;
} BLOCK_HEAP_MEM;
typedef struct _block_heap
{
SDWORD init, ext; // initial and extension block sizes
BLOCK_HEAP_MEM *psBlocks;
#ifdef DEBUG_BLOCK
STRING *pFileName;
SDWORD line;
MEM_NODE *psMemTreap; // treap of the memory blocks
BOOL free; // whether free has been called for this block
STRING *pFreeFile; // where the last free was called from
SDWORD freeLine;
UDWORD TotalAllocated; // Total amount of bytes used in the block (sum of all alloc's)
#endif
struct _block_heap *psNext;
} BLOCK_HEAP;
/**********************************************************************************/
/* function prototypes */
// initialise the block system
extern BOOL blkInitialise(void);
// shutdown the block system
extern void blkShutDown(void);
// Create a new block heap
extern BOOL blkCreate(BLOCK_HEAP **ppsHeap, SDWORD init, SDWORD ext);
// Release a block heap
extern void blkDestroy(BLOCK_HEAP *psHeap);
// Allocate some memory from a block heap
extern void *blkAlloc(BLOCK_HEAP *psHeap, SDWORD size);
// return a chunk of memory to the block
// this only does anything whith DEBUG_BLOCK defined
extern void blkFree(BLOCK_HEAP *psHeap, void *pMemToFree);
// Reset a block heap
extern void blkReset(BLOCK_HEAP *psHeap);
// Find which block a pointer is from if any
extern BLOCK_HEAP *blkFind(void *pPtr);
// check if a pointer is valid in a block
extern BOOL blkPointerValid(BLOCK_HEAP *psHeap, void *pData, SDWORD size);
// check if a pointer is valid in any currently allocated block
extern BOOL blkPointerValidAll(void *pData, SDWORD size);
// Note the call position for a blkAlloc or blkFree
extern void blkCallPos(STRING *pFileName, SDWORD line);
void blkPrintDetails(BLOCK_HEAP *psHeap);
void blkReport(void);
BOOL blkSpecialFree(BLOCK_HEAP *psHeap, void *Ptr);
void blockSuspendUsage(void);
void blockUnsuspendUsage(void);
/**********************************************************************************/
/* macro definitions */
#ifdef DEBUG_BLOCK
#define BLOCK_CREATE(ppsHeap, init, ext) \
(blkCallPos(__FILE__, __LINE__), \
blkCreate((ppsHeap), (init), (ext)))
#define BLOCK_DESTROY(psHeap) \
blkCallPos(__FILE__, __LINE__); \
blkDestroy(psHeap)
#define BLOCK_ALLOC(psHeap, size) \
(blkCallPos(__FILE__, __LINE__), \
blkAlloc(psHeap, size))
#define BLOCK_FREE(psHeap, pMemToFree) \
blkCallPos(__FILE__, __LINE__); \
blkFree(psHeap, pMemToFree)
#define BLOCK_RESET(psHeap) \
blkCallPos(__FILE__, __LINE__); \
blkReset(psHeap)
#define BLOCK_PTRVALID(psHeap, pData, size) \
blkPointerValid(psHeap, pData, size)
#else
#define BLOCK_CREATE(ppsHeap, init, ext) \
blkCreate((ppsHeap), (init), (ext))
#define BLOCK_DESTROY(psHeap) \
blkDestroy(psHeap)
#define BLOCK_ALLOC(psHeap, size) \
blkAlloc(psHeap, size)
#define BLOCK_FREE(psHeap, pMemToFree) \
blkFree(psHeap, pMemToFree)
#define BLOCK_RESET(psHeap) \
blkReset(psHeap)
#define BLOCK_PTRVALID(psHeap, pData, size) \
(TRUE)
#endif
#endif

View File

@ -1,533 +0,0 @@
// Config.c saves your favourite options to the Registry.
#include "frame.h"
#include "configfile.h"
///
//
// * Windows version
#ifdef WIN32 // registry stuff IS used but it shouldn't be, I see no need, we can use same code linux does. --Qamly
static HKEY ghWarzoneKey = NULL;
//
// =======================================================================================================================
// =======================================================================================================================
//
BOOL openWarzoneKey( void )
{
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DWORD result, ghGameDisp; // key created or opened
char keyname[256] = "SOFTWARE\\Pumpkin Studios\\Warzone2100\\";
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
result = RegCreateKeyEx
( // create/open key.
HKEY_LOCAL_MACHINE, // handle of an open key
keyname, // address of subkey name
0, // reserved
NULL, // address of class string
REG_OPTION_NON_VOLATILE, // special options flag
KEY_ALL_ACCESS, // desired security access
NULL, // address of key security structure
&ghWarzoneKey, // address of buffer for opened handle
&ghGameDisp // address of disposition value buffer
);
if ( result == ERROR_SUCCESS )
{
return TRUE;
}
return FALSE;
}
///
// =======================================================================================================================
// =======================================================================================================================
//
BOOL closeWarzoneKey( void )
{
if ( RegCloseKey(ghWarzoneKey) == ERROR_SUCCESS )
{
return TRUE;
}
return FALSE;
}
///
// =======================================================================================================================
// =======================================================================================================================
//
BOOL getWarzoneKeyNumeric( STRING *pName, DWORD *val )
{
//~~~~~~~~~~~~~~~~~~~~~~
UCHAR result[16]; // buffer
DWORD resultsize = 16; // buffersize
DWORD type; // type of reg entry.
//~~~~~~~~~~~~~~~~~~~~~~
// check guid exists
if ( RegQueryValueEx(ghWarzoneKey, pName, NULL, &type, (UCHAR *) &result, &resultsize) != ERROR_SUCCESS )
{
//
// RegCloseKey(ghWarzoneKey);
//
return FALSE;
}
if ( type == REG_DWORD )
{
memcpy( val, &result[0], sizeof(DWORD) );
return TRUE;
}
else
{
return FALSE;
}
}
///
// =======================================================================================================================
// =======================================================================================================================
//
BOOL getWarzoneKeyString( STRING *pName, STRING *pString )
{
//~~~~~~~~~~~~~~~~~~~~~~~
UCHAR result[255]; // buffer
DWORD resultsize = 255; // buffersize
DWORD type; // type of reg entry.
//~~~~~~~~~~~~~~~~~~~~~~~
// check guid exists
if ( RegQueryValueEx(ghWarzoneKey, pName, NULL, &type, (UCHAR *) &result, &resultsize) != ERROR_SUCCESS )
{
//
// RegCloseKey(ghWarzoneKey);
//
return FALSE;
}
if ( type == REG_SZ )
{
strcpy( pString, (CHAR *) result );
return TRUE;
}
else
{
return FALSE;
}
}
///
// =======================================================================================================================
// =======================================================================================================================
//
BOOL getWarzoneKeyBinary( STRING *pName, UCHAR *pData, UDWORD *pSize )
{
//~~~~~~~~~~~~~~~~~~~~~~~~
UCHAR result[2048]; // buffer
DWORD resultsize = 2048; // buffersize
DWORD type; // type of reg entry.
//~~~~~~~~~~~~~~~~~~~~~~~~
// check guid exists
if ( RegQueryValueEx(ghWarzoneKey, pName, NULL, &type, (UCHAR *) &result, &resultsize) != ERROR_SUCCESS )
{
//
// RegCloseKey(ghWarzoneKey);
//
*pSize = 0;
return FALSE;
}
if ( type == REG_BINARY )
{
memcpy( pData, &result[0], resultsize );
*pSize = resultsize;
return TRUE;
}
else
{
pSize = 0;
return FALSE;
}
}
///
// =======================================================================================================================
// =======================================================================================================================
//
BOOL setWarzoneKeyNumeric( STRING *pName, DWORD val )
{
RegSetValueEx( ghWarzoneKey, pName, 0, REG_DWORD, (UBYTE *) &val, sizeof(val) );
return TRUE;
}
///
// =======================================================================================================================
// =======================================================================================================================
//
BOOL setWarzoneKeyString( STRING *pName, STRING *pString )
{
RegSetValueEx( ghWarzoneKey, pName, 0, REG_SZ, (UBYTE *) pString, strlen(pString) );
return TRUE;
}
///
// =======================================================================================================================
// =======================================================================================================================
//
BOOL setWarzoneKeyBinary( STRING *pName, VOID *pData, UDWORD size )
{
RegSetValueEx( ghWarzoneKey, pName, 0, REG_BINARY, pData, size );
return TRUE;
}
#else // Linux version
#define REGISTRY_HASH_SIZE 32
typedef struct regkey_t
{
char *key;
char *value;
struct regkey_t *next;
} regkey_t;
regkey_t *registry[REGISTRY_HASH_SIZE] = { NULL };
char UnixRegFilePath[255];
//
// =======================================================================================================================
// =======================================================================================================================
//
void registry_clear( void )
{
//~~~~~~~~~~~~~~
unsigned int i;
//~~~~~~~~~~~~~~
for ( i = 0; i < REGISTRY_HASH_SIZE; ++i )
{
//~~~~~~~~~~~~~
regkey_t *j;
regkey_t *tmp;
//~~~~~~~~~~~~~
for ( j = registry[i]; j != NULL; j = tmp )
{
tmp = j->next;
free( j->key );
free( j->value );
free( j );
}
registry[i] = 0;
}
}
//
// =======================================================================================================================
// =======================================================================================================================
//
unsigned int registry_hash( const char *s )
{
//~~~~~~~~~~~~~~~~~~
unsigned int i;
unsigned int h = 0;
//~~~~~~~~~~~~~~~~~~
if ( s != NULL )
{
for ( i = 0; s[i] != '\0'; ++i )
{
h += s[i];
}
}
return h % REGISTRY_HASH_SIZE;
}
//
// =======================================================================================================================
// =======================================================================================================================
//
regkey_t *registry_find_key( const char *k )
{
//~~~~~~~~~~~
regkey_t *i;
//~~~~~~~~~~~
for ( i = registry[registry_hash(k)]; i != NULL; i = i->next )
{
if ( !strcmp(k, i->key) )
{
return i;
}
}
return NULL;
}
//
// =======================================================================================================================
// =======================================================================================================================
//
char *registry_get_key( const char *k )
{
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
regkey_t *key = registry_find_key( k );
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if ( key == NULL )
{
//
// printf("registry_get_key(%s) -> key not found\n", k);
//
return NULL;
}
else
{
//
// printf("registry_get_key(%s) -> %s\n", k, key->value);
//
return key->value;
}
}
//
// =======================================================================================================================
// =======================================================================================================================
//
void registry_set_key( const char *k, const char *v )
{
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
regkey_t *key = registry_find_key( k );
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// printf("registry_set_key(%s, %s)\n", k, v);
//
if ( key == NULL )
{
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
unsigned int h = registry_hash( k );
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
key = (regkey_t *) malloc( sizeof(regkey_t) );
key->key = strdup( k );
key->next = registry[h];
registry[h] = key;
}
else
{
free( key->value );
}
key->value = strdup( v );
}
//
// =======================================================================================================================
// =======================================================================================================================
//
BOOL registry_load( char *filename )
{
//~~~~~~~
FILE *f;
//~~~~~~~
f = fopen( filename, "r" );
if ( f != NULL )
{
//~~~~~~~~~~~~~~~~~~~~~~~~
unsigned int l;
char buffer[256];
char key[32];
//~~~~~~~~~~~~~~~~~~~~~~~~
//
// printf("Loading the registry from %s\n", filename);
//
while ( !feof(f) )
{
fgets( buffer, 255, f );
if ( sscanf(buffer, " %[^=] = %n", key, &l) == 1 )
{
//~~~~~~~~~~~~~~
unsigned int i;
//~~~~~~~~~~~~~~
for ( i = l;; ++i )
{
if ( buffer[i] == '\0' )
{
break;
}
else if ( buffer[i] < ' ' )
{
buffer[i] = '\0';
break;
}
}
registry_set_key( key, buffer + l );
}
}
fclose( f );
return TRUE;
}
return FALSE;
}
//
// =======================================================================================================================
// =======================================================================================================================
//
BOOL registry_save( char *filename )
{
//~~~~~~~
FILE *f;
//~~~~~~~
f = fopen( filename, "w" );
if ( f != NULL )
{
//~~~~~~~~~~~~~~
unsigned int i;
//~~~~~~~~~~~~~~
//
// printf("Saving the registry to %s\n", filename);
//
for ( i = 0; i < REGISTRY_HASH_SIZE; ++i )
{
//~~~~~~~~~~~
regkey_t *j;
//~~~~~~~~~~~
for ( j = registry[i]; j != NULL; j = j->next )
{
fprintf( f, "%s=%s\n", j->key, j->value );
}
}
fclose( f );
return TRUE;
}
return FALSE;
}
///
// =======================================================================================================================
// =======================================================================================================================
//
BOOL openWarzoneKey( void )
{
//~~~~~~~~~~~~~~~~~~~~~
static BOOL done = FALSE;
//~~~~~~~~~~~~~~~~~~~~~
if ( done == FALSE )
{
registry_load( UnixRegFilePath );
done = TRUE;
}
return TRUE;
}
///
// =======================================================================================================================
// =======================================================================================================================
//
BOOL closeWarzoneKey( void )
{
registry_save( UnixRegFilePath );
return TRUE;
}
///
// =======================================================================================================================
// =======================================================================================================================
//
BOOL getWarzoneKeyNumeric( STRING *pName, DWORD *val )
{
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
char *value = registry_get_key( pName );
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if ( value == NULL || sscanf(value, "%i", val) != 1 )
{
return FALSE;
}
else
{
return TRUE;
}
}
///
// =======================================================================================================================
// =======================================================================================================================
//
BOOL getWarzoneKeyString( STRING *pName, STRING *pString )
{
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
char *value = registry_get_key( pName );
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if ( value == NULL )
{
return FALSE;
}
else
{
strcpy( pString, value );
}
return TRUE;
}
///
// =======================================================================================================================
// =======================================================================================================================
//
BOOL getWarzoneKeyBinary( STRING *pName, UCHAR *pData, UDWORD *pSize )
{
return FALSE;
}
///
// =======================================================================================================================
// =======================================================================================================================
//
BOOL setWarzoneKeyNumeric( STRING *pName, DWORD val )
{
//~~~~~~~~~~~~
char buf[32];
//~~~~~~~~~~~~
sprintf( buf, "%i", val );
registry_set_key( pName, buf );
return TRUE;
}
///
// =======================================================================================================================
// =======================================================================================================================
//
BOOL setWarzoneKeyString( STRING *pName, STRING *pString )
{
registry_set_key( pName, pString );
return TRUE;
}
///
// =======================================================================================================================
// =======================================================================================================================
//
BOOL setWarzoneKeyBinary( STRING *pName, VOID *pData, UDWORD size )
{
return FALSE;
}
#endif // linux

View File

@ -1,12 +0,0 @@
/*
* config.h
* load and save favourites to the registry.
*/
extern BOOL getWarzoneKeyNumeric (STRING *pName,DWORD *val);
extern BOOL openWarzoneKey (VOID);
extern BOOL closeWarzoneKey (VOID);
extern BOOL setWarzoneKeyNumeric (STRING *pName,DWORD val);
extern BOOL getWarzoneKeyString(STRING *pName, STRING *pString);
extern BOOL setWarzoneKeyString(STRING *pName, STRING *pString);
extern char UnixRegFilePath[255];

File diff suppressed because it is too large Load Diff

View File

@ -1,221 +0,0 @@
/*
* Debug.c
*
* Various debugging output functions.
*
*/
#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#define WIN32_EXTRA_LEAN
#include <windows.h>
#include <stdio.h>
#endif
#include "frame.h"
#include "frameint.h"
#define MAX_FILENAME_SIZE 200
#define MAX_LEN_LOG_LINE 512
FILE *logfile = NULL;
static log_callback_fn callback;
static BOOL enabled_debug_parts[LOG_LAST];
/* This list _must_ match the enum in debug.h! */
static const char *code_part_names[] = {
"all", "sound", "video", "3d", "error", "never"
};
#ifdef _MSC_VER
#define vsnprintf _vsnprintf
#define snprintf _snprintf
#define strcasecmp stricmp
#endif
/**********************************************************************
cat_snprintf is like a combination of snprintf and strlcat;
it does snprintf to the end of an existing string.
Like mystrlcat, n is the total length available for str, including
existing contents and trailing nul. If there is no extra room
available in str, does not change the string.
Also like mystrlcat, returns the final length that str would have
had without truncation. I.e., if return is >= n, truncation occurred.
**********************************************************************/
static int cat_snprintf(char *str, size_t n, const char *format, ...)
{
size_t len;
int ret;
va_list ap;
assert(format != NULL);
assert(str != NULL);
assert(n > 0);
len = strlen(str);
assert(len < n);
va_start(ap, format);
ret = vsnprintf(str + len, n - len, format, ap);
va_end(ap);
return (int) (ret + len);
}
/**************************************************************************
Convert code_part names to enum; case insensitive; returns LOG_LAST
if can't match.
**************************************************************************/
static enum code_part code_part_from_str(const char *str)
{
enum code_part i;
for (i = 0; i < LOG_LAST; i++) {
if (strcasecmp(code_part_names[i], str) == 0) {
return i;
}
}
return LOG_LAST;
}
/**************************************************************************
Basic output callback. Just dump stuff to stderr. Add newline if none.
**************************************************************************/
static void callback_debug_stderr(const char *buf)
{
if (!strchr(buf, '\n')) {
fprintf(stderr, "%s\n", buf);
} else {
fprintf(stderr, "%s", buf);
}
}
/**************************************************************************
Call once to initialize the debug logging system.
**************************************************************************/
void debug_init(void)
{
memset(enabled_debug_parts, 0, sizeof(enabled_debug_parts));
enabled_debug_parts[LOG_ERROR] = TRUE;
callback = callback_debug_stderr;
}
/**************************************************************************
Send debug output to given file, in addition to any other places.
Only enabled output is sent to the file.
**************************************************************************/
void debug_to_file(char *file)
{
assert(strlen(file) < MAX_FILENAME_SIZE);
if (logfile) {
fclose(logfile);
}
logfile = fopen(file, "a");
if (!logfile) {
fprintf(stderr, "Could not open %s for appending!\n",
file);
} else {
fprintf(logfile, "\nStarting log\n");
}
}
/**************************************************************************
Use the given callback for outputting debug logging to screen. This
is in addition to any logging to file we do.
**************************************************************************/
void debug_use_callback(log_callback_fn use_callback)
{
callback = use_callback;
}
/**************************************************************************
Use the given callback for outputting debug logging to screen. This
is in addition to any logging to file we do.
**************************************************************************/
void debug_enable_switch(const char *str)
{
enum code_part part = code_part_from_str(str);
if (part != LOG_LAST) {
enabled_debug_parts[part] = !enabled_debug_parts[part];
}
if (part == LOG_ALL) {
memset(enabled_debug_parts, TRUE, sizeof(enabled_debug_parts));
}
}
/**************************************************************************
Output to relevant places.
**************************************************************************/
static void debug_out(const char *buf)
{
callback(buf);
if (logfile) {
if (!strchr(buf, '\n')) {
fprintf(logfile, "%s\n", buf);
} else {
fprintf(logfile, "%s", buf);
}
}
}
/**************************************************************************
Maybe output some information, depending on user settings.
**************************************************************************/
void debug(enum code_part part, const char *str, ...)
{
va_list ap;
static char bufbuf[2][MAX_LEN_LOG_LINE];
char buf[MAX_LEN_LOG_LINE];
static BOOL bufbuf1 = FALSE;
static unsigned int repeated = 0; /* times current message repeated */
static unsigned int next = 2; /* next total to print update */
static unsigned int prev = 0; /* total on last update */
/* Not enabled debugging for this part? Punt! */
if (!enabled_debug_parts[part]) {
return;
}
va_start(ap, str);
vsnprintf(bufbuf1 ? bufbuf[1] : bufbuf[0], MAX_LEN_LOG_LINE, str, ap);
if (0 == strncmp(bufbuf[0], bufbuf[1], MAX_LEN_LOG_LINE - 1)) {
repeated++;
if (repeated == next) {
snprintf(buf, sizeof(buf), "last message repeated %d times",
repeated - prev);
if (repeated > 2) {
cat_snprintf(buf, sizeof(buf), " (total %d repeats)",
repeated);
}
debug_out(buf);
prev = repeated;
next *= 2;
}
} else {
if (repeated > 0 && repeated != prev) {
if (repeated == 1) {
/* just repeat the previous message: */
debug_out(bufbuf1 ? bufbuf[0] : bufbuf[1]);
} else {
snprintf(buf, sizeof(buf),
"last message repeated %d times",
repeated - prev);
if (repeated > 2) {
cat_snprintf(buf, sizeof(buf),
" (total %d repeats)", repeated);
}
debug_out(buf);
}
}
repeated = 0;
next = 2;
prev = 0;
debug_out(bufbuf1 ? bufbuf[1] : bufbuf[0]);
}
bufbuf1 = !bufbuf1;
fflush(logfile);
va_end(ap);
}

View File

@ -1,201 +0,0 @@
#ifndef _debug_h
#define _debug_h
//#define ALWAYS_ASSERT // Define this to always process ASSERT even on release builds.
/* Check the header files have been included from frame.h if they
* are used outside of the framework library.
*/
#include <stdio.h>
#if !defined(_frame_h) && !defined(FRAME_LIB_INCLUDE)
#error Framework header files MUST be included from Frame.h ONLY.
#endif
#include <assert.h>
#include <stdarg.h>
#include "types.h"
/****************************************************************************************
*
* Basic debugging macro's
*
*/
/* DBMB used to be 'show message box' */
#ifndef _MSC_VER
#define DBMB(x) _db_debug x
#define DBPRINTF(x) _db_debug x
#define _db_debug(...) debug(LOG_NEVER, __VA_ARGS__)
#else
#define DBMB(x)
#define DBPRINTF(x)
#endif
/*
*
* ASSERT
*
* Rewritten version of assert that allows a printf format text string to be passed
* to ASSERT along with the condition.
*
* Arguments: ASSERT((condition, "Format string with variables: %d, %d", var1, var2));
*/
#ifndef _MSC_VER
#define ASSERT(x) my_assert x
#define my_assert(x, y, ...) assert(y)
#else
#define ASSERT(x)
#endif
/*
*
* DBERROR
*
* Error message macro - use this if the error should be reported even in
* production code (i.e. out of memory errors, file not found etc.)
*
* Arguments as for printf
*/
#ifndef _MSC_VER
#define DBERROR(x) _debug_error x
#define _debug_error(...) \
do { \
debug(LOG_ERROR, __VA_ARGS__); \
abort(); \
} while (FALSE);
#else
#define DBERROR(x)
#endif
/****************************************************************************************
*
* Conditional debugging macro's that can be selectively turned on or off on a file
* by file basis.
*
*/
#ifdef DEBUG_GROUP0
#define DBP0(x) DBPRINTF(x)
#define DBMB0(x) DBMB(x)
#else
#define DBP0(x)
#define DBMB0(x)
#endif
#ifdef DEBUG_GROUP1
#define DBP1(x) DBPRINTF(x)
#define DBMB1(x) DBMB(x)
#else
#define DBP1(x)
#define DBMB1(x)
#endif
#ifdef DEBUG_GROUP2
#define DBP2(x) DBPRINTF(x)
#define DBMB2(x) DBMB(x)
#else
#define DBP2(x)
#define DBMB2(x)
#endif
#ifdef DEBUG_GROUP3
#define DBP3(x) DBPRINTF(x)
#define DBMB3(x) DBMB(x)
#else
#define DBP3(x)
#define DBMB3(x)
#endif
#ifdef DEBUG_GROUP4
#define DBP4(x) DBPRINTF(x)
#define DBMB4(x) DBMB(x)
#else
#define DBP4(x)
#define DBMB4(x)
#endif
#ifdef DEBUG_GROUP5
#define DBP5(x) DBPRINTF(x)
#define DBMB5(x) DBMB(x)
#else
#define DBP5(x)
#define DBMB5(x)
#endif
#ifdef DEBUG_GROUP6
#define DBP6(x) DBPRINTF(x)
#define DBMB6(x) DBMB(x)
#else
#define DBP6(x)
#define DBMB6(x)
#endif
#ifdef DEBUG_GROUP7
#define DBP7(x) DBPRINTF(x)
#define DBMB7(x) DBMB(x)
#else
#define DBP7(x)
#define DBMB7(x)
#endif
#ifdef DEBUG_GROUP8
#define DBP8(x) DBPRINTF(x)
#define DBMB8(x) DBMB(x)
#else
#define DBP8(x)
#define DBMB8(x)
#endif
#ifdef DEBUG_GROUP9
#define DBP9(x) DBPRINTF(x)
#define DBMB9(x) DBMB(x)
#else
#define DBP9(x)
#define DBMB9(x)
#endif
/***
***
*** New debug logging output interface below. Heavily inspired
*** by similar code in Freeciv. Parts ripped directly.
***
***/
/* Want to use GCC's __attribute__ keyword to check variadic
* parameters to printf-like functions, without upsetting other
* compilers: put any required defines magic here.
* If other compilers have something equivalent, could also
* work that out here. Should this use configure stuff somehow?
* --dwp
*/
#if defined(__GNUC__)
#define wz__attribute(x) __attribute__(x)
#else
#define wz__attribute(x)
#endif
enum code_part {
LOG_ALL, /* special: sets all to on */
LOG_MAIN,
LOG_SOUND,
LOG_VIDEO,
LOG_3D,
LOG_ERROR, /* special; on by default */
LOG_NEVER, /* if too verbose for anything but dedicated debugging... */
LOG_LAST /* _must_ be last! */
};
typedef void (*log_callback_fn)(const char*);
void debug_init(void);
void debug_to_file(char *file);
void debug_use_callback(log_callback_fn use_callback);
void debug_enable_switch(const char *str);
void debug(enum code_part part, const char *str, ...)
wz__attribute((format (printf, 2, 3)));
#endif

View File

@ -1,113 +0,0 @@
/*
* Font.h
*
* Definitions for the font system.
*/
#ifndef _font_h
#define _font_h
/* Check the header files have been included from frame.h if they
* are used outside of the framework library.
*/
#if !defined(_frame_h) && !defined(FRAME_LIB_INCLUDE)
#error Framework header files MUST be included from Frame.h ONLY.
#endif
/*************************************************************************************
*
* Definitions for the fixed size font
*
*/
#define PRINTABLE_START 32
#define PRINTABLE_CHARS 97
#define FONT_WIDTH 8
#define FONT_HEIGHT 14
extern UBYTE aFontData[PRINTABLE_CHARS][FONT_HEIGHT];
/*************************************************************************************
*
* Definitions for proportional fonts.
*
*/
// these are file formats ... and hence can not be altered !!!!!
/* The data for a single proportional font character */
typedef struct _prop_char
{
/* The number of pixels across the character */
UWORD width;
/* The number of bytes used to store one horizontal line of the character */
UWORD pitch;
/* The pixel data
* This is a square array of bytes wide enough to store width bits
* and the same height as the font.
*/
UBYTE *pData;
} PROP_CHAR;
/* Store ranges of character codes that are printable */
typedef struct _prop_printable
{
UWORD end; // End of the character code range covered by this struct
UWORD offset; // Amount to subtract from char code if this range
// is printable
BOOL printable; // Whether the range is printable
} PROP_PRINTABLE;
/* The proportional font data */
typedef struct _prop_font
{
UWORD height; // Number of pixels high
UWORD spaceWidth; // Number of pixels gap to leave for a space
UWORD baseLine; // Position of bottom of letters with no tail
// i.e. where the line on lined paper would be
// This is relative to the absolute bottom of all characters.
UWORD numOffset; // Number of PROP_OFFSET stored
UWORD numChars; // Number of PROP_CHARS stored
PROP_PRINTABLE *psOffset;
PROP_CHAR *psChars;
} PROP_FONT;
/* Set the current font */
extern void fontSet(PROP_FONT *psFont);
/* Get the current font */
extern PROP_FONT *fontGet(void);
/* Set the current font colour */
extern void fontSetColour(UBYTE red, UBYTE green, UBYTE blue);
/* Set the value to be poked into screen memory for font drawing.
* The colour value used should be one returned by screenGetCacheColour.
*/
extern void fontSetCacheColour(UDWORD colour);
/* Print text in the current font at location x,y */
extern void fontPrint(SDWORD x, SDWORD y, STRING *pFormat, ...);
/* Directly print a single font character from the PROP_CHAR struct */
extern void fontPrintChar(SDWORD x,SDWORD y, PROP_CHAR *psChar, UDWORD height);
/* Return the pixel width of a string */
extern UDWORD fontPixelWidth(STRING *pString);
/* Return the index into the PROP_CHAR array for a character code.
* If the code isn't printable, return 0 (space).
*/
extern UWORD fontGetCharIndex(UWORD code);
/* Save font information into a file buffer */
extern BOOL fontSave(PROP_FONT *psFont, UBYTE **ppFileData, UDWORD *pFileSize);
/* Load in a font file */
extern BOOL fontLoad(UBYTE *pFileData, UDWORD fileSize, PROP_FONT **ppsFont);
/* Release all the memory used by a font */
extern void fontFree(PROP_FONT *psFont);
#endif

View File

@ -1,160 +0,0 @@
// Routines to provide simple maths functions that work on both PSX & PC
// Use the type "FRACT" instead of FLOAT
// - This is defined as a float on PC and a 20.12 fixed point number on PSX
//
// Use:-
// MAKEFRACT(int); to convert from a SDWORD to a FRACT
// MAKEINT(fract); to convert the other way
// FRACTmul(fract,fract); to multiply two fract numbers
// FRACTdiv(fract,fract); to divide two numbers
// SQRT(fract); to get square root of a fract (returns a fract)
// iSQRT(int); to get a square root of an integer (returns an UDWORD)
// FRACTCONST(constA,constB); ; Generates a constant of (constA/constB)
// e.g. to define 0.5 use FRACTCONST(1,2)
// to define 0.114 use FRACTCONT(114,1000)
//
// Also PERCENT(int,int); // returns a int value 0->100 of the percentage of the first param over the second
//
// This file used to be in the deliverance src directory. But Jeremy quite correctly
// pointed out to me that it should be library based not deliverance based, and hence
// has now been moved to the lib\framework directory
//
// If you are reading this file from the deliverance source directory, please delete it now
// To multiply a FRACT by a integer just use the normal operator
// e.g. FractValue2=FractValue*Interger;
//
// save is true of divide
#ifndef _FRACTIONS_
#define _FRACTIONS_
/* Check the header files have been included from frame.h if they
* are used outside of the framework library.
*/
#if !defined(_frame_h) && !defined(FRAME_LIB_INCLUDE)
#error Framework header files MUST be included from Frame.h ONLY.
#endif
#include "types.h"
#ifdef DEBUG
SDWORD PercentFunc(char *File,UDWORD Line,SDWORD a,SDWORD b);
SDWORD PerNumFunc(char *File,UDWORD Line,SDWORD range,SDWORD a,SDWORD b);
#define PERCENT(a,b) PercentFunc(__FILE__,__LINE__,a,b)
#define PERNUM(range,a,b) PerNumFunc(__FILE__,__LINE__,range,a,b)
#else
#define PERCENT(a,b) (((a)*100)/(b))
#define PERNUM(range,a,b) (((a)*range)/(b))
#endif
#include <math.h>
typedef float FRACT;
typedef float FRACT_D;
#define ROUND(x) ((x)>=0 ? (SDWORD)((x) + 0.5) : (SDWORD)((x) - 0.5))
#define FAST_FRACTS
#ifdef FAST_FRACTS
#define MAKEFRACT(x) ((FRACT)(x))
#define FRACTmul(x,y) ((x)*(y))
#define FRACTdiv(x,y) ((x)/(y))
#define FRACTmul_1(x,y) ((x)*(y))
#define FRACTdiv_1(x,y) ((x)/(y))
#define fSQRT(x) ((FRACT)sqrt(x))
// Jeremy ... the usual leg breaking rule aplies if you remove this again
#define iSQRT(x) ((FRACT)sqrt(x))
#define FRACTCONST(a,b) (((float)(a)) / ((float)(b)))
#define FRACTabs(a) ((float)fabs(a))
#define MAKEFRACT_D(x) ((FRACT_D)(x))
#define FRACTmul_D(x,y) ((x)*(y))
#define FRACTdiv_D(x,y) ((x)/(y))
#define fSQRT_D(x) ((FRACT)sqrt(x))
//#ifdef _MSC_VER //Using 'normal' version --Qamly
//__inline SDWORD MAKEINT_D (float f)
//{
// SDWORD i;
// __asm fld f;
// __asm fistp i;
// return i;
//}
//#else
#define MAKEINT_D(x) ((SDWORD)(x))
//#endif
//#ifdef _MSC_VER //Using 'normal version' --Qamly
//__inline SDWORD MAKEINT (float f)
//{
// SDWORD i;
// __asm fld f;
// __asm fistp i;
// return i;
//}
//#else
//changed definitions
#define MAKEINT(x) ((SDWORD)(x))
//#define MAKEINT(x) (ftol(x))
//#endif
//#define fastRoot(x,y) (sqrt(x * x + y * y))
#define fastRoot(x,y) ((abs(x) > abs(y)) ? (abs(x) + abs(y)/2) : (abs(y) + abs(x)/2))
//unused definitions
//#define iSQRT_D(x) ((UDWORD)sqrt((double)x))
//#define iSQRT(x) ((UDWORD)sqrt((double)x))
#else
#define MAKEFRACT(x) ((FRACT)(x))
#define FRACTmul(x,y) ((x)*(y))
#define FRACTdiv(x,y) ((x)/(y))
#define FRACTmul_1(x,y) ((x)*(y))
#define FRACTdiv_1(x,y) ((x)/(y))
#define fSQRT(x) ((FRACT)sqrt(x))
#define FRACTCONST(a,b) (((float)(a)) / ((float)(b)))
#define FRACTabs(a) ((float)fabs(a))
#define MAKEFRACT_D(x) ((FRACT_D)(x))
#define FRACTmul_D(x,y) ((x)*(y))
#define FRACTdiv_D(x,y) ((x)/(y))
#define fSQRT_D(x) ((FRACT)sqrt(x))
// Jeremy ... the usual leg breaking rule aplies if you remove this again
#define iSQRT(x) ((FRACT)sqrt(x))
#define MAKEINT(x) ((SDWORD)(x))
#define MAKEINT_D(x) ((SDWORD)(x))
#define fastRoot(x,y) (sqrt(x * x + y * y))
//#define iSQRT_D(x) ((UDWORD)sqrt((double)x))
//#define iSQRT(x) ((UDWORD)sqrt((double)x))
#endif
#endif

View File

@ -1,171 +0,0 @@
/*
* Frame.h
*
* The framework library initialisation and shutdown routines.
*
*/
#ifndef _frame_h
#define _frame_h
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef WIN32
#include <windows.h>
#endif
/* Linux specific stuff */
#ifndef WIN32
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
char* unix_path(char* path);
FILE* unix_fopen(char* filename, char* mode);
#define fopen unix_fopen
#endif
#define InitializeCriticalSection(x)
#define DeleteCriticalSection(x)
#define EnterCriticalSection(x)
#define LeaveCriticalSection(x)
#include "types.h"
#include "debug.h"
#include "mem.h"
#include "input.h"
#include "font.h"
#include "heap.h"
#include "treap.h"
//#ifdef WIN32 //bah, not needed. --Qamly
//#include "w95trace.h"
//#endif
#include "fractions.h"
#include "trig.h"
#include "frameresource.h"
#include "strres.h"
#include "block.h"
#include "listmacs.h"
#ifndef WIN32
DWORD GetTickCount();
#endif
/* Initialise the frame work library */
extern BOOL frameInitialise(HANDLE hInstance, // The windows application instance
STRING *pWindowName, // The text to appear in the window title bar
UDWORD width, // The display width
UDWORD height, // The display height
UDWORD bitDepth, // The display bit depth
BOOL fullScreen, // Whether to start full screen or windowed
BOOL bVidMem, // Whether to put surfaces in video memory
BOOL bGlide ); // Whether to create surfaces
/* Shut down the framework library.
* This clears up all the Direct Draw stuff and ensures
* that Windows gets restored properly after Full screen mode.
*/
extern void frameShutDown(void);
/* The current status of the framework */
typedef enum _frame_status
{
FRAME_OK, // Everything normal
FRAME_KILLFOCUS, // The main app window has lost focus (might well want to pause)
FRAME_SETFOCUS, // The main app window has focus back
FRAME_QUIT, // The main app window has been told to quit
} FRAME_STATUS;
/* Call this each cycle to allow the framework to deal with
* windows messages, and do general house keeping.
*
* Returns FRAME_STATUS.
*/
extern FRAME_STATUS frameUpdate(void);
/* If cursor on is TRUE the windows cursor will be displayed over the game window
* (and in full screen mode). If it is FALSE the cursor will not be displayed.
*/
extern void frameShowCursor(BOOL cursorOn);
/* Set the current cursor from a cursor handle */
extern void frameSetCursor(HCURSOR hNewCursor);
/* Set the current cursor from a Resource ID
* This is the same as calling:
* frameSetCursor(LoadCursor(MAKEINTRESOURCE(resID)));
* but with a bit of extra error checking.
*/
extern void frameSetCursorFromRes(WORD resID);
/* Returns the current frame we're on - used to establish whats on screen */
extern UDWORD frameGetFrameNumber(void);
/* Return the current frame rate */
extern UDWORD frameGetFrameRate(void);
/* Return the overall frame rate */
extern UDWORD frameGetOverallRate(void);
/* Return the frame rate for the last second */
extern UDWORD frameGetRecentRate(void);
/* The handle for the application window */
extern HANDLE frameGetWinHandle(void);
//enumerate all available direct draw devices
extern BOOL frameDDEnumerate(void);
extern SDWORD frameGetNumDDDevices(void);
extern char* frameGetDDDeviceName(SDWORD);
// Return a string for a windows error code
extern STRING *winErrorToString(SDWORD error);
/* The default window procedure for the library.
* This is initially set to the standard DefWindowProc, but can be changed
* by this function.
* Call this function with NULL to reset to DefWindowProc.
*/
typedef LRESULT (* DEFWINPROCTYPE)(HWND hWnd, UINT Msg,
WPARAM wParam, LPARAM lParam);
extern void frameSetWindowProc(DEFWINPROCTYPE winProc);
/* Load the file with name pointed to by pFileName into a memory buffer. */
extern BOOL loadFile(STRING *pFileName, // The filename
STRING **ppFileData, // A buffer containing the file contents
UDWORD *pFileSize); // The size of this buffer
/* Load the file with name pointed to by pFileName into a memory buffer. */
// if allocate mem is true then the memory is allocated ... else it is already in ppFileData, and the max size is in pFileSize ... this is adjusted to the actual loaded file size
//
BOOL loadFile2(STRING *pFileName, UBYTE **ppFileData, UDWORD *pFileSize, BOOL AllocateMem );
/* Save the data in the buffer into the given file */
extern BOOL saveFile(STRING *pFileName, UBYTE *pFileData, UDWORD fileSize);
// load a file from disk into a fixed memory buffer
extern BOOL loadFileToBuffer(STRING *pFileName, UBYTE *pFileBuffer, UDWORD bufferSize, UDWORD *pSize);
// as above but returns quietly if no file found
extern BOOL loadFileToBufferNoError(STRING *pFileName, UBYTE *pFileBuffer, UDWORD bufferSize, UDWORD *pSize);
extern SDWORD ftol(float f);
extern BOOL bRunningUnderGlide;
UINT HashString( char *String );
UINT HashStringIgnoreCase( char *String );
#endif

View File

@ -1,885 +0,0 @@
/*
* Frame.c
*
* Initialisation and shutdown for the framework library.
*
* Includes a basic windows message loop.
*
*/
// defines the inline functions in this module
#define DEFINE_INLINE
#include <stdio.h>
#include <time.h>
#include <SDL/SDL.h>
// window focus messages
//#define DEBUG_GROUP1
#include "frame.h"
#include "frameint.h"
#include "wdg.h"
#include "fractions.h"
#include <assert.h>
#include "cursors.c"
#define IGNORE_FOCUS
/* Linux specific stuff */
#ifndef WIN32
#undef fopen
char* unix_path(char* path) {
static char returnval[512];
unsigned int i;
for (i = 0; path[i] != '\0'; ++i) {
if (path[i] >= 'A' && path[i] <= 'Z') {
returnval[i] = path[i]-'A'+'a';
} else if (path[i] == '\\') {
returnval[i] = '/';
} else {
returnval[i] = path[i];
}
}
for(;returnval[i-1] == '/'; --i);
returnval[i] = '\0';
return returnval;
}
FILE* unix_fopen(char* filename, char* mode) {
return fopen(unix_path(filename), mode);
}
#define fopen unix_fopen
#endif
/* Handle for the main window */
HANDLE hWndMain;
/* Program hInstance */
HINSTANCE hInstance;
/* Are we running under glide? */
BOOL bRunningUnderGlide = FALSE;
/* Flag if directdraw is active*/
static BOOL bActiveDDraw;
static WORD currentCursorResID = UWORD_MAX;
SDL_Cursor *aCursors[MAX_CURSORS];
/* Stores whether a windows quit message has been received */
static BOOL winQuit=FALSE;
typedef enum _focus_state
{
FOCUS_OUT, // Window does not have the focus
FOCUS_SET, // Just received WM_SETFOCUS
FOCUS_IN, // Window has got the focus
FOCUS_KILL, // Just received WM_KILLFOCUS
} FOCUS_STATE;
FOCUS_STATE focusState, focusLast;
/* Whether the mouse is currently being displayed or not */
static BOOL mouseOn=TRUE;
/* Whether the mouse should be displayed in the app workspace */
static BOOL displayMouse=TRUE;
/************************************************************************************
*
* Alex's frame rate stuff
*/
/* Over how many seconds is the average required? */
#define TIMESPAN 5
/* Initial filler value for the averages - arbitrary */
#define IN_A_FRAME 70
/* Global variables for the frame rate stuff */
static SDWORD FrameCounts[TIMESPAN];
static SDWORD Frames; // Number of frames elapsed since start
static SDWORD LastFrames;
static SDWORD RecentFrames; // Number of frames in last second
static SDWORD PresSeconds; // Number of seconds since execution started
static SDWORD LastSeconds;
static SDWORD FrameRate; // Average frame rate since start
static SDWORD FrameIndex;
static SDWORD Total;
static SDWORD RecentAverage; // Average frame rate over last TIMSPAN seconds
/* InitFrameStuff - needs to be called once before frame loop commences */
static void InitFrameStuff( void )
{
SDWORD i;
for (i=0; i<TIMESPAN; i++)
{
FrameCounts[i] = IN_A_FRAME;
}
Frames = 0;
LastFrames = 0;
RecentFrames = 0;
RecentAverage = 0;
PresSeconds = 0;
LastSeconds = 0;
LastSeconds = PresSeconds;
FrameIndex = 0;
}
/* MaintainFrameStuff - call this during completion of each frame loop */
static void MaintainFrameStuff( void )
{
SDWORD i;
PresSeconds = clock()/CLOCKS_PER_SEC;
if (PresSeconds!=LastSeconds)
{
LastSeconds = PresSeconds;
RecentFrames = Frames-LastFrames;
LastFrames = Frames;
FrameCounts[FrameIndex++] = RecentFrames;
if (FrameIndex>=TIMESPAN)
{
FrameIndex = 0;
}
Total = 0;
for (i=0; i<TIMESPAN; i++)
{
Total+=FrameCounts[i];
}
RecentAverage = Total/TIMESPAN;
if (PresSeconds > 0)
FrameRate = Frames / PresSeconds;
}
Frames++;
}
/* replacement for win32 function */ //Check this. [test] --Qamly
#ifndef _MSC_VER //was WIN32, but gcc is OK with this? //Note, I vote for name change, since we are using SDL now right? --Qamly
DWORD GetTickCount()
{
return (DWORD) SDL_GetTicks();
}
#endif
/* Return the current frame rate */
UDWORD frameGetFrameRate(void)
{
return RecentAverage;
}
/* Return the overall frame rate */
UDWORD frameGetOverallRate(void)
{
return FrameRate;
}
/* Return the frame rate for the last second */
UDWORD frameGetRecentRate(void)
{
return RecentFrames;
}
UDWORD frameGetFrameNumber(void)
{
return Frames;
}
/* Return the handle for the application window */
HANDLE frameGetWinHandle(void)
{
return hWndMain;
}
/* If cursor on is TRUE the windows cursor will be displayed over the game window
* (and in full screen mode). If it is FALSE the cursor will not be displayed.
*/
void frameShowCursor(BOOL cursorOn)
{
displayMouse = cursorOn;
}
/* Set the current cursor from a cursor handle */
void frameSetCursor(HCURSOR hNewCursor)
{
}
/* Set the current cursor from a Resource ID */
void frameSetCursorFromRes(WORD resID)
{
ASSERT((resID >= CURSOR_OFFSET, "frameSetCursorFromRes: bad resource ID"));
ASSERT((resID < CURSOR_OFFSET + MAX_CURSORS, "frameSetCursorFromRes: bad resource ID"));
//If we are already using this cursor then return
if (resID != currentCursorResID)
{
SDL_SetCursor(aCursors[resID - CURSOR_OFFSET]);
currentCursorResID = resID;
}
}
/*
* Wndproc
*
* The windows message processing function.
*/
static void processEvent(SDL_Event *event)
{
switch(event->type)
{
#ifndef IGNORE_FOCUS
case SDL_ACTIVEEVENT:
if (event->active.state == SDL_APPINPUTFOCUS || event->active.state == SDL_APPACTIVE)
{
if (event->active.gain == 1)
{
DBP1(("WM_SETFOCUS\n"));
if (focusState != FOCUS_IN)
{
DBP1(("FOCUS_SET\n"));
focusState = FOCUS_SET;
}
}
else
{
DBP1(("WM_KILLFOCUS\n"));
if (focusState != FOCUS_OUT)
{
DBP1(("FOCUS_KILL\n"));
focusState = FOCUS_KILL;
}
/* Have to tell the input system that we've lost focus */
inputProcessEvent(event);
}
}
break;
#endif
case SDL_KEYUP:
case SDL_KEYDOWN:
case SDL_MOUSEBUTTONUP:
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEMOTION:
inputProcessEvent(event);
break;
}
}
static void initCursors()
{
aCursors[CURSOR_ARROW - CURSOR_OFFSET] = init_system_cursor(cursor_arrow);
aCursors[CURSOR_DEST - CURSOR_OFFSET] = init_system_cursor(cursor_dest);
aCursors[CURSOR_SIGHT - CURSOR_OFFSET] = init_system_cursor(cursor_sight);
aCursors[CURSOR_TARGET - CURSOR_OFFSET] = init_system_cursor(cursor_target);
aCursors[CURSOR_LARROW - CURSOR_OFFSET] = init_system_cursor(cursor_larrow);
aCursors[CURSOR_RARROW - CURSOR_OFFSET] = init_system_cursor(cursor_rarrow);
aCursors[CURSOR_DARROW - CURSOR_OFFSET] = init_system_cursor(cursor_darrow);
aCursors[CURSOR_UARROW - CURSOR_OFFSET] = init_system_cursor(cursor_uarrow);
aCursors[CURSOR_DEFAULT - CURSOR_OFFSET] = init_system_cursor(cursor_default);
aCursors[CURSOR_EDGEOFMAP - CURSOR_OFFSET] = init_system_cursor(cursor_default);
aCursors[CURSOR_ATTACH - CURSOR_OFFSET] = init_system_cursor(cursor_attach);
aCursors[CURSOR_ATTACK - CURSOR_OFFSET] = init_system_cursor(cursor_attack);
aCursors[CURSOR_BOMB - CURSOR_OFFSET] = init_system_cursor(cursor_bomb);
aCursors[CURSOR_BRIDGE - CURSOR_OFFSET] = init_system_cursor(cursor_bridge);
aCursors[CURSOR_BUILD - CURSOR_OFFSET] = init_system_cursor(cursor_build);
aCursors[CURSOR_EMBARK - CURSOR_OFFSET] = init_system_cursor(cursor_embark);
aCursors[CURSOR_FIX - CURSOR_OFFSET] = init_system_cursor(cursor_fix);
aCursors[CURSOR_GUARD - CURSOR_OFFSET] = init_system_cursor(cursor_guard);
aCursors[CURSOR_JAM - CURSOR_OFFSET] = init_system_cursor(cursor_jam);
aCursors[CURSOR_LOCKON - CURSOR_OFFSET] = init_system_cursor(cursor_lockon);
aCursors[CURSOR_MENU - CURSOR_OFFSET] = init_system_cursor(cursor_menu);
aCursors[CURSOR_MOVE - CURSOR_OFFSET] = init_system_cursor(cursor_move);
aCursors[CURSOR_NOTPOSSIBLE - CURSOR_OFFSET] = init_system_cursor(cursor_notpossible);
aCursors[CURSOR_PICKUP - CURSOR_OFFSET] = init_system_cursor(cursor_pickup);
aCursors[CURSOR_SEEKREPAIR - CURSOR_OFFSET] = init_system_cursor(cursor_seekrepair);
aCursors[CURSOR_SELECT - CURSOR_OFFSET] = init_system_cursor(cursor_select);
}
/*
* frameInitialise
*
* Initialise the framework library. - PC version
*/
BOOL frameInitialise(HANDLE hInst, // The windows application instance
STRING *pWindowName, // The text to appear in the window title bar
UDWORD width, // The display width
UDWORD height, // The display height
UDWORD bitDepth, // The display bit depth
BOOL fullScreen, // Whether to start full screen or windowed
BOOL bVidMem, // Whether to put surfaces in video memory
BOOL bGlide ) // Whether to create surfaces
{
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_CDROM) != 0)
{
printf("Error: Could not initialise SDL (%s).\n", SDL_GetError());
return FALSE;
}
SDL_WM_SetCaption(pWindowName, NULL);
winQuit = FALSE;
focusState = FOCUS_IN;
focusLast = FOCUS_IN;
if(!bGlide)
{
mouseOn = TRUE;
displayMouse = TRUE;
}
else //Below is glide stuff.. never used right? --Qamly
{
mouseOn = FALSE;
displayMouse = FALSE;
}
// hInstance = hInst;
bActiveDDraw = !bGlide;
// /* Initialise the memory system */
// if (!memInitialise())
// {
// return FALSE;
// }
// if (!blkInitialise())
// {
// return FALSE;
// }
/* Initialise the trig stuff */
if (!trigInitialise())
{
return FALSE;
}
/* initialise all cursors */
initCursors();
/* Initialise the Direct Draw Buffers */
if (!screenInitialise(width, height, bitDepth, fullScreen, bVidMem, bActiveDDraw, hWndMain))
{
return FALSE;
}
/* Initialise the input system */
inputInitialise();
/* Initialise the frame rate stuff */
InitFrameStuff();
// Initialise the resource stuff
if (!resInitialise())
{
return FALSE;
}
return TRUE;
}
/*
* frameUpdate
*
* Call this each cycle to allow the framework to deal with
* windows messages, and do general house keeping.
*
* Returns FRAME_STATUS.
*/
FRAME_STATUS frameUpdate(void)
{
SDL_Event event;
FRAME_STATUS retVal;
/* Tell the input system about the start of another frame */
inputNewFrame();
/* Deal with any windows messages */
while ( SDL_PollEvent( &event ) != 0)
{
if (event.type == SDL_QUIT)
{
break;
}
processEvent(&event);
}
/* Now figure out what to return */
retVal = FRAME_OK;
if (winQuit)
{
retVal = FRAME_QUIT;
}
else if ((focusState == FOCUS_SET) && (focusLast == FOCUS_OUT))
{
DBP1(("Returning SETFOCUS\n"));
focusState = FOCUS_IN;
retVal = FRAME_SETFOCUS;
}
else if ((focusState == FOCUS_KILL) && (focusLast == FOCUS_IN))
{
DBP1(("Returning KILLFOCUS\n"));
focusState = FOCUS_OUT;
retVal = FRAME_KILLFOCUS;
}
if ((focusState == FOCUS_SET) || (focusState == FOCUS_KILL))
{
/* Got a SET or KILL when we were already in or out of
focus respectively */
focusState = focusLast;
}
else if (focusLast != focusState)
{
DBP1(("focusLast changing from %d to %d\n", focusLast, focusState));
focusLast = focusState;
}
/* If things are running normally update the framerate */
if ((!winQuit) && (focusState == FOCUS_IN))
{
/* Update the frame rate stuff */
MaintainFrameStuff();
}
return retVal;
}
void frameShutDown(void)
{
screenShutDown();
/* Free the default cursor */
// DestroyCursor(hCursor);
/* Destroy the Application window */
SDL_Quit();
/* shutdown the trig stuff */
trigShutDown();
// Shutdown the resource stuff
resShutDown();
// shutdown the block memory heap
blkShutDown();
/* Shutdown the memory system */
memShutDown();
}
BOOL loadFile(STRING *pFileName, STRING **ppFileData, UDWORD *pFileSize)
{
// FIXME: evil cast
return(loadFile2(pFileName, (UBYTE **)ppFileData, pFileSize, TRUE));
}
/* Load the file with name pointed to by pFileName into a memory buffer. */
// if allocate mem is true then the memory is allocated ... else it is already in ppFileData, and the max size is in pFileSize ... this is adjusted to the actual loaded file size
//
BOOL loadFile2(STRING *pFileName, UBYTE **ppFileData, UDWORD *pFileSize, BOOL AllocateMem )
{
FILE *pFileHandle;
UDWORD FileSize;
BOOL res;
// First we try to see if we can load the file from the freedata section of the current WDG
res=loadFileFromWDG(pFileName, ppFileData, pFileSize,WDG_ALLOCATEMEM); // loaded from WDG file, and allocate memory for it
if (res==TRUE) return TRUE;
// Not in WDG so we try to load it the old fashion way !
// This will never work on the final build of the PSX because we can *ONLY* load files
// directly from CD, i.e. from the WDG's normal fopen/fread calls will never work!
#ifdef DEBUG
DBPRINTF(("FOPEN ! %s\n",pFileName));
#endif
#ifdef FINALBUILD
return FALSE;
#else
pFileHandle = fopen(pFileName, "rb");
if (pFileHandle == NULL)
{
DBERROR(("Couldn't open %s", pFileName));
return FALSE;
}
/* Get the length of the file */
if (fseek(pFileHandle, 0, SEEK_END) != 0)
{
DBERROR(("SEEK_END failed for %s", pFileName));
return FALSE;
}
FileSize = ftell(pFileHandle);
if (fseek(pFileHandle, 0, SEEK_SET) != 0)
{
DBERROR(("SEEK_SET failed for %s", pFileName));
return FALSE;
}
if (AllocateMem==TRUE)
{
/* Allocate a buffer to store the data and a terminating zero */
// we don't want this popping up in the tools (makewdg)
// DBPRINTF(("#############FILELOAD MALLOC - size=%d\n",(FileSize)+1));
*ppFileData = (UBYTE *)MALLOC((FileSize) + 1);
if (*ppFileData == NULL)
{
DBERROR(("Out of memory"));
return FALSE;
}
}
else
{
if (FileSize > *pFileSize)
{
DBERROR(("no room for file"));
return FALSE;
}
assert(*ppFileData!=NULL);
}
/* Load the file data */
if (fread(*ppFileData, 1, FileSize, pFileHandle) != FileSize)
{
DBERROR(("Read failed for %s", pFileName));
return FALSE;
}
if (fclose(pFileHandle) != 0)
{
DBERROR(("Close failed for %s", pFileName));
return FALSE;
}
// Add the terminating zero
*((*ppFileData) + FileSize) = 0;
*pFileSize=FileSize; // always set to correct size
#endif
return TRUE;
}
// load a file from disk into a fixed memory buffer
BOOL loadFileToBuffer(STRING *pFileName, UBYTE *pFileBuffer, UDWORD bufferSize, UDWORD *pSize)
{
FILE *pFileHandle;
UDWORD FileSize;
// loaded from WDG file, and allocate memory for it
if (loadFileFromWDG(pFileName, &pFileBuffer, &FileSize,WDG_USESUPPLIED))
{
*pSize=FileSize;
return TRUE;
}
pFileHandle = fopen(pFileName, "rb");
if (pFileHandle == NULL)
{
DBERROR(("Couldn't open %s", pFileName));
return FALSE;
}
/* Get the length of the file */
if (fseek(pFileHandle, 0, SEEK_END) != 0)
{
DBERROR(("SEEK_END failed for %s", pFileName));
return FALSE;
}
*pSize = ftell(pFileHandle);
if (fseek(pFileHandle, 0, SEEK_SET) != 0)
{
DBERROR(("SEEK_SET failed for %s", pFileName));
return FALSE;
}
if (*pSize >= (UDWORD)bufferSize)
{
DBERROR(("file too big !!:%s size %d\n", pFileName, *pSize));
return FALSE;
}
/* Load the file data */
if (fread(pFileBuffer, 1, *pSize, pFileHandle) != *pSize)
{
DBERROR(("Read failed for %s", pFileName));
return FALSE;
}
pFileBuffer[*pSize] = 0;
if (fclose(pFileHandle) != 0)
{
DBERROR(("Close failed for %s", pFileName));
return FALSE;
}
return TRUE;
}
// as above but returns quietly if no file found
BOOL loadFileToBufferNoError(STRING *pFileName, UBYTE *pFileBuffer, UDWORD bufferSize, UDWORD *pSize)
{
FILE *pFileHandle;
UDWORD FileSize;
// loaded from WDG file, and allocate memory for it
if (loadFileFromWDG(pFileName, &pFileBuffer, &FileSize,WDG_USESUPPLIED))
{
*pSize=FileSize;
return TRUE;
}
pFileHandle = fopen(pFileName, "rb");
if (pFileHandle == NULL)
{
return FALSE;
}
/* Get the length of the file */
if (fseek(pFileHandle, 0, SEEK_END) != 0)
{
return FALSE;
}
*pSize = ftell(pFileHandle);
if (fseek(pFileHandle, 0, SEEK_SET) != 0)
{
return FALSE;
}
if (*pSize >= (UDWORD)bufferSize)
{
return FALSE;
}
/* Load the file data */
if (fread(pFileBuffer, 1, *pSize, pFileHandle) != *pSize)
{
return FALSE;
}
pFileBuffer[*pSize] = 0;
if (fclose(pFileHandle) != 0)
{
return FALSE;
}
return TRUE;
}
/* Save the data in the buffer into the given file */
BOOL saveFile(STRING *pFileName, UBYTE *pFileData, UDWORD fileSize)
{
FILE *pFile;
/* open the file */
pFile = fopen(pFileName, "wb");
if (!pFile)
{
DBERROR(("Couldn't open %s", pFileName));
return FALSE;
}
if (fwrite(pFileData, fileSize, 1, pFile) != 1)
{
DBERROR(("Write failed for %s", pFileName ));
return FALSE;
}
if (fclose(pFile) != 0)
{
DBERROR(("Close failed for %s", pFileName));
return FALSE;
}
return TRUE;
}
//static UBYTE *WDGCacheStart=NULL;
//static UDWORD WDGCacheSize=0;
#define MAXWDGDIRSIZE (7300)
//static UBYTE WDGDirectory[MAXWDGDIRSIZE]; // Directory for current WDG file (MALLOCed)
//static SDWORD WDGCacheStartPos=-1;
//static SDWORD WDGCacheEndPos=-1;
/* next four used in HashPJW */
#define BITS_IN_int 32
#define THREE_QUARTERS ((UINT) ((BITS_IN_int * 3) / 4))
#define ONE_EIGHTH ((UINT) (BITS_IN_int / 8))
#define HIGH_BITS ( ~((UINT)(~0) >> ONE_EIGHTH ))
//#define HIGH_BITS ((UINT)(0xf0000000))
//#define LOW_BITS ((UINT)(0x0fffffff))
///////////////////////////////////////////////////////////////////
/***************************************************************************/
/*
* HashString
*
* Adaptation of Peter Weinberger's (PJW) generic hashing algorithm listed
* in Binstock+Rex, "Practical Algorithms" p 69.
*
* Accepts string and returns hashed integer.
*/
/***************************************************************************/
UINT HashString( char *String )
{
UINT iHashValue, i;
CHAR *c = (CHAR *) String;
assert(String!=NULL);
assert(*String!=0x0);
for ( iHashValue=0; *c; ++c )
{
iHashValue = ( iHashValue << ONE_EIGHTH ) + *c;
if ( (i = iHashValue & HIGH_BITS) != 0 )
{
iHashValue = ( iHashValue ^ ( i >> THREE_QUARTERS ) ) &
~HIGH_BITS;
}
}
return iHashValue;
}
UINT HashStringIgnoreCase( char *String )
{
UINT iHashValue, i;
CHAR *c = (CHAR *) String;
assert(String!=NULL);
assert(*String!=0x0);
for ( iHashValue=0; *c; ++c )
{
iHashValue = ( iHashValue << ONE_EIGHTH ) + ((*c)&(0xdf));
if ( (i = iHashValue & HIGH_BITS) != 0 )
{
iHashValue = ( iHashValue ^ ( i >> THREE_QUARTERS ) ) &
~HIGH_BITS;
}
}
return iHashValue;
}
// Examine a filename for the last dot and slash
// and so giving the extension of the file and the directory
//
// PosOfDot and/of PosOfSlash can be NULL and then nothing will be stored
//
void ScanFilename(char *Fullname, int *PosOfDot, int *PosOfSlash)
{
int Namelength;
int DotPos=-1;
int SlashPos=-1;
int Pos;
Namelength=strlen(Fullname);
for (Pos=Namelength;Pos>=0;Pos--)
{
if (Fullname[Pos]=='.')
{
DotPos=Pos;
break;
}
}
for (Pos=Namelength;Pos>=0;Pos--)
{
if (Fullname[Pos]=='\\')
{
SlashPos=Pos;
break;
}
}
if (PosOfDot!=NULL)
*PosOfDot=DotPos;
if (PosOfSlash!=NULL)
*PosOfSlash=SlashPos;
}
#ifdef DEBUG
SDWORD PercentFunc(char *File,UDWORD Line,SDWORD a,SDWORD b)
{
if(b) {
return (a*100)/b;
}
DBPRINTF(("Divide by 0 (PERCENT) in %s,line %d\n",File,Line));
return 100;
}
SDWORD PerNumFunc(char *File,UDWORD Line,SDWORD range,SDWORD a,SDWORD b)
{
if(b) {
return (a*range)/b;
}
DBPRINTF(("Divide by 0 (PERNUM) in %s,line %d\n",File,Line));
return range;
}
#endif

View File

@ -1,144 +0,0 @@
/*
* FrameInt.h
*
* Internal definitions for the framework library.
*
*/
#ifndef _frameint_h
#define _frameint_h
/* Check the header files have been included from frame.h if they
* are used outside of the framework library.
*/
#if !defined(_frame_h) && !defined(FRAME_LIB_INCLUDE)
#error Framework header files MUST be included from Frame.h ONLY.
#endif
/* Define the style and extended style of the window.
* Need these to calculate the size the window should be when returning to
* window mode.
*
* create a title bar, minimise button on the title bar,
* automatic ShowWindow, get standard system menu on title bar
*/
#define WIN_STYLE (WS_CAPTION | WS_MINIMIZEBOX | WS_VISIBLE | WS_SYSMENU)
#define WIN_EXSTYLE WS_EX_APPWINDOW // Go on task bar when iconified
/* Program hInstance */
extern HINSTANCE hInstance;
/* Handle for the main window */
extern HANDLE hWndMain;
/* Initialise the double buffered display */
extern BOOL screenInitialise(UDWORD width, // Display width
UDWORD height, // Display height
UDWORD bitDepth, // Display bit depth
BOOL fullScreen, // Whether to start windowed
// or full screen.
BOOL bVidMem, // Whether to put surfaces in
// video memory
BOOL bDDraw, // Whether to create ddraw surfaces // video memory
HANDLE hWindow); // The main windows handle
/* Release the DD objects */
extern void screenShutDown(void);
/* Restore the direct draw surfaces - internal use only */
extern void screenRestoreSurfaces(void);
/* In full screen mode flip to the GDI buffer.
* Use this if you want the user to see any GDI output.
* This is mainly used so that ASSERTs and message boxes appear
* even in full screen mode.
*/
extern void screenFlipToGDI(void);
/* Deal with windows messages to maintain the state of the keyboard and mouse */
extern void inputProcessMessages(UINT message, WPARAM wParam, LPARAM lParam);
/* This is called once a frame so that the system can tell
* whether a key was pressed this turn or held down from the last frame.
*/
extern void inputNewFrame(void);
/* The list of surfaces structure */
typedef struct _surface_list
{
LPDIRECTDRAWSURFACE4 psSurface;
struct _surface_list *psNext;
} SURFACE_LIST;
/* The list of surfaces */
extern SURFACE_LIST *psSurfaces;
/* Release all the allocated surfaces */
extern void surfShutDown(void);
/* Free current currently open widget file */
BOOL FreeCurrentWDG(void);
/* The Direct Draw object */
extern LPDIRECTDRAW4 psDD;
/* The Current screen size and bit depth */
extern UDWORD screenWidth;
extern UDWORD screenHeight;
extern UDWORD screenDepth;
/* Which modes the library can run in */
typedef enum _display_modes
{
MODE_BOTH, // Can run both windowed and full screen
MODE_WINDOWED, // Can only run windowed, not full screen
MODE_FULLSCREEN, // Can only run full screen not windowed
MODE_8BITFUDGE, // Runs 8 bit full screen, then true colour windowed
// blitting the 8 bit back buffer to the windows display
} DISPLAY_MODES;
/* The current screen mode (full screen/windowed) */
// extern SCREEN_MODE screenMode;
/* Which mode (of operation) the library is running in */
extern DISPLAY_MODES displayMode;
/* The Front and back buffers */
extern LPDIRECTDRAWSURFACE4 psFront;
extern LPDIRECTDRAWSURFACE4 psBack;
/* The Pixel format of the back buffer */
extern DDPIXELFORMAT sBackBufferPixelFormat;
/* Window's Pixel format */
extern DDPIXELFORMAT sWinPixelFormat;
// The possible flip states
typedef enum _flip_state
{
FLIP_IDLE,
FLIP_STARTED,
FLIP_FINISHED,
} FLIP_STATE;
extern FLIP_STATE screenFlipState;
// The critical section for the screen flipping
extern CRITICAL_SECTION sScreenFlipCritical;
// The semaphore for the screen flipping
extern HANDLE hScreenFlipSemaphore;
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,158 +0,0 @@
/*
* FrameResources.h
*
* Resource file processing functions
*/
// This file used to be called resource.h but that clashed with resource.h that was in the main source directory
#ifndef _resource_h
#define _resource_h
/* Maximum number of characters in a resource type */
#define RESTYPE_MAXCHAR 20
/* Maximum number of characters in a resource ID */
#define RESID_MAXCHAR 40
/* Function pointer for a function that loads from a memory buffer */
typedef BOOL (*RES_BUFFERLOAD)(UBYTE *pBuffer, UDWORD size, void **pData);
/* Function pointer for a function that loads from a filename */
typedef BOOL (*RES_FILELOAD)(STRING *pFile, void **pData);
/* Function pointer for releasing a resource loaded by the above functions */
typedef void (*RES_FREE)(void *pData);
/* callback type for resload display callback*/
typedef void (*RESLOAD_CALLBACK)(void);
typedef struct res_data
{
// aID[] is not initialised ... but for debug reasons it should be valid for PC WRF loading .... PLEASE WRITE THE CODE SOON !!!!
// This is for debug use only !!!!!!!!!!
#ifdef DEBUG
STRING aID[RESID_MAXCHAR]; // ID of the resource - filename from the .wrf - e.g. "TRON.PIE"
#endif
void *pData; // pointer to the acutal data
SDWORD blockID; // which of the blocks is it in (so we can clear some of them...)
UDWORD HashedID; // hashed version of the name of the id
struct res_data *psNext; // next entry - most likely to be following on!
#ifdef DEBUG
UDWORD usage;
#endif
} RES_DATA;
// New reduced resource type ... specially for PSX
// These types are statically defined in data.c
typedef struct _res_type
{
// type is still needed on psx ... strings are defined in source - data.c (yak!)
STRING aType[RESTYPE_MAXCHAR]; // type string (e.g. "PIE" - just for debug use only, only aplicable when loading from wrf (not wdg)
RES_BUFFERLOAD buffLoad; // routine to process the data for this type
RES_FREE release; // routine to release the data (NULL indicates none)
// we must have a pointer to the data here so that we can do a resGetData();
RES_DATA *psRes; // Linked list of data items of this type
UDWORD HashedType; // hashed version of the name of the id - // a null hashedtype indicates end of list
RES_FILELOAD fileLoad; // This isn't really used any more ?
struct _res_type *psNext;
} RES_TYPE;
/* set the function to call when loading files with resloadfile*/
extern VOID resSetLoadCallback(RESLOAD_CALLBACK funcToCall);
/* callback type for res pre-load callback*/
typedef BOOL (*RESPRELOAD_CALLBACK)(char *type, char *name, char *directory);
/* set the function to call when loading files with resloadfile*/
extern VOID resSetPreLoadCallback(RESPRELOAD_CALLBACK funcToCall);
/* Initialise the resource module */
extern BOOL resInitialise(void);
/* Shutdown the resource module */
extern void resShutDown(void);
// set the base resource directory
extern void resSetBaseDir(STRING *pResDir);
/* Parse the res file */
struct _block_heap;
extern BOOL resLoad(STRING *pResFile, SDWORD blockID,
UBYTE *pLoadBuffer, SDWORD bufferSize,
struct _block_heap *psMemHeap);
/* Release all the resources currently loaded and the resource load functions */
extern void resReleaseAll(void);
// release the data for a particular block ID
extern void resReleaseBlockData(SDWORD blockID);
/* Release all the resources currently loaded but keep the resource load functions */
extern void resReleaseAllData(void);
/* Add a buffer load and release function for a file type */
extern BOOL resAddBufferLoad(STRING *pType, RES_BUFFERLOAD buffLoad,
RES_FREE release);
/* Add a file name load and release function for a file type */
extern BOOL resAddFileLoad(STRING *pType, RES_FILELOAD fileLoad,
RES_FREE release);
/* Call the load function for a file */
extern BOOL resLoadFile(STRING *pType, STRING *pFile);
// Add data to the resource system
extern BOOL resAddData(STRING *pType, STRING *pID, void *pData);
/* Return the resource for a type and ID */
extern void *resGetDataFromHash(STRING *pType, UDWORD HashedID);
extern void *resGetData(STRING *pType, STRING *pID);
extern BOOL resPresent(STRING *pType, STRING *pID);
void resToLower(STRING *pStr);
// return the ID string for a piece of data
//extern BOOL resGetIDfromData(STRING *pType, void *pData, STRING **ppID); // no longer valid use the function below
// return the HashedID string for a piece of data
extern BOOL resGetHashfromData(STRING *pType, void *pData, UDWORD *pHash);
VOID resDoResLoadCallback();
//return last imd resource
char *GetLastResourceFilename(void);
// Set the resource name of the last resource file loaded
void SetLastResourceFilename(char *pName);
// Returns the filename of the last resource file loaded
UDWORD GetLastHashName(void);
// Set the resource name of the last resource file loaded
void SetLastHashName(UDWORD HashName);
BOOL LoadWRF(char *pResFile, UBYTE **pBuffer, UDWORD *size);
UDWORD ReadWDGData(UDWORD WDGoffset, UBYTE *DestinationAddress, UDWORD BytesToLoad);
BOOL OpenWDG(char *WDGname);
BOOL IsWDGopen(void);
void CloseWDG(void);
void SetLastResourceHash(char *fname);
#endif

View File

@ -1,576 +0,0 @@
/*
* Heap.c
*
* Memory routines for managing groups of the same sized objects.
*
*/
#include <string.h>
#include <stdio.h>
#include <assert.h>
/* Allow frame header files to be singly included */
#define FRAME_LIB_INCLUDE
#include "types.h"
#include "debug.h"
#include "mem.h"
#include "heap.h"
#include "treap.h"
#include "treapint.h"
#include "block.h"
// Control whether a heap usage report is printed out when a heap is destroyed
#define HEAP_USAGE_REPORT FALSE
// Control whether a copy for the filename string is taken in DEBUG mode
#define COPY_FILE_STRING FALSE
/* Store the call position */
static STRING *pCFile;
static SDWORD cPos;
#if DEBUG_HEAP
#define MAXDEBUGHEAPS (32)
static OBJ_HEAP * HeapDebugList[MAXDEBUGHEAPS];
#endif
/* Store the location in C code at which a call to the heap was made */
void heapSetCallPos(STRING *pFileName, SDWORD lineNumber)
{
cPos = lineNumber;
#if COPY_FILE_STRING
pCFile = (STRING *)MALLOC(strlen(pFileName) + 1);
if (!pCFile)
{
return;
}
strcpy(pCFile, pFileName);
#else
pCFile = pFileName;
#endif
}
/* Create the free list for a heap */
static void heapCreateFreeList(OBJ_HEAP *psHeap)
{
UDWORD size = psHeap->objSize;
UDWORD ext = psHeap->extAlloc;
UDWORD i, extSize;
FREE_OBJECT *psCurr = NULL;
UBYTE *pBase;
HEAP_EXTENSION *psExt;
// Set up the main memory block
#if DEBUG_HEAP
UDWORD init = psHeap->initAlloc;
// Initialise the memory to a fixed value to check for memory overwrites
memset(psHeap->pMemory, FREE_BYTE, size * init);
#endif
psHeap->psFree = (FREE_OBJECT *)(psHeap->pMemory);
pBase = psHeap->pMemory;
for(i=psHeap->initAlloc; i>0; i--)
{
psCurr = (FREE_OBJECT *)(pBase);
psCurr->psNext = (FREE_OBJECT *)(pBase + size);
pBase += size;
}
// Set up the extension blocks if any
extSize = size * ext;
for(psExt = psHeap->psExt; psExt; psExt = psExt->psNext)
{
#if DEBUG_HEAP
// Initialise the memory to check for overwrites
memset(psExt->pMemory, FREE_BYTE, extSize);
#endif
// Link this list to the end of the free list
psCurr->psNext = (FREE_OBJECT *)(psExt->pMemory);
// Now create the free object list
pBase = psExt->pMemory;
for(i=psHeap->extAlloc; i>0; i--)
{
psCurr = (FREE_OBJECT *)(pBase);
psCurr->psNext = (FREE_OBJECT *)(pBase + size);
pBase += size;
}
}
// Terminate the free list
psCurr->psNext = NULL;
}
/* Function to create a heap
* Takes the size of the objects to be managed by the heap,
* the initial number of objects to allocate and the number of
* objects to allocate when the heap is extended.
* Returns an initialised OBJ_HEAP structure.
*/
BOOL heapCreate(OBJ_HEAP **ppsHeap, UDWORD size, UDWORD init, UDWORD ext)
{
/* UDWORD i;
FREE_OBJECT *psCurr;
UBYTE *pBase;*/
#if DEBUG_HEAP
int Heap;
#endif
ASSERT((size >= sizeof(FREE_OBJECT),
"heapCreate: object is too small to be stored in free list"));
#if DEBUG_HEAP
/* Increase the object size to store the call position */
size += sizeof(HEAP_OBJHDR);
#endif
/* Allocate the heap object and its memory */
*ppsHeap = (OBJ_HEAP *)MALLOC(sizeof(OBJ_HEAP));
if (*ppsHeap == NULL)
{
DBERROR(("heapCreate: Out of memory"));
return FALSE;
}
// memset(*ppsHeap,0,sizeof(OBJ_HEAP)); //setting everything to 0 first (debug test)-Q
(*ppsHeap)->pMemory = (UBYTE *)MALLOC(size * init);
/*
if (PTRVALID((*ppsHeap)->pMemory,size*init)==FALSE)
{
DBPRINTF(("Allocated heap memory is not valid!\n"));
}
else
{
DBPRINTF(("valid\n"));
}
*/
if ((*ppsHeap)->pMemory == NULL)
{
DBERROR(("heapCreate: Out of memory"));
return FALSE;
}
/* Initialise the object */
(*ppsHeap)->objSize = size;
(*ppsHeap)->initAlloc = init;
(*ppsHeap)->extAlloc = ext;
(*ppsHeap)->psExt = NULL;
(*ppsHeap)->psBlkHeap = memGetBlockHeap();
#if DEBUG_HEAP
(*ppsHeap)->maxUsage = 0;
(*ppsHeap)->currUsage = 0;
(*ppsHeap)->pFile = pCFile;
(*ppsHeap)->line = cPos;
(*ppsHeap)->psInUse = NULL;
// Keep a list of all the heaps allocated
for (Heap=0;Heap<MAXDEBUGHEAPS;Heap++)
{
if (HeapDebugList[Heap] == NULL) // found an empty one
{
HeapDebugList[Heap]=*ppsHeap;
break;
}
}
if (HeapDebugList[Heap]!=*ppsHeap)
{
DBERROR(("heapCreate: MAXDEBUGHEAPS too small"));
}
#endif
// Now create the free object list
heapCreateFreeList(*ppsHeap);
/*
if (PTRVALID((*ppsHeap)->pMemory,10)==FALSE)
{
DBPRINTF(("Allocated heap memory is not valid!\n"));
}
else
{
DBPRINTF(("valid\n"));
}
*/
/*
#if DEBUG_MALLOC
// Initialise the memory to a fixed value to check for memory overwrites
memset((*ppsHeap)->pMemory, FREE_BYTE, size * init);
#endif
// Now create the free object list
(*ppsHeap)->psFree = (FREE_OBJECT *)((*ppsHeap)->pMemory);
pBase = (*ppsHeap)->pMemory;
for(i=0; i<init; i++)
{
psCurr = (FREE_OBJECT *)(pBase + i*size);
psCurr->psNext = (FREE_OBJECT *)((UBYTE *)psCurr + size);
}
psCurr->psNext = NULL;
*/
return TRUE;
}
/* Allocate an object from a heap
* Returns a pointer to the object if successful
*/
BOOL heapAlloc(OBJ_HEAP *psHeap, void **ppObject)
{
HEAP_EXTENSION *psNew;
UDWORD i;
FREE_OBJECT *psCurr = NULL;
UBYTE *pBase;
BLOCK_HEAP *psCurrBlk;
#if DEBUG_HEAP
HEAP_OBJHDR *psHdr;
#endif
ASSERT((PTRVALID(psHeap, sizeof(OBJ_HEAP)),
"heapAlloc: Invalid heap pointer"));
if (psHeap->psFree == NULL)
{
if (psHeap->extAlloc == 0)
{
// heap doesn't expand
#if DEBUG_HEAP && COPY_FILE_STRING
FREE(pCFile);
#endif
return FALSE;
}
/* No objects left - need to add a heap extension */
psCurrBlk = memGetBlockHeap();
memSetBlockHeap(psHeap->psBlkHeap);
#if DEBUG_HEAP
DBPRINTF(("Heap %s, line %d extended. Max use: %d\n", psHeap->pFile, psHeap->line, psHeap->maxUsage));
#endif
psNew = (HEAP_EXTENSION *)MALLOC(sizeof(HEAP_EXTENSION));
if (psNew == NULL)
{
/* Out of memory */
return FALSE;
}
psNew->pMemory = (UBYTE *)MALLOC(psHeap->objSize * psHeap->extAlloc);
if (psNew->pMemory == NULL)
{
/* Out of memory */
FREE(psNew);
return FALSE;
}
memSetBlockHeap(psCurrBlk);
#if DEBUG_HEAP
/* Initialise the memory to check for overwrites */
memset(psNew->pMemory, FREE_BYTE, psHeap->objSize * psHeap->extAlloc);
#endif
/* Add the extension to the list */
psNew->psNext = psHeap->psExt;
psHeap->psExt = psNew;
/* Now create the free object list */
psHeap->psFree = (FREE_OBJECT *)(psNew->pMemory);
pBase = psNew->pMemory;
for(i=0; i<psHeap->extAlloc; i++)
{
psCurr = (FREE_OBJECT *)(pBase + i*psHeap->objSize);
psCurr->psNext = (FREE_OBJECT *)((UBYTE *)psCurr + psHeap->objSize);
}
psCurr->psNext = NULL;
}
/* Return the object and update the free list */
*ppObject = psHeap->psFree;
psHeap->psFree = psHeap->psFree->psNext;
#if DEBUG_HEAP
/* Update the usage counts */
psHeap->currUsage += 1;
if (psHeap->currUsage > psHeap->maxUsage)
{
psHeap->maxUsage = psHeap->currUsage;
}
/* Check the object we're giving out hasn't been scribbled over by anything */
if (psHeap->objSize > sizeof(FREE_OBJECT))
{
for(pBase = (UBYTE *)*ppObject + sizeof(FREE_OBJECT);
pBase < (UBYTE *)*ppObject + psHeap->objSize;
pBase++)
{
if (*pBase != FREE_BYTE)
{
break;
}
}
ASSERT((pBase == (UBYTE *)*ppObject + psHeap->objSize,
"heapAlloc: unallocated object memory has been overwritten"));
}
/* Store the call position */
psHdr = (HEAP_OBJHDR *)*ppObject;
psHdr->pFile = pCFile;
psHdr->line = cPos;
*ppObject = ((UBYTE *)*ppObject) + sizeof(HEAP_OBJHDR);
/* Add the object to the in use list */
psHdr->psNext = psHeap->psInUse;
psHeap->psInUse = psHdr;
#endif
return TRUE;
}
/* Return an object to the heap */
BOOL heapFree(OBJ_HEAP *psHeap, void *pObject)
{
#if DEBUG_HEAP
BOOL found;
HEAP_OBJHDR *psHdr, *psCurrHdr, *psPrevHdr;
#endif
FREE_OBJECT *psFree;
ASSERT((PTRVALID(psHeap, sizeof(OBJ_HEAP)),
"heapFree: Invalid heap pointer"));
#if DEBUG_HEAP
/* Adjust the pointer to include the call position */
pObject = ((UBYTE *)pObject) - sizeof(HEAP_OBJHDR);
/* Free the string memory for the file name */
psHdr = (HEAP_OBJHDR *)pObject;
#if COPY_FILE_STRING
if (psHdr->pFile)
{
FREE(psHdr->pFile);
}
#endif
/* Remove the object from the in use list */
found = FALSE;
if (psHeap->psInUse == psHdr)
{
psHeap->psInUse = psHdr->psNext;
found = TRUE;
}
else
{
for(psCurrHdr=psHeap->psInUse; psCurrHdr; psCurrHdr = psCurrHdr->psNext)
{
if (psCurrHdr == psHdr)
{
psPrevHdr->psNext = psCurrHdr->psNext;
found = TRUE;
break;
}
psPrevHdr = psCurrHdr;
}
}
ASSERT((found, "heapFree: object not allocated on this heap"));
/* Check the object hasn't been freed already */
found = FALSE;
for(psFree = psHeap->psFree; psFree != NULL; psFree = psFree->psNext)
{
if (pObject == (void *)psFree)
{
found = TRUE;
}
}
ASSERT((!found, "heapFree: Object has already been freed"));
/* On the debug build we'll trash the memory as well - just to be sure */
memset(pObject, FREE_BYTE, psHeap->objSize);
/* Update the usage counter */
psHeap->currUsage -= 1;
#endif
psFree = (FREE_OBJECT *)pObject;
psFree->psNext = psHeap->psFree;
psHeap->psFree = psFree;
return TRUE;
}
/* Reset the heap, i.e. free all the objects in the heap */
void heapReset(OBJ_HEAP *psHeap)
{
/* Initialise the object */
#if DEBUG_HEAP
psHeap->currUsage = 0;
psHeap->psInUse = NULL;
#endif
// Now create the free object list
heapCreateFreeList(psHeap);
}
/* Destroy a heap and release all the memory associated with it */
void heapDestroy(OBJ_HEAP *psHeap)
{
HEAP_EXTENSION *psExt, *psNext;
#if DEBUG_HEAP
FREE_OBJECT *psFree;
UBYTE *pStart, *pEnd;
BOOL clean;
HEAP_OBJHDR *psCurrHdr;
int Heap;
#endif
ASSERT((PTRVALID(psHeap, sizeof(OBJ_HEAP)),
"heapDestroy: invalid heap pointer"));
#if DEBUG_HEAP
/* Warn about any unfreed objects */
if (psHeap->currUsage > 0)
{
DBPRINTF(("heapDestroy: %s, line %d : %d objects in use\n",
psHeap->pFile, psHeap->line, psHeap->currUsage));
}
/* Print out where the unfreed objects were allocated */
for(psCurrHdr = psHeap->psInUse; psCurrHdr; psCurrHdr=psCurrHdr->psNext)
{
DBPRINTF((" %s, line %d\n",
psCurrHdr->pFile, psCurrHdr->line));
#if COPY_FILE_STRING
if (psCurrHdr->pFile)
{
FREE(psCurrHdr->pFile);
}
#endif
}
/* Check for any memory overwrites on the free objects */
clean = TRUE;
for(psFree = psHeap->psFree; psFree != NULL; psFree = psFree->psNext)
{
pEnd = (UBYTE *)psFree + psHeap->objSize;
for(pStart = (UBYTE *)psFree + sizeof(FREE_OBJECT); pStart<pEnd; pStart++)
{
if (*pStart != FREE_BYTE)
{
clean = FALSE;
}
}
}
ASSERT((clean, "heapDestroy: unallocated memory has been overwritten"));
#if HEAP_USAGE_REPORT
DBPRINTF(("heapDestory: %s, line %d : Max usage %d (Init %d Ext %d)\n",
psHeap->pFile, psHeap->line, psHeap->maxUsage,
psHeap->initAlloc, psHeap->extAlloc));
#endif
#if COPY_FILE_STRING
if (psHeap->pFile)
{
FREE(psHeap->pFile);
}
#endif
// Find the heap
for (Heap=0;Heap<MAXDEBUGHEAPS;Heap++)
{
if (HeapDebugList[Heap] == psHeap) // found an match
{
HeapDebugList[Heap]=NULL;
break;
}
}
#endif
/* Deallocate all the heap's memory */
for(psExt = psHeap->psExt; psExt != NULL; psExt = psNext)
{
psNext = psExt->psNext;
FREE(psExt->pMemory);
FREE(psExt);
}
FREE(psHeap->pMemory);
FREE(psHeap);
}
BOOL heapIntegrityCheck(OBJ_HEAP *psHeap)
{
#if DEBUG_HEAP
FREE_OBJECT *psCurr;
UBYTE *pBase;
if (psHeap->objSize < sizeof(FREE_OBJECT))
{
// too small to check
return TRUE;
}
for(psCurr = psHeap->psFree; psCurr; psCurr=psCurr->psNext)
{
// Check each object hasn't been scribbled over by anything
for(pBase = (UBYTE *)psCurr + sizeof(FREE_OBJECT);
pBase < (UBYTE *)psCurr + psHeap->objSize;
pBase++)
{
if (*pBase != FREE_BYTE)
{
break;
}
}
ASSERT((pBase == (UBYTE *)psCurr + psHeap->objSize,
"heapIntegrityCheck: unallocated object memory has been overwritten"));
}
#else
psHeap = psHeap;
#endif
return TRUE;
}
void heapReport(void)
{
#if DEBUG_HEAP
int Heap;
OBJ_HEAP *psHeap;
DBPRINTF(("\nheapReport\n==========\n"));
for (Heap=0;Heap<MAXDEBUGHEAPS;Heap++)
{
if (HeapDebugList[Heap] != NULL)
{
psHeap=HeapDebugList[Heap];
DBPRINTF(("Heap: %s, line %d size=%d mem taken=%d\n",
psHeap->pFile, psHeap->line, psHeap->objSize, psHeap->objSize*psHeap->initAlloc));
DBPRINTF((" Current Usage=%d ",psHeap->currUsage));
DBPRINTF((" Max usage %d (Init %d Ext %d)\n",
psHeap->maxUsage,
psHeap->initAlloc, psHeap->extAlloc));
}
}
#else
#endif
}

View File

@ -1,134 +0,0 @@
/*
* Heap.h
*
* Interface to the heap memory routines.
*
* Overhead of using the heap is :
* 24 bytes for the initial block
* 4 bytes for the extension blocks
*
*/
#ifndef _heap_h
#define _heap_h
#include "types.h"
#include "debug.h"
/* Include Mem.h to get the DEBUG_MALLOC #define - this controls whether
* normal or debugging memory management is used.
*/
#include "mem.h"
/* structure used to store the list of free heap objects */
typedef struct _free_object
{
struct _free_object *psNext;
} FREE_OBJECT;
/* Header for each object in DEBUG_MALLOC mode */
typedef struct _heap_objhdr
{
STRING *pFile;
SDWORD line;
struct _heap_objhdr *psNext;
} HEAP_OBJHDR;
/* structure used to store the extra space allocated for the heap */
typedef struct _heap_extension
{
UBYTE *pMemory;
struct _heap_extension *psNext;
} HEAP_EXTENSION;
typedef struct _obj_heap
{
UDWORD objSize; // The size of the objects being stored on the heap
UDWORD initAlloc; // The initial number of objects allocated
UDWORD extAlloc; // The number of objects to allocate after the initial
// allocation is used up
struct _block_heap *psBlkHeap; // which block heap (if any) this object heap was allocated from
FREE_OBJECT *psFree; // The currently free objects
UBYTE *pMemory; // The main memory heap
HEAP_EXTENSION *psExt; // Extension memory for the heap
#if DEBUG_HEAP
UDWORD maxUsage; // The maximum number of objects used so far
UDWORD currUsage; // The number of objects being used at the moment
HEAP_OBJHDR *psInUse; // The list of headers of objects currently allocated
STRING *pFile; // The name of the file the heap was created in
SDWORD line; // The line of the file the heap was created on
#endif
} OBJ_HEAP;
/****************************************************************************************/
/* Function Protoypes */
/* */
/* These should not be called directly - use the macros below */
/* Store the location in C code at which a call to the heap was made */
extern void heapSetCallPos(STRING *pFileName, SDWORD lineNumber);
/* Function to create a heap
* Takes the size of the objects to be managed by the heap,
* the initial number of objects to allocate and the number of
* objects to allocate when the heap is extended.
* Returns an initialised OBJ_HEAP structure.
*/
extern BOOL heapCreate(OBJ_HEAP **ppsHeap, UDWORD size, UDWORD init, UDWORD ext);
/* Allocate an object from a heap
* Returns a pointer to the object if successful
*/
extern BOOL heapAlloc(OBJ_HEAP *psHeap, void **ppObject);
/* Return an object to the heap */
extern BOOL heapFree(OBJ_HEAP *psHeap, void *pObject);
/* Reset the heap, i.e. free all the objects in the heap */
extern void heapReset(OBJ_HEAP *psHeap);
/* Destroy a heap and release all the memory associated with it */
extern void heapDestroy(OBJ_HEAP *psHeap);
/* Produce a summary report on the heaps ... DEBUG_MALLOC only */
void heapReport(void);
/****************************************************************************************/
/* Macro definitions */
#if DEBUG_HEAP
#define HEAP_CREATE(ppsHeap, size, init, ext) \
(heapSetCallPos(__FILE__, __LINE__), \
heapCreate(ppsHeap, size, init, ext))
#define HEAP_ALLOC(psHeap, ppObject) \
(heapSetCallPos(__FILE__, __LINE__), \
heapAlloc(psHeap, ppObject))
#else
#define HEAP_CREATE(ppsHeap, size, init, ext) \
heapCreate(ppsHeap, size, init, ext)
#define HEAP_ALLOC(psHeap, ppObject) \
heapAlloc(psHeap, ppObject)
#endif
#define HEAP_FREE(psHeap, pObject) \
heapFree(psHeap, pObject)
#define HEAP_RESET(psHeap) \
heapReset(psHeap)
#define HEAP_DESTROY(psHeap) \
heapDestroy(psHeap)
#endif

View File

@ -1,539 +0,0 @@
/*
* Image.c
*
* Routines to parse different image formats
*
*/
#define WIN32_LEAN_AND_MEAN
#define WIN32_EXTRA_LEAN
#include <windows.h>
#include <ddraw.h>
/* Allow frame header files to be singly included */
#define FRAME_LIB_INCLUDE
#include "types.h"
#include "debug.h"
#include "mem.h"
#include "image.h"
// Define this if you want to generate pictures (for tools ?)
#define WRITEIMAGES
/* The byte value after which the byte represents a run length in a PCX file */
#define RLE_START 192
/* The size of a PCX palette */
#define PCX_PALETTE_SIZE (256*3)
/* The PCX file header data structure */
/*lint -e754 */
typedef struct _pcxheader {
UBYTE manufacturer; // Always 10
UBYTE version;
UBYTE encoding; // Always 1 : RLE
UBYTE bitsPerPixel;
SWORD x, y; // Upper left of the image
UWORD width, height; // Image size - have to add one to both of these
// presumably 0..width = width + 1 bytes ???
SWORD xResolution, yResolution; // Pixels in x and y direction
UBYTE aOldPalette[48]; // EGA palette
UBYTE reserved;
UBYTE planes; // Number of planes in the image
SWORD bytesPerLine;
SWORD paletteType;
UBYTE aPadding[58];
} PCXHEADER;
/* Take a memory buffer that contains a PCX file and convert it
* to an image buffer and a palette buffer.
* If the returned palette pointer is NULL a true colour PCX has
* been loaded. In this case the image data will be 32 bit true colour.
*/
BOOL imageParsePCX(UBYTE *pFileData, // Original file
UDWORD fileSize, // File size
UDWORD *pWidth, // Image width
UDWORD *pHeight, // Image height
UBYTE **ppImageData, // Image data from file
PALETTEENTRY **ppsPalette) // Palette data from file
{
PCXHEADER sHeader;
UBYTE *pSrc, *pDest, *pEndBuffer;
PALETTEENTRY *psCurrPal;
SWORD runlen;
ASSERT((fileSize > 0, "Invalid file size"));
ASSERT((PTRVALID(pFileData, fileSize), "Invalid file buffer"));
ASSERT((ppImageData != NULL, "Invalid image data pointer"));
ASSERT((ppsPalette != NULL, "Invalide palette data pointer"));
/* Get the header information */
memcpy(&sHeader, pFileData, sizeof(PCXHEADER));
/* Check the image format :
- uses RLE
- uses 8 bits per pixel
- uses one colour plane
*/
if (sHeader.encoding != 1 ||
sHeader.bitsPerPixel != 8 ||
sHeader.planes != 1)
{
DBERROR(("Unknown PCX format"));
return FALSE;
}
*pWidth = sHeader.width + 1;
*pHeight = sHeader.height + 1;
/* Allocate a buffer to store the image data */
*ppImageData = (UBYTE *)MALLOC((UDWORD)((*pWidth) * (*pHeight)));
if (!(*ppImageData))
{
DBERROR(("Out of memory"));
return FALSE;
}
/* Read in the image data, decompressing */
pSrc = pFileData + sizeof(PCXHEADER);
pDest = *ppImageData;
pEndBuffer = pDest + (*pWidth) * (*pHeight);
while (pDest < pEndBuffer)
{
if (*pSrc < RLE_START)
{
/* no run length - put it straight into the buffer */
*(pDest++) = *(pSrc++);
}
else
{
/* got an RLE - find its length and read in the actual data */
runlen = (SWORD)(*(pSrc++) - RLE_START);
/* now store the run into the image buffer */
while ((runlen > 0) && (pDest < pEndBuffer))
{
*(pDest++) = *pSrc;
runlen--;
}
pSrc++;
if (runlen != 0)
{
/* The image data is corrupt as it decompresses to a
bigger image than specified in the header */
DBERROR(("Corrupt PCX file data"));
FREE(*ppImageData);
return FALSE;
}
}
}
/* Allocate a buffer for the palette */
*ppsPalette = (PALETTEENTRY *)MALLOC(256 * sizeof(PALETTEENTRY));
if (!(*ppsPalette))
{
DBERROR(("Out of memory"));
FREE(*ppImageData);
return FALSE;
}
memset(*ppsPalette, 0, sizeof(PALETTEENTRY) * 256);
/* Ensure we are at the right place in the file data to read the palette */
pSrc = pFileData + fileSize - PCX_PALETTE_SIZE;
/* Now read in the palette inforamtion */
pEndBuffer = pSrc + PCX_PALETTE_SIZE;
psCurrPal = *ppsPalette;
while (pSrc < pEndBuffer)
{
psCurrPal->peRed = *(pSrc++);
psCurrPal->peGreen = *(pSrc++);
psCurrPal->peBlue = *(pSrc++);
psCurrPal++;
}
return TRUE;
}
typedef struct _bmp_fileheader
{
UDWORD size; // Size in bytes of the file
UWORD reserved1;
UWORD reserved2;
UDWORD offset; // Offset to image data in bytes
} BMP_FILEHEADER;
typedef struct _bmp_infoheader
{
UDWORD headerSize; // 40 for windows format, 12 for OS/2
UDWORD width; // Image width
UDWORD height; // Image height
UWORD planes; // Image planes must be 1
UWORD bitCount; // Bits per pixel, 1,4,8, or 24
/* This is as far as the OS/2 header goes, the rest is only for windows BMP */
UDWORD compression; // Compression type
UDWORD sizeImage; // Size in bytes of compressed image or zero
UDWORD xPelsPerMeter; // Horizontal resolution in pixels per meter
UDWORD yPelsPerMeter; // Vertical resolution in pixels per meter
UDWORD coloursUsed; // Number of colours actually used in the image
UDWORD coloursImportant; // Number of important colours (for reducing the bit depth)
} BMP_INFOHEADER;
/* Take a memory buffer that contains a BMP file and convert it
* to an image buffer and a palette buffer.
* If the returned palette pointer is NULL a true colour BMP has
* been loaded. In this case the image data will be 32 bit true colour.
*/
BOOL imageParseBMP(UBYTE *pFileData, // Original file
UDWORD fileSize, // File size
UDWORD *pWidth, // Image width
UDWORD *pHeight, // Image height
UBYTE **ppImageData, // Image data from file
PALETTEENTRY **ppsPalette) // Palette data from file
{
BMP_FILEHEADER *psFileHeader;
BMP_INFOHEADER *psInfoHeader;
UDWORD paletteEntries, i;
SDWORD x,y;
UBYTE *pPalByte;
UBYTE *pImgDest, *pImgSrc;
(void)fileSize;
ASSERT((PTRVALID(pFileData, fileSize),
"imageParseBMP: Invalid file data pointer"));
/* Check that the first two bytes are ASCII "BM" */
if (*((UWORD *)pFileData) != 0x4d42)
{
DBERROR(("Invalid BMP file"));
return FALSE;
}
psFileHeader = (BMP_FILEHEADER *)(pFileData + 2);
psInfoHeader = (BMP_INFOHEADER *)(pFileData + 2 + sizeof(BMP_FILEHEADER));
if (psInfoHeader->headerSize != 40)
{
if (psInfoHeader->headerSize == 12)
{
DBERROR(("OS/2 Bitmaps not implemented"));
}
else
{
DBERROR(("Unknown BMP format"));
}
return FALSE;
}
if (psInfoHeader->planes != 1)
{
DBERROR(("Unknown BMP format : more than one plane"));
return FALSE;
}
*pWidth = psInfoHeader->width;
*pHeight = psInfoHeader->height;
/* Read in the palette information if there is any */
if (psInfoHeader->bitCount <= 8)
{
/* Find out the number of entries in the palette */
if (psInfoHeader->coloursUsed > 0)
{
paletteEntries = psInfoHeader->coloursUsed;
}
else
{
switch (psInfoHeader->bitCount)
{
case 1:
paletteEntries = 2;
break;
case 4:
paletteEntries = 16;
break;
case 8:
paletteEntries = 256;
break;
default:
DBERROR(("Unknown bit depth for BMP: %d", psInfoHeader->bitCount));
return FALSE;
break;
}
}
/* Allocate a palette of a full 256 entries anyway - everything gets
* converted to 8 bit.
*/
*ppsPalette = (PALETTEENTRY *)MALLOC(sizeof(PALETTEENTRY) * 256);
if (*ppsPalette == NULL)
{
DBERROR(("Out of memory"));
return FALSE;
}
/* Set it all to zero for those images that use less than 256 entries. */
memset((void *)(*ppsPalette), 0, sizeof(PALETTEENTRY) * 256);
/* Copy the palette data over */
pPalByte = pFileData + 2 + sizeof(BMP_FILEHEADER) + sizeof(BMP_INFOHEADER);
for(i=0; i<paletteEntries; i++)
{
(*ppsPalette)[i].peBlue = *(pPalByte ++);
(*ppsPalette)[i].peGreen = *(pPalByte ++);
(*ppsPalette)[i].peRed = *(pPalByte ++);
(*ppsPalette)[i].peFlags = 0;
pPalByte ++;
}
}
switch (psInfoHeader->bitCount)
{
case 1:
DBERROR(("1 Bit BMP not implemented"));
FREE(*ppsPalette);
return FALSE;
break;
case 4:
/* Allocate the memory for the image */
*ppImageData = (UBYTE *)MALLOC((*pWidth) * (*pHeight) /2);
if (*ppImageData == NULL)
{
DBERROR(("Out of memory"));
FREE(*ppsPalette);
return FALSE;
}
if (psInfoHeader->compression == 0)
{
/* No compression on the image - just copy it */
pImgSrc = pFileData + psFileHeader->offset;
for(y=(*pHeight)-1; y >= 0; y--)
{
/* BMPs are stored upside down - have to reverse them */
pImgDest = (*ppImageData) + (*pWidth /2) * y;
/* Copy the line over */
for(x=0; x<(SDWORD)(*pWidth /2); x++)
{
BYTE SourceByte,DestByte;
SourceByte=*(pImgSrc ++);
// Swap nibbles
DestByte=(UBYTE)((SourceByte & 0x0f)<<4);
DestByte= (UBYTE)( DestByte |((SourceByte & 0xf0)>>4) );
*(pImgDest ++) = DestByte;
}
/* Now skip any padding to the next DWord boundary */
while (x % 4)
{
pImgSrc++;
x ++;
}
}
}
else
{
DBERROR(("Compressed BMP not implemented"));
FREE(*ppsPalette);
return FALSE;
}
break;
case 8:
/* Allocate the memory for the image */
*ppImageData = (UBYTE *)MALLOC((*pWidth) * (*pHeight));
if (*ppImageData == NULL)
{
DBERROR(("Out of memory"));
FREE(*ppsPalette);
return FALSE;
}
if (psInfoHeader->compression == 0)
{
/* No compression on the image - just copy it */
pImgSrc = pFileData + psFileHeader->offset;
for(y=(*pHeight)-1; y >= 0; y--)
{
/* BMPs are stored upside down - have to reverse them */
pImgDest = (*ppImageData) + (*pWidth) * y;
/* Copy the line over */
for(x=0; x<(SDWORD)(*pWidth); x++)
{
*(pImgDest ++) = *(pImgSrc ++);
}
/* Now skip any padding to the next DWord boundary */
while (x % 4)
{
pImgSrc++;
x ++;
}
}
}
else
{
DBERROR(("Compressed BMP not implemented"));
FREE(*ppsPalette);
return FALSE;
}
break;
case 24:
DBERROR(("24 Bit BMP not implemented"));
return FALSE;
break;
default:
DBERROR(("Unknown bit depth for BMP: %d", psInfoHeader->bitCount));
return FALSE;
break;
}
return TRUE;
}
#ifdef WRITEIMAGES
#define PALCOUNT (256)
/* Take a memory buffer that contains a image buffer and convert it
* to a BMP file.
*
* - NULL palette indicates a 24bit bmp
*/
BOOL imageCreateBMP(UBYTE *pImageData, // Original file
PALETTEENTRY *pPaletteData, // Palette data
UDWORD Width, // Image width
UDWORD Height, // Image height
UBYTE **ppBMPFile, // Image data from file
UDWORD *fileSize) // Generated BMP File size
{
BMP_FILEHEADER *psFileHeader;
BMP_INFOHEADER *psInfoHeader;
UDWORD BMPSize;
UBYTE *BMPdata;
int BitCount;
int PalEntry,Ycoord;
UBYTE *DataPointer;
UBYTE *ImagePointer;
// If we have no palette then assume that the BMP is 24 bit
if (pPaletteData!=NULL)
BitCount=8;
else
BitCount=24;
psFileHeader=MALLOC(sizeof(BMP_FILEHEADER));
if (psFileHeader==NULL) return FALSE;
psInfoHeader=MALLOC(sizeof(BMP_INFOHEADER));
if (psInfoHeader==NULL)
{
FREE(psFileHeader);
return FALSE;
}
// Calc the number of bytes for this BMP file
if (BitCount==8)
{
BMPSize=2+sizeof(BMP_FILEHEADER)+sizeof(BMP_INFOHEADER)+(PALCOUNT*4)+(Width*Height);
}
else
{
BMPSize=2+sizeof(BMP_FILEHEADER)+sizeof(BMP_INFOHEADER)+(Width*Height*3);
}
BMPdata=MALLOC(BMPSize);
if (BMPdata==NULL) // No mem for BMP file
{
FREE(psInfoHeader);
FREE(psFileHeader);
return FALSE;
}
psInfoHeader->headerSize=40; // Windows format bmp
psInfoHeader->width=Width;
psInfoHeader->height=Height;
psInfoHeader->planes=1;
psInfoHeader->bitCount=(UWORD)BitCount; // Bits per pixel - only 8 (256colours) is currently supported
psInfoHeader->compression=0; // Compression not supported
psInfoHeader->sizeImage=0;
psInfoHeader->xPelsPerMeter=1; // err...
psInfoHeader->yPelsPerMeter=1; // err...
psInfoHeader->coloursUsed=PALCOUNT;
psInfoHeader->coloursImportant=PALCOUNT;
psFileHeader->size=BMPSize;
psFileHeader->reserved1=0;
psFileHeader->reserved2=0;
psFileHeader->offset=2 + sizeof(BMP_FILEHEADER) + sizeof(BMP_INFOHEADER);
if (BitCount==8)
{
psFileHeader->offset+=(PALCOUNT*4);
}
// Fill out mem
*((UWORD *)BMPdata) = 0x4d42;
memcpy(BMPdata+2,psFileHeader,sizeof(BMP_FILEHEADER));
memcpy(BMPdata+2+sizeof(BMP_FILEHEADER),psInfoHeader,sizeof(BMP_INFOHEADER));
memcpy(BMPdata+2+sizeof(BMP_FILEHEADER),psInfoHeader,sizeof(BMP_INFOHEADER));
DataPointer = BMPdata+2+sizeof(BMP_FILEHEADER)+sizeof(BMP_INFOHEADER);
if (BitCount==8)
{
// Copy 'dat palette into 'da memory buffer
for (PalEntry=0;PalEntry<PALCOUNT;PalEntry++)
{
*(DataPointer++) = pPaletteData[PalEntry].peBlue;
*(DataPointer++) = pPaletteData[PalEntry].peGreen;
*(DataPointer++) = pPaletteData[PalEntry].peRed;
*(DataPointer++)=0;
}
}
// Copy the image inverted (why are bmp files inverted?)
for (Ycoord=Height-1;Ycoord>=0;Ycoord--)
{
ImagePointer= pImageData+(Ycoord*Width*(BitCount/8));
memcpy(DataPointer,ImagePointer,Width*(BitCount/8));
DataPointer+=(Width*(BitCount/8));
}
*ppBMPFile=BMPdata;
*fileSize=BMPSize;
FREE(psInfoHeader);
FREE(psFileHeader);
return TRUE;
}
#endif

View File

@ -1,55 +0,0 @@
/*
* Image.h
*
* Prototypes for the image file parsing routines
*/
#ifndef _image_h
#define _image_h
/* Check the header files have been included from frame.h if they
* are used outside of the framework library.
*/
#if !defined(_frame_h) && !defined(FRAME_LIB_INCLUDE)
#error Framework header files MUST be included from Frame.h ONLY.
#endif
/* Take a memory buffer that contains a PCX file and convert it
* to an image buffer and a palette buffer.
* If the returned palette pointer is NULL a true colour PCX has
* been loaded. In this case the image data will be 32 bit true colour.
*/
extern BOOL imageParsePCX(UBYTE *pFileData, // Original file
UDWORD fileSize, // File size
UDWORD *pWidth, // Image width
UDWORD *pHeight, // Image height
UBYTE **ppImageData, // Image data from file
PALETTEENTRY **ppsPalette); // Palette data from file
/* Take a memory buffer that contains a BMP file and convert it
* to an image buffer and a palette buffer.
* If the returned palette pointer is NULL a true colour BMP has
* been loaded. In this case the image data will be 32 bit true colour.
*/
extern BOOL imageParseBMP(UBYTE *pFileData, // Original file
UDWORD fileSize, // File size
UDWORD *pWidth, // Image width
UDWORD *pHeight, // Image height
UBYTE **ppImageData, // Image data from file
PALETTEENTRY **ppsPalette); // Palette data from file
/* Take a memory buffer that contains a image buffer and convert it
* to a BMP file.
*/
extern BOOL imageCreateBMP(UBYTE *pImageData, // Original file
PALETTEENTRY *pPaletteData, // Palette data
UDWORD Width, // Image width
UDWORD Height, // Image height
UBYTE **ppBMPFile, // Image data from file
UDWORD *fileSize); // Generated BMP File size
#endif

View File

@ -1,219 +0,0 @@
/*
* Input.h
*
* Prototypes for the keyboard and mouse input funcitons.
*/
#ifndef _input_h
#define _input_h
/* Check the header files have been included from frame.h if they
* are used outside of the framework library.
*/
#if !defined(_frame_h) && !defined(FRAME_LIB_INCLUDE)
#error Framework header files MUST be included from Frame.h ONLY.
#endif
#include <SDL/SDL.h>
#include "types.h"
/* The defines for all the key codes */
typedef enum _key_code
{
KEY_ESC =SDLK_ESCAPE,
KEY_1 =SDLK_1,
KEY_2 =SDLK_2,
KEY_3 =SDLK_3,
KEY_4 =SDLK_4,
KEY_5 =SDLK_5,
KEY_6 =SDLK_6,
KEY_7 =SDLK_7,
KEY_8 =SDLK_8,
KEY_9 =SDLK_9,
KEY_0 =SDLK_0,
KEY_MINUS =SDLK_MINUS,
KEY_EQUALS =SDLK_EQUALS,
KEY_BACKSPACE =SDLK_BACKSPACE,
KEY_TAB =SDLK_TAB,
KEY_Q =SDLK_q,
KEY_W =SDLK_w,
KEY_E =SDLK_e,
KEY_R =SDLK_r,
KEY_T =SDLK_t,
KEY_Y =SDLK_y,
KEY_U =SDLK_u,
KEY_I =SDLK_i,
KEY_O =SDLK_o,
KEY_P =SDLK_p,
KEY_LBRACE =SDLK_LEFTBRACKET,
KEY_RBRACE =SDLK_RIGHTBRACKET,
KEY_RETURN =SDLK_RETURN,
KEY_LCTRL =SDLK_LCTRL,
KEY_A =SDLK_a,
KEY_S =SDLK_s,
KEY_D =SDLK_d,
KEY_F =SDLK_f,
KEY_G =SDLK_g,
KEY_H =SDLK_h,
KEY_J =SDLK_j,
KEY_K =SDLK_k,
KEY_L =SDLK_l,
KEY_SEMICOLON =SDLK_SEMICOLON,
KEY_QUOTE =SDLK_QUOTE,
KEY_BACKQUOTE =SDLK_BACKQUOTE,
KEY_LSHIFT =SDLK_LSHIFT,
KEY_BACKSLASH =SDLK_BACKSLASH,
KEY_Z =SDLK_z,
KEY_X =SDLK_x,
KEY_C =SDLK_c,
KEY_V =SDLK_v,
KEY_B =SDLK_b,
KEY_N =SDLK_n,
KEY_M =SDLK_m,
KEY_COMMA =SDLK_COMMA,
KEY_FULLSTOP =SDLK_PERIOD,
KEY_FORWARDSLASH =SDLK_SLASH,
KEY_RSHIFT =SDLK_RSHIFT,
KEY_KP_STAR =SDLK_KP_MULTIPLY,
KEY_LALT =SDLK_LALT,
KEY_SPACE =SDLK_SPACE,
KEY_CAPSLOCK =SDLK_CAPSLOCK,
KEY_F1 =SDLK_F1,
KEY_F2 =SDLK_F2,
KEY_F3 =SDLK_F3,
KEY_F4 =SDLK_F4,
KEY_F5 =SDLK_F5,
KEY_F6 =SDLK_F6,
KEY_F7 =SDLK_F7,
KEY_F8 =SDLK_F8,
KEY_F9 =SDLK_F9,
KEY_F10 =SDLK_F10,
KEY_NUMLOCK =SDLK_NUMLOCK,
KEY_SCROLLLOCK =SDLK_SCROLLOCK,
KEY_KP_7 =SDLK_KP7,
KEY_KP_8 =SDLK_KP8,
KEY_KP_9 =SDLK_KP9,
KEY_KP_MINUS =SDLK_KP_MINUS,
KEY_KP_4 =SDLK_KP4,
KEY_KP_5 =SDLK_KP5,
KEY_KP_6 =SDLK_KP6,
KEY_KP_PLUS =SDLK_KP_PLUS,
KEY_KP_1 =SDLK_KP1,
KEY_KP_2 =SDLK_KP2,
KEY_KP_3 =SDLK_KP3,
KEY_KP_0 =SDLK_KP0,
KEY_KP_FULLSTOP =SDLK_KP_PERIOD,
KEY_F11 =SDLK_F11,
KEY_F12 =SDLK_F12,
KEY_RCTRL =SDLK_RCTRL,
KEY_KP_BACKSLASH =SDLK_KP_DIVIDE,
KEY_RALT =SDLK_RALT,
KEY_HOME =SDLK_HOME,
KEY_UPARROW =SDLK_UP,
KEY_PAGEUP =SDLK_PAGEUP,
KEY_LEFTARROW =SDLK_LEFT,
KEY_RIGHTARROW =SDLK_RIGHT,
KEY_END =SDLK_END,
KEY_DOWNARROW =SDLK_DOWN,
KEY_PAGEDOWN =SDLK_PAGEDOWN,
KEY_INSERT =SDLK_INSERT,
KEY_DELETE =SDLK_DELETE,
KEY_KPENTER =SDLK_KP_ENTER
} KEY_CODE;
/* The largest possible scan code (probably a lot less than this but ...) */
// but ... it's not as if it's got to fit into 2meg of mem or anything is it ...
#define KEY_MAXSCAN SDLK_LAST
extern void inputProcessEvent(SDL_Event *event);
/* Converts the key code into an ascii string */
extern void keyScanToString(KEY_CODE code, STRING *ascii, UDWORD maxStringSize);
/* Initialise the input module */
extern void inputInitialise(void);
/* Add a key press to the key buffer */
extern void inputAddBuffer(UDWORD code, char char_code, UDWORD count);
/* This returns true if the key is currently depressed */
extern BOOL keyDown(KEY_CODE code);
/* This returns true if the key went from being up to being down this frame */
extern BOOL keyPressed(KEY_CODE code);
/* This returns true if the key went from being down to being up this frame */
extern BOOL keyReleased(KEY_CODE code);
typedef enum _mouse_key_code
{
MOUSE_LMB,
MOUSE_MMB,
MOUSE_RMB
} MOUSE_KEY_CODE;
/* These two functions return the current position of the mouse */
extern SDWORD mouseX(void);
extern SDWORD mouseY(void);
extern BOOL mouseWheelForward( void);
extern BOOL mouseWheelBackwards( void);
extern BOOL mouseWheelStatic( void);
extern void mouseWheelProcessed(void);
/* This returns true if the mouse key is currently depressed */
extern BOOL mouseDown(MOUSE_KEY_CODE code);
/* This returns true if the mouse key was double clicked */
extern BOOL mouseDClicked(MOUSE_KEY_CODE code);
/* This returns true if the mouse key went from being up to being down this frame */
extern BOOL mousePressed(MOUSE_KEY_CODE code);
/* This returns true if the mouse key went from being down to being up this frame */
extern BOOL mouseReleased(MOUSE_KEY_CODE code);
/* Check for a mouse drag, return the drag start coords if dragging */
extern BOOL mouseDrag(MOUSE_KEY_CODE code, UDWORD *px, UDWORD *py);
/* Warps the mouse to the given position */
extern void SetMousePos(UDWORD nowt,UDWORD x,UDWORD y);
/* Sets the state of the mouse key to down */
extern void setMouseDown(MOUSE_KEY_CODE code);
/* Sets the state of the mouse key to up */
extern void setMouseUp(MOUSE_KEY_CODE code);
/* The input buffer can contain normal character codes and these control codes */
#define INPBUF_LEFT 0x010000
#define INPBUF_RIGHT 0x020000
#define INPBUF_UP 0x030000
#define INPBUF_DOWN 0x040000
#define INPBUF_HOME 0x050000
#define INPBUF_END 0x060000
#define INPBUF_INS 0x070000
#define INPBUF_DEL 0x080000
#define INPBUF_PGUP 0x090000
#define INPBUF_PGDN 0x0a0000
/* Some defines for keys that map into the normal character space */
#define INPBUF_BKSPACE 0x000008
#define INPBUF_TAB 0x000009
#define INPBUF_CR 0x00000D
#define INPBUF_ESC 0x00001b
/* Return the next key press or 0 if no key in the buffer.
* The key returned will have been remaped to the correct ascii code for the
* windows key map.
* All key presses are buffered up (including windows auto repeat).
*/
extern UDWORD inputGetKey(void);
extern char inputGetCharKey(void);
/* Clear the input buffer */
extern void inputClearBuffer(void);
#endif

View File

@ -1,654 +0,0 @@
/*
* Input.c
*
* Processes all keyboard and mouse input.
*
*/
#include <stdio.h>
#include <SDL/SDL.h>
/* Allow frame header files to be singly included */
#define FRAME_LIB_INCLUDE
/* The input buffer printf's */
//#define DEBUG_GROUP1
#include "types.h"
#include "debug.h"
#include "input.h"
#include "fractions.h"
#include "frame.h"
#include "frameint.h"
#include "configfile.h"
/* The possible states for keys */
typedef enum _key_state
{
KEY_UP,
KEY_PRESSED,
KEY_DOWN,
KEY_RELEASED,
KEY_PRESSRELEASE, // When a key goes up and down in a frame
KEY_DOUBLECLICK, // Only used by mouse keys
KEY_DRAG, // Only used by mouse keys
} KEY_STATE;
/* The current state of the keyboard */
static KEY_STATE aKeyState[KEY_MAXSCAN];
/* Mouse wheel stuff */
//static UDWORD oldWheelPos = 0;
static BOOL bMouseWheelForward = FALSE;
static BOOL bMouseWheelBackwards = FALSE;
static BOOL bMouseWheelStatic = TRUE;
/* The current location of the mouse */
static SDWORD mouseXPos, mouseYPos;
/* How far the mouse has to move to start a drag */
#define DRAG_THRESHOLD 5
/* Which button is being used for a drag */
static MOUSE_KEY_CODE dragKey;
/* The start of a possible drag by the mouse */
static SDWORD dragX, dragY;
/* The current mouse button state */
static KEY_STATE aMouseState[3];
/* The size of the input buffer */
#define INPUT_MAXSTR 512
/* The input string buffer */
static UDWORD pInputBuffer[INPUT_MAXSTR];
static UDWORD *pStartBuffer, *pEndBuffer;
static char pCharInputBuffer[INPUT_MAXSTR];
static char *pCharStartBuffer, *pCharEndBuffer;
static char currentChar;
static KEY_CODE sdlKeyToKeyCode(SDLKey key)
{
return (KEY_CODE)key;
}
static SDLKey keyCodeToSDLKey(KEY_CODE code)
{
return (SDLKey)code;
}
void keyScanToString(KEY_CODE code, STRING *ascii, UDWORD maxStringSize)
{
if(code == KEY_MAXSCAN)
{
strcpy(ascii,"???");
return;
}
ASSERT(((code >= 0) && (code <= KEY_MAXSCAN), "Invalid key code: %d", code));
#ifndef _MSC_VER
snprintf(ascii, maxStringSize, "%s", SDL_GetKeyName(keyCodeToSDLKey(code)));
#else
_snprintf(ascii, maxStringSize, "%s", SDL_GetKeyName(keyCodeToSDLKey(code)));
// sprintf(ascii,"%s",SDL_GetKeyName(keyCodeToSDLKey(code))); //temp
#endif //use _snprintf() in _MSC_VER --Q
}
/* Initialise the input module */
void inputInitialise(void)
{
UDWORD i;
for(i=0; i<KEY_MAXSCAN; i++)
{
aKeyState[i] = KEY_UP;
}
for (i=0; i<3; i++)
{
aMouseState[i] = KEY_UP;
}
pStartBuffer = pInputBuffer;
pEndBuffer = pInputBuffer;
pCharStartBuffer = pCharInputBuffer;
pCharEndBuffer = pCharInputBuffer;
dragX = mouseXPos = screenWidth/2;
dragY = mouseYPos = screenHeight/2;
dragKey = MOUSE_LMB;
SDL_EnableUNICODE(1);
}
/* add count copies of the characater code to the input buffer */
void inputAddBuffer(UDWORD code, char char_code, UDWORD count)
{
UDWORD *pNext;
char *pCharNext;
/* Calculate what pEndBuffer will be set to next */
pNext = pEndBuffer + 1;
pCharNext = pCharEndBuffer + 1;
if (pNext >= pInputBuffer + INPUT_MAXSTR)
{
pNext = pInputBuffer;
pCharNext = pCharInputBuffer;
}
while (pNext != pStartBuffer && count > 0)
{
/* Store the character */
*pEndBuffer = code;
*pCharEndBuffer = char_code;
pEndBuffer = pNext;
pCharEndBuffer = pCharNext;
count -= 1;
/* Calculate what pEndBuffer will be set to next */
pNext = pEndBuffer + 1;
pCharNext = pCharEndBuffer + 1;
if (pNext >= pInputBuffer + INPUT_MAXSTR)
{
pNext = pInputBuffer;
pCharNext = pCharInputBuffer;
}
}
}
/* Clear the input buffer */
void inputClearBuffer(void)
{
pStartBuffer = pInputBuffer;
pEndBuffer = pInputBuffer;
pCharStartBuffer = pCharInputBuffer;
pCharEndBuffer = pCharInputBuffer;
}
/* Return the next key press or 0 if no key in the buffer.
* The key returned will have been remaped to the correct ascii code for the
* windows key map.
* All key presses are buffered up (including windows auto repeat).
*/
UDWORD inputGetKey(void)
{
UDWORD retVal;
if (pStartBuffer != pEndBuffer)
{
retVal = *pStartBuffer;
currentChar = *pCharStartBuffer;
pStartBuffer += 1;
pCharStartBuffer += 1;
if (pStartBuffer >= pInputBuffer + INPUT_MAXSTR)
{
pStartBuffer = pInputBuffer;
pCharStartBuffer = pCharInputBuffer;
}
}
else
{
retVal = 0;
}
return retVal;
}
char inputGetCharKey(void) {
return currentChar;
}
/* Deal with windows messages to maintain the state of the keyboard and mouse */
void inputProcessEvent(SDL_Event *event)
{
UDWORD code,i, vk;
// FRACT divX,divY;
// UDWORD scrX,scrY;
switch(event->type)
{
case SDL_KEYDOWN:
//printf("keydown %s (%i)\n", SDL_GetKeyName(code), event->key.keysym.sym);
switch (event->key.keysym.sym)
{
case SDLK_LEFT:
vk = INPBUF_LEFT;
break;
case SDLK_RIGHT:
vk = INPBUF_RIGHT;
break;
case SDLK_UP:
vk = INPBUF_UP;
break;
case SDLK_DOWN:
vk = INPBUF_DOWN;
break;
case SDLK_HOME:
vk = INPBUF_HOME;
break;
case SDLK_END:
vk = INPBUF_END;
break;
case SDLK_INSERT:
vk = INPBUF_INS;
break;
case SDLK_DELETE:
vk = INPBUF_DEL;
break;
case SDLK_PAGEUP:
vk = INPBUF_PGUP;
break;
case SDLK_PAGEDOWN:
vk = INPBUF_PGDN;
break;
default:
vk = event->key.keysym.sym;
break;
}
{
DBP1(("Code: %x\n", vk)) //This breaks with .NET, [DBP1(("Code: %x\n", vk));]it don't want the ; at end. --Qamly
unsigned char char_code = event->key.keysym.unicode;
if (char_code < 32) {
char_code = 0;
}
inputAddBuffer(vk, char_code, 1);
}
code = sdlKeyToKeyCode(event->key.keysym.sym);
if ((aKeyState[code] == KEY_UP) ||
(aKeyState[code] == KEY_RELEASED) ||
(aKeyState[code] == KEY_PRESSRELEASE))
{
aKeyState[code] = KEY_PRESSED;
}
break;
case SDL_KEYUP:
code = sdlKeyToKeyCode(event->key.keysym.sym);
if (aKeyState[code] == KEY_PRESSED)
{
aKeyState[code] = KEY_PRESSRELEASE;
}
else if (aKeyState[code] == KEY_DOWN)
{
aKeyState[code] = KEY_RELEASED;
}
break;
/* Deal with mouse messages */
case SDL_MOUSEMOTION:
if(!mouseDown(MOUSE_MMB))
{
/* store the current mouse position */
mouseXPos = event->motion.x;
mouseYPos = event->motion.y;
/*
if(mouseXPos>=screenWidth)
{
mouseXPos = screenWidth-1;
}
if(mouseYPos >= screenHeight)
{
mouseYPos = screenHeight-1;
}
*/
/* now see if a drag has started */
if ((aMouseState[dragKey] == KEY_PRESSED ||
aMouseState[dragKey] == KEY_DOWN) &&
(ABSDIF(dragX,mouseXPos) > DRAG_THRESHOLD ||
ABSDIF(dragY,mouseYPos) > DRAG_THRESHOLD))
{
// DBPRINTF(("dragging\n"));
aMouseState[dragKey] = KEY_DRAG;
}
}
break;
case SDL_MOUSEBUTTONUP:
if (event->button.button == SDL_BUTTON_LEFT)
{
if (aMouseState[MOUSE_LMB] == KEY_PRESSED)
{
aMouseState[MOUSE_LMB] = KEY_PRESSRELEASE;
}
else if (aMouseState[MOUSE_LMB] == KEY_DOWN ||
aMouseState[MOUSE_LMB] == KEY_DRAG)
{
aMouseState[MOUSE_LMB] = KEY_RELEASED;
}
}
if (event->button.button == SDL_BUTTON_RIGHT)
{
if (aMouseState[MOUSE_RMB] == KEY_PRESSED)
{
aMouseState[MOUSE_RMB] = KEY_PRESSRELEASE;
}
else if (aMouseState[MOUSE_RMB] == KEY_DOWN ||
aMouseState[MOUSE_RMB] == KEY_DRAG)
{
aMouseState[MOUSE_RMB] = KEY_RELEASED;
}
}
if (event->button.button == SDL_BUTTON_MIDDLE)
{
if (aMouseState[MOUSE_MMB] == KEY_PRESSED)
{
aMouseState[MOUSE_MMB] = KEY_PRESSRELEASE;
}
else if (aMouseState[MOUSE_MMB] == KEY_DOWN ||
aMouseState[MOUSE_MMB] == KEY_DRAG)
{
aMouseState[MOUSE_MMB] = KEY_RELEASED;
}
}
break;
case SDL_MOUSEBUTTONDOWN:
if (event->button.button == SDL_BUTTON_LEFT)
{
if ((aMouseState[MOUSE_LMB] == KEY_UP) ||
(aMouseState[MOUSE_LMB] == KEY_RELEASED) ||
(aMouseState[MOUSE_LMB] == KEY_PRESSRELEASE))
{
aMouseState[MOUSE_LMB] = KEY_PRESSED;
dragKey = MOUSE_LMB;
dragX = mouseXPos;
dragY = mouseYPos;
}
}
// TODO: double click
if (event->button.button == SDL_BUTTON_RIGHT)
{
if ((aMouseState[MOUSE_RMB] == KEY_UP) ||
(aMouseState[MOUSE_RMB] == KEY_RELEASED) ||
(aMouseState[MOUSE_RMB] == KEY_PRESSRELEASE))
{
aMouseState[MOUSE_RMB] = KEY_PRESSED;
dragKey = MOUSE_RMB;
dragX = mouseXPos;
dragY = mouseYPos;
}
}
// TODO: double click
if (event->button.button == SDL_BUTTON_MIDDLE)
{
if ((aMouseState[MOUSE_MMB] == KEY_UP) ||
(aMouseState[MOUSE_MMB] == KEY_RELEASED) ||
(aMouseState[MOUSE_MMB] == KEY_PRESSRELEASE))
{
aMouseState[MOUSE_MMB] = KEY_PRESSED;
dragKey = MOUSE_MMB;
dragX = mouseXPos;
dragY = mouseYPos;
}
}
// TODO: double click
if (event->button.button == SDL_BUTTON_WHEELUP)
{
bMouseWheelForward = TRUE;
}
if (event->button.button == SDL_BUTTON_WHEELDOWN)
{
bMouseWheelBackwards = TRUE;
}
break;
case SDL_ACTIVEEVENT:
/* Lost the window focus, have to take this as a global key up */
for(i=0; i<KEY_MAXSCAN; i++)
{
if ((aKeyState[i] == KEY_PRESSED) ||
(aKeyState[i] == KEY_DOWN))
{
aKeyState[i] = KEY_RELEASED;
}
}
for (i=0; i<3; i++)
{
if ((aMouseState[i] == KEY_PRESSED) ||
(aMouseState[i] == KEY_DOWN) ||
(aMouseState[i] == KEY_DRAG))
{
aMouseState[i] = KEY_RELEASED;
}
}
break;
}
}
/* This is called once a frame so that the system can tell
* whether a key was pressed this turn or held down from the last frame.
*/
void inputNewFrame(void)
{
UDWORD i;
/* Do the keyboard */
for (i=0; i< KEY_MAXSCAN; i++)
{
if (aKeyState[i] == KEY_PRESSED)
{
aKeyState[i] = KEY_DOWN;
}
else if ((aKeyState[i] == KEY_RELEASED) ||
(aKeyState[i] == KEY_PRESSRELEASE))
{
aKeyState[i] = KEY_UP;
}
}
/* Do the mouse */
for(i=0; i<3; i++)
{
if (aMouseState[i] == KEY_PRESSED)
{
aMouseState[i] = KEY_DOWN;
}
else if ((aMouseState[i] == KEY_RELEASED) ||
(aMouseState[i] == KEY_DOUBLECLICK) ||
(aMouseState[i] == KEY_PRESSRELEASE))
{
aMouseState[i] = KEY_UP;
}
}
}
/* This returns true if the key is currently depressed */
BOOL keyDown(KEY_CODE code)
{
ASSERT(((code >= 0) && (code < KEY_MAXSCAN), "Invalid key code: %d", code));
return (aKeyState[code] != KEY_UP);
}
/* This returns true if the key went from being up to being down this frame */
BOOL keyPressed(KEY_CODE code)
{
ASSERT(((code >= 0) && (code < KEY_MAXSCAN), "Invalid key code: %d", code));
return ((aKeyState[code] == KEY_PRESSED) || (aKeyState[code] == KEY_PRESSRELEASE));
}
/* This returns true if the key went from being down to being up this frame */
BOOL keyReleased(KEY_CODE code)
{
ASSERT(((code >= 0) && (code < KEY_MAXSCAN), "Invalid key code: %d", code));
return ((aKeyState[code] == KEY_RELEASED) || (aKeyState[code] == KEY_PRESSRELEASE));
}
/* Return the X coordinate of the mouse */
SDWORD mouseX(void)
{
return mouseXPos;
}
/* Return the Y coordinate of the mouse */
SDWORD mouseY(void)
{
return mouseYPos;
}
/* The next three are mutually exclusive */
/* True if mouse wheel moved forward in last frame */
BOOL mouseWheelForward( void)
{
return(bMouseWheelForward);
}
/* True if mouse wheel moved backwards in last frame */
BOOL mouseWheelBackwards( void)
{
return(bMouseWheelBackwards);
}
/* True if mouse wheel remained still in last frame */
BOOL mouseWheelStatic( void)
{
return(bMouseWheelStatic);
}
/* Reset bMouseWheelForward and bMouseWheelBackwards */
void mouseWheelProcessed(void)
{
bMouseWheelForward = FALSE;
bMouseWheelBackwards = FALSE;
}
/* This returns true if the mouse key is currently depressed */
BOOL mouseDown(MOUSE_KEY_CODE code)
{
ASSERT(((code >= 0) && (code < 3), "Invalid mouse key code: %d", code));
return (aMouseState[code] != KEY_UP);
}
/* This returns true if the mouse key was double clicked */
BOOL mouseDClicked(MOUSE_KEY_CODE code)
{
ASSERT(((code >= 0) && (code < 3), "Invalid mouse key code: %d", code));
return (aMouseState[code] == KEY_DOUBLECLICK);
}
/* This returns true if the mouse key went from being up to being down this frame */
BOOL mousePressed(MOUSE_KEY_CODE code)
{
ASSERT(((code >= 0) && (code < 3), "Invalid mouse key code: %d", code));
return ((aMouseState[code] == KEY_PRESSED) ||
(aMouseState[code] == KEY_PRESSRELEASE));
}
/* This returns true if the mouse key went from being down to being up this frame */
BOOL mouseReleased(MOUSE_KEY_CODE code)
{
ASSERT(((code >= 0) && (code < 3), "Invalid mouse key code: %d", code));
return ((aMouseState[code] == KEY_RELEASED) ||
(aMouseState[code] == KEY_DOUBLECLICK) ||
(aMouseState[code] == KEY_PRESSRELEASE));
}
/* Check for a mouse drag, return the drag start coords if dragging */
BOOL mouseDrag(MOUSE_KEY_CODE code, UDWORD *px, UDWORD *py)
{
ASSERT(((code >= 0) && (code < 3), "Invalid mouse key code: %d", code));
if (aMouseState[code] == KEY_DRAG)
{
*px = dragX;
*py = dragY;
return TRUE;
}
return FALSE;
}
void SetMousePos(UDWORD nowt,UDWORD x,UDWORD y)
{
static int mousewarp = -1;
if (mousewarp == -1) {
int val;
mousewarp = 1;
if (getWarzoneKeyNumeric("nomousewarp", &val)) {
if (val) {
mousewarp = 0;
}
}
}
if (mousewarp) SDL_WarpMouse(x, y);
}
/* Sets the state of the mouse key to down */
void setMouseDown(MOUSE_KEY_CODE code)
{
Uint8 button;
SDL_Event event;
switch(code)
{
case MOUSE_LMB:
button = SDL_BUTTON_LEFT;
break;
case MOUSE_MMB:
button = SDL_BUTTON_MIDDLE;
break;
case MOUSE_RMB:
button = SDL_BUTTON_RIGHT;
break;
default:
button = SDL_BUTTON_LEFT;
break;
}
event.type = SDL_MOUSEBUTTONDOWN;
event.button.type = SDL_MOUSEBUTTONDOWN;
event.button.button = button;
event.button.state = SDL_PRESSED;
event.button.x = mouseX();
event.button.y = mouseY();
SDL_PushEvent(&event);
}
/* Sets the state of the mouse key to up */
void setMouseUp(MOUSE_KEY_CODE code)
{
Uint8 button;
SDL_Event event;
switch(code)
{
case MOUSE_LMB:
button = SDL_BUTTON_LEFT;
break;
case MOUSE_MMB:
button = SDL_BUTTON_MIDDLE;
break;
case MOUSE_RMB:
button = SDL_BUTTON_RIGHT;
break;
default:
button = SDL_BUTTON_LEFT;
break;
}
event.type = SDL_MOUSEBUTTONUP;
event.button.type = SDL_MOUSEBUTTONUP;
event.button.button = button;
event.button.state = SDL_RELEASED;
event.button.x = mouseX();
event.button.y = mouseY();
SDL_PushEvent(&event);
}

View File

@ -1,71 +0,0 @@
/*
* ListMacs.h
*
* Macros for some simple list operations
*
* The parameters for the macros are :
*
* psHead the pointer to the start of the list
* psEntry the pointer to the list entry
* TYPE the type of the list structure (not a pointer to it)
*
*/
#ifndef _listmacs_h
#define _listmacs_h
// initialise a list
#define LIST_INIT(psHead) psHead = NULL
// add an entry to the start of a list
#define LIST_ADD(psHead, psEntry) \
(psEntry)->psNext = (psHead); \
(psHead) = (psEntry)
// add an entry to a list
#define LIST_ADDEND(psHead, psEntry, TYPE) \
{ \
TYPE *psPrev, *psCurr; \
\
psPrev = NULL; \
for(psCurr = (psHead); psCurr; psCurr = psCurr->psNext) \
{ \
psPrev = psCurr; \
} \
if (psPrev) \
{ \
psPrev->psNext = (psEntry); \
} \
else \
{ \
(psEntry)->psNext = NULL; \
(psHead) = (psEntry); \
} \
}
// remove an entry from a list
#define LIST_REMOVE(psHead, psEntry, TYPE) \
{ \
TYPE *psPrev, *psCurr; \
\
psPrev = NULL; \
for(psCurr = (psHead); psCurr; psCurr = psCurr->psNext) \
{ \
if (psCurr == (psEntry)) \
{ \
break; \
} \
psPrev = psCurr; \
} \
ASSERT((psCurr!=NULL, "LIST_REMOVE: " __FILE__ "(%d): entry not found", __LINE__)); \
if (psPrev == NULL) \
{ \
(psHead) = (psHead)->psNext; \
} \
else if (psCurr != NULL) \
{ \
psPrev->psNext = psCurr->psNext; \
} \
}
#endif

View File

@ -1,516 +0,0 @@
/*
* mem.c
*
* Replacements for malloc and free to track memory usage.
*
* Also allows pointer validity checking.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Allow frame header files to be singly included */
#define FRAME_LIB_INCLUDE
#include "types.h"
#include "mem.h"
#include "debug.h"
#include "heap.h"
#include "treap.h"
#include "treapint.h"
#include "memint.h"
#include "block.h"
#include <assert.h>
/* Whether allocated memory is initialised to a value and whether the memory
* is trashed before it is freed.
* This is done automatically by Visual C's memory routines.
*/
#define MEMORY_SET TRUE
/* Number of bytes after which memory amounts are displayed in Kb */
#define SHOW_KB_LIMIT (0x400)
/* What functions to use for the real malloc and free */
#define RMALLOC malloc
#define RFREE free
/* The root of the memory treap */
static MEM_NODE *psMemRoot = NULL;
/* The current block heap to use instead of MALLOC */
static BLOCK_HEAP *psCurrBlockHeap;
void memMemoryDump(MEM_NODE *Node);
/* Initialise the memory system */
BOOL memInitialise(void)
{
if (psMemRoot != NULL)
{
DBPRINTF(("memInitialise: *** WARNING *** : memory still allocated??\n"));
}
psMemRoot = NULL;
psCurrBlockHeap = NULL;
return TRUE;
}
/* Release the memory treap */
static void memTreapDestroy(TREAP_NODE *psRoot)
{
if (psRoot)
{
// Destroy the sub trees
memTreapDestroy(psRoot->psLeft);
memTreapDestroy(psRoot->psRight);
// Free the root
RFREE(psRoot);
}
}
/* Shutdown the memory system */
void memShutDown(void)
{
// Report any memory still allocated
memMemoryReport(NULL);
// Free up the allocated memory
memTreapDestroy((TREAP_NODE *)psMemRoot);
}
/* Set a block heap to use for all memory allocation rather than standard malloc/free */
void memSetBlockHeap(BLOCK_HEAP *psHeap)
{
psCurrBlockHeap = psHeap;
}
/* Get the current block heap */
BLOCK_HEAP *memGetBlockHeap(void)
{
return psCurrBlockHeap;
}
/* compare two memory blocks
* NOTE: key1 is always the block passed into the treap code
* and therefore not necessarily to be trusted
*/
SDWORD memBlockCmp(UDWORD key1, UDWORD key2)
{
UDWORD start1,start2, end1,end2;
// Calculate the edges of the memory blocks
start1 = (UDWORD)((UBYTE *)((MEM_NODE *)key1)->pObj + sizeof(MEM_NODE)
+ SAFETY_ZONE_SIZE);
start2 = (UDWORD)((UBYTE *)((MEM_NODE *)key2)->pObj + sizeof(MEM_NODE)
+ SAFETY_ZONE_SIZE);
end1 = start1 + ((MEM_NODE *)key1)->size;
end2 = start2 + ((MEM_NODE *)key2)->size;
// see if one block is inside another
if ((start1 >= start2 && end1 <= end2))// || // block 1 inside block 2
// (start2 >= start1 && end2 <= end1)) // block 2 inside block 1
{
return 0;
}
else if (start1 < start2)
{
// less than
return -1;
}
// greater than
return 1;
}
#ifdef DEBUG_MALLOC
/* Replacement for malloc that records where the memory was requested.
* All allocated memory is initialised to INITIALISE_BYTE
* A buffer is also allocated at the top and bottom of the memory to check for
* overwrites.
*/
void *memMalloc(STRING *pFileName, SDWORD LineNumber, size_t Size)
{
void *pMemBase;
MEM_NODE *psNode;
ASSERT(((pFileName != NULL), "No filename passed to mem_Malloc"));
ASSERT((Size != 0, "Cannot allocate 0 bytes of memory."));
if (psCurrBlockHeap != NULL)
{
// use a block heap rather than normal malloc
blkCallPos(pFileName, LineNumber);
return blkAlloc(psCurrBlockHeap, Size);
}
pMemBase = RMALLOC( Size + sizeof(MEM_NODE) + 2 * SAFETY_ZONE_SIZE );
if (!pMemBase)
{
ASSERT((FALSE, "Warning: malloc returning NULL - [%s - %d]",pFileName,LineNumber));
DBPRINTF(("[%s - %d] %d bytes\n",pFileName,LineNumber,Size));
return NULL;
}
/* Got the main bit of memory - set up the node entry */
psNode = (MEM_NODE *)pMemBase;
psNode->pFile = (STRING *)RMALLOC( strlen(pFileName)+1 );
if (!psNode->pFile)
{
RFREE(pMemBase);
DBMB(("Warning: malloc returning NULL"));
return NULL;
}
strcpy(psNode->pFile, pFileName);
psNode->line = LineNumber;
psNode->size = Size;
/* Store the new entry in the memory treap */
psNode->priority = (UDWORD)rand();
psNode->key = (UDWORD)psNode;
psNode->pObj = psNode;
psNode->psLeft = NULL;
psNode->psRight = NULL;
treapAddNode((TREAP_NODE **)&psMemRoot, (TREAP_NODE *)psNode, memBlockCmp);
/* Now initialise the memory - try to catch unitialised variables */
memset((UBYTE *)(pMemBase) + sizeof(MEM_NODE),
SAFETY_ZONE_BYTE, SAFETY_ZONE_SIZE);
memset((UBYTE *)(pMemBase) + sizeof(MEM_NODE) + SAFETY_ZONE_SIZE + Size,
SAFETY_ZONE_BYTE, SAFETY_ZONE_SIZE);
#if MEMORY_SET
/* The PC initialises malloc'ed memory already, no need to do it again */
memset((UBYTE *)(pMemBase) + sizeof(MEM_NODE) + SAFETY_ZONE_SIZE,
INITIALISE_BYTE, Size);
#endif
return ((UBYTE *)(pMemBase) + sizeof(MEM_NODE) + SAFETY_ZONE_SIZE);
}
#endif
/* Replacement for malloc for release builds. */
void *memMallocRelease(size_t Size)
{
if (psCurrBlockHeap != NULL)
{
// use a block heap rather than normal malloc
return blkAlloc(psCurrBlockHeap, Size);
}
return RMALLOC(Size);
}
#ifdef DEBUG_MALLOC
/* Replacement for free
*
* Checks whether the pointer is valid before freeing it.
* If the pointer is invalid, it asserts.
* The buffer zones around the allocated memory are also checked for
* overwrites.
* All memory is reset to FREE_BYTE before freeing to avoid using
* freed memory.
*/
void memFree(STRING *pFileName, SDWORD LineNumber, void *pMemToFree)
{
MEM_NODE sNode, *psDeleted;
SDWORD i, InvalidBottom, InvalidTop;
UBYTE *pMemBase;
BLOCK_HEAP *psBlock;
#if MEMORY_SET
SDWORD Size;
#endif
(void)LineNumber;
(void)pFileName;
ASSERT(((pFileName != NULL), "No filename passed to mem_Free"));
ASSERT(((pMemToFree != NULL), "Attempt to free NULL pointer, called by:\n"
"File: %s\nLine: %d", pFileName, LineNumber));
// see if the pointer was allocated in a block
psBlock = blkFind(pMemToFree);
if (psBlock != NULL)
{
// use a block heap rather than normal free
blkCallPos(pFileName, LineNumber);
blkFree(psBlock, pMemToFree);
return;
}
// Create a dummy node for the search
// This is only looked at by memBlockCmp so only need to set the object and size
sNode.pObj = ((UBYTE *)pMemToFree) - sizeof(MEM_NODE) - SAFETY_ZONE_SIZE;
sNode.size = 1;
/* Get the node for the memory block */
psDeleted = (MEM_NODE *)treapDelRec((TREAP_NODE **)&psMemRoot,
(UDWORD)&sNode, memBlockCmp);
ASSERT((psDeleted != NULL,
"Invalid pointer passed to mem_Free by:\n"
"File: %s\nLine: %d\n\n"
"Attempt to free already freed pointer?",
pFileName, LineNumber));
if (psDeleted)
{
/* The pointer is valid, check the buffer zones */
pMemBase = (UBYTE *)(pMemToFree) - SAFETY_ZONE_SIZE;
InvalidBottom = InvalidTop = 0;
for(i=0; i<SAFETY_ZONE_SIZE; i++)
{
if (pMemBase[i] != SAFETY_ZONE_BYTE)
{
InvalidBottom++;
}
if (pMemBase[i + psDeleted->size + SAFETY_ZONE_SIZE] != SAFETY_ZONE_BYTE)
{
InvalidTop++;
}
}
ASSERT(( !InvalidBottom && !InvalidTop,
"Safety zone on memory overwritten.\n"
"%d Invalid bytes (of %d) found below memory buffer.\n"
"%d Invalid bytes (of %d) found above memory buffer.\n\n"
"Memory allocated by:\nFile: %s\nLine: %d\n"
"Memory freed by:\nFile: %s\nLine: %d\n",
InvalidBottom, SAFETY_ZONE_SIZE, InvalidTop, SAFETY_ZONE_SIZE,
psDeleted->pFile, psDeleted->line,
pFileName, LineNumber));
/* Trash the memory before it is freed (The PC already does this) */
#if MEMORY_SET
Size = psDeleted->size;
memset(pMemToFree, FREE_BYTE, Size);
#endif
/* Now free the memory */
RFREE(psDeleted->pFile);
RFREE(psDeleted);
}
}
#endif
/* Replacement for Free for release builds */
void memFreeRelease(void *pMemToFree)
{
BLOCK_HEAP *psBlock;
// see if the pointer was allocated in a block
psBlock = blkFind(pMemToFree);
if (psBlock != NULL)
{
// use a block heap rather than normal free
blkFree(psBlock, pMemToFree);
return;
}
RFREE(pMemToFree);
}
/* Checks whether the memory buffer pointed to by pPtr of size Size
* is contained in any of the memory blocks allocated.
*/
BOOL memPointerValid(void *pPtr, size_t size)
{
MEM_NODE sNode;
ASSERT((size, "memPointerValid: cannot check a pointer with zero size"));
if (pPtr == NULL)
{
return FALSE;
}
// Create a dummy node for the search
// This is only looked at by memBlockCmp so only need to set the object and size
sNode.pObj = ((UBYTE *)pPtr) - sizeof(MEM_NODE) - SAFETY_ZONE_SIZE;
sNode.size = size;
// See if the block is in the treap
if (treapFindRec((TREAP_NODE *)psMemRoot, (UDWORD)&sNode, memBlockCmp))
{
return TRUE;
}
// check the block heaps as well (if the code is there)
#ifdef DEBUG_BLOCK
return blkPointerValidAll(pPtr, size);
#else
return FALSE;
#endif
}
/* Recursive function to print out the list of memory blocks */
SDWORD memRecReport(MEM_NODE *psRoot)
{
#ifdef DEBUG_MALLOC
if (psRoot)
{
DBPRINTF(("%s, line %d : \t", psRoot->pFile, psRoot->line));
if (psRoot->size < SHOW_KB_LIMIT)
{
DBPRINTF(("%d Bytes\n", psRoot->size));
}
else
{
DBPRINTF(("%d Kb\n", (int)(psRoot->size/1024)));
}
return memRecReport((MEM_NODE *)psRoot->psLeft) +
memRecReport((MEM_NODE *)psRoot->psRight) +
psRoot->size;
}
#endif
return 0;
}
#ifdef DEBUG_MALLOC
#define MAXMODULES (32)
typedef struct
{
char pFile[128];
int Count;
int Total;
} MEMMOD;
static MEMMOD MemModuleInfo[MAXMODULES];
static UDWORD MemTotalEntries;
static UDWORD MemTotalModules;
static UDWORD MemTotalAllocated;
#endif
/* Recursive function to total up the amount of mem allocated */
void memSummary(MEM_NODE *psRoot)
{
#ifdef DEBUG_MALLOC
// bsort
if (psRoot)
{
int i;
BOOL FoundModule;
MemTotalEntries++;
MemTotalAllocated+=psRoot->size;
FoundModule=FALSE;
for (i=0;i<(SDWORD)MemTotalModules;i++)
{
if (strcmp(psRoot->pFile,MemModuleInfo[i].pFile)==0)
{
MemModuleInfo[i].Count++;
MemModuleInfo[i].Total+=psRoot->size;
FoundModule=TRUE;
}
}
if (FoundModule==FALSE)
{
if (MemTotalModules <MAXMODULES)
{
strcpy(MemModuleInfo[MemTotalModules].pFile,psRoot->pFile);
MemModuleInfo[MemTotalModules].Count=1;
MemModuleInfo[MemTotalModules].Total=psRoot->size;
MemTotalModules++;
}
}
memSummary((MEM_NODE *)psRoot->psLeft);
memSummary((MEM_NODE *)psRoot->psRight);
}
return ;
#endif
}
void memMemorySummary(void)
{
memMemoryDump(psMemRoot);
}
void memMemoryDump(MEM_NODE *Node)
{
#ifdef DEBUG_MALLOC
int i;
MemTotalEntries=0;
MemTotalModules=0;
MemTotalAllocated=0;
memSummary(Node);
DBPRINTF(("----------------\nMemory Summary\n%d Bytes allocated in %d handy size chunks\n\n", MemTotalAllocated,MemTotalEntries));
for (i=0;i<(SDWORD)MemTotalModules;i++)
{
DBPRINTF(("%d) [%s] %ld allocations totalling %ld bytes\n",i,MemModuleInfo[i].pFile,MemModuleInfo[i].Count,MemModuleInfo[i].Total));
}
#endif
}
/* Report on currently allocated memory.
* If pFileName is not NULL send the report to the specified file.
* If pFileName is NULL the report goes to DBPRINTF
*/
void memMemoryReport(STRING *pFileName)
{
#ifdef DEBUG_MALLOC
SDWORD TotMem;
DBPRINTF(("\nMemory Allocation Report\n\n"));
if (!psMemRoot)
{
DBPRINTF(("No memory Allocated\n\n"));
}
else
{
TotMem = memRecReport(psMemRoot);
DBPRINTF(("\nTotal memory allocated : "));
if (TotMem < SHOW_KB_LIMIT)
{
DBPRINTF(("%d Bytes\n\n", TotMem));
}
else
{
DBPRINTF(("%d Kb\n\n", (int)(TotMem/1024)));
}
}
#endif
}
/* Display the memory treap */
void memDisplayTreap(STRING *pFileName)
{
#ifdef DEBUG_MALLOC
DBPRINTF(("\nMemory Allocation Treap\n\n"));
treapDisplayRec((TREAP_NODE *)psMemRoot, 0);
#endif
}

View File

@ -1,88 +0,0 @@
/*
* mem.h
*
* Interface to the malloc/free replacements
*/
#ifndef _mem_h
#define _mem_h
#include <stdlib.h>
#include "types.h"
#include "debug.h"
/* DEBUG_MALLOC == TRUE uses debugging malloc and free
DEBUG_MALLOC == FALSE uses normal malloc and free */
#ifdef DEBUG
#define DEBUG_MALLOC TRUE
/* in fast debugging mode turn off heap and pointer valid checking - GJ */
#ifdef DEBUG_FAST
#undef DEBUG_HEAP
#define NO_PTRVALID TRUE
#else
#define DEBUG_HEAP TRUE
#endif
#else
#undef DEBUG_MALLOC
#undef DEBUG_HEAP
#endif
/* Function Prototypes */
/* Initialise the memory system */
extern BOOL memInitialise(void);
/* Shutdown the memory system */
extern void memShutDown(void);
/* Set a block heap to use for all memory allocation rather than standard malloc/free */
struct _block_heap;
extern void memSetBlockHeap(struct _block_heap *psHeap);
/* Get the current block heap */
extern struct _block_heap *memGetBlockHeap(void);
/* malloc replacements */
extern void *memMalloc(STRING *pFileName, SDWORD LineNumber, size_t Size);
extern void *memMallocRelease(size_t Size);
/* free replacements */
extern void memFree(STRING *pFileName, SDWORD LineNumber, void *pMemToFree);
extern void memFreeRelease(void *pMemToFree);
/* Check a pointer refers to a valid block of memory */
extern BOOL memPointerValid(void *pPtr, size_t Size);
/* Report on currently allocated memory */
extern void memMemoryReport(STRING *pFileName);
/* Display the memory treap */
extern void memDisplayTreap(STRING *pFileName);
#if DEBUG_MALLOC
#define MALLOC(size) memMalloc(__FILE__, __LINE__, size)
#define FREE(ptr) { void** p = &(ptr); memFree(__FILE__, __LINE__, *p); *p = NULL; }
#ifndef NO_PTRVALID
#define PTRVALID(ptr, size) memPointerValid(ptr, size)
#else
#define PTRVALID(ptr, size) (((ptr)==NULL)?FALSE:TRUE)
#endif
#define MEMORYREPORT(file) memMemoryReport(file)
#define MEMORYTREAP(file) memDisplayTreap(file)
#else // !DEBUG_MALLOC
#define MALLOC(size) memMallocRelease(size)
#define FREE(ptr) { void** p = (void**)&(ptr); memFreeRelease(*p); *p = NULL; }
#define PTRVALID(ptr, size) (TRUE)
#define MEMORYREPORT(file)
#define MEMORYTREAP(file) memDisplayTreap(file)
#endif // DEBUG_MALLOC
#endif

View File

@ -1,37 +0,0 @@
/*
* MemInt.h
*
* Internal framework definitions for the memory system.
*
*/
#ifndef _memint_h
#define _memint_h
/* The size of saftey buffer to leave before and after any malloc'ed memory.
Can use this to check writing over end of buffers */
#define SAFETY_ZONE_SIZE (32)
/* The character used to initialise malloc'ed memory, or to trash memory before
freeing it */
#define SAFETY_ZONE_BYTE (0xac)
#define INITIALISE_BYTE (0xcd)
#define FREE_BYTE (0xdd)
// memory block header for the treap code
typedef struct _mem_node
{
TREAP_NODE_BASE; // The treap data to store the node
TREAP_NODE_DEBUG; // The debug info for the node (file, line).
UDWORD size; // The memory block size
} MEM_NODE;
/* compare two memory blocks */
extern SDWORD memBlockCmp(UDWORD key1, UDWORD key2);
/* Recursive function to print out the list of memory blocks */
extern SDWORD memRecReport(MEM_NODE *psRoot);
#endif

View File

@ -1,489 +0,0 @@
/*
* Mono.c
*
* Output to the mono screen
*
*/
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
/* Allow frame header files to be singly included */
#define FRAME_LIB_INCLUDE
#include "mono.h"
#include "types.h"
#define MONO_SCREEN_ADDR 0xB0000
#define SLASH_T 0x09 /* tab */
#define SLASH_N 0x0A /* new line */
static void DBug_DumpString(SDWORD, SDWORD, UBYTE *, UBYTE);
static UBYTE DBug_ExpandString(UBYTE *, UBYTE *, UBYTE, va_list, UBYTE);
static UBYTE DBug_CheckFormatChar(UBYTE);
/*
* NAME
* Debug_MONO_ClearRectangle -- clear a rectangular area
*
* SYNOPSIS
* Debug_MONO_ClearRectangle(leftedge, topedge, width, height);
*
* void Debug_MONO_ClearRectangle(UBYTE, UBYTE, UBYTE, UBYTE);
*
* FUNCTION
* This function clears a rectangular area of the monochrome screen defined by
* <leftedge>, <topedge> and with the dimensions of <width> x <height>.
*
*/
void dbg_MONO_ClearRectangle(SDWORD leftedge,
SDWORD topedge,
SDWORD width,
SDWORD height)
{
UBYTE *pub_rectchar,
ub_newwidth, ub_newheight,
ub_i, ub_j,
ub_leftedge, ub_topedge,
ub_width, ub_height;
ub_leftedge = (UBYTE)leftedge;
ub_topedge = (UBYTE)topedge;
ub_width = (UBYTE)width;
ub_height = (UBYTE)height;
/* do some clipping first */
ub_newwidth = ub_width;
ub_newheight = ub_height;
if ((ub_leftedge + ub_width) > MONO_SCREEN_WIDTH)
{
ub_newwidth = MONO_SCREEN_WIDTH - ub_leftedge;
}
if ((ub_topedge + ub_height) > MONO_SCREEN_HEIGHT)
{
ub_newheight = MONO_SCREEN_HEIGHT - ub_topedge;
}
/* see if it's worth doing */
if ((ub_leftedge < MONO_SCREEN_WIDTH) && (ub_topedge < MONO_SCREEN_HEIGHT) && (ub_newwidth > 2) && (ub_newheight > 2))
{
/* get the screen address of the upper-left corner of the box */
pub_rectchar = (UBYTE *)(MONO_SCREEN_ADDR + ((ub_topedge * (MONO_SCREEN_WIDTH * 2)) + (ub_leftedge * 2)));
/* clear the rectangle */
for (ub_i = 0; ub_i < (ub_newheight - 1); ub_i++)
{
for (ub_j = 0; ub_j < (ub_newwidth * 2); ub_j++)
{
*pub_rectchar++ = '\0';
}
/* go to the start of the next line */
pub_rectchar += ((MONO_SCREEN_WIDTH * 2) - (ub_newwidth * 2));
}
}
}
/*
*
* NAME
* Debug_MONO_SClearScreen -- clear the screen
*
* SYNOPSIS
* Debug_MONO_ClearScreen();
*
* void Debug_MONO_ClearScreen(void);
*
* FUNCTION
* This routine clears the entire monochrome screen.
*
*/
void dbg_MONO_ClearScreen(void)
{
memset((char *)MONO_SCREEN_ADDR, '\0', (MONO_SCREEN_WIDTH * 2) * MONO_SCREEN_HEIGHT);
}
/*
*
* NAME
* Debug_MONO_PrintString -- print a formatted string
*
* SYNOPSIS
* Debug_MONO_PrintString(leftedge, topedge, string);
*
* void Debug_MONO_PrintString(UBYTE, UBYTE, UBYTE *, ...);
*
* FUNCTION
* Debug_MONO_PrintString dumps a printf() style NULL-terminated string to the
* monochrome screen at <leftedge>, <topedge>.
*
* To set the attribute, use %a anywhere in the format string followed by an
* attribute byte (defined in debuglib.h) in the argument list. The default
* attribute is MONO_NORMAL.
*
*/
void dbg_MONO_PrintString(SDWORD ub_leftedge,
SDWORD ub_topedge,
SBYTE *pub_formatstring,
...)
{
va_list val_arglist;
UBYTE *pub_formatstringptr,
aub_percentstring[256],
ub_percentstringindex,
aub_currentcharacter[2],
ub_attribute,
aub_expandedstring[256],
ub_numprinted;
BOOL bool_percent,
bool_printchar;
/* initialise the variables */
pub_formatstringptr = (UBYTE*)pub_formatstring;
aub_percentstring[0] = '\0';
ub_percentstringindex = 0;
aub_currentcharacter[1] = '\0';
ub_attribute = MONO_NORMAL;
aub_expandedstring[0] = '\0';
ub_numprinted = 0;
bool_percent = FALSE;
bool_printchar = FALSE;
/* get the first var arg */
va_start(val_arglist, pub_formatstring);
/* is there a format string? */
if (pub_formatstringptr)
{
/* yes, there is a format string; process it */
while (*pub_formatstringptr)
{
/* get the next character */
aub_currentcharacter[0] = *pub_formatstringptr++;
/* is the character a %? */
if (aub_currentcharacter[0] == '%')
{
/* yes, the character is a %; is the percent flag set? */
if (bool_percent == TRUE)
{
/* yes, the percent flag is set; check for a '%%' case */
if (ub_percentstringindex == 1)
{
aub_percentstring[ub_percentstringindex++] = aub_currentcharacter[0];
aub_percentstring[ub_percentstringindex] = '\0';
/* start a new percent string (sort of) */
ub_percentstringindex = 0;
bool_percent = FALSE;
}
/* expand the percent string */
ub_attribute = DBug_ExpandString(&aub_expandedstring[0], &aub_percentstring[0], ub_attribute, val_arglist, ub_numprinted);
/* print the string */
DBug_DumpString(ub_leftedge, ub_topedge, &aub_expandedstring[0], ub_attribute);
ub_leftedge += (UBYTE)strlen((const char*)aub_expandedstring);
ub_numprinted += (UBYTE)strlen((const char*)aub_expandedstring);
/* start a new percent string; don't do this for a '%%' */
if (ub_percentstringindex != 0)
{
ub_percentstringindex = 0;
aub_percentstring[ub_percentstringindex++] = aub_currentcharacter[0];
aub_percentstring[ub_percentstringindex] = '\0';
}
else
{
/* clear the strings after a '%%' */
aub_expandedstring[0] = '\0';
aub_percentstring[0] = '\0';
}
}
else
{
/* no, the percent flag isn't set; set it */
bool_percent = TRUE;
/* start a new percent string */
ub_percentstringindex = 0;
aub_percentstring[ub_percentstringindex++] = aub_currentcharacter[0];
aub_percentstring[ub_percentstringindex] = '\0';
}
}
else
{
/* no, the character isn't a %; is the percent flag set? */
if (bool_percent == TRUE)
{
/* yes, the percent flag is set; put the character in the percent string */
aub_percentstring[ub_percentstringindex++] = aub_currentcharacter[0];
aub_percentstring[ub_percentstringindex] = '\0';
/* is the character a special format character? */
if (DBug_CheckFormatChar(aub_currentcharacter[0]))
{
/* yes, the character is a special format character */
ub_attribute = DBug_ExpandString(aub_expandedstring, aub_percentstring, ub_attribute, val_arglist, ub_numprinted);
/* print the string */
DBug_DumpString(ub_leftedge, ub_topedge, aub_expandedstring, ub_attribute);
ub_leftedge += (UBYTE)strlen((const char*)aub_expandedstring);
ub_numprinted += (UBYTE)strlen((const char*)aub_expandedstring);
/* clear the strings */
ub_percentstringindex = 0;
aub_expandedstring[0] = '\0';
aub_percentstring[0] = '\0';
/* reset the percent flag */
bool_percent = FALSE;
}
}
else
{
/* no, the percent flag isn't set; is the character a special slash character? */
switch (aub_currentcharacter[0])
{
case SLASH_T:
ub_leftedge += (8 - (ub_leftedge % 8));
ub_numprinted += (8 - (ub_leftedge % 8));
bool_printchar = FALSE;
break;
case SLASH_N:
bool_printchar = FALSE;
break;
default:
bool_printchar = TRUE;
break;
}
/* print the character (maybe) */
if (bool_printchar == TRUE)
{
DBug_DumpString(ub_leftedge++, ub_topedge, &aub_currentcharacter[0], ub_attribute);
ub_numprinted++;
}
/* reset the percent flag */
bool_percent = FALSE;
}
}
}
}
/* do one last check for the percent flag; there may be a string not expanded yet */
if (bool_percent == TRUE)
{
/* there is an unxepanded string; expand it */
ub_attribute = DBug_ExpandString(&aub_expandedstring[0], &aub_percentstring[0], ub_attribute, val_arglist, ub_numprinted);
/* print the string */
DBug_DumpString(ub_leftedge, ub_topedge, &aub_expandedstring[0], ub_attribute);
}
/* clean up the var arg handler */
va_end(val_arglist);
}
static void DBug_DumpString(SDWORD ub_leftedge,
SDWORD ub_topedge,
UBYTE *pub_string,
UBYTE ub_attr)
{
UDWORD ul_stringlength,
ul_i;
UBYTE *pub_stringptr,
*pub_screenptr;
/* init the string pointer */
pub_stringptr = pub_string;
/* is there a string? */
if (pub_stringptr != NULL)
{
/* there is; is it worth printing? */
if ((ub_leftedge < MONO_SCREEN_WIDTH) && (ub_topedge < MONO_SCREEN_HEIGHT))
{
/* it is; init the variables */
pub_screenptr = (UBYTE *)(MONO_SCREEN_ADDR + ((ub_topedge * (MONO_SCREEN_WIDTH * 2)) + (ub_leftedge * 2)));
ul_stringlength = strlen((const char*)pub_stringptr);
/* check for clipping */
if ((ub_leftedge + ul_stringlength) > MONO_SCREEN_WIDTH)
{
ul_stringlength = MONO_SCREEN_WIDTH - ub_leftedge;
}
/* yes there is; print it */
for (ul_i = 0; ul_i < ul_stringlength; ul_i++)
{
*pub_screenptr++ = *pub_stringptr++;
*pub_screenptr++ = ub_attr;
}
}
}
}
static UBYTE DBug_ExpandString(UBYTE *pub_stringbuffer,
UBYTE *pub_percentstring,
UBYTE ub_oldattribute,
va_list val_arglist,
UBYTE ub_numprinted)
{
UBYTE ub_percentchar,
ub_newattribute,
ub_stringlength,
*pub_numberchars;
/* init the variables */
ub_newattribute = ub_oldattribute;
/* find the last character */
ub_stringlength = (UBYTE)strlen((const char*)pub_percentstring) - 1;
ub_percentchar = *(pub_percentstring + ub_stringlength);
/* see what it is */
switch (ub_percentchar)
{
case 'a': /* attribute (char) */
printf("Warning (%s:%d): changed char to int, might not work.\n", __FILE__, __LINE__);
ub_newattribute = va_arg(val_arglist, int);
// changed because gcc 4 says it'll crash here
// was ub_newattribute = va_arg(val_arglist, char);
break;
case 'c': /* character */
printf("Warning (%s:%d): changed char to int, might not work.\n", __FILE__, __LINE__);
sprintf((char*)pub_stringbuffer, (const char*)pub_percentstring, va_arg(val_arglist, int));
// changed because gcc 4 says it'll crash here
// was sprintf((char*)pub_stringbuffer, (const char*)pub_percentstring, va_arg(val_arglist, char));
break;
case 'd': /* signed decimal integer */
case 'i': /* signed decimal integer */
case 'u': /* unsigned decimal integers */
case 'o': /* unsigned octal */
sprintf((char*)pub_stringbuffer, (const char*)pub_percentstring, va_arg(val_arglist, int));
break;
case 'e': /* scientific notation (e) */
case 'E': /* scientific notation (E) */
case 'f': /* decimal floating point */
case 'g': /* uses %e or %f, whichever is shorter */
case 'G': /* uses %E or %F, whichever is shorter */
sprintf((char*)pub_stringbuffer, (const char*)pub_percentstring, va_arg(val_arglist, double));
break;
case 'p': /* displays a pointer */
case 's': /* string */
case 'x': /* unsigned hexadecimal (lower case) */
case 'X': /* unsigned hexadecimal (upper case) */
sprintf((char*)pub_stringbuffer, (const char*)pub_percentstring, va_arg(val_arglist, char *));
break;
case 'n': /* how many characters printed so far */
pub_numberchars = (UBYTE*)va_arg(val_arglist, char *);
*pub_numberchars = ub_numprinted;
break;
case '%': /* percent char (no arg) */
sprintf((char*)pub_stringbuffer, "%%");
break;
default: /* unknown conversion character */
break;
}
/* return a (possibly new) attribute */
return (ub_newattribute);
}
static UBYTE DBug_CheckFormatChar(UBYTE ub_percentchar)
{
UBYTE ub_isformatchar;
/* init the variable */
ub_isformatchar = 0;
/* check to see if it's a format character */
switch (ub_percentchar)
{
case 'a': /* attribute (char) */
case 'c': /* character */
case 'd': /* signed decimal integer */
case 'i': /* signed decimal integer */
case 'e': /* scientific notation (e) */
case 'E': /* scientific notation (E) */
case 'f': /* decimal floating point */
case 'g': /* uses %e or %f, whichever is shorter */
case 'G': /* uses %E or %F, whichever is shorter */
case 'o': /* unsigned octal */
case 'p': /* displays a pointer */
case 's': /* string */
case 'u': /* unsigned decimal integers */
case 'x': /* unsigned hexadecimal (lower case) */
case 'X': /* unsigned hexadecimal (upper case) */
case 'n': /* how many characters printed so far */
case '%': /* percent char (no arg) */
ub_isformatchar = 1;
break;
default: /* unknown conversion character */
ub_isformatchar = 0;
break;
}
return (ub_isformatchar);
}

View File

@ -1,53 +0,0 @@
/*
* File: mono.h
*
*/
#ifndef _mono_h
#define _mono_h
/* Check the header files have been included from frame.h if they
* are used outside of the framework library.
*/
#if !defined(_frame_h) && !defined(FRAME_LIB_INCLUDE)
#error Framework header files MUST be included from Frame.h ONLY.
#endif
#include "types.h"
/*
*****************************************************************************************
* monochrome text attributes
*****************************************************************************************
*/
#define MONO_NORMAL (0x07)
#define MONO_BRIGHT (0x0F)
#define MONO_BLINK (0x87)
#define MONO_UNDERLINE (0x01)
#define MONO_BRIGHT_UNDERLINE (0x09)
#define MONO_REVERSED (0x70)
#define MONO_BLINK_REVERSED (0xF0)
/*
*****************************************************************************************
* monochrome screen dimensions
*****************************************************************************************
*/
#define MONO_SCREEN_WIDTH (80)
#define MONO_SCREEN_HEIGHT (25)
/*
*****************************************************************************************
* library function prototypes
*****************************************************************************************
*/
extern void dbg_MONO_ClearRectangle(SDWORD, SDWORD, SDWORD, SDWORD);
extern void dbg_MONO_ClearScreen(void);
extern void dbg_MONO_PrintString(SDWORD, SDWORD, SBYTE *, ...);
/* Tell lint that PrintString takes printf like arguments */
/*lint -printf(3,dbg_MONO_PrintString) */
#endif

View File

@ -1,775 +0,0 @@
/*
* multiWDG.c
*
* Handle multiple wdg files
*
*/
#include "frame.h"
#include "wdg.h"
#include "multiwdg.h"
#ifndef WIN32 /* POSIX directory handling */
# include <sys/types.h>
# include <dirent.h>
#endif
// the list of file catalogs for all the current WDGs
WDGCACHE *psWDGCache;
WDGCACHE *psWDGCacheRev;
// store the additional WDGs when the system is limited to warzone.WDG
WDGCACHE *psWDGCacheStore;
WDGCACHE *psWDGCacheStoreRev;
// static data areas used when loading the WDG catalogs at start up
static WDGINFO WRFCatalog[MAXWRFINWDG]; // static area for the catalog of wrf files in this wdg
static WRFINFO WRFfilesCatalog[MAXFILESINWRF]; // static area for list of files in the current wrf
BOOL wdgLoadCompleteCatalog(char *pWDGName);
#define DISK_ReadPos(filepos,buffer,bytescount,handle) \
(fseek(handle,filepos,SEEK_SET), \
fread(buffer,1,bytescount,handle))
BOOL wdgMultiInit(void)
{
ASSERT((psWDGCache == NULL,
"wdgMultiInit: the WDG cache has not been reset"));
psWDGCache = NULL;
psWDGCacheRev = NULL;
psWDGCacheStore = NULL;
psWDGCacheStoreRev = NULL;
// set the catalogs to the static arrays to load them
WDG_SetCurrentWDGCatalog("", 0, WRFCatalog);
WDG_SetCurrentWRFFileCatalog(0, WRFfilesCatalog);
return TRUE;
}
void wdgMultiShutdown(void)
{
WDGCACHE *psNext;
UDWORD i;
while (psWDGCache != NULL)
{
psNext = psWDGCache->psNext;
// free the file catalogs
for(i=0; i<psWDGCache->numWRF; i++)
{
if(psWDGCache->apsWRFFileCatalog[i])
{
FREE(psWDGCache->apsWRFFileCatalog[i]);
}
}
FREE(psWDGCache->apsWRFFileCatalog);
// free the WRF catalog
FREE(psWDGCache->asWRFCatalog);
FREE(psWDGCache);
psWDGCache = psNext;
}
psWDGCacheRev = NULL;
}
// allow only the original warzone.wdg to be used
void wdgDisableAddonWDG(void)
{
if (psWDGCache == NULL)
{
// no WDG loaded
return;
}
if (strcmp(psWDGCache->aName, "warzone") == 0)
{
// only the main wdg loaded
return;
}
ASSERT(( strcmp(psWDGCacheRev->aName, "warzone") == 0,
"wdgDisableAddonWDG: cannot find warzone.wdg"));
psWDGCacheStore = psWDGCache;
psWDGCacheStoreRev = psWDGCacheRev->psPrev;
psWDGCache = psWDGCacheRev;
psWDGCache->psPrev = NULL;
}
// allow all the wdg to be used
void wdgEnableAddonWDG(void)
{
if (psWDGCacheStore == NULL)
{
// nothing in the store
return;
}
psWDGCache = psWDGCacheStore;
psWDGCacheRev->psPrev = psWDGCacheStoreRev;
psWDGCacheStore = NULL;
psWDGCacheStoreRev = NULL;
}
// check the dependancies of all the WDG
BOOL wdgCheckDependancies(void)
{
WDGCACHE *psCheck, *psSearch;
UDWORD dep, i;
STRING aText[500];
for(psCheck = psWDGCache; psCheck!=NULL; psCheck=psCheck->psNext)
{
for(dep = 0; dep < psCheck->numDep; dep++)
{
for(psSearch=psWDGCache; psSearch!=NULL; psSearch=psSearch->psNext)
{
if ((psSearch->sequence == psCheck->asDep[dep].sequence) &&
(strcmp(psSearch->aName, psCheck->asDep[dep].aName) == 0))
{
break;
}
}
if (psSearch == NULL)
{
sprintf(aText, "%s requires the following .wdg to load:\n\n", psCheck->aFileName);
for(i=0; i<psCheck->numDep; i++)
{
sprintf(aText + strlen(aText), " %s.wdg\n", psCheck->asDep[i].aName);
}
DBERROR((aText));
//return FALSE;
}
}
}
return TRUE;
}
// load all the WDG catalogs
BOOL wdgLoadAllWDGCatalogs(void)
{
#ifdef WIN32
WIN32_FIND_DATA sFindData;
HANDLE hFindHandle;
#else
DIR *dir;
struct dirent *dirent;
char *ptr;
#endif
// set the catalogs to the static arrays to load them
WDG_SetCurrentWDGCatalog("", 0, WRFCatalog);
WDG_SetCurrentWRFFileCatalog(0, WRFfilesCatalog);
#ifdef WIN32
// now load the catalog for every WDG file in the current directory
memset(&sFindData, 0, sizeof(WIN32_FIND_DATA));
hFindHandle = FindFirstFile("*.wdg", &sFindData);
while (hFindHandle != INVALID_HANDLE_VALUE)
{
if (!wdgLoadCompleteCatalog(sFindData.cFileName))
{
return FALSE;
}
if (!FindNextFile(hFindHandle, &sFindData))
{
hFindHandle = INVALID_HANDLE_VALUE;
}
}
#else
dir = opendir(".");
while ( (dirent = readdir(dir)) != NULL)
{
ptr = strrchr(dirent->d_name, '.');
if (ptr != NULL && strcmp(".wdg", ptr) == 0)
{
if (!wdgLoadCompleteCatalog(dirent->d_name))
{
closedir(dir);
return FALSE;
}
}
}
closedir(dir);
#endif
// now check the dependancies
if (!wdgCheckDependancies())
{
return FALSE;
}
return TRUE;
}
// try to load the additional header info in addon WDGs
BOOL wdgLoadAdditionalHeader(FILE *pFileHandle, WDGCACHE *psCache)
{
WDG_HEADER_V5 Header;
UDWORD BytesRead;
// okay, the file exsists (because we succsesfully opened it), now read in the WDG header
BytesRead=DISK_ReadPos(0,(UBYTE *)&Header,sizeof(WDG_HEADER_V5),pFileHandle);
if (BytesRead!=sizeof(WDG_HEADER_V5))
{
DBERROR(("wdgLoadAdditionalHeader unable to read from %s\n",psCache->aFileName));
return FALSE;
}
// right, we read in the header now check the values to make sure its okay
if (Header.WDGid[0]!='W' ||
Header.WDGid[1]!='D' ||
Header.WDGid[2]!='G')
{
DBERROR(("wdgLoadAdditionalHeader bad type of wdg file - %s\n",psCache->aFileName));
return FALSE;
}
if (Header.WDGid[3] == '4')
{
// got the original WDG
psCache->sequence = 0;
strcpy(psCache->aName, "warzone");
psCache->numDep = 0;
return TRUE;
}
// version 5 header
psCache->sequence = Header.sequence;
strcpy(psCache->aName, Header.aName);
psCache->numDep = Header.numDep;
BytesRead=DISK_ReadPos(sizeof(WDG_HEADER_V5),(UBYTE *)psCache->asDep,sizeof(WDG_DEP)*Header.numDep,pFileHandle);
if (BytesRead!=sizeof(WDG_DEP)*Header.numDep)
{
DBERROR(("wdgLoadAdditionalHeader unable to read from %s\n",psCache->aFileName));
return FALSE;
}
return TRUE;
}
// load the catalogs in a wdg
// NOTE: assumes the wdg.c catalogs have been set to the static arrays
BOOL wdgLoadCompleteCatalog(char *pWDGName)
{
WDGCACHE *psNew, *psCurr, *psPrev;
UDWORD numWRF, i, offset;
WDGINFO *psCat;
WRFINFO *psFileCat;
FILE *pFileHandle;
// allocate the cache structure
psNew = (WDGCACHE*)MALLOC(sizeof(WDGCACHE));
if (psNew == NULL)
{
DBERROR(("wdgLoadCompleteCatalog: out of memory"));
return FALSE;
}
strcpy(psNew->aFileName, pWDGName);
// load the WDGINFO
if (!WDG_SetCurrentWDG(pWDGName))
{
DBERROR(("wdgLoadCompleteCatalog: could not set %s as Current WDG", pWDGName));
return FALSE;
}
// get the WRF catalog
WDG_GetCurrentWDGCatalog(&pWDGName, &numWRF, &psCat);
psNew->numWRF = numWRF;
psNew->asWRFCatalog = (WDGINFO*)MALLOC( sizeof(WDGINFO) * numWRF);
if (psNew->asWRFCatalog == NULL)
{
DBERROR(("wdgLoadCompleteCatalog: out of memory"));
return FALSE;
}
memcpy(psNew->asWRFCatalog, psCat, sizeof(WDGINFO) * numWRF);
psNew->apsWRFFileCatalog = (WRFINFO**)MALLOC( sizeof(WRFINFO *) * numWRF );
if (psNew->apsWRFFileCatalog == NULL)
{
DBERROR(("wdgLoadCompleteCatalog: out of memory"));
return FALSE;
}
memset(psNew->apsWRFFileCatalog, 0, sizeof(WRFINFO *) * numWRF);
// get the extra WDG info
pFileHandle = fopen(pWDGName, "rb");
if (pFileHandle == NULL)
{
DBERROR(("wdgLoadCompleteCatalog: could not open %s", pWDGName));
return FALSE;
}
if (!wdgLoadAdditionalHeader(pFileHandle, psNew))
{
fclose(pFileHandle);
return FALSE;
}
// now load the file catalogs
for(i=0; i<numWRF; i++)
{
if (psCat[i].filecount == 0)
{
continue;
}
if (!LoadWRFCatalog(psCat + i, pFileHandle))
{
DBERROR(("wdgLoadCompleteCatalog: could not read file catalog for WRF number %d", i));
fclose(pFileHandle);
return FALSE;
}
psNew->apsWRFFileCatalog[i] = (WRFINFO*)MALLOC( sizeof(WRFINFO) * psCat[i].filecount );
if (psNew->apsWRFFileCatalog[i] == NULL)
{
DBERROR(("wdgLoadCompleteCatalog: out of memory"));
fclose(pFileHandle);
return FALSE;
}
WDG_GetCurrentWFRFileCatalog(&offset, &psFileCat);
memcpy(psNew->apsWRFFileCatalog[i], psFileCat, sizeof(WRFINFO) * psCat[i].filecount);
}
if (fclose(pFileHandle) != 0)
{
DBERROR(("wdgLoadCompleteCatalog: failed to close WDG %s", pWDGName));
fclose(pFileHandle);
return FALSE;
}
// add the cache structure into the list
psPrev = NULL;
for(psCurr=psWDGCache; psCurr != NULL; psCurr=psCurr->psNext)
{
if (psCurr->sequence < psNew->sequence)
{
break;
}
psPrev = psCurr;
}
if (psPrev == NULL)
{
psNew->psNext = psWDGCache;
psNew->psPrev = NULL;
psWDGCache = psNew;
}
else
{
psNew->psNext = psPrev->psNext;
psNew->psPrev = psPrev;
psPrev->psNext = psNew;
}
if (psNew->psNext == NULL)
{
psWDGCacheRev = psNew;
}
else
{
psNew->psNext->psPrev = psNew;
}
return TRUE;
}
// Find the first instance of a WRF in the WDG catalogs
BOOL wdgFindFirstWRF(UDWORD WRFName, WDG_FINDWRF *psFindData)
{
UDWORD i;
// initialise the find data
memset(psFindData, 0, sizeof(WDG_FINDWRF));
psFindData->WRFNameHash = WRFName;
psFindData->psCurrCache = psWDGCache;
if (psWDGCache == NULL)
{
return FALSE;
}
// see if the WRF is in the first WDG
for(i=0; i<psWDGCache->numWRF; i++)
{
if (psWDGCache->asWRFCatalog[i].WRFname == WRFName)
{
psFindData->currWRFIndex = i;
return TRUE;
}
}
// search the remaining WDGs
if (wdgFindNextWRF(psFindData))
{
return TRUE;
}
return FALSE;
}
// Find the next instance of a WRF in WDG catalogs
BOOL wdgFindNextWRF(WDG_FINDWRF *psFindData)
{
WDGCACHE *psCurrCache;
UDWORD i;
if (psFindData->psCurrCache == NULL)
{
return FALSE;
}
// search each WDG cache
psCurrCache=psFindData->psCurrCache->psNext;
for(; psCurrCache != NULL; psCurrCache = psCurrCache->psNext)
{
for(i=0; i<psCurrCache->numWRF; i++)
{
if (psCurrCache->asWRFCatalog[i].WRFname == psFindData->WRFNameHash)
{
goto found;
}
}
}
// jump here if a WRF has been found
found:
if (psCurrCache != NULL)
{
psFindData->psCurrCache = psCurrCache;
psFindData->currWRFIndex = i;
return TRUE;
}
psFindData->psCurrCache = NULL;
psFindData->currWRFIndex = 0;
return FALSE;
}
// Find the first instance of a file in a WRF
BOOL wdgFindFirstFile(UDWORD WRFName, UDWORD type, UDWORD FileName, WDG_FINDFILE *psFindData)
{
WDGINFO *psWRFData;
WRFINFO *asFileData;
UDWORD i;
memset(psFindData, 0, sizeof(WDG_FINDFILE));
psFindData->WRFNameHash = WRFName;
psFindData->FileType = type;
psFindData->FileNameHash = FileName;
psFindData->psCurrCache = psWDGCache;
if (psWDGCache == NULL)
{
return FALSE;
}
// find the first WRF
if (!wdgFindFirstWRF(WRFName, (WDG_FINDWRF *)psFindData))
{
return FALSE;
}
// see if there is an instance of the file in this WRF
psWRFData = psFindData->psCurrCache->asWRFCatalog + psFindData->currWRFIndex ;
asFileData = psFindData->psCurrCache->apsWRFFileCatalog[ psFindData->currWRFIndex ];
for(i=0; i<psWRFData->filecount; i++)
{
if ((asFileData[i].name == psFindData->FileNameHash) &&
(asFileData[i].type == psFindData->FileType) &&
(asFileData[i].offset != UDWORD_MAX))
{
psFindData->currFileIndex = i;
return TRUE;
}
}
// not in this WRF, try other ones
if (wdgFindNextFile(psFindData))
{
return TRUE;
}
return FALSE;
}
// Find the next instance of a file in a WRF
BOOL wdgFindNextFile(WDG_FINDFILE *psFindData)
{
WDGINFO *psWRFData;
WRFINFO *asFileData;
UDWORD i;
while (psFindData->psCurrCache != NULL)
{
// find the next WRF
if (!wdgFindNextWRF((WDG_FINDWRF *)psFindData))
{
goto failed;
}
// see if there is an instance of the file in this WRF
psWRFData = psFindData->psCurrCache->asWRFCatalog + psFindData->currWRFIndex ;
asFileData = psFindData->psCurrCache->apsWRFFileCatalog[ psFindData->currWRFIndex ];
for(i=0; i<psWRFData->filecount; i++)
{
if ((asFileData[i].name == psFindData->FileNameHash) &&
(asFileData[i].type == psFindData->FileType) &&
(asFileData[i].offset != UDWORD_MAX))
{
psFindData->currFileIndex = i;
return TRUE;
}
}
}
failed:
psFindData->psCurrCache = NULL;
psFindData->currWRFIndex = 0;
psFindData->currFileIndex = 0;
return FALSE;
}
// set the current WDG based on the found WRF
void wdgSetCurrentWDGFromFind(WDG_FINDWRF *psFindData)
{
WDGCACHE *psCache = psFindData->psCurrCache;
WDGINFO *psWRFData = psCache->asWRFCatalog + psFindData->currWRFIndex;
WDG_SetCurrentWDGCatalog(psCache->aFileName,
psCache->numWRF,
psCache->asWRFCatalog);
WDG_SetCurrentWRFFileCatalog(psWRFData->offset, psCache->apsWRFFileCatalog[ psFindData->currWRFIndex ]);
}
// load a file that is not stored in the current WDG
BOOL wdgGetFileFromOtherWDG(UDWORD WRFname, UDWORD type, UDWORD FileName,
WRFINFO **ppsNewFile, UBYTE **ppFileBuf)
{
WDG_FINDFILE sFindFile;
FILE *pOtherWDG;
WDGCACHE *psCache;
WDGINFO *psWRFData;
WRFINFO *psFileData;
UDWORD FileOffset;
// file is not in this WDG - find it in another
if (!wdgFindFirstFile(WRFname, type, FileName, &sFindFile))
{
return FALSE;
}
// open the other WDG
pOtherWDG=fopen(sFindFile.psCurrCache->aFileName, "rb");
if (pOtherWDG==NULL)
{
DBERROR(("wdgGetFileFromOtherWDG: unable to open %s\n",sFindFile.psCurrCache->aFileName));
return FALSE;
}
psCache = sFindFile.psCurrCache;
psWRFData = psCache->asWRFCatalog + sFindFile.currWRFIndex;
psFileData = psCache->apsWRFFileCatalog[ sFindFile.currWRFIndex ] + sFindFile.currFileIndex;
FileOffset=psWRFData->offset + sizeof(WRFINFO)*psWRFData->filecount + psFileData->offset;
*ppFileBuf = FILE_RetrieveSingle(pOtherWDG,FileOffset,psFileData->filesize);
*ppsNewFile = psFileData;
if ((*ppFileBuf) == NULL)
{
return FALSE;
}
fclose(pOtherWDG);
return TRUE;;
}
// Find the first instance of a WRF in the WDG catalogs
// This searches from the end to the begining
BOOL wdgFindFirstWRFRev(UDWORD WRFName, WDG_FINDWRF *psFindData)
{
UDWORD i;
// initialise the find data
memset(psFindData, 0, sizeof(WDG_FINDWRF));
psFindData->WRFNameHash = WRFName;
psFindData->psCurrCache = psWDGCacheRev;
if (psWDGCacheRev == NULL)
{
return FALSE;
}
// see if the WRF is in the first WDG
for(i=0; i<psWDGCacheRev->numWRF; i++)
{
if (psWDGCacheRev->asWRFCatalog[i].WRFname == WRFName)
{
psFindData->currWRFIndex = i;
return TRUE;
}
}
// search the remaining WDGs
if (wdgFindNextWRFRev(psFindData))
{
return TRUE;
}
return FALSE;
}
// Find the next instance of a WRF in WDG catalogs
// This searches from the end to the begining
BOOL wdgFindNextWRFRev(WDG_FINDWRF *psFindData)
{
WDGCACHE *psCurrCache;
UDWORD i;
if (psFindData->psCurrCache == NULL)
{
return FALSE;
}
// search each WDG cache
psCurrCache=psFindData->psCurrCache->psPrev;
for(; psCurrCache != NULL; psCurrCache = psCurrCache->psPrev)
{
for(i=0; i<psCurrCache->numWRF; i++)
{
if (psCurrCache->asWRFCatalog[i].WRFname == psFindData->WRFNameHash)
{
goto found;
}
}
}
// jump here if a WRF has been found
found:
if (psCurrCache != NULL)
{
psFindData->psCurrCache = psCurrCache;
psFindData->currWRFIndex = i;
return TRUE;
}
psFindData->psCurrCache = NULL;
psFindData->currWRFIndex = 0;
return FALSE;
}
// Find the first instance of a file in a WRF
// This searches from the end to the begining
BOOL wdgFindFirstFileRev(UDWORD WRFName, UDWORD type, UDWORD FileName, WDG_FINDFILE *psFindData)
{
WDGINFO *psWRFData;
WRFINFO *asFileData;
UDWORD i;
memset(psFindData, 0, sizeof(WDG_FINDFILE));
psFindData->WRFNameHash = WRFName;
psFindData->FileType = type;
psFindData->FileNameHash = FileName;
psFindData->psCurrCache = psWDGCacheRev;
if (psWDGCacheRev == NULL)
{
return FALSE;
}
// find the first WRF
if (!wdgFindFirstWRFRev(WRFName, (WDG_FINDWRF *)psFindData))
{
return FALSE;
}
// see if there is an instance of the file in this WRF
psWRFData = psFindData->psCurrCache->asWRFCatalog + psFindData->currWRFIndex ;
asFileData = psFindData->psCurrCache->apsWRFFileCatalog[ psFindData->currWRFIndex ];
for(i=0; i<psWRFData->filecount; i++)
{
if ((asFileData[i].name == psFindData->FileNameHash) &&
(asFileData[i].type == psFindData->FileType) &&
(asFileData[i].offset != UDWORD_MAX))
{
psFindData->currFileIndex = i;
return TRUE;
}
}
// not in this WRF, try other ones
if (wdgFindNextFileRev(psFindData))
{
return TRUE;
}
return FALSE;
}
// Find the next instance of a file in a WRF
// This searches from the end to the begining
BOOL wdgFindNextFileRev(WDG_FINDFILE *psFindData)
{
WDGINFO *psWRFData;
WRFINFO *asFileData;
UDWORD i;
while (psFindData->psCurrCache != NULL)
{
// find the next WRF
if (!wdgFindNextWRFRev((WDG_FINDWRF *)psFindData))
{
goto failed;
}
// see if there is an instance of the file in this WRF
psWRFData = psFindData->psCurrCache->asWRFCatalog + psFindData->currWRFIndex ;
asFileData = psFindData->psCurrCache->apsWRFFileCatalog[ psFindData->currWRFIndex ];
for(i=0; i<psWRFData->filecount; i++)
{
if ((asFileData[i].name == psFindData->FileNameHash) &&
(asFileData[i].type == psFindData->FileType) &&
(asFileData[i].offset != UDWORD_MAX))
{
psFindData->currFileIndex = i;
return TRUE;
}
}
}
failed:
psFindData->psCurrCache = NULL;
psFindData->currWRFIndex = 0;
psFindData->currFileIndex = 0;
return FALSE;
}

View File

@ -1,101 +0,0 @@
/*
* multiWDG.h
*
* Handle multiple wdg files
*
*/
#ifndef _multiwdg_h
#define _multiwdg_h
#include "wdg.h"
// maximum number of characters in the wdg name
#define WDG_NAMEMAX 16
#define WDG_FILEMAX 256
#define WDG_MAXDEP 20
// store the catalog info for a WDG
typedef struct _wdgcache
{
STRING aFileName[WDG_FILEMAX];
STRING aName[WDG_NAMEMAX];
UDWORD sequence;
UDWORD numWRF;
WDGINFO *asWRFCatalog;
WRFINFO **apsWRFFileCatalog;
// store the dependancies
UDWORD numDep;
WDG_DEP asDep[WDG_MAXDEP];
struct _wdgcache *psNext;
struct _wdgcache *psPrev;
} WDGCACHE;
// function prototypes
BOOL wdgMultiInit(void);
void wdgMultiShutdown(void);
BOOL wdgLoadAllWDGCatalogs(void);
void wdgDisableAddonWDG(void);
void wdgEnableAddonWDG(void);
// structures for the find WRF / file functions
#define WDG_FINDWRF_BASE \
/* the wrf that is being searched for */ \
UDWORD WRFNameHash; \
/* the current WDG that the WRF was found in */ \
WDGCACHE *psCurrCache; \
UDWORD currWRFIndex
typedef struct _wdg_findwrf
{
WDG_FINDWRF_BASE;
} WDG_FINDWRF;
typedef struct _wdg_findfile
{
WDG_FINDWRF_BASE;
// the file that is being searched for
UDWORD FileType;
UDWORD FileNameHash;
// the index of a found file
UDWORD currFileIndex;
} WDG_FINDFILE;
// Find the first instance of a WRF in the WDG catalogs
BOOL wdgFindFirstWRF(UDWORD WRFName, WDG_FINDWRF *psFindData);
// Find the next instance of a WRF in WDG catalogs
BOOL wdgFindNextWRF(WDG_FINDWRF *psFindData);
// Find the first instance of a file in a WRF
BOOL wdgFindFirstFile(UDWORD WRFName, UDWORD type, UDWORD FileName, WDG_FINDFILE *psFindData);
// Find the next instance of a file in a WRF
BOOL wdgFindNextFile(WDG_FINDFILE *psFindData);
// set the current WDG based on the found WRF
void wdgSetCurrentWDGFromFind(WDG_FINDWRF *psFindData);
// load a file that is not stored in the current WDG
BOOL wdgGetFileFromOtherWDG(UDWORD WRFname, UDWORD type, UDWORD FileName,
WRFINFO **ppsNewFile, UBYTE **ppFileBuf);
// Rev versions of these functions all search from the end to the begining
// Find the first instance of a WRF in the WDG catalogs
BOOL wdgFindFirstWRFRev(UDWORD WRFName, WDG_FINDWRF *psFindData);
// Find the next instance of a WRF in WDG catalogs
BOOL wdgFindNextWRFRev(WDG_FINDWRF *psFindData);
// Find the first instance of a file in a WRF
BOOL wdgFindFirstFileRev(UDWORD WRFName, UDWORD type, UDWORD FileName, WDG_FINDFILE *psFindData);
// Find the next instance of a file in a WRF
BOOL wdgFindNextFileRev(WDG_FINDFILE *psFindData);
#endif

View File

@ -1,29 +0,0 @@
/*
* ResLY.h
*
* Interface to the RES file lex and yacc functions.
*/
#ifndef _resly_h
#define _resly_h
/* Maximum number of characters in a directory entry */
#define FILE_MAXCHAR 255
/* Maximum number of TEXT items in any one Yacc rule */
#define TEXT_BUFFERS 10
/* The initial resource directory and the current resource directory */
extern STRING aResDir[FILE_MAXCHAR];
extern STRING aCurrResDir[FILE_MAXCHAR];
/* Set the current input buffer for the lexer - used by resLoad */
extern void resSetInputBuffer(UBYTE *pBuffer, UDWORD size);
/* Give access to the line number and current text for error messages */
extern void resGetErrorData(int *pLine, char **ppText);
/* Call the yacc parser */
extern int res_parse(void);
#endif

View File

@ -1,798 +0,0 @@
/* lex -p res_ -o resource_l.c Resource.l */
#define YYNEWLINE 10
#define INITIAL 0
#define COMMENT 2
#define QUOTE 4
#define SLCOMMENT 6
#define res__endst 37
#define res__nxtmax 617
#define YY_LA_SIZE 5
static unsigned int res__la_act[] = {
2, 17, 2, 17, 2, 17, 3, 17, 8, 17, 8, 17, 17, 9, 14, 7,
2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 0, 2, 12, 12,
13, 10, 11, 6, 4, 5, 6, 16, 15, 16, 0
};
static unsigned char res__look[] = {
0
};
static int res__final[] = {
0, 0, 2, 4, 6, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
21, 22, 23, 24, 25, 26, 27, 28, 30, 30, 31, 32, 33, 34, 35, 36,
37, 38, 39, 40, 41, 42
};
#ifndef res__state_t
#define res__state_t unsigned char
#endif
static res__state_t res__begin[] = {
0, 0, 24, 24, 30, 30, 34, 34, 0
};
static res__state_t res__next[] = {
8, 8, 8, 8, 8, 8, 8, 8, 8, 5, 6, 8, 8, 5, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
5, 8, 4, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 8, 8, 8, 8, 8,
8, 3, 3, 3, 1, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 8, 8, 8, 8, 8,
9, 11, 13, 12, 14, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
15, 16, 17, 18, 19, 20, 21, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 22, 23, 28, 29, 12, 37, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 26, 26, 26, 26,
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 25, 26, 26, 26, 26,
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
26, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 32, 33, 33, 33, 33,
33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
33, 33, 33, 31, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
33, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37,
37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 36, 36, 36, 36, 36, 36,
36, 36, 36, 36, 35, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 0
};
static res__state_t res__check[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
7, 4, 2, 3, 13, 7, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
14, 1, 16, 17, 18, 19, 20, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 21, 22, 25, 28, 3, 36, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
30, 33, ~0U, ~0U, ~0U, ~0U, ~0U, ~0U, ~0U, ~0U, ~0U, ~0U, ~0U, ~0U, ~0U, ~0U,
~0U, ~0U, ~0U, ~0U, ~0U, ~0U, ~0U, ~0U, ~0U, 33, 34, 34, 34, 34, 34, 34,
34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 0
};
static res__state_t res__default[] = {
37, 3, 3, 37, 37, 37, 37, 37, 37, 37, 37, 37, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 37, 37, 37, 37, 37, 37, 37, 37,
37, 30, 37, 37, 34, 0
};
static int res__base[] = {
0, 40, 25, 86, 95, 618, 618, 86, 618, 618, 618, 618, 618, 24, 43, 618,
32, 46, 49, 33, 39, 63, 57, 618, 209, 132, 618, 618, 170, 618, 337, 618,
618, 455, 490, 618, 172, 618
};
/*
* Copyright 1988, 1992 by Mortice Kern Systems Inc. All rights reserved.
* All rights reserved.
*
* $Header: /u/rd/src/lex/rcs/res_lex.c 1.57 1995/12/11 22:14:06 fredw Exp $
*
*/
#include <stdlib.h>
#include <stdio.h>
#if __STDC__
#define YY_ARGS(args) args
#else
#define YY_ARGS(args) ()
#endif
#ifdef LEX_WINDOWS
#include <windows.h>
/*
* define, if not already defined
* the flag YYEXIT, which will allow
* graceful exits from res_lex()
* without resorting to calling exit();
*/
#ifndef YYEXIT
#define YYEXIT 1
#endif
/*
* the following is the handle to the current
* instance of a windows program. The user
* program calling res_lex must supply this!
*/
#ifdef STRICT
extern HINSTANCE hInst;
#else
extern HANDLE hInst;
#endif
#endif /* LEX_WINDOWS */
/*
* Define m_textmsg() to an appropriate function for internationalized messages
* or custom processing.
*/
#ifndef I18N
#define m_textmsg(id, str, cls) (str)
#else /*I18N*/
extern char* m_textmsg YY_ARGS((int id, const char* str, char* cls));
#endif/*I18N*/
/*
* Include string.h to get definition of memmove() and size_t.
* If you do not have string.h or it does not declare memmove
* or size_t, you will have to declare them here.
*/
#include <string.h>
/* Uncomment next line if memmove() is not declared in string.h */
/*extern char * memmove();*/
/* Uncomment next line if size_t is not available in stdio.h or string.h */
/*typedef unsigned size_t;*/
/* Drop this when LATTICE provides memmove */
#ifdef LATTICE
#define memmove memcopy
#endif
/*
* YY_STATIC determines the scope of variables and functions
* declared by the lex scanner. It must be set with a -DYY_STATIC
* option to the compiler (it cannot be defined in the lex program).
*/
#ifdef YY_STATIC
/* define all variables as static to allow more than one lex scanner */
#define YY_DECL static
#else
/* define all variables as global to allow other modules to access them */
#define YY_DECL
#endif
/*
* You can redefine res_getc. For YACC Tracing, compile this code
* with -DYYTRACE to get input from yt_getc
*/
#ifdef YYTRACE
extern int yt_getc YY_ARGS((void));
#define res_getc() yt_getc()
#else
#define res_getc() getc(res_in) /* res_lex input source */
#endif
/*
* the following can be redefined by the user.
*/
#ifdef YYEXIT
#define YY_FATAL(msg) { fprintf(res_out, "res_lex: %s\n", msg); res_LexFatal = 1; }
#else /* YYEXIT */
#define YY_FATAL(msg) { fprintf(stderr, "res_lex: %s\n", msg); exit(1); }
#endif /* YYEXIT */
#undef ECHO
#define ECHO fputs(res_text, res_out)
#define output(c) putc((c), res_out) /* res_lex sink for unmatched chars */
#define YY_INTERACTIVE 1 /* save micro-seconds if 0 */
#define BEGIN res__start =
#define NLSTATE (res__lastc = YYNEWLINE)
#define YY_INIT \
(res__start = res_leng = res__end = 0, res__lastc = YYNEWLINE)
#define res_less(n) if ((n) < 0 || (n) > res__end) ; \
else { YY_SCANNER; res_leng = (n); YY_USER; }
YY_DECL void res__reset YY_ARGS((void));
/* functions defined in libl.lib */
extern int res_wrap YY_ARGS((void));
extern void res_error YY_ARGS((char *fmt, ...));
extern void res_comment YY_ARGS((char *term));
extern int res_mapch YY_ARGS((int delim, int escape));
/*
* resource.l
*
* Lex file for parsing res files
*/
#include <stdio.h>
/* Allow frame header files to be singly included */
#define FRAME_LIB_INCLUDE
#include <string.h>
#include "types.h"
#include "debug.h"
#include "resly.h"
/* Get the Yacc definitions */
#include "resource_y.h"
/* Maximum length for any TEXT value */
#define YYLMAX 255
/* Store for any string values */
STRING aText[TEXT_BUFFERS][YYLMAX]; // No longer static ... lets use this area globally
static UDWORD currText=0;
// Note if we are in a comment
static BOOL inComment = FALSE;
/* Pointer to the input buffer */
static UBYTE *pInputBuffer = NULL;
static UBYTE *pEndBuffer = NULL;
#undef res_getc
#define res_getc() (pInputBuffer != pEndBuffer ? *(pInputBuffer++) : EOF)
#ifndef YYLMAX
#define YYLMAX 100 /* token and pushback buffer size */
#endif /* YYLMAX */
/*
* If %array is used (or defaulted), res_text[] contains the token.
* If %pointer is used, res_text is a pointer to res__tbuf[].
*/
YY_DECL char res_text[YYLMAX+1];
#ifdef YY_DEBUG
#undef YY_DEBUG
#define YY_DEBUG(fmt, a1, a2) fprintf(stderr, fmt, a1, a2)
#else
#define YY_DEBUG(fmt, a1, a2)
#endif
/*
* The declaration for the lex scanner can be changed by
* redefining YYLEX or YYDECL. This must be done if you have
* more than one scanner in a program.
*/
#ifndef YYLEX
#define YYLEX res_lex /* name of lex scanner */
#endif
#ifndef YYDECL
#define YYDECL int YYLEX YY_ARGS((void)) /* declaration for lex scanner */
#endif
/*
* stdin and stdout may not neccessarily be constants.
* If stdin and stdout are constant, and you want to save a few cycles, then
* #define YY_STATIC_STDIO 1 in this file or on the commandline when
* compiling this file
*/
#ifndef YY_STATIC_STDIO
#define YY_STATIC_STDIO 0
#endif
#if YY_STATIC_STDIO
YY_DECL FILE *res_in = stdin;
YY_DECL FILE *res_out = stdout;
#else
YY_DECL FILE *res_in = (FILE *)0;
YY_DECL FILE *res_out = (FILE *)0;
#endif
YY_DECL int res_lineno = 1; /* line number */
/* res__sbuf[0:res_leng-1] contains the states corresponding to res_text.
* res_text[0:res_leng-1] contains the current token.
* res_text[res_leng:res__end-1] contains pushed-back characters.
* When the user action routine is active,
* res__save contains res_text[res_leng], which is set to '\0'.
* Things are different when YY_PRESERVE is defined.
*/
static res__state_t res__sbuf [YYLMAX+1]; /* state buffer */
static int res__end = 0; /* end of pushback */
static int res__start = 0; /* start state */
static int res__lastc = YYNEWLINE; /* previous char */
YY_DECL int res_leng = 0; /* res_text token length */
#ifdef YYEXIT
static int res_LexFatal;
#endif /* YYEXIT */
#ifndef YY_PRESERVE /* the efficient default push-back scheme */
static char res__save; /* saved res_text[res_leng] */
#define YY_USER { /* set up res_text for user */ \
res__save = res_text[res_leng]; \
res_text[res_leng] = 0; \
}
#define YY_SCANNER { /* set up res_text for scanner */ \
res_text[res_leng] = res__save; \
}
#else /* not-so efficient push-back for res_text mungers */
static char res__save [YYLMAX];
static char *res__push = res__save+YYLMAX;
#define YY_USER { \
size_t n = res__end - res_leng; \
res__push = res__save+YYLMAX - n; \
if (n > 0) \
memmove(res__push, res_text+res_leng, n); \
res_text[res_leng] = 0; \
}
#define YY_SCANNER { \
size_t n = res__save+YYLMAX - res__push; \
if (n > 0) \
memmove(res_text+res_leng, res__push, n); \
res__end = res_leng + n; \
}
#endif
#ifdef LEX_WINDOWS
/*
* When using the windows features of lex,
* it is necessary to load in the resources being
* used, and when done with them, the resources must
* be freed up, otherwise we have a windows app that
* is not following the rules. Thus, to make res_lex()
* behave in a windows environment, create a new
* res_lex() which will call the original res_lex() as
* another function call. Observe ...
*/
/*
* The actual lex scanner (usually res_lex(void)).
* NOTE: you should invoke res__init() if you are calling res_lex()
* with new input; otherwise old lookaside will get in your way
* and res_lex() will die horribly.
*/
static int win_res_lex(); /* prototype for windows res_lex handler */
YYDECL {
int wReturnValue;
HANDLE hRes_table;
unsigned short far *old_res__la_act; /* remember previous pointer values */
short far *old_res__final;
res__state_t far *old_res__begin;
res__state_t far *old_res__next;
res__state_t far *old_res__check;
res__state_t far *old_res__default;
short far *old_res__base;
/*
* the following code will load the required
* resources for a Windows based parser.
*/
hRes_table = LoadResource (hInst,
FindResource (hInst, "UD_RES_res_LEX", "res_LEXTBL"));
/*
* return an error code if any
* of the resources did not load
*/
if (hRes_table == NULL)
return (0);
/*
* the following code will lock the resources
* into fixed memory locations for the scanner
* (and remember previous pointer locations)
*/
old_res__la_act = res__la_act;
old_res__final = res__final;
old_res__begin = res__begin;
old_res__next = res__next;
old_res__check = res__check;
old_res__default = res__default;
old_res__base = res__base;
res__la_act = (unsigned short far *)LockResource (hRes_table);
res__final = (short far *)(res__la_act + Sizeof_res__la_act);
res__begin = (res__state_t far *)(res__final + Sizeof_res__final);
res__next = (res__state_t far *)(res__begin + Sizeof_res__begin);
res__check = (res__state_t far *)(res__next + Sizeof_res__next);
res__default = (res__state_t far *)(res__check + Sizeof_res__check);
res__base = (res__state_t far *)(res__default + Sizeof_res__default);
/*
* call the standard res_lex() code
*/
wReturnValue = win_res_lex();
/*
* unlock the resources
*/
UnlockResource (hRes_table);
/*
* and now free the resource
*/
FreeResource (hRes_table);
/*
* restore previously saved pointers
*/
res__la_act = old_res__la_act;
res__final = old_res__final;
res__begin = old_res__begin;
res__next = old_res__next;
res__check = old_res__check;
res__default = old_res__default;
res__base = old_res__base;
return (wReturnValue);
} /* end function */
static int win_res_lex() {
#else /* LEX_WINDOWS */
/*
* The actual lex scanner (usually res_lex(void)).
* NOTE: you should invoke res__init() if you are calling res_lex()
* with new input; otherwise old lookaside will get in your way
* and res_lex() will die horribly.
*/
YYDECL {
#endif /* LEX_WINDOWS */
register int c, i, res_base;
unsigned res_st; /* state */
int res_fmin, res_fmax; /* res__la_act indices of final states */
int res_oldi, res_oleng; /* base i, res_leng before look-ahead */
int res_eof; /* 1 if eof has already been read */
#if !YY_STATIC_STDIO
if (res_in == (FILE *)0)
res_in = stdin;
if (res_out == (FILE *)0)
res_out = stdout;
#endif
#ifdef YYEXIT
res_LexFatal = 0;
#endif /* YYEXIT */
res_eof = 0;
i = res_leng;
YY_SCANNER;
res__again:
res_leng = i;
/* determine previous char. */
if (i > 0)
res__lastc = res_text[i-1];
/* scan previously accepted token adjusting res_lineno */
while (i > 0)
if (res_text[--i] == YYNEWLINE)
res_lineno++;
/* adjust pushback */
res__end -= res_leng;
if (res__end > 0)
memmove(res_text, res_text+res_leng, (size_t) res__end);
i = 0;
res_oldi = i;
/* run the state machine until it jams */
res_st = res__begin[res__start + ((res__lastc == YYNEWLINE) ? 1 : 0)];
res__sbuf[i] = (res__state_t) res_st;
do {
YY_DEBUG(m_textmsg(1547, "<state %d, i = %d>\n", "I num1 num2"), res_st, i);
if (i >= YYLMAX) {
YY_FATAL(m_textmsg(1548, "Token buffer overflow", "E"));
#ifdef YYEXIT
if (res_LexFatal)
return -2;
#endif /* YYEXIT */
} /* endif */
/* get input char */
if (i < res__end)
c = res_text[i]; /* get pushback char */
else if (!res_eof && (c = res_getc()) != EOF) {
res__end = i+1;
res_text[i] = (char) c;
} else /* c == EOF */ {
c = EOF; /* just to make sure... */
if (i == res_oldi) { /* no token */
res_eof = 0;
if (res_wrap())
return 0;
else
goto res__again;
} else {
res_eof = 1; /* don't re-read EOF */
break;
}
}
YY_DEBUG(m_textmsg(1549, "<input %d = 0x%02x>\n", "I num hexnum"), c, c);
/* look up next state */
while ((res_base = res__base[res_st]+(unsigned char)c) > res__nxtmax
|| res__check[res_base] != (res__state_t) res_st) {
if (res_st == res__endst)
goto res__jammed;
res_st = res__default[res_st];
}
res_st = res__next[res_base];
res__jammed: ;
res__sbuf[++i] = (res__state_t) res_st;
} while (!(res_st == res__endst || (YY_INTERACTIVE && res__base[res_st] > res__nxtmax && res__default[res_st] == res__endst)));
YY_DEBUG(m_textmsg(1550, "<stopped %d, i = %d>\n", "I num1 num2"), res_st, i);
if (res_st != res__endst)
++i;
/* search backward for a final state */
while (--i > res_oldi) {
res_st = res__sbuf[i];
if ((res_fmin = res__final[res_st]) < (res_fmax = res__final[res_st+1]))
goto res__found; /* found final state(s) */
}
/* no match, default action */
i = res_oldi + 1;
output(res_text[res_oldi]);
goto res__again;
res__found:
YY_DEBUG(m_textmsg(1551, "<final state %d, i = %d>\n", "I num1 num2"), res_st, i);
res_oleng = i; /* save length for REJECT */
/* pushback look-ahead RHS */
if ((c = (int)(res__la_act[res_fmin]>>9) - 1) >= 0) { /* trailing context? */
unsigned char *bv = res__look + c*YY_LA_SIZE;
static unsigned char bits [8] = {
1<<0, 1<<1, 1<<2, 1<<3, 1<<4, 1<<5, 1<<6, 1<<7
};
while (1) {
if (--i < res_oldi) { /* no / */
i = res_oleng;
break;
}
res_st = res__sbuf[i];
if (bv[(unsigned)res_st/8] & bits[(unsigned)res_st%8])
break;
}
}
/* perform action */
res_leng = i;
YY_USER;
switch (res__la_act[res_fmin] & 0777) {
case 0:
{ return DIRECTORY; }
break;
case 1:
{ return FILETOKEN; }
break;
case 2:
{
strcpy(aText[currText], res_text);
res_lval.sval = aText[currText];
currText = (currText + 1) % TEXT_BUFFERS;
return TEXT;
}
break;
case 3:
{ BEGIN QUOTE; }
break;
case 4:
{ BEGIN 0; }
break;
case 5:
{ res_error("Unexpected end of line in string"); }
break;
case 6:
{
strcpy(aText[currText], res_text);
res_lval.sval = aText[currText];
currText = (currText + 1) % TEXT_BUFFERS;
return QTEXT;
}
break;
case 7:
{
aText[currText][0] = '\0';
aText[currText][1] = '\0';
res_lval.sval = aText[currText];
currText = (currText + 1) % TEXT_BUFFERS;
return QTEXT;
}
break;
case 8:
;
break;
case 9:
{ inComment=TRUE; BEGIN COMMENT; }
break;
case 10:
case 11:
{ inComment=FALSE; BEGIN 0; }
break;
case 12:
case 13:
;
break;
case 14:
{ BEGIN SLCOMMENT; }
break;
case 15:
{ BEGIN 0; }
break;
case 16:
;
break;
case 17:
return res_text[0];
break;
}
YY_SCANNER;
i = res_leng;
goto res__again; /* action fell though */
}
/*
* Safely switch input stream underneath LEX
*/
typedef struct res__save_block_tag {
FILE * oldfp;
int oldline;
int oldend;
int oldstart;
int oldlastc;
int oldleng;
char savetext[YYLMAX+1];
res__state_t savestate[YYLMAX+1];
} YY_SAVED;
YY_SAVED *
res_SaveScan(FILE *fp)
{
YY_SAVED * p;
if ((p = (YY_SAVED *) malloc(sizeof(*p))) == NULL)
return p;
p->oldfp = res_in;
p->oldline = res_lineno;
p->oldend = res__end;
p->oldstart = res__start;
p->oldlastc = res__lastc;
p->oldleng = res_leng;
(void) memcpy(p->savetext, res_text, sizeof res_text);
(void) memcpy((char *) p->savestate, (char *) res__sbuf,
sizeof res__sbuf);
res_in = fp;
res_lineno = 1;
YY_INIT;
return p;
}
/*f
* Restore previous LEX state
*/
void
res_RestoreScan(YY_SAVED *p)
{
if (p == NULL)
return;
res_in = p->oldfp;
res_lineno = p->oldline;
res__end = p->oldend;
res__start = p->oldstart;
res__lastc = p->oldlastc;
res_leng = p->oldleng;
(void) memcpy(res_text, p->savetext, sizeof res_text);
(void) memcpy((char *) res__sbuf, (char *) p->savestate,
sizeof res__sbuf);
free(p);
}
/*
* User-callable re-initialization of res_lex()
*/
void
res__reset()
{
YY_INIT;
res_lineno = 1; /* line number */
}
/* Set the current input buffer for the lexer */
void resSetInputBuffer(UBYTE *pBuffer, UDWORD size)
{
pInputBuffer = pBuffer;
pEndBuffer = pBuffer + size;
/* Reset the lexer incase it's been used before */
res__reset();
inComment = FALSE;
}
void resGetErrorData(int *pLine, char **ppText)
{
*pLine = res_lineno;
*ppText = res_text;
}
int res_wrap(void)
{
if (inComment)
{
DBERROR(("Warning: reched end of file in a comment"));
}
return 1;
}

View File

@ -1,147 +0,0 @@
%{
/*
* resource.l
*
* Lex file for parsing res files
*/
#ifndef PSX
#include <stdio.h>
#else
/* A few definitions so the lex generated code will compile on the PSX.
* These shouldn't actually be used by any code that is run on the PSX, it
* just keeps the compiler happy.
*/
typedef signed int FILE;
#define stderr 0
#define stdin 0
#define stdout 0
static int fprintf(FILE* f,char* c,...)
{
return 0;
}
#endif
/* Allow frame header files to be singly included */
#define FRAME_LIB_INCLUDE
#include <string.h>
#include "types.h"
#include "debug.h"
#include "resly.h"
/* Get the Yacc definitions */
#include "resource_parser.h"
extern void res_error(char *pMessage,...);
#ifndef YYLMAX
#define YYLMAX 8192
#endif
/* Store for any string values */
STRING aText[TEXT_BUFFERS][YYLMAX]; // No longer static ... lets use this area globally
static UDWORD currText=0;
// Note if we are in a comment
static BOOL inComment = FALSE;
/* Pointer to the input buffer */
static UBYTE *pInputBuffer = NULL;
static UBYTE *pEndBuffer = NULL;
#define YY_INPUT(buf,result,max_size) \
if (pInputBuffer != pEndBuffer) { \
buf[0] = *(pInputBuffer++); result = 1; \
} else { \
buf[0] = EOF; result = YY_NULL; \
}
%}
%option nounput
%option prefix="res_"
%x COMMENT
%x QUOTE
%x SLCOMMENT
%%
/* Match to key words */
directory { return DIRECTORY; }
file { return FILETOKEN; }
/* Match text values */
[a-zA-Z][-0-9_a-zA-Z]* {
strcpy(aText[currText], res_text);
res_lval.sval = aText[currText];
currText = (currText + 1) % TEXT_BUFFERS;
return TEXT;
}
/* Match quoted text */
\" { BEGIN QUOTE; }
<QUOTE>\" { BEGIN 0; }
<QUOTE>\n { res_error("Unexpected end of line in string"); }
<QUOTE>[^\"\n]* {
strcpy(aText[currText], res_text);
res_lval.sval = aText[currText];
currText = (currText + 1) % TEXT_BUFFERS;
return QTEXT;
}
\"\" {
aText[currText][0] = '\0';
aText[currText][1] = '\0';
res_lval.sval = aText[currText];
currText = (currText + 1) % TEXT_BUFFERS;
return QTEXT;
}
/* Skip white space */
[ \t\n\x0d\x0a] ;
/* Strip comments */
"/*" { inComment=TRUE; BEGIN COMMENT; }
<COMMENT>"*/" |
<COMMENT>"*/"\n { inComment=FALSE; BEGIN 0; }
<COMMENT>. |
<COMMENT>\n ;
/* Strip single line comments */
"//" { BEGIN SLCOMMENT; }
<SLCOMMENT>\n { BEGIN 0; }
<SLCOMMENT>[^\n]* ;
/* Match anything that's been missed and pass it as a char */
. return res_text[0];
%%
/* Set the current input buffer for the lexer */
void resSetInputBuffer(UBYTE *pBuffer, UDWORD size)
{
pInputBuffer = pBuffer;
pEndBuffer = pBuffer + size;
/* Reset the lexer incase it's been used before */
//res_reset();
// YY_FLUSH_BUFFER;
res__flush_buffer( YY_CURRENT_BUFFER );
inComment = FALSE;
}
void resGetErrorData(int *pLine, char **ppText)
{
*pLine = res_lineno;
*ppText = res_text;
}
int res_wrap(void)
{
if (inComment)
{
DBERROR(("Warning: reched end of file in a comment"));
}
return 1;
}

View File

@ -1,107 +0,0 @@
%{
/*
* resource.y
*
* Yacc file for parsing RES files
*/
int res_lex (void);
/* Allow frame header files to be singly included */
#define FRAME_LIB_INCLUDE
// directory printfs
#define DEBUG_GROUP0
#include <string.h>
#include "types.h"
#include "debug.h"
#include "resly.h"
#include "frameresource.h"
/*
* A simple error reporting routine
*/
void res_error(const char *pMessage,...)
{
int line;
char *pText;
resGetErrorData(&line, &pText);
DBERROR(("RES file parse error:\n%s at line %d\nText: '%s'\n",
pMessage, line, pText));
}
%}
%name-prefix="res_"
%union {
STRING *sval;
}
/* value tokens */
%token <sval> TEXT
%token <sval> QTEXT /* Text with double quotes surrounding it */
/* keywords */
%token DIRECTORY
%token FILETOKEN
%%
res_file: res_line
| res_file res_line
;
res_line: dir_line
| file_line
;
dir_line: DIRECTORY QTEXT {
UDWORD len;
// set a new input directory
DBP0(("directory: %s\n", $2));
if ($2[1] == ':' ||
$2[0] == '\\')
{
// the new dir is rooted
strcpy(aCurrResDir, $2);
}
else
{
strcpy(aCurrResDir, aResDir);
strcpy(aCurrResDir + strlen(aResDir),
$2);
}
if (strlen($2) > 0)
{
// Add a trailing '\\'
len = strlen(aCurrResDir);
aCurrResDir[len] = '\\';
aCurrResDir[len+1] = 0;
// DBP0(("aCurrResDir: %s\n", aCurrResDir));
}
}
;
file_line: FILETOKEN TEXT QTEXT
{
/* load a data file */
DBP1(("file: %s %s\n", $2, $3));
if (!resLoadFile($2, $3))
{
YYABORT;
}
}
;
%%

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +0,0 @@
typedef union {
STRING *sval;
} YYSTYPE;
#define TEXT 257
#define QTEXT 258
#define DIRECTORY 259
#define FILETOKEN 260
extern YYSTYPE res_lval;

View File

@ -1,419 +0,0 @@
/*
* StrRes.c
*
* String storage an manipulation functions
*
*/
#include <string.h>
/* Allow frame header files to be singly included */
#define FRAME_LIB_INCLUDE
// Report unused strings
//#define DEBUG_GROUP0
#include "types.h"
#include "debug.h"
#include "mem.h"
#include "heap.h"
#include "treap.h"
#include "strres.h"
#include "strresly.h"
/* The string resource currently being loaded */
STR_RES *psCurrRes;
/* The id number of ID strings allocated by the system is ORed with this */
#define ID_ALLOC 0x80000000
/* Allocate a string block */
static BOOL strresAllocBlock(STR_BLOCK **ppsBlock, UDWORD size)
{
*ppsBlock = (STR_BLOCK*)MALLOC(sizeof(STR_BLOCK));
if (!*ppsBlock)
{
DBERROR(("strresAllocBlock: Out of memory - 1"));
return FALSE;
}
(*ppsBlock)->apStrings = (STRING**)MALLOC(sizeof(STRING *) * size);
if (!(*ppsBlock)->apStrings)
{
DBERROR(("strresAllocBlock: Out of memory - 2"));
FREE(*ppsBlock);
return FALSE;
}
memset((*ppsBlock)->apStrings, 0, sizeof(STRING *) * size);
#ifdef DEBUG
(*ppsBlock)->aUsage = MALLOC(sizeof(UDWORD) * size);
memset((*ppsBlock)->aUsage, 0, sizeof(UDWORD) * size);
#endif
return TRUE;
}
/* Initialise the string system */
BOOL strresCreate(STR_RES **ppsRes, UDWORD init, UDWORD ext)
{
STR_RES *psRes;
psRes = (STR_RES*)MALLOC(sizeof(STR_RES));
if (!psRes)
{
DBERROR(("strresCreate: Out of memory"));
return FALSE;
}
psRes->init = init;
psRes->ext = ext;
psRes->nextID = 0;
if (!TREAP_CREATE(&psRes->psIDTreap, treapStringCmp, init, ext))
{
DBERROR(("strresCreate: Out of memory"));
FREE(psRes);
return FALSE;
}
if (!strresAllocBlock(&psRes->psStrings, init))
{
TREAP_DESTROY(psRes->psIDTreap);
FREE(psRes);
return FALSE;
}
psRes->psStrings->psNext = NULL;
psRes->psStrings->idStart = 0;
psRes->psStrings->idEnd = init-1;
*ppsRes = psRes;
return TRUE;
}
/* Release the id strings, but not the strings themselves,
* (they can be accessed only by id number).
*/
void strresReleaseIDStrings(STR_RES *psRes)
{
STR_ID *psID;
ASSERT((PTRVALID(psRes, sizeof(STR_RES)),
"strresLoadFixedID: Invalid string res pointer"));
for(psID = (STR_ID*)TREAP_GETSMALLEST(psRes->psIDTreap); psID;
psID = (STR_ID*)TREAP_GETSMALLEST(psRes->psIDTreap))
{
TREAP_DEL(psRes->psIDTreap, (UDWORD)psID->pIDStr);
if (psID->id & ID_ALLOC)
{
FREE(psID->pIDStr);
FREE(psID);
}
}
}
/* Shutdown the string system */
void strresDestroy(STR_RES *psRes)
{
STR_BLOCK *psBlock, *psNext = NULL;
UDWORD i;
ASSERT((PTRVALID(psRes, sizeof(STR_RES)),
"strresLoadFixedID: Invalid string res pointer"));
// Free the string id's
strresReleaseIDStrings(psRes);
// Free the strings themselves
for(psBlock = psRes->psStrings; psBlock; psBlock=psNext)
{
for(i=psBlock->idStart; i<=psBlock->idEnd; i++)
{
#ifdef DEBUG_GROUP0
if (psBlock->aUsage[i - psBlock->idStart] == 0
&& i != 0 && i < psRes->nextID)
{
DBP0(("strresDestroy: String id %d not used:\n"
" \"%s\"\n",
i, psBlock->apStrings[i - psBlock->idStart]));
}
#endif
if (psBlock->apStrings[i - psBlock->idStart])
{
FREE(psBlock->apStrings[i - psBlock->idStart]);
}
#ifdef DEBUG
else if (i < psRes->nextID)
{
DBPRINTF(("strresDestroy: No string loaded for id %d\n", i));
}
#endif
}
psNext = psBlock->psNext;
FREE(psBlock->apStrings);
#ifdef DEBUG
FREE(psBlock->aUsage);
#endif
FREE(psBlock);
}
// Release the treap and free the final memory
TREAP_DESTROY(psRes->psIDTreap);
FREE(psRes);
}
/* Load a list of string ID's from a memory buffer */
BOOL strresLoadFixedID(STR_RES *psRes, STR_ID *psID, UDWORD numID)
{
UDWORD i;
ASSERT((PTRVALID(psRes, sizeof(STR_RES)),
"strresLoadFixedID: Invalid string res pointer"));
for (i=0; i<numID; i++)
{
ASSERT((psID->id == psRes->nextID,
"strresLoadFixedID: id out of sequence"));
// Store the ID string
if (!TREAP_ADD(psRes->psIDTreap, (UDWORD)psID->pIDStr, psID))
{
DBERROR(("strresLoadFixedID: Out of memory"));
return FALSE;
}
psID += 1;
psRes->nextID += 1;
}
return TRUE;
}
/* Return the ID number for an ID string */
BOOL strresGetIDNum(STR_RES *psRes, STRING *pIDStr, UDWORD *pIDNum)
{
STR_ID *psID;
ASSERT((PTRVALID(psRes, sizeof(STR_RES)),
"strresLoadFixedID: Invalid string res pointer"));
psID = (STR_ID*)TREAP_FIND(psRes->psIDTreap, (UDWORD)pIDStr);
if (!psID)
{
*pIDNum = 0;
return FALSE;
}
if (psID->id & ID_ALLOC)
{
*pIDNum = psID->id & ~ID_ALLOC;
}
else
{
*pIDNum = psID->id;
}
return TRUE;
}
/* Return the ID stored ID string that matches the string passed in */
BOOL strresGetIDString(STR_RES *psRes, STRING *pIDStr, STRING **ppStoredID)
{
STR_ID *psID;
ASSERT((PTRVALID(psRes, sizeof(STR_RES)),
"strresLoadFixedID: Invalid string res pointer"));
psID = (STR_ID*)TREAP_FIND(psRes->psIDTreap, (UDWORD)pIDStr);
if (!psID)
{
*ppStoredID = NULL;
return FALSE;
}
*ppStoredID = psID->pIDStr;
return TRUE;
}
/* Store a string */
BOOL strresStoreString(STR_RES *psRes, STRING *pID, STRING *pString)
{
STR_ID *psID;
STRING *pNew;
STR_BLOCK *psBlock;
UDWORD id;
ASSERT((PTRVALID(psRes, sizeof(STR_RES)),
"strresLoadFixedID: Invalid string res pointer"));
// Find the id for the string
psID = (STR_ID*)TREAP_FIND(psRes->psIDTreap, (UDWORD)pID);
if (!psID)
{
// No ID yet so generate a new one
psID = (STR_ID*)MALLOC(sizeof(STR_ID));
if (!psID)
{
DBERROR(("strresStoreString: Out of memory"));
return FALSE;
}
psID->pIDStr = (STRING*)MALLOC(sizeof(STRING) * (stringLen(pID) + 1));
if (!psID->pIDStr)
{
DBERROR(("strresStoreString: Out of memory"));
FREE(psID);
return FALSE;
}
stringCpy(psID->pIDStr, pID);
psID->id = psRes->nextID | ID_ALLOC;
psRes->nextID += 1;
TREAP_ADD(psRes->psIDTreap, (UDWORD)psID->pIDStr, psID);
}
id = psID->id & ~ID_ALLOC;
// Find the block to store the string in
for(psBlock = psRes->psStrings; psBlock->idEnd < id;
psBlock = psBlock->psNext)
{
if (!psBlock->psNext)
{
// Need to allocate a new string block
if (!strresAllocBlock(&psBlock->psNext, psRes->ext))
{
return FALSE;
}
psBlock->psNext->idStart = psBlock->idEnd+1;
psBlock->psNext->idEnd = psBlock->idEnd + psRes->ext;
psBlock->psNext->psNext = NULL;
}
}
// Put the new string in the string block
if (psBlock->apStrings[psID->id - psBlock->idStart] != NULL)
{
DBERROR(("strresStoreString: Duplicate string for id: %s", psID->pIDStr));
return FALSE;
}
// Allocate a copy of the string
pNew = (STRING*)MALLOC(sizeof(STRING) * (stringLen(pString) + 1));
if (!pNew)
{
DBERROR(("strresStoreString: Out of memory"));
return FALSE;
}
stringCpy(pNew, pString);
psBlock->apStrings[psID->id - psBlock->idStart] = pNew;
return TRUE;
}
/* Get the string from an ID number */
STRING *strresGetString(STR_RES *psRes, UDWORD id)
{
STR_BLOCK *psBlock;
ASSERT((PTRVALID(psRes, sizeof(STR_RES)),
"strresLoadFixedID: Invalid string res pointer"));
// find the block the string is in
for(psBlock = psRes->psStrings; psBlock && psBlock->idEnd < id;
psBlock = psBlock->psNext)
;
if (!psBlock)
{
ASSERT((FALSE, "strresGetString: String not found"));
// Return the default string
return psRes->psStrings->apStrings[0];
}
ASSERT((psBlock->apStrings[id - psBlock->idStart] != NULL,
"strresGetString: String not found"));
#ifdef DEBUG
psBlock->aUsage[id - psBlock->idStart] += 1;
#endif
if (psBlock->apStrings[id - psBlock->idStart] == NULL)
{
// Return the default string
return psRes->psStrings->apStrings[0];
}
return psBlock->apStrings[id - psBlock->idStart];
}
/* Load a string resource file */
BOOL strresLoad(STR_RES *psRes, UBYTE *pData, UDWORD size)
{
psCurrRes = psRes;
strresSetInputBuffer(pData, size);
if (strres_parse() != 0)
{
return FALSE;
}
return TRUE;
}
/* Return the the length of a STRING */
UDWORD stringLen(STRING *pStr)
{
UDWORD count=0;
while (*pStr++)
{
count += 1;
}
return count;
}
/* Copy a STRING */
void stringCpy(STRING *pDest, STRING *pSrc)
{
do
{
*pDest++ = *pSrc;
} while (*pSrc++);
}
/* Get the ID number for a string*/
UDWORD strresGetIDfromString(STR_RES *psRes, STRING *pString)
{
STR_BLOCK *psBlock, *psNext = NULL;
UDWORD i;
ASSERT((PTRVALID(psRes, sizeof(STR_RES)),
"strresGetID: Invalid string res pointer"));
// Search through all the blocks to find the string
for(psBlock = psRes->psStrings; psBlock; psBlock=psNext)
{
for(i=psBlock->idStart; i<=psBlock->idEnd; i++)
{
if (psBlock->apStrings[i - psBlock->idStart])
{
if (!strcmp(psBlock->apStrings[i - psBlock->idStart], pString))
{
return i;
}
}
}
psNext = psBlock->psNext;
}
return 0;
}

View File

@ -1,79 +0,0 @@
/*
* StrRes.h
*
* String resource interface functions
*
*/
#ifndef _strres_h
#define _strres_h
/* A string block */
typedef struct _str_block
{
STRING **apStrings;
UDWORD idStart, idEnd;
#ifdef DEBUG
UDWORD *aUsage;
#endif
struct _str_block *psNext;
} STR_BLOCK;
/* An ID entry */
typedef struct _str_id
{
UDWORD id;
STRING *pIDStr;
} STR_ID;
/* A String Resource */
typedef struct _str_res
{
TREAP *psIDTreap; // The treap to store string identifiers
STR_BLOCK *psStrings; // The store for the strings themselves
UDWORD init,ext; // Sizes for the string blocks
UDWORD nextID; // The next free ID
} STR_RES;
/* Create a string resource object */
extern BOOL strresCreate(STR_RES **ppsRes, UDWORD init, UDWORD ext);
/* Release a string resource object */
extern void strresDestroy(STR_RES *psRes);
/* Release the id strings, but not the strings themselves,
* (they can be accessed only by id number).
*/
extern void strresReleaseIDStrings(STR_RES *psRes);
/* Load a list of string ID's from a memory buffer
* id == 0 should be a default string which is returned if the
* requested string is not found.
*/
extern BOOL strresLoadFixedID(STR_RES *psRes, STR_ID *psID, UDWORD numID);
/* Return the ID number for an ID string */
extern BOOL strresGetIDNum(STR_RES *psRes, STRING *pIDStr, UDWORD *pIDNum);
/* Return the stored ID string that matches the string passed in */
extern BOOL strresGetIDString(STR_RES *psRes, STRING *pIDStr, STRING **ppStoredID);
/* Get the string from an ID number */
extern STRING *strresGetString(STR_RES *psRes, UDWORD id);
/* Load a string resource file */
extern BOOL strresLoad(STR_RES *psRes, UBYTE *pData, UDWORD size);
/* Return the the length of a STRING */
extern UDWORD stringLen(STRING *pStr);
/* Copy a STRING */
extern void stringCpy(STRING *pDest, STRING *pSrc);
/* Get the ID number for a string*/
extern UDWORD strresGetIDfromString(STR_RES *psRes, STRING *pString);
#endif

View File

@ -1,845 +0,0 @@
/* lex -a -p strres_ -o strres_l.c StrRes.l */
#define YYNEWLINE 10
#define INITIAL 0
#define COMMENT 2
#define QUOTE 4
#define SLCOMMENT 6
#define strres__endst 23
#define strres__nxtmax 1129
#define YY_LA_SIZE 3
static unsigned int strres__la_act[] = {
0, 14, 1, 14, 5, 14, 5, 14, 14, 6, 11, 0, 9, 9, 10, 7,
8, 4, 2, 3, 4, 13, 12, 13, 0
};
static unsigned char strres__look[] = {
0
};
static int strres__final[] = {
0, 0, 2, 4, 6, 7, 8, 9, 10, 11, 12, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24
};
#ifndef strres__state_t
#define strres__state_t unsigned char
#endif
static strres__state_t strres__begin[] = {
0, 0, 10, 10, 16, 16, 20, 20, 0
};
static strres__state_t strres__next[] = {
6, 6, 6, 6, 6, 6, 6, 6, 6, 3, 4, 6, 6, 3, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
3, 6, 2, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 6, 6, 6, 6, 6,
6, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
7, 14, 15, 9, 23, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
23, 23, 23, 23, 23, 23, 23, 9, 9, 9, 9, 9, 9, 9, 9, 9,
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
9, 23, 23, 23, 23, 9, 23, 9, 9, 9, 9, 9, 9, 9, 9, 9,
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
9, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 18, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 17, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 22, 22, 22, 22, 22, 22,
22, 22, 22, 22, 21, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 0
};
static strres__state_t strres__check[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5, 11, 14, 1, 22, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
~0U, ~0U, ~0U, ~0U, ~0U, ~0U, ~0U, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, ~0U, ~0U, ~0U, ~0U, 1, ~0U, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 19, ~0U, ~0U, ~0U, ~0U, ~0U, ~0U, ~0U, ~0U, ~0U, ~0U, ~0U, ~0U, ~0U, ~0U,
~0U, ~0U, ~0U, ~0U, ~0U, ~0U, ~0U, ~0U, ~0U, 19, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0
};
static strres__state_t strres__default[] = {
23, 23, 23, 23, 23, 23, 23, 23, 23, 1, 23, 23, 23, 23, 23, 23,
23, 23, 23, 16, 23, 23, 20, 0
};
static int strres__base[] = {
0, 214, 1130, 1130, 1130, 214, 1130, 1130, 1130, 1130, 337, 210, 1130, 1130, 248, 1130,
593, 1130, 1130, 839, 874, 1130, 250, 1130
};
/*
* Copyright 1988, 1992 by Mortice Kern Systems Inc. All rights reserved.
* All rights reserved.
*
* $Header: /u/rd/src/lex/rcs/strres_lex.c 1.57 1995/12/11 22:14:06 fredw Exp $
*
*/
#include <stdlib.h>
#include <stdio.h>
#if __STDC__
#define YY_ARGS(args) args
#else
#define YY_ARGS(args) ()
#endif
#ifdef LEX_WINDOWS
#include <windows.h>
/*
* define, if not already defined
* the flag YYEXIT, which will allow
* graceful exits from strres_lex()
* without resorting to calling exit();
*/
#ifndef YYEXIT
#define YYEXIT 1
#endif
/*
* the following is the handle to the current
* instance of a windows program. The user
* program calling strres_lex must supply this!
*/
#ifdef STRICT
extern HINSTANCE hInst;
#else
extern HANDLE hInst;
#endif
#endif /* LEX_WINDOWS */
/*
* Define m_textmsg() to an appropriate function for internationalized messages
* or custom processing.
*/
#ifndef I18N
#define m_textmsg(id, str, cls) (str)
#else /*I18N*/
extern char* m_textmsg YY_ARGS((int id, const char* str, char* cls));
#endif/*I18N*/
/*
* Include string.h to get definition of memmove() and size_t.
* If you do not have string.h or it does not declare memmove
* or size_t, you will have to declare them here.
*/
#include <string.h>
/* Uncomment next line if memmove() is not declared in string.h */
/*extern char * memmove();*/
/* Uncomment next line if size_t is not available in stdio.h or string.h */
/*typedef unsigned size_t;*/
/* Drop this when LATTICE provides memmove */
#ifdef LATTICE
#define memmove memcopy
#endif
/*
* YY_STATIC determines the scope of variables and functions
* declared by the lex scanner. It must be set with a -DYY_STATIC
* option to the compiler (it cannot be defined in the lex program).
*/
#ifdef YY_STATIC
/* define all variables as static to allow more than one lex scanner */
#define YY_DECL static
#else
/* define all variables as global to allow other modules to access them */
#define YY_DECL
#endif
/*
* You can redefine strres_getc. For YACC Tracing, compile this code
* with -DYYTRACE to get input from yt_getc
*/
#ifdef YYTRACE
extern int yt_getc YY_ARGS((void));
#define strres_getc() yt_getc()
#else
#define strres_getc() getc(strres_in) /* strres_lex input source */
#endif
/*
* the following can be redefined by the user.
*/
#ifdef YYEXIT
#define YY_FATAL(msg) { fprintf(strres_out, "strres_lex: %s\n", msg); strres_LexFatal = 1; }
#else /* YYEXIT */
#define YY_FATAL(msg) { fprintf(stderr, "strres_lex: %s\n", msg); exit(1); }
#endif /* YYEXIT */
#undef ECHO
#define ECHO fputs(strres_text, strres_out)
#define output(c) putc((c), strres_out) /* strres_lex sink for unmatched chars */
#define YY_INTERACTIVE 1 /* save micro-seconds if 0 */
#define BEGIN strres__start =
#define REJECT goto strres__reject
#define NLSTATE (strres__lastc = YYNEWLINE)
#define YY_INIT \
(strres__start = strres_leng = strres__end = 0, strres__lastc = YYNEWLINE)
#define strres_more() goto strres__more
#define strres_less(n) if ((n) < 0 || (n) > strres__end) ; \
else { YY_SCANNER; strres_leng = (n); YY_USER; }
YY_DECL void strres__reset YY_ARGS((void));
/* functions defined in libl.lib */
extern int strres_wrap YY_ARGS((void));
extern void strres_error YY_ARGS((char *fmt, ...));
extern void strres_comment YY_ARGS((char *term));
extern int strres_mapch YY_ARGS((int delim, int escape));
/*
* StrRes.l
*
* Lex file for parsing string resource files
*/
#include <stdio.h>
/* Allow frame header files to be singly included */
#define FRAME_LIB_INCLUDE
#include <string.h>
#include "types.h"
#include "debug.h"
#include "mem.h"
#include "heap.h"
#include "treap.h"
#include "strres.h"
#include "strresly.h"
/* Get the Yacc definitions */
#include "strres_y.h"
/* Maximum length for any TEXT value */
#define YYLMAX 255
/* Store for any string values */
extern STRING aText[TEXT_BUFFERS][YYLMAX];
static UDWORD currText=0;
// Note if in a comment
static BOOL inComment;
/* Pointer to the input buffer */
static UBYTE *pInputBuffer = NULL;
static UBYTE *pEndBuffer = NULL;
#undef strres_getc
#define strres_getc() (pInputBuffer != pEndBuffer ? *(pInputBuffer++) : EOF)
#ifndef YYLMAX
#define YYLMAX 100 /* token and pushback buffer size */
#endif /* YYLMAX */
/*
* If %array is used (or defaulted), strres_text[] contains the token.
* If %pointer is used, strres_text is a pointer to strres__tbuf[].
*/
YY_DECL char strres_text[YYLMAX+1];
#ifdef YY_DEBUG
#undef YY_DEBUG
#define YY_DEBUG(fmt, a1, a2) fprintf(stderr, fmt, a1, a2)
#else
#define YY_DEBUG(fmt, a1, a2)
#endif
/*
* The declaration for the lex scanner can be changed by
* redefining YYLEX or YYDECL. This must be done if you have
* more than one scanner in a program.
*/
#ifndef YYLEX
#define YYLEX strres_lex /* name of lex scanner */
#endif
#ifndef YYDECL
#define YYDECL int YYLEX YY_ARGS((void)) /* declaration for lex scanner */
#endif
/*
* stdin and stdout may not neccessarily be constants.
* If stdin and stdout are constant, and you want to save a few cycles, then
* #define YY_STATIC_STDIO 1 in this file or on the commandline when
* compiling this file
*/
#ifndef YY_STATIC_STDIO
#define YY_STATIC_STDIO 0
#endif
#if YY_STATIC_STDIO
YY_DECL FILE *strres_in = stdin;
YY_DECL FILE *strres_out = stdout;
#else
YY_DECL FILE *strres_in = (FILE *)0;
YY_DECL FILE *strres_out = (FILE *)0;
#endif
YY_DECL int strres_lineno = 1; /* line number */
/* strres__sbuf[0:strres_leng-1] contains the states corresponding to strres_text.
* strres_text[0:strres_leng-1] contains the current token.
* strres_text[strres_leng:strres__end-1] contains pushed-back characters.
* When the user action routine is active,
* strres__save contains strres_text[strres_leng], which is set to '\0'.
* Things are different when YY_PRESERVE is defined.
*/
static strres__state_t strres__sbuf [YYLMAX+1]; /* state buffer */
static int strres__end = 0; /* end of pushback */
static int strres__start = 0; /* start state */
static int strres__lastc = YYNEWLINE; /* previous char */
YY_DECL int strres_leng = 0; /* strres_text token length */
#ifdef YYEXIT
static int strres_LexFatal;
#endif /* YYEXIT */
#ifndef YY_PRESERVE /* the efficient default push-back scheme */
static char strres__save; /* saved strres_text[strres_leng] */
#define YY_USER { /* set up strres_text for user */ \
strres__save = strres_text[strres_leng]; \
strres_text[strres_leng] = 0; \
}
#define YY_SCANNER { /* set up strres_text for scanner */ \
strres_text[strres_leng] = strres__save; \
}
#else /* not-so efficient push-back for strres_text mungers */
static char strres__save [YYLMAX];
static char *strres__push = strres__save+YYLMAX;
#define YY_USER { \
size_t n = strres__end - strres_leng; \
strres__push = strres__save+YYLMAX - n; \
if (n > 0) \
memmove(strres__push, strres_text+strres_leng, n); \
strres_text[strres_leng] = 0; \
}
#define YY_SCANNER { \
size_t n = strres__save+YYLMAX - strres__push; \
if (n > 0) \
memmove(strres_text+strres_leng, strres__push, n); \
strres__end = strres_leng + n; \
}
#endif
#ifdef LEX_WINDOWS
/*
* When using the windows features of lex,
* it is necessary to load in the resources being
* used, and when done with them, the resources must
* be freed up, otherwise we have a windows app that
* is not following the rules. Thus, to make strres_lex()
* behave in a windows environment, create a new
* strres_lex() which will call the original strres_lex() as
* another function call. Observe ...
*/
/*
* The actual lex scanner (usually strres_lex(void)).
* NOTE: you should invoke strres__init() if you are calling strres_lex()
* with new input; otherwise old lookaside will get in your way
* and strres_lex() will die horribly.
*/
static int win_strres_lex(); /* prototype for windows strres_lex handler */
YYDECL {
int wReturnValue;
HANDLE hRes_table;
unsigned short far *old_strres__la_act; /* remember previous pointer values */
short far *old_strres__final;
strres__state_t far *old_strres__begin;
strres__state_t far *old_strres__next;
strres__state_t far *old_strres__check;
strres__state_t far *old_strres__default;
short far *old_strres__base;
/*
* the following code will load the required
* resources for a Windows based parser.
*/
hRes_table = LoadResource (hInst,
FindResource (hInst, "UD_RES_strres_LEX", "strres_LEXTBL"));
/*
* return an error code if any
* of the resources did not load
*/
if (hRes_table == NULL)
return (0);
/*
* the following code will lock the resources
* into fixed memory locations for the scanner
* (and remember previous pointer locations)
*/
old_strres__la_act = strres__la_act;
old_strres__final = strres__final;
old_strres__begin = strres__begin;
old_strres__next = strres__next;
old_strres__check = strres__check;
old_strres__default = strres__default;
old_strres__base = strres__base;
strres__la_act = (unsigned short far *)LockResource (hRes_table);
strres__final = (short far *)(strres__la_act + Sizeof_strres__la_act);
strres__begin = (strres__state_t far *)(strres__final + Sizeof_strres__final);
strres__next = (strres__state_t far *)(strres__begin + Sizeof_strres__begin);
strres__check = (strres__state_t far *)(strres__next + Sizeof_strres__next);
strres__default = (strres__state_t far *)(strres__check + Sizeof_strres__check);
strres__base = (strres__state_t far *)(strres__default + Sizeof_strres__default);
/*
* call the standard strres_lex() code
*/
wReturnValue = win_strres_lex();
/*
* unlock the resources
*/
UnlockResource (hRes_table);
/*
* and now free the resource
*/
FreeResource (hRes_table);
/*
* restore previously saved pointers
*/
strres__la_act = old_strres__la_act;
strres__final = old_strres__final;
strres__begin = old_strres__begin;
strres__next = old_strres__next;
strres__check = old_strres__check;
strres__default = old_strres__default;
strres__base = old_strres__base;
return (wReturnValue);
} /* end function */
static int win_strres_lex() {
#else /* LEX_WINDOWS */
/*
* The actual lex scanner (usually strres_lex(void)).
* NOTE: you should invoke strres__init() if you are calling strres_lex()
* with new input; otherwise old lookaside will get in your way
* and strres_lex() will die horribly.
*/
YYDECL {
#endif /* LEX_WINDOWS */
register int c, i, strres_base;
unsigned strres_st; /* state */
int strres_fmin, strres_fmax; /* strres__la_act indices of final states */
int strres_oldi, strres_oleng; /* base i, strres_leng before look-ahead */
int strres_eof; /* 1 if eof has already been read */
#if !YY_STATIC_STDIO
if (strres_in == (FILE *)0)
strres_in = stdin;
if (strres_out == (FILE *)0)
strres_out = stdout;
#endif
#ifdef YYEXIT
strres_LexFatal = 0;
#endif /* YYEXIT */
strres_eof = 0;
i = strres_leng;
YY_SCANNER;
strres__again:
strres_leng = i;
/* determine previous char. */
if (i > 0)
strres__lastc = strres_text[i-1];
/* scan previously accepted token adjusting strres_lineno */
while (i > 0)
if (strres_text[--i] == YYNEWLINE)
strres_lineno++;
/* adjust pushback */
strres__end -= strres_leng;
if (strres__end > 0)
memmove(strres_text, strres_text+strres_leng, (size_t) strres__end);
i = 0;
strres_oldi = i;
/* run the state machine until it jams */
strres_st = strres__begin[strres__start + ((strres__lastc == YYNEWLINE) ? 1 : 0)];
strres__sbuf[i] = (strres__state_t) strres_st;
do {
YY_DEBUG(m_textmsg(1547, "<state %d, i = %d>\n", "I num1 num2"), strres_st, i);
if (i >= YYLMAX) {
YY_FATAL(m_textmsg(1548, "Token buffer overflow", "E"));
#ifdef YYEXIT
if (strres_LexFatal)
return -2;
#endif /* YYEXIT */
} /* endif */
/* get input char */
if (i < strres__end)
c = strres_text[i]; /* get pushback char */
else if (!strres_eof && (c = strres_getc()) != EOF) {
strres__end = i+1;
strres_text[i] = (char) c;
} else /* c == EOF */ {
c = EOF; /* just to make sure... */
if (i == strres_oldi) { /* no token */
strres_eof = 0;
if (strres_wrap())
return 0;
else
goto strres__again;
} else {
strres_eof = 1; /* don't re-read EOF */
break;
}
}
YY_DEBUG(m_textmsg(1549, "<input %d = 0x%02x>\n", "I num hexnum"), c, c);
/* look up next state */
while ((strres_base = strres__base[strres_st]+(unsigned char)c) > strres__nxtmax
|| strres__check[strres_base] != (strres__state_t) strres_st) {
if (strres_st == strres__endst)
goto strres__jammed;
strres_st = strres__default[strres_st];
}
strres_st = strres__next[strres_base];
strres__jammed: ;
strres__sbuf[++i] = (strres__state_t) strres_st;
} while (!(strres_st == strres__endst || (YY_INTERACTIVE && strres__base[strres_st] > strres__nxtmax && strres__default[strres_st] == strres__endst)));
YY_DEBUG(m_textmsg(1550, "<stopped %d, i = %d>\n", "I num1 num2"), strres_st, i);
if (strres_st != strres__endst)
++i;
/* search backward for a final state */
while (--i > strres_oldi) {
strres_st = strres__sbuf[i];
if ((strres_fmin = strres__final[strres_st]) < (strres_fmax = strres__final[strres_st+1]))
goto strres__found; /* found final state(s) */
}
/* no match, default action */
i = strres_oldi + 1;
output(strres_text[strres_oldi]);
goto strres__again;
strres__found:
YY_DEBUG(m_textmsg(1551, "<final state %d, i = %d>\n", "I num1 num2"), strres_st, i);
strres_oleng = i; /* save length for REJECT */
/* pushback look-ahead RHS */
if ((c = (int)(strres__la_act[strres_fmin]>>9) - 1) >= 0) { /* trailing context? */
unsigned char *bv = strres__look + c*YY_LA_SIZE;
static unsigned char bits [8] = {
1<<0, 1<<1, 1<<2, 1<<3, 1<<4, 1<<5, 1<<6, 1<<7
};
while (1) {
if (--i < strres_oldi) { /* no / */
i = strres_oleng;
break;
}
strres_st = strres__sbuf[i];
if (bv[(unsigned)strres_st/8] & bits[(unsigned)strres_st%8])
break;
}
}
/* perform action */
strres_leng = i;
YY_USER;
switch (strres__la_act[strres_fmin] & 0777) {
case 0:
{
strcpy(aText[currText], strres_text);
strres_lval.sval = aText[currText];
currText = (currText + 1) % TEXT_BUFFERS;
return TEXT;
}
break;
case 1:
{ BEGIN QUOTE; }
break;
case 2:
{ BEGIN 0; }
break;
case 3:
{ strres_error("Unexpected end of line in string"); }
break;
case 4:
{
strcpy(aText[currText], strres_text);
strres_lval.sval = aText[currText];
currText = (currText + 1) % TEXT_BUFFERS;
return QTEXT;
}
break;
case 5:
;
break;
case 6:
{ inComment=TRUE; BEGIN COMMENT; }
break;
case 7:
case 8:
{ inComment=FALSE; BEGIN 0; }
break;
case 9:
case 10:
;
break;
case 11:
{ BEGIN SLCOMMENT; }
break;
case 12:
{ BEGIN 0; }
break;
case 13:
;
break;
case 14:
return strres_text[0];
break;
}
YY_SCANNER;
i = strres_leng;
goto strres__again; /* action fell though */
}
/*
* Safely switch input stream underneath LEX
*/
typedef struct strres__save_block_tag {
FILE * oldfp;
int oldline;
int oldend;
int oldstart;
int oldlastc;
int oldleng;
char savetext[YYLMAX+1];
strres__state_t savestate[YYLMAX+1];
} YY_SAVED;
YY_SAVED *
strres_SaveScan(FILE *fp)
{
YY_SAVED * p;
if ((p = (YY_SAVED *) malloc(sizeof(*p))) == NULL)
return p;
p->oldfp = strres_in;
p->oldline = strres_lineno;
p->oldend = strres__end;
p->oldstart = strres__start;
p->oldlastc = strres__lastc;
p->oldleng = strres_leng;
(void) memcpy(p->savetext, strres_text, sizeof strres_text);
(void) memcpy((char *) p->savestate, (char *) strres__sbuf,
sizeof strres__sbuf);
strres_in = fp;
strres_lineno = 1;
YY_INIT;
return p;
}
/*f
* Restore previous LEX state
*/
void
strres_RestoreScan(YY_SAVED *p)
{
if (p == NULL)
return;
strres_in = p->oldfp;
strres_lineno = p->oldline;
strres__end = p->oldend;
strres__start = p->oldstart;
strres__lastc = p->oldlastc;
strres_leng = p->oldleng;
(void) memcpy(strres_text, p->savetext, sizeof strres_text);
(void) memcpy((char *) strres__sbuf, (char *) p->savestate,
sizeof strres__sbuf);
free(p);
}
/*
* User-callable re-initialization of strres_lex()
*/
void
strres__reset()
{
YY_INIT;
strres_lineno = 1; /* line number */
}
/* Set the current input buffer for the lexer */
void strresSetInputBuffer(UBYTE *pBuffer, UDWORD size)
{
pInputBuffer = pBuffer;
pEndBuffer = pBuffer + size;
/* Reset the lexer incase it's been used before */
strres__reset();
}
void strresGetErrorData(int *pLine, char **ppText)
{
*pLine = strres_lineno;
*ppText = strres_text;
}
int strres_wrap(void)
{
if (inComment)
{
DBERROR(("Warning: reched end of file in a comment"));
}
return 1;
}

View File

@ -1,138 +0,0 @@
%{
/*
* StrRes.l
*
* Lex file for parsing string resource files
*/
#ifndef PSX
#include <stdio.h>
#else
/* A few definitions so the lex generated code will compile on the PSX.
* These shouldn't actually be used by any code that is run on the PSX, it
* just keeps the compiler happy.
*/
typedef signed int FILE;
#define stderr 0
#define stdin 0
#define stdout 0
static int fprintf(FILE* f,char* c,...)
{
return 0;
}
#endif
/* Allow frame header files to be singly included */
#define FRAME_LIB_INCLUDE
#include <string.h>
#include "types.h"
#include "debug.h"
#include "mem.h"
#include "heap.h"
#include "treap.h"
#include "strres.h"
#include "strresly.h"
/* Get the Yacc definitions */
#include "strres_parser.h"
void strres_error(char *pMessage,...);
/* Maximum length for any TEXT value */
#define YYLMAX 255
/* Store for any string values */
extern STRING aText[TEXT_BUFFERS][YYLMAX];
static UDWORD currText=0;
// Note if in a comment
static BOOL inComment;
/* Pointer to the input buffer */
static UBYTE *pInputBuffer = NULL;
static UBYTE *pEndBuffer = NULL;
#define YY_INPUT(buf,result,max_size) \
if (pInputBuffer != pEndBuffer) { \
buf[0] = *(pInputBuffer++); result = 1; \
} else { \
buf[0] = EOF; result = YY_NULL; \
}
%}
%option nounput
%option prefix="strres_"
%x COMMENT
%x QUOTE
%x SLCOMMENT
%%
/* Match text values */
[a-zA-Z][-0-9_a-zA-Z]* {
strcpy(aText[currText], strres_text);
strres_lval.sval = aText[currText];
currText = (currText + 1) % TEXT_BUFFERS;
return TEXT;
}
/* Match quoted text */
\" { BEGIN QUOTE; }
<QUOTE>\" { BEGIN 0; }
<QUOTE>\n { strres_error("Unexpected end of line in string"); }
<QUOTE>[^\"\n]* {
strcpy(aText[currText], strres_text);
strres_lval.sval = aText[currText];
currText = (currText + 1) % TEXT_BUFFERS;
return QTEXT;
}
/* Skip white space */
[ \t\n\x0d\x0a] ;
/* Strip comments */
"/*" { inComment=TRUE; BEGIN COMMENT; }
<COMMENT>"*/" |
<COMMENT>"*/"\n { inComment=FALSE; BEGIN 0; }
<COMMENT>. |
<COMMENT>\n ;
/* Strip single line comments */
"//" { BEGIN SLCOMMENT; }
<SLCOMMENT>\n { BEGIN 0; }
<SLCOMMENT>[^\n]* ;
/* Match anything that's been missed and pass it as a char */
. return strres_text[0];
%%
/* Set the current input buffer for the lexer */
void strresSetInputBuffer(UBYTE *pBuffer, UDWORD size)
{
pInputBuffer = pBuffer;
pEndBuffer = pBuffer + size;
/* Reset the lexer incase it's been used before */
// YY_FLUSH_BUFFER;
yy_flush_buffer( YY_CURRENT_BUFFER );
}
void strresGetErrorData(int *pLine, char **ppText)
{
*pLine = strres_lineno;
*ppText = strres_text;
}
int strres_wrap(void)
{
if (inComment)
{
DBERROR(("Warning: reched end of file in a comment"));
}
return 1;
}

View File

@ -1,65 +0,0 @@
%{
/*
* StrRes.y
*
* Yacc file for parsing String Resource files
*/
/* Allow frame header files to be singly included */
#define FRAME_LIB_INCLUDE
#include "types.h"
#include "debug.h"
#include "mem.h"
#include "heap.h"
#include "treap.h"
#include "strres.h"
#include "strresly.h"
int strres_lex (void);
/*
* A simple error reporting routine
*/
void strres_error(const char *pMessage,...)
{
int line;
char *pText;
strresGetErrorData(&line, &pText);
DBERROR(("STRRES file parse error:\n%s at line %d\nText: '%s'\n",
pMessage, line, pText));
}
%}
%name-prefix="strres_"
%union {
STRING *sval;
}
/* value tokens */
%token <sval> TEXT
%token <sval> QTEXT /* Text with double quotes surrounding it */
%%
file: line
| file line
;
line: TEXT QTEXT
{
/* Pass the text string to the string manager */
if (!strresStoreString(psCurrRes, $1, $2))
{
YYABORT;
printf("Hello. I'm the parser.\n");
}
}
;
%%

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +0,0 @@
typedef union {
STRING *sval;
} YYSTYPE;
#define TEXT 257
#define QTEXT 258
extern YYSTYPE strres_lval;

View File

@ -1,31 +0,0 @@
/*
* StrResLY.h
*
* Interface to the string resource lex and yacc functions.
*/
#ifndef _strresly_h
#define _strresly_h
/* Maximum number of characters in a directory entry */
#define FILE_MAXCHAR 255
/* Maximum number of TEXT items in any one Yacc rule */
#define TEXT_BUFFERS 10
/* The string resource currently being loaded */
extern STR_RES *psCurrRes;
/* Set the current input buffer for the lexer - used by strresLoad */
extern void strresSetInputBuffer(UBYTE *pBuffer, UDWORD size);
/* Give access to the line number and current text for error messages */
extern void strresGetErrorData(int *pLine, char **ppText);
/* Call the yacc parser */
extern int strres_parse(void);
/* Store a string */
extern BOOL strresStoreString(STR_RES *psRes, STRING *pID, STRING *pString);
#endif

View File

@ -1,456 +0,0 @@
/*
* Treap.c
*
* Balanced tree implementation
*
*/
#include <string.h>
/* Allow frame header files to be singly included */
#define FRAME_LIB_INCLUDE
#include "types.h"
#include "debug.h"
#include "mem.h"
#include "heap.h"
#include "treap.h"
/* Position of the last call */
static SDWORD cLine;
static STRING *pCFile;
static STRING pCFileNone[] = "None";
/* Store the location in C code at which a call to the heap was made */
void treapSetCallPos(STRING *pFileName, SDWORD lineNumber)
{
cLine = lineNumber;
pCFile = (STRING *)MALLOC(strlen(pFileName) + 1);
if (pCFile)
{
strcpy(pCFile, pFileName);
}
else
{
pCFile = pCFileNone;
}
}
/* Default comparison function - assumes keys are ints */
static SDWORD defaultCmp(UDWORD key1, UDWORD key2)
{
if (key1 < key2)
{
return -1;
}
else if (key1 > key2)
{
return 1;
}
return 0;
}
/* A useful comparison function - keys are string pointers */
SDWORD treapStringCmp(UDWORD key1, UDWORD key2)
{
SDWORD result;
STRING *pStr1 = (STRING *)key1;
STRING *pStr2 = (STRING *)key2;
result = strcmp(pStr1,pStr2);
if (result<0) return -1;
if (result>0) return 1;
return 0;
}
/* Function to create a treap
* Pass in key comparison function,
* initial number of nodes to allocate,
* number of additional nodes to allocate when extending.
*/
BOOL treapCreate(TREAP **ppsTreap, TREAP_CMP cmp, UDWORD init, UDWORD ext)
{
*ppsTreap = (TREAP*)MALLOC(sizeof(TREAP));
if (!(*ppsTreap))
{
DBERROR(("treapCreate: Out of memory"));
return FALSE;
}
if (!HEAP_CREATE(&((*ppsTreap)->psNodes), sizeof(TREAP_NODE), init, ext))
{
DBERROR(("treapCreate: Out of memory"));
FREE(*ppsTreap);
return FALSE;
}
// Store the comparison function if there is one, use the default otherwise
if (cmp)
{
(*ppsTreap)->cmp = cmp;
}
else
{
(*ppsTreap)->cmp = defaultCmp;
}
// Initialise the tree to nothing
(*ppsTreap)->psRoot = NULL;
#if DEBUG_TREAP
// Store the call location
(*ppsTreap)->pFile = pCFile;
(*ppsTreap)->line = cLine;
#endif
return TRUE;
}
/* Rotate a tree to the right
* (Make left sub tree the root and the root the right sub tree)
*/
static void treapRotRight(TREAP_NODE **ppsRoot)
{
TREAP_NODE *psNewRoot;
psNewRoot = (*ppsRoot)->psLeft;
(*ppsRoot)->psLeft = psNewRoot->psRight;
psNewRoot->psRight = *ppsRoot;
*ppsRoot = psNewRoot;
}
/* Rotate a tree to the left
* (Make right sub tree the root and the root the left sub tree)
*/
static void treapRotLeft(TREAP_NODE **ppsRoot)
{
TREAP_NODE *psNewRoot;
psNewRoot = (*ppsRoot)->psRight;
(*ppsRoot)->psRight = psNewRoot->psLeft;
psNewRoot->psLeft = *ppsRoot;
*ppsRoot = psNewRoot;
}
/* Recursive function to add an object to a tree */
void treapAddNode(TREAP_NODE **ppsRoot, TREAP_NODE *psNew, TREAP_CMP cmp)
{
if (*ppsRoot == NULL)
{
// Make the node the root of the tree
*ppsRoot = psNew;
}
else if (cmp(psNew->key, (*ppsRoot)->key) < 0)
{
// Node less than root, insert to the left of the tree
treapAddNode(&(*ppsRoot)->psLeft, psNew, cmp);
// Sort the priority
if ((*ppsRoot)->priority > (*ppsRoot)->psLeft->priority)
{
// rotate tree right
treapRotRight(ppsRoot);
}
}
else
{
// Node greater than root, insert to the right of the tree
treapAddNode(&(*ppsRoot)->psRight, psNew, cmp);
// Sort the priority
if ((*ppsRoot)->priority > (*ppsRoot)->psRight->priority)
{
// rotate tree left
treapRotLeft(ppsRoot);
}
}
}
/* Add an object to a treap
*/
BOOL treapAdd(TREAP *psTreap, UDWORD key, void *pObj)
{
TREAP_NODE *psNew;
if (!HEAP_ALLOC(psTreap->psNodes, (void**)&psNew))
{
return FALSE;
}
psNew->priority = (UDWORD)rand();
psNew->key = key;
psNew->pObj = pObj;
psNew->psLeft = NULL;
psNew->psRight = NULL;
#if DEBUG_TREAP
// Store the call location
psNew->pFile = pCFile;
psNew->line = cLine;
#endif
treapAddNode(&psTreap->psRoot, psNew, psTreap->cmp);
return TRUE;
}
/* Recursively find and remove a node from the tree */
TREAP_NODE *treapDelRec(TREAP_NODE **ppsRoot, UDWORD key,
TREAP_CMP cmp)
{
TREAP_NODE *psFound;
if (*ppsRoot == NULL)
{
// not found
return NULL;
}
switch (cmp(key, (*ppsRoot)->key))
{
case -1:
// less than
return treapDelRec(&(*ppsRoot)->psLeft, key, cmp);
break;
case 1:
// greater than
return treapDelRec(&(*ppsRoot)->psRight, key, cmp);
break;
case 0:
// equal - either remove or push down the tree to balance it
if ((*ppsRoot)->psLeft == NULL && (*ppsRoot)->psRight == NULL)
{
// no sub trees, remove
psFound = *ppsRoot;
*ppsRoot = NULL;
return psFound;
}
else if ((*ppsRoot)->psLeft == NULL)
{
// one sub tree, replace
psFound = *ppsRoot;
*ppsRoot = psFound->psRight;
return psFound;
}
else if ((*ppsRoot)->psRight == NULL)
{
// one sub tree, replace
psFound = *ppsRoot;
*ppsRoot = psFound->psLeft;
return psFound;
}
else
{
// two sub trees, push the node down and recurse
if ((*ppsRoot)->psLeft->priority > (*ppsRoot)->psRight->priority)
{
// rotate right and recurse
treapRotLeft(ppsRoot);
return treapDelRec(&(*ppsRoot)->psLeft, key, cmp);
}
else
{
// rotate left and recurse
treapRotRight(ppsRoot);
return treapDelRec(&(*ppsRoot)->psRight, key, cmp);
}
}
break;
default:
ASSERT((FALSE, "treapDelRec: invalid return from comparison"));
break;
}
return NULL;
}
/* Remove an object from the treap */
BOOL treapDel(TREAP *psTreap, UDWORD key)
{
TREAP_NODE *psDel;
// Find the node to remove
psDel = treapDelRec(&psTreap->psRoot, key, psTreap->cmp);
if (!psDel)
{
return FALSE;
}
// Release the node
#ifdef DEBUG
FREE(psDel->pFile);
#endif
HEAP_FREE(psTreap->psNodes, psDel);
return TRUE;
}
/* Recurisvely find an object in a treap */
void *treapFindRec(TREAP_NODE *psRoot, UDWORD key, TREAP_CMP cmp)
{
if (psRoot == NULL)
{
return NULL;
}
switch (cmp(key, psRoot->key))
{
case 0:
// equal
return psRoot->pObj;
break;
case -1:
return treapFindRec(psRoot->psLeft, key, cmp);
break;
case 1:
return treapFindRec(psRoot->psRight, key, cmp);
break;
default:
ASSERT((FALSE, "treapFindRec: invalid return from comparison"));
break;
}
return NULL;
}
/* Find an object in a treap */
void *treapFind(TREAP *psTreap, UDWORD key)
{
return treapFindRec(psTreap->psRoot, key, psTreap->cmp);
}
#if DEBUG_TREAP
/* Recursively print out where the nodes were allocated */
static void treapReportRec(TREAP_NODE *psRoot)
{
if (psRoot)
{
DBPRINTF((" %s, line %d\n", psRoot->pFile, psRoot->line));
treapReportRec(psRoot->psLeft);
treapReportRec(psRoot->psRight);
}
}
#endif
/* Recursively free a treap */
static void treapDestroyRec(TREAP_NODE *psRoot, OBJ_HEAP *psHeap)
{
if (psRoot == NULL)
{
return;
}
// free the sub branches
treapDestroyRec(psRoot->psLeft, psHeap);
treapDestroyRec(psRoot->psRight, psHeap);
// free the root
HEAP_FREE(psHeap, psRoot);
}
/* Release all the nodes in the treap */
void treapReset(TREAP *psTreap)
{
treapDestroyRec(psTreap->psRoot, psTreap->psNodes);
psTreap->psRoot = NULL;
}
/* Destroy a treap and release all the memory associated with it */
void treapDestroy(TREAP *psTreap)
{
#if DEBUG_TREAP
if (psTreap->psRoot)
{
DBPRINTF(("treapDestroy: %s, line %d : nodes still in the tree\n",
psTreap->pFile, psTreap->line));
treapReportRec(psTreap->psRoot);
}
FREE(psTreap->pFile);
#endif
treapDestroyRec(psTreap->psRoot, psTreap->psNodes);
HEAP_DESTROY(psTreap->psNodes);
FREE(psTreap);
}
/* Recursively display the treap structure */
void treapDisplayRec(TREAP_NODE *psRoot, UDWORD indent)
{
UDWORD i;
// Display the root
#if DEBUG_TREAP
DBPRINTF(("%s, line %d : %d,%d\n",
psRoot->pFile, psRoot->line,
psRoot->key, psRoot->priority));
#else
DBPRINTF(("%d,%d\n", psRoot->key, psRoot->priority));
#endif
// Display the left of the tree
if (psRoot->psLeft)
{
for(i=0; i<indent; i++)
{
DBPRINTF((" "));
}
DBPRINTF(("L "));
treapDisplayRec(psRoot->psLeft, indent+1);
}
// Display the right of the tree
if (psRoot->psRight)
{
for(i=0; i<indent; i++)
{
DBPRINTF((" "));
}
DBPRINTF(("R "));
treapDisplayRec(psRoot->psRight, indent+1);
}
}
/* Display the treap structure using DBPRINTF */
void treapDisplay(TREAP *psTreap)
{
if (psTreap->psRoot)
{
treapDisplayRec(psTreap->psRoot, 0);
}
}
void *treapGetSmallestRec(TREAP_NODE *psRoot)
{
if (psRoot->psLeft == NULL)
{
return psRoot->pObj;
}
return treapGetSmallestRec(psRoot->psLeft);
}
/* Return the object with the smallest key in the treap
* This is useful if the objects in the treap need to be
* deallocated. i.e. getSmallest, delete from treap, free memory
*/
void *treapGetSmallest(TREAP *psTreap)
{
if (psTreap->psRoot == NULL)
{
return NULL;
}
return treapGetSmallestRec(psTreap->psRoot);
}

View File

@ -1,185 +0,0 @@
/*
* Treap.h
*
* A balanced binary tree implementation
*
* Overhead for using the treap is -
* Overhead for the heap used by the treap :
* 24 bytes + 4 bytes per extension
* 12 bytes for the root
* 20 bytes per node
*/
#ifndef _treap_h
#define _treap_h
#include "types.h"
#include "debug.h"
#include "mem.h"
#include "heap.h"
/* Turn on and off the treap debugging */
#ifdef DEBUG
#define DEBUG_TREAP TRUE
#else
#undef DEBUG_TREAP
#endif
/* Function type for the object compare
* return -1 for less
* 1 for more
* 0 for equal
*/
typedef SDWORD (*TREAP_CMP)(UDWORD key1, UDWORD key2);
/* The basic elements in the treap node.
* These are done as macros so that the memory system
* can use parts of the treap system.
*/
#define TREAP_NODE_BASE \
UDWORD key; /* The key to sort the node on */ \
UDWORD priority; /* Treap priority */ \
void *pObj; /* The object stored in the treap */ \
struct _treap_node *psLeft, *psRight /* The sub trees */
/* The debug info */
#define TREAP_NODE_DEBUG \
STRING *pFile; /* file the node was created in */ \
SDWORD line /* line the node was created at */
typedef struct _treap_node
{
TREAP_NODE_BASE;
#if DEBUG_TREAP
TREAP_NODE_DEBUG;
#endif
} TREAP_NODE;
/* Treap data structure */
typedef struct _treap
{
TREAP_CMP cmp; // comparison function
OBJ_HEAP *psNodes; // node heap
TREAP_NODE *psRoot; // root of the tree
#if DEBUG_TREAP
STRING *pFile; // file the treap was created in
SDWORD line; // line the treap was created at
#endif
} TREAP;
/****************************************************************************************/
/* Function Protoypes */
/* */
/* These should not be called directly - use the macros below */
/* Store the location in C code at which a call to the heap was made */
extern void treapSetCallPos(STRING *pFileName, SDWORD lineNumber);
/* Function type for object equality */
//typedef BOOL (*TREAP_EQUAL)(void *pObj1, void *pObj2);
/* Function to create a treap
* Pass in key comparison function
* Initial number of nodes to allocate
* Number of additional nodes to allocate when extending
*/
extern BOOL treapCreate(TREAP **ppsTreap, TREAP_CMP cmp, UDWORD init, UDWORD ext);
/* Add an object to a treap
*/
extern BOOL treapAdd(TREAP *psTreap, UDWORD key, void *pObj);
/* Remove an object from the treap */
extern BOOL treapDel(TREAP *psTreap, UDWORD key);
/* Find an object in a treap */
extern void *treapFind(TREAP *psTreap, UDWORD key);
/* Release all the nodes in the treap */
extern void treapReset(TREAP *psTreap);
/* Destroy a treap and release all the memory associated with it */
extern void treapDestroy(TREAP *psTreap);
/* Display the treap structure using DBPRINTF */
extern void treapDisplay(TREAP *psTreap);
/* Return the object with the smallest key in the treap
* This is useful if the objects in the treap need to be
* deallocated. i.e. getSmallest, delete from treap, free memory
*/
extern void *treapGetSmallest(TREAP *psTreap);
/****************************************************************************************/
/* Comparison Functions */
/* A useful comparison function - keys are string pointers */
extern SDWORD treapStringCmp(UDWORD key1, UDWORD key2);
/****************************************************************************************/
/* Macro definitions */
#if DEBUG_TREAP
// debugging versions of the TREAP calls
#define TREAP_CREATE(ppsTreap, cmp, init, ext) \
(treapSetCallPos(__FILE__, __LINE__), \
treapCreate(ppsTreap, cmp, init, ext))
#define TREAP_ADD(psTreap, key, pObject) \
(treapSetCallPos(__FILE__, __LINE__), \
treapAdd(psTreap, key, pObject))
#define TREAP_DEL(psTreap, key) \
treapDel(psTreap, key)
#define TREAP_FIND(psTreap, key) \
treapFind(psTreap, key)
#define TREAP_RESET(psTreap) \
treapReset(psTreap)
#define TREAP_DESTROY(psTreap) \
treapDestroy(psTreap)
#define TREAP_DISPLAY(psTreap) \
treapDisplay(psTreap)
#define TREAP_GETSMALLEST(psTreap) \
treapGetSmallest(psTreap)
#else
// release versions of the TREAP calls
#define TREAP_CREATE(ppsTreap, cmp, init, ext) \
treapCreate(ppsTreap, cmp, init, ext)
#define TREAP_ADD(psTreap, key, pObject) \
treapAdd(psTreap, key, pObject)
#define TREAP_DEL(psTreap, key) \
treapDel(psTreap, key)
#define TREAP_FIND(psTreap, key) \
treapFind(psTreap, key)
#define TREAP_RESET(psTreap) \
treapReset(psTreap)
#define TREAP_DESTROY(psTreap) \
treapDestroy(psTreap)
#define TREAP_DISPLAY(psTreap)
#define TREAP_GETSMALLEST(psTreap) \
treapGetSmallest(psTreap)
#endif
#endif

View File

@ -1,32 +0,0 @@
/*
* TreapInt.h
*
* Internal function calls for the treap system to allow it
* to be used by the memory system.
*
*/
#ifndef _treapint_h
#define _treapint_h
/* Check the header files have been included from frame.h if they
* are used outside of the framework library.
*/
#if !defined(_frame_h) && !defined(FRAME_LIB_INCLUDE)
#error Framework header files MUST be included from Frame.h ONLY.
#endif
/* Recursive function to add an object to a tree */
extern void treapAddNode(TREAP_NODE **ppsRoot, TREAP_NODE *psNew, TREAP_CMP cmp);
/* Recursively find and remove a node from the tree */
extern TREAP_NODE *treapDelRec(TREAP_NODE **ppsRoot, UDWORD key,
TREAP_CMP cmp);
/* Recurisvely find an object in a treap */
extern void *treapFindRec(TREAP_NODE *psRoot, UDWORD key, TREAP_CMP cmp);
/* Recursively display the treap structure */
extern void treapDisplayRec(TREAP_NODE *psRoot, UDWORD indent);
#endif

View File

@ -1,242 +0,0 @@
/*
* Trig.c
*
* Trig lookup tables
*
*/
/* Allow frame header files to be singly included */
#define FRAME_LIB_INCLUDE
#include <assert.h>
#include "types.h"
#include "debug.h"
#include "mem.h"
#include "fractions.h"
#include "trig.h"
#define PI 3.141592654
/* Number of steps between -1 and 1 for the inverse tables */
#define TRIG_ACCURACY 4096
#define TRIG_ACCMASK 0x0fff
/* Number of entries in sqrt table */
#define SQRT_ACCURACY 4096
#define SQRT_ACCBITS 12
/* The trig functions */
#define SINFUNC (FRACT)sin
#define COSFUNC (FRACT)cos
#define ASINFUNC (FRACT)asin
#define ACOSFUNC (FRACT)acos
static FRACT *aSin;
static FRACT *aCos;
static FRACT *aInvCos;
/* Square root table - not needed on PSX cos there is a fast hardware sqrt */
static FRACT *aSqrt;
static FRACT *aInvSin;
/* Initialise the Trig tables */
BOOL trigInitialise(void)
{
FRACT val, inc;
UDWORD count;
// Allocate the tables
aSin=(FRACT*)MALLOC(sizeof(FRACT) * TRIG_DEGREES);
if (!aSin)
{
return FALSE;
}
aCos=(FRACT*)MALLOC(sizeof(FRACT) * TRIG_DEGREES);
if (!aCos)
{
return FALSE;
}
aInvSin=(FRACT*)MALLOC(sizeof(FRACT) * TRIG_ACCURACY);
if (!aInvSin)
{
return FALSE;
}
aInvCos=(FRACT*)MALLOC(sizeof(FRACT) * TRIG_ACCURACY);
if (!aInvCos)
{
return FALSE;
}
//#ifndef PSX
aSqrt=(FRACT*)MALLOC(sizeof(FRACT) * SQRT_ACCURACY);
if (!aSqrt)
{
return FALSE;
}
//#endif
// Initialise the tables
// inc = 2*PI/TRIG_DEGREES
inc = FRACTmul(FRACTCONST(2,1), FRACTCONST(PI,TRIG_DEGREES));
val = FRACTCONST(0,1);
for(count = 0; count < TRIG_DEGREES; count++)
{
aSin[count] = SINFUNC(val);
aCos[count] = COSFUNC(val);
val += inc;
}
inc = FRACTCONST(2,TRIG_ACCURACY-1);
val = FRACTCONST(-1,1);
for(count =0; count < TRIG_ACCURACY; count++)
{
aInvSin[count] = FRACTmul( ASINFUNC(val), FRACTCONST(TRIG_DEGREES/2, PI) );
aInvCos[count] = FRACTmul( ACOSFUNC(val), FRACTCONST(TRIG_DEGREES/2, PI) );
val += inc;
}
//#ifndef PSX
// Build the sqrt table
for(count=0; count < SQRT_ACCURACY; count++)
{
val = (FRACT)count / (FRACT)(SQRT_ACCURACY / 2);
aSqrt[count]= (FRACT)sqrt(val);
}
//#endif
return TRUE;
}
/* Shutdown the trig tables */
void trigShutDown(void)
{
FREE(aSin);
FREE(aCos);
FREE(aInvSin);
FREE(aInvCos);
FREE(aSqrt);
}
/* Access the trig tables */
FRACT trigSin(SDWORD angle)
{
if (angle < 0)
{
angle = (-angle) % TRIG_DEGREES;
angle = TRIG_DEGREES - angle;
}
else
{
angle = angle % TRIG_DEGREES;
}
return aSin[angle % TRIG_DEGREES];
}
FRACT trigCos(SDWORD angle)
{
if (angle < 0)
{
angle = (-angle) % TRIG_DEGREES;
angle = TRIG_DEGREES - angle;
}
else
{
angle = angle % TRIG_DEGREES;
}
return aCos[angle % TRIG_DEGREES];
}
FRACT trigInvSin(FRACT val)
{
SDWORD index;
index = MAKEINT(FRACTmul(val, MAKEFRACT((TRIG_ACCURACY-1)/2)))
+ (TRIG_ACCURACY-1)/2;
return aInvSin[index & TRIG_ACCMASK];
}
FRACT trigInvCos(FRACT val)
{
SDWORD index;
index = MAKEINT(FRACTmul(val, MAKEFRACT((TRIG_ACCURACY-1)/2)))
+ (TRIG_ACCURACY-1)/2;
return aInvCos[index & TRIG_ACCMASK];
}
/* Fast lookup sqrt */
FRACT trigIntSqrt(UDWORD val)
{
UDWORD exp, mask;
if (val == 0)
{
return FRACTCONST(0,1);
}
// find the exponent of the number
mask = 0x80000000; // set the msb in the mask
for(exp=32; exp!=0; exp--)
{
if (val & mask)
{
break;
}
mask >>= 1;
}
// make all exponents even
// odd exponents result in a mantissa of [1..2) rather than [0..1)
if (exp & 1)
{
exp -= 1;
}
// need to shift the top bit to SQRT_BITS - left or right?
if (exp >= SQRT_ACCBITS)
{
val >>= exp - SQRT_ACCBITS + 1;
}
else
{
val <<= SQRT_ACCBITS - 1 - exp;
}
// now generate the fractional part for the lookup table
ASSERT((val < SQRT_ACCURACY,
"trigIntSqrt: aargh - table index out of range"));
return aSqrt[val] * (FRACT)((UDWORD)1 << ((UDWORD)exp/2));
}
#define DIVCNT (32)
#define ARCGAP (4096/DIVCNT) // X2-X1
#define ARCMASK (ARCGAP-1)
/* */

View File

@ -1,33 +0,0 @@
/*
* Trig.h
*
* Interface to trig lookup tables
*
*/
#ifndef _trig_h
#define _trig_h
/* The number of units around a full circle */
#define TRIG_DEGREES 360
/* conversion macros */
#define DEG_TO_RAD(x) (x*PI/180.0)
#define RAD_TO_DEG(x) (x*180.0/PI)
/* Initialise the Trig tables */
extern BOOL trigInitialise(void);
/* Shutdown the trig tables */
extern void trigShutDown(void);
/* Lookup trig functions */
extern FRACT trigSin(SDWORD angle);
extern FRACT trigCos(SDWORD angle);
extern FRACT trigInvSin(FRACT val);
extern FRACT trigInvCos(FRACT val);
/* Supposedly fast lookup sqrt - unfortunately it's probably slower than the FPU sqrt :-( */
extern FRACT trigIntSqrt(UDWORD val);
#endif

View File

@ -1,252 +0,0 @@
/*
* types.h
*
* Simple type definitions.
*
*/
#ifndef _types_h
#define _types_h
/* Check the header files have been included from frame.h if they
* are used outside of the framework library.
*/
#if !defined(_frame_h) && !defined(FRAME_LIB_INCLUDE)
#error Framework header files MUST be included from Frame.h ONLY.
#endif
#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
# include <windows.h>
#endif
/* Basic numeric types */
typedef unsigned char UBYTE;
typedef char SBYTE;
typedef char STRING;
typedef unsigned short UWORD;
typedef short SWORD;
typedef unsigned int UDWORD;
typedef int SDWORD;
#ifndef WIN32
// win32 functions to POSIX
#define stricmp(a,b) strcasecmp((a),(b))
#define CreateDirectory(dir, ptr) mkdir(unix_path(dir), 0777)
#define wsprintf sprintf
#define GetCurrentDirectory(size,buf) getcwd((buf),(size))
#define _chdir(d) chdir(unix_path(d))
#define DeleteFile(file) remove(unix_path(file))
#define RemoveDirectory(dir) remove(unix_path(dir))
#define MAKELONG(low,high) ((LONG)(((WORD)(low)) | (((DWORD)((WORD)(high))) << 16)))
#define WARZONEGUID 0
#define VER_PLATFORM_WIN32_WINDOWS 1
#define DRIVE_CDROM 5
#define INVALID_HANDLE_VALUE 0
#define REG_OPTION_NON_VOLATILE 0
#define KEY_ALL_ACCESS 0
#define ERROR_SUCCESS 0
#define REG_DWORD 0
#define REG_SZ 0
#define REG_BINARY 0
#define HKEY_LOCAL_MACHINE 0
#ifndef APIENTRY
#define APIENTRY
#endif
#define cdecl
#define __int64 long long
typedef void * HKEY;
typedef int GUID;
typedef void * LPGUID;
typedef int CRITICAL_SECTION;
typedef int HWND;
typedef void * HANDLE;
typedef int HINSTANCE;
typedef int HRESULT;
typedef int LRESULT;
typedef int HCURSOR;
typedef int WPARAM;
typedef int LPARAM;
typedef int BOOL;
typedef char CHAR;
typedef unsigned char UCHAR;
typedef unsigned char BYTE;
typedef short SHORT;
typedef unsigned short USHORT;
typedef signed short WORD;
typedef unsigned int UINT;
typedef signed int DWORD;
typedef long LONG;
typedef unsigned long ULONG;
typedef unsigned char * LPBYTE;
typedef signed int * LPDWORD;
typedef char * LPSTR;
typedef void * LPVOID;
typedef struct
{
CHAR cFileName[260];
} WIN32_FIND_DATA;
typedef struct {
UBYTE peRed;
UBYTE peGreen;
UBYTE peBlue;
UBYTE peFlags;
} PALETTEENTRY;
typedef struct
{
long x;
long y;
} POINT;
#endif /* !WIN32 */
#ifndef INC_DIRECTX
typedef void * LPDIRECTSOUND;
typedef void * LPDIRECTDRAWSURFACE4;
typedef void * LPDIRECTDRAW4;
typedef void * LPDIRECTDRAW;
typedef void * LPDIRECTDRAWPALETTE;
typedef void * LPDIRECTDRAWCLIPPER;
typedef int DDPIXELFORMAT;
typedef int DDDEVICEIDENTIFIER;
typedef int DDSURFACEDESC2;
typedef int IDirectDrawSurface4;
typedef int DPID;
typedef void * LPDIRECTPLAY4;
typedef void * LPDIRECTPLAY4A;
typedef void * LPDIRECTPLAYLOBBY3;
typedef void * LPDIRECTPLAYLOBBYA;
#define D3DVAL(val) ((float)(val))
typedef int D3DVALUE;
typedef int D3DCOLOR;
typedef struct {
D3DVALUE sx;
D3DVALUE sy;
D3DVALUE sz;
D3DVALUE rhw;
D3DCOLOR color;
D3DCOLOR specular;
D3DVALUE tu;
D3DVALUE tv;
} D3DTLVERTEX, *LPD3DTLVERTEX;
typedef struct
{
GUID guidInstance;
DWORD dwSize;
DWORD dwFlags;
DWORD dwMaxPlayers;
DWORD dwCurrentPlayers;
} DPSESSIONDESC2;
#endif
#ifndef _MSC_VER // this breaks on .net, it wants the other format. --Qamly
#define _inline inline
#define __inline inline
#else
#define _inline __inline
//#define __inline __inline //not needed really.
#endif //_MSC_VER
/* missing define - only used in Screen.c */
#define DDGDI_GETHOSTIDENTIFIER 1
/* Numeric size defines */
#define UBYTE_MAX 0xff
#define SBYTE_MIN (-128) //(0x80)
#define SBYTE_MAX 0x7f
#define UWORD_MAX 0xffff
#define SWORD_MIN (-32768) //(0x8000)
#define SWORD_MAX 0x7fff
#define UDWORD_MAX 0xffffffff
#define SDWORD_MIN (0x80000000)
#define SDWORD_MAX 0x7fffffff
/* Standard Defines */
#ifndef NULL
#define NULL (0)
#endif
#ifndef TRUE
#define TRUE (1)
#define FALSE (0)
#endif
/* locale types */
//#define LOCAL static
#define STATIC static
#define REGISTER register
#define FAST register
#define IMPORT extern
#define VOID void
/* defines for ONEINX - use
if (ONEINX)
{
code.....
}
*/
#define ONEINTWO rand()%2==0
#define ONEINTHREE rand()%3==0
#define ONEINFOUR rand()%4==0
#define ONEINFIVE rand()%5==0
#define ONEINSIX rand()%6==0
#define ONEINSEVEN rand()%7==0
#define ONEINEIGHT rand()%8==0
#define ONEINNINE rand()%9==0
#define ONEINTEN rand()%10==0
#define ONEINTWENTY rand()%20==0
#define ONEINTHIRTY rand()%30==0
#define ONEINFORTY rand()%40==0
#define ONEINFIFTY rand()%50==0
#define ONEINSIXTY rand()%60==0
#define ONEINSEVENTY rand()%70==0
#define ONEINEIGHTY rand()%80==0
#define ONEINNINETY rand()%90==0
#define ONEINHUNDRED rand()%100==0
#define ONEINTHOUSAND rand()%1000==0
#define ONEINTENTHOUSAND rand()%10000==0
#define ONEINHUNDREDTHOUSAND rand()%100000==0
#define ONEINMILLION rand()%1000000==0
#define ABSDIF(a,b) ((a)>(b) ? (a)-(b) : (b)-(a))
#define CAT(a,b) a##b
// now in fractions.h #define ROUND(x) ((x)>=0 ? (SDWORD)((x) + 0.5) : (SDWORD)((x) - 0.5))
/* Boolean operators */
#define AND &&
#define OR ||
#define NOT !
/* Break loop construct */
#define FOREVER for (;;)
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,112 +0,0 @@
/*
WDG releated goodies
*/
#ifndef _wdg_h
#define _wdg_h
// list of all wrfs in the wdg
typedef struct
{
UDWORD WRFname; // Hashed wrf name
UDWORD offset; // offset to start of wrf info
UDWORD filecount; // Number of files in wrf
} WDGINFO;
#define TPAGE_SOFTWARE (1)
#define TPAGE_HARDWARE (2)
// List of files in a wrf
typedef struct
{
UDWORD type; // Hashed type
UDWORD name; // hashed file name
UDWORD offset; // offset from start of this wrf data
UDWORD filesize; // size of file in bytes
// Extra info stored depending on type
// - TEXPAGE info
UBYTE SoftwareFlag; // is texpage for software/hardware specifically TPAGE_xxx
SBYTE TexturePage; // what texture page slot is it for (-1 for none specified)
} WRFINFO;
#define MAXFILESINWRF (900)
#define MAXWRFINWDG (128)
/* Structures for .WDG data files */
#define WDGIDcount 4
#define WDG_NAMEMAX 16
#define WDG4_HEADER \
char WDGid[WDGIDcount]; /* W,D,G,4 */ \
int NumWRFFiles /* number of wrfs in this wdg */
#define WDG5_HEADER \
WDG4_HEADER; \
STRING aName[WDG_NAMEMAX]; /* wdg name */ \
UDWORD sequence; /* WDG sequence number */ \
UDWORD numDep /* Number of WDG dependancies */
typedef struct
{
WDG4_HEADER;
} WDG_HEADER;
typedef struct
{
WDG5_HEADER;
} WDG_HEADER_V5;
// WDG dependancies
typedef struct
{
STRING aName[WDG_NAMEMAX];
UDWORD sequence;
} WDG_DEP;
typedef struct
{
UBYTE *pBufferStart; // start of the memory buffer for the cache
UDWORD BufferSize; // size of the cache
UDWORD OffsetInWDG; // the start of the cache contains data from this offset in the WDG
BOOL IsCacheDataValid;
BOOL IsCacheDataMalloced; // has the data been malloced or is it using some non-allocated buffer somewhere (display buffer)
} CACHE;
BOOL WDG_SetCurrentWDG(char *filename);
BOOL loadFileFromWDG(STRING *pFileName, UBYTE **ppFileData, UDWORD *pFileSize, UBYTE MemAllocationMode);
struct _wdg_findfile;
BOOL loadFileFromWDGCache(struct _wdg_findfile *psFindFile, UBYTE **ppFileData, UDWORD *pFileSize, UBYTE MemAllocationMode);
BOOL LoadWRFCatalog(WDGINFO *CurrentWRF, FILE *pFileHandle);
BOOL WDG_ProcessWRF(char *WRFname,BOOL UseDataFromWDG );
BOOL FILE_InitialiseCache(SDWORD CacheSize);
BOOL FILE_ShutdownCache(void);
void FILE_InvalidateCache(void);
BOOL WDG_AllowWRFs(void);
BOOL WDG_AllowWDGs(void);
UBYTE *FILE_Retrieve(FILE *pFileHandle, UDWORD offsetInWDG, UDWORD filesize);
UBYTE *FILE_RetrieveSingle(FILE *pFileHandle, UDWORD offsetInWDG, UDWORD filesize);
// MemAllocationMode can be ....
#define WDG_ALLOCATEMEM (0) // was TRUE - indicates that we allocate the memory for the file and return the size in pFileSize
#define WDG_USESUPPLIED (1) // was FALSE - indicates that we dont allocate memory and copy the file into the buffer supplie by ppFileData
#define WDG_RETURNCACHE (2) // new - just returns as much of the file as we can in the cache
// set the current WDG and it's catalogs
void WDG_SetCurrentWDGCatalog(char *filename, UDWORD numWRF, WDGINFO *psWRFCatalog);
// set the current WRF file catalog
void WDG_SetCurrentWRFFileCatalog(UDWORD catOffset, WRFINFO *psFileCatalog);
// get the current WDG and it's catalogs
void WDG_GetCurrentWDGCatalog(char **ppFileName, UDWORD *pNumWRF, WDGINFO **ppsWRFCatalog);
// get the current WRF file catalog
void WDG_GetCurrentWFRFileCatalog(UDWORD *pCatOffset, WRFINFO **ppsFileCatalog);
#endif

View File

@ -1,19 +0,0 @@
noinst_LIBRARIES = libgamelib.a
AM_CPPFLAGS = -I../framework -I../sound -I../$(RENDERER) -I../ivis_common -I../..
libgamelib_a_SOURCES = \
anim.c \
animobj.c \
gtime.c \
hashtabl.c \
parser_l.c \
parser_y.c \
pqueue.c \
ptrlist.c \
ani.h animobj.h hashtabl.h parser.h pqueue.h ptrlist.h \
anim.h gtime.h maxpidef.h parser_y.h priority.h
libgamelib_a_libs = ../framework/libframework.a \
../$(RENDERER)/lib$(RENDERER).a \
../ivis_common/libivis_common.a
libgamelib_a_DEPENDENCIES = $(libgamelib_a_libs)
libgamelib_a_LIBADD = $(libgamelib_a_libs)

View File

@ -1,22 +0,0 @@
SRC_FILES= anim.c \
animobj.c \
gtime.c \
hashtabl.c \
parser_l.c \
parser_y.c \
pqueue.c \
ptrlist.c
LIBS=ivis_common framework sound
ifeq ($(GFX), software)
LIBS+=ivis02
else
LIBS+=ivis_opengl
endif
LIB=gamelib
MAKERULES=../../makerules
include $(MAKERULES)/lib.mk

View File

@ -1,27 +0,0 @@
/***************************************************************************/
/*
* Ani.h
*
* Warzone animation function wrappers
*
* Gareth Jones 16/12/97
*/
/***************************************************************************/
#ifndef _ANI_H_
#define _ANI_H_
/***************************************************************************/
#include "frame.h"
#include "anim.h"
/***************************************************************************/
void * anim_GetShapeFunc( STRING * pStr );
/***************************************************************************/
#endif /* _ANI_H_ */
/***************************************************************************/

View File

@ -1,438 +0,0 @@
/***************************************************************************/
/*
* Anim.c
*
* Anim functions
*
* Gareth Jones 11/7/97
*
*/
/***************************************************************************/
#include <string.h>
#include "frame.h"
#include "geo.h"
#include "anim.h"
#include "parser.h"
/***************************************************************************/
/* structs */
/***************************************************************************/
/* global variables */
ANIMGLOBALS g_animGlobals;
/***************************************************************************/
/* local functions */
//static UINT anim_HashFunction( int iKey1, int iKey2 );
/***************************************************************************/
/*
* Anim functions
*/
/***************************************************************************/
BOOL
anim_Init( GETSHAPEFUNC pGetShapeFunc )
{
int iSizeAnim2D = sizeof(A_ANIM2D),
iSizeAnim3D = sizeof(ANIM3D);
/* ensure ANIM2D and ANIM3D structs same size */
if ( iSizeAnim2D != iSizeAnim3D )
{
DBERROR( ("anim_Init: ANIM2D and ANIM3D structs not same size in anim.h!") );
}
/* init globals */
g_animGlobals.psAnimList = NULL;
g_animGlobals.uwCurObj = 0;
g_animGlobals.uwCurState = 0;
g_animGlobals.pGetShapeFunc = pGetShapeFunc;
return TRUE;
}
/***************************************************************************/
void
anim_ReleaseAnim( BASEANIM *psAnim )
{
ANIM3D *psAnim3D;
// remove the anim from the list
LIST_REMOVE(g_animGlobals.psAnimList, psAnim, BASEANIM);
/* free anim scripts */
FREE( psAnim->psStates );
/* free anim shape */
if ( psAnim->animType == ANIM_3D_FRAMES ||
psAnim->animType == ANIM_3D_TRANS )
{
psAnim3D = (ANIM3D *) psAnim;
FREE( psAnim3D->apFrame );
}
FREE(psAnim);
}
/***************************************************************************/
BOOL
anim_Shutdown( void )
{
BASEANIM *psAnim, *psAnimTmp;
if (g_animGlobals.psAnimList != NULL)
{
DBPRINTF(("anim_Shutdown: warning anims still allocated"));
}
/* empty anim list */
psAnim = g_animGlobals.psAnimList;
while ( psAnim != NULL )
{
psAnimTmp = psAnim->psNext;
anim_ReleaseAnim( psAnim );
psAnim = psAnimTmp;
}
return TRUE;
}
/***************************************************************************/
static void
anim_InitBaseMembers( BASEANIM * psAnim, UWORD uwStates, UWORD uwFrameRate,
UWORD uwObj, UBYTE ubType, UWORD uwID )
{
psAnim->uwStates = uwStates;
psAnim->uwFrameRate = uwFrameRate;
psAnim->uwObj = uwObj;
psAnim->ubType = ubType;
psAnim->uwID = uwID;
psAnim->uwAnimTime = (UWORD) (uwStates*1000 / psAnim->uwFrameRate);
/* allocate frames */
psAnim->psStates = MALLOC( uwObj*psAnim->uwStates*sizeof(ANIM_STATE) );
}
/***************************************************************************/
BOOL
anim_Create3D( char szPieFileName[], UWORD uwStates,
UWORD uwFrameRate, UWORD uwObj, UBYTE ubType, UWORD uwID )
{
ANIM3D *psAnim3D;
iIMDShape *psFrames;
UWORD uwFrames, i;
/* allocate anim */
if ( (psAnim3D = MALLOC(sizeof(ANIM3D))) == NULL )
{
return FALSE;
}
/* get local pointer to shape */
psAnim3D->psFrames = (g_animGlobals.pGetShapeFunc) (szPieFileName);
/* count frames in imd */
psFrames = psAnim3D->psFrames;
uwFrames = 0;
while ( psFrames != NULL )
{
#ifdef DEBUG
if (psFrames==0xcdcdcdcd)
{
printf("bad pointer in Create 3D !!!! -[%s]\n", szPieFileName);
}
#endif
uwFrames++;
psFrames = psFrames->next;
}
/* check frame count matches script */
if ( ubType == ANIM_3D_TRANS && uwObj != uwFrames )
{
DBERROR( ("anim_Create3D: frames in pie %s != script objects %i\n",
szPieFileName, uwObj ) );
return FALSE;
}
/* get pointers to individual frames */
psAnim3D->apFrame = MALLOC( uwFrames*sizeof(iIMDShape *) );
psFrames = psAnim3D->psFrames;
for ( i=0; i<uwFrames; i++ )
{
psAnim3D->apFrame[i] = psFrames;
psFrames = psFrames->next;
}
/* init members */
psAnim3D->animType = ubType;
anim_InitBaseMembers( (BASEANIM * ) psAnim3D, uwStates,
uwFrameRate, uwObj, ubType, uwID );
/* add to head of list */
psAnim3D->psNext = g_animGlobals.psAnimList;
g_animGlobals.psAnimList = (BASEANIM * ) psAnim3D;
/* update globals */
g_animGlobals.uwCurObj = 0;
return TRUE;
}
/***************************************************************************/
void
anim_BeginScript( void )
{
/* update globals */
g_animGlobals.uwCurState = 0;
}
/***************************************************************************/
BOOL
anim_EndScript( void )
{
BASEANIM *psAnim;
/* get pointer to current anim */
psAnim = g_animGlobals.psAnimList;
if ( g_animGlobals.uwCurState != psAnim->uwStates )
{
DBERROR( ("anim_End3D: states in current anim not consistent with header\n") );
return FALSE;
}
/* update globals */
g_animGlobals.uwCurObj++;
return TRUE;
}
/***************************************************************************/
BOOL
anim_AddFrameToAnim( int iFrame, VECTOR3D vecPos, VECTOR3D vecRot,
VECTOR3D vecScale )
{
ANIM_STATE *psState;
BASEANIM *psAnim;
UWORD uwState;
/* get pointer to current anim */
psAnim = g_animGlobals.psAnimList;
/* check current anim valid */
ASSERT( (psAnim != NULL, "anim_AddFrameToAnim: NULL current anim\n") );
/* check frame number in range */
ASSERT( (iFrame<psAnim->uwStates,
"anim_AddFrameToAnim: frame number %i > %i frames in imd\n",
iFrame, psAnim->uwObj) );
/* get state */
uwState = (g_animGlobals.uwCurObj * psAnim->uwStates) +
g_animGlobals.uwCurState;
psState = &psAnim->psStates[uwState];
/* set state pointer */
psState->uwFrame = (UWORD) iFrame;
psState->vecPos.x = vecPos.x;
psState->vecPos.y = vecPos.y;
psState->vecPos.z = vecPos.z;
/* max anims right-handed; Necromancer anims left */
psState->vecAngle.x = vecRot.x;
psState->vecAngle.y = vecRot.y;
psState->vecAngle.z = vecRot.z;
psState->vecScale.x = vecScale.x;
psState->vecScale.y = vecScale.y;
psState->vecScale.z = vecScale.z;
/* update globals */
g_animGlobals.uwCurState++;
return TRUE;
}
/***************************************************************************/
BASEANIM *
anim_GetAnim( UWORD uwAnimID )
{
BASEANIM *psAnim;
/* find matching anim id in list */
psAnim = g_animGlobals.psAnimList;
while( psAnim != NULL && psAnim->uwID != uwAnimID )
{
psAnim = psAnim->psNext;
}
return psAnim;
}
/***************************************************************************/
void
anim_SetVals( char szFileName[], UWORD uwAnimID )
{
/* get track pointer from resource */
BASEANIM *psAnim = resGetData( "ANI", szFileName );
if ( psAnim == NULL )
{
DBERROR( ("anim_SetVals: can't find anim %s\n", szFileName) );
}
/* set anim vals */
psAnim->uwID = uwAnimID;
strcpy( psAnim->szFileName, szFileName );
}
/***************************************************************************/
// the playstation version uses sscanf's ... see animload.c
BASEANIM *
anim_LoadFromBuffer( UBYTE *pBuffer, UDWORD size )
{
if ( ParseResourceFile( pBuffer, size ) == FALSE )
{
DBERROR( ("anim_LoadFromBuffer: couldn't parse file\n") );
return NULL;
}
/* loaded anim is at head of list */
return g_animGlobals.psAnimList;
}
/***************************************************************************/
UWORD
anim_GetAnimID( char *szName )
{
BASEANIM *psAnim;
char *cPos = strstr( szName, ".ani" );
if ( cPos == NULL )
{
DBERROR( ("anim_GetAnimID: %s isn't .ani file\n", szName));
return NO_ANIM;
}
/* find matching anim string in list */
psAnim = g_animGlobals.psAnimList;
while( psAnim != NULL &&
stricmp( psAnim->szFileName, szName ) != 0 )
{
psAnim = psAnim->psNext;
}
if ( psAnim != NULL )
{
return psAnim->uwID;
}
else
{
return NO_ANIM;
}
}
/***************************************************************************/
iIMDShape *
anim_GetShapeFromID( UWORD uwID )
{
BASEANIM *psAnim;
ANIM3D *psAnim3D;
/* find matching anim id in list */
psAnim = g_animGlobals.psAnimList;
while( psAnim != NULL && psAnim->uwID != uwID )
{
psAnim = psAnim->psNext;
}
if ( psAnim == NULL )
{
return NULL;
}
else
{
psAnim3D = (ANIM3D *) psAnim;
ASSERT( (PTRVALID( psAnim3D, sizeof(ANIM3D)),
"anim_GetShapeFromID: invalid anim pointer\n" ) );
return psAnim3D->psFrames;
}
}
/***************************************************************************/
UWORD
anim_GetFrame3D( ANIM3D *psAnim, UWORD uwObj, UDWORD udwGameTime,
UDWORD udwStartTime, UDWORD udwStartDelay,
VECTOR3D *psVecPos, VECTOR3D *psVecRot, VECTOR3D *psVecScale )
{
DWORD dwTime;
UWORD uwState, uwFrame;
ANIM_STATE *psState;
/* calculate current anim frame */
dwTime = udwGameTime - udwStartTime - udwStartDelay;
/* return NULL if animation still delayed */
if ( dwTime < 0 )
{
return ANIM_DELAYED;
}
uwFrame = (UWORD) ((dwTime % psAnim->uwAnimTime) *
psAnim->uwFrameRate / 1000);
/* check in range */
ASSERT( (uwFrame<psAnim->uwStates,
"anim_GetObjectFrame3D: error in animation calculation\n") );
/* find current state */
uwState = (uwObj * psAnim->uwStates) + uwFrame;
psState = &psAnim->psStates[uwState];
psVecPos->x = psState->vecPos.x / INT_SCALE;
psVecPos->y = psState->vecPos.y / INT_SCALE;
psVecPos->z = psState->vecPos.z / INT_SCALE;
psVecRot->x = psState->vecAngle.x * DEG_1 / INT_SCALE;
psVecRot->y = psState->vecAngle.y * DEG_1 / INT_SCALE;
psVecRot->z = psState->vecAngle.z * DEG_1 / INT_SCALE;
psVecScale->x = psState->vecScale.x;
psVecScale->y = psState->vecScale.y;
psVecScale->z = psState->vecScale.z;
if ( psAnim->ubType == ANIM_3D_TRANS )
{
return uwFrame;
}
else
{
return psAnim->psStates[uwState].uwFrame;
}
}
/***************************************************************************/

View File

@ -1,136 +0,0 @@
/***************************************************************************/
/*
* Anim.h
*
* Animation types and function headers
*
* Gareth Jones 11/7/97
*/
/***************************************************************************/
#ifndef _ANIM_H_
#define _ANIM_H_
/***************************************************************************/
#include "types.h"
#include "imd.h"
#include "maxpidef.h"
/***************************************************************************/
#define ANIM_MAX_STR 256
#define ANIM_DELAYED 0xFFFE
#define NO_ANIM 0xFFFD
#define NO_IMD 0xFFFC
/***************************************************************************/
enum{ ANIM_2D, ANIM_3D_FRAMES, ANIM_3D_TRANS };
/***************************************************************************/
struct ANIM_STATE;
struct BASEANIM;
#define ANIM_BASE_ELEMENTS \
char szFileName[ANIM_MAX_STR]; \
char animType; \
UWORD uwID; \
UWORD uwFrameRate; \
UWORD uwStates; \
UWORD uwObj; \
UWORD uwAnimTime; \
UBYTE ubType; \
struct ANIM_STATE *psStates; \
struct BASEANIM *psNext;
/* ensure ANIM2D/3D structs same size */
#define ANIM_2D_ELEMENTS \
ANIM_BASE_ELEMENTS \
iSprite *psFrames; \
UWORD uwBmapWidth; /* width of container bitmap */
/* ensure ANIM2D/3D structs same size */
#define ANIM_3D_ELEMENTS \
ANIM_BASE_ELEMENTS \
iIMDShape *psFrames; \
iIMDShape **apFrame;
/***************************************************************************/
typedef struct VECTOR3D
{
SDWORD x, y, z;
}
VECTOR3D;
typedef struct ANIM_STATE
{
UWORD uwFrame; /* frame to play */
VECTOR3D vecPos;
VECTOR3D vecAngle;
VECTOR3D vecScale;
}
ANIM_STATE;
typedef struct BASEANIM
{
ANIM_BASE_ELEMENTS
}
BASEANIM;
typedef struct A_ANIM2D
{
ANIM_2D_ELEMENTS
}
A_ANIM2D;
typedef struct ANIM3D
{
ANIM_3D_ELEMENTS
}
ANIM3D;
/***************************************************************************/
typedef void * (* GETSHAPEFUNC) ( STRING *pStr );
typedef struct ANIMGLOBALS
{
BASEANIM *psAnimList;
UWORD uwCurObj, uwCurState;
GETSHAPEFUNC pGetShapeFunc;
}
ANIMGLOBALS;
/***************************************************************************/
BOOL anim_Init( GETSHAPEFUNC );
BOOL anim_Shutdown( void );
BASEANIM * anim_LoadFromBuffer( UBYTE *pBuffer, UDWORD size );
void anim_ReleaseAnim( BASEANIM *psAnim );
BOOL anim_Create3D( char szPieFileName[], UWORD uwFrames,
UWORD uwFrameRate, UWORD uwObj,
UBYTE ubType, UWORD uwID );
void anim_BeginScript( void );
BOOL anim_EndScript( void );
BOOL anim_AddFrameToAnim( int iFrame, VECTOR3D vecPos,
VECTOR3D vecRot, VECTOR3D vecScale );
BASEANIM * anim_GetAnim( UWORD uwAnimID );
UWORD anim_GetAnimID( char *szName );
iIMDShape * anim_GetShapeFromID( UWORD uwID );
UWORD anim_GetFrame3D( ANIM3D *psAnim, UWORD uwObj, UDWORD udwGameTime,
UDWORD udwStartTime, UDWORD udwStartDelay,
VECTOR3D *psVecPos, VECTOR3D *psVecRot,
VECTOR3D *psVecScale );
void anim_SetVals( char szFileName[], UWORD uwAnimID );
/***************************************************************************/
#endif /* _ANIM_H_ */
/***************************************************************************/

View File

@ -1,307 +0,0 @@
/***************************************************************************/
/*
* Animobj.c
*
* Anim object functions
*
* Gareth Jones 14/11/97
*/
/***************************************************************************/
#include <string.h>
#include "frame.h"
#include "hashtabl.h"
#include "gtime.h"
#include "animobj.h"
/***************************************************************************/
/* allocation sizes for anim object table */
#define ANIM_OBJ_INIT 100
#define ANIM_OBJ_EXT 20
/* max number of slots in hash table - prime numbers are best because hash
* function used here is modulous of object pointer with table size -
* prime number nearest 500 is 499.
* Table of nearest primes in Binstock+Rex, "Practical Algorithms" p 91.
*/
#define ANIM_HASH_TABLE_SIZE 499
/* Allocation sizes for the anim heap */
#define ANIM_INIT 10
#define ANIM_EXT 5
/***************************************************************************/
/* global variables */
static HASHTABLE *g_pAnimObjTable;
static ANIMOBJDIEDTESTFUNC g_pDiedFunc;
/***************************************************************************/
/* local functions */
static UINT animObj_HashFunction( int iKey1, int iKey2 );
static void animObj_HashFreeElementFunc( void * psElement );
/***************************************************************************/
/*
* Anim functions
*/
/***************************************************************************/
BOOL
animObj_Init( ANIMOBJDIEDTESTFUNC pDiedFunc )
{
SDWORD iSize = sizeof(ANIM_OBJECT);
/* allocate hashtable */
hashTable_Create( &g_pAnimObjTable, ANIM_HASH_TABLE_SIZE,
ANIM_OBJ_INIT, ANIM_OBJ_EXT, iSize );
/* set local hash table functions */
hashTable_SetHashFunction( g_pAnimObjTable, animObj_HashFunction );
hashTable_SetFreeElementFunction( g_pAnimObjTable,
animObj_HashFreeElementFunc );
/* set global died test function */
g_pDiedFunc = pDiedFunc;
return TRUE;
}
/***************************************************************************/
BOOL
animObj_Shutdown( void )
{
/* destroy hash table */
hashTable_Destroy( g_pAnimObjTable );
return TRUE;
}
/***************************************************************************/
void
animObj_SetDoneFunc( ANIM_OBJECT *psObj, ANIMOBJDONEFUNC pDoneFunc )
{
psObj->pDoneFunc = pDoneFunc;
}
/***************************************************************************/
/*
* animObj_HashFunction
*
* Takes object pointer and id and returns hashed index
*/
/***************************************************************************/
static UINT
animObj_HashFunction( int iKey1, int iKey2 )
{
return (iKey1 + iKey2)%ANIM_HASH_TABLE_SIZE;
}
/***************************************************************************/
static void
animObj_HashFreeElementFunc( void * psElement )
{
#ifdef DEBUG
ANIM_OBJECT *psObj = (ANIM_OBJECT *) psElement;
#endif
ASSERT( (PTRVALID(psObj, sizeof(ANIM_OBJECT)),
"animObj_HashFreeElementFunc: object pointer invalid\n") );
}
/***************************************************************************/
void
animObj_Update( void )
{
ANIM_OBJECT *psObj;
SDWORD dwTime;
BOOL bRemove;
psObj = hashTable_GetFirst( g_pAnimObjTable );
while ( psObj != NULL )
{
bRemove = FALSE;
/* test whether parent object has died */
if ( g_pDiedFunc != NULL )
{
bRemove = (g_pDiedFunc) (psObj->psParent);
}
/* remove any expired (non-looping) animations */
if ( (bRemove == FALSE) && (psObj->uwCycles != 0) )
{
dwTime = gameTime - psObj->udwStartTime - psObj->udwStartDelay;
if ( dwTime > (psObj->psAnim->uwAnimTime*psObj->uwCycles) )
{
/* fire callback if set */
if ( psObj->pDoneFunc != NULL )
{
(psObj->pDoneFunc) (psObj);
}
bRemove = TRUE;
}
}
/* remove object if flagged */
if ( bRemove == TRUE )
{
if ( hashTable_RemoveElement( g_pAnimObjTable, psObj,
(int) psObj->psParent, psObj->psAnim->uwID ) == FALSE )
{
DBERROR( ("animObj_Update: couldn't remove anim obj\n") );
}
}
psObj = hashTable_GetNext( g_pAnimObjTable );
}
}
/***************************************************************************/
/*
* anim_Add
*
* uwCycles=0 for infinite looping
*/
/***************************************************************************/
ANIM_OBJECT *
animObj_Add( void *pParentObj, int iAnimID,
UDWORD udwStartDelay, UWORD uwCycles )
{
ANIM_OBJECT *psObj;
BASEANIM *psAnim = anim_GetAnim( (UWORD) iAnimID );
UWORD i, uwObj;
ASSERT( (psAnim != NULL,
"anim_AddAnimObject: anim id %i not found\n", iAnimID ) );
/* get object from table */
psObj = hashTable_GetElement( g_pAnimObjTable );
if (psObj==NULL)
{
DBERROR( ("animObj_Add: No room in hash table\n") );
return(NULL);
}
/* init object */
psObj->uwID = (UWORD) iAnimID;
psObj->psAnim = (ANIM3D *) psAnim;
psObj->udwStartTime = gameTime;
psObj->udwStartDelay = udwStartDelay;
psObj->uwCycles = uwCycles;
psObj->bVisible = TRUE;
psObj->psParent = pParentObj;
psObj->pDoneFunc = NULL;
/* allocate component objects */
if ( psAnim->animType == ANIM_3D_TRANS )
{
uwObj = psAnim->uwObj;
}
else
{
uwObj = psAnim->uwStates;
}
if ( uwObj > ANIM_MAX_COMPONENTS )
{
DBERROR( ("animObj_Add: number of components too small\n") );
}
/* set parent pointer and shape pointer */
for ( i=0; i<uwObj; i++ )
{
psObj->apComponents[i].psParent = pParentObj;
psObj->apComponents[i].psShape = psObj->psAnim->apFrame[i];
}
/* insert object in table by parent */
hashTable_InsertElement( g_pAnimObjTable, psObj,
(int) pParentObj, iAnimID );
return psObj;
}
/***************************************************************************/
/*
* animObj_GetFrame3D
*
* returns NULL if animation not started yet
*/
/***************************************************************************/
UWORD
animObj_GetFrame3D( ANIM_OBJECT *psObj, UWORD uwObj, VECTOR3D *psVecPos,
VECTOR3D *psVecRot, VECTOR3D *psVecScale )
{
ANIM3D *psAnim;
/* get local anim pointer */
psAnim = (ANIM3D *) psObj->psAnim;
return anim_GetFrame3D( psAnim, uwObj, gameTime, psObj->udwStartTime,
psObj->udwStartDelay, psVecPos, psVecRot, psVecScale );
}
/***************************************************************************/
ANIM_OBJECT *
animObj_GetFirst( void )
{
ANIM_OBJECT *psObj;
psObj = (ANIM_OBJECT *) hashTable_GetFirst( g_pAnimObjTable );
ASSERT( (psObj == NULL || PTRVALID(psObj, sizeof(ANIM_OBJECT)),
"animObj_GetFirst: object pointer not valid\n") );
return psObj;
}
/***************************************************************************/
ANIM_OBJECT *
animObj_GetNext( void )
{
return hashTable_GetNext( g_pAnimObjTable );
}
/***************************************************************************/
ANIM_OBJECT *
animObj_Find( void *pParentObj, int iAnimID )
{
return hashTable_FindElement( g_pAnimObjTable,
(int) pParentObj, iAnimID );
}
/***************************************************************************/
BOOL
animObj_Remove( ANIM_OBJECT **ppsObj, int iAnimID )
{
BOOL bRemOK = hashTable_RemoveElement( g_pAnimObjTable, *ppsObj,
(int) (*ppsObj)->psParent, iAnimID );
//init the animation
*ppsObj = NULL;
return bRemOK;
}
/***************************************************************************/

View File

@ -1,96 +0,0 @@
/***************************************************************************/
/*
* Animobj.h
*
* Animation object types and function headers
*
* Gareth Jones 14/11/97
*/
/***************************************************************************/
#ifndef _ANIMOBJ_H_
#define _ANIMOBJ_H_
/***************************************************************************/
#include "anim.h"
/***************************************************************************/
#define ANIM_MAX_COMPONENTS 10
/***************************************************************************/
/* forward struct declarations */
struct ANIM_OBJECT;
struct COMPONENT_OBJECT;
/***************************************************************************/
/* typedefs */
typedef void (* ANIMOBJDONEFUNC) ( struct ANIM_OBJECT *psObj );
typedef BOOL (* ANIMOBJDIEDTESTFUNC) ( void *psParent );
/***************************************************************************/
/* struct member macros */
#define COMPONENT_ELEMENTS(pointerType) \
VECTOR3D position; \
VECTOR3D orientation; \
void *psParent; \
iIMDShape *psShape;
#define ANIM_OBJECT_ELEMENTS(pointerType) \
UWORD uwID; \
ANIM3D *psAnim; \
void *psParent; \
UDWORD udwStartTime; \
UDWORD udwStartDelay; \
UWORD uwCycles; \
BOOL bVisible; \
ANIMOBJDONEFUNC pDoneFunc; \
/* this must be the last entry in this structure */ \
COMPONENT_OBJECT apComponents[ANIM_MAX_COMPONENTS];
/***************************************************************************/
typedef struct COMPONENT_OBJECT
{
COMPONENT_ELEMENTS( struct COMPONENT_OBJECT )
}
COMPONENT_OBJECT;
typedef struct ANIM_OBJECT
{
struct ANIM_OBJECT *psNext;
/* this must be the last entry in this structure */
ANIM_OBJECT_ELEMENTS( struct ANIM_OBJECT )
}
ANIM_OBJECT;
/***************************************************************************/
BOOL animObj_Init( ANIMOBJDIEDTESTFUNC pDiedFunc );
void animObj_Update( void );
BOOL animObj_Shutdown( void );
void animObj_SetDoneFunc( ANIM_OBJECT *psObj,
ANIMOBJDONEFUNC pDoneFunc );
/* uwCycles=0 for infinite looping */
ANIM_OBJECT * animObj_Add( void *pParentObj, int iAnimID,
UDWORD udwStartDelay, UWORD uwCycles );
BOOL animObj_Remove( ANIM_OBJECT **ppsObj, int iAnimID );
ANIM_OBJECT * animObj_GetFirst( void );
ANIM_OBJECT * animObj_GetNext( void );
ANIM_OBJECT * animObj_Find( void *pParentObj, int iAnimID );
UWORD animObj_GetFrame3D( ANIM_OBJECT *psObj, UWORD uwObj,
VECTOR3D *psPos, VECTOR3D *psVecRot,
VECTOR3D *psVecScale );
/***************************************************************************/
#endif /* _ANIMOBJ_H_ */
/***************************************************************************/

View File

@ -1,189 +0,0 @@
%{
/* include framework */
#include "frame.h"
#include "parser.h"
/* Get the Yacc definitions */
#include "parser_y.h"
/* Maximum length for any TEXT value */
#define YYLMAX 255
/* extern funcs */
extern int audp_parse YY_ARGS( (void) );
/* global variables */
static BOOL g_bParsingSubFile;
static FILE *g_fpOld;
/* Pointer to the input buffer */
static UBYTE *pInputBuffer = NULL;
static UBYTE *pEndBuffer = NULL;
static int audp_GetChar( void );
#undef audp_getc
#define audp_getc() ( pInputBuffer != pEndBuffer ? *(pInputBuffer++) : EOF )
%}
%x COMMENT
%x QUOTE
%%
/* Match to key words */
oneshot { return ONESHOT; }
loop { return LOOP; }
audio { return AUDIO; }
anim3dfile { return ANIM3DFILE; }
audio_module { return AUDIO_MODULE; }
anim_module { return ANIM_MODULE; }
ANIM3DFRAMES { return ANIM3DFRAMES; }
ANIM3DTRANS { return ANIM3DTRANS; }
ANIMOBJECT { return ANIMOBJECT; }
/* Match floating point numbers */
/* This is a problem with the PSX so is disabled
-?[0-9]*"."[0-9]+ { audp_lval.fval = (float) atof(audp_text);
return FLOAT;
}
*/
/* Match integer numbers */
-?[0-9]+ { audp_lval.ival = atoi(audp_text);
return INTEGER;
}
/* Match quoted text */
\"[^\"\n]*[\"\n] {
/* skip opening quote */
strcpy( audp_lval.sval, audp_text+1 );
/* check for unterminated string */
if ( audp_text[audp_leng-1] != '"' )
{
sprintf( audp_lval.sval, "Unterminated string %s\n", audp_lval.sval );
audp_error( audp_lval.sval );
return (1);
}
/* set final quote in string to blank */
audp_lval.sval[audp_leng-2] = (char) NULL;
return QTEXT;
}
/* Match text values */
[a-zA-Z"."#][-0-9_a-zA-Z"."#]* { strcpy( audp_lval.sval, audp_text );
return TEXT;
}
/* Skip white space */
[ \t\n\x0d\x0a] ;
/* Strip comments */
"/*" { BEGIN COMMENT; }
<COMMENT>"*/" |
<COMMENT>"*/"\n { BEGIN 0; }
<COMMENT>. |
<COMMENT>\n ;
/* Match anything that's been missed and pass it as a char */
. return audp_text[0];
%%
/***************************************************************************/
BOOL
ParseFile( char szFileName[] )
{
FILE *fp;
/* open input file */
if ( (fp = fopen( szFileName, "rt" )) == NULL )
{
DBERROR( ("ParseFile: file not found\n") );
return FALSE;
}
/* point input to input file */
audp_in = fp;
audp_parse();
fclose( fp );
return TRUE;
}
/***************************************************************************/
void
IncludeFile( char szFileName[] )
{
FILE *fpNew;
/* open module file */
if ( (fpNew = fopen( szFileName, "rt" )) != NULL )
{
/* save current file pointer and switch to new */
g_fpOld = audp_in;
audp_in = fpNew;
g_bParsingSubFile = TRUE;
}
else
{
DBERROR( ("Included file %s not found\n", szFileName) );
}
}
/***************************************************************************/
int
audp_wrap( void )
{
if ( g_bParsingSubFile == TRUE )
{
/* close current file and restore old file pointer */
fclose( audp_in );
audp_in = g_fpOld;
g_bParsingSubFile = FALSE;
return 0;
}
else
{
return 1;
}
}
/***************************************************************************/
/* Set the current input buffer for the lexer */
/***************************************************************************/
void
parserSetInputBuffer( UBYTE *pBuffer, UDWORD size )
{
pInputBuffer = pBuffer;
pEndBuffer = pBuffer + size;
/* Reset the lexer in case it's been used before */
audp__reset();
}
/***************************************************************************/
void
parseGetErrorData(int *pLine, char **ppText)
{
*pLine = audp_lineno;
*ppText = audp_text;
}
/***************************************************************************/

View File

@ -1,222 +0,0 @@
%{
#include <stdio.h>
#include "frame.h"
#include "parser.h"
#include "audio.h"
#include "anim.h"
static int g_iCurAnimID = 0;
static int g_iDummy;
static VECTOR3D vecPos, vecRot, vecScale;
%}
%union {
float fval;
long ival;
signed char bval;
char sval[100];
}
/* value tokens */
%token <fval> FLOAT
%token <ival> INTEGER
%token <sval> TEXT
%token <sval> text
%token <sval> QTEXT /* Text with double quotes surrounding it */
%token <ival> LOOP
%token <ival> ONESHOT
/* types */
%type <sval> text
/* keywords */
%token AUDIO
%token ANIM2D
%token ANIM3DFRAMES
%token ANIM3DTRANS
%token ANIM3DFILE
%token AUDIO_MODULE
%token ANIM_MODULE
%token ANIMOBJECT
/* module names */
%%
data_file: module_file | anim_file
;
module_file: module_file data_list |
data_list
;
data_list: audio_module | anim_module
;
audio_header: AUDIO_MODULE "{"
;
audio_module: audio_header audio_list "}" |
audio_header "}"
;
audio_list: audio_list audio_track |
audio_track
;
/*
* BOOL audio_SetTrackVals( char szFileName[], BOOL bLoop, int *piID, int iVol,
* int iPriority, int iAudibleRadius )
*/
audio_track: AUDIO QTEXT LOOP INTEGER INTEGER INTEGER
{
audio_SetTrackVals( $2, TRUE, &g_iDummy, $4, $5, $6, 0 );
}
| AUDIO QTEXT ONESHOT INTEGER INTEGER INTEGER
{
audio_SetTrackVals( $2, FALSE, &g_iDummy, $4, $5, $6, 0 );
}
;
anim_module_header: ANIM_MODULE "{"
{
}
;
anim_module: anim_module_header anim_file_list "}" |
anim_module_header anim_config_list "}" |
/* NULL */
;
anim_config_list: anim_config_list anim_config |
anim_config |
/* NULL */
;
anim_file_list: anim_file_list anim_file |
anim_file |
/* NULL */
;
/*
anim_file: ANIM3DFILE QTEXT INTEGER
{
g_iCurAnimID = $3;
IncludeFile( $2 );
}
anim_trans | anim_frames
;
*/
anim_file: anim_trans | anim_frames
;
anim_config: QTEXT INTEGER
{
g_iCurAnimID = $2;
anim_SetVals( $1, $2 );
}
;
/*
* anim_Create3D( char szAniFileName[], char szPieFileName[], UWORD uwFrames,
* UWORD uwFrameRate, UWORD uwNumObj, char cType, UWORD uwID )
*/
anim_trans: ANIM3DTRANS QTEXT INTEGER INTEGER INTEGER
{
anim_Create3D( $2, $3, $4, $5, ANIM_3D_TRANS, g_iCurAnimID );
}
"{" anim_obj_list "}"
{
g_iCurAnimID++;
}
;
anim_frames: ANIM3DFRAMES QTEXT INTEGER INTEGER
{
anim_Create3D( $2, $3, $4, 1, ANIM_3D_FRAMES, g_iCurAnimID );
}
"{"
{
anim_BeginScript();
}
anim_script "}"
{
anim_EndScript();
g_iCurAnimID++;
}
;
anim_obj_list: anim_obj anim_obj_list |
anim_obj
;
anim_obj: ANIMOBJECT INTEGER QTEXT "{"
{
anim_BeginScript();
}
anim_script "}"
{
anim_EndScript();
}
;
anim_script: anim_script anim_state |
anim_state
;
anim_state: INTEGER INTEGER INTEGER INTEGER INTEGER INTEGER INTEGER INTEGER INTEGER INTEGER
{
vecPos.x = $2;
vecPos.y = $3;
vecPos.z = $4;
vecRot.x = $5;
vecRot.y = $6;
vecRot.z = $7;
vecScale.x = $8;
vecScale.y = $9;
vecScale.z = $10;
anim_AddFrameToAnim( $1, vecPos, vecRot, vecScale );
}
;
%%
/***************************************************************************/
/* A simple error reporting routine */
void audp_error(char *pMessage,...)
{
int line;
char *pText;
char aTxtBuf[1024];
va_list args;
va_start(args, pMessage);
vsprintf(aTxtBuf, pMessage, args);
parseGetErrorData( &line, &pText );
DBERROR(("RES file parse error:\n%s at line %d\nToken: %d, Text: '%s'\n",
aTxtBuf, line, audp_char, pText));
va_end(args);
}
/***************************************************************************/
/* Read a resource file */
BOOL ParseResourceFile( UBYTE *pData, UDWORD fileSize )
{
// Tell lex about the input buffer
parserSetInputBuffer( pData, fileSize );
audp_parse();
return TRUE;
}
/***************************************************************************/

View File

@ -1,273 +0,0 @@
/*
* GTime.c
*
* Provide a game clock that runs only when the game runs.
*
*/
#include <time.h>
//#define DEBUG_GROUP1
#include "frame.h"
#include "gtime.h"
#define TIME_FIX
//#define RATE_LIMIT
#define GTIME_MINFRAME (GAME_TICKS_PER_SEC/80)
/* The current time in the game world */
UDWORD gameTime;
/* The time for the last frame */
UDWORD frameTime;
/* The current time in the game world ( never stops )*/
UDWORD gameTime2;
/* The time for the last frame (never stops)*/
UDWORD frameTime2;
// the current clock modifier
static FRACT modifier;
// the amount of game time before the last time clock speed was set
static UDWORD timeOffset;
static UDWORD timeOffset2;
// the tick count the last time the clock speed was set
static UDWORD baseTime;
static UDWORD baseTime2;
/* When the game paused so that gameTime can be adjusted when the game restarts */
static SDWORD pauseStart;
/* Count how many times gameTimeStop has been called without a game time start */
static UDWORD stopCount;
/* Initialise the game clock */
BOOL gameTimeInit(void)
{
//gameTime = 0;
/*start the timer off at 2 so that when the scripts strip the map of objects
for multiPlayer they will be processed as if they died*/
gameTime = 2;
timeOffset = 0;
baseTime = GetTickCount();
gameTime2 = 0;
timeOffset2 = 0;
baseTime2 = baseTime;
modifier = FRACTCONST(1,1);
stopCount = 0;
return TRUE;
}
UDWORD getTimeValueRange(UDWORD tickFrequency, UDWORD requiredRange)
{
UDWORD div1,div2;
div1 = gameTime2%tickFrequency;
div2 = tickFrequency/requiredRange;
return(div1/div2);
}
UDWORD getStaticTimeValueRange(UDWORD tickFrequency, UDWORD requiredRange)
{
UDWORD div1,div2;
div1 = gameTime%tickFrequency;
div2 = tickFrequency/requiredRange;
return(div1/div2);
}
/* Call this each loop to update the game timer */
void gameTimeUpdate(void)
{
UDWORD currTime, fpMod;
#ifdef TIME_FIX
unsigned __int64 newTime;
unsigned __int64 extraTime;
#else
unsigned long long newTime;
#endif
currTime = GetTickCount();
if (currTime < baseTime)
{
#ifdef RATE_LIMIT
// Limit the frame time
#endif
// ooops the clock has wrapped round -
// someone actually managed to keep windows running for 50 days !!!!
// ........
}
//don't update the game time if gameTimeStop has been called
if (stopCount == 0)
{
// Calculate the new game time
newTime = currTime - baseTime;
// convert the modifier to fixed point cos we loose accuracy
fpMod = MAKEINT(FRACTmul(modifier, FRACTCONST(1000,1)));
newTime = newTime * fpMod / 1000;
newTime += timeOffset;
// Calculate the time for this frame
frameTime = (UDWORD)(newTime - gameTime);
// Limit the frame time
if (frameTime > GTIME_MAXFRAME)
{
#ifdef TIME_FIX
extraTime = frameTime - GTIME_MAXFRAME;
extraTime = extraTime * 1000 / fpMod;//adjust the addition to base time
baseTime += (UDWORD)extraTime;
#else
baseTime += frameTime - GTIME_MAXFRAME;
#endif
newTime = gameTime + GTIME_MAXFRAME;
frameTime = GTIME_MAXFRAME;
}
// Store the game time
gameTime = (UDWORD)newTime;
}
// now update gameTime2 which does not pause
newTime = currTime - baseTime2;
newTime += timeOffset;
// Calculate the time for this frame
frameTime2 = (UDWORD)newTime - gameTime2;
// Limit the frame time
if (frameTime2 > GTIME_MAXFRAME)
{
baseTime2 += frameTime2 - GTIME_MAXFRAME;
newTime = gameTime2 + GTIME_MAXFRAME;
frameTime2 = GTIME_MAXFRAME;
}
// Store the game time
gameTime2 = (UDWORD)newTime;
}
// reset the game time modifiers
void gameTimeResetMod(void)
{
timeOffset = gameTime;
timeOffset2 = gameTime2;
baseTime = GetTickCount();
baseTime2 = GetTickCount();
modifier = FRACTCONST(1,1);
}
// set the time modifier
void gameTimeSetMod(FRACT mod)
{
gameTimeResetMod();
modifier = mod;
}
// get the current time modifier
void gameTimeGetMod(FRACT *pMod)
{
*pMod = modifier;
}
BOOL gameTimeIsStopped(void)
{
return (stopCount != 0);
}
/* Call this to stop the game timer */
void gameTimeStop(void)
{
if (stopCount == 0)
{
pauseStart = GetTickCount();
DBP1(("Clock paused at %d\n", pauseStart));
}
stopCount += 1;
}
/* Call this to restart the game timer after a call to gameTimeStop */
void gameTimeStart(void)
{
if (stopCount == 1)
{
// shift the base time to now
timeOffset = gameTime;
baseTime = GetTickCount();
}
if (stopCount > 0)
{
stopCount --;
}
}
/*Call this to reset the game timer*/
void gameTimeReset(UDWORD time)
{
// reset the game timers
gameTime = time;
timeOffset = time;
gameTime2 = time;
timeOffset2 = time;
baseTime = GetTickCount();//used from save game only so GetTickCount is as valid as anything
baseTime2 = GetTickCount();
modifier = FRACTCONST(1,1);
}
void getTimeComponents(UDWORD time, UDWORD *hours, UDWORD *minutes, UDWORD *seconds)
{
UDWORD h,m,s;
UDWORD tph,tpm;
/* Ticks in a minute */
tpm = GAME_TICKS_PER_SEC*60;
/* Ticks in an hour */
tph = tpm*60;
h = time/tph;
m = (time - (h*tph))/tpm;
s = (time - ((h*tph) + (m*tpm)))/GAME_TICKS_PER_SEC;
*hours = h;
*minutes = m;
*seconds = s;
}

View File

@ -1,78 +0,0 @@
/*
* GTime.h
*
* Interface to the game clock.
*
*/
#ifndef _gtime_h
#define _gtime_h
/* The number of ticks per second for the game clock */
#ifdef WIN32
#define GAME_TICKS_PER_SEC 1000
#else
#define GAME_TICKS_PER_SEC 1000
#endif
// The maximum time for one frame (stops the clock running away when debugging)
// changed to /6 by ajl. if this needs to go back to ticks/10 then tell me.
#define GTIME_MAXFRAME (GAME_TICKS_PER_SEC/6)
/* The current time in the game world */
extern UDWORD gameTime;
/* The time for the last frame */
extern UDWORD frameTime;
/* The current time in the game world */
extern UDWORD gameTime2; // Never stops.
/* The time for the last frame */
extern UDWORD frameTime2; // Never stops.
/* Initialise the game clock */
extern BOOL gameTimeInit(void);
/* Call this each loop to update the game timer */
extern void gameTimeUpdate(void);
/* Returns TRUE if gameTime is stopped. */
extern BOOL gameTimeIsStopped(void);
/* Call this to stop the game timer */
extern void gameTimeStop(void);
/* Call this to restart the game timer after a call to gameTimeStop */
extern void gameTimeStart(void);
/*Call this to reset the game timer*/
extern void gameTimeReset(UDWORD time);
// reset the game time modifiers
void gameTimeResetMod(void);
// set the time modifier
void gameTimeSetMod(FRACT mod);
// get the current time modifier
void gameTimeGetMod(FRACT *pMod);
// get the current time modifier
void gameTimeGetModifier(UDWORD *pMod, UDWORD *pFactor);
/* Useful for periodical stuff */
/* Will return a number that climbs over tickFrequency game ticks and ends up in the required range. */
/*
For instance getTimeValueRange(4096,256) will return a number that cycles through
the values 0..256 every 4.096 seconds...
Ensure that the first is an integer multiple of the second
*/
extern UDWORD getTimeValueRange(UDWORD tickFrequency, UDWORD requiredRange);
extern UDWORD getStaticTimeValueRange(UDWORD tickFrequency, UDWORD requiredRange);
extern void getTimeComponents(UDWORD time, UDWORD *hours, UDWORD *minutes, UDWORD *seconds);
#endif

View File

@ -1,468 +0,0 @@
/***************************************************************************/
#include <limits.h>
#include <memory.h>
#include "frame.h"
#include "hashtabl.h"
extern void * g_ElementToBeRemoved;
/***************************************************************************/
#define HASHTEST 1
/* next four used in HashPJW */
#define BITS_IN_int 32
#define THREE_QUARTERS ((UINT) ((BITS_IN_int * 3) / 4))
#define ONE_EIGHTH ((UINT) (BITS_IN_int / 8))
//#define HIGH_BITS ( ~((UINT)(~0) >> ONE_EIGHTH )) /* DOES NOT WORK ON THE PSX ! use the version below */
#define HIGH_BITS ((UINT)( ~((0xffffffff) >> ONE_EIGHTH )))
/***************************************************************************/
UINT
HashTest( int iKey1, int iKey2 )
{
return (UINT) iKey1 + iKey2;
}
/***************************************************************************/
/*
* HashPJW
*
* Adaptation of Peter Weinberger's (PJW) generic hashing algorithm listed
* in Binstock+Rex, "Practical Algorithms" p 69.
*
* Accepts element pointer and returns hashed integer.
*/
/***************************************************************************/
UINT
HashPJW( int iKey1, int iKey2 )
{
UINT iHashValue, i;
CHAR *c = (CHAR *) iKey1;
/* don't use second key in this one */
iKey2 = UNUSED_KEY;
for ( iHashValue=0; *c; ++c )
{
iHashValue = ( iHashValue << ONE_EIGHTH ) + *c;
if ( (i = iHashValue & HIGH_BITS) != 0 )
{
iHashValue = ( iHashValue ^ ( i >> THREE_QUARTERS ) ) &
~HIGH_BITS;
}
}
return iHashValue;
}
/***************************************************************************/
BOOL
hashTable_Create( HASHTABLE **ppsTable, UDWORD udwTableSize,
UDWORD udwInitElements, UDWORD udwExtElements, UDWORD udwElementSize )
{
UDWORD udwSize;
/* allocate and init table */
(*ppsTable) = MALLOC( sizeof(HASHTABLE) );
udwSize = udwTableSize * sizeof(HASHNODE *);
(*ppsTable)->ppsNode = MALLOC( udwSize );
memset( (*ppsTable)->ppsNode, 0, udwSize );
/* allocate heaps */
if ( !HEAP_CREATE( &(*ppsTable)->psNodeHeap, sizeof(HASHNODE),
udwInitElements, udwExtElements) )
{
return FALSE;
}
if ( !HEAP_CREATE( &(*ppsTable)->psElementHeap, udwElementSize,
udwInitElements, udwExtElements) )
{
// my_error("",0,"","htc FAIL!\n");
return FALSE;
}
/* init members */
(*ppsTable)->udwTableSize = udwTableSize;
(*ppsTable)->udwElements = udwInitElements;
(*ppsTable)->udwExtElements = udwExtElements;
(*ppsTable)->udwElementSize = udwElementSize;
(*ppsTable)->sdwCurIndex = 0;
(*ppsTable)->psNextNode = (*ppsTable)->ppsNode[0];
(*ppsTable)->pFreeFunc = NULL;
/* set hash function to internal */
#if HASHTEST
hashTable_SetHashFunction( (*ppsTable), HashTest );
#else
hashTable_SetHashFunction( (*ppsTable), HashPJW );
#endif
return TRUE;
}
/***************************************************************************/
void
hashTable_Destroy( HASHTABLE *psTable )
{
ASSERT( (PTRVALID(psTable, sizeof(HASHTABLE)),
"hashTable_Destroy: table pointer invalid\n") );
hashTable_Clear( psTable );
/* destroy heaps */
HEAP_DESTROY( psTable->psNodeHeap );
HEAP_DESTROY( psTable->psElementHeap );
/* free table */
FREE( psTable->ppsNode );
FREE( psTable );
}
/***************************************************************************/
/*
* hashTable_Clear
*
* Returns all nodes from hash table to free node list
*/
/***************************************************************************/
void
hashTable_Clear( HASHTABLE *psTable )
{
HASHNODE *psNode, *psNodeTmp;
UDWORD i;
ASSERT( (PTRVALID(psTable, sizeof(HASHTABLE)),
"hashTable_Destroy: table pointer invalid\n") );
/* free nodes */
for ( i=0; i<psTable->udwTableSize; i++ )
{
/* free table entry nodelist */
psNode = psTable->ppsNode[i];
while ( psNode != NULL )
{
/* return node element to heap */
ASSERT( (PTRVALID(psNode->psElement, psTable->udwElementSize),
"hashTable_Destroy: element pointer invalid\n") );
/* do free-element callback if set */
if ( psTable->pFreeFunc != NULL )
{
(psTable->pFreeFunc) (psNode->psElement);
}
/* free element */
HEAP_FREE( psTable->psElementHeap, psNode->psElement );
/* return node to heap */
ASSERT( (PTRVALID(psNode, sizeof(HASHNODE)),
"hashTable_Destroy: node pointer invalid\n") );
psNodeTmp = psNode->psNext;
HEAP_FREE( psTable->psNodeHeap, psNode );
psNode = psNodeTmp;
}
/* set table entry to NULL */
psTable->ppsNode[i] = NULL;
}
}
/***************************************************************************/
void
hashTable_SetHashFunction( HASHTABLE *psTable, HASHFUNC pHashFunc )
{
ASSERT( (PTRVALID(psTable, sizeof(HASHTABLE)),
"hashTable_SetHashFunction: table pointer invalid\n") );
psTable->pHashFunc = pHashFunc;
}
/***************************************************************************/
void
hashTable_SetFreeElementFunction( HASHTABLE *psTable,
HASHFREEFUNC pFreeFunc )
{
ASSERT( (PTRVALID(psTable, sizeof(HASHTABLE)),
"hashTable_SetFreeElementFunction: table pointer invalid\n") );
psTable->pFreeFunc = pFreeFunc;
}
/***************************************************************************/
/*
* hashTable_GetElement
*
* Gets free node from heap and returns element pointer
*/
/***************************************************************************/
void *
hashTable_GetElement( HASHTABLE *psTable )
{
void *psElement;
BOOL result;
ASSERT( (PTRVALID(psTable, sizeof(HASHTABLE)),
"hashTable_GetElement: table pointer invalid\n") );
result=HEAP_ALLOC( psTable->psElementHeap, &psElement );
// if the alloc fails then return NULL
if (result==FALSE) return NULL;
return psElement;
}
/***************************************************************************/
UDWORD
hashTable_GetHashKey( HASHTABLE *psTable, int iKey1, int iKey2 )
{
ASSERT( (PTRVALID(psTable, sizeof(HASHTABLE)),
"hashTable_GetFirst: hash table pointer invalid\n") );
/* get hashed index */
return (psTable->pHashFunc) ( iKey1, iKey2 ) % psTable->udwTableSize;
}
/***************************************************************************/
void
hashTable_InsertElement( HASHTABLE *psTable, void *psElement,
int iKey1, int iKey2 )
{
UDWORD udwHashIndex;
HASHNODE *psNode;
ASSERT( (PTRVALID(psTable, sizeof(HASHTABLE)),
"hashTable_InsertElement: table pointer invalid\n") );
ASSERT( (PTRVALID(psElement, psTable->udwElementSize),
"hashTable_InsertElement: element pointer invalid\n") );
/* get hashed index */
udwHashIndex = hashTable_GetHashKey( psTable, iKey1, iKey2 );
/* get node from heap */
HEAP_ALLOC( psTable->psNodeHeap, (void*) &psNode );
/* set node elements */
psNode->iKey1 = iKey1;
psNode->iKey2 = iKey2;
psNode->psElement = psElement;
/* add new node to head of list */
psNode->psNext = psTable->ppsNode[udwHashIndex];
psTable->ppsNode[udwHashIndex] = psNode;
}
/***************************************************************************/
/*
* hashTable_FindElement
*
* Calculates hash index from keys and returns element in hash table
*/
/***************************************************************************/
void *
hashTable_FindElement( HASHTABLE *psTable, int iKey1, int iKey2 )
{
UDWORD udwHashIndex;
HASHNODE *psNode;
ASSERT( (PTRVALID(psTable, sizeof(HASHTABLE)),
"hashTable_FindElement: table pointer invalid\n") );
/* get hashed index */
udwHashIndex = hashTable_GetHashKey( psTable, iKey1, iKey2 );
/* check hash index within bounds */
ASSERT( (udwHashIndex>=0 && udwHashIndex<psTable->udwTableSize,
"hashTable_GetElement: hash value %i too large for table size %i\n",
udwHashIndex, psTable->udwTableSize) );
psNode = psTable->ppsNode[udwHashIndex];
/* loop through node list to find element match */
while ( psNode != NULL &&
!( psNode->iKey1 == iKey1 && psNode->iKey2 == iKey2) )
{
psNode = psNode->psNext;
}
/* remove node from hash table and return to heap */
if ( psNode == NULL )
{
return FALSE;
}
else
{
return psNode->psElement;
}
}
/***************************************************************************/
static void
hashTable_SetNextNode( HASHTABLE *psTable, BOOL bMoveToNextNode )
{
if ( (bMoveToNextNode == TRUE) && (psTable->psNextNode != NULL) )
{
/* get next node */
psTable->psNextNode = psTable->psNextNode->psNext;
/* if next node NULL increment index */
if ( psTable->psNextNode == NULL )
{
psTable->sdwCurIndex++;
}
}
/* search through table for next allocated node */
while ( psTable->sdwCurIndex < psTable->udwTableSize &&
psTable->psNextNode == NULL )
{
psTable->psNextNode = psTable->ppsNode[psTable->sdwCurIndex];
if ( psTable->psNextNode == NULL )
{
psTable->sdwCurIndex++;
}
}
/* reset pointer if table overrun */
if ( psTable->sdwCurIndex >= psTable->udwTableSize )
{
psTable->psNextNode = NULL;
}
}
/***************************************************************************/
BOOL
hashTable_RemoveElement( HASHTABLE *psTable, void *psElement,
int iKey1, int iKey2 )
{
UDWORD udwHashIndex;
HASHNODE *psNode, *psPrev;
ASSERT( (PTRVALID(psTable, sizeof(HASHTABLE)),
"hashTable_RemoveElement: table pointer invalid\n") );
/* get hashed index */
udwHashIndex = hashTable_GetHashKey( psTable, iKey1, iKey2 );
/* init previous node pointer */
psPrev = NULL;
/* get first node in table slot */
psNode = psTable->ppsNode[udwHashIndex];
/* loop through node list to find element match */
while ( psNode != NULL && !( psElement == psNode->psElement &&
psNode->iKey1 == iKey1 && psNode->iKey2 == iKey2) )
{
psPrev = psNode;
psNode = psNode->psNext;
}
/* remove node from hash table and return to heap */
if ( psNode == NULL )
{
return FALSE;
}
else
{
/* remove from hash table */
if ( psPrev == NULL )
{
psTable->ppsNode[udwHashIndex] = psNode->psNext;
}
else
{
psPrev->psNext = psNode->psNext;
}
/* set next node pointer to this one if necessary */
if ( psTable->psNextNode == psNode )
{
psTable->psNextNode = psPrev;
}
/* setup next node pointer */
hashTable_SetNextNode( psTable, TRUE );
/* return element to heap */
ASSERT( (PTRVALID(psNode->psElement, psTable->udwElementSize),
"hashTable_RemoveElement: element pointer invalid\n") );
HEAP_FREE( psTable->psElementHeap, psNode->psElement );
/* return node to heap */
ASSERT( (PTRVALID(psNode, sizeof(HASHNODE)),
"hashTable_RemoveElement: node pointer invalid\n") );
HEAP_FREE( psTable->psNodeHeap, psNode );
return TRUE;
}
}
/***************************************************************************/
void *
hashTable_GetNext( HASHTABLE *psTable )
{
void *psElement;
ASSERT( (PTRVALID(psTable, sizeof(HASHTABLE)),
"hashTable_GetNext: hash table pointer invalid\n") );
if ( psTable->psNextNode == NULL )
{
return NULL;
}
else
{
psElement = psTable->psNextNode->psElement;
/* setup next node pointer */
hashTable_SetNextNode( psTable, TRUE );
return psElement;
}
}
/***************************************************************************/
void *
hashTable_GetFirst( HASHTABLE *psTable )
{
ASSERT( (PTRVALID(psTable, sizeof(HASHTABLE)),
"hashTable_GetFirst: hash table pointer invalid\n") );
/* init current index and node to start of table */
psTable->sdwCurIndex = 0;
psTable->psNextNode = psTable->ppsNode[0];
/* search through table for first allocated node */
hashTable_SetNextNode( psTable, FALSE );
/* return it */
return hashTable_GetNext( psTable );
}
/***************************************************************************/

View File

@ -1,82 +0,0 @@
/***************************************************************************/
#ifndef _HASHTABL_H_
#define _HASHTABL_H_
/***************************************************************************/
#include "frame.h"
/***************************************************************************/
/* defines
*/
/* flags key not used in hash function */
#define UNUSED_KEY -747
/***************************************************************************/
/* macros
*/
typedef UDWORD (* HASHFUNC) ( int iKey1, int iKey2 );
typedef void (* HASHFREEFUNC) ( void *psElement );
/***************************************************************************/
/* structs
*/
typedef struct HASHNODE
{
int iKey1;
int iKey2;
void *psElement;
struct HASHNODE *psNext;
}
HASHNODE;
typedef struct HASHTABLE
{
OBJ_HEAP *psNodeHeap;
OBJ_HEAP *psElementHeap;
HASHNODE **ppsNode;
HASHNODE *psNextNode;
HASHFUNC pHashFunc;
HASHFREEFUNC pFreeFunc;
UDWORD udwTableSize;
UDWORD udwElements;
UDWORD udwExtElements;
UDWORD udwElementSize;
UDWORD sdwCurIndex;
}
HASHTABLE;
/***************************************************************************/
/* functions
*/
BOOL hashTable_Create( HASHTABLE **ppsTable, UDWORD udwTableSize,
UDWORD udwInitElements, UDWORD udwExtElements,
UDWORD udwElementSize );
void hashTable_Destroy( HASHTABLE *psTable );
void hashTable_Clear( HASHTABLE *psTable );
void * hashTable_GetElement( HASHTABLE *psTable );
void hashTable_InsertElement( HASHTABLE *psTable, void *psElement,
int iKey1, int iKey2 );
BOOL hashTable_RemoveElement( HASHTABLE *psTable, void *psElement,
int iKey1, int iKey2 );
void * hashTable_FindElement( HASHTABLE *psTable,
int iKey1, int iKey2 );
void * hashTable_GetFirst( HASHTABLE *psTable );
void * hashTable_GetNext( HASHTABLE *psTable );
void hashTable_SetHashFunction( HASHTABLE *psTable, HASHFUNC pHashFunc );
void hashTable_SetFreeElementFunction( HASHTABLE *psTable,
HASHFREEFUNC pFreeFunc );
/***************************************************************************/
#endif // _HASHTABL_H_
/***************************************************************************/

View File

@ -1,18 +0,0 @@
/***************************************************************************/
/*
* Definitions exported to anim.h
*/
/***************************************************************************/
#ifndef _MAXPIDEF_H_
#define _MAXPIDEF_H_
/***************************************************************************/
#define INT_SCALE 1000
/***************************************************************************/
#endif // _MAXPIDEF_H_
/***************************************************************************/

View File

@ -1,24 +0,0 @@
/***************************************************************************/
#ifndef _PARSER_H_
#define _PARSER_H_
/***************************************************************************/
#include <stdio.h>
/***************************************************************************/
extern void IncludeFile( char szFileName[] );
extern BOOL ParseFile( char szFileName[] );
extern void IncludeFile( char szFileName[] );
extern void parserSetInputBuffer( UBYTE *pBuffer, UDWORD size );
extern BOOL ParseResourceFile( UBYTE *pData, UDWORD fileSize );
extern BOOL ParsingBuffer( void );
extern void parseGetErrorData(int *pLine, char **ppText);
/***************************************************************************/
#endif /* _PARSER_H_ */
/***************************************************************************/

View File

@ -1,865 +0,0 @@
/* d:\mks-ly\mksnt\lex -p audp_ -o parser_l.c .\parser.l */
#define YYNEWLINE 10
#define INITIAL 0
#define COMMENT 2
#define QUOTE 4
#define audp__endst 85
#define audp__nxtmax 588
#define YY_LA_SIZE 11
static unsigned int audp__la_act[] = {
11, 18, 11, 18, 11, 18, 11, 18, 18, 9, 18, 11, 18, 11, 18, 12,
18, 12, 18, 18, 13, 11, 11, 10, 10, 11, 9, 11, 11, 11, 11, 11,
11, 11, 11, 11, 8, 11, 11, 11, 11, 11, 11, 11, 7, 11, 11, 11,
11, 11, 6, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 5,
11, 11, 11, 11, 11, 3, 11, 11, 11, 2, 11, 11, 11, 11, 11, 11,
11, 4, 11, 11, 11, 1, 11, 11, 11, 11, 11, 11, 0, 11, 16, 16,
17, 14, 15, 0
};
static unsigned char audp__look[] = {
0
};
static int audp__final[] = {
0, 0, 2, 4, 6, 8, 9, 11, 13, 15, 17, 18, 19, 20, 21, 22,
22, 23, 24, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 38, 39,
40, 41, 42, 43, 44, 46, 47, 48, 49, 50, 52, 53, 54, 55, 56, 57,
58, 59, 60, 61, 62, 63, 65, 66, 67, 68, 69, 71, 72, 73, 75, 76,
77, 78, 79, 80, 81, 83, 84, 85, 87, 88, 89, 90, 91, 92, 94, 94,
95, 96, 97, 98, 99, 99
};
#ifndef audp__state_t
#define audp__state_t unsigned char
#endif
static audp__state_t audp__begin[] = {
0, 0, 78, 78, 84, 84, 0
};
static audp__state_t audp__next[] = {
12, 12, 12, 12, 12, 12, 12, 12, 12, 9, 10, 12, 12, 9, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
9, 12, 7, 8, 12, 12, 12, 12, 12, 12, 12, 12, 12, 5, 8, 11,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 12, 12, 12, 12, 12, 12,
12, 4, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 12, 12, 12, 12, 12,
12, 3, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 2, 8, 8, 1,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 12, 12, 12, 12, 12,
13, 14, 14, 20, 21, 22, 25, 26, 27, 28, 29, 30, 14, 14, 31, 14,
14, 14, 14, 14, 14, 14, 14, 14, 14, 33, 34, 35, 32, 36, 23, 37,
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 24, 38, 39, 40, 14, 41,
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15,
15, 15, 15, 15, 17, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 18, 16, 15, 15,
15, 15, 15, 15, 15, 15, 15, 16, 16, 15, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 15, 15, 15, 15, 16, 15, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 17, 15, 43, 44, 45, 48,
49, 50, 51, 42, 52, 15, 15, 46, 15, 15, 15, 15, 15, 15, 15, 15,
15, 15, 53, 54, 55, 56, 57, 58, 59, 15, 15, 15, 15, 15, 15, 15,
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
15, 15, 15, 47, 60, 61, 62, 15, 63, 15, 15, 15, 15, 15, 15, 15,
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
15, 15, 15, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 64, 65, 66,
67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 80, 80, 80, 80, 80,
80, 80, 80, 80, 80, 81, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80,
80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80,
80, 80, 80, 80, 80, 79, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80,
80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80,
80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80,
80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80,
80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80,
80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 82, 83, 0
};
static audp__state_t audp__check[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
11, 8, 8, 4, 20, 21, 24, 25, 26, 27, 28, 23, 8, 8, 30, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 32, 33, 34, 30, 35, 22, 31,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 22, 37, 38, 39, 8, 40,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 15, 15, 3, 43, 44, 47,
48, 49, 50, 3, 51, 15, 15, 45, 15, 15, 15, 15, 15, 15, 15, 15,
15, 15, 52, 46, 54, 55, 56, 57, 42, 15, 15, 15, 15, 15, 15, 15,
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
15, 15, 15, 45, 59, 60, 61, 15, 62, 15, 15, 15, 15, 15, 15, 15,
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
15, 15, 15, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 63, 64, 65,
66, 67, 2, 69, 70, 1, 72, 73, 74, 75, 76, 78, 78, 78, 78, 78,
78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78,
78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78,
78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78,
78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78,
78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78,
78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78,
78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78,
78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 79, 82, 0
};
static audp__state_t audp__default[] = {
85, 8, 8, 8, 8, 6, 85, 85, 85, 85, 85, 85, 85, 85, 8, 7,
7, 85, 8, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 85, 85,
85, 85, 85, 85, 85, 0
};
static int audp__base[] = {
0, 343, 339, 238, 53, 589, 387, 218, 95, 589, 589, 86, 589, 589, 589, 312,
589, 589, 589, 589, 59, 56, 107, 71, 68, 61, 67, 70, 54, 589, 72, 77,
71, 89, 77, 74, 589, 122, 111, 120, 108, 589, 276, 244, 241, 308, 271, 242,
241, 253, 237, 248, 269, 589, 270, 268, 266, 274, 589, 299, 294, 311, 299, 334,
346, 330, 340, 348, 589, 340, 340, 589, 353, 340, 352, 346, 342, 589, 459, 540,
589, 589, 578, 589, 589, 589
};
/*
* Copyright 1988, 1992 by Mortice Kern Systems Inc. All rights reserved.
* All rights reserved.
*
* $Header: /u/rd/src/lex/rcs/audp_lex.c 1.57 1995/12/11 22:14:06 fredw Exp $
*
*/
#include <stdlib.h>
#include <stdio.h>
#if __STDC__
#define YY_ARGS(args) args
#else
#define YY_ARGS(args) ()
#endif
#ifdef LEX_WINDOWS
#include <windows.h>
/*
* define, if not already defined
* the flag YYEXIT, which will allow
* graceful exits from audp_lex()
* without resorting to calling exit();
*/
#ifndef YYEXIT
#define YYEXIT 1
#endif
/*
* the following is the handle to the current
* instance of a windows program. The user
* program calling audp_lex must supply this!
*/
#ifdef STRICT
extern HINSTANCE hInst;
#else
extern HANDLE hInst;
#endif
#endif /* LEX_WINDOWS */
/*
* Define m_textmsg() to an appropriate function for internationalized messages
* or custom processing.
*/
#ifndef I18N
#define m_textmsg(id, str, cls) (str)
#else /*I18N*/
extern char* m_textmsg YY_ARGS((int id, const char* str, char* cls));
#endif/*I18N*/
/*
* Include string.h to get definition of memmove() and size_t.
* If you do not have string.h or it does not declare memmove
* or size_t, you will have to declare them here.
*/
#include <string.h>
/* Uncomment next line if memmove() is not declared in string.h */
/*extern char * memmove();*/
/* Uncomment next line if size_t is not available in stdio.h or string.h */
/*typedef unsigned size_t;*/
/* Drop this when LATTICE provides memmove */
#ifdef LATTICE
#define memmove memcopy
#endif
/*
* YY_STATIC determines the scope of variables and functions
* declared by the lex scanner. It must be set with a -DYY_STATIC
* option to the compiler (it cannot be defined in the lex program).
*/
#ifdef YY_STATIC
/* define all variables as static to allow more than one lex scanner */
#define YY_DECL static
#else
/* define all variables as global to allow other modules to access them */
#define YY_DECL
#endif
/*
* You can redefine audp_getc. For YACC Tracing, compile this code
* with -DYYTRACE to get input from yt_getc
*/
#ifdef YYTRACE
extern int yt_getc YY_ARGS((void));
#define audp_getc() yt_getc()
#else
#define audp_getc() getc(audp_in) /* audp_lex input source */
#endif
/*
* the following can be redefined by the user.
*/
#ifdef YYEXIT
#define YY_FATAL(msg) { fprintf(audp_out, "audp_lex: %s\n", msg); audp_LexFatal = 1; }
#else /* YYEXIT */
#define YY_FATAL(msg) { fprintf(stderr, "audp_lex: %s\n", msg); exit(1); }
#endif /* YYEXIT */
#undef ECHO
#define ECHO fputs(audp_text, audp_out)
#define output(c) putc((c), audp_out) /* audp_lex sink for unmatched chars */
#define YY_INTERACTIVE 1 /* save micro-seconds if 0 */
#define BEGIN audp__start =
#define REJECT goto audp__reject
#define NLSTATE (audp__lastc = YYNEWLINE)
#define YY_INIT \
(audp__start = audp_leng = audp__end = 0, audp__lastc = YYNEWLINE)
#define audp_more() goto audp__more
#define audp_less(n) if ((n) < 0 || (n) > audp__end) ; \
else { YY_SCANNER; audp_leng = (n); YY_USER; }
YY_DECL void audp__reset YY_ARGS((void));
/* functions defined in libl.lib */
extern int audp_wrap YY_ARGS((void));
extern void audp_error YY_ARGS((char *fmt, ...));
extern void audp_comment YY_ARGS((char *term));
extern int audp_mapch YY_ARGS((int delim, int escape));
#include <stdio.h>
/* include framework */
#include "frame.h"
#include "parser.h"
/* Get the Yacc definitions */
#include "parser_y.h"
/* Maximum length for any TEXT value */
#define YYLMAX 255
/* extern funcs */
extern int audp_parse YY_ARGS( (void) );
/* global variables */
static BOOL g_bParsingSubFile;
static FILE *g_fpOld;
/* Pointer to the input buffer */
static UBYTE *pInputBuffer = NULL;
static UBYTE *pEndBuffer = NULL;
#undef audp_getc
#define audp_getc() ( pInputBuffer != pEndBuffer ? *(pInputBuffer++) : EOF )
#ifndef YYLMAX
#define YYLMAX 100 /* token and pushback buffer size */
#endif /* YYLMAX */
/*
* If %array is used (or defaulted), audp_text[] contains the token.
* If %pointer is used, audp_text is a pointer to audp__tbuf[].
*/
YY_DECL char audp_text[YYLMAX+1];
#ifdef YY_DEBUG
#undef YY_DEBUG
#define YY_DEBUG(fmt, a1, a2) fprintf(stderr, fmt, a1, a2)
#else
#define YY_DEBUG(fmt, a1, a2)
#endif
/*
* The declaration for the lex scanner can be changed by
* redefining YYLEX or YYDECL. This must be done if you have
* more than one scanner in a program.
*/
#ifndef YYLEX
#define YYLEX audp_lex /* name of lex scanner */
#endif
#ifndef YYDECL
#define YYDECL int YYLEX YY_ARGS((void)) /* declaration for lex scanner */
#endif
/*
* stdin and stdout may not neccessarily be constants.
* If stdin and stdout are constant, and you want to save a few cycles, then
* #define YY_STATIC_STDIO 1 in this file or on the commandline when
* compiling this file
*/
#ifndef YY_STATIC_STDIO
#define YY_STATIC_STDIO 0
#endif
#if YY_STATIC_STDIO
YY_DECL FILE *audp_in = stdin;
YY_DECL FILE *audp_out = stdout;
#else
YY_DECL FILE *audp_in = (FILE *)0;
YY_DECL FILE *audp_out = (FILE *)0;
#endif
YY_DECL int audp_lineno = 1; /* line number */
/* audp__sbuf[0:audp_leng-1] contains the states corresponding to audp_text.
* audp_text[0:audp_leng-1] contains the current token.
* audp_text[audp_leng:audp__end-1] contains pushed-back characters.
* When the user action routine is active,
* audp__save contains audp_text[audp_leng], which is set to '\0'.
* Things are different when YY_PRESERVE is defined.
*/
static audp__state_t audp__sbuf [YYLMAX+1]; /* state buffer */
static int audp__end = 0; /* end of pushback */
static int audp__start = 0; /* start state */
static int audp__lastc = YYNEWLINE; /* previous char */
YY_DECL int audp_leng = 0; /* audp_text token length */
#ifdef YYEXIT
static int audp_LexFatal;
#endif /* YYEXIT */
#ifndef YY_PRESERVE /* the efficient default push-back scheme */
static char audp__save; /* saved audp_text[audp_leng] */
#define YY_USER { /* set up audp_text for user */ \
audp__save = audp_text[audp_leng]; \
audp_text[audp_leng] = 0; \
}
#define YY_SCANNER { /* set up audp_text for scanner */ \
audp_text[audp_leng] = audp__save; \
}
#else /* not-so efficient push-back for audp_text mungers */
static char audp__save [YYLMAX];
static char *audp__push = audp__save+YYLMAX;
#define YY_USER { \
size_t n = audp__end - audp_leng; \
audp__push = audp__save+YYLMAX - n; \
if (n > 0) \
memmove(audp__push, audp_text+audp_leng, n); \
audp_text[audp_leng] = 0; \
}
#define YY_SCANNER { \
size_t n = audp__save+YYLMAX - audp__push; \
if (n > 0) \
memmove(audp_text+audp_leng, audp__push, n); \
audp__end = audp_leng + n; \
}
#endif
#ifdef LEX_WINDOWS
/*
* When using the windows features of lex,
* it is necessary to load in the resources being
* used, and when done with them, the resources must
* be freed up, otherwise we have a windows app that
* is not following the rules. Thus, to make audp_lex()
* behave in a windows environment, create a new
* audp_lex() which will call the original audp_lex() as
* another function call. Observe ...
*/
/*
* The actual lex scanner (usually audp_lex(void)).
* NOTE: you should invoke audp__init() if you are calling audp_lex()
* with new input; otherwise old lookaside will get in your way
* and audp_lex() will die horribly.
*/
static int win_audp_lex(); /* prototype for windows audp_lex handler */
YYDECL {
int wReturnValue;
HANDLE hRes_table;
unsigned short far *old_audp__la_act; /* remember previous pointer values */
short far *old_audp__final;
audp__state_t far *old_audp__begin;
audp__state_t far *old_audp__next;
audp__state_t far *old_audp__check;
audp__state_t far *old_audp__default;
short far *old_audp__base;
/*
* the following code will load the required
* resources for a Windows based parser.
*/
hRes_table = LoadResource (hInst,
FindResource (hInst, "UD_RES_audp_LEX", "audp_LEXTBL"));
/*
* return an error code if any
* of the resources did not load
*/
if (hRes_table == NULL)
return (0);
/*
* the following code will lock the resources
* into fixed memory locations for the scanner
* (and remember previous pointer locations)
*/
old_audp__la_act = audp__la_act;
old_audp__final = audp__final;
old_audp__begin = audp__begin;
old_audp__next = audp__next;
old_audp__check = audp__check;
old_audp__default = audp__default;
old_audp__base = audp__base;
audp__la_act = (unsigned short far *)LockResource (hRes_table);
audp__final = (short far *)(audp__la_act + Sizeof_audp__la_act);
audp__begin = (audp__state_t far *)(audp__final + Sizeof_audp__final);
audp__next = (audp__state_t far *)(audp__begin + Sizeof_audp__begin);
audp__check = (audp__state_t far *)(audp__next + Sizeof_audp__next);
audp__default = (audp__state_t far *)(audp__check + Sizeof_audp__check);
audp__base = (audp__state_t far *)(audp__default + Sizeof_audp__default);
/*
* call the standard audp_lex() code
*/
wReturnValue = win_audp_lex();
/*
* unlock the resources
*/
UnlockResource (hRes_table);
/*
* and now free the resource
*/
FreeResource (hRes_table);
/*
* restore previously saved pointers
*/
audp__la_act = old_audp__la_act;
audp__final = old_audp__final;
audp__begin = old_audp__begin;
audp__next = old_audp__next;
audp__check = old_audp__check;
audp__default = old_audp__default;
audp__base = old_audp__base;
return (wReturnValue);
} /* end function */
static int win_audp_lex() {
#else /* LEX_WINDOWS */
/*
* The actual lex scanner (usually audp_lex(void)).
* NOTE: you should invoke audp__init() if you are calling audp_lex()
* with new input; otherwise old lookaside will get in your way
* and audp_lex() will die horribly.
*/
YYDECL {
#endif /* LEX_WINDOWS */
register int c, i, audp_base;
unsigned audp_st; /* state */
int audp_fmin, audp_fmax; /* audp__la_act indices of final states */
int audp_oldi, audp_oleng; /* base i, audp_leng before look-ahead */
int audp_eof; /* 1 if eof has already been read */
#if !YY_STATIC_STDIO
if (audp_in == (FILE *)0)
audp_in = stdin;
if (audp_out == (FILE *)0)
audp_out = stdout;
#endif
#ifdef YYEXIT
audp_LexFatal = 0;
#endif /* YYEXIT */
audp_eof = 0;
i = audp_leng;
YY_SCANNER;
audp__again:
audp_leng = i;
/* determine previous char. */
if (i > 0)
audp__lastc = audp_text[i-1];
/* scan previously accepted token adjusting audp_lineno */
while (i > 0)
if (audp_text[--i] == YYNEWLINE)
audp_lineno++;
/* adjust pushback */
audp__end -= audp_leng;
if (audp__end > 0)
memmove(audp_text, audp_text+audp_leng, (size_t) audp__end);
i = 0;
audp_oldi = i;
/* run the state machine until it jams */
audp_st = audp__begin[audp__start + ((audp__lastc == YYNEWLINE) ? 1 : 0)];
audp__sbuf[i] = (audp__state_t) audp_st;
do {
YY_DEBUG(m_textmsg(1547, "<state %d, i = %d>\n", "I num1 num2"), audp_st, i);
if (i >= YYLMAX) {
YY_FATAL(m_textmsg(1548, "Token buffer overflow", "E"));
#ifdef YYEXIT
if (audp_LexFatal)
return -2;
#endif /* YYEXIT */
} /* endif */
/* get input char */
if (i < audp__end)
c = audp_text[i]; /* get pushback char */
else if (!audp_eof && (c = audp_getc()) != EOF) {
audp__end = i+1;
audp_text[i] = (char) c;
} else /* c == EOF */ {
c = EOF; /* just to make sure... */
if (i == audp_oldi) { /* no token */
audp_eof = 0;
if (audp_wrap())
return 0;
else
goto audp__again;
} else {
audp_eof = 1; /* don't re-read EOF */
break;
}
}
YY_DEBUG(m_textmsg(1549, "<input %d = 0x%02x>\n", "I num hexnum"), c, c);
/* look up next state */
while ((audp_base = audp__base[audp_st]+(unsigned char)c) > audp__nxtmax
|| audp__check[audp_base] != (audp__state_t) audp_st) {
if (audp_st == audp__endst)
goto audp__jammed;
audp_st = audp__default[audp_st];
}
audp_st = audp__next[audp_base];
audp__jammed: ;
audp__sbuf[++i] = (audp__state_t) audp_st;
} while (!(audp_st == audp__endst || (YY_INTERACTIVE && audp__base[audp_st] > audp__nxtmax && audp__default[audp_st] == audp__endst)));
YY_DEBUG(m_textmsg(1550, "<stopped %d, i = %d>\n", "I num1 num2"), audp_st, i);
if (audp_st != audp__endst)
++i;
/* search backward for a final state */
while (--i > audp_oldi) {
audp_st = audp__sbuf[i];
if ((audp_fmin = audp__final[audp_st]) < (audp_fmax = audp__final[audp_st+1]))
goto audp__found; /* found final state(s) */
}
/* no match, default action */
i = audp_oldi + 1;
output(audp_text[audp_oldi]);
goto audp__again;
audp__found:
YY_DEBUG(m_textmsg(1551, "<final state %d, i = %d>\n", "I num1 num2"), audp_st, i);
audp_oleng = i; /* save length for REJECT */
/* pushback look-ahead RHS */
if ((c = (int)(audp__la_act[audp_fmin]>>9) - 1) >= 0) { /* trailing context? */
unsigned char *bv = audp__look + c*YY_LA_SIZE;
static unsigned char bits [8] = {
1<<0, 1<<1, 1<<2, 1<<3, 1<<4, 1<<5, 1<<6, 1<<7
};
while (1) {
if (--i < audp_oldi) { /* no / */
i = audp_oleng;
break;
}
audp_st = audp__sbuf[i];
if (bv[(unsigned)audp_st/8] & bits[(unsigned)audp_st%8])
break;
}
}
/* perform action */
audp_leng = i;
YY_USER;
switch (audp__la_act[audp_fmin] & 0777) {
case 0:
{ return ONESHOT; }
break;
case 1:
{ return LOOP; }
break;
case 2:
{ return AUDIO; }
break;
case 3:
{ return ANIM3DFILE; }
break;
case 4:
{ return AUDIO_MODULE; }
break;
case 5:
{ return ANIM_MODULE; }
break;
case 6:
{ return ANIM3DFRAMES; }
break;
case 7:
{ return ANIM3DTRANS; }
break;
case 8:
{ return ANIMOBJECT; }
break;
case 9:
{ audp_lval.ival = atoi(audp_text);
return INTEGER;
}
break;
case 10:
{
/* skip opening quote */
strcpy( audp_lval.sval, audp_text+1 );
/* check for unterminated string */
if ( audp_text[audp_leng-1] != '"' )
{
sprintf( audp_lval.sval, "Unterminated string %s\n", audp_lval.sval );
audp_error( audp_lval.sval );
return (1);
}
/* set final quote in string to blank */
audp_lval.sval[audp_leng-2] = (char) NULL;
return QTEXT;
}
break;
case 11:
{ strcpy( audp_lval.sval, audp_text );
return TEXT;
}
break;
case 12:
;
break;
case 13:
{ BEGIN COMMENT; }
break;
case 14:
case 15:
{ BEGIN 0; }
break;
case 16:
case 17:
;
break;
case 18:
return audp_text[0];
break;
}
YY_SCANNER;
i = audp_leng;
goto audp__again; /* action fell though */
}
/*
* Safely switch input stream underneath LEX
*/
typedef struct audp__save_block_tag {
FILE * oldfp;
int oldline;
int oldend;
int oldstart;
int oldlastc;
int oldleng;
char savetext[YYLMAX+1];
audp__state_t savestate[YYLMAX+1];
} YY_SAVED;
YY_SAVED *
audp_SaveScan(FILE * fp)
{
YY_SAVED * p;
if ((p = (YY_SAVED *) malloc(sizeof(*p))) == NULL)
return p;
p->oldfp = audp_in;
p->oldline = audp_lineno;
p->oldend = audp__end;
p->oldstart = audp__start;
p->oldlastc = audp__lastc;
p->oldleng = audp_leng;
(void) memcpy(p->savetext, audp_text, sizeof audp_text);
(void) memcpy((char *) p->savestate, (char *) audp__sbuf,
sizeof audp__sbuf);
audp_in = fp;
audp_lineno = 1;
YY_INIT;
return p;
}
/*f
* Restore previous LEX state
*/
void
audp_RestoreScan(YY_SAVED * p)
{
if (p == NULL)
return;
audp_in = p->oldfp;
audp_lineno = p->oldline;
audp__end = p->oldend;
audp__start = p->oldstart;
audp__lastc = p->oldlastc;
audp_leng = p->oldleng;
(void) memcpy(audp_text, p->savetext, sizeof audp_text);
(void) memcpy((char *) audp__sbuf, (char *) p->savestate,
sizeof audp__sbuf);
free(p);
}
/*
* User-callable re-initialization of audp_lex()
*/
void
audp__reset()
{
YY_INIT;
audp_lineno = 1; /* line number */
}
/***************************************************************************/
BOOL
ParseFile( char szFileName[] )
{
FILE *fp;
/* open input file */
if ( (fp = fopen( szFileName, "rt" )) == NULL )
{
DBERROR( ("ParseFile: file not found\n") );
return FALSE;
}
/* point input to input file */
audp_in = fp;
audp_parse();
fclose( fp );
return TRUE;
}
/***************************************************************************/
void
IncludeFile( char szFileName[] )
{
FILE *fpNew;
/* open module file */
if ( (fpNew = fopen( szFileName, "rt" )) != NULL )
{
/* save current file pointer and switch to new */
g_fpOld = audp_in;
audp_in = fpNew;
g_bParsingSubFile = TRUE;
}
else
{
DBERROR( ("Included file %s not found\n", szFileName) );
}
}
/***************************************************************************/
int
audp_wrap( void )
{
if ( g_bParsingSubFile == TRUE )
{
/* close current file and restore old file pointer */
fclose( audp_in );
audp_in = g_fpOld;
g_bParsingSubFile = FALSE;
return 0;
}
else
{
return 1;
}
}
/***************************************************************************/
/* Set the current input buffer for the lexer */
/***************************************************************************/
void
parserSetInputBuffer( UBYTE *pBuffer, UDWORD size )
{
pInputBuffer = pBuffer;
pEndBuffer = pBuffer + size;
/* Reset the lexer in case it's been used before */
audp__reset();
}
/***************************************************************************/
void
parseGetErrorData(int *pLine, char **ppText)
{
*pLine = audp_lineno;
*ppText = audp_text;
}
/***************************************************************************/

File diff suppressed because it is too large Load Diff

View File

@ -1,22 +0,0 @@
typedef union {
float fval;
long ival;
signed char bval;
char sval[100];
} YYSTYPE;
#define FLOAT 257
#define INTEGER 258
#define TEXT 259
#define text 260
#define QTEXT 261
#define LOOP 262
#define ONESHOT 263
#define AUDIO 264
#define ANIM2D 265
#define ANIM3DFRAMES 266
#define ANIM3DTRANS 267
#define ANIM3DFILE 268
#define AUDIO_MODULE 269
#define ANIM_MODULE 270
#define ANIMOBJECT 271
extern YYSTYPE audp_lval;

View File

@ -1,472 +0,0 @@
/***************************************************************************/
/*
* Priority queue implementation
*
*
*/
/***************************************************************************/
#include "frame.h"
#include "priority.h"
#include "pqueue.h"
/***************************************************************************/
#define QUEUE_INSERTION_TEST 1
/***************************************************************************/
BOOL
queue_Init( QUEUE ** ppQueue, int iMaxElements, int iElementSize,
QUEUE_CLEAR_FUNC pfClearFunc )
{
int i;
QUEUE_NODE *psNode;
/* allocate queue */
(*ppQueue) = (QUEUE *) MALLOC( sizeof(QUEUE) );
if ( (*ppQueue) == NULL )
{
DBERROR( ("queue_Init: couldn't allocate memory for queue") );
return FALSE;
}
/* set up free node list */
(*ppQueue)->psFreeNodeList = NULL;
for ( i=0; i<iMaxElements; i++ )
{
/* allocate node */
psNode = (QUEUE_NODE *) MALLOC( sizeof(QUEUE_NODE) );
if ( (*ppQueue) == NULL )
{
DBERROR( ("queue_Init: couldn't allocate memory for queue node") );
return FALSE;
}
/* init node */
psNode->psElement = NULL;
psNode->iPriority = LOW_PRIORITY;
/* add to head of list */
psNode->psPrev = NULL;
psNode->psNext = (*ppQueue)->psFreeNodeList;
(*ppQueue)->psFreeNodeList = psNode;
}
/* init node counts */
(*ppQueue)->iFreeNodes = iMaxElements;
(*ppQueue)->iQueueNodes = 0;
/* init queue list */
(*ppQueue)->psNodeQHead = NULL;
(*ppQueue)->psCurNode = NULL;
/* init other queue struct members */
(*ppQueue)->iElementSize = iElementSize;
(*ppQueue)->iMaxElements = iMaxElements;
(*ppQueue)->pfClearFunc = pfClearFunc;
return TRUE;
}
/***************************************************************************/
void
queue_Destroy( QUEUE * pQueue )
{
QUEUE_NODE *psNode;
/* free up free node list */
while ( pQueue->psFreeNodeList != NULL )
{
psNode = pQueue->psFreeNodeList;
pQueue->psFreeNodeList = pQueue->psFreeNodeList->psNext;
FREE( psNode );
}
/* free up node queue */
while ( pQueue->psNodeQHead != NULL )
{
psNode = pQueue->psNodeQHead;
pQueue->psNodeQHead = pQueue->psNodeQHead->psNext;
FREE( psNode );
}
FREE( pQueue );
}
/***************************************************************************/
void queue_Clear( QUEUE * pQueue )
{
QUEUE_NODE *psNode;
while ( pQueue->psNodeQHead != NULL )
{
psNode = pQueue->psNodeQHead;
pQueue->psNodeQHead = pQueue->psNodeQHead->psNext;
/* do element callback */
(pQueue->pfClearFunc)(psNode->psElement);
/* return node to free node list */
psNode->psNext = pQueue->psFreeNodeList;
pQueue->psFreeNodeList = psNode;
/* update node counts */
pQueue->iFreeNodes++;
pQueue->iQueueNodes--;
}
}
/***************************************************************************/
/*
* queue_Enqueue
*
* Add element to queue in priority order
*/
/***************************************************************************/
void
queue_Enqueue( QUEUE * pQueue, void * psElement, int iPriority )
{
QUEUE_NODE *psFreeNode, *psNode, *psNodePrev;
/* check input */
ASSERT( (PTRVALID(pQueue,sizeof(QUEUE)),
"queue_Enqueue: queue pointer invalid\n") );
ASSERT( (PTRVALID(psElement,pQueue->iElementSize),
"queue_Enqueue: element pointer invalid\n") );
#if QUEUE_INSERTION_TEST
psNode = pQueue->psNodeQHead;
while ( psNode != NULL )
{
ASSERT( (psNode->psElement != psElement,
"duplicate element found\n") );
psNode = psNode->psNext;
}
#endif
/* check list not empty */
if ( pQueue->psFreeNodeList == NULL )
{
DBPRINTF( ("queue_GetFreeElement: all nodes allocated: flushing queue.\n") );
queue_Clear( pQueue );
}
/* get free node from head of list */
psFreeNode = pQueue->psFreeNodeList;
pQueue->psFreeNodeList = pQueue->psFreeNodeList->psNext;
/* update node counts */
pQueue->iFreeNodes--;
pQueue->iQueueNodes++;
/* attach element to node */
psFreeNode->psElement = psElement;
/* init pointer to head of queue */
psNode = pQueue->psNodeQHead;
psNodePrev = NULL;
/* init node priority */
psFreeNode->iPriority = iPriority;
/* find correct place in queue according to priority */
while ( psNode != NULL )
{
/* break if priority slot found */
if ( psNode->iPriority < iPriority )
{
break;
}
/* update pointers */
psNodePrev = psNode;
psNode = psNode->psNext;
}
/* insert new node */
psFreeNode->psPrev = psNodePrev;
psFreeNode->psNext = psNode;
/* update previous queue node pointer */
if ( psNodePrev == NULL )
{
pQueue->psNodeQHead = psFreeNode;
}
else
{
psNodePrev->psNext = psFreeNode;
}
/* update next queue node pointer */
if ( psNode != NULL )
{
psNode->psPrev = psFreeNode;
}
}
/***************************************************************************/
/*
* queue_Dequeue
*
* Remove head of queue
*/
/***************************************************************************/
void *
queue_Dequeue( QUEUE * pQueue )
{
void * psElement = NULL;
QUEUE_NODE * psNode;
/* check input */
ASSERT( (PTRVALID(pQueue,sizeof(QUEUE)),
"queue_Dequeue: queue pointer invalid\n") );
if ( pQueue->psNodeQHead != NULL )
{
/* remove node at head of queue */
psNode = pQueue->psNodeQHead;
pQueue->psNodeQHead = pQueue->psNodeQHead->psNext;
/* copy element from node for return */
psElement = psNode->psElement;
/* return node to free node list */
psNode->psNext = pQueue->psFreeNodeList;
pQueue->psFreeNodeList = psNode;
/* update node counts */
pQueue->iFreeNodes++;
pQueue->iQueueNodes--;
ASSERT( (pQueue->iQueueNodes >= 0, "queue_Dequeue: queue nodes < 0") );
}
return psElement;
}
/***************************************************************************/
/*
* queue_FindElement
*
* Find specific element in queue and return node pointer
*/
/***************************************************************************/
QUEUE_NODE *
queue_FindElement( QUEUE * pQueue, void * psElement )
{
QUEUE_NODE *psNode, *psNodePrev;
/* check input */
ASSERT( (PTRVALID(pQueue,sizeof(QUEUE)),
"queue_FindElement: queue pointer invalid\n") );
ASSERT( (PTRVALID(psElement,pQueue->iElementSize),
"queue_FindElement: element pointer invalid\n") );
/* init pointers to head of queue */
psNodePrev = psNode = pQueue->psNodeQHead;
/* find node in queue */
while ( psNodePrev != NULL && psNode != NULL )
{
/* return TRUE if match found */
if ( psNode->psElement == psElement )
{
return psNode;
}
/* update pointers */
psNodePrev = psNode;
psNode = psNode->psNext;
}
return NULL;
}
/***************************************************************************/
/*
* queue_GetHead
*
* Get element at head of queue
*/
/***************************************************************************/
void *
queue_GetHead( QUEUE * pQueue )
{
/* set current node to head of queue */
pQueue->psCurNode = pQueue->psNodeQHead;
if ( pQueue->psCurNode != NULL )
{
return pQueue->psCurNode->psElement;
}
else
{
return NULL;
}
}
/***************************************************************************/
/*
* queue_GetNext
*
* Get next element in queue
*/
/***************************************************************************/
void *
queue_GetNext( QUEUE * pQueue )
{
/* move to next node */
if ( pQueue->psCurNode != NULL )
{
pQueue->psCurNode = pQueue->psCurNode->psNext;
}
/* return node element */
if ( pQueue->psCurNode == NULL )
{
return NULL;
}
else
{
return pQueue->psCurNode->psElement;
}
}
/***************************************************************************/
/*
* queue_RemoveCurrent
*
* Remove current node from queue
*/
/***************************************************************************/
BOOL
queue_RemoveCurrent( QUEUE * pQueue )
{
return queue_RemoveNode( pQueue, pQueue->psCurNode );
}
/***************************************************************************/
/*
* queue_RemoveNode
*
* Remove node from queue
*/
/***************************************************************************/
BOOL
queue_RemoveNode( QUEUE * pQueue, QUEUE_NODE *psNode )
{
/* check input */
ASSERT( (PTRVALID(pQueue,sizeof(QUEUE)),
"queue_RemoveNode: queue pointer invalid\n") );
ASSERT( (PTRVALID(psNode,sizeof(QUEUE_NODE)),
"queue_RemoveNode: node pointer invalid\n") );
/* if node valid, remove from queue and return to free node list */
if ( psNode == NULL )
{
return FALSE;
}
else
{
/* remove node from queue */
if ( psNode->psPrev == NULL && psNode->psNext == NULL )
{
pQueue->psCurNode = NULL;
pQueue->psNodeQHead = NULL;
}
else
{
/* make previous node point to next */
if ( psNode->psPrev != NULL )
{
psNode->psPrev->psNext = psNode->psNext;
}
/* make next node point to previous */
if ( psNode->psNext != NULL )
{
psNode->psNext->psPrev = psNode->psPrev;
}
/* set current queue node if necessary */
if ( pQueue->psCurNode == psNode )
{
if ( psNode->psPrev != NULL )
{
pQueue->psCurNode = psNode->psPrev;
}
else if ( psNode->psNext != NULL )
{
pQueue->psCurNode = psNode->psNext;
}
else
{
pQueue->psCurNode = NULL;
}
}
/* update queue pointer if neccessary */
if ( pQueue->psNodeQHead == psNode )
{
pQueue->psNodeQHead = psNode->psNext;
}
}
/* return node to free node list */
psNode->psNext = pQueue->psFreeNodeList;
pQueue->psFreeNodeList = psNode;
/* update node counts */
pQueue->iFreeNodes++;
pQueue->iQueueNodes--;
ASSERT( (pQueue->iQueueNodes >= 0, "queue_RemoveNode: queue nodes < 0") );
return TRUE;
}
}
/***************************************************************************/
/*
* queue_RemoveElement
*
* Remove specific element from queue
*/
/***************************************************************************/
BOOL
queue_RemoveElement( QUEUE * pQueue, void * psElement )
{
QUEUE_NODE *psNode;
/* check input */
ASSERT( (PTRVALID(pQueue,sizeof(QUEUE)),
"queue_Dequeue: queue pointer invalid\n") );
ASSERT( (PTRVALID(psElement,pQueue->iElementSize),
"queue_RemoveElement: element pointer invalid\n") );
if ( (psNode = queue_FindElement( pQueue, psElement )) != NULL )
{
queue_RemoveNode( pQueue, psNode );
return TRUE;
}
else
{
return FALSE;
}
}
/***************************************************************************/

View File

@ -1,61 +0,0 @@
/***************************************************************************/
/*
* Priority queue code
*
*/
/***************************************************************************/
#ifndef _PQUEUE_H_
#define _PQUEUE_H_
/***************************************************************************/
typedef void (* QUEUE_CLEAR_FUNC) ( void *psElement );
typedef struct QUEUE_NODE
{
void * psElement;
int iPriority;
struct QUEUE_NODE * psPrev;
struct QUEUE_NODE * psNext;
}
QUEUE_NODE;
typedef struct QUEUE
{
QUEUE_NODE * psFreeNodeList;
QUEUE_NODE * psNodeQHead;
QUEUE_NODE * psCurNode;
int iElementSize;
int iMaxElements;
int iFreeNodes;
int iQueueNodes;
QUEUE_CLEAR_FUNC pfClearFunc;
}
QUEUE;
/***************************************************************************/
extern BOOL queue_Init( QUEUE ** ppQueue, int iMaxElements,
int iElementSize,
QUEUE_CLEAR_FUNC pfClearFunc );
extern void queue_Destroy( QUEUE * pQueue );
extern void queue_Clear( QUEUE * pQueue );
extern void queue_Enqueue( QUEUE * pQueue, void * psElement,
int iPriority );
extern void * queue_Dequeue( QUEUE * pQueue );
extern QUEUE_NODE * queue_FindElement( QUEUE * pQueue, void * psElement );
extern BOOL queue_RemoveElement( QUEUE * pQueue, void * psElement );
extern void * queue_GetHead( QUEUE * pQueue );
extern void * queue_GetNext( QUEUE * pQueue );
extern BOOL queue_RemoveCurrent( QUEUE * pQueue );
extern BOOL queue_RemoveNode( QUEUE * pQueue, QUEUE_NODE *psNode );
extern SDWORD queue_GetFreeElements( QUEUE * pQueue );
/***************************************************************************/
#endif // _PQUEUE_H_
/***************************************************************************/

View File

@ -1,17 +0,0 @@
/***************************************************************************/
#ifndef _PRIORITY_H_
#define _PRIORITY_H_
/***************************************************************************/
#define LOW_PRIORITY 0
#define MED_PRIORITY 1
#define HIGH_PRIORITY 2
#define HIGHEST_PRIORITY 10000
/***************************************************************************/
#endif // _PRIORITY_H_
/***************************************************************************/

View File

@ -1,380 +0,0 @@
/***************************************************************************/
#include <limits.h>
#include <memory.h>
#include "frame.h"
#include "ptrlist.h"
/***************************************************************************/
extern void *g_ElementToBeRemoved;
/***************************************************************************/
#ifdef WIN321 // ffs //Not really needed I guess? [Don't delete yet, possible future use?] -Qamly
static CRITICAL_SECTION critSecAudio;
#endif
/***************************************************************************/
static void ptrList_Init( PTRLIST *ptrList );
/***************************************************************************/
BOOL
ptrList_Create( PTRLIST **ppsList, UDWORD udwInitElements,
UDWORD udwExtElements, UDWORD udwElementSize )
{
/* create ptr list struct */
(*ppsList) = MALLOC( sizeof(PTRLIST) );
/* allocate heaps */
if ( !HEAP_CREATE( &(*ppsList)->psNodeHeap, sizeof(LISTNODE),
udwInitElements, udwExtElements) )
{
return FALSE;
}
if ( !HEAP_CREATE( &(*ppsList)->psElementHeap, udwElementSize,
udwInitElements, udwExtElements) )
{
return FALSE;
}
/* init members */
(*ppsList)->udwElements = udwInitElements;
(*ppsList)->udwExtElements = udwExtElements;
(*ppsList)->udwElementSize = udwElementSize;
ptrList_Init( *ppsList );
#ifdef WIN321 //ffs //Not really needed I guess? -Qamly
InitializeCriticalSection( &critSecAudio );
#endif
return TRUE;
}
/***************************************************************************/
void
ptrList_Destroy( PTRLIST *ptrList )
{
ASSERT( (PTRVALID(ptrList, sizeof(PTRLIST)),
"ptrList_Destroy: list pointer invalid\n") );
ptrList_Clear( ptrList );
/* destroy heaps */
HEAP_DESTROY( ptrList->psNodeHeap );
HEAP_DESTROY( ptrList->psElementHeap );
/* free struct */
FREE( ptrList );
#ifdef WIN321 // Not really needed I guess? -Qamly
DeleteCriticalSection( &critSecAudio );
#endif
}
/***************************************************************************/
static void
ptrList_Init( PTRLIST *ptrList )
{
ptrList->sdwCurIndex = 0;
ptrList->psCurNode = NULL;
ptrList->psNode = NULL;
ptrList->bDontGetNext = FALSE;
}
/***************************************************************************/
/*
* ptrList_Clear
*
* Returns all nodes from hash table to free node list
*/
/***************************************************************************/
void
ptrList_Clear( PTRLIST *ptrList )
{
LISTNODE *psNode, *psNodeTmp;
ASSERT( (PTRVALID(ptrList, sizeof(PTRLIST)),
"ptrList_Destroy: table pointer invalid\n") );
/* free nodes */
psNode = ptrList->psNode;
while ( psNode != NULL )
{
/* return node element to heap */
ASSERT( (PTRVALID(psNode->psElement, ptrList->udwElementSize),
"ptrList_Destroy: element pointer invalid\n") );
HEAP_FREE( ptrList->psElementHeap, psNode->psElement );
/* return node to heap */
ASSERT( (PTRVALID(psNode, sizeof(LISTNODE)),
"ptrList_Destroy: node pointer invalid\n") );
psNodeTmp = psNode->psNext;
HEAP_FREE( ptrList->psNodeHeap, psNode );
psNode = psNodeTmp;
}
ptrList_Init( ptrList );
}
/***************************************************************************/
/*
* ptrList_GetElement
*
* Gets free node from heap and returns element pointer
*/
/***************************************************************************/
void *
ptrList_GetElement( PTRLIST *ptrList )
{
void *psElement;
ASSERT( (PTRVALID(ptrList, sizeof(PTRLIST)),
"ptrList_GetElement: table pointer invalid\n") );
HEAP_ALLOC( ptrList->psElementHeap, &psElement );
return psElement;
}
/***************************************************************************/
/*
* ptrList_FreeElement
*
* Free element that was allocated using ptrList_GetElement without
* inserting in list: will fail if element not allocated from ptrList
*/
/***************************************************************************/
void
ptrList_FreeElement( PTRLIST *ptrList, void *psElement )
{
ASSERT( (PTRVALID(ptrList, sizeof(PTRLIST)),
"ptrList_FreeElement: table pointer invalid\n") );
if ( HEAP_FREE( ptrList->psElementHeap, psElement ) == FALSE )
{
DBPRINTF( ("ptrList_FreeElement: couldn't free element\n") );
}
}
/***************************************************************************/
void
ptrList_InsertElement( PTRLIST *ptrList, void *psElement, SDWORD sdwKey )
{
LISTNODE *psNode, *psCurNode, *psPrevNode;
ASSERT( (PTRVALID(ptrList, sizeof(PTRLIST)),
"ptrList_InsertElement: table pointer invalid\n") );
ASSERT( (PTRVALID(psElement, ptrList->udwElementSize),
"ptrList_InsertElement: element pointer invalid\n") );
/* get node from heap */
HEAP_ALLOC( ptrList->psNodeHeap, (void*) &psNode );
/* set node elements */
psNode->sdwKey = sdwKey;
psNode->psElement = psElement;
psNode->psNext = NULL;
psPrevNode = NULL;
psCurNode = ptrList->psNode;
#ifdef WIN321 //ffs //Not really needed I guess? -Qamly
EnterCriticalSection( &critSecAudio );
#endif
/* find correct position to insert node */
while ( psCurNode != NULL )
{
if ( psCurNode->sdwKey < sdwKey )
{
break;
}
psPrevNode = psCurNode;
psCurNode = psCurNode->psNext;
}
/* insert node */
if ( psPrevNode == NULL )
{
ptrList->psNode = psNode;
if ( psCurNode != NULL )
{
psNode->psNext = psCurNode;
}
}
else
{
psPrevNode->psNext = psNode;
psNode->psNext = psCurNode;
}
#ifdef WIN321 // ffs //Not really needed I guess? -Qamly
LeaveCriticalSection( &critSecAudio );
#endif
}
/***************************************************************************/
BOOL
ptrList_RemoveElement( PTRLIST *ptrList, void *psElement, SDWORD sdwKey )
{
LISTNODE *psCurNode, *psPrevNode;
BOOL bOK;
ASSERT( (PTRVALID(ptrList, sizeof(PTRLIST)),
"ptrList_RemoveElement: table pointer invalid\n") );
psPrevNode = NULL;
psCurNode = ptrList->psNode;
#ifdef WIN321 // ffs //Not really needed I guess? -Qamly
EnterCriticalSection( &critSecAudio );
#endif
/* find correct position to insert node */
while ( psCurNode != NULL &&
!(psCurNode->sdwKey == sdwKey &&
psCurNode->psElement == psElement) )
{
psPrevNode = psCurNode;
psCurNode = psCurNode->psNext;
}
/* remove node from hash table and return to heap */
if ( psCurNode == NULL )
{
bOK = FALSE;
}
else
{
ASSERT( (psCurNode->psElement == psElement,
"ptrList_RemoveElement: removing wrong element!\n") );
/* remove from list */
if ( psPrevNode == NULL )
{
ptrList->psNode = psCurNode->psNext;
}
else
{
psPrevNode->psNext = psCurNode->psNext;
}
/* check whether table current node pointer is this node */
if ( ptrList->psCurNode == psCurNode )
{
/* point it to the previous node if valid */
if ( psPrevNode == NULL )
{
/* set next node and set flag */
ptrList->psCurNode = psCurNode->psNext;
ptrList->bDontGetNext = TRUE;
}
else
{
ptrList->psCurNode = psPrevNode;
}
}
/* return element to heap */
ASSERT( (PTRVALID(psCurNode->psElement, ptrList->udwElementSize),
"ptrList_RemoveElement: element pointer invalid\n") );
ASSERT( (psCurNode->psElement == psElement,
"ptrList_RemoveElement: removing wrong element!\n") );
HEAP_FREE( ptrList->psElementHeap, psCurNode->psElement );
/* return node to heap */
ASSERT( (PTRVALID(psCurNode, sizeof(LISTNODE)),
"ptrList_RemoveElement: node pointer invalid\n") );
HEAP_FREE( ptrList->psNodeHeap, psCurNode );
bOK = TRUE;
}
#ifdef WIN321 // ffs //Not really needed I guess? -Qamly
LeaveCriticalSection( &critSecAudio );
#endif
return bOK;
}
/***************************************************************************/
void *
ptrList_GetNext( PTRLIST *ptrList )
{
void *pElement = NULL;
#ifdef WIN321 // ffs //Not really needed I guess? -Qamly
EnterCriticalSection( &critSecAudio );
#endif
if ( ptrList == NULL )
{
pElement = NULL;
}
if ( ptrList->psCurNode == NULL )
{
pElement = NULL;
}
else
{
if ( ptrList->bDontGetNext == TRUE )
{
ptrList->bDontGetNext = FALSE;
}
else
{
ptrList->psCurNode = ptrList->psCurNode->psNext;
}
if ( ptrList->psCurNode == NULL )
{
pElement = NULL;
}
else
{
pElement = ptrList->psCurNode->psElement;
}
}
#ifdef WIN321 // ffs //Not really needed I guess? -Qamly
LeaveCriticalSection( &critSecAudio );
#endif
return pElement;
}
/***************************************************************************/
void *
ptrList_GetFirst( PTRLIST *ptrList )
{
void *pElement = NULL;
#ifdef WIN321 // ffs //Not really needed I guess? -Qamly
EnterCriticalSection( &critSecAudio );
#endif
ptrList->bDontGetNext = FALSE;
ptrList->psCurNode = ptrList->psNode;
if ( ptrList->psCurNode == NULL )
{
pElement = NULL;
}
else
{
pElement = ptrList->psCurNode->psElement;
}
#ifdef WIN321 // ffs //Not really needed I guess? -Qamly
LeaveCriticalSection( &critSecAudio );
#endif
return pElement;
}
/***************************************************************************/

View File

@ -1,68 +0,0 @@
/***************************************************************************/
#ifndef _PTRLIST_H_
#define _PTRLIST_H_
/***************************************************************************/
#include "frame.h"
/***************************************************************************/
/* defines
*/
/***************************************************************************/
/* macros
*/
/***************************************************************************/
/* structs
*/
typedef struct LISTNODE
{
void *psElement;
SDWORD sdwKey;
struct LISTNODE *psNext;
}
LISTNODE;
typedef struct sPTRLIST
{
OBJ_HEAP *psNodeHeap;
OBJ_HEAP *psElementHeap;
LISTNODE *psNode;
LISTNODE *psCurNode;
UDWORD udwTableSize;
UDWORD udwElements;
UDWORD udwExtElements;
UDWORD udwElementSize;
UDWORD sdwCurIndex;
BOOL bDontGetNext;
}
PTRLIST;
/***************************************************************************/
/* functions
*/
BOOL ptrList_Create( PTRLIST **pptrList, UDWORD udwInitElements,
UDWORD udwExtElements, UDWORD udwElementSize );
void ptrList_Destroy( PTRLIST *ptrList );
void ptrList_Clear( PTRLIST *ptrList );
void * ptrList_GetElement( PTRLIST *ptrList );
void ptrList_FreeElement( PTRLIST *ptrList, void *psElement );
void ptrList_InsertElement( PTRLIST *ptrList, void *psElement,
SDWORD sdwKey );
BOOL ptrList_RemoveElement( PTRLIST *ptrList, void *psElement,
SDWORD sdwKey );
void * ptrList_GetFirst( PTRLIST *ptrList );
void * ptrList_GetNext( PTRLIST *ptrList );
/***************************************************************************/
#endif // _PTRLIST_H_
/***************************************************************************/

View File

@ -1,368 +0,0 @@
# Microsoft Developer Studio Project File - Name="Ivis02" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Static Library" 0x0104
CFG=Ivis02 - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "Ivis02.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "Ivis02.mak" CFG="Ivis02 - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "Ivis02 - Win32 Release" (based on "Win32 (x86) Static Library")
!MESSAGE "Ivis02 - Win32 Debug" (based on "Win32 (x86) Static Library")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "Ivis02 - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
# ADD BASE RSC /l 0x809 /d "NDEBUG"
# ADD RSC /l 0x809 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
!ELSEIF "$(CFG)" == "Ivis02 - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "..\Framework" /I "c:\glide\include" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /D "INC_GLIDE" /D "__MSC__" /FR /YX /FD /GZ /c
# ADD BASE RSC /l 0x809 /d "_DEBUG"
# ADD RSC /l 0x809 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
!ENDIF
# Begin Target
# Name "Ivis02 - Win32 Release"
# Name "Ivis02 - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\3dfxdyn.c
# End Source File
# Begin Source File
SOURCE=.\3dfxFunc.c
# End Source File
# Begin Source File
SOURCE=.\3dfxmode.c
# End Source File
# Begin Source File
SOURCE=.\3dfxtext.c
# End Source File
# Begin Source File
SOURCE=.\BitImage.c
# End Source File
# Begin Source File
SOURCE=.\Bspimd.c
# End Source File
# Begin Source File
SOURCE=.\Bug.c
# End Source File
# Begin Source File
SOURCE=.\D3dmode.c
# End Source File
# Begin Source File
SOURCE=.\d3drender.c
# End Source File
# Begin Source File
SOURCE=.\dx6TexMan.c
# End Source File
# Begin Source File
SOURCE=.\Fbf.c
# End Source File
# Begin Source File
SOURCE=.\Getdxver.cpp
# End Source File
# Begin Source File
SOURCE=.\Imd.c
# End Source File
# Begin Source File
SOURCE=.\Imdload.c
# End Source File
# Begin Source File
SOURCE=.\Ivi.c
# End Source File
# Begin Source File
SOURCE=.\Pcx.c
# End Source File
# Begin Source File
SOURCE=.\pieBlitFunc.c
# End Source File
# Begin Source File
SOURCE=.\pieClip.c
# End Source File
# Begin Source File
SOURCE=.\Piedraw.c
# End Source File
# Begin Source File
SOURCE=.\Piefunc.c
# End Source File
# Begin Source File
SOURCE=.\pieMatrix.c
# End Source File
# Begin Source File
SOURCE=.\pieMode.c
# End Source File
# Begin Source File
SOURCE=.\piePalette.c
# End Source File
# Begin Source File
SOURCE=.\pieState.c
# End Source File
# Begin Source File
SOURCE=.\pieTexture.c
# End Source File
# Begin Source File
SOURCE=.\Rendfunc.c
# End Source File
# Begin Source File
SOURCE=.\Rendmode.c
# End Source File
# Begin Source File
SOURCE=.\Tex.c
# End Source File
# Begin Source File
SOURCE=.\Texd3d.c
# End Source File
# Begin Source File
SOURCE=.\TextDraw.c
# End Source File
# Begin Source File
SOURCE=.\V4101.c
# End Source File
# Begin Source File
SOURCE=.\Vsr.c
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\3dfxFunc.h
# End Source File
# Begin Source File
SOURCE=.\3dfxmode.h
# End Source File
# Begin Source File
SOURCE=.\3dfxText.h
# End Source File
# Begin Source File
SOURCE=.\Amd3d.h
# End Source File
# Begin Source File
SOURCE=.\BitImage.h
# End Source File
# Begin Source File
SOURCE=.\Bspfunc.h
# End Source File
# Begin Source File
SOURCE=.\Bspimd.h
# End Source File
# Begin Source File
SOURCE=.\Bug.h
# End Source File
# Begin Source File
SOURCE=.\D3dmode.h
# End Source File
# Begin Source File
SOURCE=.\d3drender.h
# End Source File
# Begin Source File
SOURCE=.\Dglide.h
# End Source File
# Begin Source File
SOURCE=.\dx6TexMan.h
# End Source File
# Begin Source File
SOURCE=.\Fbf.h
# End Source File
# Begin Source File
SOURCE=.\Geo.h
# End Source File
# Begin Source File
SOURCE=.\Imd.h
# End Source File
# Begin Source File
SOURCE=.\Ivi.h
# End Source File
# Begin Source File
SOURCE=.\Ivisdef.h
# End Source File
# Begin Source File
SOURCE=.\ivispatch.h
# End Source File
# Begin Source File
SOURCE=.\Pcx.h
# End Source File
# Begin Source File
SOURCE=.\pieBlitFunc.h
# End Source File
# Begin Source File
SOURCE=.\Pieclip.h
# End Source File
# Begin Source File
SOURCE=.\Piedef.h
# End Source File
# Begin Source File
SOURCE=.\Piefunc.h
# End Source File
# Begin Source File
SOURCE=.\pieMatrix.h
# End Source File
# Begin Source File
SOURCE=.\pieMode.h
# End Source File
# Begin Source File
SOURCE=.\piePalette.h
# End Source File
# Begin Source File
SOURCE=.\pieState.h
# End Source File
# Begin Source File
SOURCE=.\pieTexture.h
# End Source File
# Begin Source File
SOURCE=.\pieTypes.h
# End Source File
# Begin Source File
SOURCE=.\Rendfunc.h
# End Source File
# Begin Source File
SOURCE=.\Rendmode.h
# End Source File
# Begin Source File
SOURCE=.\Tex.h
# End Source File
# Begin Source File
SOURCE=.\Texd3d.h
# End Source File
# Begin Source File
SOURCE=.\TextDraw.h
# End Source File
# Begin Source File
SOURCE=.\V4101.h
# End Source File
# Begin Source File
SOURCE=.\Vid.h
# End Source File
# Begin Source File
SOURCE=.\Vsr.h
# End Source File
# End Group
# End Target
# End Project

View File

@ -1,883 +0,0 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="Ivis02"
SccProjectName=""
SccLocalPath="">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory=".\Debug"
IntermediateDirectory=".\Debug"
ConfigurationType="4"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="FALSE"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\Framework,..\glide\src\include"
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;INC_GLIDE;__MSC__"
BasicRuntimeChecks="3"
RuntimeLibrary="5"
UsePrecompiledHeader="2"
PrecompiledHeaderFile=".\Debug/Ivis02.pch"
AssemblerListingLocation=".\Debug/"
ObjectFile=".\Debug/"
ProgramDataBaseFileName=".\Debug/"
BrowseInformation="1"
WarningLevel="3"
SuppressStartupBanner="TRUE"
DebugInformationFormat="4"
CompileAs="0"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLibrarianTool"
OutputFile=".\Debug\Ivis02.lib"
SuppressStartupBanner="TRUE"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="2057"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory=".\Release"
IntermediateDirectory=".\Release"
ConfigurationType="4"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="FALSE"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="/D &quot;INC_GLIDE&quot;"
Optimization="2"
InlineFunctionExpansion="1"
AdditionalIncludeDirectories="..\Framework;..\glide\Src\Include"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;YY_STATIC"
StringPooling="TRUE"
RuntimeLibrary="4"
EnableFunctionLevelLinking="TRUE"
UsePrecompiledHeader="2"
PrecompiledHeaderFile=".\Release/Ivis02.pch"
AssemblerListingLocation=".\Release/"
ObjectFile=".\Release/"
ProgramDataBaseFileName=".\Release/"
WarningLevel="3"
SuppressStartupBanner="TRUE"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLibrarianTool"
OutputFile=".\Release\Ivis02.lib"
SuppressStartupBanner="TRUE"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="2057"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
<File
RelativePath="3dfxdyn.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="3dfxFunc.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="3dfxmode.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="3dfxtext.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="BitImage.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="Bspimd.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="Bug.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="D3dmode.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="d3drender.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="dx6TexMan.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="Fbf.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="Getdxver.cpp">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="Imd.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="Imdload.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="Ivi.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="Pcx.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="pieBlitFunc.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="pieClip.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="Piedraw.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="Piefunc.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="pieMatrix.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="pieMode.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="piePalette.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="pieState.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="pieTexture.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="Rendfunc.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="Rendmode.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="Tex.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="Texd3d.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="TextDraw.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="V4101.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="Vsr.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl">
<File
RelativePath="3dfxFunc.h">
</File>
<File
RelativePath="3dfxmode.h">
</File>
<File
RelativePath="3dfxText.h">
</File>
<File
RelativePath="Amd3d.h">
</File>
<File
RelativePath="BitImage.h">
</File>
<File
RelativePath="Bspfunc.h">
</File>
<File
RelativePath="Bspimd.h">
</File>
<File
RelativePath="Bug.h">
</File>
<File
RelativePath="D3dmode.h">
</File>
<File
RelativePath="d3drender.h">
</File>
<File
RelativePath="Dglide.h">
</File>
<File
RelativePath="dx6TexMan.h">
</File>
<File
RelativePath="Fbf.h">
</File>
<File
RelativePath="Geo.h">
</File>
<File
RelativePath="Imd.h">
</File>
<File
RelativePath="Ivi.h">
</File>
<File
RelativePath="Ivisdef.h">
</File>
<File
RelativePath="ivispatch.h">
</File>
<File
RelativePath="Pcx.h">
</File>
<File
RelativePath="pieBlitFunc.h">
</File>
<File
RelativePath="Pieclip.h">
</File>
<File
RelativePath="Piedef.h">
</File>
<File
RelativePath="Piefunc.h">
</File>
<File
RelativePath="pieMatrix.h">
</File>
<File
RelativePath="pieMode.h">
</File>
<File
RelativePath="piePalette.h">
</File>
<File
RelativePath="pieState.h">
</File>
<File
RelativePath="pieTexture.h">
</File>
<File
RelativePath="pieTypes.h">
</File>
<File
RelativePath="Rendfunc.h">
</File>
<File
RelativePath="Rendmode.h">
</File>
<File
RelativePath="Tex.h">
</File>
<File
RelativePath="Texd3d.h">
</File>
<File
RelativePath="TextDraw.h">
</File>
<File
RelativePath="V4101.h">
</File>
<File
RelativePath="Vid.h">
</File>
<File
RelativePath="Vsr.h">
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -1,33 +0,0 @@
noinst_LIBRARIES = libivis02.a
AM_CPPFLAGS = -I../framework -I../gamelib -I../.. -I../ivis_common
libivis02_a_SOURCES = \
bspimd.c \
ivi.c \
pcx.c \
pieblitfunc.c \
pieclip.c \
piedraw.c \
piefunc.c \
piematrix.c \
piemode.c \
piepalette.c \
piestate.c \
pietexture.c \
rendfunc.c \
rendmode.c \
screen.c \
tex.c \
textdraw.c \
v4101_stub.c \
vsr.c \
vid.h \
screen.h \
vsr.h \
pietexture.h \
dglide.h \
piematrix.h \
v4101.h
libivis02_a_libs = ../framework/libframework.a ../ivis_common/libivis_common.a
libivis02_a_DEPENDENCIES = $(libivis02_a_libs)
libivis02_a_LIBADD = $(libivis02_a_libs)

View File

@ -1,28 +0,0 @@
SRC_FILES= \
bspimd.c \
ivi.c \
pcx.c \
pieblitfunc.c \
pieclip.c \
piedraw.c \
piefunc.c \
piematrix.c \
piemode.c \
piepalette.c \
piestate.c \
pietexture.c \
rendfunc.c \
rendmode.c \
screen.c \
tex.c \
textdraw.c \
v4101_stub.c \
vsr.c
LIBS=framework gamelib ivis_common
LIB=ivis02
MAKERULES=../../makerules
include $(MAKERULES)/lib.mk

View File

@ -1,398 +0,0 @@
/*
BSP Draw routines for iVis02
- 5 Sept 1997 - Tim Cannell - Pumpkin Studios - Eidos
- Main routines were written by Gareth Jones .... so if you find any bugs I think you better speak to him ...
*/
#include "frame.h" // just for the typedef's
#include "pietypes.h"
#include "piematrix.h"
#include "ivisdef.h"// this can have the #define for BSPIMD in it
#include "imd.h"// this has the #define for BSPPOLYID_TERMINATE
#include "ivi.h"
#ifdef BSPIMD // covers the whole file
#define BSP_BACKFACECULL // if defined we perform the backface cull in the BSP (we get this for free (!))
//#define BSP_MAXDEBUG // define this if you want max debug options (runs very slow)
#include "bspimd.h"
#include "bspfunc.h"
#include <stdio.h>
#include <assert.h>
// from imddraw.c
void DrawTriangleList(BSPPOLYID PolygonNumber);
// Local prototypes
_inline int IsPointOnPlane( PSPLANE psPlane, iVector * vP );
static iVector *IMDvec(int Vertex);
static void TraverseTreeAndRender( PSBSPTREENODE psNode);
iIMDShape *BSPimd=NULL; // This is a global ... it is used in imddraw.c (for speed)
// Local static variables
static iVector *BSPScrPos=NULL;
static iVector *CurrentVertexList=NULL;
#ifdef BSP_MAXDEBUG
static int CurrentVertexListCount=0;
#endif
extern BOOL NoCullBSP; // Oh yes... a global externaly referenced variable....
// General routines that work on both PC & PSX
/***************************************************************************/
/*
* Calculates whether point is on same side, opposite side or in plane;
*
* returns OPPOSITE_SIDE if opposite,
* IN_PLANE if contained in plane,
* SAME_SIDE if same side
* Also returns pvDot - the dot product
* - inputs vP vector to the point
* - psPlane structure containing the plane equation
*/
/***************************************************************************/
_inline int IsPointOnPlane( PSPLANE psPlane, iVector * vP )
{
iVectorf vecP;
FRACT Dot;
/* validate input */
#ifdef BSP_MAXDEBUG
ASSERT( (PTRVALID(psPlane,sizeof(PLANE)),
"IsPointOnPlane: invalid plane\n") );
#endif
/* subtract point on plane from input point to get position vector */
vecP.x = MAKEFRACT(vP->x - psPlane->vP.x);
vecP.y = MAKEFRACT(vP->y - psPlane->vP.y);
vecP.z = MAKEFRACT(vP->z - psPlane->vP.z);
/* get dot product of result with plane normal (a,b,c of plane) */
Dot = (FRACT)(FRACTmul(vecP.x,psPlane->a) + FRACTmul(vecP.y,psPlane->b) + FRACTmul(vecP.z,psPlane->c));
/* if result is -ve, return -1 */
if ( (abs((int)Dot)) < FRACTCONST(1,100) )
{
return IN_PLANE;
}
else if ( Dot < 0 )
{
return OPPOSITE_SIDE;
}
return SAME_SIDE;
}
/*
This is the main BSP Traversal routine. It Zaps through the tree (recursively) - and draws all the polygons
for the IMD in the correct order ... pretty clever eh ..
*/
static void TraverseTreeAndRender( PSBSPTREENODE psNode)
{
/* is viewer on same side? */
// On the playstation we need the list in reverse order (front most polygon first)
// so we just do the list the opposite way around - this affects the BACKFACE culling as well
if ( IsPointOnPlane( &psNode->Plane, BSPScrPos ) == SAME_SIDE )
{
/* recurse on opposite side, render this node on same side,
* recurse on same side.
*/
if (psNode->link[LEFT]!=NULL) TraverseTreeAndRender( psNode->link[LEFT]);
if (psNode->TriSameDir!=BSPPOLYID_TERMINATE) DrawTriangleList(psNode->TriSameDir);
#ifndef BSP_BACKFACECULL
if (psNode->TriOppoDir!=BSPPOLYID_TERMINATE) DrawTriangleList(psNode->TriOppoDir);
#warning LETS_FORCE_AN_ERROR_TO_MAKE_SURE_THAT_THIS_CODE_ISNT_COMPILED
#endif
if (psNode->link[RIGHT]!=NULL) TraverseTreeAndRender( psNode->link[RIGHT]);
}
else
/* viewer in plane or on opposite side */
{
/* recurse on same side, render this node on opposite side
* recurse on opposite side.
*/
if (psNode->link[RIGHT]!=NULL) TraverseTreeAndRender( psNode->link[RIGHT]);
if (psNode->TriOppoDir!=BSPPOLYID_TERMINATE) DrawTriangleList(psNode->TriOppoDir);
#ifndef BSP_BACKFACECULL
if (psNode->TriSameDir!=BSPPOLYID_TERMINATE) DrawTriangleList(psNode->TriSameDir);
#endif
if (psNode->link[LEFT]!=NULL) TraverseTreeAndRender( psNode->link[LEFT]);
}
}
/*
These routines are used by the IMD Load_BSP routine
*/
typedef iIMDPoly * PSTRIANGLE;
static iVectorf *iNormalise(iVectorf * v);
static iVectorf * iCrossProduct( iVectorf * psD, iVectorf * psA, iVectorf * psB );
static void GetTriangleNormal( PSTRIANGLE psTri, iVectorf * psN,int pA, int pB, int pC );
PSBSPTREENODE InitNode(PSBSPTREENODE psBSPNode);
static FRACT GetDist( PSTRIANGLE psTri, int pA, int pB );
// little routine for getting an imd vector structure in the IMD from the vertex ID
static _inline iVector *IMDvec(int Vertex)
{
#ifdef BSP_MAXDEBUG
assert((Vertex>=0)&&(Vertex<CurrentVertexListCount));
#endif
return (CurrentVertexList+Vertex);
}
/*
Its easy enough to calculate the plane equation if there is only 3 points
... but if there is four things get a little tricky ...
In theory you should be able the pick any 3 of the points to calculate the equation, however
in practise mathematically inacurraceys mean that you need the three points that are the furthest apart
*/
void GetPlane( iIMDShape *s, UDWORD PolygonID, PSPLANE psPlane )
{
iVectorf Result;
iIMDPoly *psTri;
/* validate input */
ASSERT( (PTRVALID(psPlane,sizeof(PLANE)),
"GetPlane: invalid plane\n") );
psTri=&(s->polys[PolygonID]);
CurrentVertexList=s->points;
#ifdef BSP_MAXDEBUG
CurrentVertexListCount=s->npoints; // for error detection
#endif
if (psTri->npnts==4)
{
int pA,pB,pC;
FRACT ShortDist,Dist;
ShortDist=MAKEFRACT(999);
pA=0;pB=1;pC=2;
Dist=GetDist(psTri,0,1); // Distance between two points in the quad
if (Dist < ShortDist) { ShortDist=Dist; pA=0;pB=2;pC=3; }
Dist=GetDist(psTri,0,2);
if (Dist < ShortDist) { ShortDist=Dist; pA=0;pB=1;pC=3; }
Dist=GetDist(psTri,0,3);
if (Dist < ShortDist) { ShortDist=Dist; pA=0;pB=1;pC=2; }
Dist=GetDist(psTri,1,2);
if (Dist < ShortDist) { ShortDist=Dist; pA=0;pB=1;pC=3; }
Dist=GetDist(psTri,1,3);
if (Dist < ShortDist) { ShortDist=Dist; pA=0;pB=1;pC=2; }
Dist=GetDist(psTri,2,3);
if (Dist < ShortDist) { ShortDist=Dist; pA=0;pB=1;pC=2; }
GetTriangleNormal(psTri,&Result,pA,pB,pC);
}
else
{
GetTriangleNormal(psTri,&Result,0,1,2); // for a triangle there is no choice ...
}
/* normalise normal */
iNormalise( &Result );
// This result MUST be cast to a fract and not called using MAKEFRACT
//
// This is because on a playstation we are casting from FRACT->FRACT (so no conversion is needed)
// ... and on a PC we are converting from DOUBLE->FLOAT (so a cast is needed)
psPlane->a = (FRACT)(Result.x);
psPlane->b = (FRACT)(Result.y);
psPlane->c = (FRACT)(Result.z);
/* since plane eqn is ax + by + cz + d = 0,
* d = -(ax + by + cz).
*/
// Because we are multiplying a FRACT by a const we can use normal '*'
psPlane->d = - ( ( psPlane->a* IMDvec(psTri->pindex[0])->x ) +
( psPlane->b* IMDvec(psTri->pindex[0])->y ) +
( psPlane->c* IMDvec(psTri->pindex[0])->z ) );
/* store first triangle vertex as point on plane for later point /
* plane classification in IsPointOnPlane
*/
memcpy( &psPlane->vP, IMDvec(psTri->pindex[0]), sizeof(iVector) );
}
/***************************************************************************/
/*
* iCrossProduct
*
* Calculates cross product of a and b.
*/
/***************************************************************************/
static iVectorf * iCrossProduct( iVectorf * psD, iVectorf * psA, iVectorf * psB )
{
psD->x = FRACTmul(psA->y , psB->z) - FRACTmul(psA->z ,psB->y);
psD->y = FRACTmul(psA->z , psB->x) - FRACTmul(psA->x ,psB->z);
psD->z = FRACTmul(psA->x , psB->y) - FRACTmul(psA->y ,psB->x);
return psD;
}
static FRACT GetDist( PSTRIANGLE psTri, int pA, int pB )
{
FRACT vx,vy,vz;
FRACT sum_square,dist;
vx = MAKEFRACT( IMDvec(psTri->pindex[pA])->x - IMDvec(psTri->pindex[pB])->x);
vy = MAKEFRACT( IMDvec(psTri->pindex[pA])->y - IMDvec(psTri->pindex[pB])->y);
vz = MAKEFRACT( IMDvec(psTri->pindex[pA])->z - IMDvec(psTri->pindex[pB])->z);
sum_square = (FRACTmul(vx,vx)+FRACTmul(vy,vy)+FRACTmul(vz,vz) );
dist = fSQRT(sum_square);
return dist;
}
static void GetTriangleNormal( PSTRIANGLE psTri, iVectorf * psN,int pA, int pB, int pC )
{
iVectorf vecA, vecB;
/* validate input */
ASSERT( (PTRVALID(psTri,sizeof(iIMDPoly)),
"GetTriangleNormal: invalid triangle\n") );
/* get triangle edge vectors */
vecA.x = MAKEFRACT( IMDvec(psTri->pindex[pA])->x - IMDvec(psTri->pindex[pB])->x);
vecA.y = MAKEFRACT( IMDvec(psTri->pindex[pA])->y - IMDvec(psTri->pindex[pB])->y);
vecA.z = MAKEFRACT( IMDvec(psTri->pindex[pA])->z - IMDvec(psTri->pindex[pB])->z);
vecB.x = MAKEFRACT( IMDvec(psTri->pindex[pA])->x - IMDvec(psTri->pindex[pC])->x);
vecB.y = MAKEFRACT( IMDvec(psTri->pindex[pA])->y - IMDvec(psTri->pindex[pC])->y);
vecB.z = MAKEFRACT( IMDvec(psTri->pindex[pA])->z - IMDvec(psTri->pindex[pC])->z);
/* normal is cross product */
iCrossProduct( psN, &vecA, &vecB );
}
/***************************************************************************/
/*
* Normalises the vector v
*/
/***************************************************************************/
static iVectorf *iNormalise(iVectorf * v)
{
FRACT vx, vy, vz, mod, sum_square;
vx = (FRACT)v->x;
vy = (FRACT)v->y;
vz = (FRACT)v->z;
if ((vx == 0) && (vy == 0) && (vz == 0))
{
return v;
}
sum_square = (FRACTmul(vx,vx)+FRACTmul(vy,vy)+FRACTmul(vz,vz) );
mod = fSQRT(sum_square);
v->x = FRACTdiv( vx , mod);
v->y = FRACTdiv( vy , mod);
v->z = FRACTdiv( vz , mod);
return v;
}
PSBSPTREENODE InitNode(PSBSPTREENODE psBSPNode)
{
PSBNODE psBNode;
/* create node triangle lists */
psBSPNode->TriSameDir=BSPPOLYID_TERMINATE;
psBSPNode->TriOppoDir=BSPPOLYID_TERMINATE;
psBNode = (PSBNODE) psBSPNode;
psBNode->link[LEFT] = NULL;
psBNode->link[RIGHT] = NULL;
return psBSPNode;
}
// PC Specific drawing routines
// Calculate the real camera position based on the coordinates of the camera and the camera
// distance - the result is stores in CameraLoc ,, up is +ve Y
void GetRealCameraPos(OBJPOS *Camera,SDWORD Distance, iVector *CameraLoc)
{
int Yinc;
// as pitch is negative ... we need to subtract the value from y to go up the axis
CameraLoc->y = Camera->y - ((SIN(Camera->pitch) * Distance)>>FP12_SHIFT);
// CameraLoc->y = Camera->y + ((iV_SIN(Camera->pitch) * Distance)>>FP12_SHIFT);
Yinc = ((COS(Camera->pitch) * Distance)>>FP12_SHIFT);
// DBPRINTF(("camera x=%d y=%d z=%d\n",Camera->x,Camera->y,Camera->z));
// DBPRINTF(("pitch=%ld yaw=%ld Yinc=%ld Dist=%ld\n",Camera->pitch,Camera->yaw,Yinc,Distance));
CameraLoc->x = Camera->x + ((SIN(-Camera->yaw) * (-Yinc))>>FP12_SHIFT);
CameraLoc->z = Camera->z + ((COS(-Camera->yaw) * (Yinc))>>FP12_SHIFT);
// DBPRINTF(("out) camera x=%d y=%d z=%d\n",CameraLoc->x,CameraLoc->y,CameraLoc->z));
// DBPRINTF(("t=%d t1=%d t2=%d t3=%d z=%d\n",t,t1,t2,t3,CameraLoc->z));
}
//iIMDPoly *BSPScrVertices=NULL;
void DrawBSPIMD(iIMDShape *IMDdef,iVector * pPos) //, iIMDPoly *ScrVertices)
{
// BSPScrVertices=ScrVertices; // this is wrong ... use vrt entry in IMDdef
BSPScrPos=pPos;
BSPimd=IMDdef;
TraverseTreeAndRender(IMDdef->BSPNode);
}
#endif // #ifdef BSPIMD

File diff suppressed because it is too large Load Diff

View File

@ -1,122 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <time.h>
#include "ivisdef.h"
#include "piestate.h"
//#include "ivi.h"
//#include "v3d.h"
#include "rendmode.h"
#include "piemode.h"
//#include "geo.h"
#include "bug.h"
//#include "pio.h"
#include "piepalette.h"
#include "piematrix.h"
//#include "kyb.h"
#include "tex.h"
//#include "pdv.h"
#include "ivispatch.h"
//*************************************************************************
//*************************************************************************
iError _iVERROR;
//*************************************************************************
//*************************************************************************
// pass in true to reset the palette too.
void iV_Reset(int bPalReset)
{
_TEX_INDEX = 0;
iV_ClearFonts(); // Initialise the IVIS font module.
}
void iV_ShutDown(void)
{
iV_DEBUG0("1\n");
#ifdef iV_DEBUG
iV_HeapLog();
#endif
iV_DEBUG0("4\n");
pie_ShutDown();
iV_DEBUG0("5\n");
iV_VideoMemoryUnlock();
iV_DEBUG0("6\n");
pie_TexShutDown();
iV_DEBUG0("7\n");
// _iv_heap_tidy();
iV_DEBUG0("8\n");
iV_DEBUG0("9\n");
iV_DEBUG0("iVi[ShutDown] = successful\n");
}
//*************************************************************************
void iV_Stop(char *string, ...)
{
va_list argptr;
iV_ShutDown();
va_start(argptr,string);
vprintf(string,argptr);
va_end(argptr);
exit(0);
}
//*************************************************************************
void iV_Abort(char *string, ...)
{
va_list argptr;
va_start(argptr,string);
vprintf(string,argptr);
va_end(argptr);
}
//*************************************************************************
#ifndef FINALBUILD
void iV_Error(long errorn, char *msge, ...)
{
va_list argptr;
va_start(argptr,msge);
vsprintf(&_iVERROR.msge[0],msge,argptr);
va_end(argptr);
_iVERROR.n = errorn;
}
#endif

View File

@ -1,389 +0,0 @@
#include "frame.h"
#include "ivisdef.h"
#include "fbf.h"
#include "bug.h"
#include "ivispatch.h"
//#include <stdio.h>
//#include <stdlib.h>
//#include <io.h>
//#include "pcx.h"
//#include "pal.h"
//#include "bug.h"
//#include "ivisheap.h"
//*************************************************************************
#define PCX_BUFFER_SIZE 65536
//#define PCX_PIXEL(s,x,y) (* ((uint8 *) ((s)->bmp + (x) + ((y) * (s)->width))))
//*************************************************************************
typedef struct {
uint8 manufacturer;
uint8 version;
uint8 encoding;
uint8 bits_per_pixel;
int16 xmin,ymin;
int16 xmax,ymax;
int16 hres, vres;
uint8 palette16[48];
uint8 reserved;
uint8 colour_planes;
int16 bytes_per_line;
int16 palette_type;
uint8 filler[58];
} iPCX_header;
//*************************************************************************
static int _PCX_FI;
static int8 *_PCX_MI;
static iBool _PCX_MEM;
//*************************************************************************
static int _pcx_read_int8(void)
{
if (_PCX_MEM)
return *_PCX_MI++;
else
return (iV_FileGet(_PCX_FI));
}
//*************************************************************************
static void _pcx_info(char *filename, iPCX_header *h)
{
iV_DEBUG1("pcx[pcx_info] = '%s' - PCX file header:\n",filename);
iV_DEBUG1( " Manufacturer %4d\n",h->manufacturer);
iV_DEBUG12( " Version %4d\n"
" Encoding %4d\n"
" Bits/pixel %4d\n"
" Xmin, Ymin %4d,%4d\n"
" Xmax, Ymax %4d,%4d\n"
" H, V resolution %4d,%4d\n"
" Colour plane %4d\n"
" Bytes/line %4d\n"
" Palette type %4d\n",
h->version,
h->encoding,
h->bits_per_pixel,
h->xmin,h->ymin,
h->xmax,h->ymax,
h->hres, h->vres,
h->colour_planes,
h->bytes_per_line,
h->palette_type);
}
//*************************************************************************
static void _load_image(iBitmap *bmp, long size)
{
int data, num_bytes;
long count;
count = 0;
while (count < size) {
data = _pcx_read_int8();
if ((data & 0xc0) == 0xc0) {
num_bytes = data & 0x3f;
data = _pcx_read_int8();
} else
num_bytes = 1;
while ((num_bytes-- > 0) && (count++ < size))
*bmp++ = data;
}
}
//*************************************************************************
static void _load_palette(iColour *pal)
{
int i;
iV_FileSeek(_PCX_FI,-769,iV_FBF_SEEK_END);
if (_pcx_read_int8() == 0x0C) {
for (i=0; i<256; i++) {
pal[i].r = _pcx_read_int8();
pal[i].g = _pcx_read_int8();
pal[i].b = _pcx_read_int8();
}
}
}
//*************************************************************************
static void _load_palette_mem(iColour *pal)
{
int i;
if (_pcx_read_int8() == 0x0C) {
iV_DEBUG0("YES YES YES\n");
for (i=0; i<256; i++) {
pal[i].r = _pcx_read_int8();
pal[i].g = _pcx_read_int8();
pal[i].b = _pcx_read_int8();
}
}
}
//*************************************************************************
BOOL pie_PCXLoadToBuffer(char *file, iSprite *s, iColour* pal)
{
iPCX_header header;
int i;
long bsize;
uint8 *hp;
_PCX_MEM = FALSE;
iV_DEBUG1("pcx[PCXLoad] = loading pcx file '%s':\n",file);
if ((_PCX_FI = iV_FileOpen(file,iV_FBF_MODE_R,51200)) <0) {
iV_DEBUG1("pcx[PCXLoad] = could not open pcx file %d\n",_PCX_FI);
return FALSE;
}
hp = (uint8 *) &header;
for (i=0; i<128; i++)
*hp++ = _pcx_read_int8();
_pcx_info(file,&header);
if ((header.manufacturer != 10) && (header.version != 5)) {
iV_FileClose(_PCX_FI);
return FALSE;
}
if (header.bits_per_pixel != 8) {
iV_FileClose(_PCX_FI);
return FALSE;
}
if (s->width != (header.xmax - header.xmin)+1)
{
iV_FileClose(_PCX_FI);
return FALSE;
}
if (s->height != (header.ymax - header.ymin)+1)
{
iV_FileClose(_PCX_FI);
return FALSE;
}
bsize = s->height * s->width;
_load_image(s->bmp,bsize);
if (pal)
{
// ASSERT((FALSE,"warning palette is being loaded for %s",file));
_load_palette(pal);
}
iV_FileClose(_PCX_FI);
iV_DEBUG3("pcx[iV_PCXLoad] = file '%s' %dx%d load successful\n",file,
s->width,s->height);
return TRUE;
}
iBool iV_PCXLoad(char *file, iSprite *s, iColour *pal)
{
iPCX_header header;
int i;
long bsize;
uint8 *hp;
_PCX_MEM = FALSE;
iV_DEBUG1("pcx[PCXLoad] = loading pcx file '%s':\n",file);
if ((_PCX_FI = iV_FileOpen(file,iV_FBF_MODE_R,51200)) <0) {
iV_DEBUG1("pcx[PCXLoad] = could not open pcx file %d\n",_PCX_FI);
return FALSE;
}
hp = (uint8 *) &header;
for (i=0; i<128; i++)
*hp++ = _pcx_read_int8();
_pcx_info(file,&header);
if ((header.manufacturer != 10) && (header.version != 5)) {
iV_FileClose(_PCX_FI);
return FALSE;
}
if (header.bits_per_pixel != 8) {
iV_FileClose(_PCX_FI);
return FALSE;
}
s->width = (header.xmax - header.xmin)+1;
s->height = (header.ymax - header.ymin)+1;
bsize = s->height * s->width;
if ((s->bmp = (uint8 *) iV_HeapAlloc(bsize)) == NULL) {
iV_FileClose(_PCX_FI);
return FALSE;
}
// DBPRINTF(("PCX LOAD [%s] size=%d ptr=%p\n",file,bsize,s->bmp));
_load_image(s->bmp,bsize);
if (pal)
{
ASSERT((FALSE,"warning palette is being loaded for %s",file));
_load_palette(pal);
}
iV_FileClose(_PCX_FI);
iV_DEBUG3("pcx[iV_PCXLoad] = file '%s' %dx%d load successful\n",file,
s->width,s->height);
return TRUE;
}
iBool iV_PCXLoadMem(int8 *pcximge, iSprite *s, iColour *pal)
{
iPCX_header header;
int i;
long bsize;
uint8 *hp;
_PCX_MEM = TRUE;
_PCX_MI = pcximge;
iV_DEBUG1("pcx[PCXLoadMem] = loading pcx from memory %p\n",_PCX_MI);
hp = (uint8 *) &header;
for (i=0; i<128; i++)
*hp++ = _pcx_read_int8();
if ((header.manufacturer != 10) && (header.version != 5))
return FALSE;
if (header.bits_per_pixel != 8)
return FALSE;
s->width = (header.xmax - header.xmin)+1;
s->height = (header.ymax - header.ymin)+1;
bsize = s->height * s->width;
if ((s->bmp = (uint8 *) iV_HeapAlloc(bsize)) == NULL)
return FALSE;
_load_image(s->bmp,bsize);
if (pal)
{
ASSERT((FALSE,"warning palette is being loaded in iV_PCXLoadMem"));
_load_palette_mem(pal);
}
iV_DEBUG3("pcx[iV_PCXLoadMEM] = mem %p %dx%d load successful\n",_PCX_MI,
s->width,s->height);
return TRUE;
}
BOOL pie_PCXLoadMemToBuffer(int8 *pcximge, iSprite *s, iColour *pal)
{
iPCX_header header;
int i;
long bsize;
uint8 *hp;
_PCX_MEM = TRUE;
_PCX_MI = pcximge;
iV_DEBUG1("pcx[PCXLoadMem] = loading pcx from memory %p\n",_PCX_MI);
hp = (uint8 *) &header;
for (i=0; i<128; i++)
*hp++ = _pcx_read_int8();
if ((header.manufacturer != 10) && (header.version != 5))
return FALSE;
if (header.bits_per_pixel != 8)
return FALSE;
if (s->width != (header.xmax - header.xmin)+1)
{
iV_FileClose(_PCX_FI);
return FALSE;
}
if (s->height != (header.ymax - header.ymin)+1)
{
iV_FileClose(_PCX_FI);
return FALSE;
}
bsize = s->height * s->width;
_load_image(s->bmp,bsize);
if (pal)
{
ASSERT((FALSE,"warning palette is being loaded in iV_PCXLoadMem"));
_load_palette_mem(pal);
}
iV_DEBUG3("pcx[iV_PCXLoadMEM] = mem %p %dx%d load successful\n",_PCX_MI,
s->width,s->height);
return TRUE;
}
//*************************************************************************
//*************************************************************************

View File

@ -1,852 +0,0 @@
/***************************************************************************/
/*
* pieBlitFunc.c
*
* patch for exisitng ivis rectangle draw functions.
*
*/
/***************************************************************************/
#include "frame.h"
#include <time.h>
#include "pieblitfunc.h"
#include "bug.h"
#include "piedef.h"
#include "piemode.h"
#include "piestate.h"
#include "rendfunc.h"
#include "rendmode.h"
#include "pcx.h"
#include "pieclip.h"
#include "piefunc.h"
#include "piematrix.h"
#include "screen.h"
/***************************************************************************/
/*
* Local Definitions
*/
/***************************************************************************/
UWORD backDropBmp[BACKDROP_WIDTH * BACKDROP_HEIGHT * 2];
SDWORD gSurfaceOffsetX;
SDWORD gSurfaceOffsetY;
UWORD* pgSrcData = NULL;
SDWORD gSrcWidth;
SDWORD gSrcHeight;
SDWORD gSrcStride;
#define COLOURINTENSITY 0xffffffff
/***************************************************************************/
/*
* Local Variables
*/
/***************************************************************************/
PIESTYLE rendStyle;
POINT rectVerts[4];
/***************************************************************************/
/*
* Local ProtoTypes
*/
/***************************************************************************/
/***************************************************************************/
/*
* Source
*/
/***************************************************************************/
void pie_Line(int x0, int y0, int x1, int y1, uint32 colour)
{
pie_SetRendMode(REND_FLAT);
pie_SetColour(colour);
pie_SetTexturePage(-1);
switch (pie_GetRenderEngine())
{
case ENGINE_4101:
line(x0, y0, x1, y1, colour);
break;
default:
break;
}
}
/***************************************************************************/
void pie_Box(int x0,int y0, int x1, int y1, uint32 colour)
{
pie_SetRendMode(REND_FLAT);
pie_SetColour(colour);
pie_SetTexturePage(-1);
if (x0>psRendSurface->clip.right || x1<psRendSurface->clip.left ||
y0>psRendSurface->clip.bottom || y1<psRendSurface->clip.top)
return;
if (x0<psRendSurface->clip.left)
x0 = psRendSurface->clip.left;
if (x1>psRendSurface->clip.right)
x1 = psRendSurface->clip.right;
if (y0<psRendSurface->clip.top)
y0 = psRendSurface->clip.top;
if (y1>psRendSurface->clip.bottom)
y1 = psRendSurface->clip.bottom;
switch (pie_GetRenderEngine())
{
case ENGINE_4101:
box(x0,y0,x1,y1,colour);
break;
default:
break;
}
}
/***************************************************************************/
void pie_BoxFillIndex(int x0,int y0, int x1, int y1, UBYTE colour)
{
pie_SetRendMode(REND_FLAT);
pie_SetTexturePage(-1);
if (x0>psRendSurface->clip.right || x1<psRendSurface->clip.left ||
y0>psRendSurface->clip.bottom || y1<psRendSurface->clip.top)
return;
if (x0<psRendSurface->clip.left)
x0 = psRendSurface->clip.left;
if (x1>psRendSurface->clip.right)
x1 = psRendSurface->clip.right;
if (y0<psRendSurface->clip.top)
y0 = psRendSurface->clip.top;
if (y1>psRendSurface->clip.bottom)
y1 = psRendSurface->clip.bottom;
switch (pie_GetRenderEngine())
{
case ENGINE_4101:
iV_pBoxFill(x0,y0,x1,y1,colour);
break;
default:
break;
}
}
void pie_BoxFill(int x0,int y0, int x1, int y1, uint32 colour)
{
PIELIGHT light;
pie_SetRendMode(REND_FLAT);
pie_SetTexturePage(-1);
if (x0>psRendSurface->clip.right || x1<psRendSurface->clip.left ||
y0>psRendSurface->clip.bottom || y1<psRendSurface->clip.top)
return;
if (x0<psRendSurface->clip.left)
x0 = psRendSurface->clip.left;
if (x1>psRendSurface->clip.right)
x1 = psRendSurface->clip.right;
if (y0<psRendSurface->clip.top)
y0 = psRendSurface->clip.top;
if (y1>psRendSurface->clip.bottom)
y1 = psRendSurface->clip.bottom;
switch (pie_GetRenderEngine())
{
case ENGINE_4101:
light.argb = colour;
iV_pBoxFill(x0,y0,x1,y1,pal_GetNearestColour(light.byte.r, light.byte.g, light.byte.b));
break;
default:
break;
}
}
/***************************************************************************/
void pie_TransBoxFill(SDWORD x0, SDWORD y0, SDWORD x1, SDWORD y1)
{
UDWORD rgb;
UDWORD transparency;
rgb = (pie_FILLRED<<16) | (pie_FILLGREEN<<8) | pie_FILLBLUE;//blue
transparency = pie_FILLTRANS;
pie_UniTransBoxFill(x0, y0, x1, y1, rgb, transparency);
// pie_doWeirdBoxFX(x0,y0,x1,y1);
}
/***************************************************************************/
void pie_UniTransBoxFill(SDWORD x0,SDWORD y0, SDWORD x1, SDWORD y1, UDWORD rgb, UDWORD transparency)
{
// pie_doWeirdBoxFX(x0,y0,x1,y1);
// return;
if (x0>psRendSurface->clip.right || x1<psRendSurface->clip.left ||
y0>psRendSurface->clip.bottom || y1<psRendSurface->clip.top)
return;
if (x0<psRendSurface->clip.left)
x0 = psRendSurface->clip.left;
if (x1>psRendSurface->clip.right)
x1 = psRendSurface->clip.right;
if (y0<psRendSurface->clip.top)
y0 = psRendSurface->clip.top;
if (y1>psRendSurface->clip.bottom)
y1 = psRendSurface->clip.bottom;
switch (pie_GetRenderEngine())
{
case ENGINE_4101:
TransBoxFill(x0,y0,x1,y1);
break;
default:
break;
}
}
/***************************************************************************/
void pie_DrawImageFileID(IMAGEFILE *ImageFile,UWORD ID,int x,int y)
{
IMAGEDEF *Image;
iBitmap *bmp;
UDWORD modulus;
SDWORD width;
SDWORD height;
SDWORD delta;
assert(ID < ImageFile->Header.NumImages);
Image = &ImageFile->ImageDefs[ID];
switch (pie_GetRenderEngine())
{
case ENGINE_4101:
width = Image->Width;
height = Image->Height;
modulus = ImageFile->TexturePages[Image->TPageID].width;
bmp = ImageFile->TexturePages[Image->TPageID].bmp;
bmp += ((UDWORD)Image->Tu) + ((UDWORD)Image->Tv) * modulus;
x +=Image->XOffset;
y +=Image->YOffset;
//clip
if (x < psRendSurface->clip.left)//off left hand edge
{
delta = psRendSurface->clip.left - x;
if (delta < width)
{
bmp += delta;
x += delta;
width -= delta;
}
else
{
return;
}
}
if ((x + width) > (psRendSurface->clip.right + 1))
{
delta = (x + width) - (psRendSurface->clip.right + 1);
if (delta < width)
{
width -= delta;
}
else
{
return;
}
}
if (y < psRendSurface->clip.top)
{
delta = psRendSurface->clip.top - y;
if (delta < height)
{
bmp+= delta * modulus;
y += delta;
height -= delta;
}
else
{
return;
}
}
if ((y + height) > (psRendSurface->clip.bottom + 1))
{
delta = (y + height) - (psRendSurface->clip.bottom + 1);
if (delta < height)
{
height -= delta;
}
else
{
return;
}
}
iV_ppBitmapTrans(bmp,x,y,width,height,modulus);
break;
default:
break;
}
}
BOOL bAddSprites = FALSE;
UDWORD addSpriteLevel;
void pie_SetAdditiveSprites(BOOL val)
{
bAddSprites = val;
}
void pie_SetAdditiveSpriteLevel(UDWORD val)
{
addSpriteLevel = val;
}
BOOL pie_GetAdditiveSprites( void )
{
return(bAddSprites);
}
void pie_ImageFileID(IMAGEFILE *ImageFile,UWORD ID,int x,int y)
{
IMAGEDEF *Image;
iBitmap *bmp;
UDWORD modulus;
SDWORD width;
SDWORD height;
SDWORD delta;
assert(ID < ImageFile->Header.NumImages);
Image = &ImageFile->ImageDefs[ID];
if(pie_GetAdditiveSprites())
{
pie_SetBilinear(TRUE);
pie_SetRendMode(REND_ALPHA_TEX);
pie_SetColour(addSpriteLevel);
pie_SetColourKeyedBlack(TRUE);
}
else
{
pie_SetBilinear(FALSE);
pie_SetRendMode(REND_GOURAUD_TEX);
pie_SetColour(COLOURINTENSITY);
pie_SetColourKeyedBlack(TRUE);
}
switch (pie_GetRenderEngine())
{
case ENGINE_4101:
width = Image->Width;
height = Image->Height;
modulus = ImageFile->TexturePages[Image->TPageID].width;
bmp = ImageFile->TexturePages[Image->TPageID].bmp;
bmp += ((UDWORD)Image->Tu) + ((UDWORD)Image->Tv) * modulus;
x +=Image->XOffset;
y +=Image->YOffset;
//clip
//clip
if (x < psRendSurface->clip.left)//off left hand edge
{
delta = psRendSurface->clip.left - x;
if (delta < width)
{
bmp += delta;
x += delta;
width -= delta;
}
else
{
return;
}
}
if ((x + width) > (psRendSurface->clip.right + 1))
{
delta = (x + width) - (psRendSurface->clip.right + 1);
if (delta < width)
{
width -= delta;
}
else
{
return;
}
}
if (y < psRendSurface->clip.top)
{
delta = psRendSurface->clip.top - y;
if (delta < height)
{
bmp+= delta * modulus;
y += delta;
height -= delta;
}
else
{
return;
}
}
if ((y + height) > (psRendSurface->clip.bottom + 1))
{
delta = (y + height) - (psRendSurface->clip.bottom + 1);
if (delta < height)
{
height -= delta;
}
else
{
return;
}
}
iV_ppBitmapTrans(bmp,x,y,width,height,modulus);
break;
default:
break;
}
}
/***************************************************************************/
void pie_ImageFileIDTile(IMAGEFILE *ImageFile,UWORD ID,int x,int y,int x0,int y0,int Width,int Height)
{
IMAGEDEF *Image;
assert(ID < ImageFile->Header.NumImages);
assert(x0 == 0);
assert(y0 == 0);
Image = &ImageFile->ImageDefs[ID];
pie_SetBilinear(FALSE);
pie_SetRendMode(REND_GOURAUD_TEX);
pie_SetColour(COLOURINTENSITY);
pie_SetColourKeyedBlack(TRUE);
switch (pie_GetRenderEngine())
{
case ENGINE_4101:
DrawImageRect(ImageFile, ID, x, y, x0, y0, Width, Height);
break;
default:
break;
}
}
void pie_ImageFileIDStretch(IMAGEFILE *ImageFile,UWORD ID,int x,int y,int Width,int Height)
{
IMAGEDEF *Image;
assert(ID < ImageFile->Header.NumImages);
Image = &ImageFile->ImageDefs[ID];
pie_SetBilinear(FALSE);
pie_SetRendMode(REND_GOURAUD_TEX);
pie_SetColour(COLOURINTENSITY);
pie_SetColourKeyedBlack(TRUE);
switch (pie_GetRenderEngine())
{
case ENGINE_4101:
break;
default:
break;
}
}
void pie_ImageDef(IMAGEDEF *Image,iBitmap *Bmp,UDWORD Modulus,int x,int y,BOOL bBilinear)
{
pie_SetBilinear(bBilinear); //changed by alex 19 oct 98
pie_SetRendMode(REND_GOURAUD_TEX);
pie_SetColour(COLOURINTENSITY);
pie_SetColourKeyedBlack(TRUE);
switch (pie_GetRenderEngine())
{
case ENGINE_4101:
// Modulus = ImageFile->TexturePages[Image->TPageID].width;
// Bmp = ImageFile->TexturePages[Image->TPageID].bmp;
Bmp += ((UDWORD)Image->Tu) + ((UDWORD)Image->Tv) * Modulus;
iV_ppBitmapTrans(Bmp,x+Image->XOffset,y+Image->YOffset,
Image->Width,Image->Height,Modulus);
break;
default:
break;
}
pie_SetBilinear(FALSE); //changed by alex 19 oct 98
}
void pie_ImageDefTrans(IMAGEDEF *Image,iBitmap *Bmp,UDWORD Modulus,int x,int y,int TransRate)
{
pie_ImageDef(Image,Bmp,Modulus,x,y,FALSE);
}
void pie_UploadDisplayBuffer(UBYTE *DisplayBuffer)
{
switch (pie_GetRenderEngine())
{
case ENGINE_4101:
UploadDisplayBuffer(DisplayBuffer);
break;
default:
break;
}
}
void pie_DownloadDisplayBuffer(UBYTE *DisplayBuffer)
{
switch (pie_GetRenderEngine())
{
case ENGINE_4101:
DownloadDisplayBuffer(DisplayBuffer);
break;
default:
break;
}
}
void pie_ScaleBitmapRGB(UBYTE *DisplayBuffer,int Width,int Height,int ScaleR,int ScaleG,int ScaleB)
{
switch (pie_GetRenderEngine())
{
case ENGINE_4101:
ScaleBitmapRGB(DisplayBuffer, Width, Height, ScaleR, ScaleG, ScaleB);
break;
default:
break;
}
}
BOOL pie_InitRadar(void)
{
switch (pie_GetRenderEngine())
{
case ENGINE_4101:
break;
default:
break;
}
return TRUE;
}
BOOL pie_ShutdownRadar(void)
{
switch (pie_GetRenderEngine())
{
case ENGINE_4101:
break;
default:
break;
}
return TRUE;
}
void pie_DownLoadRadar(unsigned char *buffer, UDWORD texPageID)
{
switch (pie_GetRenderEngine())
{
case ENGINE_4101:
DownLoadRadar(buffer);
break;
default:
break;
}
}
void pie_RenderRadar(IMAGEDEF *Image,iBitmap *Bmp,UDWORD Modulus,int x,int y)
{
//special case of pie_ImageDef
switch (pie_GetRenderEngine())
{
case ENGINE_4101:
pie_ImageDef(Image,Bmp,Modulus,x,y,FALSE);
break;
default:
break;
}
}
void pie_RenderRadarRotated(IMAGEDEF *Image,iBitmap *Bmp,UDWORD Modulus,int x,int y,int angle)
{
//special case of pie_ImageDef
switch (pie_GetRenderEngine())
{
case ENGINE_4101:
pie_ImageDef(Image,Bmp,Modulus,x,y,FALSE);
break;
default:
break;
}
}
/* Converts an 8 bit raw (palettised) source image to
a 16 bit argb destination image
*/
void bufferTo16Bit(UBYTE *origBuffer,UWORD *newBuffer, BOOL b3DFX)
{
UBYTE paletteIndex;
UWORD newColour;
UWORD gun;
UDWORD i;
ULONG mask, amask, rmask, gmask, bmask;
BYTE ap = 0, ac = 0, rp = 0, rc = 0, gp = 0, gc = 0, bp = 0, bc = 0;
iColour* psPalette;
UDWORD size;
if (b3DFX)
{
// 565 RGB
ap = 16;
ac = 0;
rp = 11;
rc = 5;
gp = 5;
gc = 6;
bp = 0;
bc = 5;
}
else
{
/*
// Cannot playback if not 16bit mode
*/
if( screenGetBackBufferBitDepth() == 16 )
{
screenGetBackBufferPixelFormatMasks(&amask, &rmask, &gmask, &bmask);
/*
// Find out the RGB type of the surface and tell the codec...
*/
mask = amask;
if(mask!=0)
{
while(!(mask & 1))
{
mask>>=1;
ap++;
}
}
while((mask & 1))
{
mask>>=1;
ac++;
}
mask = rmask;
if(mask!=0)
{
while(!(mask & 1))
{
mask>>=1;
rp++;
}
}
while((mask & 1))
{
mask>>=1;
rc++;
}
mask = gmask;
if(mask!=0)
{
while(!(mask & 1))
{
mask>>=1;
gp++;
}
}
while((mask & 1))
{
mask>>=1;
gc++;
}
mask = bmask;
if(mask!=0)
{
while(!(mask & 1))
{
mask>>=1;
bp++;
}
}
while((mask & 1))
{
mask>>=1;
bc++;
}
}
}
/*
640*480, 8 bit colour source image
640*480, 16 bit colour destination image
*/
size = BACKDROP_WIDTH*BACKDROP_HEIGHT;//pie_GetVideoBufferWidth()*pie_GetVideoBufferHeight();
for(i=0; i<size; i++)
{
psPalette = pie_GetGamePal();
/* Get the next colour */
paletteIndex = *origBuffer++;
/* Flush out destination word (and alpha bits) */
newColour = 0;
/* Get red bits - 5 */
gun = (UWORD)(psPalette[paletteIndex].r>>(8-rc));
gun = gun << rp;
newColour += gun;
/* Get green bits - 6 */
gun = (UWORD)(psPalette[paletteIndex].g>>(8-gc));
gun = gun << gp;
newColour += gun;
/* Get blue bits - 5 */
gun = (UWORD)(psPalette[paletteIndex].b>>(8-bc));
gun = gun << bp;
newColour += gun;
/* Copy over */
*newBuffer++ = newColour;
}
}
void pie_ResetBackDrop(void)
{
screen_SetBackDrop(backDropBmp, BACKDROP_WIDTH, BACKDROP_HEIGHT);
return;
}
void pie_LoadBackDrop(SCREENTYPE screenType, BOOL b3DFX)
{
iSprite backDropSprite;
iBitmap tempBmp[BACKDROP_WIDTH*BACKDROP_HEIGHT];
UDWORD chooser0,chooser1;
CHAR backd[128];
SDWORD bitDepth;
if (b3DFX)
{
bitDepth = 16;
}
else
{
if( screenGetBackBufferBitDepth() == 16 )
{
bitDepth = 16;
}
else
{
bitDepth = 8;
}
}
//randomly load in a backdrop piccy.
srand((unsigned)time( NULL ) );
chooser0 = 0;
chooser1 = rand()%7;
backDropSprite.width = BACKDROP_WIDTH;
backDropSprite.height = BACKDROP_HEIGHT;
if (bitDepth == 8)
{
backDropSprite.bmp = (UBYTE*)backDropBmp;
}
else
{
backDropSprite.bmp = tempBmp;
}
switch (screenType)
{
case SCREEN_RANDOMBDROP:
sprintf(backd,"texpages\\bdrops\\%d%d-bdrop.pcx",chooser0,chooser1);
break;
case SCREEN_COVERMOUNT:
sprintf(backd,"texpages\\bdrops\\demo-bdrop.pcx");
break;
case SCREEN_MISSIONEND:
sprintf(backd,"texpages\\bdrops\\missionend.pcx");
break;
case SCREEN_SLIDE1:
sprintf(backd,"texpages\\slides\\slide1.pcx");
break;
case SCREEN_SLIDE2:
sprintf(backd,"texpages\\slides\\slide2.pcx");
break;
case SCREEN_SLIDE3:
sprintf(backd,"texpages\\slides\\slide3.pcx");
break;
case SCREEN_SLIDE4:
sprintf(backd,"texpages\\slides\\slide4.pcx");
break;
case SCREEN_SLIDE5:
sprintf(backd,"texpages\\slides\\slide5.pcx");
break;
case SCREEN_CREDITS:
sprintf(backd,"texpages\\bdrops\\credits.pcx");
break;
default:
sprintf(backd,"texpages\\bdrops\\credits.pcx");
break;
}
if (!pie_PCXLoadToBuffer(backd, &backDropSprite, NULL))
{
return;
}
if (bitDepth != 8)
{
bufferTo16Bit(tempBmp, backDropBmp, b3DFX); // convert
}
screen_SetBackDrop(backDropBmp, BACKDROP_WIDTH, BACKDROP_HEIGHT);
}
void pie_D3DSetupRenderForFlip(SDWORD surfaceOffsetX, SDWORD surfaceOffsetY, UWORD* pSrcData, SDWORD srcWidth, SDWORD srcHeight, SDWORD srcStride)
{
gSurfaceOffsetX = surfaceOffsetX;
gSurfaceOffsetY = surfaceOffsetY;
pgSrcData = pSrcData;
gSrcWidth = srcWidth;
gSrcHeight = srcHeight;
gSrcStride = srcStride;
return;
}
void pie_D3DRenderForFlip(void)
{
if (pgSrcData != NULL)
{
pie_RenderImageToSurface(screenGetSurface(), gSurfaceOffsetX, gSurfaceOffsetY, pgSrcData, gSrcWidth, gSrcHeight, gSrcStride);
pgSrcData = NULL;
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,611 +0,0 @@
/***************************************************************************/
/*
* piefunc.c
*
* extended render routines for 3D rendering
*
*/
/***************************************************************************/
#include "frame.h"
#include "piedef.h"
#include "rendmode.h"
#include "piefunc.h"
#include "piestate.h"
#include "piematrix.h"
#include "pietexture.h"
#include "pieclip.h"
#include "gtime.h"
/***************************************************************************/
/*
* Local Definitions
*/
/***************************************************************************/
/***************************************************************************/
/*
* Local Variables
*/
/***************************************************************************/
static PIEPIXEL scrPoints[pie_MAX_POLYS];
static PIEVERTEX pieVrts[pie_MAX_POLY_VERTS];
static PIEVERTEX clippedVrts[pie_MAX_POLY_VERTS];
static D3DTLVERTEX d3dVrts[pie_MAX_POLY_VERTS];
static UBYTE aByteScale[256][256];
/***************************************************************************/
/*
* Local ProtoTypes
*/
/***************************************************************************/
/***************************************************************************/
/*
* Source
*/
/***************************************************************************/
void pie_DownLoadBufferToScreen(void *pSrcData, UDWORD destX, UDWORD destY,UDWORD srcWidth,UDWORD srcHeight,UDWORD srcStride)
{
return;
}
/***************************************************************************/
/*
* void pie_RectFilter(SDWORD x0, SDWORD y0, SDWORD x1, SDWORD y1, UDWORD colour)
*
* Draws rectangular filter to screen ivis mode defaults to
*
*/
/***************************************************************************/
void pie_RectFilter(SDWORD x0, SDWORD y0, SDWORD x1, SDWORD y1, UDWORD colour)
{
{
iV_TransBoxFill(x0, y0, x1, y1);
}
return;
}
/* ---------------------------------------------------------------------------------- */
void pie_CornerBox(SDWORD x0, SDWORD y0, SDWORD x1, SDWORD y1, UDWORD colour,
UBYTE a, UBYTE b, UBYTE c, UBYTE d)
{
}
/* ---------------------------------------------------------------------------------- */
#define D3D_VIEW_WINDOW
#ifndef D3D_VIEW_WINDOW
void pie_DrawViewingWindow( iVector *v, UDWORD x1, UDWORD y1, UDWORD x2, UDWORD y2,UDWORD colour)
{
}
#else
void pie_DrawViewingWindow(iVector *v,UDWORD x1, UDWORD y1, UDWORD x2, UDWORD y2, UDWORD colour)
{
SDWORD clip, i;
{
pie_SetTexturePage(-1);
pie_SetRendMode(REND_ALPHA_FLAT);
//PIE verts
pieVrts[0].sx = v[1].x;
pieVrts[0].sy = v[1].y;
//cull triangles with off screen points
pieVrts[0].sz = INTERFACE_DEPTH;
pieVrts[0].tu = 0.0;
pieVrts[0].tv = 0.0;
pieVrts[0].light.argb = colour;//0x7fffffff;
pieVrts[0].specular.argb = 0;
memcpy(&pieVrts[1],&pieVrts[0],sizeof(PIEVERTEX));
memcpy(&pieVrts[2],&pieVrts[0],sizeof(PIEVERTEX));
memcpy(&pieVrts[3],&pieVrts[0],sizeof(PIEVERTEX));
memcpy(&pieVrts[4],&pieVrts[0],sizeof(PIEVERTEX));
pieVrts[1].sx = v[0].x;
pieVrts[1].sy = v[0].y;
pieVrts[2].sx = v[2].x;
pieVrts[2].sy = v[2].y;
pieVrts[3].sx = v[3].x;
pieVrts[3].sy = v[3].y;
pie_Set2DClip(x1,y1,x2-1,y2-1);
clip = pie_ClipTextured(4, &pieVrts[0], &clippedVrts[0], FALSE);
pie_Set2DClip(CLIP_BORDER,CLIP_BORDER,psRendSurface->width-CLIP_BORDER,psRendSurface->height-CLIP_BORDER);
#ifndef NO_RENDER
if (clip >= 3)
{
if(!pie_Translucent())
{
for (i = 0;i < (clip - 1);i++)
{
pie_Line(clippedVrts[i].sx, clippedVrts[i].sy, clippedVrts[i+1].sx, clippedVrts[i+1].sy, colour);
}
pie_Line(clippedVrts[clip-1].sx, clippedVrts[clip-1].sy, clippedVrts[0].sx, clippedVrts[0].sy, colour);
}
}
#endif
}
}
#endif
/* ---------------------------------------------------------------------------------- */
void pie_TransColouredTriangle(PIEVERTEX *vrt, UDWORD rgb, UDWORD trans)
{
}
/* ---------------------------------------------------------------------------------- */
/* Returns number of buffers pending */
int pie_Num3dfxBuffersPending( void )
{
int retVal=0;
return(retVal);
}
/* ---------------------------------------------------------------------------------- */
void pie_DrawBoundingDisc(iIMDShape *shape, int pieFlag)
{
int i, n, radR2;
iVector vertex;
PIEPIXEL *pPixels;
PIED3DPOLY renderPoly;
DWORD colour, specular;
int32 rx, ry, rz;
int32 tzx, tzy;
// pieCount++;
pie_SetTexturePage(-1);
colour = 0xff000000;
specular = 0;
//draw bounding sphere
if (pieFlag & pie_DRAW_DISC_RED)
{
colour |= 0xff0000;
}
if (pieFlag & pie_DRAW_DISC_GREEN)
{
colour |= 0xff00;
}
if (pieFlag & pie_DRAW_DISC_YELLOW)
{
colour |= 0xffff00;
}
if (pieFlag & pie_DRAW_DISC_BLUE)
{
colour |= 0xff;
}
//rotate and project four new points
pPixels = &scrPoints[0];
radR2 = (shape->oradius * 71)/100;
if (radR2 < 10)
{
radR2 = 10;
}
for (i=0; i<8; i++, pPixels++)
{
vertex.x = 0;
vertex.y = 0;
vertex.z = 0;
switch (i)
{
case 0:
vertex.x = shape->oradius;
break;
case 1:
vertex.x = radR2;
vertex.z = -radR2;
break;
case 2:
vertex.z = -shape->oradius;
break;
case 3:
vertex.x = -radR2;
vertex.z = -radR2;
break;
case 4:
vertex.x = -shape->oradius;
break;
case 5:
vertex.x = -radR2;
vertex.z = radR2;
break;
case 6:
vertex.z = shape->oradius;
break;
case 7:
vertex.x = radR2;
vertex.z = radR2;
break;
}
rx = vertex.x * psMatrix->a + vertex.y * psMatrix->d + vertex.z * psMatrix->g + psMatrix->j;
ry = vertex.x * psMatrix->b + vertex.y * psMatrix->e + vertex.z * psMatrix->h + psMatrix->k;
rz = vertex.x * psMatrix->c + vertex.y * psMatrix->f + vertex.z * psMatrix->i + psMatrix->l;
pPixels->d3dz = D3DVAL((rz>>STRETCHED_Z_SHIFT));
tzx = rz >> psRendSurface->xpshift;
tzy = rz >> psRendSurface->ypshift;
if ((tzx<=0) || (tzy<=0))
{
pPixels->d3dx = (float)LONG_WAY;//just along way off screen
pPixels->d3dy = (float)LONG_WAY;
}
else if (pPixels->d3dz < D3DVAL(MIN_STRETCHED_Z))
{
pPixels->d3dx = (float)LONG_WAY;//just along way off screen
pPixels->d3dy = (float)LONG_WAY;
}
else
{
pPixels->d3dx = D3DVAL((psRendSurface->xcentre + (rx / tzx)));
pPixels->d3dy = D3DVAL((psRendSurface->ycentre - (ry / tzy)));
}
}
renderPoly.flags = PIE_NO_CULL | PIE_ALPHA;
for (n=0; n<8; n++)
{
d3dVrts[n].sx = scrPoints[n].d3dx;
d3dVrts[n].sy = scrPoints[n].d3dy;
//cull triangles with off screen points
if (scrPoints[n].d3dy > (float)LONG_TEST)
renderPoly.flags = 0;
d3dVrts[n].sz = (float)pPixels->d3dz * (float)INV_MAX_Z;
d3dVrts[n].rhw = (float)1.0 / d3dVrts[n].sz;
d3dVrts[n].tu = (float)0.0;
d3dVrts[n].tv = (float)0.0;
d3dVrts[n].color = colour;
d3dVrts[n].specular = specular;
}
renderPoly.nVrts = 8;
renderPoly.pVrts = &d3dVrts[0];
renderPoly.pTexAnim = NULL;
pie_D3DPoly(&renderPoly); // draw the polygon ... this is an inline function
}
void pie_Blit(SDWORD texPage, SDWORD x0, SDWORD y0, SDWORD x1, SDWORD y1)
{
SDWORD i;
PIED3DPOLY renderPoly;
for(i = 0; i < 4; i++)
{
switch(i)
{
case 0:
d3dVrts[i].sx = (float)x0;
d3dVrts[i].sy = (float)y0;
d3dVrts[i].tu = (float)0.0;
d3dVrts[i].tv = (float)0.0;
break;
case 1:
d3dVrts[i].sx = (float)x1;
d3dVrts[i].sy = (float)y0;
d3dVrts[i].tu = (float)1.0;
d3dVrts[i].tv = (float)0.0;
break;
case 2:
d3dVrts[i].sx = (float)x1;
d3dVrts[i].sy = (float)y1;
d3dVrts[i].tu = (float)1.0;
d3dVrts[i].tv = (float)1.0;
break;
case 3:
default:
d3dVrts[i].sx = (float)x0;
d3dVrts[i].sy = (float)y1;
d3dVrts[i].tu = (float)0.0;
d3dVrts[i].tv = (float)1.0;
break;
}
d3dVrts[i].sz = (float)0.001;//scrPoints[*index].d3dz;
d3dVrts[i].rhw = (float)1000.0;
d3dVrts[i].color = (D3DCOLOR)((255 << 24) + (255 << 16) + (255 << 8) + 255);
d3dVrts[i].specular = 0;
}
{
renderPoly.flags = PIE_NO_CULL | PIE_TEXTURED;
renderPoly.nVrts = 4;
renderPoly.pVrts = &d3dVrts[0];
pie_SetTexturePage(texPage);
pie_D3DPoly(&renderPoly); // draw the polygon ... this is an inline function
}
}
void pie_Sky(SDWORD texPage, PIEVERTEX* aSky)
{
SDWORD i;
PIED3DPOLY renderPoly;
if ((rendSurface.usr == iV_MODE_4101) || (rendSurface.usr == REND_GLIDE_3DFX))
{
}
else
{
renderPoly.flags = PIE_NO_CULL | PIE_TEXTURED;
renderPoly.nVrts = 4;
renderPoly.pVrts = &d3dVrts[0];
}
for(i = 0; i < 4; i++)
{
d3dVrts[i].sx = (float)aSky[i].sx;
d3dVrts[i].sy = (float)aSky[i].sy;
if (d3dVrts[i].sy == -9999)
{
renderPoly.flags = 0;
}
d3dVrts[i].tu = (float)aSky[i].tu * (float)INV_TEX_SIZE;
d3dVrts[i].tv = (float)aSky[i].tv * (float)INV_TEX_SIZE;
d3dVrts[i].sz = (float)aSky[i].sz * (float)INV_MAX_Z;//scr Points[*index].d3dz;
d3dVrts[i].rhw = (float)1.0 / d3dVrts[i].sz;
d3dVrts[i].color = (D3DCOLOR)((255 << 24) + (255 << 16) + (255 << 8) + 255);
d3dVrts[i].specular = 0;
}
if ((rendSurface.usr == iV_MODE_4101) || (rendSurface.usr == REND_GLIDE_3DFX))
{
}
else
{
pie_SetTexturePage(texPage);
pie_D3DPoly(&renderPoly); // draw the polygon ... this is an inline function
}
}
void pie_Water(SDWORD texPage, SDWORD x0, SDWORD y0, SDWORD x1, SDWORD y1, SDWORD height, SDWORD translucency)
{
SDWORD i;
PIEPIXEL pPixel;
iVector vertex;
PIED3DPOLY renderPoly;
int32 rx, ry, rz;
int32 tzx, tzy;
vertex.y = height;
if ((rendSurface.usr == iV_MODE_4101) || (rendSurface.usr == REND_GLIDE_3DFX))
{
}
else
{
renderPoly.flags = PIE_NO_CULL | PIE_TEXTURED | PIE_COLOURKEYED | PIE_ALPHA;
renderPoly.nVrts = 4;
renderPoly.pVrts = &d3dVrts[0];
}
for(i = 0; i < 4; i++)
{
switch(i)
{
case 0:
vertex.x = x0;
vertex.z = y0;
d3dVrts[i].tu = (float)0.0;
d3dVrts[i].tv = (float)0.0;
break;
case 1:
vertex.x = x1;
vertex.z = y0;
d3dVrts[i].tu = (float)1.0;
d3dVrts[i].tv = (float)0.0;
break;
case 2:
vertex.x = x1;
vertex.z = y1;
d3dVrts[i].tu = (float)1.0;
d3dVrts[i].tv = (float)0.5;
break;
case 3:
default:
vertex.x = x0;
vertex.z = y1;
d3dVrts[i].tu = (float)0.0;
d3dVrts[i].tv = (float)0.5;
break;
}
rx = vertex.x * psMatrix->a + vertex.y * psMatrix->d + vertex.z * psMatrix->g + psMatrix->j;
ry = vertex.x * psMatrix->b + vertex.y * psMatrix->e + vertex.z * psMatrix->h + psMatrix->k;
rz = vertex.x * psMatrix->c + vertex.y * psMatrix->f + vertex.z * psMatrix->i + psMatrix->l;
pPixel.d3dz = D3DVAL((rz>>STRETCHED_Z_SHIFT));
tzx = rz >> psRendSurface->xpshift;
tzy = rz >> psRendSurface->ypshift;
if ((tzx<=0) || (tzy<=0))
{
pPixel.d3dx = (float)LONG_WAY;//just along way off screen
pPixel.d3dy = (float)LONG_WAY;
}
else if (pPixel.d3dz < D3DVAL(MIN_STRETCHED_Z))
{
pPixel.d3dx = (float)LONG_WAY;//just along way off screen
pPixel.d3dy = (float)LONG_WAY;
}
else
{
pPixel.d3dx = D3DVAL((psRendSurface->xcentre + (rx / tzx)));
pPixel.d3dy = D3DVAL((psRendSurface->ycentre - (ry / tzy)));
}
d3dVrts[i].sx = (float)pPixel.d3dx;
d3dVrts[i].sy = (float)pPixel.d3dy;
if (d3dVrts[i].sy > LONG_TEST)
{
renderPoly.flags = 0;
}
d3dVrts[i].sz = (float)pPixel.d3dz * (float)INV_MAX_Z;
d3dVrts[i].rhw = (float)1.0 / d3dVrts[i].sz;
d3dVrts[i].color = (D3DCOLOR)((translucency << 24) + (translucency << 16) + (translucency << 8) + translucency);
d3dVrts[i].specular = 0;
}
if ((rendSurface.usr == iV_MODE_4101) || (rendSurface.usr == REND_GLIDE_3DFX))
{
}
else
{
pie_SetTexturePage(texPage);
pie_D3DPoly(&renderPoly); // draw the polygon ... this is an inline function
}
}
#define FOG_RED 00
#define FOG_GREEN 00
#define FOG_BLUE 80
#define MIST_RED 00
#define MIST_GREEN 80
#define MIST_BLUE 00
#define FOG_DEPTH 3000
#define FOG_RATE 4
#define MIST_HEIGHT 100
#define SPECULAR_FOG_AND_MIST 0
void pie_AddFogandMist(SDWORD depth, SDWORD height, PIELIGHT* pColour, PIELIGHT* pSpecular)
{
#if SPECULAR_FOG_AND_MIST
SDWORD fogLevel;//0 to 256
SDWORD mistLevel;//0 to 256
DWORD cRed,cGreen,cBlue;
DWORD sRed,sGreen,sBlue;
/// get colour components
/* cRed = pColour->r;
cGreen = pColour->g;
cBlue = pColour->b;
*/
/// get specular components
/* sRed = pSpecular->r;
sGreen = pSpecular->g;
sBlue = pSpecular->b;
*/
// fog level is gradual upto FOG_DEPTH then ramps up suddenly
if (depth < (FOG_DEPTH/2))
{
fogLevel = 256;
}
else if (depth < FOG_DEPTH)
{
depth -= (FOG_DEPTH/2);
fogLevel = 192 * depth/(FOG_DEPTH/2);
}
else
{
depth -= FOG_DEPTH;
fogLevel = 64 * depth/FOG_RATE;
fogLevel += 192;
if (fogLevel > 256)
{
fogLevel = 256;
}
}
pColour->a = fogLevel;
/*
cRed = (cRed * (256 - fogLevel))>>8;
cGreen = (cGreen * (256 - fogLevel))>>8;
cBlue = (cBlue * (256 - fogLevel))>>8;
sRed += (FOG_RED * fogLevel)>>8;
sGreen += (FOG_GREEN * fogLevel)>>8;
sBlue += (FOG_BLUE * fogLevel)>>8;
// set colour components
pColour->r = cRed;
pColour->g = cGreen;
pColour->b = cBlue;
// set specular components
pSpecular->r = sRed;
pSpecular->g = sGreen;
pSpecular->b = sBlue;
*/
// mist level is high upto MIST_HEIGHT then ramps up gently
#endif
}
void pie_InitMaths(void)
{
UBYTE c;
UDWORD a,b,bigC;
for(a=0; a<=UBYTE_MAX; a++)
{
for(b=0; b<=UBYTE_MAX; b++)
{
bigC = a * b;
bigC /= UBYTE_MAX;
ASSERT((bigC <= UBYTE_MAX,"light_InitMaths; rounding error"));
c = (UBYTE)bigC;
aByteScale[a][b] = c;
}
}
}
UBYTE pie_ByteScale(UBYTE a, UBYTE b)
{
return aByteScale[a][b];
}
void pie_doWeirdBoxFX(UDWORD x, UDWORD y, UDWORD x2, UDWORD y2, UDWORD trans)
{
UDWORD val;
UDWORD xDif;
UDWORD yDif;
UDWORD radius;
val = getTimeValueRange(5760,360);
radius = 100;
xDif = radius * (SIN(DEG(val)));
yDif = radius * (COS(DEG(val)));
xDif = xDif/4096; // cos it's fixed point
yDif = yDif/4096;
pie_SetDepthBufferStatus(DEPTH_CMP_ALWAYS_WRT_ON);
pie_CornerBox(x,y,x2,y2,trans,20+(radius+xDif),20+(radius+yDif),20+(radius-xDif),20+(radius-yDif));
/*
val = 360-getTimeValueRange(2880,360);
xDif = radius * (SIN(DEG(val)));
yDif = radius * (COS(DEG(val)));
xDif = xDif/4096; // cos it's fixed point
yDif = yDif/4096;
// pie_BoxFill(100,100,200,200,234);
pie_CornerBox(x,y,x2,y2,trans,20+(radius+xDif),20+(radius+yDif),20+(radius-xDif),20+(radius-yDif));
pie_SetDepthBufferStatus(DEPTH_CMP_LEQ_WRT_ON);
*/
}
//render raw data in system memory to direct draw surface
//use outside of D3D sceen only
void pie_RenderImageToSurface(LPDIRECTDRAWSURFACE4 lpDDS4, SDWORD surfaceOffsetX, SDWORD surfaceOffsetY, UWORD* pSrcData, SDWORD srcWidth, SDWORD srcHeight, SDWORD srcStride)
{
}

View File

@ -1,468 +0,0 @@
/***************************************************************************/
/*
* pieMatrix.c
*
* matrix functions for pumpkin image library.
*
*/
/***************************************************************************/
#include <stdio.h>
#include "piedef.h"
#include "piematrix.h"
#include "rendmode.h"
#include "bug.h"
/***************************************************************************/
/*
* Local Definitions
*/
/***************************************************************************/
/*
Playstation and PC stuff ... just the matrix stack & surface normal code is all thats needed on the PSX
*/
#define MATRIX_MAX 8
#define ONE_PERCENT 41 // 4096/100
void pie_PerspectiveBegin() {
}
void pie_PerspectiveEnd() {
}
static SDMATRIX aMatrixStack[MATRIX_MAX];
SDMATRIX *psMatrix = &aMatrixStack[0];
void pie_VectorNormalise(iVector *v)
{
int32 size;
iVector av;
av.x = pie_ABS(v->x);
av.y = pie_ABS(v->y);
av.z = pie_ABS(v->z);
if (av.x >= av.y) {
if (av.x > av.z)
size = av.x + (av.z >> 2) + (av.y >> 2);
else
size = av.z + (av.x >> 2) + (av.y >> 2);
} else {
if (av.y > av.z)
size = av.y + (av.z >> 2) + (av.x >> 2);
else
size = av.z + (av.y >> 2) + (av.x >> 2);
}
if (size > 0) {
v->x = (v->x << FP12_SHIFT) / size;
v->y = (v->y << FP12_SHIFT) / size;
v->z = (v->z << FP12_SHIFT) / size;
}
}
//*************************************************************************
//*** calculate surface normal
//*
//* params p1,p2,p3 = points for forming 2 vector for cross product
//* v = normal vector returned << FP12_SHIFT
//*
//* eg if a polygon (with n points in clockwise order) normal
//* is required, p1 = point 0, p2 = point 1, p3 = point n-1
//*
//******
void pie_SurfaceNormal(iVector *p1, iVector *p2, iVector *p3, iVector *v)
{
iVector a, b;
a.x = p3->x - p1->x;
a.y = p3->y - p1->y;
a.z = p3->z - p1->z;
pie_VectorNormalise(&a);
b.x = p2->x - p1->x;
b.y = p2->y - p1->y;
b.z = p2->z - p1->z;
pie_VectorNormalise(&b);
v->x = ((a.y * b.z) - (a.z * b.y)) >> FP12_SHIFT;
v->y = ((a.z * b.x) - (a.x * b.z)) >> FP12_SHIFT;
v->z = ((a.x * b.y) - (a.y * b.x)) >> FP12_SHIFT;
pie_VectorNormalise(v);
}
#define SC_TABLESIZE 4096
//*************************************************************************
#define X_INTERCEPT(pt1,pt2,yy) \
(pt2->x - (((pt2->y - yy) * (pt1->x - pt2->x)) / (pt1->y - pt2->y)))
//*************************************************************************
static SDMATRIX _MATRIX_ID = {FP12_MULTIPLIER,0,0, 0,FP12_MULTIPLIER,0, 0,0,FP12_MULTIPLIER, 0L,0L,0L};
static SDWORD _MATRIX_INDEX;
//*************************************************************************
int aSinTable[SC_TABLESIZE + (SC_TABLESIZE/4)];
//*************************************************************************
//*** reset transformation matrix stack and make current identity
//*
//******
void pie_MatReset(void)
{
psMatrix = &aMatrixStack[0];
// make 1st matrix identity
*psMatrix = _MATRIX_ID;
}
//*************************************************************************
//*** create new matrix from current transformation matrix and make current
//*
//******
void pie_MatBegin(void)
{
_MATRIX_INDEX++;
if (_MATRIX_INDEX > 3)
{
ASSERT((_MATRIX_INDEX < MATRIX_MAX,"pie_MatBegin past top of the stack"));
}
psMatrix++;
aMatrixStack[_MATRIX_INDEX] = aMatrixStack[_MATRIX_INDEX-1];
}
//*************************************************************************
//*** make current transformation matrix previous one on stack
//*
//******
void pie_MatEnd(void)
{
_MATRIX_INDEX--;
ASSERT((_MATRIX_INDEX >= 0,"pie_MatEnd of the bottom of the stack"));
psMatrix--;
}
//*************************************************************************
//*** matrix scale current transformation matrix
//*
//******
void pie_MatScale( UDWORD percent )
{
SDWORD scaleFactor;
if(percent == 100)
{
return;
}
scaleFactor = percent * ONE_PERCENT;
psMatrix->a = (psMatrix->a * scaleFactor) / 4096;
psMatrix->b = (psMatrix->b * scaleFactor) / 4096;
psMatrix->c = (psMatrix->c * scaleFactor) / 4096;
psMatrix->d = (psMatrix->d * scaleFactor) / 4096;
psMatrix->e = (psMatrix->e * scaleFactor) / 4096;
psMatrix->f = (psMatrix->f * scaleFactor) / 4096;
psMatrix->g = (psMatrix->g * scaleFactor) / 4096;
psMatrix->h = (psMatrix->h * scaleFactor) / 4096;
psMatrix->i = (psMatrix->i * scaleFactor) / 4096;
}
//*************************************************************************
//*** matrix rotate y (yaw) current transformation matrix
//*
//******
void pie_MatRotY(int y)
{
int t;
int cra, sra;
if (y != 0) {
cra = COS(y);
sra = SIN(y);
t = ((cra * psMatrix->a) - (sra * psMatrix->g))>>FP12_SHIFT;
psMatrix->g = ((sra * psMatrix->a) + (cra * psMatrix->g))>>FP12_SHIFT;
psMatrix->a = t;
t = ((cra * psMatrix->b) - (sra * psMatrix->h))>>FP12_SHIFT;
psMatrix->h = ((sra * psMatrix->b) + (cra * psMatrix->h))>>FP12_SHIFT;
psMatrix->b = t;
t = ((cra * psMatrix->c) - (sra * psMatrix->i))>>FP12_SHIFT;
psMatrix->i = ((sra * psMatrix->c) + (cra * psMatrix->i))>>FP12_SHIFT;
psMatrix->c = t;
}
}
//*************************************************************************
//*** matrix rotate z (roll) current transformation matrix
//*
//******
void pie_MatRotZ(int z)
{
int t;
int cra, sra;
if (z != 0) {
cra = COS(z);
sra = SIN(z);
t = ((cra * psMatrix->a) + (sra * psMatrix->d))>>FP12_SHIFT;
psMatrix->d = ((cra * psMatrix->d) - (sra * psMatrix->a))>>FP12_SHIFT;
psMatrix->a = t;
t = ((cra * psMatrix->b) + (sra * psMatrix->e))>>FP12_SHIFT;
psMatrix->e = ((cra * psMatrix->e) - (sra * psMatrix->b))>>FP12_SHIFT;
psMatrix->b = t;
t = ((cra * psMatrix->c) + (sra * psMatrix->f))>>FP12_SHIFT;
psMatrix->f = ((cra * psMatrix->f) - (sra * psMatrix->c))>>FP12_SHIFT;
psMatrix->c = t;
}
}
//*************************************************************************
//*** matrix rotate x (pitch) current transformation matrix
//*
//******
void pie_MatRotX(int x)
{
register int cra, sra;
register int t;
if (x != 0) {
cra = COS(x);
sra = SIN(x);
t = ((cra * psMatrix->d) + (sra * psMatrix->g))>>FP12_SHIFT;
psMatrix->g = ((cra * psMatrix->g) - (sra * psMatrix->d))>>FP12_SHIFT;
psMatrix->d = t;
t = ((cra * psMatrix->e) + (sra * psMatrix->h))>>FP12_SHIFT;
psMatrix->h = ((cra * psMatrix->h) - (sra * psMatrix->e))>>FP12_SHIFT;
psMatrix->e = t;
t = ((cra * psMatrix->f) + (sra * psMatrix->i))>>FP12_SHIFT;
psMatrix->i = ((cra * psMatrix->i) - (sra * psMatrix->f))>>FP12_SHIFT;
psMatrix->f = t;
}
}
//*************************************************************************
//*** 3D vector perspective projection
//*
//* params v1 = 3D vector to project
//* v2 = pointer to 2D resultant vector
//*
//* on exit v2 = projected vector
//*
//* returns rotated and translated z component of v1
//*
//******
int32 pie_RotProj(iVector *v3d, iPoint *v2d)
{
int32 zfx, zfy;
int32 zz, x, y, z;
x = v3d->x * psMatrix->a+v3d->y * psMatrix->d+v3d->z * psMatrix->g +
psMatrix->j;
y = v3d->x * psMatrix->b+v3d->y * psMatrix->e+v3d->z * psMatrix->h +
psMatrix->k;
z = v3d->x * psMatrix->c+v3d->y * psMatrix->f+v3d->z * psMatrix->i +
psMatrix->l;
zz = z >> STRETCHED_Z_SHIFT;
zfx = z >> psRendSurface->xpshift;
zfy = z >> psRendSurface->ypshift;
if ((zfx<=0) || (zfy<=0))
{
v2d->x = LONG_WAY;//just along way off screen
v2d->y = LONG_WAY;
}
else if (zz < MIN_STRETCHED_Z)
{
v2d->x = LONG_WAY;//just along way off screen
v2d->y = LONG_WAY;
}
else
{
v2d->x = psRendSurface->xcentre + (x / zfx);
v2d->y = psRendSurface->ycentre - (y / zfy);
}
return zz;
}
//*************************************************************************
//*** create 3x3 matrix from given euler angles
//*
//* params r = vector x,y,z euler rotation angles
//* m = pointer to matrix for storing result
//*
//* on exit *m = 3x3 pure rotation matrix
//*
//******
void pie_MatCreate(iVector *r, SDMATRIX *m)
{
int crx, cry, crz, srx, sry, srz;
crx = COS(r->x); cry = COS(r->y); crz = COS(r->z);
srx = SIN(r->x); sry = SIN(r->y); srz = SIN(r->z);
m->a = (((cry * crz) - (((sry * srx) >> FP12_SHIFT) * srz))>>FP12_SHIFT);
m->b = (((cry * srz) + (((sry * srx) >> FP12_SHIFT) * crz))>>FP12_SHIFT);
m->c = ((-sry * crx)>>FP12_SHIFT);
m->d = ((-crx * srz)>>FP12_SHIFT);
m->e = ((crx * crz)>>FP12_SHIFT);
m->f = srx;
m->g = (((sry * crz) + (((cry * srx) >> FP12_SHIFT) * srz))>>FP12_SHIFT);
m->h = (((sry * srz) - (((cry * srx) >> FP12_SHIFT) * crz))>>FP12_SHIFT);
m->i = ((cry * crx)>>FP12_SHIFT);
}
//*************************************************************************
void pie_SetGeometricOffset(int x, int y)
{
psRendSurface->xcentre = x;
psRendSurface->ycentre = y;
}
// all these routines use the PC format of iVertex ... and are not used on the PSX
//*************************************************************************
BOOL pie_Clockwise(iVertex *s)
{
return (((s[1].y - s[0].y) * (s[2].x - s[1].x)) <=
((s[1].x - s[0].x) * (s[2].y - s[1].y)));
}
BOOL pie_PieClockwise(PIEVERTEX *s)
{
return (((s[1].sy - s[0].sy) * (s[2].sx - s[1].sx)) <=
((s[1].sx - s[0].sx) * (s[2].sy - s[1].sy)));
}
//*************************************************************************
//*** inverse rotate 3D vector with current rotation matrix
//*
//* params v1 = pointer to 3D vector to rotate
//* v2 = pointer to 3D resultant vector
//*
//* on exit v2 = inverse-rotated vector
//*
//******
void pie_VectorInverseRotate0(iVector *v1, iVector *v2)
{
int32 x, y, z;
x = v1->x; y = v1->y; z = v1->z;
v2->x = (x * psMatrix->a+y * psMatrix->b+z * psMatrix->c) >> FP12_SHIFT;
v2->y = (x * psMatrix->d+y * psMatrix->e+z * psMatrix->f) >> FP12_SHIFT;
v2->z = (x * psMatrix->g+y * psMatrix->h+z * psMatrix->i) >> FP12_SHIFT;
}
//*************************************************************************
//*** setup transformation matrices/quaternions and trig tables
//*
//******
void pie_MatInit(void)
{
unsigned i, scsize;
double conv, v;
// sin/cos table
scsize = SC_TABLESIZE + (SC_TABLESIZE / 4);
conv = (float)(PI / (0.5 * SC_TABLESIZE));
for (i=0; i<scsize; i++) {
v = (double) sin(i * conv) * FP12_MULTIPLIER;
if (v >= 0.0)
aSinTable[i] = (int32)(v + 0.5);
else
aSinTable[i] = (int32)(v - 0.5);
}
// init matrix/quat stack
pie_MatReset();
iV_DEBUG0("geo[_geo_setup] = setup successful\n");
}

View File

@ -1,133 +0,0 @@
/***************************************************************************/
/*
* pieMatrix.h
*
* matrix functions for pumpkin image library.
*
*/
/***************************************************************************/
#ifndef _pieMatrix_h
#define _pieMatrix_h
#include "piedef.h"
/***************************************************************************/
/*
* Global Definitions
*/
/***************************************************************************/
typedef struct {SDWORD a, b, c, d, e, f, g, h, i, j, k, l;} SDMATRIX;
/***************************************************************************/
/*
* Global Variables
*/
/***************************************************************************/
extern SDMATRIX *psMatrix;
extern SDWORD aSinTable[];
//*************************************************************************
#define SIN(X) aSinTable[(uint16)(X) >> 4]
#define COS(X) aSinTable[((uint16)(X) >> 4) + 1024]
#define pie_INVTRANSX(X) psMatrix->j = (X)<<FP12_SHIFT
#define pie_INVTRANSY(Y) psMatrix->k = (Y)<<FP12_SHIFT
#define pie_INVTRANSZ(Z) psMatrix->l = (Z)<<FP12_SHIFT
#define pie_MATTRANS(X,Y,Z) { psMatrix->j = (X)<<FP12_SHIFT; \
psMatrix->k = (Y)<<FP12_SHIFT; \
psMatrix->l = (Z)<<FP12_SHIFT; }
//*************************************************************************
#define pie_SETUP_ROTATE_PROJECT \
int32 _ivzfx, _ivzfy, _ivx, _ivy, _ivz
#define pie_ROTATE_PROJECT(x,y,z,xs,ys) \
{ \
_ivx = (x) * psMatrix->a + (y) * psMatrix->d + (z) * psMatrix->g + \
psMatrix->j; \
_ivy = (x) * psMatrix->b + (y) * psMatrix->e + (z) * psMatrix->h + \
psMatrix->k; \
_ivz = (x) * psMatrix->c + (y) * psMatrix->f + (z) * psMatrix->i + \
psMatrix->l; \
_ivzfx = _ivz >> psRendSurface->xpshift; \
_ivzfy = _ivz >> psRendSurface->ypshift; \
if ((_ivzfx > 0) && (_ivzfy > 0)) \
{ \
(xs) = psRendSurface->xcentre + (int32) (_ivx / _ivzfx); \
(ys) = psRendSurface->ycentre - (int32) (_ivy / _ivzfy); \
} \
else \
{ \
(xs) = 1<<15; \
(ys) = 1<<15; \
} \
}
//*************************************************************************
#define pie_ROTATE_TRANSLATE(x,y,z,xs,ys,zs) \
{ \
xs = (x) * psMatrix->a + (y) * psMatrix->d + (z) * psMatrix->g + \
psMatrix->j; \
ys = (x) * psMatrix->b + (y) * psMatrix->e + (z) * psMatrix->h + \
psMatrix->k; \
zs = (x) * psMatrix->c + (y) * psMatrix->f + (z) * psMatrix->i + \
psMatrix->l; \
xs >>=FP12_SHIFT; \
ys >>=FP12_SHIFT; \
zs >>=FP12_SHIFT; \
}
//*************************************************************************
#define pie_TRANSLATE(x, y, z) \
{ \
psMatrix->j += ((x) * psMatrix->a + (y) * psMatrix->d + \
(z) * psMatrix->g); \
psMatrix->k += ((x) * psMatrix->b + (y) * psMatrix->e + \
(z) * psMatrix->h); \
psMatrix->l += ((x) * psMatrix->c + (y) * psMatrix->f + \
(z) * psMatrix->i); \
}
//*************************************************************************
#define pie_CLOCKWISE(x0,y0,x1,y1,x2,y2) ((((y1)-(y0)) * ((x2)-(x1))) <= \
(((x1)-(x0)) * ((y2)-(y1))))
//*************************************************************************
extern void pie_MatInit(void);
//*************************************************************************
extern void pie_MatBegin(void);
extern void pie_MatEnd(void);
extern void pie_MatRotX(int x);
extern void pie_MatRotY(int y);
extern void pie_MatRotZ(int z);
extern int32 pie_RotProj(iVector *v3d, iPoint *v2d);
//*************************************************************************
extern void pie_VectorNormalise(iVector *v);
extern void pie_VectorInverseRotate0(iVector *v1, iVector *v2);
extern void pie_SurfaceNormal(iVector *p1, iVector *p2, iVector *p3, iVector *v);
extern BOOL pie_Clockwise(iVertex *s);
extern void pie_SetGeometricOffset(int x, int y);
// PIEVERTEX structure contains much infomation that is not required on the playstation ... and hence is not currently used
extern BOOL pie_PieClockwise(PIEVERTEX *s);
extern void pie_MatScale( UDWORD percent );
extern void pie_PerspectiveBegin(void);
extern void pie_PerspectiveEnd(void);
#endif

View File

@ -1,237 +0,0 @@
/***************************************************************************/
/*
* pieMode.h
*
* renderer control for pumpkin library functions.
*
*/
/***************************************************************************/
#include "frame.h"
#include "piedef.h"
#include "piestate.h"
#include "piemode.h"
#include "piematrix.h"
#include "piefunc.h"
#include "tex.h"
#include "v4101.h"
#include "vsr.h"
#include "rendmode.h"
#include "pieclip.h"
#include "screen.h"
/***************************************************************************/
/*
* Local Definitions
*/
/***************************************************************************/
#define DIVIDE_TABLE_SIZE 1024
/***************************************************************************/
/*
* Local Variables
*/
/***************************************************************************/
int32 _iVPRIM_DIVTABLE[DIVIDE_TABLE_SIZE];
static BOOL bDither = FALSE;
/***************************************************************************/
/*
* Source
*/
/***************************************************************************/
BOOL pie_GetDitherStatus( void )
{
return(bDither);
}
void pie_SetDitherStatus( BOOL val )
{
bDither = val;
}
BOOL pie_Initialise(SDWORD mode)
{
BOOL r;//result
int i;
pie_InitMaths();
pie_TexInit();
pie_SetRenderEngine(ENGINE_UNDEFINED);
rendSurface.usr = REND_UNDEFINED;
rendSurface.flags = REND_SURFACE_UNDEFINED;
rendSurface.buffer = NULL;
rendSurface.size = 0;
// divtable: first entry == unity to (ie n/0 == 1 !)
_iVPRIM_DIVTABLE[0] = iV_DIVMULTP;
for (i=1; i<DIVIDE_TABLE_SIZE; i++)
{
_iVPRIM_DIVTABLE[i-0] = MAKEINT ( FRACTdiv(MAKEFRACT(1),MAKEFRACT(i)) * iV_DIVMULTP);
}
pie_MatInit();
_TEX_INDEX = 0;
//mode specific initialisation
pie_SetRenderEngine(ENGINE_4101);
r = _mode_4101(); // we always want success as jon's stuff does the init
if (r)
{
pie_SetDefaultStates();
}
if (r)
{
iV_RenderAssign(mode,&rendSurface);
pal_Init();
}
else
{
iV_ShutDown();
DBERROR(("Initialise videomode failed"));
return FALSE;
}
return TRUE;
}
void pie_ShutDown(void)
{
switch (pie_GetRenderEngine())
{
case ENGINE_4101:
_close_4101();
break;
default:
break;
}
pie_SetRenderEngine(ENGINE_UNDEFINED);
}
/***************************************************************************/
void pie_ScreenFlip(CLEAR_MODE clearMode)
{
switch (pie_GetRenderEngine())
{
case ENGINE_4101:
if (clearMode == CLEAR_OFF OR clearMode == CLEAR_OFF_AND_NO_BUFFER_DOWNLOAD)
{
screenFlip(FALSE);//automatically downloads active backdrop and never fogs
}
else
{
screenFlip(TRUE);//automatically downloads active backdrop and never fogs
}
break;
default:
break;
}
}
/***************************************************************************/
void pie_Clear(UDWORD colour)
{
switch (pie_GetRenderEngine())
{
case ENGINE_4101:
default:
break;
}
}
/***************************************************************************/
void pie_GlobalRenderBegin(void)
{
switch (pie_GetRenderEngine())
{
default:
break;
}
}
void pie_GlobalRenderEnd(BOOL bForceClearToBlack)
{
switch (pie_GetRenderEngine())
{
default:
break;
}
}
/***************************************************************************/
UDWORD pie_GetResScalingFactor( void )
{
UDWORD resWidth; //n.b. resolution width implies resolution height...!
resWidth = pie_GetVideoBufferWidth();
switch(resWidth)
{
case 640:
return(100); // game runs in 640, so scale factor is 100 (normal)
break;
case 800:
return(125);
break; // as 800 is 125 percent of 640
case 960:
return(150);
break;
case 1024:
return(160);
break;
case 1152:
return(180);
break;
case 1280:
return(200);
break;
default:
ASSERT((FALSE,"Unsupported resolution"));
return(100); // default to 640
break;
}
}
/***************************************************************************/
void pie_LocalRenderBegin(void)
{
switch (pie_GetRenderEngine())
{
case ENGINE_4101:
_bank_off_4101();
break;
default:
break;
}
}
void pie_LocalRenderEnd(void)
{
switch (pie_GetRenderEngine())
{
case ENGINE_4101:
_bank_on_4101();
break;
default:
break;
}
}
void pie_RenderSetup(void)
{
}

Some files were not shown because too many files have changed in this diff Show More